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