diff --git a/sys/dev/ic/bwfm.c b/sys/dev/ic/bwfm.c index f9e66a46ba55..5be22a11aa00 100644 --- a/sys/dev/ic/bwfm.c +++ b/sys/dev/ic/bwfm.c @@ -337,7 +337,7 @@ bwfm_start(struct ifnet *ifp) continue; } - error = sc->sc_bus_ops->bs_txdata(sc, m); + error = sc->sc_bus_ops->bs_txdata(sc, &m); if (error == ENOBUFS) { IF_PREPEND(&ifp->if_snd, m); ifp->if_flags |= IFF_OACTIVE; diff --git a/sys/dev/ic/bwfmvar.h b/sys/dev/ic/bwfmvar.h index e836152d0d7c..1dbc3f22cf7f 100644 --- a/sys/dev/ic/bwfmvar.h +++ b/sys/dev/ic/bwfmvar.h @@ -93,7 +93,7 @@ struct bwfm_bus_ops { void (*bs_init)(struct bwfm_softc *); void (*bs_stop)(struct bwfm_softc *); int (*bs_txcheck)(struct bwfm_softc *); - int (*bs_txdata)(struct bwfm_softc *, struct mbuf *); + int (*bs_txdata)(struct bwfm_softc *, struct mbuf **); int (*bs_txctl)(struct bwfm_softc *, char *, size_t); int (*bs_rxctl)(struct bwfm_softc *, char *, size_t *); }; diff --git a/sys/dev/pci/if_bwfm_pci.c b/sys/dev/pci/if_bwfm_pci.c index 696b8382f81c..b30d585ce83a 100644 --- a/sys/dev/pci/if_bwfm_pci.c +++ b/sys/dev/pci/if_bwfm_pci.c @@ -225,7 +225,7 @@ void bwfm_pci_dmamem_free(struct bwfm_pci_softc *, struct bwfm_pci_dmamem *); int bwfm_pci_pktid_avail(struct bwfm_pci_softc *, struct bwfm_pci_pkts *); int bwfm_pci_pktid_new(struct bwfm_pci_softc *, - struct bwfm_pci_pkts *, struct mbuf *, + struct bwfm_pci_pkts *, struct mbuf **, uint32_t *, paddr_t *); struct mbuf * bwfm_pci_pktid_free(struct bwfm_pci_softc *, struct bwfm_pci_pkts *, uint32_t); @@ -281,7 +281,7 @@ void bwfm_pci_flowring_delete(struct bwfm_pci_softc *, int); void bwfm_pci_stop(struct bwfm_softc *); int bwfm_pci_txcheck(struct bwfm_softc *); -int bwfm_pci_txdata(struct bwfm_softc *, struct mbuf *); +int bwfm_pci_txdata(struct bwfm_softc *, struct mbuf **); #ifdef BWFM_DEBUG void bwfm_pci_debug_console(struct bwfm_pci_softc *); @@ -922,7 +922,7 @@ bwfm_pci_pktid_avail(struct bwfm_pci_softc *sc, struct bwfm_pci_pkts *pkts) int bwfm_pci_pktid_new(struct bwfm_pci_softc *sc, struct bwfm_pci_pkts *pkts, - struct mbuf *m, uint32_t *pktid, paddr_t *paddr) + struct mbuf **mp, uint32_t *pktid, paddr_t *paddr) { int i, idx; @@ -932,15 +932,30 @@ bwfm_pci_pktid_new(struct bwfm_pci_softc *sc, struct bwfm_pci_pkts *pkts, idx = 0; if (pkts->pkts[idx].bb_m == NULL) { if (bus_dmamap_load_mbuf(sc->sc_dmat, - pkts->pkts[idx].bb_map, m, BUS_DMA_NOWAIT) != 0) { - if (m_defrag(m, M_DONTWAIT)) - return EFBIG; + pkts->pkts[idx].bb_map, *mp, BUS_DMA_NOWAIT) != 0) { + /* + * Didn't fit. Maybe it has too many + * segments. If it has only one + * segment, fail; otherwise try to + * compact it into a single mbuf + * segment. + */ + if ((*mp)->m_next == NULL) + return ENOBUFS; + struct mbuf *m0 = MCLGETI(NULL, M_DONTWAIT, + NULL, MSGBUF_MAX_PKT_SIZE); + if (m0 == NULL) + return ENOBUFS; + m_copydata(*mp, 0, (*mp)->m_pkthdr.len, + mtod(m0, void *)); + m_freem(*mp); + *mp = m0; if (bus_dmamap_load_mbuf(sc->sc_dmat, - pkts->pkts[idx].bb_map, m, BUS_DMA_NOWAIT) != 0) + pkts->pkts[idx].bb_map, *mp, BUS_DMA_NOWAIT) != 0) return EFBIG; } pkts->last = idx; - pkts->pkts[idx].bb_m = m; + pkts->pkts[idx].bb_m = *mp; *pktid = idx; *paddr = pkts->pkts[idx].bb_map->dm_segs[0].ds_addr; return 0; @@ -997,7 +1012,7 @@ bwfm_pci_fill_rx_ioctl_ring(struct bwfm_pci_softc *sc, struct if_rxring *rxring, break; } m->m_len = m->m_pkthdr.len = MSGBUF_MAX_PKT_SIZE; - if (bwfm_pci_pktid_new(sc, &sc->sc_rx_pkts, m, &pktid, &paddr)) { + if (bwfm_pci_pktid_new(sc, &sc->sc_rx_pkts, &m, &pktid, &paddr)) { bwfm_pci_ring_write_cancel(sc, &sc->sc_ctrl_submit, 1); m_freem(m); break; @@ -1037,7 +1052,7 @@ bwfm_pci_fill_rx_buf_ring(struct bwfm_pci_softc *sc) break; } m->m_len = m->m_pkthdr.len = MSGBUF_MAX_PKT_SIZE; - if (bwfm_pci_pktid_new(sc, &sc->sc_rx_pkts, m, &pktid, &paddr)) { + if (bwfm_pci_pktid_new(sc, &sc->sc_rx_pkts, &m, &pktid, &paddr)) { bwfm_pci_ring_write_cancel(sc, &sc->sc_rxpost_submit, 1); m_freem(m); break; @@ -1388,7 +1403,7 @@ bwfm_pci_msg_rx(struct bwfm_pci_softc *sc, void *buf) if (ring->m != NULL) { m = ring->m; ring->m = NULL; - if (bwfm_pci_txdata(&sc->sc_sc, m)) + if (bwfm_pci_txdata(&sc->sc_sc, &m)) m_freem(ring->m); } ifp->if_flags &= ~IFF_OACTIVE; @@ -1851,7 +1866,7 @@ bwfm_pci_txcheck(struct bwfm_softc *bwfm) } int -bwfm_pci_txdata(struct bwfm_softc *bwfm, struct mbuf *m) +bwfm_pci_txdata(struct bwfm_softc *bwfm, struct mbuf **mp) { struct bwfm_pci_softc *sc = (void *)bwfm; struct bwfm_pci_msgring *ring; @@ -1861,7 +1876,7 @@ bwfm_pci_txdata(struct bwfm_softc *bwfm, struct mbuf *m) struct ether_header *eh; int flowid, ret, ac; - flowid = bwfm_pci_flowring_lookup(sc, m); + flowid = bwfm_pci_flowring_lookup(sc, *mp); if (flowid < 0) { /* * We cannot send the packet right now as there is @@ -1872,7 +1887,7 @@ bwfm_pci_txdata(struct bwfm_softc *bwfm, struct mbuf *m) * is created the queue will be restarted and this * mbuf will be transmitted. */ - bwfm_pci_flowring_create(sc, m); + bwfm_pci_flowring_create(sc, *mp); return 0; } @@ -1890,9 +1905,9 @@ bwfm_pci_txdata(struct bwfm_softc *bwfm, struct mbuf *m) return ENOBUFS; /* No QoS for EAPOL frames. */ - eh = mtod(m, struct ether_header *); + eh = mtod(*mp, struct ether_header *); ac = (eh->ether_type != htons(ETHERTYPE_PAE)) ? - M_WME_GETAC(m) : WME_AC_BE; + M_WME_GETAC(*mp) : WME_AC_BE; memset(tx, 0, sizeof(*tx)); tx->msg.msgtype = MSGBUF_TYPE_TX_POST; @@ -1900,9 +1915,9 @@ bwfm_pci_txdata(struct bwfm_softc *bwfm, struct mbuf *m) tx->flags = BWFM_MSGBUF_PKT_FLAGS_FRAME_802_3; tx->flags |= ac << BWFM_MSGBUF_PKT_FLAGS_PRIO_SHIFT; tx->seg_cnt = 1; - memcpy(tx->txhdr, mtod(m, char *), ETHER_HDR_LEN); + memcpy(tx->txhdr, mtod(*mp, char *), ETHER_HDR_LEN); - ret = bwfm_pci_pktid_new(sc, &sc->sc_tx_pkts, m, &pktid, &paddr); + ret = bwfm_pci_pktid_new(sc, &sc->sc_tx_pkts, mp, &pktid, &paddr); if (ret) { if (ret == ENOBUFS) { printf("%s: no pktid available for TX\n", @@ -1915,7 +1930,7 @@ bwfm_pci_txdata(struct bwfm_softc *bwfm, struct mbuf *m) paddr += ETHER_HDR_LEN; tx->msg.request_id = htole32(pktid); - tx->data_len = htole16(m->m_len - ETHER_HDR_LEN); + tx->data_len = htole16((*mp)->m_len - ETHER_HDR_LEN); tx->data_buf_addr.high_addr = htole32(paddr >> 32); tx->data_buf_addr.low_addr = htole32(paddr & 0xffffffff); diff --git a/sys/dev/usb/if_bwfm_usb.c b/sys/dev/usb/if_bwfm_usb.c index f264b3e746e9..d1a44ed7679f 100644 --- a/sys/dev/usb/if_bwfm_usb.c +++ b/sys/dev/usb/if_bwfm_usb.c @@ -203,7 +203,7 @@ int bwfm_usb_alloc_tx_list(struct bwfm_usb_softc *); void bwfm_usb_free_tx_list(struct bwfm_usb_softc *); int bwfm_usb_txcheck(struct bwfm_softc *); -int bwfm_usb_txdata(struct bwfm_softc *, struct mbuf *); +int bwfm_usb_txdata(struct bwfm_softc *, struct mbuf **); int bwfm_usb_txctl(struct bwfm_softc *, char *, size_t); int bwfm_usb_rxctl(struct bwfm_softc *, char *, size_t *); @@ -785,9 +785,10 @@ bwfm_usb_txcheck(struct bwfm_softc *bwfm) int -bwfm_usb_txdata(struct bwfm_softc *bwfm, struct mbuf *m) +bwfm_usb_txdata(struct bwfm_softc *bwfm, struct mbuf **mp) { struct bwfm_usb_softc *sc = (void *)bwfm; + struct mbuf *m = *mp; struct bwfm_proto_bcdc_hdr *hdr; struct bwfm_usb_tx_data *data; struct ether_header *eh;