#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <dev/ofw/fdt.h>
#include <dev/ofw/openfirm.h>
#include <machine/bus.h>
#include <machine/fdt.h>
#include <octeon/dev/ogxreg.h>
#include <octeon/dev/ogxvar.h>
struct ogxnexus_softc {
struct device sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
int sc_bgxid;
};
#define NEXUS_RD_8(sc, reg) \
bus_space_write_8((sc)->sc_iot, (sc)->sc_ioh, (reg))
#define NEXUS_WR_8(sc, reg, val) \
bus_space_write_8((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
int ogxnexus_match(struct device *, void *, void *);
void ogxnexus_attach(struct device *, struct device *, void *);
const struct cfattach ogxnexus_ca = {
sizeof(struct ogxnexus_softc), ogxnexus_match, ogxnexus_attach
};
struct cfdriver ogxnexus_cd = {
NULL, "ogxnexus", DV_DULL
};
int
ogxnexus_match(struct device *parent, void *match, void *aux)
{
struct fdt_attach_args *faa = aux;
return OF_is_compatible(faa->fa_node, "cavium,octeon-7890-bgx");
}
void
ogxnexus_attach(struct device *parent, struct device *self, void *aux)
{
struct ogx_attach_args oaa;
struct fdt_attach_args *faa = aux;
struct ogxnexus_softc *sc = (struct ogxnexus_softc *)self;
int i, node;
if (faa->fa_nreg < 1) {
printf(": no registers\n");
return;
}
sc->sc_bgxid = (faa->fa_reg[0].addr >> 24) & 7;
sc->sc_iot = faa->fa_iot;
if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, faa->fa_reg[0].size,
0, &sc->sc_ioh)) {
printf(": can't map IO space\n");
return;
}
for (i = 0; i < BGX_NCAM; i++)
NEXUS_WR_8(sc, BGX_CMR_RX_ADR_CAM(i), 0);
NEXUS_WR_8(sc, BGX_CMR_RX_LMACS, BGX_NLMAC);
NEXUS_WR_8(sc, BGX_CMR_TX_LMACS, BGX_NLMAC);
printf("\n");
for (node = OF_child(faa->fa_node); node != 0; node = OF_peer(node)) {
memset(&oaa, 0, sizeof(oaa));
oaa.oaa_node = node;
oaa.oaa_bgxid = sc->sc_bgxid;
oaa.oaa_iot = sc->sc_iot;
oaa.oaa_ioh = sc->sc_ioh;
oaa.oaa_dmat = faa->fa_dmat;
config_found(&sc->sc_dev, &oaa, NULL);
}
}