diff mbox series

scsi: ufs: Add selector to ufshcd_query_flag* APIs

Message ID 20210317033143epcms2p25b37bba2bb515c1ce85bf555656ca3f2@epcms2p2
State New
Headers show
Series scsi: ufs: Add selector to ufshcd_query_flag* APIs | expand

Commit Message

Daejun Park March 17, 2021, 3:31 a.m. UTC
Unlike other query APIs in UFS, ufshcd_query_flag has a fixed selector
as 0. This patch allows ufshcd_query_flag API to choose selector value
by parameter.

Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
 drivers/scsi/ufs/ufs-sysfs.c |  2 +-
 drivers/scsi/ufs/ufshcd.c    | 29 +++++++++++++++++------------
 drivers/scsi/ufs/ufshcd.h    |  2 +-
 3 files changed, 19 insertions(+), 14 deletions(-)

Comments

Can Guo March 18, 2021, 5:48 a.m. UTC | #1
On 2021-03-17 11:31, Daejun Park wrote:
> Unlike other query APIs in UFS, ufshcd_query_flag has a fixed selector

> as 0. This patch allows ufshcd_query_flag API to choose selector value

> by parameter.

> 

> Signed-off-by: Daejun Park <daejun7.park@samsung.com>


Reviewed-by: Can Guo <cang@codeaurora.org>


> ---

>  drivers/scsi/ufs/ufs-sysfs.c |  2 +-

>  drivers/scsi/ufs/ufshcd.c    | 29 +++++++++++++++++------------

>  drivers/scsi/ufs/ufshcd.h    |  2 +-

>  3 files changed, 19 insertions(+), 14 deletions(-)

> 

> diff --git a/drivers/scsi/ufs/ufs-sysfs.c 

> b/drivers/scsi/ufs/ufs-sysfs.c

> index acc54f530f2d..606b058a3394 100644

> --- a/drivers/scsi/ufs/ufs-sysfs.c

> +++ b/drivers/scsi/ufs/ufs-sysfs.c

> @@ -746,7 +746,7 @@ static ssize_t _name##_show(struct device 

> *dev,				\

>  		index = ufshcd_wb_get_query_index(hba);			\

>  	pm_runtime_get_sync(hba->dev);					\

>  	ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,	\

> -		QUERY_FLAG_IDN##_uname, index, &flag);			\

> +		QUERY_FLAG_IDN##_uname, index, &flag, 0);		\

>  	pm_runtime_put_sync(hba->dev);					\

>  	if (ret) {							\

>  		ret = -EINVAL;						\

> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c

> index 8c0ff024231c..c2fd9c58d6b8 100644

> --- a/drivers/scsi/ufs/ufshcd.c

> +++ b/drivers/scsi/ufs/ufshcd.c

> @@ -2940,13 +2940,15 @@ static inline void ufshcd_init_query(struct

> ufs_hba *hba,

>  }

> 

>  static int ufshcd_query_flag_retry(struct ufs_hba *hba,

> -	enum query_opcode opcode, enum flag_idn idn, u8 index, bool 

> *flag_res)

> +	enum query_opcode opcode, enum flag_idn idn, u8 index, bool 

> *flag_res,

> +	u8 selector)

