Deleted Added
full compact
usb_msctest.c (194227) usb_msctest.c (194228)
1/* $FreeBSD: head/sys/dev/usb/usb_msctest.c 194227 2009-06-15 00:33:18Z thompsa $ */
1/* $FreeBSD: head/sys/dev/usb/usb_msctest.c 194228 2009-06-15 01:02:43Z thompsa $ */
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 21 unchanged lines hidden (view full) ---

31 * TODO: Potentially we could add code to automatically detect USB
32 * mass storage quirks for not supported SCSI commands!
33 */
34
35#include <dev/usb/usb_mfunc.h>
36#include <dev/usb/usb_error.h>
37#include <dev/usb/usb.h>
38
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 21 unchanged lines hidden (view full) ---

31 * TODO: Potentially we could add code to automatically detect USB
32 * mass storage quirks for not supported SCSI commands!
33 */
34
35#include <dev/usb/usb_mfunc.h>
36#include <dev/usb/usb_error.h>
37#include <dev/usb/usb.h>
38
39#define USB_DEBUG_VAR usb2_debug
39#define USB_DEBUG_VAR usb_debug
40
41#include <dev/usb/usb_core.h>
42#include <dev/usb/usb_busdma.h>
43#include <dev/usb/usb_process.h>
44#include <dev/usb/usb_transfer.h>
45#include <dev/usb/usb_msctest.h>
46#include <dev/usb/usb_debug.h>
47#include <dev/usb/usb_busdma.h>

--- 168 unchanged lines hidden (view full) ---

216 sc->status_try = 1;
217 cv_signal(&sc->cv);
218}
219
220static void
221bbb_transfer_start(struct bbb_transfer *sc, uint8_t xfer_index)
222{
223 sc->state = xfer_index;
40
41#include <dev/usb/usb_core.h>
42#include <dev/usb/usb_busdma.h>
43#include <dev/usb/usb_process.h>
44#include <dev/usb/usb_transfer.h>
45#include <dev/usb/usb_msctest.h>
46#include <dev/usb/usb_debug.h>
47#include <dev/usb/usb_busdma.h>

--- 168 unchanged lines hidden (view full) ---

216 sc->status_try = 1;
217 cv_signal(&sc->cv);
218}
219
220static void
221bbb_transfer_start(struct bbb_transfer *sc, uint8_t xfer_index)
222{
223 sc->state = xfer_index;
224 usb2_transfer_start(sc->xfer[xfer_index]);
224 usbd_transfer_start(sc->xfer[xfer_index]);
225}
226
227static void
228bbb_data_clear_stall_callback(struct usb_xfer *xfer,
229 uint8_t next_xfer, uint8_t stall_xfer)
230{
231 struct bbb_transfer *sc = xfer->priv_sc;
232
225}
226
227static void
228bbb_data_clear_stall_callback(struct usb_xfer *xfer,
229 uint8_t next_xfer, uint8_t stall_xfer)
230{
231 struct bbb_transfer *sc = xfer->priv_sc;
232
233 if (usb2_clear_stall_callback(xfer, sc->xfer[stall_xfer])) {
233 if (usbd_clear_stall_callback(xfer, sc->xfer[stall_xfer])) {
234 switch (USB_GET_STATE(xfer)) {
235 case USB_ST_SETUP:
236 case USB_ST_TRANSFERRED:
237 bbb_transfer_start(sc, next_xfer);
238 break;
239 default:
240 bbb_done(sc, 1);
241 break;

--- 25 unchanged lines hidden (view full) ---

267 sc->cbw.bCBWLUN = sc->lun;
268 sc->cbw.bCDBLength = sc->cmd_len;
269 if (sc->cbw.bCDBLength > sizeof(sc->cbw.CBWCDB)) {
270 sc->cbw.bCDBLength = sizeof(sc->cbw.CBWCDB);
271 DPRINTFN(0, "Truncating long command!\n");
272 }
273 xfer->frlengths[0] = sizeof(sc->cbw);
274
234 switch (USB_GET_STATE(xfer)) {
235 case USB_ST_SETUP:
236 case USB_ST_TRANSFERRED:
237 bbb_transfer_start(sc, next_xfer);
238 break;
239 default:
240 bbb_done(sc, 1);
241 break;

--- 25 unchanged lines hidden (view full) ---

267 sc->cbw.bCBWLUN = sc->lun;
268 sc->cbw.bCDBLength = sc->cmd_len;
269 if (sc->cbw.bCDBLength > sizeof(sc->cbw.CBWCDB)) {
270 sc->cbw.bCDBLength = sizeof(sc->cbw.CBWCDB);
271 DPRINTFN(0, "Truncating long command!\n");
272 }
273 xfer->frlengths[0] = sizeof(sc->cbw);
274
275 usb2_set_frame_data(xfer, &sc->cbw, 0);
276 usb2_start_hardware(xfer);
275 usbd_set_frame_data(xfer, &sc->cbw, 0);
276 usbd_transfer_submit(xfer);
277 break;
278
279 default: /* Error */
280 bbb_done(sc, 1);
281 break;
282 }
283}
284

--- 22 unchanged lines hidden (view full) ---

307 break;
308 }
309 if (max_bulk > sc->data_rem) {
310 max_bulk = sc->data_rem;
311 }
312 xfer->timeout = sc->data_timeout;
313 xfer->frlengths[0] = max_bulk;
314
277 break;
278
279 default: /* Error */
280 bbb_done(sc, 1);
281 break;
282 }
283}
284

