Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/etherswitch/ukswitch/ukswitch.c
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
MALLOC_DEFINE(M_UKSWITCH, "ukswitch", "ukswitch data structures"); | MALLOC_DEFINE(M_UKSWITCH, "ukswitch", "ukswitch data structures"); | ||||
struct ukswitch_softc { | struct ukswitch_softc { | ||||
struct mtx sc_mtx; /* serialize access to softc */ | struct mtx sc_mtx; /* serialize access to softc */ | ||||
device_t sc_dev; | device_t sc_dev; | ||||
int media; /* cpu port media */ | int media; /* cpu port media */ | ||||
int cpuport; /* which PHY is connected to the CPU */ | int cpuport; /* which PHY is connected to the CPU */ | ||||
int phymask; /* PHYs we manage */ | int phymask; /* PHYs we manage */ | ||||
int phyoffset; /* PHYs register offset */ | |||||
int numports; /* number of ports */ | int numports; /* number of ports */ | ||||
int ifpport[MII_NPHY]; | int ifpport[MII_NPHY]; | ||||
int *portphy; | int *portphy; | ||||
char **ifname; | char **ifname; | ||||
device_t **miibus; | device_t **miibus; | ||||
struct ifnet **ifp; | struct ifnet **ifp; | ||||
struct callout callout_tick; | struct callout callout_tick; | ||||
etherswitch_info_t info; | etherswitch_info_t info; | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST | | ||||
IFF_DRV_RUNNING | IFF_SIMPLEX; | IFF_DRV_RUNNING | IFF_SIMPLEX; | ||||
sc->ifname[port] = malloc(strlen(name)+1, M_UKSWITCH, M_WAITOK); | sc->ifname[port] = malloc(strlen(name)+1, M_UKSWITCH, M_WAITOK); | ||||
bcopy(name, sc->ifname[port], strlen(name)+1); | bcopy(name, sc->ifname[port], strlen(name)+1); | ||||
if_initname(sc->ifp[port], sc->ifname[port], port); | if_initname(sc->ifp[port], sc->ifname[port], port); | ||||
sc->miibus[port] = malloc(sizeof(device_t), M_UKSWITCH, | sc->miibus[port] = malloc(sizeof(device_t), M_UKSWITCH, | ||||
M_WAITOK | M_ZERO); | M_WAITOK | M_ZERO); | ||||
err = mii_attach(sc->sc_dev, sc->miibus[port], sc->ifp[port], | err = mii_attach(sc->sc_dev, sc->miibus[port], sc->ifp[port], | ||||
ukswitch_ifmedia_upd, ukswitch_ifmedia_sts, \ | ukswitch_ifmedia_upd, ukswitch_ifmedia_sts, \ | ||||
BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); | BMSR_DEFCAPMASK, phy + sc->phyoffset, MII_OFFSET_ANY, 0); | ||||
DPRINTF(sc->sc_dev, "%s attached to pseudo interface %s\n", | DPRINTF(sc->sc_dev, "%s attached to pseudo interface %s\n", | ||||
device_get_nameunit(*sc->miibus[port]), | device_get_nameunit(*sc->miibus[port]), | ||||
sc->ifp[port]->if_xname); | sc->ifp[port]->if_xname); | ||||
if (err != 0) { | if (err != 0) { | ||||
device_printf(sc->sc_dev, | device_printf(sc->sc_dev, | ||||
"attaching PHY %d failed\n", | "attaching PHY %d failed\n", | ||||
phy); | phy); | ||||
break; | break; | ||||
Show All 16 Lines | ukswitch_attach(device_t dev) | ||||
sc->sc_dev = dev; | sc->sc_dev = dev; | ||||
mtx_init(&sc->sc_mtx, "ukswitch", NULL, MTX_DEF); | mtx_init(&sc->sc_mtx, "ukswitch", NULL, MTX_DEF); | ||||
strlcpy(sc->info.es_name, device_get_desc(dev), | strlcpy(sc->info.es_name, device_get_desc(dev), | ||||
sizeof(sc->info.es_name)); | sizeof(sc->info.es_name)); | ||||
/* XXX Defaults */ | /* XXX Defaults */ | ||||
sc->numports = 6; | sc->numports = 6; | ||||
sc->phymask = 0x0f; | sc->phymask = 0x0f; | ||||
sc->phyoffset = 0; | |||||
sc->cpuport = -1; | sc->cpuport = -1; | ||||
sc->media = 100; | sc->media = 100; | ||||
(void) resource_int_value(device_get_name(dev), device_get_unit(dev), | (void) resource_int_value(device_get_name(dev), device_get_unit(dev), | ||||
"numports", &sc->numports); | "numports", &sc->numports); | ||||
(void) resource_int_value(device_get_name(dev), device_get_unit(dev), | (void) resource_int_value(device_get_name(dev), device_get_unit(dev), | ||||
"phymask", &sc->phymask); | "phymask", &sc->phymask); | ||||
(void) resource_int_value(device_get_name(dev), device_get_unit(dev), | |||||
"phyoffset", &sc->phyoffset); | |||||
(void) resource_int_value(device_get_name(dev), device_get_unit(dev), | (void) resource_int_value(device_get_name(dev), device_get_unit(dev), | ||||
"cpuport", &sc->cpuport); | "cpuport", &sc->cpuport); | ||||
(void) resource_int_value(device_get_name(dev), device_get_unit(dev), | (void) resource_int_value(device_get_name(dev), device_get_unit(dev), | ||||
"media", &sc->media); | "media", &sc->media); | ||||
/* Support only fast and giga ethernet. */ | /* Support only fast and giga ethernet. */ | ||||
if (sc->media != 100 && sc->media != 1000) | if (sc->media != 100 && sc->media != 1000) | ||||
sc->media = 100; | sc->media = 100; | ||||
▲ Show 20 Lines • Show All 389 Lines • Show Last 20 Lines |