Lines Matching full:sc

215 	e6000sw_softc_t *sc;  in e6000sw_probe()  local
224 sc = device_get_softc(dev); in e6000sw_probe()
225 sc->dev = dev; in e6000sw_probe()
241 sc->swid = MV88E6190; in e6000sw_probe()
247 sc->node = switch_node; in e6000sw_probe()
249 if (OF_getencprop(sc->node, "reg", &sc->sw_addr, in e6000sw_probe()
250 sizeof(sc->sw_addr)) < 0) in e6000sw_probe()
253 if (resource_int_value(device_get_name(sc->dev), in e6000sw_probe()
254 device_get_unit(sc->dev), "addr", &sc->sw_addr) != 0) in e6000sw_probe()
256 if (resource_int_value(device_get_name(sc->dev), in e6000sw_probe()
257 device_get_unit(sc->dev), "is6190", &is_6190) != 0) { in e6000sw_probe()
262 resource_int_value(device_get_name(sc->dev), in e6000sw_probe()
263 device_get_unit(sc->dev), "is8190", &is_6190); in e6000sw_probe()
265 resource_int_value(device_get_name(sc->dev), in e6000sw_probe()
266 device_get_unit(sc->dev), "is6190x", &is_6190x); in e6000sw_probe()
273 sc->swid = MV88E6190; in e6000sw_probe()
275 sc->swid = MV88E6190X; in e6000sw_probe()
277 if (sc->sw_addr < 0 || sc->sw_addr > 32) in e6000sw_probe()
284 sx_init(&sc->sx, "e6000sw_tmp"); in e6000sw_probe()
285 E6000SW_LOCK(sc); in e6000sw_probe()
286 sc->swid = e6000sw_readreg(sc, REG_PORT(sc, 0), SWITCH_ID) & 0xfff0; in e6000sw_probe()
287 E6000SW_UNLOCK(sc); in e6000sw_probe()
288 sx_destroy(&sc->sx); in e6000sw_probe()
290 switch (sc->swid) { in e6000sw_probe()
293 sc->phy_base = 0x10; in e6000sw_probe()
294 sc->num_ports = 6; in e6000sw_probe()
298 sc->phy_base = 0x10; in e6000sw_probe()
299 sc->num_ports = 6; in e6000sw_probe()
303 sc->num_ports = 7; in e6000sw_probe()
307 sc->num_ports = 7; in e6000sw_probe()
311 sc->num_ports = 7; in e6000sw_probe()
315 sc->num_ports = 11; in e6000sw_probe()
319 sc->num_ports = 11; in e6000sw_probe()
322 device_printf(dev, "Unrecognized device, id 0x%x.\n", sc->swid); in e6000sw_probe()
333 e6000sw_parse_fixed_link(e6000sw_softc_t *sc, phandle_t node, uint32_t port) in e6000sw_parse_fixed_link() argument
341 sc->fixed_mask |= (1 << port); in e6000sw_parse_fixed_link()
345 device_printf(sc->dev, in e6000sw_parse_fixed_link()
350 if (speed == 2500 && (MVSWITCH(sc, MV88E6141) || in e6000sw_parse_fixed_link()
351 MVSWITCH(sc, MV88E6341) || MVSWITCH(sc, MV88E6190) || MVSWITCH(sc, MV88E6190X))) in e6000sw_parse_fixed_link()
352 sc->fixed25_mask |= (1 << port); in e6000sw_parse_fixed_link()
359 e6000sw_parse_ethernet(e6000sw_softc_t *sc, phandle_t port_handle, uint32_t port) { in e6000sw_parse_ethernet() argument
367 device_printf(sc->dev, "CPU port at %d\n", port); in e6000sw_parse_ethernet()
368 sc->cpuports_mask |= (1 << port); in e6000sw_parse_ethernet()
370 return (e6000sw_parse_fixed_link(sc, switch_eth, port)); in e6000sw_parse_ethernet()
372 device_printf(sc->dev, in e6000sw_parse_ethernet()
381 e6000sw_parse_child_fdt(e6000sw_softc_t *sc, phandle_t child, int *pport) in e6000sw_parse_child_fdt() argument
390 if (port >= sc->num_ports) in e6000sw_parse_child_fdt()
394 if (e6000sw_parse_fixed_link(sc, child, port) != 0) in e6000sw_parse_child_fdt()
397 if (e6000sw_parse_ethernet(sc, child, port) != 0) in e6000sw_parse_child_fdt()
400 if ((sc->fixed_mask & (1 << port)) != 0) in e6000sw_parse_child_fdt()
401 device_printf(sc->dev, "fixed port at %d\n", port); in e6000sw_parse_child_fdt()
403 device_printf(sc->dev, "PHY at port %d\n", port); in e6000sw_parse_child_fdt()
432 e6000sw_parse_hinted_port(e6000sw_softc_t *sc, int port) in e6000sw_parse_hinted_port() argument
436 err = e6000sw_check_hint_val(sc->dev, &val, "port%ddisabled", port); in e6000sw_parse_hinted_port()
440 err = e6000sw_check_hint_val(sc->dev, &val, "port%dcpu", port); in e6000sw_parse_hinted_port()
442 sc->cpuports_mask |= (1 << port); in e6000sw_parse_hinted_port()
443 sc->fixed_mask |= (1 << port); in e6000sw_parse_hinted_port()
445 device_printf(sc->dev, "CPU port at %d\n", port); in e6000sw_parse_hinted_port()
447 err = e6000sw_check_hint_val(sc->dev, &val, "port%dspeed", port); in e6000sw_parse_hinted_port()
449 sc->fixed_mask |= (1 << port); in e6000sw_parse_hinted_port()
451 sc->fixed25_mask |= (1 << port); in e6000sw_parse_hinted_port()
455 if ((sc->fixed_mask & (1 << port)) != 0) in e6000sw_parse_hinted_port()
456 device_printf(sc->dev, "fixed port at %d\n", port); in e6000sw_parse_hinted_port()
458 device_printf(sc->dev, "PHY at port %d\n", port); in e6000sw_parse_hinted_port()
466 e6000sw_init_interface(e6000sw_softc_t *sc, int port) in e6000sw_init_interface() argument
470 snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->dev)); in e6000sw_init_interface()
472 sc->ifp[port] = if_alloc(IFT_ETHER); in e6000sw_init_interface()
473 if_setsoftc(sc->ifp[port], sc); in e6000sw_init_interface()
474 if_setflagbits(sc->ifp[port], IFF_UP | IFF_BROADCAST | in e6000sw_init_interface()
476 sc->ifname[port] = malloc(strlen(name) + 1, M_E6000SW, M_NOWAIT); in e6000sw_init_interface()
477 if (sc->ifname[port] == NULL) { in e6000sw_init_interface()
478 if_free(sc->ifp[port]); in e6000sw_init_interface()
481 memcpy(sc->ifname[port], name, strlen(name) + 1); in e6000sw_init_interface()
482 if_initname(sc->ifp[port], sc->ifname[port], port); in e6000sw_init_interface()
488 e6000sw_attach_miibus(e6000sw_softc_t *sc, int port) in e6000sw_attach_miibus() argument
492 err = mii_attach(sc->dev, &sc->miibus[port], sc->ifp[port], in e6000sw_attach_miibus()
494 port + sc->phy_base, MII_OFFSET_ANY, 0); in e6000sw_attach_miibus()
531 e6000sw_softc_t *sc; local
539 sc = device_get_softc(dev);
546 if (MVSWITCH_MULTICHIP(sc))
548 sc->sw_addr);
552 sx_init(&sc->sx, "e6000sw");
554 E6000SW_LOCK(sc);
555 e6000sw_setup(dev, sc);
557 sc->sc_tq = taskqueue_create("e6000sw_taskq", M_NOWAIT,
558 taskqueue_thread_enqueue, &sc->sc_tq);
560 TIMEOUT_TASK_INIT(sc->sc_tq, &sc->sc_tt, 0, e6000sw_tick, sc);
561 taskqueue_start_threads(&sc->sc_tq, 1, PI_NET, "%s taskq",
565 ports = ofw_bus_find_child(sc->node, "ports");
569 E6000SW_UNLOCK(sc);
574 err = e6000sw_parse_child_fdt(sc, child, &port);
576 device_printf(sc->dev, "failed to parse DTS\n");
580 for (port = 0; port < sc->num_ports; port++) {
581 err = e6000sw_parse_hinted_port(sc, port);
587 sc->ports_mask |= (1 << port);
589 err = e6000sw_init_interface(sc, port);
591 device_printf(sc->dev, "failed to init interface\n");
595 if (e6000sw_is_fixedport(sc, port)) {
597 reg = e6000sw_readreg(sc, REG_PORT(sc, port),
601 e6000sw_writereg(sc, REG_PORT(sc, port), PSC_CONTROL,
611 if (e6000sw_is_fixed25port(sc, port))
615 if ((MVSWITCH(sc, MV88E6190) ||
616 MVSWITCH(sc, MV88E6190X)) &&
617 e6000sw_is_fixed25port(sc, port))
622 if (!MVSWITCH(sc, MV88E6190) &&
623 !MVSWITCH(sc, MV88E6190X))
625 if (MVSWITCH(sc, MV88E6141) ||
626 MVSWITCH(sc, MV88E6341) ||
627 MVSWITCH(sc, MV88E6190) ||
628 MVSWITCH(sc, MV88E6190X))
630 e6000sw_writereg(sc, REG_PORT(sc, port), PSC_CONTROL,
633 if ((MVSWITCH(sc, MV88E6190) ||
634 MVSWITCH(sc, MV88E6190X)) &&
636 if (e6000sw_is_fixed25port(sc, port))
640 e6000sw_serdes_power(sc->dev, port, sgmii);
645 if (!e6000sw_is_phyport(sc, port))
648 err = e6000sw_attach_miibus(sc, port);
650 device_printf(sc->dev, "failed to attach miibus\n");
655 etherswitch_info.es_nports = sc->num_ports;
658 e6000sw_set_vlan_mode(sc, ETHERSWITCH_VLAN_PORT);
660 reg = e6000sw_readreg(sc, REG_GLOBAL, SWITCH_GLOBAL_STATUS);
663 E6000SW_UNLOCK(sc);
668 taskqueue_enqueue_timeout(sc->sc_tq, &sc->sc_tt, hz);
673 E6000SW_UNLOCK(sc);
680 e6000sw_waitready(e6000sw_softc_t *sc, uint32_t phy, uint32_t reg, argument
686 if ((e6000sw_readreg(sc, phy, reg) & busybit) == 0)
698 e6000sw_softc_t *sc; local
701 sc = device_get_softc(dev);
702 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
703 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
712 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG, devreg);
713 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG,
715 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
721 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG,
723 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
729 reg = e6000sw_readreg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG);
737 e6000sw_softc_t *sc; local
740 sc = device_get_softc(dev);
741 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
742 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
751 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG, devreg);
752 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG,
754 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
760 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG, devreg);
761 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG,
770 e6000sw_softc_t *sc; local
773 sc = device_get_softc(dev);
775 locked = E6000SW_LOCKED(sc);
777 E6000SW_LOCK(sc);
780 E6000SW_UNLOCK(sc);
792 e6000sw_softc_t *sc; local
795 sc = device_get_softc(dev);
796 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
798 if (!e6000sw_is_phyport(sc, phy) || reg >= E6000SW_NUM_PHY_REGS) {
803 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
808 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG,
811 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
816 val = e6000sw_readreg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG);
824 e6000sw_softc_t *sc; local
827 sc = device_get_softc(dev);
829 locked = E6000SW_LOCKED(sc);
831 E6000SW_LOCK(sc);
834 E6000SW_UNLOCK(sc);
842 e6000sw_softc_t *sc; local
844 sc = device_get_softc(dev);
845 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
847 if (!e6000sw_is_phyport(sc, phy) || reg >= E6000SW_NUM_PHY_REGS) {
852 if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) {
857 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG,
859 e6000sw_writereg(sc, REG_GLOBAL2, SMI_PHY_CMD_REG,
870 e6000sw_softc_t *sc; local
872 sc = device_get_softc(dev);
874 E6000SW_LOCK(sc);
875 sc->is_shutdown = true;
876 if (sc->sc_tq != NULL) {
877 while (taskqueue_cancel_timeout(sc->sc_tq, &sc->sc_tt, NULL) != 0)
878 taskqueue_drain_timeout(sc->sc_tq, &sc->sc_tt);
880 E6000SW_UNLOCK(sc);
886 if (sc->sc_tq != NULL)
887 taskqueue_free(sc->sc_tq);
889 sx_destroy(&sc->sx);
890 for (phy = 0; phy < sc->num_ports; phy++) {
891 if (sc->ifp[phy] != NULL)
892 if_free(sc->ifp[phy]);
893 if (sc->ifname[phy] != NULL)
894 free(sc->ifname[phy], M_E6000SW);
910 struct e6000sw_softc *sc; local
913 sc = device_get_softc(dev);
915 conf->vlan_mode = sc->vlan_mode;
923 struct e6000sw_softc *sc; local
926 sc = device_get_softc(dev);
928 E6000SW_LOCK(sc);
929 e6000sw_set_vlan_mode(sc, conf->vlan_mode);
930 E6000SW_UNLOCK(sc);
939 struct e6000sw_softc *sc; local
941 sc = device_get_softc(dev);
943 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
944 E6000SW_LOCK(sc);
950 struct e6000sw_softc *sc; local
952 sc = device_get_softc(dev);
954 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
955 E6000SW_UNLOCK(sc);
966 e6000sw_softc_t *sc = device_get_softc(dev); local
967 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
969 if (p->es_port >= sc->num_ports || p->es_port < 0)
971 if (!e6000sw_is_portenabled(sc, p->es_port))
974 E6000SW_LOCK(sc);
975 e6000sw_get_pvid(sc, p->es_port, &p->es_pvid);
978 reg = e6000sw_readreg(sc, REG_PORT(sc, p->es_port), PORT_CONTROL2);
985 if (e6000sw_is_fixedport(sc, p->es_port)) {
986 if (e6000sw_is_cpuport(sc, p->es_port))
991 if (e6000sw_is_fixed25port(sc, p->es_port))
999 mii = e6000sw_miiforphy(sc, p->es_port);
1003 E6000SW_UNLOCK(sc);
1011 e6000sw_softc_t *sc; local
1016 sc = device_get_softc(dev);
1017 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
1019 if (p->es_port >= sc->num_ports || p->es_port < 0)
1021 if (!e6000sw_is_portenabled(sc, p->es_port))
1024 E6000SW_LOCK(sc);
1027 reg = e6000sw_readreg(sc, REG_PORT(sc, p->es_port), PORT_CONTROL2);
1036 e6000sw_writereg(sc, REG_PORT(sc, p->es_port), PORT_CONTROL2, reg);
1040 e6000sw_set_pvid(sc, p->es_port, p->es_pvid);
1041 if (e6000sw_is_phyport(sc, p->es_port)) {
1042 mii = e6000sw_miiforphy(sc, p->es_port);
1046 E6000SW_UNLOCK(sc);
1052 e6000sw_port_vlan_assign(e6000sw_softc_t *sc, int port, uint32_t fid, argument
1057 reg = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_VLAN_MAP);
1058 reg &= ~(PORT_MASK(sc) | PORT_VLAN_MAP_FID_MASK);
1059 reg |= members & PORT_MASK(sc) & ~(1 << port);
1061 e6000sw_writereg(sc, REG_PORT(sc, port), PORT_VLAN_MAP, reg);
1062 reg = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_CONTROL1);
1065 e6000sw_writereg(sc, REG_PORT(sc, port), PORT_CONTROL1, reg);
1069 e6000sw_init_vlan(struct e6000sw_softc *sc) argument
1075 for (port = 0; port < sc->num_ports; port++) {
1076 ret = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_CONTROL);
1077 e6000sw_writereg(sc, REG_PORT(sc, port), PORT_CONTROL,
1082 e6000sw_vtu_flush(sc);
1084 for (port = 0; port < sc->num_ports; port++) {
1086 ret = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_CONTROL);
1088 e6000sw_writereg(sc, REG_PORT(sc, port), PORT_CONTROL, ret);
1091 ret = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_CONTROL2);
1093 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
1095 e6000sw_writereg(sc, REG_PORT(sc, port), PORT_CONTROL2, ret);
1098 for (port = 0; port < sc->num_ports; port++) {
1099 if (!e6000sw_is_portenabled(sc, port))
1102 ret = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_VID);
1109 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
1113 e6000sw_writereg(sc, REG_PORT(sc, port), PORT_VID, ret);
1117 for (port = 0; port < sc->num_ports; port++) {
1119 if (e6000sw_is_portenabled(sc, port)) {
1120 for (i = 0; i < sc->num_ports; i++) {
1121 if (i == port || !e6000sw_is_portenabled(sc, i))
1127 e6000sw_port_vlan_assign(sc, port, 0, members);
1131 for (i = 0; i < nitems(sc->vlans); i++)
1132 sc->vlans[i] = 0;
1135 if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q) {
1136 sc->vlans[0] = 1;
1137 e6000sw_vtu_update(sc, 0, sc->vlans[0], 1, 0, sc->ports_mask);
1141 for (port = 0; port < sc->num_ports; port++) {
1142 if (!e6000sw_is_portenabled(sc, port))
1144 ret = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_CONTROL);
1145 e6000sw_writereg(sc, REG_PORT(sc, port), PORT_CONTROL,
1153 e6000sw_set_vlan_mode(struct e6000sw_softc *sc, uint32_t mode) argument
1156 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
1159 sc->vlan_mode = ETHERSWITCH_VLAN_PORT;
1160 etherswitch_info.es_nvlangroups = sc->num_ports;
1161 return (e6000sw_init_vlan(sc));
1164 sc->vlan_mode = ETHERSWITCH_VLAN_DOT1Q;
1166 return (e6000sw_init_vlan(sc));
1182 e6000sw_softc_t *sc; local
1184 sc = device_get_softc(dev);
1186 (addr_reg < (REG_PORT(sc, 0) * 32))) {
1198 e6000sw_softc_t *sc; local
1200 sc = device_get_softc(dev);
1202 (addr_reg < (REG_PORT(sc, 0) * 32))) {
1219 e6000sw_softc_t *sc; local
1222 sc = device_get_softc(dev);
1223 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
1225 E6000SW_LOCK(sc);
1227 E6000SW_UNLOCK(sc);
1235 e6000sw_softc_t *sc; local
1238 sc = device_get_softc(dev);
1239 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
1241 E6000SW_LOCK(sc);
1243 E6000SW_UNLOCK(sc);
1249 e6000sw_set_port_vlan(e6000sw_softc_t *sc, etherswitch_vlangroup_t *vg) argument
1254 if (port > sc->num_ports)
1258 device_printf(sc->dev, "Tagged ports not supported.\n");
1262 e6000sw_port_vlan_assign(sc, port, 0, vg->es_untagged_ports);
1269 e6000sw_set_dot1q_vlan(e6000sw_softc_t *sc, etherswitch_vlangroup_t *vg) argument
1277 e6000sw_vtu_update(sc, VTU_PURGE,
1278 sc->vlans[vg->es_vlangroup], 0, 0, 0);
1279 sc->vlans[vg->es_vlangroup] = 0;
1285 if (i != vg->es_vlangroup && vlan == sc->vlans[i])
1288 sc->vlans[vg->es_vlangroup] = vlan;
1289 e6000sw_vtu_update(sc, 0, vlan, vg->es_vlangroup + 1,
1290 vg->es_member_ports & sc->ports_mask,
1291 vg->es_untagged_ports & sc->ports_mask);
1299 e6000sw_softc_t *sc; local
1301 sc = device_get_softc(dev);
1302 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
1304 if (sc->vlan_mode == ETHERSWITCH_VLAN_PORT)
1305 return (e6000sw_set_port_vlan(sc, vg));
1306 else if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
1307 return (e6000sw_set_dot1q_vlan(sc, vg));
1313 e6000sw_get_port_vlan(e6000sw_softc_t *sc, etherswitch_vlangroup_t *vg) argument
1318 if (port > sc->num_ports)
1321 if (!e6000sw_is_portenabled(sc, port)) {
1326 reg = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_VLAN_MAP);
1327 vg->es_untagged_ports = vg->es_member_ports = reg & PORT_MASK(sc);
1330 reg = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_CONTROL1);
1337 e6000sw_get_dot1q_vlan(e6000sw_softc_t *sc, etherswitch_vlangroup_t *vg) argument
1343 vg->es_vid = sc->vlans[vg->es_vlangroup];
1348 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1349 device_printf(sc->dev, "VTU unit is busy, cannot access\n");
1353 e6000sw_writereg(sc, REG_GLOBAL, VTU_VID, vg->es_vid - 1);
1355 reg = e6000sw_readreg(sc, REG_GLOBAL, VTU_OPERATION);
1358 e6000sw_writereg(sc, REG_GLOBAL, VTU_OPERATION, reg);
1359 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1360 device_printf(sc->dev, "Timeout while reading\n");
1364 reg = e6000sw_readreg(sc, REG_GLOBAL, VTU_VID);
1371 reg = e6000sw_readreg(sc, REG_GLOBAL, VTU_DATA);
1372 for (i = 0; i < sc->num_ports; i++) {
1373 if (i == VTU_PPREG(sc))
1374 reg = e6000sw_readreg(sc, REG_GLOBAL, VTU_DATA2);
1375 port = (reg >> VTU_PORT(sc, i)) & VTU_PORT_MASK;
1389 e6000sw_softc_t *sc; local
1391 sc = device_get_softc(dev);
1392 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
1394 if (sc->vlan_mode == ETHERSWITCH_VLAN_PORT)
1395 return (e6000sw_get_port_vlan(sc, vg));
1396 else if (sc->vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
1397 return (e6000sw_get_dot1q_vlan(sc, vg));
1403 e6000sw_miiforphy(e6000sw_softc_t *sc, unsigned int phy) argument
1407 if (!e6000sw_is_phyport(sc, phy))
1409 mii_dev = sc->miibus[phy];
1421 e6000sw_softc_t *sc; local
1424 sc = if_getsoftc(ifp);
1425 mii = e6000sw_miiforphy(sc, if_getdunit(ifp));
1436 e6000sw_softc_t *sc; local
1439 sc = if_getsoftc(ifp);
1440 mii = e6000sw_miiforphy(sc, if_getdunit(ifp));
1451 e6000sw_smi_waitready(e6000sw_softc_t *sc, int phy) argument
1456 if ((MDIO_READ(sc->dev, phy, SMI_CMD) & SMI_CMD_BUSY) == 0)
1465 e6000sw_readreg(e6000sw_softc_t *sc, int addr, int reg) argument
1468 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
1470 if (!MVSWITCH_MULTICHIP(sc))
1471 return (MDIO_READ(sc->dev, addr, reg) & 0xffff);
1473 if (e6000sw_smi_waitready(sc, sc->sw_addr)) {
1477 MDIO_WRITE(sc->dev, sc->sw_addr, SMI_CMD,
1480 if (e6000sw_smi_waitready(sc, sc->sw_addr)) {
1485 return (MDIO_READ(sc->dev, sc->sw_addr, SMI_DATA) & 0xffff);
1489 e6000sw_writereg(e6000sw_softc_t *sc, int addr, int reg, int val) argument
1492 E6000SW_LOCK_ASSERT(sc, SA_XLOCKED);
1494 if (!MVSWITCH_MULTICHIP(sc)) {
1495 MDIO_WRITE(sc->dev, addr, reg, val);
1499 if (e6000sw_smi_waitready(sc, sc->sw_addr)) {
1503 MDIO_WRITE(sc->dev, sc->sw_addr, SMI_DATA, val);
1504 MDIO_WRITE(sc->dev, sc->sw_addr, SMI_CMD,
1510 e6000sw_is_cpuport(e6000sw_softc_t *sc, int port) argument
1513 return ((sc->cpuports_mask & (1 << port)) ? true : false);
1517 e6000sw_is_fixedport(e6000sw_softc_t *sc, int port) argument
1520 return ((sc->fixed_mask & (1 << port)) ? true : false);
1524 e6000sw_is_fixed25port(e6000sw_softc_t *sc, int port) argument
1527 return ((sc->fixed25_mask & (1 << port)) ? true : false);
1531 e6000sw_is_phyport(e6000sw_softc_t *sc, int port) argument
1534 phy_mask = ~(sc->fixed_mask | sc->cpuports_mask);
1540 e6000sw_is_portenabled(e6000sw_softc_t *sc, int port) argument
1543 return ((sc->ports_mask & (1 << port)) ? true : false);
1547 e6000sw_set_pvid(e6000sw_softc_t *sc, int port, int pvid) argument
1551 reg = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_VID);
1554 e6000sw_writereg(sc, REG_PORT(sc, port), PORT_VID, reg);
1558 e6000sw_get_pvid(e6000sw_softc_t *sc, int port, int *pvid) argument
1564 *pvid = e6000sw_readreg(sc, REG_PORT(sc, port), PORT_VID) &
1607 e6000sw_softc_t *sc; local
1613 sc = arg;
1615 E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
1617 E6000SW_LOCK(sc);
1619 if (sc->is_shutdown) {
1620 E6000SW_UNLOCK(sc);
1624 for (port = 0; port < sc->num_ports; port++) {
1626 if (!e6000sw_is_portenabled(sc, port) ||
1627 !e6000sw_is_phyport(sc, port))
1630 mii = e6000sw_miiforphy(sc, port);
1634 portstatus = e6000sw_readreg(sc, REG_PORT(sc, port),
1658 E6000SW_UNLOCK(sc);
1659 taskqueue_enqueue_timeout(sc->sc_tq, &sc->sc_tt, hz);
1663 e6000sw_setup(device_t dev, e6000sw_softc_t *sc) argument
1668 atu_ctrl = e6000sw_readreg(sc, REG_GLOBAL, ATU_CONTROL);
1671 e6000sw_writereg(sc, REG_GLOBAL, ATU_CONTROL, atu_ctrl);
1674 e6000sw_writereg(sc, REG_GLOBAL2, MGMT_EN_2x, MGMT_EN_ALL);
1675 e6000sw_writereg(sc, REG_GLOBAL2, MGMT_EN_0x, MGMT_EN_ALL);
1678 e6000sw_writereg(sc, REG_GLOBAL, SWITCH_GLOBAL_CONTROL2, 0);
1681 e6000sw_writereg(sc, REG_GLOBAL2, SWITCH_MGMT,
1687 e6000sw_atu_flush(dev, sc, NO_OPERATION);
1688 e6000sw_atu_mac_table(dev, sc, NULL, NO_OPERATION);
1689 e6000sw_set_atustat(dev, sc, 0, COUNT_ALL);
1693 e6000sw_set_atustat(device_t dev, e6000sw_softc_t *sc, int bin, int flag) argument
1696 e6000sw_readreg(sc, REG_GLOBAL2, ATU_STATS);
1697 e6000sw_writereg(sc, REG_GLOBAL2, ATU_STATS, (bin << ATU_STATS_BIN ) |
1702 e6000sw_atu_mac_table(device_t dev, e6000sw_softc_t *sc, struct atu_opt *atu, argument
1716 if (E6000SW_WAITREADY(sc, ATU_OPERATION, ATU_UNIT_BUSY)) {
1721 ret_opt = e6000sw_readreg(sc, REG_GLOBAL, ATU_OPERATION);
1723 ret_data = e6000sw_readreg(sc, REG_GLOBAL, ATU_DATA);
1724 e6000sw_writereg(sc, REG_GLOBAL2, ATU_DATA, (ret_data &
1727 e6000sw_writereg(sc, REG_GLOBAL, ATU_MAC_ADDR01, atu->mac_01);
1728 e6000sw_writereg(sc, REG_GLOBAL, ATU_MAC_ADDR23, atu->mac_23);
1729 e6000sw_writereg(sc, REG_GLOBAL, ATU_MAC_ADDR45, atu->mac_45);
1730 e6000sw_writereg(sc, REG_GLOBAL, ATU_FID, atu->fid);
1732 e6000sw_writereg(sc, REG_GLOBAL, ATU_OPERATION,
1735 if (E6000SW_WAITREADY(sc, ATU_OPERATION, ATU_UNIT_BUSY))
1738 atu->mac_01 = e6000sw_readreg(sc, REG_GLOBAL,
1740 atu->mac_23 = e6000sw_readreg(sc, REG_GLOBAL,
1742 atu->mac_45 = e6000sw_readreg(sc, REG_GLOBAL,
1750 e6000sw_atu_flush(device_t dev, e6000sw_softc_t *sc, int flag) argument
1757 if (E6000SW_WAITREADY(sc, ATU_OPERATION, ATU_UNIT_BUSY)) {
1761 reg = e6000sw_readreg(sc, REG_GLOBAL, ATU_OPERATION);
1762 e6000sw_writereg(sc, REG_GLOBAL, ATU_OPERATION,
1764 if (E6000SW_WAITREADY(sc, ATU_OPERATION, ATU_UNIT_BUSY))
1771 e6000sw_vtu_flush(e6000sw_softc_t *sc) argument
1774 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1775 device_printf(sc->dev, "VTU unit is busy, cannot access\n");
1779 e6000sw_writereg(sc, REG_GLOBAL, VTU_OPERATION, VTU_FLUSH | VTU_BUSY);
1780 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1781 device_printf(sc->dev, "Timeout while flushing VTU\n");
1789 e6000sw_vtu_update(e6000sw_softc_t *sc, int purge, int vid, int fid, argument
1795 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1796 device_printf(sc->dev, "VTU unit is busy, cannot access\n");
1803 e6000sw_writereg(sc, REG_GLOBAL, VTU_VID, *data);
1808 for (i = 0; i < sc->num_ports; i++) {
1810 data[i / VTU_PPREG(sc)] |=
1811 VTU_PORT_UNTAGGED << VTU_PORT(sc, i);
1813 data[i / VTU_PPREG(sc)] |=
1814 VTU_PORT_TAGGED << VTU_PORT(sc, i);
1816 data[i / VTU_PPREG(sc)] |=
1817 VTU_PORT_DISCARD << VTU_PORT(sc, i);
1819 e6000sw_writereg(sc, REG_GLOBAL, VTU_DATA, data[0]);
1820 e6000sw_writereg(sc, REG_GLOBAL, VTU_DATA2, data[1]);
1821 e6000sw_writereg(sc, REG_GLOBAL, VTU_FID,
1822 fid & VTU_FID_MASK(sc));
1827 e6000sw_writereg(sc, REG_GLOBAL, VTU_OPERATION, op | VTU_BUSY);
1828 if (E6000SW_WAITREADY(sc, VTU_OPERATION, VTU_BUSY)) {
1829 device_printf(sc->dev, "Timeout while flushing VTU\n");