Commit fad74a1b authored by Tyrel Datwyler's avatar Tyrel Datwyler Committed by Martin K. Petersen

scsi: ibmvfc: Deduplicate common ibmvfc_cmd init code

The virtual FC frame command exchanged with the VIOS is used for device
reset and command abort TMF as well as normally queued commands. When
initializing the ibmvfc_cmd there are several elements of the command that
are set the same way regardless of the command type.

Deduplicate code by moving these commonally set fields into a
initialization helper routine, namely ibmvfc_init_vfc_cmd().

Link: https://lore.kernel.org/r/20201118011104.296999-2-tyreld@linux.ibm.comAcked-by: default avatarBrian King <brking@linux.vnet.ibm.com>
Signed-off-by: default avatarTyrel Datwyler <tyreld@linux.ibm.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 2aa0102c
...@@ -1646,6 +1646,25 @@ static inline int ibmvfc_host_chkready(struct ibmvfc_host *vhost) ...@@ -1646,6 +1646,25 @@ static inline int ibmvfc_host_chkready(struct ibmvfc_host *vhost)
return result; return result;
} }
static struct ibmvfc_cmd *ibmvfc_init_vfc_cmd(struct ibmvfc_event *evt, struct scsi_device *sdev)
{
struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
struct ibmvfc_cmd *vfc_cmd = &evt->iu.cmd;
size_t offset = offsetof(struct ibmvfc_cmd, rsp);
memset(vfc_cmd, 0, sizeof(*vfc_cmd));
vfc_cmd->resp.va = cpu_to_be64(be64_to_cpu(evt->crq.ioba) + offset);
vfc_cmd->resp.len = cpu_to_be32(sizeof(vfc_cmd->rsp));
vfc_cmd->frame_type = cpu_to_be32(IBMVFC_SCSI_FCP_TYPE);
vfc_cmd->payload_len = cpu_to_be32(sizeof(vfc_cmd->iu));
vfc_cmd->resp_len = cpu_to_be32(sizeof(vfc_cmd->rsp));
vfc_cmd->cancel_key = cpu_to_be32((unsigned long)sdev->hostdata);
vfc_cmd->tgt_scsi_id = cpu_to_be64(rport->port_id);
int_to_scsilun(sdev->lun, &vfc_cmd->iu.lun);
return vfc_cmd;
}
/** /**
* ibmvfc_queuecommand - The queuecommand function of the scsi template * ibmvfc_queuecommand - The queuecommand function of the scsi template
* @cmnd: struct scsi_cmnd to be executed * @cmnd: struct scsi_cmnd to be executed
...@@ -1675,17 +1694,10 @@ static int ibmvfc_queuecommand_lck(struct scsi_cmnd *cmnd, ...@@ -1675,17 +1694,10 @@ static int ibmvfc_queuecommand_lck(struct scsi_cmnd *cmnd,
ibmvfc_init_event(evt, ibmvfc_scsi_done, IBMVFC_CMD_FORMAT); ibmvfc_init_event(evt, ibmvfc_scsi_done, IBMVFC_CMD_FORMAT);
evt->cmnd = cmnd; evt->cmnd = cmnd;
cmnd->scsi_done = done; cmnd->scsi_done = done;
vfc_cmd = &evt->iu.cmd;
memset(vfc_cmd, 0, sizeof(*vfc_cmd)); vfc_cmd = ibmvfc_init_vfc_cmd(evt, cmnd->device);
vfc_cmd->resp.va = cpu_to_be64(be64_to_cpu(evt->crq.ioba) + offsetof(struct ibmvfc_cmd, rsp));
vfc_cmd->resp.len = cpu_to_be32(sizeof(vfc_cmd->rsp));
vfc_cmd->frame_type = cpu_to_be32(IBMVFC_SCSI_FCP_TYPE);
vfc_cmd->payload_len = cpu_to_be32(sizeof(vfc_cmd->iu));
vfc_cmd->resp_len = cpu_to_be32(sizeof(vfc_cmd->rsp));
vfc_cmd->cancel_key = cpu_to_be32((unsigned long)cmnd->device->hostdata);
vfc_cmd->tgt_scsi_id = cpu_to_be64(rport->port_id);
vfc_cmd->iu.xfer_len = cpu_to_be32(scsi_bufflen(cmnd)); vfc_cmd->iu.xfer_len = cpu_to_be32(scsi_bufflen(cmnd));
int_to_scsilun(cmnd->device->lun, &vfc_cmd->iu.lun);
memcpy(vfc_cmd->iu.cdb, cmnd->cmnd, cmnd->cmd_len); memcpy(vfc_cmd->iu.cdb, cmnd->cmnd, cmnd->cmd_len);
if (cmnd->flags & SCMD_TAGGED) { if (cmnd->flags & SCMD_TAGGED) {
...@@ -2014,7 +2026,6 @@ static int ibmvfc_bsg_request(struct bsg_job *job) ...@@ -2014,7 +2026,6 @@ static int ibmvfc_bsg_request(struct bsg_job *job)
static int ibmvfc_reset_device(struct scsi_device *sdev, int type, char *desc) static int ibmvfc_reset_device(struct scsi_device *sdev, int type, char *desc)
{ {
struct ibmvfc_host *vhost = shost_priv(sdev->host); struct ibmvfc_host *vhost = shost_priv(sdev->host);
struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
struct ibmvfc_cmd *tmf; struct ibmvfc_cmd *tmf;
struct ibmvfc_event *evt = NULL; struct ibmvfc_event *evt = NULL;
union ibmvfc_iu rsp_iu; union ibmvfc_iu rsp_iu;
...@@ -2027,17 +2038,8 @@ static int ibmvfc_reset_device(struct scsi_device *sdev, int type, char *desc) ...@@ -2027,17 +2038,8 @@ static int ibmvfc_reset_device(struct scsi_device *sdev, int type, char *desc)
if (vhost->state == IBMVFC_ACTIVE) { if (vhost->state == IBMVFC_ACTIVE) {
evt = ibmvfc_get_event(vhost); evt = ibmvfc_get_event(vhost);
ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT); ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT);
tmf = ibmvfc_init_vfc_cmd(evt, sdev);
tmf = &evt->iu.cmd;
memset(tmf, 0, sizeof(*tmf));
tmf->resp.va = cpu_to_be64(be64_to_cpu(evt->crq.ioba) + offsetof(struct ibmvfc_cmd, rsp));
tmf->resp.len = cpu_to_be32(sizeof(tmf->rsp));
tmf->frame_type = cpu_to_be32(IBMVFC_SCSI_FCP_TYPE);
tmf->payload_len = cpu_to_be32(sizeof(tmf->iu));
tmf->resp_len = cpu_to_be32(sizeof(tmf->rsp));
tmf->cancel_key = cpu_to_be32((unsigned long)sdev->hostdata);
tmf->tgt_scsi_id = cpu_to_be64(rport->port_id);
int_to_scsilun(sdev->lun, &tmf->iu.lun);
tmf->flags = cpu_to_be16((IBMVFC_NO_MEM_DESC | IBMVFC_TMF)); tmf->flags = cpu_to_be16((IBMVFC_NO_MEM_DESC | IBMVFC_TMF));
tmf->iu.tmf_flags = type; tmf->iu.tmf_flags = type;
evt->sync_iu = &rsp_iu; evt->sync_iu = &rsp_iu;
...@@ -2329,7 +2331,6 @@ static int ibmvfc_match_evt(struct ibmvfc_event *evt, void *match) ...@@ -2329,7 +2331,6 @@ static int ibmvfc_match_evt(struct ibmvfc_event *evt, void *match)
static int ibmvfc_abort_task_set(struct scsi_device *sdev) static int ibmvfc_abort_task_set(struct scsi_device *sdev)
{ {
struct ibmvfc_host *vhost = shost_priv(sdev->host); struct ibmvfc_host *vhost = shost_priv(sdev->host);
struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
struct ibmvfc_cmd *tmf; struct ibmvfc_cmd *tmf;
struct ibmvfc_event *evt, *found_evt; struct ibmvfc_event *evt, *found_evt;
union ibmvfc_iu rsp_iu; union ibmvfc_iu rsp_iu;
...@@ -2357,17 +2358,8 @@ static int ibmvfc_abort_task_set(struct scsi_device *sdev) ...@@ -2357,17 +2358,8 @@ static int ibmvfc_abort_task_set(struct scsi_device *sdev)
if (vhost->state == IBMVFC_ACTIVE) { if (vhost->state == IBMVFC_ACTIVE) {
evt = ibmvfc_get_event(vhost); evt = ibmvfc_get_event(vhost);
ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT); ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT);
tmf = ibmvfc_init_vfc_cmd(evt, sdev);
tmf = &evt->iu.cmd;
memset(tmf, 0, sizeof(*tmf));
tmf->resp.va = cpu_to_be64(be64_to_cpu(evt->crq.ioba) + offsetof(struct ibmvfc_cmd, rsp));
tmf->resp.len = cpu_to_be32(sizeof(tmf->rsp));
tmf->frame_type = cpu_to_be32(IBMVFC_SCSI_FCP_TYPE);
tmf->payload_len = cpu_to_be32(sizeof(tmf->iu));
tmf->resp_len = cpu_to_be32(sizeof(tmf->rsp));
tmf->cancel_key = cpu_to_be32((unsigned long)sdev->hostdata);
tmf->tgt_scsi_id = cpu_to_be64(rport->port_id);
int_to_scsilun(sdev->lun, &tmf->iu.lun);
tmf->flags = cpu_to_be16((IBMVFC_NO_MEM_DESC | IBMVFC_TMF)); tmf->flags = cpu_to_be16((IBMVFC_NO_MEM_DESC | IBMVFC_TMF));
tmf->iu.tmf_flags = IBMVFC_ABORT_TASK_SET; tmf->iu.tmf_flags = IBMVFC_ABORT_TASK_SET;
evt->sync_iu = &rsp_iu; evt->sync_iu = &rsp_iu;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment