Wed Feb 19 16:04:01 2020 UTC ()
umass dtrace probes


(riastradh)
diff -r1.179 -r1.180 src/sys/dev/usb/umass.c

cvs diff -r1.179 -r1.180 src/sys/dev/usb/umass.c (expand / switch to unified diff)

--- src/sys/dev/usb/umass.c 2020/02/19 16:02:50 1.179
+++ src/sys/dev/usb/umass.c 2020/02/19 16:04:01 1.180
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: umass.c,v 1.179 2020/02/19 16:02:50 riastradh Exp $ */ 1/* $NetBSD: umass.c,v 1.180 2020/02/19 16:04:01 riastradh 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,59 +114,110 @@ @@ -114,59 +114,110 @@
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.179 2020/02/19 16:02:50 riastradh Exp $"); 127__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.180 2020/02/19 16:04:01 riastradh Exp $");
128 128
129#ifdef _KERNEL_OPT 129#ifdef _KERNEL_OPT
130#include "opt_usb.h" 130#include "opt_usb.h"
131#endif 131#endif
132 132
133#include "atapibus.h" 133#include "atapibus.h"
134#include "scsibus.h" 134#include "scsibus.h"
135#include "wd.h" 135#include "wd.h"
136 136
137#include <sys/param.h> 137#include <sys/param.h>
138#include <sys/buf.h> 138#include <sys/buf.h>
139#include <sys/conf.h> 139#include <sys/conf.h>
140#include <sys/device.h> 140#include <sys/device.h>
141#include <sys/kernel.h> 141#include <sys/kernel.h>
142#include <sys/kmem.h> 142#include <sys/kmem.h>
143#include <sys/sysctl.h> 143#include <sys/sysctl.h>
144#include <sys/systm.h> 144#include <sys/systm.h>
145 145
146#include <dev/usb/usb.h> 146#include <dev/usb/usb.h>
 147#include <dev/usb/usb_sdt.h>
147#include <dev/usb/usbdi.h> 148#include <dev/usb/usbdi.h>
148#include <dev/usb/usbdi_util.h> 149#include <dev/usb/usbdi_util.h>
149#include <dev/usb/usbdevs.h> 150#include <dev/usb/usbdevs.h>
150#include <dev/usb/usbhist.h> 151#include <dev/usb/usbhist.h>
151 152
152#include <dev/usb/umassvar.h> 153#include <dev/usb/umassvar.h>
153#include <dev/usb/umass_quirks.h> 154#include <dev/usb/umass_quirks.h>
154#include <dev/usb/umass_scsipi.h> 155#include <dev/usb/umass_scsipi.h>
155#include <dev/usb/umass_isdata.h> 156#include <dev/usb/umass_isdata.h>
156 157
157#include <dev/scsipi/scsipi_all.h> 158#include <dev/scsipi/scsipi_all.h>
158#include <dev/scsipi/scsipiconf.h> 159#include <dev/scsipi/scsipiconf.h>
159 160
 161SDT_PROBE_DEFINE1(usb, umass, device, attach__start,
 162 "struct umass_softc *"/*sc*/);
 163SDT_PROBE_DEFINE2(usb, umass, device, attach__done,
 164 "struct umass_softc *"/*sc*/, "usbd_status"/*err*/);
 165SDT_PROBE_DEFINE1(usb, umass, device, detach__start,
 166 "struct umass_softc *"/*sc*/);
 167SDT_PROBE_DEFINE2(usb, umass, device, detach__done,
 168 "struct umass_softc *"/*sc*/, "int"/*error*/);
 169
 170SDT_PROBE_DEFINE7(usb, umass, transfer, start__bbb,
 171 "struct umass_softc *"/*sc*/,
 172 "transfer_cb_f"/*cb*/,
 173 "void *"/*priv*/,
 174 "void *"/*data*/,
 175 "int"/*datalen*/,
 176 "int"/*dir*/,
 177 "int"/*timeout*/);
 178SDT_PROBE_DEFINE7(usb, umass, transfer, start__cbi,
 179 "struct umass_softc *"/*sc*/,
 180 "transfer_cb_f"/*cb*/,
 181 "void *"/*priv*/,
 182 "void *"/*data*/,
 183 "int"/*datalen*/,
 184 "int"/*dir*/,
 185 "int"/*timeout*/);
 186SDT_PROBE_DEFINE7(usb, umass, transfer, done,
 187 "struct umass_softc *"/*sc*/,
 188 "transfer_cb_f"/*cb*/,
 189 "void *"/*priv*/,
 190 "void *"/*data*/,
 191 "int"/*datalen*/,
 192 "int"/*resid*/,
 193 "int"/*status*/); /* STATUS_* */
 194
 195SDT_PROBE_DEFINE3(usb, umass, bbb, state,
 196 "struct umass_softc *"/*sc*/,
 197 "struct usbd_xfer *"/*xfer*/,
 198 "usbd_status"/*err*/);
 199SDT_PROBE_DEFINE2(usb, umass, bbb, reset,
 200 "struct umass_softc *"/*sc*/,
 201 "int"/*status*/);
 202
 203SDT_PROBE_DEFINE3(usb, umass, cbi, state,
 204 "struct umass_softc *"/*sc*/,
 205 "struct usbd_xfer *"/*xfer*/,
 206 "usbd_status"/*err*/);
 207SDT_PROBE_DEFINE2(usb, umass, cbi, reset,
 208 "struct umass_softc *"/*sc*/,
 209 "int"/*status*/);
 210
