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*11427SVincent.Wang@Sun.COM * Copyright 2010 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 290Sstevel@tonic-gate #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/usb/usba/usbai_private.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate /* 360Sstevel@tonic-gate * SCSA2USB: This header file contains the internal structures 370Sstevel@tonic-gate * and variable definitions used in USB mass storage disk driver. 380Sstevel@tonic-gate */ 390Sstevel@tonic-gate 400Sstevel@tonic-gate 41*11427SVincent.Wang@Sun.COM #define SCSA2USB_MAX_CLONE 256 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 1065789Ssl147100 #define MS_SUPERTOP_VID 0x14cd /* Super Top USB 2.0 IDE enclosure */ 1075789Ssl147100 #define MS_SUPERTOP_DEVICE_6600 0x6600 1085789Ssl147100 1097231Slg150142 #define MS_AIGO_VID 0xed1 /* VendorID of Aigo */ 1107231Slg150142 #define MS_AIGO_DEVICE_6981 0x6981 /* Aigo Miniking Device NEHFSP14 */ 1117231Slg150142 1128075SGuoqing.Zhu@Sun.COM #define MS_ALCOR_VID 0x58f /* Vendor ID of Alcor Micro Corp */ 1138075SGuoqing.Zhu@Sun.COM #define MS_ALCOR_PID0 0x6387 /* PID for 6387 flash disk */ 1148075SGuoqing.Zhu@Sun.COM 1159729SBinzi.Cao@Sun.COM #define MS_TOSHIBA_VID 0x930 /* Vendor ID of Toshiba Corp */ 1169729SBinzi.Cao@Sun.COM #define MS_TOSHIBA_PID0 0x6545 /* Kingston DataTraveler / PNY Attache Stick */ 1179729SBinzi.Cao@Sun.COM 1189729SBinzi.Cao@Sun.COM #define MS_PNY_VID 0x154b /* Vendor ID of PNY Corp */ 1199729SBinzi.Cao@Sun.COM #define MS_PNY_PID0 0x16 /* PNY floppy drive */ 1209729SBinzi.Cao@Sun.COM 12110678SGuoqing.Zhu@Sun.COM #define MS_WD_VID 0x1058 /* Vendor ID of Western Digital */ 12210678SGuoqing.Zhu@Sun.COM #define MS_WD_PID 0x1001 /* PID for Western Digital USB External HDD */ 12310678SGuoqing.Zhu@Sun.COM 1240Sstevel@tonic-gate /* 1252506Ssl147100 * The AMI virtual floppy device is not a real USB storage device, but 1262506Ssl147100 * emulated by the SP firmware shipped together with important Sun x86 1272506Ssl147100 * products such as Galaxy and Thumper platforms. The device causes 1282506Ssl147100 * very long delay in boot process of these platforms which is a big 1292506Ssl147100 * performance issue. Improvement in firmware may solve the issue, but 1302506Ssl147100 * before the firmware is fixed, it needs to be taken care of by software 1312506Ssl147100 * to avoid the huge impact on user experience. 1322506Ssl147100 * 1332506Ssl147100 * The long boot delay is caused by timeouts and retries of READ CAPACITY 1342506Ssl147100 * command issued to the device. The device is a USB ufi subclass device 1352506Ssl147100 * using CBI protocol. When READ CAPACITY command is issued, the device 1362506Ssl147100 * returns STALL on the bulk endpoint during the data stage, however, it 1372506Ssl147100 * doesn't return status on the intr pipe during status stage, so the intr 1382506Ssl147100 * pipe can only fail with timeout. 1392506Ssl147100 * 1402506Ssl147100 * Reducing timeout value to 1 second can help a little bit, but the delay 1412506Ssl147100 * is still noticeable, because the target driver would make many retries 1422506Ssl147100 * for this command. It is not desirable to mess with the target driver 1432506Ssl147100 * for a broken USB device. So adding the device to the scsa2usb blacklist 1442506Ssl147100 * is the best choice we have. 1452506Ssl147100 * 1462506Ssl147100 * It is found that the READ CAPACITY failure only happens when there is 1472506Ssl147100 * no media in the floppy drive. When there is a media, the device works 1482506Ssl147100 * just fine. So READ CAPACITY command cannot be arbitrarily disabled. 1492506Ssl147100 * Media status needs to be checked before issuing the command by sending 1502506Ssl147100 * an additional TEST UNIT READY command. If TEST UNIT READY command 1512506Ssl147100 * return STATUS_GOOD, it means the media is ready and then READ CAPACITY 1522506Ssl147100 * can be issued. 1532506Ssl147100 * 1542506Ssl147100 * SCSA2USB_ATTRS_NO_MEDIA_CHECK is added below for this purpose. It is 1552506Ssl147100 * overrided in scsa2usb.c for the AMI virtual floppy device to take care 1562506Ssl147100 * of the special need. 1572506Ssl147100 */ 1582506Ssl147100 #define MS_AMI_VID 0x46b /* VendorId of AMI */ 1592506Ssl147100 #define MS_AMI_VIRTUAL_FLOPPY 0xff40 /* PID for AMI virtual floppy */ 1602506Ssl147100 1612506Ssl147100 /* 1620Sstevel@tonic-gate * List the attributes that need special case in the driver 1630Sstevel@tonic-gate * SCSA2USB_ATTRS_GET_LUN: Bulk Only Transport Get_Max_Lun class specific 1640Sstevel@tonic-gate * command is not implemented by these devices 1650Sstevel@tonic-gate * SCSA2USB_ATTRS_PM: Some devices don't like being power managed. 1660Sstevel@tonic-gate * SCSA2USB_ATTRS_START_STOP: Some devices don't do anything with 1670Sstevel@tonic-gate * SCMD_START_STOP opcode (for e.g. SmartMedia/CompactFlash/ 1680Sstevel@tonic-gate * Clik!/MemoryStick/MMC USB readers/writers. 1690Sstevel@tonic-gate * SCSA2USB_ATTRS_GET_CONF: SCMD_GET_CONFIGURATION is not supported 1700Sstevel@tonic-gate * SCMD_TEST_UNIT_READY: for floppies this needs to be converted to 1710Sstevel@tonic-gate * SCMD_START_STOP as floppies don't support this 1720Sstevel@tonic-gate * SCSA2USB_ATTRS_GET_PERF: SCMD_GET_PERFORMANCE not supported by 1730Sstevel@tonic-gate * Mitsumi's CD-RW devices. 1740Sstevel@tonic-gate * SCSA2USB_ATTRS_BIG_TIMEOUT: Mitsumi's CD-RW devices need large 1750Sstevel@tonic-gate * timeout with SCMD_START_STOP cmd 1760Sstevel@tonic-gate * SCSA2USB_ATTRS_RMB: Pay attention to the device's RMB setting, 1770Sstevel@tonic-gate * instead of automatically treating it as removable 1781101Ssl147100 * SCSA2USB_ATTRS_USE_CSW_RESIDUE: Some devices report false residue in 1791101Ssl147100 * the CSW of bulk-only transfer status stage though data 1801101Ssl147100 * was successfully transfered, so need to ignore residue. 1812506Ssl147100 * SCSA2USB_ATTRS_NO_MEDIA_CHECK: AMI Virtual Floppy devices need to 1822506Ssl147100 * check if media is ready before issuing READ CAPACITY. 1834834Sfb209375 * SCSA2USB_ATTRS_NO_CAP_ADJUST: Some devices return total logical block number 1844834Sfb209375 * instead of highest logical block address on READ_CAPACITY cmd. 1850Sstevel@tonic-gate * 1860Sstevel@tonic-gate * NOTE: If a device simply STALLs the GET_MAX_LUN BO class-specific command 1870Sstevel@tonic-gate * and recovers then it will not be added to the scsa2usb_blacklist[] table 1880Sstevel@tonic-gate * in scsa2usb.c. The other attributes will not be taken of the table unless 1890Sstevel@tonic-gate * their inclusion causes a recovery and retries (thus seriously affecting 1900Sstevel@tonic-gate * the driver performance). 1910Sstevel@tonic-gate */ 1920Sstevel@tonic-gate #define SCSA2USB_ATTRS_GET_LUN 0x01 /* GET_MAX_LUN (Bulk Only) */ 1930Sstevel@tonic-gate #define SCSA2USB_ATTRS_PM 0x02 /* Some don't support PM */ 1940Sstevel@tonic-gate #define SCSA2USB_ATTRS_START_STOP 0x04 /* SCMD_START_STOP */ 1950Sstevel@tonic-gate #define SCSA2USB_ATTRS_GET_CONF 0x08 /* SCMD_GET_CONFIGURATION */ 1960Sstevel@tonic-gate #define SCSA2USB_ATTRS_GET_PERF 0x10 /* SCMD_GET_PERFORMANCE */ 1970Sstevel@tonic-gate #define SCSA2USB_ATTRS_BIG_TIMEOUT 0x40 /* for SCMD_START_STOP */ 1980Sstevel@tonic-gate #define SCSA2USB_ATTRS_DOORLOCK 0x80 /* for SCMD_DOORLOCK */ 1990Sstevel@tonic-gate #define SCSA2USB_ATTRS_RMB 0x100 /* Pay attention to RMB */ 2000Sstevel@tonic-gate #define SCSA2USB_ATTRS_MODE_SENSE 0x200 /* SCMD_MODE_SENSE */ 2010Sstevel@tonic-gate #define SCSA2USB_ATTRS_INQUIRY 0x400 /* SCMD_INQUIRY */ 2021101Ssl147100 #define SCSA2USB_ATTRS_USE_CSW_RESIDUE 0x800 /* for residue checking */ 2032506Ssl147100 #define SCSA2USB_ATTRS_NO_MEDIA_CHECK 0x1000 /* for media checking */ 2044834Sfb209375 #define SCSA2USB_ATTRS_NO_CAP_ADJUST 0x2000 /* for CAPACITY adjusting */ 20510678SGuoqing.Zhu@Sun.COM #define SCSA2USB_ATTRS_INQUIRY_EVPD 0x4000 /* SCMD_INQUIRY with evpd */ 2060Sstevel@tonic-gate #define SCSA2USB_ATTRS_REDUCED_CMD \ 2070Sstevel@tonic-gate (SCSA2USB_ATTRS_DOORLOCK|SCSA2USB_ATTRS_MODE_SENSE| \ 2081101Ssl147100 SCSA2USB_ATTRS_START_STOP|SCSA2USB_ATTRS_INQUIRY| \ 2091101Ssl147100 SCSA2USB_ATTRS_USE_CSW_RESIDUE) 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate #define SCSA2USB_ALL_ATTRS 0xFFFF /* All of the above */ 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* max inquiry length */ 2140Sstevel@tonic-gate #define SCSA2USB_MAX_INQ_LEN (offsetof(struct scsi_inquiry, inq_serial)) 2150Sstevel@tonic-gate 2161984Scg149915 /* page code of scsi mode page */ 2171984Scg149915 #ifndef SD_MODE_SENSE_PAGE3_CODE 2181984Scg149915 #define SD_MODE_SENSE_PAGE3_CODE 0x03 2191984Scg149915 #endif 2201984Scg149915 2211984Scg149915 #ifndef SD_MODE_SENSE_PAGE4_CODE 2221984Scg149915 #define SD_MODE_SENSE_PAGE4_CODE 0x04 2231984Scg149915 #endif 2241984Scg149915 22510018SGuoqing.Zhu@Sun.COM #define SD_MODE_SENSE_PAGE_MASK 0x3F 22610018SGuoqing.Zhu@Sun.COM 2270Sstevel@tonic-gate /* 2280Sstevel@tonic-gate * PM support 2290Sstevel@tonic-gate */ 2300Sstevel@tonic-gate typedef struct scsa2usb_power { 2310Sstevel@tonic-gate /* device busy accounting */ 2320Sstevel@tonic-gate int scsa2usb_pm_busy; 2330Sstevel@tonic-gate /* this is the bit mask of the power states that device has */ 2340Sstevel@tonic-gate uint8_t scsa2usb_pwr_states; 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate uint8_t scsa2usb_wakeup_enabled; 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate /* current power level the device is in */ 2390Sstevel@tonic-gate uint8_t scsa2usb_current_power; 2400Sstevel@tonic-gate } scsa2usb_power_t; 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate /* 2430Sstevel@tonic-gate * CPR support: 2440Sstevel@tonic-gate * keep track of the last command issued to the drive. If it 2450Sstevel@tonic-gate * was TUR or EJECT then allow issuing a CPR suspend. 2460Sstevel@tonic-gate */ 2470Sstevel@tonic-gate #define LOEJECT 2 /* eject bit in start/stop cmd */ 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate typedef struct scsa2usb_last_cmd { 2500Sstevel@tonic-gate /* this is the cdb of the last command issued */ 2510Sstevel@tonic-gate uchar_t cdb[SCSI_CDB_SIZE]; 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate /* this is the status of the last command issued */ 2540Sstevel@tonic-gate uint_t status; 2550Sstevel@tonic-gate } scsa2usb_last_cmd_t; 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate /* 2580Sstevel@tonic-gate * override values 2590Sstevel@tonic-gate * These values may be set in scsa2usb.conf for particular devices 2600Sstevel@tonic-gate */ 2610Sstevel@tonic-gate typedef struct scsa2usb_ov { 2620Sstevel@tonic-gate int vid; /* vendor id */ 2630Sstevel@tonic-gate int pid; /* product id */ 2640Sstevel@tonic-gate int rev; /* revision */ 2650Sstevel@tonic-gate int subclass; /* subclass override */ 2660Sstevel@tonic-gate int protocol; /* protocol override */ 2670Sstevel@tonic-gate int pmoff; /* power management override */ 2681415Scg149915 int fake_removable; /* removable device override */ 2690Sstevel@tonic-gate int no_modesense; /* no mode sense */ 2700Sstevel@tonic-gate /* no modesense, doorlock, PM, start/stop */ 2710Sstevel@tonic-gate int reduced_cmd_support; 2720Sstevel@tonic-gate } scsa2usb_ov_t; 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate /* 2760Sstevel@tonic-gate * Per bulk device "state" data structure. 2770Sstevel@tonic-gate */ 2780Sstevel@tonic-gate typedef struct scsa2usb_state { 2790Sstevel@tonic-gate int scsa2usb_instance; /* Instance number */ 2800Sstevel@tonic-gate int scsa2usb_dev_state; /* USB device state */ 2810Sstevel@tonic-gate int scsa2usb_flags; /* Per instance flags */ 2820Sstevel@tonic-gate int scsa2usb_intfc_num; /* Interface number */ 2830Sstevel@tonic-gate dev_info_t *scsa2usb_dip; /* Per device. info */ 2840Sstevel@tonic-gate scsa2usb_power_t *scsa2usb_pm; /* PM state info */ 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate int scsa2usb_transport_busy; /* ugen/sd traffic */ 2870Sstevel@tonic-gate int scsa2usb_ugen_open_count; 2880Sstevel@tonic-gate kcondvar_t scsa2usb_transport_busy_cv; 289*11427SVincent.Wang@Sun.COM struct proc *scsa2usb_busy_proc; /* owner of the hardware */ 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate kmutex_t scsa2usb_mutex; /* Per instance lock */ 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate struct scsi_hba_tran *scsa2usb_tran; /* SCSI transport ptr */ 2940Sstevel@tonic-gate struct scsi_pkt *scsa2usb_cur_pkt; /* SCSI packet ptr */ 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate usba_list_entry_t scsa2usb_waitQ[SCSA2USB_MAX_LUNS]; 2970Sstevel@tonic-gate /* waitQ list */ 2980Sstevel@tonic-gate struct scsa2usb_cmd *scsa2usb_arq_cmd; /* ARQ cmd */ 2990Sstevel@tonic-gate struct buf *scsa2usb_arq_bp; /* ARQ buf */ 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate dev_info_t *scsa2usb_lun_dip[SCSA2USB_MAX_LUNS]; 3020Sstevel@tonic-gate /* store devinfo per LUN */ 3030Sstevel@tonic-gate struct scsi_inquiry scsa2usb_lun_inquiry[SCSA2USB_MAX_LUNS]; 3040Sstevel@tonic-gate /* store inquiry per LUN */ 3050Sstevel@tonic-gate usb_if_descr_t scsa2usb_intfc_descr; /* Interface descr */ 3060Sstevel@tonic-gate usb_ep_descr_t scsa2usb_bulkin_ept; /* Bulk In descriptor */ 3070Sstevel@tonic-gate usb_ep_descr_t scsa2usb_bulkout_ept; /* Bulkout descriptor */ 3080Sstevel@tonic-gate usb_ep_descr_t scsa2usb_intr_ept; /* Intr ept descr */ 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate usb_pipe_handle_t scsa2usb_default_pipe; /* Default pipe Hndle */ 3110Sstevel@tonic-gate usb_pipe_handle_t scsa2usb_intr_pipe; /* Intr polling Hndle */ 3120Sstevel@tonic-gate usb_pipe_handle_t scsa2usb_bulkin_pipe; /* Bulk Inpipe Handle */ 3130Sstevel@tonic-gate usb_pipe_handle_t scsa2usb_bulkout_pipe; /* Bulk Outpipe Hndle */ 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate uint_t scsa2usb_pipe_state; /* resetting state */ 3160Sstevel@tonic-gate uint_t scsa2usb_tag; /* current tag */ 3170Sstevel@tonic-gate uint_t scsa2usb_pkt_state; /* packet state */ 3180Sstevel@tonic-gate uint_t scsa2usb_n_luns; /* number of luns */ 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate usb_log_handle_t scsa2usb_log_handle; /* log handle */ 3210Sstevel@tonic-gate struct scsa2usb_cpr *scsa2usb_panic_info; /* for cpr info */ 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate size_t scsa2usb_lbasize[SCSA2USB_MAX_LUNS]; 3240Sstevel@tonic-gate /* sector size */ 3250Sstevel@tonic-gate size_t scsa2usb_totalsec[SCSA2USB_MAX_LUNS]; 3260Sstevel@tonic-gate /* total sectors */ 3270Sstevel@tonic-gate size_t scsa2usb_secsz[SCSA2USB_MAX_LUNS]; 3280Sstevel@tonic-gate /* sector size */ 3290Sstevel@tonic-gate size_t scsa2usb_max_bulk_xfer_size; /* from HCD */ 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate usb_client_dev_data_t *scsa2usb_dev_data; /* USB registration */ 3320Sstevel@tonic-gate scsa2usb_last_cmd_t scsa2usb_last_cmd; /* last/prev command */ 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate uint_t scsa2usb_attrs; /* for bad devices */ 3350Sstevel@tonic-gate uint_t scsa2usb_cmd_protocol; /* CMD protocol used */ 3360Sstevel@tonic-gate kthread_t *scsa2usb_work_thread_id; /* handle commands */ 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate /* conf file override values */ 3390Sstevel@tonic-gate uint_t scsa2usb_subclass_override; 3400Sstevel@tonic-gate uint_t scsa2usb_protocol_override; 3410Sstevel@tonic-gate char *scsa2usb_override_str; 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate /* suppress repetitive disconnect warnings */ 3440Sstevel@tonic-gate boolean_t scsa2usb_warning_given; 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate boolean_t scsa2usb_rcvd_not_ready; /* received NOT */ 3470Sstevel@tonic-gate /* READY sense data */ 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate usb_ugen_hdl_t scsa2usb_ugen_hdl; /* ugen support */ 350*11427SVincent.Wang@Sun.COM 351*11427SVincent.Wang@Sun.COM uint8_t scsa2usb_clones[SCSA2USB_MAX_CLONE]; 3520Sstevel@tonic-gate } scsa2usb_state_t; 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate /* for warlock */ 3560Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsa2usb_state::scsa2usb_mutex, scsa2usb_state)) 3570Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_instance)) 3580Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dip)) 3590Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_cmd)) 3600Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_bp)) 3610Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_ept)) 3620Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_ept)) 3630Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_ept)) 3640Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_default_pipe)) 3650Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_pipe)) 3660Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_pipe)) 3670Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkout_pipe)) 3680Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_log_handle)) 3690Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intfc_num)) 3700Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dev_data)) 3710Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_ugen_hdl)) 372189Sfrits _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_pm)) 3730Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa2usb_power_t)) 3740Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_hba_tran_t)) 3750Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", usb_bulk_req_t)) 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate /* scsa2usb_pipe_state values */ 3780Sstevel@tonic-gate #define SCSA2USB_PIPE_NORMAL 0x00 /* no reset or clearing */ 3790Sstevel@tonic-gate #define SCSA2USB_PIPE_CLOSING 0x01 /* closing all pipes */ 3800Sstevel@tonic-gate #define SCSA2USB_PIPE_DEV_RESET 0x02 /* device specific reset */ 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate /* pkt xfer state machine */ 3830Sstevel@tonic-gate #define SCSA2USB_PKT_NONE 0 /* device is idle */ 3840Sstevel@tonic-gate #define SCSA2USB_PKT_PROCESS_CSW 1 /* device doing status again */ 3850Sstevel@tonic-gate #define SCSA2USB_PKT_DO_COMP 2 /* device is done xfer */ 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate /* scsa2usb_flags values */ 3880Sstevel@tonic-gate #define SCSA2USB_FLAGS_PIPES_OPENED 0x001 /* usb pipes are open */ 3890Sstevel@tonic-gate #define SCSA2USB_FLAGS_HBA_ATTACH_SETUP 0x002 /* scsi hba setup done */ 3900Sstevel@tonic-gate #define SCSA2USB_FLAGS_LOCKS_INIT 0x004 /* basic inits done */ 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate /* scsa2usb_cmd_protocol values */ 3930Sstevel@tonic-gate #define SCSA2USB_UNKNOWN_PROTOCOL 0x0000 /* unknown wire protocol */ 3940Sstevel@tonic-gate #define SCSA2USB_CB_PROTOCOL 0x0001 /* CBI wire protocol */ 3950Sstevel@tonic-gate #define SCSA2USB_CBI_PROTOCOL 0x0002 /* CBI w/ intr wire protocol */ 3960Sstevel@tonic-gate #define SCSA2USB_BULK_ONLY_PROTOCOL 0x0004 /* Bulk Only wire protocol */ 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate #define SCSA2USB_SCSI_CMDSET 0x1000 /* SCSI command set followed */ 3990Sstevel@tonic-gate #define SCSA2USB_ATAPI_CMDSET 0x2000 /* ATAPI command set followed */ 4000Sstevel@tonic-gate #define SCSA2USB_UFI_CMDSET 0x4000 /* UFI command set followed */ 4010Sstevel@tonic-gate #define SCSA2USB_CMDSET_MASK 0x7000 /* OR al the above */ 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate #define SCSA2USB_IS_UFI_CMDSET(s) \ 4040Sstevel@tonic-gate (((s)->scsa2usb_cmd_protocol & SCSA2USB_UFI_CMDSET)) 4050Sstevel@tonic-gate #define SCSA2USB_IS_SCSI_CMDSET(s) \ 4060Sstevel@tonic-gate (((s)->scsa2usb_cmd_protocol & SCSA2USB_SCSI_CMDSET)) 4070Sstevel@tonic-gate #define SCSA2USB_IS_ATAPI_CMDSET(s) \ 4080Sstevel@tonic-gate (((s)->scsa2usb_cmd_protocol & SCSA2USB_ATAPI_CMDSET)) 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate #define SCSA2USB_IS_CB(s) \ 4110Sstevel@tonic-gate (((s)->scsa2usb_cmd_protocol & SCSA2USB_CB_PROTOCOL)) 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate #define SCSA2USB_IS_CBI(s) \ 4140Sstevel@tonic-gate (((s)->scsa2usb_cmd_protocol & SCSA2USB_CBI_PROTOCOL)) 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate #define SCSA2USB_IS_BULK_ONLY(s) \ 4170Sstevel@tonic-gate (((s)->scsa2usb_cmd_protocol & SCSA2USB_BULK_ONLY_PROTOCOL)) 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate /* check if it is ok to access the device and send command to it */ 4200Sstevel@tonic-gate #define SCSA2USB_DEVICE_ACCESS_OK(s) \ 4210Sstevel@tonic-gate ((s)->scsa2usb_dev_state == USB_DEV_ONLINE) 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate /* check if we are in any reset */ 4240Sstevel@tonic-gate #define SCSA2USB_IN_RESET(s) \ 4250Sstevel@tonic-gate (((s)->scsa2usb_pipe_state & SCSA2USB_PIPE_DEV_RESET) != 0) 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate /* check if the device is busy */ 4280Sstevel@tonic-gate #define SCSA2USB_BUSY(s) \ 4290Sstevel@tonic-gate (((s)->scsa2usb_cur_pkt) || \ 4300Sstevel@tonic-gate ((s)->scsa2usb_pipe_state != SCSA2USB_PIPE_NORMAL) || \ 4310Sstevel@tonic-gate ((s)->scsa2usb_pkt_state != SCSA2USB_PKT_NONE)) 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate /* check if we're doing cpr */ 4340Sstevel@tonic-gate #define SCSA2USB_CHK_CPR(s) \ 4350Sstevel@tonic-gate (((s)->scsa2usb_dev_state == USB_DEV_SUSPENDED)) 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate /* check if we're either paniced or in cpr state */ 4380Sstevel@tonic-gate #define SCSA2USB_CHK_PANIC_CPR(s) \ 4390Sstevel@tonic-gate (ddi_in_panic() || SCSA2USB_CHK_CPR(s)) 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate /* reset scsa2usb state after pkt_comp is called */ 4420Sstevel@tonic-gate #define SCSA2USB_RESET_CUR_PKT(s) \ 4430Sstevel@tonic-gate (s)->scsa2usb_cur_pkt = NULL; \ 4440Sstevel@tonic-gate (s)->scsa2usb_pkt_state = SCSA2USB_PKT_NONE; 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate /* print a panic sync message to the console */ 4470Sstevel@tonic-gate #define SCSA2USB_PRINT_SYNC_MSG(m, s) \ 4480Sstevel@tonic-gate if ((m) == B_TRUE) { \ 4493435Slg150142 USB_DPRINTF_L1(DPRINT_MASK_SCSA, (s)->scsa2usb_log_handle, \ 4500Sstevel@tonic-gate "syncing not supported"); \ 4510Sstevel@tonic-gate (m) = B_FALSE; \ 4520Sstevel@tonic-gate } 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate /* Cancel callbacks registered during attach time */ 4550Sstevel@tonic-gate #define SCSA2USB_CANCEL_CB(id) \ 4560Sstevel@tonic-gate if ((id)) { \ 4570Sstevel@tonic-gate (void) callb_delete((id)); \ 4580Sstevel@tonic-gate (id) = 0; \ 4590Sstevel@tonic-gate } 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate /* Set SCSA2USB_PKT_DO_COMP state if there is active I/O */ 4620Sstevel@tonic-gate #define SCSA2USB_SET_PKT_DO_COMP_STATE(s) \ 4630Sstevel@tonic-gate if ((s)->scsa2usb_cur_pkt) { \ 4640Sstevel@tonic-gate (s)->scsa2usb_pkt_state = SCSA2USB_PKT_DO_COMP; \ 4650Sstevel@tonic-gate } 4660Sstevel@tonic-gate 4670Sstevel@tonic-gate #define SCSA2USB_FREE_MSG(data) \ 4680Sstevel@tonic-gate if ((data)) { \ 4690Sstevel@tonic-gate freemsg((data)); \ 4700Sstevel@tonic-gate } 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate #define SCSA2USB_FREE_BULK_REQ(req) \ 4730Sstevel@tonic-gate if ((req)) { \ 4740Sstevel@tonic-gate usb_free_bulk_req((req)); /* Free request */ \ 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate /* SCSA related */ 4790Sstevel@tonic-gate #define ADDR2TRAN(ap) ((ap)->a_hba_tran) 4800Sstevel@tonic-gate #define TRAN2SCSA2USB(tran) ((scsa2usb_state_t *)(tran)->tran_hba_private) 4810Sstevel@tonic-gate #define ADDR2SCSA2USB(ap) (TRAN2SCSA2USB(ADDR2TRAN(ap))) 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate #define PKT_PRIV_LEN 16 4840Sstevel@tonic-gate 4852506Ssl147100 #define PKT_DEFAULT_TIMEOUT 5 4862506Ssl147100 4870Sstevel@tonic-gate /* 4880Sstevel@tonic-gate * auto request sense 4890Sstevel@tonic-gate */ 4900Sstevel@tonic-gate #define RQ_MAKECOM_COMMON(pktp, flag, cmd) \ 4910Sstevel@tonic-gate (pktp)->pkt_flags = (flag), \ 4920Sstevel@tonic-gate ((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_cmd = (cmd), \ 4930Sstevel@tonic-gate ((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_lun = \ 4940Sstevel@tonic-gate (pktp)->pkt_address.a_lun 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate #define RQ_MAKECOM_G0(pktp, flag, cmd, addr, cnt) \ 4970Sstevel@tonic-gate RQ_MAKECOM_COMMON((pktp), (flag), (cmd)), \ 4980Sstevel@tonic-gate FORMG0ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \ 4990Sstevel@tonic-gate FORMG0COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt)) 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate /* transport related */ 5030Sstevel@tonic-gate #define SCSA2USB_JUST_ACCEPT 0 5040Sstevel@tonic-gate #define SCSA2USB_TRANSPORT 1 5050Sstevel@tonic-gate #define SCSA2USB_REJECT -1 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate /* 5080Sstevel@tonic-gate * The scsa2usb_cpr_info data structure is used for cpr related 5090Sstevel@tonic-gate * callbacks. It is used for panic callbacks as well. 5100Sstevel@tonic-gate */ 5110Sstevel@tonic-gate typedef struct scsa2usb_cpr { 5120Sstevel@tonic-gate callb_cpr_t cpr; /* for cpr related info */ 5130Sstevel@tonic-gate struct scsa2usb_state *statep; /* for scsa2usb state info */ 5140Sstevel@tonic-gate kmutex_t lockp; /* mutex used by cpr_info_t */ 5150Sstevel@tonic-gate } scsa2usb_cpr_t; 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::cpr)) 5180Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::statep)) 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate /* 5210Sstevel@tonic-gate * The scsa2usb_cmd data structure is defined here. It gets 5220Sstevel@tonic-gate * initialized per command that is sent to the device. 5230Sstevel@tonic-gate */ 5240Sstevel@tonic-gate typedef struct scsa2usb_cmd { 5250Sstevel@tonic-gate struct scsi_pkt *cmd_pkt; /* copy of pkt ptr */ 5260Sstevel@tonic-gate struct buf *cmd_bp; /* copy of bp ptr */ 5270Sstevel@tonic-gate size_t cmd_xfercount; /* current xfer count */ 5280Sstevel@tonic-gate size_t cmd_resid_xfercount; /* last xfer resid */ 5290Sstevel@tonic-gate int cmd_scblen; /* status length */ 5300Sstevel@tonic-gate int cmd_tag; /* tag */ 5310Sstevel@tonic-gate int cmd_timeout; /* copy of pkt_time */ 5320Sstevel@tonic-gate uchar_t cmd_cdb[SCSI_CDB_SIZE]; /* CDB */ 5330Sstevel@tonic-gate uchar_t cmd_dir; /* direction */ 5340Sstevel@tonic-gate uchar_t cmd_actual_len; /* cdb len */ 5350Sstevel@tonic-gate uchar_t cmd_cdblen; /* requested cdb len */ 5360Sstevel@tonic-gate struct scsi_arq_status cmd_scb; /* status, w/ arq */ 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate /* used in multiple xfers */ 5390Sstevel@tonic-gate size_t cmd_total_xfercount; /* total xfer val */ 5400Sstevel@tonic-gate size_t cmd_offset; /* offset into buf */ 5410Sstevel@tonic-gate int cmd_lba; /* current xfer lba */ 5420Sstevel@tonic-gate int cmd_done; /* command done? */ 5430Sstevel@tonic-gate int cmd_blksize; /* block size */ 5440Sstevel@tonic-gate usba_list_entry_t cmd_waitQ; /* waitQ element */ 5450Sstevel@tonic-gate } scsa2usb_cmd_t; 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate /* for warlock */ 5480Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per packet or safe sharing", 5490Sstevel@tonic-gate scsi_cdb scsi_status scsi_pkt buf scsa2usb_cmd scsi_arq_status)) 5500Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device scsi_address)) 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate /* scsa2usb_cdb position of fields in CDB */ 5530Sstevel@tonic-gate #define SCSA2USB_OPCODE 0 /* Opcode field */ 5540Sstevel@tonic-gate #define SCSA2USB_LUN 1 /* LUN field */ 5550Sstevel@tonic-gate #define SCSA2USB_LBA_0 2 /* LBA[0] field */ 5560Sstevel@tonic-gate #define SCSA2USB_LBA_1 3 /* LBA[1] field */ 5570Sstevel@tonic-gate #define SCSA2USB_LBA_2 4 /* LBA[2] field */ 5580Sstevel@tonic-gate #define SCSA2USB_LBA_3 5 /* LBA[3] field */ 5590Sstevel@tonic-gate #define SCSA2USB_LEN_0 7 /* LEN[0] field */ 5600Sstevel@tonic-gate #define SCSA2USB_LEN_1 8 /* LEN[1] field */ 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate /* macros to calculate LBA for 6/10/12-byte commands */ 5630Sstevel@tonic-gate #define SCSA2USB_LBA_6BYTE(pkt) \ 5640Sstevel@tonic-gate (((pkt)->pkt_cdbp[1] & 0x1f) << 16) + \ 5650Sstevel@tonic-gate ((pkt)->pkt_cdbp[2] << 8) + (pkt)->pkt_cdbp[3] 5660Sstevel@tonic-gate #define SCSA2USB_LEN_6BYTE(pkt) (pkt)->pkt_cdbp[4] 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate #define SCSA2USB_LEN_10BYTE(pkt) \ 5690Sstevel@tonic-gate ((pkt)->pkt_cdbp[7] << 8) + (pkt)->pkt_cdbp[8] 5700Sstevel@tonic-gate #define SCSA2USB_LBA_10BYTE(pkt) \ 5710Sstevel@tonic-gate ((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \ 5720Sstevel@tonic-gate ((pkt)->pkt_cdbp[4] << 8) + (pkt)->pkt_cdbp[5] 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate #define SCSA2USB_LEN_12BYTE(pkt) \ 5750Sstevel@tonic-gate ((pkt)->pkt_cdbp[6] << 24) + ((pkt)->pkt_cdbp[7] << 16) + \ 5760Sstevel@tonic-gate ((pkt)->pkt_cdbp[8] << 8) + (pkt)->pkt_cdbp[9] 5770Sstevel@tonic-gate #define SCSA2USB_LBA_12BYTE(pkt) \ 5780Sstevel@tonic-gate ((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \ 5790Sstevel@tonic-gate ((pkt)->pkt_cdbp[4] << 8) + (pkt)->pkt_cdbp[5] 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate /* macros to convert a pkt to cmd and vice-versa */ 5820Sstevel@tonic-gate #define PKT2CMD(pkt) ((scsa2usb_cmd_t *)(pkt)->pkt_ha_private) 5830Sstevel@tonic-gate #define CMD2PKT(sp) ((sp)->cmd_pkt 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate /* bulk pipe default timeout value - how long the command to be tried? */ 5860Sstevel@tonic-gate #define SCSA2USB_BULK_PIPE_TIMEOUT (2 * USB_PIPE_TIMEOUT) 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate /* drain timeout in seconds on the work thread */ 5890Sstevel@tonic-gate #define SCSA2USB_DRAIN_TIMEOUT 60 5900Sstevel@tonic-gate 591918Sqz150045 /* scsa2usb pkt xfer status phase retry times */ 592918Sqz150045 #define SCSA2USB_STATUS_RETRIES 3 593918Sqz150045 5940Sstevel@tonic-gate /* 5950Sstevel@tonic-gate * limit on the number of requests that can be queued per LUN: 5960Sstevel@tonic-gate * 3 for untagged queueing, 1 for scsiwatch and a margin of 2 5970Sstevel@tonic-gate */ 5980Sstevel@tonic-gate #define SCSA2USB_MAX_REQ_PER_LUN 6 5990Sstevel@tonic-gate 6000Sstevel@tonic-gate /* 6010Sstevel@tonic-gate * The following data structure is used to save the values returned 6020Sstevel@tonic-gate * by the READ_CAPACITY command. lba is the max allowed logical block 6030Sstevel@tonic-gate * address and blen is max allowed block size. 6040Sstevel@tonic-gate */ 6050Sstevel@tonic-gate typedef struct scsa2usb_read_cap { 6060Sstevel@tonic-gate uchar_t scsa2usb_read_cap_lba3; /* Max lba supported */ 6070Sstevel@tonic-gate uchar_t scsa2usb_read_cap_lba2; 6080Sstevel@tonic-gate uchar_t scsa2usb_read_cap_lba1; 6090Sstevel@tonic-gate uchar_t scsa2usb_read_cap_lba0; 6100Sstevel@tonic-gate uchar_t scsa2usb_read_cap_blen3; /* Max block size supported */ 6110Sstevel@tonic-gate uchar_t scsa2usb_read_cap_blen2; 6120Sstevel@tonic-gate uchar_t scsa2usb_read_cap_blen1; 6130Sstevel@tonic-gate uchar_t scsa2usb_read_cap_blen0; 6140Sstevel@tonic-gate } scsa2usb_read_cap_t; 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate #define SCSA2USB_MK_32BIT(a, b, c, d) \ 6170Sstevel@tonic-gate (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate /* position of fields for SCMD_READ_CD CDB */ 6200Sstevel@tonic-gate #define SCSA2USB_READ_CD_LEN_0 6 /* LEN[0] of SCMD_READ_CD */ 6210Sstevel@tonic-gate #define SCSA2USB_READ_CD_LEN_1 7 /* LEN[1] of SCMD_READ_CD */ 6220Sstevel@tonic-gate #define SCSA2USB_READ_CD_LEN_2 8 /* LEN[2] of SCMD_READ_CD */ 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate /* macro to calculate LEN for SCMD_READ_CD command */ 6250Sstevel@tonic-gate #define SCSA2USB_LEN_READ_CD(pkt) \ 6260Sstevel@tonic-gate (((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_0] << 16) +\ 6270Sstevel@tonic-gate ((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_1] << 8) +\ 6280Sstevel@tonic-gate (pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_2]) 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate /* Figure out Block Size before issuing a WRITE to CD-RW device */ 6310Sstevel@tonic-gate #define SCSA2USB_CDRW_BLKSZ(bcount, len) ((bcount) / (len)); 6320Sstevel@tonic-gate #define SCSA2USB_VALID_CDRW_BLKSZ(blksz) \ 6330Sstevel@tonic-gate (((blksz) == CDROM_BLK_2048) || ((blksz) == CDROM_BLK_2352) || \ 6340Sstevel@tonic-gate ((blksz) == CDROM_BLK_2336) || ((blksz) == CDROM_BLK_2324) || \ 6350Sstevel@tonic-gate ((blksz) == 0)) 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate /* debug and error msg logging */ 6380Sstevel@tonic-gate #define DPRINT_MASK_SCSA 0x0001 /* for SCSA */ 6390Sstevel@tonic-gate #define DPRINT_MASK_ATTA 0x0002 /* for ATTA */ 6400Sstevel@tonic-gate #define DPRINT_MASK_EVENTS 0x0004 /* for event handling */ 6410Sstevel@tonic-gate #define DPRINT_MASK_CALLBACKS 0x0008 /* for callbacks */ 6420Sstevel@tonic-gate #define DPRINT_MASK_TIMEOUT 0x0010 /* for timeouts */ 6430Sstevel@tonic-gate #define DPRINT_MASK_DUMPING 0x0020 /* for dumping */ 6440Sstevel@tonic-gate #define DPRINT_MASK_PM 0x0040 /* for pwr mgmt */ 6450Sstevel@tonic-gate #define DPRINT_MASK_ALL 0xffffffff /* for everything */ 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate #ifdef DEBUG 6480Sstevel@tonic-gate #define SCSA2USB_PRINT_CDB scsa2usb_print_cdb 6490Sstevel@tonic-gate #else 6500Sstevel@tonic-gate #define SCSA2USB_PRINT_CDB 0 && 6510Sstevel@tonic-gate #endif 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate /* ugen support */ 6540Sstevel@tonic-gate #define SCSA2USB_MINOR_UGEN_BITS_MASK 0xff 6550Sstevel@tonic-gate #define SCSA2USB_MINOR_INSTANCE_MASK ~SCSA2USB_MINOR_UGEN_BITS_MASK 6560Sstevel@tonic-gate #define SCSA2USB_MINOR_INSTANCE_SHIFT 8 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate #define SCSA2USB_MINOR_TO_INSTANCE(minor) \ 6590Sstevel@tonic-gate (((minor) & SCSA2USB_MINOR_INSTANCE_MASK) >> \ 6600Sstevel@tonic-gate SCSA2USB_MINOR_INSTANCE_SHIFT) 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate #ifdef __cplusplus 6630Sstevel@tonic-gate } 6640Sstevel@tonic-gate #endif 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate #endif /* _SYS_USB_SCSA2USB_H */ 667