From nobody Wed Dec 17 12:55:21 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 332AACDB465 for ; Thu, 19 Oct 2023 14:30:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346148AbjJSOaF (ORCPT ); Thu, 19 Oct 2023 10:30:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346113AbjJSO3t (ORCPT ); Thu, 19 Oct 2023 10:29:49 -0400 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B29F49F; Thu, 19 Oct 2023 07:29:46 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 33ACC60002; Thu, 19 Oct 2023 14:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1697725785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zf35sOHFYIOY2HOVCtwWkmKHY/uNOiLiCC6UQaPPXNc=; b=NN9ZUsMhqwvhlll2cXv00HcKHpxLUS0bcgoPJAngyez7SxQf4K/tq1gTWEOtc9V1Rf13YU KoPBk752D+hRkJavXO5msKH6qujk70K97TGQtCAe7ptckTEYHg1RpJTbK9cgZJMrtn13Qh zuymY8vBl6ZwunHJemmiiYWTs3g+m+Ck5fQ/QYxuQfoY3u7R1SGiEGfUkSuLUJP5hY0Xs3 P26ehYf7Jd6nAUm7G+LsfFKyRaegcxes4Cwq8isLKk0OAV+7p/PxMy4I+Zdf+p+kFGzzxR z+2rt/qE0iGBnaXdj0Ju65o2EclAuehtm1ONKRwR/hD0dtjGPmJC/IhUtB4J7g== From: Kory Maincent Date: Thu, 19 Oct 2023 16:29:19 +0200 Subject: [PATCH net-next v6 04/16] net: macb: Convert to ndo_hwtstamp_get() and ndo_hwtstamp_set() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231019-feature_ptp_netnext-v6-4-71affc27b0e5@bootlin.com> References: <20231019-feature_ptp_netnext-v6-0-71affc27b0e5@bootlin.com> In-Reply-To: <20231019-feature_ptp_netnext-v6-0-71affc27b0e5@bootlin.com> To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Radu Pirea , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Willem de Bruijn , Jonathan Corbet , Horatiu Vultur , UNGLinuxDriver@microchip.com, Simon Horman , Vladimir Oltean Cc: Thomas Petazzoni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.12.3 X-GND-Sasl: kory.maincent@bootlin.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The hardware timestamping through ndo_eth_ioctl() is going away. Convert the macb driver to the new API before that can be removed. Signed-off-by: Kory Maincent Reviewed-by: Florian Fainelli --- drivers/net/ethernet/cadence/macb.h | 15 ++++++++---- drivers/net/ethernet/cadence/macb_main.c | 42 +++++++++++++++++++++++++---= ---- drivers/net/ethernet/cadence/macb_ptp.c | 28 ++++++++------------- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cad= ence/macb.h index 78c972bb1d96..aa5700ac9c00 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1165,9 +1165,10 @@ struct macb_ptp_info { int (*get_ts_info)(struct net_device *dev, struct ethtool_ts_info *info); int (*get_hwtst)(struct net_device *netdev, - struct ifreq *ifr); + struct kernel_hwtstamp_config *tstamp_config); int (*set_hwtst)(struct net_device *netdev, - struct ifreq *ifr, int cmd); + struct kernel_hwtstamp_config *tstamp_config, + struct netlink_ext_ack *extack); }; =20 struct macb_pm_data { @@ -1314,7 +1315,7 @@ struct macb { struct ptp_clock *ptp_clock; struct ptp_clock_info ptp_clock_info; struct tsu_incr tsu_incr; - struct hwtstamp_config tstamp_config; + struct kernel_hwtstamp_config tstamp_config; =20 /* RX queue filer rule set*/ struct ethtool_rx_fs_list rx_fs_list; @@ -1363,8 +1364,12 @@ static inline void gem_ptp_do_rxstamp(struct macb *b= p, struct sk_buff *skb, stru =20 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 *tstamp_config); +int gem_set_hwtst(struct net_device *dev, + struct kernel_hwtstamp_config *tstamp_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/etherne= t/cadence/macb_main.c index cebae0f418f2..898debfd4db3 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -3773,18 +3773,38 @@ static int macb_ioctl(struct net_device *dev, struc= t ifreq *rq, int cmd) if (!netif_running(dev)) return -EINVAL; =20 - if (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); } =20 +static int macb_hwtstamp_get(struct net_device *dev, + struct kernel_hwtstamp_config *cfg) +{ + struct macb *bp =3D netdev_priv(dev); + + if (!netif_running(dev)) + return -EINVAL; + + if (!bp->ptp_info) + return -EOPNOTSUPP; + + return bp->ptp_info->get_hwtst(dev, cfg); +} + +static int macb_hwtstamp_set(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) +{ + struct macb *bp =3D netdev_priv(dev); + + if (!netif_running(dev)) + return -EINVAL; + + if (!bp->ptp_info) + return -EOPNOTSUPP; + + return bp->ptp_info->set_hwtst(dev, cfg, extack); +} + static inline void macb_set_txcsum_feature(struct macb *bp, netdev_features_t features) { @@ -3884,6 +3904,8 @@ static const struct net_device_ops macb_netdev_ops = =3D { #endif .ndo_set_features =3D macb_set_features, .ndo_features_check =3D macb_features_check, + .ndo_hwtstamp_set =3D macb_hwtstamp_set, + .ndo_hwtstamp_get =3D macb_hwtstamp_get, }; =20 /* Configure peripheral capabilities according to device tree @@ -4539,6 +4561,8 @@ static const struct net_device_ops at91ether_netdev_o= ps =3D { #ifdef CONFIG_NET_POLL_CONTROLLER .ndo_poll_controller =3D at91ether_poll_controller, #endif + .ndo_hwtstamp_set =3D macb_hwtstamp_set, + .ndo_hwtstamp_get =3D macb_hwtstamp_get, }; =20 static int at91ether_clk_init(struct platform_device *pdev, struct clk **p= clk, diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet= /cadence/macb_ptp.c index 51d26fa190d7..a63bf29c4fa8 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -374,19 +374,16 @@ static int gem_ptp_set_ts_mode(struct macb *bp, return 0; } =20 -int gem_get_hwtst(struct net_device *dev, struct ifreq *rq) +int gem_get_hwtst(struct net_device *dev, + struct kernel_hwtstamp_config *tstamp_config) { - struct hwtstamp_config *tstamp_config; struct macb *bp =3D netdev_priv(dev); =20 - tstamp_config =3D &bp->tstamp_config; + *tstamp_config =3D bp->tstamp_config; if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) =3D=3D 0) return -EOPNOTSUPP; =20 - if (copy_to_user(rq->ifr_data, tstamp_config, sizeof(*tstamp_config))) - return -EFAULT; - else - return 0; + return 0; } =20 static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable) @@ -401,22 +398,18 @@ static void gem_ptp_set_one_step_sync(struct macb *bp= , u8 enable) macb_writel(bp, NCR, reg_val & ~MACB_BIT(OSSMODE)); } =20 -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 *tstamp_config, + struct netlink_ext_ack *extack) { enum macb_bd_control tx_bd_control =3D TSTAMP_DISABLED; enum macb_bd_control rx_bd_control =3D TSTAMP_DISABLED; - struct hwtstamp_config *tstamp_config; struct macb *bp =3D netdev_priv(dev); u32 regval; =20 - tstamp_config =3D &bp->tstamp_config; if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) =3D=3D 0) return -EOPNOTSUPP; =20 - if (copy_from_user(tstamp_config, ifr->ifr_data, - sizeof(*tstamp_config))) - return -EFAULT; - switch (tstamp_config->tx_type) { case HWTSTAMP_TX_OFF: break; @@ -463,12 +456,11 @@ int gem_set_hwtst(struct net_device *dev, struct ifre= q *ifr, int cmd) return -ERANGE; } =20 + bp->tstamp_config =3D *tstamp_config; + if (gem_ptp_set_ts_mode(bp, tx_bd_control, rx_bd_control) !=3D 0) return -ERANGE; =20 - if (copy_to_user(ifr->ifr_data, tstamp_config, sizeof(*tstamp_config))) - return -EFAULT; - else - return 0; + return 0; } =20 --=20 2.25.1