1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 ********************************************************************/
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
26 #include <linux/delay.h>
27 #include <asm/unaligned.h>
28 #include <linux/crc-t10dif.h>
29 #include <net/checksum.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_eh.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_tcq.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
39 #include "lpfc_version.h"
43 #include "lpfc_sli4.h"
45 #include "lpfc_disc.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_scsi.h"
49 #include "lpfc_logmsg.h"
50 #include "lpfc_crtn.h"
51 #include "lpfc_vport.h"
52 #include "lpfc_debugfs.h"
54 /* NVME initiator-based functions */
56 static struct lpfc_io_buf *
57 lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
58 int idx, int expedite);
61 lpfc_release_nvme_buf(struct lpfc_hba *, struct lpfc_io_buf *);
63 static struct nvme_fc_port_template lpfc_nvme_template;
66 * lpfc_nvme_create_queue -
67 * @pnvme_lport: Transport localport that LS is to be issued from
68 * @qidx: An cpu index used to affinitize IO queues and MSIX vectors.
69 * @qsize: Size of the queue in bytes
70 * @handle: An opaque driver handle used in follow-up calls.
72 * Driver registers this routine to preallocate and initialize any
73 * internal data structures to bind the @qidx to its internal IO queues.
74 * A hardware queue maps (qidx) to a specific driver MSI-X vector/EQ/CQ/WQ.
78 * -EINVAL - Unsupported input value.
79 * -ENOMEM - Could not alloc necessary memory
82 lpfc_nvme_create_queue(struct nvme_fc_local_port *pnvme_lport,
83 unsigned int qidx, u16 qsize,
86 struct lpfc_nvme_lport *lport;
87 struct lpfc_vport *vport;
88 struct lpfc_nvme_qhandle *qhandle;
91 if (!pnvme_lport->private)
94 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
96 qhandle = kzalloc(sizeof(struct lpfc_nvme_qhandle), GFP_KERNEL);
100 qhandle->cpu_id = raw_smp_processor_id();
101 qhandle->qidx = qidx;
103 * NVME qidx == 0 is the admin queue, so both admin queue
104 * and first IO queue will use MSI-X vector and associated
105 * EQ/CQ/WQ at index 0. After that they are sequentially assigned.
108 str = "IO "; /* IO queue */
109 qhandle->index = ((qidx - 1) %
110 lpfc_nvme_template.max_hw_queues);
112 str = "ADM"; /* Admin queue */
113 qhandle->index = qidx;
116 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
117 "6073 Binding %s HdwQueue %d (cpu %d) to "
118 "hdw_queue %d qhandle x%px\n", str,
119 qidx, qhandle->cpu_id, qhandle->index, qhandle);
120 *handle = (void *)qhandle;
125 * lpfc_nvme_delete_queue -
126 * @pnvme_lport: Transport localport that LS is to be issued from
127 * @qidx: An cpu index used to affinitize IO queues and MSIX vectors.
128 * @handle: An opaque driver handle from lpfc_nvme_create_queue
130 * Driver registers this routine to free
131 * any internal data structures to bind the @qidx to its internal
136 * TODO: What are the failure codes.
139 lpfc_nvme_delete_queue(struct nvme_fc_local_port *pnvme_lport,
143 struct lpfc_nvme_lport *lport;
144 struct lpfc_vport *vport;
146 if (!pnvme_lport->private)
149 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
150 vport = lport->vport;
152 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
153 "6001 ENTER. lpfc_pnvme x%px, qidx x%x qhandle x%px\n",
154 lport, qidx, handle);
159 lpfc_nvme_localport_delete(struct nvme_fc_local_port *localport)
161 struct lpfc_nvme_lport *lport = localport->private;
163 lpfc_printf_vlog(lport->vport, KERN_INFO, LOG_NVME,
164 "6173 localport x%px delete complete\n",
167 /* release any threads waiting for the unreg to complete */
168 if (lport->vport->localport)
169 complete(lport->lport_unreg_cmp);
172 /* lpfc_nvme_remoteport_delete
174 * @remoteport: Pointer to an nvme transport remoteport instance.
176 * This is a template downcall. NVME transport calls this function
177 * when it has completed the unregistration of a previously
178 * registered remoteport.
184 lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport)
186 struct lpfc_nvme_rport *rport = remoteport->private;
187 struct lpfc_vport *vport;
188 struct lpfc_nodelist *ndlp;
193 pr_err("**** %s: NULL ndlp on rport x%px remoteport x%px\n",
194 __func__, rport, remoteport);
200 pr_err("**** %s: Null vport on ndlp x%px, ste x%x rport x%px\n",
201 __func__, ndlp, ndlp->nlp_state, rport);
205 fc4_xpt_flags = NVME_XPT_REGD | SCSI_XPT_REGD;
207 /* Remove this rport from the lport's list - memory is owned by the
208 * transport. Remove the ndlp reference for the NVME transport before
209 * calling state machine to remove the node.
211 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
212 "6146 remoteport delete of remoteport x%px, ndlp x%px "
213 "DID x%x xflags x%x\n",
214 remoteport, ndlp, ndlp->nlp_DID, ndlp->fc4_xpt_flags);
215 spin_lock_irq(&ndlp->lock);
217 /* The register rebind might have occurred before the delete
218 * downcall. Guard against this race.
220 if (ndlp->fc4_xpt_flags & NVME_XPT_UNREG_WAIT)
221 ndlp->fc4_xpt_flags &= ~(NVME_XPT_UNREG_WAIT | NVME_XPT_REGD);
223 spin_unlock_irq(&ndlp->lock);
225 /* On a devloss timeout event, one more put is executed provided the
226 * NVME and SCSI rport unregister requests are complete. If the vport
227 * is unloading, this extra put is executed by lpfc_drop_node.
229 if (!(ndlp->fc4_xpt_flags & fc4_xpt_flags))
230 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
237 * lpfc_nvme_handle_lsreq - Process an unsolicited NVME LS request
238 * @phba: pointer to lpfc hba data structure.
239 * @axchg: pointer to exchange context for the NVME LS request
241 * This routine is used for processing an asychronously received NVME LS
242 * request. Any remaining validation is done and the LS is then forwarded
243 * to the nvme-fc transport via nvme_fc_rcv_ls_req().
245 * The calling sequence should be: nvme_fc_rcv_ls_req() -> (processing)
246 * -> lpfc_nvme_xmt_ls_rsp/cmp -> req->done.
247 * __lpfc_nvme_xmt_ls_rsp_cmp should free the allocated axchg.
249 * Returns 0 if LS was handled and delivered to the transport
250 * Returns 1 if LS failed to be handled and should be dropped
253 lpfc_nvme_handle_lsreq(struct lpfc_hba *phba,
254 struct lpfc_async_xchg_ctx *axchg)
256 #if (IS_ENABLED(CONFIG_NVME_FC))
257 struct lpfc_vport *vport;
258 struct lpfc_nvme_rport *lpfc_rport;
259 struct nvme_fc_remote_port *remoteport;
260 struct lpfc_nvme_lport *lport;
261 uint32_t *payload = axchg->payload;
264 vport = axchg->ndlp->vport;
265 lpfc_rport = axchg->ndlp->nrport;
269 remoteport = lpfc_rport->remoteport;
270 if (!vport->localport)
273 lport = vport->localport->private;
277 rc = nvme_fc_rcv_ls_req(remoteport, &axchg->ls_rsp, axchg->payload,
280 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
281 "6205 NVME Unsol rcv: sz %d rc %d: %08x %08x %08x "
284 *payload, *(payload+1), *(payload+2),
285 *(payload+3), *(payload+4), *(payload+5));
294 * __lpfc_nvme_ls_req_cmp - Generic completion handler for a NVME
296 * @phba: Pointer to HBA context object
297 * @vport: The local port that issued the LS
298 * @cmdwqe: Pointer to driver command WQE object.
299 * @wcqe: Pointer to driver response CQE object.
301 * This function is the generic completion handler for NVME LS requests.
302 * The function updates any states and statistics, calls the transport
303 * ls_req done() routine, then tears down the command and buffers used
304 * for the LS request.
307 __lpfc_nvme_ls_req_cmp(struct lpfc_hba *phba, struct lpfc_vport *vport,
308 struct lpfc_iocbq *cmdwqe,
309 struct lpfc_wcqe_complete *wcqe)
311 struct nvmefc_ls_req *pnvme_lsreq;
312 struct lpfc_dmabuf *buf_ptr;
313 struct lpfc_nodelist *ndlp;
316 pnvme_lsreq = (struct nvmefc_ls_req *)cmdwqe->context2;
317 ndlp = (struct lpfc_nodelist *)cmdwqe->context1;
318 status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK;
320 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
321 "6047 NVMEx LS REQ x%px cmpl DID %x Xri: %x "
322 "status %x reason x%x cmd:x%px lsreg:x%px bmp:x%px "
324 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
325 cmdwqe->sli4_xritag, status,
326 (wcqe->parameter & 0xffff),
327 cmdwqe, pnvme_lsreq, cmdwqe->context3, ndlp);
329 lpfc_nvmeio_data(phba, "NVMEx LS CMPL: xri x%x stat x%x parm x%x\n",
330 cmdwqe->sli4_xritag, status, wcqe->parameter);
332 if (cmdwqe->context3) {
333 buf_ptr = (struct lpfc_dmabuf *)cmdwqe->context3;
334 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
336 cmdwqe->context3 = NULL;
338 if (pnvme_lsreq->done)
339 pnvme_lsreq->done(pnvme_lsreq, status);
341 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
342 "6046 NVMEx cmpl without done call back? "
343 "Data x%px DID %x Xri: %x status %x\n",
344 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
345 cmdwqe->sli4_xritag, status);
348 cmdwqe->context1 = NULL;
350 lpfc_sli_release_iocbq(phba, cmdwqe);
354 lpfc_nvme_ls_req_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
355 struct lpfc_wcqe_complete *wcqe)
357 struct lpfc_vport *vport = cmdwqe->vport;
358 struct lpfc_nvme_lport *lport;
361 status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK;
363 if (vport->localport) {
364 lport = (struct lpfc_nvme_lport *)vport->localport->private;
366 atomic_inc(&lport->fc4NvmeLsCmpls);
368 if (bf_get(lpfc_wcqe_c_xb, wcqe))
369 atomic_inc(&lport->cmpl_ls_xb);
370 atomic_inc(&lport->cmpl_ls_err);
375 __lpfc_nvme_ls_req_cmp(phba, vport, cmdwqe, wcqe);
379 lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
380 struct lpfc_dmabuf *inp,
381 struct nvmefc_ls_req *pnvme_lsreq,
382 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
383 struct lpfc_wcqe_complete *),
384 struct lpfc_nodelist *ndlp, uint32_t num_entry,
385 uint32_t tmo, uint8_t retry)
387 struct lpfc_hba *phba = vport->phba;
388 union lpfc_wqe128 *wqe;
389 struct lpfc_iocbq *genwqe;
390 struct ulp_bde64 *bpl;
391 struct ulp_bde64 bde;
392 int i, rc, xmit_len, first_len;
394 /* Allocate buffer for command WQE */
395 genwqe = lpfc_sli_get_iocbq(phba);
400 /* Initialize only 64 bytes */
401 memset(wqe, 0, sizeof(union lpfc_wqe));
403 genwqe->context3 = (uint8_t *)bmp;
404 genwqe->iocb_flag |= LPFC_IO_NVME_LS;
406 /* Save for completion so we can release these resources */
407 genwqe->context1 = lpfc_nlp_get(ndlp);
408 if (!genwqe->context1) {
409 dev_warn(&phba->pcidev->dev,
410 "Warning: Failed node ref, not sending LS_REQ\n");
411 lpfc_sli_release_iocbq(phba, genwqe);
415 genwqe->context2 = (uint8_t *)pnvme_lsreq;
416 /* Fill in payload, bp points to frame payload */
419 /* FC spec states we need 3 * ratov for CT requests */
420 tmo = (3 * phba->fc_ratov);
422 /* For this command calculate the xmit length of the request bde. */
425 bpl = (struct ulp_bde64 *)bmp->virt;
426 for (i = 0; i < num_entry; i++) {
427 bde.tus.w = bpl[i].tus.w;
428 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
430 xmit_len += bde.tus.f.bdeSize;
432 first_len = xmit_len;
435 genwqe->rsvd2 = num_entry;
436 genwqe->hba_wqidx = 0;
439 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
440 wqe->generic.bde.tus.f.bdeSize = first_len;
441 wqe->generic.bde.addrLow = bpl[0].addrLow;
442 wqe->generic.bde.addrHigh = bpl[0].addrHigh;
445 wqe->gen_req.request_payload_len = first_len;
450 bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0);
451 bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1);
452 bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1);
453 bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_ELS4_REQ);
454 bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME);
457 bf_set(wqe_ctxt_tag, &wqe->gen_req.wqe_com,
458 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
459 bf_set(wqe_xri_tag, &wqe->gen_req.wqe_com, genwqe->sli4_xritag);
462 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, tmo);
463 bf_set(wqe_class, &wqe->gen_req.wqe_com, CLASS3);
464 bf_set(wqe_cmnd, &wqe->gen_req.wqe_com, CMD_GEN_REQUEST64_WQE);
465 bf_set(wqe_ct, &wqe->gen_req.wqe_com, SLI4_CT_RPI);
468 wqe->gen_req.wqe_com.abort_tag = genwqe->iotag;
471 bf_set(wqe_reqtag, &wqe->gen_req.wqe_com, genwqe->iotag);
474 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
475 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
476 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
477 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
478 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
481 bf_set(wqe_cqid, &wqe->gen_req.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
482 bf_set(wqe_cmd_type, &wqe->gen_req.wqe_com, OTHER_COMMAND);
485 /* Issue GEN REQ WQE for NPORT <did> */
486 genwqe->wqe_cmpl = cmpl;
487 genwqe->iocb_cmpl = NULL;
488 genwqe->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT;
489 genwqe->vport = vport;
490 genwqe->retry = retry;
492 lpfc_nvmeio_data(phba, "NVME LS XMIT: xri x%x iotag x%x to x%06x\n",
493 genwqe->sli4_xritag, genwqe->iotag, ndlp->nlp_DID);
495 rc = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[0], genwqe);
497 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
498 "6045 Issue GEN REQ WQE to NPORT x%x "
499 "Data: x%x x%x rc x%x\n",
500 ndlp->nlp_DID, genwqe->iotag,
501 vport->port_state, rc);
503 lpfc_sli_release_iocbq(phba, genwqe);
507 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC | LOG_ELS,
508 "6050 Issue GEN REQ WQE to NPORT x%x "
509 "Data: oxid: x%x state: x%x wq:x%px lsreq:x%px "
510 "bmp:x%px xmit:%d 1st:%d\n",
511 ndlp->nlp_DID, genwqe->sli4_xritag,
513 genwqe, pnvme_lsreq, bmp, xmit_len, first_len);
519 * __lpfc_nvme_ls_req - Generic service routine to issue an NVME LS request
520 * @vport: The local port issuing the LS
521 * @ndlp: The remote port to send the LS to
522 * @pnvme_lsreq: Pointer to LS request structure from the transport
523 * @gen_req_cmp: Completion call-back
525 * Routine validates the ndlp, builds buffers and sends a GEN_REQUEST
526 * WQE to perform the LS operation.
530 * non-zero: various error codes, in form of -Exxx
533 __lpfc_nvme_ls_req(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
534 struct nvmefc_ls_req *pnvme_lsreq,
535 void (*gen_req_cmp)(struct lpfc_hba *phba,
536 struct lpfc_iocbq *cmdwqe,
537 struct lpfc_wcqe_complete *wcqe))
539 struct lpfc_dmabuf *bmp;
540 struct ulp_bde64 *bpl;
542 uint16_t ntype, nstate;
545 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
546 "6051 NVMEx LS REQ: Bad NDLP x%px, Failing "
552 ntype = ndlp->nlp_type;
553 nstate = ndlp->nlp_state;
554 if ((ntype & NLP_NVME_TARGET && nstate != NLP_STE_MAPPED_NODE) ||
555 (ntype & NLP_NVME_INITIATOR && nstate != NLP_STE_UNMAPPED_NODE)) {
556 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
557 "6088 NVMEx LS REQ: Fail DID x%06x not "
558 "ready for IO. Type x%x, State x%x\n",
559 ndlp->nlp_DID, ntype, nstate);
563 if (!vport->phba->sli4_hba.nvmels_wq)
567 * there are two dma buf in the request, actually there is one and
568 * the second one is just the start address + cmd size.
569 * Before calling lpfc_nvme_gen_req these buffers need to be wrapped
570 * in a lpfc_dmabuf struct. When freeing we just free the wrapper
571 * because the nvem layer owns the data bufs.
572 * We do not have to break these packets open, we don't care what is
573 * in them. And we do not have to look at the resonse data, we only
574 * care that we got a response. All of the caring is going to happen
575 * in the nvme-fc layer.
578 bmp = kmalloc(sizeof(*bmp), GFP_KERNEL);
580 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
581 "6044 NVMEx LS REQ: Could not alloc LS buf "
587 bmp->virt = lpfc_mbuf_alloc(vport->phba, MEM_PRI, &(bmp->phys));
589 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
590 "6042 NVMEx LS REQ: Could not alloc mbuf "
597 INIT_LIST_HEAD(&bmp->list);
599 bpl = (struct ulp_bde64 *)bmp->virt;
600 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rqstdma));
601 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rqstdma));
602 bpl->tus.f.bdeFlags = 0;
603 bpl->tus.f.bdeSize = pnvme_lsreq->rqstlen;
604 bpl->tus.w = le32_to_cpu(bpl->tus.w);
607 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rspdma));
608 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rspdma));
609 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
610 bpl->tus.f.bdeSize = pnvme_lsreq->rsplen;
611 bpl->tus.w = le32_to_cpu(bpl->tus.w);
613 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
614 "6149 NVMEx LS REQ: Issue to DID 0x%06x lsreq x%px, "
615 "rqstlen:%d rsplen:%d %pad %pad\n",
616 ndlp->nlp_DID, pnvme_lsreq, pnvme_lsreq->rqstlen,
617 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
618 &pnvme_lsreq->rspdma);
620 ret = lpfc_nvme_gen_req(vport, bmp, pnvme_lsreq->rqstaddr,
621 pnvme_lsreq, gen_req_cmp, ndlp, 2,
622 pnvme_lsreq->timeout, 0);
623 if (ret != WQE_SUCCESS) {
624 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
625 "6052 NVMEx REQ: EXIT. issue ls wqe failed "
626 "lsreq x%px Status %x DID %x\n",
627 pnvme_lsreq, ret, ndlp->nlp_DID);
628 lpfc_mbuf_free(vport->phba, bmp->virt, bmp->phys);
637 * lpfc_nvme_ls_req - Issue an NVME Link Service request
638 * @pnvme_lport: Transport localport that LS is to be issued from.
639 * @pnvme_rport: Transport remoteport that LS is to be sent to.
640 * @pnvme_lsreq: the transport nvme_ls_req structure for the LS
642 * Driver registers this routine to handle any link service request
643 * from the nvme_fc transport to a remote nvme-aware port.
647 * non-zero: various error codes, in form of -Exxx
650 lpfc_nvme_ls_req(struct nvme_fc_local_port *pnvme_lport,
651 struct nvme_fc_remote_port *pnvme_rport,
652 struct nvmefc_ls_req *pnvme_lsreq)
654 struct lpfc_nvme_lport *lport;
655 struct lpfc_nvme_rport *rport;
656 struct lpfc_vport *vport;
659 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
660 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
661 if (unlikely(!lport) || unlikely(!rport))
664 vport = lport->vport;
665 if (vport->load_flag & FC_UNLOADING)
668 atomic_inc(&lport->fc4NvmeLsRequests);
670 ret = __lpfc_nvme_ls_req(vport, rport->ndlp, pnvme_lsreq,
671 lpfc_nvme_ls_req_cmp);
673 atomic_inc(&lport->xmt_ls_err);
679 * __lpfc_nvme_ls_abort - Generic service routine to abort a prior
681 * @vport: The local port that issued the LS
682 * @ndlp: The remote port the LS was sent to
683 * @pnvme_lsreq: Pointer to LS request structure from the transport
685 * The driver validates the ndlp, looks for the LS, and aborts the
689 * 0 : if LS found and aborted
690 * non-zero: various error conditions in form -Exxx
693 __lpfc_nvme_ls_abort(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
694 struct nvmefc_ls_req *pnvme_lsreq)
696 struct lpfc_hba *phba = vport->phba;
697 struct lpfc_sli_ring *pring;
698 struct lpfc_iocbq *wqe, *next_wqe;
699 bool foundit = false;
702 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
703 "6049 NVMEx LS REQ Abort: Bad NDLP x%px DID "
704 "x%06x, Failing LS Req\n",
705 ndlp, ndlp ? ndlp->nlp_DID : 0);
709 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC | LOG_NVME_ABTS,
710 "6040 NVMEx LS REQ Abort: Issue LS_ABORT for lsreq "
711 "x%px rqstlen:%d rsplen:%d %pad %pad\n",
712 pnvme_lsreq, pnvme_lsreq->rqstlen,
713 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
714 &pnvme_lsreq->rspdma);
717 * Lock the ELS ring txcmplq and look for the wqe that matches
718 * this ELS. If found, issue an abort on the wqe.
720 pring = phba->sli4_hba.nvmels_wq->pring;
721 spin_lock_irq(&phba->hbalock);
722 spin_lock(&pring->ring_lock);
723 list_for_each_entry_safe(wqe, next_wqe, &pring->txcmplq, list) {
724 if (wqe->context2 == pnvme_lsreq) {
725 wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
730 spin_unlock(&pring->ring_lock);
733 lpfc_sli_issue_abort_iotag(phba, pring, wqe, NULL);
734 spin_unlock_irq(&phba->hbalock);
739 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC | LOG_NVME_ABTS,
740 "6213 NVMEx LS REQ Abort: Unable to locate req x%px\n",
746 lpfc_nvme_xmt_ls_rsp(struct nvme_fc_local_port *localport,
747 struct nvme_fc_remote_port *remoteport,
748 struct nvmefc_ls_rsp *ls_rsp)
750 struct lpfc_async_xchg_ctx *axchg =
751 container_of(ls_rsp, struct lpfc_async_xchg_ctx, ls_rsp);
752 struct lpfc_nvme_lport *lport;
755 if (axchg->phba->pport->load_flag & FC_UNLOADING)
758 lport = (struct lpfc_nvme_lport *)localport->private;
760 rc = __lpfc_nvme_xmt_ls_rsp(axchg, ls_rsp, __lpfc_nvme_xmt_ls_rsp_cmp);
764 * unless the failure is due to having already sent
765 * the response, an abort will be generated for the
766 * exchange if the rsp can't be sent.
769 atomic_inc(&lport->xmt_ls_abort);
777 * lpfc_nvme_ls_abort - Abort a prior NVME LS request
778 * @pnvme_lport: Transport localport that LS is to be issued from.
779 * @pnvme_rport: Transport remoteport that LS is to be sent to.
780 * @pnvme_lsreq: the transport nvme_ls_req structure for the LS
782 * Driver registers this routine to abort a NVME LS request that is
783 * in progress (from the transports perspective).
786 lpfc_nvme_ls_abort(struct nvme_fc_local_port *pnvme_lport,
787 struct nvme_fc_remote_port *pnvme_rport,
788 struct nvmefc_ls_req *pnvme_lsreq)
790 struct lpfc_nvme_lport *lport;
791 struct lpfc_vport *vport;
792 struct lpfc_nodelist *ndlp;
795 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
796 if (unlikely(!lport))
798 vport = lport->vport;
800 if (vport->load_flag & FC_UNLOADING)
803 ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id);
805 ret = __lpfc_nvme_ls_abort(vport, ndlp, pnvme_lsreq);
807 atomic_inc(&lport->xmt_ls_abort);
810 /* Fix up the existing sgls for NVME IO. */
812 lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport,
813 struct lpfc_io_buf *lpfc_ncmd,
814 struct nvmefc_fcp_req *nCmd)
816 struct lpfc_hba *phba = vport->phba;
817 struct sli4_sge *sgl;
818 union lpfc_wqe128 *wqe;
819 uint32_t *wptr, *dptr;
822 * Get a local pointer to the built-in wqe and correct
823 * the cmd size to match NVME's 96 bytes and fix
827 wqe = &lpfc_ncmd->cur_iocbq.wqe;
830 * Adjust the FCP_CMD and FCP_RSP DMA data and sge_len to
831 * match NVME. NVME sends 96 bytes. Also, use the
832 * nvme commands command and response dma addresses
833 * rather than the virtual memory to ease the restore
836 sgl = lpfc_ncmd->dma_sgl;
837 sgl->sge_len = cpu_to_le32(nCmd->cmdlen);
838 if (phba->cfg_nvme_embed_cmd) {
842 /* Word 0-2 - NVME CMND IU (embedded payload) */
843 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_IMMED;
844 wqe->generic.bde.tus.f.bdeSize = 56;
845 wqe->generic.bde.addrHigh = 0;
846 wqe->generic.bde.addrLow = 64; /* Word 16 */
848 /* Word 10 - dbde is 0, wqes is 1 in template */
851 * Embed the payload in the last half of the WQE
852 * WQE words 16-30 get the NVME CMD IU payload
854 * WQE words 16-19 get payload Words 1-4
855 * WQE words 20-21 get payload Words 6-7
856 * WQE words 22-29 get payload Words 16-23
858 wptr = &wqe->words[16]; /* WQE ptr */
859 dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */
860 dptr++; /* Skip Word 0 in payload */
862 *wptr++ = *dptr++; /* Word 1 */
863 *wptr++ = *dptr++; /* Word 2 */
864 *wptr++ = *dptr++; /* Word 3 */
865 *wptr++ = *dptr++; /* Word 4 */
866 dptr++; /* Skip Word 5 in payload */
867 *wptr++ = *dptr++; /* Word 6 */
868 *wptr++ = *dptr++; /* Word 7 */
869 dptr += 8; /* Skip Words 8-15 in payload */
870 *wptr++ = *dptr++; /* Word 16 */
871 *wptr++ = *dptr++; /* Word 17 */
872 *wptr++ = *dptr++; /* Word 18 */
873 *wptr++ = *dptr++; /* Word 19 */
874 *wptr++ = *dptr++; /* Word 20 */
875 *wptr++ = *dptr++; /* Word 21 */
876 *wptr++ = *dptr++; /* Word 22 */
877 *wptr = *dptr; /* Word 23 */
879 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->cmddma));
880 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->cmddma));
882 /* Word 0-2 - NVME CMND IU Inline BDE */
883 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
884 wqe->generic.bde.tus.f.bdeSize = nCmd->cmdlen;
885 wqe->generic.bde.addrHigh = sgl->addr_hi;
886 wqe->generic.bde.addrLow = sgl->addr_lo;
889 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
890 bf_set(wqe_wqes, &wqe->generic.wqe_com, 0);
895 /* Setup the physical region for the FCP RSP */
896 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->rspdma));
897 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->rspdma));
898 sgl->word2 = le32_to_cpu(sgl->word2);
900 bf_set(lpfc_sli4_sge_last, sgl, 0);
902 bf_set(lpfc_sli4_sge_last, sgl, 1);
903 sgl->word2 = cpu_to_le32(sgl->word2);
904 sgl->sge_len = cpu_to_le32(nCmd->rsplen);
909 * lpfc_nvme_io_cmd_wqe_cmpl - Complete an NVME-over-FCP IO
911 * Driver registers this routine as it io request handler. This
912 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
913 * data structure to the rport indicated in @lpfc_nvme_rport.
917 * TODO: What are the failure codes.
920 lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
921 struct lpfc_wcqe_complete *wcqe)
923 struct lpfc_io_buf *lpfc_ncmd =
924 (struct lpfc_io_buf *)pwqeIn->context1;
925 struct lpfc_vport *vport = pwqeIn->vport;
926 struct nvmefc_fcp_req *nCmd;
927 struct nvme_fc_ersp_iu *ep;
928 struct nvme_fc_cmd_iu *cp;
929 struct lpfc_nodelist *ndlp;
930 struct lpfc_nvme_fcpreq_priv *freqpriv;
931 struct lpfc_nvme_lport *lport;
932 uint32_t code, status, idx;
933 uint16_t cid, sqhd, data;
936 bool call_done = false;
937 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
941 /* Sanity check on return of outstanding command */
943 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
944 "6071 Null lpfc_ncmd pointer. No "
945 "release, skip completion\n");
949 /* Guard against abort handler being called at same time */
950 spin_lock(&lpfc_ncmd->buf_lock);
952 if (!lpfc_ncmd->nvmeCmd) {
953 spin_unlock(&lpfc_ncmd->buf_lock);
954 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
955 "6066 Missing cmpl ptrs: lpfc_ncmd x%px, "
957 lpfc_ncmd, lpfc_ncmd->nvmeCmd);
959 /* Release the lpfc_ncmd regardless of the missing elements. */
960 lpfc_release_nvme_buf(phba, lpfc_ncmd);
963 nCmd = lpfc_ncmd->nvmeCmd;
964 status = bf_get(lpfc_wcqe_c_status, wcqe);
966 idx = lpfc_ncmd->cur_iocbq.hba_wqidx;
967 phba->sli4_hba.hdwq[idx].nvme_cstat.io_cmpls++;
969 if (unlikely(status && vport->localport)) {
970 lport = (struct lpfc_nvme_lport *)vport->localport->private;
972 if (bf_get(lpfc_wcqe_c_xb, wcqe))
973 atomic_inc(&lport->cmpl_fcp_xb);
974 atomic_inc(&lport->cmpl_fcp_err);
978 lpfc_nvmeio_data(phba, "NVME FCP CMPL: xri x%x stat x%x parm x%x\n",
979 lpfc_ncmd->cur_iocbq.sli4_xritag,
980 status, wcqe->parameter);
982 * Catch race where our node has transitioned, but the
983 * transport is still transitioning.
985 ndlp = lpfc_ncmd->ndlp;
987 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
988 "6062 Ignoring NVME cmpl. No ndlp\n");
992 code = bf_get(lpfc_wcqe_c_code, wcqe);
993 if (code == CQE_CODE_NVME_ERSP) {
994 /* For this type of CQE, we need to rebuild the rsp */
995 ep = (struct nvme_fc_ersp_iu *)nCmd->rspaddr;
998 * Get Command Id from cmd to plug into response. This
999 * code is not needed in the next NVME Transport drop.
1001 cp = (struct nvme_fc_cmd_iu *)nCmd->cmdaddr;
1002 cid = cp->sqe.common.command_id;
1005 * RSN is in CQE word 2
1006 * SQHD is in CQE Word 3 bits 15:0
1007 * Cmd Specific info is in CQE Word 1
1008 * and in CQE Word 0 bits 15:0
1010 sqhd = bf_get(lpfc_wcqe_c_sqhead, wcqe);
1012 /* Now lets build the NVME ERSP IU */
1013 ep->iu_len = cpu_to_be16(8);
1014 ep->rsn = wcqe->parameter;
1015 ep->xfrd_len = cpu_to_be32(nCmd->payload_length);
1017 ptr = (uint32_t *)&ep->cqe.result.u64;
1018 *ptr++ = wcqe->total_data_placed;
1019 data = bf_get(lpfc_wcqe_c_ersp0, wcqe);
1020 *ptr = (uint32_t)data;
1021 ep->cqe.sq_head = sqhd;
1022 ep->cqe.sq_id = nCmd->sqid;
1023 ep->cqe.command_id = cid;
1026 lpfc_ncmd->status = IOSTAT_SUCCESS;
1027 lpfc_ncmd->result = 0;
1028 nCmd->rcv_rsplen = LPFC_NVME_ERSP_LEN;
1029 nCmd->transferred_length = nCmd->payload_length;
1031 lpfc_ncmd->status = (status & LPFC_IOCB_STATUS_MASK);
1032 lpfc_ncmd->result = (wcqe->parameter & IOERR_PARAM_MASK);
1034 /* For NVME, the only failure path that results in an
1035 * IO error is when the adapter rejects it. All other
1036 * conditions are a success case and resolved by the
1038 * IOSTAT_FCP_RSP_ERROR means:
1039 * 1. Length of data received doesn't match total
1040 * transfer length in WQE
1041 * 2. If the RSP payload does NOT match these cases:
1042 * a. RSP length 12/24 bytes and all zeros
1045 switch (lpfc_ncmd->status) {
1046 case IOSTAT_SUCCESS:
1047 nCmd->transferred_length = wcqe->total_data_placed;
1048 nCmd->rcv_rsplen = 0;
1051 case IOSTAT_FCP_RSP_ERROR:
1052 nCmd->transferred_length = wcqe->total_data_placed;
1053 nCmd->rcv_rsplen = wcqe->parameter;
1056 /* Check if this is really an ERSP */
1057 if (nCmd->rcv_rsplen == LPFC_NVME_ERSP_LEN) {
1058 lpfc_ncmd->status = IOSTAT_SUCCESS;
1059 lpfc_ncmd->result = 0;
1061 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
1062 "6084 NVME Completion ERSP: "
1063 "xri %x placed x%x\n",
1064 lpfc_ncmd->cur_iocbq.sli4_xritag,
1065 wcqe->total_data_placed);
1068 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1069 "6081 NVME Completion Protocol Error: "
1070 "xri %x status x%x result x%x "
1072 lpfc_ncmd->cur_iocbq.sli4_xritag,
1073 lpfc_ncmd->status, lpfc_ncmd->result,
1074 wcqe->total_data_placed);
1076 case IOSTAT_LOCAL_REJECT:
1077 /* Let fall through to set command final state. */
1078 if (lpfc_ncmd->result == IOERR_ABORT_REQUESTED)
1079 lpfc_printf_vlog(vport, KERN_INFO,
1081 "6032 Delay Aborted cmd x%px "
1082 "nvme cmd x%px, xri x%x, "
1085 lpfc_ncmd->cur_iocbq.sli4_xritag,
1086 bf_get(lpfc_wcqe_c_xb, wcqe));
1090 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1091 "6072 NVME Completion Error: xri %x "
1092 "status x%x result x%x [x%x] "
1094 lpfc_ncmd->cur_iocbq.sli4_xritag,
1095 lpfc_ncmd->status, lpfc_ncmd->result,
1097 wcqe->total_data_placed);
1098 nCmd->transferred_length = 0;
1099 nCmd->rcv_rsplen = 0;
1100 nCmd->status = NVME_SC_INTERNAL;
1104 /* pick up SLI4 exhange busy condition */
1105 if (bf_get(lpfc_wcqe_c_xb, wcqe))
1106 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
1108 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
1110 /* Update stats and complete the IO. There is
1111 * no need for dma unprep because the nvme_transport
1112 * owns the dma address.
1114 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1115 if (lpfc_ncmd->ts_cmd_start) {
1116 lpfc_ncmd->ts_isr_cmpl = pwqeIn->isr_timestamp;
1117 lpfc_ncmd->ts_data_io = ktime_get_ns();
1118 phba->ktime_last_cmd = lpfc_ncmd->ts_data_io;
1119 lpfc_io_ktime(phba, lpfc_ncmd);
1121 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_NVME_IO)) {
1122 cpu = raw_smp_processor_id();
1123 this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io);
1124 if (lpfc_ncmd->cpu != cpu)
1125 lpfc_printf_vlog(vport,
1126 KERN_INFO, LOG_NVME_IOERR,
1127 "6701 CPU Check cmpl: "
1128 "cpu %d expect %d\n",
1129 cpu, lpfc_ncmd->cpu);
1133 /* NVME targets need completion held off until the abort exchange
1134 * completes unless the NVME Rport is getting unregistered.
1137 if (!(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) {
1138 freqpriv = nCmd->private;
1139 freqpriv->nvme_buf = NULL;
1140 lpfc_ncmd->nvmeCmd = NULL;
1143 spin_unlock(&lpfc_ncmd->buf_lock);
1145 /* Check if IO qualified for CMF */
1146 if (phba->cmf_active_mode != LPFC_CFG_OFF &&
1147 nCmd->io_dir == NVMEFC_FCP_READ &&
1148 nCmd->payload_length) {
1149 /* Used when calculating average latency */
1150 lat = ktime_get_ns() - lpfc_ncmd->rx_cmd_start;
1151 lpfc_update_cmf_cmpl(phba, lat, nCmd->payload_length, NULL);
1157 /* Call release with XB=1 to queue the IO into the abort list. */
1158 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1163 * lpfc_nvme_prep_io_cmd - Issue an NVME-over-FCP IO
1164 * @vport: pointer to a host virtual N_Port data structure
1165 * @lpfc_ncmd: Pointer to lpfc scsi command
1166 * @pnode: pointer to a node-list data structure
1167 * @cstat: pointer to the control status structure
1169 * Driver registers this routine as it io request handler. This
1170 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1171 * data structure to the rport indicated in @lpfc_nvme_rport.
1175 * TODO: What are the failure codes.
1178 lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport,
1179 struct lpfc_io_buf *lpfc_ncmd,
1180 struct lpfc_nodelist *pnode,
1181 struct lpfc_fc4_ctrl_stat *cstat)
1183 struct lpfc_hba *phba = vport->phba;
1184 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1185 struct nvme_common_command *sqe;
1186 struct lpfc_iocbq *pwqeq = &lpfc_ncmd->cur_iocbq;
1187 union lpfc_wqe128 *wqe = &pwqeq->wqe;
1191 * There are three possibilities here - use scatter-gather segment, use
1192 * the single mapping, or neither.
1195 if (nCmd->io_dir == NVMEFC_FCP_WRITE) {
1196 /* From the iwrite template, initialize words 7 - 11 */
1197 memcpy(&wqe->words[7],
1198 &lpfc_iwrite_cmd_template.words[7],
1199 sizeof(uint32_t) * 5);
1202 wqe->fcp_iwrite.total_xfer_len = nCmd->payload_length;
1205 if ((phba->cfg_nvme_enable_fb) &&
1206 (pnode->nlp_flag & NLP_FIRSTBURST)) {
1207 req_len = lpfc_ncmd->nvmeCmd->payload_length;
1208 if (req_len < pnode->nvme_fb_size)
1209 wqe->fcp_iwrite.initial_xfer_len =
1212 wqe->fcp_iwrite.initial_xfer_len =
1213 pnode->nvme_fb_size;
1215 wqe->fcp_iwrite.initial_xfer_len = 0;
1217 cstat->output_requests++;
1219 /* From the iread template, initialize words 7 - 11 */
1220 memcpy(&wqe->words[7],
1221 &lpfc_iread_cmd_template.words[7],
1222 sizeof(uint32_t) * 5);
1225 wqe->fcp_iread.total_xfer_len = nCmd->payload_length;
1228 wqe->fcp_iread.rsrvd5 = 0;
1230 /* For a CMF Managed port, iod must be zero'ed */
1231 if (phba->cmf_active_mode == LPFC_CFG_MANAGED)
1232 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com,
1234 cstat->input_requests++;
1237 /* From the icmnd template, initialize words 4 - 11 */
1238 memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4],
1239 sizeof(uint32_t) * 8);
1240 cstat->control_requests++;
1243 if (pnode->nlp_nvme_info & NLP_NVME_NSLER) {
1244 bf_set(wqe_erp, &wqe->generic.wqe_com, 1);
1245 sqe = &((struct nvme_fc_cmd_iu *)
1246 nCmd->cmdaddr)->sqe.common;
1247 if (sqe->opcode == nvme_admin_async_event)
1248 bf_set(wqe_ffrq, &wqe->generic.wqe_com, 1);
1252 * Finish initializing those WQE fields that are independent
1253 * of the nvme_cmnd request_buffer
1257 bf_set(payload_offset_len, &wqe->fcp_icmd,
1258 (nCmd->rsplen + nCmd->cmdlen));
1261 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
1262 phba->sli4_hba.rpi_ids[pnode->nlp_rpi]);
1263 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag);
1266 wqe->generic.wqe_com.abort_tag = pwqeq->iotag;
1269 bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag);
1272 bf_set(wqe_xchg, &wqe->fcp_iwrite.wqe_com, LPFC_NVME_XCHG);
1274 /* Words 13 14 15 are for PBDE support */
1276 pwqeq->vport = vport;
1282 * lpfc_nvme_prep_io_dma - Issue an NVME-over-FCP IO
1283 * @vport: pointer to a host virtual N_Port data structure
1284 * @lpfc_ncmd: Pointer to lpfc scsi command
1286 * Driver registers this routine as it io request handler. This
1287 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1288 * data structure to the rport indicated in @lpfc_nvme_rport.
1292 * TODO: What are the failure codes.
1295 lpfc_nvme_prep_io_dma(struct lpfc_vport *vport,
1296 struct lpfc_io_buf *lpfc_ncmd)
1298 struct lpfc_hba *phba = vport->phba;
1299 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1300 union lpfc_wqe128 *wqe = &lpfc_ncmd->cur_iocbq.wqe;
1301 struct sli4_sge *sgl = lpfc_ncmd->dma_sgl;
1302 struct sli4_hybrid_sgl *sgl_xtra = NULL;
1303 struct scatterlist *data_sg;
1304 struct sli4_sge *first_data_sgl;
1305 struct ulp_bde64 *bde;
1306 dma_addr_t physaddr = 0;
1307 uint32_t num_bde = 0;
1308 uint32_t dma_len = 0;
1309 uint32_t dma_offset = 0;
1311 bool lsp_just_set = false;
1313 /* Fix up the command and response DMA stuff. */
1314 lpfc_nvme_adj_fcp_sgls(vport, lpfc_ncmd, nCmd);
1317 * There are three possibilities here - use scatter-gather segment, use
1318 * the single mapping, or neither.
1322 * Jump over the cmd and rsp SGEs. The fix routine
1323 * has already adjusted for this.
1327 first_data_sgl = sgl;
1328 lpfc_ncmd->seg_cnt = nCmd->sg_cnt;
1329 if (lpfc_ncmd->seg_cnt > lpfc_nvme_template.max_sgl_segments) {
1330 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1331 "6058 Too many sg segments from "
1332 "NVME Transport. Max %d, "
1333 "nvmeIO sg_cnt %d\n",
1334 phba->cfg_nvme_seg_cnt + 1,
1335 lpfc_ncmd->seg_cnt);
1336 lpfc_ncmd->seg_cnt = 0;
1341 * The driver established a maximum scatter-gather segment count
1342 * during probe that limits the number of sg elements in any
1343 * single nvme command. Just run through the seg_cnt and format
1346 nseg = nCmd->sg_cnt;
1347 data_sg = nCmd->first_sgl;
1349 /* for tracking the segment boundaries */
1351 for (i = 0; i < nseg; i++) {
1352 if (data_sg == NULL) {
1353 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1354 "6059 dptr err %d, nseg %d\n",
1356 lpfc_ncmd->seg_cnt = 0;
1361 if ((num_bde + 1) == nseg) {
1362 bf_set(lpfc_sli4_sge_last, sgl, 1);
1363 bf_set(lpfc_sli4_sge_type, sgl,
1364 LPFC_SGE_TYPE_DATA);
1366 bf_set(lpfc_sli4_sge_last, sgl, 0);
1368 /* expand the segment */
1369 if (!lsp_just_set &&
1370 !((j + 1) % phba->border_sge_num) &&
1371 ((nseg - 1) != i)) {
1373 bf_set(lpfc_sli4_sge_type, sgl,
1376 sgl_xtra = lpfc_get_sgl_per_hdwq(
1379 if (unlikely(!sgl_xtra)) {
1380 lpfc_ncmd->seg_cnt = 0;
1383 sgl->addr_lo = cpu_to_le32(putPaddrLow(
1384 sgl_xtra->dma_phys_sgl));
1385 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
1386 sgl_xtra->dma_phys_sgl));
1389 bf_set(lpfc_sli4_sge_type, sgl,
1390 LPFC_SGE_TYPE_DATA);
1394 if (!(bf_get(lpfc_sli4_sge_type, sgl) &
1395 LPFC_SGE_TYPE_LSP)) {
1396 if ((nseg - 1) == i)
1397 bf_set(lpfc_sli4_sge_last, sgl, 1);
1399 physaddr = data_sg->dma_address;
1400 dma_len = data_sg->length;
1401 sgl->addr_lo = cpu_to_le32(
1402 putPaddrLow(physaddr));
1403 sgl->addr_hi = cpu_to_le32(
1404 putPaddrHigh(physaddr));
1406 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
1407 sgl->word2 = cpu_to_le32(sgl->word2);
1408 sgl->sge_len = cpu_to_le32(dma_len);
1410 dma_offset += dma_len;
1411 data_sg = sg_next(data_sg);
1415 lsp_just_set = false;
1417 sgl->word2 = cpu_to_le32(sgl->word2);
1419 sgl->sge_len = cpu_to_le32(
1420 phba->cfg_sg_dma_buf_size);
1422 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
1425 lsp_just_set = true;
1430 if (phba->cfg_enable_pbde) {
1431 /* Use PBDE support for first SGL only, offset == 0 */
1433 bde = (struct ulp_bde64 *)
1435 bde->addrLow = first_data_sgl->addr_lo;
1436 bde->addrHigh = first_data_sgl->addr_hi;
1437 bde->tus.f.bdeSize =
1438 le32_to_cpu(first_data_sgl->sge_len);
1439 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1440 bde->tus.w = cpu_to_le32(bde->tus.w);
1443 bf_set(wqe_pbde, &wqe->generic.wqe_com, 1);
1445 memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3));
1446 bf_set(wqe_pbde, &wqe->generic.wqe_com, 0);
1450 lpfc_ncmd->seg_cnt = 0;
1452 /* For this clause to be valid, the payload_length
1453 * and sg_cnt must zero.
1455 if (nCmd->payload_length != 0) {
1456 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1457 "6063 NVME DMA Prep Err: sg_cnt %d "
1458 "payload_length x%x\n",
1459 nCmd->sg_cnt, nCmd->payload_length);
1467 * lpfc_nvme_fcp_io_submit - Issue an NVME-over-FCP IO
1468 * @pnvme_lport: Pointer to the driver's local port data
1469 * @pnvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1470 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1471 * @pnvme_fcreq: IO request from nvme fc to driver.
1473 * Driver registers this routine as it io request handler. This
1474 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1475 * data structure to the rport indicated in @lpfc_nvme_rport.
1479 * TODO: What are the failure codes.
1482 lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
1483 struct nvme_fc_remote_port *pnvme_rport,
1484 void *hw_queue_handle,
1485 struct nvmefc_fcp_req *pnvme_fcreq)
1490 struct lpfc_nvme_lport *lport;
1491 struct lpfc_fc4_ctrl_stat *cstat;
1492 struct lpfc_vport *vport;
1493 struct lpfc_hba *phba;
1494 struct lpfc_nodelist *ndlp;
1495 struct lpfc_io_buf *lpfc_ncmd;
1496 struct lpfc_nvme_rport *rport;
1497 struct lpfc_nvme_qhandle *lpfc_queue_info;
1498 struct lpfc_nvme_fcpreq_priv *freqpriv;
1499 struct nvme_common_command *sqe;
1502 /* Validate pointers. LLDD fault handling with transport does
1503 * have timing races.
1505 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1506 if (unlikely(!lport)) {
1511 vport = lport->vport;
1513 if (unlikely(!hw_queue_handle)) {
1514 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1515 "6117 Fail IO, NULL hw_queue_handle\n");
1516 atomic_inc(&lport->xmt_fcp_err);
1523 if (unlikely(vport->load_flag & FC_UNLOADING)) {
1524 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1525 "6124 Fail IO, Driver unload\n");
1526 atomic_inc(&lport->xmt_fcp_err);
1531 freqpriv = pnvme_fcreq->private;
1532 if (unlikely(!freqpriv)) {
1533 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1534 "6158 Fail IO, NULL request data\n");
1535 atomic_inc(&lport->xmt_fcp_err);
1540 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1542 start = ktime_get_ns();
1544 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
1545 lpfc_queue_info = (struct lpfc_nvme_qhandle *)hw_queue_handle;
1548 * Catch race where our node has transitioned, but the
1549 * transport is still transitioning.
1553 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1554 "6053 Busy IO, ndlp not ready: rport x%px "
1555 "ndlp x%px, DID x%06x\n",
1556 rport, ndlp, pnvme_rport->port_id);
1557 atomic_inc(&lport->xmt_fcp_err);
1562 /* The remote node has to be a mapped target or it's an error. */
1563 if ((ndlp->nlp_type & NLP_NVME_TARGET) &&
1564 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
1565 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1566 "6036 Fail IO, DID x%06x not ready for "
1567 "IO. State x%x, Type x%x Flg x%x\n",
1568 pnvme_rport->port_id,
1569 ndlp->nlp_state, ndlp->nlp_type,
1570 ndlp->fc4_xpt_flags);
1571 atomic_inc(&lport->xmt_fcp_bad_ndlp);
1577 /* Currently only NVME Keep alive commands should be expedited
1578 * if the driver runs out of a resource. These should only be
1579 * issued on the admin queue, qidx 0
1581 if (!lpfc_queue_info->qidx && !pnvme_fcreq->sg_cnt) {
1582 sqe = &((struct nvme_fc_cmd_iu *)
1583 pnvme_fcreq->cmdaddr)->sqe.common;
1584 if (sqe->opcode == nvme_admin_keep_alive)
1588 /* Check if IO qualifies for CMF */
1589 if (phba->cmf_active_mode != LPFC_CFG_OFF &&
1590 pnvme_fcreq->io_dir == NVMEFC_FCP_READ &&
1591 pnvme_fcreq->payload_length) {
1592 ret = lpfc_update_cmf_cmd(phba, pnvme_fcreq->payload_length);
1597 /* Get start time for IO latency */
1598 start = ktime_get_ns();
1601 /* The node is shared with FCP IO, make sure the IO pending count does
1602 * not exceed the programmed depth.
1604 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
1605 if ((atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) &&
1607 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1608 "6174 Fail IO, ndlp qdepth exceeded: "
1609 "idx %d DID %x pend %d qdepth %d\n",
1610 lpfc_queue_info->index, ndlp->nlp_DID,
1611 atomic_read(&ndlp->cmd_pending),
1613 atomic_inc(&lport->xmt_fcp_qdepth);
1619 /* Lookup Hardware Queue index based on fcp_io_sched module parameter */
1620 if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) {
1621 idx = lpfc_queue_info->index;
1623 cpu = raw_smp_processor_id();
1624 idx = phba->sli4_hba.cpu_map[cpu].hdwq;
1627 lpfc_ncmd = lpfc_get_nvme_buf(phba, ndlp, idx, expedite);
1628 if (lpfc_ncmd == NULL) {
1629 atomic_inc(&lport->xmt_fcp_noxri);
1630 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1631 "6065 Fail IO, driver buffer pool is empty: "
1633 lpfc_queue_info->index, ndlp->nlp_DID);
1637 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1639 lpfc_ncmd->ts_cmd_start = start;
1640 lpfc_ncmd->ts_last_cmd = phba->ktime_last_cmd;
1642 lpfc_ncmd->ts_cmd_start = 0;
1645 lpfc_ncmd->rx_cmd_start = start;
1648 * Store the data needed by the driver to issue, abort, and complete
1650 * Do not let the IO hang out forever. There is no midlayer issuing
1651 * an abort so inform the FW of the maximum IO pending time.
1653 freqpriv->nvme_buf = lpfc_ncmd;
1654 lpfc_ncmd->nvmeCmd = pnvme_fcreq;
1655 lpfc_ncmd->ndlp = ndlp;
1656 lpfc_ncmd->qidx = lpfc_queue_info->qidx;
1659 * Issue the IO on the WQ indicated by index in the hw_queue_handle.
1660 * This identfier was create in our hardware queue create callback
1661 * routine. The driver now is dependent on the IO queue steering from
1662 * the transport. We are trusting the upper NVME layers know which
1663 * index to use and that they have affinitized a CPU to this hardware
1664 * queue. A hardware queue maps to a driver MSI-X vector/EQ/CQ/WQ.
1666 lpfc_ncmd->cur_iocbq.hba_wqidx = idx;
1667 cstat = &phba->sli4_hba.hdwq[idx].nvme_cstat;
1669 lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp, cstat);
1670 ret = lpfc_nvme_prep_io_dma(vport, lpfc_ncmd);
1672 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1673 "6175 Fail IO, Prep DMA: "
1675 lpfc_queue_info->index, ndlp->nlp_DID);
1676 atomic_inc(&lport->xmt_fcp_err);
1678 goto out_free_nvme_buf;
1681 lpfc_nvmeio_data(phba, "NVME FCP XMIT: xri x%x idx %d to %06x\n",
1682 lpfc_ncmd->cur_iocbq.sli4_xritag,
1683 lpfc_queue_info->index, ndlp->nlp_DID);
1685 ret = lpfc_sli4_issue_wqe(phba, lpfc_ncmd->hdwq, &lpfc_ncmd->cur_iocbq);
1687 atomic_inc(&lport->xmt_fcp_wqerr);
1688 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1689 "6113 Fail IO, Could not issue WQE err %x "
1690 "sid: x%x did: x%x oxid: x%x\n",
1691 ret, vport->fc_myDID, ndlp->nlp_DID,
1692 lpfc_ncmd->cur_iocbq.sli4_xritag);
1693 goto out_free_nvme_buf;
1696 if (phba->cfg_xri_rebalancing)
1697 lpfc_keep_pvt_pool_above_lowwm(phba, lpfc_ncmd->hdwq_no);
1699 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1700 if (lpfc_ncmd->ts_cmd_start)
1701 lpfc_ncmd->ts_cmd_wqput = ktime_get_ns();
1703 if (phba->hdwqstat_on & LPFC_CHECK_NVME_IO) {
1704 cpu = raw_smp_processor_id();
1705 this_cpu_inc(phba->sli4_hba.c_stat->xmt_io);
1706 lpfc_ncmd->cpu = cpu;
1708 lpfc_printf_vlog(vport,
1709 KERN_INFO, LOG_NVME_IOERR,
1710 "6702 CPU Check cmd: "
1713 lpfc_queue_info->index);
1719 if (lpfc_ncmd->nvmeCmd->sg_cnt) {
1720 if (lpfc_ncmd->nvmeCmd->io_dir == NVMEFC_FCP_WRITE)
1721 cstat->output_requests--;
1723 cstat->input_requests--;
1725 cstat->control_requests--;
1726 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1728 lpfc_update_cmf_cmpl(phba, LPFC_CGN_NOT_SENT,
1729 pnvme_fcreq->payload_length, NULL);
1735 * lpfc_nvme_abort_fcreq_cmpl - Complete an NVME FCP abort request.
1736 * @phba: Pointer to HBA context object
1737 * @cmdiocb: Pointer to command iocb object.
1738 * @abts_cmpl: Pointer to wcqe complete object.
1740 * This is the callback function for any NVME FCP IO that was aborted.
1746 lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1747 struct lpfc_wcqe_complete *abts_cmpl)
1749 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
1750 "6145 ABORT_XRI_CN completing on rpi x%x "
1751 "original iotag x%x, abort cmd iotag x%x "
1752 "req_tag x%x, status x%x, hwstatus x%x\n",
1753 cmdiocb->iocb.un.acxri.abortContextTag,
1754 cmdiocb->iocb.un.acxri.abortIoTag,
1756 bf_get(lpfc_wcqe_c_request_tag, abts_cmpl),
1757 bf_get(lpfc_wcqe_c_status, abts_cmpl),
1758 bf_get(lpfc_wcqe_c_hw_status, abts_cmpl));
1759 lpfc_sli_release_iocbq(phba, cmdiocb);
1763 * lpfc_nvme_fcp_abort - Issue an NVME-over-FCP ABTS
1764 * @pnvme_lport: Pointer to the driver's local port data
1765 * @pnvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1766 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1767 * @pnvme_fcreq: IO request from nvme fc to driver.
1769 * Driver registers this routine as its nvme request io abort handler. This
1770 * routine issues an fcp Abort WQE with data from the @lpfc_nvme_fcpreq
1771 * data structure to the rport indicated in @lpfc_nvme_rport. This routine
1772 * is executed asynchronously - one the target is validated as "MAPPED" and
1773 * ready for IO, the driver issues the abort request and returns.
1779 lpfc_nvme_fcp_abort(struct nvme_fc_local_port *pnvme_lport,
1780 struct nvme_fc_remote_port *pnvme_rport,
1781 void *hw_queue_handle,
1782 struct nvmefc_fcp_req *pnvme_fcreq)
1784 struct lpfc_nvme_lport *lport;
1785 struct lpfc_vport *vport;
1786 struct lpfc_hba *phba;
1787 struct lpfc_io_buf *lpfc_nbuf;
1788 struct lpfc_iocbq *nvmereq_wqe;
1789 struct lpfc_nvme_fcpreq_priv *freqpriv;
1790 unsigned long flags;
1793 /* Validate pointers. LLDD fault handling with transport does
1794 * have timing races.
1796 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1797 if (unlikely(!lport))
1800 vport = lport->vport;
1802 if (unlikely(!hw_queue_handle)) {
1803 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1804 "6129 Fail Abort, HW Queue Handle NULL.\n");
1809 freqpriv = pnvme_fcreq->private;
1811 if (unlikely(!freqpriv))
1813 if (vport->load_flag & FC_UNLOADING)
1816 /* Announce entry to new IO submit field. */
1817 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1818 "6002 Abort Request to rport DID x%06x "
1819 "for nvme_fc_req x%px\n",
1820 pnvme_rport->port_id,
1823 /* If the hba is getting reset, this flag is set. It is
1824 * cleared when the reset is complete and rings reestablished.
1826 spin_lock_irqsave(&phba->hbalock, flags);
1827 /* driver queued commands are in process of being flushed */
1828 if (phba->hba_flag & HBA_IOQ_FLUSH) {
1829 spin_unlock_irqrestore(&phba->hbalock, flags);
1830 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1831 "6139 Driver in reset cleanup - flushing "
1832 "NVME Req now. hba_flag x%x\n",
1837 lpfc_nbuf = freqpriv->nvme_buf;
1839 spin_unlock_irqrestore(&phba->hbalock, flags);
1840 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1841 "6140 NVME IO req has no matching lpfc nvme "
1842 "io buffer. Skipping abort req.\n");
1844 } else if (!lpfc_nbuf->nvmeCmd) {
1845 spin_unlock_irqrestore(&phba->hbalock, flags);
1846 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1847 "6141 lpfc NVME IO req has no nvme_fcreq "
1848 "io buffer. Skipping abort req.\n");
1851 nvmereq_wqe = &lpfc_nbuf->cur_iocbq;
1853 /* Guard against IO completion being called at same time */
1854 spin_lock(&lpfc_nbuf->buf_lock);
1857 * The lpfc_nbuf and the mapped nvme_fcreq in the driver's
1858 * state must match the nvme_fcreq passed by the nvme
1859 * transport. If they don't match, it is likely the driver
1860 * has already completed the NVME IO and the nvme transport
1861 * has not seen it yet.
1863 if (lpfc_nbuf->nvmeCmd != pnvme_fcreq) {
1864 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1865 "6143 NVME req mismatch: "
1866 "lpfc_nbuf x%px nvmeCmd x%px, "
1867 "pnvme_fcreq x%px. Skipping Abort xri x%x\n",
1868 lpfc_nbuf, lpfc_nbuf->nvmeCmd,
1869 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1873 /* Don't abort IOs no longer on the pending queue. */
1874 if (!(nvmereq_wqe->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
1875 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1876 "6142 NVME IO req x%px not queued - skipping "
1877 "abort req xri x%x\n",
1878 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1882 atomic_inc(&lport->xmt_fcp_abort);
1883 lpfc_nvmeio_data(phba, "NVME FCP ABORT: xri x%x idx %d to %06x\n",
1884 nvmereq_wqe->sli4_xritag,
1885 nvmereq_wqe->hba_wqidx, pnvme_rport->port_id);
1887 /* Outstanding abort is in progress */
1888 if (nvmereq_wqe->iocb_flag & LPFC_DRIVER_ABORTED) {
1889 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1890 "6144 Outstanding NVME I/O Abort Request "
1891 "still pending on nvme_fcreq x%px, "
1892 "lpfc_ncmd x%px xri x%x\n",
1893 pnvme_fcreq, lpfc_nbuf,
1894 nvmereq_wqe->sli4_xritag);
1898 ret_val = lpfc_sli4_issue_abort_iotag(phba, nvmereq_wqe,
1899 lpfc_nvme_abort_fcreq_cmpl);
1901 spin_unlock(&lpfc_nbuf->buf_lock);
1902 spin_unlock_irqrestore(&phba->hbalock, flags);
1904 /* Make sure HBA is alive */
1905 lpfc_issue_hb_tmo(phba);
1907 if (ret_val != WQE_SUCCESS) {
1908 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1909 "6137 Failed abts issue_wqe with status x%x "
1910 "for nvme_fcreq x%px.\n",
1911 ret_val, pnvme_fcreq);
1915 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1916 "6138 Transport Abort NVME Request Issued for "
1918 nvmereq_wqe->sli4_xritag);
1922 spin_unlock(&lpfc_nbuf->buf_lock);
1923 spin_unlock_irqrestore(&phba->hbalock, flags);
1927 /* Declare and initialization an instance of the FC NVME template. */
1928 static struct nvme_fc_port_template lpfc_nvme_template = {
1929 /* initiator-based functions */
1930 .localport_delete = lpfc_nvme_localport_delete,
1931 .remoteport_delete = lpfc_nvme_remoteport_delete,
1932 .create_queue = lpfc_nvme_create_queue,
1933 .delete_queue = lpfc_nvme_delete_queue,
1934 .ls_req = lpfc_nvme_ls_req,
1935 .fcp_io = lpfc_nvme_fcp_io_submit,
1936 .ls_abort = lpfc_nvme_ls_abort,
1937 .fcp_abort = lpfc_nvme_fcp_abort,
1938 .xmt_ls_rsp = lpfc_nvme_xmt_ls_rsp,
1941 .max_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1942 .max_dif_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1943 .dma_boundary = 0xFFFFFFFF,
1945 /* Sizes of additional private data for data structures.
1946 * No use for the last two sizes at this time.
1948 .local_priv_sz = sizeof(struct lpfc_nvme_lport),
1949 .remote_priv_sz = sizeof(struct lpfc_nvme_rport),
1950 .lsrqst_priv_sz = 0,
1951 .fcprqst_priv_sz = sizeof(struct lpfc_nvme_fcpreq_priv),
1955 * lpfc_get_nvme_buf - Get a nvme buffer from io_buf_list of the HBA
1957 * This routine removes a nvme buffer from head of @hdwq io_buf_list
1958 * and returns to caller.
1962 * Pointer to lpfc_nvme_buf - Success
1964 static struct lpfc_io_buf *
1965 lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1966 int idx, int expedite)
1968 struct lpfc_io_buf *lpfc_ncmd;
1969 struct lpfc_sli4_hdw_queue *qp;
1970 struct sli4_sge *sgl;
1971 struct lpfc_iocbq *pwqeq;
1972 union lpfc_wqe128 *wqe;
1974 lpfc_ncmd = lpfc_get_io_buf(phba, NULL, idx, expedite);
1977 pwqeq = &(lpfc_ncmd->cur_iocbq);
1980 /* Setup key fields in buffer that may have been changed
1981 * if other protocols used this buffer.
1983 pwqeq->iocb_flag = LPFC_IO_NVME;
1984 pwqeq->wqe_cmpl = lpfc_nvme_io_cmd_wqe_cmpl;
1985 lpfc_ncmd->start_time = jiffies;
1986 lpfc_ncmd->flags = 0;
1988 /* Rsp SGE will be filled in when we rcv an IO
1989 * from the NVME Layer to be sent.
1990 * The cmd is going to be embedded so we need a SKIP SGE.
1992 sgl = lpfc_ncmd->dma_sgl;
1993 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP);
1994 bf_set(lpfc_sli4_sge_last, sgl, 0);
1995 sgl->word2 = cpu_to_le32(sgl->word2);
1996 /* Fill in word 3 / sgl_len during cmd submission */
1998 /* Initialize 64 bytes only */
1999 memset(wqe, 0, sizeof(union lpfc_wqe));
2001 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
2002 atomic_inc(&ndlp->cmd_pending);
2003 lpfc_ncmd->flags |= LPFC_SBUF_BUMP_QDEPTH;
2007 qp = &phba->sli4_hba.hdwq[idx];
2008 qp->empty_io_bufs++;
2015 * lpfc_release_nvme_buf: Return a nvme buffer back to hba nvme buf list.
2016 * @phba: The Hba for which this call is being executed.
2017 * @lpfc_ncmd: The nvme buffer which is being released.
2019 * This routine releases @lpfc_ncmd nvme buffer by adding it to tail of @phba
2020 * lpfc_io_buf_list list. For SLI4 XRI's are tied to the nvme buffer
2021 * and cannot be reused for at least RA_TOV amount of time if it was
2025 lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd)
2027 struct lpfc_sli4_hdw_queue *qp;
2028 unsigned long iflag = 0;
2030 if ((lpfc_ncmd->flags & LPFC_SBUF_BUMP_QDEPTH) && lpfc_ncmd->ndlp)
2031 atomic_dec(&lpfc_ncmd->ndlp->cmd_pending);
2033 lpfc_ncmd->ndlp = NULL;
2034 lpfc_ncmd->flags &= ~LPFC_SBUF_BUMP_QDEPTH;
2036 qp = lpfc_ncmd->hdwq;
2037 if (unlikely(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) {
2038 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2039 "6310 XB release deferred for "
2040 "ox_id x%x on reqtag x%x\n",
2041 lpfc_ncmd->cur_iocbq.sli4_xritag,
2042 lpfc_ncmd->cur_iocbq.iotag);
2044 spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag);
2045 list_add_tail(&lpfc_ncmd->list,
2046 &qp->lpfc_abts_io_buf_list);
2047 qp->abts_nvme_io_bufs++;
2048 spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag);
2050 lpfc_release_io_buf(phba, (struct lpfc_io_buf *)lpfc_ncmd, qp);
2054 * lpfc_nvme_create_localport - Create/Bind an nvme localport instance.
2055 * @vport: the lpfc_vport instance requesting a localport.
2057 * This routine is invoked to create an nvme localport instance to bind
2058 * to the nvme_fc_transport. It is called once during driver load
2059 * like lpfc_create_shost after all other services are initialized.
2060 * It requires a vport, vpi, and wwns at call time. Other localport
2061 * parameters are modified as the driver's FCID and the Fabric WWN
2066 * -ENOMEM - no heap memory available
2067 * other values - from nvme registration upcall
2070 lpfc_nvme_create_localport(struct lpfc_vport *vport)
2073 struct lpfc_hba *phba = vport->phba;
2074 struct nvme_fc_port_info nfcp_info;
2075 struct nvme_fc_local_port *localport;
2076 struct lpfc_nvme_lport *lport;
2078 /* Initialize this localport instance. The vport wwn usage ensures
2079 * that NPIV is accounted for.
2081 memset(&nfcp_info, 0, sizeof(struct nvme_fc_port_info));
2082 nfcp_info.port_role = FC_PORT_ROLE_NVME_INITIATOR;
2083 nfcp_info.node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
2084 nfcp_info.port_name = wwn_to_u64(vport->fc_portname.u.wwn);
2086 /* We need to tell the transport layer + 1 because it takes page
2087 * alignment into account. When space for the SGL is allocated we
2088 * allocate + 3, one for cmd, one for rsp and one for this alignment
2090 lpfc_nvme_template.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1;
2092 /* Advertise how many hw queues we support based on cfg_hdw_queue,
2093 * which will not exceed cpu count.
2095 lpfc_nvme_template.max_hw_queues = phba->cfg_hdw_queue;
2097 if (!IS_ENABLED(CONFIG_NVME_FC))
2100 /* localport is allocated from the stack, but the registration
2101 * call allocates heap memory as well as the private area.
2104 ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template,
2105 &vport->phba->pcidev->dev, &localport);
2107 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC,
2108 "6005 Successfully registered local "
2109 "NVME port num %d, localP x%px, private "
2110 "x%px, sg_seg %d\n",
2111 localport->port_num, localport,
2113 lpfc_nvme_template.max_sgl_segments);
2115 /* Private is our lport size declared in the template. */
2116 lport = (struct lpfc_nvme_lport *)localport->private;
2117 vport->localport = localport;
2118 lport->vport = vport;
2119 vport->nvmei_support = 1;
2121 atomic_set(&lport->xmt_fcp_noxri, 0);
2122 atomic_set(&lport->xmt_fcp_bad_ndlp, 0);
2123 atomic_set(&lport->xmt_fcp_qdepth, 0);
2124 atomic_set(&lport->xmt_fcp_err, 0);
2125 atomic_set(&lport->xmt_fcp_wqerr, 0);
2126 atomic_set(&lport->xmt_fcp_abort, 0);
2127 atomic_set(&lport->xmt_ls_abort, 0);
2128 atomic_set(&lport->xmt_ls_err, 0);
2129 atomic_set(&lport->cmpl_fcp_xb, 0);
2130 atomic_set(&lport->cmpl_fcp_err, 0);
2131 atomic_set(&lport->cmpl_ls_xb, 0);
2132 atomic_set(&lport->cmpl_ls_err, 0);
2134 atomic_set(&lport->fc4NvmeLsRequests, 0);
2135 atomic_set(&lport->fc4NvmeLsCmpls, 0);
2141 #if (IS_ENABLED(CONFIG_NVME_FC))
2142 /* lpfc_nvme_lport_unreg_wait - Wait for the host to complete an lport unreg.
2144 * The driver has to wait for the host nvme transport to callback
2145 * indicating the localport has successfully unregistered all
2146 * resources. Since this is an uninterruptible wait, loop every ten
2147 * seconds and print a message indicating no progress.
2149 * An uninterruptible wait is used because of the risk of transport-to-
2150 * driver state mismatch.
2153 lpfc_nvme_lport_unreg_wait(struct lpfc_vport *vport,
2154 struct lpfc_nvme_lport *lport,
2155 struct completion *lport_unreg_cmp)
2158 int ret, i, pending = 0;
2159 struct lpfc_sli_ring *pring;
2160 struct lpfc_hba *phba = vport->phba;
2161 struct lpfc_sli4_hdw_queue *qp;
2162 int abts_scsi, abts_nvme;
2164 /* Host transport has to clean up and confirm requiring an indefinite
2165 * wait. Print a message if a 10 second wait expires and renew the
2166 * wait. This is unexpected.
2168 wait_tmo = msecs_to_jiffies(LPFC_NVME_WAIT_TMO * 1000);
2170 ret = wait_for_completion_timeout(lport_unreg_cmp, wait_tmo);
2171 if (unlikely(!ret)) {
2175 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2176 qp = &phba->sli4_hba.hdwq[i];
2177 pring = qp->io_wq->pring;
2180 pending += pring->txcmplq_cnt;
2181 abts_scsi += qp->abts_scsi_io_bufs;
2182 abts_nvme += qp->abts_nvme_io_bufs;
2184 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2185 "6176 Lport x%px Localport x%px wait "
2186 "timed out. Pending %d [%d:%d]. "
2188 lport, vport->localport, pending,
2189 abts_scsi, abts_nvme);
2194 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
2195 "6177 Lport x%px Localport x%px Complete Success\n",
2196 lport, vport->localport);
2201 * lpfc_nvme_destroy_localport - Destroy lpfc_nvme bound to nvme transport.
2202 * @vport: pointer to a host virtual N_Port data structure
2204 * This routine is invoked to destroy all lports bound to the phba.
2205 * The lport memory was allocated by the nvme fc transport and is
2206 * released there. This routine ensures all rports bound to the
2207 * lport have been disconnected.
2211 lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2213 #if (IS_ENABLED(CONFIG_NVME_FC))
2214 struct nvme_fc_local_port *localport;
2215 struct lpfc_nvme_lport *lport;
2217 DECLARE_COMPLETION_ONSTACK(lport_unreg_cmp);
2219 if (vport->nvmei_support == 0)
2222 localport = vport->localport;
2223 lport = (struct lpfc_nvme_lport *)localport->private;
2225 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2226 "6011 Destroying NVME localport x%px\n",
2229 /* lport's rport list is clear. Unregister
2230 * lport and release resources.
2232 lport->lport_unreg_cmp = &lport_unreg_cmp;
2233 ret = nvme_fc_unregister_localport(localport);
2235 /* Wait for completion. This either blocks
2236 * indefinitely or succeeds
2238 lpfc_nvme_lport_unreg_wait(vport, lport, &lport_unreg_cmp);
2239 vport->localport = NULL;
2241 /* Regardless of the unregister upcall response, clear
2242 * nvmei_support. All rports are unregistered and the
2243 * driver will clean up.
2245 vport->nvmei_support = 0;
2247 lpfc_printf_vlog(vport,
2248 KERN_INFO, LOG_NVME_DISC,
2249 "6009 Unregistered lport Success\n");
2251 lpfc_printf_vlog(vport,
2252 KERN_INFO, LOG_NVME_DISC,
2253 "6010 Unregistered lport "
2254 "Failed, status x%x\n",
2261 lpfc_nvme_update_localport(struct lpfc_vport *vport)
2263 #if (IS_ENABLED(CONFIG_NVME_FC))
2264 struct nvme_fc_local_port *localport;
2265 struct lpfc_nvme_lport *lport;
2267 localport = vport->localport;
2269 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2270 "6710 Update NVME fail. No localport\n");
2273 lport = (struct lpfc_nvme_lport *)localport->private;
2275 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2276 "6171 Update NVME fail. localP x%px, No lport\n",
2280 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2281 "6012 Update NVME lport x%px did x%x\n",
2282 localport, vport->fc_myDID);
2284 localport->port_id = vport->fc_myDID;
2285 if (localport->port_id == 0)
2286 localport->port_role = FC_PORT_ROLE_NVME_DISCOVERY;
2288 localport->port_role = FC_PORT_ROLE_NVME_INITIATOR;
2290 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2291 "6030 bound lport x%px to DID x%06x\n",
2292 lport, localport->port_id);
2297 lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2299 #if (IS_ENABLED(CONFIG_NVME_FC))
2301 struct nvme_fc_local_port *localport;
2302 struct lpfc_nvme_lport *lport;
2303 struct lpfc_nvme_rport *rport;
2304 struct lpfc_nvme_rport *oldrport;
2305 struct nvme_fc_remote_port *remote_port;
2306 struct nvme_fc_port_info rpinfo;
2307 struct lpfc_nodelist *prev_ndlp = NULL;
2308 struct fc_rport *srport = ndlp->rport;
2310 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC,
2311 "6006 Register NVME PORT. DID x%06x nlptype x%x\n",
2312 ndlp->nlp_DID, ndlp->nlp_type);
2314 localport = vport->localport;
2318 lport = (struct lpfc_nvme_lport *)localport->private;
2320 /* NVME rports are not preserved across devloss.
2321 * Just register this instance. Note, rpinfo->dev_loss_tmo
2322 * is left 0 to indicate accept transport defaults. The
2323 * driver communicates port role capabilities consistent
2324 * with the PRLI response data.
2326 memset(&rpinfo, 0, sizeof(struct nvme_fc_port_info));
2327 rpinfo.port_id = ndlp->nlp_DID;
2328 if (ndlp->nlp_type & NLP_NVME_TARGET)
2329 rpinfo.port_role |= FC_PORT_ROLE_NVME_TARGET;
2330 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
2331 rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR;
2333 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
2334 rpinfo.port_role |= FC_PORT_ROLE_NVME_DISCOVERY;
2336 rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
2337 rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
2339 rpinfo.dev_loss_tmo = srport->dev_loss_tmo;
2341 rpinfo.dev_loss_tmo = vport->cfg_devloss_tmo;
2343 spin_lock_irq(&ndlp->lock);
2344 oldrport = lpfc_ndlp_get_nrport(ndlp);
2346 prev_ndlp = oldrport->ndlp;
2347 spin_unlock_irq(&ndlp->lock);
2349 spin_unlock_irq(&ndlp->lock);
2350 if (!lpfc_nlp_get(ndlp)) {
2351 dev_warn(&vport->phba->pcidev->dev,
2352 "Warning - No node ref - exit register\n");
2357 ret = nvme_fc_register_remoteport(localport, &rpinfo, &remote_port);
2359 /* If the ndlp already has an nrport, this is just
2360 * a resume of the existing rport. Else this is a
2363 /* Guard against an unregister/reregister
2364 * race that leaves the WAIT flag set.
2366 spin_lock_irq(&ndlp->lock);
2367 ndlp->fc4_xpt_flags &= ~NVME_XPT_UNREG_WAIT;
2368 ndlp->fc4_xpt_flags |= NVME_XPT_REGD;
2369 spin_unlock_irq(&ndlp->lock);
2370 rport = remote_port->private;
2373 /* Sever the ndlp<->rport association
2374 * before dropping the ndlp ref from
2377 spin_lock_irq(&ndlp->lock);
2378 ndlp->nrport = NULL;
2379 ndlp->fc4_xpt_flags &= ~NVME_XPT_UNREG_WAIT;
2380 spin_unlock_irq(&ndlp->lock);
2382 rport->remoteport = NULL;
2384 /* Reference only removed if previous NDLP is no longer
2385 * active. It might be just a swap and removing the
2386 * reference would cause a premature cleanup.
2388 if (prev_ndlp && prev_ndlp != ndlp) {
2389 if (!prev_ndlp->nrport)
2390 lpfc_nlp_put(prev_ndlp);
2394 /* Clean bind the rport to the ndlp. */
2395 rport->remoteport = remote_port;
2396 rport->lport = lport;
2398 spin_lock_irq(&ndlp->lock);
2399 ndlp->nrport = rport;
2400 spin_unlock_irq(&ndlp->lock);
2401 lpfc_printf_vlog(vport, KERN_INFO,
2402 LOG_NVME_DISC | LOG_NODE,
2403 "6022 Bind lport x%px to remoteport x%px "
2404 "rport x%px WWNN 0x%llx, "
2405 "Rport WWPN 0x%llx DID "
2406 "x%06x Role x%x, ndlp %p prev_ndlp x%px\n",
2407 lport, remote_port, rport,
2408 rpinfo.node_name, rpinfo.port_name,
2409 rpinfo.port_id, rpinfo.port_role,
2412 lpfc_printf_vlog(vport, KERN_ERR,
2414 "6031 RemotePort Registration failed "
2415 "err: %d, DID x%06x\n",
2416 ret, ndlp->nlp_DID);
2426 * lpfc_nvme_rescan_port - Check to see if we should rescan this remoteport
2428 * If the ndlp represents an NVME Target, that we are logged into,
2429 * ping the NVME FC Transport layer to initiate a device rescan
2430 * on this remote NPort.
2433 lpfc_nvme_rescan_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2435 #if (IS_ENABLED(CONFIG_NVME_FC))
2436 struct lpfc_nvme_rport *nrport;
2437 struct nvme_fc_remote_port *remoteport = NULL;
2439 spin_lock_irq(&ndlp->lock);
2440 nrport = lpfc_ndlp_get_nrport(ndlp);
2442 remoteport = nrport->remoteport;
2443 spin_unlock_irq(&ndlp->lock);
2445 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2446 "6170 Rescan NPort DID x%06x type x%x "
2447 "state x%x nrport x%px remoteport x%px\n",
2448 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_state,
2449 nrport, remoteport);
2451 if (!nrport || !remoteport)
2454 /* Only rescan if we are an NVME target in the MAPPED state */
2455 if (remoteport->port_role & FC_PORT_ROLE_NVME_DISCOVERY &&
2456 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
2457 nvme_fc_rescan_remoteport(remoteport);
2459 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2460 "6172 NVME rescanned DID x%06x "
2462 ndlp->nlp_DID, remoteport->port_state);
2466 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2467 "6169 Skip NVME Rport Rescan, NVME remoteport "
2472 /* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport.
2474 * There is no notion of Devloss or rport recovery from the current
2475 * nvme_transport perspective. Loss of an rport just means IO cannot
2476 * be sent and recovery is completely up to the initator.
2477 * For now, the driver just unbinds the DID and port_role so that
2478 * no further IO can be issued. Changes are planned for later.
2480 * Notes - the ndlp reference count is not decremented here since
2481 * since there is no nvme_transport api for devloss. Node ref count
2482 * is only adjusted in driver unload.
2485 lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2487 #if (IS_ENABLED(CONFIG_NVME_FC))
2489 struct nvme_fc_local_port *localport;
2490 struct lpfc_nvme_lport *lport;
2491 struct lpfc_nvme_rport *rport;
2492 struct nvme_fc_remote_port *remoteport = NULL;
2494 localport = vport->localport;
2496 /* This is fundamental error. The localport is always
2497 * available until driver unload. Just exit.
2502 lport = (struct lpfc_nvme_lport *)localport->private;
2506 spin_lock_irq(&ndlp->lock);
2507 rport = lpfc_ndlp_get_nrport(ndlp);
2509 remoteport = rport->remoteport;
2510 spin_unlock_irq(&ndlp->lock);
2514 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2515 "6033 Unreg nvme remoteport x%px, portname x%llx, "
2516 "port_id x%06x, portstate x%x port type x%x "
2518 remoteport, remoteport->port_name,
2519 remoteport->port_id, remoteport->port_state,
2520 ndlp->nlp_type, kref_read(&ndlp->kref));
2522 /* Sanity check ndlp type. Only call for NVME ports. Don't
2523 * clear any rport state until the transport calls back.
2526 if (ndlp->nlp_type & NLP_NVME_TARGET) {
2527 /* No concern about the role change on the nvme remoteport.
2528 * The transport will update it.
2530 spin_lock_irq(&vport->phba->hbalock);
2531 ndlp->fc4_xpt_flags |= NVME_XPT_UNREG_WAIT;
2532 spin_unlock_irq(&vport->phba->hbalock);
2534 /* Don't let the host nvme transport keep sending keep-alives
2535 * on this remoteport. Vport is unloading, no recovery. The
2536 * return values is ignored. The upcall is a courtesy to the
2539 if (vport->load_flag & FC_UNLOADING)
2540 (void)nvme_fc_set_remoteport_devloss(remoteport, 0);
2542 ret = nvme_fc_unregister_remoteport(remoteport);
2544 /* The driver no longer knows if the nrport memory is valid.
2545 * because the controller teardown process has begun and
2546 * is asynchronous. Break the binding in the ndlp. Also
2547 * remove the register ndlp reference to setup node release.
2549 ndlp->nrport = NULL;
2552 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2553 "6167 NVME unregister failed %d "
2555 ret, remoteport->port_state);
2562 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2563 "6168 State error: lport x%px, rport x%px FCID x%06x\n",
2564 vport->localport, ndlp->rport, ndlp->nlp_DID);
2568 * lpfc_sli4_nvme_xri_aborted - Fast-path process of NVME xri abort
2569 * @phba: pointer to lpfc hba data structure.
2570 * @axri: pointer to the fcp xri abort wcqe structure.
2571 * @lpfc_ncmd: The nvme job structure for the request being aborted.
2573 * This routine is invoked by the worker thread to process a SLI4 fast-path
2574 * NVME aborted xri. Aborted NVME IO commands are completed to the transport
2578 lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba,
2579 struct sli4_wcqe_xri_aborted *axri,
2580 struct lpfc_io_buf *lpfc_ncmd)
2582 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
2583 struct nvmefc_fcp_req *nvme_cmd = NULL;
2584 struct lpfc_nodelist *ndlp = lpfc_ncmd->ndlp;
2588 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
2590 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2591 "6311 nvme_cmd %p xri x%x tag x%x abort complete and "
2593 lpfc_ncmd->nvmeCmd, xri,
2594 lpfc_ncmd->cur_iocbq.iotag);
2596 /* Aborted NVME commands are required to not complete
2597 * before the abort exchange command fully completes.
2598 * Once completed, it is available via the put list.
2600 if (lpfc_ncmd->nvmeCmd) {
2601 nvme_cmd = lpfc_ncmd->nvmeCmd;
2602 nvme_cmd->done(nvme_cmd);
2603 lpfc_ncmd->nvmeCmd = NULL;
2605 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2609 * lpfc_nvme_wait_for_io_drain - Wait for all NVME wqes to complete
2610 * @phba: Pointer to HBA context object.
2612 * This function flushes all wqes in the nvme rings and frees all resources
2613 * in the txcmplq. This function does not issue abort wqes for the IO
2614 * commands in txcmplq, they will just be returned with
2615 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
2616 * slot has been permanently disabled.
2619 lpfc_nvme_wait_for_io_drain(struct lpfc_hba *phba)
2621 struct lpfc_sli_ring *pring;
2622 u32 i, wait_cnt = 0;
2624 if (phba->sli_rev < LPFC_SLI_REV4 || !phba->sli4_hba.hdwq)
2627 /* Cycle through all IO rings and make sure all outstanding
2628 * WQEs have been removed from the txcmplqs.
2630 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2631 if (!phba->sli4_hba.hdwq[i].io_wq)
2633 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
2638 /* Retrieve everything on the txcmplq */
2639 while (!list_empty(&pring->txcmplq)) {
2640 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
2643 /* The sleep is 10mS. Every ten seconds,
2644 * dump a message. Something is wrong.
2646 if ((wait_cnt % 1000) == 0) {
2647 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2648 "6178 NVME IO not empty, "
2649 "cnt %d\n", wait_cnt);
2654 /* Make sure HBA is alive */
2655 lpfc_issue_hb_tmo(phba);
2660 lpfc_nvme_cancel_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
2661 uint32_t stat, uint32_t param)
2663 #if (IS_ENABLED(CONFIG_NVME_FC))
2664 struct lpfc_io_buf *lpfc_ncmd;
2665 struct nvmefc_fcp_req *nCmd;
2666 struct lpfc_wcqe_complete wcqe;
2667 struct lpfc_wcqe_complete *wcqep = &wcqe;
2669 lpfc_ncmd = (struct lpfc_io_buf *)pwqeIn->context1;
2671 lpfc_sli_release_iocbq(phba, pwqeIn);
2674 /* For abort iocb just return, IO iocb will do a done call */
2675 if (bf_get(wqe_cmnd, &pwqeIn->wqe.gen_req.wqe_com) ==
2677 lpfc_sli_release_iocbq(phba, pwqeIn);
2681 spin_lock(&lpfc_ncmd->buf_lock);
2682 nCmd = lpfc_ncmd->nvmeCmd;
2684 spin_unlock(&lpfc_ncmd->buf_lock);
2685 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2688 spin_unlock(&lpfc_ncmd->buf_lock);
2690 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR,
2691 "6194 NVME Cancel xri %x\n",
2692 lpfc_ncmd->cur_iocbq.sli4_xritag);
2695 bf_set(lpfc_wcqe_c_status, wcqep, stat);
2696 wcqep->parameter = param;
2697 wcqep->word3 = 0; /* xb is 0 */
2699 /* Call release with XB=1 to queue the IO into the abort list. */
2700 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
2701 bf_set(lpfc_wcqe_c_xb, wcqep, 1);
2703 (pwqeIn->wqe_cmpl)(phba, pwqeIn, wcqep);