Lines Matching +full:am65 +full:- +full:cpts
1 // SPDX-License-Identifier: GPL-2.0
2 /* Texas Instruments K3 AM65 Ethernet Switch SubSystem Driver
4 * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
29 #include <linux/dma/ti-cppi5.h>
30 #include <linux/dma/k3-udma-glue.h>
35 #include "am65-cpsw-nuss.h"
36 #include "am65-cpsw-switchdev.h"
37 #include "k3-cppi-desc-pool.h"
38 #include "am65-cpts.h"
113 /* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */
142 writel(mac_hi, slave->port_base + AM65_CPSW_PORTN_REG_SA_H); in am65_cpsw_port_set_sl_mac()
143 writel(mac_lo, slave->port_base + AM65_CPSW_PORTN_REG_SA_L); in am65_cpsw_port_set_sl_mac()
148 cpsw_sl_reset(port->slave.mac_sl, 100); in am65_cpsw_sl_ctl_reset()
151 port->port_base + AM65_CPSW_PORT_REG_RX_MAXLEN); in am65_cpsw_sl_ctl_reset()
156 common->nuss_ver = readl(common->ss_base); in am65_cpsw_nuss_get_ver()
157 common->cpsw_ver = readl(common->cpsw_base); in am65_cpsw_nuss_get_ver()
158 dev_info(common->dev, in am65_cpsw_nuss_get_ver()
159 "initializing am65 cpsw nuss version 0x%08X, cpsw version 0x%08X Ports: %u quirks:%08x\n", in am65_cpsw_nuss_get_ver()
160 common->nuss_ver, in am65_cpsw_nuss_get_ver()
161 common->cpsw_ver, in am65_cpsw_nuss_get_ver()
162 common->port_num + 1, in am65_cpsw_nuss_get_ver()
163 common->pdata.quirks); in am65_cpsw_nuss_get_ver()
174 if (!common->is_emac_mode) in am65_cpsw_nuss_ndo_slave_add_vid()
180 ret = pm_runtime_resume_and_get(common->dev); in am65_cpsw_nuss_ndo_slave_add_vid()
184 port_mask = BIT(port->port_id) | ALE_PORT_HOST; in am65_cpsw_nuss_ndo_slave_add_vid()
187 dev_info(common->dev, "Adding vlan %d to vlan filter\n", vid); in am65_cpsw_nuss_ndo_slave_add_vid()
188 ret = cpsw_ale_vlan_add_modify(common->ale, vid, port_mask, in am65_cpsw_nuss_ndo_slave_add_vid()
191 pm_runtime_put(common->dev); in am65_cpsw_nuss_ndo_slave_add_vid()
202 if (!common->is_emac_mode) in am65_cpsw_nuss_ndo_slave_kill_vid()
208 ret = pm_runtime_resume_and_get(common->dev); in am65_cpsw_nuss_ndo_slave_kill_vid()
212 dev_info(common->dev, "Removing vlan %d from vlan filter\n", vid); in am65_cpsw_nuss_ndo_slave_kill_vid()
213 ret = cpsw_ale_del_vlan(common->ale, vid, in am65_cpsw_nuss_ndo_slave_kill_vid()
214 BIT(port->port_id) | ALE_PORT_HOST); in am65_cpsw_nuss_ndo_slave_kill_vid()
216 pm_runtime_put(common->dev); in am65_cpsw_nuss_ndo_slave_kill_vid()
223 struct am65_cpsw_common *common = port->common; in am65_cpsw_slave_set_promisc()
225 if (promisc && !common->is_emac_mode) { in am65_cpsw_slave_set_promisc()
226 dev_dbg(common->dev, "promisc mode requested in switch mode"); in am65_cpsw_slave_set_promisc()
232 cpsw_ale_control_set(common->ale, port->port_id, in am65_cpsw_slave_set_promisc()
234 dev_dbg(common->dev, "promisc enabled\n"); in am65_cpsw_slave_set_promisc()
237 cpsw_ale_control_set(common->ale, port->port_id, in am65_cpsw_slave_set_promisc()
239 dev_dbg(common->dev, "promisc disabled\n"); in am65_cpsw_slave_set_promisc()
250 promisc = !!(ndev->flags & IFF_PROMISC); in am65_cpsw_nuss_ndo_slave_set_rx_mode()
257 cpsw_ale_set_allmulti(common->ale, in am65_cpsw_nuss_ndo_slave_set_rx_mode()
258 ndev->flags & IFF_ALLMULTI, port->port_id); in am65_cpsw_nuss_ndo_slave_set_rx_mode()
262 cpsw_ale_flush_multicast(common->ale, port_mask, -1); in am65_cpsw_nuss_ndo_slave_set_rx_mode()
269 cpsw_ale_add_mcast(common->ale, ha->addr, in am65_cpsw_nuss_ndo_slave_set_rx_mode()
284 tx_chn = &common->tx_chns[txqueue]; in am65_cpsw_nuss_ndo_host_tx_timeout()
285 trans_start = READ_ONCE(netif_txq->trans_start); in am65_cpsw_nuss_ndo_host_tx_timeout()
290 jiffies_to_msecs(jiffies - trans_start), in am65_cpsw_nuss_ndo_host_tx_timeout()
291 dql_avail(&netif_txq->dql), in am65_cpsw_nuss_ndo_host_tx_timeout()
292 k3_cppi_desc_pool_avail(tx_chn->desc_pool)); in am65_cpsw_nuss_ndo_host_tx_timeout()
304 struct am65_cpsw_rx_chn *rx_chn = &common->rx_chns; in am65_cpsw_nuss_rx_push()
306 struct device *dev = common->dev; in am65_cpsw_nuss_rx_push()
312 desc_rx = k3_cppi_desc_pool_alloc(rx_chn->desc_pool); in am65_cpsw_nuss_rx_push()
315 return -ENOMEM; in am65_cpsw_nuss_rx_push()
317 desc_dma = k3_cppi_desc_pool_virt2dma(rx_chn->desc_pool, desc_rx); in am65_cpsw_nuss_rx_push()
319 buf_dma = dma_map_single(rx_chn->dma_dev, skb->data, pkt_len, in am65_cpsw_nuss_rx_push()
321 if (unlikely(dma_mapping_error(rx_chn->dma_dev, buf_dma))) { in am65_cpsw_nuss_rx_push()
322 k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx); in am65_cpsw_nuss_rx_push()
324 return -EINVAL; in am65_cpsw_nuss_rx_push()
329 k3_udma_glue_rx_dma_to_cppi5_addr(rx_chn->rx_chn, &buf_dma); in am65_cpsw_nuss_rx_push()
334 return k3_udma_glue_push_rx_chn(rx_chn->rx_chn, 0, desc_rx, desc_dma); in am65_cpsw_nuss_rx_push()
343 val = readl(host_p->port_base + AM65_CPSW_PORT_REG_PRI_CTL); in am65_cpsw_nuss_set_p0_ptype()
345 if (common->pf_p0_rx_ptype_rrobin) { in am65_cpsw_nuss_set_p0_ptype()
357 writel(pri_map, host_p->port_base + AM65_CPSW_PORT_REG_RX_PRI_MAP); in am65_cpsw_nuss_set_p0_ptype()
358 writel(val, host_p->port_base + AM65_CPSW_PORT_REG_PRI_CTL); in am65_cpsw_nuss_set_p0_ptype()
373 if (common->usage_count) in am65_cpsw_nuss_common_open()
379 common->cpsw_base + AM65_CPSW_REG_CTL); in am65_cpsw_nuss_common_open()
382 host_p->port_base + AM65_CPSW_PORT_REG_RX_MAXLEN); in am65_cpsw_nuss_common_open()
384 writel(common->rx_flow_id_base, in am65_cpsw_nuss_common_open()
385 host_p->port_base + AM65_CPSW_PORT0_REG_FLOW_ID_OFFSET); in am65_cpsw_nuss_common_open()
387 writel(AM65_CPSW_P0_REG_CTL_RX_CHECKSUM_EN, host_p->port_base + AM65_CPSW_P0_REG_CTL); in am65_cpsw_nuss_common_open()
393 for (port_idx = 0; port_idx < common->port_num; port_idx++) { in am65_cpsw_nuss_common_open()
394 struct am65_cpsw_port *port = &common->ports[port_idx]; in am65_cpsw_nuss_common_open()
396 if (!port->disabled) in am65_cpsw_nuss_common_open()
397 val |= BIT(port->port_id); in am65_cpsw_nuss_common_open()
399 writel(val, common->cpsw_base + AM65_CPSW_REG_STAT_PORT_EN); in am65_cpsw_nuss_common_open()
402 writel(0, common->cpsw_base + AM65_CPSW_REG_PTYPE); in am65_cpsw_nuss_common_open()
404 cpsw_ale_start(common->ale); in am65_cpsw_nuss_common_open()
407 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, in am65_cpsw_nuss_common_open()
409 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, in am65_cpsw_nuss_common_open()
412 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_VLAN_AWARE, 1); in am65_cpsw_nuss_common_open()
413 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, in am65_cpsw_nuss_common_open()
417 port_mask = GENMASK(common->port_num, 0) & in am65_cpsw_nuss_common_open()
418 ~common->disabled_ports_mask; in am65_cpsw_nuss_common_open()
420 cpsw_ale_add_vlan(common->ale, 0, port_mask, in am65_cpsw_nuss_common_open()
424 if (common->is_emac_mode) in am65_cpsw_nuss_common_open()
429 for (i = 0; i < common->rx_chns.descs_num; i++) { in am65_cpsw_nuss_common_open()
434 dev_err(common->dev, "cannot allocate skb\n"); in am65_cpsw_nuss_common_open()
435 return -ENOMEM; in am65_cpsw_nuss_common_open()
440 dev_err(common->dev, in am65_cpsw_nuss_common_open()
448 k3_udma_glue_enable_rx_chn(common->rx_chns.rx_chn); in am65_cpsw_nuss_common_open()
450 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_common_open()
451 ret = k3_udma_glue_enable_tx_chn(common->tx_chns[i].tx_chn); in am65_cpsw_nuss_common_open()
454 napi_enable(&common->tx_chns[i].napi_tx); in am65_cpsw_nuss_common_open()
457 napi_enable(&common->napi_rx); in am65_cpsw_nuss_common_open()
458 if (common->rx_irq_disabled) { in am65_cpsw_nuss_common_open()
459 common->rx_irq_disabled = false; in am65_cpsw_nuss_common_open()
460 enable_irq(common->rx_chns.irq); in am65_cpsw_nuss_common_open()
463 dev_dbg(common->dev, "cpsw_nuss started\n"); in am65_cpsw_nuss_common_open()
474 if (common->usage_count != 1) in am65_cpsw_nuss_common_stop()
477 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, in am65_cpsw_nuss_common_stop()
481 atomic_set(&common->tdown_cnt, common->tx_ch_num); in am65_cpsw_nuss_common_stop()
484 reinit_completion(&common->tdown_complete); in am65_cpsw_nuss_common_stop()
486 for (i = 0; i < common->tx_ch_num; i++) in am65_cpsw_nuss_common_stop()
487 k3_udma_glue_tdown_tx_chn(common->tx_chns[i].tx_chn, false); in am65_cpsw_nuss_common_stop()
489 i = wait_for_completion_timeout(&common->tdown_complete, in am65_cpsw_nuss_common_stop()
492 dev_err(common->dev, "tx timeout\n"); in am65_cpsw_nuss_common_stop()
493 for (i = 0; i < common->tx_ch_num; i++) in am65_cpsw_nuss_common_stop()
494 napi_disable(&common->tx_chns[i].napi_tx); in am65_cpsw_nuss_common_stop()
496 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_common_stop()
497 k3_udma_glue_reset_tx_chn(common->tx_chns[i].tx_chn, in am65_cpsw_nuss_common_stop()
498 &common->tx_chns[i], in am65_cpsw_nuss_common_stop()
500 k3_udma_glue_disable_tx_chn(common->tx_chns[i].tx_chn); in am65_cpsw_nuss_common_stop()
503 k3_udma_glue_tdown_rx_chn(common->rx_chns.rx_chn, true); in am65_cpsw_nuss_common_stop()
504 napi_disable(&common->napi_rx); in am65_cpsw_nuss_common_stop()
507 k3_udma_glue_reset_rx_chn(common->rx_chns.rx_chn, i, in am65_cpsw_nuss_common_stop()
508 &common->rx_chns, in am65_cpsw_nuss_common_stop()
511 k3_udma_glue_disable_rx_chn(common->rx_chns.rx_chn); in am65_cpsw_nuss_common_stop()
513 cpsw_ale_stop(common->ale); in am65_cpsw_nuss_common_stop()
515 writel(0, common->cpsw_base + AM65_CPSW_REG_CTL); in am65_cpsw_nuss_common_stop()
516 writel(0, common->cpsw_base + AM65_CPSW_REG_STAT_PORT_EN); in am65_cpsw_nuss_common_stop()
518 dev_dbg(common->dev, "cpsw_nuss stopped\n"); in am65_cpsw_nuss_common_stop()
528 phylink_stop(port->slave.phylink); in am65_cpsw_nuss_ndo_slave_stop()
532 phylink_disconnect_phy(port->slave.phylink); in am65_cpsw_nuss_ndo_slave_stop()
538 common->usage_count--; in am65_cpsw_nuss_ndo_slave_stop()
539 pm_runtime_put(common->dev); in am65_cpsw_nuss_ndo_slave_stop()
550 return am65_cpsw_nuss_ndo_slave_add_vid(port->ndev, 0, vid); in cpsw_restore_vlans()
559 ret = pm_runtime_resume_and_get(common->dev); in am65_cpsw_nuss_ndo_slave_open()
564 ret = netif_set_real_num_tx_queues(ndev, common->tx_ch_num); in am65_cpsw_nuss_ndo_slave_open()
566 dev_err(common->dev, "cannot set real number of tx queues\n"); in am65_cpsw_nuss_ndo_slave_open()
572 dev_err(common->dev, "cannot set real number of rx queues\n"); in am65_cpsw_nuss_ndo_slave_open()
576 for (i = 0; i < common->tx_ch_num; i++) in am65_cpsw_nuss_ndo_slave_open()
583 common->usage_count++; in am65_cpsw_nuss_ndo_slave_open()
585 am65_cpsw_port_set_sl_mac(port, ndev->dev_addr); in am65_cpsw_nuss_ndo_slave_open()
587 if (common->is_emac_mode) in am65_cpsw_nuss_ndo_slave_open()
592 /* mac_sl should be configured via phy-link interface */ in am65_cpsw_nuss_ndo_slave_open()
595 ret = phylink_of_phy_connect(port->slave.phylink, port->slave.phy_node, 0); in am65_cpsw_nuss_ndo_slave_open()
602 phylink_start(port->slave.phylink); in am65_cpsw_nuss_ndo_slave_open()
620 desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma); in am65_cpsw_nuss_rx_cleanup()
624 k3_udma_glue_rx_cppi5_to_dma_addr(rx_chn->rx_chn, &buf_dma); in am65_cpsw_nuss_rx_cleanup()
626 dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE); in am65_cpsw_nuss_rx_cleanup()
627 k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx); in am65_cpsw_nuss_rx_cleanup()
641 ssh->hwtstamp = ns_to_ktime(ns); in am65_cpsw_nuss_rx_ts()
644 /* RX psdata[2] word format - checksum information */
656 * AM65_CPSW_RX_PSD_CSUM_ERR bit - indicates csum error in am65_cpsw_nuss_rx_csum()
658 * bits - indicates IPv4/IPv6 packet in am65_cpsw_nuss_rx_csum()
659 * AM65_CPSW_RX_PSD_IS_FRAGMENT bit - indicates fragmented packet in am65_cpsw_nuss_rx_csum()
665 if (unlikely(!(skb->dev->features & NETIF_F_RXCSUM))) in am65_cpsw_nuss_rx_csum()
673 skb->ip_summed = CHECKSUM_UNNECESSARY; in am65_cpsw_nuss_rx_csum()
680 struct am65_cpsw_rx_chn *rx_chn = &common->rx_chns; in am65_cpsw_nuss_rx_packets()
685 struct device *dev = common->dev; in am65_cpsw_nuss_rx_packets()
694 ret = k3_udma_glue_pop_rx_chn(rx_chn->rx_chn, flow_idx, &desc_dma); in am65_cpsw_nuss_rx_packets()
696 if (ret != -ENODATA) in am65_cpsw_nuss_rx_packets()
706 desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma); in am65_cpsw_nuss_rx_packets()
713 k3_udma_glue_rx_cppi5_to_dma_addr(rx_chn->rx_chn, &buf_dma); in am65_cpsw_nuss_rx_packets()
715 cppi5_desc_get_tags_ids(&desc_rx->hdr, &port_id, NULL); in am65_cpsw_nuss_rx_packets()
718 ndev = port->ndev; in am65_cpsw_nuss_rx_packets()
719 skb->dev = ndev; in am65_cpsw_nuss_rx_packets()
723 if (port->rx_ts_enabled) in am65_cpsw_nuss_rx_packets()
728 dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE); in am65_cpsw_nuss_rx_packets()
730 k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx); in am65_cpsw_nuss_rx_packets()
735 am65_cpsw_nuss_set_offload_fwd_mark(skb, ndev_priv->offload_fwd_mark); in am65_cpsw_nuss_rx_packets()
737 skb->protocol = eth_type_trans(skb, ndev); in am65_cpsw_nuss_rx_packets()
739 napi_gro_receive(&common->napi_rx, skb); in am65_cpsw_nuss_rx_packets()
741 stats = this_cpu_ptr(ndev_priv->stats); in am65_cpsw_nuss_rx_packets()
743 u64_stats_update_begin(&stats->syncp); in am65_cpsw_nuss_rx_packets()
744 stats->rx_packets++; in am65_cpsw_nuss_rx_packets()
745 stats->rx_bytes += pkt_len; in am65_cpsw_nuss_rx_packets()
746 u64_stats_update_end(&stats->syncp); in am65_cpsw_nuss_rx_packets()
749 ndev->stats.rx_dropped++; in am65_cpsw_nuss_rx_packets()
755 ndev->stats.rx_dropped++; in am65_cpsw_nuss_rx_packets()
762 ndev->stats.rx_errors++; in am65_cpsw_nuss_rx_packets()
763 ndev->stats.rx_dropped++; in am65_cpsw_nuss_rx_packets()
777 while (flow--) { in am65_cpsw_nuss_rx_poll()
778 cur_budget = budget - num_rx; in am65_cpsw_nuss_rx_poll()
780 while (cur_budget--) { in am65_cpsw_nuss_rx_poll()
791 dev_dbg(common->dev, "%s num_rx:%d %d\n", __func__, num_rx, budget); in am65_cpsw_nuss_rx_poll()
794 if (common->rx_irq_disabled) { in am65_cpsw_nuss_rx_poll()
795 common->rx_irq_disabled = false; in am65_cpsw_nuss_rx_poll()
796 enable_irq(common->rx_chns.irq); in am65_cpsw_nuss_rx_poll()
814 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &buf_dma); in am65_cpsw_nuss_xmit_free()
816 dma_unmap_single(tx_chn->dma_dev, buf_dma, buf_dma_len, DMA_TO_DEVICE); in am65_cpsw_nuss_xmit_free()
819 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &next_desc_dma); in am65_cpsw_nuss_xmit_free()
821 next_desc = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, in am65_cpsw_nuss_xmit_free()
824 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &buf_dma); in am65_cpsw_nuss_xmit_free()
826 dma_unmap_page(tx_chn->dma_dev, buf_dma, buf_dma_len, in am65_cpsw_nuss_xmit_free()
830 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &next_desc_dma); in am65_cpsw_nuss_xmit_free()
832 k3_cppi_desc_pool_free(tx_chn->desc_pool, next_desc); in am65_cpsw_nuss_xmit_free()
835 k3_cppi_desc_pool_free(tx_chn->desc_pool, first_desc); in am65_cpsw_nuss_xmit_free()
845 desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, desc_dma); in am65_cpsw_nuss_tx_cleanup()
864 desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, in am65_cpsw_nuss_tx_compl_packet()
870 ndev = skb->dev; in am65_cpsw_nuss_tx_compl_packet()
872 am65_cpts_tx_timestamp(tx_chn->common->cpts, skb); in am65_cpsw_nuss_tx_compl_packet()
875 stats = this_cpu_ptr(ndev_priv->stats); in am65_cpsw_nuss_tx_compl_packet()
876 u64_stats_update_begin(&stats->syncp); in am65_cpsw_nuss_tx_compl_packet()
877 stats->tx_packets++; in am65_cpsw_nuss_tx_compl_packet()
878 stats->tx_bytes += skb->len; in am65_cpsw_nuss_tx_compl_packet()
879 u64_stats_update_end(&stats->syncp); in am65_cpsw_nuss_tx_compl_packet()
894 (k3_cppi_desc_pool_avail(tx_chn->desc_pool) >= MAX_SKB_FRAGS)) in am65_cpsw_nuss_tx_wake()
904 struct device *dev = common->dev; in am65_cpsw_nuss_tx_compl_packets()
913 tx_chn = &common->tx_chns[chn]; in am65_cpsw_nuss_tx_compl_packets()
916 spin_lock(&tx_chn->lock); in am65_cpsw_nuss_tx_compl_packets()
917 res = k3_udma_glue_pop_tx_chn(tx_chn->tx_chn, &desc_dma); in am65_cpsw_nuss_tx_compl_packets()
918 spin_unlock(&tx_chn->lock); in am65_cpsw_nuss_tx_compl_packets()
919 if (res == -ENODATA) in am65_cpsw_nuss_tx_compl_packets()
923 if (atomic_dec_and_test(&common->tdown_cnt)) in am65_cpsw_nuss_tx_compl_packets()
924 complete(&common->tdown_complete); in am65_cpsw_nuss_tx_compl_packets()
929 total_bytes = skb->len; in am65_cpsw_nuss_tx_compl_packets()
930 ndev = skb->dev; in am65_cpsw_nuss_tx_compl_packets()
949 struct device *dev = common->dev; in am65_cpsw_nuss_tx_compl_packets_2g()
958 tx_chn = &common->tx_chns[chn]; in am65_cpsw_nuss_tx_compl_packets_2g()
961 res = k3_udma_glue_pop_tx_chn(tx_chn->tx_chn, &desc_dma); in am65_cpsw_nuss_tx_compl_packets_2g()
962 if (res == -ENODATA) in am65_cpsw_nuss_tx_compl_packets_2g()
966 if (atomic_dec_and_test(&common->tdown_cnt)) in am65_cpsw_nuss_tx_compl_packets_2g()
967 complete(&common->tdown_complete); in am65_cpsw_nuss_tx_compl_packets_2g()
973 ndev = skb->dev; in am65_cpsw_nuss_tx_compl_packets_2g()
974 total_bytes += skb->len; in am65_cpsw_nuss_tx_compl_packets_2g()
998 if (AM65_CPSW_IS_CPSW2G(tx_chn->common)) in am65_cpsw_nuss_tx_poll()
999 num_tx = am65_cpsw_nuss_tx_compl_packets_2g(tx_chn->common, tx_chn->id, budget); in am65_cpsw_nuss_tx_poll()
1001 num_tx = am65_cpsw_nuss_tx_compl_packets(tx_chn->common, tx_chn->id, budget); in am65_cpsw_nuss_tx_poll()
1007 enable_irq(tx_chn->irq); in am65_cpsw_nuss_tx_poll()
1016 common->rx_irq_disabled = true; in am65_cpsw_nuss_rx_irq()
1018 napi_schedule(&common->napi_rx); in am65_cpsw_nuss_rx_irq()
1028 napi_schedule(&tx_chn->napi_tx); in am65_cpsw_nuss_tx_irq()
1039 struct device *dev = common->dev; in am65_cpsw_nuss_ndo_slave_xmit()
1052 if (port->tx_ts_enabled) in am65_cpsw_nuss_ndo_slave_xmit()
1053 am65_cpts_prep_tx_timestamp(common->cpts, skb); in am65_cpsw_nuss_ndo_slave_xmit()
1058 tx_chn = &common->tx_chns[q_idx]; in am65_cpsw_nuss_ndo_slave_xmit()
1062 buf_dma = dma_map_single(tx_chn->dma_dev, skb->data, pkt_len, in am65_cpsw_nuss_ndo_slave_xmit()
1064 if (unlikely(dma_mapping_error(tx_chn->dma_dev, buf_dma))) { in am65_cpsw_nuss_ndo_slave_xmit()
1066 ndev->stats.tx_errors++; in am65_cpsw_nuss_ndo_slave_xmit()
1070 first_desc = k3_cppi_desc_pool_alloc(tx_chn->desc_pool); in am65_cpsw_nuss_ndo_slave_xmit()
1073 dma_unmap_single(tx_chn->dma_dev, buf_dma, pkt_len, in am65_cpsw_nuss_ndo_slave_xmit()
1080 cppi5_desc_set_pktids(&first_desc->hdr, 0, 0x3FFF); in am65_cpsw_nuss_ndo_slave_xmit()
1082 cppi5_desc_set_tags_ids(&first_desc->hdr, 0, port->port_id); in am65_cpsw_nuss_ndo_slave_xmit()
1084 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &buf_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1092 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { in am65_cpsw_nuss_ndo_slave_xmit()
1096 cs_offset = cs_start + skb->csum_offset; in am65_cpsw_nuss_ndo_slave_xmit()
1099 ((cs_start + 1) << 16) | (skb->len - cs_start); in am65_cpsw_nuss_ndo_slave_xmit()
1110 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in am65_cpsw_nuss_ndo_slave_xmit()
1111 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in am65_cpsw_nuss_ndo_slave_xmit()
1114 next_desc = k3_cppi_desc_pool_alloc(tx_chn->desc_pool); in am65_cpsw_nuss_ndo_slave_xmit()
1120 buf_dma = skb_frag_dma_map(tx_chn->dma_dev, frag, 0, frag_size, in am65_cpsw_nuss_ndo_slave_xmit()
1122 if (unlikely(dma_mapping_error(tx_chn->dma_dev, buf_dma))) { in am65_cpsw_nuss_ndo_slave_xmit()
1124 k3_cppi_desc_pool_free(tx_chn->desc_pool, next_desc); in am65_cpsw_nuss_ndo_slave_xmit()
1125 ndev->stats.tx_errors++; in am65_cpsw_nuss_ndo_slave_xmit()
1130 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &buf_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1134 desc_dma = k3_cppi_desc_pool_virt2dma(tx_chn->desc_pool, in am65_cpsw_nuss_ndo_slave_xmit()
1136 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &desc_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1142 WARN_ON(pkt_len != skb->len); in am65_cpsw_nuss_ndo_slave_xmit()
1151 desc_dma = k3_cppi_desc_pool_virt2dma(tx_chn->desc_pool, first_desc); in am65_cpsw_nuss_ndo_slave_xmit()
1153 ret = k3_udma_glue_push_tx_chn(tx_chn->tx_chn, first_desc, desc_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1155 spin_lock_bh(&tx_chn->lock); in am65_cpsw_nuss_ndo_slave_xmit()
1156 ret = k3_udma_glue_push_tx_chn(tx_chn->tx_chn, first_desc, desc_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1157 spin_unlock_bh(&tx_chn->lock); in am65_cpsw_nuss_ndo_slave_xmit()
1163 ndev->stats.tx_errors++; in am65_cpsw_nuss_ndo_slave_xmit()
1167 if (k3_cppi_desc_pool_avail(tx_chn->desc_pool) < MAX_SKB_FRAGS) { in am65_cpsw_nuss_ndo_slave_xmit()
1173 /* re-check for smp */ in am65_cpsw_nuss_ndo_slave_xmit()
1174 if (k3_cppi_desc_pool_avail(tx_chn->desc_pool) >= in am65_cpsw_nuss_ndo_slave_xmit()
1186 ndev->stats.tx_dropped++; in am65_cpsw_nuss_ndo_slave_xmit()
1209 ret = pm_runtime_resume_and_get(common->dev); in am65_cpsw_nuss_ndo_slave_set_mac_address()
1213 cpsw_ale_del_ucast(common->ale, ndev->dev_addr, in am65_cpsw_nuss_ndo_slave_set_mac_address()
1215 cpsw_ale_add_ucast(common->ale, sockaddr->sa_data, in am65_cpsw_nuss_ndo_slave_set_mac_address()
1221 pm_runtime_put(common->dev); in am65_cpsw_nuss_ndo_slave_set_mac_address()
1235 return -EOPNOTSUPP; in am65_cpsw_nuss_hwtstamp_set()
1237 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) in am65_cpsw_nuss_hwtstamp_set()
1238 return -EFAULT; in am65_cpsw_nuss_hwtstamp_set()
1246 return -ERANGE; in am65_cpsw_nuss_hwtstamp_set()
1251 port->rx_ts_enabled = false; in am65_cpsw_nuss_hwtstamp_set()
1268 port->rx_ts_enabled = true; in am65_cpsw_nuss_hwtstamp_set()
1272 return -ERANGE; in am65_cpsw_nuss_hwtstamp_set()
1275 port->tx_ts_enabled = (cfg.tx_type == HWTSTAMP_TX_ON); in am65_cpsw_nuss_hwtstamp_set()
1296 if (port->tx_ts_enabled) in am65_cpsw_nuss_hwtstamp_set()
1300 writel(seq_id, port->port_base + AM65_CPSW_PORTN_REG_TS_SEQ_LTYPE_REG); in am65_cpsw_nuss_hwtstamp_set()
1301 writel(ts_vlan_ltype, port->port_base + in am65_cpsw_nuss_hwtstamp_set()
1303 writel(ts_ctrl_ltype2, port->port_base + in am65_cpsw_nuss_hwtstamp_set()
1305 writel(ts_ctrl, port->port_base + AM65_CPSW_PORTN_REG_TS_CTL); in am65_cpsw_nuss_hwtstamp_set()
1308 am65_cpts_rx_enable(common->cpts, port->rx_ts_enabled); in am65_cpsw_nuss_hwtstamp_set()
1310 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; in am65_cpsw_nuss_hwtstamp_set()
1320 return -EOPNOTSUPP; in am65_cpsw_nuss_hwtstamp_get()
1323 cfg.tx_type = port->tx_ts_enabled ? in am65_cpsw_nuss_hwtstamp_get()
1325 cfg.rx_filter = port->rx_ts_enabled ? in am65_cpsw_nuss_hwtstamp_get()
1328 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; in am65_cpsw_nuss_hwtstamp_get()
1337 return -EINVAL; in am65_cpsw_nuss_ndo_slave_ioctl()
1346 return phylink_mii_ioctl(port->slave.phylink, req, cmd); in am65_cpsw_nuss_ndo_slave_ioctl()
1363 cpu_stats = per_cpu_ptr(ndev_priv->stats, cpu); in am65_cpsw_nuss_ndo_get_stats()
1365 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp); in am65_cpsw_nuss_ndo_get_stats()
1366 rx_packets = cpu_stats->rx_packets; in am65_cpsw_nuss_ndo_get_stats()
1367 rx_bytes = cpu_stats->rx_bytes; in am65_cpsw_nuss_ndo_get_stats()
1368 tx_packets = cpu_stats->tx_packets; in am65_cpsw_nuss_ndo_get_stats()
1369 tx_bytes = cpu_stats->tx_bytes; in am65_cpsw_nuss_ndo_get_stats()
1370 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start)); in am65_cpsw_nuss_ndo_get_stats()
1372 stats->rx_packets += rx_packets; in am65_cpsw_nuss_ndo_get_stats()
1373 stats->rx_bytes += rx_bytes; in am65_cpsw_nuss_ndo_get_stats()
1374 stats->tx_packets += tx_packets; in am65_cpsw_nuss_ndo_get_stats()
1375 stats->tx_bytes += tx_bytes; in am65_cpsw_nuss_ndo_get_stats()
1378 stats->rx_errors = dev->stats.rx_errors; in am65_cpsw_nuss_ndo_get_stats()
1379 stats->rx_dropped = dev->stats.rx_dropped; in am65_cpsw_nuss_ndo_get_stats()
1380 stats->tx_dropped = dev->stats.tx_dropped; in am65_cpsw_nuss_ndo_get_stats()
1387 return &port->devlink_port; in am65_cpsw_ndo_get_devlink_port()
1412 struct am65_cpsw_common *common = port->common; in am65_cpsw_nuss_mac_config()
1414 if (common->pdata.extra_modes & BIT(state->interface)) in am65_cpsw_nuss_mac_config()
1416 port->sgmii_base + AM65_CPSW_SGMII_CONTROL_REG); in am65_cpsw_nuss_mac_config()
1425 struct am65_cpsw_common *common = port->common; in am65_cpsw_nuss_mac_link_down()
1426 struct net_device *ndev = port->ndev; in am65_cpsw_nuss_mac_link_down()
1430 cpsw_ale_control_set(common->ale, port->port_id, ALE_PORT_STATE, ALE_PORT_STATE_DISABLE); in am65_cpsw_nuss_mac_link_down()
1432 cpsw_sl_ctl_set(port->slave.mac_sl, CPSW_SL_CTL_CMD_IDLE); in am65_cpsw_nuss_mac_link_down()
1434 tmo = cpsw_sl_wait_for_idle(port->slave.mac_sl, 100); in am65_cpsw_nuss_mac_link_down()
1435 dev_dbg(common->dev, "down msc_sl %08x tmo %d\n", in am65_cpsw_nuss_mac_link_down()
1436 cpsw_sl_reg_read(port->slave.mac_sl, CPSW_SL_MACSTATUS), tmo); in am65_cpsw_nuss_mac_link_down()
1438 cpsw_sl_ctl_reset(port->slave.mac_sl); in am65_cpsw_nuss_mac_link_down()
1451 struct am65_cpsw_common *common = port->common; in am65_cpsw_nuss_mac_link_up()
1453 struct net_device *ndev = port->ndev; in am65_cpsw_nuss_mac_link_up()
1472 cpsw_sl_ctl_set(port->slave.mac_sl, mac_control); in am65_cpsw_nuss_mac_link_up()
1475 cpsw_ale_control_set(common->ale, port->port_id, ALE_PORT_STATE, ALE_PORT_STATE_FORWARD); in am65_cpsw_nuss_mac_link_up()
1490 struct am65_cpsw_common *common = port->common; in am65_cpsw_nuss_slave_disable_unused()
1492 if (!port->disabled) in am65_cpsw_nuss_slave_disable_unused()
1495 cpsw_ale_control_set(common->ale, port->port_id, in am65_cpsw_nuss_slave_disable_unused()
1498 cpsw_sl_reset(port->slave.mac_sl, 100); in am65_cpsw_nuss_slave_disable_unused()
1499 cpsw_sl_ctl_reset(port->slave.mac_sl); in am65_cpsw_nuss_slave_disable_unused()
1507 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_free_tx_chns()
1508 struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i]; in am65_cpsw_nuss_free_tx_chns()
1510 if (!IS_ERR_OR_NULL(tx_chn->desc_pool)) in am65_cpsw_nuss_free_tx_chns()
1511 k3_cppi_desc_pool_destroy(tx_chn->desc_pool); in am65_cpsw_nuss_free_tx_chns()
1513 if (!IS_ERR_OR_NULL(tx_chn->tx_chn)) in am65_cpsw_nuss_free_tx_chns()
1514 k3_udma_glue_release_tx_chn(tx_chn->tx_chn); in am65_cpsw_nuss_free_tx_chns()
1522 struct device *dev = common->dev; in am65_cpsw_nuss_remove_tx_chns()
1527 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_remove_tx_chns()
1528 struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i]; in am65_cpsw_nuss_remove_tx_chns()
1530 if (tx_chn->irq) in am65_cpsw_nuss_remove_tx_chns()
1531 devm_free_irq(dev, tx_chn->irq, tx_chn); in am65_cpsw_nuss_remove_tx_chns()
1533 netif_napi_del(&tx_chn->napi_tx); in am65_cpsw_nuss_remove_tx_chns()
1535 if (!IS_ERR_OR_NULL(tx_chn->desc_pool)) in am65_cpsw_nuss_remove_tx_chns()
1536 k3_cppi_desc_pool_destroy(tx_chn->desc_pool); in am65_cpsw_nuss_remove_tx_chns()
1538 if (!IS_ERR_OR_NULL(tx_chn->tx_chn)) in am65_cpsw_nuss_remove_tx_chns()
1539 k3_udma_glue_release_tx_chn(tx_chn->tx_chn); in am65_cpsw_nuss_remove_tx_chns()
1549 struct device *dev = common->dev; in am65_cpsw_nuss_init_tx_chns()
1567 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_init_tx_chns()
1568 struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i]; in am65_cpsw_nuss_init_tx_chns()
1570 snprintf(tx_chn->tx_chn_name, in am65_cpsw_nuss_init_tx_chns()
1571 sizeof(tx_chn->tx_chn_name), "tx%d", i); in am65_cpsw_nuss_init_tx_chns()
1573 spin_lock_init(&tx_chn->lock); in am65_cpsw_nuss_init_tx_chns()
1574 tx_chn->common = common; in am65_cpsw_nuss_init_tx_chns()
1575 tx_chn->id = i; in am65_cpsw_nuss_init_tx_chns()
1576 tx_chn->descs_num = max_desc_num; in am65_cpsw_nuss_init_tx_chns()
1578 tx_chn->tx_chn = in am65_cpsw_nuss_init_tx_chns()
1580 tx_chn->tx_chn_name, in am65_cpsw_nuss_init_tx_chns()
1582 if (IS_ERR(tx_chn->tx_chn)) { in am65_cpsw_nuss_init_tx_chns()
1583 ret = dev_err_probe(dev, PTR_ERR(tx_chn->tx_chn), in am65_cpsw_nuss_init_tx_chns()
1587 tx_chn->dma_dev = k3_udma_glue_tx_get_dma_device(tx_chn->tx_chn); in am65_cpsw_nuss_init_tx_chns()
1589 tx_chn->desc_pool = k3_cppi_desc_pool_create_name(tx_chn->dma_dev, in am65_cpsw_nuss_init_tx_chns()
1590 tx_chn->descs_num, in am65_cpsw_nuss_init_tx_chns()
1592 tx_chn->tx_chn_name); in am65_cpsw_nuss_init_tx_chns()
1593 if (IS_ERR(tx_chn->desc_pool)) { in am65_cpsw_nuss_init_tx_chns()
1594 ret = PTR_ERR(tx_chn->desc_pool); in am65_cpsw_nuss_init_tx_chns()
1599 tx_chn->irq = k3_udma_glue_tx_get_irq(tx_chn->tx_chn); in am65_cpsw_nuss_init_tx_chns()
1600 if (tx_chn->irq <= 0) { in am65_cpsw_nuss_init_tx_chns()
1602 tx_chn->irq); in am65_cpsw_nuss_init_tx_chns()
1606 snprintf(tx_chn->tx_chn_name, in am65_cpsw_nuss_init_tx_chns()
1607 sizeof(tx_chn->tx_chn_name), "%s-tx%d", in am65_cpsw_nuss_init_tx_chns()
1608 dev_name(dev), tx_chn->id); in am65_cpsw_nuss_init_tx_chns()
1626 rx_chn = &common->rx_chns; in am65_cpsw_nuss_free_rx_chns()
1628 if (!IS_ERR_OR_NULL(rx_chn->desc_pool)) in am65_cpsw_nuss_free_rx_chns()
1629 k3_cppi_desc_pool_destroy(rx_chn->desc_pool); in am65_cpsw_nuss_free_rx_chns()
1631 if (!IS_ERR_OR_NULL(rx_chn->rx_chn)) in am65_cpsw_nuss_free_rx_chns()
1632 k3_udma_glue_release_rx_chn(rx_chn->rx_chn); in am65_cpsw_nuss_free_rx_chns()
1637 struct am65_cpsw_rx_chn *rx_chn = &common->rx_chns; in am65_cpsw_nuss_init_rx_chns()
1640 struct device *dev = common->dev; in am65_cpsw_nuss_init_rx_chns()
1650 rx_cfg.flow_id_base = common->rx_flow_id_base; in am65_cpsw_nuss_init_rx_chns()
1653 rx_chn->dev = dev; in am65_cpsw_nuss_init_rx_chns()
1654 rx_chn->descs_num = max_desc_num; in am65_cpsw_nuss_init_rx_chns()
1656 rx_chn->rx_chn = k3_udma_glue_request_rx_chn(dev, "rx", &rx_cfg); in am65_cpsw_nuss_init_rx_chns()
1657 if (IS_ERR(rx_chn->rx_chn)) { in am65_cpsw_nuss_init_rx_chns()
1658 ret = dev_err_probe(dev, PTR_ERR(rx_chn->rx_chn), in am65_cpsw_nuss_init_rx_chns()
1662 rx_chn->dma_dev = k3_udma_glue_rx_get_dma_device(rx_chn->rx_chn); in am65_cpsw_nuss_init_rx_chns()
1664 rx_chn->desc_pool = k3_cppi_desc_pool_create_name(rx_chn->dma_dev, in am65_cpsw_nuss_init_rx_chns()
1665 rx_chn->descs_num, in am65_cpsw_nuss_init_rx_chns()
1667 if (IS_ERR(rx_chn->desc_pool)) { in am65_cpsw_nuss_init_rx_chns()
1668 ret = PTR_ERR(rx_chn->desc_pool); in am65_cpsw_nuss_init_rx_chns()
1673 common->rx_flow_id_base = in am65_cpsw_nuss_init_rx_chns()
1674 k3_udma_glue_rx_get_flow_id_base(rx_chn->rx_chn); in am65_cpsw_nuss_init_rx_chns()
1675 dev_info(dev, "set new flow-id-base %u\n", common->rx_flow_id_base); in am65_cpsw_nuss_init_rx_chns()
1699 rx_flow_cfg.rxfdq_cfg.mode = common->pdata.fdqring_mode; in am65_cpsw_nuss_init_rx_chns()
1701 ret = k3_udma_glue_rx_flow_init(rx_chn->rx_chn, in am65_cpsw_nuss_init_rx_chns()
1709 k3_udma_glue_rx_flow_get_fdq_id(rx_chn->rx_chn, in am65_cpsw_nuss_init_rx_chns()
1712 rx_chn->irq = k3_udma_glue_rx_get_irq(rx_chn->rx_chn, i); in am65_cpsw_nuss_init_rx_chns()
1714 if (rx_chn->irq <= 0) { in am65_cpsw_nuss_init_rx_chns()
1716 rx_chn->irq); in am65_cpsw_nuss_init_rx_chns()
1717 ret = -ENXIO; in am65_cpsw_nuss_init_rx_chns()
1736 host_p->common = common; in am65_cpsw_nuss_init_host_p()
1737 host_p->port_base = common->cpsw_base + AM65_CPSW_NU_PORTS_BASE; in am65_cpsw_nuss_init_host_p()
1738 host_p->stat_base = common->cpsw_base + AM65_CPSW_NU_STATS_BASE; in am65_cpsw_nuss_init_host_p()
1750 syscon = syscon_regmap_lookup_by_phandle(of_node, "ti,syscon-efuse"); in am65_cpsw_am654_get_efuse_macid()
1752 if (PTR_ERR(syscon) == -ENODEV) in am65_cpsw_am654_get_efuse_macid()
1757 ret = of_property_read_u32_index(of_node, "ti,syscon-efuse", 1, in am65_cpsw_am654_get_efuse_macid()
1777 struct device *dev = common->dev; in am65_cpsw_init_cpts()
1779 struct am65_cpts *cpts; in am65_cpsw_init_cpts() local
1785 node = of_get_child_by_name(dev->of_node, "cpts"); in am65_cpsw_init_cpts()
1787 dev_err(dev, "%s cpts not found\n", __func__); in am65_cpsw_init_cpts()
1788 return -ENOENT; in am65_cpsw_init_cpts()
1791 reg_base = common->cpsw_base + AM65_CPSW_NU_CPTS_BASE; in am65_cpsw_init_cpts()
1792 cpts = am65_cpts_create(dev, reg_base, node); in am65_cpsw_init_cpts()
1793 if (IS_ERR(cpts)) { in am65_cpsw_init_cpts()
1794 int ret = PTR_ERR(cpts); in am65_cpsw_init_cpts()
1797 if (ret == -EOPNOTSUPP) { in am65_cpsw_init_cpts()
1798 dev_info(dev, "cpts disabled\n"); in am65_cpsw_init_cpts()
1802 dev_err(dev, "cpts create err %d\n", ret); in am65_cpsw_init_cpts()
1805 common->cpts = cpts; in am65_cpsw_init_cpts()
1806 /* Forbid PM runtime if CPTS is running. in am65_cpsw_init_cpts()
1807 * K3 CPSWxG modules may completely lose context during ON->OFF in am65_cpsw_init_cpts()
1820 struct device *dev = common->dev; in am65_cpsw_nuss_init_slave_ports()
1823 node = of_get_child_by_name(dev->of_node, "ethernet-ports"); in am65_cpsw_nuss_init_slave_ports()
1825 return -ENOENT; in am65_cpsw_nuss_init_slave_ports()
1832 if (strcmp(port_np->name, "port")) in am65_cpsw_nuss_init_slave_ports()
1842 if (!port_id || port_id > common->port_num) { in am65_cpsw_nuss_init_slave_ports()
1844 port_np, port_id, port_np->name); in am65_cpsw_nuss_init_slave_ports()
1845 ret = -EINVAL; in am65_cpsw_nuss_init_slave_ports()
1850 port->port_id = port_id; in am65_cpsw_nuss_init_slave_ports()
1851 port->common = common; in am65_cpsw_nuss_init_slave_ports()
1852 port->port_base = common->cpsw_base + AM65_CPSW_NU_PORTS_BASE + in am65_cpsw_nuss_init_slave_ports()
1854 if (common->pdata.extra_modes) in am65_cpsw_nuss_init_slave_ports()
1855 port->sgmii_base = common->ss_base + AM65_CPSW_SGMII_BASE * (port_id); in am65_cpsw_nuss_init_slave_ports()
1856 port->stat_base = common->cpsw_base + AM65_CPSW_NU_STATS_BASE + in am65_cpsw_nuss_init_slave_ports()
1858 port->name = of_get_property(port_np, "label", NULL); in am65_cpsw_nuss_init_slave_ports()
1859 port->fetch_ram_base = in am65_cpsw_nuss_init_slave_ports()
1860 common->cpsw_base + AM65_CPSW_NU_FRAM_BASE + in am65_cpsw_nuss_init_slave_ports()
1861 (AM65_CPSW_NU_FRAM_PORT_OFFSET * (port_id - 1)); in am65_cpsw_nuss_init_slave_ports()
1863 port->slave.mac_sl = cpsw_sl_get("am65", dev, port->port_base); in am65_cpsw_nuss_init_slave_ports()
1864 if (IS_ERR(port->slave.mac_sl)) { in am65_cpsw_nuss_init_slave_ports()
1865 ret = PTR_ERR(port->slave.mac_sl); in am65_cpsw_nuss_init_slave_ports()
1869 port->disabled = !of_device_is_available(port_np); in am65_cpsw_nuss_init_slave_ports()
1870 if (port->disabled) { in am65_cpsw_nuss_init_slave_ports()
1871 common->disabled_ports_mask |= BIT(port->port_id); in am65_cpsw_nuss_init_slave_ports()
1875 port->slave.ifphy = devm_of_phy_get(dev, port_np, NULL); in am65_cpsw_nuss_init_slave_ports()
1876 if (IS_ERR(port->slave.ifphy)) { in am65_cpsw_nuss_init_slave_ports()
1877 ret = PTR_ERR(port->slave.ifphy); in am65_cpsw_nuss_init_slave_ports()
1883 port->slave.mac_only = in am65_cpsw_nuss_init_slave_ports()
1884 of_property_read_bool(port_np, "ti,mac-only"); in am65_cpsw_nuss_init_slave_ports()
1887 port->slave.phy_node = port_np; in am65_cpsw_nuss_init_slave_ports()
1888 ret = of_get_phy_mode(port_np, &port->slave.phy_if); in am65_cpsw_nuss_init_slave_ports()
1890 dev_err(dev, "%pOF read phy-mode err %d\n", in am65_cpsw_nuss_init_slave_ports()
1895 ret = phy_set_mode_ext(port->slave.ifphy, PHY_MODE_ETHERNET, port->slave.phy_if); in am65_cpsw_nuss_init_slave_ports()
1899 ret = of_get_mac_address(port_np, port->slave.mac_addr); in am65_cpsw_nuss_init_slave_ports()
1902 port->port_id, in am65_cpsw_nuss_init_slave_ports()
1903 port->slave.mac_addr); in am65_cpsw_nuss_init_slave_ports()
1904 if (!is_valid_ether_addr(port->slave.mac_addr)) { in am65_cpsw_nuss_init_slave_ports()
1905 eth_random_addr(port->slave.mac_addr); in am65_cpsw_nuss_init_slave_ports()
1913 if (!(~common->disabled_ports_mask & GENMASK(common->port_num, 1))) { in am65_cpsw_nuss_init_slave_ports()
1915 return -ENODEV; in am65_cpsw_nuss_init_slave_ports()
1938 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_phylink_cleanup()
1939 port = &common->ports[i]; in am65_cpsw_nuss_phylink_cleanup()
1940 if (port->slave.phylink) in am65_cpsw_nuss_phylink_cleanup()
1941 phylink_destroy(port->slave.phylink); in am65_cpsw_nuss_phylink_cleanup()
1949 struct device *dev = common->dev; in am65_cpsw_nuss_init_port_ndev()
1954 port = &common->ports[port_idx]; in am65_cpsw_nuss_init_port_ndev()
1956 if (port->disabled) in am65_cpsw_nuss_init_port_ndev()
1960 port->ndev = devm_alloc_etherdev_mqs(common->dev, in am65_cpsw_nuss_init_port_ndev()
1964 if (!port->ndev) { in am65_cpsw_nuss_init_port_ndev()
1966 port->port_id); in am65_cpsw_nuss_init_port_ndev()
1967 return -ENOMEM; in am65_cpsw_nuss_init_port_ndev()
1970 ndev_priv = netdev_priv(port->ndev); in am65_cpsw_nuss_init_port_ndev()
1971 ndev_priv->port = port; in am65_cpsw_nuss_init_port_ndev()
1972 ndev_priv->msg_enable = AM65_CPSW_DEBUG; in am65_cpsw_nuss_init_port_ndev()
1973 SET_NETDEV_DEV(port->ndev, dev); in am65_cpsw_nuss_init_port_ndev()
1975 eth_hw_addr_set(port->ndev, port->slave.mac_addr); in am65_cpsw_nuss_init_port_ndev()
1977 port->ndev->min_mtu = AM65_CPSW_MIN_PACKET_SIZE; in am65_cpsw_nuss_init_port_ndev()
1978 port->ndev->max_mtu = AM65_CPSW_MAX_PACKET_SIZE; in am65_cpsw_nuss_init_port_ndev()
1979 port->ndev->hw_features = NETIF_F_SG | in am65_cpsw_nuss_init_port_ndev()
1983 port->ndev->features = port->ndev->hw_features | in am65_cpsw_nuss_init_port_ndev()
1985 port->ndev->vlan_features |= NETIF_F_SG; in am65_cpsw_nuss_init_port_ndev()
1986 port->ndev->netdev_ops = &am65_cpsw_nuss_netdev_ops; in am65_cpsw_nuss_init_port_ndev()
1987 port->ndev->ethtool_ops = &am65_cpsw_ethtool_ops_slave; in am65_cpsw_nuss_init_port_ndev()
1990 port->slave.phylink_config.dev = &port->ndev->dev; in am65_cpsw_nuss_init_port_ndev()
1991 port->slave.phylink_config.type = PHYLINK_NETDEV; in am65_cpsw_nuss_init_port_ndev()
1992 port->slave.phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000FD; in am65_cpsw_nuss_init_port_ndev()
1994 if (phy_interface_mode_is_rgmii(port->slave.phy_if)) { in am65_cpsw_nuss_init_port_ndev()
1995 phy_interface_set_rgmii(port->slave.phylink_config.supported_interfaces); in am65_cpsw_nuss_init_port_ndev()
1996 } else if (port->slave.phy_if == PHY_INTERFACE_MODE_RMII) { in am65_cpsw_nuss_init_port_ndev()
1998 port->slave.phylink_config.supported_interfaces); in am65_cpsw_nuss_init_port_ndev()
1999 } else if (common->pdata.extra_modes & BIT(port->slave.phy_if)) { in am65_cpsw_nuss_init_port_ndev()
2001 port->slave.phylink_config.supported_interfaces); in am65_cpsw_nuss_init_port_ndev()
2003 dev_err(dev, "selected phy-mode is not supported\n"); in am65_cpsw_nuss_init_port_ndev()
2004 return -EOPNOTSUPP; in am65_cpsw_nuss_init_port_ndev()
2007 phylink = phylink_create(&port->slave.phylink_config, in am65_cpsw_nuss_init_port_ndev()
2008 of_node_to_fwnode(port->slave.phy_node), in am65_cpsw_nuss_init_port_ndev()
2009 port->slave.phy_if, in am65_cpsw_nuss_init_port_ndev()
2014 port->slave.phylink = phylink; in am65_cpsw_nuss_init_port_ndev()
2017 if (common->pdata.quirks & AM65_CPSW_QUIRK_I2027_NO_TX_CSUM) in am65_cpsw_nuss_init_port_ndev()
2018 port->ndev->features &= ~NETIF_F_HW_CSUM; in am65_cpsw_nuss_init_port_ndev()
2020 ndev_priv->stats = netdev_alloc_pcpu_stats(struct am65_cpsw_ndev_stats); in am65_cpsw_nuss_init_port_ndev()
2021 if (!ndev_priv->stats) in am65_cpsw_nuss_init_port_ndev()
2022 return -ENOMEM; in am65_cpsw_nuss_init_port_ndev()
2025 ndev_priv->stats); in am65_cpsw_nuss_init_port_ndev()
2029 if (!common->dma_ndev) in am65_cpsw_nuss_init_port_ndev()
2030 common->dma_ndev = port->ndev; in am65_cpsw_nuss_init_port_ndev()
2040 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_init_ndevs()
2046 netif_napi_add(common->dma_ndev, &common->napi_rx, in am65_cpsw_nuss_init_ndevs()
2054 struct device *dev = common->dev; in am65_cpsw_nuss_ndev_add_tx_napi()
2057 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_ndev_add_tx_napi()
2058 struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i]; in am65_cpsw_nuss_ndev_add_tx_napi()
2060 netif_napi_add_tx(common->dma_ndev, &tx_chn->napi_tx, in am65_cpsw_nuss_ndev_add_tx_napi()
2063 ret = devm_request_irq(dev, tx_chn->irq, in am65_cpsw_nuss_ndev_add_tx_napi()
2066 tx_chn->tx_chn_name, tx_chn); in am65_cpsw_nuss_ndev_add_tx_napi()
2069 tx_chn->id, tx_chn->irq, ret); in am65_cpsw_nuss_ndev_add_tx_napi()
2083 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_cleanup_ndev()
2084 port = &common->ports[i]; in am65_cpsw_nuss_cleanup_ndev()
2085 if (port->ndev && port->ndev->reg_state == NETREG_REGISTERED) in am65_cpsw_nuss_cleanup_ndev()
2086 unregister_netdev(port->ndev); in am65_cpsw_nuss_cleanup_ndev()
2095 if (common->br_members == (GENMASK(common->port_num, 1) & ~common->disabled_ports_mask)) in am65_cpsw_port_offload_fwd_mark_update()
2098 dev_dbg(common->dev, "set offload_fwd_mark %d\n", set_val); in am65_cpsw_port_offload_fwd_mark_update()
2100 for (i = 1; i <= common->port_num; i++) { in am65_cpsw_port_offload_fwd_mark_update()
2104 if (!port->ndev) in am65_cpsw_port_offload_fwd_mark_update()
2107 priv = am65_ndev_to_priv(port->ndev); in am65_cpsw_port_offload_fwd_mark_update()
2108 priv->offload_fwd_mark = set_val; in am65_cpsw_port_offload_fwd_mark_update()
2114 if (ndev->netdev_ops == &am65_cpsw_nuss_netdev_ops) { in am65_cpsw_port_dev_check()
2117 return !common->is_emac_mode; in am65_cpsw_port_dev_check()
2131 if (!common->br_members) { in am65_cpsw_netdevice_port_link()
2132 common->hw_bridge_dev = br_ndev; in am65_cpsw_netdevice_port_link()
2137 if (common->hw_bridge_dev != br_ndev) in am65_cpsw_netdevice_port_link()
2138 return -EOPNOTSUPP; in am65_cpsw_netdevice_port_link()
2146 common->br_members |= BIT(priv->port->port_id); in am65_cpsw_netdevice_port_link()
2160 common->br_members &= ~BIT(priv->port->port_id); in am65_cpsw_netdevice_port_unlink()
2164 if (!common->br_members) in am65_cpsw_netdevice_port_unlink()
2165 common->hw_bridge_dev = NULL; in am65_cpsw_netdevice_port_unlink()
2184 if (netif_is_bridge_master(info->upper_dev)) { in am65_cpsw_netdevice_event()
2185 if (info->linking) in am65_cpsw_netdevice_event()
2187 info->upper_dev, in am65_cpsw_netdevice_event()
2208 cpsw->am65_cpsw_netdevice_nb.notifier_call = &am65_cpsw_netdevice_event; in am65_cpsw_register_notifiers()
2209 ret = register_netdevice_notifier(&cpsw->am65_cpsw_netdevice_nb); in am65_cpsw_register_notifiers()
2211 dev_err(cpsw->dev, "can't register netdevice notifier\n"); in am65_cpsw_register_notifiers()
2217 unregister_netdevice_notifier(&cpsw->am65_cpsw_netdevice_nb); in am65_cpsw_register_notifiers()
2229 unregister_netdevice_notifier(&cpsw->am65_cpsw_netdevice_nb); in am65_cpsw_unregister_notifiers()
2236 cpsw_ale_add_mcast(cpsw->ale, eth_stp_addr, ALE_PORT_HOST, ALE_SUPER, 0, in am65_cpsw_init_stp_ale_entry()
2244 writel(common->default_vlan, host->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_init_host_port_switch()
2248 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_P0_UNI_FLOOD, 1); in am65_cpsw_init_host_port_switch()
2249 dev_dbg(common->dev, "Set P0_UNI_FLOOD\n"); in am65_cpsw_init_host_port_switch()
2250 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_PORT_NOLEARN, 0); in am65_cpsw_init_host_port_switch()
2257 writel(0, host->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_init_host_port_emac()
2259 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_P0_UNI_FLOOD, 0); in am65_cpsw_init_host_port_emac()
2260 dev_dbg(common->dev, "unset P0_UNI_FLOOD\n"); in am65_cpsw_init_host_port_emac()
2262 /* learning make no sense in multi-mac mode */ in am65_cpsw_init_host_port_emac()
2263 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_PORT_NOLEARN, 1); in am65_cpsw_init_host_port_emac()
2270 struct am65_cpsw_common *common = dl_priv->common; in am65_cpsw_dl_switch_mode_get()
2272 dev_dbg(common->dev, "%s id:%u\n", __func__, id); in am65_cpsw_dl_switch_mode_get()
2275 return -EOPNOTSUPP; in am65_cpsw_dl_switch_mode_get()
2277 ctx->val.vbool = !common->is_emac_mode; in am65_cpsw_dl_switch_mode_get()
2284 struct am65_cpsw_slave_data *slave = &port->slave; in am65_cpsw_init_port_emac_ale()
2285 struct am65_cpsw_common *common = port->common; in am65_cpsw_init_port_emac_ale()
2288 writel(slave->port_vlan, port->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_init_port_emac_ale()
2290 if (slave->mac_only) in am65_cpsw_init_port_emac_ale()
2291 /* enable mac-only mode on port */ in am65_cpsw_init_port_emac_ale()
2292 cpsw_ale_control_set(common->ale, port->port_id, in am65_cpsw_init_port_emac_ale()
2295 cpsw_ale_control_set(common->ale, port->port_id, ALE_PORT_NOLEARN, 1); in am65_cpsw_init_port_emac_ale()
2297 port_mask = BIT(port->port_id) | ALE_PORT_HOST; in am65_cpsw_init_port_emac_ale()
2299 cpsw_ale_add_ucast(common->ale, port->ndev->dev_addr, in am65_cpsw_init_port_emac_ale()
2300 HOST_PORT_NUM, ALE_SECURE, slave->port_vlan); in am65_cpsw_init_port_emac_ale()
2301 cpsw_ale_add_mcast(common->ale, port->ndev->broadcast, in am65_cpsw_init_port_emac_ale()
2302 port_mask, ALE_VLAN, slave->port_vlan, ALE_MCAST_FWD_2); in am65_cpsw_init_port_emac_ale()
2307 struct am65_cpsw_slave_data *slave = &port->slave; in am65_cpsw_init_port_switch_ale()
2308 struct am65_cpsw_common *cpsw = port->common; in am65_cpsw_init_port_switch_ale()
2311 cpsw_ale_control_set(cpsw->ale, port->port_id, in am65_cpsw_init_port_switch_ale()
2314 cpsw_ale_add_ucast(cpsw->ale, port->ndev->dev_addr, in am65_cpsw_init_port_switch_ale()
2316 slave->port_vlan); in am65_cpsw_init_port_switch_ale()
2318 port_mask = BIT(port->port_id) | ALE_PORT_HOST; in am65_cpsw_init_port_switch_ale()
2320 cpsw_ale_add_mcast(cpsw->ale, port->ndev->broadcast, in am65_cpsw_init_port_switch_ale()
2321 port_mask, ALE_VLAN, slave->port_vlan, in am65_cpsw_init_port_switch_ale()
2324 writel(slave->port_vlan, port->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_init_port_switch_ale()
2326 cpsw_ale_control_set(cpsw->ale, port->port_id, in am65_cpsw_init_port_switch_ale()
2334 struct am65_cpsw_common *cpsw = dl_priv->common; in am65_cpsw_dl_switch_mode_set()
2335 bool switch_en = ctx->val.vbool; in am65_cpsw_dl_switch_mode_set()
2339 dev_dbg(cpsw->dev, "%s id:%u\n", __func__, id); in am65_cpsw_dl_switch_mode_set()
2342 return -EOPNOTSUPP; in am65_cpsw_dl_switch_mode_set()
2344 if (switch_en == !cpsw->is_emac_mode) in am65_cpsw_dl_switch_mode_set()
2347 if (!switch_en && cpsw->br_members) { in am65_cpsw_dl_switch_mode_set()
2348 dev_err(cpsw->dev, "Remove ports from bridge before disabling switch mode\n"); in am65_cpsw_dl_switch_mode_set()
2349 return -EINVAL; in am65_cpsw_dl_switch_mode_set()
2354 cpsw->is_emac_mode = !switch_en; in am65_cpsw_dl_switch_mode_set()
2356 for (i = 0; i < cpsw->port_num; i++) { in am65_cpsw_dl_switch_mode_set()
2357 struct net_device *sl_ndev = cpsw->ports[i].ndev; in am65_cpsw_dl_switch_mode_set()
2367 for (i = 0; i < cpsw->port_num; i++) { in am65_cpsw_dl_switch_mode_set()
2368 struct net_device *sl_ndev = cpsw->ports[i].ndev; in am65_cpsw_dl_switch_mode_set()
2376 slave->port_vlan = cpsw->default_vlan; in am65_cpsw_dl_switch_mode_set()
2378 slave->port_vlan = 0; in am65_cpsw_dl_switch_mode_set()
2384 cpsw_ale_control_set(cpsw->ale, 0, ALE_BYPASS, 1); in am65_cpsw_dl_switch_mode_set()
2386 cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM, ALE_CLEAR, 1); in am65_cpsw_dl_switch_mode_set()
2387 cpsw_ale_control_get(cpsw->ale, HOST_PORT_NUM, ALE_AGEOUT); in am65_cpsw_dl_switch_mode_set()
2390 dev_info(cpsw->dev, "Enable switch mode\n"); in am65_cpsw_dl_switch_mode_set()
2394 for (i = 0; i < cpsw->port_num; i++) { in am65_cpsw_dl_switch_mode_set()
2395 struct net_device *sl_ndev = cpsw->ports[i].ndev; in am65_cpsw_dl_switch_mode_set()
2404 slave->port_vlan = cpsw->default_vlan; in am65_cpsw_dl_switch_mode_set()
2411 dev_info(cpsw->dev, "Disable switch mode\n"); in am65_cpsw_dl_switch_mode_set()
2415 for (i = 0; i < cpsw->port_num; i++) { in am65_cpsw_dl_switch_mode_set()
2416 struct net_device *sl_ndev = cpsw->ports[i].ndev; in am65_cpsw_dl_switch_mode_set()
2423 port->slave.port_vlan = 0; in am65_cpsw_dl_switch_mode_set()
2428 cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM, ALE_BYPASS, 0); in am65_cpsw_dl_switch_mode_set()
2447 struct device *dev = common->dev; in am65_cpsw_nuss_register_devlink()
2453 common->devlink = in am65_cpsw_nuss_register_devlink()
2455 if (!common->devlink) in am65_cpsw_nuss_register_devlink()
2456 return -ENOMEM; in am65_cpsw_nuss_register_devlink()
2458 dl_priv = devlink_priv(common->devlink); in am65_cpsw_nuss_register_devlink()
2459 dl_priv->common = common; in am65_cpsw_nuss_register_devlink()
2466 ret = devlink_params_register(common->devlink, in am65_cpsw_nuss_register_devlink()
2475 for (i = 1; i <= common->port_num; i++) { in am65_cpsw_nuss_register_devlink()
2477 dl_port = &port->devlink_port; in am65_cpsw_nuss_register_devlink()
2479 if (port->ndev) in am65_cpsw_nuss_register_devlink()
2483 attrs.phys.port_number = port->port_id; in am65_cpsw_nuss_register_devlink()
2485 memcpy(attrs.switch_id.id, common->switch_id, attrs.switch_id.id_len); in am65_cpsw_nuss_register_devlink()
2488 ret = devlink_port_register(common->devlink, dl_port, port->port_id); in am65_cpsw_nuss_register_devlink()
2491 port->port_id, ret); in am65_cpsw_nuss_register_devlink()
2495 devlink_register(common->devlink); in am65_cpsw_nuss_register_devlink()
2499 for (i = i - 1; i >= 1; i--) { in am65_cpsw_nuss_register_devlink()
2501 dl_port = &port->devlink_port; in am65_cpsw_nuss_register_devlink()
2506 devlink_free(common->devlink); in am65_cpsw_nuss_register_devlink()
2516 devlink_unregister(common->devlink); in am65_cpsw_unregister_devlink()
2518 for (i = 1; i <= common->port_num; i++) { in am65_cpsw_unregister_devlink()
2520 dl_port = &port->devlink_port; in am65_cpsw_unregister_devlink()
2527 devlink_params_unregister(common->devlink, in am65_cpsw_unregister_devlink()
2531 devlink_free(common->devlink); in am65_cpsw_unregister_devlink()
2536 struct device *dev = common->dev; in am65_cpsw_nuss_register_ndevs()
2545 ret = devm_request_irq(dev, common->rx_chns.irq, in am65_cpsw_nuss_register_ndevs()
2550 common->rx_chns.irq, ret); in am65_cpsw_nuss_register_ndevs()
2558 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_register_ndevs()
2559 port = &common->ports[i]; in am65_cpsw_nuss_register_ndevs()
2561 if (!port->ndev) in am65_cpsw_nuss_register_ndevs()
2564 ret = register_netdev(port->ndev); in am65_cpsw_nuss_register_ndevs()
2571 dl_port = &port->devlink_port; in am65_cpsw_nuss_register_ndevs()
2572 devlink_port_type_eth_set(dl_port, port->ndev); in am65_cpsw_nuss_register_ndevs()
2596 common->tx_ch_num = num_tx; in am65_cpsw_nuss_update_tx_chns()
2622 .ale_dev_id = "am65x-cpsw2g",
2628 .ale_dev_id = "am65x-cpsw2g",
2634 .ale_dev_id = "am64-cpswxg",
2640 .ale_dev_id = "am64-cpswxg",
2646 { .compatible = "ti,am654-cpsw-nuss", .data = &am65x_sr1_0},
2647 { .compatible = "ti,j721e-cpsw-nuss", .data = &j721e_pdata},
2648 { .compatible = "ti,am642-cpsw-nuss", .data = &am64x_cpswxg_pdata},
2649 { .compatible = "ti,j7200-cpswxg-nuss", .data = &j7200_cpswxg_pdata},
2659 if (soc && soc->data) { in am65_cpsw_nuss_apply_socinfo()
2660 const struct am65_cpsw_soc_pdata *socdata = soc->data; in am65_cpsw_nuss_apply_socinfo()
2663 common->pdata.quirks &= ~socdata->quirks_dis; in am65_cpsw_nuss_apply_socinfo()
2671 struct device *dev = &pdev->dev; in am65_cpsw_nuss_probe()
2681 return -ENOMEM; in am65_cpsw_nuss_probe()
2682 common->dev = dev; in am65_cpsw_nuss_probe()
2686 return -EINVAL; in am65_cpsw_nuss_probe()
2687 common->pdata = *(const struct am65_cpsw_pdata *)of_id->data; in am65_cpsw_nuss_probe()
2692 common->ss_base = devm_ioremap_resource(&pdev->dev, res); in am65_cpsw_nuss_probe()
2693 if (IS_ERR(common->ss_base)) in am65_cpsw_nuss_probe()
2694 return PTR_ERR(common->ss_base); in am65_cpsw_nuss_probe()
2695 common->cpsw_base = common->ss_base + AM65_CPSW_CPSW_NU_BASE; in am65_cpsw_nuss_probe()
2697 id_temp = cpu_to_be64(res->start); in am65_cpsw_nuss_probe()
2698 memcpy(common->switch_id, &id_temp, sizeof(res->start)); in am65_cpsw_nuss_probe()
2700 node = of_get_child_by_name(dev->of_node, "ethernet-ports"); in am65_cpsw_nuss_probe()
2702 return -ENOENT; in am65_cpsw_nuss_probe()
2703 common->port_num = of_get_child_count(node); in am65_cpsw_nuss_probe()
2705 if (common->port_num < 1 || common->port_num > AM65_CPSW_MAX_PORTS) in am65_cpsw_nuss_probe()
2706 return -ENOENT; in am65_cpsw_nuss_probe()
2708 common->rx_flow_id_base = -1; in am65_cpsw_nuss_probe()
2709 init_completion(&common->tdown_complete); in am65_cpsw_nuss_probe()
2710 common->tx_ch_num = 1; in am65_cpsw_nuss_probe()
2711 common->pf_p0_rx_ptype_rrobin = false; in am65_cpsw_nuss_probe()
2712 common->default_vlan = 1; in am65_cpsw_nuss_probe()
2714 common->ports = devm_kcalloc(dev, common->port_num, in am65_cpsw_nuss_probe()
2715 sizeof(*common->ports), in am65_cpsw_nuss_probe()
2717 if (!common->ports) in am65_cpsw_nuss_probe()
2718 return -ENOMEM; in am65_cpsw_nuss_probe()
2723 common->bus_freq = clk_get_rate(clk); in am65_cpsw_nuss_probe()
2732 node = of_get_child_by_name(dev->of_node, "mdio"); in am65_cpsw_nuss_probe()
2740 ret = -ENODEV; in am65_cpsw_nuss_probe()
2744 common->mdio_dev = &mdio_pdev->dev; in am65_cpsw_nuss_probe()
2769 ale_params.ale_ports = common->port_num + 1; in am65_cpsw_nuss_probe()
2770 ale_params.ale_regs = common->cpsw_base + AM65_CPSW_NU_ALE_BASE; in am65_cpsw_nuss_probe()
2771 ale_params.dev_id = common->pdata.ale_dev_id; in am65_cpsw_nuss_probe()
2772 ale_params.bus_freq = common->bus_freq; in am65_cpsw_nuss_probe()
2774 common->ale = cpsw_ale_create(&ale_params); in am65_cpsw_nuss_probe()
2775 if (IS_ERR(common->ale)) { in am65_cpsw_nuss_probe()
2777 ret = PTR_ERR(common->ale); in am65_cpsw_nuss_probe()
2786 for (i = 0; i < common->port_num; i++) in am65_cpsw_nuss_probe()
2787 am65_cpsw_nuss_slave_disable_unused(&common->ports[i]); in am65_cpsw_nuss_probe()
2791 common->is_emac_mode = true; in am65_cpsw_nuss_probe()
2807 of_platform_device_destroy(common->mdio_dev, NULL); in am65_cpsw_nuss_probe()
2816 struct device *dev = &pdev->dev; in am65_cpsw_nuss_remove()
2822 ret = pm_runtime_resume_and_get(&pdev->dev); in am65_cpsw_nuss_remove()
2835 of_platform_device_destroy(common->mdio_dev, NULL); in am65_cpsw_nuss_remove()
2837 pm_runtime_put_sync(&pdev->dev); in am65_cpsw_nuss_remove()
2838 pm_runtime_disable(&pdev->dev); in am65_cpsw_nuss_remove()
2855 MODULE_DESCRIPTION("TI AM65 CPSW Ethernet driver");