xref: /onnv-gate/usr/src/uts/common/sys/usb/scsa2usb/scsa2usb.h (revision 5789:ebd29b30fffa)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51984Scg149915  * Common Development and Distribution License (the "License").
61984Scg149915  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  *
21*5789Ssl147100  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
220Sstevel@tonic-gate  * Use is subject to license terms.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef _SYS_USB_SCSA2USB_H
260Sstevel@tonic-gate #define	_SYS_USB_SCSA2USB_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifdef	__cplusplus
310Sstevel@tonic-gate extern "C" {
320Sstevel@tonic-gate #endif
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <sys/usb/usba/usbai_private.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * SCSA2USB: This header file contains the internal structures
380Sstevel@tonic-gate  * and variable definitions used in USB mass storage disk driver.
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate 
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #define	SCSA2USB_INITIAL_ALLOC	4	/* initial soft space alloc */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #define	MAX_COMPAT_NAMES	1	/* max compatible names for children */
450Sstevel@tonic-gate #define	SERIAL_NUM_LEN		64	/* for reading string descriptor */
460Sstevel@tonic-gate #define	SCSA2USB_SERIAL_LEN	12	/* len of serial no in scsi_inquiry */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #define	SCSA2USB_MAX_LUNS	0x10	/* maximum luns supported. */
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * limit the max transfer size to under <= 64K. Some devices
520Sstevel@tonic-gate  * have problems with large transfers
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate #define	SCSA2USB_MAX_BULK_XFER_SIZE	(64 * 1024)
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /* Blacklist some vendors whose devices could cause problems */
570Sstevel@tonic-gate #define	MS_HAGIWARA_SYS_COM_VID	0x693	/* VendorId of Hagiwara Sys-Com */
580Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID1	0x1	/* PID for SmartMedia(SM) device */
590Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID2	0x3	/* PID for CompactFlash(CF) device */
600Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID3	0x5	/* PID for SM/CF Combo device */
610Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID4	0x2	/* PID for new SM device */
620Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID5	0x4	/* PID for new CF device */
630Sstevel@tonic-gate 
640Sstevel@tonic-gate #define	MS_IOMEGA_VID		0x59b	/* VendorId of Iomega */
650Sstevel@tonic-gate #define	MS_IOMEGA_PID1_ZIP100	0x1	/* PID of an Older Iomega Zip100 */
660Sstevel@tonic-gate #define	MS_IOMEGA_PID2_ZIP100	0x2	/* PID of Newer Iomega Zip100 */
670Sstevel@tonic-gate #define	MS_IOMEGA_PID3_ZIP100	0x31	/* PID of Newer Iomega Zip100 */
680Sstevel@tonic-gate #define	MS_IOMEGA_PID_ZIP250	0x30	/* PID of Newer Iomega Zip250 */
690Sstevel@tonic-gate #define	MS_IOMEGA_PID_CLIK	0x60	/* PID of Iomega Clik! drive */
700Sstevel@tonic-gate 
710Sstevel@tonic-gate #define	MS_MITSUMI_VID		0x3ee	/* VendorId of Mitsumi Inc */
720Sstevel@tonic-gate #define	MS_MITSUMI_DEVICE_242	0x242	/* bcdDevice of Mitsumi CR-4804TU */
730Sstevel@tonic-gate #define	MS_MITSUMI_DEVICE_24	0x24	/* bcdDevice of Mitsumi CR-4802TU */
740Sstevel@tonic-gate 
750Sstevel@tonic-gate #define	MS_YEDATA_VID		0x57b	/* VendorId of Y-E Data Corp */
760Sstevel@tonic-gate #define	MS_SMSC_VID		0x424	/* Vendor Id of SMSC */
770Sstevel@tonic-gate #define	MS_SMSC_PID0		0xfdc	/* floppy from SMSC */
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define	MS_NEODIO_VID		0xaec	/* Neodio Technologies Corporation */
800Sstevel@tonic-gate #define	MS_NEODIO_DEVICE_3050	0x3050	/* PID of ND3050/Soyo BayOne */
810Sstevel@tonic-gate 					/* SM/CF/MS/SD */
820Sstevel@tonic-gate #define	MS_SONY_FLASH_VID	0x54c	/* sony flash device */
830Sstevel@tonic-gate #define	MS_SONY_FLASH_PID	0x8b
840Sstevel@tonic-gate 
850Sstevel@tonic-gate #define	MS_TREK_FLASH_VID	0xa16	/* Trek flash device */
860Sstevel@tonic-gate #define	MS_TREK_FLASH_PID	0x9988
870Sstevel@tonic-gate 
880Sstevel@tonic-gate #define	MS_PENN_FLASH_VID	0xd7d	/* Penn flash device */
890Sstevel@tonic-gate #define	MS_PENN_FLASH_PID	0x1320
900Sstevel@tonic-gate 
910Sstevel@tonic-gate #define	MS_SIMPLETECH_VID	0x7c4	/* VendorId of Simpltech */
920Sstevel@tonic-gate #define	MS_SIMPLETECH_PID1	0xa400	/* PID for UCF-100 device */
930Sstevel@tonic-gate 
940Sstevel@tonic-gate #define	MS_ADDONICS_CARD_READER_VID 0x7cc /* addonics */
950Sstevel@tonic-gate #define	MS_ADDONICS_CARD_READER_PID 0x320
960Sstevel@tonic-gate 
971101Ssl147100 #define	MS_ACOMDATA_VID		0xc0b	/* VendorId of DMI (Acomdata) */
981101Ssl147100 #define	MS_ACOMDATA_PID1	0x5fab	/* PID for 80GB USB/1394 disk */
991101Ssl147100 
1001101Ssl147100 #define	MS_OTI_VID		0xea0	/* VendorID of OTI */
1011101Ssl147100 #define	MS_OTI_DEVICE_6828	0x6828	/* PID for 6828 flash disk */
1020Sstevel@tonic-gate 
1034834Sfb209375 #define	MS_SCANLOGIC_VID	0x04ce	/* VendorID of ScanLogic */
1044834Sfb209375 #define	MS_SCANLOGIC_PID1	0x0002	/* SL USB Storage Device */
1054834Sfb209375 
106*5789Ssl147100 #define	MS_SUPERTOP_VID		0x14cd	/* Super Top USB 2.0 IDE enclosure */
107*5789Ssl147100 #define	MS_SUPERTOP_DEVICE_6600	0x6600
108*5789Ssl147100 
1090Sstevel@tonic-gate /*
1102506Ssl147100  * The AMI virtual floppy device is not a real USB storage device, but
1112506Ssl147100  * emulated by the SP firmware shipped together with important Sun x86
1122506Ssl147100  * products such as Galaxy and Thumper platforms. The device causes
1132506Ssl147100  * very long delay in boot process of these platforms which is a big
1142506Ssl147100  * performance issue. Improvement in firmware may solve the issue, but
1152506Ssl147100  * before the firmware is fixed, it needs to be taken care of by software
1162506Ssl147100  * to avoid the huge impact on user experience.
1172506Ssl147100  *
1182506Ssl147100  * The long boot delay is caused by timeouts and retries of READ CAPACITY
1192506Ssl147100  * command issued to the device. The device is a USB ufi subclass device
1202506Ssl147100  * using CBI protocol. When READ CAPACITY command is issued, the device
1212506Ssl147100  * returns STALL on the bulk endpoint during the data stage, however, it
1222506Ssl147100  * doesn't return status on the intr pipe during status stage, so the intr
1232506Ssl147100  * pipe can only fail with timeout.
1242506Ssl147100  *
1252506Ssl147100  * Reducing timeout value to 1 second can help a little bit, but the delay
1262506Ssl147100  * is still noticeable, because the target driver would make many retries
1272506Ssl147100  * for this command. It is not desirable to mess with the target driver
1282506Ssl147100  * for a broken USB device. So adding the device to the scsa2usb blacklist
1292506Ssl147100  * is the best choice we have.
1302506Ssl147100  *
1312506Ssl147100  * It is found that the READ CAPACITY failure only happens when there is
1322506Ssl147100  * no media in the floppy drive. When there is a media, the device works
1332506Ssl147100  * just fine. So READ CAPACITY command cannot be arbitrarily disabled.
1342506Ssl147100  * Media status needs to be checked before issuing the command by sending
1352506Ssl147100  * an additional TEST UNIT READY command. If TEST UNIT READY command
1362506Ssl147100  * return STATUS_GOOD, it means the media is ready and then READ CAPACITY
1372506Ssl147100  * can be issued.
1382506Ssl147100  *
1392506Ssl147100  * SCSA2USB_ATTRS_NO_MEDIA_CHECK is added below for this purpose. It is
1402506Ssl147100  * overrided in scsa2usb.c for the AMI virtual floppy device to take care
1412506Ssl147100  * of the special need.
1422506Ssl147100  */
1432506Ssl147100 #define	MS_AMI_VID		0x46b	/* VendorId of AMI */
1442506Ssl147100 #define	MS_AMI_VIRTUAL_FLOPPY	0xff40	/* PID for AMI virtual floppy */
1452506Ssl147100 
1462506Ssl147100 /*
1470Sstevel@tonic-gate  * List the attributes that need special case in the driver
1480Sstevel@tonic-gate  * SCSA2USB_ATTRS_GET_LUN: Bulk Only Transport Get_Max_Lun class specific
1490Sstevel@tonic-gate  *		command is not implemented by these devices
1500Sstevel@tonic-gate  * SCSA2USB_ATTRS_PM: Some devices don't like being power managed.
1510Sstevel@tonic-gate  * SCSA2USB_ATTRS_START_STOP: Some devices don't do anything with
1520Sstevel@tonic-gate  *		SCMD_START_STOP opcode (for e.g. SmartMedia/CompactFlash/
1530Sstevel@tonic-gate  *		Clik!/MemoryStick/MMC USB readers/writers.
1540Sstevel@tonic-gate  * SCSA2USB_ATTRS_GET_CONF: SCMD_GET_CONFIGURATION is not supported
1550Sstevel@tonic-gate  * SCMD_TEST_UNIT_READY: for floppies this needs to be converted to
1560Sstevel@tonic-gate  *		SCMD_START_STOP as floppies don't support this
1570Sstevel@tonic-gate  * SCSA2USB_ATTRS_GET_PERF: SCMD_GET_PERFORMANCE not supported by
1580Sstevel@tonic-gate  *		Mitsumi's CD-RW devices.
1590Sstevel@tonic-gate  * SCSA2USB_ATTRS_BIG_TIMEOUT: Mitsumi's CD-RW devices need large
1600Sstevel@tonic-gate  *		timeout with SCMD_START_STOP cmd
1610Sstevel@tonic-gate  * SCSA2USB_ATTRS_RMB: Pay attention to the device's RMB setting,
1620Sstevel@tonic-gate  *		instead of automatically treating it as removable
1631101Ssl147100  * SCSA2USB_ATTRS_USE_CSW_RESIDUE: Some devices report false residue in
1641101Ssl147100  *		the CSW of bulk-only transfer status stage though data
1651101Ssl147100  *		was successfully transfered, so need to ignore residue.
1662506Ssl147100  * SCSA2USB_ATTRS_NO_MEDIA_CHECK: AMI Virtual Floppy devices need to
1672506Ssl147100  *		check if media is ready before issuing READ CAPACITY.
1684834Sfb209375  * SCSA2USB_ATTRS_NO_CAP_ADJUST: Some devices return total logical block number
1694834Sfb209375  * 		instead of highest logical block address on READ_CAPACITY cmd.
1700Sstevel@tonic-gate  *
1710Sstevel@tonic-gate  * NOTE: If a device simply STALLs the GET_MAX_LUN BO class-specific command
1720Sstevel@tonic-gate  * and recovers then it will not be added to the scsa2usb_blacklist[] table
1730Sstevel@tonic-gate  * in scsa2usb.c. The other attributes will not be taken of the table unless
1740Sstevel@tonic-gate  * their inclusion causes a recovery and retries (thus seriously affecting
1750Sstevel@tonic-gate  * the driver performance).
1760Sstevel@tonic-gate  */
1770Sstevel@tonic-gate #define	SCSA2USB_ATTRS_GET_LUN		0x01	/* GET_MAX_LUN (Bulk Only) */
1780Sstevel@tonic-gate #define	SCSA2USB_ATTRS_PM		0x02	/* Some don't support PM */
1790Sstevel@tonic-gate #define	SCSA2USB_ATTRS_START_STOP	0x04	/* SCMD_START_STOP */
1800Sstevel@tonic-gate #define	SCSA2USB_ATTRS_GET_CONF		0x08	/* SCMD_GET_CONFIGURATION */
1810Sstevel@tonic-gate #define	SCSA2USB_ATTRS_GET_PERF		0x10	/* SCMD_GET_PERFORMANCE */
1820Sstevel@tonic-gate #define	SCSA2USB_ATTRS_BIG_TIMEOUT	0x40	/* for SCMD_START_STOP */
1830Sstevel@tonic-gate #define	SCSA2USB_ATTRS_DOORLOCK		0x80	/* for SCMD_DOORLOCK */
1840Sstevel@tonic-gate #define	SCSA2USB_ATTRS_RMB		0x100	/* Pay attention to RMB */
1850Sstevel@tonic-gate #define	SCSA2USB_ATTRS_MODE_SENSE	0x200	/* SCMD_MODE_SENSE */
1860Sstevel@tonic-gate #define	SCSA2USB_ATTRS_INQUIRY		0x400	/* SCMD_INQUIRY */
1871101Ssl147100 #define	SCSA2USB_ATTRS_USE_CSW_RESIDUE	0x800	/* for residue checking */
1882506Ssl147100 #define	SCSA2USB_ATTRS_NO_MEDIA_CHECK	0x1000	/* for media checking */
1894834Sfb209375 #define	SCSA2USB_ATTRS_NO_CAP_ADJUST	0x2000	/* for CAPACITY adjusting */
1900Sstevel@tonic-gate #define	SCSA2USB_ATTRS_REDUCED_CMD	\
1910Sstevel@tonic-gate 	(SCSA2USB_ATTRS_DOORLOCK|SCSA2USB_ATTRS_MODE_SENSE| \
1921101Ssl147100 	SCSA2USB_ATTRS_START_STOP|SCSA2USB_ATTRS_INQUIRY| \
1931101Ssl147100 	SCSA2USB_ATTRS_USE_CSW_RESIDUE)
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #define	SCSA2USB_ALL_ATTRS		0xFFFF	/* All of the above */
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate /* max inquiry length */
1980Sstevel@tonic-gate #define	SCSA2USB_MAX_INQ_LEN (offsetof(struct scsi_inquiry, inq_serial))
1990Sstevel@tonic-gate 
2001984Scg149915 /* page code of scsi mode page */
2011984Scg149915 #ifndef SD_MODE_SENSE_PAGE3_CODE
2021984Scg149915 #define	SD_MODE_SENSE_PAGE3_CODE	0x03
2031984Scg149915 #endif
2041984Scg149915 
2051984Scg149915 #ifndef SD_MODE_SENSE_PAGE4_CODE
2061984Scg149915 #define	SD_MODE_SENSE_PAGE4_CODE	0x04
2071984Scg149915 #endif
2081984Scg149915 
2090Sstevel@tonic-gate /*
2100Sstevel@tonic-gate  * PM support
2110Sstevel@tonic-gate  */
2120Sstevel@tonic-gate typedef struct scsa2usb_power  {
2130Sstevel@tonic-gate 	/* device busy accounting */
2140Sstevel@tonic-gate 	int		scsa2usb_pm_busy;
2150Sstevel@tonic-gate 	/* this is the bit mask of the power states that device has */
2160Sstevel@tonic-gate 	uint8_t		scsa2usb_pwr_states;
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 	uint8_t		scsa2usb_wakeup_enabled;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	/* current power level the device is in */
2210Sstevel@tonic-gate 	uint8_t		scsa2usb_current_power;
2220Sstevel@tonic-gate } scsa2usb_power_t;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate /*
2250Sstevel@tonic-gate  * CPR support:
2260Sstevel@tonic-gate  *	keep track of the last command issued to the drive. If it
2270Sstevel@tonic-gate  *	was TUR or EJECT then allow issuing a CPR suspend.
2280Sstevel@tonic-gate  */
2290Sstevel@tonic-gate #define	LOEJECT	2		/* eject bit in start/stop cmd */
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate typedef struct scsa2usb_last_cmd {
2320Sstevel@tonic-gate 	/* this is the cdb of the last command issued */
2330Sstevel@tonic-gate 	uchar_t		cdb[SCSI_CDB_SIZE];
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 	/* this is the status of the last command issued */
2360Sstevel@tonic-gate 	uint_t		status;
2370Sstevel@tonic-gate } scsa2usb_last_cmd_t;
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate /*
2400Sstevel@tonic-gate  * override values
2410Sstevel@tonic-gate  *	These values may be set in scsa2usb.conf for particular devices
2420Sstevel@tonic-gate  */
2430Sstevel@tonic-gate typedef struct scsa2usb_ov {
2440Sstevel@tonic-gate 	int	vid;		/* vendor id */
2450Sstevel@tonic-gate 	int	pid;		/* product id */
2460Sstevel@tonic-gate 	int	rev;		/* revision */
2470Sstevel@tonic-gate 	int	subclass;	/* subclass override */
2480Sstevel@tonic-gate 	int	protocol;	/* protocol override */
2490Sstevel@tonic-gate 	int	pmoff;		/* power management override */
2501415Scg149915 	int	fake_removable;	/* removable device override */
2510Sstevel@tonic-gate 	int	no_modesense;	/* no mode sense */
2520Sstevel@tonic-gate 				/* no modesense, doorlock, PM, start/stop */
2530Sstevel@tonic-gate 	int	reduced_cmd_support;
2540Sstevel@tonic-gate } scsa2usb_ov_t;
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate /*
2580Sstevel@tonic-gate  * Per bulk device "state" data structure.
2590Sstevel@tonic-gate  */
2600Sstevel@tonic-gate typedef struct scsa2usb_state {
2610Sstevel@tonic-gate 	int			scsa2usb_instance;	/* Instance number    */
2620Sstevel@tonic-gate 	int			scsa2usb_dev_state;	/* USB device state   */
2630Sstevel@tonic-gate 	int			scsa2usb_flags; 	/* Per instance flags */
2640Sstevel@tonic-gate 	int			scsa2usb_intfc_num;	/* Interface number   */
2650Sstevel@tonic-gate 	dev_info_t		*scsa2usb_dip;		/* Per device. info   */
2660Sstevel@tonic-gate 	scsa2usb_power_t	*scsa2usb_pm;		/* PM state info */
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 	int			scsa2usb_transport_busy; /* ugen/sd traffic */
2690Sstevel@tonic-gate 	int			scsa2usb_ugen_open_count;
2700Sstevel@tonic-gate 	kcondvar_t		scsa2usb_transport_busy_cv;
2710Sstevel@tonic-gate 	kthread_t		*scsa2usb_busy_thread;
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	kmutex_t		scsa2usb_mutex;		/* Per instance lock  */
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate 	struct scsi_hba_tran	*scsa2usb_tran;		/* SCSI transport ptr */
2760Sstevel@tonic-gate 	struct scsi_pkt		*scsa2usb_cur_pkt;	/* SCSI packet ptr    */
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate 	usba_list_entry_t	scsa2usb_waitQ[SCSA2USB_MAX_LUNS];
2790Sstevel@tonic-gate 							/* waitQ list */
2800Sstevel@tonic-gate 	struct scsa2usb_cmd	*scsa2usb_arq_cmd;	/* ARQ cmd */
2810Sstevel@tonic-gate 	struct buf		*scsa2usb_arq_bp;	/* ARQ buf */
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	dev_info_t		*scsa2usb_lun_dip[SCSA2USB_MAX_LUNS];
2840Sstevel@tonic-gate 						/* store devinfo per LUN  */
2850Sstevel@tonic-gate 	struct scsi_inquiry	scsa2usb_lun_inquiry[SCSA2USB_MAX_LUNS];
2860Sstevel@tonic-gate 						/* store inquiry per LUN  */
2870Sstevel@tonic-gate 	usb_if_descr_t		scsa2usb_intfc_descr;	/* Interface descr    */
2880Sstevel@tonic-gate 	usb_ep_descr_t		scsa2usb_bulkin_ept;	/* Bulk In descriptor */
2890Sstevel@tonic-gate 	usb_ep_descr_t		scsa2usb_bulkout_ept;	/* Bulkout descriptor */
2900Sstevel@tonic-gate 	usb_ep_descr_t		scsa2usb_intr_ept;	/* Intr ept descr */
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_default_pipe;	/* Default pipe	Hndle */
2930Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_intr_pipe;	/* Intr polling Hndle */
2940Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_bulkin_pipe;	/* Bulk Inpipe Handle */
2950Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_bulkout_pipe;	/* Bulk Outpipe Hndle */
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate 	uint_t			scsa2usb_pipe_state;	/* resetting state */
2980Sstevel@tonic-gate 	uint_t			scsa2usb_tag;		/* current tag */
2990Sstevel@tonic-gate 	uint_t			scsa2usb_pkt_state;	/* packet state */
3000Sstevel@tonic-gate 	uint_t			scsa2usb_n_luns;	/* number of luns */
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	usb_log_handle_t	scsa2usb_log_handle;	/* log handle */
3030Sstevel@tonic-gate 	struct scsa2usb_cpr	*scsa2usb_panic_info;	/* for cpr info */
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	size_t			scsa2usb_lbasize[SCSA2USB_MAX_LUNS];
3060Sstevel@tonic-gate 							/* sector size */
3070Sstevel@tonic-gate 	size_t			scsa2usb_totalsec[SCSA2USB_MAX_LUNS];
3080Sstevel@tonic-gate 							/* total sectors */
3090Sstevel@tonic-gate 	size_t			scsa2usb_secsz[SCSA2USB_MAX_LUNS];
3100Sstevel@tonic-gate 							/* sector size */
3110Sstevel@tonic-gate 	size_t			scsa2usb_max_bulk_xfer_size; /* from HCD */
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate 	usb_client_dev_data_t	*scsa2usb_dev_data;	/* USB registration */
3140Sstevel@tonic-gate 	scsa2usb_last_cmd_t	scsa2usb_last_cmd;	/* last/prev command */
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate 	uint_t			scsa2usb_attrs;		/* for bad devices */
3170Sstevel@tonic-gate 	uint_t			scsa2usb_cmd_protocol;	/* CMD protocol used */
3180Sstevel@tonic-gate 	kthread_t		*scsa2usb_work_thread_id; /* handle commands */
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 				/* conf file override values */
3210Sstevel@tonic-gate 	uint_t			scsa2usb_subclass_override;
3220Sstevel@tonic-gate 	uint_t			scsa2usb_protocol_override;
3230Sstevel@tonic-gate 	char			*scsa2usb_override_str;
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 				/* suppress repetitive disconnect warnings */
3260Sstevel@tonic-gate 	boolean_t		scsa2usb_warning_given;
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 	boolean_t		scsa2usb_rcvd_not_ready; /* received NOT */
3290Sstevel@tonic-gate 							/* READY sense data */
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate 	usb_ugen_hdl_t		scsa2usb_ugen_hdl;	/* ugen support */
3320Sstevel@tonic-gate } scsa2usb_state_t;
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate /* for warlock */
3360Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsa2usb_state::scsa2usb_mutex, scsa2usb_state))
3370Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_instance))
3380Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dip))
3390Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_cmd))
3400Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_bp))
3410Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_ept))
3420Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_ept))
3430Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_ept))
3440Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_default_pipe))
3450Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_pipe))
3460Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_pipe))
3470Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_pipe))
3480Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_log_handle))
3490Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intfc_num))
3500Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dev_data))
3510Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_ugen_hdl))
352189Sfrits _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_pm))
3530Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa2usb_power_t))
3540Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_hba_tran_t))
3550Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", usb_bulk_req_t))
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate /* scsa2usb_pipe_state values */
3580Sstevel@tonic-gate #define	SCSA2USB_PIPE_NORMAL		0x00	/* no reset or clearing	*/
3590Sstevel@tonic-gate #define	SCSA2USB_PIPE_CLOSING		0x01	/* closing all pipes */
3600Sstevel@tonic-gate #define	SCSA2USB_PIPE_DEV_RESET		0x02	/* device specific reset */
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate /* pkt xfer state machine */
3630Sstevel@tonic-gate #define	SCSA2USB_PKT_NONE		0	/* device is idle */
3640Sstevel@tonic-gate #define	SCSA2USB_PKT_PROCESS_CSW	1	/* device doing status again */
3650Sstevel@tonic-gate #define	SCSA2USB_PKT_DO_COMP		2	/* device is done xfer */
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate /* scsa2usb_flags values */
3680Sstevel@tonic-gate #define	SCSA2USB_FLAGS_PIPES_OPENED	0x001	/* usb pipes are open */
3690Sstevel@tonic-gate #define	SCSA2USB_FLAGS_HBA_ATTACH_SETUP	0x002	/* scsi hba setup done */
3700Sstevel@tonic-gate #define	SCSA2USB_FLAGS_LOCKS_INIT	0x004	/* basic inits done */
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate /* scsa2usb_cmd_protocol values */
3730Sstevel@tonic-gate #define	SCSA2USB_UNKNOWN_PROTOCOL	0x0000	/* unknown wire protocol */
3740Sstevel@tonic-gate #define	SCSA2USB_CB_PROTOCOL		0x0001	/* CBI wire protocol */
3750Sstevel@tonic-gate #define	SCSA2USB_CBI_PROTOCOL		0x0002	/* CBI w/ intr wire protocol */
3760Sstevel@tonic-gate #define	SCSA2USB_BULK_ONLY_PROTOCOL	0x0004	/* Bulk Only wire protocol */
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate #define	SCSA2USB_SCSI_CMDSET		0x1000	/* SCSI command set followed */
3790Sstevel@tonic-gate #define	SCSA2USB_ATAPI_CMDSET		0x2000	/* ATAPI command set followed */
3800Sstevel@tonic-gate #define	SCSA2USB_UFI_CMDSET		0x4000	/* UFI command set followed */
3810Sstevel@tonic-gate #define	SCSA2USB_CMDSET_MASK		0x7000	/* OR al the above */
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate #define	SCSA2USB_IS_UFI_CMDSET(s) \
3840Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_UFI_CMDSET))
3850Sstevel@tonic-gate #define	SCSA2USB_IS_SCSI_CMDSET(s) \
3860Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_SCSI_CMDSET))
3870Sstevel@tonic-gate #define	SCSA2USB_IS_ATAPI_CMDSET(s) \
3880Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_ATAPI_CMDSET))
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate #define	SCSA2USB_IS_CB(s) \
3910Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_CB_PROTOCOL))
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate #define	SCSA2USB_IS_CBI(s) \
3940Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_CBI_PROTOCOL))
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate #define	SCSA2USB_IS_BULK_ONLY(s) \
3970Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_BULK_ONLY_PROTOCOL))
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate /* check if it is ok to access the device and send command to it */
4000Sstevel@tonic-gate #define	SCSA2USB_DEVICE_ACCESS_OK(s) \
4010Sstevel@tonic-gate 	((s)->scsa2usb_dev_state == USB_DEV_ONLINE)
4020Sstevel@tonic-gate 
4030Sstevel@tonic-gate /* check if we are in any reset */
4040Sstevel@tonic-gate #define	SCSA2USB_IN_RESET(s) \
4050Sstevel@tonic-gate 	(((s)->scsa2usb_pipe_state & SCSA2USB_PIPE_DEV_RESET) != 0)
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate /* check if the device is busy */
4080Sstevel@tonic-gate #define	SCSA2USB_BUSY(s) \
4090Sstevel@tonic-gate 	(((s)->scsa2usb_cur_pkt) || \
4100Sstevel@tonic-gate 	((s)->scsa2usb_pipe_state != SCSA2USB_PIPE_NORMAL) || \
4110Sstevel@tonic-gate 	((s)->scsa2usb_pkt_state != SCSA2USB_PKT_NONE))
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate /* check if we're doing cpr */
4140Sstevel@tonic-gate #define	SCSA2USB_CHK_CPR(s) \
4150Sstevel@tonic-gate 	(((s)->scsa2usb_dev_state == USB_DEV_SUSPENDED))
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate /* check if we're either paniced or in cpr state */
4180Sstevel@tonic-gate #define	SCSA2USB_CHK_PANIC_CPR(s) \
4190Sstevel@tonic-gate 	(ddi_in_panic() || SCSA2USB_CHK_CPR(s))
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate /* reset scsa2usb state after pkt_comp is called */
4220Sstevel@tonic-gate #define	SCSA2USB_RESET_CUR_PKT(s) \
4230Sstevel@tonic-gate 	(s)->scsa2usb_cur_pkt = NULL; \
4240Sstevel@tonic-gate 	(s)->scsa2usb_pkt_state = SCSA2USB_PKT_NONE;
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate /* print a panic sync message to the console */
4270Sstevel@tonic-gate #define	SCSA2USB_PRINT_SYNC_MSG(m, s) \
4280Sstevel@tonic-gate 	if ((m) == B_TRUE) { \
4293435Slg150142 		USB_DPRINTF_L1(DPRINT_MASK_SCSA, (s)->scsa2usb_log_handle, \
4300Sstevel@tonic-gate 		    "syncing not supported"); \
4310Sstevel@tonic-gate 		(m) = B_FALSE; \
4320Sstevel@tonic-gate 	}
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate /* Cancel callbacks registered during attach time */
4350Sstevel@tonic-gate #define	SCSA2USB_CANCEL_CB(id) \
4360Sstevel@tonic-gate 	if ((id)) { \
4370Sstevel@tonic-gate 		(void) callb_delete((id)); \
4380Sstevel@tonic-gate 		(id) = 0; \
4390Sstevel@tonic-gate 	}
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate /* Set SCSA2USB_PKT_DO_COMP state if there is active I/O */
4420Sstevel@tonic-gate #define	SCSA2USB_SET_PKT_DO_COMP_STATE(s) \
4430Sstevel@tonic-gate 	if ((s)->scsa2usb_cur_pkt) { \
4440Sstevel@tonic-gate 		(s)->scsa2usb_pkt_state = SCSA2USB_PKT_DO_COMP; \
4450Sstevel@tonic-gate 	}
4460Sstevel@tonic-gate 
4470Sstevel@tonic-gate #define	SCSA2USB_FREE_MSG(data) \
4480Sstevel@tonic-gate 	if ((data)) { \
4490Sstevel@tonic-gate 		freemsg((data)); \
4500Sstevel@tonic-gate 	}
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate #define	SCSA2USB_FREE_BULK_REQ(req) \
4530Sstevel@tonic-gate 	if ((req)) { \
4540Sstevel@tonic-gate 		usb_free_bulk_req((req));	/* Free request */ \
4550Sstevel@tonic-gate 	}
4560Sstevel@tonic-gate 
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate /* SCSA related */
4590Sstevel@tonic-gate #define	ADDR2TRAN(ap)		((ap)->a_hba_tran)
4600Sstevel@tonic-gate #define	TRAN2SCSA2USB(tran)	((scsa2usb_state_t *)(tran)->tran_hba_private)
4610Sstevel@tonic-gate #define	ADDR2SCSA2USB(ap)	(TRAN2SCSA2USB(ADDR2TRAN(ap)))
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate #define	PKT_PRIV_LEN		16
4640Sstevel@tonic-gate 
4652506Ssl147100 #define	PKT_DEFAULT_TIMEOUT	5
4662506Ssl147100 
4670Sstevel@tonic-gate /*
4680Sstevel@tonic-gate  * auto request sense
4690Sstevel@tonic-gate  */
4700Sstevel@tonic-gate #define	RQ_MAKECOM_COMMON(pktp, flag, cmd) \
4710Sstevel@tonic-gate 	(pktp)->pkt_flags = (flag), \
4720Sstevel@tonic-gate 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_cmd = (cmd), \
4730Sstevel@tonic-gate 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_lun = \
4740Sstevel@tonic-gate 	    (pktp)->pkt_address.a_lun
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate #define	RQ_MAKECOM_G0(pktp, flag, cmd, addr, cnt) \
4770Sstevel@tonic-gate 	RQ_MAKECOM_COMMON((pktp), (flag), (cmd)), \
4780Sstevel@tonic-gate 	FORMG0ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
4790Sstevel@tonic-gate 	FORMG0COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
4800Sstevel@tonic-gate 
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate /* transport related */
4830Sstevel@tonic-gate #define	SCSA2USB_JUST_ACCEPT	0
4840Sstevel@tonic-gate #define	SCSA2USB_TRANSPORT	1
4850Sstevel@tonic-gate #define	SCSA2USB_REJECT		-1
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate /*
4880Sstevel@tonic-gate  * The scsa2usb_cpr_info data structure is used for cpr related
4890Sstevel@tonic-gate  * callbacks. It is used for panic callbacks as well.
4900Sstevel@tonic-gate  */
4910Sstevel@tonic-gate typedef struct scsa2usb_cpr {
4920Sstevel@tonic-gate 	callb_cpr_t		cpr;		/* for cpr related info */
4930Sstevel@tonic-gate 	struct scsa2usb_state	*statep;	/* for scsa2usb state info */
4940Sstevel@tonic-gate 	kmutex_t		lockp;		/* mutex used by cpr_info_t */
4950Sstevel@tonic-gate } scsa2usb_cpr_t;
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::cpr))
4980Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::statep))
4990Sstevel@tonic-gate 
5000Sstevel@tonic-gate /*
5010Sstevel@tonic-gate  * The scsa2usb_cmd data structure is defined here. It gets
5020Sstevel@tonic-gate  * initialized per command that is sent to the device.
5030Sstevel@tonic-gate  */
5040Sstevel@tonic-gate typedef struct scsa2usb_cmd {
5050Sstevel@tonic-gate 	struct scsi_pkt		*cmd_pkt;		/* copy of pkt ptr */
5060Sstevel@tonic-gate 	struct	buf		*cmd_bp;		/* copy of bp ptr */
5070Sstevel@tonic-gate 	size_t			cmd_xfercount;		/* current xfer count */
5080Sstevel@tonic-gate 	size_t			cmd_resid_xfercount;	/* last xfer resid */
5090Sstevel@tonic-gate 	int			cmd_scblen;		/* status length */
5100Sstevel@tonic-gate 	int			cmd_tag;		/* tag */
5110Sstevel@tonic-gate 	int			cmd_timeout;		/* copy of pkt_time */
5120Sstevel@tonic-gate 	uchar_t			cmd_cdb[SCSI_CDB_SIZE];	/* CDB */
5130Sstevel@tonic-gate 	uchar_t			cmd_dir;		/* direction */
5140Sstevel@tonic-gate 	uchar_t			cmd_actual_len; 	/* cdb len */
5150Sstevel@tonic-gate 	uchar_t			cmd_cdblen;		/* requested  cdb len */
5160Sstevel@tonic-gate 	struct scsi_arq_status	cmd_scb;		/* status, w/ arq */
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate 	/* used in multiple xfers */
5190Sstevel@tonic-gate 	size_t			cmd_total_xfercount;	/* total xfer val */
5200Sstevel@tonic-gate 	size_t			cmd_offset;		/* offset into buf */
5210Sstevel@tonic-gate 	int			cmd_lba;		/* current xfer lba */
5220Sstevel@tonic-gate 	int			cmd_done;		/* command done? */
5230Sstevel@tonic-gate 	int			cmd_blksize;		/* block size */
5240Sstevel@tonic-gate 	usba_list_entry_t	cmd_waitQ;		/* waitQ element */
5250Sstevel@tonic-gate } scsa2usb_cmd_t;
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate /* for warlock */
5280Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per packet or safe sharing",
5290Sstevel@tonic-gate     scsi_cdb scsi_status scsi_pkt buf scsa2usb_cmd scsi_arq_status))
5300Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device scsi_address))
5310Sstevel@tonic-gate 
5320Sstevel@tonic-gate /* scsa2usb_cdb position of fields in CDB */
5330Sstevel@tonic-gate #define	SCSA2USB_OPCODE		0		/* Opcode field */
5340Sstevel@tonic-gate #define	SCSA2USB_LUN		1		/* LUN field */
5350Sstevel@tonic-gate #define	SCSA2USB_LBA_0		2		/* LBA[0] field */
5360Sstevel@tonic-gate #define	SCSA2USB_LBA_1		3		/* LBA[1] field */
5370Sstevel@tonic-gate #define	SCSA2USB_LBA_2		4		/* LBA[2] field */
5380Sstevel@tonic-gate #define	SCSA2USB_LBA_3		5		/* LBA[3] field */
5390Sstevel@tonic-gate #define	SCSA2USB_LEN_0		7		/* LEN[0] field */
5400Sstevel@tonic-gate #define	SCSA2USB_LEN_1		8		/* LEN[1] field */
5410Sstevel@tonic-gate 
5420Sstevel@tonic-gate /* macros to calculate LBA for 6/10/12-byte commands */
5430Sstevel@tonic-gate #define	SCSA2USB_LBA_6BYTE(pkt) \
5440Sstevel@tonic-gate 	(((pkt)->pkt_cdbp[1] & 0x1f) << 16) + \
5450Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 8) + (pkt)->pkt_cdbp[3]
5460Sstevel@tonic-gate #define	SCSA2USB_LEN_6BYTE(pkt)		(pkt)->pkt_cdbp[4]
5470Sstevel@tonic-gate 
5480Sstevel@tonic-gate #define	SCSA2USB_LEN_10BYTE(pkt) \
5490Sstevel@tonic-gate 	((pkt)->pkt_cdbp[7] << 8) + (pkt)->pkt_cdbp[8]
5500Sstevel@tonic-gate #define	SCSA2USB_LBA_10BYTE(pkt) \
5510Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
5520Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate #define	SCSA2USB_LEN_12BYTE(pkt) \
5550Sstevel@tonic-gate 	((pkt)->pkt_cdbp[6] << 24) + ((pkt)->pkt_cdbp[7] << 16) + \
5560Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[8] << 8) +  (pkt)->pkt_cdbp[9]
5570Sstevel@tonic-gate #define	SCSA2USB_LBA_12BYTE(pkt) \
5580Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
5590Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate /* macros to convert a pkt to cmd and vice-versa */
5620Sstevel@tonic-gate #define	PKT2CMD(pkt)		((scsa2usb_cmd_t *)(pkt)->pkt_ha_private)
5630Sstevel@tonic-gate #define	CMD2PKT(sp)		((sp)->cmd_pkt
5640Sstevel@tonic-gate 
5650Sstevel@tonic-gate /* bulk pipe default timeout value - how long the command to be tried? */
5660Sstevel@tonic-gate #define	SCSA2USB_BULK_PIPE_TIMEOUT	(2 * USB_PIPE_TIMEOUT)
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate /* drain timeout in seconds on the work thread */
5690Sstevel@tonic-gate #define	SCSA2USB_DRAIN_TIMEOUT		60
5700Sstevel@tonic-gate 
571918Sqz150045 /* scsa2usb pkt xfer status phase retry times */
572918Sqz150045 #define	SCSA2USB_STATUS_RETRIES		3
573918Sqz150045 
5740Sstevel@tonic-gate /*
5750Sstevel@tonic-gate  * limit on the number of requests that can be queued per LUN:
5760Sstevel@tonic-gate  * 3 for untagged queueing, 1 for scsiwatch and a margin of 2
5770Sstevel@tonic-gate  */
5780Sstevel@tonic-gate #define	SCSA2USB_MAX_REQ_PER_LUN	6
5790Sstevel@tonic-gate 
5800Sstevel@tonic-gate /*
5810Sstevel@tonic-gate  * The following data structure is used to save the values returned
5820Sstevel@tonic-gate  * by the READ_CAPACITY command. lba is the max allowed logical block
5830Sstevel@tonic-gate  * address and blen is max allowed block size.
5840Sstevel@tonic-gate  */
5850Sstevel@tonic-gate typedef struct scsa2usb_read_cap {
5860Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba3;		/* Max lba supported */
5870Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba2;
5880Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba1;
5890Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba0;
5900Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen3;	/* Max block size supported */
5910Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen2;
5920Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen1;
5930Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen0;
5940Sstevel@tonic-gate } scsa2usb_read_cap_t;
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate #define	SCSA2USB_MK_32BIT(a, b, c, d) \
5970Sstevel@tonic-gate 		(((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
5980Sstevel@tonic-gate 
5990Sstevel@tonic-gate /* position of fields for SCMD_READ_CD CDB */
6000Sstevel@tonic-gate #define	SCSA2USB_READ_CD_LEN_0	6	/* LEN[0] of SCMD_READ_CD */
6010Sstevel@tonic-gate #define	SCSA2USB_READ_CD_LEN_1	7	/* LEN[1] of SCMD_READ_CD */
6020Sstevel@tonic-gate #define	SCSA2USB_READ_CD_LEN_2	8	/* LEN[2] of SCMD_READ_CD */
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate /* macro to calculate LEN for SCMD_READ_CD command */
6050Sstevel@tonic-gate #define	SCSA2USB_LEN_READ_CD(pkt) \
6060Sstevel@tonic-gate 	(((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_0] << 16) +\
6070Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_1] << 8) +\
6080Sstevel@tonic-gate 	    (pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_2])
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate /* Figure out Block Size before issuing a WRITE to CD-RW device */
6110Sstevel@tonic-gate #define	SCSA2USB_CDRW_BLKSZ(bcount, len)	((bcount) / (len));
6120Sstevel@tonic-gate #define	SCSA2USB_VALID_CDRW_BLKSZ(blksz) \
6130Sstevel@tonic-gate 	(((blksz) == CDROM_BLK_2048) || ((blksz) == CDROM_BLK_2352) || \
6140Sstevel@tonic-gate 	((blksz) == CDROM_BLK_2336) || ((blksz) == CDROM_BLK_2324) || \
6150Sstevel@tonic-gate 	((blksz) == 0))
6160Sstevel@tonic-gate 
6170Sstevel@tonic-gate /* debug and error msg logging */
6180Sstevel@tonic-gate #define	DPRINT_MASK_SCSA	0x0001		/* for SCSA */
6190Sstevel@tonic-gate #define	DPRINT_MASK_ATTA	0x0002		/* for ATTA */
6200Sstevel@tonic-gate #define	DPRINT_MASK_EVENTS	0x0004		/* for event handling */
6210Sstevel@tonic-gate #define	DPRINT_MASK_CALLBACKS	0x0008		/* for callbacks  */
6220Sstevel@tonic-gate #define	DPRINT_MASK_TIMEOUT	0x0010		/* for timeouts */
6230Sstevel@tonic-gate #define	DPRINT_MASK_DUMPING	0x0020		/* for dumping */
6240Sstevel@tonic-gate #define	DPRINT_MASK_PM		0x0040		/* for pwr mgmt */
6250Sstevel@tonic-gate #define	DPRINT_MASK_ALL		0xffffffff	/* for everything */
6260Sstevel@tonic-gate 
6270Sstevel@tonic-gate #ifdef	DEBUG
6280Sstevel@tonic-gate #define	SCSA2USB_PRINT_CDB	scsa2usb_print_cdb
6290Sstevel@tonic-gate #else
6300Sstevel@tonic-gate #define	SCSA2USB_PRINT_CDB	0 &&
6310Sstevel@tonic-gate #endif
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate /* ugen support */
6340Sstevel@tonic-gate #define	SCSA2USB_MINOR_UGEN_BITS_MASK	0xff
6350Sstevel@tonic-gate #define	SCSA2USB_MINOR_INSTANCE_MASK	~SCSA2USB_MINOR_UGEN_BITS_MASK
6360Sstevel@tonic-gate #define	SCSA2USB_MINOR_INSTANCE_SHIFT	8
6370Sstevel@tonic-gate 
6380Sstevel@tonic-gate #define	SCSA2USB_MINOR_TO_INSTANCE(minor)	\
6390Sstevel@tonic-gate 		(((minor) & SCSA2USB_MINOR_INSTANCE_MASK) >> \
6400Sstevel@tonic-gate 		SCSA2USB_MINOR_INSTANCE_SHIFT)
6410Sstevel@tonic-gate 
6420Sstevel@tonic-gate #ifdef __cplusplus
6430Sstevel@tonic-gate }
6440Sstevel@tonic-gate #endif
6450Sstevel@tonic-gate 
6460Sstevel@tonic-gate #endif	/* _SYS_USB_SCSA2USB_H */
647