Re: [PATCH v3 2/5] [SCSI] ufshcd: UFS UTP Transfer requests handling

2012-04-10 Thread Venkatraman S
On 26 March 2012 10:04, KOBAYASHI Yoshitake
yoshitake.kobaya...@toshiba.co.jp wrote:
 Santosh Y wrote:

 +        ucd_cmd_ptr-exp_data_transfer_len =
 +            cpu_to_be32(lrbp-cmd-transfersize);
 +
 +        memcpy(ucd_cmd_ptr-cdb,
 +               lrbp-cmd-cmnd,
 +               (min_t(unsigned short,
 +                  lrbp-cmd-cmd_len,
 +                  MAX_CDB_SIZE)));


 Exptected Data Transfer Length field contains a value that
 represents the number of bytes that are required to complete the
 SCSI command request and the number of bytes that the Initiator
 expects to be transferred to/from the Target.
 (JEDEC Standard 220 Table7-7)
 On the other hand, transfersize in a scsi_cmnd struct is trimmed
 to the sector size when requested transfer length exceeds it.
 You may derive the actual transfer length from SCSI command itself like
 following.
Hi,
  Can you please send signed-off patches for the two issues that you reported ?
I would like to use them on my development tree.

Thanks and regards,
Venkat.


 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
 index feffe65..e63fecb 100644
 --- a/drivers/scsi/ufs/ufshcd.c
 +++ b/drivers/scsi/ufs/ufshcd.c
 @@ -647,6 +647,34 @@ static void ufshcd_compose_upiu(struct ufshcd_lrb
 *lrbp)
                       (min_t(unsigned short,
                              lrbp-cmd-cmd_len,
                              MAX_CDB_SIZE)));
 +
 +               /* Overwrite exptected transfer length by using
 TRANSFER_LENGTH in SCSI commands */
 +               switch(ucd_cmd_ptr-cdb[0]) {
 +               case READ_6:
 +               case WRITE_6:
 +                       ucd_cmd_ptr-exp_data_transfer_len =
 +                               cpu_to_be32(lrbp-cmd-transfersize *
 +                                           ucd_cmd_ptr-cdb[4]);
 +                       break;
 +               case READ_10:
 +               case WRITE_10:
 +                       ucd_cmd_ptr-exp_data_transfer_len =
 +                               cpu_to_be32(lrbp-cmd-transfersize *
 +                                           ((ucd_cmd_ptr-cdb[7]  8) |
 +                                            ucd_cmd_ptr-cdb[8]));
 +                       break;
 +               case READ_12:
 +               case WRITE_12:
 +                       ucd_cmd_ptr-exp_data_transfer_len =
 +                               cpu_to_be32(lrbp-cmd-transfersize *
 +                                           ((ucd_cmd_ptr-cdb[10]  24) |
 +                                            (ucd_cmd_ptr-cdb[11]  16) |
 +                                            (ucd_cmd_ptr-cdb[12]  8) |
 +                                            ucd_cmd_ptr-cdb[13]));
 +                       break;
 +               default:
 +                       break;
 +               }
                break;
        case UTP_CMD_TYPE_DEV_MANAGE:

                /* For query function implementation */

--
To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/5] [SCSI] ufshcd: UFS UTP Transfer requests handling

2012-03-28 Thread KOBAYASHI Yoshitake

Santosh Y wrote:

+   case READ_12:
+   case WRITE_12:


Just a minor change, this will be READ_16 and WRITE_16.


Thanks. Your feedback will be correct.
--
To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/5] [SCSI] ufshcd: UFS UTP Transfer requests handling

