scsi: ufs: LU queue depth management
Subsystems (2)
v2 cover scsi: ufs: LU queue depth management
New version to fix multiple 'sparse' warnings.
Add a driver wide fix to the endian 'sparse' warnings.
Some UFS devices don't support a LUN queue depth same as the device queue depth. This requires reading the unit descriptor for extracting the LU's queue depth.
Changes from V1:
- Add static modifier to ufshcd_query_descriptor function due to 'sparse' warrning in [PATCH V1 1/4]
- Add new patch [PATCH V2 2/5] to deal with 'sparse' endian warnings
- Fix buf_len endian on [PATCH V1 2/4]
Dolev Raviv (1):
scsi: ufs: device query status and size check
scsi: ufs: query descriptor API
scsi: ufs: Logical Unit (LU) command queue depth
Sujit Reddy Thumma (2):
scsi: ufs: fix endianness sparse warnings
scsi: ufs: Fix queue depth handling for best effort cases
drivers/scsi/ufs/ufs.h | 38 +++++- drivers/scsi/ufs/ufshcd.c | 319 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 262 insertions(+), 95 deletions(-)
Signature · 1 line
1.8.5.2
PATCH v2 1/5 scsi: ufs: query descriptor API
Introduces the API for sending queries with descriptors.
A descriptor is a block or page of parameters that describe the device. The descriptors are classified into types and can range in size from 2 bytes through 255 bytes.
All descriptors have a length value as their first element, and a type identification element as their second byte.
All descriptors are readable and some may be write once. They are accessed using their type, index and selector.
--- drivers/scsi/ufs/ufs.h | 17 +++++- drivers/scsi/ufs/ufshcd.c | 139 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 128 insertions(+), 28 deletions(-)
drivers/scsi/ufs/ufs.h +16 -1
@@ -41,7 +41,8 @@#define MAX_CDB_SIZE 16#define GENERAL_UPIU_REQUEST_SIZE 32 -#define QUERY_DESC_MAX_SIZE 256 +#define QUERY_DESC_MAX_SIZE 255 +#define QUERY_DESC_MIN_SIZE 2#define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \ (sizeof(struct utp_upiu_header)))
@@ -117,6 +118,20 @@ enum attr_idn { QUERY_ATTR_IDN_EE_STATUS = 0x0E, }; +/* Descriptor idn for Query requests */ +enum desc_idn { +QUERY_DESC_IDN_DEVICE =0x0 , +QUERY_DESC_IDN_CONFIGURAION =0x1 , +QUERY_DESC_IDN_UNIT =0x2 , +QUERY_DESC_IDN_RFU_0 =0x3 , +QUERY_DESC_IDN_INTERCONNECT =0x4 , +QUERY_DESC_IDN_STRING =0x5 , +QUERY_DESC_IDN_RFU_1 =0x6 , +QUERY_DESC_IDN_GEOMETRY =0x7 , +QUERY_DESC_IDN_POWER =0x8 , +QUERY_DESC_IDN_RFU_2 =0x9 , +}; +/* Exception event mask values */ enum {MASK_EE_STATUS =0xFFFF ,
drivers/scsi/ufs/ufshcd.c +112 -27
192 lines not on this page · raw message
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/5 scsi: ufs: fix endianness sparse warnings
In reply to Dolev RavivFrom: Sujit Reddy Thumma <[email protected]>
Fix many warnings with incorrect endian assumptions which makes the code unportable to new architectures.
The UFS specification defines the byte order as big-endian for UPIU structure and little-endian for the host controller transfer/task management descriptors.
--- drivers/scsi/ufs/ufshcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/ufs/ufshcd.c +2 -2
@@ -1325,7 +1325,7 @@ static int ufshcd_query_descriptor(struct ufs_hba *hba,ufshcd_init_query (hba, &request, &response, opcode, idn, index, selector); hba->dev_cmd.query.descriptor = desc_buf; - request->upiu_req.length = *buf_len; + request->upiu_req.length =cpu_to_be16 (*buf_len);switch (opcode) {case UPIU_QUERY_OPCODE_WRITE_DESC :
@@ -1351,7 +1351,7 @@ static int ufshcd_query_descriptor(struct ufs_hba *hba, } hba->dev_cmd.query.descriptor =NULL ; - *buf_len = response->upiu_res.length; + *buf_len =be16_to_cpu (response->upiu_res.length); out_unlock:mutex_unlock (&hba->dev_cmd.lock);
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 3/5 scsi: ufs: device query status and size check
In reply to Dolev RavivCheck query response status before copying the response. Add descriptor query response size check, before copying it to buffer.
--- drivers/scsi/ufs/ufshcd.c | 50 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-)
drivers/scsi/ufs/ufshcd.c +33 -17
@@ -446,30 +446,35 @@ static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp)* @lrb - pointer to local reference block */ static -void ufshcd_copy_query_response (struct ufs_hba *hba,struct ufshcd_lrb *lrbp) +int ufshcd_copy_query_response (struct ufs_hba *hba,struct ufshcd_lrb *lrbp) {struct ufs_query_res *query_res = &hba->dev_cmd.query.response; -/* Get the UPIU response */ - query_res->response =ufshcd_get_rsp_upiu_result (lrbp->ucd_rsp_ptr) >> -UPIU_RSP_CODE_OFFSET ; -memcpy (&query_res->upiu_res, &lrbp->ucd_rsp_ptr->qr,QUERY_OSF_SIZE ); -/* Get the descriptor */ if (lrbp->ucd_rsp_ptr->qr.opcode ==UPIU_QUERY_OPCODE_READ_DESC ) {u8 *descp = (u8 *)lrbp->ucd_rsp_ptr +GENERAL_UPIU_REQUEST_SIZE ; -u16 len; +u16 resp_len; +u16 buf_len;/* data segment length */ - len =be32_to_cpu (lrbp->ucd_rsp_ptr->header.dword_2) & + resp_len =be32_to_cpu (lrbp->ucd_rsp_ptr->header.dword_2) &MASK_QUERY_DATA_SEG_LEN ; - -memcpy (hba->dev_cmd.query.descriptor, descp, -min_t (u16, len,QUERY_DESC_MAX_SIZE )); + buf_len =be16_to_cpu ( + hba->dev_cmd.query.request.upiu_req.length); +if (likely (buf_len >= resp_len)) { +memcpy (hba->dev_cmd.query.descriptor, descp, resp_len); + }else { +dev_warn (hba->dev, +"%s: Response size is bigger than buffer" , + __func__); +return -EINVAL ; + } } + +return 0 ; }/**
@@ -797,11 +802,9 @@ static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba, QUERY_OSF_SIZE);/* Copy the Descriptor */ -if ((len >0 ) && (query->request.upiu_req.opcode == -UPIU_QUERY_OPCODE_WRITE_DESC )) { -memcpy (descp, query->descriptor, -min_t (u16, len,QUERY_DESC_MAX_SIZE )); - } +if (query->request.upiu_req.opcode ==UPIU_QUERY_OPCODE_WRITE_DESC ) +memcpy (descp, query->descriptor, len); + }static inline void ufshcd_prepare_utp_nop_upiu (struct ufshcd_lrb *lrbp)
@@ -980,6 +983,17 @@ ufshcd_clear_cmd(struct ufs_hba *hba, int tag)return err; } +static int +ufshcd_check_query_response (struct ufs_hba *hba,struct ufshcd_lrb *lrbp) +{ +struct ufs_query_res *query_res = &hba->dev_cmd.query.response; + +/* Get the UPIU response */ + query_res->response =ufshcd_get_rsp_upiu_result (lrbp->ucd_rsp_ptr) >> +UPIU_RSP_CODE_OFFSET ; +return query_res->response; +} +/** * ufshcd_dev_cmd_completion() - handles device management command responses * @hba: per adapter instance
@@ -1002,7 +1016,9 @@ ufshcd_dev_cmd_completion(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) }break ;case UPIU_TRANSACTION_QUERY_RSP : -ufshcd_copy_query_response (hba, lrbp); + err =ufshcd_check_query_response (hba, lrbp); +if (!err) + err =ufshcd_copy_query_response (hba, lrbp);break ;case UPIU_TRANSACTION_REJECT_UPIU :/* TODO: handle Reject UPIU Response */
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 4/5 scsi: ufs: Logical Unit (LU) command queue depth
In reply to Dolev RavivSome of the UFS devices may support different number of commands that can be queued per LU. At the current implementation, SW configure each of the UFS devices LU's according to the controller capability.
In this patch we read the queue depth available per LU and update the LU's SW structure.
--- drivers/scsi/ufs/ufs.h | 21 +++++++++++++++++++++ drivers/scsi/ufs/ufshcd.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-)
drivers/scsi/ufs/ufs.h +21 -0
@@ -132,6 +132,27 @@ enum desc_idn { QUERY_DESC_IDN_RFU_2 = 0x9, }; +#define UNIT_DESC_MAX_SIZE 0x22 +/* Unit descriptor parameters offsets in bytes*/ +enum unit_desc_param { +UNIT_DESC_PARAM_LEN =0x0 , +UNIT_DESC_PARAM_TYPE =0x1 , +UNIT_DESC_PARAM_UNIT_INDEX =0x2 , +UNIT_DESC_PARAM_LU_ENABLE =0x3 , +UNIT_DESC_PARAM_BOOT_LUN_ID =0x4 , +UNIT_DESC_PARAM_LU_WR_PROTECT =0x5 , +UNIT_DESC_PARAM_LU_Q_DEPTH =0x6 , +UNIT_DESC_PARAM_MEM_TYPE =0x8 , +UNIT_DESC_PARAM_DATA_RELIABILITY =0x9 , +UNIT_DESC_PARAM_LOGICAL_BLK_SIZE =0xA , +UNIT_DESC_PARAM_LOGICAL_BLK_COUNT =0xB , +UNIT_DESC_PARAM_ERASE_BLK_SIZE =0x13 , +UNIT_DESC_PARAM_PROVISIONING_TYPE =0x17 , +UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT =0x18 , +UNIT_DESC_PARAM_CTX_CAPABILITIES =0x20 , +UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1 =0x22 , +}; +/* Exception event mask values */ enum {MASK_EE_STATUS =0xFFFF ,
drivers/scsi/ufs/ufshcd.c +44 -1
75 lines not on this page · raw message
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 5/5 scsi: ufs: Fix queue depth handling for best effort cases
In reply to Dolev RavivFrom: Sujit Reddy Thumma <[email protected]>
Some UFS devices may expose bLUQueueDepth field as zero indicating that the queue depth depends on the number of resources available for LUN at a particular instant to handle the outstanding transfer requests. Currently, when response for SCSI command is TASK_FULL the LLD decrements the queue depth but fails to increment when the resources are available. The scsi mid-layer handles the change in queue depth heuristically and offers simple interface with ->change_queue_depth.
--- drivers/scsi/ufs/ufshcd.c | 97 ++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 55 deletions(-)
drivers/scsi/ufs/ufshcd.c +42 -55
@@ -1992,27 +1992,55 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev)/* allow SCSI layer to restart the device in case of errors */ sdev->allow_restart =1 ; + lun_qdepth =ufshcd_read_sdev_qdepth (hba, sdev); -if (lun_qdepth ==0 || lun_qdepth > hba->nutrs) { -dev_info (hba->dev,"%s, lun %d queue depth is %d\n" , __func__, - sdev->lun, lun_qdepth); +if (lun_qdepth <=0 ) +/* eventually, we can figure out the real queue depth */ lun_qdepth = hba->nutrs; - }else if (lun_qdepth <0 ) { - lun_qdepth =1 ; - } +else + lun_qdepth =min_t (int, lun_qdepth, hba->nutrs); -/* -* Inform SCSI Midlayer that the LUN queue depth is same as the -* controller queue depth. If a LUN queue depth is less than the -* controller queue depth and if the LUN reports -* SAM_STAT_TASK_SET_FULL, the LUN queue depth will be adjusted -* with scsi_adjust_queue_depth. -*/ +dev_dbg (hba->dev,"%s: activate tcq with queue depth %d\n" , + __func__, lun_qdepth);scsi_activate_tcq (sdev, lun_qdepth); +return 0 ; }/** +* ufshcd_change_queue_depth - change queue depth +* @sdev: pointer to SCSI device +* @depth: required depth to set +* @reason: reason for changing the depth +* +* Change queue depth according to the reason and make sure +* the max. limits are not crossed. +*/ +int ufshcd_change_queue_depth (struct scsi_device *sdev,int depth,int reason) +{ +struct ufs_hba *hba =shost_priv (sdev->host); + +if (depth > hba->nutrs) + depth = hba->nutrs; + +switch (reason) { +case SCSI_QDEPTH_DEFAULT : +case SCSI_QDEPTH_RAMP_UP : +if (!sdev->tagged_supported) + depth =1 ; +scsi_adjust_queue_depth (sdev,scsi_get_tag_type (sdev), depth); +break ; +case SCSI_QDEPTH_QFULL : +scsi_track_queue_full (sdev, depth); +break ; +default : +return -EOPNOTSUPP ; + } + +return depth; +} + +/** * ufshcd_slave_destroy - remove SCSI device configurations * @sdev: pointer to SCSI device */
@@ -2065,42 +2093,6 @@ static int ufshcd_task_req_compl(struct ufs_hba *hba, u32 index, u8 *resp) }/** -* ufshcd_adjust_lun_qdepth - Update LUN queue depth if device responds with -* SAM_STAT_TASK_SET_FULL SCSI command status. -* @cmd: pointer to SCSI command -*/ -static void ufshcd_adjust_lun_qdepth (struct scsi_cmnd *cmd) -{ -struct ufs_hba *hba; -int i; -int lun_qdepth =0 ; - - hba =shost_priv (cmd->device->host); - -/* -* LUN queue depth can be obtained by counting outstanding commands -* on the LUN. -*/ -for (i =0 ; i < hba->nutrs; i++) { -if (test_bit (i, &hba->outstanding_reqs)) { - -/* -* Check if the outstanding command belongs -* to the LUN which reported SAM_STAT_TASK_SET_FULL. -*/ -if (cmd->device->lun == hba->lrb[i].lun) - lun_qdepth++; - } - } - -/* -* LUN queue depth will be total outstanding commands, except the -* command for which the LUN reported SAM_STAT_TASK_SET_FULL. -*/ -scsi_adjust_queue_depth (cmd->device,MSG_SIMPLE_TAG , lun_qdepth -1 ); -} - -/** * ufshcd_scsi_cmd_status - Update SCSI command result based on SCSI status * @lrb: pointer to local reference block of completed command * @scsi_status: SCSI command status
@@ -2121,12 +2113,6 @@ ufshcd_scsi_cmd_status(struct ufshcd_lrb *lrbp, int scsi_status) scsi_status;break ;case SAM_STAT_TASK_SET_FULL : -/* -* If a LUN reports SAM_STAT_TASK_SET_FULL, then the LUN queue -* depth needs to be adjusted to the exact number of -* outstanding commands the LUN can handle at any given time. -*/ -ufshcd_adjust_lun_qdepth (lrbp->cmd);case SAM_STAT_BUSY :case SAM_STAT_TASK_ABORTED :ufshcd_copy_sense_data (lrbp);
@@ -3157,6 +3143,7 @@ static struct scsi_host_template ufshcd_driver_template = { .queuecommand = ufshcd_queuecommand, .slave_alloc = ufshcd_slave_alloc, .slave_destroy = ufshcd_slave_destroy, + .change_queue_depth = ufshcd_change_queue_depth, .eh_abort_handler = ufshcd_abort, .eh_device_reset_handler = ufshcd_eh_device_reset_handler, .eh_host_reset_handler = ufshcd_eh_host_reset_handler,
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 5 lines · Dolev Raviv
New version to fix multiple 'sparse' warnings.
Add a driver wide fix to the endian 'sparse' warnings.
Some UFS devices don't support a LUN queue depth same as the device queue depth. This requires reading the unit descriptor for extracting the LU's queue depth.
Can you please send just the sparse fixes against the tree at:
http://git.infradead.org/users/hch/scsi-queue.git/shortlog/refs/heads/drivers-for-3.17
which already has the previous version merged?