Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp3006880rdb; Tue, 13 Feb 2024 04:19:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVIwO1HTLt/RsLtZz930Bmd8EmC+Ygogc++7YMgnxCY4WV6bf7F/7wp4taHRuFAIxwAFlNn57AgXHVmvzhMyD5N9Yz+FTu7QPeXc2hs8A== X-Google-Smtp-Source: AGHT+IHJ4Z+/6ubB9jOzdXb/ZDJDCTRFYpV0oZi9/+AJz8nYZdC+LTzDbOuWMLukgl0XwKpXuqjS X-Received: by 2002:a05:6214:4105:b0:68d:4cd:cae8 with SMTP id kc5-20020a056214410500b0068d04cdcae8mr8694670qvb.61.1707826776839; Tue, 13 Feb 2024 04:19:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707826776; cv=pass; d=google.com; s=arc-20160816; b=EnnlusXi+IN7IRDD296SSbbqlhJw9ayB7BO7oP9RssGe0KvJXxubrhtMKYtpX5ksE5 sATK+mYoNxE5QAGBePUc9O3ANVL9HEo0d8jM8jAeTHNABapyCNM+C149ZAFWWeDCRrd2 OcpDHU5A6y5eEdFTBZi323KF0JQE/i4A9kzlXEUsAEllDet6+j4xDvlbaXdF+pk9ks6L Upms239k3fck8hxJlO1QJI0JSaNkmfb3POws98al4RCTPleguwxBlxMlBWWfPcG5p2R3 YWp1ciyMm/3B8LYB600uJkBqE1Rp9NVnWeRhg4oEr5Wvg/Nb/c5dzFqbnNJUFjTLVmIO UmWA== 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=jZFPOO8PDbkxFThMtNZJYdPGYD+x95l6qX7jW2E0+wY=; fh=k+xNhSlDrVyldl3pHYvuU3tQ9kl2YMvU0x/GWcAWf+M=; b=ztcbX7GqZxMyyHXUCFVzgOfhMib15pXlPuVWdySIItUD1ReP8/VWN8Dbcmgs+VUP9b c6mhknmEBSkaBuKxzRi0ZwsbG+AMw8dq1NTNFkDpIRc/7GlYKyhGpqdC0fEgfKjMpPRe sf982AS8YxnMrxW5/ehks3SniGSzw2NHJhOAiF8q8j5fIW6f0Dtt2ehI1gyCw2zkdn6y qWN927aq4SXPVdAYNB1gmn2MhIEX2JOXdsR09vNX8JfQtYCiFOgzSCuGWMSTXc8zIJZT 471gmR6v+eCG+2UQkFz4U67URGS+UiV0VWH/qC3IIgmnSslrGJMndZjUEQ0YrDnv+RDk 8qTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=gihk+qJb; 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-63495-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63495-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com X-Forwarded-Encrypted: i=2; AJvYcCWKuqlFi0GCK52NbAoz+fwREAp17el/xN1vHdeLv1p3pmi0eNUHA1R98fZfRW77ATAzp6iTqjOxlewwOL8JwQHC+sgIFx4msHsygWRYiQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jo11-20020a056214500b00b0068c8bf7a3d8si2832533qvb.334.2024.02.13.04.19.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 04:19:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63495-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=gihk+qJb; 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-63495-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63495-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 855231C22447 for ; Tue, 13 Feb 2024 12:19:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 709E83EA76; Tue, 13 Feb 2024 12:19:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="gihk+qJb" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (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 701B73D0D4; Tue, 13 Feb 2024 12:19:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707826759; cv=none; b=YRkIX0IaFdHOFMw+Rg/MBdJTRpCrFT+A8EicMmOUUaMfY+zDKjm4hrRYhXR8fdf17UGhJWrXOQOtpcLAo6aYOXns8k1SgJcWu/EZhtWOWJYzBKJiYGz4d2kAlua1QKhot9bd2sehKM56Zr4cfOyzpf8dLZVNukXjZAO/n6VFhbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707826759; c=relaxed/simple; bh=/fjyZrBDLYmTpMFfS2OHSx6WkJIwJVBJ2XSyeuGpNNs=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=lQAsPte/lFsdtxphwfxw3H7m8QtZ+2LhRnvdNMC1WJIBr37vCvICetXbWoTFWO06VPLl9XRCyN6KbtlQnNBZFNI//iY0BGszHzQ9pSlOEZ+LOGtSecyy/wlZixnyqfak6lzGH/loZEtITk9M/jtdNqn9eWtPIaw+Tz0/J1su7Sc= 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=gihk+qJb; arc=none smtp.client-ip=68.232.154.123 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=1707826757; x=1739362757; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/fjyZrBDLYmTpMFfS2OHSx6WkJIwJVBJ2XSyeuGpNNs=; b=gihk+qJbAMpusLVdgkRl0TTHTxZPxoyVT6D6b6XSlBGBQHiz7AB6rLev QGhx3NkjSOfByU7t42tFyAn0dVnbgenU/hDsGwWVQaRU1YeBxTEOT9HdN +48MAQCpgIU0I/sFhVeauKjV0hiGS3B+sfwuOgiEP7YQmiMyiUK0mAmyV lh4K3G+cY4H1Af1/wHLIGtwaxY6wc8xsTNTMifPRHVZqyGngrgHn6njmy O7OZEYFnO6UJfL3L2tgoI0MELMUZ/uQzRlSLsfLA+nHgEgKxVnjpcrD17 FNMTFFKNRIDdGuMwQragC/RT+bBb2O2EwfMky2Aak7a64WGvtnx/YmmEl 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 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 --- 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