1 /* $NetBSD: umassvar.h,v 1.15 2002/02/07 13:52:55 augustss Exp $ */ 2 /*- 3 * Copyright (c) 1999 MAEKAWA Masahide <bishop@rr.iij4u.or.jp>, 4 * Nick Hibma <n_hibma@freebsd.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD: src/sys/dev/usb/umass.c,v 1.13 2000/03/26 01:39:12 n_hibma Exp $ 29 */ 30 31 #ifdef UMASS_DEBUG 32 #define DIF(m, x) if (umassdebug & (m)) do { x ; } while (0) 33 #define DPRINTF(m, x) if (umassdebug & (m)) logprintf x 34 #define UDMASS_UPPER 0x00008000 /* upper layer */ 35 #define UDMASS_GEN 0x00010000 /* general */ 36 #define UDMASS_SCSI 0x00020000 /* scsi */ 37 #define UDMASS_UFI 0x00040000 /* ufi command set */ 38 #define UDMASS_8070 0x00080000 /* 8070i command set */ 39 #define UDMASS_USB 0x00100000 /* USB general */ 40 #define UDMASS_BBB 0x00200000 /* Bulk-Only transfers */ 41 #define UDMASS_CBI 0x00400000 /* CBI transfers */ 42 #define UDMASS_ALL 0xffff0000 /* all of the above */ 43 44 #define UDMASS_XFER 0x40000000 /* all transfers */ 45 #define UDMASS_CMD 0x80000000 46 47 extern int umassdebug; 48 #else 49 #define DIF(m, x) /* nop */ 50 #define DPRINTF(m, x) /* nop */ 51 #endif 52 53 /* Generic definitions */ 54 55 #define UFI_COMMAND_LENGTH 12 56 57 /* Direction for umass_*_transfer */ 58 #define DIR_NONE 0 59 #define DIR_IN 1 60 #define DIR_OUT 2 61 62 #define MS_TO_TICKS(ms) ((ms) * hz / 1000) 63 64 /* Endpoints for umass */ 65 #define UMASS_BULKIN 0 66 #define UMASS_BULKOUT 1 67 #define UMASS_INTRIN 2 68 #define UMASS_NEP 3 69 70 /* Bulk-Only features */ 71 72 #define UR_BBB_RESET 0xff /* Bulk-Only reset */ 73 #define UR_BBB_GET_MAX_LUN 0xfe 74 75 /* Command Block Wrapper */ 76 typedef struct { 77 uDWord dCBWSignature; 78 #define CBWSIGNATURE 0x43425355 79 uDWord dCBWTag; 80 uDWord dCBWDataTransferLength; 81 uByte bCBWFlags; 82 #define CBWFLAGS_OUT 0x00 83 #define CBWFLAGS_IN 0x80 84 uByte bCBWLUN; 85 uByte bCDBLength; 86 #define CBWCDBLENGTH 16 87 uByte CBWCDB[CBWCDBLENGTH]; 88 } umass_bbb_cbw_t; 89 #define UMASS_BBB_CBW_SIZE 31 90 91 /* Command Status Wrapper */ 92 typedef struct { 93 uDWord dCSWSignature; 94 #define CSWSIGNATURE 0x53425355 95 #define CSWSIGNATURE_OLYMPUS_C1 0x55425355 96 uDWord dCSWTag; 97 uDWord dCSWDataResidue; 98 uByte bCSWStatus; 99 #define CSWSTATUS_GOOD 0x0 100 #define CSWSTATUS_FAILED 0x1 101 #define CSWSTATUS_PHASE 0x2 102 } umass_bbb_csw_t; 103 #define UMASS_BBB_CSW_SIZE 13 104 105 /* CBI features */ 106 107 #define UR_CBI_ADSC 0x00 108 109 typedef unsigned char umass_cbi_cbl_t[16]; /* Command block */ 110 111 typedef union { 112 struct { 113 uByte type; 114 #define IDB_TYPE_CCI 0x00 115 uByte value; 116 #define IDB_VALUE_PASS 0x00 117 #define IDB_VALUE_FAIL 0x01 118 #define IDB_VALUE_PHASE 0x02 119 #define IDB_VALUE_PERSISTENT 0x03 120 #define IDB_VALUE_STATUS_MASK 0x03 121 } common; 122 123 struct { 124 uByte asc; 125 uByte ascq; 126 } ufi; 127 } umass_cbi_sbl_t; 128 129 struct umass_softc; /* see below */ 130 131 typedef void (*umass_callback)(struct umass_softc *, void *, int, int); 132 #define STATUS_CMD_OK 0 /* everything ok */ 133 #define STATUS_CMD_UNKNOWN 1 /* will have to fetch sense */ 134 #define STATUS_CMD_FAILED 2 /* transfer was ok, command failed */ 135 #define STATUS_WIRE_FAILED 3 /* couldn't even get command across */ 136 137 typedef void (*umass_wire_xfer)(struct umass_softc *, int, void *, int, void *, 138 int, int, u_int, umass_callback, void *); 139 typedef void (*umass_wire_reset)(struct umass_softc *, int); 140 typedef void (*umass_wire_state)(usbd_xfer_handle, usbd_private_handle, 141 usbd_status); 142 143 struct umass_wire_methods { 144 umass_wire_xfer wire_xfer; 145 umass_wire_reset wire_reset; 146 umass_wire_state wire_state; 147 }; 148 149 struct umassbus_softc { 150 device_ptr_t sc_child; /* child device, for detach */ 151 }; 152 153 /* the per device structure */ 154 struct umass_softc { 155 USBBASEDEVICE sc_dev; /* base device */ 156 usbd_device_handle sc_udev; /* device */ 157 usbd_interface_handle sc_iface; /* interface */ 158 int sc_ifaceno; /* interface number */ 159 160 u_int8_t sc_epaddr[UMASS_NEP]; 161 usbd_pipe_handle sc_pipe[UMASS_NEP]; 162 usb_device_request_t sc_req; 163 164 const struct umass_wire_methods *sc_methods; 165 166 u_int8_t sc_wire; /* wire protocol */ 167 #define UMASS_WPROTO_UNSPEC 0 168 #define UMASS_WPROTO_BBB 1 169 #define UMASS_WPROTO_CBI 2 170 #define UMASS_WPROTO_CBI_I 3 171 172 u_int8_t sc_cmd; /* command protocol */ 173 #define UMASS_CPROTO_UNSPEC 0 174 #define UMASS_CPROTO_SCSI 1 175 #define UMASS_CPROTO_ATAPI 2 176 #define UMASS_CPROTO_UFI 3 177 #define UMASS_CPROTO_RBC 4 178 #define UMASS_CPROTO_ISD_ATA 5 179 180 u_int32_t sc_quirks; 181 #define UMASS_QUIRK_RS_NO_CLEAR_UA 0x00000002 182 #define UMASS_QUIRK_NO_START_STOP 0x00000004 183 #define UMASS_QUIRK_FORCE_SHORT_INQUIRY 0x00000008 184 #define UMASS_QUIRK_WRONG_CSWSIG 0x00000010 185 #define UMASS_QUIRK_NO_MAX_LUN 0x00000020 186 187 u_int32_t sc_busquirks; 188 189 /* Bulk specific variables for transfers in progress */ 190 umass_bbb_cbw_t cbw; /* command block wrapper */ 191 umass_bbb_csw_t csw; /* command status wrapper*/ 192 /* CBI specific variables for transfers in progress */ 193 umass_cbi_cbl_t cbl; /* command block */ 194 umass_cbi_sbl_t sbl; /* status block */ 195 196 /* xfer handles 197 * Most of our operations are initiated from interrupt context, so 198 * we need to avoid using the one that is in use. We want to avoid 199 * allocating them in the interrupt context as well. 200 */ 201 /* indices into array below */ 202 #define XFER_BBB_CBW 0 /* Bulk-Only */ 203 #define XFER_BBB_DATA 1 204 #define XFER_BBB_DCLEAR 2 205 #define XFER_BBB_CSW1 3 206 #define XFER_BBB_CSW2 4 207 #define XFER_BBB_SCLEAR 5 208 #define XFER_BBB_RESET1 6 209 #define XFER_BBB_RESET2 7 210 #define XFER_BBB_RESET3 8 211 212 #define XFER_CBI_CB 0 /* CBI */ 213 #define XFER_CBI_DATA 1 214 #define XFER_CBI_STATUS 2 215 #define XFER_CBI_DCLEAR 3 216 #define XFER_CBI_SCLEAR 4 217 #define XFER_CBI_RESET1 5 218 #define XFER_CBI_RESET2 6 219 #define XFER_CBI_RESET3 7 220 221 #define XFER_NR 9 /* maximum number */ 222 223 usbd_xfer_handle transfer_xfer[XFER_NR]; /* for ctrl xfers */ 224 225 void *data_buffer; 226 227 int transfer_dir; /* data direction */ 228 void *transfer_data; /* data buffer */ 229 int transfer_datalen; /* (maximum) length */ 230 int transfer_actlen; /* actual length */ 231 umass_callback transfer_cb; /* callback */ 232 void *transfer_priv; /* for callback */ 233 int transfer_status; 234 235 int transfer_state; 236 #define TSTATE_IDLE 0 237 #define TSTATE_BBB_COMMAND 1 /* CBW transfer */ 238 #define TSTATE_BBB_DATA 2 /* Data transfer */ 239 #define TSTATE_BBB_DCLEAR 3 /* clear endpt stall */ 240 #define TSTATE_BBB_STATUS1 4 /* clear endpt stall */ 241 #define TSTATE_BBB_SCLEAR 5 /* clear endpt stall */ 242 #define TSTATE_BBB_STATUS2 6 /* CSW transfer */ 243 #define TSTATE_BBB_RESET1 7 /* reset command */ 244 #define TSTATE_BBB_RESET2 8 /* in clear stall */ 245 #define TSTATE_BBB_RESET3 9 /* out clear stall */ 246 #define TSTATE_CBI_COMMAND 10 /* command transfer */ 247 #define TSTATE_CBI_DATA 11 /* data transfer */ 248 #define TSTATE_CBI_STATUS 12 /* status transfer */ 249 #define TSTATE_CBI_DCLEAR 13 /* clear ep stall */ 250 #define TSTATE_CBI_SCLEAR 14 /* clear ep stall */ 251 #define TSTATE_CBI_RESET1 15 /* reset command */ 252 #define TSTATE_CBI_RESET2 16 /* in clear stall */ 253 #define TSTATE_CBI_RESET3 17 /* out clear stall */ 254 #define TSTATE_STATES 18 /* # of states above */ 255 256 257 int timeout; /* in msecs */ 258 259 u_int8_t maxlun; /* max lun supported */ 260 261 #ifdef UMASS_DEBUG 262 struct timeval tv; 263 #endif 264 265 int sc_xfer_flags; 266 char sc_dying; 267 268 struct umassbus_softc *bus; /* bus dependent data */ 269 }; 270 271 #define UMASS_MAX_TRANSFER_SIZE MAXBSIZE 272