--- 22 unchanged lines hidden (view full) ---

307 break;
308 }
309 if (max_bulk > sc->data_rem) {
310 max_bulk = sc->data_rem;
311 }
312 xfer->timeout = sc->data_timeout;
313 xfer->frlengths[0] = max_bulk;
314
315 usb2_set_frame_data(xfer, sc->data_ptr, 0);
316 usb2_start_hardware(xfer);
315 usbd_set_frame_data(xfer, sc->data_ptr, 0);
316 usbd_transfer_submit(xfer);
317 break;
318
319 default: /* Error */
320 if (xfer->error == USB_ERR_CANCELLED) {
321 bbb_done(sc, 1);
322 } else {
323 bbb_transfer_start(sc, ST_DATA_RD_CS);
324 }

--- 33 unchanged lines hidden (view full) ---

358 return;
359 }
360 if (max_bulk > sc->data_rem) {
361 max_bulk = sc->data_rem;
362 }
363 xfer->timeout = sc->data_timeout;
364 xfer->frlengths[0] = max_bulk;
365
317 break;
318
319 default: /* Error */
320 if (xfer->error == USB_ERR_CANCELLED) {
321 bbb_done(sc, 1);
322 } else {
323 bbb_transfer_start(sc, ST_DATA_RD_CS);
324 }

--- 33 unchanged lines hidden (view full) ---

358 return;
359 }
360 if (max_bulk > sc->data_rem) {
361 max_bulk = sc->data_rem;
362 }
363 xfer->timeout = sc->data_timeout;
364 xfer->frlengths[0] = max_bulk;
365
366 usb2_set_frame_data(xfer, sc->data_ptr, 0);
367 usb2_start_hardware(xfer);
366 usbd_set_frame_data(xfer, sc->data_ptr, 0);
367 usbd_transfer_submit(xfer);
368 return;
369
370 default: /* Error */
371 if (xfer->error == USB_ERR_CANCELLED) {
372 bbb_done(sc, 1);
373 } else {
374 bbb_transfer_start(sc, ST_DATA_WR_CS);
375 }

--- 26 unchanged lines hidden (view full) ---

402 } else {
403 bbb_done(sc, 1);/* error */
404 }
405 break;
406
407 case USB_ST_SETUP:
408 xfer->frlengths[0] = sizeof(sc->csw);
409
368 return;
369
370 default: /* Error */
371 if (xfer->error == USB_ERR_CANCELLED) {
372 bbb_done(sc, 1);
373 } else {
374 bbb_transfer_start(sc, ST_DATA_WR_CS);
375 }

