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;
32 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending ELS\n");
34 rc = fc_remote_port_chkready(fcport->rport);
36 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: rport not ready\n", op);
40 if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
41 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: link is not ready\n",
47 if (!(test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags))) {
48 QEDF_ERR(&(qedf->dbg_ctx), "els 0x%x: fcport not ready\n", op);
54 els_req = qedf_alloc_cmd(fcport, QEDF_ELS);
56 current_time = jiffies / HZ;
57 if ((current_time - start_time) > 10) {
58 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
59 "els: Failed els 0x%x\n", op);
63 mdelay(20 * USEC_PER_MSEC);
67 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "initiate_els els_req = "
68 "0x%p cb_arg = %p xid = %x\n", els_req, cb_arg,
70 els_req->sc_cmd = NULL;
71 els_req->cmd_type = QEDF_ELS;
72 els_req->fcport = fcport;
73 els_req->cb_func = cb_func;
74 cb_arg->io_req = els_req;
76 els_req->cb_arg = cb_arg;
77 els_req->data_xfer_len = data_len;
79 /* Record which cpu this request is associated with */
80 els_req->cpu = smp_processor_id();
82 mp_req = (struct qedf_mp_req *)&(els_req->mp_req);
83 rc = qedf_init_mp_req(els_req);
85 QEDF_ERR(&(qedf->dbg_ctx), "ELS MP request init failed\n");
86 kref_put(&els_req->refcount, qedf_release_cmd);
92 /* Fill ELS Payload */
93 if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS)) {
94 memcpy(mp_req->req_buf, data, data_len);
96 QEDF_ERR(&(qedf->dbg_ctx), "Invalid ELS op 0x%x\n", op);
97 els_req->cb_func = NULL;
98 els_req->cb_arg = NULL;
99 kref_put(&els_req->refcount, qedf_release_cmd);
107 fc_hdr = &(mp_req->req_fc_hdr);
109 did = fcport->rdata->ids.port_id;
112 __fc_fill_fc_hdr(fc_hdr, FC_RCTL_ELS_REQ, did, sid,
113 FC_TYPE_ELS, FC_FC_FIRST_SEQ | FC_FC_END_SEQ |
116 /* Obtain exchange id */
119 spin_lock_irqsave(&fcport->rport_lock, flags);
121 sqe_idx = qedf_get_sqe_idx(fcport);
122 sqe = &fcport->sq[sqe_idx];
123 memset(sqe, 0, sizeof(struct fcoe_wqe));
125 /* Initialize task context for this IO request */
126 task = qedf_get_task_mem(&qedf->tasks, xid);
127 qedf_init_mp_task(els_req, task, sqe);
129 /* Put timer on original I/O request */
131 qedf_cmd_timer_set(qedf, els_req, timer_msec);
134 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Ringing doorbell for ELS "
136 qedf_ring_doorbell(fcport);
137 spin_unlock_irqrestore(&fcport->rport_lock, flags);
142 void qedf_process_els_compl(struct qedf_ctx *qedf, struct fcoe_cqe *cqe,
143 struct qedf_ioreq *els_req)
145 struct fcoe_task_context *task_ctx;
146 struct scsi_cmnd *sc_cmd;
148 struct fcoe_cqe_midpath_info *mp_info;
150 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered with xid = 0x%x"
151 " cmd_type = %d.\n", els_req->xid, els_req->cmd_type);
153 /* Kill the ELS timer */
154 cancel_delayed_work(&els_req->timeout_work);
157 task_ctx = qedf_get_task_mem(&qedf->tasks, xid);
158 sc_cmd = els_req->sc_cmd;
160 /* Get ELS response length from CQE */
161 mp_info = &cqe->cqe_info.midpath_info;
162 els_req->mp_req.resp_len = mp_info->data_placement_size;
164 /* Parse ELS response */
165 if ((els_req->cb_func) && (els_req->cb_arg)) {
166 els_req->cb_func(els_req->cb_arg);
167 els_req->cb_arg = NULL;
170 kref_put(&els_req->refcount, qedf_release_cmd);
173 static void qedf_rrq_compl(struct qedf_els_cb_arg *cb_arg)
175 struct qedf_ioreq *orig_io_req;
176 struct qedf_ioreq *rrq_req;
177 struct qedf_ctx *qedf;
180 rrq_req = cb_arg->io_req;
181 qedf = rrq_req->fcport->qedf;
183 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered.\n");
185 orig_io_req = cb_arg->aborted_io_req;
190 if (rrq_req->event != QEDF_IOREQ_EV_ELS_TMO &&
191 rrq_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
192 cancel_delayed_work_sync(&orig_io_req->timeout_work);
194 refcount = kref_read(&orig_io_req->refcount);
195 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "rrq_compl: orig io = %p,"
196 " orig xid = 0x%x, rrq_xid = 0x%x, refcount=%d\n",
197 orig_io_req, orig_io_req->xid, rrq_req->xid, refcount);
199 /* This should return the aborted io_req to the command pool */
201 kref_put(&orig_io_req->refcount, qedf_release_cmd);
207 /* Assumes kref is already held by caller */
208 int qedf_send_rrq(struct qedf_ioreq *aborted_io_req)
211 struct fc_els_rrq rrq;
212 struct qedf_rport *fcport;
213 struct fc_lport *lport;
214 struct qedf_els_cb_arg *cb_arg = NULL;
215 struct qedf_ctx *qedf;
220 if (!aborted_io_req) {
221 QEDF_ERR(NULL, "abort_io_req is NULL.\n");
225 fcport = aborted_io_req->fcport;
227 /* Check that fcport is still offloaded */
228 if (!(test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags))) {
229 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
234 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
241 r_a_tov = lport->r_a_tov;
243 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending RRQ orig "
244 "io = %p, orig_xid = 0x%x\n", aborted_io_req,
245 aborted_io_req->xid);
246 memset(&rrq, 0, sizeof(rrq));
248 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
250 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
256 cb_arg->aborted_io_req = aborted_io_req;
258 rrq.rrq_cmd = ELS_RRQ;
259 hton24(rrq.rrq_s_id, sid);
260 rrq.rrq_ox_id = htons(aborted_io_req->xid);
262 htons(aborted_io_req->task->tstorm_st_context.read_write.rx_id);
264 rc = qedf_initiate_els(fcport, ELS_RRQ, &rrq, sizeof(rrq),
265 qedf_rrq_compl, cb_arg, r_a_tov);
269 QEDF_ERR(&(qedf->dbg_ctx), "RRQ failed - release orig io "
270 "req 0x%x\n", aborted_io_req->xid);
272 kref_put(&aborted_io_req->refcount, qedf_release_cmd);
277 static void qedf_process_l2_frame_compl(struct qedf_rport *fcport,
281 struct fc_lport *lport = fcport->qedf->lport;
282 struct fc_frame_header *fh;
285 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
287 /* Set the OXID we return to what libfc used */
288 if (l2_oxid != FC_XID_UNKNOWN)
289 fh->fh_ox_id = htons(l2_oxid);
291 /* Setup header fields */
292 fh->fh_r_ctl = FC_RCTL_ELS_REP;
293 fh->fh_type = FC_TYPE_ELS;
294 /* Last sequence, end sequence */
295 fh->fh_f_ctl[0] = 0x98;
296 hton24(fh->fh_d_id, lport->port_id);
297 hton24(fh->fh_s_id, fcport->rdata->ids.port_id);
298 fh->fh_rx_id = 0xffff;
300 /* Set frame attributes */
301 crc = fcoe_fc_crc(fp);
304 fr_sof(fp) = FC_SOF_I3;
305 fr_eof(fp) = FC_EOF_T;
306 fr_crc(fp) = cpu_to_le32(~crc);
308 /* Send completed request to libfc */
309 fc_exch_recv(lport, fp);
313 * In instances where an ELS command times out we may need to restart the
314 * rport by logging out and then logging back in.
316 void qedf_restart_rport(struct qedf_rport *fcport)
318 struct fc_lport *lport;
319 struct fc_rport_priv *rdata;
325 rdata = fcport->rdata;
327 lport = fcport->qedf->lport;
328 port_id = rdata->ids.port_id;
329 QEDF_ERR(&(fcport->qedf->dbg_ctx),
330 "LOGO port_id=%x.\n", port_id);
331 fc_rport_logoff(rdata);
332 /* Recreate the rport and log back in */
333 rdata = fc_rport_create(lport, port_id);
335 fc_rport_login(rdata);
339 static void qedf_l2_els_compl(struct qedf_els_cb_arg *cb_arg)
341 struct qedf_ioreq *els_req;
342 struct qedf_rport *fcport;
343 struct qedf_mp_req *mp_req;
345 struct fc_frame_header *fh, *mp_fc_hdr;
346 void *resp_buf, *fc_payload;
350 l2_oxid = cb_arg->l2_oxid;
351 els_req = cb_arg->io_req;
354 QEDF_ERR(NULL, "els_req is NULL.\n");
359 * If we are flushing the command just free the cb_arg as none of the
360 * response data will be valid.
362 if (els_req->event == QEDF_IOREQ_EV_ELS_FLUSH)
365 fcport = els_req->fcport;
366 mp_req = &(els_req->mp_req);
367 mp_fc_hdr = &(mp_req->resp_fc_hdr);
368 resp_len = mp_req->resp_len;
369 resp_buf = mp_req->resp_buf;
372 * If a middle path ELS command times out, don't try to return
373 * the command but rather do any internal cleanup and then libfc
374 * timeout the command and clean up its internal resources.
376 if (els_req->event == QEDF_IOREQ_EV_ELS_TMO) {
378 * If ADISC times out, libfc will timeout the exchange and then
379 * try to send a PLOGI which will timeout since the session is
380 * still offloaded. Force libfc to logout the session which
381 * will offload the connection and allow the PLOGI response to
382 * flow over the LL2 path.
384 if (cb_arg->op == ELS_ADISC)
385 qedf_restart_rport(fcport);
389 if (sizeof(struct fc_frame_header) + resp_len > QEDF_PAGE_SIZE) {
390 QEDF_ERR(&(fcport->qedf->dbg_ctx), "resp_len is "
391 "beyond page size.\n");
395 fp = fc_frame_alloc(fcport->qedf->lport, resp_len);
397 QEDF_ERR(&(fcport->qedf->dbg_ctx),
398 "fc_frame_alloc failure.\n");
402 /* Copy frame header from firmware into fp */
403 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
404 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
406 /* Copy payload from firmware into fp */
407 fc_payload = fc_frame_payload_get(fp, resp_len);
408 memcpy(fc_payload, resp_buf, resp_len);
410 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
411 "Completing OX_ID 0x%x back to libfc.\n", l2_oxid);
412 qedf_process_l2_frame_compl(fcport, fp, l2_oxid);
418 int qedf_send_adisc(struct qedf_rport *fcport, struct fc_frame *fp)
420 struct fc_els_adisc *adisc;
421 struct fc_frame_header *fh;
422 struct fc_lport *lport = fcport->qedf->lport;
423 struct qedf_els_cb_arg *cb_arg = NULL;
424 struct qedf_ctx *qedf;
425 uint32_t r_a_tov = lport->r_a_tov;
429 fh = fc_frame_header_get(fp);
431 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
433 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
438 cb_arg->l2_oxid = ntohs(fh->fh_ox_id);
440 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
441 "Sending ADISC ox_id=0x%x.\n", cb_arg->l2_oxid);
443 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
445 rc = qedf_initiate_els(fcport, ELS_ADISC, adisc, sizeof(*adisc),
446 qedf_l2_els_compl, cb_arg, r_a_tov);
450 QEDF_ERR(&(qedf->dbg_ctx), "ADISC failed.\n");
456 static void qedf_srr_compl(struct qedf_els_cb_arg *cb_arg)
458 struct qedf_ioreq *orig_io_req;
459 struct qedf_ioreq *srr_req;
460 struct qedf_mp_req *mp_req;
461 struct fc_frame_header *mp_fc_hdr, *fh;
463 void *resp_buf, *fc_payload;
465 struct fc_lport *lport;
466 struct qedf_ctx *qedf;
470 srr_req = cb_arg->io_req;
471 qedf = srr_req->fcport->qedf;
474 orig_io_req = cb_arg->aborted_io_req;
479 clear_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags);
481 if (srr_req->event != QEDF_IOREQ_EV_ELS_TMO &&
482 srr_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
483 cancel_delayed_work_sync(&orig_io_req->timeout_work);
485 refcount = kref_read(&orig_io_req->refcount);
486 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p,"
487 " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n",
488 orig_io_req, orig_io_req->xid, srr_req->xid, refcount);
490 /* If a SRR times out, simply free resources */
491 if (srr_req->event == QEDF_IOREQ_EV_ELS_TMO)
494 /* Normalize response data into struct fc_frame */
495 mp_req = &(srr_req->mp_req);
496 mp_fc_hdr = &(mp_req->resp_fc_hdr);
497 resp_len = mp_req->resp_len;
498 resp_buf = mp_req->resp_buf;
500 fp = fc_frame_alloc(lport, resp_len);
502 QEDF_ERR(&(qedf->dbg_ctx),
503 "fc_frame_alloc failure.\n");
507 /* Copy frame header from firmware into fp */
508 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
509 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
511 /* Copy payload from firmware into fp */
512 fc_payload = fc_frame_payload_get(fp, resp_len);
513 memcpy(fc_payload, resp_buf, resp_len);
515 opcode = fc_frame_payload_op(fp);
518 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
522 QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_ELS,
524 qedf_initiate_abts(orig_io_req, true);
530 /* Put reference for original command since SRR completed */
531 kref_put(&orig_io_req->refcount, qedf_release_cmd);
535 static int qedf_send_srr(struct qedf_ioreq *orig_io_req, u32 offset, u8 r_ctl)
538 struct qedf_ctx *qedf;
539 struct qedf_rport *fcport;
540 struct fc_lport *lport;
541 struct qedf_els_cb_arg *cb_arg = NULL;
546 QEDF_ERR(NULL, "orig_io_req is NULL.\n");
550 fcport = orig_io_req->fcport;
552 /* Check that fcport is still offloaded */
553 if (!(test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags))) {
554 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
559 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
563 /* Take reference until SRR command completion */
564 kref_get(&orig_io_req->refcount);
569 r_a_tov = lport->r_a_tov;
571 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending SRR orig_io=%p, "
572 "orig_xid=0x%x\n", orig_io_req, orig_io_req->xid);
573 memset(&srr, 0, sizeof(srr));
575 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
577 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
583 cb_arg->aborted_io_req = orig_io_req;
585 srr.srr_op = ELS_SRR;
586 srr.srr_ox_id = htons(orig_io_req->xid);
587 srr.srr_rx_id = htons(orig_io_req->rx_id);
588 srr.srr_rel_off = htonl(offset);
589 srr.srr_r_ctl = r_ctl;
591 rc = qedf_initiate_els(fcport, ELS_SRR, &srr, sizeof(srr),
592 qedf_srr_compl, cb_arg, r_a_tov);
596 QEDF_ERR(&(qedf->dbg_ctx), "SRR failed - release orig_io_req"
597 "=0x%x\n", orig_io_req->xid);
599 /* If we fail to queue SRR, send ABTS to orig_io */
600 qedf_initiate_abts(orig_io_req, true);
601 kref_put(&orig_io_req->refcount, qedf_release_cmd);
603 /* Tell other threads that SRR is in progress */
604 set_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags);
609 static void qedf_initiate_seq_cleanup(struct qedf_ioreq *orig_io_req,
610 u32 offset, u8 r_ctl)
612 struct qedf_rport *fcport;
614 struct qedf_els_cb_arg *cb_arg;
615 struct fcoe_wqe *sqe;
618 fcport = orig_io_req->fcport;
620 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
621 "Doing sequence cleanup for xid=0x%x offset=%u.\n",
622 orig_io_req->xid, offset);
624 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
626 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to allocate cb_arg "
627 "for sequence cleanup\n");
631 /* Get reference for cleanup request */
632 kref_get(&orig_io_req->refcount);
634 orig_io_req->cmd_type = QEDF_SEQ_CLEANUP;
635 cb_arg->offset = offset;
636 cb_arg->r_ctl = r_ctl;
637 orig_io_req->cb_arg = cb_arg;
639 qedf_cmd_timer_set(fcport->qedf, orig_io_req,
640 QEDF_CLEANUP_TIMEOUT * HZ);
642 spin_lock_irqsave(&fcport->rport_lock, flags);
644 sqe_idx = qedf_get_sqe_idx(fcport);
645 sqe = &fcport->sq[sqe_idx];
646 memset(sqe, 0, sizeof(struct fcoe_wqe));
647 orig_io_req->task_params->sqe = sqe;
649 init_initiator_sequence_recovery_fcoe_task(orig_io_req->task_params,
651 qedf_ring_doorbell(fcport);
653 spin_unlock_irqrestore(&fcport->rport_lock, flags);
656 void qedf_process_seq_cleanup_compl(struct qedf_ctx *qedf,
657 struct fcoe_cqe *cqe, struct qedf_ioreq *io_req)
660 struct qedf_els_cb_arg *cb_arg;
662 cb_arg = io_req->cb_arg;
664 /* If we timed out just free resources */
665 if (io_req->event == QEDF_IOREQ_EV_ELS_TMO || !cqe)
668 /* Kill the timer we put on the request */
669 cancel_delayed_work_sync(&io_req->timeout_work);
671 rc = qedf_send_srr(io_req, cb_arg->offset, cb_arg->r_ctl);
673 QEDF_ERR(&(qedf->dbg_ctx), "Unable to send SRR, I/O will "
674 "abort, xid=0x%x.\n", io_req->xid);
677 kref_put(&io_req->refcount, qedf_release_cmd);
680 static bool qedf_requeue_io_req(struct qedf_ioreq *orig_io_req)
682 struct qedf_rport *fcport;
683 struct qedf_ioreq *new_io_req;
687 fcport = orig_io_req->fcport;
689 QEDF_ERR(NULL, "fcport is NULL.\n");
693 if (!orig_io_req->sc_cmd) {
694 QEDF_ERR(&(fcport->qedf->dbg_ctx), "sc_cmd is NULL for "
695 "xid=0x%x.\n", orig_io_req->xid);
699 new_io_req = qedf_alloc_cmd(fcport, QEDF_SCSI_CMD);
701 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Could not allocate new "
706 new_io_req->sc_cmd = orig_io_req->sc_cmd;
709 * This keeps the sc_cmd struct from being returned to the tape
710 * driver and being requeued twice. We do need to put a reference
711 * for the original I/O request since we will not do a SCSI completion
714 orig_io_req->sc_cmd = NULL;
715 kref_put(&orig_io_req->refcount, qedf_release_cmd);
717 spin_lock_irqsave(&fcport->rport_lock, flags);
719 /* kref for new command released in qedf_post_io_req on error */
720 if (qedf_post_io_req(fcport, new_io_req)) {
721 QEDF_ERR(&(fcport->qedf->dbg_ctx), "Unable to post io_req\n");
722 /* Return SQE to pool */
723 atomic_inc(&fcport->free_sqes);
725 QEDF_INFO(&(fcport->qedf->dbg_ctx), QEDF_LOG_ELS,
726 "Reissued SCSI command from orig_xid=0x%x on "
727 "new_xid=0x%x.\n", orig_io_req->xid, new_io_req->xid);
729 * Abort the original I/O but do not return SCSI command as
730 * it has been reissued on another OX_ID.
732 spin_unlock_irqrestore(&fcport->rport_lock, flags);
733 qedf_initiate_abts(orig_io_req, false);
737 spin_unlock_irqrestore(&fcport->rport_lock, flags);
743 static void qedf_rec_compl(struct qedf_els_cb_arg *cb_arg)
745 struct qedf_ioreq *orig_io_req;
746 struct qedf_ioreq *rec_req;
747 struct qedf_mp_req *mp_req;
748 struct fc_frame_header *mp_fc_hdr, *fh;
750 void *resp_buf, *fc_payload;
752 struct fc_lport *lport;
753 struct qedf_ctx *qedf;
756 struct fc_els_ls_rjt *rjt;
757 struct fc_els_rec_acc *acc;
760 struct scsi_cmnd *sc_cmd;
761 bool srr_needed = false;
763 rec_req = cb_arg->io_req;
764 qedf = rec_req->fcport->qedf;
767 orig_io_req = cb_arg->aborted_io_req;
772 if (rec_req->event != QEDF_IOREQ_EV_ELS_TMO &&
773 rec_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
774 cancel_delayed_work_sync(&orig_io_req->timeout_work);
776 refcount = kref_read(&orig_io_req->refcount);
777 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p,"
778 " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n",
779 orig_io_req, orig_io_req->xid, rec_req->xid, refcount);
781 /* If a REC times out, free resources */
782 if (rec_req->event == QEDF_IOREQ_EV_ELS_TMO)
785 /* Normalize response data into struct fc_frame */
786 mp_req = &(rec_req->mp_req);
787 mp_fc_hdr = &(mp_req->resp_fc_hdr);
788 resp_len = mp_req->resp_len;
789 acc = resp_buf = mp_req->resp_buf;
791 fp = fc_frame_alloc(lport, resp_len);
793 QEDF_ERR(&(qedf->dbg_ctx),
794 "fc_frame_alloc failure.\n");
798 /* Copy frame header from firmware into fp */
799 fh = (struct fc_frame_header *)fc_frame_header_get(fp);
800 memcpy(fh, mp_fc_hdr, sizeof(struct fc_frame_header));
802 /* Copy payload from firmware into fp */
803 fc_payload = fc_frame_payload_get(fp, resp_len);
804 memcpy(fc_payload, resp_buf, resp_len);
806 opcode = fc_frame_payload_op(fp);
807 if (opcode == ELS_LS_RJT) {
808 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
809 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
810 "Received LS_RJT for REC: er_reason=0x%x, "
811 "er_explan=0x%x.\n", rjt->er_reason, rjt->er_explan);
813 * The following response(s) mean that we need to reissue the
814 * request on another exchange. We need to do this without
815 * informing the upper layers lest it cause an application
818 if ((rjt->er_reason == ELS_RJT_LOGIC ||
819 rjt->er_reason == ELS_RJT_UNAB) &&
820 rjt->er_explan == ELS_EXPL_OXID_RXID) {
821 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
822 "Handle CMD LOST case.\n");
823 qedf_requeue_io_req(orig_io_req);
825 } else if (opcode == ELS_LS_ACC) {
826 offset = ntohl(acc->reca_fc4value);
827 e_stat = ntohl(acc->reca_e_stat);
828 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
829 "Received LS_ACC for REC: offset=0x%x, e_stat=0x%x.\n",
831 if (e_stat & ESB_ST_SEQ_INIT) {
832 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
833 "Target has the seq init\n");
836 sc_cmd = orig_io_req->sc_cmd;
838 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
839 "sc_cmd is NULL for xid=0x%x.\n",
843 /* SCSI write case */
844 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) {
845 if (offset == orig_io_req->data_xfer_len) {
846 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
847 "WRITE - response lost.\n");
848 r_ctl = FC_RCTL_DD_CMD_STATUS;
852 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
853 "WRITE - XFER_RDY/DATA lost.\n");
854 r_ctl = FC_RCTL_DD_DATA_DESC;
855 /* Use data from warning CQE instead of REC */
856 offset = orig_io_req->tx_buf_off;
860 if (orig_io_req->rx_buf_off ==
861 orig_io_req->data_xfer_len) {
862 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
863 "READ - response lost.\n");
865 r_ctl = FC_RCTL_DD_CMD_STATUS;
868 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
869 "READ - DATA lost.\n");
871 * For read case we always set the offset to 0
872 * for sequence recovery task.
875 r_ctl = FC_RCTL_DD_SOL_DATA;
880 qedf_send_srr(orig_io_req, offset, r_ctl);
882 qedf_initiate_seq_cleanup(orig_io_req, offset, r_ctl);
888 /* Put reference for original command since REC completed */
889 kref_put(&orig_io_req->refcount, qedf_release_cmd);
893 /* Assumes kref is already held by caller */
894 int qedf_send_rec(struct qedf_ioreq *orig_io_req)
897 struct fc_els_rec rec;
898 struct qedf_rport *fcport;
899 struct fc_lport *lport;
900 struct qedf_els_cb_arg *cb_arg = NULL;
901 struct qedf_ctx *qedf;
907 QEDF_ERR(NULL, "orig_io_req is NULL.\n");
911 fcport = orig_io_req->fcport;
913 /* Check that fcport is still offloaded */
914 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
915 QEDF_ERR(NULL, "fcport is no longer offloaded.\n");
920 QEDF_ERR(NULL, "fcport->qedf is NULL.\n");
924 /* Take reference until REC command completion */
925 kref_get(&orig_io_req->refcount);
930 r_a_tov = lport->r_a_tov;
932 memset(&rec, 0, sizeof(rec));
934 cb_arg = kzalloc(sizeof(struct qedf_els_cb_arg), GFP_NOIO);
936 QEDF_ERR(&(qedf->dbg_ctx), "Unable to allocate cb_arg for "
942 cb_arg->aborted_io_req = orig_io_req;
944 rec.rec_cmd = ELS_REC;
945 hton24(rec.rec_s_id, sid);
946 rec.rec_ox_id = htons(orig_io_req->xid);
948 htons(orig_io_req->task->tstorm_st_context.read_write.rx_id);
950 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending REC orig_io=%p, "
951 "orig_xid=0x%x rx_id=0x%x\n", orig_io_req,
952 orig_io_req->xid, rec.rec_rx_id);
953 rc = qedf_initiate_els(fcport, ELS_REC, &rec, sizeof(rec),
954 qedf_rec_compl, cb_arg, r_a_tov);
958 QEDF_ERR(&(qedf->dbg_ctx), "REC failed - release orig_io_req"
959 "=0x%x\n", orig_io_req->xid);
961 kref_put(&orig_io_req->refcount, qedf_release_cmd);