xref: /openbmc/linux/drivers/scsi/lpfc/lpfc_nvme.h (revision 2a5b7d62)
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Fibre Channel Host Bus Adapters.                                *
4  * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.  *
6  * Copyright (C) 2004-2016 Emulex.  All rights reserved.           *
7  * EMULEX and SLI are trademarks of Emulex.                        *
8  * www.broadcom.com                                                *
9  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
10  *                                                                 *
11  * This program is free software; you can redistribute it and/or   *
12  * modify it under the terms of version 2 of the GNU General       *
13  * Public License as published by the Free Software Foundation.    *
14  * This program is distributed in the hope that it will be useful. *
15  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
16  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
17  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
18  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
20  * more details, a copy of which can be found in the file COPYING  *
21  * included with this package.                                     *
22  ********************************************************************/
23 
24 #define LPFC_NVME_DEFAULT_SEGS		(64 + 1)	/* 256K IOs */
25 
26 #define LPFC_NVME_ERSP_LEN		0x20
27 
28 #define LPFC_NVME_WAIT_TMO              10
29 #define LPFC_NVME_EXPEDITE_XRICNT	8
30 #define LPFC_NVME_FB_SHIFT		9
31 #define LPFC_NVME_MAX_FB		(1 << 20)	/* 1M */
32 
33 #define lpfc_ndlp_get_nrport(ndlp)					\
34 	((!ndlp->nrport || (ndlp->upcall_flags & NLP_WAIT_FOR_UNREG))	\
35 	? NULL : ndlp->nrport)
36 
37 struct lpfc_nvme_qhandle {
38 	uint32_t index;		/* WQ index to use */
39 	uint32_t qidx;		/* queue index passed to create */
40 	uint32_t cpu_id;	/* current cpu id at time of create */
41 };
42 
43 struct lpfc_nvme_ctrl_stat {
44 	atomic_t fc4NvmeInputRequests;
45 	atomic_t fc4NvmeOutputRequests;
46 	atomic_t fc4NvmeControlRequests;
47 	atomic_t fc4NvmeIoCmpls;
48 };
49 
50 /* Declare nvme-based local and remote port definitions. */
51 struct lpfc_nvme_lport {
52 	struct lpfc_vport *vport;
53 	struct completion lport_unreg_done;
54 	/* Add stats counters here */
55 	struct lpfc_nvme_ctrl_stat *cstat;
56 	atomic_t fc4NvmeLsRequests;
57 	atomic_t fc4NvmeLsCmpls;
58 	atomic_t xmt_fcp_noxri;
59 	atomic_t xmt_fcp_bad_ndlp;
60 	atomic_t xmt_fcp_qdepth;
61 	atomic_t xmt_fcp_wqerr;
62 	atomic_t xmt_fcp_err;
63 	atomic_t xmt_fcp_abort;
64 	atomic_t xmt_ls_abort;
65 	atomic_t xmt_ls_err;
66 	atomic_t cmpl_fcp_xb;
67 	atomic_t cmpl_fcp_err;
68 	atomic_t cmpl_ls_xb;
69 	atomic_t cmpl_ls_err;
70 };
71 
72 struct lpfc_nvme_rport {
73 	struct lpfc_nvme_lport *lport;
74 	struct nvme_fc_remote_port *remoteport;
75 	struct lpfc_nodelist *ndlp;
76 	struct completion rport_unreg_done;
77 };
78 
79 struct lpfc_nvme_buf {
80 	struct list_head list;
81 	struct nvmefc_fcp_req *nvmeCmd;
82 	struct lpfc_nvme_rport *nrport;
83 	struct lpfc_nodelist *ndlp;
84 
85 	uint32_t timeout;
86 
87 	uint16_t flags;  /* TBD convert exch_busy to flags */
88 #define LPFC_SBUF_XBUSY         0x1     /* SLI4 hba reported XB on WCQE cmpl */
89 #define LPFC_BUMP_QDEPTH	0x2	/* bumped queue depth counter */
90 	uint16_t exch_busy;     /* SLI4 hba reported XB on complete WCQE */
91 	uint16_t status;	/* From IOCB Word 7- ulpStatus */
92 	uint16_t cpu;
93 	uint16_t qidx;
94 	uint16_t sqid;
95 	uint32_t result;	/* From IOCB Word 4. */
96 
97 	uint32_t   seg_cnt;	/* Number of scatter-gather segments returned by
98 				 * dma_map_sg.  The driver needs this for calls
99 				 * to dma_unmap_sg.
100 				 */
101 	dma_addr_t nonsg_phys;	/* Non scatter-gather physical address. */
102 
103 	/*
104 	 * data and dma_handle are the kernel virtual and bus address of the
105 	 * dma-able buffer containing the fcp_cmd, fcp_rsp and a scatter
106 	 * gather bde list that supports the sg_tablesize value.
107 	 */
108 	void *data;
109 	dma_addr_t dma_handle;
110 
111 	struct sli4_sge *nvme_sgl;
112 	dma_addr_t dma_phys_sgl;
113 
114 	/* cur_iocbq has phys of the dma-able buffer.
115 	 * Iotag is in here
116 	 */
117 	struct lpfc_iocbq cur_iocbq;
118 
119 	wait_queue_head_t *waitq;
120 	unsigned long start_time;
121 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
122 	uint64_t ts_cmd_start;
123 	uint64_t ts_last_cmd;
124 	uint64_t ts_cmd_wqput;
125 	uint64_t ts_isr_cmpl;
126 	uint64_t ts_data_nvme;
127 #endif
128 };
129 
130 struct lpfc_nvme_fcpreq_priv {
131 	struct lpfc_nvme_buf *nvme_buf;
132 };
133