From patchwork Tue Aug 1 14:28:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13336827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97CCBC00528 for ; Tue, 1 Aug 2023 14:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8X5JUekOOSWcSvXI0xZlRNi3cRepg6IhyF8KgunMH1s=; b=sU5ZSwKOW1MV6A KZg32yIXjJhCg2Zy/Sb8CCkDjb1Kt2h2SNzEVN3rs6Ck9qIIvZM9uK7hjma2NhlhaJHDOU9eaOZkV wJrAy7xHim5Fx31v62R2rO3EueNlKN+wWlFMiHLhdwIgnuJqzzZ8A5YXeGaGg9i+SN3eMU4chlr1+ DH/vPVIenuLEP6ivtF78KpFdyHCiKaidY3cmFNS+wTjvVY8flFpYN2d/Tq5M5TuiZMfLrrDkwPaZG xPbgInhxC49jWt2biWG78XzYnykvUWRtxQ/GClf4iWwQgjcNCyQTDrOx1teVADxgkJKcehCOrekXE rQYldZL6tnjrn7Jh0qPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQqNb-002aKw-2R; Tue, 01 Aug 2023 14:29:43 +0000 Received: from mail-db8eur05on20604.outbound.protection.outlook.com ([2a01:111:f400:7e1a::604] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQqNY-002aEd-1h for linux-arm-kernel@lists.infradead.org; Tue, 01 Aug 2023 14:29:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XyzobIVCKnnQ95mvig8IAi8clxe6DGhPaZuvC8aAtk/BTRa3LU46+3s517Mhzbd+5h6kY2VF3MYjQUf55f43NfV5sp8sDykOJicFJi7Xypf/fF78BhZk+tanJPCy00FUyT6AmpAatKgECq3FTVWessPIDGUKCentwVuZW0RyDFOOPZX/D9D4OlDCz2we5YGr9qMl9AL0v5jtza/3vGRSNAeMrDcy7pyC8XS9BgbMlVmDdvvZkrG6JFJjO23dCMELYBGFmWQpOaWSZEqcQbrz5vFdgzkOH1BUHDSF6EWlzjtnoAw08oAgioK8fRUsMTCCTB4n5gcXwyU17CrD2HdV5g== 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=tQYBURbKkUTmPrffjHkBTq0TVFR/uh+Uniw/AliMY9E=; b=fAlqySElJdb4pNpqoCXDDoYpTI5B+Svx+lMPwEsp5O6KQ4KONH84JOXtoPPmr9GWBP/+SY1attor4PVnjffpi/d7/5WeInUUXigZfQo6EtrWgM1sEMdU2jgvHEMC23p7/YXfskhZhcscv/wQX1xrSQYS/UkqZjDYYd4vD/IMvzk3ty6tkHjORo7QMGRH6N+r0QHFCIdfjlRVgamWxIiztfXLkJE8OmYzsrlQCdgKs4P5KolLFpxjGXRR3cET9I1EsLZY/ZYSqldo8KlhawGleFSST/uSXr9kOme/xEo0T3gk+cRQ7j5J2n7KkDAvUscoVDYcCe8GHPQmciB9vuU/XQ== 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=tQYBURbKkUTmPrffjHkBTq0TVFR/uh+Uniw/AliMY9E=; b=hq3KZJyBhZEPl5WcCzl0bXhGAPOB9PITY/UD2hMCoCB3jhIPYJbvp2PmJTCoppXwfrIaHkbxlZYa7IeDTdS27V8W5XkxTgMxr1Zsb8RDUs1ECX8B4qSPzIkQsyPE930EgxNa0jnecASj63JlPGTahkRBeF05zgjTrLNV1ht+F1s= 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 VI1PR04MB10028.eurprd04.prod.outlook.com (2603:10a6:800:1db::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Tue, 1 Aug 2023 14:29:32 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::6074:afac:3fae:6194]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::6074:afac:3fae:6194%4]) with mapi id 15.20.6631.043; Tue, 1 Aug 2023 14:29:32 +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 v9 net-next 05/12] net: bonding: convert to ndo_hwtstamp_get() / ndo_hwtstamp_set() Date: Tue, 1 Aug 2023 17:28:17 +0300 Message-Id: <20230801142824.1772134-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801142824.1772134-1-vladimir.oltean@nxp.com> References: <20230801142824.1772134-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR04CA0027.eurprd04.prod.outlook.com (2603:10a6:208:122::40) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VI1PR04MB10028:EE_ X-MS-Office365-Filtering-Correlation-Id: ad8f43fa-8c9f-4d58-15e8-08db929bb8a9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SzQUH5OfzBPLG/abrA05IwGx43r8yTc3chsrVF3yfGOLNJ3UT/aevJ/6rr49f39fqQTJRcvgM3IdZ96NIGNiUekRj6dCPEnZyui6cx0XnNK6jxiT8t4Oiuw9WtNfS6l5lD5dcIsy/vAH+8irqAr3BBIWht2dgZ56SyGppKDOUDLZ60cPhHMlAa9Re23A4Wk/7b0Q6A5aAb6pZOqwad538lKzTlQ5Rc18+n+wO332vHyKY1etO7rswHs0/5v2qgIsdsgvX4HZqjoiyb1FhS2Fh2TZswU1BT7TqylRMBLCAC4FxUr7y9G9ulnXmMkPLKdQqqTWBPntEfAlwAA7dRYS3osHtLycc/QipeHvOTWgOZRYDkEtsFlI0QXJR7XU8apHDV4XZfPQrBct07AiLyBjsyYYXg0JNxaT3S7ohxc4nOF+mSfSAbsuVdOXYsnw1XsUGO1ig9CJQKRE1FlgJxnR+ACH6oKtlVi3D7wMzmRPT5f0kX5uhiw178AoCudvfwSavPkq+AHVcLg6sj7fSqDPmoJnjReou+C6ESFLrHtDiHhjekRD0sdMgmTqZ1HJxQw0j7fo+qWrZ0JJEpcfe0P9CVipaaJKI17oCvKQAnSDhDNKwl9HEwQx/0vJfQYWjrV5 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)(136003)(376002)(346002)(39860400002)(396003)(451199021)(66476007)(66946007)(6916009)(66556008)(2906002)(4326008)(44832011)(5660300002)(7406005)(54906003)(41300700001)(316002)(7416002)(2616005)(52116002)(6486002)(6666004)(26005)(8936002)(6506007)(1076003)(8676002)(186003)(83380400001)(478600001)(36756003)(38100700002)(38350700002)(6512007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ht3CvT0P1mtOTRej/7LMRMbNvdh2LGFK7PFqxT1yQYSBCqbxgQ/Wx3AuQ9qbyKgc5UxII3CyiU+e7T1TyRmZ9nWZ7VCZp/0sorJju5OLh01QAWP+NIGCJ2BtE5UHtBvlxJNzfkVJG8LTY7bIG8hysppEp3p8+7XqOSoKHlnxaqM8FicCsz6zek9NQjwZG10QJ2mrqSC892cuIvgkC1fWEF9GgLtA6rqKnWtSb8jH3I/EjqGnvTohUobI2p2U9Kzx4mTl+1Mx138Q2U5G+HVNNL/c80NNek+jfYoYhfor7x1b9MQC+lVzPUC+8VtFoYoHr0iK5lR8DiEAEMuqqu7+v5q/ZK5+4o/BlfDi6znJVpEcFSYBG2yaL0BaQt9sUJFEyEBdAk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4mzLUO+Y38sxaZG6VGGKThzl1pMVNJlDvTNZhNaEFeiq6rtihG6GcMcd8OS/Zq8yM/d2WcTeOYIOYJ1vI/O+x3L+zFiF42pfCQzOcmVBsmRbXKPQHhcxEbpfByULgTrt92GGg6nbw6/9iJWg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad8f43fa-8c9f-4d58-15e8-08db929bb8a9 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2023 14:29:32.0453 (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: YJlzzGX76KyWHbETi8opeqX963bKptAI2++YaOPJY+9MG4i/kqSj9H49WZPWZE916yK0K62ajo2dnW9VsJFzFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10028 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230801_072940_566931_37C6542E X-CRM114-Status: GOOD ( 19.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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-v9: - 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 484c9e3e5e82..f04d4f28eb1a 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -4446,11 +4446,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); @@ -4477,44 +4472,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) @@ -5688,6 +5650,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) { @@ -5836,6 +5859,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 = {