xref: /illumos-gate/usr/src/uts/common/sys/scsi/impl/transport.h (revision 43d18f1c320355e93c47399bea0b2e022fe06364)
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 	int		(*tran_pkt_constructor)(
263 				struct scsi_pkt		*pkt,
264 				scsi_hba_tran_t		*tran,
265 				int			kmflag);
266 	void		(*tran_pkt_destructor)(
267 				struct scsi_pkt		*pkt,
268 				scsi_hba_tran_t		*tran);
269 	kmem_cache_t	*tran_pkt_cache_ptr;
270 
271 	uint_t		tran_hba_len;
272 	int		(*tran_setup_pkt)(
273 				struct scsi_pkt		*pkt,
274 				int			(*callback)(
275 								caddr_t	arg),
276 				caddr_t			callback_arg);
277 	int		(*tran_setup_bp)(
278 				struct scsi_pkt		*pkt,
279 				struct buf		*bp,
280 				int			flags,
281 				int			(*callback)(
282 								caddr_t	arg),
283 				caddr_t			callback_arg);
284 	void		(*tran_teardown_pkt)(
285 				struct scsi_pkt		*pkt);
286 
287 };
288 
289 #ifdef __lock_lint
290 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_hba_tran::tran_sd))
291 #endif
292 
293 /*
294  * Prototypes for SCSI HBA interface functions
295  *
296  * All these functions are public interfaces, with the
297  * exception of scsi_initialize_hba_interface() and
298  * scsi_uninitialize_hba_interface(), called by the
299  * scsi module _init() and _fini(), respectively.
300  */
301 
302 extern void		scsi_initialize_hba_interface(void);
303 
304 #ifdef	NO_SCSI_FINI_YET
305 extern void		scsi_uninitialize_hba_interface(void);
306 #endif	/* NO_SCSI_FINI_YET */
307 
308 extern int		scsi_hba_init(
309 				struct modlinkage	*modlp);
310 
311 extern void		scsi_hba_fini(
312 				struct modlinkage	*modlp);
313 
314 extern int		scsi_hba_attach(
315 				dev_info_t		*hba_dip,
316 				ddi_dma_lim_t		*hba_lim,
317 				scsi_hba_tran_t		*hba_tran,
318 				int			flags,
319 				void			*hba_options);
320 
321 extern int		scsi_hba_attach_setup(
322 				dev_info_t		*hba_dip,
323 				ddi_dma_attr_t		*hba_dma_attr,
324 				scsi_hba_tran_t		*hba_tran,
325 				int			flags);
326 
327 extern int		scsi_hba_detach(
328 				dev_info_t		*hba_dip);
329 
330 extern scsi_hba_tran_t	*scsi_hba_tran_alloc(
331 				dev_info_t		*hba_dip,
332 				int			flags);
333 
334 extern void		scsi_hba_tran_free(
335 				scsi_hba_tran_t		*hba_tran);
336 
337 extern int		scsi_hba_probe(
338 				struct scsi_device	*sd,
339 				int			(*callback)(void));
340 
341 extern int		scsi_get_device_type_scsi_options(
342 				dev_info_t		*hba_dip,
343 				struct scsi_device	*devp,
344 				int			default_scsi_options);
345 
346 extern struct scsi_pkt	*scsi_hba_pkt_alloc(
347 				dev_info_t		*hba_dip,
348 				struct scsi_address	*ap,
349 				int			cmdlen,
350 				int			statuslen,
351 				int			tgtlen,
352 				int			hbalen,
353 				int			(*callback)(caddr_t),
354 				caddr_t			arg);
355 
356 extern void		scsi_hba_pkt_free(
357 				struct scsi_address	*ap,
358 				struct scsi_pkt		*pkt);
359 
360 
361 extern int		scsi_hba_lookup_capstr(
362 				char			*capstr);
363 
364 extern int		scsi_hba_in_panic(void);
365 
366 extern int		scsi_hba_open(
367 				dev_t			*devp,
368 				int			flags,
369 				int			otyp,
370 				cred_t			*credp);
371 
372 extern int		scsi_hba_close(
373 				dev_t			dev,
374 				int			flag,
375 				int			otyp,
376 				cred_t			*credp);
377 
378 extern int		scsi_hba_ioctl(
379 				dev_t			dev,
380 				int			cmd,
381 				intptr_t		arg,
382 				int			mode,
383 				cred_t			*credp,
384 				int			*rvalp);
385 
386 extern void		scsi_hba_nodename_compatible_get(
387 				struct scsi_inquiry	*inq,
388 				char			*binding_set,
389 				int			dtype_node,
390 				char			*compat0,
391 				char			**nodenamep,
392 				char			***compatiblep,
393 				int			*ncompatiblep);
394 
395 extern void		scsi_hba_nodename_compatible_free(
396 				char			*nodename,
397 				char			**compatible);
398 
399 
400 /*
401  * Flags for scsi_hba_attach
402  */
403 #define	SCSI_HBA_TRAN_CLONE	0x01		/* clone scsi_hba_tran_t */
404 						/* structure per target */
405 #define	SCSI_HBA_TRAN_ALLOC	0x02		/* set if scsi_hba_tran_alloc */
406 						/* is called */
407 #define	SCSI_HBA_TRAN_CDB	0x04		/* allocate cdb */
408 #define	SCSI_HBA_TRAN_SCB	0x08		/* allocate sense */
409 
410 /*
411  * Flags for scsi_hba allocation functions
412  */
413 #define	SCSI_HBA_CANSLEEP	0x01		/* can sleep */
414 
415 /*
416  * For minor nodes created by the SCSA framework, minor numbers are
417  * formed by left-shifting instance by INST_MINOR_SHIFT and OR in a
418  * number less than 64.
419  *
420  * - Numbers 0 - 31 are reserved by the framework, part of the range are
421  *	in use, as defined below.
422  *
423  * - Numbers 32 - 63 are available for HBA driver use.
424  */
425 #define	INST_MINOR_SHIFT	6
426 #define	TRAN_MINOR_MASK		((1 << INST_MINOR_SHIFT) - 1)
427 #define	TRAN_OPEN_EXCL		(uint64_t)-1
428 
429 #define	DEVCTL_MINOR		0
430 #define	SCSI_MINOR		1
431 
432 #define	INST2DEVCTL(x)		(((x) << INST_MINOR_SHIFT) | DEVCTL_MINOR)
433 #define	INST2SCSI(x)		(((x) << INST_MINOR_SHIFT) | SCSI_MINOR)
434 #define	MINOR2INST(x)		((x) >> INST_MINOR_SHIFT)
435 
436 
437 #endif	/* _KERNEL */
438 
439 
440 #ifdef	__cplusplus
441 }
442 #endif
443 
444 #endif	/* _SYS_SCSI_IMPL_TRANSPORT_H */
445