FreeBSD/Linux Kernel Cross Reference
sys/dev/usb/umassvar.h
1 /* $NetBSD: umassvar.h,v 1.23 2004/03/22 14:55:42 tls 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 /* Endpoints for umass */
63 #define UMASS_BULKIN 0
64 #define UMASS_BULKOUT 1
65 #define UMASS_INTRIN 2
66 #define UMASS_NEP 3
67
68 /* Bulk-Only features */
69
70 #define UR_BBB_RESET 0xff /* Bulk-Only reset */
71 #define UR_BBB_GET_MAX_LUN 0xfe
72
73 /* Command Block Wrapper */
74 typedef struct {
75 uDWord dCBWSignature;
76 #define CBWSIGNATURE 0x43425355
77 uDWord dCBWTag;
78 uDWord dCBWDataTransferLength;
79 uByte bCBWFlags;
80 #define CBWFLAGS_OUT 0x00
81 #define CBWFLAGS_IN 0x80
82 uByte bCBWLUN;
83 uByte bCDBLength;
84 #define CBWCDBLENGTH 16
85 uByte CBWCDB[CBWCDBLENGTH];
86 } umass_bbb_cbw_t;
87 #define UMASS_BBB_CBW_SIZE 31
88
89 /* Command Status Wrapper */
90 typedef struct {
91 uDWord dCSWSignature;
92 #define CSWSIGNATURE 0x53425355
93 #define CSWSIGNATURE_OLYMPUS_C1 0x55425355
94 uDWord dCSWTag;
95 uDWord dCSWDataResidue;
96 uByte bCSWStatus;
97 #define CSWSTATUS_GOOD 0x0
98 #define CSWSTATUS_FAILED 0x1
99 #define CSWSTATUS_PHASE 0x2
100 } umass_bbb_csw_t;
101 #define UMASS_BBB_CSW_SIZE 13
102
103 /* CBI features */
104
105 #define UR_CBI_ADSC 0x00
106
107 typedef unsigned char umass_cbi_cbl_t[16]; /* Command block */
108
109 typedef union {
110 struct {
111 uByte type;
112 #define IDB_TYPE_CCI 0x00
113 uByte value;
114 #define IDB_VALUE_PASS 0x00
115 #define IDB_VALUE_FAIL 0x01
116 #define IDB_VALUE_PHASE 0x02
117 #define IDB_VALUE_PERSISTENT 0x03
118 #define IDB_VALUE_STATUS_MASK 0x03
119 } common;
120
121 struct {
122 uByte asc;
123 uByte ascq;
124 } ufi;
125 } umass_cbi_sbl_t;
126
127 struct umass_softc; /* see below */
128
129 typedef void (*umass_callback)(struct umass_softc *, void *, int, int);
130 #define STATUS_CMD_OK 0 /* everything ok */
131 #define STATUS_CMD_UNKNOWN 1 /* will have to fetch sense */
132 #define STATUS_CMD_FAILED 2 /* transfer was ok, command failed */
133 #define STATUS_WIRE_FAILED 3 /* couldn't even get command across */
134
135 typedef void (*umass_wire_xfer)(struct umass_softc *, int, void *, int, void *,
136 int, int, u_int, umass_callback, void *);
137 typedef void (*umass_wire_reset)(struct umass_softc *, int);
138 typedef void (*umass_wire_state)(usbd_xfer_handle, usbd_private_handle,
139 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 umassbus_softc {
148 device_ptr_t sc_child; /* child device, for detach */
149 };
150
151 /* the per device structure */
152 struct umass_softc {
153 USBBASEDEVICE sc_dev; /* base device */
154 usbd_device_handle sc_udev; /* device */
155 usbd_interface_handle sc_iface; /* interface */
156 int sc_ifaceno; /* interface number */
157
158 u_int8_t sc_epaddr[UMASS_NEP];
159 usbd_pipe_handle sc_pipe[UMASS_NEP];
160 usb_device_request_t sc_req;
161
162 const struct umass_wire_methods *sc_methods;
163
164 u_int8_t sc_wire; /* wire protocol */
165 #define UMASS_WPROTO_UNSPEC 0
166 #define UMASS_WPROTO_BBB 1
167 #define UMASS_WPROTO_CBI 2
168 #define UMASS_WPROTO_CBI_I 3
169
170 u_int8_t sc_cmd; /* command protocol */
171 #define UMASS_CPROTO_UNSPEC 0
172 #define UMASS_CPROTO_SCSI 1
173 #define UMASS_CPROTO_ATAPI 2
174 #define UMASS_CPROTO_UFI 3
175 #define UMASS_CPROTO_RBC 4
176 #define UMASS_CPROTO_ISD_ATA 5
177
178 u_int32_t sc_quirks;
179 #define UMASS_QUIRK_WRONG_CSWSIG 0x00000001
180 #define UMASS_QUIRK_WRONG_CSWTAG 0x00000002
181
182 u_int32_t sc_busquirks;
183
184 /* Bulk specific variables for transfers in progress */
185 umass_bbb_cbw_t cbw; /* command block wrapper */
186 umass_bbb_csw_t csw; /* command status wrapper*/
187 /* CBI specific variables for transfers in progress */
188 umass_cbi_cbl_t cbl; /* command block */
189 umass_cbi_sbl_t sbl; /* status block */
190
191 /* xfer handles
192 * Most of our operations are initiated from interrupt context, so
193 * we need to avoid using the one that is in use. We want to avoid
194 * allocating them in the interrupt context as well.
195 */
196 /* indices into array below */
197 #define XFER_BBB_CBW 0 /* Bulk-Only */
198 #define XFER_BBB_DATA 1
199 #define XFER_BBB_DCLEAR 2
200 #define XFER_BBB_CSW1 3
201 #define XFER_BBB_CSW2 4
202 #define XFER_BBB_SCLEAR 5
203 #define XFER_BBB_RESET1 6
204 #define XFER_BBB_RESET2 7
205 #define XFER_BBB_RESET3 8
206
207 #define XFER_CBI_CB 0 /* CBI */
208 #define XFER_CBI_DATA 1
209 #define XFER_CBI_STATUS 2
210 #define XFER_CBI_DCLEAR 3
211 #define XFER_CBI_SCLEAR 4
212 #define XFER_CBI_RESET1 5
213 #define XFER_CBI_RESET2 6
214 #define XFER_CBI_RESET3 7
215
216 #define XFER_NR 9 /* maximum number */
217
218 usbd_xfer_handle transfer_xfer[XFER_NR]; /* for ctrl xfers */
219
220 void *data_buffer;
221
222 int transfer_dir; /* data direction */
223 void *transfer_data; /* data buffer */
224 int transfer_datalen; /* (maximum) length */
225 int transfer_actlen; /* actual length */
226 umass_callback transfer_cb; /* callback */
227 void *transfer_priv; /* for callback */
228 int transfer_status;
229
230 int transfer_state;
231 #define TSTATE_IDLE 0
232 #define TSTATE_BBB_COMMAND 1 /* CBW transfer */
233 #define TSTATE_BBB_DATA 2 /* Data transfer */
234 #define TSTATE_BBB_DCLEAR 3 /* clear endpt stall */
235 #define TSTATE_BBB_STATUS1 4 /* clear endpt stall */
236 #define TSTATE_BBB_SCLEAR 5 /* clear endpt stall */
237 #define TSTATE_BBB_STATUS2 6 /* CSW transfer */
238 #define TSTATE_BBB_RESET1 7 /* reset command */
239 #define TSTATE_BBB_RESET2 8 /* in clear stall */
240 #define TSTATE_BBB_RESET3 9 /* out clear stall */
241 #define TSTATE_CBI_COMMAND 10 /* command transfer */
242 #define TSTATE_CBI_DATA 11 /* data transfer */
243 #define TSTATE_CBI_STATUS 12 /* status transfer */
244 #define TSTATE_CBI_DCLEAR 13 /* clear ep stall */
245 #define TSTATE_CBI_SCLEAR 14 /* clear ep stall */
246 #define TSTATE_CBI_RESET1 15 /* reset command */
247 #define TSTATE_CBI_RESET2 16 /* in clear stall */
248 #define TSTATE_CBI_RESET3 17 /* out clear stall */
249 #define TSTATE_STATES 18 /* # of states above */
250
251
252 int timeout; /* in msecs */
253
254 u_int8_t maxlun; /* max lun supported */
255
256 #ifdef UMASS_DEBUG
257 struct timeval tv;
258 #endif
259
260 int sc_xfer_flags;
261 char sc_dying;
262 int sc_refcnt;
263 int sc_sense;
264
265 struct umassbus_softc *bus; /* bus dependent data */
266 };
267
268 #define UMASS_MAX_TRANSFER_SIZE MAXPHYS
Cache object: 211bd064a3d7107ab80f69bccfd142d8
|