Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / usb / umassvar.h
blob70d703a6d561569701f53ec9b41cb49ecc7da685
1 /* $NetBSD: umassvar.h,v 1.27 2008/09/06 21:49:00 rmind Exp $ */
2 /*-
3 * Copyright (c) 1999 MAEKAWA Masahide <bishop@rr.iij4u.or.jp>,
4 * Nick Hibma <n_hibma@freebsd.org>
5 * All rights reserved.
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.
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.
28 * $FreeBSD: src/sys/dev/usb/umass.c,v 1.13 2000/03/26 01:39:12 n_hibma Exp $
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 */
44 #define UDMASS_XFER 0x40000000 /* all transfers */
45 #define UDMASS_CMD 0x80000000
47 extern int umassdebug;
48 #else
49 #define DIF(m, x) /* nop */
50 #define DPRINTF(m, x) /* nop */
51 #endif
53 /* Generic definitions */
55 #define UFI_COMMAND_LENGTH 12
57 /* Direction for umass_*_transfer */
58 #define DIR_NONE 0
59 #define DIR_IN 1
60 #define DIR_OUT 2
62 /* Endpoints for umass */
63 #define UMASS_BULKIN 0
64 #define UMASS_BULKOUT 1
65 #define UMASS_INTRIN 2
66 #define UMASS_NEP 3
68 /* Bulk-Only features */
70 #define UR_BBB_RESET 0xff /* Bulk-Only reset */
71 #define UR_BBB_GET_MAX_LUN 0xfe
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
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
103 /* CBI features */
105 #define UR_CBI_ADSC 0x00
107 typedef unsigned char umass_cbi_cbl_t[16]; /* Command block */
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;
121 struct {
122 uByte asc;
123 uByte ascq;
124 } ufi;
125 } umass_cbi_sbl_t;
127 struct umass_softc; /* see below */
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 */
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);
141 struct umass_wire_methods {
142 umass_wire_xfer wire_xfer;
143 umass_wire_reset wire_reset;
144 umass_wire_state wire_state;
147 struct umassbus_softc {
148 device_ptr_t sc_child; /* child device, for detach */
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 */
158 u_int8_t sc_epaddr[UMASS_NEP];
159 usbd_pipe_handle sc_pipe[UMASS_NEP];
160 usb_device_request_t sc_req;
162 const struct umass_wire_methods *sc_methods;
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
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
178 u_int32_t sc_quirks;
179 #define UMASS_QUIRK_WRONG_CSWSIG 0x00000001
180 #define UMASS_QUIRK_WRONG_CSWTAG 0x00000002
181 #define UMASS_QUIRK_RBC_PAD_TO_12 0x00000004
182 #define UMASS_QUIRK_NOGETMAXLUN 0x00000008
183 #define UMASS_QUIRK_IGNORE_RESIDUE 0x00000010
185 #define UMASS_QUIRK_USE_DEFAULTMATCH -1
187 u_int32_t sc_busquirks;
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 */
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.
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
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
221 #define XFER_NR 9 /* maximum number */
223 usbd_xfer_handle transfer_xfer[XFER_NR]; /* for ctrl xfers */
225 void *data_buffer;
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;
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 */
257 int timeout; /* in msecs */
259 u_int8_t maxlun; /* max lun supported */
261 #ifdef UMASS_DEBUG
262 struct timeval tv;
263 #endif
265 int sc_xfer_flags;
266 char sc_dying;
267 int sc_refcnt;
268 int sc_sense;
270 struct umassbus_softc *bus; /* bus dependent data */
273 #define UMASS_MAX_TRANSFER_SIZE MAXPHYS