161d8658bSDupuis, Chad /* 261d8658bSDupuis, Chad * QLogic FCoE Offload Driver 361d8658bSDupuis, Chad * Copyright (c) 2016 Cavium Inc. 461d8658bSDupuis, Chad * 561d8658bSDupuis, Chad * This software is available under the terms of the GNU General Public License 661d8658bSDupuis, Chad * (GPL) Version 2, available from the file COPYING in the main directory of 761d8658bSDupuis, Chad * this source tree. 861d8658bSDupuis, Chad */ 961d8658bSDupuis, Chad #include "qedf.h" 1061d8658bSDupuis, Chad 1161d8658bSDupuis, Chad /* It's assumed that the lock is held when calling this function. */ 1261d8658bSDupuis, Chad static int qedf_initiate_els(struct qedf_rport *fcport, unsigned int op, 1361d8658bSDupuis, Chad void *data, uint32_t data_len, 1461d8658bSDupuis, Chad void (*cb_func)(struct qedf_els_cb_arg *cb_arg), 1561d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg, uint32_t timer_msec) 1661d8658bSDupuis, Chad { 1761d8658bSDupuis, Chad struct qedf_ctx *qedf = fcport->qedf; 1861d8658bSDupuis, Chad struct fc_lport *lport = qedf->lport; 1961d8658bSDupuis, Chad struct qedf_ioreq *els_req; 2061d8658bSDupuis, Chad struct qedf_mp_req *mp_req; 2161d8658bSDupuis, Chad struct fc_frame_header *fc_hdr; 2261d8658bSDupuis, Chad struct fcoe_task_context *task; 2361d8658bSDupuis, Chad int rc = 0; 2461d8658bSDupuis, Chad uint32_t did, sid; 2561d8658bSDupuis, Chad uint16_t xid; 2661d8658bSDupuis, Chad uint32_t start_time = jiffies / HZ; 2761d8658bSDupuis, Chad uint32_t current_time; 28be086e7cSMintz, Yuval struct fcoe_wqe *sqe; 29be086e7cSMintz, Yuval unsigned long flags; 30be086e7cSMintz, Yuval u16 sqe_idx; 3161d8658bSDupuis, Chad 3261d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending ELS\n"); 3361d8658bSDupuis, Chad 3461d8658bSDupuis, Chad rc = fc_remote_port_chkready(fcport->rport); 3561d8658bSDupuis, Chad if (rc) { 3661d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: rport not ready\n", op); 3761d8658bSDupuis, Chad rc = -EAGAIN; 3861d8658bSDupuis, Chad goto els_err; 3961d8658bSDupuis, Chad } 4061d8658bSDupuis, Chad if (lport->state != LPORT_ST_READY || !(lport->link_up)) { 4161d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: link is not ready\n", 4261d8658bSDupuis, Chad op); 4361d8658bSDupuis, Chad rc = -EAGAIN; 4461d8658bSDupuis, Chad goto els_err; 4561d8658bSDupuis, Chad } 4661d8658bSDupuis, Chad 4761d8658bSDupuis, Chad if (!(test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags))) { 4861d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: fcport not ready\n", op); 4961d8658bSDupuis, Chad rc = -EINVAL; 5061d8658bSDupuis, Chad goto els_err; 5161d8658bSDupuis, Chad } 5261d8658bSDupuis, Chad 5361d8658bSDupuis, Chad retry_els: 5461d8658bSDupuis, Chad els_req = qedf_alloc_cmd(fcport, QEDF_ELS); 5561d8658bSDupuis, Chad if (!els_req) { 5661d8658bSDupuis, Chad current_time = jiffies / HZ; 5761d8658bSDupuis, Chad if ((current_time - start_time) > 10) { 5861d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 5961d8658bSDupuis, Chad "els: Failed els 0x%x\n", op); 6061d8658bSDupuis, Chad rc = -ENOMEM; 6161d8658bSDupuis, Chad goto els_err; 6261d8658bSDupuis, Chad } 6361d8658bSDupuis, Chad mdelay(20 * USEC_PER_MSEC); 6461d8658bSDupuis, Chad goto retry_els; 6561d8658bSDupuis, Chad } 6661d8658bSDupuis, Chad 6761d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "initiate_els els_req = " 6861d8658bSDupuis, Chad "0x%p cb_arg = %p xid = %x\n", els_req, cb_arg, 6961d8658bSDupuis, Chad els_req->xid); 7061d8658bSDupuis, Chad els_req->sc_cmd = NULL; 7161d8658bSDupuis, Chad els_req->cmd_type = QEDF_ELS; 7261d8658bSDupuis, Chad els_req->fcport = fcport; 7361d8658bSDupuis, Chad els_req->cb_func = cb_func; 7461d8658bSDupuis, Chad cb_arg->io_req = els_req; 7561d8658bSDupuis, Chad cb_arg->op = op; 7661d8658bSDupuis, Chad els_req->cb_arg = cb_arg; 7761d8658bSDupuis, Chad els_req->data_xfer_len = data_len; 7861d8658bSDupuis, Chad 7961d8658bSDupuis, Chad /* Record which cpu this request is associated with */ 8061d8658bSDupuis, Chad els_req->cpu = smp_processor_id(); 8161d8658bSDupuis, Chad 8261d8658bSDupuis, Chad mp_req = (struct qedf_mp_req *)&(els_req->mp_req); 8361d8658bSDupuis, Chad rc = qedf_init_mp_req(els_req); 8461d8658bSDupuis, Chad if (rc) { 8561d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "ELS MP request init failed\n"); 8661d8658bSDupuis, Chad kref_put(&els_req->refcount, qedf_release_cmd); 8761d8658bSDupuis, Chad goto els_err; 8861d8658bSDupuis, Chad } else { 8961d8658bSDupuis, Chad rc = 0; 9061d8658bSDupuis, Chad } 9161d8658bSDupuis, Chad 9261d8658bSDupuis, Chad /* Fill ELS Payload */ 9361d8658bSDupuis, Chad if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS)) { 9461d8658bSDupuis, Chad memcpy(mp_req->req_buf, data, data_len); 9561d8658bSDupuis, Chad } else { 9661d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Invalid ELS op 0x%x\n", op); 9761d8658bSDupuis, Chad els_req->cb_func = NULL; 9861d8658bSDupuis, Chad els_req->cb_arg = NULL; 9961d8658bSDupuis, Chad kref_put(&els_req->refcount, qedf_release_cmd); 10061d8658bSDupuis, Chad rc = -EINVAL; 10161d8658bSDupuis, Chad } 10261d8658bSDupuis, Chad 10361d8658bSDupuis, Chad if (rc) 10461d8658bSDupuis, Chad goto els_err; 10561d8658bSDupuis, Chad 10661d8658bSDupuis, Chad /* Fill FC header */ 10761d8658bSDupuis, Chad fc_hdr = &(mp_req->req_fc_hdr); 10861d8658bSDupuis, Chad 10961d8658bSDupuis, Chad did = fcport->rdata->ids.port_id; 11061d8658bSDupuis, Chad sid = fcport->sid; 11161d8658bSDupuis, Chad 11261d8658bSDupuis, Chad __fc_fill_fc_hdr(fc_hdr, FC_RCTL_ELS_REQ, sid, did, 11361d8658bSDupuis, Chad FC_TYPE_ELS, FC_FC_FIRST_SEQ | FC_FC_END_SEQ | 11461d8658bSDupuis, Chad FC_FC_SEQ_INIT, 0); 11561d8658bSDupuis, Chad 11661d8658bSDupuis, Chad /* Obtain exchange id */ 11761d8658bSDupuis, Chad xid = els_req->xid; 11861d8658bSDupuis, Chad 119be086e7cSMintz, Yuval spin_lock_irqsave(&fcport->rport_lock, flags); 120be086e7cSMintz, Yuval 121be086e7cSMintz, Yuval sqe_idx = qedf_get_sqe_idx(fcport); 122be086e7cSMintz, Yuval sqe = &fcport->sq[sqe_idx]; 123be086e7cSMintz, Yuval memset(sqe, 0, sizeof(struct fcoe_wqe)); 124be086e7cSMintz, Yuval 12561d8658bSDupuis, Chad /* Initialize task context for this IO request */ 12661d8658bSDupuis, Chad task = qedf_get_task_mem(&qedf->tasks, xid); 127be086e7cSMintz, Yuval qedf_init_mp_task(els_req, task, sqe); 12861d8658bSDupuis, Chad 12961d8658bSDupuis, Chad /* Put timer on original I/O request */ 13061d8658bSDupuis, Chad if (timer_msec) 13161d8658bSDupuis, Chad qedf_cmd_timer_set(qedf, els_req, timer_msec); 13261d8658bSDupuis, Chad 13361d8658bSDupuis, Chad /* Ring doorbell */ 13461d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Ringing doorbell for ELS " 13561d8658bSDupuis, Chad "req\n"); 13661d8658bSDupuis, Chad qedf_ring_doorbell(fcport); 137be086e7cSMintz, Yuval spin_unlock_irqrestore(&fcport->rport_lock, flags); 13861d8658bSDupuis, Chad els_err: 13961d8658bSDupuis, Chad return rc; 14061d8658bSDupuis, Chad } 14161d8658bSDupuis, Chad 14261d8658bSDupuis, Chad void qedf_process_els_compl(struct qedf_ctx *qedf, struct fcoe_cqe *cqe, 14361d8658bSDupuis, Chad struct qedf_ioreq *els_req) 14461d8658bSDupuis, Chad { 14561d8658bSDupuis, Chad struct fcoe_task_context *task_ctx; 14661d8658bSDupuis, Chad struct scsi_cmnd *sc_cmd; 14761d8658bSDupuis, Chad uint16_t xid; 14861d8658bSDupuis, Chad struct fcoe_cqe_midpath_info *mp_info; 14961d8658bSDupuis, Chad 15061d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered with xid = 0x%x" 15161d8658bSDupuis, Chad " cmd_type = %d.\n", els_req->xid, els_req->cmd_type); 15261d8658bSDupuis, Chad 15361d8658bSDupuis, Chad /* Kill the ELS timer */ 15461d8658bSDupuis, Chad cancel_delayed_work(&els_req->timeout_work); 15561d8658bSDupuis, Chad 15661d8658bSDupuis, Chad xid = els_req->xid; 15761d8658bSDupuis, Chad task_ctx = qedf_get_task_mem(&qedf->tasks, xid); 15861d8658bSDupuis, Chad sc_cmd = els_req->sc_cmd; 15961d8658bSDupuis, Chad 16061d8658bSDupuis, Chad /* Get ELS response length from CQE */ 16161d8658bSDupuis, Chad mp_info = &cqe->cqe_info.midpath_info; 16261d8658bSDupuis, Chad els_req->mp_req.resp_len = mp_info->data_placement_size; 16361d8658bSDupuis, Chad 16461d8658bSDupuis, Chad /* Parse ELS response */ 16561d8658bSDupuis, Chad if ((els_req->cb_func) && (els_req->cb_arg)) { 16661d8658bSDupuis, Chad els_req->cb_func(els_req->cb_arg); 16761d8658bSDupuis, Chad els_req->cb_arg = NULL; 16861d8658bSDupuis, Chad } 16961d8658bSDupuis, Chad 17061d8658bSDupuis, Chad kref_put(&els_req->refcount, qedf_release_cmd); 17161d8658bSDupuis, Chad } 17261d8658bSDupuis, Chad 17361d8658bSDupuis, Chad static void qedf_rrq_compl(struct qedf_els_cb_arg *cb_arg) 17461d8658bSDupuis, Chad { 17561d8658bSDupuis, Chad struct qedf_ioreq *orig_io_req; 17661d8658bSDupuis, Chad struct qedf_ioreq *rrq_req; 17761d8658bSDupuis, Chad struct qedf_ctx *qedf; 17861d8658bSDupuis, Chad int refcount; 17961d8658bSDupuis, Chad 18061d8658bSDupuis, Chad rrq_req = cb_arg->io_req; 18161d8658bSDupuis, Chad qedf = rrq_req->fcport->qedf; 18261d8658bSDupuis, Chad 18361d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered.\n"); 18461d8658bSDupuis, Chad 18561d8658bSDupuis, Chad orig_io_req = cb_arg->aborted_io_req; 18661d8658bSDupuis, Chad 18761d8658bSDupuis, Chad if (!orig_io_req) 18861d8658bSDupuis, Chad goto out_free; 18961d8658bSDupuis, Chad 19061d8658bSDupuis, Chad if (rrq_req->event != QEDF_IOREQ_EV_ELS_TMO && 19161d8658bSDupuis, Chad rrq_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT) 19261d8658bSDupuis, Chad cancel_delayed_work_sync(&orig_io_req->timeout_work); 19361d8658bSDupuis, Chad 1941afca6b5SDupuis, Chad refcount = kref_read(&orig_io_req->refcount); 19561d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "rrq_compl: orig io = %p," 19661d8658bSDupuis, Chad " orig xid = 0x%x, rrq_xid = 0x%x, refcount=%d\n", 19761d8658bSDupuis, Chad orig_io_req, orig_io_req->xid, rrq_req->xid, refcount); 19861d8658bSDupuis, Chad 19961d8658bSDupuis, Chad /* This should return the aborted io_req to the command pool */ 20061d8658bSDupuis, Chad if (orig_io_req) 20161d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 20261d8658bSDupuis, Chad 20361d8658bSDupuis, Chad out_free: 20461d8658bSDupuis, Chad kfree(cb_arg); 20561d8658bSDupuis, Chad } 20661d8658bSDupuis, Chad 20761d8658bSDupuis, Chad /* Assumes kref is already held by caller */ 20861d8658bSDupuis, Chad int qedf_send_rrq(struct qedf_ioreq *aborted_io_req) 20961d8658bSDupuis, Chad { 21061d8658bSDupuis, Chad 21161d8658bSDupuis, Chad struct fc_els_rrq rrq; 21261d8658bSDupuis, Chad struct qedf_rport *fcport; 21361d8658bSDupuis, Chad struct fc_lport *lport; 21461d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg = NULL; 21561d8658bSDupuis, Chad struct qedf_ctx *qedf; 21661d8658bSDupuis, Chad uint32_t sid; 21761d8658bSDupuis, Chad uint32_t r_a_tov; 21861d8658bSDupuis, Chad int rc; 21961d8658bSDupuis, Chad 22061d8658bSDupuis, Chad if (!aborted_io_req) { 22161d8658bSDupuis, Chad QEDF_ERR(NULL, "abort_io_req is NULL.\n"); 22261d8658bSDupuis, Chad return -EINVAL; 22361d8658bSDupuis, Chad } 22461d8658bSDupuis, Chad 22561d8658bSDupuis, Chad fcport = aborted_io_req->fcport; 22661d8658bSDupuis, Chad 22761d8658bSDupuis, Chad /* Check that fcport is still offloaded */ 22861d8658bSDupuis, Chad if (!(test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags))) { 22961d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport is no longer offloaded.\n"); 23061d8658bSDupuis, Chad return -EINVAL; 23161d8658bSDupuis, Chad } 23261d8658bSDupuis, Chad 23361d8658bSDupuis, Chad if (!fcport->qedf) { 23461d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport->qedf is NULL.\n"); 23561d8658bSDupuis, Chad return -EINVAL; 23661d8658bSDupuis, Chad } 23761d8658bSDupuis, Chad 23861d8658bSDupuis, Chad qedf = fcport->qedf; 23961d8658bSDupuis, Chad lport = qedf->lport; 24061d8658bSDupuis, Chad sid = fcport->sid; 24161d8658bSDupuis, Chad r_a_tov = lport->r_a_tov; 24261d8658bSDupuis, Chad 24361d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending RRQ orig " 24461d8658bSDupuis, Chad "io = %p, orig_xid = 0x%x\n", aborted_io_req, 24561d8658bSDupuis, Chad aborted_io_req->xid); 24661d8658bSDupuis, Chad memset(&rrq, 0, sizeof(rrq)); 24761d8658bSDupuis, Chad 24861d8658bSDupuis, Chad cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO); 24961d8658bSDupuis, Chad if (!cb_arg) { 25061d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for " 25161d8658bSDupuis, Chad "RRQ\n"); 25261d8658bSDupuis, Chad rc = -ENOMEM; 25361d8658bSDupuis, Chad goto rrq_err; 25461d8658bSDupuis, Chad } 25561d8658bSDupuis, Chad 25661d8658bSDupuis, Chad cb_arg->aborted_io_req = aborted_io_req; 25761d8658bSDupuis, Chad 25861d8658bSDupuis, Chad rrq.rrq_cmd = ELS_RRQ; 25961d8658bSDupuis, Chad hton24(rrq.rrq_s_id, sid); 26061d8658bSDupuis, Chad rrq.rrq_ox_id = htons(aborted_io_req->xid); 26161d8658bSDupuis, Chad rrq.rrq_rx_id = 26261d8658bSDupuis, Chad htons(aborted_io_req->task->tstorm_st_context.read_write.rx_id); 26361d8658bSDupuis, Chad 26461d8658bSDupuis, Chad rc = qedf_initiate_els(fcport, ELS_RRQ, &rrq, sizeof(rrq), 26561d8658bSDupuis, Chad qedf_rrq_compl, cb_arg, r_a_tov); 26661d8658bSDupuis, Chad 26761d8658bSDupuis, Chad rrq_err: 26861d8658bSDupuis, Chad if (rc) { 26961d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "RRQ failed - release orig io " 27061d8658bSDupuis, Chad "req 0x%x\n", aborted_io_req->xid); 27161d8658bSDupuis, Chad kfree(cb_arg); 27261d8658bSDupuis, Chad kref_put(&aborted_io_req->refcount, qedf_release_cmd); 27361d8658bSDupuis, Chad } 27461d8658bSDupuis, Chad return rc; 27561d8658bSDupuis, Chad } 27661d8658bSDupuis, Chad 27761d8658bSDupuis, Chad static void qedf_process_l2_frame_compl(struct qedf_rport *fcport, 27861d8658bSDupuis, Chad struct fc_frame *fp, 27961d8658bSDupuis, Chad u16 l2_oxid) 28061d8658bSDupuis, Chad { 28161d8658bSDupuis, Chad struct fc_lport *lport = fcport->qedf->lport; 28261d8658bSDupuis, Chad struct fc_frame_header *fh; 28361d8658bSDupuis, Chad u32 crc; 28461d8658bSDupuis, Chad 28561d8658bSDupuis, Chad fh = (struct fc_frame_header *)fc_frame_header_get(fp); 28661d8658bSDupuis, Chad 28761d8658bSDupuis, Chad /* Set the OXID we return to what libfc used */ 28861d8658bSDupuis, Chad if (l2_oxid != FC_XID_UNKNOWN) 28961d8658bSDupuis, Chad fh->fh_ox_id = htons(l2_oxid); 29061d8658bSDupuis, Chad 29161d8658bSDupuis, Chad /* Setup header fields */ 29261d8658bSDupuis, Chad fh->fh_r_ctl = FC_RCTL_ELS_REP; 29361d8658bSDupuis, Chad fh->fh_type = FC_TYPE_ELS; 29461d8658bSDupuis, Chad /* Last sequence, end sequence */ 29561d8658bSDupuis, Chad fh->fh_f_ctl[0] = 0x98; 29661d8658bSDupuis, Chad hton24(fh->fh_d_id, lport->port_id); 29761d8658bSDupuis, Chad hton24(fh->fh_s_id, fcport->rdata->ids.port_id); 29861d8658bSDupuis, Chad fh->fh_rx_id = 0xffff; 29961d8658bSDupuis, Chad 30061d8658bSDupuis, Chad /* Set frame attributes */ 30161d8658bSDupuis, Chad crc = fcoe_fc_crc(fp); 30261d8658bSDupuis, Chad fc_frame_init(fp); 30361d8658bSDupuis, Chad fr_dev(fp) = lport; 30461d8658bSDupuis, Chad fr_sof(fp) = FC_SOF_I3; 30561d8658bSDupuis, Chad fr_eof(fp) = FC_EOF_T; 30661d8658bSDupuis, Chad fr_crc(fp) = cpu_to_le32(~crc); 30761d8658bSDupuis, Chad 30861d8658bSDupuis, Chad /* Send completed request to libfc */ 30961d8658bSDupuis, Chad fc_exch_recv(lport, fp); 31061d8658bSDupuis, Chad } 31161d8658bSDupuis, Chad 31261d8658bSDupuis, Chad /* 31361d8658bSDupuis, Chad * In instances where an ELS command times out we may need to restart the 31461d8658bSDupuis, Chad * rport by logging out and then logging back in. 31561d8658bSDupuis, Chad */ 31661d8658bSDupuis, Chad void qedf_restart_rport(struct qedf_rport *fcport) 31761d8658bSDupuis, Chad { 31861d8658bSDupuis, Chad struct fc_lport *lport; 31961d8658bSDupuis, Chad struct fc_rport_priv *rdata; 32061d8658bSDupuis, Chad u32 port_id; 32161d8658bSDupuis, Chad 32261d8658bSDupuis, Chad if (!fcport) 32361d8658bSDupuis, Chad return; 32461d8658bSDupuis, Chad 32561d8658bSDupuis, Chad rdata = fcport->rdata; 32661d8658bSDupuis, Chad if (rdata) { 32761d8658bSDupuis, Chad lport = fcport->qedf->lport; 32861d8658bSDupuis, Chad port_id = rdata->ids.port_id; 32961d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), 33061d8658bSDupuis, Chad "LOGO port_id=%x.\n", port_id); 33161d8658bSDupuis, Chad fc_rport_logoff(rdata); 33261d8658bSDupuis, Chad /* Recreate the rport and log back in */ 33361d8658bSDupuis, Chad rdata = fc_rport_create(lport, port_id); 33461d8658bSDupuis, Chad if (rdata) 33561d8658bSDupuis, Chad fc_rport_login(rdata); 33661d8658bSDupuis, Chad } 33761d8658bSDupuis, Chad } 33861d8658bSDupuis, Chad 33961d8658bSDupuis, Chad static void qedf_l2_els_compl(struct qedf_els_cb_arg *cb_arg) 34061d8658bSDupuis, Chad { 34161d8658bSDupuis, Chad struct qedf_ioreq *els_req; 34261d8658bSDupuis, Chad struct qedf_rport *fcport; 34361d8658bSDupuis, Chad struct qedf_mp_req *mp_req; 34461d8658bSDupuis, Chad struct fc_frame *fp; 34561d8658bSDupuis, Chad struct fc_frame_header *fh, *mp_fc_hdr; 34661d8658bSDupuis, Chad void *resp_buf, *fc_payload; 34761d8658bSDupuis, Chad u32 resp_len; 34861d8658bSDupuis, Chad u16 l2_oxid; 34961d8658bSDupuis, Chad 35061d8658bSDupuis, Chad l2_oxid = cb_arg->l2_oxid; 35161d8658bSDupuis, Chad els_req = cb_arg->io_req; 35261d8658bSDupuis, Chad 35361d8658bSDupuis, Chad if (!els_req) { 35461d8658bSDupuis, Chad QEDF_ERR(NULL, "els_req is NULL.\n"); 35561d8658bSDupuis, Chad goto free_arg; 35661d8658bSDupuis, Chad } 35761d8658bSDupuis, Chad 35861d8658bSDupuis, Chad /* 35961d8658bSDupuis, Chad * If we are flushing the command just free the cb_arg as none of the 36061d8658bSDupuis, Chad * response data will be valid. 36161d8658bSDupuis, Chad */ 36261d8658bSDupuis, Chad if (els_req->event == QEDF_IOREQ_EV_ELS_FLUSH) 36361d8658bSDupuis, Chad goto free_arg; 36461d8658bSDupuis, Chad 36561d8658bSDupuis, Chad fcport = els_req->fcport; 36661d8658bSDupuis, Chad mp_req = &(els_req->mp_req); 36761d8658bSDupuis, Chad mp_fc_hdr = &(mp_req->resp_fc_hdr); 36861d8658bSDupuis, Chad resp_len = mp_req->resp_len; 36961d8658bSDupuis, Chad resp_buf = mp_req->resp_buf; 37061d8658bSDupuis, Chad 37161d8658bSDupuis, Chad /* 37261d8658bSDupuis, Chad * If a middle path ELS command times out, don't try to return 37361d8658bSDupuis, Chad * the command but rather do any internal cleanup and then libfc 37461d8658bSDupuis, Chad * timeout the command and clean up its internal resources. 37561d8658bSDupuis, Chad */ 37661d8658bSDupuis, Chad if (els_req->event == QEDF_IOREQ_EV_ELS_TMO) { 37761d8658bSDupuis, Chad /* 37861d8658bSDupuis, Chad * If ADISC times out, libfc will timeout the exchange and then 37961d8658bSDupuis, Chad * try to send a PLOGI which will timeout since the session is 38061d8658bSDupuis, Chad * still offloaded. Force libfc to logout the session which 38161d8658bSDupuis, Chad * will offload the connection and allow the PLOGI response to 38261d8658bSDupuis, Chad * flow over the LL2 path. 38361d8658bSDupuis, Chad */ 38461d8658bSDupuis, Chad if (cb_arg->op == ELS_ADISC) 38561d8658bSDupuis, Chad qedf_restart_rport(fcport); 38661d8658bSDupuis, Chad return; 38761d8658bSDupuis, Chad } 38861d8658bSDupuis, Chad 38961d8658bSDupuis, Chad if (sizeof(struct fc_frame_header) + resp_len > QEDF_PAGE_SIZE) { 39061d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "resp_len is " 39161d8658bSDupuis, Chad "beyond page size.\n"); 39261d8658bSDupuis, Chad goto free_arg; 39361d8658bSDupuis, Chad } 39461d8658bSDupuis, Chad 39561d8658bSDupuis, Chad fp = fc_frame_alloc(fcport->qedf->lport, resp_len); 39661d8658bSDupuis, Chad if (!fp) { 39761d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), 39861d8658bSDupuis, Chad "fc_frame_alloc failure.\n"); 39961d8658bSDupuis, Chad return; 40061d8658bSDupuis, Chad } 40161d8658bSDupuis, Chad 40261d8658bSDupuis, Chad /* Copy frame header from firmware into fp */ 40361d8658bSDupuis, Chad fh = (struct fc_frame_header *)fc_frame_header_get(fp); 40461d8658bSDupuis, Chad memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header)); 40561d8658bSDupuis, Chad 40661d8658bSDupuis, Chad /* Copy payload from firmware into fp */ 40761d8658bSDupuis, Chad fc_payload = fc_frame_payload_get(fp, resp_len); 40861d8658bSDupuis, Chad memcpy(fc_payload, resp_buf, resp_len); 40961d8658bSDupuis, Chad 41061d8658bSDupuis, Chad QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS, 41161d8658bSDupuis, Chad "Completing OX_ID 0x%x back to libfc.\n", l2_oxid); 41261d8658bSDupuis, Chad qedf_process_l2_frame_compl(fcport, fp, l2_oxid); 41361d8658bSDupuis, Chad 41461d8658bSDupuis, Chad free_arg: 41561d8658bSDupuis, Chad kfree(cb_arg); 41661d8658bSDupuis, Chad } 41761d8658bSDupuis, Chad 41861d8658bSDupuis, Chad int qedf_send_adisc(struct qedf_rport *fcport, struct fc_frame *fp) 41961d8658bSDupuis, Chad { 42061d8658bSDupuis, Chad struct fc_els_adisc *adisc; 42161d8658bSDupuis, Chad struct fc_frame_header *fh; 42261d8658bSDupuis, Chad struct fc_lport *lport = fcport->qedf->lport; 42361d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg = NULL; 42461d8658bSDupuis, Chad struct qedf_ctx *qedf; 42561d8658bSDupuis, Chad uint32_t r_a_tov = lport->r_a_tov; 42661d8658bSDupuis, Chad int rc; 42761d8658bSDupuis, Chad 42861d8658bSDupuis, Chad qedf = fcport->qedf; 42961d8658bSDupuis, Chad fh = fc_frame_header_get(fp); 43061d8658bSDupuis, Chad 43161d8658bSDupuis, Chad cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO); 43261d8658bSDupuis, Chad if (!cb_arg) { 43361d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for " 43461d8658bSDupuis, Chad "ADISC\n"); 43561d8658bSDupuis, Chad rc = -ENOMEM; 43661d8658bSDupuis, Chad goto adisc_err; 43761d8658bSDupuis, Chad } 43861d8658bSDupuis, Chad cb_arg->l2_oxid = ntohs(fh->fh_ox_id); 43961d8658bSDupuis, Chad 44061d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 44161d8658bSDupuis, Chad "Sending ADISC ox_id=0x%x.\n", cb_arg->l2_oxid); 44261d8658bSDupuis, Chad 44361d8658bSDupuis, Chad adisc = fc_frame_payload_get(fp, sizeof(*adisc)); 44461d8658bSDupuis, Chad 44561d8658bSDupuis, Chad rc = qedf_initiate_els(fcport, ELS_ADISC, adisc, sizeof(*adisc), 44661d8658bSDupuis, Chad qedf_l2_els_compl, cb_arg, r_a_tov); 44761d8658bSDupuis, Chad 44861d8658bSDupuis, Chad adisc_err: 44961d8658bSDupuis, Chad if (rc) { 45061d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "ADISC failed.\n"); 45161d8658bSDupuis, Chad kfree(cb_arg); 45261d8658bSDupuis, Chad } 45361d8658bSDupuis, Chad return rc; 45461d8658bSDupuis, Chad } 45561d8658bSDupuis, Chad 45661d8658bSDupuis, Chad static void qedf_srr_compl(struct qedf_els_cb_arg *cb_arg) 45761d8658bSDupuis, Chad { 45861d8658bSDupuis, Chad struct qedf_ioreq *orig_io_req; 45961d8658bSDupuis, Chad struct qedf_ioreq *srr_req; 46061d8658bSDupuis, Chad struct qedf_mp_req *mp_req; 46161d8658bSDupuis, Chad struct fc_frame_header *mp_fc_hdr, *fh; 46261d8658bSDupuis, Chad struct fc_frame *fp; 46361d8658bSDupuis, Chad void *resp_buf, *fc_payload; 46461d8658bSDupuis, Chad u32 resp_len; 46561d8658bSDupuis, Chad struct fc_lport *lport; 46661d8658bSDupuis, Chad struct qedf_ctx *qedf; 46761d8658bSDupuis, Chad int refcount; 46861d8658bSDupuis, Chad u8 opcode; 46961d8658bSDupuis, Chad 47061d8658bSDupuis, Chad srr_req = cb_arg->io_req; 47161d8658bSDupuis, Chad qedf = srr_req->fcport->qedf; 47261d8658bSDupuis, Chad lport = qedf->lport; 47361d8658bSDupuis, Chad 47461d8658bSDupuis, Chad orig_io_req = cb_arg->aborted_io_req; 47561d8658bSDupuis, Chad 47661d8658bSDupuis, Chad if (!orig_io_req) 47761d8658bSDupuis, Chad goto out_free; 47861d8658bSDupuis, Chad 47961d8658bSDupuis, Chad clear_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags); 48061d8658bSDupuis, Chad 48161d8658bSDupuis, Chad if (srr_req->event != QEDF_IOREQ_EV_ELS_TMO && 48261d8658bSDupuis, Chad srr_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT) 48361d8658bSDupuis, Chad cancel_delayed_work_sync(&orig_io_req->timeout_work); 48461d8658bSDupuis, Chad 4851afca6b5SDupuis, Chad refcount = kref_read(&orig_io_req->refcount); 48661d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p," 48761d8658bSDupuis, Chad " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n", 48861d8658bSDupuis, Chad orig_io_req, orig_io_req->xid, srr_req->xid, refcount); 48961d8658bSDupuis, Chad 49061d8658bSDupuis, Chad /* If a SRR times out, simply free resources */ 49161d8658bSDupuis, Chad if (srr_req->event == QEDF_IOREQ_EV_ELS_TMO) 49261d8658bSDupuis, Chad goto out_free; 49361d8658bSDupuis, Chad 49461d8658bSDupuis, Chad /* Normalize response data into struct fc_frame */ 49561d8658bSDupuis, Chad mp_req = &(srr_req->mp_req); 49661d8658bSDupuis, Chad mp_fc_hdr = &(mp_req->resp_fc_hdr); 49761d8658bSDupuis, Chad resp_len = mp_req->resp_len; 49861d8658bSDupuis, Chad resp_buf = mp_req->resp_buf; 49961d8658bSDupuis, Chad 50061d8658bSDupuis, Chad fp = fc_frame_alloc(lport, resp_len); 50161d8658bSDupuis, Chad if (!fp) { 50261d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), 50361d8658bSDupuis, Chad "fc_frame_alloc failure.\n"); 50461d8658bSDupuis, Chad goto out_free; 50561d8658bSDupuis, Chad } 50661d8658bSDupuis, Chad 50761d8658bSDupuis, Chad /* Copy frame header from firmware into fp */ 50861d8658bSDupuis, Chad fh = (struct fc_frame_header *)fc_frame_header_get(fp); 50961d8658bSDupuis, Chad memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header)); 51061d8658bSDupuis, Chad 51161d8658bSDupuis, Chad /* Copy payload from firmware into fp */ 51261d8658bSDupuis, Chad fc_payload = fc_frame_payload_get(fp, resp_len); 51361d8658bSDupuis, Chad memcpy(fc_payload, resp_buf, resp_len); 51461d8658bSDupuis, Chad 51561d8658bSDupuis, Chad opcode = fc_frame_payload_op(fp); 51661d8658bSDupuis, Chad switch (opcode) { 51761d8658bSDupuis, Chad case ELS_LS_ACC: 51861d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 51961d8658bSDupuis, Chad "SRR success.\n"); 52061d8658bSDupuis, Chad break; 52161d8658bSDupuis, Chad case ELS_LS_RJT: 52261d8658bSDupuis, Chad QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_ELS, 52361d8658bSDupuis, Chad "SRR rejected.\n"); 52461d8658bSDupuis, Chad qedf_initiate_abts(orig_io_req, true); 52561d8658bSDupuis, Chad break; 52661d8658bSDupuis, Chad } 52761d8658bSDupuis, Chad 52861d8658bSDupuis, Chad fc_frame_free(fp); 52961d8658bSDupuis, Chad out_free: 53061d8658bSDupuis, Chad /* Put reference for original command since SRR completed */ 53161d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 53261d8658bSDupuis, Chad kfree(cb_arg); 53361d8658bSDupuis, Chad } 53461d8658bSDupuis, Chad 53561d8658bSDupuis, Chad static int qedf_send_srr(struct qedf_ioreq *orig_io_req, u32 offset, u8 r_ctl) 53661d8658bSDupuis, Chad { 53761d8658bSDupuis, Chad struct fcp_srr srr; 53861d8658bSDupuis, Chad struct qedf_ctx *qedf; 53961d8658bSDupuis, Chad struct qedf_rport *fcport; 54061d8658bSDupuis, Chad struct fc_lport *lport; 54161d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg = NULL; 54261d8658bSDupuis, Chad u32 sid, r_a_tov; 54361d8658bSDupuis, Chad int rc; 54461d8658bSDupuis, Chad 54561d8658bSDupuis, Chad if (!orig_io_req) { 54661d8658bSDupuis, Chad QEDF_ERR(NULL, "orig_io_req is NULL.\n"); 54761d8658bSDupuis, Chad return -EINVAL; 54861d8658bSDupuis, Chad } 54961d8658bSDupuis, Chad 55061d8658bSDupuis, Chad fcport = orig_io_req->fcport; 55161d8658bSDupuis, Chad 55261d8658bSDupuis, Chad /* Check that fcport is still offloaded */ 55361d8658bSDupuis, Chad if (!(test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags))) { 55461d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport is no longer offloaded.\n"); 55561d8658bSDupuis, Chad return -EINVAL; 55661d8658bSDupuis, Chad } 55761d8658bSDupuis, Chad 55861d8658bSDupuis, Chad if (!fcport->qedf) { 55961d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport->qedf is NULL.\n"); 56061d8658bSDupuis, Chad return -EINVAL; 56161d8658bSDupuis, Chad } 56261d8658bSDupuis, Chad 56361d8658bSDupuis, Chad /* Take reference until SRR command completion */ 56461d8658bSDupuis, Chad kref_get(&orig_io_req->refcount); 56561d8658bSDupuis, Chad 56661d8658bSDupuis, Chad qedf = fcport->qedf; 56761d8658bSDupuis, Chad lport = qedf->lport; 56861d8658bSDupuis, Chad sid = fcport->sid; 56961d8658bSDupuis, Chad r_a_tov = lport->r_a_tov; 57061d8658bSDupuis, Chad 57161d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending SRR orig_io=%p, " 57261d8658bSDupuis, Chad "orig_xid=0x%x\n", orig_io_req, orig_io_req->xid); 57361d8658bSDupuis, Chad memset(&srr, 0, sizeof(srr)); 57461d8658bSDupuis, Chad 57561d8658bSDupuis, Chad cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO); 57661d8658bSDupuis, Chad if (!cb_arg) { 57761d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for " 57861d8658bSDupuis, Chad "SRR\n"); 57961d8658bSDupuis, Chad rc = -ENOMEM; 58061d8658bSDupuis, Chad goto srr_err; 58161d8658bSDupuis, Chad } 58261d8658bSDupuis, Chad 58361d8658bSDupuis, Chad cb_arg->aborted_io_req = orig_io_req; 58461d8658bSDupuis, Chad 58561d8658bSDupuis, Chad srr.srr_op = ELS_SRR; 58661d8658bSDupuis, Chad srr.srr_ox_id = htons(orig_io_req->xid); 58761d8658bSDupuis, Chad srr.srr_rx_id = htons(orig_io_req->rx_id); 58861d8658bSDupuis, Chad srr.srr_rel_off = htonl(offset); 58961d8658bSDupuis, Chad srr.srr_r_ctl = r_ctl; 59061d8658bSDupuis, Chad 59161d8658bSDupuis, Chad rc = qedf_initiate_els(fcport, ELS_SRR, &srr, sizeof(srr), 59261d8658bSDupuis, Chad qedf_srr_compl, cb_arg, r_a_tov); 59361d8658bSDupuis, Chad 59461d8658bSDupuis, Chad srr_err: 59561d8658bSDupuis, Chad if (rc) { 59661d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "SRR failed - release orig_io_req" 59761d8658bSDupuis, Chad "=0x%x\n", orig_io_req->xid); 59861d8658bSDupuis, Chad kfree(cb_arg); 59961d8658bSDupuis, Chad /* If we fail to queue SRR, send ABTS to orig_io */ 60061d8658bSDupuis, Chad qedf_initiate_abts(orig_io_req, true); 60161d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 60261d8658bSDupuis, Chad } else 60361d8658bSDupuis, Chad /* Tell other threads that SRR is in progress */ 60461d8658bSDupuis, Chad set_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags); 60561d8658bSDupuis, Chad 60661d8658bSDupuis, Chad return rc; 60761d8658bSDupuis, Chad } 60861d8658bSDupuis, Chad 60961d8658bSDupuis, Chad static void qedf_initiate_seq_cleanup(struct qedf_ioreq *orig_io_req, 61061d8658bSDupuis, Chad u32 offset, u8 r_ctl) 61161d8658bSDupuis, Chad { 61261d8658bSDupuis, Chad struct qedf_rport *fcport; 61361d8658bSDupuis, Chad unsigned long flags; 61461d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg; 615be086e7cSMintz, Yuval struct fcoe_wqe *sqe; 616be086e7cSMintz, Yuval u16 sqe_idx; 61761d8658bSDupuis, Chad 61861d8658bSDupuis, Chad fcport = orig_io_req->fcport; 61961d8658bSDupuis, Chad 62061d8658bSDupuis, Chad QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS, 62161d8658bSDupuis, Chad "Doing sequence cleanup for xid=0x%x offset=%u.\n", 62261d8658bSDupuis, Chad orig_io_req->xid, offset); 62361d8658bSDupuis, Chad 62461d8658bSDupuis, Chad cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO); 62561d8658bSDupuis, Chad if (!cb_arg) { 62661d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to allocate cb_arg " 62761d8658bSDupuis, Chad "for sequence cleanup\n"); 62861d8658bSDupuis, Chad return; 62961d8658bSDupuis, Chad } 63061d8658bSDupuis, Chad 63161d8658bSDupuis, Chad /* Get reference for cleanup request */ 63261d8658bSDupuis, Chad kref_get(&orig_io_req->refcount); 63361d8658bSDupuis, Chad 63461d8658bSDupuis, Chad orig_io_req->cmd_type = QEDF_SEQ_CLEANUP; 63561d8658bSDupuis, Chad cb_arg->offset = offset; 63661d8658bSDupuis, Chad cb_arg->r_ctl = r_ctl; 63761d8658bSDupuis, Chad orig_io_req->cb_arg = cb_arg; 63861d8658bSDupuis, Chad 63961d8658bSDupuis, Chad qedf_cmd_timer_set(fcport->qedf, orig_io_req, 64061d8658bSDupuis, Chad QEDF_CLEANUP_TIMEOUT * HZ); 64161d8658bSDupuis, Chad 64261d8658bSDupuis, Chad spin_lock_irqsave(&fcport->rport_lock, flags); 64361d8658bSDupuis, Chad 644be086e7cSMintz, Yuval sqe_idx = qedf_get_sqe_idx(fcport); 645be086e7cSMintz, Yuval sqe = &fcport->sq[sqe_idx]; 646be086e7cSMintz, Yuval memset(sqe, 0, sizeof(struct fcoe_wqe)); 647be086e7cSMintz, Yuval orig_io_req->task_params->sqe = sqe; 648be086e7cSMintz, Yuval 649be086e7cSMintz, Yuval init_initiator_sequence_recovery_fcoe_task(orig_io_req->task_params, 650be086e7cSMintz, Yuval offset); 65161d8658bSDupuis, Chad qedf_ring_doorbell(fcport); 65261d8658bSDupuis, Chad 65361d8658bSDupuis, Chad spin_unlock_irqrestore(&fcport->rport_lock, flags); 65461d8658bSDupuis, Chad } 65561d8658bSDupuis, Chad 65661d8658bSDupuis, Chad void qedf_process_seq_cleanup_compl(struct qedf_ctx *qedf, 65761d8658bSDupuis, Chad struct fcoe_cqe *cqe, struct qedf_ioreq *io_req) 65861d8658bSDupuis, Chad { 65961d8658bSDupuis, Chad int rc; 66061d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg; 66161d8658bSDupuis, Chad 66261d8658bSDupuis, Chad cb_arg = io_req->cb_arg; 66361d8658bSDupuis, Chad 66461d8658bSDupuis, Chad /* If we timed out just free resources */ 66561d8658bSDupuis, Chad if (io_req->event == QEDF_IOREQ_EV_ELS_TMO || !cqe) 66661d8658bSDupuis, Chad goto free; 66761d8658bSDupuis, Chad 66861d8658bSDupuis, Chad /* Kill the timer we put on the request */ 66961d8658bSDupuis, Chad cancel_delayed_work_sync(&io_req->timeout_work); 67061d8658bSDupuis, Chad 67161d8658bSDupuis, Chad rc = qedf_send_srr(io_req, cb_arg->offset, cb_arg->r_ctl); 67261d8658bSDupuis, Chad if (rc) 67361d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Unable to send SRR, I/O will " 67461d8658bSDupuis, Chad "abort, xid=0x%x.\n", io_req->xid); 67561d8658bSDupuis, Chad free: 67661d8658bSDupuis, Chad kfree(cb_arg); 67761d8658bSDupuis, Chad kref_put(&io_req->refcount, qedf_release_cmd); 67861d8658bSDupuis, Chad } 67961d8658bSDupuis, Chad 68061d8658bSDupuis, Chad static bool qedf_requeue_io_req(struct qedf_ioreq *orig_io_req) 68161d8658bSDupuis, Chad { 68261d8658bSDupuis, Chad struct qedf_rport *fcport; 68361d8658bSDupuis, Chad struct qedf_ioreq *new_io_req; 68461d8658bSDupuis, Chad unsigned long flags; 68561d8658bSDupuis, Chad bool rc = false; 68661d8658bSDupuis, Chad 68761d8658bSDupuis, Chad fcport = orig_io_req->fcport; 68861d8658bSDupuis, Chad if (!fcport) { 68961d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport is NULL.\n"); 69061d8658bSDupuis, Chad goto out; 69161d8658bSDupuis, Chad } 69261d8658bSDupuis, Chad 69361d8658bSDupuis, Chad if (!orig_io_req->sc_cmd) { 69461d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "sc_cmd is NULL for " 69561d8658bSDupuis, Chad "xid=0x%x.\n", orig_io_req->xid); 69661d8658bSDupuis, Chad goto out; 69761d8658bSDupuis, Chad } 69861d8658bSDupuis, Chad 69961d8658bSDupuis, Chad new_io_req = qedf_alloc_cmd(fcport, QEDF_SCSI_CMD); 70061d8658bSDupuis, Chad if (!new_io_req) { 70161d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "Could not allocate new " 70261d8658bSDupuis, Chad "io_req.\n"); 70361d8658bSDupuis, Chad goto out; 70461d8658bSDupuis, Chad } 70561d8658bSDupuis, Chad 70661d8658bSDupuis, Chad new_io_req->sc_cmd = orig_io_req->sc_cmd; 70761d8658bSDupuis, Chad 70861d8658bSDupuis, Chad /* 70961d8658bSDupuis, Chad * This keeps the sc_cmd struct from being returned to the tape 71061d8658bSDupuis, Chad * driver and being requeued twice. We do need to put a reference 71161d8658bSDupuis, Chad * for the original I/O request since we will not do a SCSI completion 71261d8658bSDupuis, Chad * for it. 71361d8658bSDupuis, Chad */ 71461d8658bSDupuis, Chad orig_io_req->sc_cmd = NULL; 71561d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 71661d8658bSDupuis, Chad 71761d8658bSDupuis, Chad spin_lock_irqsave(&fcport->rport_lock, flags); 71861d8658bSDupuis, Chad 71961d8658bSDupuis, Chad /* kref for new command released in qedf_post_io_req on error */ 72061d8658bSDupuis, Chad if (qedf_post_io_req(fcport, new_io_req)) { 72161d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to post io_req\n"); 72261d8658bSDupuis, Chad /* Return SQE to pool */ 72361d8658bSDupuis, Chad atomic_inc(&fcport->free_sqes); 72461d8658bSDupuis, Chad } else { 72561d8658bSDupuis, Chad QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS, 72661d8658bSDupuis, Chad "Reissued SCSI command from orig_xid=0x%x on " 72761d8658bSDupuis, Chad "new_xid=0x%x.\n", orig_io_req->xid, new_io_req->xid); 72861d8658bSDupuis, Chad /* 72961d8658bSDupuis, Chad * Abort the original I/O but do not return SCSI command as 73061d8658bSDupuis, Chad * it has been reissued on another OX_ID. 73161d8658bSDupuis, Chad */ 73261d8658bSDupuis, Chad spin_unlock_irqrestore(&fcport->rport_lock, flags); 73361d8658bSDupuis, Chad qedf_initiate_abts(orig_io_req, false); 73461d8658bSDupuis, Chad goto out; 73561d8658bSDupuis, Chad } 73661d8658bSDupuis, Chad 73761d8658bSDupuis, Chad spin_unlock_irqrestore(&fcport->rport_lock, flags); 73861d8658bSDupuis, Chad out: 73961d8658bSDupuis, Chad return rc; 74061d8658bSDupuis, Chad } 74161d8658bSDupuis, Chad 74261d8658bSDupuis, Chad 74361d8658bSDupuis, Chad static void qedf_rec_compl(struct qedf_els_cb_arg *cb_arg) 74461d8658bSDupuis, Chad { 74561d8658bSDupuis, Chad struct qedf_ioreq *orig_io_req; 74661d8658bSDupuis, Chad struct qedf_ioreq *rec_req; 74761d8658bSDupuis, Chad struct qedf_mp_req *mp_req; 74861d8658bSDupuis, Chad struct fc_frame_header *mp_fc_hdr, *fh; 74961d8658bSDupuis, Chad struct fc_frame *fp; 75061d8658bSDupuis, Chad void *resp_buf, *fc_payload; 75161d8658bSDupuis, Chad u32 resp_len; 75261d8658bSDupuis, Chad struct fc_lport *lport; 75361d8658bSDupuis, Chad struct qedf_ctx *qedf; 75461d8658bSDupuis, Chad int refcount; 75561d8658bSDupuis, Chad enum fc_rctl r_ctl; 75661d8658bSDupuis, Chad struct fc_els_ls_rjt *rjt; 75761d8658bSDupuis, Chad struct fc_els_rec_acc *acc; 75861d8658bSDupuis, Chad u8 opcode; 75961d8658bSDupuis, Chad u32 offset, e_stat; 76061d8658bSDupuis, Chad struct scsi_cmnd *sc_cmd; 76161d8658bSDupuis, Chad bool srr_needed = false; 76261d8658bSDupuis, Chad 76361d8658bSDupuis, Chad rec_req = cb_arg->io_req; 76461d8658bSDupuis, Chad qedf = rec_req->fcport->qedf; 76561d8658bSDupuis, Chad lport = qedf->lport; 76661d8658bSDupuis, Chad 76761d8658bSDupuis, Chad orig_io_req = cb_arg->aborted_io_req; 76861d8658bSDupuis, Chad 76961d8658bSDupuis, Chad if (!orig_io_req) 77061d8658bSDupuis, Chad goto out_free; 77161d8658bSDupuis, Chad 77261d8658bSDupuis, Chad if (rec_req->event != QEDF_IOREQ_EV_ELS_TMO && 77361d8658bSDupuis, Chad rec_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT) 77461d8658bSDupuis, Chad cancel_delayed_work_sync(&orig_io_req->timeout_work); 77561d8658bSDupuis, Chad 7761afca6b5SDupuis, Chad refcount = kref_read(&orig_io_req->refcount); 77761d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p," 77861d8658bSDupuis, Chad " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n", 77961d8658bSDupuis, Chad orig_io_req, orig_io_req->xid, rec_req->xid, refcount); 78061d8658bSDupuis, Chad 78161d8658bSDupuis, Chad /* If a REC times out, free resources */ 78261d8658bSDupuis, Chad if (rec_req->event == QEDF_IOREQ_EV_ELS_TMO) 78361d8658bSDupuis, Chad goto out_free; 78461d8658bSDupuis, Chad 78561d8658bSDupuis, Chad /* Normalize response data into struct fc_frame */ 78661d8658bSDupuis, Chad mp_req = &(rec_req->mp_req); 78761d8658bSDupuis, Chad mp_fc_hdr = &(mp_req->resp_fc_hdr); 78861d8658bSDupuis, Chad resp_len = mp_req->resp_len; 78961d8658bSDupuis, Chad acc = resp_buf = mp_req->resp_buf; 79061d8658bSDupuis, Chad 79161d8658bSDupuis, Chad fp = fc_frame_alloc(lport, resp_len); 79261d8658bSDupuis, Chad if (!fp) { 79361d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), 79461d8658bSDupuis, Chad "fc_frame_alloc failure.\n"); 79561d8658bSDupuis, Chad goto out_free; 79661d8658bSDupuis, Chad } 79761d8658bSDupuis, Chad 79861d8658bSDupuis, Chad /* Copy frame header from firmware into fp */ 79961d8658bSDupuis, Chad fh = (struct fc_frame_header *)fc_frame_header_get(fp); 80061d8658bSDupuis, Chad memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header)); 80161d8658bSDupuis, Chad 80261d8658bSDupuis, Chad /* Copy payload from firmware into fp */ 80361d8658bSDupuis, Chad fc_payload = fc_frame_payload_get(fp, resp_len); 80461d8658bSDupuis, Chad memcpy(fc_payload, resp_buf, resp_len); 80561d8658bSDupuis, Chad 80661d8658bSDupuis, Chad opcode = fc_frame_payload_op(fp); 80761d8658bSDupuis, Chad if (opcode == ELS_LS_RJT) { 80861d8658bSDupuis, Chad rjt = fc_frame_payload_get(fp, sizeof(*rjt)); 80961d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 81061d8658bSDupuis, Chad "Received LS_RJT for REC: er_reason=0x%x, " 81161d8658bSDupuis, Chad "er_explan=0x%x.\n", rjt->er_reason, rjt->er_explan); 81261d8658bSDupuis, Chad /* 81361d8658bSDupuis, Chad * The following response(s) mean that we need to reissue the 81461d8658bSDupuis, Chad * request on another exchange. We need to do this without 81561d8658bSDupuis, Chad * informing the upper layers lest it cause an application 81661d8658bSDupuis, Chad * error. 81761d8658bSDupuis, Chad */ 81861d8658bSDupuis, Chad if ((rjt->er_reason == ELS_RJT_LOGIC || 81961d8658bSDupuis, Chad rjt->er_reason == ELS_RJT_UNAB) && 82061d8658bSDupuis, Chad rjt->er_explan == ELS_EXPL_OXID_RXID) { 82161d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 82261d8658bSDupuis, Chad "Handle CMD LOST case.\n"); 82361d8658bSDupuis, Chad qedf_requeue_io_req(orig_io_req); 82461d8658bSDupuis, Chad } 82561d8658bSDupuis, Chad } else if (opcode == ELS_LS_ACC) { 82661d8658bSDupuis, Chad offset = ntohl(acc->reca_fc4value); 82761d8658bSDupuis, Chad e_stat = ntohl(acc->reca_e_stat); 82861d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 82961d8658bSDupuis, Chad "Received LS_ACC for REC: offset=0x%x, e_stat=0x%x.\n", 83061d8658bSDupuis, Chad offset, e_stat); 83161d8658bSDupuis, Chad if (e_stat & ESB_ST_SEQ_INIT) { 83261d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 83361d8658bSDupuis, Chad "Target has the seq init\n"); 83461d8658bSDupuis, Chad goto out_free_frame; 83561d8658bSDupuis, Chad } 83661d8658bSDupuis, Chad sc_cmd = orig_io_req->sc_cmd; 83761d8658bSDupuis, Chad if (!sc_cmd) { 83861d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 83961d8658bSDupuis, Chad "sc_cmd is NULL for xid=0x%x.\n", 84061d8658bSDupuis, Chad orig_io_req->xid); 84161d8658bSDupuis, Chad goto out_free_frame; 84261d8658bSDupuis, Chad } 84361d8658bSDupuis, Chad /* SCSI write case */ 84461d8658bSDupuis, Chad if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) { 84561d8658bSDupuis, Chad if (offset == orig_io_req->data_xfer_len) { 84661d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 84761d8658bSDupuis, Chad "WRITE - response lost.\n"); 84861d8658bSDupuis, Chad r_ctl = FC_RCTL_DD_CMD_STATUS; 84961d8658bSDupuis, Chad srr_needed = true; 85061d8658bSDupuis, Chad offset = 0; 85161d8658bSDupuis, Chad } else { 85261d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 85361d8658bSDupuis, Chad "WRITE - XFER_RDY/DATA lost.\n"); 85461d8658bSDupuis, Chad r_ctl = FC_RCTL_DD_DATA_DESC; 85561d8658bSDupuis, Chad /* Use data from warning CQE instead of REC */ 85661d8658bSDupuis, Chad offset = orig_io_req->tx_buf_off; 85761d8658bSDupuis, Chad } 85861d8658bSDupuis, Chad /* SCSI read case */ 85961d8658bSDupuis, Chad } else { 86061d8658bSDupuis, Chad if (orig_io_req->rx_buf_off == 86161d8658bSDupuis, Chad orig_io_req->data_xfer_len) { 86261d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 86361d8658bSDupuis, Chad "READ - response lost.\n"); 86461d8658bSDupuis, Chad srr_needed = true; 86561d8658bSDupuis, Chad r_ctl = FC_RCTL_DD_CMD_STATUS; 86661d8658bSDupuis, Chad offset = 0; 86761d8658bSDupuis, Chad } else { 86861d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 86961d8658bSDupuis, Chad "READ - DATA lost.\n"); 87061d8658bSDupuis, Chad /* 87161d8658bSDupuis, Chad * For read case we always set the offset to 0 87261d8658bSDupuis, Chad * for sequence recovery task. 87361d8658bSDupuis, Chad */ 87461d8658bSDupuis, Chad offset = 0; 87561d8658bSDupuis, Chad r_ctl = FC_RCTL_DD_SOL_DATA; 87661d8658bSDupuis, Chad } 87761d8658bSDupuis, Chad } 87861d8658bSDupuis, Chad 87961d8658bSDupuis, Chad if (srr_needed) 88061d8658bSDupuis, Chad qedf_send_srr(orig_io_req, offset, r_ctl); 88161d8658bSDupuis, Chad else 88261d8658bSDupuis, Chad qedf_initiate_seq_cleanup(orig_io_req, offset, r_ctl); 88361d8658bSDupuis, Chad } 88461d8658bSDupuis, Chad 88561d8658bSDupuis, Chad out_free_frame: 88661d8658bSDupuis, Chad fc_frame_free(fp); 88761d8658bSDupuis, Chad out_free: 88861d8658bSDupuis, Chad /* Put reference for original command since REC completed */ 88961d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 89061d8658bSDupuis, Chad kfree(cb_arg); 89161d8658bSDupuis, Chad } 89261d8658bSDupuis, Chad 89361d8658bSDupuis, Chad /* Assumes kref is already held by caller */ 89461d8658bSDupuis, Chad int qedf_send_rec(struct qedf_ioreq *orig_io_req) 89561d8658bSDupuis, Chad { 89661d8658bSDupuis, Chad 89761d8658bSDupuis, Chad struct fc_els_rec rec; 89861d8658bSDupuis, Chad struct qedf_rport *fcport; 89961d8658bSDupuis, Chad struct fc_lport *lport; 90061d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg = NULL; 90161d8658bSDupuis, Chad struct qedf_ctx *qedf; 90261d8658bSDupuis, Chad uint32_t sid; 90361d8658bSDupuis, Chad uint32_t r_a_tov; 90461d8658bSDupuis, Chad int rc; 90561d8658bSDupuis, Chad 90661d8658bSDupuis, Chad if (!orig_io_req) { 90761d8658bSDupuis, Chad QEDF_ERR(NULL, "orig_io_req is NULL.\n"); 90861d8658bSDupuis, Chad return -EINVAL; 90961d8658bSDupuis, Chad } 91061d8658bSDupuis, Chad 91161d8658bSDupuis, Chad fcport = orig_io_req->fcport; 91261d8658bSDupuis, Chad 91361d8658bSDupuis, Chad /* Check that fcport is still offloaded */ 91461d8658bSDupuis, Chad if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) { 91561d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport is no longer offloaded.\n"); 91661d8658bSDupuis, Chad return -EINVAL; 91761d8658bSDupuis, Chad } 91861d8658bSDupuis, Chad 91961d8658bSDupuis, Chad if (!fcport->qedf) { 92061d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport->qedf is NULL.\n"); 92161d8658bSDupuis, Chad return -EINVAL; 92261d8658bSDupuis, Chad } 92361d8658bSDupuis, Chad 92461d8658bSDupuis, Chad /* Take reference until REC command completion */ 92561d8658bSDupuis, Chad kref_get(&orig_io_req->refcount); 92661d8658bSDupuis, Chad 92761d8658bSDupuis, Chad qedf = fcport->qedf; 92861d8658bSDupuis, Chad lport = qedf->lport; 92961d8658bSDupuis, Chad sid = fcport->sid; 93061d8658bSDupuis, Chad r_a_tov = lport->r_a_tov; 93161d8658bSDupuis, Chad 93261d8658bSDupuis, Chad memset(&rec, 0, sizeof(rec)); 93361d8658bSDupuis, Chad 93461d8658bSDupuis, Chad cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO); 93561d8658bSDupuis, Chad if (!cb_arg) { 93661d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for " 93761d8658bSDupuis, Chad "REC\n"); 93861d8658bSDupuis, Chad rc = -ENOMEM; 93961d8658bSDupuis, Chad goto rec_err; 94061d8658bSDupuis, Chad } 94161d8658bSDupuis, Chad 94261d8658bSDupuis, Chad cb_arg->aborted_io_req = orig_io_req; 94361d8658bSDupuis, Chad 94461d8658bSDupuis, Chad rec.rec_cmd = ELS_REC; 94561d8658bSDupuis, Chad hton24(rec.rec_s_id, sid); 94661d8658bSDupuis, Chad rec.rec_ox_id = htons(orig_io_req->xid); 94761d8658bSDupuis, Chad rec.rec_rx_id = 94861d8658bSDupuis, Chad htons(orig_io_req->task->tstorm_st_context.read_write.rx_id); 94961d8658bSDupuis, Chad 95061d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending REC orig_io=%p, " 95161d8658bSDupuis, Chad "orig_xid=0x%x rx_id=0x%x\n", orig_io_req, 95261d8658bSDupuis, Chad orig_io_req->xid, rec.rec_rx_id); 95361d8658bSDupuis, Chad rc = qedf_initiate_els(fcport, ELS_REC, &rec, sizeof(rec), 95461d8658bSDupuis, Chad qedf_rec_compl, cb_arg, r_a_tov); 95561d8658bSDupuis, Chad 95661d8658bSDupuis, Chad rec_err: 95761d8658bSDupuis, Chad if (rc) { 95861d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "REC failed - release orig_io_req" 95961d8658bSDupuis, Chad "=0x%x\n", orig_io_req->xid); 96061d8658bSDupuis, Chad kfree(cb_arg); 96161d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 96261d8658bSDupuis, Chad } 96361d8658bSDupuis, Chad return rc; 96461d8658bSDupuis, Chad } 965