/* * Need to call kref_put for reference taken when initiate_abts * was called since abts_compl won't be called now that we've * cleaned up the task.
*/
kref_put(&io_req->refcount, qedf_release_cmd);
/* Clear in abort bit now that we're done with the command */
clear_bit(QEDF_CMD_IN_ABORT, &io_req->flags);
/* * Now that the original I/O and the ABTS are complete see * if we need to reconnect to the target.
*/
qedf_restart_rport(fcport); break; case QEDF_ELS: if (!qedf) {
QEDF_INFO(NULL, QEDF_LOG_IO, "qedf is NULL for ELS xid=0x%x.\n",
io_req->xid); return;
} /* ELS request no longer outstanding since it timed out */
clear_bit(QEDF_CMD_OUTSTANDING, &io_req->flags);
kref_get(&io_req->refcount); /* * Don't attempt to clean an ELS timeout as any subseqeunt * ABTS or cleanup requests just hang. For now just free * the resources of the original I/O and the RRQ
*/
QEDF_ERR(&(qedf->dbg_ctx), "ELS timeout, xid=0x%x.\n",
io_req->xid);
qedf_initiate_cleanup(io_req, true);
io_req->event = QEDF_IOREQ_EV_ELS_TMO; /* Call callback function to complete command */ if (io_req->cb_func && io_req->cb_arg) {
io_req->cb_func(io_req->cb_arg);
io_req->cb_arg = NULL;
}
kref_put(&io_req->refcount, qedf_release_cmd); break; case QEDF_SEQ_CLEANUP:
QEDF_ERR(&(qedf->dbg_ctx), "Sequence cleanup timeout, " "xid=0x%x.\n", io_req->xid);
qedf_initiate_cleanup(io_req, true);
io_req->event = QEDF_IOREQ_EV_ELS_TMO;
qedf_process_seq_cleanup_compl(qedf, NULL, io_req); break; default:
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Hit default case, xid=0x%x.\n", io_req->xid); break;
}
}
for (i = 0; i < num_ios; i++) {
io_req = &cmgr->cmds[i];
kfree(io_req->sgl_task_params);
kfree(io_req->task_params); /* Make sure we free per command sense buffer */ if (io_req->sense_buffer)
dma_free_coherent(&qedf->pdev->dev,
QEDF_SCSI_SENSE_BUFFERSIZE, io_req->sense_buffer,
io_req->sense_buffer_dma);
cancel_delayed_work_sync(&io_req->rrq_work);
}
/* Make sure num_queues is already set before calling this function */ if (!qedf->num_queues) {
QEDF_ERR(&(qedf->dbg_ctx), "num_queues is not set.\n"); return NULL;
}
/* Allocate DMA memory to hold sense buffer */
io_req->sense_buffer = dma_alloc_coherent(&qedf->pdev->dev,
QEDF_SCSI_SENSE_BUFFERSIZE, &io_req->sense_buffer_dma,
GFP_KERNEL); if (!io_req->sense_buffer) {
QEDF_ERR(&qedf->dbg_ctx, "Failed to alloc sense buffer.\n"); goto mem_err;
}
/* Allocate task parameters to pass to f/w init funcions */
io_req->task_params = kzalloc(sizeof(*io_req->task_params),
GFP_KERNEL); if (!io_req->task_params) {
QEDF_ERR(&(qedf->dbg_ctx), "Failed to allocate task_params for xid=0x%x\n",
i); goto mem_err;
}
/* * Allocate scatter/gather list info to pass to f/w init * functions.
*/
io_req->sgl_task_params = kzalloc( sizeof(struct scsi_sgl_task_params), GFP_KERNEL); if (!io_req->sgl_task_params) {
QEDF_ERR(&(qedf->dbg_ctx), "Failed to allocate sgl_task_params for xid=0x%x\n",
i); goto mem_err;
}
}
/* Allocate pool of io_bdts - one for each qedf_ioreq */
cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
GFP_KERNEL);
if (!cmgr->io_bdt_pool) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n"); goto mem_err;
}
for (i = 0; i < num_ios; i++) {
cmgr->io_bdt_pool[i] = kmalloc(sizeof(struct io_bdt),
GFP_KERNEL); if (!cmgr->io_bdt_pool[i]) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool[%d].\n", i); goto mem_err;
}
}
for (i = 0; i < num_ios; i++) {
bdt_info = cmgr->io_bdt_pool[i];
bdt_info->bd_tbl = dma_alloc_coherent(&qedf->pdev->dev,
QEDF_MAX_BDS_PER_CMD * sizeof(struct scsi_sge),
&bdt_info->bd_tbl_dma, GFP_KERNEL); if (!bdt_info->bd_tbl) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc bdt_tbl[%d].\n", i); goto mem_err;
}
}
atomic_set(&cmgr->free_list_cnt, num_ios);
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, "cmgr->free_list_cnt=%d.\n",
atomic_read(&cmgr->free_list_cnt));
if (io_req->cmd_type == QEDF_SCSI_CMD) {
QEDF_WARN(&fcport->qedf->dbg_ctx, "Cmd released called without scsi_done called, io_req %p xid=0x%x.\n",
io_req, io_req->xid);
WARN_ON(io_req->sc_cmd);
}
if (io_req->cmd_type == QEDF_ELS ||
io_req->cmd_type == QEDF_TASK_MGMT_CMD)
qedf_free_mp_resc(io_req);
/* * Intermediate s/g element so check if start address * is page aligned. Only required for writes and only if the * number of scatter/gather elements is 8 or more.
*/ if (io_req->sge_type == QEDF_IOREQ_UNKNOWN_SGE && (i) &&
(i != (sg_count - 1)) && sg_len < QEDF_PAGE_SIZE)
io_req->sge_type = QEDF_IOREQ_SLOW_SGE;
/* To catch a case where FAST and SLOW nothing is set, set FAST */ if (io_req->sge_type == QEDF_IOREQ_UNKNOWN_SGE)
io_req->sge_type = QEDF_IOREQ_FAST_SGE;
/* Fill in information for scatter/gather list */ if (io_req->cmd_type != QEDF_TASK_MGMT_CMD) {
bd_count = bd_tbl->bd_valid;
io_req->sgl_task_params->sgl = bd_tbl->bd_tbl;
io_req->sgl_task_params->sgl_phys_addr.lo =
U64_LO(bd_tbl->bd_tbl_dma);
io_req->sgl_task_params->sgl_phys_addr.hi =
U64_HI(bd_tbl->bd_tbl_dma);
io_req->sgl_task_params->num_sges = bd_count;
io_req->sgl_task_params->total_buffer_size =
scsi_bufflen(io_req->sc_cmd); if (io_req->sge_type == QEDF_IOREQ_SLOW_SGE)
io_req->sgl_task_params->small_mid_sge = 1; else
io_req->sgl_task_params->small_mid_sge = 0;
}
/* Fill in physical address of sense buffer */
sense_data_buffer_phys_addr.lo = U64_LO(io_req->sense_buffer_dma);
sense_data_buffer_phys_addr.hi = U64_HI(io_req->sense_buffer_dma);
/* fill FCP_CMND IU */
qedf_build_fcp_cmnd(io_req, (struct fcp_cmnd *)tmp_fcp_cmnd);
/* Swap fcp_cmnd since FC is big endian */
cnt = sizeof(struct fcp_cmnd) / sizeof(u32); for (i = 0; i < cnt; i++) {
tmp_fcp_cmnd[i] = cpu_to_be32(tmp_fcp_cmnd[i]);
}
memcpy(fcp_cmnd, tmp_fcp_cmnd, sizeof(struct fcp_cmnd));
/* Setup the task from io_req for easy reference */
io_req->task = task_ctx;
/* Setup the fields for fcoe_task_params */
io_req->task_params->context = task_ctx;
io_req->task_params->sqe = sqe;
io_req->task_params->task_type = FCOE_TASK_TYPE_MIDPATH;
io_req->task_params->tx_io_size = io_req->data_xfer_len; /* rx_io_size tells the f/w how large a response buffer we have */
io_req->task_params->rx_io_size = PAGE_SIZE;
io_req->task_params->conn_cid = fcport->fw_cid;
io_req->task_params->itid = io_req->xid; /* Return middle path commands on CQ 0 */
io_req->task_params->cq_rss_number = 0;
io_req->task_params->is_tape_device = fcport->dev_type;
fc_hdr = &(mp_req->req_fc_hdr); /* Set OX_ID and RX_ID based on driver task id */
fc_hdr->fh_ox_id = io_req->xid;
fc_hdr->fh_rx_id = htons(0xffff);
/* Set up FC header information */
task_fc_hdr.parameter = fc_hdr->fh_parm_offset;
task_fc_hdr.r_ctl = fc_hdr->fh_r_ctl;
task_fc_hdr.type = fc_hdr->fh_type;
task_fc_hdr.cs_ctl = fc_hdr->fh_cs_ctl;
task_fc_hdr.df_ctl = fc_hdr->fh_df_ctl;
task_fc_hdr.rx_id = fc_hdr->fh_rx_id;
task_fc_hdr.ox_id = fc_hdr->fh_ox_id;
/* Set up s/g list parameters for request buffer */
tx_sgl_task_params.sgl = mp_req->mp_req_bd;
tx_sgl_task_params.sgl_phys_addr.lo = U64_LO(mp_req->mp_req_bd_dma);
tx_sgl_task_params.sgl_phys_addr.hi = U64_HI(mp_req->mp_req_bd_dma);
tx_sgl_task_params.num_sges = 1; /* Set PAGE_SIZE for now since sg element is that size ??? */
tx_sgl_task_params.total_buffer_size = io_req->data_xfer_len;
tx_sgl_task_params.small_mid_sge = 0;
/* Set up s/g list parameters for request buffer */
rx_sgl_task_params.sgl = mp_req->mp_resp_bd;
rx_sgl_task_params.sgl_phys_addr.lo = U64_LO(mp_req->mp_resp_bd_dma);
rx_sgl_task_params.sgl_phys_addr.hi = U64_HI(mp_req->mp_resp_bd_dma);
rx_sgl_task_params.num_sges = 1; /* Set PAGE_SIZE for now since sg element is that size ??? */
rx_sgl_task_params.total_buffer_size = PAGE_SIZE;
rx_sgl_task_params.small_mid_sge = 0;
/* * Last arg is 0 as previous code did not set that we wanted the * fc header information.
*/
init_initiator_midpath_unsolicited_fcoe_task(io_req->task_params,
&task_fc_hdr,
&tx_sgl_task_params,
&rx_sgl_task_params, 0);
}
/* Presumed that fcport->rport_lock is held */
u16 qedf_get_sqe_idx(struct qedf_rport *fcport)
{
uint16_t total_sqe = (fcport->sq_mem_size)/(sizeof(struct fcoe_wqe));
u16 rval;
rval = fcport->sq_prod_idx;
/* Adjust ring index */
fcport->sq_prod_idx++;
fcport->fw_sq_prod_idx++; if (fcport->sq_prod_idx == total_sqe)
fcport->sq_prod_idx = 0;
dbell.sq_prod = fcport->fw_sq_prod_idx; /* wmb makes sure that the BDs data is updated before updating the * producer, otherwise FW may read old data from the BDs.
*/
wmb();
barrier();
writel(*(u32 *)&dbell, fcport->p_doorbell); /* * Fence required to flush the write combined buffer, since another * CPU may write to the same doorbell address and data may be lost * due to relaxed order nature of write combined bar.
*/
wmb();
}
/* Build buffer descriptor list for firmware from sg list */ if (qedf_build_bd_list_from_sg(io_req)) {
QEDF_ERR(&(qedf->dbg_ctx), "BD list creation failed.\n"); /* Release cmd will release io_req, but sc_cmd is assigned */
io_req->sc_cmd = NULL;
kref_put(&io_req->refcount, qedf_release_cmd); return -EAGAIN;
}
if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags) ||
test_bit(QEDF_RPORT_UPLOADING_CONNECTION, &fcport->flags)) {
QEDF_ERR(&(qedf->dbg_ctx), "Session not offloaded yet.\n"); /* Release cmd will release io_req, but sc_cmd is assigned */
io_req->sc_cmd = NULL;
kref_put(&io_req->refcount, qedf_release_cmd); return -EINVAL;
}
/* Record LUN number for later use if we need them */
io_req->lun = (int)sc_cmd->device->lun;
/* Retry command if we are doing a qed drain operation */ if (test_bit(QEDF_DRAIN_ACTIVE, &qedf->flags)) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Drain active.\n");
rc = SCSI_MLQUEUE_HOST_BUSY; goto exit_qcmd;
}
/* rport and tgt are allocated together, so tgt should be non-NULL */
fcport = (struct qedf_rport *)&rp[1];
if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags) ||
test_bit(QEDF_RPORT_UPLOADING_CONNECTION, &fcport->flags)) { /* * Session is not offloaded yet. Let SCSI-ml retry * the command.
*/
rc = SCSI_MLQUEUE_TARGET_BUSY; goto exit_qcmd;
}
atomic_inc(&fcport->ios_to_queue);
if (fcport->retry_delay_timestamp) { /* Take fcport->rport_lock for resetting the delay_timestamp */
spin_lock_irqsave(&fcport->rport_lock, flags); if (time_after(jiffies, fcport->retry_delay_timestamp)) {
fcport->retry_delay_timestamp = 0;
} else {
spin_unlock_irqrestore(&fcport->rport_lock, flags); /* If retry_delay timer is active, flow off the ML */
rc = SCSI_MLQUEUE_TARGET_BUSY;
atomic_dec(&fcport->ios_to_queue); goto exit_qcmd;
}
spin_unlock_irqrestore(&fcport->rport_lock, flags);
}
/* Take fcport->rport_lock for posting to fcport send queue */
spin_lock_irqsave(&fcport->rport_lock, flags); if (qedf_post_io_req(fcport, io_req)) {
QEDF_WARN(&(qedf->dbg_ctx), "Unable to post io_req\n"); /* Return SQE to pool */
atomic_inc(&fcport->free_sqes);
rc = SCSI_MLQUEUE_HOST_BUSY;
}
spin_unlock_irqrestore(&fcport->rport_lock, flags);
atomic_dec(&fcport->ios_to_queue);
/* fetch fcp_rsp_code */ if ((fcp_rsp_len == 4) || (fcp_rsp_len == 8)) { /* Only for task management function */
io_req->fcp_rsp_code = rsp_info[3];
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, "fcp_rsp_code = %d\n", io_req->fcp_rsp_code); /* Adjust sense-data location. */
sense_data += fcp_rsp_len;
}
if (fcp_sns_len > SCSI_SENSE_BUFFERSIZE) {
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, "Truncating sense buffer\n");
fcp_sns_len = SCSI_SENSE_BUFFERSIZE;
}
/* The sense buffer can be NULL for TMF commands */ if (sc_cmd && sc_cmd->sense_buffer) {
memset(sc_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); if (fcp_sns_len)
memcpy(sc_cmd->sense_buffer, sense_data,
fcp_sns_len);
}
}
if (!sc_cmd) {
QEDF_WARN(&(qedf->dbg_ctx), "sc_cmd is NULL!\n"); return;
}
if (!qedf_priv(sc_cmd)->io_req) {
QEDF_WARN(&(qedf->dbg_ctx), "io_req is NULL, returned in another context.\n"); return;
}
if (!sc_cmd->device) {
QEDF_ERR(&qedf->dbg_ctx, "Device for sc_cmd %p is NULL.\n", sc_cmd); return;
}
if (!scsi_cmd_to_rq(sc_cmd)->q) {
QEDF_WARN(&(qedf->dbg_ctx), "request->q is NULL so request " "is not valid, sc_cmd=%p.\n", sc_cmd); return;
}
fcport = io_req->fcport;
/* * When flush is active, let the cmds be completed from the cleanup * context
*/ if (test_bit(QEDF_RPORT_IN_TARGET_RESET, &fcport->flags) ||
(test_bit(QEDF_RPORT_IN_LUN_RESET, &fcport->flags) &&
sc_cmd->device->lun == (u64)fcport->lun_reset_lun)) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Dropping good completion xid=0x%x as fcport is flushing",
io_req->xid); return;
}
if (io_req->cdb_status == SAM_STAT_TASK_SET_FULL ||
io_req->cdb_status == SAM_STAT_BUSY) { /* * Check whether we need to set retry_delay at * all based on retry_delay module parameter * and the status qualifier.
*/
if (qedf_retry_delay)
chk_scope = 1; /* Record stats */ if (io_req->cdb_status ==
SAM_STAT_TASK_SET_FULL)
qedf->task_set_fulls++; else
qedf->busy++;
}
} if (io_req->fcp_resid)
scsi_set_resid(sc_cmd, io_req->fcp_resid);
if (chk_scope == 1) { if ((scope == 1 || scope == 2) &&
(qualifier > 0 && qualifier <= 0x3FEF)) { /* Check we don't go over the max */ if (qualifier > QEDF_RETRY_DELAY_MAX) {
qualifier = QEDF_RETRY_DELAY_MAX;
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "qualifier = %d\n",
(fcp_rsp->retry_delay_timer &
0x3FFF));
}
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Scope = %d and qualifier = %d",
scope, qualifier); /* Take fcport->rport_lock to * update the retry_delay_timestamp
*/
spin_lock_irqsave(&fcport->rport_lock, flags);
fcport->retry_delay_timestamp =
jiffies + (qualifier * HZ / 10);
spin_unlock_irqrestore(&fcport->rport_lock,
flags);
} else {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "combination of scope = %d and qualifier = %d is not handled in qedf.\n",
scope, qualifier);
}
} break; default:
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, "fcp_status=%d.\n",
io_req->fcp_status); break;
}
out: if (qedf_io_tracing)
qedf_trace_io(fcport, io_req, QEDF_IO_TRACE_RSP);
/* * We wait till the end of the function to clear the * outstanding bit in case we need to send an abort
*/
clear_bit(QEDF_CMD_OUTSTANDING, &io_req->flags);
/* Return a SCSI command in some other context besides a normal completion */ void qedf_scsi_done(struct qedf_ctx *qedf, struct qedf_ioreq *io_req, int result)
{ struct scsi_cmnd *sc_cmd; int refcount;
if (!io_req) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "io_req is NULL\n"); return;
}
bad_scsi_ptr: /* * Clear the io_req->sc_cmd backpointer so we don't try to process * this again
*/
io_req->sc_cmd = NULL;
kref_put(&io_req->refcount, qedf_release_cmd); /* ID: 001 */
}
/* * Handle warning type CQE completions. This is mainly used for REC timer * popping.
*/ void qedf_process_warning_compl(struct qedf_ctx *qedf, struct fcoe_cqe *cqe, struct qedf_ioreq *io_req)
{ int rval, i; struct qedf_rport *fcport = io_req->fcport;
u64 err_warn_bit_map;
u8 err_warn = 0xff;
if (!cqe) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "cqe is NULL for io_req %p xid=0x%x\n",
io_req, io_req->xid); return;
}
/* Normalize the error bitmap value to an just an unsigned int */
err_warn_bit_map = (u64)
((u64)cqe->cqe_info.err_info.err_warn_bitmap_hi << 32) |
(u64)cqe->cqe_info.err_info.err_warn_bitmap_lo; for (i = 0; i < 64; i++) { if (err_warn_bit_map & (u64)((u64)1 << i)) {
err_warn = i; break;
}
}
/* Check if REC TOV expired if this is a tape device */ if (fcport->dev_type == QEDF_RPORT_TYPE_TAPE) { if (err_warn ==
FCOE_WARNING_CODE_REC_TOV_TIMER_EXPIRATION) {
QEDF_ERR(&(qedf->dbg_ctx), "REC timer expired.\n"); if (!test_bit(QEDF_CMD_SRR_SENT, &io_req->flags)) {
io_req->rx_buf_off =
cqe->cqe_info.err_info.rx_buf_off;
io_req->tx_buf_off =
cqe->cqe_info.err_info.tx_buf_off;
io_req->rx_id = cqe->cqe_info.err_info.rx_id;
rval = qedf_send_rec(io_req); /* * We only want to abort the io_req if we * can't queue the REC command as we want to * keep the exchange open for recovery.
*/ if (rval) goto send_abort;
} return;
}
}
send_abort:
init_completion(&io_req->abts_done);
rval = qedf_initiate_abts(io_req, true); if (rval)
QEDF_ERR(&(qedf->dbg_ctx), "Failed to queue ABTS.\n");
}
/* Cleanup a command when we receive an error detection completion */ void qedf_process_error_detect(struct qedf_ctx *qedf, struct fcoe_cqe *cqe, struct qedf_ioreq *io_req)
{ int rval;
if (io_req == NULL) {
QEDF_INFO(NULL, QEDF_LOG_IO, "io_req is NULL.\n"); return;
}
if (io_req->fcport == NULL) {
QEDF_INFO(NULL, QEDF_LOG_IO, "fcport is NULL.\n"); return;
}
if (!cqe) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "cqe is NULL for io_req %p\n", io_req); return;
}
/* When flush is active, let the cmds be flushed out from the cleanup context */ if (test_bit(QEDF_RPORT_IN_TARGET_RESET, &io_req->fcport->flags) ||
(test_bit(QEDF_RPORT_IN_LUN_RESET, &io_req->fcport->flags) &&
io_req->sc_cmd->device->lun == (u64)io_req->fcport->lun_reset_lun)) {
QEDF_ERR(&qedf->dbg_ctx, "Dropping EQE for xid=0x%x as fcport is flushing",
io_req->xid); return;
}
if (qedf->stop_io_on_error) {
qedf_stop_all_io(qedf); return;
}
init_completion(&io_req->abts_done);
rval = qedf_initiate_abts(io_req, true); if (rval)
QEDF_ERR(&(qedf->dbg_ctx), "Failed to queue ABTS.\n");
}
/* * Need to distinguish this from a timeout when calling the * els_req->cb_func.
*/
els_req->event = QEDF_IOREQ_EV_ELS_FLUSH;
clear_bit(QEDF_CMD_OUTSTANDING, &els_req->flags);
/* Cancel the timer */
cancel_delayed_work_sync(&els_req->timeout_work);
/* Call callback function to complete command */ if (els_req->cb_func && els_req->cb_arg) {
els_req->cb_func(els_req->cb_arg);
els_req->cb_arg = NULL;
}
/* Release kref for original initiate_els */
kref_put(&els_req->refcount, qedf_release_cmd);
}
/* A value of -1 for lun is a wild card that means flush all * active SCSI I/Os for the target.
*/ void qedf_flush_active_ios(struct qedf_rport *fcport, u64 lun)
{ struct qedf_ioreq *io_req; struct qedf_ctx *qedf; struct qedf_cmd_mgr *cmd_mgr; int i, rc; unsignedlong flags; int flush_cnt = 0; int wait_cnt = 100; int refcount = 0;
if (!fcport) {
QEDF_ERR(NULL, "fcport is NULL\n"); return;
}
/* Check that fcport is still offloaded */ if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
QEDF_ERR(NULL, "fcport is no longer offloaded.\n"); return;
}
qedf = fcport->qedf;
if (!qedf) {
QEDF_ERR(NULL, "qedf is NULL.\n"); return;
}
/* Only wait for all commands to be queued in the Upload context */ if (test_bit(QEDF_RPORT_UPLOADING_CONNECTION, &fcport->flags) &&
(lun == -1)) { while (atomic_read(&fcport->ios_to_queue)) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Waiting for %d I/Os to be queued\n",
atomic_read(&fcport->ios_to_queue)); if (wait_cnt == 0) {
QEDF_ERR(NULL, "%d IOs request could not be queued\n",
atomic_read(&fcport->ios_to_queue));
}
msleep(20);
wait_cnt--;
}
}
for (i = 0; i < FCOE_PARAMS_NUM_TASKS; i++) {
io_req = &cmd_mgr->cmds[i];
if (!io_req) continue; if (!io_req->fcport) continue;
spin_lock_irqsave(&cmd_mgr->lock, flags);
if (io_req->alloc) { if (!test_bit(QEDF_CMD_OUTSTANDING, &io_req->flags)) { if (io_req->cmd_type == QEDF_SCSI_CMD)
QEDF_ERR(&qedf->dbg_ctx, "Allocated but not queued, xid=0x%x\n",
io_req->xid);
}
spin_unlock_irqrestore(&cmd_mgr->lock, flags);
} else {
spin_unlock_irqrestore(&cmd_mgr->lock, flags); continue;
}
if (io_req->fcport != fcport) continue;
/* In case of ABTS, CMD_OUTSTANDING is cleared on ABTS response, * but RRQ is still pending. * Workaround: Within qedf_send_rrq, we check if the fcport is * NULL, and we drop the ref on the io_req to clean it up.
*/ if (!test_bit(QEDF_CMD_OUTSTANDING, &io_req->flags)) {
refcount = kref_read(&io_req->refcount);
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Not outstanding, xid=0x%x, cmd_type=%d refcount=%d.\n",
io_req->xid, io_req->cmd_type, refcount); /* If RRQ work has been queue, try to cancel it and * free the io_req
*/ if (atomic_read(&io_req->state) ==
QEDFC_CMD_ST_RRQ_WAIT) { if (cancel_delayed_work_sync
(&io_req->rrq_work)) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Putting reference for pending RRQ work xid=0x%x.\n",
io_req->xid); /* ID: 003 */
kref_put(&io_req->refcount,
qedf_release_cmd);
}
} continue;
}
/* Only consider flushing ELS during target reset */ if (io_req->cmd_type == QEDF_ELS &&
lun == -1) {
rc = kref_get_unless_zero(&io_req->refcount); if (!rc) {
QEDF_ERR(&(qedf->dbg_ctx), "Could not get kref for ELS io_req=0x%p xid=0x%x.\n",
io_req, io_req->xid); continue;
}
qedf_initiate_cleanup(io_req, false);
flush_cnt++;
qedf_flush_els_req(qedf, io_req);
/* * Release the kref and go back to the top of the * loop.
*/ goto free_cmd;
}
if (io_req->cmd_type == QEDF_ABTS) { /* ID: 004 */
rc = kref_get_unless_zero(&io_req->refcount); if (!rc) {
QEDF_ERR(&(qedf->dbg_ctx), "Could not get kref for abort io_req=0x%p xid=0x%x.\n",
io_req, io_req->xid); continue;
} if (lun != -1 && io_req->lun != lun) goto free_cmd;
if (cancel_delayed_work_sync(&io_req->rrq_work)) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Putting ref for cancelled RRQ work xid=0x%x.\n",
io_req->xid);
kref_put(&io_req->refcount, qedf_release_cmd);
}
if (cancel_delayed_work_sync(&io_req->timeout_work)) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Putting ref for cancelled tmo work xid=0x%x.\n",
io_req->xid);
qedf_initiate_cleanup(io_req, true); /* Notify eh_abort handler that ABTS is * complete
*/
complete(&io_req->abts_done);
clear_bit(QEDF_CMD_IN_ABORT, &io_req->flags); /* ID: 002 */
kref_put(&io_req->refcount, qedf_release_cmd);
}
flush_cnt++; goto free_cmd;
}
if (!io_req->sc_cmd) continue; if (!io_req->sc_cmd->device) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Device backpointer NULL for sc_cmd=%p.\n",
io_req->sc_cmd); /* Put reference for non-existent scsi_cmnd */
io_req->sc_cmd = NULL;
qedf_initiate_cleanup(io_req, false);
kref_put(&io_req->refcount, qedf_release_cmd); continue;
}
/* * Use kref_get_unless_zero in the unlikely case the command * we're about to flush was completed in the normal SCSI path
*/
rc = kref_get_unless_zero(&io_req->refcount); if (!rc) {
QEDF_ERR(&(qedf->dbg_ctx), "Could not get kref for " "io_req=0x%p xid=0x%x\n", io_req, io_req->xid); continue;
}
/* This was added at a point when we were scheduling abts_compl & * cleanup_compl on different CPUs and there was a possibility of * the io_req to be freed from the other context before we got here.
*/ if (!fcport) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Dropping ABTS completion xid=0x%x as fcport is NULL",
io_req->xid); return;
}
/* * When flush is active, let the cmds be completed from the cleanup * context
*/ if (test_bit(QEDF_RPORT_IN_TARGET_RESET, &fcport->flags) ||
test_bit(QEDF_RPORT_IN_LUN_RESET, &fcport->flags)) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO, "Dropping ABTS completion xid=0x%x as fcport is flushing",
io_req->xid); return;
}
if (!cancel_delayed_work(&io_req->timeout_work)) {
QEDF_ERR(&qedf->dbg_ctx, "Wasn't able to cancel abts timeout work.\n");
}
switch (r_ctl) { case FC_RCTL_BA_ACC:
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_SCSI_TM, "ABTS response - ACC Send RRQ after R_A_TOV\n");
io_req->event = QEDF_IOREQ_EV_ABORT_SUCCESS;
rc = kref_get_unless_zero(&io_req->refcount); /* ID: 003 */ if (!rc) {
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_SCSI_TM, "kref is already zero so ABTS was already completed or flushed xid=0x%x.\n",
io_req->xid); return;
} /* * Dont release this cmd yet. It will be relesed * after we get RRQ response
*/
queue_delayed_work(qedf->dpc_wq, &io_req->rrq_work,
msecs_to_jiffies(qedf->lport->r_a_tov));
atomic_set(&io_req->state, QEDFC_CMD_ST_RRQ_WAIT); break; /* For error cases let the cleanup return the command */ case FC_RCTL_BA_RJT:
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_SCSI_TM, "ABTS response - RJT\n");
io_req->event = QEDF_IOREQ_EV_ABORT_FAILED; break; default:
QEDF_ERR(&(qedf->dbg_ctx), "Unknown ABTS response\n"); break;
}
clear_bit(QEDF_CMD_IN_ABORT, &io_req->flags);
if (io_req->sc_cmd) { if (!io_req->return_scsi_cmd_on_abts)
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_SCSI_TM, "Not call scsi_done for xid=0x%x.\n",
io_req->xid); if (io_req->return_scsi_cmd_on_abts)
qedf_scsi_done(qedf, io_req, DID_ERROR);
}
/* Notify eh_abort handler that ABTS is complete */
complete(&io_req->abts_done);
/* * MP buffer is either a task mgmt command or an ELS. * So the assumption is that it consumes a single bd * entry in the bd table
*/
mp_resp_bd = mp_req->mp_resp_bd;
addr = mp_req->resp_buf_dma;
mp_resp_bd->sge_addr.lo = U64_LO(addr);
mp_resp_bd->sge_addr.hi = U64_HI(addr);
mp_resp_bd->sge_len = QEDF_PAGE_SIZE;
return 0;
}
/* * Last ditch effort to clear the port if it's stuck. Used only after a * cleanup task times out.
*/ staticvoid qedf_drain_request(struct qedf_ctx *qedf)
{ if (test_bit(QEDF_DRAIN_ACTIVE, &qedf->flags)) {
QEDF_ERR(&(qedf->dbg_ctx), "MCP drain already active.\n"); return;
}
/* Set bit to return all queuecommand requests as busy */
set_bit(QEDF_DRAIN_ACTIVE, &qedf->flags);
/* Call qed drain request for function. Should be synchronous */
qed_ops->common->drain(qedf->cdev);
/* Settle time for CQEs to be returned */
msleep(100);
/* Unplug and continue */
clear_bit(QEDF_DRAIN_ACTIVE, &qedf->flags);
}
/* * Returns SUCCESS if the cleanup task does not timeout, otherwise return * FAILURE.
*/ int qedf_initiate_cleanup(struct qedf_ioreq *io_req, bool return_scsi_cmd_on_abts)
{ struct qedf_rport *fcport; struct qedf_ctx *qedf; int tmo = 0; int rc = SUCCESS; unsignedlong flags; struct fcoe_wqe *sqe;
u16 sqe_idx; int refcount = 0;
fcport = io_req->fcport; if (!fcport) {
QEDF_ERR(NULL, "fcport is NULL.\n"); return SUCCESS;
}
/* Sanity check qedf_rport before dereferencing any pointers */ if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
QEDF_ERR(NULL, "tgt not offloaded\n"); return SUCCESS;
}
qedf = fcport->qedf; if (!qedf) {
QEDF_ERR(NULL, "qedf is NULL.\n"); return SUCCESS;
}
if (io_req->cmd_type == QEDF_ELS) { goto process_els;
}
if (!test_bit(QEDF_CMD_OUTSTANDING, &io_req->flags) ||
test_and_set_bit(QEDF_CMD_IN_CLEANUP, &io_req->flags)) {
QEDF_ERR(&(qedf->dbg_ctx), "io_req xid=0x%x already in " "cleanup processing or already completed.\n",
io_req->xid); return SUCCESS;
}
set_bit(QEDF_CMD_IN_CLEANUP, &io_req->flags);
process_els: /* Ensure room on SQ */ if (!atomic_read(&fcport->free_sqes)) {
QEDF_ERR(&(qedf->dbg_ctx), "No SQ entries available\n"); /* Need to make sure we clear the flag since it was set */
clear_bit(QEDF_CMD_IN_CLEANUP, &io_req->flags); return FAILED;
}
if (io_req->cmd_type == QEDF_CLEANUP) {
QEDF_ERR(&qedf->dbg_ctx, "io_req=0x%x is already a cleanup command cmd_type=%d.\n",
io_req->xid, io_req->cmd_type);
clear_bit(QEDF_CMD_IN_CLEANUP, &io_req->flags); return SUCCESS;
}
/* Cleanup cmds re-use the same TID as the original I/O */
spin_lock_irqsave(&fcport->rport_lock, flags);
io_req->cmd_type = QEDF_CLEANUP;
spin_unlock_irqrestore(&fcport->rport_lock, flags);
io_req->return_scsi_cmd_on_abts = return_scsi_cmd_on_abts;
if (!tmo) {
rc = FAILED; /* Timeout case */
QEDF_ERR(&(qedf->dbg_ctx), "Cleanup command timeout, " "xid=%x.\n", io_req->xid);
clear_bit(QEDF_CMD_IN_CLEANUP, &io_req->flags); /* Issue a drain request if cleanup task times out */
QEDF_ERR(&(qedf->dbg_ctx), "Issuing MCP drain request.\n");
qedf_drain_request(qedf);
}
/* If it TASK MGMT handle it, reference will be decreased * in qedf_execute_tmf
*/ if (io_req->tm_flags == FCP_TMF_LUN_RESET ||
io_req->tm_flags == FCP_TMF_TGT_RESET) {
clear_bit(QEDF_CMD_OUTSTANDING, &io_req->flags);
io_req->sc_cmd = NULL;
kref_put(&io_req->refcount, qedf_release_cmd);
complete(&io_req->tm_done);
}
if (io_req->sc_cmd) { if (!io_req->return_scsi_cmd_on_abts)
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_SCSI_TM, "Not call scsi_done for xid=0x%x.\n",
io_req->xid); if (io_req->return_scsi_cmd_on_abts)
qedf_scsi_done(qedf, io_req, DID_ERROR);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.