2 * Copyright (c) 1999 MAEKAWA Masahide <bishop@rr.iij4u.or.jp>,
3 * Nick Hibma <n_hibma@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $NetBSD: umass.c,v 1.28 2000/04/02 23:46:53 augustss Exp $
28 * $FreeBSD: src/sys/dev/usb/umass.c,v 1.96 2003/12/19 12:19:11 sanpei Exp $
29 * $DragonFly: src/sys/dev/usbmisc/umass/umass.c,v 1.40 2008/08/16 21:42:19 thomas Exp $
33 * Universal Serial Bus Mass Storage Class specs:
34 * http://www.usb.org/developers/data/devclass/usbmassover_11.pdf
35 * http://www.usb.org/developers/data/devclass/usbmassbulk_10.pdf
36 * http://www.usb.org/developers/data/devclass/usbmass-cbi10.pdf
37 * http://www.usb.org/developers/data/devclass/usbmass-ufi10.pdf
41 * Ported to NetBSD by Lennart Augustsson <augustss@netbsd.org>.
42 * Parts of the code written my Jason R. Thorpe <thorpej@shagadelic.org>.
46 * The driver handles 3 Wire Protocols
47 * - Command/Bulk/Interrupt (CBI)
48 * - Command/Bulk/Interrupt with Command Completion Interrupt (CBI with CCI)
49 * - Mass Storage Bulk-Only (BBB)
50 * (BBB refers Bulk/Bulk/Bulk for Command/Data/Status phases)
52 * Over these wire protocols it handles the following command protocols
54 * - UFI (floppy command set)
57 * UFI and 8070i (ATAPI) are transformed versions of the SCSI command set. The
58 * sc->transform method is used to convert the commands into the appropriate
59 * format (if at all necessary). For example, UFI requires all commands to be
60 * 12 bytes in length amongst other things.
62 * The source code below is marked and can be split into a number of pieces
65 * - probe/attach/detach
66 * - generic transfer routines
69 * - CBI_I (in addition to functions from CBI)
70 * - CAM (Common Access Method)
75 * The protocols are implemented using a state machine, for the transfers as
76 * well as for the resets. The state machine is contained in umass_*_state.
77 * The state machine is started through either umass_*_transfer or
80 * The reason for doing this is a) CAM performs a lot better this way and b) it
81 * avoids using tsleep from interrupt context (for example after a failed
86 * The SCSI related part of this driver has been derived from the
87 * dev/ppbus/vpo.c driver, by Nicolas Souchu (nsouch@freebsd.org).
89 * The CAM layer uses so called actions which are messages sent to the host
90 * adapter for completion. The actions come in through umass_cam_action. The
91 * appropriate block of routines is called depending on the transport protocol
92 * in use. When the transfer has finished, these routines call
93 * umass_cam_cb again to complete the CAM command.
97 * XXX Currently CBI with CCI is not supported because it bombs the system
98 * when the device is detached (low frequency interrupts are detached
103 #include <sys/param.h>
104 #include <sys/systm.h>
105 #include <sys/kernel.h>
106 #include <sys/module.h>
108 #include <sys/sysctl.h>
110 #include <bus/usb/usb.h>
111 #include <bus/usb/usbdi.h>
112 #include <bus/usb/usbdi_util.h>
113 #include <bus/usb/usbdivar.h>
115 #include <bus/cam/cam.h>
116 #include <bus/cam/cam_ccb.h>
117 #include <bus/cam/cam_sim.h>
118 #include <bus/cam/cam_xpt_sim.h>
119 #include <bus/cam/scsi/scsi_all.h>
120 #include <bus/cam/scsi/scsi_da.h>
121 #include <bus/cam/scsi/scsi_cd.h>
122 #include <bus/cam/scsi/scsi_ch.h>
123 #include <dev/disk/ata/atapi-all.h>
125 #include <bus/cam/cam_periph.h>
128 #define DIF(m, x) if (umassdebug & (m)) do { x ; } while (0)
129 #define DPRINTF(m, x) if (umassdebug & (m)) kprintf x
130 #define UDMASS_GEN 0x00010000 /* general */
131 #define UDMASS_SCSI 0x00020000 /* scsi */
132 #define UDMASS_UFI 0x00040000 /* ufi command set */
133 #define UDMASS_ATAPI 0x00080000 /* 8070i command set */
134 #define UDMASS_CMD (UDMASS_SCSI|UDMASS_UFI|UDMASS_ATAPI)
135 #define UDMASS_USB 0x00100000 /* USB general */
136 #define UDMASS_BBB 0x00200000 /* Bulk-Only transfers */
137 #define UDMASS_CBI 0x00400000 /* CBI transfers */
138 #define UDMASS_WIRE (UDMASS_BBB|UDMASS_CBI)
139 #define UDMASS_ALL 0xffff0000 /* all of the above */
141 SYSCTL_NODE(_hw_usb
, OID_AUTO
, umass
, CTLFLAG_RW
, 0, "USB umass");
142 SYSCTL_INT(_hw_usb_umass
, OID_AUTO
, debug
, CTLFLAG_RW
,
143 &umassdebug
, 0, "umass debug level");
145 #define DIF(m, x) /* nop */
146 #define DPRINTF(m, x) /* nop */
150 /* Generic definitions */
152 /* Direction for umass_*_transfer */
158 #define DEVNAME "umass"
159 #define DEVNAME_SIM "umass-sim"
161 #define UMASS_MAX_TRANSFER_SIZE 65536
162 /* Approximate maximum transfer speeds (assumes 33% overhead). */
163 #define UMASS_FULL_TRANSFER_SPEED 1000
164 #define UMASS_HIGH_TRANSFER_SPEED 40000
165 #define UMASS_FLOPPY_TRANSFER_SPEED 20
167 #define UMASS_TIMEOUT 5000 /* msecs */
169 /* CAM specific definitions */
171 #define UMASS_SCSIID_MAX 1 /* maximum number of drives expected */
172 #define UMASS_SCSIID_HOST UMASS_SCSIID_MAX
174 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
177 /* Bulk-Only features */
179 #define UR_BBB_RESET 0xff /* Bulk-Only reset */
180 #define UR_BBB_GET_MAX_LUN 0xfe /* Get maximum lun */
182 /* Command Block Wrapper */
184 uDWord dCBWSignature
;
185 # define CBWSIGNATURE 0x43425355
187 uDWord dCBWDataTransferLength
;
189 # define CBWFLAGS_OUT 0x00
190 # define CBWFLAGS_IN 0x80
193 # define CBWCDBLENGTH 16
194 uByte CBWCDB
[CBWCDBLENGTH
];
196 #define UMASS_BBB_CBW_SIZE 31
198 /* Command Status Wrapper */
200 uDWord dCSWSignature
;
201 # define CSWSIGNATURE 0x53425355
202 # define CSWSIGNATURE_OLYMPUS_C1 0x55425355
204 uDWord dCSWDataResidue
;
206 # define CSWSTATUS_GOOD 0x0
207 # define CSWSTATUS_FAILED 0x1
208 # define CSWSTATUS_PHASE 0x2
210 #define UMASS_BBB_CSW_SIZE 13
214 #define UR_CBI_ADSC 0x00
216 typedef unsigned char umass_cbi_cbl_t
[16]; /* Command block */
221 #define IDB_TYPE_CCI 0x00
223 #define IDB_VALUE_PASS 0x00
224 #define IDB_VALUE_FAIL 0x01
225 #define IDB_VALUE_PHASE 0x02
226 #define IDB_VALUE_PERSISTENT 0x03
227 #define IDB_VALUE_STATUS_MASK 0x03
238 struct umass_softc
; /* see below */
240 typedef void (*transfer_cb_f
) (struct umass_softc
*sc
, void *priv
,
241 int residue
, int status
);
242 #define STATUS_CMD_OK 0 /* everything ok */
243 #define STATUS_CMD_UNKNOWN 1 /* will have to fetch sense */
244 #define STATUS_CMD_FAILED 2 /* transfer was ok, command failed */
245 #define STATUS_WIRE_FAILED 3 /* couldn't even get command across */
247 typedef void (*wire_reset_f
) (struct umass_softc
*sc
, int status
);
248 typedef void (*wire_transfer_f
) (struct umass_softc
*sc
, int lun
,
249 void *cmd
, int cmdlen
, void *data
, int datalen
,
250 int dir
, u_int timeout
, transfer_cb_f cb
, void *priv
);
251 typedef void (*wire_state_f
) (usbd_xfer_handle xfer
,
252 usbd_private_handle priv
, usbd_status err
);
254 typedef int (*command_transform_f
) (struct umass_softc
*sc
,
255 unsigned char *cmd
, int cmdlen
,
256 unsigned char **rcmd
, int *rcmdlen
);
259 struct umass_devdescr_t
{
263 # define WILDCARD_ID 0xffffffff
264 # define EOT_ID 0xfffffffe
266 /* wire and command protocol */
268 # define UMASS_PROTO_BBB 0x0001 /* USB wire protocol */
269 # define UMASS_PROTO_CBI 0x0002
270 # define UMASS_PROTO_CBI_I 0x0004
271 # define UMASS_PROTO_WIRE 0x00ff /* USB wire protocol mask */
272 # define UMASS_PROTO_SCSI 0x0100 /* command protocol */
273 # define UMASS_PROTO_ATAPI 0x0200
274 # define UMASS_PROTO_UFI 0x0400
275 # define UMASS_PROTO_RBC 0x0800
276 # define UMASS_PROTO_COMMAND 0xff00 /* command protocol mask */
278 /* Device specific quirks */
280 # define NO_QUIRKS 0x0000
281 /* The drive does not support Test Unit Ready. Convert to Start Unit
283 # define NO_TEST_UNIT_READY 0x0001
284 /* The drive does not reset the Unit Attention state after REQUEST
285 * SENSE has been sent. The INQUIRY command does not reset the UA
286 * either, and so CAM runs in circles trying to retrieve the initial
289 # define RS_NO_CLEAR_UA 0x0002
290 /* The drive does not support START STOP. */
291 # define NO_START_STOP 0x0004
292 /* Don't ask for full inquiry data (255b). */
293 # define FORCE_SHORT_INQUIRY 0x0008
294 /* Needs to be initialised the Shuttle way */
295 # define SHUTTLE_INIT 0x0010
296 /* Drive needs to be switched to alternate iface 1 */
297 # define ALT_IFACE_1 0x0020
298 /* Drive does not do 1Mb/s, but just floppy speeds (20kb/s) */
299 # define FLOPPY_SPEED 0x0040
300 /* The device can't count and gets the residue of transfers wrong */
301 # define IGNORE_RESIDUE 0x0080
302 /* No GetMaxLun call */
303 # define NO_GETMAXLUN 0x0100
304 /* The device uses a weird CSWSIGNATURE. */
305 # define WRONG_CSWSIG 0x0200
306 /* Device cannot handle INQUIRY so fake a generic response */
307 # define NO_INQUIRY 0x0400
308 /* Device cannot handle INQUIRY EVPD, return CHECK CONDITION */
309 # define NO_INQUIRY_EVPD 0x0800
310 # define READ_CAPACITY_OFFBY1 0x2000
313 static struct umass_devdescr_t umass_devdescrs
[] = {
314 /* Addonics Cable 205 */
315 { .vendor
= 0x0bf6, .product
= 0xa001, .release
= WILDCARD_ID
,
316 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
319 /* Addonics USB 2.0 Flash */
320 { .vendor
= 0x09df, .product
= 0x1300, .release
= WILDCARD_ID
,
321 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
322 .quirks
= IGNORE_RESIDUE
324 /* Addonics Attache 256MB USB */
325 { .vendor
= 0x09df, .product
= 0x1400, .release
= WILDCARD_ID
,
326 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
327 .quirks
= IGNORE_RESIDUE
329 /* Addonics USB 2.0 Flash */
330 { .vendor
= 0x09df, .product
= 0x1420, .release
= WILDCARD_ID
,
331 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
332 .quirks
= IGNORE_RESIDUE
334 /* AIPTEK PocketCAM 3Mega */
335 { .vendor
= 0x08ca, .product
= 0x2011, .release
= WILDCARD_ID
,
336 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
339 /* All Asahi Optical products */
340 { .vendor
= 0x0a17, .product
= WILDCARD_ID
, .release
= WILDCARD_ID
,
341 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI_I
,
342 .quirks
= RS_NO_CLEAR_UA
344 /* Belkin USB to SCSI */
345 { .vendor
= 0x050d, .product
= 0x0115, .release
= WILDCARD_ID
,
346 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
349 /* CASIO QV DigiCam */
350 { .vendor
= 0x07cf, .product
= 0x1001, .release
= WILDCARD_ID
,
351 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_CBI
,
354 /* CCYU EasyDisk ED1064 */
355 { .vendor
= 0x1065, .product
= 0x2136, .release
= WILDCARD_ID
,
356 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
359 /* Century Century USB Disk */
360 { .vendor
= 0x07f7, .product
= 0x011e, .release
= WILDCARD_ID
,
361 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
362 .quirks
= FORCE_SHORT_INQUIRY
| NO_START_STOP
| IGNORE_RESIDUE
364 /* Desknote UCR-61S2B */
365 { .vendor
= 0x1019, .product
= 0x0c55, .release
= WILDCARD_ID
,
366 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
369 /* DMI CF/SM Reader/Writer */
370 { .vendor
= 0x0c0b, .product
= 0xa109, .release
= WILDCARD_ID
,
371 .proto
= UMASS_PROTO_SCSI
,
372 .quirks
= NO_GETMAXLUN
374 /* Epson Stylus Photo 875DC */
375 { .vendor
= 0x03f8, .product
= 0x0601, .release
= WILDCARD_ID
,
376 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_CBI
,
379 /* Epson Stylus Photo 895 */
380 { .vendor
= 0x03f8, .product
= 0x0602, .release
= WILDCARD_ID
,
381 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
382 .quirks
= NO_GETMAXLUN
384 /* Feiya 5-in-1 Card Reader */
385 { .vendor
= 0x090c, .product
= 0x1132, .release
= WILDCARD_ID
,
386 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
389 /* Freecom DVD drive */
390 { .vendor
= 0x07ab, .product
= 0xfc01, .release
= WILDCARD_ID
,
391 .proto
= UMASS_PROTO_SCSI
,
394 /* Fujiphoto mass storage products */
395 { .vendor
= 0x04cb, .product
= 0x0100, .release
= WILDCARD_ID
,
396 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI_I
,
397 .quirks
= RS_NO_CLEAR_UA
399 /* Genesys GL641USB USB-IDE Bridge */
400 { .vendor
= 0x05e3, .product
= 0x0701, .release
= WILDCARD_ID
,
401 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
402 .quirks
= FORCE_SHORT_INQUIRY
| NO_START_STOP
| IGNORE_RESIDUE
404 /* Genesys GL641USB USB-IDE Bridge */
405 { .vendor
= 0x05e3, .product
= 0x0702, .release
= WILDCARD_ID
,
406 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
407 .quirks
= FORCE_SHORT_INQUIRY
| NO_START_STOP
| IGNORE_RESIDUE
409 /* Genesys GL641USB CompactFlash Card */
410 { .vendor
= 0x05e3, .product
= 0x0700, .release
= WILDCARD_ID
,
411 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
412 .quirks
= FORCE_SHORT_INQUIRY
| NO_START_STOP
| IGNORE_RESIDUE
414 /* Genesys GL641USB 6-in-1 Card */
415 { .vendor
= 0x05e3, .product
= 0x0760, .release
= WILDCARD_ID
,
416 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
417 .quirks
= WRONG_CSWSIG
419 /* Hagiwara FlashGate SmartMedia Card */
420 { .vendor
= 0x0693, .product
= 0x0002, .release
= WILDCARD_ID
,
421 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
424 /* Hitachi DVDCAM USB HS Interface */
425 { .vendor
= 0x04a4, .product
= 0x001e, .release
= WILDCARD_ID
,
426 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI_I
,
429 /* Hitachi DVD-CAM DZ-MV100A Camcorder */
430 { .vendor
= 0x04a4, .product
= 0x0004, .release
= WILDCARD_ID
,
431 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_CBI
,
432 .quirks
= NO_GETMAXLUN
434 /* Hewlett CD-Writer+ CD-4e */
435 { .vendor
= 0x03f0, .product
= 0x0307, .release
= WILDCARD_ID
,
436 .proto
= UMASS_PROTO_ATAPI
,
439 /* Hewlett CD-Writer Plus 8200e */
440 { .vendor
= 0x03f0, .product
= 0x0207, .release
= WILDCARD_ID
,
441 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI_I
,
442 .quirks
= NO_TEST_UNIT_READY
| NO_START_STOP
444 /* Imagination DBX1 DSP core */
445 { .vendor
= 0x149a, .product
= 0x2107, .release
= WILDCARD_ID
,
446 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
447 .quirks
= WRONG_CSWSIG
449 /* In-System ATAPI Adapter */
450 { .vendor
= 0x05ab, .product
= 0x0031, .release
= WILDCARD_ID
,
451 .proto
= UMASS_PROTO_RBC
| UMASS_PROTO_CBI
,
454 /* In-System USB Storage Adapter */
455 { .vendor
= 0x05ab, .product
= 0x5701, .release
= WILDCARD_ID
,
456 .proto
= UMASS_PROTO_RBC
| UMASS_PROTO_CBI
,
459 /* In-System USB cable */
460 { .vendor
= 0x05ab, .product
= 0x081a, .release
= WILDCARD_ID
,
461 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI
,
462 .quirks
= NO_TEST_UNIT_READY
| NO_START_STOP
| ALT_IFACE_1
464 /* I-O DVD Multi-plus unit */
465 { .vendor
= 0x04bb, .product
= 0x0204, .release
= WILDCARD_ID
,
466 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
469 /* I-O DVD Multi-plus unit */
470 { .vendor
= 0x04bb, .product
= 0x0206, .release
= WILDCARD_ID
,
471 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
475 { .vendor
= 0x059b, .product
= 0x0001, .release
= WILDCARD_ID
,
476 /* XXX This is not correct as there are Zip drives that use ATAPI. */
477 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
478 .quirks
= NO_TEST_UNIT_READY
480 /* Kyocera Finecam L3 */
481 { .vendor
= 0x0482, .product
= 0x0105, .release
= WILDCARD_ID
,
482 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
485 /* Kyocera Finecam S3x */
486 { .vendor
= 0x0482, .product
= 0x0100, .release
= WILDCARD_ID
,
487 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI
,
490 /* Kyocera Finecam S4 */
491 { .vendor
= 0x0482, .product
= 0x0101, .release
= WILDCARD_ID
,
492 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI
,
495 /* Kyocera Finecam S5 */
496 { .vendor
= 0x0482, .product
= 0x0103, .release
= WILDCARD_ID
,
497 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
500 /* LaCie Hard Disk */
501 { .vendor
= 0x059f, .product
= 0xa601, .release
= WILDCARD_ID
,
502 .proto
= UMASS_PROTO_RBC
| UMASS_PROTO_CBI
,
505 /* Lexar USB CF Reader */
506 { .vendor
= 0x05dc, .product
= 0xb002, .release
= WILDCARD_ID
,
507 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
510 /* Lexar jumpSHOT CompactFlash Reader */
511 { .vendor
= 0x05dc, .product
= 0x0001, .release
= WILDCARD_ID
,
512 .proto
= UMASS_PROTO_SCSI
,
515 /* Logitech DVD Multi-plus unit */
516 { .vendor
= 0x046d, .product
= 0x0033, .release
= WILDCARD_ID
,
517 .proto
= UMASS_PROTO_SCSI
,
520 /* Logitech DVD Multi-plus unit LDR-H443U2 */
521 { .vendor
= 0x0789, .product
= 0x00b3, .release
= WILDCARD_ID
,
522 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
525 /* Melco USB-IDE Bridge: DUB-PxxG */
526 { .vendor
= 0x0411, .product
= 0x001c, .release
= WILDCARD_ID
,
527 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
528 .quirks
= FORCE_SHORT_INQUIRY
| NO_START_STOP
| IGNORE_RESIDUE
530 /* Microtech USB CameraMate */
531 { .vendor
= 0x07af, .product
= 0x0006, .release
= WILDCARD_ID
,
532 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_CBI
,
533 .quirks
= NO_TEST_UNIT_READY
| NO_START_STOP
535 /* Microtech USB-SCSI-DB25 */
536 { .vendor
= 0x07af, .product
= 0x0004, .release
= WILDCARD_ID
,
537 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
540 /* Microtech USB-SCSI-HD50 */
541 { .vendor
= 0x07af, .product
= 0x0005, .release
= WILDCARD_ID
,
542 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
545 /* Minolta Dimage E223 */
546 { .vendor
= 0x0686, .product
= 0x4017, .release
= WILDCARD_ID
,
547 .proto
= UMASS_PROTO_SCSI
,
550 /* Minolta Dimage F300 */
551 { .vendor
= 0x0686, .product
= 0x4011, .release
= WILDCARD_ID
,
552 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
555 /* Mitsumi CD-R/RW Drive */
556 { .vendor
= 0x03ee, .product
= 0x0000, .release
= WILDCARD_ID
,
557 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI
,
560 /* Mitsumi USB FDD */
561 { .vendor
= 0x03ee, .product
= 0x6901, .release
= WILDCARD_ID
,
562 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
563 .quirks
= NO_GETMAXLUN
565 /* Motorola E398 Mobile Phone */
566 { .vendor
= 0x22b8, .product
= 0x4810, .release
= WILDCARD_ID
,
567 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
568 .quirks
= FORCE_SHORT_INQUIRY
| NO_INQUIRY_EVPD
| NO_GETMAXLUN
570 /* M-Systems DiskOnKey */
571 { .vendor
= 0x08ec, .product
= 0x0010, .release
= WILDCARD_ID
,
572 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
573 .quirks
= IGNORE_RESIDUE
| NO_GETMAXLUN
| RS_NO_CLEAR_UA
575 /* M-Systems DiskOnKey */
576 { .vendor
= 0x08ec, .product
= 0x0011, .release
= WILDCARD_ID
,
577 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_BBB
,
581 { .vendor
= 0x04cf, .product
= 0x8818, .release
= WILDCARD_ID
,
582 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
583 .quirks
= NO_INQUIRY
| IGNORE_RESIDUE
585 /* Neodio 8-in-1 Multi-format Flash */
586 { .vendor
= 0x0aec, .product
= 0x3260, .release
= WILDCARD_ID
,
587 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
588 .quirks
= FORCE_SHORT_INQUIRY
590 /* Netac USB-CF-Card */
591 { .vendor
= 0x0dd8, .product
= 0x1060, .release
= WILDCARD_ID
,
592 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
596 { .vendor
= 0x0dd8, .product
= 0x0003, .release
= WILDCARD_ID
,
597 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
598 .quirks
= IGNORE_RESIDUE
600 /* NetChip USB Clik! 40 */
601 { .vendor
= 0x0525, .product
= 0xa140, .release
= WILDCARD_ID
,
602 .proto
= UMASS_PROTO_ATAPI
,
605 /* Olympus C-1 Digital Camera */
606 { .vendor
= 0x07b4, .product
= 0x0102, .release
= WILDCARD_ID
,
607 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
608 .quirks
= WRONG_CSWSIG
610 /* Olympus C-700 Ultra Zoom */
611 { .vendor
= 0x07b4, .product
= 0x0105, .release
= WILDCARD_ID
,
612 .proto
= UMASS_PROTO_SCSI
,
613 .quirks
= NO_GETMAXLUN
615 /* OnSpec SIIG/Datafab Memory Stick+CF */
616 { .vendor
= 0x07c4, .product
= 0xa001, .release
= WILDCARD_ID
,
617 .proto
= UMASS_PROTO_SCSI
,
620 /* OnSpec USB to CF */
621 { .vendor
= 0x07c4, .product
= 0xa109, .release
= WILDCARD_ID
,
622 .proto
= UMASS_PROTO_SCSI
,
625 /* OnSpec PNY/Datafab CF+SM Reader */
626 { .vendor
= 0x07c4, .product
= 0xa005, .release
= WILDCARD_ID
,
627 .proto
= UMASS_PROTO_SCSI
,
630 /* OnSpec Simple Tech/Datafab CF+SM */
631 { .vendor
= 0x07c4, .product
= 0xa006, .release
= WILDCARD_ID
,
632 .proto
= UMASS_PROTO_SCSI
,
635 /* OnSpec MDCFE-B USB CF */
636 { .vendor
= 0x07c4, .product
= 0xa000, .release
= WILDCARD_ID
,
637 .proto
= UMASS_PROTO_SCSI
,
640 /* OnSpec MDSM-B reader */
641 { .vendor
= 0x07c4, .product
= 0xa103, .release
= WILDCARD_ID
,
642 .proto
= UMASS_PROTO_SCSI
,
645 /* OnSpec Datafab-based Reader */
646 { .vendor
= 0x07c4, .product
= 0xa003, .release
= WILDCARD_ID
,
647 .proto
= UMASS_PROTO_SCSI
,
650 /* OnSpec FlashLink UCF-100 CompactFlash */
651 { .vendor
= 0x07c4, .product
= 0xa400, .release
= WILDCARD_ID
,
652 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_BBB
,
653 .quirks
= NO_INQUIRY
| NO_GETMAXLUN
655 /* OnSpec ImageMate SDDR55 */
656 { .vendor
= 0x55aa, .product
= 0xa103, .release
= WILDCARD_ID
,
657 .proto
= UMASS_PROTO_SCSI
,
658 .quirks
= NO_GETMAXLUN
660 /* Panasonic CD-R Drive KXL-840AN */
661 { .vendor
= 0x04da, .product
= 0x0d01, .release
= WILDCARD_ID
,
662 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_BBB
,
663 .quirks
= NO_GETMAXLUN
665 /* Panasonic CD-R Drive KXL-CB20AN */
666 { .vendor
= 0x04da, .product
= 0x0d0a, .release
= WILDCARD_ID
,
667 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
670 /* Panasonic DVD-ROM & CD-R/RW */
671 { .vendor
= 0x04da, .product
= 0x0d0e, .release
= WILDCARD_ID
,
672 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
675 /* Panasonic LS-120 Camera */
676 { .vendor
= 0x04da, .product
= 0x0901, .release
= WILDCARD_ID
,
677 .proto
= UMASS_PROTO_UFI
,
680 /* Plextor PlexWriter 40/12/40U */
681 { .vendor
= 0x093b, .product
= 0x0011, .release
= WILDCARD_ID
,
682 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
683 .quirks
= NO_TEST_UNIT_READY
685 /* PNY USB 2.0 Flash */
686 { .vendor
= 0x154b, .product
= 0x0010, .release
= WILDCARD_ID
,
687 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
688 .quirks
= IGNORE_RESIDUE
| NO_START_STOP
690 /* Pen USB 2.0 Flash Drive */
691 { .vendor
= 0x0d7d, .product
= 0x1300, .release
= WILDCARD_ID
,
692 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
693 .quirks
= IGNORE_RESIDUE
695 /* Samsung YP-U2 MP3 Player */
696 { .vendor
= 0x04e8, .product
= 0x5050, .release
= WILDCARD_ID
,
697 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
698 .quirks
= SHUTTLE_INIT
| NO_GETMAXLUN
700 /* Samsung Digimax 410 */
701 { .vendor
= 0x0839, .product
= 0x000a, .release
= WILDCARD_ID
,
702 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
705 /* SanDisk ImageMate SDDR-05a */
706 { .vendor
= 0x0781, .product
= 0x0001, .release
= WILDCARD_ID
,
707 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_CBI
,
708 .quirks
= READ_CAPACITY_OFFBY1
| NO_GETMAXLUN
710 /* SanDisk ImageMate SDDR-09 */
711 { .vendor
= 0x0781, .product
= 0x0200, .release
= WILDCARD_ID
,
712 .proto
= UMASS_PROTO_SCSI
,
713 .quirks
= READ_CAPACITY_OFFBY1
| NO_GETMAXLUN
715 /* SanDisk ImageMate SDDR-12 */
716 { .vendor
= 0x0781, .product
= 0x0100, .release
= WILDCARD_ID
,
717 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_CBI
,
718 .quirks
= READ_CAPACITY_OFFBY1
| NO_GETMAXLUN
720 /* SanDisk ImageMate SDDR-31 */
721 { .vendor
= 0x0781, .product
= 0x0002, .release
= WILDCARD_ID
,
722 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
723 .quirks
= READ_CAPACITY_OFFBY1
725 /* SanDisk Cruzer Mini 256MB */
726 { .vendor
= 0x0781, .product
= 0x7104, .release
= WILDCARD_ID
,
727 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
728 .quirks
= IGNORE_RESIDUE
730 /* SanDisk Cruzer Micro 128MB */
731 { .vendor
= 0x0781, .product
= 0x7112, .release
= WILDCARD_ID
,
732 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
733 .quirks
= IGNORE_RESIDUE
735 /* SanDisk Cruzer Micro 256MB */
736 { .vendor
= 0x0781, .product
= 0x7113, .release
= WILDCARD_ID
,
737 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
738 .quirks
= IGNORE_RESIDUE
740 /* ScanLogic SL11R IDE Adapter */
741 { .vendor
= 0x04ce, .product
= 0x0002, .release
= WILDCARD_ID
,
742 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI_I
,
745 /* Shuttle CD-RW Device */
746 { .vendor
= 0x04e6, .product
= 0x0101, .release
= WILDCARD_ID
,
747 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI
,
750 /* Shuttle eUSB CompactFlash Adapter */
751 { .vendor
= 0x04e6, .product
= 0x000a, .release
= WILDCARD_ID
,
752 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI
,
755 /* Shuttle E-USB Bridge */
756 { .vendor
= 0x04e6, .product
= 0x0001, .release
= WILDCARD_ID
,
757 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI_I
,
758 .quirks
= NO_TEST_UNIT_READY
| NO_START_STOP
| SHUTTLE_INIT
760 /* Shuttle eUSB ATA/ATAPI Adapter */
761 { .vendor
= 0x04e6, .product
= 0x0009, .release
= WILDCARD_ID
,
762 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI
,
765 /* Shuttle eUSB SmartMedia / */
766 { .vendor
= 0x04e6, .product
= 0x0005, .release
= WILDCARD_ID
,
767 .proto
= UMASS_PROTO_SCSI
,
770 /* Shuttle eUSCSI Bridge */
771 { .vendor
= 0x04e6, .product
= 0x0002, .release
= WILDCARD_ID
,
772 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
775 /* Shuttle Sony Hifd */
776 { .vendor
= 0x04e6, .product
= 0x0007, .release
= WILDCARD_ID
,
777 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_CBI
,
778 .quirks
= NO_GETMAXLUN
780 /* Shuttle ImageMate SDDR09 */
781 { .vendor
= 0x04e6, .product
= 0x0003, .release
= WILDCARD_ID
,
782 .proto
= UMASS_PROTO_SCSI
,
783 .quirks
= NO_GETMAXLUN
785 /* Shuttle eUSB MultiMediaCard Adapter */
786 { .vendor
= 0x04e6, .product
= 0x0006, .release
= WILDCARD_ID
,
787 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_CBI
,
788 .quirks
= NO_GETMAXLUN
790 /* Sigmatel i-Bead 100 MP3 */
791 { .vendor
= 0x066f, .product
= 0x8008, .release
= WILDCARD_ID
,
792 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
793 .quirks
= SHUTTLE_INIT
795 /* SIIG WINTERREADER Reader */
796 { .vendor
= 0x07cc, .product
= 0x0330, .release
= WILDCARD_ID
,
797 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
798 .quirks
= IGNORE_RESIDUE
800 /* Skanhex MD 7425 Camera */
801 { .vendor
= 0x0d96, .product
= 0x410a, .release
= WILDCARD_ID
,
802 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
805 /* Skanhex SX 520z Camera */
806 { .vendor
= 0x0d96, .product
= 0x5200, .release
= WILDCARD_ID
,
807 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
811 { .vendor
= 0x054c, .product
= 0x006d, .release
= WILDCARD_ID
,
812 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
815 /* Sony DSC cameras */
816 { .vendor
= 0x054c, .product
= 0x0010, .release
= WILDCARD_ID
,
817 .proto
= UMASS_PROTO_RBC
| UMASS_PROTO_CBI
,
821 { .vendor
= 0x054c, .product
= 0x002e, .release
= WILDCARD_ID
,
822 .proto
= UMASS_PROTO_RBC
| UMASS_PROTO_CBI
,
825 /* Sony Memorystick MSC-U03 */
826 { .vendor
= 0x054c, .product
= 0x0069, .release
= WILDCARD_ID
,
827 .proto
= UMASS_PROTO_UFI
| UMASS_PROTO_CBI
,
828 .quirks
= NO_GETMAXLUN
830 /* Sony Memorystick NW-MS7 */
831 { .vendor
= 0x054c, .product
= 0x0025, .release
= WILDCARD_ID
,
832 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
833 .quirks
= NO_GETMAXLUN
835 /* Sony PEG N760c Memorystick */
836 { .vendor
= 0x054c, .product
= 0x0058, .release
= WILDCARD_ID
,
837 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
840 /* Sony Memorystick MSAC-US1 */
841 { .vendor
= 0x054c, .product
= 0x002d, .release
= WILDCARD_ID
,
842 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
843 .quirks
= NO_GETMAXLUN
845 /* Sony MSC memory stick */
846 { .vendor
= 0x054c, .product
= 0x0032, .release
= WILDCARD_ID
,
847 .proto
= UMASS_PROTO_RBC
| UMASS_PROTO_CBI
,
850 /* Sony Portable USB Harddrive */
851 { .vendor
= 0x054c, .product
= 0x002b, .release
= WILDCARD_ID
,
852 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
855 /* Taugagreining CameraMate (DPCM_USB) */
856 { .vendor
= 0x0436, .product
= 0x0005, .release
= WILDCARD_ID
,
857 .proto
= UMASS_PROTO_SCSI
,
860 /* TEAC FD-05PUB floppy */
861 { .vendor
= 0x0644, .product
= 0x0000, .release
= WILDCARD_ID
,
862 .proto
= UMASS_PROTO_UFI
| UMASS_PROTO_CBI
,
865 /* Trek IBM USB Memory */
866 { .vendor
= 0x0a16, .product
= 0x8888, .release
= WILDCARD_ID
,
867 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
870 /* Trek ThumbDrive_8MB */
871 { .vendor
= 0x0a16, .product
= 0x9988, .release
= WILDCARD_ID
,
872 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_BBB
,
873 .quirks
= IGNORE_RESIDUE
875 /* Trumpion Comotron C3310 MP3 */
876 { .vendor
= 0x090a, .product
= 0x1100, .release
= WILDCARD_ID
,
877 .proto
= UMASS_PROTO_UFI
| UMASS_PROTO_CBI
,
880 /* Trumpion MP3 player */
881 { .vendor
= 0x090a, .product
= 0x1200, .release
= WILDCARD_ID
,
882 .proto
= UMASS_PROTO_RBC
,
885 /* Trumpion T33520 USB Flash */
886 { .vendor
= 0x090a, .product
= 0x1001, .release
= WILDCARD_ID
,
887 .proto
= UMASS_PROTO_SCSI
,
890 /* TwinMOS Memory Disk IV */
891 { .vendor
= 0x126f, .product
= 0x1325, .release
= WILDCARD_ID
,
892 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
895 /* Vivitar Vivicam 35Xx */
896 { .vendor
= 0x0636, .product
= 0x0003, .release
= WILDCARD_ID
,
897 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
900 /* Western Firewire USB Combo */
901 { .vendor
= 0x1058, .product
= 0x0200, .release
= WILDCARD_ID
,
902 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
903 .quirks
= FORCE_SHORT_INQUIRY
| NO_START_STOP
| IGNORE_RESIDUE
905 /* Western External HDD */
906 { .vendor
= 0x1058, .product
= 0x0400, .release
= WILDCARD_ID
,
907 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
908 .quirks
= FORCE_SHORT_INQUIRY
| NO_START_STOP
| IGNORE_RESIDUE
910 /* Western MyBook External HDD */
911 { .vendor
= 0x1058, .product
= 0x0901, .release
= WILDCARD_ID
,
912 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
913 .quirks
= NO_INQUIRY_EVPD
915 /* WinMaxGroup USB Flash Disk */
916 { .vendor
= 0x0ed1, .product
= 0x6660, .release
= WILDCARD_ID
,
917 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
920 /* Yano METALWEAR-HDD */
921 { .vendor
= 0x094f, .product
= 0x05fc, .release
= WILDCARD_ID
,
922 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_BBB
,
923 .quirks
= FORCE_SHORT_INQUIRY
| NO_START_STOP
| IGNORE_RESIDUE
926 { .vendor
= 0x094f, .product
= 0x0101, .release
= WILDCARD_ID
,
927 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI_I
,
928 .quirks
= FORCE_SHORT_INQUIRY
930 /* Y-E Flashbuster-U */
931 { .vendor
= 0x057b, .product
= 0x0000, .release
= WILDCARD_ID
,
932 .proto
= UMASS_PROTO_SCSI
| UMASS_PROTO_CBI
,
933 .quirks
= NO_GETMAXLUN
935 /* Zoran Digital Camera EX-20 */
936 { .vendor
= 0x0595, .product
= 0x4343, .release
= WILDCARD_ID
,
937 .proto
= UMASS_PROTO_ATAPI
| UMASS_PROTO_CBI
,
940 { .vendor
= EOT_ID
, .product
= EOT_ID
, .release
= EOT_ID
,
941 .proto
= 0, .quirks
= 0 }
945 /* the per device structure */
947 device_t sc_dev
; /* base device */
948 usbd_device_handle sc_udev
; /* USB device */
950 struct cam_sim
*umass_sim
; /* SCSI Interface Module */
952 unsigned char flags
; /* various device flags */
953 # define UMASS_FLAGS_GONE 0x01 /* devices is no more */
955 u_int16_t proto
; /* wire and cmd protocol */
956 u_int16_t quirks
; /* they got it almost right */
958 usbd_interface_handle iface
; /* Mass Storage interface */
959 int ifaceno
; /* MS iface number */
961 u_int8_t bulkin
; /* bulk-in Endpoint Address */
962 u_int8_t bulkout
; /* bulk-out Endpoint Address */
963 u_int8_t intrin
; /* intr-in Endp. (CBI) */
964 usbd_pipe_handle bulkin_pipe
;
965 usbd_pipe_handle bulkout_pipe
;
966 usbd_pipe_handle intrin_pipe
;
968 /* Reset the device in a wire protocol specific way */
971 /* The start of a wire transfer. It prepares the whole transfer (cmd,
972 * data, and status stage) and initiates it. It is up to the state
973 * machine (below) to handle the various stages and errors in these
975 wire_transfer_f transfer
;
977 /* The state machine, handling the various states during a transfer */
980 /* The command transform function is used to conver the SCSI commands
981 * into their derivatives, like UFI, ATAPI, and friends.
983 command_transform_f transform
; /* command transform */
985 /* Bulk specific variables for transfers in progress */
986 umass_bbb_cbw_t cbw
; /* command block wrapper */
987 umass_bbb_csw_t csw
; /* command status wrapper*/
988 /* CBI specific variables for transfers in progress */
989 umass_cbi_cbl_t cbl
; /* command block */
990 umass_cbi_sbl_t sbl
; /* status block */
992 /* generic variables for transfers in progress */
993 /* ctrl transfer requests */
994 usb_device_request_t request
;
997 * Most of our operations are initiated from interrupt context, so
998 * we need to avoid using the one that is in use. We want to avoid
999 * allocating them in the interrupt context as well.
1001 /* indices into array below */
1002 # define XFER_BBB_CBW 0 /* Bulk-Only */
1003 # define XFER_BBB_DATA 1
1004 # define XFER_BBB_DCLEAR 2
1005 # define XFER_BBB_CSW1 3
1006 # define XFER_BBB_CSW2 4
1007 # define XFER_BBB_SCLEAR 5
1008 # define XFER_BBB_RESET1 6
1009 # define XFER_BBB_RESET2 7
1010 # define XFER_BBB_RESET3 8
1012 # define XFER_CBI_CB 0 /* CBI */
1013 # define XFER_CBI_DATA 1
1014 # define XFER_CBI_STATUS 2
1015 # define XFER_CBI_DCLEAR 3
1016 # define XFER_CBI_SCLEAR 4
1017 # define XFER_CBI_RESET1 5
1018 # define XFER_CBI_RESET2 6
1019 # define XFER_CBI_RESET3 7
1021 # define XFER_NR 9 /* maximum number */
1023 usbd_xfer_handle transfer_xfer
[XFER_NR
]; /* for ctrl xfers */
1025 int transfer_dir
; /* data direction */
1026 void *transfer_data
; /* data buffer */
1027 int transfer_datalen
; /* (maximum) length */
1028 int transfer_actlen
; /* actual length */
1029 transfer_cb_f transfer_cb
; /* callback */
1030 void *transfer_priv
; /* for callback */
1031 int transfer_status
;
1034 # define TSTATE_ATTACH 0 /* in attach */
1035 # define TSTATE_IDLE 1
1036 # define TSTATE_BBB_COMMAND 2 /* CBW transfer */
1037 # define TSTATE_BBB_DATA 3 /* Data transfer */
1038 # define TSTATE_BBB_DCLEAR 4 /* clear endpt stall */
1039 # define TSTATE_BBB_STATUS1 5 /* clear endpt stall */
1040 # define TSTATE_BBB_SCLEAR 6 /* clear endpt stall */
1041 # define TSTATE_BBB_STATUS2 7 /* CSW transfer */
1042 # define TSTATE_BBB_RESET1 8 /* reset command */
1043 # define TSTATE_BBB_RESET2 9 /* in clear stall */
1044 # define TSTATE_BBB_RESET3 10 /* out clear stall */
1045 # define TSTATE_CBI_COMMAND 11 /* command transfer */
1046 # define TSTATE_CBI_DATA 12 /* data transfer */
1047 # define TSTATE_CBI_STATUS 13 /* status transfer */
1048 # define TSTATE_CBI_DCLEAR 14 /* clear ep stall */
1049 # define TSTATE_CBI_SCLEAR 15 /* clear ep stall */
1050 # define TSTATE_CBI_RESET1 16 /* reset command */
1051 # define TSTATE_CBI_RESET2 17 /* in clear stall */
1052 # define TSTATE_CBI_RESET3 18 /* out clear stall */
1053 # define TSTATE_STATES 19 /* # of states above */
1056 /* SCSI/CAM specific variables */
1057 unsigned char cam_scsi_command
[CAM_MAX_CDBLEN
];
1058 unsigned char cam_scsi_command2
[CAM_MAX_CDBLEN
];
1059 struct scsi_sense cam_scsi_sense
;
1060 struct scsi_sense cam_scsi_test_unit_ready
;
1061 int timeout
; /* in msecs */
1063 int maxlun
; /* maximum LUN number */
1064 struct callout rescan_timeout
;
1068 char *states
[TSTATE_STATES
+1] = {
1069 /* should be kept in sync with the list at transfer_state */
1074 "BBB Data bulk-in/-out clear stall",
1075 "BBB CSW, 1st attempt",
1076 "BBB CSW bulk-in clear stall",
1077 "BBB CSW, 2nd attempt",
1079 "BBB bulk-in clear stall",
1080 "BBB bulk-out clear stall",
1084 "CBI Data bulk-in/-out clear stall",
1085 "CBI Status intr-in clear stall",
1087 "CBI bulk-in clear stall",
1088 "CBI bulk-out clear stall",
1093 /* If device cannot return valid inquiry data, fake it */
1094 static uint8_t fake_inq_data
[SHORT_INQUIRY_LENGTH
] = {
1095 0, /*removable*/ 0x80, SCSI_REV_2
, SCSI_REV_2
,
1096 /*additional_length*/ 31, 0, 0, 0
1099 /* USB device probe/attach/detach functions */
1100 static device_probe_t umass_match
;
1101 static device_attach_t umass_attach
;
1102 static device_detach_t umass_detach
;
1104 static devclass_t umass_devclass
;
1106 static kobj_method_t umass_methods
[] = {
1107 DEVMETHOD(device_probe
, umass_match
),
1108 DEVMETHOD(device_attach
, umass_attach
),
1109 DEVMETHOD(device_detach
, umass_detach
),
1114 static driver_t umass_driver
= {
1117 sizeof(struct umass_softc
)
1120 MODULE_DEPEND(umass
, usb
, 1, 1, 1);
1122 static int umass_match_proto (struct umass_softc
*sc
,
1123 usbd_interface_handle iface
,
1124 usbd_device_handle udev
);
1126 /* quirk functions */
1127 static void umass_init_shuttle (struct umass_softc
*sc
);
1129 /* generic transfer functions */
1130 static usbd_status
umass_setup_transfer (struct umass_softc
*sc
,
1131 usbd_pipe_handle pipe
,
1132 void *buffer
, int buflen
, int flags
,
1133 usbd_xfer_handle xfer
);
1134 static usbd_status
umass_setup_ctrl_transfer (struct umass_softc
*sc
,
1135 usbd_device_handle udev
,
1136 usb_device_request_t
*req
,
1137 void *buffer
, int buflen
, int flags
,
1138 usbd_xfer_handle xfer
);
1139 static void umass_clear_endpoint_stall (struct umass_softc
*sc
,
1140 u_int8_t endpt
, usbd_pipe_handle pipe
,
1141 int state
, usbd_xfer_handle xfer
);
1142 static void umass_reset (struct umass_softc
*sc
,
1143 transfer_cb_f cb
, void *priv
);
1145 /* Bulk-Only related functions */
1146 static void umass_bbb_reset (struct umass_softc
*sc
, int status
);
1147 static void umass_bbb_transfer (struct umass_softc
*sc
, int lun
,
1148 void *cmd
, int cmdlen
,
1149 void *data
, int datalen
, int dir
, u_int timeout
,
1150 transfer_cb_f cb
, void *priv
);
1151 static void umass_bbb_state (usbd_xfer_handle xfer
,
1152 usbd_private_handle priv
,
1154 static int umass_bbb_get_max_lun
1155 (struct umass_softc
*sc
);
1157 /* CBI related functions */
1158 static int umass_cbi_adsc (struct umass_softc
*sc
,
1159 char *buffer
, int buflen
,
1160 usbd_xfer_handle xfer
);
1161 static void umass_cbi_reset (struct umass_softc
*sc
, int status
);
1162 static void umass_cbi_transfer (struct umass_softc
*sc
, int lun
,
1163 void *cmd
, int cmdlen
,
1164 void *data
, int datalen
, int dir
, u_int timeout
,
1165 transfer_cb_f cb
, void *priv
);
1166 static void umass_cbi_state (usbd_xfer_handle xfer
,
1167 usbd_private_handle priv
, usbd_status err
);
1169 /* CAM related functions */
1170 static void umass_cam_action (struct cam_sim
*sim
, union ccb
*ccb
);
1171 static void umass_cam_poll (struct cam_sim
*sim
);
1173 static void umass_cam_cb (struct umass_softc
*sc
, void *priv
,
1174 int residue
, int status
);
1175 static void umass_cam_sense_cb (struct umass_softc
*sc
, void *priv
,
1176 int residue
, int status
);
1177 static void umass_cam_quirk_cb (struct umass_softc
*sc
, void *priv
,
1178 int residue
, int status
);
1180 static void umass_cam_rescan_callback
1181 (struct cam_periph
*periph
,union ccb
*ccb
);
1182 static void umass_cam_rescan (void *addr
);
1184 static int umass_cam_attach_sim (struct umass_softc
*sc
);
1185 static int umass_cam_attach (struct umass_softc
*sc
);
1186 static int umass_cam_detach_sim (struct umass_softc
*sc
);
1189 /* SCSI specific functions */
1190 static int umass_scsi_transform (struct umass_softc
*sc
,
1191 unsigned char *cmd
, int cmdlen
,
1192 unsigned char **rcmd
, int *rcmdlen
);
1194 /* UFI specific functions */
1195 #define UFI_COMMAND_LENGTH 12 /* UFI commands are always 12 bytes */
1196 static int umass_ufi_transform (struct umass_softc
*sc
,
1197 unsigned char *cmd
, int cmdlen
,
1198 unsigned char **rcmd
, int *rcmdlen
);
1200 /* ATAPI (8070i) specific functions */
1201 #define ATAPI_COMMAND_LENGTH 12 /* ATAPI commands are always 12 bytes */
1202 static int umass_atapi_transform (struct umass_softc
*sc
,
1203 unsigned char *cmd
, int cmdlen
,
1204 unsigned char **rcmd
, int *rcmdlen
);
1206 /* RBC specific functions */
1207 static int umass_rbc_transform (struct umass_softc
*sc
,
1208 unsigned char *cmd
, int cmdlen
,
1209 unsigned char **rcmd
, int *rcmdlen
);
1212 /* General debugging functions */
1213 static void umass_bbb_dump_cbw (struct umass_softc
*sc
, umass_bbb_cbw_t
*cbw
);
1214 static void umass_bbb_dump_csw (struct umass_softc
*sc
, umass_bbb_csw_t
*csw
);
1215 static void umass_cbi_dump_cmd (struct umass_softc
*sc
, void *cmd
, int cmdlen
);
1216 static void umass_dump_buffer (struct umass_softc
*sc
, u_int8_t
*buffer
,
1217 int buflen
, int printlen
);
1220 MODULE_DEPEND(umass
, cam
, 1,1,1);
1223 * USB device probe/attach/detach
1227 * Match the device we are seeing with the devices supported. Fill in the
1228 * description in the softc accordingly. This function is called from both
1233 umass_match_proto(struct umass_softc
*sc
, usbd_interface_handle iface
,
1234 usbd_device_handle udev
)
1236 usb_device_descriptor_t
*dd
;
1237 usb_interface_descriptor_t
*id
;
1245 dd
= usbd_get_device_descriptor(udev
);
1247 /* An entry specifically for Y-E Data devices as they don't fit in the
1248 * device description table.
1250 if (UGETW(dd
->idVendor
) == 0x057b && UGETW(dd
->idProduct
) == 0x0000) {
1252 /* Revisions < 1.28 do not handle the inerrupt endpoint
1255 if (UGETW(dd
->bcdDevice
) < 0x128) {
1256 sc
->proto
= UMASS_PROTO_UFI
| UMASS_PROTO_CBI
;
1258 sc
->proto
= UMASS_PROTO_UFI
| UMASS_PROTO_CBI_I
;
1262 * Revisions < 1.28 do not have the TEST UNIT READY command
1263 * Revisions == 1.28 have a broken TEST UNIT READY
1265 if (UGETW(dd
->bcdDevice
) <= 0x128)
1266 sc
->quirks
|= NO_TEST_UNIT_READY
;
1268 sc
->quirks
|= RS_NO_CLEAR_UA
| FLOPPY_SPEED
;
1269 return(UMATCH_VENDOR_PRODUCT
);
1272 /* Check the list of supported devices for a match. While looking,
1273 * check for wildcarded and fully matched. First match wins.
1275 for (i
= 0; umass_devdescrs
[i
].vendor
!= EOT_ID
&& !found
; i
++) {
1276 if (umass_devdescrs
[i
].vendor
== WILDCARD_ID
&&
1277 umass_devdescrs
[i
].product
== WILDCARD_ID
&&
1278 umass_devdescrs
[i
].release
== WILDCARD_ID
) {
1279 kprintf("umass: ignoring invalid wildcard quirk\n");
1282 if ((umass_devdescrs
[i
].vendor
== UGETW(dd
->idVendor
) ||
1283 umass_devdescrs
[i
].vendor
== WILDCARD_ID
)
1284 && (umass_devdescrs
[i
].product
== UGETW(dd
->idProduct
) ||
1285 umass_devdescrs
[i
].product
== WILDCARD_ID
)) {
1286 if (umass_devdescrs
[i
].release
== WILDCARD_ID
) {
1287 sc
->proto
= umass_devdescrs
[i
].proto
;
1288 sc
->quirks
= umass_devdescrs
[i
].quirks
;
1289 return (UMATCH_VENDOR_PRODUCT
);
1290 } else if (umass_devdescrs
[i
].release
==
1291 UGETW(dd
->bcdDevice
)) {
1292 sc
->proto
= umass_devdescrs
[i
].proto
;
1293 sc
->quirks
= umass_devdescrs
[i
].quirks
;
1294 return (UMATCH_VENDOR_PRODUCT_REV
);
1295 } /* else RID does not match */
1299 /* Check for a standards compliant device */
1301 id
= usbd_get_interface_descriptor(iface
);
1302 if (id
== NULL
|| id
->bInterfaceClass
!= UICLASS_MASS
)
1303 return(UMATCH_NONE
);
1305 switch (id
->bInterfaceSubClass
) {
1306 case UISUBCLASS_SCSI
:
1307 sc
->proto
|= UMASS_PROTO_SCSI
;
1309 case UISUBCLASS_UFI
:
1310 sc
->proto
|= UMASS_PROTO_UFI
;
1312 case UISUBCLASS_RBC
:
1313 sc
->proto
|= UMASS_PROTO_RBC
;
1315 case UISUBCLASS_SFF8020I
:
1316 case UISUBCLASS_SFF8070I
:
1317 sc
->proto
|= UMASS_PROTO_ATAPI
;
1320 DPRINTF(UDMASS_GEN
, ("%s: Unsupported command protocol %d\n",
1321 device_get_nameunit(sc
->sc_dev
), id
->bInterfaceSubClass
));
1322 return(UMATCH_NONE
);
1325 switch (id
->bInterfaceProtocol
) {
1326 case UIPROTO_MASS_CBI
:
1327 sc
->proto
|= UMASS_PROTO_CBI
;
1329 case UIPROTO_MASS_CBI_I
:
1330 sc
->proto
|= UMASS_PROTO_CBI_I
;
1332 case UIPROTO_MASS_BBB_OLD
:
1333 case UIPROTO_MASS_BBB
:
1334 sc
->proto
|= UMASS_PROTO_BBB
;
1337 DPRINTF(UDMASS_GEN
, ("%s: Unsupported wire protocol %d\n",
1338 device_get_nameunit(sc
->sc_dev
), id
->bInterfaceProtocol
));
1339 return(UMATCH_NONE
);
1342 return(UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO
);
1346 umass_match(device_t self
)
1348 struct usb_attach_arg
*uaa
= device_get_ivars(self
);
1349 struct umass_softc
*sc
= device_get_softc(self
);
1353 if (uaa
->iface
== NULL
)
1354 return(UMATCH_NONE
);
1356 return(umass_match_proto(sc
, uaa
->iface
, uaa
->device
));
1360 umass_attach(device_t self
)
1362 struct umass_softc
*sc
= device_get_softc(self
);
1363 struct usb_attach_arg
*uaa
= device_get_ivars(self
);
1364 usb_interface_descriptor_t
*id
;
1365 usb_endpoint_descriptor_t
*ed
;
1370 * the softc struct is bzero-ed in device_set_driver. We can safely
1371 * call umass_detach without specifically initialising the struct.
1376 sc
->iface
= uaa
->iface
;
1377 sc
->ifaceno
= uaa
->ifaceno
;
1379 /* initialise the proto and drive values in the umass_softc (again) */
1380 (void) umass_match_proto(sc
, sc
->iface
, uaa
->device
);
1382 id
= usbd_get_interface_descriptor(sc
->iface
);
1384 kprintf("%s: ", device_get_nameunit(sc
->sc_dev
));
1385 switch (sc
->proto
&UMASS_PROTO_COMMAND
) {
1386 case UMASS_PROTO_SCSI
:
1389 case UMASS_PROTO_ATAPI
:
1390 kprintf("8070i (ATAPI)");
1392 case UMASS_PROTO_UFI
:
1395 case UMASS_PROTO_RBC
:
1399 kprintf("(unknown 0x%02x)", sc
->proto
&UMASS_PROTO_COMMAND
);
1403 switch (sc
->proto
&UMASS_PROTO_WIRE
) {
1404 case UMASS_PROTO_BBB
:
1405 kprintf("Bulk-Only");
1407 case UMASS_PROTO_CBI
: /* uses Comand/Bulk pipes */
1410 case UMASS_PROTO_CBI_I
: /* uses Comand/Bulk/Interrupt pipes */
1411 kprintf("CBI with CCI");
1413 kprintf(" (using CBI)");
1417 kprintf("(unknown 0x%02x)", sc
->proto
&UMASS_PROTO_WIRE
);
1419 kprintf("; quirks = 0x%04x\n", sc
->quirks
);
1423 if (sc
->proto
& UMASS_PROTO_CBI_I
) {
1424 /* See beginning of file for comment on the use of CBI with CCI */
1425 sc
->proto
= (sc
->proto
& ~UMASS_PROTO_CBI_I
) | UMASS_PROTO_CBI
;
1429 if (sc
->quirks
& ALT_IFACE_1
) {
1430 err
= usbd_set_interface(0, 1);
1432 DPRINTF(UDMASS_USB
, ("%s: could not switch to "
1433 "Alt Interface %d\n",
1434 device_get_nameunit(sc
->sc_dev
), 1));
1441 * In addition to the Control endpoint the following endpoints
1443 * a) bulk-in endpoint.
1444 * b) bulk-out endpoint.
1445 * and for Control/Bulk/Interrupt with CCI (CBI_I)
1448 * The endpoint addresses are not fixed, so we have to read them
1449 * from the device descriptors of the current interface.
1451 for (i
= 0 ; i
< id
->bNumEndpoints
; i
++) {
1452 ed
= usbd_interface2endpoint_descriptor(sc
->iface
, i
);
1454 kprintf("%s: could not read endpoint descriptor\n",
1455 device_get_nameunit(sc
->sc_dev
));
1458 if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_IN
1459 && (ed
->bmAttributes
& UE_XFERTYPE
) == UE_BULK
) {
1460 sc
->bulkin
= ed
->bEndpointAddress
;
1461 } else if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_OUT
1462 && (ed
->bmAttributes
& UE_XFERTYPE
) == UE_BULK
) {
1463 sc
->bulkout
= ed
->bEndpointAddress
;
1464 } else if (sc
->proto
& UMASS_PROTO_CBI_I
1465 && UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_IN
1466 && (ed
->bmAttributes
& UE_XFERTYPE
) == UE_INTERRUPT
) {
1467 sc
->intrin
= ed
->bEndpointAddress
;
1469 if (UGETW(ed
->wMaxPacketSize
) > 2) {
1470 DPRINTF(UDMASS_CBI
, ("%s: intr size is %d\n",
1471 device_get_nameunit(sc
->sc_dev
),
1472 UGETW(ed
->wMaxPacketSize
)));
1478 /* check whether we found all the endpoints we need */
1479 if (!sc
->bulkin
|| !sc
->bulkout
1480 || (sc
->proto
& UMASS_PROTO_CBI_I
&& !sc
->intrin
) ) {
1481 DPRINTF(UDMASS_USB
, ("%s: endpoint not found %d/%d/%d\n",
1482 device_get_nameunit(sc
->sc_dev
),
1483 sc
->bulkin
, sc
->bulkout
, sc
->intrin
));
1488 /* Open the bulk-in and -out pipe */
1489 err
= usbd_open_pipe(sc
->iface
, sc
->bulkout
,
1490 USBD_EXCLUSIVE_USE
, &sc
->bulkout_pipe
);
1492 DPRINTF(UDMASS_USB
, ("%s: cannot open %d-out pipe (bulk)\n",
1493 device_get_nameunit(sc
->sc_dev
), sc
->bulkout
));
1497 err
= usbd_open_pipe(sc
->iface
, sc
->bulkin
,
1498 USBD_EXCLUSIVE_USE
, &sc
->bulkin_pipe
);
1500 DPRINTF(UDMASS_USB
, ("%s: could not open %d-in pipe (bulk)\n",
1501 device_get_nameunit(sc
->sc_dev
), sc
->bulkin
));
1505 /* Open the intr-in pipe if the protocol is CBI with CCI.
1506 * Note: early versions of the Zip drive do have an interrupt pipe, but
1507 * this pipe is unused
1509 * We do not open the interrupt pipe as an interrupt pipe, but as a
1510 * normal bulk endpoint. We send an IN transfer down the wire at the
1511 * appropriate time, because we know exactly when to expect data on
1512 * that endpoint. This saves bandwidth, but more important, makes the
1513 * code for handling the data on that endpoint simpler. No data
1514 * arriving concurently.
1516 if (sc
->proto
& UMASS_PROTO_CBI_I
) {
1517 err
= usbd_open_pipe(sc
->iface
, sc
->intrin
,
1518 USBD_EXCLUSIVE_USE
, &sc
->intrin_pipe
);
1520 DPRINTF(UDMASS_USB
, ("%s: couldn't open %d-in (intr)\n",
1521 device_get_nameunit(sc
->sc_dev
), sc
->intrin
));
1527 /* initialisation of generic part */
1528 sc
->transfer_state
= TSTATE_ATTACH
;
1530 /* request a sufficient number of xfer handles */
1531 for (i
= 0; i
< XFER_NR
; i
++) {
1532 sc
->transfer_xfer
[i
] = usbd_alloc_xfer(uaa
->device
);
1533 if (!sc
->transfer_xfer
[i
]) {
1534 DPRINTF(UDMASS_USB
, ("%s: Out of memory\n",
1535 device_get_nameunit(sc
->sc_dev
)));
1542 * Preallocate buffers to avoid auto-allocation from an interrupt
1545 usbd_alloc_buffer(sc
->transfer_xfer
[XFER_BBB_DATA
],
1547 usbd_alloc_buffer(sc
->transfer_xfer
[XFER_BBB_CBW
],
1548 UMASS_BBB_CBW_SIZE
);
1549 usbd_alloc_buffer(sc
->transfer_xfer
[XFER_BBB_CSW1
],
1550 UMASS_BBB_CSW_SIZE
);
1551 usbd_alloc_buffer(sc
->transfer_xfer
[XFER_BBB_CSW2
],
1552 UMASS_BBB_CSW_SIZE
);
1553 usbd_alloc_buffer(sc
->transfer_xfer
[XFER_CBI_DATA
],
1556 /* Initialise the wire protocol specific methods */
1557 if (sc
->proto
& UMASS_PROTO_BBB
) {
1558 sc
->reset
= umass_bbb_reset
;
1559 sc
->transfer
= umass_bbb_transfer
;
1560 sc
->state
= umass_bbb_state
;
1561 } else if (sc
->proto
& (UMASS_PROTO_CBI
|UMASS_PROTO_CBI_I
)) {
1562 sc
->reset
= umass_cbi_reset
;
1563 sc
->transfer
= umass_cbi_transfer
;
1564 sc
->state
= umass_cbi_state
;
1567 panic("%s:%d: Unknown proto 0x%02x",
1568 __FILE__
, __LINE__
, sc
->proto
);
1572 if (sc
->proto
& UMASS_PROTO_SCSI
)
1573 sc
->transform
= umass_scsi_transform
;
1574 else if (sc
->proto
& UMASS_PROTO_UFI
)
1575 sc
->transform
= umass_ufi_transform
;
1576 else if (sc
->proto
& UMASS_PROTO_ATAPI
)
1577 sc
->transform
= umass_atapi_transform
;
1578 else if (sc
->proto
& UMASS_PROTO_RBC
)
1579 sc
->transform
= umass_rbc_transform
;
1582 panic("No transformation defined for command proto 0x%02x",
1583 sc
->proto
& UMASS_PROTO_COMMAND
);
1586 /* From here onwards the device can be used. */
1588 if (sc
->quirks
& SHUTTLE_INIT
)
1589 umass_init_shuttle(sc
);
1591 /* Get the maximum LUN supported by the device.
1593 if (((sc
->proto
& UMASS_PROTO_WIRE
) == UMASS_PROTO_BBB
) &&
1594 !(sc
->quirks
& NO_GETMAXLUN
))
1595 sc
->maxlun
= umass_bbb_get_max_lun(sc
);
1599 if ((sc
->proto
& UMASS_PROTO_SCSI
) ||
1600 (sc
->proto
& UMASS_PROTO_ATAPI
) ||
1601 (sc
->proto
& UMASS_PROTO_UFI
) ||
1602 (sc
->proto
& UMASS_PROTO_RBC
)) {
1603 /* Prepare the SCSI command block */
1604 sc
->cam_scsi_sense
.opcode
= REQUEST_SENSE
;
1605 sc
->cam_scsi_test_unit_ready
.opcode
= TEST_UNIT_READY
;
1607 /* register the SIM */
1608 err
= umass_cam_attach_sim(sc
);
1613 /* scan the new sim */
1614 err
= umass_cam_attach(sc
);
1616 umass_cam_detach_sim(sc
);
1621 panic("%s:%d: Unknown proto 0x%02x",
1622 __FILE__
, __LINE__
, sc
->proto
);
1625 sc
->transfer_state
= TSTATE_IDLE
;
1626 DPRINTF(UDMASS_GEN
, ("%s: Attach finished\n", device_get_nameunit(sc
->sc_dev
)));
1632 umass_detach(device_t self
)
1634 struct umass_softc
*sc
= device_get_softc(self
);
1639 DPRINTF(UDMASS_USB
, ("%s: detached\n", device_get_nameunit(sc
->sc_dev
)));
1642 * Set UMASS_FLAGS_GONE to prevent any new transfers from being
1643 * queued, and abort any transfers in progress to ensure that
1644 * pending requests (e.g. from CAM's bus scan) are terminated.
1646 sc
->flags
|= UMASS_FLAGS_GONE
;
1648 if (sc
->bulkout_pipe
)
1649 usbd_abort_pipe(sc
->bulkout_pipe
);
1650 if (sc
->bulkin_pipe
)
1651 usbd_abort_pipe(sc
->bulkin_pipe
);
1652 if (sc
->intrin_pipe
)
1653 usbd_abort_pipe(sc
->intrin_pipe
);
1656 * Wait until we go idle to make sure that all of our xfer requests
1657 * have finished. We could be in the middle of a BBB reset (which
1658 * would not be effected by the pipe aborts above).
1661 while (sc
->transfer_state
!= TSTATE_IDLE
) {
1662 kprintf("%s: state %d waiting for idle\n",
1663 device_get_nameunit(sc
->sc_dev
), sc
->transfer_state
);
1664 tsleep(sc
, 0, "umassidl", to
);
1665 if (to
>= hz
* 10) {
1666 kprintf("%s: state %d giving up!\n",
1667 device_get_nameunit(sc
->sc_dev
), sc
->transfer_state
);
1673 if ((sc
->proto
& UMASS_PROTO_SCSI
) ||
1674 (sc
->proto
& UMASS_PROTO_ATAPI
) ||
1675 (sc
->proto
& UMASS_PROTO_UFI
) ||
1676 (sc
->proto
& UMASS_PROTO_RBC
)) {
1677 /* detach the SCSI host controller (SIM) */
1678 err
= umass_cam_detach_sim(sc
);
1681 for (i
= 0; i
< XFER_NR
; i
++) {
1682 if (sc
->transfer_xfer
[i
])
1683 usbd_free_xfer(sc
->transfer_xfer
[i
]);
1686 /* remove all the pipes */
1687 if (sc
->bulkout_pipe
)
1688 usbd_close_pipe(sc
->bulkout_pipe
);
1689 if (sc
->bulkin_pipe
)
1690 usbd_close_pipe(sc
->bulkin_pipe
);
1691 if (sc
->intrin_pipe
)
1692 usbd_close_pipe(sc
->intrin_pipe
);
1698 umass_init_shuttle(struct umass_softc
*sc
)
1700 usb_device_request_t req
;
1703 /* The Linux driver does this, but no one can tell us what the
1706 req
.bmRequestType
= UT_READ_VENDOR_DEVICE
;
1707 req
.bRequest
= 1; /* XXX unknown command */
1708 USETW(req
.wValue
, 0);
1709 USETW(req
.wIndex
, sc
->ifaceno
);
1710 USETW(req
.wLength
, sizeof status
);
1711 (void) usbd_do_request(sc
->sc_udev
, &req
, &status
);
1713 DPRINTF(UDMASS_GEN
, ("%s: Shuttle init returned 0x%02x%02x\n",
1714 device_get_nameunit(sc
->sc_dev
), status
[0], status
[1]));
1718 * Generic functions to handle transfers
1722 umass_setup_transfer(struct umass_softc
*sc
, usbd_pipe_handle pipe
,
1723 void *buffer
, int buflen
, int flags
,
1724 usbd_xfer_handle xfer
)
1728 /* Initialiase a USB transfer and then schedule it */
1730 (void) usbd_setup_xfer(xfer
, pipe
, (void *) sc
, buffer
, buflen
, flags
,
1731 sc
->timeout
, sc
->state
);
1733 err
= usbd_transfer(xfer
);
1734 if (err
&& err
!= USBD_IN_PROGRESS
) {
1735 DPRINTF(UDMASS_BBB
, ("%s: failed to setup transfer, %s\n",
1736 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
)));
1740 return (USBD_NORMAL_COMPLETION
);
1745 umass_setup_ctrl_transfer(struct umass_softc
*sc
, usbd_device_handle udev
,
1746 usb_device_request_t
*req
,
1747 void *buffer
, int buflen
, int flags
,
1748 usbd_xfer_handle xfer
)
1752 /* Initialiase a USB control transfer and then schedule it */
1754 (void) usbd_setup_default_xfer(xfer
, udev
, (void *) sc
,
1755 UMASS_TIMEOUT
, req
, buffer
, buflen
, flags
, sc
->state
);
1757 err
= usbd_transfer(xfer
);
1758 if (err
&& err
!= USBD_IN_PROGRESS
) {
1759 DPRINTF(UDMASS_BBB
, ("%s: failed to setup ctrl transfer, %s\n",
1760 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
)));
1762 /* do not reset, as this would make us loop */
1766 return (USBD_NORMAL_COMPLETION
);
1770 umass_clear_endpoint_stall(struct umass_softc
*sc
,
1771 u_int8_t endpt
, usbd_pipe_handle pipe
,
1772 int state
, usbd_xfer_handle xfer
)
1774 usbd_device_handle udev
;
1776 DPRINTF(UDMASS_BBB
, ("%s: Clear endpoint 0x%02x stall\n",
1777 device_get_nameunit(sc
->sc_dev
), endpt
));
1779 usbd_interface2device_handle(sc
->iface
, &udev
);
1781 sc
->transfer_state
= state
;
1783 usbd_clear_endpoint_toggle(pipe
);
1785 sc
->request
.bmRequestType
= UT_WRITE_ENDPOINT
;
1786 sc
->request
.bRequest
= UR_CLEAR_FEATURE
;
1787 USETW(sc
->request
.wValue
, UF_ENDPOINT_HALT
);
1788 USETW(sc
->request
.wIndex
, endpt
);
1789 USETW(sc
->request
.wLength
, 0);
1790 umass_setup_ctrl_transfer(sc
, udev
, &sc
->request
, NULL
, 0, 0, xfer
);
1794 umass_reset(struct umass_softc
*sc
, transfer_cb_f cb
, void *priv
)
1796 sc
->transfer_cb
= cb
;
1797 sc
->transfer_priv
= priv
;
1799 /* The reset is a forced reset, so no error (yet) */
1800 sc
->reset(sc
, STATUS_CMD_OK
);
1804 * Bulk protocol specific functions
1808 umass_bbb_reset(struct umass_softc
*sc
, int status
)
1810 usbd_device_handle udev
;
1812 KASSERT(sc
->proto
& UMASS_PROTO_BBB
,
1813 ("%s: umass_bbb_reset: wrong sc->proto 0x%02x\n",
1814 device_get_nameunit(sc
->sc_dev
), sc
->proto
));
1817 * Reset recovery (5.3.4 in Universal Serial Bus Mass Storage Class)
1819 * For Reset Recovery the host shall issue in the following order:
1820 * a) a Bulk-Only Mass Storage Reset
1821 * b) a Clear Feature HALT to the Bulk-In endpoint
1822 * c) a Clear Feature HALT to the Bulk-Out endpoint
1824 * This is done in 3 steps, states:
1829 * If the reset doesn't succeed, the device should be port reset.
1832 DPRINTF(UDMASS_BBB
, ("%s: Bulk Reset\n",
1833 device_get_nameunit(sc
->sc_dev
)));
1835 sc
->transfer_state
= TSTATE_BBB_RESET1
;
1836 sc
->transfer_status
= status
;
1838 usbd_interface2device_handle(sc
->iface
, &udev
);
1840 /* reset is a class specific interface write */
1841 sc
->request
.bmRequestType
= UT_WRITE_CLASS_INTERFACE
;
1842 sc
->request
.bRequest
= UR_BBB_RESET
;
1843 USETW(sc
->request
.wValue
, 0);
1844 USETW(sc
->request
.wIndex
, sc
->ifaceno
);
1845 USETW(sc
->request
.wLength
, 0);
1846 umass_setup_ctrl_transfer(sc
, udev
, &sc
->request
, NULL
, 0, 0,
1847 sc
->transfer_xfer
[XFER_BBB_RESET1
]);
1851 umass_bbb_transfer(struct umass_softc
*sc
, int lun
, void *cmd
, int cmdlen
,
1852 void *data
, int datalen
, int dir
, u_int timeout
,
1853 transfer_cb_f cb
, void *priv
)
1855 KASSERT(sc
->proto
& UMASS_PROTO_BBB
,
1856 ("%s: umass_bbb_transfer: wrong sc->proto 0x%02x\n",
1857 device_get_nameunit(sc
->sc_dev
), sc
->proto
));
1858 /* Be a little generous. */
1859 sc
->timeout
= timeout
+ UMASS_TIMEOUT
;
1862 * Do a Bulk-Only transfer with cmdlen bytes from cmd, possibly
1863 * a data phase of datalen bytes from/to the device and finally a
1865 * If the data direction was inbound a maximum of datalen bytes
1866 * is stored in the buffer pointed to by data.
1868 * umass_bbb_transfer initialises the transfer and lets the state
1869 * machine in umass_bbb_state handle the completion. It uses the
1871 * TSTATE_BBB_COMMAND
1872 * -> TSTATE_BBB_DATA
1873 * -> TSTATE_BBB_STATUS
1874 * -> TSTATE_BBB_STATUS2
1875 * -> TSTATE_BBB_IDLE
1877 * An error in any of those states will invoke
1881 /* check the given arguments */
1882 KASSERT(datalen
== 0 || data
!= NULL
,
1883 ("%s: datalen > 0, but no buffer",device_get_nameunit(sc
->sc_dev
)));
1884 KASSERT(cmdlen
<= CBWCDBLENGTH
,
1885 ("%s: cmdlen exceeds CDB length in CBW (%d > %d)",
1886 device_get_nameunit(sc
->sc_dev
), cmdlen
, CBWCDBLENGTH
));
1887 KASSERT(dir
== DIR_NONE
|| datalen
> 0,
1888 ("%s: datalen == 0 while direction is not NONE\n",
1889 device_get_nameunit(sc
->sc_dev
)));
1890 KASSERT(datalen
== 0 || dir
!= DIR_NONE
,
1891 ("%s: direction is NONE while datalen is not zero\n",
1892 device_get_nameunit(sc
->sc_dev
)));
1893 KASSERT(sizeof(umass_bbb_cbw_t
) == UMASS_BBB_CBW_SIZE
,
1894 ("%s: CBW struct does not have the right size (%ld vs. %d)\n",
1895 device_get_nameunit(sc
->sc_dev
),
1896 (long)sizeof(umass_bbb_cbw_t
), UMASS_BBB_CBW_SIZE
));
1897 KASSERT(sizeof(umass_bbb_csw_t
) == UMASS_BBB_CSW_SIZE
,
1898 ("%s: CSW struct does not have the right size (%ld vs. %d)\n",
1899 device_get_nameunit(sc
->sc_dev
),
1900 (long)sizeof(umass_bbb_csw_t
), UMASS_BBB_CSW_SIZE
));
1903 * Determine the direction of the data transfer and the length.
1905 * dCBWDataTransferLength (datalen) :
1906 * This field indicates the number of bytes of data that the host
1907 * intends to transfer on the IN or OUT Bulk endpoint(as indicated by
1908 * the Direction bit) during the execution of this command. If this
1909 * field is set to 0, the device will expect that no data will be
1910 * transferred IN or OUT during this command, regardless of the value
1911 * of the Direction bit defined in dCBWFlags.
1914 * The bits of the Flags field are defined as follows:
1916 * Bit 7 Direction - this bit shall be ignored if the
1917 * dCBWDataTransferLength field is zero.
1918 * 0 = data Out from host to device
1919 * 1 = data In from device to host
1922 /* Fill in the Command Block Wrapper
1923 * We fill in all the fields, so there is no need to bzero it first.
1925 USETDW(sc
->cbw
.dCBWSignature
, CBWSIGNATURE
);
1926 /* We don't care about the initial value, as long as the values are unique */
1927 USETDW(sc
->cbw
.dCBWTag
, UGETDW(sc
->cbw
.dCBWTag
) + 1);
1928 USETDW(sc
->cbw
.dCBWDataTransferLength
, datalen
);
1929 /* DIR_NONE is treated as DIR_OUT (0x00) */
1930 sc
->cbw
.bCBWFlags
= (dir
== DIR_IN
? CBWFLAGS_IN
:CBWFLAGS_OUT
);
1931 sc
->cbw
.bCBWLUN
= lun
;
1932 sc
->cbw
.bCDBLength
= cmdlen
;
1933 bcopy(cmd
, sc
->cbw
.CBWCDB
, cmdlen
);
1935 DIF(UDMASS_BBB
, umass_bbb_dump_cbw(sc
, &sc
->cbw
));
1937 /* store the details for the data transfer phase */
1938 sc
->transfer_dir
= dir
;
1939 sc
->transfer_data
= data
;
1940 sc
->transfer_datalen
= datalen
;
1941 sc
->transfer_actlen
= 0;
1942 sc
->transfer_cb
= cb
;
1943 sc
->transfer_priv
= priv
;
1944 sc
->transfer_status
= STATUS_CMD_OK
;
1946 /* move from idle to the command state */
1947 sc
->transfer_state
= TSTATE_BBB_COMMAND
;
1949 /* Send the CBW from host to device via bulk-out endpoint. */
1950 if (umass_setup_transfer(sc
, sc
->bulkout_pipe
,
1951 &sc
->cbw
, UMASS_BBB_CBW_SIZE
, 0,
1952 sc
->transfer_xfer
[XFER_BBB_CBW
])) {
1953 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
1959 umass_bbb_state(usbd_xfer_handle xfer
, usbd_private_handle priv
,
1962 struct umass_softc
*sc
= (struct umass_softc
*) priv
;
1963 usbd_xfer_handle next_xfer
;
1965 KASSERT(sc
->proto
& UMASS_PROTO_BBB
,
1966 ("%s: umass_bbb_state: wrong sc->proto 0x%02x\n",
1967 device_get_nameunit(sc
->sc_dev
), sc
->proto
));
1970 * State handling for BBB transfers.
1972 * The subroutine is rather long. It steps through the states given in
1973 * Annex A of the Bulk-Only specification.
1974 * Each state first does the error handling of the previous transfer
1975 * and then prepares the next transfer.
1976 * Each transfer is done asynchroneously so after the request/transfer
1977 * has been submitted you will find a 'return;'.
1980 DPRINTF(UDMASS_BBB
, ("%s: Handling BBB state %d (%s), xfer=%p, %s\n",
1981 device_get_nameunit(sc
->sc_dev
), sc
->transfer_state
,
1982 states
[sc
->transfer_state
], xfer
, usbd_errstr(err
)));
1984 switch (sc
->transfer_state
) {
1986 /***** Bulk Transfer *****/
1987 case TSTATE_BBB_COMMAND
:
1988 /* Command transport phase, error handling */
1990 DPRINTF(UDMASS_BBB
, ("%s: failed to send CBW\n",
1991 device_get_nameunit(sc
->sc_dev
)));
1992 /* If the device detects that the CBW is invalid, then
1993 * the device may STALL both bulk endpoints and require
1996 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2000 /* Data transport phase, setup transfer */
2001 sc
->transfer_state
= TSTATE_BBB_DATA
;
2002 if (sc
->transfer_dir
== DIR_IN
) {
2003 if (umass_setup_transfer(sc
, sc
->bulkin_pipe
,
2004 sc
->transfer_data
, sc
->transfer_datalen
,
2006 sc
->transfer_xfer
[XFER_BBB_DATA
]))
2007 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2010 } else if (sc
->transfer_dir
== DIR_OUT
) {
2011 if (umass_setup_transfer(sc
, sc
->bulkout_pipe
,
2012 sc
->transfer_data
, sc
->transfer_datalen
,
2013 0, /* fixed length transfer */
2014 sc
->transfer_xfer
[XFER_BBB_DATA
]))
2015 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2019 DPRINTF(UDMASS_BBB
, ("%s: no data phase\n",
2020 device_get_nameunit(sc
->sc_dev
)));
2023 /* FALLTHROUGH if no data phase, err == 0 */
2024 case TSTATE_BBB_DATA
:
2025 /* Command transport phase, error handling (ignored if no data
2026 * phase (fallthrough from previous state)) */
2027 if (sc
->transfer_dir
!= DIR_NONE
) {
2028 /* retrieve the length of the transfer that was done */
2029 usbd_get_xfer_status(xfer
, NULL
, NULL
,
2030 &sc
->transfer_actlen
, NULL
);
2033 DPRINTF(UDMASS_BBB
, ("%s: Data-%s %db failed, "
2034 "%s\n", device_get_nameunit(sc
->sc_dev
),
2035 (sc
->transfer_dir
== DIR_IN
?"in":"out"),
2036 sc
->transfer_datalen
,usbd_errstr(err
)));
2038 if (err
== USBD_STALLED
) {
2039 umass_clear_endpoint_stall(sc
,
2040 (sc
->transfer_dir
== DIR_IN
?
2041 sc
->bulkin
:sc
->bulkout
),
2042 (sc
->transfer_dir
== DIR_IN
?
2043 sc
->bulkin_pipe
:sc
->bulkout_pipe
),
2045 sc
->transfer_xfer
[XFER_BBB_DCLEAR
]);
2048 /* Unless the error is a pipe stall the
2051 umass_bbb_reset(sc
,STATUS_WIRE_FAILED
);
2057 DIF(UDMASS_BBB
, if (sc
->transfer_dir
== DIR_IN
)
2058 umass_dump_buffer(sc
, sc
->transfer_data
,
2059 sc
->transfer_datalen
, 48));
2063 /* FALLTHROUGH, err == 0 (no data phase or successfull) */
2064 case TSTATE_BBB_DCLEAR
: /* stall clear after data phase */
2065 case TSTATE_BBB_SCLEAR
: /* stall clear after status phase */
2066 /* Reading of CSW after bulk stall condition in data phase
2067 * (TSTATE_BBB_DATA2) or bulk-in stall condition after
2068 * reading CSW (TSTATE_BBB_SCLEAR).
2069 * In the case of no data phase or successfull data phase,
2070 * err == 0 and the following if block is passed.
2072 if (err
) { /* should not occur */
2073 /* try the transfer below, even if clear stall failed */
2074 DPRINTF(UDMASS_BBB
, ("%s: bulk-%s stall clear failed"
2075 ", %s\n", device_get_nameunit(sc
->sc_dev
),
2076 (sc
->transfer_dir
== DIR_IN
? "in":"out"),
2078 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2082 /* Status transport phase, setup transfer */
2083 if (sc
->transfer_state
== TSTATE_BBB_COMMAND
||
2084 sc
->transfer_state
== TSTATE_BBB_DATA
||
2085 sc
->transfer_state
== TSTATE_BBB_DCLEAR
) {
2086 /* After no data phase, successfull data phase and
2087 * after clearing bulk-in/-out stall condition
2089 sc
->transfer_state
= TSTATE_BBB_STATUS1
;
2090 next_xfer
= sc
->transfer_xfer
[XFER_BBB_CSW1
];
2092 /* After first attempt of fetching CSW */
2093 sc
->transfer_state
= TSTATE_BBB_STATUS2
;
2094 next_xfer
= sc
->transfer_xfer
[XFER_BBB_CSW2
];
2097 /* Read the Command Status Wrapper via bulk-in endpoint. */
2098 if (umass_setup_transfer(sc
, sc
->bulkin_pipe
,
2099 &sc
->csw
, UMASS_BBB_CSW_SIZE
, 0,
2101 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2106 case TSTATE_BBB_STATUS1
: /* first attempt */
2107 case TSTATE_BBB_STATUS2
: /* second attempt */
2108 /* Status transfer, error handling */
2112 DPRINTF(UDMASS_BBB
, ("%s: Failed to read CSW, %s%s\n",
2113 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
),
2114 (sc
->transfer_state
== TSTATE_BBB_STATUS1
?
2117 /* If this was the first attempt at fetching the CSW
2118 * retry it, otherwise fail.
2120 if (sc
->transfer_state
== TSTATE_BBB_STATUS1
) {
2121 umass_clear_endpoint_stall(sc
,
2122 sc
->bulkin
, sc
->bulkin_pipe
,
2124 sc
->transfer_xfer
[XFER_BBB_SCLEAR
]);
2127 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2132 DIF(UDMASS_BBB
, umass_bbb_dump_csw(sc
, &sc
->csw
));
2134 /* Translate weird command-status signatures. */
2135 if ((sc
->quirks
& WRONG_CSWSIG
) &&
2136 UGETDW(sc
->csw
.dCSWSignature
) == CSWSIGNATURE_OLYMPUS_C1
)
2137 USETDW(sc
->csw
.dCSWSignature
, CSWSIGNATURE
);
2139 Residue
= UGETDW(sc
->csw
.dCSWDataResidue
);
2141 sc
->transfer_datalen
- sc
->transfer_actlen
!= 0)
2142 Residue
= sc
->transfer_datalen
- sc
->transfer_actlen
;
2144 /* Check CSW and handle any error */
2145 if (UGETDW(sc
->csw
.dCSWSignature
) != CSWSIGNATURE
) {
2146 /* Invalid CSW: Wrong signature or wrong tag might
2147 * indicate that the device is confused -> reset it.
2149 kprintf("%s: Invalid CSW: sig 0x%08x should be 0x%08x\n",
2150 device_get_nameunit(sc
->sc_dev
),
2151 UGETDW(sc
->csw
.dCSWSignature
),
2154 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2156 } else if (UGETDW(sc
->csw
.dCSWTag
)
2157 != UGETDW(sc
->cbw
.dCBWTag
)) {
2158 kprintf("%s: Invalid CSW: tag %d should be %d\n",
2159 device_get_nameunit(sc
->sc_dev
),
2160 UGETDW(sc
->csw
.dCSWTag
),
2161 UGETDW(sc
->cbw
.dCBWTag
));
2163 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2166 /* CSW is valid here */
2167 } else if (sc
->csw
.bCSWStatus
> CSWSTATUS_PHASE
) {
2168 kprintf("%s: Invalid CSW: status %d > %d\n",
2169 device_get_nameunit(sc
->sc_dev
),
2173 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2175 } else if (sc
->csw
.bCSWStatus
== CSWSTATUS_PHASE
) {
2176 kprintf("%s: Phase Error, residue = %d\n",
2177 device_get_nameunit(sc
->sc_dev
), Residue
);
2179 umass_bbb_reset(sc
, STATUS_WIRE_FAILED
);
2182 } else if (sc
->transfer_actlen
> sc
->transfer_datalen
) {
2183 /* Buffer overrun! Don't let this go by unnoticed */
2184 panic("%s: transferred %db instead of %db",
2185 device_get_nameunit(sc
->sc_dev
),
2186 sc
->transfer_actlen
, sc
->transfer_datalen
);
2188 } else if (sc
->csw
.bCSWStatus
== CSWSTATUS_FAILED
) {
2189 DPRINTF(UDMASS_BBB
, ("%s: Command Failed, res = %d\n",
2190 device_get_nameunit(sc
->sc_dev
), Residue
));
2192 /* SCSI command failed but transfer was succesful */
2193 sc
->transfer_state
= TSTATE_IDLE
;
2194 sc
->transfer_cb(sc
, sc
->transfer_priv
, Residue
,
2198 } else { /* success */
2199 sc
->transfer_state
= TSTATE_IDLE
;
2200 sc
->transfer_cb(sc
, sc
->transfer_priv
, Residue
,
2207 /***** Bulk Reset *****/
2208 case TSTATE_BBB_RESET1
:
2210 kprintf("%s: BBB reset failed, %s\n",
2211 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
));
2213 umass_clear_endpoint_stall(sc
,
2214 sc
->bulkin
, sc
->bulkin_pipe
, TSTATE_BBB_RESET2
,
2215 sc
->transfer_xfer
[XFER_BBB_RESET2
]);
2218 case TSTATE_BBB_RESET2
:
2219 if (err
) /* should not occur */
2220 kprintf("%s: BBB bulk-in clear stall failed, %s\n",
2221 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
));
2222 /* no error recovery, otherwise we end up in a loop */
2224 umass_clear_endpoint_stall(sc
,
2225 sc
->bulkout
, sc
->bulkout_pipe
, TSTATE_BBB_RESET3
,
2226 sc
->transfer_xfer
[XFER_BBB_RESET3
]);
2229 case TSTATE_BBB_RESET3
:
2230 if (err
) /* should not occur */
2231 kprintf("%s: BBB bulk-out clear stall failed, %s\n",
2232 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
));
2233 /* no error recovery, otherwise we end up in a loop */
2235 sc
->transfer_state
= TSTATE_IDLE
;
2236 if (sc
->transfer_priv
) {
2237 sc
->transfer_cb(sc
, sc
->transfer_priv
,
2238 sc
->transfer_datalen
,
2239 sc
->transfer_status
);
2244 /***** Default *****/
2246 panic("%s: Unknown state %d",
2247 device_get_nameunit(sc
->sc_dev
), sc
->transfer_state
);
2252 umass_bbb_get_max_lun(struct umass_softc
*sc
)
2254 usbd_device_handle udev
;
2255 usb_device_request_t req
;
2257 usb_interface_descriptor_t
*id
;
2261 usbd_interface2device_handle(sc
->iface
, &udev
);
2262 id
= usbd_get_interface_descriptor(sc
->iface
);
2264 /* The Get Max Lun command is a class-specific request. */
2265 req
.bmRequestType
= UT_READ_CLASS_INTERFACE
;
2266 req
.bRequest
= UR_BBB_GET_MAX_LUN
;
2267 USETW(req
.wValue
, 0);
2268 USETW(req
.wIndex
, id
->bInterfaceNumber
);
2269 USETW(req
.wLength
, 1);
2271 err
= usbd_do_request(udev
, &req
, &buf
);
2273 case USBD_NORMAL_COMPLETION
:
2275 DPRINTF(UDMASS_BBB
, ("%s: Max Lun is %d\n",
2276 device_get_nameunit(sc
->sc_dev
), maxlun
));
2279 case USBD_SHORT_XFER
:
2281 /* Device doesn't support Get Max Lun request. */
2282 kprintf("%s: Get Max Lun not supported (%s)\n",
2283 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
));
2284 /* XXX Should we port_reset the device? */
2292 * Command/Bulk/Interrupt (CBI) specific functions
2296 umass_cbi_adsc(struct umass_softc
*sc
, char *buffer
, int buflen
,
2297 usbd_xfer_handle xfer
)
2299 usbd_device_handle udev
;
2301 KASSERT(sc
->proto
& (UMASS_PROTO_CBI
|UMASS_PROTO_CBI_I
),
2302 ("%s: umass_cbi_adsc: wrong sc->proto 0x%02x\n",
2303 device_get_nameunit(sc
->sc_dev
), sc
->proto
));
2305 usbd_interface2device_handle(sc
->iface
, &udev
);
2307 sc
->request
.bmRequestType
= UT_WRITE_CLASS_INTERFACE
;
2308 sc
->request
.bRequest
= UR_CBI_ADSC
;
2309 USETW(sc
->request
.wValue
, 0);
2310 USETW(sc
->request
.wIndex
, sc
->ifaceno
);
2311 USETW(sc
->request
.wLength
, buflen
);
2312 return umass_setup_ctrl_transfer(sc
, udev
, &sc
->request
, buffer
,
2318 umass_cbi_reset(struct umass_softc
*sc
, int status
)
2321 # define SEND_DIAGNOSTIC_CMDLEN 12
2323 KASSERT(sc
->proto
& (UMASS_PROTO_CBI
|UMASS_PROTO_CBI_I
),
2324 ("%s: umass_cbi_reset: wrong sc->proto 0x%02x\n",
2325 device_get_nameunit(sc
->sc_dev
), sc
->proto
));
2328 * Command Block Reset Protocol
2330 * First send a reset request to the device. Then clear
2331 * any possibly stalled bulk endpoints.
2333 * This is done in 3 steps, states:
2338 * If the reset doesn't succeed, the device should be port reset.
2341 DPRINTF(UDMASS_CBI
, ("%s: CBI Reset\n",
2342 device_get_nameunit(sc
->sc_dev
)));
2344 KASSERT(sizeof(sc
->cbl
) >= SEND_DIAGNOSTIC_CMDLEN
,
2345 ("%s: CBL struct is too small (%ld < %d)\n",
2346 device_get_nameunit(sc
->sc_dev
),
2347 (long)sizeof(sc
->cbl
), SEND_DIAGNOSTIC_CMDLEN
));
2349 sc
->transfer_state
= TSTATE_CBI_RESET1
;
2350 sc
->transfer_status
= status
;
2352 /* The 0x1d code is the SEND DIAGNOSTIC command. To distingiush between
2353 * the two the last 10 bytes of the cbl is filled with 0xff (section
2354 * 2.2 of the CBI spec).
2356 sc
->cbl
[0] = 0x1d; /* Command Block Reset */
2358 for (i
= 2; i
< SEND_DIAGNOSTIC_CMDLEN
; i
++)
2361 umass_cbi_adsc(sc
, sc
->cbl
, SEND_DIAGNOSTIC_CMDLEN
,
2362 sc
->transfer_xfer
[XFER_CBI_RESET1
]);
2363 /* XXX if the command fails we should reset the port on the bub */
2367 umass_cbi_transfer(struct umass_softc
*sc
, int lun
,
2368 void *cmd
, int cmdlen
, void *data
, int datalen
, int dir
,
2369 u_int timeout
, transfer_cb_f cb
, void *priv
)
2371 KASSERT(sc
->proto
& (UMASS_PROTO_CBI
|UMASS_PROTO_CBI_I
),
2372 ("%s: umass_cbi_transfer: wrong sc->proto 0x%02x\n",
2373 device_get_nameunit(sc
->sc_dev
), sc
->proto
));
2374 /* Be a little generous. */
2375 sc
->timeout
= timeout
+ UMASS_TIMEOUT
;
2378 * Do a CBI transfer with cmdlen bytes from cmd, possibly
2379 * a data phase of datalen bytes from/to the device and finally a
2381 * If the data direction was inbound a maximum of datalen bytes
2382 * is stored in the buffer pointed to by data.
2384 * umass_cbi_transfer initialises the transfer and lets the state
2385 * machine in umass_cbi_state handle the completion. It uses the
2387 * TSTATE_CBI_COMMAND
2390 * An error in any of those states will invoke
2394 /* check the given arguments */
2395 KASSERT(datalen
== 0 || data
!= NULL
,
2396 ("%s: datalen > 0, but no buffer",device_get_nameunit(sc
->sc_dev
)));
2397 KASSERT(datalen
== 0 || dir
!= DIR_NONE
,
2398 ("%s: direction is NONE while datalen is not zero\n",
2399 device_get_nameunit(sc
->sc_dev
)));
2401 /* store the details for the data transfer phase */
2402 sc
->transfer_dir
= dir
;
2403 sc
->transfer_data
= data
;
2404 sc
->transfer_datalen
= datalen
;
2405 sc
->transfer_actlen
= 0;
2406 sc
->transfer_cb
= cb
;
2407 sc
->transfer_priv
= priv
;
2408 sc
->transfer_status
= STATUS_CMD_OK
;
2410 /* move from idle to the command state */
2411 sc
->transfer_state
= TSTATE_CBI_COMMAND
;
2413 DIF(UDMASS_CBI
, umass_cbi_dump_cmd(sc
, cmd
, cmdlen
));
2415 /* Send the Command Block from host to device via control endpoint. */
2416 if (umass_cbi_adsc(sc
, cmd
, cmdlen
, sc
->transfer_xfer
[XFER_CBI_CB
]))
2417 umass_cbi_reset(sc
, STATUS_WIRE_FAILED
);
2421 umass_cbi_state(usbd_xfer_handle xfer
, usbd_private_handle priv
,
2424 struct umass_softc
*sc
= (struct umass_softc
*) priv
;
2426 KASSERT(sc
->proto
& (UMASS_PROTO_CBI
|UMASS_PROTO_CBI_I
),
2427 ("%s: umass_cbi_state: wrong sc->proto 0x%02x\n",
2428 device_get_nameunit(sc
->sc_dev
), sc
->proto
));
2431 * State handling for CBI transfers.
2434 DPRINTF(UDMASS_CBI
, ("%s: Handling CBI state %d (%s), xfer=%p, %s\n",
2435 device_get_nameunit(sc
->sc_dev
), sc
->transfer_state
,
2436 states
[sc
->transfer_state
], xfer
, usbd_errstr(err
)));
2438 switch (sc
->transfer_state
) {
2440 /***** CBI Transfer *****/
2441 case TSTATE_CBI_COMMAND
:
2442 if (err
== USBD_STALLED
) {
2443 DPRINTF(UDMASS_CBI
, ("%s: Command Transport failed\n",
2444 device_get_nameunit(sc
->sc_dev
)));
2445 /* Status transport by control pipe (section 2.3.2.1).
2446 * The command contained in the command block failed.
2448 * The control pipe has already been unstalled by the
2450 * Section 2.4.3.1.1 states that the bulk in endpoints
2451 * should not be stalled at this point.
2454 sc
->transfer_state
= TSTATE_IDLE
;
2455 sc
->transfer_cb(sc
, sc
->transfer_priv
,
2456 sc
->transfer_datalen
,
2461 DPRINTF(UDMASS_CBI
, ("%s: failed to send ADSC\n",
2462 device_get_nameunit(sc
->sc_dev
)));
2463 umass_cbi_reset(sc
, STATUS_WIRE_FAILED
);
2468 sc
->transfer_state
= TSTATE_CBI_DATA
;
2469 if (sc
->transfer_dir
== DIR_IN
) {
2470 if (umass_setup_transfer(sc
, sc
->bulkin_pipe
,
2471 sc
->transfer_data
, sc
->transfer_datalen
,
2473 sc
->transfer_xfer
[XFER_CBI_DATA
]))
2474 umass_cbi_reset(sc
, STATUS_WIRE_FAILED
);
2476 } else if (sc
->transfer_dir
== DIR_OUT
) {
2477 if (umass_setup_transfer(sc
, sc
->bulkout_pipe
,
2478 sc
->transfer_data
, sc
->transfer_datalen
,
2479 0, /* fixed length transfer */
2480 sc
->transfer_xfer
[XFER_CBI_DATA
]))
2481 umass_cbi_reset(sc
, STATUS_WIRE_FAILED
);
2483 } else if (sc
->proto
& UMASS_PROTO_CBI_I
) {
2484 DPRINTF(UDMASS_CBI
, ("%s: no data phase\n",
2485 device_get_nameunit(sc
->sc_dev
)));
2486 sc
->transfer_state
= TSTATE_CBI_STATUS
;
2487 if (umass_setup_transfer(sc
, sc
->intrin_pipe
,
2488 &sc
->sbl
, sizeof(sc
->sbl
),
2489 0, /* fixed length transfer */
2490 sc
->transfer_xfer
[XFER_CBI_STATUS
])){
2491 umass_cbi_reset(sc
, STATUS_WIRE_FAILED
);
2494 DPRINTF(UDMASS_CBI
, ("%s: no data phase\n",
2495 device_get_nameunit(sc
->sc_dev
)));
2496 /* No command completion interrupt. Request
2499 sc
->transfer_state
= TSTATE_IDLE
;
2500 sc
->transfer_cb(sc
, sc
->transfer_priv
,
2501 0, STATUS_CMD_UNKNOWN
);
2506 case TSTATE_CBI_DATA
:
2507 /* retrieve the length of the transfer that was done */
2508 usbd_get_xfer_status(xfer
,NULL
,NULL
,&sc
->transfer_actlen
,NULL
);
2511 DPRINTF(UDMASS_CBI
, ("%s: Data-%s %db failed, "
2512 "%s\n", device_get_nameunit(sc
->sc_dev
),
2513 (sc
->transfer_dir
== DIR_IN
?"in":"out"),
2514 sc
->transfer_datalen
,usbd_errstr(err
)));
2516 if (err
== USBD_STALLED
) {
2517 umass_clear_endpoint_stall(sc
,
2518 sc
->bulkin
, sc
->bulkin_pipe
,
2520 sc
->transfer_xfer
[XFER_CBI_DCLEAR
]);
2522 umass_cbi_reset(sc
, STATUS_WIRE_FAILED
);
2527 DIF(UDMASS_CBI
, if (sc
->transfer_dir
== DIR_IN
)
2528 umass_dump_buffer(sc
, sc
->transfer_data
,
2529 sc
->transfer_actlen
, 48));
2531 if (sc
->proto
& UMASS_PROTO_CBI_I
) {
2532 sc
->transfer_state
= TSTATE_CBI_STATUS
;
2533 if (umass_setup_transfer(sc
, sc
->intrin_pipe
,
2534 &sc
->sbl
, sizeof(sc
->sbl
),
2535 0, /* fixed length transfer */
2536 sc
->transfer_xfer
[XFER_CBI_STATUS
])){
2537 umass_cbi_reset(sc
, STATUS_WIRE_FAILED
);
2540 /* No command completion interrupt. Request
2541 * sense to get status of command.
2543 sc
->transfer_state
= TSTATE_IDLE
;
2544 sc
->transfer_cb(sc
, sc
->transfer_priv
,
2545 sc
->transfer_datalen
- sc
->transfer_actlen
,
2546 STATUS_CMD_UNKNOWN
);
2550 case TSTATE_CBI_STATUS
:
2552 DPRINTF(UDMASS_CBI
, ("%s: Status Transport failed\n",
2553 device_get_nameunit(sc
->sc_dev
)));
2554 /* Status transport by interrupt pipe (section 2.3.2.2).
2557 if (err
== USBD_STALLED
) {
2558 umass_clear_endpoint_stall(sc
,
2559 sc
->intrin
, sc
->intrin_pipe
,
2561 sc
->transfer_xfer
[XFER_CBI_SCLEAR
]);
2563 umass_cbi_reset(sc
, STATUS_WIRE_FAILED
);
2568 /* Dissect the information in the buffer */
2570 if (sc
->proto
& UMASS_PROTO_UFI
) {
2573 /* Section 3.4.3.1.3 specifies that the UFI command
2574 * protocol returns an ASC and ASCQ in the interrupt
2578 DPRINTF(UDMASS_CBI
, ("%s: UFI CCI, ASC = 0x%02x, "
2580 device_get_nameunit(sc
->sc_dev
),
2581 sc
->sbl
.ufi
.asc
, sc
->sbl
.ufi
.ascq
));
2583 if (sc
->sbl
.ufi
.asc
== 0 && sc
->sbl
.ufi
.ascq
== 0)
2584 status
= STATUS_CMD_OK
;
2586 status
= STATUS_CMD_FAILED
;
2588 sc
->transfer_state
= TSTATE_IDLE
;
2589 sc
->transfer_cb(sc
, sc
->transfer_priv
,
2590 sc
->transfer_datalen
- sc
->transfer_actlen
,
2593 /* Command Interrupt Data Block */
2594 DPRINTF(UDMASS_CBI
, ("%s: type=0x%02x, value=0x%02x\n",
2595 device_get_nameunit(sc
->sc_dev
),
2596 sc
->sbl
.common
.type
, sc
->sbl
.common
.value
));
2598 if (sc
->sbl
.common
.type
== IDB_TYPE_CCI
) {
2601 if ((sc
->sbl
.common
.value
&IDB_VALUE_STATUS_MASK
)
2602 == IDB_VALUE_PASS
) {
2603 err
= STATUS_CMD_OK
;
2604 } else if ((sc
->sbl
.common
.value
& IDB_VALUE_STATUS_MASK
)
2605 == IDB_VALUE_FAIL
||
2606 (sc
->sbl
.common
.value
& IDB_VALUE_STATUS_MASK
)
2607 == IDB_VALUE_PERSISTENT
) {
2608 err
= STATUS_CMD_FAILED
;
2610 err
= STATUS_WIRE_FAILED
;
2613 sc
->transfer_state
= TSTATE_IDLE
;
2614 sc
->transfer_cb(sc
, sc
->transfer_priv
,
2615 sc
->transfer_datalen
-sc
->transfer_actlen
,
2621 case TSTATE_CBI_DCLEAR
:
2622 if (err
) { /* should not occur */
2623 kprintf("%s: CBI bulk-in/out stall clear failed, %s\n",
2624 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
));
2625 umass_cbi_reset(sc
, STATUS_WIRE_FAILED
);
2628 sc
->transfer_state
= TSTATE_IDLE
;
2629 sc
->transfer_cb(sc
, sc
->transfer_priv
,
2630 sc
->transfer_datalen
,
2634 case TSTATE_CBI_SCLEAR
:
2635 if (err
) /* should not occur */
2636 kprintf("%s: CBI intr-in stall clear failed, %s\n",
2637 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
));
2639 /* Something really bad is going on. Reset the device */
2640 umass_cbi_reset(sc
, STATUS_CMD_FAILED
);
2643 /***** CBI Reset *****/
2644 case TSTATE_CBI_RESET1
:
2646 kprintf("%s: CBI reset failed, %s\n",
2647 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
));
2649 umass_clear_endpoint_stall(sc
,
2650 sc
->bulkin
, sc
->bulkin_pipe
, TSTATE_CBI_RESET2
,
2651 sc
->transfer_xfer
[XFER_CBI_RESET2
]);
2654 case TSTATE_CBI_RESET2
:
2655 if (err
) /* should not occur */
2656 kprintf("%s: CBI bulk-in stall clear failed, %s\n",
2657 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
));
2658 /* no error recovery, otherwise we end up in a loop */
2660 umass_clear_endpoint_stall(sc
,
2661 sc
->bulkout
, sc
->bulkout_pipe
, TSTATE_CBI_RESET3
,
2662 sc
->transfer_xfer
[XFER_CBI_RESET3
]);
2665 case TSTATE_CBI_RESET3
:
2666 if (err
) /* should not occur */
2667 kprintf("%s: CBI bulk-out stall clear failed, %s\n",
2668 device_get_nameunit(sc
->sc_dev
), usbd_errstr(err
));
2669 /* no error recovery, otherwise we end up in a loop */
2671 sc
->transfer_state
= TSTATE_IDLE
;
2672 if (sc
->transfer_priv
) {
2673 sc
->transfer_cb(sc
, sc
->transfer_priv
,
2674 sc
->transfer_datalen
,
2675 sc
->transfer_status
);
2681 /***** Default *****/
2683 panic("%s: Unknown state %d",
2684 device_get_nameunit(sc
->sc_dev
), sc
->transfer_state
);
2692 * CAM specific functions (used by SCSI, UFI, 8070i (ATAPI))
2696 umass_cam_attach_sim(struct umass_softc
*sc
)
2698 struct cam_devq
*devq
; /* Per device Queue */
2700 /* A HBA is attached to the CAM layer.
2702 * The CAM layer will then after a while start probing for
2703 * devices on the bus. The number of SIMs is limited to one.
2706 callout_init(&sc
->rescan_timeout
);
2707 devq
= cam_simq_alloc(1 /*maximum openings*/);
2711 sc
->umass_sim
= cam_sim_alloc(umass_cam_action
, umass_cam_poll
,
2714 device_get_unit(sc
->sc_dev
) /*unit number*/,
2716 1 /*maximum device openings*/,
2717 0 /*maximum tagged device openings*/,
2719 cam_simq_release(devq
);
2720 if (sc
->umass_sim
== NULL
)
2724 * If we could not register the bus we must immediately free the
2725 * sim so we do not attempt to deregister a bus later on that we
2726 * had not registered.
2728 if (xpt_bus_register(sc
->umass_sim
, device_get_unit(sc
->sc_dev
)) !=
2730 cam_sim_free(sc
->umass_sim
);
2731 sc
->umass_sim
= NULL
;
2739 umass_cam_rescan_callback(struct cam_periph
*periph
, union ccb
*ccb
)
2742 if (ccb
->ccb_h
.status
!= CAM_REQ_CMP
) {
2743 DPRINTF(UDMASS_SCSI
, ("%s:%d Rescan failed, 0x%04x\n",
2744 periph
->periph_name
, periph
->unit_number
,
2745 ccb
->ccb_h
.status
));
2747 DPRINTF(UDMASS_SCSI
, ("%s%d: Rescan succeeded\n",
2748 periph
->periph_name
, periph
->unit_number
));
2752 xpt_free_path(ccb
->ccb_h
.path
);
2753 kfree(ccb
, M_USBDEV
);
2757 * Rescan the SCSI bus to detect newly added devices. We use
2758 * an async rescan to avoid reentrancy issues.
2761 umass_cam_rescan(void *addr
)
2763 struct umass_softc
*sc
= (struct umass_softc
*) addr
;
2764 struct cam_path
*path
;
2767 ccb
= kmalloc(sizeof(union ccb
), M_USBDEV
, M_INTWAIT
|M_ZERO
);
2769 DPRINTF(UDMASS_SCSI
, ("scbus%d: scanning for %s:%d:%d:%d\n",
2770 cam_sim_path(sc
->umass_sim
),
2771 device_get_nameunit(sc
->sc_dev
), cam_sim_path(sc
->umass_sim
),
2772 device_get_unit(sc
->sc_dev
), CAM_LUN_WILDCARD
));
2774 if (xpt_create_path(&path
, xpt_periph
, cam_sim_path(sc
->umass_sim
),
2775 CAM_TARGET_WILDCARD
, CAM_LUN_WILDCARD
)
2777 kfree(ccb
, M_USBDEV
);
2781 xpt_setup_ccb(&ccb
->ccb_h
, path
, 5/*priority (low)*/);
2782 ccb
->ccb_h
.func_code
= XPT_SCAN_BUS
;
2783 ccb
->ccb_h
.cbfcnp
= umass_cam_rescan_callback
;
2784 ccb
->crcn
.flags
= CAM_FLAG_NONE
;
2785 xpt_action_async(ccb
);
2787 /* The scan is in progress now. */
2791 umass_cam_attach(struct umass_softc
*sc
)
2796 kprintf("%s:%d:%d:%d: Attached to scbus%d\n",
2797 device_get_nameunit(sc
->sc_dev
), cam_sim_path(sc
->umass_sim
),
2798 device_get_unit(sc
->sc_dev
), CAM_LUN_WILDCARD
,
2799 cam_sim_path(sc
->umass_sim
));
2803 * Notify CAM of the new device after a 0.2 second delay. Any
2804 * failure is benign, as the user can still do it by hand
2805 * (camcontrol rescan <busno>). Only do this if we are not
2806 * booting, because CAM does a scan after booting has
2807 * completed, when interrupts have been enabled.
2809 callout_reset(&sc
->rescan_timeout
, MS_TO_TICKS(200),
2810 umass_cam_rescan
, sc
);
2813 return(0); /* always succesfull */
2817 * detach from the CAM layer
2821 umass_cam_detach_sim(struct umass_softc
*sc
)
2823 callout_stop(&sc
->rescan_timeout
);
2824 if (sc
->umass_sim
) {
2825 xpt_bus_deregister(cam_sim_path(sc
->umass_sim
));
2826 cam_sim_free(sc
->umass_sim
);
2828 sc
->umass_sim
= NULL
;
2835 * CAM requests for action come through here
2839 umass_cam_action(struct cam_sim
*sim
, union ccb
*ccb
)
2841 struct umass_softc
*sc
= (struct umass_softc
*)sim
->softc
;
2843 /* The softc is still there, but marked as going away. umass_cam_detach
2844 * has not yet notified CAM of the lost device however.
2846 if (sc
&& (sc
->flags
& UMASS_FLAGS_GONE
)) {
2847 DPRINTF(UDMASS_SCSI
, ("%s:%d:%d:%d:func_code 0x%04x: "
2848 "Invalid target (gone)\n",
2849 device_get_nameunit(sc
->sc_dev
), cam_sim_path(sc
->umass_sim
),
2850 ccb
->ccb_h
.target_id
, ccb
->ccb_h
.target_lun
,
2851 ccb
->ccb_h
.func_code
));
2852 ccb
->ccb_h
.status
= CAM_TID_INVALID
;
2857 /* Verify, depending on the operation to perform, that we either got a
2858 * valid sc, because an existing target was referenced, or otherwise
2859 * the SIM is addressed.
2861 * This avoids bombing out at a kprintf and does give the CAM layer some
2862 * sensible feedback on errors.
2864 switch (ccb
->ccb_h
.func_code
) {
2867 case XPT_GET_TRAN_SETTINGS
:
2868 case XPT_SET_TRAN_SETTINGS
:
2869 case XPT_CALC_GEOMETRY
:
2870 /* the opcodes requiring a target. These should never occur. */
2872 kprintf("%s:%d:%d:%d:func_code 0x%04x: "
2873 "Invalid target (target needed)\n",
2874 DEVNAME_SIM
, 0, ccb
->ccb_h
.target_id
,
2875 ccb
->ccb_h
.target_lun
, ccb
->ccb_h
.func_code
);
2877 ccb
->ccb_h
.status
= CAM_TID_INVALID
;
2884 /* The opcodes sometimes aimed at a target (sc is valid),
2885 * sometimes aimed at the SIM (sc is invalid and target is
2886 * CAM_TARGET_WILDCARD)
2888 if (sc
== NULL
&& ccb
->ccb_h
.target_id
!= CAM_TARGET_WILDCARD
) {
2889 DPRINTF(UDMASS_SCSI
, ("%s:%d:%d:%d:func_code 0x%04x: "
2890 "Invalid target (no wildcard)\n",
2891 DEVNAME_SIM
, 0, ccb
->ccb_h
.target_id
,
2892 ccb
->ccb_h
.target_lun
, ccb
->ccb_h
.func_code
));
2894 ccb
->ccb_h
.status
= CAM_TID_INVALID
;
2900 /* XXX Hm, we should check the input parameters */
2904 /* Perform the requested action */
2905 switch (ccb
->ccb_h
.func_code
) {
2908 struct ccb_scsiio
*csio
= &ccb
->csio
; /* deref union */
2912 unsigned char *rcmd
;
2915 DPRINTF(UDMASS_SCSI
, ("%s:%d:%d:%d:XPT_SCSI_IO: "
2916 "cmd: 0x%02x, flags: 0x%02x, "
2917 "%db cmd/%db data/%db sense\n",
2918 device_get_nameunit(sc
->sc_dev
), cam_sim_path(sc
->umass_sim
),
2919 ccb
->ccb_h
.target_id
, ccb
->ccb_h
.target_lun
,
2920 csio
->cdb_io
.cdb_bytes
[0],
2921 ccb
->ccb_h
.flags
& CAM_DIR_MASK
,
2922 csio
->cdb_len
, csio
->dxfer_len
,
2925 /* clear the end of the buffer to make sure we don't send out
2928 DIF(UDMASS_SCSI
, if ((ccb
->ccb_h
.flags
& CAM_DIR_MASK
)
2930 umass_dump_buffer(sc
, csio
->data_ptr
,
2931 csio
->dxfer_len
, 48));
2933 if (sc
->transfer_state
!= TSTATE_IDLE
) {
2934 DPRINTF(UDMASS_SCSI
, ("%s:%d:%d:%d:XPT_SCSI_IO: "
2935 "I/O in progress, deferring (state %d, %s)\n",
2936 device_get_nameunit(sc
->sc_dev
), cam_sim_path(sc
->umass_sim
),
2937 ccb
->ccb_h
.target_id
, ccb
->ccb_h
.target_lun
,
2938 sc
->transfer_state
,states
[sc
->transfer_state
]));
2939 ccb
->ccb_h
.status
= CAM_SCSI_BUSY
;
2944 switch(ccb
->ccb_h
.flags
&CAM_DIR_MASK
) {
2955 ccb
->ccb_h
.status
= CAM_REQ_INPROG
| CAM_SIM_QUEUED
;
2958 if (csio
->ccb_h
.flags
& CAM_CDB_POINTER
) {
2959 cmd
= (unsigned char *) csio
->cdb_io
.cdb_ptr
;
2961 cmd
= (unsigned char *) &csio
->cdb_io
.cdb_bytes
;
2963 cmdlen
= csio
->cdb_len
;
2964 rcmd
= (unsigned char *) &sc
->cam_scsi_command
;
2965 rcmdlen
= sizeof(sc
->cam_scsi_command
);
2967 /* sc->transform will convert the command to the command
2968 * (format) needed by the specific command set and return
2969 * the converted command in a buffer pointed to be rcmd.
2970 * We pass in a buffer, but if the command does not
2971 * have to be transformed it returns a ptr to the original
2972 * buffer (see umass_scsi_transform).
2975 if (sc
->transform(sc
, cmd
, cmdlen
, &rcmd
, &rcmdlen
)) {
2977 * Handle EVPD inquiry for broken devices first
2978 * NO_INQUIRY also implies NO_INQUIRY_EVPD
2980 if ((sc
->quirks
& (NO_INQUIRY_EVPD
| NO_INQUIRY
)) &&
2981 rcmd
[0] == INQUIRY
&& (rcmd
[1] & SI_EVPD
)) {
2982 struct scsi_sense_data
*sense
;
2984 sense
= &ccb
->csio
.sense_data
;
2985 bzero(sense
, sizeof(*sense
));
2986 sense
->error_code
= SSD_CURRENT_ERROR
;
2987 sense
->flags
= SSD_KEY_ILLEGAL_REQUEST
;
2988 sense
->add_sense_code
= 0x24;
2989 sense
->extra_len
= 10;
2990 ccb
->csio
.scsi_status
= SCSI_STATUS_CHECK_COND
;
2991 ccb
->ccb_h
.status
= CAM_SCSI_STATUS_ERROR
|
2996 /* Return fake inquiry data for broken devices */
2997 if ((sc
->quirks
& NO_INQUIRY
) && rcmd
[0] == INQUIRY
) {
2998 struct ccb_scsiio
*csio
= &ccb
->csio
;
3000 memcpy(csio
->data_ptr
, &fake_inq_data
,
3001 sizeof(fake_inq_data
));
3002 csio
->scsi_status
= SCSI_STATUS_OK
;
3003 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
3007 if ((sc
->quirks
& FORCE_SHORT_INQUIRY
) &&
3008 rcmd
[0] == INQUIRY
) {
3009 csio
->dxfer_len
= SHORT_INQUIRY_LENGTH
;
3011 sc
->transfer(sc
, ccb
->ccb_h
.target_lun
, rcmd
, rcmdlen
,
3013 csio
->dxfer_len
, dir
, ccb
->ccb_h
.timeout
,
3014 umass_cam_cb
, (void *) ccb
);
3016 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
3024 struct ccb_pathinq
*cpi
= &ccb
->cpi
;
3026 DPRINTF(UDMASS_SCSI
, ("%s:%d:%d:%d:XPT_PATH_INQ:.\n",
3027 (sc
== NULL
? DEVNAME_SIM
: device_get_nameunit(sc
->sc_dev
)),
3028 (sc
== NULL
? 0 : cam_sim_path(sc
->umass_sim
)),
3029 ccb
->ccb_h
.target_id
, ccb
->ccb_h
.target_lun
));
3031 /* host specific information */
3032 cpi
->version_num
= 1;
3033 cpi
->hba_inquiry
= 0;
3034 cpi
->target_sprt
= 0;
3035 cpi
->hba_misc
= PIM_NO_6_BYTE
;
3036 cpi
->hba_eng_cnt
= 0;
3037 cpi
->max_target
= UMASS_SCSIID_MAX
; /* one target */
3038 cpi
->initiator_id
= UMASS_SCSIID_HOST
;
3039 strncpy(cpi
->sim_vid
, "FreeBSD", SIM_IDLEN
);
3040 strncpy(cpi
->hba_vid
, "USB SCSI", HBA_IDLEN
);
3041 strncpy(cpi
->dev_name
, cam_sim_name(sim
), DEV_IDLEN
);
3042 cpi
->unit_number
= cam_sim_unit(sim
);
3045 cpi
->base_transfer_speed
= 0;
3048 cpi
->bus_id
= device_get_unit(sc
->sc_dev
);
3050 if (sc
->quirks
& FLOPPY_SPEED
) {
3051 cpi
->base_transfer_speed
=
3052 UMASS_FLOPPY_TRANSFER_SPEED
;
3053 } else if (usbd_get_speed(sc
->sc_udev
) ==
3055 cpi
->base_transfer_speed
=
3056 UMASS_HIGH_TRANSFER_SPEED
;
3058 cpi
->base_transfer_speed
=
3059 UMASS_FULL_TRANSFER_SPEED
;
3061 cpi
->max_lun
= sc
->maxlun
;
3064 cpi
->ccb_h
.status
= CAM_REQ_CMP
;
3070 DPRINTF(UDMASS_SCSI
, ("%s:%d:%d:%d:XPT_RESET_DEV:.\n",
3071 device_get_nameunit(sc
->sc_dev
), cam_sim_path(sc
->umass_sim
),
3072 ccb
->ccb_h
.target_id
, ccb
->ccb_h
.target_lun
));
3074 ccb
->ccb_h
.status
= CAM_REQ_INPROG
;
3075 umass_reset(sc
, umass_cam_cb
, (void *) ccb
);
3078 case XPT_GET_TRAN_SETTINGS
:
3080 struct ccb_trans_settings
*cts
= &ccb
->cts
;
3081 cts
->protocol
= PROTO_SCSI
;
3082 cts
->protocol_version
= SCSI_REV_2
;
3083 cts
->transport
= XPORT_USB
;
3084 cts
->transport_version
= XPORT_VERSION_UNSPECIFIED
;
3085 cts
->xport_specific
.valid
= 0;
3087 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
3091 case XPT_SET_TRAN_SETTINGS
:
3093 DPRINTF(UDMASS_SCSI
, ("%s:%d:%d:%d:XPT_SET_TRAN_SETTINGS:.\n",
3094 device_get_nameunit(sc
->sc_dev
), cam_sim_path(sc
->umass_sim
),
3095 ccb
->ccb_h
.target_id
, ccb
->ccb_h
.target_lun
));
3097 ccb
->ccb_h
.status
= CAM_FUNC_NOTAVAIL
;
3101 case XPT_CALC_GEOMETRY
:
3103 cam_calc_geometry(&ccb
->ccg
, /*extended*/1);
3109 DPRINTF(UDMASS_SCSI
, ("%s:%d:%d:%d:XPT_NOOP:.\n",
3110 (sc
== NULL
? DEVNAME_SIM
: device_get_nameunit(sc
->sc_dev
)),
3111 (sc
== NULL
? 0 : cam_sim_path(sc
->umass_sim
)),
3112 ccb
->ccb_h
.target_id
, ccb
->ccb_h
.target_lun
));
3114 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
3119 DPRINTF(UDMASS_SCSI
, ("%s:%d:%d:%d:func_code 0x%04x: "
3120 "Not implemented\n",
3121 (sc
== NULL
? DEVNAME_SIM
: device_get_nameunit(sc
->sc_dev
)),
3122 (sc
== NULL
? 0 : cam_sim_path(sc
->umass_sim
)),
3123 ccb
->ccb_h
.target_id
, ccb
->ccb_h
.target_lun
,
3124 ccb
->ccb_h
.func_code
));
3126 ccb
->ccb_h
.status
= CAM_FUNC_NOTAVAIL
;
3133 umass_cam_poll(struct cam_sim
*sim
)
3135 struct umass_softc
*sc
= (struct umass_softc
*) sim
->softc
;
3137 KKASSERT(sc
!= NULL
);
3139 DPRINTF(UDMASS_SCSI
, ("%s: CAM poll\n",
3140 device_get_nameunit(sc
->sc_dev
)));
3142 usbd_set_polling(sc
->sc_udev
->bus
, 1);
3143 usbd_dopoll(sc
->iface
);
3144 usbd_set_polling(sc
->sc_udev
->bus
, 0);
3149 * finalise a completed CAM command
3153 umass_cam_cb(struct umass_softc
*sc
, void *priv
, int residue
, int status
)
3155 union ccb
*ccb
= (union ccb
*) priv
;
3156 struct ccb_scsiio
*csio
= &ccb
->csio
; /* deref union */
3158 csio
->resid
= residue
;
3162 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
3163 if ((sc
->quirks
& READ_CAPACITY_OFFBY1
) &&
3164 (ccb
->ccb_h
.func_code
== XPT_SCSI_IO
) &&
3165 (csio
->cdb_io
.cdb_bytes
[0] == READ_CAPACITY
)) {
3166 struct scsi_read_capacity_data
*rcap
;
3169 rcap
= (struct scsi_read_capacity_data
*)csio
->data_ptr
;
3170 maxsector
= scsi_4btoul(rcap
->addr
) - 1;
3171 scsi_ulto4b(maxsector
, rcap
->addr
);
3176 case STATUS_CMD_UNKNOWN
:
3177 case STATUS_CMD_FAILED
:
3178 switch (ccb
->ccb_h
.func_code
) {
3181 unsigned char *rcmd
;
3184 /* fetch sense data */
3185 /* the rest of the command was filled in at attach */
3186 sc
->cam_scsi_sense
.length
= csio
->sense_len
;
3188 DPRINTF(UDMASS_SCSI
,("%s: Fetching %db sense data\n",
3189 device_get_nameunit(sc
->sc_dev
), csio
->sense_len
));
3191 rcmd
= (unsigned char *) &sc
->cam_scsi_command
;
3192 rcmdlen
= sizeof(sc
->cam_scsi_command
);
3194 if (sc
->transform(sc
,
3195 (unsigned char *) &sc
->cam_scsi_sense
,
3196 sizeof(sc
->cam_scsi_sense
),
3198 if ((sc
->quirks
& FORCE_SHORT_INQUIRY
) && (rcmd
[0] == INQUIRY
)) {
3199 csio
->sense_len
= SHORT_INQUIRY_LENGTH
;
3201 sc
->transfer(sc
, ccb
->ccb_h
.target_lun
,
3204 csio
->sense_len
, DIR_IN
, ccb
->ccb_h
.timeout
,
3205 umass_cam_sense_cb
, (void *) ccb
);
3207 panic("transform(REQUEST_SENSE) failed");
3211 case XPT_RESET_DEV
: /* Reset failed */
3212 ccb
->ccb_h
.status
= CAM_REQ_CMP_ERR
;
3216 panic("umass_cam_cb called for func_code %d",
3217 ccb
->ccb_h
.func_code
);
3221 case STATUS_WIRE_FAILED
:
3222 /* the wire protocol failed and will have recovered
3223 * (hopefully). We return an error to CAM and let CAM retry
3224 * the command if necessary.
3226 ccb
->ccb_h
.status
= CAM_REQ_CMP_ERR
;
3230 panic("%s: Unknown status %d in umass_cam_cb",
3231 device_get_nameunit(sc
->sc_dev
), status
);
3235 /* Finalise a completed autosense operation
3238 umass_cam_sense_cb(struct umass_softc
*sc
, void *priv
, int residue
, int status
)
3240 union ccb
*ccb
= (union ccb
*) priv
;
3241 struct ccb_scsiio
*csio
= &ccb
->csio
; /* deref union */
3242 unsigned char *rcmd
;
3247 case STATUS_CMD_UNKNOWN
:
3248 case STATUS_CMD_FAILED
:
3249 /* Getting sense data always succeeds (apart from wire
3252 if ((sc
->quirks
& RS_NO_CLEAR_UA
)
3253 && csio
->cdb_io
.cdb_bytes
[0] == INQUIRY
3254 && (csio
->sense_data
.flags
& SSD_KEY
)
3255 == SSD_KEY_UNIT_ATTENTION
) {
3256 /* Ignore unit attention errors in the case where
3257 * the Unit Attention state is not cleared on
3258 * REQUEST SENSE. They will appear again at the next
3261 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
3262 } else if ((csio
->sense_data
.flags
& SSD_KEY
)
3263 == SSD_KEY_NO_SENSE
) {
3264 /* No problem after all (in the case of CBI without
3267 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
3268 } else if ((sc
->quirks
& RS_NO_CLEAR_UA
) &&
3269 (csio
->cdb_io
.cdb_bytes
[0] == READ_CAPACITY
) &&
3270 ((csio
->sense_data
.flags
& SSD_KEY
)
3271 == SSD_KEY_UNIT_ATTENTION
)) {
3273 * Some devices do not clear the unit attention error
3274 * on request sense. We insert a test unit ready
3275 * command to make sure we clear the unit attention
3276 * condition, then allow the retry to proceed as
3280 ccb
->ccb_h
.status
= CAM_SCSI_STATUS_ERROR
3281 | CAM_AUTOSNS_VALID
;
3282 csio
->scsi_status
= SCSI_STATUS_CHECK_COND
;
3288 DPRINTF(UDMASS_SCSI
,("%s: Doing a sneaky"
3289 "TEST_UNIT_READY\n",
3290 device_get_nameunit(sc
->sc_dev
)));
3292 /* the rest of the command was filled in at attach */
3294 rcmd
= (unsigned char *) &sc
->cam_scsi_command2
;
3295 rcmdlen
= sizeof(sc
->cam_scsi_command2
);
3297 if (sc
->transform(sc
,
3299 &sc
->cam_scsi_test_unit_ready
,
3300 sizeof(sc
->cam_scsi_test_unit_ready
),
3302 sc
->transfer(sc
, ccb
->ccb_h
.target_lun
,
3304 NULL
, 0, DIR_NONE
, ccb
->ccb_h
.timeout
,
3305 umass_cam_quirk_cb
, (void *) ccb
);
3307 panic("transform(TEST_UNIT_READY) failed");
3311 ccb
->ccb_h
.status
= CAM_SCSI_STATUS_ERROR
3312 | CAM_AUTOSNS_VALID
;
3313 csio
->scsi_status
= SCSI_STATUS_CHECK_COND
;
3319 DPRINTF(UDMASS_SCSI
, ("%s: Autosense failed, status %d\n",
3320 device_get_nameunit(sc
->sc_dev
), status
));
3321 ccb
->ccb_h
.status
= CAM_AUTOSENSE_FAIL
;
3327 * This completion code just handles the fact that we sent a test-unit-ready
3328 * after having previously failed a READ CAPACITY with CHECK_COND. Even
3329 * though this command succeeded, we have to tell CAM to retry.
3332 umass_cam_quirk_cb(struct umass_softc
*sc
, void *priv
, int residue
, int status
)
3334 union ccb
*ccb
= (union ccb
*) priv
;
3336 DPRINTF(UDMASS_SCSI
, ("%s: Test unit ready returned status %d\n",
3337 device_get_nameunit(sc
->sc_dev
), status
));
3339 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
3341 ccb
->ccb_h
.status
= CAM_SCSI_STATUS_ERROR
3342 | CAM_AUTOSNS_VALID
;
3343 ccb
->csio
.scsi_status
= SCSI_STATUS_CHECK_COND
;
3348 umass_driver_load(module_t mod
, int what
, void *arg
)
3354 return(usbd_driver_load(mod
, what
, arg
));
3359 * SCSI specific functions
3363 umass_scsi_transform(struct umass_softc
*sc
, unsigned char *cmd
, int cmdlen
,
3364 unsigned char **rcmd
, int *rcmdlen
)
3367 case TEST_UNIT_READY
:
3368 if (sc
->quirks
& NO_TEST_UNIT_READY
) {
3369 KASSERT(*rcmdlen
>= sizeof(struct scsi_start_stop_unit
),
3370 ("rcmdlen = %d < %ld, buffer too small",
3372 (long)sizeof(struct scsi_start_stop_unit
)));
3373 DPRINTF(UDMASS_SCSI
, ("%s: Converted TEST_UNIT_READY "
3374 "to START_UNIT\n", device_get_nameunit(sc
->sc_dev
)));
3375 memset(*rcmd
, 0, *rcmdlen
);
3376 (*rcmd
)[0] = START_STOP_UNIT
;
3377 (*rcmd
)[4] = SSS_START
;
3382 /* some drives wedge when asked for full inquiry information. */
3383 if (sc
->quirks
& FORCE_SHORT_INQUIRY
) {
3384 memcpy(*rcmd
, cmd
, cmdlen
);
3386 (*rcmd
)[4] = SHORT_INQUIRY_LENGTH
;
3391 *rcmd
= cmd
; /* We don't need to copy it */
3397 /* RBC specific functions */
3399 umass_rbc_transform(struct umass_softc
*sc
, unsigned char *cmd
, int cmdlen
,
3400 unsigned char **rcmd
, int *rcmdlen
)
3403 /* these commands are defined in RBC: */
3406 case START_STOP_UNIT
:
3407 case SYNCHRONIZE_CACHE
:
3409 case 0x2f: /* VERIFY_10 is absent from scsi_all.h??? */
3411 case MODE_SELECT_10
:
3413 case TEST_UNIT_READY
:
3415 /* The following commands are not listed in my copy of the RBC specs.
3416 * CAM however seems to want those, and at least the Sony DSC device
3417 * appears to support those as well */
3420 *rcmd
= cmd
; /* We don't need to copy it */
3423 /* All other commands are not legal in RBC */
3425 kprintf("%s: Unsupported RBC command 0x%02x",
3426 device_get_nameunit(sc
->sc_dev
), cmd
[0]);
3428 return 0; /* failure */
3433 * UFI specific functions
3436 umass_ufi_transform(struct umass_softc
*sc
, unsigned char *cmd
, int cmdlen
,
3437 unsigned char **rcmd
, int *rcmdlen
)
3439 /* A UFI command is always 12 bytes in length */
3440 KASSERT(*rcmdlen
>= UFI_COMMAND_LENGTH
,
3441 ("rcmdlen = %d < %d, buffer too small",
3442 *rcmdlen
, UFI_COMMAND_LENGTH
));
3444 *rcmdlen
= UFI_COMMAND_LENGTH
;
3445 memset(*rcmd
, 0, UFI_COMMAND_LENGTH
);
3448 /* Commands of which the format has been verified. They should work.
3449 * Copy the command into the (zeroed out) destination buffer.
3451 case TEST_UNIT_READY
:
3452 if (sc
->quirks
& NO_TEST_UNIT_READY
) {
3453 /* Some devices do not support this command.
3454 * Start Stop Unit should give the same results
3456 DPRINTF(UDMASS_UFI
, ("%s: Converted TEST_UNIT_READY "
3457 "to START_UNIT\n", device_get_nameunit(sc
->sc_dev
)));
3458 (*rcmd
)[0] = START_STOP_UNIT
;
3459 (*rcmd
)[4] = SSS_START
;
3461 memcpy(*rcmd
, cmd
, cmdlen
);
3468 case START_STOP_UNIT
:
3469 case SEND_DIAGNOSTIC
:
3474 case POSITION_TO_ELEMENT
: /* SEEK_10 */
3475 case MODE_SELECT_10
:
3479 memcpy(*rcmd
, cmd
, cmdlen
);
3482 /* Other UFI commands: FORMAT_UNIT, READ_FORMAT_CAPACITY,
3483 * VERIFY, WRITE_AND_VERIFY.
3484 * These should be checked whether they somehow can be made to fit.
3488 kprintf("%s: Unsupported UFI command 0x%02x\n",
3489 device_get_nameunit(sc
->sc_dev
), cmd
[0]);
3490 return 0; /* failure */
3495 * 8070i (ATAPI) specific functions
3498 umass_atapi_transform(struct umass_softc
*sc
, unsigned char *cmd
, int cmdlen
,
3499 unsigned char **rcmd
, int *rcmdlen
)
3501 /* An ATAPI command is always 12 bytes in length. */
3502 KASSERT(*rcmdlen
>= ATAPI_COMMAND_LENGTH
,
3503 ("rcmdlen = %d < %d, buffer too small",
3504 *rcmdlen
, ATAPI_COMMAND_LENGTH
));
3506 *rcmdlen
= ATAPI_COMMAND_LENGTH
;
3507 memset(*rcmd
, 0, ATAPI_COMMAND_LENGTH
);
3510 /* Commands of which the format has been verified. They should work.
3511 * Copy the command into the (zeroed out) destination buffer.
3514 memcpy(*rcmd
, cmd
, cmdlen
);
3515 /* some drives wedge when asked for full inquiry information. */
3516 if (sc
->quirks
& FORCE_SHORT_INQUIRY
)
3517 (*rcmd
)[4] = SHORT_INQUIRY_LENGTH
;
3520 case TEST_UNIT_READY
:
3521 if (sc
->quirks
& NO_TEST_UNIT_READY
) {
3522 KASSERT(*rcmdlen
>= sizeof(struct scsi_start_stop_unit
),
3523 ("rcmdlen = %d < %ld, buffer too small",
3525 (long)sizeof(struct scsi_start_stop_unit
)));
3526 DPRINTF(UDMASS_SCSI
, ("%s: Converted TEST_UNIT_READY "
3527 "to START_UNIT\n", device_get_nameunit(sc
->sc_dev
)));
3528 memset(*rcmd
, 0, *rcmdlen
);
3529 (*rcmd
)[0] = START_STOP_UNIT
;
3530 (*rcmd
)[4] = SSS_START
;
3536 * All commands are passed through, very likely it will just work
3537 * regardless whether we know these commands or not.
3539 memcpy(*rcmd
, cmd
, cmdlen
);
3545 /* (even the comment is missing) */
3547 DRIVER_MODULE(umass
, uhub
, umass_driver
, umass_devclass
, umass_driver_load
, 0);
3553 umass_bbb_dump_cbw(struct umass_softc
*sc
, umass_bbb_cbw_t
*cbw
)
3555 int clen
= cbw
->bCDBLength
;
3556 int dlen
= UGETDW(cbw
->dCBWDataTransferLength
);
3557 u_int8_t
*c
= cbw
->CBWCDB
;
3558 int tag
= UGETDW(cbw
->dCBWTag
);
3559 int flags
= cbw
->bCBWFlags
;
3561 DPRINTF(UDMASS_BBB
, ("%s: CBW %d: cmd = %db "
3562 "(0x%02x%02x%02x%02x%02x%02x%s), "
3563 "data = %db, dir = %s\n",
3564 device_get_nameunit(sc
->sc_dev
), tag
, clen
,
3565 c
[0], c
[1], c
[2], c
[3], c
[4], c
[5], (clen
> 6? "...":""),
3566 dlen
, (flags
== CBWFLAGS_IN
? "in":
3567 (flags
== CBWFLAGS_OUT
? "out":"<invalid>"))));
3571 umass_bbb_dump_csw(struct umass_softc
*sc
, umass_bbb_csw_t
*csw
)
3573 int sig
= UGETDW(csw
->dCSWSignature
);
3574 int tag
= UGETW(csw
->dCSWTag
);
3575 int res
= UGETDW(csw
->dCSWDataResidue
);
3576 int status
= csw
->bCSWStatus
;
3578 DPRINTF(UDMASS_BBB
, ("%s: CSW %d: sig = 0x%08x (%s), tag = %d, "
3579 "res = %d, status = 0x%02x (%s)\n", device_get_nameunit(sc
->sc_dev
),
3580 tag
, sig
, (sig
== CSWSIGNATURE
? "valid":"invalid"),
3582 status
, (status
== CSWSTATUS_GOOD
? "good":
3583 (status
== CSWSTATUS_FAILED
? "failed":
3584 (status
== CSWSTATUS_PHASE
? "phase":"<invalid>")))));
3588 umass_cbi_dump_cmd(struct umass_softc
*sc
, void *cmd
, int cmdlen
)
3591 int dir
= sc
->transfer_dir
;
3593 DPRINTF(UDMASS_BBB
, ("%s: cmd = %db "
3594 "(0x%02x%02x%02x%02x%02x%02x%s), "
3595 "data = %db, dir = %s\n",
3596 device_get_nameunit(sc
->sc_dev
), cmdlen
,
3597 c
[0], c
[1], c
[2], c
[3], c
[4], c
[5], (cmdlen
> 6? "...":""),
3598 sc
->transfer_datalen
,
3599 (dir
== DIR_IN
? "in":
3600 (dir
== DIR_OUT
? "out":
3601 (dir
== DIR_NONE
? "no data phase": "<invalid>")))));
3605 umass_dump_buffer(struct umass_softc
*sc
, u_int8_t
*buffer
, int buflen
,
3616 ksprintf(s2
, " buffer=%p, buflen=%d", buffer
, buflen
);
3617 for (i
= 0; i
< buflen
&& i
< printlen
; i
++) {
3619 if (j
== 0 && i
!= 0) {
3620 DPRINTF(UDMASS_GEN
, ("%s: 0x %s%s\n",
3621 device_get_nameunit(sc
->sc_dev
), s1
, s2
));
3624 ksprintf(&s1
[j
*2], "%02x", buffer
[i
] & 0xff);
3626 if (buflen
> printlen
)
3627 ksprintf(s3
, " ...");
3628 DPRINTF(UDMASS_GEN
, ("%s: 0x %s%s%s\n",
3629 device_get_nameunit(sc
->sc_dev
), s1
, s2
, s3
));