Module Name: src Committed By: mrg Date: Fri Aug 16 08:38:21 UTC 2019
Modified Files: src/sys/dev/usb: usbnet.c Log Message: internal to usbnet: add buflen param to usbnet_newbuf(). use this to skip allocating an mbuf cluster for small packets (ported from kue(4).) remove usbnet_rx_start_pipes()'s always usbnet_rxeof argument. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/dev/usb/usbnet.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/usb/usbnet.c diff -u src/sys/dev/usb/usbnet.c:1.15 src/sys/dev/usb/usbnet.c:1.16 --- src/sys/dev/usb/usbnet.c:1.15 Thu Aug 15 05:52:23 2019 +++ src/sys/dev/usb/usbnet.c Fri Aug 16 08:38:21 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: usbnet.c,v 1.15 2019/08/15 05:52:23 mrg Exp $ */ +/* $NetBSD: usbnet.c,v 1.16 2019/08/16 08:38:21 mrg Exp $ */ /* * Copyright (c) 2019 Matthew R. Green @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.15 2019/08/15 05:52:23 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.16 2019/08/16 08:38:21 mrg Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -211,7 +211,7 @@ uno_intr(struct usbnet *un, usbd_status /* Interrupt handling. */ static struct mbuf * -usbnet_newbuf(void) +usbnet_newbuf(size_t buflen) { struct mbuf *m; @@ -219,14 +219,16 @@ usbnet_newbuf(void) if (m == NULL) return NULL; - MCLGET(m, M_DONTWAIT); - if (!(m->m_flags & M_EXT)) { - m_freem(m); - return NULL; + if (buflen > MHLEN - ETHER_ALIGN) { + MCLGET(m, M_DONTWAIT); + if (!(m->m_flags & M_EXT)) { + m_freem(m); + return NULL; + } } - m->m_len = m->m_pkthdr.len = MCLBYTES; m_adj(m, ETHER_ALIGN); + m->m_len = m->m_pkthdr.len = buflen; return m; } @@ -248,18 +250,17 @@ usbnet_enqueue(struct usbnet * const un, usbnet_isowned_rx(un); - m = usbnet_newbuf(); + m = usbnet_newbuf(buflen); if (m == NULL) { ifp->if_ierrors++; return; } m_set_rcvif(m, ifp); - m->m_pkthdr.len = m->m_len = buflen; m->m_pkthdr.csum_flags = csum_flags; m->m_pkthdr.csum_data = csum_data; m->m_flags |= mbuf_flags; - memcpy(mtod(m, char *), buf, buflen); + memcpy(mtod(m, uint8_t *), buf, buflen); /* push the packet up */ if_percpuq_enqueue(ifp->if_percpuq, m); @@ -274,14 +275,13 @@ usbnet_input(struct usbnet * const un, u usbnet_isowned_rx(un); - m = usbnet_newbuf(); + m = usbnet_newbuf(buflen); if (m == NULL) { ifp->if_ierrors++; return; } m_set_rcvif(m, ifp); - m->m_pkthdr.len = m->m_len = buflen; memcpy(mtod(m, char *), buf, buflen); /* push the packet up */ @@ -576,7 +576,7 @@ usbnet_rx_list_fini(struct usbnet * cons /* End of common RX functions */ static void -usbnet_rx_start_pipes(struct usbnet * const un, usbd_callback cb) +usbnet_rx_start_pipes(struct usbnet * const un) { struct usbnet_cdata * const cd = un_cdata(un); struct usbnet_private * const unp = un->un_pri; @@ -589,7 +589,7 @@ usbnet_rx_start_pipes(struct usbnet * co struct usbnet_chain *c = &cd->uncd_rx_chain[i]; usbd_setup_xfer(c->unc_xfer, c, c->unc_buf, un->un_rx_bufsz, - un->un_rx_xfer_flags, USBD_NO_TIMEOUT, cb); + un->un_rx_xfer_flags, USBD_NO_TIMEOUT, usbnet_rxeof); usbd_transfer(c->unc_xfer); } @@ -769,7 +769,7 @@ usbnet_init_rx_tx(struct usbnet * const } /* Start up the receive pipe(s). */ - usbnet_rx_start_pipes(un, usbnet_rxeof); + usbnet_rx_start_pipes(un); /* Indicate we are up and running. */ KASSERT(ifp->if_softc == NULL || IFNET_LOCKED(ifp));