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
5910cba4fScg  * Common Development and Distribution License (the "License").
6910cba4fScg  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  *
21*5547f1d8SBinzi Cao - Sun Microsystems - Beijing China  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
227c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef _SYS_USB_SCSA2USB_H
267c478bd9Sstevel@tonic-gate #define	_SYS_USB_SCSA2USB_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usbai_private.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * SCSA2USB: This header file contains the internal structures
377c478bd9Sstevel@tonic-gate  * and variable definitions used in USB mass storage disk driver.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	SCSA2USB_INITIAL_ALLOC	4	/* initial soft space alloc */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	MAX_COMPAT_NAMES	1	/* max compatible names for children */
447c478bd9Sstevel@tonic-gate #define	SERIAL_NUM_LEN		64	/* for reading string descriptor */
457c478bd9Sstevel@tonic-gate #define	SCSA2USB_SERIAL_LEN	12	/* len of serial no in scsi_inquiry */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	SCSA2USB_MAX_LUNS	0x10	/* maximum luns supported. */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * limit the max transfer size to under <= 64K. Some devices
517c478bd9Sstevel@tonic-gate  * have problems with large transfers
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate #define	SCSA2USB_MAX_BULK_XFER_SIZE	(64 * 1024)
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /* Blacklist some vendors whose devices could cause problems */
567c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYS_COM_VID	0x693	/* VendorId of Hagiwara Sys-Com */
577c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID1	0x1	/* PID for SmartMedia(SM) device */
587c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID2	0x3	/* PID for CompactFlash(CF) device */
597c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID3	0x5	/* PID for SM/CF Combo device */
607c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID4	0x2	/* PID for new SM device */
617c478bd9Sstevel@tonic-gate #define	MS_HAGIWARA_SYSCOM_PID5	0x4	/* PID for new CF device */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_VID		0x59b	/* VendorId of Iomega */
647c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID1_ZIP100	0x1	/* PID of an Older Iomega Zip100 */
657c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID2_ZIP100	0x2	/* PID of Newer Iomega Zip100 */
667c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID3_ZIP100	0x31	/* PID of Newer Iomega Zip100 */
677c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID_ZIP250	0x30	/* PID of Newer Iomega Zip250 */
687c478bd9Sstevel@tonic-gate #define	MS_IOMEGA_PID_CLIK	0x60	/* PID of Iomega Clik! drive */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	MS_MITSUMI_VID		0x3ee	/* VendorId of Mitsumi Inc */
717c478bd9Sstevel@tonic-gate #define	MS_MITSUMI_DEVICE_242	0x242	/* bcdDevice of Mitsumi CR-4804TU */
727c478bd9Sstevel@tonic-gate #define	MS_MITSUMI_DEVICE_24	0x24	/* bcdDevice of Mitsumi CR-4802TU */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	MS_YEDATA_VID		0x57b	/* VendorId of Y-E Data Corp */
757c478bd9Sstevel@tonic-gate #define	MS_SMSC_VID		0x424	/* Vendor Id of SMSC */
767c478bd9Sstevel@tonic-gate #define	MS_SMSC_PID0		0xfdc	/* floppy from SMSC */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	MS_NEODIO_VID		0xaec	/* Neodio Technologies Corporation */
797c478bd9Sstevel@tonic-gate #define	MS_NEODIO_DEVICE_3050	0x3050	/* PID of ND3050/Soyo BayOne */
807c478bd9Sstevel@tonic-gate 					/* SM/CF/MS/SD */
817c478bd9Sstevel@tonic-gate #define	MS_SONY_FLASH_VID	0x54c	/* sony flash device */
827c478bd9Sstevel@tonic-gate #define	MS_SONY_FLASH_PID	0x8b
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #define	MS_TREK_FLASH_VID	0xa16	/* Trek flash device */
857c478bd9Sstevel@tonic-gate #define	MS_TREK_FLASH_PID	0x9988
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate #define	MS_PENN_FLASH_VID	0xd7d	/* Penn flash device */
887c478bd9Sstevel@tonic-gate #define	MS_PENN_FLASH_PID	0x1320
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	MS_SIMPLETECH_VID	0x7c4	/* VendorId of Simpltech */
917c478bd9Sstevel@tonic-gate #define	MS_SIMPLETECH_PID1	0xa400	/* PID for UCF-100 device */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	MS_ADDONICS_CARD_READER_VID 0x7cc /* addonics */
947c478bd9Sstevel@tonic-gate #define	MS_ADDONICS_CARD_READER_PID 0x320
957c478bd9Sstevel@tonic-gate 
962115f0c6Ssl #define	MS_ACOMDATA_VID		0xc0b	/* VendorId of DMI (Acomdata) */
972115f0c6Ssl #define	MS_ACOMDATA_PID1	0x5fab	/* PID for 80GB USB/1394 disk */
982115f0c6Ssl 
992115f0c6Ssl #define	MS_OTI_VID		0xea0	/* VendorID of OTI */
1002115f0c6Ssl #define	MS_OTI_DEVICE_6828	0x6828	/* PID for 6828 flash disk */
1017c478bd9Sstevel@tonic-gate 
10263602c90Sfb #define	MS_SCANLOGIC_VID	0x04ce	/* VendorID of ScanLogic */
10363602c90Sfb #define	MS_SCANLOGIC_PID1	0x0002	/* SL USB Storage Device */
10463602c90Sfb 
1053fbbb872Ssl #define	MS_SUPERTOP_VID		0x14cd	/* Super Top USB 2.0 IDE enclosure */
1063fbbb872Ssl #define	MS_SUPERTOP_DEVICE_6600	0x6600
1073fbbb872Ssl 
10867318e4aSlg #define	MS_AIGO_VID		0xed1	/* VendorID of Aigo */
10967318e4aSlg #define	MS_AIGO_DEVICE_6981	0x6981	/* Aigo Miniking Device NEHFSP14 */
11067318e4aSlg 
111f0e30896Sguoqing zhu - Sun Microsystems - Beijing China #define	MS_ALCOR_VID	0x58f	/* Vendor ID of Alcor Micro Corp */
112f0e30896Sguoqing zhu - Sun Microsystems - Beijing China #define	MS_ALCOR_PID0	0x6387	/* PID for 6387 flash disk */
113f0e30896Sguoqing zhu - Sun Microsystems - Beijing China 
114*5547f1d8SBinzi Cao - Sun Microsystems - Beijing China #define	MS_TOSHIBA_VID	0x930	/* Vendor ID of Toshiba Corp */
115*5547f1d8SBinzi Cao - Sun Microsystems - Beijing China #define	MS_TOSHIBA_PID0	0x6545	/* Kingston DataTraveler / PNY Attache Stick */
116*5547f1d8SBinzi Cao - Sun Microsystems - Beijing China 
117*5547f1d8SBinzi Cao - Sun Microsystems - Beijing China #define	MS_PNY_VID	0x154b	/* Vendor ID of PNY Corp */
118*5547f1d8SBinzi Cao - Sun Microsystems - Beijing China #define	MS_PNY_PID0	0x16	/* PNY floppy drive */
119*5547f1d8SBinzi Cao - Sun Microsystems - Beijing China 
120df4cb6e0Ssl /*
121df4cb6e0Ssl  * The AMI virtual floppy device is not a real USB storage device, but
122df4cb6e0Ssl  * emulated by the SP firmware shipped together with important Sun x86
123df4cb6e0Ssl  * products such as Galaxy and Thumper platforms. The device causes
124df4cb6e0Ssl  * very long delay in boot process of these platforms which is a big
125df4cb6e0Ssl  * performance issue. Improvement in firmware may solve the issue, but
126df4cb6e0Ssl  * before the firmware is fixed, it needs to be taken care of by software
127df4cb6e0Ssl  * to avoid the huge impact on user experience.
128df4cb6e0Ssl  *
129df4cb6e0Ssl  * The long boot delay is caused by timeouts and retries of READ CAPACITY
130df4cb6e0Ssl  * command issued to the device. The device is a USB ufi subclass device
131df4cb6e0Ssl  * using CBI protocol. When READ CAPACITY command is issued, the device
132df4cb6e0Ssl  * returns STALL on the bulk endpoint during the data stage, however, it
133df4cb6e0Ssl  * doesn't return status on the intr pipe during status stage, so the intr
134df4cb6e0Ssl  * pipe can only fail with timeout.
135df4cb6e0Ssl  *
136df4cb6e0Ssl  * Reducing timeout value to 1 second can help a little bit, but the delay
137df4cb6e0Ssl  * is still noticeable, because the target driver would make many retries
138df4cb6e0Ssl  * for this command. It is not desirable to mess with the target driver
139df4cb6e0Ssl  * for a broken USB device. So adding the device to the scsa2usb blacklist
140df4cb6e0Ssl  * is the best choice we have.
141df4cb6e0Ssl  *
142df4cb6e0Ssl  * It is found that the READ CAPACITY failure only happens when there is
143df4cb6e0Ssl  * no media in the floppy drive. When there is a media, the device works
144df4cb6e0Ssl  * just fine. So READ CAPACITY command cannot be arbitrarily disabled.
145df4cb6e0Ssl  * Media status needs to be checked before issuing the command by sending
146df4cb6e0Ssl  * an additional TEST UNIT READY command. If TEST UNIT READY command
147df4cb6e0Ssl  * return STATUS_GOOD, it means the media is ready and then READ CAPACITY
148df4cb6e0Ssl  * can be issued.
149df4cb6e0Ssl  *
150df4cb6e0Ssl  * SCSA2USB_ATTRS_NO_MEDIA_CHECK is added below for this purpose. It is
151df4cb6e0Ssl  * overrided in scsa2usb.c for the AMI virtual floppy device to take care
152df4cb6e0Ssl  * of the special need.
153df4cb6e0Ssl  */
154df4cb6e0Ssl #define	MS_AMI_VID		0x46b	/* VendorId of AMI */
155df4cb6e0Ssl #define	MS_AMI_VIRTUAL_FLOPPY	0xff40	/* PID for AMI virtual floppy */
156df4cb6e0Ssl 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * List the attributes that need special case in the driver
1597c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_GET_LUN: Bulk Only Transport Get_Max_Lun class specific
1607c478bd9Sstevel@tonic-gate  *		command is not implemented by these devices
1617c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_PM: Some devices don't like being power managed.
1627c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_START_STOP: Some devices don't do anything with
1637c478bd9Sstevel@tonic-gate  *		SCMD_START_STOP opcode (for e.g. SmartMedia/CompactFlash/
1647c478bd9Sstevel@tonic-gate  *		Clik!/MemoryStick/MMC USB readers/writers.
1657c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_GET_CONF: SCMD_GET_CONFIGURATION is not supported
1667c478bd9Sstevel@tonic-gate  * SCMD_TEST_UNIT_READY: for floppies this needs to be converted to
1677c478bd9Sstevel@tonic-gate  *		SCMD_START_STOP as floppies don't support this
1687c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_GET_PERF: SCMD_GET_PERFORMANCE not supported by
1697c478bd9Sstevel@tonic-gate  *		Mitsumi's CD-RW devices.
1707c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_BIG_TIMEOUT: Mitsumi's CD-RW devices need large
1717c478bd9Sstevel@tonic-gate  *		timeout with SCMD_START_STOP cmd
1727c478bd9Sstevel@tonic-gate  * SCSA2USB_ATTRS_RMB: Pay attention to the device's RMB setting,
1737c478bd9Sstevel@tonic-gate  *		instead of automatically treating it as removable
1742115f0c6Ssl  * SCSA2USB_ATTRS_USE_CSW_RESIDUE: Some devices report false residue in
1752115f0c6Ssl  *		the CSW of bulk-only transfer status stage though data
1762115f0c6Ssl  *		was successfully transfered, so need to ignore residue.
177df4cb6e0Ssl  * SCSA2USB_ATTRS_NO_MEDIA_CHECK: AMI Virtual Floppy devices need to
178df4cb6e0Ssl  *		check if media is ready before issuing READ CAPACITY.
17963602c90Sfb  * SCSA2USB_ATTRS_NO_CAP_ADJUST: Some devices return total logical block number
18063602c90Sfb  * 		instead of highest logical block address on READ_CAPACITY cmd.
1817c478bd9Sstevel@tonic-gate  *
1827c478bd9Sstevel@tonic-gate  * NOTE: If a device simply STALLs the GET_MAX_LUN BO class-specific command
1837c478bd9Sstevel@tonic-gate  * and recovers then it will not be added to the scsa2usb_blacklist[] table
1847c478bd9Sstevel@tonic-gate  * in scsa2usb.c. The other attributes will not be taken of the table unless
1857c478bd9Sstevel@tonic-gate  * their inclusion causes a recovery and retries (thus seriously affecting
1867c478bd9Sstevel@tonic-gate  * the driver performance).
1877c478bd9Sstevel@tonic-gate  */
1887c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_GET_LUN		0x01	/* GET_MAX_LUN (Bulk Only) */
1897c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_PM		0x02	/* Some don't support PM */
1907c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_START_STOP	0x04	/* SCMD_START_STOP */
1917c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_GET_CONF		0x08	/* SCMD_GET_CONFIGURATION */
1927c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_GET_PERF		0x10	/* SCMD_GET_PERFORMANCE */
1937c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_BIG_TIMEOUT	0x40	/* for SCMD_START_STOP */
1947c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_DOORLOCK		0x80	/* for SCMD_DOORLOCK */
1957c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_RMB		0x100	/* Pay attention to RMB */
1967c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_MODE_SENSE	0x200	/* SCMD_MODE_SENSE */
1977c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_INQUIRY		0x400	/* SCMD_INQUIRY */
1982115f0c6Ssl #define	SCSA2USB_ATTRS_USE_CSW_RESIDUE	0x800	/* for residue checking */
199df4cb6e0Ssl #define	SCSA2USB_ATTRS_NO_MEDIA_CHECK	0x1000	/* for media checking */
20063602c90Sfb #define	SCSA2USB_ATTRS_NO_CAP_ADJUST	0x2000	/* for CAPACITY adjusting */
2017c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATTRS_REDUCED_CMD	\
2027c478bd9Sstevel@tonic-gate 	(SCSA2USB_ATTRS_DOORLOCK|SCSA2USB_ATTRS_MODE_SENSE| \
2032115f0c6Ssl 	SCSA2USB_ATTRS_START_STOP|SCSA2USB_ATTRS_INQUIRY| \
2042115f0c6Ssl 	SCSA2USB_ATTRS_USE_CSW_RESIDUE)
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate #define	SCSA2USB_ALL_ATTRS		0xFFFF	/* All of the above */
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /* max inquiry length */
2097c478bd9Sstevel@tonic-gate #define	SCSA2USB_MAX_INQ_LEN (offsetof(struct scsi_inquiry, inq_serial))
2107c478bd9Sstevel@tonic-gate 
211910cba4fScg /* page code of scsi mode page */
212910cba4fScg #ifndef SD_MODE_SENSE_PAGE3_CODE
213910cba4fScg #define	SD_MODE_SENSE_PAGE3_CODE	0x03
214910cba4fScg #endif
215910cba4fScg 
216910cba4fScg #ifndef SD_MODE_SENSE_PAGE4_CODE
217910cba4fScg #define	SD_MODE_SENSE_PAGE4_CODE	0x04
218910cba4fScg #endif
219910cba4fScg 
2207c478bd9Sstevel@tonic-gate /*
2217c478bd9Sstevel@tonic-gate  * PM support
2227c478bd9Sstevel@tonic-gate  */
2237c478bd9Sstevel@tonic-gate typedef struct scsa2usb_power  {
2247c478bd9Sstevel@tonic-gate 	/* device busy accounting */
2257c478bd9Sstevel@tonic-gate 	int		scsa2usb_pm_busy;
2267c478bd9Sstevel@tonic-gate 	/* this is the bit mask of the power states that device has */
2277c478bd9Sstevel@tonic-gate 	uint8_t		scsa2usb_pwr_states;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	uint8_t		scsa2usb_wakeup_enabled;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	/* current power level the device is in */
2327c478bd9Sstevel@tonic-gate 	uint8_t		scsa2usb_current_power;
2337c478bd9Sstevel@tonic-gate } scsa2usb_power_t;
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  * CPR support:
2377c478bd9Sstevel@tonic-gate  *	keep track of the last command issued to the drive. If it
2387c478bd9Sstevel@tonic-gate  *	was TUR or EJECT then allow issuing a CPR suspend.
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate #define	LOEJECT	2		/* eject bit in start/stop cmd */
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate typedef struct scsa2usb_last_cmd {
2437c478bd9Sstevel@tonic-gate 	/* this is the cdb of the last command issued */
2447c478bd9Sstevel@tonic-gate 	uchar_t		cdb[SCSI_CDB_SIZE];
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 	/* this is the status of the last command issued */
2477c478bd9Sstevel@tonic-gate 	uint_t		status;
2487c478bd9Sstevel@tonic-gate } scsa2usb_last_cmd_t;
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate /*
2517c478bd9Sstevel@tonic-gate  * override values
2527c478bd9Sstevel@tonic-gate  *	These values may be set in scsa2usb.conf for particular devices
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate typedef struct scsa2usb_ov {
2557c478bd9Sstevel@tonic-gate 	int	vid;		/* vendor id */
2567c478bd9Sstevel@tonic-gate 	int	pid;		/* product id */
2577c478bd9Sstevel@tonic-gate 	int	rev;		/* revision */
2587c478bd9Sstevel@tonic-gate 	int	subclass;	/* subclass override */
2597c478bd9Sstevel@tonic-gate 	int	protocol;	/* protocol override */
2607c478bd9Sstevel@tonic-gate 	int	pmoff;		/* power management override */
2610167b58cScg 	int	fake_removable;	/* removable device override */
2627c478bd9Sstevel@tonic-gate 	int	no_modesense;	/* no mode sense */
2637c478bd9Sstevel@tonic-gate 				/* no modesense, doorlock, PM, start/stop */
2647c478bd9Sstevel@tonic-gate 	int	reduced_cmd_support;
2657c478bd9Sstevel@tonic-gate } scsa2usb_ov_t;
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate  * Per bulk device "state" data structure.
2707c478bd9Sstevel@tonic-gate  */
2717c478bd9Sstevel@tonic-gate typedef struct scsa2usb_state {
2727c478bd9Sstevel@tonic-gate 	int			scsa2usb_instance;	/* Instance number    */
2737c478bd9Sstevel@tonic-gate 	int			scsa2usb_dev_state;	/* USB device state   */
2747c478bd9Sstevel@tonic-gate 	int			scsa2usb_flags; 	/* Per instance flags */
2757c478bd9Sstevel@tonic-gate 	int			scsa2usb_intfc_num;	/* Interface number   */
2767c478bd9Sstevel@tonic-gate 	dev_info_t		*scsa2usb_dip;		/* Per device. info   */
2777c478bd9Sstevel@tonic-gate 	scsa2usb_power_t	*scsa2usb_pm;		/* PM state info */
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	int			scsa2usb_transport_busy; /* ugen/sd traffic */
2807c478bd9Sstevel@tonic-gate 	int			scsa2usb_ugen_open_count;
2817c478bd9Sstevel@tonic-gate 	kcondvar_t		scsa2usb_transport_busy_cv;
2827c478bd9Sstevel@tonic-gate 	kthread_t		*scsa2usb_busy_thread;
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	kmutex_t		scsa2usb_mutex;		/* Per instance lock  */
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	struct scsi_hba_tran	*scsa2usb_tran;		/* SCSI transport ptr */
2877c478bd9Sstevel@tonic-gate 	struct scsi_pkt		*scsa2usb_cur_pkt;	/* SCSI packet ptr    */
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	usba_list_entry_t	scsa2usb_waitQ[SCSA2USB_MAX_LUNS];
2907c478bd9Sstevel@tonic-gate 							/* waitQ list */
2917c478bd9Sstevel@tonic-gate 	struct scsa2usb_cmd	*scsa2usb_arq_cmd;	/* ARQ cmd */
2927c478bd9Sstevel@tonic-gate 	struct buf		*scsa2usb_arq_bp;	/* ARQ buf */
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	dev_info_t		*scsa2usb_lun_dip[SCSA2USB_MAX_LUNS];
2957c478bd9Sstevel@tonic-gate 						/* store devinfo per LUN  */
2967c478bd9Sstevel@tonic-gate 	struct scsi_inquiry	scsa2usb_lun_inquiry[SCSA2USB_MAX_LUNS];
2977c478bd9Sstevel@tonic-gate 						/* store inquiry per LUN  */
2987c478bd9Sstevel@tonic-gate 	usb_if_descr_t		scsa2usb_intfc_descr;	/* Interface descr    */
2997c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		scsa2usb_bulkin_ept;	/* Bulk In descriptor */
3007c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		scsa2usb_bulkout_ept;	/* Bulkout descriptor */
3017c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		scsa2usb_intr_ept;	/* Intr ept descr */
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_default_pipe;	/* Default pipe	Hndle */
3047c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_intr_pipe;	/* Intr polling Hndle */
3057c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_bulkin_pipe;	/* Bulk Inpipe Handle */
3067c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	scsa2usb_bulkout_pipe;	/* Bulk Outpipe Hndle */
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_pipe_state;	/* resetting state */
3097c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_tag;		/* current tag */
3107c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_pkt_state;	/* packet state */
3117c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_n_luns;	/* number of luns */
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	usb_log_handle_t	scsa2usb_log_handle;	/* log handle */
3147c478bd9Sstevel@tonic-gate 	struct scsa2usb_cpr	*scsa2usb_panic_info;	/* for cpr info */
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	size_t			scsa2usb_lbasize[SCSA2USB_MAX_LUNS];
3177c478bd9Sstevel@tonic-gate 							/* sector size */
3187c478bd9Sstevel@tonic-gate 	size_t			scsa2usb_totalsec[SCSA2USB_MAX_LUNS];
3197c478bd9Sstevel@tonic-gate 							/* total sectors */
3207c478bd9Sstevel@tonic-gate 	size_t			scsa2usb_secsz[SCSA2USB_MAX_LUNS];
3217c478bd9Sstevel@tonic-gate 							/* sector size */
3227c478bd9Sstevel@tonic-gate 	size_t			scsa2usb_max_bulk_xfer_size; /* from HCD */
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	usb_client_dev_data_t	*scsa2usb_dev_data;	/* USB registration */
3257c478bd9Sstevel@tonic-gate 	scsa2usb_last_cmd_t	scsa2usb_last_cmd;	/* last/prev command */
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_attrs;		/* for bad devices */
3287c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_cmd_protocol;	/* CMD protocol used */
3297c478bd9Sstevel@tonic-gate 	kthread_t		*scsa2usb_work_thread_id; /* handle commands */
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 				/* conf file override values */
3327c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_subclass_override;
3337c478bd9Sstevel@tonic-gate 	uint_t			scsa2usb_protocol_override;
3347c478bd9Sstevel@tonic-gate 	char			*scsa2usb_override_str;
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 				/* suppress repetitive disconnect warnings */
3377c478bd9Sstevel@tonic-gate 	boolean_t		scsa2usb_warning_given;
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	boolean_t		scsa2usb_rcvd_not_ready; /* received NOT */
3407c478bd9Sstevel@tonic-gate 							/* READY sense data */
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	usb_ugen_hdl_t		scsa2usb_ugen_hdl;	/* ugen support */
3437c478bd9Sstevel@tonic-gate } scsa2usb_state_t;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate /* for warlock */
3477c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsa2usb_state::scsa2usb_mutex, scsa2usb_state))
3487c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_instance))
3497c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dip))
3507c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_cmd))
3517c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_bp))
3527c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_ept))
3537c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_ept))
3547c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_ept))
3557c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_default_pipe))
3567c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_pipe))
3577c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_pipe))
3587c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_pipe))
3597c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_log_handle))
3607c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intfc_num))
3617c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dev_data))
3627c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_ugen_hdl))
363496d8c83Sfrits _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_pm))
3647c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa2usb_power_t))
3657c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_hba_tran_t))
3667c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", usb_bulk_req_t))
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate /* scsa2usb_pipe_state values */
3697c478bd9Sstevel@tonic-gate #define	SCSA2USB_PIPE_NORMAL		0x00	/* no reset or clearing	*/
3707c478bd9Sstevel@tonic-gate #define	SCSA2USB_PIPE_CLOSING		0x01	/* closing all pipes */
3717c478bd9Sstevel@tonic-gate #define	SCSA2USB_PIPE_DEV_RESET		0x02	/* device specific reset */
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate /* pkt xfer state machine */
3747c478bd9Sstevel@tonic-gate #define	SCSA2USB_PKT_NONE		0	/* device is idle */
3757c478bd9Sstevel@tonic-gate #define	SCSA2USB_PKT_PROCESS_CSW	1	/* device doing status again */
3767c478bd9Sstevel@tonic-gate #define	SCSA2USB_PKT_DO_COMP		2	/* device is done xfer */
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate /* scsa2usb_flags values */
3797c478bd9Sstevel@tonic-gate #define	SCSA2USB_FLAGS_PIPES_OPENED	0x001	/* usb pipes are open */
3807c478bd9Sstevel@tonic-gate #define	SCSA2USB_FLAGS_HBA_ATTACH_SETUP	0x002	/* scsi hba setup done */
3817c478bd9Sstevel@tonic-gate #define	SCSA2USB_FLAGS_LOCKS_INIT	0x004	/* basic inits done */
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate /* scsa2usb_cmd_protocol values */
3847c478bd9Sstevel@tonic-gate #define	SCSA2USB_UNKNOWN_PROTOCOL	0x0000	/* unknown wire protocol */
3857c478bd9Sstevel@tonic-gate #define	SCSA2USB_CB_PROTOCOL		0x0001	/* CBI wire protocol */
3867c478bd9Sstevel@tonic-gate #define	SCSA2USB_CBI_PROTOCOL		0x0002	/* CBI w/ intr wire protocol */
3877c478bd9Sstevel@tonic-gate #define	SCSA2USB_BULK_ONLY_PROTOCOL	0x0004	/* Bulk Only wire protocol */
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate #define	SCSA2USB_SCSI_CMDSET		0x1000	/* SCSI command set followed */
3907c478bd9Sstevel@tonic-gate #define	SCSA2USB_ATAPI_CMDSET		0x2000	/* ATAPI command set followed */
3917c478bd9Sstevel@tonic-gate #define	SCSA2USB_UFI_CMDSET		0x4000	/* UFI command set followed */
3927c478bd9Sstevel@tonic-gate #define	SCSA2USB_CMDSET_MASK		0x7000	/* OR al the above */
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_UFI_CMDSET(s) \
3957c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_UFI_CMDSET))
3967c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_SCSI_CMDSET(s) \
3977c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_SCSI_CMDSET))
3987c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_ATAPI_CMDSET(s) \
3997c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_ATAPI_CMDSET))
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_CB(s) \
4027c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_CB_PROTOCOL))
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_CBI(s) \
4057c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_CBI_PROTOCOL))
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate #define	SCSA2USB_IS_BULK_ONLY(s) \
4087c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cmd_protocol & SCSA2USB_BULK_ONLY_PROTOCOL))
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate /* check if it is ok to access the device and send command to it */
4117c478bd9Sstevel@tonic-gate #define	SCSA2USB_DEVICE_ACCESS_OK(s) \
4127c478bd9Sstevel@tonic-gate 	((s)->scsa2usb_dev_state == USB_DEV_ONLINE)
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate /* check if we are in any reset */
4157c478bd9Sstevel@tonic-gate #define	SCSA2USB_IN_RESET(s) \
4167c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_pipe_state & SCSA2USB_PIPE_DEV_RESET) != 0)
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate /* check if the device is busy */
4197c478bd9Sstevel@tonic-gate #define	SCSA2USB_BUSY(s) \
4207c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_cur_pkt) || \
4217c478bd9Sstevel@tonic-gate 	((s)->scsa2usb_pipe_state != SCSA2USB_PIPE_NORMAL) || \
4227c478bd9Sstevel@tonic-gate 	((s)->scsa2usb_pkt_state != SCSA2USB_PKT_NONE))
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate /* check if we're doing cpr */
4257c478bd9Sstevel@tonic-gate #define	SCSA2USB_CHK_CPR(s) \
4267c478bd9Sstevel@tonic-gate 	(((s)->scsa2usb_dev_state == USB_DEV_SUSPENDED))
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate /* check if we're either paniced or in cpr state */
4297c478bd9Sstevel@tonic-gate #define	SCSA2USB_CHK_PANIC_CPR(s) \
4307c478bd9Sstevel@tonic-gate 	(ddi_in_panic() || SCSA2USB_CHK_CPR(s))
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /* reset scsa2usb state after pkt_comp is called */
4337c478bd9Sstevel@tonic-gate #define	SCSA2USB_RESET_CUR_PKT(s) \
4347c478bd9Sstevel@tonic-gate 	(s)->scsa2usb_cur_pkt = NULL; \
4357c478bd9Sstevel@tonic-gate 	(s)->scsa2usb_pkt_state = SCSA2USB_PKT_NONE;
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate /* print a panic sync message to the console */
4387c478bd9Sstevel@tonic-gate #define	SCSA2USB_PRINT_SYNC_MSG(m, s) \
4397c478bd9Sstevel@tonic-gate 	if ((m) == B_TRUE) { \
4408668df41Slg 		USB_DPRINTF_L1(DPRINT_MASK_SCSA, (s)->scsa2usb_log_handle, \
4417c478bd9Sstevel@tonic-gate 		    "syncing not supported"); \
4427c478bd9Sstevel@tonic-gate 		(m) = B_FALSE; \
4437c478bd9Sstevel@tonic-gate 	}
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate /* Cancel callbacks registered during attach time */
4467c478bd9Sstevel@tonic-gate #define	SCSA2USB_CANCEL_CB(id) \
4477c478bd9Sstevel@tonic-gate 	if ((id)) { \
4487c478bd9Sstevel@tonic-gate 		(void) callb_delete((id)); \
4497c478bd9Sstevel@tonic-gate 		(id) = 0; \
4507c478bd9Sstevel@tonic-gate 	}
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate /* Set SCSA2USB_PKT_DO_COMP state if there is active I/O */
4537c478bd9Sstevel@tonic-gate #define	SCSA2USB_SET_PKT_DO_COMP_STATE(s) \
4547c478bd9Sstevel@tonic-gate 	if ((s)->scsa2usb_cur_pkt) { \
4557c478bd9Sstevel@tonic-gate 		(s)->scsa2usb_pkt_state = SCSA2USB_PKT_DO_COMP; \
4567c478bd9Sstevel@tonic-gate 	}
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate #define	SCSA2USB_FREE_MSG(data) \
4597c478bd9Sstevel@tonic-gate 	if ((data)) { \
4607c478bd9Sstevel@tonic-gate 		freemsg((data)); \
4617c478bd9Sstevel@tonic-gate 	}
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate #define	SCSA2USB_FREE_BULK_REQ(req) \
4647c478bd9Sstevel@tonic-gate 	if ((req)) { \
4657c478bd9Sstevel@tonic-gate 		usb_free_bulk_req((req));	/* Free request */ \
4667c478bd9Sstevel@tonic-gate 	}
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate /* SCSA related */
4707c478bd9Sstevel@tonic-gate #define	ADDR2TRAN(ap)		((ap)->a_hba_tran)
4717c478bd9Sstevel@tonic-gate #define	TRAN2SCSA2USB(tran)	((scsa2usb_state_t *)(tran)->tran_hba_private)
4727c478bd9Sstevel@tonic-gate #define	ADDR2SCSA2USB(ap)	(TRAN2SCSA2USB(ADDR2TRAN(ap)))
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate #define	PKT_PRIV_LEN		16
4757c478bd9Sstevel@tonic-gate 
476df4cb6e0Ssl #define	PKT_DEFAULT_TIMEOUT	5
477df4cb6e0Ssl 
4787c478bd9Sstevel@tonic-gate /*
4797c478bd9Sstevel@tonic-gate  * auto request sense
4807c478bd9Sstevel@tonic-gate  */
4817c478bd9Sstevel@tonic-gate #define	RQ_MAKECOM_COMMON(pktp, flag, cmd) \
4827c478bd9Sstevel@tonic-gate 	(pktp)->pkt_flags = (flag), \
4837c478bd9Sstevel@tonic-gate 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_cmd = (cmd), \
4847c478bd9Sstevel@tonic-gate 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_lun = \
4857c478bd9Sstevel@tonic-gate 	    (pktp)->pkt_address.a_lun
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate #define	RQ_MAKECOM_G0(pktp, flag, cmd, addr, cnt) \
4887c478bd9Sstevel@tonic-gate 	RQ_MAKECOM_COMMON((pktp), (flag), (cmd)), \
4897c478bd9Sstevel@tonic-gate 	FORMG0ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
4907c478bd9Sstevel@tonic-gate 	FORMG0COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate /* transport related */
4947c478bd9Sstevel@tonic-gate #define	SCSA2USB_JUST_ACCEPT	0
4957c478bd9Sstevel@tonic-gate #define	SCSA2USB_TRANSPORT	1
4967c478bd9Sstevel@tonic-gate #define	SCSA2USB_REJECT		-1
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate /*
4997c478bd9Sstevel@tonic-gate  * The scsa2usb_cpr_info data structure is used for cpr related
5007c478bd9Sstevel@tonic-gate  * callbacks. It is used for panic callbacks as well.
5017c478bd9Sstevel@tonic-gate  */
5027c478bd9Sstevel@tonic-gate typedef struct scsa2usb_cpr {
5037c478bd9Sstevel@tonic-gate 	callb_cpr_t		cpr;		/* for cpr related info */
5047c478bd9Sstevel@tonic-gate 	struct scsa2usb_state	*statep;	/* for scsa2usb state info */
5057c478bd9Sstevel@tonic-gate 	kmutex_t		lockp;		/* mutex used by cpr_info_t */
5067c478bd9Sstevel@tonic-gate } scsa2usb_cpr_t;
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::cpr))
5097c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::statep))
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate /*
5127c478bd9Sstevel@tonic-gate  * The scsa2usb_cmd data structure is defined here. It gets
5137c478bd9Sstevel@tonic-gate  * initialized per command that is sent to the device.
5147c478bd9Sstevel@tonic-gate  */
5157c478bd9Sstevel@tonic-gate typedef struct scsa2usb_cmd {
5167c478bd9Sstevel@tonic-gate 	struct scsi_pkt		*cmd_pkt;		/* copy of pkt ptr */
5177c478bd9Sstevel@tonic-gate 	struct	buf		*cmd_bp;		/* copy of bp ptr */
5187c478bd9Sstevel@tonic-gate 	size_t			cmd_xfercount;		/* current xfer count */
5197c478bd9Sstevel@tonic-gate 	size_t			cmd_resid_xfercount;	/* last xfer resid */
5207c478bd9Sstevel@tonic-gate 	int			cmd_scblen;		/* status length */
5217c478bd9Sstevel@tonic-gate 	int			cmd_tag;		/* tag */
5227c478bd9Sstevel@tonic-gate 	int			cmd_timeout;		/* copy of pkt_time */
5237c478bd9Sstevel@tonic-gate 	uchar_t			cmd_cdb[SCSI_CDB_SIZE];	/* CDB */
5247c478bd9Sstevel@tonic-gate 	uchar_t			cmd_dir;		/* direction */
5257c478bd9Sstevel@tonic-gate 	uchar_t			cmd_actual_len; 	/* cdb len */
5267c478bd9Sstevel@tonic-gate 	uchar_t			cmd_cdblen;		/* requested  cdb len */
5277c478bd9Sstevel@tonic-gate 	struct scsi_arq_status	cmd_scb;		/* status, w/ arq */
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	/* used in multiple xfers */
5307c478bd9Sstevel@tonic-gate 	size_t			cmd_total_xfercount;	/* total xfer val */
5317c478bd9Sstevel@tonic-gate 	size_t			cmd_offset;		/* offset into buf */
5327c478bd9Sstevel@tonic-gate 	int			cmd_lba;		/* current xfer lba */
5337c478bd9Sstevel@tonic-gate 	int			cmd_done;		/* command done? */
5347c478bd9Sstevel@tonic-gate 	int			cmd_blksize;		/* block size */
5357c478bd9Sstevel@tonic-gate 	usba_list_entry_t	cmd_waitQ;		/* waitQ element */
5367c478bd9Sstevel@tonic-gate } scsa2usb_cmd_t;
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate /* for warlock */
5397c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per packet or safe sharing",
5407c478bd9Sstevel@tonic-gate     scsi_cdb scsi_status scsi_pkt buf scsa2usb_cmd scsi_arq_status))
5417c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device scsi_address))
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate /* scsa2usb_cdb position of fields in CDB */
5447c478bd9Sstevel@tonic-gate #define	SCSA2USB_OPCODE		0		/* Opcode field */
5457c478bd9Sstevel@tonic-gate #define	SCSA2USB_LUN		1		/* LUN field */
5467c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_0		2		/* LBA[0] field */
5477c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_1		3		/* LBA[1] field */
5487c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_2		4		/* LBA[2] field */
5497c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_3		5		/* LBA[3] field */
5507c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_0		7		/* LEN[0] field */
5517c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_1		8		/* LEN[1] field */
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate /* macros to calculate LBA for 6/10/12-byte commands */
5547c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_6BYTE(pkt) \
5557c478bd9Sstevel@tonic-gate 	(((pkt)->pkt_cdbp[1] & 0x1f) << 16) + \
5567c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 8) + (pkt)->pkt_cdbp[3]
5577c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_6BYTE(pkt)		(pkt)->pkt_cdbp[4]
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_10BYTE(pkt) \
5607c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[7] << 8) + (pkt)->pkt_cdbp[8]
5617c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_10BYTE(pkt) \
5627c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
5637c478bd9Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_12BYTE(pkt) \
5667c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[6] << 24) + ((pkt)->pkt_cdbp[7] << 16) + \
5677c478bd9Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[8] << 8) +  (pkt)->pkt_cdbp[9]
5687c478bd9Sstevel@tonic-gate #define	SCSA2USB_LBA_12BYTE(pkt) \
5697c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
5707c478bd9Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate /* macros to convert a pkt to cmd and vice-versa */
5737c478bd9Sstevel@tonic-gate #define	PKT2CMD(pkt)		((scsa2usb_cmd_t *)(pkt)->pkt_ha_private)
5747c478bd9Sstevel@tonic-gate #define	CMD2PKT(sp)		((sp)->cmd_pkt
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate /* bulk pipe default timeout value - how long the command to be tried? */
5777c478bd9Sstevel@tonic-gate #define	SCSA2USB_BULK_PIPE_TIMEOUT	(2 * USB_PIPE_TIMEOUT)
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate /* drain timeout in seconds on the work thread */
5807c478bd9Sstevel@tonic-gate #define	SCSA2USB_DRAIN_TIMEOUT		60
5817c478bd9Sstevel@tonic-gate 
5826d9a41ffSqz /* scsa2usb pkt xfer status phase retry times */
5836d9a41ffSqz #define	SCSA2USB_STATUS_RETRIES		3
5846d9a41ffSqz 
5857c478bd9Sstevel@tonic-gate /*
5867c478bd9Sstevel@tonic-gate  * limit on the number of requests that can be queued per LUN:
5877c478bd9Sstevel@tonic-gate  * 3 for untagged queueing, 1 for scsiwatch and a margin of 2
5887c478bd9Sstevel@tonic-gate  */
5897c478bd9Sstevel@tonic-gate #define	SCSA2USB_MAX_REQ_PER_LUN	6
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate /*
5927c478bd9Sstevel@tonic-gate  * The following data structure is used to save the values returned
5937c478bd9Sstevel@tonic-gate  * by the READ_CAPACITY command. lba is the max allowed logical block
5947c478bd9Sstevel@tonic-gate  * address and blen is max allowed block size.
5957c478bd9Sstevel@tonic-gate  */
5967c478bd9Sstevel@tonic-gate typedef struct scsa2usb_read_cap {
5977c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba3;		/* Max lba supported */
5987c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba2;
5997c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba1;
6007c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_lba0;
6017c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen3;	/* Max block size supported */
6027c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen2;
6037c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen1;
6047c478bd9Sstevel@tonic-gate 	uchar_t	scsa2usb_read_cap_blen0;
6057c478bd9Sstevel@tonic-gate } scsa2usb_read_cap_t;
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate #define	SCSA2USB_MK_32BIT(a, b, c, d) \
6087c478bd9Sstevel@tonic-gate 		(((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate /* position of fields for SCMD_READ_CD CDB */
6117c478bd9Sstevel@tonic-gate #define	SCSA2USB_READ_CD_LEN_0	6	/* LEN[0] of SCMD_READ_CD */
6127c478bd9Sstevel@tonic-gate #define	SCSA2USB_READ_CD_LEN_1	7	/* LEN[1] of SCMD_READ_CD */
6137c478bd9Sstevel@tonic-gate #define	SCSA2USB_READ_CD_LEN_2	8	/* LEN[2] of SCMD_READ_CD */
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate /* macro to calculate LEN for SCMD_READ_CD command */
6167c478bd9Sstevel@tonic-gate #define	SCSA2USB_LEN_READ_CD(pkt) \
6177c478bd9Sstevel@tonic-gate 	(((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_0] << 16) +\
6187c478bd9Sstevel@tonic-gate 	    ((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_1] << 8) +\
6197c478bd9Sstevel@tonic-gate 	    (pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_2])
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate /* Figure out Block Size before issuing a WRITE to CD-RW device */
6227c478bd9Sstevel@tonic-gate #define	SCSA2USB_CDRW_BLKSZ(bcount, len)	((bcount) / (len));
6237c478bd9Sstevel@tonic-gate #define	SCSA2USB_VALID_CDRW_BLKSZ(blksz) \
6247c478bd9Sstevel@tonic-gate 	(((blksz) == CDROM_BLK_2048) || ((blksz) == CDROM_BLK_2352) || \
6257c478bd9Sstevel@tonic-gate 	((blksz) == CDROM_BLK_2336) || ((blksz) == CDROM_BLK_2324) || \
6267c478bd9Sstevel@tonic-gate 	((blksz) == 0))
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate /* debug and error msg logging */
6297c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_SCSA	0x0001		/* for SCSA */
6307c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_ATTA	0x0002		/* for ATTA */
6317c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_EVENTS	0x0004		/* for event handling */
6327c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_CALLBACKS	0x0008		/* for callbacks  */
6337c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_TIMEOUT	0x0010		/* for timeouts */
6347c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_DUMPING	0x0020		/* for dumping */
6357c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_PM		0x0040		/* for pwr mgmt */
6367c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_ALL		0xffffffff	/* for everything */
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate #ifdef	DEBUG
6397c478bd9Sstevel@tonic-gate #define	SCSA2USB_PRINT_CDB	scsa2usb_print_cdb
6407c478bd9Sstevel@tonic-gate #else
6417c478bd9Sstevel@tonic-gate #define	SCSA2USB_PRINT_CDB	0 &&
6427c478bd9Sstevel@tonic-gate #endif
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate /* ugen support */
6457c478bd9Sstevel@tonic-gate #define	SCSA2USB_MINOR_UGEN_BITS_MASK	0xff
6467c478bd9Sstevel@tonic-gate #define	SCSA2USB_MINOR_INSTANCE_MASK	~SCSA2USB_MINOR_UGEN_BITS_MASK
6477c478bd9Sstevel@tonic-gate #define	SCSA2USB_MINOR_INSTANCE_SHIFT	8
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate #define	SCSA2USB_MINOR_TO_INSTANCE(minor)	\
6507c478bd9Sstevel@tonic-gate 		(((minor) & SCSA2USB_MINOR_INSTANCE_MASK) >> \
6517c478bd9Sstevel@tonic-gate 		SCSA2USB_MINOR_INSTANCE_SHIFT)
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate #ifdef __cplusplus
6547c478bd9Sstevel@tonic-gate }
6557c478bd9Sstevel@tonic-gate #endif
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate #endif	/* _SYS_USB_SCSA2USB_H */
658