Thu Mar 3 06:13:23 2022 UTC ()
usbdi(9): dtrace probes for USB control requests.


(riastradh)
diff -r1.232 -r1.233 src/sys/dev/usb/usbdi.c

cvs diff -r1.232 -r1.233 src/sys/dev/usb/usbdi.c (expand / switch to unified diff)

--- src/sys/dev/usb/usbdi.c 2022/03/03 06:12:49 1.232
+++ src/sys/dev/usb/usbdi.c 2022/03/03 06:13:23 1.233
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbdi.c,v 1.232 2022/03/03 06:12:49 riastradh Exp $ */ 1/* $NetBSD: usbdi.c,v 1.233 2022/03/03 06:13:23 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2012, 2015 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 Lennart Augustsson (lennart@augustsson.net) at 8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology, Matthew R. Green (mrg@eterna.com.au), 9 * Carlstedt Research & Technology, Matthew R. Green (mrg@eterna.com.au),
10 * and Nick Hudson. 10 * and Nick Hudson.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE. 31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.232 2022/03/03 06:12:49 riastradh Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.233 2022/03/03 06:13:23 riastradh Exp $");
36 36
37#ifdef _KERNEL_OPT 37#ifdef _KERNEL_OPT
38#include "opt_usb.h" 38#include "opt_usb.h"
39#include "opt_compat_netbsd.h" 39#include "opt_compat_netbsd.h"
40#include "usb_dma.h" 40#include "usb_dma.h"
41#endif 41#endif
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/device.h> 46#include <sys/device.h>
47#include <sys/kmem.h> 47#include <sys/kmem.h>
48#include <sys/proc.h> 48#include <sys/proc.h>
@@ -103,26 +103,42 @@ SDT_PROBE_DEFINE5(usb, device, xfer, cre @@ -103,26 +103,42 @@ SDT_PROBE_DEFINE5(usb, device, xfer, cre
103 "struct usbd_pipe *"/*pipe*/, 103 "struct usbd_pipe *"/*pipe*/,
104 "size_t"/*len*/, 104 "size_t"/*len*/,
105 "unsigned int"/*flags*/, 105 "unsigned int"/*flags*/,
106 "unsigned int"/*nframes*/); 106 "unsigned int"/*nframes*/);
107SDT_PROBE_DEFINE1(usb, device, xfer, start, "struct usbd_xfer *"/*xfer*/); 107SDT_PROBE_DEFINE1(usb, device, xfer, start, "struct usbd_xfer *"/*xfer*/);
108SDT_PROBE_DEFINE1(usb, device, xfer, preabort, "struct usbd_xfer *"/*xfer*/); 108SDT_PROBE_DEFINE1(usb, device, xfer, preabort, "struct usbd_xfer *"/*xfer*/);
109SDT_PROBE_DEFINE1(usb, device, xfer, abort, "struct usbd_xfer *"/*xfer*/); 109SDT_PROBE_DEFINE1(usb, device, xfer, abort, "struct usbd_xfer *"/*xfer*/);
110SDT_PROBE_DEFINE1(usb, device, xfer, timeout, "struct usbd_xfer *"/*xfer*/); 110SDT_PROBE_DEFINE1(usb, device, xfer, timeout, "struct usbd_xfer *"/*xfer*/);
111SDT_PROBE_DEFINE2(usb, device, xfer, done, 111SDT_PROBE_DEFINE2(usb, device, xfer, done,
112 "struct usbd_xfer *"/*xfer*/, 112 "struct usbd_xfer *"/*xfer*/,
113 "usbd_status"/*status*/); 113 "usbd_status"/*status*/);
114SDT_PROBE_DEFINE1(usb, device, xfer, destroy, "struct usbd_xfer *"/*xfer*/); 114SDT_PROBE_DEFINE1(usb, device, xfer, destroy, "struct usbd_xfer *"/*xfer*/);
115 115
 116SDT_PROBE_DEFINE5(usb, device, request, start,
 117 "struct usbd_device *"/*dev*/,
 118 "usb_device_request_t *"/*req*/,
 119 "size_t"/*len*/,
 120 "int"/*flags*/,
 121 "uint32_t"/*timeout*/);
 122
 123SDT_PROBE_DEFINE7(usb, device, request, done,
 124 "struct usbd_device *"/*dev*/,
 125 "usb_device_request_t *"/*req*/,
 126 "size_t"/*actlen*/,
 127 "int"/*flags*/,
 128 "uint32_t"/*timeout*/,
 129 "void *"/*data*/,
 130 "usbd_status"/*status*/);
 131
