xref: /freebsd/sys/dev/ocs_fc/ocs.h (revision 98d835ae)
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 #if !defined(__OCS_H__)
40 #define __OCS_H__
41 
42 #include "ocs_os.h"
43 #include "ocs_utils.h"
44 
45 #include "ocs_hw.h"
46 #include "ocs_scsi.h"
47 #include "ocs_io.h"
48 
49 #include "version.h"
50 
51 #define DRV_NAME			"ocs_fc"
52 #define DRV_VERSION 							\
53 	STR_BE_MAJOR "." STR_BE_MINOR "." STR_BE_BUILD "." STR_BE_BRANCH
54 
55 /**
56  * @brief Interrupt context
57  */
58 typedef struct ocs_intr_ctx_s {
59 	uint32_t	vec;		/** Zero based interrupt vector */
60 	void		*softc;		/** software context for interrupt */
61 	char		name[64];	/** label for this context */
62 } ocs_intr_ctx_t;
63 
64 typedef struct ocs_fc_rport_db_s {
65 	uint32_t	node_id;
66 	uint32_t	state;
67 	uint8_t		is_target;
68 	uint8_t		is_initiator;
69 
70 	uint32_t	port_id;
71 	uint64_t	wwnn;
72 	uint64_t	wwpn;
73 	uint32_t	gone_timer;
74 
75 } ocs_fc_target_t;
76 
77 #define OCS_TGT_STATE_NONE		0	/* Empty DB slot */
78 #define OCS_TGT_STATE_VALID		1	/* Valid*/
79 #define OCS_TGT_STATE_LOST		2	/* LOST*/
80 
81 typedef struct ocs_fcport_s {
82 	ocs_t			*ocs;
83 	struct cam_sim		*sim;
84 	struct cam_path		*path;
85 	uint32_t		role;
86 	uint32_t                fc_id;
87 
88 	ocs_fc_target_t	tgt[OCS_MAX_TARGETS];
89 	int lost_device_time;
90 	struct callout ldt;     /* device lost timer */
91 	struct task ltask;
92 
93 	ocs_tgt_resource_t	targ_rsrc_wildcard;
94 	ocs_tgt_resource_t	targ_rsrc[OCS_MAX_LUN];
95 	ocs_vport_spec_t	*vport;
96 } ocs_fcport;
97 
98 #define FCPORT(ocs, chan)	(&((ocs_fcport *)(ocs)->fcports)[(chan)])
99 
100 /**
101  * @brief Driver's context
102  */
103 
104 struct ocs_softc {
105 	device_t		dev;
106 	struct cdev		*cdev;
107 
108 	ocs_pci_reg_t		reg[PCI_MAX_BAR];
109 
110 	uint32_t		instance_index;
111 	const char		*desc;
112 
113 	uint32_t		irqid;
114 	struct resource		*irq;
115 	void			*tag;
116 
117 	ocs_intr_ctx_t		intr_ctx;
118 	uint32_t		n_vec;
119 
120 	bus_dma_tag_t		dmat;	/** Parent DMA tag */
121 	bus_dma_tag_t		buf_dmat;/** IO buffer DMA tag */
122 	char display_name[OCS_DISPLAY_NAME_LENGTH];
123 	uint16_t		pci_vendor;
124 	uint16_t		pci_device;
125 	uint16_t		pci_subsystem_vendor;
126 	uint16_t		pci_subsystem_device;
127 	char			businfo[16];
128 	const char		*driver_version;
129 	const char		*fw_version;
130 	const char		*model;
131 
132 	ocs_hw_t hw;
133 
134 	ocs_rlock_t lock;	/**< device wide lock */
135 
136 	ocs_xport_e		ocs_xport;
137 	ocs_xport_t *xport;	/**< pointer to transport object */
138 	ocs_domain_t *domain;
139 	ocs_list_t domain_list;
140 	uint32_t domain_instance_count;
141 	void (*domain_list_empty_cb)(ocs_t *ocs, void *arg);
142 	void *domain_list_empty_cb_arg;
143 
144 	uint8_t enable_ini;
145 	uint8_t enable_tgt;
146 	uint8_t fc_type;
147 	int ctrlmask;
148 	uint8_t explicit_buffer_list;
149 	uint8_t external_loopback;
150 	uint8_t skip_hw_teardown;
151 	int speed;
152 	int topology;
153 	int ethernet_license;
154 	int num_scsi_ios;
155 	uint8_t enable_hlm;
156 	uint32_t hlm_group_size;
157 	uint32_t max_isr_time_msec;	/*>> Maximum ISR time */
158 	uint32_t auto_xfer_rdy_size; /*>> Max sized write to use auto xfer rdy*/
159 	uint8_t esoc;
160 	int logmask;
161 	char *hw_war_version;
162 	uint32_t num_vports;
163 	uint32_t target_io_timer_sec;
164 	uint32_t hw_bounce;
165 	uint8_t rq_threads;
166 	uint8_t rq_selection_policy;
167 	uint8_t rr_quanta;
168 	char *filter_def;
169 	uint32_t max_remote_nodes;
170 
171 	/*
172 	 * tgt_rscn_delay - delay in kicking off RSCN processing
173 	 * (nameserver queries) after receiving an RSCN on the target.
174 	 * This prevents thrashing of nameserver requests due to a huge burst of
175 	 * RSCNs received in a short period of time.
176 	 * Note: this is only valid when target RSCN handling is enabled -- see
177 	 * ctrlmask.
178 	 */
179 	time_t tgt_rscn_delay_msec;	/*>> minimum target RSCN delay */
180 
181 	/*
182 	 * tgt_rscn_period - determines maximum frequency when processing
183 	 * back-to-back RSCNs; e.g. if this value is 30, there will never be
184 	 * any more than 1 RSCN handling per 30s window. This prevents
185 	 * initiators on a faulty link generating many RSCN from causing the
186 	 * target to continually query the nameserver.
187 	 * Note: This is only valid when target RSCN handling is enabled
188 	 */
189 	time_t tgt_rscn_period_msec;	/*>> minimum target RSCN period */
190 
191 	uint32_t		enable_task_set_full;
192 	uint32_t		io_in_use;
193 	uint32_t		io_high_watermark; /**< used to send task set full */
194 	struct mtx		sim_lock;
195 	uint32_t		config_tgt:1,	/**< Configured to support target mode */
196 				config_ini:1;	/**< Configured to support initiator mode */
197 
198 	uint32_t nodedb_mask;			/**< Node debugging mask */
199 
200 	char			modeldesc[64];
201 	char			serialnum[64];
202 	char			fwrev[64];
203 	char			sli_intf[9];
204 
205 	ocs_ramlog_t		*ramlog;
206 	ocs_textbuf_t		ddump_saved;
207 
208 	ocs_mgmt_functions_t	*mgmt_functions;
209 	ocs_mgmt_functions_t	*tgt_mgmt_functions;
210 	ocs_mgmt_functions_t	*ini_mgmt_functions;
211 
212 	ocs_err_injection_e err_injection;
213 	uint32_t cmd_err_inject;
214 	time_t delay_value_msec;
215 
216 	bool			attached;
217 	struct mtx		dbg_lock;
218 
219 	struct cam_devq		*devq;
220 	ocs_fcport		*fcports;
221 
222 	void*			tgt_ocs;
223 };
224 
225 static inline void
226 ocs_device_lock_init(ocs_t *ocs)
227 {
228 	ocs_rlock_init(ocs, &ocs->lock, "ocsdevicelock");
229 }
230 
231 static inline int32_t
232 ocs_device_lock_try(ocs_t *ocs)
233 {
234 	return ocs_rlock_try(&ocs->lock);
235 }
236 
237 static inline void
238 ocs_device_lock(ocs_t *ocs)
239 {
240 	ocs_rlock_acquire(&ocs->lock);
241 }
242 
243 static inline void
244 ocs_device_unlock(ocs_t *ocs)
245 {
246 	ocs_rlock_release(&ocs->lock);
247 }
248 
249 static inline void
250 ocs_device_lock_free(ocs_t *ocs)
251 {
252 	ocs_rlock_free(&ocs->lock);
253 }
254 
255 extern int32_t ocs_device_detach(ocs_t *ocs);
256 
257 extern int32_t ocs_device_attach(ocs_t *ocs);
258 
259 #define ocs_is_initiator_enabled()	(ocs->enable_ini)
260 #define ocs_is_target_enabled()	(ocs->enable_tgt)
261 
262 #include "ocs_xport.h"
263 #include "ocs_domain.h"
264 #include "ocs_sport.h"
265 #include "ocs_node.h"
266 #include "ocs_unsol.h"
267 #include "ocs_scsi.h"
268 #include "ocs_ioctl.h"
269 
270 static inline ocs_io_t *
271 ocs_io_alloc(ocs_t *ocs)
272 {
273 	return ocs_io_pool_io_alloc(ocs->xport->io_pool);
274 }
275 
276 static inline void
277 ocs_io_free(ocs_t *ocs, ocs_io_t *io)
278 {
279 	ocs_io_pool_io_free(ocs->xport->io_pool, io);
280 }
281 
282 #endif /* __OCS_H__ */
283