diff options
author | jlemon <jlemon@FreeBSD.org> | 2000-11-25 07:35:38 +0000 |
---|---|---|
committer | jlemon <jlemon@FreeBSD.org> | 2000-11-25 07:35:38 +0000 |
commit | 954e1d2ccdb661d5c8b7f69340d118fa7ba7fb85 (patch) | |
tree | 0a4e9f6dcd5fa64a78f5991ac425f3ca97aba154 /sys/dev/usb | |
parent | 2daca11cae375091daf49a7cd704e5e4e1be27db (diff) | |
download | FreeBSD-src-954e1d2ccdb661d5c8b7f69340d118fa7ba7fb85.zip FreeBSD-src-954e1d2ccdb661d5c8b7f69340d118fa7ba7fb85.tar.gz |
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
Diffstat (limited to 'sys/dev/usb')
-rw-r--r-- | sys/dev/usb/udbp.c | 23 | ||||
-rw-r--r-- | sys/dev/usb/usb_ethersubr.c | 14 |
2 files changed, 12 insertions, 25 deletions
diff --git a/sys/dev/usb/udbp.c b/sys/dev/usb/udbp.c index 71eb710..d75e1f2 100644 --- a/sys/dev/usb/udbp.c +++ b/sys/dev/usb/udbp.c @@ -359,6 +359,8 @@ USB_ATTACH(udbp) sc->node->private = sc; sc->xmitq.ifq_maxlen = IFQ_MAXLEN; sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN; + mtx_init(&sc->xmitq.ifq_mtx, "usb_xmitq", MTX_DEF); + mtx_init(&sc->xmitq_hipri.ifq_mtx, "usb_xmitq_hipri", MTX_DEF); sprintf(nodename, "%s", USBDEVNAME(sc->sc_dev)); if ((err = ng_name_node(sc->node, nodename))) { ng_rmnode(sc->node); @@ -737,13 +739,16 @@ ng_udbp_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, xmitq_p = (&sc->xmitq); } s = splusb(); - if (IF_QFULL(xmitq_p)) { - IF_DROP(xmitq_p); + IF_LOCK(xmitq_p); + if (_IF_QFULL(xmitq_p)) { + _IF_DROP(xmitq_p); + IF_UNLOCK(xmitq_p); splx(s); error = ENOBUFS; goto bad; } - IF_ENQUEUE(xmitq_p, m); + _IF_ENQUEUE(xmitq_p, m); + IF_UNLOCK(xmitq_p); if (!(sc->flags & OUT_BUSY)) udbp_setup_out_transfer(sc); splx(s); @@ -772,16 +777,8 @@ ng_udbp_rmnode(node_p node) ng_cutlinks(node); /* Drain the queues */ - do { - IF_DEQUEUE(&sc->xmitq_hipri, m); - if (m) - m_freem(m); - } while (m); - do { - IF_DEQUEUE(&sc->xmitq, m); - if (m) - m_freem(m); - } while (m); + IF_DRAIN(&sc->xmitq_hipri); + IF_DRAIN(&sc->xmitq); sc->packets_in = 0; /* reset stats */ sc->packets_out = 0; diff --git a/sys/dev/usb/usb_ethersubr.c b/sys/dev/usb/usb_ethersubr.c index c02ed7d..3065c47 100644 --- a/sys/dev/usb/usb_ethersubr.c +++ b/sys/dev/usb/usb_ethersubr.c @@ -73,9 +73,7 @@ Static const char rcsid[] = #endif Static struct ifqueue usbq_rx; -Static struct mtx usbq_rx_mtx; Static struct ifqueue usbq_tx; -Static struct mtx usbq_tx_mtx; Static int mtx_inited = 0; Static void usbintr __P((void)); @@ -89,9 +87,7 @@ Static void usbintr() /* Check the RX queue */ while(1) { - mtx_enter(&usbq_rx_mtx, MTX_DEF); IF_DEQUEUE(&usbq_rx, m); - mtx_exit(&usbq_rx_mtx, MTX_DEF); if (m == NULL) break; eh = mtod(m, struct ether_header *); @@ -109,9 +105,7 @@ Static void usbintr() /* Check the TX queue */ while(1) { - mtx_enter(&usbq_tx_mtx, MTX_DEF); IF_DEQUEUE(&usbq_tx, m); - mtx_exit(&usbq_tx_mtx, MTX_DEF); if (m == NULL) break; ifp = m->m_pkthdr.rcvif; @@ -128,8 +122,8 @@ void usb_register_netisr() if (mtx_inited) return; register_netisr(NETISR_USB, usbintr); - mtx_init(&usbq_tx_mtx, "usbq_tx_mtx", MTX_DEF); - mtx_init(&usbq_rx_mtx, "usbq_rx_mtx", MTX_DEF); + mtx_init(&usbq_tx.ifq_mtx, "usbq_tx_mtx", MTX_DEF); + mtx_init(&usbq_rx.ifq_mtx, "usbq_rx_mtx", MTX_DEF); mtx_inited++; return; } @@ -141,9 +135,7 @@ void usb_register_netisr() void usb_ether_input(m) struct mbuf *m; { - mtx_enter(&usbq_rx_mtx, MTX_DEF); IF_ENQUEUE(&usbq_rx, m); - mtx_exit(&usbq_rx_mtx, MTX_DEF); schednetisr(NETISR_USB); return; @@ -152,9 +144,7 @@ void usb_ether_input(m) void usb_tx_done(m) struct mbuf *m; { - mtx_enter(&usbq_tx_mtx, MTX_DEF); IF_ENQUEUE(&usbq_tx, m); - mtx_exit(&usbq_tx_mtx, MTX_DEF); schednetisr(NETISR_USB); return; |