netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Köry Maincent" <kory.maincent@bootlin.com>
To: glipus@gmail.com
Cc: kory.maincent@bootlin.com, kuba@kernel.org,
	netdev@vger.kernel.org, maxime.chevallier@bootlin.com,
	vladimir.oltean@nxp.com, vadim.fedorenko@linux.dev,
	richardcochran@gmail.com, gerhard@engleder-embedded.com,
	thomas.petazzoni@bootlin.com
Subject: [RFC PATCH v4 0/5] New NDO methods ndo_hwtstamp_get/set
Date: Wed, 26 Apr 2023 18:58:35 +0200	[thread overview]
Message-ID: <20230426165835.443259-1-kory.maincent@bootlin.com> (raw)
In-Reply-To: <20230423032437.285014-1-glipus@gmail.com>

From: Kory Maincent <kory.maincent@bootlin.com>

You patch series work on my side with the macb MAC controller and this
patch.
I don't know if you are waiting for more reviews but it seems good enough
to drop the RFC tag.

---

 drivers/net/ethernet/cadence/macb.h      | 10 ++++++--
 drivers/net/ethernet/cadence/macb_main.c | 15 ++++--------
 drivers/net/ethernet/cadence/macb_ptp.c  | 30 ++++++++++++++----------
 3 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index cfbdd0022764..bc73b080093e 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -1350,8 +1350,14 @@ static inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, stru
 
 	gem_ptp_rxstamp(bp, skb, desc);
 }
-int gem_get_hwtst(struct net_device *dev, struct ifreq *rq);
-int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd);
+
+int gem_get_hwtst(struct net_device *dev,
+		  struct kernel_hwtstamp_config *kernel_config,
+		  struct netlink_ext_ack *extack);
+int gem_set_hwtst(struct net_device *dev,
+		  struct kernel_hwtstamp_config *kernel_config,
+		  struct netlink_ext_ack *extack);
+
 #else
 static inline void gem_ptp_init(struct net_device *ndev) { }
 static inline void gem_ptp_remove(struct net_device *ndev) { }
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 45f63df5bdc4..c1d65be88835 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -3402,8 +3402,6 @@ static struct macb_ptp_info gem_ptp_info = {
 	.get_ptp_max_adj = gem_get_ptp_max_adj,
 	.get_tsu_rate	 = gem_get_tsu_rate,
 	.get_ts_info	 = gem_get_ts_info,
-	.get_hwtst	 = gem_get_hwtst,
-	.set_hwtst	 = gem_set_hwtst,
 };
 #endif
 
@@ -3764,15 +3762,6 @@ static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 	if (!netif_running(dev))
 		return -EINVAL;
 
-	if (!phy_has_hwtstamp(dev->phydev) && bp->ptp_info) {
-		switch (cmd) {
-		case SIOCSHWTSTAMP:
-			return bp->ptp_info->set_hwtst(dev, rq, cmd);
-		case SIOCGHWTSTAMP:
-			return bp->ptp_info->get_hwtst(dev, rq);
-		}
-	}
-
 	return phylink_mii_ioctl(bp->phylink, rq, cmd);
 }
 