2012-03-26 Thread Santosh Y
On Mon, Mar 26, 2012 at 10:04 AM, KOBAYASHI Yoshitake
yoshitake.kobaya...@toshiba.co.jp wrote:
 Santosh Y wrote:

 +        ucd_cmd_ptr-exp_data_transfer_len =
 +            cpu_to_be32(lrbp-cmd-transfersize);
 +
 +        memcpy(ucd_cmd_ptr-cdb,
 +               lrbp-cmd-cmnd,
 +               (min_t(unsigned short,
 +                  lrbp-cmd-cmd_len,
 +                  MAX_CDB_SIZE)));


 Exptected Data Transfer Length field contains a value that
 represents the number of bytes that are required to complete the
 SCSI command request and the number of bytes that the Initiator
 expects to be transferred to/from the Target.
 (JEDEC Standard 220 Table7-7)
 On the other hand, transfersize in a scsi_cmnd struct is trimmed
 to the sector size when requested transfer length exceeds it.
 You may derive the actual transfer length from SCSI command itself like
 following.

 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
 index feffe65..e63fecb 100644
 --- a/drivers/scsi/ufs/ufshcd.c
 +++ b/drivers/scsi/ufs/ufshcd.c
 @@ -647,6 +647,34 @@ static void ufshcd_compose_upiu(struct ufshcd_lrb
 *lrbp)
                       (min_t(unsigned short,
                              lrbp-cmd-cmd_len,
                              MAX_CDB_SIZE)));
 +
 +               /* Overwrite exptected transfer length by using
 TRANSFER_LENGTH in SCSI commands */
 +               switch(ucd_cmd_ptr-cdb[0]) {
 +               case READ_6:
 +               case WRITE_6:
 +                       ucd_cmd_ptr-exp_data_transfer_len =
 +                               cpu_to_be32(lrbp-cmd-transfersize *
 +                                           ucd_cmd_ptr-cdb[4]);
 +                       break;
 +               case READ_10:
 +               case WRITE_10:
 +                       ucd_cmd_ptr-exp_data_transfer_len =
 +                               cpu_to_be32(lrbp-cmd-transfersize *
 +                                           ((ucd_cmd_ptr-cdb[7]  8) |
 +                                            ucd_cmd_ptr-cdb[8]));
 +                       break;
 +               case READ_12:
 +               case WRITE_12:
 +                       ucd_cmd_ptr-exp_data_transfer_len =
 +                               cpu_to_be32(lrbp-cmd-transfersize *
 +                                           ((ucd_cmd_ptr-cdb[10]  24) |
 +                                            (ucd_cmd_ptr-cdb[11]  16) |
 +                                            (ucd_cmd_ptr-cdb[12]  8) |
 +                                            ucd_cmd_ptr-cdb[13]));
 +                       break;
 +               default:
 +                       break;
 +               }
                break;
        case UTP_CMD_TYPE_DEV_MANAGE:

                /* For query function implementation */


Thanks, will incorporate the changes accordingly.

-- 
~Santosh
--
To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/5] [SCSI] ufshcd: UFS UTP Transfer requests handling

2012-03-26 Thread Santosh Y
On Mon, Mar 26, 2012 at 10:04 AM, KOBAYASHI Yoshitake
yoshitake.kobaya...@toshiba.co.jp wrote:
 Santosh Y wrote:

 +        ucd_cmd_ptr-exp_data_transfer_len =
 +            cpu_to_be32(lrbp-cmd-transfersize);
 +
 +        memcpy(ucd_cmd_ptr-cdb,
 +               lrbp-cmd-cmnd,
 +               (min_t(unsigned short,
 +                  lrbp-cmd-cmd_len,
 +                  MAX_CDB_SIZE)));


 Exptected Data Transfer Length field contains a value that
 represents the number of bytes that are required to complete the
 SCSI command request and the number of bytes that the Initiator
 expects to be transferred to/from the Target.
 (JEDEC Standard 220 Table7-7)
 On the other hand, transfersize in a scsi_cmnd struct is trimmed
 to the sector size when requested transfer length exceeds it.
 You may derive the actual transfer length from SCSI command itself like
 following.

 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
 index feffe65..e63fecb 100644
 --- a/drivers/scsi/ufs/ufshcd.c
 +++ b/drivers/scsi/ufs/ufshcd.c
 @@ -647,6 +647,34 @@ static void ufshcd_compose_upiu(struct ufshcd_lrb
 *lrbp)
                       (min_t(unsigned short,
                              lrbp-cmd-cmd_len,
                              MAX_CDB_SIZE)));
 +
 +               /* Overwrite exptected transfer length by using
 TRANSFER_LENGTH in SCSI commands */
 +               switch(ucd_cmd_ptr-cdb[0]) {
 +               case READ_6:
 +               case WRITE_6:
 +                       ucd_cmd_ptr-exp_data_transfer_len =
 +                               cpu_to_be32(lrbp-cmd-transfersize *
 +                                           ucd_cmd_ptr-cdb[4]);
 +                       break;
 +               case READ_10:
 +               case WRITE_10:
 +                       ucd_cmd_ptr-exp_data_transfer_len =
 +                               cpu_to_be32(lrbp-cmd-transfersize *
 +                                           ((ucd_cmd_ptr-cdb[7]  8) |
 +                                            ucd_cmd_ptr-cdb[8]));
 +                       break;
 +               case READ_12:
 +               case WRITE_12:

Just a minor change, this will be READ_16 and WRITE_16.

 +                       ucd_cmd_ptr-exp_data_transfer_len =
 +                               cpu_to_be32(lrbp-cmd-transfersize *
 +                                           ((ucd_cmd_ptr-cdb[10]  24) |
 +                                            (ucd_cmd_ptr-cdb[11]  16) |
 +                                            (ucd_cmd_ptr-cdb[12]  8) |
 +                                            ucd_cmd_ptr-cdb[13]));
 +                       break;
 +               default:
 +                       break;
 +               }
                break;
        case UTP_CMD_TYPE_DEV_MANAGE:

                /* For query function implementation */


