From d44a5f98bb49b2c15348fa65cee73df4a157bfbf Mon Sep 17 00:00:00 2001 From: Dolev Raviv Date: Sun, 29 Jun 2014 09:40:17 +0300 Subject: 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. Signed-off-by: Dolev Raviv Signed-off-by: Raviv Shvili Acked-by: Santosh Y Signed-off-by: Christoph Hellwig --- drivers/scsi/ufs/ufs.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'drivers/scsi/ufs/ufs.h') diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index f42d1cee652a..1545cd7877d0 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -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, -- cgit v1.2.3 From 1b3e89563119f1e0422230915dcaf23a262628b7 Mon Sep 17 00:00:00 2001 From: Dolev Raviv Date: Sun, 29 Jun 2014 09:40:19 +0300 Subject: ufs: Logical Unit (LU) command queue depth Some 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 the queue depth available per LU is read and updated in the LU's SW structure. Signed-off-by: Dolev Raviv Signed-off-by: Raviv Shvili Acked-by: Santosh Y Signed-off-by: Christoph Hellwig --- drivers/scsi/ufs/ufs.h | 21 +++++++++++++++++++++ drivers/scsi/ufs/ufshcd.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) (limited to 'drivers/scsi/ufs/ufs.h') diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index 1545cd7877d0..fafcf5e354c6 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -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, diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index f3768ec25c2f..b301ed82ab0a 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -110,6 +110,8 @@ static void ufshcd_tmc_handler(struct ufs_hba *hba); static void ufshcd_async_scan(void *data, async_cookie_t cookie); static int ufshcd_reset_and_restore(struct ufs_hba *hba); static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag); +static int ufshcd_read_sdev_qdepth(struct ufs_hba *hba, + struct scsi_device *sdev); /* * ufshcd_wait_for_register - wait for register value to change @@ -1978,6 +1980,7 @@ static int ufshcd_verify_dev_init(struct ufs_hba *hba) static int ufshcd_slave_alloc(struct scsi_device *sdev) { struct ufs_hba *hba; + int lun_qdepth; hba = shost_priv(sdev->host); sdev->tagged_supported = 1; @@ -1988,6 +1991,14 @@ 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); + lun_qdepth = hba->nutrs; + } else if (lun_qdepth < 0) { + lun_qdepth = 1; + } /* * Inform SCSI Midlayer that the LUN queue depth is same as the @@ -1996,7 +2007,7 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev) * SAM_STAT_TASK_SET_FULL, the LUN queue depth will be adjusted * with scsi_adjust_queue_depth. */ - scsi_activate_tcq(sdev, hba->nutrs); + scsi_activate_tcq(sdev, lun_qdepth); return 0; } @@ -3070,6 +3081,38 @@ static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd) return err; } +/** + * ufshcd_read_sdev_qdepth - read the lun command queue depth + * @hba: Pointer to adapter instance + * @sdev: pointer to SCSI device + * + * Return in case of success the lun's queue depth else error. + */ +static int ufshcd_read_sdev_qdepth(struct ufs_hba *hba, + struct scsi_device *sdev) +{ + int ret; + int buff_len = UNIT_DESC_MAX_SIZE; + u8 desc_buf[UNIT_DESC_MAX_SIZE]; + + ret = ufshcd_query_descriptor(hba, UPIU_QUERY_OPCODE_READ_DESC, + QUERY_DESC_IDN_UNIT, sdev->lun, 0, desc_buf, &buff_len); + + if (ret || (buff_len < UNIT_DESC_PARAM_LU_Q_DEPTH)) { + dev_err(hba->dev, + "%s:Failed reading unit descriptor. len = %d ret = %d" + , __func__, buff_len, ret); + if (!ret) + ret = -EINVAL; + + goto out; + } + + ret = desc_buf[UNIT_DESC_PARAM_LU_Q_DEPTH] & 0xFF; +out: + return ret; +} + /** * ufshcd_async_scan - asynchronous execution for link startup * @data: data pointer to pass to this function -- cgit v1.2.3