Provide and use (when appropriate) a bge_free_jumbo_mem.

This commit is contained in:
skrll 2022-08-07 08:37:48 +00:00
parent f51d91299f
commit 288cf70d48
2 changed files with 32 additions and 9 deletions

View File

@ -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 * Copyright (c) 2001 Wind River Systems
@ -79,7 +79,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/param.h> #include <sys/param.h>
#include <sys/types.h> #include <sys/types.h>
@ -223,9 +223,7 @@ static void bge_setmulti(struct bge_softc *);
static void bge_handle_events(struct bge_softc *); static void bge_handle_events(struct bge_softc *);
static int bge_alloc_jumbo_mem(struct bge_softc *); static int bge_alloc_jumbo_mem(struct bge_softc *);
#if 0 /* XXX */
static void bge_free_jumbo_mem(struct bge_softc *); static void bge_free_jumbo_mem(struct bge_softc *);
#endif
static void *bge_jalloc(struct bge_softc *); static void *bge_jalloc(struct bge_softc *);
static void bge_jfree(struct mbuf *, void *, size_t, void *); static void bge_jfree(struct mbuf *, void *, size_t, void *);
static int bge_newbuf_std(struct bge_softc *, int, struct mbuf *, 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) bge_alloc_jumbo_mem(struct bge_softc *sc)
{ {
char *ptr, *kva; char *ptr, *kva;
bus_dma_segment_t seg;
int i, rseg, state, error; int i, rseg, state, error;
struct bge_jpool_entry *entry; struct bge_jpool_entry *entry;
@ -1321,13 +1318,14 @@ bge_alloc_jumbo_mem(struct bge_softc *sc)
/* Grab a big chunk o' storage. */ /* Grab a big chunk o' storage. */
if (bus_dmamem_alloc(sc->bge_dmatag, BGE_JMEM, PAGE_SIZE, 0, 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"); aprint_error_dev(sc->bge_dev, "can't alloc rx buffers\n");
return ENOBUFS; return ENOBUFS;
} }
state = 1; 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)) { BUS_DMA_NOWAIT)) {
aprint_error_dev(sc->bge_dev, aprint_error_dev(sc->bge_dev,
"can't map DMA buffers (%d bytes)\n", (int)BGE_JMEM); "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); bus_dmamem_unmap(sc->bge_dmatag, kva, BGE_JMEM);
/* FALLTHROUGH */ /* FALLTHROUGH */
case 1: 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; break;
default: default:
break; break;
@ -1396,6 +1395,26 @@ out:
return error; 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. * Allocate a jumbo buffer.
*/ */
@ -4071,6 +4090,9 @@ bge_release_resources(struct bge_softc *sc)
sc->bge_intrhand = NULL; sc->bge_intrhand = NULL;
} }
if (sc->bge_cdata.bge_jumbo_buf != NULL)
bge_free_jumbo_mem(sc);
if (sc->bge_dmatag != NULL) { if (sc->bge_dmatag != NULL) {
bus_dmamap_unload(sc->bge_dmatag, sc->bge_ring_map); bus_dmamap_unload(sc->bge_dmatag, sc->bge_ring_map);
bus_dmamap_destroy(sc->bge_dmatag, sc->bge_ring_map); bus_dmamap_destroy(sc->bge_dmatag, sc->bge_ring_map);

View File

@ -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) 2001 Wind River Systems
* Copyright (c) 1997, 1998, 1999, 2001 * 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]; 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_std_map[BGE_STD_RX_RING_CNT];
bus_dmamap_t bge_rx_jumbo_map; bus_dmamap_t bge_rx_jumbo_map;
bus_dma_segment_t bge_rx_jumbo_seg;
/* Stick the jumbo mem management stuff here too. */ /* Stick the jumbo mem management stuff here too. */
void * bge_jslots[BGE_JSLOTS]; void * bge_jslots[BGE_JSLOTS];
void * bge_jumbo_buf; void * bge_jumbo_buf;