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

From: Namjae Jeon
Date: Sun Feb 05 2012 - 07:51:27 EST


2012/2/2 Vinayak Holikatti <vinholikatti@xxxxxxxxx>:
> From: Santosh Yaraganavi <santoshsy@xxxxxxxxx>
>
> 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 <santoshsy@xxxxxxxxx>
> Signed-off-by: Vinayak Holikatti <vinholikatti@xxxxxxxxx>
> Reviewed-by: Arnd Bergmann <arnd@xxxxxxxx>
> Reviewed-by: Saugata Das <saugata.das@xxxxxxxxxx>
> Reviewed-by: Vishak G <vishak.g@xxxxxxxxxxx>
> Reviewed-by: Girish K S <girish.shivananjappa@xxxxxxxxxx>
> ---
> Âdrivers/scsi/ufs/ufshcd.c | Â447 +++++++++++++++++++++++++++++++++++++++++++++
> Â1 files changed, 447 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index c82eeea..23d758b 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -62,6 +62,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"
> @@ -81,6 +82,7 @@ enum {
> Â Â Â ÂUFSHCD_MAX_CHANNEL Â Â Â= 1,
> Â Â Â ÂUFSHCD_MAX_ID Â Â Â Â Â = 1,
> Â Â Â ÂUFSHCD_MAX_LUNS Â Â Â Â = 8,
> + Â Â Â UFSHCD_CMD_PER_LUN Â Â Â= 16,
> Â Â Â ÂUFSHCD_CAN_QUEUE Â Â Â Â= 32,
> Â Â Â ÂBYTES_128 Â Â Â Â Â Â Â = 128,
> Â Â Â ÂBYTES_1024 Â Â Â Â Â Â Â= 1024
> @@ -146,6 +148,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
> @@ -184,6 +187,8 @@ struct ufs_hba {
>
> Â Â Â Âstruct ufshcd_lrb *lrb;
>
> + Â Â Â u32 outstanding_reqs;
> +
> Â Â Â Âu32 capabilities;
> Â Â Â Âint nutrs;
> Â Â Â Âint nutmrs;
> @@ -204,12 +209,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 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;
> + Â Â Â int lun;
> Â};
>
> Â/**
> @@ -236,6 +257,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
> Â*
> @@ -303,6 +336,36 @@ 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 |
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂCOMMAND_COMPLETE << 8);
> +}
> +
> +/**
> + * 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 code.
> + */
> +static inline int
> +ufshcd_get_rsp_upiu_result(struct utp_upiu_rsp *ucd_rsp_ptr)
> +{
> + Â Â Â return be32_to_cpu(ucd_rsp_ptr->header.dword_1) & MASK_RSP_UPIU_RESULT;
> +}
> +
> +/**
> Â* ufshcd_config_int_aggr - Configure interrupt aggregation values
> Â* Â Â Â Â Â Â currently there is no use case where we want to configure
> Â* Â Â Â Â Â Â interrupt aggregation dynamically. So to configure interrupt
> @@ -342,6 +405,34 @@ static inline void ufshcd_hba_stop(struct ufs_hba *hba)
> Â}
>
> Â/**
> + * ufshcd_send_command - Send SCSI or device management commands
> + * @hba: per adapter instance
> + * @task_tag: Task tag of the command
> + */
> +static inline
> +void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
> +{
> + Â Â Â hba->outstanding_reqs |= (1 << task_tag);
> + Â Â Â writel((1 << task_tag),
> + Â Â Â Â Â Â Â(UFSHCD_MMIO_BASE + REG_UTP_TRANSFER_REQ_DOOR_BELL));
> +}
> +
> +/**
> + * ufshcd_copy_sense_data - Copy sense data in case of check condition
> + * @lrb - pointer to local reference block
> + */
> +static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp)
> +{
> + Â Â Â int len;
> + Â Â Â if (lrbp->sense_buffer != NULL) {
> + Â Â Â Â Â Â Â len = be16_to_cpu(lrbp->ucd_rsp_ptr->sense_data_len);
> + Â Â Â Â Â Â Â memcpy(lrbp->sense_buffer,
> + Â Â Â Â Â Â Â Â Â Â Â lrbp->ucd_rsp_ptr->sense_data,
> + Â Â Â Â Â Â Â Â Â Â Â min_t(int, len, SCSI_SENSE_BUFFERSIZE));
> + Â Â Â }
> +}
> +
> +/**
> Â* ufshcd_hba_capabilities - Read controller capabilities
> Â* @hba: per adapter instance
> Â*/
> @@ -385,6 +476,42 @@ ufshcd_send_uic_command(struct ufs_hba *hba, struct uic_command *uic_cmnd)
> Â}
>
> Â/**
> + * ufshcd_map_sg - Map scatter-gather list to prdt
> + * @lrbp - pointer to local reference block
> + */
> +static void ufshcd_map_sg(struct ufshcd_lrb *lrbp)
> +{
> + Â Â Â struct ufshcd_sg_entry *prd_table;
> + Â Â Â struct scatterlist *sg;
> + Â Â Â struct scsi_cmnd *cmd;
> + Â Â Â int sg_segments;
> + Â Â Â int i;
> +
> + Â Â Â cmd = lrbp->cmd;
> + Â Â Â sg_segments = scsi_dma_map(cmd);
> +
> + Â Â Â BUG_ON(sg_segments < 0);
> +
> + Â Â Â if (sg_segments) {
> + Â Â Â Â Â Â Â lrbp->utr_descriptor_ptr->prd_table_length =
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu_to_le16((u16) (sg_segments));
> +
> + Â Â Â Â Â Â Â prd_table = (struct ufshcd_sg_entry *)lrbp->ucd_prdt_ptr;
> +
> + Â Â Â Â Â Â Â scsi_for_each_sg(cmd, sg, sg_segments, i) {
> + Â Â Â Â Â Â Â Â Â Â Â prd_table[i].size Â=
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu_to_le32(((u32) sg_dma_len(sg))-1);
> + Â Â Â Â Â Â Â Â Â Â Â prd_table[i].base_addr =
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu_to_le32(sg->dma_address);
> + Â Â Â Â Â Â Â Â Â Â Â prd_table[i].upper_addr =
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu_to_le32((sg->dma_address >> 32));
> + Â Â Â Â Â Â Â }
> + Â Â Â } else {
> + Â Â Â Â Â Â Â lrbp->utr_descriptor_ptr->prd_table_length = 0;
> + Â Â Â }
> +}
> +
> +/**
> Â* ufshcd_int_config - enable/disable interrupts
> Â* @hba: per adapter instance
> Â* @option: interrupt option
> @@ -410,6 +537,124 @@ static void ufshcd_int_config(struct ufs_hba *hba, u32 option)
> Â}
>
> Â/**
> + * ufshcd_compose_upiu - form UFS Protocol Information Unit(UPIU)
> + * @hba: per adapter instance
> + * @lrb - pointer to local reference block
> + */
> +static void ufshcd_compose_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
> +{
> + Â Â Â struct utp_transfer_req_desc *req_desc;
> + Â Â Â struct utp_upiu_cmd *ucd_cmd_ptr;
> + Â Â Â u32 data_direction;
> + Â Â Â u32 upiu_flags;
> +
> + Â Â Â ucd_cmd_ptr = lrbp->ucd_cmd_ptr;
> + Â Â Â req_desc = lrbp->utr_descriptor_ptr;
> +
> + Â Â Â memset(ucd_cmd_ptr, 0, sizeof(struct utp_upiu_cmd));
> +
> + Â Â Â switch (lrbp->command_type) {
> + Â Â Â case UTP_CMD_TYPE_SCSI:
> + Â Â Â Â Â Â Â if (DMA_FROM_DEVICE == lrbp->cmd->sc_data_direction) {
> + Â Â Â Â Â Â Â Â Â Â Â data_direction = UTP_DEVICE_TO_HOST;
> + Â Â Â Â Â Â Â Â Â Â Â upiu_flags = UPIU_CMD_FLAGS_READ;
> + Â Â Â Â Â Â Â } else if (DMA_TO_DEVICE == lrbp->cmd->sc_data_direction) {
> + Â Â Â Â Â Â Â Â Â Â Â data_direction = UTP_HOST_TO_DEVICE;
> + Â Â Â Â Â Â Â Â Â Â Â upiu_flags = UPIU_CMD_FLAGS_WRITE;
> + Â Â Â Â Â Â Â } else {
> + Â Â Â Â Â Â Â Â Â Â Â data_direction = UTP_NO_DATA_TRANSFER;
> + Â Â Â Â Â Â Â Â Â Â Â upiu_flags = 0;
I think that we can add some enum value for like UTP_NO_DATA_TRANSFER.
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* Transfer request desc header fields
> + Â Â Â Â Â Â Â Â* set interrupt bit if interrupt aggregation is disabled
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â req_desc->header.dword_0 = cpu_to_le32(data_direction |
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂUTP_SCSI_COMMAND);
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* assigning invalid value for command status. Controller
> + Â Â Â Â Â Â Â Â* updates OCS on command completion, with the command
> + Â Â Â Â Â Â Â Â* status
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â req_desc->header.dword_2 =
> + Â Â Â Â Â Â Â Â Â Â Â cpu_to_le32(OCS_INVALID_COMMAND_STATUS);
> +
> + Â Â Â Â Â Â Â /* command descriptor fields */
> + Â Â Â Â Â Â Â 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,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â(unsigned short)MAX_CDB_SIZE)));
Is there any reason type casting for MAX_CDB_SIZE ?

