From patchwork Fri Mar 3 16:42:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13158996 X-Patchwork-Delegate: kuba@kernel.org 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 2DBFDC7EE2D for ; Fri, 3 Mar 2023 16:43:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231228AbjCCQnV (ORCPT ); Fri, 3 Mar 2023 11:43:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231249AbjCCQnT (ORCPT ); Fri, 3 Mar 2023 11:43:19 -0500 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC52B2884E; Fri, 3 Mar 2023 08:43:15 -0800 (PST) Received: (Authenticated sender: kory.maincent@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id D098940009; Fri, 3 Mar 2023 16:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677861794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NFWNgWUO7ht6IxOffU33Vyth+9mz8NU5szlox5lMPSk=; b=PSgSqa/IASgFC0/Zs555HTAsr8ef3BktnmZwJSCiHdc3XF00kVMvhi1nzTxLvcjJNSteo5 +VY7EhQVoeglPjN/rwJWHs6o+GqwJ1POoX3j88z0JPldWI6MEmPs/a4e2SXJdAfmp5g425 iBnFxDu6iXPrKHUe1srfhM5KIZwe3RZog1dQsb4SjNYyRtIYPC3ngJIWufKNOT1ihg9IU5 0Ii6+txKg9VWx8MkBTgB4xOPYeftc3zUa3BRZOL9YP393+Eu/Na32lXYld4jVz7VtUbb6N jZim7nZfnpSd+cpyvraRfyqW/I2L7YIeQeE3P3dF3n45mvqkvksvz+0Z7yoRPA== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-omap@vger.kernel.org Cc: Michael Walle , Richard Cochran , Kory Maincent , thomas.petazzoni@bootlin.com, Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Joakim Zhang , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Grygorii Strashko , Andrew Lunn , Heiner Kallweit , Russell King , Minghao Chi , Guangbin Huang , Jie Wang , Wolfram Sang , Sven Eckelmann , Wang Yufen , Oleksij Rempel , Alexandru Tachici Subject: [PATCH v2 2/4] net: Expose available time stamping layers to user space. Date: Fri, 3 Mar 2023 17:42:39 +0100 Message-Id: <20230303164248.499286-3-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230303164248.499286-1-kory.maincent@bootlin.com> References: <20230303164248.499286-1-kory.maincent@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Richard Cochran Time stamping on network packets may happen either in the MAC or in the PHY, but not both. In preparation for making the choice selectable, expose both the current and available layers via sysfs. In accordance with the kernel implementation as it stands, the current layer will always read as "phy" when a PHY time stamping device is present. Future patches will allow changing the current layer administratively. Signed-off-by: Richard Cochran Signed-off-by: Kory Maincent --- Notes: Changes in v2: - Move the introduction of selected_timestamping_layer variable in next patch. .../ABI/testing/sysfs-class-net-timestamping | 17 ++++++ net/core/net-sysfs.c | 60 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-net-timestamping diff --git a/Documentation/ABI/testing/sysfs-class-net-timestamping b/Documentation/ABI/testing/sysfs-class-net-timestamping new file mode 100644 index 000000000000..529c3a6eb607 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-net-timestamping @@ -0,0 +1,17 @@ +What: /sys/class/net//available_timestamping_providers +Date: January 2022 +Contact: Richard Cochran +Description: + Enumerates the available providers for SO_TIMESTAMPING. + The possible values are: + - "mac" The MAC provides time stamping. + - "phy" The PHY or MII device provides time stamping. + +What: /sys/class/net//current_timestamping_provider +Date: January 2022 +Contact: Richard Cochran +Description: + Show the current SO_TIMESTAMPING provider. + The possible values are: + - "mac" The MAC provides time stamping. + - "phy" The PHY or MII device provides time stamping. diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 8409d41405df..26095634fb31 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -620,6 +620,64 @@ static ssize_t threaded_store(struct device *dev, } static DEVICE_ATTR_RW(threaded); +static ssize_t available_timestamping_providers_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + const struct ethtool_ops *ops; + struct net_device *netdev; + struct phy_device *phydev; + int ret = 0; + + netdev = to_net_dev(dev); + phydev = netdev->phydev; + ops = netdev->ethtool_ops; + + if (!rtnl_trylock()) + return restart_syscall(); + + ret += sprintf(buf, "%s\n", "mac"); + buf += 4; + + if (phy_has_tsinfo(phydev)) { + ret += sprintf(buf, "%s\n", "phy"); + buf += 4; + } + + rtnl_unlock(); + + return ret; +} +static DEVICE_ATTR_RO(available_timestamping_providers); + +static ssize_t current_timestamping_provider_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + const struct ethtool_ops *ops; + struct net_device *netdev; + struct phy_device *phydev; + int ret; + + netdev = to_net_dev(dev); + phydev = netdev->phydev; + ops = netdev->ethtool_ops; + + if (!rtnl_trylock()) + return restart_syscall(); + + if (phy_has_tsinfo(phydev)) { + ret = sprintf(buf, "%s\n", "phy"); + } else { + ret = sprintf(buf, "%s\n", "mac"); + } + + rtnl_unlock(); + + return ret; +} +static DEVICE_ATTR_RO(current_timestamping_provider); + static struct attribute *net_class_attrs[] __ro_after_init = { &dev_attr_netdev_group.attr, &dev_attr_type.attr, @@ -653,6 +711,8 @@ static struct attribute *net_class_attrs[] __ro_after_init = { &dev_attr_carrier_up_count.attr, &dev_attr_carrier_down_count.attr, &dev_attr_threaded.attr, + &dev_attr_available_timestamping_providers.attr, + &dev_attr_current_timestamping_provider.attr, NULL, }; ATTRIBUTE_GROUPS(net_class);