summaryrefslogtreecommitdiff
path: root/sys/dev/pci
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2008-06-13 07:40:31 +0000
committerBrad Smith <brad@cvs.openbsd.org>2008-06-13 07:40:31 +0000
commit189552dcbfe0baf98c8e2d5a8951c5633064727e (patch)
treeaab6f02c3e04a1fbca28d3cf4aa879a6cefe66e7 /sys/dev/pci
parent06f24d6e6538bff2849cab957df1ac2c50b90259 (diff)
Remove slack space for RX/TX chains since it only covers sloppy coding.
From davidch @ FreeBSD
Diffstat (limited to 'sys/dev/pci')
-rw-r--r--sys/dev/pci/if_bnx.c48
-rw-r--r--sys/dev/pci/if_bnxreg.h8
2 files changed, 30 insertions, 26 deletions
diff --git a/sys/dev/pci/if_bnx.c b/sys/dev/pci/if_bnx.c
index d73fd9f8cd2..0e9852063ea 100644
--- a/sys/dev/pci/if_bnx.c
+++ b/sys/dev/pci/if_bnx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_bnx.c,v 1.61 2008/06/08 16:20:27 reyk Exp $ */
+/* $OpenBSD: if_bnx.c,v 1.62 2008/06/13 07:40:30 brad Exp $ */
/*-
* Copyright (c) 2006 Broadcom Corporation
@@ -2317,10 +2317,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
*/
for (i = 0; i < TOTAL_TX_BD; i++) {
if (bus_dmamap_create(sc->bnx_dmatag,
- MCLBYTES * BNX_MAX_SEGMENTS,
- USABLE_TX_BD - BNX_TX_SLACK_SPACE,
- MCLBYTES, 0, BUS_DMA_NOWAIT,
- &sc->tx_mbuf_map[i])) {
+ MCLBYTES * BNX_MAX_SEGMENTS, USABLE_TX_BD,
+ MCLBYTES, 0, BUS_DMA_NOWAIT, &sc->tx_mbuf_map[i])) {
printf(": Could not create Tx mbuf %d DMA map!\n", i);
rc = ENOMEM;
goto bnx_dma_alloc_exit;
@@ -3341,8 +3339,10 @@ bnx_get_buf(struct bnx_softc *sc, struct mbuf *m, u_int16_t *prod,
printf("%s: Too many free rx_bd (0x%04X > 0x%04X)!\n",
sc->free_rx_bd, (u_int16_t) USABLE_RX_BD));
+ /* Update some debug statistics counters */
DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
sc->rx_low_watermark = sc->free_rx_bd);
+ DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
/* Setup the rx_bd for the first segment. */
rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
@@ -3417,7 +3417,9 @@ bnx_init_tx_chain(struct bnx_softc *sc)
sc->tx_cons = 0;
sc->tx_prod_bseq = 0;
sc->used_tx_bd = 0;
+ sc->max_tx_bd = USABLE_TX_BD;
DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
+ DBRUNIF(1, sc->tx_full_count = 0);
/*
* The NetXtreme II supports a linked-list structure called
@@ -3529,8 +3531,10 @@ bnx_init_rx_chain(struct bnx_softc *sc)
sc->rx_prod = 0;
sc->rx_cons = 0;
sc->rx_prod_bseq = 0;
- sc->free_rx_bd = BNX_RX_SLACK_SPACE;
+ sc->free_rx_bd = USABLE_RX_BD;
+ sc->max_rx_bd = USABLE_RX_BD;
DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
+ DBRUNIF(1, sc->rx_empty_count = 0);
/* Initialize the RX next pointer chain entries. */
for (i = 0; i < RX_PAGES; i++) {
@@ -3565,7 +3569,7 @@ bnx_init_rx_chain(struct bnx_softc *sc)
/* Allocate mbuf clusters for the rx_bd chain. */
prod = prod_bseq = 0;
- while (prod < BNX_RX_SLACK_SPACE) {
+ while (prod < TOTAL_RX_BD) {
chain_prod = RX_CHAIN_IDX(prod);
if (bnx_get_buf(sc, NULL, &prod, &chain_prod, &prod_bseq)) {
BNX_PRINTF(sc, "Error filling RX chain: rx_bd[0x%04X]!\n",
@@ -3772,8 +3776,10 @@ bnx_rx_intr(struct bnx_softc *sc)
bus_space_barrier(sc->bnx_btag, sc->bnx_bhandle, 0, 0,
BUS_SPACE_BARRIER_READ);
+ /* Update some debug statistics counters */
DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
sc->rx_low_watermark = sc->free_rx_bd);
+ DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
/*
* Scan through the receive chain as long
@@ -4145,10 +4151,11 @@ bnx_tx_intr(struct bnx_softc *sc)
ifp->if_timer = 0;
/* Clear the tx hardware queue full flag. */
- if ((sc->used_tx_bd + BNX_TX_SLACK_SPACE) < USABLE_TX_BD) {
+ if (sc->used_tx_bd < sc->max_tx_bd) {
DBRUNIF((ifp->if_flags & IFF_OACTIVE),
- printf("%s: TX chain is open for business! Used "
- "tx_bd = %d\n", sc->used_tx_bd));
+ printf("%s: Open TX chain! %d/%d (used/total)\n",
+ sc->bnx_dev.dv_xname, sc->used_tx_bd,
+ sc->max_tx_bd));
ifp->if_flags &= ~IFF_OACTIVE;
}
@@ -4361,13 +4368,8 @@ bnx_tx_encap(struct bnx_softc *sc, struct mbuf **m_head)
return (error);
}
- /*
- * The chip seems to require that at least 16 descriptors be kept
- * empty at all times. Make sure we honor that.
- * XXX Would it be faster to assume worst case scenario for
- * map->dm_nsegs and do this calculation higher up?
- */
- if (map->dm_nsegs > (USABLE_TX_BD - sc->used_tx_bd - BNX_TX_SLACK_SPACE)) {
+ /* Make sure there's room in the chain */
+ if (map->dm_nsegs > (sc->max_tx_bd - sc->used_tx_bd)) {
bus_dmamap_unload(sc->bnx_dmatag, map);
return (ENOBUFS);
}
@@ -4428,9 +4430,10 @@ bnx_tx_encap(struct bnx_softc *sc, struct mbuf **m_head)
sc->tx_mbuf_ptr[chain_prod] = m0;
sc->used_tx_bd += map->dm_nsegs;
+ /* Update some debug statistics counters */
DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
sc->tx_hi_watermark = sc->used_tx_bd);
-
+ DBRUNIF(sc->used_tx_bd == sc->max_tx_bd, sc->tx_full_count++);
DBRUNIF(1, sc->tx_mbuf_alloc++);
DBRUN(BNX_VERBOSE_SEND, bnx_dump_tx_mbuf_chain(sc, chain_prod,
@@ -4473,10 +4476,9 @@ bnx_start(struct ifnet *ifp)
__FUNCTION__, tx_prod, tx_chain_prod, sc->tx_prod_bseq);
/*
- * Keep adding entries while there is space in the ring. We keep
- * BNX_TX_SLACK_SPACE entries unused at all times.
+ * Keep adding entries while there is space in the ring.
*/
- while (sc->used_tx_bd < USABLE_TX_BD - BNX_TX_SLACK_SPACE) {
+ while (sc->used_tx_bd < sc->max_tx_bd) {
/* Check for any frames to send. */
IFQ_POLL(&ifp->if_snd, m_head);
if (m_head == NULL)
@@ -5731,7 +5733,7 @@ bnx_dump_driver_state(struct bnx_softc *sc)
BNX_PRINTF(sc,
"0x%08X/%08X - (sc->rx_low_watermark) rx low watermark\n",
- sc->rx_low_watermark, (u_int32_t) USABLE_RX_BD);
+ sc->rx_low_watermark, sc->max_rx_bd);
BNX_PRINTF(sc,
" 0x%08X - (sc->txmbuf_alloc) tx mbufs allocated\n",
@@ -5745,7 +5747,7 @@ bnx_dump_driver_state(struct bnx_softc *sc)
sc->used_tx_bd);
BNX_PRINTF(sc, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
- sc->tx_hi_watermark, (u_int32_t) USABLE_TX_BD);
+ sc->tx_hi_watermark, sc->max_tx_bd);
BNX_PRINTF(sc,
" 0x%08X - (sc->mbuf_alloc_failed) failed mbuf alloc\n",
diff --git a/sys/dev/pci/if_bnxreg.h b/sys/dev/pci/if_bnxreg.h
index 490bf95e726..3631be964b5 100644
--- a/sys/dev/pci/if_bnxreg.h
+++ b/sys/dev/pci/if_bnxreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_bnxreg.h,v 1.24 2008/05/29 05:36:49 brad Exp $ */
+/* $OpenBSD: if_bnxreg.h,v 1.25 2008/06/13 07:40:30 brad Exp $ */
/*-
* Copyright (c) 2006 Broadcom Corporation
@@ -4429,7 +4429,6 @@ struct l2_fhdr {
#define TOTAL_TX_BD (TOTAL_TX_BD_PER_PAGE * TX_PAGES)
#define USABLE_TX_BD (USABLE_TX_BD_PER_PAGE * TX_PAGES)
#define MAX_TX_BD (TOTAL_TX_BD - 1)
-#define BNX_TX_SLACK_SPACE 16
#define RX_PAGES 2
#define TOTAL_RX_BD_PER_PAGE (BCM_PAGE_SIZE / sizeof(struct rx_bd))
@@ -4437,7 +4436,6 @@ struct l2_fhdr {
#define TOTAL_RX_BD (TOTAL_RX_BD_PER_PAGE * RX_PAGES)
#define USABLE_RX_BD (USABLE_RX_BD_PER_PAGE * RX_PAGES)
#define MAX_RX_BD (TOTAL_RX_BD - 1)
-#define BNX_RX_SLACK_SPACE (MAX_RX_BD - 8)
#define NEXT_TX_BD(x) (((x) & USABLE_TX_BD_PER_PAGE) == \
(USABLE_TX_BD_PER_PAGE - 1)) ? \
@@ -4752,7 +4750,9 @@ struct bnx_softc
/* Track the number of rx_bd and tx_bd's in use. */
u_int16_t free_rx_bd;
+ u_int16_t max_rx_bd;
u_int16_t used_tx_bd;
+ u_int16_t max_tx_bd;
/* Provides access to hardware statistics through sysctl. */
u_int64_t stat_IfHCInOctets;
@@ -4823,7 +4823,9 @@ struct bnx_softc
u_int32_t tx_interrupts;
u_int32_t rx_low_watermark; /* Lowest number of rx_bd's free. */
+ u_int32_t rx_empty_count; /* Number of times the RX chain was empty. */
u_int32_t tx_hi_watermark; /* Greatest number of tx_bd's used. */
+ u_int32_t tx_full_count; /* Number of times the TX chain was full. */
u_int32_t mbuf_alloc_failed; /* Mbuf allocation failure counter. */
u_int32_t l2fhdr_status_errors;
u_int32_t unexpected_attentions;