summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/arch/octeon/dev/if_cnmac.c16
-rw-r--r--sys/dev/pci/if_myx.c4
-rw-r--r--sys/dev/pci/if_nep.c9
-rw-r--r--sys/kern/uipc_mbuf.c29
-rw-r--r--sys/net/if_ppp.c4
-rw-r--r--sys/sys/mbuf.h11
6 files changed, 52 insertions, 21 deletions
diff --git a/sys/arch/octeon/dev/if_cnmac.c b/sys/arch/octeon/dev/if_cnmac.c
index e8625d83b85..5240737e864 100644
--- a/sys/arch/octeon/dev/if_cnmac.c
+++ b/sys/arch/octeon/dev/if_cnmac.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_cnmac.c,v 1.45 2016/05/21 11:04:38 visa Exp $ */
+/* $OpenBSD: if_cnmac.c,v 1.46 2016/05/23 15:22:45 tedu Exp $ */
/*
* Copyright (c) 2007 Internet Initiative Japan, Inc.
@@ -138,8 +138,6 @@ void octeon_eth_send_queue_del(struct octeon_eth_softc *,
struct mbuf **, uint64_t **);
int octeon_eth_buf_free_work(struct octeon_eth_softc *,
uint64_t *, uint64_t);
-void octeon_eth_buf_ext_free_m(caddr_t, u_int, void *);
-void octeon_eth_buf_ext_free_ext(caddr_t, u_int, void *);
int octeon_eth_ioctl(struct ifnet *, u_long, caddr_t);
void octeon_eth_watchdog(struct ifnet *);
@@ -212,6 +210,8 @@ struct cn30xxfpa_buf *octeon_eth_pools[8/* XXX */];
uint64_t octeon_eth_mac_addr = 0;
uint32_t octeon_eth_mac_addr_offset = 0;
+static u_int octeon_ext_free_idx;
+
void
octeon_eth_buf_init(struct octeon_eth_softc *sc)
{
@@ -253,6 +253,10 @@ octeon_eth_attach(struct device *parent, struct device *self, void *aux)
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
uint8_t enaddr[ETHER_ADDR_LEN];
+ if (octeon_ext_free_idx == 0)
+ octeon_ext_free_idx =
+ mextfree_register(octeon_eth_buf_ext_free);
+
sc->sc_regt = ga->ga_regt;
sc->sc_dmat = ga->ga_dmat;
sc->sc_port = ga->ga_portno;
@@ -616,7 +620,7 @@ octeon_eth_send_queue_add(struct octeon_eth_softc *sc, struct mbuf *m,
m->m_pkthdr.ph_cookie = gbuf;
ml_enqueue(&sc->sc_sendq, m);
- if (m->m_ext.ext_free != NULL)
+ if (m->m_ext.ext_free_fn != 0)
sc->sc_ext_callback_cnt++;
}
@@ -631,7 +635,7 @@ octeon_eth_send_queue_del(struct octeon_eth_softc *sc, struct mbuf **rm,
*rm = m;
*rgbuf = m->m_pkthdr.ph_cookie;
- if (m->m_ext.ext_free != NULL) {
+ if (m->m_ext.ext_free_fn != 0) {
sc->sc_ext_callback_cnt--;
OCTEON_ETH_KASSERT(sc->sc_ext_callback_cnt >= 0);
}
@@ -1158,7 +1162,7 @@ octeon_eth_recv_mbuf(struct octeon_eth_softc *sc, uint64_t *work,
ext_size = OCTEON_POOL_SIZE_PKT;
ext_buf = addr & ~(ext_size - 1);
- MEXTADD(m, ext_buf, ext_size, 0, octeon_eth_buf_ext_free, NULL);
+ MEXTADD(m, ext_buf, ext_size, 0, octeon_ext_free_idx, NULL);
m->m_data = (void *)addr;
m->m_len = m->m_pkthdr.len = (word1 & PIP_WQE_WORD1_LEN) >> 48;
diff --git a/sys/dev/pci/if_myx.c b/sys/dev/pci/if_myx.c
index 6e98c1ab64f..cae0b82daa3 100644
--- a/sys/dev/pci/if_myx.c
+++ b/sys/dev/pci/if_myx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_myx.c,v 1.94 2016/04/13 11:36:00 mpi Exp $ */
+/* $OpenBSD: if_myx.c,v 1.95 2016/05/23 15:22:44 tedu Exp $ */
/*
* Copyright (c) 2007 Reyk Floeter <reyk@openbsd.org>
@@ -1931,7 +1931,7 @@ myx_mcl_big(void)
return (NULL);
}
- MEXTADD(m, mcl, MYX_RXBIG_SIZE, M_EXTWR, m_extfree_pool, myx_mcl_pool);
+ MEXTADD(m, mcl, MYX_RXBIG_SIZE, M_EXTWR, MEXTFREE_POOL, myx_mcl_pool);
m->m_len = m->m_pkthdr.len = MYX_RXBIG_SIZE;
return (m);
diff --git a/sys/dev/pci/if_nep.c b/sys/dev/pci/if_nep.c
index ae3d817d588..62417f15776 100644
--- a/sys/dev/pci/if_nep.c
+++ b/sys/dev/pci/if_nep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_nep.c,v 1.24 2015/11/25 03:09:59 dlg Exp $ */
+/* $OpenBSD: if_nep.c,v 1.25 2016/05/23 15:22:44 tedu Exp $ */
/*
* Copyright (c) 2014, 2015 Mark Kettenis
*
@@ -465,6 +465,8 @@ struct cfdriver nep_cd = {
NULL, "nep", DV_DULL
};
+static u_int nep_mextfree_idx;
+
int nep_pci_enaddr(struct nep_softc *, struct pci_attach_args *);
uint64_t nep_read(struct nep_softc *, uint32_t);
@@ -541,6 +543,9 @@ nep_attach(struct device *parent, struct device *self, void *aux)
pcireg_t memtype;
uint64_t val;
+ if (nep_mextfree_idx == 0)
+ nep_mextfree_idx = mextfree_register(nep_extfree);
+
sc->sc_dmat = pa->pa_dmat;
memtype = PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT;
@@ -1024,7 +1029,7 @@ nep_rx_proc(struct nep_softc *sc)
ifp->if_ierrors++;
} else {
MEXTADD(m, block + off, PAGE_SIZE, M_EXTWR,
- nep_extfree, block);
+ nep_mextfree_idx, block);
m->m_pkthdr.len = m->m_len = len;
m->m_data += ETHER_ALIGN;
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index b84d42ea1ea..951c474811e 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf.c,v 1.224 2016/04/15 05:05:21 dlg Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.225 2016/05/23 15:22:44 tedu Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
@@ -130,6 +130,8 @@ struct mbuf *m_copym0(struct mbuf *, int, int, int, int);
void nmbclust_update(void);
void m_zero(struct mbuf *);
+static void (*mextfree_fns[4])(caddr_t, u_int, void *);
+static u_int num_extfree_fns;
const char *mclpool_warnmsg =
"WARNING: mclpools limit reached; increase kern.maxclusters";
@@ -168,6 +170,9 @@ mbinit(void)
pool_setlowat(&mclpools[i], mcllowat);
}
+ (void)mextfree_register(m_extfree_pool);
+ KASSERT(num_extfree_fns == 1);
+
nmbclust_update();
}
@@ -331,7 +336,7 @@ m_clget(struct mbuf *m, int how, u_int pktlen)
return (NULL);
}
- MEXTADD(m, buf, pp->pr_size, M_EXTWR, m_extfree_pool, pp);
+ MEXTADD(m, buf, pp->pr_size, M_EXTWR, MEXTFREE_POOL, pp);
return (m);
}
@@ -414,11 +419,25 @@ m_extunref(struct mbuf *m)
return (refs);
}
+/*
+ * Returns a number for use with MEXTADD.
+ * Should only be called once per function.
+ * Drivers can be assured that the index will be non zero.
+ */
+u_int
+mextfree_register(void (*fn)(caddr_t, u_int, void *))
+{
+ KASSERT(num_extfree_fns < nitems(mextfree_fns));
+ mextfree_fns[num_extfree_fns] = fn;
+ return num_extfree_fns++;
+}
+
void
m_extfree(struct mbuf *m)
{
if (m_extunref(m) == 0) {
- (*(m->m_ext.ext_free))(m->m_ext.ext_buf,
+ KASSERT(m->m_ext.ext_free_fn < num_extfree_fns);
+ mextfree_fns[m->m_ext.ext_free_fn](m->m_ext.ext_buf,
m->m_ext.ext_size, m->m_ext.ext_arg);
}
@@ -1317,8 +1336,8 @@ m_print(void *v,
if (m->m_flags & M_EXT) {
(*pr)("m_ext.ext_buf: %p\tm_ext.ext_size: %u\n",
m->m_ext.ext_buf, m->m_ext.ext_size);
- (*pr)("m_ext.ext_free: %p\tm_ext.ext_arg: %p\n",
- m->m_ext.ext_free, m->m_ext.ext_arg);
+ (*pr)("m_ext.ext_free_fn: %u\tm_ext.ext_arg: %p\n",
+ m->m_ext.ext_free_fn, m->m_ext.ext_arg);
(*pr)("m_ext.ext_nextref: %p\tm_ext.ext_prevref: %p\n",
m->m_ext.ext_nextref, m->m_ext.ext_prevref);
diff --git a/sys/net/if_ppp.c b/sys/net/if_ppp.c
index 99ddaf972a9..c4763232bc7 100644
--- a/sys/net/if_ppp.c
+++ b/sys/net/if_ppp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ppp.c,v 1.98 2016/04/13 11:41:15 mpi Exp $ */
+/* $OpenBSD: if_ppp.c,v 1.99 2016/05/23 15:22:44 tedu Exp $ */
/* $NetBSD: if_ppp.c,v 1.39 1997/05/17 21:11:59 christos Exp $ */
/*
@@ -1568,7 +1568,7 @@ ppp_pkt_mbuf(struct ppp_pkt *pkt0)
goto fail;
MEXTADD(m, pkt, sizeof(*pkt), M_EXTWR,
- m_extfree_pool, &ppp_pkts);
+ MEXTFREE_POOL, &ppp_pkts);
m->m_data += sizeof(pkt->p_hdr);
m->m_len = PKT_LEN(pkt);
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index da2f544adeb..8c42d57a9db 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbuf.h,v 1.213 2016/04/27 12:27:03 dlg Exp $ */
+/* $OpenBSD: mbuf.h,v 1.214 2016/05/23 15:22:44 tedu Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
@@ -136,8 +136,8 @@ struct pkthdr {
struct mbuf_ext {
caddr_t ext_buf; /* start of buffer */
/* free routine if not the usual */
- void (*ext_free)(caddr_t, u_int, void *);
void *ext_arg;
+ u_int ext_free_fn;
u_int ext_size; /* size of buffer, for ext_free */
struct mbuf *ext_nextref;
struct mbuf *ext_prevref;
@@ -296,11 +296,11 @@ struct mbuf {
* MCLGET allocates and adds an mbuf cluster to a normal mbuf;
* the flag M_EXT is set upon success.
*/
-#define MEXTADD(m, buf, size, mflags, free, arg) do { \
+#define MEXTADD(m, buf, size, mflags, freefn, arg) do { \
(m)->m_data = (m)->m_ext.ext_buf = (caddr_t)(buf); \
(m)->m_flags |= M_EXT | (mflags & M_EXTWR); \
(m)->m_ext.ext_size = (size); \
- (m)->m_ext.ext_free = (free); \
+ (m)->m_ext.ext_free_fn = (freefn); \
(m)->m_ext.ext_arg = (arg); \
MCLINITREFERENCE(m); \
} while (/* CONSTCOND */ 0)
@@ -308,6 +308,9 @@ struct mbuf {
#define MCLGET(m, how) (void) m_clget((m), (how), MCLBYTES)
#define MCLGETI(m, how, ifp, l) m_clget((m), (how), (l))
+u_int mextfree_register(void (*)(caddr_t, u_int, void *));
+#define MEXTFREE_POOL 0
+
/*
* Move just m_pkthdr from from to to,
* remove M_PKTHDR and clean flags/tags for from.