xref: /openbmc/linux/drivers/scsi/lpfc/lpfc_nvme.h (revision 2a1160a0)
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Fibre Channel Host Bus Adapters.                                *
4  * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
5  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.  *
6  * Copyright (C) 2004-2016 Emulex.  All rights reserved.           *
7  * EMULEX and SLI are trademarks of Emulex.                        *
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 #include <linux/nvme.h>
25 #include <linux/nvme-fc-driver.h>
26 #include <linux/nvme-fc.h>
27 
28 #define LPFC_NVME_DEFAULT_SEGS		(64 + 1)	/* 256K IOs */
29 
30 #define LPFC_NVME_ERSP_LEN		0x20
31 
32 #define LPFC_NVME_WAIT_TMO              10
33 #define LPFC_NVME_EXPEDITE_XRICNT	8
34 #define LPFC_NVME_FB_SHIFT		9
35 #define LPFC_NVME_MAX_FB		(1 << 20)	/* 1M */
36 
37 #define LPFC_MAX_NVME_INFO_TMP_LEN	100
38 #define LPFC_NVME_INFO_MORE_STR		"\nCould be more info...\n"
39 
40 #define lpfc_ndlp_get_nrport(ndlp)					\
41 	((!ndlp->nrport || (ndlp->upcall_flags & NLP_WAIT_FOR_UNREG))	\
42 	? NULL : ndlp->nrport)
43 
44 struct lpfc_nvme_qhandle {
45 	uint32_t index;		/* WQ index to use */
46 	uint32_t qidx;		/* queue index passed to create */
47 	uint32_t cpu_id;	/* current cpu id at time of create */
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_cmp;
54 	/* Add stats counters here */
55 	atomic_t fc4NvmeLsRequests;
56 	atomic_t fc4NvmeLsCmpls;
57 	atomic_t xmt_fcp_noxri;
58 	atomic_t xmt_fcp_bad_ndlp;
59 	atomic_t xmt_fcp_qdepth;
60 	atomic_t xmt_fcp_wqerr;
61 	atomic_t xmt_fcp_err;
62 	atomic_t xmt_fcp_abort;
63 	atomic_t xmt_ls_abort;
64 	atomic_t xmt_ls_err;
65 	atomic_t cmpl_fcp_xb;
66 	atomic_t cmpl_fcp_err;
67 	atomic_t cmpl_ls_xb;
68 	atomic_t cmpl_ls_err;
69 };
70 
71 struct lpfc_nvme_rport {
72 	struct lpfc_nvme_lport *lport;
73 	struct nvme_fc_remote_port *remoteport;
74 	struct lpfc_nodelist *ndlp;
75 	struct completion rport_unreg_done;
76 };
77 
78 struct lpfc_nvme_fcpreq_priv {
79 	struct lpfc_io_buf *nvme_buf;
80 };
81 
82 
83 #define LPFC_NVMET_DEFAULT_SEGS		(64 + 1)	/* 256K IOs */
84 #define LPFC_NVMET_RQE_MIN_POST		128
85 #define LPFC_NVMET_RQE_DEF_POST		512
86 #define LPFC_NVMET_RQE_DEF_COUNT	2048
87 #define LPFC_NVMET_SUCCESS_LEN		12
88 
89 #define LPFC_NVMET_MRQ_AUTO		0
90 #define LPFC_NVMET_MRQ_MAX		16
91 
92 #define LPFC_NVMET_WAIT_TMO		(5 * MSEC_PER_SEC)
93 
94 /* Used for NVME Target */
95 struct lpfc_nvmet_tgtport {
96 	struct lpfc_hba *phba;
97 	struct completion *tport_unreg_cmp;
98 
99 	/* Stats counters - lpfc_nvmet_unsol_ls_buffer */
100 	atomic_t rcv_ls_req_in;
101 	atomic_t rcv_ls_req_out;
102 	atomic_t rcv_ls_req_drop;
103 	atomic_t xmt_ls_abort;
104 	atomic_t xmt_ls_abort_cmpl;
105 
106 	/* Stats counters - lpfc_nvmet_xmt_ls_rsp */
107 	atomic_t xmt_ls_rsp;
108 	atomic_t xmt_ls_drop;
109 
110 	/* Stats counters - lpfc_nvmet_xmt_ls_rsp_cmp */
111 	atomic_t xmt_ls_rsp_error;
112 	atomic_t xmt_ls_rsp_aborted;
113 	atomic_t xmt_ls_rsp_xb_set;
114 	atomic_t xmt_ls_rsp_cmpl;
115 
116 	/* Stats counters - lpfc_nvmet_unsol_fcp_buffer */
117 	atomic_t rcv_fcp_cmd_in;
118 	atomic_t rcv_fcp_cmd_out;
119 	atomic_t rcv_fcp_cmd_drop;
120 	atomic_t rcv_fcp_cmd_defer;
121 	atomic_t xmt_fcp_release;
122 
123 	/* Stats counters - lpfc_nvmet_xmt_fcp_op */
124 	atomic_t xmt_fcp_drop;
125 	atomic_t xmt_fcp_read_rsp;
126 	atomic_t xmt_fcp_read;
127 	atomic_t xmt_fcp_write;
128 	atomic_t xmt_fcp_rsp;
129 
130 	/* Stats counters - lpfc_nvmet_xmt_fcp_op_cmp */
131 	atomic_t xmt_fcp_rsp_xb_set;
132 	atomic_t xmt_fcp_rsp_cmpl;
133 	atomic_t xmt_fcp_rsp_error;
134 	atomic_t xmt_fcp_rsp_aborted;
135 	atomic_t xmt_fcp_rsp_drop;
136 
137 	/* Stats counters - lpfc_nvmet_xmt_fcp_abort */
138 	atomic_t xmt_fcp_xri_abort_cqe;
139 	atomic_t xmt_fcp_abort;
140 	atomic_t xmt_fcp_abort_cmpl;
141 	atomic_t xmt_abort_sol;
142 	atomic_t xmt_abort_unsol;
143 	atomic_t xmt_abort_rsp;
144 	atomic_t xmt_abort_rsp_error;
145 
146 	/* Stats counters - defer IO */
147 	atomic_t defer_ctx;
148 	atomic_t defer_fod;
149 	atomic_t defer_wqfull;
150 };
151 
152 struct lpfc_nvmet_ctx_info {
153 	struct list_head nvmet_ctx_list;
154 	spinlock_t	nvmet_ctx_list_lock; /* lock per CPU */
155 	struct lpfc_nvmet_ctx_info *nvmet_ctx_next_cpu;
156 	struct lpfc_nvmet_ctx_info *nvmet_ctx_start_cpu;
157 	uint16_t	nvmet_ctx_list_cnt;
158 	char pad[16];  /* pad to a cache-line */
159 };
160 
161 /* This retrieves the context info associated with the specified cpu / mrq */
162 #define lpfc_get_ctx_list(phba, cpu, mrq)  \
163 	(phba->sli4_hba.nvmet_ctx_info + ((cpu * phba->cfg_nvmet_mrq) + mrq))
164 
165 struct lpfc_nvmet_rcv_ctx {
166 	union {
167 		struct nvmefc_ls_rsp ls_rsp;
168 		struct nvmefc_tgt_fcp_req fcp_req;
169 	} ctx;
170 	struct list_head list;
171 	struct lpfc_hba *phba;
172 	struct lpfc_iocbq *wqeq;
173 	struct lpfc_iocbq *abort_wqeq;
174 	spinlock_t ctxlock; /* protect flag access */
175 	uint32_t sid;
176 	uint32_t offset;
177 	uint16_t oxid;
178 	uint16_t size;
179 	uint16_t entry_cnt;
180 	uint16_t cpu;
181 	uint16_t idx;
182 	uint16_t state;
183 	/* States */
184 #define LPFC_NVMET_STE_LS_RCV		1
185 #define LPFC_NVMET_STE_LS_ABORT		2
186 #define LPFC_NVMET_STE_LS_RSP		3
187 #define LPFC_NVMET_STE_RCV		4
188 #define LPFC_NVMET_STE_DATA		5
189 #define LPFC_NVMET_STE_ABORT		6
190 #define LPFC_NVMET_STE_DONE		7
191 #define LPFC_NVMET_STE_FREE		0xff
192 	uint16_t flag;
193 #define LPFC_NVMET_IO_INP		0x1  /* IO is in progress on exchange */
194 #define LPFC_NVMET_ABORT_OP		0x2  /* Abort WQE issued on exchange */
195 #define LPFC_NVMET_XBUSY		0x4  /* XB bit set on IO cmpl */
196 #define LPFC_NVMET_CTX_RLS		0x8  /* ctx free requested */
197 #define LPFC_NVMET_ABTS_RCV		0x10  /* ABTS received on exchange */
198 #define LPFC_NVMET_CTX_REUSE_WQ		0x20  /* ctx reused via WQ */
199 #define LPFC_NVMET_DEFER_WQFULL		0x40  /* Waiting on a free WQE */
200 #define LPFC_NVMET_TNOTIFY		0x80  /* notify transport of abts */
201 	struct rqb_dmabuf *rqb_buffer;
202 	struct lpfc_nvmet_ctxbuf *ctxbuf;
203 	struct lpfc_sli4_hdw_queue *hdwq;
204 
205 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
206 	uint64_t ts_isr_cmd;
207 	uint64_t ts_cmd_nvme;
208 	uint64_t ts_nvme_data;
209 	uint64_t ts_data_wqput;
210 	uint64_t ts_isr_data;
211 	uint64_t ts_data_nvme;
212 	uint64_t ts_nvme_status;
213 	uint64_t ts_status_wqput;
214 	uint64_t ts_isr_status;
215 	uint64_t ts_status_nvme;
216 #endif
217 };
218 
219 
220 /* routines found in lpfc_nvme.c */
221 
222 /* routines found in lpfc_nvmet.c */
223