From patchwork Sun Apr 23 03:27:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13221163 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 54C17C7618E for ; Sun, 23 Apr 2023 03:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229668AbjDWD1x (ORCPT ); Sat, 22 Apr 2023 23:27:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjDWD1u (ORCPT ); Sat, 22 Apr 2023 23:27:50 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 948521FCC for ; Sat, 22 Apr 2023 20:27:49 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-760f4dcfdf4so321261439f.2 for ; Sat, 22 Apr 2023 20:27:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682220469; x=1684812469; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wo/pA3JfWPnhr3873Y/T/4AhC8WxshHyfwZ3E9LgLtg=; b=KbzYHFLp/CKU2WRzwsKeSwHRcQfdQRDROS2yPjdJ/Qx0MISC7LUbiu7IB7EycerCW6 OzR4M8Yiy2ANB+GwF6ED5fZv9006CYVjjq3ij6rWk3e1uYipgNm1/8cjW/5DUUV1+NSU 0L44DvDVWAs9EnlDjjstII3AOBUrRRXstLbevd1ZC1+tcNm3gQHg3YcHifWWc+EaSsof gt4Hn7JRx/vLBMC2Rn3r62r4muYvHweD5qrbUqoUaP7t5zlMZnYBZ7B9xcrN983w3H57 wWvegiJvg5af8AcVfXclyvsWIpFfmJTh2rD+6FU9n2YEpt7p0OwHdemQXHrNClnAy3L0 vRLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682220469; x=1684812469; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wo/pA3JfWPnhr3873Y/T/4AhC8WxshHyfwZ3E9LgLtg=; b=Ty0keo9D/vqcjbfFUdrra9avTJJnl1PyaM+cNuD148yOyg6oEhuUv3zaMYE0qxnsuc s829P3R02IFnOjgZQBT0sTI7b0wX4rDp8KQqkaA1RiL7NtnrYoN95JUK9m8d05eFISJO rvjrr4nVhD9d3c5wyEGl5J8yvVGDamtW043KBWmLav7/C1nKhb4hIQI8MlfxOziZEA04 NUDW2DaNDVrpl9iOYLVcn/H+KMZmUv1AkhtT0YsyiKHEiw4irg47gNHcIJLfaPib2q/5 bqTix5oVBodPvHkTFC99p17RJDaRgXIuG1VU0YukMSt6Qa+CFMcREfkcvMGIZh3IOtgG pnBA== X-Gm-Message-State: AAQBX9dRzFoQ5V7HZJjR8uMDlK2sqQBqXQBecw1IW+LtCounVyhztRed wzJ0PGOaEpU6XsOiSbvRJ2c= X-Google-Smtp-Source: AKy350abqy6y0H/62WCfNBzyddlPYKZYZnUaPxGzuFvEQxBOiHkzaYycDlD9qHWwDq+v6+mNBxKS9w== X-Received: by 2002:a5e:aa07:0:b0:752:ee32:322d with SMTP id s7-20020a5eaa07000000b00752ee32322dmr2915494ioe.18.1682220468890; Sat, 22 Apr 2023 20:27:48 -0700 (PDT) Received: from lenovot480s.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id y24-20020a027318000000b0040fbc31614esm2357450jab.54.2023.04.22.20.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 20:27:48 -0700 (PDT) From: Maxim Georgiev To: kory.maincent@bootlin.com Cc: kuba@kernel.org, netdev@vger.kernel.org, glipus@gmail.com, maxime.chevallier@bootlin.com, vladimir.oltean@nxp.com, vadim.fedorenko@linux.dev, richardcochran@gmail.com, gerhard@engleder-embedded.com Subject: [RFC PATCH v4 1/5] Add NDOs for hardware timestamp get/set Date: Sat, 22 Apr 2023 21:27:47 -0600 Message-Id: <20230423032747.285295-1-glipus@gmail.com> X-Mailer: git-send-email 2.39.2 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 Current NIC driver API demands drivers supporting hardware timestamping to implement handling logic for SIOCGHWTSTAMP/SIOCSHWTSTAMP IOCTLs. Handling these IOCTLs requires dirivers to implement request parameter structure translation between user and kernel address spaces, handling possible translation failures, etc. This translation code is pretty much identical across most of the NIC drivers that support SIOCGHWTSTAMP/ SIOCSHWTSTAMP. This patch extends NDO functiuon set with ndo_hwtstamp_get/set functions, implements SIOCGHWTSTAMP/SIOCSHWTSTAMP IOCTL translation to ndo_hwtstamp_get/set function calls including parameter structure translation and translation error handling. This patch is sent out as RFC. It still pending on basic testing. Suggested-by: Jakub Kicinski Signed-off-by: Maxim Georgiev --- Changes in v4: - Renamed hwtstamp_kernel_to_config() function to hwtstamp_config_from_kernel(). - Added struct kernel_hwtstamp_config zero initialization in dev_get_hwtstamp() and in dev_get_hwtstamp(). Changes in v3: - Moved individual driver conversions to separate patches Changes in v2: - Introduced kernel_hwtstamp_config structure - Added netlink_ext_ack* and kernel_hwtstamp_config* as NDO hw timestamp function parameters - Reodered function variable declarations in dev_hwtstamp() - Refactored error handling logic in dev_hwtstamp() - Split dev_hwtstamp() into GET and SET versions - Changed net_hwtstamp_validate() to accept struct hwtstamp_config * as a parameter --- include/linux/net_tstamp.h | 8 ++++++++ include/linux/netdevice.h | 16 +++++++++++++++ net/core/dev_ioctl.c | 42 +++++++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h index fd67f3cc0c4b..7c59824f43f5 100644 --- a/include/linux/net_tstamp.h +++ b/include/linux/net_tstamp.h @@ -30,4 +30,12 @@ static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kern kernel_cfg->rx_filter = cfg->rx_filter; } +static inline void hwtstamp_config_from_kernel(struct hwtstamp_config *cfg, + const struct kernel_hwtstamp_config *kernel_cfg) +{ + cfg->flags = kernel_cfg->flags; + cfg->tx_type = kernel_cfg->tx_type; + cfg->rx_filter = kernel_cfg->rx_filter; +} + #endif /* _LINUX_NET_TIMESTAMPING_H_ */ diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index a6a3e9457d6c..ea10fb1dd6fc 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -57,6 +57,7 @@ struct netpoll_info; struct device; struct ethtool_ops; +struct kernel_hwtstamp_config; struct phy_device; struct dsa_port; struct ip_tunnel_parm; @@ -1415,6 +1416,15 @@ struct netdev_net_notifier { * Get hardware timestamp based on normal/adjustable time or free running * cycle counter. This function is required if physical clock supports a * free running cycle counter. + * int (*ndo_hwtstamp_get)(struct net_device *dev, + * struct kernel_hwtstamp_config *kernel_config, + * struct netlink_ext_ack *extack); + * Get hardware timestamping parameters currently configured for NIC + * device. + * int (*ndo_hwtstamp_set)(struct net_device *dev, + * struct kernel_hwtstamp_config *kernel_config, + * struct netlink_ext_ack *extack); + * Set hardware timestamping parameters for NIC device. */ struct net_device_ops { int (*ndo_init)(struct net_device *dev); @@ -1649,6 +1659,12 @@ struct net_device_ops { ktime_t (*ndo_get_tstamp)(struct net_device *dev, const struct skb_shared_hwtstamps *hwtstamps, bool cycles); + int (*ndo_hwtstamp_get)(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_config, + struct netlink_ext_ack *extack); + int (*ndo_hwtstamp_set)(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_config, + struct netlink_ext_ack *extack); }; struct xdp_metadata_ops { diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 3730945ee294..a157b9ab5237 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -254,12 +254,33 @@ static int dev_eth_ioctl(struct net_device *dev, static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) { - return dev_eth_ioctl(dev, ifr, SIOCGHWTSTAMP); + const struct net_device_ops *ops = dev->netdev_ops; + struct kernel_hwtstamp_config kernel_cfg = {}; + struct hwtstamp_config config; + int err; + + if (!ops->ndo_hwtstamp_get) + return dev_eth_ioctl(dev, ifr, SIOCGHWTSTAMP); + + if (!netif_device_present(dev)) + return -ENODEV; + + err = ops->ndo_hwtstamp_get(dev, &kernel_cfg, NULL); + if (err) + return err; + + hwtstamp_config_from_kernel(&config, &kernel_cfg); + + if (copy_to_user(ifr->ifr_data, &config, sizeof(config))) + return -EFAULT; + + return 0; } static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) { - struct kernel_hwtstamp_config kernel_cfg; + const struct net_device_ops *ops = dev->netdev_ops; + struct kernel_hwtstamp_config kernel_cfg = {}; struct netlink_ext_ack extack = {}; struct hwtstamp_config cfg; int err; @@ -280,7 +301,22 @@ static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) return err; } - return dev_eth_ioctl(dev, ifr, SIOCSHWTSTAMP); + if (!ops->ndo_hwtstamp_set) + return dev_eth_ioctl(dev, ifr, SIOCSHWTSTAMP); + + if (!netif_device_present(dev)) + return -ENODEV; + + err = ops->ndo_hwtstamp_set(dev, &kernel_cfg, NULL); + if (err) + return err; + + hwtstamp_config_from_kernel(&cfg, &kernel_cfg); + + if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg))) + return -EFAULT; + + return 0; } static int dev_siocbond(struct net_device *dev, From patchwork Sun Apr 23 03:28:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13221164 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 0F941C7618E for ; Sun, 23 Apr 2023 03:28:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229745AbjDWD2W (ORCPT ); Sat, 22 Apr 2023 23:28:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjDWD2V (ORCPT ); Sat, 22 Apr 2023 23:28:21 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80FF81FCC for ; Sat, 22 Apr 2023 20:28:19 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-7606d44dbb5so322253839f.1 for ; Sat, 22 Apr 2023 20:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682220499; x=1684812499; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3GgoE2aOQOI5zItubNE1qgEZS1ikxgaHXPxaumgsPxE=; b=n/5DV0ulQhMkbgG1W6ufUeXLvXKMrs6M2IQ4iOHvYm0/YftlLaH2bfJVgqSe9Kd5gR 7oNmDuT/Fkw6Ayh6gwCRferNnOQFWVjEGGqF8bKKiwVV685TWhkEJcomsqxITBMAmZMp jdSPFhraDbDE77WC/zx1PjnJCYFujclXlsPCDRzv2SpeDsVJMQBzKIF3oL6JWPq32cgI SDZ5sK0WLSgeyaoMGvPszI/elESJ/9mtI9fFObvGrYGwOFHgL5H8TDfdsn4Ovh6KOuvP YPIB2gcalXDQUcO1j4dyFdkwQKDcYrYoJHSYwbi4CuhxbuOEEtrF+ScU5iRRIWBXDXFX bwNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682220499; x=1684812499; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3GgoE2aOQOI5zItubNE1qgEZS1ikxgaHXPxaumgsPxE=; b=SN/3q1lcqYLAk0/ipI6TboAjwwYUnuqEddQ11yWpghQIPqgLH8XLWQ69qRYF51I3st JhFO6K46FPx79SmHxjcpDSZLTEZPdm/Wtf17A5sLHx3diofqR9oOgAmnW/nQuzIS1khW /h1e8VnyhWR5BASG3n95BiIS7RgTS/My9sF2Dx8jMq/7zKB+lLq1FUifwEaxiyo0micD flVwp4HwBd8pmynJCPrfgmHHtx5dkqphtfhk/OOnnbqQ6kutiKbLUTSLAkVds+ledwZ/ JYtDcIMJI6KsMQ/8HTG0k0nnTCJHWWlW7WqlZ9sBqCZwN4RhqTmM3EJLevsEKBSL2amZ OhGw== X-Gm-Message-State: AAQBX9cYUsqDrJpprkJsn8kfZkBA3aOfUuiTfL/oVhhvZPHlSQyippjE 8Tk1pH4HkxhQaK517t46URU= X-Google-Smtp-Source: AKy350ZhkZnXPMOu3Z5ALAOuHuTcE6+V0V/EoWGq9TgUkaY/ARfJpVAZnNRNXjUbdnABUk+V9mZPTQ== X-Received: by 2002:a6b:f315:0:b0:74c:ae72:dc16 with SMTP id m21-20020a6bf315000000b0074cae72dc16mr2983099ioh.5.1682220498817; Sat, 22 Apr 2023 20:28:18 -0700 (PDT) Received: from lenovot480s.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id 18-20020a5d9c52000000b0076350d7c4b6sm1275122iof.36.2023.04.22.20.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 20:28:18 -0700 (PDT) From: Maxim Georgiev To: kory.maincent@bootlin.com Cc: kuba@kernel.org, netdev@vger.kernel.org, glipus@gmail.com, maxime.chevallier@bootlin.com, vladimir.oltean@nxp.com, vadim.fedorenko@linux.dev, richardcochran@gmail.com, gerhard@engleder-embedded.com Subject: [RFC PATCH v4 2/5] Add ifreq pointer field to kernel_hwtstamp_config structure Date: Sat, 22 Apr 2023 21:28:17 -0600 Message-Id: <20230423032817.285371-1-glipus@gmail.com> X-Mailer: git-send-email 2.39.2 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 Considering the stackable nature of drivers there will be situations where a driver implementing ndo_hwtstamp_get/set functions will have to translate requests back to SIOCGHWTSTAMP/SIOCSHWTSTAMP IOCTLs to pass them to lower level drivers that do not provide ndo_hwtstamp_get/set callbacks. To simplify request translation in such scenarios let's include a pointer to the original struct ifreq to kernel_hwtstamp_config structure. Suggested-by: Jakub Kicinski Signed-off-by: Maxim Georgiev Notes: Changes in V4: - Introducing KERNEL_HWTSTAMP_FLAG_IFR_RESULT flag indicating that the operation results are returned in the ifr referred by struct kernel_hwtstamp_config instead of kernel_hwtstamp_config glags/tx_type/rx_filter fields. - Implementing generic_hwtstamp_set/set_lower() functions which will be used by vlan, maxvlan, bond and potentially other drivers translating ndo_hwtstamp_set/set calls to lower level drivers. --- include/linux/net_tstamp.h | 7 ++++ include/linux/netdevice.h | 6 +++ net/core/dev_ioctl.c | 80 +++++++++++++++++++++++++++++++++++--- 3 files changed, 87 insertions(+), 6 deletions(-) diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h index 7c59824f43f5..5164dce3f9a0 100644 --- a/include/linux/net_tstamp.h +++ b/include/linux/net_tstamp.h @@ -20,6 +20,13 @@ struct kernel_hwtstamp_config { int flags; int tx_type; int rx_filter; + struct ifreq *ifr; + int kernel_flags; +}; + +/* possible values for kernel_hwtstamp_config->kernel_flags */ +enum kernel_hwtstamp_flags { + KERNEL_HWTSTAMP_FLAG_IFR_RESULT = (1 << 0), }; static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg, diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index ea10fb1dd6fc..40f4018b13f2 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3939,6 +3939,12 @@ int put_user_ifreq(struct ifreq *ifr, void __user *arg); int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr, void __user *data, bool *need_copyout); int dev_ifconf(struct net *net, struct ifconf __user *ifc); +int generic_hwtstamp_set_lower(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_cfg, + struct netlink_ext_ack *extack); +int generic_hwtstamp_get_lower(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_cfg, + struct netlink_ext_ack *extack); int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *userdata); unsigned int dev_get_flags(const struct net_device *); int __dev_change_flags(struct net_device *dev, unsigned int flags, diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index a157b9ab5237..da1d2391822f 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -265,14 +265,17 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) if (!netif_device_present(dev)) return -ENODEV; + kernel_cfg.ifr = ifr; err = ops->ndo_hwtstamp_get(dev, &kernel_cfg, NULL); if (err) return err; - hwtstamp_config_from_kernel(&config, &kernel_cfg); + if (!(kernel_cfg.kernel_flags & KERNEL_HWTSTAMP_FLAG_IFR_RESULT)) { + hwtstamp_config_from_kernel(&config, &kernel_cfg); - if (copy_to_user(ifr->ifr_data, &config, sizeof(config))) - return -EFAULT; + if (copy_to_user(ifr->ifr_data, &config, sizeof(config))) + return -EFAULT; + } return 0; } @@ -289,6 +292,7 @@ static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) return -EFAULT; hwtstamp_config_to_kernel(&kernel_cfg, &cfg); + kernel_cfg.ifr = ifr; err = net_hwtstamp_validate(&kernel_cfg); if (err) @@ -311,14 +315,78 @@ static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) if (err) return err; - hwtstamp_config_from_kernel(&cfg, &kernel_cfg); + if (!(kernel_cfg.kernel_flags & KERNEL_HWTSTAMP_FLAG_IFR_RESULT)) { + hwtstamp_config_from_kernel(&cfg, &kernel_cfg); - if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg))) - return -EFAULT; + if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg))) + return -EFAULT; + } return 0; } +int generic_hwtstamp_set_lower(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_cfg, + struct netlink_ext_ack *extack) +{ + const struct net_device_ops *ops = dev->netdev_ops; + struct ifreq ifrr; + int err; + + if (!netif_device_present(dev)) + return -ENODEV; + + if (ops->ndo_hwtstamp_set) { + kernel_cfg->kernel_flags &= ~KERNEL_HWTSTAMP_FLAG_IFR_RESULT; + err = ops->ndo_hwtstamp_set(dev, kernel_cfg, extack); + return err; + } + + if (!kernel_cfg->ifr) + return -EOPNOTSUPP; + + strscpy_pad(ifrr.ifr_name, dev->name, IFNAMSIZ); + ifrr.ifr_ifru = kernel_cfg->ifr->ifr_ifru; + err = dev_eth_ioctl(dev, &ifrr, SIOCSHWTSTAMP); + if (!err) { + kernel_cfg->ifr->ifr_ifru = ifrr.ifr_ifru; + kernel_cfg->kernel_flags |= KERNEL_HWTSTAMP_FLAG_IFR_RESULT; + } + return err; +} +EXPORT_SYMBOL(generic_hwtstamp_set_lower); + +int generic_hwtstamp_get_lower(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_cfg, + struct netlink_ext_ack *extack) +{ + const struct net_device_ops *ops = dev->netdev_ops; + struct ifreq ifrr; + int err; + + if (!netif_device_present(dev)) + return -ENODEV; + + if (ops->ndo_hwtstamp_get) { + kernel_cfg->kernel_flags &= ~KERNEL_HWTSTAMP_FLAG_IFR_RESULT; + err = ops->ndo_hwtstamp_get(dev, kernel_cfg, extack); + return err; + } + + if (!kernel_cfg->ifr) + return -EOPNOTSUPP; + + strscpy_pad(ifrr.ifr_name, dev->name, IFNAMSIZ); + ifrr.ifr_ifru = kernel_cfg->ifr->ifr_ifru; + err = dev_eth_ioctl(dev, &ifrr, SIOCGHWTSTAMP); + if (!err) { + kernel_cfg->ifr->ifr_ifru = ifrr.ifr_ifru; + kernel_cfg->kernel_flags |= KERNEL_HWTSTAMP_FLAG_IFR_RESULT; + } + return err; +} +EXPORT_SYMBOL(generic_hwtstamp_get_lower); + static int dev_siocbond(struct net_device *dev, struct ifreq *ifr, unsigned int cmd) { From patchwork Sun Apr 23 03:28:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13221165 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 C99DEC77B76 for ; Sun, 23 Apr 2023 03:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbjDWD2l (ORCPT ); Sat, 22 Apr 2023 23:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229806AbjDWD2j (ORCPT ); Sat, 22 Apr 2023 23:28:39 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C433268C for ; Sat, 22 Apr 2023 20:28:37 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3294eacb2f6so8249045ab.3 for ; Sat, 22 Apr 2023 20:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682220516; x=1684812516; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=X6ncj33axFGuFSNqzwi02ap0pe4Ng+6vF3DosaLcrFo=; b=fQy9CTKUG0L22usws+M5ZVn3UxJXTMl6i//ATEDOmL5kiiN+0VjPPBbj8lLVK1jzgg Vbu8AS5V3He6EUg0DsXZJq38hVRBkC7NT+pjn2dpnINnbQ8rEjI9TMPxkMrrK8YdPLdh p80QyTLJkPbYhTZrTDBwFJ+2wEHTsCs9GZClT6YMHZHGJSslrNWvUr6lvrFzpDwnzAHp v2df5P86NHRAMbRE9ckeGIfnBzWb/YyhBxsoc1/rHs+Ys0zH9dnmIOZsnGVu1B9SU+Xg 6g9ou1lgFe2GZ1iIWsvuCY4+Y5ZgHh3I0Sy7r0GTxpW0zdL/1FaXcEqkWtWl8o0aw7wI gsMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682220516; x=1684812516; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X6ncj33axFGuFSNqzwi02ap0pe4Ng+6vF3DosaLcrFo=; b=ErlFLUam3tAF221G4KALZaGzIN86BWRwk/7Ex+A04R7IWMpsL2P+u7RYxnV6PBQFx6 wb1I//ORz6I6XjiV5NtrfBpe8wzdR00HyVJm2zh5XWNQBWRoZ6RRb5B88Sc832woQr+Z KD8HmGtliTWrS3amUUGlcLbLbbgnBvnXIpe5e2O7KoaSf6uJfVGUadz0wSmI7BsyGVCV +KvPFFh5vtco/TqXNj6gaFLhtJUZ9mFVraT0HQynw2KojbXdX+B1a6D71XVNfoWVWLpK w0rcU9imEPg1l+dBQAJU4+FQuJQEkrLc2ZKMTKW/E5ryaHda9thb8oRp0zMlxDry4ZG9 MUFA== X-Gm-Message-State: AAQBX9fJI+sqzjyueQ1gGgHCccXRBIz6mwIwIoqkotjDmtS1YTEHYAWV wCOnfrOFLFUiPtLklsni/Uk= X-Google-Smtp-Source: AKy350YJCkf41Lbqop9xRXTdObTDu1KgSo4jSsAVqxIKfB2+YcVvTF3sdIkqyscsr5NRf2d4BGjHsg== X-Received: by 2002:a6b:e50a:0:b0:763:5ead:f20b with SMTP id y10-20020a6be50a000000b007635eadf20bmr2857912ioc.16.1682220516304; Sat, 22 Apr 2023 20:28:36 -0700 (PDT) Received: from lenovot480s.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id t14-20020a5d884e000000b00760a612675dsm2158330ios.16.2023.04.22.20.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 20:28:35 -0700 (PDT) From: Maxim Georgiev To: kory.maincent@bootlin.com Cc: kuba@kernel.org, netdev@vger.kernel.org, glipus@gmail.com, maxime.chevallier@bootlin.com, vladimir.oltean@nxp.com, vadim.fedorenko@linux.dev, richardcochran@gmail.com, gerhard@engleder-embedded.com Subject: [RFC PATCH v4 3/5] Add ndo_hwtstamp_get/set support to vlan/maxvlan code path Date: Sat, 22 Apr 2023 21:28:35 -0600 Message-Id: <20230423032835.285406-1-glipus@gmail.com> X-Mailer: git-send-email 2.39.2 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 This patch makes VLAN and MAXVLAN drivers to use the newly introduced ndo_hwtstamp_get/set API to pass hw timestamp requests to underlying NIC drivers in case if these drivers implement ndo_hwtstamp_get/set functions. Otherwise VLAN subsystems falls back to calling ndo_eth_ioctl. Suggested-by: Vladimir Oltean Signed-off-by: Maxim Georgiev --- Notes: Changes in v4: - Moved hw timestamp get/set request processing logic from vlan_dev_ioctl() to .ndo_hwtstamp_get/set callbacks. - Use the shared generic_hwtstamp_get/set_lower() functions to handle ndo_hwtstamp_get/set requests. - Applay the same changes to macvlan driver. --- drivers/net/macvlan.c | 34 +++++++++++++--------------------- net/8021q/vlan_dev.c | 25 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 4a53debf9d7c..32683d859f5f 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -868,31 +868,22 @@ static int macvlan_change_mtu(struct net_device *dev, int new_mtu) return 0; } -static int macvlan_eth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +static int macvlan_hwtstamp_get(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) { struct net_device *real_dev = macvlan_dev_real_dev(dev); - const struct net_device_ops *ops = real_dev->netdev_ops; - struct ifreq ifrr; - int err = -EOPNOTSUPP; - strscpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ); - ifrr.ifr_ifru = ifr->ifr_ifru; - - switch (cmd) { - case SIOCSHWTSTAMP: - if (!net_eq(dev_net(dev), &init_net)) - break; - fallthrough; - case SIOCGHWTSTAMP: - if (netif_device_present(real_dev) && ops->ndo_eth_ioctl) - err = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd); - break; - } + return generic_hwtstamp_get_lower(real_dev, cfg, extack); +} - if (!err) - ifr->ifr_ifru = ifrr.ifr_ifru; +static int macvlan_hwtstamp_set(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) +{ + struct net_device *real_dev = macvlan_dev_real_dev(dev); - return err; + return generic_hwtstamp_set_lower(real_dev, cfg, extack); } /* @@ -1193,7 +1184,6 @@ static const struct net_device_ops macvlan_netdev_ops = { .ndo_stop = macvlan_stop, .ndo_start_xmit = macvlan_start_xmit, .ndo_change_mtu = macvlan_change_mtu, - .ndo_eth_ioctl = macvlan_eth_ioctl, .ndo_fix_features = macvlan_fix_features, .ndo_change_rx_flags = macvlan_change_rx_flags, .ndo_set_mac_address = macvlan_set_mac_address, @@ -1212,6 +1202,8 @@ static const struct net_device_ops macvlan_netdev_ops = { #endif .ndo_get_iflink = macvlan_dev_get_iflink, .ndo_features_check = passthru_features_check, + .ndo_hwtstamp_get = macvlan_hwtstamp_get, + .ndo_hwtstamp_set = macvlan_hwtstamp_set, }; static void macvlan_dev_free(struct net_device *dev) diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 5920544e93e8..38a31dca3bb9 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -353,6 +353,24 @@ static int vlan_dev_set_mac_address(struct net_device *dev, void *p) return 0; } +static int vlan_hwtstamp_get(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) +{ + struct net_device *real_dev = vlan_dev_priv(dev)->real_dev; + + return generic_hwtstamp_get_lower(real_dev, cfg, extack); +} + +static int vlan_hwtstamp_set(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) +{ + struct net_device *real_dev = vlan_dev_priv(dev)->real_dev; + + return generic_hwtstamp_set_lower(real_dev, cfg, extack); +} + static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { struct net_device *real_dev = vlan_dev_priv(dev)->real_dev; @@ -364,14 +382,9 @@ static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ifrr.ifr_ifru = ifr->ifr_ifru; switch (cmd) { - case SIOCSHWTSTAMP: - if (!net_eq(dev_net(dev), dev_net(real_dev))) - break; - fallthrough; case SIOCGMIIPHY: case SIOCGMIIREG: case SIOCSMIIREG: - case SIOCGHWTSTAMP: if (netif_device_present(real_dev) && ops->ndo_eth_ioctl) err = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd); break; @@ -842,6 +855,8 @@ static const struct net_device_ops vlan_netdev_ops = { .ndo_fix_features = vlan_dev_fix_features, .ndo_get_iflink = vlan_dev_get_iflink, .ndo_fill_forward_path = vlan_dev_fill_forward_path, + .ndo_hwtstamp_get = vlan_hwtstamp_get, + .ndo_hwtstamp_set = vlan_hwtstamp_set, }; static void vlan_dev_free(struct net_device *dev) From patchwork Sun Apr 23 03:28:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13221166 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 29468C7618E for ; Sun, 23 Apr 2023 03:28:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229908AbjDWD2y (ORCPT ); Sat, 22 Apr 2023 23:28:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbjDWD2w (ORCPT ); Sat, 22 Apr 2023 23:28:52 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6D40268C for ; Sat, 22 Apr 2023 20:28:51 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-32b1c8ff598so29320575ab.3 for ; Sat, 22 Apr 2023 20:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682220531; x=1684812531; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p2zQDhkK5lKaWRelWoXh0mPSTQhbApTm4KvEZpVaTCM=; b=Gcos/7Gp4huSTIB/us95wVt+1ewWc/oBcO2HoJliiwTkRK6zrdd7zYp0jPL9hLhZqu VOBpQXsVf/0u/Sa3flVhRlzQMmTDZ5UBaKwBzdqEO38dgfwVsyVl/Ezqh8aLC4Z/LuE2 FBODO8RAGt7MjJDrCOt/Dqh34ldMISQdPavY1afZsJWKvqGebJxq3ZjKPbPMm8sMsBZ5 sUoDJleDONHkJ8jE1RKp+Uu+tsmlLAxHovGTb52YV54VVkwEaOjqVp3n7TuAHt/54Dk+ p8yD/eGPb6roZpDJwcQBy0wIaCRDXC0g1FLNByDVJrZ7zwPnKwNoDzzc9NCX8frNpbRl e3Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682220531; x=1684812531; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p2zQDhkK5lKaWRelWoXh0mPSTQhbApTm4KvEZpVaTCM=; b=gtnTqBEtLIqW2frrMXNA1tLUxV4fdKDTrmYTf7Hf/n1Aiw+dVE+sQ1PVIfRDsagyHA MJzMPWWv2nh0dZz3J6AOEm+phDCrf8B8dpwui0ig5GOeVnTP/YXfUIghjynmd1HYuxIT G+owmP9liqV4mTi20gMR3Gvsfc4Ljv+Vy83Fs9+OFNp0neYf1oh7yNoiCL2obRbFhRw0 4sD++3nLP6pt8lbeVoL2ZdWq2hxPu34pRG1GQ3JVdhhkz8dOwLPukVzcLaGxh2FgMuVi TBPEhqV6i5shbogFjawqD1Aww/rGqiTQ9semZw3n0LcG00BY5Qy3UShhYFcE4xYF+mgp Fs9Q== X-Gm-Message-State: AAQBX9dtpsFiYNscvexcDR8NGnDZYQfaawgpuvlf8Eep9YO99b2UIxZG aprHdcAJ1sOL2VUVXEGR41o= X-Google-Smtp-Source: AKy350bdEYGE3/kxoQJeOoK4GCIYKOnh0diW7zH7tuiLqIplXSGXyqVGB0nzN+W+tMVuR2sEznL3tA== X-Received: by 2002:a92:da86:0:b0:325:eb13:1045 with SMTP id u6-20020a92da86000000b00325eb131045mr2973988iln.2.1682220531055; Sat, 22 Apr 2023 20:28:51 -0700 (PDT) Received: from lenovot480s.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id cx27-20020a056638491b00b0040fa19472bcsm2384977jab.92.2023.04.22.20.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 20:28:50 -0700 (PDT) From: Maxim Georgiev To: kory.maincent@bootlin.com Cc: kuba@kernel.org, netdev@vger.kernel.org, glipus@gmail.com, maxime.chevallier@bootlin.com, vladimir.oltean@nxp.com, vadim.fedorenko@linux.dev, richardcochran@gmail.com, gerhard@engleder-embedded.com Subject: [RFC PATCH v4 4/5] Add ndo_hwtstamp_get/set support to bond driver Date: Sat, 22 Apr 2023 21:28:49 -0600 Message-Id: <20230423032849.285441-1-glipus@gmail.com> X-Mailer: git-send-email 2.39.2 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 This patch changes bonding net driver to use the newly introduced ndo_hwtstamp_get/set API to pass hw timestamp requests to underlying NIC drivers in case if these drivers implement ndo_hwtstamp_get/set functions. Otherwise VLAN subsystem falls back to calling ndo_eth_ioctl. Suggested-by: Vladimir Oltean Signed-off-by: Maxim Georgiev --- drivers/net/bonding/bond_main.c | 106 ++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 40 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 710548dbd0c1..21969afff2a9 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -4408,11 +4408,6 @@ static int bond_eth_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cm { struct bonding *bond = netdev_priv(bond_dev); struct mii_ioctl_data *mii = NULL; - const struct net_device_ops *ops; - struct net_device *real_dev; - struct hwtstamp_config cfg; - struct ifreq ifrr; - int res = 0; netdev_dbg(bond_dev, "bond_eth_ioctl: cmd=%d\n", cmd); @@ -4439,44 +4434,11 @@ static int bond_eth_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cm } break; - case SIOCSHWTSTAMP: - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - if (!(cfg.flags & HWTSTAMP_FLAG_BONDED_PHC_INDEX)) - return -EOPNOTSUPP; - - fallthrough; - case SIOCGHWTSTAMP: - real_dev = bond_option_active_slave_get_rcu(bond); - if (!real_dev) - return -EOPNOTSUPP; - - strscpy_pad(ifrr.ifr_name, real_dev->name, IFNAMSIZ); - ifrr.ifr_ifru = ifr->ifr_ifru; - - ops = real_dev->netdev_ops; - if (netif_device_present(real_dev) && ops->ndo_eth_ioctl) { - res = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd); - if (res) - return res; - - ifr->ifr_ifru = ifrr.ifr_ifru; - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - /* Set the BOND_PHC_INDEX flag to notify user space */ - cfg.flags |= HWTSTAMP_FLAG_BONDED_PHC_INDEX; - - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? - -EFAULT : 0; - } - fallthrough; default: - res = -EOPNOTSUPP; + return -EOPNOTSUPP; } - return res; + return 0; } static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd) @@ -5650,6 +5612,68 @@ static u32 bond_mode_bcast_speed(struct slave *slave, u32 speed) return speed; } +static int bond_set_phc_index_flag(struct kernel_hwtstamp_config *kernel_cfg) +{ + struct ifreq *ifr = kernel_cfg->ifr; + struct hwtstamp_config cfg; + + if (kernel_cfg->kernel_flags & KERNEL_HWTSTAMP_FLAG_IFR_RESULT) { + if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) + return -EFAULT; + + cfg.flags |= HWTSTAMP_FLAG_BONDED_PHC_INDEX; + if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg))) + return -EFAULT; + } else { + kernel_cfg->flags |= HWTSTAMP_FLAG_BONDED_PHC_INDEX; + } + + return 0; +} + +static int bond_hwtstamp_get(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) +{ + struct bonding *bond = netdev_priv(dev); + struct net_device *real_dev; + int err; + + real_dev = bond_option_active_slave_get_rcu(bond); + if (!real_dev) + return -EOPNOTSUPP; + + err = generic_hwtstamp_get_lower(real_dev, cfg, extack); + if (err) + return err; + + /* Set the BOND_PHC_INDEX flag to notify user space */ + return bond_set_phc_index_flag(cfg); +} + +static int bond_hwtstamp_set(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_cfg, + struct netlink_ext_ack *extack) +{ + struct bonding *bond = netdev_priv(dev); + struct net_device *real_dev; + int err; + + if (!(kernel_cfg->flags & HWTSTAMP_FLAG_BONDED_PHC_INDEX)) + return -EOPNOTSUPP; + + real_dev = bond_option_active_slave_get_rcu(bond); + if (!real_dev) + return -EOPNOTSUPP; + + err = generic_hwtstamp_set_lower(real_dev, kernel_cfg, extack); + if (err) + return err; + + /* Set the BOND_PHC_INDEX flag to notify user space */ + return bond_set_phc_index_flag(kernel_cfg); +} + static int bond_ethtool_get_link_ksettings(struct net_device *bond_dev, struct ethtool_link_ksettings *cmd) { @@ -5798,6 +5822,8 @@ static const struct net_device_ops bond_netdev_ops = { .ndo_bpf = bond_xdp, .ndo_xdp_xmit = bond_xdp_xmit, .ndo_xdp_get_xmit_slave = bond_xdp_get_xmit_slave, + .ndo_hwtstamp_get = bond_hwtstamp_get, + .ndo_hwtstamp_set = bond_hwtstamp_set, }; static const struct device_type bond_type = { From patchwork Sun Apr 23 03:29:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13221168 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 BEA1EC7618E for ; Sun, 23 Apr 2023 03:29:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjDWD3N (ORCPT ); Sat, 22 Apr 2023 23:29:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjDWD3M (ORCPT ); Sat, 22 Apr 2023 23:29:12 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6CD0210E for ; Sat, 22 Apr 2023 20:29:10 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7606ce89ebcso99031139f.0 for ; Sat, 22 Apr 2023 20:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682220550; x=1684812550; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hP8bu5KOGUVN1Wbdd5TILgIDJzXdQwhiwCS7uGeLOsE=; b=m3yuMWdg9ldpkx0UEOT4e2xZole3qgCHBSLuqnC+E497JhhQRFh5Owuu1ateZ8plYk jv+l6Tae8J7p6TrKyg9zdtzU38jYzD0IZ+1lt7WJU+kCksxEF3YQZ7QSS8qkce3Qmu+C ZBSoZcCtpDJhBu7nwhPHbAmwIW/qcikMz/Vjgtu8cbLW/08X+ajvP7dHasADe4+77kIc F9Qk1POQnoFIgDXa2oJYJcZqaUX0nMtzhLUugeAWzlFvOebquCQanLUBj12MSCVemVTN e6baY6OXR1PxIgQDWjEBG0We0CkTYD8wtV9/eEKJ48qkOruNij2qT3Q57lh877vnck6F kwXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682220550; x=1684812550; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hP8bu5KOGUVN1Wbdd5TILgIDJzXdQwhiwCS7uGeLOsE=; b=Rd4Huq8EHI4bRvfwhb73e7BzeOYVWXgEMIZvhniXskfb8/VFSHIhWgjkqR4wKuvKMf dnzR5iIWuNLMsjAEnvolEgAk94sX3GBkxIO9Ak88wr0TE7V4XIzj95Ag0sxX30jS5vQx GM3MYhEDTkH9UGIBS/viHL1sBgjrCwNVJUNn6weYVZTaIGjwSvgYr0lSOWGxLpWgl0be V0T9igWcjDEWfiyUxGaHNR6UZ2eVvDnO34Q3iYZQkDi4dMLGXyWDACByfq5D45WFeVu7 faqQSynNL/cBZoRi9VFSqKnd1xunIBh2rP6DjZ2RjOsXJjZ5tmWG4lFoTNj0YXwv1+DH zsAg== X-Gm-Message-State: AAQBX9d0cmb+fajV1StjajRaBz8HcxL2pGYnE1g/okjxINqiVCCQiPcC Jm6uqMhlTcOF1iMwmBCPBVE= X-Google-Smtp-Source: AKy350ae5i5mVNWfg/T4rv6HIo+7HqCOrAr4q9tdxQpm7U+oIeeS9Hzg8bNZgJbmebJaHfW3JhgxqQ== X-Received: by 2002:a92:cc12:0:b0:328:18af:df0 with SMTP id s18-20020a92cc12000000b0032818af0df0mr2896816ilp.23.1682220550106; Sat, 22 Apr 2023 20:29:10 -0700 (PDT) Received: from lenovot480s.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id v4-20020a056e0213c400b0031796c6d735sm2134561ilj.41.2023.04.22.20.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 20:29:09 -0700 (PDT) From: Maxim Georgiev To: kory.maincent@bootlin.com Cc: kuba@kernel.org, netdev@vger.kernel.org, glipus@gmail.com, maxime.chevallier@bootlin.com, vladimir.oltean@nxp.com, vadim.fedorenko@linux.dev, richardcochran@gmail.com, gerhard@engleder-embedded.com Subject: [RFC PATCH v4 5/5] Implement ndo_hwtstamp_get/set methods in netdevsim driver Date: Sat, 22 Apr 2023 21:29:08 -0600 Message-Id: <20230423032908.285475-1-glipus@gmail.com> X-Mailer: git-send-email 2.39.2 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 Implementing ndo_hwtstamp_get/set methods in netdevsim driver to use the newly introduced ndo_hwtstamp_get/setmake it respond to SIOCGHWTSTAMP/SIOCSHWTSTAMP IOCTLs. Also adding .get_ts_info ethtool method allowing to monitor HW timestamp configuration values set using SIOCSHWTSTAMP·IOCTL. Suggested-by: Jakub Kicinski Signed-off-by: Maxim Georgiev --- Notes: Changes in V4: - Implemented .get_ts_info·ethtool·method. - Tested the patch using hwstamp_ctl and ethtool: [root@centosvm kernel-net-next]# ethtool -T eni0np1 Time stamping parameters for eni0np1: Capabilities: software-transmit software-receive software-system-clock PTP Hardware Clock: none Hardware Transmit Timestamp Modes: none Hardware Receive Filter Modes: none [root@centosvm kernel-net-next]# hwstamp_ctl -i eni0np1 -t 1 -r 0 current settings: tx_type 0 rx_filter 0 new settings: tx_type 1 rx_filter 0 [root@centosvm kernel-net-next]# ethtool -T eni0np1 Time stamping parameters for eni0np1: Capabilities: software-transmit software-receive software-system-clock PTP Hardware Clock: none Hardware Transmit Timestamp Modes: off Hardware Receive Filter Modes: none [root@centosvm kernel-net-next]# hwstamp_ctl -i eni0np1 -t 1 -r 14 current settings: tx_type 1 rx_filter 0 new settings: tx_type 1 rx_filter 14 [root@centosvm kernel-net-next]# ethtool -T eni0np1 Time stamping parameters for eni0np1: Capabilities: software-transmit software-receive software-system-clock PTP Hardware Clock: none Hardware Transmit Timestamp Modes: off Hardware Receive Filter Modes: all some ptpv1-l4-event --- drivers/net/netdevsim/ethtool.c | 11 +++++++++++ drivers/net/netdevsim/netdev.c | 24 ++++++++++++++++++++++++ drivers/net/netdevsim/netdevsim.h | 1 + 3 files changed, 36 insertions(+) diff --git a/drivers/net/netdevsim/ethtool.c b/drivers/net/netdevsim/ethtool.c index ffd9f84b6644..cbb8e261b759 100644 --- a/drivers/net/netdevsim/ethtool.c +++ b/drivers/net/netdevsim/ethtool.c @@ -140,6 +140,16 @@ nsim_set_fecparam(struct net_device *dev, struct ethtool_fecparam *fecparam) return 0; } +static int nsim_get_ts_info(struct net_device *netdev, + struct ethtool_ts_info *info) +{ + struct netdevsim *ns = netdev_priv(netdev); + + info->tx_types = ns->hw_tstamp_config.tx_type; + info->rx_filters = ns->hw_tstamp_config.rx_filter; + return ethtool_op_get_ts_info(netdev, info); +} + static const struct ethtool_ops nsim_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_ALL_PARAMS, .get_pause_stats = nsim_get_pause_stats, @@ -153,6 +163,7 @@ static const struct ethtool_ops nsim_ethtool_ops = { .set_channels = nsim_set_channels, .get_fecparam = nsim_get_fecparam, .set_fecparam = nsim_set_fecparam, + .get_ts_info = nsim_get_ts_info, }; static void nsim_ethtool_ring_init(struct netdevsim *ns) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 35fa1ca98671..6c29dfa3bb4e 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -238,6 +238,28 @@ nsim_set_features(struct net_device *dev, netdev_features_t features) return 0; } +static int +nsim_hwtstamp_get(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_config, + struct netlink_ext_ack *extack) +{ + struct netdevsim *ns = netdev_priv(dev); + + *kernel_config = ns->hw_tstamp_config; + return 0; +} + +static int +nsim_hwtstamp_set(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_config, + struct netlink_ext_ack *extack) +{ + struct netdevsim *ns = netdev_priv(dev); + + ns->hw_tstamp_config = *kernel_config; + return 0; +} + static const struct net_device_ops nsim_netdev_ops = { .ndo_start_xmit = nsim_start_xmit, .ndo_set_rx_mode = nsim_set_rx_mode, @@ -256,6 +278,8 @@ static const struct net_device_ops nsim_netdev_ops = { .ndo_setup_tc = nsim_setup_tc, .ndo_set_features = nsim_set_features, .ndo_bpf = nsim_bpf, + .ndo_hwtstamp_get = nsim_hwtstamp_get, + .ndo_hwtstamp_set = nsim_hwtstamp_set, }; static const struct net_device_ops nsim_vf_netdev_ops = { diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 7d8ed8d8df5c..e78e88a0baa1 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -102,6 +102,7 @@ struct netdevsim { } udp_ports; struct nsim_ethtool ethtool; + struct kernel_hwtstamp_config hw_tstamp_config; }; struct netdevsim *