xref: /freebsd/sys/dev/ocs_fc/ocs.h (revision 732a02b4e77866604a120a275c082bb6221bd2ff)
1 /*-
2  * Copyright (c) 2017 Broadcom. All rights reserved.
3  * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *    this list of conditions and the following disclaimer in the documentation
13  *    and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $FreeBSD$
32  */
33 
34 /**
35  * @file
36  * OCS bsd driver common include file
37  */
38 
39 
40 #if !defined(__OCS_H__)
41 #define __OCS_H__
42 
43 #include "ocs_os.h"
44 #include "ocs_utils.h"
45 
46 #include "ocs_hw.h"
47 #include "ocs_scsi.h"
48 #include "ocs_io.h"
49 
50 #include "version.h"
51 
52 #define DRV_NAME			"ocs_fc"
53 #define DRV_VERSION 							\
54 	STR_BE_MAJOR "." STR_BE_MINOR "." STR_BE_BUILD "." STR_BE_BRANCH
55 
56 /**
57  * @brief Interrupt context
58  */
59 typedef struct ocs_intr_ctx_s {
60 	uint32_t	vec;		/** Zero based interrupt vector */
61 	void		*softc;		/** software context for interrupt */
62 	char		name[64];	/** label for this context */
63 } ocs_intr_ctx_t;
64 
65 typedef struct ocs_fc_rport_db_s {
66 	uint32_t	node_id;
67 	uint32_t	state;
68 	uint8_t		is_target;
69 	uint8_t		is_initiator;
70 
71 	uint32_t	port_id;
72 	uint64_t	wwnn;
73 	uint64_t	wwpn;
74 	uint32_t	gone_timer;
75 
76 } ocs_fc_target_t;
77 
78 #define OCS_TGT_STATE_NONE		0	/* Empty DB slot */
79 #define OCS_TGT_STATE_VALID		1	/* Valid*/
80 #define OCS_TGT_STATE_LOST		2	/* LOST*/
81 
82 typedef struct ocs_fcport_s {
83 	ocs_t			*ocs;
84 	struct cam_sim		*sim;
85 	struct cam_path		*path;
86 	uint32_t		role;
87 	uint32_t                fc_id;
88 
89 	ocs_fc_target_t	tgt[OCS_MAX_TARGETS];
90 	int lost_device_time;
91 	struct callout ldt;     /* device lost timer */
92 	struct task ltask;
93 
94 	ocs_tgt_resource_t	targ_rsrc_wildcard;
95 	ocs_tgt_resource_t	targ_rsrc[OCS_MAX_LUN];
96 	ocs_vport_spec_t	*vport;
97 } ocs_fcport;
98 
99 #define FCPORT(ocs, chan)	(&((ocs_fcport *)(ocs)->fcports)[(chan)])
100 
101 /**
102  * @brief Driver's context
103  */
104 
105 struct ocs_softc {
106 
107 	device_t		dev;
108 	struct cdev		*cdev;
109 
110 	ocs_pci_reg_t		reg[PCI_MAX_BAR];
111 
112 	uint32_t		instance_index;
113 	const char		*desc;
114 
115 	uint32_t		irqid;
116 	struct resource		*irq;
117 	void			*tag;
118 
119 	ocs_intr_ctx_t		intr_ctx;
120 	uint32_t		n_vec;
121 
122 	bus_dma_tag_t		dmat;	/** Parent DMA tag */
123 	bus_dma_tag_t		buf_dmat;/** IO buffer DMA tag */
124 	char display_name[OCS_DISPLAY_NAME_LENGTH];
125 	uint16_t		pci_vendor;
126 	uint16_t		pci_device;
127 	uint16_t		pci_subsystem_vendor;
128 	uint16_t		pci_subsystem_device;
129 	char			businfo[16];
130 	const char		*driver_version;
131 	const char		*fw_version;
132 	const char		*model;
133 
134 	ocs_hw_t hw;
135 
136 	ocs_rlock_t lock;	/**< device wide lock */
137 
138 	ocs_xport_e		ocs_xport;
139 	ocs_xport_t *xport;	/**< pointer to transport object */
140 	ocs_domain_t *domain;
141 	ocs_list_t domain_list;
142 	uint32_t domain_instance_count;
143 	void (*domain_list_empty_cb)(ocs_t *ocs, void *arg);
144 	void *domain_list_empty_cb_arg;
145 
146 	uint8_t enable_ini;
147 	uint8_t enable_tgt;
148 	uint8_t fc_type;
149 	int ctrlmask;
150 	uint8_t explicit_buffer_list;
151 	uint8_t external_loopback;
152 	uint8_t skip_hw_teardown;
153 	int speed;
154 	int topology;
155 	int ethernet_license;
156 	int num_scsi_ios;
157 	uint8_t enable_hlm;
158 	uint32_t hlm_group_size;
159 	uint32_t max_isr_time_msec;	/*>> Maximum ISR time */
160 	uint32_t auto_xfer_rdy_size; /*>> Max sized write to use auto xfer rdy*/
161 	uint8_t esoc;
162 	int logmask;
163 	char *hw_war_version;
164 	uint32_t num_vports;
165 	uint32_t target_io_timer_sec;
166 	uint32_t hw_bounce;
167 	uint8_t rq_threads;
168 	uint8_t rq_selection_policy;
169 	uint8_t rr_quanta;
170 	char *filter_def;
171 	uint32_t max_remote_nodes;
172 
173 	/*
174 	 * tgt_rscn_delay - delay in kicking off RSCN processing
175 	 * (nameserver queries) after receiving an RSCN on the target.
176 	 * This prevents thrashing of nameserver requests due to a huge burst of
177 	 * RSCNs received in a short period of time.
178 	 * Note: this is only valid when target RSCN handling is enabled -- see
179 	 * ctrlmask.
180 	 */
181 	time_t tgt_rscn_delay_msec;	/*>> minimum target RSCN delay */
182 
183 	/*
184 	 * tgt_rscn_period - determines maximum frequency when processing
185 	 * back-to-back RSCNs; e.g. if this value is 30, there will never be
186 	 * any more than 1 RSCN handling per 30s window. This prevents
187 	 * initiators on a faulty link generating many RSCN from causing the
188 	 * target to continually query the nameserver.
189 	 * Note: This is only valid when target RSCN handling is enabled
190 	 */
191 	time_t tgt_rscn_period_msec;	/*>> minimum target RSCN period */
192 
193 	uint32_t		enable_task_set_full;
194 	uint32_t		io_in_use;
195 	uint32_t		io_high_watermark; /**< used to send task set full */
196 	struct mtx		sim_lock;
197 	uint32_t		config_tgt:1,	/**< Configured to support target mode */
198 				config_ini:1;	/**< Configured to support initiator mode */
199 
200 
201 	uint32_t nodedb_mask;			/**< Node debugging mask */
202 
203 	char			modeldesc[64];
204 	char			serialnum[64];
205 	char			fwrev[64];
206 	char			sli_intf[9];
207 
208 	ocs_ramlog_t		*ramlog;
209 	ocs_textbuf_t		ddump_saved;
210 
211 	ocs_mgmt_functions_t	*mgmt_functions;
212 	ocs_mgmt_functions_t	*tgt_mgmt_functions;
213 	ocs_mgmt_functions_t	*ini_mgmt_functions;
214 
215 	ocs_err_injection_e err_injection;
216 	uint32_t cmd_err_inject;
217 	time_t delay_value_msec;
218 
219 	bool			attached;
220 	struct mtx		dbg_lock;
221 
222 	struct cam_devq		*devq;
223 	ocs_fcport		*fcports;
224 
225 	void*			tgt_ocs;
226 };
227 
228 static inline void
229 ocs_device_lock_init(ocs_t *ocs)
230 {
231 	ocs_rlock_init(ocs, &ocs->lock, "ocsdevicelock");
232 }
233 
234 static inline int32_t
235 ocs_device_lock_try(ocs_t *ocs)
236 {
237 	return ocs_rlock_try(&ocs->lock);
238 }
239 
240 static inline void
241 ocs_device_lock(ocs_t *ocs)
242 {
243 	ocs_rlock_acquire(&ocs->lock);
244 }
245 
246 static inline void
247 ocs_device_unlock(ocs_t *ocs)
248 {
249 	ocs_rlock_release(&ocs->lock);
250 }
251 
252 static inline void
253 ocs_device_lock_free(ocs_t *ocs)
254 {
255 	ocs_rlock_free(&ocs->lock);
256 }
257 
258 extern int32_t ocs_device_detach(ocs_t *ocs);
259 
260 extern int32_t ocs_device_attach(ocs_t *ocs);
261 
262 #define ocs_is_initiator_enabled()	(ocs->enable_ini)
263 #define ocs_is_target_enabled()	(ocs->enable_tgt)
264 
265 #include "ocs_xport.h"
266 #include "ocs_domain.h"
267 #include "ocs_sport.h"
268 #include "ocs_node.h"
269 #include "ocs_unsol.h"
270 #include "ocs_scsi.h"
271 #include "ocs_ioctl.h"
272 
273 static inline ocs_io_t *
274 ocs_io_alloc(ocs_t *ocs)
275 {
276 	return ocs_io_pool_io_alloc(ocs->xport->io_pool);
277 }
278 
279 static inline void
280 ocs_io_free(ocs_t *ocs, ocs_io_t *io)
281 {
282 	ocs_io_pool_io_free(ocs->xport->io_pool, io);
283 }
284 
285 #endif /* __OCS_H__ */
286