-- 
~Santosh
--
To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/5] [SCSI] ufshcd: UFS UTP Transfer requests handling

2012-03-25 Thread KOBAYASHI Yoshitake

Santosh Y wrote:

+ucd_cmd_ptr-exp_data_transfer_len =
+cpu_to_be32(lrbp-cmd-transfersize);
+
+memcpy(ucd_cmd_ptr-cdb,
+   lrbp-cmd-cmnd,
+   (min_t(unsigned short,
+  lrbp-cmd-cmd_len,
+  MAX_CDB_SIZE)));


Exptected Data Transfer Length field contains a value that
represents the number of bytes that are required to complete the
SCSI command request and the number of bytes that the Initiator
expects to be transferred to/from the Target.
(JEDEC Standard 220 Table7-7)
On the other hand, transfersize in a scsi_cmnd struct is trimmed
to the sector size when requested transfer length exceeds it.
You may derive the actual transfer length from SCSI command itself like 
following.

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index feffe65..e63fecb 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -647,6 +647,34 @@ static void ufshcd_compose_upiu(struct ufshcd_lrb *lrbp)
   (min_t(unsigned short,
  lrbp-cmd-cmd_len,
  MAX_CDB_SIZE)));
+
+   /* Overwrite exptected transfer length by using TRANSFER_LENGTH 
in SCSI commands */
+   switch(ucd_cmd_ptr-cdb[0]) {
+   case READ_6:
+   case WRITE_6:
+   ucd_cmd_ptr-exp_data_transfer_len =
+   cpu_to_be32(lrbp-cmd-transfersize *
+   ucd_cmd_ptr-cdb[4]);
+   break;
+   case READ_10:
+   case WRITE_10:
+   ucd_cmd_ptr-exp_data_transfer_len =
+   cpu_to_be32(lrbp-cmd-transfersize *
+   ((ucd_cmd_ptr-cdb[7]  8) |
+ucd_cmd_ptr-cdb[8]));
+   break;
+   case READ_12:
+   case WRITE_12:
+   ucd_cmd_ptr-exp_data_transfer_len =
+   cpu_to_be32(lrbp-cmd-transfersize *
+   ((ucd_cmd_ptr-cdb[10]  24) |
+(ucd_cmd_ptr-cdb[11]  16) |
+(ucd_cmd_ptr-cdb[12]  8) |
+ucd_cmd_ptr-cdb[13]));
+   break;
+   default:
+   break;
+   }
break;
case UTP_CMD_TYPE_DEV_MANAGE:
/* For query function implementation */

--
To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/5] [SCSI] ufshcd: UFS UTP Transfer requests handling

2012-02-28 Thread Santosh Y
From: Santosh Yaraganavi santos...@gmail.com

This patch adds support for Transfer request handling.

ufshcd includes following implementations:
 - SCSI queuecommand
 - Compose UPIU(UFS Protocol information unit)
 - Issue commands to UFS host controller
 - Handle completed commands

Signed-off-by: Santosh Yaraganavi santos...@gmail.com
Signed-off-by: Vinayak Holikatti vinholika...@gmail.com
Reviewed-by: Arnd Bergmann a...@linaro.org
Reviewed-by: Vishak G visha...@samsung.com
Reviewed-by: Girish K S girish.shivananja...@linaro.org
Reviewed-by: Namjae Jeon linkinj...@gmail.com
---
v2 - v3:
- use shost_priv() instead of accessing hostdata directly.
- update SCSI command result with appropriate byte codes.
v1 - v2:
- Use bitops.h defined functions to perform bit operations.
  Ex: set_bit(), __set_bit, clear_bit...
- ufshcd_map_sg(): remove BUG_ON on scsi_dma_map() failure
  and return error value.
- ufshcd_compose_upiu(): add missing break in switch case,
  remove unused parameter hba.
- ufshcd_slave_alloc(): set sdev-use_10_for_ms = 1, since UFS
  does not support MODE_SENSE_6.
