Commit 924cb24d authored by Bart Van Assche's avatar Bart Van Assche Committed by Martin K. Petersen

scsi: fnic: Stop using the SCSI pointer

Set .cmd_size in the SCSI host template instead of using the SCSI pointer
from struct scsi_cmnd. This patch prepares for removal of the SCSI pointer
from struct scsi_cmnd.

Link: https://lore.kernel.org/r/20220218195117.25689-23-bvanassche@acm.orgReviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 3032ed77
...@@ -89,15 +89,28 @@ ...@@ -89,15 +89,28 @@
#define FNIC_DEV_RST_ABTS_PENDING BIT(21) #define FNIC_DEV_RST_ABTS_PENDING BIT(21)
/* /*
* Usage of the scsi_cmnd scratchpad. * fnic private data per SCSI command.
* These fields are locked by the hashed io_req_lock. * These fields are locked by the hashed io_req_lock.
*/ */
#define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr) struct fnic_cmd_priv {
#define CMD_STATE(Cmnd) ((Cmnd)->SCp.phase) struct fnic_io_req *io_req;
#define CMD_ABTS_STATUS(Cmnd) ((Cmnd)->SCp.Message) enum fnic_ioreq_state state;
#define CMD_LR_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in) u32 flags;
#define CMD_TAG(Cmnd) ((Cmnd)->SCp.sent_command) u16 abts_status;
#define CMD_FLAGS(Cmnd) ((Cmnd)->SCp.Status) u16 lr_status;
};
static inline struct fnic_cmd_priv *fnic_priv(struct scsi_cmnd *cmd)
{
return scsi_cmd_priv(cmd);
}
static inline u64 fnic_flags_and_state(struct scsi_cmnd *cmd)
{
struct fnic_cmd_priv *fcmd = fnic_priv(cmd);
return ((u64)fcmd->flags << 32) | fcmd->state;
}
#define FCPIO_INVALID_CODE 0x100 /* hdr_status value unused by firmware */ #define FCPIO_INVALID_CODE 0x100 /* hdr_status value unused by firmware */
......
...@@ -124,6 +124,7 @@ static struct scsi_host_template fnic_host_template = { ...@@ -124,6 +124,7 @@ static struct scsi_host_template fnic_host_template = {
.max_sectors = 0xffff, .max_sectors = 0xffff,
.shost_groups = fnic_host_groups, .shost_groups = fnic_host_groups,
.track_queue_depth = 1, .track_queue_depth = 1,
.cmd_size = sizeof(struct fnic_cmd_priv),
}; };
static void static void
......
...@@ -497,8 +497,8 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) ...@@ -497,8 +497,8 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc)
* caller disabling them. * caller disabling them.
*/ */
spin_unlock(lp->host->host_lock); spin_unlock(lp->host->host_lock);
CMD_STATE(sc) = FNIC_IOREQ_NOT_INITED; fnic_priv(sc)->state = FNIC_IOREQ_NOT_INITED;
CMD_FLAGS(sc) = FNIC_NO_FLAGS; fnic_priv(sc)->flags = FNIC_NO_FLAGS;
/* Get a new io_req for this SCSI IO */ /* Get a new io_req for this SCSI IO */
io_req = mempool_alloc(fnic->io_req_pool, GFP_ATOMIC); io_req = mempool_alloc(fnic->io_req_pool, GFP_ATOMIC);
...@@ -513,7 +513,7 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) ...@@ -513,7 +513,7 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc)
sg_count = scsi_dma_map(sc); sg_count = scsi_dma_map(sc);
if (sg_count < 0) { if (sg_count < 0) {
FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no, FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no,
tag, sc, 0, sc->cmnd[0], sg_count, CMD_STATE(sc)); tag, sc, 0, sc->cmnd[0], sg_count, fnic_priv(sc)->state);
mempool_free(io_req, fnic->io_req_pool); mempool_free(io_req, fnic->io_req_pool);
goto out; goto out;
} }
...@@ -558,9 +558,9 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) ...@@ -558,9 +558,9 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc)
io_lock_acquired = 1; io_lock_acquired = 1;
io_req->port_id = rport->port_id; io_req->port_id = rport->port_id;
io_req->start_time = jiffies; io_req->start_time = jiffies;
CMD_STATE(sc) = FNIC_IOREQ_CMD_PENDING; fnic_priv(sc)->state = FNIC_IOREQ_CMD_PENDING;
CMD_SP(sc) = (char *)io_req; fnic_priv(sc)->io_req = io_req;
CMD_FLAGS(sc) |= FNIC_IO_INITIALIZED; fnic_priv(sc)->flags |= FNIC_IO_INITIALIZED;
/* create copy wq desc and enqueue it */ /* create copy wq desc and enqueue it */
wq = &fnic->wq_copy[0]; wq = &fnic->wq_copy[0];
...@@ -571,11 +571,10 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) ...@@ -571,11 +571,10 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc)
* refetch the pointer under the lock. * refetch the pointer under the lock.
*/ */
FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no, FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no,
tag, sc, 0, 0, 0, tag, sc, 0, 0, 0, fnic_flags_and_state(sc));
(((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); io_req = fnic_priv(sc)->io_req;
io_req = (struct fnic_io_req *)CMD_SP(sc); fnic_priv(sc)->io_req = NULL;
CMD_SP(sc) = NULL; fnic_priv(sc)->state = FNIC_IOREQ_CMD_COMPLETE;
CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
if (io_req) { if (io_req) {
fnic_release_ioreq_buf(fnic, io_req, sc); fnic_release_ioreq_buf(fnic, io_req, sc);
...@@ -594,7 +593,7 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) ...@@ -594,7 +593,7 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc)
atomic64_read(&fnic_stats->io_stats.active_ios)); atomic64_read(&fnic_stats->io_stats.active_ios));
/* REVISIT: Use per IO lock in the final code */ /* REVISIT: Use per IO lock in the final code */
CMD_FLAGS(sc) |= FNIC_IO_ISSUED; fnic_priv(sc)->flags |= FNIC_IO_ISSUED;
} }
out: out:
cmd_trace = ((u64)sc->cmnd[0] << 56 | (u64)sc->cmnd[7] << 40 | cmd_trace = ((u64)sc->cmnd[0] << 56 | (u64)sc->cmnd[7] << 40 |
...@@ -603,8 +602,8 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) ...@@ -603,8 +602,8 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc)
sc->cmnd[5]); sc->cmnd[5]);
FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no, FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no,
tag, sc, io_req, sg_count, cmd_trace, tag, sc, io_req, sg_count, cmd_trace,
(((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); fnic_flags_and_state(sc));
/* if only we issued IO, will we have the io lock */ /* if only we issued IO, will we have the io lock */
if (io_lock_acquired) if (io_lock_acquired)
...@@ -867,11 +866,11 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, ...@@ -867,11 +866,11 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
io_lock = fnic_io_lock_hash(fnic, sc); io_lock = fnic_io_lock_hash(fnic, sc);
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
WARN_ON_ONCE(!io_req); WARN_ON_ONCE(!io_req);
if (!io_req) { if (!io_req) {
atomic64_inc(&fnic_stats->io_stats.ioreq_null); atomic64_inc(&fnic_stats->io_stats.ioreq_null);
CMD_FLAGS(sc) |= FNIC_IO_REQ_NULL; fnic_priv(sc)->flags |= FNIC_IO_REQ_NULL;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
shost_printk(KERN_ERR, fnic->lport->host, shost_printk(KERN_ERR, fnic->lport->host,
"icmnd_cmpl io_req is null - " "icmnd_cmpl io_req is null - "
...@@ -888,17 +887,17 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, ...@@ -888,17 +887,17 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
* if SCSI-ML has already issued abort on this command, * if SCSI-ML has already issued abort on this command,
* set completion of the IO. The abts path will clean it up * set completion of the IO. The abts path will clean it up
*/ */
if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { if (fnic_priv(sc)->state == FNIC_IOREQ_ABTS_PENDING) {
/* /*
* set the FNIC_IO_DONE so that this doesn't get * set the FNIC_IO_DONE so that this doesn't get
* flagged as 'out of order' if it was not aborted * flagged as 'out of order' if it was not aborted
*/ */
CMD_FLAGS(sc) |= FNIC_IO_DONE; fnic_priv(sc)->flags |= FNIC_IO_DONE;
CMD_FLAGS(sc) |= FNIC_IO_ABTS_PENDING; fnic_priv(sc)->flags |= FNIC_IO_ABTS_PENDING;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
if(FCPIO_ABORTED == hdr_status) if(FCPIO_ABORTED == hdr_status)
CMD_FLAGS(sc) |= FNIC_IO_ABORTED; fnic_priv(sc)->flags |= FNIC_IO_ABORTED;
FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host,
"icmnd_cmpl abts pending " "icmnd_cmpl abts pending "
...@@ -912,7 +911,7 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, ...@@ -912,7 +911,7 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
} }
/* Mark the IO as complete */ /* Mark the IO as complete */
CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE; fnic_priv(sc)->state = FNIC_IOREQ_CMD_COMPLETE;
icmnd_cmpl = &desc->u.icmnd_cmpl; icmnd_cmpl = &desc->u.icmnd_cmpl;
...@@ -983,8 +982,8 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, ...@@ -983,8 +982,8 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
} }
/* Break link with the SCSI command */ /* Break link with the SCSI command */
CMD_SP(sc) = NULL; fnic_priv(sc)->io_req = NULL;
CMD_FLAGS(sc) |= FNIC_IO_DONE; fnic_priv(sc)->flags |= FNIC_IO_DONE;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
...@@ -1009,8 +1008,7 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, ...@@ -1009,8 +1008,7 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
((u64)icmnd_cmpl->_resvd0[1] << 56 | ((u64)icmnd_cmpl->_resvd0[1] << 56 |
(u64)icmnd_cmpl->_resvd0[0] << 48 | (u64)icmnd_cmpl->_resvd0[0] << 48 |
jiffies_to_msecs(jiffies - start_time)), jiffies_to_msecs(jiffies - start_time)),
desc, cmd_trace, desc, cmd_trace, fnic_flags_and_state(sc));
(((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc)));
if (sc->sc_data_direction == DMA_FROM_DEVICE) { if (sc->sc_data_direction == DMA_FROM_DEVICE) {
fnic->lport->host_stats.fcp_input_requests++; fnic->lport->host_stats.fcp_input_requests++;
...@@ -1095,12 +1093,12 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1095,12 +1093,12 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
} }
io_lock = fnic_io_lock_hash(fnic, sc); io_lock = fnic_io_lock_hash(fnic, sc);
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
WARN_ON_ONCE(!io_req); WARN_ON_ONCE(!io_req);
if (!io_req) { if (!io_req) {
atomic64_inc(&fnic_stats->io_stats.ioreq_null); atomic64_inc(&fnic_stats->io_stats.ioreq_null);
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_REQ_NULL; fnic_priv(sc)->flags |= FNIC_IO_ABT_TERM_REQ_NULL;
shost_printk(KERN_ERR, fnic->lport->host, shost_printk(KERN_ERR, fnic->lport->host,
"itmf_cmpl io_req is null - " "itmf_cmpl io_req is null - "
"hdr status = %s tag = 0x%x sc 0x%p\n", "hdr status = %s tag = 0x%x sc 0x%p\n",
...@@ -1115,9 +1113,9 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1115,9 +1113,9 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"dev reset abts cmpl recd. id %x status %s\n", "dev reset abts cmpl recd. id %x status %s\n",
id, fnic_fcpio_status_to_str(hdr_status)); id, fnic_fcpio_status_to_str(hdr_status));
CMD_STATE(sc) = FNIC_IOREQ_ABTS_COMPLETE; fnic_priv(sc)->state = FNIC_IOREQ_ABTS_COMPLETE;
CMD_ABTS_STATUS(sc) = hdr_status; fnic_priv(sc)->abts_status = hdr_status;
CMD_FLAGS(sc) |= FNIC_DEV_RST_DONE; fnic_priv(sc)->flags |= FNIC_DEV_RST_DONE;
if (io_req->abts_done) if (io_req->abts_done)
complete(io_req->abts_done); complete(io_req->abts_done);
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
...@@ -1127,7 +1125,7 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1127,7 +1125,7 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
case FCPIO_SUCCESS: case FCPIO_SUCCESS:
break; break;
case FCPIO_TIMEOUT: case FCPIO_TIMEOUT:
if (CMD_FLAGS(sc) & FNIC_IO_ABTS_ISSUED) if (fnic_priv(sc)->flags & FNIC_IO_ABTS_ISSUED)
atomic64_inc(&abts_stats->abort_fw_timeouts); atomic64_inc(&abts_stats->abort_fw_timeouts);
else else
atomic64_inc( atomic64_inc(
...@@ -1139,34 +1137,34 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1139,34 +1137,34 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
(int)(id & FNIC_TAG_MASK)); (int)(id & FNIC_TAG_MASK));
break; break;
case FCPIO_IO_NOT_FOUND: case FCPIO_IO_NOT_FOUND:
if (CMD_FLAGS(sc) & FNIC_IO_ABTS_ISSUED) if (fnic_priv(sc)->flags & FNIC_IO_ABTS_ISSUED)
atomic64_inc(&abts_stats->abort_io_not_found); atomic64_inc(&abts_stats->abort_io_not_found);
else else
atomic64_inc( atomic64_inc(
&term_stats->terminate_io_not_found); &term_stats->terminate_io_not_found);
break; break;
default: default:
if (CMD_FLAGS(sc) & FNIC_IO_ABTS_ISSUED) if (fnic_priv(sc)->flags & FNIC_IO_ABTS_ISSUED)
atomic64_inc(&abts_stats->abort_failures); atomic64_inc(&abts_stats->abort_failures);
else else
atomic64_inc( atomic64_inc(
&term_stats->terminate_failures); &term_stats->terminate_failures);
break; break;
} }
if (CMD_STATE(sc) != FNIC_IOREQ_ABTS_PENDING) { if (fnic_priv(sc)->state != FNIC_IOREQ_ABTS_PENDING) {
/* This is a late completion. Ignore it */ /* This is a late completion. Ignore it */
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
return; return;
} }
CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_DONE; fnic_priv(sc)->flags |= FNIC_IO_ABT_TERM_DONE;
CMD_ABTS_STATUS(sc) = hdr_status; fnic_priv(sc)->abts_status = hdr_status;
/* If the status is IO not found consider it as success */ /* If the status is IO not found consider it as success */
if (hdr_status == FCPIO_IO_NOT_FOUND) if (hdr_status == FCPIO_IO_NOT_FOUND)
CMD_ABTS_STATUS(sc) = FCPIO_SUCCESS; fnic_priv(sc)->abts_status = FCPIO_SUCCESS;
if (!(CMD_FLAGS(sc) & (FNIC_IO_ABORTED | FNIC_IO_DONE))) if (!(fnic_priv(sc)->flags & (FNIC_IO_ABORTED | FNIC_IO_DONE)))
atomic64_inc(&misc_stats->no_icmnd_itmf_cmpls); atomic64_inc(&misc_stats->no_icmnd_itmf_cmpls);
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
...@@ -1185,7 +1183,7 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1185,7 +1183,7 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
} else { } else {
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"abts cmpl, completing IO\n"); "abts cmpl, completing IO\n");
CMD_SP(sc) = NULL; fnic_priv(sc)->io_req = NULL;
sc->result = (DID_ERROR << 16); sc->result = (DID_ERROR << 16);
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
...@@ -1202,8 +1200,7 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1202,8 +1200,7 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
(u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[2] << 24 |
(u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[3] << 16 |
(u64)sc->cmnd[4] << 8 | sc->cmnd[5]), (u64)sc->cmnd[4] << 8 | sc->cmnd[5]),
(((u64)CMD_FLAGS(sc) << 32) | fnic_flags_and_state(sc));
CMD_STATE(sc)));
scsi_done(sc); scsi_done(sc);
atomic64_dec(&fnic_stats->io_stats.active_ios); atomic64_dec(&fnic_stats->io_stats.active_ios);
if (atomic64_read(&fnic->io_cmpl_skip)) if (atomic64_read(&fnic->io_cmpl_skip))
...@@ -1213,15 +1210,14 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1213,15 +1210,14 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
} }
} else if (id & FNIC_TAG_DEV_RST) { } else if (id & FNIC_TAG_DEV_RST) {
/* Completion of device reset */ /* Completion of device reset */
CMD_LR_STATUS(sc) = hdr_status; fnic_priv(sc)->lr_status = hdr_status;
if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { if (fnic_priv(sc)->state == FNIC_IOREQ_ABTS_PENDING) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
CMD_FLAGS(sc) |= FNIC_DEV_RST_ABTS_PENDING; fnic_priv(sc)->flags |= FNIC_DEV_RST_ABTS_PENDING;
FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler, FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler,
sc->device->host->host_no, id, sc, sc->device->host->host_no, id, sc,
jiffies_to_msecs(jiffies - start_time), jiffies_to_msecs(jiffies - start_time),
desc, 0, desc, 0, fnic_flags_and_state(sc));
(((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc)));
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"Terminate pending " "Terminate pending "
"dev reset cmpl recd. id %d status %s\n", "dev reset cmpl recd. id %d status %s\n",
...@@ -1229,14 +1225,13 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1229,14 +1225,13 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
fnic_fcpio_status_to_str(hdr_status)); fnic_fcpio_status_to_str(hdr_status));
return; return;
} }
if (CMD_FLAGS(sc) & FNIC_DEV_RST_TIMED_OUT) { if (fnic_priv(sc)->flags & FNIC_DEV_RST_TIMED_OUT) {
/* Need to wait for terminate completion */ /* Need to wait for terminate completion */
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler, FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler,
sc->device->host->host_no, id, sc, sc->device->host->host_no, id, sc,
jiffies_to_msecs(jiffies - start_time), jiffies_to_msecs(jiffies - start_time),
desc, 0, desc, 0, fnic_flags_and_state(sc));
(((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc)));
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"dev reset cmpl recd after time out. " "dev reset cmpl recd after time out. "
"id %d status %s\n", "id %d status %s\n",
...@@ -1244,8 +1239,8 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1244,8 +1239,8 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
fnic_fcpio_status_to_str(hdr_status)); fnic_fcpio_status_to_str(hdr_status));
return; return;
} }
CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE; fnic_priv(sc)->state = FNIC_IOREQ_CMD_COMPLETE;
CMD_FLAGS(sc) |= FNIC_DEV_RST_DONE; fnic_priv(sc)->flags |= FNIC_DEV_RST_DONE;
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"dev reset cmpl recd. id %d status %s\n", "dev reset cmpl recd. id %d status %s\n",
(int)(id & FNIC_TAG_MASK), (int)(id & FNIC_TAG_MASK),
...@@ -1257,7 +1252,7 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, ...@@ -1257,7 +1252,7 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic,
} else { } else {
shost_printk(KERN_ERR, fnic->lport->host, shost_printk(KERN_ERR, fnic->lport->host,
"Unexpected itmf io state %s tag %x\n", "Unexpected itmf io state %s tag %x\n",
fnic_ioreq_state_to_str(CMD_STATE(sc)), id); fnic_ioreq_state_to_str(fnic_priv(sc)->state), id);
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
} }
...@@ -1370,21 +1365,21 @@ static bool fnic_cleanup_io_iter(struct scsi_cmnd *sc, void *data, ...@@ -1370,21 +1365,21 @@ static bool fnic_cleanup_io_iter(struct scsi_cmnd *sc, void *data,
io_lock = fnic_io_lock_tag(fnic, tag); io_lock = fnic_io_lock_tag(fnic, tag);
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) && if ((fnic_priv(sc)->flags & FNIC_DEVICE_RESET) &&
!(CMD_FLAGS(sc) & FNIC_DEV_RST_DONE)) { !(fnic_priv(sc)->flags & FNIC_DEV_RST_DONE)) {
/* /*
* We will be here only when FW completes reset * We will be here only when FW completes reset
* without sending completions for outstanding ios. * without sending completions for outstanding ios.
*/ */
CMD_FLAGS(sc) |= FNIC_DEV_RST_DONE; fnic_priv(sc)->flags |= FNIC_DEV_RST_DONE;
if (io_req && io_req->dr_done) if (io_req && io_req->dr_done)
complete(io_req->dr_done); complete(io_req->dr_done);
else if (io_req && io_req->abts_done) else if (io_req && io_req->abts_done)
complete(io_req->abts_done); complete(io_req->abts_done);
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
return true; return true;
} else if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) { } else if (fnic_priv(sc)->flags & FNIC_DEVICE_RESET) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
return true; return true;
} }
...@@ -1393,7 +1388,7 @@ static bool fnic_cleanup_io_iter(struct scsi_cmnd *sc, void *data, ...@@ -1393,7 +1388,7 @@ static bool fnic_cleanup_io_iter(struct scsi_cmnd *sc, void *data,
goto cleanup_scsi_cmd; goto cleanup_scsi_cmd;
} }
CMD_SP(sc) = NULL; fnic_priv(sc)->io_req = NULL;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
...@@ -1417,7 +1412,7 @@ static bool fnic_cleanup_io_iter(struct scsi_cmnd *sc, void *data, ...@@ -1417,7 +1412,7 @@ static bool fnic_cleanup_io_iter(struct scsi_cmnd *sc, void *data,
atomic64_inc(&fnic_stats->io_stats.io_completions); atomic64_inc(&fnic_stats->io_stats.io_completions);
/* Complete the command to SCSI */ /* Complete the command to SCSI */
if (!(CMD_FLAGS(sc) & FNIC_IO_ISSUED)) if (!(fnic_priv(sc)->flags & FNIC_IO_ISSUED))
shost_printk(KERN_ERR, fnic->lport->host, shost_printk(KERN_ERR, fnic->lport->host,
"Calling done for IO not issued to fw: tag:0x%x sc:0x%p\n", "Calling done for IO not issued to fw: tag:0x%x sc:0x%p\n",
tag, sc); tag, sc);
...@@ -1429,7 +1424,7 @@ static bool fnic_cleanup_io_iter(struct scsi_cmnd *sc, void *data, ...@@ -1429,7 +1424,7 @@ static bool fnic_cleanup_io_iter(struct scsi_cmnd *sc, void *data,
(u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[2] << 24 |
(u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[3] << 16 |
(u64)sc->cmnd[4] << 8 | sc->cmnd[5]), (u64)sc->cmnd[4] << 8 | sc->cmnd[5]),
(((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); fnic_flags_and_state(sc));
scsi_done(sc); scsi_done(sc);
...@@ -1468,7 +1463,7 @@ void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq, ...@@ -1468,7 +1463,7 @@ void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq,
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
/* Get the IO context which this desc refers to */ /* Get the IO context which this desc refers to */
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
/* fnic interrupts are turned off by now */ /* fnic interrupts are turned off by now */
...@@ -1477,7 +1472,7 @@ void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq, ...@@ -1477,7 +1472,7 @@ void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq,
goto wq_copy_cleanup_scsi_cmd; goto wq_copy_cleanup_scsi_cmd;
} }
CMD_SP(sc) = NULL; fnic_priv(sc)->io_req = NULL;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
...@@ -1496,7 +1491,7 @@ void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq, ...@@ -1496,7 +1491,7 @@ void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq,
0, ((u64)sc->cmnd[0] << 32 | 0, ((u64)sc->cmnd[0] << 32 |
(u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 |
(u64)sc->cmnd[4] << 8 | sc->cmnd[5]), (u64)sc->cmnd[4] << 8 | sc->cmnd[5]),
(((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); fnic_flags_and_state(sc));
scsi_done(sc); scsi_done(sc);
} }
...@@ -1571,15 +1566,15 @@ static bool fnic_rport_abort_io_iter(struct scsi_cmnd *sc, void *data, ...@@ -1571,15 +1566,15 @@ static bool fnic_rport_abort_io_iter(struct scsi_cmnd *sc, void *data,
io_lock = fnic_io_lock_tag(fnic, abt_tag); io_lock = fnic_io_lock_tag(fnic, abt_tag);
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (!io_req || io_req->port_id != iter_data->port_id) { if (!io_req || io_req->port_id != iter_data->port_id) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
return true; return true;
} }
if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) && if ((fnic_priv(sc)->flags & FNIC_DEVICE_RESET) &&
(!(CMD_FLAGS(sc) & FNIC_DEV_RST_ISSUED))) { !(fnic_priv(sc)->flags & FNIC_DEV_RST_ISSUED)) {
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"fnic_rport_exch_reset dev rst not pending sc 0x%p\n", "fnic_rport_exch_reset dev rst not pending sc 0x%p\n",
sc); sc);
...@@ -1591,7 +1586,7 @@ static bool fnic_rport_abort_io_iter(struct scsi_cmnd *sc, void *data, ...@@ -1591,7 +1586,7 @@ static bool fnic_rport_abort_io_iter(struct scsi_cmnd *sc, void *data,
* Found IO that is still pending with firmware and * Found IO that is still pending with firmware and
* belongs to rport that went away * belongs to rport that went away
*/ */
if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { if (fnic_priv(sc)->state == FNIC_IOREQ_ABTS_PENDING) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
return true; return true;
} }
...@@ -1599,20 +1594,20 @@ static bool fnic_rport_abort_io_iter(struct scsi_cmnd *sc, void *data, ...@@ -1599,20 +1594,20 @@ static bool fnic_rport_abort_io_iter(struct scsi_cmnd *sc, void *data,
shost_printk(KERN_ERR, fnic->lport->host, shost_printk(KERN_ERR, fnic->lport->host,
"fnic_rport_exch_reset: io_req->abts_done is set " "fnic_rport_exch_reset: io_req->abts_done is set "
"state is %s\n", "state is %s\n",
fnic_ioreq_state_to_str(CMD_STATE(sc))); fnic_ioreq_state_to_str(fnic_priv(sc)->state));
} }
if (!(CMD_FLAGS(sc) & FNIC_IO_ISSUED)) { if (!(fnic_priv(sc)->flags & FNIC_IO_ISSUED)) {
shost_printk(KERN_ERR, fnic->lport->host, shost_printk(KERN_ERR, fnic->lport->host,
"rport_exch_reset " "rport_exch_reset "
"IO not yet issued %p tag 0x%x flags " "IO not yet issued %p tag 0x%x flags "
"%x state %d\n", "%x state %d\n",
sc, abt_tag, CMD_FLAGS(sc), CMD_STATE(sc)); sc, abt_tag, fnic_priv(sc)->flags, fnic_priv(sc)->state);
} }
old_ioreq_state = CMD_STATE(sc); old_ioreq_state = fnic_priv(sc)->state;
CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; fnic_priv(sc)->state = FNIC_IOREQ_ABTS_PENDING;
CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; fnic_priv(sc)->abts_status = FCPIO_INVALID_CODE;
if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) { if (fnic_priv(sc)->flags & FNIC_DEVICE_RESET) {
atomic64_inc(&reset_stats->device_reset_terminates); atomic64_inc(&reset_stats->device_reset_terminates);
abt_tag |= FNIC_TAG_DEV_RST; abt_tag |= FNIC_TAG_DEV_RST;
} }
...@@ -1638,15 +1633,15 @@ static bool fnic_rport_abort_io_iter(struct scsi_cmnd *sc, void *data, ...@@ -1638,15 +1633,15 @@ static bool fnic_rport_abort_io_iter(struct scsi_cmnd *sc, void *data,
* lun reset * lun reset
*/ */
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) if (fnic_priv(sc)->state == FNIC_IOREQ_ABTS_PENDING)
CMD_STATE(sc) = old_ioreq_state; fnic_priv(sc)->state = old_ioreq_state;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
} else { } else {
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) if (fnic_priv(sc)->flags & FNIC_DEVICE_RESET)
CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED; fnic_priv(sc)->flags |= FNIC_DEV_RST_TERM_ISSUED;
else else
CMD_FLAGS(sc) |= FNIC_IO_INTERNAL_TERM_ISSUED; fnic_priv(sc)->flags |= FNIC_IO_INTERNAL_TERM_ISSUED;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
atomic64_inc(&term_stats->terminates); atomic64_inc(&term_stats->terminates);
iter_data->term_cnt++; iter_data->term_cnt++;
...@@ -1754,9 +1749,9 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1754,9 +1749,9 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
FNIC_SCSI_DBG(KERN_DEBUG, FNIC_SCSI_DBG(KERN_DEBUG,
fnic->lport->host, fnic->lport->host,
"Abort Cmd called FCID 0x%x, LUN 0x%llx TAG %x flags %x\n", "Abort Cmd called FCID 0x%x, LUN 0x%llx TAG %x flags %x\n",
rport->port_id, sc->device->lun, tag, CMD_FLAGS(sc)); rport->port_id, sc->device->lun, tag, fnic_priv(sc)->flags);
CMD_FLAGS(sc) = FNIC_NO_FLAGS; fnic_priv(sc)->flags = FNIC_NO_FLAGS;
if (lp->state != LPORT_ST_READY || !(lp->link_up)) { if (lp->state != LPORT_ST_READY || !(lp->link_up)) {
ret = FAILED; ret = FAILED;
...@@ -1773,11 +1768,11 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1773,11 +1768,11 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
* happened, the completion wont actually complete the command * happened, the completion wont actually complete the command
* and it will be considered as an aborted command * and it will be considered as an aborted command
* *
* The CMD_SP will not be cleared except while holding io_req_lock. * .io_req will not be cleared except while holding io_req_lock.
*/ */
io_lock = fnic_io_lock_hash(fnic, sc); io_lock = fnic_io_lock_hash(fnic, sc);
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (!io_req) { if (!io_req) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
goto fnic_abort_cmd_end; goto fnic_abort_cmd_end;
...@@ -1785,7 +1780,7 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1785,7 +1780,7 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
io_req->abts_done = &tm_done; io_req->abts_done = &tm_done;
if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { if (fnic_priv(sc)->state == FNIC_IOREQ_ABTS_PENDING) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
goto wait_pending; goto wait_pending;
} }
...@@ -1814,9 +1809,9 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1814,9 +1809,9 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
* the completion wont be done till mid-layer, since abort * the completion wont be done till mid-layer, since abort
* has already started. * has already started.
*/ */
old_ioreq_state = CMD_STATE(sc); old_ioreq_state = fnic_priv(sc)->state;
CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; fnic_priv(sc)->state = FNIC_IOREQ_ABTS_PENDING;
CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; fnic_priv(sc)->abts_status = FCPIO_INVALID_CODE;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
...@@ -1838,9 +1833,9 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1838,9 +1833,9 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
if (fnic_queue_abort_io_req(fnic, tag, task_req, fc_lun.scsi_lun, if (fnic_queue_abort_io_req(fnic, tag, task_req, fc_lun.scsi_lun,
io_req)) { io_req)) {
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) if (fnic_priv(sc)->state == FNIC_IOREQ_ABTS_PENDING)
CMD_STATE(sc) = old_ioreq_state; fnic_priv(sc)->state = old_ioreq_state;
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (io_req) if (io_req)
io_req->abts_done = NULL; io_req->abts_done = NULL;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
...@@ -1848,10 +1843,10 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1848,10 +1843,10 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
goto fnic_abort_cmd_end; goto fnic_abort_cmd_end;
} }
if (task_req == FCPIO_ITMF_ABT_TASK) { if (task_req == FCPIO_ITMF_ABT_TASK) {
CMD_FLAGS(sc) |= FNIC_IO_ABTS_ISSUED; fnic_priv(sc)->flags |= FNIC_IO_ABTS_ISSUED;
atomic64_inc(&fnic_stats->abts_stats.aborts); atomic64_inc(&fnic_stats->abts_stats.aborts);
} else { } else {
CMD_FLAGS(sc) |= FNIC_IO_TERM_ISSUED; fnic_priv(sc)->flags |= FNIC_IO_TERM_ISSUED;
atomic64_inc(&fnic_stats->term_stats.terminates); atomic64_inc(&fnic_stats->term_stats.terminates);
} }
...@@ -1869,32 +1864,32 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1869,32 +1864,32 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
/* Check the abort status */ /* Check the abort status */
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (!io_req) { if (!io_req) {
atomic64_inc(&fnic_stats->io_stats.ioreq_null); atomic64_inc(&fnic_stats->io_stats.ioreq_null);
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_REQ_NULL; fnic_priv(sc)->flags |= FNIC_IO_ABT_TERM_REQ_NULL;
ret = FAILED; ret = FAILED;
goto fnic_abort_cmd_end; goto fnic_abort_cmd_end;
} }
io_req->abts_done = NULL; io_req->abts_done = NULL;
/* fw did not complete abort, timed out */ /* fw did not complete abort, timed out */
if (CMD_ABTS_STATUS(sc) == FCPIO_INVALID_CODE) { if (fnic_priv(sc)->abts_status == FCPIO_INVALID_CODE) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
if (task_req == FCPIO_ITMF_ABT_TASK) { if (task_req == FCPIO_ITMF_ABT_TASK) {
atomic64_inc(&abts_stats->abort_drv_timeouts); atomic64_inc(&abts_stats->abort_drv_timeouts);
} else { } else {
atomic64_inc(&term_stats->terminate_drv_timeouts); atomic64_inc(&term_stats->terminate_drv_timeouts);
} }
CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_TIMED_OUT; fnic_priv(sc)->flags |= FNIC_IO_ABT_TERM_TIMED_OUT;
ret = FAILED; ret = FAILED;
goto fnic_abort_cmd_end; goto fnic_abort_cmd_end;
} }
/* IO out of order */ /* IO out of order */
if (!(CMD_FLAGS(sc) & (FNIC_IO_ABORTED | FNIC_IO_DONE))) { if (!(fnic_priv(sc)->flags & (FNIC_IO_ABORTED | FNIC_IO_DONE))) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"Issuing Host reset due to out of order IO\n"); "Issuing Host reset due to out of order IO\n");
...@@ -1903,7 +1898,7 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1903,7 +1898,7 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
goto fnic_abort_cmd_end; goto fnic_abort_cmd_end;
} }
CMD_STATE(sc) = FNIC_IOREQ_ABTS_COMPLETE; fnic_priv(sc)->state = FNIC_IOREQ_ABTS_COMPLETE;
start_time = io_req->start_time; start_time = io_req->start_time;
/* /*
...@@ -1911,9 +1906,9 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1911,9 +1906,9 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
* free the io_req if successful. If abort fails, * free the io_req if successful. If abort fails,
* Device reset will clean the I/O. * Device reset will clean the I/O.
*/ */
if (CMD_ABTS_STATUS(sc) == FCPIO_SUCCESS) if (fnic_priv(sc)->abts_status == FCPIO_SUCCESS) {
CMD_SP(sc) = NULL; fnic_priv(sc)->io_req = NULL;
else { } else {
ret = FAILED; ret = FAILED;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
goto fnic_abort_cmd_end; goto fnic_abort_cmd_end;
...@@ -1939,7 +1934,7 @@ int fnic_abort_cmd(struct scsi_cmnd *sc) ...@@ -1939,7 +1934,7 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
0, ((u64)sc->cmnd[0] << 32 | 0, ((u64)sc->cmnd[0] << 32 |
(u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 |
(u64)sc->cmnd[4] << 8 | sc->cmnd[5]), (u64)sc->cmnd[4] << 8 | sc->cmnd[5]),
(((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); fnic_flags_and_state(sc));
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"Returning from abort cmd type %x %s\n", task_req, "Returning from abort cmd type %x %s\n", task_req,
...@@ -2030,7 +2025,7 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc, ...@@ -2030,7 +2025,7 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc,
io_lock = fnic_io_lock_tag(fnic, abt_tag); io_lock = fnic_io_lock_tag(fnic, abt_tag);
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (!io_req) { if (!io_req) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
return true; return true;
...@@ -2042,14 +2037,14 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc, ...@@ -2042,14 +2037,14 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc,
*/ */
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"Found IO in %s on lun\n", "Found IO in %s on lun\n",
fnic_ioreq_state_to_str(CMD_STATE(sc))); fnic_ioreq_state_to_str(fnic_priv(sc)->state));
if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { if (fnic_priv(sc)->state == FNIC_IOREQ_ABTS_PENDING) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
return true; return true;
} }
if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) && if ((fnic_priv(sc)->flags & FNIC_DEVICE_RESET) &&
(!(CMD_FLAGS(sc) & FNIC_DEV_RST_ISSUED))) { (!(fnic_priv(sc)->flags & FNIC_DEV_RST_ISSUED))) {
FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host,
"%s dev rst not pending sc 0x%p\n", __func__, "%s dev rst not pending sc 0x%p\n", __func__,
sc); sc);
...@@ -2060,8 +2055,8 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc, ...@@ -2060,8 +2055,8 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc,
if (io_req->abts_done) if (io_req->abts_done)
shost_printk(KERN_ERR, fnic->lport->host, shost_printk(KERN_ERR, fnic->lport->host,
"%s: io_req->abts_done is set state is %s\n", "%s: io_req->abts_done is set state is %s\n",
__func__, fnic_ioreq_state_to_str(CMD_STATE(sc))); __func__, fnic_ioreq_state_to_str(fnic_priv(sc)->state));
old_ioreq_state = CMD_STATE(sc); old_ioreq_state = fnic_priv(sc)->state;
/* /*
* Any pending IO issued prior to reset is expected to be * Any pending IO issued prior to reset is expected to be
* in abts pending state, if not we need to set * in abts pending state, if not we need to set
...@@ -2069,17 +2064,17 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc, ...@@ -2069,17 +2064,17 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc,
* When IO is completed, the IO will be handed over and * When IO is completed, the IO will be handed over and
* handled in this function. * handled in this function.
*/ */
CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; fnic_priv(sc)->state = FNIC_IOREQ_ABTS_PENDING;
BUG_ON(io_req->abts_done); BUG_ON(io_req->abts_done);
if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) { if (fnic_priv(sc)->flags & FNIC_DEVICE_RESET) {
abt_tag |= FNIC_TAG_DEV_RST; abt_tag |= FNIC_TAG_DEV_RST;
FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host,
"%s: dev rst sc 0x%p\n", __func__, sc); "%s: dev rst sc 0x%p\n", __func__, sc);
} }
CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; fnic_priv(sc)->abts_status = FCPIO_INVALID_CODE;
io_req->abts_done = &tm_done; io_req->abts_done = &tm_done;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
...@@ -2090,48 +2085,48 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc, ...@@ -2090,48 +2085,48 @@ static bool fnic_pending_aborts_iter(struct scsi_cmnd *sc,
FCPIO_ITMF_ABT_TASK_TERM, FCPIO_ITMF_ABT_TASK_TERM,
fc_lun.scsi_lun, io_req)) { fc_lun.scsi_lun, io_req)) {
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (io_req) if (io_req)
io_req->abts_done = NULL; io_req->abts_done = NULL;
if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) if (fnic_priv(sc)->state == FNIC_IOREQ_ABTS_PENDING)
CMD_STATE(sc) = old_ioreq_state; fnic_priv(sc)->state = old_ioreq_state;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
iter_data->ret = FAILED; iter_data->ret = FAILED;
return false; return false;
} else { } else {
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) if (fnic_priv(sc)->flags & FNIC_DEVICE_RESET)
CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED; fnic_priv(sc)->flags |= FNIC_DEV_RST_TERM_ISSUED;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
} }
CMD_FLAGS(sc) |= FNIC_IO_INTERNAL_TERM_ISSUED; fnic_priv(sc)->flags |= FNIC_IO_INTERNAL_TERM_ISSUED;
wait_for_completion_timeout(&tm_done, msecs_to_jiffies wait_for_completion_timeout(&tm_done, msecs_to_jiffies
(fnic->config.ed_tov)); (fnic->config.ed_tov));
/* Recheck cmd state to check if it is now aborted */ /* Recheck cmd state to check if it is now aborted */
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (!io_req) { if (!io_req) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_REQ_NULL; fnic_priv(sc)->flags |= FNIC_IO_ABT_TERM_REQ_NULL;
return true; return true;
} }
io_req->abts_done = NULL; io_req->abts_done = NULL;
/* if abort is still pending with fw, fail */ /* if abort is still pending with fw, fail */
if (CMD_ABTS_STATUS(sc) == FCPIO_INVALID_CODE) { if (fnic_priv(sc)->abts_status == FCPIO_INVALID_CODE) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_DONE; fnic_priv(sc)->flags |= FNIC_IO_ABT_TERM_DONE;
iter_data->ret = FAILED; iter_data->ret = FAILED;
return false; return false;
} }
CMD_STATE(sc) = FNIC_IOREQ_ABTS_COMPLETE; fnic_priv(sc)->state = FNIC_IOREQ_ABTS_COMPLETE;
/* original sc used for lr is handled by dev reset code */ /* original sc used for lr is handled by dev reset code */
if (sc != iter_data->lr_sc) if (sc != iter_data->lr_sc)
CMD_SP(sc) = NULL; fnic_priv(sc)->io_req = NULL;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
/* original sc used for lr is handled by dev reset code */ /* original sc used for lr is handled by dev reset code */
...@@ -2272,7 +2267,7 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2272,7 +2267,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
goto fnic_device_reset_end; goto fnic_device_reset_end;
} }
CMD_FLAGS(sc) = FNIC_DEVICE_RESET; fnic_priv(sc)->flags = FNIC_DEVICE_RESET;
/* Allocate tag if not present */ /* Allocate tag if not present */
if (unlikely(tag < 0)) { if (unlikely(tag < 0)) {
...@@ -2288,7 +2283,7 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2288,7 +2283,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
} }
io_lock = fnic_io_lock_hash(fnic, sc); io_lock = fnic_io_lock_hash(fnic, sc);
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
/* /*
* If there is a io_req attached to this command, then use it, * If there is a io_req attached to this command, then use it,
...@@ -2302,11 +2297,11 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2302,11 +2297,11 @@ int fnic_device_reset(struct scsi_cmnd *sc)
} }
memset(io_req, 0, sizeof(*io_req)); memset(io_req, 0, sizeof(*io_req));
io_req->port_id = rport->port_id; io_req->port_id = rport->port_id;
CMD_SP(sc) = (char *)io_req; fnic_priv(sc)->io_req = io_req;
} }
io_req->dr_done = &tm_done; io_req->dr_done = &tm_done;
CMD_STATE(sc) = FNIC_IOREQ_CMD_PENDING; fnic_priv(sc)->state = FNIC_IOREQ_CMD_PENDING;
CMD_LR_STATUS(sc) = FCPIO_INVALID_CODE; fnic_priv(sc)->lr_status = FCPIO_INVALID_CODE;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "TAG %x\n", tag); FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "TAG %x\n", tag);
...@@ -2317,13 +2312,13 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2317,13 +2312,13 @@ int fnic_device_reset(struct scsi_cmnd *sc)
*/ */
if (fnic_queue_dr_io_req(fnic, sc, io_req)) { if (fnic_queue_dr_io_req(fnic, sc, io_req)) {
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (io_req) if (io_req)
io_req->dr_done = NULL; io_req->dr_done = NULL;
goto fnic_device_reset_clean; goto fnic_device_reset_clean;
} }
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
CMD_FLAGS(sc) |= FNIC_DEV_RST_ISSUED; fnic_priv(sc)->flags |= FNIC_DEV_RST_ISSUED;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
/* /*
...@@ -2334,7 +2329,7 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2334,7 +2329,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT)); msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT));
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (!io_req) { if (!io_req) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
...@@ -2343,7 +2338,7 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2343,7 +2338,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
} }
io_req->dr_done = NULL; io_req->dr_done = NULL;
status = CMD_LR_STATUS(sc); status = fnic_priv(sc)->lr_status;
/* /*
* If lun reset not completed, bail out with failed. io_req * If lun reset not completed, bail out with failed. io_req
...@@ -2353,7 +2348,7 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2353,7 +2348,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
atomic64_inc(&reset_stats->device_reset_timeouts); atomic64_inc(&reset_stats->device_reset_timeouts);
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"Device reset timed out\n"); "Device reset timed out\n");
CMD_FLAGS(sc) |= FNIC_DEV_RST_TIMED_OUT; fnic_priv(sc)->flags |= FNIC_DEV_RST_TIMED_OUT;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
int_to_scsilun(sc->device->lun, &fc_lun); int_to_scsilun(sc->device->lun, &fc_lun);
/* /*
...@@ -2362,7 +2357,7 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2362,7 +2357,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
*/ */
while (1) { while (1) {
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
if (CMD_FLAGS(sc) & FNIC_DEV_RST_TERM_ISSUED) { if (fnic_priv(sc)->flags & FNIC_DEV_RST_TERM_ISSUED) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
break; break;
} }
...@@ -2375,8 +2370,8 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2375,8 +2370,8 @@ int fnic_device_reset(struct scsi_cmnd *sc)
msecs_to_jiffies(FNIC_ABT_TERM_DELAY_TIMEOUT)); msecs_to_jiffies(FNIC_ABT_TERM_DELAY_TIMEOUT));
} else { } else {
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED; fnic_priv(sc)->flags |= FNIC_DEV_RST_TERM_ISSUED;
CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; fnic_priv(sc)->state = FNIC_IOREQ_ABTS_PENDING;
io_req->abts_done = &tm_done; io_req->abts_done = &tm_done;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
...@@ -2387,13 +2382,13 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2387,13 +2382,13 @@ int fnic_device_reset(struct scsi_cmnd *sc)
} }
while (1) { while (1) {
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
if (!(CMD_FLAGS(sc) & FNIC_DEV_RST_DONE)) { if (!(fnic_priv(sc)->flags & FNIC_DEV_RST_DONE)) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
wait_for_completion_timeout(&tm_done, wait_for_completion_timeout(&tm_done,
msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT)); msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT));
break; break;
} else { } else {
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
io_req->abts_done = NULL; io_req->abts_done = NULL;
goto fnic_device_reset_clean; goto fnic_device_reset_clean;
} }
...@@ -2408,7 +2403,7 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2408,7 +2403,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
FNIC_SCSI_DBG(KERN_DEBUG, FNIC_SCSI_DBG(KERN_DEBUG,
fnic->lport->host, fnic->lport->host,
"Device reset completed - failed\n"); "Device reset completed - failed\n");
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
goto fnic_device_reset_clean; goto fnic_device_reset_clean;
} }
...@@ -2421,7 +2416,7 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2421,7 +2416,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
*/ */
if (fnic_clean_pending_aborts(fnic, sc, new_sc)) { if (fnic_clean_pending_aborts(fnic, sc, new_sc)) {
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
"Device reset failed" "Device reset failed"
" since could not abort all IOs\n"); " since could not abort all IOs\n");
...@@ -2430,14 +2425,14 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2430,14 +2425,14 @@ int fnic_device_reset(struct scsi_cmnd *sc)
/* Clean lun reset command */ /* Clean lun reset command */
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (io_req) if (io_req)
/* Completed, and successful */ /* Completed, and successful */
ret = SUCCESS; ret = SUCCESS;
fnic_device_reset_clean: fnic_device_reset_clean:
if (io_req) if (io_req)
CMD_SP(sc) = NULL; fnic_priv(sc)->io_req = NULL;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
...@@ -2453,7 +2448,7 @@ int fnic_device_reset(struct scsi_cmnd *sc) ...@@ -2453,7 +2448,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
0, ((u64)sc->cmnd[0] << 32 | 0, ((u64)sc->cmnd[0] << 32 |
(u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 |
(u64)sc->cmnd[4] << 8 | sc->cmnd[5]), (u64)sc->cmnd[4] << 8 | sc->cmnd[5]),
(((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); fnic_flags_and_state(sc));
/* free tag if it is allocated */ /* free tag if it is allocated */
if (unlikely(tag_gen_flag)) if (unlikely(tag_gen_flag))
...@@ -2698,7 +2693,7 @@ static bool fnic_abts_pending_iter(struct scsi_cmnd *sc, void *data, ...@@ -2698,7 +2693,7 @@ static bool fnic_abts_pending_iter(struct scsi_cmnd *sc, void *data,
io_lock = fnic_io_lock_hash(fnic, sc); io_lock = fnic_io_lock_hash(fnic, sc);
spin_lock_irqsave(io_lock, flags); spin_lock_irqsave(io_lock, flags);
io_req = (struct fnic_io_req *)CMD_SP(sc); io_req = fnic_priv(sc)->io_req;
if (!io_req) { if (!io_req) {
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
return true; return true;
...@@ -2710,8 +2705,8 @@ static bool fnic_abts_pending_iter(struct scsi_cmnd *sc, void *data, ...@@ -2710,8 +2705,8 @@ static bool fnic_abts_pending_iter(struct scsi_cmnd *sc, void *data,
*/ */
FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host,
"Found IO in %s on lun\n", "Found IO in %s on lun\n",
fnic_ioreq_state_to_str(CMD_STATE(sc))); fnic_ioreq_state_to_str(fnic_priv(sc)->state));
cmd_state = CMD_STATE(sc); cmd_state = fnic_priv(sc)->state;
spin_unlock_irqrestore(io_lock, flags); spin_unlock_irqrestore(io_lock, flags);
if (cmd_state == FNIC_IOREQ_ABTS_PENDING) if (cmd_state == FNIC_IOREQ_ABTS_PENDING)
iter_data->ret = 1; iter_data->ret = 1;
......
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