use UFS device indicated maximum LU number
cover use UFS device indicated maximum LU number
According to Jedec standard UFS 3.0 and UFS 2.1 Spec, Maximum number of logical units supported by the UFS device is specified by parameter bMaxNumberLU in Geometry Descriptor. This series of patches is to delete macro definition UFS_UPIU_MAX_GENERAL_LUN, and switch to use indicated value in descriptor instead.
Bean Huo (3):
scsi: ufs: add max_lu_supported in struct ufs_dev_info
scsi: ufs: initialize max_lu_supported while booting
scsi: ufs: use UFS device indicated maximum LU number
drivers/scsi/ufs/ufs-sysfs.c | 2 +- drivers/scsi/ufs/ufs.h | 14 +++++++--- drivers/scsi/ufs/ufshcd.c | 51 +++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 7 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 scsi: ufs: add max_lu_supported in struct ufs_dev_info
From: Bean Huo <[email protected]>
Add one new parameter max_lu_supported in struct ufs_dev_info, which will be used to express exactly how many general LUs being supported by UFS device.
--- drivers/scsi/ufs/ufs.h | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/ufs/ufs.h +2 -0
@@ -530,6 +530,8 @@ struct ufs_dev_info {bool f_power_on_wp_en;/* Keeps information if any of the LU is power on write protected */ bool is_lu_power_on_wp; +/* Maximum number of general LU supported by the UFS device */ +u8 max_lu_supported; };#define MAX_MODEL_LEN 16
Signature · 1 line
2.17.1
Re: [PATCH 1/3] scsi: ufs: add max_lu_supported in struct ufs_dev_info
Quoted 5 lines · Bean Huo
From: Bean Huo <[email protected]>
Add one new parameter
max_lu_supportedin structufs_dev_info, which will be used to express exactly how many general LUs being supported by UFS device.
Re: [PATCH 1/3] scsi: ufs: add max_lu_supported in struct ufs_dev_info
In reply to Bean HuoQuoted 16 lines · Bean Huo
From: Bean Huo <[email protected]>
Add one new parameter
max_lu_supportedin structufs_dev_info, which will be used to express exactly how many general LUs being supported by UFS device.Signed-off-by Bean Huo <[email protected]>--- drivers/scsi/ufs/ufs.h | 2 ++ 1 file changed, 2 insertions(+)drivers/scsi/ufs/ufs.h +0
-0
drivers/scsi/ufs/ufs.h struct ufs_dev_info { · line 537
Quoted 8 lines
drivers/scsi/ufs/ufs.h +2
-0@@ -530,6 +530,8 @@ struct ufs_dev_info {bool f_power_on_wp_en;/* Keeps information if any of the LU is power on write protected */ bool is_lu_power_on_wp; +/* Maximum number of general LU supported by the UFS device */ +u8 max_lu_supported; };#define MAX_MODEL_LEN 16
Looks good to me.
PATCH 2/3 scsi: ufs: initialize max_lu_supported while booting
In reply to Bean HuoFrom: Bean Huo <[email protected]>
This patch is to add a new function ufshcd_init_device_param() for initialization of UFS device related parameters which are used by driver. In this version patch, there is only dev_info.max_lu_supported being initialized.
--- drivers/scsi/ufs/ufshcd.c | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +46 -1
@@ -3158,6 +3158,11 @@ static int ufshcd_read_device_desc(struct ufs_hba *hba, u8 *buf, u32 size)return ufshcd_read_desc (hba,QUERY_DESC_IDN_DEVICE ,0 , buf, size); } +static int ufshcd_read_geometry_desc (struct ufs_hba *hba,u8 *buf,u32 size) +{ +return ufshcd_read_desc (hba,QUERY_DESC_IDN_GEOMETRY ,0 , buf, size); +} +/** * struct uc_string_id - unicode string *
@@ -6827,6 +6832,37 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) hba->req_abort_count =0 ; } +static int ufshcd_init_device_param (struct ufs_hba *hba) +{ +int err; +size_t buff_len; +u8 *desc_buf; + + buff_len =QUERY_DESC_MAX_SIZE ; + desc_buf =kmalloc (buff_len,GFP_KERNEL ); +if (!desc_buf) { + err = -ENOMEM ; + goto out; + } + + err =ufshcd_read_geometry_desc (hba, desc_buf, + hba->desc_size.geom_desc); +if (err) { +dev_err (hba->dev,"%s: Failed reading Geometry Desc. err = %d\n" , + __func__, err); + goto out; + } + +if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN ] ==1 ) + hba->dev_info.max_lu_supported =32 ; +else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN ] ==0 ) + hba->dev_info.max_lu_supported =8 ; + +out: +kfree (desc_buf); +return err; +} +static void ufshcd_init_desc_sizes (struct ufs_hba *hba) {int err;
@@ -7016,13 +7052,22 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)/* * If we are in error handling context or in power management callbacks -* context, no need to scan the host +* context, no need to scan the host and to reinitialize the parameters */ if (!ufshcd_eh_in_progress (hba) && !hba->pm_op_in_progress) {bool flag;/* clear any previous UFS device information */ memset (&hba->dev_info,0 ,sizeof (hba->dev_info)); +/* Init parameters according to UFS relevant descriptors */ + ret =ufshcd_init_device_param (hba); +if (ret) { +dev_err (hba->dev, +"%s: Init of device param failed. err = %d\n" , + __func__, ret); + goto out; + } +if (!ufshcd_query_flag_retry (hba,UPIU_QUERY_OPCODE_READ_FLAG ,QUERY_FLAG_IDN_PWR_ON_WPE , &flag)) hba->dev_info.f_power_on_wp_en = flag;
Signature · 1 line
2.17.1
Re: [PATCH 2/3] scsi: ufs: initialize max_lu_supported while booting
drivers/scsi/ufs/ufshcd.c static int ufshcd_read_device_desc(struct ufs_hba *hba, u8 *buf, u32 size) · line 3164
Quoted 4 lines · Bean Huo
drivers/scsi/ufs/ufshcd.c +4
-0+static int ufshcd_read_geometry_desc (struct ufs_hba *hba,u8 *buf,u32 size) +{ +return ufshcd_read_desc (hba,QUERY_DESC_IDN_GEOMETRY ,0 , buf, size); +}
The declaration of this function is longer than its body. Do we really need this function? Has it been considered to inline this function into its caller?
drivers/scsi/ufs/ufshcd.c static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) · line 6846
Quoted 12 lines
drivers/scsi/ufs/ufshcd.c +12
-0+static int ufshcd_init_device_param (struct ufs_hba *hba) +{ +int err; +size_t buff_len; +u8 *desc_buf; + + buff_len =QUERY_DESC_MAX_SIZE ; + desc_buf =kmalloc (buff_len,GFP_KERNEL ); +if (!desc_buf) { + err = -ENOMEM ; + goto out; + }
Has it been considered to use hba->desc_size.geom_desc instead of QUERY_DESC_MAX_SIZE?
drivers/scsi/ufs/ufshcd.c static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) · line 6859
Quoted 12 lines
drivers/scsi/ufs/ufshcd.c +12
-0+ err =ufshcd_read_geometry_desc (hba, desc_buf, + hba->desc_size.geom_desc); +if (err) { +dev_err (hba->dev,"%s: Failed reading Geometry Desc. err = %d\n" , + __func__, err); + goto out; + } + +if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN ] ==1 ) + hba->dev_info.max_lu_supported =32 ; +else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN ] ==0 ) + hba->dev_info.max_lu_supported =8 ;
Can it happen that GEOMETRY_DESC_PARAM_MAX_NUM_LUN >= hba->desc_size.geom_desc and hence that the above code reads uninitialized data?
Quoted 14 lines
drivers/scsi/ufs/ufshcd.c +3
-1@@ -7016,13 +7052,22 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)/* * If we are in error handling context or in power management callbacks -* context, no need to scan the host +* context, no need to scan the host and to reinitialize the parameters */ if (!ufshcd_eh_in_progress (hba) && !hba->pm_op_in_progress) {bool flag;/* clear any previous UFS device information */ memset (&hba->dev_info,0 ,sizeof (hba->dev_info)); +/* Init parameters according to UFS relevant descriptors */ + ret =ufshcd_init_device_param (hba);
drivers/scsi/ufs/ufshcd.c static int ufshcd_probe_hba(struct ufs_hba *hba) · line 7073
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +7
-0+if (ret) { +dev_err (hba->dev, +"%s: Init of device param failed. err = %d\n" , + __func__, ret); + goto out; + } +if (!ufshcd_query_flag_retry (hba,UPIU_QUERY_OPCODE_READ_FLAG ,QUERY_FLAG_IDN_PWR_ON_WPE , &flag)) hba->dev_info.f_power_on_wp_en = flag;
The context check in ufshcd_probe_hba() looks ugly to me. Has it been considered to move all code that is controlled by the if-statement with the context check into ufshcd_async_scan()?
Thanks,
Bart.
RE: [PATCH 2/3] scsi: ufs: initialize max_lu_supported while booting
Quoted 12 lines
drivers/scsi/ufs/ufshcd.c static int ufshcd_probe_hba(struct ufs_hba *hba)
Quoted 12 lines
memset(&hba->dev_info, 0, sizeof(hba->dev_info));drivers/scsi/ufs/ufshcd.c +9
-0+/* Init parameters according to UFS relevant descriptors */ + ret =ufshcd_init_device_param (hba); +if (ret) { +dev_err (hba->dev, +"%s: Init of device param failed. err = %d\n" , + __func__, ret); + goto out; + } + if (!ufshcd_query_flag_retry(hba,
Quoted 7 lines
UPIU_QUERY_OPCODE_READ_FLAG,Quoted 2 lines
QUERY_FLAG_IDN_PWR_ON_WPE, &flag)) hba->dev_info.f_power_on_wp_en = flag;The context check in
ufshcd_probe_hba()looks ugly to me. Has it been considered to move all code that is controlled by the if-statement with the context check intoufshcd_async_scan()?
As part of ufshcd_probe_hba we also read the device descriptor,
Which is, by spec, an optional stage of the boot process, right after the unipro boot sequence. Might want to consider moving the call there, as an integral phase of obtaining device info.
Thanks,
Avri
Quoted 5 lines
Thanks,
Bart.
RE: [EXT] Re: [PATCH 2/3] scsi: ufs: initialize max_lu_supported while booting
In reply to Bart Van AsscheHi, Bart
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+static int ufshcd_read_geometry_desc(struct ufs_hba *hba, u8 *buf, +u32 size) { + return ufshcd_read_desc(hba, QUERY_DESC_IDN_GEOMETRY, 0, buf,size);
Quoted 1 line
+}
The declaration of this function is longer than its body. Do we really need this function? Has it been considered to inline this function into its caller?
No, absolutely doesn't need it. ufshcd_read_power_desc() and ufshcd_read_device_desc() as well. Let me try to simplify them in the next version.
Quoted 6 lines
Quoted 6 lines
drivers/scsi/ufs/ufshcd.c +6
-0+static int ufshcd_init_device_param (struct ufs_hba *hba) { +int err; +size_t buff_len; +u8 *desc_buf; + + buff_len =QUERY_DESC_MAX_SIZE ;
Quoted 9 lines
drivers/scsi/ufs/ufshcd.c static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) · line 6846
Quoted 5 lines
drivers/scsi/ufs/ufshcd.c +5
-0+ desc_buf =kmalloc (buff_len,GFP_KERNEL ); +if (!desc_buf) { + err = -ENOMEM ; + goto out; + }Has it been considered to use
hba->desc_size.geom_descinstead ofQUERY_DESC_MAX_SIZE?
The reason is that I want all of UFS device related parameters move to ufshcd_init_device_param(), And QUERY_DESC_MAX_SIZE is to compatible with all of descriptors size.
Quoted 5 lines
drivers/scsi/ufs/ufshcd.c static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba)
Quoted 4 lines
drivers/scsi/ufs/ufshcd.c +4
-0+ err =ufshcd_read_geometry_desc (hba, desc_buf, + hba->desc_size.geom_desc); +if (err) { + dev_err(hba->dev, "%s: Failed reading Geometry Desc. err= %d\n",
Quoted 13 lines
drivers/scsi/ufs/ufshcd.c static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) · line 6859
Quoted 8 lines
drivers/scsi/ufs/ufshcd.c +8
-0+ __func__, err); + goto out; + } + +if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN ] ==1 ) + hba->dev_info.max_lu_supported =32 ; +else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN ] ==0 ) + hba->dev_info.max_lu_supported =8 ;Can it happen that
GEOMETRY_DESC_PARAM_MAX_NUM_LUN>=hba->desc_size.geom_descand hence that the above code reads uninitialized data?
No, GEOMETRY_DESC_PARAM_MAX_NUM_LUN 0x0c is far less than geometry descriptor size.
As for the UFS 2.0, this field is reserved, it is default 0. For the UFS 2.1 and UFS 3.0, there are only two valid value for this filed, either 00h: 8 Logical units, or 01h: 32 Logical units.
Quoted 25 lines
Quoted 14 lines
drivers/scsi/ufs/ufshcd.c +2
-1@@ -7016,13 +7052,22 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)/* * If we are in error handling context or in power management callbacks -* context, no need to scan the host +* context, no need to scan the host and to reinitialize the +parameters */ if (!ufshcd_eh_in_progress (hba) && !hba->pm_op_in_progress) {bool flag;/* clear any previous UFS device information */ memset (&hba->dev_info,0 ,sizeof (hba->dev_info));drivers/scsi/ufs/ufshcd.c static int ufshcd_probe_hba(struct ufs_hba · line 7073
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +9
-0+/* Init parameters according to UFS relevant descriptors */ + ret =ufshcd_init_device_param (hba); +if (ret) { +dev_err (hba->dev, +"%s: Init of device param failed. err = %d\n" , + __func__, ret); + goto out; + } + if (!ufshcd_query_flag_retry(hba,
UPIU_QUERY_OPCODE_READ_FLAG,
Quoted 7 lines
drivers/scsi/ufs/ufshcd.c static int ufshcd_probe_hba(struct ufs_hba *hba) · line 7073
Quoted 2 lines
drivers/scsi/ufs/ufshcd.c +0
-0QUERY_FLAG_IDN_PWR_ON_WPE, &flag)) hba->dev_info.f_power_on_wp_en = flag;The context check in
ufshcd_probe_hba()looks ugly to me. Has it been considered to move all code that is controlled by the if-statement with the context check intoufshcd_async_scan()?
I totally agree with you. They should be moved out from ufshcd_probe_hba(), And moved to ufshcd_async_scan(). Let me do in the next version.
Thanks.
//Bean Huo
Re: [PATCH 2/3] scsi: ufs: initialize max_lu_supported while booting
In reply to Bean HuoQuoted 86 lines · Bean Huo
From: Bean Huo <[email protected]>
This patch is to add a new function
ufshcd_init_device_param()for initialization of UFS device related parameters which are used by driver. In this version patch, there is only dev_info.max_lu_supported being initialized.Signed-off-by Bean Huo <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)drivers/scsi/ufs/ufshcd.c +5
-0@@ -3158,6 +3158,11 @@ static int ufshcd_read_device_desc(struct ufs_hba *hba, u8 *buf, u32 size)return ufshcd_read_desc (hba,QUERY_DESC_IDN_DEVICE ,0 , buf, size); } +static int ufshcd_read_geometry_desc (struct ufs_hba *hba,u8 *buf,u32 size) +{ +return ufshcd_read_desc (hba,QUERY_DESC_IDN_GEOMETRY ,0 , buf, size); +} +/** * struct
uc_string_id- unicode string
*drivers/scsi/ufs/ufshcd.c +31
-0@@ -6827,6 +6832,37 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) hba->req_abort_count = 0; } +static int ufshcd_init_device_param (struct ufs_hba *hba) +{ +int err; +size_t buff_len; +u8 *desc_buf; + + buff_len =QUERY_DESC_MAX_SIZE ; + desc_buf =kmalloc (buff_len,GFP_KERNEL ); +if (!desc_buf) { + err = -ENOMEM ; + goto out; + } + + err =ufshcd_read_geometry_desc (hba, desc_buf, + hba->desc_size.geom_desc); +if (err) { +dev_err (hba->dev,"%s: Failed reading Geometry Desc. err = %d\n" , + __func__, err); + goto out; + } + +if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN ] ==1 ) + hba->dev_info.max_lu_supported =32 ; +else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN ] ==0 ) + hba->dev_info.max_lu_supported =8 ; + +out: +kfree (desc_buf); +return err; +} +static void ufshcd_init_desc_sizes (struct ufs_hba *hba) {drivers/scsi/ufs/ufshcd.c +0
-0int err;@@ -7016,13 +7052,22 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)/* * If we are in error handling context or in power management callbacks
drivers/scsi/ufs/ufshcd.c +1
-1-* context, no need to scan the host +* context, no need to scan the host and to reinitialize the parameters
drivers/scsi/ufs/ufshcd.c +2
-0*/ if (!ufshcd_eh_in_progress (hba) && !hba->pm_op_in_progress) {bool flag;/* clear any previous UFS device information */ memset (&hba->dev_info,0 ,sizeof (hba->dev_info)); +/* Init parameters according to UFS relevant descriptors */ + ret =ufshcd_init_device_param (hba);
drivers/scsi/ufs/ufshcd.c static int ufshcd_probe_hba(struct ufs_hba *hba) · line 7073
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +7
-0+if (ret) { +dev_err (hba->dev, +"%s: Init of device param failed. err = %d\n" , + __func__, ret); + goto out; + } +if (!ufshcd_query_flag_retry (hba,UPIU_QUERY_OPCODE_READ_FLAG ,QUERY_FLAG_IDN_PWR_ON_WPE , &flag)) hba->dev_info.f_power_on_wp_en = flag;
Looks good to me.
PATCH 3/3 scsi: ufs: use UFS device indicated maximum LU number
In reply to Bean HuoFrom: Bean Huo <[email protected]>
According to Jedec standard UFS 3.0 and UFS 2.1 Spec, Maximum number of logical units supported by the UFS device is indicated by parameter bMaxNumberLU in Geometry Descriptor. This patch is to delete current hard code macro definition of UFS_UPIU_MAX_GENERAL_LUN, and switch to use device indicated number instead.
--- drivers/scsi/ufs/ufs-sysfs.c | 2 +- drivers/scsi/ufs/ufs.h | 12 +++++++++--- drivers/scsi/ufs/ufshcd.c | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-)
drivers/scsi/ufs/ufs-sysfs.c +1 -1
@@ -713,7 +713,7 @@ static ssize_t _pname##_show(struct device *dev, \struct scsi_device *sdev =to_scsi_device (dev); \struct ufs_hba *hba =shost_priv (sdev->host); \u8 lun =ufshcd_scsi_to_upiu_lun (sdev->lun); \ -if (!ufs_is_valid_unit_desc_lun (lun)) \ +if (!ufs_is_valid_unit_desc_lun (&hba->dev_info, lun)) \return -EINVAL ; \ return ufs_sysfs_read_desc_param(hba, QUERY_DESC_IDN_##_duname, \ lun, _duname##_DESC_PARAM##_puname, buf, _size); \
drivers/scsi/ufs/ufs.h +9 -3
@@ -63,7 +63,6 @@#define UFS_UPIU_MAX_UNIT_NUM_ID 0x7F#define UFS_MAX_LUNS (SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID)#define UFS_UPIU_WLUN_ID (1 << 7) -#define UFS_UPIU_MAX_GENERAL_LUN 8/* Well known logical unit id in LUN field of UPIU */ enum {
@@ -548,12 +547,19 @@ struct ufs_dev_desc {/** * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor +* @dev_info: pointer of instance of struct ufs_dev_info * @lun: LU number to check * @return: true if the lun has a matching unit descriptor, false otherwise */ -static inline bool ufs_is_valid_unit_desc_lun (u8 lun) +static inline bool ufs_is_valid_unit_desc_lun (struct ufs_dev_info *dev_info, +u8 lun) { -return lun ==UFS_UPIU_RPMB_WLUN || (lun <UFS_UPIU_MAX_GENERAL_LUN ); +if (!dev_info || !dev_info->max_lu_supported) { +pr_err ("Max General LU supported by UFS isn't initilized\n" ); +return false; + } + +return lun ==UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported); }#endif /* End of Header */
drivers/scsi/ufs/ufshcd.c +2 -2
@@ -3286,7 +3286,7 @@ static inline int ufshcd_read_unit_desc_param(struct ufs_hba *hba,* Unit descriptors are only available for general purpose LUs (LUN id * from 0 to 7) and RPMB Well known LU. */ -if (!ufs_is_valid_unit_desc_lun (lun)) +if (!ufs_is_valid_unit_desc_lun (&hba->dev_info, lun))return -EOPNOTSUPP ; return ufshcd_read_desc_param(hba, QUERY_DESC_IDN_UNIT, lun,
@@ -4540,7 +4540,7 @@ static int ufshcd_get_lu_wp(struct ufs_hba *hba,* protected so skip reading bLUWriteProtect parameter for * it. For other W-LUs, UNIT DESCRIPTOR is not available. */ - else if (lun >= UFS_UPIU_MAX_GENERAL_LUN) + else if (lun >= hba->dev_info.max_lu_supported) ret = -ENOTSUPP ; else ret = ufshcd_read_unit_desc_param(hba,
Signature · 1 line
2.17.1
Re: [PATCH 3/3] scsi: ufs: use UFS device indicated maximum LU number
drivers/scsi/ufs/ufs.h struct ufs_dev_desc { · line 556
Quoted 12 lines · Bean Huo
drivers/scsi/ufs/ufs.h +3
-1@@ -548,12 +547,19 @@ struct ufs_dev_desc {/** * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor +* @dev_info: pointer of instance of struct ufs_dev_info * @lun: LU number to check * @return: true if the lun has a matching unit descriptor, false otherwise */ -static inline bool ufs_is_valid_unit_desc_lun (u8 lun) +static inline bool ufs_is_valid_unit_desc_lun (struct ufs_dev_info *dev_info, +u8 lun) {
Can the dev_info be declared 'const' (const truct ufs_dev_info *dev_info)?
drivers/scsi/ufs/ufs.h struct ufs_dev_desc { · line 558
Quoted 3 lines
drivers/scsi/ufs/ufs.h +2
-1-return lun ==UFS_UPIU_RPMB_WLUN || (lun <UFS_UPIU_MAX_GENERAL_LUN ); +if (!dev_info || !dev_info->max_lu_supported) { +pr_err ("Max General LU supported by UFS isn't initilized\n" );
^^^^^^^^^^
initialized?drivers/scsi/ufs/ufs.h struct ufs_dev_desc { · line 563
Quoted 5 lines
drivers/scsi/ufs/ufs.h +4
-0+return false; + } + +return lun ==UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported); }
Are the parentheses in the above expression necessary?
Thanks,
Bart.
Re: [PATCH 3/3] scsi: ufs: use UFS device indicated maximum LU number
In reply to Bean HuoQuoted 82 lines · Bean Huo
From: Bean Huo <[email protected]>
According to Jedec standard UFS 3.0 and UFS 2.1 Spec, Maximum number of logical units supported by the UFS device is indicated by parameter bMaxNumberLU in Geometry Descriptor. This patch is to delete current hard code macro definition of
UFS_UPIU_MAX_GENERAL_LUN, and switch to use device indicated number instead.Signed-off-by Bean Huo <[email protected]>--- drivers/scsi/ufs/ufs-sysfs.c | 2 +- drivers/scsi/ufs/ufs.h | 12 +++++++++--- drivers/scsi/ufs/ufshcd.c | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-)drivers/scsi/ufs/ufs-sysfs.c +1
-1@@ -713,7 +713,7 @@ static ssize_t _pname##_show(struct device *dev, \ struct scsi_device *sdev = to_scsi_device(dev); \struct ufs_hba *hba =shost_priv (sdev->host); \u8 lun =ufshcd_scsi_to_upiu_lun (sdev->lun); \ -if (!ufs_is_valid_unit_desc_lun (lun)) \ +if (!ufs_is_valid_unit_desc_lun (&hba->dev_info, lun)) \return -EINVAL ; \ return ufs_sysfs_read_desc_param(hba, QUERY_DESC_IDN_##_duname, \drivers/scsi/ufs/ufs-sysfs.c +0
-0lun, _duname##_DESC_PARAM##_puname, buf, _size); \drivers/scsi/ufs/ufs.h +0
-1@@ -63,7 +63,6 @@#define UFS_UPIU_MAX_UNIT_NUM_ID 0x7F#define UFS_MAX_LUNS (SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID)#define UFS_UPIU_WLUN_ID (1 << 7) -#define UFS_UPIU_MAX_GENERAL_LUN 8/* Well known logical unit id in LUN field of UPIU */ enum {@@ -548,12 +547,19 @@ struct ufs_dev_desc {/** * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor
+ * @dev_info: pointer of instance of structufs_dev_info
* @lun: LU number to check
* @return: true if the lun has a matching unit descriptor, false
otherwise
*/drivers/scsi/ufs/ufs.h +1
-1-static inline bool ufs_is_valid_unit_desc_lun (u8 lun) +static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info
*dev_info,drivers/scsi/ufs/ufs.h +7
-1+ u8 lun) { -return lun ==UFS_UPIU_RPMB_WLUN || (lun <UFS_UPIU_MAX_GENERAL_LUN ); +if (!dev_info || !dev_info->max_lu_supported) { +pr_err ("Max General LU supported by UFS isn't initilized\n" ); +return false; + } + + return lun == UFS_UPIU_RPMB_WLUN || (lun <
dev_info->max_lu_supported);
}#endif /* End of Header */
drivers/scsi/ufs/ufshcd.c +0
-0@@ -3286,7 +3286,7 @@ static inline int ufshcd_read_unit_desc_param(struct ufs_hba *hba, * Unit descriptors are only available for general purpose LUs (LUNid
drivers/scsi/ufs/ufshcd.c +1
-1* from 0 to 7) and RPMB Well known LU. */ -if (!ufs_is_valid_unit_desc_lun (lun)) +if (!ufs_is_valid_unit_desc_lun (&hba->dev_info, lun))return -EOPNOTSUPP ; return ufshcd_read_desc_param(hba, QUERY_DESC_IDN_UNIT, lun,
drivers/scsi/ufs/ufshcd.c static int ufshcd_get_lu_wp(struct ufs_hba *hba, · line 4546
Quoted 8 lines
drivers/scsi/ufs/ufshcd.c +1
-1@@ -4540,7 +4540,7 @@ static int ufshcd_get_lu_wp(struct ufs_hba *hba,* protected so skip reading bLUWriteProtect parameter for * it. For other W-LUs, UNIT DESCRIPTOR is not available. */ - else if (lun >= UFS_UPIU_MAX_GENERAL_LUN) + else if (lun >= hba->dev_info.max_lu_supported) ret = -ENOTSUPP ; else ret = ufshcd_read_unit_desc_param(hba,
Looks good to me.