>  {

>  	int ret;

>  	int retries;

> 

>  	for (retries = 0; retries < QUERY_REQ_RETRIES; retries++) {

> -		ret = ufshcd_query_flag(hba, opcode, idn, index, flag_res);

> +		ret = ufshcd_query_flag(hba, opcode, idn, index, flag_res,

> +					selector);

>  		if (ret)

>  			dev_dbg(hba->dev,

>  				"%s: failed with error %d, retries %d\n",

> @@ -2969,15 +2971,17 @@ static int ufshcd_query_flag_retry(struct 

> ufs_hba *hba,

>   * @idn: flag idn to access

>   * @index: flag index to access

>   * @flag_res: the flag value after the query request completes

> + * @selector: selector field

>   *

>   * Returns 0 for success, non-zero in case of failure

>   */

>  int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,

> -			enum flag_idn idn, u8 index, bool *flag_res)

> +			enum flag_idn idn, u8 index, bool *flag_res,

> +			u8 selector)

>  {

>  	struct ufs_query_req *request = NULL;

>  	struct ufs_query_res *response = NULL;

> -	int err, selector = 0;

> +	int err;

>  	int timeout = QUERY_REQ_TIMEOUT;

> 

>  	BUG_ON(!hba);

> @@ -4331,7 +4335,7 @@ static int ufshcd_complete_dev_init(struct 

> ufs_hba *hba)

>  	ktime_t timeout;

> 

>  	err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,

> -		QUERY_FLAG_IDN_FDEVICEINIT, 0, NULL);

> +		QUERY_FLAG_IDN_FDEVICEINIT, 0, NULL, 0);

>  	if (err) {

>  		dev_err(hba->dev,

>  			"%s setting fDeviceInit flag failed with error %d\n",

> @@ -4343,7 +4347,8 @@ static int ufshcd_complete_dev_init(struct 

> ufs_hba *hba)

>  	timeout = ktime_add_ms(ktime_get(), FDEVICEINIT_COMPL_TIMEOUT);

>  	do {

>  		err = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,

> -					QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res);

> +					QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res,

> +					0);

>  		if (!flag_res)

>  			break;

>  		usleep_range(5000, 10000);

> @@ -5250,7 +5255,7 @@ static int ufshcd_enable_auto_bkops(struct 

> ufs_hba *hba)

>  		goto out;

> 

>  	err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,

> -			QUERY_FLAG_IDN_BKOPS_EN, 0, NULL);

> +			QUERY_FLAG_IDN_BKOPS_EN, 0, NULL, 0);

>  	if (err) {

>  		dev_err(hba->dev, "%s: failed to enable bkops %d\n",

>  				__func__, err);

> @@ -5300,7 +5305,7 @@ static int ufshcd_disable_auto_bkops(struct 

> ufs_hba *hba)

>  	}

> 

>  	err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG,

> -			QUERY_FLAG_IDN_BKOPS_EN, 0, NULL);

> +			QUERY_FLAG_IDN_BKOPS_EN, 0, NULL, 0);

>  	if (err) {

>  		dev_err(hba->dev, "%s: failed to disable bkops %d\n",

>  				__func__, err);

> @@ -5463,7 +5468,7 @@ int ufshcd_wb_ctrl(struct ufs_hba *hba, bool 

> enable)

> 

>  	index = ufshcd_wb_get_query_index(hba);

>  	ret = ufshcd_query_flag_retry(hba, opcode,

> -				      QUERY_FLAG_IDN_WB_EN, index, NULL);

> +				      QUERY_FLAG_IDN_WB_EN, index, NULL, 0);

>  	if (ret) {

>  		dev_err(hba->dev, "%s write booster %s failed %d\n",

>  			__func__, enable ? "enable" : "disable", ret);

> @@ -5490,7 +5495,7 @@ static int

> ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set)

>  	index = ufshcd_wb_get_query_index(hba);

>  	return ufshcd_query_flag_retry(hba, val,

>  				QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8,

> -				index, NULL);

> +				index, NULL, 0);

>  }

> 

>  static inline int ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool 

> enable)

> @@ -5511,7 +5516,7 @@ static inline int ufshcd_wb_toggle_flush(struct

> ufs_hba *hba, bool enable)

>  	index = ufshcd_wb_get_query_index(hba);

>  	ret = ufshcd_query_flag_retry(hba, opcode,

>  				      QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, index,

> -				      NULL);

> +				      NULL, 0);

>  	if (ret) {

>  		dev_err(hba->dev, "%s WB-Buf Flush %s failed %d\n", __func__,

>  			enable ? "enable" : "disable", ret);

> @@ -7751,7 +7756,7 @@ static int ufshcd_device_params_init(struct 

> ufs_hba *hba)

>  	ufshcd_get_ref_clk_gating_wait(hba);

> 

>  	if (!ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_READ_FLAG,

> -			QUERY_FLAG_IDN_PWR_ON_WPE, 0, &flag))

> +			QUERY_FLAG_IDN_PWR_ON_WPE, 0, &flag, 0))

>  		hba->dev_info.f_power_on_wp_en = flag;

> 

>  	/* Probe maximum power mode co-supported by both UFS host and device 

> */

> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h