> +
> + Â Â Â Â Â Â Â ucd_cmd_ptr->header.dword_0 =
> + Â Â Â Â Â Â Â Â Â Â Â cpu_to_be32(UPIU_HEADER_DWORD(UPIU_TRANSACTION_COMMAND,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â upiu_flags,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â lrbp->lun,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â lrbp->task_tag));
> + Â Â Â Â Â Â Â ucd_cmd_ptr->header.dword_1 =
> + Â Â Â Â Â Â Â Â Â Â Â cpu_to_be32(
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UPIU_HEADER_DWORD(UPIU_COMMAND_SET_TYPE_SCSI,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0));
> +
> + Â Â Â Â Â Â Â /* set command response to zero */
> + Â Â Â Â Â Â Â memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp));
Why did you set ucd_rsp_ptr to zero afte adding value ?
And plz add break here.
> + Â Â Â case UTP_CMD_TYPE_DEV_MANAGE:
> + Â Â Â Â Â Â Â /* For query function implementation */
> + Â Â Â Â Â Â Â break;
> + Â Â Â case UTP_CMD_TYPE_UFS:
> + Â Â Â Â Â Â Â /* For UFS native command implementation */
> + Â Â Â Â Â Â Â break;
> + Â Â Â } /* end of switch, command_type */
> +}
> +
> +/**
> + * ufshcd_queuecommand - main entry point for SCSI requests
> + * @cmd: command from SCSI Midlayer
> + * @done: call back function
> + *
> + * Retruns 0 for success, SCSI Midlayer specific error in case of failure
> + */
> +static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
> +{
> + Â Â Â struct ufshcd_lrb *lrbp;
> + Â Â Â struct ufs_hba *hba;
> + Â Â Â unsigned long flags;
> + Â Â Â int tag;
> +
> + Â Â Â hba = (struct ufs_hba *) &host->hostdata[0];
> +
> + Â Â Â tag = cmd->request->tag;
> +
> + Â Â Â if (UFSHCD_STATE_OPERATIONAL != hba->ufshcd_state)
> + Â Â Â Â Â Â Â return SCSI_MLQUEUE_HOST_BUSY;
> +
> + Â Â Â lrbp = &hba->lrb[tag];
> +
> + Â Â Â lrbp->cmd = cmd;
> + Â Â Â lrbp->sense_bufflen = SCSI_SENSE_BUFFERSIZE;
> + Â Â Â lrbp->sense_buffer = cmd->sense_buffer;
> + Â Â Â lrbp->task_tag = tag;
> + Â Â Â lrbp->lun = cmd->device->lun;
> +
> + Â Â Â lrbp->command_type = UTP_CMD_TYPE_SCSI;
> +
> + Â Â Â /* form UPIU before issuing the command */
> + Â Â Â ufshcd_compose_upiu(hba, lrbp);
> + Â Â Â ufshcd_map_sg(lrbp);
> +
> + Â Â Â /* issue command to the controller */
> + Â Â Â spin_lock_irqsave(host->host_lock, flags);
> + Â Â Â ufshcd_send_command(hba, tag);
> + Â Â Â spin_unlock_irqrestore(host->host_lock, flags);
> + Â Â Â return 0;
> +}
> +
> +/**
> Â* ufshcd_memory_alloc - allocate memory for host memory space data structures
> Â* @hba: per adapter instance
> Â*
> @@ -680,6 +925,7 @@ static int ufshcd_make_hba_operational(struct ufs_hba *hba)
> Â Â Â Âufshcd_config_int_aggr(hba, INT_AGGR_CONFIG);
>
> Â Â Â Âhba->ufshcd_state = UFSHCD_STATE_OPERATIONAL;
> + Â Â Â scsi_scan_host(hba->host);
>
> Â Â Â Âreturn 0;
> Â}
> @@ -763,6 +1009,190 @@ static int ufshcd_initialize_hba(struct ufs_hba *hba)
> Â}
>
> Â/**
> + * ufshcd_slave_alloc - handle initial scsi devie configurations
> + * @sdev: pointer to scsi device
> + *
> + * Returns success
> + */
> +static int ufshcd_slave_alloc(struct scsi_device *sdev)
> +{
> + Â Â Â struct ufs_hba *hba;
> +
> + Â Â Â hba = (struct ufs_hba *)sdev->host->hostdata;
> + Â Â Â sdev->tagged_supported = 1;
> + Â Â Â scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
> + Â Â Â scsi_activate_tcq(sdev, hba->nutrs);
> +
> + Â Â Â return 0;
> +}
> +
> +/**
> + * ufshcd_slave_destroy - remove scsi device configurations
> + * @sdev: pointer to scsi device
> + */
> +static void ufshcd_slave_destroy(struct scsi_device *sdev)
> +{
> + Â Â Â struct ufs_hba *hba;
> +
> + Â Â Â hba = (struct ufs_hba *)sdev->host->hostdata;
> + Â Â Â scsi_deactivate_tcq(sdev, hba->nutrs);
> +}
> +
> +/**
> + * 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
> + *
> + * Returns value base on SCSI command status
> + */
> +static inline int
> +ufshcd_scsi_cmd_status(struct ufshcd_lrb *lrbp, int scsi_status)
> +{
> + Â Â Â int result = 0;
> +
> + Â Â Â switch (scsi_status) {
> + Â Â Â case SAM_STAT_GOOD:
> + Â Â Â Â Â Â Â result |= DID_OK << 16 |
> + Â Â Â Â Â Â Â Â Â Â Â Â COMMAND_COMPLETE << 8 |
> + Â Â Â Â Â Â Â Â Â Â Â Â SAM_STAT_GOOD;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case SAM_STAT_CHECK_CONDITION:
> + Â Â Â Â Â Â Â result |= DRIVER_SENSE << 24 |
> + Â Â Â Â Â Â Â Â Â Â Â Â COMMAND_COMPLETE << 8 |
> + Â Â Â Â Â Â Â Â Â Â Â Â SAM_STAT_CHECK_CONDITION;
> + Â Â Â Â Â Â Â ufshcd_copy_sense_data(lrbp);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case SAM_STAT_BUSY:
> + Â Â Â Â Â Â Â result |= DID_BUS_BUSY << 16 |
> + Â Â Â Â Â Â Â Â Â Â Â Â SAM_STAT_BUSY;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case SAM_STAT_TASK_SET_FULL:
> + Â Â Â Â Â Â Â result |= DID_OK << 16 |
> + Â Â Â Â Â Â Â Â Â Â Â Â COMMAND_COMPLETE << 8 |
> + Â Â Â Â Â Â Â Â Â Â Â Â SAM_STAT_TASK_SET_FULL;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case SAM_STAT_TASK_ABORTED:
> + Â Â Â Â Â Â Â result |= ÂDID_ABORT << 16 |
> + Â Â Â Â Â Â Â Â Â Â Â Â ÂABORT_TASK << 8 |
> + Â Â Â Â Â Â Â Â Â Â Â Â ÂSAM_STAT_TASK_ABORTED;
plz add break here also.
> + Â Â Â default:
> + Â Â Â Â Â Â Â result |= DID_ERROR << 16;
> + Â Â Â Â Â Â Â break;
> + Â Â Â } /* end of switch */
> +
> + Â Â Â return result;
> +}
> +
> +/**
> + * ufshcd_transfer_rsp_status - Get overall status of the response
> + * @lrb: pointer to local reference block of completed command
> + *
> + * Returns result of the command to notify SCSI midlayer
> + */
> +static inline int ufshcd_transfer_rsp_status(struct ufshcd_lrb *lrbp)
> +{
> + Â Â Â int result = 0;
> + Â Â Â int scsi_status;
> + Â Â Â int ocs;
> +
> + Â Â Â /* overall command status of utrd */
> + Â Â Â ocs = ufshcd_get_tr_ocs(lrbp);
> +
> + Â Â Â switch (ocs) {
> + Â Â Â case OCS_SUCCESS:
> +
> + Â Â Â Â Â Â Â /* check if the returned transfer response is valid */
> + Â Â Â Â Â Â Â result = ufshcd_is_valid_req_rsp(lrbp->ucd_rsp_ptr);
> + Â Â Â Â Â Â Â if (result) {
> + Â Â Â Â Â Â Â Â Â Â Â pr_err(UFSHCD ":Invalid Response\n");
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* get the response UPIU result to extract
> + Â Â Â Â Â Â Â Â* the SCSI command status
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â result = ufshcd_get_rsp_upiu_result(lrbp->ucd_rsp_ptr);
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* get the result based on SCSI status response
> + Â Â Â Â Â Â Â Â* to notify the SCSI midlayer of the command status
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â scsi_status = result & MASK_SCSI_STATUS;
> + Â Â Â Â Â Â Â result = ufshcd_scsi_cmd_status(lrbp, scsi_status);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case OCS_INVALID_CMD_TABLE_ATTR:
> + Â Â Â Â Â Â Â result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case OCS_INVALID_PRDT_ATTR:
> + Â Â Â Â Â Â Â result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case OCS_MISMATCH_DATA_BUF_SIZE:
> + Â Â Â Â Â Â Â result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case OCS_MISMATCH_RESP_UPIU_SIZE:
> + Â Â Â Â Â Â Â result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case OCS_PEER_COMM_FAILURE:
> + Â Â Â Â Â Â Â result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case OCS_ABORTED:
> + Â Â Â Â Â Â Â result |= DID_ABORT << 16 | ABORT_TASK << 8;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case OCS_FATAL_ERROR:
> + Â Â Â Â Â Â Â result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
> + Â Â Â Â Â Â Â break;
> + Â Â Â default:
> + Â Â Â Â Â Â Â /* should not come here */
> + Â Â Â Â Â Â Â result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
> + Â Â Â Â Â Â Â pr_err(UFSHCD ":Invalid OCS from controller\n");
> + Â Â Â Â Â Â Â break;
> + Â Â Â } /* end of switch */
> +
> + Â Â Â return result;
> +}
> +
> +/**
> + * ufshcd_transfer_req_compl - handle SCSI and query command completion
> + * @hba: per adapter instance
> + */
> +static void ufshcd_transfer_req_compl(struct ufs_hba *hba)
> +{
> + Â Â Â struct ufshcd_lrb *lrb;
> + Â Â Â u32 completed_reqs;
> + Â Â Â u32 tr_doorbell;
> + Â Â Â int result;
> + Â Â Â int index;
> +
> + Â Â Â lrb = hba->lrb;
> + Â Â Â tr_doorbell =
> + Â Â Â Â Â Â Â readl(hba->mmio_base + REG_UTP_TRANSFER_REQ_DOOR_BELL);
> + Â Â Â completed_reqs = tr_doorbell ^ hba->outstanding_reqs;
> +
> + Â Â Â /* clear completed commands from outstanding_reqs */
> + Â Â Â hba->outstanding_reqs ^= completed_reqs;
> +
> + Â Â Â for (index = 0; index < hba->nutrs; index++) {
> + Â Â Â Â Â Â Â if (completed_reqs & (1 << index)) {
> +
> + Â Â Â Â Â Â Â Â Â Â Â result = ufshcd_transfer_rsp_status(&lrb[index]);
> +
> + Â Â Â Â Â Â Â Â Â Â Â if (NULL != lrb[index].cmd) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â scsi_dma_unmap(lrb[index].cmd);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â lrb[index].cmd->result = result;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â lrb[index].cmd->scsi_done(lrb[index].cmd);
> +
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â /* Mark completed command as NULL in LRB */
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â lrb[index].cmd = NULL;
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â } /* end of if */
> + Â Â Â } /* end of for */
> +
> + Â Â Â /* Reset interrupt aggregation counters */
> + Â Â Â ufshcd_config_int_aggr(hba, INT_AGGR_RESET);
> +}
> +
> +/**
> Â* ufshcd_uic_cc_handler - handle UIC command completion
> Â* @work: pointer to a work queue structure
> Â*
> @@ -793,6 +1223,9 @@ static void ufshcd_sl_intr(struct ufs_hba *hba, u32 intr_status)
> Â{
> Â Â Â Âif (intr_status & UIC_COMMAND_COMPL)
> Â Â Â Â Â Â Â Âschedule_work(&hba->uic_workq);
> +
> + Â Â Â if (intr_status & UTP_TRANSFER_REQ_COMPL)
> + Â Â Â Â Â Â Â ufshcd_transfer_req_compl(hba);
> Â}
>
> Â/**
> @@ -830,7 +1263,13 @@ static struct scsi_host_template ufshcd_driver_template = {
>    Â.module         = THIS_MODULE,
>    Â.name          = UFSHCD,
>    Â.proc_name       Â= UFSHCD,
> +    .queuecommand      = ufshcd_queuecommand,
> +    .slave_alloc      Â= ufshcd_slave_alloc,
> +    .slave_destroy     Â= ufshcd_slave_destroy,
>    Â.this_id        Â= -1,
> +    .sg_tablesize      = SG_ALL,
> +    .cmd_per_lun      Â= UFSHCD_CMD_PER_LUN,
> +    .can_queue       Â= UFSHCD_CAN_QUEUE
> Â};
>
> Â/**
> @@ -1003,6 +1442,7 @@ ufshcd_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> Â Â Â Âhost->max_lun = UFSHCD_MAX_LUNS;
> Â Â Â Âhost->max_channel = UFSHCD_MAX_CHANNEL;
> Â Â Â Âhost->unique_id = host->host_no;
> + Â Â Â host->max_cmd_len = MAX_CDB_SIZE;
>
> Â Â Â Â/* Initialize work queues */
> Â Â Â ÂINIT_WORK(&hba->uic_workq, ufshcd_uic_cc_handler);
> @@ -1014,6 +1454,13 @@ ufshcd_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> Â Â Â Â Â Â Â Âgoto out_lrb_free;
> Â Â Â Â}
>
> + Â Â Â /* Enable scsi tag mapping */
> + Â Â Â err = scsi_init_shared_tag_map(host, host->can_queue);
> + Â Â Â if (err) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "init shared queue failed\n");
> + Â Â Â Â Â Â Â goto out_free_irq;
> + Â Â Â }
> +
> Â Â Â Âpci_set_drvdata(pdev, hba);
>
> Â Â Â Âerr = scsi_add_host(host, &pdev->dev);
> --
> 1.7.5.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/