Skip to contentSkip to conversation

ti: netcp: convert to ndo_hwtstamp callbacks

PATCH Applied Vadim Fedorenko 3 participants 6 messages Nov 3, 2025 – Nov 5, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ti: netcp: convert to ndo_hwtstamp callbacks

Convert TI NetCP driver to use ndo_hwtstamp_get()/ndo_hwtstamp_set() callbacks. The logic is slightly changed, because I believe the original logic was not really correct. Config reading part is using the very first module to get the configuration instead of iterating over all of them and keep the last one as the configuration is supposed to be identical for all modules. HW timestamp config set path is now trying to configure all modules, but in case of error from one module it adds extack message. This way the configuration will be as synchronized as possible.

There are only 2 modules using netcp core infrastructure, and both use the very same function to configure HW timestamping, so no actual difference in behavior is expected.

---
v1 -> v2:
- avoid changing logic and hiding errors. keep the call failing after the first error

---
 drivers/net/ethernet/ti/netcp.h       |  5 ++
 drivers/net/ethernet/ti/netcp_core.c  | 58 +++++++++++++++++++++
 drivers/net/ethernet/ti/netcp_ethss.c | 72 +++++++++++++++------------
 3 files changed, 103 insertions(+), 32 deletions(-)
drivers/net/ethernet/ti/netcp.h +5 -0
index 7007eb8bed36..b9cbd3b4a8a2 100644
@@ -207,6 +207,11 @@ struct netcp_module {
 	int	(*del_vid)(void *intf_priv, int vid);
 	int	(*ioctl)(void *intf_priv, struct ifreq *req, int cmd);
 	int	(*set_rx_mode)(void *intf_priv, bool promisc);
+	int	(*hwtstamp_get)(void *intf_priv,
+				struct kernel_hwtstamp_config *cfg);
+	int	(*hwtstamp_set)(void *intf_priv,
+				struct kernel_hwtstamp_config *cfg,
+				struct netlink_ext_ack *extack);
 
 	/* used internally */
 	struct list_head	module_list;
drivers/net/ethernet/ti/netcp_core.c +58 -0

70 lines not on this page · raw message

drivers/net/ethernet/ti/netcp_ethss.c +40 -32

146 lines not on this page · raw message

Signature · 1 line
2.47.3
#1 lore raw
Quoted 19 lines · On Mon, 3 Nov 2025 17:29:02 +0000 Vadim Fedorenko <[email protected]>…

Convert TI NetCP driver to use ndo_hwtstamp_get()/ndo_hwtstamp_set() callbacks. The logic is slightly changed, because I believe the original logic was not really correct. Config reading part is using the very first module to get the configuration instead of iterating over all of them and keep the last one as the configuration is supposed to be identical for all modules. HW timestamp config set path is now trying to configure all modules, but in case of error from one module it adds extack message. This way the configuration will be as synchronized as possible.

There are only 2 modules using netcp core infrastructure, and both use the very same function to configure HW timestamping, so no actual difference in behavior is expected.

---
v1 -> v2:
- avoid changing logic and hiding errors. keep the call failing after the first error
---

...

Quoted 12 lines
drivers/net/ethernet/ti/netcp_core.c +11 -0
+
+	for_each_module(netcp, intf_modpriv) {
+		module = intf_modpriv->netcp_module;
+		if (!module->hwtstamp_set)
+			continue;
+
+		err = module->hwtstamp_set(intf_modpriv->module_priv, config,
+					   extack);
+		if ((err < 0) && (err != -EOPNOTSUPP)) {
+			NL_SET_ERR_MSG_WEAK_MOD(extack,
+						"At least one module failed

to setup HW timestamps");

drivers/net/ethernet/ti/netcp_core.c static int netcp_ndo_stop(struct net_device *ndev) · line 1830

Quoted 2 lines
drivers/net/ethernet/ti/netcp_core.c +2 -0
+			ret = err;
+			goto out;

Why don't you use break.

Quoted 9 lines
drivers/net/ethernet/ti/netcp_core.c +9 -0
+		}
+		if (err == 0)
+			ret = err;
+	}
+
+out:
+	return (ret == 0) ? 0 : err;
+}
+

...

Quoted 13 lines
(quoted diff) +1 -1
-static int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *ifr)
+static int gbe_hwtstamp_set(void *intf_priv, struct kernel_hwtstamp_config

*cfg,

drivers/net/ethernet/ti/netcp_ethss.c +4 -4
+			    struct netlink_ext_ack *extack)
 {
-	struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
-	struct cpts *cpts = gbe_dev->cpts;
-	struct hwtstamp_config cfg;
+	struct gbe_intf *gbe_intf = intf_priv;
+	struct gbe_priv *gbe_dev;
+	struct phy_device *phy;
 
-	if (!cpts)

drivers/net/ethernet/ti/netcp_ethss.c static void gbe_hwtstamp(struct gbe_intf *gbe_intf) · line 2660

Quoted 10 lines
drivers/net/ethernet/ti/netcp_ethss.c +6 -2
+	gbe_dev = gbe_intf->gbe_dev;
+
+	if (!gbe_dev->cpts)
 		return -EOPNOTSUPP;
 
-	if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
-		return -EFAULT;
+	phy = gbe_intf->slave->phy;
+	if (phy_has_hwtstamp(phy))
+		return phy->mii_ts->hwtstamp(phy->mii_ts, cfg, extack);

Sorry to come back to this but the choice of using PHY or MAC timestamping is done in the core. Putting this here may conflict with the core.
I know this driver has kind of a weird PHYs management through slave description but we shouldn't let the MAC driver call the PHY hwtstamp ops. If there is indeed an issue due to the weird development of this driver, people will write a patch specifically tackling this issue and maybe (by luck) refactoring this driver.

Anyway, this was not in the driver before, so I think we should not make this change in this patch.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#2 lore raw
Quoted 25 lines · Kory Maincent
Quoted 19 lines · On Mon, 3 Nov 2025 17:29:02 +0000 Vadim Fedorenko <[email protected]>…

Convert TI NetCP driver to use ndo_hwtstamp_get()/ndo_hwtstamp_set() callbacks. The logic is slightly changed, because I believe the original logic was not really correct. Config reading part is using the very first module to get the configuration instead of iterating over all of them and keep the last one as the configuration is supposed to be identical for all modules. HW timestamp config set path is now trying to configure all modules, but in case of error from one module it adds extack message. This way the configuration will be as synchronized as possible.

There are only 2 modules using netcp core infrastructure, and both use the very same function to configure HW timestamping, so no actual difference in behavior is expected.

---
v1 -> v2:
- avoid changing logic and hiding errors. keep the call failing after the first error
---

...

Quoted 16 lines
Quoted 12 lines
drivers/net/ethernet/ti/netcp_core.c +11 -0
+
+	for_each_module(netcp, intf_modpriv) {
+		module = intf_modpriv->netcp_module;
+		if (!module->hwtstamp_set)
+			continue;
+
+		err = module->hwtstamp_set(intf_modpriv->module_priv, config,
+					   extack);
+		if ((err < 0) && (err != -EOPNOTSUPP)) {
+			NL_SET_ERR_MSG_WEAK_MOD(extack,
+						"At least one module failed

to setup HW timestamps");

drivers/net/ethernet/ti/netcp_core.c static int netcp_ndo_stop(struct net_device *ndev) · line 1830

Quoted 2 lines
drivers/net/ethernet/ti/netcp_core.c +2 -0
+			ret = err;
+			goto out;

Why don't you use break.

That's the original code, I tried to make as less changes as possible

Quoted 45 lines
Quoted 10 lines
drivers/net/ethernet/ti/netcp_core.c +9 -0
+		}
+		if (err == 0)
+			ret = err;
+	}
+
+out:
+	return (ret == 0) ? 0 : err;
+}
+

...

Quoted 13 lines
(quoted diff) +1 -1
-static int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *ifr)
+static int gbe_hwtstamp_set(void *intf_priv, struct kernel_hwtstamp_config

*cfg,

drivers/net/ethernet/ti/netcp_ethss.c +4 -4
+			    struct netlink_ext_ack *extack)
  {
-	struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
-	struct cpts *cpts = gbe_dev->cpts;
-	struct hwtstamp_config cfg;
+	struct gbe_intf *gbe_intf = intf_priv;
+	struct gbe_priv *gbe_dev;
+	struct phy_device *phy;
 
-	if (!cpts)

drivers/net/ethernet/ti/netcp_ethss.c static void gbe_hwtstamp(struct gbe_intf *gbe_intf) · line 2660

Quoted 10 lines
drivers/net/ethernet/ti/netcp_ethss.c +6 -2
+	gbe_dev = gbe_intf->gbe_dev;
+
+	if (!gbe_dev->cpts)
  		return -EOPNOTSUPP;
 
-	if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
-		return -EFAULT;
+	phy = gbe_intf->slave->phy;
+	if (phy_has_hwtstamp(phy))
+		return phy->mii_ts->hwtstamp(phy->mii_ts, cfg, extack);

Sorry to come back to this but the choice of using PHY or MAC timestamping is done in the core. Putting this here may conflict with the core.
I know this driver has kind of a weird PHYs management through slave description but we shouldn't let the MAC driver call the PHY hwtstamp ops. If there is indeed an issue due to the weird development of this driver, people will write a patch specifically tackling this issue and maybe (by luck) refactoring this driver.

Quoted 2 lines

Anyway, this was not in the driver before, so I think we should not make this change in this patch.

Well, that was actually in the original code:

static int gbe_ioctl(void *intf_priv, struct ifreq *req, int cmd)

{
        struct gbe_intf *gbe_intf = intf_priv;
        struct phy_device *phy = gbe_intf->slave->phy;

        if (!phy_has_hwtstamp(phy)) {
                switch (cmd) {
                case SIOCGHWTSTAMP:
                        return gbe_hwtstamp_get(gbe_intf, req);
                case SIOCSHWTSTAMP:
                        return gbe_hwtstamp_set(gbe_intf, req);
                }
        }

        if (phy)
                return phy_mii_ioctl(phy, req, cmd);

        return -EOPNOTSUPP;
}

SIOCGHWTSTAMP/SIOCSHWTSTAMP were sent to gbe functions only when there was no support for hwtstamps on phy layer. The original flow of the call is:

netcp_ndo_ioctl -> gbe_ioctl -> gbe_hwtstamp_*/phy_mii_ioctl

where netcp_ndo_ioctl operating over netdev while other function operating with other objects, with phy taken from gbe_intf.

Checking on init part of phy devices, I found that the only phydev allocated structure is stored in gbe_slave object, which is definitely not accessible from the core. I haven't found any assignments to net_device->phydev in neither netcp_core.c nor netcp_ethss.c. Even though there are checks for some phy functions from netdev->phydev in RX and TX paths, I'm not quite sure it works properly.

I decided to keep the original logic here with checking phy from gbe_intf->slave.

Reviewed-by
#3 lore raw
Quoted 91 lines · On Tue, 4 Nov 2025 12:15:32 +0000 Vadim Fedorenko <[email protected]>…
Quoted 34 lines · Kory Maincent
Quoted 19 lines · On Mon, 3 Nov 2025 17:29:02 +0000 Vadim Fedorenko <[email protected]>…

Convert TI NetCP driver to use ndo_hwtstamp_get()/ndo_hwtstamp_set() callbacks. The logic is slightly changed, because I believe the original logic was not really correct. Config reading part is using the very first module to get the configuration instead of iterating over all of them and keep the last one as the configuration is supposed to be identical for all modules. HW timestamp config set path is now trying to configure all modules, but in case of error from one module it adds extack message. This way the configuration will be as synchronized as possible.

There are only 2 modules using netcp core infrastructure, and both use the very same function to configure HW timestamping, so no actual difference in behavior is expected.

---
v1 -> v2:
- avoid changing logic and hiding errors. keep the call failing after the first error
---

...

Quoted 9 lines
drivers/net/ethernet/ti/netcp_core.c +7 -0
+
+	for_each_module(netcp, intf_modpriv) {
+		module = intf_modpriv->netcp_module;
+		if (!module->hwtstamp_set)
+			continue;
+
+		err = module->hwtstamp_set(intf_modpriv->module_priv,

config,

drivers/net/ethernet/ti/netcp_core.c +1 -0
+					   extack);
Quoted 8 lines

drivers/net/ethernet/ti/netcp_core.c static int netcp_ndo_stop(struct net_device *ndev) · line 1830

Quoted 6 lines
drivers/net/ethernet/ti/netcp_core.c +3 -0
+		if ((err < 0) && (err != -EOPNOTSUPP)) {
+			NL_SET_ERR_MSG_WEAK_MOD(extack,
+						"At least one module

failed to setup HW timestamps");

drivers/net/ethernet/ti/netcp_core.c +2 -0
+			ret = err;
+			goto out;  

Why don't you use break.

That's the original code, I tried to make as less changes as possible

Quoted 45 lines
Quoted 10 lines
drivers/net/ethernet/ti/netcp_core.c +9 -0
+		}
+		if (err == 0)
+			ret = err;
+	}
+
+out:
+	return (ret == 0) ? 0 : err;
+}
+  

...

Quoted 13 lines
(quoted diff) +1 -1
-static int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *ifr)
+static int gbe_hwtstamp_set(void *intf_priv, struct kernel_hwtstamp_config

*cfg,

drivers/net/ethernet/ti/netcp_ethss.c +4 -4
+			    struct netlink_ext_ack *extack)
  {
-	struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
-	struct cpts *cpts = gbe_dev->cpts;
-	struct hwtstamp_config cfg;
+	struct gbe_intf *gbe_intf = intf_priv;
+	struct gbe_priv *gbe_dev;
+	struct phy_device *phy;
 
-	if (!cpts)

drivers/net/ethernet/ti/netcp_ethss.c static void gbe_hwtstamp(struct gbe_intf *gbe_intf) · line 2660

Quoted 10 lines
drivers/net/ethernet/ti/netcp_ethss.c +6 -2
+	gbe_dev = gbe_intf->gbe_dev;
+
+	if (!gbe_dev->cpts)
  		return -EOPNOTSUPP;
 
-	if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
-		return -EFAULT;
+	phy = gbe_intf->slave->phy;
+	if (phy_has_hwtstamp(phy))
+		return phy->mii_ts->hwtstamp(phy->mii_ts, cfg, extack);  

Sorry to come back to this but the choice of using PHY or MAC timestamping is done in the core. Putting this here may conflict with the core. I know this driver has kind of a weird PHYs management through slave description but we shouldn't let the MAC driver call the PHY hwtstamp ops. If there is indeed an issue due to the weird development of this driver, people will write a patch specifically tackling this issue and maybe (by luck) refactoring this driver.

Quoted 4 lines
Quoted 2 lines

Anyway, this was not in the driver before, so I think we should not make this change in this patch.

Well, that was actually in the original code:

Oh indeed, sorry, I missed that.

Quoted 36 lines

static int gbe_ioctl(void *intf_priv, struct ifreq *req, int cmd)

{
         struct gbe_intf *gbe_intf = intf_priv;
         struct phy_device *phy = gbe_intf->slave->phy;

         if (!phy_has_hwtstamp(phy)) {
                 switch (cmd) {
                 case SIOCGHWTSTAMP:
                         return gbe_hwtstamp_get(gbe_intf, req);
                 case SIOCSHWTSTAMP:
                         return gbe_hwtstamp_set(gbe_intf, req);
                 }
         }

         if (phy)
                 return phy_mii_ioctl(phy, req, cmd);

         return -EOPNOTSUPP;
}

SIOCGHWTSTAMP/SIOCSHWTSTAMP were sent to gbe functions only when there was no support for hwtstamps on phy layer. The original flow of the call is:

netcp_ndo_ioctl -> gbe_ioctl -> gbe_hwtstamp_*/phy_mii_ioctl

where netcp_ndo_ioctl operating over netdev while other function operating with other objects, with phy taken from gbe_intf.

Checking on init part of phy devices, I found that the only phydev allocated structure is stored in gbe_slave object, which is definitely not accessible from the core. I haven't found any assignments to net_device->phydev in neither netcp_core.c nor netcp_ethss.c. Even though there are checks for some phy functions from netdev->phydev in RX and TX paths, I'm not quite sure it works properly.

Quoted 2 lines

I decided to keep the original logic here with checking phy from gbe_intf->slave.

Ok. I still think this may conflict when associated to a PHY that support hwtstamp, but if you keep the old logic then it is ok to me. Someone will fix it when the case appear. FYI you could use the phy_hwtstamp() helper instead of phy->mii_ts->hwtstamp(). Relevant in case of v3.

Thank you!

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#4 lore raw
Quoted 137 lines · Kory Maincent
Quoted 91 lines · On Tue, 4 Nov 2025 12:15:32 +0000 Vadim Fedorenko <[email protected]>…
Quoted 34 lines · Kory Maincent
Quoted 19 lines · On Mon, 3 Nov 2025 17:29:02 +0000 Vadim Fedorenko <[email protected]>…

Convert TI NetCP driver to use ndo_hwtstamp_get()/ndo_hwtstamp_set() callbacks. The logic is slightly changed, because I believe the original logic was not really correct. Config reading part is using the very first module to get the configuration instead of iterating over all of them and keep the last one as the configuration is supposed to be identical for all modules. HW timestamp config set path is now trying to configure all modules, but in case of error from one module it adds extack message. This way the configuration will be as synchronized as possible.

There are only 2 modules using netcp core infrastructure, and both use the very same function to configure HW timestamping, so no actual difference in behavior is expected.

---
v1 -> v2:
- avoid changing logic and hiding errors. keep the call failing after the first error
---

...

Quoted 9 lines
drivers/net/ethernet/ti/netcp_core.c +7 -0
+
+	for_each_module(netcp, intf_modpriv) {
+		module = intf_modpriv->netcp_module;
+		if (!module->hwtstamp_set)
+			continue;
+
+		err = module->hwtstamp_set(intf_modpriv->module_priv,

config,

drivers/net/ethernet/ti/netcp_core.c +1 -0
+					   extack);
Quoted 8 lines

drivers/net/ethernet/ti/netcp_core.c static int netcp_ndo_stop(struct net_device *ndev) · line 1830

Quoted 6 lines
drivers/net/ethernet/ti/netcp_core.c +3 -0
+		if ((err < 0) && (err != -EOPNOTSUPP)) {
+			NL_SET_ERR_MSG_WEAK_MOD(extack,
+						"At least one module

failed to setup HW timestamps");

drivers/net/ethernet/ti/netcp_core.c +2 -0
+			ret = err;
+			goto out;

Why don't you use break.

That's the original code, I tried to make as less changes as possible

Quoted 45 lines
Quoted 10 lines
drivers/net/ethernet/ti/netcp_core.c +9 -0
+		}
+		if (err == 0)
+			ret = err;
+	}
+
+out:
+	return (ret == 0) ? 0 : err;
+}
+

...

Quoted 13 lines
(quoted diff) +1 -1
-static int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *ifr)
+static int gbe_hwtstamp_set(void *intf_priv, struct kernel_hwtstamp_config

*cfg,

drivers/net/ethernet/ti/netcp_ethss.c +4 -4
+			    struct netlink_ext_ack *extack)
   {
-	struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
-	struct cpts *cpts = gbe_dev->cpts;
-	struct hwtstamp_config cfg;
+	struct gbe_intf *gbe_intf = intf_priv;
+	struct gbe_priv *gbe_dev;
+	struct phy_device *phy;
 
-	if (!cpts)

drivers/net/ethernet/ti/netcp_ethss.c static void gbe_hwtstamp(struct gbe_intf *gbe_intf) · line 2660

Quoted 10 lines
drivers/net/ethernet/ti/netcp_ethss.c +6 -2
+	gbe_dev = gbe_intf->gbe_dev;
+
+	if (!gbe_dev->cpts)
   		return -EOPNOTSUPP;
 
-	if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
-		return -EFAULT;
+	phy = gbe_intf->slave->phy;
+	if (phy_has_hwtstamp(phy))
+		return phy->mii_ts->hwtstamp(phy->mii_ts, cfg, extack);

Sorry to come back to this but the choice of using PHY or MAC timestamping is done in the core. Putting this here may conflict with the core. I know this driver has kind of a weird PHYs management through slave description but we shouldn't let the MAC driver call the PHY hwtstamp ops. If there is indeed an issue due to the weird development of this driver, people will write a patch specifically tackling this issue and maybe (by luck) refactoring this driver.

Quoted 4 lines
Quoted 2 lines

Anyway, this was not in the driver before, so I think we should not make this change in this patch.

Well, that was actually in the original code:

Oh indeed, sorry, I missed that.

Quoted 36 lines

static int gbe_ioctl(void *intf_priv, struct ifreq *req, int cmd)

{
          struct gbe_intf *gbe_intf = intf_priv;
          struct phy_device *phy = gbe_intf->slave->phy;

          if (!phy_has_hwtstamp(phy)) {
                  switch (cmd) {
                  case SIOCGHWTSTAMP:
                          return gbe_hwtstamp_get(gbe_intf, req);
                  case SIOCSHWTSTAMP:
                          return gbe_hwtstamp_set(gbe_intf, req);
                  }
          }

          if (phy)
                  return phy_mii_ioctl(phy, req, cmd);

          return -EOPNOTSUPP;
}

SIOCGHWTSTAMP/SIOCSHWTSTAMP were sent to gbe functions only when there was no support for hwtstamps on phy layer. The original flow of the call is:

netcp_ndo_ioctl -> gbe_ioctl -> gbe_hwtstamp_*/phy_mii_ioctl

where netcp_ndo_ioctl operating over netdev while other function operating with other objects, with phy taken from gbe_intf.

Checking on init part of phy devices, I found that the only phydev allocated structure is stored in gbe_slave object, which is definitely not accessible from the core. I haven't found any assignments to net_device->phydev in neither netcp_core.c nor netcp_ethss.c. Even though there are checks for some phy functions from netdev->phydev in RX and TX paths, I'm not quite sure it works properly.

Quoted 7 lines
Quoted 2 lines

I decided to keep the original logic here with checking phy from gbe_intf->slave.

Ok. I still think this may conflict when associated to a PHY that support hwtstamp, but if you keep the old logic then it is ok to me. Someone will fix it when the case appear. FYI you could use the phy_hwtstamp() helper instead of phy->mii_ts->hwtstamp(). Relevant in case of v3.

Sure, good catch. I'll change it if v3 is needed

Quoted 6 lines

Thank you!

Regards,

#5 lore raw
In reply to Vadim Fedorenko
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Mon, 3 Nov 2025 17:29:02 +0000 you wrote:

Convert TI NetCP driver to use ndo_hwtstamp_get()/ndo_hwtstamp_set() callbacks. The logic is slightly changed, because I believe the original logic was not really correct. Config reading part is using the very first module to get the configuration instead of iterating over all of them and keep the last one as the configuration is supposed to be identical for all modules. HW timestamp config set path is now trying to configure all modules, but in case of error from one module it adds extack message. This way the configuration will be as synchronized as possible.

[...]

Here is the summary with links:
- [net-next,v2] ti: netcp: convert to ndo_hwtstamp callbacks

    https://git.kernel.org/netdev/net-next/c/3f02b8272557

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html