| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: umass.c,v 1.130 2008/12/12 05:35:11 jmorse Exp $ */ | | 1 | /* $NetBSD: umass.c,v 1.131 2009/03/17 19:12:17 dyoung Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2003 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2003 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Charles M. Hannum. | | 8 | * by Charles M. Hannum. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -114,27 +114,27 @@ | | | @@ -114,27 +114,27 @@ |
114 | | | 114 | |
115 | /* | | 115 | /* |
116 | * The SCSI related part of this driver has been derived from the | | 116 | * The SCSI related part of this driver has been derived from the |
117 | * dev/ppbus/vpo.c driver, by Nicolas Souchu (nsouch@freebsd.org). | | 117 | * dev/ppbus/vpo.c driver, by Nicolas Souchu (nsouch@freebsd.org). |
118 | * | | 118 | * |
119 | * The CAM layer uses so called actions which are messages sent to the host | | 119 | * The CAM layer uses so called actions which are messages sent to the host |
120 | * adapter for completion. The actions come in through umass_cam_action. The | | 120 | * adapter for completion. The actions come in through umass_cam_action. The |
121 | * appropriate block of routines is called depending on the transport protocol | | 121 | * appropriate block of routines is called depending on the transport protocol |
122 | * in use. When the transfer has finished, these routines call | | 122 | * in use. When the transfer has finished, these routines call |
123 | * umass_cam_cb again to complete the CAM command. | | 123 | * umass_cam_cb again to complete the CAM command. |
124 | */ | | 124 | */ |
125 | | | 125 | |
126 | #include <sys/cdefs.h> | | 126 | #include <sys/cdefs.h> |
127 | __KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.130 2008/12/12 05:35:11 jmorse Exp $"); | | 127 | __KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.131 2009/03/17 19:12:17 dyoung Exp $"); |
128 | | | 128 | |
129 | #include "atapibus.h" | | 129 | #include "atapibus.h" |
130 | #include "scsibus.h" | | 130 | #include "scsibus.h" |
131 | #include "wd.h" | | 131 | #include "wd.h" |
132 | | | 132 | |
133 | #include <sys/param.h> | | 133 | #include <sys/param.h> |
134 | #include <sys/systm.h> | | 134 | #include <sys/systm.h> |
135 | #include <sys/kernel.h> | | 135 | #include <sys/kernel.h> |
136 | #include <sys/conf.h> | | 136 | #include <sys/conf.h> |
137 | #if defined(__NetBSD__) || defined(__OpenBSD__) | | 137 | #if defined(__NetBSD__) || defined(__OpenBSD__) |
138 | #include <sys/buf.h> | | 138 | #include <sys/buf.h> |
139 | #include <sys/device.h> | | 139 | #include <sys/device.h> |
140 | #include <sys/malloc.h> | | 140 | #include <sys/malloc.h> |
| @@ -178,27 +178,35 @@ const char *states[TSTATE_STATES+1] = { | | | @@ -178,27 +178,35 @@ const char *states[TSTATE_STATES+1] = { |
178 | "CBI Command", | | 178 | "CBI Command", |
179 | "CBI Data", | | 179 | "CBI Data", |
180 | "CBI Status", | | 180 | "CBI Status", |
181 | "CBI Data bulk-in/-out clear stall", | | 181 | "CBI Data bulk-in/-out clear stall", |
182 | "CBI Status intr-in clear stall", | | 182 | "CBI Status intr-in clear stall", |
183 | "CBI Reset", | | 183 | "CBI Reset", |
184 | "CBI bulk-in clear stall", | | 184 | "CBI bulk-in clear stall", |
185 | "CBI bulk-out clear stall", | | 185 | "CBI bulk-out clear stall", |
186 | NULL | | 186 | NULL |
187 | }; | | 187 | }; |
188 | #endif | | 188 | #endif |
189 | | | 189 | |
190 | /* USB device probe/attach/detach functions */ | | 190 | /* USB device probe/attach/detach functions */ |
191 | USB_DECLARE_DRIVER(umass); | | 191 | int umass_match(device_t, cfdata_t, void *); |
| | | 192 | void umass_attach(device_t, device_t, void *); |
| | | 193 | int umass_detach(device_t, int); |
| | | 194 | static void umass_childdet(device_t, device_t); |
| | | 195 | int umass_activate(device_t, enum devact); |
| | | 196 | extern struct cfdriver umass_cd; |
| | | 197 | CFATTACH_DECL2_NEW(umass, sizeof(struct umass_softc), umass_match, umass_attach, |
| | | 198 | umass_detach, umass_activate, NULL, umass_childdet); |
| | | 199 | |
192 | Static void umass_disco(struct umass_softc *sc); | | 200 | Static void umass_disco(struct umass_softc *sc); |
193 | | | 201 | |
194 | /* generic transfer functions */ | | 202 | /* generic transfer functions */ |
195 | Static usbd_status umass_setup_transfer(struct umass_softc *sc, | | 203 | Static usbd_status umass_setup_transfer(struct umass_softc *sc, |
196 | usbd_pipe_handle pipe, | | 204 | usbd_pipe_handle pipe, |
197 | void *buffer, int buflen, int flags, | | 205 | void *buffer, int buflen, int flags, |
198 | usbd_xfer_handle xfer); | | 206 | usbd_xfer_handle xfer); |
199 | Static usbd_status umass_setup_ctrl_transfer(struct umass_softc *sc, | | 207 | Static usbd_status umass_setup_ctrl_transfer(struct umass_softc *sc, |
200 | usb_device_request_t *req, | | 208 | usb_device_request_t *req, |
201 | void *buffer, int buflen, int flags, | | 209 | void *buffer, int buflen, int flags, |
202 | usbd_xfer_handle xfer); | | 210 | usbd_xfer_handle xfer); |
203 | Static void umass_clear_endpoint_stall(struct umass_softc *sc, int endpt, | | 211 | Static void umass_clear_endpoint_stall(struct umass_softc *sc, int endpt, |
204 | usbd_xfer_handle xfer); | | 212 | usbd_xfer_handle xfer); |
| @@ -239,29 +247,30 @@ const struct umass_wire_methods umass_cb | | | @@ -239,29 +247,30 @@ const struct umass_wire_methods umass_cb |
239 | Static void umass_bbb_dump_cbw(struct umass_softc *sc, | | 247 | Static void umass_bbb_dump_cbw(struct umass_softc *sc, |
240 | umass_bbb_cbw_t *cbw); | | 248 | umass_bbb_cbw_t *cbw); |
241 | Static void umass_bbb_dump_csw(struct umass_softc *sc, | | 249 | Static void umass_bbb_dump_csw(struct umass_softc *sc, |
242 | umass_bbb_csw_t *csw); | | 250 | umass_bbb_csw_t *csw); |
243 | Static void umass_dump_buffer(struct umass_softc *sc, u_int8_t *buffer, | | 251 | Static void umass_dump_buffer(struct umass_softc *sc, u_int8_t *buffer, |
244 | int buflen, int printlen); | | 252 | int buflen, int printlen); |
245 | #endif | | 253 | #endif |
246 | | | 254 | |
247 | | | 255 | |
248 | /* | | 256 | /* |
249 | * USB device probe/attach/detach | | 257 | * USB device probe/attach/detach |
250 | */ | | 258 | */ |
251 | | | 259 | |
252 | USB_MATCH(umass) | | 260 | int |
| | | 261 | umass_match(device_t parent, cfdata_t match, void *aux) |
253 | { | | 262 | { |
254 | USB_IFMATCH_START(umass, uaa); | | 263 | struct usbif_attach_arg *uaa = aux; |
255 | const struct umass_quirk *quirk; | | 264 | const struct umass_quirk *quirk; |
256 | | | 265 | |
257 | quirk = umass_lookup(uaa->vendor, uaa->product); | | 266 | quirk = umass_lookup(uaa->vendor, uaa->product); |
258 | if (quirk != NULL && quirk->uq_match != UMASS_QUIRK_USE_DEFAULTMATCH) | | 267 | if (quirk != NULL && quirk->uq_match != UMASS_QUIRK_USE_DEFAULTMATCH) |
259 | return (quirk->uq_match); | | 268 | return (quirk->uq_match); |
260 | | | 269 | |
261 | if (uaa->class != UICLASS_MASS) | | 270 | if (uaa->class != UICLASS_MASS) |
262 | return (UMATCH_NONE); | | 271 | return (UMATCH_NONE); |
263 | | | 272 | |
264 | switch (uaa->subclass) { | | 273 | switch (uaa->subclass) { |
265 | case UISUBCLASS_RBC: | | 274 | case UISUBCLASS_RBC: |
266 | case UISUBCLASS_SFF8020I: | | 275 | case UISUBCLASS_SFF8020I: |
267 | case UISUBCLASS_QIC157: | | 276 | case UISUBCLASS_QIC157: |
| @@ -276,41 +285,44 @@ USB_MATCH(umass) | | | @@ -276,41 +285,44 @@ USB_MATCH(umass) |
276 | switch (uaa->proto) { | | 285 | switch (uaa->proto) { |
277 | case UIPROTO_MASS_CBI_I: | | 286 | case UIPROTO_MASS_CBI_I: |
278 | case UIPROTO_MASS_CBI: | | 287 | case UIPROTO_MASS_CBI: |
279 | case UIPROTO_MASS_BBB_OLD: | | 288 | case UIPROTO_MASS_BBB_OLD: |
280 | case UIPROTO_MASS_BBB: | | 289 | case UIPROTO_MASS_BBB: |
281 | break; | | 290 | break; |
282 | default: | | 291 | default: |
283 | return (UMATCH_IFACECLASS_IFACESUBCLASS); | | 292 | return (UMATCH_IFACECLASS_IFACESUBCLASS); |
284 | } | | 293 | } |
285 | | | 294 | |
286 | return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO); | | 295 | return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO); |
287 | } | | 296 | } |
288 | | | 297 | |
289 | USB_ATTACH(umass) | | 298 | void |
| | | 299 | umass_attach(device_t parent, device_t self, void *aux) |
290 | { | | 300 | { |
291 | USB_IFATTACH_START(umass, sc, uaa); | | 301 | struct umass_softc *sc = device_private(self); |
| | | 302 | struct usbif_attach_arg *uaa = aux; |
292 | const struct umass_quirk *quirk; | | 303 | const struct umass_quirk *quirk; |
293 | usb_interface_descriptor_t *id; | | 304 | usb_interface_descriptor_t *id; |
294 | usb_endpoint_descriptor_t *ed; | | 305 | usb_endpoint_descriptor_t *ed; |
295 | const char *sWire, *sCommand; | | 306 | const char *sWire, *sCommand; |
296 | char *devinfop; | | 307 | char *devinfop; |
297 | usbd_status err; | | 308 | usbd_status err; |
298 | int i, bno, error; | | 309 | int i, bno, error; |
299 | | | 310 | |
300 | sc->sc_dev = self; | | 311 | sc->sc_dev = self; |
301 | | | 312 | |
302 | devinfop = usbd_devinfo_alloc(uaa->device, 0); | | 313 | devinfop = usbd_devinfo_alloc(uaa->device, 0); |
303 | USB_ATTACH_SETUP; | | 314 | aprint_naive("\n"); |
| | | 315 | aprint_normal("\n"); |
304 | aprint_normal_dev(self, "%s\n", devinfop); | | 316 | aprint_normal_dev(self, "%s\n", devinfop); |
305 | usbd_devinfo_free(devinfop); | | 317 | usbd_devinfo_free(devinfop); |
306 | | | 318 | |
307 | sc->sc_udev = uaa->device; | | 319 | sc->sc_udev = uaa->device; |
308 | sc->sc_iface = uaa->iface; | | 320 | sc->sc_iface = uaa->iface; |
309 | sc->sc_ifaceno = uaa->ifaceno; | | 321 | sc->sc_ifaceno = uaa->ifaceno; |
310 | | | 322 | |
311 | quirk = umass_lookup(uaa->vendor, uaa->product); | | 323 | quirk = umass_lookup(uaa->vendor, uaa->product); |
312 | if (quirk != NULL) { | | 324 | if (quirk != NULL) { |
313 | sc->sc_wire = quirk->uq_wire; | | 325 | sc->sc_wire = quirk->uq_wire; |
314 | sc->sc_cmd = quirk->uq_cmd; | | 326 | sc->sc_cmd = quirk->uq_cmd; |
315 | sc->sc_quirks = quirk->uq_flags; | | 327 | sc->sc_quirks = quirk->uq_flags; |
316 | sc->sc_busquirks = quirk->uq_busquirks; | | 328 | sc->sc_busquirks = quirk->uq_busquirks; |
| @@ -329,54 +341,54 @@ USB_ATTACH(umass) | | | @@ -329,54 +341,54 @@ USB_ATTACH(umass) |
329 | case UIPROTO_MASS_CBI: | | 341 | case UIPROTO_MASS_CBI: |
330 | sc->sc_wire = UMASS_WPROTO_CBI; | | 342 | sc->sc_wire = UMASS_WPROTO_CBI; |
331 | break; | | 343 | break; |
332 | case UIPROTO_MASS_CBI_I: | | 344 | case UIPROTO_MASS_CBI_I: |
333 | sc->sc_wire = UMASS_WPROTO_CBI_I; | | 345 | sc->sc_wire = UMASS_WPROTO_CBI_I; |
334 | break; | | 346 | break; |
335 | case UIPROTO_MASS_BBB: | | 347 | case UIPROTO_MASS_BBB: |
336 | case UIPROTO_MASS_BBB_OLD: | | 348 | case UIPROTO_MASS_BBB_OLD: |
337 | sc->sc_wire = UMASS_WPROTO_BBB; | | 349 | sc->sc_wire = UMASS_WPROTO_BBB; |
338 | break; | | 350 | break; |
339 | default: | | 351 | default: |
340 | DPRINTF(UDMASS_GEN, | | 352 | DPRINTF(UDMASS_GEN, |
341 | ("%s: Unsupported wire protocol %u\n", | | 353 | ("%s: Unsupported wire protocol %u\n", |
342 | USBDEVNAME(sc->sc_dev), | | 354 | device_xname(sc->sc_dev), |
343 | uaa->proto)); | | 355 | uaa->proto)); |
344 | USB_ATTACH_ERROR_RETURN; | | 356 | return; |
345 | } | | 357 | } |
346 | } | | 358 | } |
347 | | | 359 | |
348 | if (sc->sc_cmd == UMASS_CPROTO_UNSPEC) { | | 360 | if (sc->sc_cmd == UMASS_CPROTO_UNSPEC) { |
349 | switch (uaa->subclass) { | | 361 | switch (uaa->subclass) { |
350 | case UISUBCLASS_SCSI: | | 362 | case UISUBCLASS_SCSI: |
351 | sc->sc_cmd = UMASS_CPROTO_SCSI; | | 363 | sc->sc_cmd = UMASS_CPROTO_SCSI; |
352 | break; | | 364 | break; |
353 | case UISUBCLASS_UFI: | | 365 | case UISUBCLASS_UFI: |
354 | sc->sc_cmd = UMASS_CPROTO_UFI; | | 366 | sc->sc_cmd = UMASS_CPROTO_UFI; |
355 | break; | | 367 | break; |
356 | case UISUBCLASS_SFF8020I: | | 368 | case UISUBCLASS_SFF8020I: |
357 | case UISUBCLASS_SFF8070I: | | 369 | case UISUBCLASS_SFF8070I: |
358 | case UISUBCLASS_QIC157: | | 370 | case UISUBCLASS_QIC157: |
359 | sc->sc_cmd = UMASS_CPROTO_ATAPI; | | 371 | sc->sc_cmd = UMASS_CPROTO_ATAPI; |
360 | break; | | 372 | break; |
361 | case UISUBCLASS_RBC: | | 373 | case UISUBCLASS_RBC: |
362 | sc->sc_cmd = UMASS_CPROTO_RBC; | | 374 | sc->sc_cmd = UMASS_CPROTO_RBC; |
363 | break; | | 375 | break; |
364 | default: | | 376 | default: |
365 | DPRINTF(UDMASS_GEN, | | 377 | DPRINTF(UDMASS_GEN, |
366 | ("%s: Unsupported command protocol %u\n", | | 378 | ("%s: Unsupported command protocol %u\n", |
367 | USBDEVNAME(sc->sc_dev), | | 379 | device_xname(sc->sc_dev), |
368 | uaa->subclass)); | | 380 | uaa->subclass)); |
369 | USB_ATTACH_ERROR_RETURN; | | 381 | return; |
370 | } | | 382 | } |
371 | } | | 383 | } |
372 | | | 384 | |
373 | switch (sc->sc_wire) { | | 385 | switch (sc->sc_wire) { |
374 | case UMASS_WPROTO_CBI: | | 386 | case UMASS_WPROTO_CBI: |
375 | sWire = "CBI"; | | 387 | sWire = "CBI"; |
376 | break; | | 388 | break; |
377 | case UMASS_WPROTO_CBI_I: | | 389 | case UMASS_WPROTO_CBI_I: |
378 | sWire = "CBI with CCI"; | | 390 | sWire = "CBI with CCI"; |
379 | break; | | 391 | break; |
380 | case UMASS_WPROTO_BBB: | | 392 | case UMASS_WPROTO_BBB: |
381 | sWire = "Bulk-Only"; | | 393 | sWire = "Bulk-Only"; |
382 | break; | | 394 | break; |
| @@ -403,194 +415,194 @@ USB_ATTACH(umass) | | | @@ -403,194 +415,194 @@ USB_ATTACH(umass) |
403 | break; | | 415 | break; |
404 | default: | | 416 | default: |
405 | sCommand = "unknown"; | | 417 | sCommand = "unknown"; |
406 | break; | | 418 | break; |
407 | } | | 419 | } |
408 | | | 420 | |
409 | aprint_normal_dev(self, "using %s over %s\n", sCommand, sWire); | | 421 | aprint_normal_dev(self, "using %s over %s\n", sCommand, sWire); |
410 | | | 422 | |
411 | if (quirk != NULL && quirk->uq_init != NULL) { | | 423 | if (quirk != NULL && quirk->uq_init != NULL) { |
412 | err = (*quirk->uq_init)(sc); | | 424 | err = (*quirk->uq_init)(sc); |
413 | if (err) { | | 425 | if (err) { |
414 | aprint_error_dev(self, "quirk init failed\n"); | | 426 | aprint_error_dev(self, "quirk init failed\n"); |
415 | umass_disco(sc); | | 427 | umass_disco(sc); |
416 | USB_ATTACH_ERROR_RETURN; | | 428 | return; |
417 | } | | 429 | } |
418 | } | | 430 | } |
419 | | | 431 | |
420 | /* | | 432 | /* |
421 | * In addition to the Control endpoint the following endpoints | | 433 | * In addition to the Control endpoint the following endpoints |
422 | * are required: | | 434 | * are required: |
423 | * a) bulk-in endpoint. | | 435 | * a) bulk-in endpoint. |
424 | * b) bulk-out endpoint. | | 436 | * b) bulk-out endpoint. |
425 | * and for Control/Bulk/Interrupt with CCI (CBI_I) | | 437 | * and for Control/Bulk/Interrupt with CCI (CBI_I) |
426 | * c) intr-in | | 438 | * c) intr-in |
427 | * | | 439 | * |
428 | * The endpoint addresses are not fixed, so we have to read them | | 440 | * The endpoint addresses are not fixed, so we have to read them |
429 | * from the device descriptors of the current interface. | | 441 | * from the device descriptors of the current interface. |
430 | */ | | 442 | */ |
431 | id = usbd_get_interface_descriptor(sc->sc_iface); | | 443 | id = usbd_get_interface_descriptor(sc->sc_iface); |
432 | for (i = 0 ; i < id->bNumEndpoints ; i++) { | | 444 | for (i = 0 ; i < id->bNumEndpoints ; i++) { |
433 | ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i); | | 445 | ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i); |
434 | if (ed == NULL) { | | 446 | if (ed == NULL) { |
435 | aprint_error_dev(self, | | 447 | aprint_error_dev(self, |
436 | "could not read endpoint descriptor\n"); | | 448 | "could not read endpoint descriptor\n"); |
437 | USB_ATTACH_ERROR_RETURN; | | 449 | return; |
438 | } | | 450 | } |
439 | if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN | | 451 | if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN |
440 | && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { | | 452 | && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { |
441 | sc->sc_epaddr[UMASS_BULKIN] = ed->bEndpointAddress; | | 453 | sc->sc_epaddr[UMASS_BULKIN] = ed->bEndpointAddress; |
442 | } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT | | 454 | } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT |
443 | && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { | | 455 | && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { |
444 | sc->sc_epaddr[UMASS_BULKOUT] = ed->bEndpointAddress; | | 456 | sc->sc_epaddr[UMASS_BULKOUT] = ed->bEndpointAddress; |
445 | } else if (sc->sc_wire == UMASS_WPROTO_CBI_I | | 457 | } else if (sc->sc_wire == UMASS_WPROTO_CBI_I |
446 | && UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN | | 458 | && UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN |
447 | && (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) { | | 459 | && (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) { |
448 | sc->sc_epaddr[UMASS_INTRIN] = ed->bEndpointAddress; | | 460 | sc->sc_epaddr[UMASS_INTRIN] = ed->bEndpointAddress; |
449 | #ifdef UMASS_DEBUG | | 461 | #ifdef UMASS_DEBUG |
450 | if (UGETW(ed->wMaxPacketSize) > 2) { | | 462 | if (UGETW(ed->wMaxPacketSize) > 2) { |
451 | DPRINTF(UDMASS_CBI, ("%s: intr size is %d\n", | | 463 | DPRINTF(UDMASS_CBI, ("%s: intr size is %d\n", |
452 | USBDEVNAME(sc->sc_dev), | | 464 | device_xname(sc->sc_dev), |
453 | UGETW(ed->wMaxPacketSize))); | | 465 | UGETW(ed->wMaxPacketSize))); |
454 | } | | 466 | } |
455 | #endif | | 467 | #endif |
456 | } | | 468 | } |
457 | } | | 469 | } |
458 | | | 470 | |
459 | /* check whether we found all the endpoints we need */ | | 471 | /* check whether we found all the endpoints we need */ |
460 | if (!sc->sc_epaddr[UMASS_BULKIN] || !sc->sc_epaddr[UMASS_BULKOUT] || | | 472 | if (!sc->sc_epaddr[UMASS_BULKIN] || !sc->sc_epaddr[UMASS_BULKOUT] || |
461 | (sc->sc_wire == UMASS_WPROTO_CBI_I && | | 473 | (sc->sc_wire == UMASS_WPROTO_CBI_I && |
462 | !sc->sc_epaddr[UMASS_INTRIN])) { | | 474 | !sc->sc_epaddr[UMASS_INTRIN])) { |
463 | aprint_error_dev(self, "endpoint not found %u/%u/%u\n", | | 475 | aprint_error_dev(self, "endpoint not found %u/%u/%u\n", |
464 | sc->sc_epaddr[UMASS_BULKIN], | | 476 | sc->sc_epaddr[UMASS_BULKIN], |
465 | sc->sc_epaddr[UMASS_BULKOUT], | | 477 | sc->sc_epaddr[UMASS_BULKOUT], |
466 | sc->sc_epaddr[UMASS_INTRIN]); | | 478 | sc->sc_epaddr[UMASS_INTRIN]); |
467 | USB_ATTACH_ERROR_RETURN; | | 479 | return; |
468 | } | | 480 | } |
469 | | | 481 | |
470 | /* | | 482 | /* |
471 | * Get the maximum LUN supported by the device. | | 483 | * Get the maximum LUN supported by the device. |
472 | */ | | 484 | */ |
473 | if (sc->sc_wire == UMASS_WPROTO_BBB && | | 485 | if (sc->sc_wire == UMASS_WPROTO_BBB && |
474 | (sc->sc_quirks & UMASS_QUIRK_NOGETMAXLUN) == 0) { | | 486 | (sc->sc_quirks & UMASS_QUIRK_NOGETMAXLUN) == 0) { |
475 | err = umass_bbb_get_max_lun(sc, &sc->maxlun); | | 487 | err = umass_bbb_get_max_lun(sc, &sc->maxlun); |
476 | if (err) { | | 488 | if (err) { |
477 | aprint_error_dev(self, "unable to get Max Lun: %s\n", | | 489 | aprint_error_dev(self, "unable to get Max Lun: %s\n", |
478 | usbd_errstr(err)); | | 490 | usbd_errstr(err)); |
479 | USB_ATTACH_ERROR_RETURN; | | 491 | return; |
480 | } | | 492 | } |
481 | if (sc->maxlun > 0) | | 493 | if (sc->maxlun > 0) |
482 | sc->sc_busquirks |= PQUIRK_FORCELUNS; | | 494 | sc->sc_busquirks |= PQUIRK_FORCELUNS; |
483 | } else { | | 495 | } else { |
484 | sc->maxlun = 0; | | 496 | sc->maxlun = 0; |
485 | } | | 497 | } |
486 | | | 498 | |
487 | /* Open the bulk-in and -out pipe */ | | 499 | /* Open the bulk-in and -out pipe */ |
488 | DPRINTF(UDMASS_USB, ("%s: opening iface %p epaddr %d for BULKOUT\n", | | 500 | DPRINTF(UDMASS_USB, ("%s: opening iface %p epaddr %d for BULKOUT\n", |
489 | USBDEVNAME(sc->sc_dev), sc->sc_iface, | | 501 | device_xname(sc->sc_dev), sc->sc_iface, |
490 | sc->sc_epaddr[UMASS_BULKOUT])); | | 502 | sc->sc_epaddr[UMASS_BULKOUT])); |
491 | err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_BULKOUT], | | 503 | err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_BULKOUT], |
492 | USBD_EXCLUSIVE_USE, | | 504 | USBD_EXCLUSIVE_USE, |
493 | &sc->sc_pipe[UMASS_BULKOUT]); | | 505 | &sc->sc_pipe[UMASS_BULKOUT]); |
494 | if (err) { | | 506 | if (err) { |
495 | aprint_error_dev(self, "cannot open %u-out pipe (bulk)\n", | | 507 | aprint_error_dev(self, "cannot open %u-out pipe (bulk)\n", |
496 | sc->sc_epaddr[UMASS_BULKOUT]); | | 508 | sc->sc_epaddr[UMASS_BULKOUT]); |
497 | umass_disco(sc); | | 509 | umass_disco(sc); |
498 | USB_ATTACH_ERROR_RETURN; | | 510 | return; |
499 | } | | 511 | } |
500 | DPRINTF(UDMASS_USB, ("%s: opening iface %p epaddr %d for BULKIN\n", | | 512 | DPRINTF(UDMASS_USB, ("%s: opening iface %p epaddr %d for BULKIN\n", |
501 | USBDEVNAME(sc->sc_dev), sc->sc_iface, | | 513 | device_xname(sc->sc_dev), sc->sc_iface, |
502 | sc->sc_epaddr[UMASS_BULKIN])); | | 514 | sc->sc_epaddr[UMASS_BULKIN])); |
503 | err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_BULKIN], | | 515 | err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_BULKIN], |
504 | USBD_EXCLUSIVE_USE, &sc->sc_pipe[UMASS_BULKIN]); | | 516 | USBD_EXCLUSIVE_USE, &sc->sc_pipe[UMASS_BULKIN]); |
505 | if (err) { | | 517 | if (err) { |
506 | aprint_error_dev(self, "could not open %u-in pipe (bulk)\n", | | 518 | aprint_error_dev(self, "could not open %u-in pipe (bulk)\n", |
507 | sc->sc_epaddr[UMASS_BULKIN]); | | 519 | sc->sc_epaddr[UMASS_BULKIN]); |
508 | umass_disco(sc); | | 520 | umass_disco(sc); |
509 | USB_ATTACH_ERROR_RETURN; | | 521 | return; |
510 | } | | 522 | } |
511 | /* | | 523 | /* |
512 | * Open the intr-in pipe if the protocol is CBI with CCI. | | 524 | * Open the intr-in pipe if the protocol is CBI with CCI. |
513 | * Note: early versions of the Zip drive do have an interrupt pipe, but | | 525 | * Note: early versions of the Zip drive do have an interrupt pipe, but |
514 | * this pipe is unused | | 526 | * this pipe is unused |
515 | * | | 527 | * |
516 | * We do not open the interrupt pipe as an interrupt pipe, but as a | | 528 | * We do not open the interrupt pipe as an interrupt pipe, but as a |
517 | * normal bulk endpoint. We send an IN transfer down the wire at the | | 529 | * normal bulk endpoint. We send an IN transfer down the wire at the |
518 | * appropriate time, because we know exactly when to expect data on | | 530 | * appropriate time, because we know exactly when to expect data on |
519 | * that endpoint. This saves bandwidth, but more important, makes the | | 531 | * that endpoint. This saves bandwidth, but more important, makes the |
520 | * code for handling the data on that endpoint simpler. No data | | 532 | * code for handling the data on that endpoint simpler. No data |
521 | * arriving concurrently. | | 533 | * arriving concurrently. |
522 | */ | | 534 | */ |
523 | if (sc->sc_wire == UMASS_WPROTO_CBI_I) { | | 535 | if (sc->sc_wire == UMASS_WPROTO_CBI_I) { |
524 | DPRINTF(UDMASS_USB, ("%s: opening iface %p epaddr %d for INTRIN\n", | | 536 | DPRINTF(UDMASS_USB, ("%s: opening iface %p epaddr %d for INTRIN\n", |
525 | USBDEVNAME(sc->sc_dev), sc->sc_iface, | | 537 | device_xname(sc->sc_dev), sc->sc_iface, |
526 | sc->sc_epaddr[UMASS_INTRIN])); | | 538 | sc->sc_epaddr[UMASS_INTRIN])); |
527 | err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_INTRIN], | | 539 | err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_INTRIN], |
528 | USBD_EXCLUSIVE_USE, &sc->sc_pipe[UMASS_INTRIN]); | | 540 | USBD_EXCLUSIVE_USE, &sc->sc_pipe[UMASS_INTRIN]); |
529 | if (err) { | | 541 | if (err) { |
530 | aprint_error_dev(self, "couldn't open %u-in (intr)\n", | | 542 | aprint_error_dev(self, "couldn't open %u-in (intr)\n", |
531 | sc->sc_epaddr[UMASS_INTRIN]); | | 543 | sc->sc_epaddr[UMASS_INTRIN]); |
532 | umass_disco(sc); | | 544 | umass_disco(sc); |
533 | USB_ATTACH_ERROR_RETURN; | | 545 | return; |
534 | } | | 546 | } |
535 | } | | 547 | } |
536 | | | 548 | |
537 | /* initialisation of generic part */ | | 549 | /* initialisation of generic part */ |
538 | sc->transfer_state = TSTATE_IDLE; | | 550 | sc->transfer_state = TSTATE_IDLE; |
539 | | | 551 | |
540 | /* request a sufficient number of xfer handles */ | | 552 | /* request a sufficient number of xfer handles */ |
541 | for (i = 0; i < XFER_NR; i++) { | | 553 | for (i = 0; i < XFER_NR; i++) { |
542 | sc->transfer_xfer[i] = usbd_alloc_xfer(uaa->device); | | 554 | sc->transfer_xfer[i] = usbd_alloc_xfer(uaa->device); |
543 | if (sc->transfer_xfer[i] == NULL) { | | 555 | if (sc->transfer_xfer[i] == NULL) { |
544 | aprint_error_dev(self, "Out of memory\n"); | | 556 | aprint_error_dev(self, "Out of memory\n"); |
545 | umass_disco(sc); | | 557 | umass_disco(sc); |
546 | USB_ATTACH_ERROR_RETURN; | | 558 | return; |
547 | } | | 559 | } |
548 | } | | 560 | } |
549 | /* Allocate buffer for data transfer (it's huge). */ | | 561 | /* Allocate buffer for data transfer (it's huge). */ |
550 | switch (sc->sc_wire) { | | 562 | switch (sc->sc_wire) { |
551 | case UMASS_WPROTO_BBB: | | 563 | case UMASS_WPROTO_BBB: |
552 | bno = XFER_BBB_DATA; | | 564 | bno = XFER_BBB_DATA; |
553 | goto dalloc; | | 565 | goto dalloc; |
554 | case UMASS_WPROTO_CBI: | | 566 | case UMASS_WPROTO_CBI: |
555 | bno = XFER_CBI_DATA; | | 567 | bno = XFER_CBI_DATA; |
556 | goto dalloc; | | 568 | goto dalloc; |
557 | case UMASS_WPROTO_CBI_I: | | 569 | case UMASS_WPROTO_CBI_I: |
558 | bno = XFER_CBI_DATA; | | 570 | bno = XFER_CBI_DATA; |
559 | dalloc: | | 571 | dalloc: |
560 | sc->data_buffer = usbd_alloc_buffer(sc->transfer_xfer[bno], | | 572 | sc->data_buffer = usbd_alloc_buffer(sc->transfer_xfer[bno], |
561 | UMASS_MAX_TRANSFER_SIZE); | | 573 | UMASS_MAX_TRANSFER_SIZE); |
562 | if (sc->data_buffer == NULL) { | | 574 | if (sc->data_buffer == NULL) { |
563 | aprint_error_dev(self, "no buffer memory\n"); | | 575 | aprint_error_dev(self, "no buffer memory\n"); |
564 | umass_disco(sc); | | 576 | umass_disco(sc); |
565 | USB_ATTACH_ERROR_RETURN; | | 577 | return; |
566 | } | | 578 | } |
567 | break; | | 579 | break; |
568 | default: | | 580 | default: |
569 | break; | | 581 | break; |
570 | } | | 582 | } |
571 | | | 583 | |
572 | /* Initialise the wire protocol specific methods */ | | 584 | /* Initialise the wire protocol specific methods */ |
573 | switch (sc->sc_wire) { | | 585 | switch (sc->sc_wire) { |
574 | case UMASS_WPROTO_BBB: | | 586 | case UMASS_WPROTO_BBB: |
575 | sc->sc_methods = &umass_bbb_methods; | | 587 | sc->sc_methods = &umass_bbb_methods; |
576 | break; | | 588 | break; |
577 | case UMASS_WPROTO_CBI: | | 589 | case UMASS_WPROTO_CBI: |
578 | case UMASS_WPROTO_CBI_I: | | 590 | case UMASS_WPROTO_CBI_I: |
579 | sc->sc_methods = &umass_cbi_methods; | | 591 | sc->sc_methods = &umass_cbi_methods; |
580 | break; | | 592 | break; |
581 | default: | | 593 | default: |
582 | umass_disco(sc); | | 594 | umass_disco(sc); |
583 | USB_ATTACH_ERROR_RETURN; | | 595 | return; |
584 | } | | 596 | } |
585 | | | 597 | |
586 | error = 0; | | 598 | error = 0; |
587 | switch (sc->sc_cmd) { | | 599 | switch (sc->sc_cmd) { |
588 | case UMASS_CPROTO_RBC: | | 600 | case UMASS_CPROTO_RBC: |
589 | case UMASS_CPROTO_SCSI: | | 601 | case UMASS_CPROTO_SCSI: |
590 | #if NSCSIBUS > 0 | | 602 | #if NSCSIBUS > 0 |
591 | error = umass_scsi_attach(sc); | | 603 | error = umass_scsi_attach(sc); |
592 | #else | | 604 | #else |
593 | aprint_error_dev(self, "scsibus not configured\n"); | | 605 | aprint_error_dev(self, "scsibus not configured\n"); |
594 | #endif | | 606 | #endif |
595 | break; | | 607 | break; |
596 | | | 608 | |
| @@ -605,117 +617,127 @@ USB_ATTACH(umass) | | | @@ -605,117 +617,127 @@ USB_ATTACH(umass) |
605 | | | 617 | |
606 | case UMASS_CPROTO_ISD_ATA: | | 618 | case UMASS_CPROTO_ISD_ATA: |
607 | #if NWD > 0 | | 619 | #if NWD > 0 |
608 | error = umass_isdata_attach(sc); | | 620 | error = umass_isdata_attach(sc); |
609 | #else | | 621 | #else |
610 | aprint_error_dev(self, "isdata not configured\n"); | | 622 | aprint_error_dev(self, "isdata not configured\n"); |
611 | #endif | | 623 | #endif |
612 | break; | | 624 | break; |
613 | | | 625 | |
614 | default: | | 626 | default: |
615 | aprint_error_dev(self, "command protocol=0x%x not supported\n", | | 627 | aprint_error_dev(self, "command protocol=0x%x not supported\n", |
616 | sc->sc_cmd); | | 628 | sc->sc_cmd); |
617 | umass_disco(sc); | | 629 | umass_disco(sc); |
618 | USB_ATTACH_ERROR_RETURN; | | 630 | return; |
619 | } | | 631 | } |
620 | if (error) { | | 632 | if (error) { |
621 | aprint_error_dev(self, "bus attach failed\n"); | | 633 | aprint_error_dev(self, "bus attach failed\n"); |
622 | umass_disco(sc); | | 634 | umass_disco(sc); |
623 | USB_ATTACH_ERROR_RETURN; | | 635 | return; |
624 | } | | 636 | } |
625 | | | 637 | |
626 | usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, | | 638 | usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, |
627 | USBDEV(sc->sc_dev)); | | 639 | sc->sc_dev); |
628 | | | 640 | |
629 | if (!pmf_device_register(self, NULL, NULL)) | | 641 | if (!pmf_device_register(self, NULL, NULL)) |
630 | aprint_error_dev(self, "couldn't establish power handler\n"); | | 642 | aprint_error_dev(self, "couldn't establish power handler\n"); |
631 | | | 643 | |
632 | DPRINTF(UDMASS_GEN, ("%s: Attach finished\n", USBDEVNAME(sc->sc_dev))); | | 644 | DPRINTF(UDMASS_GEN, ("%s: Attach finished\n", device_xname(sc->sc_dev))); |
633 | | | 645 | |
634 | USB_ATTACH_SUCCESS_RETURN; | | 646 | return; |
635 | } | | 647 | } |
636 | | | 648 | |
637 | USB_DETACH(umass) | | 649 | static void |
| | | 650 | umass_childdet(device_t self, device_t child) |
| | | 651 | { |
| | | 652 | struct umass_softc *sc = device_private(self); |
| | | 653 | |
| | | 654 | KASSERT(child == sc->bus->sc_child, ("assertion child == sc->bus->sc_child failed\n")); |
| | | 655 | sc->bus->sc_child = NULL; |
| | | 656 | } |
| | | 657 | |
| | | 658 | int |
| | | 659 | umass_detach(device_t self, int flags) |
638 | { | | 660 | { |
639 | USB_DETACH_START(umass, sc); | | 661 | struct umass_softc *sc = device_private(self); |
640 | struct umassbus_softc *scbus; | | 662 | struct umassbus_softc *scbus; |
641 | int rv = 0, i, s; | | 663 | int rv = 0, i, s; |
642 | | | 664 | |
643 | DPRINTF(UDMASS_USB, ("%s: detached\n", USBDEVNAME(sc->sc_dev))); | | 665 | DPRINTF(UDMASS_USB, ("%s: detached\n", device_xname(sc->sc_dev))); |
644 | | | 666 | |
645 | pmf_device_deregister(self); | | 667 | pmf_device_deregister(self); |
646 | | | 668 | |
647 | /* Abort the pipes to wake up any waiting processes. */ | | 669 | /* Abort the pipes to wake up any waiting processes. */ |
648 | for (i = 0 ; i < UMASS_NEP ; i++) { | | 670 | for (i = 0 ; i < UMASS_NEP ; i++) { |
649 | if (sc->sc_pipe[i] != NULL) | | 671 | if (sc->sc_pipe[i] != NULL) |
650 | usbd_abort_pipe(sc->sc_pipe[i]); | | 672 | usbd_abort_pipe(sc->sc_pipe[i]); |
651 | } | | 673 | } |
652 | | | 674 | |
653 | /* Do we really need reference counting? Perhaps in ioctl() */ | | 675 | /* Do we really need reference counting? Perhaps in ioctl() */ |
654 | s = splusb(); | | 676 | s = splusb(); |
655 | if (--sc->sc_refcnt >= 0) { | | 677 | if (--sc->sc_refcnt >= 0) { |
656 | #ifdef DIAGNOSTIC | | 678 | #ifdef DIAGNOSTIC |
657 | aprint_normal_dev(self, "waiting for refcnt\n"); | | 679 | aprint_normal_dev(self, "waiting for refcnt\n"); |
658 | #endif | | 680 | #endif |
659 | /* Wait for processes to go away. */ | | 681 | /* Wait for processes to go away. */ |
660 | usb_detach_wait(USBDEV(sc->sc_dev)); | | 682 | usb_detach_wait(sc->sc_dev); |
661 | } | | 683 | } |
662 | splx(s); | | 684 | splx(s); |
663 | | | 685 | |
664 | scbus = sc->bus; | | 686 | scbus = sc->bus; |
665 | if (scbus != NULL) { | | 687 | if (scbus != NULL) { |
666 | if (scbus->sc_child != NULL) | | 688 | if (scbus->sc_child != NULL) |
667 | rv = config_detach(scbus->sc_child, flags); | | 689 | rv = config_detach(scbus->sc_child, flags); |
668 | free(scbus, M_DEVBUF); | | 690 | free(scbus, M_DEVBUF); |
669 | sc->bus = NULL; | | 691 | sc->bus = NULL; |
670 | } | | 692 | } |
671 | | | 693 | |
672 | if (rv != 0) | | 694 | if (rv != 0) |
673 | return (rv); | | 695 | return (rv); |
674 | | | 696 | |
675 | umass_disco(sc); | | 697 | umass_disco(sc); |
676 | | | 698 | |
677 | usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, | | 699 | usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, |
678 | USBDEV(sc->sc_dev)); | | 700 | sc->sc_dev); |
679 | | | 701 | |
680 | return (rv); | | 702 | return (rv); |
681 | } | | 703 | } |
682 | | | 704 | |
683 | int | | 705 | int |
684 | umass_activate(device_t dev, enum devact act) | | 706 | umass_activate(device_t dev, enum devact act) |
685 | { | | 707 | { |
686 | struct umass_softc *sc = device_private(dev); | | 708 | struct umass_softc *sc = device_private(dev); |
687 | struct umassbus_softc *scbus = sc->bus; | | 709 | struct umassbus_softc *scbus = sc->bus; |
688 | int rv = 0; | | 710 | int rv = 0; |
689 | | | 711 | |
690 | DPRINTF(UDMASS_USB, ("%s: umass_activate: %d\n", | | 712 | DPRINTF(UDMASS_USB, ("%s: umass_activate: %d\n", |
691 | USBDEVNAME(sc->sc_dev), act)); | | 713 | device_xname(sc->sc_dev), act)); |
692 | | | 714 | |
693 | switch (act) { | | 715 | switch (act) { |
694 | case DVACT_ACTIVATE: | | 716 | case DVACT_ACTIVATE: |
695 | if (scbus == NULL || scbus->sc_child == NULL) | | 717 | if (scbus == NULL || scbus->sc_child == NULL) |
696 | break; | | 718 | break; |
697 | rv = config_activate(scbus->sc_child); | | 719 | rv = config_activate(scbus->sc_child); |
698 | DPRINTF(UDMASS_USB, ("%s: umass activate: child " | | 720 | DPRINTF(UDMASS_USB, ("%s: umass activate: child " |
699 | "returned %d\n", USBDEVNAME(sc->sc_dev), rv)); | | 721 | "returned %d\n", device_xname(sc->sc_dev), rv)); |
700 | break; | | 722 | break; |
701 | | | 723 | |
702 | case DVACT_DEACTIVATE: | | 724 | case DVACT_DEACTIVATE: |
703 | sc->sc_dying = 1; | | 725 | sc->sc_dying = 1; |
704 | if (scbus == NULL || scbus->sc_child == NULL) | | 726 | if (scbus == NULL || scbus->sc_child == NULL) |
705 | break; | | 727 | break; |
706 | rv = config_deactivate(scbus->sc_child); | | 728 | rv = config_deactivate(scbus->sc_child); |
707 | DPRINTF(UDMASS_USB, ("%s: umass_deactivate: child " | | 729 | DPRINTF(UDMASS_USB, ("%s: umass_deactivate: child " |
708 | "returned %d\n", USBDEVNAME(sc->sc_dev), rv)); | | 730 | "returned %d\n", device_xname(sc->sc_dev), rv)); |
709 | break; | | 731 | break; |
710 | } | | 732 | } |
711 | return (rv); | | 733 | return (rv); |
712 | } | | 734 | } |
713 | | | 735 | |
714 | Static void | | 736 | Static void |
715 | umass_disco(struct umass_softc *sc) | | 737 | umass_disco(struct umass_softc *sc) |
716 | { | | 738 | { |
717 | int i; | | 739 | int i; |
718 | | | 740 | |
719 | DPRINTF(UDMASS_GEN, ("umass_disco\n")); | | 741 | DPRINTF(UDMASS_GEN, ("umass_disco\n")); |
720 | | | 742 | |
721 | /* Remove all the pipes. */ | | 743 | /* Remove all the pipes. */ |
| @@ -749,73 +771,73 @@ umass_setup_transfer(struct umass_softc | | | @@ -749,73 +771,73 @@ umass_setup_transfer(struct umass_softc |
749 | { | | 771 | { |
750 | usbd_status err; | | 772 | usbd_status err; |
751 | | | 773 | |
752 | if (sc->sc_dying) | | 774 | if (sc->sc_dying) |
753 | return (USBD_IOERROR); | | 775 | return (USBD_IOERROR); |
754 | | | 776 | |
755 | /* Initialiase a USB transfer and then schedule it */ | | 777 | /* Initialiase a USB transfer and then schedule it */ |
756 | | | 778 | |
757 | usbd_setup_xfer(xfer, pipe, (void *)sc, buffer, buflen, | | 779 | usbd_setup_xfer(xfer, pipe, (void *)sc, buffer, buflen, |
758 | flags | sc->sc_xfer_flags, sc->timeout, sc->sc_methods->wire_state); | | 780 | flags | sc->sc_xfer_flags, sc->timeout, sc->sc_methods->wire_state); |
759 | | | 781 | |
760 | err = usbd_transfer(xfer); | | 782 | err = usbd_transfer(xfer); |
761 | DPRINTF(UDMASS_XFER,("%s: start xfer buffer=%p buflen=%d flags=0x%x " | | 783 | DPRINTF(UDMASS_XFER,("%s: start xfer buffer=%p buflen=%d flags=0x%x " |
762 | "timeout=%d\n", USBDEVNAME(sc->sc_dev), | | 784 | "timeout=%d\n", device_xname(sc->sc_dev), |
763 | buffer, buflen, flags | sc->sc_xfer_flags, sc->timeout)); | | 785 | buffer, buflen, flags | sc->sc_xfer_flags, sc->timeout)); |
764 | if (err && err != USBD_IN_PROGRESS) { | | 786 | if (err && err != USBD_IN_PROGRESS) { |
765 | DPRINTF(UDMASS_BBB, ("%s: failed to setup transfer, %s\n", | | 787 | DPRINTF(UDMASS_BBB, ("%s: failed to setup transfer, %s\n", |
766 | USBDEVNAME(sc->sc_dev), usbd_errstr(err))); | | 788 | device_xname(sc->sc_dev), usbd_errstr(err))); |
767 | return (err); | | 789 | return (err); |
768 | } | | 790 | } |
769 | | | 791 | |
770 | return (USBD_NORMAL_COMPLETION); | | 792 | return (USBD_NORMAL_COMPLETION); |
771 | } | | 793 | } |
772 | | | 794 | |
773 | | | 795 | |
774 | Static usbd_status | | 796 | Static usbd_status |
775 | umass_setup_ctrl_transfer(struct umass_softc *sc, usb_device_request_t *req, | | 797 | umass_setup_ctrl_transfer(struct umass_softc *sc, usb_device_request_t *req, |
776 | void *buffer, int buflen, int flags, usbd_xfer_handle xfer) | | 798 | void *buffer, int buflen, int flags, usbd_xfer_handle xfer) |
777 | { | | 799 | { |
778 | usbd_status err; | | 800 | usbd_status err; |
779 | | | 801 | |
780 | if (sc->sc_dying) | | 802 | if (sc->sc_dying) |
781 | return (USBD_IOERROR); | | 803 | return (USBD_IOERROR); |
782 | | | 804 | |
783 | /* Initialiase a USB control transfer and then schedule it */ | | 805 | /* Initialiase a USB control transfer and then schedule it */ |
784 | | | 806 | |
785 | usbd_setup_default_xfer(xfer, sc->sc_udev, (void *) sc, sc->timeout, | | 807 | usbd_setup_default_xfer(xfer, sc->sc_udev, (void *) sc, sc->timeout, |
786 | req, buffer, buflen, flags, sc->sc_methods->wire_state); | | 808 | req, buffer, buflen, flags, sc->sc_methods->wire_state); |
787 | | | 809 | |
788 | err = usbd_transfer(xfer); | | 810 | err = usbd_transfer(xfer); |
789 | if (err && err != USBD_IN_PROGRESS) { | | 811 | if (err && err != USBD_IN_PROGRESS) { |
790 | DPRINTF(UDMASS_BBB, ("%s: failed to setup ctrl transfer, %s\n", | | 812 | DPRINTF(UDMASS_BBB, ("%s: failed to setup ctrl transfer, %s\n", |
791 | USBDEVNAME(sc->sc_dev), usbd_errstr(err))); | | 813 | device_xname(sc->sc_dev), usbd_errstr(err))); |
792 | | | 814 | |
793 | /* do not reset, as this would make us loop */ | | 815 | /* do not reset, as this would make us loop */ |
794 | return (err); | | 816 | return (err); |
795 | } | | 817 | } |
796 | | | 818 | |
797 | return (USBD_NORMAL_COMPLETION); | | 819 | return (USBD_NORMAL_COMPLETION); |
798 | } | | 820 | } |
799 | | | 821 | |
800 | Static void | | 822 | Static void |
801 | umass_clear_endpoint_stall(struct umass_softc *sc, int endpt, | | 823 | umass_clear_endpoint_stall(struct umass_softc *sc, int endpt, |
802 | usbd_xfer_handle xfer) | | 824 | usbd_xfer_handle xfer) |
803 | { | | 825 | { |
804 | if (sc->sc_dying) | | 826 | if (sc->sc_dying) |
805 | return; | | 827 | return; |
806 | | | 828 | |
807 | DPRINTF(UDMASS_BBB, ("%s: Clear endpoint 0x%02x stall\n", | | 829 | DPRINTF(UDMASS_BBB, ("%s: Clear endpoint 0x%02x stall\n", |
808 | USBDEVNAME(sc->sc_dev), sc->sc_epaddr[endpt])); | | 830 | device_xname(sc->sc_dev), sc->sc_epaddr[endpt])); |
809 | | | 831 | |
810 | usbd_clear_endpoint_toggle(sc->sc_pipe[endpt]); | | 832 | usbd_clear_endpoint_toggle(sc->sc_pipe[endpt]); |
811 | | | 833 | |
812 | sc->sc_req.bmRequestType = UT_WRITE_ENDPOINT; | | 834 | sc->sc_req.bmRequestType = UT_WRITE_ENDPOINT; |
813 | sc->sc_req.bRequest = UR_CLEAR_FEATURE; | | 835 | sc->sc_req.bRequest = UR_CLEAR_FEATURE; |
814 | USETW(sc->sc_req.wValue, UF_ENDPOINT_HALT); | | 836 | USETW(sc->sc_req.wValue, UF_ENDPOINT_HALT); |
815 | USETW(sc->sc_req.wIndex, sc->sc_epaddr[endpt]); | | 837 | USETW(sc->sc_req.wIndex, sc->sc_epaddr[endpt]); |
816 | USETW(sc->sc_req.wLength, 0); | | 838 | USETW(sc->sc_req.wLength, 0); |
817 | umass_setup_ctrl_transfer(sc, &sc->sc_req, NULL, 0, 0, xfer); | | 839 | umass_setup_ctrl_transfer(sc, &sc->sc_req, NULL, 0, 0, xfer); |
818 | } | | 840 | } |
819 | | | 841 | |
820 | #if 0 | | 842 | #if 0 |
821 | Static void | | 843 | Static void |
| @@ -850,50 +872,50 @@ umass_bbb_reset(struct umass_softc *sc, | | | @@ -850,50 +872,50 @@ umass_bbb_reset(struct umass_softc *sc, |
850 | * a) a Bulk-Only Mass Storage Reset | | 872 | * a) a Bulk-Only Mass Storage Reset |
851 | * b) a Clear Feature HALT to the Bulk-In endpoint | | 873 | * b) a Clear Feature HALT to the Bulk-In endpoint |
852 | * c) a Clear Feature HALT to the Bulk-Out endpoint | | 874 | * c) a Clear Feature HALT to the Bulk-Out endpoint |
853 | * | | 875 | * |
854 | * This is done in 3 steps, states: | | 876 | * This is done in 3 steps, states: |
855 | * TSTATE_BBB_RESET1 | | 877 | * TSTATE_BBB_RESET1 |
856 | * TSTATE_BBB_RESET2 | | 878 | * TSTATE_BBB_RESET2 |
857 | * TSTATE_BBB_RESET3 | | 879 | * TSTATE_BBB_RESET3 |
858 | * | | 880 | * |
859 | * If the reset doesn't succeed, the device should be port reset. | | 881 | * If the reset doesn't succeed, the device should be port reset. |
860 | */ | | 882 | */ |
861 | | | 883 | |
862 | DPRINTF(UDMASS_BBB, ("%s: Bulk Reset\n", | | 884 | DPRINTF(UDMASS_BBB, ("%s: Bulk Reset\n", |
863 | USBDEVNAME(sc->sc_dev))); | | 885 | device_xname(sc->sc_dev))); |
864 | | | 886 | |
865 | sc->transfer_state = TSTATE_BBB_RESET1; | | 887 | sc->transfer_state = TSTATE_BBB_RESET1; |
866 | sc->transfer_status = status; | | 888 | sc->transfer_status = status; |
867 | | | 889 | |
868 | /* reset is a class specific interface write */ | | 890 | /* reset is a class specific interface write */ |
869 | sc->sc_req.bmRequestType = UT_WRITE_CLASS_INTERFACE; | | 891 | sc->sc_req.bmRequestType = UT_WRITE_CLASS_INTERFACE; |
870 | sc->sc_req.bRequest = UR_BBB_RESET; | | 892 | sc->sc_req.bRequest = UR_BBB_RESET; |
871 | USETW(sc->sc_req.wValue, 0); | | 893 | USETW(sc->sc_req.wValue, 0); |
872 | USETW(sc->sc_req.wIndex, sc->sc_ifaceno); | | 894 | USETW(sc->sc_req.wIndex, sc->sc_ifaceno); |
873 | USETW(sc->sc_req.wLength, 0); | | 895 | USETW(sc->sc_req.wLength, 0); |
874 | umass_setup_ctrl_transfer(sc, &sc->sc_req, NULL, 0, 0, | | 896 | umass_setup_ctrl_transfer(sc, &sc->sc_req, NULL, 0, 0, |
875 | sc->transfer_xfer[XFER_BBB_RESET1]); | | 897 | sc->transfer_xfer[XFER_BBB_RESET1]); |
876 | } | | 898 | } |
877 | | | 899 | |
878 | Static void | | 900 | Static void |
879 | umass_bbb_transfer(struct umass_softc *sc, int lun, void *cmd, int cmdlen, | | 901 | umass_bbb_transfer(struct umass_softc *sc, int lun, void *cmd, int cmdlen, |
880 | void *data, int datalen, int dir, u_int timeout, | | 902 | void *data, int datalen, int dir, u_int timeout, |
881 | umass_callback cb, void *priv) | | 903 | umass_callback cb, void *priv) |
882 | { | | 904 | { |
883 | static int dCBWtag = 42; /* unique for CBW of transfer */ | | 905 | static int dCBWtag = 42; /* unique for CBW of transfer */ |
884 | | | 906 | |
885 | DPRINTF(UDMASS_BBB,("%s: umass_bbb_transfer cmd=0x%02x\n", | | 907 | DPRINTF(UDMASS_BBB,("%s: umass_bbb_transfer cmd=0x%02x\n", |
886 | USBDEVNAME(sc->sc_dev), *(u_char *)cmd)); | | 908 | device_xname(sc->sc_dev), *(u_char *)cmd)); |
887 | | | 909 | |
888 | KASSERT(sc->sc_wire & UMASS_WPROTO_BBB, | | 910 | KASSERT(sc->sc_wire & UMASS_WPROTO_BBB, |
889 | ("sc->sc_wire == 0x%02x wrong for umass_bbb_transfer\n", | | 911 | ("sc->sc_wire == 0x%02x wrong for umass_bbb_transfer\n", |
890 | sc->sc_wire)); | | 912 | sc->sc_wire)); |
891 | | | 913 | |
892 | if (sc->sc_dying) | | 914 | if (sc->sc_dying) |
893 | return; | | 915 | return; |
894 | | | 916 | |
895 | /* Be a little generous. */ | | 917 | /* Be a little generous. */ |
896 | sc->timeout = timeout + USBD_DEFAULT_TIMEOUT; | | 918 | sc->timeout = timeout + USBD_DEFAULT_TIMEOUT; |
897 | | | 919 | |
898 | /* | | 920 | /* |
899 | * Do a Bulk-Only transfer with cmdlen bytes from cmd, possibly | | 921 | * Do a Bulk-Only transfer with cmdlen bytes from cmd, possibly |
| @@ -907,43 +929,43 @@ umass_bbb_transfer(struct umass_softc *s | | | @@ -907,43 +929,43 @@ umass_bbb_transfer(struct umass_softc *s |
907 | * following states: | | 929 | * following states: |
908 | * TSTATE_BBB_COMMAND | | 930 | * TSTATE_BBB_COMMAND |
909 | * -> TSTATE_BBB_DATA | | 931 | * -> TSTATE_BBB_DATA |
910 | * -> TSTATE_BBB_STATUS | | 932 | * -> TSTATE_BBB_STATUS |
911 | * -> TSTATE_BBB_STATUS2 | | 933 | * -> TSTATE_BBB_STATUS2 |
912 | * -> TSTATE_BBB_IDLE | | 934 | * -> TSTATE_BBB_IDLE |
913 | * | | 935 | * |
914 | * An error in any of those states will invoke | | 936 | * An error in any of those states will invoke |
915 | * umass_bbb_reset. | | 937 | * umass_bbb_reset. |
916 | */ | | 938 | */ |
917 | | | 939 | |
918 | /* check the given arguments */ | | 940 | /* check the given arguments */ |
919 | KASSERT(datalen == 0 || data != NULL, | | 941 | KASSERT(datalen == 0 || data != NULL, |
920 | ("%s: datalen > 0, but no buffer",USBDEVNAME(sc->sc_dev))); | | 942 | ("%s: datalen > 0, but no buffer",device_xname(sc->sc_dev))); |
921 | KASSERT(cmdlen <= CBWCDBLENGTH, | | 943 | KASSERT(cmdlen <= CBWCDBLENGTH, |
922 | ("%s: cmdlen exceeds CDB length in CBW (%d > %d)", | | 944 | ("%s: cmdlen exceeds CDB length in CBW (%d > %d)", |
923 | USBDEVNAME(sc->sc_dev), cmdlen, CBWCDBLENGTH)); | | 945 | device_xname(sc->sc_dev), cmdlen, CBWCDBLENGTH)); |
924 | KASSERT(dir == DIR_NONE || datalen > 0, | | 946 | KASSERT(dir == DIR_NONE || datalen > 0, |
925 | ("%s: datalen == 0 while direction is not NONE\n", | | 947 | ("%s: datalen == 0 while direction is not NONE\n", |
926 | USBDEVNAME(sc->sc_dev))); | | 948 | device_xname(sc->sc_dev))); |
927 | KASSERT(datalen == 0 || dir != DIR_NONE, | | 949 | KASSERT(datalen == 0 || dir != DIR_NONE, |
928 | ("%s: direction is NONE while datalen is not zero\n", | | 950 | ("%s: direction is NONE while datalen is not zero\n", |
929 | USBDEVNAME(sc->sc_dev))); | | 951 | device_xname(sc->sc_dev))); |
930 | KASSERT(sizeof(umass_bbb_cbw_t) == UMASS_BBB_CBW_SIZE, | | 952 | KASSERT(sizeof(umass_bbb_cbw_t) == UMASS_BBB_CBW_SIZE, |
931 | ("%s: CBW struct does not have the right size (%d vs. %d)\n", | | 953 | ("%s: CBW struct does not have the right size (%d vs. %d)\n", |
932 | USBDEVNAME(sc->sc_dev), | | 954 | device_xname(sc->sc_dev), |
933 | sizeof(umass_bbb_cbw_t), UMASS_BBB_CBW_SIZE)); | | 955 | sizeof(umass_bbb_cbw_t), UMASS_BBB_CBW_SIZE)); |
934 | KASSERT(sizeof(umass_bbb_csw_t) == UMASS_BBB_CSW_SIZE, | | 956 | KASSERT(sizeof(umass_bbb_csw_t) == UMASS_BBB_CSW_SIZE, |
935 | ("%s: CSW struct does not have the right size (%d vs. %d)\n", | | 957 | ("%s: CSW struct does not have the right size (%d vs. %d)\n", |
936 | USBDEVNAME(sc->sc_dev), | | 958 | device_xname(sc->sc_dev), |
937 | sizeof(umass_bbb_csw_t), UMASS_BBB_CSW_SIZE)); | | 959 | sizeof(umass_bbb_csw_t), UMASS_BBB_CSW_SIZE)); |
938 | | | 960 | |
939 | /* | | 961 | /* |
940 | * Determine the direction of the data transfer and the length. | | 962 | * Determine the direction of the data transfer and the length. |
941 | * | | 963 | * |
942 | * dCBWDataTransferLength (datalen) : | | 964 | * dCBWDataTransferLength (datalen) : |
943 | * This field indicates the number of bytes of data that the host | | 965 | * This field indicates the number of bytes of data that the host |
944 | * intends to transfer on the IN or OUT Bulk endpoint(as indicated by | | 966 | * intends to transfer on the IN or OUT Bulk endpoint(as indicated by |
945 | * the Direction bit) during the execution of this command. If this | | 967 | * the Direction bit) during the execution of this command. If this |
946 | * field is set to 0, the device will expect that no data will be | | 968 | * field is set to 0, the device will expect that no data will be |
947 | * transferred IN or OUT during this command, regardless of the value | | 969 | * transferred IN or OUT during this command, regardless of the value |
948 | * of the Direction bit defined in dCBWFlags. | | 970 | * of the Direction bit defined in dCBWFlags. |
949 | * | | 971 | * |
| @@ -1006,37 +1028,37 @@ umass_bbb_state(usbd_xfer_handle xfer, u | | | @@ -1006,37 +1028,37 @@ umass_bbb_state(usbd_xfer_handle xfer, u |
1006 | | | 1028 | |
1007 | /* | | 1029 | /* |
1008 | * State handling for BBB transfers. | | 1030 | * State handling for BBB transfers. |
1009 | * | | 1031 | * |
1010 | * The subroutine is rather long. It steps through the states given in | | 1032 | * The subroutine is rather long. It steps through the states given in |
1011 | * Annex A of the Bulk-Only specification. | | 1033 | * Annex A of the Bulk-Only specification. |
1012 | * Each state first does the error handling of the previous transfer | | 1034 | * Each state first does the error handling of the previous transfer |
1013 | * and then prepares the next transfer. | | 1035 | * and then prepares the next transfer. |
1014 | * Each transfer is done asynchroneously so after the request/transfer | | 1036 | * Each transfer is done asynchroneously so after the request/transfer |
1015 | * has been submitted you will find a 'return;'. | | 1037 | * has been submitted you will find a 'return;'. |
1016 | */ | | 1038 | */ |
1017 | | | 1039 | |
1018 | DPRINTF(UDMASS_BBB, ("%s: Handling BBB state %d (%s), xfer=%p, %s\n", | | 1040 | DPRINTF(UDMASS_BBB, ("%s: Handling BBB state %d (%s), xfer=%p, %s\n", |
1019 | USBDEVNAME(sc->sc_dev), sc->transfer_state, | | 1041 | device_xname(sc->sc_dev), sc->transfer_state, |
1020 | states[sc->transfer_state], xfer, usbd_errstr(err))); | | 1042 | states[sc->transfer_state], xfer, usbd_errstr(err))); |
1021 | | | 1043 | |
1022 | switch (sc->transfer_state) { | | 1044 | switch (sc->transfer_state) { |
1023 | | | 1045 | |
1024 | /***** Bulk Transfer *****/ | | 1046 | /***** Bulk Transfer *****/ |
1025 | case TSTATE_BBB_COMMAND: | | 1047 | case TSTATE_BBB_COMMAND: |
1026 | /* Command transport phase, error handling */ | | 1048 | /* Command transport phase, error handling */ |
1027 | if (err) { | | 1049 | if (err) { |
1028 | DPRINTF(UDMASS_BBB, ("%s: failed to send CBW\n", | | 1050 | DPRINTF(UDMASS_BBB, ("%s: failed to send CBW\n", |
1029 | USBDEVNAME(sc->sc_dev))); | | 1051 | device_xname(sc->sc_dev))); |
1030 | /* If the device detects that the CBW is invalid, then | | 1052 | /* If the device detects that the CBW is invalid, then |
1031 | * the device may STALL both bulk endpoints and require | | 1053 | * the device may STALL both bulk endpoints and require |
1032 | * a Bulk-Reset | | 1054 | * a Bulk-Reset |
1033 | */ | | 1055 | */ |
1034 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1056 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
1035 | return; | | 1057 | return; |
1036 | } | | 1058 | } |
1037 | | | 1059 | |
1038 | /* Data transport phase, setup transfer */ | | 1060 | /* Data transport phase, setup transfer */ |
1039 | sc->transfer_state = TSTATE_BBB_DATA; | | 1061 | sc->transfer_state = TSTATE_BBB_DATA; |
1040 | if (sc->transfer_dir == DIR_IN) { | | 1062 | if (sc->transfer_dir == DIR_IN) { |
1041 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKIN], | | 1063 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKIN], |
1042 | sc->data_buffer, sc->transfer_datalen, | | 1064 | sc->data_buffer, sc->transfer_datalen, |
| @@ -1047,43 +1069,43 @@ umass_bbb_state(usbd_xfer_handle xfer, u | | | @@ -1047,43 +1069,43 @@ umass_bbb_state(usbd_xfer_handle xfer, u |
1047 | return; | | 1069 | return; |
1048 | } else if (sc->transfer_dir == DIR_OUT) { | | 1070 | } else if (sc->transfer_dir == DIR_OUT) { |
1049 | memcpy(sc->data_buffer, sc->transfer_data, | | 1071 | memcpy(sc->data_buffer, sc->transfer_data, |
1050 | sc->transfer_datalen); | | 1072 | sc->transfer_datalen); |
1051 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKOUT], | | 1073 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKOUT], |
1052 | sc->data_buffer, sc->transfer_datalen, | | 1074 | sc->data_buffer, sc->transfer_datalen, |
1053 | USBD_NO_COPY,/* fixed length transfer */ | | 1075 | USBD_NO_COPY,/* fixed length transfer */ |
1054 | sc->transfer_xfer[XFER_BBB_DATA])) | | 1076 | sc->transfer_xfer[XFER_BBB_DATA])) |
1055 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1077 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
1056 | | | 1078 | |
1057 | return; | | 1079 | return; |
1058 | } else { | | 1080 | } else { |
1059 | DPRINTF(UDMASS_BBB, ("%s: no data phase\n", | | 1081 | DPRINTF(UDMASS_BBB, ("%s: no data phase\n", |
1060 | USBDEVNAME(sc->sc_dev))); | | 1082 | device_xname(sc->sc_dev))); |
1061 | } | | 1083 | } |
1062 | | | 1084 | |
1063 | /* FALLTHROUGH if no data phase, err == 0 */ | | 1085 | /* FALLTHROUGH if no data phase, err == 0 */ |
1064 | case TSTATE_BBB_DATA: | | 1086 | case TSTATE_BBB_DATA: |
1065 | /* Command transport phase error handling (ignored if no data | | 1087 | /* Command transport phase error handling (ignored if no data |
1066 | * phase (fallthrough from previous state)) */ | | 1088 | * phase (fallthrough from previous state)) */ |
1067 | if (sc->transfer_dir != DIR_NONE) { | | 1089 | if (sc->transfer_dir != DIR_NONE) { |
1068 | /* retrieve the length of the transfer that was done */ | | 1090 | /* retrieve the length of the transfer that was done */ |
1069 | usbd_get_xfer_status(xfer, NULL, NULL, | | 1091 | usbd_get_xfer_status(xfer, NULL, NULL, |
1070 | &sc->transfer_actlen, NULL); | | 1092 | &sc->transfer_actlen, NULL); |
1071 | DPRINTF(UDMASS_BBB, ("%s: BBB_DATA actlen=%d\n", | | 1093 | DPRINTF(UDMASS_BBB, ("%s: BBB_DATA actlen=%d\n", |
1072 | USBDEVNAME(sc->sc_dev), sc->transfer_actlen)); | | 1094 | device_xname(sc->sc_dev), sc->transfer_actlen)); |
1073 | | | 1095 | |
1074 | if (err) { | | 1096 | if (err) { |
1075 | DPRINTF(UDMASS_BBB, ("%s: Data-%s %d failed, " | | 1097 | DPRINTF(UDMASS_BBB, ("%s: Data-%s %d failed, " |
1076 | "%s\n", USBDEVNAME(sc->sc_dev), | | 1098 | "%s\n", device_xname(sc->sc_dev), |
1077 | (sc->transfer_dir == DIR_IN?"in":"out"), | | 1099 | (sc->transfer_dir == DIR_IN?"in":"out"), |
1078 | sc->transfer_datalen,usbd_errstr(err))); | | 1100 | sc->transfer_datalen,usbd_errstr(err))); |
1079 | | | 1101 | |
1080 | if (err == USBD_STALLED) { | | 1102 | if (err == USBD_STALLED) { |
1081 | sc->transfer_state = TSTATE_BBB_DCLEAR; | | 1103 | sc->transfer_state = TSTATE_BBB_DCLEAR; |
1082 | umass_clear_endpoint_stall(sc, | | 1104 | umass_clear_endpoint_stall(sc, |
1083 | (sc->transfer_dir == DIR_IN? | | 1105 | (sc->transfer_dir == DIR_IN? |
1084 | UMASS_BULKIN:UMASS_BULKOUT), | | 1106 | UMASS_BULKIN:UMASS_BULKOUT), |
1085 | sc->transfer_xfer[XFER_BBB_DCLEAR]); | | 1107 | sc->transfer_xfer[XFER_BBB_DCLEAR]); |
1086 | } else { | | 1108 | } else { |
1087 | /* Unless the error is a pipe stall the | | 1109 | /* Unless the error is a pipe stall the |
1088 | * error is fatal. | | 1110 | * error is fatal. |
1089 | */ | | 1111 | */ |
| @@ -1103,27 +1125,27 @@ umass_bbb_state(usbd_xfer_handle xfer, u | | | @@ -1103,27 +1125,27 @@ umass_bbb_state(usbd_xfer_handle xfer, u |
1103 | umass_dump_buffer(sc, sc->transfer_data, | | 1125 | umass_dump_buffer(sc, sc->transfer_data, |
1104 | sc->transfer_datalen, 48)); | | 1126 | sc->transfer_datalen, 48)); |
1105 | | | 1127 | |
1106 | /* FALLTHROUGH, err == 0 (no data phase or successful) */ | | 1128 | /* FALLTHROUGH, err == 0 (no data phase or successful) */ |
1107 | case TSTATE_BBB_SCLEAR: /* stall clear after status phase */ | | 1129 | case TSTATE_BBB_SCLEAR: /* stall clear after status phase */ |
1108 | /* Reading of CSW after bulk stall condition in data phase | | 1130 | /* Reading of CSW after bulk stall condition in data phase |
1109 | * (TSTATE_BBB_DATA2) or bulk-in stall condition after | | 1131 | * (TSTATE_BBB_DATA2) or bulk-in stall condition after |
1110 | * reading CSW (TSTATE_BBB_SCLEAR). | | 1132 | * reading CSW (TSTATE_BBB_SCLEAR). |
1111 | * In the case of no data phase or successful data phase, | | 1133 | * In the case of no data phase or successful data phase, |
1112 | * err == 0 and the following if block is passed. | | 1134 | * err == 0 and the following if block is passed. |
1113 | */ | | 1135 | */ |
1114 | if (err) { /* should not occur */ | | 1136 | if (err) { /* should not occur */ |
1115 | printf("%s: BBB bulk-%s stall clear failed, %s\n", | | 1137 | printf("%s: BBB bulk-%s stall clear failed, %s\n", |
1116 | USBDEVNAME(sc->sc_dev), | | 1138 | device_xname(sc->sc_dev), |
1117 | (sc->transfer_dir == DIR_IN? "in":"out"), | | 1139 | (sc->transfer_dir == DIR_IN? "in":"out"), |
1118 | usbd_errstr(err)); | | 1140 | usbd_errstr(err)); |
1119 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1141 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
1120 | return; | | 1142 | return; |
1121 | } | | 1143 | } |
1122 | | | 1144 | |
1123 | /* Status transport phase, setup transfer */ | | 1145 | /* Status transport phase, setup transfer */ |
1124 | if (sc->transfer_state == TSTATE_BBB_COMMAND || | | 1146 | if (sc->transfer_state == TSTATE_BBB_COMMAND || |
1125 | sc->transfer_state == TSTATE_BBB_DATA || | | 1147 | sc->transfer_state == TSTATE_BBB_DATA || |
1126 | sc->transfer_state == TSTATE_BBB_DCLEAR) { | | 1148 | sc->transfer_state == TSTATE_BBB_DCLEAR) { |
1127 | /* After no data phase, successful data phase and | | 1149 | /* After no data phase, successful data phase and |
1128 | * after clearing bulk-in/-out stall condition | | 1150 | * after clearing bulk-in/-out stall condition |
1129 | */ | | 1151 | */ |
| @@ -1138,27 +1160,27 @@ umass_bbb_state(usbd_xfer_handle xfer, u | | | @@ -1138,27 +1160,27 @@ umass_bbb_state(usbd_xfer_handle xfer, u |
1138 | /* Read the Command Status Wrapper via bulk-in endpoint. */ | | 1160 | /* Read the Command Status Wrapper via bulk-in endpoint. */ |
1139 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKIN], | | 1161 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKIN], |
1140 | &sc->csw, UMASS_BBB_CSW_SIZE, 0, next_xfer)) { | | 1162 | &sc->csw, UMASS_BBB_CSW_SIZE, 0, next_xfer)) { |
1141 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1163 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
1142 | return; | | 1164 | return; |
1143 | } | | 1165 | } |
1144 | | | 1166 | |
1145 | return; | | 1167 | return; |
1146 | case TSTATE_BBB_STATUS1: /* first attempt */ | | 1168 | case TSTATE_BBB_STATUS1: /* first attempt */ |
1147 | case TSTATE_BBB_STATUS2: /* second attempt */ | | 1169 | case TSTATE_BBB_STATUS2: /* second attempt */ |
1148 | /* Status transfer, error handling */ | | 1170 | /* Status transfer, error handling */ |
1149 | if (err) { | | 1171 | if (err) { |
1150 | DPRINTF(UDMASS_BBB, ("%s: Failed to read CSW, %s%s\n", | | 1172 | DPRINTF(UDMASS_BBB, ("%s: Failed to read CSW, %s%s\n", |
1151 | USBDEVNAME(sc->sc_dev), usbd_errstr(err), | | 1173 | device_xname(sc->sc_dev), usbd_errstr(err), |
1152 | (sc->transfer_state == TSTATE_BBB_STATUS1? | | 1174 | (sc->transfer_state == TSTATE_BBB_STATUS1? |
1153 | ", retrying":""))); | | 1175 | ", retrying":""))); |
1154 | | | 1176 | |
1155 | /* If this was the first attempt at fetching the CSW | | 1177 | /* If this was the first attempt at fetching the CSW |
1156 | * retry it, otherwise fail. | | 1178 | * retry it, otherwise fail. |
1157 | */ | | 1179 | */ |
1158 | if (sc->transfer_state == TSTATE_BBB_STATUS1) { | | 1180 | if (sc->transfer_state == TSTATE_BBB_STATUS1) { |
1159 | sc->transfer_state = TSTATE_BBB_SCLEAR; | | 1181 | sc->transfer_state = TSTATE_BBB_SCLEAR; |
1160 | umass_clear_endpoint_stall(sc, UMASS_BULKIN, | | 1182 | umass_clear_endpoint_stall(sc, UMASS_BULKIN, |
1161 | sc->transfer_xfer[XFER_BBB_SCLEAR]); | | 1183 | sc->transfer_xfer[XFER_BBB_SCLEAR]); |
1162 | return; | | 1184 | return; |
1163 | } else { | | 1185 | } else { |
1164 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1186 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
| @@ -1173,138 +1195,138 @@ umass_bbb_state(usbd_xfer_handle xfer, u | | | @@ -1173,138 +1195,138 @@ umass_bbb_state(usbd_xfer_handle xfer, u |
1173 | UGETDW(sc->csw.dCSWSignature) == CSWSIGNATURE_OLYMPUS_C1) | | 1195 | UGETDW(sc->csw.dCSWSignature) == CSWSIGNATURE_OLYMPUS_C1) |
1174 | USETDW(sc->csw.dCSWSignature, CSWSIGNATURE); | | 1196 | USETDW(sc->csw.dCSWSignature, CSWSIGNATURE); |
1175 | | | 1197 | |
1176 | /* Translate invalid command-status tags */ | | 1198 | /* Translate invalid command-status tags */ |
1177 | if (sc->sc_quirks & UMASS_QUIRK_WRONG_CSWTAG) | | 1199 | if (sc->sc_quirks & UMASS_QUIRK_WRONG_CSWTAG) |
1178 | USETDW(sc->csw.dCSWTag, UGETDW(sc->cbw.dCBWTag)); | | 1200 | USETDW(sc->csw.dCSWTag, UGETDW(sc->cbw.dCBWTag)); |
1179 | | | 1201 | |
1180 | /* Check CSW and handle any error */ | | 1202 | /* Check CSW and handle any error */ |
1181 | if (UGETDW(sc->csw.dCSWSignature) != CSWSIGNATURE) { | | 1203 | if (UGETDW(sc->csw.dCSWSignature) != CSWSIGNATURE) { |
1182 | /* Invalid CSW: Wrong signature or wrong tag might | | 1204 | /* Invalid CSW: Wrong signature or wrong tag might |
1183 | * indicate that the device is confused -> reset it. | | 1205 | * indicate that the device is confused -> reset it. |
1184 | */ | | 1206 | */ |
1185 | printf("%s: Invalid CSW: sig 0x%08x should be 0x%08x\n", | | 1207 | printf("%s: Invalid CSW: sig 0x%08x should be 0x%08x\n", |
1186 | USBDEVNAME(sc->sc_dev), | | 1208 | device_xname(sc->sc_dev), |
1187 | UGETDW(sc->csw.dCSWSignature), | | 1209 | UGETDW(sc->csw.dCSWSignature), |
1188 | CSWSIGNATURE); | | 1210 | CSWSIGNATURE); |
1189 | | | 1211 | |
1190 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1212 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
1191 | return; | | 1213 | return; |
1192 | } else if (UGETDW(sc->csw.dCSWTag) | | 1214 | } else if (UGETDW(sc->csw.dCSWTag) |
1193 | != UGETDW(sc->cbw.dCBWTag)) { | | 1215 | != UGETDW(sc->cbw.dCBWTag)) { |
1194 | printf("%s: Invalid CSW: tag %d should be %d\n", | | 1216 | printf("%s: Invalid CSW: tag %d should be %d\n", |
1195 | USBDEVNAME(sc->sc_dev), | | 1217 | device_xname(sc->sc_dev), |
1196 | UGETDW(sc->csw.dCSWTag), | | 1218 | UGETDW(sc->csw.dCSWTag), |
1197 | UGETDW(sc->cbw.dCBWTag)); | | 1219 | UGETDW(sc->cbw.dCBWTag)); |
1198 | | | 1220 | |
1199 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1221 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
1200 | return; | | 1222 | return; |
1201 | | | 1223 | |
1202 | /* CSW is valid here */ | | 1224 | /* CSW is valid here */ |
1203 | } else if (sc->csw.bCSWStatus > CSWSTATUS_PHASE) { | | 1225 | } else if (sc->csw.bCSWStatus > CSWSTATUS_PHASE) { |
1204 | printf("%s: Invalid CSW: status %d > %d\n", | | 1226 | printf("%s: Invalid CSW: status %d > %d\n", |
1205 | USBDEVNAME(sc->sc_dev), | | 1227 | device_xname(sc->sc_dev), |
1206 | sc->csw.bCSWStatus, | | 1228 | sc->csw.bCSWStatus, |
1207 | CSWSTATUS_PHASE); | | 1229 | CSWSTATUS_PHASE); |
1208 | | | 1230 | |
1209 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1231 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
1210 | return; | | 1232 | return; |
1211 | } else if (sc->csw.bCSWStatus == CSWSTATUS_PHASE) { | | 1233 | } else if (sc->csw.bCSWStatus == CSWSTATUS_PHASE) { |
1212 | printf("%s: Phase Error, residue = %d\n", | | 1234 | printf("%s: Phase Error, residue = %d\n", |
1213 | USBDEVNAME(sc->sc_dev), | | 1235 | device_xname(sc->sc_dev), |
1214 | UGETDW(sc->csw.dCSWDataResidue)); | | 1236 | UGETDW(sc->csw.dCSWDataResidue)); |
1215 | | | 1237 | |
1216 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1238 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
1217 | return; | | 1239 | return; |
1218 | | | 1240 | |
1219 | } else if (sc->transfer_actlen > sc->transfer_datalen) { | | 1241 | } else if (sc->transfer_actlen > sc->transfer_datalen) { |
1220 | /* Buffer overrun! Don't let this go by unnoticed */ | | 1242 | /* Buffer overrun! Don't let this go by unnoticed */ |
1221 | panic("%s: transferred %d bytes instead of %d bytes", | | 1243 | panic("%s: transferred %d bytes instead of %d bytes", |
1222 | USBDEVNAME(sc->sc_dev), | | 1244 | device_xname(sc->sc_dev), |
1223 | sc->transfer_actlen, sc->transfer_datalen); | | 1245 | sc->transfer_actlen, sc->transfer_datalen); |
1224 | #if 0 | | 1246 | #if 0 |
1225 | } else if (sc->transfer_datalen - sc->transfer_actlen | | 1247 | } else if (sc->transfer_datalen - sc->transfer_actlen |
1226 | != UGETDW(sc->csw.dCSWDataResidue)) { | | 1248 | != UGETDW(sc->csw.dCSWDataResidue)) { |
1227 | DPRINTF(UDMASS_BBB, ("%s: actlen=%d != residue=%d\n", | | 1249 | DPRINTF(UDMASS_BBB, ("%s: actlen=%d != residue=%d\n", |
1228 | USBDEVNAME(sc->sc_dev), | | 1250 | device_xname(sc->sc_dev), |
1229 | sc->transfer_datalen - sc->transfer_actlen, | | 1251 | sc->transfer_datalen - sc->transfer_actlen, |
1230 | UGETDW(sc->csw.dCSWDataResidue))); | | 1252 | UGETDW(sc->csw.dCSWDataResidue))); |
1231 | | | 1253 | |
1232 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); | | 1254 | umass_bbb_reset(sc, STATUS_WIRE_FAILED); |
1233 | return; | | 1255 | return; |
1234 | #endif | | 1256 | #endif |
1235 | } else if (sc->csw.bCSWStatus == CSWSTATUS_FAILED) { | | 1257 | } else if (sc->csw.bCSWStatus == CSWSTATUS_FAILED) { |
1236 | DPRINTF(UDMASS_BBB, ("%s: Command Failed, res = %d\n", | | 1258 | DPRINTF(UDMASS_BBB, ("%s: Command Failed, res = %d\n", |
1237 | USBDEVNAME(sc->sc_dev), | | 1259 | device_xname(sc->sc_dev), |
1238 | UGETDW(sc->csw.dCSWDataResidue))); | | 1260 | UGETDW(sc->csw.dCSWDataResidue))); |
1239 | | | 1261 | |
1240 | /* SCSI command failed but transfer was succesful */ | | 1262 | /* SCSI command failed but transfer was succesful */ |
1241 | sc->transfer_state = TSTATE_IDLE; | | 1263 | sc->transfer_state = TSTATE_IDLE; |
1242 | sc->transfer_cb(sc, sc->transfer_priv, | | 1264 | sc->transfer_cb(sc, sc->transfer_priv, |
1243 | UGETDW(sc->csw.dCSWDataResidue), | | 1265 | UGETDW(sc->csw.dCSWDataResidue), |
1244 | STATUS_CMD_FAILED); | | 1266 | STATUS_CMD_FAILED); |
1245 | | | 1267 | |
1246 | return; | | 1268 | return; |
1247 | | | 1269 | |
1248 | } else { /* success */ | | 1270 | } else { /* success */ |
1249 | sc->transfer_state = TSTATE_IDLE; | | 1271 | sc->transfer_state = TSTATE_IDLE; |
1250 | sc->transfer_cb(sc, sc->transfer_priv, | | 1272 | sc->transfer_cb(sc, sc->transfer_priv, |
1251 | UGETDW(sc->csw.dCSWDataResidue), | | 1273 | UGETDW(sc->csw.dCSWDataResidue), |
1252 | STATUS_CMD_OK); | | 1274 | STATUS_CMD_OK); |
1253 | | | 1275 | |
1254 | return; | | 1276 | return; |
1255 | } | | 1277 | } |
1256 | | | 1278 | |
1257 | /***** Bulk Reset *****/ | | 1279 | /***** Bulk Reset *****/ |
1258 | case TSTATE_BBB_RESET1: | | 1280 | case TSTATE_BBB_RESET1: |
1259 | if (err) | | 1281 | if (err) |
1260 | printf("%s: BBB reset failed, %s\n", | | 1282 | printf("%s: BBB reset failed, %s\n", |
1261 | USBDEVNAME(sc->sc_dev), usbd_errstr(err)); | | 1283 | device_xname(sc->sc_dev), usbd_errstr(err)); |
1262 | | | 1284 | |
1263 | sc->transfer_state = TSTATE_BBB_RESET2; | | 1285 | sc->transfer_state = TSTATE_BBB_RESET2; |
1264 | umass_clear_endpoint_stall(sc, UMASS_BULKIN, | | 1286 | umass_clear_endpoint_stall(sc, UMASS_BULKIN, |
1265 | sc->transfer_xfer[XFER_BBB_RESET2]); | | 1287 | sc->transfer_xfer[XFER_BBB_RESET2]); |
1266 | | | 1288 | |
1267 | return; | | 1289 | return; |
1268 | case TSTATE_BBB_RESET2: | | 1290 | case TSTATE_BBB_RESET2: |
1269 | if (err) /* should not occur */ | | 1291 | if (err) /* should not occur */ |
1270 | printf("%s: BBB bulk-in clear stall failed, %s\n", | | 1292 | printf("%s: BBB bulk-in clear stall failed, %s\n", |
1271 | USBDEVNAME(sc->sc_dev), usbd_errstr(err)); | | 1293 | device_xname(sc->sc_dev), usbd_errstr(err)); |
1272 | /* no error recovery, otherwise we end up in a loop */ | | 1294 | /* no error recovery, otherwise we end up in a loop */ |
1273 | | | 1295 | |
1274 | sc->transfer_state = TSTATE_BBB_RESET3; | | 1296 | sc->transfer_state = TSTATE_BBB_RESET3; |
1275 | umass_clear_endpoint_stall(sc, UMASS_BULKOUT, | | 1297 | umass_clear_endpoint_stall(sc, UMASS_BULKOUT, |
1276 | sc->transfer_xfer[XFER_BBB_RESET3]); | | 1298 | sc->transfer_xfer[XFER_BBB_RESET3]); |
1277 | | | 1299 | |
1278 | return; | | 1300 | return; |
1279 | case TSTATE_BBB_RESET3: | | 1301 | case TSTATE_BBB_RESET3: |
1280 | if (err) /* should not occur */ | | 1302 | if (err) /* should not occur */ |
1281 | printf("%s: BBB bulk-out clear stall failed, %s\n", | | 1303 | printf("%s: BBB bulk-out clear stall failed, %s\n", |
1282 | USBDEVNAME(sc->sc_dev), usbd_errstr(err)); | | 1304 | device_xname(sc->sc_dev), usbd_errstr(err)); |
1283 | /* no error recovery, otherwise we end up in a loop */ | | 1305 | /* no error recovery, otherwise we end up in a loop */ |
1284 | | | 1306 | |
1285 | sc->transfer_state = TSTATE_IDLE; | | 1307 | sc->transfer_state = TSTATE_IDLE; |
1286 | if (sc->transfer_priv) { | | 1308 | if (sc->transfer_priv) { |
1287 | sc->transfer_cb(sc, sc->transfer_priv, | | 1309 | sc->transfer_cb(sc, sc->transfer_priv, |
1288 | sc->transfer_datalen, | | 1310 | sc->transfer_datalen, |
1289 | sc->transfer_status); | | 1311 | sc->transfer_status); |
1290 | } | | 1312 | } |
1291 | | | 1313 | |
1292 | return; | | 1314 | return; |
1293 | | | 1315 | |
1294 | /***** Default *****/ | | 1316 | /***** Default *****/ |
1295 | default: | | 1317 | default: |
1296 | panic("%s: Unknown state %d", | | 1318 | panic("%s: Unknown state %d", |
1297 | USBDEVNAME(sc->sc_dev), sc->transfer_state); | | 1319 | device_xname(sc->sc_dev), sc->transfer_state); |
1298 | } | | 1320 | } |
1299 | } | | 1321 | } |
1300 | | | 1322 | |
1301 | /* | | 1323 | /* |
1302 | * Command/Bulk/Interrupt (CBI) specific functions | | 1324 | * Command/Bulk/Interrupt (CBI) specific functions |
1303 | */ | | 1325 | */ |
1304 | | | 1326 | |
1305 | Static int | | 1327 | Static int |
1306 | umass_cbi_adsc(struct umass_softc *sc, char *buffer, int buflen, | | 1328 | umass_cbi_adsc(struct umass_softc *sc, char *buffer, int buflen, |
1307 | usbd_xfer_handle xfer) | | 1329 | usbd_xfer_handle xfer) |
1308 | { | | 1330 | { |
1309 | KASSERT(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I), | | 1331 | KASSERT(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I), |
1310 | ("sc->sc_wire == 0x%02x wrong for umass_cbi_adsc\n", | | 1332 | ("sc->sc_wire == 0x%02x wrong for umass_cbi_adsc\n", |
| @@ -1344,57 +1366,57 @@ umass_cbi_reset(struct umass_softc *sc, | | | @@ -1344,57 +1366,57 @@ umass_cbi_reset(struct umass_softc *sc, |
1344 | * | | 1366 | * |
1345 | * First send a reset request to the device. Then clear | | 1367 | * First send a reset request to the device. Then clear |
1346 | * any possibly stalled bulk endpoints. | | 1368 | * any possibly stalled bulk endpoints. |
1347 | | | 1369 | |
1348 | * This is done in 3 steps, states: | | 1370 | * This is done in 3 steps, states: |
1349 | * TSTATE_CBI_RESET1 | | 1371 | * TSTATE_CBI_RESET1 |
1350 | * TSTATE_CBI_RESET2 | | 1372 | * TSTATE_CBI_RESET2 |
1351 | * TSTATE_CBI_RESET3 | | 1373 | * TSTATE_CBI_RESET3 |
1352 | * | | 1374 | * |
1353 | * If the reset doesn't succeed, the device should be port reset. | | 1375 | * If the reset doesn't succeed, the device should be port reset. |
1354 | */ | | 1376 | */ |
1355 | | | 1377 | |
1356 | DPRINTF(UDMASS_CBI, ("%s: CBI Reset\n", | | 1378 | DPRINTF(UDMASS_CBI, ("%s: CBI Reset\n", |
1357 | USBDEVNAME(sc->sc_dev))); | | 1379 | device_xname(sc->sc_dev))); |
1358 | | | 1380 | |
1359 | KASSERT(sizeof(sc->cbl) >= SEND_DIAGNOSTIC_CMDLEN, | | 1381 | KASSERT(sizeof(sc->cbl) >= SEND_DIAGNOSTIC_CMDLEN, |
1360 | ("%s: CBL struct is too small (%d < %d)\n", | | 1382 | ("%s: CBL struct is too small (%d < %d)\n", |
1361 | USBDEVNAME(sc->sc_dev), | | 1383 | device_xname(sc->sc_dev), |
1362 | sizeof(sc->cbl), SEND_DIAGNOSTIC_CMDLEN)); | | 1384 | sizeof(sc->cbl), SEND_DIAGNOSTIC_CMDLEN)); |
1363 | | | 1385 | |
1364 | sc->transfer_state = TSTATE_CBI_RESET1; | | 1386 | sc->transfer_state = TSTATE_CBI_RESET1; |
1365 | sc->transfer_status = status; | | 1387 | sc->transfer_status = status; |
1366 | | | 1388 | |
1367 | /* The 0x1d code is the SEND DIAGNOSTIC command. To distingiush between | | 1389 | /* The 0x1d code is the SEND DIAGNOSTIC command. To distingiush between |
1368 | * the two the last 10 bytes of the cbl is filled with 0xff (section | | 1390 | * the two the last 10 bytes of the cbl is filled with 0xff (section |
1369 | * 2.2 of the CBI spec). | | 1391 | * 2.2 of the CBI spec). |
1370 | */ | | 1392 | */ |
1371 | sc->cbl[0] = 0x1d; /* Command Block Reset */ | | 1393 | sc->cbl[0] = 0x1d; /* Command Block Reset */ |
1372 | sc->cbl[1] = 0x04; | | 1394 | sc->cbl[1] = 0x04; |
1373 | for (i = 2; i < SEND_DIAGNOSTIC_CMDLEN; i++) | | 1395 | for (i = 2; i < SEND_DIAGNOSTIC_CMDLEN; i++) |
1374 | sc->cbl[i] = 0xff; | | 1396 | sc->cbl[i] = 0xff; |
1375 | | | 1397 | |
1376 | umass_cbi_adsc(sc, sc->cbl, SEND_DIAGNOSTIC_CMDLEN, | | 1398 | umass_cbi_adsc(sc, sc->cbl, SEND_DIAGNOSTIC_CMDLEN, |
1377 | sc->transfer_xfer[XFER_CBI_RESET1]); | | 1399 | sc->transfer_xfer[XFER_CBI_RESET1]); |
1378 | /* XXX if the command fails we should reset the port on the bub */ | | 1400 | /* XXX if the command fails we should reset the port on the bub */ |
1379 | } | | 1401 | } |
1380 | | | 1402 | |
1381 | Static void | | 1403 | Static void |
1382 | umass_cbi_transfer(struct umass_softc *sc, int lun, | | 1404 | umass_cbi_transfer(struct umass_softc *sc, int lun, |
1383 | void *cmd, int cmdlen, void *data, int datalen, int dir, | | 1405 | void *cmd, int cmdlen, void *data, int datalen, int dir, |
1384 | u_int timeout, umass_callback cb, void *priv) | | 1406 | u_int timeout, umass_callback cb, void *priv) |
1385 | { | | 1407 | { |
1386 | DPRINTF(UDMASS_CBI,("%s: umass_cbi_transfer cmd=0x%02x, len=%d\n", | | 1408 | DPRINTF(UDMASS_CBI,("%s: umass_cbi_transfer cmd=0x%02x, len=%d\n", |
1387 | USBDEVNAME(sc->sc_dev), *(u_char *)cmd, datalen)); | | 1409 | device_xname(sc->sc_dev), *(u_char *)cmd, datalen)); |
1388 | | | 1410 | |
1389 | KASSERT(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I), | | 1411 | KASSERT(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I), |
1390 | ("sc->sc_wire == 0x%02x wrong for umass_cbi_transfer\n", | | 1412 | ("sc->sc_wire == 0x%02x wrong for umass_cbi_transfer\n", |
1391 | sc->sc_wire)); | | 1413 | sc->sc_wire)); |
1392 | | | 1414 | |
1393 | if (sc->sc_dying) | | 1415 | if (sc->sc_dying) |
1394 | return; | | 1416 | return; |
1395 | | | 1417 | |
1396 | /* Be a little generous. */ | | 1418 | /* Be a little generous. */ |
1397 | sc->timeout = timeout + USBD_DEFAULT_TIMEOUT; | | 1419 | sc->timeout = timeout + USBD_DEFAULT_TIMEOUT; |
1398 | | | 1420 | |
1399 | /* | | 1421 | /* |
1400 | * Do a CBI transfer with cmdlen bytes from cmd, possibly | | 1422 | * Do a CBI transfer with cmdlen bytes from cmd, possibly |
| @@ -1405,30 +1427,30 @@ umass_cbi_transfer(struct umass_softc *s | | | @@ -1405,30 +1427,30 @@ umass_cbi_transfer(struct umass_softc *s |
1405 | * | | 1427 | * |
1406 | * umass_cbi_transfer initialises the transfer and lets the state | | 1428 | * umass_cbi_transfer initialises the transfer and lets the state |
1407 | * machine in umass_cbi_state handle the completion. It uses the | | 1429 | * machine in umass_cbi_state handle the completion. It uses the |
1408 | * following states: | | 1430 | * following states: |
1409 | * TSTATE_CBI_COMMAND | | 1431 | * TSTATE_CBI_COMMAND |
1410 | * -> XXX fill in | | 1432 | * -> XXX fill in |
1411 | * | | 1433 | * |
1412 | * An error in any of those states will invoke | | 1434 | * An error in any of those states will invoke |
1413 | * umass_cbi_reset. | | 1435 | * umass_cbi_reset. |
1414 | */ | | 1436 | */ |
1415 | | | 1437 | |
1416 | /* check the given arguments */ | | 1438 | /* check the given arguments */ |
1417 | KASSERT(datalen == 0 || data != NULL, | | 1439 | KASSERT(datalen == 0 || data != NULL, |
1418 | ("%s: datalen > 0, but no buffer",USBDEVNAME(sc->sc_dev))); | | 1440 | ("%s: datalen > 0, but no buffer",device_xname(sc->sc_dev))); |
1419 | KASSERT(datalen == 0 || dir != DIR_NONE, | | 1441 | KASSERT(datalen == 0 || dir != DIR_NONE, |
1420 | ("%s: direction is NONE while datalen is not zero\n", | | 1442 | ("%s: direction is NONE while datalen is not zero\n", |
1421 | USBDEVNAME(sc->sc_dev))); | | 1443 | device_xname(sc->sc_dev))); |
1422 | | | 1444 | |
1423 | /* store the details for the data transfer phase */ | | 1445 | /* store the details for the data transfer phase */ |
1424 | sc->transfer_dir = dir; | | 1446 | sc->transfer_dir = dir; |
1425 | sc->transfer_data = data; | | 1447 | sc->transfer_data = data; |
1426 | sc->transfer_datalen = datalen; | | 1448 | sc->transfer_datalen = datalen; |
1427 | sc->transfer_actlen = 0; | | 1449 | sc->transfer_actlen = 0; |
1428 | sc->transfer_cb = cb; | | 1450 | sc->transfer_cb = cb; |
1429 | sc->transfer_priv = priv; | | 1451 | sc->transfer_priv = priv; |
1430 | sc->transfer_status = STATUS_CMD_OK; | | 1452 | sc->transfer_status = STATUS_CMD_OK; |
1431 | | | 1453 | |
1432 | /* move from idle to the command state */ | | 1454 | /* move from idle to the command state */ |
1433 | sc->transfer_state = TSTATE_CBI_COMMAND; | | 1455 | sc->transfer_state = TSTATE_CBI_COMMAND; |
1434 | | | 1456 | |
| @@ -1445,97 +1467,97 @@ umass_cbi_state(usbd_xfer_handle xfer, u | | | @@ -1445,97 +1467,97 @@ umass_cbi_state(usbd_xfer_handle xfer, u |
1445 | | | 1467 | |
1446 | KASSERT(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I), | | 1468 | KASSERT(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I), |
1447 | ("sc->sc_wire == 0x%02x wrong for umass_cbi_state\n", | | 1469 | ("sc->sc_wire == 0x%02x wrong for umass_cbi_state\n", |
1448 | sc->sc_wire)); | | 1470 | sc->sc_wire)); |
1449 | | | 1471 | |
1450 | if (sc->sc_dying) | | 1472 | if (sc->sc_dying) |
1451 | return; | | 1473 | return; |
1452 | | | 1474 | |
1453 | /* | | 1475 | /* |
1454 | * State handling for CBI transfers. | | 1476 | * State handling for CBI transfers. |
1455 | */ | | 1477 | */ |
1456 | | | 1478 | |
1457 | DPRINTF(UDMASS_CBI, ("%s: Handling CBI state %d (%s), xfer=%p, %s\n", | | 1479 | DPRINTF(UDMASS_CBI, ("%s: Handling CBI state %d (%s), xfer=%p, %s\n", |
1458 | USBDEVNAME(sc->sc_dev), sc->transfer_state, | | 1480 | device_xname(sc->sc_dev), sc->transfer_state, |
1459 | states[sc->transfer_state], xfer, usbd_errstr(err))); | | 1481 | states[sc->transfer_state], xfer, usbd_errstr(err))); |
1460 | | | 1482 | |
1461 | switch (sc->transfer_state) { | | 1483 | switch (sc->transfer_state) { |
1462 | | | 1484 | |
1463 | /***** CBI Transfer *****/ | | 1485 | /***** CBI Transfer *****/ |
1464 | case TSTATE_CBI_COMMAND: | | 1486 | case TSTATE_CBI_COMMAND: |
1465 | if (err == USBD_STALLED) { | | 1487 | if (err == USBD_STALLED) { |
1466 | DPRINTF(UDMASS_CBI, ("%s: Command Transport failed\n", | | 1488 | DPRINTF(UDMASS_CBI, ("%s: Command Transport failed\n", |
1467 | USBDEVNAME(sc->sc_dev))); | | 1489 | device_xname(sc->sc_dev))); |
1468 | /* Status transport by control pipe (section 2.3.2.1). | | 1490 | /* Status transport by control pipe (section 2.3.2.1). |
1469 | * The command contained in the command block failed. | | 1491 | * The command contained in the command block failed. |
1470 | * | | 1492 | * |
1471 | * The control pipe has already been unstalled by the | | 1493 | * The control pipe has already been unstalled by the |
1472 | * USB stack. | | 1494 | * USB stack. |
1473 | * Section 2.4.3.1.1 states that the bulk in endpoints | | 1495 | * Section 2.4.3.1.1 states that the bulk in endpoints |
1474 | * should not stalled at this point. | | 1496 | * should not stalled at this point. |
1475 | */ | | 1497 | */ |
1476 | | | 1498 | |
1477 | sc->transfer_state = TSTATE_IDLE; | | 1499 | sc->transfer_state = TSTATE_IDLE; |
1478 | sc->transfer_cb(sc, sc->transfer_priv, | | 1500 | sc->transfer_cb(sc, sc->transfer_priv, |
1479 | sc->transfer_datalen, | | 1501 | sc->transfer_datalen, |
1480 | STATUS_CMD_FAILED); | | 1502 | STATUS_CMD_FAILED); |
1481 | | | 1503 | |
1482 | return; | | 1504 | return; |
1483 | } else if (err) { | | 1505 | } else if (err) { |
1484 | DPRINTF(UDMASS_CBI, ("%s: failed to send ADSC\n", | | 1506 | DPRINTF(UDMASS_CBI, ("%s: failed to send ADSC\n", |
1485 | USBDEVNAME(sc->sc_dev))); | | 1507 | device_xname(sc->sc_dev))); |
1486 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); | | 1508 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); |
1487 | return; | | 1509 | return; |
1488 | } | | 1510 | } |
1489 | | | 1511 | |
1490 | /* Data transport phase, setup transfer */ | | 1512 | /* Data transport phase, setup transfer */ |
1491 | sc->transfer_state = TSTATE_CBI_DATA; | | 1513 | sc->transfer_state = TSTATE_CBI_DATA; |
1492 | if (sc->transfer_dir == DIR_IN) { | | 1514 | if (sc->transfer_dir == DIR_IN) { |
1493 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKIN], | | 1515 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKIN], |
1494 | sc->data_buffer, sc->transfer_datalen, | | 1516 | sc->data_buffer, sc->transfer_datalen, |
1495 | USBD_SHORT_XFER_OK | USBD_NO_COPY, | | 1517 | USBD_SHORT_XFER_OK | USBD_NO_COPY, |
1496 | sc->transfer_xfer[XFER_CBI_DATA])) | | 1518 | sc->transfer_xfer[XFER_CBI_DATA])) |
1497 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); | | 1519 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); |
1498 | | | 1520 | |
1499 | return; | | 1521 | return; |
1500 | } else if (sc->transfer_dir == DIR_OUT) { | | 1522 | } else if (sc->transfer_dir == DIR_OUT) { |
1501 | memcpy(sc->data_buffer, sc->transfer_data, | | 1523 | memcpy(sc->data_buffer, sc->transfer_data, |
1502 | sc->transfer_datalen); | | 1524 | sc->transfer_datalen); |
1503 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKOUT], | | 1525 | if (umass_setup_transfer(sc, sc->sc_pipe[UMASS_BULKOUT], |
1504 | sc->data_buffer, sc->transfer_datalen, | | 1526 | sc->data_buffer, sc->transfer_datalen, |
1505 | USBD_NO_COPY,/* fixed length transfer */ | | 1527 | USBD_NO_COPY,/* fixed length transfer */ |
1506 | sc->transfer_xfer[XFER_CBI_DATA])) | | 1528 | sc->transfer_xfer[XFER_CBI_DATA])) |
1507 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); | | 1529 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); |
1508 | | | 1530 | |
1509 | return; | | 1531 | return; |
1510 | } else { | | 1532 | } else { |
1511 | DPRINTF(UDMASS_CBI, ("%s: no data phase\n", | | 1533 | DPRINTF(UDMASS_CBI, ("%s: no data phase\n", |
1512 | USBDEVNAME(sc->sc_dev))); | | 1534 | device_xname(sc->sc_dev))); |
1513 | } | | 1535 | } |
1514 | | | 1536 | |
1515 | /* FALLTHROUGH if no data phase, err == 0 */ | | 1537 | /* FALLTHROUGH if no data phase, err == 0 */ |
1516 | case TSTATE_CBI_DATA: | | 1538 | case TSTATE_CBI_DATA: |
1517 | /* Command transport phase error handling (ignored if no data | | 1539 | /* Command transport phase error handling (ignored if no data |
1518 | * phase (fallthrough from previous state)) */ | | 1540 | * phase (fallthrough from previous state)) */ |
1519 | if (sc->transfer_dir != DIR_NONE) { | | 1541 | if (sc->transfer_dir != DIR_NONE) { |
1520 | /* retrieve the length of the transfer that was done */ | | 1542 | /* retrieve the length of the transfer that was done */ |
1521 | usbd_get_xfer_status(xfer, NULL, NULL, | | 1543 | usbd_get_xfer_status(xfer, NULL, NULL, |
1522 | &sc->transfer_actlen, NULL); | | 1544 | &sc->transfer_actlen, NULL); |
1523 | DPRINTF(UDMASS_CBI, ("%s: CBI_DATA actlen=%d\n", | | 1545 | DPRINTF(UDMASS_CBI, ("%s: CBI_DATA actlen=%d\n", |
1524 | USBDEVNAME(sc->sc_dev), sc->transfer_actlen)); | | 1546 | device_xname(sc->sc_dev), sc->transfer_actlen)); |
1525 | | | 1547 | |
1526 | if (err) { | | 1548 | if (err) { |
1527 | DPRINTF(UDMASS_CBI, ("%s: Data-%s %d failed, " | | 1549 | DPRINTF(UDMASS_CBI, ("%s: Data-%s %d failed, " |
1528 | "%s\n", USBDEVNAME(sc->sc_dev), | | 1550 | "%s\n", device_xname(sc->sc_dev), |
1529 | (sc->transfer_dir == DIR_IN?"in":"out"), | | 1551 | (sc->transfer_dir == DIR_IN?"in":"out"), |
1530 | sc->transfer_datalen,usbd_errstr(err))); | | 1552 | sc->transfer_datalen,usbd_errstr(err))); |
1531 | | | 1553 | |
1532 | if (err == USBD_STALLED) { | | 1554 | if (err == USBD_STALLED) { |
1533 | sc->transfer_state = TSTATE_CBI_DCLEAR; | | 1555 | sc->transfer_state = TSTATE_CBI_DCLEAR; |
1534 | umass_clear_endpoint_stall(sc, | | 1556 | umass_clear_endpoint_stall(sc, |
1535 | (sc->transfer_dir == DIR_IN? | | 1557 | (sc->transfer_dir == DIR_IN? |
1536 | UMASS_BULKIN:UMASS_BULKOUT), | | 1558 | UMASS_BULKIN:UMASS_BULKOUT), |
1537 | sc->transfer_xfer[XFER_CBI_DCLEAR]); | | 1559 | sc->transfer_xfer[XFER_CBI_DCLEAR]); |
1538 | } else { | | 1560 | } else { |
1539 | /* Unless the error is a pipe stall the | | 1561 | /* Unless the error is a pipe stall the |
1540 | * error is fatal. | | 1562 | * error is fatal. |
1541 | */ | | 1563 | */ |
| @@ -1566,81 +1588,81 @@ umass_cbi_state(usbd_xfer_handle xfer, u | | | @@ -1566,81 +1588,81 @@ umass_cbi_state(usbd_xfer_handle xfer, u |
1566 | /* No command completion interrupt. Request | | 1588 | /* No command completion interrupt. Request |
1567 | * sense to get status of command. | | 1589 | * sense to get status of command. |
1568 | */ | | 1590 | */ |
1569 | sc->transfer_state = TSTATE_IDLE; | | 1591 | sc->transfer_state = TSTATE_IDLE; |
1570 | sc->transfer_cb(sc, sc->transfer_priv, | | 1592 | sc->transfer_cb(sc, sc->transfer_priv, |
1571 | sc->transfer_datalen - sc->transfer_actlen, | | 1593 | sc->transfer_datalen - sc->transfer_actlen, |
1572 | STATUS_CMD_UNKNOWN); | | 1594 | STATUS_CMD_UNKNOWN); |
1573 | } | | 1595 | } |
1574 | return; | | 1596 | return; |
1575 | | | 1597 | |
1576 | case TSTATE_CBI_STATUS: | | 1598 | case TSTATE_CBI_STATUS: |
1577 | if (err) { | | 1599 | if (err) { |
1578 | DPRINTF(UDMASS_CBI, ("%s: Status Transport failed\n", | | 1600 | DPRINTF(UDMASS_CBI, ("%s: Status Transport failed\n", |
1579 | USBDEVNAME(sc->sc_dev))); | | 1601 | device_xname(sc->sc_dev))); |
1580 | /* Status transport by interrupt pipe (section 2.3.2.2). | | 1602 | /* Status transport by interrupt pipe (section 2.3.2.2). |
1581 | */ | | 1603 | */ |
1582 | | | 1604 | |
1583 | if (err == USBD_STALLED) { | | 1605 | if (err == USBD_STALLED) { |
1584 | sc->transfer_state = TSTATE_CBI_SCLEAR; | | 1606 | sc->transfer_state = TSTATE_CBI_SCLEAR; |
1585 | umass_clear_endpoint_stall(sc, UMASS_INTRIN, | | 1607 | umass_clear_endpoint_stall(sc, UMASS_INTRIN, |
1586 | sc->transfer_xfer[XFER_CBI_SCLEAR]); | | 1608 | sc->transfer_xfer[XFER_CBI_SCLEAR]); |
1587 | } else { | | 1609 | } else { |
1588 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); | | 1610 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); |
1589 | } | | 1611 | } |
1590 | return; | | 1612 | return; |
1591 | } | | 1613 | } |
1592 | | | 1614 | |
1593 | /* Dissect the information in the buffer */ | | 1615 | /* Dissect the information in the buffer */ |
1594 | | | 1616 | |
1595 | { | | 1617 | { |
1596 | u_int32_t actlen; | | 1618 | u_int32_t actlen; |
1597 | usbd_get_xfer_status(xfer,NULL,NULL,&actlen,NULL); | | 1619 | usbd_get_xfer_status(xfer,NULL,NULL,&actlen,NULL); |
1598 | DPRINTF(UDMASS_CBI, ("%s: CBI_STATUS actlen=%d\n", | | 1620 | DPRINTF(UDMASS_CBI, ("%s: CBI_STATUS actlen=%d\n", |
1599 | USBDEVNAME(sc->sc_dev), actlen)); | | 1621 | device_xname(sc->sc_dev), actlen)); |
1600 | if (actlen != 2) | | 1622 | if (actlen != 2) |
1601 | break; | | 1623 | break; |
1602 | } | | 1624 | } |
1603 | | | 1625 | |
1604 | if (sc->sc_cmd == UMASS_CPROTO_UFI) { | | 1626 | if (sc->sc_cmd == UMASS_CPROTO_UFI) { |
1605 | int status; | | 1627 | int status; |
1606 | | | 1628 | |
1607 | /* Section 3.4.3.1.3 specifies that the UFI command | | 1629 | /* Section 3.4.3.1.3 specifies that the UFI command |
1608 | * protocol returns an ASC and ASCQ in the interrupt | | 1630 | * protocol returns an ASC and ASCQ in the interrupt |
1609 | * data block. | | 1631 | * data block. |
1610 | */ | | 1632 | */ |
1611 | | | 1633 | |
1612 | DPRINTF(UDMASS_CBI, ("%s: UFI CCI, ASC = 0x%02x, " | | 1634 | DPRINTF(UDMASS_CBI, ("%s: UFI CCI, ASC = 0x%02x, " |
1613 | "ASCQ = 0x%02x\n", | | 1635 | "ASCQ = 0x%02x\n", |
1614 | USBDEVNAME(sc->sc_dev), | | 1636 | device_xname(sc->sc_dev), |
1615 | sc->sbl.ufi.asc, sc->sbl.ufi.ascq)); | | 1637 | sc->sbl.ufi.asc, sc->sbl.ufi.ascq)); |
1616 | | | 1638 | |
1617 | if ((sc->sbl.ufi.asc == 0 && sc->sbl.ufi.ascq == 0) || | | 1639 | if ((sc->sbl.ufi.asc == 0 && sc->sbl.ufi.ascq == 0) || |
1618 | sc->sc_sense) | | 1640 | sc->sc_sense) |
1619 | status = STATUS_CMD_OK; | | 1641 | status = STATUS_CMD_OK; |
1620 | else | | 1642 | else |
1621 | status = STATUS_CMD_FAILED; | | 1643 | status = STATUS_CMD_FAILED; |
1622 | | | 1644 | |
1623 | /* No autosense, command successful */ | | 1645 | /* No autosense, command successful */ |
1624 | sc->transfer_state = TSTATE_IDLE; | | 1646 | sc->transfer_state = TSTATE_IDLE; |
1625 | sc->transfer_cb(sc, sc->transfer_priv, | | 1647 | sc->transfer_cb(sc, sc->transfer_priv, |
1626 | sc->transfer_datalen - sc->transfer_actlen, status); | | 1648 | sc->transfer_datalen - sc->transfer_actlen, status); |
1627 | } else { | | 1649 | } else { |
1628 | int status; | | 1650 | int status; |
1629 | | | 1651 | |
1630 | /* Command Interrupt Data Block */ | | 1652 | /* Command Interrupt Data Block */ |
1631 | | | 1653 | |
1632 | DPRINTF(UDMASS_CBI, ("%s: type=0x%02x, value=0x%02x\n", | | 1654 | DPRINTF(UDMASS_CBI, ("%s: type=0x%02x, value=0x%02x\n", |
1633 | USBDEVNAME(sc->sc_dev), | | 1655 | device_xname(sc->sc_dev), |
1634 | sc->sbl.common.type, sc->sbl.common.value)); | | 1656 | sc->sbl.common.type, sc->sbl.common.value)); |
1635 | | | 1657 | |
1636 | if (sc->sbl.common.type == IDB_TYPE_CCI) { | | 1658 | if (sc->sbl.common.type == IDB_TYPE_CCI) { |
1637 | switch (sc->sbl.common.value & IDB_VALUE_STATUS_MASK) { | | 1659 | switch (sc->sbl.common.value & IDB_VALUE_STATUS_MASK) { |
1638 | case IDB_VALUE_PASS: | | 1660 | case IDB_VALUE_PASS: |
1639 | status = STATUS_CMD_OK; | | 1661 | status = STATUS_CMD_OK; |
1640 | break; | | 1662 | break; |
1641 | case IDB_VALUE_FAIL: | | 1663 | case IDB_VALUE_FAIL: |
1642 | case IDB_VALUE_PERSISTENT: | | 1664 | case IDB_VALUE_PERSISTENT: |
1643 | status = STATUS_CMD_FAILED; | | 1665 | status = STATUS_CMD_FAILED; |
1644 | break; | | 1666 | break; |
1645 | case IDB_VALUE_PHASE: | | 1667 | case IDB_VALUE_PHASE: |
1646 | default: /* XXX: gcc */ | | 1668 | default: /* XXX: gcc */ |
| @@ -1648,204 +1670,204 @@ umass_cbi_state(usbd_xfer_handle xfer, u | | | @@ -1648,204 +1670,204 @@ umass_cbi_state(usbd_xfer_handle xfer, u |
1648 | break; | | 1670 | break; |
1649 | } | | 1671 | } |
1650 | | | 1672 | |
1651 | sc->transfer_state = TSTATE_IDLE; | | 1673 | sc->transfer_state = TSTATE_IDLE; |
1652 | sc->transfer_cb(sc, sc->transfer_priv, | | 1674 | sc->transfer_cb(sc, sc->transfer_priv, |
1653 | sc->transfer_datalen - sc->transfer_actlen, status); | | 1675 | sc->transfer_datalen - sc->transfer_actlen, status); |
1654 | } | | 1676 | } |
1655 | } | | 1677 | } |
1656 | return; | | 1678 | return; |
1657 | | | 1679 | |
1658 | case TSTATE_CBI_DCLEAR: | | 1680 | case TSTATE_CBI_DCLEAR: |
1659 | if (err) { /* should not occur */ | | 1681 | if (err) { /* should not occur */ |
1660 | printf("%s: CBI bulk-%s stall clear failed, %s\n", | | 1682 | printf("%s: CBI bulk-%s stall clear failed, %s\n", |
1661 | USBDEVNAME(sc->sc_dev), | | 1683 | device_xname(sc->sc_dev), |
1662 | (sc->transfer_dir == DIR_IN? "in":"out"), | | 1684 | (sc->transfer_dir == DIR_IN? "in":"out"), |
1663 | usbd_errstr(err)); | | 1685 | usbd_errstr(err)); |
1664 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); | | 1686 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); |
1665 | } else { | | 1687 | } else { |
1666 | sc->transfer_state = TSTATE_IDLE; | | 1688 | sc->transfer_state = TSTATE_IDLE; |
1667 | sc->transfer_cb(sc, sc->transfer_priv, | | 1689 | sc->transfer_cb(sc, sc->transfer_priv, |
1668 | sc->transfer_datalen, STATUS_CMD_FAILED); | | 1690 | sc->transfer_datalen, STATUS_CMD_FAILED); |
1669 | } | | 1691 | } |
1670 | return; | | 1692 | return; |
1671 | | | 1693 | |
1672 | case TSTATE_CBI_SCLEAR: | | 1694 | case TSTATE_CBI_SCLEAR: |
1673 | if (err) { /* should not occur */ | | 1695 | if (err) { /* should not occur */ |
1674 | printf("%s: CBI intr-in stall clear failed, %s\n", | | 1696 | printf("%s: CBI intr-in stall clear failed, %s\n", |
1675 | USBDEVNAME(sc->sc_dev), usbd_errstr(err)); | | 1697 | device_xname(sc->sc_dev), usbd_errstr(err)); |
1676 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); | | 1698 | umass_cbi_reset(sc, STATUS_WIRE_FAILED); |
1677 | } else { | | 1699 | } else { |
1678 | sc->transfer_state = TSTATE_IDLE; | | 1700 | sc->transfer_state = TSTATE_IDLE; |
1679 | sc->transfer_cb(sc, sc->transfer_priv, | | 1701 | sc->transfer_cb(sc, sc->transfer_priv, |
1680 | sc->transfer_datalen, STATUS_CMD_FAILED); | | 1702 | sc->transfer_datalen, STATUS_CMD_FAILED); |
1681 | } | | 1703 | } |
1682 | return; | | 1704 | return; |
1683 | | | 1705 | |
1684 | /***** CBI Reset *****/ | | 1706 | /***** CBI Reset *****/ |
1685 | case TSTATE_CBI_RESET1: | | 1707 | case TSTATE_CBI_RESET1: |
1686 | if (err) | | 1708 | if (err) |
1687 | printf("%s: CBI reset failed, %s\n", | | 1709 | printf("%s: CBI reset failed, %s\n", |
1688 | USBDEVNAME(sc->sc_dev), usbd_errstr(err)); | | 1710 | device_xname(sc->sc_dev), usbd_errstr(err)); |
1689 | | | 1711 | |
1690 | sc->transfer_state = TSTATE_CBI_RESET2; | | 1712 | sc->transfer_state = TSTATE_CBI_RESET2; |
1691 | umass_clear_endpoint_stall(sc, UMASS_BULKIN, | | 1713 | umass_clear_endpoint_stall(sc, UMASS_BULKIN, |
1692 | sc->transfer_xfer[XFER_CBI_RESET2]); | | 1714 | sc->transfer_xfer[XFER_CBI_RESET2]); |
1693 | | | 1715 | |
1694 | return; | | 1716 | return; |
1695 | case TSTATE_CBI_RESET2: | | 1717 | case TSTATE_CBI_RESET2: |
1696 | if (err) /* should not occur */ | | 1718 | if (err) /* should not occur */ |
1697 | printf("%s: CBI bulk-in stall clear failed, %s\n", | | 1719 | printf("%s: CBI bulk-in stall clear failed, %s\n", |
1698 | USBDEVNAME(sc->sc_dev), usbd_errstr(err)); | | 1720 | device_xname(sc->sc_dev), usbd_errstr(err)); |
1699 | /* no error recovery, otherwise we end up in a loop */ | | 1721 | /* no error recovery, otherwise we end up in a loop */ |
1700 | | | 1722 | |
1701 | sc->transfer_state = TSTATE_CBI_RESET3; | | 1723 | sc->transfer_state = TSTATE_CBI_RESET3; |
1702 | umass_clear_endpoint_stall(sc, UMASS_BULKOUT, | | 1724 | umass_clear_endpoint_stall(sc, UMASS_BULKOUT, |
1703 | sc->transfer_xfer[XFER_CBI_RESET3]); | | 1725 | sc->transfer_xfer[XFER_CBI_RESET3]); |
1704 | | | 1726 | |
1705 | return; | | 1727 | return; |
1706 | case TSTATE_CBI_RESET3: | | 1728 | case TSTATE_CBI_RESET3: |
1707 | if (err) /* should not occur */ | | 1729 | if (err) /* should not occur */ |
1708 | printf("%s: CBI bulk-out stall clear failed, %s\n", | | 1730 | printf("%s: CBI bulk-out stall clear failed, %s\n", |
1709 | USBDEVNAME(sc->sc_dev), usbd_errstr(err)); | | 1731 | device_xname(sc->sc_dev), usbd_errstr(err)); |
1710 | /* no error recovery, otherwise we end up in a loop */ | | 1732 | /* no error recovery, otherwise we end up in a loop */ |
1711 | | | 1733 | |
1712 | sc->transfer_state = TSTATE_IDLE; | | 1734 | sc->transfer_state = TSTATE_IDLE; |
1713 | if (sc->transfer_priv) { | | 1735 | if (sc->transfer_priv) { |
1714 | sc->transfer_cb(sc, sc->transfer_priv, | | 1736 | sc->transfer_cb(sc, sc->transfer_priv, |
1715 | sc->transfer_datalen, | | 1737 | sc->transfer_datalen, |
1716 | sc->transfer_status); | | 1738 | sc->transfer_status); |
1717 | } | | 1739 | } |
1718 | | | 1740 | |
1719 | return; | | 1741 | return; |
1720 | | | 1742 | |
1721 | | | 1743 | |
1722 | /***** Default *****/ | | 1744 | /***** Default *****/ |
1723 | default: | | 1745 | default: |
1724 | panic("%s: Unknown state %d", | | 1746 | panic("%s: Unknown state %d", |
1725 | USBDEVNAME(sc->sc_dev), sc->transfer_state); | | 1747 | device_xname(sc->sc_dev), sc->transfer_state); |
1726 | } | | 1748 | } |
1727 | } | | 1749 | } |
1728 | | | 1750 | |
1729 | usbd_status | | 1751 | usbd_status |
1730 | umass_bbb_get_max_lun(struct umass_softc *sc, u_int8_t *maxlun) | | 1752 | umass_bbb_get_max_lun(struct umass_softc *sc, u_int8_t *maxlun) |
1731 | { | | 1753 | { |
1732 | usb_device_request_t req; | | 1754 | usb_device_request_t req; |
1733 | usbd_status err; | | 1755 | usbd_status err; |
1734 | | | 1756 | |
1735 | *maxlun = 0; /* Default to 0. */ | | 1757 | *maxlun = 0; /* Default to 0. */ |
1736 | | | 1758 | |
1737 | DPRINTF(UDMASS_BBB, ("%s: Get Max Lun\n", USBDEVNAME(sc->sc_dev))); | | 1759 | DPRINTF(UDMASS_BBB, ("%s: Get Max Lun\n", device_xname(sc->sc_dev))); |
1738 | | | 1760 | |
1739 | /* The Get Max Lun command is a class-specific request. */ | | 1761 | /* The Get Max Lun command is a class-specific request. */ |
1740 | req.bmRequestType = UT_READ_CLASS_INTERFACE; | | 1762 | req.bmRequestType = UT_READ_CLASS_INTERFACE; |
1741 | req.bRequest = UR_BBB_GET_MAX_LUN; | | 1763 | req.bRequest = UR_BBB_GET_MAX_LUN; |
1742 | USETW(req.wValue, 0); | | 1764 | USETW(req.wValue, 0); |
1743 | USETW(req.wIndex, sc->sc_ifaceno); | | 1765 | USETW(req.wIndex, sc->sc_ifaceno); |
1744 | USETW(req.wLength, 1); | | 1766 | USETW(req.wLength, 1); |
1745 | | | 1767 | |
1746 | err = usbd_do_request_flags(sc->sc_udev, &req, maxlun, | | 1768 | err = usbd_do_request_flags(sc->sc_udev, &req, maxlun, |
1747 | USBD_SHORT_XFER_OK, 0, USBD_DEFAULT_TIMEOUT); | | 1769 | USBD_SHORT_XFER_OK, 0, USBD_DEFAULT_TIMEOUT); |
1748 | switch (err) { | | 1770 | switch (err) { |
1749 | case USBD_NORMAL_COMPLETION: | | 1771 | case USBD_NORMAL_COMPLETION: |
1750 | DPRINTF(UDMASS_BBB, ("%s: Max Lun %d\n", | | 1772 | DPRINTF(UDMASS_BBB, ("%s: Max Lun %d\n", |
1751 | USBDEVNAME(sc->sc_dev), *maxlun)); | | 1773 | device_xname(sc->sc_dev), *maxlun)); |
1752 | break; | | 1774 | break; |
1753 | | | 1775 | |
1754 | case USBD_STALLED: | | 1776 | case USBD_STALLED: |
1755 | /* | | 1777 | /* |
1756 | * Device doesn't support Get Max Lun request. | | 1778 | * Device doesn't support Get Max Lun request. |
1757 | */ | | 1779 | */ |
1758 | err = USBD_NORMAL_COMPLETION; | | 1780 | err = USBD_NORMAL_COMPLETION; |
1759 | DPRINTF(UDMASS_BBB, ("%s: Get Max Lun not supported\n", | | 1781 | DPRINTF(UDMASS_BBB, ("%s: Get Max Lun not supported\n", |
1760 | USBDEVNAME(sc->sc_dev))); | | 1782 | device_xname(sc->sc_dev))); |
1761 | break; | | 1783 | break; |
1762 | | | 1784 | |
1763 | case USBD_SHORT_XFER: | | 1785 | case USBD_SHORT_XFER: |
1764 | /* | | 1786 | /* |
1765 | * XXX This must mean Get Max Lun is not supported, too! | | 1787 | * XXX This must mean Get Max Lun is not supported, too! |
1766 | */ | | 1788 | */ |
1767 | err = USBD_NORMAL_COMPLETION; | | 1789 | err = USBD_NORMAL_COMPLETION; |
1768 | DPRINTF(UDMASS_BBB, ("%s: Get Max Lun SHORT_XFER\n", | | 1790 | DPRINTF(UDMASS_BBB, ("%s: Get Max Lun SHORT_XFER\n", |
1769 | USBDEVNAME(sc->sc_dev))); | | 1791 | device_xname(sc->sc_dev))); |
1770 | break; | | 1792 | break; |
1771 | | | 1793 | |
1772 | default: | | 1794 | default: |
1773 | printf("%s: Get Max Lun failed: %s\n", | | 1795 | printf("%s: Get Max Lun failed: %s\n", |
1774 | USBDEVNAME(sc->sc_dev), usbd_errstr(err)); | | 1796 | device_xname(sc->sc_dev), usbd_errstr(err)); |
1775 | /* XXX Should we port_reset the device? */ | | 1797 | /* XXX Should we port_reset the device? */ |
1776 | break; | | 1798 | break; |
1777 | } | | 1799 | } |
1778 | | | 1800 | |
1779 | return (err); | | 1801 | return (err); |
1780 | } | | 1802 | } |
1781 | | | 1803 | |
1782 | | | 1804 | |
1783 | | | 1805 | |
1784 | | | 1806 | |
1785 | #ifdef UMASS_DEBUG | | 1807 | #ifdef UMASS_DEBUG |
1786 | Static void | | 1808 | Static void |
1787 | umass_bbb_dump_cbw(struct umass_softc *sc, umass_bbb_cbw_t *cbw) | | 1809 | umass_bbb_dump_cbw(struct umass_softc *sc, umass_bbb_cbw_t *cbw) |
1788 | { | | 1810 | { |
1789 | int clen = cbw->bCDBLength; | | 1811 | int clen = cbw->bCDBLength; |
1790 | int dlen = UGETDW(cbw->dCBWDataTransferLength); | | 1812 | int dlen = UGETDW(cbw->dCBWDataTransferLength); |
1791 | u_int8_t *c = cbw->CBWCDB; | | 1813 | u_int8_t *c = cbw->CBWCDB; |
1792 | int tag = UGETDW(cbw->dCBWTag); | | 1814 | int tag = UGETDW(cbw->dCBWTag); |
1793 | int flags = cbw->bCBWFlags; | | 1815 | int flags = cbw->bCBWFlags; |
1794 | | | 1816 | |
1795 | DPRINTF(UDMASS_BBB, ("%s: CBW %d: cmdlen=%d " | | 1817 | DPRINTF(UDMASS_BBB, ("%s: CBW %d: cmdlen=%d " |
1796 | "(0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%s), " | | 1818 | "(0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%s), " |
1797 | "data = %d bytes, dir = %s\n", | | 1819 | "data = %d bytes, dir = %s\n", |
1798 | USBDEVNAME(sc->sc_dev), tag, clen, | | 1820 | device_xname(sc->sc_dev), tag, clen, |
1799 | c[0], c[1], c[2], c[3], c[4], c[5], | | 1821 | c[0], c[1], c[2], c[3], c[4], c[5], |
1800 | c[6], c[7], c[8], c[9], | | 1822 | c[6], c[7], c[8], c[9], |
1801 | (clen > 10? "...":""), | | 1823 | (clen > 10? "...":""), |
1802 | dlen, (flags == CBWFLAGS_IN? "in": | | 1824 | dlen, (flags == CBWFLAGS_IN? "in": |
1803 | (flags == CBWFLAGS_OUT? "out":"<invalid>")))); | | 1825 | (flags == CBWFLAGS_OUT? "out":"<invalid>")))); |
1804 | } | | 1826 | } |
1805 | | | 1827 | |
1806 | Static void | | 1828 | Static void |
1807 | umass_bbb_dump_csw(struct umass_softc *sc, umass_bbb_csw_t *csw) | | 1829 | umass_bbb_dump_csw(struct umass_softc *sc, umass_bbb_csw_t *csw) |
1808 | { | | 1830 | { |
1809 | int sig = UGETDW(csw->dCSWSignature); | | 1831 | int sig = UGETDW(csw->dCSWSignature); |
1810 | int tag = UGETDW(csw->dCSWTag); | | 1832 | int tag = UGETDW(csw->dCSWTag); |
1811 | int res = UGETDW(csw->dCSWDataResidue); | | 1833 | int res = UGETDW(csw->dCSWDataResidue); |
1812 | int status = csw->bCSWStatus; | | 1834 | int status = csw->bCSWStatus; |
1813 | | | 1835 | |
1814 | DPRINTF(UDMASS_BBB, ("%s: CSW %d: sig = 0x%08x (%s), tag = %d, " | | 1836 | DPRINTF(UDMASS_BBB, ("%s: CSW %d: sig = 0x%08x (%s), tag = %d, " |
1815 | "res = %d, status = 0x%02x (%s)\n", USBDEVNAME(sc->sc_dev), | | 1837 | "res = %d, status = 0x%02x (%s)\n", device_xname(sc->sc_dev), |
1816 | tag, sig, (sig == CSWSIGNATURE? "valid":"invalid"), | | 1838 | tag, sig, (sig == CSWSIGNATURE? "valid":"invalid"), |
1817 | tag, res, | | 1839 | tag, res, |
1818 | status, (status == CSWSTATUS_GOOD? "good": | | 1840 | status, (status == CSWSTATUS_GOOD? "good": |
1819 | (status == CSWSTATUS_FAILED? "failed": | | 1841 | (status == CSWSTATUS_FAILED? "failed": |
1820 | (status == CSWSTATUS_PHASE? "phase":"<invalid>"))))); | | 1842 | (status == CSWSTATUS_PHASE? "phase":"<invalid>"))))); |
1821 | } | | 1843 | } |
1822 | | | 1844 | |
1823 | Static void | | 1845 | Static void |
1824 | umass_dump_buffer(struct umass_softc *sc, u_int8_t *buffer, int buflen, | | 1846 | umass_dump_buffer(struct umass_softc *sc, u_int8_t *buffer, int buflen, |
1825 | int printlen) | | 1847 | int printlen) |
1826 | { | | 1848 | { |
1827 | int i, j; | | 1849 | int i, j; |
1828 | char s1[40]; | | 1850 | char s1[40]; |
1829 | char s2[40]; | | 1851 | char s2[40]; |
1830 | char s3[5]; | | 1852 | char s3[5]; |
1831 | | | 1853 | |
1832 | s1[0] = '\0'; | | 1854 | s1[0] = '\0'; |
1833 | s3[0] = '\0'; | | 1855 | s3[0] = '\0'; |
1834 | | | 1856 | |
1835 | snprintf(s2, sizeof(s2), " buffer=%p, buflen=%d", buffer, buflen); | | 1857 | snprintf(s2, sizeof(s2), " buffer=%p, buflen=%d", buffer, buflen); |
1836 | for (i = 0; i < buflen && i < printlen; i++) { | | 1858 | for (i = 0; i < buflen && i < printlen; i++) { |
1837 | j = i % 16; | | 1859 | j = i % 16; |
1838 | if (j == 0 && i != 0) { | | 1860 | if (j == 0 && i != 0) { |
1839 | DPRINTF(UDMASS_GEN, ("%s: 0x %s%s\n", | | 1861 | DPRINTF(UDMASS_GEN, ("%s: 0x %s%s\n", |
1840 | USBDEVNAME(sc->sc_dev), s1, s2)); | | 1862 | device_xname(sc->sc_dev), s1, s2)); |
1841 | s2[0] = '\0'; | | 1863 | s2[0] = '\0'; |
1842 | } | | 1864 | } |
1843 | snprintf(&s1[j * 2], sizeof(s1) - j * 2, "%02x", | | 1865 | snprintf(&s1[j * 2], sizeof(s1) - j * 2, "%02x", |
1844 | buffer[i] & 0xff); | | 1866 | buffer[i] & 0xff); |
1845 | } | | 1867 | } |
1846 | if (buflen > printlen) | | 1868 | if (buflen > printlen) |
1847 | snprintf(s3, sizeof(s3), " ..."); | | 1869 | snprintf(s3, sizeof(s3), " ..."); |
1848 | DPRINTF(UDMASS_GEN, ("%s: 0x %s%s%s\n", | | 1870 | DPRINTF(UDMASS_GEN, ("%s: 0x %s%s%s\n", |
1849 | USBDEVNAME(sc->sc_dev), s1, s2, s3)); | | 1871 | device_xname(sc->sc_dev), s1, s2, s3)); |
1850 | } | | 1872 | } |
1851 | #endif | | 1873 | #endif |