From patchwork Mon Jan 3 23:25:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Cochran X-Patchwork-Id: 12702810 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 F03ACC433EF for ; Mon, 3 Jan 2022 23:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbiACX0B (ORCPT ); Mon, 3 Jan 2022 18:26:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230490AbiACXZ7 (ORCPT ); Mon, 3 Jan 2022 18:25:59 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96416C061761; Mon, 3 Jan 2022 15:25:59 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id x194so7972621pgx.4; Mon, 03 Jan 2022 15:25:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=s8UxwvmkIsqGsTpVpE5Hu0C6rAGO/S5eDabYd0ebEco=; b=V4Fiu7UovDGhwD+9jwq9p8a5Pi/KmyePIwRa+p/C4koXbD8Y00KruT93l5++uR63iZ hhGvtO3uxNI1QaNY2e8iHZShwHWEbRlBxAJPXtVOcE6vwEu/0vDg6TF6/8e9jzjtiN2D Ac+sMz1Rv50GTZ7RUNe7B6ljw7LIrorVvgr/vV5HOEhIh07hsyslzflfEYlE3pkfNUn6 xoEJrGEOkI1yIVxQr4VFRwLHRzq3+rKpd8LXNK44JOJkYNcNpyB3+SZ5T6nBv2/f9YKJ MlmaSo4d/QXXrbTWbuXNi07j0UqLlhAi+Yo6XjolMM28E+1dcroCbJEAuRAUwr1/CT2n ydqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=s8UxwvmkIsqGsTpVpE5Hu0C6rAGO/S5eDabYd0ebEco=; b=o8PVT8nKMpXmrvdKHhT+DpsMDCti/FXUr9ZcAa+sgxtzcl26JqMhNma/CSmiA20FvM mg0QWpfQqagyvmOlMwjeLYRlaY7k2tdwZxWRmxrfhngNmDNlacwS12a9hOPFnQBD4g0R +u6l5uXuALHoiAsIXT7VwUrFhL7uVUsPwzT3Vz7bl6rqJL9bxynRIInjMCKCxZzA5Zd/ sPWqJWcHKyGT3qcPy2qoD38zzkj30IiIULLxS0NoPAm5mp3SKHYsoVg5HMDBTyNMHLS1 HICd1N2ZRPDXvricXOjHBeM+d60TLrCHbDutY8DzSBK0V0NxtTMe9ZALo9Rxsog1tApY pZMQ== X-Gm-Message-State: AOAM5335hzj2JiR7U10TJ2aMyRLp6SbCLPCDU88KJTaqywbznY63t0SJ x6txg1OYlP4tEEJkpLPs2v1468aw36M= X-Google-Smtp-Source: ABdhPJzgxwG2LIaWzNKuFcqrQmws+Vz9rzG2gt7XW61SY71WyXxrK8/12fiNhaLA8mrpqipawYdtRQ== X-Received: by 2002:a62:7c58:0:b0:4bb:314b:86b9 with SMTP id x85-20020a627c58000000b004bb314b86b9mr48290021pfc.84.1641252358834; Mon, 03 Jan 2022 15:25:58 -0800 (PST) Received: from localhost.localdomain ([2601:640:8200:33:e2d5:5eff:fea5:802f]) by smtp.gmail.com with ESMTPSA id k6sm41340191pff.106.2022.01.03.15.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jan 2022 15:25:58 -0800 (PST) From: Richard Cochran To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrew Lunn , David Miller , Grygorii Strashko , Jakub Kicinski , Joakim Zhang , Kurt Kanzenbach , Miroslav Lichvar , Russell King , Vladimir Oltean Subject: [PATCH RFC V1 net-next 1/4] net: ethtool: Refactor identical get_ts_info implementations. Date: Mon, 3 Jan 2022 15:25:52 -0800 Message-Id: <20220103232555.19791-2-richardcochran@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Both the vlan 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 Reviewed-by: Vladimir Oltean --- drivers/net/bonding/bond_main.c | 14 ++------------ include/linux/ethtool.h | 8 ++++++++ net/8021q/vlan_dev.c | 15 +-------------- net/ethtool/common.c | 6 ++++++ 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index b60e22f6394a..f28b88b67b9e 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -5353,23 +5353,13 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev, struct ethtool_ts_info *info) { struct bonding *bond = netdev_priv(bond_dev); - const struct ethtool_ops *ops; struct net_device *real_dev; - struct phy_device *phydev; rcu_read_lock(); real_dev = bond_option_active_slave_get_rcu(bond); rcu_read_unlock(); - if (real_dev) { - ops = real_dev->ethtool_ops; - phydev = 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(real_dev, info); - } - } + if (real_dev) + return ethtool_get_ts_info_by_layer(real_dev, info); info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE; diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index a26f37a27167..1d72344493bb 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -824,6 +824,14 @@ ethtool_params_from_link_mode(struct ethtool_link_ksettings *link_ksettings, */ int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index); +/** + * 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 sauces, 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 start of string to update diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 26d031a43cc1..c645d7c46d78 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -679,20 +679,7 @@ static int vlan_ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) { const struct vlan_dev_priv *vlan = vlan_dev_priv(dev); - const struct ethtool_ops *ops = vlan->real_dev->ethtool_ops; - struct phy_device *phydev = 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 = SOF_TIMESTAMPING_RX_SOFTWARE | - SOF_TIMESTAMPING_SOFTWARE; - info->phc_index = -1; - } - - return 0; + return ethtool_get_ts_info_by_layer(vlan->real_dev, info); } static void vlan_dev_get_stats64(struct net_device *dev, diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 0c5210015911..651d18eef589 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -569,6 +569,12 @@ int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index) } EXPORT_SYMBOL(ethtool_get_phc_vclocks); +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; void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops) From patchwork Mon Jan 3 23:25:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Cochran X-Patchwork-Id: 12702811 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 16095C4332F for ; Mon, 3 Jan 2022 23:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230509AbiACX0D (ORCPT ); Mon, 3 Jan 2022 18:26:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbiACX0B (ORCPT ); Mon, 3 Jan 2022 18:26:01 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B10DCC061784; Mon, 3 Jan 2022 15:26:00 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id c2so30619901pfc.1; Mon, 03 Jan 2022 15:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QCUoaEOA0tftjLb0LI0lpsnVHcMQNSiDzWVP7rq9STo=; b=qCu8poPV1paRstjK/1c6MsqZuvuiM7u/06fcyyrJT4eWMWjThBKeGEWVDWKFGUJct+ 7JcKrq/RawsTOLlXps/BJEe2Ke8tBDxrTLvp/aNqGmY1pKqUZKBNPJikyRPq6O67HNCj CG/LwAGRzQVwOdorhD0uueD6A1JXgKkZvRdgrZmT9KtvmGN3ojGcKWrnOh8q7ECHKr8B yuFNXYM16ai+FfOFdszskAblpYTj75HzysrCHBAiPeqRFzNbz0xZruhBxqorkbTVhuuv 3K9TjLcG0yG4GXRWtKzG+lzSHo6hTqD8gOJdA5dbqJ0ypwAOrK24o+PHyrULGaFU5yzV VvQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QCUoaEOA0tftjLb0LI0lpsnVHcMQNSiDzWVP7rq9STo=; b=U8uAC0TtM1msSRAPn0BLUP/073AMZ9cq93RcG9TMscWIgWIcRi5TdZ7ezjXhaDZb1V 4J4XcZZa3oN1hyEuJdOGHpYBXWkD2QPZiTcic4QvXCO7FSPKeEN9tnjZp+ufGFSrev5h +KbX/M4jQ5ENUYEGluRnF1GDVVU7sN2bzqmo5t+V75rCN4J+DAVdnX1IxigW31weXX7R UF6bdI75i/USEerJ3jfcn5RQzg4124k2F4Q8xMzQalN2PqxYLpFVZvV4eM68qKucniQ6 EnCG1NqXLyGinXEa6df8hYxTuxRnz2v7D+Qp6/oIepoNik0Xyosq/7llGQ4IsQvMENhL iOdQ== X-Gm-Message-State: AOAM5337wrYXbe6aYQSKaIyGOw2FBXted/o9eqrzsKJ/Q4JU3Kel09Mu eKmyDn/Q9Kp8UDd7myFoBoSufk8DyTo= X-Google-Smtp-Source: ABdhPJwOApE90rsP5VPsbCmqmpHBnliakFXKKz3HaJtUGyVIrzT8QBWRVvQef5Zo5Wbevc+UA+v/0A== X-Received: by 2002:a63:91c1:: with SMTP id l184mr42672766pge.452.1641252360121; Mon, 03 Jan 2022 15:26:00 -0800 (PST) Received: from localhost.localdomain ([2601:640:8200:33:e2d5:5eff:fea5:802f]) by smtp.gmail.com with ESMTPSA id k6sm41340191pff.106.2022.01.03.15.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jan 2022 15:25:59 -0800 (PST) From: Richard Cochran To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrew Lunn , David Miller , Grygorii Strashko , Jakub Kicinski , Joakim Zhang , Kurt Kanzenbach , Miroslav Lichvar , Russell King , Vladimir Oltean Subject: [PATCH RFC V1 net-next 2/4] net: Expose available time stamping layers to user space. Date: Mon, 3 Jan 2022 15:25:53 -0800 Message-Id: <20220103232555.19791-3-richardcochran@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 --- .../ABI/testing/sysfs-class-net-timestamping | 17 ++++++ drivers/net/phy/phy_device.c | 2 + include/linux/netdevice.h | 10 ++++ net/core/net-sysfs.c | 60 +++++++++++++++++++ 4 files changed, 89 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/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 74d8e1dc125f..5538ee27e865 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1415,6 +1415,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, phydev->phy_link_change = phy_link_change; if (dev) { + dev->selected_timestamping_layer = PHY_TIMESTAMPING; phydev->attached_dev = dev; dev->phydev = phydev; @@ -1727,6 +1728,7 @@ void phy_detach(struct phy_device *phydev) phy_suspend(phydev); if (dev) { + dev->selected_timestamping_layer = MAC_TIMESTAMPING; phydev->attached_dev->phydev = NULL; phydev->attached_dev = NULL; } diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 2684bdb6defa..b44ae00df3a8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1687,6 +1687,11 @@ enum netdev_ml_priv_type { ML_PRIV_CAN, }; +enum timestamping_layer { + MAC_TIMESTAMPING, + PHY_TIMESTAMPING, +}; + /** * struct net_device - The DEVICE structure. * @@ -1927,6 +1932,9 @@ enum netdev_ml_priv_type { * * @threaded: napi threaded mode is enabled * + * @selected_timestamping_layer: Tracks whether the MAC or the PHY + * performs packet time stamping. + * * @net_notifier_list: List of per-net netdev notifier block * that follow this device when it is moved * to another network namespace. @@ -2263,6 +2271,8 @@ struct net_device { unsigned wol_enabled:1; unsigned threaded:1; + enum timestamping_layer selected_timestamping_layer; + struct list_head net_notifier_list; #if IS_ENABLED(CONFIG_MACSEC) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 53ea262ecafd..4ff7ef417c38 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -618,6 +618,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, @@ -651,6 +709,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); From patchwork Mon Jan 3 23:25:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Cochran X-Patchwork-Id: 12702812 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 26EA5C433FE for ; Mon, 3 Jan 2022 23:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbiACX0E (ORCPT ); Mon, 3 Jan 2022 18:26:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbiACX0C (ORCPT ); Mon, 3 Jan 2022 18:26:02 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18B03C061761; Mon, 3 Jan 2022 15:26:02 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id z3so25820852plg.8; Mon, 03 Jan 2022 15:26:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tRbA9VyOjLVvoknHXvMJ6qY2wU3zvdmza99A/Uu0abA=; b=Z+85qpx9leulsSqxTd77xcqihNi07ZXv6tL8A3Hgw2tYFWfVP/c260x2sm6U9fFSpO 0yl2Cl5JkdRJk9jumUxYqRXS/DMEt7JJ4B8bA9lhOg0+d8SCV9KxifW6sP5c33G/7Ntu QnpfOjz8/veOsrqB/pluigIMGeZm5UFDUv5tnvMomCW2nizaeGNIhr4sFXdP+hPptzWT EZ31GX8tS5YUyhTZuFtaI+ak528IpmAA+ZG/A5ptzcogkPPF7K4xNkuw9ArsUgpvnQHi exjUXeQArDvach8gHBEK7XDKWtgiA5i+kDpFvRnCy8BMUpAwiHH/dAAVYyPaVKsRQxuw jMPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tRbA9VyOjLVvoknHXvMJ6qY2wU3zvdmza99A/Uu0abA=; b=HCd8tR7kHjHe2F4IOagRvxCZ7agcE0eWO9ZIQPJpwM6Pi+iS05O0ks/fWXilyv35HC swBMRVrv4tfbq16ZZlMMWlXwgx1EbO+EfSAdjLA3ya/4MoKgMP0V1w00M1ARi9vsHJYa flON2jUVIXUxp0JWFmJVr2S59uCvG59caZIlDSuJT8puZweeJOZ/GXf3+PwQwWaWey7S VTuyhRsk63GgdoIip7qEpjmKTTrLX5yTTWVnZFNU9r8YVFZkPXUKKHhDI7h+QQMj6lOq 1R40/z3lb3TtTQPY3B19vTcNEFsJvmfZTzS2FPAUaQfc+fzGv+sylgaic5b1rqOE1jp3 Qqng== X-Gm-Message-State: AOAM532jFl3oNZUnw6SoMyoHkn4WWaQbbAcy3TnRUPxcnoETpwmjE7T0 a51c5NX/RbSGBZbdyIjSafnnqXzMcLw= X-Google-Smtp-Source: ABdhPJzbFGPyBHeabrShgT2zS30eSrQJFXKU5DFm67QkXsLT06zy66akf3/lXzJuvW6ahfcSQftZkw== X-Received: by 2002:a17:902:7443:b0:149:b16d:c527 with SMTP id e3-20020a170902744300b00149b16dc527mr12811751plt.89.1641252361409; Mon, 03 Jan 2022 15:26:01 -0800 (PST) Received: from localhost.localdomain ([2601:640:8200:33:e2d5:5eff:fea5:802f]) by smtp.gmail.com with ESMTPSA id k6sm41340191pff.106.2022.01.03.15.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jan 2022 15:26:01 -0800 (PST) From: Richard Cochran To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrew Lunn , David Miller , Grygorii Strashko , Jakub Kicinski , Joakim Zhang , Kurt Kanzenbach , Miroslav Lichvar , Russell King , Vladimir Oltean Subject: [PATCH RFC V1 net-next 3/4] net: Let the active time stamping layer be selectable. Date: Mon, 3 Jan 2022 15:25:54 -0800 Message-Id: <20220103232555.19791-4-richardcochran@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Make the sysfs knob writable, and add checks in the ioctl and time stamping paths to respect the currently selected time stamping layer. Signed-off-by: Richard Cochran --- .../ABI/testing/sysfs-class-net-timestamping | 5 +- net/core/dev_ioctl.c | 44 ++++++++++++++-- net/core/net-sysfs.c | 50 +++++++++++++++++-- net/core/timestamping.c | 6 +++ net/ethtool/common.c | 18 +++++-- 5 files changed, 111 insertions(+), 12 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-net-timestamping b/Documentation/ABI/testing/sysfs-class-net-timestamping index 529c3a6eb607..6dfd59740cad 100644 --- a/Documentation/ABI/testing/sysfs-class-net-timestamping +++ b/Documentation/ABI/testing/sysfs-class-net-timestamping @@ -11,7 +11,10 @@ What: /sys/class/net//current_timestamping_provider Date: January 2022 Contact: Richard Cochran Description: - Show the current SO_TIMESTAMPING provider. + Shows or sets the current SO_TIMESTAMPING provider. + When changing the value, some packets in the kernel + networking stack may still be delivered with time + stamps from the previous 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/dev_ioctl.c b/net/core/dev_ioctl.c index 1b807d119da5..269068ce3a51 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -260,6 +260,43 @@ static int dev_eth_ioctl(struct net_device *dev, return err; } +static int dev_hwtstamp_ioctl(struct net_device *dev, + struct ifreq *ifr, unsigned int cmd) +{ + const struct net_device_ops *ops = dev->netdev_ops; + int err; + + err = dsa_ndo_eth_ioctl(dev, ifr, cmd); + if (err == 0 || err != -EOPNOTSUPP) + return err; + + if (!netif_device_present(dev)) + return -ENODEV; + + switch (dev->selected_timestamping_layer) { + + case MAC_TIMESTAMPING: + if (ops->ndo_do_ioctl == phy_do_ioctl) { + /* Some drivers set .ndo_do_ioctl to phy_do_ioctl. */ + err = -EOPNOTSUPP; + } else { + err = ops->ndo_eth_ioctl(dev, ifr, cmd); + } + break; + + case PHY_TIMESTAMPING: + if (phy_has_hwtstamp(dev->phydev)) { + err = phy_mii_ioctl(dev->phydev, ifr, cmd); + } else { + err = -ENODEV; + WARN_ON(1); + } + break; + } + + return err; +} + static int dev_siocbond(struct net_device *dev, struct ifreq *ifr, unsigned int cmd) { @@ -395,6 +432,9 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data, return err; fallthrough; + case SIOCGHWTSTAMP: + return dev_hwtstamp_ioctl(dev, ifr, cmd); + /* * Unknown or private ioctl */ @@ -405,9 +445,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data, if (cmd == SIOCGMIIPHY || cmd == SIOCGMIIREG || - cmd == SIOCSMIIREG || - cmd == SIOCSHWTSTAMP || - cmd == SIOCGHWTSTAMP) { + cmd == SIOCSMIIREG) { err = dev_eth_ioctl(dev, ifr, cmd); } else if (cmd == SIOCBONDENSLAVE || cmd == SIOCBONDRELEASE || diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 4ff7ef417c38..c27f01a1a285 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -664,17 +664,59 @@ static ssize_t current_timestamping_provider_show(struct device *dev, if (!rtnl_trylock()) return restart_syscall(); - if (phy_has_tsinfo(phydev)) { - ret = sprintf(buf, "%s\n", "phy"); - } else { + switch (netdev->selected_timestamping_layer) { + case MAC_TIMESTAMPING: ret = sprintf(buf, "%s\n", "mac"); + break; + case PHY_TIMESTAMPING: + ret = sprintf(buf, "%s\n", "phy"); + break; } rtnl_unlock(); return ret; } -static DEVICE_ATTR_RO(current_timestamping_provider); + +static ssize_t current_timestamping_provider_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct net_device *netdev = to_net_dev(dev); + struct net *net = dev_net(netdev); + enum timestamping_layer flavor; + + if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) + return -EPERM; + + if (!strcmp(buf, "mac\n")) + flavor = MAC_TIMESTAMPING; + else if (!strcmp(buf, "phy\n")) + flavor = PHY_TIMESTAMPING; + else + return -EINVAL; + + if (!rtnl_trylock()) + return restart_syscall(); + + if (!dev_isalive(netdev)) + goto out; + + if (netdev->selected_timestamping_layer != flavor) { + const struct net_device_ops *ops = netdev->netdev_ops; + struct ifreq ifr = {0}; + + /* Disable time stamping in the current layer. */ + if (netif_device_present(netdev) && ops->ndo_eth_ioctl) + ops->ndo_eth_ioctl(netdev, &ifr, SIOCSHWTSTAMP); + + netdev->selected_timestamping_layer = flavor; + } +out: + rtnl_unlock(); + return len; +} +static DEVICE_ATTR_RW(current_timestamping_provider); static struct attribute *net_class_attrs[] __ro_after_init = { &dev_attr_netdev_group.attr, diff --git a/net/core/timestamping.c b/net/core/timestamping.c index 04840697fe79..31c3142787b7 100644 --- a/net/core/timestamping.c +++ b/net/core/timestamping.c @@ -28,6 +28,9 @@ void skb_clone_tx_timestamp(struct sk_buff *skb) if (!skb->sk) return; + if (skb->dev->selected_timestamping_layer != PHY_TIMESTAMPING) + return; + type = classify(skb); if (type == PTP_CLASS_NONE) return; @@ -50,6 +53,9 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb) if (!skb->dev || !skb->dev->phydev || !skb->dev->phydev->mii_ts) return false; + if (skb->dev->selected_timestamping_layer != PHY_TIMESTAMPING) + return false; + if (skb_headroom(skb) < ETH_HLEN) return false; diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 651d18eef589..7b50820c1d1d 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -545,10 +545,20 @@ int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) memset(info, 0, sizeof(*info)); info->cmd = ETHTOOL_GET_TS_INFO; - if (phy_has_tsinfo(phydev)) - return phy_ts_info(phydev, info); - if (ops->get_ts_info) - return ops->get_ts_info(dev, info); + switch (dev->selected_timestamping_layer) { + + case MAC_TIMESTAMPING: + if (ops->get_ts_info) + return ops->get_ts_info(dev, info); + break; + + case PHY_TIMESTAMPING: + if (phy_has_tsinfo(phydev)) { + return phy_ts_info(phydev, info); + } + WARN_ON(1); + return -ENODEV; + } info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE; From patchwork Mon Jan 3 23:25:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Cochran X-Patchwork-Id: 12702813 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 92BA6C433FE for ; Mon, 3 Jan 2022 23:26:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231130AbiACX0G (ORCPT ); Mon, 3 Jan 2022 18:26:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230501AbiACX0D (ORCPT ); Mon, 3 Jan 2022 18:26:03 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79C52C061761; Mon, 3 Jan 2022 15:26:03 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id t187so17104012pfb.11; Mon, 03 Jan 2022 15:26:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nunRUnjuTlZ2TkjRJzWs2h82t5bGSvU4/zGNqg54R6s=; b=cUUBnoXtq1vx7LD8nnJg56cLY42F8nERJOLNmLfhPcDB4ZFAi+MrSkHblqc5Jt73eb 8WAJ2tpYfcx+QezaXXTysW0+u+VfN7eukl0rnpEC0+2AL7FMsg64GXSZEJozgQhAFUkI QJlEkow7zpac+ufwnNECt+5LgDMZY0pGUr8vId/kj3Er7VROCVmomfxfskDG6BJ4KcnJ eov8rkeIFGUHRnc7tS6++G0oUNVGJ5Pud0tRA4auQEV3MV12Fqvl701bwoQVTRfsmvFJ RRQpwsp8vJTQNnBzoNovxd03PxLaaGg8TEBBrTkOZZpo4BXCp2x0EcZkKhMaYXMhl0m5 PSlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nunRUnjuTlZ2TkjRJzWs2h82t5bGSvU4/zGNqg54R6s=; b=K55KvcvHNHxhPges8DqACqa10LXZgBCdASfEdtggqB0Ns83lmAhIHiNwjc5q2L2l3N 3VfQUzX9ppeNyDZUzQ0oLNoXFTuRPmoGty2mVlORv+Nn7CgvpJiBE5oaTLUBH2Y7Y6uT 3HDHk5s8gbZ/pGcovJe/RKbeKIpRYcL20rInG2kzjyB9OHRtQNh5/+Ulj5zaUQGlQ+iV ocgLT1XkeNywaoNN2YBRbj9IVK+EVsiCM5KJsWLyulNbQzBi+/0pBQ4gLrc9XYAxXFLO 1oGKjOj4Hd1YN0osqXU00Om7I/XyO3OP/jhJ+ADCYusj8X2SDiSPUBHGNV2aC1feboUT NlBA== X-Gm-Message-State: AOAM530S7aonyxxkFWqAluMKqgY61SvK8i8sPMahFfS6uAbe+b7kGSQb xEV98OT0BNP3ceZLBcy5LXIad2YWRKs= X-Google-Smtp-Source: ABdhPJzpzuFJv3nBIb7tK8IXIzoyfa98OakrwcFZCAI4dRsFtuolDGYYNvE/uyeEWjFtL3daFee9ng== X-Received: by 2002:a63:154f:: with SMTP id 15mr41804582pgv.521.1641252362841; Mon, 03 Jan 2022 15:26:02 -0800 (PST) Received: from localhost.localdomain ([2601:640:8200:33:e2d5:5eff:fea5:802f]) by smtp.gmail.com with ESMTPSA id k6sm41340191pff.106.2022.01.03.15.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jan 2022 15:26:02 -0800 (PST) From: Richard Cochran To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrew Lunn , David Miller , Grygorii Strashko , Jakub Kicinski , Joakim Zhang , Kurt Kanzenbach , Miroslav Lichvar , Russell King , Vladimir Oltean Subject: [PATCH RFC V1 net-next 4/4] net: fix up drivers WRT phy time stamping Date: Mon, 3 Jan 2022 15:25:55 -0800 Message-Id: <20220103232555.19791-5-richardcochran@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC For "git bisect" correctness, this patch should be squashed in to the previous one, but it is broken out here for the purpose of review. Signed-off-by: Richard Cochran --- drivers/net/ethernet/freescale/fec_main.c | 23 +++++++++----------- drivers/net/ethernet/mscc/ocelot_net.c | 21 +++++++++--------- drivers/net/ethernet/ti/cpsw_priv.c | 12 +++++------ drivers/net/ethernet/ti/netcp_ethss.c | 26 +++++------------------ drivers/net/macvlan.c | 4 +--- 5 files changed, 32 insertions(+), 54 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 796133de527e..2f62990f9ced 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -2935,22 +2935,19 @@ static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) if (!netif_running(ndev)) return -EINVAL; + switch (cmd) { + case SIOCSHWTSTAMP: + return fep->bufdesc_ex ? fec_ptp_set(ndev, rq) : + -EOPNOTSUPP; + + case SIOCGHWTSTAMP: + return fep->bufdesc_ex ? fec_ptp_get(ndev, rq) : + -EOPNOTSUPP; + } + if (!phydev) return -ENODEV; - if (fep->bufdesc_ex) { - bool use_fec_hwts = !phy_has_hwtstamp(phydev); - - if (cmd == SIOCSHWTSTAMP) { - if (use_fec_hwts) - return fec_ptp_set(ndev, rq); - fec_ptp_disable_hwts(ndev); - } else if (cmd == SIOCGHWTSTAMP) { - if (use_fec_hwts) - return fec_ptp_get(ndev, rq); - } - } - return phy_mii_ioctl(phydev, rq, cmd); } diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index 8115c3db252e..d9a0988404d0 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -755,18 +755,19 @@ static int ocelot_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) struct ocelot *ocelot = priv->port.ocelot; int port = priv->chip_port; - /* If the attached PHY device isn't capable of timestamping operations, - * use our own (when possible). - */ - if (!phy_has_hwtstamp(dev->phydev) && ocelot->ptp) { - switch (cmd) { - case SIOCSHWTSTAMP: - return ocelot_hwstamp_set(ocelot, port, ifr); - case SIOCGHWTSTAMP: - return ocelot_hwstamp_get(ocelot, port, ifr); - } + switch (cmd) { + case SIOCSHWTSTAMP: + return ocelot->ptp ? ocelot_hwstamp_set(ocelot, port, ifr) : + -EOPNOTSUPP; + + case SIOCGHWTSTAMP: + return ocelot->ptp ? ocelot_hwstamp_get(ocelot, port, ifr) : + -EOPNOTSUPP; } + if (!dev->phydev) + return -ENODEV; + return phy_mii_ioctl(dev->phydev, ifr, cmd); } diff --git a/drivers/net/ethernet/ti/cpsw_priv.c b/drivers/net/ethernet/ti/cpsw_priv.c index 8624a044776f..5825efc6426e 100644 --- a/drivers/net/ethernet/ti/cpsw_priv.c +++ b/drivers/net/ethernet/ti/cpsw_priv.c @@ -713,13 +713,11 @@ int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd) phy = cpsw->slaves[slave_no].phy; - if (!phy_has_hwtstamp(phy)) { - switch (cmd) { - case SIOCSHWTSTAMP: - return cpsw_hwtstamp_set(dev, req); - case SIOCGHWTSTAMP: - return cpsw_hwtstamp_get(dev, req); - } + switch (cmd) { + case SIOCSHWTSTAMP: + return cpsw_hwtstamp_set(dev, req); + case SIOCGHWTSTAMP: + return cpsw_hwtstamp_get(dev, req); } if (phy) diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c index 751fb0bc65c5..36ce80f8bd6b 100644 --- a/drivers/net/ethernet/ti/netcp_ethss.c +++ b/drivers/net/ethernet/ti/netcp_ethss.c @@ -2557,15 +2557,6 @@ static int gbe_txtstamp_mark_pkt(struct gbe_intf *gbe_intf, !gbe_dev->tx_ts_enabled) return 0; - /* If phy has the txtstamp api, assume it will do it. - * We mark it here because skb_tx_timestamp() is called - * after all the txhooks are called. - */ - if (phy_has_txtstamp(phydev)) { - skb_shinfo(p_info->skb)->tx_flags |= SKBTX_IN_PROGRESS; - return 0; - } - if (gbe_need_txtstamp(gbe_intf, p_info)) { p_info->txtstamp = gbe_txtstamp; p_info->ts_context = (void *)gbe_intf; @@ -2583,11 +2574,6 @@ static int gbe_rxtstamp(struct gbe_intf *gbe_intf, struct netcp_packet *p_info) if (p_info->rxtstamp_complete) return 0; - if (phy_has_rxtstamp(phydev)) { - p_info->rxtstamp_complete = true; - return 0; - } - if (gbe_dev->rx_ts_enabled) cpts_rx_timestamp(gbe_dev->cpts, p_info->skb); @@ -2821,13 +2807,11 @@ 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); - } + switch (cmd) { + case SIOCGHWTSTAMP: + return gbe_hwtstamp_get(gbe_intf, req); + case SIOCSHWTSTAMP: + return gbe_hwtstamp_set(gbe_intf, req); } if (phy) diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 6ef5f77be4d0..13264c3e4192 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -1055,9 +1055,7 @@ static int macvlan_ethtool_get_ts_info(struct net_device *dev, const struct ethtool_ops *ops = real_dev->ethtool_ops; struct phy_device *phydev = real_dev->phydev; - if (phy_has_tsinfo(phydev)) { - return phy_ts_info(phydev, info); - } else if (ops->get_ts_info) { + if (ops->get_ts_info) { return ops->get_ts_info(real_dev, info); } else { info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |