xref: /illumos-gate/usr/src/uts/common/sys/scsi/impl/transport.h (revision db874c57ae335a07060499f1492b0d0e2593e26c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_SCSI_IMPL_TRANSPORT_H
28 #define	_SYS_SCSI_IMPL_TRANSPORT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Include the loadable module wrapper.
34  */
35 #include <sys/modctl.h>
36 #include <sys/note.h>
37 
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #ifdef	_KERNEL
44 
45 /*
46  * SCSI transport structures
47  *
48  *	As each Host Adapter makes itself known to the system,
49  *	it will create and register with the library the structure
50  *	described below. This is so that the library knows how to route
51  *	packets, resource control requests, and capability requests
52  *	for any particular host adapter. The 'a_hba_tran' field of a
53  *	scsi_address structure made known to a Target driver will
54  *	point to one of these transport structures.
55  */
56 
57 typedef struct scsi_hba_tran	scsi_hba_tran_t;
58 
59 struct scsi_hba_tran {
60 	/*
61 	 * Ptr to the device info structure for this particular HBA.
62 	 */
63 	dev_info_t	*tran_hba_dip;
64 
65 	/*
66 	 * Private fields for use by the HBA itself.
67 	 */
68 	void		*tran_hba_private;	/* HBA softstate */
69 	void		*tran_tgt_private;	/* target-specific info */
70 
71 	/*
72 	 * Only used to refer to a particular scsi device
73 	 * if the entire scsi_hba_tran structure is "cloned"
74 	 * per target device, otherwise NULL.
75 	 */
76 	struct scsi_device	*tran_sd;
77 
78 	/*
79 	 * Vectors to point to specific HBA entry points
80 	 */
81 
82 	int		(*tran_tgt_init)(
83 				dev_info_t		*hba_dip,
84 				dev_info_t		*tgt_dip,
85 				scsi_hba_tran_t		*hba_tran,
86 				struct scsi_device	*sd);
87 
88 	int		(*tran_tgt_probe)(
89 				struct scsi_device	*sd,
90 				int			(*callback)(
91 								void));
92 	void		(*tran_tgt_free)(
93 				dev_info_t		*hba_dip,
94 				dev_info_t		*tgt_dip,
95 				scsi_hba_tran_t		*hba_tran,
96 				struct scsi_device	*sd);
97 
98 	int		(*tran_start)(
99 				struct scsi_address	*ap,
100 				struct scsi_pkt		*pkt);
101 
102 	int		(*tran_reset)(
103 				struct scsi_address	*ap,
104 				int			level);
105 
106 	int		(*tran_abort)(
107 				struct scsi_address	*ap,
108 				struct scsi_pkt		*pkt);
109 
110 	int		(*tran_getcap)(
111 				struct scsi_address	*ap,
112 				char			*cap,
113 				int			whom);
114 
115 	int		(*tran_setcap)(
116 				struct scsi_address	*ap,
117 				char			*cap,
118 				int			value,
119 				int			whom);
120 
121 	struct scsi_pkt	*(*tran_init_pkt)(
122 				struct scsi_address	*ap,
123 				struct scsi_pkt		*pkt,
124 				struct buf		*bp,
125 				int			cmdlen,
126 				int			statuslen,
127 				int			tgtlen,
128 				int			flags,
129 				int			(*callback)(
130 								caddr_t	arg),
131 				caddr_t			callback_arg);
132 
133 	void		(*tran_destroy_pkt)(
134 				struct scsi_address	*ap,
135 				struct scsi_pkt		*pkt);
136 
137 	void		(*tran_dmafree)(
138 				struct scsi_address	*ap,
139 				struct scsi_pkt		*pkt);
140 
141 	void		(*tran_sync_pkt)(
142 				struct scsi_address	*ap,
143 				struct scsi_pkt		*pkt);
144 
145 	int		(*tran_reset_notify)(
146 				struct scsi_address	*ap,
147 				int			flag,
148 				void			(*callback)(caddr_t),
149 				caddr_t			arg);
150 
151 	int		(*tran_get_bus_addr)(
152 				struct scsi_device	*devp,
153 				char			*name,
154 				int			len);
155 
156 	int		(*tran_get_name)(
157 				struct scsi_device	*devp,
158 				char			*name,
159 				int			len);
160 
161 	int		(*tran_clear_aca)(
162 				struct scsi_address	*ap);
163 
164 	int		(*tran_clear_task_set)(
165 				struct scsi_address	*ap);
166 
167 	int		(*tran_terminate_task)(
168 				struct scsi_address	*ap,
169 				struct scsi_pkt		*pkt);
170 
171 	int		(*tran_get_eventcookie)(
172 				dev_info_t		*hba_dip,
173 				dev_info_t		*tgt_dip,
174 				char			*name,
175 				ddi_eventcookie_t	*eventp);
176 
177 	int		(*tran_add_eventcall)(
178 				dev_info_t		*hba_dip,
179 				dev_info_t		*tgt_dip,
180 				ddi_eventcookie_t	event,
181 				void			(*callback)(
182 						dev_info_t *tgt_dip,
183 						ddi_eventcookie_t event,
184 						void *arg,
185 						void *bus_impldata),
186 				void			*arg,
187 				ddi_callback_id_t *cb_id);
188 
189 	int		(*tran_remove_eventcall)(dev_info_t *devi,
190 			ddi_callback_id_t cb_id);
191 
192 	int		(*tran_post_event)(
193 				dev_info_t		*hba_dip,
194 				dev_info_t		*tgt_dip,
195 				ddi_eventcookie_t	event,
196 				void			*bus_impldata);
197 
198 	int		(*tran_quiesce)(
199 				dev_info_t		*hba_dip);
200 
201 	int		(*tran_unquiesce)(
202 				dev_info_t		*hba_dip);
203 
204 	int		(*tran_bus_reset)(
205 				dev_info_t		*hba_dip,
206 				int			level);
207 
208 	/*
209 	 * Implementation-private specifics.
210 	 * No HBA should refer to any of the fields below.
211 	 * This information can and will change.
212 	 */
213 	int			tran_hba_flags;		/* flag options */
214 
215 	/*
216 	 * min xfer and min/max burstsizes for DDI_CTLOPS_IOMIN
217 	 */
218 	uint_t			tran_min_xfer;
219 	uchar_t			tran_min_burst_size;
220 	uchar_t			tran_max_burst_size;
221 
222 	/*
223 	 * open_lock: protect tran_minor_isopen
224 	 * open_flag: bit field indicating which minor nodes are open.
225 	 *	0 = closed, 1 = shared open, all bits 1 = excl open.
226 	 *
227 	 * XXX Unused if hba driver chooses to implement own
228 	 *	xxopen(9e) entry point
229 	 */
230 	kmutex_t		tran_open_lock;
231 	uint64_t		tran_open_flag;
232 
233 	/*
234 	 * bus_config vectors - ON Consolidation Private
235 	 * These interfaces are subject to change.
236 	 */
237 	int		(*tran_bus_config)(
238 				dev_info_t		*hba_dip,
239 				uint_t			flag,
240 				ddi_bus_config_op_t	op,
241 				void			*arg,
242 				dev_info_t		**tgt_dipp);
243 
244 	int		(*tran_bus_unconfig)(
245 				dev_info_t		*hba_dip,
246 				uint_t			flag,
247 				ddi_bus_config_op_t	op,
248 				void			*arg);
249 
250 	int		(*tran_bus_power)(
251 				dev_info_t		*dip,
252 				void			*impl_arg,
253 				pm_bus_power_op_t	op,
254 				void			*arg,
255 				void			*result);
256 
257 	/*
258 	 * Inter-Connect type of trasnport as defined in
259 	 * usr/src/uts/common/sys/scsi/impl/services.h
260 	 */
261 	int		tran_interconnect_type;
262 };
263 
264 #ifdef __lock_lint
265 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_hba_tran::tran_sd))
266 #endif
267 
268 /*
269  * Prototypes for SCSI HBA interface functions
270  *
271  * All these functions are public interfaces, with the
272  * exception of scsi_initialize_hba_interface() and
273  * scsi_uninitialize_hba_interface(), called by the
274  * scsi module _init() and _fini(), respectively.
275  */
276 
277 extern void		scsi_initialize_hba_interface(void);
278 
279 #ifdef	NO_SCSI_FINI_YET
280 extern void		scsi_uninitialize_hba_interface(void);
281 #endif	/* NO_SCSI_FINI_YET */
282 
283 extern int		scsi_hba_init(
284 				struct modlinkage	*modlp);
285 
286 extern void		scsi_hba_fini(
287 				struct modlinkage	*modlp);
288 
289 extern int		scsi_hba_attach(
290 				dev_info_t		*hba_dip,
291 				ddi_dma_lim_t		*hba_lim,
292 				scsi_hba_tran_t		*hba_tran,
293 				int			flags,
294 				void			*hba_options);
295 
296 extern int		scsi_hba_attach_setup(
297 				dev_info_t		*hba_dip,
298 				ddi_dma_attr_t		*hba_dma_attr,
299 				scsi_hba_tran_t		*hba_tran,
300 				int			flags);
301 
302 extern int		scsi_hba_detach(
303 				dev_info_t		*hba_dip);
304 
305 extern scsi_hba_tran_t	*scsi_hba_tran_alloc(
306 				dev_info_t		*hba_dip,
307 				int			flags);
308 
309 extern void		scsi_hba_tran_free(
310 				scsi_hba_tran_t		*hba_tran);
311 
312 extern int		scsi_hba_probe(
313 				struct scsi_device	*sd,
314 				int			(*callback)(void));
315 
316 extern int		scsi_get_device_type_scsi_options(
317 				dev_info_t		*hba_dip,
318 				struct scsi_device	*devp,
319 				int			default_scsi_options);
320 
321 extern struct scsi_pkt	*scsi_hba_pkt_alloc(
322 				dev_info_t		*hba_dip,
323 				struct scsi_address	*ap,
324 				int			cmdlen,
325 				int			statuslen,
326 				int			tgtlen,
327 				int			hbalen,
328 				int			(*callback)(caddr_t),
329 				caddr_t			arg);
330 
331 extern void		scsi_hba_pkt_free(
332 				struct scsi_address	*ap,
333 				struct scsi_pkt		*pkt);
334 
335 
336 extern int		scsi_hba_lookup_capstr(
337 				char			*capstr);
338 
339 extern int		scsi_hba_in_panic(void);
340 
341 extern int		scsi_hba_open(
342 				dev_t			*devp,
343 				int			flags,
344 				int			otyp,
345 				cred_t			*credp);
346 
347 extern int		scsi_hba_close(
348 				dev_t			dev,
349 				int			flag,
350 				int			otyp,
351 				cred_t			*credp);
352 
353 extern int		scsi_hba_ioctl(
354 				dev_t			dev,
355 				int			cmd,
356 				intptr_t		arg,
357 				int			mode,
358 				cred_t			*credp,
359 				int			*rvalp);
360 
361 extern void		scsi_hba_nodename_compatible_get(
362 				struct scsi_inquiry	*inq,
363 				char			*binding_set,
364 				int			dtype_node,
365 				char			*compat0,
366 				char			**nodenamep,
367 				char			***compatiblep,
368 				int			*ncompatiblep);
369 
370 extern void		scsi_hba_nodename_compatible_free(
371 				char			*nodename,
372 				char			**compatible);
373 
374 
375 /*
376  * Flags for scsi_hba_attach
377  */
378 #define	SCSI_HBA_TRAN_CLONE	0x01		/* clone scsi_hba_tran_t */
379 						/* structure per target */
380 #define	SCSI_HBA_TRAN_ALLOC	0x02		/* set if scsi_hba_tran_alloc */
381 						/* is called */
382 
383 /*
384  * Flags for scsi_hba allocation functions
385  */
386 #define	SCSI_HBA_CANSLEEP	0x01		/* can sleep */
387 
388 /*
389  * For minor nodes created by the SCSA framework, minor numbers are
390  * formed by left-shifting instance by INST_MINOR_SHIFT and OR in a
391  * number less than 64.
392  *
393  * - Numbers 0 - 31 are reserved by the framework, part of the range are
394  *	in use, as defined below.
395  *
396  * - Numbers 32 - 63 are available for HBA driver use.
397  */
398 #define	INST_MINOR_SHIFT	6
399 #define	TRAN_MINOR_MASK		((1 << INST_MINOR_SHIFT) - 1)
400 #define	TRAN_OPEN_EXCL		(uint64_t)-1
401 
402 #define	DEVCTL_MINOR		0
403 #define	SCSI_MINOR		1
404 
405 #define	INST2DEVCTL(x)		(((x) << INST_MINOR_SHIFT) | DEVCTL_MINOR)
406 #define	INST2SCSI(x)		(((x) << INST_MINOR_SHIFT) | SCSI_MINOR)
407 #define	MINOR2INST(x)		((x) >> INST_MINOR_SHIFT)
408 
409 
410 #endif	/* _KERNEL */
411 
412 
413 #ifdef	__cplusplus
414 }
415 #endif
416 
417 #endif	/* _SYS_SCSI_IMPL_TRANSPORT_H */
418