Lines Matching +full:conf +full:- +full:mdio

1 /*-
3 * Copyright (c) 2011-2012 Stefan Bethke.
51 #include <dev/mdio/mdio.h>
75 { "ralink,rt3050-esw", MTK_SWITCH_RT3050 },
76 { "ralink,rt3352-esw", MTK_SWITCH_RT3352 },
77 { "ralink,rt5350-esw", MTK_SWITCH_RT5350 },
78 { "mediatek,mt7620-gsw", MTK_SWITCH_MT7620 },
79 { "mediatek,mt7621-gsw", MTK_SWITCH_MT7621 },
80 { "mediatek,mt7628-esw", MTK_SWITCH_MT7628 },
95 switch_type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; in mtkswitch_probe()
101 sc->sc_switchtype = switch_type; in mtkswitch_probe()
115 snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->sc_dev)); in mtkswitch_attach_phys()
116 for (phy = 0; phy < sc->numphys; phy++) { in mtkswitch_attach_phys()
117 if ((sc->phymap & (1u << phy)) == 0) { in mtkswitch_attach_phys()
118 sc->ifp[phy] = NULL; in mtkswitch_attach_phys()
119 sc->ifname[phy] = NULL; in mtkswitch_attach_phys()
120 sc->miibus[phy] = NULL; in mtkswitch_attach_phys()
123 sc->ifp[phy] = if_alloc(IFT_ETHER); in mtkswitch_attach_phys()
124 sc->ifp[phy]->if_softc = sc; in mtkswitch_attach_phys()
125 sc->ifp[phy]->if_flags |= IFF_UP | IFF_BROADCAST | in mtkswitch_attach_phys()
127 sc->ifname[phy] = malloc(strlen(name) + 1, M_DEVBUF, M_WAITOK); in mtkswitch_attach_phys()
128 bcopy(name, sc->ifname[phy], strlen(name) + 1); in mtkswitch_attach_phys()
129 if_initname(sc->ifp[phy], sc->ifname[phy], in mtkswitch_attach_phys()
131 err = mii_attach(sc->sc_dev, &sc->miibus[phy], sc->ifp[phy], in mtkswitch_attach_phys()
135 device_printf(sc->sc_dev, in mtkswitch_attach_phys()
139 DPRINTF(sc->sc_dev, "%s attached to pseudo interface " in mtkswitch_attach_phys()
140 "%s\n", device_get_nameunit(sc->miibus[phy]), in mtkswitch_attach_phys()
141 sc->ifp[phy]->if_xname); in mtkswitch_attach_phys()
152 if ((mode & sc->info.es_vlan_caps) != mode) in mtkswitch_set_vlan_mode()
155 sc->vlan_mode = mode; in mtkswitch_set_vlan_mode()
158 sc->hal.mtkswitch_vlan_init_hw(sc); in mtkswitch_set_vlan_mode()
172 /* sc->sc_switchtype is already decided in mtkswitch_probe() */ in mtkswitch_attach()
173 sc->numports = MTKSWITCH_MAX_PORTS; in mtkswitch_attach()
174 sc->numphys = MTKSWITCH_MAX_PHYS; in mtkswitch_attach()
175 sc->cpuport = MTKSWITCH_CPU_PORT; in mtkswitch_attach()
176 sc->sc_dev = dev; in mtkswitch_attach()
179 if (sc->sc_switchtype == MTK_SWITCH_NONE) { in mtkswitch_attach()
184 if (sc->sc_switchtype == MTK_SWITCH_MT7620 || in mtkswitch_attach()
185 sc->sc_switchtype == MTK_SWITCH_MT7621) in mtkswitch_attach()
192 sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in mtkswitch_attach()
194 if (sc->sc_res == NULL) { in mtkswitch_attach()
199 mtx_init(&sc->sc_mtx, "mtkswitch", NULL, MTX_DEF); in mtkswitch_attach()
202 if (sc->hal.mtkswitch_reset(sc)) { in mtkswitch_attach()
207 err = sc->hal.mtkswitch_hw_setup(sc); in mtkswitch_attach()
212 err = sc->hal.mtkswitch_hw_global_setup(sc); in mtkswitch_attach()
218 for (port = 0; port < sc->numports; port++) { in mtkswitch_attach()
219 sc->hal.mtkswitch_port_init(sc, port); in mtkswitch_attach()
238 callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0); in mtkswitch_attach()
253 callout_drain(&sc->callout_tick); in mtkswitch_detach()
256 if (sc->miibus[phy] != NULL) in mtkswitch_detach()
257 device_delete_child(dev, sc->miibus[phy]); in mtkswitch_detach()
258 if (sc->ifp[phy] != NULL) in mtkswitch_detach()
259 if_free(sc->ifp[phy]); in mtkswitch_detach()
260 free(sc->ifname[phy], M_DEVBUF); in mtkswitch_detach()
264 mtx_destroy(&sc->sc_mtx); in mtkswitch_detach()
269 /* PHY <-> port mapping is currently 1:1 */
289 if (phy < 0 || phy >= MTKSWITCH_MAX_PHYS || sc->miibus[phy] == NULL) in mtkswitch_miiforport()
292 return (device_get_softc(sc->miibus[phy])); in mtkswitch_miiforport()
303 return (sc->ifp[phy]); in mtkswitch_ifpforport()
356 for (i = 0; i < sc->numphys; i++) { in mtkswitch_miipollstat()
357 if (sc->miibus[i] == NULL) in mtkswitch_miipollstat()
359 mii = device_get_softc(sc->miibus[i]); in mtkswitch_miipollstat()
360 portstatus = sc->hal.mtkswitch_get_port_status(sc, in mtkswitch_miipollstat()
363 /* If a port has flapped - mark it so we can flush the ATU */ in mtkswitch_miipollstat()
364 if (((mii->mii_media_status & IFM_ACTIVE) == 0 && in mtkswitch_miipollstat()
366 ((mii->mii_media_status & IFM_ACTIVE) != 0 && in mtkswitch_miipollstat()
371 mtkswitch_update_ifmedia(portstatus, &mii->mii_media_status, in mtkswitch_miipollstat()
372 &mii->mii_media_active); in mtkswitch_miipollstat()
373 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) { in mtkswitch_miipollstat()
374 if (IFM_INST(mii->mii_media.ifm_cur->ifm_media) != in mtkswitch_miipollstat()
375 miisc->mii_inst) in mtkswitch_miipollstat()
382 sc->hal.mtkswitch_atu_flush(sc); in mtkswitch_miipollstat()
391 callout_reset(&sc->callout_tick, hz, mtkswitch_tick, sc); in mtkswitch_tick()
417 return (&sc->info); in mtkswitch_getinfo()
424 return (sc->cpuport == port); in mtkswitch_is_cpuport()
436 if (p->es_port < 0 || p->es_port > sc->info.es_nports) in mtkswitch_getport()
439 err = sc->hal.mtkswitch_port_vlan_get(sc, p); in mtkswitch_getport()
443 mii = mtkswitch_miiforport(sc, p->es_port); in mtkswitch_getport()
444 if (mtkswitch_is_cpuport(sc, p->es_port)) { in mtkswitch_getport()
447 p->es_flags |= ETHERSWITCH_PORT_CPU; in mtkswitch_getport()
448 ifmr = &p->es_ifmr; in mtkswitch_getport()
449 ifmr->ifm_count = 0; in mtkswitch_getport()
450 ifmr->ifm_current = ifmr->ifm_active = in mtkswitch_getport()
452 ifmr->ifm_mask = 0; in mtkswitch_getport()
453 ifmr->ifm_status = IFM_ACTIVE | IFM_AVALID; in mtkswitch_getport()
455 err = ifmedia_ioctl(mii->mii_ifp, &p->es_ifr, in mtkswitch_getport()
456 &mii->mii_media, SIOCGIFMEDIA); in mtkswitch_getport()
460 ifmr = &p->es_ifmr; in mtkswitch_getport()
461 ifmr->ifm_count = 0; in mtkswitch_getport()
462 ifmr->ifm_current = ifmr->ifm_active = IFM_NONE; in mtkswitch_getport()
463 ifmr->ifm_mask = 0; in mtkswitch_getport()
464 ifmr->ifm_status = 0; in mtkswitch_getport()
479 if (p->es_port < 0 || p->es_port > sc->info.es_nports) in mtkswitch_setport()
483 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q) { in mtkswitch_setport()
484 err = sc->hal.mtkswitch_port_vlan_setup(sc, p); in mtkswitch_setport()
490 if (mtkswitch_is_cpuport(sc, p->es_port)) in mtkswitch_setport()
493 mii = mtkswitch_miiforport(sc, p->es_port); in mtkswitch_setport()
497 ifp = mtkswitch_ifpforport(sc, p->es_port); in mtkswitch_setport()
499 ifm = &mii->mii_media; in mtkswitch_setport()
500 return (ifmedia_ioctl(ifp, &p->es_ifr, ifm, SIOCSIFMEDIA)); in mtkswitch_setport()
528 DPRINTF(sc->sc_dev, "%s\n", __func__); in mtkswitch_ifmedia_sts()
533 ifmr->ifm_active = mii->mii_media_active; in mtkswitch_ifmedia_sts()
534 ifmr->ifm_status = mii->mii_media_status; in mtkswitch_ifmedia_sts()
538 mtkswitch_getconf(device_t dev, etherswitch_conf_t *conf) in mtkswitch_getconf() argument
545 conf->cmd = ETHERSWITCH_CONF_VLAN_MODE; in mtkswitch_getconf()
546 conf->vlan_mode = sc->vlan_mode; in mtkswitch_getconf()
552 mtkswitch_setconf(device_t dev, etherswitch_conf_t *conf) in mtkswitch_setconf() argument
560 if (conf->cmd & ETHERSWITCH_CONF_VLAN_MODE) { in mtkswitch_setconf()
561 err = mtkswitch_set_vlan_mode(sc, conf->vlan_mode); in mtkswitch_setconf()
574 return (sc->hal.mtkswitch_vlan_getvgroup(sc, e)); in mtkswitch_getvgroup()
582 return (sc->hal.mtkswitch_vlan_setvgroup(sc, e)); in mtkswitch_setvgroup()
590 return (sc->hal.mtkswitch_phy_read(dev, phy, reg)); in mtkswitch_readphy()
598 return (sc->hal.mtkswitch_phy_write(dev, phy, reg, val)); in mtkswitch_writephy()
606 return (sc->hal.mtkswitch_reg_read(dev, addr)); in mtkswitch_readreg()
614 return (sc->hal.mtkswitch_reg_write(dev, addr, value)); in mtkswitch_writereg()
631 /* MDIO interface */
658 DRIVER_MODULE(mdio, mtkswitch, mdio_driver, 0, 0);