Lines Matching full:lan966x
30 { .compatible = "microchip,lan966x-switch" },
68 struct lan966x *lan966x) in lan966x_create_targets() argument
101 lan966x->regs[iomap->id] = begin[iomap->range] + iomap->offset; in lan966x_create_targets()
110 struct lan966x *lan966x = port->lan966x; in lan966x_port_unique_address() local
113 for (p = 0; p < lan966x->num_phys_ports; ++p) { in lan966x_port_unique_address()
114 port = lan966x->ports[p]; in lan966x_port_unique_address()
128 struct lan966x *lan966x = port->lan966x; in lan966x_port_set_mac_address() local
136 ret = lan966x_mac_cpu_learn(lan966x, addr->sa_data, HOST_PVID); in lan966x_port_set_mac_address()
147 ret = lan966x_mac_cpu_forget(lan966x, dev->dev_addr, HOST_PVID); in lan966x_port_set_mac_address()
172 struct lan966x *lan966x = port->lan966x; in lan966x_port_open() local
184 lan966x, ANA_PORT_CFG(port->chip_port)); in lan966x_port_open()
208 static int lan966x_port_inj_status(struct lan966x *lan966x) in lan966x_port_inj_status() argument
210 return lan_rd(lan966x, QS_INJ_STATUS); in lan966x_port_inj_status()
213 static int lan966x_port_inj_ready(struct lan966x *lan966x, u8 grp) in lan966x_port_inj_ready() argument
217 if (lan_rd(lan966x, QS_INJ_STATUS) & QS_INJ_STATUS_FIFO_RDY_SET(BIT(grp))) in lan966x_port_inj_ready()
220 return readx_poll_timeout_atomic(lan966x_port_inj_status, lan966x, val, in lan966x_port_inj_ready()
230 struct lan966x *lan966x = port->lan966x; in lan966x_port_ifh_xmit() local
236 val = lan_rd(lan966x, QS_INJ_STATUS); in lan966x_port_ifh_xmit()
244 lan966x, QS_INJ_CTRL(grp)); in lan966x_port_ifh_xmit()
249 err = lan966x_port_inj_ready(lan966x, grp); in lan966x_port_ifh_xmit()
253 lan_wr((__force u32)ifh[i], lan966x, QS_INJ_WR(grp)); in lan966x_port_ifh_xmit()
261 err = lan966x_port_inj_ready(lan966x, grp); in lan966x_port_ifh_xmit()
265 lan_wr(((u32 *)skb->data)[i], lan966x, QS_INJ_WR(grp)); in lan966x_port_ifh_xmit()
271 err = lan966x_port_inj_ready(lan966x, grp); in lan966x_port_ifh_xmit()
275 lan_wr(0, lan966x, QS_INJ_WR(grp)); in lan966x_port_ifh_xmit()
284 lan966x, QS_INJ_CTRL(grp)); in lan966x_port_ifh_xmit()
287 lan_wr(0, lan966x, QS_INJ_WR(grp)); in lan966x_port_ifh_xmit()
365 struct lan966x *lan966x = port->lan966x; in lan966x_port_xmit() local
377 if (port->lan966x->ptp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) { in lan966x_port_xmit()
386 spin_lock(&lan966x->tx_lock); in lan966x_port_xmit()
387 if (port->lan966x->fdma) in lan966x_port_xmit()
391 spin_unlock(&lan966x->tx_lock); in lan966x_port_xmit()
399 struct lan966x *lan966x = port->lan966x; in lan966x_port_change_mtu() local
404 lan966x, DEV_MAC_MAXLEN_CFG(port->chip_port)); in lan966x_port_change_mtu()
407 if (!lan966x->fdma) in lan966x_port_change_mtu()
410 err = lan966x_fdma_change_mtu(lan966x); in lan966x_port_change_mtu()
413 lan966x, DEV_MAC_MAXLEN_CFG(port->chip_port)); in lan966x_port_change_mtu()
423 struct lan966x *lan966x = port->lan966x; in lan966x_mc_unsync() local
425 return lan966x_mac_forget(lan966x, addr, HOST_PVID, ENTRYTYPE_LOCKED); in lan966x_mc_unsync()
431 struct lan966x *lan966x = port->lan966x; in lan966x_mc_sync() local
433 return lan966x_mac_cpu_learn(lan966x, addr, HOST_PVID); in lan966x_mc_sync()
445 struct lan966x *lan966x = port->lan966x; in lan966x_port_get_parent_id() local
447 ppid->id_len = sizeof(lan966x->base_mac); in lan966x_port_get_parent_id()
448 memcpy(&ppid->id, &lan966x->base_mac, ppid->id_len); in lan966x_port_get_parent_id()
458 if (!port->lan966x->ptp) in lan966x_port_hwtstamp_get()
477 if (cfg->source == HWTSTAMP_SOURCE_NETDEV && !port->lan966x->ptp) in lan966x_port_hwtstamp_set()
518 bool lan966x_hw_offload(struct lan966x *lan966x, u32 port, struct sk_buff *skb) in lan966x_hw_offload() argument
526 val = lan_rd(lan966x, ANA_CPU_FWD_CFG(port)); in lan966x_hw_offload()
550 static int lan966x_port_xtr_status(struct lan966x *lan966x, u8 grp) in lan966x_port_xtr_status() argument
552 return lan_rd(lan966x, QS_XTR_RD(grp)); in lan966x_port_xtr_status()
555 static int lan966x_port_xtr_ready(struct lan966x *lan966x, u8 grp) in lan966x_port_xtr_ready() argument
562 lan966x, grp); in lan966x_port_xtr_ready()
565 static int lan966x_rx_frame_word(struct lan966x *lan966x, u8 grp, u32 *rval) in lan966x_rx_frame_word() argument
571 val = lan_rd(lan966x, QS_XTR_RD(grp)); in lan966x_rx_frame_word()
573 err = lan966x_port_xtr_ready(lan966x, grp); in lan966x_rx_frame_word()
587 val = lan_rd(lan966x, QS_XTR_RD(grp)); in lan966x_rx_frame_word()
589 *rval = lan_rd(lan966x, QS_XTR_RD(grp)); in lan966x_rx_frame_word()
595 *rval = lan_rd(lan966x, QS_XTR_RD(grp)); in lan966x_rx_frame_word()
641 struct lan966x *lan966x = args; in lan966x_xtr_irq_handler() local
644 if (!(lan_rd(lan966x, QS_XTR_DATA_PRESENT) & BIT(grp))) in lan966x_xtr_irq_handler()
657 err = lan966x_rx_frame_word(lan966x, grp, &ifh[i]); in lan966x_xtr_irq_handler()
668 WARN_ON(src_port >= lan966x->num_phys_ports); in lan966x_xtr_irq_handler()
670 dev = lan966x->ports[src_port]->dev; in lan966x_xtr_irq_handler()
681 sz = lan966x_rx_frame_word(lan966x, grp, &val); in lan966x_xtr_irq_handler()
692 sz = lan966x_rx_frame_word(lan966x, grp, &val); in lan966x_xtr_irq_handler()
706 lan966x_ptp_rxtstamp(lan966x, skb, src_port, timestamp); in lan966x_xtr_irq_handler()
709 if (lan966x->bridge_mask & BIT(src_port)) { in lan966x_xtr_irq_handler()
713 if (!lan966x_hw_offload(lan966x, src_port, skb)) in lan966x_xtr_irq_handler()
725 lan_rd(lan966x, QS_XTR_RD(grp)); in lan966x_xtr_irq_handler()
727 } while (lan_rd(lan966x, QS_XTR_DATA_PRESENT) & BIT(grp)); in lan966x_xtr_irq_handler()
734 struct lan966x *lan966x = args; in lan966x_ana_irq_handler() local
736 return lan966x_mac_irq_handler(lan966x); in lan966x_ana_irq_handler()
739 static void lan966x_cleanup_ports(struct lan966x *lan966x) in lan966x_cleanup_ports() argument
744 for (p = 0; p < lan966x->num_phys_ports; p++) { in lan966x_cleanup_ports()
745 port = lan966x->ports[p]; in lan966x_cleanup_ports()
753 if (lan966x->fdma && lan966x->fdma_ndev == port->dev) in lan966x_cleanup_ports()
754 lan966x_fdma_netdev_deinit(lan966x, port->dev); in lan966x_cleanup_ports()
768 disable_irq(lan966x->xtr_irq); in lan966x_cleanup_ports()
769 lan966x->xtr_irq = -ENXIO; in lan966x_cleanup_ports()
771 if (lan966x->ana_irq > 0) { in lan966x_cleanup_ports()
772 disable_irq(lan966x->ana_irq); in lan966x_cleanup_ports()
773 lan966x->ana_irq = -ENXIO; in lan966x_cleanup_ports()
776 if (lan966x->fdma) in lan966x_cleanup_ports()
777 devm_free_irq(lan966x->dev, lan966x->fdma_irq, lan966x); in lan966x_cleanup_ports()
779 if (lan966x->ptp_irq > 0) in lan966x_cleanup_ports()
780 devm_free_irq(lan966x->dev, lan966x->ptp_irq, lan966x); in lan966x_cleanup_ports()
782 if (lan966x->ptp_ext_irq > 0) in lan966x_cleanup_ports()
783 devm_free_irq(lan966x->dev, lan966x->ptp_ext_irq, lan966x); in lan966x_cleanup_ports()
786 static int lan966x_probe_port(struct lan966x *lan966x, u32 p, in lan966x_probe_port() argument
795 if (p >= lan966x->num_phys_ports) in lan966x_probe_port()
798 dev = devm_alloc_etherdev_mqs(lan966x->dev, in lan966x_probe_port()
804 SET_NETDEV_DEV(dev, lan966x->dev); in lan966x_probe_port()
807 port->lan966x = lan966x; in lan966x_probe_port()
809 lan966x->ports[p] = port; in lan966x_probe_port()
822 eth_hw_addr_gen(dev, lan966x->base_mac, p + 1); in lan966x_probe_port()
824 lan966x_mac_learn(lan966x, PGID_CPU, dev->dev_addr, HOST_PVID, in lan966x_probe_port()
863 if (lan966x->fdma) in lan966x_probe_port()
870 dev_err(lan966x->dev, "register_netdev failed\n"); in lan966x_probe_port()
881 static void lan966x_init(struct lan966x *lan966x) in lan966x_init() argument
886 lan966x_mac_init(lan966x); in lan966x_init()
888 lan966x_vlan_init(lan966x); in lan966x_init()
891 lan_wr(lan_rd(lan966x, QS_XTR_FLUSH) | in lan966x_init()
893 lan966x, QS_XTR_FLUSH); in lan966x_init()
899 lan_wr(lan_rd(lan966x, QS_XTR_FLUSH) & in lan966x_init()
901 lan966x, QS_XTR_FLUSH); in lan966x_init()
907 lan966x, ANA_AUTOAGE); in lan966x_init()
912 lan966x, ANA_ADVLEARN); in lan966x_init()
914 /* Setup frame ageing - "2 sec" - The unit is 6.5 us on lan966x */ in lan966x_init()
917 lan966x, SYS_FRM_AGING); in lan966x_init()
920 lan_wr(0, lan966x, QSYS_CPU_GROUP_MAP); in lan966x_init()
925 lan_wr(QS_XTR_GRP_CFG_MODE_SET(lan966x->fdma ? 2 : 1) | in lan966x_init()
927 lan966x, QS_XTR_GRP_CFG(0)); in lan966x_init()
930 lan_wr(QS_INJ_GRP_CFG_MODE_SET(lan966x->fdma ? 2 : 1) | in lan966x_init()
932 lan966x, QS_INJ_GRP_CFG(0)); in lan966x_init()
936 lan966x, QS_INJ_CTRL(0)); in lan966x_init()
941 lan966x, SYS_PORT_MODE(CPU_PORT)); in lan966x_init()
948 lan966x, ANA_FLOODING_IPMC); in lan966x_init()
958 lan966x, ANA_FLOODING(i)); in lan966x_init()
964 lan966x, ANA_PGID_CFG(i)); in lan966x_init()
966 for (p = 0; p < lan966x->num_phys_ports; p++) { in lan966x_init()
970 lan966x, ANA_PGID(p + PGID_SRC)); in lan966x_init()
975 lan_wr(0xffff, lan966x, ANA_CPU_FWD_BPDU_CFG(p)); in lan966x_init()
980 lan_wr(1500 / 64, lan966x, QSYS_RES_CFG(i)); in lan966x_init()
981 lan_wr(1500 / 64, lan966x, QSYS_RES_CFG(512 + i)); in lan966x_init()
988 lan966x, QSYS_SW_PORT_MODE(CPU_PORT)); in lan966x_init()
993 lan966x, ANA_PGID(CPU_PORT)); in lan966x_init()
996 lan966x, ANA_PGID(PGID_CPU)); in lan966x_init()
999 lan_rmw(GENMASK(lan966x->num_phys_ports - 1, 0), in lan966x_init()
1001 lan966x, ANA_PGID(PGID_MC)); in lan966x_init()
1004 lan_rmw(GENMASK(lan966x->num_phys_ports - 1, 0), in lan966x_init()
1006 lan966x, ANA_PGID(PGID_MCIPV4)); in lan966x_init()
1008 lan_rmw(GENMASK(lan966x->num_phys_ports - 1, 0), in lan966x_init()
1010 lan966x, ANA_PGID(PGID_MCIPV6)); in lan966x_init()
1013 lan_rmw(GENMASK(lan966x->num_phys_ports - 1, 0), in lan966x_init()
1015 lan966x, ANA_PGID(PGID_UC)); in lan966x_init()
1018 lan_rmw(ANA_PGID_PGID_SET(BIT(CPU_PORT) | GENMASK(lan966x->num_phys_ports - 1, 0)), in lan966x_init()
1020 lan966x, ANA_PGID(PGID_BC)); in lan966x_init()
1023 lan966x, REW_PORT_CFG(CPU_PORT)); in lan966x_init()
1027 lan966x, ANA_ANAINTR); in lan966x_init()
1029 spin_lock_init(&lan966x->tx_lock); in lan966x_init()
1031 lan966x_taprio_init(lan966x); in lan966x_init()
1034 static int lan966x_ram_init(struct lan966x *lan966x) in lan966x_ram_init() argument
1036 return lan_rd(lan966x, SYS_RAM_INIT); in lan966x_ram_init()
1039 static int lan966x_reset_switch(struct lan966x *lan966x) in lan966x_reset_switch() argument
1045 switch_reset = devm_reset_control_get_optional_shared(lan966x->dev, in lan966x_reset_switch()
1048 return dev_err_probe(lan966x->dev, PTR_ERR(switch_reset), in lan966x_reset_switch()
1060 if (lan_rd(lan966x, SYS_RESET_CFG) & SYS_RESET_CFG_CORE_ENA) in lan966x_reset_switch()
1063 lan_wr(SYS_RESET_CFG_CORE_ENA_SET(0), lan966x, SYS_RESET_CFG); in lan966x_reset_switch()
1064 lan_wr(SYS_RAM_INIT_RAM_INIT_SET(1), lan966x, SYS_RAM_INIT); in lan966x_reset_switch()
1065 ret = readx_poll_timeout(lan966x_ram_init, lan966x, in lan966x_reset_switch()
1071 lan_wr(SYS_RESET_CFG_CORE_ENA_SET(1), lan966x, SYS_RESET_CFG); in lan966x_reset_switch()
1079 struct lan966x *lan966x; in lan966x_probe() local
1083 lan966x = devm_kzalloc(&pdev->dev, sizeof(*lan966x), GFP_KERNEL); in lan966x_probe()
1084 if (!lan966x) in lan966x_probe()
1087 platform_set_drvdata(pdev, lan966x); in lan966x_probe()
1088 lan966x->dev = &pdev->dev; in lan966x_probe()
1091 ether_addr_copy(lan966x->base_mac, mac_addr); in lan966x_probe()
1094 eth_random_addr(lan966x->base_mac); in lan966x_probe()
1095 lan966x->base_mac[5] &= 0xf0; in lan966x_probe()
1098 err = lan966x_create_targets(pdev, lan966x); in lan966x_probe()
1103 err = lan966x_reset_switch(lan966x); in lan966x_probe()
1107 lan966x->num_phys_ports = NUM_PHYS_PORTS; in lan966x_probe()
1108 lan966x->ports = devm_kcalloc(&pdev->dev, lan966x->num_phys_ports, in lan966x_probe()
1111 if (!lan966x->ports) in lan966x_probe()
1115 lan966x->shared_queue_sz = LAN966X_BUFFER_MEMORY; in lan966x_probe()
1118 lan966x->xtr_irq = platform_get_irq_byname(pdev, "xtr"); in lan966x_probe()
1119 if (lan966x->xtr_irq < 0) in lan966x_probe()
1120 return lan966x->xtr_irq; in lan966x_probe()
1122 err = devm_request_threaded_irq(&pdev->dev, lan966x->xtr_irq, NULL, in lan966x_probe()
1124 "frame extraction", lan966x); in lan966x_probe()
1130 lan966x->ana_irq = platform_get_irq_byname(pdev, "ana"); in lan966x_probe()
1131 if (lan966x->ana_irq > 0) { in lan966x_probe()
1132 err = devm_request_threaded_irq(&pdev->dev, lan966x->ana_irq, NULL, in lan966x_probe()
1134 "ana irq", lan966x); in lan966x_probe()
1139 lan966x->ptp_irq = platform_get_irq_byname(pdev, "ptp"); in lan966x_probe()
1140 if (lan966x->ptp_irq > 0) { in lan966x_probe()
1141 err = devm_request_threaded_irq(&pdev->dev, lan966x->ptp_irq, NULL, in lan966x_probe()
1143 "ptp irq", lan966x); in lan966x_probe()
1147 lan966x->ptp = 1; in lan966x_probe()
1150 lan966x->fdma_irq = platform_get_irq_byname(pdev, "fdma"); in lan966x_probe()
1151 if (lan966x->fdma_irq > 0) { in lan966x_probe()
1152 err = devm_request_irq(&pdev->dev, lan966x->fdma_irq, in lan966x_probe()
1154 "fdma irq", lan966x); in lan966x_probe()
1158 lan966x->fdma = true; in lan966x_probe()
1161 if (lan966x->ptp) { in lan966x_probe()
1162 lan966x->ptp_ext_irq = platform_get_irq_byname(pdev, "ptp-ext"); in lan966x_probe()
1163 if (lan966x->ptp_ext_irq > 0) { in lan966x_probe()
1165 lan966x->ptp_ext_irq, NULL, in lan966x_probe()
1168 "ptp-ext irq", lan966x); in lan966x_probe()
1180 lan966x->debugfs_root = debugfs_create_dir("lan966x", NULL); in lan966x_probe()
1183 lan966x_init(lan966x); in lan966x_probe()
1184 lan966x_stats_init(lan966x); in lan966x_probe()
1196 err = lan966x_probe_port(lan966x, p, phy_mode, portnp); in lan966x_probe()
1201 lan966x->ports[p]->config.portmode = phy_mode; in lan966x_probe()
1202 lan966x->ports[p]->fwnode = fwnode_handle_get(portnp); in lan966x_probe()
1204 serdes = devm_of_phy_optional_get(lan966x->dev, in lan966x_probe()
1210 lan966x->ports[p]->serdes = serdes; in lan966x_probe()
1212 lan966x_port_init(lan966x->ports[p]); in lan966x_probe()
1213 err = lan966x_xdp_port_init(lan966x->ports[p]); in lan966x_probe()
1220 lan966x_mdb_init(lan966x); in lan966x_probe()
1221 err = lan966x_fdb_init(lan966x); in lan966x_probe()
1225 err = lan966x_ptp_init(lan966x); in lan966x_probe()
1229 err = lan966x_fdma_init(lan966x); in lan966x_probe()
1233 err = lan966x_vcap_init(lan966x); in lan966x_probe()
1237 lan966x_dcb_init(lan966x); in lan966x_probe()
1242 lan966x_fdma_deinit(lan966x); in lan966x_probe()
1245 lan966x_ptp_deinit(lan966x); in lan966x_probe()
1248 lan966x_fdb_deinit(lan966x); in lan966x_probe()
1254 lan966x_cleanup_ports(lan966x); in lan966x_probe()
1256 cancel_delayed_work_sync(&lan966x->stats_work); in lan966x_probe()
1257 destroy_workqueue(lan966x->stats_queue); in lan966x_probe()
1258 mutex_destroy(&lan966x->stats_lock); in lan966x_probe()
1260 debugfs_remove_recursive(lan966x->debugfs_root); in lan966x_probe()
1267 struct lan966x *lan966x = platform_get_drvdata(pdev); in lan966x_remove() local
1269 lan966x_taprio_deinit(lan966x); in lan966x_remove()
1270 lan966x_vcap_deinit(lan966x); in lan966x_remove()
1271 lan966x_fdma_deinit(lan966x); in lan966x_remove()
1272 lan966x_cleanup_ports(lan966x); in lan966x_remove()
1274 cancel_delayed_work_sync(&lan966x->stats_work); in lan966x_remove()
1275 destroy_workqueue(lan966x->stats_queue); in lan966x_remove()
1276 mutex_destroy(&lan966x->stats_lock); in lan966x_remove()
1278 lan966x_mac_purge_entries(lan966x); in lan966x_remove()
1279 lan966x_mdb_deinit(lan966x); in lan966x_remove()
1280 lan966x_fdb_deinit(lan966x); in lan966x_remove()
1281 lan966x_ptp_deinit(lan966x); in lan966x_remove()
1283 debugfs_remove_recursive(lan966x->debugfs_root); in lan966x_remove()
1290 .name = "lan966x-switch",
1321 MODULE_DESCRIPTION("Microchip LAN966X switch driver");