From 288cf70d48950c313e83af7c9721541b8b4983d9 Mon Sep 17 00:00:00 2001 From: skrll Date: Sun, 7 Aug 2022 08:37:48 +0000 Subject: [PATCH] Provide and use (when appropriate) a bge_free_jumbo_mem. --- sys/dev/pci/if_bge.c | 38 ++++++++++++++++++++++++++++++-------- sys/dev/pci/if_bgevar.h | 3 ++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/sys/dev/pci/if_bge.c b/sys/dev/pci/if_bge.c index 56a94a2eafde..bd4cd3d7522d 100644 --- a/sys/dev/pci/if_bge.c +++ b/sys/dev/pci/if_bge.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_bge.c,v 1.372 2022/08/07 08:26:18 skrll Exp $ */ +/* $NetBSD: if_bge.c,v 1.373 2022/08/07 08:37:48 skrll Exp $ */ /* * Copyright (c) 2001 Wind River Systems @@ -79,7 +79,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.372 2022/08/07 08:26:18 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.373 2022/08/07 08:37:48 skrll Exp $"); #include #include @@ -223,9 +223,7 @@ static void bge_setmulti(struct bge_softc *); static void bge_handle_events(struct bge_softc *); static int bge_alloc_jumbo_mem(struct bge_softc *); -#if 0 /* XXX */ static void bge_free_jumbo_mem(struct bge_softc *); -#endif static void *bge_jalloc(struct bge_softc *); static void bge_jfree(struct mbuf *, void *, size_t, void *); static int bge_newbuf_std(struct bge_softc *, int, struct mbuf *, @@ -1313,7 +1311,6 @@ static int bge_alloc_jumbo_mem(struct bge_softc *sc) { char *ptr, *kva; - bus_dma_segment_t seg; int i, rseg, state, error; struct bge_jpool_entry *entry; @@ -1321,13 +1318,14 @@ bge_alloc_jumbo_mem(struct bge_softc *sc) /* Grab a big chunk o' storage. */ if (bus_dmamem_alloc(sc->bge_dmatag, BGE_JMEM, PAGE_SIZE, 0, - &seg, 1, &rseg, BUS_DMA_NOWAIT)) { + &sc->bge_cdata.bge_rx_jumbo_seg, 1, &rseg, BUS_DMA_NOWAIT)) { aprint_error_dev(sc->bge_dev, "can't alloc rx buffers\n"); return ENOBUFS; } state = 1; - if (bus_dmamem_map(sc->bge_dmatag, &seg, rseg, BGE_JMEM, (void **)&kva, + if (bus_dmamem_map(sc->bge_dmatag, &sc->bge_cdata.bge_rx_jumbo_seg, + rseg, BGE_JMEM, (void **)&kva, BUS_DMA_NOWAIT)) { aprint_error_dev(sc->bge_dev, "can't map DMA buffers (%d bytes)\n", (int)BGE_JMEM); @@ -1386,7 +1384,8 @@ out: bus_dmamem_unmap(sc->bge_dmatag, kva, BGE_JMEM); /* FALLTHROUGH */ case 1: - bus_dmamem_free(sc->bge_dmatag, &seg, rseg); + bus_dmamem_free(sc->bge_dmatag, + &sc->bge_cdata.bge_rx_jumbo_seg, rseg); break; default: break; @@ -1396,6 +1395,26 @@ out: return error; } +static void +bge_free_jumbo_mem(struct bge_softc *sc) +{ + struct bge_jpool_entry *entry, *tmp; + + KASSERT(SLIST_EMPTY(&sc->bge_jinuse_listhead)); + + SLIST_FOREACH_SAFE(entry, &sc->bge_jfree_listhead, jpool_entries, tmp) { + kmem_free(entry, sizeof(*entry)); + } + + bus_dmamap_unload(sc->bge_dmatag, sc->bge_cdata.bge_rx_jumbo_map); + + bus_dmamap_destroy(sc->bge_dmatag, sc->bge_cdata.bge_rx_jumbo_map); + + bus_dmamem_unmap(sc->bge_dmatag, sc->bge_cdata.bge_jumbo_buf, BGE_JMEM); + + bus_dmamem_free(sc->bge_dmatag, &sc->bge_cdata.bge_rx_jumbo_seg, 1); +} + /* * Allocate a jumbo buffer. */ @@ -4071,6 +4090,9 @@ bge_release_resources(struct bge_softc *sc) sc->bge_intrhand = NULL; } + if (sc->bge_cdata.bge_jumbo_buf != NULL) + bge_free_jumbo_mem(sc); + if (sc->bge_dmatag != NULL) { bus_dmamap_unload(sc->bge_dmatag, sc->bge_ring_map); bus_dmamap_destroy(sc->bge_dmatag, sc->bge_ring_map); diff --git a/sys/dev/pci/if_bgevar.h b/sys/dev/pci/if_bgevar.h index 55bb8051df85..15f37dad453c 100644 --- a/sys/dev/pci/if_bgevar.h +++ b/sys/dev/pci/if_bgevar.h @@ -1,4 +1,4 @@ -/* $NetBSD: if_bgevar.h,v 1.30 2022/07/25 08:29:14 skrll Exp $ */ +/* $NetBSD: if_bgevar.h,v 1.31 2022/08/07 08:37:48 skrll Exp $ */ /* * Copyright (c) 2001 Wind River Systems * Copyright (c) 1997, 1998, 1999, 2001 @@ -218,6 +218,7 @@ struct bge_chain_data { struct mbuf *bge_rx_jumbo_chain[BGE_JUMBO_RX_RING_CNT]; bus_dmamap_t bge_rx_std_map[BGE_STD_RX_RING_CNT]; bus_dmamap_t bge_rx_jumbo_map; + bus_dma_segment_t bge_rx_jumbo_seg; /* Stick the jumbo mem management stuff here too. */ void * bge_jslots[BGE_JSLOTS]; void * bge_jumbo_buf;