| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: usbdi.c,v 1.162.2.11 2015/03/05 08:34:47 skrll Exp $ */ | | 1 | /* $NetBSD: usbdi.c,v 1.162.2.12 2015/03/05 08:48:07 skrll Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1998, 2012 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 and Matthew R. Green (mrg@eterna.com.au). | | 9 | * Carlstedt Research & Technology and Matthew R. Green (mrg@eterna.com.au). |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | * POSSIBILITY OF SUCH DAMAGE. | | 30 | * POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.162.2.11 2015/03/05 08:34:47 skrll Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.162.2.12 2015/03/05 08:48:07 skrll Exp $"); |
35 | | | 35 | |
36 | #ifdef _KERNEL_OPT | | 36 | #ifdef _KERNEL_OPT |
37 | #include "opt_usb.h" | | 37 | #include "opt_usb.h" |
38 | #include "opt_compat_netbsd.h" | | 38 | #include "opt_compat_netbsd.h" |
39 | #endif | | 39 | #endif |
40 | | | 40 | |
41 | #include "usb_dma.h" | | 41 | #include "usb_dma.h" |
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> |
| @@ -221,26 +221,27 @@ usbd_open_pipe_intr(usbd_interface_handl | | | @@ -221,26 +221,27 @@ usbd_open_pipe_intr(usbd_interface_handl |
221 | if (xfer == NULL) { | | 221 | if (xfer == NULL) { |
222 | err = USBD_NOMEM; | | 222 | err = USBD_NOMEM; |
223 | goto bad1; | | 223 | goto bad1; |
224 | } | | 224 | } |
225 | void *buf = usbd_alloc_buffer(xfer, len); | | 225 | void *buf = usbd_alloc_buffer(xfer, len); |
226 | if (buf == NULL) { | | 226 | if (buf == NULL) { |
227 | err = ENOMEM; | | 227 | err = ENOMEM; |
228 | goto bad2; | | 228 | goto bad2; |
229 | } | | 229 | } |
230 | | | 230 | |
231 | usbd_setup_xfer(xfer, ipipe, priv, buffer, len, flags, | | 231 | usbd_setup_xfer(xfer, ipipe, priv, buffer, len, flags, |
232 | USBD_NO_TIMEOUT, cb); | | 232 | USBD_NO_TIMEOUT, cb); |
233 | ipipe->up_intrxfer = xfer; | | 233 | ipipe->up_intrxfer = xfer; |
| | | 234 | ipipe->up_intrbuf = buf; |
234 | ipipe->up_repeat = 1; | | 235 | ipipe->up_repeat = 1; |
235 | err = usbd_transfer(xfer); | | 236 | err = usbd_transfer(xfer); |
236 | *pipe = ipipe; | | 237 | *pipe = ipipe; |
237 | if (err != USBD_IN_PROGRESS) | | 238 | if (err != USBD_IN_PROGRESS) |
238 | goto bad3; | | 239 | goto bad3; |
239 | return USBD_NORMAL_COMPLETION; | | 240 | return USBD_NORMAL_COMPLETION; |
240 | | | 241 | |
241 | bad3: | | 242 | bad3: |
242 | ipipe->up_intrxfer = NULL; | | 243 | ipipe->up_intrxfer = NULL; |
243 | ipipe->up_repeat = 0; | | 244 | ipipe->up_repeat = 0; |
244 | bad2: | | 245 | bad2: |
245 | usbd_free_xfer(xfer); | | 246 | usbd_free_xfer(xfer); |
246 | bad1: | | 247 | bad1: |
| @@ -264,28 +265,30 @@ usbd_close_pipe(usbd_pipe_handle pipe) | | | @@ -264,28 +265,30 @@ usbd_close_pipe(usbd_pipe_handle pipe) |
264 | usbd_lock_pipe(pipe); | | 265 | usbd_lock_pipe(pipe); |
265 | if (--pipe->up_refcnt != 0) { | | 266 | if (--pipe->up_refcnt != 0) { |
266 | usbd_unlock_pipe(pipe); | | 267 | usbd_unlock_pipe(pipe); |
267 | return USBD_NORMAL_COMPLETION; | | 268 | return USBD_NORMAL_COMPLETION; |
268 | } | | 269 | } |
269 | if (! SIMPLEQ_EMPTY(&pipe->up_queue)) { | | 270 | if (! SIMPLEQ_EMPTY(&pipe->up_queue)) { |
270 | usbd_unlock_pipe(pipe); | | 271 | usbd_unlock_pipe(pipe); |
271 | return USBD_PENDING_REQUESTS; | | 272 | return USBD_PENDING_REQUESTS; |
272 | } | | 273 | } |
273 | LIST_REMOVE(pipe, up_next); | | 274 | LIST_REMOVE(pipe, up_next); |
274 | pipe->up_endpoint->ue_refcnt--; | | 275 | pipe->up_endpoint->ue_refcnt--; |
275 | pipe->up_methods->upm_close(pipe); | | 276 | pipe->up_methods->upm_close(pipe); |
276 | usbd_unlock_pipe(pipe); | | 277 | usbd_unlock_pipe(pipe); |
277 | if (pipe->up_intrxfer != NULL) | | 278 | if (pipe->up_intrxfer != NULL) { |
278 | usbd_free_xfer(pipe->up_intrxfer); | | 279 | usbd_free_xfer(pipe->up_intrxfer); |
| | | 280 | usbd_free_buffer(pipe->up_intrbuf); |
| | | 281 | } |
279 | kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize); | | 282 | kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize); |
280 | return USBD_NORMAL_COMPLETION; | | 283 | return USBD_NORMAL_COMPLETION; |
281 | } | | 284 | } |
282 | | | 285 | |
283 | usbd_status | | 286 | usbd_status |
284 | usbd_transfer(usbd_xfer_handle xfer) | | 287 | usbd_transfer(usbd_xfer_handle xfer) |
285 | { | | 288 | { |
286 | usbd_pipe_handle pipe = xfer->ux_pipe; | | 289 | usbd_pipe_handle pipe = xfer->ux_pipe; |
287 | usbd_status err; | | 290 | usbd_status err; |
288 | unsigned int size, flags; | | 291 | unsigned int size, flags; |
289 | | | 292 | |
290 | USBHIST_FUNC(); USBHIST_CALLED(usbdebug); | | 293 | USBHIST_FUNC(); USBHIST_CALLED(usbdebug); |
291 | | | 294 | |
| @@ -1059,44 +1062,44 @@ usbd_do_request_flags(usbd_device_handle | | | @@ -1059,44 +1062,44 @@ usbd_do_request_flags(usbd_device_handle |
1059 | void *data, uint16_t flags, int *actlen, uint32_t timo) | | 1062 | void *data, uint16_t flags, int *actlen, uint32_t timo) |
1060 | { | | 1063 | { |
1061 | return (usbd_do_request_flags_pipe(dev, dev->ud_pipe0, req, | | 1064 | return (usbd_do_request_flags_pipe(dev, dev->ud_pipe0, req, |
1062 | data, flags, actlen, timo)); | | 1065 | data, flags, actlen, timo)); |
1063 | } | | 1066 | } |
1064 | | | 1067 | |
1065 | usbd_status | | 1068 | usbd_status |
1066 | usbd_do_request_flags_pipe(usbd_device_handle dev, usbd_pipe_handle pipe, | | 1069 | usbd_do_request_flags_pipe(usbd_device_handle dev, usbd_pipe_handle pipe, |
1067 | usb_device_request_t *req, void *data, uint16_t flags, int *actlen, | | 1070 | usb_device_request_t *req, void *data, uint16_t flags, int *actlen, |
1068 | uint32_t timeout) | | 1071 | uint32_t timeout) |
1069 | { | | 1072 | { |
1070 | usbd_xfer_handle xfer; | | 1073 | usbd_xfer_handle xfer; |
1071 | usbd_status err; | | 1074 | usbd_status err; |
| | | 1075 | void *buf = NULL; |
1072 | | | 1076 | |
1073 | USBHIST_FUNC(); USBHIST_CALLED(usbdebug); | | 1077 | USBHIST_FUNC(); USBHIST_CALLED(usbdebug); |
1074 | | | 1078 | |
1075 | ASSERT_SLEEPABLE(); | | 1079 | ASSERT_SLEEPABLE(); |
1076 | | | 1080 | |
1077 | xfer = usbd_alloc_xfer(dev); | | 1081 | xfer = usbd_alloc_xfer(dev); |
1078 | if (xfer == NULL) | | 1082 | if (xfer == NULL) |
1079 | return USBD_NOMEM; | | 1083 | return USBD_NOMEM; |
1080 | | | 1084 | |
1081 | if (UGETW(req->wLength) != 0) { | | 1085 | if (UGETW(req->wLength) != 0) { |
1082 | void *buf = usbd_alloc_buffer(xfer, UGETW(req->wLength)); | | 1086 | buf = usbd_alloc_buffer(xfer, UGETW(req->wLength)); |
1083 | if (buf == NULL) { | | 1087 | if (buf == NULL) { |
1084 | err = ENOMEM; | | 1088 | err = ENOMEM; |
1085 | goto bad; | | 1089 | goto bad; |
1086 | } | | 1090 | } |
1087 | } | | 1091 | } |
1088 | | | 1092 | |
1089 | | | | |
1090 | usbd_setup_default_xfer(xfer, dev, 0, timeout, req, | | 1093 | usbd_setup_default_xfer(xfer, dev, 0, timeout, req, |
1091 | data, UGETW(req->wLength), flags, 0); | | 1094 | data, UGETW(req->wLength), flags, 0); |
1092 | xfer->ux_pipe = pipe; | | 1095 | xfer->ux_pipe = pipe; |
1093 | err = usbd_sync_transfer(xfer); | | 1096 | err = usbd_sync_transfer(xfer); |
1094 | #if defined(USB_DEBUG) || defined(DIAGNOSTIC) | | 1097 | #if defined(USB_DEBUG) || defined(DIAGNOSTIC) |
1095 | if (xfer->ux_actlen > xfer->ux_length) { | | 1098 | if (xfer->ux_actlen > xfer->ux_length) { |
1096 | USBHIST_LOG(usbdebug, "overrun addr = %d type = 0x%02x", | | 1099 | USBHIST_LOG(usbdebug, "overrun addr = %d type = 0x%02x", |
1097 | dev->ud_addr, xfer->ux_request.bmRequestType, 0, 0); | | 1100 | dev->ud_addr, xfer->ux_request.bmRequestType, 0, 0); |
1098 | USBHIST_LOG(usbdebug, " req = 0x%02x val = %d index = %d", | | 1101 | USBHIST_LOG(usbdebug, " req = 0x%02x val = %d index = %d", |
1099 | xfer->ux_request.bRequest, UGETW(xfer->ux_request.wValue), | | 1102 | xfer->ux_request.bRequest, UGETW(xfer->ux_request.wValue), |
1100 | UGETW(xfer->ux_request.wIndex), 0); | | 1103 | UGETW(xfer->ux_request.wIndex), 0); |
1101 | USBHIST_LOG(usbdebug, " rlen = %d length = %d actlen = %d", | | 1104 | USBHIST_LOG(usbdebug, " rlen = %d length = %d actlen = %d", |
1102 | UGETW(xfer->ux_request.wLength), | | 1105 | UGETW(xfer->ux_request.wLength), |
| @@ -1139,26 +1142,28 @@ usbd_do_request_flags_pipe(usbd_device_h | | | @@ -1139,26 +1142,28 @@ usbd_do_request_flags_pipe(usbd_device_h |
1139 | usbd_setup_default_xfer(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, | | 1142 | usbd_setup_default_xfer(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, |
1140 | &treq, &status, 0, 0, 0); | | 1143 | &treq, &status, 0, 0, 0); |
1141 | nerr = usbd_sync_transfer(xfer); | | 1144 | nerr = usbd_sync_transfer(xfer); |
1142 | if (nerr) | | 1145 | if (nerr) |
1143 | goto bad; | | 1146 | goto bad; |
1144 | } | | 1147 | } |
1145 | | | 1148 | |
1146 | bad: | | 1149 | bad: |
1147 | if (err) { | | 1150 | if (err) { |
1148 | USBHIST_LOG(usbdebug, "returning err = %s", | | 1151 | USBHIST_LOG(usbdebug, "returning err = %s", |
1149 | usbd_errstr(err), 0, 0, 0); | | 1152 | usbd_errstr(err), 0, 0, 0); |
1150 | } | | 1153 | } |
1151 | usbd_free_xfer(xfer); | | 1154 | usbd_free_xfer(xfer); |
| | | 1155 | if (buf) |
| | | 1156 | usbd_free_buffer(buf); |
1152 | return err; | | 1157 | return err; |
1153 | } | | 1158 | } |
1154 | | | 1159 | |
1155 | const struct usbd_quirks * | | 1160 | const struct usbd_quirks * |
1156 | usbd_get_quirks(usbd_device_handle dev) | | 1161 | usbd_get_quirks(usbd_device_handle dev) |
1157 | { | | 1162 | { |
1158 | #ifdef DIAGNOSTIC | | 1163 | #ifdef DIAGNOSTIC |
1159 | if (dev == NULL) { | | 1164 | if (dev == NULL) { |
1160 | printf("usbd_get_quirks: dev == NULL\n"); | | 1165 | printf("usbd_get_quirks: dev == NULL\n"); |
1161 | return 0; | | 1166 | return 0; |
1162 | } | | 1167 | } |
1163 | #endif | | 1168 | #endif |
1164 | return dev->ud_quirks; | | 1169 | return dev->ud_quirks; |