Lines Matching +full:am654 +full:- +full:pru

1 // SPDX-License-Identifier: GPL-2.0
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"
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()
193 dev_err(dev, "failed to boot PRU%d: %d\n", slice, ret); 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()
600 /* reset and start PRU firmware */ 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()
824 struct prueth *prueth = emac->prueth; in emac_ndo_vlan_rx_add_vid()
828 if (prueth->is_hsr_offload_mode) { in emac_ndo_vlan_rx_add_vid()
829 port_mask = BIT(PRUETH_PORT_HOST) | BIT(emac->port_id); in emac_ndo_vlan_rx_add_vid()
832 netdev_dbg(emac->ndev, "VID add vid:%u port_mask:%X untag_mask %X\n", in emac_ndo_vlan_rx_add_vid()
836 icssg_set_pvid(emac->prueth, vid, emac->port_id); in emac_ndo_vlan_rx_add_vid()
845 struct prueth *prueth = emac->prueth; in emac_ndo_vlan_rx_del_vid()
849 if (prueth->is_hsr_offload_mode) { in emac_ndo_vlan_rx_del_vid()
853 netdev_dbg(emac->ndev, "VID del vid:%u port_mask:%X untag_mask %X\n", in emac_ndo_vlan_rx_del_vid()
889 return -EINVAL; in prueth_netdev_init()
893 return -EINVAL; in prueth_netdev_init()
897 return -ENOMEM; in prueth_netdev_init()
900 emac->prueth = prueth; in prueth_netdev_init()
901 emac->ndev = ndev; in prueth_netdev_init()
902 emac->port_id = port; in prueth_netdev_init()
903 emac->cmd_wq = create_singlethread_workqueue("icssg_cmd_wq"); in prueth_netdev_init()
904 if (!emac->cmd_wq) { in prueth_netdev_init()
905 ret = -ENOMEM; in prueth_netdev_init()
908 INIT_WORK(&emac->rx_mode_work, emac_ndo_set_rx_mode_work); in prueth_netdev_init()
910 INIT_DELAYED_WORK(&emac->stats_work, icssg_stats_work_handler); in prueth_netdev_init()
912 ret = pruss_request_mem_region(prueth->pruss, in prueth_netdev_init()
915 &emac->dram); in prueth_netdev_init()
917 dev_err(prueth->dev, "unable to get DRAM: %d\n", ret); in prueth_netdev_init()
918 ret = -ENOMEM; in prueth_netdev_init()
922 emac->tx_ch_num = 1; in prueth_netdev_init()
925 if (emac->port_id == PRUETH_PORT_MII1) in prueth_netdev_init()
927 emac->tx_ts_irq = platform_get_irq_byname_optional(prueth->pdev, irq_name); in prueth_netdev_init()
928 if (emac->tx_ts_irq < 0) { in prueth_netdev_init()
929 ret = dev_err_probe(prueth->dev, emac->tx_ts_irq, "could not get tx_ts_irq\n"); in prueth_netdev_init()
933 SET_NETDEV_DEV(ndev, prueth->dev); in prueth_netdev_init()
934 spin_lock_init(&emac->lock); in prueth_netdev_init()
935 mutex_init(&emac->cmd_lock); in prueth_netdev_init()
937 emac->phy_node = of_parse_phandle(eth_node, "phy-handle", 0); in prueth_netdev_init()
938 if (!emac->phy_node && !of_phy_is_fixed_link(eth_node)) { in prueth_netdev_init()
939 dev_err(prueth->dev, "couldn't find phy-handle\n"); in prueth_netdev_init()
940 ret = -ENODEV; in prueth_netdev_init()
945 ret = dev_err_probe(prueth->dev, ret, in prueth_netdev_init()
946 "failed to register fixed-link phy\n"); in prueth_netdev_init()
950 emac->phy_node = eth_node; in prueth_netdev_init()
953 ret = of_get_phy_mode(eth_node, &emac->phy_if); in prueth_netdev_init()
955 dev_err(prueth->dev, "could not get phy-mode property\n"); in prueth_netdev_init()
959 if (emac->phy_if != PHY_INTERFACE_MODE_MII && in prueth_netdev_init()
960 !phy_interface_mode_is_rgmii(emac->phy_if)) { in prueth_netdev_init()
961 dev_err(prueth->dev, "PHY mode unsupported %s\n", phy_modes(emac->phy_if)); in prueth_netdev_init()
962 ret = -EINVAL; in prueth_netdev_init()
971 switch (emac->phy_if) { in prueth_netdev_init()
973 emac->phy_if = PHY_INTERFACE_MODE_RGMII_RXID; in prueth_netdev_init()
976 emac->phy_if = PHY_INTERFACE_MODE_RGMII; in prueth_netdev_init()
980 dev_err(prueth->dev, "RGMII mode without TX delay is not supported"); in prueth_netdev_init()
981 ret = -EINVAL; in prueth_netdev_init()
989 if (!is_valid_ether_addr(ndev->dev_addr)) { in prueth_netdev_init()
991 dev_warn(prueth->dev, "port %d: using random MAC addr: %pM\n", in prueth_netdev_init()
992 port, ndev->dev_addr); in prueth_netdev_init()
994 ether_addr_copy(emac->mac_addr, ndev->dev_addr); in prueth_netdev_init()
996 ndev->dev.of_node = eth_node; in prueth_netdev_init()
997 ndev->min_mtu = PRUETH_MIN_PKT_SIZE; in prueth_netdev_init()
998 ndev->max_mtu = PRUETH_MAX_MTU; in prueth_netdev_init()
999 ndev->netdev_ops = &emac_netdev_ops; in prueth_netdev_init()
1000 ndev->ethtool_ops = &icssg_ethtool_ops; in prueth_netdev_init()
1001 ndev->hw_features = NETIF_F_SG; in prueth_netdev_init()
1002 ndev->features = ndev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; in prueth_netdev_init()
1003 ndev->hw_features |= NETIF_PRUETH_HSR_OFFLOAD_FEATURES; in prueth_netdev_init()
1005 netif_napi_add(ndev, &emac->napi_rx, icssg_napi_rx_poll); in prueth_netdev_init()
1006 hrtimer_init(&emac->rx_hrtimer, CLOCK_MONOTONIC, in prueth_netdev_init()
1008 emac->rx_hrtimer.function = &emac_rx_timer_callback; in prueth_netdev_init()
1009 prueth->emac[mac] = emac; in prueth_netdev_init()
1014 pruss_release_mem_region(prueth->pruss, &emac->dram); in prueth_netdev_init()
1016 destroy_workqueue(emac->cmd_wq); in prueth_netdev_init()
1018 emac->ndev = NULL; in prueth_netdev_init()
1019 prueth->emac[mac] = NULL; in prueth_netdev_init()
1027 if (ndev->netdev_ops == &emac_netdev_ops && netif_running(ndev)) { in prueth_dev_check()
1030 return emac->prueth->is_switch_mode; in prueth_dev_check()
1041 if (prueth->br_members == (BIT(PRUETH_PORT_MII0) | BIT(PRUETH_PORT_MII1))) in prueth_offload_fwd_mark_update()
1044 dev_dbg(prueth->dev, "set offload_fwd_mark %d\n", set_val); in prueth_offload_fwd_mark_update()
1047 struct prueth_emac *emac = prueth->emac[i]; in prueth_offload_fwd_mark_update()
1049 if (!emac || !emac->ndev) in prueth_offload_fwd_mark_update()
1052 emac->offload_fwd_mark = set_val; in prueth_offload_fwd_mark_update()
1058 struct prueth_emac *emac0 = prueth->emac[PRUETH_MAC0]; in prueth_emac_restart()
1059 struct prueth_emac *emac1 = prueth->emac[PRUETH_MAC1]; in prueth_emac_restart()
1062 if (netif_running(emac0->ndev)) in prueth_emac_restart()
1063 netif_device_detach(emac0->ndev); in prueth_emac_restart()
1064 if (netif_running(emac1->ndev)) in prueth_emac_restart()
1065 netif_device_detach(emac1->ndev); in prueth_emac_restart()
1071 /* Stop both pru cores for both PRUeth ports*/ in prueth_emac_restart()
1073 prueth->emacs_initialized--; in prueth_emac_restart()
1075 prueth->emacs_initialized--; in prueth_emac_restart()
1077 /* Start both pru cores for both PRUeth ports */ in prueth_emac_restart()
1079 prueth->emacs_initialized++; in prueth_emac_restart()
1081 prueth->emacs_initialized++; in prueth_emac_restart()
1088 netif_device_attach(emac0->ndev); in prueth_emac_restart()
1089 netif_device_attach(emac1->ndev); in prueth_emac_restart()
1100 emac = prueth->emac[mac]; in icssg_change_mode()
1101 if (prueth->is_hsr_offload_mode) { in icssg_change_mode()
1102 if (emac->ndev->features & NETIF_F_HW_HSR_TAG_RM) in icssg_change_mode()
1108 if (netif_running(emac->ndev)) { in icssg_change_mode()
1109 icssg_fdb_add_del(emac, eth_stp_addr, prueth->default_vlan, in icssg_change_mode()
1115 icssg_vtbl_modify(emac, emac->port_vlan | DEFAULT_VID, in icssg_change_mode()
1116 BIT(emac->port_id) | DEFAULT_PORT_MASK, in icssg_change_mode()
1117 BIT(emac->port_id) | DEFAULT_UNTAG_MASK, in icssg_change_mode()
1119 if (prueth->is_hsr_offload_mode) in icssg_change_mode()
1123 icssg_set_pvid(prueth, emac->port_vlan, emac->port_id); in icssg_change_mode()
1124 if (prueth->is_switch_mode) in icssg_change_mode()
1135 struct prueth *prueth = emac->prueth; in prueth_netdevice_port_link()
1138 if (!prueth->br_members) { in prueth_netdevice_port_link()
1139 prueth->hw_bridge_dev = br_ndev; in prueth_netdevice_port_link()
1144 if (prueth->hw_bridge_dev != br_ndev) in prueth_netdevice_port_link()
1145 return -EOPNOTSUPP; in prueth_netdevice_port_link()
1149 &prueth->prueth_switchdev_nb, in prueth_netdevice_port_link()
1150 &prueth->prueth_switchdev_bl_nb, in prueth_netdevice_port_link()
1155 prueth->br_members |= BIT(emac->port_id); in prueth_netdevice_port_link()
1157 if (!prueth->is_switch_mode) { in prueth_netdevice_port_link()
1158 if (prueth->br_members & BIT(PRUETH_PORT_MII0) && in prueth_netdevice_port_link()
1159 prueth->br_members & BIT(PRUETH_PORT_MII1)) { in prueth_netdevice_port_link()
1160 prueth->is_switch_mode = true; in prueth_netdevice_port_link()
1161 prueth->default_vlan = 1; in prueth_netdevice_port_link()
1162 emac->port_vlan = prueth->default_vlan; in prueth_netdevice_port_link()
1175 struct prueth *prueth = emac->prueth; in prueth_netdevice_port_unlink()
1177 prueth->br_members &= ~BIT(emac->port_id); in prueth_netdevice_port_unlink()
1179 if (prueth->is_switch_mode) { in prueth_netdevice_port_unlink()
1180 prueth->is_switch_mode = false; in prueth_netdevice_port_unlink()
1181 emac->port_vlan = 0; in prueth_netdevice_port_unlink()
1187 if (!prueth->br_members) in prueth_netdevice_port_unlink()
1188 prueth->hw_bridge_dev = NULL; in prueth_netdevice_port_unlink()
1194 struct prueth *prueth = emac->prueth; in prueth_hsr_port_link()
1198 emac0 = prueth->emac[PRUETH_MAC0]; in prueth_hsr_port_link()
1199 emac1 = prueth->emac[PRUETH_MAC1]; in prueth_hsr_port_link()
1201 if (prueth->is_switch_mode) in prueth_hsr_port_link()
1202 return -EOPNOTSUPP; in prueth_hsr_port_link()
1204 prueth->hsr_members |= BIT(emac->port_id); in prueth_hsr_port_link()
1205 if (!prueth->is_hsr_offload_mode) { in prueth_hsr_port_link()
1206 if (prueth->hsr_members & BIT(PRUETH_PORT_MII0) && in prueth_hsr_port_link()
1207 prueth->hsr_members & BIT(PRUETH_PORT_MII1)) { in prueth_hsr_port_link()
1208 if (!(emac0->ndev->features & in prueth_hsr_port_link()
1210 !(emac1->ndev->features & in prueth_hsr_port_link()
1212 return -EOPNOTSUPP; in prueth_hsr_port_link()
1213 prueth->is_hsr_offload_mode = true; in prueth_hsr_port_link()
1214 prueth->default_vlan = 1; in prueth_hsr_port_link()
1215 emac0->port_vlan = prueth->default_vlan; in prueth_hsr_port_link()
1216 emac1->port_vlan = prueth->default_vlan; in prueth_hsr_port_link()
1228 struct prueth *prueth = emac->prueth; in prueth_hsr_port_unlink()
1232 emac0 = prueth->emac[PRUETH_MAC0]; in prueth_hsr_port_unlink()
1233 emac1 = prueth->emac[PRUETH_MAC1]; in prueth_hsr_port_unlink()
1235 prueth->hsr_members &= ~BIT(emac->port_id); in prueth_hsr_port_unlink()
1236 if (prueth->is_hsr_offload_mode) { in prueth_hsr_port_unlink()
1237 prueth->is_hsr_offload_mode = false; in prueth_hsr_port_unlink()
1238 emac0->port_vlan = 0; in prueth_hsr_port_unlink()
1239 emac1->port_vlan = 0; in prueth_hsr_port_unlink()
1240 prueth->hsr_dev = NULL; in prueth_hsr_port_unlink()
1254 struct prueth *prueth = emac->prueth; in prueth_netdevice_event()
1257 if (ndev->netdev_ops != &emac_netdev_ops) in prueth_netdevice_event()
1264 if ((ndev->features & NETIF_PRUETH_HSR_OFFLOAD_FEATURES) && in prueth_netdevice_event()
1265 is_hsr_master(info->upper_dev)) { in prueth_netdevice_event()
1266 if (info->linking) { in prueth_netdevice_event()
1267 if (!prueth->hsr_dev) { in prueth_netdevice_event()
1268 prueth->hsr_dev = info->upper_dev; in prueth_netdevice_event()
1269 icssg_class_set_host_mac_addr(prueth->miig_rt, in prueth_netdevice_event()
1270 prueth->hsr_dev->dev_addr); in prueth_netdevice_event()
1272 if (prueth->hsr_dev != info->upper_dev) { in prueth_netdevice_event()
1274 return -EOPNOTSUPP; in prueth_netdevice_event()
1283 if (netif_is_bridge_master(info->upper_dev)) { in prueth_netdevice_event()
1284 if (info->linking) in prueth_netdevice_event()
1285 ret = prueth_netdevice_port_link(ndev, info->upper_dev, extack); in prueth_netdevice_event()
1301 prueth->prueth_netdevice_nb.notifier_call = &prueth_netdevice_event; in prueth_register_notifiers()
1302 ret = register_netdevice_notifier(&prueth->prueth_netdevice_nb); in prueth_register_notifiers()
1304 dev_err(prueth->dev, "can't register netdevice notifier\n"); in prueth_register_notifiers()
1310 unregister_netdevice_notifier(&prueth->prueth_netdevice_nb); in prueth_register_notifiers()
1318 unregister_netdevice_notifier(&prueth->prueth_netdevice_nb); in prueth_unregister_notifiers()
1329 struct device *dev = &pdev->dev; in prueth_probe()
1336 np = dev->of_node; in prueth_probe()
1340 return -ENOMEM; in prueth_probe()
1343 prueth->pdev = pdev; in prueth_probe()
1344 prueth->pdata = *(const struct prueth_pdata *)device_get_match_data(dev); in prueth_probe()
1346 prueth->dev = dev; in prueth_probe()
1347 eth_ports_node = of_get_child_by_name(np, "ethernet-ports"); in prueth_probe()
1349 return -ENOENT; in prueth_probe()
1354 if (strcmp(eth_node->name, "port")) in prueth_probe()
1386 return -ENODEV; in prueth_probe()
1392 return -ENODEV; in prueth_probe()
1395 prueth->eth_node[PRUETH_MAC0] = eth0_node; in prueth_probe()
1396 prueth->eth_node[PRUETH_MAC1] = eth1_node; in prueth_probe()
1398 prueth->miig_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-g-rt"); in prueth_probe()
1399 if (IS_ERR(prueth->miig_rt)) { in prueth_probe()
1400 dev_err(dev, "couldn't get ti,mii-g-rt syscon regmap\n"); in prueth_probe()
1401 return -ENODEV; in prueth_probe()
1404 prueth->mii_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-rt"); in prueth_probe()
1405 if (IS_ERR(prueth->mii_rt)) { in prueth_probe()
1406 dev_err(dev, "couldn't get ti,mii-rt syscon regmap\n"); in prueth_probe()
1407 return -ENODEV; in prueth_probe()
1410 prueth->pa_stats = syscon_regmap_lookup_by_phandle(np, "ti,pa-stats"); in prueth_probe()
1411 if (IS_ERR(prueth->pa_stats)) { in prueth_probe()
1412 dev_err(dev, "couldn't get ti,pa-stats syscon regmap\n"); in prueth_probe()
1413 prueth->pa_stats = NULL; in prueth_probe()
1429 prueth->pru[ICSS_SLICE0] : prueth->pru[ICSS_SLICE1]); in prueth_probe()
1436 prueth->pruss = pruss; in prueth_probe()
1439 &prueth->shram); in prueth_probe()
1445 prueth->sram_pool = of_gen_pool_get(np, "sram", 0); in prueth_probe()
1446 if (!prueth->sram_pool) { in prueth_probe()
1448 ret = -ENODEV; in prueth_probe()
1454 prueth->is_switchmode_supported = prueth->pdata.switch_mode; in prueth_probe()
1455 if (prueth->is_switchmode_supported) in prueth_probe()
1459 prueth->msmcram.va = in prueth_probe()
1460 (void __iomem *)gen_pool_alloc_algo(prueth->sram_pool, in prueth_probe()
1465 if (!prueth->msmcram.va) { in prueth_probe()
1466 ret = -ENOMEM; in prueth_probe()
1470 prueth->msmcram.pa = gen_pool_virt_to_phys(prueth->sram_pool, in prueth_probe()
1471 (unsigned long)prueth->msmcram.va); in prueth_probe()
1472 prueth->msmcram.size = msmc_ram_size; in prueth_probe()
1473 memset_io(prueth->msmcram.va, 0, msmc_ram_size); in prueth_probe()
1474 dev_dbg(dev, "sram: pa %llx va %p size %zx\n", prueth->msmcram.pa, in prueth_probe()
1475 prueth->msmcram.va, prueth->msmcram.size); in prueth_probe()
1477 prueth->iep0 = icss_iep_get_idx(np, 0); in prueth_probe()
1478 if (IS_ERR(prueth->iep0)) { in prueth_probe()
1479 ret = dev_err_probe(dev, PTR_ERR(prueth->iep0), "iep0 get failed\n"); in prueth_probe()
1480 prueth->iep0 = NULL; in prueth_probe()
1484 prueth->iep1 = icss_iep_get_idx(np, 1); in prueth_probe()
1485 if (IS_ERR(prueth->iep1)) { in prueth_probe()
1486 ret = dev_err_probe(dev, PTR_ERR(prueth->iep1), "iep1 get failed\n"); in prueth_probe()
1490 if (prueth->pdata.quirk_10m_link_issue) { in prueth_probe()
1494 icss_iep_init_fw(prueth->iep1); in prueth_probe()
1497 spin_lock_init(&prueth->vtbl_lock); in prueth_probe()
1503 eth0_node->name); in prueth_probe()
1507 prueth->emac[PRUETH_MAC0]->half_duplex = in prueth_probe()
1508 of_property_read_bool(eth0_node, "ti,half-duplex-capable"); in prueth_probe()
1510 prueth->emac[PRUETH_MAC0]->iep = prueth->iep0; in prueth_probe()
1517 eth1_node->name); in prueth_probe()
1521 prueth->emac[PRUETH_MAC1]->half_duplex = in prueth_probe()
1522 of_property_read_bool(eth1_node, "ti,half-duplex-capable"); in prueth_probe()
1524 prueth->emac[PRUETH_MAC1]->iep = prueth->iep0; in prueth_probe()
1529 ret = register_netdev(prueth->emac[PRUETH_MAC0]->ndev); in prueth_probe()
1535 prueth->registered_netdevs[PRUETH_MAC0] = prueth->emac[PRUETH_MAC0]->ndev; in prueth_probe()
1537 ret = emac_phy_connect(prueth->emac[PRUETH_MAC0]); in prueth_probe()
1540 "can't connect to MII0 PHY, error -%d", ret); in prueth_probe()
1543 phy_attached_info(prueth->emac[PRUETH_MAC0]->ndev->phydev); in prueth_probe()
1547 ret = register_netdev(prueth->emac[PRUETH_MAC1]->ndev); in prueth_probe()
1553 prueth->registered_netdevs[PRUETH_MAC1] = prueth->emac[PRUETH_MAC1]->ndev; in prueth_probe()
1554 ret = emac_phy_connect(prueth->emac[PRUETH_MAC1]); in prueth_probe()
1560 phy_attached_info(prueth->emac[PRUETH_MAC1]->ndev->phydev); in prueth_probe()
1563 if (prueth->is_switchmode_supported) { in prueth_probe()
1568 sprintf(prueth->switch_id, "%s", dev_name(dev)); in prueth_probe()
1571 dev_info(dev, "TI PRU ethernet driver initialized: %s EMAC mode\n", in prueth_probe()
1582 if (!prueth->registered_netdevs[i]) in prueth_probe()
1584 if (prueth->emac[i]->ndev->phydev) { in prueth_probe()
1585 phy_disconnect(prueth->emac[i]->ndev->phydev); in prueth_probe()
1586 prueth->emac[i]->ndev->phydev = NULL; in prueth_probe()
1588 unregister_netdev(prueth->registered_netdevs[i]); in prueth_probe()
1593 eth_node = prueth->eth_node[i]; in prueth_probe()
1601 if (prueth->pdata.quirk_10m_link_issue) in prueth_probe()
1602 icss_iep_exit_fw(prueth->iep1); in prueth_probe()
1603 icss_iep_put(prueth->iep1); in prueth_probe()
1606 icss_iep_put(prueth->iep0); in prueth_probe()
1607 prueth->iep0 = NULL; in prueth_probe()
1608 prueth->iep1 = NULL; in prueth_probe()
1611 gen_pool_free(prueth->sram_pool, in prueth_probe()
1612 (unsigned long)prueth->msmcram.va, msmc_ram_size); in prueth_probe()
1615 pruss_release_mem_region(prueth->pruss, &prueth->shram); in prueth_probe()
1618 pruss_put(prueth->pruss); in prueth_probe()
1643 if (!prueth->registered_netdevs[i]) in prueth_remove()
1645 phy_stop(prueth->emac[i]->ndev->phydev); in prueth_remove()
1646 phy_disconnect(prueth->emac[i]->ndev->phydev); in prueth_remove()
1647 prueth->emac[i]->ndev->phydev = NULL; in prueth_remove()
1648 unregister_netdev(prueth->registered_netdevs[i]); in prueth_remove()
1652 eth_node = prueth->eth_node[i]; in prueth_remove()
1659 if (prueth->pdata.quirk_10m_link_issue) in prueth_remove()
1660 icss_iep_exit_fw(prueth->iep1); in prueth_remove()
1662 icss_iep_put(prueth->iep1); in prueth_remove()
1663 icss_iep_put(prueth->iep0); in prueth_remove()
1665 gen_pool_free(prueth->sram_pool, in prueth_remove()
1666 (unsigned long)prueth->msmcram.va, in prueth_remove()
1669 pruss_release_mem_region(prueth->pruss, &prueth->shram); in prueth_remove()
1671 pruss_put(prueth->pruss); in prueth_remove()
1673 if (prueth->eth_node[PRUETH_MAC1]) in prueth_remove()
1676 if (prueth->eth_node[PRUETH_MAC0]) in prueth_remove()
1693 { .compatible = "ti,am654-icssg-prueth", .data = &am654_icssg_pdata },
1694 { .compatible = "ti,am642-icssg-prueth", .data = &am64x_icssg_pdata },
1703 .name = "icssg-prueth",