Lines Matching +full:- +full:chn +full:- +full:disabled
1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
31 #include <linux/dma/ti-cppi5.h>
32 #include <linux/dma/k3-udma-glue.h>
37 #include "am65-cpsw-nuss.h"
38 #include "am65-cpsw-switchdev.h"
39 #include "k3-cppi-desc-pool.h"
40 #include "am65-cpts.h"
117 /* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */
146 writel(mac_hi, slave->port_base + AM65_CPSW_PORTN_REG_SA_H); in am65_cpsw_port_set_sl_mac()
147 writel(mac_lo, slave->port_base + AM65_CPSW_PORTN_REG_SA_L); in am65_cpsw_port_set_sl_mac()
152 cpsw_sl_reset(port->slave.mac_sl, 100); in am65_cpsw_sl_ctl_reset()
155 port->port_base + AM65_CPSW_PORT_REG_RX_MAXLEN); in am65_cpsw_sl_ctl_reset()
160 common->nuss_ver = readl(common->ss_base); in am65_cpsw_nuss_get_ver()
161 common->cpsw_ver = readl(common->cpsw_base); in am65_cpsw_nuss_get_ver()
162 dev_info(common->dev, in am65_cpsw_nuss_get_ver()
164 common->nuss_ver, in am65_cpsw_nuss_get_ver()
165 common->cpsw_ver, in am65_cpsw_nuss_get_ver()
166 common->port_num + 1, in am65_cpsw_nuss_get_ver()
167 common->pdata.quirks); in am65_cpsw_nuss_get_ver()
178 if (!common->is_emac_mode) in am65_cpsw_nuss_ndo_slave_add_vid()
184 ret = pm_runtime_resume_and_get(common->dev); in am65_cpsw_nuss_ndo_slave_add_vid()
188 port_mask = BIT(port->port_id) | ALE_PORT_HOST; in am65_cpsw_nuss_ndo_slave_add_vid()
191 dev_info(common->dev, "Adding vlan %d to vlan filter\n", vid); in am65_cpsw_nuss_ndo_slave_add_vid()
192 ret = cpsw_ale_vlan_add_modify(common->ale, vid, port_mask, in am65_cpsw_nuss_ndo_slave_add_vid()
195 pm_runtime_put(common->dev); in am65_cpsw_nuss_ndo_slave_add_vid()
206 if (!common->is_emac_mode) in am65_cpsw_nuss_ndo_slave_kill_vid()
212 ret = pm_runtime_resume_and_get(common->dev); in am65_cpsw_nuss_ndo_slave_kill_vid()
216 dev_info(common->dev, "Removing vlan %d from vlan filter\n", vid); in am65_cpsw_nuss_ndo_slave_kill_vid()
217 ret = cpsw_ale_del_vlan(common->ale, vid, in am65_cpsw_nuss_ndo_slave_kill_vid()
218 BIT(port->port_id) | ALE_PORT_HOST); in am65_cpsw_nuss_ndo_slave_kill_vid()
220 pm_runtime_put(common->dev); in am65_cpsw_nuss_ndo_slave_kill_vid()
227 struct am65_cpsw_common *common = port->common; in am65_cpsw_slave_set_promisc()
229 if (promisc && !common->is_emac_mode) { in am65_cpsw_slave_set_promisc()
230 dev_dbg(common->dev, "promisc mode requested in switch mode"); in am65_cpsw_slave_set_promisc()
236 cpsw_ale_control_set(common->ale, port->port_id, in am65_cpsw_slave_set_promisc()
238 dev_dbg(common->dev, "promisc enabled\n"); in am65_cpsw_slave_set_promisc()
241 cpsw_ale_control_set(common->ale, port->port_id, in am65_cpsw_slave_set_promisc()
243 dev_dbg(common->dev, "promisc disabled\n"); in am65_cpsw_slave_set_promisc()
254 promisc = !!(ndev->flags & IFF_PROMISC); in am65_cpsw_nuss_ndo_slave_set_rx_mode()
261 cpsw_ale_set_allmulti(common->ale, in am65_cpsw_nuss_ndo_slave_set_rx_mode()
262 ndev->flags & IFF_ALLMULTI, port->port_id); in am65_cpsw_nuss_ndo_slave_set_rx_mode()
266 cpsw_ale_flush_multicast(common->ale, port_mask, -1); in am65_cpsw_nuss_ndo_slave_set_rx_mode()
273 cpsw_ale_add_mcast(common->ale, ha->addr, in am65_cpsw_nuss_ndo_slave_set_rx_mode()
288 tx_chn = &common->tx_chns[txqueue]; in am65_cpsw_nuss_ndo_host_tx_timeout()
289 trans_start = READ_ONCE(netif_txq->trans_start); in am65_cpsw_nuss_ndo_host_tx_timeout()
294 jiffies_to_msecs(jiffies - trans_start), in am65_cpsw_nuss_ndo_host_tx_timeout()
295 dql_avail(&netif_txq->dql), in am65_cpsw_nuss_ndo_host_tx_timeout()
296 k3_cppi_desc_pool_avail(tx_chn->desc_pool)); in am65_cpsw_nuss_ndo_host_tx_timeout()
308 struct am65_cpsw_rx_chn *rx_chn = &common->rx_chns; in am65_cpsw_nuss_rx_push()
310 struct device *dev = common->dev; in am65_cpsw_nuss_rx_push()
316 desc_rx = k3_cppi_desc_pool_alloc(rx_chn->desc_pool); in am65_cpsw_nuss_rx_push()
319 return -ENOMEM; in am65_cpsw_nuss_rx_push()
321 desc_dma = k3_cppi_desc_pool_virt2dma(rx_chn->desc_pool, desc_rx); in am65_cpsw_nuss_rx_push()
323 buf_dma = dma_map_single(rx_chn->dma_dev, skb->data, pkt_len, in am65_cpsw_nuss_rx_push()
325 if (unlikely(dma_mapping_error(rx_chn->dma_dev, buf_dma))) { in am65_cpsw_nuss_rx_push()
326 k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx); in am65_cpsw_nuss_rx_push()
328 return -EINVAL; in am65_cpsw_nuss_rx_push()
333 k3_udma_glue_rx_dma_to_cppi5_addr(rx_chn->rx_chn, &buf_dma); in am65_cpsw_nuss_rx_push()
338 return k3_udma_glue_push_rx_chn(rx_chn->rx_chn, 0, desc_rx, desc_dma); in am65_cpsw_nuss_rx_push()
347 val = readl(host_p->port_base + AM65_CPSW_PORT_REG_PRI_CTL); in am65_cpsw_nuss_set_p0_ptype()
349 if (common->pf_p0_rx_ptype_rrobin) { in am65_cpsw_nuss_set_p0_ptype()
361 writel(pri_map, host_p->port_base + AM65_CPSW_PORT_REG_RX_PRI_MAP); in am65_cpsw_nuss_set_p0_ptype()
362 writel(val, host_p->port_base + AM65_CPSW_PORT_REG_PRI_CTL); in am65_cpsw_nuss_set_p0_ptype()
377 if (common->usage_count) in am65_cpsw_nuss_common_open()
383 common->cpsw_base + AM65_CPSW_REG_CTL); in am65_cpsw_nuss_common_open()
386 host_p->port_base + AM65_CPSW_PORT_REG_RX_MAXLEN); in am65_cpsw_nuss_common_open()
388 writel(common->rx_flow_id_base, in am65_cpsw_nuss_common_open()
389 host_p->port_base + AM65_CPSW_PORT0_REG_FLOW_ID_OFFSET); in am65_cpsw_nuss_common_open()
391 host_p->port_base + AM65_CPSW_P0_REG_CTL); in am65_cpsw_nuss_common_open()
397 for (port_idx = 0; port_idx < common->port_num; port_idx++) { in am65_cpsw_nuss_common_open()
398 struct am65_cpsw_port *port = &common->ports[port_idx]; in am65_cpsw_nuss_common_open()
400 if (!port->disabled) in am65_cpsw_nuss_common_open()
401 val |= BIT(port->port_id); in am65_cpsw_nuss_common_open()
403 writel(val, common->cpsw_base + AM65_CPSW_REG_STAT_PORT_EN); in am65_cpsw_nuss_common_open()
406 writel(0, common->cpsw_base + AM65_CPSW_REG_PTYPE); in am65_cpsw_nuss_common_open()
408 cpsw_ale_start(common->ale); in am65_cpsw_nuss_common_open()
411 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, in am65_cpsw_nuss_common_open()
413 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, in am65_cpsw_nuss_common_open()
416 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_VLAN_AWARE, 1); in am65_cpsw_nuss_common_open()
417 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, in am65_cpsw_nuss_common_open()
421 port_mask = GENMASK(common->port_num, 0) & in am65_cpsw_nuss_common_open()
422 ~common->disabled_ports_mask; in am65_cpsw_nuss_common_open()
424 cpsw_ale_add_vlan(common->ale, 0, port_mask, in am65_cpsw_nuss_common_open()
428 if (common->is_emac_mode) in am65_cpsw_nuss_common_open()
435 for (i = 0; i < common->rx_chns.descs_num; i++) { in am65_cpsw_nuss_common_open()
440 dev_err(common->dev, "cannot allocate skb\n"); in am65_cpsw_nuss_common_open()
441 return -ENOMEM; in am65_cpsw_nuss_common_open()
446 dev_err(common->dev, in am65_cpsw_nuss_common_open()
454 k3_udma_glue_enable_rx_chn(common->rx_chns.rx_chn); in am65_cpsw_nuss_common_open()
456 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_common_open()
457 ret = k3_udma_glue_enable_tx_chn(common->tx_chns[i].tx_chn); in am65_cpsw_nuss_common_open()
460 napi_enable(&common->tx_chns[i].napi_tx); in am65_cpsw_nuss_common_open()
463 napi_enable(&common->napi_rx); in am65_cpsw_nuss_common_open()
464 if (common->rx_irq_disabled) { in am65_cpsw_nuss_common_open()
465 common->rx_irq_disabled = false; in am65_cpsw_nuss_common_open()
466 enable_irq(common->rx_chns.irq); in am65_cpsw_nuss_common_open()
469 dev_dbg(common->dev, "cpsw_nuss started\n"); in am65_cpsw_nuss_common_open()
480 if (common->usage_count != 1) in am65_cpsw_nuss_common_stop()
483 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, in am65_cpsw_nuss_common_stop()
487 atomic_set(&common->tdown_cnt, common->tx_ch_num); in am65_cpsw_nuss_common_stop()
490 reinit_completion(&common->tdown_complete); in am65_cpsw_nuss_common_stop()
492 for (i = 0; i < common->tx_ch_num; i++) in am65_cpsw_nuss_common_stop()
493 k3_udma_glue_tdown_tx_chn(common->tx_chns[i].tx_chn, false); in am65_cpsw_nuss_common_stop()
495 i = wait_for_completion_timeout(&common->tdown_complete, in am65_cpsw_nuss_common_stop()
498 dev_err(common->dev, "tx timeout\n"); in am65_cpsw_nuss_common_stop()
499 for (i = 0; i < common->tx_ch_num; i++) in am65_cpsw_nuss_common_stop()
500 napi_disable(&common->tx_chns[i].napi_tx); in am65_cpsw_nuss_common_stop()
502 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_common_stop()
503 k3_udma_glue_reset_tx_chn(common->tx_chns[i].tx_chn, in am65_cpsw_nuss_common_stop()
504 &common->tx_chns[i], in am65_cpsw_nuss_common_stop()
506 k3_udma_glue_disable_tx_chn(common->tx_chns[i].tx_chn); in am65_cpsw_nuss_common_stop()
509 reinit_completion(&common->tdown_complete); in am65_cpsw_nuss_common_stop()
510 k3_udma_glue_tdown_rx_chn(common->rx_chns.rx_chn, true); in am65_cpsw_nuss_common_stop()
512 if (common->pdata.quirks & AM64_CPSW_QUIRK_DMA_RX_TDOWN_IRQ) { in am65_cpsw_nuss_common_stop()
513 i = wait_for_completion_timeout(&common->tdown_complete, msecs_to_jiffies(1000)); in am65_cpsw_nuss_common_stop()
515 dev_err(common->dev, "rx teardown timeout\n"); in am65_cpsw_nuss_common_stop()
518 napi_disable(&common->napi_rx); in am65_cpsw_nuss_common_stop()
521 k3_udma_glue_reset_rx_chn(common->rx_chns.rx_chn, i, in am65_cpsw_nuss_common_stop()
522 &common->rx_chns, in am65_cpsw_nuss_common_stop()
525 k3_udma_glue_disable_rx_chn(common->rx_chns.rx_chn); in am65_cpsw_nuss_common_stop()
527 cpsw_ale_stop(common->ale); in am65_cpsw_nuss_common_stop()
529 writel(0, common->cpsw_base + AM65_CPSW_REG_CTL); in am65_cpsw_nuss_common_stop()
530 writel(0, common->cpsw_base + AM65_CPSW_REG_STAT_PORT_EN); in am65_cpsw_nuss_common_stop()
532 dev_dbg(common->dev, "cpsw_nuss stopped\n"); in am65_cpsw_nuss_common_stop()
542 phylink_stop(port->slave.phylink); in am65_cpsw_nuss_ndo_slave_stop()
546 phylink_disconnect_phy(port->slave.phylink); in am65_cpsw_nuss_ndo_slave_stop()
552 common->usage_count--; in am65_cpsw_nuss_ndo_slave_stop()
553 pm_runtime_put(common->dev); in am65_cpsw_nuss_ndo_slave_stop()
564 return am65_cpsw_nuss_ndo_slave_add_vid(port->ndev, 0, vid); in cpsw_restore_vlans()
574 ret = pm_runtime_resume_and_get(common->dev); in am65_cpsw_nuss_ndo_slave_open()
579 cpsw_sl_ctl_set(port->slave.mac_sl, CPSW_SL_CTL_CMD_IDLE); in am65_cpsw_nuss_ndo_slave_open()
580 cpsw_sl_wait_for_idle(port->slave.mac_sl, 100); in am65_cpsw_nuss_ndo_slave_open()
581 cpsw_sl_ctl_reset(port->slave.mac_sl); in am65_cpsw_nuss_ndo_slave_open()
584 cpsw_sl_reg_write(port->slave.mac_sl, CPSW_SL_SOFT_RESET, 1); in am65_cpsw_nuss_ndo_slave_open()
586 reg = cpsw_sl_reg_read(port->slave.mac_sl, CPSW_SL_SOFT_RESET); in am65_cpsw_nuss_ndo_slave_open()
588 dev_err(common->dev, "soft RESET didn't complete\n"); in am65_cpsw_nuss_ndo_slave_open()
589 ret = -ETIMEDOUT; in am65_cpsw_nuss_ndo_slave_open()
594 ret = netif_set_real_num_tx_queues(ndev, common->tx_ch_num); in am65_cpsw_nuss_ndo_slave_open()
596 dev_err(common->dev, "cannot set real number of tx queues\n"); in am65_cpsw_nuss_ndo_slave_open()
602 dev_err(common->dev, "cannot set real number of rx queues\n"); in am65_cpsw_nuss_ndo_slave_open()
606 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_ndo_slave_open()
610 txq->tx_maxrate = common->tx_chns[i].rate_mbps; in am65_cpsw_nuss_ndo_slave_open()
617 common->usage_count++; in am65_cpsw_nuss_ndo_slave_open()
619 am65_cpsw_port_set_sl_mac(port, ndev->dev_addr); in am65_cpsw_nuss_ndo_slave_open()
621 if (common->is_emac_mode) in am65_cpsw_nuss_ndo_slave_open()
626 /* mac_sl should be configured via phy-link interface */ in am65_cpsw_nuss_ndo_slave_open()
629 ret = phylink_of_phy_connect(port->slave.phylink, port->slave.phy_node, 0); in am65_cpsw_nuss_ndo_slave_open()
636 phylink_start(port->slave.phylink); in am65_cpsw_nuss_ndo_slave_open()
645 pm_runtime_put(common->dev); in am65_cpsw_nuss_ndo_slave_open()
658 desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma); in am65_cpsw_nuss_rx_cleanup()
662 k3_udma_glue_rx_cppi5_to_dma_addr(rx_chn->rx_chn, &buf_dma); in am65_cpsw_nuss_rx_cleanup()
664 dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE); in am65_cpsw_nuss_rx_cleanup()
665 k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx); in am65_cpsw_nuss_rx_cleanup()
679 ssh->hwtstamp = ns_to_ktime(ns); in am65_cpsw_nuss_rx_ts()
682 /* RX psdata[2] word format - checksum information */
694 * AM65_CPSW_RX_PSD_CSUM_ERR bit - indicates csum error in am65_cpsw_nuss_rx_csum()
696 * bits - indicates IPv4/IPv6 packet in am65_cpsw_nuss_rx_csum()
697 * AM65_CPSW_RX_PSD_IS_FRAGMENT bit - indicates fragmented packet in am65_cpsw_nuss_rx_csum()
703 if (unlikely(!(skb->dev->features & NETIF_F_RXCSUM))) in am65_cpsw_nuss_rx_csum()
711 skb->ip_summed = CHECKSUM_UNNECESSARY; in am65_cpsw_nuss_rx_csum()
718 struct am65_cpsw_rx_chn *rx_chn = &common->rx_chns; in am65_cpsw_nuss_rx_packets()
723 struct device *dev = common->dev; in am65_cpsw_nuss_rx_packets()
732 ret = k3_udma_glue_pop_rx_chn(rx_chn->rx_chn, flow_idx, &desc_dma); in am65_cpsw_nuss_rx_packets()
734 if (ret != -ENODATA) in am65_cpsw_nuss_rx_packets()
735 dev_err(dev, "RX: pop chn fail %d\n", ret); in am65_cpsw_nuss_rx_packets()
741 if (common->pdata.quirks & AM64_CPSW_QUIRK_DMA_RX_TDOWN_IRQ) in am65_cpsw_nuss_rx_packets()
742 complete(&common->tdown_complete); in am65_cpsw_nuss_rx_packets()
746 desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma); in am65_cpsw_nuss_rx_packets()
753 k3_udma_glue_rx_cppi5_to_dma_addr(rx_chn->rx_chn, &buf_dma); in am65_cpsw_nuss_rx_packets()
755 cppi5_desc_get_tags_ids(&desc_rx->hdr, &port_id, NULL); in am65_cpsw_nuss_rx_packets()
758 ndev = port->ndev; in am65_cpsw_nuss_rx_packets()
759 skb->dev = ndev; in am65_cpsw_nuss_rx_packets()
763 if (port->rx_ts_enabled) in am65_cpsw_nuss_rx_packets()
768 dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE); in am65_cpsw_nuss_rx_packets()
770 k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx); in am65_cpsw_nuss_rx_packets()
775 am65_cpsw_nuss_set_offload_fwd_mark(skb, ndev_priv->offload_fwd_mark); in am65_cpsw_nuss_rx_packets()
777 skb->protocol = eth_type_trans(skb, ndev); in am65_cpsw_nuss_rx_packets()
779 napi_gro_receive(&common->napi_rx, skb); in am65_cpsw_nuss_rx_packets()
781 stats = this_cpu_ptr(ndev_priv->stats); in am65_cpsw_nuss_rx_packets()
783 u64_stats_update_begin(&stats->syncp); in am65_cpsw_nuss_rx_packets()
784 stats->rx_packets++; in am65_cpsw_nuss_rx_packets()
785 stats->rx_bytes += pkt_len; in am65_cpsw_nuss_rx_packets()
786 u64_stats_update_end(&stats->syncp); in am65_cpsw_nuss_rx_packets()
789 ndev->stats.rx_dropped++; in am65_cpsw_nuss_rx_packets()
795 ndev->stats.rx_dropped++; in am65_cpsw_nuss_rx_packets()
802 ndev->stats.rx_errors++; in am65_cpsw_nuss_rx_packets()
803 ndev->stats.rx_dropped++; in am65_cpsw_nuss_rx_packets()
817 while (flow--) { in am65_cpsw_nuss_rx_poll()
818 cur_budget = budget - num_rx; in am65_cpsw_nuss_rx_poll()
820 while (cur_budget--) { in am65_cpsw_nuss_rx_poll()
831 dev_dbg(common->dev, "%s num_rx:%d %d\n", __func__, num_rx, budget); in am65_cpsw_nuss_rx_poll()
834 if (common->rx_irq_disabled) { in am65_cpsw_nuss_rx_poll()
835 common->rx_irq_disabled = false; in am65_cpsw_nuss_rx_poll()
836 enable_irq(common->rx_chns.irq); in am65_cpsw_nuss_rx_poll()
854 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &buf_dma); in am65_cpsw_nuss_xmit_free()
856 dma_unmap_single(tx_chn->dma_dev, buf_dma, buf_dma_len, DMA_TO_DEVICE); in am65_cpsw_nuss_xmit_free()
859 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &next_desc_dma); in am65_cpsw_nuss_xmit_free()
861 next_desc = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, in am65_cpsw_nuss_xmit_free()
864 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &buf_dma); in am65_cpsw_nuss_xmit_free()
866 dma_unmap_page(tx_chn->dma_dev, buf_dma, buf_dma_len, in am65_cpsw_nuss_xmit_free()
870 k3_udma_glue_tx_cppi5_to_dma_addr(tx_chn->tx_chn, &next_desc_dma); in am65_cpsw_nuss_xmit_free()
872 k3_cppi_desc_pool_free(tx_chn->desc_pool, next_desc); in am65_cpsw_nuss_xmit_free()
875 k3_cppi_desc_pool_free(tx_chn->desc_pool, first_desc); in am65_cpsw_nuss_xmit_free()
885 desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, desc_dma); in am65_cpsw_nuss_tx_cleanup()
904 desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, in am65_cpsw_nuss_tx_compl_packet()
910 ndev = skb->dev; in am65_cpsw_nuss_tx_compl_packet()
912 am65_cpts_tx_timestamp(tx_chn->common->cpts, skb); in am65_cpsw_nuss_tx_compl_packet()
915 stats = this_cpu_ptr(ndev_priv->stats); in am65_cpsw_nuss_tx_compl_packet()
916 u64_stats_update_begin(&stats->syncp); in am65_cpsw_nuss_tx_compl_packet()
917 stats->tx_packets++; in am65_cpsw_nuss_tx_compl_packet()
918 stats->tx_bytes += skb->len; in am65_cpsw_nuss_tx_compl_packet()
919 u64_stats_update_end(&stats->syncp); in am65_cpsw_nuss_tx_compl_packet()
934 (k3_cppi_desc_pool_avail(tx_chn->desc_pool) >= MAX_SKB_FRAGS)) in am65_cpsw_nuss_tx_wake()
942 int chn, unsigned int budget) in am65_cpsw_nuss_tx_compl_packets() argument
944 struct device *dev = common->dev; in am65_cpsw_nuss_tx_compl_packets()
953 tx_chn = &common->tx_chns[chn]; in am65_cpsw_nuss_tx_compl_packets()
956 spin_lock(&tx_chn->lock); in am65_cpsw_nuss_tx_compl_packets()
957 res = k3_udma_glue_pop_tx_chn(tx_chn->tx_chn, &desc_dma); in am65_cpsw_nuss_tx_compl_packets()
958 spin_unlock(&tx_chn->lock); in am65_cpsw_nuss_tx_compl_packets()
959 if (res == -ENODATA) in am65_cpsw_nuss_tx_compl_packets()
963 if (atomic_dec_and_test(&common->tdown_cnt)) in am65_cpsw_nuss_tx_compl_packets()
964 complete(&common->tdown_complete); in am65_cpsw_nuss_tx_compl_packets()
969 total_bytes = skb->len; in am65_cpsw_nuss_tx_compl_packets()
970 ndev = skb->dev; in am65_cpsw_nuss_tx_compl_packets()
974 netif_txq = netdev_get_tx_queue(ndev, chn); in am65_cpsw_nuss_tx_compl_packets()
981 dev_dbg(dev, "%s:%u pkt:%d\n", __func__, chn, num_tx); in am65_cpsw_nuss_tx_compl_packets()
987 int chn, unsigned int budget) in am65_cpsw_nuss_tx_compl_packets_2g() argument
989 struct device *dev = common->dev; in am65_cpsw_nuss_tx_compl_packets_2g()
998 tx_chn = &common->tx_chns[chn]; in am65_cpsw_nuss_tx_compl_packets_2g()
1001 res = k3_udma_glue_pop_tx_chn(tx_chn->tx_chn, &desc_dma); in am65_cpsw_nuss_tx_compl_packets_2g()
1002 if (res == -ENODATA) in am65_cpsw_nuss_tx_compl_packets_2g()
1006 if (atomic_dec_and_test(&common->tdown_cnt)) in am65_cpsw_nuss_tx_compl_packets_2g()
1007 complete(&common->tdown_complete); in am65_cpsw_nuss_tx_compl_packets_2g()
1013 ndev = skb->dev; in am65_cpsw_nuss_tx_compl_packets_2g()
1014 total_bytes += skb->len; in am65_cpsw_nuss_tx_compl_packets_2g()
1022 netif_txq = netdev_get_tx_queue(ndev, chn); in am65_cpsw_nuss_tx_compl_packets_2g()
1028 dev_dbg(dev, "%s:%u pkt:%d\n", __func__, chn, num_tx); in am65_cpsw_nuss_tx_compl_packets_2g()
1038 if (AM65_CPSW_IS_CPSW2G(tx_chn->common)) in am65_cpsw_nuss_tx_poll()
1039 num_tx = am65_cpsw_nuss_tx_compl_packets_2g(tx_chn->common, tx_chn->id, budget); in am65_cpsw_nuss_tx_poll()
1041 num_tx = am65_cpsw_nuss_tx_compl_packets(tx_chn->common, tx_chn->id, budget); in am65_cpsw_nuss_tx_poll()
1047 enable_irq(tx_chn->irq); in am65_cpsw_nuss_tx_poll()
1056 common->rx_irq_disabled = true; in am65_cpsw_nuss_rx_irq()
1058 napi_schedule(&common->napi_rx); in am65_cpsw_nuss_rx_irq()
1068 napi_schedule(&tx_chn->napi_tx); in am65_cpsw_nuss_tx_irq()
1079 struct device *dev = common->dev; in am65_cpsw_nuss_ndo_slave_xmit()
1092 if (port->tx_ts_enabled) in am65_cpsw_nuss_ndo_slave_xmit()
1093 am65_cpts_prep_tx_timestamp(common->cpts, skb); in am65_cpsw_nuss_ndo_slave_xmit()
1098 tx_chn = &common->tx_chns[q_idx]; in am65_cpsw_nuss_ndo_slave_xmit()
1102 buf_dma = dma_map_single(tx_chn->dma_dev, skb->data, pkt_len, in am65_cpsw_nuss_ndo_slave_xmit()
1104 if (unlikely(dma_mapping_error(tx_chn->dma_dev, buf_dma))) { in am65_cpsw_nuss_ndo_slave_xmit()
1106 ndev->stats.tx_errors++; in am65_cpsw_nuss_ndo_slave_xmit()
1110 first_desc = k3_cppi_desc_pool_alloc(tx_chn->desc_pool); in am65_cpsw_nuss_ndo_slave_xmit()
1113 dma_unmap_single(tx_chn->dma_dev, buf_dma, pkt_len, in am65_cpsw_nuss_ndo_slave_xmit()
1120 cppi5_desc_set_pktids(&first_desc->hdr, 0, 0x3FFF); in am65_cpsw_nuss_ndo_slave_xmit()
1122 cppi5_desc_set_tags_ids(&first_desc->hdr, 0, port->port_id); in am65_cpsw_nuss_ndo_slave_xmit()
1124 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &buf_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1132 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { in am65_cpsw_nuss_ndo_slave_xmit()
1136 cs_offset = cs_start + skb->csum_offset; in am65_cpsw_nuss_ndo_slave_xmit()
1139 ((cs_start + 1) << 16) | (skb->len - cs_start); in am65_cpsw_nuss_ndo_slave_xmit()
1150 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in am65_cpsw_nuss_ndo_slave_xmit()
1151 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in am65_cpsw_nuss_ndo_slave_xmit()
1154 next_desc = k3_cppi_desc_pool_alloc(tx_chn->desc_pool); in am65_cpsw_nuss_ndo_slave_xmit()
1160 buf_dma = skb_frag_dma_map(tx_chn->dma_dev, frag, 0, frag_size, in am65_cpsw_nuss_ndo_slave_xmit()
1162 if (unlikely(dma_mapping_error(tx_chn->dma_dev, buf_dma))) { in am65_cpsw_nuss_ndo_slave_xmit()
1164 k3_cppi_desc_pool_free(tx_chn->desc_pool, next_desc); in am65_cpsw_nuss_ndo_slave_xmit()
1165 ndev->stats.tx_errors++; in am65_cpsw_nuss_ndo_slave_xmit()
1170 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &buf_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1174 desc_dma = k3_cppi_desc_pool_virt2dma(tx_chn->desc_pool, in am65_cpsw_nuss_ndo_slave_xmit()
1176 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &desc_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1182 WARN_ON(pkt_len != skb->len); in am65_cpsw_nuss_ndo_slave_xmit()
1191 desc_dma = k3_cppi_desc_pool_virt2dma(tx_chn->desc_pool, first_desc); in am65_cpsw_nuss_ndo_slave_xmit()
1193 ret = k3_udma_glue_push_tx_chn(tx_chn->tx_chn, first_desc, desc_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1195 spin_lock_bh(&tx_chn->lock); in am65_cpsw_nuss_ndo_slave_xmit()
1196 ret = k3_udma_glue_push_tx_chn(tx_chn->tx_chn, first_desc, desc_dma); in am65_cpsw_nuss_ndo_slave_xmit()
1197 spin_unlock_bh(&tx_chn->lock); in am65_cpsw_nuss_ndo_slave_xmit()
1203 ndev->stats.tx_errors++; in am65_cpsw_nuss_ndo_slave_xmit()
1207 if (k3_cppi_desc_pool_avail(tx_chn->desc_pool) < MAX_SKB_FRAGS) { in am65_cpsw_nuss_ndo_slave_xmit()
1213 /* re-check for smp */ in am65_cpsw_nuss_ndo_slave_xmit()
1214 if (k3_cppi_desc_pool_avail(tx_chn->desc_pool) >= in am65_cpsw_nuss_ndo_slave_xmit()
1226 ndev->stats.tx_dropped++; in am65_cpsw_nuss_ndo_slave_xmit()
1249 ret = pm_runtime_resume_and_get(common->dev); in am65_cpsw_nuss_ndo_slave_set_mac_address()
1253 cpsw_ale_del_ucast(common->ale, ndev->dev_addr, in am65_cpsw_nuss_ndo_slave_set_mac_address()
1255 cpsw_ale_add_ucast(common->ale, sockaddr->sa_data, in am65_cpsw_nuss_ndo_slave_set_mac_address()
1261 pm_runtime_put(common->dev); in am65_cpsw_nuss_ndo_slave_set_mac_address()
1275 return -EOPNOTSUPP; in am65_cpsw_nuss_hwtstamp_set()
1277 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) in am65_cpsw_nuss_hwtstamp_set()
1278 return -EFAULT; in am65_cpsw_nuss_hwtstamp_set()
1286 return -ERANGE; in am65_cpsw_nuss_hwtstamp_set()
1291 port->rx_ts_enabled = false; in am65_cpsw_nuss_hwtstamp_set()
1308 port->rx_ts_enabled = true; in am65_cpsw_nuss_hwtstamp_set()
1312 return -ERANGE; in am65_cpsw_nuss_hwtstamp_set()
1315 port->tx_ts_enabled = (cfg.tx_type == HWTSTAMP_TX_ON); in am65_cpsw_nuss_hwtstamp_set()
1336 if (port->tx_ts_enabled) in am65_cpsw_nuss_hwtstamp_set()
1340 writel(seq_id, port->port_base + AM65_CPSW_PORTN_REG_TS_SEQ_LTYPE_REG); in am65_cpsw_nuss_hwtstamp_set()
1341 writel(ts_vlan_ltype, port->port_base + in am65_cpsw_nuss_hwtstamp_set()
1343 writel(ts_ctrl_ltype2, port->port_base + in am65_cpsw_nuss_hwtstamp_set()
1345 writel(ts_ctrl, port->port_base + AM65_CPSW_PORTN_REG_TS_CTL); in am65_cpsw_nuss_hwtstamp_set()
1348 am65_cpts_rx_enable(common->cpts, port->rx_ts_enabled); in am65_cpsw_nuss_hwtstamp_set()
1350 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; in am65_cpsw_nuss_hwtstamp_set()
1360 return -EOPNOTSUPP; in am65_cpsw_nuss_hwtstamp_get()
1363 cfg.tx_type = port->tx_ts_enabled ? in am65_cpsw_nuss_hwtstamp_get()
1365 cfg.rx_filter = port->rx_ts_enabled ? in am65_cpsw_nuss_hwtstamp_get()
1368 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; in am65_cpsw_nuss_hwtstamp_get()
1377 return -EINVAL; in am65_cpsw_nuss_ndo_slave_ioctl()
1386 return phylink_mii_ioctl(port->slave.phylink, req, cmd); in am65_cpsw_nuss_ndo_slave_ioctl()
1403 cpu_stats = per_cpu_ptr(ndev_priv->stats, cpu); in am65_cpsw_nuss_ndo_get_stats()
1405 start = u64_stats_fetch_begin(&cpu_stats->syncp); in am65_cpsw_nuss_ndo_get_stats()
1406 rx_packets = cpu_stats->rx_packets; in am65_cpsw_nuss_ndo_get_stats()
1407 rx_bytes = cpu_stats->rx_bytes; in am65_cpsw_nuss_ndo_get_stats()
1408 tx_packets = cpu_stats->tx_packets; in am65_cpsw_nuss_ndo_get_stats()
1409 tx_bytes = cpu_stats->tx_bytes; in am65_cpsw_nuss_ndo_get_stats()
1410 } while (u64_stats_fetch_retry(&cpu_stats->syncp, start)); in am65_cpsw_nuss_ndo_get_stats()
1412 stats->rx_packets += rx_packets; in am65_cpsw_nuss_ndo_get_stats()
1413 stats->rx_bytes += rx_bytes; in am65_cpsw_nuss_ndo_get_stats()
1414 stats->tx_packets += tx_packets; in am65_cpsw_nuss_ndo_get_stats()
1415 stats->tx_bytes += tx_bytes; in am65_cpsw_nuss_ndo_get_stats()
1418 stats->rx_errors = dev->stats.rx_errors; in am65_cpsw_nuss_ndo_get_stats()
1419 stats->rx_dropped = dev->stats.rx_dropped; in am65_cpsw_nuss_ndo_get_stats()
1420 stats->tx_dropped = dev->stats.tx_dropped; in am65_cpsw_nuss_ndo_get_stats()
1468 for (i = 0; i < common->port_num; i++) { in am65_cpsw_disable_serdes_phy()
1469 port = &common->ports[i]; in am65_cpsw_disable_serdes_phy()
1470 phy = port->slave.serdes_phy; in am65_cpsw_disable_serdes_phy()
1488 port->slave.serdes_phy = phy; in am65_cpsw_init_serdes_phy()
1507 struct am65_cpsw_common *common = port->common; in am65_cpsw_nuss_mac_config()
1509 if (common->pdata.extra_modes & BIT(state->interface)) { in am65_cpsw_nuss_mac_config()
1510 if (state->interface == PHY_INTERFACE_MODE_SGMII) { in am65_cpsw_nuss_mac_config()
1512 port->sgmii_base + AM65_CPSW_SGMII_MR_ADV_ABILITY_REG); in am65_cpsw_nuss_mac_config()
1513 cpsw_sl_ctl_set(port->slave.mac_sl, CPSW_SL_CTL_EXT_EN); in am65_cpsw_nuss_mac_config()
1515 cpsw_sl_ctl_clr(port->slave.mac_sl, CPSW_SL_CTL_EXT_EN); in am65_cpsw_nuss_mac_config()
1518 if (state->interface == PHY_INTERFACE_MODE_USXGMII) { in am65_cpsw_nuss_mac_config()
1519 cpsw_sl_ctl_set(port->slave.mac_sl, in am65_cpsw_nuss_mac_config()
1522 cpsw_sl_ctl_clr(port->slave.mac_sl, in am65_cpsw_nuss_mac_config()
1527 port->sgmii_base + AM65_CPSW_SGMII_CONTROL_REG); in am65_cpsw_nuss_mac_config()
1537 struct am65_cpsw_common *common = port->common; in am65_cpsw_nuss_mac_link_down()
1538 struct net_device *ndev = port->ndev; in am65_cpsw_nuss_mac_link_down()
1543 cpsw_ale_control_set(common->ale, port->port_id, ALE_PORT_STATE, ALE_PORT_STATE_DISABLE); in am65_cpsw_nuss_mac_link_down()
1545 cpsw_sl_ctl_set(port->slave.mac_sl, CPSW_SL_CTL_CMD_IDLE); in am65_cpsw_nuss_mac_link_down()
1547 tmo = cpsw_sl_wait_for_idle(port->slave.mac_sl, 100); in am65_cpsw_nuss_mac_link_down()
1548 dev_dbg(common->dev, "down msc_sl %08x tmo %d\n", in am65_cpsw_nuss_mac_link_down()
1549 cpsw_sl_reg_read(port->slave.mac_sl, CPSW_SL_MACSTATUS), tmo); in am65_cpsw_nuss_mac_link_down()
1558 cpsw_sl_ctl_clr(port->slave.mac_sl, mac_control); in am65_cpsw_nuss_mac_link_down()
1571 struct am65_cpsw_common *common = port->common; in am65_cpsw_nuss_mac_link_up()
1573 struct net_device *ndev = port->ndev; in am65_cpsw_nuss_mac_link_up()
1576 cpsw_sl_ctl_clr(port->slave.mac_sl, CPSW_SL_CTL_CMD_IDLE); in am65_cpsw_nuss_mac_link_up()
1580 /* TODO: Verify whether in-band is necessary for 10 Mbps RGMII */ in am65_cpsw_nuss_mac_link_up()
1596 cpsw_sl_ctl_set(port->slave.mac_sl, mac_control); in am65_cpsw_nuss_mac_link_up()
1599 cpsw_ale_control_set(common->ale, port->port_id, ALE_PORT_STATE, ALE_PORT_STATE_FORWARD); in am65_cpsw_nuss_mac_link_up()
1613 struct am65_cpsw_common *common = port->common; in am65_cpsw_nuss_slave_disable_unused()
1615 if (!port->disabled) in am65_cpsw_nuss_slave_disable_unused()
1618 cpsw_ale_control_set(common->ale, port->port_id, in am65_cpsw_nuss_slave_disable_unused()
1621 cpsw_sl_reset(port->slave.mac_sl, 100); in am65_cpsw_nuss_slave_disable_unused()
1622 cpsw_sl_ctl_reset(port->slave.mac_sl); in am65_cpsw_nuss_slave_disable_unused()
1630 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_free_tx_chns()
1631 struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i]; in am65_cpsw_nuss_free_tx_chns()
1633 if (!IS_ERR_OR_NULL(tx_chn->desc_pool)) in am65_cpsw_nuss_free_tx_chns()
1634 k3_cppi_desc_pool_destroy(tx_chn->desc_pool); in am65_cpsw_nuss_free_tx_chns()
1636 if (!IS_ERR_OR_NULL(tx_chn->tx_chn)) in am65_cpsw_nuss_free_tx_chns()
1637 k3_udma_glue_release_tx_chn(tx_chn->tx_chn); in am65_cpsw_nuss_free_tx_chns()
1645 struct device *dev = common->dev; in am65_cpsw_nuss_remove_tx_chns()
1650 common->tx_ch_rate_msk = 0; in am65_cpsw_nuss_remove_tx_chns()
1651 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_remove_tx_chns()
1652 struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i]; in am65_cpsw_nuss_remove_tx_chns()
1654 if (tx_chn->irq) in am65_cpsw_nuss_remove_tx_chns()
1655 devm_free_irq(dev, tx_chn->irq, tx_chn); in am65_cpsw_nuss_remove_tx_chns()
1657 netif_napi_del(&tx_chn->napi_tx); in am65_cpsw_nuss_remove_tx_chns()
1659 if (!IS_ERR_OR_NULL(tx_chn->desc_pool)) in am65_cpsw_nuss_remove_tx_chns()
1660 k3_cppi_desc_pool_destroy(tx_chn->desc_pool); in am65_cpsw_nuss_remove_tx_chns()
1662 if (!IS_ERR_OR_NULL(tx_chn->tx_chn)) in am65_cpsw_nuss_remove_tx_chns()
1663 k3_udma_glue_release_tx_chn(tx_chn->tx_chn); in am65_cpsw_nuss_remove_tx_chns()
1671 struct device *dev = common->dev; in am65_cpsw_nuss_ndev_add_tx_napi()
1674 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_ndev_add_tx_napi()
1675 struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i]; in am65_cpsw_nuss_ndev_add_tx_napi()
1677 netif_napi_add_tx(common->dma_ndev, &tx_chn->napi_tx, in am65_cpsw_nuss_ndev_add_tx_napi()
1680 ret = devm_request_irq(dev, tx_chn->irq, in am65_cpsw_nuss_ndev_add_tx_napi()
1683 tx_chn->tx_chn_name, tx_chn); in am65_cpsw_nuss_ndev_add_tx_napi()
1686 tx_chn->id, tx_chn->irq, ret); in am65_cpsw_nuss_ndev_add_tx_napi()
1699 struct device *dev = common->dev; in am65_cpsw_nuss_init_tx_chns()
1717 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_init_tx_chns()
1718 struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i]; in am65_cpsw_nuss_init_tx_chns()
1720 snprintf(tx_chn->tx_chn_name, in am65_cpsw_nuss_init_tx_chns()
1721 sizeof(tx_chn->tx_chn_name), "tx%d", i); in am65_cpsw_nuss_init_tx_chns()
1723 spin_lock_init(&tx_chn->lock); in am65_cpsw_nuss_init_tx_chns()
1724 tx_chn->common = common; in am65_cpsw_nuss_init_tx_chns()
1725 tx_chn->id = i; in am65_cpsw_nuss_init_tx_chns()
1726 tx_chn->descs_num = max_desc_num; in am65_cpsw_nuss_init_tx_chns()
1728 tx_chn->tx_chn = in am65_cpsw_nuss_init_tx_chns()
1730 tx_chn->tx_chn_name, in am65_cpsw_nuss_init_tx_chns()
1732 if (IS_ERR(tx_chn->tx_chn)) { in am65_cpsw_nuss_init_tx_chns()
1733 ret = dev_err_probe(dev, PTR_ERR(tx_chn->tx_chn), in am65_cpsw_nuss_init_tx_chns()
1737 tx_chn->dma_dev = k3_udma_glue_tx_get_dma_device(tx_chn->tx_chn); in am65_cpsw_nuss_init_tx_chns()
1739 tx_chn->desc_pool = k3_cppi_desc_pool_create_name(tx_chn->dma_dev, in am65_cpsw_nuss_init_tx_chns()
1740 tx_chn->descs_num, in am65_cpsw_nuss_init_tx_chns()
1742 tx_chn->tx_chn_name); in am65_cpsw_nuss_init_tx_chns()
1743 if (IS_ERR(tx_chn->desc_pool)) { in am65_cpsw_nuss_init_tx_chns()
1744 ret = PTR_ERR(tx_chn->desc_pool); in am65_cpsw_nuss_init_tx_chns()
1749 tx_chn->irq = k3_udma_glue_tx_get_irq(tx_chn->tx_chn); in am65_cpsw_nuss_init_tx_chns()
1750 if (tx_chn->irq < 0) { in am65_cpsw_nuss_init_tx_chns()
1752 tx_chn->irq); in am65_cpsw_nuss_init_tx_chns()
1753 ret = tx_chn->irq; in am65_cpsw_nuss_init_tx_chns()
1757 snprintf(tx_chn->tx_chn_name, in am65_cpsw_nuss_init_tx_chns()
1758 sizeof(tx_chn->tx_chn_name), "%s-tx%d", in am65_cpsw_nuss_init_tx_chns()
1759 dev_name(dev), tx_chn->id); in am65_cpsw_nuss_init_tx_chns()
1783 rx_chn = &common->rx_chns; in am65_cpsw_nuss_free_rx_chns()
1785 if (!IS_ERR_OR_NULL(rx_chn->desc_pool)) in am65_cpsw_nuss_free_rx_chns()
1786 k3_cppi_desc_pool_destroy(rx_chn->desc_pool); in am65_cpsw_nuss_free_rx_chns()
1788 if (!IS_ERR_OR_NULL(rx_chn->rx_chn)) in am65_cpsw_nuss_free_rx_chns()
1789 k3_udma_glue_release_rx_chn(rx_chn->rx_chn); in am65_cpsw_nuss_free_rx_chns()
1796 struct device *dev = common->dev; in am65_cpsw_nuss_remove_rx_chns()
1798 rx_chn = &common->rx_chns; in am65_cpsw_nuss_remove_rx_chns()
1801 if (!(rx_chn->irq < 0)) in am65_cpsw_nuss_remove_rx_chns()
1802 devm_free_irq(dev, rx_chn->irq, common); in am65_cpsw_nuss_remove_rx_chns()
1804 netif_napi_del(&common->napi_rx); in am65_cpsw_nuss_remove_rx_chns()
1806 if (!IS_ERR_OR_NULL(rx_chn->desc_pool)) in am65_cpsw_nuss_remove_rx_chns()
1807 k3_cppi_desc_pool_destroy(rx_chn->desc_pool); in am65_cpsw_nuss_remove_rx_chns()
1809 if (!IS_ERR_OR_NULL(rx_chn->rx_chn)) in am65_cpsw_nuss_remove_rx_chns()
1810 k3_udma_glue_release_rx_chn(rx_chn->rx_chn); in am65_cpsw_nuss_remove_rx_chns()
1812 common->rx_flow_id_base = -1; in am65_cpsw_nuss_remove_rx_chns()
1817 struct am65_cpsw_rx_chn *rx_chn = &common->rx_chns; in am65_cpsw_nuss_init_rx_chns()
1820 struct device *dev = common->dev; in am65_cpsw_nuss_init_rx_chns()
1830 rx_cfg.flow_id_base = common->rx_flow_id_base; in am65_cpsw_nuss_init_rx_chns()
1833 rx_chn->dev = dev; in am65_cpsw_nuss_init_rx_chns()
1834 rx_chn->descs_num = max_desc_num; in am65_cpsw_nuss_init_rx_chns()
1836 rx_chn->rx_chn = k3_udma_glue_request_rx_chn(dev, "rx", &rx_cfg); in am65_cpsw_nuss_init_rx_chns()
1837 if (IS_ERR(rx_chn->rx_chn)) { in am65_cpsw_nuss_init_rx_chns()
1838 ret = dev_err_probe(dev, PTR_ERR(rx_chn->rx_chn), in am65_cpsw_nuss_init_rx_chns()
1842 rx_chn->dma_dev = k3_udma_glue_rx_get_dma_device(rx_chn->rx_chn); in am65_cpsw_nuss_init_rx_chns()
1844 rx_chn->desc_pool = k3_cppi_desc_pool_create_name(rx_chn->dma_dev, in am65_cpsw_nuss_init_rx_chns()
1845 rx_chn->descs_num, in am65_cpsw_nuss_init_rx_chns()
1847 if (IS_ERR(rx_chn->desc_pool)) { in am65_cpsw_nuss_init_rx_chns()
1848 ret = PTR_ERR(rx_chn->desc_pool); in am65_cpsw_nuss_init_rx_chns()
1853 common->rx_flow_id_base = in am65_cpsw_nuss_init_rx_chns()
1854 k3_udma_glue_rx_get_flow_id_base(rx_chn->rx_chn); in am65_cpsw_nuss_init_rx_chns()
1855 dev_info(dev, "set new flow-id-base %u\n", common->rx_flow_id_base); in am65_cpsw_nuss_init_rx_chns()
1879 rx_flow_cfg.rxfdq_cfg.mode = common->pdata.fdqring_mode; in am65_cpsw_nuss_init_rx_chns()
1881 ret = k3_udma_glue_rx_flow_init(rx_chn->rx_chn, in am65_cpsw_nuss_init_rx_chns()
1889 k3_udma_glue_rx_flow_get_fdq_id(rx_chn->rx_chn, in am65_cpsw_nuss_init_rx_chns()
1892 rx_chn->irq = k3_udma_glue_rx_get_irq(rx_chn->rx_chn, i); in am65_cpsw_nuss_init_rx_chns()
1894 if (rx_chn->irq <= 0) { in am65_cpsw_nuss_init_rx_chns()
1896 rx_chn->irq); in am65_cpsw_nuss_init_rx_chns()
1897 ret = -ENXIO; in am65_cpsw_nuss_init_rx_chns()
1902 netif_napi_add(common->dma_ndev, &common->napi_rx, in am65_cpsw_nuss_init_rx_chns()
1905 ret = devm_request_irq(dev, rx_chn->irq, in am65_cpsw_nuss_init_rx_chns()
1910 rx_chn->irq, ret); in am65_cpsw_nuss_init_rx_chns()
1928 host_p->common = common; in am65_cpsw_nuss_init_host_p()
1929 host_p->port_base = common->cpsw_base + AM65_CPSW_NU_PORTS_BASE; in am65_cpsw_nuss_init_host_p()
1930 host_p->stat_base = common->cpsw_base + AM65_CPSW_NU_STATS_BASE; in am65_cpsw_nuss_init_host_p()
1942 syscon = syscon_regmap_lookup_by_phandle(of_node, "ti,syscon-efuse"); in am65_cpsw_am654_get_efuse_macid()
1944 if (PTR_ERR(syscon) == -ENODEV) in am65_cpsw_am654_get_efuse_macid()
1949 ret = of_property_read_u32_index(of_node, "ti,syscon-efuse", 1, in am65_cpsw_am654_get_efuse_macid()
1969 struct device *dev = common->dev; in am65_cpsw_init_cpts()
1977 node = of_get_child_by_name(dev->of_node, "cpts"); in am65_cpsw_init_cpts()
1980 return -ENOENT; in am65_cpsw_init_cpts()
1983 reg_base = common->cpsw_base + AM65_CPSW_NU_CPTS_BASE; in am65_cpsw_init_cpts()
1992 common->cpts = cpts; in am65_cpsw_init_cpts()
1994 * K3 CPSWxG modules may completely lose context during ON->OFF in am65_cpsw_init_cpts()
2007 struct device *dev = common->dev; in am65_cpsw_nuss_init_slave_ports()
2010 node = of_get_child_by_name(dev->of_node, "ethernet-ports"); in am65_cpsw_nuss_init_slave_ports()
2012 return -ENOENT; in am65_cpsw_nuss_init_slave_ports()
2019 if (strcmp(port_np->name, "port")) in am65_cpsw_nuss_init_slave_ports()
2029 if (!port_id || port_id > common->port_num) { in am65_cpsw_nuss_init_slave_ports()
2031 port_np, port_id, port_np->name); in am65_cpsw_nuss_init_slave_ports()
2032 ret = -EINVAL; in am65_cpsw_nuss_init_slave_ports()
2037 port->port_id = port_id; in am65_cpsw_nuss_init_slave_ports()
2038 port->common = common; in am65_cpsw_nuss_init_slave_ports()
2039 port->port_base = common->cpsw_base + AM65_CPSW_NU_PORTS_BASE + in am65_cpsw_nuss_init_slave_ports()
2041 if (common->pdata.extra_modes) in am65_cpsw_nuss_init_slave_ports()
2042 port->sgmii_base = common->ss_base + AM65_CPSW_SGMII_BASE * (port_id); in am65_cpsw_nuss_init_slave_ports()
2043 port->stat_base = common->cpsw_base + AM65_CPSW_NU_STATS_BASE + in am65_cpsw_nuss_init_slave_ports()
2045 port->name = of_get_property(port_np, "label", NULL); in am65_cpsw_nuss_init_slave_ports()
2046 port->fetch_ram_base = in am65_cpsw_nuss_init_slave_ports()
2047 common->cpsw_base + AM65_CPSW_NU_FRAM_BASE + in am65_cpsw_nuss_init_slave_ports()
2048 (AM65_CPSW_NU_FRAM_PORT_OFFSET * (port_id - 1)); in am65_cpsw_nuss_init_slave_ports()
2050 port->slave.mac_sl = cpsw_sl_get("am65", dev, port->port_base); in am65_cpsw_nuss_init_slave_ports()
2051 if (IS_ERR(port->slave.mac_sl)) { in am65_cpsw_nuss_init_slave_ports()
2052 ret = PTR_ERR(port->slave.mac_sl); in am65_cpsw_nuss_init_slave_ports()
2056 port->disabled = !of_device_is_available(port_np); in am65_cpsw_nuss_init_slave_ports()
2057 if (port->disabled) { in am65_cpsw_nuss_init_slave_ports()
2058 common->disabled_ports_mask |= BIT(port->port_id); in am65_cpsw_nuss_init_slave_ports()
2062 port->slave.ifphy = devm_of_phy_get(dev, port_np, NULL); in am65_cpsw_nuss_init_slave_ports()
2063 if (IS_ERR(port->slave.ifphy)) { in am65_cpsw_nuss_init_slave_ports()
2064 ret = PTR_ERR(port->slave.ifphy); in am65_cpsw_nuss_init_slave_ports()
2075 port->slave.mac_only = in am65_cpsw_nuss_init_slave_ports()
2076 of_property_read_bool(port_np, "ti,mac-only"); in am65_cpsw_nuss_init_slave_ports()
2079 port->slave.phy_node = port_np; in am65_cpsw_nuss_init_slave_ports()
2080 ret = of_get_phy_mode(port_np, &port->slave.phy_if); in am65_cpsw_nuss_init_slave_ports()
2082 dev_err(dev, "%pOF read phy-mode err %d\n", in am65_cpsw_nuss_init_slave_ports()
2087 ret = phy_set_mode_ext(port->slave.ifphy, PHY_MODE_ETHERNET, port->slave.phy_if); in am65_cpsw_nuss_init_slave_ports()
2091 ret = of_get_mac_address(port_np, port->slave.mac_addr); in am65_cpsw_nuss_init_slave_ports()
2094 port->port_id, in am65_cpsw_nuss_init_slave_ports()
2095 port->slave.mac_addr); in am65_cpsw_nuss_init_slave_ports()
2096 if (!is_valid_ether_addr(port->slave.mac_addr)) { in am65_cpsw_nuss_init_slave_ports()
2097 eth_random_addr(port->slave.mac_addr); in am65_cpsw_nuss_init_slave_ports()
2105 if (!(~common->disabled_ports_mask & GENMASK(common->port_num, 1))) { in am65_cpsw_nuss_init_slave_ports()
2107 return -ENODEV; in am65_cpsw_nuss_init_slave_ports()
2130 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_phylink_cleanup()
2131 port = &common->ports[i]; in am65_cpsw_nuss_phylink_cleanup()
2132 if (port->slave.phylink) in am65_cpsw_nuss_phylink_cleanup()
2133 phylink_destroy(port->slave.phylink); in am65_cpsw_nuss_phylink_cleanup()
2141 struct device *dev = common->dev; in am65_cpsw_nuss_init_port_ndev()
2146 port = &common->ports[port_idx]; in am65_cpsw_nuss_init_port_ndev()
2148 if (port->disabled) in am65_cpsw_nuss_init_port_ndev()
2152 port->ndev = devm_alloc_etherdev_mqs(common->dev, in am65_cpsw_nuss_init_port_ndev()
2156 if (!port->ndev) { in am65_cpsw_nuss_init_port_ndev()
2158 port->port_id); in am65_cpsw_nuss_init_port_ndev()
2159 return -ENOMEM; in am65_cpsw_nuss_init_port_ndev()
2162 ndev_priv = netdev_priv(port->ndev); in am65_cpsw_nuss_init_port_ndev()
2163 ndev_priv->port = port; in am65_cpsw_nuss_init_port_ndev()
2164 ndev_priv->msg_enable = AM65_CPSW_DEBUG; in am65_cpsw_nuss_init_port_ndev()
2165 SET_NETDEV_DEV(port->ndev, dev); in am65_cpsw_nuss_init_port_ndev()
2167 eth_hw_addr_set(port->ndev, port->slave.mac_addr); in am65_cpsw_nuss_init_port_ndev()
2169 port->ndev->min_mtu = AM65_CPSW_MIN_PACKET_SIZE; in am65_cpsw_nuss_init_port_ndev()
2170 port->ndev->max_mtu = AM65_CPSW_MAX_PACKET_SIZE - in am65_cpsw_nuss_init_port_ndev()
2172 port->ndev->hw_features = NETIF_F_SG | in am65_cpsw_nuss_init_port_ndev()
2176 port->ndev->features = port->ndev->hw_features | in am65_cpsw_nuss_init_port_ndev()
2178 port->ndev->vlan_features |= NETIF_F_SG; in am65_cpsw_nuss_init_port_ndev()
2179 port->ndev->netdev_ops = &am65_cpsw_nuss_netdev_ops; in am65_cpsw_nuss_init_port_ndev()
2180 port->ndev->ethtool_ops = &am65_cpsw_ethtool_ops_slave; in am65_cpsw_nuss_init_port_ndev()
2183 port->slave.phylink_config.dev = &port->ndev->dev; in am65_cpsw_nuss_init_port_ndev()
2184 port->slave.phylink_config.type = PHYLINK_NETDEV; in am65_cpsw_nuss_init_port_ndev()
2185 port->slave.phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | in am65_cpsw_nuss_init_port_ndev()
2187 port->slave.phylink_config.mac_managed_pm = true; /* MAC does PM */ in am65_cpsw_nuss_init_port_ndev()
2189 switch (port->slave.phy_if) { in am65_cpsw_nuss_init_port_ndev()
2194 phy_interface_set_rgmii(port->slave.phylink_config.supported_interfaces); in am65_cpsw_nuss_init_port_ndev()
2199 port->slave.phylink_config.supported_interfaces); in am65_cpsw_nuss_init_port_ndev()
2205 if (common->pdata.extra_modes & BIT(port->slave.phy_if)) { in am65_cpsw_nuss_init_port_ndev()
2206 __set_bit(port->slave.phy_if, in am65_cpsw_nuss_init_port_ndev()
2207 port->slave.phylink_config.supported_interfaces); in am65_cpsw_nuss_init_port_ndev()
2209 dev_err(dev, "selected phy-mode is not supported\n"); in am65_cpsw_nuss_init_port_ndev()
2210 return -EOPNOTSUPP; in am65_cpsw_nuss_init_port_ndev()
2215 dev_err(dev, "selected phy-mode is not supported\n"); in am65_cpsw_nuss_init_port_ndev()
2216 return -EOPNOTSUPP; in am65_cpsw_nuss_init_port_ndev()
2219 phylink = phylink_create(&port->slave.phylink_config, in am65_cpsw_nuss_init_port_ndev()
2220 of_node_to_fwnode(port->slave.phy_node), in am65_cpsw_nuss_init_port_ndev()
2221 port->slave.phy_if, in am65_cpsw_nuss_init_port_ndev()
2226 port->slave.phylink = phylink; in am65_cpsw_nuss_init_port_ndev()
2229 if (common->pdata.quirks & AM65_CPSW_QUIRK_I2027_NO_TX_CSUM) in am65_cpsw_nuss_init_port_ndev()
2230 port->ndev->features &= ~NETIF_F_HW_CSUM; in am65_cpsw_nuss_init_port_ndev()
2232 ndev_priv->stats = netdev_alloc_pcpu_stats(struct am65_cpsw_ndev_stats); in am65_cpsw_nuss_init_port_ndev()
2233 if (!ndev_priv->stats) in am65_cpsw_nuss_init_port_ndev()
2234 return -ENOMEM; in am65_cpsw_nuss_init_port_ndev()
2237 ndev_priv->stats); in am65_cpsw_nuss_init_port_ndev()
2241 if (!common->dma_ndev) in am65_cpsw_nuss_init_port_ndev()
2242 common->dma_ndev = port->ndev; in am65_cpsw_nuss_init_port_ndev()
2252 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_init_ndevs()
2266 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_cleanup_ndev()
2267 port = &common->ports[i]; in am65_cpsw_nuss_cleanup_ndev()
2268 if (port->ndev && port->ndev->reg_state == NETREG_REGISTERED) in am65_cpsw_nuss_cleanup_ndev()
2269 unregister_netdev(port->ndev); in am65_cpsw_nuss_cleanup_ndev()
2278 if (common->br_members == (GENMASK(common->port_num, 1) & ~common->disabled_ports_mask)) in am65_cpsw_port_offload_fwd_mark_update()
2281 dev_dbg(common->dev, "set offload_fwd_mark %d\n", set_val); in am65_cpsw_port_offload_fwd_mark_update()
2283 for (i = 1; i <= common->port_num; i++) { in am65_cpsw_port_offload_fwd_mark_update()
2287 if (!port->ndev) in am65_cpsw_port_offload_fwd_mark_update()
2290 priv = am65_ndev_to_priv(port->ndev); in am65_cpsw_port_offload_fwd_mark_update()
2291 priv->offload_fwd_mark = set_val; in am65_cpsw_port_offload_fwd_mark_update()
2297 if (ndev->netdev_ops == &am65_cpsw_nuss_netdev_ops) { in am65_cpsw_port_dev_check()
2300 return !common->is_emac_mode; in am65_cpsw_port_dev_check()
2314 if (!common->br_members) { in am65_cpsw_netdevice_port_link()
2315 common->hw_bridge_dev = br_ndev; in am65_cpsw_netdevice_port_link()
2320 if (common->hw_bridge_dev != br_ndev) in am65_cpsw_netdevice_port_link()
2321 return -EOPNOTSUPP; in am65_cpsw_netdevice_port_link()
2329 common->br_members |= BIT(priv->port->port_id); in am65_cpsw_netdevice_port_link()
2343 common->br_members &= ~BIT(priv->port->port_id); in am65_cpsw_netdevice_port_unlink()
2347 if (!common->br_members) in am65_cpsw_netdevice_port_unlink()
2348 common->hw_bridge_dev = NULL; in am65_cpsw_netdevice_port_unlink()
2367 if (netif_is_bridge_master(info->upper_dev)) { in am65_cpsw_netdevice_event()
2368 if (info->linking) in am65_cpsw_netdevice_event()
2370 info->upper_dev, in am65_cpsw_netdevice_event()
2391 cpsw->am65_cpsw_netdevice_nb.notifier_call = &am65_cpsw_netdevice_event; in am65_cpsw_register_notifiers()
2392 ret = register_netdevice_notifier(&cpsw->am65_cpsw_netdevice_nb); in am65_cpsw_register_notifiers()
2394 dev_err(cpsw->dev, "can't register netdevice notifier\n"); in am65_cpsw_register_notifiers()
2400 unregister_netdevice_notifier(&cpsw->am65_cpsw_netdevice_nb); in am65_cpsw_register_notifiers()
2412 unregister_netdevice_notifier(&cpsw->am65_cpsw_netdevice_nb); in am65_cpsw_unregister_notifiers()
2419 cpsw_ale_add_mcast(cpsw->ale, eth_stp_addr, ALE_PORT_HOST, ALE_SUPER, 0, in am65_cpsw_init_stp_ale_entry()
2427 writel(common->default_vlan, host->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_init_host_port_switch()
2431 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_P0_UNI_FLOOD, 1); in am65_cpsw_init_host_port_switch()
2432 dev_dbg(common->dev, "Set P0_UNI_FLOOD\n"); in am65_cpsw_init_host_port_switch()
2433 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_PORT_NOLEARN, 0); in am65_cpsw_init_host_port_switch()
2440 writel(0, host->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_init_host_port_emac()
2442 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_P0_UNI_FLOOD, 0); in am65_cpsw_init_host_port_emac()
2443 dev_dbg(common->dev, "unset P0_UNI_FLOOD\n"); in am65_cpsw_init_host_port_emac()
2445 /* learning make no sense in multi-mac mode */ in am65_cpsw_init_host_port_emac()
2446 cpsw_ale_control_set(common->ale, HOST_PORT_NUM, ALE_PORT_NOLEARN, 1); in am65_cpsw_init_host_port_emac()
2453 struct am65_cpsw_common *common = dl_priv->common; in am65_cpsw_dl_switch_mode_get()
2455 dev_dbg(common->dev, "%s id:%u\n", __func__, id); in am65_cpsw_dl_switch_mode_get()
2458 return -EOPNOTSUPP; in am65_cpsw_dl_switch_mode_get()
2460 ctx->val.vbool = !common->is_emac_mode; in am65_cpsw_dl_switch_mode_get()
2467 struct am65_cpsw_slave_data *slave = &port->slave; in am65_cpsw_init_port_emac_ale()
2468 struct am65_cpsw_common *common = port->common; in am65_cpsw_init_port_emac_ale()
2471 writel(slave->port_vlan, port->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_init_port_emac_ale()
2473 if (slave->mac_only) in am65_cpsw_init_port_emac_ale()
2474 /* enable mac-only mode on port */ in am65_cpsw_init_port_emac_ale()
2475 cpsw_ale_control_set(common->ale, port->port_id, in am65_cpsw_init_port_emac_ale()
2478 cpsw_ale_control_set(common->ale, port->port_id, ALE_PORT_NOLEARN, 1); in am65_cpsw_init_port_emac_ale()
2480 port_mask = BIT(port->port_id) | ALE_PORT_HOST; in am65_cpsw_init_port_emac_ale()
2482 cpsw_ale_add_ucast(common->ale, port->ndev->dev_addr, in am65_cpsw_init_port_emac_ale()
2483 HOST_PORT_NUM, ALE_SECURE, slave->port_vlan); in am65_cpsw_init_port_emac_ale()
2484 cpsw_ale_add_mcast(common->ale, port->ndev->broadcast, in am65_cpsw_init_port_emac_ale()
2485 port_mask, ALE_VLAN, slave->port_vlan, ALE_MCAST_FWD_2); in am65_cpsw_init_port_emac_ale()
2490 struct am65_cpsw_slave_data *slave = &port->slave; in am65_cpsw_init_port_switch_ale()
2491 struct am65_cpsw_common *cpsw = port->common; in am65_cpsw_init_port_switch_ale()
2494 cpsw_ale_control_set(cpsw->ale, port->port_id, in am65_cpsw_init_port_switch_ale()
2497 cpsw_ale_add_ucast(cpsw->ale, port->ndev->dev_addr, in am65_cpsw_init_port_switch_ale()
2499 slave->port_vlan); in am65_cpsw_init_port_switch_ale()
2501 port_mask = BIT(port->port_id) | ALE_PORT_HOST; in am65_cpsw_init_port_switch_ale()
2503 cpsw_ale_add_mcast(cpsw->ale, port->ndev->broadcast, in am65_cpsw_init_port_switch_ale()
2504 port_mask, ALE_VLAN, slave->port_vlan, in am65_cpsw_init_port_switch_ale()
2507 writel(slave->port_vlan, port->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_init_port_switch_ale()
2509 cpsw_ale_control_set(cpsw->ale, port->port_id, in am65_cpsw_init_port_switch_ale()
2517 struct am65_cpsw_common *cpsw = dl_priv->common; in am65_cpsw_dl_switch_mode_set()
2518 bool switch_en = ctx->val.vbool; in am65_cpsw_dl_switch_mode_set()
2522 dev_dbg(cpsw->dev, "%s id:%u\n", __func__, id); in am65_cpsw_dl_switch_mode_set()
2525 return -EOPNOTSUPP; in am65_cpsw_dl_switch_mode_set()
2527 if (switch_en == !cpsw->is_emac_mode) in am65_cpsw_dl_switch_mode_set()
2530 if (!switch_en && cpsw->br_members) { in am65_cpsw_dl_switch_mode_set()
2531 dev_err(cpsw->dev, "Remove ports from bridge before disabling switch mode\n"); in am65_cpsw_dl_switch_mode_set()
2532 return -EINVAL; in am65_cpsw_dl_switch_mode_set()
2537 cpsw->is_emac_mode = !switch_en; in am65_cpsw_dl_switch_mode_set()
2539 for (i = 0; i < cpsw->port_num; i++) { in am65_cpsw_dl_switch_mode_set()
2540 struct net_device *sl_ndev = cpsw->ports[i].ndev; in am65_cpsw_dl_switch_mode_set()
2550 for (i = 0; i < cpsw->port_num; i++) { in am65_cpsw_dl_switch_mode_set()
2551 struct net_device *sl_ndev = cpsw->ports[i].ndev; in am65_cpsw_dl_switch_mode_set()
2559 slave->port_vlan = cpsw->default_vlan; in am65_cpsw_dl_switch_mode_set()
2561 slave->port_vlan = 0; in am65_cpsw_dl_switch_mode_set()
2567 cpsw_ale_control_set(cpsw->ale, 0, ALE_BYPASS, 1); in am65_cpsw_dl_switch_mode_set()
2569 cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM, ALE_CLEAR, 1); in am65_cpsw_dl_switch_mode_set()
2570 cpsw_ale_control_get(cpsw->ale, HOST_PORT_NUM, ALE_AGEOUT); in am65_cpsw_dl_switch_mode_set()
2573 dev_info(cpsw->dev, "Enable switch mode\n"); in am65_cpsw_dl_switch_mode_set()
2577 for (i = 0; i < cpsw->port_num; i++) { in am65_cpsw_dl_switch_mode_set()
2578 struct net_device *sl_ndev = cpsw->ports[i].ndev; in am65_cpsw_dl_switch_mode_set()
2587 slave->port_vlan = cpsw->default_vlan; in am65_cpsw_dl_switch_mode_set()
2594 dev_info(cpsw->dev, "Disable switch mode\n"); in am65_cpsw_dl_switch_mode_set()
2598 for (i = 0; i < cpsw->port_num; i++) { in am65_cpsw_dl_switch_mode_set()
2599 struct net_device *sl_ndev = cpsw->ports[i].ndev; in am65_cpsw_dl_switch_mode_set()
2606 port->slave.port_vlan = 0; in am65_cpsw_dl_switch_mode_set()
2611 cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM, ALE_BYPASS, 0); in am65_cpsw_dl_switch_mode_set()
2630 struct device *dev = common->dev; in am65_cpsw_nuss_register_devlink()
2636 common->devlink = in am65_cpsw_nuss_register_devlink()
2638 if (!common->devlink) in am65_cpsw_nuss_register_devlink()
2639 return -ENOMEM; in am65_cpsw_nuss_register_devlink()
2641 dl_priv = devlink_priv(common->devlink); in am65_cpsw_nuss_register_devlink()
2642 dl_priv->common = common; in am65_cpsw_nuss_register_devlink()
2649 ret = devlink_params_register(common->devlink, in am65_cpsw_nuss_register_devlink()
2658 for (i = 1; i <= common->port_num; i++) { in am65_cpsw_nuss_register_devlink()
2660 dl_port = &port->devlink_port; in am65_cpsw_nuss_register_devlink()
2662 if (port->ndev) in am65_cpsw_nuss_register_devlink()
2666 attrs.phys.port_number = port->port_id; in am65_cpsw_nuss_register_devlink()
2668 memcpy(attrs.switch_id.id, common->switch_id, attrs.switch_id.id_len); in am65_cpsw_nuss_register_devlink()
2671 ret = devlink_port_register(common->devlink, dl_port, port->port_id); in am65_cpsw_nuss_register_devlink()
2674 port->port_id, ret); in am65_cpsw_nuss_register_devlink()
2678 devlink_register(common->devlink); in am65_cpsw_nuss_register_devlink()
2682 for (i = i - 1; i >= 1; i--) { in am65_cpsw_nuss_register_devlink()
2684 dl_port = &port->devlink_port; in am65_cpsw_nuss_register_devlink()
2689 devlink_free(common->devlink); in am65_cpsw_nuss_register_devlink()
2699 devlink_unregister(common->devlink); in am65_cpsw_unregister_devlink()
2701 for (i = 1; i <= common->port_num; i++) { in am65_cpsw_unregister_devlink()
2703 dl_port = &port->devlink_port; in am65_cpsw_unregister_devlink()
2710 devlink_params_unregister(common->devlink, in am65_cpsw_unregister_devlink()
2714 devlink_free(common->devlink); in am65_cpsw_unregister_devlink()
2719 struct am65_cpsw_rx_chn *rx_chan = &common->rx_chns; in am65_cpsw_nuss_register_ndevs()
2720 struct am65_cpsw_tx_chn *tx_chan = common->tx_chns; in am65_cpsw_nuss_register_ndevs()
2721 struct device *dev = common->dev; in am65_cpsw_nuss_register_ndevs()
2737 for (i = 0; i < common->tx_ch_num; i++) { in am65_cpsw_nuss_register_ndevs()
2744 k3_udma_glue_reset_rx_chn(rx_chan->rx_chn, i, rx_chan, in am65_cpsw_nuss_register_ndevs()
2747 k3_udma_glue_disable_rx_chn(rx_chan->rx_chn); in am65_cpsw_nuss_register_ndevs()
2753 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_register_ndevs()
2754 port = &common->ports[i]; in am65_cpsw_nuss_register_ndevs()
2756 if (!port->ndev) in am65_cpsw_nuss_register_ndevs()
2759 SET_NETDEV_DEVLINK_PORT(port->ndev, &port->devlink_port); in am65_cpsw_nuss_register_ndevs()
2761 ret = register_netdev(port->ndev); in am65_cpsw_nuss_register_ndevs()
2790 common->tx_ch_num = num_tx; in am65_cpsw_nuss_update_tx_chns()
2814 .ale_dev_id = "am65x-cpsw2g",
2820 .ale_dev_id = "am65x-cpsw2g",
2826 .ale_dev_id = "am64-cpswxg",
2832 .ale_dev_id = "am64-cpswxg",
2839 .ale_dev_id = "am64-cpswxg",
2846 .ale_dev_id = "am64-cpswxg",
2852 { .compatible = "ti,am654-cpsw-nuss", .data = &am65x_sr1_0},
2853 { .compatible = "ti,j721e-cpsw-nuss", .data = &j721e_pdata},
2854 { .compatible = "ti,am642-cpsw-nuss", .data = &am64x_cpswxg_pdata},
2855 { .compatible = "ti,j7200-cpswxg-nuss", .data = &j7200_cpswxg_pdata},
2856 { .compatible = "ti,j721e-cpswxg-nuss", .data = &j721e_cpswxg_pdata},
2857 { .compatible = "ti,j784s4-cpswxg-nuss", .data = &j784s4_cpswxg_pdata},
2867 if (soc && soc->data) { in am65_cpsw_nuss_apply_socinfo()
2868 const struct am65_cpsw_soc_pdata *socdata = soc->data; in am65_cpsw_nuss_apply_socinfo()
2871 common->pdata.quirks &= ~socdata->quirks_dis; in am65_cpsw_nuss_apply_socinfo()
2879 struct device *dev = &pdev->dev; in am65_cpsw_nuss_probe()
2890 return -ENOMEM; in am65_cpsw_nuss_probe()
2891 common->dev = dev; in am65_cpsw_nuss_probe()
2895 return -EINVAL; in am65_cpsw_nuss_probe()
2896 common->pdata = *(const struct am65_cpsw_pdata *)of_id->data; in am65_cpsw_nuss_probe()
2901 common->ss_base = devm_ioremap_resource(&pdev->dev, res); in am65_cpsw_nuss_probe()
2902 if (IS_ERR(common->ss_base)) in am65_cpsw_nuss_probe()
2903 return PTR_ERR(common->ss_base); in am65_cpsw_nuss_probe()
2904 common->cpsw_base = common->ss_base + AM65_CPSW_CPSW_NU_BASE; in am65_cpsw_nuss_probe()
2906 id_temp = cpu_to_be64(res->start); in am65_cpsw_nuss_probe()
2907 memcpy(common->switch_id, &id_temp, sizeof(res->start)); in am65_cpsw_nuss_probe()
2909 node = of_get_child_by_name(dev->of_node, "ethernet-ports"); in am65_cpsw_nuss_probe()
2911 return -ENOENT; in am65_cpsw_nuss_probe()
2912 common->port_num = of_get_child_count(node); in am65_cpsw_nuss_probe()
2914 if (common->port_num < 1 || common->port_num > AM65_CPSW_MAX_PORTS) in am65_cpsw_nuss_probe()
2915 return -ENOENT; in am65_cpsw_nuss_probe()
2917 common->rx_flow_id_base = -1; in am65_cpsw_nuss_probe()
2918 init_completion(&common->tdown_complete); in am65_cpsw_nuss_probe()
2919 common->tx_ch_num = 1; in am65_cpsw_nuss_probe()
2920 common->pf_p0_rx_ptype_rrobin = false; in am65_cpsw_nuss_probe()
2921 common->default_vlan = 1; in am65_cpsw_nuss_probe()
2923 common->ports = devm_kcalloc(dev, common->port_num, in am65_cpsw_nuss_probe()
2924 sizeof(*common->ports), in am65_cpsw_nuss_probe()
2926 if (!common->ports) in am65_cpsw_nuss_probe()
2927 return -ENOMEM; in am65_cpsw_nuss_probe()
2932 common->bus_freq = clk_get_rate(clk); in am65_cpsw_nuss_probe()
2941 node = of_get_child_by_name(dev->of_node, "mdio"); in am65_cpsw_nuss_probe()
2949 ret = -ENODEV; in am65_cpsw_nuss_probe()
2953 common->mdio_dev = &mdio_pdev->dev; in am65_cpsw_nuss_probe()
2970 ale_params.ale_ports = common->port_num + 1; in am65_cpsw_nuss_probe()
2971 ale_params.ale_regs = common->cpsw_base + AM65_CPSW_NU_ALE_BASE; in am65_cpsw_nuss_probe()
2972 ale_params.dev_id = common->pdata.ale_dev_id; in am65_cpsw_nuss_probe()
2973 ale_params.bus_freq = common->bus_freq; in am65_cpsw_nuss_probe()
2975 common->ale = cpsw_ale_create(&ale_params); in am65_cpsw_nuss_probe()
2976 if (IS_ERR(common->ale)) { in am65_cpsw_nuss_probe()
2978 ret = PTR_ERR(common->ale); in am65_cpsw_nuss_probe()
2982 ale_entries = common->ale->params.ale_entries; in am65_cpsw_nuss_probe()
2983 common->ale_context = devm_kzalloc(dev, in am65_cpsw_nuss_probe()
2991 for (i = 0; i < common->port_num; i++) in am65_cpsw_nuss_probe()
2992 am65_cpsw_nuss_slave_disable_unused(&common->ports[i]); in am65_cpsw_nuss_probe()
2996 common->is_emac_mode = true; in am65_cpsw_nuss_probe()
3011 am65_cpts_release(common->cpts); in am65_cpsw_nuss_probe()
3013 if (common->mdio_dev) in am65_cpsw_nuss_probe()
3014 of_platform_device_destroy(common->mdio_dev, NULL); in am65_cpsw_nuss_probe()
3023 struct device *dev = &pdev->dev; in am65_cpsw_nuss_remove()
3029 ret = pm_runtime_resume_and_get(&pdev->dev); in am65_cpsw_nuss_remove()
3041 am65_cpts_release(common->cpts); in am65_cpsw_nuss_remove()
3044 if (common->mdio_dev) in am65_cpsw_nuss_remove()
3045 of_platform_device_destroy(common->mdio_dev, NULL); in am65_cpsw_nuss_remove()
3047 pm_runtime_put_sync(&pdev->dev); in am65_cpsw_nuss_remove()
3048 pm_runtime_disable(&pdev->dev); in am65_cpsw_nuss_remove()
3060 cpsw_ale_dump(common->ale, common->ale_context); in am65_cpsw_nuss_suspend()
3061 host_p->vid_context = readl(host_p->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_nuss_suspend()
3062 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_suspend()
3063 port = &common->ports[i]; in am65_cpsw_nuss_suspend()
3064 ndev = port->ndev; in am65_cpsw_nuss_suspend()
3069 port->vid_context = readl(port->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_nuss_suspend()
3082 am65_cpts_suspend(common->cpts); in am65_cpsw_nuss_suspend()
3105 /* If RX IRQ was disabled before suspend, keep it disabled */ in am65_cpsw_nuss_resume()
3106 if (common->rx_irq_disabled) in am65_cpsw_nuss_resume()
3107 disable_irq(common->rx_chns.irq); in am65_cpsw_nuss_resume()
3109 am65_cpts_resume(common->cpts); in am65_cpsw_nuss_resume()
3111 for (i = 0; i < common->port_num; i++) { in am65_cpsw_nuss_resume()
3112 port = &common->ports[i]; in am65_cpsw_nuss_resume()
3113 ndev = port->ndev; in am65_cpsw_nuss_resume()
3129 writel(port->vid_context, port->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_nuss_resume()
3132 writel(host_p->vid_context, host_p->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET); in am65_cpsw_nuss_resume()
3133 cpsw_ale_restore(common->ale, common->ale_context); in am65_cpsw_nuss_resume()