From patchwork Mon Jul 17 15:26:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315949 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB853253B4 for ; Mon, 17 Jul 2023 15:27:54 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2054.outbound.protection.outlook.com [40.107.7.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77502199A; Mon, 17 Jul 2023 08:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iGYA+ukNocGvDMWY78smGK7pb6DWLzb3MUAJKEjZDadKxcj6iSzK3HqS61nLyGdneOUK4sJUK4v+wl5UEXYMdP4JoPZHdNtIGE/z7sUeTt97zJrO+xnlk261dwcr5MViGOwMm4SoSdmROqPES8fb46CJuw5FHVHGSOrwk+toTXnoGBxBfFn89A8G8/LVeUhNYBYX5a5pXxQdqRQmGQ0xlRn6hX2I3otHimuoBzHxcTPdAoB3qtFH+o13Q1McPmIyUkMf3K+Sozotsit2i65Fvg1gorSxy1OyK0pI0Ksx2lpEJxcEk1Iv7nmiReysFv7I175M0MdTqc2Cw98QDVBSpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eg+A9fEjh0+r0lOpQqoLdNZpxQ6zFhDo6POuUhc0S3c=; b=k3ME6uaxi7CZYZ7NMFswceR03bq9swjgk9djyYdY5WmQ5FBqBgTNNX5FeHw5MpO13o01M7D3BtAuktMZtEABV1h0cf7wwJ3KUc2aDxbUvF4fCx1fjMzVReSwP6xiihXl/F81kK5niIApqGXYUWqVKeaKI1NMy6CK0N83D7s31WO/YJ3AVX3vOeQ/PtAtZ/5x8SJNF3DRGbyM54YyPwG+yAfVOrV3qvW0oCP/biT/0vbH7J7c4QYz6l9cPQkw4UtSkPS40tBXOQBqogbKQSBZgvuPBo6G+INmmWcUcQWRCo1uDbCSlC5RxND+XBB1ioFrMVgb8eplFP7W2dP8+auDAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eg+A9fEjh0+r0lOpQqoLdNZpxQ6zFhDo6POuUhc0S3c=; b=fX6+8xokXiJztKDUDFoJfoYnE1cOAk9ZGu0whYkxl8U03TrPC6idvzd9Yff6n//YoOQpeLYspQdZiRo/HTEKVyD57ohlgP/MggcKGXPt4naWNJDVM1dNXlZCZGfu9I7U+0u4DGwIYa+YzE/lsSgo/ajwaZhOLKEgfTfvdtYJ7ZI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:25 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:25 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 01/12] net: add NDOs for configuring hardware timestamping Date: Mon, 17 Jul 2023 18:26:58 +0300 Message-Id: <20230717152709.574773-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: 4728be3b-995a-4790-5f30-08db86da52a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /Qfk1JDc9bDxkMsclpPhA0H154cBYq7QikJCIX4TbmBeEuasEKJy9OkezKJ2Fcv8St9cjMQ2HcEDFpH8mfXbT/dLykuA3MNXQBmV88RR8S/JMVHuE42DxOVJuZUVTEXEqryaYcmYf4zX5wkjEfQs02cRbAERARb5cuVCUTuGFbDezs1XO28f/G0qEJ2wX4m35I9QCgmLuI5EKyh0aHi62s6zchboWO9sDbBrS/NSonxpYGVtUhBlf5Ufz7sbzDrDJcGwK91T7DI0IvpphzrmdFW4rUje17exTssJOKjtd/MKY/5x/CPUzJKxDJ3VQRDXP7L7gcGNbB8pvV6TtF1IY8h4FNGK7aIMQXP08JhIPoJJsGjY40PMCcTNZH5/erCmaOUMJnQiwYlmtgvcrhOQBYvPb/fhzcYAuakunOukEUIaVCKfPYVdAjIcBskHgQiPFTcOvGo/6L2uqeJqqc4xSh9Y9sL5gRbjayfv3GwCed28YkFdp8B601sCJWHFqoyjUZ9AKrKaJy0B6krNlfLakEhP5+yzGtcVwQqtLdwkarlvkOTryUqoM+ACImUJ6WKY9Wd38UZrKNlEgVQBvj4kbQLXNOQ8HxO8kfeVdGja0HU15EQ6FYlyAS4VwdGY+qAV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ohYdY1r7rUbbX/woGuRow0xfEMtZXXDC78UVz+x2wYxbpHgExP6AgdpMQtZewaRcoQU30SC7CCPc539jUKFywOA4rpMOut0uiFZ+5nP+1sRGytorglqLSac5HzSW1+3PTrxJejQRJxhf5bk19PNBbh+OLJ7g5TgvG2WBJNXA879gMip2qoq2twSmSja1snisq7NXJg0t65l44weAD7IibMq2HbvXJUSwgP81G6j256tHeAbaSiU7sulXDhfFU4kUBHW2DoHL0zYwh8ARjxahs6imR09QOrCKOexladjJ405o8T7h11XbF7h5/a6lwNpQCNOLqCB48veItJ1hThqhwEV+Sv5oVgNl7yBKeqjApVLNrvSgwZI9N0MXOKZuKNHEqoEGlegL02HNiRTzxRhPoASD8Fuv9F19N+crxlOZYP7fAbxOwzaypLsqWLfIhzxHVn1dxFjXgKcBTB9/ROgrumiOrjdoNXtSBsoz9aeEI1EjA7vCWwOJZnFTlFtzCZrdzO9Twla64CdUE/vRRAFe5072NKEGfjPb2VZPsxrw2OcNdKDAr1sZjuMNTg485UXYePv1ffQ3Nicx5HBupjKVFMNL0YCVivqIV4a36ua7CV6L8e0ee5zrdn3JJOnNx1tw5NeV889+P8MqEFFt2z2gE9BgC1fNmt8ToGbyiDXQ+TDDKJX71g3xf2IUKAjciOmpLGYfpNDpxk9YBKUiu65iDlsF7kfColkxIShHK1H4hSb6L0K7w0BIL6J7OLdywQrQhz0jCnXrDrpjJfAOZKBb0CapE0ckjezUKo/LFJXc/OSOZJxoR9Pt9tepkuyV5Lw6GU18g/Wwzls3N3Wp4q2ALkUrKtzvZshsa71vooeMcGlIra552lmBbQUdeLvBivlnrXQl4iNbwuZB+MGIaeGvBrC2effli9aUC3l/z4DsHamEMos4YMqvZxiqAbAxoJ6LAw2lFVIbASgtz5S3WJhG128zMjLaJPSNB7m17TIW9sYyI9G2lc/GrjVYRPomX27awHD1VcuqPqeTTt6ALvOR36nEWPgS1/H2JGWm6+jaOQAwH/ET673CQDqTfVwjQQ9duzrV05RRwXUAwCoc/l2zA+0kqi1dU94rBLJio01Iisyt1SrnvHuvSwEfLUsMay6pmfnpKsTlMbKbXlrAB+x8k21PiC/HLLjX6Wyu9X8B2lGF7lKniHB/5zOfPJ3RCjlwE6sfSNDHJP2MdDqdGV3C9szuCI8YnbBQMOpSabWipzg3eAUQ/dYIyMgcjyf6dI5MrNaXIvKNqHBd5VgWOdMuEzqaas5INLKQJxXCiMpqimbo66ZnyS5JhUY+Hxafv3JRV+cjkDyplNpJg7m9hQSF3L6WizeooxrZnJYbkZA5SVbVU1f6LTrvfREhe5/q++cSy5lxOHyiBLhkAqHbFlf0jQwROupCg9inhwYeZq7l0AwWr1Ujh+gUuDZVsznCXqPI13ydHuqVb8sIY3aisFc5cWh935y8O4q2bSgYlXcnZQntdg3Qb0geo+jPm6bb/zG+0p3ITH+Nedlm7eQZ6jxGR6Df41FfdEhfj82ujsPc/Rr34eRmsc8R2jBlGte6xsuEsZu6sdE7kqbLa8nDz0CZOg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4728be3b-995a-4790-5f30-08db86da52a3 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:25.2486 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VeMSB4LdHuzOTLOQw8Hjpjy3SEVVts3UfIJpTzZ1hEhYJzJli8SiiVAy0cxNvxCbNo5sn6a/HFjoTjDGKtz3XA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Maxim Georgiev Current hardware timestamping API for NICs requires implementing .ndo_eth_ioctl() for SIOCGHWTSTAMP and SIOCSHWTSTAMP. That API has some boilerplate such as request parameter translation between user and kernel address spaces, handling possible translation failures correctly, etc. Since it is the same all across the board, it would be desirable to handle it through generic code. Here we introduce .ndo_hwtstamp_get() and .ndo_hwtstamp_set(), which implement that boilerplate and allow drivers to just act upon requests. Suggested-by: Jakub Kicinski Signed-off-by: Maxim Georgiev Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller Tested-by: Horatiu Vultur --- Changes in v8: - None Changes in v7: - Remove extack from ndo_hwtstamp_get() - Reword commit message 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 | 46 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 2 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 b828c7a75be2..17a442ed683b 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; @@ -1418,6 +1419,16 @@ 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); + * Get the currently configured hardware timestamping parameters for the + * NIC device. + * + * int (*ndo_hwtstamp_set)(struct net_device *dev, + * struct kernel_hwtstamp_config *kernel_config, + * struct netlink_ext_ack *extack); + * Change the hardware timestamping parameters for NIC device. */ struct net_device_ops { int (*ndo_init)(struct net_device *dev); @@ -1652,6 +1663,11 @@ 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); + 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..10c0e173b38b 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -254,11 +254,32 @@ 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 cfg; + int err; + + if (!ops->ndo_hwtstamp_get) + return dev_eth_ioctl(dev, ifr, SIOCGHWTSTAMP); /* legacy */ + + if (!netif_device_present(dev)) + return -ENODEV; + + err = ops->ndo_hwtstamp_get(dev, &kernel_cfg); + 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_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) { + const struct net_device_ops *ops = dev->netdev_ops; struct kernel_hwtstamp_config kernel_cfg; struct netlink_ext_ack extack = {}; struct hwtstamp_config cfg; @@ -280,7 +301,28 @@ 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); /* legacy */ + + if (!netif_device_present(dev)) + return -ENODEV; + + err = ops->ndo_hwtstamp_set(dev, &kernel_cfg, &extack); + if (err) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); + return err; + } + + /* The driver may have modified the configuration, so copy the + * updated version of it back to user space + */ + 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 Mon Jul 17 15:26:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315953 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53ABABE4D for ; Mon, 17 Jul 2023 15:28:03 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2082.outbound.protection.outlook.com [40.107.7.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B37561706; Mon, 17 Jul 2023 08:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IMAMLXZxEEC7kOpk2jigCwSzKZjphsJ7XfU0+8OZYHwINfQSMb/3e1O6YXcav/CeF/sq5+IrskNe3Hp1dzhio0Q6vZ0q+nubtHFohdUTGm3f58sJ+wtHYzm3feBnixd4ITam4Rm9bzQdPhj9gahBbl6C+am5Q0JDmKo51gQX77miHpy6Zsi7ApVwsGYEoXGiYECjNwI7W/QPd2EUZ2GW6EreczPDnoDETY9eGB/2WRFCLXN1Y/PEfkkmoro7i11zlwgS6yZoOSiKMV5y9wR8WZaUy0EodfsuUQWQdCr2BG+/hZEk4trsEjkfbpndka4OSO7EHfnGam9OL+8yIngBQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mg1jOIHnGJBPpcL37o66qFLzpD0P64Qc0aaKn6Ccix8=; b=CKKMUncGw31rfVFsnOxhbfwrm7qT/tJKvGK68chfDMrlpcQSlYHaCJa5v4C8gV4tSKEIwP3Yd1r1VS3FEPl7m1C8mvVXcFnq3jJfMsLMXHKGzzOXWSLvoTxHV2gCN3u7qitM/EcI6mtgBnRk0yYZZXv8Tuwj6mYl3fymaW1VkX/Rod1kwIvZD9aniYkjqSEn7izFhe1sk1iaNLBDEYq2qz8ZWcAMscxOoa699PFgIek/3WKBkmyz+Qn62bz2CdLZ5mZPqLis+zSRdwmbxhPsxkEvnZnm/gf1E9mN9kZJW+4i6fjdYiDxuZVLsSi3ofKUo8cU8n1gaLYoSVhYAZ7CZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mg1jOIHnGJBPpcL37o66qFLzpD0P64Qc0aaKn6Ccix8=; b=PPgqA39hiIOcg29GB42Mkd+YDh7WPzeEvl079C+dGqAG/yd46orjS1EzuvuORRsdcSlcRTRmtwz3YbZk3H2fTSrk1If/2bdV4LJwFWTcvsejwl8K1xLso92iXsGKfi60ChpoZz1pZknUiM/mDES6pvM36R9quyfzYNL0VZJTQSg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:27 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:27 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 02/12] net: add hwtstamping helpers for stackable net devices Date: Mon, 17 Jul 2023 18:26:59 +0300 Message-Id: <20230717152709.574773-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: 152cfac5-63eb-4296-9a37-08db86da53e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GBajpWVH52AkleSFmYQ/L7VKC/drm7qEms8GyBN5ESXKrcPRAZsMzo35xjJBJNaxtRtCHMI2WLpAkmO+rt5hZcOweqsRm7yanDMfwS6S5MFpVe+yEnA6d2YMEz/EDzAVPHLnWSeQmqetP4Imr3wTJaHI9tzaGzdDe00uTBdp/2obLJX7AhMOqmTaGRVIfrHb3IoGs08vGFFF0Wkt6XbGc43Bcon00fC8HYGEhRz2u3BcWmG9E9CZKSX/n9YW+ySo2A9SEO76JDsJj6wG6H5Q+W+NgshPMgTI4hkOJmExcsAr9LMM3EwyF9E5ly2FgeeyzCA26OLjlGudXyo+f93uRDbmxdt5CZ3DPJ4Nq11de6cJ6ljswZwCgtOWFQiny8DwPCRfNwVYByFpeGeoPHRu8EjYThNwCCTlPhmT92/aWG5tKBzSo3TcnoUoBW3DRBMYg8A/cNzu78maVSIfpZ0z/EFcYYuU0ya7a6GIK5VS55vNbTKPTUU4aedjhDBMh4biJFwKGCaJWu2mHceGz2LUfbycCFKPS7XvkCdXMoRl+9GAjSduS3wa8Udcw+2+5f6il91n6Qd8Ol42LI7gRAFn8CqWkPiZJTIP4BE2dCS+ee+CpoTfRAVjgpfwSufM28xV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YTQsUsF2OPax+fTpsmH3OhwC7iKeamqtyuGy9Ixtro6C1u66m6ODa5Hkt4DSD4rZaAvbA9ZcxvIR90/gFvM/7oNKjsW1aDmLTkAv8zeOcvzR/IjyW+yHAxMLBUZgv01Pz/E1wHpWv4HLQWvNJOK8ao/MWnyVbMG1MFGG/r4IM7YpK/jQfEG8BJhDV6l1s3dHNsmiopwvAyoWf5epa5tkLrIoJmDkAR6zj0SW1CGvJecxI+Lw5fZhz4xx3zIrUmYHAf6e2uWzgW+9V3RKlDdli9JLWxezck/WER0Z2bWoOglSOXGvWfJWBEtsbJ7EiPHpXJuvJIZz8a+1SeafDfMz+2C11Xgt7jwK0dP0OK+WJJ8+cXOnlvPbY1B28uzFGoXLWKKqLCTgUsBN4ZfP9kN1J8fABpRylLX4FSw78xxJPr73VPMd4tMtOZEKccY143aFfpv9uBvhmcaHGnaFggo6JMl8nSpQa+XlvXPxEw3Vsv8zReXAgN8uiyCKQFx3jGCkQcl+w7jltuUB8GMHYNPfH8RFZ4IKXMH4WiIPS38Vm7X0S3WPEQl9Vlxnd9ZiPDJs7uVpiLq0GITSgr8HyaKP0peLeVuRtUERFxpaqfoBdnmxw/Ifm3YZB79ADtaPO5pZkwT82kfn0N2yrqJBnkjlDTPf2hGZsdmIO0VTZc3jeLCZFccZbXAbOyT+FRebcRX3W1UyTBDPuxOQmByAZ/VsvN1kguJRMPI8jM+SOgGC8kjrHXi0yGx9OHJoSTpZP/T/aIQuQPvQMXLPwQ7SbH33Yk2mXe6jLPihYNzwOFUVvtwTR70yqPXNYrvIZay75JDFP8LtHm0NrMY1QSCaKF/rL7yDyATvH/4roGKHi+XM2/+RBUZGIHwHii9vKNCjnK+KIqzjHsVVAFsC666eL2si7Ih7zdBBMo6ki4dLQW2bnnOlHJxL/ULljKrXLsBtPa9X52PoN2DErbznrzeBPKwUCNMGbBEad6x2B4Bl24PQYkSDPI+f3C4jXbxNY5b2btiNyDYIVMmyf2YsEn1H6lCmt17mSn0h3ge3T0xvglIOce+HyEYpk3oFiKF6G2x4x1G9Yme7Zv0/B+voYejy9xy94z9Zu0yiOvNozbPf0KBwGG/0Ew/L1WC0sGcw4+UslRIKdpj6L5FbE3NVTxIyKQAMyBPYb0cFahV2HLwXIKu2KGIGGEt9Psdbdv2Svjy2c4+vaD832gQUr1N9FvaSKmwCnjwGpzZDc5A6Feyvsw6Wt4JmlEE7wGw1Fs+keQVQ6BZSjhNHMOk6FVGSgOIlHgN13ZQm0JXH0wyISNx5iZJu3DLIys2kEen3xX4FW+NgJ9vdxlDjAIGN+ZTh49Xnuisb404bQ3+OdroOfubCNHyrdrLUqGr/Vt8/YTqgdPCsaKPI2+ofyzlRaBD/s9ogzzb29qt5w+NWM1UIkj9zeUtDqWZGs+KAcTK1SY/6Hpvzqm0x3y8xBmYw1FybqK4XWMWU7xKGtsLMM5QwoQis1WP2sJFIGO6aYDwJpDRpyZ+AienV3zweDoNao0SSnUlyIH518NtyH5I9f5xCNnFcL8sxQFNdZvbsFAtDc41Gtq9j3HkWPRpuPLpLnje+3/S4lPPYog== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 152cfac5-63eb-4296-9a37-08db86da53e7 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:27.3517 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PHKLlL+bpwufBmaZ4Nty+DpyKgBeQw+nVoUAbjbdo+oP+s0dTCZtivHG2goNc50+I6ibM6n5zuLv8pDxfgFi9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Maxim Georgiev The stackable net devices with hwtstamping support (vlan, macvlan, bonding) only pass the hwtstamping ops to the lower (real) device. These drivers are the first that need to be converted to the new timestamping API, because if they aren't prepared to handle that, then no real device driver cannot be converted to the new API either. After studying what vlan_dev_ioctl(), macvlan_eth_ioctl() and bond_eth_ioctl() have in common, here we propose two generic implementations of ndo_hwtstamp_get() and ndo_hwtstamp_set() which can be called by those 3 drivers, with "dev" being their lower device. These helpers cover both cases, when the lower driver is converted to the new API or unconverted. We need some hacks in case of an unconverted driver, namely to stuff some pointers in struct kernel_hwtstamp_config which shouldn't have been there (since the new API isn't supposed to need it). These will be removed when all drivers will have been converted to the new API. Signed-off-by: Maxim Georgiev Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller --- Changes in v8: - None Changes in v7: - Reword commit message - Convert "int kernel_flags" to "bool copied_to_user" - Minor style fixups, and a refactor of duplicated code into a common generic_hwtstamp_ioctl_lower() 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 | 6 +++ include/linux/netdevice.h | 5 +++ net/core/dev_ioctl.c | 75 ++++++++++++++++++++++++++++++++++---- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h index 7c59824f43f5..03e922814851 100644 --- a/include/linux/net_tstamp.h +++ b/include/linux/net_tstamp.h @@ -11,6 +11,10 @@ * @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, to pass to + * a legacy implementation of a lower driver + * @copied_to_user: request was passed to a legacy implementation which already + * copied the ioctl request back to user space * * Prefer using this structure for in-kernel processing of hardware * timestamping configuration, over the inextensible struct hwtstamp_config @@ -20,6 +24,8 @@ struct kernel_hwtstamp_config { int flags; int tx_type; int rx_filter; + struct ifreq *ifr; + bool copied_to_user; }; 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 17a442ed683b..ca3bcf2257c0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3949,6 +3949,11 @@ 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_get_lower(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_cfg); +int generic_hwtstamp_set_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 10c0e173b38b..d0223ecd6f6f 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -265,14 +265,20 @@ 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); if (err) return err; - hwtstamp_config_from_kernel(&cfg, &kernel_cfg); + /* If the request was resolved through an unconverted driver, omit + * the copy_to_user(), since the implementation has already done that + */ + if (!kernel_cfg.copied_to_user) { + 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; } @@ -280,7 +286,7 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) static int dev_set_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 netlink_ext_ack extack = {}; struct hwtstamp_config cfg; int err; @@ -289,6 +295,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) @@ -317,14 +324,68 @@ static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) /* The driver may have modified the configuration, so copy the * updated version of it back to user space */ - hwtstamp_config_from_kernel(&cfg, &kernel_cfg); + if (!kernel_cfg.copied_to_user) { + 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; +} + +static int generic_hwtstamp_ioctl_lower(struct net_device *dev, int cmd, + struct kernel_hwtstamp_config *kernel_cfg) +{ + struct ifreq ifrr; + int err; + + strscpy_pad(ifrr.ifr_name, dev->name, IFNAMSIZ); + ifrr.ifr_ifru = kernel_cfg->ifr->ifr_ifru; + + err = dev_eth_ioctl(dev, &ifrr, cmd); + if (err) + return err; + + kernel_cfg->ifr->ifr_ifru = ifrr.ifr_ifru; + kernel_cfg->copied_to_user = true; return 0; } +int generic_hwtstamp_get_lower(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_cfg) +{ + const struct net_device_ops *ops = dev->netdev_ops; + + if (!netif_device_present(dev)) + return -ENODEV; + + if (ops->ndo_hwtstamp_get) + return ops->ndo_hwtstamp_get(dev, kernel_cfg); + + /* Legacy path: unconverted lower driver */ + return generic_hwtstamp_ioctl_lower(dev, SIOCGHWTSTAMP, kernel_cfg); +} +EXPORT_SYMBOL(generic_hwtstamp_get_lower); + +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; + + if (!netif_device_present(dev)) + return -ENODEV; + + if (ops->ndo_hwtstamp_set) + return ops->ndo_hwtstamp_set(dev, kernel_cfg, extack); + + /* Legacy path: unconverted lower driver */ + return generic_hwtstamp_ioctl_lower(dev, SIOCSHWTSTAMP, kernel_cfg); +} +EXPORT_SYMBOL(generic_hwtstamp_set_lower); + static int dev_siocbond(struct net_device *dev, struct ifreq *ifr, unsigned int cmd) { From patchwork Mon Jul 17 15:27:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315950 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6234F253C3 for ; Mon, 17 Jul 2023 15:28:00 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2040.outbound.protection.outlook.com [40.107.20.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADA97138; Mon, 17 Jul 2023 08:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q3DKu6Z+BduwwcF2IyySVdBwq/gqUMK9dJaCuGNHcTYu325ut6A7R/Y/xsVxQ7F87mYAfh/Pvjq3UHOyVnx4ae+3SWHoSHo7+m6dRDWAM1h7tzEJ0MUIFhnr97y/B0Sw/7e4jU7Ntah9UkWyhVkkIsTt63s9tVQfkEe2ZMViZWxh7gzVK1ILY4CRUco5+pA9HLDRtyVvkheCUn0Cw9bv6Ititrj2pvRfcTIGLcAT6qL8dI5hTh8GGlrao4OnhU7yvWg9cJqQYlp339WloGnqT+0XAm8u+znRi1oV+r/wKlNsaW84nOKks8rXRpwPf/v0R+Hyi0Ch8m9MUNfhzXRtyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/NUHxNUP+Eu2P3/cmRP9EQdFZZ8zYy0VLlFljFtH4KU=; b=m+BokpRbjE+Pekhb9bePg1gqfIQuMPrrWTvKn1NPBaJNvSe0KdQFOnqaha3zKfHMUGCWvn5p4ghghKF6YIfuygJV20RT9OT8GL5YA8cs2JrvoYOpJrb+LpU1WiPErebiGqR6OuaFF15m7CfleLt42FGwFdRZNHCDuMZL/EdZC4umCBIacMqqS+BMyr15Y3MexFRgKM07C8XV3INpKX7fei5OFOAYCpQ+6SAQxDmNZwo0s1pwo5/2bm6/hDgt2feTCV2Ia5Eu5cTVqq0TbQ53iHYNmr3S8ATQP1BKSqn0AYw2gGPHX45OEc5vbQpKsuIAW3J4KFVNQKnCKPCOL6F+0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/NUHxNUP+Eu2P3/cmRP9EQdFZZ8zYy0VLlFljFtH4KU=; b=agRh1P5oVGmGny+s400O88G14+H8+j5jiWp3pfXs5z1t831nlpWnrryR1RsUfYuuYCkuo7kiqMS/TL+N6E6e5W1ag+falcfxwIIiQwQRKlavbQ7wFrOQRVWn1wd6MZJCe1H6T9H1+KTTxvqS2rIz15pfG/1yd0uhBp9m1T0k88Q= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:29 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:29 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 03/12] net: vlan: convert to ndo_hwtstamp_get() / ndo_hwtstamp_set() Date: Mon, 17 Jul 2023 18:27:00 +0300 Message-Id: <20230717152709.574773-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: dbe0c5ee-01d8-42c0-2585-08db86da551b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +baf49l9hVPwLG5XyRN1lm85E/VWN9jl09fBKkS4J1xtjyLGVz7yhPGp7m7RrWJJi/qGq3mhUlQPqENuk6uXqrLRkRBE/pJ9rfbxtDVv7nA8fhNKAVyBu8pzH+HqhFTLL/TL9S9rxzywN0sPx7i0BxcuMLUmdE3PytJf4QhrovV/FNj+dwbTK1E7bsRbWuW03bFlkwdEOJrM3pc5B69wj66pVjssCj1Q+ymLQ5OePsRDSzWPvJ3ir4/2+EbQCO+x/mUTQKKPHMJtXAA6TSdmFMtvltZTu47y9ojEiSO9vncOUOftWTuPs4i+imFCEoF9zGOoJpSkGsNOquK1Yk6aii7vgQduTUZULMG1pD9wWVYYAk5sitIrFYVyMhi51fma7THCgwXiMIh4hm4opp5MKVU+v1B/2p+anuPSPgAM686hKgeS8Surh/pXWYmxQwTLybsIS0vlfNj06LQf2k1gZj3jNAbH0VexbI/RuXMWxpD271qHLChzwjscwfpxSnQtcum2EiYRh0V85qXp+gHRB1qjTpew3xH6UZyRi1/ceoahvyb9IwQj0kGYzzxhLAxMIuQb97+uzAawOjd0KmCPHtP25dq3l3S901e0ukxX/MUcpkvRx53PFdIiR4uGh4kn X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pyGS5RA275M7L3RbugCHFinorrFHsYwpD8iVCNfwzHAfQnPzcCUwXFKBOqQJa0lIeVVhb0nyFw4ORM+qFUVx5fYqgYoPEdE4+hU45Br8bn3kDcQJ1FxDXJ95+sN1rkWo4ZukYfBgEu9ckhAL2WQ0sBmSRpNKrgc4TBYpttaw+PSlHOAFxAfdvqxrlvmPe58SeV4AxN5CW0KCEK3913kINBeUHJKiiyxbeavACd++MnQWO4lPEtKWKMXxKkPVk50yYUg/ftYQRFQo1oUOixBFVpatx/wwhSWrn8xS/2D6RgBmE54tV/inIqgdaLapGjumOotng+67w5x10HwR10PWYhe/lr+GaiaN0F7wKf21oIj3jRu4vPA/rCVTiUMXCNxQP66pnRfq4d7NYrTwdJKGyrfj2bFmJXz/v0EYdwoSiBxvrEXTezuuvnAG80+lTtbtLh01tLI33/GvQs0Lj+AmrMjigh+m75TN3tdhrl9Z/MCCjvOqJbPucPwVh6lRlTdJYaZ6BZwtymvPRs9L6E72NyKO/Eb8+c1dCPDmvfEFJda9az9hQjT2MzLfoZsEYwhTAuXGIsvo/Ol4rOo4T41ky1koIqkTsee3ScXsBjXOgUX9ZZSSgF5IqG7AkKnFH1CsrKHyTJCsNqORnTFIy5b1F8N+UWPcu3uZJ6nFPtDbikir7saNgC3R3z2xc0NghnZjgmex6nBpXysgoF0cQJgkuLd1eKSjO2cNI/6DqtVqNZsOIMfJ1ZuoBuiBoNDXI2Suj7SmV2A0MFok9F7sK2NPd6x8tIFRdqqdeGXRmvPQt3BUegn2j0Ej+B31tsXXdFtlw9iQ5zXnb3yA4qA9Jx9X5DMOOBNEUKJRhyJaBdp8VR06T43ITNARbNlvt62Rlrl0A8vfAHEoMb/ag+uMZV6ymg8aV+UWU8wAzfY25T49d0YGTrbtcidXi3K7WS7Ach4HhgqnWCEIduF6I+ZmMrRZZaiXBAzmdZ3Nqyc4CRxOe+KdsY0n19kl2umVz52GPAbO5kG5STekm0Vsk125/nX43LgkVXV6k9THxi+ZF0TKBLIzpQS6+YwC1IeXh/gcv6irr3/ttRkjRyzG5TOMZGFOrkTXGW6sdfgsCvAtwEirKMDtjvLUPf3ekqnlwUCk0yAlj396cqMwyt/AohLQthxVoUWdDHwR4Frqv9MJnsnOLIf6rYOK+X29M03MGcLAlxJUAyUYFPphmEdme9n2O44ZmI2efCvTiDJDpczxZuFY8ZJXX71loyjDX9Byp/VjbYUEmy0lku+1586Pe03C9Zd/KoCIAGHGbwtt2xFyIdOaEMeFcHasL+252WhcCkBEVIHBhXhm554XftRQjIF2v+pvE3vnsM8shC+cUPGzPJZbr+bKNoLb66YRQ6FafXSoXXjmmSEInZhaU2jG5Jf4lkX5NgAl7NPKRZ+0Y/V3Mbw5bHHnTqX7S4eir22L+3K+dxnLIc15NU0tzaHXbfbNhwVvGVzUWq45uFw6R5EmOfUB7/nEYWUrQiNSAnIB5E6nitC7J8h3Udaor7/a8fs2G7sNRi9fkeaQE/H3QR839HznU5JL/Ebw5Dh51W2ru6bx2QzwraFY2GvGq9lNDZP52oRBeg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: dbe0c5ee-01d8-42c0-2585-08db86da551b X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:29.4207 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TFSKaotM+6dizo1KJcaFtwIZSL8bqgYgj0LF4hwu+rQW8bpOGIy1AlxQLwZMCJMFqYqfIwvJf3UhekuIcOCzGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Maxim Georgiev 8021q is one of the stackable net devices which pass the hardware timestamping ops to the real device through ndo_eth_ioctl(). This prevents converting any device driver to the new hwtimestamping API without regressions. Remove that limitation in the vlan driver by using the newly introduced helpers for timestamping through lower devices, that handle both the new and the old driver API. Signed-off-by: Maxim Georgiev Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller --- Changes in v8: - None. Changes in v7: - Split vlan and macvlan to separate patches - Reword commit message 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. - Apply the same changes to macvlan driver. net/8021q/vlan_dev.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index b90781b9ece6..2a7f1b15714a 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -354,6 +354,26 @@ 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 net_device *real_dev = vlan_dev_priv(dev)->real_dev; + + return generic_hwtstamp_get_lower(real_dev, cfg); +} + +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), dev_net(real_dev))) + 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 +385,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 +1096,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 Mon Jul 17 15:27:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315952 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7249DBE50 for ; Mon, 17 Jul 2023 15:28:03 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2054.outbound.protection.outlook.com [40.107.7.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C628B107; Mon, 17 Jul 2023 08:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W/AisSpow/4fx6BZ7Jc5p/6SqnDHf251C1LaZLXO49S1y6tcMVrfa3POmwVp9X/H7DEx3S4h7sXOtuL6VF4WUFbaU9wYkZg6BHLAYWbL9QTS5gPHmcGvK9jhPc2JPixHcTRUrgdZW/8x8rT4i//etjgptUgQVcMYbA8YcngorZo0fEoKYMjNxfp2DGYqBTqCveIuEnTETaMry448AaMRFtiS6VXvUN23ojHcOZ/0v/ZZgDQ9KG+LE8RR/37c/NXV/DFzWIHU2EPSu+SBwwGnBkQ5pwLnfZmWy4CFcYPtG4WWGsjQroxGNk5K1iybi4iZv0UfHnCRyrbYF10zbp7RaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OWwXS83P2zx4yIhHQw8PDkfdP1vWtRYXe3Yz4X1NgAk=; b=jurowIO9tdeS/4PhQzgUxCM4OGOktRHIHENLAr9655MC2s7I3AKBshqyx8FU0DltaLVp849b3SyaBYLoqkMspnLzq34fAHPhiqvu4xHL83UX8BGZtQDFiakpXq3wWf5RytAh6mnHUFXkhHahW/+/fzs9ZWOtnC9ZUmdy0+x9y2bTqpObSKzO2kvY/KgPcymyWpxshqM8pjV/gS0HYBcZNA1TTtaIVXw45S9WIarp049A4x/6KhYmaEtwZZ/5wjfRh08HcHezjwv/JdJsno+QTFIrJzK1ha6zhxXXiHmEgmJdI87iLWI5S9rghsZ8p+QVR4OGzC15U4Yl57FkDQVvNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OWwXS83P2zx4yIhHQw8PDkfdP1vWtRYXe3Yz4X1NgAk=; b=kpvN9DYW5l7HUrwNIU8ACL4mKJsIZMKGvTF9NJ0Pvs72zUlod6etsVA3QdV67/dwoOMsUQnJ6C2/NLHUcNuxZn8BFkl5z9a4olxXTwA5zPezMvrOBVX/sloC4/77fKlugoGDEHbC22RWpfAfM9IwAVRRD+/qGZMyhVN5W6iLkjA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:31 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:31 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 04/12] net: macvlan: convert to ndo_hwtstamp_get() / ndo_hwtstamp_set() Date: Mon, 17 Jul 2023 18:27:01 +0300 Message-Id: <20230717152709.574773-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: 5dd41a24-c833-4e81-9c76-08db86da565a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A0EKb3cMTvGRF0UDsQaD5egdEYv3NqgXPIjIYboQj4e1rhQ5LlZ+dnv3K8R8YDCBB1TZixY0BUgYUNVhdSWAaK0j7c4CiSxNeyVPVdOIuO0cbu8+vfGaBvylJZrSbtN4O81XIZK0kBoj19sB8DeEc27hWy9vNnjQH/Ew/jqij0GXygYGJEXqYnfOCY0tI1VIfTu+lWAKW2TRAoKRNhRbQ1+t5g9Umxyj1erRBBW8ejdp/LytcgHIbW7r+ln6pZeDzJfzxBvel2ydw/Dr2JqmH2aiWD5fKcxAeRdtSFGA2yKbnzbSPQk6hDMFm5J63dOh8u/0jN/5HCjuIve6RuViRoxcOaTZuuGU8qa0Vi88Orc1uZK9ZT7XXgfDa6/ko7GN7d1mbg+onXOL5djjAQHsr912mjjIMD2VzWuExxDd2aQoR/ZGVIHE5JKxHE3lzfbbV6ar3B+lSIVYEA7SMyMgStj/TL2bkgaTEVqAl8D7LCYPQ3n+3A1us6p7+NHJLoKaB7C/HYKMLLzCjUxkhDkbIvNNmS9aVErC0ih7RegIhM8tzavJ5Ez7qVO5rTAJfhx7Jp7wz6x/eQnJbCzlAaruEVCNJp4Me4yOMf3enUwcydA++J0sXiZW4fyK40V35FUQ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VgxkbN96rUVOdHsOc5SeKXjnI+UKEe7cOnr9DKctYrkHK38dxrSXZ6xe85KJGoAl65O9RNoeVCESXz6QOHFPX5h1905sdXDXhQGq6kJPw4KxXT7hpuGZ/Jo4FzHN470ol9cPj4Dn3ud9i9+NgbilpEhwWv84puP6kTlB3zc/F7Z9Aj9lWDAejrxVgrOofuHnTw8ALbXKds/UeZfb1Zag+zgXeJY0YZ8jVd3Nmv/9AIMiLVcXShePLEm7WmPHHrnIpkagU47DwnS/2w+7TrxEN2kW/KHOwHG+djNXlmxaTgn7/FhVansSm0LrXqK7nFewe9lIbGVqJNlOIST44TL3W7vkELzK3VL9YZcOUAWMSSIk8X3Dto+VO+MrVeC7tYNJOXypS83ilKqLj8fUZVA/G11UuMk16qY0vutX0LhnRgEaHw/Zac5cnKAMeCptPz4Vfs+df+t1Ga7Y+7/0ExvF7xqzF/A76JCTXd40YdCETHqIgwNaQv2HC7Jh3uHKHEgZ96hplpOkJnbpPjzvXe32etmiytdrEgEH3QgvfByVi/Ejosz++fVNdqXCVntECxW3rNc610UnrIIbz3B5EF5kEasm3wGCMShPfQsi5ikTOq/4CzzyTh4GRvupdGPIB2DYvDYpOSdpmjDvV+ISOUrl0WjemSVKQifs2/VdfrBPJDSv7UT4GmQe8kAvk0WBGNLiJHMBiH6M3d0orPBE1Uekiz29pzSo9U0CC8zOoV/IPsdBHEi4byOxFz7pXPw/tn+7bqjcmrGiWABdVMSZRGGRExkS7PDgSrVsPT4iEthkXJHwYJzuOvgu4sWS2C7cHQJBS3RZxGX32pNk3Ljj//Sbvg5Zw8L6wDYHLQqkFEty736rjFmD0JSpWlgf1PRyYLbCmzl5fJ+wsUnDbCVPOZSZPrhjIakEEa++Nwvqm8uXK/l/hDA0aIK51S/nJVX+tqBzvHCrf4qd9mr8EnPk3503s3+/QEOZy4a9WutqpVadey2AJv6tEW3LFyhWtlB5OkVBwEzeVlMuloQ8yraOsy6W1c+Om52bFsB5e2C7pZE51Yjqs5M9k3qPsmaPTV//YcsWP2ike9PT3yhheF6VtGO9IAQyIve76n/EHF0QvHTW1IRccbGwvqjEn8Wg09uzw8bB+zkCR0zM+RGeWq7FwIqlzr+IcXINmekHbkj0ghWFfDCPVUVzkbvLHKIdymfd42mv8i6BdSstz7AIb70qwzAYNN4UYASK/vpuogfFMiPOqnNOqNK6s9Y9ZIQ8YalWXLHkw7XYBy6Z6yhx7qsHV3NpDXHuDlYOdJZzg9goCJiD0j2jXs/gJJDXZNS3319hTfBn5XJgbiQX2v/ae/9nVArqU4HfjNE7j5LDEL+cTTZ69IaAiypC5+bFlIu2ME9Ro2ov1C7ou3Ir080sUfBfn6qLnu3AAbOSvDko8yC9DkLQ2W2hbeVNrhK5Yg39yaTPrQ8vsqrv+4b06ObITBNVvPVTweSA/9ncywoq4ZV2MfMuZ/v00RmIGvD4RUi5jc3SQqkraTePIP/0d+gVFSrMtL/DuCftBRRS73BeJR+CVj4R7uDObb1eH0yNSFh5hFMa9nZkRU4y05aD3hA2TWlm2HLXcQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5dd41a24-c833-4e81-9c76-08db86da565a X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:31.5134 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DC7AY6hNaaYCOK2bAHXq9MUFVOAIS1XBljCxET//10uF9t2wxDuqG+SdPIr+2Ki03WvMyS1zFeLAAuSKhGjCbw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Maxim Georgiev macvlan is one of the stackable net devices which pass the hardware timestamping ops to the real device through ndo_eth_ioctl(). This prevents converting any device driver to the new hwtimestamping API without regressions. Remove that limitation in macvlan by using the newly introduced helpers for timestamping through lower devices, that handle both the new and the old driver API. macvlan only implements ndo_eth_ioctl() for these 2 operations, so delete that method. Signed-off-by: Maxim Georgiev Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller --- Changes in v8: - None. Changes in v7: - Split vlan and macvlan to separate patches - Reword commit message 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. - Apply the same changes to macvlan driver. drivers/net/macvlan.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 4a53debf9d7c..01acb57aa40c 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -868,31 +868,24 @@ 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 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); +} - 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 +1186,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 +1204,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) From patchwork Mon Jul 17 15:27:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315954 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE4D8BE4D for ; Mon, 17 Jul 2023 15:28:06 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2040.outbound.protection.outlook.com [40.107.20.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 570CE10DF; Mon, 17 Jul 2023 08:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N3phavZv7qyw8VfShr+tLn4VUctxbMcW5VaRwDEYUVWKveov17ofBBkS7lCAVSiZQijY98x13kVP12rMZ6QlV6fLRFCaHObeSLwvcI2wkT07lYMxctXGSDEu8ZTozoLqlgaa558Tzgs5Zca68ayxaQE+bpZXIWg2IG0KhExSWK7tDjcaN1cLMgRz7/gOcyYuqkrqnnXqwc2luFfBK63y5yhs0lCKBhVsNQZ8/FA+wt0SHO3wjUTywIOTU6jJzFLIpBVWi1inY2CYDIS9AvuMl6TZsxAosswVK5bufC4stnOJwelrc2NZLRFcgOoxZTJmtOeuwAcI73nKaEqWfjsInA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BC0nTl8AHj9lufMrAhgkWMIdvAxRAnDTbH8XIbBzuMc=; b=d9gm5vLtKkFMkUoCnTMglITk0UEV4dRZ43/+zfI3FojtJbd0z4zo487DT/cHD+BXhIzAI16hxZwKO+vNN+YuktNjSSr1SR1fjsFp0N11h85f5pByFB4vWhnjdNlqkk06ZnA8gLoufQjyQVO7u/ZSsa4L+7EhZyWLzKjCKAzMj6Fa5ifmpjCpCYxrKWXjrzzg2GMaFLUJdx0MLiaU4/z7LOFU2mcIS9z52mAJ389QqnbwelE/IhDmo8/uZEbXd5qRMO0UdXGGHLqtRAPXngXBGpFk88bXFbtpsLYkb0J2Jlgx8JvfNVdCE9+FdQ7k++jV0nL9qEBYFRoKr1KIOGV7Yw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BC0nTl8AHj9lufMrAhgkWMIdvAxRAnDTbH8XIbBzuMc=; b=lET/6FfnYZXPFGyr428cRQNGkw9p3FiuR2/MolO+5cjqLjigs+/1sRyxzVkOlCXH/G6TCa1qtJ6QPEf9gVZg5O4lqXVc8gyCMPL5NlAzEOHsBNDY115tQyMIz7Jp47T9TPYxo2vnzbs6yR/bGHe3jjrhWJ2Chd0tIYg2XLgrsc4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:33 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:33 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 05/12] net: bonding: convert to ndo_hwtstamp_get() / ndo_hwtstamp_set() Date: Mon, 17 Jul 2023 18:27:02 +0300 Message-Id: <20230717152709.574773-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: b73d49b3-1fb6-47d9-b124-08db86da5797 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SjyFXwFL8NpWLSDzCtuQltPPgt81QDld9e8chkxivG+sD/dP6NE9YTD16ipEEGoTDgG+mPILCC47XcIQwxjhDlidZH04a9Ps09Birblr7aT0WVC/iz9h+09Qr+w7lHXkcUH295LlzdRlila7w1TGeQrqQr5Ip8Bvfv1qkBfgBEG2uMKoZ0C+UgS5Goibyi/SX0fK8yvTkD6PfmvVevUgS0M1W7Pra0eiwxWouR7kLWbNmUXt36b1O9epPiTd2lYn1fJXEC4EQOQJBuJYAuV30IYkaCruK6PdyX27zgovOH58yhFEzom/qn6oIDA6cCDc8KrldeS0Rd6YipIWPZZnIkq54lILWye1/ZFSw8ZD/y+hkd3rQ1QtPNSJEk5Lnmcb57OD1wxnmFY1FTK6jSzTbdEIEWUDAhGIsEaPaqmGEbQKPBGZ0j7zfh0/IX21B5o9aOrq+v+kmqPvyHS78IOP0ApblTqI7X9ak55Zql0O8Q8J7WPztWsG4yP14kUBknf8xpotkag0O6dH3SqmVimXSKtkz6UrzSeIcojMlZbcD7fkgVKBS3hN5eQ8MZo02wZwbGF6Vq8fCt002PwgBXeuJqPl8naXL707spJMvY9golNvit+ajAWQYHX0UaiTj3H/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PiEEIjZ929Szfc51CioV/4fsPcciz/nzJef0RuFacz9GTWUBw85AfI+mnWPXcqEKWGlKyfoZVFEOrnKoRyLT1T1U8J7d6TEcU03fMnO5jlddFIWpd4WRKg1aYtundhn83e4E0780MU5LHflesrfOqn3VJgOXG135TNudtnAm/eGT2FhjGlMi5oX5IN5CRcp9sCtR0w/DxbP2ADL2LNBCf0yDbCtQuasAdfwyUZUDl0eUr9Om17lWzZca5c4Ff5i5R7DbSgRH8zBVDti8nhYCfs7tJCE5QD4BJNpTWl2g6LFglLoVKYPnvD7ejM/SaGCuQ2qIQBctF6przoCloPgmvKTBkTBPDvetaK3RWcJyOxOW3j6uiy4jyV1Yg6hJ8n+KtWSzq6qZDhZI+L+PcFmdnSJSpKn4A+oehwK9QvPFeO0Tbf08KG0OwfghRdUfxgDPY8GzeLvA4M2AN/OXCNcXMEcIKnhcpUnji/ezlTVjkpxBjztaQAoN7fYOXhWQDQqfmm1It7p8quIbnno3hJnOGdggfOyae+jsNXAx/9+VYxpZNz6Xz23ON3hhYAUAHrXF0cwD/xxUc4nUrj1KDM4av9SNCKqciCZnR9Eah/qbEpZUy2bIk20soTgAkfTMTpghFxYFZbIVzItVAKC8PpDfIkriOOsxA+/BNc2Jriqc1WhWL18umT1FaJF0gh4zdHEbREa80l7hLoliOlbMZdI4i8cPyATHD90Qf/brs23zeoFQu9HBe0PgqiQkbSymtrJDUHinZJBIPacxGWDsz0rYXdxcTCnNDgsDVYKueSvtu7pk+yv2SKGh5sQX8p3YoiiaPcnglyUSybq/2fYIkEVnnybiMAoHsgZsLnAKQ/3hIajJfqZsfcsozDbTCYpBAj5Ff4IAdLVWfWFHkgx04jwSQ6d1P1VhNSVly3DnrMujK7Nggr5sznlLhItgDAlSsEwitG8hlPex14CClGRdqRhEZ3GFsBuDQYyfZcFIowLXCzftxudHjRLR6iGvuxzXJqkY35ReIYI8guzzmYrSERtM8eYvREwfr0LhtUYnL8Ve7e2ovCr9soy9b97wSTJAm1zsnQ5R1IPypTJIDv7LqtmOuBnok/o12x+wU0jjZTmDB/f0Oa/DpWe9O07USkYbzK4bOzjuId/lNFZpLgsoGGG+zX+xGjNazcg3k03UhvmXAYLAEShZTLbMp6nyBPC69JmZumpH33bZ3i/mBWuo2nRaBXWGwssdWYEI9uXquigyY+iBOo9vIzmhcPhuj+csjSR9X5/zisDpjKR5zoniu1N5idsgJRe7HwfT+y3gGOwpw2HfkZChKGFg7vVK2qu91M11Lq9mRPlhCLMxRxoGXjCbLkXhM6qmxBdsbnvVwoM6lSP+XMzOT/wyzQPtImgX1zH5f+iAYoobRM4MNE2HNMfL5BmwyQ6gwzCXKKxXp1e91Wl8HItKnQaz2iSre7BOEG3KLf3uRvQsqmTgg6zZOq9RSkh6oTbMKNHomvgY83OnKx7PCVmhfulRVpkQmDtNc0Jkro4QYFJdoSNDS6JoIi+C29lOexf7YxwuCpZawM1dhON4fOyfqPiZCtYIZVXNFtA3CpMqOaxVb1eDgW8zfJhPCw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b73d49b3-1fb6-47d9-b124-08db86da5797 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:33.5571 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SP+5rQY5WgSp26YhCsDYotR1s+S5ubDg5VkDk/69L1n1iKSh8iQIv0gEXQ41JNdYudQR7XoVrNSDClWWoEvY4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Maxim Georgiev bonding is one of the stackable net devices which pass the hardware timestamping ops to the real device through ndo_eth_ioctl(). This prevents converting any device driver to the new hwtimestamping API without regressions. Remove that limitation in bonding by using the newly introduced helpers for timestamping through lower devices, that handle both the new and the old driver API. Signed-off-by: Maxim Georgiev Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller --- Changes in v8: - None. Changes in v7: - Use copied_to_user instead of KERNEL_HWTSTAMP_FLAG_IFR_RESULT - Reword commit message Changes in v6: - Patch title was updated. No code changes. drivers/net/bonding/bond_main.c | 105 ++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 40 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 7a0f25301f7e..d591992e3eda 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -4441,11 +4441,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); @@ -4472,44 +4467,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) @@ -5683,6 +5645,67 @@ static u32 bond_mode_bcast_speed(struct slave *slave, u32 speed) return speed; } +/* Set the BOND_PHC_INDEX flag to notify user space */ +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->copied_to_user) { + /* Lower device has a legacy implementation */ + 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 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); + if (err) + return err; + + return bond_set_phc_index_flag(cfg); +} + +static int bond_hwtstamp_set(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; + + if (!(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, cfg, extack); + if (err) + return err; + + return bond_set_phc_index_flag(cfg); +} + static int bond_ethtool_get_link_ksettings(struct net_device *bond_dev, struct ethtool_link_ksettings *cmd) { @@ -5831,6 +5854,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 Mon Jul 17 15:27:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315956 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28A46C129 for ; Mon, 17 Jul 2023 15:28:08 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2082.outbound.protection.outlook.com [40.107.7.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 511DB1723; Mon, 17 Jul 2023 08:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n2ujHbdLyh/N3FWAP454bZ21cbFBQEghfZxx3YvgTxUXkOKwEicSvBnPdMV8MYRBwJxjA4fwUVV4AiK9EW+CuyzJeUDKIxhQ6zPB5BT3DWe4/IHC5F82VJwXYPp9NspdN1B0b7xXNrkwpIiqLLok2AyJ1t3JJzX8FZ2jcc/APyPdetADlT6D4rC8CnvwWLXKbCUBDlr2+pq8fGyG4xak/Y2v1wkDX1k6RVKgskz6sWjdLqDQfaeJvs8Nuj1QUIZQwj3zh5RK1HKY4KgXKpHvVfc7S95rqtL2YHFRAHwTidSQwEWq0CxW7/iTygsBKkmGwO+bTb21rw2MnAe5TotuPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vf3LGB//DyDswjAN7ULL/qkbov8wZz/8LILpVHSu5No=; b=dRHylKNTyuaNVgTWEbAekn77xRhZYYtlvj/RgusjycRw7SoSoE3PLgb8OsM+fYv18mdDITdTr7QSeK932+0gP9c6an/gdSYjeDwjztQP2xvwiX9b6+Jy/sYN72HpC3KQFcboqqf2+UgFtLfK2T64+FL5kAI/ChHelrHgaM5PicnocbMMRtNwI35dLFu+n+t+aSszsK938gNzJAuHfeYKrUoZFn0Bpn4ijqrTSe6F1m4zx38MUTG7bisDyvaDLSgLO2+gA6Qbtn1JMhnPpgg5V7KcQX7/rgw9CBScME6Ct0Q/cjRfl/BvGL8DMe09xPTjctMYHktyg84ot8AcUeHqcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vf3LGB//DyDswjAN7ULL/qkbov8wZz/8LILpVHSu5No=; b=ccJMkTnUpaMymeHqWagh4KcDXaWt/qiqriPePP2+TYseZcbi0rLCxK7A1vY4D3zDAtjj7+/6+ozDBNQAngdRcffSujBiOo/i8abRTiu7TdlJbTxRGP7l5an02tsRJnqJNTPotie39HyAC9hLph4n6Lsg8t4TqsnW0ydMK2XgMmU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:35 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:35 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 06/12] net: fec: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set() Date: Mon, 17 Jul 2023 18:27:03 +0300 Message-Id: <20230717152709.574773-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: 84679f55-7588-4837-c5be-08db86da58d4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qcMI+Eo45zZ6BAmmUxWWuMOaCVEHmlaMvmpxvuFlQK2mMEMaGjtrz77t0BnYHF5qQAzybAeMvb29FjFsC7FAmxTYR3ok7Qp+rVo0c/XmzMfJAOtoB8L/XK+Dz3ldh4pAfdIEzn8Doc67TRtS5gCeBLrsIuWpf2Gu0brE34pw3SeDTfq5smBTSLf2L3vIYZhc6+vuSLWMMb7Y7vyODoSBiijMa0ugJH3sSqINyH18Jcelrf0M60RCTk5M5mzW38/O80WrzMi4KOYQ6nhlcp1+hqczG7Qp7iGxUaunkm9QdMkb4KXLAD5zTw4d5oHCl97Msac15vsdg6HQGqB7PaTrCiiaL9nybWr7VeUe5LmPuLkO+a8m5p1j4BcH2CjTCqnsBssEdknD0CNATnLCENbs6jTljLkgarULA0baNF8b+kG5BsPl04LWKbdUEaVxlhwJhwNWIUwSVpFBsSxJyAaCokCuQzKLD/uaI2tiDVpCQeoOkfH2yuZqQ34BkypFoaVBtpl+HuDau2WxbxfYLUlP8xN5SfSYeBd02Phxy6tmG9Sp3AGZhQlLtz2vYzFwiEbVNzPdEKfGYsRG31eyLwpepFfnaBZ6PCibEcdMEifBUsUxx+/Oz3wDVkF/m90FyDHm X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ngKcg8eXkDc0QKCwzubSDJrV1neSMgEyMRSrWCk+L6erCggaSyq/OqfP48LJ6rdZURtmAPrUmvR5zSNoPiPJqzcfhLnM6HBvL013Mi5I3wuhNLF1MZst9HWu/q7jMJBGkCH6cgwd9cPaoDQTsUd+SWc6O0HjFyd4Eemb7q9wcupckTbP8akVPDrHfxRrK/kPi8SFiSVYCbW3c4f3xr0RHsSnufTPqa+pQEVsGvzZx7p3PzS9JWsabufe+Zc4uUnD79dgHSiGf6WXXZTNj8gY9YNPWIAVwcSHrrtqw/NOHizCRW4aFLZ3KaiRi5ZUBFx9/F6/uSZFuI6pfHlhFtmwFqmqJmRWRR5gdRGXiFmTDvvofYk1KQXL3LhMx2qGJGTUlND+cf1kFrSGnDJowKgdfM70kkMNdmCQPCj1W0uHest645d8s0EFYgl7l0niiLfRo+Q9+MlqUC+76X08EyImYlKBitIHanaZujs7BYkld8I+mvzBfJsA3tojahwQnVcXWvxmZ/OKAHs3k5MDuaKViAyFiZcwj/UdWx9nUa22mBpOD6XAmZA265CdKy9wskYEdUOrWv+v0L7ODRm5QPBdt0JCxkIy0eTQJvCJJbhb8fo1gJ2Dmy4YKBGxW01u4DX0YE+SULW3fqeJV5gK1dgeSGkqw6woML6LtpC6Ixrkxegkk7F6jvYPpYPCwFUhfobeLPpZdbdWlJQz4fN4NGU0kdEyQfqbp8SHzqO3qJG8d/aJpcJdg4sZN7wvwEWlQfX/EGflVqE1+/llW67sKp5CXOwUL3dDNx/EYPC6UzO9UpIm6Luu8zNE4QHdrwNOI7kiApIbeQJ2JyhbAuWBKccSTaK+J6nUyuPTFHUGk+0VtonYmEI6d8x3z9dC8DXVNf9w3Hsuojm8nziR53ExsOJ0cxIrzI+Ub2DeBLXKi3ZCAQKE1BxR1LmlgVCH8O8Z4M/xZsYfsW2XojlqI+ObmWm8Ot2qNNdzR+hKwBJus2CicC8ZKmF7ocuDIVkmRr3FgSFKpPLmUEJ3Iqu+pmzmW66fuexA2OBZhAkk6UD0MjTgxPSO1IrsGK8TQ2UQ/PSytOk6KOgKUVMVsLewZxnmN7xZLxT7NedGAtqQpgos+Q0yI23c7q9NdBL3b9prrdYJUNynVF/E8/3b/nbTkpUPYn1r+ocqCs/PX5MSindXB7lyO8L8WerKGEip+//fl06oOP9+9JprkvxWkDRZCnTN8vasxIZFMd+iWxSZYKUgkq5+W55DjymYfDuYniGvwZf0AxI3r3no9U4zdV8W+3iM9eZCtKGpSejLgV8KXDHq7uFShqZS8qcpgbMMAHvsGiPpIPZSKvhywzInCjDstgS1653k32JQQs9QIp5jZvgtyv6QBX9tWl5I52zrs6FKIVquOG89Zj/FOl5YN5f6loG2OBcBnYKTxDLtjGyFmG8YSc9HyDMUUg2knYQZ8HnKNmCFAa3Xrj4u8UIjLB1DqzoTXKYl9Bu43iDbH1p5slZwV1DewgZM+NzLNlXkts+jmeXyioAEXN94jK0/SWsZ0eMQfTIoC5ldBiZmsyHCXPgtc7sbuvCun90FNADi5PfO6wVcx0JKy6LzWDjLuQ8E5SDUBbMTZw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84679f55-7588-4837-c5be-08db86da58d4 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:35.6451 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VJ7krIKwAYXpNkp43T8nOdDeXQZ3HChNGjtKUQMRaAH89rhpfcl5Ql/GpwEWkx4xz7wDK7lRZZcSRsaPnsCo7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The hardware timestamping through ndo_eth_ioctl() is going away. Convert the FEC driver to the new API before that can be removed. After removing the timestamping logic from fec_enet_ioctl(), the rest is equivalent to phy_do_ioctl_running(). Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller Reviewed-by: Wei Fang --- Changes in v8: - Use phy_do_ioctl_running() Changes in v7: - Patch is new drivers/net/ethernet/freescale/fec.h | 5 +- drivers/net/ethernet/freescale/fec_main.c | 67 +++++++++++++---------- drivers/net/ethernet/freescale/fec_ptp.c | 31 ++++------- 3 files changed, 53 insertions(+), 50 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index 63a053dea819..5d7b76f0c829 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -704,8 +704,9 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx); void fec_ptp_stop(struct platform_device *pdev); void fec_ptp_start_cyclecounter(struct net_device *ndev); void fec_ptp_disable_hwts(struct net_device *ndev); -int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr); -int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr); +int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack); +void fec_ptp_get(struct net_device *ndev, struct kernel_hwtstamp_config *config); /****************************************************************************/ #endif /* FEC_H */ diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 1b990a486059..c35b569d848a 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3237,33 +3237,6 @@ static const struct ethtool_ops fec_enet_ethtool_ops = { .self_test = net_selftest, }; -static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) -{ - struct fec_enet_private *fep = netdev_priv(ndev); - struct phy_device *phydev = ndev->phydev; - - if (!netif_running(ndev)) - return -EINVAL; - - if (!phydev) - return -ENODEV; - - if (fep->bufdesc_ex) { - bool use_fec_hwts = !phy_has_hwtstamp(phydev); - - if (cmd == SIOCSHWTSTAMP) { - if (use_fec_hwts) - return fec_ptp_set(ndev, rq); - fec_ptp_disable_hwts(ndev); - } else if (cmd == SIOCGHWTSTAMP) { - if (use_fec_hwts) - return fec_ptp_get(ndev, rq); - } - } - - return phy_mii_ioctl(phydev, rq, cmd); -} - static void fec_enet_free_buffers(struct net_device *ndev) { struct fec_enet_private *fep = netdev_priv(ndev); @@ -3927,6 +3900,42 @@ static int fec_enet_xdp_xmit(struct net_device *dev, return sent_frames; } +static int fec_hwtstamp_get(struct net_device *ndev, + struct kernel_hwtstamp_config *config) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + struct phy_device *phydev = ndev->phydev; + + if (phy_has_hwtstamp(phydev)) + return phy_mii_ioctl(phydev, config->ifr, SIOCGHWTSTAMP); + + if (!fep->bufdesc_ex) + return -EOPNOTSUPP; + + fec_ptp_get(ndev, config); + + return 0; +} + +static int fec_hwtstamp_set(struct net_device *ndev, + struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + struct phy_device *phydev = ndev->phydev; + + if (phy_has_hwtstamp(phydev)) { + fec_ptp_disable_hwts(ndev); + + return phy_mii_ioctl(phydev, config->ifr, SIOCSHWTSTAMP); + } + + if (!fep->bufdesc_ex) + return -EOPNOTSUPP; + + return fec_ptp_set(ndev, config, extack); +} + static const struct net_device_ops fec_netdev_ops = { .ndo_open = fec_enet_open, .ndo_stop = fec_enet_close, @@ -3936,13 +3945,15 @@ static const struct net_device_ops fec_netdev_ops = { .ndo_validate_addr = eth_validate_addr, .ndo_tx_timeout = fec_timeout, .ndo_set_mac_address = fec_set_mac_address, - .ndo_eth_ioctl = fec_enet_ioctl, + .ndo_eth_ioctl = phy_do_ioctl_running, #ifdef CONFIG_NET_POLL_CONTROLLER .ndo_poll_controller = fec_poll_controller, #endif .ndo_set_features = fec_set_features, .ndo_bpf = fec_enet_bpf, .ndo_xdp_xmit = fec_enet_xdp_xmit, + .ndo_hwtstamp_get = fec_hwtstamp_get, + .ndo_hwtstamp_set = fec_hwtstamp_set, }; static const unsigned short offset_des_active_rxq[] = { diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c index afc658d2c271..50943db40f2d 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -618,16 +618,12 @@ void fec_ptp_disable_hwts(struct net_device *ndev) fep->hwts_rx_en = 0; } -int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr) +int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack) { struct fec_enet_private *fep = netdev_priv(ndev); - struct hwtstamp_config config; - - if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) - return -EFAULT; - - switch (config.tx_type) { + switch (config->tx_type) { case HWTSTAMP_TX_OFF: fep->hwts_tx_en = 0; break; @@ -638,33 +634,28 @@ int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr) return -ERANGE; } - switch (config.rx_filter) { + switch (config->rx_filter) { case HWTSTAMP_FILTER_NONE: fep->hwts_rx_en = 0; break; default: fep->hwts_rx_en = 1; - config.rx_filter = HWTSTAMP_FILTER_ALL; + config->rx_filter = HWTSTAMP_FILTER_ALL; break; } - return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? - -EFAULT : 0; + return 0; } -int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr) +void fec_ptp_get(struct net_device *ndev, struct kernel_hwtstamp_config *config) { struct fec_enet_private *fep = netdev_priv(ndev); - struct hwtstamp_config config; - - config.flags = 0; - config.tx_type = fep->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; - config.rx_filter = (fep->hwts_rx_en ? - HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE); - return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? - -EFAULT : 0; + config->flags = 0; + config->tx_type = fep->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; + config->rx_filter = (fep->hwts_rx_en ? + HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE); } /* From patchwork Mon Jul 17 15:27:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315955 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A421BE4D for ; Mon, 17 Jul 2023 15:28:07 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2054.outbound.protection.outlook.com [40.107.7.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 510951722; Mon, 17 Jul 2023 08:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BcokrBE9ffOs69vSdszDVg6BsteUKuTr0HC9ddEGNxAkyxjQUhnNQg+vxEK/pBRV/lSxT577wnH5yZL7OisvHRKxC23OhY1azgDWam57f29v7nDZ1cA5060N1qZebFP+gair/Rp6PB3NQ0W6L5lwR9f9Uxe/Re5fzQvQWvsyIWCnxdn3/djOYb74Ct+70o3WA17Nd/PAwZQXhJWFcXC0zxKj16qG7RDOMFdVs7Ntq6r2dY9+t7XPvqjiTsVKbBJDcWhamHhClfuITL7V7r7jgePdqaVZ3Hskg6bIHWCifT4lsswBq7EOxiITwxzr9IEIrLnXteuJrbHb/VsRIX3Q/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lUAanPRK1diQyomFpVqbG558jdidXyXGrqDt5hijqYI=; b=PRdkkUHT7wdPY/9kaD0u7B9hNj3VLdR6IuBDxXLXG3ZWNqnOCYs3eG5dQMkX1cT366BXrZnypALkD16HaaLz01P2DmzYpG/QWc8bDcb1nHZhKAtExdDbUGklr/pwE2a4dCSh8FDrydXYl6E2gOJlrx8/oyg840eqWMHwBFilrxmQsrEBTg19idxwn5NJtRY0lzi/c1DSacOrDUhYcDuPvdVhbTl6oT4qgMsKp5EB0I54puQ5XOegzr8ZMNF+lmFq3kMBH/H4DQ1ez7RVhnaYtyQckiQkAAHCnWgzWJXuBwqNqiqQpA422VtHyB1Qi85bFCw7MIJzUibcShf8XDlEyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lUAanPRK1diQyomFpVqbG558jdidXyXGrqDt5hijqYI=; b=gV2RE3SeVnANpe7wxldeAsdwWqkM+6JByTfg9y6+md0droxCdGa3dt4/mRkION5ArUX7OzyUa2BEcvSyIFU7xwplDIok7eEONK9Inu5qrNZ2U9swuLRCcXidYDZxhycLo7KQm5LPgM2FOPbrpBWy1FTkK+cbT5wznm+1e1Gy4nM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:37 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:37 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 07/12] net: fec: delete fec_ptp_disable_hwts() Date: Mon, 17 Jul 2023 18:27:04 +0300 Message-Id: <20230717152709.574773-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: fdd8b566-8493-4446-7818-08db86da5a0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XTqS0FQCwkrOdw9ast3MEIuqQbWDJglGoFvhr7tXmBgojLjlxf6FMZW4TpsAtWLVeBoQQVMfllLJO6GOy0WRlh8Irplf/GebBgaDht0NiiCKhEY7dNA2MvToUkBJGAbh+VmSvIzA38BYNIPpRAQ1Yav0sJII/TvbbO9+TTPLPcuGZ1ACguIm4QloG6h8tRwaSJE1OPSUY0/AQvt9Qbiw1M4MLhVTyAj5L9Tocv5npO77n+uyo5OKjtaWVWLMbJuaeBwylGL7vb2/hQm5CSBZwpmsr6tnhrs45kBLWC9k0/elBq0H7Nzv0T1Iszd1CsuFELUxdLLOxJfJEYV6fHU4ql3h1YYdpeRy6tMlf8jO37YOc/JGWyVafkqGY9n0MHtwULyKIPKrXigN0pVHue9vyKR9TReLMtIBXy9LFJAzY8Jz220XZxmrQLPuKi4jNo5twJ7gJaTUehD7QuisnIpziExYfllVe5eBUsgOW21JlaflV6dJorni1/PJIVXRH84M9sTVn6SaBs1aD6m8YuiEOjFBHvyDiFaqKjmANgko1lAURv1fgKUnxIMeyslrhwpR6puD0qlzG6AzN36Ykncd2UgzLF/MapZ32Kz58ExM55Gq+QhU/IyqDcECvmOR3RDk X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W/9QgzLrGUmi/YWl+P9WdYrZ8Hjf9UszQpnYlqwDfjQgtpmWZudevBtaCAqj5+OEr8nB1Sz6TEDM9EUQ+rFG1Kbqaov0HrXraFQdzs3FVYc5NDD0bttn4Uh7q9xmObmL4qecKgSVz+dTXipMGNecwBorXH9V+MzzjgK4bhW7S7gCIlXLx/iueuvFw1KdmOJxzTzbtFeLWns1a/4h7eWU1Jya0Ey/YLfqjI7m+mWqlr0lJmFt5StVKY6TiLQd1yk3ViTGrx2i41OL6mncJuH85pstUQMDjyVLJ2SmW1TVlDdcdm3zglHEdASBHW32ZEd0pG88i/c3ZKHEpcBzIm/asR97f0kU4IzE6ZI/4Iz22Qbw/3Cv2MsHSzEkGxm7WIJ2z5masqyOhHttCmCKFyBgWKmyuydHJynInGtiZuWTJkcMQDWRjkh1IaqdehBjmKr3O63U3CNnP7lKrHRCJAvf8ELv7NiQgomr2Ajndnh/6HK9IMBJveg37UU+zuZfGbylT1hqY1LFyehN1eLD0ddQNGvN1f1KdatIogh8yUvxLQKKNesH11O3PNdz0Rg2yJm/cOa1Hmh2dxZAyDqZzxkHIsG6VeofPHb5onbyaxRy/Srj/8ItGjpkH20oQJEKjXjSHFOP3u0FoD8DiWk1VQZJ+BqcWMdk8KzmZkCaZHu1ZPjAIZiLGg+v8t62mP9fUDqI5rHzcOs/0vDX7NX6b9pVTX4YKNZe7rKx5D4CpHIPv8Dg50a1jMo7xAX3Mr2O/J/EMq2DCqd1stBoC8eqYHsa8FoGjsP1Bzg0Ar7a3OUeA149pXKKsctCJahsC3N++VQ6UoxjP1qKVoVlZk35Ym2jRGqZK/PsEUGDsv4akW8Jcsn6MTGXdNN6UEAdRZgtzOWpMgg7Z9Pkd8AR+kEJfQTEHqzbVZxqqAaKo0Qc4Sf2KXuIE1Irdmm7J5Yrmi46+ziN8QA1XlHRLU936XpVcKxm6t2KZgPUdcDFIfbmUmtZWt7vYE+TJULELCWr5BCxAszWsoJVbiFYzQP1GFdo+8IfTRqSC5nJJWK2o+RB5OwG2AqX4msjjDMGi6vAV3sntXiVriFgH7n4sImvwITAnhgcF4BpSv7XxZGno6m3wj0ULxAW+RxxnmOVF5Vq447Z0uDHFyUa06GO3jpWg8nIlHvrIbLL4uYYq8qc4khPXabCl43CN3b+FHWOdQXmMOO8DseR4KV18wKWlPml1KPz/pxxgas8hsBMkGUmHFa3Obtqpt3u7l6UUdCdGMCBPNM4e6GirNcVe0kHB6EkQ6BaTEI2ZRK3Id2mtMlngHlDvTrv+At2jgFB6d8r1BkHZqL/egH3w+uqm51r9su4qNg0L7WQNguhH8PNbDqvuhaklaAOfXSr9yIaqydrqLkz4LIuFxTRCspNeQZO8CwPNbqGf541qGe54goGiB0/fYuknHv7fXERqsoMoZcB/396aZfCzV9ZMVoxJWLizRo3yzpH0Ts0v+4slL/wgWFdDEOHJxYeJ1s09HgIImjuNwBJWJfwZrCOVyWWcri6LLJPez+G95xoplGWMC/pjTyS+26s5JOh6pdHKzDsZ3yeWIA3Np3XLYFxDkZAW/8+DQ2W4Zcj9UWbJg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fdd8b566-8493-4446-7818-08db86da5a0f X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:37.6726 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4CWXLF59zHwelOpq5dCsKxkVS08lSY7jD27Nja8vrA994hEvyj/OLh5FEBbnuvVHdImXkK+N/T2zAbDNd0uZpQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Commit 340746398b67 ("net: fec: fix hardware time stamping by external devices") was overly cautious with calling fec_ptp_disable_hwts() when cmd == SIOCSHWTSTAMP and use_fec_hwts == false, because use_fec_hwts is based on a runtime invariant (phy_has_hwtstamp()). Thus, if use_fec_hwts is false, then fep->hwts_tx_en and fep->hwts_rx_en cannot be changed at runtime; their values depend on the initial memory allocation, which already sets them to zeroes. If the core will ever gain support for switching timestamping layers, it will arrange for a more organized calling convention and disable timestamping in the previous layer as a first step. This means that the code in the FEC driver is not necessary in any case. The purpose of this change is to arrange the phy_has_hwtstamp() code in a way in which it can be refactored away into generic logic. Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller Reviewed-by: Wei Fang --- Changes in v8: - None Changes in v7: - Patch is new drivers/net/ethernet/freescale/fec.h | 1 - drivers/net/ethernet/freescale/fec_main.c | 5 +---- drivers/net/ethernet/freescale/fec_ptp.c | 12 ------------ 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index 5d7b76f0c829..ae356c5c2ba1 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -703,7 +703,6 @@ struct fec_enet_private { void fec_ptp_init(struct platform_device *pdev, int irq_idx); void fec_ptp_stop(struct platform_device *pdev); void fec_ptp_start_cyclecounter(struct net_device *ndev); -void fec_ptp_disable_hwts(struct net_device *ndev); int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config, struct netlink_ext_ack *extack); void fec_ptp_get(struct net_device *ndev, struct kernel_hwtstamp_config *config); diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index c35b569d848a..28c5f8f8106d 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3924,11 +3924,8 @@ static int fec_hwtstamp_set(struct net_device *ndev, struct fec_enet_private *fep = netdev_priv(ndev); struct phy_device *phydev = ndev->phydev; - if (phy_has_hwtstamp(phydev)) { - fec_ptp_disable_hwts(ndev); - + if (phy_has_hwtstamp(phydev)) return phy_mii_ioctl(phydev, config->ifr, SIOCSHWTSTAMP); - } if (!fep->bufdesc_ex) return -EOPNOTSUPP; diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c index 50943db40f2d..8e64399452ef 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -606,18 +606,6 @@ static int fec_ptp_enable(struct ptp_clock_info *ptp, } } -/** - * fec_ptp_disable_hwts - disable hardware time stamping - * @ndev: pointer to net_device - */ -void fec_ptp_disable_hwts(struct net_device *ndev) -{ - struct fec_enet_private *fep = netdev_priv(ndev); - - fep->hwts_tx_en = 0; - fep->hwts_rx_en = 0; -} - int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config, struct netlink_ext_ack *extack) { From patchwork Mon Jul 17 15:27:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315957 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77354C128 for ; Mon, 17 Jul 2023 15:28:09 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2040.outbound.protection.outlook.com [40.107.20.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4ED7E4; Mon, 17 Jul 2023 08:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N4+ghV72HnHWfTipIgTSdpbsfJ5spPCKE25W+4+a609e2KVaMF5IkTZ3vFyE+RrfBCIrdJFtXzmamdu3jSQmYSKjvJ3YW/kLeLwuel3Lyz1ZejM85Y+tTfvK6zepMVWD8UMECT2jf2mL+SPOkYuQxuhxXh3N6as97fxEQMPj/Umohi5gBZAmvM2SL+F3JpDJidJBnDTATs0MmxgQC6eTYTJtPSKMc0LcaREDfgUkns0CrBBCtYrcHVgSPYn5ZnoMxBqLVm9SFveI486OMDUX1jPFGqvHUUV+pAt9hNiaB0vdIyl7rmQafHaESOQ4FySZJC6G7OPuBHshOu0tIwXDbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AFjoeeps10qbR9+7xOMARTMAfrdxf8YZ3Yp8lRiMMMY=; b=KjSpBP5tGFNRzd/Qdelep8ecb9fVWPu+PqCB2WTl0eXMaQ1Y3TvGFyllAnbNsXwNxy71Tu2gHtGR2W8bgSe54YIv2nz61v7QOHuvkRlnHrUAzZLshRfYkK+U4X1IBrlEwCi5hzemhMnyIO4SHH/g8sRgMXlvuZi6PCdpyClUdpiMgFRXR49Lr0RUyDnXhfCIWuMEKEu/yaNT8NptqXlsTUDKSfshg7IslvWkuALwY780B/w8HZ9cWKl5u1f0+cl48KVuxTVNZh7ubIJtnDc9Xpbh+nZzf7MfNDyTXB8KsyUCqXa9hsIsk/hIqDS2PBYmEWjsW7Z7UrW3SPz1Vzpmzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AFjoeeps10qbR9+7xOMARTMAfrdxf8YZ3Yp8lRiMMMY=; b=BA/QaIFLHq5ws5qSsfYILQEcT3iLZ2umwoN54J9ak9rneaMAAY7L6Wmhfqph65TgbrGVHG1OncdAXwBbXC+XS6cYy/bXe7YufRQ2k4GkArG0b0L1tWPQKALtdlQQ9IGPBK+UV33hYlpuL5EZMQioSVTwdWtKmqkvwgEDWRAF3gI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:39 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:39 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 08/12] net: sparx5: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set() Date: Mon, 17 Jul 2023 18:27:05 +0300 Message-Id: <20230717152709.574773-9-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: 90ee424c-ba60-4132-c81e-08db86da5b47 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7/UiUe5PCliaWuKQT+tTGviGWnTa0WjKTyszYUgJR54Y3eXt3kxu2oOQxNKLOqhvEby+ceDN3zQyCV/dzlt0CfO6E3FlKOngCTePALY+VvXa05R9FeaDVjLgXMWh6Gz+MIk0K37gCaPZsVGY+AL+3Rvf7c3l0THbaKwscY3GYDaAJBQc5iUIOnX3ER+SJIjVgJe2ifGhxqAn4WQ4UMtf9YnBEaFlweYdy2a9NClMp1FXKhug5f5y8z8NJTaPnCm1sDMwGZ/AvLfJkbUGsjMKD+v2tz92KozlTiVItZVdmOn8oeqgCTD8J/Rew2/ORWI69vhTmBuj92Iw1ttvpu1EgHUR5O7wCzcX0GhTFlKD9VxnTmH2fwgHGvPPQvC7IG4+jyhcqZuqVkfdr5ewsPJwQMF6z3bnFeQoOUijE/KAnFGtDhZfty7J3KWZYzy5VKHLBoL3JuD5PvdCCa9xxQeAkAaeB9hXlmrfhTAKHTMB3bCtLVTpPx1ccgZMtQIHQTS1k/+i6K52thL3FQPzYfy4tBWBKY+JXKPLJ1JsPDjNpMQSEKC10hx+IsmvDmxB4Ry6zCGJVdLdnM1E/uJB8lT6ZU/EzEUAunPpE/urpJ1phvxs+iE+sDBFMY0u67zhZtEX X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: R5jY0wFkU1l2F7umdQq7URHrinA6P1FXdHEUmAa+x/6v6ozkpYxQJrHsKZ09+co0z1+3net/1LPwikz27O4L0OWsOgdPp+W5+TWgg5j+NapZkBsICenOIo4UKnzmoXHyClTJBYDuUfNycRx3kLiz/DTRQtjvi/qgvIXM9XL65Zkf8+DIiRBdZl30xi1tJXoW/gkD2iswQooxgx9O8FHkkPkU1nkgxCUWeqFOg/yINQJQ7IV16zE47omR7MGak30rpTQ2LkJcvm1/pRSUxyosdm91W0T9fq+XqqdbtVxLgeNrR8liP4cLHrxhfCnFjnSVKBYrn0KtSZviGZYdDfTyqBjckPC/RKM206t+7xmpOFXPLniSaroG07sX226+9urSfJhq8gs4A466mw55hPDAyro11AoS0XIa0kebv4UVtpm4iEMvMaT0vrgujDiJT1NE9GeHJIxqC0y3QONczyuPJ46soA+8kmxBm/0+N7mcQfuq6uUl869KTYoW4DEXsfof8rPIpQFYfJZBGSUhhR8G0gNGm9QxoYQpVGYl9QATCM7TAozlxzu5fHx1gvMvMMIhVXTJXcATpNfOAorKqZXSintDPyMh4r0T6VuKBokxdeRIajiuj0Qcxk8sFub78B0oqY7QLHTWXncyQlVVRWtX7NoJzy1ld9iyRWxq2M4Xw4ywh9uVkNCHAquTXuhGpSoRrHGRL0kmEwKgJiOEbjlMKWX2M9PW9lhO6tBC0LXlImgdqduZ3BT2bjhkqjyfkWNJoW+rr6feGDifRbHfZESjRIz+GZCgVaOgkf+cWrxdn76G1XVUFRxypUzBoOCZzvXnI3TELlu41JqFomCE2br8i3jpPXIu2hLS6O8jFO2fBtVX1lSRfz8JR3ia+Zle2ErGAvMYBGybz+iDlCwAmGh6fp2Ywn/zptWFUzGzG9Lp8L3luy1U/qD2MX5JdjZXVHo6g/9iEWrN1xdWDlmZmjIFGV0X4BJkHz2Nxv2lyLK4XPfnfh30ClsO3uBYbMYrozV+liyYCw10US1Cxm3YDKbSISEgjsBxR9XnJMs92b+Rsg9EQewVnuGxykigQ4LiSJ7CIgLrXfszDUKBZ1aadK9g+Rd9rREy4WxFDeSpgmXUAcQ8ImP3MCb/r12hiof74rDKC/QyIFB92AnF9FSUwstDBB0CKKS4F6jKA4bhffgxZic09qwNIMuBqBM87Ddv0sGSWhOv7a1agP81mGMmzrqaZIhoR9eMhnt3TvM8OkpZ3YJWCzCg06DuXXY8Wk02NZs3MTIzflwkgsaZjSnnuJgMys623j2gXGhZwis87mO4ffCWQ3w/Tjg/zjYjco5+TsIi57W83QbOSquMJxow4QFKEXoCE6b+fLykefVqSoqVtbk0O+iKpRi/eOBQkLvZphm9ExbFXbdj07hr+sGiExHJYZZsyXywkU52vIA+cChdfOjCb9MJDM93KuER7KKhabQfkVMAI7U/e4r5lfGWPZUARcwh6+32WGjdwRCvLYmRWiDcGKTcL4pi6Zq7ah1Ie7wjuBaohkuWN+JAl0onCg9NpbfffcB79kziwDlGHdiKJojs58WGQRbpGTyXULQ+XTbe7Nr1bJuOv9fj6ke+fch/3w== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90ee424c-ba60-4132-c81e-08db86da5b47 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:39.7065 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1JC25/R2OzYVS1eSId3rUx+g8UzXxhFgWah/Eu90PNj3cDsr4ui5kd7Cw9NJ7JPjZe/6euDSW7VUc/XlBEmjCQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The hardware timestamping through ndo_eth_ioctl() is going away. Convert the sparx5 driver to the new API before that can be removed. After removing the timestamping logic from sparx5_port_ioctl(), the rest is equivalent to phy_do_ioctl(). Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller Reviewed-by: Steen Hegelund --- Changes in v8: - Use phy_do_ioctl() Changes in v7: - Patch is new .../ethernet/microchip/sparx5/sparx5_main.h | 9 ++-- .../ethernet/microchip/sparx5/sparx5_netdev.c | 41 +++++++++++++------ .../ethernet/microchip/sparx5/sparx5_ptp.c | 24 +++++------ 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h index 62c85463b634..89a9a7afa32c 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h @@ -205,7 +205,7 @@ enum sparx5_core_clockfreq { struct sparx5_phc { struct ptp_clock *clock; struct ptp_clock_info info; - struct hwtstamp_config hwtstamp_config; + struct kernel_hwtstamp_config hwtstamp_config; struct sparx5 *sparx5; u8 index; }; @@ -388,8 +388,11 @@ void sparx5_unregister_netdevs(struct sparx5 *sparx5); /* sparx5_ptp.c */ int sparx5_ptp_init(struct sparx5 *sparx5); void sparx5_ptp_deinit(struct sparx5 *sparx5); -int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr); -int sparx5_ptp_hwtstamp_get(struct sparx5_port *port, struct ifreq *ifr); +int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack); +void sparx5_ptp_hwtstamp_get(struct sparx5_port *port, + struct kernel_hwtstamp_config *cfg); void sparx5_ptp_rxtstamp(struct sparx5 *sparx5, struct sk_buff *skb, u64 timestamp); int sparx5_ptp_txtstamp_request(struct sparx5_port *port, diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c b/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c index d078156581d5..e01d3b1e17e0 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c @@ -210,22 +210,37 @@ static int sparx5_get_port_parent_id(struct net_device *dev, return 0; } -static int sparx5_port_ioctl(struct net_device *dev, struct ifreq *ifr, - int cmd) +static int sparx5_port_hwtstamp_get(struct net_device *dev, + struct kernel_hwtstamp_config *cfg) { struct sparx5_port *sparx5_port = netdev_priv(dev); struct sparx5 *sparx5 = sparx5_port->sparx5; - if (!phy_has_hwtstamp(dev->phydev) && sparx5->ptp) { - switch (cmd) { - case SIOCSHWTSTAMP: - return sparx5_ptp_hwtstamp_set(sparx5_port, ifr); - case SIOCGHWTSTAMP: - return sparx5_ptp_hwtstamp_get(sparx5_port, ifr); - } - } + if (phy_has_hwtstamp(dev->phydev)) + return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCGHWTSTAMP); + + if (!sparx5->ptp) + return -EOPNOTSUPP; + + sparx5_ptp_hwtstamp_get(sparx5_port, cfg); + + return 0; +} + +static int sparx5_port_hwtstamp_set(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) +{ + struct sparx5_port *sparx5_port = netdev_priv(dev); + struct sparx5 *sparx5 = sparx5_port->sparx5; + + if (phy_has_hwtstamp(dev->phydev)) + return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCSHWTSTAMP); + + if (!sparx5->ptp) + return -EOPNOTSUPP; - return phy_mii_ioctl(dev->phydev, ifr, cmd); + return sparx5_ptp_hwtstamp_set(sparx5_port, cfg, extack); } static const struct net_device_ops sparx5_port_netdev_ops = { @@ -238,8 +253,10 @@ static const struct net_device_ops sparx5_port_netdev_ops = { .ndo_validate_addr = eth_validate_addr, .ndo_get_stats64 = sparx5_get_stats64, .ndo_get_port_parent_id = sparx5_get_port_parent_id, - .ndo_eth_ioctl = sparx5_port_ioctl, + .ndo_eth_ioctl = phy_do_ioctl, .ndo_setup_tc = sparx5_port_setup_tc, + .ndo_hwtstamp_get = sparx5_port_hwtstamp_get, + .ndo_hwtstamp_set = sparx5_port_hwtstamp_set, }; bool sparx5_netdevice_check(const struct net_device *dev) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c b/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c index 0edb98cef7e4..5a932460db58 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c @@ -74,10 +74,11 @@ static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5) return res; } -int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) +int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) { struct sparx5 *sparx5 = port->sparx5; - struct hwtstamp_config cfg; struct sparx5_phc *phc; /* For now don't allow to run ptp on ports that are part of a bridge, @@ -88,10 +89,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) if (test_bit(port->portno, sparx5->bridge_mask)) return -EINVAL; - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - switch (cfg.tx_type) { + switch (cfg->tx_type) { case HWTSTAMP_TX_ON: port->ptp_cmd = IFH_REW_OP_TWO_STEP_PTP; break; @@ -105,7 +103,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) return -ERANGE; } - switch (cfg.rx_filter) { + switch (cfg->rx_filter) { case HWTSTAMP_FILTER_NONE: break; case HWTSTAMP_FILTER_ALL: @@ -122,7 +120,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) case HWTSTAMP_FILTER_PTP_V2_SYNC: case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: case HWTSTAMP_FILTER_NTP_ALL: - cfg.rx_filter = HWTSTAMP_FILTER_ALL; + cfg->rx_filter = HWTSTAMP_FILTER_ALL; break; default: return -ERANGE; @@ -131,20 +129,20 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) /* Commit back the result & save it */ mutex_lock(&sparx5->ptp_lock); phc = &sparx5->phc[SPARX5_PHC_PORT]; - memcpy(&phc->hwtstamp_config, &cfg, sizeof(cfg)); + phc->hwtstamp_config = *cfg; mutex_unlock(&sparx5->ptp_lock); - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; + return 0; } -int sparx5_ptp_hwtstamp_get(struct sparx5_port *port, struct ifreq *ifr) +void sparx5_ptp_hwtstamp_get(struct sparx5_port *port, + struct kernel_hwtstamp_config *cfg) { struct sparx5 *sparx5 = port->sparx5; struct sparx5_phc *phc; phc = &sparx5->phc[SPARX5_PHC_PORT]; - return copy_to_user(ifr->ifr_data, &phc->hwtstamp_config, - sizeof(phc->hwtstamp_config)) ? -EFAULT : 0; + *cfg = phc->hwtstamp_config; } static void sparx5_ptp_classify(struct sparx5_port *port, struct sk_buff *skb, From patchwork Mon Jul 17 15:27:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315960 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F836C141 for ; Mon, 17 Jul 2023 15:28:10 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2054.outbound.protection.outlook.com [40.107.7.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83BBC10DD; Mon, 17 Jul 2023 08:28:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O03xGqhpvLZhOkyPM0bBiwgt44x9z3zEKmI9v8cKh7QVuBfLWPIUt1K7tKm2AERUILLkgkB8G+FdbEq0LAmYowh9JFQuwHEZzeiVEvK33SbrHShEIO++BoRvsLkDnk7N65GG1I61StGxnN5+rmqgecP9H/4o2BXPPV6zQT1G5xfLzEcWCteSw1uzq/EHiRr4SG1Wz7UvQStkviEHvAUyz3uE2mw4bw0mLp8CFnXPXqzNOvSSzxjXZUFs1pxX5D4cE2NHkAg2ENArdOh7YO2kkLRtQSyi5lZfOVEV3TmEExvwCE44gRcq8WTTb2enDl6mHgMdaZz1GjJ7wYcaaN0xUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HUtSGkapv7OUjcIv8IKaB+k5i8nfs7VHcZWEItKQ6/c=; b=JdevS0XXrH3ML4QWFrzj/NxMOtUEQloILfZYCne1c4NPRDPC1Pyj8eZCbEWGU7vE2sZsvlKOcGnFOzVvc4SOOqmhk+AOXNiHwT/HL4lY847/XseyEml4P8h8gyaCPbRI+PNSeI6IA888eoigwNjbHbRRFXfvvytdlmTCeCaMSXY5c6Qli7nlpmOZUoU1W+9AfbVanFugqiF1/REqDwmgYTT+8dEX/UMzExDqD3K+OyyaF3JgrbwZCHQNuJRvE97AbEJQ2e0HPscL8JQ7IzOzHg4/Mzv+JKr/M9F7sGne3h/Tb/aUmIhXsL0P0cMVgzlbUd3NAIwpAd22mG6Gi9lx3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HUtSGkapv7OUjcIv8IKaB+k5i8nfs7VHcZWEItKQ6/c=; b=iTaG05ZOBDudjkPkz4GyLJdWoyDK/2EqNCv+RdiWldci3Zv/mfHXcVkI6Yy0/7VUyApQxtgFPUcPlSjgecx9pUKWF77ODrNGadw2N1+cJw0q3Mus0cAyrKZECiu5gpomgEkKk+mCAMoun6iC5TTtGTpHx/2TNECFD96ksOnT8uI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:41 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:41 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 09/12] net: lan966x: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set() Date: Mon, 17 Jul 2023 18:27:06 +0300 Message-Id: <20230717152709.574773-10-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: 744c6b5b-5794-458b-5378-08db86da5c7b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BEfZGwZfll5NHXNMrV4OiE1lXvUPDu8+MT4TTnVlYDxb5lQzDQHt/SYMNmD1Xy4oFLlxbIag7Ceh4JkX668uCsD7xmxe9A4DxJUyPgnsRVVHb+UIS6n25BCnYcf/UBGCmFuqK6trC+rrQWX687qWF/jDf05P4Vr3q4npVA0JAQC4yDW2s4V+u/TqhNRCngqLP9dxpR2/7JxPxbkcsdJ4sxBMPf0jjCPpZkFEKYRrCiMrRLPjmLu8scQew/XUtJXW2NB9i2UW3hiGPYBzUJYFYfp8w6fwNiw308nl1DhvXybL+uQ7RNA3W2oO6TSZ/XWwlzMADC0NbRUqz0FToj+OukHyvKry23cWLP/GY6mVZzFXX+POaBwCF2ioulQWxikeD4l0kEbCxwHwv/I25szhokSOOWitvreTWwAPd6fC/ZrCuYl7V6ee1H1BW3BtZw7Sb+REhs6iov/htMVeZbQPJcs2lDrxKjjmXfJlRMfKvgJBwV95CtS8ZWxx0ycPsErOBafHrzHUhBTt9kdNN9FrHw02DZAygXX98L0GRuGitYSdFXWKcMk2dDzWoTLPy9F1H8ZQJiIauhtsZprOv51cA2EQfxu4P1iIPFJA4dpQJSN6UnJZu4anziq+u9EKWIuy X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G0PmKMffhpfpuV0cmRZohLDTMY3T6yEhQLxuTCA9qWAb8gEqRoaJSTRqunHPU/uefAZlE4H0rtPNfG2dhn0ULHnn2pBtFyEGnY3SRpF9WtEXpuRY0/CLlUWGaFQS98NW3WkC2Sljr43ADAFcGh9KQbzo+TzuN5jJbzSXRsst5FFQcUddRWEbGrtNpeo0Ri+PeYNjtzm0mdiUrFwRfUh+2wtxWoBlifw4/6zelWfcVMa7OL5ptCAEFsSqlmKRzCEU/7mo+T9ETqqnTjOGmSUUOJw2oWQeZ4yqk9GY4hHH7Z/jSC4qEfmomqPQ7Xu72UdHeHQ+i+nBgCkKw9y0+bstrx8oveaSnY+azJWbEz84fX6QOsBqlQZwn3xhmHJMtBziHcMRGGjMlVzqgNjVnuy8qYUmsOTPDnw56gIWDge3rkCxFXqQPEUOclgh4RWwAVzBjAfR3dj8dGvaDmw55g9JNxt7KfIypPs0f3O9EIF/ODfnIM4avm052q08OfxhxrtYg8vnHxFj9GVvtzvu1BZBeY4g3A5lG4Ew6YeLj9kzsV+FLlyVug2ZZlYGXHAW/Hk8rOI9CkDfxvn3FT0cyEekcpylhrZYqOC8BW4I39R2AleSn/ZHyrHQdDl+UwjWUQ3/5g5HpFMNBDnz62NUMXH6Xa9LVyf3FEmctvM3/ijo2pBAupE36kQgLIWNOeU/QGH0gt+dt91RNP/F5Zkn3WVj3tfF2TwdhGMeu6MZnyHv3L6Qy4iA39qAq6Smx94wIW+FATLDrms21KhJftdZE1G6QpIpF+YgSyEFb8+SDkmSEnBfo+27TbFpEsnBoaQJMiea+VInlpS1KuQZVpkgRpHJRTrtAIXUA7jFt9ekZNu4dDsv1Y9uQaWB9+T1lrSDTWhKHALlrjvh/AShy7yQwJfdK6l2NQNx/aQlFmvPPTTf3CPxvMfJGydK/jJ2CP7AfSK7JSUB1LXCZpYTKvPxBIIu2aN+ekSve+FWOQsHBDxm0msoyWVbWsFEdBBTfA/1XnLI2jGkqtweJdUEb9DNH2jNdNZFUoWA+1CbdTihGtoGlxGyedwMI9QV0b2Mb5MaVDUUDIFH4+F0IrX3zsby8QPdUVzIw0CWGZmBz364mc8YzuLQdgoVtSt2YHhcwmehqXZVqj7guML+heMl9xDu6OWt+n4JiaCnq7xGkzvyBakzpPGtrwe1bLJM7XeeRgEmJKzL97sQhW2pAxp/mstXeyTz9KycK/u/4w8qgFdZwtMa211DXS3ST3BQRdld7CcxSHkCFlFN320clsp1XKl1TOp7s0CfHDJvw8Bt/UtED2RnXpeRbpgI3GdvQY8XuF7ka1ClHQ0K3/Pm4u+bS2TaL9f+Z5UIOe4QKSTNkwXWhgp0lLWYaYYbhBuhjBqXLr+UnKxBX1c8EOfT5EbT+knabxjw0f5l0KjKmBN3LrSBv/n7qHiyhxI4TkVVVQToRk9ocGbAw5Z7xUx42CzEVMTcCt91f5f8RVeB0qUfpIndwdJlFcKGWozxU8S/uITv+0zol6XbpOfqp0JHCEkYCC4uBsiWdNcvFib2XicB0s0qF1PiBB0Ukoa40laeqSXdiCs94IaJWqBMaOkCoXMj2XWtbVzBWg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 744c6b5b-5794-458b-5378-08db86da5c7b X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:41.6990 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eEd4qtEQ7MwGZDBW1S08zRN6x+IMiolB71WEogLsgsPUl4CqInIZqHzNVuGipYGnejLEO71wsvkElGMaBHyv4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The hardware timestamping through ndo_eth_ioctl() is going away. Convert the lan966x driver to the new API before that can be removed. After removing the timestamping logic from lan966x_port_ioctl(), the rest is equivalent to phy_do_ioctl(). Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller Tested-by: Horatiu Vultur --- Changes in v8: - Use phy_do_ioctl() Changes in v7: - Patch is new .../ethernet/microchip/lan966x/lan966x_main.c | 59 +++++++++++-------- .../ethernet/microchip/lan966x/lan966x_main.h | 12 ++-- .../ethernet/microchip/lan966x/lan966x_ptp.c | 34 +++++------ 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index fbb0bb4594cd..b0f614fbc5db 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -449,39 +449,44 @@ static int lan966x_port_get_parent_id(struct net_device *dev, return 0; } -static int lan966x_port_ioctl(struct net_device *dev, struct ifreq *ifr, - int cmd) +static int lan966x_port_hwtstamp_get(struct net_device *dev, + struct kernel_hwtstamp_config *cfg) { struct lan966x_port *port = netdev_priv(dev); - int err; - if (cmd == SIOCSHWTSTAMP) { - err = lan966x_ptp_setup_traps(port, ifr); - if (err) - return err; - } + if (phy_has_hwtstamp(dev->phydev)) + return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCGHWTSTAMP); - if (!phy_has_hwtstamp(dev->phydev) && port->lan966x->ptp) { - switch (cmd) { - case SIOCSHWTSTAMP: - err = lan966x_ptp_hwtstamp_set(port, ifr); - if (err) - lan966x_ptp_del_traps(port); + if (!port->lan966x->ptp) + return -EOPNOTSUPP; - return err; - case SIOCGHWTSTAMP: - return lan966x_ptp_hwtstamp_get(port, ifr); - } - } + lan966x_ptp_hwtstamp_get(port, cfg); - if (!dev->phydev) - return -ENODEV; + return 0; +} - err = phy_mii_ioctl(dev->phydev, ifr, cmd); - if (err && cmd == SIOCSHWTSTAMP) - lan966x_ptp_del_traps(port); +static int lan966x_port_hwtstamp_set(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) +{ + struct lan966x_port *port = netdev_priv(dev); + int err; - return err; + err = lan966x_ptp_setup_traps(port, cfg); + if (err) + return err; + + if (phy_has_hwtstamp(dev->phydev)) { + err = phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCSHWTSTAMP); + if (err) + lan966x_ptp_del_traps(port); + return err; + } + + if (!port->lan966x->ptp) + return -EOPNOTSUPP; + + return lan966x_ptp_hwtstamp_set(port, cfg, extack); } static const struct net_device_ops lan966x_port_netdev_ops = { @@ -494,10 +499,12 @@ static const struct net_device_ops lan966x_port_netdev_ops = { .ndo_get_stats64 = lan966x_stats_get, .ndo_set_mac_address = lan966x_port_set_mac_address, .ndo_get_port_parent_id = lan966x_port_get_parent_id, - .ndo_eth_ioctl = lan966x_port_ioctl, + .ndo_eth_ioctl = phy_do_ioctl, .ndo_setup_tc = lan966x_tc_setup, .ndo_bpf = lan966x_xdp, .ndo_xdp_xmit = lan966x_xdp_xmit, + .ndo_hwtstamp_get = lan966x_port_hwtstamp_get, + .ndo_hwtstamp_set = lan966x_port_hwtstamp_set, }; bool lan966x_netdevice_check(const struct net_device *dev) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 27f272831ea5..b538d496e8d7 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -298,7 +298,7 @@ struct lan966x_phc { struct ptp_clock *clock; struct ptp_clock_info info; struct ptp_pin_desc pins[LAN966X_PHC_PINS_NUM]; - struct hwtstamp_config hwtstamp_config; + struct kernel_hwtstamp_config hwtstamp_config; struct lan966x *lan966x; u8 index; }; @@ -578,8 +578,11 @@ void lan966x_mdb_restore_entries(struct lan966x *lan966x); int lan966x_ptp_init(struct lan966x *lan966x); void lan966x_ptp_deinit(struct lan966x *lan966x); -int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, struct ifreq *ifr); -int lan966x_ptp_hwtstamp_get(struct lan966x_port *port, struct ifreq *ifr); +int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack); +void lan966x_ptp_hwtstamp_get(struct lan966x_port *port, + struct kernel_hwtstamp_config *cfg); void lan966x_ptp_rxtstamp(struct lan966x *lan966x, struct sk_buff *skb, u64 src_port, u64 timestamp); int lan966x_ptp_txtstamp_request(struct lan966x_port *port, @@ -590,7 +593,8 @@ irqreturn_t lan966x_ptp_irq_handler(int irq, void *args); irqreturn_t lan966x_ptp_ext_irq_handler(int irq, void *args); u32 lan966x_ptp_get_period_ps(void); int lan966x_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts); -int lan966x_ptp_setup_traps(struct lan966x_port *port, struct ifreq *ifr); +int lan966x_ptp_setup_traps(struct lan966x_port *port, + struct kernel_hwtstamp_config *cfg); int lan966x_ptp_del_traps(struct lan966x_port *port); int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c index 266a21a2d124..60bd0cff6677 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c @@ -248,29 +248,23 @@ int lan966x_ptp_del_traps(struct lan966x_port *port) return err; } -int lan966x_ptp_setup_traps(struct lan966x_port *port, struct ifreq *ifr) +int lan966x_ptp_setup_traps(struct lan966x_port *port, + struct kernel_hwtstamp_config *cfg) { - struct hwtstamp_config cfg; - - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - if (cfg.rx_filter == HWTSTAMP_FILTER_NONE) + if (cfg->rx_filter == HWTSTAMP_FILTER_NONE) return lan966x_ptp_del_traps(port); else return lan966x_ptp_add_traps(port); } -int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, struct ifreq *ifr) +int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) { struct lan966x *lan966x = port->lan966x; - struct hwtstamp_config cfg; struct lan966x_phc *phc; - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - switch (cfg.tx_type) { + switch (cfg->tx_type) { case HWTSTAMP_TX_ON: port->ptp_tx_cmd = IFH_REW_OP_TWO_STEP_PTP; break; @@ -284,7 +278,7 @@ int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, struct ifreq *ifr) return -ERANGE; } - switch (cfg.rx_filter) { + switch (cfg->rx_filter) { case HWTSTAMP_FILTER_NONE: port->ptp_rx_cmd = false; break; @@ -303,7 +297,7 @@ int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, struct ifreq *ifr) case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: case HWTSTAMP_FILTER_NTP_ALL: port->ptp_rx_cmd = true; - cfg.rx_filter = HWTSTAMP_FILTER_ALL; + cfg->rx_filter = HWTSTAMP_FILTER_ALL; break; default: return -ERANGE; @@ -312,20 +306,20 @@ int lan966x_ptp_hwtstamp_set(struct lan966x_port *port, struct ifreq *ifr) /* Commit back the result & save it */ mutex_lock(&lan966x->ptp_lock); phc = &lan966x->phc[LAN966X_PHC_PORT]; - memcpy(&phc->hwtstamp_config, &cfg, sizeof(cfg)); + phc->hwtstamp_config = *cfg; mutex_unlock(&lan966x->ptp_lock); - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; + return 0; } -int lan966x_ptp_hwtstamp_get(struct lan966x_port *port, struct ifreq *ifr) +void lan966x_ptp_hwtstamp_get(struct lan966x_port *port, + struct kernel_hwtstamp_config *cfg) { struct lan966x *lan966x = port->lan966x; struct lan966x_phc *phc; phc = &lan966x->phc[LAN966X_PHC_PORT]; - return copy_to_user(ifr->ifr_data, &phc->hwtstamp_config, - sizeof(phc->hwtstamp_config)) ? -EFAULT : 0; + *cfg = phc->hwtstamp_config; } static int lan966x_ptp_classify(struct lan966x_port *port, struct sk_buff *skb) From patchwork Mon Jul 17 15:27:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315958 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26E4EC141 for ; Mon, 17 Jul 2023 15:28:10 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2082.outbound.protection.outlook.com [40.107.7.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 015BF10F1; Mon, 17 Jul 2023 08:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vr2WcPMui2vtcw0Iyuijimks+bAvVGLqJVFPckQaHvUmZjkQ5Qbud1djkxR374AgPM9laY/PpjvI02pSsA7/NuXom6MTNO11PGDzPKa7R2YhlAJh63lmvyLsBiAqO2iu0kC/3pT6aIQBd7Ywkg1Zj+RbKzwnXp/q7yBYKomBCdll0RFoVOVsL7G1kca4/XGonqxy79c6CuX5WYUPZib18WrH/BwsA90RZdnWEVHRxAdwtmrdWxzlZjBcURthAyj2uTCGa5Jk7O/a+bDe4627kVdVXSPW+9n/BFkBidH/SXsIEzJHMPRDtC2ZPiT6818RlPZnsq4ISaWy1BNXGOHoQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zzc7E6CfYK2zrLX0w9MQWTufyjGs6lAs5lxehq134N0=; b=ZgyQdC7JMwEVUcR39tlyJLZ7M+VCRUN343Ay6N5Af8lzz6dazwk/rSKU5Zz8BDZawUxsDtqg4vN1B/amWKfzSy4JR/dP/z7Df4oz9Skf+Rc2DEvjwCVIcAoWuzDzbvbIXOTvqVyvNR3J9pstnlW7A+z3SB1Op5UXXtSCcZPN1u5ReN1AMdP6Qecm9O4HRZuTqdNctg8gl0HAmKfCJisdzeBYlFWKrrP1wKSh261lwuUssliJ8RN5utuA9J+dsOEYd9rl1fGI04JtfuC4pOxBQrRrKYwMeI4MEW+wSy5rNUt8+dip/SHo5CcuuLg1lrE3jvkAt+6o5pto6enfGeibMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zzc7E6CfYK2zrLX0w9MQWTufyjGs6lAs5lxehq134N0=; b=QzdivViPK9znGAsSR9Tdb3vgdeT9KGZJZJvi6jWGo6N/E1tah4TUUpetex6pAlZdiyUBoR/ncJvU+s1nv08yE0b0WMln5zDAl0CfZk/DZlVfKVgmstNj15TJRDR/iFjBIc1faGrJa7MDY6kZnhAqUQqP8lpOc+ra/9XwkDzNq7o= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:43 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:43 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 10/12] net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller Date: Mon, 17 Jul 2023 18:27:07 +0300 Message-Id: <20230717152709.574773-11-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: ab8b09c6-9f9d-4860-f33b-08db86da5da2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hNKNeyk3KvtwhfV1WFaF/8uhAGxov6c6Xy0IqoMc8j8qEObksh+mdZKHWEuHKRp83W7EcUg7tmUS1NDdR/siQ4gsXWuz6JI62SoUnBMRoH3qfeqrn9Ni6m6qte7JUtWvPQ4octiyG7QozMHDkdw09MKdUoqpTytlI10AM3xeQ2u4L26yhhX6sAvm2bE6jAnNvBlKr+LMvI7sqO6mVfbf6FlC0mh4MSdbLtY3lWrLAVE3lsECjcDNGhEhPH/rCCBUS0CN02r2uUuOMUhso/ehdt+EwOvHhZRL6WrZ3a5XGrtUgKjCxw7+L/NhyxBl+NgyujSceXZHObSuKKMQ8NO2+FF0QV/ilXQ4gg9BQLtMqeF2Ao4DXNBGJvRljwmFMMdCcESY4vIshiRDvBNvm4jGThdY1OXikFjTwDGlS4VAt/l0YLiE80VqzHkR7xGvWQp5aJSgghVpavEhlNRLNbyWWgQikZ9Sr1bVdwrG4itozTXwdgNjFnyxMoAeeE+Wj8mp0AttWoccXNFnH+Mz1hLsxNd2qMMt80RlpW5zSXLOuSCtiyrGDTxXncrIuQHCPCJRvUiqjxYqZ4a8r22cEdxTH932mlTmzypfa9NJ+ZjOgxlG1xQi//X1Kuh4FkTBJC96 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TTLYsPvzgDE5o6bMJ7XgVJ3gLxbb3r0eOCCqrdPqvqHZLTwsCBC4S/f8VCgFGCGQKqnNeF2LaWxepyFtgbCfJ7Me6azBrhP4iO+39ErTU1NmmwD5WXCLD5Xb1qgVryqzELmeixO4x5h/gas0GSpgGJuajpY+UOvRDnveJIgBIlWJh0auBtpH0JPnvf2pIUtbAyKjoruXcbQkr3bivRYmVXUjjpf6ZdB/LTEW8rcokVijtc51uYprnEPRhpWcwTfYtPqOCOdgs+rT3KbVA+zLTSjxM7SVUC4h6gMYIslLGoPqFdEBAEmU4UbjjfL8fV8QfbH1ZTp6NyghOgVEPZ9DlpIBiRXxnVj9tYr3KaWyeVbVBNFDF4wz0NNKiy1jTFy2mAX98//7HOALb27k+JRs+sxaKKdq7EGnpX3CgXeSJQ96hjezbdOu51IJnfDoBJnK2e0kdreKVftRsFUpZHn7Gi+IXdv12US25PxVL7eNkmPTal4FV1yMS8JPZH2+s5d+RSg7hzOLJ7djy/19gcVeNLIZQp+e+vA9AjyzXhuLuMKGgdYAlbruTGI5YjTs45cS9dsMARSvVqDFi1bSgUVbii6yKJZcPSyhIvoEHjwMCxGyZuRU2Vjzt3PhCtViF7zHi4lwkzuGbGQntEz3GtWoYH5k3BwmXeVyPKySBeG40v2YSkeklDqf3LXIV23Lv+Hb/MDNtCAAUh+VaV3XPmuh0tnMmatTkEoSEn9SIsKX0aMVgL4rBFvII9Rz8YipPrHkqh/qHB6BPsmdqtSLYTi1QCoIoxxqxWPVH3FUFs4U0T8iDtELkmxExh3o3crKIeP+qeSWPr1TkFbNOf4yC0MkedxusEJXI/MQJJftmONs5MtqLiud6SazW9UtNcYT8JhXePzroOVAHSopiREUzl+8BUoCLSzVG4fM0MfA3mnvwZ/fmS+4jgH3pjJl6PcVT1xpldN/fvXEOkoLdU10SbwxWi5LSC7wIuP//ZV7LMrTBU3Zv3qPCk7XTOP5SvoQAmNDeEpoxEVQ/wm8UclnQnkt0CDHe9STfLsoddGzo84xe8rU0ICfoEsP/DgecZARyfDKbsdgkeymbQ2lPu4MuIM1uWwba4JnyJQTIl/DZTqfxavYbXyIO/u3Kc2s+qVD06SdKvSW2O1k0JJBR6f8FF3hqXoA8plwccKY8ic7dSTAr8DHIEaznB659yvZyfJInRFOQo68+RjQgv7OPcY2uxkNL9l+h82h1iSRN7JSzJR6Q4c/OvPG3OO/nloPlIO4blX776Yh3odo6xMM03Buf5wTKXuzhVGi/m6bz82RNT0tOplgWIVlS98nQxMskr1SS120mIkZfxp9NWXp0oG62Rl4zVgVZGokMm2sychsCK4WnX9LG3SO9D14sLBTBw+952yqZPgbC7ugbDz/TruLUJnAc2eZFU7qWxfsGuiIn0QjAHHNo39F79xLbowIQlEQnKhaQk52QUCSvOHxgltR5aLMnJemsLSJo1s0opE5gHddzpqBcvv4Z7ffX1DFzzE/DWqETipYCdnPY8xMLIEMp1w+MnyaC9gJa6Md/dLL9hPkhn3tLKnE5q4XbNP1hlXRw3c7kr0AmLmOOBkeVVSkAW5xdA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab8b09c6-9f9d-4860-f33b-08db86da5da2 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:43.6584 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5R5jCZdD8wkPjSWjau3Pjmh3FisCrNXLD1yx4ySLZEwG/gWy4NDIFu59y2pRmBnTNQFTDBeZEFxUJJ83H4J4gQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org phy_init() and phy_exit() will have to do more stuff under rtnl_lock() in a future change. Since rtnl_unlock() -> netdev_run_todo() does a lot of stuff under the hood, it's a pity to lock and unlock the rtnetlink mutex twice in a row. Change the calling convention such that the only caller of ethtool_set_ethtool_phy_ops(), phy_device.c, provides a context where the rtnl_mutex is already acquired. Note that phy_exit() wasn't performing the opposite teardown of phy_init(). Reverse mdio_bus_init() with ethtool_set_ethtool_phy_ops(), so that this is now the case. Signed-off-by: Vladimir Oltean --- Changes in v8: - Patch is new drivers/net/phy/phy_device.c | 8 +++++++- net/ethtool/common.c | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 0c2014accba7..ab53d10f1844 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -3451,11 +3452,14 @@ static int __init phy_init(void) { int rc; + rtnl_lock(); + ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops); + rtnl_unlock(); + rc = mdio_bus_init(); if (rc) return rc; - ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops); features_init(); rc = phy_driver_register(&genphy_c45_driver, THIS_MODULE); @@ -3477,7 +3481,9 @@ static void __exit phy_exit(void) phy_driver_unregister(&genphy_c45_driver); phy_driver_unregister(&genphy_driver); mdio_bus_exit(); + rtnl_lock(); ethtool_set_ethtool_phy_ops(NULL); + rtnl_unlock(); } subsys_initcall(phy_init); diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 5fb19050991e..f5598c5f50de 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -665,9 +665,8 @@ const struct ethtool_phy_ops *ethtool_phy_ops; void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops) { - rtnl_lock(); + ASSERT_RTNL(); ethtool_phy_ops = ops; - rtnl_unlock(); } EXPORT_SYMBOL_GPL(ethtool_set_ethtool_phy_ops); From patchwork Mon Jul 17 15:27:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315959 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F17CAC15A for ; Mon, 17 Jul 2023 15:28:10 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2040.outbound.protection.outlook.com [40.107.20.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ADFC1710; Mon, 17 Jul 2023 08:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mI2rUfuuJjNpVoTbLC/T7Y1GLK2i54VReUK9DNrIUscasmSPoBKfXJQPW4a2EeeOQAzl2kc3t5XnZTI+UDdJNHLjaLSl2THo9ZIxzN01JZTdQ5RMHcfo9aBRVkYpB1Px+HBJmBeAt7MYqPeQurwuViM0jftJ7v0Fe39tRAg9R84UTom5+wIVJEfB3H1wLbdZ3nsaYq5lydn0VwqeSjSY8zvRMTMYruO0ED+uoIbSWw+K62lutyZuydU/fA2zj5Z+JW3x4YE0G+PoIol9CEhFEW49azM18rv7MnmJeHZ84fxYlm+noqwsMswjZtRaks8b1LyBBO1bv/zIp0plqhJhDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xUgpC8b6GWi5ys60SQGjyFsEvn/6TqMCm35reK7DuHk=; b=MRLQ6n07TgdEyp4glYe3NrBNk1mjj0AcqsPW9UqmBpAQxkNsAHeeUj1xvv40iWPxH0VT5S/uyQYZU6XVLahYTc7iG6q79WjdyTP4NNFEkHqoKmu0pmCVhjpxecEKqpEenTnCdxeIzblpFejgPdmVMTwzFMy6RCxyr1s8umaPH6lP+DXwB6d+ZzY83jFucAGeWZDCkBC/BLuCbDYOKFwTa7RSzrpRm9oZbB7hbyILpzL0PcdnYMFaiZOzknk9L2vtrJbD/U6S40cDHb8DsmMKdbjv3Ukh0622xKEuzsVvcMwqokQWwoTOYstp++A2hstiRJ3dZhJ5LLlgiFI7hCoiUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xUgpC8b6GWi5ys60SQGjyFsEvn/6TqMCm35reK7DuHk=; b=eNVvw6jxfNYakjlbs1ywUbODZ+TVCr4NhdjdY2Dz4Yc3r47MwCFPbJPz3SeIHIUnY6jiDe/E9/bQ/WCzkHCA0/MITCRj9vnc1DvJcA+uY2WGntTGzKPpDEtSMNwd9W28vaNUrqam0hsKjj600kdLf6H5u0rOgHqGf3FIC5OW5Cg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:45 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:45 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 11/12] net: phy: provide phylib stubs for hardware timestamping operations Date: Mon, 17 Jul 2023 18:27:08 +0300 Message-Id: <20230717152709.574773-12-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: 666d5023-6d35-4b59-7eab-08db86da5ed6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: omQ6S65nEhHvDXqAwrNp8Fps0V/N8rjJ3mBlv6DbBUCwluX60yuULmflpmofl/uEwsjIj2++92+AEN9MxsgdGuD0Xlx4V1YTVnAfokzAT8ZuFqHqZVhIcLAsCu3c4+FJpuSpxIP86wsZ3PjDaGUr8denIh+5KwplPmSuLs5DNavKLIFL1cKxjDyItQBY9fLE9JpJJu557wFhkNYyoTiM0SKgw3ipXnoicYhR5ExaqFPjt9qTIoL9UK14FqdKrt8zCB1USR3KigdHlwNqOkJzV+cMOCuh7lS4BVhu/kTJ5g1o+hvB3D1dwGk6QtUoSw/+MZAEjgrwxs663XLI8Wfo4HRoD3OkUS+zENR/VR0H5phi3xL8THg1YnIjNe4pHjobm3UNAUNywsTf0TmnS93vvx+YKLoXf2zRc73sKLoLAVEOhGMj7lUFwvlOd95XeHo196l1bLJ8Vn/m7lJ8mh26ZLYjgikn2RN1DWOU/0fFFrw66P0i4djPsX7PS/YYxGowaE/4w5hcaE/IY3UuhIC5j3N2hX8yTgmujBZKt6drazpokMEfYcoDBkAJMLE1cl5Zdmqo8FaOxPWfgLOcRQJkg4lM3dVU/ZvWDj8vhizxmdjrtRIYs/fjVzsVGAtnLQZ0 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(451199021)(2906002)(38100700002)(86362001)(6512007)(83380400001)(2616005)(1076003)(186003)(26005)(6506007)(38350700002)(5660300002)(36756003)(8676002)(8936002)(7416002)(44832011)(7406005)(66556008)(478600001)(6486002)(54906003)(52116002)(6666004)(316002)(41300700001)(66476007)(6916009)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5m7JCTKAcmPMCJRik1F+pWivERBAwWU8Jm2llUAv5XiTfNq/h+io5U/AaHPf9Z1HEFWxjFp4ekU6+6SHlgHYpIuAlX9cfsE3l62S4/okmBtTue1dTjDeXbCnTXgDylV466wC2k+B6zlM7jqBGl0NtyWRvOhzi8BvTVoiZIZN6F7mX6kbW4y3/qOrQ92tvTfaMYUVelrXFT7ucyI+78iuC1DHFe/unXDHQMWdA/Mn7U6KbxEJW7o5XWg25V4NJjiU6N3I1t+6gdxluRnmnWEK+C9I3Dddso48relfQDvcvk4WXWWfQIzIBSPT8V/o7avQKQxCg43CRhbPFCymvZilYrAv/0Ea+6DZfoSRuXcD9IS+IKplh4gU4ppGTqWCeoFAI1m90dWibqU/nqZ6ikQI5keqGj0uZv4TMk+w49Iq3ZnK/TIse7aLstwMHEe127gcB8qBt/bJv87MxQVXaFdK11DSdzCd6I7qx3Mbt3IboeDPhizL7kt7tc0MqeSWXml0EY/FkkThwSQ6Uu4pG6tv94Ln5kILaDTLdWJGU2I4RlYMhBu40CSQ6OuGiyV0T/vKI9MYqFmHuXcILdZbfxaIo4Bjxr4Y2BCUwqo+pZnJ2FA4iplhVJ3utvoO+NXCCUH3gi69oYA8LEE/PoNj+52k79VLp67BxajxuimncLY0ErKVroIr1j3UlODofJr8ZG04APMVTYKlqD1dwlkk6REWzjvj/h+Ms8+OYuBVaA/AkuJI8rf8NgKrlV8M2JBck16feq4Xyyo+hy/xRYsgi1lDozwzbBdhvRKZIBdi3lv0uvHOIogC0nGr2bf9jTpoY2IiuyFw5FrSq/pZSiDs4nZ3gBoTH3+11LHK7TVkJCVC+fgaP9I+FuaVuTIsQFfHec1mdPeGcZNlyxrrPpokfKbw9w+s4X+To1lLTsovgdrEi3SZ7/hARk6yaWh9PJYivNHNRcpvsRB1UyaV+1rGjdQOiGkFe1wlvgAVziaMCKKSkZ2qIUYRsrYhkJrkGYe5DxAiyLBfoJt44qs/B4z6NW6TSdwV7JHcrVYtgObEUP6dzJUqNbkqBh1qYCmEO69FBkrjk3lLNg5yopVilDzL+G2fknyiXEgQByLCWdzLZ7aGNgzhxwojJ5qWuW5IPuzJPzbTSkC6aXQh0x8QriOWjfe2NDeWYedHON3Y8Ld/U3OeJhCEffR2bzS2jfbSVHdIRB95m1Ij7rl8XKRJPLL9gX1Hg8WVwV9fnvrQQs1jbonroZZzz3y1r+HDg1NzAptbcjETPiyliran0SuKi+GeXrko1Xr5fzrsA+iGdoH/sKENCRGbws1r6+71DzO7uc8kFkj/LhmKsaczPgs4tDImLHP6UoYQTOYDqvPcwnk96J8hi3FFCZeLRIcCBnE51rZxKnbcTH/CUdbX4PRm16cQz3LYa0x7crCbRBMxahR2iIWh6ZwK8s3RjaxLJcXYBuQKtSs/PdBO/XlQDajl+JE6pQfBSsv/I4P/NWa8DrNetgH7wKd0XQeuyMLkdeiJuTxWp0JciKrGrKyVhnegPx8lt7Ja/lAYi2TOyfF/gemYnmpoNToOW75VfteTRJLaxNm2iOtxKwjzmNkkovIMN5VhmD+OyQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 666d5023-6d35-4b59-7eab-08db86da5ed6 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:45.7425 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +jHGc42/uE2DCy6w0i6c1wepS0FXzodMv85BX0qMd4SwyUywNVhozWldt2No/Ej8jzc/cebKTCZsYKU/VpAfHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org net/core/dev_ioctl.c (built-in code) will want to call phy_mii_ioctl() for hardware timestamping purposes. This is not directly possible, because phy_mii_ioctl() is a symbol provided under CONFIG_PHYLIB. Do something similar to what was done in DSA in commit 5a17818682cf ("net: dsa: replace NETDEV_PRE_CHANGE_HWTSTAMP notifier with a stub"), and arrange some indirect calls to phy_mii_ioctl() through a stub structure containing function pointers, that's provided by phylib as built-in even when CONFIG_PHYLIB=m, and which phy_init() populates at runtime (module insertion). Note: maybe the ownership of the ethtool_phy_ops singleton is backwards, and the methods exposed by that should be later merged into phylib_stubs. Signed-off-by: Vladimir Oltean --- Changes in v8: - Patch is new drivers/net/phy/Makefile | 2 ++ drivers/net/phy/phy.c | 34 ++++++++++++++++++++++++++++++++++ drivers/net/phy/phy_device.c | 18 ++++++++++++++++++ include/linux/phy.h | 7 +++++++ 4 files changed, 61 insertions(+) diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 2fe51ea83bab..5b5b0d300220 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -14,6 +14,8 @@ endif # dedicated loadable module, so we bundle them all together into libphy.ko ifdef CONFIG_PHYLIB libphy-y += $(mdio-bus-y) +# the stubs are built-in whenever PHYLIB is built-in or module +obj-y += stubs.o else obj-$(CONFIG_MDIO_DEVICE) += mdio-bus.o endif diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index bdf00b2b2c1d..8aec8e83038c 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -455,6 +455,40 @@ int phy_do_ioctl_running(struct net_device *dev, struct ifreq *ifr, int cmd) } EXPORT_SYMBOL(phy_do_ioctl_running); +/** + * __phy_hwtstamp_get - Get hardware timestamping configuration from PHY + * + * @phydev: the PHY device structure + * @config: structure holding the timestamping configuration + * + * Query the PHY device for its current hardware timestamping configuration. + */ +int __phy_hwtstamp_get(struct phy_device *phydev, + struct kernel_hwtstamp_config *config) +{ + if (!phydev) + return -ENODEV; + + return phy_mii_ioctl(phydev, config->ifr, SIOCGHWTSTAMP); +} + +/** + * __phy_hwtstamp_set - Modify PHY hardware timestamping configuration + * + * @phydev: the PHY device structure + * @config: structure holding the timestamping configuration + * @extack: netlink extended ack structure, for error reporting + */ +int __phy_hwtstamp_set(struct phy_device *phydev, + struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack) +{ + if (!phydev) + return -ENODEV; + + return phy_mii_ioctl(phydev, config->ifr, SIOCSHWTSTAMP); +} + /** * phy_queue_state_machine - Trigger the state machine to run soon * diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index ab53d10f1844..08c162b7e6be 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -3448,12 +3449,28 @@ static const struct ethtool_phy_ops phy_ethtool_phy_ops = { .start_cable_test_tdr = phy_start_cable_test_tdr, }; +static const struct phylib_stubs __phylib_stubs = { + .hwtstamp_get = __phy_hwtstamp_get, + .hwtstamp_set = __phy_hwtstamp_set, +}; + +static void phylib_register_stubs(void) +{ + phylib_stubs = &__phylib_stubs; +} + +static void phylib_unregister_stubs(void) +{ + phylib_stubs = NULL; +} + static int __init phy_init(void) { int rc; rtnl_lock(); ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops); + phylib_register_stubs(); rtnl_unlock(); rc = mdio_bus_init(); @@ -3483,6 +3500,7 @@ static void __exit phy_exit(void) mdio_bus_exit(); rtnl_lock(); ethtool_set_ethtool_phy_ops(NULL); + phylib_unregister_stubs(); rtnl_unlock(); } diff --git a/include/linux/phy.h b/include/linux/phy.h index 11c1e91563d4..6710508e8c97 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -298,6 +298,7 @@ static inline const char *phy_modes(phy_interface_t interface) #define MII_BUS_ID_SIZE 61 struct device; +struct kernel_hwtstamp_config; struct phylink; struct sfp_bus; struct sfp_upstream_ops; @@ -1954,6 +1955,12 @@ int phy_ethtool_set_plca_cfg(struct phy_device *phydev, int phy_ethtool_get_plca_status(struct phy_device *phydev, struct phy_plca_status *plca_st); +int __phy_hwtstamp_get(struct phy_device *phydev, + struct kernel_hwtstamp_config *config); +int __phy_hwtstamp_set(struct phy_device *phydev, + struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack); + static inline int phy_package_read(struct phy_device *phydev, u32 regnum) { struct phy_package_shared *shared = phydev->shared; From patchwork Mon Jul 17 15:27:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13315951 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 991BDBA56 for ; Mon, 17 Jul 2023 15:28:02 +0000 (UTC) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2068.outbound.protection.outlook.com [40.107.6.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F24891704; Mon, 17 Jul 2023 08:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MizlmyA6xQx1ai2ajNNjKSCHaU6eWXcu/fXD6sOg3Hw7OVcDZzr/6OwKl8gfbPEgs/rabo2QKtqQz3/GIQ7oEfaE9FxNWAccUNFwUC/A02cC2mBXfAR0dgSIid0xrWo1B/pTBVeOuziGpwG4tlp2rP5P+WnSIHDwgVVQN3KhEp4CoiudsmbxPfZZXTSEtrq1HTIZ0ddSyyuNMhPTFMC2e3KePBcevlmLc6V5au1imqAlQY5TcKuGwWsYb28oTJV3qOIm14a/kSrRVHkwJeyIuw9uI8Ig8/zRscMaYdmLm8ZoTmcSAdDBi1LrryEt4yk/qgH4CYPHY7fVOvmewUrPag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=o47KaUMkf2K17437PM92Lmueuo24U0vLwPfJrAXZu3k=; b=b2heMhbTvy1A1+ft147f31WfC+ZWsD4LZ0e5R2xGX0YrUhylWnZrkTknREi2n6DBFA7QiDJwMYpu1nzkT79cOPFtkm67N1uu4VBsEO7hg4bKhXiJ+QbM5HNO8yVvl+suDUTIpyzEiRzDxY10lZA3P71kolkfBKZhWlEPDiedz3gjjlbNLRvuK2KzVdSfz2R5FHxYcu9AChFcUl6Fq6IBRkTvUe65I/WHOV21H1jjnmM4iG3QysWunPXtStlzfXLdSnXIyH+QzWmsviq5iKi1UssfIOkFEE0lV/cMLQzGat0WTVJfzbOdHSDuUUqPbmXyIDR1EgHB/Ym1069Hhu5xZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o47KaUMkf2K17437PM92Lmueuo24U0vLwPfJrAXZu3k=; b=oIRE3KdihC7JgBt9jLbAst5RDuCea41C7NRZhfZ4H5DABr1JZm/Z/ECiQZAzcR9AI1sezbAeMozrtiwTHzO3eWNAXPHdYXPHg8jRKLhIFBXm7PXB70awB+KtCvHCI+mWy1rQZSlTVzvXh10FKSbQ4Tp7rNqqlc0J0zQ9xKW6uhw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by PAXPR04MB8846.eurprd04.prod.outlook.com (2603:10a6:102:20d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 15:27:48 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c680:1128:9d53:24ae%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 15:27:47 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 net-next 12/12] net: remove phy_has_hwtstamp() -> phy_mii_ioctl() decision from converted drivers Date: Mon, 17 Jul 2023 18:27:09 +0300 Message-Id: <20230717152709.574773-13-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717152709.574773-1-vladimir.oltean@nxp.com> References: <20230717152709.574773-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VE1PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:803:118::24) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|PAXPR04MB8846:EE_ X-MS-Office365-Filtering-Correlation-Id: b8a7bed6-d3a6-4f44-933a-08db86da6013 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H3Ou4e7AUfuBqfYlhykos3XyhL1iWGjsX4Ld8oFf+kK6p2IPJENu5uorB/EQn/HHj6Pp3oE26YJWE7k3zOirzpvYQjNk5XsIpLLPE6u0BDZqNnqfZst2oIiEyzC7cQvQw+DFQGolrZv6165YTylGn5qOvAXUznrHq93wZ84vokMGeowdrAw/m9fDYv/I4xxLoJzR3UM0Owhj3d+XYciVXY25+CA0VEU0dyEB4pOvqGW33kPGxvDompi0zZo4/0MbggKbR4+hnGyZWgL8alygtYA//rLqqPdC7S0zx/aAqWbBClF0XmV6kR4RhsBfSULZBa8gAziQm6tJd6z2iuP9TGzPAtZ9zBzIfmUQsL8SUSlCgapY6Cfcxiiwu8HZ3W1++RdFZrp7sSEFxE5gDTrB8yLNn1GJe2pGjLc98iqv3QcS1PUdLAmvhfar5xvelIwH67peG8L6o/kssiM3FC5VgmYnJfMhIVktgfbSCRRSYmWRpg3xuqhigxU84RWLtNEmMrif4MtpD/20Ya1M7xEDRPk9aGRLKkI0veDZ+Vq5BXYCVVl7tnyqIW9z1iBqlM0L4X+08EjWNTL+kRdcbCwuPHEk2p1tv5FgxTAf6DfOkZ8TExQzD4+fIXSQwyTcxBuN X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(366004)(136003)(396003)(39860400002)(451199021)(316002)(6916009)(66946007)(86362001)(4326008)(38350700002)(38100700002)(6666004)(6512007)(6486002)(26005)(478600001)(8936002)(44832011)(8676002)(7416002)(2616005)(7406005)(41300700001)(66556008)(1076003)(66476007)(186003)(52116002)(6506007)(5660300002)(54906003)(83380400001)(2906002)(36756003)(30864003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ++TndgQloDDO+VZvXDe4WDj8lzPfDa9WvR9Pzi9gqu+Q6nQtvO03iOL/wOEpDsxTdLOPnK8dn5iBRQOr5PTi5tijAiSabS4t65bKHsgLAw0XMssD//p4p7LO33CyR9Q76kh1FQYO53A+BRY0HxqktI/FbBGTG4vvvVA7faFOY5RemCymSVVgKaZY5oPGoFI1yUF8SsuA+xUbuq//TiX0Qxy2NmvtS/hDp7hussxxt3WtxaEMrEO3uWIVJMipb/HmPJXGGko5MQ2lWiLqC87lDE82fXrmvdQdZhgGoKKJGSR4h8/vv/5UzgLXLelV/htFhqTF3X2Hg7uI4y0gM8eMzHKIM4rbO68coXzEVJGzloYBCg0qLpcZfuU753BRA5zShHfMW4CWVd3RDujdliOiAmORhzI7h3vLnlP/sFKVQB47T4en4v2/O5uvwj23WJLC52NdwyNNddSG7b/bi22Q7y4yAjEonw1NzTVoB0IziANCZEQoRvFgZkH0QS4PvMT2shqjbuzhAY7H+OYO0BFeYj2ORBR2107IIe7A0pPEzLwDOUIYbFIilavq6+tCLTSbxFGTV7uiczxXMHkgVIhi9ZSHENY51dk9vDaTYparL/NUuPECgPMRKRghsHl5MTcNuQiyVRTo5QDCXz0DB63pWXmtQSA+ALr74227onwJTy3tJqHWxMxLu2fXAqZnitjAkg8eUIsC69HdFpURxE7cr9RMxy5xCECM43XUEdRsjnOe4KXf4mzPRqyK9vPLIT/d4rjpkP2bdMjjjUd5yEhZW2TMNBC+hWwzEhd0H5yFIcgoZiqle1uWM97FxWE3V7ttAjrO2ErVkhhBny79z9hLJEy6o4hky4gxtHKX1pbKzx/+XcspXUfsT95j60m4A8lyFG4PDgGQtJMuBDkC6Ae2PDAsPY9DQSxg710MWVymUH6FpJFkns3tJfjMrV2tWyvadPPHIYkAdUvo4DmVOTJye+c1G278g9MUeG46raBBbzLBV/ONhmVQlpwxoQtsP89RU02RfPZP/AST6Nywv+vcw7MNLPI0ttEQY3hnbmkBv5s70HvKnO73nKkRkP+RShHW4v7yeWabh57uhvqbuoRSnassYJ6Sp+UcKIcvvzu5M76hzpQZy+FvTUKuX1k0Efdjj3XK71Uh/Vjyp7rhwNLmGr5hHdAQ43u2Wfhtxd4FSXui3JiNHf5KeF5iAoP1jjA7lzTy2AJDt9JKU2daYHLnviPSxJkFBYvcMAIVyrwBKYEos4l5pTV+SFuo4Bv1XgNQeNB8iPs0AJQhEV8kDr59ZagOKxKffqM0JBa5qIfcsg7vye/ijEuEHqyotpiXs0VVyt1fFB0z8iogsyLZyutm+zEsRQGnfFisdn4Td3diKRXRM5H+rpYtPT/CmnJNXPneanF33gZWHqWzW/jqUp2Kk7we0O05owE/nJzsQIgnSZWZ/HD9HdJYM6tXVsbreXxR0K0xZReR0I3nApE9r3Jd8NeIHExoNkIUsuY1nwTiQCLIJJed7mNbuZlfeNOCOfEM1LxlSVGhjNdldnsIAEbGROlQzM3o4Qj4VvLNP6rarawxcTBEzhDEMnKrFQkpER+UqAtFKLrEqP3QZAqnjvj5gQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8a7bed6-d3a6-4f44-933a-08db86da6013 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 15:27:47.8075 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yzHL8muEAA0Hr9AM1kJDg3jV8DYo8oz3LtE+onjPn3k+hGQI979jImOsJwtaNGJsxNznlwdYi4jZv/4j9U3L5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8846 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org It is desirable that the new .ndo_hwtstamp_set() API gives more uniformity, less overhead and future flexibility w.r.t. the PHY timestamping behavior. Currently there are some drivers which allow PHY timestamping through the procedure mentioned in Documentation/networking/timestamping.rst. They don't do anything locally if phy_has_hwtstamp() is set, except for lan966x which installs PTP packet traps. Centralize that behavior in a new dev_set_hwtstamp_phylib() code function, which calls either phy_mii_ioctl() for the phylib PHY, or .ndo_hwtstamp_set() of the netdev, based on a single policy (currently simplistic: phy_has_hwtstamp()). Any driver converted to .ndo_hwtstamp_set() will automatically opt into the centralized phylib timestamping policy. Unconverted drivers still get to choose whether they let the PHY handle timestamping or not. Netdev drivers with integrated PHY drivers that don't use phylib presumably don't set dev->phydev, and those will always see HWTSTAMP_SOURCE_NETDEV requests even when converted. The timestamping policy will remain 100% up to them. Signed-off-by: Vladimir Oltean Reviewed-by: Jacob Keller Tested-by: Horatiu Vultur --- Changes in v8: - Replace direct phy_mii_ioctl() calls with indirect phy_hwtstamp_get() and phy_hwtstamp_set() stubs. - Add missing kerneldoc for kernel_hwtstamp_config :: source. Changes in v7: - Patch is new drivers/net/ethernet/freescale/fec_main.c | 8 -- .../ethernet/microchip/lan966x/lan966x_main.c | 25 ++--- .../ethernet/microchip/sparx5/sparx5_netdev.c | 6 -- include/linux/net_tstamp.h | 16 ++++ include/linux/netdevice.h | 4 + net/core/dev_ioctl.c | 91 +++++++++++++++++-- 6 files changed, 117 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 28c5f8f8106d..c66864f9d9ee 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3904,10 +3904,6 @@ static int fec_hwtstamp_get(struct net_device *ndev, struct kernel_hwtstamp_config *config) { struct fec_enet_private *fep = netdev_priv(ndev); - struct phy_device *phydev = ndev->phydev; - - if (phy_has_hwtstamp(phydev)) - return phy_mii_ioctl(phydev, config->ifr, SIOCGHWTSTAMP); if (!fep->bufdesc_ex) return -EOPNOTSUPP; @@ -3922,10 +3918,6 @@ static int fec_hwtstamp_set(struct net_device *ndev, struct netlink_ext_ack *extack) { struct fec_enet_private *fep = netdev_priv(ndev); - struct phy_device *phydev = ndev->phydev; - - if (phy_has_hwtstamp(phydev)) - return phy_mii_ioctl(phydev, config->ifr, SIOCSHWTSTAMP); if (!fep->bufdesc_ex) return -EOPNOTSUPP; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index b0f614fbc5db..ef23153a48f1 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -454,9 +454,6 @@ static int lan966x_port_hwtstamp_get(struct net_device *dev, { struct lan966x_port *port = netdev_priv(dev); - if (phy_has_hwtstamp(dev->phydev)) - return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCGHWTSTAMP); - if (!port->lan966x->ptp) return -EOPNOTSUPP; @@ -472,21 +469,26 @@ static int lan966x_port_hwtstamp_set(struct net_device *dev, struct lan966x_port *port = netdev_priv(dev); int err; + if (cfg->source != HWTSTAMP_SOURCE_NETDEV && + cfg->source != HWTSTAMP_SOURCE_PHYLIB) + return -EOPNOTSUPP; + err = lan966x_ptp_setup_traps(port, cfg); if (err) return err; - if (phy_has_hwtstamp(dev->phydev)) { - err = phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCSHWTSTAMP); - if (err) + if (cfg->source == HWTSTAMP_SOURCE_NETDEV) { + if (!port->lan966x->ptp) + return -EOPNOTSUPP; + + err = lan966x_ptp_hwtstamp_set(port, cfg, extack); + if (err) { lan966x_ptp_del_traps(port); - return err; + return err; + } } - if (!port->lan966x->ptp) - return -EOPNOTSUPP; - - return lan966x_ptp_hwtstamp_set(port, cfg, extack); + return 0; } static const struct net_device_ops lan966x_port_netdev_ops = { @@ -814,6 +816,7 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p, NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_TC; dev->hw_features |= NETIF_F_HW_TC; + dev->priv_flags |= IFF_SEE_ALL_HWTSTAMP_REQUESTS; dev->needed_headroom = IFH_LEN_BYTES; eth_hw_addr_gen(dev, lan966x->base_mac, p + 1); diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c b/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c index e01d3b1e17e0..705a004b324f 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c @@ -216,9 +216,6 @@ static int sparx5_port_hwtstamp_get(struct net_device *dev, struct sparx5_port *sparx5_port = netdev_priv(dev); struct sparx5 *sparx5 = sparx5_port->sparx5; - if (phy_has_hwtstamp(dev->phydev)) - return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCGHWTSTAMP); - if (!sparx5->ptp) return -EOPNOTSUPP; @@ -234,9 +231,6 @@ static int sparx5_port_hwtstamp_set(struct net_device *dev, struct sparx5_port *sparx5_port = netdev_priv(dev); struct sparx5 *sparx5 = sparx5_port->sparx5; - if (phy_has_hwtstamp(dev->phydev)) - return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCSHWTSTAMP); - if (!sparx5->ptp) return -EOPNOTSUPP; diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h index 03e922814851..eb01c37e71e0 100644 --- a/include/linux/net_tstamp.h +++ b/include/linux/net_tstamp.h @@ -5,6 +5,11 @@ #include +enum hwtstamp_source { + HWTSTAMP_SOURCE_NETDEV, + HWTSTAMP_SOURCE_PHYLIB, +}; + /** * struct kernel_hwtstamp_config - Kernel copy of struct hwtstamp_config * @@ -15,6 +20,8 @@ * a legacy implementation of a lower driver * @copied_to_user: request was passed to a legacy implementation which already * copied the ioctl request back to user space + * @source: indication whether timestamps should come from the netdev or from + * an attached phylib PHY * * Prefer using this structure for in-kernel processing of hardware * timestamping configuration, over the inextensible struct hwtstamp_config @@ -26,6 +33,7 @@ struct kernel_hwtstamp_config { int rx_filter; struct ifreq *ifr; bool copied_to_user; + enum hwtstamp_source source; }; static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg, @@ -44,4 +52,12 @@ static inline void hwtstamp_config_from_kernel(struct hwtstamp_config *cfg, cfg->rx_filter = kernel_cfg->rx_filter; } +static inline bool kernel_hwtstamp_config_changed(const struct kernel_hwtstamp_config *a, + const struct kernel_hwtstamp_config *b) +{ + return a->flags != b->flags || + a->tx_type != b->tx_type || + a->rx_filter != b->rx_filter; +} + #endif /* _LINUX_NET_TIMESTAMPING_H_ */ diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index ca3bcf2257c0..0d8a7ac67cf1 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1724,6 +1724,9 @@ struct xdp_metadata_ops { * @IFF_TX_SKB_NO_LINEAR: device/driver is capable of xmitting frames with * skb_headlen(skb) == 0 (data starts from frag0) * @IFF_CHANGE_PROTO_DOWN: device supports setting carrier via IFLA_PROTO_DOWN + * @IFF_SEE_ALL_HWTSTAMP_REQUESTS: device wants to see calls to + * ndo_hwtstamp_set() for all timestamp requests regardless of source, + * even if those aren't HWTSTAMP_SOURCE_NETDEV. */ enum netdev_priv_flags { IFF_802_1Q_VLAN = 1<<0, @@ -1759,6 +1762,7 @@ enum netdev_priv_flags { IFF_NO_ADDRCONF = BIT_ULL(30), IFF_TX_SKB_NO_LINEAR = BIT_ULL(31), IFF_CHANGE_PROTO_DOWN = BIT_ULL(32), + IFF_SEE_ALL_HWTSTAMP_REQUESTS = BIT_ULL(33), }; #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index d0223ecd6f6f..72e077022348 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -252,6 +253,30 @@ static int dev_eth_ioctl(struct net_device *dev, return ops->ndo_eth_ioctl(dev, ifr, cmd); } +/** + * dev_get_hwtstamp_phylib() - Get hardware timestamping settings of NIC + * or of attached phylib PHY + * @dev: Network device + * @cfg: Timestamping configuration structure + * + * Helper for enforcing a common policy that phylib timestamping, if available, + * should take precedence in front of hardware timestamping provided by the + * netdev. + * + * Note: phy_mii_ioctl() only handles SIOCSHWTSTAMP (not SIOCGHWTSTAMP), and + * there only exists a phydev->mii_ts->hwtstamp() method. So this will return + * -EOPNOTSUPP for phylib for now, which is still more accurate than letting + * the netdev handle the GET request. + */ +static int dev_get_hwtstamp_phylib(struct net_device *dev, + struct kernel_hwtstamp_config *cfg) +{ + if (phy_has_hwtstamp(dev->phydev)) + return phy_hwtstamp_get(dev->phydev, cfg); + + return dev->netdev_ops->ndo_hwtstamp_get(dev, cfg); +} + static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) { const struct net_device_ops *ops = dev->netdev_ops; @@ -266,7 +291,7 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) return -ENODEV; kernel_cfg.ifr = ifr; - err = ops->ndo_hwtstamp_get(dev, &kernel_cfg); + err = dev_get_hwtstamp_phylib(dev, &kernel_cfg); if (err) return err; @@ -283,6 +308,59 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) return 0; } +/** + * dev_set_hwtstamp_phylib() - Change hardware timestamping of NIC + * or of attached phylib PHY + * @dev: Network device + * @cfg: Timestamping configuration structure + * @extack: Netlink extended ack message structure, for error reporting + * + * Helper for enforcing a common policy that phylib timestamping, if available, + * should take precedence in front of hardware timestamping provided by the + * netdev. If the netdev driver needs to perform specific actions even for PHY + * timestamping to work properly (a switch port must trap the timestamped + * frames and not forward them), it must set IFF_SEE_ALL_HWTSTAMP_REQUESTS in + * dev->priv_flags. + */ +static int dev_set_hwtstamp_phylib(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) +{ + const struct net_device_ops *ops = dev->netdev_ops; + bool phy_ts = phy_has_hwtstamp(dev->phydev); + struct kernel_hwtstamp_config old_cfg = {}; + bool changed = false; + int err; + + cfg->source = phy_ts ? HWTSTAMP_SOURCE_PHYLIB : HWTSTAMP_SOURCE_NETDEV; + + if (!phy_ts || (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) { + err = ops->ndo_hwtstamp_get(dev, &old_cfg); + if (err) + return err; + + err = ops->ndo_hwtstamp_set(dev, cfg, extack); + if (err) { + if (extack->_msg) + netdev_err(dev, "%s\n", extack->_msg); + return err; + } + + changed = kernel_hwtstamp_config_changed(&old_cfg, cfg); + } + + if (phy_ts) { + err = phy_hwtstamp_set(dev->phydev, cfg, extack); + if (err) { + if (changed) + ops->ndo_hwtstamp_set(dev, &old_cfg, NULL); + return err; + } + } + + return 0; +} + static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) { const struct net_device_ops *ops = dev->netdev_ops; @@ -314,12 +392,9 @@ static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) if (!netif_device_present(dev)) return -ENODEV; - err = ops->ndo_hwtstamp_set(dev, &kernel_cfg, &extack); - if (err) { - if (extack._msg) - netdev_err(dev, "%s\n", extack._msg); + err = dev_set_hwtstamp_phylib(dev, &kernel_cfg, &extack); + if (err) return err; - } /* The driver may have modified the configuration, so copy the * updated version of it back to user space @@ -362,7 +437,7 @@ int generic_hwtstamp_get_lower(struct net_device *dev, return -ENODEV; if (ops->ndo_hwtstamp_get) - return ops->ndo_hwtstamp_get(dev, kernel_cfg); + return dev_get_hwtstamp_phylib(dev, kernel_cfg); /* Legacy path: unconverted lower driver */ return generic_hwtstamp_ioctl_lower(dev, SIOCGHWTSTAMP, kernel_cfg); @@ -379,7 +454,7 @@ int generic_hwtstamp_set_lower(struct net_device *dev, return -ENODEV; if (ops->ndo_hwtstamp_set) - return ops->ndo_hwtstamp_set(dev, kernel_cfg, extack); + return dev_set_hwtstamp_phylib(dev, kernel_cfg, extack); /* Legacy path: unconverted lower driver */ return generic_hwtstamp_ioctl_lower(dev, SIOCSHWTSTAMP, kernel_cfg);