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