Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'enetc-Migrate-to-PHYLINK-and-PCS_LYNX'

Claudiu Manoil says:

====================
enetc: Migrate to PHYLINK and PCS_LYNX

Transitioning the enetc driver from phylib to phylink.
Offloading the serdes configuration to the PCS_LYNX
module is a mandatory part of this transition. Aiming
for a cleaner, more maintainable design, and better
code reuse.
The first 2 patches are clean up prerequisites.

Tested on a p1028rdb board.

v2: validate() explicitly rejects now all interface modes not
supported by the driver instead of relying on the device tree
to provide only supported interfaces, and dropped redundant
activation of pcs_poll (addressing Ioana's findings)
====================

Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+252 -212
+1
arch/arm64/boot/dts/freescale/fsl-ls1028a-rdb.dts
··· 199 199 &enetc_port0 { 200 200 phy-handle = <&sgmii_phy0>; 201 201 phy-connection-type = "sgmii"; 202 + managed = "in-band-status"; 202 203 status = "okay"; 203 204 204 205 mdio {
+3 -2
drivers/net/ethernet/freescale/enetc/Kconfig
··· 3 3 tristate "ENETC PF driver" 4 4 depends on PCI && PCI_MSI 5 5 select FSL_ENETC_MDIO 6 - select PHYLIB 6 + select PHYLINK 7 + select PCS_LYNX 7 8 select DIMLIB 8 9 help 9 10 This driver supports NXP ENETC gigabit ethernet controller PCIe ··· 16 15 config FSL_ENETC_VF 17 16 tristate "ENETC VF driver" 18 17 depends on PCI && PCI_MSI 19 - select PHYLIB 18 + select PHYLINK 20 19 select DIMLIB 21 20 help 22 21 This driver supports NXP ENETC gigabit ethernet controller PCIe
+20 -33
drivers/net/ethernet/freescale/enetc/enetc.c
··· 4 4 #include "enetc.h" 5 5 #include <linux/tcp.h> 6 6 #include <linux/udp.h> 7 - #include <linux/of_mdio.h> 8 7 #include <linux/vmalloc.h> 9 8 10 9 /* ENETC overhead: optional extension BD + 1 BD gap */ ··· 1391 1392 enetc_rxbdr_wr(&priv->si->hw, i, ENETC_RBIER, 0); 1392 1393 } 1393 1394 1394 - static void adjust_link(struct net_device *ndev) 1395 + static int enetc_phylink_connect(struct net_device *ndev) 1395 1396 { 1396 1397 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1397 - struct phy_device *phydev = ndev->phydev; 1398 - 1399 - if (priv->active_offloads & ENETC_F_QBV) 1400 - enetc_sched_speed_set(ndev); 1401 - 1402 - phy_print_status(phydev); 1403 - } 1404 - 1405 - static int enetc_phy_connect(struct net_device *ndev) 1406 - { 1407 - struct enetc_ndev_priv *priv = netdev_priv(ndev); 1408 - struct phy_device *phydev; 1409 1398 struct ethtool_eee edata; 1399 + int err; 1410 1400 1411 - if (!priv->phy_node) 1401 + if (!priv->phylink) 1412 1402 return 0; /* phy-less mode */ 1413 1403 1414 - phydev = of_phy_connect(ndev, priv->phy_node, &adjust_link, 1415 - 0, priv->if_mode); 1416 - if (!phydev) { 1404 + err = phylink_of_phy_connect(priv->phylink, priv->dev->of_node, 0); 1405 + if (err) { 1417 1406 dev_err(&ndev->dev, "could not attach to PHY\n"); 1418 - return -ENODEV; 1407 + return err; 1419 1408 } 1420 - 1421 - phy_attached_info(phydev); 1422 1409 1423 1410 /* disable EEE autoneg, until ENETC driver supports it */ 1424 1411 memset(&edata, 0, sizeof(struct ethtool_eee)); 1425 - phy_ethtool_set_eee(phydev, &edata); 1412 + phylink_ethtool_set_eee(priv->phylink, &edata); 1426 1413 1427 1414 return 0; 1428 1415 } ··· 1428 1443 enable_irq(irq); 1429 1444 } 1430 1445 1431 - if (ndev->phydev) 1432 - phy_start(ndev->phydev); 1446 + if (priv->phylink) 1447 + phylink_start(priv->phylink); 1433 1448 else 1434 1449 netif_carrier_on(ndev); 1435 1450 ··· 1445 1460 if (err) 1446 1461 return err; 1447 1462 1448 - err = enetc_phy_connect(ndev); 1463 + err = enetc_phylink_connect(ndev); 1449 1464 if (err) 1450 1465 goto err_phy_connect; 1451 1466 ··· 1475 1490 err_alloc_rx: 1476 1491 enetc_free_tx_resources(priv); 1477 1492 err_alloc_tx: 1478 - if (ndev->phydev) 1479 - phy_disconnect(ndev->phydev); 1493 + if (priv->phylink) 1494 + phylink_disconnect_phy(priv->phylink); 1480 1495 err_phy_connect: 1481 1496 enetc_free_irqs(priv); 1482 1497 ··· 1499 1514 napi_disable(&priv->int_vector[i]->napi); 1500 1515 } 1501 1516 1502 - if (ndev->phydev) 1503 - phy_stop(ndev->phydev); 1517 + if (priv->phylink) 1518 + phylink_stop(priv->phylink); 1504 1519 else 1505 1520 netif_carrier_off(ndev); 1506 1521 ··· 1514 1529 enetc_stop(ndev); 1515 1530 enetc_clear_bdrs(priv); 1516 1531 1517 - if (ndev->phydev) 1518 - phy_disconnect(ndev->phydev); 1532 + if (priv->phylink) 1533 + phylink_disconnect_phy(priv->phylink); 1519 1534 enetc_free_rxtx_rings(priv); 1520 1535 enetc_free_rx_resources(priv); 1521 1536 enetc_free_tx_resources(priv); ··· 1765 1780 1766 1781 int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) 1767 1782 { 1783 + struct enetc_ndev_priv *priv = netdev_priv(ndev); 1768 1784 #ifdef CONFIG_FSL_ENETC_PTP_CLOCK 1769 1785 if (cmd == SIOCSHWTSTAMP) 1770 1786 return enetc_hwtstamp_set(ndev, rq); ··· 1773 1787 return enetc_hwtstamp_get(ndev, rq); 1774 1788 #endif 1775 1789 1776 - if (!ndev->phydev) 1790 + if (!priv->phylink) 1777 1791 return -EOPNOTSUPP; 1778 - return phy_mii_ioctl(ndev->phydev, rq, cmd); 1792 + 1793 + return phylink_mii_ioctl(priv->phylink, rq, cmd); 1779 1794 } 1780 1795 1781 1796 int enetc_alloc_msix(struct enetc_ndev_priv *priv)
+4 -5
drivers/net/ethernet/freescale/enetc/enetc.h
··· 9 9 #include <linux/skbuff.h> 10 10 #include <linux/ethtool.h> 11 11 #include <linux/if_vlan.h> 12 - #include <linux/phy.h> 12 + #include <linux/phylink.h> 13 13 #include <linux/dim.h> 14 14 15 15 #include "enetc_hw.h" ··· 264 264 265 265 struct psfp_cap psfp_cap; 266 266 267 - struct device_node *phy_node; 268 - phy_interface_t if_mode; 267 + struct phylink *phylink; 269 268 int ic_mode; 270 269 u32 tx_ictt; 271 270 }; ··· 322 323 323 324 #ifdef CONFIG_FSL_ENETC_QOS 324 325 int enetc_setup_tc_taprio(struct net_device *ndev, void *type_data); 325 - void enetc_sched_speed_set(struct net_device *ndev); 326 + void enetc_sched_speed_set(struct enetc_ndev_priv *priv, int speed); 326 327 int enetc_setup_tc_cbs(struct net_device *ndev, void *type_data); 327 328 int enetc_setup_tc_txtime(struct net_device *ndev, void *type_data); 328 329 int enetc_setup_tc_block_cb(enum tc_setup_type type, void *type_data, ··· 387 388 388 389 #else 389 390 #define enetc_setup_tc_taprio(ndev, type_data) -EOPNOTSUPP 390 - #define enetc_sched_speed_set(ndev) (void)0 391 + #define enetc_sched_speed_set(priv, speed) (void)0 391 392 #define enetc_setup_tc_cbs(ndev, type_data) -EOPNOTSUPP 392 393 #define enetc_setup_tc_txtime(ndev, type_data) -EOPNOTSUPP 393 394 #define enetc_setup_tc_psfp(ndev, type_data) -EOPNOTSUPP
+24 -2
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
··· 686 686 return ret; 687 687 } 688 688 689 + static int enetc_get_link_ksettings(struct net_device *dev, 690 + struct ethtool_link_ksettings *cmd) 691 + { 692 + struct enetc_ndev_priv *priv = netdev_priv(dev); 693 + 694 + if (!priv->phylink) 695 + return -EOPNOTSUPP; 696 + 697 + return phylink_ethtool_ksettings_get(priv->phylink, cmd); 698 + } 699 + 700 + static int enetc_set_link_ksettings(struct net_device *dev, 701 + const struct ethtool_link_ksettings *cmd) 702 + { 703 + struct enetc_ndev_priv *priv = netdev_priv(dev); 704 + 705 + if (!priv->phylink) 706 + return -EOPNOTSUPP; 707 + 708 + return phylink_ethtool_ksettings_set(priv->phylink, cmd); 709 + } 710 + 689 711 static const struct ethtool_ops enetc_pf_ethtool_ops = { 690 712 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 691 713 ETHTOOL_COALESCE_MAX_FRAMES | ··· 726 704 .get_ringparam = enetc_get_ringparam, 727 705 .get_coalesce = enetc_get_coalesce, 728 706 .set_coalesce = enetc_set_coalesce, 729 - .get_link_ksettings = phy_ethtool_get_link_ksettings, 730 - .set_link_ksettings = phy_ethtool_set_link_ksettings, 707 + .get_link_ksettings = enetc_get_link_ksettings, 708 + .set_link_ksettings = enetc_set_link_ksettings, 731 709 .get_link = ethtool_op_get_link, 732 710 .get_ts_info = enetc_get_ts_info, 733 711 .get_wol = enetc_get_wol,
+191 -162
drivers/net/ethernet/freescale/enetc/enetc_pf.c
··· 482 482 enetc_port_wr(hw, ENETC_PSIVLANFMR, ENETC_PSIVLANFMR_VS); 483 483 } 484 484 485 - static void enetc_configure_port_mac(struct enetc_hw *hw, 486 - phy_interface_t phy_mode) 485 + static void enetc_configure_port_mac(struct enetc_hw *hw) 487 486 { 488 487 enetc_port_wr(hw, ENETC_PM0_MAXFRM, 489 488 ENETC_SET_MAXFRM(ENETC_RX_MAXFRM_SIZE)); ··· 491 492 enetc_port_wr(hw, ENETC_PTXMBAR, 2 * ENETC_MAC_MAXFRM_SIZE); 492 493 493 494 enetc_port_wr(hw, ENETC_PM0_CMD_CFG, ENETC_PM0_CMD_PHY_TX_EN | 494 - ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC | 495 - ENETC_PM0_TX_EN | ENETC_PM0_RX_EN); 495 + ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC); 496 496 497 497 enetc_port_wr(hw, ENETC_PM1_CMD_CFG, ENETC_PM0_CMD_PHY_TX_EN | 498 - ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC | 499 - ENETC_PM0_TX_EN | ENETC_PM0_RX_EN); 498 + ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC); 499 + } 500 + 501 + static void enetc_mac_config(struct enetc_hw *hw, phy_interface_t phy_mode) 502 + { 500 503 /* set auto-speed for RGMII */ 501 504 if (enetc_port_rd(hw, ENETC_PM0_IF_MODE) & ENETC_PMO_IFM_RG || 502 505 phy_interface_mode_is_rgmii(phy_mode)) ··· 506 505 507 506 if (phy_mode == PHY_INTERFACE_MODE_USXGMII) 508 507 enetc_port_wr(hw, ENETC_PM0_IF_MODE, ENETC_PM0_IFM_XGMII); 508 + } 509 + 510 + static void enetc_mac_enable(struct enetc_hw *hw, bool en) 511 + { 512 + u32 val = enetc_port_rd(hw, ENETC_PM0_CMD_CFG); 513 + 514 + val &= ~(ENETC_PM0_TX_EN | ENETC_PM0_RX_EN); 515 + val |= en ? (ENETC_PM0_TX_EN | ENETC_PM0_RX_EN) : 0; 516 + 517 + enetc_port_wr(hw, ENETC_PM0_CMD_CFG, val); 518 + enetc_port_wr(hw, ENETC_PM1_CMD_CFG, val); 509 519 } 510 520 511 521 static void enetc_configure_port_pmac(struct enetc_hw *hw) ··· 539 527 540 528 enetc_configure_port_pmac(hw); 541 529 542 - enetc_configure_port_mac(hw, pf->if_mode); 530 + enetc_configure_port_mac(hw); 543 531 544 532 enetc_port_si_configure(pf->si); 545 533 ··· 745 733 enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr); 746 734 } 747 735 748 - static int enetc_mdio_probe(struct enetc_pf *pf) 736 + static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np) 749 737 { 750 738 struct device *dev = &pf->si->pdev->dev; 751 739 struct enetc_mdio_priv *mdio_priv; 752 - struct device_node *np; 753 740 struct mii_bus *bus; 754 741 int err; 755 742 ··· 765 754 mdio_priv->mdio_base = ENETC_EMDIO_BASE; 766 755 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev)); 767 756 768 - np = of_get_child_by_name(dev->of_node, "mdio"); 769 - if (!np) { 770 - dev_err(dev, "MDIO node missing\n"); 771 - return -EINVAL; 772 - } 773 - 774 757 err = of_mdiobus_register(bus, np); 775 758 if (err) { 776 - of_node_put(np); 777 759 dev_err(dev, "cannot register MDIO bus\n"); 778 760 return err; 779 761 } 780 762 781 - of_node_put(np); 782 763 pf->mdio = bus; 783 764 784 765 return 0; ··· 782 779 mdiobus_unregister(pf->mdio); 783 780 } 784 781 785 - static int enetc_of_get_phy(struct enetc_pf *pf) 786 - { 787 - struct device *dev = &pf->si->pdev->dev; 788 - struct device_node *np = dev->of_node; 789 - struct device_node *mdio_np; 790 - int err; 791 - 792 - pf->phy_node = of_parse_phandle(np, "phy-handle", 0); 793 - if (!pf->phy_node) { 794 - if (!of_phy_is_fixed_link(np)) { 795 - dev_err(dev, "PHY not specified\n"); 796 - return -ENODEV; 797 - } 798 - 799 - err = of_phy_register_fixed_link(np); 800 - if (err < 0) { 801 - dev_err(dev, "fixed link registration failed\n"); 802 - return err; 803 - } 804 - 805 - pf->phy_node = of_node_get(np); 806 - } 807 - 808 - mdio_np = of_get_child_by_name(np, "mdio"); 809 - if (mdio_np) { 810 - of_node_put(mdio_np); 811 - err = enetc_mdio_probe(pf); 812 - if (err) { 813 - of_node_put(pf->phy_node); 814 - return err; 815 - } 816 - } 817 - 818 - err = of_get_phy_mode(np, &pf->if_mode); 819 - if (err) { 820 - dev_err(dev, "missing phy type\n"); 821 - of_node_put(pf->phy_node); 822 - if (of_phy_is_fixed_link(np)) 823 - of_phy_deregister_fixed_link(np); 824 - else 825 - enetc_mdio_remove(pf); 826 - 827 - return -EINVAL; 828 - } 829 - 830 - return 0; 831 - } 832 - 833 - static void enetc_of_put_phy(struct enetc_pf *pf) 834 - { 835 - struct device_node *np = pf->si->pdev->dev.of_node; 836 - 837 - if (np && of_phy_is_fixed_link(np)) 838 - of_phy_deregister_fixed_link(np); 839 - if (pf->phy_node) 840 - of_node_put(pf->phy_node); 841 - } 842 - 843 - static int enetc_imdio_init(struct enetc_pf *pf, bool is_c45) 782 + static int enetc_imdio_create(struct enetc_pf *pf) 844 783 { 845 784 struct device *dev = &pf->si->pdev->dev; 846 785 struct enetc_mdio_priv *mdio_priv; 847 - struct phy_device *pcs; 786 + struct lynx_pcs *pcs_lynx; 787 + struct mdio_device *pcs; 848 788 struct mii_bus *bus; 849 789 int err; 850 790 ··· 811 865 goto free_mdio_bus; 812 866 } 813 867 814 - pcs = get_phy_device(bus, 0, is_c45); 868 + pcs = mdio_device_create(bus, 0); 815 869 if (IS_ERR(pcs)) { 816 870 err = PTR_ERR(pcs); 817 - dev_err(dev, "cannot get internal PCS PHY (%d)\n", err); 871 + dev_err(dev, "cannot create pcs (%d)\n", err); 872 + goto unregister_mdiobus; 873 + } 874 + 875 + pcs_lynx = lynx_pcs_create(pcs); 876 + if (!pcs_lynx) { 877 + mdio_device_free(pcs); 878 + err = -ENOMEM; 879 + dev_err(dev, "cannot create lynx pcs (%d)\n", err); 818 880 goto unregister_mdiobus; 819 881 } 820 882 821 883 pf->imdio = bus; 822 - pf->pcs = pcs; 884 + pf->pcs = pcs_lynx; 823 885 824 886 return 0; 825 887 ··· 840 886 841 887 static void enetc_imdio_remove(struct enetc_pf *pf) 842 888 { 843 - if (pf->pcs) 844 - put_device(&pf->pcs->mdio.dev); 889 + if (pf->pcs) { 890 + mdio_device_free(pf->pcs->mdio); 891 + lynx_pcs_destroy(pf->pcs); 892 + } 845 893 if (pf->imdio) { 846 894 mdiobus_unregister(pf->imdio); 847 895 mdiobus_free(pf->imdio); 848 896 } 849 897 } 850 898 851 - static void enetc_configure_sgmii(struct phy_device *pcs) 899 + static bool enetc_port_has_pcs(struct enetc_pf *pf) 852 900 { 853 - /* SGMII spec requires tx_config_Reg[15:0] to be exactly 0x4001 854 - * for the MAC PCS in order to acknowledge the AN. 855 - */ 856 - phy_write(pcs, MII_ADVERTISE, ADVERTISE_SGMII | ADVERTISE_LPACK); 857 - 858 - phy_write(pcs, ENETC_PCS_IF_MODE, 859 - ENETC_PCS_IF_MODE_SGMII_EN | 860 - ENETC_PCS_IF_MODE_USE_SGMII_AN); 861 - 862 - /* Adjust link timer for SGMII */ 863 - phy_write(pcs, ENETC_PCS_LINK_TIMER1, ENETC_PCS_LINK_TIMER1_VAL); 864 - phy_write(pcs, ENETC_PCS_LINK_TIMER2, ENETC_PCS_LINK_TIMER2_VAL); 865 - 866 - phy_write(pcs, MII_BMCR, BMCR_ANRESTART | BMCR_ANENABLE); 901 + return (pf->if_mode == PHY_INTERFACE_MODE_SGMII || 902 + pf->if_mode == PHY_INTERFACE_MODE_2500BASEX || 903 + pf->if_mode == PHY_INTERFACE_MODE_USXGMII); 867 904 } 868 905 869 - static void enetc_configure_2500basex(struct phy_device *pcs) 906 + static int enetc_mdiobus_create(struct enetc_pf *pf) 870 907 { 871 - phy_write(pcs, ENETC_PCS_IF_MODE, 872 - ENETC_PCS_IF_MODE_SGMII_EN | 873 - ENETC_PCS_IF_MODE_SGMII_SPEED(ENETC_PCS_SPEED_2500)); 874 - 875 - phy_write(pcs, MII_BMCR, BMCR_SPEED1000 | BMCR_FULLDPLX | BMCR_RESET); 876 - } 877 - 878 - static void enetc_configure_usxgmii(struct phy_device *pcs) 879 - { 880 - /* Configure device ability for the USXGMII Replicator */ 881 - phy_write_mmd(pcs, MDIO_MMD_VEND2, MII_ADVERTISE, 882 - ADVERTISE_SGMII | ADVERTISE_LPACK | 883 - MDIO_USXGMII_FULL_DUPLEX); 884 - 885 - /* Restart PCS AN */ 886 - phy_write_mmd(pcs, MDIO_MMD_VEND2, MII_BMCR, 887 - BMCR_RESET | BMCR_ANENABLE | BMCR_ANRESTART); 888 - } 889 - 890 - static int enetc_configure_serdes(struct enetc_ndev_priv *priv) 891 - { 892 - bool is_c45 = priv->if_mode == PHY_INTERFACE_MODE_USXGMII; 893 - struct enetc_pf *pf = enetc_si_priv(priv->si); 908 + struct device *dev = &pf->si->pdev->dev; 909 + struct device_node *mdio_np; 894 910 int err; 895 911 896 - if (priv->if_mode != PHY_INTERFACE_MODE_SGMII && 897 - priv->if_mode != PHY_INTERFACE_MODE_2500BASEX && 898 - priv->if_mode != PHY_INTERFACE_MODE_USXGMII) 899 - return 0; 912 + mdio_np = of_get_child_by_name(dev->of_node, "mdio"); 913 + if (mdio_np) { 914 + err = enetc_mdio_probe(pf, mdio_np); 900 915 901 - err = enetc_imdio_init(pf, is_c45); 902 - if (err) 903 - return err; 916 + of_node_put(mdio_np); 917 + if (err) 918 + return err; 919 + } 904 920 905 - switch (priv->if_mode) { 906 - case PHY_INTERFACE_MODE_SGMII: 907 - enetc_configure_sgmii(pf->pcs); 908 - break; 909 - case PHY_INTERFACE_MODE_2500BASEX: 910 - enetc_configure_2500basex(pf->pcs); 911 - break; 912 - case PHY_INTERFACE_MODE_USXGMII: 913 - enetc_configure_usxgmii(pf->pcs); 914 - break; 915 - default: 916 - dev_err(&pf->si->pdev->dev, "Unsupported link mode %s\n", 917 - phy_modes(priv->if_mode)); 921 + if (enetc_port_has_pcs(pf)) { 922 + err = enetc_imdio_create(pf); 923 + if (err) { 924 + enetc_mdio_remove(pf); 925 + return err; 926 + } 918 927 } 919 928 920 929 return 0; 921 930 } 922 931 923 - static void enetc_teardown_serdes(struct enetc_ndev_priv *priv) 932 + static void enetc_mdiobus_destroy(struct enetc_pf *pf) 933 + { 934 + enetc_mdio_remove(pf); 935 + enetc_imdio_remove(pf); 936 + } 937 + 938 + static void enetc_pl_mac_validate(struct phylink_config *config, 939 + unsigned long *supported, 940 + struct phylink_link_state *state) 941 + { 942 + __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; 943 + 944 + if (state->interface != PHY_INTERFACE_MODE_NA && 945 + state->interface != PHY_INTERFACE_MODE_INTERNAL && 946 + state->interface != PHY_INTERFACE_MODE_SGMII && 947 + state->interface != PHY_INTERFACE_MODE_2500BASEX && 948 + state->interface != PHY_INTERFACE_MODE_USXGMII && 949 + !phy_interface_mode_is_rgmii(state->interface)) { 950 + bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS); 951 + return; 952 + } 953 + 954 + phylink_set_port_modes(mask); 955 + phylink_set(mask, Autoneg); 956 + phylink_set(mask, Pause); 957 + phylink_set(mask, Asym_Pause); 958 + phylink_set(mask, 10baseT_Half); 959 + phylink_set(mask, 10baseT_Full); 960 + phylink_set(mask, 100baseT_Half); 961 + phylink_set(mask, 100baseT_Full); 962 + phylink_set(mask, 100baseT_Half); 963 + phylink_set(mask, 1000baseT_Half); 964 + phylink_set(mask, 1000baseT_Full); 965 + 966 + if (state->interface == PHY_INTERFACE_MODE_INTERNAL || 967 + state->interface == PHY_INTERFACE_MODE_2500BASEX || 968 + state->interface == PHY_INTERFACE_MODE_USXGMII) { 969 + phylink_set(mask, 2500baseT_Full); 970 + phylink_set(mask, 2500baseX_Full); 971 + } 972 + 973 + bitmap_and(supported, supported, mask, 974 + __ETHTOOL_LINK_MODE_MASK_NBITS); 975 + bitmap_and(state->advertising, state->advertising, mask, 976 + __ETHTOOL_LINK_MODE_MASK_NBITS); 977 + } 978 + 979 + static void enetc_pl_mac_config(struct phylink_config *config, 980 + unsigned int mode, 981 + const struct phylink_link_state *state) 982 + { 983 + struct enetc_pf *pf = phylink_to_enetc_pf(config); 984 + struct enetc_ndev_priv *priv; 985 + 986 + enetc_mac_config(&pf->si->hw, state->interface); 987 + 988 + priv = netdev_priv(pf->si->ndev); 989 + if (pf->pcs) 990 + phylink_set_pcs(priv->phylink, &pf->pcs->pcs); 991 + } 992 + 993 + static void enetc_pl_mac_link_up(struct phylink_config *config, 994 + struct phy_device *phy, unsigned int mode, 995 + phy_interface_t interface, int speed, 996 + int duplex, bool tx_pause, bool rx_pause) 997 + { 998 + struct enetc_pf *pf = phylink_to_enetc_pf(config); 999 + struct enetc_ndev_priv *priv; 1000 + 1001 + priv = netdev_priv(pf->si->ndev); 1002 + if (priv->active_offloads & ENETC_F_QBV) 1003 + enetc_sched_speed_set(priv, speed); 1004 + 1005 + enetc_mac_enable(&pf->si->hw, true); 1006 + } 1007 + 1008 + static void enetc_pl_mac_link_down(struct phylink_config *config, 1009 + unsigned int mode, 1010 + phy_interface_t interface) 1011 + { 1012 + struct enetc_pf *pf = phylink_to_enetc_pf(config); 1013 + 1014 + enetc_mac_enable(&pf->si->hw, false); 1015 + } 1016 + 1017 + static const struct phylink_mac_ops enetc_mac_phylink_ops = { 1018 + .validate = enetc_pl_mac_validate, 1019 + .mac_config = enetc_pl_mac_config, 1020 + .mac_link_up = enetc_pl_mac_link_up, 1021 + .mac_link_down = enetc_pl_mac_link_down, 1022 + }; 1023 + 1024 + static int enetc_phylink_create(struct enetc_ndev_priv *priv) 924 1025 { 925 1026 struct enetc_pf *pf = enetc_si_priv(priv->si); 1027 + struct device *dev = &pf->si->pdev->dev; 1028 + struct phylink *phylink; 1029 + int err; 926 1030 927 - enetc_imdio_remove(pf); 1031 + pf->phylink_config.dev = &priv->ndev->dev; 1032 + pf->phylink_config.type = PHYLINK_NETDEV; 1033 + 1034 + phylink = phylink_create(&pf->phylink_config, 1035 + of_fwnode_handle(dev->of_node), 1036 + pf->if_mode, &enetc_mac_phylink_ops); 1037 + if (IS_ERR(phylink)) { 1038 + err = PTR_ERR(phylink); 1039 + return err; 1040 + } 1041 + 1042 + priv->phylink = phylink; 1043 + 1044 + return 0; 1045 + } 1046 + 1047 + static void enetc_phylink_destroy(struct enetc_ndev_priv *priv) 1048 + { 1049 + if (priv->phylink) 1050 + phylink_destroy(priv->phylink); 928 1051 } 929 1052 930 1053 static int enetc_pf_probe(struct pci_dev *pdev, ··· 1035 1004 pf->si = si; 1036 1005 pf->total_vfs = pci_sriov_get_totalvfs(pdev); 1037 1006 1038 - err = enetc_of_get_phy(pf); 1039 - if (err) 1040 - dev_warn(&pdev->dev, "Fallback to PHY-less operation\n"); 1041 - 1042 1007 enetc_configure_port(pf); 1043 1008 1044 1009 enetc_get_si_caps(si); ··· 1049 1022 enetc_pf_netdev_setup(si, ndev, &enetc_ndev_ops); 1050 1023 1051 1024 priv = netdev_priv(ndev); 1052 - priv->phy_node = pf->phy_node; 1053 - priv->if_mode = pf->if_mode; 1054 1025 1055 1026 enetc_init_si_rings_params(priv); 1056 1027 ··· 1064 1039 goto err_alloc_msix; 1065 1040 } 1066 1041 1067 - err = enetc_configure_serdes(priv); 1068 - if (err) 1069 - dev_warn(&pdev->dev, "Attempted SerDes config but failed\n"); 1042 + if (!of_get_phy_mode(pdev->dev.of_node, &pf->if_mode)) { 1043 + err = enetc_mdiobus_create(pf); 1044 + if (err) 1045 + goto err_mdiobus_create; 1046 + 1047 + err = enetc_phylink_create(priv); 1048 + if (err) 1049 + goto err_phylink_create; 1050 + } 1070 1051 1071 1052 err = register_netdev(ndev); 1072 1053 if (err) 1073 1054 goto err_reg_netdev; 1074 1055 1075 - netif_carrier_off(ndev); 1076 - 1077 1056 return 0; 1078 1057 1079 1058 err_reg_netdev: 1080 - enetc_teardown_serdes(priv); 1059 + enetc_phylink_destroy(priv); 1060 + err_phylink_create: 1061 + enetc_mdiobus_destroy(pf); 1062 + err_mdiobus_create: 1081 1063 enetc_free_msix(priv); 1082 1064 err_alloc_msix: 1083 1065 enetc_free_si_resources(priv); ··· 1092 1060 si->ndev = NULL; 1093 1061 free_netdev(ndev); 1094 1062 err_alloc_netdev: 1095 - enetc_mdio_remove(pf); 1096 - enetc_of_put_phy(pf); 1097 1063 err_map_pf_space: 1098 1064 enetc_pci_remove(pdev); 1099 1065 ··· 1104 1074 struct enetc_pf *pf = enetc_si_priv(si); 1105 1075 struct enetc_ndev_priv *priv; 1106 1076 1077 + priv = netdev_priv(si->ndev); 1078 + enetc_phylink_destroy(priv); 1079 + enetc_mdiobus_destroy(pf); 1080 + 1107 1081 if (pf->num_vfs) 1108 1082 enetc_sriov_configure(pdev, 0); 1109 1083 1110 - priv = netdev_priv(si->ndev); 1111 1084 unregister_netdev(si->ndev); 1112 - 1113 - enetc_teardown_serdes(priv); 1114 - enetc_mdio_remove(pf); 1115 - enetc_of_put_phy(pf); 1116 1085 1117 1086 enetc_free_msix(priv); 1118 1087
+6 -2
drivers/net/ethernet/freescale/enetc/enetc_pf.h
··· 2 2 /* Copyright 2017-2019 NXP */ 3 3 4 4 #include "enetc.h" 5 + #include <linux/pcs-lynx.h> 5 6 6 7 #define ENETC_PF_NUM_RINGS 8 7 8 ··· 46 45 47 46 struct mii_bus *mdio; /* saved for cleanup */ 48 47 struct mii_bus *imdio; 49 - struct phy_device *pcs; 48 + struct lynx_pcs *pcs; 50 49 51 - struct device_node *phy_node; 52 50 phy_interface_t if_mode; 51 + struct phylink_config phylink_config; 53 52 }; 53 + 54 + #define phylink_to_enetc_pf(config) \ 55 + container_of((config), struct enetc_pf, phylink_config) 54 56 55 57 int enetc_msg_psi_init(struct enetc_pf *pf); 56 58 void enetc_msg_psi_free(struct enetc_pf *pf);
+3 -6
drivers/net/ethernet/freescale/enetc/enetc_qos.c
··· 15 15 & ENETC_QBV_MAX_GCL_LEN_MASK; 16 16 } 17 17 18 - void enetc_sched_speed_set(struct net_device *ndev) 18 + void enetc_sched_speed_set(struct enetc_ndev_priv *priv, int speed) 19 19 { 20 - struct enetc_ndev_priv *priv = netdev_priv(ndev); 21 - struct phy_device *phydev = ndev->phydev; 22 20 u32 old_speed = priv->speed; 23 - u32 speed, pspeed; 21 + u32 pspeed; 24 22 25 - if (phydev->speed == old_speed) 23 + if (speed == old_speed) 26 24 return; 27 25 28 - speed = phydev->speed; 29 26 switch (speed) { 30 27 case SPEED_1000: 31 28 pspeed = ENETC_PMR_PSPEED_1000M;