1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 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 <linux/nvme.h>
40 #include <linux/nvme-fc-driver.h>
41 #include <linux/nvme-fc.h>
42 #include "lpfc_version.h"
46 #include "lpfc_sli4.h"
48 #include "lpfc_disc.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_scsi.h"
52 #include "lpfc_logmsg.h"
53 #include "lpfc_crtn.h"
54 #include "lpfc_vport.h"
55 #include "lpfc_debugfs.h"
57 /* NVME initiator-based functions */
59 static struct lpfc_nvme_buf *
60 lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
64 lpfc_release_nvme_buf(struct lpfc_hba *, struct lpfc_nvme_buf *);
66 static struct nvme_fc_port_template lpfc_nvme_template;
68 static union lpfc_wqe128 lpfc_iread_cmd_template;
69 static union lpfc_wqe128 lpfc_iwrite_cmd_template;
70 static union lpfc_wqe128 lpfc_icmnd_cmd_template;
72 /* Setup WQE templates for NVME IOs */
74 lpfc_nvme_cmd_template(void)
76 union lpfc_wqe128 *wqe;
79 wqe = &lpfc_iread_cmd_template;
80 memset(wqe, 0, sizeof(union lpfc_wqe128));
82 /* Word 0, 1, 2 - BDE is variable */
84 /* Word 3 - cmd_buff_len, payload_offset_len is zero */
86 /* Word 4 - total_xfer_len is variable */
88 /* Word 5 - is zero */
90 /* Word 6 - ctxt_tag, xri_tag is variable */
93 bf_set(wqe_cmnd, &wqe->fcp_iread.wqe_com, CMD_FCP_IREAD64_WQE);
94 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, PARM_READ_CHECK);
95 bf_set(wqe_class, &wqe->fcp_iread.wqe_com, CLASS3);
96 bf_set(wqe_ct, &wqe->fcp_iread.wqe_com, SLI4_CT_RPI);
98 /* Word 8 - abort_tag is variable */
100 /* Word 9 - reqtag is variable */
102 /* Word 10 - dbde, wqes is variable */
103 bf_set(wqe_qosd, &wqe->fcp_iread.wqe_com, 0);
104 bf_set(wqe_nvme, &wqe->fcp_iread.wqe_com, 1);
105 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
106 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, LPFC_WQE_LENLOC_WORD4);
107 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0);
108 bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1);
110 /* Word 11 - pbde is variable */
111 bf_set(wqe_cmd_type, &wqe->fcp_iread.wqe_com, NVME_READ_CMD);
112 bf_set(wqe_cqid, &wqe->fcp_iread.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
113 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1);
115 /* Word 12 - is zero */
117 /* Word 13, 14, 15 - PBDE is variable */
119 /* IWRITE template */
120 wqe = &lpfc_iwrite_cmd_template;
121 memset(wqe, 0, sizeof(union lpfc_wqe128));
123 /* Word 0, 1, 2 - BDE is variable */
125 /* Word 3 - cmd_buff_len, payload_offset_len is zero */
127 /* Word 4 - total_xfer_len is variable */
129 /* Word 5 - initial_xfer_len is variable */
131 /* Word 6 - ctxt_tag, xri_tag is variable */
134 bf_set(wqe_cmnd, &wqe->fcp_iwrite.wqe_com, CMD_FCP_IWRITE64_WQE);
135 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, PARM_READ_CHECK);
136 bf_set(wqe_class, &wqe->fcp_iwrite.wqe_com, CLASS3);
137 bf_set(wqe_ct, &wqe->fcp_iwrite.wqe_com, SLI4_CT_RPI);
139 /* Word 8 - abort_tag is variable */
141 /* Word 9 - reqtag is variable */
143 /* Word 10 - dbde, wqes is variable */
144 bf_set(wqe_qosd, &wqe->fcp_iwrite.wqe_com, 0);
145 bf_set(wqe_nvme, &wqe->fcp_iwrite.wqe_com, 1);
146 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
147 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_LENLOC_WORD4);
148 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
149 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
151 /* Word 11 - pbde is variable */
152 bf_set(wqe_cmd_type, &wqe->fcp_iwrite.wqe_com, NVME_WRITE_CMD);
153 bf_set(wqe_cqid, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
154 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1);
156 /* Word 12 - is zero */
158 /* Word 13, 14, 15 - PBDE is variable */
161 wqe = &lpfc_icmnd_cmd_template;
162 memset(wqe, 0, sizeof(union lpfc_wqe128));
164 /* Word 0, 1, 2 - BDE is variable */
166 /* Word 3 - payload_offset_len is variable */
168 /* Word 4, 5 - is zero */
170 /* Word 6 - ctxt_tag, xri_tag is variable */
173 bf_set(wqe_cmnd, &wqe->fcp_icmd.wqe_com, CMD_FCP_ICMND64_WQE);
174 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
175 bf_set(wqe_class, &wqe->fcp_icmd.wqe_com, CLASS3);
176 bf_set(wqe_ct, &wqe->fcp_icmd.wqe_com, SLI4_CT_RPI);
178 /* Word 8 - abort_tag is variable */
180 /* Word 9 - reqtag is variable */
182 /* Word 10 - dbde, wqes is variable */
183 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
184 bf_set(wqe_nvme, &wqe->fcp_icmd.wqe_com, 1);
185 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_NONE);
186 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, LPFC_WQE_LENLOC_NONE);
187 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0);
188 bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
191 bf_set(wqe_cmd_type, &wqe->fcp_icmd.wqe_com, FCP_COMMAND);
192 bf_set(wqe_cqid, &wqe->fcp_icmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
193 bf_set(wqe_pbde, &wqe->fcp_icmd.wqe_com, 0);
195 /* Word 12, 13, 14, 15 - is zero */
199 * lpfc_nvme_create_queue -
200 * @lpfc_pnvme: Pointer to the driver's nvme instance data
201 * @qidx: An cpu index used to affinitize IO queues and MSIX vectors.
202 * @handle: An opaque driver handle used in follow-up calls.
204 * Driver registers this routine to preallocate and initialize any
205 * internal data structures to bind the @qidx to its internal IO queues.
206 * A hardware queue maps (qidx) to a specific driver MSI-X vector/EQ/CQ/WQ.
210 * -EINVAL - Unsupported input value.
211 * -ENOMEM - Could not alloc necessary memory
214 lpfc_nvme_create_queue(struct nvme_fc_local_port *pnvme_lport,
215 unsigned int qidx, u16 qsize,
218 struct lpfc_nvme_lport *lport;
219 struct lpfc_vport *vport;
220 struct lpfc_nvme_qhandle *qhandle;
223 if (!pnvme_lport->private)
226 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
227 vport = lport->vport;
228 qhandle = kzalloc(sizeof(struct lpfc_nvme_qhandle), GFP_KERNEL);
232 qhandle->cpu_id = smp_processor_id();
233 qhandle->qidx = qidx;
235 * NVME qidx == 0 is the admin queue, so both admin queue
236 * and first IO queue will use MSI-X vector and associated
237 * EQ/CQ/WQ at index 0. After that they are sequentially assigned.
240 str = "IO "; /* IO queue */
241 qhandle->index = ((qidx - 1) %
242 vport->phba->cfg_nvme_io_channel);
244 str = "ADM"; /* Admin queue */
245 qhandle->index = qidx;
248 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
249 "6073 Binding %s HdwQueue %d (cpu %d) to "
250 "io_channel %d qhandle %p\n", str,
251 qidx, qhandle->cpu_id, qhandle->index, qhandle);
252 *handle = (void *)qhandle;
257 * lpfc_nvme_delete_queue -
258 * @lpfc_pnvme: Pointer to the driver's nvme instance data
259 * @qidx: An cpu index used to affinitize IO queues and MSIX vectors.
260 * @handle: An opaque driver handle from lpfc_nvme_create_queue
262 * Driver registers this routine to free
263 * any internal data structures to bind the @qidx to its internal
268 * TODO: What are the failure codes.
271 lpfc_nvme_delete_queue(struct nvme_fc_local_port *pnvme_lport,
275 struct lpfc_nvme_lport *lport;
276 struct lpfc_vport *vport;
278 if (!pnvme_lport->private)
281 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
282 vport = lport->vport;
284 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
285 "6001 ENTER. lpfc_pnvme %p, qidx x%x qhandle %p\n",
286 lport, qidx, handle);
291 lpfc_nvme_localport_delete(struct nvme_fc_local_port *localport)
293 struct lpfc_nvme_lport *lport = localport->private;
295 lpfc_printf_vlog(lport->vport, KERN_INFO, LOG_NVME,
296 "6173 localport %p delete complete\n",
299 /* release any threads waiting for the unreg to complete */
300 if (lport->vport->localport)
301 complete(lport->lport_unreg_cmp);
304 /* lpfc_nvme_remoteport_delete
306 * @remoteport: Pointer to an nvme transport remoteport instance.
308 * This is a template downcall. NVME transport calls this function
309 * when it has completed the unregistration of a previously
310 * registered remoteport.
316 lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport)
318 struct lpfc_nvme_rport *rport = remoteport->private;
319 struct lpfc_vport *vport;
320 struct lpfc_nodelist *ndlp;
330 /* Remove this rport from the lport's list - memory is owned by the
331 * transport. Remove the ndlp reference for the NVME transport before
332 * calling state machine to remove the node.
334 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
335 "6146 remoteport delete of remoteport %p\n",
337 spin_lock_irq(&vport->phba->hbalock);
339 /* The register rebind might have occurred before the delete
340 * downcall. Guard against this race.
342 if (ndlp->upcall_flags & NLP_WAIT_FOR_UNREG) {
344 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
345 spin_unlock_irq(&vport->phba->hbalock);
347 /* Remove original register reference. The host transport
348 * won't reference this rport/remoteport any further.
352 spin_unlock_irq(&vport->phba->hbalock);
360 lpfc_nvme_cmpl_gen_req(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
361 struct lpfc_wcqe_complete *wcqe)
363 struct lpfc_vport *vport = cmdwqe->vport;
364 struct lpfc_nvme_lport *lport;
366 struct nvmefc_ls_req *pnvme_lsreq;
367 struct lpfc_dmabuf *buf_ptr;
368 struct lpfc_nodelist *ndlp;
370 pnvme_lsreq = (struct nvmefc_ls_req *)cmdwqe->context2;
371 status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK;
373 if (vport->localport) {
374 lport = (struct lpfc_nvme_lport *)vport->localport->private;
376 atomic_inc(&lport->fc4NvmeLsCmpls);
378 if (bf_get(lpfc_wcqe_c_xb, wcqe))
379 atomic_inc(&lport->cmpl_ls_xb);
380 atomic_inc(&lport->cmpl_ls_err);
385 ndlp = (struct lpfc_nodelist *)cmdwqe->context1;
386 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
387 "6047 nvme cmpl Enter "
388 "Data %p DID %x Xri: %x status %x reason x%x cmd:%p "
389 "lsreg:%p bmp:%p ndlp:%p\n",
390 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
391 cmdwqe->sli4_xritag, status,
392 (wcqe->parameter & 0xffff),
393 cmdwqe, pnvme_lsreq, cmdwqe->context3, ndlp);
395 lpfc_nvmeio_data(phba, "NVME LS CMPL: xri x%x stat x%x parm x%x\n",
396 cmdwqe->sli4_xritag, status, wcqe->parameter);
398 if (cmdwqe->context3) {
399 buf_ptr = (struct lpfc_dmabuf *)cmdwqe->context3;
400 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
402 cmdwqe->context3 = NULL;
404 if (pnvme_lsreq->done)
405 pnvme_lsreq->done(pnvme_lsreq, status);
407 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
408 "6046 nvme cmpl without done call back? "
409 "Data %p DID %x Xri: %x status %x\n",
410 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
411 cmdwqe->sli4_xritag, status);
414 cmdwqe->context1 = NULL;
416 lpfc_sli_release_iocbq(phba, cmdwqe);
420 lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
421 struct lpfc_dmabuf *inp,
422 struct nvmefc_ls_req *pnvme_lsreq,
423 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
424 struct lpfc_wcqe_complete *),
425 struct lpfc_nodelist *ndlp, uint32_t num_entry,
426 uint32_t tmo, uint8_t retry)
428 struct lpfc_hba *phba = vport->phba;
429 union lpfc_wqe128 *wqe;
430 struct lpfc_iocbq *genwqe;
431 struct ulp_bde64 *bpl;
432 struct ulp_bde64 bde;
433 int i, rc, xmit_len, first_len;
435 /* Allocate buffer for command WQE */
436 genwqe = lpfc_sli_get_iocbq(phba);
441 memset(wqe, 0, sizeof(union lpfc_wqe));
443 genwqe->context3 = (uint8_t *)bmp;
444 genwqe->iocb_flag |= LPFC_IO_NVME_LS;
446 /* Save for completion so we can release these resources */
447 genwqe->context1 = lpfc_nlp_get(ndlp);
448 genwqe->context2 = (uint8_t *)pnvme_lsreq;
449 /* Fill in payload, bp points to frame payload */
452 /* FC spec states we need 3 * ratov for CT requests */
453 tmo = (3 * phba->fc_ratov);
455 /* For this command calculate the xmit length of the request bde. */
458 bpl = (struct ulp_bde64 *)bmp->virt;
459 for (i = 0; i < num_entry; i++) {
460 bde.tus.w = bpl[i].tus.w;
461 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
463 xmit_len += bde.tus.f.bdeSize;
465 first_len = xmit_len;
468 genwqe->rsvd2 = num_entry;
469 genwqe->hba_wqidx = 0;
472 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
473 wqe->generic.bde.tus.f.bdeSize = first_len;
474 wqe->generic.bde.addrLow = bpl[0].addrLow;
475 wqe->generic.bde.addrHigh = bpl[0].addrHigh;
478 wqe->gen_req.request_payload_len = first_len;
483 bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0);
484 bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1);
485 bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1);
486 bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_ELS4_REQ);
487 bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME);
490 bf_set(wqe_ctxt_tag, &wqe->gen_req.wqe_com,
491 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
492 bf_set(wqe_xri_tag, &wqe->gen_req.wqe_com, genwqe->sli4_xritag);
495 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, (vport->phba->fc_ratov-1));
496 bf_set(wqe_class, &wqe->gen_req.wqe_com, CLASS3);
497 bf_set(wqe_cmnd, &wqe->gen_req.wqe_com, CMD_GEN_REQUEST64_WQE);
498 bf_set(wqe_ct, &wqe->gen_req.wqe_com, SLI4_CT_RPI);
501 wqe->gen_req.wqe_com.abort_tag = genwqe->iotag;
504 bf_set(wqe_reqtag, &wqe->gen_req.wqe_com, genwqe->iotag);
507 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
508 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
509 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
510 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
511 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
514 bf_set(wqe_cqid, &wqe->gen_req.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
515 bf_set(wqe_cmd_type, &wqe->gen_req.wqe_com, OTHER_COMMAND);
518 /* Issue GEN REQ WQE for NPORT <did> */
519 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
520 "6050 Issue GEN REQ WQE to NPORT x%x "
521 "Data: x%x x%x wq:%p lsreq:%p bmp:%p xmit:%d 1st:%d\n",
522 ndlp->nlp_DID, genwqe->iotag,
524 genwqe, pnvme_lsreq, bmp, xmit_len, first_len);
525 genwqe->wqe_cmpl = cmpl;
526 genwqe->iocb_cmpl = NULL;
527 genwqe->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT;
528 genwqe->vport = vport;
529 genwqe->retry = retry;
531 lpfc_nvmeio_data(phba, "NVME LS XMIT: xri x%x iotag x%x to x%06x\n",
532 genwqe->sli4_xritag, genwqe->iotag, ndlp->nlp_DID);
534 rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, genwqe);
536 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
537 "6045 Issue GEN REQ WQE to NPORT x%x "
539 ndlp->nlp_DID, genwqe->iotag,
541 lpfc_sli_release_iocbq(phba, genwqe);
548 * lpfc_nvme_ls_req - Issue an Link Service request
549 * @lpfc_pnvme: Pointer to the driver's nvme instance data
550 * @lpfc_nvme_lport: Pointer to the driver's local port data
551 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
553 * Driver registers this routine to handle any link service request
554 * from the nvme_fc transport to a remote nvme-aware port.
558 * TODO: What are the failure codes.
561 lpfc_nvme_ls_req(struct nvme_fc_local_port *pnvme_lport,
562 struct nvme_fc_remote_port *pnvme_rport,
563 struct nvmefc_ls_req *pnvme_lsreq)
566 struct lpfc_nvme_lport *lport;
567 struct lpfc_nvme_rport *rport;
568 struct lpfc_vport *vport;
569 struct lpfc_nodelist *ndlp;
570 struct ulp_bde64 *bpl;
571 struct lpfc_dmabuf *bmp;
572 uint16_t ntype, nstate;
574 /* there are two dma buf in the request, actually there is one and
575 * the second one is just the start address + cmd size.
576 * Before calling lpfc_nvme_gen_req these buffers need to be wrapped
577 * in a lpfc_dmabuf struct. When freeing we just free the wrapper
578 * because the nvem layer owns the data bufs.
579 * We do not have to break these packets open, we don't care what is in
580 * them. And we do not have to look at the resonse data, we only care
581 * that we got a response. All of the caring is going to happen in the
585 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
586 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
587 if (unlikely(!lport) || unlikely(!rport))
590 vport = lport->vport;
592 if (vport->load_flag & FC_UNLOADING)
595 /* Need the ndlp. It is stored in the driver's rport. */
597 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
598 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
599 "6051 Remoteport %p, rport has invalid ndlp. "
600 "Failing LS Req\n", pnvme_rport);
604 /* The remote node has to be a mapped nvme target or an
605 * unmapped nvme initiator or it's an error.
607 ntype = ndlp->nlp_type;
608 nstate = ndlp->nlp_state;
609 if ((ntype & NLP_NVME_TARGET && nstate != NLP_STE_MAPPED_NODE) ||
610 (ntype & NLP_NVME_INITIATOR && nstate != NLP_STE_UNMAPPED_NODE)) {
611 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
612 "6088 DID x%06x not ready for "
613 "IO. State x%x, Type x%x\n",
614 pnvme_rport->port_id,
615 ndlp->nlp_state, ndlp->nlp_type);
618 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
621 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
622 "6044 Could not find node for DID %x\n",
623 pnvme_rport->port_id);
626 INIT_LIST_HEAD(&bmp->list);
627 bmp->virt = lpfc_mbuf_alloc(vport->phba, MEM_PRI, &(bmp->phys));
629 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
630 "6042 Could not find node for DID %x\n",
631 pnvme_rport->port_id);
635 bpl = (struct ulp_bde64 *)bmp->virt;
636 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rqstdma));
637 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rqstdma));
638 bpl->tus.f.bdeFlags = 0;
639 bpl->tus.f.bdeSize = pnvme_lsreq->rqstlen;
640 bpl->tus.w = le32_to_cpu(bpl->tus.w);
643 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rspdma));
644 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rspdma));
645 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
646 bpl->tus.f.bdeSize = pnvme_lsreq->rsplen;
647 bpl->tus.w = le32_to_cpu(bpl->tus.w);
649 /* Expand print to include key fields. */
650 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
651 "6149 Issue LS Req to DID 0x%06x lport %p, rport %p "
652 "lsreq%p rqstlen:%d rsplen:%d %pad %pad\n",
654 pnvme_lport, pnvme_rport,
655 pnvme_lsreq, pnvme_lsreq->rqstlen,
656 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
657 &pnvme_lsreq->rspdma);
659 atomic_inc(&lport->fc4NvmeLsRequests);
661 /* Hardcode the wait to 30 seconds. Connections are failing otherwise.
662 * This code allows it all to work.
664 ret = lpfc_nvme_gen_req(vport, bmp, pnvme_lsreq->rqstaddr,
665 pnvme_lsreq, lpfc_nvme_cmpl_gen_req,
667 if (ret != WQE_SUCCESS) {
668 atomic_inc(&lport->xmt_ls_err);
669 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
670 "6052 EXIT. issue ls wqe failed lport %p, "
671 "rport %p lsreq%p Status %x DID %x\n",
672 pnvme_lport, pnvme_rport, pnvme_lsreq,
674 lpfc_mbuf_free(vport->phba, bmp->virt, bmp->phys);
679 /* Stub in routine and return 0 for now. */
684 * lpfc_nvme_ls_abort - Issue an Link Service request
685 * @lpfc_pnvme: Pointer to the driver's nvme instance data
686 * @lpfc_nvme_lport: Pointer to the driver's local port data
687 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
689 * Driver registers this routine to handle any link service request
690 * from the nvme_fc transport to a remote nvme-aware port.
694 * TODO: What are the failure codes.
697 lpfc_nvme_ls_abort(struct nvme_fc_local_port *pnvme_lport,
698 struct nvme_fc_remote_port *pnvme_rport,
699 struct nvmefc_ls_req *pnvme_lsreq)
701 struct lpfc_nvme_lport *lport;
702 struct lpfc_vport *vport;
703 struct lpfc_hba *phba;
704 struct lpfc_nodelist *ndlp;
705 LIST_HEAD(abort_list);
706 struct lpfc_sli_ring *pring;
707 struct lpfc_iocbq *wqe, *next_wqe;
709 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
710 if (unlikely(!lport))
712 vport = lport->vport;
715 if (vport->load_flag & FC_UNLOADING)
718 ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id);
720 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
721 "6049 Could not find node for DID %x\n",
722 pnvme_rport->port_id);
726 /* Expand print to include key fields. */
727 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
728 "6040 ENTER. lport %p, rport %p lsreq %p rqstlen:%d "
729 "rsplen:%d %pad %pad\n",
730 pnvme_lport, pnvme_rport,
731 pnvme_lsreq, pnvme_lsreq->rqstlen,
732 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
733 &pnvme_lsreq->rspdma);
736 * Lock the ELS ring txcmplq and build a local list of all ELS IOs
737 * that need an ABTS. The IOs need to stay on the txcmplq so that
738 * the abort operation completes them successfully.
740 pring = phba->sli4_hba.nvmels_wq->pring;
741 spin_lock_irq(&phba->hbalock);
742 spin_lock(&pring->ring_lock);
743 list_for_each_entry_safe(wqe, next_wqe, &pring->txcmplq, list) {
744 /* Add to abort_list on on NDLP match. */
745 if (lpfc_check_sli_ndlp(phba, pring, wqe, ndlp)) {
746 wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
747 list_add_tail(&wqe->dlist, &abort_list);
750 spin_unlock(&pring->ring_lock);
751 spin_unlock_irq(&phba->hbalock);
753 /* Abort the targeted IOs and remove them from the abort list. */
754 list_for_each_entry_safe(wqe, next_wqe, &abort_list, dlist) {
755 atomic_inc(&lport->xmt_ls_abort);
756 spin_lock_irq(&phba->hbalock);
757 list_del_init(&wqe->dlist);
758 lpfc_sli_issue_abort_iotag(phba, pring, wqe);
759 spin_unlock_irq(&phba->hbalock);
763 /* Fix up the existing sgls for NVME IO. */
765 lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport,
766 struct lpfc_nvme_buf *lpfc_ncmd,
767 struct nvmefc_fcp_req *nCmd)
769 struct lpfc_hba *phba = vport->phba;
770 struct sli4_sge *sgl;
771 union lpfc_wqe128 *wqe;
772 uint32_t *wptr, *dptr;
775 * Get a local pointer to the built-in wqe and correct
776 * the cmd size to match NVME's 96 bytes and fix
780 wqe = &lpfc_ncmd->cur_iocbq.wqe;
783 * Adjust the FCP_CMD and FCP_RSP DMA data and sge_len to
784 * match NVME. NVME sends 96 bytes. Also, use the
785 * nvme commands command and response dma addresses
786 * rather than the virtual memory to ease the restore
789 sgl = lpfc_ncmd->nvme_sgl;
790 sgl->sge_len = cpu_to_le32(nCmd->cmdlen);
791 if (phba->cfg_nvme_embed_cmd) {
795 /* Word 0-2 - NVME CMND IU (embedded payload) */
796 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_IMMED;
797 wqe->generic.bde.tus.f.bdeSize = 56;
798 wqe->generic.bde.addrHigh = 0;
799 wqe->generic.bde.addrLow = 64; /* Word 16 */
801 /* Word 10 - dbde is 0, wqes is 1 in template */
804 * Embed the payload in the last half of the WQE
805 * WQE words 16-30 get the NVME CMD IU payload
807 * WQE words 16-19 get payload Words 1-4
808 * WQE words 20-21 get payload Words 6-7
809 * WQE words 22-29 get payload Words 16-23
811 wptr = &wqe->words[16]; /* WQE ptr */
812 dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */
813 dptr++; /* Skip Word 0 in payload */
815 *wptr++ = *dptr++; /* Word 1 */
816 *wptr++ = *dptr++; /* Word 2 */
817 *wptr++ = *dptr++; /* Word 3 */
818 *wptr++ = *dptr++; /* Word 4 */
819 dptr++; /* Skip Word 5 in payload */
820 *wptr++ = *dptr++; /* Word 6 */
821 *wptr++ = *dptr++; /* Word 7 */
822 dptr += 8; /* Skip Words 8-15 in payload */
823 *wptr++ = *dptr++; /* Word 16 */
824 *wptr++ = *dptr++; /* Word 17 */
825 *wptr++ = *dptr++; /* Word 18 */
826 *wptr++ = *dptr++; /* Word 19 */
827 *wptr++ = *dptr++; /* Word 20 */
828 *wptr++ = *dptr++; /* Word 21 */
829 *wptr++ = *dptr++; /* Word 22 */
830 *wptr = *dptr; /* Word 23 */
832 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->cmddma));
833 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->cmddma));
835 /* Word 0-2 - NVME CMND IU Inline BDE */
836 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
837 wqe->generic.bde.tus.f.bdeSize = nCmd->cmdlen;
838 wqe->generic.bde.addrHigh = sgl->addr_hi;
839 wqe->generic.bde.addrLow = sgl->addr_lo;
842 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
843 bf_set(wqe_wqes, &wqe->generic.wqe_com, 0);
848 /* Setup the physical region for the FCP RSP */
849 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->rspdma));
850 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->rspdma));
851 sgl->word2 = le32_to_cpu(sgl->word2);
853 bf_set(lpfc_sli4_sge_last, sgl, 0);
855 bf_set(lpfc_sli4_sge_last, sgl, 1);
856 sgl->word2 = cpu_to_le32(sgl->word2);
857 sgl->sge_len = cpu_to_le32(nCmd->rsplen);
860 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
862 lpfc_nvme_ktime(struct lpfc_hba *phba,
863 struct lpfc_nvme_buf *lpfc_ncmd)
865 uint64_t seg1, seg2, seg3, seg4;
868 if (!lpfc_ncmd->ts_last_cmd ||
869 !lpfc_ncmd->ts_cmd_start ||
870 !lpfc_ncmd->ts_cmd_wqput ||
871 !lpfc_ncmd->ts_isr_cmpl ||
872 !lpfc_ncmd->ts_data_nvme)
875 if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_cmd_start)
877 if (lpfc_ncmd->ts_cmd_start < lpfc_ncmd->ts_last_cmd)
879 if (lpfc_ncmd->ts_cmd_wqput < lpfc_ncmd->ts_cmd_start)
881 if (lpfc_ncmd->ts_isr_cmpl < lpfc_ncmd->ts_cmd_wqput)
883 if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_isr_cmpl)
886 * Segment 1 - Time from Last FCP command cmpl is handed
887 * off to NVME Layer to start of next command.
888 * Segment 2 - Time from Driver receives a IO cmd start
889 * from NVME Layer to WQ put is done on IO cmd.
890 * Segment 3 - Time from Driver WQ put is done on IO cmd
891 * to MSI-X ISR for IO cmpl.
892 * Segment 4 - Time from MSI-X ISR for IO cmpl to when
893 * cmpl is handled off to the NVME Layer.
895 seg1 = lpfc_ncmd->ts_cmd_start - lpfc_ncmd->ts_last_cmd;
896 if (seg1 > 5000000) /* 5 ms - for sequential IOs only */
899 /* Calculate times relative to start of IO */
900 seg2 = (lpfc_ncmd->ts_cmd_wqput - lpfc_ncmd->ts_cmd_start);
902 seg3 = lpfc_ncmd->ts_isr_cmpl - lpfc_ncmd->ts_cmd_start;
908 seg4 = lpfc_ncmd->ts_data_nvme - lpfc_ncmd->ts_cmd_start;
913 phba->ktime_data_samples++;
914 phba->ktime_seg1_total += seg1;
915 if (seg1 < phba->ktime_seg1_min)
916 phba->ktime_seg1_min = seg1;
917 else if (seg1 > phba->ktime_seg1_max)
918 phba->ktime_seg1_max = seg1;
919 phba->ktime_seg2_total += seg2;
920 if (seg2 < phba->ktime_seg2_min)
921 phba->ktime_seg2_min = seg2;
922 else if (seg2 > phba->ktime_seg2_max)
923 phba->ktime_seg2_max = seg2;
924 phba->ktime_seg3_total += seg3;
925 if (seg3 < phba->ktime_seg3_min)
926 phba->ktime_seg3_min = seg3;
927 else if (seg3 > phba->ktime_seg3_max)
928 phba->ktime_seg3_max = seg3;
929 phba->ktime_seg4_total += seg4;
930 if (seg4 < phba->ktime_seg4_min)
931 phba->ktime_seg4_min = seg4;
932 else if (seg4 > phba->ktime_seg4_max)
933 phba->ktime_seg4_max = seg4;
935 lpfc_ncmd->ts_last_cmd = 0;
936 lpfc_ncmd->ts_cmd_start = 0;
937 lpfc_ncmd->ts_cmd_wqput = 0;
938 lpfc_ncmd->ts_isr_cmpl = 0;
939 lpfc_ncmd->ts_data_nvme = 0;
944 * lpfc_nvme_io_cmd_wqe_cmpl - Complete an NVME-over-FCP IO
945 * @lpfc_pnvme: Pointer to the driver's nvme instance data
946 * @lpfc_nvme_lport: Pointer to the driver's local port data
947 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
949 * Driver registers this routine as it io request handler. This
950 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
951 * data structure to the rport indicated in @lpfc_nvme_rport.
955 * TODO: What are the failure codes.
958 lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
959 struct lpfc_wcqe_complete *wcqe)
961 struct lpfc_nvme_buf *lpfc_ncmd =
962 (struct lpfc_nvme_buf *)pwqeIn->context1;
963 struct lpfc_vport *vport = pwqeIn->vport;
964 struct nvmefc_fcp_req *nCmd;
965 struct nvme_fc_ersp_iu *ep;
966 struct nvme_fc_cmd_iu *cp;
967 struct lpfc_nvme_rport *rport;
968 struct lpfc_nodelist *ndlp;
969 struct lpfc_nvme_fcpreq_priv *freqpriv;
970 struct lpfc_nvme_lport *lport;
971 struct lpfc_nvme_ctrl_stat *cstat;
973 uint32_t code, status, idx;
974 uint16_t cid, sqhd, data;
977 /* Sanity check on return of outstanding command */
978 if (!lpfc_ncmd || !lpfc_ncmd->nvmeCmd || !lpfc_ncmd->nrport) {
980 lpfc_printf_vlog(vport, KERN_ERR,
981 LOG_NODE | LOG_NVME_IOERR,
982 "6071 Null lpfc_ncmd pointer. No "
983 "release, skip completion\n");
987 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
988 "6066 Missing cmpl ptrs: lpfc_ncmd %p, "
989 "nvmeCmd %p nrport %p\n",
990 lpfc_ncmd, lpfc_ncmd->nvmeCmd,
993 /* Release the lpfc_ncmd regardless of the missing elements. */
994 lpfc_release_nvme_buf(phba, lpfc_ncmd);
997 nCmd = lpfc_ncmd->nvmeCmd;
998 rport = lpfc_ncmd->nrport;
999 status = bf_get(lpfc_wcqe_c_status, wcqe);
1001 if (vport->localport) {
1002 lport = (struct lpfc_nvme_lport *)vport->localport->private;
1004 idx = lpfc_ncmd->cur_iocbq.hba_wqidx;
1005 cstat = &lport->cstat[idx];
1006 atomic_inc(&cstat->fc4NvmeIoCmpls);
1008 if (bf_get(lpfc_wcqe_c_xb, wcqe))
1009 atomic_inc(&lport->cmpl_fcp_xb);
1010 atomic_inc(&lport->cmpl_fcp_err);
1015 lpfc_nvmeio_data(phba, "NVME FCP CMPL: xri x%x stat x%x parm x%x\n",
1016 lpfc_ncmd->cur_iocbq.sli4_xritag,
1017 status, wcqe->parameter);
1019 * Catch race where our node has transitioned, but the
1020 * transport is still transitioning.
1023 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1024 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
1025 "6061 rport %p, DID x%06x node not ready.\n",
1026 rport, rport->remoteport->port_id);
1028 ndlp = lpfc_findnode_did(vport, rport->remoteport->port_id);
1030 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1031 "6062 Ignoring NVME cmpl. No ndlp\n");
1036 code = bf_get(lpfc_wcqe_c_code, wcqe);
1037 if (code == CQE_CODE_NVME_ERSP) {
1038 /* For this type of CQE, we need to rebuild the rsp */
1039 ep = (struct nvme_fc_ersp_iu *)nCmd->rspaddr;
1042 * Get Command Id from cmd to plug into response. This
1043 * code is not needed in the next NVME Transport drop.
1045 cp = (struct nvme_fc_cmd_iu *)nCmd->cmdaddr;
1046 cid = cp->sqe.common.command_id;
1049 * RSN is in CQE word 2
1050 * SQHD is in CQE Word 3 bits 15:0
1051 * Cmd Specific info is in CQE Word 1
1052 * and in CQE Word 0 bits 15:0
1054 sqhd = bf_get(lpfc_wcqe_c_sqhead, wcqe);
1056 /* Now lets build the NVME ERSP IU */
1057 ep->iu_len = cpu_to_be16(8);
1058 ep->rsn = wcqe->parameter;
1059 ep->xfrd_len = cpu_to_be32(nCmd->payload_length);
1061 ptr = (uint32_t *)&ep->cqe.result.u64;
1062 *ptr++ = wcqe->total_data_placed;
1063 data = bf_get(lpfc_wcqe_c_ersp0, wcqe);
1064 *ptr = (uint32_t)data;
1065 ep->cqe.sq_head = sqhd;
1066 ep->cqe.sq_id = nCmd->sqid;
1067 ep->cqe.command_id = cid;
1070 lpfc_ncmd->status = IOSTAT_SUCCESS;
1071 lpfc_ncmd->result = 0;
1072 nCmd->rcv_rsplen = LPFC_NVME_ERSP_LEN;
1073 nCmd->transferred_length = nCmd->payload_length;
1075 lpfc_ncmd->status = (status & LPFC_IOCB_STATUS_MASK);
1076 lpfc_ncmd->result = (wcqe->parameter & IOERR_PARAM_MASK);
1078 /* For NVME, the only failure path that results in an
1079 * IO error is when the adapter rejects it. All other
1080 * conditions are a success case and resolved by the
1082 * IOSTAT_FCP_RSP_ERROR means:
1083 * 1. Length of data received doesn't match total
1084 * transfer length in WQE
1085 * 2. If the RSP payload does NOT match these cases:
1086 * a. RSP length 12/24 bytes and all zeros
1089 switch (lpfc_ncmd->status) {
1090 case IOSTAT_SUCCESS:
1091 nCmd->transferred_length = wcqe->total_data_placed;
1092 nCmd->rcv_rsplen = 0;
1095 case IOSTAT_FCP_RSP_ERROR:
1096 nCmd->transferred_length = wcqe->total_data_placed;
1097 nCmd->rcv_rsplen = wcqe->parameter;
1100 if (nCmd->rcv_rsplen == LPFC_NVME_ERSP_LEN)
1102 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1103 "6081 NVME Completion Protocol Error: "
1104 "xri %x status x%x result x%x "
1106 lpfc_ncmd->cur_iocbq.sli4_xritag,
1107 lpfc_ncmd->status, lpfc_ncmd->result,
1108 wcqe->total_data_placed);
1110 case IOSTAT_LOCAL_REJECT:
1111 /* Let fall through to set command final state. */
1112 if (lpfc_ncmd->result == IOERR_ABORT_REQUESTED)
1113 lpfc_printf_vlog(vport, KERN_INFO,
1115 "6032 Delay Aborted cmd %p "
1116 "nvme cmd %p, xri x%x, "
1119 lpfc_ncmd->cur_iocbq.sli4_xritag,
1120 bf_get(lpfc_wcqe_c_xb, wcqe));
1123 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1124 "6072 NVME Completion Error: xri %x "
1125 "status x%x result x%x placed x%x\n",
1126 lpfc_ncmd->cur_iocbq.sli4_xritag,
1127 lpfc_ncmd->status, lpfc_ncmd->result,
1128 wcqe->total_data_placed);
1129 nCmd->transferred_length = 0;
1130 nCmd->rcv_rsplen = 0;
1131 nCmd->status = NVME_SC_INTERNAL;
1135 /* pick up SLI4 exhange busy condition */
1136 if (bf_get(lpfc_wcqe_c_xb, wcqe))
1137 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
1139 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
1141 /* Update stats and complete the IO. There is
1142 * no need for dma unprep because the nvme_transport
1143 * owns the dma address.
1145 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1146 if (lpfc_ncmd->ts_cmd_start) {
1147 lpfc_ncmd->ts_isr_cmpl = pwqeIn->isr_timestamp;
1148 lpfc_ncmd->ts_data_nvme = ktime_get_ns();
1149 phba->ktime_last_cmd = lpfc_ncmd->ts_data_nvme;
1150 lpfc_nvme_ktime(phba, lpfc_ncmd);
1152 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) {
1153 if (lpfc_ncmd->cpu != smp_processor_id())
1154 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1155 "6701 CPU Check cmpl: "
1156 "cpu %d expect %d\n",
1157 smp_processor_id(), lpfc_ncmd->cpu);
1158 if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT)
1159 phba->cpucheck_cmpl_io[lpfc_ncmd->cpu]++;
1163 /* NVME targets need completion held off until the abort exchange
1164 * completes unless the NVME Rport is getting unregistered.
1167 if (!(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) {
1168 freqpriv = nCmd->private;
1169 freqpriv->nvme_buf = NULL;
1171 lpfc_ncmd->nvmeCmd = NULL;
1174 spin_lock_irqsave(&phba->hbalock, flags);
1175 lpfc_ncmd->nrport = NULL;
1176 spin_unlock_irqrestore(&phba->hbalock, flags);
1178 /* Call release with XB=1 to queue the IO into the abort list. */
1179 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1184 * lpfc_nvme_prep_io_cmd - Issue an NVME-over-FCP IO
1185 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1186 * @lpfc_nvme_lport: Pointer to the driver's local port data
1187 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1188 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1189 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1191 * Driver registers this routine as it io request handler. This
1192 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1193 * data structure to the rport indicated in @lpfc_nvme_rport.
1197 * TODO: What are the failure codes.
1200 lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport,
1201 struct lpfc_nvme_buf *lpfc_ncmd,
1202 struct lpfc_nodelist *pnode,
1203 struct lpfc_nvme_ctrl_stat *cstat)
1205 struct lpfc_hba *phba = vport->phba;
1206 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1207 struct lpfc_iocbq *pwqeq = &(lpfc_ncmd->cur_iocbq);
1208 union lpfc_wqe128 *wqe = &pwqeq->wqe;
1211 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
1215 * There are three possibilities here - use scatter-gather segment, use
1216 * the single mapping, or neither.
1219 if (nCmd->io_dir == NVMEFC_FCP_WRITE) {
1220 /* From the iwrite template, initialize words 7 - 11 */
1221 memcpy(&wqe->words[7],
1222 &lpfc_iwrite_cmd_template.words[7],
1223 sizeof(uint32_t) * 5);
1226 wqe->fcp_iwrite.total_xfer_len = nCmd->payload_length;
1229 if ((phba->cfg_nvme_enable_fb) &&
1230 (pnode->nlp_flag & NLP_FIRSTBURST)) {
1231 req_len = lpfc_ncmd->nvmeCmd->payload_length;
1232 if (req_len < pnode->nvme_fb_size)
1233 wqe->fcp_iwrite.initial_xfer_len =
1236 wqe->fcp_iwrite.initial_xfer_len =
1237 pnode->nvme_fb_size;
1239 wqe->fcp_iwrite.initial_xfer_len = 0;
1241 atomic_inc(&cstat->fc4NvmeOutputRequests);
1243 /* From the iread template, initialize words 7 - 11 */
1244 memcpy(&wqe->words[7],
1245 &lpfc_iread_cmd_template.words[7],
1246 sizeof(uint32_t) * 5);
1249 wqe->fcp_iread.total_xfer_len = nCmd->payload_length;
1252 wqe->fcp_iread.rsrvd5 = 0;
1254 atomic_inc(&cstat->fc4NvmeInputRequests);
1257 /* From the icmnd template, initialize words 4 - 11 */
1258 memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4],
1259 sizeof(uint32_t) * 8);
1260 atomic_inc(&cstat->fc4NvmeControlRequests);
1263 * Finish initializing those WQE fields that are independent
1264 * of the nvme_cmnd request_buffer
1268 bf_set(payload_offset_len, &wqe->fcp_icmd,
1269 (nCmd->rsplen + nCmd->cmdlen));
1272 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
1273 phba->sli4_hba.rpi_ids[pnode->nlp_rpi]);
1274 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag);
1277 wqe->generic.wqe_com.abort_tag = pwqeq->iotag;
1280 bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag);
1282 /* Words 13 14 15 are for PBDE support */
1284 pwqeq->vport = vport;
1290 * lpfc_nvme_prep_io_dma - Issue an NVME-over-FCP IO
1291 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1292 * @lpfc_nvme_lport: Pointer to the driver's local port data
1293 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1294 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1295 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1297 * Driver registers this routine as it io request handler. This
1298 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1299 * data structure to the rport indicated in @lpfc_nvme_rport.
1303 * TODO: What are the failure codes.
1306 lpfc_nvme_prep_io_dma(struct lpfc_vport *vport,
1307 struct lpfc_nvme_buf *lpfc_ncmd)
1309 struct lpfc_hba *phba = vport->phba;
1310 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1311 union lpfc_wqe128 *wqe = &lpfc_ncmd->cur_iocbq.wqe;
1312 struct sli4_sge *sgl = lpfc_ncmd->nvme_sgl;
1313 struct scatterlist *data_sg;
1314 struct sli4_sge *first_data_sgl;
1315 struct ulp_bde64 *bde;
1316 dma_addr_t physaddr;
1317 uint32_t num_bde = 0;
1319 uint32_t dma_offset = 0;
1322 /* Fix up the command and response DMA stuff. */
1323 lpfc_nvme_adj_fcp_sgls(vport, lpfc_ncmd, nCmd);
1326 * There are three possibilities here - use scatter-gather segment, use
1327 * the single mapping, or neither.
1331 * Jump over the cmd and rsp SGEs. The fix routine
1332 * has already adjusted for this.
1336 first_data_sgl = sgl;
1337 lpfc_ncmd->seg_cnt = nCmd->sg_cnt;
1338 if (lpfc_ncmd->seg_cnt > lpfc_nvme_template.max_sgl_segments) {
1339 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1340 "6058 Too many sg segments from "
1341 "NVME Transport. Max %d, "
1342 "nvmeIO sg_cnt %d\n",
1343 phba->cfg_nvme_seg_cnt + 1,
1344 lpfc_ncmd->seg_cnt);
1345 lpfc_ncmd->seg_cnt = 0;
1350 * The driver established a maximum scatter-gather segment count
1351 * during probe that limits the number of sg elements in any
1352 * single nvme command. Just run through the seg_cnt and format
1355 nseg = nCmd->sg_cnt;
1356 data_sg = nCmd->first_sgl;
1357 for (i = 0; i < nseg; i++) {
1358 if (data_sg == NULL) {
1359 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1360 "6059 dptr err %d, nseg %d\n",
1362 lpfc_ncmd->seg_cnt = 0;
1365 physaddr = data_sg->dma_address;
1366 dma_len = data_sg->length;
1367 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
1368 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
1369 sgl->word2 = le32_to_cpu(sgl->word2);
1370 if ((num_bde + 1) == nseg)
1371 bf_set(lpfc_sli4_sge_last, sgl, 1);
1373 bf_set(lpfc_sli4_sge_last, sgl, 0);
1374 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
1375 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
1376 sgl->word2 = cpu_to_le32(sgl->word2);
1377 sgl->sge_len = cpu_to_le32(dma_len);
1379 dma_offset += dma_len;
1380 data_sg = sg_next(data_sg);
1383 if (phba->cfg_enable_pbde) {
1384 /* Use PBDE support for first SGL only, offset == 0 */
1386 bde = (struct ulp_bde64 *)
1388 bde->addrLow = first_data_sgl->addr_lo;
1389 bde->addrHigh = first_data_sgl->addr_hi;
1390 bde->tus.f.bdeSize =
1391 le32_to_cpu(first_data_sgl->sge_len);
1392 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1393 bde->tus.w = cpu_to_le32(bde->tus.w);
1394 /* wqe_pbde is 1 in template */
1396 memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3));
1397 bf_set(wqe_pbde, &wqe->generic.wqe_com, 0);
1401 /* For this clause to be valid, the payload_length
1402 * and sg_cnt must zero.
1404 if (nCmd->payload_length != 0) {
1405 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1406 "6063 NVME DMA Prep Err: sg_cnt %d "
1407 "payload_length x%x\n",
1408 nCmd->sg_cnt, nCmd->payload_length);
1416 * lpfc_nvme_fcp_io_submit - Issue an NVME-over-FCP IO
1417 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1418 * @lpfc_nvme_lport: Pointer to the driver's local port data
1419 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1420 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1421 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1423 * Driver registers this routine as it io request handler. This
1424 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1425 * data structure to the rport
1426 indicated in @lpfc_nvme_rport.
1430 * TODO: What are the failure codes.
1433 lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
1434 struct nvme_fc_remote_port *pnvme_rport,
1435 void *hw_queue_handle,
1436 struct nvmefc_fcp_req *pnvme_fcreq)
1441 struct lpfc_nvme_lport *lport;
1442 struct lpfc_nvme_ctrl_stat *cstat;
1443 struct lpfc_vport *vport;
1444 struct lpfc_hba *phba;
1445 struct lpfc_nodelist *ndlp;
1446 struct lpfc_nvme_buf *lpfc_ncmd;
1447 struct lpfc_nvme_rport *rport;
1448 struct lpfc_nvme_qhandle *lpfc_queue_info;
1449 struct lpfc_nvme_fcpreq_priv *freqpriv;
1450 struct nvme_common_command *sqe;
1451 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1455 /* Validate pointers. LLDD fault handling with transport does
1456 * have timing races.
1458 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1459 if (unlikely(!lport)) {
1464 vport = lport->vport;
1466 if (unlikely(!hw_queue_handle)) {
1467 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1468 "6117 Fail IO, NULL hw_queue_handle\n");
1469 atomic_inc(&lport->xmt_fcp_err);
1476 if (vport->load_flag & FC_UNLOADING) {
1481 if (vport->load_flag & FC_UNLOADING) {
1482 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1483 "6124 Fail IO, Driver unload\n");
1484 atomic_inc(&lport->xmt_fcp_err);
1489 freqpriv = pnvme_fcreq->private;
1490 if (unlikely(!freqpriv)) {
1491 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1492 "6158 Fail IO, NULL request data\n");
1493 atomic_inc(&lport->xmt_fcp_err);
1498 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1500 start = ktime_get_ns();
1502 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
1503 lpfc_queue_info = (struct lpfc_nvme_qhandle *)hw_queue_handle;
1506 * Catch race where our node has transitioned, but the
1507 * transport is still transitioning.
1510 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1511 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1512 "6053 Fail IO, ndlp not ready: rport %p "
1513 "ndlp %p, DID x%06x\n",
1514 rport, ndlp, pnvme_rport->port_id);
1515 atomic_inc(&lport->xmt_fcp_err);
1520 /* The remote node has to be a mapped target or it's an error. */
1521 if ((ndlp->nlp_type & NLP_NVME_TARGET) &&
1522 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
1523 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1524 "6036 Fail IO, DID x%06x not ready for "
1525 "IO. State x%x, Type x%x Flg x%x\n",
1526 pnvme_rport->port_id,
1527 ndlp->nlp_state, ndlp->nlp_type,
1528 ndlp->upcall_flags);
1529 atomic_inc(&lport->xmt_fcp_bad_ndlp);
1535 /* Currently only NVME Keep alive commands should be expedited
1536 * if the driver runs out of a resource. These should only be
1537 * issued on the admin queue, qidx 0
1539 if (!lpfc_queue_info->qidx && !pnvme_fcreq->sg_cnt) {
1540 sqe = &((struct nvme_fc_cmd_iu *)
1541 pnvme_fcreq->cmdaddr)->sqe.common;
1542 if (sqe->opcode == nvme_admin_keep_alive)
1546 /* The node is shared with FCP IO, make sure the IO pending count does
1547 * not exceed the programmed depth.
1549 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
1550 if ((atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) &&
1552 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1553 "6174 Fail IO, ndlp qdepth exceeded: "
1554 "idx %d DID %x pend %d qdepth %d\n",
1555 lpfc_queue_info->index, ndlp->nlp_DID,
1556 atomic_read(&ndlp->cmd_pending),
1558 atomic_inc(&lport->xmt_fcp_qdepth);
1564 lpfc_ncmd = lpfc_get_nvme_buf(phba, ndlp, expedite);
1565 if (lpfc_ncmd == NULL) {
1566 atomic_inc(&lport->xmt_fcp_noxri);
1567 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1568 "6065 Fail IO, driver buffer pool is empty: "
1570 lpfc_queue_info->index, ndlp->nlp_DID);
1574 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1576 lpfc_ncmd->ts_cmd_start = start;
1577 lpfc_ncmd->ts_last_cmd = phba->ktime_last_cmd;
1579 lpfc_ncmd->ts_cmd_start = 0;
1584 * Store the data needed by the driver to issue, abort, and complete
1586 * Do not let the IO hang out forever. There is no midlayer issuing
1587 * an abort so inform the FW of the maximum IO pending time.
1589 freqpriv->nvme_buf = lpfc_ncmd;
1590 lpfc_ncmd->nvmeCmd = pnvme_fcreq;
1591 lpfc_ncmd->nrport = rport;
1592 lpfc_ncmd->ndlp = ndlp;
1593 lpfc_ncmd->start_time = jiffies;
1596 * Issue the IO on the WQ indicated by index in the hw_queue_handle.
1597 * This identfier was create in our hardware queue create callback
1598 * routine. The driver now is dependent on the IO queue steering from
1599 * the transport. We are trusting the upper NVME layers know which
1600 * index to use and that they have affinitized a CPU to this hardware
1601 * queue. A hardware queue maps to a driver MSI-X vector/EQ/CQ/WQ.
1603 idx = lpfc_queue_info->index;
1604 lpfc_ncmd->cur_iocbq.hba_wqidx = idx;
1605 cstat = &lport->cstat[idx];
1607 lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp, cstat);
1608 ret = lpfc_nvme_prep_io_dma(vport, lpfc_ncmd);
1610 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1611 "6175 Fail IO, Prep DMA: "
1613 lpfc_queue_info->index, ndlp->nlp_DID);
1614 atomic_inc(&lport->xmt_fcp_err);
1616 goto out_free_nvme_buf;
1619 lpfc_nvmeio_data(phba, "NVME FCP XMIT: xri x%x idx %d to %06x\n",
1620 lpfc_ncmd->cur_iocbq.sli4_xritag,
1621 lpfc_queue_info->index, ndlp->nlp_DID);
1623 ret = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, &lpfc_ncmd->cur_iocbq);
1625 atomic_inc(&lport->xmt_fcp_wqerr);
1626 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1627 "6113 Fail IO, Could not issue WQE err %x "
1628 "sid: x%x did: x%x oxid: x%x\n",
1629 ret, vport->fc_myDID, ndlp->nlp_DID,
1630 lpfc_ncmd->cur_iocbq.sli4_xritag);
1631 goto out_free_nvme_buf;
1634 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1635 if (lpfc_ncmd->ts_cmd_start)
1636 lpfc_ncmd->ts_cmd_wqput = ktime_get_ns();
1638 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) {
1639 lpfc_ncmd->cpu = smp_processor_id();
1640 if (lpfc_ncmd->cpu != lpfc_queue_info->index) {
1641 /* Check for admin queue */
1642 if (lpfc_queue_info->qidx) {
1643 lpfc_printf_vlog(vport,
1644 KERN_ERR, LOG_NVME_IOERR,
1645 "6702 CPU Check cmd: "
1648 lpfc_queue_info->index);
1650 lpfc_ncmd->cpu = lpfc_queue_info->index;
1652 if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT)
1653 phba->cpucheck_xmt_io[lpfc_ncmd->cpu]++;
1659 if (lpfc_ncmd->nvmeCmd->sg_cnt) {
1660 if (lpfc_ncmd->nvmeCmd->io_dir == NVMEFC_FCP_WRITE)
1661 atomic_dec(&cstat->fc4NvmeOutputRequests);
1663 atomic_dec(&cstat->fc4NvmeInputRequests);
1665 atomic_dec(&cstat->fc4NvmeControlRequests);
1666 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1672 * lpfc_nvme_abort_fcreq_cmpl - Complete an NVME FCP abort request.
1673 * @phba: Pointer to HBA context object
1674 * @cmdiocb: Pointer to command iocb object.
1675 * @rspiocb: Pointer to response iocb object.
1677 * This is the callback function for any NVME FCP IO that was aborted.
1683 lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1684 struct lpfc_wcqe_complete *abts_cmpl)
1686 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
1687 "6145 ABORT_XRI_CN completing on rpi x%x "
1688 "original iotag x%x, abort cmd iotag x%x "
1689 "req_tag x%x, status x%x, hwstatus x%x\n",
1690 cmdiocb->iocb.un.acxri.abortContextTag,
1691 cmdiocb->iocb.un.acxri.abortIoTag,
1693 bf_get(lpfc_wcqe_c_request_tag, abts_cmpl),
1694 bf_get(lpfc_wcqe_c_status, abts_cmpl),
1695 bf_get(lpfc_wcqe_c_hw_status, abts_cmpl));
1696 lpfc_sli_release_iocbq(phba, cmdiocb);
1700 * lpfc_nvme_fcp_abort - Issue an NVME-over-FCP ABTS
1701 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1702 * @lpfc_nvme_lport: Pointer to the driver's local port data
1703 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1704 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1705 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1707 * Driver registers this routine as its nvme request io abort handler. This
1708 * routine issues an fcp Abort WQE with data from the @lpfc_nvme_fcpreq
1709 * data structure to the rport indicated in @lpfc_nvme_rport. This routine
1710 * is executed asynchronously - one the target is validated as "MAPPED" and
1711 * ready for IO, the driver issues the abort request and returns.
1717 lpfc_nvme_fcp_abort(struct nvme_fc_local_port *pnvme_lport,
1718 struct nvme_fc_remote_port *pnvme_rport,
1719 void *hw_queue_handle,
1720 struct nvmefc_fcp_req *pnvme_fcreq)
1722 struct lpfc_nvme_lport *lport;
1723 struct lpfc_vport *vport;
1724 struct lpfc_hba *phba;
1725 struct lpfc_nvme_buf *lpfc_nbuf;
1726 struct lpfc_iocbq *abts_buf;
1727 struct lpfc_iocbq *nvmereq_wqe;
1728 struct lpfc_nvme_fcpreq_priv *freqpriv;
1729 union lpfc_wqe128 *abts_wqe;
1730 unsigned long flags;
1733 /* Validate pointers. LLDD fault handling with transport does
1734 * have timing races.
1736 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1737 if (unlikely(!lport))
1740 vport = lport->vport;
1742 if (unlikely(!hw_queue_handle)) {
1743 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1744 "6129 Fail Abort, HW Queue Handle NULL.\n");
1749 freqpriv = pnvme_fcreq->private;
1751 if (unlikely(!freqpriv))
1753 if (vport->load_flag & FC_UNLOADING)
1756 /* Announce entry to new IO submit field. */
1757 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1758 "6002 Abort Request to rport DID x%06x "
1759 "for nvme_fc_req %p\n",
1760 pnvme_rport->port_id,
1763 /* If the hba is getting reset, this flag is set. It is
1764 * cleared when the reset is complete and rings reestablished.
1766 spin_lock_irqsave(&phba->hbalock, flags);
1767 /* driver queued commands are in process of being flushed */
1768 if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) {
1769 spin_unlock_irqrestore(&phba->hbalock, flags);
1770 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1771 "6139 Driver in reset cleanup - flushing "
1772 "NVME Req now. hba_flag x%x\n",
1777 lpfc_nbuf = freqpriv->nvme_buf;
1779 spin_unlock_irqrestore(&phba->hbalock, flags);
1780 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1781 "6140 NVME IO req has no matching lpfc nvme "
1782 "io buffer. Skipping abort req.\n");
1784 } else if (!lpfc_nbuf->nvmeCmd) {
1785 spin_unlock_irqrestore(&phba->hbalock, flags);
1786 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1787 "6141 lpfc NVME IO req has no nvme_fcreq "
1788 "io buffer. Skipping abort req.\n");
1791 nvmereq_wqe = &lpfc_nbuf->cur_iocbq;
1794 * The lpfc_nbuf and the mapped nvme_fcreq in the driver's
1795 * state must match the nvme_fcreq passed by the nvme
1796 * transport. If they don't match, it is likely the driver
1797 * has already completed the NVME IO and the nvme transport
1798 * has not seen it yet.
1800 if (lpfc_nbuf->nvmeCmd != pnvme_fcreq) {
1801 spin_unlock_irqrestore(&phba->hbalock, flags);
1802 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1803 "6143 NVME req mismatch: "
1804 "lpfc_nbuf %p nvmeCmd %p, "
1805 "pnvme_fcreq %p. Skipping Abort xri x%x\n",
1806 lpfc_nbuf, lpfc_nbuf->nvmeCmd,
1807 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1811 /* Don't abort IOs no longer on the pending queue. */
1812 if (!(nvmereq_wqe->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
1813 spin_unlock_irqrestore(&phba->hbalock, flags);
1814 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1815 "6142 NVME IO req %p not queued - skipping "
1816 "abort req xri x%x\n",
1817 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1821 atomic_inc(&lport->xmt_fcp_abort);
1822 lpfc_nvmeio_data(phba, "NVME FCP ABORT: xri x%x idx %d to %06x\n",
1823 nvmereq_wqe->sli4_xritag,
1824 nvmereq_wqe->hba_wqidx, pnvme_rport->port_id);
1826 /* Outstanding abort is in progress */
1827 if (nvmereq_wqe->iocb_flag & LPFC_DRIVER_ABORTED) {
1828 spin_unlock_irqrestore(&phba->hbalock, flags);
1829 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1830 "6144 Outstanding NVME I/O Abort Request "
1831 "still pending on nvme_fcreq %p, "
1832 "lpfc_ncmd %p xri x%x\n",
1833 pnvme_fcreq, lpfc_nbuf,
1834 nvmereq_wqe->sli4_xritag);
1838 abts_buf = __lpfc_sli_get_iocbq(phba);
1840 spin_unlock_irqrestore(&phba->hbalock, flags);
1841 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1842 "6136 No available abort wqes. Skipping "
1843 "Abts req for nvme_fcreq %p xri x%x\n",
1844 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1848 /* Ready - mark outstanding as aborted by driver. */
1849 nvmereq_wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
1851 /* Complete prepping the abort wqe and issue to the FW. */
1852 abts_wqe = &abts_buf->wqe;
1854 /* WQEs are reused. Clear stale data and set key fields to
1855 * zero like ia, iaab, iaar, xri_tag, and ctxt_tag.
1857 memset(abts_wqe, 0, sizeof(union lpfc_wqe));
1858 bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG);
1861 bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
1862 bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com,
1863 nvmereq_wqe->iocb.ulpClass);
1865 /* word 8 - tell the FW to abort the IO associated with this
1866 * outstanding exchange ID.
1868 abts_wqe->abort_cmd.wqe_com.abort_tag = nvmereq_wqe->sli4_xritag;
1870 /* word 9 - this is the iotag for the abts_wqe completion. */
1871 bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com,
1875 bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1);
1876 bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
1879 bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND);
1880 bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1);
1881 bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
1883 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
1884 abts_buf->iocb_flag |= LPFC_IO_NVME;
1885 abts_buf->hba_wqidx = nvmereq_wqe->hba_wqidx;
1886 abts_buf->vport = vport;
1887 abts_buf->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl;
1888 ret_val = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_buf);
1889 spin_unlock_irqrestore(&phba->hbalock, flags);
1891 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1892 "6137 Failed abts issue_wqe with status x%x "
1893 "for nvme_fcreq %p.\n",
1894 ret_val, pnvme_fcreq);
1895 lpfc_sli_release_iocbq(phba, abts_buf);
1899 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1900 "6138 Transport Abort NVME Request Issued for "
1901 "ox_id x%x on reqtag x%x\n",
1902 nvmereq_wqe->sli4_xritag,
1906 /* Declare and initialization an instance of the FC NVME template. */
1907 static struct nvme_fc_port_template lpfc_nvme_template = {
1908 /* initiator-based functions */
1909 .localport_delete = lpfc_nvme_localport_delete,
1910 .remoteport_delete = lpfc_nvme_remoteport_delete,
1911 .create_queue = lpfc_nvme_create_queue,
1912 .delete_queue = lpfc_nvme_delete_queue,
1913 .ls_req = lpfc_nvme_ls_req,
1914 .fcp_io = lpfc_nvme_fcp_io_submit,
1915 .ls_abort = lpfc_nvme_ls_abort,
1916 .fcp_abort = lpfc_nvme_fcp_abort,
1919 .max_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1920 .max_dif_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1921 .dma_boundary = 0xFFFFFFFF,
1923 /* Sizes of additional private data for data structures.
1924 * No use for the last two sizes at this time.
1926 .local_priv_sz = sizeof(struct lpfc_nvme_lport),
1927 .remote_priv_sz = sizeof(struct lpfc_nvme_rport),
1928 .lsrqst_priv_sz = 0,
1929 .fcprqst_priv_sz = sizeof(struct lpfc_nvme_fcpreq_priv),
1933 * lpfc_sli4_post_nvme_sgl_block - post a block of nvme sgl list to firmware
1934 * @phba: pointer to lpfc hba data structure.
1935 * @nblist: pointer to nvme buffer list.
1936 * @count: number of scsi buffers on the list.
1938 * This routine is invoked to post a block of @count scsi sgl pages from a
1939 * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
1944 lpfc_sli4_post_nvme_sgl_block(struct lpfc_hba *phba,
1945 struct list_head *nblist,
1948 struct lpfc_nvme_buf *lpfc_ncmd;
1949 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
1950 struct sgl_page_pairs *sgl_pg_pairs;
1953 uint32_t reqlen, alloclen, pg_pairs;
1955 uint16_t xritag_start = 0;
1957 uint32_t shdr_status, shdr_add_status;
1958 dma_addr_t pdma_phys_bpl1;
1959 union lpfc_sli4_cfg_shdr *shdr;
1961 /* Calculate the requested length of the dma memory */
1962 reqlen = count * sizeof(struct sgl_page_pairs) +
1963 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
1964 if (reqlen > SLI4_PAGE_SIZE) {
1965 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1966 "6118 Block sgl registration required DMA "
1967 "size (%d) great than a page\n", reqlen);
1970 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1972 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1973 "6119 Failed to allocate mbox cmd memory\n");
1977 /* Allocate DMA memory and set up the non-embedded mailbox command */
1978 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1979 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
1980 LPFC_SLI4_MBX_NEMBED);
1982 if (alloclen < reqlen) {
1983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1984 "6120 Allocated DMA memory size (%d) is "
1985 "less than the requested DMA memory "
1986 "size (%d)\n", alloclen, reqlen);
1987 lpfc_sli4_mbox_cmd_free(phba, mbox);
1991 /* Get the first SGE entry from the non-embedded DMA memory */
1992 viraddr = mbox->sge_array->addr[0];
1994 /* Set up the SGL pages in the non-embedded DMA pages */
1995 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
1996 sgl_pg_pairs = &sgl->sgl_pg_pairs;
1999 list_for_each_entry(lpfc_ncmd, nblist, list) {
2000 /* Set up the sge entry */
2001 sgl_pg_pairs->sgl_pg0_addr_lo =
2002 cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
2003 sgl_pg_pairs->sgl_pg0_addr_hi =
2004 cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
2005 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
2006 pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
2010 sgl_pg_pairs->sgl_pg1_addr_lo =
2011 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
2012 sgl_pg_pairs->sgl_pg1_addr_hi =
2013 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
2014 /* Keep the first xritag on the list */
2016 xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
2020 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
2021 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
2022 /* Perform endian conversion if necessary */
2023 sgl->word0 = cpu_to_le32(sgl->word0);
2025 if (!phba->sli4_hba.intr_enable)
2026 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
2028 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
2029 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
2031 shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
2032 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2033 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2034 if (rc != MBX_TIMEOUT)
2035 lpfc_sli4_mbox_cmd_free(phba, mbox);
2036 if (shdr_status || shdr_add_status || rc) {
2037 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2038 "6125 POST_SGL_BLOCK mailbox command failed "
2039 "status x%x add_status x%x mbx status x%x\n",
2040 shdr_status, shdr_add_status, rc);
2047 * lpfc_post_nvme_sgl_list - Post blocks of nvme buffer sgls from a list
2048 * @phba: pointer to lpfc hba data structure.
2049 * @post_nblist: pointer to the nvme buffer list.
2051 * This routine walks a list of nvme buffers that was passed in. It attempts
2052 * to construct blocks of nvme buffer sgls which contains contiguous xris and
2053 * uses the non-embedded SGL block post mailbox commands to post to the port.
2054 * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
2055 * embedded SGL post mailbox command for posting. The @post_nblist passed in
2056 * must be local list, thus no lock is needed when manipulate the list.
2058 * Returns: 0 = failure, non-zero number of successfully posted buffers.
2061 lpfc_post_nvme_sgl_list(struct lpfc_hba *phba,
2062 struct list_head *post_nblist, int sb_count)
2064 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
2065 int status, sgl_size;
2066 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
2067 dma_addr_t pdma_phys_sgl1;
2068 int last_xritag = NO_XRI;
2070 LIST_HEAD(prep_nblist);
2071 LIST_HEAD(blck_nblist);
2072 LIST_HEAD(nvme_nblist);
2078 sgl_size = phba->cfg_sg_dma_buf_size;
2080 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
2081 list_del_init(&lpfc_ncmd->list);
2083 if ((last_xritag != NO_XRI) &&
2084 (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
2085 /* a hole in xri block, form a sgl posting block */
2086 list_splice_init(&prep_nblist, &blck_nblist);
2087 post_cnt = block_cnt - 1;
2088 /* prepare list for next posting block */
2089 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
2092 /* prepare list for next posting block */
2093 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
2094 /* enough sgls for non-embed sgl mbox command */
2095 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
2096 list_splice_init(&prep_nblist, &blck_nblist);
2097 post_cnt = block_cnt;
2102 last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
2104 /* end of repost sgl list condition for NVME buffers */
2105 if (num_posting == sb_count) {
2106 if (post_cnt == 0) {
2107 /* last sgl posting block */
2108 list_splice_init(&prep_nblist, &blck_nblist);
2109 post_cnt = block_cnt;
2110 } else if (block_cnt == 1) {
2111 /* last single sgl with non-contiguous xri */
2112 if (sgl_size > SGL_PAGE_SIZE)
2114 lpfc_ncmd->dma_phys_sgl +
2118 cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
2119 status = lpfc_sli4_post_sgl(phba,
2120 lpfc_ncmd->dma_phys_sgl,
2121 pdma_phys_sgl1, cur_xritag);
2123 /* failure, put on abort nvme list */
2124 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
2126 /* success, put on NVME buffer list */
2127 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2128 lpfc_ncmd->status = IOSTAT_SUCCESS;
2131 /* success, put on NVME buffer sgl list */
2132 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
2136 /* continue until a nembed page worth of sgls */
2140 /* post block of NVME buffer list sgls */
2141 status = lpfc_sli4_post_nvme_sgl_block(phba, &blck_nblist,
2144 /* don't reset xirtag due to hole in xri block */
2146 last_xritag = NO_XRI;
2148 /* reset NVME buffer post count for next round of posting */
2151 /* put posted NVME buffer-sgl posted on NVME buffer sgl list */
2152 while (!list_empty(&blck_nblist)) {
2153 list_remove_head(&blck_nblist, lpfc_ncmd,
2154 struct lpfc_nvme_buf, list);
2156 /* failure, put on abort nvme list */
2157 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
2159 /* success, put on NVME buffer list */
2160 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2161 lpfc_ncmd->status = IOSTAT_SUCCESS;
2164 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
2167 /* Push NVME buffers with sgl posted to the available list */
2168 while (!list_empty(&nvme_nblist)) {
2169 list_remove_head(&nvme_nblist, lpfc_ncmd,
2170 struct lpfc_nvme_buf, list);
2171 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2177 * lpfc_repost_nvme_sgl_list - Repost all the allocated nvme buffer sgls
2178 * @phba: pointer to lpfc hba data structure.
2180 * This routine walks the list of nvme buffers that have been allocated and
2181 * repost them to the port by using SGL block post. This is needed after a
2182 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
2183 * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
2184 * to the lpfc_nvme_buf_list. If the repost fails, reject all nvme buffers.
2186 * Returns: 0 = success, non-zero failure.
2189 lpfc_repost_nvme_sgl_list(struct lpfc_hba *phba)
2191 LIST_HEAD(post_nblist);
2192 int num_posted, rc = 0;
2194 /* get all NVME buffers need to repost to a local list */
2195 spin_lock_irq(&phba->nvme_buf_list_get_lock);
2196 spin_lock(&phba->nvme_buf_list_put_lock);
2197 list_splice_init(&phba->lpfc_nvme_buf_list_get, &post_nblist);
2198 list_splice(&phba->lpfc_nvme_buf_list_put, &post_nblist);
2199 phba->get_nvme_bufs = 0;
2200 phba->put_nvme_bufs = 0;
2201 spin_unlock(&phba->nvme_buf_list_put_lock);
2202 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
2204 /* post the list of nvme buffer sgls to port if available */
2205 if (!list_empty(&post_nblist)) {
2206 num_posted = lpfc_post_nvme_sgl_list(phba, &post_nblist,
2207 phba->sli4_hba.nvme_xri_cnt);
2208 /* failed to post any nvme buffer, return error */
2209 if (num_posted == 0)
2216 * lpfc_new_nvme_buf - Scsi buffer allocator for HBA with SLI4 IF spec
2217 * @vport: The virtual port for which this call being executed.
2218 * @num_to_allocate: The requested number of buffers to allocate.
2220 * This routine allocates nvme buffers for device with SLI-4 interface spec,
2221 * the nvme buffer contains all the necessary information needed to initiate
2222 * a NVME I/O. After allocating up to @num_to_allocate NVME buffers and put
2223 * them on a list, it post them to the port by using SGL block post.
2226 * int - number of nvme buffers that were allocated and posted.
2227 * 0 = failure, less than num_to_alloc is a partial failure.
2230 lpfc_new_nvme_buf(struct lpfc_vport *vport, int num_to_alloc)
2232 struct lpfc_hba *phba = vport->phba;
2233 struct lpfc_nvme_buf *lpfc_ncmd;
2234 struct lpfc_iocbq *pwqeq;
2235 union lpfc_wqe128 *wqe;
2236 struct sli4_sge *sgl;
2237 dma_addr_t pdma_phys_sgl;
2238 uint16_t iotag, lxri = 0;
2239 int bcnt, num_posted, sgl_size;
2240 LIST_HEAD(prep_nblist);
2241 LIST_HEAD(post_nblist);
2242 LIST_HEAD(nvme_nblist);
2244 sgl_size = phba->cfg_sg_dma_buf_size;
2246 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
2247 lpfc_ncmd = kzalloc(sizeof(struct lpfc_nvme_buf), GFP_KERNEL);
2251 * Get memory from the pci pool to map the virt space to
2252 * pci bus space for an I/O. The DMA buffer includes the
2253 * number of SGE's necessary to support the sg_tablesize.
2255 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
2257 &lpfc_ncmd->dma_handle);
2258 if (!lpfc_ncmd->data) {
2263 lxri = lpfc_sli4_next_xritag(phba);
2264 if (lxri == NO_XRI) {
2265 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
2266 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
2270 pwqeq = &(lpfc_ncmd->cur_iocbq);
2273 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
2274 iotag = lpfc_sli_next_iotag(phba, pwqeq);
2276 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
2277 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
2279 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
2280 "6121 Failed to allocated IOTAG for"
2281 " XRI:0x%x\n", lxri);
2282 lpfc_sli4_free_xri(phba, lxri);
2285 pwqeq->sli4_lxritag = lxri;
2286 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
2287 pwqeq->iocb_flag |= LPFC_IO_NVME;
2288 pwqeq->context1 = lpfc_ncmd;
2289 pwqeq->wqe_cmpl = lpfc_nvme_io_cmd_wqe_cmpl;
2291 /* Initialize local short-hand pointers. */
2292 lpfc_ncmd->nvme_sgl = lpfc_ncmd->data;
2293 sgl = lpfc_ncmd->nvme_sgl;
2294 pdma_phys_sgl = lpfc_ncmd->dma_handle;
2295 lpfc_ncmd->dma_phys_sgl = pdma_phys_sgl;
2297 /* Rsp SGE will be filled in when we rcv an IO
2298 * from the NVME Layer to be sent.
2299 * The cmd is going to be embedded so we need a SKIP SGE.
2301 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP);
2302 bf_set(lpfc_sli4_sge_last, sgl, 0);
2303 sgl->word2 = cpu_to_le32(sgl->word2);
2304 /* Fill in word 3 / sgl_len during cmd submission */
2306 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
2308 /* Initialize WQE */
2309 memset(wqe, 0, sizeof(union lpfc_wqe));
2311 /* add the nvme buffer to a post list */
2312 list_add_tail(&lpfc_ncmd->list, &post_nblist);
2313 spin_lock_irq(&phba->nvme_buf_list_get_lock);
2314 phba->sli4_hba.nvme_xri_cnt++;
2315 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
2317 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
2318 "6114 Allocate %d out of %d requested new NVME "
2319 "buffers\n", bcnt, num_to_alloc);
2321 /* post the list of nvme buffer sgls to port if available */
2322 if (!list_empty(&post_nblist))
2323 num_posted = lpfc_post_nvme_sgl_list(phba,
2324 &post_nblist, bcnt);
2331 static inline struct lpfc_nvme_buf *
2332 lpfc_nvme_buf(struct lpfc_hba *phba)
2334 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
2336 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
2337 &phba->lpfc_nvme_buf_list_get, list) {
2338 list_del_init(&lpfc_ncmd->list);
2339 phba->get_nvme_bufs--;
2346 * lpfc_get_nvme_buf - Get a nvme buffer from lpfc_nvme_buf_list of the HBA
2347 * @phba: The HBA for which this call is being executed.
2349 * This routine removes a nvme buffer from head of @phba lpfc_nvme_buf_list list
2350 * and returns to caller.
2354 * Pointer to lpfc_nvme_buf - Success
2356 static struct lpfc_nvme_buf *
2357 lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
2360 struct lpfc_nvme_buf *lpfc_ncmd = NULL;
2361 unsigned long iflag = 0;
2363 spin_lock_irqsave(&phba->nvme_buf_list_get_lock, iflag);
2364 if (phba->get_nvme_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
2365 lpfc_ncmd = lpfc_nvme_buf(phba);
2367 spin_lock(&phba->nvme_buf_list_put_lock);
2368 list_splice(&phba->lpfc_nvme_buf_list_put,
2369 &phba->lpfc_nvme_buf_list_get);
2370 phba->get_nvme_bufs += phba->put_nvme_bufs;
2371 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
2372 phba->put_nvme_bufs = 0;
2373 spin_unlock(&phba->nvme_buf_list_put_lock);
2374 if (phba->get_nvme_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
2375 lpfc_ncmd = lpfc_nvme_buf(phba);
2377 spin_unlock_irqrestore(&phba->nvme_buf_list_get_lock, iflag);
2379 if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_ncmd) {
2380 atomic_inc(&ndlp->cmd_pending);
2381 lpfc_ncmd->flags |= LPFC_BUMP_QDEPTH;
2387 * lpfc_release_nvme_buf: Return a nvme buffer back to hba nvme buf list.
2388 * @phba: The Hba for which this call is being executed.
2389 * @lpfc_ncmd: The nvme buffer which is being released.
2391 * This routine releases @lpfc_ncmd nvme buffer by adding it to tail of @phba
2392 * lpfc_nvme_buf_list list. For SLI4 XRI's are tied to the nvme buffer
2393 * and cannot be reused for at least RA_TOV amount of time if it was
2397 lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_nvme_buf *lpfc_ncmd)
2399 unsigned long iflag = 0;
2401 if ((lpfc_ncmd->flags & LPFC_BUMP_QDEPTH) && lpfc_ncmd->ndlp)
2402 atomic_dec(&lpfc_ncmd->ndlp->cmd_pending);
2404 lpfc_ncmd->nonsg_phys = 0;
2405 lpfc_ncmd->ndlp = NULL;
2406 lpfc_ncmd->flags &= ~LPFC_BUMP_QDEPTH;
2408 if (lpfc_ncmd->flags & LPFC_SBUF_XBUSY) {
2409 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2410 "6310 XB release deferred for "
2411 "ox_id x%x on reqtag x%x\n",
2412 lpfc_ncmd->cur_iocbq.sli4_xritag,
2413 lpfc_ncmd->cur_iocbq.iotag);
2415 spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock,
2417 list_add_tail(&lpfc_ncmd->list,
2418 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
2419 spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock,
2422 lpfc_ncmd->nvmeCmd = NULL;
2423 lpfc_ncmd->cur_iocbq.iocb_flag = LPFC_IO_NVME;
2424 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
2425 list_add_tail(&lpfc_ncmd->list, &phba->lpfc_nvme_buf_list_put);
2426 phba->put_nvme_bufs++;
2427 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
2432 * lpfc_nvme_create_localport - Create/Bind an nvme localport instance.
2433 * @pvport - the lpfc_vport instance requesting a localport.
2435 * This routine is invoked to create an nvme localport instance to bind
2436 * to the nvme_fc_transport. It is called once during driver load
2437 * like lpfc_create_shost after all other services are initialized.
2438 * It requires a vport, vpi, and wwns at call time. Other localport
2439 * parameters are modified as the driver's FCID and the Fabric WWN
2444 * -ENOMEM - no heap memory available
2445 * other values - from nvme registration upcall
2448 lpfc_nvme_create_localport(struct lpfc_vport *vport)
2451 struct lpfc_hba *phba = vport->phba;
2452 struct nvme_fc_port_info nfcp_info;
2453 struct nvme_fc_local_port *localport;
2454 struct lpfc_nvme_lport *lport;
2455 struct lpfc_nvme_ctrl_stat *cstat;
2458 /* Initialize this localport instance. The vport wwn usage ensures
2459 * that NPIV is accounted for.
2461 memset(&nfcp_info, 0, sizeof(struct nvme_fc_port_info));
2462 nfcp_info.port_role = FC_PORT_ROLE_NVME_INITIATOR;
2463 nfcp_info.node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
2464 nfcp_info.port_name = wwn_to_u64(vport->fc_portname.u.wwn);
2466 /* Limit to LPFC_MAX_NVME_SEG_CNT.
2467 * For now need + 1 to get around NVME transport logic.
2469 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
2470 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_INIT,
2471 "6300 Reducing sg segment cnt to %d\n",
2472 LPFC_MAX_NVME_SEG_CNT);
2473 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
2475 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
2477 lpfc_nvme_template.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1;
2478 lpfc_nvme_template.max_hw_queues = phba->cfg_nvme_io_channel;
2480 if (!IS_ENABLED(CONFIG_NVME_FC))
2483 cstat = kmalloc((sizeof(struct lpfc_nvme_ctrl_stat) *
2484 phba->cfg_nvme_io_channel), GFP_KERNEL);
2488 /* localport is allocated from the stack, but the registration
2489 * call allocates heap memory as well as the private area.
2492 ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template,
2493 &vport->phba->pcidev->dev, &localport);
2495 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC,
2496 "6005 Successfully registered local "
2497 "NVME port num %d, localP %p, private %p, "
2499 localport->port_num, localport,
2501 lpfc_nvme_template.max_sgl_segments);
2503 /* Private is our lport size declared in the template. */
2504 lport = (struct lpfc_nvme_lport *)localport->private;
2505 vport->localport = localport;
2506 lport->vport = vport;
2507 lport->cstat = cstat;
2508 vport->nvmei_support = 1;
2510 atomic_set(&lport->xmt_fcp_noxri, 0);
2511 atomic_set(&lport->xmt_fcp_bad_ndlp, 0);
2512 atomic_set(&lport->xmt_fcp_qdepth, 0);
2513 atomic_set(&lport->xmt_fcp_err, 0);
2514 atomic_set(&lport->xmt_fcp_wqerr, 0);
2515 atomic_set(&lport->xmt_fcp_abort, 0);
2516 atomic_set(&lport->xmt_ls_abort, 0);
2517 atomic_set(&lport->xmt_ls_err, 0);
2518 atomic_set(&lport->cmpl_fcp_xb, 0);
2519 atomic_set(&lport->cmpl_fcp_err, 0);
2520 atomic_set(&lport->cmpl_ls_xb, 0);
2521 atomic_set(&lport->cmpl_ls_err, 0);
2522 atomic_set(&lport->fc4NvmeLsRequests, 0);
2523 atomic_set(&lport->fc4NvmeLsCmpls, 0);
2525 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
2526 cstat = &lport->cstat[i];
2527 atomic_set(&cstat->fc4NvmeInputRequests, 0);
2528 atomic_set(&cstat->fc4NvmeOutputRequests, 0);
2529 atomic_set(&cstat->fc4NvmeControlRequests, 0);
2530 atomic_set(&cstat->fc4NvmeIoCmpls, 0);
2533 /* Don't post more new bufs if repost already recovered
2536 if (phba->sli4_hba.nvme_xri_cnt == 0) {
2537 len = lpfc_new_nvme_buf(vport,
2538 phba->sli4_hba.nvme_xri_max);
2539 vport->phba->total_nvme_bufs += len;
2548 /* lpfc_nvme_lport_unreg_wait - Wait for the host to complete an lport unreg.
2550 * The driver has to wait for the host nvme transport to callback
2551 * indicating the localport has successfully unregistered all
2552 * resources. Since this is an uninterruptible wait, loop every ten
2553 * seconds and print a message indicating no progress.
2555 * An uninterruptible wait is used because of the risk of transport-to-
2556 * driver state mismatch.
2559 lpfc_nvme_lport_unreg_wait(struct lpfc_vport *vport,
2560 struct lpfc_nvme_lport *lport,
2561 struct completion *lport_unreg_cmp)
2563 #if (IS_ENABLED(CONFIG_NVME_FC))
2567 /* Host transport has to clean up and confirm requiring an indefinite
2568 * wait. Print a message if a 10 second wait expires and renew the
2569 * wait. This is unexpected.
2571 wait_tmo = msecs_to_jiffies(LPFC_NVME_WAIT_TMO * 1000);
2573 ret = wait_for_completion_timeout(lport_unreg_cmp, wait_tmo);
2574 if (unlikely(!ret)) {
2575 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
2576 "6176 Lport %p Localport %p wait "
2577 "timed out. Renewing.\n",
2578 lport, vport->localport);
2583 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
2584 "6177 Lport %p Localport %p Complete Success\n",
2585 lport, vport->localport);
2590 * lpfc_nvme_destroy_localport - Destroy lpfc_nvme bound to nvme transport.
2591 * @pnvme: pointer to lpfc nvme data structure.
2593 * This routine is invoked to destroy all lports bound to the phba.
2594 * The lport memory was allocated by the nvme fc transport and is
2595 * released there. This routine ensures all rports bound to the
2596 * lport have been disconnected.
2600 lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2602 #if (IS_ENABLED(CONFIG_NVME_FC))
2603 struct nvme_fc_local_port *localport;
2604 struct lpfc_nvme_lport *lport;
2605 struct lpfc_nvme_ctrl_stat *cstat;
2607 DECLARE_COMPLETION_ONSTACK(lport_unreg_cmp);
2609 if (vport->nvmei_support == 0)
2612 localport = vport->localport;
2613 lport = (struct lpfc_nvme_lport *)localport->private;
2614 cstat = lport->cstat;
2616 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2617 "6011 Destroying NVME localport %p\n",
2620 /* lport's rport list is clear. Unregister
2621 * lport and release resources.
2623 lport->lport_unreg_cmp = &lport_unreg_cmp;
2624 ret = nvme_fc_unregister_localport(localport);
2626 /* Wait for completion. This either blocks
2627 * indefinitely or succeeds
2629 lpfc_nvme_lport_unreg_wait(vport, lport, &lport_unreg_cmp);
2630 vport->localport = NULL;
2633 /* Regardless of the unregister upcall response, clear
2634 * nvmei_support. All rports are unregistered and the
2635 * driver will clean up.
2637 vport->nvmei_support = 0;
2639 lpfc_printf_vlog(vport,
2640 KERN_INFO, LOG_NVME_DISC,
2641 "6009 Unregistered lport Success\n");
2643 lpfc_printf_vlog(vport,
2644 KERN_INFO, LOG_NVME_DISC,
2645 "6010 Unregistered lport "
2646 "Failed, status x%x\n",
2653 lpfc_nvme_update_localport(struct lpfc_vport *vport)
2655 #if (IS_ENABLED(CONFIG_NVME_FC))
2656 struct nvme_fc_local_port *localport;
2657 struct lpfc_nvme_lport *lport;
2659 localport = vport->localport;
2661 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2662 "6710 Update NVME fail. No localport\n");
2665 lport = (struct lpfc_nvme_lport *)localport->private;
2667 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2668 "6171 Update NVME fail. localP %p, No lport\n",
2672 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2673 "6012 Update NVME lport %p did x%x\n",
2674 localport, vport->fc_myDID);
2676 localport->port_id = vport->fc_myDID;
2677 if (localport->port_id == 0)
2678 localport->port_role = FC_PORT_ROLE_NVME_DISCOVERY;
2680 localport->port_role = FC_PORT_ROLE_NVME_INITIATOR;
2682 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2683 "6030 bound lport %p to DID x%06x\n",
2684 lport, localport->port_id);
2689 lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2691 #if (IS_ENABLED(CONFIG_NVME_FC))
2693 struct nvme_fc_local_port *localport;
2694 struct lpfc_nvme_lport *lport;
2695 struct lpfc_nvme_rport *rport;
2696 struct lpfc_nvme_rport *oldrport;
2697 struct nvme_fc_remote_port *remote_port;
2698 struct nvme_fc_port_info rpinfo;
2699 struct lpfc_nodelist *prev_ndlp = NULL;
2701 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC,
2702 "6006 Register NVME PORT. DID x%06x nlptype x%x\n",
2703 ndlp->nlp_DID, ndlp->nlp_type);
2705 localport = vport->localport;
2709 lport = (struct lpfc_nvme_lport *)localport->private;
2711 /* NVME rports are not preserved across devloss.
2712 * Just register this instance. Note, rpinfo->dev_loss_tmo
2713 * is left 0 to indicate accept transport defaults. The
2714 * driver communicates port role capabilities consistent
2715 * with the PRLI response data.
2717 memset(&rpinfo, 0, sizeof(struct nvme_fc_port_info));
2718 rpinfo.port_id = ndlp->nlp_DID;
2719 if (ndlp->nlp_type & NLP_NVME_TARGET)
2720 rpinfo.port_role |= FC_PORT_ROLE_NVME_TARGET;
2721 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
2722 rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR;
2724 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
2725 rpinfo.port_role |= FC_PORT_ROLE_NVME_DISCOVERY;
2727 rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
2728 rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
2730 spin_lock_irq(&vport->phba->hbalock);
2731 oldrport = lpfc_ndlp_get_nrport(ndlp);
2732 spin_unlock_irq(&vport->phba->hbalock);
2736 ret = nvme_fc_register_remoteport(localport, &rpinfo, &remote_port);
2738 /* If the ndlp already has an nrport, this is just
2739 * a resume of the existing rport. Else this is a
2742 /* Guard against an unregister/reregister
2743 * race that leaves the WAIT flag set.
2745 spin_lock_irq(&vport->phba->hbalock);
2746 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
2747 spin_unlock_irq(&vport->phba->hbalock);
2748 rport = remote_port->private;
2750 /* New remoteport record does not guarantee valid
2751 * host private memory area.
2753 prev_ndlp = oldrport->ndlp;
2754 if (oldrport == remote_port->private) {
2755 /* Same remoteport - ndlp should match.
2758 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2760 "6014 Rebinding lport to "
2761 "remoteport %p wwpn 0x%llx, "
2762 "Data: x%x x%x %p %p x%x x%06x\n",
2764 remote_port->port_name,
2765 remote_port->port_id,
2766 remote_port->port_role,
2774 /* Sever the ndlp<->rport association
2775 * before dropping the ndlp ref from
2778 spin_lock_irq(&vport->phba->hbalock);
2779 ndlp->nrport = NULL;
2780 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
2781 spin_unlock_irq(&vport->phba->hbalock);
2783 rport->remoteport = NULL;
2785 /* Reference only removed if previous NDLP is no longer
2786 * active. It might be just a swap and removing the
2787 * reference would cause a premature cleanup.
2789 if (prev_ndlp && prev_ndlp != ndlp) {
2790 if ((!NLP_CHK_NODE_ACT(prev_ndlp)) ||
2791 (!prev_ndlp->nrport))
2792 lpfc_nlp_put(prev_ndlp);
2796 /* Clean bind the rport to the ndlp. */
2797 rport->remoteport = remote_port;
2798 rport->lport = lport;
2800 spin_lock_irq(&vport->phba->hbalock);
2801 ndlp->nrport = rport;
2802 spin_unlock_irq(&vport->phba->hbalock);
2803 lpfc_printf_vlog(vport, KERN_INFO,
2804 LOG_NVME_DISC | LOG_NODE,
2805 "6022 Binding new rport to "
2806 "lport %p Remoteport %p rport %p WWNN 0x%llx, "
2807 "Rport WWPN 0x%llx DID "
2808 "x%06x Role x%x, ndlp %p prev_ndlp %p\n",
2809 lport, remote_port, rport,
2810 rpinfo.node_name, rpinfo.port_name,
2811 rpinfo.port_id, rpinfo.port_role,
2814 lpfc_printf_vlog(vport, KERN_ERR,
2815 LOG_NVME_DISC | LOG_NODE,
2816 "6031 RemotePort Registration failed "
2817 "err: %d, DID x%06x\n",
2818 ret, ndlp->nlp_DID);
2827 /* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport.
2829 * There is no notion of Devloss or rport recovery from the current
2830 * nvme_transport perspective. Loss of an rport just means IO cannot
2831 * be sent and recovery is completely up to the initator.
2832 * For now, the driver just unbinds the DID and port_role so that
2833 * no further IO can be issued. Changes are planned for later.
2835 * Notes - the ndlp reference count is not decremented here since
2836 * since there is no nvme_transport api for devloss. Node ref count
2837 * is only adjusted in driver unload.
2840 lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2842 #if (IS_ENABLED(CONFIG_NVME_FC))
2844 struct nvme_fc_local_port *localport;
2845 struct lpfc_nvme_lport *lport;
2846 struct lpfc_nvme_rport *rport;
2847 struct nvme_fc_remote_port *remoteport = NULL;
2849 localport = vport->localport;
2851 /* This is fundamental error. The localport is always
2852 * available until driver unload. Just exit.
2857 lport = (struct lpfc_nvme_lport *)localport->private;
2861 spin_lock_irq(&vport->phba->hbalock);
2862 rport = lpfc_ndlp_get_nrport(ndlp);
2864 remoteport = rport->remoteport;
2865 spin_unlock_irq(&vport->phba->hbalock);
2869 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2870 "6033 Unreg nvme remoteport %p, portname x%llx, "
2871 "port_id x%06x, portstate x%x port type x%x\n",
2872 remoteport, remoteport->port_name,
2873 remoteport->port_id, remoteport->port_state,
2876 /* Sanity check ndlp type. Only call for NVME ports. Don't
2877 * clear any rport state until the transport calls back.
2880 if (ndlp->nlp_type & NLP_NVME_TARGET) {
2881 /* No concern about the role change on the nvme remoteport.
2882 * The transport will update it.
2884 ndlp->upcall_flags |= NLP_WAIT_FOR_UNREG;
2886 /* Don't let the host nvme transport keep sending keep-alives
2887 * on this remoteport. Vport is unloading, no recovery. The
2888 * return values is ignored. The upcall is a courtesy to the
2891 if (vport->load_flag & FC_UNLOADING)
2892 (void)nvme_fc_set_remoteport_devloss(remoteport, 0);
2894 ret = nvme_fc_unregister_remoteport(remoteport);
2897 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2898 "6167 NVME unregister failed %d "
2900 ret, remoteport->port_state);
2907 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2908 "6168 State error: lport %p, rport%p FCID x%06x\n",
2909 vport->localport, ndlp->rport, ndlp->nlp_DID);
2913 * lpfc_sli4_nvme_xri_aborted - Fast-path process of NVME xri abort
2914 * @phba: pointer to lpfc hba data structure.
2915 * @axri: pointer to the fcp xri abort wcqe structure.
2917 * This routine is invoked by the worker thread to process a SLI4 fast-path
2918 * NVME aborted xri. Aborted NVME IO commands are completed to the transport
2922 lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba,
2923 struct sli4_wcqe_xri_aborted *axri)
2925 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
2926 struct lpfc_nvme_buf *lpfc_ncmd, *next_lpfc_ncmd;
2927 struct nvmefc_fcp_req *nvme_cmd = NULL;
2928 struct lpfc_nodelist *ndlp;
2929 unsigned long iflag = 0;
2931 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
2933 spin_lock_irqsave(&phba->hbalock, iflag);
2934 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2935 list_for_each_entry_safe(lpfc_ncmd, next_lpfc_ncmd,
2936 &phba->sli4_hba.lpfc_abts_nvme_buf_list,
2938 if (lpfc_ncmd->cur_iocbq.sli4_xritag == xri) {
2939 list_del_init(&lpfc_ncmd->list);
2940 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2941 lpfc_ncmd->status = IOSTAT_SUCCESS;
2943 &phba->sli4_hba.abts_nvme_buf_list_lock);
2945 spin_unlock_irqrestore(&phba->hbalock, iflag);
2946 ndlp = lpfc_ncmd->ndlp;
2948 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
2950 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2951 "6311 nvme_cmd %p xri x%x tag x%x "
2952 "abort complete and xri released\n",
2953 lpfc_ncmd->nvmeCmd, xri,
2954 lpfc_ncmd->cur_iocbq.iotag);
2956 /* Aborted NVME commands are required to not complete
2957 * before the abort exchange command fully completes.
2958 * Once completed, it is available via the put list.
2960 if (lpfc_ncmd->nvmeCmd) {
2961 nvme_cmd = lpfc_ncmd->nvmeCmd;
2962 nvme_cmd->done(nvme_cmd);
2963 lpfc_ncmd->nvmeCmd = NULL;
2965 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2969 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2970 spin_unlock_irqrestore(&phba->hbalock, iflag);
2972 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2973 "6312 XRI Aborted xri x%x not found\n", xri);
2978 * lpfc_nvme_wait_for_io_drain - Wait for all NVME wqes to complete
2979 * @phba: Pointer to HBA context object.
2981 * This function flushes all wqes in the nvme rings and frees all resources
2982 * in the txcmplq. This function does not issue abort wqes for the IO
2983 * commands in txcmplq, they will just be returned with
2984 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
2985 * slot has been permanently disabled.
2988 lpfc_nvme_wait_for_io_drain(struct lpfc_hba *phba)
2990 struct lpfc_sli_ring *pring;
2991 u32 i, wait_cnt = 0;
2993 if (phba->sli_rev < LPFC_SLI_REV4 || !phba->sli4_hba.nvme_wq)
2996 /* Cycle through all NVME rings and make sure all outstanding
2997 * WQEs have been removed from the txcmplqs.
2999 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
3000 pring = phba->sli4_hba.nvme_wq[i]->pring;
3005 /* Retrieve everything on the txcmplq */
3006 while (!list_empty(&pring->txcmplq)) {
3007 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
3010 /* The sleep is 10mS. Every ten seconds,
3011 * dump a message. Something is wrong.
3013 if ((wait_cnt % 1000) == 0) {
3014 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
3015 "6178 NVME IO not empty, "
3016 "cnt %d\n", wait_cnt);