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 { 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; 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 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 4757a3548aSChad Dupuis 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 11287ea6bddSGustavo A. R. Silva __fc_fill_fc_hdr(fc_hdr, FC_RCTL_ELS_REQ, did, sid, 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 */ 22857a3548aSChad Dupuis 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 32544c7c859SChad Dupuis if (test_bit(QEDF_RPORT_IN_RESET, &fcport->flags) || 32644c7c859SChad Dupuis !test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags) || 32744c7c859SChad Dupuis test_bit(QEDF_RPORT_UPLOADING_CONNECTION, &fcport->flags)) { 32844c7c859SChad Dupuis QEDF_ERR(&(fcport->qedf->dbg_ctx), "fcport %p already in reset or not offloaded.\n", 32944c7c859SChad Dupuis fcport); 33044c7c859SChad Dupuis return; 33144c7c859SChad Dupuis } 33244c7c859SChad Dupuis 33344c7c859SChad Dupuis /* Set that we are now in reset */ 33444c7c859SChad Dupuis set_bit(QEDF_RPORT_IN_RESET, &fcport->flags); 33544c7c859SChad Dupuis 33661d8658bSDupuis, Chad rdata = fcport->rdata; 33761d8658bSDupuis, Chad if (rdata) { 33861d8658bSDupuis, Chad lport = fcport->qedf->lport; 33961d8658bSDupuis, Chad port_id = rdata->ids.port_id; 34061d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), 34161d8658bSDupuis, Chad "LOGO port_id=%x.\n", port_id); 34261d8658bSDupuis, Chad fc_rport_logoff(rdata); 34361d8658bSDupuis, Chad /* Recreate the rport and log back in */ 34461d8658bSDupuis, Chad rdata = fc_rport_create(lport, port_id); 34561d8658bSDupuis, Chad if (rdata) 34661d8658bSDupuis, Chad fc_rport_login(rdata); 34761d8658bSDupuis, Chad } 34844c7c859SChad Dupuis clear_bit(QEDF_RPORT_IN_RESET, &fcport->flags); 34961d8658bSDupuis, Chad } 35061d8658bSDupuis, Chad 35161d8658bSDupuis, Chad static void qedf_l2_els_compl(struct qedf_els_cb_arg *cb_arg) 35261d8658bSDupuis, Chad { 35361d8658bSDupuis, Chad struct qedf_ioreq *els_req; 35461d8658bSDupuis, Chad struct qedf_rport *fcport; 35561d8658bSDupuis, Chad struct qedf_mp_req *mp_req; 35661d8658bSDupuis, Chad struct fc_frame *fp; 35761d8658bSDupuis, Chad struct fc_frame_header *fh, *mp_fc_hdr; 35861d8658bSDupuis, Chad void *resp_buf, *fc_payload; 35961d8658bSDupuis, Chad u32 resp_len; 36061d8658bSDupuis, Chad u16 l2_oxid; 36161d8658bSDupuis, Chad 36261d8658bSDupuis, Chad l2_oxid = cb_arg->l2_oxid; 36361d8658bSDupuis, Chad els_req = cb_arg->io_req; 36461d8658bSDupuis, Chad 36561d8658bSDupuis, Chad if (!els_req) { 36661d8658bSDupuis, Chad QEDF_ERR(NULL, "els_req is NULL.\n"); 36761d8658bSDupuis, Chad goto free_arg; 36861d8658bSDupuis, Chad } 36961d8658bSDupuis, Chad 37061d8658bSDupuis, Chad /* 37161d8658bSDupuis, Chad * If we are flushing the command just free the cb_arg as none of the 37261d8658bSDupuis, Chad * response data will be valid. 37361d8658bSDupuis, Chad */ 37461d8658bSDupuis, Chad if (els_req->event == QEDF_IOREQ_EV_ELS_FLUSH) 37561d8658bSDupuis, Chad goto free_arg; 37661d8658bSDupuis, Chad 37761d8658bSDupuis, Chad fcport = els_req->fcport; 37861d8658bSDupuis, Chad mp_req = &(els_req->mp_req); 37961d8658bSDupuis, Chad mp_fc_hdr = &(mp_req->resp_fc_hdr); 38061d8658bSDupuis, Chad resp_len = mp_req->resp_len; 38161d8658bSDupuis, Chad resp_buf = mp_req->resp_buf; 38261d8658bSDupuis, Chad 38361d8658bSDupuis, Chad /* 38461d8658bSDupuis, Chad * If a middle path ELS command times out, don't try to return 38561d8658bSDupuis, Chad * the command but rather do any internal cleanup and then libfc 38661d8658bSDupuis, Chad * timeout the command and clean up its internal resources. 38761d8658bSDupuis, Chad */ 38861d8658bSDupuis, Chad if (els_req->event == QEDF_IOREQ_EV_ELS_TMO) { 38961d8658bSDupuis, Chad /* 39061d8658bSDupuis, Chad * If ADISC times out, libfc will timeout the exchange and then 39161d8658bSDupuis, Chad * try to send a PLOGI which will timeout since the session is 39261d8658bSDupuis, Chad * still offloaded. Force libfc to logout the session which 39361d8658bSDupuis, Chad * will offload the connection and allow the PLOGI response to 39461d8658bSDupuis, Chad * flow over the LL2 path. 39561d8658bSDupuis, Chad */ 39661d8658bSDupuis, Chad if (cb_arg->op == ELS_ADISC) 39761d8658bSDupuis, Chad qedf_restart_rport(fcport); 39861d8658bSDupuis, Chad return; 39961d8658bSDupuis, Chad } 40061d8658bSDupuis, Chad 40161d8658bSDupuis, Chad if (sizeof(struct fc_frame_header) + resp_len > QEDF_PAGE_SIZE) { 40261d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "resp_len is " 40361d8658bSDupuis, Chad "beyond page size.\n"); 40461d8658bSDupuis, Chad goto free_arg; 40561d8658bSDupuis, Chad } 40661d8658bSDupuis, Chad 40761d8658bSDupuis, Chad fp = fc_frame_alloc(fcport->qedf->lport, resp_len); 40861d8658bSDupuis, Chad if (!fp) { 40961d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), 41061d8658bSDupuis, Chad "fc_frame_alloc failure.\n"); 41161d8658bSDupuis, Chad return; 41261d8658bSDupuis, Chad } 41361d8658bSDupuis, Chad 41461d8658bSDupuis, Chad /* Copy frame header from firmware into fp */ 41561d8658bSDupuis, Chad fh = (struct fc_frame_header *)fc_frame_header_get(fp); 41661d8658bSDupuis, Chad memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header)); 41761d8658bSDupuis, Chad 41861d8658bSDupuis, Chad /* Copy payload from firmware into fp */ 41961d8658bSDupuis, Chad fc_payload = fc_frame_payload_get(fp, resp_len); 42061d8658bSDupuis, Chad memcpy(fc_payload, resp_buf, resp_len); 42161d8658bSDupuis, Chad 42261d8658bSDupuis, Chad QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS, 42361d8658bSDupuis, Chad "Completing OX_ID 0x%x back to libfc.\n", l2_oxid); 42461d8658bSDupuis, Chad qedf_process_l2_frame_compl(fcport, fp, l2_oxid); 42561d8658bSDupuis, Chad 42661d8658bSDupuis, Chad free_arg: 42761d8658bSDupuis, Chad kfree(cb_arg); 42861d8658bSDupuis, Chad } 42961d8658bSDupuis, Chad 43061d8658bSDupuis, Chad int qedf_send_adisc(struct qedf_rport *fcport, struct fc_frame *fp) 43161d8658bSDupuis, Chad { 43261d8658bSDupuis, Chad struct fc_els_adisc *adisc; 43361d8658bSDupuis, Chad struct fc_frame_header *fh; 43461d8658bSDupuis, Chad struct fc_lport *lport = fcport->qedf->lport; 43561d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg = NULL; 43661d8658bSDupuis, Chad struct qedf_ctx *qedf; 43761d8658bSDupuis, Chad uint32_t r_a_tov = lport->r_a_tov; 43861d8658bSDupuis, Chad int rc; 43961d8658bSDupuis, Chad 44061d8658bSDupuis, Chad qedf = fcport->qedf; 44161d8658bSDupuis, Chad fh = fc_frame_header_get(fp); 44261d8658bSDupuis, Chad 44361d8658bSDupuis, Chad cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO); 44461d8658bSDupuis, Chad if (!cb_arg) { 44561d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for " 44661d8658bSDupuis, Chad "ADISC\n"); 44761d8658bSDupuis, Chad rc = -ENOMEM; 44861d8658bSDupuis, Chad goto adisc_err; 44961d8658bSDupuis, Chad } 45061d8658bSDupuis, Chad cb_arg->l2_oxid = ntohs(fh->fh_ox_id); 45161d8658bSDupuis, Chad 45261d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 45361d8658bSDupuis, Chad "Sending ADISC ox_id=0x%x.\n", cb_arg->l2_oxid); 45461d8658bSDupuis, Chad 45561d8658bSDupuis, Chad adisc = fc_frame_payload_get(fp, sizeof(*adisc)); 45661d8658bSDupuis, Chad 45761d8658bSDupuis, Chad rc = qedf_initiate_els(fcport, ELS_ADISC, adisc, sizeof(*adisc), 45861d8658bSDupuis, Chad qedf_l2_els_compl, cb_arg, r_a_tov); 45961d8658bSDupuis, Chad 46061d8658bSDupuis, Chad adisc_err: 46161d8658bSDupuis, Chad if (rc) { 46261d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "ADISC failed.\n"); 46361d8658bSDupuis, Chad kfree(cb_arg); 46461d8658bSDupuis, Chad } 46561d8658bSDupuis, Chad return rc; 46661d8658bSDupuis, Chad } 46761d8658bSDupuis, Chad 46861d8658bSDupuis, Chad static void qedf_srr_compl(struct qedf_els_cb_arg *cb_arg) 46961d8658bSDupuis, Chad { 47061d8658bSDupuis, Chad struct qedf_ioreq *orig_io_req; 47161d8658bSDupuis, Chad struct qedf_ioreq *srr_req; 47261d8658bSDupuis, Chad struct qedf_mp_req *mp_req; 47361d8658bSDupuis, Chad struct fc_frame_header *mp_fc_hdr, *fh; 47461d8658bSDupuis, Chad struct fc_frame *fp; 47561d8658bSDupuis, Chad void *resp_buf, *fc_payload; 47661d8658bSDupuis, Chad u32 resp_len; 47761d8658bSDupuis, Chad struct fc_lport *lport; 47861d8658bSDupuis, Chad struct qedf_ctx *qedf; 47961d8658bSDupuis, Chad int refcount; 48061d8658bSDupuis, Chad u8 opcode; 48161d8658bSDupuis, Chad 48261d8658bSDupuis, Chad srr_req = cb_arg->io_req; 48361d8658bSDupuis, Chad qedf = srr_req->fcport->qedf; 48461d8658bSDupuis, Chad lport = qedf->lport; 48561d8658bSDupuis, Chad 48661d8658bSDupuis, Chad orig_io_req = cb_arg->aborted_io_req; 48761d8658bSDupuis, Chad 48861d8658bSDupuis, Chad if (!orig_io_req) 48961d8658bSDupuis, Chad goto out_free; 49061d8658bSDupuis, Chad 49161d8658bSDupuis, Chad clear_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags); 49261d8658bSDupuis, Chad 49361d8658bSDupuis, Chad if (srr_req->event != QEDF_IOREQ_EV_ELS_TMO && 49461d8658bSDupuis, Chad srr_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT) 49561d8658bSDupuis, Chad cancel_delayed_work_sync(&orig_io_req->timeout_work); 49661d8658bSDupuis, Chad 4971afca6b5SDupuis, Chad refcount = kref_read(&orig_io_req->refcount); 49861d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p," 49961d8658bSDupuis, Chad " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n", 50061d8658bSDupuis, Chad orig_io_req, orig_io_req->xid, srr_req->xid, refcount); 50161d8658bSDupuis, Chad 50261d8658bSDupuis, Chad /* If a SRR times out, simply free resources */ 50361d8658bSDupuis, Chad if (srr_req->event == QEDF_IOREQ_EV_ELS_TMO) 50447c4ccd3SChristophe JAILLET goto out_put; 50561d8658bSDupuis, Chad 50661d8658bSDupuis, Chad /* Normalize response data into struct fc_frame */ 50761d8658bSDupuis, Chad mp_req = &(srr_req->mp_req); 50861d8658bSDupuis, Chad mp_fc_hdr = &(mp_req->resp_fc_hdr); 50961d8658bSDupuis, Chad resp_len = mp_req->resp_len; 51061d8658bSDupuis, Chad resp_buf = mp_req->resp_buf; 51161d8658bSDupuis, Chad 51261d8658bSDupuis, Chad fp = fc_frame_alloc(lport, resp_len); 51361d8658bSDupuis, Chad if (!fp) { 51461d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), 51561d8658bSDupuis, Chad "fc_frame_alloc failure.\n"); 51647c4ccd3SChristophe JAILLET goto out_put; 51761d8658bSDupuis, Chad } 51861d8658bSDupuis, Chad 51961d8658bSDupuis, Chad /* Copy frame header from firmware into fp */ 52061d8658bSDupuis, Chad fh = (struct fc_frame_header *)fc_frame_header_get(fp); 52161d8658bSDupuis, Chad memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header)); 52261d8658bSDupuis, Chad 52361d8658bSDupuis, Chad /* Copy payload from firmware into fp */ 52461d8658bSDupuis, Chad fc_payload = fc_frame_payload_get(fp, resp_len); 52561d8658bSDupuis, Chad memcpy(fc_payload, resp_buf, resp_len); 52661d8658bSDupuis, Chad 52761d8658bSDupuis, Chad opcode = fc_frame_payload_op(fp); 52861d8658bSDupuis, Chad switch (opcode) { 52961d8658bSDupuis, Chad case ELS_LS_ACC: 53061d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 53161d8658bSDupuis, Chad "SRR success.\n"); 53261d8658bSDupuis, Chad break; 53361d8658bSDupuis, Chad case ELS_LS_RJT: 53461d8658bSDupuis, Chad QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_ELS, 53561d8658bSDupuis, Chad "SRR rejected.\n"); 53661d8658bSDupuis, Chad qedf_initiate_abts(orig_io_req, true); 53761d8658bSDupuis, Chad break; 53861d8658bSDupuis, Chad } 53961d8658bSDupuis, Chad 54061d8658bSDupuis, Chad fc_frame_free(fp); 54147c4ccd3SChristophe JAILLET out_put: 54261d8658bSDupuis, Chad /* Put reference for original command since SRR completed */ 54361d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 54447c4ccd3SChristophe JAILLET out_free: 54561d8658bSDupuis, Chad kfree(cb_arg); 54661d8658bSDupuis, Chad } 54761d8658bSDupuis, Chad 54861d8658bSDupuis, Chad static int qedf_send_srr(struct qedf_ioreq *orig_io_req, u32 offset, u8 r_ctl) 54961d8658bSDupuis, Chad { 55061d8658bSDupuis, Chad struct fcp_srr srr; 55161d8658bSDupuis, Chad struct qedf_ctx *qedf; 55261d8658bSDupuis, Chad struct qedf_rport *fcport; 55361d8658bSDupuis, Chad struct fc_lport *lport; 55461d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg = NULL; 55561d8658bSDupuis, Chad u32 sid, r_a_tov; 55661d8658bSDupuis, Chad int rc; 55761d8658bSDupuis, Chad 55861d8658bSDupuis, Chad if (!orig_io_req) { 55961d8658bSDupuis, Chad QEDF_ERR(NULL, "orig_io_req is NULL.\n"); 56061d8658bSDupuis, Chad return -EINVAL; 56161d8658bSDupuis, Chad } 56261d8658bSDupuis, Chad 56361d8658bSDupuis, Chad fcport = orig_io_req->fcport; 56461d8658bSDupuis, Chad 56561d8658bSDupuis, Chad /* Check that fcport is still offloaded */ 56657a3548aSChad Dupuis if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) { 56761d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport is no longer offloaded.\n"); 56861d8658bSDupuis, Chad return -EINVAL; 56961d8658bSDupuis, Chad } 57061d8658bSDupuis, Chad 57161d8658bSDupuis, Chad if (!fcport->qedf) { 57261d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport->qedf is NULL.\n"); 57361d8658bSDupuis, Chad return -EINVAL; 57461d8658bSDupuis, Chad } 57561d8658bSDupuis, Chad 57661d8658bSDupuis, Chad /* Take reference until SRR command completion */ 57761d8658bSDupuis, Chad kref_get(&orig_io_req->refcount); 57861d8658bSDupuis, Chad 57961d8658bSDupuis, Chad qedf = fcport->qedf; 58061d8658bSDupuis, Chad lport = qedf->lport; 58161d8658bSDupuis, Chad sid = fcport->sid; 58261d8658bSDupuis, Chad r_a_tov = lport->r_a_tov; 58361d8658bSDupuis, Chad 58461d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending SRR orig_io=%p, " 58561d8658bSDupuis, Chad "orig_xid=0x%x\n", orig_io_req, orig_io_req->xid); 58661d8658bSDupuis, Chad memset(&srr, 0, sizeof(srr)); 58761d8658bSDupuis, Chad 58861d8658bSDupuis, Chad cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO); 58961d8658bSDupuis, Chad if (!cb_arg) { 59061d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for " 59161d8658bSDupuis, Chad "SRR\n"); 59261d8658bSDupuis, Chad rc = -ENOMEM; 59361d8658bSDupuis, Chad goto srr_err; 59461d8658bSDupuis, Chad } 59561d8658bSDupuis, Chad 59661d8658bSDupuis, Chad cb_arg->aborted_io_req = orig_io_req; 59761d8658bSDupuis, Chad 59861d8658bSDupuis, Chad srr.srr_op = ELS_SRR; 59961d8658bSDupuis, Chad srr.srr_ox_id = htons(orig_io_req->xid); 60061d8658bSDupuis, Chad srr.srr_rx_id = htons(orig_io_req->rx_id); 60161d8658bSDupuis, Chad srr.srr_rel_off = htonl(offset); 60261d8658bSDupuis, Chad srr.srr_r_ctl = r_ctl; 60361d8658bSDupuis, Chad 60461d8658bSDupuis, Chad rc = qedf_initiate_els(fcport, ELS_SRR, &srr, sizeof(srr), 60561d8658bSDupuis, Chad qedf_srr_compl, cb_arg, r_a_tov); 60661d8658bSDupuis, Chad 60761d8658bSDupuis, Chad srr_err: 60861d8658bSDupuis, Chad if (rc) { 60961d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "SRR failed - release orig_io_req" 61061d8658bSDupuis, Chad "=0x%x\n", orig_io_req->xid); 61161d8658bSDupuis, Chad kfree(cb_arg); 61261d8658bSDupuis, Chad /* If we fail to queue SRR, send ABTS to orig_io */ 61361d8658bSDupuis, Chad qedf_initiate_abts(orig_io_req, true); 61461d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 61561d8658bSDupuis, Chad } else 61661d8658bSDupuis, Chad /* Tell other threads that SRR is in progress */ 61761d8658bSDupuis, Chad set_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags); 61861d8658bSDupuis, Chad 61961d8658bSDupuis, Chad return rc; 62061d8658bSDupuis, Chad } 62161d8658bSDupuis, Chad 62261d8658bSDupuis, Chad static void qedf_initiate_seq_cleanup(struct qedf_ioreq *orig_io_req, 62361d8658bSDupuis, Chad u32 offset, u8 r_ctl) 62461d8658bSDupuis, Chad { 62561d8658bSDupuis, Chad struct qedf_rport *fcport; 62661d8658bSDupuis, Chad unsigned long flags; 62761d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg; 628be086e7cSMintz, Yuval struct fcoe_wqe *sqe; 629be086e7cSMintz, Yuval u16 sqe_idx; 63061d8658bSDupuis, Chad 63161d8658bSDupuis, Chad fcport = orig_io_req->fcport; 63261d8658bSDupuis, Chad 63361d8658bSDupuis, Chad QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS, 63461d8658bSDupuis, Chad "Doing sequence cleanup for xid=0x%x offset=%u.\n", 63561d8658bSDupuis, Chad orig_io_req->xid, offset); 63661d8658bSDupuis, Chad 63761d8658bSDupuis, Chad cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO); 63861d8658bSDupuis, Chad if (!cb_arg) { 63961d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to allocate cb_arg " 64061d8658bSDupuis, Chad "for sequence cleanup\n"); 64161d8658bSDupuis, Chad return; 64261d8658bSDupuis, Chad } 64361d8658bSDupuis, Chad 64461d8658bSDupuis, Chad /* Get reference for cleanup request */ 64561d8658bSDupuis, Chad kref_get(&orig_io_req->refcount); 64661d8658bSDupuis, Chad 64761d8658bSDupuis, Chad orig_io_req->cmd_type = QEDF_SEQ_CLEANUP; 64861d8658bSDupuis, Chad cb_arg->offset = offset; 64961d8658bSDupuis, Chad cb_arg->r_ctl = r_ctl; 65061d8658bSDupuis, Chad orig_io_req->cb_arg = cb_arg; 65161d8658bSDupuis, Chad 65261d8658bSDupuis, Chad qedf_cmd_timer_set(fcport->qedf, orig_io_req, 65361d8658bSDupuis, Chad QEDF_CLEANUP_TIMEOUT * HZ); 65461d8658bSDupuis, Chad 65561d8658bSDupuis, Chad spin_lock_irqsave(&fcport->rport_lock, flags); 65661d8658bSDupuis, Chad 657be086e7cSMintz, Yuval sqe_idx = qedf_get_sqe_idx(fcport); 658be086e7cSMintz, Yuval sqe = &fcport->sq[sqe_idx]; 659be086e7cSMintz, Yuval memset(sqe, 0, sizeof(struct fcoe_wqe)); 660be086e7cSMintz, Yuval orig_io_req->task_params->sqe = sqe; 661be086e7cSMintz, Yuval 662be086e7cSMintz, Yuval init_initiator_sequence_recovery_fcoe_task(orig_io_req->task_params, 663be086e7cSMintz, Yuval offset); 66461d8658bSDupuis, Chad qedf_ring_doorbell(fcport); 66561d8658bSDupuis, Chad 66661d8658bSDupuis, Chad spin_unlock_irqrestore(&fcport->rport_lock, flags); 66761d8658bSDupuis, Chad } 66861d8658bSDupuis, Chad 66961d8658bSDupuis, Chad void qedf_process_seq_cleanup_compl(struct qedf_ctx *qedf, 67061d8658bSDupuis, Chad struct fcoe_cqe *cqe, struct qedf_ioreq *io_req) 67161d8658bSDupuis, Chad { 67261d8658bSDupuis, Chad int rc; 67361d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg; 67461d8658bSDupuis, Chad 67561d8658bSDupuis, Chad cb_arg = io_req->cb_arg; 67661d8658bSDupuis, Chad 67761d8658bSDupuis, Chad /* If we timed out just free resources */ 67861d8658bSDupuis, Chad if (io_req->event == QEDF_IOREQ_EV_ELS_TMO || !cqe) 67961d8658bSDupuis, Chad goto free; 68061d8658bSDupuis, Chad 68161d8658bSDupuis, Chad /* Kill the timer we put on the request */ 68261d8658bSDupuis, Chad cancel_delayed_work_sync(&io_req->timeout_work); 68361d8658bSDupuis, Chad 68461d8658bSDupuis, Chad rc = qedf_send_srr(io_req, cb_arg->offset, cb_arg->r_ctl); 68561d8658bSDupuis, Chad if (rc) 68661d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Unable to send SRR, I/O will " 68761d8658bSDupuis, Chad "abort, xid=0x%x.\n", io_req->xid); 68861d8658bSDupuis, Chad free: 68961d8658bSDupuis, Chad kfree(cb_arg); 69061d8658bSDupuis, Chad kref_put(&io_req->refcount, qedf_release_cmd); 69161d8658bSDupuis, Chad } 69261d8658bSDupuis, Chad 69361d8658bSDupuis, Chad static bool qedf_requeue_io_req(struct qedf_ioreq *orig_io_req) 69461d8658bSDupuis, Chad { 69561d8658bSDupuis, Chad struct qedf_rport *fcport; 69661d8658bSDupuis, Chad struct qedf_ioreq *new_io_req; 69761d8658bSDupuis, Chad unsigned long flags; 69861d8658bSDupuis, Chad bool rc = false; 69961d8658bSDupuis, Chad 70061d8658bSDupuis, Chad fcport = orig_io_req->fcport; 70161d8658bSDupuis, Chad if (!fcport) { 70261d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport is NULL.\n"); 70361d8658bSDupuis, Chad goto out; 70461d8658bSDupuis, Chad } 70561d8658bSDupuis, Chad 70661d8658bSDupuis, Chad if (!orig_io_req->sc_cmd) { 70761d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "sc_cmd is NULL for " 70861d8658bSDupuis, Chad "xid=0x%x.\n", orig_io_req->xid); 70961d8658bSDupuis, Chad goto out; 71061d8658bSDupuis, Chad } 71161d8658bSDupuis, Chad 71261d8658bSDupuis, Chad new_io_req = qedf_alloc_cmd(fcport, QEDF_SCSI_CMD); 71361d8658bSDupuis, Chad if (!new_io_req) { 71461d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "Could not allocate new " 71561d8658bSDupuis, Chad "io_req.\n"); 71661d8658bSDupuis, Chad goto out; 71761d8658bSDupuis, Chad } 71861d8658bSDupuis, Chad 71961d8658bSDupuis, Chad new_io_req->sc_cmd = orig_io_req->sc_cmd; 72061d8658bSDupuis, Chad 72161d8658bSDupuis, Chad /* 72261d8658bSDupuis, Chad * This keeps the sc_cmd struct from being returned to the tape 72361d8658bSDupuis, Chad * driver and being requeued twice. We do need to put a reference 72461d8658bSDupuis, Chad * for the original I/O request since we will not do a SCSI completion 72561d8658bSDupuis, Chad * for it. 72661d8658bSDupuis, Chad */ 72761d8658bSDupuis, Chad orig_io_req->sc_cmd = NULL; 72861d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 72961d8658bSDupuis, Chad 73061d8658bSDupuis, Chad spin_lock_irqsave(&fcport->rport_lock, flags); 73161d8658bSDupuis, Chad 73261d8658bSDupuis, Chad /* kref for new command released in qedf_post_io_req on error */ 73361d8658bSDupuis, Chad if (qedf_post_io_req(fcport, new_io_req)) { 73461d8658bSDupuis, Chad QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to post io_req\n"); 73561d8658bSDupuis, Chad /* Return SQE to pool */ 73661d8658bSDupuis, Chad atomic_inc(&fcport->free_sqes); 73761d8658bSDupuis, Chad } else { 73861d8658bSDupuis, Chad QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS, 73961d8658bSDupuis, Chad "Reissued SCSI command from orig_xid=0x%x on " 74061d8658bSDupuis, Chad "new_xid=0x%x.\n", orig_io_req->xid, new_io_req->xid); 74161d8658bSDupuis, Chad /* 74261d8658bSDupuis, Chad * Abort the original I/O but do not return SCSI command as 74361d8658bSDupuis, Chad * it has been reissued on another OX_ID. 74461d8658bSDupuis, Chad */ 74561d8658bSDupuis, Chad spin_unlock_irqrestore(&fcport->rport_lock, flags); 74661d8658bSDupuis, Chad qedf_initiate_abts(orig_io_req, false); 74761d8658bSDupuis, Chad goto out; 74861d8658bSDupuis, Chad } 74961d8658bSDupuis, Chad 75061d8658bSDupuis, Chad spin_unlock_irqrestore(&fcport->rport_lock, flags); 75161d8658bSDupuis, Chad out: 75261d8658bSDupuis, Chad return rc; 75361d8658bSDupuis, Chad } 75461d8658bSDupuis, Chad 75561d8658bSDupuis, Chad 75661d8658bSDupuis, Chad static void qedf_rec_compl(struct qedf_els_cb_arg *cb_arg) 75761d8658bSDupuis, Chad { 75861d8658bSDupuis, Chad struct qedf_ioreq *orig_io_req; 75961d8658bSDupuis, Chad struct qedf_ioreq *rec_req; 76061d8658bSDupuis, Chad struct qedf_mp_req *mp_req; 76161d8658bSDupuis, Chad struct fc_frame_header *mp_fc_hdr, *fh; 76261d8658bSDupuis, Chad struct fc_frame *fp; 76361d8658bSDupuis, Chad void *resp_buf, *fc_payload; 76461d8658bSDupuis, Chad u32 resp_len; 76561d8658bSDupuis, Chad struct fc_lport *lport; 76661d8658bSDupuis, Chad struct qedf_ctx *qedf; 76761d8658bSDupuis, Chad int refcount; 76861d8658bSDupuis, Chad enum fc_rctl r_ctl; 76961d8658bSDupuis, Chad struct fc_els_ls_rjt *rjt; 77061d8658bSDupuis, Chad struct fc_els_rec_acc *acc; 77161d8658bSDupuis, Chad u8 opcode; 77261d8658bSDupuis, Chad u32 offset, e_stat; 77361d8658bSDupuis, Chad struct scsi_cmnd *sc_cmd; 77461d8658bSDupuis, Chad bool srr_needed = false; 77561d8658bSDupuis, Chad 77661d8658bSDupuis, Chad rec_req = cb_arg->io_req; 77761d8658bSDupuis, Chad qedf = rec_req->fcport->qedf; 77861d8658bSDupuis, Chad lport = qedf->lport; 77961d8658bSDupuis, Chad 78061d8658bSDupuis, Chad orig_io_req = cb_arg->aborted_io_req; 78161d8658bSDupuis, Chad 78261d8658bSDupuis, Chad if (!orig_io_req) 78361d8658bSDupuis, Chad goto out_free; 78461d8658bSDupuis, Chad 78561d8658bSDupuis, Chad if (rec_req->event != QEDF_IOREQ_EV_ELS_TMO && 78661d8658bSDupuis, Chad rec_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT) 78761d8658bSDupuis, Chad cancel_delayed_work_sync(&orig_io_req->timeout_work); 78861d8658bSDupuis, Chad 7891afca6b5SDupuis, Chad refcount = kref_read(&orig_io_req->refcount); 79061d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p," 79161d8658bSDupuis, Chad " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n", 79261d8658bSDupuis, Chad orig_io_req, orig_io_req->xid, rec_req->xid, refcount); 79361d8658bSDupuis, Chad 79461d8658bSDupuis, Chad /* If a REC times out, free resources */ 79561d8658bSDupuis, Chad if (rec_req->event == QEDF_IOREQ_EV_ELS_TMO) 79647c4ccd3SChristophe JAILLET goto out_put; 79761d8658bSDupuis, Chad 79861d8658bSDupuis, Chad /* Normalize response data into struct fc_frame */ 79961d8658bSDupuis, Chad mp_req = &(rec_req->mp_req); 80061d8658bSDupuis, Chad mp_fc_hdr = &(mp_req->resp_fc_hdr); 80161d8658bSDupuis, Chad resp_len = mp_req->resp_len; 80261d8658bSDupuis, Chad acc = resp_buf = mp_req->resp_buf; 80361d8658bSDupuis, Chad 80461d8658bSDupuis, Chad fp = fc_frame_alloc(lport, resp_len); 80561d8658bSDupuis, Chad if (!fp) { 80661d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), 80761d8658bSDupuis, Chad "fc_frame_alloc failure.\n"); 80847c4ccd3SChristophe JAILLET goto out_put; 80961d8658bSDupuis, Chad } 81061d8658bSDupuis, Chad 81161d8658bSDupuis, Chad /* Copy frame header from firmware into fp */ 81261d8658bSDupuis, Chad fh = (struct fc_frame_header *)fc_frame_header_get(fp); 81361d8658bSDupuis, Chad memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header)); 81461d8658bSDupuis, Chad 81561d8658bSDupuis, Chad /* Copy payload from firmware into fp */ 81661d8658bSDupuis, Chad fc_payload = fc_frame_payload_get(fp, resp_len); 81761d8658bSDupuis, Chad memcpy(fc_payload, resp_buf, resp_len); 81861d8658bSDupuis, Chad 81961d8658bSDupuis, Chad opcode = fc_frame_payload_op(fp); 82061d8658bSDupuis, Chad if (opcode == ELS_LS_RJT) { 82161d8658bSDupuis, Chad rjt = fc_frame_payload_get(fp, sizeof(*rjt)); 82261d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 82361d8658bSDupuis, Chad "Received LS_RJT for REC: er_reason=0x%x, " 82461d8658bSDupuis, Chad "er_explan=0x%x.\n", rjt->er_reason, rjt->er_explan); 82561d8658bSDupuis, Chad /* 82661d8658bSDupuis, Chad * The following response(s) mean that we need to reissue the 82761d8658bSDupuis, Chad * request on another exchange. We need to do this without 82861d8658bSDupuis, Chad * informing the upper layers lest it cause an application 82961d8658bSDupuis, Chad * error. 83061d8658bSDupuis, Chad */ 83161d8658bSDupuis, Chad if ((rjt->er_reason == ELS_RJT_LOGIC || 83261d8658bSDupuis, Chad rjt->er_reason == ELS_RJT_UNAB) && 83361d8658bSDupuis, Chad rjt->er_explan == ELS_EXPL_OXID_RXID) { 83461d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 83561d8658bSDupuis, Chad "Handle CMD LOST case.\n"); 83661d8658bSDupuis, Chad qedf_requeue_io_req(orig_io_req); 83761d8658bSDupuis, Chad } 83861d8658bSDupuis, Chad } else if (opcode == ELS_LS_ACC) { 83961d8658bSDupuis, Chad offset = ntohl(acc->reca_fc4value); 84061d8658bSDupuis, Chad e_stat = ntohl(acc->reca_e_stat); 84161d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 84261d8658bSDupuis, Chad "Received LS_ACC for REC: offset=0x%x, e_stat=0x%x.\n", 84361d8658bSDupuis, Chad offset, e_stat); 84461d8658bSDupuis, Chad if (e_stat & ESB_ST_SEQ_INIT) { 84561d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 84661d8658bSDupuis, Chad "Target has the seq init\n"); 84761d8658bSDupuis, Chad goto out_free_frame; 84861d8658bSDupuis, Chad } 84961d8658bSDupuis, Chad sc_cmd = orig_io_req->sc_cmd; 85061d8658bSDupuis, Chad if (!sc_cmd) { 85161d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 85261d8658bSDupuis, Chad "sc_cmd is NULL for xid=0x%x.\n", 85361d8658bSDupuis, Chad orig_io_req->xid); 85461d8658bSDupuis, Chad goto out_free_frame; 85561d8658bSDupuis, Chad } 85661d8658bSDupuis, Chad /* SCSI write case */ 85761d8658bSDupuis, Chad if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) { 85861d8658bSDupuis, Chad if (offset == orig_io_req->data_xfer_len) { 85961d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 86061d8658bSDupuis, Chad "WRITE - response lost.\n"); 86161d8658bSDupuis, Chad r_ctl = FC_RCTL_DD_CMD_STATUS; 86261d8658bSDupuis, Chad srr_needed = true; 86361d8658bSDupuis, Chad offset = 0; 86461d8658bSDupuis, Chad } else { 86561d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 86661d8658bSDupuis, Chad "WRITE - XFER_RDY/DATA lost.\n"); 86761d8658bSDupuis, Chad r_ctl = FC_RCTL_DD_DATA_DESC; 86861d8658bSDupuis, Chad /* Use data from warning CQE instead of REC */ 86961d8658bSDupuis, Chad offset = orig_io_req->tx_buf_off; 87061d8658bSDupuis, Chad } 87161d8658bSDupuis, Chad /* SCSI read case */ 87261d8658bSDupuis, Chad } else { 87361d8658bSDupuis, Chad if (orig_io_req->rx_buf_off == 87461d8658bSDupuis, Chad orig_io_req->data_xfer_len) { 87561d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 87661d8658bSDupuis, Chad "READ - response lost.\n"); 87761d8658bSDupuis, Chad srr_needed = true; 87861d8658bSDupuis, Chad r_ctl = FC_RCTL_DD_CMD_STATUS; 87961d8658bSDupuis, Chad offset = 0; 88061d8658bSDupuis, Chad } else { 88161d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, 88261d8658bSDupuis, Chad "READ - DATA lost.\n"); 88361d8658bSDupuis, Chad /* 88461d8658bSDupuis, Chad * For read case we always set the offset to 0 88561d8658bSDupuis, Chad * for sequence recovery task. 88661d8658bSDupuis, Chad */ 88761d8658bSDupuis, Chad offset = 0; 88861d8658bSDupuis, Chad r_ctl = FC_RCTL_DD_SOL_DATA; 88961d8658bSDupuis, Chad } 89061d8658bSDupuis, Chad } 89161d8658bSDupuis, Chad 89261d8658bSDupuis, Chad if (srr_needed) 89361d8658bSDupuis, Chad qedf_send_srr(orig_io_req, offset, r_ctl); 89461d8658bSDupuis, Chad else 89561d8658bSDupuis, Chad qedf_initiate_seq_cleanup(orig_io_req, offset, r_ctl); 89661d8658bSDupuis, Chad } 89761d8658bSDupuis, Chad 89861d8658bSDupuis, Chad out_free_frame: 89961d8658bSDupuis, Chad fc_frame_free(fp); 90047c4ccd3SChristophe JAILLET out_put: 90161d8658bSDupuis, Chad /* Put reference for original command since REC completed */ 90261d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 90347c4ccd3SChristophe JAILLET out_free: 90461d8658bSDupuis, Chad kfree(cb_arg); 90561d8658bSDupuis, Chad } 90661d8658bSDupuis, Chad 90761d8658bSDupuis, Chad /* Assumes kref is already held by caller */ 90861d8658bSDupuis, Chad int qedf_send_rec(struct qedf_ioreq *orig_io_req) 90961d8658bSDupuis, Chad { 91061d8658bSDupuis, Chad 91161d8658bSDupuis, Chad struct fc_els_rec rec; 91261d8658bSDupuis, Chad struct qedf_rport *fcport; 91361d8658bSDupuis, Chad struct fc_lport *lport; 91461d8658bSDupuis, Chad struct qedf_els_cb_arg *cb_arg = NULL; 91561d8658bSDupuis, Chad struct qedf_ctx *qedf; 91661d8658bSDupuis, Chad uint32_t sid; 91761d8658bSDupuis, Chad uint32_t r_a_tov; 91861d8658bSDupuis, Chad int rc; 91961d8658bSDupuis, Chad 92061d8658bSDupuis, Chad if (!orig_io_req) { 92161d8658bSDupuis, Chad QEDF_ERR(NULL, "orig_io_req is NULL.\n"); 92261d8658bSDupuis, Chad return -EINVAL; 92361d8658bSDupuis, Chad } 92461d8658bSDupuis, Chad 92561d8658bSDupuis, Chad fcport = orig_io_req->fcport; 92661d8658bSDupuis, Chad 92761d8658bSDupuis, Chad /* Check that fcport is still offloaded */ 92861d8658bSDupuis, Chad if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) { 92961d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport is no longer offloaded.\n"); 93061d8658bSDupuis, Chad return -EINVAL; 93161d8658bSDupuis, Chad } 93261d8658bSDupuis, Chad 93361d8658bSDupuis, Chad if (!fcport->qedf) { 93461d8658bSDupuis, Chad QEDF_ERR(NULL, "fcport->qedf is NULL.\n"); 93561d8658bSDupuis, Chad return -EINVAL; 93661d8658bSDupuis, Chad } 93761d8658bSDupuis, Chad 93861d8658bSDupuis, Chad /* Take reference until REC command completion */ 93961d8658bSDupuis, Chad kref_get(&orig_io_req->refcount); 94061d8658bSDupuis, Chad 94161d8658bSDupuis, Chad qedf = fcport->qedf; 94261d8658bSDupuis, Chad lport = qedf->lport; 94361d8658bSDupuis, Chad sid = fcport->sid; 94461d8658bSDupuis, Chad r_a_tov = lport->r_a_tov; 94561d8658bSDupuis, Chad 94661d8658bSDupuis, Chad memset(&rec, 0, sizeof(rec)); 94761d8658bSDupuis, Chad 94861d8658bSDupuis, Chad cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO); 94961d8658bSDupuis, Chad if (!cb_arg) { 95061d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for " 95161d8658bSDupuis, Chad "REC\n"); 95261d8658bSDupuis, Chad rc = -ENOMEM; 95361d8658bSDupuis, Chad goto rec_err; 95461d8658bSDupuis, Chad } 95561d8658bSDupuis, Chad 95661d8658bSDupuis, Chad cb_arg->aborted_io_req = orig_io_req; 95761d8658bSDupuis, Chad 95861d8658bSDupuis, Chad rec.rec_cmd = ELS_REC; 95961d8658bSDupuis, Chad hton24(rec.rec_s_id, sid); 96061d8658bSDupuis, Chad rec.rec_ox_id = htons(orig_io_req->xid); 96161d8658bSDupuis, Chad rec.rec_rx_id = 96261d8658bSDupuis, Chad htons(orig_io_req->task->tstorm_st_context.read_write.rx_id); 96361d8658bSDupuis, Chad 96461d8658bSDupuis, Chad QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending REC orig_io=%p, " 96561d8658bSDupuis, Chad "orig_xid=0x%x rx_id=0x%x\n", orig_io_req, 96661d8658bSDupuis, Chad orig_io_req->xid, rec.rec_rx_id); 96761d8658bSDupuis, Chad rc = qedf_initiate_els(fcport, ELS_REC, &rec, sizeof(rec), 96861d8658bSDupuis, Chad qedf_rec_compl, cb_arg, r_a_tov); 96961d8658bSDupuis, Chad 97061d8658bSDupuis, Chad rec_err: 97161d8658bSDupuis, Chad if (rc) { 97261d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "REC failed - release orig_io_req" 97361d8658bSDupuis, Chad "=0x%x\n", orig_io_req->xid); 97461d8658bSDupuis, Chad kfree(cb_arg); 97561d8658bSDupuis, Chad kref_put(&orig_io_req->refcount, qedf_release_cmd); 97661d8658bSDupuis, Chad } 97761d8658bSDupuis, Chad return rc; 97861d8658bSDupuis, Chad } 979