> index 1af91661dc83..67a26b2be36f 100644

> --- a/drivers/scsi/ufs/ufshcd.h

> +++ b/drivers/scsi/ufs/ufshcd.h

> @@ -1077,7 +1077,7 @@ int ufshcd_read_desc_param(struct ufs_hba *hba,

>  int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,

>  		      enum attr_idn idn, u8 index, u8 selector, u32 *attr_val);

>  int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,

> -	enum flag_idn idn, u8 index, bool *flag_res);

> +	enum flag_idn idn, u8 index, bool *flag_res, u8 selector);

> 

>  void ufshcd_auto_hibern8_enable(struct ufs_hba *hba);

>  void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
Martin K. Petersen March 19, 2021, 2:25 a.m. UTC | #2
Daejun,

> Unlike other query APIs in UFS, ufshcd_query_flag has a fixed selector

> as 0. This patch allows ufshcd_query_flag API to choose selector value

> by parameter.


I don't see any users of the added parameter. Am I missing something?

-- 
Martin K. Petersen	Oracle Linux Engineering
Daejun Park March 19, 2021, 2:51 a.m. UTC | #3
Hi Martin

> 

>Daejun,

> 

>> Unlike other query APIs in UFS, ufshcd_query_flag has a fixed selector

>> as 0. This patch allows ufshcd_query_flag API to choose selector value

>> by parameter.

> 

>I don't see any users of the added parameter. Am I missing something?


The JEDEC standard describes it as follows:
The selector field may be needed to further identify a particular element of a flag.

Other cannot used it because it is fixed as zero in the API.

Thanks,
Daejun

The selector field may be needed to further identify a particular element of a flag. Selector field is not
2218 used in this version of the standard and its value shall be zero.
> 

>-- 

>Martin K. Petersen        Oracle Linux Engineering

> 

> 

>
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c
index acc54f530f2d..606b058a3394 100644
--- a/drivers/scsi/ufs/ufs-sysfs.c
+++ b/drivers/scsi/ufs/ufs-sysfs.c
@@ -746,7 +746,7 @@  static ssize_t _name##_show(struct device *dev,				\
 		index = ufshcd_wb_get_query_index(hba);			\
 	pm_runtime_get_sync(hba->dev);					\
 	ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,	\
-		QUERY_FLAG_IDN##_uname, index, &flag);			\
+		QUERY_FLAG_IDN##_uname, index, &flag, 0);		\
 	pm_runtime_put_sync(hba->dev);					\
 	if (ret) {							\
 		ret = -EINVAL;						\
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 8c0ff024231c..c2fd9c58d6b8 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -2940,13 +2940,15 @@  static inline void ufshcd_init_query(struct ufs_hba *hba,
 }
 
 static int ufshcd_query_flag_retry(struct ufs_hba *hba,
-	enum query_opcode opcode, enum flag_idn idn, u8 index, bool *flag_res)
+	enum query_opcode opcode, enum flag_idn idn, u8 index, bool *flag_res,
+	u8 selector)
 {
 	int ret;
 	int retries;
 
 	for (retries = 0; retries < QUERY_REQ_RETRIES; retries++) {
-		ret = ufshcd_query_flag(hba, opcode, idn, index, flag_res);
+		ret = ufshcd_query_flag(hba, opcode, idn, index, flag_res,
+					selector);
 		if (ret)
 			dev_dbg(hba->dev,
 				"%s: failed with error %d, retries %d\n",
@@ -2969,15 +2971,17 @@  static int ufshcd_query_flag_retry(struct ufs_hba *hba,
  * @idn: flag idn to access
  * @index: flag index to access
  * @flag_res: the flag value after the query request completes
+ * @selector: selector field
  *
  * Returns 0 for success, non-zero in case of failure
  */
 int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
-			enum flag_idn idn, u8 index, bool *flag_res)
+			enum flag_idn idn, u8 index, bool *flag_res,
+			u8 selector)
 {
 	struct ufs_query_req *request = NULL;
 	struct ufs_query_res *response = NULL;
-	int err, selector = 0;
+	int err;
 	int timeout = QUERY_REQ_TIMEOUT;
 
 	BUG_ON(!hba);
@@ -4331,7 +4335,7 @@  static int ufshcd_complete_dev_init(struct ufs_hba *hba)
 	ktime_t timeout;
 
 	err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,
-		QUERY_FLAG_IDN_FDEVICEINIT, 0, NULL);
+		QUERY_FLAG_IDN_FDEVICEINIT, 0, NULL, 0);
 	if (err) {
 		dev_err(hba->dev,
 			"%s setting fDeviceInit flag failed with error %d\n",
@@ -4343,7 +4347,8 @@  static int ufshcd_complete_dev_init(struct ufs_hba *hba)
 	timeout = ktime_add_ms(ktime_get(), FDEVICEINIT_COMPL_TIMEOUT);
 	do {
 		err = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,
-					QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res);
+					QUERY_FLAG_IDN_FDEVICEINIT, 0, &flag_res,
+					0);
 		if (!flag_res)
 			break;
 		usleep_range(5000, 10000);
@@ -5250,7 +5255,7 @@  static int ufshcd_enable_auto_bkops(struct ufs_hba *hba)
 		goto out;
 
 	err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_SET_FLAG,
-			QUERY_FLAG_IDN_BKOPS_EN, 0, NULL);
+			QUERY_FLAG_IDN_BKOPS_EN, 0, NULL, 0);
 	if (err) {
 		dev_err(hba->dev, "%s: failed to enable bkops %d\n",
 				__func__, err);
@@ -5300,7 +5305,7 @@  static int ufshcd_disable_auto_bkops(struct ufs_hba *hba)
 	}
 
 	err = ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_CLEAR_FLAG,
