Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci Allocate a static set of receive software state ...
details: https://anonhg.NetBSD.org/src/rev/ed50fcfeb0dd
branches: trunk
changeset: 745691:ed50fcfeb0dd
user: thorpej <thorpej%NetBSD.org@localhost>
date: Mon Mar 09 00:32:53 2020 +0000
description:
Allocate a static set of receive software state descriptors at attach
time, and create a simple allocator for them for use by the rx reclaim
handlers. Don't create and destroy DMA maps for receoive buffers
in the interrupt handlers -- just use the maps that are created at
attach time.
diffstat:
sys/dev/pci/if_txp.c | 48 +++++++++++++++++++++++++++++-------------------
sys/dev/pci/if_txpreg.h | 5 ++++-
2 files changed, 33 insertions(+), 20 deletions(-)
diffs (163 lines):
diff -r d8eb964eb8b1 -r ed50fcfeb0dd sys/dev/pci/if_txp.c
--- a/sys/dev/pci/if_txp.c Mon Mar 09 00:03:00 2020 +0000
+++ b/sys/dev/pci/if_txp.c Mon Mar 09 00:32:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_txp.c,v 1.68 2020/03/08 22:26:03 thorpej Exp $ */
+/* $NetBSD: if_txp.c,v 1.69 2020/03/09 00:32:53 thorpej Exp $ */
/*
* Copyright (c) 2001
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_txp.c,v 1.68 2020/03/08 22:26:03 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_txp.c,v 1.69 2020/03/09 00:32:53 thorpej Exp $");
#include "opt_inet.h"
@@ -122,6 +122,9 @@
static void txp_rx_reclaim(struct txp_softc *, struct txp_rx_ring *,
struct txp_dma_alloc *);
+static void txp_rxd_free(struct txp_softc *, struct txp_swdesc *);
+static struct txp_swdesc *txp_rxd_alloc(struct txp_softc *);
+
CFATTACH_DECL_NEW(txp, sizeof(struct txp_softc), txp_probe, txp_attach,
NULL, NULL);
@@ -660,6 +663,21 @@
return (claimed);
}
+static struct txp_swdesc *
+txp_rxd_alloc(struct txp_softc *sc)
+{
+ if (sc->sc_txd_pool_ptr == 0)
+ return NULL;
+ return sc->sc_rxd_pool[--sc->sc_txd_pool_ptr];
+}
+
+static void
+txp_rxd_free(struct txp_softc *sc, struct txp_swdesc *sd)
+{
+ KASSERT(sc->sc_txd_pool_ptr < RXBUF_ENTRIES);
+ sc->sc_rxd_pool[sc->sc_txd_pool_ptr++] = sd;
+}
+
static void
txp_rx_reclaim(struct txp_softc *sc, struct txp_rx_ring *r,
struct txp_dma_alloc *dma)
@@ -696,9 +714,8 @@
bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
sd->sd_map->dm_mapsize, BUS_DMASYNC_POSTREAD);
bus_dmamap_unload(sc->sc_dmat, sd->sd_map);
- bus_dmamap_destroy(sc->sc_dmat, sd->sd_map);
m = sd->sd_mbuf;
- free(sd, M_DEVBUF);
+ txp_rxd_free(sc, sd);
m->m_pkthdr.len = m->m_len = le16toh(rxd->rx_len);
#ifdef __STRICT_ALIGNMENT
@@ -794,8 +811,7 @@
rbd = sc->sc_rxbufs + i;
while (i != end) {
- sd = (struct txp_swdesc *)malloc(sizeof(struct txp_swdesc),
- M_DEVBUF, M_NOWAIT);
+ sd = txp_rxd_alloc(sc);
if (sd == NULL)
break;
@@ -808,12 +824,8 @@
goto err_mbuf;
m_set_rcvif(sd->sd_mbuf, ifp);
sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
- if (bus_dmamap_create(sc->sc_dmat, TXP_MAX_PKTLEN, 1,
- TXP_MAX_PKTLEN, 0, BUS_DMA_NOWAIT, &sd->sd_map))
- goto err_mbuf;
if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map, sd->sd_mbuf,
BUS_DMA_NOWAIT)) {
- bus_dmamap_destroy(sc->sc_dmat, sd->sd_map);
goto err_mbuf;
}
@@ -849,7 +861,7 @@
err_mbuf:
m_freem(sd->sd_mbuf);
err_sd:
- free(sd, M_DEVBUF);
+ txp_rxd_free(sc, sd);
}
/*
@@ -1091,35 +1103,34 @@
boot->br_rxbuf_siz = htole32(RXBUF_ENTRIES * sizeof(struct txp_rxbuf_desc));
sc->sc_rxbufs = (struct txp_rxbuf_desc *)sc->sc_rxbufring_dma.dma_vaddr;
for (nb = 0; nb < RXBUF_ENTRIES; nb++) {
- sd = malloc(sizeof(struct txp_swdesc), M_DEVBUF, M_WAITOK);
+ sd = &sc->sc_rxd[nb];
/* stash away pointer */
memcpy(__UNVOLATILE(&sc->sc_rxbufs[nb].rb_vaddrlo), &sd,
sizeof(sd));
- MGETHDR(sd->sd_mbuf, M_DONTWAIT, MT_DATA);
+ MGETHDR(sd->sd_mbuf, M_WAIT, MT_DATA);
if (sd->sd_mbuf == NULL) {
goto bail_rxbufring;
}
- MCLGET(sd->sd_mbuf, M_DONTWAIT);
+ MCLGET(sd->sd_mbuf, M_WAIT);
if ((sd->sd_mbuf->m_flags & M_EXT) == 0) {
goto bail_rxbufring;
}
sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
m_set_rcvif(sd->sd_mbuf, ifp);
if (bus_dmamap_create(sc->sc_dmat, TXP_MAX_PKTLEN, 1,
- TXP_MAX_PKTLEN, 0, BUS_DMA_NOWAIT, &sd->sd_map)) {
+ TXP_MAX_PKTLEN, 0, BUS_DMA_WAITOK, &sd->sd_map)) {
goto bail_rxbufring;
}
if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map, sd->sd_mbuf,
- BUS_DMA_NOWAIT)) {
+ BUS_DMA_WAITOK)) {
bus_dmamap_destroy(sc->sc_dmat, sd->sd_map);
goto bail_rxbufring;
}
bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
sd->sd_map->dm_mapsize, BUS_DMASYNC_PREREAD);
-
sc->sc_rxbufs[nb].rb_paddrlo =
htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[0].ds_addr));
sc->sc_rxbufs[nb].rb_paddrhi =
@@ -1184,8 +1195,7 @@
for (i = 0; i <= nb; i++) {
memcpy(&sd, __UNVOLATILE(&sc->sc_rxbufs[i].rb_vaddrlo),
sizeof(sd));
- if (sd)
- free(sd, M_DEVBUF);
+ /* XXXJRT */
}
txp_dma_free(sc, &sc->sc_rxbufring_dma);
bail_rspring:
diff -r d8eb964eb8b1 -r ed50fcfeb0dd sys/dev/pci/if_txpreg.h
--- a/sys/dev/pci/if_txpreg.h Mon Mar 09 00:03:00 2020 +0000
+++ b/sys/dev/pci/if_txpreg.h Mon Mar 09 00:32:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_txpreg.h,v 1.9 2020/03/08 22:26:03 thorpej Exp $ */
+/* $NetBSD: if_txpreg.h,v 1.10 2020/03/09 00:32:53 thorpej Exp $ */
/*
* Copyright (c) 2001 Aaron Campbell <aaron%monkey.org@localhost>.
@@ -581,6 +581,9 @@
struct txp_tx_ring sc_txhir, sc_txlor;
struct txp_rxbuf_desc *sc_rxbufs;
struct txp_rx_ring sc_rxhir, sc_rxlor;
+ struct txp_swdesc sc_rxd[RXBUF_ENTRIES];
+ struct txp_swdesc *sc_rxd_pool[RXBUF_ENTRIES];
+ unsigned int sc_txd_pool_ptr;
u_int16_t sc_xcvr;
u_int16_t sc_seq;
struct txp_dma_alloc sc_boot_dma, sc_host_dma, sc_zero_dma;
Home |
Main Index |
Thread Index |
Old Index