add rnd(4) hooks. Note that interrupts on bge hardware may occur

with certain patterns, especially when the interrupt mitigation
logic kicks in. So this might be a very weak entropy source.
This commit is contained in:
mlelstv 2008-06-17 06:08:46 +00:00
parent f1f0ceb1ae
commit 2f1d68867c
2 changed files with 26 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_bge.c,v 1.147 2008/06/17 06:04:07 mlelstv Exp $ */ /* $NetBSD: if_bge.c,v 1.148 2008/06/17 06:08:46 mlelstv Exp $ */
/* /*
* Copyright (c) 2001 Wind River Systems * Copyright (c) 2001 Wind River Systems
@ -79,10 +79,11 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.147 2008/06/17 06:04:07 mlelstv Exp $"); __KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.148 2008/06/17 06:08:46 mlelstv Exp $");
#include "bpfilter.h" #include "bpfilter.h"
#include "vlan.h" #include "vlan.h"
#include "rnd.h"
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -100,6 +101,10 @@ __KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.147 2008/06/17 06:04:07 mlelstv Exp $")
#include <net/if_media.h> #include <net/if_media.h>
#include <net/if_ether.h> #include <net/if_ether.h>
#if NRND > 0
#include <sys/rnd.h>
#endif
#ifdef INET #ifdef INET
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/in_systm.h> #include <netinet/in_systm.h>
@ -2745,6 +2750,10 @@ bge_attach(device_t parent, device_t self, void *aux)
if_attach(ifp); if_attach(ifp);
DPRINTFN(5, ("ether_ifattach\n")); DPRINTFN(5, ("ether_ifattach\n"));
ether_ifattach(ifp, eaddr); ether_ifattach(ifp, eaddr);
#if NRND > 0
rnd_attach_source(&sc->rnd_source, device_xname(sc->bge_dev),
RND_TYPE_NET, 0);
#endif
#ifdef BGE_EVENT_COUNTERS #ifdef BGE_EVENT_COUNTERS
/* /*
* Attach event counters. * Attach event counters.
@ -2971,6 +2980,11 @@ bge_rxeof(struct bge_softc *sc)
tosync = sc->bge_rdata->bge_status_block.bge_idx[0].bge_rx_prod_idx - tosync = sc->bge_rdata->bge_status_block.bge_idx[0].bge_rx_prod_idx -
sc->bge_rx_saved_considx; sc->bge_rx_saved_considx;
#if NRND > 0
if (tosync != 0 && RND_ENABLED(&sc->rnd_source))
rnd_add_uint32(&sc->rnd_source, tosync);
#endif
toff = offset + (sc->bge_rx_saved_considx * sizeof (struct bge_rx_bd)); toff = offset + (sc->bge_rx_saved_considx * sizeof (struct bge_rx_bd));
if (tosync < 0) { if (tosync < 0) {
@ -3124,6 +3138,11 @@ bge_txeof(struct bge_softc *sc)
tosync = sc->bge_rdata->bge_status_block.bge_idx[0].bge_tx_cons_idx - tosync = sc->bge_rdata->bge_status_block.bge_idx[0].bge_tx_cons_idx -
sc->bge_tx_saved_considx; sc->bge_tx_saved_considx;
#if NRND > 0
if (tosync != 0 && RND_ENABLED(&sc->rnd_source))
rnd_add_uint32(&sc->rnd_source, tosync);
#endif
toff = offset + (sc->bge_tx_saved_considx * sizeof (struct bge_tx_bd)); toff = offset + (sc->bge_tx_saved_considx * sizeof (struct bge_tx_bd));
if (tosync < 0) { if (tosync < 0) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_bgereg.h,v 1.45 2007/12/09 20:28:08 jmcneill Exp $ */ /* $NetBSD: if_bgereg.h,v 1.46 2008/06/17 06:12:10 mlelstv 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
@ -2439,4 +2439,8 @@ struct bge_softc {
int bge_pending_rxintr_change; int bge_pending_rxintr_change;
SLIST_HEAD(, txdmamap_pool_entry) txdma_list; SLIST_HEAD(, txdmamap_pool_entry) txdma_list;
struct txdmamap_pool_entry *txdma[BGE_TX_RING_CNT]; struct txdmamap_pool_entry *txdma[BGE_TX_RING_CNT];
#if NRND > 0
rndsource_element_t rnd_source; /* random source */
#endif
}; };