Lines Matching +full:dra7 +full:- +full:cpsw +full:- +full:switch

1 // SPDX-License-Identifier: GPL-2.0
3 * Texas Instruments Ethernet Switch Driver
41 #include "cpsw.h"
52 MODULE_PARM_DESC(debug_level, "cpsw debug level (NETIF_MSG bits)");
56 MODULE_PARM_DESC(ale_ageout, "cpsw ale ageout interval (seconds)");
69 struct cpsw_common *cpsw = (priv)->cpsw; \
71 if (cpsw->data.dual_emac) \
72 (func)((cpsw)->slaves + priv->emac_port, ##arg);\
74 for (n = cpsw->data.slaves, \
75 slave = cpsw->slaves; \
76 n; n--) \
80 static int cpsw_slave_index_priv(struct cpsw_common *cpsw, in cpsw_slave_index_priv() argument
83 return cpsw->data.dual_emac ? priv->emac_port : cpsw->data.active_slave; in cpsw_slave_index_priv()
96 struct cpsw_common *cpsw = ndev_to_cpsw(ndev); in cpsw_set_promiscious() local
97 struct cpsw_ale *ale = cpsw->ale; in cpsw_set_promiscious()
100 if (cpsw->data.dual_emac) { in cpsw_set_promiscious()
107 for (i = 0; i < cpsw->data.slaves; i++) in cpsw_set_promiscious()
108 if (cpsw->slaves[i].ndev->flags & IFF_PROMISC) in cpsw_set_promiscious()
113 …dev_err(&ndev->dev, "promiscuity not disabled as the other interface is still in promiscuity mode\… in cpsw_set_promiscious()
120 dev_dbg(&ndev->dev, "promiscuity enabled\n"); in cpsw_set_promiscious()
124 dev_dbg(&ndev->dev, "promiscuity disabled\n"); in cpsw_set_promiscious()
131 for (i = 0; i <= cpsw->data.slaves; i++) { in cpsw_set_promiscious()
148 cpsw_ale_flush_multicast(ale, ALE_ALL_PORTS, -1); in cpsw_set_promiscious()
149 __hw_addr_ref_unsync_dev(&ndev->mc, ndev, NULL); in cpsw_set_promiscious()
153 dev_dbg(&ndev->dev, "promiscuity enabled\n"); in cpsw_set_promiscious()
159 for (i = 0; i <= cpsw->data.slaves; i++) { in cpsw_set_promiscious()
165 dev_dbg(&ndev->dev, "promiscuity disabled\n"); in cpsw_set_promiscious()
171 * cpsw_set_mc - adds multicast entry to the table if it's not added or deletes
182 struct cpsw_common *cpsw = priv->cpsw; in cpsw_set_mc() local
186 if (cpsw->data.dual_emac) in cpsw_set_mc()
187 vid = cpsw->slaves[priv->emac_port].port_vlan; in cpsw_set_mc()
192 mask = cpsw->data.dual_emac ? ALE_PORT_HOST : ALE_ALL_PORTS; in cpsw_set_mc()
196 ret = cpsw_ale_add_mcast(cpsw->ale, addr, mask, flags, vid, 0); in cpsw_set_mc()
198 ret = cpsw_ale_del_mcast(cpsw->ale, addr, 0, flags, vid); in cpsw_set_mc()
209 if (!vdev || !(vdev->flags & IFF_UP)) in cpsw_update_vlan_mc()
214 if (ether_addr_equal(ha->addr, sync_ctx->addr)) { in cpsw_update_vlan_mc()
215 found = ha->sync_cnt; in cpsw_update_vlan_mc()
221 sync_ctx->consumed++; in cpsw_update_vlan_mc()
223 if (sync_ctx->flush) { in cpsw_update_vlan_mc()
225 cpsw_set_mc(sync_ctx->ndev, sync_ctx->addr, vid, 0); in cpsw_update_vlan_mc()
230 ret = cpsw_set_mc(sync_ctx->ndev, sync_ctx->addr, vid, 1); in cpsw_update_vlan_mc()
247 ret = cpsw_set_mc(ndev, addr, -1, 1); in cpsw_add_mc_addr()
263 cpsw_set_mc(ndev, addr, -1, 0); in cpsw_del_mc_addr()
274 if (!vdev || !(vdev->flags & IFF_UP)) in cpsw_purge_vlan_mc()
279 if (ether_addr_equal(ha->addr, sync_ctx->addr)) { in cpsw_purge_vlan_mc()
280 found = ha->sync_cnt; in cpsw_purge_vlan_mc()
288 sync_ctx->consumed++; in cpsw_purge_vlan_mc()
289 cpsw_set_mc(sync_ctx->ndev, sync_ctx->addr, vid, 0); in cpsw_purge_vlan_mc()
303 cpsw_set_mc(ndev, addr, -1, 0); in cpsw_purge_all_mc()
311 struct cpsw_common *cpsw = priv->cpsw; in cpsw_ndo_set_rx_mode() local
312 int slave_port = -1; in cpsw_ndo_set_rx_mode()
314 if (cpsw->data.dual_emac) in cpsw_ndo_set_rx_mode()
315 slave_port = priv->emac_port + 1; in cpsw_ndo_set_rx_mode()
317 if (ndev->flags & IFF_PROMISC) { in cpsw_ndo_set_rx_mode()
320 cpsw_ale_set_allmulti(cpsw->ale, IFF_ALLMULTI, slave_port); in cpsw_ndo_set_rx_mode()
328 cpsw_ale_set_allmulti(cpsw->ale, in cpsw_ndo_set_rx_mode()
329 ndev->flags & IFF_ALLMULTI, slave_port); in cpsw_ndo_set_rx_mode()
332 __hw_addr_ref_sync_dev(&ndev->mc, ndev, cpsw_add_mc_addr, in cpsw_ndo_set_rx_mode()
349 struct cpsw_common *cpsw = ndev_to_cpsw(xmeta->ndev); in cpsw_rx_handler() local
350 int pkt_size = cpsw->rx_packet_max; in cpsw_rx_handler()
351 int ret = 0, port, ch = xmeta->ch; in cpsw_rx_handler()
353 struct net_device *ndev = xmeta->ndev; in cpsw_rx_handler()
360 if (cpsw->data.dual_emac && status >= 0) { in cpsw_rx_handler()
363 ndev = cpsw->slaves[--port].ndev; in cpsw_rx_handler()
367 pool = cpsw->page_pool[ch]; in cpsw_rx_handler()
370 if (cpsw->data.dual_emac && cpsw->usage_count && in cpsw_rx_handler()
390 ndev->stats.rx_dropped++; in cpsw_rx_handler()
394 if (priv->xdp_prog) { in cpsw_rx_handler()
397 xdp_init_buff(&xdp, PAGE_SIZE, &priv->xdp_rxq[ch]); in cpsw_rx_handler()
400 size -= CPSW_RX_VLAN_ENCAP_HDR_SIZE; in cpsw_rx_handler()
405 port = priv->emac_port + cpsw->data.dual_emac; in cpsw_rx_handler()
410 headroom = xdp.data - xdp.data_hard_start; in cpsw_rx_handler()
419 ndev->stats.rx_dropped++; in cpsw_rx_handler()
426 skb->dev = ndev; in cpsw_rx_handler()
429 if (priv->rx_ts_enabled) in cpsw_rx_handler()
430 cpts_rx_timestamp(cpsw->cpts, skb); in cpsw_rx_handler()
431 skb->protocol = eth_type_trans(skb, ndev); in cpsw_rx_handler()
437 ndev->stats.rx_bytes += len; in cpsw_rx_handler()
438 ndev->stats.rx_packets++; in cpsw_rx_handler()
442 xmeta->ndev = ndev; in cpsw_rx_handler()
443 xmeta->ch = ch; in cpsw_rx_handler()
446 ret = cpdma_chan_submit_mapped(cpsw->rxv[ch].ch, new_page, dma, in cpsw_rx_handler()
449 WARN_ON(ret == -ENOMEM); in cpsw_rx_handler()
457 struct phy_device *phy = slave->phy; in _cpsw_adjust_link()
460 struct cpsw_common *cpsw = priv->cpsw; in _cpsw_adjust_link() local
465 slave_port = cpsw_get_slave_port(slave->slave_num); in _cpsw_adjust_link()
467 if (phy->link) { in _cpsw_adjust_link()
470 if (phy->speed == 1000) in _cpsw_adjust_link()
472 if (phy->duplex) in _cpsw_adjust_link()
476 if (phy->speed == 100) in _cpsw_adjust_link()
479 else if ((phy->speed == 10) && phy_interface_is_rgmii(phy)) in _cpsw_adjust_link()
482 if (priv->rx_pause) in _cpsw_adjust_link()
485 if (priv->tx_pause) in _cpsw_adjust_link()
488 if (mac_control != slave->mac_control) in _cpsw_adjust_link()
489 cpsw_sl_ctl_set(slave->mac_sl, mac_control); in _cpsw_adjust_link()
492 cpsw_ale_control_set(cpsw->ale, slave_port, in _cpsw_adjust_link()
497 if (priv->shp_cfg_speed && in _cpsw_adjust_link()
498 priv->shp_cfg_speed != slave->phy->speed && in _cpsw_adjust_link()
500 dev_warn(priv->dev, in _cpsw_adjust_link()
505 cpsw_ale_control_set(cpsw->ale, slave_port, in _cpsw_adjust_link()
508 cpsw_sl_wait_for_idle(slave->mac_sl, 100); in _cpsw_adjust_link()
510 cpsw_sl_ctl_reset(slave->mac_sl); in _cpsw_adjust_link()
513 if (mac_control != slave->mac_control) in _cpsw_adjust_link()
516 slave->mac_control = mac_control; in _cpsw_adjust_link()
522 struct cpsw_common *cpsw = priv->cpsw; in cpsw_adjust_link() local
528 if (cpsw_need_resplit(cpsw)) in cpsw_adjust_link()
529 cpsw_split_res(cpsw); in cpsw_adjust_link()
544 struct cpsw_common *cpsw = priv->cpsw; in cpsw_add_dual_emac_def_ale_entries() local
547 if (cpsw->version == CPSW_VERSION_1) in cpsw_add_dual_emac_def_ale_entries()
548 slave_write(slave, slave->port_vlan, CPSW1_PORT_VLAN); in cpsw_add_dual_emac_def_ale_entries()
550 slave_write(slave, slave->port_vlan, CPSW2_PORT_VLAN); in cpsw_add_dual_emac_def_ale_entries()
551 cpsw_ale_add_vlan(cpsw->ale, slave->port_vlan, port_mask, in cpsw_add_dual_emac_def_ale_entries()
553 cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast, in cpsw_add_dual_emac_def_ale_entries()
554 ALE_PORT_HOST, ALE_VLAN, slave->port_vlan, 0); in cpsw_add_dual_emac_def_ale_entries()
555 cpsw_ale_add_ucast(cpsw->ale, priv->mac_addr, in cpsw_add_dual_emac_def_ale_entries()
557 ALE_SECURE, slave->port_vlan); in cpsw_add_dual_emac_def_ale_entries()
558 cpsw_ale_control_set(cpsw->ale, slave_port, in cpsw_add_dual_emac_def_ale_entries()
566 struct cpsw_common *cpsw = priv->cpsw; in cpsw_slave_open() local
568 cpsw_sl_reset(slave->mac_sl, 100); in cpsw_slave_open()
569 cpsw_sl_ctl_reset(slave->mac_sl); in cpsw_slave_open()
572 cpsw_sl_reg_write(slave->mac_sl, CPSW_SL_RX_PRI_MAP, in cpsw_slave_open()
575 switch (cpsw->version) { in cpsw_slave_open()
599 cpsw_sl_reg_write(slave->mac_sl, CPSW_SL_RX_MAXLEN, in cpsw_slave_open()
600 cpsw->rx_packet_max); in cpsw_slave_open()
603 slave->mac_control = 0; /* no link yet */ in cpsw_slave_open()
605 slave_port = cpsw_get_slave_port(slave->slave_num); in cpsw_slave_open()
607 if (cpsw->data.dual_emac) in cpsw_slave_open()
610 cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast, in cpsw_slave_open()
613 if (slave->data->phy_node) { in cpsw_slave_open()
614 phy = of_phy_connect(priv->ndev, slave->data->phy_node, in cpsw_slave_open()
615 &cpsw_adjust_link, 0, slave->data->phy_if); in cpsw_slave_open()
617 dev_err(priv->dev, "phy \"%pOF\" not found on slave %d\n", in cpsw_slave_open()
618 slave->data->phy_node, in cpsw_slave_open()
619 slave->slave_num); in cpsw_slave_open()
623 phy = phy_connect(priv->ndev, slave->data->phy_id, in cpsw_slave_open()
624 &cpsw_adjust_link, slave->data->phy_if); in cpsw_slave_open()
626 dev_err(priv->dev, in cpsw_slave_open()
628 slave->data->phy_id, slave->slave_num, in cpsw_slave_open()
634 phy->mac_managed_pm = true; in cpsw_slave_open()
636 slave->phy = phy; in cpsw_slave_open()
638 phy_attached_info(slave->phy); in cpsw_slave_open()
640 phy_start(slave->phy); in cpsw_slave_open()
643 if (!IS_ERR(slave->data->ifphy)) in cpsw_slave_open()
644 phy_set_mode_ext(slave->data->ifphy, PHY_MODE_ETHERNET, in cpsw_slave_open()
645 slave->data->phy_if); in cpsw_slave_open()
647 cpsw_phy_sel(cpsw->dev, slave->phy->interface, in cpsw_slave_open()
648 slave->slave_num); in cpsw_slave_open()
653 struct cpsw_common *cpsw = priv->cpsw; in cpsw_add_default_vlan() local
654 const int vlan = cpsw->data.default_vlan; in cpsw_add_default_vlan()
659 reg = (cpsw->version == CPSW_VERSION_1) ? CPSW1_PORT_VLAN : in cpsw_add_default_vlan()
662 writel(vlan, &cpsw->host_port_regs->port_vlan); in cpsw_add_default_vlan()
664 for (i = 0; i < cpsw->data.slaves; i++) in cpsw_add_default_vlan()
665 slave_write(cpsw->slaves + i, vlan, reg); in cpsw_add_default_vlan()
667 if (priv->ndev->flags & IFF_ALLMULTI) in cpsw_add_default_vlan()
672 cpsw_ale_add_vlan(cpsw->ale, vlan, ALE_ALL_PORTS, in cpsw_add_default_vlan()
681 struct cpsw_common *cpsw = priv->cpsw; in cpsw_init_host_port() local
684 soft_reset("cpsw", &cpsw->regs->soft_reset); in cpsw_init_host_port()
685 cpsw_ale_start(cpsw->ale); in cpsw_init_host_port()
687 /* switch to vlan unaware mode */ in cpsw_init_host_port()
688 cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM, ALE_VLAN_AWARE, in cpsw_init_host_port()
690 control_reg = readl(&cpsw->regs->control); in cpsw_init_host_port()
692 writel(control_reg, &cpsw->regs->control); in cpsw_init_host_port()
693 fifo_mode = (cpsw->data.dual_emac) ? CPSW_FIFO_DUAL_MAC_MODE : in cpsw_init_host_port()
695 writel(fifo_mode, &cpsw->host_port_regs->tx_in_ctl); in cpsw_init_host_port()
699 &cpsw->host_port_regs->cpdma_tx_pri_map); in cpsw_init_host_port()
700 writel_relaxed(0, &cpsw->host_port_regs->cpdma_rx_chan_map); in cpsw_init_host_port()
702 cpsw_ale_control_set(cpsw->ale, HOST_PORT_NUM, in cpsw_init_host_port()
705 if (!cpsw->data.dual_emac) { in cpsw_init_host_port()
706 cpsw_ale_add_ucast(cpsw->ale, priv->mac_addr, HOST_PORT_NUM, in cpsw_init_host_port()
708 cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast, in cpsw_init_host_port()
713 static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_common *cpsw) in cpsw_slave_stop() argument
717 slave_port = cpsw_get_slave_port(slave->slave_num); in cpsw_slave_stop()
719 if (!slave->phy) in cpsw_slave_stop()
721 phy_stop(slave->phy); in cpsw_slave_stop()
722 phy_disconnect(slave->phy); in cpsw_slave_stop()
723 slave->phy = NULL; in cpsw_slave_stop()
724 cpsw_ale_control_set(cpsw->ale, slave_port, in cpsw_slave_stop()
726 cpsw_sl_reset(slave->mac_sl, 100); in cpsw_slave_stop()
727 cpsw_sl_ctl_reset(slave->mac_sl); in cpsw_slave_stop()
737 cpsw_ndo_vlan_rx_add_vid(priv->ndev, 0, vid); in cpsw_restore_vlans()
745 vlan_for_each(priv->ndev, cpsw_restore_vlans, priv); in cpsw_restore()
757 struct cpsw_common *cpsw = priv->cpsw; in cpsw_ndo_open() local
761 ret = pm_runtime_resume_and_get(cpsw->dev); in cpsw_ndo_open()
768 ret = netif_set_real_num_tx_queues(ndev, cpsw->tx_ch_num); in cpsw_ndo_open()
770 dev_err(priv->dev, "cannot set real number of tx queues\n"); in cpsw_ndo_open()
774 ret = netif_set_real_num_rx_queues(ndev, cpsw->rx_ch_num); in cpsw_ndo_open()
776 dev_err(priv->dev, "cannot set real number of rx queues\n"); in cpsw_ndo_open()
780 reg = cpsw->version; in cpsw_ndo_open()
782 dev_info(priv->dev, "initializing cpsw version %d.%d (%d)\n", in cpsw_ndo_open()
787 if (!cpsw->usage_count) in cpsw_ndo_open()
792 if (!cpsw->data.dual_emac) in cpsw_ndo_open()
795 cpsw_ale_add_vlan(cpsw->ale, cpsw->data.default_vlan, in cpsw_ndo_open()
799 if (!cpsw->usage_count) { in cpsw_ndo_open()
801 writel_relaxed(0, &cpsw->regs->ptype); in cpsw_ndo_open()
804 writel_relaxed(0x7, &cpsw->regs->stat_port_en); in cpsw_ndo_open()
807 writel(0x7, &cpsw->regs->flow_control); in cpsw_ndo_open()
809 napi_enable(&cpsw->napi_rx); in cpsw_ndo_open()
810 napi_enable(&cpsw->napi_tx); in cpsw_ndo_open()
812 if (cpsw->tx_irq_disabled) { in cpsw_ndo_open()
813 cpsw->tx_irq_disabled = false; in cpsw_ndo_open()
814 enable_irq(cpsw->irqs_table[1]); in cpsw_ndo_open()
817 if (cpsw->rx_irq_disabled) { in cpsw_ndo_open()
818 cpsw->rx_irq_disabled = false; in cpsw_ndo_open()
819 enable_irq(cpsw->irqs_table[0]); in cpsw_ndo_open()
825 ret = cpsw_create_xdp_rxqs(cpsw); in cpsw_ndo_open()
833 if (cpsw->cpts) { in cpsw_ndo_open()
834 if (cpts_register(cpsw->cpts)) in cpsw_ndo_open()
835 dev_err(priv->dev, "error registering cpts device\n"); in cpsw_ndo_open()
837 writel(0x10, &cpsw->wr_regs->misc_en); in cpsw_ndo_open()
844 if (cpsw->coal_intvl != 0) { in cpsw_ndo_open()
847 coal.rx_coalesce_usecs = cpsw->coal_intvl; in cpsw_ndo_open()
851 cpdma_ctlr_start(cpsw->dma); in cpsw_ndo_open()
852 cpsw_intr_enable(cpsw); in cpsw_ndo_open()
853 cpsw->usage_count++; in cpsw_ndo_open()
858 if (!cpsw->usage_count) { in cpsw_ndo_open()
859 napi_disable(&cpsw->napi_rx); in cpsw_ndo_open()
860 napi_disable(&cpsw->napi_tx); in cpsw_ndo_open()
861 cpdma_ctlr_stop(cpsw->dma); in cpsw_ndo_open()
862 cpsw_destroy_xdp_rxqs(cpsw); in cpsw_ndo_open()
865 for_each_slave(priv, cpsw_slave_stop, cpsw); in cpsw_ndo_open()
866 pm_runtime_put_sync(cpsw->dev); in cpsw_ndo_open()
867 netif_carrier_off(priv->ndev); in cpsw_ndo_open()
874 struct cpsw_common *cpsw = priv->cpsw; in cpsw_ndo_stop() local
876 cpsw_info(priv, ifdown, "shutting down cpsw device\n"); in cpsw_ndo_stop()
877 __hw_addr_ref_unsync_dev(&ndev->mc, ndev, cpsw_purge_all_mc); in cpsw_ndo_stop()
878 netif_tx_stop_all_queues(priv->ndev); in cpsw_ndo_stop()
879 netif_carrier_off(priv->ndev); in cpsw_ndo_stop()
881 if (cpsw->usage_count <= 1) { in cpsw_ndo_stop()
882 napi_disable(&cpsw->napi_rx); in cpsw_ndo_stop()
883 napi_disable(&cpsw->napi_tx); in cpsw_ndo_stop()
884 cpts_unregister(cpsw->cpts); in cpsw_ndo_stop()
885 cpsw_intr_disable(cpsw); in cpsw_ndo_stop()
886 cpdma_ctlr_stop(cpsw->dma); in cpsw_ndo_stop()
887 cpsw_ale_stop(cpsw->ale); in cpsw_ndo_stop()
888 cpsw_destroy_xdp_rxqs(cpsw); in cpsw_ndo_stop()
890 for_each_slave(priv, cpsw_slave_stop, cpsw); in cpsw_ndo_stop()
892 if (cpsw_need_resplit(cpsw)) in cpsw_ndo_stop()
893 cpsw_split_res(cpsw); in cpsw_ndo_stop()
895 cpsw->usage_count--; in cpsw_ndo_stop()
896 pm_runtime_put_sync(cpsw->dev); in cpsw_ndo_stop()
904 struct cpsw_common *cpsw = priv->cpsw; in cpsw_ndo_start_xmit() local
905 struct cpts *cpts = cpsw->cpts; in cpsw_ndo_start_xmit()
912 ndev->stats.tx_dropped++; in cpsw_ndo_start_xmit()
916 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && in cpsw_ndo_start_xmit()
917 priv->tx_ts_enabled && cpts_can_timestamp(cpts, skb)) in cpsw_ndo_start_xmit()
918 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in cpsw_ndo_start_xmit()
921 if (q_idx >= cpsw->tx_ch_num) in cpsw_ndo_start_xmit()
922 q_idx = q_idx % cpsw->tx_ch_num; in cpsw_ndo_start_xmit()
924 txch = cpsw->txv[q_idx].ch; in cpsw_ndo_start_xmit()
927 ret = cpdma_chan_submit(txch, skb, skb->data, skb->len, in cpsw_ndo_start_xmit()
928 priv->emac_port + cpsw->data.dual_emac); in cpsw_ndo_start_xmit()
949 ndev->stats.tx_dropped++; in cpsw_ndo_start_xmit()
965 struct cpsw_common *cpsw = priv->cpsw; in cpsw_ndo_set_mac_address() local
970 if (!is_valid_ether_addr(addr->sa_data)) in cpsw_ndo_set_mac_address()
971 return -EADDRNOTAVAIL; in cpsw_ndo_set_mac_address()
973 ret = pm_runtime_resume_and_get(cpsw->dev); in cpsw_ndo_set_mac_address()
977 if (cpsw->data.dual_emac) { in cpsw_ndo_set_mac_address()
978 vid = cpsw->slaves[priv->emac_port].port_vlan; in cpsw_ndo_set_mac_address()
982 cpsw_ale_del_ucast(cpsw->ale, priv->mac_addr, HOST_PORT_NUM, in cpsw_ndo_set_mac_address()
984 cpsw_ale_add_ucast(cpsw->ale, addr->sa_data, HOST_PORT_NUM, in cpsw_ndo_set_mac_address()
987 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); in cpsw_ndo_set_mac_address()
988 eth_hw_addr_set(ndev, priv->mac_addr); in cpsw_ndo_set_mac_address()
991 pm_runtime_put(cpsw->dev); in cpsw_ndo_set_mac_address()
1003 struct cpsw_common *cpsw = priv->cpsw; in cpsw_add_vlan_ale_entry() local
1005 if (cpsw->data.dual_emac) { in cpsw_add_vlan_ale_entry()
1006 port_mask = (1 << (priv->emac_port + 1)) | ALE_PORT_HOST; in cpsw_add_vlan_ale_entry()
1009 if (priv->ndev->flags & IFF_ALLMULTI) in cpsw_add_vlan_ale_entry()
1015 if (priv->ndev->flags & IFF_ALLMULTI) in cpsw_add_vlan_ale_entry()
1021 ret = cpsw_ale_add_vlan(cpsw->ale, vid, port_mask, 0, port_mask, in cpsw_add_vlan_ale_entry()
1026 ret = cpsw_ale_add_ucast(cpsw->ale, priv->mac_addr, in cpsw_add_vlan_ale_entry()
1031 ret = cpsw_ale_add_mcast(cpsw->ale, priv->ndev->broadcast, in cpsw_add_vlan_ale_entry()
1038 cpsw_ale_del_ucast(cpsw->ale, priv->mac_addr, in cpsw_add_vlan_ale_entry()
1041 cpsw_ale_del_vlan(cpsw->ale, vid, 0); in cpsw_add_vlan_ale_entry()
1049 struct cpsw_common *cpsw = priv->cpsw; in cpsw_ndo_vlan_rx_add_vid() local
1052 if (vid == cpsw->data.default_vlan) in cpsw_ndo_vlan_rx_add_vid()
1055 ret = pm_runtime_resume_and_get(cpsw->dev); in cpsw_ndo_vlan_rx_add_vid()
1059 if (cpsw->data.dual_emac) { in cpsw_ndo_vlan_rx_add_vid()
1066 for (i = 0; i < cpsw->data.slaves; i++) { in cpsw_ndo_vlan_rx_add_vid()
1067 if (vid == cpsw->slaves[i].port_vlan) { in cpsw_ndo_vlan_rx_add_vid()
1068 ret = -EINVAL; in cpsw_ndo_vlan_rx_add_vid()
1074 dev_info(priv->dev, "Adding vlanid %d to vlan filter\n", vid); in cpsw_ndo_vlan_rx_add_vid()
1077 pm_runtime_put(cpsw->dev); in cpsw_ndo_vlan_rx_add_vid()
1085 struct cpsw_common *cpsw = priv->cpsw; in cpsw_ndo_vlan_rx_kill_vid() local
1088 if (vid == cpsw->data.default_vlan) in cpsw_ndo_vlan_rx_kill_vid()
1091 ret = pm_runtime_resume_and_get(cpsw->dev); in cpsw_ndo_vlan_rx_kill_vid()
1095 if (cpsw->data.dual_emac) { in cpsw_ndo_vlan_rx_kill_vid()
1098 for (i = 0; i < cpsw->data.slaves; i++) { in cpsw_ndo_vlan_rx_kill_vid()
1099 if (vid == cpsw->slaves[i].port_vlan) in cpsw_ndo_vlan_rx_kill_vid()
1104 dev_info(priv->dev, "removing vlanid %d from vlan filter\n", vid); in cpsw_ndo_vlan_rx_kill_vid()
1105 ret = cpsw_ale_del_vlan(cpsw->ale, vid, 0); in cpsw_ndo_vlan_rx_kill_vid()
1106 ret |= cpsw_ale_del_ucast(cpsw->ale, priv->mac_addr, in cpsw_ndo_vlan_rx_kill_vid()
1108 ret |= cpsw_ale_del_mcast(cpsw->ale, priv->ndev->broadcast, in cpsw_ndo_vlan_rx_kill_vid()
1110 ret |= cpsw_ale_flush_multicast(cpsw->ale, ALE_PORT_HOST, vid); in cpsw_ndo_vlan_rx_kill_vid()
1112 pm_runtime_put(cpsw->dev); in cpsw_ndo_vlan_rx_kill_vid()
1120 struct cpsw_common *cpsw = priv->cpsw; in cpsw_ndo_xdp_xmit() local
1125 return -EINVAL; in cpsw_ndo_xdp_xmit()
1129 if (xdpf->len < CPSW_MIN_PACKET_SIZE) in cpsw_ndo_xdp_xmit()
1132 port = priv->emac_port + cpsw->data.dual_emac; in cpsw_ndo_xdp_xmit()
1144 struct cpsw_common *cpsw = ndev_to_cpsw(ndev); in cpsw_ndo_poll_controller() local
1146 cpsw_intr_disable(cpsw); in cpsw_ndo_poll_controller()
1147 cpsw_rx_interrupt(cpsw->irqs_table[0], cpsw); in cpsw_ndo_poll_controller()
1148 cpsw_tx_interrupt(cpsw->irqs_table[1], cpsw); in cpsw_ndo_poll_controller()
1149 cpsw_intr_enable(cpsw); in cpsw_ndo_poll_controller()
1176 struct cpsw_common *cpsw = ndev_to_cpsw(ndev); in cpsw_get_drvinfo() local
1177 struct platform_device *pdev = to_platform_device(cpsw->dev); in cpsw_get_drvinfo()
1179 strscpy(info->driver, "cpsw", sizeof(info->driver)); in cpsw_get_drvinfo()
1180 strscpy(info->version, "1.0", sizeof(info->version)); in cpsw_get_drvinfo()
1181 strscpy(info->bus_info, pdev->name, sizeof(info->bus_info)); in cpsw_get_drvinfo()
1190 priv->rx_pause = pause->rx_pause ? true : false; in cpsw_set_pauseparam()
1191 priv->tx_pause = pause->tx_pause ? true : false; in cpsw_set_pauseparam()
1237 struct device_node *node = pdev->dev.of_node; in cpsw_probe_dt()
1243 return -EINVAL; in cpsw_probe_dt()
1246 dev_err(&pdev->dev, "Missing slaves property in the DT.\n"); in cpsw_probe_dt()
1247 return -EINVAL; in cpsw_probe_dt()
1249 data->slaves = prop; in cpsw_probe_dt()
1252 dev_err(&pdev->dev, "Missing active_slave property in the DT.\n"); in cpsw_probe_dt()
1253 return -EINVAL; in cpsw_probe_dt()
1255 data->active_slave = prop; in cpsw_probe_dt()
1257 data->slave_data = devm_kcalloc(&pdev->dev, in cpsw_probe_dt()
1258 data->slaves, in cpsw_probe_dt()
1261 if (!data->slave_data) in cpsw_probe_dt()
1262 return -ENOMEM; in cpsw_probe_dt()
1265 dev_err(&pdev->dev, "Missing cpdma_channels property in the DT.\n"); in cpsw_probe_dt()
1266 return -EINVAL; in cpsw_probe_dt()
1268 data->channels = prop; in cpsw_probe_dt()
1271 dev_err(&pdev->dev, "Missing bd_ram_size property in the DT.\n"); in cpsw_probe_dt()
1272 return -EINVAL; in cpsw_probe_dt()
1274 data->bd_ram_size = prop; in cpsw_probe_dt()
1277 dev_err(&pdev->dev, "Missing mac_control property in the DT.\n"); in cpsw_probe_dt()
1278 return -EINVAL; in cpsw_probe_dt()
1280 data->mac_control = prop; in cpsw_probe_dt()
1283 data->dual_emac = true; in cpsw_probe_dt()
1288 ret = of_platform_populate(node, NULL, NULL, &pdev->dev); in cpsw_probe_dt()
1291 dev_warn(&pdev->dev, "Doesn't have any child node\n"); in cpsw_probe_dt()
1294 struct cpsw_slave_data *slave_data = data->slave_data + i; in cpsw_probe_dt()
1302 slave_data->ifphy = devm_of_phy_get(&pdev->dev, slave_node, in cpsw_probe_dt()
1305 IS_ERR(slave_data->ifphy)) { in cpsw_probe_dt()
1306 ret = PTR_ERR(slave_data->ifphy); in cpsw_probe_dt()
1307 dev_err(&pdev->dev, in cpsw_probe_dt()
1312 slave_data->slave_node = slave_node; in cpsw_probe_dt()
1313 slave_data->phy_node = of_parse_phandle(slave_node, in cpsw_probe_dt()
1314 "phy-handle", 0); in cpsw_probe_dt()
1316 if (slave_data->phy_node) { in cpsw_probe_dt()
1317 dev_dbg(&pdev->dev, in cpsw_probe_dt()
1318 "slave[%d] using phy-handle=\"%pOF\"\n", in cpsw_probe_dt()
1319 i, slave_data->phy_node); in cpsw_probe_dt()
1326 dev_err_probe(&pdev->dev, ret, "failed to register fixed-link phy\n"); in cpsw_probe_dt()
1329 slave_data->phy_node = of_node_get(slave_node); in cpsw_probe_dt()
1336 dev_err(&pdev->dev, "Invalid slave[%d] phy_id property\n", i); in cpsw_probe_dt()
1344 dev_err(&pdev->dev, "Missing mdio platform device\n"); in cpsw_probe_dt()
1345 ret = -EINVAL; in cpsw_probe_dt()
1348 snprintf(slave_data->phy_id, sizeof(slave_data->phy_id), in cpsw_probe_dt()
1349 PHY_ID_FMT, mdio->name, phyid); in cpsw_probe_dt()
1350 put_device(&mdio->dev); in cpsw_probe_dt()
1352 dev_err(&pdev->dev, in cpsw_probe_dt()
1353 "No slave[%d] phy_id, phy-handle, or fixed-link property\n", in cpsw_probe_dt()
1357 ret = of_get_phy_mode(slave_node, &slave_data->phy_if); in cpsw_probe_dt()
1359 dev_err(&pdev->dev, "Missing or malformed slave[%d] phy-mode property\n", in cpsw_probe_dt()
1365 ret = of_get_mac_address(slave_node, slave_data->mac_addr); in cpsw_probe_dt()
1367 ret = ti_cm_get_macid(&pdev->dev, i, in cpsw_probe_dt()
1368 slave_data->mac_addr); in cpsw_probe_dt()
1372 if (data->dual_emac) { in cpsw_probe_dt()
1375 dev_err(&pdev->dev, "Missing dual_emac_res_vlan in DT.\n"); in cpsw_probe_dt()
1376 slave_data->dual_emac_res_vlan = i+1; in cpsw_probe_dt()
1377 dev_err(&pdev->dev, "Using %d as Reserved VLAN for %d slave\n", in cpsw_probe_dt()
1378 slave_data->dual_emac_res_vlan, i); in cpsw_probe_dt()
1380 slave_data->dual_emac_res_vlan = prop; in cpsw_probe_dt()
1385 if (i == data->slaves) { in cpsw_probe_dt()
1400 struct cpsw_common *cpsw = platform_get_drvdata(pdev); in cpsw_remove_dt() local
1401 struct cpsw_platform_data *data = &cpsw->data; in cpsw_remove_dt()
1402 struct device_node *node = pdev->dev.of_node; in cpsw_remove_dt()
1407 struct cpsw_slave_data *slave_data = &data->slave_data[i]; in cpsw_remove_dt()
1415 of_node_put(slave_data->phy_node); in cpsw_remove_dt()
1418 if (i == data->slaves) { in cpsw_remove_dt()
1424 of_platform_depopulate(&pdev->dev); in cpsw_remove_dt()
1429 struct cpsw_common *cpsw = priv->cpsw; in cpsw_probe_dual_emac() local
1430 struct cpsw_platform_data *data = &cpsw->data; in cpsw_probe_dual_emac()
1435 ndev = devm_alloc_etherdev_mqs(cpsw->dev, sizeof(struct cpsw_priv), in cpsw_probe_dual_emac()
1438 dev_err(cpsw->dev, "cpsw: error allocating net_device\n"); in cpsw_probe_dual_emac()
1439 return -ENOMEM; in cpsw_probe_dual_emac()
1443 priv_sl2->cpsw = cpsw; in cpsw_probe_dual_emac()
1444 priv_sl2->ndev = ndev; in cpsw_probe_dual_emac()
1445 priv_sl2->dev = &ndev->dev; in cpsw_probe_dual_emac()
1446 priv_sl2->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG); in cpsw_probe_dual_emac()
1448 if (is_valid_ether_addr(data->slave_data[1].mac_addr)) { in cpsw_probe_dual_emac()
1449 memcpy(priv_sl2->mac_addr, data->slave_data[1].mac_addr, in cpsw_probe_dual_emac()
1451 dev_info(cpsw->dev, "cpsw: Detected MACID = %pM\n", in cpsw_probe_dual_emac()
1452 priv_sl2->mac_addr); in cpsw_probe_dual_emac()
1454 eth_random_addr(priv_sl2->mac_addr); in cpsw_probe_dual_emac()
1455 dev_info(cpsw->dev, "cpsw: Random MACID = %pM\n", in cpsw_probe_dual_emac()
1456 priv_sl2->mac_addr); in cpsw_probe_dual_emac()
1458 eth_hw_addr_set(ndev, priv_sl2->mac_addr); in cpsw_probe_dual_emac()
1460 priv_sl2->emac_port = 1; in cpsw_probe_dual_emac()
1461 cpsw->slaves[1].ndev = ndev; in cpsw_probe_dual_emac()
1462 ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_RX; in cpsw_probe_dual_emac()
1463 ndev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | in cpsw_probe_dual_emac()
1466 ndev->netdev_ops = &cpsw_netdev_ops; in cpsw_probe_dual_emac()
1467 ndev->ethtool_ops = &cpsw_ethtool_ops; in cpsw_probe_dual_emac()
1470 SET_NETDEV_DEV(ndev, cpsw->dev); in cpsw_probe_dual_emac()
1471 ndev->dev.of_node = cpsw->slaves[1].data->slave_node; in cpsw_probe_dual_emac()
1474 dev_err(cpsw->dev, "cpsw: error registering net device\n"); in cpsw_probe_dual_emac()
1480 { .compatible = "ti,cpsw"},
1481 { .compatible = "ti,am335x-cpsw"},
1482 { .compatible = "ti,am4372-cpsw"},
1483 { .compatible = "ti,dra7-cpsw"},
1495 struct device *dev = &pdev->dev; in cpsw_probe()
1504 struct cpsw_common *cpsw; in cpsw_probe() local
1508 cpsw = devm_kzalloc(dev, sizeof(struct cpsw_common), GFP_KERNEL); in cpsw_probe()
1509 if (!cpsw) in cpsw_probe()
1510 return -ENOMEM; in cpsw_probe()
1512 platform_set_drvdata(pdev, cpsw); in cpsw_probe()
1515 cpsw->dev = dev; in cpsw_probe()
1530 cpsw->bus_freq_mhz = clk_get_rate(clk) / 1000000; in cpsw_probe()
1535 cpsw->regs = ss_regs; in cpsw_probe()
1537 cpsw->wr_regs = devm_platform_ioremap_resource(pdev, 1); in cpsw_probe()
1538 if (IS_ERR(cpsw->wr_regs)) in cpsw_probe()
1539 return PTR_ERR(cpsw->wr_regs); in cpsw_probe()
1545 cpsw->irqs_table[0] = irq; in cpsw_probe()
1551 cpsw->irqs_table[1] = irq; in cpsw_probe()
1557 cpsw->misc_irq = irq; in cpsw_probe()
1571 ret = cpsw_probe_dt(&cpsw->data, pdev); in cpsw_probe()
1577 cpsw->quirk_irq = true; in cpsw_probe()
1579 data = &cpsw->data; in cpsw_probe()
1580 cpsw->slaves = devm_kcalloc(dev, in cpsw_probe()
1581 data->slaves, sizeof(struct cpsw_slave), in cpsw_probe()
1583 if (!cpsw->slaves) { in cpsw_probe()
1584 ret = -ENOMEM; in cpsw_probe()
1588 cpsw->rx_packet_max = max(rx_packet_max, CPSW_MAX_PACKET_SIZE); in cpsw_probe()
1589 cpsw->descs_pool_size = descs_pool_size; in cpsw_probe()
1591 ret = cpsw_init_common(cpsw, ss_regs, ale_ageout, in cpsw_probe()
1592 ss_res->start + CPSW2_BD_OFFSET, in cpsw_probe()
1597 ch = cpsw->quirk_irq ? 0 : 7; in cpsw_probe()
1598 cpsw->txv[0].ch = cpdma_chan_create(cpsw->dma, ch, cpsw_tx_handler, 0); in cpsw_probe()
1599 if (IS_ERR(cpsw->txv[0].ch)) { in cpsw_probe()
1601 ret = PTR_ERR(cpsw->txv[0].ch); in cpsw_probe()
1605 cpsw->rxv[0].ch = cpdma_chan_create(cpsw->dma, 0, cpsw_rx_handler, 1); in cpsw_probe()
1606 if (IS_ERR(cpsw->rxv[0].ch)) { in cpsw_probe()
1608 ret = PTR_ERR(cpsw->rxv[0].ch); in cpsw_probe()
1611 cpsw_split_res(cpsw); in cpsw_probe()
1618 ret = -ENOMEM; in cpsw_probe()
1623 priv->cpsw = cpsw; in cpsw_probe()
1624 priv->ndev = ndev; in cpsw_probe()
1625 priv->dev = dev; in cpsw_probe()
1626 priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG); in cpsw_probe()
1627 priv->emac_port = 0; in cpsw_probe()
1629 if (is_valid_ether_addr(data->slave_data[0].mac_addr)) { in cpsw_probe()
1630 memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN); in cpsw_probe()
1631 dev_info(dev, "Detected MACID = %pM\n", priv->mac_addr); in cpsw_probe()
1633 eth_random_addr(priv->mac_addr); in cpsw_probe()
1634 dev_info(dev, "Random MACID = %pM\n", priv->mac_addr); in cpsw_probe()
1637 eth_hw_addr_set(ndev, priv->mac_addr); in cpsw_probe()
1639 cpsw->slaves[0].ndev = ndev; in cpsw_probe()
1641 ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_RX; in cpsw_probe()
1642 ndev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | in cpsw_probe()
1645 ndev->netdev_ops = &cpsw_netdev_ops; in cpsw_probe()
1646 ndev->ethtool_ops = &cpsw_ethtool_ops; in cpsw_probe()
1647 netif_napi_add(ndev, &cpsw->napi_rx, in cpsw_probe()
1648 cpsw->quirk_irq ? cpsw_rx_poll : cpsw_rx_mq_poll); in cpsw_probe()
1649 netif_napi_add_tx(ndev, &cpsw->napi_tx, in cpsw_probe()
1650 cpsw->quirk_irq ? cpsw_tx_poll : cpsw_tx_mq_poll); in cpsw_probe()
1654 ndev->dev.of_node = cpsw->slaves[0].data->slave_node; in cpsw_probe()
1658 ret = -ENODEV; in cpsw_probe()
1662 if (cpsw->data.dual_emac) { in cpsw_probe()
1677 ret = devm_request_irq(dev, cpsw->irqs_table[0], cpsw_rx_interrupt, in cpsw_probe()
1678 0, dev_name(dev), cpsw); in cpsw_probe()
1685 ret = devm_request_irq(dev, cpsw->irqs_table[1], cpsw_tx_interrupt, in cpsw_probe()
1686 0, dev_name(&pdev->dev), cpsw); in cpsw_probe()
1692 if (!cpsw->cpts) in cpsw_probe()
1695 ret = devm_request_irq(&pdev->dev, cpsw->misc_irq, cpsw_misc_interrupt, in cpsw_probe()
1696 0, dev_name(&pdev->dev), cpsw); in cpsw_probe()
1703 cpts_set_irqpoll(cpsw->cpts, false); in cpsw_probe()
1708 &ss_res->start, cpsw->irqs_table[0], descs_pool_size); in cpsw_probe()
1710 pm_runtime_put(&pdev->dev); in cpsw_probe()
1717 cpts_release(cpsw->cpts); in cpsw_probe()
1718 cpdma_ctlr_destroy(cpsw->dma); in cpsw_probe()
1721 pm_runtime_put_sync(&pdev->dev); in cpsw_probe()
1723 pm_runtime_disable(&pdev->dev); in cpsw_probe()
1729 struct cpsw_common *cpsw = platform_get_drvdata(pdev); in cpsw_remove() local
1732 ret = pm_runtime_resume_and_get(&pdev->dev); in cpsw_remove()
1737 dev_err(&pdev->dev, "Failed to resume device (%pe)\n", in cpsw_remove()
1742 for (i = 0; i < cpsw->data.slaves; i++) in cpsw_remove()
1743 if (cpsw->slaves[i].ndev) in cpsw_remove()
1744 unregister_netdev(cpsw->slaves[i].ndev); in cpsw_remove()
1746 cpts_release(cpsw->cpts); in cpsw_remove()
1747 cpdma_ctlr_destroy(cpsw->dma); in cpsw_remove()
1749 pm_runtime_put_sync(&pdev->dev); in cpsw_remove()
1750 pm_runtime_disable(&pdev->dev); in cpsw_remove()
1756 struct cpsw_common *cpsw = dev_get_drvdata(dev); in cpsw_suspend() local
1761 for (i = 0; i < cpsw->data.slaves; i++) in cpsw_suspend()
1762 if (cpsw->slaves[i].ndev) in cpsw_suspend()
1763 if (netif_running(cpsw->slaves[i].ndev)) in cpsw_suspend()
1764 cpsw_ndo_stop(cpsw->slaves[i].ndev); in cpsw_suspend()
1776 struct cpsw_common *cpsw = dev_get_drvdata(dev); in cpsw_resume() local
1785 for (i = 0; i < cpsw->data.slaves; i++) in cpsw_resume()
1786 if (cpsw->slaves[i].ndev) in cpsw_resume()
1787 if (netif_running(cpsw->slaves[i].ndev)) in cpsw_resume()
1788 cpsw_ndo_open(cpsw->slaves[i].ndev); in cpsw_resume()
1800 .name = "cpsw",
1813 MODULE_DESCRIPTION("TI CPSW Ethernet driver");