Lines Matching +full:am654 +full:- +full:icssg

1 // SPDX-License-Identifier: GPL-2.0
3 /* Texas Instruments ICSSG Ethernet Driver
5 * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
12 #include <linux/dma-mapping.h>
13 #include <linux/dma/ti-cppi5.h>
19 #include <linux/io-64-nonatomic-hi-lo.h>
37 #include "../k3-cppi-desc-pool.h"
39 #define PRUETH_MODULE_DESCRIPTION "PRUSS ICSSG Ethernet driver"
56 struct prueth *prueth = emac->prueth; in emac_get_tx_ts()
65 memcpy_fromio(rsp, prueth->shram.va + addr, sizeof(*rsp)); in emac_get_tx_ts()
89 !emac->tx_ts_skb[tsr.cookie]) { in tx_ts_work()
90 netdev_err(emac->ndev, "Invalid TX TS cookie 0x%x\n", in tx_ts_work()
95 skb = emac->tx_ts_skb[tsr.cookie]; in tx_ts_work()
96 emac->tx_ts_skb[tsr.cookie] = NULL; /* free slot */ in tx_ts_work()
98 netdev_err(emac->ndev, "Driver Bug! got NULL skb\n"); in tx_ts_work()
102 hi_sw = readl(emac->prueth->shram.va + in tx_ts_work()
113 if (atomic_dec_and_test(&emac->tx_ts_pending)) /* no more? */ in tx_ts_work()
130 .pru = "ti-pruss/am65x-sr2-pru0-pruhsr-fw.elf",
131 .rtu = "ti-pruss/am65x-sr2-rtu0-pruhsr-fw.elf",
132 .txpru = "ti-pruss/am65x-sr2-txpru0-pruhsr-fw.elf",
135 .pru = "ti-pruss/am65x-sr2-pru1-pruhsr-fw.elf",
136 .rtu = "ti-pruss/am65x-sr2-rtu1-pruhsr-fw.elf",
137 .txpru = "ti-pruss/am65x-sr2-txpru1-pruhsr-fw.elf",
143 .pru = "ti-pruss/am65x-sr2-pru0-prusw-fw.elf",
144 .rtu = "ti-pruss/am65x-sr2-rtu0-prusw-fw.elf",
145 .txpru = "ti-pruss/am65x-sr2-txpru0-prusw-fw.elf",
148 .pru = "ti-pruss/am65x-sr2-pru1-prusw-fw.elf",
149 .rtu = "ti-pruss/am65x-sr2-rtu1-prusw-fw.elf",
150 .txpru = "ti-pruss/am65x-sr2-txpru1-prusw-fw.elf",
156 .pru = "ti-pruss/am65x-sr2-pru0-prueth-fw.elf",
157 .rtu = "ti-pruss/am65x-sr2-rtu0-prueth-fw.elf",
158 .txpru = "ti-pruss/am65x-sr2-txpru0-prueth-fw.elf",
161 .pru = "ti-pruss/am65x-sr2-pru1-prueth-fw.elf",
162 .rtu = "ti-pruss/am65x-sr2-rtu1-prueth-fw.elf",
163 .txpru = "ti-pruss/am65x-sr2-txpru1-prueth-fw.elf",
170 struct device *dev = prueth->dev; in prueth_emac_start()
173 if (prueth->is_switch_mode) in prueth_emac_start()
175 else if (prueth->is_hsr_offload_mode) in prueth_emac_start()
182 netdev_err(emac->ndev, "invalid port\n"); in prueth_emac_start()
183 return -EINVAL; in prueth_emac_start()
190 ret = rproc_set_firmware(prueth->pru[slice], firmwares[slice].pru); in prueth_emac_start()
191 ret = rproc_boot(prueth->pru[slice]); in prueth_emac_start()
194 return -EINVAL; in prueth_emac_start()
197 ret = rproc_set_firmware(prueth->rtu[slice], firmwares[slice].rtu); in prueth_emac_start()
198 ret = rproc_boot(prueth->rtu[slice]); in prueth_emac_start()
204 ret = rproc_set_firmware(prueth->txpru[slice], firmwares[slice].txpru); in prueth_emac_start()
205 ret = rproc_boot(prueth->txpru[slice]); in prueth_emac_start()
211 emac->fw_running = 1; in prueth_emac_start()
215 rproc_shutdown(prueth->rtu[slice]); in prueth_emac_start()
218 rproc_shutdown(prueth->pru[slice]); in prueth_emac_start()
227 struct phy_device *phydev = ndev->phydev; in emac_adjust_link()
228 struct prueth *prueth = emac->prueth; in emac_adjust_link()
232 if (phydev->link) { in emac_adjust_link()
233 /* check the mode of operation - full/half duplex */ in emac_adjust_link()
234 if (phydev->duplex != emac->duplex) { in emac_adjust_link()
236 emac->duplex = phydev->duplex; in emac_adjust_link()
238 if (phydev->speed != emac->speed) { in emac_adjust_link()
240 emac->speed = phydev->speed; in emac_adjust_link()
242 if (!emac->link) { in emac_adjust_link()
244 emac->link = 1; in emac_adjust_link()
246 } else if (emac->link) { in emac_adjust_link()
248 emac->link = 0; in emac_adjust_link()
251 emac->speed = SPEED_1000; in emac_adjust_link()
254 emac->duplex = DUPLEX_FULL; in emac_adjust_link()
263 if (emac->link) { in emac_adjust_link()
264 if (emac->duplex == DUPLEX_HALF) in emac_adjust_link()
267 icssg_update_rgmii_cfg(prueth->miig_rt, emac); in emac_adjust_link()
270 spin_lock_irqsave(&emac->lock, flags); in emac_adjust_link()
272 spin_unlock_irqrestore(&emac->lock, flags); in emac_adjust_link()
281 if (emac->link) { in emac_adjust_link()
296 enable_irq(emac->rx_chns.irq[rx_flow]); in emac_rx_timer_callback()
302 struct prueth *prueth = emac->prueth; in emac_phy_connect()
303 struct net_device *ndev = emac->ndev; in emac_phy_connect()
305 ndev->phydev = of_phy_connect(emac->ndev, emac->phy_node, in emac_phy_connect()
307 emac->phy_if); in emac_phy_connect()
308 if (!ndev->phydev) { in emac_phy_connect()
309 dev_err(prueth->dev, "couldn't connect to phy %s\n", in emac_phy_connect()
310 emac->phy_node->full_name); in emac_phy_connect()
311 return -ENODEV; in emac_phy_connect()
314 if (!emac->half_duplex) { in emac_phy_connect()
315 dev_dbg(prueth->dev, "half duplex mode is not supported\n"); in emac_phy_connect()
316 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_10baseT_Half_BIT); in emac_phy_connect()
317 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_100baseT_Half_BIT); in emac_phy_connect()
321 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT); in emac_phy_connect()
322 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_Pause_BIT); in emac_phy_connect()
323 phy_remove_link_mode(ndev->phydev, ETHTOOL_LINK_MODE_Asym_Pause_BIT); in emac_phy_connect()
325 if (emac->phy_if == PHY_INTERFACE_MODE_MII) in emac_phy_connect()
326 phy_set_max_speed(ndev->phydev, SPEED_100); in emac_phy_connect()
335 struct prueth *prueth = emac->prueth; in prueth_iep_gettime()
343 fw_count_hi_addr = prueth->shram.va + TIMESYNC_FW_WC_COUNT_HI_SW_OFFSET_OFFSET; in prueth_iep_gettime()
344 fw_hi_r_count_addr = prueth->shram.va + TIMESYNC_FW_WC_HI_ROLLOVER_COUNT_OFFSET; in prueth_iep_gettime()
348 iepcount_hi = icss_iep_get_count_hi(emac->iep); in prueth_iep_gettime()
352 iepcount_lo = icss_iep_get_count_low(emac->iep); in prueth_iep_gettime()
355 iepcount_hi_r = icss_iep_get_count_hi(emac->iep); in prueth_iep_gettime()
377 if (!emac->fw_running) in prueth_iep_settime()
380 sc_descp = emac->prueth->shram.va + TIMESYNC_FW_WC_SETCLOCK_DESC_OFFSET; in prueth_iep_settime()
386 sc_desc.margin = cycletime - 1000; in prueth_iep_settime()
390 /* Count from 0 to (cycle time) - emac->iep->def_inc */ in prueth_iep_settime()
391 sc_desc.CMP0_current = cycletime - emac->iep->def_inc; in prueth_iep_settime()
395 writeb(1, &sc_descp->request); in prueth_iep_settime()
397 timeout = 5; /* fw should take 2-3 ms */ in prueth_iep_settime()
398 while (timeout--) { in prueth_iep_settime()
399 if (readb(&sc_descp->acknowledgment)) in prueth_iep_settime()
405 dev_err(emac->prueth->dev, "settime timeout\n"); in prueth_iep_settime()
423 ts.tv_sec = req->period.sec; in prueth_perout_enable()
424 ts.tv_nsec = req->period.nsec; in prueth_perout_enable()
429 return -ENXIO; in prueth_perout_enable()
446 if (offset > IEP_DEFAULT_CYCLE_TIME_NS - 8) in prueth_perout_enable()
447 offset = IEP_DEFAULT_CYCLE_TIME_NS - 8; in prueth_perout_enable()
449 /* we're in shadow mode so need to set upper 32-bits */ in prueth_perout_enable()
452 writel(reduction_factor, emac->prueth->shram.va + in prueth_perout_enable()
455 current_cycle = icssg_read_time(emac->prueth->shram.va + in prueth_perout_enable()
461 hi_lo_writeq(start_offset, emac->prueth->shram.va + in prueth_perout_enable()
476 int port_mask = BIT(emac->port_id); in icssg_prueth_add_mcast()
488 int port_mask = BIT(emac->port_id); in icssg_prueth_del_mcast()
507 struct prueth *prueth = emac->prueth; in icssg_prueth_hsr_add_mcast()
509 icssg_fdb_add_del(emac, addr, prueth->default_vlan, in icssg_prueth_hsr_add_mcast()
515 icssg_vtbl_modify(emac, emac->port_vlan, BIT(emac->port_id), in icssg_prueth_hsr_add_mcast()
516 BIT(emac->port_id), true); in icssg_prueth_hsr_add_mcast()
523 struct prueth *prueth = emac->prueth; in icssg_prueth_hsr_del_mcast()
525 icssg_fdb_add_del(emac, addr, prueth->default_vlan, in icssg_prueth_hsr_del_mcast()
535 * emac_ndo_open - EMAC device open
545 int ret, i, num_data_chn = emac->tx_ch_num; in emac_ndo_open()
546 struct prueth *prueth = emac->prueth; in emac_ndo_open()
548 struct device *dev = prueth->dev; in emac_ndo_open()
553 if (!prueth->emacs_initialized) { in emac_ndo_open()
554 memset_io(prueth->msmcram.va, 0, prueth->msmcram.size); in emac_ndo_open()
555 memset_io(prueth->shram.va, 0, ICSSG_CONFIG_OFFSET_SLICE1 * PRUETH_NUM_MACS); in emac_ndo_open()
558 /* set h/w MAC as user might have re-configured */ in emac_ndo_open()
559 ether_addr_copy(emac->mac_addr, ndev->dev_addr); in emac_ndo_open()
561 icssg_class_set_mac_addr(prueth->miig_rt, slice, emac->mac_addr); in emac_ndo_open()
562 icssg_class_default(prueth->miig_rt, slice, 0, false); in emac_ndo_open()
563 icssg_ft1_set_mac_addr(prueth->miig_rt, slice, emac->mac_addr); in emac_ndo_open()
572 init_completion(&emac->cmd_complete); in emac_ndo_open()
580 ret = prueth_init_rx_chns(emac, &emac->rx_chns, "rx", in emac_ndo_open()
593 ret = request_irq(emac->rx_chns.irq[rx_flow], prueth_rx_irq, in emac_ndo_open()
605 icssg_mii_update_mtu(prueth->mii_rt, slice, ndev->max_mtu); in emac_ndo_open()
607 if (!prueth->emacs_initialized) { in emac_ndo_open()
608 ret = icss_iep_init(emac->iep, &prueth_iep_clockops, in emac_ndo_open()
612 ret = request_threaded_irq(emac->tx_ts_irq, NULL, prueth_tx_ts_irq, in emac_ndo_open()
618 ret = prueth_prepare_rx_chan(emac, &emac->rx_chns, PRUETH_MAX_PKT_SIZE); in emac_ndo_open()
622 ret = k3_udma_glue_enable_rx_chn(emac->rx_chns.rx_chn); in emac_ndo_open()
626 for (i = 0; i < emac->tx_ch_num; i++) { in emac_ndo_open()
627 ret = k3_udma_glue_enable_tx_chn(emac->tx_chns[i].tx_chn); in emac_ndo_open()
633 for (i = 0; i < emac->tx_ch_num; i++) in emac_ndo_open()
634 napi_enable(&emac->tx_chns[i].napi_tx); in emac_ndo_open()
635 napi_enable(&emac->napi_rx); in emac_ndo_open()
638 phy_start(ndev->phydev); in emac_ndo_open()
640 prueth->emacs_initialized++; in emac_ndo_open()
642 queue_work(system_long_wq, &emac->stats_work.work); in emac_ndo_open()
652 prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, false); in emac_ndo_open()
654 free_irq(emac->tx_ts_irq, emac); in emac_ndo_open()
658 free_irq(emac->rx_chns.irq[rx_flow], emac); in emac_ndo_open()
660 prueth_ndev_del_tx_napi(emac, emac->tx_ch_num); in emac_ndo_open()
662 prueth_cleanup_rx_chns(emac, &emac->rx_chns, max_rx_flows); in emac_ndo_open()
670 * emac_ndo_stop - EMAC device stop
680 struct prueth *prueth = emac->prueth; in emac_ndo_stop()
689 if (ndev->phydev) in emac_ndo_stop()
690 phy_stop(ndev->phydev); in emac_ndo_stop()
692 icssg_class_disable(prueth->miig_rt, prueth_emac_slice(emac)); in emac_ndo_stop()
694 if (emac->prueth->is_hsr_offload_mode) in emac_ndo_stop()
699 atomic_set(&emac->tdown_cnt, emac->tx_ch_num); in emac_ndo_stop()
703 reinit_completion(&emac->tdown_complete); in emac_ndo_stop()
704 for (i = 0; i < emac->tx_ch_num; i++) in emac_ndo_stop()
705 k3_udma_glue_tdown_tx_chn(emac->tx_chns[i].tx_chn, false); in emac_ndo_stop()
707 ret = wait_for_completion_timeout(&emac->tdown_complete, in emac_ndo_stop()
712 prueth_reset_tx_chan(emac, emac->tx_ch_num, true); in emac_ndo_stop()
713 for (i = 0; i < emac->tx_ch_num; i++) { in emac_ndo_stop()
714 napi_disable(&emac->tx_chns[i].napi_tx); in emac_ndo_stop()
715 hrtimer_cancel(&emac->tx_chns[i].tx_hrtimer); in emac_ndo_stop()
719 k3_udma_glue_tdown_rx_chn(emac->rx_chns.rx_chn, true); in emac_ndo_stop()
721 prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, true); in emac_ndo_stop()
723 napi_disable(&emac->napi_rx); in emac_ndo_stop()
724 hrtimer_cancel(&emac->rx_hrtimer); in emac_ndo_stop()
726 cancel_work_sync(&emac->rx_mode_work); in emac_ndo_stop()
729 cancel_delayed_work_sync(&emac->stats_work); in emac_ndo_stop()
731 if (prueth->emacs_initialized == 1) in emac_ndo_stop()
732 icss_iep_exit(emac->iep); in emac_ndo_stop()
737 free_irq(emac->tx_ts_irq, emac); in emac_ndo_stop()
739 free_irq(emac->rx_chns.irq[rx_flow], emac); in emac_ndo_stop()
740 prueth_ndev_del_tx_napi(emac, emac->tx_ch_num); in emac_ndo_stop()
742 prueth_cleanup_rx_chns(emac, &emac->rx_chns, max_rx_flows); in emac_ndo_stop()
745 prueth->emacs_initialized--; in emac_ndo_stop()
753 struct net_device *ndev = emac->ndev; in emac_ndo_set_rx_mode_work()
759 promisc = ndev->flags & IFF_PROMISC; in emac_ndo_set_rx_mode_work()
760 allmulti = ndev->flags & IFF_ALLMULTI; in emac_ndo_set_rx_mode_work()
775 if (emac->prueth->is_hsr_offload_mode) in emac_ndo_set_rx_mode_work()
784 * emac_ndo_set_rx_mode - EMAC set receive mode function
794 queue_work(emac->cmd_wq, &emac->rx_mode_work); in emac_ndo_set_rx_mode()
804 if (!(ndev->features & (NETIF_F_HW_HSR_DUP | NETIF_F_HW_HSR_TAG_INS))) in emac_ndo_fix_features()
810 if ((ndev->features & NETIF_F_HW_HSR_DUP) || in emac_ndo_fix_features()
811 (ndev->features & NETIF_F_HW_HSR_TAG_INS)) in emac_ndo_fix_features()
846 return -EINVAL; in prueth_netdev_init()
850 return -EINVAL; in prueth_netdev_init()
854 return -ENOMEM; in prueth_netdev_init()
857 emac->prueth = prueth; in prueth_netdev_init()
858 emac->ndev = ndev; in prueth_netdev_init()
859 emac->port_id = port; in prueth_netdev_init()
860 emac->cmd_wq = create_singlethread_workqueue("icssg_cmd_wq"); in prueth_netdev_init()
861 if (!emac->cmd_wq) { in prueth_netdev_init()
862 ret = -ENOMEM; in prueth_netdev_init()
865 INIT_WORK(&emac->rx_mode_work, emac_ndo_set_rx_mode_work); in prueth_netdev_init()
867 INIT_DELAYED_WORK(&emac->stats_work, icssg_stats_work_handler); in prueth_netdev_init()
869 ret = pruss_request_mem_region(prueth->pruss, in prueth_netdev_init()
872 &emac->dram); in prueth_netdev_init()
874 dev_err(prueth->dev, "unable to get DRAM: %d\n", ret); in prueth_netdev_init()
875 ret = -ENOMEM; in prueth_netdev_init()
879 emac->tx_ch_num = 1; in prueth_netdev_init()
882 if (emac->port_id == PRUETH_PORT_MII1) in prueth_netdev_init()
884 emac->tx_ts_irq = platform_get_irq_byname_optional(prueth->pdev, irq_name); in prueth_netdev_init()
885 if (emac->tx_ts_irq < 0) { in prueth_netdev_init()
886 ret = dev_err_probe(prueth->dev, emac->tx_ts_irq, "could not get tx_ts_irq\n"); in prueth_netdev_init()
890 SET_NETDEV_DEV(ndev, prueth->dev); in prueth_netdev_init()
891 spin_lock_init(&emac->lock); in prueth_netdev_init()
892 mutex_init(&emac->cmd_lock); in prueth_netdev_init()
894 emac->phy_node = of_parse_phandle(eth_node, "phy-handle", 0); in prueth_netdev_init()
895 if (!emac->phy_node && !of_phy_is_fixed_link(eth_node)) { in prueth_netdev_init()
896 dev_err(prueth->dev, "couldn't find phy-handle\n"); in prueth_netdev_init()
897 ret = -ENODEV; in prueth_netdev_init()
902 ret = dev_err_probe(prueth->dev, ret, in prueth_netdev_init()
903 "failed to register fixed-link phy\n"); in prueth_netdev_init()
907 emac->phy_node = eth_node; in prueth_netdev_init()
910 ret = of_get_phy_mode(eth_node, &emac->phy_if); in prueth_netdev_init()
912 dev_err(prueth->dev, "could not get phy-mode property\n"); in prueth_netdev_init()
916 if (emac->phy_if != PHY_INTERFACE_MODE_MII && in prueth_netdev_init()
917 !phy_interface_mode_is_rgmii(emac->phy_if)) { in prueth_netdev_init()
918 dev_err(prueth->dev, "PHY mode unsupported %s\n", phy_modes(emac->phy_if)); in prueth_netdev_init()
919 ret = -EINVAL; in prueth_netdev_init()
928 switch (emac->phy_if) { in prueth_netdev_init()
930 emac->phy_if = PHY_INTERFACE_MODE_RGMII_RXID; in prueth_netdev_init()
933 emac->phy_if = PHY_INTERFACE_MODE_RGMII; in prueth_netdev_init()
937 dev_err(prueth->dev, "RGMII mode without TX delay is not supported"); in prueth_netdev_init()
938 ret = -EINVAL; in prueth_netdev_init()
946 if (!is_valid_ether_addr(ndev->dev_addr)) { in prueth_netdev_init()
948 dev_warn(prueth->dev, "port %d: using random MAC addr: %pM\n", in prueth_netdev_init()
949 port, ndev->dev_addr); in prueth_netdev_init()
951 ether_addr_copy(emac->mac_addr, ndev->dev_addr); in prueth_netdev_init()
953 ndev->dev.of_node = eth_node; in prueth_netdev_init()
954 ndev->min_mtu = PRUETH_MIN_PKT_SIZE; in prueth_netdev_init()
955 ndev->max_mtu = PRUETH_MAX_MTU; in prueth_netdev_init()
956 ndev->netdev_ops = &emac_netdev_ops; in prueth_netdev_init()
957 ndev->ethtool_ops = &icssg_ethtool_ops; in prueth_netdev_init()
958 ndev->hw_features = NETIF_F_SG; in prueth_netdev_init()
959 ndev->features = ndev->hw_features; in prueth_netdev_init()
960 ndev->hw_features |= NETIF_PRUETH_HSR_OFFLOAD_FEATURES; in prueth_netdev_init()
962 netif_napi_add(ndev, &emac->napi_rx, icssg_napi_rx_poll); in prueth_netdev_init()
963 hrtimer_init(&emac->rx_hrtimer, CLOCK_MONOTONIC, in prueth_netdev_init()
965 emac->rx_hrtimer.function = &emac_rx_timer_callback; in prueth_netdev_init()
966 prueth->emac[mac] = emac; in prueth_netdev_init()
971 pruss_release_mem_region(prueth->pruss, &emac->dram); in prueth_netdev_init()
973 destroy_workqueue(emac->cmd_wq); in prueth_netdev_init()
975 emac->ndev = NULL; in prueth_netdev_init()
976 prueth->emac[mac] = NULL; in prueth_netdev_init()
984 if (ndev->netdev_ops == &emac_netdev_ops && netif_running(ndev)) { in prueth_dev_check()
987 return emac->prueth->is_switch_mode; in prueth_dev_check()
998 if (prueth->br_members == (BIT(PRUETH_PORT_MII0) | BIT(PRUETH_PORT_MII1))) in prueth_offload_fwd_mark_update()
1001 dev_dbg(prueth->dev, "set offload_fwd_mark %d\n", set_val); in prueth_offload_fwd_mark_update()
1004 struct prueth_emac *emac = prueth->emac[i]; in prueth_offload_fwd_mark_update()
1006 if (!emac || !emac->ndev) in prueth_offload_fwd_mark_update()
1009 emac->offload_fwd_mark = set_val; in prueth_offload_fwd_mark_update()
1015 struct prueth_emac *emac0 = prueth->emac[PRUETH_MAC0]; in prueth_emac_restart()
1016 struct prueth_emac *emac1 = prueth->emac[PRUETH_MAC1]; in prueth_emac_restart()
1019 if (netif_running(emac0->ndev)) in prueth_emac_restart()
1020 netif_device_detach(emac0->ndev); in prueth_emac_restart()
1021 if (netif_running(emac1->ndev)) in prueth_emac_restart()
1022 netif_device_detach(emac1->ndev); in prueth_emac_restart()
1030 prueth->emacs_initialized--; in prueth_emac_restart()
1032 prueth->emacs_initialized--; in prueth_emac_restart()
1036 prueth->emacs_initialized++; in prueth_emac_restart()
1038 prueth->emacs_initialized++; in prueth_emac_restart()
1045 netif_device_attach(emac0->ndev); in prueth_emac_restart()
1046 netif_device_attach(emac1->ndev); in prueth_emac_restart()
1057 emac = prueth->emac[mac]; in icssg_change_mode()
1058 if (prueth->is_hsr_offload_mode) { in icssg_change_mode()
1059 if (emac->ndev->features & NETIF_F_HW_HSR_TAG_RM) in icssg_change_mode()
1065 if (netif_running(emac->ndev)) { in icssg_change_mode()
1066 icssg_fdb_add_del(emac, eth_stp_addr, prueth->default_vlan, in icssg_change_mode()
1072 icssg_vtbl_modify(emac, emac->port_vlan | DEFAULT_VID, in icssg_change_mode()
1073 BIT(emac->port_id) | DEFAULT_PORT_MASK, in icssg_change_mode()
1074 BIT(emac->port_id) | DEFAULT_UNTAG_MASK, in icssg_change_mode()
1076 if (prueth->is_hsr_offload_mode) in icssg_change_mode()
1080 icssg_set_pvid(prueth, emac->port_vlan, emac->port_id); in icssg_change_mode()
1081 if (prueth->is_switch_mode) in icssg_change_mode()
1092 struct prueth *prueth = emac->prueth; in prueth_netdevice_port_link()
1095 if (!prueth->br_members) { in prueth_netdevice_port_link()
1096 prueth->hw_bridge_dev = br_ndev; in prueth_netdevice_port_link()
1101 if (prueth->hw_bridge_dev != br_ndev) in prueth_netdevice_port_link()
1102 return -EOPNOTSUPP; in prueth_netdevice_port_link()
1106 &prueth->prueth_switchdev_nb, in prueth_netdevice_port_link()
1107 &prueth->prueth_switchdev_bl_nb, in prueth_netdevice_port_link()
1112 prueth->br_members |= BIT(emac->port_id); in prueth_netdevice_port_link()
1114 if (!prueth->is_switch_mode) { in prueth_netdevice_port_link()
1115 if (prueth->br_members & BIT(PRUETH_PORT_MII0) && in prueth_netdevice_port_link()
1116 prueth->br_members & BIT(PRUETH_PORT_MII1)) { in prueth_netdevice_port_link()
1117 prueth->is_switch_mode = true; in prueth_netdevice_port_link()
1118 prueth->default_vlan = 1; in prueth_netdevice_port_link()
1119 emac->port_vlan = prueth->default_vlan; in prueth_netdevice_port_link()
1132 struct prueth *prueth = emac->prueth; in prueth_netdevice_port_unlink()
1134 prueth->br_members &= ~BIT(emac->port_id); in prueth_netdevice_port_unlink()
1136 if (prueth->is_switch_mode) { in prueth_netdevice_port_unlink()
1137 prueth->is_switch_mode = false; in prueth_netdevice_port_unlink()
1138 emac->port_vlan = 0; in prueth_netdevice_port_unlink()
1144 if (!prueth->br_members) in prueth_netdevice_port_unlink()
1145 prueth->hw_bridge_dev = NULL; in prueth_netdevice_port_unlink()
1151 struct prueth *prueth = emac->prueth; in prueth_hsr_port_link()
1155 emac0 = prueth->emac[PRUETH_MAC0]; in prueth_hsr_port_link()
1156 emac1 = prueth->emac[PRUETH_MAC1]; in prueth_hsr_port_link()
1158 if (prueth->is_switch_mode) in prueth_hsr_port_link()
1159 return -EOPNOTSUPP; in prueth_hsr_port_link()
1161 prueth->hsr_members |= BIT(emac->port_id); in prueth_hsr_port_link()
1162 if (!prueth->is_hsr_offload_mode) { in prueth_hsr_port_link()
1163 if (prueth->hsr_members & BIT(PRUETH_PORT_MII0) && in prueth_hsr_port_link()
1164 prueth->hsr_members & BIT(PRUETH_PORT_MII1)) { in prueth_hsr_port_link()
1165 if (!(emac0->ndev->features & in prueth_hsr_port_link()
1167 !(emac1->ndev->features & in prueth_hsr_port_link()
1169 return -EOPNOTSUPP; in prueth_hsr_port_link()
1170 prueth->is_hsr_offload_mode = true; in prueth_hsr_port_link()
1171 prueth->default_vlan = 1; in prueth_hsr_port_link()
1172 emac0->port_vlan = prueth->default_vlan; in prueth_hsr_port_link()
1173 emac1->port_vlan = prueth->default_vlan; in prueth_hsr_port_link()
1185 struct prueth *prueth = emac->prueth; in prueth_hsr_port_unlink()
1189 emac0 = prueth->emac[PRUETH_MAC0]; in prueth_hsr_port_unlink()
1190 emac1 = prueth->emac[PRUETH_MAC1]; in prueth_hsr_port_unlink()
1192 prueth->hsr_members &= ~BIT(emac->port_id); in prueth_hsr_port_unlink()
1193 if (prueth->is_hsr_offload_mode) { in prueth_hsr_port_unlink()
1194 prueth->is_hsr_offload_mode = false; in prueth_hsr_port_unlink()
1195 emac0->port_vlan = 0; in prueth_hsr_port_unlink()
1196 emac1->port_vlan = 0; in prueth_hsr_port_unlink()
1197 prueth->hsr_dev = NULL; in prueth_hsr_port_unlink()
1211 struct prueth *prueth = emac->prueth; in prueth_netdevice_event()
1214 if (ndev->netdev_ops != &emac_netdev_ops) in prueth_netdevice_event()
1221 if ((ndev->features & NETIF_PRUETH_HSR_OFFLOAD_FEATURES) && in prueth_netdevice_event()
1222 is_hsr_master(info->upper_dev)) { in prueth_netdevice_event()
1223 if (info->linking) { in prueth_netdevice_event()
1224 if (!prueth->hsr_dev) { in prueth_netdevice_event()
1225 prueth->hsr_dev = info->upper_dev; in prueth_netdevice_event()
1226 icssg_class_set_host_mac_addr(prueth->miig_rt, in prueth_netdevice_event()
1227 prueth->hsr_dev->dev_addr); in prueth_netdevice_event()
1229 if (prueth->hsr_dev != info->upper_dev) { in prueth_netdevice_event()
1231 return -EOPNOTSUPP; in prueth_netdevice_event()
1240 if (netif_is_bridge_master(info->upper_dev)) { in prueth_netdevice_event()
1241 if (info->linking) in prueth_netdevice_event()
1242 ret = prueth_netdevice_port_link(ndev, info->upper_dev, extack); in prueth_netdevice_event()
1258 prueth->prueth_netdevice_nb.notifier_call = &prueth_netdevice_event; in prueth_register_notifiers()
1259 ret = register_netdevice_notifier(&prueth->prueth_netdevice_nb); in prueth_register_notifiers()
1261 dev_err(prueth->dev, "can't register netdevice notifier\n"); in prueth_register_notifiers()
1267 unregister_netdevice_notifier(&prueth->prueth_netdevice_nb); in prueth_register_notifiers()
1275 unregister_netdevice_notifier(&prueth->prueth_netdevice_nb); in prueth_unregister_notifiers()
1286 struct device *dev = &pdev->dev; in prueth_probe()
1293 np = dev->of_node; in prueth_probe()
1297 return -ENOMEM; in prueth_probe()
1300 prueth->pdev = pdev; in prueth_probe()
1301 prueth->pdata = *(const struct prueth_pdata *)device_get_match_data(dev); in prueth_probe()
1303 prueth->dev = dev; in prueth_probe()
1304 eth_ports_node = of_get_child_by_name(np, "ethernet-ports"); in prueth_probe()
1306 return -ENOENT; in prueth_probe()
1311 if (strcmp(eth_node->name, "port")) in prueth_probe()
1343 return -ENODEV; in prueth_probe()
1349 return -ENODEV; in prueth_probe()
1352 prueth->eth_node[PRUETH_MAC0] = eth0_node; in prueth_probe()
1353 prueth->eth_node[PRUETH_MAC1] = eth1_node; in prueth_probe()
1355 prueth->miig_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-g-rt"); in prueth_probe()
1356 if (IS_ERR(prueth->miig_rt)) { in prueth_probe()
1357 dev_err(dev, "couldn't get ti,mii-g-rt syscon regmap\n"); in prueth_probe()
1358 return -ENODEV; in prueth_probe()
1361 prueth->mii_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-rt"); in prueth_probe()
1362 if (IS_ERR(prueth->mii_rt)) { in prueth_probe()
1363 dev_err(dev, "couldn't get ti,mii-rt syscon regmap\n"); in prueth_probe()
1364 return -ENODEV; in prueth_probe()
1367 prueth->pa_stats = syscon_regmap_lookup_by_phandle(np, "ti,pa-stats"); in prueth_probe()
1368 if (IS_ERR(prueth->pa_stats)) { in prueth_probe()
1369 dev_err(dev, "couldn't get ti,pa-stats syscon regmap\n"); in prueth_probe()
1370 prueth->pa_stats = NULL; in prueth_probe()
1386 prueth->pru[ICSS_SLICE0] : prueth->pru[ICSS_SLICE1]); in prueth_probe()
1393 prueth->pruss = pruss; in prueth_probe()
1396 &prueth->shram); in prueth_probe()
1402 prueth->sram_pool = of_gen_pool_get(np, "sram", 0); in prueth_probe()
1403 if (!prueth->sram_pool) { in prueth_probe()
1405 ret = -ENODEV; in prueth_probe()
1411 prueth->is_switchmode_supported = prueth->pdata.switch_mode; in prueth_probe()
1412 if (prueth->is_switchmode_supported) in prueth_probe()
1416 prueth->msmcram.va = in prueth_probe()
1417 (void __iomem *)gen_pool_alloc_algo(prueth->sram_pool, in prueth_probe()
1422 if (!prueth->msmcram.va) { in prueth_probe()
1423 ret = -ENOMEM; in prueth_probe()
1427 prueth->msmcram.pa = gen_pool_virt_to_phys(prueth->sram_pool, in prueth_probe()
1428 (unsigned long)prueth->msmcram.va); in prueth_probe()
1429 prueth->msmcram.size = msmc_ram_size; in prueth_probe()
1430 memset_io(prueth->msmcram.va, 0, msmc_ram_size); in prueth_probe()
1431 dev_dbg(dev, "sram: pa %llx va %p size %zx\n", prueth->msmcram.pa, in prueth_probe()
1432 prueth->msmcram.va, prueth->msmcram.size); in prueth_probe()
1434 prueth->iep0 = icss_iep_get_idx(np, 0); in prueth_probe()
1435 if (IS_ERR(prueth->iep0)) { in prueth_probe()
1436 ret = dev_err_probe(dev, PTR_ERR(prueth->iep0), "iep0 get failed\n"); in prueth_probe()
1437 prueth->iep0 = NULL; in prueth_probe()
1441 prueth->iep1 = icss_iep_get_idx(np, 1); in prueth_probe()
1442 if (IS_ERR(prueth->iep1)) { in prueth_probe()
1443 ret = dev_err_probe(dev, PTR_ERR(prueth->iep1), "iep1 get failed\n"); in prueth_probe()
1447 if (prueth->pdata.quirk_10m_link_issue) { in prueth_probe()
1451 icss_iep_init_fw(prueth->iep1); in prueth_probe()
1454 spin_lock_init(&prueth->vtbl_lock); in prueth_probe()
1460 eth0_node->name); in prueth_probe()
1464 prueth->emac[PRUETH_MAC0]->half_duplex = in prueth_probe()
1465 of_property_read_bool(eth0_node, "ti,half-duplex-capable"); in prueth_probe()
1467 prueth->emac[PRUETH_MAC0]->iep = prueth->iep0; in prueth_probe()
1474 eth1_node->name); in prueth_probe()
1478 prueth->emac[PRUETH_MAC1]->half_duplex = in prueth_probe()
1479 of_property_read_bool(eth1_node, "ti,half-duplex-capable"); in prueth_probe()
1481 prueth->emac[PRUETH_MAC1]->iep = prueth->iep0; in prueth_probe()
1486 ret = register_netdev(prueth->emac[PRUETH_MAC0]->ndev); in prueth_probe()
1492 prueth->registered_netdevs[PRUETH_MAC0] = prueth->emac[PRUETH_MAC0]->ndev; in prueth_probe()
1494 ret = emac_phy_connect(prueth->emac[PRUETH_MAC0]); in prueth_probe()
1497 "can't connect to MII0 PHY, error -%d", ret); in prueth_probe()
1500 phy_attached_info(prueth->emac[PRUETH_MAC0]->ndev->phydev); in prueth_probe()
1504 ret = register_netdev(prueth->emac[PRUETH_MAC1]->ndev); in prueth_probe()
1510 prueth->registered_netdevs[PRUETH_MAC1] = prueth->emac[PRUETH_MAC1]->ndev; in prueth_probe()
1511 ret = emac_phy_connect(prueth->emac[PRUETH_MAC1]); in prueth_probe()
1517 phy_attached_info(prueth->emac[PRUETH_MAC1]->ndev->phydev); in prueth_probe()
1520 if (prueth->is_switchmode_supported) { in prueth_probe()
1525 sprintf(prueth->switch_id, "%s", dev_name(dev)); in prueth_probe()
1539 if (!prueth->registered_netdevs[i]) in prueth_probe()
1541 if (prueth->emac[i]->ndev->phydev) { in prueth_probe()
1542 phy_disconnect(prueth->emac[i]->ndev->phydev); in prueth_probe()
1543 prueth->emac[i]->ndev->phydev = NULL; in prueth_probe()
1545 unregister_netdev(prueth->registered_netdevs[i]); in prueth_probe()
1550 eth_node = prueth->eth_node[i]; in prueth_probe()
1558 if (prueth->pdata.quirk_10m_link_issue) in prueth_probe()
1559 icss_iep_exit_fw(prueth->iep1); in prueth_probe()
1560 icss_iep_put(prueth->iep1); in prueth_probe()
1563 icss_iep_put(prueth->iep0); in prueth_probe()
1564 prueth->iep0 = NULL; in prueth_probe()
1565 prueth->iep1 = NULL; in prueth_probe()
1568 gen_pool_free(prueth->sram_pool, in prueth_probe()
1569 (unsigned long)prueth->msmcram.va, msmc_ram_size); in prueth_probe()
1572 pruss_release_mem_region(prueth->pruss, &prueth->shram); in prueth_probe()
1575 pruss_put(prueth->pruss); in prueth_probe()
1600 if (!prueth->registered_netdevs[i]) in prueth_remove()
1602 phy_stop(prueth->emac[i]->ndev->phydev); in prueth_remove()
1603 phy_disconnect(prueth->emac[i]->ndev->phydev); in prueth_remove()
1604 prueth->emac[i]->ndev->phydev = NULL; in prueth_remove()
1605 unregister_netdev(prueth->registered_netdevs[i]); in prueth_remove()
1609 eth_node = prueth->eth_node[i]; in prueth_remove()
1616 if (prueth->pdata.quirk_10m_link_issue) in prueth_remove()
1617 icss_iep_exit_fw(prueth->iep1); in prueth_remove()
1619 icss_iep_put(prueth->iep1); in prueth_remove()
1620 icss_iep_put(prueth->iep0); in prueth_remove()
1622 gen_pool_free(prueth->sram_pool, in prueth_remove()
1623 (unsigned long)prueth->msmcram.va, in prueth_remove()
1626 pruss_release_mem_region(prueth->pruss, &prueth->shram); in prueth_remove()
1628 pruss_put(prueth->pruss); in prueth_remove()
1630 if (prueth->eth_node[PRUETH_MAC1]) in prueth_remove()
1633 if (prueth->eth_node[PRUETH_MAC0]) in prueth_remove()
1650 { .compatible = "ti,am654-icssg-prueth", .data = &am654_icssg_pdata },
1651 { .compatible = "ti,am642-icssg-prueth", .data = &am64x_icssg_pdata },
1660 .name = "icssg-prueth",
1669 MODULE_DESCRIPTION("PRUSS ICSSG Ethernet Driver");