net: cpsw: isolate cpsw_ndo_ioctl() to just the old driver
authorVladimir Oltean <vladimir.oltean@nxp.com>
Mon, 12 May 2025 11:44:22 +0000 (14:44 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 15 May 2025 02:41:46 +0000 (19:41 -0700)
cpsw->slaves[slave_no].phy should be equal to netdev->phydev, because it
is assigned from phy_attach_direct(). The latter is indirectly called
from the two identically named cpsw_slave_open() functions, one in
cpsw.c and another in cpsw_new.c.

Thus, the driver should not need custom logic to find the PHY, the core
can find it, and phy_do_ioctl_running() achieves exactly that.

However, that is only the case for cpsw_new and for the cpsw driver in
dual EMAC mode. This is explained in more detail in the previous commit.
Thus, allow the simpler core logic to execute for cpsw_new, and move
cpsw_ndo_ioctl() to cpsw.c.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20250512114422.4176010-2-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/ti/cpsw.c
drivers/net/ethernet/ti/cpsw_new.c
drivers/net/ethernet/ti/cpsw_priv.c
drivers/net/ethernet/ti/cpsw_priv.h

index b71352689768750bc9f30a39cbe3b8312a055bcd..54c24cd3d3be639c90111856efaf154cd77f7ee4 100644 (file)
@@ -1156,6 +1156,27 @@ static void cpsw_ndo_poll_controller(struct net_device *ndev)
 }
 #endif
 
+/* We need a custom implementation of phy_do_ioctl_running() because in switch
+ * mode, dev->phydev may be different than the phy of the active_slave. We need
+ * to operate on the locally saved phy instead.
+ */
+static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
+{
+       struct cpsw_priv *priv = netdev_priv(dev);
+       struct cpsw_common *cpsw = priv->cpsw;
+       int slave_no = cpsw_slave_index(cpsw, priv);
+       struct phy_device *phy;
+
+       if (!netif_running(dev))
+               return -EINVAL;
+
+       phy = cpsw->slaves[slave_no].phy;
+       if (phy)
+               return phy_mii_ioctl(phy, req, cmd);
+
+       return -EOPNOTSUPP;
+}
+
 static const struct net_device_ops cpsw_netdev_ops = {
        .ndo_open               = cpsw_ndo_open,
        .ndo_stop               = cpsw_ndo_stop,
index f5b74d066f0eb60e713772a2e796b8eb2aa07b25..8b9e2078c6025a099e0f90d4d80395b7622cf0f6 100644 (file)
@@ -1132,7 +1132,7 @@ static const struct net_device_ops cpsw_netdev_ops = {
        .ndo_stop               = cpsw_ndo_stop,
        .ndo_start_xmit         = cpsw_ndo_start_xmit,
        .ndo_set_mac_address    = cpsw_ndo_set_mac_address,
-       .ndo_eth_ioctl          = cpsw_ndo_ioctl,
+       .ndo_eth_ioctl          = phy_do_ioctl_running,
        .ndo_validate_addr      = eth_validate_addr,
        .ndo_tx_timeout         = cpsw_ndo_tx_timeout,
        .ndo_set_rx_mode        = cpsw_ndo_set_rx_mode,
index 8e17da12d8f522ab98d5754385b8db43d17eac5f..bc4fdf17a99ec0fcf3273e0243be2a0e4fa47861 100644 (file)
@@ -710,23 +710,6 @@ int cpsw_hwtstamp_set(struct net_device *dev,
 }
 #endif /*CONFIG_TI_CPTS*/
 
-int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
-{
-       struct cpsw_priv *priv = netdev_priv(dev);
-       struct cpsw_common *cpsw = priv->cpsw;
-       int slave_no = cpsw_slave_index(cpsw, priv);
-       struct phy_device *phy;
-
-       if (!netif_running(dev))
-               return -EINVAL;
-
-       phy = cpsw->slaves[slave_no].phy;
-       if (phy)
-               return phy_mii_ioctl(phy, req, cmd);
-
-       return -EOPNOTSUPP;
-}
-
 int cpsw_ndo_set_tx_maxrate(struct net_device *ndev, int queue, u32 rate)
 {
        struct cpsw_priv *priv = netdev_priv(ndev);
index b23f980326699bcdeddc9deaefcd96cb53c5a89a..91add8925e235c6cf5542fde11f3383b9234c872 100644 (file)
@@ -461,7 +461,6 @@ void soft_reset(const char *module, void __iomem *reg);
 void cpsw_set_slave_mac(struct cpsw_slave *slave, struct cpsw_priv *priv);
 void cpsw_ndo_tx_timeout(struct net_device *ndev, unsigned int txqueue);
 int cpsw_need_resplit(struct cpsw_common *cpsw);
-int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd);
 int cpsw_ndo_set_tx_maxrate(struct net_device *ndev, int queue, u32 rate);
 int cpsw_ndo_setup_tc(struct net_device *ndev, enum tc_setup_type type,
                      void *type_data);