2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016-2017 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 = fcport->qedf;
18 struct fc_lport *lport = qedf->lport;
19 struct qedf_ioreq *els_req;
20 struct qedf_mp_req *mp_req;
21 struct fc_frame_header *fc_hdr;
22 struct fcoe_task_context *task;
30 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending ELS\n");
32 rc = fc_remote_port_chkready(fcport->rport);
34 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: rport not ready\n", op);
38 if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
39 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: link is not ready\n",
45 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
46 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: fcport not ready\n", op);
51 els_req = qedf_alloc_cmd(fcport, QEDF_ELS);
53 QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_ELS,
54 "Failed to alloc ELS request 0x%x\n", op);
59 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "initiate_els els_req = "
60 "0x%p cb_arg = %p xid = %x\n", els_req, cb_arg,
62 els_req->sc_cmd = NULL;
63 els_req->cmd_type = QEDF_ELS;
64 els_req->fcport = fcport;
65 els_req->cb_func = cb_func;
66 cb_arg->io_req = els_req;
68 els_req->cb_arg = cb_arg;
69 els_req->data_xfer_len = data_len;
71 /* Record which cpu this request is associated with */
72 els_req->cpu = smp_processor_id();
74 mp_req = (struct qedf_mp_req *)&(els_req->mp_req);
75 rc = qedf_init_mp_req(els_req);
77 QEDF_ERR(&(qedf->dbg_ctx), "ELS MP request init failed\n");
78 kref_put(&els_req->refcount, qedf_release_cmd);
84 /* Fill ELS Payload */
85 if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS)) {
86 memcpy(mp_req->req_buf, data, data_len);
88 QEDF_ERR(&(qedf->dbg_ctx), "Invalid ELS op 0x%x\n", op);
89 els_req->cb_func = NULL;
90 els_req->cb_arg = NULL;
91 kref_put(&els_req->refcount, qedf_release_cmd);
99 fc_hdr = &(mp_req->req_fc_hdr);
101 did = fcport->rdata->ids.port_id;
104 __fc_fill_fc_hdr(fc_hdr, FC_RCTL_ELS_REQ, did, sid,
105 FC_TYPE_ELS, FC_FC_FIRST_SEQ | FC_FC_END_SEQ |
108 /* Obtain exchange id */
111 spin_lock_irqsave(&fcport->rport_lock, flags);
113 sqe_idx = qedf_get_sqe_idx(fcport);
114 sqe = &fcport->sq[sqe_idx];
115 memset(sqe, 0, sizeof(struct fcoe_wqe));
117 /* Initialize task context for this IO request */
118 task = qedf_get_task_mem(&qedf->tasks, xid);
119 qedf_init_mp_task(els_req, task, sqe);
121 /* Put timer on original I/O request */
123 qedf_cmd_timer_set(qedf, els_req, timer_msec);
126 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Ringing doorbell for ELS "
128 qedf_ring_doorbell(fcport);
129 spin_unlock_irqrestore(&fcport->rport_lock, flags);
134 void qedf_process_els_compl(struct qedf_ctx *qedf, struct fcoe_cqe *cqe,
135 struct qedf_ioreq *els_req)
137 struct fcoe_task_context *task_ctx;
138 struct scsi_cmnd *sc_cmd;
140 struct fcoe_cqe_midpath_info *mp_info;
142 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered with xid = 0x%x"
143 " cmd_type = %d.\n", els_req->xid, els_req->cmd_type);
145 /* Kill the ELS timer */
146 cancel_delayed_work(&els_req->timeout_work);
149 task_ctx = qedf_get_task_mem(&qedf->tasks, xid);
150 sc_cmd = els_req->sc_cmd;
152 /* Get ELS response length from CQE */
153 mp_info = &cqe->cqe_info.midpath_info;
154 els_req->mp_req.resp_len = mp_info->data_placement_size;
156 /* Parse ELS response */
157 if ((els_req->cb_func) && (els_req->cb_arg)) {
158 els_req->cb_func(els_req->cb_arg);
159 els_req->cb_arg = NULL;
162 kref_put(&els_req->refcount, qedf_release_cmd);
165 static void qedf_rrq_compl(struct qedf_els_cb_arg *cb_arg)
167 struct qedf_ioreq *orig_io_req;
168 struct qedf_ioreq *rrq_req;
169 struct qedf_ctx *qedf;
172 rrq_req = cb_arg->io_req;
173 qedf = rrq_req->fcport->qedf;
175 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered.\n");
177 orig_io_req = cb_arg->aborted_io_req;
182 if (rrq_req->event != QEDF_IOREQ_EV_ELS_TMO &&
183 rrq_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
184 cancel_delayed_work_sync(&orig_io_req->timeout_work);
186 refcount = kref_read(&orig_io_req->refcount);
187 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "rrq_compl: orig io = %p,"
188 " orig xid = 0x%x, rrq_xid = 0x%x, refcount=%d\n",
189 orig_io_req, orig_io_req->xid, rrq_req->xid, refcount);
191 /* This should return the aborted io_req to the command pool */
193 kref_put(&orig_io_req->refcount, qedf_release_cmd);
199 /* Assumes kref is already held by caller */
200 int qedf_send_rrq(struct qedf_ioreq *aborted_io_req)
203 struct fc_els_rrq rrq;
204 struct qedf_rport *fcport;
205 struct fc_lport *lport;
206 struct qedf_els_cb_arg *cb_arg = NULL;
207 struct qedf_ctx *qedf;
212 if (!aborted_io_req) {
213 QEDF_ERR(NULL, "abort_io_req is NULL.\n");
217 fcport = aborted_io_req->fcport;
219 /* Check that fcport is still offloaded */
220 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
221 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
226 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
233 r_a_tov = lport->r_a_tov;
235 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending RRQ orig "
236 "io = %p, orig_xid = 0x%x\n", aborted_io_req,
237 aborted_io_req->xid);
238 memset(&rrq, 0, sizeof(rrq));
240 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
242 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
248 cb_arg->aborted_io_req = aborted_io_req;
250 rrq.rrq_cmd = ELS_RRQ;
251 hton24(rrq.rrq_s_id, sid);
252 rrq.rrq_ox_id = htons(aborted_io_req->xid);
254 htons(aborted_io_req->task->tstorm_st_context.read_write.rx_id);
256 rc = qedf_initiate_els(fcport, ELS_RRQ, &rrq, sizeof(rrq),
257 qedf_rrq_compl, cb_arg, r_a_tov);
261 QEDF_ERR(&(qedf->dbg_ctx), "RRQ failed - release orig io "
262 "req 0x%x\n", aborted_io_req->xid);
264 kref_put(&aborted_io_req->refcount, qedf_release_cmd);
269 static void qedf_process_l2_frame_compl(struct qedf_rport *fcport,
273 struct fc_lport *lport = fcport->qedf->lport;
274 struct fc_frame_header *fh;
277 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
279 /* Set the OXID we return to what libfc used */
280 if (l2_oxid != FC_XID_UNKNOWN)
281 fh->fh_ox_id = htons(l2_oxid);
283 /* Setup header fields */
284 fh->fh_r_ctl = FC_RCTL_ELS_REP;
285 fh->fh_type = FC_TYPE_ELS;
286 /* Last sequence, end sequence */
287 fh->fh_f_ctl[0] = 0x98;
288 hton24(fh->fh_d_id, lport->port_id);
289 hton24(fh->fh_s_id, fcport->rdata->ids.port_id);
290 fh->fh_rx_id = 0xffff;
292 /* Set frame attributes */
293 crc = fcoe_fc_crc(fp);
296 fr_sof(fp) = FC_SOF_I3;
297 fr_eof(fp) = FC_EOF_T;
298 fr_crc(fp) = cpu_to_le32(~crc);
300 /* Send completed request to libfc */
301 fc_exch_recv(lport, fp);
305 * In instances where an ELS command times out we may need to restart the
306 * rport by logging out and then logging back in.
308 void qedf_restart_rport(struct qedf_rport *fcport)
310 struct fc_lport *lport;
311 struct fc_rport_priv *rdata;
317 rdata = fcport->rdata;
319 lport = fcport->qedf->lport;
320 port_id = rdata->ids.port_id;
321 QEDF_ERR(&(fcport->qedf->dbg_ctx),
322 "LOGO port_id=%x.\n", port_id);
323 fc_rport_logoff(rdata);
324 /* Recreate the rport and log back in */
325 rdata = fc_rport_create(lport, port_id);
327 fc_rport_login(rdata);
331 static void qedf_l2_els_compl(struct qedf_els_cb_arg *cb_arg)
333 struct qedf_ioreq *els_req;
334 struct qedf_rport *fcport;
335 struct qedf_mp_req *mp_req;
337 struct fc_frame_header *fh, *mp_fc_hdr;
338 void *resp_buf, *fc_payload;
342 l2_oxid = cb_arg->l2_oxid;
343 els_req = cb_arg->io_req;
346 QEDF_ERR(NULL, "els_req is NULL.\n");
351 * If we are flushing the command just free the cb_arg as none of the
352 * response data will be valid.
354 if (els_req->event == QEDF_IOREQ_EV_ELS_FLUSH)
357 fcport = els_req->fcport;
358 mp_req = &(els_req->mp_req);
359 mp_fc_hdr = &(mp_req->resp_fc_hdr);
360 resp_len = mp_req->resp_len;
361 resp_buf = mp_req->resp_buf;
364 * If a middle path ELS command times out, don't try to return
365 * the command but rather do any internal cleanup and then libfc
366 * timeout the command and clean up its internal resources.
368 if (els_req->event == QEDF_IOREQ_EV_ELS_TMO) {
370 * If ADISC times out, libfc will timeout the exchange and then
371 * try to send a PLOGI which will timeout since the session is
372 * still offloaded. Force libfc to logout the session which
373 * will offload the connection and allow the PLOGI response to
374 * flow over the LL2 path.
376 if (cb_arg->op == ELS_ADISC)
377 qedf_restart_rport(fcport);
381 if (sizeof(struct fc_frame_header) + resp_len > QEDF_PAGE_SIZE) {
382 QEDF_ERR(&(fcport->qedf->dbg_ctx), "resp_len is "
383 "beyond page size.\n");
387 fp = fc_frame_alloc(fcport->qedf->lport, resp_len);
389 QEDF_ERR(&(fcport->qedf->dbg_ctx),
390 "fc_frame_alloc failure.\n");
394 /* Copy frame header from firmware into fp */
395 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
396 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
398 /* Copy payload from firmware into fp */
399 fc_payload = fc_frame_payload_get(fp, resp_len);
400 memcpy(fc_payload, resp_buf, resp_len);
402 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
403 "Completing OX_ID 0x%x back to libfc.\n", l2_oxid);
404 qedf_process_l2_frame_compl(fcport, fp, l2_oxid);
410 int qedf_send_adisc(struct qedf_rport *fcport, struct fc_frame *fp)
412 struct fc_els_adisc *adisc;
413 struct fc_frame_header *fh;
414 struct fc_lport *lport = fcport->qedf->lport;
415 struct qedf_els_cb_arg *cb_arg = NULL;
416 struct qedf_ctx *qedf;
417 uint32_t r_a_tov = lport->r_a_tov;
421 fh = fc_frame_header_get(fp);
423 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
425 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
430 cb_arg->l2_oxid = ntohs(fh->fh_ox_id);
432 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
433 "Sending ADISC ox_id=0x%x.\n", cb_arg->l2_oxid);
435 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
437 rc = qedf_initiate_els(fcport, ELS_ADISC, adisc, sizeof(*adisc),
438 qedf_l2_els_compl, cb_arg, r_a_tov);
442 QEDF_ERR(&(qedf->dbg_ctx), "ADISC failed.\n");
448 static void qedf_srr_compl(struct qedf_els_cb_arg *cb_arg)
450 struct qedf_ioreq *orig_io_req;
451 struct qedf_ioreq *srr_req;
452 struct qedf_mp_req *mp_req;
453 struct fc_frame_header *mp_fc_hdr, *fh;
455 void *resp_buf, *fc_payload;
457 struct fc_lport *lport;
458 struct qedf_ctx *qedf;
462 srr_req = cb_arg->io_req;
463 qedf = srr_req->fcport->qedf;
466 orig_io_req = cb_arg->aborted_io_req;
471 clear_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags);
473 if (srr_req->event != QEDF_IOREQ_EV_ELS_TMO &&
474 srr_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
475 cancel_delayed_work_sync(&orig_io_req->timeout_work);
477 refcount = kref_read(&orig_io_req->refcount);
478 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p,"
479 " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n",
480 orig_io_req, orig_io_req->xid, srr_req->xid, refcount);
482 /* If a SRR times out, simply free resources */
483 if (srr_req->event == QEDF_IOREQ_EV_ELS_TMO)
486 /* Normalize response data into struct fc_frame */
487 mp_req = &(srr_req->mp_req);
488 mp_fc_hdr = &(mp_req->resp_fc_hdr);
489 resp_len = mp_req->resp_len;
490 resp_buf = mp_req->resp_buf;
492 fp = fc_frame_alloc(lport, resp_len);
494 QEDF_ERR(&(qedf->dbg_ctx),
495 "fc_frame_alloc failure.\n");
499 /* Copy frame header from firmware into fp */
500 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
501 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
503 /* Copy payload from firmware into fp */
504 fc_payload = fc_frame_payload_get(fp, resp_len);
505 memcpy(fc_payload, resp_buf, resp_len);
507 opcode = fc_frame_payload_op(fp);
510 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
514 QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_ELS,
516 qedf_initiate_abts(orig_io_req, true);
522 /* Put reference for original command since SRR completed */
523 kref_put(&orig_io_req->refcount, qedf_release_cmd);
528 static int qedf_send_srr(struct qedf_ioreq *orig_io_req, u32 offset, u8 r_ctl)
531 struct qedf_ctx *qedf;
532 struct qedf_rport *fcport;
533 struct fc_lport *lport;
534 struct qedf_els_cb_arg *cb_arg = NULL;
539 QEDF_ERR(NULL, "orig_io_req is NULL.\n");
543 fcport = orig_io_req->fcport;
545 /* Check that fcport is still offloaded */
546 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
547 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
552 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
556 /* Take reference until SRR command completion */
557 kref_get(&orig_io_req->refcount);
562 r_a_tov = lport->r_a_tov;
564 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending SRR orig_io=%p, "
565 "orig_xid=0x%x\n", orig_io_req, orig_io_req->xid);
566 memset(&srr, 0, sizeof(srr));
568 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
570 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
576 cb_arg->aborted_io_req = orig_io_req;
578 srr.srr_op = ELS_SRR;
579 srr.srr_ox_id = htons(orig_io_req->xid);
580 srr.srr_rx_id = htons(orig_io_req->rx_id);
581 srr.srr_rel_off = htonl(offset);
582 srr.srr_r_ctl = r_ctl;
584 rc = qedf_initiate_els(fcport, ELS_SRR, &srr, sizeof(srr),
585 qedf_srr_compl, cb_arg, r_a_tov);
589 QEDF_ERR(&(qedf->dbg_ctx), "SRR failed - release orig_io_req"
590 "=0x%x\n", orig_io_req->xid);
592 /* If we fail to queue SRR, send ABTS to orig_io */
593 qedf_initiate_abts(orig_io_req, true);
594 kref_put(&orig_io_req->refcount, qedf_release_cmd);
596 /* Tell other threads that SRR is in progress */
597 set_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags);
602 static void qedf_initiate_seq_cleanup(struct qedf_ioreq *orig_io_req,
603 u32 offset, u8 r_ctl)
605 struct qedf_rport *fcport;
607 struct qedf_els_cb_arg *cb_arg;
608 struct fcoe_wqe *sqe;
611 fcport = orig_io_req->fcport;
613 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
614 "Doing sequence cleanup for xid=0x%x offset=%u.\n",
615 orig_io_req->xid, offset);
617 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
619 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to allocate cb_arg "
620 "for sequence cleanup\n");
624 /* Get reference for cleanup request */
625 kref_get(&orig_io_req->refcount);
627 orig_io_req->cmd_type = QEDF_SEQ_CLEANUP;
628 cb_arg->offset = offset;
629 cb_arg->r_ctl = r_ctl;
630 orig_io_req->cb_arg = cb_arg;
632 qedf_cmd_timer_set(fcport->qedf, orig_io_req,
633 QEDF_CLEANUP_TIMEOUT * HZ);
635 spin_lock_irqsave(&fcport->rport_lock, flags);
637 sqe_idx = qedf_get_sqe_idx(fcport);
638 sqe = &fcport->sq[sqe_idx];
639 memset(sqe, 0, sizeof(struct fcoe_wqe));
640 orig_io_req->task_params->sqe = sqe;
642 init_initiator_sequence_recovery_fcoe_task(orig_io_req->task_params,
644 qedf_ring_doorbell(fcport);
646 spin_unlock_irqrestore(&fcport->rport_lock, flags);
649 void qedf_process_seq_cleanup_compl(struct qedf_ctx *qedf,
650 struct fcoe_cqe *cqe, struct qedf_ioreq *io_req)
653 struct qedf_els_cb_arg *cb_arg;
655 cb_arg = io_req->cb_arg;
657 /* If we timed out just free resources */
658 if (io_req->event == QEDF_IOREQ_EV_ELS_TMO || !cqe)
661 /* Kill the timer we put on the request */
662 cancel_delayed_work_sync(&io_req->timeout_work);
664 rc = qedf_send_srr(io_req, cb_arg->offset, cb_arg->r_ctl);
666 QEDF_ERR(&(qedf->dbg_ctx), "Unable to send SRR, I/O will "
667 "abort, xid=0x%x.\n", io_req->xid);
670 kref_put(&io_req->refcount, qedf_release_cmd);
673 static bool qedf_requeue_io_req(struct qedf_ioreq *orig_io_req)
675 struct qedf_rport *fcport;
676 struct qedf_ioreq *new_io_req;
680 fcport = orig_io_req->fcport;
682 QEDF_ERR(NULL, "fcport is NULL.\n");
686 if (!orig_io_req->sc_cmd) {
687 QEDF_ERR(&(fcport->qedf->dbg_ctx), "sc_cmd is NULL for "
688 "xid=0x%x.\n", orig_io_req->xid);
692 new_io_req = qedf_alloc_cmd(fcport, QEDF_SCSI_CMD);
694 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Could not allocate new "
699 new_io_req->sc_cmd = orig_io_req->sc_cmd;
702 * This keeps the sc_cmd struct from being returned to the tape
703 * driver and being requeued twice. We do need to put a reference
704 * for the original I/O request since we will not do a SCSI completion
707 orig_io_req->sc_cmd = NULL;
708 kref_put(&orig_io_req->refcount, qedf_release_cmd);
710 spin_lock_irqsave(&fcport->rport_lock, flags);
712 /* kref for new command released in qedf_post_io_req on error */
713 if (qedf_post_io_req(fcport, new_io_req)) {
714 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to post io_req\n");
715 /* Return SQE to pool */
716 atomic_inc(&fcport->free_sqes);
718 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
719 "Reissued SCSI command from orig_xid=0x%x on "
720 "new_xid=0x%x.\n", orig_io_req->xid, new_io_req->xid);
722 * Abort the original I/O but do not return SCSI command as
723 * it has been reissued on another OX_ID.
725 spin_unlock_irqrestore(&fcport->rport_lock, flags);
726 qedf_initiate_abts(orig_io_req, false);
730 spin_unlock_irqrestore(&fcport->rport_lock, flags);
736 static void qedf_rec_compl(struct qedf_els_cb_arg *cb_arg)
738 struct qedf_ioreq *orig_io_req;
739 struct qedf_ioreq *rec_req;
740 struct qedf_mp_req *mp_req;
741 struct fc_frame_header *mp_fc_hdr, *fh;
743 void *resp_buf, *fc_payload;
745 struct fc_lport *lport;
746 struct qedf_ctx *qedf;
749 struct fc_els_ls_rjt *rjt;
750 struct fc_els_rec_acc *acc;
753 struct scsi_cmnd *sc_cmd;
754 bool srr_needed = false;
756 rec_req = cb_arg->io_req;
757 qedf = rec_req->fcport->qedf;
760 orig_io_req = cb_arg->aborted_io_req;
765 if (rec_req->event != QEDF_IOREQ_EV_ELS_TMO &&
766 rec_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
767 cancel_delayed_work_sync(&orig_io_req->timeout_work);
769 refcount = kref_read(&orig_io_req->refcount);
770 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p,"
771 " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n",
772 orig_io_req, orig_io_req->xid, rec_req->xid, refcount);
774 /* If a REC times out, free resources */
775 if (rec_req->event == QEDF_IOREQ_EV_ELS_TMO)
778 /* Normalize response data into struct fc_frame */
779 mp_req = &(rec_req->mp_req);
780 mp_fc_hdr = &(mp_req->resp_fc_hdr);
781 resp_len = mp_req->resp_len;
782 acc = resp_buf = mp_req->resp_buf;
784 fp = fc_frame_alloc(lport, resp_len);
786 QEDF_ERR(&(qedf->dbg_ctx),
787 "fc_frame_alloc failure.\n");
791 /* Copy frame header from firmware into fp */
792 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
793 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
795 /* Copy payload from firmware into fp */
796 fc_payload = fc_frame_payload_get(fp, resp_len);
797 memcpy(fc_payload, resp_buf, resp_len);
799 opcode = fc_frame_payload_op(fp);
800 if (opcode == ELS_LS_RJT) {
801 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
802 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
803 "Received LS_RJT for REC: er_reason=0x%x, "
804 "er_explan=0x%x.\n", rjt->er_reason, rjt->er_explan);
806 * The following response(s) mean that we need to reissue the
807 * request on another exchange. We need to do this without
808 * informing the upper layers lest it cause an application
811 if ((rjt->er_reason == ELS_RJT_LOGIC ||
812 rjt->er_reason == ELS_RJT_UNAB) &&
813 rjt->er_explan == ELS_EXPL_OXID_RXID) {
814 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
815 "Handle CMD LOST case.\n");
816 qedf_requeue_io_req(orig_io_req);
818 } else if (opcode == ELS_LS_ACC) {
819 offset = ntohl(acc->reca_fc4value);
820 e_stat = ntohl(acc->reca_e_stat);
821 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
822 "Received LS_ACC for REC: offset=0x%x, e_stat=0x%x.\n",
824 if (e_stat & ESB_ST_SEQ_INIT) {
825 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
826 "Target has the seq init\n");
829 sc_cmd = orig_io_req->sc_cmd;
831 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
832 "sc_cmd is NULL for xid=0x%x.\n",
836 /* SCSI write case */
837 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) {
838 if (offset == orig_io_req->data_xfer_len) {
839 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
840 "WRITE - response lost.\n");
841 r_ctl = FC_RCTL_DD_CMD_STATUS;
845 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
846 "WRITE - XFER_RDY/DATA lost.\n");
847 r_ctl = FC_RCTL_DD_DATA_DESC;
848 /* Use data from warning CQE instead of REC */
849 offset = orig_io_req->tx_buf_off;
853 if (orig_io_req->rx_buf_off ==
854 orig_io_req->data_xfer_len) {
855 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
856 "READ - response lost.\n");
858 r_ctl = FC_RCTL_DD_CMD_STATUS;
861 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
862 "READ - DATA lost.\n");
864 * For read case we always set the offset to 0
865 * for sequence recovery task.
868 r_ctl = FC_RCTL_DD_SOL_DATA;
873 qedf_send_srr(orig_io_req, offset, r_ctl);
875 qedf_initiate_seq_cleanup(orig_io_req, offset, r_ctl);
881 /* Put reference for original command since REC completed */
882 kref_put(&orig_io_req->refcount, qedf_release_cmd);
887 /* Assumes kref is already held by caller */
888 int qedf_send_rec(struct qedf_ioreq *orig_io_req)
891 struct fc_els_rec rec;
892 struct qedf_rport *fcport;
893 struct fc_lport *lport;
894 struct qedf_els_cb_arg *cb_arg = NULL;
895 struct qedf_ctx *qedf;
901 QEDF_ERR(NULL, "orig_io_req is NULL.\n");
905 fcport = orig_io_req->fcport;
907 /* Check that fcport is still offloaded */
908 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
909 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
914 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
918 /* Take reference until REC command completion */
919 kref_get(&orig_io_req->refcount);
924 r_a_tov = lport->r_a_tov;
926 memset(&rec, 0, sizeof(rec));
928 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
930 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
936 cb_arg->aborted_io_req = orig_io_req;
938 rec.rec_cmd = ELS_REC;
939 hton24(rec.rec_s_id, sid);
940 rec.rec_ox_id = htons(orig_io_req->xid);
942 htons(orig_io_req->task->tstorm_st_context.read_write.rx_id);
944 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending REC orig_io=%p, "
945 "orig_xid=0x%x rx_id=0x%x\n", orig_io_req,
946 orig_io_req->xid, rec.rec_rx_id);
947 rc = qedf_initiate_els(fcport, ELS_REC, &rec, sizeof(rec),
948 qedf_rec_compl, cb_arg, r_a_tov);
952 QEDF_ERR(&(qedf->dbg_ctx), "REC failed - release orig_io_req"
953 "=0x%x\n", orig_io_req->xid);
955 kref_put(&orig_io_req->refcount, qedf_release_cmd);