| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if_aue.c,v 1.143 2018/06/26 06:48:02 msaitoh Exp $ */ | | 1 | /* $NetBSD: if_aue.c,v 1.144 2018/07/29 02:00:17 riastradh Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1997, 1998, 1999, 2000 | | 4 | * Copyright (c) 1997, 1998, 1999, 2000 |
5 | * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. | | 5 | * Bill Paul <wpaul@ee.columbia.edu>. 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. |
| @@ -68,27 +68,27 @@ | | | @@ -68,27 +68,27 @@ |
68 | */ | | 68 | */ |
69 | | | 69 | |
70 | /* | | 70 | /* |
71 | * TODO: | | 71 | * TODO: |
72 | * better error messages from rxstat | | 72 | * better error messages from rxstat |
73 | * split out if_auevar.h | | 73 | * split out if_auevar.h |
74 | * add thread to avoid register reads from interrupt context | | 74 | * add thread to avoid register reads from interrupt context |
75 | * more error checks | | 75 | * more error checks |
76 | * investigate short rx problem | | 76 | * investigate short rx problem |
77 | * proper cleanup on errors | | 77 | * proper cleanup on errors |
78 | */ | | 78 | */ |
79 | | | 79 | |
80 | #include <sys/cdefs.h> | | 80 | #include <sys/cdefs.h> |
81 | __KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.143 2018/06/26 06:48:02 msaitoh Exp $"); | | 81 | __KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.144 2018/07/29 02:00:17 riastradh Exp $"); |
82 | | | 82 | |
83 | #ifdef _KERNEL_OPT | | 83 | #ifdef _KERNEL_OPT |
84 | #include "opt_usb.h" | | 84 | #include "opt_usb.h" |
85 | #include "opt_inet.h" | | 85 | #include "opt_inet.h" |
86 | #endif | | 86 | #endif |
87 | | | 87 | |
88 | #include <sys/param.h> | | 88 | #include <sys/param.h> |
89 | #include <sys/systm.h> | | 89 | #include <sys/systm.h> |
90 | #include <sys/sockio.h> | | 90 | #include <sys/sockio.h> |
91 | #include <sys/mutex.h> | | 91 | #include <sys/mutex.h> |
92 | #include <sys/mbuf.h> | | 92 | #include <sys/mbuf.h> |
93 | #include <sys/kernel.h> | | 93 | #include <sys/kernel.h> |
94 | #include <sys/socket.h> | | 94 | #include <sys/socket.h> |
| @@ -876,33 +876,36 @@ int | | | @@ -876,33 +876,36 @@ int |
876 | aue_detach(device_t self, int flags) | | 876 | aue_detach(device_t self, int flags) |
877 | { | | 877 | { |
878 | struct aue_softc *sc = device_private(self); | | 878 | struct aue_softc *sc = device_private(self); |
879 | struct ifnet *ifp = GET_IFP(sc); | | 879 | struct ifnet *ifp = GET_IFP(sc); |
880 | int s; | | 880 | int s; |
881 | | | 881 | |
882 | DPRINTFN(2,("%s: %s: enter\n", device_xname(sc->aue_dev), __func__)); | | 882 | DPRINTFN(2,("%s: %s: enter\n", device_xname(sc->aue_dev), __func__)); |
883 | | | 883 | |
884 | if (!sc->aue_attached) { | | 884 | if (!sc->aue_attached) { |
885 | /* Detached before attached finished, so just bail out. */ | | 885 | /* Detached before attached finished, so just bail out. */ |
886 | return 0; | | 886 | return 0; |
887 | } | | 887 | } |
888 | | | 888 | |
889 | callout_stop(&sc->aue_stat_ch); | | | |
890 | /* | | 889 | /* |
891 | * Remove any pending tasks. They cannot be executing because they run | | 890 | * XXX Halting callout guarantees no more tick tasks. What |
892 | * in the same thread as detach. | | 891 | * guarantees no more stop tasks? What guarantees no more |
| | | 892 | * calls to aue_send? Don't we need to wait for if_detach or |
| | | 893 | * something? Should we set sc->aue_dying here? Is device |
| | | 894 | * deactivation guaranteed to have already happened? |
893 | */ | | 895 | */ |
894 | usb_rem_task(sc->aue_udev, &sc->aue_tick_task); | | 896 | callout_halt(&sc->aue_stat_ch, NULL); |
895 | usb_rem_task(sc->aue_udev, &sc->aue_stop_task); | | 897 | usb_rem_task_wait(sc->aue_udev, &sc->aue_tick_task, USB_TASKQ_DRIVER); |
| | | 898 | usb_rem_task_wait(sc->aue_udev, &sc->aue_stop_task, USB_TASKQ_DRIVER); |
896 | | | 899 | |
897 | sc->aue_closing = 1; | | 900 | sc->aue_closing = 1; |
898 | cv_signal(&sc->aue_domc); | | 901 | cv_signal(&sc->aue_domc); |
899 | | | 902 | |
900 | mutex_enter(&sc->aue_mcmtx); | | 903 | mutex_enter(&sc->aue_mcmtx); |
901 | cv_wait(&sc->aue_closemc,&sc->aue_mcmtx); | | 904 | cv_wait(&sc->aue_closemc,&sc->aue_mcmtx); |
902 | mutex_exit(&sc->aue_mcmtx); | | 905 | mutex_exit(&sc->aue_mcmtx); |
903 | | | 906 | |
904 | mutex_destroy(&sc->aue_mcmtx); | | 907 | mutex_destroy(&sc->aue_mcmtx); |
905 | cv_destroy(&sc->aue_domc); | | 908 | cv_destroy(&sc->aue_domc); |
906 | cv_destroy(&sc->aue_closemc); | | 909 | cv_destroy(&sc->aue_closemc); |
907 | | | 910 | |
908 | s = splusb(); | | 911 | s = splusb(); |