Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3514182pxp; Tue, 8 Mar 2022 16:21:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtUWEBztATNwM2v8oseo6ZFpqtFWDRzqbVaqRFTre7dvjZ8mMCNnrWFAnoUnDVjMeHfA3f X-Received: by 2002:a17:90b:350c:b0:1bf:1dc5:1c3d with SMTP id ls12-20020a17090b350c00b001bf1dc51c3dmr7473190pjb.53.1646785281237; Tue, 08 Mar 2022 16:21:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646785281; cv=none; d=google.com; s=arc-20160816; b=AgPDqW5Z4uMEw5jPIi1C66FN156XXFLFFwL5sdgkMeCTrWlmMX18Yu05zvdjzkL1Be Rd6GP4Ox2OGCno15gSSGUd90+dQt7PJchDAhb7Jlsak/i72aWi0eAm3DGtgEaU6s+vDg R0yvdmFmP3R1v4GJHCLDfl6ye4zb2qb1Xtd0r3t92qXvzMCVFMsBMj8+DHQG43XSUiwy T3FX3uJ0cczh5vx3S6655SGU7pSI78N3sIN/8UwZWI25fsGs0OfBsqS39feOnj+AUIWq Lygtrzu6m24dBcb1AktHnimTgT2TjTo0NNyZvtQFbfA7hpcvhb0znrr9Yu93OITa1l6c FXBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=LQqVZFBgsSjFGnIQr0IAIdSfBVvESo9IS/ULpNAXL78=; b=lycnOi1gZIC5Ko/pZBzozUtmfXtpWOy/PmHzufdSHRp714OJBzJ4+WPp9kPBAjqKQF O2RqBeBJ8zMInvRpSv70IEoYjDPCA6BxHbGQ7cdy6r+Wr5e7NTQE5iI8hR1AfYZ8KYoi Yt1/UrrLFHGa2CRmWRvITvcbuSUGyhaMpHlN0vrgd9OzV88hDHYFrBa/FPUHk/AxHcEB L/peAmDmrKe9OYXOf13j7AgRelDezP3XLp4XAZJolQcoGL5/J9DbHrO7XWLKUacLdBoq Qb+n44Wvuoxpu2HYBzCZeBiwbEOwCloRALoEHd2BN/lTyclIQ/506ktovi5FKTLdwxkD Tb2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b="Fn2/+MLW"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 2-20020a630802000000b0037716e2e56bsi313520pgi.550.2022.03.08.16.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:21:21 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b="Fn2/+MLW"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8268AFDFBF; Tue, 8 Mar 2022 15:45:47 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345853AbiCHK3f (ORCPT + 99 others); Tue, 8 Mar 2022 05:29:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345848AbiCHK3e (ORCPT ); Tue, 8 Mar 2022 05:29:34 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5164942A06; Tue, 8 Mar 2022 02:28:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1646735319; x=1678271319; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ArbjmZUZ0l6WdorlwWCLAqiEYpli5Fr0XItnFGrqD60=; b=Fn2/+MLWew5DZi2vOtQ6xWqm94QRsmWLK8PJENWu3SuGSNk+Lm7Nlk/E Th2T+HJH+s8O0JkGKfdsris/m5QlIIEgQ+JgMme88x0Bnp7Qcg2MGj4P3 lzXvoXSLnlT5+lyRa6YdTo/dvL35Q/jRO3J2JKdeU7u65kJfCtGKPS0af prdL+PkinHd/IEhzxdyRSdajZt4oh+gL4blr6QcMDN085AFuZJclCiKQ/ /uPPZlySaAuszFkgYfMABw0RjA7apfPOOLDEpmWtJJlJZ9thRvygeQE7j gnKmXXjj+0zJNhFzDclRB2vmBHTO9HrUxKP9dexjvS/sGJ7mYpIYe1NYr A==; X-IronPort-AV: E=Sophos;i="5.90,164,1643698800"; d="scan'208";a="155629249" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 08 Mar 2022 03:28:38 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Tue, 8 Mar 2022 03:28:09 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Tue, 8 Mar 2022 03:28:07 -0700 From: Horatiu Vultur To: , CC: , , , Horatiu Vultur Subject: [PATCH net-next] net: lan966x: Add spinlock for frame transmission from CPU. Date: Tue, 8 Mar 2022 11:29:04 +0100 Message-ID: <20220308102904.3978779-1-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The registers used to inject a frame to one of the ports is shared between all the net devices. Therefore, there can be race conditions for accessing the registers when two processes send frames at the same time on different ports. To fix this, add a spinlock around the function 'lan966x_port_ifh_xmit()'. Signed-off-by: Horatiu Vultur --- drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 9 ++++++++- drivers/net/ethernet/microchip/lan966x/lan966x_main.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 750f2cc2f695..81c01665d01e 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -318,6 +318,7 @@ static void lan966x_ifh_set_timestamp(void *ifh, u64 timestamp) static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev) { struct lan966x_port *port = netdev_priv(dev); + struct lan966x *lan966x = port->lan966x; __be32 ifh[IFH_LEN]; int err; @@ -338,7 +339,11 @@ static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev) lan966x_ifh_set_timestamp(ifh, LAN966X_SKB_CB(skb)->ts_id); } - return lan966x_port_ifh_xmit(skb, ifh, dev); + spin_lock(&lan966x->tx_lock); + err = lan966x_port_ifh_xmit(skb, ifh, dev); + spin_unlock(&lan966x->tx_lock); + + return err; } static int lan966x_port_change_mtu(struct net_device *dev, int new_mtu) @@ -885,6 +890,8 @@ static void lan966x_init(struct lan966x *lan966x) lan_rmw(ANA_ANAINTR_INTR_ENA_SET(1), ANA_ANAINTR_INTR_ENA, lan966x, ANA_ANAINTR); + + spin_lock_init(&lan966x->tx_lock); } static int lan966x_ram_init(struct lan966x *lan966x) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 058e43531818..ae282da1da74 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -108,6 +108,8 @@ struct lan966x { u8 base_mac[ETH_ALEN]; + spinlock_t tx_lock; /* lock for frame transmition */ + struct net_device *bridge; u16 bridge_mask; u16 bridge_fwd_mask; -- 2.33.0