From patchwork Tue Feb 13 12:17:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 13555065 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 9AA98C4829A for ; Tue, 13 Feb 2024 12:19:45 +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: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:In-Reply-To:References: List-Owner; bh=CF8E1QDFzCV4al0MQlzCu1WnfeqU+QUMJvoDlMHMgQo=; b=U3S6QXxWNaNos8 7K8YaRq5XgoAfTQs6jusW3sAXVQTj01tcgo3Y2kRddyDh+NYhkT9lQl0ZniYRZGLIDPwKC8Em16bw fwi6MVrmU174bqYwApRMcda/f+7JqxMp1FpMOIWYa0lCTD6cYHimXANKcscHptYeUFPVrA577ALjA TH59jXFnPce28z1nsLZIL+k08qmshmX0OFK+/PAs/4ePPNzwx7zOU+82F88jhbu5sbYjaFYvUbm0p fX8V0B5+cQ53Z3mUBYq67vj4DQQeWiiNEBunUiKgZu3TekgUhv0mFr6I0RxwM9C+Q2GyT2XxFieSb 4zKIaB7jFHBl5LuYuWDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZrl8-000000099Wj-3Ni6; Tue, 13 Feb 2024 12:19:34 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZrkv-000000099QB-3pO0 for linux-arm-kernel@lists.infradead.org; Tue, 13 Feb 2024 12:19:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1707826761; x=1739362761; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/fjyZrBDLYmTpMFfS2OHSx6WkJIwJVBJ2XSyeuGpNNs=; b=ZAwjzDC0hFVSbeO8KbDJfNKNT8SzZQkvTh/LI+H5pknW5deLKpXnoj41 SJNhn5V4SQDhpbScRjdklwD/VxQNR+TcghR33LpF5qxCTGHEdp59p1QpN EOqIrhWxlIBhWnYuAvqVodX5mI8Qs2UjLpOiowFQF+TcnXfZAMx5+oK/i 8DzomxFqO8hCXiDaemy/M1+0swQhhMvjZQaPVVb8v369Dn2AHNT55RLk0 3aFxwy0QdlXQPWmwxV23sIEBIPSNCLnoFolRJY83Y6QcvfOv4SJ0HwLjJ fbPW2AO5KrYRS8aN1yNcGj6fpqr5ahaX9kRhD02PSjRSUvIFMCluTniBn A==; X-CSE-ConnectionGUID: wLQvEHzgQYe+b74dcDn/DQ== X-CSE-MsgGUID: 2q/bPEAUQlSu9JSpAF1pdQ== X-IronPort-AV: E=Sophos;i="6.06,157,1705388400"; d="scan'208";a="16684392" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 13 Feb 2024 05:19:16 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 13 Feb 2024 05:18:45 -0700 Received: from DEN-DL-M31836.microsemi.net (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Tue, 13 Feb 2024 05:18:42 -0700 From: Horatiu Vultur To: , , , , , , , CC: , , , , , , , , Horatiu Vultur Subject: [PATCH net-next] net: sparx5: Add spinlock for frame transmission from CPU Date: Tue, 13 Feb 2024 13:17:05 +0100 Message-ID: <20240213121705.4070598-1-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240213_041922_261713_86654C2D X-CRM114-Status: GOOD ( 14.81 ) 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 Both registers used when doing manual injection or fdma injection are shared between all the net devices of the switch. It was noticed that when having two process which each of them trying to inject frames on different ethernet ports, that the HW started to behave strange, by sending out more frames then expected. When doing fdma injection it is required to set the frame in the DCB and then make sure that the next pointer of the last DCB is invalid. But because there is no locks for this, then easily this pointer between the DCB can be broken and then it would create a loop of DCBs. And that means that the HW will continuously transmit these frames in a loop. Until the SW will break this loop. Therefore to fix this issue, add a spin lock for when accessing the registers for manual or fdma injection. Signed-off-by: Horatiu Vultur Reviewed-by: Daniel Machon --- drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 1 + drivers/net/ethernet/microchip/sparx5/sparx5_main.h | 1 + drivers/net/ethernet/microchip/sparx5/sparx5_packet.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c index d1f7fc8b1b71a..3c066b62e6894 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c @@ -757,6 +757,7 @@ static int mchp_sparx5_probe(struct platform_device *pdev) platform_set_drvdata(pdev, sparx5); sparx5->pdev = pdev; sparx5->dev = &pdev->dev; + spin_lock_init(&sparx5->tx_lock); /* Do switch core reset if available */ reset = devm_reset_control_get_optional_shared(&pdev->dev, "switch"); diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h index 6f565c0c0c3dc..316fed5f27355 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h @@ -280,6 +280,7 @@ struct sparx5 { int xtr_irq; /* Frame DMA */ int fdma_irq; + spinlock_t tx_lock; /* lock for frame transmission */ struct sparx5_rx rx; struct sparx5_tx tx; /* PTP */ diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c index 6db6ac6a3bbc2..ac7e1cffbcecf 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c @@ -244,10 +244,12 @@ netdev_tx_t sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev) } skb_tx_timestamp(skb); + spin_lock(&sparx5->tx_lock); if (sparx5->fdma_irq > 0) ret = sparx5_fdma_xmit(sparx5, ifh, skb); else ret = sparx5_inject(sparx5, ifh, skb, dev); + spin_unlock(&sparx5->tx_lock); if (ret == -EBUSY) goto busy;