this adds a pool backend for MCLGETI thats 2k+2 bytes in size, which
can be used on some very common nics that have annoying constraints
on their rx descriptors.

this in turn simplifies the code in those drivers and lets them
always operate on ETHER_ALIGN boundaries.

the pool is cheap, pages will only be allocated in it if something
asks for them, and it keeps this complexity out of the drivers.

ok?

Index: net/if.h
===================================================================
RCS file: /cvs/src/sys/net/if.h,v
retrieving revision 1.179
diff -u -p -r1.179 if.h
--- net/if.h    4 Sep 2016 15:10:59 -0000       1.179
+++ net/if.h    14 Oct 2016 03:46:22 -0000
@@ -68,7 +68,7 @@ struct if_clonereq {
        char    *ifcr_buffer;           /* buffer for cloner names */
 };
 
-#define MCLPOOLS       7               /* number of cluster pools */
+#define MCLPOOLS       8               /* number of cluster pools */
 
 struct if_rxring {
        int     rxr_adjusted;
Index: kern/uipc_mbuf.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.233
diff -u -p -r1.233 uipc_mbuf.c
--- kern/uipc_mbuf.c    10 Oct 2016 00:41:17 -0000      1.233
+++ kern/uipc_mbuf.c    14 Oct 2016 03:46:22 -0000
@@ -107,6 +107,7 @@ struct      pool mtagpool;
 /* mbuf cluster pools */
 u_int  mclsizes[MCLPOOLS] = {
        MCLBYTES,       /* must be at slot 0 */
+       MCLBYTES + 2,   /* ETHER_ALIGNED 2k mbufs */
        4 * 1024,
        8 * 1024,
        9 * 1024,
@@ -142,6 +143,7 @@ void
 mbinit(void)
 {
        int i;
+       unsigned int lowbits;
 
 #if DIAGNOSTIC
        if (mclsizes[0] != MCLBYTES)
@@ -158,9 +160,15 @@ mbinit(void)
            IPL_NET, 0, "mtagpl", NULL);
 
        for (i = 0; i < nitems(mclsizes); i++) {
-               snprintf(mclnames[i], sizeof(mclnames[0]), "mcl%dk",
-                   mclsizes[i] >> 10);
-               pool_init(&mclpools[i], mclsizes[i], 0, IPL_NET, 0,
+               lowbits = mclsizes[i] & ((1 << 10) - 1);
+               if (lowbits) {
+                       snprintf(mclnames[i], sizeof(mclnames[0]),
+                           "mcl%dk%u", mclsizes[i] >> 10, lowbits);
+               } else {
+                       snprintf(mclnames[i], sizeof(mclnames[0]), "mcl%dk",
+                           mclsizes[i] >> 10);
+               }
+               pool_init(&mclpools[i], mclsizes[i], 64, IPL_NET, 0,
                    mclnames[i], NULL);
                pool_set_constraints(&mclpools[i], &kp_dma_contig);
                pool_setlowat(&mclpools[i], mcllowat);
Index: dev/pci/if_em.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_em.c,v
retrieving revision 1.331
diff -u -p -r1.331 if_em.c
--- dev/pci/if_em.c     13 Apr 2016 10:34:32 -0000      1.331
+++ dev/pci/if_em.c     14 Oct 2016 03:47:21 -0000
@@ -2450,9 +2450,7 @@ em_get_buf(struct em_softc *sc, int i)
                return (ENOBUFS);
        }
        m->m_len = m->m_pkthdr.len = EM_MCLBYTES;
-#ifdef __STRICT_ALIGNMENT
        m_adj(m, ETHER_ALIGN);
-#endif
 
        error = bus_dmamap_load_mbuf(sc->sc_dmat, pkt->pkt_map,
            m, BUS_DMA_NOWAIT);
Index: dev/pci/if_ix.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.132
diff -u -p -r1.132 if_ix.c
--- dev/pci/if_ix.c     13 Apr 2016 10:34:32 -0000      1.132
+++ dev/pci/if_ix.c     14 Oct 2016 03:47:21 -0000
@@ -616,11 +616,7 @@ ixgbe_init(void *arg)
        ixgbe_initialize_transmit_units(sc);
 
        /* Use 2k clusters, even for jumbo frames */
-#ifdef __STRICT_ALIGNMENT
        sc->rx_mbuf_sz = MCLBYTES + ETHER_ALIGN;
-#else
-       sc->rx_mbuf_sz = MCLBYTES;
-#endif
 
        /* Prepare receive descriptors and buffers */
        if (ixgbe_setup_receive_structures(sc)) {
@@ -2458,9 +2454,7 @@ ixgbe_get_buf(struct rx_ring *rxr, int i
                return (ENOBUFS);
 
        mp->m_len = mp->m_pkthdr.len = sc->rx_mbuf_sz;
-#ifdef __STRICT_ALIGNMENT
        m_adj(mp, ETHER_ALIGN);
-#endif
 
        error = bus_dmamap_load_mbuf(rxr->rxdma.dma_tag, rxbuf->map,
            mp, BUS_DMA_NOWAIT);
@@ -2667,11 +2661,7 @@ ixgbe_initialize_receive_units(struct ix
        hlreg |= IXGBE_HLREG0_JUMBOEN;
        IXGBE_WRITE_REG(&sc->hw, IXGBE_HLREG0, hlreg);
 
-#ifdef __STRICT_ALIGNMENT
        bufsz = (sc->rx_mbuf_sz - ETHER_ALIGN) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
-#else
-       bufsz = sc->rx_mbuf_sz >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
-#endif
 
        for (i = 0; i < sc->num_queues; i++, rxr++) {
                uint64_t rdba = rxr->rxdma.dma_map->dm_segs[0].ds_addr;
Index: dev/pci/if_em.h
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_em.h,v
retrieving revision 1.72
diff -u -p -r1.72 if_em.h
--- dev/pci/if_em.h     18 Feb 2016 14:24:39 -0000      1.72
+++ dev/pci/if_em.h     14 Oct 2016 03:48:32 -0000
@@ -263,11 +263,7 @@ typedef int        boolean_t;
 #define EM_RXBUFFER_8192       8192
 #define EM_RXBUFFER_16384      16384
 
-#ifdef __STRICT_ALIGNMENT
 #define EM_MCLBYTES            (EM_RXBUFFER_2048 + ETHER_ALIGN)
-#else
-#define EM_MCLBYTES            EM_RXBUFFER_2048
-#endif
 
 #define EM_MAX_SCATTER         64
 #define EM_TSO_SIZE            65535

Reply via email to