From owner-svn-src-user@FreeBSD.ORG Sun Oct 20 17:47:41 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5B9E930F; Sun, 20 Oct 2013 17:47:41 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 39F26254E; Sun, 20 Oct 2013 17:47:41 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9KHlfPc064892; Sun, 20 Oct 2013 17:47:41 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9KHlePv064890; Sun, 20 Oct 2013 17:47:40 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201310201747.r9KHlePv064890@svn.freebsd.org> From: Andre Oppermann Date: Sun, 20 Oct 2013 17:47:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256796 - user/andre/mbuf_staging/dev/lge X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Oct 2013 17:47:41 -0000 Author: andre Date: Sun Oct 20 17:47:40 2013 New Revision: 256796 URL: http://svnweb.freebsd.org/changeset/base/256796 Log: Change lge(4) driver from managing its own jumbo mbuf pool to the generic MJUM9BYTES jumbo buffers provided by the kernel. NB: The driver always uses jumbo mbufs, even when the MTU is the normal 1500. That issue is not fixed. Untested due to lack of hardware. Modified: user/andre/mbuf_staging/dev/lge/if_lge.c user/andre/mbuf_staging/dev/lge/if_lgereg.h Modified: user/andre/mbuf_staging/dev/lge/if_lge.c ============================================================================== --- user/andre/mbuf_staging/dev/lge/if_lge.c Sun Oct 20 16:52:27 2013 (r256795) +++ user/andre/mbuf_staging/dev/lge/if_lge.c Sun Oct 20 17:47:40 2013 (r256796) @@ -119,11 +119,6 @@ static int lge_probe(device_t); static int lge_attach(device_t); static int lge_detach(device_t); -static int lge_alloc_jumbo_mem(struct lge_softc *); -static void lge_free_jumbo_mem(struct lge_softc *); -static void *lge_jalloc(struct lge_softc *); -static int lge_jfree(struct mbuf *, void *, void *, int); - static int lge_newbuf(struct lge_softc *, struct lge_rx_desc *, struct mbuf *); static int lge_encap(struct lge_softc *, struct mbuf *, u_int32_t *); static void lge_rxeof(struct lge_softc *, int); @@ -521,13 +516,6 @@ lge_attach(dev) goto fail; } - /* Try to allocate memory for jumbo buffers. */ - if (lge_alloc_jumbo_mem(sc)) { - device_printf(dev, "jumbo buffer allocation failed\n"); - error = ENXIO; - goto fail; - } - ifp = sc->lge_ifp = if_alloc(IFT_ETHER); if (ifp == NULL) { device_printf(dev, "can not if_alloc()\n"); @@ -575,10 +563,6 @@ lge_attach(dev) return (0); fail: - lge_free_jumbo_mem(sc); - if (sc->lge_ldata) - contigfree(sc->lge_ldata, - sizeof(struct lge_list_data), M_DEVBUF); if (ifp) if_free(ifp); if (sc->lge_irq) @@ -615,7 +599,6 @@ lge_detach(dev) contigfree(sc->lge_ldata, sizeof(struct lge_list_data), M_DEVBUF); if_free(ifp); - lge_free_jumbo_mem(sc); mtx_destroy(&sc->lge_mtx); return(0); @@ -688,31 +671,14 @@ lge_newbuf(sc, c, m) struct mbuf *m; { struct mbuf *m_new = NULL; - caddr_t *buf = NULL; if (m == NULL) { - MGETHDR(m_new, M_NOWAIT, MT_DATA); + m_new = m_getjcl(M_NOWAIT, MT_DATA, 0, MJUM9BYTES); if (m_new == NULL) { device_printf(sc->lge_dev, "no memory for rx list " "-- packet dropped!\n"); return(ENOBUFS); } - - /* Allocate the jumbo buffer */ - buf = lge_jalloc(sc); - if (buf == NULL) { -#ifdef LGE_VERBOSE - device_printf(sc->lge_dev, "jumbo allocation failed " - "-- packet dropped!\n"); -#endif - m_freem(m_new); - return(ENOBUFS); - } - /* Attach the buffer to the mbuf */ - m_new->m_data = (void *)buf; - m_new->m_len = m_new->m_pkthdr.len = LGE_JUMBO_FRAMELEN; - MEXTADD(m_new, buf, LGE_JUMBO_FRAMELEN, lge_jfree, - buf, (struct lge_softc *)sc, 0, EXT_NET_DRV); } else { m_new = m; m_new->m_len = m_new->m_pkthdr.len = LGE_JUMBO_FRAMELEN; @@ -750,132 +716,6 @@ lge_newbuf(sc, c, m) return(0); } -static int -lge_alloc_jumbo_mem(sc) - struct lge_softc *sc; -{ - caddr_t ptr; - register int i; - struct lge_jpool_entry *entry; - - /* Grab a big chunk o' storage. */ - sc->lge_cdata.lge_jumbo_buf = contigmalloc(LGE_JMEM, M_DEVBUF, - M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); - - if (sc->lge_cdata.lge_jumbo_buf == NULL) { - device_printf(sc->lge_dev, "no memory for jumbo buffers!\n"); - return(ENOBUFS); - } - - SLIST_INIT(&sc->lge_jfree_listhead); - SLIST_INIT(&sc->lge_jinuse_listhead); - - /* - * Now divide it up into 9K pieces and save the addresses - * in an array. - */ - ptr = sc->lge_cdata.lge_jumbo_buf; - for (i = 0; i < LGE_JSLOTS; i++) { - sc->lge_cdata.lge_jslots[i] = ptr; - ptr += LGE_JLEN; - entry = malloc(sizeof(struct lge_jpool_entry), - M_DEVBUF, M_NOWAIT); - if (entry == NULL) { - device_printf(sc->lge_dev, "no memory for jumbo " - "buffer queue!\n"); - return(ENOBUFS); - } - entry->slot = i; - SLIST_INSERT_HEAD(&sc->lge_jfree_listhead, - entry, jpool_entries); - } - - return(0); -} - -static void -lge_free_jumbo_mem(sc) - struct lge_softc *sc; -{ - struct lge_jpool_entry *entry; - - if (sc->lge_cdata.lge_jumbo_buf == NULL) - return; - - while ((entry = SLIST_FIRST(&sc->lge_jinuse_listhead))) { - device_printf(sc->lge_dev, - "asked to free buffer that is in use!\n"); - SLIST_REMOVE_HEAD(&sc->lge_jinuse_listhead, jpool_entries); - SLIST_INSERT_HEAD(&sc->lge_jfree_listhead, entry, - jpool_entries); - } - while (!SLIST_EMPTY(&sc->lge_jfree_listhead)) { - entry = SLIST_FIRST(&sc->lge_jfree_listhead); - SLIST_REMOVE_HEAD(&sc->lge_jfree_listhead, jpool_entries); - free(entry, M_DEVBUF); - } - - contigfree(sc->lge_cdata.lge_jumbo_buf, LGE_JMEM, M_DEVBUF); - - return; -} - -/* - * Allocate a jumbo buffer. - */ -static void * -lge_jalloc(sc) - struct lge_softc *sc; -{ - struct lge_jpool_entry *entry; - - entry = SLIST_FIRST(&sc->lge_jfree_listhead); - - if (entry == NULL) { -#ifdef LGE_VERBOSE - device_printf(sc->lge_dev, "no free jumbo buffers\n"); -#endif - return(NULL); - } - - SLIST_REMOVE_HEAD(&sc->lge_jfree_listhead, jpool_entries); - SLIST_INSERT_HEAD(&sc->lge_jinuse_listhead, entry, jpool_entries); - return(sc->lge_cdata.lge_jslots[entry->slot]); -} - -/* - * Release a jumbo buffer. - */ -static int -lge_jfree(struct mbuf *m, void *buf, void *args, int action) -{ - struct lge_softc *sc; - int i; - struct lge_jpool_entry *entry; - - /* Extract the softc struct pointer. */ - sc = args; - - if (sc == NULL) - panic("lge_jfree: can't find softc pointer!"); - - /* calculate the slot this buffer belongs to */ - i = ((vm_offset_t)buf - - (vm_offset_t)sc->lge_cdata.lge_jumbo_buf) / LGE_JLEN; - - if ((i < 0) || (i >= LGE_JSLOTS)) - panic("lge_jfree: asked to free buffer that we don't manage!"); - - entry = SLIST_FIRST(&sc->lge_jinuse_listhead); - if (entry == NULL) - panic("lge_jfree: buffer not in use!"); - entry->slot = i; - SLIST_REMOVE_HEAD(&sc->lge_jinuse_listhead, jpool_entries); - SLIST_INSERT_HEAD(&sc->lge_jfree_listhead, entry, jpool_entries); - - return (EXT_FREE_OK); -} - /* * A frame has been uploaded: pass the resulting mbuf chain up to * the higher level protocols. Modified: user/andre/mbuf_staging/dev/lge/if_lgereg.h ============================================================================== --- user/andre/mbuf_staging/dev/lge/if_lgereg.h Sun Oct 20 16:52:27 2013 (r256795) +++ user/andre/mbuf_staging/dev/lge/if_lgereg.h Sun Oct 20 17:47:40 2013 (r256796) @@ -480,28 +480,15 @@ struct lge_type { #define LGE_JUMBO_FRAMELEN 9018 #define LGE_JUMBO_MTU (LGE_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN) -#define LGE_JSLOTS 384 -#define LGE_JRAWLEN (LGE_JUMBO_FRAMELEN + ETHER_ALIGN) -#define LGE_JLEN (LGE_JRAWLEN + (sizeof(u_int64_t) - \ - (LGE_JRAWLEN % sizeof(u_int64_t)))) #define LGE_JPAGESZ PAGE_SIZE #define LGE_RESID (LGE_JPAGESZ - (LGE_JLEN * LGE_JSLOTS) % LGE_JPAGESZ) -#define LGE_JMEM ((LGE_JLEN * LGE_JSLOTS) + LGE_RESID) - -struct lge_jpool_entry { - int slot; - SLIST_ENTRY(lge_jpool_entry) jpool_entries; -}; struct lge_ring_data { int lge_rx_prod; int lge_rx_cons; int lge_tx_prod; int lge_tx_cons; - /* Stick the jumbo mem management stuff here too. */ - caddr_t lge_jslots[LGE_JSLOTS]; - void *lge_jumbo_buf; }; struct lge_softc { @@ -522,8 +509,6 @@ struct lge_softc { struct lge_ring_data lge_cdata; struct callout lge_stat_callout; struct mtx lge_mtx; - SLIST_HEAD(__lge_jfreehead, lge_jpool_entry) lge_jfree_listhead; - SLIST_HEAD(__lge_jinusehead, lge_jpool_entry) lge_jinuse_listhead; }; /*