17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  *
227c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_USB_SCSA2USB_H
277c478bd9Sstevel@tonic-gate #define	_SYS_USB_SCSA2USB_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usbai_private.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * SCSA2USB: This header file contains the internal structures
397c478bd9Sstevel@tonic-gate  * and variable definitions used in USB mass storage disk driver.
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	SCSA2USB_INITIAL_ALLOC	4	/* initial soft space alloc */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	MAX_COMPAT_NAMES	1	/* max compatible names for children */
467c478bd9Sstevel@tonic-gate #define	SERIAL_NUM_LEN		64	/* for reading string descriptor */
477c478bd9Sstevel@tonic-gate #define	SCSA2USB_SERIAL_LEN	12	/* len of serial no in scsi_inquiry */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	SCSA2USB_MAX_LUNS	0x10	/* maximum luns supported. */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * limit the max transfer size to under <= 64K. Some devices
537c478bd9Sstevel@tonic-gate  * have problems with large transfers
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate #define	SCSA2USB_MAX_BULK_XFER_SIZE	(64 * 1024)
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /* Blacklist some vendors whose devices could cause problems */
587c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYS_COM_VID	0x693	/* VendorId of Hagiwara Sys-Com */
597c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID1	0x1	/* PID for SmartMedia(SM) device */
607c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID2	0x3	/* PID for CompactFlash(CF) device */
617c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID3	0x5	/* PID for SM/CF Combo device */
627c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID4	0x2	/* PID for new SM device */
637c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID5	0x4	/* PID for new CF device */
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_VID		0x59b	/* VendorId of Iomega */
667c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID1_ZIP100	0x1	/* PID of an Older Iomega Zip100 */
677c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID2_ZIP100	0x2	/* PID of Newer Iomega Zip100 */
687c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID3_ZIP100	0x31	/* PID of Newer Iomega Zip100 */
697c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID_ZIP250	0x30	/* PID of Newer Iomega Zip250 */
707c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID_CLIK	0x60	/* PID of Iomega Clik! drive */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #define	MS_MITSUMI_VID		0x3ee	/* VendorId of Mitsumi Inc */
737c478bd9Sstevel@tonic-gate #define	MS_MITSUMI_DEVICE_242	0x242	/* bcdDevice of Mitsumi CR-4804TU */
747c478bd9Sstevel@tonic-gate #define	MS_MITSUMI_DEVICE_24	0x24	/* bcdDevice of Mitsumi CR-4802TU */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	MS_YEDATA_VID		0x57b	/* VendorId of Y-E Data Corp */
777c478bd9Sstevel@tonic-gate #define	MS_SMSC_VID		0x424	/* Vendor Id of SMSC */
787c478bd9Sstevel@tonic-gate #define	MS_SMSC_PID0		0xfdc	/* floppy from SMSC */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #define	MS_NEODIO_VID		0xaec	/* Neodio Technologies Corporation */
817c478bd9Sstevel@tonic-gate #define	MS_NEODIO_DEVICE_3050	0x3050	/* PID of ND3050/Soyo BayOne */
827c478bd9Sstevel@tonic-gate 					/* SM/CF/MS/SD */
837c478bd9Sstevel@tonic-gate #define	MS_SONY_FLASH_VID	0x54c	/* sony flash device */
847c478bd9Sstevel@tonic-gate #define	MS_SONY_FLASH_PID	0x8b
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #define	MS_TREK_FLASH_VID	0xa16	/* Trek flash device */
877c478bd9Sstevel@tonic-gate #define	MS_TREK_FLASH_PID	0x9988
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #define	MS_PENN_FLASH_VID	0xd7d	/* Penn flash device */
907c478bd9Sstevel@tonic-gate #define	MS_PENN_FLASH_PID	0x1320
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #define	MS_SIMPLETECH_VID	0x7c4	/* VendorId of Simpltech */
937c478bd9Sstevel@tonic-gate #define	MS_SIMPLETECH_PID1	0xa400	/* PID for UCF-100 device */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	MS_ADDONICS_CARD_READER_VID 0x7cc /* addonics */
967c478bd9Sstevel@tonic-gate #define	MS_ADDONICS_CARD_READER_PID 0x320
977c478bd9Sstevel@tonic-gate 
98*2115f0c6Ssl #define	MS_NEWMAN_FLASH_VID	0x1043	/* Newman flash device */
99*2115f0c6Ssl #define	MS_NEWMAN_FLASH_PID	0x8006
100*2115f0c6Ssl 
101*2115f0c6Ssl #define	MS_ACOMDATA_VID		0xc0b	/* VendorId of DMI (Acomdata) */
102*2115f0c6Ssl #define	MS_ACOMDATA_PID1	0x5fab	/* PID for 80GB USB/1394 disk */
103*2115f0c6Ssl 
104*2115f0c6Ssl #define	MS_OTI_VID		0xea0	/* VendorID of OTI */
105*2115f0c6Ssl #define	MS_OTI_DEVICE_6828	0x6828	/* PID for 6828 flash disk */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * List the attributes that need special case in the driver
1097c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_GET_LUN: Bulk Only Transport Get_Max_Lun class specific
1107c478bd9Sstevel@tonic-gate  *		command is not implemented by these devices
1117c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_PM: Some devices don't like being power managed.
1127c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_START_STOP: Some devices don't do anything with
1137c478bd9Sstevel@tonic-gate  *		SCMD_START_STOP opcode (for e.g. SmartMedia/CompactFlash/
1147c478bd9Sstevel@tonic-gate  *		Clik!/MemoryStick/MMC USB readers/writers.
1157c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_GET_CONF: SCMD_GET_CONFIGURATION is not supported
1167c478bd9Sstevel@tonic-gate  * SCMD_TEST_UNIT_READY: for floppies this needs to be converted to
1177c478bd9Sstevel@tonic-gate  *		SCMD_START_STOP as floppies don't support this
1187c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_GET_PERF: SCMD_GET_PERFORMANCE not supported by
1197c478bd9Sstevel@tonic-gate  *		Mitsumi's CD-RW devices.
1207c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_BIG_TIMEOUT: Mitsumi's CD-RW devices need large
1217c478bd9Sstevel@tonic-gate  *		timeout with SCMD_START_STOP cmd
1227c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_RMB: Pay attention to the device's RMB setting,
1237c478bd9Sstevel@tonic-gate  *		instead of automatically treating it as removable
124*2115f0c6Ssl  * SCSA2USB_ATTRS_USE_CSW_RESIDUE: Some devices report false residue in
125*2115f0c6Ssl  *		the CSW of bulk-only transfer status stage though data
126*2115f0c6Ssl  *		was successfully transfered, so need to ignore residue.
1277c478bd9Sstevel@tonic-gate  *
1287c478bd9Sstevel@tonic-gate  * NOTE: If a device simply STALLs the GET_MAX_LUN BO class-specific command
1297c478bd9Sstevel@tonic-gate  * and recovers then it will not be added to the scsa2usb_blacklist[] table
1307c478bd9Sstevel@tonic-gate  * in scsa2usb.c. The other attributes will not be taken of the table unless
1317c478bd9Sstevel@tonic-gate  * their inclusion causes a recovery and retries (thus seriously affecting
1327c478bd9Sstevel@tonic-gate  * the driver performance).
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_GET_LUN		0x01	/* GET_MAX_LUN (Bulk Only) */
1357c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_PM		0x02	/* Some don't support PM */
1367c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_START_STOP	0x04	/* SCMD_START_STOP */
1377c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_GET_CONF		0x08	/* SCMD_GET_CONFIGURATION */
1387c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_GET_PERF		0x10	/* SCMD_GET_PERFORMANCE */
1397c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_BIG_TIMEOUT	0x40	/* for SCMD_START_STOP */
1407c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_DOORLOCK		0x80	/* for SCMD_DOORLOCK */
1417c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_RMB		0x100	/* Pay attention to RMB */
1427c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_MODE_SENSE	0x200	/* SCMD_MODE_SENSE */
1437c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_INQUIRY		0x400	/* SCMD_INQUIRY */
144*2115f0c6Ssl #define	SCSA2USB_ATTRS_USE_CSW_RESIDUE	0x800	/* for residue checking */
1457c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_REDUCED_CMD	\
1467c478bd9Sstevel@tonic-gate 	(SCSA2USB_ATTRS_DOORLOCK|SCSA2USB_ATTRS_MODE_SENSE| \
147*2115f0c6Ssl 	SCSA2USB_ATTRS_START_STOP|SCSA2USB_ATTRS_INQUIRY| \
148*2115f0c6Ssl 	SCSA2USB_ATTRS_USE_CSW_RESIDUE)
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #define	SCSA2USB_ALL_ATTRS		0xFFFF	/* All of the above */
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /* max inquiry length */
1537c478bd9Sstevel@tonic-gate #define	SCSA2USB_MAX_INQ_LEN (offsetof(struct scsi_inquiry, inq_serial))
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * PM support
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate typedef struct scsa2usb_power  {
1597c478bd9Sstevel@tonic-gate 	/* device busy accounting */
1607c478bd9Sstevel@tonic-gate 	int		scsa2usb_pm_busy;
1617c478bd9Sstevel@tonic-gate 	/* this is the bit mask of the power states that device has */
1627c478bd9Sstevel@tonic-gate 	uint8_t		scsa2usb_pwr_states;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	uint8_t		scsa2usb_wakeup_enabled;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/* current power level the device is in */
1677c478bd9Sstevel@tonic-gate 	uint8_t		scsa2usb_current_power;
1687c478bd9Sstevel@tonic-gate } scsa2usb_power_t;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * CPR support:
1727c478bd9Sstevel@tonic-gate  *	keep track of the last command issued to the drive. If it
1737c478bd9Sstevel@tonic-gate  *	was TUR or EJECT then allow issuing a CPR suspend.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate #define	LOEJECT	2		/* eject bit in start/stop cmd */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate typedef struct scsa2usb_last_cmd {
1787c478bd9Sstevel@tonic-gate 	/* this is the cdb of the last command issued */
1797c478bd9Sstevel@tonic-gate 	uchar_t		cdb[SCSI_CDB_SIZE];
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	/* this is the status of the last command issued */
1827c478bd9Sstevel@tonic-gate 	uint_t		status;
1837c478bd9Sstevel@tonic-gate } scsa2usb_last_cmd_t;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate  * override values
1877c478bd9Sstevel@tonic-gate  *	These values may be set in scsa2usb.conf for particular devices
1887c478bd9Sstevel@tonic-gate  */
1897c478bd9Sstevel@tonic-gate typedef struct scsa2usb_ov {
1907c478bd9Sstevel@tonic-gate 	int	vid;		/* vendor id */
1917c478bd9Sstevel@tonic-gate 	int	pid;		/* product id */
1927c478bd9Sstevel@tonic-gate 	int	rev;		/* revision */
1937c478bd9Sstevel@tonic-gate 	int	subclass;	/* subclass override */
1947c478bd9Sstevel@tonic-gate 	int	protocol;	/* protocol override */
1957c478bd9Sstevel@tonic-gate 	int	pmoff;		/* power management override */
1967c478bd9Sstevel@tonic-gate 	int	not_removable;	/* removable device override */
1977c478bd9Sstevel@tonic-gate 	int	no_modesense;	/* no mode sense */
1987c478bd9Sstevel@tonic-gate 				/* no modesense, doorlock, PM, start/stop */
1997c478bd9Sstevel@tonic-gate 	int	reduced_cmd_support;
2007c478bd9Sstevel@tonic-gate } scsa2usb_ov_t;
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate  * Per bulk device "state" data structure.
2057c478bd9Sstevel@tonic-gate  */
2067c478bd9Sstevel@tonic-gate typedef struct scsa2usb_state {
2077c478bd9Sstevel@tonic-gate 	int			scsa2usb_instance;	/* Instance number    */
2087c478bd9Sstevel@tonic-gate 	int			scsa2usb_dev_state;	/* USB device state   */
2097c478bd9Sstevel@tonic-gate 	int			scsa2usb_flags; 	/* Per instance flags */
2107c478bd9Sstevel@tonic-gate 	int			scsa2usb_intfc_num;	/* Interface number   */
2117c478bd9Sstevel@tonic-gate 	dev_info_t		*scsa2usb_dip;		/* Per device. info   */
2127c478bd9Sstevel@tonic-gate 	scsa2usb_power_t	*scsa2usb_pm;		/* PM state info */
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	int			scsa2usb_transport_busy; /* ugen/sd traffic */
2157c478bd9Sstevel@tonic-gate 	int			scsa2usb_ugen_open_count;
2167c478bd9Sstevel@tonic-gate 	kcondvar_t		scsa2usb_transport_busy_cv;
2177c478bd9Sstevel@tonic-gate 	kthread_t		*scsa2usb_busy_thread;
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	kmutex_t		scsa2usb_mutex;		/* Per instance lock  */
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	struct scsi_hba_tran	*scsa2usb_tran;		/* SCSI transport ptr */
2227c478bd9Sstevel@tonic-gate 	struct scsi_pkt		*scsa2usb_cur_pkt;	/* SCSI packet ptr    */
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	usba_list_entry_t	scsa2usb_waitQ[SCSA2USB_MAX_LUNS];
2257c478bd9Sstevel@tonic-gate 							/* waitQ list */
2267c478bd9Sstevel@tonic-gate 	struct scsa2usb_cmd	*scsa2usb_arq_cmd;	/* ARQ cmd */
2277c478bd9Sstevel@tonic-gate 	struct buf		*scsa2usb_arq_bp;	/* ARQ buf */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	dev_info_t		*scsa2usb_lun_dip[SCSA2USB_MAX_LUNS];
2307c478bd9Sstevel@tonic-gate 						/* store devinfo per LUN  */
2317c478bd9Sstevel@tonic-gate 	struct scsi_inquiry	scsa2usb_lun_inquiry[SCSA2USB_MAX_LUNS];
2327c478bd9Sstevel@tonic-gate 						/* store inquiry per LUN  */
2337c478bd9Sstevel@tonic-gate 	usb_if_descr_t		scsa2usb_intfc_descr;	/* Interface descr    */
2347c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		scsa2usb_bulkin_ept;	/* Bulk In descriptor */
2357c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		scsa2usb_bulkout_ept;	/* Bulkout descriptor */
2367c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		scsa2usb_intr_ept;	/* Intr ept descr */
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_default_pipe;	/* Default pipe	Hndle */
2397c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_intr_pipe;	/* Intr polling Hndle */
2407c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_bulkin_pipe;	/* Bulk Inpipe Handle */
2417c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_bulkout_pipe;	/* Bulk Outpipe Hndle */
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_pipe_state;	/* resetting state */
2447c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_tag;		/* current tag */
2457c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_pkt_state;	/* packet state */
2467c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_n_luns;	/* number of luns */
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	usb_log_handle_t	scsa2usb_log_handle;	/* log handle */
2497c478bd9Sstevel@tonic-gate 	struct scsa2usb_cpr	*scsa2usb_panic_info;	/* for cpr info */
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	size_t			scsa2usb_lbasize[SCSA2USB_MAX_LUNS];
2527c478bd9Sstevel@tonic-gate 							/* sector size */
2537c478bd9Sstevel@tonic-gate 	size_t			scsa2usb_totalsec[SCSA2USB_MAX_LUNS];
2547c478bd9Sstevel@tonic-gate 							/* total sectors */
2557c478bd9Sstevel@tonic-gate 	size_t			scsa2usb_secsz[SCSA2USB_MAX_LUNS];
2567c478bd9Sstevel@tonic-gate 							/* sector size */
2577c478bd9Sstevel@tonic-gate 	size_t			scsa2usb_max_bulk_xfer_size; /* from HCD */
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	usb_client_dev_data_t	*scsa2usb_dev_data;	/* USB registration */
2607c478bd9Sstevel@tonic-gate 	scsa2usb_last_cmd_t	scsa2usb_last_cmd;	/* last/prev command */
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_attrs;		/* for bad devices */
2637c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_cmd_protocol;	/* CMD protocol used */
2647c478bd9Sstevel@tonic-gate 	kthread_t		*scsa2usb_work_thread_id; /* handle commands */
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 				/* conf file override values */
2677c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_subclass_override;
2687c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_protocol_override;
2697c478bd9Sstevel@tonic-gate 	char			*scsa2usb_override_str;
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 				/* suppress repetitive disconnect warnings */
2727c478bd9Sstevel@tonic-gate 	boolean_t		scsa2usb_warning_given;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	boolean_t		scsa2usb_rcvd_not_ready; /* received NOT */
2757c478bd9Sstevel@tonic-gate 							/* READY sense data */
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	usb_ugen_hdl_t		scsa2usb_ugen_hdl;	/* ugen support */
2787c478bd9Sstevel@tonic-gate } scsa2usb_state_t;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate /* for warlock */
2827c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsa2usb_state::scsa2usb_mutex, scsa2usb_state))
2837c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_instance))
2847c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dip))
2857c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_cmd))
2867c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_bp))
2877c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_ept))
2887c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_ept))
2897c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_ept))
2907c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_default_pipe))
2917c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_pipe))
2927c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_pipe))
2937c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_pipe))
2947c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_log_handle))
2957c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intfc_num))
2967c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dev_data))
2977c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_ugen_hdl))
298496d8c83Sfrits _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_pm))
2997c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa2usb_power_t))
3007c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_hba_tran_t))
3017c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", usb_bulk_req_t))
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate /* scsa2usb_pipe_state values */
3047c478bd9Sstevel@tonic-gate #define	SCSA2USB_PIPE_NORMAL		0x00	/* no reset or clearing	*/
3057c478bd9Sstevel@tonic-gate #define	SCSA2USB_PIPE_CLOSING		0x01	/* closing all pipes */
3067c478bd9Sstevel@tonic-gate #define	SCSA2USB_PIPE_DEV_RESET		0x02	/* device specific reset */
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate /* pkt xfer state machine */
3097c478bd9Sstevel@tonic-gate #define	SCSA2USB_PKT_NONE		0	/* device is idle */
3107c478bd9Sstevel@tonic-gate #define	SCSA2USB_PKT_PROCESS_CSW	1	/* device doing status again */
3117c478bd9Sstevel@tonic-gate #define	SCSA2USB_PKT_DO_COMP		2	/* device is done xfer */
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /* scsa2usb_flags values */
3147c478bd9Sstevel@tonic-gate #define	SCSA2USB_FLAGS_PIPES_OPENED	0x001	/* usb pipes are open */
3157c478bd9Sstevel@tonic-gate #define	SCSA2USB_FLAGS_HBA_ATTACH_SETUP	0x002	/* scsi hba setup done */
3167c478bd9Sstevel@tonic-gate #define	SCSA2USB_FLAGS_LOCKS_INIT	0x004	/* basic inits done */
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate /* scsa2usb_cmd_protocol values */
3197c478bd9Sstevel@tonic-gate #define	SCSA2USB_UNKNOWN_PROTOCOL	0x0000	/* unknown wire protocol */
3207c478bd9Sstevel@tonic-gate #define	SCSA2USB_CB_PROTOCOL		0x0001	/* CBI wire protocol */
3217c478bd9Sstevel@tonic-gate #define	SCSA2USB_CBI_PROTOCOL		0x0002	/* CBI w/ intr wire protocol */
3227c478bd9Sstevel@tonic-gate #define	SCSA2USB_BULK_ONLY_PROTOCOL	0x0004	/* Bulk Only wire protocol */
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate #define	SCSA2USB_SCSI_CMDSET		0x1000	/* SCSI command set followed */
3257c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATAPI_CMDSET		0x2000	/* ATAPI command set followed */
3267c478bd9Sstevel@tonic-gate #define	SCSA2USB_UFI_CMDSET		0x4000	/* UFI command set followed */
3277c478bd9Sstevel@tonic-gate #define	SCSA2USB_CMDSET_MASK		0x7000	/* OR al the above */
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_UFI_CMDSET(s) \
3307c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_UFI_CMDSET))
3317c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_SCSI_CMDSET(s) \
3327c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_SCSI_CMDSET))
3337c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_ATAPI_CMDSET(s) \
3347c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_ATAPI_CMDSET))
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_CB(s) \
3377c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_CB_PROTOCOL))
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_CBI(s) \
3407c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_CBI_PROTOCOL))
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_BULK_ONLY(s) \
3437c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_BULK_ONLY_PROTOCOL))
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate /* check if it is ok to access the device and send command to it */
3467c478bd9Sstevel@tonic-gate #define	SCSA2USB_DEVICE_ACCESS_OK(s) \
3477c478bd9Sstevel@tonic-gate 	((s)->scsa2usb_dev_state == USB_DEV_ONLINE)
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate /* check if we are in any reset */
3507c478bd9Sstevel@tonic-gate #define	SCSA2USB_IN_RESET(s) \
3517c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_pipe_state & SCSA2USB_PIPE_DEV_RESET) != 0)
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate /* check if the device is busy */
3547c478bd9Sstevel@tonic-gate #define	SCSA2USB_BUSY(s) \
3557c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cur_pkt) || \
3567c478bd9Sstevel@tonic-gate 	((s)->scsa2usb_pipe_state != SCSA2USB_PIPE_NORMAL) || \
3577c478bd9Sstevel@tonic-gate 	((s)->scsa2usb_pkt_state != SCSA2USB_PKT_NONE))
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate /* check if we're doing cpr */
3607c478bd9Sstevel@tonic-gate #define	SCSA2USB_CHK_CPR(s) \
3617c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_dev_state == USB_DEV_SUSPENDED))
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate /* check if we're either paniced or in cpr state */
3647c478bd9Sstevel@tonic-gate #define	SCSA2USB_CHK_PANIC_CPR(s) \
3657c478bd9Sstevel@tonic-gate 	(ddi_in_panic() || SCSA2USB_CHK_CPR(s))
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate /* reset scsa2usb state after pkt_comp is called */
3687c478bd9Sstevel@tonic-gate #define	SCSA2USB_RESET_CUR_PKT(s) \
3697c478bd9Sstevel@tonic-gate 	(s)->scsa2usb_cur_pkt = NULL; \
3707c478bd9Sstevel@tonic-gate 	(s)->scsa2usb_pkt_state = SCSA2USB_PKT_NONE;
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate /* print a panic sync message to the console */
3737c478bd9Sstevel@tonic-gate #define	SCSA2USB_PRINT_SYNC_MSG(m, s) \
3747c478bd9Sstevel@tonic-gate 	if ((m) == B_TRUE) { \
3757c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L0(DPRINT_MASK_SCSA, (s)->scsa2usb_log_handle, \
3767c478bd9Sstevel@tonic-gate 		    "syncing not supported"); \
3777c478bd9Sstevel@tonic-gate 		(m) = B_FALSE; \
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate /* Cancel callbacks registered during attach time */
3817c478bd9Sstevel@tonic-gate #define	SCSA2USB_CANCEL_CB(id) \
3827c478bd9Sstevel@tonic-gate 	if ((id)) { \
3837c478bd9Sstevel@tonic-gate 		(void) callb_delete((id)); \
3847c478bd9Sstevel@tonic-gate 		(id) = 0; \
3857c478bd9Sstevel@tonic-gate 	}
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate /* Set SCSA2USB_PKT_DO_COMP state if there is active I/O */
3887c478bd9Sstevel@tonic-gate #define	SCSA2USB_SET_PKT_DO_COMP_STATE(s) \
3897c478bd9Sstevel@tonic-gate 	if ((s)->scsa2usb_cur_pkt) { \
3907c478bd9Sstevel@tonic-gate 		(s)->scsa2usb_pkt_state = SCSA2USB_PKT_DO_COMP; \
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate #define	SCSA2USB_FREE_MSG(data) \
3947c478bd9Sstevel@tonic-gate 	if ((data)) { \
3957c478bd9Sstevel@tonic-gate 		freemsg((data)); \
3967c478bd9Sstevel@tonic-gate 	}
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate #define	SCSA2USB_FREE_BULK_REQ(req) \
3997c478bd9Sstevel@tonic-gate 	if ((req)) { \
4007c478bd9Sstevel@tonic-gate 		usb_free_bulk_req((req));	/* Free request */ \
4017c478bd9Sstevel@tonic-gate 	}
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate /* SCSA related */
4057c478bd9Sstevel@tonic-gate #define	ADDR2TRAN(ap)		((ap)->a_hba_tran)
4067c478bd9Sstevel@tonic-gate #define	TRAN2SCSA2USB(tran)	((scsa2usb_state_t *)(tran)->tran_hba_private)
4077c478bd9Sstevel@tonic-gate #define	ADDR2SCSA2USB(ap)	(TRAN2SCSA2USB(ADDR2TRAN(ap)))
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate #define	PKT_PRIV_LEN		16
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate /*
4127c478bd9Sstevel@tonic-gate  * auto request sense
4137c478bd9Sstevel@tonic-gate  */
4147c478bd9Sstevel@tonic-gate #define	RQ_MAKECOM_COMMON(pktp, flag, cmd) \
4157c478bd9Sstevel@tonic-gate 	(pktp)->pkt_flags = (flag), \
4167c478bd9Sstevel@tonic-gate 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_cmd = (cmd), \
4177c478bd9Sstevel@tonic-gate 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_lun = \
4187c478bd9Sstevel@tonic-gate 	    (pktp)->pkt_address.a_lun
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate #define	RQ_MAKECOM_G0(pktp, flag, cmd, addr, cnt) \
4217c478bd9Sstevel@tonic-gate 	RQ_MAKECOM_COMMON((pktp), (flag), (cmd)), \
4227c478bd9Sstevel@tonic-gate 	FORMG0ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
4237c478bd9Sstevel@tonic-gate 	FORMG0COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate /* transport related */
4277c478bd9Sstevel@tonic-gate #define	SCSA2USB_JUST_ACCEPT	0
4287c478bd9Sstevel@tonic-gate #define	SCSA2USB_TRANSPORT	1
4297c478bd9Sstevel@tonic-gate #define	SCSA2USB_REJECT		-1
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate /*
4327c478bd9Sstevel@tonic-gate  * The scsa2usb_cpr_info data structure is used for cpr related
4337c478bd9Sstevel@tonic-gate  * callbacks. It is used for panic callbacks as well.
4347c478bd9Sstevel@tonic-gate  */
4357c478bd9Sstevel@tonic-gate typedef struct scsa2usb_cpr {
4367c478bd9Sstevel@tonic-gate 	callb_cpr_t		cpr;		/* for cpr related info */
4377c478bd9Sstevel@tonic-gate 	struct scsa2usb_state	*statep;	/* for scsa2usb state info */
4387c478bd9Sstevel@tonic-gate 	kmutex_t		lockp;		/* mutex used by cpr_info_t */
4397c478bd9Sstevel@tonic-gate } scsa2usb_cpr_t;
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::cpr))
4427c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::statep))
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate /*
4457c478bd9Sstevel@tonic-gate  * The scsa2usb_cmd data structure is defined here. It gets
4467c478bd9Sstevel@tonic-gate  * initialized per command that is sent to the device.
4477c478bd9Sstevel@tonic-gate  */
4487c478bd9Sstevel@tonic-gate typedef struct scsa2usb_cmd {
4497c478bd9Sstevel@tonic-gate 	struct scsi_pkt		*cmd_pkt;		/* copy of pkt ptr */
4507c478bd9Sstevel@tonic-gate 	struct	buf		*cmd_bp;		/* copy of bp ptr */
4517c478bd9Sstevel@tonic-gate 	size_t			cmd_xfercount;		/* current xfer count */
4527c478bd9Sstevel@tonic-gate 	size_t			cmd_resid_xfercount;	/* last xfer resid */
4537c478bd9Sstevel@tonic-gate 	int			cmd_scblen;		/* status length */
4547c478bd9Sstevel@tonic-gate 	int			cmd_tag;		/* tag */
4557c478bd9Sstevel@tonic-gate 	int			cmd_timeout;		/* copy of pkt_time */
4567c478bd9Sstevel@tonic-gate 	uchar_t			cmd_cdb[SCSI_CDB_SIZE];	/* CDB */
4577c478bd9Sstevel@tonic-gate 	uchar_t			cmd_dir;		/* direction */
4587c478bd9Sstevel@tonic-gate 	uchar_t			cmd_actual_len; 	/* cdb len */
4597c478bd9Sstevel@tonic-gate 	uchar_t			cmd_cdblen;		/* requested  cdb len */
4607c478bd9Sstevel@tonic-gate 	struct scsi_arq_status	cmd_scb;		/* status, w/ arq */
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	/* used in multiple xfers */
4637c478bd9Sstevel@tonic-gate 	size_t			cmd_total_xfercount;	/* total xfer val */
4647c478bd9Sstevel@tonic-gate 	size_t			cmd_offset;		/* offset into buf */
4657c478bd9Sstevel@tonic-gate 	int			cmd_lba;		/* current xfer lba */
4667c478bd9Sstevel@tonic-gate 	int			cmd_done;		/* command done? */
4677c478bd9Sstevel@tonic-gate 	int			cmd_blksize;		/* block size */
4687c478bd9Sstevel@tonic-gate 	usba_list_entry_t	cmd_waitQ;		/* waitQ element */
4697c478bd9Sstevel@tonic-gate } scsa2usb_cmd_t;
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate /* for warlock */
4727c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per packet or safe sharing",
4737c478bd9Sstevel@tonic-gate     scsi_cdb scsi_status scsi_pkt buf scsa2usb_cmd scsi_arq_status))
4747c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device scsi_address))
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate /* scsa2usb_cdb position of fields in CDB */
4777c478bd9Sstevel@tonic-gate #define	SCSA2USB_OPCODE		0		/* Opcode field */
4787c478bd9Sstevel@tonic-gate #define	SCSA2USB_LUN		1		/* LUN field */
4797c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_0		2		/* LBA[0] field */
4807c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_1		3		/* LBA[1] field */
4817c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_2		4		/* LBA[2] field */
4827c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_3		5		/* LBA[3] field */
4837c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_0		7		/* LEN[0] field */
4847c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_1		8		/* LEN[1] field */
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate /* macros to calculate LBA for 6/10/12-byte commands */
4877c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_6BYTE(pkt) \
4887c478bd9Sstevel@tonic-gate 	(((pkt)->pkt_cdbp[1] & 0x1f) << 16) + \
4897c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 8) + (pkt)->pkt_cdbp[3]
4907c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_6BYTE(pkt)		(pkt)->pkt_cdbp[4]
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_10BYTE(pkt) \
4937c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[7] << 8) + (pkt)->pkt_cdbp[8]
4947c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_10BYTE(pkt) \
4957c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
4967c478bd9Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_12BYTE(pkt) \
4997c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[6] << 24) + ((pkt)->pkt_cdbp[7] << 16) + \
5007c478bd9Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[8] << 8) +  (pkt)->pkt_cdbp[9]
5017c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_12BYTE(pkt) \
5027c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
5037c478bd9Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate /* macros to convert a pkt to cmd and vice-versa */
5067c478bd9Sstevel@tonic-gate #define	PKT2CMD(pkt)		((scsa2usb_cmd_t *)(pkt)->pkt_ha_private)
5077c478bd9Sstevel@tonic-gate #define	CMD2PKT(sp)		((sp)->cmd_pkt
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate /* bulk pipe default timeout value - how long the command to be tried? */
5107c478bd9Sstevel@tonic-gate #define	SCSA2USB_BULK_PIPE_TIMEOUT	(2 * USB_PIPE_TIMEOUT)
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate /* drain timeout in seconds on the work thread */
5137c478bd9Sstevel@tonic-gate #define	SCSA2USB_DRAIN_TIMEOUT		60
5147c478bd9Sstevel@tonic-gate 
5156d9a41ffSqz /* scsa2usb pkt xfer status phase retry times */
5166d9a41ffSqz #define	SCSA2USB_STATUS_RETRIES		3
5176d9a41ffSqz 
5187c478bd9Sstevel@tonic-gate /*
5197c478bd9Sstevel@tonic-gate  * limit on the number of requests that can be queued per LUN:
5207c478bd9Sstevel@tonic-gate  * 3 for untagged queueing, 1 for scsiwatch and a margin of 2
5217c478bd9Sstevel@tonic-gate  */
5227c478bd9Sstevel@tonic-gate #define	SCSA2USB_MAX_REQ_PER_LUN	6
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate /*
5257c478bd9Sstevel@tonic-gate  * The following data structure is used to save the values returned
5267c478bd9Sstevel@tonic-gate  * by the READ_CAPACITY command. lba is the max allowed logical block
5277c478bd9Sstevel@tonic-gate  * address and blen is max allowed block size.
5287c478bd9Sstevel@tonic-gate  */
5297c478bd9Sstevel@tonic-gate typedef struct scsa2usb_read_cap {
5307c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba3;		/* Max lba supported */
5317c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba2;
5327c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba1;
5337c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba0;
5347c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen3;	/* Max block size supported */
5357c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen2;
5367c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen1;
5377c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen0;
5387c478bd9Sstevel@tonic-gate } scsa2usb_read_cap_t;
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate #define	SCSA2USB_MK_32BIT(a, b, c, d) \
5417c478bd9Sstevel@tonic-gate 		(((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate /* position of fields for SCMD_READ_CD CDB */
5447c478bd9Sstevel@tonic-gate #define	SCSA2USB_READ_CD_LEN_0	6	/* LEN[0] of SCMD_READ_CD */
5457c478bd9Sstevel@tonic-gate #define	SCSA2USB_READ_CD_LEN_1	7	/* LEN[1] of SCMD_READ_CD */
5467c478bd9Sstevel@tonic-gate #define	SCSA2USB_READ_CD_LEN_2	8	/* LEN[2] of SCMD_READ_CD */
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate /* macro to calculate LEN for SCMD_READ_CD command */
5497c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_READ_CD(pkt) \
5507c478bd9Sstevel@tonic-gate 	(((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_0] << 16) +\
5517c478bd9Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_1] << 8) +\
5527c478bd9Sstevel@tonic-gate 	    (pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_2])
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate /* Figure out Block Size before issuing a WRITE to CD-RW device */
5557c478bd9Sstevel@tonic-gate #define	SCSA2USB_CDRW_BLKSZ(bcount, len)	((bcount) / (len));
5567c478bd9Sstevel@tonic-gate #define	SCSA2USB_VALID_CDRW_BLKSZ(blksz) \
5577c478bd9Sstevel@tonic-gate 	(((blksz) == CDROM_BLK_2048) || ((blksz) == CDROM_BLK_2352) || \
5587c478bd9Sstevel@tonic-gate 	((blksz) == CDROM_BLK_2336) || ((blksz) == CDROM_BLK_2324) || \
5597c478bd9Sstevel@tonic-gate 	((blksz) == 0))
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate /* debug and error msg logging */
5627c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_SCSA	0x0001		/* for SCSA */
5637c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_ATTA	0x0002		/* for ATTA */
5647c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_EVENTS	0x0004		/* for event handling */
5657c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_CALLBACKS	0x0008		/* for callbacks  */
5667c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_TIMEOUT	0x0010		/* for timeouts */
5677c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_DUMPING	0x0020		/* for dumping */
5687c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_PM		0x0040		/* for pwr mgmt */
5697c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_ALL		0xffffffff	/* for everything */
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate #ifdef	DEBUG
5727c478bd9Sstevel@tonic-gate #define	SCSA2USB_PRINT_CDB	scsa2usb_print_cdb
5737c478bd9Sstevel@tonic-gate #else
5747c478bd9Sstevel@tonic-gate #define	SCSA2USB_PRINT_CDB	0 &&
5757c478bd9Sstevel@tonic-gate #endif
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate /* ugen support */
5787c478bd9Sstevel@tonic-gate #define	SCSA2USB_MINOR_UGEN_BITS_MASK	0xff
5797c478bd9Sstevel@tonic-gate #define	SCSA2USB_MINOR_INSTANCE_MASK	~SCSA2USB_MINOR_UGEN_BITS_MASK
5807c478bd9Sstevel@tonic-gate #define	SCSA2USB_MINOR_INSTANCE_SHIFT	8
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate #define	SCSA2USB_MINOR_TO_INSTANCE(minor)	\
5837c478bd9Sstevel@tonic-gate 		(((minor) & SCSA2USB_MINOR_INSTANCE_MASK) >> \
5847c478bd9Sstevel@tonic-gate 		SCSA2USB_MINOR_INSTANCE_SHIFT)
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate #ifdef __cplusplus
5877c478bd9Sstevel@tonic-gate }
5887c478bd9Sstevel@tonic-gate #endif
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate #endif	/* _SYS_USB_SCSA2USB_H */
591