From patchwork Fri Nov 11 21:10:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13040790 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA609C4332F for ; Fri, 11 Nov 2022 21:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234080AbiKKVKk (ORCPT ); Fri, 11 Nov 2022 16:10:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234330AbiKKVKi (ORCPT ); Fri, 11 Nov 2022 16:10:38 -0500 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2081.outbound.protection.outlook.com [40.107.247.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99CCC86D66 for ; Fri, 11 Nov 2022 13:10:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kLvsRRV4rqB9y2EV309lRURjj107TPQdLr/RPA3OpRaj9R51WYWRD0AQYfC73IMVkr1UB8OJ3ixvjDcfc5ugr2Egi8wrVvEPkEyZTOAv/6M1/iYe+7zF9xiqYc6EWEnRLv6lEmI2F9tpND+hFvLfeR23Xzj7zo8g4m+Lpxnpl1p+Mn5ind7p434IuTpwzDuygqB2zgVNhBUjMSACUgjnYopz0Bg+JPjldoYN63OnnKe9XLgbttXjsjAwxibvtDZQX6hSkh8b51aZ5T0CJJTQe8NDF4ZDC7u2VGbx/YTt1qEjE+L41MgI+mER01fw8iu6ZH/cfeNP9ffQ7f0m271D/A== 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=3wmX71NYUueparYgrUU9dVEM8uMuSqjizM96oBtmcd4=; b=YPt/yVEP1dIEEEiCAntwgL2T4BBw8+TJM+uQBAhaaDzOjYCgaiCU30tvB93x8Wn1LCqJuzdRtCxKksg+WuFkIKX7ucYsx7nV5sHV0/FD2TQaWBMjdVXjsfk1mQzrAyvw5bQpV5wtoKG4Sm2paw5ULBcu7RK2IskqnCdQAimWPLorVgApj8AHNyG6T2I0wwQl/F/dwuXCdMst/lNDRW4VkQkjml+Wd+C/V+N9nWNMeK/HM3v6knNNjD2fxWnPYWYiUlGJrMYvFKD0WuiGPRchz4/rKVE5yyRrG0pgAEoVf9Wk9CvYTZKCORuzu5Gazo12fyz4tGMUntxClwBqVmJzRw== 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=3wmX71NYUueparYgrUU9dVEM8uMuSqjizM96oBtmcd4=; b=LjELmQlHFeSXDUha6NR3lBEqZdpTxouvUNboW8Vtu2+wU90AqCO4yKYAkfyonsB+jhDDIuJlCu20ZXG0tD4mBwRYPugVMJhLIwtyw7WveSJdSoUywDUhmcUcwa9aPhNMBEga8lhNLBnIXkHhqh0dANYyewHlgQ/6/jof6uM9Gc4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by AM0PR04MB7058.eurprd04.prod.outlook.com (2603:10a6:208:195::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.15; Fri, 11 Nov 2022 21:10:34 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::9317:77dc:9be2:63b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::9317:77dc:9be2:63b%7]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 21:10:34 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Fabio Estevam , =?utf-8?q?Steffen_B=C3=A4tz?= Subject: [PATCH net] net: dsa: make dsa_master_ioctl() see through port_hwtstamp_get() shims Date: Fri, 11 Nov 2022 23:10:20 +0200 Message-Id: <20221111211020.543540-1-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: AM0PR01CA0073.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::14) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|AM0PR04MB7058:EE_ X-MS-Office365-Filtering-Correlation-Id: cf62d9bb-20a8-4824-7cf4-08dac4292c50 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5qKdoemVRskpXfFgNRz5yQWWMGmNQaUT5LrpVqYb57+Nv3BPWKBuYdEVw/0anWhThT1rgko1dQvIZF2+E7L+yOaYx+sGsrKn8FW7UCmsX3Cft/N/7arrHl3S24FOqcOj5mIemXBk9z9HUmobuzRLc66k15jbjnI0V12UvXumjhjcxyJR7tjF/bUoC+kAREkg19CMQ8HCBzwkhhoZ7SHu1odpvM/nkegDAePEC9z/jkmkWNpqklOD/AsGazjlsBzU1nt4JSo7LChZXQrXaA+H8l4GZ73tNtg2mYUVhNHU/Q8rTBIdJ2KAHFGGY+mtijU/TqmE3ofDIU2msxwCOw8bsfDUfwxyL7xySvCvKRRaz9q8rFC+0ILxilWHTgyMLSOGtJEM52RkoW0lcMzzCT8Z5P2CI+dOGBQzGLmH05kHa7p+lHFAJtMBffOPIJfeFHRbqfs9CXxWha29YZAlEN00Q1N1pixA/CkaomPUjxpMjx4nu5WHlF4hGEovIHVjuFf+9k8S6CHQxeYxGyeGNPeJR/axmQ3xvDPo5Zf4ul/1I3ezmIzYu1P2LzUq7FBmpTgg9GYruNXxQvEPmxqP+cwp+r+GmOhvSJOj3glohXJ4eLlPK/OT2g9pMKNGHqSc8GUVERc7mSVFTrqu1AONMYE5Os3eKHAOkXr5pmtEMwUYLzd9o5U8eophgEBv2M6ovepEkpeKamTeupzc51WLr+MDeCngEnpvBxK8uVRYb2Nv93c0PzFVrWQNw7XE9MYhR3rjfkq79DlWsCZj+xNIcs0Dqizx1SBUNToxC6jFVfSnhas= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(136003)(346002)(376002)(366004)(396003)(451199015)(66946007)(66556008)(66476007)(36756003)(54906003)(38100700002)(478600001)(6486002)(966005)(38350700002)(1076003)(2616005)(186003)(6916009)(316002)(52116002)(5660300002)(44832011)(26005)(6506007)(6666004)(6512007)(2906002)(7416002)(8936002)(8676002)(4326008)(86362001)(83380400001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?U38N6HoErNtMsHKotqA1Wlb6gql4?= =?utf-8?q?BhJMh7PCFXeawE3pF0x+Gvy6k0ANtlLT0sG59Xgy7zbV6rOS2pejpmT9i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?utf-8?q?ZWj/PS/54h1gtqfzUL2ThC+D7H8iMbVsM2W7sMp1V8h8oxEXuxNmOlGA2R4KEjsg1?= =?utf-8?q?HiL8Jc95WARIErJELcjqTk+kv4v1hN4e2Ci/KCEMGBtmyF64X6U4cYzuetcs02Fyq?= =?utf-8?q?5V41M2YqDq/sgOMYJmX/5DT5y7Burj5dyEO44wfGvMvPMABhU8YhIz9s50M8+6e4m?= =?utf-8?q?X9uapYveI8g4G3IHO80+cSRTPlS4OdFi1/h8VtNYsvFiNZysMe6LrT2dHM4qD1Njr?= =?utf-8?q?Sn+rJNL80zlQ3WVbwUIaeFa187b/bdqmRG1rGCutDxdxQDB7cbsKkALqKYBglSB8T?= =?utf-8?q?1WJBJbRfjAGb8z51VH7nbBIJ5LoBsevCJZ7osTNzYVG8kOPUt6KhC3uXzikrmX269?= =?utf-8?q?bz2mUOxMzmkvMFs8EhsBx3e2nj15cfG0kURV9W2Duu+jiK2anH0oSFTHSEugSM5uq?= =?utf-8?q?JuIin2F6zxx84sAE2BZI/ZhybkU8qZ6bNVPK2Sgwq9wcDPC2BHp9QWWZU9NsCQCIl?= =?utf-8?q?7R6TH/EWRpGZ6m0eTDPi6RUGbbmETps0Tx6SZFCt5GKh4dK/auT/yX6btR1vBt1F2?= =?utf-8?q?Iai3k6f1d9b/aayl8WN5ISkhhrs6ao439A=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf62d9bb-20a8-4824-7cf4-08dac4292c50 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 21:10:34.4553 (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: nu2ix0feve4ILvhYbb0RtlCoNX1uBkjzRE7yHhgHiTXeC9XO98Alpg6lIHXNmQ/J8dt6vx7DAArO6ufmJ/WEDw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7058 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There are multi-generational drivers like mv88e6xxx which have code like this: int mv88e6xxx_port_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr) { if (!chip->info->ptp_support) return -EOPNOTSUPP; ... } DSA wants to deny PTP timestamping on the master if the switch supports timestamping too. However it currently relies on the presence of the port_hwtstamp_get() callback to determine PTP capability, and this clearly does not work in that case (method is present but returns -EOPNOTSUPP). We should not deny PTP on the DSA master for those switches which truly do not support hardware timestamping. Create a dsa_port_supports_hwtstamp() method which actually probes for support by calling port_hwtstamp_get() and seeing whether that returned -EOPNOTSUPP or not. Fixes: f685e609a301 ("net: dsa: Deny PTP on master if switch supports it") Link: https://patchwork.kernel.org/project/netdevbpf/patch/20221110124345.3901389-1-festevam@gmail.com/ Reported-by: Fabio Estevam Reported-by: Steffen Bätz Signed-off-by: Vladimir Oltean Tested-by: Fabio Estevam --- net/dsa/dsa_priv.h | 1 + net/dsa/master.c | 3 +-- net/dsa/port.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 6e65c7ffd6f3..71e9707d11d4 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -210,6 +210,7 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev, extern struct rtnl_link_ops dsa_link_ops __read_mostly; /* port.c */ +bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr); void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, const struct dsa_device_ops *tag_ops); int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age); diff --git a/net/dsa/master.c b/net/dsa/master.c index 40367ab41cf8..421de166515f 100644 --- a/net/dsa/master.c +++ b/net/dsa/master.c @@ -204,8 +204,7 @@ static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) * switch in the tree that is PTP capable. */ list_for_each_entry(dp, &dst->ports, list) - if (dp->ds->ops->port_hwtstamp_get || - dp->ds->ops->port_hwtstamp_set) + if (dsa_port_supports_hwtstamp(dp, ifr)) return -EBUSY; break; } diff --git a/net/dsa/port.c b/net/dsa/port.c index 208168276995..750fe68d9b2a 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -110,6 +110,22 @@ static bool dsa_port_can_configure_learning(struct dsa_port *dp) return !err; } +bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr) +{ + struct dsa_switch *ds = dp->ds; + int err; + + if (!ds->ops->port_hwtstamp_get || !ds->ops->port_hwtstamp_set) + return false; + + /* "See through" shim implementations of the "get" method. + * This will clobber the ifreq structure, but we will either return an + * error, or the master will overwrite it with proper values. + */ + err = ds->ops->port_hwtstamp_get(ds, dp->index, ifr); + return err != -EOPNOTSUPP; +} + int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age) { struct dsa_switch *ds = dp->ds;