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