xref: /linux/drivers/scsi/fnic/fnic_nvme.h (revision 35748ddd3b2c91555bd86b8cf88edc90e7317e57)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
4  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
5  */
6 #ifndef _FNIC_NVME_H
7 #define _FNIC_NVME_H
8 
9 #include "fdls_fc.h"
10 #include "fnic_fdls.h"
11 
12 #define FNIC_NVME_TPORT_REMOVE_WAIT (5 * 1000)
13 #define FNIC_NVME_TPORT_LIST_EMPTY_WAIT (FNIC_NVME_TPORT_REMOVE_WAIT * 2)
14 #define FNIC_TPORT_CLEANUP_WAIT_COUNT 8
15 #define FNIC_NVME_LPORT_REMOVE_WAIT (2 * 60 * 1000)
16 
17 #define FNIC_LS_REQ_FLAGS_NONE      0x0
18 #define FNIC_LS_REQ_FLAGS_ABORTED   0x1
19 #define FNIC_LS_REQ_FLAGS_DONE      0x2
20 #define FNIC_LS_REQ_ABORT_COMPLETED 0x4
21 #define FNIC_STATUS_LS_REQ_ABORTED 0x1
22 
23 #define FNIC_LS_REQ_MIN_TMO_SECS (2)
24 #define FNIC_LS_REQ_MAX_TMO_SECS (5)
25 #define FNIC_NVME_ADMIN_IO_TIMEOUT 30000	/* mSec */
26 #define FNIC_NVME_NO_FREE_TAG     (0xFFFF)
27 
28 #define FNIC_LS_REQ_TMO_MSECS(tmo)    (((tmo >= FNIC_LS_REQ_MIN_TMO_SECS) && \
29 					(tmo <= FNIC_LS_REQ_MAX_TMO_SECS)) ? \
30 					(tmo * 1000) : (FNIC_LS_REQ_MIN_TMO_SECS * 1000))
31 
32 #define IS_ADMIN_IO(_io_req)     \
33 	(NVME_CMD_FLAGS(_io_req) & FNIC_NVME_ADMIN_IO_TIMER_PENDING)
34 
35 extern unsigned int nvme_max_ios_to_process;
36 extern unsigned int nvme_dev_loss_tmo;
37 extern spinlock_t fnic_list_lock;
38 
39 enum nvfnic_lsreq_state_e {
40 	FNIC_LS_REQ_CMD_INIT = 0,
41 	FNIC_LS_REQ_CMD_PENDING,
42 	FNIC_LS_REQ_CMD_ABTS_PENDING,
43 	FNIC_LS_REQ_CMD_COMPLETE,
44 	FNIC_LS_REQ_ABTS_COMPLETE,
45 	FNIC_LS_REQ_CMD_ABTS_STARTED,
46 };
47 
48 struct fnic_nvme_tag {
49 	struct list_head free_list;
50 	int tag_id;
51 };
52 
53 struct nvfnic_ls_req {
54 	struct list_head list;
55 	struct nvmefc_ls_req *ls_req;
56 	uint16_t oxid;
57 	struct timer_list ls_req_timer;
58 	struct fnic *fnic;
59 	struct fnic_tport_s *tport;
60 	int state;
61 	unsigned int flags;
62 };
63 
64 #if IS_REACHABLE(CONFIG_NVME_FC)
65 int nvfnic_nvme_io_done_handler(void *arg);
66 struct fnic_io_req *nvfnic_find_io_req_by_tag(struct fnic *fnic, uint16_t tag);
67 void nvfnic_reset_fcpio_tag_pool(struct fnic_iport_s *iport);
68 int nvfnic_add_lport(struct fnic *fnic);
69 void nvfnic_fcpio_abort(struct nvme_fc_local_port *lport,
70 			struct nvme_fc_remote_port *rport,
71 			void *hw_queue_handle, struct nvmefc_fcp_req *fcp_req);
72 void nvfnic_remote_port_delete(struct nvme_fc_remote_port *rport);
73 void nvfnic_local_port_delete(struct nvme_fc_local_port *lport);
74 int nvfnic_dma_map_sgl(struct fnic *fnic, struct fnic_io_req *io_req,
75 		       int sg_count);
76 void nvfnic_dma_unmap_sgl(struct fnic *fnic, struct fnic_io_req *io_req);
77 int nvfnic_get_sg_count(struct fnic_io_req *io_req);
78 void nvfnic_release_nvme_ioreq_buf(struct fnic_iport_s *iport,
79 				   struct fnic_io_req *io_req);
80 void nvfnic_dump_nvcmd(struct fnic_io_req *io_req, uint8_t flags);
81 bool _cleanup_tport_io(struct sbitmap *map, unsigned int tag, void *data);
82 void nvfnic_flush_nvme_io_list(struct fnic *fnic);
83 void nvfnic_fcpio_cmpl(struct fnic_io_req *io_req);
84 bool nvfnic_transport_ready(struct fnic_iport_s *iport,
85 			    struct fnic_tport_s *tport);
86 int nvfnic_alloc_fcpio_tag(struct fnic_iport_s *iport,
87 				struct fnic_io_req *io_req);
88 int nvfnic_queuecommand(struct fnic_io_req *io_req);
89 void nvfnic_free_fcpio_tag(struct fnic_iport_s *iport,
90 			   struct fnic_io_req *io_req);
91 void nvfnic_delete_lport(struct fnic_iport_s *iport);
92 int nvfnic_add_tport(struct fnic *fnic, struct fnic_tport_s *tport,
93 		     unsigned long flags);
94 void nvfnic_cleanup_all_nvme_ios(struct fnic *fnic);
95 void nvfnic_delete_tport_work(struct work_struct *work);
96 void nvfnic_delete_tport(struct fnic_iport_s *iport,
97 			 struct fnic_tport_s *tport, unsigned long flags);
98 void nvfnic_fcpio_nvme_fast_cmpl_handler(struct fnic *fnic,
99 					 struct fcpio_fw_req *desc);
100 void nvfnic_ls_rsp_recv(struct fnic_iport_s *iport,
101 			struct fc_frame_header *fchdr, int len);
102 void nvfnic_process_ls_abts_rsp(struct fnic_iport_s *iport,
103 				struct fc_frame_header *fchdr);
104 void nvfnic_admin_io_timeout(struct timer_list *t);
105 void nvfnic_fcpio_nvme_itmf_cmpl_handler(struct fnic *fnic,
106 					 struct fcpio_fw_req *desc);
107 void nvfnic_nvme_zero_devloss_tports(struct fnic *fnic);
108 bool nvfnic_queue_abort_io_req(struct fnic *fnic, int tag, u32 task_req,
109 			       struct fnic_io_req *io_req);
110 void nvfnic_ls_req_abort(struct nvme_fc_local_port *lport,
111 			 struct nvme_fc_remote_port *rport,
112 			 struct nvmefc_ls_req *lsreq);
113 int nvfnic_create_queue(struct nvme_fc_local_port *lport, unsigned int idx,
114 			u16 size, void **handle);
115 int nvfnic_ls_req_send(struct nvme_fc_local_port *lport,
116 		       struct nvme_fc_remote_port *rport,
117 		       struct nvmefc_ls_req *ls_req);
118 void nvfnic_ls_req_timeout(struct timer_list *t);
119 uint16_t nvfnic_alloc_ls_req_oxid(struct fnic_iport_s *iport);
120 struct nvfnic_ls_req *nvfnic_find_ls_req(struct fnic_tport_s *tport,
121 					 uint16_t oxid);
122 void nvfnic_terminate_tport_ios(struct fnic *fnic, struct fnic_tport_s *tport);
123 bool _terminate_tport_ios(struct sbitmap *map, unsigned int tag, void *data);
124 bool _cleanup_all_nvme_io(struct sbitmap *map, unsigned int tag, void *data);
125 void nvfnic_cleanup_all_nvme_ios(struct fnic *fnic);
126 int nvfnic_fcpio_send(struct nvme_fc_local_port *lport,
127 		      struct nvme_fc_remote_port *rport, void *hw_queue_handle,
128 		      struct nvmefc_fcp_req *fcp_req);
129 void nvfnic_fcpio_ersp_cmpl_handler(struct fnic *fnic,
130 				    struct fcpio_fw_req *desc, int sw_flag);
131 void nvfnic_terminate_tport_ls_reqs(struct fnic *fnic,
132 				    struct fnic_tport_s *tport);
133 void nvfnic_terminate_tport_admin_ios(struct fnic *fnic,
134 				      struct fnic_tport_s *tport);
135 void nvfnic_cleanup_tport_io(struct fnic *fnic, struct fnic_tport_s *tport);
136 void nvfnic_nvme_unload(struct fnic *fnic);
137 int nvfnic_get_nvmef_info(struct fnic *fnic, struct fnic_nvmef_info *info);
138 void nvfnic_exch_reset(struct fnic_iport_s *iport, struct fnic_tport_s *tport);
139 void nvfnic_nvme_iodone_work(struct work_struct *work);
140 #else
141 static inline int nvfnic_add_lport(struct fnic *fnic)
142 {
143 	return -EOPNOTSUPP;
144 }
145 
146 static inline void nvfnic_nvme_unload(struct fnic *fnic)
147 {
148 }
149 
150 static inline void nvfnic_flush_nvme_io_list(struct fnic *fnic)
151 {
152 }
153 
154 static inline void nvfnic_nvme_iodone_work(struct work_struct *work)
155 {
156 }
157 
158 static inline void nvfnic_exch_reset(struct fnic_iport_s *iport,
159 				     struct fnic_tport_s *tport)
160 {
161 }
162 
163 static inline void nvfnic_process_ls_abts_rsp(struct fnic_iport_s *iport,
164 					      struct fc_frame_header *fchdr)
165 {
166 }
167 
168 static inline void nvfnic_ls_rsp_recv(struct fnic_iport_s *iport,
169 				      struct fc_frame_header *fchdr, int len)
170 {
171 }
172 
173 static inline int nvfnic_add_tport(struct fnic *fnic,
174 				   struct fnic_tport_s *tport,
175 				   unsigned long flags)
176 {
177 	return 0;
178 }
179 
180 static inline void nvfnic_delete_tport(struct fnic_iport_s *iport,
181 				       struct fnic_tport_s *tport,
182 				       unsigned long flags)
183 {
184 }
185 
186 static inline void nvfnic_cleanup_all_nvme_ios(struct fnic *fnic)
187 {
188 }
189 
190 static inline void nvfnic_fcpio_nvme_fast_cmpl_handler(struct fnic *fnic,
191 						       struct fcpio_fw_req *desc)
192 {
193 }
194 
195 static inline void nvfnic_fcpio_ersp_cmpl_handler(struct fnic *fnic,
196 						  struct fcpio_fw_req *desc,
197 						  int sw_flag)
198 {
199 }
200 
201 static inline void nvfnic_fcpio_nvme_itmf_cmpl_handler(struct fnic *fnic,
202 						       struct fcpio_fw_req *desc)
203 {
204 }
205 
206 static inline int nvfnic_get_nvmef_info(struct fnic *fnic,
207 					struct fnic_nvmef_info *info)
208 {
209 	return 0;
210 }
211 #endif
212 
213 extern const char *fnic_fcpio_status_to_str(unsigned int status);
214 #endif				/* _FNIC_NVME_H */
215