1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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"
55#include "lpfc_debugfs.h"
56
57
58
59static struct lpfc_nvme_buf *
60lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
61 int expedite);
62
63static void
64lpfc_release_nvme_buf(struct lpfc_hba *, struct lpfc_nvme_buf *);
65
66static struct nvme_fc_port_template lpfc_nvme_template;
67
68static union lpfc_wqe128 lpfc_iread_cmd_template;
69static union lpfc_wqe128 lpfc_iwrite_cmd_template;
70static union lpfc_wqe128 lpfc_icmnd_cmd_template;
71
72
73void
74lpfc_nvme_cmd_template(void)
75{
76 union lpfc_wqe128 *wqe;
77
78
79 wqe = &lpfc_iread_cmd_template;
80 memset(wqe, 0, sizeof(union lpfc_wqe128));
81
82
83
84
85
86
87
88
89
90
91
92
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);
97
98
99
100
101
102
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);
109
110
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);
114
115
116
117
118
119
120 wqe = &lpfc_iwrite_cmd_template;
121 memset(wqe, 0, sizeof(union lpfc_wqe128));
122
123
124
125
126
127
128
129
130
131
132
133
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);
138
139
140
141
142
143
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);
150
151
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);
155
156
157
158
159
160
161 wqe = &lpfc_icmnd_cmd_template;
162 memset(wqe, 0, sizeof(union lpfc_wqe128));
163
164
165
166
167
168
169
170
171
172
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);
177
178
179
180
181
182
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);
189
190
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);
194
195
196}
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213static int
214lpfc_nvme_create_queue(struct nvme_fc_local_port *pnvme_lport,
215 unsigned int qidx, u16 qsize,
216 void **handle)
217{
218 struct lpfc_nvme_lport *lport;
219 struct lpfc_vport *vport;
220 struct lpfc_nvme_qhandle *qhandle;
221 char *str;
222
223 if (!pnvme_lport->private)
224 return -ENOMEM;
225
226 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
227 vport = lport->vport;
228 qhandle = kzalloc(sizeof(struct lpfc_nvme_qhandle), GFP_KERNEL);
229 if (qhandle == NULL)
230 return -ENOMEM;
231
232 qhandle->cpu_id = smp_processor_id();
233 qhandle->qidx = qidx;
234
235
236
237
238
239 if (qidx) {
240 str = "IO ";
241 qhandle->index = ((qidx - 1) %
242 vport->phba->cfg_nvme_io_channel);
243 } else {
244 str = "ADM";
245 qhandle->index = qidx;
246 }
247
248 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
249 "6073 Binding %s HdwQueue %d (cpu %d) to "
250 "io_channel %d qhandle %p\n", str,
251 qidx, qhandle->cpu_id, qhandle->index, qhandle);
252 *handle = (void *)qhandle;
253 return 0;
254}
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270static void
271lpfc_nvme_delete_queue(struct nvme_fc_local_port *pnvme_lport,
272 unsigned int qidx,
273 void *handle)
274{
275 struct lpfc_nvme_lport *lport;
276 struct lpfc_vport *vport;
277
278 if (!pnvme_lport->private)
279 return;
280
281 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
282 vport = lport->vport;
283
284 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
285 "6001 ENTER. lpfc_pnvme %p, qidx x%xi qhandle %p\n",
286 lport, qidx, handle);
287 kfree(handle);
288}
289
290static void
291lpfc_nvme_localport_delete(struct nvme_fc_local_port *localport)
292{
293 struct lpfc_nvme_lport *lport = localport->private;
294
295 lpfc_printf_vlog(lport->vport, KERN_INFO, LOG_NVME,
296 "6173 localport %p delete complete\n",
297 lport);
298
299
300 complete(&lport->lport_unreg_done);
301}
302
303
304
305
306
307
308
309
310
311
312
313
314void
315lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport)
316{
317 struct lpfc_nvme_rport *rport = remoteport->private;
318 struct lpfc_vport *vport;
319 struct lpfc_nodelist *ndlp;
320
321 ndlp = rport->ndlp;
322 if (!ndlp)
323 goto rport_err;
324
325 vport = ndlp->vport;
326 if (!vport)
327 goto rport_err;
328
329
330
331
332
333 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
334 "6146 remoteport delete of remoteport %p\n",
335 remoteport);
336 spin_lock_irq(&vport->phba->hbalock);
337
338
339
340
341 if (ndlp->upcall_flags & NLP_WAIT_FOR_UNREG) {
342 ndlp->nrport = NULL;
343 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
344 }
345 spin_unlock_irq(&vport->phba->hbalock);
346
347
348
349
350 lpfc_nlp_put(ndlp);
351
352 rport_err:
353 return;
354}
355
356static void
357lpfc_nvme_cmpl_gen_req(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
358 struct lpfc_wcqe_complete *wcqe)
359{
360 struct lpfc_vport *vport = cmdwqe->vport;
361 struct lpfc_nvme_lport *lport;
362 uint32_t status;
363 struct nvmefc_ls_req *pnvme_lsreq;
364 struct lpfc_dmabuf *buf_ptr;
365 struct lpfc_nodelist *ndlp;
366
367 pnvme_lsreq = (struct nvmefc_ls_req *)cmdwqe->context2;
368 status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK;
369
370 if (vport->localport) {
371 lport = (struct lpfc_nvme_lport *)vport->localport->private;
372 if (lport) {
373 atomic_inc(&lport->fc4NvmeLsCmpls);
374 if (status) {
375 if (bf_get(lpfc_wcqe_c_xb, wcqe))
376 atomic_inc(&lport->cmpl_ls_xb);
377 atomic_inc(&lport->cmpl_ls_err);
378 }
379 }
380 }
381
382 ndlp = (struct lpfc_nodelist *)cmdwqe->context1;
383 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
384 "6047 nvme cmpl Enter "
385 "Data %p DID %x Xri: %x status %x reason x%x cmd:%p "
386 "lsreg:%p bmp:%p ndlp:%p\n",
387 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
388 cmdwqe->sli4_xritag, status,
389 (wcqe->parameter & 0xffff),
390 cmdwqe, pnvme_lsreq, cmdwqe->context3, ndlp);
391
392 lpfc_nvmeio_data(phba, "NVME LS CMPL: xri x%x stat x%x parm x%x\n",
393 cmdwqe->sli4_xritag, status, wcqe->parameter);
394
395 if (cmdwqe->context3) {
396 buf_ptr = (struct lpfc_dmabuf *)cmdwqe->context3;
397 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
398 kfree(buf_ptr);
399 cmdwqe->context3 = NULL;
400 }
401 if (pnvme_lsreq->done)
402 pnvme_lsreq->done(pnvme_lsreq, status);
403 else
404 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
405 "6046 nvme cmpl without done call back? "
406 "Data %p DID %x Xri: %x status %x\n",
407 pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0,
408 cmdwqe->sli4_xritag, status);
409 if (ndlp) {
410 lpfc_nlp_put(ndlp);
411 cmdwqe->context1 = NULL;
412 }
413 lpfc_sli_release_iocbq(phba, cmdwqe);
414}
415
416static int
417lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
418 struct lpfc_dmabuf *inp,
419 struct nvmefc_ls_req *pnvme_lsreq,
420 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
421 struct lpfc_wcqe_complete *),
422 struct lpfc_nodelist *ndlp, uint32_t num_entry,
423 uint32_t tmo, uint8_t retry)
424{
425 struct lpfc_hba *phba = vport->phba;
426 union lpfc_wqe128 *wqe;
427 struct lpfc_iocbq *genwqe;
428 struct ulp_bde64 *bpl;
429 struct ulp_bde64 bde;
430 int i, rc, xmit_len, first_len;
431
432
433 genwqe = lpfc_sli_get_iocbq(phba);
434 if (genwqe == NULL)
435 return 1;
436
437 wqe = &genwqe->wqe;
438 memset(wqe, 0, sizeof(union lpfc_wqe));
439
440 genwqe->context3 = (uint8_t *)bmp;
441 genwqe->iocb_flag |= LPFC_IO_NVME_LS;
442
443
444 genwqe->context1 = lpfc_nlp_get(ndlp);
445 genwqe->context2 = (uint8_t *)pnvme_lsreq;
446
447
448 if (!tmo)
449
450 tmo = (3 * phba->fc_ratov);
451
452
453 xmit_len = 0;
454 first_len = 0;
455 bpl = (struct ulp_bde64 *)bmp->virt;
456 for (i = 0; i < num_entry; i++) {
457 bde.tus.w = bpl[i].tus.w;
458 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
459 break;
460 xmit_len += bde.tus.f.bdeSize;
461 if (i == 0)
462 first_len = xmit_len;
463 }
464
465 genwqe->rsvd2 = num_entry;
466 genwqe->hba_wqidx = 0;
467
468
469 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
470 wqe->generic.bde.tus.f.bdeSize = first_len;
471 wqe->generic.bde.addrLow = bpl[0].addrLow;
472 wqe->generic.bde.addrHigh = bpl[0].addrHigh;
473
474
475 wqe->gen_req.request_payload_len = first_len;
476
477
478
479
480 bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0);
481 bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1);
482 bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1);
483 bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_ELS4_REQ);
484 bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME);
485
486
487 bf_set(wqe_ctxt_tag, &wqe->gen_req.wqe_com,
488 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
489 bf_set(wqe_xri_tag, &wqe->gen_req.wqe_com, genwqe->sli4_xritag);
490
491
492 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, (vport->phba->fc_ratov-1));
493 bf_set(wqe_class, &wqe->gen_req.wqe_com, CLASS3);
494 bf_set(wqe_cmnd, &wqe->gen_req.wqe_com, CMD_GEN_REQUEST64_WQE);
495 bf_set(wqe_ct, &wqe->gen_req.wqe_com, SLI4_CT_RPI);
496
497
498 wqe->gen_req.wqe_com.abort_tag = genwqe->iotag;
499
500
501 bf_set(wqe_reqtag, &wqe->gen_req.wqe_com, genwqe->iotag);
502
503
504 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
505 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
506 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
507 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
508 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
509
510
511 bf_set(wqe_cqid, &wqe->gen_req.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
512 bf_set(wqe_cmd_type, &wqe->gen_req.wqe_com, OTHER_COMMAND);
513
514
515
516 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
517 "6050 Issue GEN REQ WQE to NPORT x%x "
518 "Data: x%x x%x wq:%p lsreq:%p bmp:%p xmit:%d 1st:%d\n",
519 ndlp->nlp_DID, genwqe->iotag,
520 vport->port_state,
521 genwqe, pnvme_lsreq, bmp, xmit_len, first_len);
522 genwqe->wqe_cmpl = cmpl;
523 genwqe->iocb_cmpl = NULL;
524 genwqe->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT;
525 genwqe->vport = vport;
526 genwqe->retry = retry;
527
528 lpfc_nvmeio_data(phba, "NVME LS XMIT: xri x%x iotag x%x to x%06x\n",
529 genwqe->sli4_xritag, genwqe->iotag, ndlp->nlp_DID);
530
531 rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, genwqe);
532 if (rc) {
533 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
534 "6045 Issue GEN REQ WQE to NPORT x%x "
535 "Data: x%x x%x\n",
536 ndlp->nlp_DID, genwqe->iotag,
537 vport->port_state);
538 lpfc_sli_release_iocbq(phba, genwqe);
539 return 1;
540 }
541 return 0;
542}
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557static int
558lpfc_nvme_ls_req(struct nvme_fc_local_port *pnvme_lport,
559 struct nvme_fc_remote_port *pnvme_rport,
560 struct nvmefc_ls_req *pnvme_lsreq)
561{
562 int ret = 0;
563 struct lpfc_nvme_lport *lport;
564 struct lpfc_nvme_rport *rport;
565 struct lpfc_vport *vport;
566 struct lpfc_nodelist *ndlp;
567 struct ulp_bde64 *bpl;
568 struct lpfc_dmabuf *bmp;
569 uint16_t ntype, nstate;
570
571
572
573
574
575
576
577
578
579
580
581
582 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
583 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
584 if (unlikely(!lport) || unlikely(!rport))
585 return -EINVAL;
586
587 vport = lport->vport;
588
589 if (vport->load_flag & FC_UNLOADING)
590 return -ENODEV;
591
592
593 ndlp = rport->ndlp;
594 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
595 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
596 "6051 Remoteport %p, rport has invalid ndlp. "
597 "Failing LS Req\n", pnvme_rport);
598 return -ENODEV;
599 }
600
601
602
603
604 ntype = ndlp->nlp_type;
605 nstate = ndlp->nlp_state;
606 if ((ntype & NLP_NVME_TARGET && nstate != NLP_STE_MAPPED_NODE) ||
607 (ntype & NLP_NVME_INITIATOR && nstate != NLP_STE_UNMAPPED_NODE)) {
608 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
609 "6088 DID x%06x not ready for "
610 "IO. State x%x, Type x%x\n",
611 pnvme_rport->port_id,
612 ndlp->nlp_state, ndlp->nlp_type);
613 return -ENODEV;
614 }
615 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
616 if (!bmp) {
617
618 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
619 "6044 Could not find node for DID %x\n",
620 pnvme_rport->port_id);
621 return 2;
622 }
623 INIT_LIST_HEAD(&bmp->list);
624 bmp->virt = lpfc_mbuf_alloc(vport->phba, MEM_PRI, &(bmp->phys));
625 if (!bmp->virt) {
626 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
627 "6042 Could not find node for DID %x\n",
628 pnvme_rport->port_id);
629 kfree(bmp);
630 return 3;
631 }
632 bpl = (struct ulp_bde64 *)bmp->virt;
633 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rqstdma));
634 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rqstdma));
635 bpl->tus.f.bdeFlags = 0;
636 bpl->tus.f.bdeSize = pnvme_lsreq->rqstlen;
637 bpl->tus.w = le32_to_cpu(bpl->tus.w);
638 bpl++;
639
640 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rspdma));
641 bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rspdma));
642 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
643 bpl->tus.f.bdeSize = pnvme_lsreq->rsplen;
644 bpl->tus.w = le32_to_cpu(bpl->tus.w);
645
646
647 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
648 "6149 Issue LS Req to DID 0x%06x lport %p, rport %p "
649 "lsreq%p rqstlen:%d rsplen:%d %pad %pad\n",
650 ndlp->nlp_DID,
651 pnvme_lport, pnvme_rport,
652 pnvme_lsreq, pnvme_lsreq->rqstlen,
653 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
654 &pnvme_lsreq->rspdma);
655
656 atomic_inc(&lport->fc4NvmeLsRequests);
657
658
659
660
661 ret = lpfc_nvme_gen_req(vport, bmp, pnvme_lsreq->rqstaddr,
662 pnvme_lsreq, lpfc_nvme_cmpl_gen_req,
663 ndlp, 2, 30, 0);
664 if (ret != WQE_SUCCESS) {
665 atomic_inc(&lport->xmt_ls_err);
666 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
667 "6052 EXIT. issue ls wqe failed lport %p, "
668 "rport %p lsreq%p Status %x DID %x\n",
669 pnvme_lport, pnvme_rport, pnvme_lsreq,
670 ret, ndlp->nlp_DID);
671 lpfc_mbuf_free(vport->phba, bmp->virt, bmp->phys);
672 kfree(bmp);
673 return ret;
674 }
675
676
677 return ret;
678}
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693static void
694lpfc_nvme_ls_abort(struct nvme_fc_local_port *pnvme_lport,
695 struct nvme_fc_remote_port *pnvme_rport,
696 struct nvmefc_ls_req *pnvme_lsreq)
697{
698 struct lpfc_nvme_lport *lport;
699 struct lpfc_vport *vport;
700 struct lpfc_hba *phba;
701 struct lpfc_nodelist *ndlp;
702 LIST_HEAD(abort_list);
703 struct lpfc_sli_ring *pring;
704 struct lpfc_iocbq *wqe, *next_wqe;
705
706 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
707 if (unlikely(!lport))
708 return;
709 vport = lport->vport;
710 phba = vport->phba;
711
712 if (vport->load_flag & FC_UNLOADING)
713 return;
714
715 ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id);
716 if (!ndlp) {
717 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
718 "6049 Could not find node for DID %x\n",
719 pnvme_rport->port_id);
720 return;
721 }
722
723
724 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
725 "6040 ENTER. lport %p, rport %p lsreq %p rqstlen:%d "
726 "rsplen:%d %pad %pad\n",
727 pnvme_lport, pnvme_rport,
728 pnvme_lsreq, pnvme_lsreq->rqstlen,
729 pnvme_lsreq->rsplen, &pnvme_lsreq->rqstdma,
730 &pnvme_lsreq->rspdma);
731
732
733
734
735
736
737 pring = phba->sli4_hba.nvmels_wq->pring;
738 spin_lock_irq(&phba->hbalock);
739 spin_lock(&pring->ring_lock);
740 list_for_each_entry_safe(wqe, next_wqe, &pring->txcmplq, list) {
741
742 if (lpfc_check_sli_ndlp(phba, pring, wqe, ndlp)) {
743 wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
744 list_add_tail(&wqe->dlist, &abort_list);
745 }
746 }
747 spin_unlock(&pring->ring_lock);
748 spin_unlock_irq(&phba->hbalock);
749
750
751 list_for_each_entry_safe(wqe, next_wqe, &abort_list, dlist) {
752 atomic_inc(&lport->xmt_ls_abort);
753 spin_lock_irq(&phba->hbalock);
754 list_del_init(&wqe->dlist);
755 lpfc_sli_issue_abort_iotag(phba, pring, wqe);
756 spin_unlock_irq(&phba->hbalock);
757 }
758}
759
760
761static inline void
762lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport,
763 struct lpfc_nvme_buf *lpfc_ncmd,
764 struct nvmefc_fcp_req *nCmd)
765{
766 struct lpfc_hba *phba = vport->phba;
767 struct sli4_sge *sgl;
768 union lpfc_wqe128 *wqe;
769 uint32_t *wptr, *dptr;
770
771
772
773
774
775
776
777 wqe = &lpfc_ncmd->cur_iocbq.wqe;
778
779
780
781
782
783
784
785
786 sgl = lpfc_ncmd->nvme_sgl;
787 sgl->sge_len = cpu_to_le32(nCmd->cmdlen);
788 if (phba->cfg_nvme_embed_cmd) {
789 sgl->addr_hi = 0;
790 sgl->addr_lo = 0;
791
792
793 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_IMMED;
794 wqe->generic.bde.tus.f.bdeSize = 56;
795 wqe->generic.bde.addrHigh = 0;
796 wqe->generic.bde.addrLow = 64;
797
798
799
800
801
802
803
804
805
806
807
808 wptr = &wqe->words[16];
809 dptr = (uint32_t *)nCmd->cmdaddr;
810 dptr++;
811
812 *wptr++ = *dptr++;
813 *wptr++ = *dptr++;
814 *wptr++ = *dptr++;
815 *wptr++ = *dptr++;
816 dptr++;
817 *wptr++ = *dptr++;
818 *wptr++ = *dptr++;
819 dptr += 8;
820 *wptr++ = *dptr++;
821 *wptr++ = *dptr++;
822 *wptr++ = *dptr++;
823 *wptr++ = *dptr++;
824 *wptr++ = *dptr++;
825 *wptr++ = *dptr++;
826 *wptr++ = *dptr++;
827 *wptr = *dptr;
828 } else {
829 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->cmddma));
830 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->cmddma));
831
832
833 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
834 wqe->generic.bde.tus.f.bdeSize = nCmd->cmdlen;
835 wqe->generic.bde.addrHigh = sgl->addr_hi;
836 wqe->generic.bde.addrLow = sgl->addr_lo;
837
838
839 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
840 bf_set(wqe_wqes, &wqe->generic.wqe_com, 0);
841 }
842
843 sgl++;
844
845
846 sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->rspdma));
847 sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->rspdma));
848 sgl->word2 = le32_to_cpu(sgl->word2);
849 if (nCmd->sg_cnt)
850 bf_set(lpfc_sli4_sge_last, sgl, 0);
851 else
852 bf_set(lpfc_sli4_sge_last, sgl, 1);
853 sgl->word2 = cpu_to_le32(sgl->word2);
854 sgl->sge_len = cpu_to_le32(nCmd->rsplen);
855}
856
857#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
858static void
859lpfc_nvme_ktime(struct lpfc_hba *phba,
860 struct lpfc_nvme_buf *lpfc_ncmd)
861{
862 uint64_t seg1, seg2, seg3, seg4;
863 uint64_t segsum;
864
865 if (!lpfc_ncmd->ts_last_cmd ||
866 !lpfc_ncmd->ts_cmd_start ||
867 !lpfc_ncmd->ts_cmd_wqput ||
868 !lpfc_ncmd->ts_isr_cmpl ||
869 !lpfc_ncmd->ts_data_nvme)
870 return;
871
872 if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_cmd_start)
873 return;
874 if (lpfc_ncmd->ts_cmd_start < lpfc_ncmd->ts_last_cmd)
875 return;
876 if (lpfc_ncmd->ts_cmd_wqput < lpfc_ncmd->ts_cmd_start)
877 return;
878 if (lpfc_ncmd->ts_isr_cmpl < lpfc_ncmd->ts_cmd_wqput)
879 return;
880 if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_isr_cmpl)
881 return;
882
883
884
885
886
887
888
889
890
891
892 seg1 = lpfc_ncmd->ts_cmd_start - lpfc_ncmd->ts_last_cmd;
893 if (seg1 > 5000000)
894 seg1 = 0;
895
896
897 seg2 = (lpfc_ncmd->ts_cmd_wqput - lpfc_ncmd->ts_cmd_start);
898 segsum = seg2;
899 seg3 = lpfc_ncmd->ts_isr_cmpl - lpfc_ncmd->ts_cmd_start;
900 if (segsum > seg3)
901 return;
902 seg3 -= segsum;
903 segsum += seg3;
904
905 seg4 = lpfc_ncmd->ts_data_nvme - lpfc_ncmd->ts_cmd_start;
906 if (segsum > seg4)
907 return;
908 seg4 -= segsum;
909
910 phba->ktime_data_samples++;
911 phba->ktime_seg1_total += seg1;
912 if (seg1 < phba->ktime_seg1_min)
913 phba->ktime_seg1_min = seg1;
914 else if (seg1 > phba->ktime_seg1_max)
915 phba->ktime_seg1_max = seg1;
916 phba->ktime_seg2_total += seg2;
917 if (seg2 < phba->ktime_seg2_min)
918 phba->ktime_seg2_min = seg2;
919 else if (seg2 > phba->ktime_seg2_max)
920 phba->ktime_seg2_max = seg2;
921 phba->ktime_seg3_total += seg3;
922 if (seg3 < phba->ktime_seg3_min)
923 phba->ktime_seg3_min = seg3;
924 else if (seg3 > phba->ktime_seg3_max)
925 phba->ktime_seg3_max = seg3;
926 phba->ktime_seg4_total += seg4;
927 if (seg4 < phba->ktime_seg4_min)
928 phba->ktime_seg4_min = seg4;
929 else if (seg4 > phba->ktime_seg4_max)
930 phba->ktime_seg4_max = seg4;
931
932 lpfc_ncmd->ts_last_cmd = 0;
933 lpfc_ncmd->ts_cmd_start = 0;
934 lpfc_ncmd->ts_cmd_wqput = 0;
935 lpfc_ncmd->ts_isr_cmpl = 0;
936 lpfc_ncmd->ts_data_nvme = 0;
937}
938#endif
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954static void
955lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
956 struct lpfc_wcqe_complete *wcqe)
957{
958 struct lpfc_nvme_buf *lpfc_ncmd =
959 (struct lpfc_nvme_buf *)pwqeIn->context1;
960 struct lpfc_vport *vport = pwqeIn->vport;
961 struct nvmefc_fcp_req *nCmd;
962 struct nvme_fc_ersp_iu *ep;
963 struct nvme_fc_cmd_iu *cp;
964 struct lpfc_nvme_rport *rport;
965 struct lpfc_nodelist *ndlp;
966 struct lpfc_nvme_fcpreq_priv *freqpriv;
967 struct lpfc_nvme_lport *lport;
968 struct lpfc_nvme_ctrl_stat *cstat;
969 unsigned long flags;
970 uint32_t code, status, idx;
971 uint16_t cid, sqhd, data;
972 uint32_t *ptr;
973
974
975 if (!lpfc_ncmd || !lpfc_ncmd->nvmeCmd || !lpfc_ncmd->nrport) {
976 if (!lpfc_ncmd) {
977 lpfc_printf_vlog(vport, KERN_ERR,
978 LOG_NODE | LOG_NVME_IOERR,
979 "6071 Null lpfc_ncmd pointer. No "
980 "release, skip completion\n");
981 return;
982 }
983
984 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
985 "6066 Missing cmpl ptrs: lpfc_ncmd %p, "
986 "nvmeCmd %p nrport %p\n",
987 lpfc_ncmd, lpfc_ncmd->nvmeCmd,
988 lpfc_ncmd->nrport);
989
990
991 lpfc_release_nvme_buf(phba, lpfc_ncmd);
992 return;
993 }
994 nCmd = lpfc_ncmd->nvmeCmd;
995 rport = lpfc_ncmd->nrport;
996 status = bf_get(lpfc_wcqe_c_status, wcqe);
997
998 if (vport->localport) {
999 lport = (struct lpfc_nvme_lport *)vport->localport->private;
1000 if (lport) {
1001 idx = lpfc_ncmd->cur_iocbq.hba_wqidx;
1002 cstat = &lport->cstat[idx];
1003 atomic_inc(&cstat->fc4NvmeIoCmpls);
1004 if (status) {
1005 if (bf_get(lpfc_wcqe_c_xb, wcqe))
1006 atomic_inc(&lport->cmpl_fcp_xb);
1007 atomic_inc(&lport->cmpl_fcp_err);
1008 }
1009 }
1010 }
1011
1012 lpfc_nvmeio_data(phba, "NVME FCP CMPL: xri x%x stat x%x parm x%x\n",
1013 lpfc_ncmd->cur_iocbq.sli4_xritag,
1014 status, wcqe->parameter);
1015
1016
1017
1018
1019 ndlp = rport->ndlp;
1020 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1021 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR,
1022 "6061 rport %p, DID x%06x node not ready.\n",
1023 rport, rport->remoteport->port_id);
1024
1025 ndlp = lpfc_findnode_did(vport, rport->remoteport->port_id);
1026 if (!ndlp) {
1027 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1028 "6062 Ignoring NVME cmpl. No ndlp\n");
1029 goto out_err;
1030 }
1031 }
1032
1033 code = bf_get(lpfc_wcqe_c_code, wcqe);
1034 if (code == CQE_CODE_NVME_ERSP) {
1035
1036 ep = (struct nvme_fc_ersp_iu *)nCmd->rspaddr;
1037
1038
1039
1040
1041
1042 cp = (struct nvme_fc_cmd_iu *)nCmd->cmdaddr;
1043 cid = cp->sqe.common.command_id;
1044
1045
1046
1047
1048
1049
1050
1051 sqhd = bf_get(lpfc_wcqe_c_sqhead, wcqe);
1052
1053
1054 ep->iu_len = cpu_to_be16(8);
1055 ep->rsn = wcqe->parameter;
1056 ep->xfrd_len = cpu_to_be32(nCmd->payload_length);
1057 ep->rsvd12 = 0;
1058 ptr = (uint32_t *)&ep->cqe.result.u64;
1059 *ptr++ = wcqe->total_data_placed;
1060 data = bf_get(lpfc_wcqe_c_ersp0, wcqe);
1061 *ptr = (uint32_t)data;
1062 ep->cqe.sq_head = sqhd;
1063 ep->cqe.sq_id = nCmd->sqid;
1064 ep->cqe.command_id = cid;
1065 ep->cqe.status = 0;
1066
1067 lpfc_ncmd->status = IOSTAT_SUCCESS;
1068 lpfc_ncmd->result = 0;
1069 nCmd->rcv_rsplen = LPFC_NVME_ERSP_LEN;
1070 nCmd->transferred_length = nCmd->payload_length;
1071 } else {
1072 lpfc_ncmd->status = (status & LPFC_IOCB_STATUS_MASK);
1073 lpfc_ncmd->result = (wcqe->parameter & IOERR_PARAM_MASK);
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086 switch (lpfc_ncmd->status) {
1087 case IOSTAT_SUCCESS:
1088 nCmd->transferred_length = wcqe->total_data_placed;
1089 nCmd->rcv_rsplen = 0;
1090 nCmd->status = 0;
1091 break;
1092 case IOSTAT_FCP_RSP_ERROR:
1093 nCmd->transferred_length = wcqe->total_data_placed;
1094 nCmd->rcv_rsplen = wcqe->parameter;
1095 nCmd->status = 0;
1096
1097 if (nCmd->rcv_rsplen == LPFC_NVME_ERSP_LEN)
1098 break;
1099 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1100 "6081 NVME Completion Protocol Error: "
1101 "xri %x status x%x result x%x "
1102 "placed x%x\n",
1103 lpfc_ncmd->cur_iocbq.sli4_xritag,
1104 lpfc_ncmd->status, lpfc_ncmd->result,
1105 wcqe->total_data_placed);
1106 break;
1107 case IOSTAT_LOCAL_REJECT:
1108
1109 if (lpfc_ncmd->result == IOERR_ABORT_REQUESTED)
1110 lpfc_printf_vlog(vport, KERN_INFO,
1111 LOG_NVME_IOERR,
1112 "6032 Delay Aborted cmd %p "
1113 "nvme cmd %p, xri x%x, "
1114 "xb %d\n",
1115 lpfc_ncmd, nCmd,
1116 lpfc_ncmd->cur_iocbq.sli4_xritag,
1117 bf_get(lpfc_wcqe_c_xb, wcqe));
1118 default:
1119out_err:
1120 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1121 "6072 NVME Completion Error: xri %x "
1122 "status x%x result x%x placed x%x\n",
1123 lpfc_ncmd->cur_iocbq.sli4_xritag,
1124 lpfc_ncmd->status, lpfc_ncmd->result,
1125 wcqe->total_data_placed);
1126 nCmd->transferred_length = 0;
1127 nCmd->rcv_rsplen = 0;
1128 nCmd->status = NVME_SC_INTERNAL;
1129 }
1130 }
1131
1132
1133 if (bf_get(lpfc_wcqe_c_xb, wcqe))
1134 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
1135 else
1136 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
1137
1138
1139
1140
1141
1142#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1143 if (lpfc_ncmd->ts_cmd_start) {
1144 lpfc_ncmd->ts_isr_cmpl = pwqeIn->isr_timestamp;
1145 lpfc_ncmd->ts_data_nvme = ktime_get_ns();
1146 phba->ktime_last_cmd = lpfc_ncmd->ts_data_nvme;
1147 lpfc_nvme_ktime(phba, lpfc_ncmd);
1148 }
1149 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) {
1150 if (lpfc_ncmd->cpu != smp_processor_id())
1151 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
1152 "6701 CPU Check cmpl: "
1153 "cpu %d expect %d\n",
1154 smp_processor_id(), lpfc_ncmd->cpu);
1155 if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT)
1156 phba->cpucheck_cmpl_io[lpfc_ncmd->cpu]++;
1157 }
1158#endif
1159
1160
1161
1162
1163
1164 if (!(lpfc_ncmd->flags & LPFC_SBUF_XBUSY)) {
1165 freqpriv = nCmd->private;
1166 freqpriv->nvme_buf = NULL;
1167 nCmd->done(nCmd);
1168 lpfc_ncmd->nvmeCmd = NULL;
1169 }
1170
1171 spin_lock_irqsave(&phba->hbalock, flags);
1172 lpfc_ncmd->nrport = NULL;
1173 spin_unlock_irqrestore(&phba->hbalock, flags);
1174
1175
1176 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1177}
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196static int
1197lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport,
1198 struct lpfc_nvme_buf *lpfc_ncmd,
1199 struct lpfc_nodelist *pnode,
1200 struct lpfc_nvme_ctrl_stat *cstat)
1201{
1202 struct lpfc_hba *phba = vport->phba;
1203 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1204 struct lpfc_iocbq *pwqeq = &(lpfc_ncmd->cur_iocbq);
1205 union lpfc_wqe128 *wqe = &pwqeq->wqe;
1206 uint32_t req_len;
1207
1208 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
1209 return -EINVAL;
1210
1211
1212
1213
1214
1215 if (nCmd->sg_cnt) {
1216 if (nCmd->io_dir == NVMEFC_FCP_WRITE) {
1217
1218 memcpy(&wqe->words[7],
1219 &lpfc_iwrite_cmd_template.words[7],
1220 sizeof(uint32_t) * 5);
1221
1222
1223 wqe->fcp_iwrite.total_xfer_len = nCmd->payload_length;
1224
1225
1226 if ((phba->cfg_nvme_enable_fb) &&
1227 (pnode->nlp_flag & NLP_FIRSTBURST)) {
1228 req_len = lpfc_ncmd->nvmeCmd->payload_length;
1229 if (req_len < pnode->nvme_fb_size)
1230 wqe->fcp_iwrite.initial_xfer_len =
1231 req_len;
1232 else
1233 wqe->fcp_iwrite.initial_xfer_len =
1234 pnode->nvme_fb_size;
1235 } else {
1236 wqe->fcp_iwrite.initial_xfer_len = 0;
1237 }
1238 atomic_inc(&cstat->fc4NvmeOutputRequests);
1239 } else {
1240
1241 memcpy(&wqe->words[7],
1242 &lpfc_iread_cmd_template.words[7],
1243 sizeof(uint32_t) * 5);
1244
1245
1246 wqe->fcp_iread.total_xfer_len = nCmd->payload_length;
1247
1248
1249 wqe->fcp_iread.rsrvd5 = 0;
1250
1251 atomic_inc(&cstat->fc4NvmeInputRequests);
1252 }
1253 } else {
1254
1255 memcpy(&wqe->words[4], &lpfc_icmnd_cmd_template.words[4],
1256 sizeof(uint32_t) * 8);
1257 atomic_inc(&cstat->fc4NvmeControlRequests);
1258 }
1259
1260
1261
1262
1263
1264
1265 bf_set(payload_offset_len, &wqe->fcp_icmd,
1266 (nCmd->rsplen + nCmd->cmdlen));
1267
1268
1269 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
1270 phba->sli4_hba.rpi_ids[pnode->nlp_rpi]);
1271 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag);
1272
1273
1274 wqe->generic.wqe_com.abort_tag = pwqeq->iotag;
1275
1276
1277 bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag);
1278
1279
1280
1281 pwqeq->vport = vport;
1282 return 0;
1283}
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302static int
1303lpfc_nvme_prep_io_dma(struct lpfc_vport *vport,
1304 struct lpfc_nvme_buf *lpfc_ncmd)
1305{
1306 struct lpfc_hba *phba = vport->phba;
1307 struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd;
1308 union lpfc_wqe128 *wqe = &lpfc_ncmd->cur_iocbq.wqe;
1309 struct sli4_sge *sgl = lpfc_ncmd->nvme_sgl;
1310 struct scatterlist *data_sg;
1311 struct sli4_sge *first_data_sgl;
1312 struct ulp_bde64 *bde;
1313 dma_addr_t physaddr;
1314 uint32_t num_bde = 0;
1315 uint32_t dma_len;
1316 uint32_t dma_offset = 0;
1317 int nseg, i;
1318
1319
1320 lpfc_nvme_adj_fcp_sgls(vport, lpfc_ncmd, nCmd);
1321
1322
1323
1324
1325
1326 if (nCmd->sg_cnt) {
1327
1328
1329
1330
1331 sgl += 2;
1332
1333 first_data_sgl = sgl;
1334 lpfc_ncmd->seg_cnt = nCmd->sg_cnt;
1335 if (lpfc_ncmd->seg_cnt > lpfc_nvme_template.max_sgl_segments) {
1336 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1337 "6058 Too many sg segments from "
1338 "NVME Transport. Max %d, "
1339 "nvmeIO sg_cnt %d\n",
1340 phba->cfg_nvme_seg_cnt + 1,
1341 lpfc_ncmd->seg_cnt);
1342 lpfc_ncmd->seg_cnt = 0;
1343 return 1;
1344 }
1345
1346
1347
1348
1349
1350
1351
1352 nseg = nCmd->sg_cnt;
1353 data_sg = nCmd->first_sgl;
1354 for (i = 0; i < nseg; i++) {
1355 if (data_sg == NULL) {
1356 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1357 "6059 dptr err %d, nseg %d\n",
1358 i, nseg);
1359 lpfc_ncmd->seg_cnt = 0;
1360 return 1;
1361 }
1362 physaddr = data_sg->dma_address;
1363 dma_len = data_sg->length;
1364 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
1365 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
1366 sgl->word2 = le32_to_cpu(sgl->word2);
1367 if ((num_bde + 1) == nseg)
1368 bf_set(lpfc_sli4_sge_last, sgl, 1);
1369 else
1370 bf_set(lpfc_sli4_sge_last, sgl, 0);
1371 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
1372 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
1373 sgl->word2 = cpu_to_le32(sgl->word2);
1374 sgl->sge_len = cpu_to_le32(dma_len);
1375
1376 dma_offset += dma_len;
1377 data_sg = sg_next(data_sg);
1378 sgl++;
1379 }
1380 if (phba->cfg_enable_pbde) {
1381
1382
1383 bde = (struct ulp_bde64 *)
1384 &wqe->words[13];
1385 bde->addrLow = first_data_sgl->addr_lo;
1386 bde->addrHigh = first_data_sgl->addr_hi;
1387 bde->tus.f.bdeSize =
1388 le32_to_cpu(first_data_sgl->sge_len);
1389 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1390 bde->tus.w = cpu_to_le32(bde->tus.w);
1391
1392 } else {
1393 memset(&wqe->words[13], 0, (sizeof(uint32_t) * 3));
1394 bf_set(wqe_pbde, &wqe->generic.wqe_com, 0);
1395 }
1396
1397 } else {
1398
1399
1400
1401 if (nCmd->payload_length != 0) {
1402 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1403 "6063 NVME DMA Prep Err: sg_cnt %d "
1404 "payload_length x%x\n",
1405 nCmd->sg_cnt, nCmd->payload_length);
1406 return 1;
1407 }
1408 }
1409 return 0;
1410}
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429static int
1430lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
1431 struct nvme_fc_remote_port *pnvme_rport,
1432 void *hw_queue_handle,
1433 struct nvmefc_fcp_req *pnvme_fcreq)
1434{
1435 int ret = 0;
1436 int expedite = 0;
1437 int idx;
1438 struct lpfc_nvme_lport *lport;
1439 struct lpfc_nvme_ctrl_stat *cstat;
1440 struct lpfc_vport *vport;
1441 struct lpfc_hba *phba;
1442 struct lpfc_nodelist *ndlp;
1443 struct lpfc_nvme_buf *lpfc_ncmd;
1444 struct lpfc_nvme_rport *rport;
1445 struct lpfc_nvme_qhandle *lpfc_queue_info;
1446 struct lpfc_nvme_fcpreq_priv *freqpriv;
1447 struct nvme_common_command *sqe;
1448#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1449 uint64_t start = 0;
1450#endif
1451
1452
1453
1454
1455 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1456 if (unlikely(!lport)) {
1457 ret = -EINVAL;
1458 goto out_fail;
1459 }
1460
1461 vport = lport->vport;
1462
1463 if (unlikely(!hw_queue_handle)) {
1464 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1465 "6117 Fail IO, NULL hw_queue_handle\n");
1466 atomic_inc(&lport->xmt_fcp_err);
1467 ret = -EBUSY;
1468 goto out_fail;
1469 }
1470
1471 phba = vport->phba;
1472
1473 if (vport->load_flag & FC_UNLOADING) {
1474 ret = -ENODEV;
1475 goto out_fail;
1476 }
1477
1478 if (vport->load_flag & FC_UNLOADING) {
1479 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1480 "6124 Fail IO, Driver unload\n");
1481 atomic_inc(&lport->xmt_fcp_err);
1482 ret = -ENODEV;
1483 goto out_fail;
1484 }
1485
1486 freqpriv = pnvme_fcreq->private;
1487 if (unlikely(!freqpriv)) {
1488 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1489 "6158 Fail IO, NULL request data\n");
1490 atomic_inc(&lport->xmt_fcp_err);
1491 ret = -EINVAL;
1492 goto out_fail;
1493 }
1494
1495#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1496 if (phba->ktime_on)
1497 start = ktime_get_ns();
1498#endif
1499 rport = (struct lpfc_nvme_rport *)pnvme_rport->private;
1500 lpfc_queue_info = (struct lpfc_nvme_qhandle *)hw_queue_handle;
1501
1502
1503
1504
1505
1506 ndlp = rport->ndlp;
1507 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1508 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1509 "6053 Fail IO, ndlp not ready: rport %p "
1510 "ndlp %p, DID x%06x\n",
1511 rport, ndlp, pnvme_rport->port_id);
1512 atomic_inc(&lport->xmt_fcp_err);
1513 ret = -EBUSY;
1514 goto out_fail;
1515 }
1516
1517
1518 if ((ndlp->nlp_type & NLP_NVME_TARGET) &&
1519 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
1520 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_NVME_IOERR,
1521 "6036 Fail IO, DID x%06x not ready for "
1522 "IO. State x%x, Type x%x Flg x%x\n",
1523 pnvme_rport->port_id,
1524 ndlp->nlp_state, ndlp->nlp_type,
1525 ndlp->upcall_flags);
1526 atomic_inc(&lport->xmt_fcp_bad_ndlp);
1527 ret = -EBUSY;
1528 goto out_fail;
1529
1530 }
1531
1532
1533
1534
1535
1536 if (!lpfc_queue_info->qidx && !pnvme_fcreq->sg_cnt) {
1537 sqe = &((struct nvme_fc_cmd_iu *)
1538 pnvme_fcreq->cmdaddr)->sqe.common;
1539 if (sqe->opcode == nvme_admin_keep_alive)
1540 expedite = 1;
1541 }
1542
1543
1544
1545
1546 if (lpfc_ndlp_check_qdepth(phba, ndlp)) {
1547 if ((atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) &&
1548 !expedite) {
1549 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1550 "6174 Fail IO, ndlp qdepth exceeded: "
1551 "idx %d DID %x pend %d qdepth %d\n",
1552 lpfc_queue_info->index, ndlp->nlp_DID,
1553 atomic_read(&ndlp->cmd_pending),
1554 ndlp->cmd_qdepth);
1555 atomic_inc(&lport->xmt_fcp_qdepth);
1556 ret = -EBUSY;
1557 goto out_fail;
1558 }
1559 }
1560
1561 lpfc_ncmd = lpfc_get_nvme_buf(phba, ndlp, expedite);
1562 if (lpfc_ncmd == NULL) {
1563 atomic_inc(&lport->xmt_fcp_noxri);
1564 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1565 "6065 Fail IO, driver buffer pool is empty: "
1566 "idx %d DID %x\n",
1567 lpfc_queue_info->index, ndlp->nlp_DID);
1568 ret = -EBUSY;
1569 goto out_fail;
1570 }
1571#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1572 if (start) {
1573 lpfc_ncmd->ts_cmd_start = start;
1574 lpfc_ncmd->ts_last_cmd = phba->ktime_last_cmd;
1575 } else {
1576 lpfc_ncmd->ts_cmd_start = 0;
1577 }
1578#endif
1579
1580
1581
1582
1583
1584
1585
1586 freqpriv->nvme_buf = lpfc_ncmd;
1587 lpfc_ncmd->nvmeCmd = pnvme_fcreq;
1588 lpfc_ncmd->nrport = rport;
1589 lpfc_ncmd->ndlp = ndlp;
1590 lpfc_ncmd->start_time = jiffies;
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600 idx = lpfc_queue_info->index;
1601 lpfc_ncmd->cur_iocbq.hba_wqidx = idx;
1602 cstat = &lport->cstat[idx];
1603
1604 lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp, cstat);
1605 ret = lpfc_nvme_prep_io_dma(vport, lpfc_ncmd);
1606 if (ret) {
1607 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1608 "6175 Fail IO, Prep DMA: "
1609 "idx %d DID %x\n",
1610 lpfc_queue_info->index, ndlp->nlp_DID);
1611 atomic_inc(&lport->xmt_fcp_err);
1612 ret = -ENOMEM;
1613 goto out_free_nvme_buf;
1614 }
1615
1616 lpfc_nvmeio_data(phba, "NVME FCP XMIT: xri x%x idx %d to %06x\n",
1617 lpfc_ncmd->cur_iocbq.sli4_xritag,
1618 lpfc_queue_info->index, ndlp->nlp_DID);
1619
1620 ret = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, &lpfc_ncmd->cur_iocbq);
1621 if (ret) {
1622 atomic_inc(&lport->xmt_fcp_wqerr);
1623 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
1624 "6113 Fail IO, Could not issue WQE err %x "
1625 "sid: x%x did: x%x oxid: x%x\n",
1626 ret, vport->fc_myDID, ndlp->nlp_DID,
1627 lpfc_ncmd->cur_iocbq.sli4_xritag);
1628 goto out_free_nvme_buf;
1629 }
1630
1631#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1632 if (lpfc_ncmd->ts_cmd_start)
1633 lpfc_ncmd->ts_cmd_wqput = ktime_get_ns();
1634
1635 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) {
1636 lpfc_ncmd->cpu = smp_processor_id();
1637 if (lpfc_ncmd->cpu != lpfc_queue_info->index) {
1638
1639 if (lpfc_queue_info->qidx) {
1640 lpfc_printf_vlog(vport,
1641 KERN_ERR, LOG_NVME_IOERR,
1642 "6702 CPU Check cmd: "
1643 "cpu %d wq %d\n",
1644 lpfc_ncmd->cpu,
1645 lpfc_queue_info->index);
1646 }
1647 lpfc_ncmd->cpu = lpfc_queue_info->index;
1648 }
1649 if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT)
1650 phba->cpucheck_xmt_io[lpfc_ncmd->cpu]++;
1651 }
1652#endif
1653 return 0;
1654
1655 out_free_nvme_buf:
1656 if (lpfc_ncmd->nvmeCmd->sg_cnt) {
1657 if (lpfc_ncmd->nvmeCmd->io_dir == NVMEFC_FCP_WRITE)
1658 atomic_dec(&cstat->fc4NvmeOutputRequests);
1659 else
1660 atomic_dec(&cstat->fc4NvmeInputRequests);
1661 } else
1662 atomic_dec(&cstat->fc4NvmeControlRequests);
1663 lpfc_release_nvme_buf(phba, lpfc_ncmd);
1664 out_fail:
1665 return ret;
1666}
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679void
1680lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1681 struct lpfc_wcqe_complete *abts_cmpl)
1682{
1683 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
1684 "6145 ABORT_XRI_CN completing on rpi x%x "
1685 "original iotag x%x, abort cmd iotag x%x "
1686 "req_tag x%x, status x%x, hwstatus x%x\n",
1687 cmdiocb->iocb.un.acxri.abortContextTag,
1688 cmdiocb->iocb.un.acxri.abortIoTag,
1689 cmdiocb->iotag,
1690 bf_get(lpfc_wcqe_c_request_tag, abts_cmpl),
1691 bf_get(lpfc_wcqe_c_status, abts_cmpl),
1692 bf_get(lpfc_wcqe_c_hw_status, abts_cmpl));
1693 lpfc_sli_release_iocbq(phba, cmdiocb);
1694}
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713static void
1714lpfc_nvme_fcp_abort(struct nvme_fc_local_port *pnvme_lport,
1715 struct nvme_fc_remote_port *pnvme_rport,
1716 void *hw_queue_handle,
1717 struct nvmefc_fcp_req *pnvme_fcreq)
1718{
1719 struct lpfc_nvme_lport *lport;
1720 struct lpfc_vport *vport;
1721 struct lpfc_hba *phba;
1722 struct lpfc_nvme_buf *lpfc_nbuf;
1723 struct lpfc_iocbq *abts_buf;
1724 struct lpfc_iocbq *nvmereq_wqe;
1725 struct lpfc_nvme_fcpreq_priv *freqpriv;
1726 union lpfc_wqe128 *abts_wqe;
1727 unsigned long flags;
1728 int ret_val;
1729
1730
1731
1732
1733 lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
1734 if (unlikely(!lport))
1735 return;
1736
1737 vport = lport->vport;
1738
1739 if (unlikely(!hw_queue_handle)) {
1740 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1741 "6129 Fail Abort, HW Queue Handle NULL.\n");
1742 return;
1743 }
1744
1745 phba = vport->phba;
1746 freqpriv = pnvme_fcreq->private;
1747
1748 if (unlikely(!freqpriv))
1749 return;
1750 if (vport->load_flag & FC_UNLOADING)
1751 return;
1752
1753
1754 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1755 "6002 Abort Request to rport DID x%06x "
1756 "for nvme_fc_req %p\n",
1757 pnvme_rport->port_id,
1758 pnvme_fcreq);
1759
1760
1761
1762
1763 spin_lock_irqsave(&phba->hbalock, flags);
1764
1765 if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) {
1766 spin_unlock_irqrestore(&phba->hbalock, flags);
1767 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1768 "6139 Driver in reset cleanup - flushing "
1769 "NVME Req now. hba_flag x%x\n",
1770 phba->hba_flag);
1771 return;
1772 }
1773
1774 lpfc_nbuf = freqpriv->nvme_buf;
1775 if (!lpfc_nbuf) {
1776 spin_unlock_irqrestore(&phba->hbalock, flags);
1777 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1778 "6140 NVME IO req has no matching lpfc nvme "
1779 "io buffer. Skipping abort req.\n");
1780 return;
1781 } else if (!lpfc_nbuf->nvmeCmd) {
1782 spin_unlock_irqrestore(&phba->hbalock, flags);
1783 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1784 "6141 lpfc NVME IO req has no nvme_fcreq "
1785 "io buffer. Skipping abort req.\n");
1786 return;
1787 }
1788 nvmereq_wqe = &lpfc_nbuf->cur_iocbq;
1789
1790
1791
1792
1793
1794
1795
1796
1797 if (lpfc_nbuf->nvmeCmd != pnvme_fcreq) {
1798 spin_unlock_irqrestore(&phba->hbalock, flags);
1799 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1800 "6143 NVME req mismatch: "
1801 "lpfc_nbuf %p nvmeCmd %p, "
1802 "pnvme_fcreq %p. Skipping Abort xri x%x\n",
1803 lpfc_nbuf, lpfc_nbuf->nvmeCmd,
1804 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1805 return;
1806 }
1807
1808
1809 if (!(nvmereq_wqe->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
1810 spin_unlock_irqrestore(&phba->hbalock, flags);
1811 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1812 "6142 NVME IO req %p not queued - skipping "
1813 "abort req xri x%x\n",
1814 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1815 return;
1816 }
1817
1818 atomic_inc(&lport->xmt_fcp_abort);
1819 lpfc_nvmeio_data(phba, "NVME FCP ABORT: xri x%x idx %d to %06x\n",
1820 nvmereq_wqe->sli4_xritag,
1821 nvmereq_wqe->hba_wqidx, pnvme_rport->port_id);
1822
1823
1824 if (nvmereq_wqe->iocb_flag & LPFC_DRIVER_ABORTED) {
1825 spin_unlock_irqrestore(&phba->hbalock, flags);
1826 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1827 "6144 Outstanding NVME I/O Abort Request "
1828 "still pending on nvme_fcreq %p, "
1829 "lpfc_ncmd %p xri x%x\n",
1830 pnvme_fcreq, lpfc_nbuf,
1831 nvmereq_wqe->sli4_xritag);
1832 return;
1833 }
1834
1835 abts_buf = __lpfc_sli_get_iocbq(phba);
1836 if (!abts_buf) {
1837 spin_unlock_irqrestore(&phba->hbalock, flags);
1838 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1839 "6136 No available abort wqes. Skipping "
1840 "Abts req for nvme_fcreq %p xri x%x\n",
1841 pnvme_fcreq, nvmereq_wqe->sli4_xritag);
1842 return;
1843 }
1844
1845
1846 nvmereq_wqe->iocb_flag |= LPFC_DRIVER_ABORTED;
1847
1848
1849 abts_wqe = &abts_buf->wqe;
1850
1851
1852
1853
1854 memset(abts_wqe, 0, sizeof(union lpfc_wqe));
1855 bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG);
1856
1857
1858 bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0);
1859 bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
1860 bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com,
1861 nvmereq_wqe->iocb.ulpClass);
1862
1863
1864
1865
1866 abts_wqe->abort_cmd.wqe_com.abort_tag = nvmereq_wqe->sli4_xritag;
1867
1868
1869 bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com,
1870 abts_buf->iotag);
1871
1872
1873 bf_set(wqe_wqid, &abts_wqe->abort_cmd.wqe_com, nvmereq_wqe->hba_wqidx);
1874 bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1);
1875 bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
1876
1877
1878 bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND);
1879 bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1);
1880 bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
1881
1882
1883 abts_buf->iocb_flag |= LPFC_IO_NVME;
1884 abts_buf->hba_wqidx = nvmereq_wqe->hba_wqidx;
1885 abts_buf->vport = vport;
1886 abts_buf->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl;
1887 ret_val = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_buf);
1888 spin_unlock_irqrestore(&phba->hbalock, flags);
1889 if (ret_val) {
1890 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS,
1891 "6137 Failed abts issue_wqe with status x%x "
1892 "for nvme_fcreq %p.\n",
1893 ret_val, pnvme_fcreq);
1894 lpfc_sli_release_iocbq(phba, abts_buf);
1895 return;
1896 }
1897
1898 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS,
1899 "6138 Transport Abort NVME Request Issued for "
1900 "ox_id x%x on reqtag x%x\n",
1901 nvmereq_wqe->sli4_xritag,
1902 abts_buf->iotag);
1903}
1904
1905
1906static struct nvme_fc_port_template lpfc_nvme_template = {
1907
1908 .localport_delete = lpfc_nvme_localport_delete,
1909 .remoteport_delete = lpfc_nvme_remoteport_delete,
1910 .create_queue = lpfc_nvme_create_queue,
1911 .delete_queue = lpfc_nvme_delete_queue,
1912 .ls_req = lpfc_nvme_ls_req,
1913 .fcp_io = lpfc_nvme_fcp_io_submit,
1914 .ls_abort = lpfc_nvme_ls_abort,
1915 .fcp_abort = lpfc_nvme_fcp_abort,
1916
1917 .max_hw_queues = 1,
1918 .max_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1919 .max_dif_sgl_segments = LPFC_NVME_DEFAULT_SEGS,
1920 .dma_boundary = 0xFFFFFFFF,
1921
1922
1923
1924
1925 .local_priv_sz = sizeof(struct lpfc_nvme_lport),
1926 .remote_priv_sz = sizeof(struct lpfc_nvme_rport),
1927 .lsrqst_priv_sz = 0,
1928 .fcprqst_priv_sz = sizeof(struct lpfc_nvme_fcpreq_priv),
1929};
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942static int
1943lpfc_sli4_post_nvme_sgl_block(struct lpfc_hba *phba,
1944 struct list_head *nblist,
1945 int count)
1946{
1947 struct lpfc_nvme_buf *lpfc_ncmd;
1948 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
1949 struct sgl_page_pairs *sgl_pg_pairs;
1950 void *viraddr;
1951 LPFC_MBOXQ_t *mbox;
1952 uint32_t reqlen, alloclen, pg_pairs;
1953 uint32_t mbox_tmo;
1954 uint16_t xritag_start = 0;
1955 int rc = 0;
1956 uint32_t shdr_status, shdr_add_status;
1957 dma_addr_t pdma_phys_bpl1;
1958 union lpfc_sli4_cfg_shdr *shdr;
1959
1960
1961 reqlen = count * sizeof(struct sgl_page_pairs) +
1962 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
1963 if (reqlen > SLI4_PAGE_SIZE) {
1964 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1965 "6118 Block sgl registration required DMA "
1966 "size (%d) great than a page\n", reqlen);
1967 return -ENOMEM;
1968 }
1969 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1970 if (!mbox) {
1971 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1972 "6119 Failed to allocate mbox cmd memory\n");
1973 return -ENOMEM;
1974 }
1975
1976
1977 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1978 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
1979 LPFC_SLI4_MBX_NEMBED);
1980
1981 if (alloclen < reqlen) {
1982 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1983 "6120 Allocated DMA memory size (%d) is "
1984 "less than the requested DMA memory "
1985 "size (%d)\n", alloclen, reqlen);
1986 lpfc_sli4_mbox_cmd_free(phba, mbox);
1987 return -ENOMEM;
1988 }
1989
1990
1991 viraddr = mbox->sge_array->addr[0];
1992
1993
1994 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
1995 sgl_pg_pairs = &sgl->sgl_pg_pairs;
1996
1997 pg_pairs = 0;
1998 list_for_each_entry(lpfc_ncmd, nblist, list) {
1999
2000 sgl_pg_pairs->sgl_pg0_addr_lo =
2001 cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
2002 sgl_pg_pairs->sgl_pg0_addr_hi =
2003 cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
2004 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
2005 pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
2006 SGL_PAGE_SIZE;
2007 else
2008 pdma_phys_bpl1 = 0;
2009 sgl_pg_pairs->sgl_pg1_addr_lo =
2010 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
2011 sgl_pg_pairs->sgl_pg1_addr_hi =
2012 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
2013
2014 if (pg_pairs == 0)
2015 xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
2016 sgl_pg_pairs++;
2017 pg_pairs++;
2018 }
2019 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
2020 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
2021
2022 sgl->word0 = cpu_to_le32(sgl->word0);
2023
2024 if (!phba->sli4_hba.intr_enable)
2025 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
2026 else {
2027 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
2028 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
2029 }
2030 shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
2031 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2032 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2033 if (rc != MBX_TIMEOUT)
2034 lpfc_sli4_mbox_cmd_free(phba, mbox);
2035 if (shdr_status || shdr_add_status || rc) {
2036 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2037 "6125 POST_SGL_BLOCK mailbox command failed "
2038 "status x%x add_status x%x mbx status x%x\n",
2039 shdr_status, shdr_add_status, rc);
2040 rc = -ENXIO;
2041 }
2042 return rc;
2043}
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059static int
2060lpfc_post_nvme_sgl_list(struct lpfc_hba *phba,
2061 struct list_head *post_nblist, int sb_count)
2062{
2063 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
2064 int status, sgl_size;
2065 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
2066 dma_addr_t pdma_phys_sgl1;
2067 int last_xritag = NO_XRI;
2068 int cur_xritag;
2069 LIST_HEAD(prep_nblist);
2070 LIST_HEAD(blck_nblist);
2071 LIST_HEAD(nvme_nblist);
2072
2073
2074 if (sb_count <= 0)
2075 return -EINVAL;
2076
2077 sgl_size = phba->cfg_sg_dma_buf_size;
2078
2079 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
2080 list_del_init(&lpfc_ncmd->list);
2081 block_cnt++;
2082 if ((last_xritag != NO_XRI) &&
2083 (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
2084
2085 list_splice_init(&prep_nblist, &blck_nblist);
2086 post_cnt = block_cnt - 1;
2087
2088 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
2089 block_cnt = 1;
2090 } else {
2091
2092 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
2093
2094 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
2095 list_splice_init(&prep_nblist, &blck_nblist);
2096 post_cnt = block_cnt;
2097 block_cnt = 0;
2098 }
2099 }
2100 num_posting++;
2101 last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
2102
2103
2104 if (num_posting == sb_count) {
2105 if (post_cnt == 0) {
2106
2107 list_splice_init(&prep_nblist, &blck_nblist);
2108 post_cnt = block_cnt;
2109 } else if (block_cnt == 1) {
2110
2111 if (sgl_size > SGL_PAGE_SIZE)
2112 pdma_phys_sgl1 =
2113 lpfc_ncmd->dma_phys_sgl +
2114 SGL_PAGE_SIZE;
2115 else
2116 pdma_phys_sgl1 = 0;
2117 cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
2118 status = lpfc_sli4_post_sgl(phba,
2119 lpfc_ncmd->dma_phys_sgl,
2120 pdma_phys_sgl1, cur_xritag);
2121 if (status) {
2122
2123 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
2124 } else {
2125
2126 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2127 lpfc_ncmd->status = IOSTAT_SUCCESS;
2128 num_posted++;
2129 }
2130
2131 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
2132 }
2133 }
2134
2135
2136 if (post_cnt == 0)
2137 continue;
2138
2139
2140 status = lpfc_sli4_post_nvme_sgl_block(phba, &blck_nblist,
2141 post_cnt);
2142
2143
2144 if (block_cnt == 0)
2145 last_xritag = NO_XRI;
2146
2147
2148 post_cnt = 0;
2149
2150
2151 while (!list_empty(&blck_nblist)) {
2152 list_remove_head(&blck_nblist, lpfc_ncmd,
2153 struct lpfc_nvme_buf, list);
2154 if (status) {
2155
2156 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
2157 } else {
2158
2159 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2160 lpfc_ncmd->status = IOSTAT_SUCCESS;
2161 num_posted++;
2162 }
2163 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
2164 }
2165 }
2166
2167 while (!list_empty(&nvme_nblist)) {
2168 list_remove_head(&nvme_nblist, lpfc_ncmd,
2169 struct lpfc_nvme_buf, list);
2170 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2171 }
2172 return num_posted;
2173}
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187int
2188lpfc_repost_nvme_sgl_list(struct lpfc_hba *phba)
2189{
2190 LIST_HEAD(post_nblist);
2191 int num_posted, rc = 0;
2192
2193
2194 spin_lock_irq(&phba->nvme_buf_list_get_lock);
2195 spin_lock(&phba->nvme_buf_list_put_lock);
2196 list_splice_init(&phba->lpfc_nvme_buf_list_get, &post_nblist);
2197 list_splice(&phba->lpfc_nvme_buf_list_put, &post_nblist);
2198 phba->get_nvme_bufs = 0;
2199 phba->put_nvme_bufs = 0;
2200 spin_unlock(&phba->nvme_buf_list_put_lock);
2201 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
2202
2203
2204 if (!list_empty(&post_nblist)) {
2205 num_posted = lpfc_post_nvme_sgl_list(phba, &post_nblist,
2206 phba->sli4_hba.nvme_xri_cnt);
2207
2208 if (num_posted == 0)
2209 rc = -EIO;
2210 }
2211 return rc;
2212}
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228static int
2229lpfc_new_nvme_buf(struct lpfc_vport *vport, int num_to_alloc)
2230{
2231 struct lpfc_hba *phba = vport->phba;
2232 struct lpfc_nvme_buf *lpfc_ncmd;
2233 struct lpfc_iocbq *pwqeq;
2234 union lpfc_wqe128 *wqe;
2235 struct sli4_sge *sgl;
2236 dma_addr_t pdma_phys_sgl;
2237 uint16_t iotag, lxri = 0;
2238 int bcnt, num_posted, sgl_size;
2239 LIST_HEAD(prep_nblist);
2240 LIST_HEAD(post_nblist);
2241 LIST_HEAD(nvme_nblist);
2242
2243 sgl_size = phba->cfg_sg_dma_buf_size;
2244
2245 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
2246 lpfc_ncmd = kzalloc(sizeof(struct lpfc_nvme_buf), GFP_KERNEL);
2247 if (!lpfc_ncmd)
2248 break;
2249
2250
2251
2252
2253
2254 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
2255 GFP_KERNEL,
2256 &lpfc_ncmd->dma_handle);
2257 if (!lpfc_ncmd->data) {
2258 kfree(lpfc_ncmd);
2259 break;
2260 }
2261
2262 lxri = lpfc_sli4_next_xritag(phba);
2263 if (lxri == NO_XRI) {
2264 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
2265 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
2266 kfree(lpfc_ncmd);
2267 break;
2268 }
2269 pwqeq = &(lpfc_ncmd->cur_iocbq);
2270 wqe = &pwqeq->wqe;
2271
2272
2273 iotag = lpfc_sli_next_iotag(phba, pwqeq);
2274 if (iotag == 0) {
2275 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
2276 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
2277 kfree(lpfc_ncmd);
2278 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
2279 "6121 Failed to allocated IOTAG for"
2280 " XRI:0x%x\n", lxri);
2281 lpfc_sli4_free_xri(phba, lxri);
2282 break;
2283 }
2284 pwqeq->sli4_lxritag = lxri;
2285 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
2286 pwqeq->iocb_flag |= LPFC_IO_NVME;
2287 pwqeq->context1 = lpfc_ncmd;
2288 pwqeq->wqe_cmpl = lpfc_nvme_io_cmd_wqe_cmpl;
2289
2290
2291 lpfc_ncmd->nvme_sgl = lpfc_ncmd->data;
2292 sgl = lpfc_ncmd->nvme_sgl;
2293 pdma_phys_sgl = lpfc_ncmd->dma_handle;
2294 lpfc_ncmd->dma_phys_sgl = pdma_phys_sgl;
2295
2296
2297
2298
2299
2300 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP);
2301 bf_set(lpfc_sli4_sge_last, sgl, 0);
2302 sgl->word2 = cpu_to_le32(sgl->word2);
2303
2304
2305 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
2306
2307
2308 memset(wqe, 0, sizeof(union lpfc_wqe));
2309
2310
2311 list_add_tail(&lpfc_ncmd->list, &post_nblist);
2312 spin_lock_irq(&phba->nvme_buf_list_get_lock);
2313 phba->sli4_hba.nvme_xri_cnt++;
2314 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
2315 }
2316 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
2317 "6114 Allocate %d out of %d requested new NVME "
2318 "buffers\n", bcnt, num_to_alloc);
2319
2320
2321 if (!list_empty(&post_nblist))
2322 num_posted = lpfc_post_nvme_sgl_list(phba,
2323 &post_nblist, bcnt);
2324 else
2325 num_posted = 0;
2326
2327 return num_posted;
2328}
2329
2330static inline struct lpfc_nvme_buf *
2331lpfc_nvme_buf(struct lpfc_hba *phba)
2332{
2333 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
2334
2335 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
2336 &phba->lpfc_nvme_buf_list_get, list) {
2337 list_del_init(&lpfc_ncmd->list);
2338 phba->get_nvme_bufs--;
2339 return lpfc_ncmd;
2340 }
2341 return NULL;
2342}
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355static struct lpfc_nvme_buf *
2356lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
2357 int expedite)
2358{
2359 struct lpfc_nvme_buf *lpfc_ncmd = NULL;
2360 unsigned long iflag = 0;
2361
2362 spin_lock_irqsave(&phba->nvme_buf_list_get_lock, iflag);
2363 if (phba->get_nvme_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
2364 lpfc_ncmd = lpfc_nvme_buf(phba);
2365 if (!lpfc_ncmd) {
2366 spin_lock(&phba->nvme_buf_list_put_lock);
2367 list_splice(&phba->lpfc_nvme_buf_list_put,
2368 &phba->lpfc_nvme_buf_list_get);
2369 phba->get_nvme_bufs += phba->put_nvme_bufs;
2370 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
2371 phba->put_nvme_bufs = 0;
2372 spin_unlock(&phba->nvme_buf_list_put_lock);
2373 if (phba->get_nvme_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
2374 lpfc_ncmd = lpfc_nvme_buf(phba);
2375 }
2376 spin_unlock_irqrestore(&phba->nvme_buf_list_get_lock, iflag);
2377
2378 if (lpfc_ndlp_check_qdepth(phba, ndlp) && lpfc_ncmd) {
2379 atomic_inc(&ndlp->cmd_pending);
2380 lpfc_ncmd->flags |= LPFC_BUMP_QDEPTH;
2381 }
2382 return lpfc_ncmd;
2383}
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395static void
2396lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_nvme_buf *lpfc_ncmd)
2397{
2398 unsigned long iflag = 0;
2399
2400 if ((lpfc_ncmd->flags & LPFC_BUMP_QDEPTH) && lpfc_ncmd->ndlp)
2401 atomic_dec(&lpfc_ncmd->ndlp->cmd_pending);
2402
2403 lpfc_ncmd->nonsg_phys = 0;
2404 lpfc_ncmd->ndlp = NULL;
2405 lpfc_ncmd->flags &= ~LPFC_BUMP_QDEPTH;
2406
2407 if (lpfc_ncmd->flags & LPFC_SBUF_XBUSY) {
2408 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2409 "6310 XB release deferred for "
2410 "ox_id x%x on reqtag x%x\n",
2411 lpfc_ncmd->cur_iocbq.sli4_xritag,
2412 lpfc_ncmd->cur_iocbq.iotag);
2413
2414 spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock,
2415 iflag);
2416 list_add_tail(&lpfc_ncmd->list,
2417 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
2418 spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock,
2419 iflag);
2420 } else {
2421 lpfc_ncmd->nvmeCmd = NULL;
2422 lpfc_ncmd->cur_iocbq.iocb_flag = LPFC_IO_NVME;
2423 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
2424 list_add_tail(&lpfc_ncmd->list, &phba->lpfc_nvme_buf_list_put);
2425 phba->put_nvme_bufs++;
2426 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
2427 }
2428}
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446int
2447lpfc_nvme_create_localport(struct lpfc_vport *vport)
2448{
2449 int ret = 0;
2450 struct lpfc_hba *phba = vport->phba;
2451 struct nvme_fc_port_info nfcp_info;
2452 struct nvme_fc_local_port *localport;
2453 struct lpfc_nvme_lport *lport;
2454 struct lpfc_nvme_ctrl_stat *cstat;
2455 int len, i;
2456
2457
2458
2459
2460 memset(&nfcp_info, 0, sizeof(struct nvme_fc_port_info));
2461 nfcp_info.port_role = FC_PORT_ROLE_NVME_INITIATOR;
2462 nfcp_info.node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
2463 nfcp_info.port_name = wwn_to_u64(vport->fc_portname.u.wwn);
2464
2465
2466
2467
2468 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
2469 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_INIT,
2470 "6300 Reducing sg segment cnt to %d\n",
2471 LPFC_MAX_NVME_SEG_CNT);
2472 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
2473 } else {
2474 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
2475 }
2476 lpfc_nvme_template.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1;
2477 lpfc_nvme_template.max_hw_queues = phba->cfg_nvme_io_channel;
2478
2479 cstat = kmalloc((sizeof(struct lpfc_nvme_ctrl_stat) *
2480 phba->cfg_nvme_io_channel), GFP_KERNEL);
2481 if (!cstat)
2482 return -ENOMEM;
2483
2484
2485
2486
2487#if (IS_ENABLED(CONFIG_NVME_FC))
2488 ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template,
2489 &vport->phba->pcidev->dev, &localport);
2490#else
2491 ret = -ENOMEM;
2492#endif
2493 if (!ret) {
2494 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC,
2495 "6005 Successfully registered local "
2496 "NVME port num %d, localP %p, private %p, "
2497 "sg_seg %d\n",
2498 localport->port_num, localport,
2499 localport->private,
2500 lpfc_nvme_template.max_sgl_segments);
2501
2502
2503 lport = (struct lpfc_nvme_lport *)localport->private;
2504 vport->localport = localport;
2505 lport->vport = vport;
2506 lport->cstat = cstat;
2507 vport->nvmei_support = 1;
2508
2509 atomic_set(&lport->xmt_fcp_noxri, 0);
2510 atomic_set(&lport->xmt_fcp_bad_ndlp, 0);
2511 atomic_set(&lport->xmt_fcp_qdepth, 0);
2512 atomic_set(&lport->xmt_fcp_err, 0);
2513 atomic_set(&lport->xmt_fcp_wqerr, 0);
2514 atomic_set(&lport->xmt_fcp_abort, 0);
2515 atomic_set(&lport->xmt_ls_abort, 0);
2516 atomic_set(&lport->xmt_ls_err, 0);
2517 atomic_set(&lport->cmpl_fcp_xb, 0);
2518 atomic_set(&lport->cmpl_fcp_err, 0);
2519 atomic_set(&lport->cmpl_ls_xb, 0);
2520 atomic_set(&lport->cmpl_ls_err, 0);
2521 atomic_set(&lport->fc4NvmeLsRequests, 0);
2522 atomic_set(&lport->fc4NvmeLsCmpls, 0);
2523
2524 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
2525 cstat = &lport->cstat[i];
2526 atomic_set(&cstat->fc4NvmeInputRequests, 0);
2527 atomic_set(&cstat->fc4NvmeOutputRequests, 0);
2528 atomic_set(&cstat->fc4NvmeControlRequests, 0);
2529 atomic_set(&cstat->fc4NvmeIoCmpls, 0);
2530 }
2531
2532
2533
2534
2535 if (phba->sli4_hba.nvme_xri_cnt == 0) {
2536 len = lpfc_new_nvme_buf(vport,
2537 phba->sli4_hba.nvme_xri_max);
2538 vport->phba->total_nvme_bufs += len;
2539 }
2540 } else {
2541 kfree(cstat);
2542 }
2543
2544 return ret;
2545}
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557void
2558lpfc_nvme_lport_unreg_wait(struct lpfc_vport *vport,
2559 struct lpfc_nvme_lport *lport)
2560{
2561#if (IS_ENABLED(CONFIG_NVME_FC))
2562 u32 wait_tmo;
2563 int ret;
2564
2565
2566
2567
2568
2569 wait_tmo = msecs_to_jiffies(LPFC_NVME_WAIT_TMO * 1000);
2570 while (true) {
2571 ret = wait_for_completion_timeout(&lport->lport_unreg_done,
2572 wait_tmo);
2573 if (unlikely(!ret)) {
2574 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR,
2575 "6176 Lport %p Localport %p wait "
2576 "timed out. Renewing.\n",
2577 lport, vport->localport);
2578 continue;
2579 }
2580 break;
2581 }
2582 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR,
2583 "6177 Lport %p Localport %p Complete Success\n",
2584 lport, vport->localport);
2585#endif
2586}
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598void
2599lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2600{
2601#if (IS_ENABLED(CONFIG_NVME_FC))
2602 struct nvme_fc_local_port *localport;
2603 struct lpfc_nvme_lport *lport;
2604 struct lpfc_nvme_ctrl_stat *cstat;
2605 int ret;
2606
2607 if (vport->nvmei_support == 0)
2608 return;
2609
2610 localport = vport->localport;
2611 vport->localport = NULL;
2612 lport = (struct lpfc_nvme_lport *)localport->private;
2613 cstat = lport->cstat;
2614
2615 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2616 "6011 Destroying NVME localport %p\n",
2617 localport);
2618
2619
2620
2621
2622 init_completion(&lport->lport_unreg_done);
2623 ret = nvme_fc_unregister_localport(localport);
2624
2625
2626
2627
2628 lpfc_nvme_lport_unreg_wait(vport, lport);
2629 kfree(cstat);
2630
2631
2632
2633
2634
2635 vport->nvmei_support = 0;
2636 if (ret == 0) {
2637 lpfc_printf_vlog(vport,
2638 KERN_INFO, LOG_NVME_DISC,
2639 "6009 Unregistered lport Success\n");
2640 } else {
2641 lpfc_printf_vlog(vport,
2642 KERN_INFO, LOG_NVME_DISC,
2643 "6010 Unregistered lport "
2644 "Failed, status x%x\n",
2645 ret);
2646 }
2647#endif
2648}
2649
2650void
2651lpfc_nvme_update_localport(struct lpfc_vport *vport)
2652{
2653#if (IS_ENABLED(CONFIG_NVME_FC))
2654 struct nvme_fc_local_port *localport;
2655 struct lpfc_nvme_lport *lport;
2656
2657 localport = vport->localport;
2658 if (!localport) {
2659 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2660 "6710 Update NVME fail. No localport\n");
2661 return;
2662 }
2663 lport = (struct lpfc_nvme_lport *)localport->private;
2664 if (!lport) {
2665 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME,
2666 "6171 Update NVME fail. localP %p, No lport\n",
2667 localport);
2668 return;
2669 }
2670 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2671 "6012 Update NVME lport %p did x%x\n",
2672 localport, vport->fc_myDID);
2673
2674 localport->port_id = vport->fc_myDID;
2675 if (localport->port_id == 0)
2676 localport->port_role = FC_PORT_ROLE_NVME_DISCOVERY;
2677 else
2678 localport->port_role = FC_PORT_ROLE_NVME_INITIATOR;
2679
2680 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2681 "6030 bound lport %p to DID x%06x\n",
2682 lport, localport->port_id);
2683#endif
2684}
2685
2686int
2687lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2688{
2689#if (IS_ENABLED(CONFIG_NVME_FC))
2690 int ret = 0;
2691 struct nvme_fc_local_port *localport;
2692 struct lpfc_nvme_lport *lport;
2693 struct lpfc_nvme_rport *rport;
2694 struct lpfc_nvme_rport *oldrport;
2695 struct nvme_fc_remote_port *remote_port;
2696 struct nvme_fc_port_info rpinfo;
2697 struct lpfc_nodelist *prev_ndlp = NULL;
2698
2699 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC,
2700 "6006 Register NVME PORT. DID x%06x nlptype x%x\n",
2701 ndlp->nlp_DID, ndlp->nlp_type);
2702
2703 localport = vport->localport;
2704 if (!localport)
2705 return 0;
2706
2707 lport = (struct lpfc_nvme_lport *)localport->private;
2708
2709
2710
2711
2712
2713
2714
2715 memset(&rpinfo, 0, sizeof(struct nvme_fc_port_info));
2716 rpinfo.port_id = ndlp->nlp_DID;
2717 if (ndlp->nlp_type & NLP_NVME_TARGET)
2718 rpinfo.port_role |= FC_PORT_ROLE_NVME_TARGET;
2719 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
2720 rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR;
2721
2722 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
2723 rpinfo.port_role |= FC_PORT_ROLE_NVME_DISCOVERY;
2724
2725 rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
2726 rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
2727
2728 spin_lock_irq(&vport->phba->hbalock);
2729 oldrport = lpfc_ndlp_get_nrport(ndlp);
2730 spin_unlock_irq(&vport->phba->hbalock);
2731 if (!oldrport)
2732 lpfc_nlp_get(ndlp);
2733
2734 ret = nvme_fc_register_remoteport(localport, &rpinfo, &remote_port);
2735 if (!ret) {
2736
2737
2738
2739
2740
2741
2742
2743 spin_lock_irq(&vport->phba->hbalock);
2744 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
2745 spin_unlock_irq(&vport->phba->hbalock);
2746 rport = remote_port->private;
2747 if (oldrport) {
2748
2749
2750
2751 prev_ndlp = oldrport->ndlp;
2752 if (oldrport == remote_port->private) {
2753
2754
2755
2756 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2757 LOG_NVME_DISC,
2758 "6014 Rebinding lport to "
2759 "remoteport %p wwpn 0x%llx, "
2760 "Data: x%x x%x %p %p x%x x%06x\n",
2761 remote_port,
2762 remote_port->port_name,
2763 remote_port->port_id,
2764 remote_port->port_role,
2765 prev_ndlp,
2766 ndlp,
2767 ndlp->nlp_type,
2768 ndlp->nlp_DID);
2769 return 0;
2770 }
2771
2772
2773
2774
2775
2776 spin_lock_irq(&vport->phba->hbalock);
2777 ndlp->nrport = NULL;
2778 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
2779 spin_unlock_irq(&vport->phba->hbalock);
2780 rport->ndlp = NULL;
2781 rport->remoteport = NULL;
2782
2783
2784
2785
2786
2787 if (prev_ndlp && prev_ndlp != ndlp) {
2788 if ((!NLP_CHK_NODE_ACT(prev_ndlp)) ||
2789 (!prev_ndlp->nrport))
2790 lpfc_nlp_put(prev_ndlp);
2791 }
2792 }
2793
2794
2795 rport->remoteport = remote_port;
2796 rport->lport = lport;
2797 rport->ndlp = ndlp;
2798 spin_lock_irq(&vport->phba->hbalock);
2799 ndlp->nrport = rport;
2800 spin_unlock_irq(&vport->phba->hbalock);
2801 lpfc_printf_vlog(vport, KERN_INFO,
2802 LOG_NVME_DISC | LOG_NODE,
2803 "6022 Binding new rport to "
2804 "lport %p Remoteport %p rport %p WWNN 0x%llx, "
2805 "Rport WWPN 0x%llx DID "
2806 "x%06x Role x%x, ndlp %p prev_ndlp %p\n",
2807 lport, remote_port, rport,
2808 rpinfo.node_name, rpinfo.port_name,
2809 rpinfo.port_id, rpinfo.port_role,
2810 ndlp, prev_ndlp);
2811 } else {
2812 lpfc_printf_vlog(vport, KERN_ERR,
2813 LOG_NVME_DISC | LOG_NODE,
2814 "6031 RemotePort Registration failed "
2815 "err: %d, DID x%06x\n",
2816 ret, ndlp->nlp_DID);
2817 }
2818
2819 return ret;
2820#else
2821 return 0;
2822#endif
2823}
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837void
2838lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2839{
2840#if (IS_ENABLED(CONFIG_NVME_FC))
2841 int ret;
2842 struct nvme_fc_local_port *localport;
2843 struct lpfc_nvme_lport *lport;
2844 struct lpfc_nvme_rport *rport;
2845 struct nvme_fc_remote_port *remoteport = NULL;
2846
2847 localport = vport->localport;
2848
2849
2850
2851
2852 if (!localport)
2853 return;
2854
2855 lport = (struct lpfc_nvme_lport *)localport->private;
2856 if (!lport)
2857 goto input_err;
2858
2859 spin_lock_irq(&vport->phba->hbalock);
2860 rport = lpfc_ndlp_get_nrport(ndlp);
2861 if (rport)
2862 remoteport = rport->remoteport;
2863 spin_unlock_irq(&vport->phba->hbalock);
2864 if (!remoteport)
2865 goto input_err;
2866
2867 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2868 "6033 Unreg nvme remoteport %p, portname x%llx, "
2869 "port_id x%06x, portstate x%x port type x%x\n",
2870 remoteport, remoteport->port_name,
2871 remoteport->port_id, remoteport->port_state,
2872 ndlp->nlp_type);
2873
2874
2875
2876
2877
2878 if (ndlp->nlp_type & NLP_NVME_TARGET) {
2879
2880
2881
2882 ndlp->upcall_flags |= NLP_WAIT_FOR_UNREG;
2883
2884
2885
2886
2887
2888
2889 if (vport->load_flag & FC_UNLOADING)
2890 (void)nvme_fc_set_remoteport_devloss(remoteport, 0);
2891
2892 ret = nvme_fc_unregister_remoteport(remoteport);
2893 if (ret != 0) {
2894 lpfc_nlp_put(ndlp);
2895 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2896 "6167 NVME unregister failed %d "
2897 "port_state x%x\n",
2898 ret, remoteport->port_state);
2899 }
2900 }
2901 return;
2902
2903 input_err:
2904#endif
2905 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2906 "6168 State error: lport %p, rport%p FCID x%06x\n",
2907 vport->localport, ndlp->rport, ndlp->nlp_DID);
2908}
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919void
2920lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba,
2921 struct sli4_wcqe_xri_aborted *axri)
2922{
2923 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
2924 struct lpfc_nvme_buf *lpfc_ncmd, *next_lpfc_ncmd;
2925 struct nvmefc_fcp_req *nvme_cmd = NULL;
2926 struct lpfc_nodelist *ndlp;
2927 unsigned long iflag = 0;
2928
2929 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
2930 return;
2931 spin_lock_irqsave(&phba->hbalock, iflag);
2932 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2933 list_for_each_entry_safe(lpfc_ncmd, next_lpfc_ncmd,
2934 &phba->sli4_hba.lpfc_abts_nvme_buf_list,
2935 list) {
2936 if (lpfc_ncmd->cur_iocbq.sli4_xritag == xri) {
2937 list_del_init(&lpfc_ncmd->list);
2938 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2939 lpfc_ncmd->status = IOSTAT_SUCCESS;
2940 spin_unlock(
2941 &phba->sli4_hba.abts_nvme_buf_list_lock);
2942
2943 spin_unlock_irqrestore(&phba->hbalock, iflag);
2944 ndlp = lpfc_ncmd->ndlp;
2945 if (ndlp)
2946 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
2947
2948 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2949 "6311 nvme_cmd %p xri x%x tag x%x "
2950 "abort complete and xri released\n",
2951 lpfc_ncmd->nvmeCmd, xri,
2952 lpfc_ncmd->cur_iocbq.iotag);
2953
2954
2955
2956
2957
2958 if (lpfc_ncmd->nvmeCmd) {
2959 nvme_cmd = lpfc_ncmd->nvmeCmd;
2960 nvme_cmd->done(nvme_cmd);
2961 lpfc_ncmd->nvmeCmd = NULL;
2962 }
2963 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2964 return;
2965 }
2966 }
2967 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2968 spin_unlock_irqrestore(&phba->hbalock, iflag);
2969
2970 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2971 "6312 XRI Aborted xri x%x not found\n", xri);
2972
2973}
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985void
2986lpfc_nvme_wait_for_io_drain(struct lpfc_hba *phba)
2987{
2988 struct lpfc_sli_ring *pring;
2989 u32 i, wait_cnt = 0;
2990
2991 if (phba->sli_rev < LPFC_SLI_REV4 || !phba->sli4_hba.nvme_wq)
2992 return;
2993
2994
2995
2996
2997 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
2998 pring = phba->sli4_hba.nvme_wq[i]->pring;
2999
3000 if (!pring)
3001 continue;
3002
3003
3004 while (!list_empty(&pring->txcmplq)) {
3005 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
3006 wait_cnt++;
3007
3008
3009
3010
3011 if ((wait_cnt % 1000) == 0) {
3012 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
3013 "6178 NVME IO not empty, "
3014 "cnt %d\n", wait_cnt);
3015 }
3016 }
3017 }
3018}
3019