Lines Matching +full:enetc +full:- +full:mdio
1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2017-2019 NXP */
5 #include <linux/mdio.h>
11 #include <linux/pcs-lynx.h>
15 #define ENETC_DRV_NAME_STR "ENETC PF driver"
19 u32 upper = __raw_readl(hw->port + ENETC_PSIPMAR0(si)); in enetc_pf_get_primary_mac_addr()
20 u16 lower = __raw_readw(hw->port + ENETC_PSIPMAR1(si)); in enetc_pf_get_primary_mac_addr()
32 __raw_writel(upper, hw->port + ENETC_PSIPMAR0(si)); in enetc_pf_set_primary_mac_addr()
33 __raw_writew(lower, hw->port + ENETC_PSIPMAR1(si)); in enetc_pf_set_primary_mac_addr()
41 if (!is_valid_ether_addr(saddr->sa_data)) in enetc_pf_set_mac_addr()
42 return -EADDRNOTAVAIL; in enetc_pf_set_mac_addr()
44 eth_hw_addr_set(ndev, saddr->sa_data); in enetc_pf_set_mac_addr()
45 enetc_pf_set_primary_mac_addr(&priv->si->hw, 0, saddr->sa_data); in enetc_pf_set_mac_addr()
60 pf->vlan_promisc_simap |= BIT(si_idx); in enetc_enable_si_vlan_promisc()
61 enetc_set_vlan_promisc(&pf->si->hw, pf->vlan_promisc_simap); in enetc_enable_si_vlan_promisc()
66 pf->vlan_promisc_simap &= ~BIT(si_idx); in enetc_disable_si_vlan_promisc()
67 enetc_set_vlan_promisc(&pf->si->hw, pf->vlan_promisc_simap); in enetc_disable_si_vlan_promisc()
98 filter->mac_addr_cnt = 0; in enetc_reset_mac_addr_filter()
100 bitmap_zero(filter->mac_hash_table, in enetc_reset_mac_addr_filter()
108 ether_addr_copy(filter->mac_addr, addr); in enetc_add_mac_addr_em_filter()
109 filter->mac_addr_cnt++; in enetc_add_mac_addr_em_filter()
118 __set_bit(idx, filter->mac_hash_table); in enetc_add_mac_addr_ht_filter()
119 filter->mac_addr_cnt++; in enetc_add_mac_addr_ht_filter()
124 bool err = si->errata & ENETC_ERR_UCMCSWP; in enetc_clear_mac_ht_flt()
127 enetc_port_wr(&si->hw, ENETC_PSIUMHFR0(si_idx, err), 0); in enetc_clear_mac_ht_flt()
128 enetc_port_wr(&si->hw, ENETC_PSIUMHFR1(si_idx), 0); in enetc_clear_mac_ht_flt()
130 enetc_port_wr(&si->hw, ENETC_PSIMMHFR0(si_idx, err), 0); in enetc_clear_mac_ht_flt()
131 enetc_port_wr(&si->hw, ENETC_PSIMMHFR1(si_idx), 0); in enetc_clear_mac_ht_flt()
138 bool err = si->errata & ENETC_ERR_UCMCSWP; in enetc_set_mac_ht_flt()
141 enetc_port_wr(&si->hw, ENETC_PSIUMHFR0(si_idx, err), in enetc_set_mac_ht_flt()
143 enetc_port_wr(&si->hw, ENETC_PSIUMHFR1(si_idx), in enetc_set_mac_ht_flt()
146 enetc_port_wr(&si->hw, ENETC_PSIMMHFR0(si_idx, err), in enetc_set_mac_ht_flt()
148 enetc_port_wr(&si->hw, ENETC_PSIMMHFR1(si_idx), in enetc_set_mac_ht_flt()
155 struct enetc_mac_filter *f = pf->mac_filter; in enetc_sync_mac_filters()
156 struct enetc_si *si = pf->si; in enetc_sync_mac_filters()
162 bool em = (f->mac_addr_cnt == 1) && (i == UC); in enetc_sync_mac_filters()
163 bool clear = !f->mac_addr_cnt; in enetc_sync_mac_filters()
179 err = enetc_set_mac_flt_entry(si, pos, f->mac_addr, in enetc_sync_mac_filters()
185 dev_warn(&si->pdev->dev, "fallback to HT filt (%d)\n", in enetc_sync_mac_filters()
193 enetc_set_mac_ht_flt(si, 0, i, *f->mac_hash_table); in enetc_sync_mac_filters()
200 struct enetc_pf *pf = enetc_si_priv(priv->si); in enetc_pf_set_rx_mode()
201 struct enetc_hw *hw = &priv->si->hw; in enetc_pf_set_rx_mode()
208 if (ndev->flags & IFF_PROMISC) { in enetc_pf_set_rx_mode()
213 } else if (ndev->flags & IFF_ALLMULTI) { in enetc_pf_set_rx_mode()
222 filter = &pf->mac_filter[UC]; in enetc_pf_set_rx_mode()
228 enetc_add_mac_addr_em_filter(filter, ha->addr); in enetc_pf_set_rx_mode()
232 enetc_add_mac_addr_ht_filter(filter, ha->addr); in enetc_pf_set_rx_mode()
238 filter = &pf->mac_filter[MC]; in enetc_pf_set_rx_mode()
242 if (!is_multicast_ether_addr(ha->addr)) in enetc_pf_set_rx_mode()
245 enetc_add_mac_addr_ht_filter(filter, ha->addr); in enetc_pf_set_rx_mode()
281 bitmap_zero(pf->vlan_ht_filter, ENETC_VLAN_HT_SIZE); in enetc_sync_vlan_ht_filter()
283 for_each_set_bit(i, pf->active_vlans, VLAN_N_VID) { in enetc_sync_vlan_ht_filter()
286 __set_bit(hidx, pf->vlan_ht_filter); in enetc_sync_vlan_ht_filter()
290 enetc_set_vlan_ht_filter(&pf->si->hw, 0, *pf->vlan_ht_filter); in enetc_sync_vlan_ht_filter()
296 struct enetc_pf *pf = enetc_si_priv(priv->si); in enetc_vlan_rx_add_vid()
299 __set_bit(vid, pf->active_vlans); in enetc_vlan_rx_add_vid()
302 if (!__test_and_set_bit(idx, pf->vlan_ht_filter)) in enetc_vlan_rx_add_vid()
311 struct enetc_pf *pf = enetc_si_priv(priv->si); in enetc_vlan_rx_del_vid()
313 __clear_bit(vid, pf->active_vlans); in enetc_vlan_rx_del_vid()
322 struct enetc_si *si = priv->si; in enetc_set_loopback()
345 struct enetc_pf *pf = enetc_si_priv(priv->si); in enetc_pf_set_vf_mac()
348 if (vf >= pf->total_vfs) in enetc_pf_set_vf_mac()
349 return -EINVAL; in enetc_pf_set_vf_mac()
352 return -EADDRNOTAVAIL; in enetc_pf_set_vf_mac()
354 vf_state = &pf->vf_state[vf]; in enetc_pf_set_vf_mac()
355 vf_state->flags |= ENETC_VF_FLAG_PF_SET_MAC; in enetc_pf_set_vf_mac()
356 enetc_pf_set_primary_mac_addr(&priv->si->hw, vf + 1, mac); in enetc_pf_set_vf_mac()
364 struct enetc_pf *pf = enetc_si_priv(priv->si); in enetc_pf_set_vf_vlan()
366 if (priv->si->errata & ENETC_ERR_VLAN_ISOL) in enetc_pf_set_vf_vlan()
367 return -EOPNOTSUPP; in enetc_pf_set_vf_vlan()
369 if (vf >= pf->total_vfs) in enetc_pf_set_vf_vlan()
370 return -EINVAL; in enetc_pf_set_vf_vlan()
373 /* only C-tags supported for now */ in enetc_pf_set_vf_vlan()
374 return -EPROTONOSUPPORT; in enetc_pf_set_vf_vlan()
376 enetc_set_isol_vlan(&priv->si->hw, vf + 1, vlan, qos); in enetc_pf_set_vf_vlan()
383 struct enetc_pf *pf = enetc_si_priv(priv->si); in enetc_pf_set_vf_spoofchk()
386 if (vf >= pf->total_vfs) in enetc_pf_set_vf_spoofchk()
387 return -EINVAL; in enetc_pf_set_vf_spoofchk()
389 cfgr = enetc_port_rd(&priv->si->hw, ENETC_PSICFGR0(vf + 1)); in enetc_pf_set_vf_spoofchk()
391 enetc_port_wr(&priv->si->hw, ENETC_PSICFGR0(vf + 1), cfgr); in enetc_pf_set_vf_spoofchk()
399 struct device *dev = &pf->si->pdev->dev; in enetc_setup_mac_address()
400 struct enetc_hw *hw = &pf->si->hw; in enetc_setup_mac_address()
407 if (err == -EPROBE_DEFER) in enetc_setup_mac_address()
437 for (i = 0; i < pf->total_vfs; i++) { in enetc_setup_mac_addresses()
449 struct enetc_hw *hw = &si->hw; in enetc_port_assign_rfs_entries()
456 vf_entries = num_entries / (pf->total_vfs + 1); in enetc_port_assign_rfs_entries()
458 for (i = 0; i < pf->total_vfs; i++) in enetc_port_assign_rfs_entries()
461 num_entries - vf_entries * pf->total_vfs); in enetc_port_assign_rfs_entries()
470 struct enetc_hw *hw = &si->hw; in enetc_port_si_configure()
484 dev_warn(&si->pdev->dev, "Found %d rings, expected %d!\n", in enetc_port_si_configure()
490 /* Add default one-time settings for SI0 (PF) */ in enetc_port_si_configure()
496 num_rings -= ENETC_PF_NUM_RINGS; in enetc_port_si_configure()
503 num_rings /= pf->total_vfs; in enetc_port_si_configure()
508 for (i = 0; i < pf->total_vfs; i++) in enetc_port_si_configure()
542 struct enetc_hw *hw = &si->hw; in enetc_configure_port_mac()
553 * and may lead to RX lock-up under traffic. Set it to 1 instead, in enetc_configure_port_mac()
589 struct enetc_hw *hw = &pf->si->hw; in enetc_configure_port()
591 enetc_configure_port_mac(pf->si); in enetc_configure_port()
593 enetc_port_si_configure(pf->si); in enetc_configure_port()
600 enetc_port_assign_rfs_entries(pf->si); in enetc_configure_port()
603 pf->vlan_promisc_simap = ENETC_VLAN_PROMISC_MAP_ALL; in enetc_configure_port()
604 enetc_set_vlan_promisc(hw, pf->vlan_promisc_simap); in enetc_configure_port()
616 struct enetc_vf_state *vf_state = &pf->vf_state[vf_id]; in enetc_msg_pf_set_vf_primary_mac_addr()
617 struct enetc_msg_swbd *msg = &pf->rxmsg[vf_id]; in enetc_msg_pf_set_vf_primary_mac_addr()
619 struct device *dev = &pf->si->pdev->dev; in enetc_msg_pf_set_vf_primary_mac_addr()
623 cmd = (struct enetc_msg_cmd_set_primary_mac *)msg->vaddr; in enetc_msg_pf_set_vf_primary_mac_addr()
624 cmd_id = cmd->header.id; in enetc_msg_pf_set_vf_primary_mac_addr()
628 addr = cmd->mac.sa_data; in enetc_msg_pf_set_vf_primary_mac_addr()
629 if (vf_state->flags & ENETC_VF_FLAG_PF_SET_MAC) in enetc_msg_pf_set_vf_primary_mac_addr()
633 enetc_pf_set_primary_mac_addr(&pf->si->hw, vf_id + 1, addr); in enetc_msg_pf_set_vf_primary_mac_addr()
640 struct enetc_msg_swbd *msg = &pf->rxmsg[vf_id]; in enetc_msg_handle_rxmsg()
641 struct device *dev = &pf->si->pdev->dev; in enetc_msg_handle_rxmsg()
646 cmd_hdr = (struct enetc_msg_cmd_header *)msg->vaddr; in enetc_msg_handle_rxmsg()
647 cmd_type = cmd_hdr->type; in enetc_msg_handle_rxmsg()
668 pf->num_vfs = 0; in enetc_sriov_configure()
671 pf->num_vfs = num_vfs; in enetc_sriov_configure()
675 dev_err(&pdev->dev, "enetc_msg_psi_init (%d)\n", err); in enetc_sriov_configure()
681 dev_err(&pdev->dev, "pci_enable_sriov err %d\n", err); in enetc_sriov_configure()
691 pf->num_vfs = 0; in enetc_sriov_configure()
702 netdev_features_t changed = ndev->features ^ features; in enetc_pf_set_features()
713 struct enetc_pf *pf = enetc_si_priv(priv->si); in enetc_pf_set_features()
746 return -EOPNOTSUPP; in enetc_pf_setup_tc()
774 SET_NETDEV_DEV(ndev, &si->pdev->dev); in enetc_pf_netdev_setup()
775 priv->ndev = ndev; in enetc_pf_netdev_setup()
776 priv->si = si; in enetc_pf_netdev_setup()
777 priv->dev = &si->pdev->dev; in enetc_pf_netdev_setup()
778 si->ndev = ndev; in enetc_pf_netdev_setup()
780 priv->msg_enable = (NETIF_MSG_WOL << 1) - 1; in enetc_pf_netdev_setup()
781 ndev->netdev_ops = ndev_ops; in enetc_pf_netdev_setup()
783 ndev->watchdog_timeo = 5 * HZ; in enetc_pf_netdev_setup()
784 ndev->max_mtu = ENETC_MAX_MTU; in enetc_pf_netdev_setup()
786 ndev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM | in enetc_pf_netdev_setup()
790 ndev->features = NETIF_F_HIGHDMA | NETIF_F_SG | NETIF_F_RXCSUM | in enetc_pf_netdev_setup()
794 ndev->vlan_features = NETIF_F_SG | NETIF_F_HW_CSUM | in enetc_pf_netdev_setup()
797 if (si->num_rss) in enetc_pf_netdev_setup()
798 ndev->hw_features |= NETIF_F_RXHASH; in enetc_pf_netdev_setup()
800 ndev->priv_flags |= IFF_UNICAST_FLT; in enetc_pf_netdev_setup()
801 ndev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | in enetc_pf_netdev_setup()
805 if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) { in enetc_pf_netdev_setup()
806 priv->active_offloads |= ENETC_F_QCI; in enetc_pf_netdev_setup()
807 ndev->features |= NETIF_F_HW_TC; in enetc_pf_netdev_setup()
808 ndev->hw_features |= NETIF_F_HW_TC; in enetc_pf_netdev_setup()
812 enetc_load_primary_mac_addr(&si->hw, ndev); in enetc_pf_netdev_setup()
817 struct device *dev = &pf->si->pdev->dev; in enetc_mdio_probe()
824 return -ENOMEM; in enetc_mdio_probe()
826 bus->name = "Freescale ENETC MDIO Bus"; in enetc_mdio_probe()
827 bus->read = enetc_mdio_read_c22; in enetc_mdio_probe()
828 bus->write = enetc_mdio_write_c22; in enetc_mdio_probe()
829 bus->read_c45 = enetc_mdio_read_c45; in enetc_mdio_probe()
830 bus->write_c45 = enetc_mdio_write_c45; in enetc_mdio_probe()
831 bus->parent = dev; in enetc_mdio_probe()
832 mdio_priv = bus->priv; in enetc_mdio_probe()
833 mdio_priv->hw = &pf->si->hw; in enetc_mdio_probe()
834 mdio_priv->mdio_base = ENETC_EMDIO_BASE; in enetc_mdio_probe()
835 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev)); in enetc_mdio_probe()
839 return dev_err_probe(dev, err, "cannot register MDIO bus\n"); in enetc_mdio_probe()
841 pf->mdio = bus; in enetc_mdio_probe()
848 if (pf->mdio) in enetc_mdio_remove()
849 mdiobus_unregister(pf->mdio); in enetc_mdio_remove()
854 struct device *dev = &pf->si->pdev->dev; in enetc_imdio_create()
862 return -ENOMEM; in enetc_imdio_create()
864 bus->name = "Freescale ENETC internal MDIO Bus"; in enetc_imdio_create()
865 bus->read = enetc_mdio_read_c22; in enetc_imdio_create()
866 bus->write = enetc_mdio_write_c22; in enetc_imdio_create()
867 bus->read_c45 = enetc_mdio_read_c45; in enetc_imdio_create()
868 bus->write_c45 = enetc_mdio_write_c45; in enetc_imdio_create()
869 bus->parent = dev; in enetc_imdio_create()
870 bus->phy_mask = ~0; in enetc_imdio_create()
871 mdio_priv = bus->priv; in enetc_imdio_create()
872 mdio_priv->hw = &pf->si->hw; in enetc_imdio_create()
873 mdio_priv->mdio_base = ENETC_PM_IMDIO_BASE; in enetc_imdio_create()
874 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev)); in enetc_imdio_create()
878 dev_err(dev, "cannot register internal MDIO bus (%d)\n", err); in enetc_imdio_create()
889 pf->imdio = bus; in enetc_imdio_create()
890 pf->pcs = phylink_pcs; in enetc_imdio_create()
903 if (pf->pcs) in enetc_imdio_remove()
904 lynx_pcs_destroy(pf->pcs); in enetc_imdio_remove()
905 if (pf->imdio) { in enetc_imdio_remove()
906 mdiobus_unregister(pf->imdio); in enetc_imdio_remove()
907 mdiobus_free(pf->imdio); in enetc_imdio_remove()
913 return (pf->if_mode == PHY_INTERFACE_MODE_SGMII || in enetc_port_has_pcs()
914 pf->if_mode == PHY_INTERFACE_MODE_1000BASEX || in enetc_port_has_pcs()
915 pf->if_mode == PHY_INTERFACE_MODE_2500BASEX || in enetc_port_has_pcs()
916 pf->if_mode == PHY_INTERFACE_MODE_USXGMII); in enetc_port_has_pcs()
924 mdio_np = of_get_child_by_name(node, "mdio"); in enetc_mdiobus_create()
955 return pf->pcs; in enetc_pl_mac_select_pcs()
964 enetc_mac_config(pf->si, state->interface); in enetc_pl_mac_config()
1003 struct enetc_hw *hw = &pf->si->hw; in enetc_pl_mac_link_up()
1004 struct enetc_si *si = pf->si; in enetc_pl_mac_link_up()
1009 priv = netdev_priv(pf->si->ndev); in enetc_pl_mac_link_up()
1011 if (pf->si->hw_features & ENETC_SI_F_QBV) in enetc_pl_mac_link_up()
1019 for (idx = 0; idx < priv->num_rx_rings; idx++) { in enetc_pl_mac_link_up()
1038 /* Also, set up the refresh timer to send follow-up PAUSE in enetc_pl_mac_link_up()
1068 if (si->hw_features & ENETC_SI_F_QBU) in enetc_pl_mac_link_up()
1077 struct enetc_si *si = pf->si; in enetc_pl_mac_link_down()
1080 priv = netdev_priv(si->ndev); in enetc_pl_mac_link_down()
1082 if (si->hw_features & ENETC_SI_F_QBU) in enetc_pl_mac_link_down()
1098 struct enetc_pf *pf = enetc_si_priv(priv->si); in enetc_phylink_create()
1102 pf->phylink_config.dev = &priv->ndev->dev; in enetc_phylink_create()
1103 pf->phylink_config.type = PHYLINK_NETDEV; in enetc_phylink_create()
1104 pf->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | in enetc_phylink_create()
1108 pf->phylink_config.supported_interfaces); in enetc_phylink_create()
1110 pf->phylink_config.supported_interfaces); in enetc_phylink_create()
1112 pf->phylink_config.supported_interfaces); in enetc_phylink_create()
1114 pf->phylink_config.supported_interfaces); in enetc_phylink_create()
1116 pf->phylink_config.supported_interfaces); in enetc_phylink_create()
1117 phy_interface_set_rgmii(pf->phylink_config.supported_interfaces); in enetc_phylink_create()
1119 phylink = phylink_create(&pf->phylink_config, of_fwnode_handle(node), in enetc_phylink_create()
1120 pf->if_mode, &enetc_mac_phylink_ops); in enetc_phylink_create()
1126 priv->phylink = phylink; in enetc_phylink_create()
1133 phylink_destroy(priv->phylink); in enetc_phylink_destroy()
1142 struct enetc_hw *hw = &si->hw; in enetc_init_port_rfs_memory()
1160 struct enetc_hw *hw = &si->hw; in enetc_init_port_rss_memory()
1172 return -ENOMEM; in enetc_init_port_rss_memory()
1187 "fsl,ls1028a-enetc-ierb"); in enetc_pf_register_with_ierb()
1189 return -ENODEV; in enetc_pf_register_with_ierb()
1195 return -EPROBE_DEFER; in enetc_pf_register_with_ierb()
1207 dev_err_probe(&pdev->dev, err, "PCI probing failed\n"); in enetc_psi_create()
1212 if (!si->hw.port || !si->hw.global) { in enetc_psi_create()
1213 err = -ENODEV; in enetc_psi_create()
1214 dev_err(&pdev->dev, "could not map PF space, probing a VF?\n"); in enetc_psi_create()
1218 err = enetc_setup_cbdr(&pdev->dev, &si->hw, ENETC_CBDR_DEFAULT_SIZE, in enetc_psi_create()
1219 &si->cbd_ring); in enetc_psi_create()
1225 dev_err(&pdev->dev, "Failed to initialize RFS memory\n"); in enetc_psi_create()
1231 dev_err(&pdev->dev, "Failed to initialize RSS memory\n"); in enetc_psi_create()
1238 enetc_teardown_cbdr(&si->cbd_ring); in enetc_psi_create()
1249 enetc_teardown_cbdr(&si->cbd_ring); in enetc_psi_destroy()
1256 struct device_node *node = pdev->dev.of_node; in enetc_pf_probe()
1264 if (err == -EPROBE_DEFER) in enetc_pf_probe()
1267 dev_warn(&pdev->dev, in enetc_pf_probe()
1278 pf->si = si; in enetc_pf_probe()
1279 pf->total_vfs = pci_sriov_get_totalvfs(pdev); in enetc_pf_probe()
1280 if (pf->total_vfs) { in enetc_pf_probe()
1281 pf->vf_state = kcalloc(pf->total_vfs, sizeof(struct enetc_vf_state), in enetc_pf_probe()
1283 if (!pf->vf_state) in enetc_pf_probe()
1297 err = -ENOMEM; in enetc_pf_probe()
1298 dev_err(&pdev->dev, "netdev creation failed\n"); in enetc_pf_probe()
1306 mutex_init(&priv->mm_lock); in enetc_pf_probe()
1312 dev_err(&pdev->dev, "SI resource alloc failed\n"); in enetc_pf_probe()
1318 dev_err(&pdev->dev, "Failed to configure SI\n"); in enetc_pf_probe()
1324 dev_err(&pdev->dev, "MSIX alloc failed\n"); in enetc_pf_probe()
1328 err = of_get_phy_mode(node, &pf->if_mode); in enetc_pf_probe()
1330 dev_err(&pdev->dev, "Failed to read PHY mode\n"); in enetc_pf_probe()
1359 si->ndev = NULL; in enetc_pf_probe()
1363 kfree(pf->vf_state); in enetc_pf_probe()
1376 priv = netdev_priv(si->ndev); in enetc_pf_remove()
1378 if (pf->num_vfs) in enetc_pf_remove()
1381 unregister_netdev(si->ndev); in enetc_pf_remove()
1390 free_netdev(si->ndev); in enetc_pf_remove()
1391 kfree(pf->vf_state); in enetc_pf_remove()
1398 struct device_node *node = pdev->dev.of_node; in enetc_fixup_clear_rss_rfs()