2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016-2018 Cavium Inc.
5 * This software is available under the terms of the GNU General Public License
6 * (GPL) Version 2, available from the file COPYING in the main directory of
11 /* It's assumed that the lock is held when calling this function. */
12 static int qedf_initiate_els(struct qedf_rport *fcport, unsigned int op,
13 void *data, uint32_t data_len,
14 void (*cb_func)(struct qedf_els_cb_arg *cb_arg),
15 struct qedf_els_cb_arg *cb_arg, uint32_t timer_msec)
17 struct qedf_ctx *qedf;
18 struct fc_lport *lport;
19 struct qedf_ioreq *els_req;
20 struct qedf_mp_req *mp_req;
21 struct fc_frame_header *fc_hdr;
22 struct e4_fcoe_task_context *task;
31 QEDF_ERR(NULL, "fcport is NULL");
39 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending ELS\n");
41 rc = fc_remote_port_chkready(fcport->rport);
43 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: rport not ready\n", op);
47 if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
48 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: link is not ready\n",
54 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
55 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: fcport not ready\n", op);
60 els_req = qedf_alloc_cmd(fcport, QEDF_ELS);
62 QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_ELS,
63 "Failed to alloc ELS request 0x%x\n", op);
68 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "initiate_els els_req = "
69 "0x%p cb_arg = %p xid = %x\n", els_req, cb_arg,
71 els_req->sc_cmd = NULL;
72 els_req->cmd_type = QEDF_ELS;
73 els_req->fcport = fcport;
74 els_req->cb_func = cb_func;
75 cb_arg->io_req = els_req;
77 els_req->cb_arg = cb_arg;
78 els_req->data_xfer_len = data_len;
80 /* Record which cpu this request is associated with */
81 els_req->cpu = smp_processor_id();
83 mp_req = (struct qedf_mp_req *)&(els_req->mp_req);
84 rc = qedf_init_mp_req(els_req);
86 QEDF_ERR(&(qedf->dbg_ctx), "ELS MP request init failed\n");
87 kref_put(&els_req->refcount, qedf_release_cmd);
93 /* Fill ELS Payload */
94 if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS)) {
95 memcpy(mp_req->req_buf, data, data_len);
97 QEDF_ERR(&(qedf->dbg_ctx), "Invalid ELS op 0x%x\n", op);
98 els_req->cb_func = NULL;
99 els_req->cb_arg = NULL;
100 kref_put(&els_req->refcount, qedf_release_cmd);
108 fc_hdr = &(mp_req->req_fc_hdr);
110 did = fcport->rdata->ids.port_id;
113 __fc_fill_fc_hdr(fc_hdr, FC_RCTL_ELS_REQ, did, sid,
114 FC_TYPE_ELS, FC_FC_FIRST_SEQ | FC_FC_END_SEQ |
117 /* Obtain exchange id */
120 spin_lock_irqsave(&fcport->rport_lock, flags);
122 sqe_idx = qedf_get_sqe_idx(fcport);
123 sqe = &fcport->sq[sqe_idx];
124 memset(sqe, 0, sizeof(struct fcoe_wqe));
126 /* Initialize task context for this IO request */
127 task = qedf_get_task_mem(&qedf->tasks, xid);
128 qedf_init_mp_task(els_req, task, sqe);
130 /* Put timer on original I/O request */
132 qedf_cmd_timer_set(qedf, els_req, timer_msec);
135 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Ringing doorbell for ELS "
137 qedf_ring_doorbell(fcport);
138 set_bit(QEDF_CMD_OUTSTANDING, &els_req->flags);
140 spin_unlock_irqrestore(&fcport->rport_lock, flags);
145 void qedf_process_els_compl(struct qedf_ctx *qedf, struct fcoe_cqe *cqe,
146 struct qedf_ioreq *els_req)
148 struct fcoe_task_context *task_ctx;
149 struct scsi_cmnd *sc_cmd;
151 struct fcoe_cqe_midpath_info *mp_info;
153 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered with xid = 0x%x"
154 " cmd_type = %d.\n", els_req->xid, els_req->cmd_type);
156 clear_bit(QEDF_CMD_OUTSTANDING, &els_req->flags);
158 /* Kill the ELS timer */
159 cancel_delayed_work(&els_req->timeout_work);
162 task_ctx = qedf_get_task_mem(&qedf->tasks, xid);
163 sc_cmd = els_req->sc_cmd;
165 /* Get ELS response length from CQE */
166 mp_info = &cqe->cqe_info.midpath_info;
167 els_req->mp_req.resp_len = mp_info->data_placement_size;
169 /* Parse ELS response */
170 if ((els_req->cb_func) && (els_req->cb_arg)) {
171 els_req->cb_func(els_req->cb_arg);
172 els_req->cb_arg = NULL;
175 kref_put(&els_req->refcount, qedf_release_cmd);
178 static void qedf_rrq_compl(struct qedf_els_cb_arg *cb_arg)
180 struct qedf_ioreq *orig_io_req;
181 struct qedf_ioreq *rrq_req;
182 struct qedf_ctx *qedf;
185 rrq_req = cb_arg->io_req;
186 qedf = rrq_req->fcport->qedf;
188 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered.\n");
190 orig_io_req = cb_arg->aborted_io_req;
195 if (rrq_req->event != QEDF_IOREQ_EV_ELS_TMO &&
196 rrq_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
197 cancel_delayed_work_sync(&orig_io_req->timeout_work);
199 refcount = kref_read(&orig_io_req->refcount);
200 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "rrq_compl: orig io = %p,"
201 " orig xid = 0x%x, rrq_xid = 0x%x, refcount=%d\n",
202 orig_io_req, orig_io_req->xid, rrq_req->xid, refcount);
205 * This should return the aborted io_req to the command pool. Note that
206 * we need to check the refcound in case the original request was
207 * flushed but we get a completion on this xid.
209 if (orig_io_req && refcount > 0)
210 kref_put(&orig_io_req->refcount, qedf_release_cmd);
214 * Release a reference to the rrq request if we timed out as the
215 * rrq completion handler is called directly from the timeout handler
216 * and not from els_compl where the reference would have normally been
219 if (rrq_req->event == QEDF_IOREQ_EV_ELS_TMO)
220 kref_put(&rrq_req->refcount, qedf_release_cmd);
224 /* Assumes kref is already held by caller */
225 int qedf_send_rrq(struct qedf_ioreq *aborted_io_req)
228 struct fc_els_rrq rrq;
229 struct qedf_rport *fcport;
230 struct fc_lport *lport;
231 struct qedf_els_cb_arg *cb_arg = NULL;
232 struct qedf_ctx *qedf;
238 if (!aborted_io_req) {
239 QEDF_ERR(NULL, "abort_io_req is NULL.\n");
243 fcport = aborted_io_req->fcport;
246 refcount = kref_read(&aborted_io_req->refcount);
248 "RRQ work was queued prior to a flush xid=0x%x, refcount=%d.\n",
249 aborted_io_req->xid, refcount);
250 kref_put(&aborted_io_req->refcount, qedf_release_cmd);
254 /* Check that fcport is still offloaded */
255 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
256 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
261 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
268 * Sanity check that we can send a RRQ to make sure that refcount isn't
271 refcount = kref_read(&aborted_io_req->refcount);
273 QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_ELS,
274 "refcount for xid=%x io_req=%p refcount=%d is not 1.\n",
275 aborted_io_req->xid, aborted_io_req, refcount);
281 r_a_tov = lport->r_a_tov;
283 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending RRQ orig "
284 "io = %p, orig_xid = 0x%x\n", aborted_io_req,
285 aborted_io_req->xid);
286 memset(&rrq, 0, sizeof(rrq));
288 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
290 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
296 cb_arg->aborted_io_req = aborted_io_req;
298 rrq.rrq_cmd = ELS_RRQ;
299 hton24(rrq.rrq_s_id, sid);
300 rrq.rrq_ox_id = htons(aborted_io_req->xid);
302 htons(aborted_io_req->task->tstorm_st_context.read_write.rx_id);
304 rc = qedf_initiate_els(fcport, ELS_RRQ, &rrq, sizeof(rrq),
305 qedf_rrq_compl, cb_arg, r_a_tov);
309 QEDF_ERR(&(qedf->dbg_ctx), "RRQ failed - release orig io "
310 "req 0x%x\n", aborted_io_req->xid);
312 kref_put(&aborted_io_req->refcount, qedf_release_cmd);
317 static void qedf_process_l2_frame_compl(struct qedf_rport *fcport,
321 struct fc_lport *lport = fcport->qedf->lport;
322 struct fc_frame_header *fh;
325 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
327 /* Set the OXID we return to what libfc used */
328 if (l2_oxid != FC_XID_UNKNOWN)
329 fh->fh_ox_id = htons(l2_oxid);
331 /* Setup header fields */
332 fh->fh_r_ctl = FC_RCTL_ELS_REP;
333 fh->fh_type = FC_TYPE_ELS;
334 /* Last sequence, end sequence */
335 fh->fh_f_ctl[0] = 0x98;
336 hton24(fh->fh_d_id, lport->port_id);
337 hton24(fh->fh_s_id, fcport->rdata->ids.port_id);
338 fh->fh_rx_id = 0xffff;
340 /* Set frame attributes */
341 crc = fcoe_fc_crc(fp);
344 fr_sof(fp) = FC_SOF_I3;
345 fr_eof(fp) = FC_EOF_T;
346 fr_crc(fp) = cpu_to_le32(~crc);
348 /* Send completed request to libfc */
349 fc_exch_recv(lport, fp);
353 * In instances where an ELS command times out we may need to restart the
354 * rport by logging out and then logging back in.
356 void qedf_restart_rport(struct qedf_rport *fcport)
358 struct fc_lport *lport;
359 struct fc_rport_priv *rdata;
365 if (test_bit(QEDF_RPORT_IN_RESET, &fcport->flags) ||
366 !test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags) ||
367 test_bit(QEDF_RPORT_UPLOADING_CONNECTION, &fcport->flags)) {
368 QEDF_ERR(&(fcport->qedf->dbg_ctx), "fcport %p already in reset or not offloaded.\n",
373 /* Set that we are now in reset */
374 set_bit(QEDF_RPORT_IN_RESET, &fcport->flags);
376 rdata = fcport->rdata;
378 lport = fcport->qedf->lport;
379 port_id = rdata->ids.port_id;
380 QEDF_ERR(&(fcport->qedf->dbg_ctx),
381 "LOGO port_id=%x.\n", port_id);
382 fc_rport_logoff(rdata);
383 mutex_lock(&lport->disc.disc_mutex);
384 /* Recreate the rport and log back in */
385 rdata = fc_rport_create(lport, port_id);
387 mutex_unlock(&lport->disc.disc_mutex);
388 fc_rport_login(rdata);
389 fcport->rdata = rdata;
391 mutex_unlock(&lport->disc.disc_mutex);
394 clear_bit(QEDF_RPORT_IN_RESET, &fcport->flags);
397 static void qedf_l2_els_compl(struct qedf_els_cb_arg *cb_arg)
399 struct qedf_ioreq *els_req;
400 struct qedf_rport *fcport;
401 struct qedf_mp_req *mp_req;
403 struct fc_frame_header *fh, *mp_fc_hdr;
404 void *resp_buf, *fc_payload;
408 l2_oxid = cb_arg->l2_oxid;
409 els_req = cb_arg->io_req;
412 QEDF_ERR(NULL, "els_req is NULL.\n");
417 * If we are flushing the command just free the cb_arg as none of the
418 * response data will be valid.
420 if (els_req->event == QEDF_IOREQ_EV_ELS_FLUSH)
423 fcport = els_req->fcport;
424 mp_req = &(els_req->mp_req);
425 mp_fc_hdr = &(mp_req->resp_fc_hdr);
426 resp_len = mp_req->resp_len;
427 resp_buf = mp_req->resp_buf;
430 * If a middle path ELS command times out, don't try to return
431 * the command but rather do any internal cleanup and then libfc
432 * timeout the command and clean up its internal resources.
434 if (els_req->event == QEDF_IOREQ_EV_ELS_TMO) {
436 * If ADISC times out, libfc will timeout the exchange and then
437 * try to send a PLOGI which will timeout since the session is
438 * still offloaded. Force libfc to logout the session which
439 * will offload the connection and allow the PLOGI response to
440 * flow over the LL2 path.
442 if (cb_arg->op == ELS_ADISC)
443 qedf_restart_rport(fcport);
447 if (sizeof(struct fc_frame_header) + resp_len > QEDF_PAGE_SIZE) {
448 QEDF_ERR(&(fcport->qedf->dbg_ctx), "resp_len is "
449 "beyond page size.\n");
453 fp = fc_frame_alloc(fcport->qedf->lport, resp_len);
455 QEDF_ERR(&(fcport->qedf->dbg_ctx),
456 "fc_frame_alloc failure.\n");
460 /* Copy frame header from firmware into fp */
461 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
462 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
464 /* Copy payload from firmware into fp */
465 fc_payload = fc_frame_payload_get(fp, resp_len);
466 memcpy(fc_payload, resp_buf, resp_len);
468 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
469 "Completing OX_ID 0x%x back to libfc.\n", l2_oxid);
470 qedf_process_l2_frame_compl(fcport, fp, l2_oxid);
476 int qedf_send_adisc(struct qedf_rport *fcport, struct fc_frame *fp)
478 struct fc_els_adisc *adisc;
479 struct fc_frame_header *fh;
480 struct fc_lport *lport = fcport->qedf->lport;
481 struct qedf_els_cb_arg *cb_arg = NULL;
482 struct qedf_ctx *qedf;
483 uint32_t r_a_tov = lport->r_a_tov;
487 fh = fc_frame_header_get(fp);
489 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
491 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
496 cb_arg->l2_oxid = ntohs(fh->fh_ox_id);
498 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
499 "Sending ADISC ox_id=0x%x.\n", cb_arg->l2_oxid);
501 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
503 rc = qedf_initiate_els(fcport, ELS_ADISC, adisc, sizeof(*adisc),
504 qedf_l2_els_compl, cb_arg, r_a_tov);
508 QEDF_ERR(&(qedf->dbg_ctx), "ADISC failed.\n");
514 static void qedf_srr_compl(struct qedf_els_cb_arg *cb_arg)
516 struct qedf_ioreq *orig_io_req;
517 struct qedf_ioreq *srr_req;
518 struct qedf_mp_req *mp_req;
519 struct fc_frame_header *mp_fc_hdr, *fh;
521 void *resp_buf, *fc_payload;
523 struct fc_lport *lport;
524 struct qedf_ctx *qedf;
528 srr_req = cb_arg->io_req;
529 qedf = srr_req->fcport->qedf;
532 orig_io_req = cb_arg->aborted_io_req;
537 clear_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags);
539 if (srr_req->event != QEDF_IOREQ_EV_ELS_TMO &&
540 srr_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
541 cancel_delayed_work_sync(&orig_io_req->timeout_work);
543 refcount = kref_read(&orig_io_req->refcount);
544 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p,"
545 " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n",
546 orig_io_req, orig_io_req->xid, srr_req->xid, refcount);
548 /* If a SRR times out, simply free resources */
549 if (srr_req->event == QEDF_IOREQ_EV_ELS_TMO)
552 /* Normalize response data into struct fc_frame */
553 mp_req = &(srr_req->mp_req);
554 mp_fc_hdr = &(mp_req->resp_fc_hdr);
555 resp_len = mp_req->resp_len;
556 resp_buf = mp_req->resp_buf;
558 fp = fc_frame_alloc(lport, resp_len);
560 QEDF_ERR(&(qedf->dbg_ctx),
561 "fc_frame_alloc failure.\n");
565 /* Copy frame header from firmware into fp */
566 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
567 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
569 /* Copy payload from firmware into fp */
570 fc_payload = fc_frame_payload_get(fp, resp_len);
571 memcpy(fc_payload, resp_buf, resp_len);
573 opcode = fc_frame_payload_op(fp);
576 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
580 QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_ELS,
582 qedf_initiate_abts(orig_io_req, true);
588 /* Put reference for original command since SRR completed */
589 kref_put(&orig_io_req->refcount, qedf_release_cmd);
594 static int qedf_send_srr(struct qedf_ioreq *orig_io_req, u32 offset, u8 r_ctl)
597 struct qedf_ctx *qedf;
598 struct qedf_rport *fcport;
599 struct fc_lport *lport;
600 struct qedf_els_cb_arg *cb_arg = NULL;
605 QEDF_ERR(NULL, "orig_io_req is NULL.\n");
609 fcport = orig_io_req->fcport;
611 /* Check that fcport is still offloaded */
612 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
613 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
618 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
622 /* Take reference until SRR command completion */
623 kref_get(&orig_io_req->refcount);
628 r_a_tov = lport->r_a_tov;
630 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending SRR orig_io=%p, "
631 "orig_xid=0x%x\n", orig_io_req, orig_io_req->xid);
632 memset(&srr, 0, sizeof(srr));
634 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
636 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
642 cb_arg->aborted_io_req = orig_io_req;
644 srr.srr_op = ELS_SRR;
645 srr.srr_ox_id = htons(orig_io_req->xid);
646 srr.srr_rx_id = htons(orig_io_req->rx_id);
647 srr.srr_rel_off = htonl(offset);
648 srr.srr_r_ctl = r_ctl;
650 rc = qedf_initiate_els(fcport, ELS_SRR, &srr, sizeof(srr),
651 qedf_srr_compl, cb_arg, r_a_tov);
655 QEDF_ERR(&(qedf->dbg_ctx), "SRR failed - release orig_io_req"
656 "=0x%x\n", orig_io_req->xid);
658 /* If we fail to queue SRR, send ABTS to orig_io */
659 qedf_initiate_abts(orig_io_req, true);
660 kref_put(&orig_io_req->refcount, qedf_release_cmd);
662 /* Tell other threads that SRR is in progress */
663 set_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags);
668 static void qedf_initiate_seq_cleanup(struct qedf_ioreq *orig_io_req,
669 u32 offset, u8 r_ctl)
671 struct qedf_rport *fcport;
673 struct qedf_els_cb_arg *cb_arg;
674 struct fcoe_wqe *sqe;
677 fcport = orig_io_req->fcport;
679 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
680 "Doing sequence cleanup for xid=0x%x offset=%u.\n",
681 orig_io_req->xid, offset);
683 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
685 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to allocate cb_arg "
686 "for sequence cleanup\n");
690 /* Get reference for cleanup request */
691 kref_get(&orig_io_req->refcount);
693 orig_io_req->cmd_type = QEDF_SEQ_CLEANUP;
694 cb_arg->offset = offset;
695 cb_arg->r_ctl = r_ctl;
696 orig_io_req->cb_arg = cb_arg;
698 qedf_cmd_timer_set(fcport->qedf, orig_io_req,
699 QEDF_CLEANUP_TIMEOUT * HZ);
701 spin_lock_irqsave(&fcport->rport_lock, flags);
703 sqe_idx = qedf_get_sqe_idx(fcport);
704 sqe = &fcport->sq[sqe_idx];
705 memset(sqe, 0, sizeof(struct fcoe_wqe));
706 orig_io_req->task_params->sqe = sqe;
708 init_initiator_sequence_recovery_fcoe_task(orig_io_req->task_params,
710 qedf_ring_doorbell(fcport);
712 spin_unlock_irqrestore(&fcport->rport_lock, flags);
715 void qedf_process_seq_cleanup_compl(struct qedf_ctx *qedf,
716 struct fcoe_cqe *cqe, struct qedf_ioreq *io_req)
719 struct qedf_els_cb_arg *cb_arg;
721 cb_arg = io_req->cb_arg;
723 /* If we timed out just free resources */
724 if (io_req->event == QEDF_IOREQ_EV_ELS_TMO || !cqe)
727 /* Kill the timer we put on the request */
728 cancel_delayed_work_sync(&io_req->timeout_work);
730 rc = qedf_send_srr(io_req, cb_arg->offset, cb_arg->r_ctl);
732 QEDF_ERR(&(qedf->dbg_ctx), "Unable to send SRR, I/O will "
733 "abort, xid=0x%x.\n", io_req->xid);
736 kref_put(&io_req->refcount, qedf_release_cmd);
739 static bool qedf_requeue_io_req(struct qedf_ioreq *orig_io_req)
741 struct qedf_rport *fcport;
742 struct qedf_ioreq *new_io_req;
746 fcport = orig_io_req->fcport;
748 QEDF_ERR(NULL, "fcport is NULL.\n");
752 if (!orig_io_req->sc_cmd) {
753 QEDF_ERR(&(fcport->qedf->dbg_ctx), "sc_cmd is NULL for "
754 "xid=0x%x.\n", orig_io_req->xid);
758 new_io_req = qedf_alloc_cmd(fcport, QEDF_SCSI_CMD);
760 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Could not allocate new "
765 new_io_req->sc_cmd = orig_io_req->sc_cmd;
768 * This keeps the sc_cmd struct from being returned to the tape
769 * driver and being requeued twice. We do need to put a reference
770 * for the original I/O request since we will not do a SCSI completion
773 orig_io_req->sc_cmd = NULL;
774 kref_put(&orig_io_req->refcount, qedf_release_cmd);
776 spin_lock_irqsave(&fcport->rport_lock, flags);
778 /* kref for new command released in qedf_post_io_req on error */
779 if (qedf_post_io_req(fcport, new_io_req)) {
780 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to post io_req\n");
781 /* Return SQE to pool */
782 atomic_inc(&fcport->free_sqes);
784 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
785 "Reissued SCSI command from orig_xid=0x%x on "
786 "new_xid=0x%x.\n", orig_io_req->xid, new_io_req->xid);
788 * Abort the original I/O but do not return SCSI command as
789 * it has been reissued on another OX_ID.
791 spin_unlock_irqrestore(&fcport->rport_lock, flags);
792 qedf_initiate_abts(orig_io_req, false);
796 spin_unlock_irqrestore(&fcport->rport_lock, flags);
802 static void qedf_rec_compl(struct qedf_els_cb_arg *cb_arg)
804 struct qedf_ioreq *orig_io_req;
805 struct qedf_ioreq *rec_req;
806 struct qedf_mp_req *mp_req;
807 struct fc_frame_header *mp_fc_hdr, *fh;
809 void *resp_buf, *fc_payload;
811 struct fc_lport *lport;
812 struct qedf_ctx *qedf;
815 struct fc_els_ls_rjt *rjt;
816 struct fc_els_rec_acc *acc;
819 struct scsi_cmnd *sc_cmd;
820 bool srr_needed = false;
822 rec_req = cb_arg->io_req;
823 qedf = rec_req->fcport->qedf;
826 orig_io_req = cb_arg->aborted_io_req;
831 if (rec_req->event != QEDF_IOREQ_EV_ELS_TMO &&
832 rec_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
833 cancel_delayed_work_sync(&orig_io_req->timeout_work);
835 refcount = kref_read(&orig_io_req->refcount);
836 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p,"
837 " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n",
838 orig_io_req, orig_io_req->xid, rec_req->xid, refcount);
840 /* If a REC times out, free resources */
841 if (rec_req->event == QEDF_IOREQ_EV_ELS_TMO)
844 /* Normalize response data into struct fc_frame */
845 mp_req = &(rec_req->mp_req);
846 mp_fc_hdr = &(mp_req->resp_fc_hdr);
847 resp_len = mp_req->resp_len;
848 acc = resp_buf = mp_req->resp_buf;
850 fp = fc_frame_alloc(lport, resp_len);
852 QEDF_ERR(&(qedf->dbg_ctx),
853 "fc_frame_alloc failure.\n");
857 /* Copy frame header from firmware into fp */
858 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
859 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
861 /* Copy payload from firmware into fp */
862 fc_payload = fc_frame_payload_get(fp, resp_len);
863 memcpy(fc_payload, resp_buf, resp_len);
865 opcode = fc_frame_payload_op(fp);
866 if (opcode == ELS_LS_RJT) {
867 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
868 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
869 "Received LS_RJT for REC: er_reason=0x%x, "
870 "er_explan=0x%x.\n", rjt->er_reason, rjt->er_explan);
872 * The following response(s) mean that we need to reissue the
873 * request on another exchange. We need to do this without
874 * informing the upper layers lest it cause an application
877 if ((rjt->er_reason == ELS_RJT_LOGIC ||
878 rjt->er_reason == ELS_RJT_UNAB) &&
879 rjt->er_explan == ELS_EXPL_OXID_RXID) {
880 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
881 "Handle CMD LOST case.\n");
882 qedf_requeue_io_req(orig_io_req);
884 } else if (opcode == ELS_LS_ACC) {
885 offset = ntohl(acc->reca_fc4value);
886 e_stat = ntohl(acc->reca_e_stat);
887 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
888 "Received LS_ACC for REC: offset=0x%x, e_stat=0x%x.\n",
890 if (e_stat & ESB_ST_SEQ_INIT) {
891 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
892 "Target has the seq init\n");
895 sc_cmd = orig_io_req->sc_cmd;
897 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
898 "sc_cmd is NULL for xid=0x%x.\n",
902 /* SCSI write case */
903 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) {
904 if (offset == orig_io_req->data_xfer_len) {
905 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
906 "WRITE - response lost.\n");
907 r_ctl = FC_RCTL_DD_CMD_STATUS;
911 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
912 "WRITE - XFER_RDY/DATA lost.\n");
913 r_ctl = FC_RCTL_DD_DATA_DESC;
914 /* Use data from warning CQE instead of REC */
915 offset = orig_io_req->tx_buf_off;
919 if (orig_io_req->rx_buf_off ==
920 orig_io_req->data_xfer_len) {
921 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
922 "READ - response lost.\n");
924 r_ctl = FC_RCTL_DD_CMD_STATUS;
927 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
928 "READ - DATA lost.\n");
930 * For read case we always set the offset to 0
931 * for sequence recovery task.
934 r_ctl = FC_RCTL_DD_SOL_DATA;
939 qedf_send_srr(orig_io_req, offset, r_ctl);
941 qedf_initiate_seq_cleanup(orig_io_req, offset, r_ctl);
947 /* Put reference for original command since REC completed */
948 kref_put(&orig_io_req->refcount, qedf_release_cmd);
953 /* Assumes kref is already held by caller */
954 int qedf_send_rec(struct qedf_ioreq *orig_io_req)
957 struct fc_els_rec rec;
958 struct qedf_rport *fcport;
959 struct fc_lport *lport;
960 struct qedf_els_cb_arg *cb_arg = NULL;
961 struct qedf_ctx *qedf;
967 QEDF_ERR(NULL, "orig_io_req is NULL.\n");
971 fcport = orig_io_req->fcport;
973 /* Check that fcport is still offloaded */
974 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
975 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
980 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
984 /* Take reference until REC command completion */
985 kref_get(&orig_io_req->refcount);
990 r_a_tov = lport->r_a_tov;
992 memset(&rec, 0, sizeof(rec));
994 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
996 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
1002 cb_arg->aborted_io_req = orig_io_req;
1004 rec.rec_cmd = ELS_REC;
1005 hton24(rec.rec_s_id, sid);
1006 rec.rec_ox_id = htons(orig_io_req->xid);
1008 htons(orig_io_req->task->tstorm_st_context.read_write.rx_id);
1010 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending REC orig_io=%p, "
1011 "orig_xid=0x%x rx_id=0x%x\n", orig_io_req,
1012 orig_io_req->xid, rec.rec_rx_id);
1013 rc = qedf_initiate_els(fcport, ELS_REC, &rec, sizeof(rec),
1014 qedf_rec_compl, cb_arg, r_a_tov);
1018 QEDF_ERR(&(qedf->dbg_ctx), "REC failed - release orig_io_req"
1019 "=0x%x\n", orig_io_req->xid);
1021 kref_put(&orig_io_req->refcount, qedf_release_cmd);