160#ifdef USB_DEBUG 211#ifdef USB_DEBUG
161#ifdef UMASS_DEBUG 212#ifdef UMASS_DEBUG
162int umassdebug = 0; 213int umassdebug = 0;
163 214
164SYSCTL_SETUP(sysctl_hw_umass_setup, "sysctl hw.umass setup") 215SYSCTL_SETUP(sysctl_hw_umass_setup, "sysctl hw.umass setup")
165{ 216{
166 int err; 217 int err;
167 const struct sysctlnode *rnode; 218 const struct sysctlnode *rnode;
168 const struct sysctlnode *cnode; 219 const struct sysctlnode *cnode;
169 220
170 err = sysctl_createv(clog, 0, NULL, &rnode, 221 err = sysctl_createv(clog, 0, NULL, &rnode,
171 CTLFLAG_PERMANENT, CTLTYPE_NODE, "umass", 222 CTLFLAG_PERMANENT, CTLTYPE_NODE, "umass",
172 SYSCTL_DESCR("umass global controls"), 223 SYSCTL_DESCR("umass global controls"),
@@ -325,26 +376,28 @@ static void @@ -325,26 +376,28 @@ static void
325umass_attach(device_t parent, device_t self, void *aux) 376umass_attach(device_t parent, device_t self, void *aux)
326{ 377{
327 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 378 UMASSHIST_FUNC(); UMASSHIST_CALLED();
328 struct umass_softc *sc = device_private(self); 379 struct umass_softc *sc = device_private(self);
329 struct usbif_attach_arg *uiaa = aux; 380 struct usbif_attach_arg *uiaa = aux;
330 const struct umass_quirk *quirk; 381 const struct umass_quirk *quirk;
331 usb_interface_descriptor_t *id; 382 usb_interface_descriptor_t *id;
332 usb_endpoint_descriptor_t *ed; 383 usb_endpoint_descriptor_t *ed;
333 const char *sWire, *sCommand; 384 const char *sWire, *sCommand;
334 char *devinfop; 385 char *devinfop;
335 usbd_status err; 386 usbd_status err;
336 int i, error; 387 int i, error;
337 388
 389 SDT_PROBE1(usb, umass, device, attach__start, sc);
 390
338 sc->sc_dev = self; 391 sc->sc_dev = self;
339 392
340 aprint_naive("\n"); 393 aprint_naive("\n");
341 aprint_normal("\n"); 394 aprint_normal("\n");
342 395
343 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); 396 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB);
344 cv_init(&sc->sc_detach_cv, "umassdet"); 397 cv_init(&sc->sc_detach_cv, "umassdet");
345 398
346 devinfop = usbd_devinfo_alloc(uiaa->uiaa_device, 0); 399 devinfop = usbd_devinfo_alloc(uiaa->uiaa_device, 0);
347 aprint_normal_dev(self, "%s\n", devinfop); 400 aprint_normal_dev(self, "%s\n", devinfop);
348 usbd_devinfo_free(devinfop); 401 usbd_devinfo_free(devinfop);
349 402
350 sc->sc_udev = uiaa->uiaa_device; 403 sc->sc_udev = uiaa->uiaa_device;
@@ -372,49 +425,53 @@ umass_attach(device_t parent, device_t s @@ -372,49 +425,53 @@ umass_attach(device_t parent, device_t s
372 case UIPROTO_MASS_CBI: 425 case UIPROTO_MASS_CBI:
373 sc->sc_wire = UMASS_WPROTO_CBI; 426 sc->sc_wire = UMASS_WPROTO_CBI;
374 break; 427 break;
375 case UIPROTO_MASS_CBI_I: 428 case UIPROTO_MASS_CBI_I:
376 sc->sc_wire = UMASS_WPROTO_CBI_I; 429 sc->sc_wire = UMASS_WPROTO_CBI_I;
377 break; 430 break;
378 case UIPROTO_MASS_BBB: 431 case UIPROTO_MASS_BBB:
379 case UIPROTO_MASS_BBB_OLD: 432 case UIPROTO_MASS_BBB_OLD:
380 sc->sc_wire = UMASS_WPROTO_BBB; 433 sc->sc_wire = UMASS_WPROTO_BBB;
381 break; 434 break;
382 default: 435 default:
383 DPRINTFM(UDMASS_GEN, "Unsupported wire protocol %ju", 436 DPRINTFM(UDMASS_GEN, "Unsupported wire protocol %ju",
384 uiaa->uiaa_proto, 0, 0, 0); 437 uiaa->uiaa_proto, 0, 0, 0);
 438 SDT_PROBE2(usb, umass, device, attach__done,
 439 sc, USBD_IOERROR);
385 return; 440 return;
386 } 441 }
387 } 442 }
388 443
389 if (sc->sc_cmd == UMASS_CPROTO_UNSPEC) { 444 if (sc->sc_cmd == UMASS_CPROTO_UNSPEC) {
390 switch (uiaa->uiaa_subclass) { 445 switch (uiaa->uiaa_subclass) {
391 case UISUBCLASS_SCSI: 446 case UISUBCLASS_SCSI:
392 sc->sc_cmd = UMASS_CPROTO_SCSI; 447 sc->sc_cmd = UMASS_CPROTO_SCSI;
393 break; 448 break;
394 case UISUBCLASS_UFI: 449 case UISUBCLASS_UFI:
395 sc->sc_cmd = UMASS_CPROTO_UFI; 450 sc->sc_cmd = UMASS_CPROTO_UFI;
396 break; 451 break;
397 case UISUBCLASS_SFF8020I: 452 case UISUBCLASS_SFF8020I:
398 case UISUBCLASS_SFF8070I: 453 case UISUBCLASS_SFF8070I:
399 case UISUBCLASS_QIC157: 454 case UISUBCLASS_QIC157:
400 sc->sc_cmd = UMASS_CPROTO_ATAPI; 455 sc->sc_cmd = UMASS_CPROTO_ATAPI;
401 break; 456 break;
402 case UISUBCLASS_RBC: 457 case UISUBCLASS_RBC:
403 sc->sc_cmd = UMASS_CPROTO_RBC; 458 sc->sc_cmd = UMASS_CPROTO_RBC;
404 break; 459 break;
405 default: 460 default:
406 DPRINTFM(UDMASS_GEN, "Unsupported command protocol %ju", 461 DPRINTFM(UDMASS_GEN, "Unsupported command protocol %ju",
407 uiaa->uiaa_subclass, 0, 0, 0); 462 uiaa->uiaa_subclass, 0, 0, 0);
 463 SDT_PROBE2(usb, umass, device, attach__done,
 464 sc, USBD_IOERROR);
408 return; 465 return;
409 } 466 }
410 } 467 }
411 468
412 switch (sc->sc_wire) { 469 switch (sc->sc_wire) {
413 case UMASS_WPROTO_CBI: 470 case UMASS_WPROTO_CBI:
414 sWire = "CBI"; 471 sWire = "CBI";
415 break; 472 break;
416 case UMASS_WPROTO_CBI_I: 473 case UMASS_WPROTO_CBI_I:
417 sWire = "CBI with CCI"; 474 sWire = "CBI with CCI";
418 break; 475 break;
419 case UMASS_WPROTO_BBB: 476 case UMASS_WPROTO_BBB:
420 sWire = "Bulk-Only"; 477 sWire = "Bulk-Only";
@@ -441,48 +498,51 @@ umass_attach(device_t parent, device_t s @@ -441,48 +498,51 @@ umass_attach(device_t parent, device_t s
441 sCommand = "ISD-ATA"; 498 sCommand = "ISD-ATA";
442 break; 499 break;
443 default: 500 default:
444 sCommand = "unknown"; 501 sCommand = "unknown";
445 break; 502 break;
446 } 503 }
447 504
448 aprint_verbose_dev(self, "using %s over %s\n", sCommand, sWire); 505 aprint_verbose_dev(self, "using %s over %s\n", sCommand, sWire);
449 506
450 if (quirk != NULL && quirk->uq_init != NULL) { 507 if (quirk != NULL && quirk->uq_init != NULL) {
451 err = (*quirk->uq_init)(sc); 508 err = (*quirk->uq_init)(sc);
452 if (err) { 509 if (err) {
453 aprint_error_dev(self, "quirk init failed\n"); 510 aprint_error_dev(self, "quirk init failed\n");
 511 SDT_PROBE2(usb, umass, device, attach__done, sc, err);
454 umass_disco(sc); 512 umass_disco(sc);
455 return; 513 return;
456 } 514 }
457 } 515 }
458 516
459 /* 517 /*
460 * In addition to the Control endpoint the following endpoints 518 * In addition to the Control endpoint the following endpoints
461 * are required: 519 * are required:
462 * a) bulk-in endpoint. 520 * a) bulk-in endpoint.
463 * b) bulk-out endpoint. 521 * b) bulk-out endpoint.
464 * and for Control/Bulk/Interrupt with CCI (CBI_I) 522 * and for Control/Bulk/Interrupt with CCI (CBI_I)
465 * c) intr-in 523 * c) intr-in
466 * 524 *
467 * The endpoint addresses are not fixed, so we have to read them 525 * The endpoint addresses are not fixed, so we have to read them
468 * from the device descriptors of the current interface. 526 * from the device descriptors of the current interface.
469 */ 527 */
470 id = usbd_get_interface_descriptor(sc->sc_iface); 528 id = usbd_get_interface_descriptor(sc->sc_iface);
471 for (i = 0 ; i < id->bNumEndpoints ; i++) { 529 for (i = 0 ; i < id->bNumEndpoints ; i++) {
472 ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i); 530 ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
473 if (ed == NULL) { 531 if (ed == NULL) {
474 aprint_error_dev(self, 532 aprint_error_dev(self,
475 "could not read endpoint descriptor\n"); 533 "could not read endpoint descriptor\n");
 534 SDT_PROBE2(usb, umass, device, attach__done,
 535 sc, USBD_IOERROR);
476 return; 536 return;
477 } 537 }
478 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN 538 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN
479 && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { 539 && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
480 sc->sc_epaddr[UMASS_BULKIN] = ed->bEndpointAddress; 540 sc->sc_epaddr[UMASS_BULKIN] = ed->bEndpointAddress;
481 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT 541 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT
482 && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { 542 && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
483 sc->sc_epaddr[UMASS_BULKOUT] = ed->bEndpointAddress; 543 sc->sc_epaddr[UMASS_BULKOUT] = ed->bEndpointAddress;
484 } else if (sc->sc_wire == UMASS_WPROTO_CBI_I 544 } else if (sc->sc_wire == UMASS_WPROTO_CBI_I
485 && UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN 545 && UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN
486 && (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) { 546 && (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
487 sc->sc_epaddr[UMASS_INTRIN] = ed->bEndpointAddress; 547 sc->sc_epaddr[UMASS_INTRIN] = ed->bEndpointAddress;
488#ifdef UMASS_DEBUG 548#ifdef UMASS_DEBUG
@@ -505,79 +565,83 @@ umass_attach(device_t parent, device_t s @@ -505,79 +565,83 @@ umass_attach(device_t parent, device_t s
505 sc->sc_epaddr[UMASS_INTRIN]); 565 sc->sc_epaddr[UMASS_INTRIN]);
506 return; 566 return;
507 } 567 }
508 568
509 /* 569 /*
510 * Get the maximum LUN supported by the device. 570 * Get the maximum LUN supported by the device.
511 */ 571 */
512 if (sc->sc_wire == UMASS_WPROTO_BBB && 572 if (sc->sc_wire == UMASS_WPROTO_BBB &&
513 (sc->sc_quirks & UMASS_QUIRK_NOGETMAXLUN) == 0) { 573 (sc->sc_quirks & UMASS_QUIRK_NOGETMAXLUN) == 0) {
514 err = umass_bbb_get_max_lun(sc, &sc->maxlun); 574 err = umass_bbb_get_max_lun(sc, &sc->maxlun);
515 if (err) { 575 if (err) {
516 aprint_error_dev(self, "unable to get Max Lun: %s\n", 576 aprint_error_dev(self, "unable to get Max Lun: %s\n",
517 usbd_errstr(err)); 577 usbd_errstr(err));
 578 SDT_PROBE2(usb, umass, device, attach__done, sc, err);
518 return; 579 return;
519 } 580 }
520 if (sc->maxlun > 0) 581 if (sc->maxlun > 0)
521 sc->sc_busquirks |= PQUIRK_FORCELUNS; 582 sc->sc_busquirks |= PQUIRK_FORCELUNS;
522 } else { 583 } else {
523 sc->maxlun = 0; 584 sc->maxlun = 0;
524 } 585 }
525 586
526 /* Open the bulk-in and -out pipe */ 587 /* Open the bulk-in and -out pipe */
527 DPRINTFM(UDMASS_USB, "sc %#jx: opening iface %#jx epaddr %jd for " 588 DPRINTFM(UDMASS_USB, "sc %#jx: opening iface %#jx epaddr %jd for "
528 "BULKOUT", (uintptr_t)sc, (uintptr_t)sc->sc_iface, 589 "BULKOUT", (uintptr_t)sc, (uintptr_t)sc->sc_iface,
529 sc->sc_epaddr[UMASS_BULKOUT], 0); 590 sc->sc_epaddr[UMASS_BULKOUT], 0);
530 err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_BULKOUT], 591 err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_BULKOUT],
531 USBD_EXCLUSIVE_USE | USBD_MPSAFE, &sc->sc_pipe[UMASS_BULKOUT]); 592 USBD_EXCLUSIVE_USE | USBD_MPSAFE, &sc->sc_pipe[UMASS_BULKOUT]);
532 if (err) { 593 if (err) {
533 aprint_error_dev(self, "cannot open %u-out pipe (bulk)\n", 594 aprint_error_dev(self, "cannot open %u-out pipe (bulk)\n",
534 sc->sc_epaddr[UMASS_BULKOUT]); 595 sc->sc_epaddr[UMASS_BULKOUT]);
 596 SDT_PROBE2(usb, umass, device, attach__done, sc, err);
535 umass_disco(sc); 597 umass_disco(sc);
536 return; 598 return;
537 } 599 }
538 DPRINTFM(UDMASS_USB, "sc %#jx: opening iface %#jx epaddr %jd for " 600 DPRINTFM(UDMASS_USB, "sc %#jx: opening iface %#jx epaddr %jd for "
539 "BULKIN", (uintptr_t)sc, (uintptr_t)sc->sc_iface, 601 "BULKIN", (uintptr_t)sc, (uintptr_t)sc->sc_iface,
540 sc->sc_epaddr[UMASS_BULKIN], 0); 602 sc->sc_epaddr[UMASS_BULKIN], 0);
541 err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_BULKIN], 603 err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_BULKIN],
542 USBD_EXCLUSIVE_USE | USBD_MPSAFE, &sc->sc_pipe[UMASS_BULKIN]); 604 USBD_EXCLUSIVE_USE | USBD_MPSAFE, &sc->sc_pipe[UMASS_BULKIN]);
543 if (err) { 605 if (err) {
544 aprint_error_dev(self, "could not open %u-in pipe (bulk)\n", 606 aprint_error_dev(self, "could not open %u-in pipe (bulk)\n",
545 sc->sc_epaddr[UMASS_BULKIN]); 607 sc->sc_epaddr[UMASS_BULKIN]);
 608 SDT_PROBE2(usb, umass, device, attach__done, sc, err);
546 umass_disco(sc); 609 umass_disco(sc);
547 return; 610 return;
548 } 611 }
549 /* 612 /*
550 * Open the intr-in pipe if the protocol is CBI with CCI. 613 * Open the intr-in pipe if the protocol is CBI with CCI.
551 * Note: early versions of the Zip drive do have an interrupt pipe, but 614 * Note: early versions of the Zip drive do have an interrupt pipe, but
552 * this pipe is unused 615 * this pipe is unused
553 * 616 *
554 * We do not open the interrupt pipe as an interrupt pipe, but as a 617 * We do not open the interrupt pipe as an interrupt pipe, but as a
555 * normal bulk endpoint. We send an IN transfer down the wire at the 618 * normal bulk endpoint. We send an IN transfer down the wire at the
556 * appropriate time, because we know exactly when to expect data on 619 * appropriate time, because we know exactly when to expect data on
557 * that endpoint. This saves bandwidth, but more important, makes the 620 * that endpoint. This saves bandwidth, but more important, makes the
558 * code for handling the data on that endpoint simpler. No data 621 * code for handling the data on that endpoint simpler. No data
559 * arriving concurrently. 622 * arriving concurrently.
560 */ 623 */
561 if (sc->sc_wire == UMASS_WPROTO_CBI_I) { 624 if (sc->sc_wire == UMASS_WPROTO_CBI_I) {
562 DPRINTFM(UDMASS_USB, 625 DPRINTFM(UDMASS_USB,
563 "sc %#jx: opening iface %#jx epaddr %jd for INTRIN", 626 "sc %#jx: opening iface %#jx epaddr %jd for INTRIN",
564 (uintptr_t)sc, (uintptr_t)sc->sc_iface, 627 (uintptr_t)sc, (uintptr_t)sc->sc_iface,
565 sc->sc_epaddr[UMASS_INTRIN], 0); 628 sc->sc_epaddr[UMASS_INTRIN], 0);
566 err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_INTRIN], 629 err = usbd_open_pipe(sc->sc_iface, sc->sc_epaddr[UMASS_INTRIN],
567 USBD_EXCLUSIVE_USE | USBD_MPSAFE, &sc->sc_pipe[UMASS_INTRIN]); 630 USBD_EXCLUSIVE_USE | USBD_MPSAFE, &sc->sc_pipe[UMASS_INTRIN]);
568 if (err) { 631 if (err) {
569 aprint_error_dev(self, "couldn't open %u-in (intr)\n", 632 aprint_error_dev(self, "couldn't open %u-in (intr)\n",
570 sc->sc_epaddr[UMASS_INTRIN]); 633 sc->sc_epaddr[UMASS_INTRIN]);
 634 SDT_PROBE2(usb, umass, device, attach__done, sc, err);
571 umass_disco(sc); 635 umass_disco(sc);
572 return; 636 return;
573 } 637 }
574 } 638 }
575 639
576 /* initialisation of generic part */ 640 /* initialisation of generic part */
577 sc->transfer_state = TSTATE_IDLE; 641 sc->transfer_state = TSTATE_IDLE;
578 642
579 for (i = 0; i < XFER_NR; i++) { 643 for (i = 0; i < XFER_NR; i++) {
580 sc->transfer_xfer[i] = NULL; 644 sc->transfer_xfer[i] = NULL;
581 } 645 }
582 646
583 /* 647 /*
@@ -667,26 +731,27 @@ umass_attach(device_t parent, device_t s @@ -667,26 +731,27 @@ umass_attach(device_t parent, device_t s
667 goto fail_create; 731 goto fail_create;
668 err = usbd_create_xfer(pipe0, sizeof(sc->cbl), 0, 0, 732 err = usbd_create_xfer(pipe0, sizeof(sc->cbl), 0, 0,
669 &sc->transfer_xfer[XFER_CBI_RESET2]); 733 &sc->transfer_xfer[XFER_CBI_RESET2]);
670 if (err) 734 if (err)
671 goto fail_create; 735 goto fail_create;
672 err = usbd_create_xfer(pipe0, sizeof(sc->cbl), 0, 0, 736 err = usbd_create_xfer(pipe0, sizeof(sc->cbl), 0, 0,
673 &sc->transfer_xfer[XFER_CBI_RESET3]); 737 &sc->transfer_xfer[XFER_CBI_RESET3]);
674 if (err) 738 if (err)
675 goto fail_create; 739 goto fail_create;
676 break; 740 break;
677 default: 741 default:
678 fail_create: 742 fail_create:
679 aprint_error_dev(self, "failed to create xfers\n"); 743 aprint_error_dev(self, "failed to create xfers\n");
 744 SDT_PROBE2(usb, umass, device, attach__done, sc, err);
680 umass_disco(sc); 745 umass_disco(sc);
681 return; 746 return;
682 } 747 }
683 748
684 /* 749 /*
685 * Record buffer pointers for data transfer (it's huge), command and 750 * Record buffer pointers for data transfer (it's huge), command and
686 * status data here 751 * status data here
687 */ 752 */
688 switch (sc->sc_wire) { 753 switch (sc->sc_wire) {
689 case UMASS_WPROTO_BBB: 754 case UMASS_WPROTO_BBB:
690 sc->datain_buffer = 755 sc->datain_buffer =
691 usbd_get_buffer(sc->transfer_xfer[XFER_BBB_DATAIN]); 756 usbd_get_buffer(sc->transfer_xfer[XFER_BBB_DATAIN]);
692 sc->dataout_buffer = 757 sc->dataout_buffer =
@@ -755,60 +820,64 @@ umass_attach(device_t parent, device_t s @@ -755,60 +820,64 @@ umass_attach(device_t parent, device_t s
755#else 820#else
756 aprint_error_dev(self, "isdata not configured\n"); 821 aprint_error_dev(self, "isdata not configured\n");
757#endif 822#endif
758 break; 823 break;
759 824
760 default: 825 default:
761 aprint_error_dev(self, "command protocol=0x%x not supported\n", 826 aprint_error_dev(self, "command protocol=0x%x not supported\n",
762 sc->sc_cmd); 827 sc->sc_cmd);
763 umass_disco(sc); 828 umass_disco(sc);
764 return; 829 return;
765 } 830 }
766 if (error) { 831 if (error) {
767 aprint_error_dev(self, "bus attach failed\n"); 832 aprint_error_dev(self, "bus attach failed\n");
 833 SDT_PROBE2(usb, umass, device, attach__done,
 834 sc, USBD_IOERROR);
768 umass_disco(sc); 835 umass_disco(sc);
769 return; 836 return;
770 } 837 }
771 838
772 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev); 839 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
773 840
774 if (!pmf_device_register(self, NULL, NULL)) 841 if (!pmf_device_register(self, NULL, NULL))
775 aprint_error_dev(self, "couldn't establish power handler\n"); 842 aprint_error_dev(self, "couldn't establish power handler\n");
776 843
777 DPRINTFM(UDMASS_GEN, "sc %#jx: Attach finished", (uintptr_t)sc, 844 DPRINTFM(UDMASS_GEN, "sc %#jx: Attach finished", (uintptr_t)sc,
778 0, 0, 0); 845 0, 0, 0);
779 846
 847 SDT_PROBE2(usb, umass, device, attach__done, sc, 0);
780 return; 848 return;
781} 849}
782 850
783static void 851static void
784umass_childdet(device_t self, device_t child) 852umass_childdet(device_t self, device_t child)
785{ 853{
786 struct umass_softc *sc = device_private(self); 854 struct umass_softc *sc = device_private(self);
787 855
788 KASSERTMSG(child == sc->bus->sc_child, 856 KASSERTMSG(child == sc->bus->sc_child,
789 "assertion child == sc->bus->sc_child failed\n"); 857 "assertion child == sc->bus->sc_child failed\n");
790 sc->bus->sc_child = NULL; 858 sc->bus->sc_child = NULL;
791} 859}
792 860
793static int 861static int
794umass_detach(device_t self, int flags) 862umass_detach(device_t self, int flags)
795{ 863{
796 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 864 UMASSHIST_FUNC(); UMASSHIST_CALLED();
797 struct umass_softc *sc = device_private(self); 865 struct umass_softc *sc = device_private(self);
798 struct umassbus_softc *scbus; 866 struct umassbus_softc *scbus;
799 int rv = 0, i; 867 int rv = 0, i;
800 868
801 DPRINTFM(UDMASS_USB, "sc %#jx detached", (uintptr_t)sc, 0, 0, 0); 869 DPRINTFM(UDMASS_USB, "sc %#jx detached", (uintptr_t)sc, 0, 0, 0);
 870 SDT_PROBE1(usb, umass, device, detach__start, sc);
802 871
803 mutex_enter(&sc->sc_lock); 872 mutex_enter(&sc->sc_lock);
804 sc->sc_dying = true; 873 sc->sc_dying = true;
805 mutex_exit(&sc->sc_lock); 874 mutex_exit(&sc->sc_lock);
806 875
807 pmf_device_deregister(self); 876 pmf_device_deregister(self);
808 877
809 /* Abort the pipes to wake up any waiting processes. */ 878 /* Abort the pipes to wake up any waiting processes. */
810 for (i = 0 ; i < UMASS_NEP ; i++) { 879 for (i = 0 ; i < UMASS_NEP ; i++) {
811 if (sc->sc_pipe[i] != NULL) 880 if (sc->sc_pipe[i] != NULL)
812 usbd_abort_pipe(sc->sc_pipe[i]); 881 usbd_abort_pipe(sc->sc_pipe[i]);
813 } 882 }
814 usbd_abort_default_pipe(sc->sc_udev); 883 usbd_abort_default_pipe(sc->sc_udev);
@@ -856,36 +925,37 @@ umass_detach(device_t self, int flags) @@ -856,36 +925,37 @@ umass_detach(device_t self, int flags)
856 aprint_error_dev(self, "isdata not configured\n"); 925 aprint_error_dev(self, "isdata not configured\n");
857#endif 926#endif
858 break; 927 break;
859 928
860 default: 929 default:
861 /* nothing to do */ 930 /* nothing to do */
862 break; 931 break;
863 } 932 }
864 933
865 /* protocol detach is expected to free sc->bus */ 934 /* protocol detach is expected to free sc->bus */
866 KASSERT(sc->bus == NULL); 935 KASSERT(sc->bus == NULL);
867 } 936 }
868 937
869 if (rv != 0) 938 if (rv)
870 return rv; 939 goto out;
871 940
872 umass_disco(sc); 941 umass_disco(sc);
873 942
874 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev); 943 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
875 944
876 mutex_destroy(&sc->sc_lock); 945 mutex_destroy(&sc->sc_lock);
877 cv_destroy(&sc->sc_detach_cv); 946 cv_destroy(&sc->sc_detach_cv);
878 947
 948out: SDT_PROBE2(usb, umass, device, detach__done, sc, rv);
