Ejemplo n.º 1
0
void
tsec_get_hwaddr(struct tsec_softc *sc, uint8_t *addr)
{
	union {
		uint32_t reg[2];
		uint8_t addr[6];
	} hw;
	int i;

	hw.reg[0] = hw.reg[1] = 0;

	/* Retrieve the hardware address from the device tree. */
	i = OF_getprop(sc->node, "local-mac-address", (void *)hw.addr, 6);
	if (i == 6 && (hw.reg[0] != 0 || hw.reg[1] != 0)) {
		bcopy(hw.addr, addr, 6);
		return;
	}

	/* Also try the mac-address property, which is second-best */
	i = OF_getprop(sc->node, "mac-address", (void *)hw.addr, 6);
	if (i == 6 && (hw.reg[0] != 0 || hw.reg[1] != 0)) {
		bcopy(hw.addr, addr, 6);
		return;
	}

	/*
	 * Fall back -- use the currently programmed address in the hope that
	 * it was set be firmware...
	 */
	hw.reg[0] = TSEC_READ(sc, TSEC_REG_MACSTNADDR1);
	hw.reg[1] = TSEC_READ(sc, TSEC_REG_MACSTNADDR2);
	for (i = 0; i < 6; i++)
		addr[5-i] = hw.addr[i];
}
Ejemplo n.º 2
0
void
tsec_get_hwaddr(struct tsec_softc *sc, uint8_t *addr)
{
	union {
		uint32_t reg[2];
		uint8_t addr[6];
	} curmac;
	uint32_t a[6];
	device_t parent;
	uintptr_t macaddr;
	int i;

	parent = device_get_parent(sc->dev);
	if (BUS_READ_IVAR(parent, sc->dev, OCPBUS_IVAR_MACADDR,
	    &macaddr) == 0) {
		bcopy((uint8_t *)macaddr, addr, 6);
		return;
	}

	/*
	 * Fall back -- use the currently programmed address in the hope that
	 * it was set be firmware...
	 */
	curmac.reg[0] = TSEC_READ(sc, TSEC_REG_MACSTNADDR1);
	curmac.reg[1] = TSEC_READ(sc, TSEC_REG_MACSTNADDR2);
	for (i = 0; i < 6; i++)
		a[5-i] = curmac.addr[i];

	addr[0] = a[0];
	addr[1] = a[1];
	addr[2] = a[2];
	addr[3] = a[3];
	addr[4] = a[4];
	addr[5] = a[5];
}
Ejemplo n.º 3
0
static int
tsec_ocp_probe(device_t dev)
{
	struct tsec_softc *sc;
	device_t parent;
	uintptr_t devtype;
	int error;
	uint32_t id;

	parent = device_get_parent(dev);

	error = BUS_READ_IVAR(parent, dev, OCPBUS_IVAR_DEVTYPE, &devtype);
	if (error)
		return (error);
	if (devtype != OCPBUS_DEVTYPE_TSEC)
		return (ENXIO);

	sc = device_get_softc(dev);

	sc->sc_rrid = 0;
	sc->sc_rres = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->sc_rrid,
	    0ul, ~0ul, TSEC_IO_SIZE, RF_ACTIVE);
	if (sc->sc_rres == NULL)
		return (ENXIO);

	sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres);
	sc->sc_bas.bst = rman_get_bustag(sc->sc_rres);

	/* Check if we are eTSEC (enhanced TSEC) */
	id = TSEC_READ(sc, TSEC_REG_ID);
	sc->is_etsec = ((id >> 16) == TSEC_ETSEC_ID) ? 1 : 0;
	id |= TSEC_READ(sc, TSEC_REG_ID2);

	bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rrid, sc->sc_rres);

	if (id == 0) {
		device_printf(dev, "could not identify TSEC type\n");
		return (ENXIO);
	}

	if (sc->is_etsec)
		device_set_desc(dev, "Enhanced Three-Speed Ethernet Controller");
	else
		device_set_desc(dev, "Three-Speed Ethernet Controller");

	return (BUS_PROBE_DEFAULT);
}
Ejemplo n.º 4
0
static int
tsec_fdt_probe(device_t dev)
{
	struct tsec_softc *sc;
	uint32_t id;

	if (!ofw_bus_status_okay(dev))
		return (ENXIO);

	if (ofw_bus_get_type(dev) == NULL ||
	    strcmp(ofw_bus_get_type(dev), "network") != 0)
		return (ENXIO);

	if (!ofw_bus_is_compatible(dev, "gianfar"))
		return (ENXIO);

	sc = device_get_softc(dev);

	sc->sc_rrid = 0;
	sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rrid,
	    RF_ACTIVE);
	if (sc->sc_rres == NULL)
		return (ENXIO);

	sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres);
	sc->sc_bas.bst = rman_get_bustag(sc->sc_rres);

	/* Check if we are eTSEC (enhanced TSEC) */
	id = TSEC_READ(sc, TSEC_REG_ID);
	sc->is_etsec = ((id >> 16) == TSEC_ETSEC_ID) ? 1 : 0;
	id |= TSEC_READ(sc, TSEC_REG_ID2);

	bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rrid, sc->sc_rres);

	if (id == 0) {
		device_printf(dev, "could not identify TSEC type\n");
		return (ENXIO);
	}

	if (sc->is_etsec)
		device_set_desc(dev, "Enhanced Three-Speed Ethernet Controller");
	else
		device_set_desc(dev, "Three-Speed Ethernet Controller");

	return (BUS_PROBE_DEFAULT);
}
Ejemplo n.º 5
0
void
tsec_get_hwaddr(struct tsec_softc *sc, uint8_t *addr)
{
	union {
		uint32_t reg[2];
		uint8_t addr[6];
	} curmac;
	uint32_t a[6];
	uint8_t lma[6];
	int i;

	/*
	 * Retrieve hw address from the device tree.
	 */
	i = OF_getprop(sc->node, "local-mac-address", (void *)lma, 6);
	if (i == 6) {
		bcopy(lma, addr, 6);
		return;
	}

	/*
	 * Fall back -- use the currently programmed address in the hope that
	 * it was set be firmware...
	 */
	curmac.reg[0] = TSEC_READ(sc, TSEC_REG_MACSTNADDR1);
	curmac.reg[1] = TSEC_READ(sc, TSEC_REG_MACSTNADDR2);
	for (i = 0; i < 6; i++)
		a[5-i] = curmac.addr[i];

	addr[0] = a[0];
	addr[1] = a[1];
	addr[2] = a[2];
	addr[3] = a[3];
	addr[4] = a[4];
	addr[5] = a[5];
}