2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016 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;
26 uint32_t start_time = jiffies / HZ;
27 uint32_t current_time;
29 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending ELS\n");
31 rc = fc_remote_port_chkready(fcport->rport);
33 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: rport not ready\n", op);
37 if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
38 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: link is not ready\n",
44 if (!(test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags))) {
45 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: fcport not ready\n", op);
51 els_req = qedf_alloc_cmd(fcport, QEDF_ELS);
53 current_time = jiffies / HZ;
54 if ((current_time - start_time) > 10) {
55 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
56 "els: Failed els 0x%x\n", op);
60 mdelay(20 * USEC_PER_MSEC);
64 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "initiate_els els_req = "
65 "0x%p cb_arg = %p xid = %x\n", els_req, cb_arg,
67 els_req->sc_cmd = NULL;
68 els_req->cmd_type = QEDF_ELS;
69 els_req->fcport = fcport;
70 els_req->cb_func = cb_func;
71 cb_arg->io_req = els_req;
73 els_req->cb_arg = cb_arg;
74 els_req->data_xfer_len = data_len;
76 /* Record which cpu this request is associated with */
77 els_req->cpu = smp_processor_id();
79 mp_req = (struct qedf_mp_req *)&(els_req->mp_req);
80 rc = qedf_init_mp_req(els_req);
82 QEDF_ERR(&(qedf->dbg_ctx), "ELS MP request init failed\n");
83 kref_put(&els_req->refcount, qedf_release_cmd);
89 /* Fill ELS Payload */
90 if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS)) {
91 memcpy(mp_req->req_buf, data, data_len);
93 QEDF_ERR(&(qedf->dbg_ctx), "Invalid ELS op 0x%x\n", op);
94 els_req->cb_func = NULL;
95 els_req->cb_arg = NULL;
96 kref_put(&els_req->refcount, qedf_release_cmd);
104 fc_hdr = &(mp_req->req_fc_hdr);
106 did = fcport->rdata->ids.port_id;
109 __fc_fill_fc_hdr(fc_hdr, FC_RCTL_ELS_REQ, sid, did,
110 FC_TYPE_ELS, FC_FC_FIRST_SEQ | FC_FC_END_SEQ |
113 /* Obtain exchange id */
116 /* Initialize task context for this IO request */
117 task = qedf_get_task_mem(&qedf->tasks, xid);
118 qedf_init_mp_task(els_req, task);
120 /* Put timer on original I/O request */
122 qedf_cmd_timer_set(qedf, els_req, timer_msec);
124 qedf_add_to_sq(fcport, xid, 0, FCOE_TASK_TYPE_MIDPATH, 0);
127 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Ringing doorbell for ELS "
129 qedf_ring_doorbell(fcport);
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);
527 static int qedf_send_srr(struct qedf_ioreq *orig_io_req, u32 offset, u8 r_ctl)
530 struct qedf_ctx *qedf;
531 struct qedf_rport *fcport;
532 struct fc_lport *lport;
533 struct qedf_els_cb_arg *cb_arg = NULL;
538 QEDF_ERR(NULL, "orig_io_req is NULL.\n");
542 fcport = orig_io_req->fcport;
544 /* Check that fcport is still offloaded */
545 if (!(test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags))) {
546 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
551 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
555 /* Take reference until SRR command completion */
556 kref_get(&orig_io_req->refcount);
561 r_a_tov = lport->r_a_tov;
563 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending SRR orig_io=%p, "
564 "orig_xid=0x%x\n", orig_io_req, orig_io_req->xid);
565 memset(&srr, 0, sizeof(srr));
567 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
569 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
575 cb_arg->aborted_io_req = orig_io_req;
577 srr.srr_op = ELS_SRR;
578 srr.srr_ox_id = htons(orig_io_req->xid);
579 srr.srr_rx_id = htons(orig_io_req->rx_id);
580 srr.srr_rel_off = htonl(offset);
581 srr.srr_r_ctl = r_ctl;
583 rc = qedf_initiate_els(fcport, ELS_SRR, &srr, sizeof(srr),
584 qedf_srr_compl, cb_arg, r_a_tov);
588 QEDF_ERR(&(qedf->dbg_ctx), "SRR failed - release orig_io_req"
589 "=0x%x\n", orig_io_req->xid);
591 /* If we fail to queue SRR, send ABTS to orig_io */
592 qedf_initiate_abts(orig_io_req, true);
593 kref_put(&orig_io_req->refcount, qedf_release_cmd);
595 /* Tell other threads that SRR is in progress */
596 set_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags);
601 static void qedf_initiate_seq_cleanup(struct qedf_ioreq *orig_io_req,
602 u32 offset, u8 r_ctl)
604 struct qedf_rport *fcport;
606 struct qedf_els_cb_arg *cb_arg;
608 fcport = orig_io_req->fcport;
610 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
611 "Doing sequence cleanup for xid=0x%x offset=%u.\n",
612 orig_io_req->xid, offset);
614 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
616 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to allocate cb_arg "
617 "for sequence cleanup\n");
621 /* Get reference for cleanup request */
622 kref_get(&orig_io_req->refcount);
624 orig_io_req->cmd_type = QEDF_SEQ_CLEANUP;
625 cb_arg->offset = offset;
626 cb_arg->r_ctl = r_ctl;
627 orig_io_req->cb_arg = cb_arg;
629 qedf_cmd_timer_set(fcport->qedf, orig_io_req,
630 QEDF_CLEANUP_TIMEOUT * HZ);
632 spin_lock_irqsave(&fcport->rport_lock, flags);
634 qedf_add_to_sq(fcport, orig_io_req->xid, 0,
635 FCOE_TASK_TYPE_SEQUENCE_CLEANUP, offset);
636 qedf_ring_doorbell(fcport);
638 spin_unlock_irqrestore(&fcport->rport_lock, flags);
641 void qedf_process_seq_cleanup_compl(struct qedf_ctx *qedf,
642 struct fcoe_cqe *cqe, struct qedf_ioreq *io_req)
645 struct qedf_els_cb_arg *cb_arg;
647 cb_arg = io_req->cb_arg;
649 /* If we timed out just free resources */
650 if (io_req->event == QEDF_IOREQ_EV_ELS_TMO || !cqe)
653 /* Kill the timer we put on the request */
654 cancel_delayed_work_sync(&io_req->timeout_work);
656 rc = qedf_send_srr(io_req, cb_arg->offset, cb_arg->r_ctl);
658 QEDF_ERR(&(qedf->dbg_ctx), "Unable to send SRR, I/O will "
659 "abort, xid=0x%x.\n", io_req->xid);
662 kref_put(&io_req->refcount, qedf_release_cmd);
665 static bool qedf_requeue_io_req(struct qedf_ioreq *orig_io_req)
667 struct qedf_rport *fcport;
668 struct qedf_ioreq *new_io_req;
672 fcport = orig_io_req->fcport;
674 QEDF_ERR(NULL, "fcport is NULL.\n");
678 if (!orig_io_req->sc_cmd) {
679 QEDF_ERR(&(fcport->qedf->dbg_ctx), "sc_cmd is NULL for "
680 "xid=0x%x.\n", orig_io_req->xid);
684 new_io_req = qedf_alloc_cmd(fcport, QEDF_SCSI_CMD);
686 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Could not allocate new "
691 new_io_req->sc_cmd = orig_io_req->sc_cmd;
694 * This keeps the sc_cmd struct from being returned to the tape
695 * driver and being requeued twice. We do need to put a reference
696 * for the original I/O request since we will not do a SCSI completion
699 orig_io_req->sc_cmd = NULL;
700 kref_put(&orig_io_req->refcount, qedf_release_cmd);
702 spin_lock_irqsave(&fcport->rport_lock, flags);
704 /* kref for new command released in qedf_post_io_req on error */
705 if (qedf_post_io_req(fcport, new_io_req)) {
706 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to post io_req\n");
707 /* Return SQE to pool */
708 atomic_inc(&fcport->free_sqes);
710 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
711 "Reissued SCSI command from orig_xid=0x%x on "
712 "new_xid=0x%x.\n", orig_io_req->xid, new_io_req->xid);
714 * Abort the original I/O but do not return SCSI command as
715 * it has been reissued on another OX_ID.
717 spin_unlock_irqrestore(&fcport->rport_lock, flags);
718 qedf_initiate_abts(orig_io_req, false);
722 spin_unlock_irqrestore(&fcport->rport_lock, flags);
728 static void qedf_rec_compl(struct qedf_els_cb_arg *cb_arg)
730 struct qedf_ioreq *orig_io_req;
731 struct qedf_ioreq *rec_req;
732 struct qedf_mp_req *mp_req;
733 struct fc_frame_header *mp_fc_hdr, *fh;
735 void *resp_buf, *fc_payload;
737 struct fc_lport *lport;
738 struct qedf_ctx *qedf;
741 struct fc_els_ls_rjt *rjt;
742 struct fc_els_rec_acc *acc;
745 struct scsi_cmnd *sc_cmd;
746 bool srr_needed = false;
748 rec_req = cb_arg->io_req;
749 qedf = rec_req->fcport->qedf;
752 orig_io_req = cb_arg->aborted_io_req;
757 if (rec_req->event != QEDF_IOREQ_EV_ELS_TMO &&
758 rec_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
759 cancel_delayed_work_sync(&orig_io_req->timeout_work);
761 refcount = kref_read(&orig_io_req->refcount);
762 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p,"
763 " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n",
764 orig_io_req, orig_io_req->xid, rec_req->xid, refcount);
766 /* If a REC times out, free resources */
767 if (rec_req->event == QEDF_IOREQ_EV_ELS_TMO)
770 /* Normalize response data into struct fc_frame */
771 mp_req = &(rec_req->mp_req);
772 mp_fc_hdr = &(mp_req->resp_fc_hdr);
773 resp_len = mp_req->resp_len;
774 acc = resp_buf = mp_req->resp_buf;
776 fp = fc_frame_alloc(lport, resp_len);
778 QEDF_ERR(&(qedf->dbg_ctx),
779 "fc_frame_alloc failure.\n");
783 /* Copy frame header from firmware into fp */
784 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
785 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
787 /* Copy payload from firmware into fp */
788 fc_payload = fc_frame_payload_get(fp, resp_len);
789 memcpy(fc_payload, resp_buf, resp_len);
791 opcode = fc_frame_payload_op(fp);
792 if (opcode == ELS_LS_RJT) {
793 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
794 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
795 "Received LS_RJT for REC: er_reason=0x%x, "
796 "er_explan=0x%x.\n", rjt->er_reason, rjt->er_explan);
798 * The following response(s) mean that we need to reissue the
799 * request on another exchange. We need to do this without
800 * informing the upper layers lest it cause an application
803 if ((rjt->er_reason == ELS_RJT_LOGIC ||
804 rjt->er_reason == ELS_RJT_UNAB) &&
805 rjt->er_explan == ELS_EXPL_OXID_RXID) {
806 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
807 "Handle CMD LOST case.\n");
808 qedf_requeue_io_req(orig_io_req);
810 } else if (opcode == ELS_LS_ACC) {
811 offset = ntohl(acc->reca_fc4value);
812 e_stat = ntohl(acc->reca_e_stat);
813 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
814 "Received LS_ACC for REC: offset=0x%x, e_stat=0x%x.\n",
816 if (e_stat & ESB_ST_SEQ_INIT) {
817 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
818 "Target has the seq init\n");
821 sc_cmd = orig_io_req->sc_cmd;
823 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
824 "sc_cmd is NULL for xid=0x%x.\n",
828 /* SCSI write case */
829 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) {
830 if (offset == orig_io_req->data_xfer_len) {
831 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
832 "WRITE - response lost.\n");
833 r_ctl = FC_RCTL_DD_CMD_STATUS;
837 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
838 "WRITE - XFER_RDY/DATA lost.\n");
839 r_ctl = FC_RCTL_DD_DATA_DESC;
840 /* Use data from warning CQE instead of REC */
841 offset = orig_io_req->tx_buf_off;
845 if (orig_io_req->rx_buf_off ==
846 orig_io_req->data_xfer_len) {
847 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
848 "READ - response lost.\n");
850 r_ctl = FC_RCTL_DD_CMD_STATUS;
853 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
854 "READ - DATA lost.\n");
856 * For read case we always set the offset to 0
857 * for sequence recovery task.
860 r_ctl = FC_RCTL_DD_SOL_DATA;
865 qedf_send_srr(orig_io_req, offset, r_ctl);
867 qedf_initiate_seq_cleanup(orig_io_req, offset, r_ctl);
873 /* Put reference for original command since REC completed */
874 kref_put(&orig_io_req->refcount, qedf_release_cmd);
878 /* Assumes kref is already held by caller */
879 int qedf_send_rec(struct qedf_ioreq *orig_io_req)
882 struct fc_els_rec rec;
883 struct qedf_rport *fcport;
884 struct fc_lport *lport;
885 struct qedf_els_cb_arg *cb_arg = NULL;
886 struct qedf_ctx *qedf;
892 QEDF_ERR(NULL, "orig_io_req is NULL.\n");
896 fcport = orig_io_req->fcport;
898 /* Check that fcport is still offloaded */
899 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
900 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
905 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
909 /* Take reference until REC command completion */
910 kref_get(&orig_io_req->refcount);
915 r_a_tov = lport->r_a_tov;
917 memset(&rec, 0, sizeof(rec));
919 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
921 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
927 cb_arg->aborted_io_req = orig_io_req;
929 rec.rec_cmd = ELS_REC;
930 hton24(rec.rec_s_id, sid);
931 rec.rec_ox_id = htons(orig_io_req->xid);
933 htons(orig_io_req->task->tstorm_st_context.read_write.rx_id);
935 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending REC orig_io=%p, "
936 "orig_xid=0x%x rx_id=0x%x\n", orig_io_req,
937 orig_io_req->xid, rec.rec_rx_id);
938 rc = qedf_initiate_els(fcport, ELS_REC, &rec, sizeof(rec),
939 qedf_rec_compl, cb_arg, r_a_tov);
943 QEDF_ERR(&(qedf->dbg_ctx), "REC failed - release orig_io_req"
944 "=0x%x\n", orig_io_req->xid);
946 kref_put(&orig_io_req->refcount, qedf_release_cmd);