]> www.infradead.org Git - users/hch/misc.git/commitdiff
net: enetc: use generic interfaces to get phc_index for ENETC v1
authorWei Fang <wei.fang@nxp.com>
Fri, 19 Sep 2025 08:45:09 +0000 (16:45 +0800)
committerJakub Kicinski <kuba@kernel.org>
Mon, 22 Sep 2025 18:49:16 +0000 (11:49 -0700)
The commit 61f132ca8c46 ("ptp: add helpers to get the phc_index by
of_node or dev") has added two generic interfaces to get the phc_index
of the PTP clock. This eliminates the need for PTP device drivers to
provide custom APIs for consumers to retrieve the phc_index. This has
already been implemented for ENETC v4 and is also applicable to ENETC
v1. Therefore, the global variable enetc_phc_index is removed from the
driver. ENETC v1 now uses the same interface as v4 to get phc_index.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20250919084509.1846513-3-wei.fang@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/freescale/enetc/enetc.h
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
drivers/net/ethernet/freescale/enetc/enetc_ptp.c

index 815afdc2ec239704c442551f68bfa7436cc0e28e..0ec010a7d640377cde72cd60f885f6a3055fe804 100644 (file)
@@ -493,9 +493,6 @@ struct enetc_msg_cmd_set_primary_mac {
 
 #define ENETC_CBDR_TIMEOUT     1000 /* usecs */
 
-/* PTP driver exports */
-extern int enetc_phc_index;
-
 /* SI common */
 u32 enetc_port_mac_rd(struct enetc_si *si, u32 reg);
 void enetc_port_mac_wr(struct enetc_si *si, u32 reg, u32 val);
index 445bfd032e0f1c4d6b4c6992a6cae585956ad31c..71d052de669abc1e82b00bec81659a1138e9a57e 100644 (file)
@@ -880,7 +880,7 @@ static int enetc_set_coalesce(struct net_device *ndev,
        return 0;
 }
 
-static int enetc4_get_phc_index_by_pdev(struct enetc_si *si)
+static int enetc_get_phc_index_by_pdev(struct enetc_si *si)
 {
        struct pci_bus *bus = si->pdev->bus;
        struct pci_dev *timer_pdev;
@@ -888,6 +888,9 @@ static int enetc4_get_phc_index_by_pdev(struct enetc_si *si)
        int phc_index;
 
        switch (si->revision) {
+       case ENETC_REV_1_0:
+               devfn = PCI_DEVFN(0, 4);
+               break;
        case ENETC_REV_4_1:
                devfn = PCI_DEVFN(24, 0);
                break;
@@ -906,18 +909,18 @@ static int enetc4_get_phc_index_by_pdev(struct enetc_si *si)
        return phc_index;
 }
 
-static int enetc4_get_phc_index(struct enetc_si *si)
+static int enetc_get_phc_index(struct enetc_si *si)
 {
        struct device_node *np = si->pdev->dev.of_node;
        struct device_node *timer_np;
        int phc_index;
 
        if (!np)
-               return enetc4_get_phc_index_by_pdev(si);
+               return enetc_get_phc_index_by_pdev(si);
 
        timer_np = of_parse_phandle(np, "ptp-timer", 0);
        if (!timer_np)
-               return enetc4_get_phc_index_by_pdev(si);
+               return enetc_get_phc_index_by_pdev(si);
 
        phc_index = ptp_clock_index_by_of_node(timer_np);
        of_node_put(timer_np);
@@ -950,22 +953,13 @@ static int enetc_get_ts_info(struct net_device *ndev,
 {
        struct enetc_ndev_priv *priv = netdev_priv(ndev);
        struct enetc_si *si = priv->si;
-       int *phc_idx;
 
        if (!enetc_ptp_clock_is_enabled(si))
                goto timestamp_tx_sw;
 
-       if (is_enetc_rev1(si)) {
-               phc_idx = symbol_get(enetc_phc_index);
-               if (phc_idx) {
-                       info->phc_index = *phc_idx;
-                       symbol_put(enetc_phc_index);
-               }
-       } else {
-               info->phc_index = enetc4_get_phc_index(si);
-               if (info->phc_index < 0)
-                       goto timestamp_tx_sw;
-       }
+       info->phc_index = enetc_get_phc_index(si);
+       if (info->phc_index < 0)
+               goto timestamp_tx_sw;
 
        enetc_get_ts_generic_info(ndev, info);
 
index 5243fc031058904b27b0cf208a9d9ec5a6c58aa9..b8413d3b4f16e69744405230166e28000798d65f 100644 (file)
@@ -7,9 +7,6 @@
 
 #include "enetc.h"
 
-int enetc_phc_index = -1;
-EXPORT_SYMBOL_GPL(enetc_phc_index);
-
 static struct ptp_clock_info enetc_ptp_caps = {
        .owner          = THIS_MODULE,
        .name           = "ENETC PTP clock",
@@ -92,7 +89,6 @@ static int enetc_ptp_probe(struct pci_dev *pdev,
        if (err)
                goto err_no_clock;
 
-       enetc_phc_index = ptp_qoriq->phc_index;
        pci_set_drvdata(pdev, ptp_qoriq);
 
        return 0;
@@ -118,7 +114,6 @@ static void enetc_ptp_remove(struct pci_dev *pdev)
 {
        struct ptp_qoriq *ptp_qoriq = pci_get_drvdata(pdev);
 
-       enetc_phc_index = -1;
        ptp_qoriq_free(ptp_qoriq);
        pci_free_irq_vectors(pdev);
        kfree(ptp_qoriq);