1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2019 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_io_buf *
60 lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
61 int idx, int expedite);
64 lpfc_release_nvme_buf(struct lpfc_hba *, struct lpfc_io_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_prep_abort_wqe - set up 'abort' work queue entry.
200 * @pwqeq: Pointer to command iocb.
201 * @xritag: Tag that uniqely identifies the local exchange resource.
202 * @opt: Option bits -
203 * bit 0 = inhibit sending abts on the link
205 * This function is called with hbalock held.
208 lpfc_nvme_prep_abort_wqe(struct lpfc_iocbq *pwqeq, u16 xritag, u8 opt)
210 union lpfc_wqe128 *wqe = &pwqeq->wqe;
212 /* WQEs are reused. Clear stale data and set key fields to
213 * zero like ia, iaab, iaar, xri_tag, and ctxt_tag.
215 memset(wqe, 0, sizeof(*wqe));
217 if (opt & INHIBIT_ABORT)
218 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
219 /* Abort specified xri tag, with the mask deliberately zeroed */
220 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
222 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
224 /* Abort the IO associated with this outstanding exchange ID. */
225 wqe->abort_cmd.wqe_com.abort_tag = xritag;
227 /* iotag for the wqe completion. */
228 bf_set(wqe_reqtag, &wqe->abort_cmd.wqe_com, pwqeq->iotag);
230 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
231 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
233 bf_set(wqe_cmd_type, &wqe->abort_cmd.wqe_com, OTHER_COMMAND);
234 bf_set(wqe_wqec, &wqe->abort_cmd.wqe_com, 1);
235 bf_set(wqe_cqid, &wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
239 * lpfc_nvme_create_queue -
240 * @lpfc_pnvme: Pointer to the driver's nvme instance data
241 * @qidx: An cpu index used to affinitize IO queues and MSIX vectors.
242 * @handle: An opaque driver handle used in follow-up calls.
244 * Driver registers this routine to preallocate and initialize any
245 * internal data structures to bind the @qidx to its internal IO queues.
246 * A hardware queue maps (qidx) to a specific driver MSI-X vector/EQ/CQ/WQ.
250 * -EINVAL - Unsupported input value.
251 * -ENOMEM - Could not alloc necessary memory
254 lpfc_nvme_create_queue(struct nvme_fc_local_port *pnvme_lport,
255 unsigned int qidx, u16 qsize,
258 struct lpfc_nvme_lport *lport;
259 struct lpfc_vport *vport;
260 struct lpfc_nvme_qhandle *qhandle;
263 if (!pnvme_lport->private)
266 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
267 vport = lport->vport;
268 qhandle = kzalloc(sizeof(struct lpfc_nvme_qhandle), GFP_KERNEL);
272 qhandle->cpu_id = raw_smp_processor_id();
273 qhandle->qidx = qidx;
275 * NVME qidx == 0 is the admin queue, so both admin queue
276 * and first IO queue will use MSI-X vector and associated
277 * EQ/CQ/WQ at index 0. After that they are sequentially assigned.
280 str = "IO "; /* IO queue */
281 qhandle->index = ((qidx - 1) %
282 lpfc_nvme_template.max_hw_queues);
284 str = "ADM"; /* Admin queue */
285 qhandle->index = qidx;
288 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
289 "6073 Binding %s HdwQueue %d (cpu %d) to "
290 "hdw_queue %d qhandle x%px\n", str,
291 qidx, qhandle->cpu_id, qhandle->index, qhandle);
292 *handle = (void *)qhandle;
297 * lpfc_nvme_delete_queue -
298 * @lpfc_pnvme: Pointer to the driver's nvme instance data
299 * @qidx: An cpu index used to affinitize IO queues and MSIX vectors.
300 * @handle: An opaque driver handle from lpfc_nvme_create_queue
302 * Driver registers this routine to free
303 * any internal data structures to bind the @qidx to its internal
308 * TODO: What are the failure codes.
311 lpfc_nvme_delete_queue(struct nvme_fc_local_port *pnvme_lport,
315 struct lpfc_nvme_lport *lport;
316 struct lpfc_vport *vport;
318 if (!pnvme_lport->private)
321 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
322 vport = lport->vport;
324 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
325 "6001 ENTER. lpfc_pnvme x%px, qidx x%x qhandle x%px\n",
326 lport, qidx, handle);
331 lpfc_nvme_localport_delete(struct nvme_fc_local_port *localport)
333 struct lpfc_nvme_lport *lport = localport->private;
335 lpfc_printf_vlog(lport->vport, KERN_INFO, LOG_NVME,
336 "6173 localport x%px delete complete\n",
339 /* release any threads waiting for the unreg to complete */
340 if (lport->vport->localport)
341 complete(lport->lport_unreg_cmp);
344 /* lpfc_nvme_remoteport_delete
346 * @remoteport: Pointer to an nvme transport remoteport instance.
348 * This is a template downcall. NVME transport calls this function
349 * when it has completed the unregistration of a previously
350 * registered remoteport.
356 lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport)
358 struct lpfc_nvme_rport *rport = remoteport->private;
359 struct lpfc_vport *vport;
360 struct lpfc_nodelist *ndlp;
370 /* Remove this rport from the lport's list - memory is owned by the
371 * transport. Remove the ndlp reference for the NVME transport before
372 * calling state machine to remove the node.
374 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
375 "6146 remoteport delete of remoteport x%px\n",
377 spin_lock_irq(&vport->phba->hbalock);
379 /* The register rebind might have occurred before the delete
380 * downcall. Guard against this race.
382 if (ndlp->upcall_flags & NLP_WAIT_FOR_UNREG) {
384 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
385 spin_unlock_irq(&vport->phba->hbalock);
387 /* Remove original register reference. The host transport
388 * won't reference this rport/remoteport any further.
392 spin_unlock_irq(&vport->phba->hbalock);
400 lpfc_nvme_cmpl_gen_req(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
401 struct lpfc_wcqe_complete *wcqe)
403 struct lpfc_vport *vport = cmdwqe->vport;
404 struct lpfc_nvme_lport *lport;
406 struct nvmefc_ls_req *pnvme_lsreq;
407 struct lpfc_dmabuf *buf_ptr;
408 struct lpfc_nodelist *ndlp;
410 pnvme_lsreq = (struct nvmefc_ls_req *)cmdwqe->context2;
411 status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK;
413 if (vport->localport) {
414 lport = (struct lpfc_nvme_lport *)vport->localport->private;
416 atomic_inc(&lport->fc4NvmeLsCmpls);
418 if (bf_get(lpfc_wcqe_c_xb, wcqe))
419 atomic_inc(&lport->cmpl_ls_xb);
420 atomic_inc(&lport->cmpl_ls_err);
425 ndlp = (struct lpfc_nodelist *)cmdwqe->context1;
426 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
427 "6047 nvme cmpl Enter "
428 "Data %px DID %x Xri: %x status %x reason x%x "
429 "cmd:x%px lsreg:x%px bmp:x%px ndlp:x%px\n",
430 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
431 cmdwqe->sli4_xritag, status,
432 (wcqe->parameter & 0xffff),
433 cmdwqe, pnvme_lsreq, cmdwqe->context3, ndlp);
435 lpfc_nvmeio_data(phba, "NVME LS CMPL: xri x%x stat x%x parm x%x\n",
436 cmdwqe->sli4_xritag, status, wcqe->parameter);
438 if (cmdwqe->context3) {
439 buf_ptr = (struct lpfc_dmabuf *)cmdwqe->context3;
440 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
442 cmdwqe->context3 = NULL;
444 if (pnvme_lsreq->done)
445 pnvme_lsreq->done(pnvme_lsreq, status);
447 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
448 "6046 nvme cmpl without done call back? "
449 "Data %px DID %x Xri: %x status %x\n",
450 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
451 cmdwqe->sli4_xritag, status);
454 cmdwqe->context1 = NULL;
456 lpfc_sli_release_iocbq(phba, cmdwqe);
460 lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
461 struct lpfc_dmabuf *inp,
462 struct nvmefc_ls_req *pnvme_lsreq,
463 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
464 struct lpfc_wcqe_complete *),
465 struct lpfc_nodelist *ndlp, uint32_t num_entry,
466 uint32_t tmo, uint8_t retry)
468 struct lpfc_hba *phba = vport->phba;
469 union lpfc_wqe128 *wqe;
470 struct lpfc_iocbq *genwqe;
471 struct ulp_bde64 *bpl;
472 struct ulp_bde64 bde;
473 int i, rc, xmit_len, first_len;
475 /* Allocate buffer for command WQE */
476 genwqe = lpfc_sli_get_iocbq(phba);
481 /* Initialize only 64 bytes */
482 memset(wqe, 0, sizeof(union lpfc_wqe));
484 genwqe->context3 = (uint8_t *)bmp;
485 genwqe->iocb_flag |= LPFC_IO_NVME_LS;
487 /* Save for completion so we can release these resources */
488 genwqe->context1 = lpfc_nlp_get(ndlp);
489 genwqe->context2 = (uint8_t *)pnvme_lsreq;
490 /* Fill in payload, bp points to frame payload */
493 /* FC spec states we need 3 * ratov for CT requests */
494 tmo = (3 * phba->fc_ratov);
496 /* For this command calculate the xmit length of the request bde. */
499 bpl = (struct ulp_bde64 *)bmp->virt;
500 for (i = 0; i < num_entry; i++) {
501 bde.tus.w = bpl[i].tus.w;
502 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
504 xmit_len += bde.tus.f.bdeSize;
506 first_len = xmit_len;
509 genwqe->rsvd2 = num_entry;
510 genwqe->hba_wqidx = 0;
513 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
514 wqe->generic.bde.tus.f.bdeSize = first_len;
515 wqe->generic.bde.addrLow = bpl[0].addrLow;
516 wqe->generic.bde.addrHigh = bpl[0].addrHigh;
519 wqe->gen_req.request_payload_len = first_len;
524 bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0);
525 bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1);
526 bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1);
527 bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_ELS4_REQ);
528 bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME);
531 bf_set(wqe_ctxt_tag, &wqe->gen_req.wqe_com,
532 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
533 bf_set(wqe_xri_tag, &wqe->gen_req.wqe_com, genwqe->sli4_xritag);
536 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, (vport->phba->fc_ratov-1));
537 bf_set(wqe_class, &wqe->gen_req.wqe_com, CLASS3);
538 bf_set(wqe_cmnd, &wqe->gen_req.wqe_com, CMD_GEN_REQUEST64_WQE);
539 bf_set(wqe_ct, &wqe->gen_req.wqe_com, SLI4_CT_RPI);
542 wqe->gen_req.wqe_com.abort_tag = genwqe->iotag;
545 bf_set(wqe_reqtag, &wqe->gen_req.wqe_com, genwqe->iotag);
548 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
549 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
550 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
551 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
552 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
555 bf_set(wqe_cqid, &wqe->gen_req.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
556 bf_set(wqe_cmd_type, &wqe->gen_req.wqe_com, OTHER_COMMAND);
559 /* Issue GEN REQ WQE for NPORT <did> */
560 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
561 "6050 Issue GEN REQ WQE to NPORT x%x "
562 "Data: x%x x%x wq:x%px lsreq:x%px bmp:x%px "
564 ndlp->nlp_DID, genwqe->iotag,
566 genwqe, pnvme_lsreq, bmp, xmit_len, first_len);
567 genwqe->wqe_cmpl = cmpl;
568 genwqe->iocb_cmpl = NULL;
569 genwqe->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT;
570 genwqe->vport = vport;
571 genwqe->retry = retry;
573 lpfc_nvmeio_data(phba, "NVME LS XMIT: xri x%x iotag x%x to x%06x\n",
574 genwqe->sli4_xritag, genwqe->iotag, ndlp->nlp_DID);
576 rc = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[0], genwqe);
578 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
579 "6045 Issue GEN REQ WQE to NPORT x%x "
581 ndlp->nlp_DID, genwqe->iotag,
583 lpfc_sli_release_iocbq(phba, genwqe);
590 * lpfc_nvme_ls_req - Issue an Link Service request
591 * @lpfc_pnvme: Pointer to the driver's nvme instance data
592 * @lpfc_nvme_lport: Pointer to the driver's local port data
593 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
595 * Driver registers this routine to handle any link service request
596 * from the nvme_fc transport to a remote nvme-aware port.
600 * TODO: What are the failure codes.
603 lpfc_nvme_ls_req(struct nvme_fc_local_port *pnvme_lport,
604 struct nvme_fc_remote_port *pnvme_rport,
605 struct nvmefc_ls_req *pnvme_lsreq)
608 struct lpfc_nvme_lport *lport;
609 struct lpfc_nvme_rport *rport;
610 struct lpfc_vport *vport;
611 struct lpfc_nodelist *ndlp;
612 struct ulp_bde64 *bpl;
613 struct lpfc_dmabuf *bmp;
614 uint16_t ntype, nstate;
616 /* there are two dma buf in the request, actually there is one and
617 * the second one is just the start address + cmd size.
618 * Before calling lpfc_nvme_gen_req these buffers need to be wrapped
619 * in a lpfc_dmabuf struct. When freeing we just free the wrapper
620 * because the nvem layer owns the data bufs.
621 * We do not have to break these packets open, we don't care what is in
622 * them. And we do not have to look at the resonse data, we only care
623 * that we got a response. All of the caring is going to happen in the
627 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
628 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
629 if (unlikely(!lport) || unlikely(!rport))
632 vport = lport->vport;
634 if (vport->load_flag & FC_UNLOADING)
637 /* Need the ndlp. It is stored in the driver's rport. */
639 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
640 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
641 "6051 Remoteport x%px, rport has invalid ndlp. "
642 "Failing LS Req\n", pnvme_rport);
646 /* The remote node has to be a mapped nvme target or an
647 * unmapped nvme initiator or it's an error.
649 ntype = ndlp->nlp_type;
650 nstate = ndlp->nlp_state;
651 if ((ntype & NLP_NVME_TARGET && nstate != NLP_STE_MAPPED_NODE) ||
652 (ntype & NLP_NVME_INITIATOR && nstate != NLP_STE_UNMAPPED_NODE)) {
653 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
654 "6088 DID x%06x not ready for "
655 "IO. State x%x, Type x%x\n",
656 pnvme_rport->port_id,
657 ndlp->nlp_state, ndlp->nlp_type);
660 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
663 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
664 "6044 Could not find node for DID %x\n",
665 pnvme_rport->port_id);
668 INIT_LIST_HEAD(&bmp->list);
669 bmp->virt = lpfc_mbuf_alloc(vport->phba, MEM_PRI, &(bmp->phys));
671 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
672 "6042 Could not find node for DID %x\n",
673 pnvme_rport->port_id);
677 bpl = (struct ulp_bde64 *)bmp->virt;
678 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rqstdma));
679 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rqstdma));
680 bpl->tus.f.bdeFlags = 0;
681 bpl->tus.f.bdeSize = pnvme_lsreq->rqstlen;
682 bpl->tus.w = le32_to_cpu(bpl->tus.w);
685 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rspdma));
686 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rspdma));
687 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
688 bpl->tus.f.bdeSize = pnvme_lsreq->rsplen;
689 bpl->tus.w = le32_to_cpu(bpl->tus.w);
691 /* Expand print to include key fields. */
692 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
693 "6149 Issue LS Req to DID 0x%06x lport x%px, "
694 "rport x%px lsreq x%px rqstlen:%d rsplen:%d "
696 ndlp->nlp_DID, pnvme_lport, pnvme_rport,
697 pnvme_lsreq, pnvme_lsreq->rqstlen,
698 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
699 &pnvme_lsreq->rspdma);
701 atomic_inc(&lport->fc4NvmeLsRequests);
703 /* Hardcode the wait to 30 seconds. Connections are failing otherwise.
704 * This code allows it all to work.
706 ret = lpfc_nvme_gen_req(vport, bmp, pnvme_lsreq->rqstaddr,
707 pnvme_lsreq, lpfc_nvme_cmpl_gen_req,
709 if (ret != WQE_SUCCESS) {
710 atomic_inc(&lport->xmt_ls_err);
711 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
712 "6052 EXIT. issue ls wqe failed lport x%px, "
713 "rport x%px lsreq x%px Status %x DID %x\n",
714 pnvme_lport, pnvme_rport, pnvme_lsreq,
716 lpfc_mbuf_free(vport->phba, bmp->virt, bmp->phys);
721 /* Stub in routine and return 0 for now. */
726 * lpfc_nvme_ls_abort - Issue an Link Service request
727 * @lpfc_pnvme: Pointer to the driver's nvme instance data
728 * @lpfc_nvme_lport: Pointer to the driver's local port data
729 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
731 * Driver registers this routine to handle any link service request
732 * from the nvme_fc transport to a remote nvme-aware port.
736 * TODO: What are the failure codes.
739 lpfc_nvme_ls_abort(struct nvme_fc_local_port *pnvme_lport,
740 struct nvme_fc_remote_port *pnvme_rport,
741 struct nvmefc_ls_req *pnvme_lsreq)
743 struct lpfc_nvme_lport *lport;
744 struct lpfc_vport *vport;
745 struct lpfc_hba *phba;
746 struct lpfc_nodelist *ndlp;
747 LIST_HEAD(abort_list);
748 struct lpfc_sli_ring *pring;
749 struct lpfc_iocbq *wqe, *next_wqe;
751 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
752 if (unlikely(!lport))
754 vport = lport->vport;
757 if (vport->load_flag & FC_UNLOADING)
760 ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id);
762 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
763 "6049 Could not find node for DID %x\n",
764 pnvme_rport->port_id);
768 /* Expand print to include key fields. */
769 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
770 "6040 ENTER. lport x%px, rport x%px lsreq x%px rqstlen:%d "
771 "rsplen:%d %pad %pad\n",
772 pnvme_lport, pnvme_rport,
773 pnvme_lsreq, pnvme_lsreq->rqstlen,
774 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
775 &pnvme_lsreq->rspdma);
778 * Lock the ELS ring txcmplq and build a local list of all ELS IOs
779 * that need an ABTS. The IOs need to stay on the txcmplq so that
780 * the abort operation completes them successfully.
782 pring = phba->sli4_hba.nvmels_wq->pring;
783 spin_lock_irq(&phba->hbalock);
784 spin_lock(&pring->ring_lock);
785 list_for_each_entry_safe(wqe, next_wqe, &pring->txcmplq, list) {
786 /* Add to abort_list on on NDLP match. */
787 if (lpfc_check_sli_ndlp(phba, pring, wqe, ndlp)) {
788 wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
789 list_add_tail(&wqe->dlist, &abort_list);
792 spin_unlock(&pring->ring_lock);
793 spin_unlock_irq(&phba->hbalock);
795 /* Abort the targeted IOs and remove them from the abort list. */
796 list_for_each_entry_safe(wqe, next_wqe, &abort_list, dlist) {
797 atomic_inc(&lport->xmt_ls_abort);
798 spin_lock_irq(&phba->hbalock);
799 list_del_init(&wqe->dlist);
800 lpfc_sli_issue_abort_iotag(phba, pring, wqe);
801 spin_unlock_irq(&phba->hbalock);
805 /* Fix up the existing sgls for NVME IO. */
807 lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport,
808 struct lpfc_io_buf *lpfc_ncmd,
809 struct nvmefc_fcp_req *nCmd)
811 struct lpfc_hba *phba = vport->phba;
812 struct sli4_sge *sgl;
813 union lpfc_wqe128 *wqe;
814 uint32_t *wptr, *dptr;
817 * Get a local pointer to the built-in wqe and correct
818 * the cmd size to match NVME's 96 bytes and fix
822 wqe = &lpfc_ncmd->cur_iocbq.wqe;
825 * Adjust the FCP_CMD and FCP_RSP DMA data and sge_len to
826 * match NVME. NVME sends 96 bytes. Also, use the
827 * nvme commands command and response dma addresses
828 * rather than the virtual memory to ease the restore
831 sgl = lpfc_ncmd->dma_sgl;
832 sgl->sge_len = cpu_to_le32(nCmd->cmdlen);
833 if (phba->cfg_nvme_embed_cmd) {
837 /* Word 0-2 - NVME CMND IU (embedded payload) */
838 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_IMMED;
839 wqe->generic.bde.tus.f.bdeSize = 56;
840 wqe->generic.bde.addrHigh = 0;
841 wqe->generic.bde.addrLow = 64; /* Word 16 */
843 /* Word 10 - dbde is 0, wqes is 1 in template */
846 * Embed the payload in the last half of the WQE
847 * WQE words 16-30 get the NVME CMD IU payload
849 * WQE words 16-19 get payload Words 1-4
850 * WQE words 20-21 get payload Words 6-7
851 * WQE words 22-29 get payload Words 16-23
853 wptr = &wqe->words[16]; /* WQE ptr */
854 dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */
855 dptr++; /* Skip Word 0 in payload */
857 *wptr++ = *dptr++; /* Word 1 */
858 *wptr++ = *dptr++; /* Word 2 */
859 *wptr++ = *dptr++; /* Word 3 */
860 *wptr++ = *dptr++; /* Word 4 */
861 dptr++; /* Skip Word 5 in payload */
862 *wptr++ = *dptr++; /* Word 6 */
863 *wptr++ = *dptr++; /* Word 7 */
864 dptr += 8; /* Skip Words 8-15 in payload */
865 *wptr++ = *dptr++; /* Word 16 */
866 *wptr++ = *dptr++; /* Word 17 */
867 *wptr++ = *dptr++; /* Word 18 */
868 *wptr++ = *dptr++; /* Word 19 */
869 *wptr++ = *dptr++; /* Word 20 */
870 *wptr++ = *dptr++; /* Word 21 */
871 *wptr++ = *dptr++; /* Word 22 */
872 *wptr = *dptr; /* Word 23 */
874 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->cmddma));
875 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->cmddma));
877 /* Word 0-2 - NVME CMND IU Inline BDE */
878 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
879 wqe->generic.bde.tus.f.bdeSize = nCmd->cmdlen;
880 wqe->generic.bde.addrHigh = sgl->addr_hi;
881 wqe->generic.bde.addrLow = sgl->addr_lo;
884 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
885 bf_set(wqe_wqes, &wqe->generic.wqe_com, 0);
890 /* Setup the physical region for the FCP RSP */
891 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->rspdma));
892 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->rspdma));
893 sgl->word2 = le32_to_cpu(sgl->word2);
895 bf_set(lpfc_sli4_sge_last, sgl, 0);
897 bf_set(lpfc_sli4_sge_last, sgl, 1);
898 sgl->word2 = cpu_to_le32(sgl->word2);
899 sgl->sge_len = cpu_to_le32(nCmd->rsplen);
904 * lpfc_nvme_io_cmd_wqe_cmpl - Complete an NVME-over-FCP IO
905 * @lpfc_pnvme: Pointer to the driver's nvme instance data
906 * @lpfc_nvme_lport: Pointer to the driver's local port data
907 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
909 * Driver registers this routine as it io request handler. This
910 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
911 * data structure to the rport indicated in @lpfc_nvme_rport.
915 * TODO: What are the failure codes.
918 lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
919 struct lpfc_wcqe_complete *wcqe)
921 struct lpfc_io_buf *lpfc_ncmd =
922 (struct lpfc_io_buf *)pwqeIn->context1;
923 struct lpfc_vport *vport = pwqeIn->vport;
924 struct nvmefc_fcp_req *nCmd;
925 struct nvme_fc_ersp_iu *ep;
926 struct nvme_fc_cmd_iu *cp;
927 struct lpfc_nodelist *ndlp;
928 struct lpfc_nvme_fcpreq_priv *freqpriv;
929 struct lpfc_nvme_lport *lport;
930 uint32_t code, status, idx;
931 uint16_t cid, sqhd, data;
933 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
937 /* Sanity check on return of outstanding command */
939 lpfc_printf_vlog(vport, KERN_ERR,
940 LOG_NODE | LOG_NVME_IOERR,
941 "6071 Null lpfc_ncmd pointer. No "
942 "release, skip completion\n");
946 /* Guard against abort handler being called at same time */
947 spin_lock(&lpfc_ncmd->buf_lock);
949 if (!lpfc_ncmd->nvmeCmd) {
950 spin_unlock(&lpfc_ncmd->buf_lock);
951 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
952 "6066 Missing cmpl ptrs: lpfc_ncmd x%px, "
954 lpfc_ncmd, lpfc_ncmd->nvmeCmd);
956 /* Release the lpfc_ncmd regardless of the missing elements. */
957 lpfc_release_nvme_buf(phba, lpfc_ncmd);
960 nCmd = lpfc_ncmd->nvmeCmd;
961 status = bf_get(lpfc_wcqe_c_status, wcqe);
963 idx = lpfc_ncmd->cur_iocbq.hba_wqidx;
964 phba->sli4_hba.hdwq[idx].nvme_cstat.io_cmpls++;
966 if (unlikely(status && vport->localport)) {
967 lport = (struct lpfc_nvme_lport *)vport->localport->private;
969 if (bf_get(lpfc_wcqe_c_xb, wcqe))
970 atomic_inc(&lport->cmpl_fcp_xb);
971 atomic_inc(&lport->cmpl_fcp_err);
975 lpfc_nvmeio_data(phba, "NVME FCP CMPL: xri x%x stat x%x parm x%x\n",
976 lpfc_ncmd->cur_iocbq.sli4_xritag,
977 status, wcqe->parameter);
979 * Catch race where our node has transitioned, but the
980 * transport is still transitioning.
982 ndlp = lpfc_ncmd->ndlp;
983 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
984 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
985 "6062 Ignoring NVME cmpl. No ndlp\n");
989 code = bf_get(lpfc_wcqe_c_code, wcqe);
990 if (code == CQE_CODE_NVME_ERSP) {
991 /* For this type of CQE, we need to rebuild the rsp */
992 ep = (struct nvme_fc_ersp_iu *)nCmd->rspaddr;
995 * Get Command Id from cmd to plug into response. This
996 * code is not needed in the next NVME Transport drop.
998 cp = (struct nvme_fc_cmd_iu *)nCmd->cmdaddr;
999 cid = cp->sqe.common.command_id;
1002 * RSN is in CQE word 2
1003 * SQHD is in CQE Word 3 bits 15:0
1004 * Cmd Specific info is in CQE Word 1
1005 * and in CQE Word 0 bits 15:0
1007 sqhd = bf_get(lpfc_wcqe_c_sqhead, wcqe);
1009 /* Now lets build the NVME ERSP IU */
1010 ep->iu_len = cpu_to_be16(8);
1011 ep->rsn = wcqe->parameter;
1012 ep->xfrd_len = cpu_to_be32(nCmd->payload_length);
1014 ptr = (uint32_t *)&ep->cqe.result.u64;
1015 *ptr++ = wcqe->total_data_placed;
1016 data = bf_get(lpfc_wcqe_c_ersp0, wcqe);
1017 *ptr = (uint32_t)data;
1018 ep->cqe.sq_head = sqhd;
1019 ep->cqe.sq_id = nCmd->sqid;
1020 ep->cqe.command_id = cid;
1023 lpfc_ncmd->status = IOSTAT_SUCCESS;
1024 lpfc_ncmd->result = 0;
1025 nCmd->rcv_rsplen = LPFC_NVME_ERSP_LEN;
1026 nCmd->transferred_length = nCmd->payload_length;
1028 lpfc_ncmd->status = (status & LPFC_IOCB_STATUS_MASK);
1029 lpfc_ncmd->result = (wcqe->parameter & IOERR_PARAM_MASK);
1031 /* For NVME, the only failure path that results in an
1032 * IO error is when the adapter rejects it. All other
1033 * conditions are a success case and resolved by the
1035 * IOSTAT_FCP_RSP_ERROR means:
1036 * 1. Length of data received doesn't match total
1037 * transfer length in WQE
1038 * 2. If the RSP payload does NOT match these cases:
1039 * a. RSP length 12/24 bytes and all zeros
1042 switch (lpfc_ncmd->status) {
1043 case IOSTAT_SUCCESS:
1044 nCmd->transferred_length = wcqe->total_data_placed;
1045 nCmd->rcv_rsplen = 0;
1048 case IOSTAT_FCP_RSP_ERROR:
1049 nCmd->transferred_length = wcqe->total_data_placed;
1050 nCmd->rcv_rsplen = wcqe->parameter;
1053 if (nCmd->rcv_rsplen == LPFC_NVME_ERSP_LEN)
1055 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1056 "6081 NVME Completion Protocol Error: "
1057 "xri %x status x%x result x%x "
1059 lpfc_ncmd->cur_iocbq.sli4_xritag,
1060 lpfc_ncmd->status, lpfc_ncmd->result,
1061 wcqe->total_data_placed);
1063 case IOSTAT_LOCAL_REJECT:
1064 /* Let fall through to set command final state. */
1065 if (lpfc_ncmd->result == IOERR_ABORT_REQUESTED)
1066 lpfc_printf_vlog(vport, KERN_INFO,
1068 "6032 Delay Aborted cmd x%px "
1069 "nvme cmd x%px, xri x%x, "
1072 lpfc_ncmd->cur_iocbq.sli4_xritag,
1073 bf_get(lpfc_wcqe_c_xb, wcqe));
1077 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1078 "6072 NVME Completion Error: xri %x "
1079 "status x%x result x%x [x%x] "
1081 lpfc_ncmd->cur_iocbq.sli4_xritag,
1082 lpfc_ncmd->status, lpfc_ncmd->result,
1084 wcqe->total_data_placed);
1085 nCmd->transferred_length = 0;
1086 nCmd->rcv_rsplen = 0;
1087 nCmd->status = NVME_SC_INTERNAL;
1091 /* pick up SLI4 exhange busy condition */
1092 if (bf_get(lpfc_wcqe_c_xb, wcqe))
1093 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
1095 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
1097 /* Update stats and complete the IO. There is
1098 * no need for dma unprep because the nvme_transport
1099 * owns the dma address.
1101 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1102 if (lpfc_ncmd->ts_cmd_start) {
1103 lpfc_ncmd->ts_isr_cmpl = pwqeIn->isr_timestamp;
1104 lpfc_ncmd->ts_data_io = ktime_get_ns();
1105 phba->ktime_last_cmd = lpfc_ncmd->ts_data_io;
1106 lpfc_io_ktime(phba, lpfc_ncmd);
1108 if (unlikely(phba->hdwqstat_on & LPFC_CHECK_NVME_IO)) {
1109 cpu = raw_smp_processor_id();
1110 this_cpu_inc(phba->sli4_hba.c_stat->cmpl_io);
1111 if (lpfc_ncmd->cpu != cpu)
1112 lpfc_printf_vlog(vport,
1113 KERN_INFO, LOG_NVME_IOERR,
1114 "6701 CPU Check cmpl: "
1115 "cpu %d expect %d\n",
1116 cpu, lpfc_ncmd->cpu);
1120 /* NVME targets need completion held off until the abort exchange
1121 * completes unless the NVME Rport is getting unregistered.
1124 if (!(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) {
1125 freqpriv = nCmd->private;
1126 freqpriv->nvme_buf = NULL;
1127 lpfc_ncmd->nvmeCmd = NULL;
1128 spin_unlock(&lpfc_ncmd->buf_lock);
1131 spin_unlock(&lpfc_ncmd->buf_lock);
1133 /* Call release with XB=1 to queue the IO into the abort list. */
1134 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1139 * lpfc_nvme_prep_io_cmd - Issue an NVME-over-FCP IO
1140 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1141 * @lpfc_nvme_lport: Pointer to the driver's local port data
1142 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1143 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1144 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1146 * Driver registers this routine as it io request handler. This
1147 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1148 * data structure to the rport indicated in @lpfc_nvme_rport.
1152 * TODO: What are the failure codes.
1155 lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport,
1156 struct lpfc_io_buf *lpfc_ncmd,
1157 struct lpfc_nodelist *pnode,
1158 struct lpfc_fc4_ctrl_stat *cstat)
1160 struct lpfc_hba *phba = vport->phba;
1161 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1162 struct lpfc_iocbq *pwqeq = &(lpfc_ncmd->cur_iocbq);
1163 union lpfc_wqe128 *wqe = &pwqeq->wqe;
1166 if (!NLP_CHK_NODE_ACT(pnode))
1170 * There are three possibilities here - use scatter-gather segment, use
1171 * the single mapping, or neither.
1174 if (nCmd->io_dir == NVMEFC_FCP_WRITE) {
1175 /* From the iwrite template, initialize words 7 - 11 */
1176 memcpy(&wqe->words[7],
1177 &lpfc_iwrite_cmd_template.words[7],
1178 sizeof(uint32_t) * 5);
1181 wqe->fcp_iwrite.total_xfer_len = nCmd->payload_length;
1184 if ((phba->cfg_nvme_enable_fb) &&
1185 (pnode->nlp_flag & NLP_FIRSTBURST)) {
1186 req_len = lpfc_ncmd->nvmeCmd->payload_length;
1187 if (req_len < pnode->nvme_fb_size)
1188 wqe->fcp_iwrite.initial_xfer_len =
1191 wqe->fcp_iwrite.initial_xfer_len =
1192 pnode->nvme_fb_size;
1194 wqe->fcp_iwrite.initial_xfer_len = 0;
1196 cstat->output_requests++;
1198 /* From the iread template, initialize words 7 - 11 */
1199 memcpy(&wqe->words[7],
1200 &lpfc_iread_cmd_template.words[7],
1201 sizeof(uint32_t) * 5);
1204 wqe->fcp_iread.total_xfer_len = nCmd->payload_length;
1207 wqe->fcp_iread.rsrvd5 = 0;
1209 cstat->input_requests++;
1212 /* From the icmnd template, initialize words 4 - 11 */
1213 memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4],
1214 sizeof(uint32_t) * 8);
1215 cstat->control_requests++;
1218 if (pnode->nlp_nvme_info & NLP_NVME_NSLER)
1219 bf_set(wqe_erp, &wqe->generic.wqe_com, 1);
1221 * Finish initializing those WQE fields that are independent
1222 * of the nvme_cmnd request_buffer
1226 bf_set(payload_offset_len, &wqe->fcp_icmd,
1227 (nCmd->rsplen + nCmd->cmdlen));
1230 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
1231 phba->sli4_hba.rpi_ids[pnode->nlp_rpi]);
1232 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag);
1235 wqe->generic.wqe_com.abort_tag = pwqeq->iotag;
1238 bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag);
1240 /* Words 13 14 15 are for PBDE support */
1242 pwqeq->vport = vport;
1248 * lpfc_nvme_prep_io_dma - Issue an NVME-over-FCP IO
1249 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1250 * @lpfc_nvme_lport: Pointer to the driver's local port data
1251 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1252 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1253 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1255 * Driver registers this routine as it io request handler. This
1256 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1257 * data structure to the rport indicated in @lpfc_nvme_rport.
1261 * TODO: What are the failure codes.
1264 lpfc_nvme_prep_io_dma(struct lpfc_vport *vport,
1265 struct lpfc_io_buf *lpfc_ncmd)
1267 struct lpfc_hba *phba = vport->phba;
1268 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1269 union lpfc_wqe128 *wqe = &lpfc_ncmd->cur_iocbq.wqe;
1270 struct sli4_sge *sgl = lpfc_ncmd->dma_sgl;
1271 struct sli4_hybrid_sgl *sgl_xtra = NULL;
1272 struct scatterlist *data_sg;
1273 struct sli4_sge *first_data_sgl;
1274 struct ulp_bde64 *bde;
1275 dma_addr_t physaddr = 0;
1276 uint32_t num_bde = 0;
1277 uint32_t dma_len = 0;
1278 uint32_t dma_offset = 0;
1280 bool lsp_just_set = false;
1282 /* Fix up the command and response DMA stuff. */
1283 lpfc_nvme_adj_fcp_sgls(vport, lpfc_ncmd, nCmd);
1286 * There are three possibilities here - use scatter-gather segment, use
1287 * the single mapping, or neither.
1291 * Jump over the cmd and rsp SGEs. The fix routine
1292 * has already adjusted for this.
1296 first_data_sgl = sgl;
1297 lpfc_ncmd->seg_cnt = nCmd->sg_cnt;
1298 if (lpfc_ncmd->seg_cnt > lpfc_nvme_template.max_sgl_segments) {
1299 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1300 "6058 Too many sg segments from "
1301 "NVME Transport. Max %d, "
1302 "nvmeIO sg_cnt %d\n",
1303 phba->cfg_nvme_seg_cnt + 1,
1304 lpfc_ncmd->seg_cnt);
1305 lpfc_ncmd->seg_cnt = 0;
1310 * The driver established a maximum scatter-gather segment count
1311 * during probe that limits the number of sg elements in any
1312 * single nvme command. Just run through the seg_cnt and format
1315 nseg = nCmd->sg_cnt;
1316 data_sg = nCmd->first_sgl;
1318 /* for tracking the segment boundaries */
1320 for (i = 0; i < nseg; i++) {
1321 if (data_sg == NULL) {
1322 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1323 "6059 dptr err %d, nseg %d\n",
1325 lpfc_ncmd->seg_cnt = 0;
1330 if ((num_bde + 1) == nseg) {
1331 bf_set(lpfc_sli4_sge_last, sgl, 1);
1332 bf_set(lpfc_sli4_sge_type, sgl,
1333 LPFC_SGE_TYPE_DATA);
1335 bf_set(lpfc_sli4_sge_last, sgl, 0);
1337 /* expand the segment */
1338 if (!lsp_just_set &&
1339 !((j + 1) % phba->border_sge_num) &&
1340 ((nseg - 1) != i)) {
1342 bf_set(lpfc_sli4_sge_type, sgl,
1345 sgl_xtra = lpfc_get_sgl_per_hdwq(
1348 if (unlikely(!sgl_xtra)) {
1349 lpfc_ncmd->seg_cnt = 0;
1352 sgl->addr_lo = cpu_to_le32(putPaddrLow(
1353 sgl_xtra->dma_phys_sgl));
1354 sgl->addr_hi = cpu_to_le32(putPaddrHigh(
1355 sgl_xtra->dma_phys_sgl));
1358 bf_set(lpfc_sli4_sge_type, sgl,
1359 LPFC_SGE_TYPE_DATA);
1363 if (!(bf_get(lpfc_sli4_sge_type, sgl) &
1364 LPFC_SGE_TYPE_LSP)) {
1365 if ((nseg - 1) == i)
1366 bf_set(lpfc_sli4_sge_last, sgl, 1);
1368 physaddr = data_sg->dma_address;
1369 dma_len = data_sg->length;
1370 sgl->addr_lo = cpu_to_le32(
1371 putPaddrLow(physaddr));
1372 sgl->addr_hi = cpu_to_le32(
1373 putPaddrHigh(physaddr));
1375 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
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);
1384 lsp_just_set = false;
1386 sgl->word2 = cpu_to_le32(sgl->word2);
1388 sgl->sge_len = cpu_to_le32(
1389 phba->cfg_sg_dma_buf_size);
1391 sgl = (struct sli4_sge *)sgl_xtra->dma_sgl;
1394 lsp_just_set = true;
1399 if (phba->cfg_enable_pbde) {
1400 /* Use PBDE support for first SGL only, offset == 0 */
1402 bde = (struct ulp_bde64 *)
1404 bde->addrLow = first_data_sgl->addr_lo;
1405 bde->addrHigh = first_data_sgl->addr_hi;
1406 bde->tus.f.bdeSize =
1407 le32_to_cpu(first_data_sgl->sge_len);
1408 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1409 bde->tus.w = cpu_to_le32(bde->tus.w);
1410 /* wqe_pbde is 1 in template */
1412 memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3));
1413 bf_set(wqe_pbde, &wqe->generic.wqe_com, 0);
1417 lpfc_ncmd->seg_cnt = 0;
1419 /* For this clause to be valid, the payload_length
1420 * and sg_cnt must zero.
1422 if (nCmd->payload_length != 0) {
1423 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1424 "6063 NVME DMA Prep Err: sg_cnt %d "
1425 "payload_length x%x\n",
1426 nCmd->sg_cnt, nCmd->payload_length);
1434 * lpfc_nvme_fcp_io_submit - Issue an NVME-over-FCP IO
1435 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1436 * @lpfc_nvme_lport: Pointer to the driver's local port data
1437 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1438 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1439 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1441 * Driver registers this routine as it io request handler. This
1442 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1443 * data structure to the rport
1444 indicated in @lpfc_nvme_rport.
1448 * TODO: What are the failure codes.
1451 lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
1452 struct nvme_fc_remote_port *pnvme_rport,
1453 void *hw_queue_handle,
1454 struct nvmefc_fcp_req *pnvme_fcreq)
1459 struct lpfc_nvme_lport *lport;
1460 struct lpfc_fc4_ctrl_stat *cstat;
1461 struct lpfc_vport *vport;
1462 struct lpfc_hba *phba;
1463 struct lpfc_nodelist *ndlp;
1464 struct lpfc_io_buf *lpfc_ncmd;
1465 struct lpfc_nvme_rport *rport;
1466 struct lpfc_nvme_qhandle *lpfc_queue_info;
1467 struct lpfc_nvme_fcpreq_priv *freqpriv;
1468 struct nvme_common_command *sqe;
1469 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1473 /* Validate pointers. LLDD fault handling with transport does
1474 * have timing races.
1476 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1477 if (unlikely(!lport)) {
1482 vport = lport->vport;
1484 if (unlikely(!hw_queue_handle)) {
1485 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1486 "6117 Fail IO, NULL hw_queue_handle\n");
1487 atomic_inc(&lport->xmt_fcp_err);
1494 if (vport->load_flag & FC_UNLOADING) {
1499 if (unlikely(vport->load_flag & FC_UNLOADING)) {
1500 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1501 "6124 Fail IO, Driver unload\n");
1502 atomic_inc(&lport->xmt_fcp_err);
1507 freqpriv = pnvme_fcreq->private;
1508 if (unlikely(!freqpriv)) {
1509 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1510 "6158 Fail IO, NULL request data\n");
1511 atomic_inc(&lport->xmt_fcp_err);
1516 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1518 start = ktime_get_ns();
1520 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
1521 lpfc_queue_info = (struct lpfc_nvme_qhandle *)hw_queue_handle;
1524 * Catch race where our node has transitioned, but the
1525 * transport is still transitioning.
1528 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1529 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1530 "6053 Busy IO, ndlp not ready: rport x%px "
1531 "ndlp x%px, DID x%06x\n",
1532 rport, ndlp, pnvme_rport->port_id);
1533 atomic_inc(&lport->xmt_fcp_err);
1538 /* The remote node has to be a mapped target or it's an error. */
1539 if ((ndlp->nlp_type & NLP_NVME_TARGET) &&
1540 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
1541 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1542 "6036 Fail IO, DID x%06x not ready for "
1543 "IO. State x%x, Type x%x Flg x%x\n",
1544 pnvme_rport->port_id,
1545 ndlp->nlp_state, ndlp->nlp_type,
1546 ndlp->upcall_flags);
1547 atomic_inc(&lport->xmt_fcp_bad_ndlp);
1553 /* Currently only NVME Keep alive commands should be expedited
1554 * if the driver runs out of a resource. These should only be
1555 * issued on the admin queue, qidx 0
1557 if (!lpfc_queue_info->qidx && !pnvme_fcreq->sg_cnt) {
1558 sqe = &((struct nvme_fc_cmd_iu *)
1559 pnvme_fcreq->cmdaddr)->sqe.common;
1560 if (sqe->opcode == nvme_admin_keep_alive)
1564 /* The node is shared with FCP IO, make sure the IO pending count does
1565 * not exceed the programmed depth.
1567 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
1568 if ((atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) &&
1570 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1571 "6174 Fail IO, ndlp qdepth exceeded: "
1572 "idx %d DID %x pend %d qdepth %d\n",
1573 lpfc_queue_info->index, ndlp->nlp_DID,
1574 atomic_read(&ndlp->cmd_pending),
1576 atomic_inc(&lport->xmt_fcp_qdepth);
1582 /* Lookup Hardware Queue index based on fcp_io_sched module parameter */
1583 if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) {
1584 idx = lpfc_queue_info->index;
1586 cpu = raw_smp_processor_id();
1587 idx = phba->sli4_hba.cpu_map[cpu].hdwq;
1590 lpfc_ncmd = lpfc_get_nvme_buf(phba, ndlp, idx, expedite);
1591 if (lpfc_ncmd == NULL) {
1592 atomic_inc(&lport->xmt_fcp_noxri);
1593 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1594 "6065 Fail IO, driver buffer pool is empty: "
1596 lpfc_queue_info->index, ndlp->nlp_DID);
1600 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1602 lpfc_ncmd->ts_cmd_start = start;
1603 lpfc_ncmd->ts_last_cmd = phba->ktime_last_cmd;
1605 lpfc_ncmd->ts_cmd_start = 0;
1610 * Store the data needed by the driver to issue, abort, and complete
1612 * Do not let the IO hang out forever. There is no midlayer issuing
1613 * an abort so inform the FW of the maximum IO pending time.
1615 freqpriv->nvme_buf = lpfc_ncmd;
1616 lpfc_ncmd->nvmeCmd = pnvme_fcreq;
1617 lpfc_ncmd->ndlp = ndlp;
1618 lpfc_ncmd->qidx = lpfc_queue_info->qidx;
1621 * Issue the IO on the WQ indicated by index in the hw_queue_handle.
1622 * This identfier was create in our hardware queue create callback
1623 * routine. The driver now is dependent on the IO queue steering from
1624 * the transport. We are trusting the upper NVME layers know which
1625 * index to use and that they have affinitized a CPU to this hardware
1626 * queue. A hardware queue maps to a driver MSI-X vector/EQ/CQ/WQ.
1628 lpfc_ncmd->cur_iocbq.hba_wqidx = idx;
1629 cstat = &phba->sli4_hba.hdwq[idx].nvme_cstat;
1631 lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp, cstat);
1632 ret = lpfc_nvme_prep_io_dma(vport, lpfc_ncmd);
1634 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1635 "6175 Fail IO, Prep DMA: "
1637 lpfc_queue_info->index, ndlp->nlp_DID);
1638 atomic_inc(&lport->xmt_fcp_err);
1640 goto out_free_nvme_buf;
1643 lpfc_nvmeio_data(phba, "NVME FCP XMIT: xri x%x idx %d to %06x\n",
1644 lpfc_ncmd->cur_iocbq.sli4_xritag,
1645 lpfc_queue_info->index, ndlp->nlp_DID);
1647 ret = lpfc_sli4_issue_wqe(phba, lpfc_ncmd->hdwq, &lpfc_ncmd->cur_iocbq);
1649 atomic_inc(&lport->xmt_fcp_wqerr);
1650 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1651 "6113 Fail IO, Could not issue WQE err %x "
1652 "sid: x%x did: x%x oxid: x%x\n",
1653 ret, vport->fc_myDID, ndlp->nlp_DID,
1654 lpfc_ncmd->cur_iocbq.sli4_xritag);
1655 goto out_free_nvme_buf;
1658 if (phba->cfg_xri_rebalancing)
1659 lpfc_keep_pvt_pool_above_lowwm(phba, lpfc_ncmd->hdwq_no);
1661 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1662 if (lpfc_ncmd->ts_cmd_start)
1663 lpfc_ncmd->ts_cmd_wqput = ktime_get_ns();
1665 if (phba->hdwqstat_on & LPFC_CHECK_NVME_IO) {
1666 cpu = raw_smp_processor_id();
1667 this_cpu_inc(phba->sli4_hba.c_stat->xmt_io);
1668 lpfc_ncmd->cpu = cpu;
1670 lpfc_printf_vlog(vport,
1671 KERN_INFO, LOG_NVME_IOERR,
1672 "6702 CPU Check cmd: "
1675 lpfc_queue_info->index);
1681 if (lpfc_ncmd->nvmeCmd->sg_cnt) {
1682 if (lpfc_ncmd->nvmeCmd->io_dir == NVMEFC_FCP_WRITE)
1683 cstat->output_requests--;
1685 cstat->input_requests--;
1687 cstat->control_requests--;
1688 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1694 * lpfc_nvme_abort_fcreq_cmpl - Complete an NVME FCP abort request.
1695 * @phba: Pointer to HBA context object
1696 * @cmdiocb: Pointer to command iocb object.
1697 * @rspiocb: Pointer to response iocb object.
1699 * This is the callback function for any NVME FCP IO that was aborted.
1705 lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1706 struct lpfc_wcqe_complete *abts_cmpl)
1708 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
1709 "6145 ABORT_XRI_CN completing on rpi x%x "
1710 "original iotag x%x, abort cmd iotag x%x "
1711 "req_tag x%x, status x%x, hwstatus x%x\n",
1712 cmdiocb->iocb.un.acxri.abortContextTag,
1713 cmdiocb->iocb.un.acxri.abortIoTag,
1715 bf_get(lpfc_wcqe_c_request_tag, abts_cmpl),
1716 bf_get(lpfc_wcqe_c_status, abts_cmpl),
1717 bf_get(lpfc_wcqe_c_hw_status, abts_cmpl));
1718 lpfc_sli_release_iocbq(phba, cmdiocb);
1722 * lpfc_nvme_fcp_abort - Issue an NVME-over-FCP ABTS
1723 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1724 * @lpfc_nvme_lport: Pointer to the driver's local port data
1725 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1726 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1727 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1729 * Driver registers this routine as its nvme request io abort handler. This
1730 * routine issues an fcp Abort WQE with data from the @lpfc_nvme_fcpreq
1731 * data structure to the rport indicated in @lpfc_nvme_rport. This routine
1732 * is executed asynchronously - one the target is validated as "MAPPED" and
1733 * ready for IO, the driver issues the abort request and returns.
1739 lpfc_nvme_fcp_abort(struct nvme_fc_local_port *pnvme_lport,
1740 struct nvme_fc_remote_port *pnvme_rport,
1741 void *hw_queue_handle,
1742 struct nvmefc_fcp_req *pnvme_fcreq)
1744 struct lpfc_nvme_lport *lport;
1745 struct lpfc_vport *vport;
1746 struct lpfc_hba *phba;
1747 struct lpfc_io_buf *lpfc_nbuf;
1748 struct lpfc_iocbq *abts_buf;
1749 struct lpfc_iocbq *nvmereq_wqe;
1750 struct lpfc_nvme_fcpreq_priv *freqpriv;
1751 unsigned long flags;
1754 /* Validate pointers. LLDD fault handling with transport does
1755 * have timing races.
1757 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1758 if (unlikely(!lport))
1761 vport = lport->vport;
1763 if (unlikely(!hw_queue_handle)) {
1764 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1765 "6129 Fail Abort, HW Queue Handle NULL.\n");
1770 freqpriv = pnvme_fcreq->private;
1772 if (unlikely(!freqpriv))
1774 if (vport->load_flag & FC_UNLOADING)
1777 /* Announce entry to new IO submit field. */
1778 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1779 "6002 Abort Request to rport DID x%06x "
1780 "for nvme_fc_req x%px\n",
1781 pnvme_rport->port_id,
1784 /* If the hba is getting reset, this flag is set. It is
1785 * cleared when the reset is complete and rings reestablished.
1787 spin_lock_irqsave(&phba->hbalock, flags);
1788 /* driver queued commands are in process of being flushed */
1789 if (phba->hba_flag & HBA_IOQ_FLUSH) {
1790 spin_unlock_irqrestore(&phba->hbalock, flags);
1791 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1792 "6139 Driver in reset cleanup - flushing "
1793 "NVME Req now. hba_flag x%x\n",
1798 lpfc_nbuf = freqpriv->nvme_buf;
1800 spin_unlock_irqrestore(&phba->hbalock, flags);
1801 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1802 "6140 NVME IO req has no matching lpfc nvme "
1803 "io buffer. Skipping abort req.\n");
1805 } else if (!lpfc_nbuf->nvmeCmd) {
1806 spin_unlock_irqrestore(&phba->hbalock, flags);
1807 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1808 "6141 lpfc NVME IO req has no nvme_fcreq "
1809 "io buffer. Skipping abort req.\n");
1812 nvmereq_wqe = &lpfc_nbuf->cur_iocbq;
1814 /* Guard against IO completion being called at same time */
1815 spin_lock(&lpfc_nbuf->buf_lock);
1818 * The lpfc_nbuf and the mapped nvme_fcreq in the driver's
1819 * state must match the nvme_fcreq passed by the nvme
1820 * transport. If they don't match, it is likely the driver
1821 * has already completed the NVME IO and the nvme transport
1822 * has not seen it yet.
1824 if (lpfc_nbuf->nvmeCmd != pnvme_fcreq) {
1825 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1826 "6143 NVME req mismatch: "
1827 "lpfc_nbuf x%px nvmeCmd x%px, "
1828 "pnvme_fcreq x%px. Skipping Abort xri x%x\n",
1829 lpfc_nbuf, lpfc_nbuf->nvmeCmd,
1830 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1834 /* Don't abort IOs no longer on the pending queue. */
1835 if (!(nvmereq_wqe->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
1836 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1837 "6142 NVME IO req x%px not queued - skipping "
1838 "abort req xri x%x\n",
1839 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1843 atomic_inc(&lport->xmt_fcp_abort);
1844 lpfc_nvmeio_data(phba, "NVME FCP ABORT: xri x%x idx %d to %06x\n",
1845 nvmereq_wqe->sli4_xritag,
1846 nvmereq_wqe->hba_wqidx, pnvme_rport->port_id);
1848 /* Outstanding abort is in progress */
1849 if (nvmereq_wqe->iocb_flag & LPFC_DRIVER_ABORTED) {
1850 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1851 "6144 Outstanding NVME I/O Abort Request "
1852 "still pending on nvme_fcreq x%px, "
1853 "lpfc_ncmd %px xri x%x\n",
1854 pnvme_fcreq, lpfc_nbuf,
1855 nvmereq_wqe->sli4_xritag);
1859 abts_buf = __lpfc_sli_get_iocbq(phba);
1861 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1862 "6136 No available abort wqes. Skipping "
1863 "Abts req for nvme_fcreq x%px xri x%x\n",
1864 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1868 /* Ready - mark outstanding as aborted by driver. */
1869 nvmereq_wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
1871 lpfc_nvme_prep_abort_wqe(abts_buf, nvmereq_wqe->sli4_xritag, 0);
1873 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
1874 abts_buf->iocb_flag |= LPFC_IO_NVME;
1875 abts_buf->hba_wqidx = nvmereq_wqe->hba_wqidx;
1876 abts_buf->vport = vport;
1877 abts_buf->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl;
1878 ret_val = lpfc_sli4_issue_wqe(phba, lpfc_nbuf->hdwq, abts_buf);
1879 spin_unlock(&lpfc_nbuf->buf_lock);
1880 spin_unlock_irqrestore(&phba->hbalock, flags);
1882 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1883 "6137 Failed abts issue_wqe with status x%x "
1884 "for nvme_fcreq x%px.\n",
1885 ret_val, pnvme_fcreq);
1886 lpfc_sli_release_iocbq(phba, abts_buf);
1890 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1891 "6138 Transport Abort NVME Request Issued for "
1892 "ox_id x%x on reqtag x%x\n",
1893 nvmereq_wqe->sli4_xritag,
1898 spin_unlock(&lpfc_nbuf->buf_lock);
1899 spin_unlock_irqrestore(&phba->hbalock, flags);
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_get_nvme_buf - Get a nvme buffer from io_buf_list of the HBA
1931 * @phba: The HBA for which this call is being executed.
1933 * This routine removes a nvme buffer from head of @hdwq io_buf_list
1934 * and returns to caller.
1938 * Pointer to lpfc_nvme_buf - Success
1940 static struct lpfc_io_buf *
1941 lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1942 int idx, int expedite)
1944 struct lpfc_io_buf *lpfc_ncmd;
1945 struct lpfc_sli4_hdw_queue *qp;
1946 struct sli4_sge *sgl;
1947 struct lpfc_iocbq *pwqeq;
1948 union lpfc_wqe128 *wqe;
1950 lpfc_ncmd = lpfc_get_io_buf(phba, NULL, idx, expedite);
1953 pwqeq = &(lpfc_ncmd->cur_iocbq);
1956 /* Setup key fields in buffer that may have been changed
1957 * if other protocols used this buffer.
1959 pwqeq->iocb_flag = LPFC_IO_NVME;
1960 pwqeq->wqe_cmpl = lpfc_nvme_io_cmd_wqe_cmpl;
1961 lpfc_ncmd->start_time = jiffies;
1962 lpfc_ncmd->flags = 0;
1964 /* Rsp SGE will be filled in when we rcv an IO
1965 * from the NVME Layer to be sent.
1966 * The cmd is going to be embedded so we need a SKIP SGE.
1968 sgl = lpfc_ncmd->dma_sgl;
1969 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP);
1970 bf_set(lpfc_sli4_sge_last, sgl, 0);
1971 sgl->word2 = cpu_to_le32(sgl->word2);
1972 /* Fill in word 3 / sgl_len during cmd submission */
1974 /* Initialize 64 bytes only */
1975 memset(wqe, 0, sizeof(union lpfc_wqe));
1977 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
1978 atomic_inc(&ndlp->cmd_pending);
1979 lpfc_ncmd->flags |= LPFC_SBUF_BUMP_QDEPTH;
1983 qp = &phba->sli4_hba.hdwq[idx];
1984 qp->empty_io_bufs++;
1991 * lpfc_release_nvme_buf: Return a nvme buffer back to hba nvme buf list.
1992 * @phba: The Hba for which this call is being executed.
1993 * @lpfc_ncmd: The nvme buffer which is being released.
1995 * This routine releases @lpfc_ncmd nvme buffer by adding it to tail of @phba
1996 * lpfc_io_buf_list list. For SLI4 XRI's are tied to the nvme buffer
1997 * and cannot be reused for at least RA_TOV amount of time if it was
2001 lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd)
2003 struct lpfc_sli4_hdw_queue *qp;
2004 unsigned long iflag = 0;
2006 if ((lpfc_ncmd->flags & LPFC_SBUF_BUMP_QDEPTH) && lpfc_ncmd->ndlp)
2007 atomic_dec(&lpfc_ncmd->ndlp->cmd_pending);
2009 lpfc_ncmd->ndlp = NULL;
2010 lpfc_ncmd->flags &= ~LPFC_SBUF_BUMP_QDEPTH;
2012 qp = lpfc_ncmd->hdwq;
2013 if (unlikely(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) {
2014 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2015 "6310 XB release deferred for "
2016 "ox_id x%x on reqtag x%x\n",
2017 lpfc_ncmd->cur_iocbq.sli4_xritag,
2018 lpfc_ncmd->cur_iocbq.iotag);
2020 spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag);
2021 list_add_tail(&lpfc_ncmd->list,
2022 &qp->lpfc_abts_io_buf_list);
2023 qp->abts_nvme_io_bufs++;
2024 spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag);
2026 lpfc_release_io_buf(phba, (struct lpfc_io_buf *)lpfc_ncmd, qp);
2030 * lpfc_nvme_create_localport - Create/Bind an nvme localport instance.
2031 * @pvport - the lpfc_vport instance requesting a localport.
2033 * This routine is invoked to create an nvme localport instance to bind
2034 * to the nvme_fc_transport. It is called once during driver load
2035 * like lpfc_create_shost after all other services are initialized.
2036 * It requires a vport, vpi, and wwns at call time. Other localport
2037 * parameters are modified as the driver's FCID and the Fabric WWN
2042 * -ENOMEM - no heap memory available
2043 * other values - from nvme registration upcall
2046 lpfc_nvme_create_localport(struct lpfc_vport *vport)
2049 struct lpfc_hba *phba = vport->phba;
2050 struct nvme_fc_port_info nfcp_info;
2051 struct nvme_fc_local_port *localport;
2052 struct lpfc_nvme_lport *lport;
2054 /* Initialize this localport instance. The vport wwn usage ensures
2055 * that NPIV is accounted for.
2057 memset(&nfcp_info, 0, sizeof(struct nvme_fc_port_info));
2058 nfcp_info.port_role = FC_PORT_ROLE_NVME_INITIATOR;
2059 nfcp_info.node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
2060 nfcp_info.port_name = wwn_to_u64(vport->fc_portname.u.wwn);
2062 /* We need to tell the transport layer + 1 because it takes page
2063 * alignment into account. When space for the SGL is allocated we
2064 * allocate + 3, one for cmd, one for rsp and one for this alignment
2066 lpfc_nvme_template.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1;
2068 /* Advertise how many hw queues we support based on cfg_hdw_queue,
2069 * which will not exceed cpu count.
2071 lpfc_nvme_template.max_hw_queues = phba->cfg_hdw_queue;
2073 if (!IS_ENABLED(CONFIG_NVME_FC))
2076 /* localport is allocated from the stack, but the registration
2077 * call allocates heap memory as well as the private area.
2080 ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template,
2081 &vport->phba->pcidev->dev, &localport);
2083 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC,
2084 "6005 Successfully registered local "
2085 "NVME port num %d, localP x%px, private "
2086 "x%px, sg_seg %d\n",
2087 localport->port_num, localport,
2089 lpfc_nvme_template.max_sgl_segments);
2091 /* Private is our lport size declared in the template. */
2092 lport = (struct lpfc_nvme_lport *)localport->private;
2093 vport->localport = localport;
2094 lport->vport = vport;
2095 vport->nvmei_support = 1;
2097 atomic_set(&lport->xmt_fcp_noxri, 0);
2098 atomic_set(&lport->xmt_fcp_bad_ndlp, 0);
2099 atomic_set(&lport->xmt_fcp_qdepth, 0);
2100 atomic_set(&lport->xmt_fcp_err, 0);
2101 atomic_set(&lport->xmt_fcp_wqerr, 0);
2102 atomic_set(&lport->xmt_fcp_abort, 0);
2103 atomic_set(&lport->xmt_ls_abort, 0);
2104 atomic_set(&lport->xmt_ls_err, 0);
2105 atomic_set(&lport->cmpl_fcp_xb, 0);
2106 atomic_set(&lport->cmpl_fcp_err, 0);
2107 atomic_set(&lport->cmpl_ls_xb, 0);
2108 atomic_set(&lport->cmpl_ls_err, 0);
2109 atomic_set(&lport->fc4NvmeLsRequests, 0);
2110 atomic_set(&lport->fc4NvmeLsCmpls, 0);
2116 #if (IS_ENABLED(CONFIG_NVME_FC))
2117 /* lpfc_nvme_lport_unreg_wait - Wait for the host to complete an lport unreg.
2119 * The driver has to wait for the host nvme transport to callback
2120 * indicating the localport has successfully unregistered all
2121 * resources. Since this is an uninterruptible wait, loop every ten
2122 * seconds and print a message indicating no progress.
2124 * An uninterruptible wait is used because of the risk of transport-to-
2125 * driver state mismatch.
2128 lpfc_nvme_lport_unreg_wait(struct lpfc_vport *vport,
2129 struct lpfc_nvme_lport *lport,
2130 struct completion *lport_unreg_cmp)
2133 int ret, i, pending = 0;
2134 struct lpfc_sli_ring *pring;
2135 struct lpfc_hba *phba = vport->phba;
2137 /* Host transport has to clean up and confirm requiring an indefinite
2138 * wait. Print a message if a 10 second wait expires and renew the
2139 * wait. This is unexpected.
2141 wait_tmo = msecs_to_jiffies(LPFC_NVME_WAIT_TMO * 1000);
2143 ret = wait_for_completion_timeout(lport_unreg_cmp, wait_tmo);
2144 if (unlikely(!ret)) {
2146 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2147 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
2150 if (pring->txcmplq_cnt)
2151 pending += pring->txcmplq_cnt;
2153 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
2154 "6176 Lport x%px Localport x%px wait "
2155 "timed out. Pending %d. Renewing.\n",
2156 lport, vport->localport, pending);
2161 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
2162 "6177 Lport x%px Localport x%px Complete Success\n",
2163 lport, vport->localport);
2168 * lpfc_nvme_destroy_localport - Destroy lpfc_nvme bound to nvme transport.
2169 * @pnvme: pointer to lpfc nvme data structure.
2171 * This routine is invoked to destroy all lports bound to the phba.
2172 * The lport memory was allocated by the nvme fc transport and is
2173 * released there. This routine ensures all rports bound to the
2174 * lport have been disconnected.
2178 lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2180 #if (IS_ENABLED(CONFIG_NVME_FC))
2181 struct nvme_fc_local_port *localport;
2182 struct lpfc_nvme_lport *lport;
2184 DECLARE_COMPLETION_ONSTACK(lport_unreg_cmp);
2186 if (vport->nvmei_support == 0)
2189 localport = vport->localport;
2190 lport = (struct lpfc_nvme_lport *)localport->private;
2192 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2193 "6011 Destroying NVME localport x%px\n",
2196 /* lport's rport list is clear. Unregister
2197 * lport and release resources.
2199 lport->lport_unreg_cmp = &lport_unreg_cmp;
2200 ret = nvme_fc_unregister_localport(localport);
2202 /* Wait for completion. This either blocks
2203 * indefinitely or succeeds
2205 lpfc_nvme_lport_unreg_wait(vport, lport, &lport_unreg_cmp);
2206 vport->localport = NULL;
2208 /* Regardless of the unregister upcall response, clear
2209 * nvmei_support. All rports are unregistered and the
2210 * driver will clean up.
2212 vport->nvmei_support = 0;
2214 lpfc_printf_vlog(vport,
2215 KERN_INFO, LOG_NVME_DISC,
2216 "6009 Unregistered lport Success\n");
2218 lpfc_printf_vlog(vport,
2219 KERN_INFO, LOG_NVME_DISC,
2220 "6010 Unregistered lport "
2221 "Failed, status x%x\n",
2228 lpfc_nvme_update_localport(struct lpfc_vport *vport)
2230 #if (IS_ENABLED(CONFIG_NVME_FC))
2231 struct nvme_fc_local_port *localport;
2232 struct lpfc_nvme_lport *lport;
2234 localport = vport->localport;
2236 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2237 "6710 Update NVME fail. No localport\n");
2240 lport = (struct lpfc_nvme_lport *)localport->private;
2242 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2243 "6171 Update NVME fail. localP x%px, No lport\n",
2247 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2248 "6012 Update NVME lport x%px did x%x\n",
2249 localport, vport->fc_myDID);
2251 localport->port_id = vport->fc_myDID;
2252 if (localport->port_id == 0)
2253 localport->port_role = FC_PORT_ROLE_NVME_DISCOVERY;
2255 localport->port_role = FC_PORT_ROLE_NVME_INITIATOR;
2257 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2258 "6030 bound lport x%px to DID x%06x\n",
2259 lport, localport->port_id);
2264 lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2266 #if (IS_ENABLED(CONFIG_NVME_FC))
2268 struct nvme_fc_local_port *localport;
2269 struct lpfc_nvme_lport *lport;
2270 struct lpfc_nvme_rport *rport;
2271 struct lpfc_nvme_rport *oldrport;
2272 struct nvme_fc_remote_port *remote_port;
2273 struct nvme_fc_port_info rpinfo;
2274 struct lpfc_nodelist *prev_ndlp = NULL;
2276 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC,
2277 "6006 Register NVME PORT. DID x%06x nlptype x%x\n",
2278 ndlp->nlp_DID, ndlp->nlp_type);
2280 localport = vport->localport;
2284 lport = (struct lpfc_nvme_lport *)localport->private;
2286 /* NVME rports are not preserved across devloss.
2287 * Just register this instance. Note, rpinfo->dev_loss_tmo
2288 * is left 0 to indicate accept transport defaults. The
2289 * driver communicates port role capabilities consistent
2290 * with the PRLI response data.
2292 memset(&rpinfo, 0, sizeof(struct nvme_fc_port_info));
2293 rpinfo.port_id = ndlp->nlp_DID;
2294 if (ndlp->nlp_type & NLP_NVME_TARGET)
2295 rpinfo.port_role |= FC_PORT_ROLE_NVME_TARGET;
2296 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
2297 rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR;
2299 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
2300 rpinfo.port_role |= FC_PORT_ROLE_NVME_DISCOVERY;
2302 rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
2303 rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
2305 spin_lock_irq(&vport->phba->hbalock);
2306 oldrport = lpfc_ndlp_get_nrport(ndlp);
2308 prev_ndlp = oldrport->ndlp;
2309 spin_unlock_irq(&vport->phba->hbalock);
2311 spin_unlock_irq(&vport->phba->hbalock);
2315 ret = nvme_fc_register_remoteport(localport, &rpinfo, &remote_port);
2317 /* If the ndlp already has an nrport, this is just
2318 * a resume of the existing rport. Else this is a
2321 /* Guard against an unregister/reregister
2322 * race that leaves the WAIT flag set.
2324 spin_lock_irq(&vport->phba->hbalock);
2325 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
2326 spin_unlock_irq(&vport->phba->hbalock);
2327 rport = remote_port->private;
2329 /* New remoteport record does not guarantee valid
2330 * host private memory area.
2332 if (oldrport == remote_port->private) {
2333 /* Same remoteport - ndlp should match.
2336 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2338 "6014 Rebind lport to current "
2339 "remoteport x%px wwpn 0x%llx, "
2340 "Data: x%x x%x x%px x%px x%x "
2343 remote_port->port_name,
2344 remote_port->port_id,
2345 remote_port->port_role,
2351 /* It's a complete rebind only if the driver
2352 * is registering with the same ndlp. Otherwise
2353 * the driver likely executed a node swap
2354 * prior to this registration and the ndlp to
2355 * remoteport binding needs to be redone.
2357 if (prev_ndlp == ndlp)
2362 /* Sever the ndlp<->rport association
2363 * before dropping the ndlp ref from
2366 spin_lock_irq(&vport->phba->hbalock);
2367 ndlp->nrport = NULL;
2368 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
2369 spin_unlock_irq(&vport->phba->hbalock);
2371 rport->remoteport = NULL;
2373 /* Reference only removed if previous NDLP is no longer
2374 * active. It might be just a swap and removing the
2375 * reference would cause a premature cleanup.
2377 if (prev_ndlp && prev_ndlp != ndlp) {
2378 if ((!NLP_CHK_NODE_ACT(prev_ndlp)) ||
2379 (!prev_ndlp->nrport))
2380 lpfc_nlp_put(prev_ndlp);
2384 /* Clean bind the rport to the ndlp. */
2385 rport->remoteport = remote_port;
2386 rport->lport = lport;
2388 spin_lock_irq(&vport->phba->hbalock);
2389 ndlp->nrport = rport;
2390 spin_unlock_irq(&vport->phba->hbalock);
2391 lpfc_printf_vlog(vport, KERN_INFO,
2392 LOG_NVME_DISC | LOG_NODE,
2393 "6022 Bind lport x%px to remoteport x%px "
2394 "rport x%px WWNN 0x%llx, "
2395 "Rport WWPN 0x%llx DID "
2396 "x%06x Role x%x, ndlp %p prev_ndlp x%px\n",
2397 lport, remote_port, rport,
2398 rpinfo.node_name, rpinfo.port_name,
2399 rpinfo.port_id, rpinfo.port_role,
2402 lpfc_printf_vlog(vport, KERN_ERR,
2403 LOG_NVME_DISC | LOG_NODE,
2404 "6031 RemotePort Registration failed "
2405 "err: %d, DID x%06x\n",
2406 ret, ndlp->nlp_DID);
2416 * lpfc_nvme_rescan_port - Check to see if we should rescan this remoteport
2418 * If the ndlp represents an NVME Target, that we are logged into,
2419 * ping the NVME FC Transport layer to initiate a device rescan
2420 * on this remote NPort.
2423 lpfc_nvme_rescan_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2425 #if (IS_ENABLED(CONFIG_NVME_FC))
2426 struct lpfc_nvme_rport *nrport;
2427 struct nvme_fc_remote_port *remoteport = NULL;
2429 spin_lock_irq(&vport->phba->hbalock);
2430 nrport = lpfc_ndlp_get_nrport(ndlp);
2432 remoteport = nrport->remoteport;
2433 spin_unlock_irq(&vport->phba->hbalock);
2435 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2436 "6170 Rescan NPort DID x%06x type x%x "
2437 "state x%x nrport x%px remoteport x%px\n",
2438 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_state,
2439 nrport, remoteport);
2441 if (!nrport || !remoteport)
2444 /* Only rescan if we are an NVME target in the MAPPED state */
2445 if (remoteport->port_role & FC_PORT_ROLE_NVME_DISCOVERY &&
2446 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
2447 nvme_fc_rescan_remoteport(remoteport);
2449 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2450 "6172 NVME rescanned DID x%06x "
2452 ndlp->nlp_DID, remoteport->port_state);
2456 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2457 "6169 Skip NVME Rport Rescan, NVME remoteport "
2462 /* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport.
2464 * There is no notion of Devloss or rport recovery from the current
2465 * nvme_transport perspective. Loss of an rport just means IO cannot
2466 * be sent and recovery is completely up to the initator.
2467 * For now, the driver just unbinds the DID and port_role so that
2468 * no further IO can be issued. Changes are planned for later.
2470 * Notes - the ndlp reference count is not decremented here since
2471 * since there is no nvme_transport api for devloss. Node ref count
2472 * is only adjusted in driver unload.
2475 lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2477 #if (IS_ENABLED(CONFIG_NVME_FC))
2479 struct nvme_fc_local_port *localport;
2480 struct lpfc_nvme_lport *lport;
2481 struct lpfc_nvme_rport *rport;
2482 struct nvme_fc_remote_port *remoteport = NULL;
2484 localport = vport->localport;
2486 /* This is fundamental error. The localport is always
2487 * available until driver unload. Just exit.
2492 lport = (struct lpfc_nvme_lport *)localport->private;
2496 spin_lock_irq(&vport->phba->hbalock);
2497 rport = lpfc_ndlp_get_nrport(ndlp);
2499 remoteport = rport->remoteport;
2500 spin_unlock_irq(&vport->phba->hbalock);
2504 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2505 "6033 Unreg nvme remoteport x%px, portname x%llx, "
2506 "port_id x%06x, portstate x%x port type x%x\n",
2507 remoteport, remoteport->port_name,
2508 remoteport->port_id, remoteport->port_state,
2511 /* Sanity check ndlp type. Only call for NVME ports. Don't
2512 * clear any rport state until the transport calls back.
2515 if (ndlp->nlp_type & NLP_NVME_TARGET) {
2516 /* No concern about the role change on the nvme remoteport.
2517 * The transport will update it.
2519 ndlp->upcall_flags |= NLP_WAIT_FOR_UNREG;
2521 /* Don't let the host nvme transport keep sending keep-alives
2522 * on this remoteport. Vport is unloading, no recovery. The
2523 * return values is ignored. The upcall is a courtesy to the
2526 if (vport->load_flag & FC_UNLOADING)
2527 (void)nvme_fc_set_remoteport_devloss(remoteport, 0);
2529 ret = nvme_fc_unregister_remoteport(remoteport);
2532 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2533 "6167 NVME unregister failed %d "
2535 ret, remoteport->port_state);
2542 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2543 "6168 State error: lport x%px, rport x%px FCID x%06x\n",
2544 vport->localport, ndlp->rport, ndlp->nlp_DID);
2548 * lpfc_sli4_nvme_xri_aborted - Fast-path process of NVME xri abort
2549 * @phba: pointer to lpfc hba data structure.
2550 * @axri: pointer to the fcp xri abort wcqe structure.
2551 * @lpfc_ncmd: The nvme job structure for the request being aborted.
2553 * This routine is invoked by the worker thread to process a SLI4 fast-path
2554 * NVME aborted xri. Aborted NVME IO commands are completed to the transport
2558 lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba,
2559 struct sli4_wcqe_xri_aborted *axri,
2560 struct lpfc_io_buf *lpfc_ncmd)
2562 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
2563 struct nvmefc_fcp_req *nvme_cmd = NULL;
2564 struct lpfc_nodelist *ndlp = lpfc_ncmd->ndlp;
2568 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
2570 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2571 "6311 nvme_cmd %p xri x%x tag x%x abort complete and "
2573 lpfc_ncmd->nvmeCmd, xri,
2574 lpfc_ncmd->cur_iocbq.iotag);
2576 /* Aborted NVME commands are required to not complete
2577 * before the abort exchange command fully completes.
2578 * Once completed, it is available via the put list.
2580 if (lpfc_ncmd->nvmeCmd) {
2581 nvme_cmd = lpfc_ncmd->nvmeCmd;
2582 nvme_cmd->done(nvme_cmd);
2583 lpfc_ncmd->nvmeCmd = NULL;
2585 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2589 * lpfc_nvme_wait_for_io_drain - Wait for all NVME wqes to complete
2590 * @phba: Pointer to HBA context object.
2592 * This function flushes all wqes in the nvme rings and frees all resources
2593 * in the txcmplq. This function does not issue abort wqes for the IO
2594 * commands in txcmplq, they will just be returned with
2595 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
2596 * slot has been permanently disabled.
2599 lpfc_nvme_wait_for_io_drain(struct lpfc_hba *phba)
2601 struct lpfc_sli_ring *pring;
2602 u32 i, wait_cnt = 0;
2604 if (phba->sli_rev < LPFC_SLI_REV4 || !phba->sli4_hba.hdwq)
2607 /* Cycle through all IO rings and make sure all outstanding
2608 * WQEs have been removed from the txcmplqs.
2610 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2611 if (!phba->sli4_hba.hdwq[i].io_wq)
2613 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
2618 /* Retrieve everything on the txcmplq */
2619 while (!list_empty(&pring->txcmplq)) {
2620 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
2623 /* The sleep is 10mS. Every ten seconds,
2624 * dump a message. Something is wrong.
2626 if ((wait_cnt % 1000) == 0) {
2627 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
2628 "6178 NVME IO not empty, "
2629 "cnt %d\n", wait_cnt);
2636 lpfc_nvme_cancel_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn)
2638 #if (IS_ENABLED(CONFIG_NVME_FC))
2639 struct lpfc_io_buf *lpfc_ncmd;
2640 struct nvmefc_fcp_req *nCmd;
2641 struct lpfc_nvme_fcpreq_priv *freqpriv;
2643 if (!pwqeIn->context1) {
2644 lpfc_sli_release_iocbq(phba, pwqeIn);
2647 /* For abort iocb just return, IO iocb will do a done call */
2648 if (bf_get(wqe_cmnd, &pwqeIn->wqe.gen_req.wqe_com) ==
2650 lpfc_sli_release_iocbq(phba, pwqeIn);
2653 lpfc_ncmd = (struct lpfc_io_buf *)pwqeIn->context1;
2655 spin_lock(&lpfc_ncmd->buf_lock);
2656 if (!lpfc_ncmd->nvmeCmd) {
2657 spin_unlock(&lpfc_ncmd->buf_lock);
2658 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2662 nCmd = lpfc_ncmd->nvmeCmd;
2663 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR,
2664 "6194 NVME Cancel xri %x\n",
2665 lpfc_ncmd->cur_iocbq.sli4_xritag);
2667 nCmd->transferred_length = 0;
2668 nCmd->rcv_rsplen = 0;
2669 nCmd->status = NVME_SC_INTERNAL;
2670 freqpriv = nCmd->private;
2671 freqpriv->nvme_buf = NULL;
2672 lpfc_ncmd->nvmeCmd = NULL;
2674 spin_unlock(&lpfc_ncmd->buf_lock);
2677 /* Call release with XB=1 to queue the IO into the abort list. */
2678 lpfc_release_nvme_buf(phba, lpfc_ncmd);