1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channsel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 ********************************************************************/
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
26 #include <linux/delay.h>
27 #include <asm/unaligned.h>
28 #include <linux/crc-t10dif.h>
29 #include <net/checksum.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_eh.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_tcq.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
39 #include <../drivers/nvme/host/nvme.h>
40 #include <linux/nvme-fc-driver.h>
42 #include "lpfc_version.h"
46 #include "lpfc_sli4.h"
48 #include "lpfc_disc.h"
50 #include "lpfc_scsi.h"
51 #include "lpfc_nvme.h"
52 #include "lpfc_nvmet.h"
53 #include "lpfc_logmsg.h"
54 #include "lpfc_crtn.h"
55 #include "lpfc_vport.h"
56 #include "lpfc_debugfs.h"
58 static struct lpfc_iocbq *lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *,
59 struct lpfc_nvmet_rcv_ctx *,
62 static struct lpfc_iocbq *lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *,
63 struct lpfc_nvmet_rcv_ctx *);
64 static int lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *,
65 struct lpfc_nvmet_rcv_ctx *,
67 static int lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *,
68 struct lpfc_nvmet_rcv_ctx *,
70 static int lpfc_nvmet_unsol_ls_issue_abort(struct lpfc_hba *,
71 struct lpfc_nvmet_rcv_ctx *,
75 lpfc_nvmet_defer_release(struct lpfc_hba *phba, struct lpfc_nvmet_rcv_ctx *ctxp)
79 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
80 "6313 NVMET Defer ctx release xri x%x flg x%x\n",
81 ctxp->oxid, ctxp->flag);
83 spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock, iflag);
84 if (ctxp->flag & LPFC_NVMET_CTX_RLS) {
85 spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock,
89 ctxp->flag |= LPFC_NVMET_CTX_RLS;
90 list_add_tail(&ctxp->list, &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
91 spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock, iflag);
95 * lpfc_nvmet_xmt_ls_rsp_cmp - Completion handler for LS Response
96 * @phba: Pointer to HBA context object.
97 * @cmdwqe: Pointer to driver command WQE object.
98 * @wcqe: Pointer to driver response CQE object.
100 * The function is called from SLI ring event handler with no
101 * lock held. This function is the completion handler for NVME LS commands
102 * The function frees memory resources used for the NVME commands.
105 lpfc_nvmet_xmt_ls_rsp_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
106 struct lpfc_wcqe_complete *wcqe)
108 struct lpfc_nvmet_tgtport *tgtp;
109 struct nvmefc_tgt_ls_req *rsp;
110 struct lpfc_nvmet_rcv_ctx *ctxp;
111 uint32_t status, result;
113 status = bf_get(lpfc_wcqe_c_status, wcqe);
114 result = wcqe->parameter;
115 ctxp = cmdwqe->context2;
117 if (ctxp->state != LPFC_NVMET_STE_LS_RSP || ctxp->entry_cnt != 2) {
118 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
119 "6410 NVMET LS cmpl state mismatch IO x%x: "
121 ctxp->oxid, ctxp->state, ctxp->entry_cnt);
124 if (!phba->targetport)
127 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
130 atomic_inc(&tgtp->xmt_ls_rsp_error);
132 atomic_inc(&tgtp->xmt_ls_rsp_cmpl);
135 rsp = &ctxp->ctx.ls_req;
137 lpfc_nvmeio_data(phba, "NVMET LS CMPL: xri x%x stat x%x result x%x\n",
138 ctxp->oxid, status, result);
140 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
141 "6038 NVMET LS rsp cmpl: %d %d oxid x%x\n",
142 status, result, ctxp->oxid);
144 lpfc_nlp_put(cmdwqe->context1);
145 cmdwqe->context2 = NULL;
146 cmdwqe->context3 = NULL;
147 lpfc_sli_release_iocbq(phba, cmdwqe);
153 * lpfc_nvmet_ctxbuf_post - Repost a NVMET RQ DMA buffer and clean up context
154 * @phba: HBA buffer is associated with
155 * @ctxp: context to clean up
156 * @mp: Buffer to free
158 * Description: Frees the given DMA buffer in the appropriate way given by
159 * reposting it to its associated RQ so it can be reused.
161 * Notes: Takes phba->hbalock. Can be called with or without other locks held.
166 lpfc_nvmet_ctxbuf_post(struct lpfc_hba *phba, struct lpfc_nvmet_ctxbuf *ctx_buf)
168 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
169 struct lpfc_nvmet_rcv_ctx *ctxp = ctx_buf->context;
170 struct lpfc_nvmet_tgtport *tgtp;
171 struct fc_frame_header *fc_hdr;
172 struct rqb_dmabuf *nvmebuf;
174 uint32_t size, oxid, sid, rc;
178 pci_pool_free(phba->txrdy_payload_pool, ctxp->txrdy,
181 ctxp->txrdy_phys = 0;
184 if (ctxp->state == LPFC_NVMET_STE_FREE) {
185 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
186 "6411 NVMET free, already free IO x%x: %d %d\n",
187 ctxp->oxid, ctxp->state, ctxp->entry_cnt);
189 ctxp->state = LPFC_NVMET_STE_FREE;
191 spin_lock_irqsave(&phba->sli4_hba.nvmet_io_wait_lock, iflag);
192 if (phba->sli4_hba.nvmet_io_wait_cnt) {
193 list_remove_head(&phba->sli4_hba.lpfc_nvmet_io_wait_list,
194 nvmebuf, struct rqb_dmabuf,
196 phba->sli4_hba.nvmet_io_wait_cnt--;
197 spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock,
200 fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt);
201 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
202 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
203 payload = (uint32_t *)(nvmebuf->dbuf.virt);
204 size = nvmebuf->bytes_recv;
205 sid = sli4_sid_from_fc_hdr(fc_hdr);
207 ctxp = (struct lpfc_nvmet_rcv_ctx *)ctx_buf->context;
215 ctxp->state = LPFC_NVMET_STE_RCV;
218 ctxp->ctxbuf = ctx_buf;
219 spin_lock_init(&ctxp->ctxlock);
221 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
222 if (phba->ktime_on) {
223 ctxp->ts_cmd_nvme = ktime_get_ns();
224 ctxp->ts_isr_cmd = ctxp->ts_cmd_nvme;
225 ctxp->ts_nvme_data = 0;
226 ctxp->ts_data_wqput = 0;
227 ctxp->ts_isr_data = 0;
228 ctxp->ts_data_nvme = 0;
229 ctxp->ts_nvme_status = 0;
230 ctxp->ts_status_wqput = 0;
231 ctxp->ts_isr_status = 0;
232 ctxp->ts_status_nvme = 0;
235 atomic_inc(&tgtp->rcv_fcp_cmd_in);
237 * The calling sequence should be:
238 * nvmet_fc_rcv_fcp_req->lpfc_nvmet_xmt_fcp_op/cmp- req->done
239 * lpfc_nvmet_xmt_fcp_op_cmp should free the allocated ctxp.
240 * When we return from nvmet_fc_rcv_fcp_req, all relevant info
241 * the NVME command / FC header is stored.
242 * A buffer has already been reposted for this IO, so just free
245 rc = nvmet_fc_rcv_fcp_req(phba->targetport, &ctxp->ctx.fcp_req,
248 /* Process FCP command */
250 atomic_inc(&tgtp->rcv_fcp_cmd_out);
251 nvmebuf->hrq->rqbp->rqb_free_buffer(phba, nvmebuf);
255 atomic_inc(&tgtp->rcv_fcp_cmd_drop);
256 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
257 "2582 FCP Drop IO x%x: err x%x: x%x x%x x%x\n",
259 atomic_read(&tgtp->rcv_fcp_cmd_in),
260 atomic_read(&tgtp->rcv_fcp_cmd_out),
261 atomic_read(&tgtp->xmt_fcp_release));
263 lpfc_nvmet_defer_release(phba, ctxp);
264 lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid);
265 nvmebuf->hrq->rqbp->rqb_free_buffer(phba, nvmebuf);
268 spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock, iflag);
270 spin_lock_irqsave(&phba->sli4_hba.nvmet_io_lock, iflag);
271 list_add_tail(&ctx_buf->list,
272 &phba->sli4_hba.lpfc_nvmet_ctx_list);
273 phba->sli4_hba.nvmet_ctx_cnt++;
274 spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_lock, iflag);
278 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
280 lpfc_nvmet_ktime(struct lpfc_hba *phba,
281 struct lpfc_nvmet_rcv_ctx *ctxp)
283 uint64_t seg1, seg2, seg3, seg4, seg5;
284 uint64_t seg6, seg7, seg8, seg9, seg10;
289 if (!ctxp->ts_isr_cmd || !ctxp->ts_cmd_nvme ||
290 !ctxp->ts_nvme_data || !ctxp->ts_data_wqput ||
291 !ctxp->ts_isr_data || !ctxp->ts_data_nvme ||
292 !ctxp->ts_nvme_status || !ctxp->ts_status_wqput ||
293 !ctxp->ts_isr_status || !ctxp->ts_status_nvme)
296 if (ctxp->ts_isr_cmd > ctxp->ts_cmd_nvme)
298 if (ctxp->ts_cmd_nvme > ctxp->ts_nvme_data)
300 if (ctxp->ts_nvme_data > ctxp->ts_data_wqput)
302 if (ctxp->ts_data_wqput > ctxp->ts_isr_data)
304 if (ctxp->ts_isr_data > ctxp->ts_data_nvme)
306 if (ctxp->ts_data_nvme > ctxp->ts_nvme_status)
308 if (ctxp->ts_nvme_status > ctxp->ts_status_wqput)
310 if (ctxp->ts_status_wqput > ctxp->ts_isr_status)
312 if (ctxp->ts_isr_status > ctxp->ts_status_nvme)
315 * Segment 1 - Time from FCP command received by MSI-X ISR
316 * to FCP command is passed to NVME Layer.
317 * Segment 2 - Time from FCP command payload handed
318 * off to NVME Layer to Driver receives a Command op
320 * Segment 3 - Time from Driver receives a Command op
321 * from NVME Layer to Command is put on WQ.
322 * Segment 4 - Time from Driver WQ put is done
323 * to MSI-X ISR for Command cmpl.
324 * Segment 5 - Time from MSI-X ISR for Command cmpl to
325 * Command cmpl is passed to NVME Layer.
326 * Segment 6 - Time from Command cmpl is passed to NVME
327 * Layer to Driver receives a RSP op from NVME Layer.
328 * Segment 7 - Time from Driver receives a RSP op from
329 * NVME Layer to WQ put is done on TRSP FCP Status.
330 * Segment 8 - Time from Driver WQ put is done on TRSP
331 * FCP Status to MSI-X ISR for TRSP cmpl.
332 * Segment 9 - Time from MSI-X ISR for TRSP cmpl to
333 * TRSP cmpl is passed to NVME Layer.
334 * Segment 10 - Time from FCP command received by
335 * MSI-X ISR to command is completed on wire.
336 * (Segments 1 thru 8) for READDATA / WRITEDATA
337 * (Segments 1 thru 4) for READDATA_RSP
339 seg1 = ctxp->ts_cmd_nvme - ctxp->ts_isr_cmd;
340 seg2 = (ctxp->ts_nvme_data - ctxp->ts_isr_cmd) - seg1;
341 seg3 = (ctxp->ts_data_wqput - ctxp->ts_isr_cmd) -
343 seg4 = (ctxp->ts_isr_data - ctxp->ts_isr_cmd) -
345 seg5 = (ctxp->ts_data_nvme - ctxp->ts_isr_cmd) -
346 seg1 - seg2 - seg3 - seg4;
348 /* For auto rsp commands seg6 thru seg10 will be 0 */
349 if (ctxp->ts_nvme_status > ctxp->ts_data_nvme) {
350 seg6 = (ctxp->ts_nvme_status -
352 seg1 - seg2 - seg3 - seg4 - seg5;
353 seg7 = (ctxp->ts_status_wqput -
357 seg8 = (ctxp->ts_isr_status -
359 seg1 - seg2 - seg3 - seg4 -
361 seg9 = (ctxp->ts_status_nvme -
363 seg1 - seg2 - seg3 - seg4 -
364 seg5 - seg6 - seg7 - seg8;
365 seg10 = (ctxp->ts_isr_status -
372 seg10 = (ctxp->ts_isr_data - ctxp->ts_isr_cmd);
375 phba->ktime_seg1_total += seg1;
376 if (seg1 < phba->ktime_seg1_min)
377 phba->ktime_seg1_min = seg1;
378 else if (seg1 > phba->ktime_seg1_max)
379 phba->ktime_seg1_max = seg1;
381 phba->ktime_seg2_total += seg2;
382 if (seg2 < phba->ktime_seg2_min)
383 phba->ktime_seg2_min = seg2;
384 else if (seg2 > phba->ktime_seg2_max)
385 phba->ktime_seg2_max = seg2;
387 phba->ktime_seg3_total += seg3;
388 if (seg3 < phba->ktime_seg3_min)
389 phba->ktime_seg3_min = seg3;
390 else if (seg3 > phba->ktime_seg3_max)
391 phba->ktime_seg3_max = seg3;
393 phba->ktime_seg4_total += seg4;
394 if (seg4 < phba->ktime_seg4_min)
395 phba->ktime_seg4_min = seg4;
396 else if (seg4 > phba->ktime_seg4_max)
397 phba->ktime_seg4_max = seg4;
399 phba->ktime_seg5_total += seg5;
400 if (seg5 < phba->ktime_seg5_min)
401 phba->ktime_seg5_min = seg5;
402 else if (seg5 > phba->ktime_seg5_max)
403 phba->ktime_seg5_max = seg5;
405 phba->ktime_data_samples++;
409 phba->ktime_seg6_total += seg6;
410 if (seg6 < phba->ktime_seg6_min)
411 phba->ktime_seg6_min = seg6;
412 else if (seg6 > phba->ktime_seg6_max)
413 phba->ktime_seg6_max = seg6;
415 phba->ktime_seg7_total += seg7;
416 if (seg7 < phba->ktime_seg7_min)
417 phba->ktime_seg7_min = seg7;
418 else if (seg7 > phba->ktime_seg7_max)
419 phba->ktime_seg7_max = seg7;
421 phba->ktime_seg8_total += seg8;
422 if (seg8 < phba->ktime_seg8_min)
423 phba->ktime_seg8_min = seg8;
424 else if (seg8 > phba->ktime_seg8_max)
425 phba->ktime_seg8_max = seg8;
427 phba->ktime_seg9_total += seg9;
428 if (seg9 < phba->ktime_seg9_min)
429 phba->ktime_seg9_min = seg9;
430 else if (seg9 > phba->ktime_seg9_max)
431 phba->ktime_seg9_max = seg9;
433 phba->ktime_seg10_total += seg10;
434 if (seg10 < phba->ktime_seg10_min)
435 phba->ktime_seg10_min = seg10;
436 else if (seg10 > phba->ktime_seg10_max)
437 phba->ktime_seg10_max = seg10;
438 phba->ktime_status_samples++;
443 * lpfc_nvmet_xmt_fcp_op_cmp - Completion handler for FCP Response
444 * @phba: Pointer to HBA context object.
445 * @cmdwqe: Pointer to driver command WQE object.
446 * @wcqe: Pointer to driver response CQE object.
448 * The function is called from SLI ring event handler with no
449 * lock held. This function is the completion handler for NVME FCP commands
450 * The function frees memory resources used for the NVME commands.
453 lpfc_nvmet_xmt_fcp_op_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
454 struct lpfc_wcqe_complete *wcqe)
456 struct lpfc_nvmet_tgtport *tgtp;
457 struct nvmefc_tgt_fcp_req *rsp;
458 struct lpfc_nvmet_rcv_ctx *ctxp;
459 uint32_t status, result, op, start_clean;
460 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
464 ctxp = cmdwqe->context2;
465 ctxp->flag &= ~LPFC_NVMET_IO_INP;
467 rsp = &ctxp->ctx.fcp_req;
470 status = bf_get(lpfc_wcqe_c_status, wcqe);
471 result = wcqe->parameter;
473 if (phba->targetport)
474 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
478 lpfc_nvmeio_data(phba, "NVMET FCP CMPL: xri x%x op x%x status x%x\n",
479 ctxp->oxid, op, status);
482 rsp->fcp_error = NVME_SC_DATA_XFER_ERROR;
483 rsp->transferred_length = 0;
485 atomic_inc(&tgtp->xmt_fcp_rsp_error);
487 /* pick up SLI4 exhange busy condition */
488 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
489 ctxp->flag |= LPFC_NVMET_XBUSY;
491 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
492 "6315 IO Cmpl XBUSY: xri x%x: %x/%x\n",
493 ctxp->oxid, status, result);
495 ctxp->flag &= ~LPFC_NVMET_XBUSY;
499 rsp->fcp_error = NVME_SC_SUCCESS;
500 if (op == NVMET_FCOP_RSP)
501 rsp->transferred_length = rsp->rsplen;
503 rsp->transferred_length = rsp->transfer_length;
505 atomic_inc(&tgtp->xmt_fcp_rsp_cmpl);
508 if ((op == NVMET_FCOP_READDATA_RSP) ||
509 (op == NVMET_FCOP_RSP)) {
511 ctxp->state = LPFC_NVMET_STE_DONE;
514 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
515 if (phba->ktime_on) {
516 if (rsp->op == NVMET_FCOP_READDATA_RSP) {
518 cmdwqe->isr_timestamp;
521 ctxp->ts_nvme_status =
523 ctxp->ts_status_wqput =
525 ctxp->ts_isr_status =
527 ctxp->ts_status_nvme =
530 ctxp->ts_isr_status =
531 cmdwqe->isr_timestamp;
532 ctxp->ts_status_nvme =
536 if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) {
537 id = smp_processor_id();
539 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
540 "6703 CPU Check cmpl: "
541 "cpu %d expect %d\n",
543 if (ctxp->cpu < LPFC_CHECK_CPU_CNT)
544 phba->cpucheck_cmpl_io[id]++;
548 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
550 lpfc_nvmet_ktime(phba, ctxp);
552 /* lpfc_nvmet_xmt_fcp_release() will recycle the context */
555 start_clean = offsetof(struct lpfc_iocbq, wqe);
556 memset(((char *)cmdwqe) + start_clean, 0,
557 (sizeof(struct lpfc_iocbq) - start_clean));
558 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
559 if (phba->ktime_on) {
560 ctxp->ts_isr_data = cmdwqe->isr_timestamp;
561 ctxp->ts_data_nvme = ktime_get_ns();
563 if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) {
564 id = smp_processor_id();
566 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
567 "6704 CPU Check cmdcmpl: "
568 "cpu %d expect %d\n",
570 if (ctxp->cpu < LPFC_CHECK_CPU_CNT)
571 phba->cpucheck_ccmpl_io[id]++;
579 lpfc_nvmet_xmt_ls_rsp(struct nvmet_fc_target_port *tgtport,
580 struct nvmefc_tgt_ls_req *rsp)
582 struct lpfc_nvmet_rcv_ctx *ctxp =
583 container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.ls_req);
584 struct lpfc_hba *phba = ctxp->phba;
585 struct hbq_dmabuf *nvmebuf =
586 (struct hbq_dmabuf *)ctxp->rqb_buffer;
587 struct lpfc_iocbq *nvmewqeq;
588 struct lpfc_nvmet_tgtport *nvmep = tgtport->private;
589 struct lpfc_dmabuf dmabuf;
590 struct ulp_bde64 bpl;
593 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
594 "6023 NVMET LS rsp oxid x%x\n", ctxp->oxid);
596 if ((ctxp->state != LPFC_NVMET_STE_LS_RCV) ||
597 (ctxp->entry_cnt != 1)) {
598 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
599 "6412 NVMET LS rsp state mismatch "
601 ctxp->oxid, ctxp->state, ctxp->entry_cnt);
603 ctxp->state = LPFC_NVMET_STE_LS_RSP;
606 nvmewqeq = lpfc_nvmet_prep_ls_wqe(phba, ctxp, rsp->rspdma,
608 if (nvmewqeq == NULL) {
609 atomic_inc(&nvmep->xmt_ls_drop);
610 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
611 "6150 LS Drop IO x%x: Prep\n",
613 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
614 atomic_inc(&nvmep->xmt_ls_abort);
615 lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp,
616 ctxp->sid, ctxp->oxid);
620 /* Save numBdes for bpl2sgl */
622 nvmewqeq->hba_wqidx = 0;
623 nvmewqeq->context3 = &dmabuf;
625 bpl.addrLow = nvmewqeq->wqe.xmit_sequence.bde.addrLow;
626 bpl.addrHigh = nvmewqeq->wqe.xmit_sequence.bde.addrHigh;
627 bpl.tus.f.bdeSize = rsp->rsplen;
628 bpl.tus.f.bdeFlags = 0;
629 bpl.tus.w = le32_to_cpu(bpl.tus.w);
631 nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_rsp_cmp;
632 nvmewqeq->iocb_cmpl = NULL;
633 nvmewqeq->context2 = ctxp;
635 lpfc_nvmeio_data(phba, "NVMET LS RESP: xri x%x wqidx x%x len x%x\n",
636 ctxp->oxid, nvmewqeq->hba_wqidx, rsp->rsplen);
638 rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, nvmewqeq);
639 if (rc == WQE_SUCCESS) {
641 * Okay to repost buffer here, but wait till cmpl
642 * before freeing ctxp and iocbq.
644 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
645 ctxp->rqb_buffer = 0;
646 atomic_inc(&nvmep->xmt_ls_rsp);
649 /* Give back resources */
650 atomic_inc(&nvmep->xmt_ls_drop);
651 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
652 "6151 LS Drop IO x%x: Issue %d\n",
655 lpfc_nlp_put(nvmewqeq->context1);
657 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
658 atomic_inc(&nvmep->xmt_ls_abort);
659 lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, ctxp->sid, ctxp->oxid);
664 lpfc_nvmet_xmt_fcp_op(struct nvmet_fc_target_port *tgtport,
665 struct nvmefc_tgt_fcp_req *rsp)
667 struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private;
668 struct lpfc_nvmet_rcv_ctx *ctxp =
669 container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req);
670 struct lpfc_hba *phba = ctxp->phba;
671 struct lpfc_iocbq *nvmewqeq;
674 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
675 if (phba->ktime_on) {
676 if (rsp->op == NVMET_FCOP_RSP)
677 ctxp->ts_nvme_status = ktime_get_ns();
679 ctxp->ts_nvme_data = ktime_get_ns();
681 if (phba->cpucheck_on & LPFC_CHECK_NVMET_IO) {
682 int id = smp_processor_id();
684 if (id < LPFC_CHECK_CPU_CNT)
685 phba->cpucheck_xmt_io[id]++;
686 if (rsp->hwqid != id) {
687 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
688 "6705 CPU Check OP: "
689 "cpu %d expect %d\n",
691 ctxp->cpu = rsp->hwqid;
697 if ((ctxp->flag & LPFC_NVMET_ABTS_RCV) ||
698 (ctxp->state == LPFC_NVMET_STE_ABORT)) {
699 atomic_inc(&lpfc_nvmep->xmt_fcp_drop);
700 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
701 "6102 IO xri x%x aborted\n",
707 nvmewqeq = lpfc_nvmet_prep_fcp_wqe(phba, ctxp);
708 if (nvmewqeq == NULL) {
709 atomic_inc(&lpfc_nvmep->xmt_fcp_drop);
710 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
711 "6152 FCP Drop IO x%x: Prep\n",
717 nvmewqeq->wqe_cmpl = lpfc_nvmet_xmt_fcp_op_cmp;
718 nvmewqeq->iocb_cmpl = NULL;
719 nvmewqeq->context2 = ctxp;
720 nvmewqeq->iocb_flag |= LPFC_IO_NVMET;
721 ctxp->wqeq->hba_wqidx = rsp->hwqid;
723 lpfc_nvmeio_data(phba, "NVMET FCP CMND: xri x%x op x%x len x%x\n",
724 ctxp->oxid, rsp->op, rsp->rsplen);
726 ctxp->flag |= LPFC_NVMET_IO_INP;
727 rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, nvmewqeq);
728 if (rc == WQE_SUCCESS) {
729 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
732 if (rsp->op == NVMET_FCOP_RSP)
733 ctxp->ts_status_wqput = ktime_get_ns();
735 ctxp->ts_data_wqput = ktime_get_ns();
740 /* Give back resources */
741 atomic_inc(&lpfc_nvmep->xmt_fcp_drop);
742 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
743 "6153 FCP Drop IO x%x: Issue: %d\n",
746 ctxp->wqeq->hba_wqidx = 0;
747 nvmewqeq->context2 = NULL;
748 nvmewqeq->context3 = NULL;
755 lpfc_nvmet_targetport_delete(struct nvmet_fc_target_port *targetport)
757 struct lpfc_nvmet_tgtport *tport = targetport->private;
759 /* release any threads waiting for the unreg to complete */
760 complete(&tport->tport_unreg_done);
764 lpfc_nvmet_xmt_fcp_abort(struct nvmet_fc_target_port *tgtport,
765 struct nvmefc_tgt_fcp_req *req)
767 struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private;
768 struct lpfc_nvmet_rcv_ctx *ctxp =
769 container_of(req, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req);
770 struct lpfc_hba *phba = ctxp->phba;
773 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
774 "6103 NVMET Abort op: oxri x%x flg x%x ste %d\n",
775 ctxp->oxid, ctxp->flag, ctxp->state);
777 lpfc_nvmeio_data(phba, "NVMET FCP ABRT: xri x%x flg x%x ste x%x\n",
778 ctxp->oxid, ctxp->flag, ctxp->state);
780 atomic_inc(&lpfc_nvmep->xmt_fcp_abort);
782 spin_lock_irqsave(&ctxp->ctxlock, flags);
784 /* Since iaab/iaar are NOT set, we need to check
785 * if the firmware is in process of aborting IO
787 if (ctxp->flag & LPFC_NVMET_XBUSY) {
788 spin_unlock_irqrestore(&ctxp->ctxlock, flags);
791 ctxp->flag |= LPFC_NVMET_ABORT_OP;
793 /* An state of LPFC_NVMET_STE_RCV means we have just received
794 * the NVME command and have not started processing it.
795 * (by issuing any IO WQEs on this exchange yet)
797 if (ctxp->state == LPFC_NVMET_STE_RCV)
798 lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, ctxp->sid,
801 lpfc_nvmet_sol_fcp_issue_abort(phba, ctxp, ctxp->sid,
803 spin_unlock_irqrestore(&ctxp->ctxlock, flags);
807 lpfc_nvmet_xmt_fcp_release(struct nvmet_fc_target_port *tgtport,
808 struct nvmefc_tgt_fcp_req *rsp)
810 struct lpfc_nvmet_tgtport *lpfc_nvmep = tgtport->private;
811 struct lpfc_nvmet_rcv_ctx *ctxp =
812 container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req);
813 struct lpfc_hba *phba = ctxp->phba;
815 bool aborting = false;
817 if (ctxp->state != LPFC_NVMET_STE_DONE &&
818 ctxp->state != LPFC_NVMET_STE_ABORT) {
819 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
820 "6413 NVMET release bad state %d %d oxid x%x\n",
821 ctxp->state, ctxp->entry_cnt, ctxp->oxid);
824 spin_lock_irqsave(&ctxp->ctxlock, flags);
825 if ((ctxp->flag & LPFC_NVMET_ABORT_OP) ||
826 (ctxp->flag & LPFC_NVMET_XBUSY)) {
828 /* let the abort path do the real release */
829 lpfc_nvmet_defer_release(phba, ctxp);
831 spin_unlock_irqrestore(&ctxp->ctxlock, flags);
833 lpfc_nvmeio_data(phba, "NVMET FCP FREE: xri x%x ste %d abt %d\n", ctxp->oxid,
834 ctxp->state, aborting);
836 atomic_inc(&lpfc_nvmep->xmt_fcp_release);
841 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
844 static struct nvmet_fc_target_template lpfc_tgttemplate = {
845 .targetport_delete = lpfc_nvmet_targetport_delete,
846 .xmt_ls_rsp = lpfc_nvmet_xmt_ls_rsp,
847 .fcp_op = lpfc_nvmet_xmt_fcp_op,
848 .fcp_abort = lpfc_nvmet_xmt_fcp_abort,
849 .fcp_req_release = lpfc_nvmet_xmt_fcp_release,
852 .max_sgl_segments = LPFC_NVMET_DEFAULT_SEGS,
853 .max_dif_sgl_segments = LPFC_NVMET_DEFAULT_SEGS,
854 .dma_boundary = 0xFFFFFFFF,
856 /* optional features */
857 .target_features = 0,
858 /* sizes of additional private data for data structures */
859 .target_priv_sz = sizeof(struct lpfc_nvmet_tgtport),
863 lpfc_nvmet_cleanup_io_context(struct lpfc_hba *phba)
865 struct lpfc_nvmet_ctxbuf *ctx_buf, *next_ctx_buf;
868 list_for_each_entry_safe(
869 ctx_buf, next_ctx_buf,
870 &phba->sli4_hba.lpfc_nvmet_ctx_list, list) {
872 &phba->sli4_hba.abts_nvme_buf_list_lock, flags);
873 list_del_init(&ctx_buf->list);
874 spin_unlock_irqrestore(
875 &phba->sli4_hba.abts_nvme_buf_list_lock, flags);
876 __lpfc_clear_active_sglq(phba,
877 ctx_buf->sglq->sli4_lxritag);
878 ctx_buf->sglq->state = SGL_FREED;
879 ctx_buf->sglq->ndlp = NULL;
881 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, flags);
882 list_add_tail(&ctx_buf->sglq->list,
883 &phba->sli4_hba.lpfc_nvmet_sgl_list);
884 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock,
887 lpfc_sli_release_iocbq(phba, ctx_buf->iocbq);
888 kfree(ctx_buf->context);
893 lpfc_nvmet_setup_io_context(struct lpfc_hba *phba)
895 struct lpfc_nvmet_ctxbuf *ctx_buf;
896 struct lpfc_iocbq *nvmewqe;
897 union lpfc_wqe128 *wqe;
900 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
901 "6403 Allocate NVMET resources for %d XRIs\n",
902 phba->sli4_hba.nvmet_xri_cnt);
904 /* For all nvmet xris, allocate resources needed to process a
905 * received command on a per xri basis.
907 for (i = 0; i < phba->sli4_hba.nvmet_xri_cnt; i++) {
908 ctx_buf = kzalloc(sizeof(*ctx_buf), GFP_KERNEL);
910 lpfc_printf_log(phba, KERN_ERR, LOG_NVME,
911 "6404 Ran out of memory for NVMET\n");
915 ctx_buf->context = kzalloc(sizeof(*ctx_buf->context),
917 if (!ctx_buf->context) {
919 lpfc_printf_log(phba, KERN_ERR, LOG_NVME,
920 "6405 Ran out of NVMET "
924 ctx_buf->context->ctxbuf = ctx_buf;
925 ctx_buf->context->state = LPFC_NVMET_STE_FREE;
927 ctx_buf->iocbq = lpfc_sli_get_iocbq(phba);
928 if (!ctx_buf->iocbq) {
929 kfree(ctx_buf->context);
931 lpfc_printf_log(phba, KERN_ERR, LOG_NVME,
932 "6406 Ran out of NVMET iocb/WQEs\n");
935 ctx_buf->iocbq->iocb_flag = LPFC_IO_NVMET;
936 nvmewqe = ctx_buf->iocbq;
937 wqe = (union lpfc_wqe128 *)&nvmewqe->wqe;
939 memset(wqe, 0, sizeof(union lpfc_wqe));
941 bf_set(wqe_ct, &wqe->generic.wqe_com, SLI4_CT_RPI);
942 bf_set(wqe_class, &wqe->generic.wqe_com, CLASS3);
943 bf_set(wqe_pu, &wqe->generic.wqe_com, 1);
945 bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1);
946 bf_set(wqe_ebde_cnt, &wqe->generic.wqe_com, 0);
947 bf_set(wqe_qosd, &wqe->generic.wqe_com, 0);
949 ctx_buf->iocbq->context1 = NULL;
950 spin_lock(&phba->sli4_hba.sgl_list_lock);
951 ctx_buf->sglq = __lpfc_sli_get_nvmet_sglq(phba, ctx_buf->iocbq);
952 spin_unlock(&phba->sli4_hba.sgl_list_lock);
953 if (!ctx_buf->sglq) {
954 lpfc_sli_release_iocbq(phba, ctx_buf->iocbq);
955 kfree(ctx_buf->context);
957 lpfc_printf_log(phba, KERN_ERR, LOG_NVME,
958 "6407 Ran out of NVMET XRIs\n");
961 spin_lock(&phba->sli4_hba.nvmet_io_lock);
962 list_add_tail(&ctx_buf->list,
963 &phba->sli4_hba.lpfc_nvmet_ctx_list);
964 spin_unlock(&phba->sli4_hba.nvmet_io_lock);
966 phba->sli4_hba.nvmet_ctx_cnt = phba->sli4_hba.nvmet_xri_cnt;
971 lpfc_nvmet_create_targetport(struct lpfc_hba *phba)
973 struct lpfc_vport *vport = phba->pport;
974 struct lpfc_nvmet_tgtport *tgtp;
975 struct nvmet_fc_port_info pinfo;
978 if (phba->targetport)
981 error = lpfc_nvmet_setup_io_context(phba);
985 memset(&pinfo, 0, sizeof(struct nvmet_fc_port_info));
986 pinfo.node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
987 pinfo.port_name = wwn_to_u64(vport->fc_portname.u.wwn);
988 pinfo.port_id = vport->fc_myDID;
990 /* Limit to LPFC_MAX_NVME_SEG_CNT.
991 * For now need + 1 to get around NVME transport logic.
993 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
994 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
995 "6400 Reducing sg segment cnt to %d\n",
996 LPFC_MAX_NVME_SEG_CNT);
997 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
999 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
1001 lpfc_tgttemplate.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1;
1002 lpfc_tgttemplate.max_hw_queues = phba->cfg_nvme_io_channel;
1003 lpfc_tgttemplate.target_features = NVMET_FCTGTFEAT_READDATA_RSP |
1004 NVMET_FCTGTFEAT_CMD_IN_ISR |
1005 NVMET_FCTGTFEAT_OPDONE_IN_ISR;
1007 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
1008 error = nvmet_fc_register_targetport(&pinfo, &lpfc_tgttemplate,
1015 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
1016 "6025 Cannot register NVME targetport "
1018 phba->targetport = NULL;
1020 lpfc_nvmet_cleanup_io_context(phba);
1023 tgtp = (struct lpfc_nvmet_tgtport *)
1024 phba->targetport->private;
1027 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
1028 "6026 Registered NVME "
1029 "targetport: %p, private %p "
1030 "portnm %llx nodenm %llx\n",
1031 phba->targetport, tgtp,
1032 pinfo.port_name, pinfo.node_name);
1034 atomic_set(&tgtp->rcv_ls_req_in, 0);
1035 atomic_set(&tgtp->rcv_ls_req_out, 0);
1036 atomic_set(&tgtp->rcv_ls_req_drop, 0);
1037 atomic_set(&tgtp->xmt_ls_abort, 0);
1038 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
1039 atomic_set(&tgtp->xmt_ls_rsp, 0);
1040 atomic_set(&tgtp->xmt_ls_drop, 0);
1041 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
1042 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
1043 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
1044 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
1045 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
1046 atomic_set(&tgtp->xmt_fcp_drop, 0);
1047 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
1048 atomic_set(&tgtp->xmt_fcp_read, 0);
1049 atomic_set(&tgtp->xmt_fcp_write, 0);
1050 atomic_set(&tgtp->xmt_fcp_rsp, 0);
1051 atomic_set(&tgtp->xmt_fcp_release, 0);
1052 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
1053 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
1054 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
1055 atomic_set(&tgtp->xmt_fcp_abort, 0);
1056 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
1057 atomic_set(&tgtp->xmt_abort_unsol, 0);
1058 atomic_set(&tgtp->xmt_abort_sol, 0);
1059 atomic_set(&tgtp->xmt_abort_rsp, 0);
1060 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
1066 lpfc_nvmet_update_targetport(struct lpfc_hba *phba)
1068 struct lpfc_vport *vport = phba->pport;
1070 if (!phba->targetport)
1073 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
1074 "6007 Update NVMET port %p did x%x\n",
1075 phba->targetport, vport->fc_myDID);
1077 phba->targetport->port_id = vport->fc_myDID;
1082 * lpfc_sli4_nvmet_xri_aborted - Fast-path process of nvmet xri abort
1083 * @phba: pointer to lpfc hba data structure.
1084 * @axri: pointer to the nvmet xri abort wcqe structure.
1086 * This routine is invoked by the worker thread to process a SLI4 fast-path
1087 * NVMET aborted xri.
1090 lpfc_sli4_nvmet_xri_aborted(struct lpfc_hba *phba,
1091 struct sli4_wcqe_xri_aborted *axri)
1093 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
1094 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
1095 struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp;
1096 struct lpfc_nodelist *ndlp;
1097 unsigned long iflag = 0;
1099 bool released = false;
1101 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
1102 "6317 XB aborted xri x%x rxid x%x\n", xri, rxid);
1104 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
1106 spin_lock_irqsave(&phba->hbalock, iflag);
1107 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1108 list_for_each_entry_safe(ctxp, next_ctxp,
1109 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1111 if (ctxp->ctxbuf->sglq->sli4_xritag != xri)
1114 /* Check if we already received a free context call
1115 * and we have completed processing an abort situation.
1117 if (ctxp->flag & LPFC_NVMET_CTX_RLS &&
1118 !(ctxp->flag & LPFC_NVMET_ABORT_OP)) {
1119 list_del(&ctxp->list);
1122 ctxp->flag &= ~LPFC_NVMET_XBUSY;
1123 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1125 rrq_empty = list_empty(&phba->active_rrq_list);
1126 spin_unlock_irqrestore(&phba->hbalock, iflag);
1127 ndlp = lpfc_findnode_did(phba->pport, ctxp->sid);
1128 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1129 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
1130 ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
1131 lpfc_set_rrq_active(phba, ndlp,
1132 ctxp->ctxbuf->sglq->sli4_lxritag,
1134 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
1137 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
1138 "6318 XB aborted oxid %x flg x%x (%x)\n",
1139 ctxp->oxid, ctxp->flag, released);
1141 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1144 lpfc_worker_wake_up(phba);
1147 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1148 spin_unlock_irqrestore(&phba->hbalock, iflag);
1152 lpfc_nvmet_rcv_unsol_abort(struct lpfc_vport *vport,
1153 struct fc_frame_header *fc_hdr)
1156 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
1157 struct lpfc_hba *phba = vport->phba;
1158 struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp;
1159 struct nvmefc_tgt_fcp_req *rsp;
1161 unsigned long iflag = 0;
1163 xri = be16_to_cpu(fc_hdr->fh_ox_id);
1165 spin_lock_irqsave(&phba->hbalock, iflag);
1166 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1167 list_for_each_entry_safe(ctxp, next_ctxp,
1168 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1170 if (ctxp->ctxbuf->sglq->sli4_xritag != xri)
1173 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1174 spin_unlock_irqrestore(&phba->hbalock, iflag);
1176 spin_lock_irqsave(&ctxp->ctxlock, iflag);
1177 ctxp->flag |= LPFC_NVMET_ABTS_RCV;
1178 spin_unlock_irqrestore(&ctxp->ctxlock, iflag);
1180 lpfc_nvmeio_data(phba,
1181 "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n",
1182 xri, smp_processor_id(), 0);
1184 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
1185 "6319 NVMET Rcv ABTS:acc xri x%x\n", xri);
1187 rsp = &ctxp->ctx.fcp_req;
1188 nvmet_fc_rcv_fcp_abort(phba->targetport, rsp);
1190 /* Respond with BA_ACC accordingly */
1191 lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 1);
1194 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1195 spin_unlock_irqrestore(&phba->hbalock, iflag);
1197 lpfc_nvmeio_data(phba, "NVMET ABTS RCV: xri x%x CPU %02x rjt %d\n",
1198 xri, smp_processor_id(), 1);
1200 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
1201 "6320 NVMET Rcv ABTS:rjt xri x%x\n", xri);
1203 /* Respond with BA_RJT accordingly */
1204 lpfc_sli4_seq_abort_rsp(vport, fc_hdr, 0);
1210 lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba)
1212 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
1213 struct lpfc_nvmet_tgtport *tgtp;
1215 if (phba->nvmet_support == 0)
1217 if (phba->targetport) {
1218 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1219 init_completion(&tgtp->tport_unreg_done);
1220 nvmet_fc_unregister_targetport(phba->targetport);
1221 wait_for_completion_timeout(&tgtp->tport_unreg_done, 5);
1222 lpfc_nvmet_cleanup_io_context(phba);
1224 phba->targetport = NULL;
1229 * lpfc_nvmet_unsol_ls_buffer - Process an unsolicited event data buffer
1230 * @phba: pointer to lpfc hba data structure.
1231 * @pring: pointer to a SLI ring.
1232 * @nvmebuf: pointer to lpfc nvme command HBQ data structure.
1234 * This routine is used for processing the WQE associated with a unsolicited
1235 * event. It first determines whether there is an existing ndlp that matches
1236 * the DID from the unsolicited WQE. If not, it will create a new one with
1237 * the DID from the unsolicited WQE. The ELS command from the unsolicited
1238 * WQE is then used to invoke the proper routine and to set up proper state
1239 * of the discovery state machine.
1242 lpfc_nvmet_unsol_ls_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1243 struct hbq_dmabuf *nvmebuf)
1245 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
1246 struct lpfc_nvmet_tgtport *tgtp;
1247 struct fc_frame_header *fc_hdr;
1248 struct lpfc_nvmet_rcv_ctx *ctxp;
1250 uint32_t size, oxid, sid, rc;
1252 if (!nvmebuf || !phba->targetport) {
1253 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1254 "6154 LS Drop IO\n");
1262 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1263 payload = (uint32_t *)(nvmebuf->dbuf.virt);
1264 fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt);
1265 size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl);
1266 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
1267 sid = sli4_sid_from_fc_hdr(fc_hdr);
1269 ctxp = kzalloc(sizeof(struct lpfc_nvmet_rcv_ctx), GFP_ATOMIC);
1271 atomic_inc(&tgtp->rcv_ls_req_drop);
1272 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1273 "6155 LS Drop IO x%x: Alloc\n",
1276 lpfc_nvmeio_data(phba, "NVMET LS DROP: "
1277 "xri x%x sz %d from %06x\n",
1280 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
1288 ctxp->state = LPFC_NVMET_STE_LS_RCV;
1289 ctxp->entry_cnt = 1;
1290 ctxp->rqb_buffer = (void *)nvmebuf;
1292 lpfc_nvmeio_data(phba, "NVMET LS RCV: xri x%x sz %d from %06x\n",
1295 * The calling sequence should be:
1296 * nvmet_fc_rcv_ls_req -> lpfc_nvmet_xmt_ls_rsp/cmp ->_req->done
1297 * lpfc_nvmet_xmt_ls_rsp_cmp should free the allocated ctxp.
1299 atomic_inc(&tgtp->rcv_ls_req_in);
1300 rc = nvmet_fc_rcv_ls_req(phba->targetport, &ctxp->ctx.ls_req,
1303 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
1304 "6037 NVMET Unsol rcv: sz %d rc %d: %08x %08x %08x "
1305 "%08x %08x %08x\n", size, rc,
1306 *payload, *(payload+1), *(payload+2),
1307 *(payload+3), *(payload+4), *(payload+5));
1310 atomic_inc(&tgtp->rcv_ls_req_out);
1314 lpfc_nvmeio_data(phba, "NVMET LS DROP: xri x%x sz %d from %06x\n",
1317 atomic_inc(&tgtp->rcv_ls_req_drop);
1318 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1319 "6156 LS Drop IO x%x: nvmet_fc_rcv_ls_req %d\n",
1322 /* We assume a rcv'ed cmd ALWAYs fits into 1 buffer */
1324 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
1326 atomic_inc(&tgtp->xmt_ls_abort);
1327 lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, sid, oxid);
1332 * lpfc_nvmet_unsol_fcp_buffer - Process an unsolicited event data buffer
1333 * @phba: pointer to lpfc hba data structure.
1334 * @pring: pointer to a SLI ring.
1335 * @nvmebuf: pointer to lpfc nvme command HBQ data structure.
1337 * This routine is used for processing the WQE associated with a unsolicited
1338 * event. It first determines whether there is an existing ndlp that matches
1339 * the DID from the unsolicited WQE. If not, it will create a new one with
1340 * the DID from the unsolicited WQE. The ELS command from the unsolicited
1341 * WQE is then used to invoke the proper routine and to set up proper state
1342 * of the discovery state machine.
1345 lpfc_nvmet_unsol_fcp_buffer(struct lpfc_hba *phba,
1346 struct lpfc_sli_ring *pring,
1347 struct rqb_dmabuf *nvmebuf,
1348 uint64_t isr_timestamp)
1350 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
1351 struct lpfc_nvmet_rcv_ctx *ctxp;
1352 struct lpfc_nvmet_tgtport *tgtp;
1353 struct fc_frame_header *fc_hdr;
1354 struct lpfc_nvmet_ctxbuf *ctx_buf;
1356 uint32_t size, oxid, sid, rc, qno;
1357 unsigned long iflag;
1358 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1363 if (!nvmebuf || !phba->targetport) {
1364 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1365 "6157 NVMET FCP Drop IO\n");
1373 spin_lock_irqsave(&phba->sli4_hba.nvmet_io_lock, iflag);
1374 if (phba->sli4_hba.nvmet_ctx_cnt) {
1375 list_remove_head(&phba->sli4_hba.lpfc_nvmet_ctx_list,
1376 ctx_buf, struct lpfc_nvmet_ctxbuf, list);
1377 phba->sli4_hba.nvmet_ctx_cnt--;
1379 spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_lock, iflag);
1381 fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt);
1382 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
1383 size = nvmebuf->bytes_recv;
1385 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1386 if (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV) {
1387 id = smp_processor_id();
1388 if (id < LPFC_CHECK_CPU_CNT)
1389 phba->cpucheck_rcv_io[id]++;
1393 lpfc_nvmeio_data(phba, "NVMET FCP RCV: xri x%x sz %d CPU %02x\n",
1394 oxid, size, smp_processor_id());
1397 /* Queue this NVME IO to process later */
1398 spin_lock_irqsave(&phba->sli4_hba.nvmet_io_wait_lock, iflag);
1399 list_add_tail(&nvmebuf->hbuf.list,
1400 &phba->sli4_hba.lpfc_nvmet_io_wait_list);
1401 phba->sli4_hba.nvmet_io_wait_cnt++;
1402 phba->sli4_hba.nvmet_io_wait_total++;
1403 spin_unlock_irqrestore(&phba->sli4_hba.nvmet_io_wait_lock,
1406 /* Post a brand new DMA buffer to RQ */
1408 lpfc_post_rq_buffer(
1409 phba, phba->sli4_hba.nvmet_mrq_hdr[qno],
1410 phba->sli4_hba.nvmet_mrq_data[qno], 1, qno);
1414 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1415 payload = (uint32_t *)(nvmebuf->dbuf.virt);
1416 sid = sli4_sid_from_fc_hdr(fc_hdr);
1418 ctxp = (struct lpfc_nvmet_rcv_ctx *)ctx_buf->context;
1419 if (ctxp->state != LPFC_NVMET_STE_FREE) {
1420 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1421 "6414 NVMET Context corrupt %d %d oxid x%x\n",
1422 ctxp->state, ctxp->entry_cnt, ctxp->oxid);
1431 ctxp->state = LPFC_NVMET_STE_RCV;
1432 ctxp->entry_cnt = 1;
1434 ctxp->ctxbuf = ctx_buf;
1435 spin_lock_init(&ctxp->ctxlock);
1437 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1438 if (phba->ktime_on) {
1439 ctxp->ts_isr_cmd = isr_timestamp;
1440 ctxp->ts_cmd_nvme = ktime_get_ns();
1441 ctxp->ts_nvme_data = 0;
1442 ctxp->ts_data_wqput = 0;
1443 ctxp->ts_isr_data = 0;
1444 ctxp->ts_data_nvme = 0;
1445 ctxp->ts_nvme_status = 0;
1446 ctxp->ts_status_wqput = 0;
1447 ctxp->ts_isr_status = 0;
1448 ctxp->ts_status_nvme = 0;
1452 atomic_inc(&tgtp->rcv_fcp_cmd_in);
1454 * The calling sequence should be:
1455 * nvmet_fc_rcv_fcp_req -> lpfc_nvmet_xmt_fcp_op/cmp -> req->done
1456 * lpfc_nvmet_xmt_fcp_op_cmp should free the allocated ctxp.
1457 * When we return from nvmet_fc_rcv_fcp_req, all relevant info in
1458 * the NVME command / FC header is stored, so we are free to repost
1461 rc = nvmet_fc_rcv_fcp_req(phba->targetport, &ctxp->ctx.fcp_req,
1464 /* Process FCP command */
1466 atomic_inc(&tgtp->rcv_fcp_cmd_out);
1467 lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */
1471 atomic_inc(&tgtp->rcv_fcp_cmd_drop);
1472 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1473 "6159 FCP Drop IO x%x: err x%x: x%x x%x x%x\n",
1475 atomic_read(&tgtp->rcv_fcp_cmd_in),
1476 atomic_read(&tgtp->rcv_fcp_cmd_out),
1477 atomic_read(&tgtp->xmt_fcp_release));
1479 lpfc_nvmeio_data(phba, "NVMET FCP DROP: xri x%x sz %d from %06x\n",
1482 lpfc_nvmet_defer_release(phba, ctxp);
1483 lpfc_nvmet_unsol_fcp_issue_abort(phba, ctxp, sid, oxid);
1484 lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */
1489 lpfc_nvmet_ctxbuf_post(phba, ctx_buf);
1492 lpfc_rq_buf_free(phba, &nvmebuf->hbuf); /* repost */
1497 * lpfc_nvmet_unsol_ls_event - Process an unsolicited event from an nvme nport
1498 * @phba: pointer to lpfc hba data structure.
1499 * @pring: pointer to a SLI ring.
1500 * @nvmebuf: pointer to received nvme data structure.
1502 * This routine is used to process an unsolicited event received from a SLI
1503 * (Service Level Interface) ring. The actual processing of the data buffer
1504 * associated with the unsolicited event is done by invoking the routine
1505 * lpfc_nvmet_unsol_ls_buffer() after properly set up the buffer from the
1506 * SLI RQ on which the unsolicited event was received.
1509 lpfc_nvmet_unsol_ls_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1510 struct lpfc_iocbq *piocb)
1512 struct lpfc_dmabuf *d_buf;
1513 struct hbq_dmabuf *nvmebuf;
1515 d_buf = piocb->context2;
1516 nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
1518 if (phba->nvmet_support == 0) {
1519 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
1522 lpfc_nvmet_unsol_ls_buffer(phba, pring, nvmebuf);
1526 * lpfc_nvmet_unsol_fcp_event - Process an unsolicited event from an nvme nport
1527 * @phba: pointer to lpfc hba data structure.
1528 * @pring: pointer to a SLI ring.
1529 * @nvmebuf: pointer to received nvme data structure.
1531 * This routine is used to process an unsolicited event received from a SLI
1532 * (Service Level Interface) ring. The actual processing of the data buffer
1533 * associated with the unsolicited event is done by invoking the routine
1534 * lpfc_nvmet_unsol_fcp_buffer() after properly set up the buffer from the
1535 * SLI RQ on which the unsolicited event was received.
1538 lpfc_nvmet_unsol_fcp_event(struct lpfc_hba *phba,
1539 struct lpfc_sli_ring *pring,
1540 struct rqb_dmabuf *nvmebuf,
1541 uint64_t isr_timestamp)
1543 if (phba->nvmet_support == 0) {
1544 lpfc_rq_buf_free(phba, &nvmebuf->hbuf);
1547 lpfc_nvmet_unsol_fcp_buffer(phba, pring, nvmebuf,
1552 * lpfc_nvmet_prep_ls_wqe - Allocate and prepare a lpfc wqe data structure
1553 * @phba: pointer to a host N_Port data structure.
1554 * @ctxp: Context info for NVME LS Request
1555 * @rspbuf: DMA buffer of NVME command.
1556 * @rspsize: size of the NVME command.
1558 * This routine is used for allocating a lpfc-WQE data structure from
1559 * the driver lpfc-WQE free-list and prepare the WQE with the parameters
1560 * passed into the routine for discovery state machine to issue an Extended
1561 * Link Service (NVME) commands. It is a generic lpfc-WQE allocation
1562 * and preparation routine that is used by all the discovery state machine
1563 * routines and the NVME command-specific fields will be later set up by
1564 * the individual discovery machine routines after calling this routine
1565 * allocating and preparing a generic WQE data structure. It fills in the
1566 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
1567 * payload and response payload (if expected). The reference count on the
1568 * ndlp is incremented by 1 and the reference to the ndlp is put into
1569 * context1 of the WQE data structure for this WQE to hold the ndlp
1570 * reference for the command's callback function to access later.
1573 * Pointer to the newly allocated/prepared nvme wqe data structure
1574 * NULL - when nvme wqe data structure allocation/preparation failed
1576 static struct lpfc_iocbq *
1577 lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *phba,
1578 struct lpfc_nvmet_rcv_ctx *ctxp,
1579 dma_addr_t rspbuf, uint16_t rspsize)
1581 struct lpfc_nodelist *ndlp;
1582 struct lpfc_iocbq *nvmewqe;
1583 union lpfc_wqe *wqe;
1585 if (!lpfc_is_link_up(phba)) {
1586 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
1587 "6104 NVMET prep LS wqe: link err: "
1588 "NPORT x%x oxid:x%x ste %d\n",
1589 ctxp->sid, ctxp->oxid, ctxp->state);
1593 /* Allocate buffer for command wqe */
1594 nvmewqe = lpfc_sli_get_iocbq(phba);
1595 if (nvmewqe == NULL) {
1596 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
1597 "6105 NVMET prep LS wqe: No WQE: "
1598 "NPORT x%x oxid x%x ste %d\n",
1599 ctxp->sid, ctxp->oxid, ctxp->state);
1603 ndlp = lpfc_findnode_did(phba->pport, ctxp->sid);
1604 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
1605 ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
1606 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
1607 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
1608 "6106 NVMET prep LS wqe: No ndlp: "
1609 "NPORT x%x oxid x%x ste %d\n",
1610 ctxp->sid, ctxp->oxid, ctxp->state);
1611 goto nvme_wqe_free_wqeq_exit;
1613 ctxp->wqeq = nvmewqe;
1615 /* prevent preparing wqe with NULL ndlp reference */
1616 nvmewqe->context1 = lpfc_nlp_get(ndlp);
1617 if (nvmewqe->context1 == NULL)
1618 goto nvme_wqe_free_wqeq_exit;
1619 nvmewqe->context2 = ctxp;
1621 wqe = &nvmewqe->wqe;
1622 memset(wqe, 0, sizeof(union lpfc_wqe));
1625 wqe->xmit_sequence.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1626 wqe->xmit_sequence.bde.tus.f.bdeSize = rspsize;
1627 wqe->xmit_sequence.bde.addrLow = le32_to_cpu(putPaddrLow(rspbuf));
1628 wqe->xmit_sequence.bde.addrHigh = le32_to_cpu(putPaddrHigh(rspbuf));
1635 bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0);
1636 bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, 1);
1637 bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 0);
1638 bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, FC_RCTL_ELS4_REP);
1639 bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_NVME);
1642 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
1643 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
1644 bf_set(wqe_xri_tag, &wqe->xmit_sequence.wqe_com, nvmewqe->sli4_xritag);
1647 bf_set(wqe_cmnd, &wqe->xmit_sequence.wqe_com,
1648 CMD_XMIT_SEQUENCE64_WQE);
1649 bf_set(wqe_ct, &wqe->xmit_sequence.wqe_com, SLI4_CT_RPI);
1650 bf_set(wqe_class, &wqe->xmit_sequence.wqe_com, CLASS3);
1651 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
1654 wqe->xmit_sequence.wqe_com.abort_tag = nvmewqe->iotag;
1657 bf_set(wqe_reqtag, &wqe->xmit_sequence.wqe_com, nvmewqe->iotag);
1658 /* Needs to be set by caller */
1659 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, ctxp->oxid);
1662 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
1663 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE);
1664 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
1665 LPFC_WQE_LENLOC_WORD12);
1666 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
1669 bf_set(wqe_cqid, &wqe->xmit_sequence.wqe_com,
1670 LPFC_WQE_CQ_ID_DEFAULT);
1671 bf_set(wqe_cmd_type, &wqe->xmit_sequence.wqe_com,
1675 wqe->xmit_sequence.xmit_len = rspsize;
1678 nvmewqe->vport = phba->pport;
1679 nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT;
1680 nvmewqe->iocb_flag |= LPFC_IO_NVME_LS;
1682 /* Xmit NVMET response to remote NPORT <did> */
1683 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
1684 "6039 Xmit NVMET LS response to remote "
1685 "NPORT x%x iotag:x%x oxid:x%x size:x%x\n",
1686 ndlp->nlp_DID, nvmewqe->iotag, ctxp->oxid,
1690 nvme_wqe_free_wqeq_exit:
1691 nvmewqe->context2 = NULL;
1692 nvmewqe->context3 = NULL;
1693 lpfc_sli_release_iocbq(phba, nvmewqe);
1698 static struct lpfc_iocbq *
1699 lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *phba,
1700 struct lpfc_nvmet_rcv_ctx *ctxp)
1702 struct nvmefc_tgt_fcp_req *rsp = &ctxp->ctx.fcp_req;
1703 struct lpfc_nvmet_tgtport *tgtp;
1704 struct sli4_sge *sgl;
1705 struct lpfc_nodelist *ndlp;
1706 struct lpfc_iocbq *nvmewqe;
1707 struct scatterlist *sgel;
1708 union lpfc_wqe128 *wqe;
1710 dma_addr_t physaddr;
1714 if (!lpfc_is_link_up(phba)) {
1715 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1716 "6107 NVMET prep FCP wqe: link err:"
1717 "NPORT x%x oxid x%x ste %d\n",
1718 ctxp->sid, ctxp->oxid, ctxp->state);
1722 ndlp = lpfc_findnode_did(phba->pport, ctxp->sid);
1723 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
1724 ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
1725 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
1726 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1727 "6108 NVMET prep FCP wqe: no ndlp: "
1728 "NPORT x%x oxid x%x ste %d\n",
1729 ctxp->sid, ctxp->oxid, ctxp->state);
1733 if (rsp->sg_cnt > phba->cfg_nvme_seg_cnt) {
1734 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1735 "6109 NVMET prep FCP wqe: seg cnt err: "
1736 "NPORT x%x oxid x%x ste %d cnt %d\n",
1737 ctxp->sid, ctxp->oxid, ctxp->state,
1738 phba->cfg_nvme_seg_cnt);
1742 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1743 nvmewqe = ctxp->wqeq;
1744 if (nvmewqe == NULL) {
1745 /* Allocate buffer for command wqe */
1746 nvmewqe = ctxp->ctxbuf->iocbq;
1747 if (nvmewqe == NULL) {
1748 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1749 "6110 NVMET prep FCP wqe: No "
1750 "WQE: NPORT x%x oxid x%x ste %d\n",
1751 ctxp->sid, ctxp->oxid, ctxp->state);
1754 ctxp->wqeq = nvmewqe;
1755 xc = 0; /* create new XRI */
1756 nvmewqe->sli4_lxritag = NO_XRI;
1757 nvmewqe->sli4_xritag = NO_XRI;
1761 if (((ctxp->state == LPFC_NVMET_STE_RCV) &&
1762 (ctxp->entry_cnt == 1)) ||
1763 (ctxp->state == LPFC_NVMET_STE_DATA)) {
1764 wqe = (union lpfc_wqe128 *)&nvmewqe->wqe;
1766 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1767 "6111 Wrong state NVMET FCP: %d cnt %d\n",
1768 ctxp->state, ctxp->entry_cnt);
1772 sgl = (struct sli4_sge *)ctxp->ctxbuf->sglq->sgl;
1774 case NVMET_FCOP_READDATA:
1775 case NVMET_FCOP_READDATA_RSP:
1776 /* Words 0 - 2 : The first sg segment */
1778 physaddr = sg_dma_address(sgel);
1779 wqe->fcp_tsend.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1780 wqe->fcp_tsend.bde.tus.f.bdeSize = sg_dma_len(sgel);
1781 wqe->fcp_tsend.bde.addrLow = cpu_to_le32(putPaddrLow(physaddr));
1782 wqe->fcp_tsend.bde.addrHigh =
1783 cpu_to_le32(putPaddrHigh(physaddr));
1786 wqe->fcp_tsend.payload_offset_len = 0;
1789 wqe->fcp_tsend.relative_offset = ctxp->offset;
1794 bf_set(wqe_ctxt_tag, &wqe->fcp_tsend.wqe_com,
1795 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
1796 bf_set(wqe_xri_tag, &wqe->fcp_tsend.wqe_com,
1797 nvmewqe->sli4_xritag);
1800 bf_set(wqe_cmnd, &wqe->fcp_tsend.wqe_com, CMD_FCP_TSEND64_WQE);
1803 wqe->fcp_tsend.wqe_com.abort_tag = nvmewqe->iotag;
1806 bf_set(wqe_reqtag, &wqe->fcp_tsend.wqe_com, nvmewqe->iotag);
1807 bf_set(wqe_rcvoxid, &wqe->fcp_tsend.wqe_com, ctxp->oxid);
1810 bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1);
1811 bf_set(wqe_dbde, &wqe->fcp_tsend.wqe_com, 1);
1812 bf_set(wqe_iod, &wqe->fcp_tsend.wqe_com, LPFC_WQE_IOD_WRITE);
1813 bf_set(wqe_lenloc, &wqe->fcp_tsend.wqe_com,
1814 LPFC_WQE_LENLOC_WORD12);
1815 bf_set(wqe_ebde_cnt, &wqe->fcp_tsend.wqe_com, 0);
1816 bf_set(wqe_xc, &wqe->fcp_tsend.wqe_com, xc);
1817 bf_set(wqe_nvme, &wqe->fcp_tsend.wqe_com, 1);
1818 if (phba->cfg_nvme_oas)
1819 bf_set(wqe_oas, &wqe->fcp_tsend.wqe_com, 1);
1822 bf_set(wqe_cqid, &wqe->fcp_tsend.wqe_com,
1823 LPFC_WQE_CQ_ID_DEFAULT);
1824 bf_set(wqe_cmd_type, &wqe->fcp_tsend.wqe_com,
1828 wqe->fcp_tsend.fcp_data_len = rsp->transfer_length;
1830 /* Setup 2 SKIP SGEs */
1834 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP);
1835 sgl->word2 = cpu_to_le32(sgl->word2);
1841 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP);
1842 sgl->word2 = cpu_to_le32(sgl->word2);
1845 if (rsp->op == NVMET_FCOP_READDATA_RSP) {
1846 atomic_inc(&tgtp->xmt_fcp_read_rsp);
1847 bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 1);
1848 if ((ndlp->nlp_flag & NLP_SUPPRESS_RSP) &&
1849 (rsp->rsplen == 12)) {
1850 bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 1);
1851 bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0);
1852 bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0);
1853 bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0);
1855 bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0);
1856 bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 1);
1857 bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 1);
1858 bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com,
1859 ((rsp->rsplen >> 2) - 1));
1860 memcpy(&wqe->words[16], rsp->rspaddr,
1864 atomic_inc(&tgtp->xmt_fcp_read);
1866 bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0);
1867 bf_set(wqe_wqes, &wqe->fcp_tsend.wqe_com, 0);
1868 bf_set(wqe_irsp, &wqe->fcp_tsend.wqe_com, 0);
1869 bf_set(wqe_ar, &wqe->fcp_tsend.wqe_com, 0);
1870 bf_set(wqe_irsplen, &wqe->fcp_tsend.wqe_com, 0);
1874 case NVMET_FCOP_WRITEDATA:
1875 /* Words 0 - 2 : The first sg segment */
1876 txrdy = pci_pool_alloc(phba->txrdy_payload_pool,
1877 GFP_KERNEL, &physaddr);
1879 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
1880 "6041 Bad txrdy buffer: oxid x%x\n",
1884 ctxp->txrdy = txrdy;
1885 ctxp->txrdy_phys = physaddr;
1886 wqe->fcp_treceive.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1887 wqe->fcp_treceive.bde.tus.f.bdeSize = TXRDY_PAYLOAD_LEN;
1888 wqe->fcp_treceive.bde.addrLow =
1889 cpu_to_le32(putPaddrLow(physaddr));
1890 wqe->fcp_treceive.bde.addrHigh =
1891 cpu_to_le32(putPaddrHigh(physaddr));
1894 wqe->fcp_treceive.payload_offset_len = TXRDY_PAYLOAD_LEN;
1897 wqe->fcp_treceive.relative_offset = ctxp->offset;
1902 bf_set(wqe_ctxt_tag, &wqe->fcp_treceive.wqe_com,
1903 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
1904 bf_set(wqe_xri_tag, &wqe->fcp_treceive.wqe_com,
1905 nvmewqe->sli4_xritag);
1908 bf_set(wqe_ar, &wqe->fcp_treceive.wqe_com, 0);
1909 bf_set(wqe_cmnd, &wqe->fcp_treceive.wqe_com,
1910 CMD_FCP_TRECEIVE64_WQE);
1913 wqe->fcp_treceive.wqe_com.abort_tag = nvmewqe->iotag;
1916 bf_set(wqe_reqtag, &wqe->fcp_treceive.wqe_com, nvmewqe->iotag);
1917 bf_set(wqe_rcvoxid, &wqe->fcp_treceive.wqe_com, ctxp->oxid);
1920 bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1);
1921 bf_set(wqe_dbde, &wqe->fcp_treceive.wqe_com, 1);
1922 bf_set(wqe_iod, &wqe->fcp_treceive.wqe_com, LPFC_WQE_IOD_READ);
1923 bf_set(wqe_lenloc, &wqe->fcp_treceive.wqe_com,
1924 LPFC_WQE_LENLOC_WORD12);
1925 bf_set(wqe_xc, &wqe->fcp_treceive.wqe_com, xc);
1926 bf_set(wqe_wqes, &wqe->fcp_treceive.wqe_com, 0);
1927 bf_set(wqe_irsp, &wqe->fcp_treceive.wqe_com, 0);
1928 bf_set(wqe_irsplen, &wqe->fcp_treceive.wqe_com, 0);
1929 bf_set(wqe_nvme, &wqe->fcp_treceive.wqe_com, 1);
1930 if (phba->cfg_nvme_oas)
1931 bf_set(wqe_oas, &wqe->fcp_treceive.wqe_com, 1);
1934 bf_set(wqe_cqid, &wqe->fcp_treceive.wqe_com,
1935 LPFC_WQE_CQ_ID_DEFAULT);
1936 bf_set(wqe_cmd_type, &wqe->fcp_treceive.wqe_com,
1937 FCP_COMMAND_TRECEIVE);
1938 bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0);
1941 wqe->fcp_tsend.fcp_data_len = rsp->transfer_length;
1943 /* Setup 1 TXRDY and 1 SKIP SGE */
1945 txrdy[1] = cpu_to_be32(rsp->transfer_length);
1948 sgl->addr_hi = putPaddrHigh(physaddr);
1949 sgl->addr_lo = putPaddrLow(physaddr);
1951 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
1952 sgl->word2 = cpu_to_le32(sgl->word2);
1953 sgl->sge_len = cpu_to_le32(TXRDY_PAYLOAD_LEN);
1958 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP);
1959 sgl->word2 = cpu_to_le32(sgl->word2);
1962 atomic_inc(&tgtp->xmt_fcp_write);
1965 case NVMET_FCOP_RSP:
1967 physaddr = rsp->rspdma;
1968 wqe->fcp_trsp.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1969 wqe->fcp_trsp.bde.tus.f.bdeSize = rsp->rsplen;
1970 wqe->fcp_trsp.bde.addrLow =
1971 cpu_to_le32(putPaddrLow(physaddr));
1972 wqe->fcp_trsp.bde.addrHigh =
1973 cpu_to_le32(putPaddrHigh(physaddr));
1976 wqe->fcp_trsp.response_len = rsp->rsplen;
1979 wqe->fcp_trsp.rsvd_4_5[0] = 0;
1985 bf_set(wqe_ctxt_tag, &wqe->fcp_trsp.wqe_com,
1986 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
1987 bf_set(wqe_xri_tag, &wqe->fcp_trsp.wqe_com,
1988 nvmewqe->sli4_xritag);
1991 bf_set(wqe_ag, &wqe->fcp_trsp.wqe_com, 1);
1992 bf_set(wqe_cmnd, &wqe->fcp_trsp.wqe_com, CMD_FCP_TRSP64_WQE);
1995 wqe->fcp_trsp.wqe_com.abort_tag = nvmewqe->iotag;
1998 bf_set(wqe_reqtag, &wqe->fcp_trsp.wqe_com, nvmewqe->iotag);
1999 bf_set(wqe_rcvoxid, &wqe->fcp_trsp.wqe_com, ctxp->oxid);
2002 bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1);
2003 bf_set(wqe_dbde, &wqe->fcp_trsp.wqe_com, 0);
2004 bf_set(wqe_iod, &wqe->fcp_trsp.wqe_com, LPFC_WQE_IOD_WRITE);
2005 bf_set(wqe_lenloc, &wqe->fcp_trsp.wqe_com,
2006 LPFC_WQE_LENLOC_WORD3);
2007 bf_set(wqe_xc, &wqe->fcp_trsp.wqe_com, xc);
2008 bf_set(wqe_nvme, &wqe->fcp_trsp.wqe_com, 1);
2009 if (phba->cfg_nvme_oas)
2010 bf_set(wqe_oas, &wqe->fcp_trsp.wqe_com, 1);
2013 bf_set(wqe_cqid, &wqe->fcp_trsp.wqe_com,
2014 LPFC_WQE_CQ_ID_DEFAULT);
2015 bf_set(wqe_cmd_type, &wqe->fcp_trsp.wqe_com,
2017 bf_set(wqe_sup, &wqe->fcp_tsend.wqe_com, 0);
2019 if (rsp->rsplen == LPFC_NVMET_SUCCESS_LEN) {
2020 /* Good response - all zero's on wire */
2021 bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 0);
2022 bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 0);
2023 bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com, 0);
2025 bf_set(wqe_wqes, &wqe->fcp_trsp.wqe_com, 1);
2026 bf_set(wqe_irsp, &wqe->fcp_trsp.wqe_com, 1);
2027 bf_set(wqe_irsplen, &wqe->fcp_trsp.wqe_com,
2028 ((rsp->rsplen >> 2) - 1));
2029 memcpy(&wqe->words[16], rsp->rspaddr, rsp->rsplen);
2032 /* Use rspbuf, NOT sg list */
2035 atomic_inc(&tgtp->xmt_fcp_rsp);
2039 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_IOERR,
2040 "6064 Unknown Rsp Op %d\n",
2046 nvmewqe->vport = phba->pport;
2047 nvmewqe->drvrTimeout = (phba->fc_ratov * 3) + LPFC_DRVR_TIMEOUT;
2048 nvmewqe->context1 = ndlp;
2050 for (i = 0; i < rsp->sg_cnt; i++) {
2052 physaddr = sg_dma_address(sgel);
2053 cnt = sg_dma_len(sgel);
2054 sgl->addr_hi = putPaddrHigh(physaddr);
2055 sgl->addr_lo = putPaddrLow(physaddr);
2057 bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
2058 bf_set(lpfc_sli4_sge_offset, sgl, ctxp->offset);
2059 if ((i+1) == rsp->sg_cnt)
2060 bf_set(lpfc_sli4_sge_last, sgl, 1);
2061 sgl->word2 = cpu_to_le32(sgl->word2);
2062 sgl->sge_len = cpu_to_le32(cnt);
2064 ctxp->offset += cnt;
2066 ctxp->state = LPFC_NVMET_STE_DATA;
2072 * lpfc_nvmet_sol_fcp_abort_cmp - Completion handler for ABTS
2073 * @phba: Pointer to HBA context object.
2074 * @cmdwqe: Pointer to driver command WQE object.
2075 * @wcqe: Pointer to driver response CQE object.
2077 * The function is called from SLI ring event handler with no
2078 * lock held. This function is the completion handler for NVME ABTS for FCP cmds
2079 * The function frees memory resources used for the NVME commands.
2082 lpfc_nvmet_sol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
2083 struct lpfc_wcqe_complete *wcqe)
2085 struct lpfc_nvmet_rcv_ctx *ctxp;
2086 struct lpfc_nvmet_tgtport *tgtp;
2087 uint32_t status, result;
2088 unsigned long flags;
2089 bool released = false;
2091 ctxp = cmdwqe->context2;
2092 status = bf_get(lpfc_wcqe_c_status, wcqe);
2093 result = wcqe->parameter;
2095 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2096 if (ctxp->flag & LPFC_NVMET_ABORT_OP)
2097 atomic_inc(&tgtp->xmt_fcp_abort_cmpl);
2099 ctxp->state = LPFC_NVMET_STE_DONE;
2101 /* Check if we already received a free context call
2102 * and we have completed processing an abort situation.
2104 spin_lock_irqsave(&ctxp->ctxlock, flags);
2105 if ((ctxp->flag & LPFC_NVMET_CTX_RLS) &&
2106 !(ctxp->flag & LPFC_NVMET_XBUSY)) {
2107 list_del(&ctxp->list);
2110 ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
2111 spin_unlock_irqrestore(&ctxp->ctxlock, flags);
2112 atomic_inc(&tgtp->xmt_abort_rsp);
2114 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2115 "6165 ABORT cmpl: xri x%x flg x%x (%d) "
2116 "WCQE: %08x %08x %08x %08x\n",
2117 ctxp->oxid, ctxp->flag, released,
2118 wcqe->word0, wcqe->total_data_placed,
2119 result, wcqe->word3);
2121 cmdwqe->context2 = NULL;
2122 cmdwqe->context3 = NULL;
2124 * if transport has released ctx, then can reuse it. Otherwise,
2125 * will be recycled by transport release call.
2128 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
2130 /* This is the iocbq for the abort, not the command */
2131 lpfc_sli_release_iocbq(phba, cmdwqe);
2133 /* Since iaab/iaar are NOT set, there is no work left.
2134 * For LPFC_NVMET_XBUSY, lpfc_sli4_nvmet_xri_aborted
2135 * should have been called already.
2140 * lpfc_nvmet_unsol_fcp_abort_cmp - Completion handler for ABTS
2141 * @phba: Pointer to HBA context object.
2142 * @cmdwqe: Pointer to driver command WQE object.
2143 * @wcqe: Pointer to driver response CQE object.
2145 * The function is called from SLI ring event handler with no
2146 * lock held. This function is the completion handler for NVME ABTS for FCP cmds
2147 * The function frees memory resources used for the NVME commands.
2150 lpfc_nvmet_unsol_fcp_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
2151 struct lpfc_wcqe_complete *wcqe)
2153 struct lpfc_nvmet_rcv_ctx *ctxp;
2154 struct lpfc_nvmet_tgtport *tgtp;
2155 unsigned long flags;
2156 uint32_t status, result;
2157 bool released = false;
2159 ctxp = cmdwqe->context2;
2160 status = bf_get(lpfc_wcqe_c_status, wcqe);
2161 result = wcqe->parameter;
2164 /* if context is clear, related io alrady complete */
2165 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2166 "6070 ABTS cmpl: WCQE: %08x %08x %08x %08x\n",
2167 wcqe->word0, wcqe->total_data_placed,
2168 result, wcqe->word3);
2172 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2173 if (ctxp->flag & LPFC_NVMET_ABORT_OP)
2174 atomic_inc(&tgtp->xmt_fcp_abort_cmpl);
2177 if (ctxp->state != LPFC_NVMET_STE_ABORT) {
2178 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2179 "6112 ABTS Wrong state:%d oxid x%x\n",
2180 ctxp->state, ctxp->oxid);
2183 /* Check if we already received a free context call
2184 * and we have completed processing an abort situation.
2186 ctxp->state = LPFC_NVMET_STE_DONE;
2187 spin_lock_irqsave(&ctxp->ctxlock, flags);
2188 if ((ctxp->flag & LPFC_NVMET_CTX_RLS) &&
2189 !(ctxp->flag & LPFC_NVMET_XBUSY)) {
2190 list_del(&ctxp->list);
2193 ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
2194 spin_unlock_irqrestore(&ctxp->ctxlock, flags);
2195 atomic_inc(&tgtp->xmt_abort_rsp);
2197 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2198 "6316 ABTS cmpl xri x%x flg x%x (%x) "
2199 "WCQE: %08x %08x %08x %08x\n",
2200 ctxp->oxid, ctxp->flag, released,
2201 wcqe->word0, wcqe->total_data_placed,
2202 result, wcqe->word3);
2204 cmdwqe->context2 = NULL;
2205 cmdwqe->context3 = NULL;
2207 * if transport has released ctx, then can reuse it. Otherwise,
2208 * will be recycled by transport release call.
2211 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
2213 /* Since iaab/iaar are NOT set, there is no work left.
2214 * For LPFC_NVMET_XBUSY, lpfc_sli4_nvmet_xri_aborted
2215 * should have been called already.
2220 * lpfc_nvmet_xmt_ls_abort_cmp - Completion handler for ABTS
2221 * @phba: Pointer to HBA context object.
2222 * @cmdwqe: Pointer to driver command WQE object.
2223 * @wcqe: Pointer to driver response CQE object.
2225 * The function is called from SLI ring event handler with no
2226 * lock held. This function is the completion handler for NVME ABTS for LS cmds
2227 * The function frees memory resources used for the NVME commands.
2230 lpfc_nvmet_xmt_ls_abort_cmp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe,
2231 struct lpfc_wcqe_complete *wcqe)
2233 struct lpfc_nvmet_rcv_ctx *ctxp;
2234 struct lpfc_nvmet_tgtport *tgtp;
2235 uint32_t status, result;
2237 ctxp = cmdwqe->context2;
2238 status = bf_get(lpfc_wcqe_c_status, wcqe);
2239 result = wcqe->parameter;
2241 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2242 atomic_inc(&tgtp->xmt_ls_abort_cmpl);
2244 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2245 "6083 Abort cmpl: ctx %p WCQE:%08x %08x %08x %08x\n",
2246 ctxp, wcqe->word0, wcqe->total_data_placed,
2247 result, wcqe->word3);
2250 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2251 "6415 NVMET LS Abort No ctx: WCQE: "
2252 "%08x %08x %08x %08x\n",
2253 wcqe->word0, wcqe->total_data_placed,
2254 result, wcqe->word3);
2256 lpfc_sli_release_iocbq(phba, cmdwqe);
2260 if (ctxp->state != LPFC_NVMET_STE_LS_ABORT) {
2261 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
2262 "6416 NVMET LS abort cmpl state mismatch: "
2263 "oxid x%x: %d %d\n",
2264 ctxp->oxid, ctxp->state, ctxp->entry_cnt);
2267 cmdwqe->context2 = NULL;
2268 cmdwqe->context3 = NULL;
2269 lpfc_sli_release_iocbq(phba, cmdwqe);
2274 lpfc_nvmet_unsol_issue_abort(struct lpfc_hba *phba,
2275 struct lpfc_nvmet_rcv_ctx *ctxp,
2276 uint32_t sid, uint16_t xri)
2278 struct lpfc_nvmet_tgtport *tgtp;
2279 struct lpfc_iocbq *abts_wqeq;
2280 union lpfc_wqe *wqe_abts;
2281 struct lpfc_nodelist *ndlp;
2283 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2284 "6067 ABTS: sid %x xri x%x/x%x\n",
2285 sid, xri, ctxp->wqeq->sli4_xritag);
2287 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2289 ndlp = lpfc_findnode_did(phba->pport, sid);
2290 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
2291 ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2292 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
2293 atomic_inc(&tgtp->xmt_abort_rsp_error);
2294 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2295 "6134 Drop ABTS - wrong NDLP state x%x.\n",
2296 (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE);
2298 /* No failure to an ABTS request. */
2302 abts_wqeq = ctxp->wqeq;
2303 wqe_abts = &abts_wqeq->wqe;
2306 * Since we zero the whole WQE, we need to ensure we set the WQE fields
2307 * that were initialized in lpfc_sli4_nvmet_alloc.
2309 memset(wqe_abts, 0, sizeof(union lpfc_wqe));
2312 bf_set(wqe_dfctl, &wqe_abts->xmit_sequence.wge_ctl, 0);
2313 bf_set(wqe_ls, &wqe_abts->xmit_sequence.wge_ctl, 1);
2314 bf_set(wqe_la, &wqe_abts->xmit_sequence.wge_ctl, 0);
2315 bf_set(wqe_rctl, &wqe_abts->xmit_sequence.wge_ctl, FC_RCTL_BA_ABTS);
2316 bf_set(wqe_type, &wqe_abts->xmit_sequence.wge_ctl, FC_TYPE_BLS);
2319 bf_set(wqe_ctxt_tag, &wqe_abts->xmit_sequence.wqe_com,
2320 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
2321 bf_set(wqe_xri_tag, &wqe_abts->xmit_sequence.wqe_com,
2322 abts_wqeq->sli4_xritag);
2325 bf_set(wqe_cmnd, &wqe_abts->xmit_sequence.wqe_com,
2326 CMD_XMIT_SEQUENCE64_WQE);
2327 bf_set(wqe_ct, &wqe_abts->xmit_sequence.wqe_com, SLI4_CT_RPI);
2328 bf_set(wqe_class, &wqe_abts->xmit_sequence.wqe_com, CLASS3);
2329 bf_set(wqe_pu, &wqe_abts->xmit_sequence.wqe_com, 0);
2332 wqe_abts->xmit_sequence.wqe_com.abort_tag = abts_wqeq->iotag;
2335 bf_set(wqe_reqtag, &wqe_abts->xmit_sequence.wqe_com, abts_wqeq->iotag);
2336 /* Needs to be set by caller */
2337 bf_set(wqe_rcvoxid, &wqe_abts->xmit_sequence.wqe_com, xri);
2340 bf_set(wqe_dbde, &wqe_abts->xmit_sequence.wqe_com, 1);
2341 bf_set(wqe_iod, &wqe_abts->xmit_sequence.wqe_com, LPFC_WQE_IOD_WRITE);
2342 bf_set(wqe_lenloc, &wqe_abts->xmit_sequence.wqe_com,
2343 LPFC_WQE_LENLOC_WORD12);
2344 bf_set(wqe_ebde_cnt, &wqe_abts->xmit_sequence.wqe_com, 0);
2345 bf_set(wqe_qosd, &wqe_abts->xmit_sequence.wqe_com, 0);
2348 bf_set(wqe_cqid, &wqe_abts->xmit_sequence.wqe_com,
2349 LPFC_WQE_CQ_ID_DEFAULT);
2350 bf_set(wqe_cmd_type, &wqe_abts->xmit_sequence.wqe_com,
2353 abts_wqeq->vport = phba->pport;
2354 abts_wqeq->context1 = ndlp;
2355 abts_wqeq->context2 = ctxp;
2356 abts_wqeq->context3 = NULL;
2357 abts_wqeq->rsvd2 = 0;
2358 /* hba_wqidx should already be setup from command we are aborting */
2359 abts_wqeq->iocb.ulpCommand = CMD_XMIT_SEQUENCE64_CR;
2360 abts_wqeq->iocb.ulpLe = 1;
2362 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2363 "6069 Issue ABTS to xri x%x reqtag x%x\n",
2364 xri, abts_wqeq->iotag);
2369 lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *phba,
2370 struct lpfc_nvmet_rcv_ctx *ctxp,
2371 uint32_t sid, uint16_t xri)
2373 struct lpfc_nvmet_tgtport *tgtp;
2374 struct lpfc_iocbq *abts_wqeq;
2375 union lpfc_wqe *abts_wqe;
2376 struct lpfc_nodelist *ndlp;
2377 unsigned long flags;
2380 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2382 ctxp->wqeq = ctxp->ctxbuf->iocbq;
2383 ctxp->wqeq->hba_wqidx = 0;
2386 ndlp = lpfc_findnode_did(phba->pport, sid);
2387 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
2388 ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2389 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
2390 atomic_inc(&tgtp->xmt_abort_rsp_error);
2391 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2392 "6160 Drop ABORT - wrong NDLP state x%x.\n",
2393 (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE);
2395 /* No failure to an ABTS request. */
2396 ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
2400 /* Issue ABTS for this WQE based on iotag */
2401 ctxp->abort_wqeq = lpfc_sli_get_iocbq(phba);
2402 if (!ctxp->abort_wqeq) {
2403 atomic_inc(&tgtp->xmt_abort_rsp_error);
2404 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2405 "6161 ABORT failed: No wqeqs: "
2406 "xri: x%x\n", ctxp->oxid);
2407 /* No failure to an ABTS request. */
2408 ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
2411 abts_wqeq = ctxp->abort_wqeq;
2412 abts_wqe = &abts_wqeq->wqe;
2413 ctxp->state = LPFC_NVMET_STE_ABORT;
2415 /* Announce entry to new IO submit field. */
2416 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
2417 "6162 ABORT Request to rport DID x%06x "
2418 "for xri x%x x%x\n",
2419 ctxp->sid, ctxp->oxid, ctxp->wqeq->sli4_xritag);
2421 /* If the hba is getting reset, this flag is set. It is
2422 * cleared when the reset is complete and rings reestablished.
2424 spin_lock_irqsave(&phba->hbalock, flags);
2425 /* driver queued commands are in process of being flushed */
2426 if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) {
2427 spin_unlock_irqrestore(&phba->hbalock, flags);
2428 atomic_inc(&tgtp->xmt_abort_rsp_error);
2429 lpfc_printf_log(phba, KERN_ERR, LOG_NVME,
2430 "6163 Driver in reset cleanup - flushing "
2431 "NVME Req now. hba_flag x%x oxid x%x\n",
2432 phba->hba_flag, ctxp->oxid);
2433 lpfc_sli_release_iocbq(phba, abts_wqeq);
2434 ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
2438 /* Outstanding abort is in progress */
2439 if (abts_wqeq->iocb_flag & LPFC_DRIVER_ABORTED) {
2440 spin_unlock_irqrestore(&phba->hbalock, flags);
2441 atomic_inc(&tgtp->xmt_abort_rsp_error);
2442 lpfc_printf_log(phba, KERN_ERR, LOG_NVME,
2443 "6164 Outstanding NVME I/O Abort Request "
2444 "still pending on oxid x%x\n",
2446 lpfc_sli_release_iocbq(phba, abts_wqeq);
2447 ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
2451 /* Ready - mark outstanding as aborted by driver. */
2452 abts_wqeq->iocb_flag |= LPFC_DRIVER_ABORTED;
2454 /* WQEs are reused. Clear stale data and set key fields to
2455 * zero like ia, iaab, iaar, xri_tag, and ctxt_tag.
2457 memset(abts_wqe, 0, sizeof(union lpfc_wqe));
2460 bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG);
2463 bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0);
2464 bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
2466 /* word 8 - tell the FW to abort the IO associated with this
2467 * outstanding exchange ID.
2469 abts_wqe->abort_cmd.wqe_com.abort_tag = ctxp->wqeq->sli4_xritag;
2471 /* word 9 - this is the iotag for the abts_wqe completion. */
2472 bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com,
2476 bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1);
2477 bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
2480 bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND);
2481 bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1);
2482 bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
2484 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
2485 abts_wqeq->hba_wqidx = ctxp->wqeq->hba_wqidx;
2486 abts_wqeq->wqe_cmpl = lpfc_nvmet_sol_fcp_abort_cmp;
2487 abts_wqeq->iocb_cmpl = 0;
2488 abts_wqeq->iocb_flag |= LPFC_IO_NVME;
2489 abts_wqeq->context2 = ctxp;
2490 rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq);
2491 spin_unlock_irqrestore(&phba->hbalock, flags);
2492 if (rc == WQE_SUCCESS) {
2493 atomic_inc(&tgtp->xmt_abort_sol);
2497 atomic_inc(&tgtp->xmt_abort_rsp_error);
2498 ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
2499 lpfc_sli_release_iocbq(phba, abts_wqeq);
2500 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2501 "6166 Failed ABORT issue_wqe with status x%x "
2509 lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *phba,
2510 struct lpfc_nvmet_rcv_ctx *ctxp,
2511 uint32_t sid, uint16_t xri)
2513 struct lpfc_nvmet_tgtport *tgtp;
2514 struct lpfc_iocbq *abts_wqeq;
2515 unsigned long flags;
2518 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2520 ctxp->wqeq = ctxp->ctxbuf->iocbq;
2521 ctxp->wqeq->hba_wqidx = 0;
2524 if (ctxp->state == LPFC_NVMET_STE_FREE) {
2525 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
2526 "6417 NVMET ABORT ctx freed %d %d oxid x%x\n",
2527 ctxp->state, ctxp->entry_cnt, ctxp->oxid);
2531 ctxp->state = LPFC_NVMET_STE_ABORT;
2533 rc = lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri);
2537 spin_lock_irqsave(&phba->hbalock, flags);
2538 abts_wqeq = ctxp->wqeq;
2539 abts_wqeq->wqe_cmpl = lpfc_nvmet_unsol_fcp_abort_cmp;
2540 abts_wqeq->iocb_cmpl = NULL;
2541 abts_wqeq->iocb_flag |= LPFC_IO_NVMET;
2542 rc = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_wqeq);
2543 spin_unlock_irqrestore(&phba->hbalock, flags);
2544 if (rc == WQE_SUCCESS) {
2549 atomic_inc(&tgtp->xmt_abort_rsp_error);
2550 ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
2551 atomic_inc(&tgtp->xmt_abort_rsp_error);
2552 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2553 "6135 Failed to Issue ABTS for oxid x%x. Status x%x\n",
2559 lpfc_nvmet_unsol_ls_issue_abort(struct lpfc_hba *phba,
2560 struct lpfc_nvmet_rcv_ctx *ctxp,
2561 uint32_t sid, uint16_t xri)
2563 struct lpfc_nvmet_tgtport *tgtp;
2564 struct lpfc_iocbq *abts_wqeq;
2565 union lpfc_wqe *wqe_abts;
2566 unsigned long flags;
2569 if ((ctxp->state == LPFC_NVMET_STE_LS_RCV && ctxp->entry_cnt == 1) ||
2570 (ctxp->state == LPFC_NVMET_STE_LS_RSP && ctxp->entry_cnt == 2)) {
2571 ctxp->state = LPFC_NVMET_STE_LS_ABORT;
2574 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
2575 "6418 NVMET LS abort state mismatch "
2577 ctxp->oxid, ctxp->state, ctxp->entry_cnt);
2578 ctxp->state = LPFC_NVMET_STE_LS_ABORT;
2581 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2583 /* Issue ABTS for this WQE based on iotag */
2584 ctxp->wqeq = lpfc_sli_get_iocbq(phba);
2586 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2587 "6068 Abort failed: No wqeqs: "
2589 /* No failure to an ABTS request. */
2594 abts_wqeq = ctxp->wqeq;
2595 wqe_abts = &abts_wqeq->wqe;
2597 if (lpfc_nvmet_unsol_issue_abort(phba, ctxp, sid, xri) == 0) {
2602 spin_lock_irqsave(&phba->hbalock, flags);
2603 abts_wqeq->wqe_cmpl = lpfc_nvmet_xmt_ls_abort_cmp;
2604 abts_wqeq->iocb_cmpl = 0;
2605 abts_wqeq->iocb_flag |= LPFC_IO_NVME_LS;
2606 rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, abts_wqeq);
2607 spin_unlock_irqrestore(&phba->hbalock, flags);
2608 if (rc == WQE_SUCCESS) {
2609 atomic_inc(&tgtp->xmt_abort_unsol);
2613 atomic_inc(&tgtp->xmt_abort_rsp_error);
2614 abts_wqeq->context2 = NULL;
2615 abts_wqeq->context3 = NULL;
2616 lpfc_sli_release_iocbq(phba, abts_wqeq);
2618 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,
2619 "6056 Failed to Issue ABTS. Status x%x\n", rc);