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 complete(&lport->lport_unreg_done);
303 /* lpfc_nvme_remoteport_delete
305 * @remoteport: Pointer to an nvme transport remoteport instance.
307 * This is a template downcall. NVME transport calls this function
308 * when it has completed the unregistration of a previously
309 * registered remoteport.
315 lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport)
317 struct lpfc_nvme_rport *rport = remoteport->private;
318 struct lpfc_vport *vport;
319 struct lpfc_nodelist *ndlp;
329 /* Remove this rport from the lport's list - memory is owned by the
330 * transport. Remove the ndlp reference for the NVME transport before
331 * calling state machine to remove the node.
333 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
334 "6146 remoteport delete of remoteport %p\n",
336 spin_lock_irq(&vport->phba->hbalock);
338 /* The register rebind might have occurred before the delete
339 * downcall. Guard against this race.
341 if (ndlp->upcall_flags & NLP_WAIT_FOR_UNREG) {
343 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.
357 lpfc_nvme_cmpl_gen_req(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
358 struct lpfc_wcqe_complete *wcqe)
360 struct lpfc_vport *vport = cmdwqe->vport;
361 struct lpfc_nvme_lport *lport;
363 struct nvmefc_ls_req *pnvme_lsreq;
364 struct lpfc_dmabuf *buf_ptr;
365 struct lpfc_nodelist *ndlp;
367 pnvme_lsreq = (struct nvmefc_ls_req *)cmdwqe->context2;
368 status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK;
370 if (vport->localport) {
371 lport = (struct lpfc_nvme_lport *)vport->localport->private;
373 atomic_inc(&lport->fc4NvmeLsCmpls);
375 if (bf_get(lpfc_wcqe_c_xb, wcqe))
376 atomic_inc(&lport->cmpl_ls_xb);
377 atomic_inc(&lport->cmpl_ls_err);
382 ndlp = (struct lpfc_nodelist *)cmdwqe->context1;
383 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
384 "6047 nvme cmpl Enter "
385 "Data %p DID %x Xri: %x status %x reason x%x cmd:%p "
386 "lsreg:%p bmp:%p ndlp:%p\n",
387 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
388 cmdwqe->sli4_xritag, status,
389 (wcqe->parameter & 0xffff),
390 cmdwqe, pnvme_lsreq, cmdwqe->context3, ndlp);
392 lpfc_nvmeio_data(phba, "NVME LS CMPL: xri x%x stat x%x parm x%x\n",
393 cmdwqe->sli4_xritag, status, wcqe->parameter);
395 if (cmdwqe->context3) {
396 buf_ptr = (struct lpfc_dmabuf *)cmdwqe->context3;
397 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
399 cmdwqe->context3 = NULL;
401 if (pnvme_lsreq->done)
402 pnvme_lsreq->done(pnvme_lsreq, status);
404 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
405 "6046 nvme cmpl without done call back? "
406 "Data %p DID %x Xri: %x status %x\n",
407 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
408 cmdwqe->sli4_xritag, status);
411 cmdwqe->context1 = NULL;
413 lpfc_sli_release_iocbq(phba, cmdwqe);
417 lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
418 struct lpfc_dmabuf *inp,
419 struct nvmefc_ls_req *pnvme_lsreq,
420 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
421 struct lpfc_wcqe_complete *),
422 struct lpfc_nodelist *ndlp, uint32_t num_entry,
423 uint32_t tmo, uint8_t retry)
425 struct lpfc_hba *phba = vport->phba;
426 union lpfc_wqe128 *wqe;
427 struct lpfc_iocbq *genwqe;
428 struct ulp_bde64 *bpl;
429 struct ulp_bde64 bde;
430 int i, rc, xmit_len, first_len;
432 /* Allocate buffer for command WQE */
433 genwqe = lpfc_sli_get_iocbq(phba);
438 memset(wqe, 0, sizeof(union lpfc_wqe));
440 genwqe->context3 = (uint8_t *)bmp;
441 genwqe->iocb_flag |= LPFC_IO_NVME_LS;
443 /* Save for completion so we can release these resources */
444 genwqe->context1 = lpfc_nlp_get(ndlp);
445 genwqe->context2 = (uint8_t *)pnvme_lsreq;
446 /* Fill in payload, bp points to frame payload */
449 /* FC spec states we need 3 * ratov for CT requests */
450 tmo = (3 * phba->fc_ratov);
452 /* For this command calculate the xmit length of the request bde. */
455 bpl = (struct ulp_bde64 *)bmp->virt;
456 for (i = 0; i < num_entry; i++) {
457 bde.tus.w = bpl[i].tus.w;
458 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
460 xmit_len += bde.tus.f.bdeSize;
462 first_len = xmit_len;
465 genwqe->rsvd2 = num_entry;
466 genwqe->hba_wqidx = 0;
469 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
470 wqe->generic.bde.tus.f.bdeSize = first_len;
471 wqe->generic.bde.addrLow = bpl[0].addrLow;
472 wqe->generic.bde.addrHigh = bpl[0].addrHigh;
475 wqe->gen_req.request_payload_len = first_len;
480 bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0);
481 bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1);
482 bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1);
483 bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_ELS4_REQ);
484 bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME);
487 bf_set(wqe_ctxt_tag, &wqe->gen_req.wqe_com,
488 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
489 bf_set(wqe_xri_tag, &wqe->gen_req.wqe_com, genwqe->sli4_xritag);
492 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, (vport->phba->fc_ratov-1));
493 bf_set(wqe_class, &wqe->gen_req.wqe_com, CLASS3);
494 bf_set(wqe_cmnd, &wqe->gen_req.wqe_com, CMD_GEN_REQUEST64_WQE);
495 bf_set(wqe_ct, &wqe->gen_req.wqe_com, SLI4_CT_RPI);
498 wqe->gen_req.wqe_com.abort_tag = genwqe->iotag;
501 bf_set(wqe_reqtag, &wqe->gen_req.wqe_com, genwqe->iotag);
504 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
505 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
506 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
507 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
508 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
511 bf_set(wqe_cqid, &wqe->gen_req.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
512 bf_set(wqe_cmd_type, &wqe->gen_req.wqe_com, OTHER_COMMAND);
515 /* Issue GEN REQ WQE for NPORT <did> */
516 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
517 "6050 Issue GEN REQ WQE to NPORT x%x "
518 "Data: x%x x%x wq:%p lsreq:%p bmp:%p xmit:%d 1st:%d\n",
519 ndlp->nlp_DID, genwqe->iotag,
521 genwqe, pnvme_lsreq, bmp, xmit_len, first_len);
522 genwqe->wqe_cmpl = cmpl;
523 genwqe->iocb_cmpl = NULL;
524 genwqe->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT;
525 genwqe->vport = vport;
526 genwqe->retry = retry;
528 lpfc_nvmeio_data(phba, "NVME LS XMIT: xri x%x iotag x%x to x%06x\n",
529 genwqe->sli4_xritag, genwqe->iotag, ndlp->nlp_DID);
531 rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, genwqe);
533 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
534 "6045 Issue GEN REQ WQE to NPORT x%x "
536 ndlp->nlp_DID, genwqe->iotag,
538 lpfc_sli_release_iocbq(phba, genwqe);
545 * lpfc_nvme_ls_req - Issue an Link Service request
546 * @lpfc_pnvme: Pointer to the driver's nvme instance data
547 * @lpfc_nvme_lport: Pointer to the driver's local port data
548 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
550 * Driver registers this routine to handle any link service request
551 * from the nvme_fc transport to a remote nvme-aware port.
555 * TODO: What are the failure codes.
558 lpfc_nvme_ls_req(struct nvme_fc_local_port *pnvme_lport,
559 struct nvme_fc_remote_port *pnvme_rport,
560 struct nvmefc_ls_req *pnvme_lsreq)
563 struct lpfc_nvme_lport *lport;
564 struct lpfc_nvme_rport *rport;
565 struct lpfc_vport *vport;
566 struct lpfc_nodelist *ndlp;
567 struct ulp_bde64 *bpl;
568 struct lpfc_dmabuf *bmp;
569 uint16_t ntype, nstate;
571 /* there are two dma buf in the request, actually there is one and
572 * the second one is just the start address + cmd size.
573 * Before calling lpfc_nvme_gen_req these buffers need to be wrapped
574 * in a lpfc_dmabuf struct. When freeing we just free the wrapper
575 * because the nvem layer owns the data bufs.
576 * We do not have to break these packets open, we don't care what is in
577 * them. And we do not have to look at the resonse data, we only care
578 * that we got a response. All of the caring is going to happen in the
582 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
583 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
584 if (unlikely(!lport) || unlikely(!rport))
587 vport = lport->vport;
589 if (vport->load_flag & FC_UNLOADING)
592 /* Need the ndlp. It is stored in the driver's rport. */
594 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
595 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
596 "6051 Remoteport %p, rport has invalid ndlp. "
597 "Failing LS Req\n", pnvme_rport);
601 /* The remote node has to be a mapped nvme target or an
602 * unmapped nvme initiator or it's an error.
604 ntype = ndlp->nlp_type;
605 nstate = ndlp->nlp_state;
606 if ((ntype & NLP_NVME_TARGET && nstate != NLP_STE_MAPPED_NODE) ||
607 (ntype & NLP_NVME_INITIATOR && nstate != NLP_STE_UNMAPPED_NODE)) {
608 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
609 "6088 DID x%06x not ready for "
610 "IO. State x%x, Type x%x\n",
611 pnvme_rport->port_id,
612 ndlp->nlp_state, ndlp->nlp_type);
615 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
618 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
619 "6044 Could not find node for DID %x\n",
620 pnvme_rport->port_id);
623 INIT_LIST_HEAD(&bmp->list);
624 bmp->virt = lpfc_mbuf_alloc(vport->phba, MEM_PRI, &(bmp->phys));
626 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
627 "6042 Could not find node for DID %x\n",
628 pnvme_rport->port_id);
632 bpl = (struct ulp_bde64 *)bmp->virt;
633 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rqstdma));
634 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rqstdma));
635 bpl->tus.f.bdeFlags = 0;
636 bpl->tus.f.bdeSize = pnvme_lsreq->rqstlen;
637 bpl->tus.w = le32_to_cpu(bpl->tus.w);
640 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rspdma));
641 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rspdma));
642 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
643 bpl->tus.f.bdeSize = pnvme_lsreq->rsplen;
644 bpl->tus.w = le32_to_cpu(bpl->tus.w);
646 /* Expand print to include key fields. */
647 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
648 "6149 Issue LS Req to DID 0x%06x lport %p, rport %p "
649 "lsreq%p rqstlen:%d rsplen:%d %pad %pad\n",
651 pnvme_lport, pnvme_rport,
652 pnvme_lsreq, pnvme_lsreq->rqstlen,
653 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
654 &pnvme_lsreq->rspdma);
656 atomic_inc(&lport->fc4NvmeLsRequests);
658 /* Hardcode the wait to 30 seconds. Connections are failing otherwise.
659 * This code allows it all to work.
661 ret = lpfc_nvme_gen_req(vport, bmp, pnvme_lsreq->rqstaddr,
662 pnvme_lsreq, lpfc_nvme_cmpl_gen_req,
664 if (ret != WQE_SUCCESS) {
665 atomic_inc(&lport->xmt_ls_err);
666 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
667 "6052 EXIT. issue ls wqe failed lport %p, "
668 "rport %p lsreq%p Status %x DID %x\n",
669 pnvme_lport, pnvme_rport, pnvme_lsreq,
671 lpfc_mbuf_free(vport->phba, bmp->virt, bmp->phys);
676 /* Stub in routine and return 0 for now. */
681 * lpfc_nvme_ls_abort - Issue an Link Service request
682 * @lpfc_pnvme: Pointer to the driver's nvme instance data
683 * @lpfc_nvme_lport: Pointer to the driver's local port data
684 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
686 * Driver registers this routine to handle any link service request
687 * from the nvme_fc transport to a remote nvme-aware port.
691 * TODO: What are the failure codes.
694 lpfc_nvme_ls_abort(struct nvme_fc_local_port *pnvme_lport,
695 struct nvme_fc_remote_port *pnvme_rport,
696 struct nvmefc_ls_req *pnvme_lsreq)
698 struct lpfc_nvme_lport *lport;
699 struct lpfc_vport *vport;
700 struct lpfc_hba *phba;
701 struct lpfc_nodelist *ndlp;
702 LIST_HEAD(abort_list);
703 struct lpfc_sli_ring *pring;
704 struct lpfc_iocbq *wqe, *next_wqe;
706 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
707 if (unlikely(!lport))
709 vport = lport->vport;
712 if (vport->load_flag & FC_UNLOADING)
715 ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id);
717 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
718 "6049 Could not find node for DID %x\n",
719 pnvme_rport->port_id);
723 /* Expand print to include key fields. */
724 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
725 "6040 ENTER. lport %p, rport %p lsreq %p rqstlen:%d "
726 "rsplen:%d %pad %pad\n",
727 pnvme_lport, pnvme_rport,
728 pnvme_lsreq, pnvme_lsreq->rqstlen,
729 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
730 &pnvme_lsreq->rspdma);
733 * Lock the ELS ring txcmplq and build a local list of all ELS IOs
734 * that need an ABTS. The IOs need to stay on the txcmplq so that
735 * the abort operation completes them successfully.
737 pring = phba->sli4_hba.nvmels_wq->pring;
738 spin_lock_irq(&phba->hbalock);
739 spin_lock(&pring->ring_lock);
740 list_for_each_entry_safe(wqe, next_wqe, &pring->txcmplq, list) {
741 /* Add to abort_list on on NDLP match. */
742 if (lpfc_check_sli_ndlp(phba, pring, wqe, ndlp)) {
743 wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
744 list_add_tail(&wqe->dlist, &abort_list);
747 spin_unlock(&pring->ring_lock);
748 spin_unlock_irq(&phba->hbalock);
750 /* Abort the targeted IOs and remove them from the abort list. */
751 list_for_each_entry_safe(wqe, next_wqe, &abort_list, dlist) {
752 atomic_inc(&lport->xmt_ls_abort);
753 spin_lock_irq(&phba->hbalock);
754 list_del_init(&wqe->dlist);
755 lpfc_sli_issue_abort_iotag(phba, pring, wqe);
756 spin_unlock_irq(&phba->hbalock);
760 /* Fix up the existing sgls for NVME IO. */
762 lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport,
763 struct lpfc_nvme_buf *lpfc_ncmd,
764 struct nvmefc_fcp_req *nCmd)
766 struct lpfc_hba *phba = vport->phba;
767 struct sli4_sge *sgl;
768 union lpfc_wqe128 *wqe;
769 uint32_t *wptr, *dptr;
772 * Get a local pointer to the built-in wqe and correct
773 * the cmd size to match NVME's 96 bytes and fix
777 wqe = &lpfc_ncmd->cur_iocbq.wqe;
780 * Adjust the FCP_CMD and FCP_RSP DMA data and sge_len to
781 * match NVME. NVME sends 96 bytes. Also, use the
782 * nvme commands command and response dma addresses
783 * rather than the virtual memory to ease the restore
786 sgl = lpfc_ncmd->nvme_sgl;
787 sgl->sge_len = cpu_to_le32(nCmd->cmdlen);
788 if (phba->cfg_nvme_embed_cmd) {
792 /* Word 0-2 - NVME CMND IU (embedded payload) */
793 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_IMMED;
794 wqe->generic.bde.tus.f.bdeSize = 56;
795 wqe->generic.bde.addrHigh = 0;
796 wqe->generic.bde.addrLow = 64; /* Word 16 */
798 /* Word 10 - dbde is 0, wqes is 1 in template */
801 * Embed the payload in the last half of the WQE
802 * WQE words 16-30 get the NVME CMD IU payload
804 * WQE words 16-19 get payload Words 1-4
805 * WQE words 20-21 get payload Words 6-7
806 * WQE words 22-29 get payload Words 16-23
808 wptr = &wqe->words[16]; /* WQE ptr */
809 dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */
810 dptr++; /* Skip Word 0 in payload */
812 *wptr++ = *dptr++; /* Word 1 */
813 *wptr++ = *dptr++; /* Word 2 */
814 *wptr++ = *dptr++; /* Word 3 */
815 *wptr++ = *dptr++; /* Word 4 */
816 dptr++; /* Skip Word 5 in payload */
817 *wptr++ = *dptr++; /* Word 6 */
818 *wptr++ = *dptr++; /* Word 7 */
819 dptr += 8; /* Skip Words 8-15 in payload */
820 *wptr++ = *dptr++; /* Word 16 */
821 *wptr++ = *dptr++; /* Word 17 */
822 *wptr++ = *dptr++; /* Word 18 */
823 *wptr++ = *dptr++; /* Word 19 */
824 *wptr++ = *dptr++; /* Word 20 */
825 *wptr++ = *dptr++; /* Word 21 */
826 *wptr++ = *dptr++; /* Word 22 */
827 *wptr = *dptr; /* Word 23 */
829 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->cmddma));
830 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->cmddma));
832 /* Word 0-2 - NVME CMND IU Inline BDE */
833 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
834 wqe->generic.bde.tus.f.bdeSize = nCmd->cmdlen;
835 wqe->generic.bde.addrHigh = sgl->addr_hi;
836 wqe->generic.bde.addrLow = sgl->addr_lo;
839 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
840 bf_set(wqe_wqes, &wqe->generic.wqe_com, 0);
845 /* Setup the physical region for the FCP RSP */
846 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->rspdma));
847 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->rspdma));
848 sgl->word2 = le32_to_cpu(sgl->word2);
850 bf_set(lpfc_sli4_sge_last, sgl, 0);
852 bf_set(lpfc_sli4_sge_last, sgl, 1);
853 sgl->word2 = cpu_to_le32(sgl->word2);
854 sgl->sge_len = cpu_to_le32(nCmd->rsplen);
857 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
859 lpfc_nvme_ktime(struct lpfc_hba *phba,
860 struct lpfc_nvme_buf *lpfc_ncmd)
862 uint64_t seg1, seg2, seg3, seg4;
865 if (!lpfc_ncmd->ts_last_cmd ||
866 !lpfc_ncmd->ts_cmd_start ||
867 !lpfc_ncmd->ts_cmd_wqput ||
868 !lpfc_ncmd->ts_isr_cmpl ||
869 !lpfc_ncmd->ts_data_nvme)
872 if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_cmd_start)
874 if (lpfc_ncmd->ts_cmd_start < lpfc_ncmd->ts_last_cmd)
876 if (lpfc_ncmd->ts_cmd_wqput < lpfc_ncmd->ts_cmd_start)
878 if (lpfc_ncmd->ts_isr_cmpl < lpfc_ncmd->ts_cmd_wqput)
880 if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_isr_cmpl)
883 * Segment 1 - Time from Last FCP command cmpl is handed
884 * off to NVME Layer to start of next command.
885 * Segment 2 - Time from Driver receives a IO cmd start
886 * from NVME Layer to WQ put is done on IO cmd.
887 * Segment 3 - Time from Driver WQ put is done on IO cmd
888 * to MSI-X ISR for IO cmpl.
889 * Segment 4 - Time from MSI-X ISR for IO cmpl to when
890 * cmpl is handled off to the NVME Layer.
892 seg1 = lpfc_ncmd->ts_cmd_start - lpfc_ncmd->ts_last_cmd;
893 if (seg1 > 5000000) /* 5 ms - for sequential IOs only */
896 /* Calculate times relative to start of IO */
897 seg2 = (lpfc_ncmd->ts_cmd_wqput - lpfc_ncmd->ts_cmd_start);
899 seg3 = lpfc_ncmd->ts_isr_cmpl - lpfc_ncmd->ts_cmd_start;
905 seg4 = lpfc_ncmd->ts_data_nvme - lpfc_ncmd->ts_cmd_start;
910 phba->ktime_data_samples++;
911 phba->ktime_seg1_total += seg1;
912 if (seg1 < phba->ktime_seg1_min)
913 phba->ktime_seg1_min = seg1;
914 else if (seg1 > phba->ktime_seg1_max)
915 phba->ktime_seg1_max = seg1;
916 phba->ktime_seg2_total += seg2;
917 if (seg2 < phba->ktime_seg2_min)
918 phba->ktime_seg2_min = seg2;
919 else if (seg2 > phba->ktime_seg2_max)
920 phba->ktime_seg2_max = seg2;
921 phba->ktime_seg3_total += seg3;
922 if (seg3 < phba->ktime_seg3_min)
923 phba->ktime_seg3_min = seg3;
924 else if (seg3 > phba->ktime_seg3_max)
925 phba->ktime_seg3_max = seg3;
926 phba->ktime_seg4_total += seg4;
927 if (seg4 < phba->ktime_seg4_min)
928 phba->ktime_seg4_min = seg4;
929 else if (seg4 > phba->ktime_seg4_max)
930 phba->ktime_seg4_max = seg4;
932 lpfc_ncmd->ts_last_cmd = 0;
933 lpfc_ncmd->ts_cmd_start = 0;
934 lpfc_ncmd->ts_cmd_wqput = 0;
935 lpfc_ncmd->ts_isr_cmpl = 0;
936 lpfc_ncmd->ts_data_nvme = 0;
941 * lpfc_nvme_io_cmd_wqe_cmpl - Complete an NVME-over-FCP IO
942 * @lpfc_pnvme: Pointer to the driver's nvme instance data
943 * @lpfc_nvme_lport: Pointer to the driver's local port data
944 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
946 * Driver registers this routine as it io request handler. This
947 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
948 * data structure to the rport indicated in @lpfc_nvme_rport.
952 * TODO: What are the failure codes.
955 lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
956 struct lpfc_wcqe_complete *wcqe)
958 struct lpfc_nvme_buf *lpfc_ncmd =
959 (struct lpfc_nvme_buf *)pwqeIn->context1;
960 struct lpfc_vport *vport = pwqeIn->vport;
961 struct nvmefc_fcp_req *nCmd;
962 struct nvme_fc_ersp_iu *ep;
963 struct nvme_fc_cmd_iu *cp;
964 struct lpfc_nvme_rport *rport;
965 struct lpfc_nodelist *ndlp;
966 struct lpfc_nvme_fcpreq_priv *freqpriv;
967 struct lpfc_nvme_lport *lport;
968 struct lpfc_nvme_ctrl_stat *cstat;
970 uint32_t code, status, idx;
971 uint16_t cid, sqhd, data;
974 /* Sanity check on return of outstanding command */
975 if (!lpfc_ncmd || !lpfc_ncmd->nvmeCmd || !lpfc_ncmd->nrport) {
977 lpfc_printf_vlog(vport, KERN_ERR,
978 LOG_NODE | LOG_NVME_IOERR,
979 "6071 Null lpfc_ncmd pointer. No "
980 "release, skip completion\n");
984 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
985 "6066 Missing cmpl ptrs: lpfc_ncmd %p, "
986 "nvmeCmd %p nrport %p\n",
987 lpfc_ncmd, lpfc_ncmd->nvmeCmd,
990 /* Release the lpfc_ncmd regardless of the missing elements. */
991 lpfc_release_nvme_buf(phba, lpfc_ncmd);
994 nCmd = lpfc_ncmd->nvmeCmd;
995 rport = lpfc_ncmd->nrport;
996 status = bf_get(lpfc_wcqe_c_status, wcqe);
998 if (vport->localport) {
999 lport = (struct lpfc_nvme_lport *)vport->localport->private;
1001 idx = lpfc_ncmd->cur_iocbq.hba_wqidx;
1002 cstat = &lport->cstat[idx];
1003 atomic_inc(&cstat->fc4NvmeIoCmpls);
1005 if (bf_get(lpfc_wcqe_c_xb, wcqe))
1006 atomic_inc(&lport->cmpl_fcp_xb);
1007 atomic_inc(&lport->cmpl_fcp_err);
1012 lpfc_nvmeio_data(phba, "NVME FCP CMPL: xri x%x stat x%x parm x%x\n",
1013 lpfc_ncmd->cur_iocbq.sli4_xritag,
1014 status, wcqe->parameter);
1016 * Catch race where our node has transitioned, but the
1017 * transport is still transitioning.
1020 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1021 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
1022 "6061 rport %p, DID x%06x node not ready.\n",
1023 rport, rport->remoteport->port_id);
1025 ndlp = lpfc_findnode_did(vport, rport->remoteport->port_id);
1027 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1028 "6062 Ignoring NVME cmpl. No ndlp\n");
1033 code = bf_get(lpfc_wcqe_c_code, wcqe);
1034 if (code == CQE_CODE_NVME_ERSP) {
1035 /* For this type of CQE, we need to rebuild the rsp */
1036 ep = (struct nvme_fc_ersp_iu *)nCmd->rspaddr;
1039 * Get Command Id from cmd to plug into response. This
1040 * code is not needed in the next NVME Transport drop.
1042 cp = (struct nvme_fc_cmd_iu *)nCmd->cmdaddr;
1043 cid = cp->sqe.common.command_id;
1046 * RSN is in CQE word 2
1047 * SQHD is in CQE Word 3 bits 15:0
1048 * Cmd Specific info is in CQE Word 1
1049 * and in CQE Word 0 bits 15:0
1051 sqhd = bf_get(lpfc_wcqe_c_sqhead, wcqe);
1053 /* Now lets build the NVME ERSP IU */
1054 ep->iu_len = cpu_to_be16(8);
1055 ep->rsn = wcqe->parameter;
1056 ep->xfrd_len = cpu_to_be32(nCmd->payload_length);
1058 ptr = (uint32_t *)&ep->cqe.result.u64;
1059 *ptr++ = wcqe->total_data_placed;
1060 data = bf_get(lpfc_wcqe_c_ersp0, wcqe);
1061 *ptr = (uint32_t)data;
1062 ep->cqe.sq_head = sqhd;
1063 ep->cqe.sq_id = nCmd->sqid;
1064 ep->cqe.command_id = cid;
1067 lpfc_ncmd->status = IOSTAT_SUCCESS;
1068 lpfc_ncmd->result = 0;
1069 nCmd->rcv_rsplen = LPFC_NVME_ERSP_LEN;
1070 nCmd->transferred_length = nCmd->payload_length;
1072 lpfc_ncmd->status = (status & LPFC_IOCB_STATUS_MASK);
1073 lpfc_ncmd->result = (wcqe->parameter & IOERR_PARAM_MASK);
1075 /* For NVME, the only failure path that results in an
1076 * IO error is when the adapter rejects it. All other
1077 * conditions are a success case and resolved by the
1079 * IOSTAT_FCP_RSP_ERROR means:
1080 * 1. Length of data received doesn't match total
1081 * transfer length in WQE
1082 * 2. If the RSP payload does NOT match these cases:
1083 * a. RSP length 12/24 bytes and all zeros
1086 switch (lpfc_ncmd->status) {
1087 case IOSTAT_SUCCESS:
1088 nCmd->transferred_length = wcqe->total_data_placed;
1089 nCmd->rcv_rsplen = 0;
1092 case IOSTAT_FCP_RSP_ERROR:
1093 nCmd->transferred_length = wcqe->total_data_placed;
1094 nCmd->rcv_rsplen = wcqe->parameter;
1097 if (nCmd->rcv_rsplen == LPFC_NVME_ERSP_LEN)
1099 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1100 "6081 NVME Completion Protocol Error: "
1101 "xri %x status x%x result x%x "
1103 lpfc_ncmd->cur_iocbq.sli4_xritag,
1104 lpfc_ncmd->status, lpfc_ncmd->result,
1105 wcqe->total_data_placed);
1107 case IOSTAT_LOCAL_REJECT:
1108 /* Let fall through to set command final state. */
1109 if (lpfc_ncmd->result == IOERR_ABORT_REQUESTED)
1110 lpfc_printf_vlog(vport, KERN_INFO,
1112 "6032 Delay Aborted cmd %p "
1113 "nvme cmd %p, xri x%x, "
1116 lpfc_ncmd->cur_iocbq.sli4_xritag,
1117 bf_get(lpfc_wcqe_c_xb, wcqe));
1120 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1121 "6072 NVME Completion Error: xri %x "
1122 "status x%x result x%x placed x%x\n",
1123 lpfc_ncmd->cur_iocbq.sli4_xritag,
1124 lpfc_ncmd->status, lpfc_ncmd->result,
1125 wcqe->total_data_placed);
1126 nCmd->transferred_length = 0;
1127 nCmd->rcv_rsplen = 0;
1128 nCmd->status = NVME_SC_INTERNAL;
1132 /* pick up SLI4 exhange busy condition */
1133 if (bf_get(lpfc_wcqe_c_xb, wcqe))
1134 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
1136 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
1138 /* Update stats and complete the IO. There is
1139 * no need for dma unprep because the nvme_transport
1140 * owns the dma address.
1142 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1143 if (lpfc_ncmd->ts_cmd_start) {
1144 lpfc_ncmd->ts_isr_cmpl = pwqeIn->isr_timestamp;
1145 lpfc_ncmd->ts_data_nvme = ktime_get_ns();
1146 phba->ktime_last_cmd = lpfc_ncmd->ts_data_nvme;
1147 lpfc_nvme_ktime(phba, lpfc_ncmd);
1149 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) {
1150 if (lpfc_ncmd->cpu != smp_processor_id())
1151 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1152 "6701 CPU Check cmpl: "
1153 "cpu %d expect %d\n",
1154 smp_processor_id(), lpfc_ncmd->cpu);
1155 if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT)
1156 phba->cpucheck_cmpl_io[lpfc_ncmd->cpu]++;
1160 /* NVME targets need completion held off until the abort exchange
1161 * completes unless the NVME Rport is getting unregistered.
1164 if (!(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) {
1165 freqpriv = nCmd->private;
1166 freqpriv->nvme_buf = NULL;
1168 lpfc_ncmd->nvmeCmd = NULL;
1171 spin_lock_irqsave(&phba->hbalock, flags);
1172 lpfc_ncmd->nrport = NULL;
1173 spin_unlock_irqrestore(&phba->hbalock, flags);
1175 /* Call release with XB=1 to queue the IO into the abort list. */
1176 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1181 * lpfc_nvme_prep_io_cmd - Issue an NVME-over-FCP IO
1182 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1183 * @lpfc_nvme_lport: Pointer to the driver's local port data
1184 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1185 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1186 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1188 * Driver registers this routine as it io request handler. This
1189 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1190 * data structure to the rport indicated in @lpfc_nvme_rport.
1194 * TODO: What are the failure codes.
1197 lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport,
1198 struct lpfc_nvme_buf *lpfc_ncmd,
1199 struct lpfc_nodelist *pnode,
1200 struct lpfc_nvme_ctrl_stat *cstat)
1202 struct lpfc_hba *phba = vport->phba;
1203 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1204 struct lpfc_iocbq *pwqeq = &(lpfc_ncmd->cur_iocbq);
1205 union lpfc_wqe128 *wqe = &pwqeq->wqe;
1208 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
1212 * There are three possibilities here - use scatter-gather segment, use
1213 * the single mapping, or neither.
1216 if (nCmd->io_dir == NVMEFC_FCP_WRITE) {
1217 /* From the iwrite template, initialize words 7 - 11 */
1218 memcpy(&wqe->words[7],
1219 &lpfc_iwrite_cmd_template.words[7],
1220 sizeof(uint32_t) * 5);
1223 wqe->fcp_iwrite.total_xfer_len = nCmd->payload_length;
1226 if ((phba->cfg_nvme_enable_fb) &&
1227 (pnode->nlp_flag & NLP_FIRSTBURST)) {
1228 req_len = lpfc_ncmd->nvmeCmd->payload_length;
1229 if (req_len < pnode->nvme_fb_size)
1230 wqe->fcp_iwrite.initial_xfer_len =
1233 wqe->fcp_iwrite.initial_xfer_len =
1234 pnode->nvme_fb_size;
1236 wqe->fcp_iwrite.initial_xfer_len = 0;
1238 atomic_inc(&cstat->fc4NvmeOutputRequests);
1240 /* From the iread template, initialize words 7 - 11 */
1241 memcpy(&wqe->words[7],
1242 &lpfc_iread_cmd_template.words[7],
1243 sizeof(uint32_t) * 5);
1246 wqe->fcp_iread.total_xfer_len = nCmd->payload_length;
1249 wqe->fcp_iread.rsrvd5 = 0;
1251 atomic_inc(&cstat->fc4NvmeInputRequests);
1254 /* From the icmnd template, initialize words 4 - 11 */
1255 memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4],
1256 sizeof(uint32_t) * 8);
1257 atomic_inc(&cstat->fc4NvmeControlRequests);
1260 * Finish initializing those WQE fields that are independent
1261 * of the nvme_cmnd request_buffer
1265 bf_set(payload_offset_len, &wqe->fcp_icmd,
1266 (nCmd->rsplen + nCmd->cmdlen));
1269 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
1270 phba->sli4_hba.rpi_ids[pnode->nlp_rpi]);
1271 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag);
1274 wqe->generic.wqe_com.abort_tag = pwqeq->iotag;
1277 bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag);
1279 /* Words 13 14 15 are for PBDE support */
1281 pwqeq->vport = vport;
1287 * lpfc_nvme_prep_io_dma - Issue an NVME-over-FCP IO
1288 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1289 * @lpfc_nvme_lport: Pointer to the driver's local port data
1290 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1291 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1292 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1294 * Driver registers this routine as it io request handler. This
1295 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1296 * data structure to the rport indicated in @lpfc_nvme_rport.
1300 * TODO: What are the failure codes.
1303 lpfc_nvme_prep_io_dma(struct lpfc_vport *vport,
1304 struct lpfc_nvme_buf *lpfc_ncmd)
1306 struct lpfc_hba *phba = vport->phba;
1307 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1308 union lpfc_wqe128 *wqe = &lpfc_ncmd->cur_iocbq.wqe;
1309 struct sli4_sge *sgl = lpfc_ncmd->nvme_sgl;
1310 struct scatterlist *data_sg;
1311 struct sli4_sge *first_data_sgl;
1312 struct ulp_bde64 *bde;
1313 dma_addr_t physaddr;
1314 uint32_t num_bde = 0;
1316 uint32_t dma_offset = 0;
1319 /* Fix up the command and response DMA stuff. */
1320 lpfc_nvme_adj_fcp_sgls(vport, lpfc_ncmd, nCmd);
1323 * There are three possibilities here - use scatter-gather segment, use
1324 * the single mapping, or neither.
1328 * Jump over the cmd and rsp SGEs. The fix routine
1329 * has already adjusted for this.
1333 first_data_sgl = sgl;
1334 lpfc_ncmd->seg_cnt = nCmd->sg_cnt;
1335 if (lpfc_ncmd->seg_cnt > lpfc_nvme_template.max_sgl_segments) {
1336 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1337 "6058 Too many sg segments from "
1338 "NVME Transport. Max %d, "
1339 "nvmeIO sg_cnt %d\n",
1340 phba->cfg_nvme_seg_cnt + 1,
1341 lpfc_ncmd->seg_cnt);
1342 lpfc_ncmd->seg_cnt = 0;
1347 * The driver established a maximum scatter-gather segment count
1348 * during probe that limits the number of sg elements in any
1349 * single nvme command. Just run through the seg_cnt and format
1352 nseg = nCmd->sg_cnt;
1353 data_sg = nCmd->first_sgl;
1354 for (i = 0; i < nseg; i++) {
1355 if (data_sg == NULL) {
1356 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1357 "6059 dptr err %d, nseg %d\n",
1359 lpfc_ncmd->seg_cnt = 0;
1362 physaddr = data_sg->dma_address;
1363 dma_len = data_sg->length;
1364 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
1365 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
1366 sgl->word2 = le32_to_cpu(sgl->word2);
1367 if ((num_bde + 1) == nseg)
1368 bf_set(lpfc_sli4_sge_last, sgl, 1);
1370 bf_set(lpfc_sli4_sge_last, sgl, 0);
1371 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
1372 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
1373 sgl->word2 = cpu_to_le32(sgl->word2);
1374 sgl->sge_len = cpu_to_le32(dma_len);
1376 dma_offset += dma_len;
1377 data_sg = sg_next(data_sg);
1380 if (phba->cfg_enable_pbde) {
1381 /* Use PBDE support for first SGL only, offset == 0 */
1383 bde = (struct ulp_bde64 *)
1385 bde->addrLow = first_data_sgl->addr_lo;
1386 bde->addrHigh = first_data_sgl->addr_hi;
1387 bde->tus.f.bdeSize =
1388 le32_to_cpu(first_data_sgl->sge_len);
1389 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1390 bde->tus.w = cpu_to_le32(bde->tus.w);
1391 /* wqe_pbde is 1 in template */
1393 memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3));
1394 bf_set(wqe_pbde, &wqe->generic.wqe_com, 0);
1398 /* For this clause to be valid, the payload_length
1399 * and sg_cnt must zero.
1401 if (nCmd->payload_length != 0) {
1402 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1403 "6063 NVME DMA Prep Err: sg_cnt %d "
1404 "payload_length x%x\n",
1405 nCmd->sg_cnt, nCmd->payload_length);
1413 * lpfc_nvme_fcp_io_submit - Issue an NVME-over-FCP IO
1414 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1415 * @lpfc_nvme_lport: Pointer to the driver's local port data
1416 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1417 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1418 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1420 * Driver registers this routine as it io request handler. This
1421 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1422 * data structure to the rport
1423 indicated in @lpfc_nvme_rport.
1427 * TODO: What are the failure codes.
1430 lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
1431 struct nvme_fc_remote_port *pnvme_rport,
1432 void *hw_queue_handle,
1433 struct nvmefc_fcp_req *pnvme_fcreq)
1438 struct lpfc_nvme_lport *lport;
1439 struct lpfc_nvme_ctrl_stat *cstat;
1440 struct lpfc_vport *vport;
1441 struct lpfc_hba *phba;
1442 struct lpfc_nodelist *ndlp;
1443 struct lpfc_nvme_buf *lpfc_ncmd;
1444 struct lpfc_nvme_rport *rport;
1445 struct lpfc_nvme_qhandle *lpfc_queue_info;
1446 struct lpfc_nvme_fcpreq_priv *freqpriv;
1447 struct nvme_common_command *sqe;
1448 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1452 /* Validate pointers. LLDD fault handling with transport does
1453 * have timing races.
1455 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1456 if (unlikely(!lport)) {
1461 vport = lport->vport;
1463 if (unlikely(!hw_queue_handle)) {
1464 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1465 "6117 Fail IO, NULL hw_queue_handle\n");
1466 atomic_inc(&lport->xmt_fcp_err);
1473 if (vport->load_flag & FC_UNLOADING) {
1478 if (vport->load_flag & FC_UNLOADING) {
1479 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1480 "6124 Fail IO, Driver unload\n");
1481 atomic_inc(&lport->xmt_fcp_err);
1486 freqpriv = pnvme_fcreq->private;
1487 if (unlikely(!freqpriv)) {
1488 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1489 "6158 Fail IO, NULL request data\n");
1490 atomic_inc(&lport->xmt_fcp_err);
1495 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1497 start = ktime_get_ns();
1499 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
1500 lpfc_queue_info = (struct lpfc_nvme_qhandle *)hw_queue_handle;
1503 * Catch race where our node has transitioned, but the
1504 * transport is still transitioning.
1507 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1508 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1509 "6053 Fail IO, ndlp not ready: rport %p "
1510 "ndlp %p, DID x%06x\n",
1511 rport, ndlp, pnvme_rport->port_id);
1512 atomic_inc(&lport->xmt_fcp_err);
1517 /* The remote node has to be a mapped target or it's an error. */
1518 if ((ndlp->nlp_type & NLP_NVME_TARGET) &&
1519 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
1520 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1521 "6036 Fail IO, DID x%06x not ready for "
1522 "IO. State x%x, Type x%x Flg x%x\n",
1523 pnvme_rport->port_id,
1524 ndlp->nlp_state, ndlp->nlp_type,
1525 ndlp->upcall_flags);
1526 atomic_inc(&lport->xmt_fcp_bad_ndlp);
1532 /* Currently only NVME Keep alive commands should be expedited
1533 * if the driver runs out of a resource. These should only be
1534 * issued on the admin queue, qidx 0
1536 if (!lpfc_queue_info->qidx && !pnvme_fcreq->sg_cnt) {
1537 sqe = &((struct nvme_fc_cmd_iu *)
1538 pnvme_fcreq->cmdaddr)->sqe.common;
1539 if (sqe->opcode == nvme_admin_keep_alive)
1543 /* The node is shared with FCP IO, make sure the IO pending count does
1544 * not exceed the programmed depth.
1546 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
1547 if ((atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) &&
1549 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1550 "6174 Fail IO, ndlp qdepth exceeded: "
1551 "idx %d DID %x pend %d qdepth %d\n",
1552 lpfc_queue_info->index, ndlp->nlp_DID,
1553 atomic_read(&ndlp->cmd_pending),
1555 atomic_inc(&lport->xmt_fcp_qdepth);
1561 lpfc_ncmd = lpfc_get_nvme_buf(phba, ndlp, expedite);
1562 if (lpfc_ncmd == NULL) {
1563 atomic_inc(&lport->xmt_fcp_noxri);
1564 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1565 "6065 Fail IO, driver buffer pool is empty: "
1567 lpfc_queue_info->index, ndlp->nlp_DID);
1571 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1573 lpfc_ncmd->ts_cmd_start = start;
1574 lpfc_ncmd->ts_last_cmd = phba->ktime_last_cmd;
1576 lpfc_ncmd->ts_cmd_start = 0;
1581 * Store the data needed by the driver to issue, abort, and complete
1583 * Do not let the IO hang out forever. There is no midlayer issuing
1584 * an abort so inform the FW of the maximum IO pending time.
1586 freqpriv->nvme_buf = lpfc_ncmd;
1587 lpfc_ncmd->nvmeCmd = pnvme_fcreq;
1588 lpfc_ncmd->nrport = rport;
1589 lpfc_ncmd->ndlp = ndlp;
1590 lpfc_ncmd->start_time = jiffies;
1593 * Issue the IO on the WQ indicated by index in the hw_queue_handle.
1594 * This identfier was create in our hardware queue create callback
1595 * routine. The driver now is dependent on the IO queue steering from
1596 * the transport. We are trusting the upper NVME layers know which
1597 * index to use and that they have affinitized a CPU to this hardware
1598 * queue. A hardware queue maps to a driver MSI-X vector/EQ/CQ/WQ.
1600 idx = lpfc_queue_info->index;
1601 lpfc_ncmd->cur_iocbq.hba_wqidx = idx;
1602 cstat = &lport->cstat[idx];
1604 lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp, cstat);
1605 ret = lpfc_nvme_prep_io_dma(vport, lpfc_ncmd);
1607 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1608 "6175 Fail IO, Prep DMA: "
1610 lpfc_queue_info->index, ndlp->nlp_DID);
1611 atomic_inc(&lport->xmt_fcp_err);
1613 goto out_free_nvme_buf;
1616 lpfc_nvmeio_data(phba, "NVME FCP XMIT: xri x%x idx %d to %06x\n",
1617 lpfc_ncmd->cur_iocbq.sli4_xritag,
1618 lpfc_queue_info->index, ndlp->nlp_DID);
1620 ret = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, &lpfc_ncmd->cur_iocbq);
1622 atomic_inc(&lport->xmt_fcp_wqerr);
1623 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1624 "6113 Fail IO, Could not issue WQE err %x "
1625 "sid: x%x did: x%x oxid: x%x\n",
1626 ret, vport->fc_myDID, ndlp->nlp_DID,
1627 lpfc_ncmd->cur_iocbq.sli4_xritag);
1628 goto out_free_nvme_buf;
1631 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1632 if (lpfc_ncmd->ts_cmd_start)
1633 lpfc_ncmd->ts_cmd_wqput = ktime_get_ns();
1635 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) {
1636 lpfc_ncmd->cpu = smp_processor_id();
1637 if (lpfc_ncmd->cpu != lpfc_queue_info->index) {
1638 /* Check for admin queue */
1639 if (lpfc_queue_info->qidx) {
1640 lpfc_printf_vlog(vport,
1641 KERN_ERR, LOG_NVME_IOERR,
1642 "6702 CPU Check cmd: "
1645 lpfc_queue_info->index);
1647 lpfc_ncmd->cpu = lpfc_queue_info->index;
1649 if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT)
1650 phba->cpucheck_xmt_io[lpfc_ncmd->cpu]++;
1656 if (lpfc_ncmd->nvmeCmd->sg_cnt) {
1657 if (lpfc_ncmd->nvmeCmd->io_dir == NVMEFC_FCP_WRITE)
1658 atomic_dec(&cstat->fc4NvmeOutputRequests);
1660 atomic_dec(&cstat->fc4NvmeInputRequests);
1662 atomic_dec(&cstat->fc4NvmeControlRequests);
1663 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1669 * lpfc_nvme_abort_fcreq_cmpl - Complete an NVME FCP abort request.
1670 * @phba: Pointer to HBA context object
1671 * @cmdiocb: Pointer to command iocb object.
1672 * @rspiocb: Pointer to response iocb object.
1674 * This is the callback function for any NVME FCP IO that was aborted.
1680 lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1681 struct lpfc_wcqe_complete *abts_cmpl)
1683 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
1684 "6145 ABORT_XRI_CN completing on rpi x%x "
1685 "original iotag x%x, abort cmd iotag x%x "
1686 "req_tag x%x, status x%x, hwstatus x%x\n",
1687 cmdiocb->iocb.un.acxri.abortContextTag,
1688 cmdiocb->iocb.un.acxri.abortIoTag,
1690 bf_get(lpfc_wcqe_c_request_tag, abts_cmpl),
1691 bf_get(lpfc_wcqe_c_status, abts_cmpl),
1692 bf_get(lpfc_wcqe_c_hw_status, abts_cmpl));
1693 lpfc_sli_release_iocbq(phba, cmdiocb);
1697 * lpfc_nvme_fcp_abort - Issue an NVME-over-FCP ABTS
1698 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1699 * @lpfc_nvme_lport: Pointer to the driver's local port data
1700 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1701 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1702 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1704 * Driver registers this routine as its nvme request io abort handler. This
1705 * routine issues an fcp Abort WQE with data from the @lpfc_nvme_fcpreq
1706 * data structure to the rport indicated in @lpfc_nvme_rport. This routine
1707 * is executed asynchronously - one the target is validated as "MAPPED" and
1708 * ready for IO, the driver issues the abort request and returns.
1714 lpfc_nvme_fcp_abort(struct nvme_fc_local_port *pnvme_lport,
1715 struct nvme_fc_remote_port *pnvme_rport,
1716 void *hw_queue_handle,
1717 struct nvmefc_fcp_req *pnvme_fcreq)
1719 struct lpfc_nvme_lport *lport;
1720 struct lpfc_vport *vport;
1721 struct lpfc_hba *phba;
1722 struct lpfc_nvme_buf *lpfc_nbuf;
1723 struct lpfc_iocbq *abts_buf;
1724 struct lpfc_iocbq *nvmereq_wqe;
1725 struct lpfc_nvme_fcpreq_priv *freqpriv;
1726 union lpfc_wqe128 *abts_wqe;
1727 unsigned long flags;
1730 /* Validate pointers. LLDD fault handling with transport does
1731 * have timing races.
1733 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1734 if (unlikely(!lport))
1737 vport = lport->vport;
1739 if (unlikely(!hw_queue_handle)) {
1740 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1741 "6129 Fail Abort, HW Queue Handle NULL.\n");
1746 freqpriv = pnvme_fcreq->private;
1748 if (unlikely(!freqpriv))
1750 if (vport->load_flag & FC_UNLOADING)
1753 /* Announce entry to new IO submit field. */
1754 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1755 "6002 Abort Request to rport DID x%06x "
1756 "for nvme_fc_req %p\n",
1757 pnvme_rport->port_id,
1760 /* If the hba is getting reset, this flag is set. It is
1761 * cleared when the reset is complete and rings reestablished.
1763 spin_lock_irqsave(&phba->hbalock, flags);
1764 /* driver queued commands are in process of being flushed */
1765 if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) {
1766 spin_unlock_irqrestore(&phba->hbalock, flags);
1767 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1768 "6139 Driver in reset cleanup - flushing "
1769 "NVME Req now. hba_flag x%x\n",
1774 lpfc_nbuf = freqpriv->nvme_buf;
1776 spin_unlock_irqrestore(&phba->hbalock, flags);
1777 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1778 "6140 NVME IO req has no matching lpfc nvme "
1779 "io buffer. Skipping abort req.\n");
1781 } else if (!lpfc_nbuf->nvmeCmd) {
1782 spin_unlock_irqrestore(&phba->hbalock, flags);
1783 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1784 "6141 lpfc NVME IO req has no nvme_fcreq "
1785 "io buffer. Skipping abort req.\n");
1788 nvmereq_wqe = &lpfc_nbuf->cur_iocbq;
1791 * The lpfc_nbuf and the mapped nvme_fcreq in the driver's
1792 * state must match the nvme_fcreq passed by the nvme
1793 * transport. If they don't match, it is likely the driver
1794 * has already completed the NVME IO and the nvme transport
1795 * has not seen it yet.
1797 if (lpfc_nbuf->nvmeCmd != pnvme_fcreq) {
1798 spin_unlock_irqrestore(&phba->hbalock, flags);
1799 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1800 "6143 NVME req mismatch: "
1801 "lpfc_nbuf %p nvmeCmd %p, "
1802 "pnvme_fcreq %p. Skipping Abort xri x%x\n",
1803 lpfc_nbuf, lpfc_nbuf->nvmeCmd,
1804 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1808 /* Don't abort IOs no longer on the pending queue. */
1809 if (!(nvmereq_wqe->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
1810 spin_unlock_irqrestore(&phba->hbalock, flags);
1811 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1812 "6142 NVME IO req %p not queued - skipping "
1813 "abort req xri x%x\n",
1814 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1818 atomic_inc(&lport->xmt_fcp_abort);
1819 lpfc_nvmeio_data(phba, "NVME FCP ABORT: xri x%x idx %d to %06x\n",
1820 nvmereq_wqe->sli4_xritag,
1821 nvmereq_wqe->hba_wqidx, pnvme_rport->port_id);
1823 /* Outstanding abort is in progress */
1824 if (nvmereq_wqe->iocb_flag & LPFC_DRIVER_ABORTED) {
1825 spin_unlock_irqrestore(&phba->hbalock, flags);
1826 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1827 "6144 Outstanding NVME I/O Abort Request "
1828 "still pending on nvme_fcreq %p, "
1829 "lpfc_ncmd %p xri x%x\n",
1830 pnvme_fcreq, lpfc_nbuf,
1831 nvmereq_wqe->sli4_xritag);
1835 abts_buf = __lpfc_sli_get_iocbq(phba);
1837 spin_unlock_irqrestore(&phba->hbalock, flags);
1838 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1839 "6136 No available abort wqes. Skipping "
1840 "Abts req for nvme_fcreq %p xri x%x\n",
1841 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1845 /* Ready - mark outstanding as aborted by driver. */
1846 nvmereq_wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
1848 /* Complete prepping the abort wqe and issue to the FW. */
1849 abts_wqe = &abts_buf->wqe;
1851 /* WQEs are reused. Clear stale data and set key fields to
1852 * zero like ia, iaab, iaar, xri_tag, and ctxt_tag.
1854 memset(abts_wqe, 0, sizeof(union lpfc_wqe));
1855 bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG);
1858 bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
1859 bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com,
1860 nvmereq_wqe->iocb.ulpClass);
1862 /* word 8 - tell the FW to abort the IO associated with this
1863 * outstanding exchange ID.
1865 abts_wqe->abort_cmd.wqe_com.abort_tag = nvmereq_wqe->sli4_xritag;
1867 /* word 9 - this is the iotag for the abts_wqe completion. */
1868 bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com,
1872 bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1);
1873 bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
1876 bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND);
1877 bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1);
1878 bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
1880 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
1881 abts_buf->iocb_flag |= LPFC_IO_NVME;
1882 abts_buf->hba_wqidx = nvmereq_wqe->hba_wqidx;
1883 abts_buf->vport = vport;
1884 abts_buf->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl;
1885 ret_val = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_buf);
1886 spin_unlock_irqrestore(&phba->hbalock, flags);
1888 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1889 "6137 Failed abts issue_wqe with status x%x "
1890 "for nvme_fcreq %p.\n",
1891 ret_val, pnvme_fcreq);
1892 lpfc_sli_release_iocbq(phba, abts_buf);
1896 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1897 "6138 Transport Abort NVME Request Issued for "
1898 "ox_id x%x on reqtag x%x\n",
1899 nvmereq_wqe->sli4_xritag,
1903 /* Declare and initialization an instance of the FC NVME template. */
1904 static struct nvme_fc_port_template lpfc_nvme_template = {
1905 /* initiator-based functions */
1906 .localport_delete = lpfc_nvme_localport_delete,
1907 .remoteport_delete = lpfc_nvme_remoteport_delete,
1908 .create_queue = lpfc_nvme_create_queue,
1909 .delete_queue = lpfc_nvme_delete_queue,
1910 .ls_req = lpfc_nvme_ls_req,
1911 .fcp_io = lpfc_nvme_fcp_io_submit,
1912 .ls_abort = lpfc_nvme_ls_abort,
1913 .fcp_abort = lpfc_nvme_fcp_abort,
1916 .max_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1917 .max_dif_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1918 .dma_boundary = 0xFFFFFFFF,
1920 /* Sizes of additional private data for data structures.
1921 * No use for the last two sizes at this time.
1923 .local_priv_sz = sizeof(struct lpfc_nvme_lport),
1924 .remote_priv_sz = sizeof(struct lpfc_nvme_rport),
1925 .lsrqst_priv_sz = 0,
1926 .fcprqst_priv_sz = sizeof(struct lpfc_nvme_fcpreq_priv),
1930 * lpfc_sli4_post_nvme_sgl_block - post a block of nvme sgl list to firmware
1931 * @phba: pointer to lpfc hba data structure.
1932 * @nblist: pointer to nvme buffer list.
1933 * @count: number of scsi buffers on the list.
1935 * This routine is invoked to post a block of @count scsi sgl pages from a
1936 * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
1941 lpfc_sli4_post_nvme_sgl_block(struct lpfc_hba *phba,
1942 struct list_head *nblist,
1945 struct lpfc_nvme_buf *lpfc_ncmd;
1946 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
1947 struct sgl_page_pairs *sgl_pg_pairs;
1950 uint32_t reqlen, alloclen, pg_pairs;
1952 uint16_t xritag_start = 0;
1954 uint32_t shdr_status, shdr_add_status;
1955 dma_addr_t pdma_phys_bpl1;
1956 union lpfc_sli4_cfg_shdr *shdr;
1958 /* Calculate the requested length of the dma memory */
1959 reqlen = count * sizeof(struct sgl_page_pairs) +
1960 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
1961 if (reqlen > SLI4_PAGE_SIZE) {
1962 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1963 "6118 Block sgl registration required DMA "
1964 "size (%d) great than a page\n", reqlen);
1967 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1969 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1970 "6119 Failed to allocate mbox cmd memory\n");
1974 /* Allocate DMA memory and set up the non-embedded mailbox command */
1975 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1976 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
1977 LPFC_SLI4_MBX_NEMBED);
1979 if (alloclen < reqlen) {
1980 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1981 "6120 Allocated DMA memory size (%d) is "
1982 "less than the requested DMA memory "
1983 "size (%d)\n", alloclen, reqlen);
1984 lpfc_sli4_mbox_cmd_free(phba, mbox);
1988 /* Get the first SGE entry from the non-embedded DMA memory */
1989 viraddr = mbox->sge_array->addr[0];
1991 /* Set up the SGL pages in the non-embedded DMA pages */
1992 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
1993 sgl_pg_pairs = &sgl->sgl_pg_pairs;
1996 list_for_each_entry(lpfc_ncmd, nblist, list) {
1997 /* Set up the sge entry */
1998 sgl_pg_pairs->sgl_pg0_addr_lo =
1999 cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
2000 sgl_pg_pairs->sgl_pg0_addr_hi =
2001 cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
2002 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
2003 pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
2007 sgl_pg_pairs->sgl_pg1_addr_lo =
2008 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
2009 sgl_pg_pairs->sgl_pg1_addr_hi =
2010 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
2011 /* Keep the first xritag on the list */
2013 xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
2017 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
2018 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
2019 /* Perform endian conversion if necessary */
2020 sgl->word0 = cpu_to_le32(sgl->word0);
2022 if (!phba->sli4_hba.intr_enable)
2023 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
2025 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
2026 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
2028 shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
2029 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2030 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2031 if (rc != MBX_TIMEOUT)
2032 lpfc_sli4_mbox_cmd_free(phba, mbox);
2033 if (shdr_status || shdr_add_status || rc) {
2034 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2035 "6125 POST_SGL_BLOCK mailbox command failed "
2036 "status x%x add_status x%x mbx status x%x\n",
2037 shdr_status, shdr_add_status, rc);
2044 * lpfc_post_nvme_sgl_list - Post blocks of nvme buffer sgls from a list
2045 * @phba: pointer to lpfc hba data structure.
2046 * @post_nblist: pointer to the nvme buffer list.
2048 * This routine walks a list of nvme buffers that was passed in. It attempts
2049 * to construct blocks of nvme buffer sgls which contains contiguous xris and
2050 * uses the non-embedded SGL block post mailbox commands to post to the port.
2051 * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
2052 * embedded SGL post mailbox command for posting. The @post_nblist passed in
2053 * must be local list, thus no lock is needed when manipulate the list.
2055 * Returns: 0 = failure, non-zero number of successfully posted buffers.
2058 lpfc_post_nvme_sgl_list(struct lpfc_hba *phba,
2059 struct list_head *post_nblist, int sb_count)
2061 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
2062 int status, sgl_size;
2063 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
2064 dma_addr_t pdma_phys_sgl1;
2065 int last_xritag = NO_XRI;
2067 LIST_HEAD(prep_nblist);
2068 LIST_HEAD(blck_nblist);
2069 LIST_HEAD(nvme_nblist);
2075 sgl_size = phba->cfg_sg_dma_buf_size;
2077 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
2078 list_del_init(&lpfc_ncmd->list);
2080 if ((last_xritag != NO_XRI) &&
2081 (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
2082 /* a hole in xri block, form a sgl posting block */
2083 list_splice_init(&prep_nblist, &blck_nblist);
2084 post_cnt = block_cnt - 1;
2085 /* prepare list for next posting block */
2086 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
2089 /* prepare list for next posting block */
2090 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
2091 /* enough sgls for non-embed sgl mbox command */
2092 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
2093 list_splice_init(&prep_nblist, &blck_nblist);
2094 post_cnt = block_cnt;
2099 last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
2101 /* end of repost sgl list condition for NVME buffers */
2102 if (num_posting == sb_count) {
2103 if (post_cnt == 0) {
2104 /* last sgl posting block */
2105 list_splice_init(&prep_nblist, &blck_nblist);
2106 post_cnt = block_cnt;
2107 } else if (block_cnt == 1) {
2108 /* last single sgl with non-contiguous xri */
2109 if (sgl_size > SGL_PAGE_SIZE)
2111 lpfc_ncmd->dma_phys_sgl +
2115 cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
2116 status = lpfc_sli4_post_sgl(phba,
2117 lpfc_ncmd->dma_phys_sgl,
2118 pdma_phys_sgl1, cur_xritag);
2120 /* failure, put on abort nvme list */
2121 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
2123 /* success, put on NVME buffer list */
2124 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2125 lpfc_ncmd->status = IOSTAT_SUCCESS;
2128 /* success, put on NVME buffer sgl list */
2129 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
2133 /* continue until a nembed page worth of sgls */
2137 /* post block of NVME buffer list sgls */
2138 status = lpfc_sli4_post_nvme_sgl_block(phba, &blck_nblist,
2141 /* don't reset xirtag due to hole in xri block */
2143 last_xritag = NO_XRI;
2145 /* reset NVME buffer post count for next round of posting */
2148 /* put posted NVME buffer-sgl posted on NVME buffer sgl list */
2149 while (!list_empty(&blck_nblist)) {
2150 list_remove_head(&blck_nblist, lpfc_ncmd,
2151 struct lpfc_nvme_buf, list);
2153 /* failure, put on abort nvme list */
2154 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
2156 /* success, put on NVME buffer list */
2157 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2158 lpfc_ncmd->status = IOSTAT_SUCCESS;
2161 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
2164 /* Push NVME buffers with sgl posted to the available list */
2165 while (!list_empty(&nvme_nblist)) {
2166 list_remove_head(&nvme_nblist, lpfc_ncmd,
2167 struct lpfc_nvme_buf, list);
2168 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2174 * lpfc_repost_nvme_sgl_list - Repost all the allocated nvme buffer sgls
2175 * @phba: pointer to lpfc hba data structure.
2177 * This routine walks the list of nvme buffers that have been allocated and
2178 * repost them to the port by using SGL block post. This is needed after a
2179 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
2180 * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
2181 * to the lpfc_nvme_buf_list. If the repost fails, reject all nvme buffers.
2183 * Returns: 0 = success, non-zero failure.
2186 lpfc_repost_nvme_sgl_list(struct lpfc_hba *phba)
2188 LIST_HEAD(post_nblist);
2189 int num_posted, rc = 0;
2191 /* get all NVME buffers need to repost to a local list */
2192 spin_lock_irq(&phba->nvme_buf_list_get_lock);
2193 spin_lock(&phba->nvme_buf_list_put_lock);
2194 list_splice_init(&phba->lpfc_nvme_buf_list_get, &post_nblist);
2195 list_splice(&phba->lpfc_nvme_buf_list_put, &post_nblist);
2196 phba->get_nvme_bufs = 0;
2197 phba->put_nvme_bufs = 0;
2198 spin_unlock(&phba->nvme_buf_list_put_lock);
2199 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
2201 /* post the list of nvme buffer sgls to port if available */
2202 if (!list_empty(&post_nblist)) {
2203 num_posted = lpfc_post_nvme_sgl_list(phba, &post_nblist,
2204 phba->sli4_hba.nvme_xri_cnt);
2205 /* failed to post any nvme buffer, return error */
2206 if (num_posted == 0)
2213 * lpfc_new_nvme_buf - Scsi buffer allocator for HBA with SLI4 IF spec
2214 * @vport: The virtual port for which this call being executed.
2215 * @num_to_allocate: The requested number of buffers to allocate.
2217 * This routine allocates nvme buffers for device with SLI-4 interface spec,
2218 * the nvme buffer contains all the necessary information needed to initiate
2219 * a NVME I/O. After allocating up to @num_to_allocate NVME buffers and put
2220 * them on a list, it post them to the port by using SGL block post.
2223 * int - number of nvme buffers that were allocated and posted.
2224 * 0 = failure, less than num_to_alloc is a partial failure.
2227 lpfc_new_nvme_buf(struct lpfc_vport *vport, int num_to_alloc)
2229 struct lpfc_hba *phba = vport->phba;
2230 struct lpfc_nvme_buf *lpfc_ncmd;
2231 struct lpfc_iocbq *pwqeq;
2232 union lpfc_wqe128 *wqe;
2233 struct sli4_sge *sgl;
2234 dma_addr_t pdma_phys_sgl;
2235 uint16_t iotag, lxri = 0;
2236 int bcnt, num_posted;
2237 LIST_HEAD(prep_nblist);
2238 LIST_HEAD(post_nblist);
2239 LIST_HEAD(nvme_nblist);
2241 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
2242 lpfc_ncmd = kzalloc(sizeof(struct lpfc_nvme_buf), GFP_KERNEL);
2246 * Get memory from the pci pool to map the virt space to
2247 * pci bus space for an I/O. The DMA buffer includes the
2248 * number of SGE's necessary to support the sg_tablesize.
2250 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
2252 &lpfc_ncmd->dma_handle);
2253 if (!lpfc_ncmd->data) {
2258 lxri = lpfc_sli4_next_xritag(phba);
2259 if (lxri == NO_XRI) {
2260 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
2261 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
2265 pwqeq = &(lpfc_ncmd->cur_iocbq);
2268 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
2269 iotag = lpfc_sli_next_iotag(phba, pwqeq);
2271 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
2272 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
2274 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
2275 "6121 Failed to allocated IOTAG for"
2276 " XRI:0x%x\n", lxri);
2277 lpfc_sli4_free_xri(phba, lxri);
2280 pwqeq->sli4_lxritag = lxri;
2281 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
2282 pwqeq->iocb_flag |= LPFC_IO_NVME;
2283 pwqeq->context1 = lpfc_ncmd;
2284 pwqeq->wqe_cmpl = lpfc_nvme_io_cmd_wqe_cmpl;
2286 /* Initialize local short-hand pointers. */
2287 lpfc_ncmd->nvme_sgl = lpfc_ncmd->data;
2288 sgl = lpfc_ncmd->nvme_sgl;
2289 pdma_phys_sgl = lpfc_ncmd->dma_handle;
2290 lpfc_ncmd->dma_phys_sgl = pdma_phys_sgl;
2292 /* Rsp SGE will be filled in when we rcv an IO
2293 * from the NVME Layer to be sent.
2294 * The cmd is going to be embedded so we need a SKIP SGE.
2296 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP);
2297 bf_set(lpfc_sli4_sge_last, sgl, 0);
2298 sgl->word2 = cpu_to_le32(sgl->word2);
2299 /* Fill in word 3 / sgl_len during cmd submission */
2301 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
2303 /* Initialize WQE */
2304 memset(wqe, 0, sizeof(union lpfc_wqe));
2306 /* add the nvme buffer to a post list */
2307 list_add_tail(&lpfc_ncmd->list, &post_nblist);
2308 spin_lock_irq(&phba->nvme_buf_list_get_lock);
2309 phba->sli4_hba.nvme_xri_cnt++;
2310 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
2312 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
2313 "6114 Allocate %d out of %d requested new NVME "
2314 "buffers\n", bcnt, num_to_alloc);
2316 /* post the list of nvme buffer sgls to port if available */
2317 if (!list_empty(&post_nblist))
2318 num_posted = lpfc_post_nvme_sgl_list(phba,
2319 &post_nblist, bcnt);
2326 static inline struct lpfc_nvme_buf *
2327 lpfc_nvme_buf(struct lpfc_hba *phba)
2329 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
2331 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
2332 &phba->lpfc_nvme_buf_list_get, list) {
2333 list_del_init(&lpfc_ncmd->list);
2334 phba->get_nvme_bufs--;
2341 * lpfc_get_nvme_buf - Get a nvme buffer from lpfc_nvme_buf_list of the HBA
2342 * @phba: The HBA for which this call is being executed.
2344 * This routine removes a nvme buffer from head of @phba lpfc_nvme_buf_list list
2345 * and returns to caller.
2349 * Pointer to lpfc_nvme_buf - Success
2351 static struct lpfc_nvme_buf *
2352 lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
2355 struct lpfc_nvme_buf *lpfc_ncmd = NULL;
2356 unsigned long iflag = 0;
2358 spin_lock_irqsave(&phba->nvme_buf_list_get_lock, iflag);
2359 if (phba->get_nvme_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
2360 lpfc_ncmd = lpfc_nvme_buf(phba);
2362 spin_lock(&phba->nvme_buf_list_put_lock);
2363 list_splice(&phba->lpfc_nvme_buf_list_put,
2364 &phba->lpfc_nvme_buf_list_get);
2365 phba->get_nvme_bufs += phba->put_nvme_bufs;
2366 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
2367 phba->put_nvme_bufs = 0;
2368 spin_unlock(&phba->nvme_buf_list_put_lock);
2369 if (phba->get_nvme_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
2370 lpfc_ncmd = lpfc_nvme_buf(phba);
2372 spin_unlock_irqrestore(&phba->nvme_buf_list_get_lock, iflag);
2374 if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_ncmd) {
2375 atomic_inc(&ndlp->cmd_pending);
2376 lpfc_ncmd->flags |= LPFC_BUMP_QDEPTH;
2382 * lpfc_release_nvme_buf: Return a nvme buffer back to hba nvme buf list.
2383 * @phba: The Hba for which this call is being executed.
2384 * @lpfc_ncmd: The nvme buffer which is being released.
2386 * This routine releases @lpfc_ncmd nvme buffer by adding it to tail of @phba
2387 * lpfc_nvme_buf_list list. For SLI4 XRI's are tied to the nvme buffer
2388 * and cannot be reused for at least RA_TOV amount of time if it was
2392 lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_nvme_buf *lpfc_ncmd)
2394 unsigned long iflag = 0;
2396 if ((lpfc_ncmd->flags & LPFC_BUMP_QDEPTH) && lpfc_ncmd->ndlp)
2397 atomic_dec(&lpfc_ncmd->ndlp->cmd_pending);
2399 lpfc_ncmd->nonsg_phys = 0;
2400 lpfc_ncmd->ndlp = NULL;
2401 lpfc_ncmd->flags &= ~LPFC_BUMP_QDEPTH;
2403 if (lpfc_ncmd->flags & LPFC_SBUF_XBUSY) {
2404 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2405 "6310 XB release deferred for "
2406 "ox_id x%x on reqtag x%x\n",
2407 lpfc_ncmd->cur_iocbq.sli4_xritag,
2408 lpfc_ncmd->cur_iocbq.iotag);
2410 spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock,
2412 list_add_tail(&lpfc_ncmd->list,
2413 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
2414 spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock,
2417 lpfc_ncmd->nvmeCmd = NULL;
2418 lpfc_ncmd->cur_iocbq.iocb_flag = LPFC_IO_NVME;
2419 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
2420 list_add_tail(&lpfc_ncmd->list, &phba->lpfc_nvme_buf_list_put);
2421 phba->put_nvme_bufs++;
2422 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
2427 * lpfc_nvme_create_localport - Create/Bind an nvme localport instance.
2428 * @pvport - the lpfc_vport instance requesting a localport.
2430 * This routine is invoked to create an nvme localport instance to bind
2431 * to the nvme_fc_transport. It is called once during driver load
2432 * like lpfc_create_shost after all other services are initialized.
2433 * It requires a vport, vpi, and wwns at call time. Other localport
2434 * parameters are modified as the driver's FCID and the Fabric WWN
2439 * -ENOMEM - no heap memory available
2440 * other values - from nvme registration upcall
2443 lpfc_nvme_create_localport(struct lpfc_vport *vport)
2446 struct lpfc_hba *phba = vport->phba;
2447 struct nvme_fc_port_info nfcp_info;
2448 struct nvme_fc_local_port *localport;
2449 struct lpfc_nvme_lport *lport;
2450 struct lpfc_nvme_ctrl_stat *cstat;
2453 /* Initialize this localport instance. The vport wwn usage ensures
2454 * that NPIV is accounted for.
2456 memset(&nfcp_info, 0, sizeof(struct nvme_fc_port_info));
2457 nfcp_info.port_role = FC_PORT_ROLE_NVME_INITIATOR;
2458 nfcp_info.node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
2459 nfcp_info.port_name = wwn_to_u64(vport->fc_portname.u.wwn);
2461 /* We need to tell the transport layer + 1 because it takes page
2462 * alignment into account. When space for the SGL is allocated we
2463 * allocate + 3, one for cmd, one for rsp and one for this alignment
2465 lpfc_nvme_template.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1;
2466 lpfc_nvme_template.max_hw_queues = phba->cfg_nvme_io_channel;
2468 cstat = kmalloc((sizeof(struct lpfc_nvme_ctrl_stat) *
2469 phba->cfg_nvme_io_channel), GFP_KERNEL);
2473 /* localport is allocated from the stack, but the registration
2474 * call allocates heap memory as well as the private area.
2476 #if (IS_ENABLED(CONFIG_NVME_FC))
2477 ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template,
2478 &vport->phba->pcidev->dev, &localport);
2483 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC,
2484 "6005 Successfully registered local "
2485 "NVME port num %d, localP %p, private %p, "
2487 localport->port_num, localport,
2489 lpfc_nvme_template.max_sgl_segments);
2491 /* Private is our lport size declared in the template. */
2492 lport = (struct lpfc_nvme_lport *)localport->private;
2493 vport->localport = localport;
2494 lport->vport = vport;
2495 lport->cstat = cstat;
2496 vport->nvmei_support = 1;
2498 atomic_set(&lport->xmt_fcp_noxri, 0);
2499 atomic_set(&lport->xmt_fcp_bad_ndlp, 0);
2500 atomic_set(&lport->xmt_fcp_qdepth, 0);
2501 atomic_set(&lport->xmt_fcp_err, 0);
2502 atomic_set(&lport->xmt_fcp_wqerr, 0);
2503 atomic_set(&lport->xmt_fcp_abort, 0);
2504 atomic_set(&lport->xmt_ls_abort, 0);
2505 atomic_set(&lport->xmt_ls_err, 0);
2506 atomic_set(&lport->cmpl_fcp_xb, 0);
2507 atomic_set(&lport->cmpl_fcp_err, 0);
2508 atomic_set(&lport->cmpl_ls_xb, 0);
2509 atomic_set(&lport->cmpl_ls_err, 0);
2510 atomic_set(&lport->fc4NvmeLsRequests, 0);
2511 atomic_set(&lport->fc4NvmeLsCmpls, 0);
2513 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
2514 cstat = &lport->cstat[i];
2515 atomic_set(&cstat->fc4NvmeInputRequests, 0);
2516 atomic_set(&cstat->fc4NvmeOutputRequests, 0);
2517 atomic_set(&cstat->fc4NvmeControlRequests, 0);
2518 atomic_set(&cstat->fc4NvmeIoCmpls, 0);
2521 /* Don't post more new bufs if repost already recovered
2524 if (phba->sli4_hba.nvme_xri_cnt == 0) {
2525 len = lpfc_new_nvme_buf(vport,
2526 phba->sli4_hba.nvme_xri_max);
2527 vport->phba->total_nvme_bufs += len;
2536 /* lpfc_nvme_lport_unreg_wait - Wait for the host to complete an lport unreg.
2538 * The driver has to wait for the host nvme transport to callback
2539 * indicating the localport has successfully unregistered all
2540 * resources. Since this is an uninterruptible wait, loop every ten
2541 * seconds and print a message indicating no progress.
2543 * An uninterruptible wait is used because of the risk of transport-to-
2544 * driver state mismatch.
2547 lpfc_nvme_lport_unreg_wait(struct lpfc_vport *vport,
2548 struct lpfc_nvme_lport *lport)
2550 #if (IS_ENABLED(CONFIG_NVME_FC))
2554 /* Host transport has to clean up and confirm requiring an indefinite
2555 * wait. Print a message if a 10 second wait expires and renew the
2556 * wait. This is unexpected.
2558 wait_tmo = msecs_to_jiffies(LPFC_NVME_WAIT_TMO * 1000);
2560 ret = wait_for_completion_timeout(&lport->lport_unreg_done,
2562 if (unlikely(!ret)) {
2563 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
2564 "6176 Lport %p Localport %p wait "
2565 "timed out. Renewing.\n",
2566 lport, vport->localport);
2571 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
2572 "6177 Lport %p Localport %p Complete Success\n",
2573 lport, vport->localport);
2578 * lpfc_nvme_destroy_localport - Destroy lpfc_nvme bound to nvme transport.
2579 * @pnvme: pointer to lpfc nvme data structure.
2581 * This routine is invoked to destroy all lports bound to the phba.
2582 * The lport memory was allocated by the nvme fc transport and is
2583 * released there. This routine ensures all rports bound to the
2584 * lport have been disconnected.
2588 lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2590 #if (IS_ENABLED(CONFIG_NVME_FC))
2591 struct nvme_fc_local_port *localport;
2592 struct lpfc_nvme_lport *lport;
2593 struct lpfc_nvme_ctrl_stat *cstat;
2596 if (vport->nvmei_support == 0)
2599 localport = vport->localport;
2600 vport->localport = NULL;
2601 lport = (struct lpfc_nvme_lport *)localport->private;
2602 cstat = lport->cstat;
2604 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2605 "6011 Destroying NVME localport %p\n",
2608 /* lport's rport list is clear. Unregister
2609 * lport and release resources.
2611 init_completion(&lport->lport_unreg_done);
2612 ret = nvme_fc_unregister_localport(localport);
2614 /* Wait for completion. This either blocks
2615 * indefinitely or succeeds
2617 lpfc_nvme_lport_unreg_wait(vport, lport);
2620 /* Regardless of the unregister upcall response, clear
2621 * nvmei_support. All rports are unregistered and the
2622 * driver will clean up.
2624 vport->nvmei_support = 0;
2626 lpfc_printf_vlog(vport,
2627 KERN_INFO, LOG_NVME_DISC,
2628 "6009 Unregistered lport Success\n");
2630 lpfc_printf_vlog(vport,
2631 KERN_INFO, LOG_NVME_DISC,
2632 "6010 Unregistered lport "
2633 "Failed, status x%x\n",
2640 lpfc_nvme_update_localport(struct lpfc_vport *vport)
2642 #if (IS_ENABLED(CONFIG_NVME_FC))
2643 struct nvme_fc_local_port *localport;
2644 struct lpfc_nvme_lport *lport;
2646 localport = vport->localport;
2648 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2649 "6710 Update NVME fail. No localport\n");
2652 lport = (struct lpfc_nvme_lport *)localport->private;
2654 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2655 "6171 Update NVME fail. localP %p, No lport\n",
2659 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2660 "6012 Update NVME lport %p did x%x\n",
2661 localport, vport->fc_myDID);
2663 localport->port_id = vport->fc_myDID;
2664 if (localport->port_id == 0)
2665 localport->port_role = FC_PORT_ROLE_NVME_DISCOVERY;
2667 localport->port_role = FC_PORT_ROLE_NVME_INITIATOR;
2669 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2670 "6030 bound lport %p to DID x%06x\n",
2671 lport, localport->port_id);
2676 lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2678 #if (IS_ENABLED(CONFIG_NVME_FC))
2680 struct nvme_fc_local_port *localport;
2681 struct lpfc_nvme_lport *lport;
2682 struct lpfc_nvme_rport *rport;
2683 struct lpfc_nvme_rport *oldrport;
2684 struct nvme_fc_remote_port *remote_port;
2685 struct nvme_fc_port_info rpinfo;
2686 struct lpfc_nodelist *prev_ndlp = NULL;
2688 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC,
2689 "6006 Register NVME PORT. DID x%06x nlptype x%x\n",
2690 ndlp->nlp_DID, ndlp->nlp_type);
2692 localport = vport->localport;
2696 lport = (struct lpfc_nvme_lport *)localport->private;
2698 /* NVME rports are not preserved across devloss.
2699 * Just register this instance. Note, rpinfo->dev_loss_tmo
2700 * is left 0 to indicate accept transport defaults. The
2701 * driver communicates port role capabilities consistent
2702 * with the PRLI response data.
2704 memset(&rpinfo, 0, sizeof(struct nvme_fc_port_info));
2705 rpinfo.port_id = ndlp->nlp_DID;
2706 if (ndlp->nlp_type & NLP_NVME_TARGET)
2707 rpinfo.port_role |= FC_PORT_ROLE_NVME_TARGET;
2708 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
2709 rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR;
2711 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
2712 rpinfo.port_role |= FC_PORT_ROLE_NVME_DISCOVERY;
2714 rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
2715 rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
2717 spin_lock_irq(&vport->phba->hbalock);
2718 oldrport = lpfc_ndlp_get_nrport(ndlp);
2719 spin_unlock_irq(&vport->phba->hbalock);
2723 ret = nvme_fc_register_remoteport(localport, &rpinfo, &remote_port);
2725 /* If the ndlp already has an nrport, this is just
2726 * a resume of the existing rport. Else this is a
2729 /* Guard against an unregister/reregister
2730 * race that leaves the WAIT flag set.
2732 spin_lock_irq(&vport->phba->hbalock);
2733 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
2734 spin_unlock_irq(&vport->phba->hbalock);
2735 rport = remote_port->private;
2737 /* New remoteport record does not guarantee valid
2738 * host private memory area.
2740 prev_ndlp = oldrport->ndlp;
2741 if (oldrport == remote_port->private) {
2742 /* Same remoteport - ndlp should match.
2745 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2747 "6014 Rebinding lport to "
2748 "remoteport %p wwpn 0x%llx, "
2749 "Data: x%x x%x %p %p x%x x%06x\n",
2751 remote_port->port_name,
2752 remote_port->port_id,
2753 remote_port->port_role,
2761 /* Sever the ndlp<->rport association
2762 * before dropping the ndlp ref from
2765 spin_lock_irq(&vport->phba->hbalock);
2766 ndlp->nrport = NULL;
2767 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
2768 spin_unlock_irq(&vport->phba->hbalock);
2770 rport->remoteport = NULL;
2772 /* Reference only removed if previous NDLP is no longer
2773 * active. It might be just a swap and removing the
2774 * reference would cause a premature cleanup.
2776 if (prev_ndlp && prev_ndlp != ndlp) {
2777 if ((!NLP_CHK_NODE_ACT(prev_ndlp)) ||
2778 (!prev_ndlp->nrport))
2779 lpfc_nlp_put(prev_ndlp);
2783 /* Clean bind the rport to the ndlp. */
2784 rport->remoteport = remote_port;
2785 rport->lport = lport;
2787 spin_lock_irq(&vport->phba->hbalock);
2788 ndlp->nrport = rport;
2789 spin_unlock_irq(&vport->phba->hbalock);
2790 lpfc_printf_vlog(vport, KERN_INFO,
2791 LOG_NVME_DISC | LOG_NODE,
2792 "6022 Binding new rport to "
2793 "lport %p Remoteport %p rport %p WWNN 0x%llx, "
2794 "Rport WWPN 0x%llx DID "
2795 "x%06x Role x%x, ndlp %p prev_ndlp %p\n",
2796 lport, remote_port, rport,
2797 rpinfo.node_name, rpinfo.port_name,
2798 rpinfo.port_id, rpinfo.port_role,
2801 lpfc_printf_vlog(vport, KERN_ERR,
2802 LOG_NVME_DISC | LOG_NODE,
2803 "6031 RemotePort Registration failed "
2804 "err: %d, DID x%06x\n",
2805 ret, ndlp->nlp_DID);
2814 /* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport.
2816 * There is no notion of Devloss or rport recovery from the current
2817 * nvme_transport perspective. Loss of an rport just means IO cannot
2818 * be sent and recovery is completely up to the initator.
2819 * For now, the driver just unbinds the DID and port_role so that
2820 * no further IO can be issued. Changes are planned for later.
2822 * Notes - the ndlp reference count is not decremented here since
2823 * since there is no nvme_transport api for devloss. Node ref count
2824 * is only adjusted in driver unload.
2827 lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2829 #if (IS_ENABLED(CONFIG_NVME_FC))
2831 struct nvme_fc_local_port *localport;
2832 struct lpfc_nvme_lport *lport;
2833 struct lpfc_nvme_rport *rport;
2834 struct nvme_fc_remote_port *remoteport = NULL;
2836 localport = vport->localport;
2838 /* This is fundamental error. The localport is always
2839 * available until driver unload. Just exit.
2844 lport = (struct lpfc_nvme_lport *)localport->private;
2848 spin_lock_irq(&vport->phba->hbalock);
2849 rport = lpfc_ndlp_get_nrport(ndlp);
2851 remoteport = rport->remoteport;
2852 spin_unlock_irq(&vport->phba->hbalock);
2856 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2857 "6033 Unreg nvme remoteport %p, portname x%llx, "
2858 "port_id x%06x, portstate x%x port type x%x\n",
2859 remoteport, remoteport->port_name,
2860 remoteport->port_id, remoteport->port_state,
2863 /* Sanity check ndlp type. Only call for NVME ports. Don't
2864 * clear any rport state until the transport calls back.
2867 if (ndlp->nlp_type & NLP_NVME_TARGET) {
2868 /* No concern about the role change on the nvme remoteport.
2869 * The transport will update it.
2871 ndlp->upcall_flags |= NLP_WAIT_FOR_UNREG;
2873 /* Don't let the host nvme transport keep sending keep-alives
2874 * on this remoteport. Vport is unloading, no recovery. The
2875 * return values is ignored. The upcall is a courtesy to the
2878 if (vport->load_flag & FC_UNLOADING)
2879 (void)nvme_fc_set_remoteport_devloss(remoteport, 0);
2881 ret = nvme_fc_unregister_remoteport(remoteport);
2884 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2885 "6167 NVME unregister failed %d "
2887 ret, remoteport->port_state);
2894 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2895 "6168 State error: lport %p, rport%p FCID x%06x\n",
2896 vport->localport, ndlp->rport, ndlp->nlp_DID);
2900 * lpfc_sli4_nvme_xri_aborted - Fast-path process of NVME xri abort
2901 * @phba: pointer to lpfc hba data structure.
2902 * @axri: pointer to the fcp xri abort wcqe structure.
2904 * This routine is invoked by the worker thread to process a SLI4 fast-path
2905 * NVME aborted xri. Aborted NVME IO commands are completed to the transport
2909 lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba,
2910 struct sli4_wcqe_xri_aborted *axri)
2912 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
2913 struct lpfc_nvme_buf *lpfc_ncmd, *next_lpfc_ncmd;
2914 struct nvmefc_fcp_req *nvme_cmd = NULL;
2915 struct lpfc_nodelist *ndlp;
2916 unsigned long iflag = 0;
2918 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
2920 spin_lock_irqsave(&phba->hbalock, iflag);
2921 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2922 list_for_each_entry_safe(lpfc_ncmd, next_lpfc_ncmd,
2923 &phba->sli4_hba.lpfc_abts_nvme_buf_list,
2925 if (lpfc_ncmd->cur_iocbq.sli4_xritag == xri) {
2926 list_del_init(&lpfc_ncmd->list);
2927 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2928 lpfc_ncmd->status = IOSTAT_SUCCESS;
2930 &phba->sli4_hba.abts_nvme_buf_list_lock);
2932 spin_unlock_irqrestore(&phba->hbalock, iflag);
2933 ndlp = lpfc_ncmd->ndlp;
2935 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
2937 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2938 "6311 nvme_cmd %p xri x%x tag x%x "
2939 "abort complete and xri released\n",
2940 lpfc_ncmd->nvmeCmd, xri,
2941 lpfc_ncmd->cur_iocbq.iotag);
2943 /* Aborted NVME commands are required to not complete
2944 * before the abort exchange command fully completes.
2945 * Once completed, it is available via the put list.
2947 if (lpfc_ncmd->nvmeCmd) {
2948 nvme_cmd = lpfc_ncmd->nvmeCmd;
2949 nvme_cmd->done(nvme_cmd);
2950 lpfc_ncmd->nvmeCmd = NULL;
2952 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2956 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2957 spin_unlock_irqrestore(&phba->hbalock, iflag);
2959 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2960 "6312 XRI Aborted xri x%x not found\n", xri);
2965 * lpfc_nvme_wait_for_io_drain - Wait for all NVME wqes to complete
2966 * @phba: Pointer to HBA context object.
2968 * This function flushes all wqes in the nvme rings and frees all resources
2969 * in the txcmplq. This function does not issue abort wqes for the IO
2970 * commands in txcmplq, they will just be returned with
2971 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
2972 * slot has been permanently disabled.
2975 lpfc_nvme_wait_for_io_drain(struct lpfc_hba *phba)
2977 struct lpfc_sli_ring *pring;
2978 u32 i, wait_cnt = 0;
2980 if (phba->sli_rev < LPFC_SLI_REV4 || !phba->sli4_hba.nvme_wq)
2983 /* Cycle through all NVME rings and make sure all outstanding
2984 * WQEs have been removed from the txcmplqs.
2986 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
2987 pring = phba->sli4_hba.nvme_wq[i]->pring;
2992 /* Retrieve everything on the txcmplq */
2993 while (!list_empty(&pring->txcmplq)) {
2994 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
2997 /* The sleep is 10mS. Every ten seconds,
2998 * dump a message. Something is wrong.
3000 if ((wait_cnt % 1000) == 0) {
3001 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
3002 "6178 NVME IO not empty, "
3003 "cnt %d\n", wait_cnt);