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+mnWPXcqEKWGlKyfoZVFEOrnKoRyLT1T1U8J7d6TEcU03fMnO5jlddFIWpd4WRKg1aY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ZumpH33bZ3i/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 = {