Lines Matching defs:sc
89 struct mtkswitch_softc *sc;
99 sc = device_get_softc(dev);
100 bzero(sc, sizeof(*sc));
101 sc->sc_switchtype = switch_type;
109 mtkswitch_attach_phys(struct mtkswitch_softc *sc)
115 snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->sc_dev));
116 for (phy = 0; phy < sc->numphys; phy++) {
117 if ((sc->phymap & (1u << phy)) == 0) {
118 sc->ifp[phy] = NULL;
119 sc->ifname[phy] = NULL;
120 sc->miibus[phy] = NULL;
123 sc->ifp[phy] = if_alloc(IFT_ETHER);
124 sc->ifp[phy]->if_softc = sc;
125 sc->ifp[phy]->if_flags |= IFF_UP | IFF_BROADCAST |
127 sc->ifname[phy] = malloc(strlen(name) + 1, M_DEVBUF, M_WAITOK);
128 bcopy(name, sc->ifname[phy], strlen(name) + 1);
129 if_initname(sc->ifp[phy], sc->ifname[phy],
131 err = mii_attach(sc->sc_dev, &sc->miibus[phy], sc->ifp[phy],
135 device_printf(sc->sc_dev,
139 DPRINTF(sc->sc_dev, "%s attached to pseudo interface "
140 "%s\n", device_get_nameunit(sc->miibus[phy]),
141 sc->ifp[phy]->if_xname);
148 mtkswitch_set_vlan_mode(struct mtkswitch_softc *sc, uint32_t mode)
152 if ((mode & sc->info.es_vlan_caps) != mode)
155 sc->vlan_mode = mode;
158 sc->hal.mtkswitch_vlan_init_hw(sc);
166 struct mtkswitch_softc *sc;
170 sc = device_get_softc(dev);
172 /* sc->sc_switchtype is already decided in mtkswitch_probe() */
173 sc->numports = MTKSWITCH_MAX_PORTS;
174 sc->numphys = MTKSWITCH_MAX_PHYS;
175 sc->cpuport = MTKSWITCH_CPU_PORT;
176 sc->sc_dev = dev;
179 if (sc->sc_switchtype == MTK_SWITCH_NONE) {
184 if (sc->sc_switchtype == MTK_SWITCH_MT7620 ||
185 sc->sc_switchtype == MTK_SWITCH_MT7621)
186 mtk_attach_switch_mt7620(sc);
188 mtk_attach_switch_rt3050(sc);
192 sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
194 if (sc->sc_res == NULL) {
199 mtx_init(&sc->sc_mtx, "mtkswitch", NULL, MTX_DEF);
202 if (sc->hal.mtkswitch_reset(sc)) {
207 err = sc->hal.mtkswitch_hw_setup(sc);
212 err = sc->hal.mtkswitch_hw_global_setup(sc);
218 for (port = 0; port < sc->numports; port++) {
219 sc->hal.mtkswitch_port_init(sc, port);
223 err = mtkswitch_attach_phys(sc);
229 err = mtkswitch_set_vlan_mode(sc, ETHERSWITCH_VLAN_DOT1Q);
238 callout_init_mtx(&sc->callout_tick, &sc->sc_mtx, 0);
240 MTKSWITCH_LOCK(sc);
241 mtkswitch_tick(sc);
242 MTKSWITCH_UNLOCK(sc);
250 struct mtkswitch_softc *sc = device_get_softc(dev);
257 callout_drain(&sc->callout_tick);
260 if (sc->ifp[phy] != NULL)
261 if_free(sc->ifp[phy]);
262 free(sc->ifname[phy], M_DEVBUF);
265 mtx_destroy(&sc->sc_mtx);
286 mtkswitch_miiforport(struct mtkswitch_softc *sc, int port)
290 if (phy < 0 || phy >= MTKSWITCH_MAX_PHYS || sc->miibus[phy] == NULL)
293 return (device_get_softc(sc->miibus[phy]));
297 mtkswitch_ifpforport(struct mtkswitch_softc *sc, int port)
304 return (sc->ifp[phy]);
348 mtkswitch_miipollstat(struct mtkswitch_softc *sc)
355 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED);
357 for (i = 0; i < sc->numphys; i++) {
358 if (sc->miibus[i] == NULL)
360 mii = device_get_softc(sc->miibus[i]);
361 portstatus = sc->hal.mtkswitch_get_port_status(sc,
383 sc->hal.mtkswitch_atu_flush(sc);
389 struct mtkswitch_softc *sc = arg;
391 mtkswitch_miipollstat(sc);
392 callout_reset(&sc->callout_tick, hz, mtkswitch_tick, sc);
398 struct mtkswitch_softc *sc = device_get_softc(dev);
400 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED);
401 MTKSWITCH_LOCK(sc);
407 struct mtkswitch_softc *sc = device_get_softc(dev);
409 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED);
410 MTKSWITCH_UNLOCK(sc);
416 struct mtkswitch_softc *sc = device_get_softc(dev);
418 return (&sc->info);
422 mtkswitch_is_cpuport(struct mtkswitch_softc *sc, int port)
425 return (sc->cpuport == port);
431 struct mtkswitch_softc *sc;
436 sc = device_get_softc(dev);
437 if (p->es_port < 0 || p->es_port > sc->info.es_nports)
440 err = sc->hal.mtkswitch_port_vlan_get(sc, p);
444 mii = mtkswitch_miiforport(sc, p->es_port);
445 if (mtkswitch_is_cpuport(sc, p->es_port)) {
474 struct mtkswitch_softc *sc;
479 sc = device_get_softc(dev);
480 if (p->es_port < 0 || p->es_port > sc->info.es_nports)
484 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q) {
485 err = sc->hal.mtkswitch_port_vlan_setup(sc, p);
491 if (mtkswitch_is_cpuport(sc, p->es_port))
494 mii = mtkswitch_miiforport(sc, p->es_port);
498 ifp = mtkswitch_ifpforport(sc, p->es_port);
514 struct mtkswitch_softc *sc = if_getsoftc(ifp);
515 struct mii_data *mii = mtkswitch_miiforport(sc, if_getdunit(ifp));
526 struct mtkswitch_softc *sc = if_getsoftc(ifp);
527 struct mii_data *mii = mtkswitch_miiforport(sc, if_getdunit(ifp));
529 DPRINTF(sc->sc_dev, "%s\n", __func__);
541 struct mtkswitch_softc *sc;
543 sc = device_get_softc(dev);
547 conf->vlan_mode = sc->vlan_mode;
555 struct mtkswitch_softc *sc;
558 sc = device_get_softc(dev);
562 err = mtkswitch_set_vlan_mode(sc, conf->vlan_mode);
573 struct mtkswitch_softc *sc = device_get_softc(dev);
575 return (sc->hal.mtkswitch_vlan_getvgroup(sc, e));
581 struct mtkswitch_softc *sc = device_get_softc(dev);
583 return (sc->hal.mtkswitch_vlan_setvgroup(sc, e));
589 struct mtkswitch_softc *sc = device_get_softc(dev);
591 return (sc->hal.mtkswitch_phy_read(dev, phy, reg));
597 struct mtkswitch_softc *sc = device_get_softc(dev);
599 return (sc->hal.mtkswitch_phy_write(dev, phy, reg, val));
605 struct mtkswitch_softc *sc = device_get_softc(dev);
607 return (sc->hal.mtkswitch_reg_read(dev, addr));
613 struct mtkswitch_softc *sc = device_get_softc(dev);
615 return (sc->hal.mtkswitch_reg_write(dev, addr, value));