Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp317671rdb; Thu, 15 Feb 2024 00:34:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX2dEkudoMQkuZbRFGCFLFMNksn9ocGxA4/RuAm7nI6IwdFnc+mySshYsjiw0uZ7vjWvEcgD3NuYpkoKbi+fRs1VZQrzUEz/AQo3coE2g== X-Google-Smtp-Source: AGHT+IFZK08U4Z9cTATcpJkfQ05B8BNuPD2N00RG85KdTca+XeOd+vC/4gwqzZnAZkv2Aks5x2jG X-Received: by 2002:ad4:5f0a:0:b0:68c:c173:112a with SMTP id fo10-20020ad45f0a000000b0068cc173112amr1365010qvb.21.1707986088385; Thu, 15 Feb 2024 00:34:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707986088; cv=pass; d=google.com; s=arc-20160816; b=vJEmnFbgFhRtDRvQn+a0YHRYA7Erp8VGFsRnVu9ZAMM3PXupgbG7Qc4mH2oYQYsXSY 2gT5ZHLphnZuh/nqNBUlWr6+VFBPR3Re/mKvuyoj6UkiOx44F1KaAzdJ/Xa/gS5bFoLG UOAEyynmiO2ue/ozFuyL2lge748VccN1SNrMyjH5ZCIX168w1AIxFKYQCgY4DUFSan4d jF6QpG5/WvkXi36sPeTRnaHyIHZ44shmcaRFoRYGpaL2oeeX5+qDERA1bpcYGGCsHhrU NgO6RKauK7uwWhiR+qHnCZ30SzaDY7z3csq6dGLCr7W1PgsknA6z//NeEOLfZU6i2VDK oR7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=MIMzPHS/7kW5iyCq6+1ifX/LQoU0n3TEItZCBlk5+Mo=; fh=cMak4EYXNzixv26tbd/W/8VRG+M8XzFxcqxFkjIwCnY=; b=cPvyV5uiUFHskt2ITJBLqqyrPEuAXJHiybcANiw47Lk+I2+klGpqGzdjPzpticML4C dtmxp/kaX6fxqoL1drr23T+yoSd/+eDqQ3+ZN+N95YDx3TW4nDlqIJcaMH6Q1rWSqm9y 1RbqlgHAbbEtxPfMJgVfbqV+FgAeoTAVO9IMb3UNzSXqd+YIzn3eQZrY3njKge6GFnk6 zxLuIXtBovi6CuQb/8AXK40Y/KVQD2Mwkc2hZzMKtcTnFG2lND8QH2hmxOyubtpnD0IP P6TXLosdYkyPkKfaoF26TDEsRw4cT78ls6Igb8ZlYy4eoGVC4nCbX2tw/ip707WxQLeO KoIA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=TxGAAZCm; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-66425-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66425-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jx6-20020a0562142b0600b0068ef74704a1si949351qvb.453.2024.02.15.00.34.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 00:34:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66425-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=TxGAAZCm; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-66425-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66425-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 153D81C22F5C for ; Thu, 15 Feb 2024 08:34:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9AD10134CA; Thu, 15 Feb 2024 08:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="TxGAAZCm" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (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 F0A176138; Thu, 15 Feb 2024 08:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707986047; cv=none; b=uJNphwalOv/hCoUsqdxeDepYSZNE8fkCAEsapW0jSl/YdzIHdX/IshUOfumjPwwE2xC/ed7R4I9I0HtsJXG3CGiicyQNyu50kg+KKDr/5XSZmHc/S37b1PJvg7DbBjja2NWJ+mkGsFmjnGOscH3DXhYv5Es2g9GJmj6rfjaZxUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707986047; c=relaxed/simple; bh=1PN5B4HatVU4lz03ulC8NL9fJ0XJu/MDPjB+SmKs/Ow=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=CpScA9JHI82jOvR3OP5TCa6qcekYHHiYcAiefCIk/BnxkrWSBH3/dkCEF5U6DbP2GeivhKNTKnBv4MaYhGdLyJQFM7ollEHMcUR5/vlnO47oLDBiK7RYQnQeINYThVHGFNDE0WQkUMKsx38itOlS7+qOqUK+0OjUT7x0bZU4bnM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=TxGAAZCm; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1707986046; x=1739522046; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1PN5B4HatVU4lz03ulC8NL9fJ0XJu/MDPjB+SmKs/Ow=; b=TxGAAZCmYExn2sPDtEstudLL8eapoCxNJWxq3LjMGy/C/YzaFU0llDGu dpJqrdBNZozIIooH+oQoa5TAWMV3WOYw+bBBTig2grCuMxTDtTyVAKKiw biCRhzmQw6tCi0GgMS+xQX5VTZuRi8bAPAANTBr++MNeyQ8vUYM4gJ3bH p8bCiaP90wBx/Sp5JUl8HNGw15Pve5yli33CmUaLNuyLPMSUSnEB6W/w9 KTiwmzfCRA18fUevoPjcog1ghawOQoxwaU7s+rm7ADqVQF4I5MOw3nBKx hJf6rLVnOKv6Zqrav4zN9fkxgg8wW/2BPu0Wr+5m+L8Pn5hLlnuNYhXmO Q==; X-CSE-ConnectionGUID: 1+ZJrS8eQVCWRu3QTzhT8A== X-CSE-MsgGUID: bM0MQsLhRxaPsBiqvRBQLA== X-IronPort-AV: E=Sophos;i="6.06,161,1705388400"; d="scan'208";a="247019029" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2024 01:34:04 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 15 Feb 2024 01:33:40 -0700 Received: from DEN-DL-M31836.microsemi.net (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 15 Feb 2024 01:33:37 -0700 From: Horatiu Vultur To: , , , , , , , CC: , , , , , , , , Horatiu Vultur Subject: [PATCH net v2] net: sparx5: Add spinlock for frame transmission from CPU Date: Thu, 15 Feb 2024 09:33:33 +0100 Message-ID: <20240215083333.2139380-1-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 --- v1->v2: - target net instead of net-next --- 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; -- 2.34.1