genet(4): Add support for rnd(9).

This commit is contained in:
rin 2021-05-03 10:28:26 +00:00
parent e8311a17cd
commit 6bcd046821
4 changed files with 26 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: genet_acpi.c,v 1.4 2021/01/29 15:49:55 thorpej Exp $ */
/* $NetBSD: genet_acpi.c,v 1.5 2021/05/03 10:28:26 rin Exp $ */
/*-
* Copyright (c) 2020 Jared McNeill <jmcneill@invisible.ca>
@ -29,13 +29,15 @@
#include "opt_net_mpsafe.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: genet_acpi.c,v 1.4 2021/01/29 15:49:55 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: genet_acpi.c,v 1.5 2021/05/03 10:28:26 rin Exp $");
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/cpu.h>
#include <sys/device.h>
#include <sys/rndsource.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_ether.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: genet_fdt.c,v 1.5 2021/03/08 13:15:06 mlelstv Exp $ */
/* $NetBSD: genet_fdt.c,v 1.6 2021/05/03 10:28:26 rin Exp $ */
/*-
* Copyright (c) 2020 Jared McNeill <jmcneill@invisible.ca>
@ -29,7 +29,7 @@
#include "opt_net_mpsafe.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: genet_fdt.c,v 1.5 2021/03/08 13:15:06 mlelstv Exp $");
__KERNEL_RCSID(0, "$NetBSD: genet_fdt.c,v 1.6 2021/05/03 10:28:26 rin Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@ -38,6 +38,8 @@ __KERNEL_RCSID(0, "$NetBSD: genet_fdt.c,v 1.5 2021/03/08 13:15:06 mlelstv Exp $"
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/rndsource.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_ether.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: bcmgenet.c,v 1.8 2021/03/08 13:14:44 mlelstv Exp $ */
/* $NetBSD: bcmgenet.c,v 1.9 2021/05/03 10:28:26 rin Exp $ */
/*-
* Copyright (c) 2020 Jared McNeill <jmcneill@invisible.ca>
@ -34,7 +34,7 @@
#include "opt_ddb.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.8 2021/03/08 13:14:44 mlelstv Exp $");
__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.9 2021/05/03 10:28:26 rin Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@ -46,6 +46,8 @@ __KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.8 2021/03/08 13:14:44 mlelstv Exp $")
#include <sys/callout.h>
#include <sys/cprng.h>
#include <sys/rndsource.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_ether.h>
@ -681,6 +683,7 @@ genet_rxintr(struct genet_softc *sc, int qid)
int error, index, len, n;
struct mbuf *m, *m0;
uint32_t status, pidx, total;
int pkts = 0;
pidx = RD4(sc, GENET_RX_DMA_PROD_INDEX(qid)) & 0xffff;
total = (pidx - sc->sc_rx.cidx) & 0xffff;
@ -749,6 +752,7 @@ genet_rxintr(struct genet_softc *sc, int qid)
m_adj(m, ETHER_ALIGN);
if_percpuq_enqueue(ifp->if_percpuq, m);
++pkts;
next:
index = RX_NEXT(index);
@ -756,6 +760,9 @@ next:
sc->sc_rx.cidx = (sc->sc_rx.cidx + 1) & 0xffff;
WR4(sc, GENET_RX_DMA_CONS_INDEX(qid), sc->sc_rx.cidx);
}
if (pkts != 0)
rnd_add_uint32(&sc->sc_rndsource, pkts);
}
static void
@ -785,6 +792,9 @@ genet_txintr(struct genet_softc *sc, int qid)
}
if_statadd(ifp, if_opackets, pkts);
if (pkts != 0)
rnd_add_uint32(&sc->sc_rndsource, pkts);
}
static void
@ -1100,6 +1110,9 @@ genet_attach(struct genet_softc *sc)
/* Attach ethernet interface */
ether_ifattach(ifp, eaddr);
rnd_attach_source(&sc->sc_rndsource, ifp->if_xname, RND_TYPE_NET,
RND_FLAG_DEFAULT);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: bcmgenetvar.h,v 1.3 2021/03/08 13:14:44 mlelstv Exp $ */
/* $NetBSD: bcmgenetvar.h,v 1.4 2021/05/03 10:28:26 rin Exp $ */
/*-
* Copyright (c) 2020 Jared McNeill <jmcneill@invisible.ca>
@ -70,6 +70,8 @@ struct genet_softc {
struct genet_ring sc_tx;
struct genet_ring sc_rx;
krndsource_t sc_rndsource;
};
int genet_attach(struct genet_softc *);