- ufshcd_scsi_cmd_status(): add missing break in switch case.
  Add ufshcd_adjust_lun_qdepth to adjust LUN queue depth
  if SAM_STAT_TASK_SET_FULL is received from the device.
- ufshcd_transfer_rsp_status(): combine cases with same error code.

 drivers/scsi/ufs/ufshcd.c |  494 +
 1 files changed, 494 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 26b16c1..43b9c62 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -63,6 +63,7 @@
 #include scsi/scsi.h
 #include scsi/scsi_cmnd.h
 #include scsi/scsi_host.h
+#include scsi/scsi_tcq.h
 #include scsi/scsi_dbg.h
 
 #include ufs.h
@@ -75,6 +76,8 @@ enum {
UFSHCD_MAX_CHANNEL  = 0,
UFSHCD_MAX_ID   = 1,
UFSHCD_MAX_LUNS = 8,
+   UFSHCD_CMD_PER_LUN  = 32,
+   UFSHCD_CAN_QUEUE= 32,
 };
 
 /* UFSHCD states */
@@ -127,6 +130,7 @@ struct uic_command {
  * @host: Scsi_Host instance of the driver
  * @pdev: PCI device handle
  * @lrb: local reference block
+ * @outstanding_reqs: Bits representing outstanding transfer requests
  * @capabilities: UFS Controller Capabilities
  * @nutrs: Transfer Request Queue depth supported by controller
  * @nutmrs: Task Management Queue depth supported by controller
@@ -153,6 +157,8 @@ struct ufs_hba {
 
struct ufshcd_lrb *lrb;
 
+   unsigned long outstanding_reqs;
+
u32 capabilities;
int nutrs;
int nutmrs;
@@ -173,12 +179,28 @@ struct ufs_hba {
  * @ucd_cmd_ptr: UCD address of the command
  * @ucd_rsp_ptr: Response UPIU address for this command
  * @ucd_prdt_ptr: PRDT address of the command
+ * @cmd: pointer to SCSI command
+ * @sense_buffer: pointer to sense buffer address of the SCSI command
+ * @sense_bufflen: Length of the sense buffer
+ * @scsi_status: SCSI status of the command
+ * @command_type: SCSI, UFS, Query.
+ * @task_tag: Task tag of the command
+ * @lun: LUN of the command
  */
 struct ufshcd_lrb {
struct utp_transfer_req_desc *utr_descriptor_ptr;
struct utp_upiu_cmd *ucd_cmd_ptr;
struct utp_upiu_rsp *ucd_rsp_ptr;
struct ufshcd_sg_entry *ucd_prdt_ptr;
+
+   struct scsi_cmnd *cmd;
+   u8 *sense_buffer;
+   unsigned int sense_bufflen;
+   int scsi_status;
+
+   int command_type;
+   int task_tag;
+   unsigned int lun;
 };
 
 /**
@@ -205,6 +227,18 @@ static inline int ufshcd_is_device_present(u32 reg_hcs)
 }
 
 /**
+ * ufshcd_get_tr_ocs - Get the UTRD Overall Command Status
+ * @lrb: pointer to local command reference block
+ *
+ * This function is used to get the OCS field from UTRD
+ * Returns the OCS field in the UTRD
+ */
+static inline int ufshcd_get_tr_ocs(struct ufshcd_lrb *lrbp)
+{
+   return lrbp-utr_descriptor_ptr-header.dword_2  MASK_OCS;
+}
+
+/**
  * ufshcd_get_lists_status - Check UCRDY, UTRLRDY and UTMRLRDY
  * @reg: Register value of host controller status
  *
@@ -272,6 +306,34 @@ static inline void ufshcd_free_hba_memory(struct ufs_hba 
*hba)
 }
 
 /**
+ * ufshcd_is_valid_req_rsp - checks if controller TR response is valid
+ * @ucd_rsp_ptr: pointer to response UPIU
+ *
+ * This function checks the response UPIU for valid transaction type in
+ * response field
+ * Returns 0 on success, non-zero on failure
+ */
+static inline int
+ufshcd_is_valid_req_rsp(struct utp_upiu_rsp *ucd_rsp_ptr)
+{
+   return ((be32_to_cpu(ucd_rsp_ptr-header.dword_0)  24) ==
+UPIU_TRANSACTION_RESPONSE) ? 0 : DID_ERROR  16;
+}
+
+/**
+ * ufshcd_get_rsp_upiu_result - Get the result from response UPIU
+ * @ucd_rsp_ptr: pointer to response UPIU
+ *
+ * This function gets the response status and scsi_status from response UPIU
+ * Returns the response result