xref: /titanic_51/usr/src/uts/common/sys/usb/scsa2usb/scsa2usb.h (revision 43a291055ab3951f6372241323fd4e2486098fff)
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  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_USB_SCSA2USB_H
27 #define	_SYS_USB_SCSA2USB_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/usb/usba/usbai_private.h>
36 
37 /*
38  * SCSA2USB: This header file contains the internal structures
39  * and variable definitions used in USB mass storage disk driver.
40  */
41 
42 
43 #define	SCSA2USB_INITIAL_ALLOC	4	/* initial soft space alloc */
44 
45 #define	MAX_COMPAT_NAMES	1	/* max compatible names for children */
46 #define	SERIAL_NUM_LEN		64	/* for reading string descriptor */
47 #define	SCSA2USB_SERIAL_LEN	12	/* len of serial no in scsi_inquiry */
48 
49 #define	SCSA2USB_MAX_LUNS	0x10	/* maximum luns supported. */
50 
51 /*
52  * limit the max transfer size to under <= 64K. Some devices
53  * have problems with large transfers
54  */
55 #define	SCSA2USB_MAX_BULK_XFER_SIZE	(64 * 1024)
56 
57 /* Blacklist some vendors whose devices could cause problems */
58 #define	MS_HAGIWARA_SYS_COM_VID	0x693	/* VendorId of Hagiwara Sys-Com */
59 #define	MS_HAGIWARA_SYSCOM_PID1	0x1	/* PID for SmartMedia(SM) device */
60 #define	MS_HAGIWARA_SYSCOM_PID2	0x3	/* PID for CompactFlash(CF) device */
61 #define	MS_HAGIWARA_SYSCOM_PID3	0x5	/* PID for SM/CF Combo device */
62 #define	MS_HAGIWARA_SYSCOM_PID4	0x2	/* PID for new SM device */
63 #define	MS_HAGIWARA_SYSCOM_PID5	0x4	/* PID for new CF device */
64 
65 #define	MS_IOMEGA_VID		0x59b	/* VendorId of Iomega */
66 #define	MS_IOMEGA_PID1_ZIP100	0x1	/* PID of an Older Iomega Zip100 */
67 #define	MS_IOMEGA_PID2_ZIP100	0x2	/* PID of Newer Iomega Zip100 */
68 #define	MS_IOMEGA_PID3_ZIP100	0x31	/* PID of Newer Iomega Zip100 */
69 #define	MS_IOMEGA_PID_ZIP250	0x30	/* PID of Newer Iomega Zip250 */
70 #define	MS_IOMEGA_PID_CLIK	0x60	/* PID of Iomega Clik! drive */
71 
72 #define	MS_MITSUMI_VID		0x3ee	/* VendorId of Mitsumi Inc */
73 #define	MS_MITSUMI_DEVICE_242	0x242	/* bcdDevice of Mitsumi CR-4804TU */
74 #define	MS_MITSUMI_DEVICE_24	0x24	/* bcdDevice of Mitsumi CR-4802TU */
75 
76 #define	MS_YEDATA_VID		0x57b	/* VendorId of Y-E Data Corp */
77 #define	MS_SMSC_VID		0x424	/* Vendor Id of SMSC */
78 #define	MS_SMSC_PID0		0xfdc	/* floppy from SMSC */
79 
80 #define	MS_NEODIO_VID		0xaec	/* Neodio Technologies Corporation */
81 #define	MS_NEODIO_DEVICE_3050	0x3050	/* PID of ND3050/Soyo BayOne */
82 					/* SM/CF/MS/SD */
83 #define	MS_SONY_FLASH_VID	0x54c	/* sony flash device */
84 #define	MS_SONY_FLASH_PID	0x8b
85 
86 #define	MS_TREK_FLASH_VID	0xa16	/* Trek flash device */
87 #define	MS_TREK_FLASH_PID	0x9988
88 
89 #define	MS_PENN_FLASH_VID	0xd7d	/* Penn flash device */
90 #define	MS_PENN_FLASH_PID	0x1320
91 
92 #define	MS_SIMPLETECH_VID	0x7c4	/* VendorId of Simpltech */
93 #define	MS_SIMPLETECH_PID1	0xa400	/* PID for UCF-100 device */
94 
95 #define	MS_ADDONICS_CARD_READER_VID 0x7cc /* addonics */
96 #define	MS_ADDONICS_CARD_READER_PID 0x320
97 
98 
99 /*
100  * List the attributes that need special case in the driver
101  * SCSA2USB_ATTRS_GET_LUN: Bulk Only Transport Get_Max_Lun class specific
102  *		command is not implemented by these devices
103  * SCSA2USB_ATTRS_PM: Some devices don't like being power managed.
104  * SCSA2USB_ATTRS_START_STOP: Some devices don't do anything with
105  *		SCMD_START_STOP opcode (for e.g. SmartMedia/CompactFlash/
106  *		Clik!/MemoryStick/MMC USB readers/writers.
107  * SCSA2USB_ATTRS_GET_CONF: SCMD_GET_CONFIGURATION is not supported
108  * SCMD_TEST_UNIT_READY: for floppies this needs to be converted to
109  *		SCMD_START_STOP as floppies don't support this
110  * SCSA2USB_ATTRS_GET_PERF: SCMD_GET_PERFORMANCE not supported by
111  *		Mitsumi's CD-RW devices.
112  * SCSA2USB_ATTRS_BIG_TIMEOUT: Mitsumi's CD-RW devices need large
113  *		timeout with SCMD_START_STOP cmd
114  * SCSA2USB_ATTRS_RMB: Pay attention to the device's RMB setting,
115  *		instead of automatically treating it as removable
116  *
117  * NOTE: If a device simply STALLs the GET_MAX_LUN BO class-specific command
118  * and recovers then it will not be added to the scsa2usb_blacklist[] table
119  * in scsa2usb.c. The other attributes will not be taken of the table unless
120  * their inclusion causes a recovery and retries (thus seriously affecting
121  * the driver performance).
122  */
123 #define	SCSA2USB_ATTRS_GET_LUN		0x01	/* GET_MAX_LUN (Bulk Only) */
124 #define	SCSA2USB_ATTRS_PM		0x02	/* Some don't support PM */
125 #define	SCSA2USB_ATTRS_START_STOP	0x04	/* SCMD_START_STOP */
126 #define	SCSA2USB_ATTRS_GET_CONF		0x08	/* SCMD_GET_CONFIGURATION */
127 #define	SCSA2USB_ATTRS_GET_PERF		0x10	/* SCMD_GET_PERFORMANCE */
128 #define	SCSA2USB_ATTRS_BIG_TIMEOUT	0x40	/* for SCMD_START_STOP */
129 #define	SCSA2USB_ATTRS_DOORLOCK		0x80	/* for SCMD_DOORLOCK */
130 #define	SCSA2USB_ATTRS_RMB		0x100	/* Pay attention to RMB */
131 #define	SCSA2USB_ATTRS_MODE_SENSE	0x200	/* SCMD_MODE_SENSE */
132 #define	SCSA2USB_ATTRS_INQUIRY		0x400	/* SCMD_INQUIRY */
133 #define	SCSA2USB_ATTRS_REDUCED_CMD	\
134 	(SCSA2USB_ATTRS_DOORLOCK|SCSA2USB_ATTRS_MODE_SENSE| \
135 	SCSA2USB_ATTRS_START_STOP|SCSA2USB_ATTRS_INQUIRY)
136 
137 #define	SCSA2USB_ALL_ATTRS		0xFFFF	/* All of the above */
138 
139 /* max inquiry length */
140 #define	SCSA2USB_MAX_INQ_LEN (offsetof(struct scsi_inquiry, inq_serial))
141 
142 /*
143  * PM support
144  */
145 typedef struct scsa2usb_power  {
146 	/* device busy accounting */
147 	int		scsa2usb_pm_busy;
148 	/* this is the bit mask of the power states that device has */
149 	uint8_t		scsa2usb_pwr_states;
150 
151 	uint8_t		scsa2usb_wakeup_enabled;
152 
153 	/* current power level the device is in */
154 	uint8_t		scsa2usb_current_power;
155 } scsa2usb_power_t;
156 
157 /*
158  * CPR support:
159  *	keep track of the last command issued to the drive. If it
160  *	was TUR or EJECT then allow issuing a CPR suspend.
161  */
162 #define	LOEJECT	2		/* eject bit in start/stop cmd */
163 
164 typedef struct scsa2usb_last_cmd {
165 	/* this is the cdb of the last command issued */
166 	uchar_t		cdb[SCSI_CDB_SIZE];
167 
168 	/* this is the status of the last command issued */
169 	uint_t		status;
170 } scsa2usb_last_cmd_t;
171 
172 /*
173  * override values
174  *	These values may be set in scsa2usb.conf for particular devices
175  */
176 typedef struct scsa2usb_ov {
177 	int	vid;		/* vendor id */
178 	int	pid;		/* product id */
179 	int	rev;		/* revision */
180 	int	subclass;	/* subclass override */
181 	int	protocol;	/* protocol override */
182 	int	pmoff;		/* power management override */
183 	int	not_removable;	/* removable device override */
184 	int	no_modesense;	/* no mode sense */
185 				/* no modesense, doorlock, PM, start/stop */
186 	int	reduced_cmd_support;
187 } scsa2usb_ov_t;
188 
189 
190 /*
191  * Per bulk device "state" data structure.
192  */
193 typedef struct scsa2usb_state {
194 	int			scsa2usb_instance;	/* Instance number    */
195 	int			scsa2usb_dev_state;	/* USB device state   */
196 	int			scsa2usb_flags; 	/* Per instance flags */
197 	int			scsa2usb_intfc_num;	/* Interface number   */
198 	dev_info_t		*scsa2usb_dip;		/* Per device. info   */
199 	scsa2usb_power_t	*scsa2usb_pm;		/* PM state info */
200 
201 	int			scsa2usb_transport_busy; /* ugen/sd traffic */
202 	int			scsa2usb_ugen_open_count;
203 	kcondvar_t		scsa2usb_transport_busy_cv;
204 	kthread_t		*scsa2usb_busy_thread;
205 
206 	kmutex_t		scsa2usb_mutex;		/* Per instance lock  */
207 
208 	struct scsi_hba_tran	*scsa2usb_tran;		/* SCSI transport ptr */
209 	struct scsi_pkt		*scsa2usb_cur_pkt;	/* SCSI packet ptr    */
210 
211 	usba_list_entry_t	scsa2usb_waitQ[SCSA2USB_MAX_LUNS];
212 							/* waitQ list */
213 	struct scsa2usb_cmd	*scsa2usb_arq_cmd;	/* ARQ cmd */
214 	struct buf		*scsa2usb_arq_bp;	/* ARQ buf */
215 
216 	dev_info_t		*scsa2usb_lun_dip[SCSA2USB_MAX_LUNS];
217 						/* store devinfo per LUN  */
218 	struct scsi_inquiry	scsa2usb_lun_inquiry[SCSA2USB_MAX_LUNS];
219 						/* store inquiry per LUN  */
220 	usb_if_descr_t		scsa2usb_intfc_descr;	/* Interface descr    */
221 	usb_ep_descr_t		scsa2usb_bulkin_ept;	/* Bulk In descriptor */
222 	usb_ep_descr_t		scsa2usb_bulkout_ept;	/* Bulkout descriptor */
223 	usb_ep_descr_t		scsa2usb_intr_ept;	/* Intr ept descr */
224 
225 	usb_pipe_handle_t	scsa2usb_default_pipe;	/* Default pipe	Hndle */
226 	usb_pipe_handle_t	scsa2usb_intr_pipe;	/* Intr polling Hndle */
227 	usb_pipe_handle_t	scsa2usb_bulkin_pipe;	/* Bulk Inpipe Handle */
228 	usb_pipe_handle_t	scsa2usb_bulkout_pipe;	/* Bulk Outpipe Hndle */
229 
230 	uint_t			scsa2usb_pipe_state;	/* resetting state */
231 	uint_t			scsa2usb_tag;		/* current tag */
232 	uint_t			scsa2usb_pkt_state;	/* packet state */
233 	uint_t			scsa2usb_n_luns;	/* number of luns */
234 
235 	usb_log_handle_t	scsa2usb_log_handle;	/* log handle */
236 	struct scsa2usb_cpr	*scsa2usb_panic_info;	/* for cpr info */
237 
238 	size_t			scsa2usb_lbasize[SCSA2USB_MAX_LUNS];
239 							/* sector size */
240 	size_t			scsa2usb_totalsec[SCSA2USB_MAX_LUNS];
241 							/* total sectors */
242 	size_t			scsa2usb_secsz[SCSA2USB_MAX_LUNS];
243 							/* sector size */
244 	size_t			scsa2usb_max_bulk_xfer_size; /* from HCD */
245 
246 	usb_client_dev_data_t	*scsa2usb_dev_data;	/* USB registration */
247 	scsa2usb_last_cmd_t	scsa2usb_last_cmd;	/* last/prev command */
248 
249 	uint_t			scsa2usb_attrs;		/* for bad devices */
250 	uint_t			scsa2usb_cmd_protocol;	/* CMD protocol used */
251 	kthread_t		*scsa2usb_work_thread_id; /* handle commands */
252 
253 				/* conf file override values */
254 	uint_t			scsa2usb_subclass_override;
255 	uint_t			scsa2usb_protocol_override;
256 	char			*scsa2usb_override_str;
257 
258 				/* suppress repetitive disconnect warnings */
259 	boolean_t		scsa2usb_warning_given;
260 
261 	boolean_t		scsa2usb_rcvd_not_ready; /* received NOT */
262 							/* READY sense data */
263 
264 	usb_ugen_hdl_t		scsa2usb_ugen_hdl;	/* ugen support */
265 } scsa2usb_state_t;
266 
267 
268 /* for warlock */
269 _NOTE(MUTEX_PROTECTS_DATA(scsa2usb_state::scsa2usb_mutex, scsa2usb_state))
270 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_instance))
271 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dip))
272 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_cmd))
273 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_bp))
274 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_ept))
275 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_ept))
276 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_ept))
277 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_default_pipe))
278 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_pipe))
279 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_pipe))
280 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_pipe))
281 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_log_handle))
282 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intfc_num))
283 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dev_data))
284 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_ugen_hdl))
285 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_pm))
286 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa2usb_power_t))
287 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_hba_tran_t))
288 _NOTE(SCHEME_PROTECTS_DATA("unshared data", usb_bulk_req_t))
289 
290 /* scsa2usb_pipe_state values */
291 #define	SCSA2USB_PIPE_NORMAL		0x00	/* no reset or clearing	*/
292 #define	SCSA2USB_PIPE_CLOSING		0x01	/* closing all pipes */
293 #define	SCSA2USB_PIPE_DEV_RESET		0x02	/* device specific reset */
294 
295 /* pkt xfer state machine */
296 #define	SCSA2USB_PKT_NONE		0	/* device is idle */
297 #define	SCSA2USB_PKT_PROCESS_CSW	1	/* device doing status again */
298 #define	SCSA2USB_PKT_DO_COMP		2	/* device is done xfer */
299 
300 /* scsa2usb_flags values */
301 #define	SCSA2USB_FLAGS_PIPES_OPENED	0x001	/* usb pipes are open */
302 #define	SCSA2USB_FLAGS_HBA_ATTACH_SETUP	0x002	/* scsi hba setup done */
303 #define	SCSA2USB_FLAGS_LOCKS_INIT	0x004	/* basic inits done */
304 
305 /* scsa2usb_cmd_protocol values */
306 #define	SCSA2USB_UNKNOWN_PROTOCOL	0x0000	/* unknown wire protocol */
307 #define	SCSA2USB_CB_PROTOCOL		0x0001	/* CBI wire protocol */
308 #define	SCSA2USB_CBI_PROTOCOL		0x0002	/* CBI w/ intr wire protocol */
309 #define	SCSA2USB_BULK_ONLY_PROTOCOL	0x0004	/* Bulk Only wire protocol */
310 
311 #define	SCSA2USB_SCSI_CMDSET		0x1000	/* SCSI command set followed */
312 #define	SCSA2USB_ATAPI_CMDSET		0x2000	/* ATAPI command set followed */
313 #define	SCSA2USB_UFI_CMDSET		0x4000	/* UFI command set followed */
314 #define	SCSA2USB_CMDSET_MASK		0x7000	/* OR al the above */
315 
316 #define	SCSA2USB_IS_UFI_CMDSET(s) \
317 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_UFI_CMDSET))
318 #define	SCSA2USB_IS_SCSI_CMDSET(s) \
319 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_SCSI_CMDSET))
320 #define	SCSA2USB_IS_ATAPI_CMDSET(s) \
321 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_ATAPI_CMDSET))
322 
323 #define	SCSA2USB_IS_CB(s) \
324 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_CB_PROTOCOL))
325 
326 #define	SCSA2USB_IS_CBI(s) \
327 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_CBI_PROTOCOL))
328 
329 #define	SCSA2USB_IS_BULK_ONLY(s) \
330 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_BULK_ONLY_PROTOCOL))
331 
332 /* check if it is ok to access the device and send command to it */
333 #define	SCSA2USB_DEVICE_ACCESS_OK(s) \
334 	((s)->scsa2usb_dev_state == USB_DEV_ONLINE)
335 
336 /* check if we are in any reset */
337 #define	SCSA2USB_IN_RESET(s) \
338 	(((s)->scsa2usb_pipe_state & SCSA2USB_PIPE_DEV_RESET) != 0)
339 
340 /* check if the device is busy */
341 #define	SCSA2USB_BUSY(s) \
342 	(((s)->scsa2usb_cur_pkt) || \
343 	((s)->scsa2usb_pipe_state != SCSA2USB_PIPE_NORMAL) || \
344 	((s)->scsa2usb_pkt_state != SCSA2USB_PKT_NONE))
345 
346 /* check if we're doing cpr */
347 #define	SCSA2USB_CHK_CPR(s) \
348 	(((s)->scsa2usb_dev_state == USB_DEV_SUSPENDED))
349 
350 /* check if we're either paniced or in cpr state */
351 #define	SCSA2USB_CHK_PANIC_CPR(s) \
352 	(ddi_in_panic() || SCSA2USB_CHK_CPR(s))
353 
354 /* reset scsa2usb state after pkt_comp is called */
355 #define	SCSA2USB_RESET_CUR_PKT(s) \
356 	(s)->scsa2usb_cur_pkt = NULL; \
357 	(s)->scsa2usb_pkt_state = SCSA2USB_PKT_NONE;
358 
359 /* print a panic sync message to the console */
360 #define	SCSA2USB_PRINT_SYNC_MSG(m, s) \
361 	if ((m) == B_TRUE) { \
362 		USB_DPRINTF_L0(DPRINT_MASK_SCSA, (s)->scsa2usb_log_handle, \
363 		    "syncing not supported"); \
364 		(m) = B_FALSE; \
365 	}
366 
367 /* Cancel callbacks registered during attach time */
368 #define	SCSA2USB_CANCEL_CB(id) \
369 	if ((id)) { \
370 		(void) callb_delete((id)); \
371 		(id) = 0; \
372 	}
373 
374 /* Set SCSA2USB_PKT_DO_COMP state if there is active I/O */
375 #define	SCSA2USB_SET_PKT_DO_COMP_STATE(s) \
376 	if ((s)->scsa2usb_cur_pkt) { \
377 		(s)->scsa2usb_pkt_state = SCSA2USB_PKT_DO_COMP; \
378 	}
379 
380 #define	SCSA2USB_FREE_MSG(data) \
381 	if ((data)) { \
382 		freemsg((data)); \
383 	}
384 
385 #define	SCSA2USB_FREE_BULK_REQ(req) \
386 	if ((req)) { \
387 		usb_free_bulk_req((req));	/* Free request */ \
388 	}
389 
390 
391 /* SCSA related */
392 #define	ADDR2TRAN(ap)		((ap)->a_hba_tran)
393 #define	TRAN2SCSA2USB(tran)	((scsa2usb_state_t *)(tran)->tran_hba_private)
394 #define	ADDR2SCSA2USB(ap)	(TRAN2SCSA2USB(ADDR2TRAN(ap)))
395 
396 #define	PKT_PRIV_LEN		16
397 
398 /*
399  * auto request sense
400  */
401 #define	RQ_MAKECOM_COMMON(pktp, flag, cmd) \
402 	(pktp)->pkt_flags = (flag), \
403 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_cmd = (cmd), \
404 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_lun = \
405 	    (pktp)->pkt_address.a_lun
406 
407 #define	RQ_MAKECOM_G0(pktp, flag, cmd, addr, cnt) \
408 	RQ_MAKECOM_COMMON((pktp), (flag), (cmd)), \
409 	FORMG0ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
410 	FORMG0COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
411 
412 
413 /* transport related */
414 #define	SCSA2USB_JUST_ACCEPT	0
415 #define	SCSA2USB_TRANSPORT	1
416 #define	SCSA2USB_REJECT		-1
417 
418 /*
419  * The scsa2usb_cpr_info data structure is used for cpr related
420  * callbacks. It is used for panic callbacks as well.
421  */
422 typedef struct scsa2usb_cpr {
423 	callb_cpr_t		cpr;		/* for cpr related info */
424 	struct scsa2usb_state	*statep;	/* for scsa2usb state info */
425 	kmutex_t		lockp;		/* mutex used by cpr_info_t */
426 } scsa2usb_cpr_t;
427 
428 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::cpr))
429 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::statep))
430 
431 /*
432  * The scsa2usb_cmd data structure is defined here. It gets
433  * initialized per command that is sent to the device.
434  */
435 typedef struct scsa2usb_cmd {
436 	struct scsi_pkt		*cmd_pkt;		/* copy of pkt ptr */
437 	struct	buf		*cmd_bp;		/* copy of bp ptr */
438 	size_t			cmd_xfercount;		/* current xfer count */
439 	size_t			cmd_resid_xfercount;	/* last xfer resid */
440 	int			cmd_scblen;		/* status length */
441 	int			cmd_tag;		/* tag */
442 	int			cmd_timeout;		/* copy of pkt_time */
443 	uchar_t			cmd_cdb[SCSI_CDB_SIZE];	/* CDB */
444 	uchar_t			cmd_dir;		/* direction */
445 	uchar_t			cmd_actual_len; 	/* cdb len */
446 	uchar_t			cmd_cdblen;		/* requested  cdb len */
447 	struct scsi_arq_status	cmd_scb;		/* status, w/ arq */
448 
449 	/* used in multiple xfers */
450 	size_t			cmd_total_xfercount;	/* total xfer val */
451 	size_t			cmd_offset;		/* offset into buf */
452 	int			cmd_lba;		/* current xfer lba */
453 	int			cmd_done;		/* command done? */
454 	int			cmd_blksize;		/* block size */
455 	usba_list_entry_t	cmd_waitQ;		/* waitQ element */
456 } scsa2usb_cmd_t;
457 
458 /* for warlock */
459 _NOTE(SCHEME_PROTECTS_DATA("unique per packet or safe sharing",
460     scsi_cdb scsi_status scsi_pkt buf scsa2usb_cmd scsi_arq_status))
461 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device scsi_address))
462 
463 /* scsa2usb_cdb position of fields in CDB */
464 #define	SCSA2USB_OPCODE		0		/* Opcode field */
465 #define	SCSA2USB_LUN		1		/* LUN field */
466 #define	SCSA2USB_LBA_0		2		/* LBA[0] field */
467 #define	SCSA2USB_LBA_1		3		/* LBA[1] field */
468 #define	SCSA2USB_LBA_2		4		/* LBA[2] field */
469 #define	SCSA2USB_LBA_3		5		/* LBA[3] field */
470 #define	SCSA2USB_LEN_0		7		/* LEN[0] field */
471 #define	SCSA2USB_LEN_1		8		/* LEN[1] field */
472 
473 /* macros to calculate LBA for 6/10/12-byte commands */
474 #define	SCSA2USB_LBA_6BYTE(pkt) \
475 	(((pkt)->pkt_cdbp[1] & 0x1f) << 16) + \
476 	((pkt)->pkt_cdbp[2] << 8) + (pkt)->pkt_cdbp[3]
477 #define	SCSA2USB_LEN_6BYTE(pkt)		(pkt)->pkt_cdbp[4]
478 
479 #define	SCSA2USB_LEN_10BYTE(pkt) \
480 	((pkt)->pkt_cdbp[7] << 8) + (pkt)->pkt_cdbp[8]
481 #define	SCSA2USB_LBA_10BYTE(pkt) \
482 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
483 	    ((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
484 
485 #define	SCSA2USB_LEN_12BYTE(pkt) \
486 	((pkt)->pkt_cdbp[6] << 24) + ((pkt)->pkt_cdbp[7] << 16) + \
487 	    ((pkt)->pkt_cdbp[8] << 8) +  (pkt)->pkt_cdbp[9]
488 #define	SCSA2USB_LBA_12BYTE(pkt) \
489 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
490 	    ((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
491 
492 /* macros to convert a pkt to cmd and vice-versa */
493 #define	PKT2CMD(pkt)		((scsa2usb_cmd_t *)(pkt)->pkt_ha_private)
494 #define	CMD2PKT(sp)		((sp)->cmd_pkt
495 
496 /* bulk pipe default timeout value - how long the command to be tried? */
497 #define	SCSA2USB_BULK_PIPE_TIMEOUT	(2 * USB_PIPE_TIMEOUT)
498 
499 /* drain timeout in seconds on the work thread */
500 #define	SCSA2USB_DRAIN_TIMEOUT		60
501 
502 /*
503  * limit on the number of requests that can be queued per LUN:
504  * 3 for untagged queueing, 1 for scsiwatch and a margin of 2
505  */
506 #define	SCSA2USB_MAX_REQ_PER_LUN	6
507 
508 /*
509  * The following data structure is used to save the values returned
510  * by the READ_CAPACITY command. lba is the max allowed logical block
511  * address and blen is max allowed block size.
512  */
513 typedef struct scsa2usb_read_cap {
514 	uchar_t	scsa2usb_read_cap_lba3;		/* Max lba supported */
515 	uchar_t	scsa2usb_read_cap_lba2;
516 	uchar_t	scsa2usb_read_cap_lba1;
517 	uchar_t	scsa2usb_read_cap_lba0;
518 	uchar_t	scsa2usb_read_cap_blen3;	/* Max block size supported */
519 	uchar_t	scsa2usb_read_cap_blen2;
520 	uchar_t	scsa2usb_read_cap_blen1;
521 	uchar_t	scsa2usb_read_cap_blen0;
522 } scsa2usb_read_cap_t;
523 
524 #define	SCSA2USB_MK_32BIT(a, b, c, d) \
525 		(((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
526 
527 /* position of fields for SCMD_READ_CD CDB */
528 #define	SCSA2USB_READ_CD_LEN_0	6	/* LEN[0] of SCMD_READ_CD */
529 #define	SCSA2USB_READ_CD_LEN_1	7	/* LEN[1] of SCMD_READ_CD */
530 #define	SCSA2USB_READ_CD_LEN_2	8	/* LEN[2] of SCMD_READ_CD */
531 
532 /* macro to calculate LEN for SCMD_READ_CD command */
533 #define	SCSA2USB_LEN_READ_CD(pkt) \
534 	(((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_0] << 16) +\
535 	    ((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_1] << 8) +\
536 	    (pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_2])
537 
538 /* Figure out Block Size before issuing a WRITE to CD-RW device */
539 #define	SCSA2USB_CDRW_BLKSZ(bcount, len)	((bcount) / (len));
540 #define	SCSA2USB_VALID_CDRW_BLKSZ(blksz) \
541 	(((blksz) == CDROM_BLK_2048) || ((blksz) == CDROM_BLK_2352) || \
542 	((blksz) == CDROM_BLK_2336) || ((blksz) == CDROM_BLK_2324) || \
543 	((blksz) == 0))
544 
545 /* debug and error msg logging */
546 #define	DPRINT_MASK_SCSA	0x0001		/* for SCSA */
547 #define	DPRINT_MASK_ATTA	0x0002		/* for ATTA */
548 #define	DPRINT_MASK_EVENTS	0x0004		/* for event handling */
549 #define	DPRINT_MASK_CALLBACKS	0x0008		/* for callbacks  */
550 #define	DPRINT_MASK_TIMEOUT	0x0010		/* for timeouts */
551 #define	DPRINT_MASK_DUMPING	0x0020		/* for dumping */
552 #define	DPRINT_MASK_PM		0x0040		/* for pwr mgmt */
553 #define	DPRINT_MASK_ALL		0xffffffff	/* for everything */
554 
555 #ifdef	DEBUG
556 #define	SCSA2USB_PRINT_CDB	scsa2usb_print_cdb
557 #else
558 #define	SCSA2USB_PRINT_CDB	0 &&
559 #endif
560 
561 /* ugen support */
562 #define	SCSA2USB_MINOR_UGEN_BITS_MASK	0xff
563 #define	SCSA2USB_MINOR_INSTANCE_MASK	~SCSA2USB_MINOR_UGEN_BITS_MASK
564 #define	SCSA2USB_MINOR_INSTANCE_SHIFT	8
565 
566 #define	SCSA2USB_MINOR_TO_INSTANCE(minor)	\
567 		(((minor) & SCSA2USB_MINOR_INSTANCE_MASK) >> \
568 		SCSA2USB_MINOR_INSTANCE_SHIFT)
569 
570 #ifdef __cplusplus
571 }
572 #endif
573 
574 #endif	/* _SYS_USB_SCSA2USB_H */
575