Lines Matching +full:cpsw +full:- +full:mdio

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
31 * TI Common Platform Ethernet Switch (CPSW) Driver
39 * a 3-port store-and-forward switch connected to two independent
226 "cpsw",
236 DRIVER_MODULE(cpsw, cpswss, cpswp_driver, 0, 0);
237 DRIVER_MODULE(miibus, cpsw, miibus_driver, 0, 0);
238 MODULE_DEPEND(cpsw, ether, 1, 1, 1);
239 MODULE_DEPEND(cpsw, miibus, 1, 1, 1);
252 { -1, 0 }
331 if ((_sc)->debug) { \
341 mtx_assert(&(sc)->rx.lock, MA_NOTOWNED); \
342 mtx_lock(&(sc)->tx.lock); \
345 #define CPSW_TX_UNLOCK(sc) mtx_unlock(&(sc)->tx.lock)
346 #define CPSW_TX_LOCK_ASSERT(sc) mtx_assert(&(sc)->tx.lock, MA_OWNED)
349 mtx_assert(&(sc)->tx.lock, MA_NOTOWNED); \
350 mtx_lock(&(sc)->rx.lock); \
353 #define CPSW_RX_UNLOCK(sc) mtx_unlock(&(sc)->rx.lock)
354 #define CPSW_RX_LOCK_ASSERT(sc) mtx_assert(&(sc)->rx.lock, MA_OWNED)
357 mtx_assert(&(_sc)->lock, MA_NOTOWNED); \
358 mtx_lock(&(_sc)->lock); \
361 #define CPSW_PORT_UNLOCK(_sc) mtx_unlock(&(_sc)->lock)
362 #define CPSW_PORT_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->lock, MA_OWNED)
367 #define cpsw_read_4(_sc, _reg) bus_read_4((_sc)->mem_res, (_reg))
369 bus_write_4((_sc)->mem_res, (_reg), (_val))
374 BUS_SPACE_PHYSADDR(sc->mem_res, slot->bd_offset)
376 bus_read_region_4(sc->mem_res, slot->bd_offset, (uint32_t *) val, 4)
378 bus_write_region_4(sc->mem_res, slot->bd_offset, (uint32_t *) val, 4)
380 cpsw_write_4(sc, slot->bd_offset, cpsw_cpdma_bd_paddr(sc, next_slot))
382 bus_write_2(sc->mem_res, slot->bd_offset + 14, val)
384 bus_read_2(sc->mem_res, slot->bd_offset + 14)
386 cpsw_write_4(sc, (queue)->hdp_offset, cpsw_cpdma_bd_paddr(sc, slot))
387 #define CP_OFFSET (CPSW_CPDMA_TX_CP(0) - CPSW_CPDMA_TX_HDP(0))
389 cpsw_read_4(sc, (queue)->hdp_offset + CP_OFFSET)
391 cpsw_write_4(sc, (queue)->hdp_offset + CP_OFFSET, (val))
400 uint32_t reg = queue->hdp_offset;
437 if (bd.flags & (1 << (15 - i))) { in cpsw_dump_slot()
443 if (slot->mbuf) { in cpsw_dump_slot()
445 (char *)(slot->mbuf->m_data), " "); in cpsw_dump_slot()
447 (char *)(slot->mbuf->m_data) + 14, " "); in cpsw_dump_slot()
488 STAILQ_INIT(&sc->avail); in cpsw_init_slots()
491 for (i = 0; i < nitems(sc->_slots); i++) { in cpsw_init_slots()
492 slot = &sc->_slots[i]; in cpsw_init_slots()
493 slot->bd_offset = cpsw_cpdma_bd_offset(i); in cpsw_init_slots()
494 STAILQ_INSERT_TAIL(&sc->avail, slot, next); in cpsw_init_slots()
501 const int max_slots = nitems(sc->_slots); in cpsw_add_slots()
509 slot = STAILQ_FIRST(&sc->avail); in cpsw_add_slots()
512 if (bus_dmamap_create(sc->mbuf_dtag, 0, &slot->dmamap)) { in cpsw_add_slots()
513 device_printf(sc->dev, "failed to create dmamap\n"); in cpsw_add_slots()
516 STAILQ_REMOVE_HEAD(&sc->avail, next); in cpsw_add_slots()
517 STAILQ_INSERT_TAIL(&queue->avail, slot, next); in cpsw_add_slots()
518 ++queue->avail_queue_len; in cpsw_add_slots()
519 ++queue->queue_slots; in cpsw_add_slots()
529 if (slot->dmamap) { in cpsw_free_slot()
530 if (slot->mbuf) in cpsw_free_slot()
531 bus_dmamap_unload(sc->mbuf_dtag, slot->dmamap); in cpsw_free_slot()
532 error = bus_dmamap_destroy(sc->mbuf_dtag, slot->dmamap); in cpsw_free_slot()
534 slot->dmamap = NULL; in cpsw_free_slot()
536 if (slot->mbuf) { in cpsw_free_slot()
537 m_freem(slot->mbuf); in cpsw_free_slot()
538 slot->mbuf = NULL; in cpsw_free_slot()
547 callout_stop(&sc->watchdog.callout); in cpsw_reset()
562 /* Reset CPSW subsystem. */ in cpsw_reset()
613 if (sc->dualemac) in cpsw_init()
658 /* Initialze MDIO - ENABLE, PREAMBLE=0, FAULTENB, CLKDIV=0xFF */ in cpsw_init()
666 slot = STAILQ_FIRST(&sc->tx.active); in cpsw_init()
668 cpsw_write_hdp_slot(sc, &sc->tx, slot); in cpsw_init()
669 slot = STAILQ_FIRST(&sc->rx.active); in cpsw_init()
671 cpsw_write_hdp_slot(sc, &sc->rx, slot); in cpsw_init()
673 cpsw_write_4(sc, CPSW_CPDMA_RX_FREEBUFFER(0), sc->rx.active_queue_len); in cpsw_init()
677 sc->rx.running = 1; in cpsw_init()
678 sc->tx.running = 1; in cpsw_init()
679 sc->watchdog.timer = 0; in cpsw_init()
680 callout_init(&sc->watchdog.callout, 0); in cpsw_init()
681 callout_reset(&sc->watchdog.callout, hz, cpsw_tx_watchdog, sc); in cpsw_init()
697 if (!ofw_bus_is_compatible(dev, "ti,cpsw")) in cpsw_probe()
700 device_set_desc(dev, "3-port Switch Ethernet Subsystem"); in cpsw_probe()
710 if (bus_setup_intr(sc->dev, sc->irq_res[i], in cpsw_intr_attach()
712 cpsw_intr_cb[i].cb, sc, &sc->ih_cookie[i]) != 0) { in cpsw_intr_attach()
713 return (-1); in cpsw_intr_attach()
726 if (sc->ih_cookie[i]) { in cpsw_intr_detach()
727 bus_teardown_intr(sc->dev, sc->irq_res[i], in cpsw_intr_detach()
728 sc->ih_cookie[i]); in cpsw_intr_detach()
742 /* Find any slave with phy-handle/phy_id */ in cpsw_get_fdt_data()
743 phy = -1; in cpsw_get_fdt_data()
744 vlan = -1; in cpsw_get_fdt_data()
745 for (child = OF_child(sc->node); child != 0; child = OF_peer(child)) { in cpsw_get_fdt_data()
760 phy = -1; in cpsw_get_fdt_data()
780 if (phy == -1) in cpsw_get_fdt_data()
782 sc->port[port].phy = phy; in cpsw_get_fdt_data()
783 sc->port[port].vlan = vlan; in cpsw_get_fdt_data()
796 sc->dev = dev; in cpsw_attach()
797 sc->node = ofw_bus_get_node(dev); in cpsw_attach()
798 getbinuptime(&sc->attach_uptime); in cpsw_attach()
800 if (OF_getencprop(sc->node, "active_slave", &sc->active_slave, in cpsw_attach()
801 sizeof(sc->active_slave)) <= 0) { in cpsw_attach()
802 sc->active_slave = 0; in cpsw_attach()
804 if (sc->active_slave > 1) in cpsw_attach()
805 sc->active_slave = 1; in cpsw_attach()
807 if (OF_hasprop(sc->node, "dual_emac")) in cpsw_attach()
808 sc->dualemac = 1; in cpsw_attach()
811 if (!sc->dualemac && i != sc->active_slave) in cpsw_attach()
821 mtx_init(&sc->tx.lock, device_get_nameunit(dev), in cpsw_attach()
822 "cpsw TX lock", MTX_DEF); in cpsw_attach()
823 mtx_init(&sc->rx.lock, device_get_nameunit(dev), in cpsw_attach()
824 "cpsw RX lock", MTX_DEF); in cpsw_attach()
827 error = bus_alloc_resources(dev, irq_res_spec, sc->irq_res); in cpsw_attach()
834 sc->mem_rid = 0; in cpsw_attach()
835 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in cpsw_attach()
836 &sc->mem_rid, RF_ACTIVE); in cpsw_attach()
837 if (sc->mem_res == NULL) { in cpsw_attach()
838 device_printf(sc->dev, "failed to allocate memory resource\n"); in cpsw_attach()
844 device_printf(dev, "CPSW SS Version %d.%d (%d)\n", (reg >> 8 & 0x7), in cpsw_attach()
851 bus_get_dma_tag(sc->dev), /* parent */ in cpsw_attach()
859 &sc->mbuf_dtag); /* dmatag */ in cpsw_attach()
867 sc->nullpad = malloc(ETHER_MIN_LEN, M_DEVBUF, M_WAITOK | M_ZERO); in cpsw_attach()
872 STAILQ_INIT(&sc->rx.avail); in cpsw_attach()
873 STAILQ_INIT(&sc->rx.active); in cpsw_attach()
874 STAILQ_INIT(&sc->tx.avail); in cpsw_attach()
875 STAILQ_INIT(&sc->tx.active); in cpsw_attach()
878 if (cpsw_add_slots(sc, &sc->tx, 128) || in cpsw_attach()
879 cpsw_add_slots(sc, &sc->rx, -1)) { in cpsw_attach()
885 sc->tx.queue_slots, sc->rx.queue_slots); in cpsw_attach()
887 sc->tx.hdp_offset = CPSW_CPDMA_TX_HDP(0); in cpsw_attach()
888 sc->rx.hdp_offset = CPSW_CPDMA_RX_HDP(0); in cpsw_attach()
890 if (cpsw_intr_attach(sc) == -1) { in cpsw_attach()
898 cpsw_vgroups[i].vid = -1; in cpsw_attach()
906 if (!sc->dualemac && i != sc->active_slave) in cpsw_attach()
908 sc->port[i].dev = device_add_child(dev, "cpsw", i); in cpsw_attach()
909 if (sc->port[i].dev == NULL) { in cpsw_attach()
933 callout_stop(&sc->watchdog.callout); in cpsw_detach()
934 callout_drain(&sc->watchdog.callout); in cpsw_detach()
941 for (i = 0; i < nitems(sc->_slots); ++i) in cpsw_detach()
942 cpsw_free_slot(sc, &sc->_slots[i]); in cpsw_detach()
945 if (sc->nullpad) in cpsw_detach()
946 free(sc->nullpad, M_DEVBUF); in cpsw_detach()
949 if (sc->mbuf_dtag) { in cpsw_detach()
950 error = bus_dma_tag_destroy(sc->mbuf_dtag); in cpsw_detach()
955 if (sc->mem_res != NULL) in cpsw_detach()
956 bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res); in cpsw_detach()
957 bus_release_resources(dev, irq_res_spec, sc->irq_res); in cpsw_detach()
960 mtx_destroy(&sc->rx.lock); in cpsw_detach()
961 mtx_destroy(&sc->tx.lock); in cpsw_detach()
999 sc->dev = dev; in cpswp_attach()
1000 sc->pdev = device_get_parent(dev); in cpswp_attach()
1001 sc->swsc = device_get_softc(sc->pdev); in cpswp_attach()
1002 sc->unit = device_get_unit(dev); in cpswp_attach()
1003 sc->phy = sc->swsc->port[sc->unit].phy; in cpswp_attach()
1004 sc->vlan = sc->swsc->port[sc->unit].vlan; in cpswp_attach()
1005 if (sc->swsc->dualemac && sc->vlan == -1) in cpswp_attach()
1006 sc->vlan = sc->unit + 1; in cpswp_attach()
1008 if (sc->unit == 0) { in cpswp_attach()
1009 sc->physel = MDIOUSERPHYSEL0; in cpswp_attach()
1010 sc->phyaccess = MDIOUSERACCESS0; in cpswp_attach()
1012 sc->physel = MDIOUSERPHYSEL1; in cpswp_attach()
1013 sc->phyaccess = MDIOUSERACCESS1; in cpswp_attach()
1016 mtx_init(&sc->lock, device_get_nameunit(dev), "cpsw port lock", in cpswp_attach()
1020 ifp = sc->ifp = if_alloc(IFT_ETHER); in cpswp_attach()
1021 if_initname(ifp, device_get_name(sc->dev), sc->unit); in cpswp_attach()
1031 if_setsendqlen(ifp, sc->swsc->tx.queue_slots); in cpswp_attach()
1034 /* FIXME: For now; Go and kidnap syscon from opp-table */ in cpswp_attach()
1035 /* ti,cpsw actually have an optional syscon reference but only for am33xx?? */ in cpswp_attach()
1036 opp_table = OF_finddevice("/opp-table"); in cpswp_attach()
1037 if (opp_table == -1) { in cpswp_attach()
1038 device_printf(dev, "Cant find /opp-table\n"); in cpswp_attach()
1043 device_printf(dev, "/opp-table doesnt have required syscon property\n"); in cpswp_attach()
1054 reg = SYSCON_READ_4(syscon, SCM_MAC_ID0_HI + sc->unit * 8); in cpswp_attach()
1061 reg = SYSCON_READ_4(syscon, SCM_MAC_ID0_LO + sc->unit * 8); in cpswp_attach()
1065 error = mii_attach(dev, &sc->miibus, ifp, cpswp_ifmedia_upd, in cpswp_attach()
1066 cpswp_ifmedia_sts, BMSR_DEFCAPMASK, sc->phy, MII_OFFSET_ANY, 0); in cpswp_attach()
1072 sc->mii = device_get_softc(sc->miibus); in cpswp_attach()
1075 cpsw_write_4(sc->swsc, sc->physel, in cpswp_attach()
1076 MDIO_PHYSEL_LINKINTENB | (sc->phy & 0x1F)); in cpswp_attach()
1078 ether_ifattach(sc->ifp, mac_addr); in cpswp_attach()
1079 callout_init(&sc->mii_callout, 0); in cpswp_attach()
1095 CPSW_DEBUGF(sc->swsc, ("")); in cpswp_detach()
1097 ether_ifdetach(sc->ifp); in cpswp_detach()
1101 callout_drain(&sc->mii_callout); in cpswp_detach()
1104 if_free(sc->ifp); in cpswp_detach()
1105 mtx_destroy(&sc->lock); in cpswp_detach()
1122 if (!sc->dualemac) in cpsw_ports_down()
1124 psc = device_get_softc(sc->port[0].dev); in cpsw_ports_down()
1125 ifp1 = psc->ifp; in cpsw_ports_down()
1126 psc = device_get_softc(sc->port[1].dev); in cpsw_ports_down()
1127 ifp2 = psc->ifp; in cpsw_ports_down()
1139 CPSW_DEBUGF(sc->swsc, ("")); in cpswp_init()
1155 CPSW_DEBUGF(sc->swsc, ("")); in cpswp_init_locked()
1157 ifp = sc->ifp; in cpswp_init_locked()
1161 getbinuptime(&sc->init_uptime); in cpswp_init_locked()
1163 if (!sc->swsc->rx.running && !sc->swsc->tx.running) { in cpswp_init_locked()
1165 cpsw_reset(sc->swsc); in cpswp_init_locked()
1166 cpsw_init(sc->swsc); in cpswp_init_locked()
1170 cpsw_write_4(sc->swsc, CPSW_SL_RX_PRI_MAP(sc->unit), 0x76543210); in cpswp_init_locked()
1171 cpsw_write_4(sc->swsc, CPSW_PORT_P_TX_PRI_MAP(sc->unit + 1), in cpswp_init_locked()
1173 cpsw_write_4(sc->swsc, CPSW_SL_RX_MAXLEN(sc->unit), 0x5f2); in cpswp_init_locked()
1177 reg = cpsw_read_4(sc->swsc, CPSW_SL_MACCONTROL(sc->unit)); in cpswp_init_locked()
1179 cpsw_write_4(sc->swsc, CPSW_SL_MACCONTROL(sc->unit), reg); in cpswp_init_locked()
1182 cpsw_write_4(sc->swsc, CPSW_ALE_PORTCTL(sc->unit + 1), in cpswp_init_locked()
1186 if (sc->swsc->dualemac) { in cpswp_init_locked()
1188 cpsw_write_4(sc->swsc, CPSW_PORT_P_VLAN(sc->unit + 1), in cpswp_init_locked()
1189 sc->vlan & 0xfff); in cpswp_init_locked()
1190 cpsw_ale_update_vlan_table(sc->swsc, sc->vlan, in cpswp_init_locked()
1191 (1 << (sc->unit + 1)) | (1 << 0), /* Member list */ in cpswp_init_locked()
1192 (1 << (sc->unit + 1)) | (1 << 0), /* Untagged egress */ in cpswp_init_locked()
1193 (1 << (sc->unit + 1)) | (1 << 0), 0); /* mcast reg flood */ in cpswp_init_locked()
1196 if (cpsw_vgroups[i].vid != -1) in cpswp_init_locked()
1198 cpsw_vgroups[i].vid = sc->vlan; in cpswp_init_locked()
1204 mii_mediachg(sc->mii); in cpswp_init_locked()
1205 callout_reset(&sc->mii_callout, hz, cpswp_tick, sc); in cpswp_init_locked()
1220 if (!sc->dualemac && i != sc->active_slave) in cpsw_shutdown()
1222 psc = device_get_softc(sc->port[i].dev); in cpsw_shutdown()
1238 sc->rx.teardown = 1; in cpsw_rx_teardown()
1241 while (sc->rx.running) { in cpsw_rx_teardown()
1243 device_printf(sc->dev, in cpsw_rx_teardown()
1249 if (!sc->rx.running) in cpsw_rx_teardown()
1261 if (STAILQ_FIRST(&sc->tx.active) != NULL) in cpsw_tx_teardown()
1264 sc->tx.teardown = 1; in cpsw_tx_teardown()
1266 while (sc->tx.running && ++i < 10) { in cpsw_tx_teardown()
1270 if (sc->tx.running) { in cpsw_tx_teardown()
1271 device_printf(sc->dev, in cpsw_tx_teardown()
1276 sc->tx.active_queue_len)); in cpsw_tx_teardown()
1286 ifp = sc->ifp; in cpswp_stop_locked()
1287 CPSW_DEBUGF(sc->swsc, ("")); in cpswp_stop_locked()
1298 callout_stop(&sc->mii_callout); in cpswp_stop_locked()
1301 if (cpsw_ports_down(sc->swsc)) { in cpswp_stop_locked()
1302 cpsw_rx_teardown(sc->swsc); in cpswp_stop_locked()
1303 cpsw_tx_teardown(sc->swsc); in cpswp_stop_locked()
1307 reg = cpsw_read_4(sc->swsc, CPSW_SL_MACCONTROL(sc->unit)); in cpswp_stop_locked()
1309 cpsw_write_4(sc->swsc, CPSW_SL_MACCONTROL(sc->unit), reg); in cpswp_stop_locked()
1311 if (cpsw_ports_down(sc->swsc)) { in cpswp_stop_locked()
1313 cpsw_stats_collect(sc->swsc); in cpswp_stop_locked()
1315 cpsw_reset(sc->swsc); in cpswp_stop_locked()
1316 cpsw_init(sc->swsc); in cpswp_stop_locked()
1334 if (!sc->dualemac && i != sc->active_slave) in cpsw_suspend()
1336 psc = device_get_softc(sc->port[i].dev); in cpsw_suspend()
1374 reg = cpsw_read_4(sc->swsc, CPSW_ALE_CONTROL); in cpsw_set_promisc()
1378 cpsw_write_4(sc->swsc, CPSW_ALE_CONTROL, reg); in cpsw_set_promisc()
1385 printf("All-multicast mode unimplemented\n"); in cpsw_set_allmulti()
1403 changed = if_getcapenable(ifp) ^ ifr->ifr_reqcap; in cpswp_ioctl()
1405 if ((ifr->ifr_reqcap & changed) & IFCAP_HWCSUM) in cpswp_ioctl()
1416 changed = if_getflags(ifp) ^ sc->if_flags; in cpswp_ioctl()
1417 CPSW_DEBUGF(sc->swsc, in cpswp_ioctl()
1427 CPSW_DEBUGF(sc->swsc, in cpswp_ioctl()
1432 CPSW_DEBUGF(sc->swsc, ("SIOCSIFFLAGS: shutting down")); in cpswp_ioctl()
1436 sc->if_flags = if_getflags(ifp); in cpswp_ioctl()
1450 error = ifmedia_ioctl(ifp, ifr, &sc->mii->mii_media, command); in cpswp_ioctl()
1468 while (--retries) { in cpswp_miibus_ready()
1485 if (!cpswp_miibus_ready(sc->swsc, sc->phyaccess)) { in cpswp_miibus_readreg()
1486 device_printf(dev, "MDIO not ready to read\n"); in cpswp_miibus_readreg()
1492 cpsw_write_4(sc->swsc, sc->phyaccess, cmd); in cpswp_miibus_readreg()
1494 if (!cpswp_miibus_ready(sc->swsc, sc->phyaccess)) { in cpswp_miibus_readreg()
1495 device_printf(dev, "MDIO timed out during read\n"); in cpswp_miibus_readreg()
1499 r = cpsw_read_4(sc->swsc, sc->phyaccess); in cpswp_miibus_readreg()
1514 if (!cpswp_miibus_ready(sc->swsc, sc->phyaccess)) { in cpswp_miibus_writereg()
1515 device_printf(dev, "MDIO not ready to write\n"); in cpswp_miibus_writereg()
1522 cpsw_write_4(sc->swsc, sc->phyaccess, cmd); in cpswp_miibus_writereg()
1524 if (!cpswp_miibus_ready(sc->swsc, sc->phyaccess)) { in cpswp_miibus_writereg()
1525 device_printf(dev, "MDIO timed out during write\n"); in cpswp_miibus_writereg()
1539 CPSW_DEBUGF(sc->swsc, ("")); in cpswp_miibus_statchg()
1541 reg = CPSW_SL_MACCONTROL(sc->unit); in cpswp_miibus_statchg()
1542 mac_control = cpsw_read_4(sc->swsc, reg); in cpswp_miibus_statchg()
1546 switch(IFM_SUBTYPE(sc->mii->mii_media_active)) { in cpswp_miibus_statchg()
1558 if (sc->mii->mii_media_active & IFM_FDX) in cpswp_miibus_statchg()
1561 cpsw_write_4(sc->swsc, reg, mac_control); in cpswp_miibus_statchg()
1578 if (sc->rx.teardown) { in cpsw_intr_rx()
1579 sc->rx.running = 0; in cpsw_intr_rx()
1580 sc->rx.teardown = 0; in cpsw_intr_rx()
1581 cpsw_write_cp(sc, &sc->rx, 0xfffffffc); in cpsw_intr_rx()
1589 next = received->m_nextpkt; in cpsw_intr_rx()
1590 received->m_nextpkt = NULL; in cpsw_intr_rx()
1591 ifp = received->m_pkthdr.rcvif; in cpsw_intr_rx()
1616 while ((slot = STAILQ_FIRST(&sc->rx.active)) != NULL) { in cpsw_rx_dequeue()
1630 STAILQ_REMOVE_HEAD(&sc->rx.active, next); in cpsw_rx_dequeue()
1631 STAILQ_INSERT_TAIL(&sc->rx.avail, slot, next); in cpsw_rx_dequeue()
1633 bus_dmamap_sync(sc->mbuf_dtag, slot->dmamap, BUS_DMASYNC_POSTREAD); in cpsw_rx_dequeue()
1634 bus_dmamap_unload(sc->mbuf_dtag, slot->dmamap); in cpsw_rx_dequeue()
1636 m = slot->mbuf; in cpsw_rx_dequeue()
1637 slot->mbuf = NULL; in cpsw_rx_dequeue()
1642 sc->rx.running = 0; in cpsw_rx_dequeue()
1643 sc->rx.teardown = 0; in cpsw_rx_dequeue()
1647 port = (bd.flags & CPDMA_BD_PORT_MASK) - 1; in cpsw_rx_dequeue()
1650 psc = device_get_softc(sc->port[port].dev); in cpsw_rx_dequeue()
1653 m->m_data += bd.bufoff; in cpsw_rx_dequeue()
1654 m->m_len = bd.buflen; in cpsw_rx_dequeue()
1656 m->m_pkthdr.len = bd.pktlen; in cpsw_rx_dequeue()
1657 m->m_pkthdr.rcvif = psc->ifp; in cpsw_rx_dequeue()
1658 m->m_flags |= M_PKTHDR; in cpsw_rx_dequeue()
1663 m->m_next = NULL; in cpsw_rx_dequeue()
1664 m->m_nextpkt = NULL; in cpsw_rx_dequeue()
1667 m_adj(m0, -ETHER_CRC_LEN); in cpsw_rx_dequeue()
1670 if (nsegs > sc->rx.longest_chain) in cpsw_rx_dequeue()
1671 sc->rx.longest_chain = nsegs; in cpsw_rx_dequeue()
1675 if ((if_getcapenable(psc->ifp) & IFCAP_RXCSUM) != 0) { in cpsw_rx_dequeue()
1680 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED; in cpsw_rx_dequeue()
1681 m->m_pkthdr.csum_flags |= CSUM_IP_VALID; in cpsw_rx_dequeue()
1682 m->m_pkthdr.csum_data = 0xffff; in cpsw_rx_dequeue()
1686 if (STAILQ_FIRST(&sc->rx.active) != NULL && in cpsw_rx_dequeue()
1689 cpsw_write_hdp_slot(sc, &sc->rx, in cpsw_rx_dequeue()
1690 STAILQ_FIRST(&sc->rx.active)); in cpsw_rx_dequeue()
1691 sc->rx.queue_restart++; in cpsw_rx_dequeue()
1696 mb_tail->m_nextpkt = m; in cpsw_rx_dequeue()
1698 mb_tail->m_next = m; in cpsw_rx_dequeue()
1703 __func__, if_name(psc->ifp)); in cpsw_rx_dequeue()
1713 cpsw_write_cp_slot(sc, &sc->rx, last); in cpsw_rx_dequeue()
1714 sc->rx.queue_removes += removed; in cpsw_rx_dequeue()
1715 sc->rx.avail_queue_len += removed; in cpsw_rx_dequeue()
1716 sc->rx.active_queue_len -= removed; in cpsw_rx_dequeue()
1717 if (sc->rx.avail_queue_len > sc->rx.max_avail_queue_len) in cpsw_rx_dequeue()
1718 sc->rx.max_avail_queue_len = sc->rx.avail_queue_len; in cpsw_rx_dequeue()
1735 last_old_slot = STAILQ_LAST(&sc->rx.active, cpsw_slot, next); in cpsw_rx_enqueue()
1736 while ((slot = STAILQ_FIRST(&sc->rx.avail)) != NULL) { in cpsw_rx_enqueue()
1739 if (slot->mbuf == NULL) { in cpsw_rx_enqueue()
1740 slot->mbuf = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); in cpsw_rx_enqueue()
1741 if (slot->mbuf == NULL) { in cpsw_rx_enqueue()
1742 device_printf(sc->dev, in cpsw_rx_enqueue()
1746 slot->mbuf->m_len = in cpsw_rx_enqueue()
1747 slot->mbuf->m_pkthdr.len = in cpsw_rx_enqueue()
1748 slot->mbuf->m_ext.ext_size; in cpsw_rx_enqueue()
1751 error = bus_dmamap_load_mbuf_sg(sc->mbuf_dtag, slot->dmamap, in cpsw_rx_enqueue()
1752 slot->mbuf, seg, &nsegs, BUS_DMA_NOWAIT); in cpsw_rx_enqueue()
1757 device_printf(sc->dev, in cpsw_rx_enqueue()
1760 bus_dmamap_unload(sc->mbuf_dtag, slot->dmamap); in cpsw_rx_enqueue()
1761 m_freem(slot->mbuf); in cpsw_rx_enqueue()
1762 slot->mbuf = NULL; in cpsw_rx_enqueue()
1766 bus_dmamap_sync(sc->mbuf_dtag, slot->dmamap, BUS_DMASYNC_PREREAD); in cpsw_rx_enqueue()
1773 bd.bufptr = seg->ds_addr; in cpsw_rx_enqueue()
1775 bd.buflen = MCLBYTES - 1; in cpsw_rx_enqueue()
1781 STAILQ_REMOVE_HEAD(&sc->rx.avail, next); in cpsw_rx_enqueue()
1782 STAILQ_INSERT_TAIL(&sc->rx.active, slot, next); in cpsw_rx_enqueue()
1793 cpsw_write_hdp_slot(sc, &sc->rx, first_new_slot); in cpsw_rx_enqueue()
1798 sc->rx.queue_adds += added; in cpsw_rx_enqueue()
1799 sc->rx.avail_queue_len -= added; in cpsw_rx_enqueue()
1800 sc->rx.active_queue_len += added; in cpsw_rx_enqueue()
1802 if (sc->rx.active_queue_len > sc->rx.max_active_queue_len) in cpsw_rx_enqueue()
1803 sc->rx.max_active_queue_len = sc->rx.active_queue_len; in cpsw_rx_enqueue()
1813 sc->swsc->tx.running == 0) { in cpswp_start()
1816 CPSW_TX_LOCK(sc->swsc); in cpswp_start()
1818 cpsw_tx_dequeue(sc->swsc); in cpswp_start()
1819 CPSW_TX_UNLOCK(sc->swsc); in cpswp_start()
1830 cpsw_write_cp(sc, &sc->tx, 0xfffffffc); in cpsw_intr_tx()
1848 last_old_slot = STAILQ_LAST(&sc->swsc->tx.active, cpsw_slot, next); in cpswp_tx_enqueue()
1849 while ((slot = STAILQ_FIRST(&sc->swsc->tx.avail)) != NULL) { in cpswp_tx_enqueue()
1850 m0 = if_dequeue(sc->ifp); in cpswp_tx_enqueue()
1854 slot->mbuf = m0; in cpswp_tx_enqueue()
1855 padlen = ETHER_MIN_LEN - ETHER_CRC_LEN - m0->m_pkthdr.len; in cpswp_tx_enqueue()
1859 m_append(slot->mbuf, padlen, sc->swsc->nullpad); in cpswp_tx_enqueue()
1862 error = bus_dmamap_load_mbuf_sg(sc->swsc->mbuf_dtag, in cpswp_tx_enqueue()
1863 slot->dmamap, slot->mbuf, segs, &nsegs, BUS_DMA_NOWAIT); in cpswp_tx_enqueue()
1866 (error == 0 && nsegs > sc->swsc->tx.avail_queue_len)) { in cpswp_tx_enqueue()
1867 bus_dmamap_unload(sc->swsc->mbuf_dtag, slot->dmamap); in cpswp_tx_enqueue()
1868 m0 = m_defrag(slot->mbuf, M_NOWAIT); in cpswp_tx_enqueue()
1870 device_printf(sc->dev, in cpswp_tx_enqueue()
1872 m_freem(slot->mbuf); in cpswp_tx_enqueue()
1874 CPSW_DEBUGF(sc->swsc, in cpswp_tx_enqueue()
1876 if_sendq_prepend(sc->ifp, m0); in cpswp_tx_enqueue()
1878 slot->mbuf = NULL; in cpswp_tx_enqueue()
1882 device_printf(sc->dev, in cpswp_tx_enqueue()
1885 bus_dmamap_unload(sc->swsc->mbuf_dtag, slot->dmamap); in cpswp_tx_enqueue()
1886 m_freem(slot->mbuf); in cpswp_tx_enqueue()
1887 slot->mbuf = NULL; in cpswp_tx_enqueue()
1891 bus_dmamap_sync(sc->swsc->mbuf_dtag, slot->dmamap, in cpswp_tx_enqueue()
1894 CPSW_DEBUGF(sc->swsc, in cpswp_tx_enqueue()
1903 cpsw_cpdma_write_bd_next(sc->swsc, last, slot); in cpswp_tx_enqueue()
1905 slot->ifp = sc->ifp; in cpswp_tx_enqueue()
1912 bd.next = cpsw_cpdma_bd_paddr(sc->swsc, next); in cpswp_tx_enqueue()
1919 bd.pktlen = m_length(slot->mbuf, NULL); in cpswp_tx_enqueue()
1921 if (sc->swsc->dualemac) { in cpswp_tx_enqueue()
1923 bd.flags |= ((sc->unit + 1) & CPDMA_BD_PORT_MASK); in cpswp_tx_enqueue()
1927 cpsw_cpdma_write_bd(sc->swsc, slot, &bd); in cpswp_tx_enqueue()
1928 STAILQ_REMOVE_HEAD(&sc->swsc->tx.avail, next); in cpswp_tx_enqueue()
1929 STAILQ_INSERT_TAIL(&sc->swsc->tx.active, slot, next); in cpswp_tx_enqueue()
1930 slot = STAILQ_FIRST(&sc->swsc->tx.avail); in cpswp_tx_enqueue()
1935 bd.next = cpsw_cpdma_bd_paddr(sc->swsc, next); in cpswp_tx_enqueue()
1947 cpsw_cpdma_write_bd(sc->swsc, slot, &bd); in cpswp_tx_enqueue()
1948 STAILQ_REMOVE_HEAD(&sc->swsc->tx.avail, next); in cpswp_tx_enqueue()
1949 STAILQ_INSERT_TAIL(&sc->swsc->tx.active, slot, next); in cpswp_tx_enqueue()
1953 if (nsegs > sc->swsc->tx.longest_chain) in cpswp_tx_enqueue()
1954 sc->swsc->tx.longest_chain = nsegs; in cpswp_tx_enqueue()
1956 BPF_MTAP(sc->ifp, m0); in cpswp_tx_enqueue()
1964 (cpsw_cpdma_read_bd_flags(sc->swsc, last_old_slot) & in cpswp_tx_enqueue()
1967 cpsw_cpdma_write_bd_next(sc->swsc, last_old_slot, in cpswp_tx_enqueue()
1971 cpsw_write_hdp_slot(sc->swsc, &sc->swsc->tx, first_new_slot); in cpswp_tx_enqueue()
1973 sc->swsc->tx.queue_adds += added; in cpswp_tx_enqueue()
1974 sc->swsc->tx.avail_queue_len -= added; in cpswp_tx_enqueue()
1975 sc->swsc->tx.active_queue_len += added; in cpswp_tx_enqueue()
1976 if (sc->swsc->tx.active_queue_len > sc->swsc->tx.max_active_queue_len) { in cpswp_tx_enqueue()
1977 sc->swsc->tx.max_active_queue_len = sc->swsc->tx.active_queue_len; in cpswp_tx_enqueue()
1979 CPSW_DEBUGF(sc->swsc, ("Queued %d TX packet(s)", added)); in cpswp_tx_enqueue()
1990 slot = STAILQ_FIRST(&sc->tx.active); in cpsw_tx_dequeue()
1997 sc->tx.teardown = 1; in cpsw_tx_dequeue()
2001 (CPDMA_BD_SOP | CPDMA_BD_OWNER) && sc->tx.teardown == 0) in cpsw_tx_dequeue()
2004 bus_dmamap_sync(sc->mbuf_dtag, slot->dmamap, BUS_DMASYNC_POSTWRITE); in cpsw_tx_dequeue()
2005 bus_dmamap_unload(sc->mbuf_dtag, slot->dmamap); in cpsw_tx_dequeue()
2006 m_freem(slot->mbuf); in cpsw_tx_dequeue()
2007 slot->mbuf = NULL; in cpsw_tx_dequeue()
2009 if (slot->ifp) { in cpsw_tx_dequeue()
2010 if (sc->tx.teardown == 0) in cpsw_tx_dequeue()
2011 if_inc_counter(slot->ifp, IFCOUNTER_OPACKETS, 1); in cpsw_tx_dequeue()
2013 if_inc_counter(slot->ifp, IFCOUNTER_OQDROPS, 1); in cpsw_tx_dequeue()
2017 while (slot != NULL && slot->mbuf == NULL) { in cpsw_tx_dequeue()
2018 STAILQ_REMOVE_HEAD(&sc->tx.active, next); in cpsw_tx_dequeue()
2019 STAILQ_INSERT_TAIL(&sc->tx.avail, slot, next); in cpsw_tx_dequeue()
2022 slot = STAILQ_FIRST(&sc->tx.active); in cpsw_tx_dequeue()
2025 cpsw_write_cp_slot(sc, &sc->tx, last_removed_slot); in cpsw_tx_dequeue()
2032 cpsw_write_hdp_slot(sc, &sc->tx, slot); in cpsw_tx_dequeue()
2033 sc->tx.queue_restart++; in cpsw_tx_dequeue()
2039 sc->tx.queue_removes += removed; in cpsw_tx_dequeue()
2040 sc->tx.active_queue_len -= removed; in cpsw_tx_dequeue()
2041 sc->tx.avail_queue_len += removed; in cpsw_tx_dequeue()
2042 if (sc->tx.avail_queue_len > sc->tx.max_avail_queue_len) in cpsw_tx_dequeue()
2043 sc->tx.max_avail_queue_len = sc->tx.avail_queue_len; in cpsw_tx_dequeue()
2047 if (sc->tx.teardown && STAILQ_EMPTY(&sc->tx.active)) { in cpsw_tx_dequeue()
2049 sc->tx.teardown = 0; in cpsw_tx_dequeue()
2050 sc->tx.running = 0; in cpsw_tx_dequeue()
2077 next = received->m_nextpkt; in cpsw_intr_rx_thresh()
2078 received->m_nextpkt = NULL; in cpsw_intr_rx_thresh()
2079 ifp = received->m_pkthdr.rcvif; in cpsw_intr_rx_thresh()
2094 device_printf(sc->dev, in cpsw_intr_misc_host_error()
2098 device_printf(sc->dev, "CPSW_CPDMA_DMA_INTSTAT_MASKED=0x%x\n", intstat); in cpsw_intr_misc_host_error()
2100 device_printf(sc->dev, "CPSW_CPDMA_DMASTATUS=0x%x\n", dmastat); in cpsw_intr_misc_host_error()
2130 cpsw_dump_queue(sc, &sc->tx.active); in cpsw_intr_misc_host_error()
2152 cpsw_dump_queue(sc, &sc->rx.active); in cpsw_intr_misc_host_error()
2159 panic("CPSW HOST ERROR INTERRUPT"); in cpsw_intr_misc_host_error()
2186 ("MDIO operation completed interrupt unimplemented")); in cpsw_intr_misc()
2203 mii_tick(sc->mii); in cpswp_tick()
2204 if (sc->media_status != sc->mii->mii_media.ifm_media) { in cpswp_tick()
2206 sc->mii->mii_media.ifm_media); in cpswp_tick()
2207 cpswp_ifmedia_upd(sc->ifp); in cpswp_tick()
2211 callout_reset(&sc->mii_callout, hz, cpswp_tick, sc); in cpswp_tick()
2221 CPSW_DEBUGF(sc->swsc, ("")); in cpswp_ifmedia_sts()
2224 mii = sc->mii; in cpswp_ifmedia_sts()
2227 ifmr->ifm_active = mii->mii_media_active; in cpswp_ifmedia_sts()
2228 ifmr->ifm_status = mii->mii_media_status; in cpswp_ifmedia_sts()
2238 CPSW_DEBUGF(sc->swsc, ("")); in cpswp_ifmedia_upd()
2240 mii_mediachg(sc->mii); in cpswp_ifmedia_upd()
2241 sc->media_status = sc->mii->mii_media.ifm_media; in cpswp_ifmedia_upd()
2253 cpsw_debugf_head("CPSW watchdog"); in cpsw_tx_watchdog_full_reset()
2254 device_printf(sc->dev, "watchdog timeout\n"); in cpsw_tx_watchdog_full_reset()
2259 cpsw_dump_queue(sc, &sc->tx.active); in cpsw_tx_watchdog_full_reset()
2261 if (!sc->dualemac && i != sc->active_slave) in cpsw_tx_watchdog_full_reset()
2263 psc = device_get_softc(sc->port[i].dev); in cpsw_tx_watchdog_full_reset()
2277 if (sc->tx.active_queue_len == 0 || !sc->tx.running) { in cpsw_tx_watchdog()
2278 sc->watchdog.timer = 0; /* Nothing to do. */ in cpsw_tx_watchdog()
2279 } else if (sc->tx.queue_removes > sc->tx.queue_removes_at_last_tick) { in cpsw_tx_watchdog()
2280 sc->watchdog.timer = 0; /* Stuff done while we weren't looking. */ in cpsw_tx_watchdog()
2282 sc->watchdog.timer = 0; /* We just did something. */ in cpsw_tx_watchdog()
2285 ++sc->watchdog.timer; in cpsw_tx_watchdog()
2286 if (sc->watchdog.timer > 5) { in cpsw_tx_watchdog()
2287 sc->watchdog.timer = 0; in cpsw_tx_watchdog()
2288 ++sc->watchdog.resets; in cpsw_tx_watchdog()
2292 sc->tx.queue_removes_at_last_tick = sc->tx.queue_removes; in cpsw_tx_watchdog()
2296 callout_reset(&sc->watchdog.callout, hz, cpsw_tx_watchdog, sc); in cpsw_tx_watchdog()
2345 int free_index = -1, matching_index = -1, i; in cpsw_ale_mc_entry_set()
2373 if (vlan != -1) in cpsw_ale_mc_entry_set()
2440 if (sc->swsc->dualemac) in cpswp_set_maddr()
2441 portmask = 1 << (sc->unit + 1) | 1 << 0; in cpswp_set_maddr()
2445 cpsw_ale_mc_entry_set(sc->swsc, portmask, sc->vlan, LLADDR(sdl)); in cpswp_set_maddr()
2456 if (sc->swsc->dualemac) { in cpswp_ale_update_addresses()
2457 ale_type = ALE_TYPE_VLAN_ADDR << 28 | sc->vlan << 16; in cpswp_ale_update_addresses()
2458 portmask = 1 << (sc->unit + 1) | 1 << 0; in cpswp_ale_update_addresses()
2469 mac = LLADDR((struct sockaddr_dl *)if_getifaddr(sc->ifp)->ifa_addr); in cpswp_ale_update_addresses()
2473 cpsw_ale_write_entry(sc->swsc, 0 + 2 * sc->unit, ale_entry); in cpswp_ale_update_addresses()
2476 cpsw_write_4(sc->swsc, CPSW_PORT_P_SA_HI(sc->unit + 1), in cpswp_ale_update_addresses()
2478 cpsw_write_4(sc->swsc, CPSW_PORT_P_SA_LO(sc->unit + 1), in cpswp_ale_update_addresses()
2486 cpsw_ale_write_entry(sc->swsc, 1 + 2 * sc->unit, ale_entry); in cpswp_ale_update_addresses()
2491 cpsw_ale_remove_all_mc_entries(sc->swsc); in cpswp_ale_update_addresses()
2494 if_foreach_llmaddr(sc->ifp, cpswp_set_maddr, sc); in cpswp_ale_update_addresses()
2506 free_index = matching_index = -1; in cpsw_ale_update_vlan_table()
2523 return (-1); in cpsw_ale_update_vlan_table()
2553 (intmax_t)sc->shadow_stats[i], r,
2554 (intmax_t)sc->shadow_stats[i] + r));
2570 sc->shadow_stats[i] += r; in cpsw_stats_collect()
2584 stat = &cpsw_stat_sysctls[oidp->oid_number]; in cpsw_stats_sysctl()
2585 result = sc->shadow_stats[oidp->oid_number]; in cpsw_stats_sysctl()
2586 result += cpsw_read_4(sc, CPSW_STATS_OFFSET + stat->reg); in cpsw_stats_sysctl()
2599 bintime_sub(&t, &sc->attach_uptime); in cpsw_stat_attached()
2612 error = sysctl_handle_int(oidp, &sc->coal_us, 0, req); in cpsw_intr_coalesce()
2613 if (error != 0 || req->newptr == NULL) in cpsw_intr_coalesce()
2618 if (sc->coal_us == 0) { in cpsw_intr_coalesce()
2626 if (sc->coal_us > CPSW_WR_C_IMAX_US_MAX) in cpsw_intr_coalesce()
2627 sc->coal_us = CPSW_WR_C_IMAX_US_MAX; in cpsw_intr_coalesce()
2628 if (sc->coal_us < CPSW_WR_C_IMAX_US_MIN) in cpsw_intr_coalesce()
2629 sc->coal_us = CPSW_WR_C_IMAX_US_MIN; in cpsw_intr_coalesce()
2630 intr_per_ms = 1000 / sc->coal_us; in cpsw_intr_coalesce()
2658 sc = device_get_softc(swsc->port[arg2].dev); in cpsw_stat_uptime()
2659 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) { in cpsw_stat_uptime()
2661 bintime_sub(&t, &sc->init_uptime); in cpsw_stat_uptime()
2676 CTLFLAG_RD, &queue->queue_slots, 0, in cpsw_add_queue_sysctls()
2679 CTLFLAG_RD, &queue->active_queue_len, 0, in cpsw_add_queue_sysctls()
2682 CTLFLAG_RD, &queue->max_active_queue_len, 0, in cpsw_add_queue_sysctls()
2685 CTLFLAG_RD, &queue->avail_queue_len, 0, in cpsw_add_queue_sysctls()
2689 CTLFLAG_RD, &queue->max_avail_queue_len, 0, in cpsw_add_queue_sysctls()
2692 CTLFLAG_RD, &queue->queue_adds, 0, in cpsw_add_queue_sysctls()
2695 CTLFLAG_RD, &queue->queue_removes, 0, in cpsw_add_queue_sysctls()
2698 CTLFLAG_RD, &queue->queue_restart, 0, in cpsw_add_queue_sysctls()
2701 CTLFLAG_RD, &queue->longest_chain, 0, in cpsw_add_queue_sysctls()
2713 CTLFLAG_RD, &sc->watchdog.resets, 0, in cpsw_add_watchdog_sysctls()
2727 ctx = device_get_sysctl_ctx(sc->dev); in cpsw_add_sysctls()
2728 parent = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)); in cpsw_add_sysctls()
2731 CTLFLAG_RW, &sc->debug, 0, "Enable switch debug messages"); in cpsw_add_sysctls()
2744 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "CPSW Ports Statistics"); in cpsw_add_sysctls()
2747 if (!sc->dualemac && i != sc->active_slave) in cpsw_add_sysctls()
2753 "CPSW Port Statistics"); in cpsw_add_sysctls()
2761 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "CPSW Statistics"); in cpsw_add_sysctls()
2772 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "CPSW Queue Statistics"); in cpsw_add_sysctls()
2777 cpsw_add_queue_sysctls(ctx, node, &sc->tx); in cpsw_add_sysctls()
2781 cpsw_add_queue_sysctls(ctx, node, &sc->rx); in cpsw_add_sysctls()
2792 .es_name = "TI Common Platform Ethernet Switch (CPSW)",
2811 if (p->es_port < 0 || p->es_port > CPSW_PORTS) in cpsw_getport()
2816 if (p->es_port == CPSW_CPU_PORT) { in cpsw_getport()
2817 p->es_flags |= ETHERSWITCH_PORT_CPU; in cpsw_getport()
2818 ifmr = &p->es_ifmr; in cpsw_getport()
2819 ifmr->ifm_current = ifmr->ifm_active = in cpsw_getport()
2821 ifmr->ifm_mask = 0; in cpsw_getport()
2822 ifmr->ifm_status = IFM_ACTIVE | IFM_AVALID; in cpsw_getport()
2823 ifmr->ifm_count = 0; in cpsw_getport()
2825 psc = device_get_softc(sc->port[p->es_port - 1].dev); in cpsw_getport()
2826 err = ifmedia_ioctl(psc->ifp, &p->es_ifr, in cpsw_getport()
2827 &psc->mii->mii_media, SIOCGIFMEDIA); in cpsw_getport()
2829 reg = cpsw_read_4(sc, CPSW_PORT_P_VLAN(p->es_port)); in cpsw_getport()
2830 p->es_pvid = reg & ETHERSWITCH_VID_MASK; in cpsw_getport()
2832 reg = cpsw_read_4(sc, CPSW_ALE_PORTCTL(p->es_port)); in cpsw_getport()
2834 p->es_flags |= ETHERSWITCH_PORT_DROPUNTAGGED; in cpsw_getport()
2836 p->es_flags |= ETHERSWITCH_PORT_INGRESS; in cpsw_getport()
2849 if (p->es_port < 0 || p->es_port > CPSW_PORTS) in cpsw_setport()
2853 if (p->es_pvid != 0) { in cpsw_setport()
2854 cpsw_write_4(sc, CPSW_PORT_P_VLAN(p->es_port), in cpsw_setport()
2855 p->es_pvid & ETHERSWITCH_VID_MASK); in cpsw_setport()
2858 reg = cpsw_read_4(sc, CPSW_ALE_PORTCTL(p->es_port)); in cpsw_setport()
2859 if (p->es_flags & ETHERSWITCH_PORT_DROPUNTAGGED) in cpsw_setport()
2863 if (p->es_flags & ETHERSWITCH_PORT_INGRESS) in cpsw_setport()
2867 cpsw_write_4(sc, CPSW_ALE_PORTCTL(p->es_port), reg); in cpsw_setport()
2870 if (p->es_port == CPSW_CPU_PORT) in cpsw_setport()
2873 psc = device_get_softc(sc->port[p->es_port - 1].dev); in cpsw_setport()
2874 ifm = &psc->mii->mii_media; in cpsw_setport()
2876 return (ifmedia_ioctl(psc->ifp, &p->es_ifr, ifm, SIOCSIFMEDIA)); in cpsw_setport()
2884 conf->cmd = ETHERSWITCH_CONF_VLAN_MODE; in cpsw_getconf()
2885 conf->vlan_mode = ETHERSWITCH_VLAN_DOT1Q; in cpsw_getconf()
2899 if (vg->es_vlangroup >= CPSW_VLANS) in cpsw_getvgroup()
2902 vg->es_vid = 0; in cpsw_getvgroup()
2903 vid = cpsw_vgroups[vg->es_vlangroup].vid; in cpsw_getvgroup()
2904 if (vid == -1) in cpsw_getvgroup()
2914 vg->es_fid = 0; in cpsw_getvgroup()
2915 vg->es_vid = ALE_VLAN(ale_entry) | ETHERSWITCH_VID_VALID; in cpsw_getvgroup()
2916 vg->es_member_ports = ALE_VLAN_MEMBERS(ale_entry); in cpsw_getvgroup()
2917 vg->es_untagged_ports = ALE_VLAN_UNTAG(ale_entry); in cpsw_getvgroup()
2951 if (vg->es_vlangroup != i && cpsw_vgroups[i].vid == vg->es_vid) in cpsw_setvgroup()
2955 if (vg->es_vid == 0) { in cpsw_setvgroup()
2956 if (cpsw_vgroups[vg->es_vlangroup].vid == -1) in cpsw_setvgroup()
2958 cpsw_remove_vlan(sc, cpsw_vgroups[vg->es_vlangroup].vid); in cpsw_setvgroup()
2959 cpsw_vgroups[vg->es_vlangroup].vid = -1; in cpsw_setvgroup()
2960 vg->es_untagged_ports = 0; in cpsw_setvgroup()
2961 vg->es_member_ports = 0; in cpsw_setvgroup()
2962 vg->es_vid = 0; in cpsw_setvgroup()
2966 vg->es_vid &= ETHERSWITCH_VID_MASK; in cpsw_setvgroup()
2967 vg->es_member_ports &= CPSW_PORTS_MASK; in cpsw_setvgroup()
2968 vg->es_untagged_ports &= CPSW_PORTS_MASK; in cpsw_setvgroup()
2970 if (cpsw_vgroups[vg->es_vlangroup].vid != -1 && in cpsw_setvgroup()
2971 cpsw_vgroups[vg->es_vlangroup].vid != vg->es_vid) in cpsw_setvgroup()
2974 cpsw_vgroups[vg->es_vlangroup].vid = vg->es_vid; in cpsw_setvgroup()
2975 cpsw_ale_update_vlan_table(sc, vg->es_vid, vg->es_member_ports, in cpsw_setvgroup()
2976 vg->es_untagged_ports, vg->es_member_ports, 0); in cpsw_setvgroup()