From patchwork Wed Apr 5 06:31:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13201168 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 72952C7619A for ; Wed, 5 Apr 2023 06:31:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236999AbjDEGbu (ORCPT ); Wed, 5 Apr 2023 02:31:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229760AbjDEGbt (ORCPT ); Wed, 5 Apr 2023 02:31:49 -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 EB8F430ED for ; Tue, 4 Apr 2023 23:31:47 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id h14so16952137ilj.0 for ; Tue, 04 Apr 2023 23:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680676307; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BLvDTEE/530Yby/LivmClwoLh0lmaDCct+VjUBSu2Js=; b=NDX6bflE+O8K255gE7wg8xDh+Q7NOdZKkz4LcnTnL7cEvUgBHyd4tEJyarwSYK3ZT9 jTX/0DokPg2mmCQ3VVxOh2efFjuDpnvo8tmVOButboe4gBHSclyELPKVG+eh2bRVQnUD ptwBdAEILpih8DbfOCtLAnj3hTHByuJb2tFyHr0sRgPuFCxkBWIPQFk+YYyUYez1r3UX vMOir5Fk2KBYymaphstaFYt73uAHY6jEUGsJIy1+rhe882Nw4FxrQsu2fru+wJfX5N4w l9RpESZ8SJHDnV/EITfatqdxzjrgoAHCFG0GiBp59667nSZ9IMqa9p+7P0RL0Gt4ajnK Vfig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680676307; 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=BLvDTEE/530Yby/LivmClwoLh0lmaDCct+VjUBSu2Js=; b=dQAFXhtdJXEhXt6B5XAYTORG2JZl5JzZp9IF9+ZGgF/7gQfZiRq6NOAFoJOqH1nCYX wgdNGeSZ8vVlfe+04rDpznkEiqLMskcPCIb0j105LcmZ2YjIk1fy4KSoa8kSHX8fvWmE 7Z+jpzzhY8M2X2+vlqbd9sFCEuFm+l2hd54iVb6Q0lRlUR8Dnz0IzGqx9vk7yp7ikkrK ol7JwSC/wen6V2G6OIdu/f+4P5QIgZD93OraF5bfSGlxVcxtkR7Y9L2O7CFviiUzdLVp HY/I9+XjO2+cwT3cuTctV9oTPb+k6Gy/q4zAefUe9Hazs5QIP0EPCAZ/Q6FxJUcztvB+ QmVQ== X-Gm-Message-State: AAQBX9duZ2M0OsFARcEAyNXScyF/2j8EQcIbJki1Nl+QKlndiyHW10Iv qAxTeOqenZTiOk2OzOO5eZk= X-Google-Smtp-Source: AKy350YPoUvzgF4suNHhPlPa5FlClqCHTbp+iMrp3LAv5ciC2ropMyHEfyK+4Q4y7lWq8YDnDP6K4w== X-Received: by 2002:a92:da81:0:b0:326:3001:1f8b with SMTP id u1-20020a92da81000000b0032630011f8bmr3762084iln.19.1680676306840; Tue, 04 Apr 2023 23:31:46 -0700 (PDT) Received: from fedora.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id v14-20020a922e0e000000b00325c0d7a0bcsm3635480ile.72.2023.04.04.23.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:31:46 -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 v3 1/5] Add NDOs for hardware timestamp get/set Date: Wed, 5 Apr 2023 00:31:44 -0600 Message-Id: <20230405063144.36231-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 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 | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h index fd67f3cc0c4b..063260475e77 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_kernel_to_config(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 a740be3bb911..8356002d0ac0 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; @@ -1412,6 +1413,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); @@ -1646,6 +1656,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 6d772837eb3f..736f310a0661 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -254,11 +254,30 @@ 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_kernel_to_config(&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) { + const struct net_device_ops *ops = dev->netdev_ops; struct netdev_notifier_hwtstamp_info info = { .info.dev = dev, }; @@ -288,7 +307,20 @@ 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_kernel_to_config(&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 Wed Apr 5 06:33:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13201169 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 1CFCDC76188 for ; Wed, 5 Apr 2023 06:33:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237024AbjDEGdK (ORCPT ); Wed, 5 Apr 2023 02:33:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236912AbjDEGdJ (ORCPT ); Wed, 5 Apr 2023 02:33:09 -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 83D9F30FF for ; Tue, 4 Apr 2023 23:33:08 -0700 (PDT) Received: by mail-io1-xd2e.google.com with SMTP id d20so4679325ioe.4 for ; Tue, 04 Apr 2023 23:33:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680676388; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DVEvhQ63v2M8qGMNfqrKQ30XTMTVWTaguYlJhV5s4BY=; b=mZ8B1QOEIdhtqQEU3KFDl0C4NSq+9hcnsWKxJS+uUznfpbmwdq8jmW8cON38YzWLPM 70DQKGTzh6VcFAwuRdUdtbzN8iyJnB7kMxePT8A0yBQReOTHdxssJlpqY5VKwUfDFFjk pTrHq3jj1jgVK4qeae3tCEG1655cZy/ftveXRptXIpCUM3pphbcPhdAFzhqonM3UmryZ TlWKKmYY+49omYElACnv0J3k/agjL20GtTZvs49YJO3VpENJcWFzFdDIEu1bE9tqxVlS /qb7EHmWk8qlEpzTvB4DjbjGnIjEbS1hE0wlIDsEA+hz6OvykVBv9UktwpRSj0yj+aOD fKog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680676388; 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=DVEvhQ63v2M8qGMNfqrKQ30XTMTVWTaguYlJhV5s4BY=; b=FGWMVwZ8UYDqSSdX2tWXf2lRndzAo0xxVLAwoQbVj+WMEmmei0txDMLHz5N1cC8LAr fqCmu/Mh+/EUaPGo5/qxI1EtyV9JNKTRCAwzBw4SqJIXNhq1//DUZG/siJRWi5kbKVKS MjGt2qKHOYp/4hIZvlbRm7oHpcCGZOd+t7JyINRq0JfIyN01usxK3Np/z5bydqohC5Oo ZtEk12epsIexSrnyFNaxi4yExw3KmThtATl5tTRufRl67f1A0R+yKi5wLoT7mMcde2zm ojEh3s8PANqcWXL8Da+JO/vvRZbunXKc6RyIvoii+XsGXp4V+oWI2y729a0KdmHDHrPH bVzw== X-Gm-Message-State: AAQBX9dxSAOEgcCioQk+VJSkCO17jM7OOP/ZBgZ39uXpDJBEtro1UOw3 dSfyb1slHu+E+5NBvY5wi+o= X-Google-Smtp-Source: AKy350bzANOKaQJjRP0TUnIOBIAaIqrEchpen6ShXmtFUKF190CUya58VCb1a7tA+dPJ4HyaDVO3sQ== X-Received: by 2002:a6b:ee01:0:b0:74c:8b56:42bb with SMTP id i1-20020a6bee01000000b0074c8b5642bbmr1180347ioh.8.1680676387834; Tue, 04 Apr 2023 23:33:07 -0700 (PDT) Received: from fedora.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id c18-20020a5ea912000000b007594a835232sm3915104iod.13.2023.04.04.23.33.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:33:07 -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 v3 2/5] Add ifreq pointer field to kernel_hwtstamp_config structure Date: Wed, 5 Apr 2023 00:33:06 -0600 Message-Id: <20230405063306.36253-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 --- include/linux/net_tstamp.h | 1 + net/core/dev_ioctl.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h index 063260475e77..bbb41f4fe985 100644 --- a/include/linux/net_tstamp.h +++ b/include/linux/net_tstamp.h @@ -20,6 +20,7 @@ struct kernel_hwtstamp_config { int flags; int tx_type; int rx_filter; + struct ifreq *ifr; }; static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg, diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 736f310a0661..043f4363c98f 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -255,7 +255,7 @@ static int dev_eth_ioctl(struct net_device *dev, static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) { const struct net_device_ops *ops = dev->netdev_ops; - struct kernel_hwtstamp_config kernel_cfg; + struct kernel_hwtstamp_config kernel_cfg = {}; struct hwtstamp_config config; int err; @@ -265,6 +265,7 @@ 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; @@ -281,7 +282,7 @@ static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) struct netdev_notifier_hwtstamp_info info = { .info.dev = dev, }; - struct kernel_hwtstamp_config kernel_cfg; + struct kernel_hwtstamp_config kernel_cfg = {}; struct netlink_ext_ack extack = {}; struct hwtstamp_config cfg; int err; @@ -290,6 +291,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) From patchwork Wed Apr 5 06:33:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13201170 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 5822EC76188 for ; Wed, 5 Apr 2023 06:33:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237061AbjDEGda (ORCPT ); Wed, 5 Apr 2023 02:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236912AbjDEGd2 (ORCPT ); Wed, 5 Apr 2023 02:33:28 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8226130FF for ; Tue, 4 Apr 2023 23:33:25 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id q8so3682829ilo.1 for ; Tue, 04 Apr 2023 23:33:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680676405; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=k2r4QI5U2xToOmDkPtJhf7Jhqw0jIt0t8tP0ZqCmskQ=; b=GSnrsXD+T0b/pGmUJruXFQ/5/adaCmoasKrB12+KWkLtnjyx9JXCT2DqIDns0sQ2Wd lXjW5Q1Ki2mbI+4pp2cGrhgeREldTXExSqapa9Wf7UA+nnxTcpH2tV3JVciSK9gmWCV1 U6rXyQ9ukf/5bDjxoIyRFeQuB4YfCdVGL01AjgdRMVXmK3QYZ5Z7WTRbXwGfkMsTGNWI 3j+A1YSPu26COgCVOuoTm1iRXM5e3OzqLyLlXAzjyQ5JbPLxaqYVPzrqKKo1LaIW53sw EOo3kCCBAyYTVzcwEB6ulRirHae6s6hgQZHq6k3SfIhvVgeIAqTCaJKIU+fkCtfUST9O 1WdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680676405; 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=k2r4QI5U2xToOmDkPtJhf7Jhqw0jIt0t8tP0ZqCmskQ=; b=cHwminN+v2MiRBe6mK2Hie29j1LLJbVxdr9KPSHhpL1y40DSKdncV7y9x/wVyGC2DM rfRGX3q5m8N5E2k0aHvpn2EW2H15dwHANThQ6XyP0JHKW16B9wEYyzVF2ccyDUUbbvcP xBT9MdmNlDX4kdW+vi/euH1WMWb5moRaIw4GdWqA0xGS7kOPkE7j3NbjStYZfgeJUODe 9+jRBLMUlHpNiDdvOyMFobTySpNN3mZQr6w0ZOGPXtIOXb1WN7AbEmbZs63tUpmjVeNv s+lWW6ghlHAF4mt9n8G9ODdEqTCB0qG930PB1sWJigBq96e8XgTADBkfEqs9cyAJDXKY /o8w== X-Gm-Message-State: AAQBX9djgr+PiO5btRgVzLkLNnrc3ZvT0QdrsDCxBCnmakB92oxM7Mgu 4SNQOjrbkeG99x9bBOoKcls= X-Google-Smtp-Source: AKy350ZptuN1F948ptgZ1usiP5xteDxIa+AjMHGz+psh2lpE+hlTKUI6bBWvdHr29wZ9G5cC+LtKtQ== X-Received: by 2002:a92:d385:0:b0:326:6d28:94be with SMTP id o5-20020a92d385000000b003266d2894bemr3797517ilo.12.1680676404782; Tue, 04 Apr 2023 23:33:24 -0700 (PDT) Received: from fedora.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id g3-20020a056e020d0300b003230c7d6a3csm3786671ilj.67.2023.04.04.23.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:33:24 -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 v3 3/5] Add ndo_hwtstamp_get/set support to vlan code path Date: Wed, 5 Apr 2023 00:33:23 -0600 Message-Id: <20230405063323.36270-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 subsystem 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 --- net/8021q/vlan_dev.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 5920544e93e8..66d54c610aa5 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -353,6 +353,44 @@ static int vlan_dev_set_mac_address(struct net_device *dev, void *p) return 0; } +static int vlan_dev_hwtstamp(struct net_device *dev, struct ifreq *ifr, int cmd) +{ + const struct net_device_ops *ops = dev->netdev_ops; + struct kernel_hwtstamp_config kernel_config = {}; + struct hwtstamp_config config; + int err; + + if (!netif_device_present(dev)) + return -ENODEV; + + if ((cmd == SIOCSHWTSTAMP && !ops->ndo_hwtstamp_set) || + (cmd == SIOCGHWTSTAMP && !ops->ndo_hwtstamp_get)) { + if (ops->ndo_eth_ioctl) { + return ops->ndo_eth_ioctl(real_dev, &ifr, cmd); + else + return -EOPNOTSUPP; + } + + kernel_config.ifr = ifr; + if (cmd == SIOCSHWTSTAMP) { + if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) + return -EFAULT; + + hwtstamp_config_to_kernel(&kernel_config, &config); + err = ops->ndo_hwtstamp_set(dev, &kernel_config, NULL); + } else if (cmd == SIOCGHWTSTAMP) { + err = ops->ndo_hwtstamp_get(dev, &kernel_config, NULL); + } + + if (err) + return err; + + hwtstamp_kernel_to_config(&config, &kernel_config); + if (copy_to_user(ifr->ifr_data, &config, sizeof(config))) + return -EFAULT; + return 0; +} + 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; @@ -368,10 +406,12 @@ static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) if (!net_eq(dev_net(dev), dev_net(real_dev))) break; fallthrough; + case SIOCGHWTSTAMP: + err = vlan_dev_hwtstamp(real_dev, &ifrr, cmd); + break; 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; From patchwork Wed Apr 5 06:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13201171 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 58FA9C76188 for ; Wed, 5 Apr 2023 06:33:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236912AbjDEGdg (ORCPT ); Wed, 5 Apr 2023 02:33:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237073AbjDEGdf (ORCPT ); Wed, 5 Apr 2023 02:33:35 -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 E93BB4693 for ; Tue, 4 Apr 2023 23:33:32 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id o12so15440498iow.6 for ; Tue, 04 Apr 2023 23:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680676412; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7TaIEn3IKeNSqnukSFhOIbi52j1qTH9Yw+ZNAcS+2YE=; b=jBUcLX2y9uDGiI8lmM9HmaOHTkPgVFAGxBPZO76rQbkxG/fZtA9jpx3Tr7VoYtdeCJ lS/W4qSTn/U1bgf9PXdfwwCoVJZWEFTT/LX1lVf203ygvAojUvmxH5KP/tVgvjH4y0MU qL8npnqQHW9xXGNr9WDhbb5v7KLo/8dCDYYCJQxJ5RagOQpU52FcHvXSHryNrDeMcyHH uxeSitWksf0lMHKTQmI76U+LVEmYIQxoFzhDIFgcxd5ncb+nl60WhOTx1HxSuDXuonho OehszL4yPZ2yLFFIUC9eNA8fZJ3DgfGeO8+3WIqjubZcSx0zPzjPUmlJlgs+3NHc8OLj CwrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680676412; 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=7TaIEn3IKeNSqnukSFhOIbi52j1qTH9Yw+ZNAcS+2YE=; b=7o2AXPl/d9hR7QUIQ6Pw3FO+kMv9TLZ3t5Ont6glc4jkqQLIN9t3yOTH1VuXXYh+Vo ATD1f+5vq+euIE2TlvGmg5kEbPHOzhjDqIVoYZ92d+xad0EM3U5dzeyYByIYcSHLSBW6 2hdt6O9ALV/V1etVfiDzwGejktZ/bUBdMfY1z66j0kmM0PEQKD6wzL77foGx9GF6UaRR xHyktpkjTOUahEWr2GFmcRFnbKeBZc2dnfOIiKWm2UQ+oOIMTkA/y4poRpqiFj6+ACyw FhLVwOMc3D4zCacfZdjO9Q9pmfVHmpuIv+QlKvL0lPMO/vhv0GvCVE/eUWYjWm1xOWnL qWAQ== X-Gm-Message-State: AAQBX9cfmdGv3I3Z+SgVBHDEdAM613YG5erALckN3Ve9yutEudSEm6H2 zkkdw4xq/sM1jsrY/1YsLxA= X-Google-Smtp-Source: AKy350YUhlZUwspJQ8BmQiBJICi8fMTrONGbbXhZxYtHrH11kBVRSgQlzgEzVw801Fgxgu4wTTXcdQ== X-Received: by 2002:a6b:ce0d:0:b0:74c:c47e:e338 with SMTP id p13-20020a6bce0d000000b0074cc47ee338mr3806484iob.1.1680676412161; Tue, 04 Apr 2023 23:33:32 -0700 (PDT) Received: from fedora.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id ce6-20020a0566381a8600b00374bf3b62a0sm3648562jab.99.2023.04.04.23.33.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:33:31 -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 v3 4/5] Convert netdevsim driver to use ndo_hwtstamp_get/set for hw timestamp requests Date: Wed, 5 Apr 2023 00:33:30 -0600 Message-Id: <20230405063330.36287-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 Changing netdevsim driver to use the newly introduced ndo_hwtstamp_get/set callback functions instead of implementing full-blown SIOCGHWTSTAMP/ SIOCSHWTSTAMP IOCTLs handling logic. Suggested-by: Jakub Kicinski Signed-off-by: Maxim Georgiev --- drivers/net/netdevsim/netdev.c | 24 ++++++++++++++++++++++++ drivers/net/netdevsim/netdevsim.h | 1 + 2 files changed, 25 insertions(+) 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 * From patchwork Wed Apr 5 06:33:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Max Georgiev X-Patchwork-Id: 13201172 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 C2204C7619A for ; Wed, 5 Apr 2023 06:33:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237072AbjDEGdn (ORCPT ); Wed, 5 Apr 2023 02:33:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237073AbjDEGdm (ORCPT ); Wed, 5 Apr 2023 02:33:42 -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 026264693 for ; Tue, 4 Apr 2023 23:33:40 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id n1so17589467ili.10 for ; Tue, 04 Apr 2023 23:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680676419; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=FHkayuJtl6xCLTlAQSI4IXA3UYe1TqqY69yR4IhqOlg=; b=OAIolssD6kfxsXLgf2OZT3oF2SDY+Gji+GdA4NG+0WiLXxk8RozSj038zYZuqRjkdv GSjoeVYKSfQnf4DG3s7PMu7T8m9AVJdDtmEs5o+v16rW+IrGZGZ42WD1skv+/kJtTvNa MtLrVFykZPW3/HUl79w0iE5c/tMe9OHaMWMPVznQN1xmbqIkg//xIPSWS3BL3iYJ/rN9 bSYYm5D1Cmwv45WLAh/CuNYznTjVkLOZ+Ae+yw2QKSEyxVHRKU2Im2kFugcZewz4vEvP JG90+KQM2ZmhxtaDvoQhONN4SITGZswB9gli1fFST0QvHrOME8u2rbslHVjiW77Von+0 8VSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680676419; 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=FHkayuJtl6xCLTlAQSI4IXA3UYe1TqqY69yR4IhqOlg=; b=X2fpyYTvcSTxZR04TSl2hhqWHoaS3IPezkynLDnMMSwBBP+cTXqnnnOJh0RrNEQSJH RSgQuojagw3/ul8fM5e52qS7v4guRcHdGD5O2i57LFMgmi9bV3c3wv4cQ2bNsLnLYhFw K/1VCwgXvq8Fep32urAw5xhJfPbeo+wgGo+7z4zNASTfxmRk7LkbDh2Omt9903ycvdwe NnD8pPa5t6DFsBjd/JmLN7XR+51aY6VxdL0mZIpcuOYYQuPOtK1SlSX9+emeCRY+3CQf Ym77xJCqsoqL06sB5i+j84I7xFVAFt0xoDxMzW15X7YihDPR21yyTzHMowC44BkwruVg Z1Eg== X-Gm-Message-State: AAQBX9dpCHHWHHaG8yUw7Cgufb8YMyYvKDiHO0DeFt9+/g5d3d+8hnXU jB6EG9821ZKj8SBkpYpSnUI= X-Google-Smtp-Source: AKy350YvKpDjFidq7hEvPTey/RL01wr5LT91YGn20eqdVaPV0WaVCvvf2GCMmyIJUB0KbExiQ3aM3w== X-Received: by 2002:a92:6912:0:b0:310:c6f7:c1e9 with SMTP id e18-20020a926912000000b00310c6f7c1e9mr3740697ilc.5.1680676419230; Tue, 04 Apr 2023 23:33:39 -0700 (PDT) Received: from fedora.. (c-73-78-138-46.hsd1.co.comcast.net. [73.78.138.46]) by smtp.gmail.com with ESMTPSA id d62-20020a0285c4000000b004089e0b68fbsm3877107jai.12.2023.04.04.23.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:33:39 -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 v3 5/5] Convert Intel e1000e NIC driver to use ndo_hwtstamp_get/set callbacks Date: Wed, 5 Apr 2023 00:33:38 -0600 Message-Id: <20230405063338.36305-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 converts Intel·e1000e·NIC·driver·to·use the newly introduced ndo_hwtstamp_get/set functions to handle HW timestamp set and query requests instead of implementing SIOCGHWTSTAMP/SIOCSHWTSTAMP IOCTLs handling logic. Suggested-by: Jakub Kicinski Signed-off-by: Maxim Georgiev --- drivers/net/ethernet/intel/e1000e/netdev.c | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c index 6f5c16aebcbf..207e439b949c 100644 --- a/drivers/net/ethernet/intel/e1000e/netdev.c +++ b/drivers/net/ethernet/intel/e1000e/netdev.c @@ -6161,7 +6161,8 @@ static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, /** * e1000e_hwtstamp_set - control hardware time stamping * @netdev: network interface device structure - * @ifr: interface request + * @kernel_config: kernel version of config parameter structure + * @extack: netlink request parameters * * Outgoing time stamping can be enabled and disabled. Play nice and * disable it when requested, although it shouldn't cause any overhead @@ -6174,15 +6175,15 @@ static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, * specified. Matching the kind of event packet is not supported, with the * exception of "all V2 events regardless of level 2 or 4". **/ -static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr) +static int e1000e_hwtstamp_set(struct net_device *netdev, + struct kernel_hwtstamp_config *kernel_config, + struct netlink_ext_ack *extack) { struct e1000_adapter *adapter = netdev_priv(netdev); struct hwtstamp_config config; int ret_val; - if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) - return -EFAULT; - + hwtstamp_kernel_to_config(&config, kernel_config); ret_val = e1000e_config_hwtstamp(adapter, &config); if (ret_val) return ret_val; @@ -6205,16 +6206,18 @@ static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr) break; } - return copy_to_user(ifr->ifr_data, &config, - sizeof(config)) ? -EFAULT : 0; + hwtstamp_config_to_kernel(kernel_config, &config); + return 0; } -static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr) +static int e1000e_hwtstamp_get(struct net_device *netdev, + struct kernel_hwtstamp_config *kernel_config, + struct netlink_ext_ack *extack) { struct e1000_adapter *adapter = netdev_priv(netdev); - return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config, - sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0; + hwtstamp_config_to_kernel(kernel_config, &adapter->hwtstamp_config); + return 0; } static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) @@ -6224,10 +6227,6 @@ static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) case SIOCGMIIREG: case SIOCSMIIREG: return e1000_mii_ioctl(netdev, ifr, cmd); - case SIOCSHWTSTAMP: - return e1000e_hwtstamp_set(netdev, ifr); - case SIOCGHWTSTAMP: - return e1000e_hwtstamp_get(netdev, ifr); default: return -EOPNOTSUPP; } @@ -7365,6 +7364,8 @@ static const struct net_device_ops e1000e_netdev_ops = { .ndo_set_features = e1000_set_features, .ndo_fix_features = e1000_fix_features, .ndo_features_check = passthru_features_check, + .ndo_hwtstamp_get = e1000e_hwtstamp_get, + .ndo_hwtstamp_set = e1000e_hwtstamp_set, }; /**