From nobody Fri Dec 19 20:36:07 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 D8D48C4167B for ; Tue, 14 Nov 2023 11:29:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233053AbjKNL3m (ORCPT ); Tue, 14 Nov 2023 06:29:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232932AbjKNL3L (ORCPT ); Tue, 14 Nov 2023 06:29:11 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D72621BC8; Tue, 14 Nov 2023 03:28:55 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id CD68560002; Tue, 14 Nov 2023 11:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1699961334; 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=C2aAKl8aAUGB8CnJuHJk1iCyOBJNsjbnsgy1tmN3prk=; b=I9Az4JIB4EmIyHdaj2Ds0MwGTyBeYILqi1US9V+6RJR8WEdD6I1lyIrNeMqByv/zXU8o8M 24Bbm3dgpwPsOkwPW9cq9qDw4oRDSQbFhKiJ3lPFNK9vVu/GAi2Uy7xtPZhfSo4NQbpgQc qNVYfzmlP1jde0fDFuWKF/Jk1mci9MXm2kHpdBYnFnSHffaHB7uF0OOQd5Xmb31gftufM+ 9mUuR5QByEFGhSe+Y/767fNG9yr7ccr2LS7G4WlRE7TRM84AUd4ifgb5l12lqP1EPGygk4 IxIAT+3LCb6NV8my0fa8hIiULOXgSJQzfhm2XrYavs6Igs322c6l8NyTctU3wg== From: =?utf-8?q?K=C3=B6ry_Maincent?= Date: Tue, 14 Nov 2023 12:28:31 +0100 Subject: [PATCH net-next v7 03/16] net: ethtool: Refactor identical get_ts_info implementations. MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231114-feature_ptp_netnext-v7-3-472e77951e40@bootlin.com> References: <20231114-feature_ptp_netnext-v7-0-472e77951e40@bootlin.com> In-Reply-To: <20231114-feature_ptp_netnext-v7-0-472e77951e40@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 , Jay Vosburgh X-Mailer: b4 0.12.4 X-GND-Sasl: kory.maincent@bootlin.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Richard Cochran The vlan, macvlan and the bonding drivers call their "real" device driver in order to report the time stamping capabilities. Provide a core ethtool helper function to avoid copy/paste in the stack. Signed-off-by: Richard Cochran Signed-off-by: Kory Maincent Reviewed-by: Florian Fainelli Reviewed-by: Jay Vosburgh --- Change in v5: - Fixe typo. Change in v6: - Removed unused variable spotted by kernel test robot. --- drivers/net/bonding/bond_main.c | 29 ++--------------------------- drivers/net/macvlan.c | 14 +------------- include/linux/ethtool.h | 8 ++++++++ net/8021q/vlan_dev.c | 15 +-------------- net/ethtool/common.c | 6 ++++++ 5 files changed, 18 insertions(+), 54 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_mai= n.c index 51d47eda1c87..10181c2c63fc 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -5749,10 +5749,8 @@ static int bond_ethtool_get_ts_info(struct net_devic= e *bond_dev, { struct bonding *bond =3D netdev_priv(bond_dev); struct ethtool_ts_info ts_info; - const struct ethtool_ops *ops; struct net_device *real_dev; bool sw_tx_support =3D false; - struct phy_device *phydev; struct list_head *iter; struct slave *slave; int ret =3D 0; @@ -5763,29 +5761,12 @@ static int bond_ethtool_get_ts_info(struct net_devi= ce *bond_dev, rcu_read_unlock(); =20 if (real_dev) { - ops =3D real_dev->ethtool_ops; - phydev =3D real_dev->phydev; - - if (phy_has_tsinfo(phydev)) { - ret =3D phy_ts_info(phydev, info); - goto out; - } else if (ops->get_ts_info) { - ret =3D ops->get_ts_info(real_dev, info); - goto out; - } + ret =3D ethtool_get_ts_info_by_layer(real_dev, info); } else { /* Check if all slaves support software tx timestamping */ rcu_read_lock(); bond_for_each_slave_rcu(bond, slave, iter) { - ret =3D -1; - ops =3D slave->dev->ethtool_ops; - phydev =3D slave->dev->phydev; - - if (phy_has_tsinfo(phydev)) - ret =3D phy_ts_info(phydev, &ts_info); - else if (ops->get_ts_info) - ret =3D ops->get_ts_info(slave->dev, &ts_info); - + ret =3D ethtool_get_ts_info_by_layer(slave->dev, &ts_info); if (!ret && (ts_info.so_timestamping & SOF_TIMESTAMPING_TX_SOFTWARE)) { sw_tx_support =3D true; continue; @@ -5797,15 +5778,9 @@ static int bond_ethtool_get_ts_info(struct net_devic= e *bond_dev, rcu_read_unlock(); } =20 - ret =3D 0; - info->so_timestamping =3D SOF_TIMESTAMPING_RX_SOFTWARE | - SOF_TIMESTAMPING_SOFTWARE; if (sw_tx_support) info->so_timestamping |=3D SOF_TIMESTAMPING_TX_SOFTWARE; =20 - info->phc_index =3D -1; - -out: dev_put(real_dev); return ret; } diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 02bd201bc7e5..759406fbaea8 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -1086,20 +1086,8 @@ static int macvlan_ethtool_get_ts_info(struct net_de= vice *dev, struct ethtool_ts_info *info) { struct net_device *real_dev =3D macvlan_dev_real_dev(dev); - const struct ethtool_ops *ops =3D real_dev->ethtool_ops; - struct phy_device *phydev =3D real_dev->phydev; =20 - if (phy_has_tsinfo(phydev)) { - return phy_ts_info(phydev, info); - } else if (ops->get_ts_info) { - return ops->get_ts_info(real_dev, info); - } else { - info->so_timestamping =3D SOF_TIMESTAMPING_RX_SOFTWARE | - SOF_TIMESTAMPING_SOFTWARE; - info->phc_index =3D -1; - } - - return 0; + return ethtool_get_ts_info_by_layer(real_dev, info); } =20 static netdev_features_t macvlan_fix_features(struct net_device *dev, diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 689028257fcc..c2bb74143eda 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -1043,6 +1043,14 @@ static inline int ethtool_mm_frag_size_min_to_add(u3= 2 val_min, u32 *val_add, return -EINVAL; } =20 +/** + * ethtool_get_ts_info_by_layer - Obtains time stamping capabilities from = the MAC or PHY layer. + * @dev: pointer to net_device structure + * @info: buffer to hold the result + * Returns zero on success, non-zero otherwise. + */ +int ethtool_get_ts_info_by_layer(struct net_device *dev, struct ethtool_ts= _info *info); + /** * ethtool_sprintf - Write formatted string to ethtool string data * @data: Pointer to a pointer to the start of string to update diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 2a7f1b15714a..407b2335f091 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -702,20 +702,7 @@ static int vlan_ethtool_get_ts_info(struct net_device = *dev, struct ethtool_ts_info *info) { const struct vlan_dev_priv *vlan =3D vlan_dev_priv(dev); - const struct ethtool_ops *ops =3D vlan->real_dev->ethtool_ops; - struct phy_device *phydev =3D vlan->real_dev->phydev; - - if (phy_has_tsinfo(phydev)) { - return phy_ts_info(phydev, info); - } else if (ops->get_ts_info) { - return ops->get_ts_info(vlan->real_dev, info); - } else { - info->so_timestamping =3D SOF_TIMESTAMPING_RX_SOFTWARE | - SOF_TIMESTAMPING_SOFTWARE; - info->phc_index =3D -1; - } - - return 0; + return ethtool_get_ts_info_by_layer(vlan->real_dev, info); } =20 static void vlan_dev_get_stats64(struct net_device *dev, diff --git a/net/ethtool/common.c b/net/ethtool/common.c index b4419fb6df6a..11d8797f63f6 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -661,6 +661,12 @@ int ethtool_get_phc_vclocks(struct net_device *dev, in= t **vclock_index) } EXPORT_SYMBOL(ethtool_get_phc_vclocks); =20 +int ethtool_get_ts_info_by_layer(struct net_device *dev, struct ethtool_ts= _info *info) +{ + return __ethtool_get_ts_info(dev, info); +} +EXPORT_SYMBOL(ethtool_get_ts_info_by_layer); + const struct ethtool_phy_ops *ethtool_phy_ops; =20 void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops) --=20 2.25.1