879 return rv; 949 return rv;
880} 950}
881 951
882static int 952static int
883umass_activate(device_t dev, enum devact act) 953umass_activate(device_t dev, enum devact act)
884{ 954{
885 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 955 UMASSHIST_FUNC(); UMASSHIST_CALLED();
886 struct umass_softc *sc = device_private(dev); 956 struct umass_softc *sc = device_private(dev);
887 957
888 DPRINTFM(UDMASS_USB, "sc %#jx act %jd", (uintptr_t)sc, act, 0, 0); 958 DPRINTFM(UDMASS_USB, "sc %#jx act %jd", (uintptr_t)sc, act, 0, 0);
889 959
890 switch (act) { 960 switch (act) {
891 case DVACT_DEACTIVATE: 961 case DVACT_DEACTIVATE:
@@ -1012,60 +1082,78 @@ umass_clear_endpoint_stall(struct umass_ @@ -1012,60 +1082,78 @@ umass_clear_endpoint_stall(struct umass_
1012 USETW(sc->sc_req.wIndex, sc->sc_epaddr[endpt]); 1082 USETW(sc->sc_req.wIndex, sc->sc_epaddr[endpt]);
1013 USETW(sc->sc_req.wLength, 0); 1083 USETW(sc->sc_req.wLength, 0);
1014 if (umass_setup_ctrl_transfer(sc, &sc->sc_req, NULL, 0, 0, xfer)) 1084 if (umass_setup_ctrl_transfer(sc, &sc->sc_req, NULL, 0, 0, xfer))
1015 umass_transfer_done(sc, sc->transfer_datalen, 1085 umass_transfer_done(sc, sc->transfer_datalen,
1016 STATUS_WIRE_FAILED); 1086 STATUS_WIRE_FAILED);
1017} 1087}
1018 1088
1019Static void 1089Static void
1020umass_transfer_done(struct umass_softc *sc, int residue, int status) 1090umass_transfer_done(struct umass_softc *sc, int residue, int status)
1021{ 1091{
1022 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 1092 UMASSHIST_FUNC(); UMASSHIST_CALLED();
1023 1093
1024 sc->transfer_state = TSTATE_IDLE; 1094 sc->transfer_state = TSTATE_IDLE;
 1095 SDT_PROBE7(usb, umass, transfer, done,
 1096 sc,
 1097 sc->transfer_cb,
 1098 sc->transfer_priv,
 1099 sc->transfer_data,
 1100 sc->transfer_datalen,
 1101 residue,
 1102 status);
1025 sc->transfer_cb(sc, sc->transfer_priv, residue, status); 1103 sc->transfer_cb(sc, sc->transfer_priv, residue, status);
1026} 1104}
1027 1105
1028Static void 1106Static void
1029umass_transfer_reset(struct umass_softc *sc) 1107umass_transfer_reset(struct umass_softc *sc)
1030{ 1108{
1031 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 1109 UMASSHIST_FUNC(); UMASSHIST_CALLED();
1032 1110
1033 sc->transfer_state = TSTATE_IDLE; 1111 sc->transfer_state = TSTATE_IDLE;
1034 if (sc->transfer_priv) 1112 if (sc->transfer_priv) {
 1113 SDT_PROBE7(usb, umass, transfer, done,
 1114 sc,
 1115 sc->transfer_cb,
 1116 sc->transfer_priv,
 1117 sc->transfer_data,
 1118 sc->transfer_datalen,
 1119 sc->transfer_datalen,
 1120 sc->transfer_status);
1035 sc->transfer_cb(sc, sc->transfer_priv, sc->transfer_datalen, 1121 sc->transfer_cb(sc, sc->transfer_priv, sc->transfer_datalen,
1036 sc->transfer_status); 1122 sc->transfer_status);
 1123 }
1037} 1124}
1038 1125
1039#if 0 1126#if 0
1040Static void 1127Static void
1041umass_reset(struct umass_softc *sc, transfer_cb_f cb, void *priv) 1128umass_reset(struct umass_softc *sc, transfer_cb_f cb, void *priv)
1042{ 1129{
1043 sc->transfer_cb = cb; 1130 sc->transfer_cb = cb;
1044 sc->transfer_priv = priv; 1131 sc->transfer_priv = priv;
1045 1132
1046 /* The reset is a forced reset, so no error (yet) */ 1133 /* The reset is a forced reset, so no error (yet) */
1047 sc->reset(sc, STATUS_CMD_OK); 1134 sc->reset(sc, STATUS_CMD_OK);
1048} 1135}
1049#endif 1136#endif
1050 1137
1051/* 1138/*
1052 * Bulk protocol specific functions 1139 * Bulk protocol specific functions
1053 */ 1140 */
1054 1141
1055Static void 1142Static void
1056umass_bbb_reset(struct umass_softc *sc, int status) 1143umass_bbb_reset(struct umass_softc *sc, int status)
1057{ 1144{
1058 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 1145 UMASSHIST_FUNC(); UMASSHIST_CALLED();
 1146 SDT_PROBE2(usb, umass, bbb, reset, sc, status);
1059 KASSERTMSG(sc->sc_wire & UMASS_WPROTO_BBB, 1147 KASSERTMSG(sc->sc_wire & UMASS_WPROTO_BBB,
1060 "sc->sc_wire == 0x%02x wrong for umass_bbb_reset\n", 1148 "sc->sc_wire == 0x%02x wrong for umass_bbb_reset\n",
1061 sc->sc_wire); 1149 sc->sc_wire);
1062 1150
1063 if (sc->sc_dying) { 1151 if (sc->sc_dying) {
1064 umass_transfer_done(sc, sc->transfer_datalen, status); 1152 umass_transfer_done(sc, sc->transfer_datalen, status);
1065 return; 1153 return;
1066 } 1154 }
1067 1155
1068 /* 1156 /*
1069 * Reset recovery (5.3.4 in Universal Serial Bus Mass Storage Class) 1157 * Reset recovery (5.3.4 in Universal Serial Bus Mass Storage Class)
1070 * 1158 *
1071 * For Reset Recovery the host shall issue in the following order: 1159 * For Reset Recovery the host shall issue in the following order:
@@ -1093,36 +1181,40 @@ umass_bbb_reset(struct umass_softc *sc,  @@ -1093,36 +1181,40 @@ umass_bbb_reset(struct umass_softc *sc,
1093 USETW(sc->sc_req.wIndex, sc->sc_ifaceno); 1181 USETW(sc->sc_req.wIndex, sc->sc_ifaceno);
1094 USETW(sc->sc_req.wLength, 0); 1182 USETW(sc->sc_req.wLength, 0);
1095 if (umass_setup_ctrl_transfer(sc, &sc->sc_req, NULL, 0, 0, 1183 if (umass_setup_ctrl_transfer(sc, &sc->sc_req, NULL, 0, 0,
1096 sc->transfer_xfer[XFER_BBB_RESET1])) 1184 sc->transfer_xfer[XFER_BBB_RESET1]))
1097 umass_transfer_done(sc, sc->transfer_datalen, status); 1185 umass_transfer_done(sc, sc->transfer_datalen, status);
1098} 1186}
1099 1187
1100Static void 1188Static void
1101umass_bbb_transfer(struct umass_softc *sc, int lun, void *cmd, int cmdlen, 1189umass_bbb_transfer(struct umass_softc *sc, int lun, void *cmd, int cmdlen,
1102 void *data, int datalen, int dir, u_int timeout, 1190 void *data, int datalen, int dir, u_int timeout,
1103 int flags, umass_callback cb, void *priv) 1191 int flags, umass_callback cb, void *priv)
1104{ 1192{
1105 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 1193 UMASSHIST_FUNC(); UMASSHIST_CALLED();
 1194 SDT_PROBE7(usb, umass, transfer, start__bbb,
 1195 sc, cb, priv, data, datalen, dir, timeout);
1106 static int dCBWtag = 42; /* unique for CBW of transfer */ 1196 static int dCBWtag = 42; /* unique for CBW of transfer */
1107 1197
1108 DPRINTFM(UDMASS_BBB, "sc %#jx cmd=0x%02jx", (uintptr_t)sc, 1198 DPRINTFM(UDMASS_BBB, "sc %#jx cmd=0x%02jx", (uintptr_t)sc,
1109 *(u_char *)cmd, 0, 0); 1199 *(u_char *)cmd, 0, 0);
1110 1200
1111 KASSERTMSG(sc->sc_wire & UMASS_WPROTO_BBB, 1201 KASSERTMSG(sc->sc_wire & UMASS_WPROTO_BBB,
1112 "sc->sc_wire == 0x%02x wrong for umass_bbb_transfer\n", 1202 "sc->sc_wire == 0x%02x wrong for umass_bbb_transfer\n",
1113 sc->sc_wire); 1203 sc->sc_wire);
1114 1204
1115 if (sc->sc_dying) { 1205 if (sc->sc_dying) {
 1206 SDT_PROBE7(usb, umass, transfer, done,
 1207 sc, cb, priv, data, datalen, datalen, STATUS_WIRE_FAILED);
1116 cb(sc, priv, datalen, STATUS_WIRE_FAILED); 1208 cb(sc, priv, datalen, STATUS_WIRE_FAILED);
1117 return; 1209 return;
1118 } 1210 }
1119 1211
1120 /* Be a little generous. */ 1212 /* Be a little generous. */
1121 sc->timeout = timeout + USBD_DEFAULT_TIMEOUT; 1213 sc->timeout = timeout + USBD_DEFAULT_TIMEOUT;
1122 1214
1123 /* 1215 /*
1124 * Do a Bulk-Only transfer with cmdlen bytes from cmd, possibly 1216 * Do a Bulk-Only transfer with cmdlen bytes from cmd, possibly
1125 * a data phase of datalen bytes from/to the device and finally a 1217 * a data phase of datalen bytes from/to the device and finally a
1126 * csw read phase. 1218 * csw read phase.
1127 * If the data direction was inbound a maximum of datalen bytes 1219 * If the data direction was inbound a maximum of datalen bytes
1128 * is stored in the buffer pointed to by data. 1220 * is stored in the buffer pointed to by data.
@@ -1216,26 +1308,28 @@ umass_bbb_transfer(struct umass_softc *s @@ -1216,26 +1308,28 @@ umass_bbb_transfer(struct umass_softc *s
1216 } 1308 }
1217} 1309}
1218 1310
1219 1311
1220Static void 1312Static void
1221umass_bbb_state(struct usbd_xfer *xfer, void *priv, 1313umass_bbb_state(struct usbd_xfer *xfer, void *priv,
1222 usbd_status err) 1314 usbd_status err)
1223{ 1315{
1224 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 1316 UMASSHIST_FUNC(); UMASSHIST_CALLED();
1225 struct umass_softc *sc = (struct umass_softc *) priv; 1317 struct umass_softc *sc = (struct umass_softc *) priv;
1226 struct usbd_xfer *next_xfer; 1318 struct usbd_xfer *next_xfer;
1227 int residue; 1319 int residue;
1228 1320
 1321 SDT_PROBE3(usb, umass, bbb, state, sc, xfer, err);
 1322
1229 KASSERTMSG(sc->sc_wire & UMASS_WPROTO_BBB, 1323 KASSERTMSG(sc->sc_wire & UMASS_WPROTO_BBB,
1230 "sc->sc_wire == 0x%02x wrong for umass_bbb_state\n", 1324 "sc->sc_wire == 0x%02x wrong for umass_bbb_state\n",
1231 sc->sc_wire); 1325 sc->sc_wire);
1232 1326
1233 /* 1327 /*
1234 * State handling for BBB transfers. 1328 * State handling for BBB transfers.
1235 * 1329 *
1236 * The subroutine is rather long. It steps through the states given in 1330 * The subroutine is rather long. It steps through the states given in
1237 * Annex A of the Bulk-Only specification. 1331 * Annex A of the Bulk-Only specification.
1238 * Each state first does the error handling of the previous transfer 1332 * Each state first does the error handling of the previous transfer
1239 * and then prepares the next transfer. 1333 * and then prepares the next transfer.
1240 * Each transfer is done asynchroneously so after the request/transfer 1334 * Each transfer is done asynchroneously so after the request/transfer
1241 * has been submitted you will find a 'return;'. 1335 * has been submitted you will find a 'return;'.
@@ -1557,26 +1651,27 @@ umass_cbi_adsc(struct umass_softc *sc, c @@ -1557,26 +1651,27 @@ umass_cbi_adsc(struct umass_softc *sc, c
1557 sc->sc_req.bRequest = UR_CBI_ADSC; 1651 sc->sc_req.bRequest = UR_CBI_ADSC;
1558 USETW(sc->sc_req.wValue, 0); 1652 USETW(sc->sc_req.wValue, 0);
1559 USETW(sc->sc_req.wIndex, sc->sc_ifaceno); 1653 USETW(sc->sc_req.wIndex, sc->sc_ifaceno);
1560 USETW(sc->sc_req.wLength, buflen); 1654 USETW(sc->sc_req.wLength, buflen);
1561 return umass_setup_ctrl_transfer(sc, &sc->sc_req, buffer, 1655 return umass_setup_ctrl_transfer(sc, &sc->sc_req, buffer,
1562 buflen, flags, xfer); 1656 buflen, flags, xfer);
1563} 1657}
1564 1658
1565 1659
1566Static void 1660Static void
1567umass_cbi_reset(struct umass_softc *sc, int status) 1661umass_cbi_reset(struct umass_softc *sc, int status)
1568{ 1662{
1569 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 1663 UMASSHIST_FUNC(); UMASSHIST_CALLED();
 1664 SDT_PROBE2(usb, umass, bbb, reset, sc, status);
1570 int i; 1665 int i;
1571# define SEND_DIAGNOSTIC_CMDLEN 12 1666# define SEND_DIAGNOSTIC_CMDLEN 12
1572 1667
1573 KASSERTMSG(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I), 1668 KASSERTMSG(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I),
1574 "sc->sc_wire == 0x%02x wrong for umass_cbi_reset\n", 1669 "sc->sc_wire == 0x%02x wrong for umass_cbi_reset\n",
1575 sc->sc_wire); 1670 sc->sc_wire);
1576 1671
1577 if (sc->sc_dying) { 1672 if (sc->sc_dying) {
1578 umass_transfer_done(sc, sc->transfer_datalen, status); 1673 umass_transfer_done(sc, sc->transfer_datalen, status);
1579 return; 1674 return;
1580 } 1675 }
1581 1676
1582 /* 1677 /*
@@ -1615,35 +1710,39 @@ umass_cbi_reset(struct umass_softc *sc,  @@ -1615,35 +1710,39 @@ umass_cbi_reset(struct umass_softc *sc,
1615 1710
1616 if (umass_cbi_adsc(sc, sc->cbl, SEND_DIAGNOSTIC_CMDLEN, 0, 1711 if (umass_cbi_adsc(sc, sc->cbl, SEND_DIAGNOSTIC_CMDLEN, 0,
1617 sc->transfer_xfer[XFER_CBI_RESET1])) 1712 sc->transfer_xfer[XFER_CBI_RESET1]))
1618 umass_transfer_done(sc, sc->transfer_datalen, status); 1713 umass_transfer_done(sc, sc->transfer_datalen, status);
1619 /* XXX if the command fails we should reset the port on the bub */ 1714 /* XXX if the command fails we should reset the port on the bub */
1620} 1715}
1621 1716
1622Static void 1717Static void
1623umass_cbi_transfer(struct umass_softc *sc, int lun, 1718umass_cbi_transfer(struct umass_softc *sc, int lun,
1624 void *cmd, int cmdlen, void *data, int datalen, int dir, 1719 void *cmd, int cmdlen, void *data, int datalen, int dir,
1625 u_int timeout, int flags, umass_callback cb, void *priv) 1720 u_int timeout, int flags, umass_callback cb, void *priv)
1626{ 1721{
1627 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 1722 UMASSHIST_FUNC(); UMASSHIST_CALLED();
 1723 SDT_PROBE7(usb, umass, transfer, start__cbi,
 1724 sc, cb, priv, data, datalen, dir, timeout);
1628 1725
1629 DPRINTFM(UDMASS_CBI, "sc %#jx: cmd=0x%02jx, len=%jd", 1726 DPRINTFM(UDMASS_CBI, "sc %#jx: cmd=0x%02jx, len=%jd",
1630 (uintptr_t)sc, *(u_char *)cmd, datalen, 0); 1727 (uintptr_t)sc, *(u_char *)cmd, datalen, 0);
1631 1728
1632 KASSERTMSG(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I), 1729 KASSERTMSG(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I),
1633 "sc->sc_wire == 0x%02x wrong for umass_cbi_transfer\n", 1730 "sc->sc_wire == 0x%02x wrong for umass_cbi_transfer\n",
1634 sc->sc_wire); 1731 sc->sc_wire);
1635 1732
1636 if (sc->sc_dying) { 1733 if (sc->sc_dying) {
 1734 SDT_PROBE7(usb, umass, transfer, done,
 1735 sc, cb, priv, data, datalen, datalen, STATUS_WIRE_FAILED);
1637 cb(sc, priv, datalen, STATUS_WIRE_FAILED); 1736 cb(sc, priv, datalen, STATUS_WIRE_FAILED);
1638 return; 1737 return;
1639 } 1738 }
1640 1739
1641 /* Be a little generous. */ 1740 /* Be a little generous. */
1642 sc->timeout = timeout + USBD_DEFAULT_TIMEOUT; 1741 sc->timeout = timeout + USBD_DEFAULT_TIMEOUT;
1643 1742
1644 /* 1743 /*
1645 * Do a CBI transfer with cmdlen bytes from cmd, possibly 1744 * Do a CBI transfer with cmdlen bytes from cmd, possibly
1646 * a data phase of datalen bytes from/to the device and finally a 1745 * a data phase of datalen bytes from/to the device and finally a
1647 * csw read phase. 1746 * csw read phase.
1648 * If the data direction was inbound a maximum of datalen bytes 1747 * If the data direction was inbound a maximum of datalen bytes
1649 * is stored in the buffer pointed to by data. 1748 * is stored in the buffer pointed to by data.
@@ -1680,26 +1779,28 @@ umass_cbi_transfer(struct umass_softc *s @@ -1680,26 +1779,28 @@ umass_cbi_transfer(struct umass_softc *s
1680 /* Send the Command Block from host to device via control endpoint. */ 1779 /* Send the Command Block from host to device via control endpoint. */
1681 if (umass_cbi_adsc(sc, cmd, cmdlen, flags, 1780 if (umass_cbi_adsc(sc, cmd, cmdlen, flags,
1682 sc->transfer_xfer[XFER_CBI_CB])) 1781 sc->transfer_xfer[XFER_CBI_CB]))
1683 umass_cbi_reset(sc, STATUS_WIRE_FAILED); 1782 umass_cbi_reset(sc, STATUS_WIRE_FAILED);
1684} 1783}
1685 1784
1686Static void 1785Static void
1687umass_cbi_state(struct usbd_xfer *xfer, void *priv, 1786umass_cbi_state(struct usbd_xfer *xfer, void *priv,
1688 usbd_status err) 1787 usbd_status err)
1689{ 1788{
1690 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 1789 UMASSHIST_FUNC(); UMASSHIST_CALLED();
1691 struct umass_softc *sc = (struct umass_softc *) priv; 1790 struct umass_softc *sc = (struct umass_softc *) priv;
1692 1791
 1792 SDT_PROBE3(usb, umass, bbb, state, sc, xfer, err);
 1793
1693 KASSERTMSG(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I), 1794 KASSERTMSG(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I),
1694 "sc->sc_wire == 0x%02x wrong for umass_cbi_state\n", 1795 "sc->sc_wire == 0x%02x wrong for umass_cbi_state\n",
1695 sc->sc_wire); 1796 sc->sc_wire);
1696 1797
1697 if (err == USBD_CANCELLED) { 1798 if (err == USBD_CANCELLED) {
1698 DPRINTFM(UDMASS_BBB, "sc %#jx xfer %#jx cancelled", 1799 DPRINTFM(UDMASS_BBB, "sc %#jx xfer %#jx cancelled",
1699 (uintptr_t)sc, (uintptr_t)xfer, 0, 0); 1800 (uintptr_t)sc, (uintptr_t)xfer, 0, 0);
1700 umass_transfer_done(sc, 0, STATUS_TIMEOUT); 1801 umass_transfer_done(sc, 0, STATUS_TIMEOUT);
1701 return; 1802 return;
1702 } 1803 }
1703 1804
1704 if (sc->sc_dying) { 1805 if (sc->sc_dying) {
1705 umass_transfer_done(sc, sc->transfer_datalen, 1806 umass_transfer_done(sc, sc->transfer_datalen,