scsi: lpfc: Extend RDP support
[linux-2.6-block.git] / drivers / scsi / lpfc / lpfc_nvme.c
CommitLineData
01649561
JS
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
d080abe0
JS
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
01649561
JS
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
d080abe0 8 * www.broadcom.com *
01649561
JS
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
10 * *
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>
30
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>
38
39#include <linux/nvme.h>
40#include <linux/nvme-fc-driver.h>
41#include <linux/nvme-fc.h>
42#include "lpfc_version.h"
43#include "lpfc_hw4.h"
44#include "lpfc_hw.h"
45#include "lpfc_sli.h"
46#include "lpfc_sli4.h"
47#include "lpfc_nl.h"
48#include "lpfc_disc.h"
49#include "lpfc.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"
bd2cdd5e 55#include "lpfc_debugfs.h"
01649561
JS
56
57/* NVME initiator-based functions */
58
59static struct lpfc_nvme_buf *
60lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp);
61
62static void
63lpfc_release_nvme_buf(struct lpfc_hba *, struct lpfc_nvme_buf *);
64
65
66/**
67 * lpfc_nvme_create_queue -
68 * @lpfc_pnvme: Pointer to the driver's nvme instance data
69 * @qidx: An cpu index used to affinitize IO queues and MSIX vectors.
70 * @handle: An opaque driver handle used in follow-up calls.
71 *
72 * Driver registers this routine to preallocate and initialize any
73 * internal data structures to bind the @qidx to its internal IO queues.
74 * A hardware queue maps (qidx) to a specific driver MSI-X vector/EQ/CQ/WQ.
75 *
76 * Return value :
77 * 0 - Success
78 * -EINVAL - Unsupported input value.
79 * -ENOMEM - Could not alloc necessary memory
80 **/
81static int
82lpfc_nvme_create_queue(struct nvme_fc_local_port *pnvme_lport,
83 unsigned int qidx, u16 qsize,
84 void **handle)
85{
86 struct lpfc_nvme_lport *lport;
87 struct lpfc_vport *vport;
88 struct lpfc_nvme_qhandle *qhandle;
89 char *str;
90
91 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
92 vport = lport->vport;
93 qhandle = kzalloc(sizeof(struct lpfc_nvme_qhandle), GFP_KERNEL);
94 if (qhandle == NULL)
95 return -ENOMEM;
96
97 qhandle->cpu_id = smp_processor_id();
98 qhandle->qidx = qidx;
99 /*
100 * NVME qidx == 0 is the admin queue, so both admin queue
101 * and first IO queue will use MSI-X vector and associated
102 * EQ/CQ/WQ at index 0. After that they are sequentially assigned.
103 */
104 if (qidx) {
105 str = "IO "; /* IO queue */
106 qhandle->index = ((qidx - 1) %
107 vport->phba->cfg_nvme_io_channel);
108 } else {
109 str = "ADM"; /* Admin queue */
110 qhandle->index = qidx;
111 }
112
d58734f0 113 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
01649561
JS
114 "6073 Binding %s HdwQueue %d (cpu %d) to "
115 "io_channel %d qhandle %p\n", str,
116 qidx, qhandle->cpu_id, qhandle->index, qhandle);
117 *handle = (void *)qhandle;
118 return 0;
119}
120
121/**
122 * lpfc_nvme_delete_queue -
123 * @lpfc_pnvme: Pointer to the driver's nvme instance data
124 * @qidx: An cpu index used to affinitize IO queues and MSIX vectors.
125 * @handle: An opaque driver handle from lpfc_nvme_create_queue
126 *
127 * Driver registers this routine to free
128 * any internal data structures to bind the @qidx to its internal
129 * IO queues.
130 *
131 * Return value :
132 * 0 - Success
133 * TODO: What are the failure codes.
134 **/
135static void
136lpfc_nvme_delete_queue(struct nvme_fc_local_port *pnvme_lport,
137 unsigned int qidx,
138 void *handle)
139{
140 struct lpfc_nvme_lport *lport;
141 struct lpfc_vport *vport;
142
143 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
144 vport = lport->vport;
145
146 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
147 "6001 ENTER. lpfc_pnvme %p, qidx x%xi qhandle %p\n",
148 lport, qidx, handle);
149 kfree(handle);
150}
151
152static void
153lpfc_nvme_localport_delete(struct nvme_fc_local_port *localport)
154{
155 struct lpfc_nvme_lport *lport = localport->private;
156
157 /* release any threads waiting for the unreg to complete */
158 complete(&lport->lport_unreg_done);
159}
160
161/* lpfc_nvme_remoteport_delete
162 *
163 * @remoteport: Pointer to an nvme transport remoteport instance.
164 *
165 * This is a template downcall. NVME transport calls this function
166 * when it has completed the unregistration of a previously
167 * registered remoteport.
168 *
169 * Return value :
170 * None
171 */
172void
173lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport)
174{
175 struct lpfc_nvme_rport *rport = remoteport->private;
176 struct lpfc_vport *vport;
177 struct lpfc_nodelist *ndlp;
178
179 ndlp = rport->ndlp;
180 if (!ndlp)
181 goto rport_err;
182
183 vport = ndlp->vport;
184 if (!vport)
185 goto rport_err;
186
187 /* Remove this rport from the lport's list - memory is owned by the
188 * transport. Remove the ndlp reference for the NVME transport before
7a06dcd3 189 * calling state machine to remove the node.
01649561
JS
190 */
191 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
192 "6146 remoteport delete complete %p\n",
193 remoteport);
7a06dcd3 194 ndlp->nrport = NULL;
01649561
JS
195 lpfc_nlp_put(ndlp);
196
197 rport_err:
198 /* This call has to execute as long as the rport is valid.
199 * Release any threads waiting for the unreg to complete.
200 */
201 complete(&rport->rport_unreg_done);
202}
203
204static void
205lpfc_nvme_cmpl_gen_req(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
206 struct lpfc_wcqe_complete *wcqe)
207{
208 struct lpfc_vport *vport = cmdwqe->vport;
209 uint32_t status;
210 struct nvmefc_ls_req *pnvme_lsreq;
211 struct lpfc_dmabuf *buf_ptr;
212 struct lpfc_nodelist *ndlp;
213
2cee7808 214 atomic_inc(&vport->phba->fc4NvmeLsCmpls);
01649561
JS
215
216 pnvme_lsreq = (struct nvmefc_ls_req *)cmdwqe->context2;
217 status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK;
218 ndlp = (struct lpfc_nodelist *)cmdwqe->context1;
219 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
220 "6047 nvme cmpl Enter "
221 "Data %p DID %x Xri: %x status %x cmd:%p lsreg:%p "
222 "bmp:%p ndlp:%p\n",
223 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
224 cmdwqe->sli4_xritag, status,
225 cmdwqe, pnvme_lsreq, cmdwqe->context3, ndlp);
226
bd2cdd5e
JS
227 lpfc_nvmeio_data(phba, "NVME LS CMPL: xri x%x stat x%x parm x%x\n",
228 cmdwqe->sli4_xritag, status, wcqe->parameter);
229
01649561
JS
230 if (cmdwqe->context3) {
231 buf_ptr = (struct lpfc_dmabuf *)cmdwqe->context3;
232 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
233 kfree(buf_ptr);
234 cmdwqe->context3 = NULL;
235 }
236 if (pnvme_lsreq->done)
237 pnvme_lsreq->done(pnvme_lsreq, status);
238 else
239 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
240 "6046 nvme cmpl without done call back? "
241 "Data %p DID %x Xri: %x status %x\n",
242 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
243 cmdwqe->sli4_xritag, status);
244 if (ndlp) {
245 lpfc_nlp_put(ndlp);
246 cmdwqe->context1 = NULL;
247 }
248 lpfc_sli_release_iocbq(phba, cmdwqe);
249}
250
251static int
252lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
253 struct lpfc_dmabuf *inp,
254 struct nvmefc_ls_req *pnvme_lsreq,
255 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
256 struct lpfc_wcqe_complete *),
257 struct lpfc_nodelist *ndlp, uint32_t num_entry,
258 uint32_t tmo, uint8_t retry)
259{
260 struct lpfc_hba *phba = vport->phba;
261 union lpfc_wqe *wqe;
262 struct lpfc_iocbq *genwqe;
263 struct ulp_bde64 *bpl;
264 struct ulp_bde64 bde;
265 int i, rc, xmit_len, first_len;
266
267 /* Allocate buffer for command WQE */
268 genwqe = lpfc_sli_get_iocbq(phba);
269 if (genwqe == NULL)
270 return 1;
271
272 wqe = &genwqe->wqe;
273 memset(wqe, 0, sizeof(union lpfc_wqe));
274
275 genwqe->context3 = (uint8_t *)bmp;
276 genwqe->iocb_flag |= LPFC_IO_NVME_LS;
277
278 /* Save for completion so we can release these resources */
279 genwqe->context1 = lpfc_nlp_get(ndlp);
280 genwqe->context2 = (uint8_t *)pnvme_lsreq;
281 /* Fill in payload, bp points to frame payload */
282
283 if (!tmo)
284 /* FC spec states we need 3 * ratov for CT requests */
285 tmo = (3 * phba->fc_ratov);
286
287 /* For this command calculate the xmit length of the request bde. */
288 xmit_len = 0;
289 first_len = 0;
290 bpl = (struct ulp_bde64 *)bmp->virt;
291 for (i = 0; i < num_entry; i++) {
292 bde.tus.w = bpl[i].tus.w;
293 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
294 break;
295 xmit_len += bde.tus.f.bdeSize;
296 if (i == 0)
297 first_len = xmit_len;
298 }
299
300 genwqe->rsvd2 = num_entry;
301 genwqe->hba_wqidx = 0;
302
303 /* Words 0 - 2 */
304 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
305 wqe->generic.bde.tus.f.bdeSize = first_len;
306 wqe->generic.bde.addrLow = bpl[0].addrLow;
307 wqe->generic.bde.addrHigh = bpl[0].addrHigh;
308
309 /* Word 3 */
310 wqe->gen_req.request_payload_len = first_len;
311
312 /* Word 4 */
313
314 /* Word 5 */
315 bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0);
316 bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1);
317 bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1);
8b361639 318 bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_ELS4_REQ);
01649561
JS
319 bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME);
320
321 /* Word 6 */
322 bf_set(wqe_ctxt_tag, &wqe->gen_req.wqe_com,
323 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
324 bf_set(wqe_xri_tag, &wqe->gen_req.wqe_com, genwqe->sli4_xritag);
325
326 /* Word 7 */
327 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, (vport->phba->fc_ratov-1));
328 bf_set(wqe_class, &wqe->gen_req.wqe_com, CLASS3);
329 bf_set(wqe_cmnd, &wqe->gen_req.wqe_com, CMD_GEN_REQUEST64_WQE);
330 bf_set(wqe_ct, &wqe->gen_req.wqe_com, SLI4_CT_RPI);
331
332 /* Word 8 */
333 wqe->gen_req.wqe_com.abort_tag = genwqe->iotag;
334
335 /* Word 9 */
336 bf_set(wqe_reqtag, &wqe->gen_req.wqe_com, genwqe->iotag);
337
338 /* Word 10 */
339 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
340 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
341 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
342 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
343 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
344
345 /* Word 11 */
346 bf_set(wqe_cqid, &wqe->gen_req.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
347 bf_set(wqe_cmd_type, &wqe->gen_req.wqe_com, OTHER_COMMAND);
348
349
350 /* Issue GEN REQ WQE for NPORT <did> */
351 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
352 "6050 Issue GEN REQ WQE to NPORT x%x "
353 "Data: x%x x%x wq:%p lsreq:%p bmp:%p xmit:%d 1st:%d\n",
354 ndlp->nlp_DID, genwqe->iotag,
355 vport->port_state,
356 genwqe, pnvme_lsreq, bmp, xmit_len, first_len);
357 genwqe->wqe_cmpl = cmpl;
358 genwqe->iocb_cmpl = NULL;
359 genwqe->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT;
360 genwqe->vport = vport;
361 genwqe->retry = retry;
362
bd2cdd5e
JS
363 lpfc_nvmeio_data(phba, "NVME LS XMIT: xri x%x iotag x%x to x%06x\n",
364 genwqe->sli4_xritag, genwqe->iotag, ndlp->nlp_DID);
365
01649561 366 rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, genwqe);
cd22d605 367 if (rc) {
01649561
JS
368 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
369 "6045 Issue GEN REQ WQE to NPORT x%x "
370 "Data: x%x x%x\n",
371 ndlp->nlp_DID, genwqe->iotag,
372 vport->port_state);
373 lpfc_sli_release_iocbq(phba, genwqe);
374 return 1;
375 }
376 return 0;
377}
378
379/**
380 * lpfc_nvme_ls_req - Issue an Link Service request
381 * @lpfc_pnvme: Pointer to the driver's nvme instance data
382 * @lpfc_nvme_lport: Pointer to the driver's local port data
383 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
384 *
385 * Driver registers this routine to handle any link service request
386 * from the nvme_fc transport to a remote nvme-aware port.
387 *
388 * Return value :
389 * 0 - Success
390 * TODO: What are the failure codes.
391 **/
392static int
393lpfc_nvme_ls_req(struct nvme_fc_local_port *pnvme_lport,
394 struct nvme_fc_remote_port *pnvme_rport,
395 struct nvmefc_ls_req *pnvme_lsreq)
396{
397 int ret = 0;
398 struct lpfc_nvme_lport *lport;
399 struct lpfc_vport *vport;
400 struct lpfc_nodelist *ndlp;
401 struct ulp_bde64 *bpl;
402 struct lpfc_dmabuf *bmp;
ba43c4d0 403 uint16_t ntype, nstate;
01649561
JS
404
405 /* there are two dma buf in the request, actually there is one and
406 * the second one is just the start address + cmd size.
407 * Before calling lpfc_nvme_gen_req these buffers need to be wrapped
408 * in a lpfc_dmabuf struct. When freeing we just free the wrapper
409 * because the nvem layer owns the data bufs.
410 * We do not have to break these packets open, we don't care what is in
411 * them. And we do not have to look at the resonse data, we only care
412 * that we got a response. All of the caring is going to happen in the
413 * nvme-fc layer.
414 */
415
416 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
417 vport = lport->vport;
418
419 ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id);
ba43c4d0
JS
420 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
421 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
422 "6051 DID x%06x not an active rport.\n",
01649561 423 pnvme_rport->port_id);
ba43c4d0
JS
424 return -ENODEV;
425 }
426
427 /* The remote node has to be a mapped nvme target or an
428 * unmapped nvme initiator or it's an error.
429 */
430 ntype = ndlp->nlp_type;
431 nstate = ndlp->nlp_state;
432 if ((ntype & NLP_NVME_TARGET && nstate != NLP_STE_MAPPED_NODE) ||
433 (ntype & NLP_NVME_INITIATOR && nstate != NLP_STE_UNMAPPED_NODE)) {
434 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
435 "6088 DID x%06x not ready for "
436 "IO. State x%x, Type x%x\n",
437 pnvme_rport->port_id,
438 ndlp->nlp_state, ndlp->nlp_type);
439 return -ENODEV;
01649561
JS
440 }
441 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
442 if (!bmp) {
443
444 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
445 "6044 Could not find node for DID %x\n",
446 pnvme_rport->port_id);
447 return 2;
448 }
449 INIT_LIST_HEAD(&bmp->list);
450 bmp->virt = lpfc_mbuf_alloc(vport->phba, MEM_PRI, &(bmp->phys));
451 if (!bmp->virt) {
452 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
453 "6042 Could not find node for DID %x\n",
454 pnvme_rport->port_id);
455 kfree(bmp);
456 return 3;
457 }
458 bpl = (struct ulp_bde64 *)bmp->virt;
459 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rqstdma));
460 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rqstdma));
461 bpl->tus.f.bdeFlags = 0;
462 bpl->tus.f.bdeSize = pnvme_lsreq->rqstlen;
463 bpl->tus.w = le32_to_cpu(bpl->tus.w);
464 bpl++;
465
466 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rspdma));
467 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rspdma));
468 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
469 bpl->tus.f.bdeSize = pnvme_lsreq->rsplen;
470 bpl->tus.w = le32_to_cpu(bpl->tus.w);
471
472 /* Expand print to include key fields. */
473 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
ba43c4d0 474 "6149 ENTER. lport %p, rport %p lsreq%p rqstlen:%d "
825c6abb 475 "rsplen:%d %pad %pad\n",
01649561
JS
476 pnvme_lport, pnvme_rport,
477 pnvme_lsreq, pnvme_lsreq->rqstlen,
825c6abb
AB
478 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
479 &pnvme_lsreq->rspdma);
01649561 480
2cee7808 481 atomic_inc(&vport->phba->fc4NvmeLsRequests);
01649561
JS
482
483 /* Hardcode the wait to 30 seconds. Connections are failing otherwise.
484 * This code allows it all to work.
485 */
486 ret = lpfc_nvme_gen_req(vport, bmp, pnvme_lsreq->rqstaddr,
487 pnvme_lsreq, lpfc_nvme_cmpl_gen_req,
488 ndlp, 2, 30, 0);
489 if (ret != WQE_SUCCESS) {
490 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
491 "6052 EXIT. issue ls wqe failed lport %p, "
492 "rport %p lsreq%p Status %x DID %x\n",
493 pnvme_lport, pnvme_rport, pnvme_lsreq,
494 ret, ndlp->nlp_DID);
495 lpfc_mbuf_free(vport->phba, bmp->virt, bmp->phys);
496 kfree(bmp);
497 return ret;
498 }
499
500 /* Stub in routine and return 0 for now. */
501 return ret;
502}
503
504/**
505 * lpfc_nvme_ls_abort - Issue an Link Service request
506 * @lpfc_pnvme: Pointer to the driver's nvme instance data
507 * @lpfc_nvme_lport: Pointer to the driver's local port data
508 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
509 *
510 * Driver registers this routine to handle any link service request
511 * from the nvme_fc transport to a remote nvme-aware port.
512 *
513 * Return value :
514 * 0 - Success
515 * TODO: What are the failure codes.
516 **/
517static void
518lpfc_nvme_ls_abort(struct nvme_fc_local_port *pnvme_lport,
519 struct nvme_fc_remote_port *pnvme_rport,
520 struct nvmefc_ls_req *pnvme_lsreq)
521{
522 struct lpfc_nvme_lport *lport;
523 struct lpfc_vport *vport;
524 struct lpfc_hba *phba;
525 struct lpfc_nodelist *ndlp;
526 LIST_HEAD(abort_list);
527 struct lpfc_sli_ring *pring;
528 struct lpfc_iocbq *wqe, *next_wqe;
529
530 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
531 vport = lport->vport;
532 phba = vport->phba;
533
534 ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id);
535 if (!ndlp) {
536 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
537 "6049 Could not find node for DID %x\n",
538 pnvme_rport->port_id);
539 return;
540 }
541
542 /* Expand print to include key fields. */
543 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
544 "6040 ENTER. lport %p, rport %p lsreq %p rqstlen:%d "
825c6abb 545 "rsplen:%d %pad %pad\n",
01649561
JS
546 pnvme_lport, pnvme_rport,
547 pnvme_lsreq, pnvme_lsreq->rqstlen,
825c6abb
AB
548 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
549 &pnvme_lsreq->rspdma);
01649561
JS
550
551 /*
552 * Lock the ELS ring txcmplq and build a local list of all ELS IOs
553 * that need an ABTS. The IOs need to stay on the txcmplq so that
554 * the abort operation completes them successfully.
555 */
556 pring = phba->sli4_hba.nvmels_wq->pring;
557 spin_lock_irq(&phba->hbalock);
558 spin_lock(&pring->ring_lock);
559 list_for_each_entry_safe(wqe, next_wqe, &pring->txcmplq, list) {
560 /* Add to abort_list on on NDLP match. */
561 if (lpfc_check_sli_ndlp(phba, pring, wqe, ndlp)) {
562 wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
563 list_add_tail(&wqe->dlist, &abort_list);
564 }
565 }
566 spin_unlock(&pring->ring_lock);
567 spin_unlock_irq(&phba->hbalock);
568
569 /* Abort the targeted IOs and remove them from the abort list. */
570 list_for_each_entry_safe(wqe, next_wqe, &abort_list, dlist) {
571 spin_lock_irq(&phba->hbalock);
572 list_del_init(&wqe->dlist);
573 lpfc_sli_issue_abort_iotag(phba, pring, wqe);
574 spin_unlock_irq(&phba->hbalock);
575 }
576}
577
578/* Fix up the existing sgls for NVME IO. */
579static void
580lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport,
581 struct lpfc_nvme_buf *lpfc_ncmd,
582 struct nvmefc_fcp_req *nCmd)
583{
584 struct sli4_sge *sgl;
585 union lpfc_wqe128 *wqe;
586 uint32_t *wptr, *dptr;
587
588 /*
589 * Adjust the FCP_CMD and FCP_RSP DMA data and sge_len to
590 * match NVME. NVME sends 96 bytes. Also, use the
591 * nvme commands command and response dma addresses
592 * rather than the virtual memory to ease the restore
593 * operation.
594 */
595 sgl = lpfc_ncmd->nvme_sgl;
596 sgl->sge_len = cpu_to_le32(nCmd->cmdlen);
597
598 sgl++;
599
600 /* Setup the physical region for the FCP RSP */
601 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->rspdma));
602 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->rspdma));
603 sgl->word2 = le32_to_cpu(sgl->word2);
604 if (nCmd->sg_cnt)
605 bf_set(lpfc_sli4_sge_last, sgl, 0);
606 else
607 bf_set(lpfc_sli4_sge_last, sgl, 1);
608 sgl->word2 = cpu_to_le32(sgl->word2);
609 sgl->sge_len = cpu_to_le32(nCmd->rsplen);
610
611 /*
612 * Get a local pointer to the built-in wqe and correct
613 * the cmd size to match NVME's 96 bytes and fix
614 * the dma address.
615 */
616
617 /* 128 byte wqe support here */
618 wqe = (union lpfc_wqe128 *)&lpfc_ncmd->cur_iocbq.wqe;
619
620 /* Word 0-2 - NVME CMND IU (embedded payload) */
621 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_IMMED;
622 wqe->generic.bde.tus.f.bdeSize = 60;
623 wqe->generic.bde.addrHigh = 0;
624 wqe->generic.bde.addrLow = 64; /* Word 16 */
625
626 /* Word 3 */
627 bf_set(payload_offset_len, &wqe->fcp_icmd,
628 (nCmd->rsplen + nCmd->cmdlen));
629
630 /* Word 10 */
631 bf_set(wqe_nvme, &wqe->fcp_icmd.wqe_com, 1);
632 bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
633
634 /*
635 * Embed the payload in the last half of the WQE
636 * WQE words 16-30 get the NVME CMD IU payload
637 *
b06a622f 638 * WQE words 16-19 get payload Words 1-4
01649561
JS
639 * WQE words 20-21 get payload Words 6-7
640 * WQE words 22-29 get payload Words 16-23
641 */
b06a622f 642 wptr = &wqe->words[16]; /* WQE ptr */
01649561 643 dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */
b06a622f 644 dptr++; /* Skip Word 0 in payload */
01649561 645
b06a622f 646 *wptr++ = *dptr++; /* Word 1 */
01649561
JS
647 *wptr++ = *dptr++; /* Word 2 */
648 *wptr++ = *dptr++; /* Word 3 */
649 *wptr++ = *dptr++; /* Word 4 */
650 dptr++; /* Skip Word 5 in payload */
651 *wptr++ = *dptr++; /* Word 6 */
652 *wptr++ = *dptr++; /* Word 7 */
653 dptr += 8; /* Skip Words 8-15 in payload */
654 *wptr++ = *dptr++; /* Word 16 */
655 *wptr++ = *dptr++; /* Word 17 */
656 *wptr++ = *dptr++; /* Word 18 */
657 *wptr++ = *dptr++; /* Word 19 */
658 *wptr++ = *dptr++; /* Word 20 */
659 *wptr++ = *dptr++; /* Word 21 */
660 *wptr++ = *dptr++; /* Word 22 */
661 *wptr = *dptr; /* Word 23 */
662}
663
bd2cdd5e
JS
664#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
665static void
666lpfc_nvme_ktime(struct lpfc_hba *phba,
667 struct lpfc_nvme_buf *lpfc_ncmd)
668{
669 uint64_t seg1, seg2, seg3, seg4;
c8a4ce0b 670 uint64_t segsum;
bd2cdd5e 671
bd2cdd5e
JS
672 if (!lpfc_ncmd->ts_last_cmd ||
673 !lpfc_ncmd->ts_cmd_start ||
674 !lpfc_ncmd->ts_cmd_wqput ||
675 !lpfc_ncmd->ts_isr_cmpl ||
676 !lpfc_ncmd->ts_data_nvme)
677 return;
c8a4ce0b
DK
678
679 if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_cmd_start)
680 return;
bd2cdd5e
JS
681 if (lpfc_ncmd->ts_cmd_start < lpfc_ncmd->ts_last_cmd)
682 return;
683 if (lpfc_ncmd->ts_cmd_wqput < lpfc_ncmd->ts_cmd_start)
684 return;
685 if (lpfc_ncmd->ts_isr_cmpl < lpfc_ncmd->ts_cmd_wqput)
686 return;
687 if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_isr_cmpl)
688 return;
689 /*
690 * Segment 1 - Time from Last FCP command cmpl is handed
691 * off to NVME Layer to start of next command.
692 * Segment 2 - Time from Driver receives a IO cmd start
693 * from NVME Layer to WQ put is done on IO cmd.
694 * Segment 3 - Time from Driver WQ put is done on IO cmd
695 * to MSI-X ISR for IO cmpl.
696 * Segment 4 - Time from MSI-X ISR for IO cmpl to when
697 * cmpl is handled off to the NVME Layer.
698 */
699 seg1 = lpfc_ncmd->ts_cmd_start - lpfc_ncmd->ts_last_cmd;
c8a4ce0b
DK
700 if (seg1 > 5000000) /* 5 ms - for sequential IOs only */
701 seg1 = 0;
bd2cdd5e
JS
702
703 /* Calculate times relative to start of IO */
704 seg2 = (lpfc_ncmd->ts_cmd_wqput - lpfc_ncmd->ts_cmd_start);
c8a4ce0b
DK
705 segsum = seg2;
706 seg3 = lpfc_ncmd->ts_isr_cmpl - lpfc_ncmd->ts_cmd_start;
707 if (segsum > seg3)
708 return;
709 seg3 -= segsum;
710 segsum += seg3;
711
712 seg4 = lpfc_ncmd->ts_data_nvme - lpfc_ncmd->ts_cmd_start;
713 if (segsum > seg4)
714 return;
715 seg4 -= segsum;
716
bd2cdd5e
JS
717 phba->ktime_data_samples++;
718 phba->ktime_seg1_total += seg1;
719 if (seg1 < phba->ktime_seg1_min)
720 phba->ktime_seg1_min = seg1;
721 else if (seg1 > phba->ktime_seg1_max)
722 phba->ktime_seg1_max = seg1;
723 phba->ktime_seg2_total += seg2;
724 if (seg2 < phba->ktime_seg2_min)
725 phba->ktime_seg2_min = seg2;
726 else if (seg2 > phba->ktime_seg2_max)
727 phba->ktime_seg2_max = seg2;
728 phba->ktime_seg3_total += seg3;
729 if (seg3 < phba->ktime_seg3_min)
730 phba->ktime_seg3_min = seg3;
731 else if (seg3 > phba->ktime_seg3_max)
732 phba->ktime_seg3_max = seg3;
733 phba->ktime_seg4_total += seg4;
734 if (seg4 < phba->ktime_seg4_min)
735 phba->ktime_seg4_min = seg4;
736 else if (seg4 > phba->ktime_seg4_max)
737 phba->ktime_seg4_max = seg4;
738
739 lpfc_ncmd->ts_last_cmd = 0;
740 lpfc_ncmd->ts_cmd_start = 0;
741 lpfc_ncmd->ts_cmd_wqput = 0;
742 lpfc_ncmd->ts_isr_cmpl = 0;
743 lpfc_ncmd->ts_data_nvme = 0;
744}
745#endif
746
01649561
JS
747/**
748 * lpfc_nvme_io_cmd_wqe_cmpl - Complete an NVME-over-FCP IO
749 * @lpfc_pnvme: Pointer to the driver's nvme instance data
750 * @lpfc_nvme_lport: Pointer to the driver's local port data
751 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
752 *
753 * Driver registers this routine as it io request handler. This
754 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
755 * data structure to the rport indicated in @lpfc_nvme_rport.
756 *
757 * Return value :
758 * 0 - Success
759 * TODO: What are the failure codes.
760 **/
761static void
762lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
763 struct lpfc_wcqe_complete *wcqe)
764{
765 struct lpfc_nvme_buf *lpfc_ncmd =
766 (struct lpfc_nvme_buf *)pwqeIn->context1;
767 struct lpfc_vport *vport = pwqeIn->vport;
768 struct nvmefc_fcp_req *nCmd;
769 struct nvme_fc_ersp_iu *ep;
770 struct nvme_fc_cmd_iu *cp;
771 struct lpfc_nvme_rport *rport;
772 struct lpfc_nodelist *ndlp;
bbe3012b 773 struct lpfc_nvme_fcpreq_priv *freqpriv;
01649561
JS
774 unsigned long flags;
775 uint32_t code;
776 uint16_t cid, sqhd, data;
777 uint32_t *ptr;
778
779 /* Sanity check on return of outstanding command */
780 if (!lpfc_ncmd || !lpfc_ncmd->nvmeCmd || !lpfc_ncmd->nrport) {
781 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
782 "6071 Completion pointers bad on wqe %p.\n",
783 wcqe);
784 return;
785 }
2cee7808 786 atomic_inc(&phba->fc4NvmeIoCmpls);
01649561
JS
787
788 nCmd = lpfc_ncmd->nvmeCmd;
789 rport = lpfc_ncmd->nrport;
790
bd2cdd5e
JS
791 lpfc_nvmeio_data(phba, "NVME FCP CMPL: xri x%x stat x%x parm x%x\n",
792 lpfc_ncmd->cur_iocbq.sli4_xritag,
793 bf_get(lpfc_wcqe_c_status, wcqe), wcqe->parameter);
01649561
JS
794 /*
795 * Catch race where our node has transitioned, but the
796 * transport is still transitioning.
797 */
798 ndlp = rport->ndlp;
799 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
800 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
c154e750
JS
801 "6061 rport %p, DID x%06x node not ready.\n",
802 rport, rport->remoteport->port_id);
01649561
JS
803
804 ndlp = lpfc_findnode_did(vport, rport->remoteport->port_id);
805 if (!ndlp) {
806 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
807 "6062 Ignoring NVME cmpl. No ndlp\n");
808 goto out_err;
809 }
810 }
811
812 code = bf_get(lpfc_wcqe_c_code, wcqe);
813 if (code == CQE_CODE_NVME_ERSP) {
814 /* For this type of CQE, we need to rebuild the rsp */
815 ep = (struct nvme_fc_ersp_iu *)nCmd->rspaddr;
816
817 /*
818 * Get Command Id from cmd to plug into response. This
819 * code is not needed in the next NVME Transport drop.
820 */
821 cp = (struct nvme_fc_cmd_iu *)nCmd->cmdaddr;
822 cid = cp->sqe.common.command_id;
823
824 /*
825 * RSN is in CQE word 2
826 * SQHD is in CQE Word 3 bits 15:0
827 * Cmd Specific info is in CQE Word 1
828 * and in CQE Word 0 bits 15:0
829 */
830 sqhd = bf_get(lpfc_wcqe_c_sqhead, wcqe);
831
832 /* Now lets build the NVME ERSP IU */
833 ep->iu_len = cpu_to_be16(8);
834 ep->rsn = wcqe->parameter;
835 ep->xfrd_len = cpu_to_be32(nCmd->payload_length);
836 ep->rsvd12 = 0;
837 ptr = (uint32_t *)&ep->cqe.result.u64;
838 *ptr++ = wcqe->total_data_placed;
839 data = bf_get(lpfc_wcqe_c_ersp0, wcqe);
840 *ptr = (uint32_t)data;
841 ep->cqe.sq_head = sqhd;
842 ep->cqe.sq_id = nCmd->sqid;
843 ep->cqe.command_id = cid;
844 ep->cqe.status = 0;
845
846 lpfc_ncmd->status = IOSTAT_SUCCESS;
847 lpfc_ncmd->result = 0;
848 nCmd->rcv_rsplen = LPFC_NVME_ERSP_LEN;
849 nCmd->transferred_length = nCmd->payload_length;
850 } else {
851 lpfc_ncmd->status = (bf_get(lpfc_wcqe_c_status, wcqe) &
852 LPFC_IOCB_STATUS_MASK);
952c303b 853 lpfc_ncmd->result = (wcqe->parameter & IOERR_PARAM_MASK);
01649561
JS
854
855 /* For NVME, the only failure path that results in an
856 * IO error is when the adapter rejects it. All other
857 * conditions are a success case and resolved by the
858 * transport.
859 * IOSTAT_FCP_RSP_ERROR means:
860 * 1. Length of data received doesn't match total
861 * transfer length in WQE
862 * 2. If the RSP payload does NOT match these cases:
863 * a. RSP length 12/24 bytes and all zeros
864 * b. NVME ERSP
865 */
866 switch (lpfc_ncmd->status) {
867 case IOSTAT_SUCCESS:
868 nCmd->transferred_length = wcqe->total_data_placed;
869 nCmd->rcv_rsplen = 0;
870 nCmd->status = 0;
871 break;
872 case IOSTAT_FCP_RSP_ERROR:
873 nCmd->transferred_length = wcqe->total_data_placed;
874 nCmd->rcv_rsplen = wcqe->parameter;
875 nCmd->status = 0;
876 /* Sanity check */
877 if (nCmd->rcv_rsplen == LPFC_NVME_ERSP_LEN)
878 break;
879 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
880 "6081 NVME Completion Protocol Error: "
86c67379
JS
881 "xri %x status x%x result x%x "
882 "placed x%x\n",
883 lpfc_ncmd->cur_iocbq.sli4_xritag,
01649561
JS
884 lpfc_ncmd->status, lpfc_ncmd->result,
885 wcqe->total_data_placed);
886 break;
952c303b
DK
887 case IOSTAT_LOCAL_REJECT:
888 /* Let fall through to set command final state. */
889 if (lpfc_ncmd->result == IOERR_ABORT_REQUESTED)
890 lpfc_printf_vlog(vport, KERN_INFO,
891 LOG_NVME_IOERR,
892 "6032 Delay Aborted cmd %p "
893 "nvme cmd %p, xri x%x, "
894 "xb %d\n",
895 lpfc_ncmd, nCmd,
896 lpfc_ncmd->cur_iocbq.sli4_xritag,
897 bf_get(lpfc_wcqe_c_xb, wcqe));
01649561
JS
898 default:
899out_err:
e3246a12 900 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
86c67379 901 "6072 NVME Completion Error: xri %x "
01649561 902 "status x%x result x%x placed x%x\n",
86c67379 903 lpfc_ncmd->cur_iocbq.sli4_xritag,
01649561
JS
904 lpfc_ncmd->status, lpfc_ncmd->result,
905 wcqe->total_data_placed);
906 nCmd->transferred_length = 0;
907 nCmd->rcv_rsplen = 0;
908 nCmd->status = NVME_SC_FC_TRANSPORT_ERROR;
909 }
910 }
911
912 /* pick up SLI4 exhange busy condition */
913 if (bf_get(lpfc_wcqe_c_xb, wcqe))
914 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
915 else
916 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
917
918 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
919 atomic_dec(&ndlp->cmd_pending);
920
921 /* Update stats and complete the IO. There is
922 * no need for dma unprep because the nvme_transport
923 * owns the dma address.
924 */
bd2cdd5e 925#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
c8a4ce0b 926 if (lpfc_ncmd->ts_cmd_start) {
bd2cdd5e
JS
927 lpfc_ncmd->ts_isr_cmpl = pwqeIn->isr_timestamp;
928 lpfc_ncmd->ts_data_nvme = ktime_get_ns();
929 phba->ktime_last_cmd = lpfc_ncmd->ts_data_nvme;
930 lpfc_nvme_ktime(phba, lpfc_ncmd);
931 }
932 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) {
933 if (lpfc_ncmd->cpu != smp_processor_id())
934 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
935 "6701 CPU Check cmpl: "
936 "cpu %d expect %d\n",
937 smp_processor_id(), lpfc_ncmd->cpu);
938 if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT)
939 phba->cpucheck_cmpl_io[lpfc_ncmd->cpu]++;
940 }
941#endif
bbe3012b
JS
942 freqpriv = nCmd->private;
943 freqpriv->nvme_buf = NULL;
952c303b
DK
944
945 /* NVME targets need completion held off until the abort exchange
946 * completes.
947 */
948 if (!lpfc_ncmd->flags & LPFC_SBUF_XBUSY)
949 nCmd->done(nCmd);
01649561
JS
950
951 spin_lock_irqsave(&phba->hbalock, flags);
952 lpfc_ncmd->nrport = NULL;
953 spin_unlock_irqrestore(&phba->hbalock, flags);
954
952c303b 955 /* Call release with XB=1 to queue the IO into the abort list. */
01649561
JS
956 lpfc_release_nvme_buf(phba, lpfc_ncmd);
957}
958
959
960/**
961 * lpfc_nvme_prep_io_cmd - Issue an NVME-over-FCP IO
962 * @lpfc_pnvme: Pointer to the driver's nvme instance data
963 * @lpfc_nvme_lport: Pointer to the driver's local port data
964 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
965 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
966 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
967 *
968 * Driver registers this routine as it io request handler. This
969 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
970 * data structure to the rport indicated in @lpfc_nvme_rport.
971 *
972 * Return value :
973 * 0 - Success
974 * TODO: What are the failure codes.
975 **/
976static int
977lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport,
978 struct lpfc_nvme_buf *lpfc_ncmd,
979 struct lpfc_nodelist *pnode)
980{
981 struct lpfc_hba *phba = vport->phba;
982 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
983 struct lpfc_iocbq *pwqeq = &(lpfc_ncmd->cur_iocbq);
984 union lpfc_wqe128 *wqe = (union lpfc_wqe128 *)&pwqeq->wqe;
985 uint32_t req_len;
986
987 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
988 return -EINVAL;
989
990 /*
991 * There are three possibilities here - use scatter-gather segment, use
992 * the single mapping, or neither.
993 */
994 wqe->fcp_iwrite.initial_xfer_len = 0;
995 if (nCmd->sg_cnt) {
996 if (nCmd->io_dir == NVMEFC_FCP_WRITE) {
997 /* Word 5 */
998 if ((phba->cfg_nvme_enable_fb) &&
999 (pnode->nlp_flag & NLP_FIRSTBURST)) {
1000 req_len = lpfc_ncmd->nvmeCmd->payload_length;
1001 if (req_len < pnode->nvme_fb_size)
1002 wqe->fcp_iwrite.initial_xfer_len =
1003 req_len;
1004 else
1005 wqe->fcp_iwrite.initial_xfer_len =
1006 pnode->nvme_fb_size;
1007 }
1008
1009 /* Word 7 */
1010 bf_set(wqe_cmnd, &wqe->generic.wqe_com,
1011 CMD_FCP_IWRITE64_WQE);
1012 bf_set(wqe_pu, &wqe->generic.wqe_com,
1013 PARM_READ_CHECK);
1014
1015 /* Word 10 */
1016 bf_set(wqe_qosd, &wqe->fcp_iwrite.wqe_com, 0);
1017 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com,
1018 LPFC_WQE_IOD_WRITE);
1019 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
1020 LPFC_WQE_LENLOC_WORD4);
1021 if (phba->cfg_nvme_oas)
1022 bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
1023
1024 /* Word 11 */
1025 bf_set(wqe_cmd_type, &wqe->generic.wqe_com,
1026 NVME_WRITE_CMD);
1027
2cee7808 1028 atomic_inc(&phba->fc4NvmeOutputRequests);
01649561
JS
1029 } else {
1030 /* Word 7 */
1031 bf_set(wqe_cmnd, &wqe->generic.wqe_com,
1032 CMD_FCP_IREAD64_WQE);
1033 bf_set(wqe_pu, &wqe->generic.wqe_com,
1034 PARM_READ_CHECK);
1035
1036 /* Word 10 */
1037 bf_set(wqe_qosd, &wqe->fcp_iread.wqe_com, 0);
1038 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com,
1039 LPFC_WQE_IOD_READ);
1040 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
1041 LPFC_WQE_LENLOC_WORD4);
1042 if (phba->cfg_nvme_oas)
1043 bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
1044
1045 /* Word 11 */
1046 bf_set(wqe_cmd_type, &wqe->generic.wqe_com,
1047 NVME_READ_CMD);
1048
2cee7808 1049 atomic_inc(&phba->fc4NvmeInputRequests);
01649561
JS
1050 }
1051 } else {
1052 /* Word 4 */
1053 wqe->fcp_icmd.rsrvd4 = 0;
1054
1055 /* Word 7 */
1056 bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_FCP_ICMND64_WQE);
1057 bf_set(wqe_pu, &wqe->generic.wqe_com, 0);
1058
1059 /* Word 10 */
1060 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
1061 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
1062 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
1063 LPFC_WQE_LENLOC_NONE);
1064 if (phba->cfg_nvme_oas)
1065 bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
1066
1067 /* Word 11 */
1068 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, NVME_READ_CMD);
1069
2cee7808 1070 atomic_inc(&phba->fc4NvmeControlRequests);
01649561
JS
1071 }
1072 /*
1073 * Finish initializing those WQE fields that are independent
1074 * of the nvme_cmnd request_buffer
1075 */
1076
1077 /* Word 6 */
1078 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
1079 phba->sli4_hba.rpi_ids[pnode->nlp_rpi]);
1080 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag);
1081
1082 /* Word 7 */
1083 /* Preserve Class data in the ndlp. */
1084 bf_set(wqe_class, &wqe->generic.wqe_com,
1085 (pnode->nlp_fcp_info & 0x0f));
1086
1087 /* Word 8 */
1088 wqe->generic.wqe_com.abort_tag = pwqeq->iotag;
1089
1090 /* Word 9 */
1091 bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag);
1092
1093 /* Word 11 */
1094 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
1095
1096 pwqeq->vport = vport;
1097 return 0;
1098}
1099
1100
1101/**
1102 * lpfc_nvme_prep_io_dma - Issue an NVME-over-FCP IO
1103 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1104 * @lpfc_nvme_lport: Pointer to the driver's local port data
1105 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1106 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1107 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1108 *
1109 * Driver registers this routine as it io request handler. This
1110 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1111 * data structure to the rport indicated in @lpfc_nvme_rport.
1112 *
1113 * Return value :
1114 * 0 - Success
1115 * TODO: What are the failure codes.
1116 **/
1117static int
1118lpfc_nvme_prep_io_dma(struct lpfc_vport *vport,
1119 struct lpfc_nvme_buf *lpfc_ncmd)
1120{
1121 struct lpfc_hba *phba = vport->phba;
1122 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1123 union lpfc_wqe128 *wqe = (union lpfc_wqe128 *)&lpfc_ncmd->cur_iocbq.wqe;
1124 struct sli4_sge *sgl = lpfc_ncmd->nvme_sgl;
1125 struct scatterlist *data_sg;
1126 struct sli4_sge *first_data_sgl;
1127 dma_addr_t physaddr;
1128 uint32_t num_bde = 0;
1129 uint32_t dma_len;
1130 uint32_t dma_offset = 0;
1131 int nseg, i;
1132
1133 /* Fix up the command and response DMA stuff. */
1134 lpfc_nvme_adj_fcp_sgls(vport, lpfc_ncmd, nCmd);
1135
1136 /*
1137 * There are three possibilities here - use scatter-gather segment, use
1138 * the single mapping, or neither.
1139 */
1140 if (nCmd->sg_cnt) {
1141 /*
1142 * Jump over the cmd and rsp SGEs. The fix routine
1143 * has already adjusted for this.
1144 */
1145 sgl += 2;
1146
1147 first_data_sgl = sgl;
1148 lpfc_ncmd->seg_cnt = nCmd->sg_cnt;
4d4c4a4a 1149 if (lpfc_ncmd->seg_cnt > phba->cfg_nvme_seg_cnt) {
01649561
JS
1150 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1151 "6058 Too many sg segments from "
1152 "NVME Transport. Max %d, "
1153 "nvmeIO sg_cnt %d\n",
4d4c4a4a 1154 phba->cfg_nvme_seg_cnt,
01649561
JS
1155 lpfc_ncmd->seg_cnt);
1156 lpfc_ncmd->seg_cnt = 0;
1157 return 1;
1158 }
1159
1160 /*
1161 * The driver established a maximum scatter-gather segment count
1162 * during probe that limits the number of sg elements in any
1163 * single nvme command. Just run through the seg_cnt and format
1164 * the sge's.
1165 */
1166 nseg = nCmd->sg_cnt;
1167 data_sg = nCmd->first_sgl;
1168 for (i = 0; i < nseg; i++) {
1169 if (data_sg == NULL) {
1170 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1171 "6059 dptr err %d, nseg %d\n",
1172 i, nseg);
1173 lpfc_ncmd->seg_cnt = 0;
1174 return 1;
1175 }
1176 physaddr = data_sg->dma_address;
1177 dma_len = data_sg->length;
1178 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
1179 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
1180 sgl->word2 = le32_to_cpu(sgl->word2);
1181 if ((num_bde + 1) == nseg)
1182 bf_set(lpfc_sli4_sge_last, sgl, 1);
1183 else
1184 bf_set(lpfc_sli4_sge_last, sgl, 0);
1185 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
1186 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
1187 sgl->word2 = cpu_to_le32(sgl->word2);
1188 sgl->sge_len = cpu_to_le32(dma_len);
1189
1190 dma_offset += dma_len;
1191 data_sg = sg_next(data_sg);
1192 sgl++;
1193 }
1194 } else {
1195 /* For this clause to be valid, the payload_length
1196 * and sg_cnt must zero.
1197 */
1198 if (nCmd->payload_length != 0) {
1199 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1200 "6063 NVME DMA Prep Err: sg_cnt %d "
1201 "payload_length x%x\n",
1202 nCmd->sg_cnt, nCmd->payload_length);
1203 return 1;
1204 }
1205 }
1206
1207 /*
1208 * Due to difference in data length between DIF/non-DIF paths,
1209 * we need to set word 4 of WQE here
1210 */
1211 wqe->fcp_iread.total_xfer_len = nCmd->payload_length;
1212 return 0;
1213}
1214
1215/**
1216 * lpfc_nvme_fcp_io_submit - Issue an NVME-over-FCP IO
1217 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1218 * @lpfc_nvme_lport: Pointer to the driver's local port data
1219 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1220 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1221 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1222 *
1223 * Driver registers this routine as it io request handler. This
1224 * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq
1225 * data structure to the rport
1226 indicated in @lpfc_nvme_rport.
1227 *
1228 * Return value :
1229 * 0 - Success
1230 * TODO: What are the failure codes.
1231 **/
1232static int
1233lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
1234 struct nvme_fc_remote_port *pnvme_rport,
1235 void *hw_queue_handle,
1236 struct nvmefc_fcp_req *pnvme_fcreq)
1237{
1238 int ret = 0;
1239 struct lpfc_nvme_lport *lport;
1240 struct lpfc_vport *vport;
1241 struct lpfc_hba *phba;
1242 struct lpfc_nodelist *ndlp;
1243 struct lpfc_nvme_buf *lpfc_ncmd;
1244 struct lpfc_nvme_rport *rport;
1245 struct lpfc_nvme_qhandle *lpfc_queue_info;
bbe3012b 1246 struct lpfc_nvme_fcpreq_priv *freqpriv = pnvme_fcreq->private;
bd2cdd5e
JS
1247#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1248 uint64_t start = 0;
1249#endif
01649561
JS
1250
1251 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1252 vport = lport->vport;
1253 phba = vport->phba;
1254
b7672ae6
DK
1255 /* Validate pointers. */
1256 if (!pnvme_lport || !pnvme_rport || !freqpriv) {
1257 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR | LOG_NODE,
1258 "6117 No Send:IO submit ptrs NULL, lport %p, "
1259 "rport %p fcreq_priv %p\n",
1260 pnvme_lport, pnvme_rport, freqpriv);
1261 ret = -ENODEV;
1262 goto out_fail;
1263 }
1264
bd2cdd5e
JS
1265#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1266 if (phba->ktime_on)
1267 start = ktime_get_ns();
1268#endif
01649561
JS
1269 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
1270 lpfc_queue_info = (struct lpfc_nvme_qhandle *)hw_queue_handle;
1271
1272 /*
1273 * Catch race where our node has transitioned, but the
1274 * transport is still transitioning.
1275 */
1276 ndlp = rport->ndlp;
1277 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1278 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
1279 "6053 rport %p, ndlp %p, DID x%06x "
1280 "ndlp not ready.\n",
1281 rport, ndlp, pnvme_rport->port_id);
1282
1283 ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id);
1284 if (!ndlp) {
1285 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1286 "6066 Missing node for DID %x\n",
1287 pnvme_rport->port_id);
1288 ret = -ENODEV;
1289 goto out_fail;
1290 }
1291 }
1292
1293 /* The remote node has to be a mapped target or it's an error. */
1294 if ((ndlp->nlp_type & NLP_NVME_TARGET) &&
1295 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
1296 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
1297 "6036 rport %p, DID x%06x not ready for "
1298 "IO. State x%x, Type x%x\n",
1299 rport, pnvme_rport->port_id,
1300 ndlp->nlp_state, ndlp->nlp_type);
1301 ret = -ENODEV;
1302 goto out_fail;
1303
1304 }
1305
1306 /* The node is shared with FCP IO, make sure the IO pending count does
1307 * not exceed the programmed depth.
1308 */
1309 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) {
cd22d605 1310 ret = -EBUSY;
01649561
JS
1311 goto out_fail;
1312 }
1313
1314 lpfc_ncmd = lpfc_get_nvme_buf(phba, ndlp);
1315 if (lpfc_ncmd == NULL) {
1316 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1317 "6065 driver's buffer pool is empty, "
1318 "IO failed\n");
cd22d605 1319 ret = -EBUSY;
01649561
JS
1320 goto out_fail;
1321 }
bd2cdd5e 1322#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
c8a4ce0b 1323 if (start) {
bd2cdd5e
JS
1324 lpfc_ncmd->ts_cmd_start = start;
1325 lpfc_ncmd->ts_last_cmd = phba->ktime_last_cmd;
c8a4ce0b
DK
1326 } else {
1327 lpfc_ncmd->ts_cmd_start = 0;
bd2cdd5e
JS
1328 }
1329#endif
01649561
JS
1330
1331 /*
1332 * Store the data needed by the driver to issue, abort, and complete
1333 * an IO.
1334 * Do not let the IO hang out forever. There is no midlayer issuing
1335 * an abort so inform the FW of the maximum IO pending time.
1336 */
bbe3012b 1337 freqpriv->nvme_buf = lpfc_ncmd;
01649561
JS
1338 lpfc_ncmd->nvmeCmd = pnvme_fcreq;
1339 lpfc_ncmd->nrport = rport;
318083ad 1340 lpfc_ncmd->ndlp = ndlp;
01649561
JS
1341 lpfc_ncmd->start_time = jiffies;
1342
1343 lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp);
1344 ret = lpfc_nvme_prep_io_dma(vport, lpfc_ncmd);
1345 if (ret) {
1346 ret = -ENOMEM;
1347 goto out_free_nvme_buf;
1348 }
1349
1350 atomic_inc(&ndlp->cmd_pending);
1351
1352 /*
1353 * Issue the IO on the WQ indicated by index in the hw_queue_handle.
1354 * This identfier was create in our hardware queue create callback
1355 * routine. The driver now is dependent on the IO queue steering from
1356 * the transport. We are trusting the upper NVME layers know which
1357 * index to use and that they have affinitized a CPU to this hardware
1358 * queue. A hardware queue maps to a driver MSI-X vector/EQ/CQ/WQ.
1359 */
1360 lpfc_ncmd->cur_iocbq.hba_wqidx = lpfc_queue_info->index;
1361
bd2cdd5e
JS
1362 lpfc_nvmeio_data(phba, "NVME FCP XMIT: xri x%x idx %d to %06x\n",
1363 lpfc_ncmd->cur_iocbq.sli4_xritag,
1364 lpfc_queue_info->index, ndlp->nlp_DID);
1365
01649561
JS
1366 ret = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, &lpfc_ncmd->cur_iocbq);
1367 if (ret) {
1368 atomic_dec(&ndlp->cmd_pending);
e3246a12 1369 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
01649561
JS
1370 "6113 FCP could not issue WQE err %x "
1371 "sid: x%x did: x%x oxid: x%x\n",
1372 ret, vport->fc_myDID, ndlp->nlp_DID,
1373 lpfc_ncmd->cur_iocbq.sli4_xritag);
01649561
JS
1374 goto out_free_nvme_buf;
1375 }
1376
bd2cdd5e 1377#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
c8a4ce0b 1378 if (lpfc_ncmd->ts_cmd_start)
bd2cdd5e
JS
1379 lpfc_ncmd->ts_cmd_wqput = ktime_get_ns();
1380
1381 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) {
1382 lpfc_ncmd->cpu = smp_processor_id();
1383 if (lpfc_ncmd->cpu != lpfc_queue_info->index) {
1384 /* Check for admin queue */
1385 if (lpfc_queue_info->qidx) {
1386 lpfc_printf_vlog(vport,
1387 KERN_ERR, LOG_NVME_IOERR,
1388 "6702 CPU Check cmd: "
1389 "cpu %d wq %d\n",
1390 lpfc_ncmd->cpu,
1391 lpfc_queue_info->index);
1392 }
1393 lpfc_ncmd->cpu = lpfc_queue_info->index;
1394 }
1395 if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT)
1396 phba->cpucheck_xmt_io[lpfc_ncmd->cpu]++;
1397 }
1398#endif
01649561
JS
1399 return 0;
1400
1401 out_free_nvme_buf:
2cee7808
JS
1402 if (lpfc_ncmd->nvmeCmd->sg_cnt) {
1403 if (lpfc_ncmd->nvmeCmd->io_dir == NVMEFC_FCP_WRITE)
1404 atomic_dec(&phba->fc4NvmeOutputRequests);
1405 else
1406 atomic_dec(&phba->fc4NvmeInputRequests);
1407 } else
1408 atomic_dec(&phba->fc4NvmeControlRequests);
01649561
JS
1409 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1410 out_fail:
1411 return ret;
1412}
1413
1414/**
1415 * lpfc_nvme_abort_fcreq_cmpl - Complete an NVME FCP abort request.
1416 * @phba: Pointer to HBA context object
1417 * @cmdiocb: Pointer to command iocb object.
1418 * @rspiocb: Pointer to response iocb object.
1419 *
1420 * This is the callback function for any NVME FCP IO that was aborted.
1421 *
1422 * Return value:
1423 * None
1424 **/
1425void
1426lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1427 struct lpfc_wcqe_complete *abts_cmpl)
1428{
e3246a12 1429 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
01649561
JS
1430 "6145 ABORT_XRI_CN completing on rpi x%x "
1431 "original iotag x%x, abort cmd iotag x%x "
1432 "req_tag x%x, status x%x, hwstatus x%x\n",
1433 cmdiocb->iocb.un.acxri.abortContextTag,
1434 cmdiocb->iocb.un.acxri.abortIoTag,
1435 cmdiocb->iotag,
1436 bf_get(lpfc_wcqe_c_request_tag, abts_cmpl),
1437 bf_get(lpfc_wcqe_c_status, abts_cmpl),
1438 bf_get(lpfc_wcqe_c_hw_status, abts_cmpl));
1439 lpfc_sli_release_iocbq(phba, cmdiocb);
1440}
1441
1442/**
1443 * lpfc_nvme_fcp_abort - Issue an NVME-over-FCP ABTS
1444 * @lpfc_pnvme: Pointer to the driver's nvme instance data
1445 * @lpfc_nvme_lport: Pointer to the driver's local port data
1446 * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq
1447 * @lpfc_nvme_fcreq: IO request from nvme fc to driver.
1448 * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue
1449 *
1450 * Driver registers this routine as its nvme request io abort handler. This
1451 * routine issues an fcp Abort WQE with data from the @lpfc_nvme_fcpreq
1452 * data structure to the rport indicated in @lpfc_nvme_rport. This routine
1453 * is executed asynchronously - one the target is validated as "MAPPED" and
1454 * ready for IO, the driver issues the abort request and returns.
1455 *
1456 * Return value:
1457 * None
1458 **/
1459static void
1460lpfc_nvme_fcp_abort(struct nvme_fc_local_port *pnvme_lport,
1461 struct nvme_fc_remote_port *pnvme_rport,
1462 void *hw_queue_handle,
1463 struct nvmefc_fcp_req *pnvme_fcreq)
1464{
1465 struct lpfc_nvme_lport *lport;
1466 struct lpfc_vport *vport;
1467 struct lpfc_hba *phba;
01649561
JS
1468 struct lpfc_nvme_rport *rport;
1469 struct lpfc_nvme_buf *lpfc_nbuf;
1470 struct lpfc_iocbq *abts_buf;
1471 struct lpfc_iocbq *nvmereq_wqe;
bbe3012b 1472 struct lpfc_nvme_fcpreq_priv *freqpriv = pnvme_fcreq->private;
01649561
JS
1473 union lpfc_wqe *abts_wqe;
1474 unsigned long flags;
1475 int ret_val;
1476
1477 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1478 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
1479 vport = lport->vport;
1480 phba = vport->phba;
1481
1482 /* Announce entry to new IO submit field. */
86c67379 1483 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
01649561
JS
1484 "6002 Abort Request to rport DID x%06x "
1485 "for nvme_fc_req %p\n",
1486 pnvme_rport->port_id,
1487 pnvme_fcreq);
1488
01649561
JS
1489 /* If the hba is getting reset, this flag is set. It is
1490 * cleared when the reset is complete and rings reestablished.
1491 */
1492 spin_lock_irqsave(&phba->hbalock, flags);
1493 /* driver queued commands are in process of being flushed */
1494 if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) {
1495 spin_unlock_irqrestore(&phba->hbalock, flags);
86c67379 1496 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
01649561
JS
1497 "6139 Driver in reset cleanup - flushing "
1498 "NVME Req now. hba_flag x%x\n",
1499 phba->hba_flag);
1500 return;
1501 }
1502
bbe3012b 1503 lpfc_nbuf = freqpriv->nvme_buf;
01649561
JS
1504 if (!lpfc_nbuf) {
1505 spin_unlock_irqrestore(&phba->hbalock, flags);
86c67379 1506 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
01649561
JS
1507 "6140 NVME IO req has no matching lpfc nvme "
1508 "io buffer. Skipping abort req.\n");
1509 return;
1510 } else if (!lpfc_nbuf->nvmeCmd) {
1511 spin_unlock_irqrestore(&phba->hbalock, flags);
86c67379 1512 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
01649561
JS
1513 "6141 lpfc NVME IO req has no nvme_fcreq "
1514 "io buffer. Skipping abort req.\n");
1515 return;
1516 }
2b7824d0 1517 nvmereq_wqe = &lpfc_nbuf->cur_iocbq;
01649561
JS
1518
1519 /*
1520 * The lpfc_nbuf and the mapped nvme_fcreq in the driver's
1521 * state must match the nvme_fcreq passed by the nvme
1522 * transport. If they don't match, it is likely the driver
1523 * has already completed the NVME IO and the nvme transport
1524 * has not seen it yet.
1525 */
1526 if (lpfc_nbuf->nvmeCmd != pnvme_fcreq) {
1527 spin_unlock_irqrestore(&phba->hbalock, flags);
86c67379 1528 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
01649561
JS
1529 "6143 NVME req mismatch: "
1530 "lpfc_nbuf %p nvmeCmd %p, "
2b7824d0 1531 "pnvme_fcreq %p. Skipping Abort xri x%x\n",
01649561 1532 lpfc_nbuf, lpfc_nbuf->nvmeCmd,
2b7824d0 1533 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
01649561
JS
1534 return;
1535 }
1536
1537 /* Don't abort IOs no longer on the pending queue. */
01649561
JS
1538 if (!(nvmereq_wqe->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
1539 spin_unlock_irqrestore(&phba->hbalock, flags);
86c67379 1540 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
01649561 1541 "6142 NVME IO req %p not queued - skipping "
2b7824d0
JS
1542 "abort req xri x%x\n",
1543 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
01649561
JS
1544 return;
1545 }
1546
bd2cdd5e
JS
1547 lpfc_nvmeio_data(phba, "NVME FCP ABORT: xri x%x idx %d to %06x\n",
1548 nvmereq_wqe->sli4_xritag,
00cefeb9 1549 nvmereq_wqe->hba_wqidx, pnvme_rport->port_id);
bd2cdd5e 1550
01649561
JS
1551 /* Outstanding abort is in progress */
1552 if (nvmereq_wqe->iocb_flag & LPFC_DRIVER_ABORTED) {
1553 spin_unlock_irqrestore(&phba->hbalock, flags);
86c67379 1554 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
01649561
JS
1555 "6144 Outstanding NVME I/O Abort Request "
1556 "still pending on nvme_fcreq %p, "
2b7824d0
JS
1557 "lpfc_ncmd %p xri x%x\n",
1558 pnvme_fcreq, lpfc_nbuf,
1559 nvmereq_wqe->sli4_xritag);
01649561
JS
1560 return;
1561 }
1562
1563 abts_buf = __lpfc_sli_get_iocbq(phba);
1564 if (!abts_buf) {
1565 spin_unlock_irqrestore(&phba->hbalock, flags);
86c67379 1566 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
01649561 1567 "6136 No available abort wqes. Skipping "
2b7824d0
JS
1568 "Abts req for nvme_fcreq %p xri x%x\n",
1569 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
01649561
JS
1570 return;
1571 }
1572
1573 /* Ready - mark outstanding as aborted by driver. */
1574 nvmereq_wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
1575
1576 /* Complete prepping the abort wqe and issue to the FW. */
1577 abts_wqe = &abts_buf->wqe;
1578
1579 /* WQEs are reused. Clear stale data and set key fields to
1580 * zero like ia, iaab, iaar, xri_tag, and ctxt_tag.
1581 */
1582 memset(abts_wqe, 0, sizeof(union lpfc_wqe));
1583 bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG);
1584
1585 /* word 7 */
1586 bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0);
1587 bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
1588 bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com,
1589 nvmereq_wqe->iocb.ulpClass);
1590
1591 /* word 8 - tell the FW to abort the IO associated with this
1592 * outstanding exchange ID.
1593 */
1594 abts_wqe->abort_cmd.wqe_com.abort_tag = nvmereq_wqe->sli4_xritag;
1595
1596 /* word 9 - this is the iotag for the abts_wqe completion. */
1597 bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com,
1598 abts_buf->iotag);
1599
1600 /* word 10 */
1601 bf_set(wqe_wqid, &abts_wqe->abort_cmd.wqe_com, nvmereq_wqe->hba_wqidx);
1602 bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1);
1603 bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
1604
1605 /* word 11 */
1606 bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND);
1607 bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1);
1608 bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
1609
1610 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
1611 abts_buf->iocb_flag |= LPFC_IO_NVME;
1612 abts_buf->hba_wqidx = nvmereq_wqe->hba_wqidx;
1613 abts_buf->vport = vport;
1614 abts_buf->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl;
1615 ret_val = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_buf);
1616 spin_unlock_irqrestore(&phba->hbalock, flags);
cd22d605 1617 if (ret_val) {
86c67379 1618 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
01649561
JS
1619 "6137 Failed abts issue_wqe with status x%x "
1620 "for nvme_fcreq %p.\n",
1621 ret_val, pnvme_fcreq);
1622 lpfc_sli_release_iocbq(phba, abts_buf);
1623 return;
1624 }
1625
86c67379 1626 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
2b7824d0 1627 "6138 Transport Abort NVME Request Issued for "
01649561
JS
1628 "ox_id x%x on reqtag x%x\n",
1629 nvmereq_wqe->sli4_xritag,
1630 abts_buf->iotag);
1631}
1632
1633/* Declare and initialization an instance of the FC NVME template. */
1634static struct nvme_fc_port_template lpfc_nvme_template = {
1635 /* initiator-based functions */
1636 .localport_delete = lpfc_nvme_localport_delete,
1637 .remoteport_delete = lpfc_nvme_remoteport_delete,
1638 .create_queue = lpfc_nvme_create_queue,
1639 .delete_queue = lpfc_nvme_delete_queue,
1640 .ls_req = lpfc_nvme_ls_req,
1641 .fcp_io = lpfc_nvme_fcp_io_submit,
1642 .ls_abort = lpfc_nvme_ls_abort,
1643 .fcp_abort = lpfc_nvme_fcp_abort,
1644
1645 .max_hw_queues = 1,
1646 .max_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1647 .max_dif_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1648 .dma_boundary = 0xFFFFFFFF,
1649
1650 /* Sizes of additional private data for data structures.
1651 * No use for the last two sizes at this time.
1652 */
1653 .local_priv_sz = sizeof(struct lpfc_nvme_lport),
1654 .remote_priv_sz = sizeof(struct lpfc_nvme_rport),
1655 .lsrqst_priv_sz = 0,
bbe3012b 1656 .fcprqst_priv_sz = sizeof(struct lpfc_nvme_fcpreq_priv),
01649561
JS
1657};
1658
1659/**
1660 * lpfc_sli4_post_nvme_sgl_block - post a block of nvme sgl list to firmware
1661 * @phba: pointer to lpfc hba data structure.
1662 * @nblist: pointer to nvme buffer list.
1663 * @count: number of scsi buffers on the list.
1664 *
1665 * This routine is invoked to post a block of @count scsi sgl pages from a
1666 * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
1667 * No Lock is held.
1668 *
1669 **/
1670static int
1671lpfc_sli4_post_nvme_sgl_block(struct lpfc_hba *phba,
1672 struct list_head *nblist,
1673 int count)
1674{
1675 struct lpfc_nvme_buf *lpfc_ncmd;
1676 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
1677 struct sgl_page_pairs *sgl_pg_pairs;
1678 void *viraddr;
1679 LPFC_MBOXQ_t *mbox;
1680 uint32_t reqlen, alloclen, pg_pairs;
1681 uint32_t mbox_tmo;
1682 uint16_t xritag_start = 0;
1683 int rc = 0;
1684 uint32_t shdr_status, shdr_add_status;
1685 dma_addr_t pdma_phys_bpl1;
1686 union lpfc_sli4_cfg_shdr *shdr;
1687
1688 /* Calculate the requested length of the dma memory */
1689 reqlen = count * sizeof(struct sgl_page_pairs) +
1690 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
1691 if (reqlen > SLI4_PAGE_SIZE) {
1692 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1693 "6118 Block sgl registration required DMA "
1694 "size (%d) great than a page\n", reqlen);
1695 return -ENOMEM;
1696 }
1697 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1698 if (!mbox) {
1699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1700 "6119 Failed to allocate mbox cmd memory\n");
1701 return -ENOMEM;
1702 }
1703
1704 /* Allocate DMA memory and set up the non-embedded mailbox command */
1705 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1706 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
1707 LPFC_SLI4_MBX_NEMBED);
1708
1709 if (alloclen < reqlen) {
1710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1711 "6120 Allocated DMA memory size (%d) is "
1712 "less than the requested DMA memory "
1713 "size (%d)\n", alloclen, reqlen);
1714 lpfc_sli4_mbox_cmd_free(phba, mbox);
1715 return -ENOMEM;
1716 }
1717
1718 /* Get the first SGE entry from the non-embedded DMA memory */
1719 viraddr = mbox->sge_array->addr[0];
1720
1721 /* Set up the SGL pages in the non-embedded DMA pages */
1722 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
1723 sgl_pg_pairs = &sgl->sgl_pg_pairs;
1724
1725 pg_pairs = 0;
1726 list_for_each_entry(lpfc_ncmd, nblist, list) {
1727 /* Set up the sge entry */
1728 sgl_pg_pairs->sgl_pg0_addr_lo =
1729 cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
1730 sgl_pg_pairs->sgl_pg0_addr_hi =
1731 cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
1732 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
1733 pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
1734 SGL_PAGE_SIZE;
1735 else
1736 pdma_phys_bpl1 = 0;
1737 sgl_pg_pairs->sgl_pg1_addr_lo =
1738 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
1739 sgl_pg_pairs->sgl_pg1_addr_hi =
1740 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
1741 /* Keep the first xritag on the list */
1742 if (pg_pairs == 0)
1743 xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
1744 sgl_pg_pairs++;
1745 pg_pairs++;
1746 }
1747 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
1748 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
1749 /* Perform endian conversion if necessary */
1750 sgl->word0 = cpu_to_le32(sgl->word0);
1751
1752 if (!phba->sli4_hba.intr_enable)
1753 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1754 else {
1755 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
1756 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
1757 }
1758 shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
1759 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1760 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
1761 if (rc != MBX_TIMEOUT)
1762 lpfc_sli4_mbox_cmd_free(phba, mbox);
1763 if (shdr_status || shdr_add_status || rc) {
1764 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1765 "6125 POST_SGL_BLOCK mailbox command failed "
1766 "status x%x add_status x%x mbx status x%x\n",
1767 shdr_status, shdr_add_status, rc);
1768 rc = -ENXIO;
1769 }
1770 return rc;
1771}
1772
1773/**
1774 * lpfc_post_nvme_sgl_list - Post blocks of nvme buffer sgls from a list
1775 * @phba: pointer to lpfc hba data structure.
1776 * @post_nblist: pointer to the nvme buffer list.
1777 *
1778 * This routine walks a list of nvme buffers that was passed in. It attempts
1779 * to construct blocks of nvme buffer sgls which contains contiguous xris and
1780 * uses the non-embedded SGL block post mailbox commands to post to the port.
1781 * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
1782 * embedded SGL post mailbox command for posting. The @post_nblist passed in
1783 * must be local list, thus no lock is needed when manipulate the list.
1784 *
1785 * Returns: 0 = failure, non-zero number of successfully posted buffers.
1786 **/
1787static int
1788lpfc_post_nvme_sgl_list(struct lpfc_hba *phba,
1789 struct list_head *post_nblist, int sb_count)
1790{
1791 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
1792 int status, sgl_size;
1793 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
1794 dma_addr_t pdma_phys_sgl1;
1795 int last_xritag = NO_XRI;
1796 int cur_xritag;
1797 LIST_HEAD(prep_nblist);
1798 LIST_HEAD(blck_nblist);
1799 LIST_HEAD(nvme_nblist);
1800
1801 /* sanity check */
1802 if (sb_count <= 0)
1803 return -EINVAL;
1804
1805 sgl_size = phba->cfg_sg_dma_buf_size;
1806
1807 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
1808 list_del_init(&lpfc_ncmd->list);
1809 block_cnt++;
1810 if ((last_xritag != NO_XRI) &&
1811 (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
1812 /* a hole in xri block, form a sgl posting block */
1813 list_splice_init(&prep_nblist, &blck_nblist);
1814 post_cnt = block_cnt - 1;
1815 /* prepare list for next posting block */
1816 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
1817 block_cnt = 1;
1818 } else {
1819 /* prepare list for next posting block */
1820 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
1821 /* enough sgls for non-embed sgl mbox command */
1822 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
1823 list_splice_init(&prep_nblist, &blck_nblist);
1824 post_cnt = block_cnt;
1825 block_cnt = 0;
1826 }
1827 }
1828 num_posting++;
1829 last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
1830
1831 /* end of repost sgl list condition for NVME buffers */
1832 if (num_posting == sb_count) {
1833 if (post_cnt == 0) {
1834 /* last sgl posting block */
1835 list_splice_init(&prep_nblist, &blck_nblist);
1836 post_cnt = block_cnt;
1837 } else if (block_cnt == 1) {
1838 /* last single sgl with non-contiguous xri */
1839 if (sgl_size > SGL_PAGE_SIZE)
1840 pdma_phys_sgl1 =
1841 lpfc_ncmd->dma_phys_sgl +
1842 SGL_PAGE_SIZE;
1843 else
1844 pdma_phys_sgl1 = 0;
1845 cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
1846 status = lpfc_sli4_post_sgl(phba,
1847 lpfc_ncmd->dma_phys_sgl,
1848 pdma_phys_sgl1, cur_xritag);
1849 if (status) {
1850 /* failure, put on abort nvme list */
318083ad 1851 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
01649561
JS
1852 } else {
1853 /* success, put on NVME buffer list */
318083ad 1854 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
01649561
JS
1855 lpfc_ncmd->status = IOSTAT_SUCCESS;
1856 num_posted++;
1857 }
1858 /* success, put on NVME buffer sgl list */
1859 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
1860 }
1861 }
1862
1863 /* continue until a nembed page worth of sgls */
1864 if (post_cnt == 0)
1865 continue;
1866
1867 /* post block of NVME buffer list sgls */
1868 status = lpfc_sli4_post_nvme_sgl_block(phba, &blck_nblist,
1869 post_cnt);
1870
1871 /* don't reset xirtag due to hole in xri block */
1872 if (block_cnt == 0)
1873 last_xritag = NO_XRI;
1874
1875 /* reset NVME buffer post count for next round of posting */
1876 post_cnt = 0;
1877
1878 /* put posted NVME buffer-sgl posted on NVME buffer sgl list */
1879 while (!list_empty(&blck_nblist)) {
1880 list_remove_head(&blck_nblist, lpfc_ncmd,
1881 struct lpfc_nvme_buf, list);
1882 if (status) {
1883 /* failure, put on abort nvme list */
318083ad 1884 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
01649561
JS
1885 } else {
1886 /* success, put on NVME buffer list */
318083ad 1887 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
01649561
JS
1888 lpfc_ncmd->status = IOSTAT_SUCCESS;
1889 num_posted++;
1890 }
1891 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
1892 }
1893 }
1894 /* Push NVME buffers with sgl posted to the available list */
1895 while (!list_empty(&nvme_nblist)) {
1896 list_remove_head(&nvme_nblist, lpfc_ncmd,
1897 struct lpfc_nvme_buf, list);
1898 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1899 }
1900 return num_posted;
1901}
1902
1903/**
1904 * lpfc_repost_nvme_sgl_list - Repost all the allocated nvme buffer sgls
1905 * @phba: pointer to lpfc hba data structure.
1906 *
1907 * This routine walks the list of nvme buffers that have been allocated and
1908 * repost them to the port by using SGL block post. This is needed after a
1909 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
1910 * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
1911 * to the lpfc_nvme_buf_list. If the repost fails, reject all nvme buffers.
1912 *
1913 * Returns: 0 = success, non-zero failure.
1914 **/
1915int
1916lpfc_repost_nvme_sgl_list(struct lpfc_hba *phba)
1917{
1918 LIST_HEAD(post_nblist);
1919 int num_posted, rc = 0;
1920
1921 /* get all NVME buffers need to repost to a local list */
1922 spin_lock_irq(&phba->nvme_buf_list_get_lock);
1923 spin_lock(&phba->nvme_buf_list_put_lock);
1924 list_splice_init(&phba->lpfc_nvme_buf_list_get, &post_nblist);
1925 list_splice(&phba->lpfc_nvme_buf_list_put, &post_nblist);
1926 spin_unlock(&phba->nvme_buf_list_put_lock);
1927 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
1928
1929 /* post the list of nvme buffer sgls to port if available */
1930 if (!list_empty(&post_nblist)) {
1931 num_posted = lpfc_post_nvme_sgl_list(phba, &post_nblist,
1932 phba->sli4_hba.nvme_xri_cnt);
1933 /* failed to post any nvme buffer, return error */
1934 if (num_posted == 0)
1935 rc = -EIO;
1936 }
1937 return rc;
1938}
1939
1940/**
1941 * lpfc_new_nvme_buf - Scsi buffer allocator for HBA with SLI4 IF spec
1942 * @vport: The virtual port for which this call being executed.
1943 * @num_to_allocate: The requested number of buffers to allocate.
1944 *
1945 * This routine allocates nvme buffers for device with SLI-4 interface spec,
1946 * the nvme buffer contains all the necessary information needed to initiate
1947 * a NVME I/O. After allocating up to @num_to_allocate NVME buffers and put
1948 * them on a list, it post them to the port by using SGL block post.
1949 *
1950 * Return codes:
1951 * int - number of nvme buffers that were allocated and posted.
1952 * 0 = failure, less than num_to_alloc is a partial failure.
1953 **/
1954static int
1955lpfc_new_nvme_buf(struct lpfc_vport *vport, int num_to_alloc)
1956{
1957 struct lpfc_hba *phba = vport->phba;
1958 struct lpfc_nvme_buf *lpfc_ncmd;
1959 struct lpfc_iocbq *pwqeq;
1960 union lpfc_wqe128 *wqe;
1961 struct sli4_sge *sgl;
1962 dma_addr_t pdma_phys_sgl;
1963 uint16_t iotag, lxri = 0;
1964 int bcnt, num_posted, sgl_size;
1965 LIST_HEAD(prep_nblist);
1966 LIST_HEAD(post_nblist);
1967 LIST_HEAD(nvme_nblist);
1968
1969 sgl_size = phba->cfg_sg_dma_buf_size;
1970
1971 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
1972 lpfc_ncmd = kzalloc(sizeof(struct lpfc_nvme_buf), GFP_KERNEL);
1973 if (!lpfc_ncmd)
1974 break;
1975 /*
1976 * Get memory from the pci pool to map the virt space to
1977 * pci bus space for an I/O. The DMA buffer includes the
1978 * number of SGE's necessary to support the sg_tablesize.
1979 */
df2f7729
TM
1980 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
1981 GFP_KERNEL,
1982 &lpfc_ncmd->dma_handle);
01649561
JS
1983 if (!lpfc_ncmd->data) {
1984 kfree(lpfc_ncmd);
1985 break;
1986 }
01649561
JS
1987
1988 lxri = lpfc_sli4_next_xritag(phba);
1989 if (lxri == NO_XRI) {
771db5c0 1990 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
01649561
JS
1991 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
1992 kfree(lpfc_ncmd);
1993 break;
1994 }
1995 pwqeq = &(lpfc_ncmd->cur_iocbq);
1996 wqe = (union lpfc_wqe128 *)&pwqeq->wqe;
1997
1998 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
1999 iotag = lpfc_sli_next_iotag(phba, pwqeq);
2000 if (iotag == 0) {
771db5c0 2001 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
01649561
JS
2002 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
2003 kfree(lpfc_ncmd);
2004 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
2005 "6121 Failed to allocated IOTAG for"
2006 " XRI:0x%x\n", lxri);
2007 lpfc_sli4_free_xri(phba, lxri);
2008 break;
2009 }
2010 pwqeq->sli4_lxritag = lxri;
2011 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
2012 pwqeq->iocb_flag |= LPFC_IO_NVME;
2013 pwqeq->context1 = lpfc_ncmd;
2014 pwqeq->wqe_cmpl = lpfc_nvme_io_cmd_wqe_cmpl;
2015
2016 /* Initialize local short-hand pointers. */
2017 lpfc_ncmd->nvme_sgl = lpfc_ncmd->data;
2018 sgl = lpfc_ncmd->nvme_sgl;
2019 pdma_phys_sgl = lpfc_ncmd->dma_handle;
2020 lpfc_ncmd->dma_phys_sgl = pdma_phys_sgl;
2021
2022 /* Rsp SGE will be filled in when we rcv an IO
2023 * from the NVME Layer to be sent.
2024 * The cmd is going to be embedded so we need a SKIP SGE.
2025 */
2026 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP);
2027 bf_set(lpfc_sli4_sge_last, sgl, 0);
2028 sgl->word2 = cpu_to_le32(sgl->word2);
2029 /* Fill in word 3 / sgl_len during cmd submission */
2030
2031 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
2032
2033 /* Word 7 */
2034 bf_set(wqe_erp, &wqe->generic.wqe_com, 0);
2035 /* NVME upper layers will time things out, if needed */
2036 bf_set(wqe_tmo, &wqe->generic.wqe_com, 0);
2037
2038 /* Word 10 */
2039 bf_set(wqe_ebde_cnt, &wqe->generic.wqe_com, 0);
2040 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
2041
2042 /* add the nvme buffer to a post list */
2043 list_add_tail(&lpfc_ncmd->list, &post_nblist);
2044 spin_lock_irq(&phba->nvme_buf_list_get_lock);
2045 phba->sli4_hba.nvme_xri_cnt++;
2046 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
2047 }
2048 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
2049 "6114 Allocate %d out of %d requested new NVME "
2050 "buffers\n", bcnt, num_to_alloc);
2051
2052 /* post the list of nvme buffer sgls to port if available */
2053 if (!list_empty(&post_nblist))
2054 num_posted = lpfc_post_nvme_sgl_list(phba,
2055 &post_nblist, bcnt);
2056 else
2057 num_posted = 0;
2058
2059 return num_posted;
2060}
2061
2062/**
2063 * lpfc_get_nvme_buf - Get a nvme buffer from lpfc_nvme_buf_list of the HBA
2064 * @phba: The HBA for which this call is being executed.
2065 *
2066 * This routine removes a nvme buffer from head of @phba lpfc_nvme_buf_list list
2067 * and returns to caller.
2068 *
2069 * Return codes:
2070 * NULL - Error
2071 * Pointer to lpfc_nvme_buf - Success
2072 **/
2073static struct lpfc_nvme_buf *
2074lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
2075{
2076 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
2077 unsigned long iflag = 0;
2078 int found = 0;
2079
2080 spin_lock_irqsave(&phba->nvme_buf_list_get_lock, iflag);
2081 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
2082 &phba->lpfc_nvme_buf_list_get, list) {
bbe3012b 2083 list_del_init(&lpfc_ncmd->list);
01649561
JS
2084 found = 1;
2085 break;
2086 }
2087 if (!found) {
2088 spin_lock(&phba->nvme_buf_list_put_lock);
2089 list_splice(&phba->lpfc_nvme_buf_list_put,
2090 &phba->lpfc_nvme_buf_list_get);
2091 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
2092 spin_unlock(&phba->nvme_buf_list_put_lock);
2093 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
2094 &phba->lpfc_nvme_buf_list_get, list) {
bbe3012b 2095 list_del_init(&lpfc_ncmd->list);
01649561
JS
2096 found = 1;
2097 break;
2098 }
2099 }
2100 spin_unlock_irqrestore(&phba->nvme_buf_list_get_lock, iflag);
2101 if (!found)
2102 return NULL;
2103 return lpfc_ncmd;
2104}
2105
2106/**
2107 * lpfc_release_nvme_buf: Return a nvme buffer back to hba nvme buf list.
2108 * @phba: The Hba for which this call is being executed.
2109 * @lpfc_ncmd: The nvme buffer which is being released.
2110 *
2111 * This routine releases @lpfc_ncmd nvme buffer by adding it to tail of @phba
2112 * lpfc_nvme_buf_list list. For SLI4 XRI's are tied to the nvme buffer
2113 * and cannot be reused for at least RA_TOV amount of time if it was
2114 * aborted.
2115 **/
2116static void
2117lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_nvme_buf *lpfc_ncmd)
2118{
2119 unsigned long iflag = 0;
2120
2121 lpfc_ncmd->nonsg_phys = 0;
318083ad 2122 if (lpfc_ncmd->flags & LPFC_SBUF_XBUSY) {
86c67379
JS
2123 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2124 "6310 XB release deferred for "
2125 "ox_id x%x on reqtag x%x\n",
2126 lpfc_ncmd->cur_iocbq.sli4_xritag,
2127 lpfc_ncmd->cur_iocbq.iotag);
2128
01649561
JS
2129 spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock,
2130 iflag);
01649561
JS
2131 list_add_tail(&lpfc_ncmd->list,
2132 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
2133 spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock,
2134 iflag);
2135 } else {
2136 lpfc_ncmd->nvmeCmd = NULL;
2137 lpfc_ncmd->cur_iocbq.iocb_flag = LPFC_IO_NVME;
2138 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
2139 list_add_tail(&lpfc_ncmd->list, &phba->lpfc_nvme_buf_list_put);
2140 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
2141 }
2142}
2143
2144/**
2145 * lpfc_nvme_create_localport - Create/Bind an nvme localport instance.
2146 * @pvport - the lpfc_vport instance requesting a localport.
2147 *
2148 * This routine is invoked to create an nvme localport instance to bind
2149 * to the nvme_fc_transport. It is called once during driver load
2150 * like lpfc_create_shost after all other services are initialized.
2151 * It requires a vport, vpi, and wwns at call time. Other localport
2152 * parameters are modified as the driver's FCID and the Fabric WWN
2153 * are established.
2154 *
2155 * Return codes
2156 * 0 - successful
2157 * -ENOMEM - no heap memory available
2158 * other values - from nvme registration upcall
2159 **/
2160int
2161lpfc_nvme_create_localport(struct lpfc_vport *vport)
2162{
166d7211 2163 int ret = 0;
01649561
JS
2164 struct lpfc_hba *phba = vport->phba;
2165 struct nvme_fc_port_info nfcp_info;
2166 struct nvme_fc_local_port *localport;
2167 struct lpfc_nvme_lport *lport;
166d7211 2168 int len;
01649561
JS
2169
2170 /* Initialize this localport instance. The vport wwn usage ensures
2171 * that NPIV is accounted for.
2172 */
2173 memset(&nfcp_info, 0, sizeof(struct nvme_fc_port_info));
2174 nfcp_info.port_role = FC_PORT_ROLE_NVME_INITIATOR;
2175 nfcp_info.node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
2176 nfcp_info.port_name = wwn_to_u64(vport->fc_portname.u.wwn);
2177
4d4c4a4a
JS
2178 /* Limit to LPFC_MAX_NVME_SEG_CNT.
2179 * For now need + 1 to get around NVME transport logic.
2180 */
2181 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
2182 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_INIT,
2183 "6300 Reducing sg segment cnt to %d\n",
2184 LPFC_MAX_NVME_SEG_CNT);
2185 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
2186 } else {
2187 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
2188 }
2189 lpfc_nvme_template.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1;
01649561
JS
2190 lpfc_nvme_template.max_hw_queues = phba->cfg_nvme_io_channel;
2191
2192 /* localport is allocated from the stack, but the registration
2193 * call allocates heap memory as well as the private area.
2194 */
7d708033 2195#if (IS_ENABLED(CONFIG_NVME_FC))
01649561
JS
2196 ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template,
2197 &vport->phba->pcidev->dev, &localport);
166d7211
JS
2198#else
2199 ret = -ENOMEM;
2200#endif
01649561
JS
2201 if (!ret) {
2202 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC,
2203 "6005 Successfully registered local "
2204 "NVME port num %d, localP %p, private %p, "
2205 "sg_seg %d\n",
2206 localport->port_num, localport,
2207 localport->private,
2208 lpfc_nvme_template.max_sgl_segments);
2209
2210 /* Private is our lport size declared in the template. */
2211 lport = (struct lpfc_nvme_lport *)localport->private;
2212 vport->localport = localport;
2213 lport->vport = vport;
01649561 2214 vport->nvmei_support = 1;
6b486ce9
DK
2215
2216 /* Don't post more new bufs if repost already recovered
2217 * the nvme sgls.
2218 */
2219 if (phba->sli4_hba.nvme_xri_cnt == 0) {
2220 len = lpfc_new_nvme_buf(vport,
2221 phba->sli4_hba.nvme_xri_max);
2222 vport->phba->total_nvme_bufs += len;
2223 }
01649561
JS
2224 }
2225
01649561
JS
2226 return ret;
2227}
2228
2229/**
2230 * lpfc_nvme_destroy_localport - Destroy lpfc_nvme bound to nvme transport.
2231 * @pnvme: pointer to lpfc nvme data structure.
2232 *
2233 * This routine is invoked to destroy all lports bound to the phba.
2234 * The lport memory was allocated by the nvme fc transport and is
2235 * released there. This routine ensures all rports bound to the
2236 * lport have been disconnected.
2237 *
2238 **/
2239void
2240lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2241{
7d708033 2242#if (IS_ENABLED(CONFIG_NVME_FC))
01649561
JS
2243 struct nvme_fc_local_port *localport;
2244 struct lpfc_nvme_lport *lport;
01649561
JS
2245 int ret;
2246
2247 if (vport->nvmei_support == 0)
2248 return;
2249
2250 localport = vport->localport;
2251 vport->localport = NULL;
2252 lport = (struct lpfc_nvme_lport *)localport->private;
2253
2254 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2255 "6011 Destroying NVME localport %p\n",
2256 localport);
166d7211 2257
01649561
JS
2258 /* lport's rport list is clear. Unregister
2259 * lport and release resources.
2260 */
2261 init_completion(&lport->lport_unreg_done);
2262 ret = nvme_fc_unregister_localport(localport);
2263 wait_for_completion_timeout(&lport->lport_unreg_done, 5);
2264
2265 /* Regardless of the unregister upcall response, clear
2266 * nvmei_support. All rports are unregistered and the
2267 * driver will clean up.
2268 */
2269 vport->nvmei_support = 0;
2270 if (ret == 0) {
2271 lpfc_printf_vlog(vport,
2272 KERN_INFO, LOG_NVME_DISC,
2273 "6009 Unregistered lport Success\n");
2274 } else {
2275 lpfc_printf_vlog(vport,
2276 KERN_INFO, LOG_NVME_DISC,
2277 "6010 Unregistered lport "
2278 "Failed, status x%x\n",
2279 ret);
2280 }
166d7211 2281#endif
01649561
JS
2282}
2283
2284void
2285lpfc_nvme_update_localport(struct lpfc_vport *vport)
2286{
4410a67a 2287#if (IS_ENABLED(CONFIG_NVME_FC))
01649561
JS
2288 struct nvme_fc_local_port *localport;
2289 struct lpfc_nvme_lport *lport;
2290
2291 localport = vport->localport;
4410a67a
JS
2292 if (!localport) {
2293 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2294 "6710 Update NVME fail. No localport\n");
2295 return;
2296 }
01649561 2297 lport = (struct lpfc_nvme_lport *)localport->private;
4410a67a
JS
2298 if (!lport) {
2299 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2300 "6171 Update NVME fail. localP %p, No lport\n",
2301 localport);
2302 return;
2303 }
01649561
JS
2304 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2305 "6012 Update NVME lport %p did x%x\n",
2306 localport, vport->fc_myDID);
2307
2308 localport->port_id = vport->fc_myDID;
2309 if (localport->port_id == 0)
2310 localport->port_role = FC_PORT_ROLE_NVME_DISCOVERY;
2311 else
2312 localport->port_role = FC_PORT_ROLE_NVME_INITIATOR;
2313
2314 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2315 "6030 bound lport %p to DID x%06x\n",
2316 lport, localport->port_id);
4410a67a 2317#endif
01649561
JS
2318}
2319
2320int
2321lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2322{
7d708033 2323#if (IS_ENABLED(CONFIG_NVME_FC))
01649561
JS
2324 int ret = 0;
2325 struct nvme_fc_local_port *localport;
2326 struct lpfc_nvme_lport *lport;
2327 struct lpfc_nvme_rport *rport;
2328 struct nvme_fc_remote_port *remote_port;
2329 struct nvme_fc_port_info rpinfo;
2b75d0f9 2330 struct lpfc_nodelist *prev_ndlp;
01649561
JS
2331
2332 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC,
2333 "6006 Register NVME PORT. DID x%06x nlptype x%x\n",
2334 ndlp->nlp_DID, ndlp->nlp_type);
2335
2336 localport = vport->localport;
bb6a8a2c
DK
2337 if (!localport)
2338 return 0;
2339
01649561
JS
2340 lport = (struct lpfc_nvme_lport *)localport->private;
2341
7a06dcd3
JS
2342 /* NVME rports are not preserved across devloss.
2343 * Just register this instance. Note, rpinfo->dev_loss_tmo
2344 * is left 0 to indicate accept transport defaults. The
2345 * driver communicates port role capabilities consistent
2346 * with the PRLI response data.
2347 */
2348 memset(&rpinfo, 0, sizeof(struct nvme_fc_port_info));
2349 rpinfo.port_id = ndlp->nlp_DID;
2350 if (ndlp->nlp_type & NLP_NVME_TARGET)
2351 rpinfo.port_role |= FC_PORT_ROLE_NVME_TARGET;
2352 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
2353 rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR;
2354
2355 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
2356 rpinfo.port_role |= FC_PORT_ROLE_NVME_DISCOVERY;
2357
2358 rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
2359 rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
2360 ret = nvme_fc_register_remoteport(localport, &rpinfo, &remote_port);
2361 if (!ret) {
2362 /* If the ndlp already has an nrport, this is just
2363 * a resume of the existing rport. Else this is a
2364 * new rport.
01649561 2365 */
7a06dcd3 2366 rport = remote_port->private;
2b75d0f9 2367 if (ndlp->nrport) {
7a06dcd3
JS
2368 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2369 LOG_NVME_DISC,
2370 "6014 Rebinding lport to "
2371 "rport wwpn 0x%llx, "
2372 "Data: x%x x%x x%x x%06x\n",
2373 remote_port->port_name,
2374 remote_port->port_id,
2375 remote_port->port_role,
01649561
JS
2376 ndlp->nlp_type,
2377 ndlp->nlp_DID);
2b75d0f9
DK
2378 prev_ndlp = rport->ndlp;
2379
2380 /* Sever the ndlp<->rport connection before dropping
2381 * the ndlp ref from register.
2382 */
2383 ndlp->nrport = NULL;
2384 rport->ndlp = NULL;
2385 if (prev_ndlp)
2386 lpfc_nlp_put(ndlp);
01649561 2387 }
2b75d0f9
DK
2388
2389 /* Clean bind the rport to the ndlp. */
2390 rport->remoteport = remote_port;
2391 rport->lport = lport;
2392 rport->ndlp = lpfc_nlp_get(ndlp);
2393 if (!rport->ndlp)
2394 return -1;
2395 ndlp->nrport = rport;
2396 lpfc_printf_vlog(vport, KERN_INFO,
2397 LOG_NVME_DISC | LOG_NODE,
2398 "6022 Binding new rport to "
2399 "lport %p Rport WWNN 0x%llx, "
2400 "Rport WWPN 0x%llx DID "
2401 "x%06x Role x%x\n",
2402 lport,
2403 rpinfo.node_name, rpinfo.port_name,
2404 rpinfo.port_id, rpinfo.port_role);
01649561 2405 } else {
7a06dcd3
JS
2406 lpfc_printf_vlog(vport, KERN_ERR,
2407 LOG_NVME_DISC | LOG_NODE,
2408 "6031 RemotePort Registration failed "
2409 "err: %d, DID x%06x\n",
2410 ret, ndlp->nlp_DID);
01649561 2411 }
7a06dcd3 2412
01649561 2413 return ret;
166d7211
JS
2414#else
2415 return 0;
2416#endif
01649561
JS
2417}
2418
2419/* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport.
2420 *
2421 * There is no notion of Devloss or rport recovery from the current
2422 * nvme_transport perspective. Loss of an rport just means IO cannot
2423 * be sent and recovery is completely up to the initator.
2424 * For now, the driver just unbinds the DID and port_role so that
2425 * no further IO can be issued. Changes are planned for later.
2426 *
2427 * Notes - the ndlp reference count is not decremented here since
2428 * since there is no nvme_transport api for devloss. Node ref count
2429 * is only adjusted in driver unload.
2430 */
2431void
2432lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2433{
7d708033 2434#if (IS_ENABLED(CONFIG_NVME_FC))
01649561
JS
2435 int ret;
2436 struct nvme_fc_local_port *localport;
2437 struct lpfc_nvme_lport *lport;
2438 struct lpfc_nvme_rport *rport;
2439 struct nvme_fc_remote_port *remoteport;
2440
2441 localport = vport->localport;
2442
2443 /* This is fundamental error. The localport is always
2444 * available until driver unload. Just exit.
2445 */
2446 if (!localport)
2447 return;
2448
2449 lport = (struct lpfc_nvme_lport *)localport->private;
2450 if (!lport)
2451 goto input_err;
2452
2453 rport = ndlp->nrport;
2454 if (!rport)
2455 goto input_err;
2456
2457 remoteport = rport->remoteport;
2458 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2459 "6033 Unreg nvme remoteport %p, portname x%llx, "
2460 "port_id x%06x, portstate x%x port type x%x\n",
2461 remoteport, remoteport->port_name,
2462 remoteport->port_id, remoteport->port_state,
2463 ndlp->nlp_type);
2464
2465 /* Sanity check ndlp type. Only call for NVME ports. Don't
2466 * clear any rport state until the transport calls back.
2467 */
2468 if (ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_INITIATOR)) {
2469 init_completion(&rport->rport_unreg_done);
7a06dcd3
JS
2470
2471 /* No concern about the role change on the nvme remoteport.
2472 * The transport will update it.
2473 */
01649561
JS
2474 ret = nvme_fc_unregister_remoteport(remoteport);
2475 if (ret != 0) {
2476 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2477 "6167 NVME unregister failed %d "
2478 "port_state x%x\n",
2479 ret, remoteport->port_state);
2480 }
2481
01649561
JS
2482 }
2483 return;
2484
2485 input_err:
166d7211 2486#endif
01649561 2487 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2b7824d0 2488 "6168 State error: lport %p, rport%p FCID x%06x\n",
01649561
JS
2489 vport->localport, ndlp->rport, ndlp->nlp_DID);
2490}
318083ad
JS
2491
2492/**
2493 * lpfc_sli4_nvme_xri_aborted - Fast-path process of NVME xri abort
2494 * @phba: pointer to lpfc hba data structure.
2495 * @axri: pointer to the fcp xri abort wcqe structure.
2496 *
2497 * This routine is invoked by the worker thread to process a SLI4 fast-path
952c303b
DK
2498 * NVME aborted xri. Aborted NVME IO commands are completed to the transport
2499 * here.
318083ad
JS
2500 **/
2501void
2502lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba,
2503 struct sli4_wcqe_xri_aborted *axri)
2504{
2505 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
318083ad 2506 struct lpfc_nvme_buf *lpfc_ncmd, *next_lpfc_ncmd;
952c303b 2507 struct nvmefc_fcp_req *nvme_cmd = NULL;
318083ad
JS
2508 struct lpfc_nodelist *ndlp;
2509 unsigned long iflag = 0;
318083ad
JS
2510
2511 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
2512 return;
2513 spin_lock_irqsave(&phba->hbalock, iflag);
2514 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2515 list_for_each_entry_safe(lpfc_ncmd, next_lpfc_ncmd,
2516 &phba->sli4_hba.lpfc_abts_nvme_buf_list,
2517 list) {
2518 if (lpfc_ncmd->cur_iocbq.sli4_xritag == xri) {
bbe3012b 2519 list_del_init(&lpfc_ncmd->list);
318083ad
JS
2520 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2521 lpfc_ncmd->status = IOSTAT_SUCCESS;
2522 spin_unlock(
2523 &phba->sli4_hba.abts_nvme_buf_list_lock);
2524
318083ad
JS
2525 spin_unlock_irqrestore(&phba->hbalock, iflag);
2526 ndlp = lpfc_ncmd->ndlp;
952c303b 2527 if (ndlp)
318083ad 2528 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
86c67379
JS
2529
2530 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
952c303b
DK
2531 "6311 nvme_cmd %p xri x%x tag x%x "
2532 "abort complete and xri released\n",
2533 lpfc_ncmd->nvmeCmd, xri,
2534 lpfc_ncmd->cur_iocbq.iotag);
2535
2536 /* Aborted NVME commands are required to not complete
2537 * before the abort exchange command fully completes.
2538 * Once completed, it is available via the put list.
2539 */
2540 nvme_cmd = lpfc_ncmd->nvmeCmd;
2541 nvme_cmd->done(nvme_cmd);
318083ad 2542 lpfc_release_nvme_buf(phba, lpfc_ncmd);
318083ad
JS
2543 return;
2544 }
2545 }
2546 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2547 spin_unlock_irqrestore(&phba->hbalock, iflag);
86c67379
JS
2548
2549 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2550 "6312 XRI Aborted xri x%x not found\n", xri);
2551
318083ad 2552}