From patchwork Tue May 2 04:31:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13228502 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 A97E5C77B73 for ; Tue, 2 May 2023 04:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233273AbjEBEb5 (ORCPT ); Tue, 2 May 2023 00:31:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232790AbjEBEb4 (ORCPT ); Tue, 2 May 2023 00:31:56 -0400 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04FFC273F for ; Mon, 1 May 2023 21:31:55 -0700 (PDT) Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-763ae160c47so274301339f.3 for ; Mon, 01 May 2023 21:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683001914; x=1685593914; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YZiQrbOmYut+4xGG+JMRh4ps4Y3zfa3UhXGIHY+uYOs=; b=bOSXH8EdqtvYGUd6OT+VzGeXpe6znOVUr0p+AFR+vw2SjXMHHmWM3UJX5TnWsDnQhh 352f3WrMZl2MLZY3EMgQUqF0SVtn8V0t2Mo1NO3DJy+R5zK4r0xwF7aUa5ivMpnwXeI0 nAmyO5Bcd1bsNWld9lSMZRMjpZOjiQE9DV7Zo2IE+S2uVZOk8edUteS7lB9sm+nhPCMl pk43Y8Ne4qeUJuNGXOsMHzAHBdbgXQBxmQW4bsvCQfmcueU2+j6wQnBNPzuF06ZypSQ7 4Y7x78kqzuJkWsABgFpiEJ4jDXoNy2p5CESRwu7zlumQYy+KEhaPrjo9GkXhxdclMp2j R1FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683001914; x=1685593914; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YZiQrbOmYut+4xGG+JMRh4ps4Y3zfa3UhXGIHY+uYOs=; b=MIfuksmY80WqItCYd42Y+fPOdP0TJdI9qBDph/1WuCqHDhpziycf22GmAXnZExDeLW UyOcrzJhRFDpMJYh2mvvh2AEwXS3wQMUpNfMXzQBNcTsdygZ5KGDaK40LwlgGLz+oTRL SvOmPpnT42G6KUxyVfFTo9eokc2G1lPaYpMX5oHsEGexIwTh23cVd/BIcIDMbLGuvShV AKyoRJ7avbkenLww2VhWM9AErD744Z+EkMSeEfdm5o1+mvUZfa0mS+mExUiSA7F1Uu93 n0J930iOOGQkUB7JiNeE2XS9PHkkQ0QJOea+Mmyg9YvIG8kpC84cKqVGM4E/tBTazATl aUEw== X-Gm-Message-State: AC+VfDzaP1suoo4hqUSbcha7rHEB6YbiS1d5mv37Oo355i6GztsqRrmc kDHNnhdoKr5criLcwcd6uvY= X-Google-Smtp-Source: ACHHUZ6SG1SA6V0cE1ZGhdr0ej8LSo1btA6W2Kzgeq/i1brWV0hjPX5K70zu/DtFnjuzO+fnPcSw4Q== X-Received: by 2002:a05:6602:22d5:b0:760:debf:6c42 with SMTP id e21-20020a05660222d500b00760debf6c42mr10129034ioe.20.1683001914275; Mon, 01 May 2023 21:31:54 -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 a10-20020a5d980a000000b0076373f90e46sm8239781iol.33.2023.05.01.21.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 21:31:53 -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, liuhangbin@gmail.com Subject: [RFC PATCH net-next v6 1/5] net: Add NDOs for hardware timestamp get/set Date: Mon, 1 May 2023 22:31:46 -0600 Message-Id: <20230502043150.17097-2-glipus@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230502043150.17097-1-glipus@gmail.com> References: <20230502043150.17097-1-glipus@gmail.com> 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 --- Notes: Changes in v6: - The patch title was updated. No code changes. 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 08fbd4622ccf..7160135ca540 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 Tue May 2 04:31: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: 13228503 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 EE9CBC77B73 for ; Tue, 2 May 2023 04:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233401AbjEBEcE (ORCPT ); Tue, 2 May 2023 00:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233286AbjEBEb5 (ORCPT ); Tue, 2 May 2023 00:31:57 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB249273A for ; Mon, 1 May 2023 21:31:55 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-76375982b6aso261956039f.1 for ; Mon, 01 May 2023 21:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683001915; x=1685593915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i4dXJVblBjfmsi29jlImQ6psqGmHx6Xz2r6UEIXvBeI=; b=EbNt4whF2EfO/lIb9eZXgyIGmr4dc+NZT96OIBwQWgQBci72AO8av9jK25vESiR2j0 3YcVaP8/TlPONzoHFwbmRtGnlKQS6kNh1e1MT0wfvsSijhUPWSmrCwUyYNb6I0xASiab bwYSUSWcRICSsX27ZIr1ZmrmKGFaRXIvhGvTp4MENV8/1X/VTIWakoKFp+c82i3OsbUu NoqOPosZOsFF6Sv8p3fpBH+0o2CH9KbgbD+9w+Z6UJuX4n/U574ozJpDbmn7IQlFQa1a imWV/Uh+sDKUMEfxTKgrUTZsdLLfvZXj5ef1fKVMTNWoLgPClhsS5M+VxpWaeJbhyTga IWpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683001915; x=1685593915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i4dXJVblBjfmsi29jlImQ6psqGmHx6Xz2r6UEIXvBeI=; b=Ze8ykRyx0RFOczRlNxPkiBJlAVucvkAvHkLboPmKiVbQnhy/2vhTw5Z+YfC6cd6aeY uoSchH/eL2tIaUpU9Hc6BdDS7AcgAjg+IfNEpYSwz56N/tbiOEIstg3Q6M7Tkv/ZzGSR XBwy+DLIHRn1wp38s2xXBznQfkBqiuYIJqHsaxYIgfEXkPqiabZUXYzuuGT1EzdZ4jCA vx/DtM12Xdo6wApztXkmdnmoqCOixwqbjUjVPoWeBq6K0gMmGbbI6yGfS6bAWW1E7tPs Ssl5bYXXD+ZC6hH0dQLE5kqJUyA9ltOf+Wp7zaXl2hng7HfdC5W5LW3sGqyl9LlakM8v PLJA== X-Gm-Message-State: AC+VfDzCID+VbjgdnqaHxkp0NPqfDQov7EC08crmPLh67NVLbaQTcG0z n1mmJr+MrQKg7fKIpKOBLkIVu8yb8oejlQ== X-Google-Smtp-Source: ACHHUZ6xXKPfucFCAiG9mzSIFt2dQPi5P1FDSuz1ifD9N1ioLHUVx+2/MtafAxtvyt9NIfBGxlI3eQ== X-Received: by 2002:a05:6602:20c8:b0:753:568:358e with SMTP id 8-20020a05660220c800b007530568358emr11832993ioz.20.1683001915158; Mon, 01 May 2023 21:31:55 -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 a10-20020a5d980a000000b0076373f90e46sm8239781iol.33.2023.05.01.21.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 21:31:54 -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, liuhangbin@gmail.com Subject: [RFC PATCH net-next v6 2/5] net: Add ifreq pointer field to kernel_hwtstamp_config structure Date: Mon, 1 May 2023 22:31:47 -0600 Message-Id: <20230502043150.17097-3-glipus@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230502043150.17097-1-glipus@gmail.com> References: <20230502043150.17097-1-glipus@gmail.com> 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 v6: - Patch title was updated. No code changes. Changes in v5: - kernel_hwtstamp_config kdoc is updated with the new field descriptions. 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 | 9 +++++ include/linux/netdevice.h | 6 +++ net/core/dev_ioctl.c | 80 +++++++++++++++++++++++++++++++++++--- 3 files changed, 89 insertions(+), 6 deletions(-) diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h index 7c59824f43f5..91d2738bf0a0 100644 --- a/include/linux/net_tstamp.h +++ b/include/linux/net_tstamp.h @@ -11,6 +11,8 @@ * @flags: see struct hwtstamp_config * @tx_type: see struct hwtstamp_config * @rx_filter: see struct hwtstamp_config + * @ifr: pointer to ifreq structure from the original IOCTL request + * @kernel_flags: possible flags defined by kernel_hwtstamp_flags below * * Prefer using this structure for in-kernel processing of hardware * timestamping configuration, over the inextensible struct hwtstamp_config @@ -20,6 +22,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 = BIT(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 7160135ca540..42e96b12fd21 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3942,6 +3942,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 Tue May 2 04:31:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13228504 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 AE57CC7EE23 for ; Tue, 2 May 2023 04:32:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233390AbjEBEcF (ORCPT ); Tue, 2 May 2023 00:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232790AbjEBEb7 (ORCPT ); Tue, 2 May 2023 00:31:59 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DF4E4215 for ; Mon, 1 May 2023 21:31:57 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-76983b8a1f5so69870639f.0 for ; Mon, 01 May 2023 21:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683001916; x=1685593916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ilatR2KkApwPQ+dLScq/1Zwt9VdF0R2vfroZOKzv62I=; b=co/yAMlE5bPts3Or3JiDdPYEg3mtT7mk2dKdd2BIFH/uLlbCXl/gGDpeqEGOEa8Tx1 3QkumJj5Rt9zIqapqaKOBExtlvwy+ogGuQ5M8wPa4uP0GVspmwH02lDMUhTdsdN3Hvxr +HZLpLkIOIf/N3MrKbEnV8WKuTNd8P98Uj+wGaXO6Vn+hRA7t5QMi1t95Swe8d2/yKK4 0eZUsj1di7bZaT47pMCVAXnYzdK8i4zcjP8m86T4XciR8qo+qyIZ/Y2c+mw/i0I0Qj9E 4ZFouY9pEBSRHuzNJ5pF/HnzBPFZ/WW4maL2TSy5G5I+oiKMF4FBFaBaU88V+P1I0phQ z6pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683001916; x=1685593916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ilatR2KkApwPQ+dLScq/1Zwt9VdF0R2vfroZOKzv62I=; b=TT+3d0htRPJqlbojXx905XSupNAVg1HNvMaZNuPqKxOZL6Bgq36s8gppuf72XzUFQn uQ5n5n0APiIlQ2UpOOK65H69veHA38AolAV/UIKNrXLPfdpt0KA1XxcL8jh58vReaUJt YLVUBTAvfIgz+Zshf/49cCcC9lXcs0RHcRIzFxH9f6KBLoyFr8kQ+Vaxjxk/LYmqTQ7k 3SxIE9c/9Y4MbyyRYbpd/8TLHIgU4JzLuD0daJ76ham3d4nSrV9sLpmThPfs9cuhfKTG CBnQXGLfS2zs1zqLxjXYvRPAs7u4N5DZy9cAr14SHJ8YFrk0c1Ikr6ADpB0lmoyhzIL8 8TDw== X-Gm-Message-State: AC+VfDy8X6g/AHlqPpjHgogYFurIy3xY2TvwJrDlBO3W8eDhm/YlifFY Qzc1ScHuJ+Gb8VjzkuTft0A= X-Google-Smtp-Source: ACHHUZ5eaeQEXrMSydZi1EQEPAo/AvY0YkcjVyh/3yq3ZdrBZXofi8ZWUvxQw0GzOTXhQED1jqXO8Q== X-Received: by 2002:a6b:5c0a:0:b0:760:ec21:a8af with SMTP id z10-20020a6b5c0a000000b00760ec21a8afmr13175972ioh.0.1683001916355; Mon, 01 May 2023 21:31:56 -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 a10-20020a5d980a000000b0076373f90e46sm8239781iol.33.2023.05.01.21.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 21:31:55 -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, liuhangbin@gmail.com Subject: [RFC PATCH net-next v6 3/5] vlan/macvlan: Add ndo_hwtstamp_get/set support to vlan/macvlan code path Date: Mon, 1 May 2023 22:31:48 -0600 Message-Id: <20230502043150.17097-4-glipus@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230502043150.17097-1-glipus@gmail.com> References: <20230502043150.17097-1-glipus@gmail.com> 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 MACVLAN 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 v6: - Patch title was updated. No code changes. Changes in v5: - Re-introduced the net namespace check which was dropped in v4. 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 | 35 +++++++++++++++-------------------- net/8021q/vlan_dev.c | 28 +++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 4a53debf9d7c..58515c9fdf49 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -868,31 +868,25 @@ 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; + return generic_hwtstamp_get_lower(real_dev, cfg, extack); +} - 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; - } +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); - if (!err) - ifr->ifr_ifru = ifrr.ifr_ifru; + if (!net_eq(dev_net(dev), &init_net)) + return -EOPNOTSUPP; - return err; + return generic_hwtstamp_set_lower(real_dev, cfg, extack); } /* @@ -1193,7 +1187,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 +1205,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 870e4935d6e6..66423eaad84d 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -354,6 +354,27 @@ 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; + + if (!net_eq(dev_net(dev), &init_net)) + return -EOPNOTSUPP; + + 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; @@ -365,14 +386,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; @@ -1081,6 +1097,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 Tue May 2 04:31: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: 13228506 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 4140AC77B73 for ; Tue, 2 May 2023 04:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233392AbjEBEcL (ORCPT ); Tue, 2 May 2023 00:32:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233380AbjEBEb7 (ORCPT ); Tue, 2 May 2023 00:31:59 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C8F04483 for ; Mon, 1 May 2023 21:31:58 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-763c3429aa6so261646539f.2 for ; Mon, 01 May 2023 21:31:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683001917; x=1685593917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uXD+xT+8WJbTZw9PPdSypLYGLQQDJ6OoxlPkrP0zNaU=; b=mdkWUgFzw1mjM6S0YXMlQQgh/umlqnFB9x8HAoVYdg2huis+jhdarKLQjfifBBAc3/ x1yT8fA5tvQEajo1OuVbnAbx5zfzeWgqd3OXNmBmP4iwcUhzwtQRjoyIk70xGfPIB7ur /BRmFqzVQFk8LTwuj9X756GXlK2MKNCOJJ5o/lye2OyjbrNzD3RdxlDGBGVVYmcllV63 bIkAdfcMIFffpG5tSEZ0Lq+WJvKSDakcOT2j8xcXacBLSNP+gQJiIpWtpkeP3bdEBQr2 Sn/Fg12kMhUtJP3ow/G27vMlu1jG/pY5oCmaSo7VPIsVQkYnPobRXRfl2AlIE2sgoJuQ 1oVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683001917; x=1685593917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uXD+xT+8WJbTZw9PPdSypLYGLQQDJ6OoxlPkrP0zNaU=; b=MpCPR6IBsP0n+Yz2dh+gu11pTiMY8v2H2+6Kv6TiiuWx2K+sI1IH+nnkHVn/bE2U2Y gzdTmHcmw6XG0sqtNwOjy94Hpj7ZWQWSFR2FsQ26ur+JDMab2kCKuHBldwKTYfAdgfDC A90Epe6yQe1VxikxbmDjc9HlF6gVN3N/UE2Swm+2je6Xyj7e0Pf53o6FBMQeb38wYH5C oGwCrciiY79gVjeQQ9FINRRR/zaYa1n64WkOOguFNTx9cufGz+8zZOjHDeTr+VzPsD7b TJoUcBvtfq9NoAZ6yKe8cFG4C+QwuuPvQp09DHapph1R3OLKvwvFx90fwG7dMedfj4gI rf5A== X-Gm-Message-State: AC+VfDxjoAsS47s219La5SRaRXNR11VTm9658uU0L8QRI2bJ8/ip4YkY 5b6oQ+px5/Jn/QTOCstmu4Y= X-Google-Smtp-Source: ACHHUZ7qqh5xFveMnzp5aHUtyQp4VDEghn1P4X0NXMksfHGRVBamkpSGElG022IsXh2MuHzkuprD1w== X-Received: by 2002:a6b:ed05:0:b0:763:a593:68fc with SMTP id n5-20020a6bed05000000b00763a59368fcmr8965587iog.6.1683001917453; Mon, 01 May 2023 21:31:57 -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 a10-20020a5d980a000000b0076373f90e46sm8239781iol.33.2023.05.01.21.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 21:31:57 -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, liuhangbin@gmail.com Subject: [RFC PATCH net-next v6 4/5] bond: Add ndo_hwtstamp_get/set support to bond driver Date: Mon, 1 May 2023 22:31:49 -0600 Message-Id: <20230502043150.17097-5-glipus@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230502043150.17097-1-glipus@gmail.com> References: <20230502043150.17097-1-glipus@gmail.com> 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 Bonding subsystem falls back to calling ndo_eth_ioctl. Suggested-by: Vladimir Oltean Signed-off-by: Maxim Georgiev --- Notes: Changes in v6: - Patch title was updated. No code changes. --- 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 Tue May 2 04:31:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13228505 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 2E295C77B73 for ; Tue, 2 May 2023 04:32:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233410AbjEBEcH (ORCPT ); Tue, 2 May 2023 00:32:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233384AbjEBEcA (ORCPT ); Tue, 2 May 2023 00:32:00 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ACEE449E for ; Mon, 1 May 2023 21:31:59 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-32a7770f7baso8806065ab.2 for ; Mon, 01 May 2023 21:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683001918; x=1685593918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/oNmPdGypaQsPeyiAflmaKyny/t3TVT2+8BbOja89Xg=; b=NWV0HQlWxDbvfQeYhA/yKsas+6emXes99/x/PNcUHvNeHjSfs41sA2WBZp5U1y/J8e Ah/sfs5lXVDwvoG/k50+auNJqaEeTPRWWvG0CGFchDH6Dd1fUYz3hAzXlt8ORXQN3VHw zDxSCtPbqt+isXT+0Kba88bIYH9Q2gDQZ6gxDHBmA5JJIyphcMVOV1hrIqzvQXZAsMCj Bt7+cFAoRlELc7V5jMEa3PVt3nBmEwgPxudpaw7rfpBNPl1mDEFH4yBK8Z/XmiD5Ys4O v+mYFN7WN2GYHPd0v/feglWOkHsbXsi5/41perdLoWl0FUyo0z0dyrtmVa6HIRnq+vZV USjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683001918; x=1685593918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/oNmPdGypaQsPeyiAflmaKyny/t3TVT2+8BbOja89Xg=; b=X6aVgChDRr0fMYQwTSo827FenwKiplqwvnK2kE9/FrYKbrgBi3KuCQklAUCkBBZI4+ gLp5mWrE8ALrBcruWfiBd46P4bRuLEJvxKIXtzG7pYYCrvbm8N0TrXoCObcgAxYLrgMa 9r/E8mdhu/40rU0akq6xHQeag6SaFE3NDzz3dh2nYoMCC5K73Knc8+XyBKGUVPs+0Qmb JhS6Q6t5WgnBZM6NliJbucswc3qo4iop40TAjNHQM5esezqLOghejoiF+HsyjQiNP2Wz DQIyVtRy/X9fc+tyxZrdyfV+nukDxpetTrZ1o8hfjAO50W1tG1hdYSzaiujdHCxDZCqL AO0g== X-Gm-Message-State: AC+VfDz50bJl1oJoNSXoXmNC6tDaVmn9hZZaazYSs5CCY4xRgNDsqVQk bwRwD8X1UI1G8bIK30XgVQU= X-Google-Smtp-Source: ACHHUZ5ivVTTEXl1lP9Ft7p2TX+gmktfGyBbJdF+jrDgoHX31GYh1UnuiySLqMgFikKsqGpluIJ4nw== X-Received: by 2002:a05:6e02:78a:b0:323:ced:cffe with SMTP id q10-20020a056e02078a00b003230cedcffemr10292039ils.12.1683001918438; Mon, 01 May 2023 21:31:58 -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 a10-20020a5d980a000000b0076373f90e46sm8239781iol.33.2023.05.01.21.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 21:31:58 -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, liuhangbin@gmail.com Subject: [RFC PATCH net-next v6 5/5] netdevsim: Implement ndo_hwtstamp_get/set methods in netdevsim driver Date: Mon, 1 May 2023 22:31:50 -0600 Message-Id: <20230502043150.17097-6-glipus@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230502043150.17097-1-glipus@gmail.com> References: <20230502043150.17097-1-glipus@gmail.com> 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 v6: - Patch title was updated. No code changes. 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 *