Lines Matching +full:lan966x +full:- +full:switch
1 // SPDX-License-Identifier: GPL-2.0+
25 #define XTR_VALID_BYTES(x) (4 - (((x) >> 24) & 3))
30 { .compatible = "microchip,lan966x-switch" },
68 struct lan966x *lan966x) in lan966x_create_targets() argument
83 dev_err(&pdev->dev, "Invalid resource\n"); in lan966x_create_targets()
84 return -EINVAL; in lan966x_create_targets()
87 begin[idx] = devm_ioremap(&pdev->dev, in lan966x_create_targets()
88 iores[idx]->start, in lan966x_create_targets()
91 dev_err(&pdev->dev, "Unable to get registers: %s\n", in lan966x_create_targets()
92 iores[idx]->name); in lan966x_create_targets()
93 return -ENOMEM; in lan966x_create_targets()
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()
115 if (!port || port->dev == dev) in lan966x_port_unique_address()
118 if (ether_addr_equal(dev->dev_addr, port->dev->dev_addr)) in lan966x_port_unique_address()
128 struct lan966x *lan966x = port->lan966x; in lan966x_port_set_mac_address() local
132 if (ether_addr_equal(addr->sa_data, dev->dev_addr)) in lan966x_port_set_mac_address()
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()
152 eth_hw_addr_set(dev, addr->sa_data); in lan966x_port_set_mac_address()
162 ret = snprintf(buf, len, "p%d", port->chip_port); in lan966x_port_get_phys_port_name()
164 return -EINVAL; in lan966x_port_get_phys_port_name()
172 struct lan966x *lan966x = port->lan966x; in lan966x_port_open() local
175 /* Enable receiving frames on the port, and activate auto-learning of in lan966x_port_open()
180 ANA_PORT_CFG_PORTID_VAL_SET(port->chip_port), in lan966x_port_open()
184 lan966x, ANA_PORT_CFG(port->chip_port)); in lan966x_port_open()
186 err = phylink_fwnode_phy_connect(port->phylink, port->fwnode, 0); in lan966x_port_open()
192 phylink_start(port->phylink); in lan966x_port_open()
202 phylink_stop(port->phylink); in lan966x_port_stop()
203 phylink_disconnect_phy(port->phylink); in lan966x_port_stop()
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()
257 count = DIV_ROUND_UP(skb->len, 4); in lan966x_port_ifh_xmit()
258 last = skb->len % 4; 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()
281 QS_INJ_CTRL_VLD_BYTES_SET(skb->len < LAN966X_BUFFER_MIN_SZ ? 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()
290 dev->stats.tx_packets++; in lan966x_port_ifh_xmit()
291 dev->stats.tx_bytes += skb->len; in lan966x_port_ifh_xmit()
293 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && in lan966x_port_ifh_xmit()
294 LAN966X_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP) in lan966x_port_ifh_xmit()
301 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && in lan966x_port_ifh_xmit()
302 LAN966X_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP) in lan966x_port_ifh_xmit()
313 u8 p = IFH_LEN_BYTES - (pos + i) / 8 - 1; in lan966x_ifh_set()
320 ifh[p - 1] |= v >> (8 - (pos + i) % 8); in lan966x_ifh_set()
365 struct lan966x *lan966x = port->lan966x; in lan966x_port_xmit() local
372 lan966x_ifh_set_port(ifh, BIT_ULL(port->chip_port)); in lan966x_port_xmit()
373 lan966x_ifh_set_qos_class(ifh, skb->priority >= 7 ? 0x7 : skb->priority); in lan966x_port_xmit()
374 lan966x_ifh_set_ipv(ifh, skb->priority >= 7 ? 0x7 : skb->priority); in lan966x_port_xmit()
377 if (port->lan966x->ptp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) { in lan966x_port_xmit()
382 lan966x_ifh_set_rew_op(ifh, LAN966X_SKB_CB(skb)->rew_op); in lan966x_port_xmit()
383 lan966x_ifh_set_timestamp(ifh, LAN966X_SKB_CB(skb)->ts_id); 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
400 int old_mtu = dev->mtu; in lan966x_port_change_mtu()
404 lan966x, DEV_MAC_MAXLEN_CFG(port->chip_port)); in lan966x_port_change_mtu()
405 WRITE_ONCE(dev->mtu, new_mtu); 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()
414 dev->mtu = old_mtu; 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()
459 return -EOPNOTSUPP; in lan966x_port_hwtstamp_get()
473 if (cfg->source != HWTSTAMP_SOURCE_NETDEV && in lan966x_port_hwtstamp_set()
474 cfg->source != HWTSTAMP_SOURCE_PHYLIB) in lan966x_port_hwtstamp_set()
475 return -EOPNOTSUPP; in lan966x_port_hwtstamp_set()
477 if (cfg->source == HWTSTAMP_SOURCE_NETDEV && !port->lan966x->ptp) in lan966x_port_hwtstamp_set()
478 return -EOPNOTSUPP; in lan966x_port_hwtstamp_set()
484 if (cfg->source == HWTSTAMP_SOURCE_NETDEV) { in lan966x_port_hwtstamp_set()
515 return dev->netdev_ops == &lan966x_port_netdev_ops; in lan966x_netdevice_check()
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()
531 if (eth_type_vlan(skb->protocol)) { in lan966x_hw_offload()
537 if (skb->protocol == htons(ETH_P_IP) && in lan966x_hw_offload()
538 ip_hdr(skb)->protocol == IPPROTO_IGMP) in lan966x_hw_offload()
542 skb->protocol == htons(ETH_P_IPV6) && in lan966x_hw_offload()
543 ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) && 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()
575 return -EIO; in lan966x_rx_frame_word()
578 switch (val) { in lan966x_rx_frame_word()
580 return -EIO; 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()
615 v = ifh[IFH_LEN_BYTES - (j / 8) - 1]; in lan966x_ifh_get()
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()
676 buf_len = len - ETH_FCS_LEN; 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()
699 len -= ETH_FCS_LEN - sz; in lan966x_xtr_irq_handler()
701 if (unlikely(dev->features & NETIF_F_RXFCS)) { in lan966x_xtr_irq_handler()
706 lan966x_ptp_rxtstamp(lan966x, skb, src_port, timestamp); in lan966x_xtr_irq_handler()
707 skb->protocol = eth_type_trans(skb, dev); in lan966x_xtr_irq_handler()
709 if (lan966x->bridge_mask & BIT(src_port)) { in lan966x_xtr_irq_handler()
710 skb->offload_fwd_mark = 1; in lan966x_xtr_irq_handler()
713 if (!lan966x_hw_offload(lan966x, src_port, skb)) in lan966x_xtr_irq_handler()
714 skb->offload_fwd_mark = 0; in lan966x_xtr_irq_handler()
720 dev->stats.rx_bytes += len; in lan966x_xtr_irq_handler()
721 dev->stats.rx_packets++; 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()
749 if (port->dev) in lan966x_cleanup_ports()
750 unregister_netdev(port->dev); 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()
756 if (port->phylink) { in lan966x_cleanup_ports()
758 lan966x_port_stop(port->dev); in lan966x_cleanup_ports()
760 phylink_destroy(port->phylink); in lan966x_cleanup_ports()
761 port->phylink = NULL; in lan966x_cleanup_ports()
764 if (port->fwnode) in lan966x_cleanup_ports()
765 fwnode_handle_put(port->fwnode); 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()
796 return -EINVAL; in lan966x_probe_port()
798 dev = devm_alloc_etherdev_mqs(lan966x->dev, in lan966x_probe_port()
802 return -ENOMEM; in lan966x_probe_port()
804 SET_NETDEV_DEV(dev, lan966x->dev); in lan966x_probe_port()
806 port->dev = dev; in lan966x_probe_port()
807 port->lan966x = lan966x; in lan966x_probe_port()
808 port->chip_port = p; in lan966x_probe_port()
809 lan966x->ports[p] = port; in lan966x_probe_port()
811 dev->max_mtu = ETH_MAX_MTU; in lan966x_probe_port()
813 dev->netdev_ops = &lan966x_port_netdev_ops; in lan966x_probe_port()
814 dev->ethtool_ops = &lan966x_ethtool_ops; in lan966x_probe_port()
815 dev->features |= NETIF_F_HW_VLAN_CTAG_TX | in lan966x_probe_port()
818 dev->hw_features |= NETIF_F_HW_TC; in lan966x_probe_port()
819 dev->see_all_hwtstamp_requests = true; in lan966x_probe_port()
820 dev->needed_headroom = IFH_LEN_BYTES; 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()
827 port->phylink_config.dev = &port->dev->dev; in lan966x_probe_port()
828 port->phylink_config.type = PHYLINK_NETDEV; in lan966x_probe_port()
829 port->phylink_pcs.poll = true; in lan966x_probe_port()
830 port->phylink_pcs.ops = &lan966x_phylink_pcs_ops; in lan966x_probe_port()
831 port->phylink_pcs.neg_mode = true; in lan966x_probe_port()
833 port->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | in lan966x_probe_port()
836 phy_interface_set_rgmii(port->phylink_config.supported_interfaces); in lan966x_probe_port()
838 port->phylink_config.supported_interfaces); in lan966x_probe_port()
840 port->phylink_config.supported_interfaces); in lan966x_probe_port()
842 port->phylink_config.supported_interfaces); in lan966x_probe_port()
844 port->phylink_config.supported_interfaces); in lan966x_probe_port()
846 port->phylink_config.supported_interfaces); in lan966x_probe_port()
848 port->phylink_config.supported_interfaces); in lan966x_probe_port()
850 port->phylink_config.supported_interfaces); in lan966x_probe_port()
852 phylink = phylink_create(&port->phylink_config, in lan966x_probe_port()
857 port->dev = NULL; in lan966x_probe_port()
861 port->phylink = phylink; in lan966x_probe_port()
863 if (lan966x->fdma) in lan966x_probe_port()
864 dev->xdp_features = NETDEV_XDP_ACT_BASIC | 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()
922 /* Do byte-swap and expect status after last data word 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()
1046 "switch"); in lan966x_reset_switch()
1048 return dev_err_probe(lan966x->dev, PTR_ERR(switch_reset), in lan966x_reset_switch()
1049 "Could not obtain switch reset"); in lan966x_reset_switch()
1053 /* Don't reinitialize the switch core, if it is already initialized. In in lan966x_reset_switch()
1056 * full and no traffic is passing through the switch. The issue is seen in lan966x_reset_switch()
1058 * switch. 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()
1085 return -ENOMEM; in lan966x_probe()
1087 platform_set_drvdata(pdev, lan966x); in lan966x_probe()
1088 lan966x->dev = &pdev->dev; in lan966x_probe()
1090 if (!device_get_mac_address(&pdev->dev, mac_addr)) { 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()
1100 return dev_err_probe(&pdev->dev, err, in lan966x_probe()
1103 err = lan966x_reset_switch(lan966x); in lan966x_probe()
1105 return dev_err_probe(&pdev->dev, err, "Reset failed"); 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()
1112 return -ENOMEM; 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()
1127 return -ENODEV; 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()
1136 return dev_err_probe(&pdev->dev, err, "Unable to use ana irq"); 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()
1145 return dev_err_probe(&pdev->dev, err, "Unable to use ptp irq"); 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()
1156 return dev_err_probe(&pdev->dev, err, "Unable to use fdma irq"); 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()
1164 err = devm_request_threaded_irq(&pdev->dev, in lan966x_probe()
1165 lan966x->ptp_ext_irq, NULL, in lan966x_probe()
1168 "ptp-ext irq", lan966x); in lan966x_probe()
1170 return dev_err_probe(&pdev->dev, err, in lan966x_probe()
1171 "Unable to use ptp-ext irq"); in lan966x_probe()
1175 ports = device_get_named_child_node(&pdev->dev, "ethernet-ports"); in lan966x_probe()
1177 return dev_err_probe(&pdev->dev, -ENODEV, in lan966x_probe()
1178 "no ethernet-ports child found\n"); in lan966x_probe()
1180 lan966x->debugfs_root = debugfs_create_dir("lan966x", NULL); in lan966x_probe()
1182 /* init switch */ 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");