116Static void usbd_ar_pipe(struct usbd_pipe *); 132Static void usbd_ar_pipe(struct usbd_pipe *);
117Static void usbd_start_next(struct usbd_pipe *); 133Static void usbd_start_next(struct usbd_pipe *);
118Static usbd_status usbd_open_pipe_ival 134Static usbd_status usbd_open_pipe_ival
119 (struct usbd_interface *, uint8_t, uint8_t, struct usbd_pipe **, int); 135 (struct usbd_interface *, uint8_t, uint8_t, struct usbd_pipe **, int);
120static void *usbd_alloc_buffer(struct usbd_xfer *, uint32_t); 136static void *usbd_alloc_buffer(struct usbd_xfer *, uint32_t);
121static void usbd_free_buffer(struct usbd_xfer *); 137static void usbd_free_buffer(struct usbd_xfer *);
122static struct usbd_xfer *usbd_alloc_xfer(struct usbd_device *, unsigned int); 138static struct usbd_xfer *usbd_alloc_xfer(struct usbd_device *, unsigned int);
123static void usbd_free_xfer(struct usbd_xfer *); 139static void usbd_free_xfer(struct usbd_xfer *);
124static void usbd_request_async_cb(struct usbd_xfer *, void *, usbd_status); 140static void usbd_request_async_cb(struct usbd_xfer *, void *, usbd_status);
125static void usbd_xfer_timeout(void *); 141static void usbd_xfer_timeout(void *);
126static void usbd_xfer_timeout_task(void *); 142static void usbd_xfer_timeout_task(void *);
127static bool usbd_xfer_probe_timeout(struct usbd_xfer *); 143static bool usbd_xfer_probe_timeout(struct usbd_xfer *);
128static void usbd_xfer_cancel_timeout_async(struct usbd_xfer *); 144static void usbd_xfer_cancel_timeout_async(struct usbd_xfer *);
@@ -1226,53 +1242,62 @@ usbd_do_request_len(struct usbd_device * @@ -1226,53 +1242,62 @@ usbd_do_request_len(struct usbd_device *
1226 size_t len, void *data, uint16_t flags, int *actlen, uint32_t timeout) 1242 size_t len, void *data, uint16_t flags, int *actlen, uint32_t timeout)
1227{ 1243{
1228 struct usbd_xfer *xfer; 1244 struct usbd_xfer *xfer;
1229 usbd_status err; 1245 usbd_status err;
1230 1246
1231 KASSERT(len >= UGETW(req->wLength)); 1247 KASSERT(len >= UGETW(req->wLength));
1232 1248
1233 USBHIST_FUNC(); 1249 USBHIST_FUNC();
1234 USBHIST_CALLARGS(usbdebug, "dev=%#jx req=%jx flags=%jx len=%jx", 1250 USBHIST_CALLARGS(usbdebug, "dev=%#jx req=%jx flags=%jx len=%jx",
1235 (uintptr_t)dev, (uintptr_t)req, flags, len); 1251 (uintptr_t)dev, (uintptr_t)req, flags, len);
1236 1252
1237 ASSERT_SLEEPABLE(); 1253 ASSERT_SLEEPABLE();
1238 1254
 1255 SDT_PROBE5(usb, device, request, start,
 1256 dev, req, len, flags, timeout);
 1257
1239 int error = usbd_create_xfer(dev->ud_pipe0, len, 0, 0, &xfer); 1258 int error = usbd_create_xfer(dev->ud_pipe0, len, 0, 0, &xfer);
1240 if (error) 1259 if (error) {
 1260 SDT_PROBE7(usb, device, request, done,
 1261 dev, req, /*actlen*/0, flags, timeout, data, USBD_NOMEM);
1241 return USBD_NOMEM; 1262 return USBD_NOMEM;
 1263 }
1242 1264
1243 usbd_setup_default_xfer(xfer, dev, 0, timeout, req, data, 1265 usbd_setup_default_xfer(xfer, dev, 0, timeout, req, data,
1244 UGETW(req->wLength), flags, NULL); 1266 UGETW(req->wLength), flags, NULL);
1245 KASSERT(xfer->ux_pipe == dev->ud_pipe0); 1267 KASSERT(xfer->ux_pipe == dev->ud_pipe0);
1246 err = usbd_sync_transfer(xfer); 1268 err = usbd_sync_transfer(xfer);
1247#if defined(USB_DEBUG) || defined(DIAGNOSTIC) 1269#if defined(USB_DEBUG) || defined(DIAGNOSTIC)
1248 if (xfer->ux_actlen > xfer->ux_length) { 1270 if (xfer->ux_actlen > xfer->ux_length) {
1249 USBHIST_LOG(usbdebug, "overrun addr = %jd type = 0x%02jx", 1271 USBHIST_LOG(usbdebug, "overrun addr = %jd type = 0x%02jx",
1250 dev->ud_addr, xfer->ux_request.bmRequestType, 0, 0); 1272 dev->ud_addr, xfer->ux_request.bmRequestType, 0, 0);
1251 USBHIST_LOG(usbdebug, " req = 0x%02jx val = %jd " 1273 USBHIST_LOG(usbdebug, " req = 0x%02jx val = %jd "
1252 "index = %jd", 1274 "index = %jd",
1253 xfer->ux_request.bRequest, UGETW(xfer->ux_request.wValue), 1275 xfer->ux_request.bRequest, UGETW(xfer->ux_request.wValue),
1254 UGETW(xfer->ux_request.wIndex), 0); 1276 UGETW(xfer->ux_request.wIndex), 0);
1255 USBHIST_LOG(usbdebug, " rlen = %jd length = %jd " 1277 USBHIST_LOG(usbdebug, " rlen = %jd length = %jd "
1256 "actlen = %jd", 1278 "actlen = %jd",
1257 UGETW(xfer->ux_request.wLength), 1279 UGETW(xfer->ux_request.wLength),
1258 xfer->ux_length, xfer->ux_actlen, 0); 1280 xfer->ux_length, xfer->ux_actlen, 0);
1259 } 1281 }
1260#endif 1282#endif
1261 if (actlen != NULL) 1283 if (actlen != NULL)
1262 *actlen = xfer->ux_actlen; 1284 *actlen = xfer->ux_actlen;
1263 1285
1264 usbd_destroy_xfer(xfer); 1286 usbd_destroy_xfer(xfer);
1265 1287
 1288 SDT_PROBE7(usb, device, request, done,
 1289 dev, req, xfer->ux_actlen, flags, timeout, data, err);
 1290
1266 if (err) { 1291 if (err) {
1267 USBHIST_LOG(usbdebug, "returning err = %jd", err, 0, 0, 0); 1292 USBHIST_LOG(usbdebug, "returning err = %jd", err, 0, 0, 0);
1268 } 1293 }
1269 return err; 1294 return err;
1270} 1295}
1271 1296
1272static void 1297static void
1273usbd_request_async_cb(struct usbd_xfer *xfer, void *priv, usbd_status status) 1298usbd_request_async_cb(struct usbd_xfer *xfer, void *priv, usbd_status status)
1274{ 1299{
1275 usbd_destroy_xfer(xfer); 1300 usbd_destroy_xfer(xfer);
1276} 1301}
1277 1302
1278/* 1303/*