-			QUERY_FLAG_IDN_BKOPS_EN, 0, NULL);
+			QUERY_FLAG_IDN_BKOPS_EN, 0, NULL, 0);
 	if (err) {
 		dev_err(hba->dev, "%s: failed to disable bkops %d\n",
 				__func__, err);
@@ -5463,7 +5468,7 @@  int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable)
 
 	index = ufshcd_wb_get_query_index(hba);
 	ret = ufshcd_query_flag_retry(hba, opcode,
-				      QUERY_FLAG_IDN_WB_EN, index, NULL);
+				      QUERY_FLAG_IDN_WB_EN, index, NULL, 0);
 	if (ret) {
 		dev_err(hba->dev, "%s write booster %s failed %d\n",
 			__func__, enable ? "enable" : "disable", ret);
@@ -5490,7 +5495,7 @@  static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set)
 	index = ufshcd_wb_get_query_index(hba);
 	return ufshcd_query_flag_retry(hba, val,
 				QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8,
-				index, NULL);
+				index, NULL, 0);
 }
 
 static inline int ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable)
@@ -5511,7 +5516,7 @@  static inline int ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable)
 	index = ufshcd_wb_get_query_index(hba);
 	ret = ufshcd_query_flag_retry(hba, opcode,
 				      QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN, index,
-				      NULL);
+				      NULL, 0);
 	if (ret) {
 		dev_err(hba->dev, "%s WB-Buf Flush %s failed %d\n", __func__,
 			enable ? "enable" : "disable", ret);
@@ -7751,7 +7756,7 @@  static int ufshcd_device_params_init(struct ufs_hba *hba)
 	ufshcd_get_ref_clk_gating_wait(hba);
 
 	if (!ufshcd_query_flag_retry(hba, UPIU_QUERY_OPCODE_READ_FLAG,
-			QUERY_FLAG_IDN_PWR_ON_WPE, 0, &flag))
+			QUERY_FLAG_IDN_PWR_ON_WPE, 0, &flag, 0))
 		hba->dev_info.f_power_on_wp_en = flag;
 
 	/* Probe maximum power mode co-supported by both UFS host and device */
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 1af91661dc83..67a26b2be36f 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -1077,7 +1077,7 @@  int ufshcd_read_desc_param(struct ufs_hba *hba,
 int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
 		      enum attr_idn idn, u8 index, u8 selector, u32 *attr_val);
 int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
-	enum flag_idn idn, u8 index, bool *flag_res);
+	enum flag_idn idn, u8 index, bool *flag_res, u8 selector);
 
 void ufshcd_auto_hibern8_enable(struct ufs_hba *hba);
 void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);