Thu Mar 3 06:05:38 2022 UTC ()
usb: usbd_abort_pipe never fails.  Make it return void.

Prune dead branches as a result of this change.


(riastradh)
diff -r1.73 -r1.74 src/sys/dev/usb/if_atu.c
diff -r1.13 -r1.14 src/sys/dev/usb/ualea.c
diff -r1.223 -r1.224 src/sys/dev/usb/usbdi.c
diff -r1.104 -r1.105 src/sys/dev/usb/usbdi.h
diff -r1.91 -r1.92 src/sys/dev/usb/usbnet.c
diff -r1.35 -r1.36 src/sys/dev/usb/utoppy.c

cvs diff -r1.73 -r1.74 src/sys/dev/usb/if_atu.c (expand / switch to unified diff)

--- src/sys/dev/usb/if_atu.c 2020/08/28 19:02:19 1.73
+++ src/sys/dev/usb/if_atu.c 2022/03/03 06:05:38 1.74
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_atu.c,v 1.73 2020/08/28 19:02:19 riastradh Exp $ */ 1/* $NetBSD: if_atu.c,v 1.74 2022/03/03 06:05:38 riastradh Exp $ */
2/* $OpenBSD: if_atu.c,v 1.48 2004/12/30 01:53:21 dlg Exp $ */ 2/* $OpenBSD: if_atu.c,v 1.48 2004/12/30 01:53:21 dlg Exp $ */
3/* 3/*
4 * Copyright (c) 2003, 2004 4 * Copyright (c) 2003, 2004
5 * Daan Vreeken <Danovitsch@Vitsch.net>. All rights reserved. 5 * Daan Vreeken <Danovitsch@Vitsch.net>. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -38,27 +38,27 @@ @@ -38,27 +38,27 @@
38 * 38 *
39 * Originally written by Daan Vreeken <Danovitsch @ Vitsch . net> 39 * Originally written by Daan Vreeken <Danovitsch @ Vitsch . net>
40 * http://vitsch.net/bsd/atuwi 40 * http://vitsch.net/bsd/atuwi
41 * 41 *
42 * Contributed to by : 42 * Contributed to by :
43 * Chris Whitehouse, Alistair Phillips, Peter Pilka, Martijn van Buul, 43 * Chris Whitehouse, Alistair Phillips, Peter Pilka, Martijn van Buul,
44 * Suihong Liang, Arjan van Leeuwen, Stuart Walsh 44 * Suihong Liang, Arjan van Leeuwen, Stuart Walsh
45 * 45 *
46 * Ported to OpenBSD by Theo de Raadt and David Gwynne. 46 * Ported to OpenBSD by Theo de Raadt and David Gwynne.
47 * Ported to NetBSD by Jesse Off 47 * Ported to NetBSD by Jesse Off
48 */ 48 */
49 49
50#include <sys/cdefs.h> 50#include <sys/cdefs.h>
51__KERNEL_RCSID(0, "$NetBSD: if_atu.c,v 1.73 2020/08/28 19:02:19 riastradh Exp $"); 51__KERNEL_RCSID(0, "$NetBSD: if_atu.c,v 1.74 2022/03/03 06:05:38 riastradh Exp $");
52 52
53#ifdef _KERNEL_OPT 53#ifdef _KERNEL_OPT
54#include "opt_usb.h" 54#include "opt_usb.h"
55#endif 55#endif
56 56
57#include <sys/param.h> 57#include <sys/param.h>
58#include <sys/sockio.h> 58#include <sys/sockio.h>
59#include <sys/mbuf.h> 59#include <sys/mbuf.h>
60#include <sys/kernel.h> 60#include <sys/kernel.h>
61#include <sys/socket.h> 61#include <sys/socket.h>
62#include <sys/systm.h> 62#include <sys/systm.h>
63#include <sys/kthread.h> 63#include <sys/kthread.h>
64#include <sys/queue.h> 64#include <sys/queue.h>
@@ -2225,39 +2225,31 @@ atu_stop(struct ifnet *ifp, int disable) @@ -2225,39 +2225,31 @@ atu_stop(struct ifnet *ifp, int disable)
2225 struct atu_cdata *cd; 2225 struct atu_cdata *cd;
2226 usbd_status err; 2226 usbd_status err;
2227 int s; 2227 int s;
2228 2228
2229 s = splnet(); 2229 s = splnet();
2230 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); 2230 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
2231 ifp->if_timer = 0; 2231 ifp->if_timer = 0;
2232 2232
2233 usb_rem_task_wait(sc->atu_udev, &sc->sc_task, USB_TASKQ_DRIVER, NULL); 2233 usb_rem_task_wait(sc->atu_udev, &sc->sc_task, USB_TASKQ_DRIVER, NULL);
2234 ieee80211_new_state(ic, IEEE80211_S_INIT, -1); 2234 ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
2235 2235
2236 /* Stop transfers. */ 2236 /* Stop transfers. */
2237 if (sc->atu_ep[ATU_ENDPT_RX] != NULL) { 2237 if (sc->atu_ep[ATU_ENDPT_RX] != NULL) {
2238 err = usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_RX]); 2238 usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_RX]);
2239 if (err) { 
2240 DPRINTF(("%s: abort rx pipe failed: %s\n", 
2241 device_xname(sc->atu_dev), usbd_errstr(err))); 
2242 } 
2243 } 2239 }
2244 2240
2245 if (sc->atu_ep[ATU_ENDPT_TX] != NULL) { 2241 if (sc->atu_ep[ATU_ENDPT_TX] != NULL) {
2246 err = usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_TX]); 2242 usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_TX]);
2247 if (err) { 
2248 DPRINTF(("%s: abort tx pipe failed: %s\n", 
2249 device_xname(sc->atu_dev), usbd_errstr(err))); 
2250 } 
2251 } 2243 }
2252 2244
2253 /* Free RX/TX/MGMT list resources. */ 2245 /* Free RX/TX/MGMT list resources. */
2254 cd = &sc->atu_cdata; 2246 cd = &sc->atu_cdata;
2255 atu_xfer_list_free(sc, cd->atu_rx_chain, ATU_RX_LIST_CNT); 2247 atu_xfer_list_free(sc, cd->atu_rx_chain, ATU_RX_LIST_CNT);
2256 atu_xfer_list_free(sc, cd->atu_tx_chain, ATU_TX_LIST_CNT); 2248 atu_xfer_list_free(sc, cd->atu_tx_chain, ATU_TX_LIST_CNT);
2257 2249
2258 /* Close pipes */ 2250 /* Close pipes */
2259 if (sc->atu_ep[ATU_ENDPT_RX] != NULL) { 2251 if (sc->atu_ep[ATU_ENDPT_RX] != NULL) {
2260 err = usbd_close_pipe(sc->atu_ep[ATU_ENDPT_RX]); 2252 err = usbd_close_pipe(sc->atu_ep[ATU_ENDPT_RX]);
2261 if (err) { 2253 if (err) {
2262 DPRINTF(("%s: close rx pipe failed: %s\n", 2254 DPRINTF(("%s: close rx pipe failed: %s\n",
2263 device_xname(sc->atu_dev), usbd_errstr(err))); 2255 device_xname(sc->atu_dev), usbd_errstr(err)));

cvs diff -r1.13 -r1.14 src/sys/dev/usb/ualea.c (expand / switch to unified diff)

--- src/sys/dev/usb/ualea.c 2021/05/29 08:45:19 1.13
+++ src/sys/dev/usb/ualea.c 2022/03/03 06:05:38 1.14
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ualea.c,v 1.13 2021/05/29 08:45:19 riastradh Exp $ */ 1/* $NetBSD: ualea.c,v 1.14 2022/03/03 06:05:38 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2017 The NetBSD Foundation, Inc. 4 * Copyright (c) 2017 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 Taylor R. Campbell. 8 * by Taylor R. Campbell.
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.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.13 2021/05/29 08:45:19 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.14 2022/03/03 06:05:38 riastradh Exp $");
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/atomic.h> 36#include <sys/atomic.h>
37#include <sys/device_if.h> 37#include <sys/device_if.h>
38#include <sys/kmem.h> 38#include <sys/kmem.h>
39#include <sys/module.h> 39#include <sys/module.h>
40#include <sys/rndsource.h> 40#include <sys/rndsource.h>
41 41
42#include <dev/usb/usb.h> 42#include <dev/usb/usb.h>
43#include <dev/usb/usbdevs.h> 43#include <dev/usb/usbdevs.h>
44#include <dev/usb/usbdi.h> 44#include <dev/usb/usbdi.h>
45#include <dev/usb/usbdi_util.h> 45#include <dev/usb/usbdi_util.h>
46 46
@@ -151,27 +151,27 @@ ualea_attach(device_t parent, device_t s @@ -151,27 +151,27 @@ ualea_attach(device_t parent, device_t s
151} 151}
152 152
153static int 153static int
154ualea_detach(device_t self, int flags) 154ualea_detach(device_t self, int flags)
155{ 155{
156 struct ualea_softc *sc = device_private(self); 156 struct ualea_softc *sc = device_private(self);
157 157
158 /* Prevent new use of xfer. */ 158 /* Prevent new use of xfer. */
159 if (sc->sc_attached) 159 if (sc->sc_attached)
160 rnd_detach_source(&sc->sc_rnd); 160 rnd_detach_source(&sc->sc_rnd);
161 161
162 /* Cancel pending xfer. */ 162 /* Cancel pending xfer. */
163 if (sc->sc_pipe) 163 if (sc->sc_pipe)
164 (void)usbd_abort_pipe(sc->sc_pipe); 164 usbd_abort_pipe(sc->sc_pipe);
165 KASSERT(!sc->sc_inflight); 165 KASSERT(!sc->sc_inflight);
166 166
167 /* All users have drained. Tear it all down. */ 167 /* All users have drained. Tear it all down. */
168 if (sc->sc_xfer) 168 if (sc->sc_xfer)
169 usbd_destroy_xfer(sc->sc_xfer); 169 usbd_destroy_xfer(sc->sc_xfer);
170 if (sc->sc_pipe) 170 if (sc->sc_pipe)
171 (void)usbd_close_pipe(sc->sc_pipe); 171 (void)usbd_close_pipe(sc->sc_pipe);
172 mutex_destroy(&sc->sc_lock); 172 mutex_destroy(&sc->sc_lock);
173 173
174 return 0; 174 return 0;
175} 175}
176 176
177static void 177static void

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

--- src/sys/dev/usb/usbdi.c 2022/03/03 06:04:31 1.223
+++ src/sys/dev/usb/usbdi.c 2022/03/03 06:05:38 1.224
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbdi.c,v 1.223 2022/03/03 06:04:31 riastradh Exp $ */ 1/* $NetBSD: usbdi.c,v 1.224 2022/03/03 06:05:38 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.223 2022/03/03 06:04:31 riastradh Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.224 2022/03/03 06:05:38 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,27 +103,27 @@ SDT_PROBE_DEFINE5(usb, device, xfer, cre @@ -103,27 +103,27 @@ 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
116Static usbd_status usbd_ar_pipe(struct usbd_pipe *); 116Static void usbd_ar_pipe(struct usbd_pipe *);
117static usbd_status usb_insert_transfer(struct usbd_xfer *); 117static usbd_status usb_insert_transfer(struct usbd_xfer *);
118Static void usbd_start_next(struct usbd_pipe *); 118Static void usbd_start_next(struct usbd_pipe *);
119Static usbd_status usbd_open_pipe_ival 119Static usbd_status usbd_open_pipe_ival
120 (struct usbd_interface *, uint8_t, uint8_t, struct usbd_pipe **, int); 120 (struct usbd_interface *, uint8_t, uint8_t, struct usbd_pipe **, int);
121static void *usbd_alloc_buffer(struct usbd_xfer *, uint32_t); 121static void *usbd_alloc_buffer(struct usbd_xfer *, uint32_t);
122static void usbd_free_buffer(struct usbd_xfer *); 122static void usbd_free_buffer(struct usbd_xfer *);
123static struct usbd_xfer *usbd_alloc_xfer(struct usbd_device *, unsigned int); 123static struct usbd_xfer *usbd_alloc_xfer(struct usbd_device *, unsigned int);
124static usbd_status usbd_free_xfer(struct usbd_xfer *); 124static usbd_status usbd_free_xfer(struct usbd_xfer *);
125static void usbd_request_async_cb(struct usbd_xfer *, void *, usbd_status); 125static void usbd_request_async_cb(struct usbd_xfer *, void *, usbd_status);
126static void usbd_xfer_timeout(void *); 126static void usbd_xfer_timeout(void *);
127static void usbd_xfer_timeout_task(void *); 127static void usbd_xfer_timeout_task(void *);
128static bool usbd_xfer_probe_timeout(struct usbd_xfer *); 128static bool usbd_xfer_probe_timeout(struct usbd_xfer *);
129static void usbd_xfer_cancel_timeout_async(struct usbd_xfer *); 129static void usbd_xfer_cancel_timeout_async(struct usbd_xfer *);
@@ -759,43 +759,41 @@ usbd_get_device_descriptor(struct usbd_d @@ -759,43 +759,41 @@ usbd_get_device_descriptor(struct usbd_d
759} 759}
760 760
761usb_endpoint_descriptor_t * 761usb_endpoint_descriptor_t *
762usbd_interface2endpoint_descriptor(struct usbd_interface *iface, uint8_t index) 762usbd_interface2endpoint_descriptor(struct usbd_interface *iface, uint8_t index)
763{ 763{
764 764
765 if (index >= iface->ui_idesc->bNumEndpoints) 765 if (index >= iface->ui_idesc->bNumEndpoints)
766 return NULL; 766 return NULL;
767 return iface->ui_endpoints[index].ue_edesc; 767 return iface->ui_endpoints[index].ue_edesc;
768} 768}
769 769
770/* Some drivers may wish to abort requests on the default pipe, * 770/* Some drivers may wish to abort requests on the default pipe, *
771 * but there is no mechanism for getting a handle on it. */ 771 * but there is no mechanism for getting a handle on it. */
772usbd_status 772void
773usbd_abort_default_pipe(struct usbd_device *device) 773usbd_abort_default_pipe(struct usbd_device *device)
774{ 774{
775 return usbd_abort_pipe(device->ud_pipe0); 775 usbd_abort_pipe(device->ud_pipe0);
776} 776}
777 777
778usbd_status 778void
779usbd_abort_pipe(struct usbd_pipe *pipe) 779usbd_abort_pipe(struct usbd_pipe *pipe)
780{ 780{
781 usbd_status err; 
782 781
783 KASSERT(pipe != NULL); 782 KASSERT(pipe != NULL);
784 783
785 usbd_lock_pipe(pipe); 784 usbd_lock_pipe(pipe);
786 err = usbd_ar_pipe(pipe); 785 usbd_ar_pipe(pipe);
787 usbd_unlock_pipe(pipe); 786 usbd_unlock_pipe(pipe);
788 return err; 
789} 787}
790 788
791usbd_status 789usbd_status
792usbd_clear_endpoint_stall(struct usbd_pipe *pipe) 790usbd_clear_endpoint_stall(struct usbd_pipe *pipe)
793{ 791{
794 struct usbd_device *dev = pipe->up_dev; 792 struct usbd_device *dev = pipe->up_dev;
795 usbd_status err; 793 usbd_status err;
796 794
797 USBHIST_FUNC(); USBHIST_CALLED(usbdebug); 795 USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
798 SDT_PROBE1(usb, device, pipe, clear__endpoint__stall, pipe); 796 SDT_PROBE1(usb, device, pipe, clear__endpoint__stall, pipe);
799 797
800 /* 798 /*
801 * Clearing en endpoint stall resets the endpoint toggle, so 799 * Clearing en endpoint stall resets the endpoint toggle, so
@@ -956,27 +954,27 @@ usbd_get_interface(struct usbd_interface @@ -956,27 +954,27 @@ usbd_get_interface(struct usbd_interface
956 usb_device_request_t req; 954 usb_device_request_t req;
957 955
958 req.bmRequestType = UT_READ_INTERFACE; 956 req.bmRequestType = UT_READ_INTERFACE;
959 req.bRequest = UR_GET_INTERFACE; 957 req.bRequest = UR_GET_INTERFACE;
960 USETW(req.wValue, 0); 958 USETW(req.wValue, 0);
961 USETW(req.wIndex, iface->ui_idesc->bInterfaceNumber); 959 USETW(req.wIndex, iface->ui_idesc->bInterfaceNumber);
962 USETW(req.wLength, 1); 960 USETW(req.wLength, 1);
963 return usbd_do_request(iface->ui_dev, &req, aiface); 961 return usbd_do_request(iface->ui_dev, &req, aiface);
964} 962}
965 963
966/*** Internal routines ***/ 964/*** Internal routines ***/
967 965
968/* Dequeue all pipe operations, called with bus lock held. */ 966/* Dequeue all pipe operations, called with bus lock held. */
969Static usbd_status 967Static void
970usbd_ar_pipe(struct usbd_pipe *pipe) 968usbd_ar_pipe(struct usbd_pipe *pipe)
971{ 969{
972 struct usbd_xfer *xfer; 970 struct usbd_xfer *xfer;
973 971
974 USBHIST_FUNC(); 972 USBHIST_FUNC();
975 USBHIST_CALLARGS(usbdebug, "pipe = %#jx", (uintptr_t)pipe, 0, 0, 0); 973 USBHIST_CALLARGS(usbdebug, "pipe = %#jx", (uintptr_t)pipe, 0, 0, 0);
976 SDT_PROBE1(usb, device, pipe, abort__start, pipe); 974 SDT_PROBE1(usb, device, pipe, abort__start, pipe);
977 975
978 KASSERT(mutex_owned(pipe->up_dev->ud_bus->ub_lock)); 976 KASSERT(mutex_owned(pipe->up_dev->ud_bus->ub_lock));
979 977
980#ifdef USB_DEBUG 978#ifdef USB_DEBUG
981 if (usbdebug > 5) 979 if (usbdebug > 5)
982 usbd_dump_queue(pipe); 980 usbd_dump_queue(pipe);
@@ -1000,27 +998,26 @@ usbd_ar_pipe(struct usbd_pipe *pipe) @@ -1000,27 +998,26 @@ usbd_ar_pipe(struct usbd_pipe *pipe)
1000 pipe->up_methods->upm_abort(xfer); 998 pipe->up_methods->upm_abort(xfer);
1001 while (pipe->up_callingxfer == xfer) { 999 while (pipe->up_callingxfer == xfer) {
1002 USBHIST_LOG(usbdebug, "wait for callback" 1000 USBHIST_LOG(usbdebug, "wait for callback"
1003 "pipe = %#jx xfer = %#jx", 1001 "pipe = %#jx xfer = %#jx",
1004 (uintptr_t)pipe, (uintptr_t)xfer, 0, 0); 1002 (uintptr_t)pipe, (uintptr_t)xfer, 0, 0);
1005 cv_wait(&pipe->up_callingcv, 1003 cv_wait(&pipe->up_callingcv,
1006 pipe->up_dev->ud_bus->ub_lock); 1004 pipe->up_dev->ud_bus->ub_lock);
1007 } 1005 }
1008 /* XXX only for non-0 usbd_clear_endpoint_stall(pipe); */ 1006 /* XXX only for non-0 usbd_clear_endpoint_stall(pipe); */
1009 } 1007 }
1010 } 1008 }
1011 pipe->up_aborting = 0; 1009 pipe->up_aborting = 0;
1012 SDT_PROBE1(usb, device, pipe, abort__done, pipe); 1010 SDT_PROBE1(usb, device, pipe, abort__done, pipe);
1013 return USBD_NORMAL_COMPLETION; 
1014} 1011}
1015 1012
1016/* Called with USB lock held. */ 1013/* Called with USB lock held. */
1017void 1014void
1018usb_transfer_complete(struct usbd_xfer *xfer) 1015usb_transfer_complete(struct usbd_xfer *xfer)
1019{ 1016{
1020 struct usbd_pipe *pipe = xfer->ux_pipe; 1017 struct usbd_pipe *pipe = xfer->ux_pipe;
1021 struct usbd_bus *bus = pipe->up_dev->ud_bus; 1018 struct usbd_bus *bus = pipe->up_dev->ud_bus;
1022 int sync = xfer->ux_flags & USBD_SYNCHRONOUS; 1019 int sync = xfer->ux_flags & USBD_SYNCHRONOUS;
1023 int erred; 1020 int erred;
1024 int polling = bus->ub_usepolling; 1021 int polling = bus->ub_usepolling;
1025 int repeat = pipe->up_repeat; 1022 int repeat = pipe->up_repeat;
1026 1023

cvs diff -r1.104 -r1.105 src/sys/dev/usb/usbdi.h (expand / switch to unified diff)

--- src/sys/dev/usb/usbdi.h 2022/02/14 09:22:30 1.104
+++ src/sys/dev/usb/usbdi.h 2022/03/03 06:05:38 1.105
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbdi.h,v 1.104 2022/02/14 09:22:30 riastradh Exp $ */ 1/* $NetBSD: usbdi.h,v 1.105 2022/03/03 06:05:38 riastradh Exp $ */
2/* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */ 2/* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at 9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology. 10 * Carlstedt Research & Technology.
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:
@@ -112,28 +112,28 @@ void usbd_setup_xfer(struct usbd_xfer *, @@ -112,28 +112,28 @@ void usbd_setup_xfer(struct usbd_xfer *,
112void usbd_setup_default_xfer(struct usbd_xfer *, struct usbd_device *, 112void usbd_setup_default_xfer(struct usbd_xfer *, struct usbd_device *,
113 void *, uint32_t, usb_device_request_t *, void *, 113 void *, uint32_t, usb_device_request_t *, void *,
114 uint32_t, uint16_t, usbd_callback); 114 uint32_t, uint16_t, usbd_callback);
115 115
116void usbd_setup_isoc_xfer(struct usbd_xfer *, void *, uint16_t *, 116void usbd_setup_isoc_xfer(struct usbd_xfer *, void *, uint16_t *,
117 uint32_t, uint16_t, usbd_callback); 117 uint32_t, uint16_t, usbd_callback);
118 118
119void usbd_get_xfer_status(struct usbd_xfer *, void **, 119void usbd_get_xfer_status(struct usbd_xfer *, void **,
120 void **, uint32_t *, usbd_status *); 120 void **, uint32_t *, usbd_status *);
121 121
122usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor 122usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
123 (struct usbd_interface *, uint8_t); 123 (struct usbd_interface *, uint8_t);
124 124
125usbd_status usbd_abort_pipe(struct usbd_pipe *); 125void usbd_abort_pipe(struct usbd_pipe *);
126usbd_status usbd_abort_default_pipe(struct usbd_device *); 126void usbd_abort_default_pipe(struct usbd_device *);
127 127
128usbd_status usbd_clear_endpoint_stall(struct usbd_pipe *); 128usbd_status usbd_clear_endpoint_stall(struct usbd_pipe *);
129void usbd_clear_endpoint_stall_async(struct usbd_pipe *); 129void usbd_clear_endpoint_stall_async(struct usbd_pipe *);
130 130
131void usbd_clear_endpoint_toggle(struct usbd_pipe *); 131void usbd_clear_endpoint_toggle(struct usbd_pipe *);
132usbd_status usbd_endpoint_count(struct usbd_interface *, uint8_t *); 132usbd_status usbd_endpoint_count(struct usbd_interface *, uint8_t *);
133 133
134usbd_status usbd_interface_count(struct usbd_device *, uint8_t *); 134usbd_status usbd_interface_count(struct usbd_device *, uint8_t *);
135 135
136void usbd_interface2device_handle(struct usbd_interface *, struct usbd_device **); 136void usbd_interface2device_handle(struct usbd_interface *, struct usbd_device **);
137usbd_status usbd_device2interface_handle(struct usbd_device *, 137usbd_status usbd_device2interface_handle(struct usbd_device *,
138 uint8_t, struct usbd_interface **); 138 uint8_t, struct usbd_interface **);
139 139

cvs diff -r1.91 -r1.92 src/sys/dev/usb/usbnet.c (expand / switch to unified diff)

--- src/sys/dev/usb/usbnet.c 2022/03/03 05:56:44 1.91
+++ src/sys/dev/usb/usbnet.c 2022/03/03 06:05:38 1.92
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbnet.c,v 1.91 2022/03/03 05:56:44 riastradh Exp $ */ 1/* $NetBSD: usbnet.c,v 1.92 2022/03/03 06:05:38 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2019 Matthew R. Green 4 * Copyright (c) 2019 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * Common code shared between USB network drivers. 30 * Common code shared between USB network drivers.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.91 2022/03/03 05:56:44 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.92 2022/03/03 06:05:38 riastradh Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/kmem.h> 38#include <sys/kmem.h>
39#include <sys/module.h> 39#include <sys/module.h>
40#include <sys/atomic.h> 40#include <sys/atomic.h>
41 41
42#include <dev/usb/usbnet.h> 42#include <dev/usb/usbnet.h>
43#include <dev/usb/usbhist.h> 43#include <dev/usb/usbhist.h>
44 44
45struct usbnet_cdata { 45struct usbnet_cdata {
46 struct usbnet_chain *uncd_tx_chain; 46 struct usbnet_chain *uncd_tx_chain;
47 struct usbnet_chain *uncd_rx_chain; 47 struct usbnet_chain *uncd_rx_chain;
@@ -807,41 +807,36 @@ usbnet_ep_open_pipes(struct usbnet * con @@ -807,41 +807,36 @@ usbnet_ep_open_pipes(struct usbnet * con
807 } else { 807 } else {
808 err = usbd_open_pipe(un->un_iface, un->un_ed[i], 808 err = usbd_open_pipe(un->un_iface, un->un_ed[i],
809 USBD_EXCLUSIVE_USE | USBD_MPSAFE, &unp->unp_ep[i]); 809 USBD_EXCLUSIVE_USE | USBD_MPSAFE, &unp->unp_ep[i]);
810 } 810 }
811 if (err) { 811 if (err) {
812 usbnet_ep_close_pipes(un); 812 usbnet_ep_close_pipes(un);
813 return err; 813 return err;
814 } 814 }
815 } 815 }
816 816
817 return USBD_NORMAL_COMPLETION; 817 return USBD_NORMAL_COMPLETION;
818} 818}
819 819
820static usbd_status 820static void
821usbnet_ep_stop_pipes(struct usbnet * const un) 821usbnet_ep_stop_pipes(struct usbnet * const un)
822{ 822{
823 struct usbnet_private * const unp = un->un_pri; 823 struct usbnet_private * const unp = un->un_pri;
824 usbd_status err = USBD_NORMAL_COMPLETION; 
825 824
826 for (size_t i = 0; i < __arraycount(unp->unp_ep); i++) { 825 for (size_t i = 0; i < __arraycount(unp->unp_ep); i++) {
827 if (unp->unp_ep[i] == NULL) 826 if (unp->unp_ep[i] == NULL)
828 continue; 827 continue;
829 usbd_status err2 = usbd_abort_pipe(unp->unp_ep[i]); 828 usbd_abort_pipe(unp->unp_ep[i]);
830 if (err == USBD_NORMAL_COMPLETION && err2) 
831 err = err2; 
832 } 829 }
833 
834 return err; 
835} 830}
836 831
837static int 832static int
838usbnet_init_rx_tx(struct usbnet * const un) 833usbnet_init_rx_tx(struct usbnet * const un)
839{ 834{
840 USBNETHIST_FUNC(); USBNETHIST_CALLED(); 835 USBNETHIST_FUNC(); USBNETHIST_CALLED();
841 struct usbnet_private * const unp = un->un_pri; 836 struct usbnet_private * const unp = un->un_pri;
842 struct ifnet * const ifp = usbnet_ifp(un); 837 struct ifnet * const ifp = usbnet_ifp(un);
843 usbd_status err; 838 usbd_status err;
844 int error = 0; 839 int error = 0;
845 840
846 KASSERTMSG(!unp->unp_ifp_attached || IFNET_LOCKED(ifp), 841 KASSERTMSG(!unp->unp_ifp_attached || IFNET_LOCKED(ifp),
847 "%s", ifp->if_xname); 842 "%s", ifp->if_xname);
@@ -1198,37 +1193,33 @@ usbnet_tick(void *arg) @@ -1198,37 +1193,33 @@ usbnet_tick(void *arg)
1198 USBNETHIST_CALLARGSN(10, "%jd: enter", unp->unp_number, 0, 0, 0); 1193 USBNETHIST_CALLARGSN(10, "%jd: enter", unp->unp_number, 0, 0, 0);
1199 1194
1200 /* Perform periodic stuff in process context */ 1195 /* Perform periodic stuff in process context */
1201 usb_add_task(un->un_udev, &unp->unp_ticktask, USB_TASKQ_DRIVER); 1196 usb_add_task(un->un_udev, &unp->unp_ticktask, USB_TASKQ_DRIVER);
1202} 1197}
1203 1198
1204static void 1199static void
1205usbnet_watchdog(struct ifnet *ifp) 1200usbnet_watchdog(struct ifnet *ifp)
1206{ 1201{
1207 USBNETHIST_FUNC(); USBNETHIST_CALLED(); 1202 USBNETHIST_FUNC(); USBNETHIST_CALLED();
1208 struct usbnet * const un = ifp->if_softc; 1203 struct usbnet * const un = ifp->if_softc;
1209 struct usbnet_private * const unp = un->un_pri; 1204 struct usbnet_private * const unp = un->un_pri;
1210 struct usbnet_cdata * const cd = un_cdata(un); 1205 struct usbnet_cdata * const cd = un_cdata(un);
1211 usbd_status err; 
1212 1206
1213 if_statinc(ifp, if_oerrors); 1207 if_statinc(ifp, if_oerrors);
1214 device_printf(un->un_dev, "watchdog timeout\n"); 1208 device_printf(un->un_dev, "watchdog timeout\n");
1215 1209
1216 if (cd->uncd_tx_cnt > 0) { 1210 if (cd->uncd_tx_cnt > 0) {
1217 DPRINTF("uncd_tx_cnt=%ju non zero, aborting pipe", 0, 0, 0, 0); 1211 DPRINTF("uncd_tx_cnt=%ju non zero, aborting pipe", 0, 0, 0, 0);
1218 err = usbd_abort_pipe(unp->unp_ep[USBNET_ENDPT_TX]); 1212 usbd_abort_pipe(unp->unp_ep[USBNET_ENDPT_TX]);
1219 if (err) 
1220 device_printf(un->un_dev, "pipe abort failed: %s\n", 
1221 usbd_errstr(err)); 
1222 if (cd->uncd_tx_cnt != 0) 1213 if (cd->uncd_tx_cnt != 0)
1223 DPRINTF("uncd_tx_cnt now %ju", cd->uncd_tx_cnt, 0, 0, 0); 1214 DPRINTF("uncd_tx_cnt now %ju", cd->uncd_tx_cnt, 0, 0, 0);
1224 } 1215 }
1225 1216
1226 if (!IFQ_IS_EMPTY(&ifp->if_snd)) 1217 if (!IFQ_IS_EMPTY(&ifp->if_snd))
1227 (*ifp->if_start)(ifp); 1218 (*ifp->if_start)(ifp);
1228} 1219}
1229 1220
1230static void 1221static void
1231usbnet_tick_task(void *arg) 1222usbnet_tick_task(void *arg)
1232{ 1223{
1233 USBNETHIST_FUNC(); 1224 USBNETHIST_FUNC();
1234 struct usbnet * const un = arg; 1225 struct usbnet * const un = arg;

cvs diff -r1.35 -r1.36 src/sys/dev/usb/utoppy.c (expand / switch to unified diff)

--- src/sys/dev/usb/utoppy.c 2020/03/14 02:35:34 1.35
+++ src/sys/dev/usb/utoppy.c 2022/03/03 06:05:38 1.36
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: utoppy.c,v 1.35 2020/03/14 02:35:34 christos Exp $ */ 1/* $NetBSD: utoppy.c,v 1.36 2022/03/03 06:05:38 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006 The NetBSD Foundation, Inc. 4 * Copyright (c) 2006 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 Steve C. Woodford. 8 * by Steve C. Woodford.
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.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: utoppy.c,v 1.35 2020/03/14 02:35:34 christos Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: utoppy.c,v 1.36 2022/03/03 06:05:38 riastradh Exp $");
34 34
35#ifdef _KERNEL_OPT 35#ifdef _KERNEL_OPT
36#include "opt_usb.h" 36#include "opt_usb.h"
37#endif 37#endif
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/proc.h> 41#include <sys/proc.h>
42#include <sys/kernel.h> 42#include <sys/kernel.h>
43#include <sys/fcntl.h> 43#include <sys/fcntl.h>
44#include <sys/device.h> 44#include <sys/device.h>
45#include <sys/ioctl.h> 45#include <sys/ioctl.h>
46#include <sys/uio.h> 46#include <sys/uio.h>
@@ -1355,53 +1355,50 @@ utoppyopen(dev_t dev, int flag, int mode @@ -1355,53 +1355,50 @@ utoppyopen(dev_t dev, int flag, int mode
1355 "'%s'\n", device_xname(sc->sc_dev), error, 1355 "'%s'\n", device_xname(sc->sc_dev), error,
1356 utoppy_state_string(sc->sc_state))); 1356 utoppy_state_string(sc->sc_state)));
1357 1357
1358 if (--sc->sc_refcnt < 0) 1358 if (--sc->sc_refcnt < 0)
1359 usb_detach_wakeupold(sc->sc_dev); 1359 usb_detach_wakeupold(sc->sc_dev);
1360 1360
1361 return error; 1361 return error;
1362} 1362}
1363 1363
1364static int 1364static int
1365utoppyclose(dev_t dev, int flag, int mode, struct lwp *l) 1365utoppyclose(dev_t dev, int flag, int mode, struct lwp *l)
1366{ 1366{
1367 struct utoppy_softc *sc; 1367 struct utoppy_softc *sc;
1368 usbd_status err; 
1369 1368
1370 sc = device_lookup_private(&utoppy_cd, UTOPPYUNIT(dev)); 1369 sc = device_lookup_private(&utoppy_cd, UTOPPYUNIT(dev));
1371 1370
1372 DPRINTF(UTOPPY_DBG_CLOSE, ("%s: utoppyclose: closing...\n", 1371 DPRINTF(UTOPPY_DBG_CLOSE, ("%s: utoppyclose: closing...\n",
1373 device_xname(sc->sc_dev))); 1372 device_xname(sc->sc_dev)));
1374 1373
1375 if (sc->sc_state < UTOPPY_STATE_IDLE) { 1374 if (sc->sc_state < UTOPPY_STATE_IDLE) {
1376 /* We are being forced to close before the open completed. */ 1375 /* We are being forced to close before the open completed. */
1377 DPRINTF(UTOPPY_DBG_CLOSE, ("%s: utoppyclose: not properly " 1376 DPRINTF(UTOPPY_DBG_CLOSE, ("%s: utoppyclose: not properly "
1378 "open: %s\n", device_xname(sc->sc_dev), 1377 "open: %s\n", device_xname(sc->sc_dev),
1379 utoppy_state_string(sc->sc_state))); 1378 utoppy_state_string(sc->sc_state)));
1380 return 0; 1379 return 0;
1381 } 1380 }
1382 1381
1383 if (sc->sc_out_data) 1382 if (sc->sc_out_data)
1384 (void) utoppy_cancel(sc); 1383 (void) utoppy_cancel(sc);
1385 1384
1386 if (sc->sc_out_pipe != NULL) { 1385 if (sc->sc_out_pipe != NULL) {
1387 if ((err = usbd_abort_pipe(sc->sc_out_pipe)) != 0) 1386 usbd_abort_pipe(sc->sc_out_pipe);
1388 printf("usbd_abort_pipe(OUT) returned %d\n", err); 
1389 sc->sc_out_pipe = NULL; 1387 sc->sc_out_pipe = NULL;
1390 } 1388 }
1391 1389
1392 if (sc->sc_in_pipe != NULL) { 1390 if (sc->sc_in_pipe != NULL) {
1393 if ((err = usbd_abort_pipe(sc->sc_in_pipe)) != 0) 1391 usbd_abort_pipe(sc->sc_in_pipe);
1394 printf("usbd_abort_pipe(IN) returned %d\n", err); 
1395 sc->sc_in_pipe = NULL; 1392 sc->sc_in_pipe = NULL;
1396 } 1393 }
1397 1394
1398 if (sc->sc_out_data) { 1395 if (sc->sc_out_data) {
1399 kmem_free(sc->sc_out_data, UTOPPY_BSIZE + 1); 1396 kmem_free(sc->sc_out_data, UTOPPY_BSIZE + 1);
1400 sc->sc_out_data = NULL; 1397 sc->sc_out_data = NULL;
1401 } 1398 }
1402 1399
1403 if (sc->sc_in_data) { 1400 if (sc->sc_in_data) {
1404 kmem_free(sc->sc_in_data, UTOPPY_BSIZE + 1); 1401 kmem_free(sc->sc_in_data, UTOPPY_BSIZE + 1);
1405 sc->sc_in_data = NULL; 1402 sc->sc_in_data = NULL;
1406 } 1403 }
1407 1404