From patchwork Wed Oct 30 09:39:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Fang X-Patchwork-Id: 13856217 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2079.outbound.protection.outlook.com [40.107.247.79]) (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 61AB91E882D for ; Wed, 30 Oct 2024 09:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730282130; cv=fail; b=CphDi4XJSbWNESP7OUlXFg7aN1Rb0bkp/Hmkh9nKfGJrz3uM5i/Q7G3rUbtwDq/WrHsDfjM1XJZTj/IM+vIPJz3DBI4f3jSsTLlEzPSvVwyehjuuu9ghn4GqIj34DotSyND6QeiTjZs766S21ckkSPGK+iRx1mmrIUeghM8UPng= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730282130; c=relaxed/simple; bh=LoUsaxQvi5J2FenkG0OgttwaDu0kjbKp1DRV2sJvJZc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=uGCAVuRuYju++/N/zHsN3il08Y2UNgfAPrXlRpEpolRx5yKqBmB0HzTLpoQafgdvGU4ass6y/TtKpLrK2lwFMDkr3rG1yfho76vdJboUwUHVLjQgCVggdWD252nBJL8i38HfNxJf0kTfM3Et3pqjOBk5sOzVTtsbwprhghDGPXs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=mFbldHw+; arc=fail smtp.client-ip=40.107.247.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="mFbldHw+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pk6yQc1NHW2Ru+6OCKtXxN4o4jeDefvcBoQkNmF3r0Zhg7f4do213cY1Dbe+fF6xwdO3YGlkBMnWv+xpGPk0dkwd82vh0xyTJIaLw8LAd9mbfadid/iM60A75rjtYs20srQrBleu0BTPw/SqDiSpIFU3vx5Qolx8YT0yQWhZuO5C0QnedYP+mIAaCn6tgWmDOBUMKteNk+viystBVRXQ+2lHB1p9qy/khQgEymK73MnGCYsDXfZ9sPH+9zOjTBvXwoF3qYiO7N2Yn+pvNGnVXrynGdlnE0bjxosCYYVz5F43K3a2VuU+9CL7CpB6TWypu34N7eu/ZCwt6cFEE8DCdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=6qGdonxkWsA0PHrlZn2YAzdO0pw9VKF0Ky5FzaXdeNQ=; b=fF6IxnIghux+x1nVfyQzLGtRPTFWUPRAx5cImSzTCsOr8aWkqSXwxITFrNZxEvHwWJo9VF1zZ1GIA0G6RLNsYKJpPpDQgb2LJY4tlXQlVWJZKy1cj5zrnCrwUEVp4gHvo5p9kDyRr2gjl06Ev0Zb5YRdgUIP2jKuFxdQrqrAYeRA/l+BO/VpdemATE9xysLzptvrGLBXYS2VIvbqidZxs5KZw3BLqXrLCSF9VZbb2Kpp9USvgbOnOZxSYquy+mSMmjSrDmxK7Exx03Pe8DOsHNtTtoLF0EDgbz6Mwwj5g3DTWy3Lbzwm5vmR96UEMbX7zHbzUPkCdCcgB2X3tpM51Q== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6qGdonxkWsA0PHrlZn2YAzdO0pw9VKF0Ky5FzaXdeNQ=; b=mFbldHw+tYgVSjEO2XNoBx959OxQ9jKXKgL2Fu6wqNuNwYpATIJZwbCmeyBKWgM8PQq8fGErqtCWiEep+ZKiMyey9DLMxEhK5jKUnsEwwOTNSPYnROysnP88Aomec8LnZfn2NQhGfxZ1W7m5cYYCjwLtnOzBPmLF6jbTmoyp8I2yJxSSnhog5dbPlJWb89kFx3dmpz81PZT4XKEk00YGM71FuzA1e9fArvreJ4j27/fWcry12YL/suqjpZqMu8RAUPUNSHQwJVbodYyAH+qRK5tNvJSMzVuBi1lgl0CltBuBwp6FwagWyoIeoAkk3AGD2w4l80C2SpmDj3e7ELtnOw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) by PA2PR04MB10347.eurprd04.prod.outlook.com (2603:10a6:102:424::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 09:55:25 +0000 Received: from PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::a7c2:e2fa:8e04:40db]) by PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::a7c2:e2fa:8e04:40db%7]) with mapi id 15.20.8093.027; Wed, 30 Oct 2024 09:55:25 +0000 From: Wei Fang To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, vladimir.oltean@nxp.com, claudiu.manoil@nxp.com, xiaoning.wang@nxp.com, Frank.Li@nxp.com, christophe.leroy@csgroup.eu, linux@armlinux.org.uk, horms@kernel.org Cc: imx@lists.linux.dev, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, alexander.stein@ew.tq-group.com Subject: [PATCH v6 net-next 07/12] net: enetc: remove ERR050089 workaround for i.MX95 Date: Wed, 30 Oct 2024 17:39:18 +0800 Message-Id: <20241030093924.1251343-8-wei.fang@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241030093924.1251343-1-wei.fang@nxp.com> References: <20241030093924.1251343-1-wei.fang@nxp.com> X-ClientProxiedBy: SG3P274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::21) To PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8510:EE_|PA2PR04MB10347:EE_ X-MS-Office365-Filtering-Correlation-Id: d03f02bc-2390-4b65-b173-08dcf8c8fa4b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|52116014|7416014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: l7kwhRFcLU6xc0clJHUHSG6vsoc3BoKxlYQavQgnedJXwWG/Q6roq80qRvlf7oJ1SGe1flS2f/uxGcNdl5IatP8e2VMv/xnG8+8EHDkUo2kPezd+pB7paBtC6H6BMKu37eEw9A6h9maj45ezR7pPpAiUj9u3TsjdW4qihmHseyxdqYs9Nq4GKxTACwnubOWLhenZ/ZNaJu/bqkUxNS1zNDjrKmS4iglSdQZttcANR1eIqbJkQkRfOX4pssMPymb3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TPwHup4q9FioJG+My0MET9idJ/NAxPkklvLIWuVwDQFDHMSoJUDIzlmBCADUb6xvlm3mb5VlE6x1J X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8510.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(52116014)(7416014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1NHb9UVewLxIq2lHqtfr80ZI7xZT8lISNXDKcdr4MsjuRTpDlxXo0lQ5O+Qz1aZqeDPM3JO0MF4G2AaAN9zDZRO3QjMikvfScE5FBBc5qqUk2AFb3KfACaCoqsUFHcoe55uSQo15gUUKHLwgluDqD+p4C1bC+iTWePfhxcbOPnsEXBZoAIsgRe0JF1lQ+ijb3qKzH2KlR3OZTtyqiY+fWtoTUgHppIzvPc34xSIT5vpBgb73UlobM+M6neRR8ykhy388dviToMDa1enVKMkAT3KLXUPFYXYAs6z3q58jQqOnmCCQgO+x3hePtv5uLsWeaHbRKWOmrkq1bhSJXgyHiqvZnOLsfInATI5JkgryzXX1T8OqCfJ0bXKRGxv0HUk134BbKmJ509gW7C8420RmmPB1wXp1RH3q9HHmqF8utaz04fgRDw3XlGV0t47kcBnRwvl5YH2ULTWXEnEBVRpKFdxz9TFtA6NK1aFqGuFDEPwzU7vlHDOxW3GIlBVNqxvnHgIt6CVHlFF14E2QTlMPY9BDVFRscnv9V7LEvh85sGzBgpELpqWwergJWRn7pvTcwvkktad++rRgjUaPv1HbWNWB0i1IZCw4+TT3o56zw6R8yJK0QzybrDUCEGTcdh87EeIP5XizKxMusr9G58mLOEI2p4szrDdenEYp5AH5jNEg4k0OEeGUEQlLbumw11+qZdn0h6PD68tOOBTBF/5s4C+fXyeVIHVggf74yxlxNTOKJVWQyc8myMZU5DMbWib2W07QoPJkTpuLBB5j5gFCDABiRW1aj9vb+eOnLWN9SDIM1wiCQ4a4AojpAueUYCc8Vg6HfOINLf3nfsiEjJrnQ8fPLWzwcxjiZT+fAZsmygj17mgaRdVqlm7+wuSGz35r5Jng0rzjkeuzAX19fiWtMWzUBvg7s8rMoffFEY49oTT1gF4aeSGm1K0iopWGop9T98qHEwz3i2+tg/NtQJpxxCoz4zQB8lvQ6tHDohYWAK1khoe4PgsHf6N9Gd1AkXjnaxekHpA0ENs1GKE0LQj9FaBsCtOhCAxkBu8TRuR64nepJQlTsfvCnVozKpRlyFfobzw0jR2B8jzjzUPWJI3ON1l2e4KNbX+6DQz0byCq3Ssz+CRMc4wPP3FAEnmWO6oNqarCKeE4Z9AT4Nov+z9tbd3n/O8MXLxaecdwFp+CGTCte9Ys7O8zTiq+qTXrKmHPUgDybQkbrYSOEQrevkqd0BLJahSWN+9vM6PMd7/Q7khMLkJ3+AlRr73rlW6+G7rxXHe+HH1ZlOQ+qpd9qeL58wRLhHuV3GVxWeeFiKaDh6dPbtLf361F2s50w04juZiK2PMTHOCEnwWdoNItKbpcWUWdtKmgTXqMAoL9dDvZygBAgRWcweStMz6j6z4ZLmwj6whi+qOu5h3a8wU/5eIsr9CDJMhQlNsw4EQ+UQ31HbE2pMyL8HnDO8PwTeIrJOD35AR0FDDNGk17t59Vbyr70Y5FvzkUhHpd1EXJ83Vlpr8v4Mt0dHKnvSeNcr73i7H673rPk8Nguw0r6Ds+beABzLS8G4pQNiHL+X8Qc5/pt8Pq8GgEKoCNs4vbjB2aQueD X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d03f02bc-2390-4b65-b173-08dcf8c8fa4b X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8510.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 09:55:25.8169 (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: ZY0pv/rcJkCUpXLCIRPIUE7aAHwK0l8Zx6Itch/t84HYCU8IfpupXaUzPLfMzumELsRrAbokkYmuOlz0aaT/zA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR04MB10347 From: Vladimir Oltean The ERR050089 workaround causes performance degradation and potential functional issues (e.g., RCU stalls) under certain workloads. Since new SoCs like i.MX95 do not require this workaround, use a static key to compile out enetc_lock_mdio() and enetc_unlock_mdio() at runtime, improving performance and avoiding unnecessary logic. Signed-off-by: Vladimir Oltean Signed-off-by: Wei Fang --- v6: 1. add helper functions to enable/disable the static key 2. disable the static key if of_mdiobus_register() returns error --- .../net/ethernet/freescale/enetc/enetc_hw.h | 34 +++++++++++++------ .../ethernet/freescale/enetc/enetc_pci_mdio.c | 28 +++++++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h b/drivers/net/ethernet/freescale/enetc/enetc_hw.h index 1619943fb263..6a7b9b75d660 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h @@ -396,18 +396,22 @@ struct enetc_hw { */ extern rwlock_t enetc_mdio_lock; +DECLARE_STATIC_KEY_FALSE(enetc_has_err050089); + /* use this locking primitive only on the fast datapath to * group together multiple non-MDIO register accesses to * minimize the overhead of the lock */ static inline void enetc_lock_mdio(void) { - read_lock(&enetc_mdio_lock); + if (static_branch_unlikely(&enetc_has_err050089)) + read_lock(&enetc_mdio_lock); } static inline void enetc_unlock_mdio(void) { - read_unlock(&enetc_mdio_lock); + if (static_branch_unlikely(&enetc_has_err050089)) + read_unlock(&enetc_mdio_lock); } /* use these accessors only on the fast datapath under @@ -416,14 +420,16 @@ static inline void enetc_unlock_mdio(void) */ static inline u32 enetc_rd_reg_hot(void __iomem *reg) { - lockdep_assert_held(&enetc_mdio_lock); + if (static_branch_unlikely(&enetc_has_err050089)) + lockdep_assert_held(&enetc_mdio_lock); return ioread32(reg); } static inline void enetc_wr_reg_hot(void __iomem *reg, u32 val) { - lockdep_assert_held(&enetc_mdio_lock); + if (static_branch_unlikely(&enetc_has_err050089)) + lockdep_assert_held(&enetc_mdio_lock); iowrite32(val, reg); } @@ -452,9 +458,13 @@ static inline u32 _enetc_rd_mdio_reg_wa(void __iomem *reg) unsigned long flags; u32 val; - write_lock_irqsave(&enetc_mdio_lock, flags); - val = ioread32(reg); - write_unlock_irqrestore(&enetc_mdio_lock, flags); + if (static_branch_unlikely(&enetc_has_err050089)) { + write_lock_irqsave(&enetc_mdio_lock, flags); + val = ioread32(reg); + write_unlock_irqrestore(&enetc_mdio_lock, flags); + } else { + val = ioread32(reg); + } return val; } @@ -463,9 +473,13 @@ static inline void _enetc_wr_mdio_reg_wa(void __iomem *reg, u32 val) { unsigned long flags; - write_lock_irqsave(&enetc_mdio_lock, flags); - iowrite32(val, reg); - write_unlock_irqrestore(&enetc_mdio_lock, flags); + if (static_branch_unlikely(&enetc_has_err050089)) { + write_lock_irqsave(&enetc_mdio_lock, flags); + iowrite32(val, reg); + write_unlock_irqrestore(&enetc_mdio_lock, flags); + } else { + iowrite32(val, reg); + } } #ifdef ioread64 diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c b/drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c index a1b595bd7993..e178cd9375a1 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c @@ -9,6 +9,28 @@ #define ENETC_MDIO_BUS_NAME ENETC_MDIO_DEV_NAME " Bus" #define ENETC_MDIO_DRV_NAME ENETC_MDIO_DEV_NAME " driver" +DEFINE_STATIC_KEY_FALSE(enetc_has_err050089); +EXPORT_SYMBOL_GPL(enetc_has_err050089); + +static void enetc_emdio_enable_err050089(struct pci_dev *pdev) +{ + if (pdev->vendor == PCI_VENDOR_ID_FREESCALE && + pdev->device == ENETC_MDIO_DEV_ID) { + static_branch_inc(&enetc_has_err050089); + dev_info(&pdev->dev, "Enabled ERR050089 workaround\n"); + } +} + +static void enetc_emdio_disable_err050089(struct pci_dev *pdev) +{ + if (pdev->vendor == PCI_VENDOR_ID_FREESCALE && + pdev->device == ENETC_MDIO_DEV_ID) { + static_branch_dec(&enetc_has_err050089); + if (!static_key_enabled(&enetc_has_err050089.key)) + dev_info(&pdev->dev, "Disabled ERR050089 workaround\n"); + } +} + static int enetc_pci_mdio_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -62,6 +84,8 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev, goto err_pci_mem_reg; } + enetc_emdio_enable_err050089(pdev); + err = of_mdiobus_register(bus, dev->of_node); if (err) goto err_mdiobus_reg; @@ -71,6 +95,7 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev, return 0; err_mdiobus_reg: + enetc_emdio_disable_err050089(pdev); pci_release_region(pdev, 0); err_pci_mem_reg: pci_disable_device(pdev); @@ -88,6 +113,9 @@ static void enetc_pci_mdio_remove(struct pci_dev *pdev) struct enetc_mdio_priv *mdio_priv; mdiobus_unregister(bus); + + enetc_emdio_disable_err050089(pdev); + mdio_priv = bus->priv; iounmap(mdio_priv->hw->port); pci_release_region(pdev, 0);