diff --git a/sys/conf/files b/sys/conf/files index 6427b6e86d48..e2565189b6dc 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -884,6 +884,7 @@ dev/usb/usb.c optional usb dev/usb/usbdi.c optional usb dev/usb/usbdi_util.c optional usb #dev/usb/usb_mem.c optional usb +dev/usb/usb_ethersubr.c optional usb dev/usb/usb_subr.c optional usb dev/usb/usb_quirks.c optional usb dev/usb/hid.c optional usb diff --git a/sys/dev/usb/if_aue.c b/sys/dev/usb/if_aue.c index c8c204c715eb..66ef16ba1596 100644 --- a/sys/dev/usb/if_aue.c +++ b/sys/dev/usb/if_aue.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 1998, 1999 + * Copyright (c) 1997, 1998, 1999, 2000 * Bill Paul . All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -77,21 +77,15 @@ #include -#include /* for vtophys */ -#include /* for vtophys */ #include /* for DELAY */ -#include -#include -#include -#include #include -#include #include #include #include #include #include +#include #include #include @@ -688,6 +682,7 @@ USB_ATTACH(aue) ether_ifattach(ifp); callout_handle_init(&sc->aue_stat_ch); bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); + usb_register_netisr(); splx(s); USB_ATTACH_SUCCESS_RETURN; @@ -879,24 +874,17 @@ static void aue_rxeof(xfer, priv, status) struct ifnet *ifp; int total_len = 0; struct aue_rxpkt r; - int s; - - s = splimp(); c = priv; sc = c->aue_sc; ifp = &sc->arpcom.ac_if; - if (!(ifp->if_flags & IFF_RUNNING)) { + if (!(ifp->if_flags & IFF_RUNNING)) return; - splx(s); - } if (status != USBD_NORMAL_COMPLETION) { - if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { - splx(s); + if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) return; - } printf("aue%d: usb error on rx: %s\n", sc->aue_unit, usbd_errstr(status)); if (status == USBD_STALLED) @@ -938,7 +926,6 @@ static void aue_rxeof(xfer, priv, status) AUE_CUTOFF, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, aue_rxeof); usbd_transfer(xfer); - splx(s); return; } @@ -976,9 +963,8 @@ static void aue_rxeof(xfer, priv, status) } } - /* Remove header from mbuf and pass it on. */ - m_adj(m, sizeof(struct ether_header)); - ether_input(ifp, eh, m); + /* Put the packet on the special USB input queue. */ + usb_ether_input(m); done: @@ -988,8 +974,6 @@ static void aue_rxeof(xfer, priv, status) USBD_NO_TIMEOUT, aue_rxeof); usbd_transfer(xfer); - splx(s); - return; } diff --git a/sys/dev/usb/if_kue.c b/sys/dev/usb/if_kue.c index 0167d9e75e57..2371a879c393 100644 --- a/sys/dev/usb/if_kue.c +++ b/sys/dev/usb/if_kue.c @@ -80,15 +80,8 @@ #include -#include /* for vtophys */ -#include /* for vtophys */ #include /* for DELAY */ -#include -#include -#include -#include #include -#include #include #include @@ -96,6 +89,7 @@ #include #include #include +#include #include #include @@ -516,6 +510,7 @@ USB_ATTACH(kue) if_attach(ifp); ether_ifattach(ifp); bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); + usb_register_netisr(); splx(s); USB_ATTACH_SUCCESS_RETURN; @@ -654,24 +649,17 @@ static void kue_rxeof(xfer, priv, status) struct ifnet *ifp; int total_len = 0; u_int16_t len; - int s; - - s = splimp(); c = priv; sc = c->kue_sc; ifp = &sc->arpcom.ac_if; - if (!(ifp->if_flags & IFF_RUNNING)) { + if (!(ifp->if_flags & IFF_RUNNING)) return; - splx(s); - } if (status != USBD_NORMAL_COMPLETION) { - if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { - splx(s); + if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) return; - } printf("kue%d: usb error on rx: %s\n", sc->kue_unit, usbd_errstr(status)); if (status == USBD_STALLED) @@ -715,9 +703,8 @@ static void kue_rxeof(xfer, priv, status) } } - /* Remove header from mbuf and pass it on. */ - m_adj(m, sizeof(struct ether_header)); - ether_input(ifp, eh, m); + /* Put the packet on the special USB input queue. */ + usb_ether_input(m); done: @@ -727,8 +714,6 @@ static void kue_rxeof(xfer, priv, status) USBD_NO_TIMEOUT, kue_rxeof); usbd_transfer(xfer); - splx(s); - return; } diff --git a/sys/dev/usb/usb_ethersubr.c b/sys/dev/usb/usb_ethersubr.c new file mode 100644 index 000000000000..ded747e61edb --- /dev/null +++ b/sys/dev/usb/usb_ethersubr.c @@ -0,0 +1,118 @@ +/* + * Copyright (c) 1997, 1998, 1999, 2000 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Callbacks in the USB code operate at splusb() (actually splbio() + * in FreeBSD). However adding packets to the input queues has to be + * done at splimp(). It is conceivable that this arrangement could + * trigger a condition where the splimp() is ignored and the input + * queues could get trampled in spite of our best effors to prevent + * it. To work around this, we implement a special input queue for + * USB ethernet adapter drivers. Rather than passing the frames directly + * to ether_input(), we pass them here, then schedule a soft interrupt + * to hand them to ether_input() later, outside of the USB interrupt + * context. + * + * It's questional as to whether this code should be expanded to + * handle other kinds of devices, or handle USB transfer callbacks + * in general. Right now, I need USB network interfaces to work + * properly. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#ifndef lint +static const char rcsid[] = + "$FreeBSD$"; +#endif + +static struct ifqueue usbq; + +static void usbintr __P((void)); + +static void usbintr() +{ + struct ether_header *eh; + struct mbuf *m; + int s; + + s = splimp(); + + while(1) { + IF_DEQUEUE(&usbq, m); + if (m == NULL) + break; + eh = mtod(m, struct ether_header *); + m_adj(m, sizeof(struct ether_header)); + ether_input(m->m_pkthdr.rcvif, eh, m); + } + + splx(s); + + return; +} + +void usb_register_netisr() +{ + register_netisr(NETISR_USB, usbintr); + return; +} + +/* + * Must be called at splusp() (actually splbio()). This should be + * the case when called from a transfer callback routine. + */ +void usb_ether_input(m) + struct mbuf *m; +{ + int s; + s = splimp(); + IF_ENQUEUE(&usbq, m); + schednetisr(NETISR_USB); + splx(s); + return; +} diff --git a/sys/dev/usb/usb_ethersubr.h b/sys/dev/usb/usb_ethersubr.h new file mode 100644 index 000000000000..f137c3e0f300 --- /dev/null +++ b/sys/dev/usb/usb_ethersubr.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 1997, 1998, 1999, 2000 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _USB_ETHERSUBR_H_ +#define _USB_ETHERSUBR_H_ + +#ifndef NETISR_USB +#define NETISR_USB 25 +#endif + +void usb_register_netisr __P((void)); +void usb_ether_input __P((struct mbuf *)); + +#endif diff --git a/sys/modules/usb/Makefile b/sys/modules/usb/Makefile index e372b737dd8b..ff49f8914088 100644 --- a/sys/modules/usb/Makefile +++ b/sys/modules/usb/Makefile @@ -17,7 +17,8 @@ SRCS = bus_if.h device_if.h usb_if.h usb_if.c \ usb_subr.c \ usbdevs.h usbdevs_data.h \ usbdi.c usbdi.h usbdivar.h \ - usbdi_util.c usbdi_util.h + usbdi_util.c usbdi_util.h \ + usb_ethersubr.c SRCS += uhci_pci.c uhci.c uhcireg.h uhcivar.h SRCS += ohci_pci.c ohci.c ohcireg.h ohcivar.h diff --git a/sys/net/netisr.h b/sys/net/netisr.h index b1e32f39e3e9..563c4ec6b0d2 100644 --- a/sys/net/netisr.h +++ b/sys/net/netisr.h @@ -64,6 +64,7 @@ #define NETISR_ATALK 16 /* same as AF_APPLETALK */ #define NETISR_ARP 18 /* same as AF_LINK */ #define NETISR_IPX 23 /* same as AF_IPX */ +#define NETISR_USB 25 /* USB soft interrupt */ #define NETISR_ISDN 26 /* same as AF_E164 */ #define NETISR_PPP 27 /* PPP soft interrupt */ #define NETISR_IPV6 28 /* same as AF_INET6 */