hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/scsi/ufs/ufs.h
....@@ -1,36 +1,11 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Universal Flash Storage Host controller driver
3
- *
4
- * This code is based on drivers/scsi/ufs/ufs.h
54 * Copyright (C) 2011-2013 Samsung India Software Operations
65 *
76 * Authors:
87 * Santosh Yaraganavi <santosh.sy@samsung.com>
98 * Vinayak Holikatti <h.vinayak@samsung.com>
10
- *
11
- * This program is free software; you can redistribute it and/or
12
- * modify it under the terms of the GNU General Public License
13
- * as published by the Free Software Foundation; either version 2
14
- * of the License, or (at your option) any later version.
15
- * See the COPYING file in the top-level directory or visit
16
- * <http://www.gnu.org/licenses/gpl-2.0.html>
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * This program is provided "AS IS" and "WITH ALL FAULTS" and
24
- * without warranty of any kind. You are solely responsible for
25
- * determining the appropriateness of using and distributing
26
- * the program and assume all risks associated with your exercise
27
- * of rights with respect to the program, including but not limited
28
- * to infringement of third party rights, the risks and costs of
29
- * program errors, damage to or loss of data, programs or equipment,
30
- * and unavailability or interruption of operations. Under no
31
- * circumstances will the contributor of this Program be liable for
32
- * any damages of any kind arising from your use or distribution of
33
- * this program.
349 */
3510
3611 #ifndef _UFS_H
....@@ -38,15 +13,16 @@
3813
3914 #include <linux/mutex.h>
4015 #include <linux/types.h>
16
+#include <linux/android_kabi.h>
17
+#include <uapi/scsi/scsi_bsg_ufs.h>
4118
42
-#define MAX_CDB_SIZE 16
43
-#define GENERAL_UPIU_REQUEST_SIZE 32
19
+#define GENERAL_UPIU_REQUEST_SIZE (sizeof(struct utp_upiu_req))
4420 #define QUERY_DESC_MAX_SIZE 255
4521 #define QUERY_DESC_MIN_SIZE 2
4622 #define QUERY_DESC_HDR_SIZE 2
4723 #define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \
4824 (sizeof(struct utp_upiu_header)))
49
-#define RESPONSE_UPIU_SENSE_DATA_LENGTH 18
25
+#define UFS_SENSE_SIZE 18
5026
5127 #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
5228 cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
....@@ -63,7 +39,10 @@
6339 #define UFS_UPIU_MAX_UNIT_NUM_ID 0x7F
6440 #define UFS_MAX_LUNS (SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID)
6541 #define UFS_UPIU_WLUN_ID (1 << 7)
66
-#define UFS_UPIU_MAX_GENERAL_LUN 8
42
+#define UFS_RPMB_UNIT 0xC4
43
+
44
+/* WriteBooster buffer is available only for the logical unit from 0 to 7 */
45
+#define UFS_UPIU_MAX_WB_LUN_ID 8
6746
6847 /* Well known logical unit id in LUN field of UPIU */
6948 enum {
....@@ -141,12 +120,17 @@
141120 QUERY_FLAG_IDN_BUSY_RTC = 0x09,
142121 QUERY_FLAG_IDN_RESERVED3 = 0x0A,
143122 QUERY_FLAG_IDN_PERMANENTLY_DISABLE_FW_UPDATE = 0x0B,
123
+ QUERY_FLAG_IDN_WB_EN = 0x0E,
124
+ QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN = 0x0F,
125
+ QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8 = 0x10,
126
+ QUERY_FLAG_IDN_HPB_RESET = 0x11,
127
+ QUERY_FLAG_IDN_HPB_EN = 0x12,
144128 };
145129
146130 /* Attribute idn for Query requests */
147131 enum attr_idn {
148132 QUERY_ATTR_IDN_BOOT_LU_EN = 0x00,
149
- QUERY_ATTR_IDN_RESERVED = 0x01,
133
+ QUERY_ATTR_IDN_MAX_HPB_SINGLE_CMD = 0x01,
150134 QUERY_ATTR_IDN_POWER_MODE = 0x02,
151135 QUERY_ATTR_IDN_ACTIVE_ICC_LVL = 0x03,
152136 QUERY_ATTR_IDN_OOO_DATA_EN = 0x04,
....@@ -168,6 +152,11 @@
168152 QUERY_ATTR_IDN_FFU_STATUS = 0x14,
169153 QUERY_ATTR_IDN_PSA_STATE = 0x15,
170154 QUERY_ATTR_IDN_PSA_DATA_SIZE = 0x16,
155
+ QUERY_ATTR_IDN_REF_CLK_GATING_WAIT_TIME = 0x17,
156
+ QUERY_ATTR_IDN_WB_FLUSH_STATUS = 0x1C,
157
+ QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE = 0x1D,
158
+ QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST = 0x1E,
159
+ QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE = 0x1F,
171160 };
172161
173162 /* Descriptor idn for Query requests */
....@@ -190,16 +179,6 @@
190179 QUERY_DESC_DESC_TYPE_OFFSET = 0x01,
191180 };
192181
193
-enum ufs_desc_def_size {
194
- QUERY_DESC_DEVICE_DEF_SIZE = 0x40,
195
- QUERY_DESC_CONFIGURATION_DEF_SIZE = 0x90,
196
- QUERY_DESC_UNIT_DEF_SIZE = 0x23,
197
- QUERY_DESC_INTERCONNECT_DEF_SIZE = 0x06,
198
- QUERY_DESC_GEOMETRY_DEF_SIZE = 0x48,
199
- QUERY_DESC_POWER_DEF_SIZE = 0x62,
200
- QUERY_DESC_HEALTH_DEF_SIZE = 0x25,
201
-};
202
-
203182 /* Unit descriptor parameters offsets in bytes*/
204183 enum unit_desc_param {
205184 UNIT_DESC_PARAM_LEN = 0x0,
....@@ -219,6 +198,10 @@
219198 UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT = 0x18,
220199 UNIT_DESC_PARAM_CTX_CAPABILITIES = 0x20,
221200 UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1 = 0x22,
201
+ UNIT_DESC_PARAM_HPB_LU_MAX_ACTIVE_RGNS = 0x23,
202
+ UNIT_DESC_PARAM_HPB_PIN_RGN_START_OFF = 0x25,
203
+ UNIT_DESC_PARAM_HPB_NUM_PIN_RGNS = 0x27,
204
+ UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS = 0x29,
222205 };
223206
224207 /* Device descriptor parameters offsets in bytes*/
....@@ -258,6 +241,12 @@
258241 DEVICE_DESC_PARAM_PSA_MAX_DATA = 0x25,
259242 DEVICE_DESC_PARAM_PSA_TMT = 0x29,
260243 DEVICE_DESC_PARAM_PRDCT_REV = 0x2A,
244
+ DEVICE_DESC_PARAM_HPB_VER = 0x40,
245
+ DEVICE_DESC_PARAM_HPB_CONTROL = 0x42,
246
+ DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP = 0x4F,
247
+ DEVICE_DESC_PARAM_WB_PRESRV_USRSPC_EN = 0x53,
248
+ DEVICE_DESC_PARAM_WB_TYPE = 0x54,
249
+ DEVICE_DESC_PARAM_WB_SHARED_ALLOC_UNITS = 0x55,
261250 };
262251
263252 /* Interconnect descriptor parameters offsets in bytes*/
....@@ -302,6 +291,15 @@
302291 GEOMETRY_DESC_PARAM_ENM4_MAX_NUM_UNITS = 0x3E,
303292 GEOMETRY_DESC_PARAM_ENM4_CAP_ADJ_FCTR = 0x42,
304293 GEOMETRY_DESC_PARAM_OPT_LOG_BLK_SIZE = 0x44,
294
+ GEOMETRY_DESC_PARAM_HPB_REGION_SIZE = 0x48,
295
+ GEOMETRY_DESC_PARAM_HPB_NUMBER_LU = 0x49,
296
+ GEOMETRY_DESC_PARAM_HPB_SUBREGION_SIZE = 0x4A,
297
+ GEOMETRY_DESC_PARAM_HPB_MAX_ACTIVE_REGS = 0x4B,
298
+ GEOMETRY_DESC_PARAM_WB_MAX_ALLOC_UNITS = 0x4F,
299
+ GEOMETRY_DESC_PARAM_WB_MAX_WB_LUNS = 0x53,
300
+ GEOMETRY_DESC_PARAM_WB_BUFF_CAP_ADJ = 0x54,
301
+ GEOMETRY_DESC_PARAM_WB_SUP_RED_TYPE = 0x55,
302
+ GEOMETRY_DESC_PARAM_WB_SUP_WB_TYPE = 0x56,
305303 };
306304
307305 /* Health descriptor parameters offsets in bytes*/
....@@ -311,6 +309,12 @@
311309 HEALTH_DESC_PARAM_EOL_INFO = 0x2,
312310 HEALTH_DESC_PARAM_LIFE_TIME_EST_A = 0x3,
313311 HEALTH_DESC_PARAM_LIFE_TIME_EST_B = 0x4,
312
+};
313
+
314
+/* WriteBooster buffer mode */
315
+enum {
316
+ WB_BUF_MODE_LU_DEDICATED = 0x0,
317
+ WB_BUF_MODE_SHARED = 0x1,
314318 };
315319
316320 /*
....@@ -332,6 +336,13 @@
332336 UFSHCD_MILI_AMP = 2,
333337 UFSHCD_AMP = 3,
334338 };
339
+
340
+/* Possible values for dExtendedUFSFeaturesSupport */
341
+enum {
342
+ UFS_DEV_HPB_SUPPORT = BIT(7),
343
+ UFS_DEV_WRITE_BOOSTER_SUP = BIT(8),
344
+};
345
+#define UFS_DEV_HPB_SUPPORT_VERSION 0x310
335346
336347 #define POWER_DESC_MAX_SIZE 0x62
337348 #define POWER_DESC_MAX_ACTV_ICC_LVLS 16
....@@ -378,6 +389,20 @@
378389 UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8,
379390 };
380391
392
+/* bRefClkFreq attribute values */
393
+enum ufs_ref_clk_freq {
394
+ REF_CLK_FREQ_19_2_MHZ = 0,
395
+ REF_CLK_FREQ_26_MHZ = 1,
396
+ REF_CLK_FREQ_38_4_MHZ = 2,
397
+ REF_CLK_FREQ_52_MHZ = 3,
398
+ REF_CLK_FREQ_INVAL = -1,
399
+};
400
+
401
+struct ufs_ref_clk {
402
+ unsigned long freq_hz;
403
+ enum ufs_ref_clk_freq val;
404
+};
405
+
381406 /* Query response result code */
382407 enum {
383408 QUERY_RESULT_SUCCESS = 0x00,
....@@ -414,6 +439,7 @@
414439 MASK_RSP_UPIU_DATA_SEG_LEN = 0xFFFF,
415440 MASK_RSP_EXCEPTION_EVENT = 0x10000,
416441 MASK_TM_SERVICE_RESP = 0xFF,
442
+ MASK_TM_FUNC = 0xFF,
417443 };
418444
419445 /* Task management service response */
....@@ -432,64 +458,7 @@
432458 UFS_POWERDOWN_PWR_MODE = 3,
433459 };
434460
435
-/**
436
- * struct utp_upiu_header - UPIU header structure
437
- * @dword_0: UPIU header DW-0
438
- * @dword_1: UPIU header DW-1
439
- * @dword_2: UPIU header DW-2
440
- */
441
-struct utp_upiu_header {
442
- __be32 dword_0;
443
- __be32 dword_1;
444
- __be32 dword_2;
445
-};
446
-
447
-/**
448
- * struct utp_upiu_cmd - Command UPIU structure
449
- * @data_transfer_len: Data Transfer Length DW-3
450
- * @cdb: Command Descriptor Block CDB DW-4 to DW-7
451
- */
452
-struct utp_upiu_cmd {
453
- __be32 exp_data_transfer_len;
454
- u8 cdb[MAX_CDB_SIZE];
455
-};
456
-
457
-/**
458
- * struct utp_upiu_query - upiu request buffer structure for
459
- * query request.
460
- * @opcode: command to perform B-0
461
- * @idn: a value that indicates the particular type of data B-1
462
- * @index: Index to further identify data B-2
463
- * @selector: Index to further identify data B-3
464
- * @reserved_osf: spec reserved field B-4,5
465
- * @length: number of descriptor bytes to read/write B-6,7
466
- * @value: Attribute value to be written DW-5
467
- * @reserved: spec reserved DW-6,7
468
- */
469
-struct utp_upiu_query {
470
- u8 opcode;
471
- u8 idn;
472
- u8 index;
473
- u8 selector;
474
- __be16 reserved_osf;
475
- __be16 length;
476
- __be32 value;
477
- __be32 reserved[2];
478
-};
479
-
480
-/**
481
- * struct utp_upiu_req - general upiu request structure
482
- * @header:UPIU header structure DW-0 to DW-2
483
- * @sc: fields structure for scsi command DW-3 to DW-7
484
- * @qr: fields structure for query request DW-3 to DW-7
485
- */
486
-struct utp_upiu_req {
487
- struct utp_upiu_header header;
488
- union {
489
- struct utp_upiu_cmd sc;
490
- struct utp_upiu_query qr;
491
- };
492
-};
461
+#define UFS_WB_BUF_REMAIN_PERCENT(val) ((val) / 10)
493462
494463 /**
495464 * struct utp_cmd_rsp - Response UPIU structure
....@@ -502,8 +471,43 @@
502471 __be32 residual_transfer_count;
503472 __be32 reserved[4];
504473 __be16 sense_data_len;
505
- u8 sense_data[RESPONSE_UPIU_SENSE_DATA_LENGTH];
474
+ u8 sense_data[UFS_SENSE_SIZE];
506475 };
476
+
477
+struct ufshpb_active_field {
478
+ __be16 active_rgn;
479
+ __be16 active_srgn;
480
+};
481
+#define HPB_ACT_FIELD_SIZE 4
482
+
483
+/**
484
+ * struct utp_hpb_rsp - Response UPIU structure
485
+ * @residual_transfer_count: Residual transfer count DW-3
486
+ * @reserved1: Reserved double words DW-4 to DW-7
487
+ * @sense_data_len: Sense data length DW-8 U16
488
+ * @desc_type: Descriptor type of sense data
489
+ * @additional_len: Additional length of sense data
490
+ * @hpb_op: HPB operation type
491
+ * @lun: LUN of response UPIU
492
+ * @active_rgn_cnt: Active region count
493
+ * @inactive_rgn_cnt: Inactive region count
494
+ * @hpb_active_field: Recommended to read HPB region and subregion
495
+ * @hpb_inactive_field: To be inactivated HPB region and subregion
496
+ */
497
+struct utp_hpb_rsp {
498
+ __be32 residual_transfer_count;
499
+ __be32 reserved1[4];
500
+ __be16 sense_data_len;
501
+ u8 desc_type;
502
+ u8 additional_len;
503
+ u8 hpb_op;
504
+ u8 lun;
505
+ u8 active_rgn_cnt;
506
+ u8 inactive_rgn_cnt;
507
+ struct ufshpb_active_field hpb_active_field[2];
508
+ __be16 hpb_inactive_field[2];
509
+};
510
+#define UTP_HPB_RSP_SIZE 40
507511
508512 /**
509513 * struct utp_upiu_rsp - general upiu response structure
....@@ -515,38 +519,9 @@
515519 struct utp_upiu_header header;
516520 union {
517521 struct utp_cmd_rsp sr;
522
+ struct utp_hpb_rsp hr;
518523 struct utp_upiu_query qr;
519524 };
520
-};
521
-
522
-/**
523
- * struct utp_upiu_task_req - Task request UPIU structure
524
- * @header - UPIU header structure DW0 to DW-2
525
- * @input_param1: Input parameter 1 DW-3
526
- * @input_param2: Input parameter 2 DW-4
527
- * @input_param3: Input parameter 3 DW-5
528
- * @reserved: Reserved double words DW-6 to DW-7
529
- */
530
-struct utp_upiu_task_req {
531
- struct utp_upiu_header header;
532
- __be32 input_param1;
533
- __be32 input_param2;
534
- __be32 input_param3;
535
- __be32 reserved[2];
536
-};
537
-
538
-/**
539
- * struct utp_upiu_task_rsp - Task Management Response UPIU structure
540
- * @header: UPIU header structure DW0-DW-2
541
- * @output_param1: Ouput parameter 1 DW3
542
- * @output_param2: Output parameter 2 DW4
543
- * @reserved: Reserved double words DW-5 to DW-7
544
- */
545
-struct utp_upiu_task_rsp {
546
- struct utp_upiu_header header;
547
- __be32 output_param1;
548
- __be32 output_param2;
549
- __be32 reserved[3];
550525 };
551526
552527 /**
....@@ -573,9 +548,9 @@
573548 #define UFS_VREG_VCC_MAX_UV 3600000 /* uV */
574549 #define UFS_VREG_VCC_1P8_MIN_UV 1700000 /* uV */
575550 #define UFS_VREG_VCC_1P8_MAX_UV 1950000 /* uV */
576
-#define UFS_VREG_VCCQ_MIN_UV 1100000 /* uV */
577
-#define UFS_VREG_VCCQ_MAX_UV 1300000 /* uV */
578
-#define UFS_VREG_VCCQ2_MIN_UV 1650000 /* uV */
551
+#define UFS_VREG_VCCQ_MIN_UV 1140000 /* uV */
552
+#define UFS_VREG_VCCQ_MAX_UV 1260000 /* uV */
553
+#define UFS_VREG_VCCQ2_MIN_UV 1700000 /* uV */
579554 #define UFS_VREG_VCCQ2_MAX_UV 1950000 /* uV */
580555
581556 /*
....@@ -587,11 +562,10 @@
587562 struct ufs_vreg {
588563 struct regulator *reg;
589564 const char *name;
565
+ bool always_on;
590566 bool enabled;
591
- bool unused;
592567 int min_uV;
593568 int max_uV;
594
- int min_uA;
595569 int max_uA;
596570 };
597571
....@@ -606,28 +580,41 @@
606580 bool f_power_on_wp_en;
607581 /* Keeps information if any of the LU is power on write protected */
608582 bool is_lu_power_on_wp;
609
-};
610
-
611
-#define MAX_MODEL_LEN 16
612
-/**
613
- * ufs_dev_desc - ufs device details from the device descriptor
614
- *
615
- * @wmanufacturerid: card details
616
- * @model: card model
617
- */
618
-struct ufs_dev_desc {
583
+ /* Maximum number of general LU supported by the UFS device */
584
+ u8 max_lu_supported;
585
+ u8 wb_dedicated_lu;
619586 u16 wmanufacturerid;
620
- char model[MAX_MODEL_LEN + 1];
587
+ /*UFS device Product Name */
588
+ u8 *model;
589
+ u16 wspecversion;
590
+ u32 clk_gating_wait_us;
591
+ u32 d_ext_ufs_feature_sup;
592
+ u8 b_wb_buffer_type;
593
+ u32 d_wb_alloc_units;
594
+ bool b_rpm_dev_flush_capable;
595
+ u8 b_presrv_uspc_en;
596
+ /* UFS HPB related flag */
597
+ bool hpb_enabled;
598
+ ANDROID_KABI_RESERVE(1);
621599 };
622600
623601 /**
624602 * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor
603
+ * @dev_info: pointer of instance of struct ufs_dev_info
625604 * @lun: LU number to check
626605 * @return: true if the lun has a matching unit descriptor, false otherwise
627606 */
628
-static inline bool ufs_is_valid_unit_desc_lun(u8 lun)
607
+static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info,
608
+ u8 lun, u8 param_offset)
629609 {
630
- return lun == UFS_UPIU_RPMB_WLUN || (lun < UFS_UPIU_MAX_GENERAL_LUN);
610
+ if (!dev_info || !dev_info->max_lu_supported) {
611
+ pr_err("Max General LU supported by UFS isn't initialized\n");
612
+ return false;
613
+ }
614
+ /* WB is available only for the logical unit from 0 to 7 */
615
+ if (param_offset == UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS)
616
+ return lun < UFS_UPIU_MAX_WB_LUN_ID;
617
+ return lun == UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported);
631618 }
632619
633620 #endif /* End of Header */