--- 26 unchanged lines hidden (view full) ---

402 } else {
403 bbb_done(sc, 1);/* error */
404 }
405 break;
406
407 case USB_ST_SETUP:
408 xfer->frlengths[0] = sizeof(sc->csw);
409
410 usb2_set_frame_data(xfer, &sc->csw, 0);
411 usb2_start_hardware(xfer);
410 usbd_set_frame_data(xfer, &sc->csw, 0);
411 usbd_transfer_submit(xfer);
412 break;
413
414 default:
415 DPRINTFN(0, "Failed to read CSW: %s, try %d\n",
412 break;
413
414 default:
415 DPRINTFN(0, "Failed to read CSW: %s, try %d\n",
416 usb2_errstr(xfer->error), sc->status_try);
416 usbd_errstr(xfer->error), sc->status_try);
417
418 if ((xfer->error == USB_ERR_CANCELLED) ||
419 (sc->status_try)) {
420 bbb_done(sc, 1);
421 } else {
422 sc->status_try = 1;
423 bbb_transfer_start(sc, ST_DATA_RD_CS);
424 }

--- 17 unchanged lines hidden (view full) ---

442 sc->dir = data_len ? dir : DIR_NONE;
443 sc->data_ptr = data_ptr;
444 sc->data_len = data_len;
445 sc->data_rem = data_len;
446 sc->data_timeout = (data_timeout + USB_MS_HZ);
447 sc->actlen = 0;
448 sc->cmd_len = cmd_len;
449
417
418 if ((xfer->error == USB_ERR_CANCELLED) ||
419 (sc->status_try)) {
420 bbb_done(sc, 1);
421 } else {
422 sc->status_try = 1;
423 bbb_transfer_start(sc, ST_DATA_RD_CS);
424 }

--- 17 unchanged lines hidden (view full) ---

