Lines Matching full:emac

54 static void icssg_config_sr1(struct prueth *prueth, struct prueth_emac *emac,  in icssg_config_sr1()  argument
64 config.rx_flow_id = cpu_to_le32(emac->rx_flow_id_base); /* flow id for host port */ in icssg_config_sr1()
65 config.rx_mgr_flow_id = cpu_to_le32(emac->rx_mgm_flow_id_base); /* for mgm ch */ in icssg_config_sr1()
76 emac->speed = SPEED_1000; in icssg_config_sr1()
77 emac->duplex = DUPLEX_FULL; in icssg_config_sr1()
80 static int emac_send_command_sr1(struct prueth_emac *emac, u32 cmd) in emac_send_command_sr1() argument
83 u32 pkt_len = sizeof(emac->cmd_data); in emac_send_command_sr1()
84 __le32 *data = emac->cmd_data; in emac_send_command_sr1()
91 netdev_dbg(emac->ndev, "Sending cmd %x\n", cmd); in emac_send_command_sr1()
94 mutex_lock(&emac->cmd_lock); in emac_send_command_sr1()
98 tx_chn = &emac->tx_chns[emac->tx_ch_num - 1]; in emac_send_command_sr1()
103 netdev_err(emac->ndev, "cmd %x: failed to map cmd buffer\n", cmd); in emac_send_command_sr1()
110 netdev_err(emac->ndev, "cmd %x: failed to allocate descriptor\n", cmd); in emac_send_command_sr1()
131 reinit_completion(&emac->cmd_complete); in emac_send_command_sr1()
134 netdev_err(emac->ndev, "cmd %x: push failed: %d\n", cmd, ret); in emac_send_command_sr1()
137 ret = wait_for_completion_timeout(&emac->cmd_complete, msecs_to_jiffies(100)); in emac_send_command_sr1()
139 netdev_err(emac->ndev, "cmd %x: completion timeout\n", cmd); in emac_send_command_sr1()
141 mutex_unlock(&emac->cmd_lock); in emac_send_command_sr1()
147 mutex_unlock(&emac->cmd_lock); in emac_send_command_sr1()
152 static void icssg_config_set_speed_sr1(struct prueth_emac *emac) in icssg_config_set_speed_sr1() argument
155 struct prueth *prueth = emac->prueth; in icssg_config_set_speed_sr1()
156 int slice = prueth_emac_slice(emac); in icssg_config_set_speed_sr1()
168 emac_send_command_sr1(emac, cmd); in icssg_config_set_speed_sr1()
174 struct prueth_emac *emac = netdev_priv(ndev); in emac_adjust_link_sr1() local
176 struct prueth *prueth = emac->prueth; in emac_adjust_link_sr1()
182 if (phydev->duplex != emac->duplex) { in emac_adjust_link_sr1()
184 emac->duplex = phydev->duplex; in emac_adjust_link_sr1()
186 if (phydev->speed != emac->speed) { in emac_adjust_link_sr1()
188 emac->speed = phydev->speed; in emac_adjust_link_sr1()
190 if (!emac->link) { in emac_adjust_link_sr1()
192 emac->link = 1; in emac_adjust_link_sr1()
194 } else if (emac->link) { in emac_adjust_link_sr1()
196 emac->link = 0; in emac_adjust_link_sr1()
199 emac->speed = SPEED_1000; in emac_adjust_link_sr1()
202 emac->duplex = DUPLEX_FULL; in emac_adjust_link_sr1()
211 if (emac->link) { in emac_adjust_link_sr1()
213 icssg_update_rgmii_cfg(prueth->miig_rt, emac); in emac_adjust_link_sr1()
216 spin_lock_irqsave(&emac->lock, flags); in emac_adjust_link_sr1()
217 icssg_config_ipg(emac); in emac_adjust_link_sr1()
218 spin_unlock_irqrestore(&emac->lock, flags); in emac_adjust_link_sr1()
219 icssg_config_set_speed_sr1(emac); in emac_adjust_link_sr1()
223 if (emac->link) { in emac_adjust_link_sr1()
228 prueth_cleanup_tx_ts(emac); in emac_adjust_link_sr1()
232 static int emac_phy_connect(struct prueth_emac *emac) in emac_phy_connect() argument
234 struct prueth *prueth = emac->prueth; in emac_phy_connect()
235 struct net_device *ndev = emac->ndev; in emac_phy_connect()
237 ndev->phydev = of_phy_connect(emac->ndev, emac->phy_node, in emac_phy_connect()
239 emac->phy_if); in emac_phy_connect()
242 emac->phy_node->full_name); in emac_phy_connect()
246 if (!emac->half_duplex) { in emac_phy_connect()
260 if (emac->phy_if == PHY_INTERFACE_MODE_MII) in emac_phy_connect()
271 static struct sk_buff *prueth_process_rx_mgm(struct prueth_emac *emac, in prueth_process_rx_mgm() argument
274 struct prueth_rx_chn *rx_chn = &emac->rx_mgm_chn; in prueth_process_rx_mgm()
275 struct net_device *ndev = emac->ndev; in prueth_process_rx_mgm()
325 ret = prueth_dma_rx_push(emac, new_skb, &emac->rx_mgm_chn); in prueth_process_rx_mgm()
332 static void prueth_tx_ts_sr1(struct prueth_emac *emac, in prueth_tx_ts_sr1() argument
347 netdev_dbg(emac->ndev, "Invalid TX TS cookie 0x%x\n", in prueth_tx_ts_sr1()
352 skb = emac->tx_ts_skb[cookie]; in prueth_tx_ts_sr1()
353 emac->tx_ts_skb[cookie] = NULL; /* free slot */ in prueth_tx_ts_sr1()
364 struct prueth_emac *emac = dev_id; in prueth_rx_mgm_ts_thread_sr1() local
367 skb = prueth_process_rx_mgm(emac, PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1); in prueth_rx_mgm_ts_thread_sr1()
371 prueth_tx_ts_sr1(emac, (void *)skb->data); in prueth_rx_mgm_ts_thread_sr1()
379 struct prueth_emac *emac = dev_id; in prueth_rx_mgm_rsp_thread() local
383 skb = prueth_process_rx_mgm(emac, PRUETH_RX_MGM_FLOW_RESPONSE_SR1); in prueth_rx_mgm_rsp_thread()
390 netdev_dbg(emac->ndev, "f/w Shutdown cmd resp %x\n", rsp); in prueth_rx_mgm_rsp_thread()
391 complete(&emac->cmd_complete); in prueth_rx_mgm_rsp_thread()
393 netdev_dbg(emac->ndev, "f/w Speed/Duplex cmd rsp %x\n", rsp); in prueth_rx_mgm_rsp_thread()
394 complete(&emac->cmd_complete); in prueth_rx_mgm_rsp_thread()
413 static int prueth_emac_start(struct prueth *prueth, struct prueth_emac *emac) in prueth_emac_start() argument
421 slice = prueth_emac_slice(emac); in prueth_emac_start()
423 netdev_err(emac->ndev, "invalid port\n"); in prueth_emac_start()
427 icssg_config_sr1(prueth, emac, slice); in prueth_emac_start()
443 emac->fw_running = 1; in prueth_emac_start()
453 * emac_ndo_open - EMAC device open
462 struct prueth_emac *emac = netdev_priv(ndev); in emac_ndo_open() local
463 int num_data_chn = emac->tx_ch_num - 1; in emac_ndo_open()
464 struct prueth *prueth = emac->prueth; in emac_ndo_open()
465 int slice = prueth_emac_slice(emac); in emac_ndo_open()
477 ether_addr_copy(emac->mac_addr, ndev->dev_addr); in emac_ndo_open()
479 icssg_class_set_mac_addr(prueth->miig_rt, slice, emac->mac_addr); in emac_ndo_open()
490 init_completion(&emac->cmd_complete); in emac_ndo_open()
491 ret = prueth_init_tx_chns(emac); in emac_ndo_open()
498 ret = prueth_init_rx_chns(emac, &emac->rx_chns, "rx", in emac_ndo_open()
505 ret = prueth_init_rx_chns(emac, &emac->rx_mgm_chn, "rxmgm", in emac_ndo_open()
514 ret = prueth_ndev_add_tx_napi(emac); in emac_ndo_open()
520 ret = request_irq(emac->rx_chns.irq[rx_flow], prueth_rx_irq, in emac_ndo_open()
521 IRQF_TRIGGER_HIGH, dev_name(dev), emac); in emac_ndo_open()
527 ret = request_threaded_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_RESPONSE_SR1], in emac_ndo_open()
530 dev_name(dev), emac); in emac_ndo_open()
536 ret = request_threaded_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1], in emac_ndo_open()
539 dev_name(dev), emac); in emac_ndo_open()
546 ret = prueth_emac_start(prueth, emac); in emac_ndo_open()
553 ret = prueth_prepare_rx_chan(emac, &emac->rx_chns, PRUETH_MAX_PKT_SIZE); in emac_ndo_open()
557 ret = prueth_prepare_rx_chan(emac, &emac->rx_mgm_chn, 64); in emac_ndo_open()
561 ret = k3_udma_glue_enable_rx_chn(emac->rx_mgm_chn.rx_chn); in emac_ndo_open()
565 ret = k3_udma_glue_enable_rx_chn(emac->rx_chns.rx_chn); in emac_ndo_open()
569 for (i = 0; i < emac->tx_ch_num; i++) { in emac_ndo_open()
570 ret = k3_udma_glue_enable_tx_chn(emac->tx_chns[i].tx_chn); in emac_ndo_open()
576 for (i = 0; i < emac->tx_ch_num; i++) in emac_ndo_open()
577 napi_enable(&emac->tx_chns[i].napi_tx); in emac_ndo_open()
578 napi_enable(&emac->napi_rx); in emac_ndo_open()
585 queue_work(system_long_wq, &emac->stats_work.work); in emac_ndo_open()
593 prueth_reset_tx_chan(emac, i, false); in emac_ndo_open()
595 prueth_reset_rx_chan(&emac->rx_mgm_chn, in emac_ndo_open()
598 prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, false); in emac_ndo_open()
600 prueth_emac_stop(emac); in emac_ndo_open()
602 free_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1], in emac_ndo_open()
603 emac); in emac_ndo_open()
605 free_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_RESPONSE_SR1], in emac_ndo_open()
606 emac); in emac_ndo_open()
608 free_irq(emac->rx_chns.irq[rx_flow], emac); in emac_ndo_open()
610 prueth_ndev_del_tx_napi(emac, emac->tx_ch_num); in emac_ndo_open()
612 prueth_cleanup_rx_chns(emac, &emac->rx_mgm_chn, in emac_ndo_open()
615 prueth_cleanup_rx_chns(emac, &emac->rx_chns, max_rx_flows); in emac_ndo_open()
617 prueth_cleanup_tx_chns(emac); in emac_ndo_open()
623 * emac_ndo_stop - EMAC device stop
632 struct prueth_emac *emac = netdev_priv(ndev); in emac_ndo_stop() local
634 struct prueth *prueth = emac->prueth; in emac_ndo_stop()
645 icssg_class_disable(prueth->miig_rt, prueth_emac_slice(emac)); in emac_ndo_stop()
647 emac_send_command_sr1(emac, ICSSG_SHUTDOWN_CMD_SR1); in emac_ndo_stop()
649 atomic_set(&emac->tdown_cnt, emac->tx_ch_num); in emac_ndo_stop()
653 reinit_completion(&emac->tdown_complete); in emac_ndo_stop()
654 for (i = 0; i < emac->tx_ch_num; i++) in emac_ndo_stop()
655 k3_udma_glue_tdown_tx_chn(emac->tx_chns[i].tx_chn, false); in emac_ndo_stop()
657 ret = wait_for_completion_timeout(&emac->tdown_complete, in emac_ndo_stop()
662 prueth_reset_tx_chan(emac, emac->tx_ch_num, true); in emac_ndo_stop()
663 for (i = 0; i < emac->tx_ch_num; i++) in emac_ndo_stop()
664 napi_disable(&emac->tx_chns[i].napi_tx); in emac_ndo_stop()
667 k3_udma_glue_tdown_rx_chn(emac->rx_chns.rx_chn, true); in emac_ndo_stop()
669 prueth_reset_rx_chan(&emac->rx_chns, max_rx_flows, true); in emac_ndo_stop()
671 k3_udma_glue_tdown_rx_chn(emac->rx_mgm_chn.rx_chn, true); in emac_ndo_stop()
672 prueth_reset_rx_chan(&emac->rx_mgm_chn, in emac_ndo_stop()
675 napi_disable(&emac->napi_rx); in emac_ndo_stop()
678 cancel_delayed_work_sync(&emac->stats_work); in emac_ndo_stop()
681 prueth_emac_stop(emac); in emac_ndo_stop()
683 free_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1], emac); in emac_ndo_stop()
684 free_irq(emac->rx_mgm_chn.irq[PRUETH_RX_MGM_FLOW_RESPONSE_SR1], emac); in emac_ndo_stop()
685 free_irq(emac->rx_chns.irq[rx_flow], emac); in emac_ndo_stop()
686 prueth_ndev_del_tx_napi(emac, emac->tx_ch_num); in emac_ndo_stop()
687 prueth_cleanup_tx_chns(emac); in emac_ndo_stop()
689 prueth_cleanup_rx_chns(emac, &emac->rx_mgm_chn, PRUETH_MAX_RX_MGM_FLOWS_SR1); in emac_ndo_stop()
690 prueth_cleanup_rx_chns(emac, &emac->rx_chns, max_rx_flows); in emac_ndo_stop()
699 struct prueth_emac *emac = netdev_priv(ndev); in emac_ndo_set_rx_mode_sr1() local
702 struct prueth *prueth = emac->prueth; in emac_ndo_set_rx_mode_sr1()
703 int slice = prueth_emac_slice(emac); in emac_ndo_set_rx_mode_sr1()
738 struct prueth_emac *emac; in prueth_netdev_init() local
755 ndev = alloc_etherdev_mq(sizeof(*emac), num_tx_chn); in prueth_netdev_init()
759 emac = netdev_priv(ndev); in prueth_netdev_init()
760 emac->is_sr1 = 1; in prueth_netdev_init()
761 emac->prueth = prueth; in prueth_netdev_init()
762 emac->ndev = ndev; in prueth_netdev_init()
763 emac->port_id = port; in prueth_netdev_init()
764 emac->cmd_wq = create_singlethread_workqueue("icssg_cmd_wq"); in prueth_netdev_init()
765 if (!emac->cmd_wq) { in prueth_netdev_init()
770 INIT_DELAYED_WORK(&emac->stats_work, icssg_stats_work_handler); in prueth_netdev_init()
775 &emac->dram); in prueth_netdev_init()
785 emac->tx_ch_num = 2; in prueth_netdev_init()
788 spin_lock_init(&emac->lock); in prueth_netdev_init()
789 mutex_init(&emac->cmd_lock); in prueth_netdev_init()
791 emac->phy_node = of_parse_phandle(eth_node, "phy-handle", 0); in prueth_netdev_init()
792 if (!emac->phy_node && !of_phy_is_fixed_link(eth_node)) { in prueth_netdev_init()
804 emac->phy_node = eth_node; in prueth_netdev_init()
807 ret = of_get_phy_mode(eth_node, &emac->phy_if); in prueth_netdev_init()
813 if (emac->phy_if != PHY_INTERFACE_MODE_MII && in prueth_netdev_init()
814 !phy_interface_mode_is_rgmii(emac->phy_if)) { in prueth_netdev_init()
815 dev_err(prueth->dev, "PHY mode unsupported %s\n", phy_modes(emac->phy_if)); in prueth_netdev_init()
825 switch (emac->phy_if) { in prueth_netdev_init()
827 emac->phy_if = PHY_INTERFACE_MODE_RGMII_RXID; in prueth_netdev_init()
830 emac->phy_if = PHY_INTERFACE_MODE_RGMII; in prueth_netdev_init()
848 ether_addr_copy(emac->mac_addr, ndev->dev_addr); in prueth_netdev_init()
858 netif_napi_add(ndev, &emac->napi_rx, icssg_napi_rx_poll); in prueth_netdev_init()
859 prueth->emac[mac] = emac; in prueth_netdev_init()
864 pruss_release_mem_region(prueth->pruss, &emac->dram); in prueth_netdev_init()
866 destroy_workqueue(emac->cmd_wq); in prueth_netdev_init()
868 emac->ndev = NULL; in prueth_netdev_init()
869 prueth->emac[mac] = NULL; in prueth_netdev_init()
1049 prueth->emac[PRUETH_MAC0]->half_duplex = in prueth_probe()
1052 prueth->emac[PRUETH_MAC0]->iep = prueth->iep0; in prueth_probe()
1063 prueth->emac[PRUETH_MAC1]->half_duplex = in prueth_probe()
1066 prueth->emac[PRUETH_MAC1]->iep = prueth->iep1; in prueth_probe()
1071 ret = register_netdev(prueth->emac[PRUETH_MAC0]->ndev); in prueth_probe()
1077 prueth->registered_netdevs[PRUETH_MAC0] = prueth->emac[PRUETH_MAC0]->ndev; in prueth_probe()
1078 emac_phy_connect(prueth->emac[PRUETH_MAC0]); in prueth_probe()
1079 phy_attached_info(prueth->emac[PRUETH_MAC0]->ndev->phydev); in prueth_probe()
1083 ret = register_netdev(prueth->emac[PRUETH_MAC1]->ndev); in prueth_probe()
1089 prueth->registered_netdevs[PRUETH_MAC1] = prueth->emac[PRUETH_MAC1]->ndev; in prueth_probe()
1090 emac_phy_connect(prueth->emac[PRUETH_MAC1]); in prueth_probe()
1091 phy_attached_info(prueth->emac[PRUETH_MAC1]->ndev->phydev); in prueth_probe()
1094 dev_info(dev, "TI PRU SR1.0 ethernet driver initialized: %s EMAC mode\n", in prueth_probe()
1109 if (prueth->emac[i]->ndev->phydev) { in prueth_probe()
1110 phy_disconnect(prueth->emac[i]->ndev->phydev); in prueth_probe()
1111 prueth->emac[i]->ndev->phydev = NULL; in prueth_probe()
1171 phy_stop(prueth->emac[i]->ndev->phydev); in prueth_remove()
1172 phy_disconnect(prueth->emac[i]->ndev->phydev); in prueth_remove()
1173 prueth->emac[i]->ndev->phydev = NULL; in prueth_remove()