@@ -3875,6 +3864,10 @@ static const struct net_device_ops macb_netdev_ops = {
 #endif
 	.ndo_set_features	= macb_set_features,
 	.ndo_features_check	= macb_features_check,
+#ifdef CONFIG_MACB_USE_HWSTAMP
+	.ndo_hwtstamp_get	= gem_get_hwtst,
+	.ndo_hwtstamp_set	= gem_set_hwtst,
+#endif
 };
 
 /* Configure peripheral capabilities according to device tree
diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c
index 51d26fa190d7..eddacc5df435 100644
--- a/drivers/net/ethernet/cadence/macb_ptp.c
+++ b/drivers/net/ethernet/cadence/macb_ptp.c
@@ -374,19 +374,22 @@ static int gem_ptp_set_ts_mode(struct macb *bp,
 	return 0;
 }
 
-int gem_get_hwtst(struct net_device *dev, struct ifreq *rq)
+int gem_get_hwtst(struct net_device *dev,
+		  struct kernel_hwtstamp_config *kernel_config,
+		  struct netlink_ext_ack *extack)
 {
 	struct hwtstamp_config *tstamp_config;
 	struct macb *bp = netdev_priv(dev);
 
+	if (phy_has_hwtstamp(dev->phydev))
+		return phylink_mii_ioctl(bp->phylink, kernel_config->ifr, SIOCGHWTSTAMP);
+
 	tstamp_config = &bp->tstamp_config;
 	if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) == 0)
 		return -EOPNOTSUPP;
 
-	if (copy_to_user(rq->ifr_data, tstamp_config, sizeof(*tstamp_config)))
-		return -EFAULT;
-	else
-		return 0;
+	hwtstamp_config_to_kernel(kernel_config, tstamp_config);
+	return 0;
 }
 
 static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable)
@@ -401,7 +404,9 @@ static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable)
 		macb_writel(bp, NCR, reg_val & ~MACB_BIT(OSSMODE));
 }
 
-int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd)
+int gem_set_hwtst(struct net_device *dev,
+		  struct kernel_hwtstamp_config *kernel_config,
+		  struct netlink_ext_ack *extack)
 {
 	enum macb_bd_control tx_bd_control = TSTAMP_DISABLED;
 	enum macb_bd_control rx_bd_control = TSTAMP_DISABLED;
@@ -409,13 +414,14 @@ int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd)
 	struct macb *bp = netdev_priv(dev);
 	u32 regval;
 
+	if (phy_has_hwtstamp(dev->phydev))
+		return phylink_mii_ioctl(bp->phylink, kernel_config->ifr, SIOCSHWTSTAMP);
+
 	tstamp_config = &bp->tstamp_config;
 	if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) == 0)
 		return -EOPNOTSUPP;
 
-	if (copy_from_user(tstamp_config, ifr->ifr_data,
-			   sizeof(*tstamp_config)))
-		return -EFAULT;
+	hwtstamp_config_from_kernel(tstamp_config, kernel_config);
 
 	switch (tstamp_config->tx_type) {
 	case HWTSTAMP_TX_OFF:
@@ -466,9 +472,7 @@ int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd)
 	if (gem_ptp_set_ts_mode(bp, tx_bd_control, rx_bd_control) != 0)
 		return -ERANGE;
 
-	if (copy_to_user(ifr->ifr_data, tstamp_config, sizeof(*tstamp_config)))
-		return -EFAULT;
-	else
-		return 0;
+	hwtstamp_config_to_kernel(kernel_config, tstamp_config);
+	return 0;
 }
 
-- 
2.25.1


  reply	other threads:[~2023-04-26 16:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-23  3:24 [RFC PATCH v4 0/5] New NDO methods ndo_hwtstamp_get/set Maxim Georgiev
2023-04-26 16:58 ` Köry Maincent [this message]
2023-04-27  4:00   ` Max Georgiev
2023-04-27  8:43     ` Köry Maincent
2023-04-28  4:57       ` Max Georgiev
2023-04-28  8:11         ` Köry Maincent
2023-04-28 14:14           ` Max Georgiev
2023-04-28 14:34             ` Köry Maincent
2023-04-29 19:44             ` Vadim Fedorenko
2023-05-02  4:35               ` Max Georgiev
2023-05-02  4:44                 ` Max Georgiev
2023-05-02  9:13                   ` Köry Maincent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230426165835.443259-1-kory.maincent@bootlin.com \
    --to=kory.maincent@bootlin.com \
    --cc=gerhard@engleder-embedded.com \
    --cc=glipus@gmail.com \
    --cc=kuba@kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vadim.fedorenko@linux.dev \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).