442 sc->dir = data_len ? dir : DIR_NONE;
443 sc->data_ptr = data_ptr;
444 sc->data_len = data_len;
445 sc->data_rem = data_len;
446 sc->data_timeout = (data_timeout + USB_MS_HZ);
447 sc->actlen = 0;
448 sc->cmd_len = cmd_len;
449
450 usb2_transfer_start(sc->xfer[sc->state]);
450 usbd_transfer_start(sc->xfer[sc->state]);
451
451
452 while (usb2_transfer_pending(sc->xfer[sc->state])) {
452 while (usbd_transfer_pending(sc->xfer[sc->state])) {
453 cv_wait(&sc->cv, &sc->mtx);
454 }
455 return (sc->error);
456}
457
458/*------------------------------------------------------------------------*
453 cv_wait(&sc->cv, &sc->mtx);
454 }
455 return (sc->error);
456}
457
458/*------------------------------------------------------------------------*
459 * usb2_test_autoinstall
459 * usb_test_autoinstall
460 *
461 * Return values:
462 * 0: This interface is an auto install disk (CD-ROM)
463 * Else: Not an auto install disk.
464 *------------------------------------------------------------------------*/
465usb_error_t
460 *
461 * Return values:
462 * 0: This interface is an auto install disk (CD-ROM)
463 * Else: Not an auto install disk.
464 *------------------------------------------------------------------------*/
465usb_error_t
466usb2_test_autoinstall(struct usb_device *udev, uint8_t iface_index,
466usb_test_autoinstall(struct usb_device *udev, uint8_t iface_index,
467 uint8_t do_eject)
468{
469 struct usb_interface *iface;
470 struct usb_interface_descriptor *id;
471 usb_error_t err;
472 uint8_t timeout;
473 uint8_t sid_type;
474 struct bbb_transfer *sc;
475
476 if (udev == NULL) {
477 return (USB_ERR_INVAL);
478 }
467 uint8_t do_eject)
468{
469 struct usb_interface *iface;
470 struct usb_interface_descriptor *id;
471 usb_error_t err;
472 uint8_t timeout;
473 uint8_t sid_type;
474 struct bbb_transfer *sc;
475
476 if (udev == NULL) {
477 return (USB_ERR_INVAL);
478 }
479 iface = usb2_get_iface(udev, iface_index);
479 iface = usbd_get_iface(udev, iface_index);
480 if (iface == NULL) {
481 return (USB_ERR_INVAL);
482 }
483 id = iface->idesc;
484 if (id == NULL) {
485 return (USB_ERR_INVAL);
486 }
487 if (id->bInterfaceClass != UICLASS_MASS) {

--- 17 unchanged lines hidden (view full) ---

505
506 sc = malloc(sizeof(*sc), M_USB, M_WAITOK | M_ZERO);
507 if (sc == NULL) {
508 return (USB_ERR_NOMEM);
509 }
510 mtx_init(&sc->mtx, "USB autoinstall", NULL, MTX_DEF);
511 cv_init(&sc->cv, "WBBB");
512
480 if (iface == NULL) {
481 return (USB_ERR_INVAL);
482 }
483 id = iface->idesc;
484 if (id == NULL) {
485 return (USB_ERR_INVAL);
486 }
487 if (id->bInterfaceClass != UICLASS_MASS) {

--- 17 unchanged lines hidden (view full) ---

505
506 sc = malloc(sizeof(*sc), M_USB, M_WAITOK | M_ZERO);
507 if (sc == NULL) {
508 return (USB_ERR_NOMEM);
509 }
510 mtx_init(&sc->mtx, "USB autoinstall", NULL, MTX_DEF);
511 cv_init(&sc->cv, "WBBB");
512
513 err = usb2_transfer_setup(udev,
513 err = usbd_transfer_setup(udev,
514 &iface_index, sc->xfer, bbb_config,
515 ST_MAX, sc, &sc->mtx);
516
517 if (err) {
518 goto done;
519 }
520 mtx_lock(&sc->mtx);
521

--- 25 unchanged lines hidden (view full) ---

547 /* 4: Load/Eject command */
548 sc->cbw.CBWCDB[4] = 0x02;
549 /* 5: control */
550 sc->cbw.CBWCDB[5] = 0x00;
551 err = bbb_command_start(sc, DIR_OUT, 0,
552 NULL, 0, 6, USB_MS_HZ);
553
554 DPRINTFN(0, "Eject CD command "
514 &iface_index, sc->xfer, bbb_config,
515 ST_MAX, sc, &sc->mtx);
516
517 if (err) {
518 goto done;
519 }
520 mtx_lock(&sc->mtx);
521

--- 25 unchanged lines hidden (view full) ---

547 /* 4: Load/Eject command */
548 sc->cbw.CBWCDB[4] = 0x02;
549 /* 5: control */
550 sc->cbw.CBWCDB[5] = 0x00;
551 err = bbb_command_start(sc, DIR_OUT, 0,
552 NULL, 0, 6, USB_MS_HZ);
553
554 DPRINTFN(0, "Eject CD command "
555 "status: %s\n", usb2_errstr(err));
555 "status: %s\n", usbd_errstr(err));
556 }
557 err = 0;
558 goto done;
559 }
560 } else if ((err != 2) && --timeout) {
556 }
557 err = 0;
558 goto done;
559 }
560 } else if ((err != 2) && --timeout) {
561 usb2_pause_mtx(&sc->mtx, hz);
561 usb_pause_mtx(&sc->mtx, hz);
562 goto repeat_inquiry;
563 }
564 err = USB_ERR_INVAL;
565 goto done;
566
567done:
568 mtx_unlock(&sc->mtx);
562 goto repeat_inquiry;
563 }
564 err = USB_ERR_INVAL;
565 goto done;
566
567done:
568 mtx_unlock(&sc->mtx);
569 usb2_transfer_unsetup(sc->xfer, ST_MAX);
569 usbd_transfer_unsetup(sc->xfer, ST_MAX);
570 mtx_destroy(&sc->mtx);
571 cv_destroy(&sc->cv);
572 free(sc, M_USB);
573 return (err);
574}
570 mtx_destroy(&sc->mtx);
571 cv_destroy(&sc->cv);
572 free(sc, M_USB);
573 return (err);
574}