Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2852829rwd; Mon, 22 May 2023 05:26:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4YHRgGGkUmqZ1vMzsIWhwqZ+EM4auNqsJ+1gC0peCGgVx0Hi0hnq4oGCbeurBxe1dsefqW X-Received: by 2002:a05:6a20:938e:b0:10b:7243:c212 with SMTP id x14-20020a056a20938e00b0010b7243c212mr4483824pzh.42.1684758418957; Mon, 22 May 2023 05:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684758418; cv=none; d=google.com; s=arc-20160816; b=0PJs1oGGo0Vx4FRlLa6OKVVOrAV4Zsvrr/k4lEc/wxMbOEdytCLdJNssluyaLBjKJG zgB4QhhntsjVVq/iXW0neU05enOZ2QYGIyn8vBNHWqSAm8WS1lkarAKj6HMvYcVcx0Vn wzK480qtyYxVRxmZu+Py/JPQXd3HSDRwEGsuaV+r9bl6p9MzINAgHFVw7tRVHBzUHByh UYvfoUw2uxCCqgHvHccFD6gveYo1VtkEp3PihUSuAplRzNVBqUhpRn2mi7NX8Ov6WBgz uPprGEvBgVnCKovRRTLIygv1vsSWEe1TD3sSEIkce2SCgyBCz4vAD9XMOGmp09nl/cRq huQQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WPQmGsbOPIy9wPstzIBKggjPnfoTVHg5cTQKcX+NZkA=; b=Or5j7YExrtEvr5R5DQFfVtuQyEedZt5f+ug02dzmPj+Ap6+XGLGNSzdb1kA+Fk7VoP 7j5k5VmAkfThrjqz1ATZHkqBgqpws+GtE4eHRZT0EBVjJFuHkn7otocGK/hu5Bqhqe50 Mpva3SW51RCEcVhY7yl/nsGFID9BvzE2lgM8xey8CZNmq1jKcCQsYWI0eb2CqJFDz7PB m+qvO4qdhMoHYg0TFRLlnFtOWqrhtCaUCOR4M5v1yLFagJJJ6Qz0ounpJkXz1MnqEs+f ZQo4yncXUqtBxEdaFiTSFNd4pYNZak7CfqcfVaBKyAvXqRRBAM7j1i/GiaAq72zZ5v0/ hucA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fx8uQ3GY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t20-20020a63b254000000b0053413a8294fsi3135219pgo.899.2023.05.22.05.26.46; Mon, 22 May 2023 05:26:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fx8uQ3GY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233869AbjEVMUo (ORCPT + 99 others); Mon, 22 May 2023 08:20:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232730AbjEVMTN (ORCPT ); Mon, 22 May 2023 08:19:13 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 252CDE0; Mon, 22 May 2023 05:17:06 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-96fb45a5258so345352666b.2; Mon, 22 May 2023 05:17:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684757824; x=1687349824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WPQmGsbOPIy9wPstzIBKggjPnfoTVHg5cTQKcX+NZkA=; b=fx8uQ3GYpgRsHyL6dZtp9/EUw/x7/v2NuHFv1Fck7p8yRfR2+KxdHdS5+fR38zWink u+GlxOuK0KczPi5WbnTYbRL/djIGyQCkePQ89NngPwMQrudlDBnolgm5G1oHaaakwPxm LR18qpdlQquOZsYlAP13riLQOeBZ5xFNOeqsVdkV5FqPP5uW3kNAmGbgf65HJMSzIA3+ tctwHZWLyvC375W34wStBbYMSPLAYfXt6os0VVaa/u4faCPf4UXTTxxExUGJacy1d33h /q/zSFPZ9UGNYK3EqCIi4jfsxexgNbYc4gvHZWE/t1kROWGvinFlre0rvJv31MtoOhLW zDGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684757824; x=1687349824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WPQmGsbOPIy9wPstzIBKggjPnfoTVHg5cTQKcX+NZkA=; b=HuE/TdzaRQYATkJtteabmzMQJJyXQGOtwpU5LkLwmtYa2eWl/5VwaV16tXx97FWdon ziFInOKXDuPkP0Zq1m/tnj7X8vfhIoacx4DOOeW0QVitMkX83x/4V/r1Ld0bzwbomo1D +kxWLq9hHoFYda+gCRciqPTacW11H/WnHM0G6vibxtQtRiujMFJRep2KkBihmnitttbE OVmGKXcFkGuS4eDJZdCp/BDwUjeHgCgoGJU9Cw8TRJ1BvV4z3MUqtndZgWXd3RL3x0JW +VQv+fZTzaQbbqDo0qckLs98Z+idjYn9UTnvQLRrLy3c7lIIQQuCs3YM8hGTI7d+K1tW BGVQ== X-Gm-Message-State: AC+VfDxPRFt9VmjbSw+D84zeYBG3s7gYsFAbiTT1F7s/yju93+TEnZ0q t/E41JqjYkp27+dEUL0DPXw= X-Received: by 2002:a17:907:8390:b0:953:37eb:7727 with SMTP id mv16-20020a170907839000b0095337eb7727mr7799238ejc.43.1684757824116; Mon, 22 May 2023 05:17:04 -0700 (PDT) Received: from arinc9-PC.. ([149.91.1.15]) by smtp.gmail.com with ESMTPSA id y26-20020a17090614da00b009659fed3612sm2999950ejc.24.2023.05.22.05.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 05:17:03 -0700 (PDT) From: arinc9.unal@gmail.com X-Google-Original-From: arinc.unal@arinc9.com To: Sean Wang , Landen Chao , DENG Qingfang , Daniel Golle , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Russell King Cc: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= , Richard van Schagen , Richard van Schagen , Frank Wunderlich , Bartel Eerdekens , erkin.bozoglu@xeront.com, mithat.guner@xeront.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH net-next 26/30] net: dsa: mt7530: properly set MT7530_CPU_PORT Date: Mon, 22 May 2023 15:15:28 +0300 Message-Id: <20230522121532.86610-27-arinc.unal@arinc9.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230522121532.86610-1-arinc.unal@arinc9.com> References: <20230522121532.86610-1-arinc.unal@arinc9.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Arınç ÜNAL The MT7530_CPU_PORT bits represent the CPU port to trap frames to for the MT7530 switch. There are two issues with the current way of setting these bits. ID_MT7530 which is for the standalone MT7530 switch is not included. When multiple CPU ports are being used, the trapped frames won't be received when the DSA conduit interface, which the frames are supposed to be trapped to, is down because it's not affine to any user port. This requires the DSA conduit interface to be manually set up for the trapped frames to be received. Address these issues by implementing ds->ops->master_state_change() on this subdriver and setting the MT7530_CPU_PORT bits there. Introduce the active_cpu_ports field to store the information of active CPU ports. Correct the macros, MT7530_CPU_PORT is bits 4 through 6 of the register. Any frames set for trapping to CPU port will be trapped to the numerically smallest CPU port which is affine to the DSA conduit interface that is set up. To make the understatement obvious, the frames won't necessarily be trapped to the CPU port the user port, which these frames are received from, is affine to. This operation is only there to make sure the trapped frames always reach the CPU. Tested-by: Arınç ÜNAL Co-developed-by: Vladimir Oltean Signed-off-by: Vladimir Oltean Signed-off-by: Arınç ÜNAL --- drivers/net/dsa/mt7530.c | 33 ++++++++++++++++++++++++++++----- drivers/net/dsa/mt7530.h | 6 ++++-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 0b513e3628fe..cd16911fcb01 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -958,11 +958,6 @@ mt753x_cpu_port_enable(struct dsa_switch *ds, int port) mt7530_set(priv, MT753X_MFC, MT753X_BC_FFP(BIT(port)) | MT753X_UNM_FFP(BIT(port)) | MT753X_UNU_FFP(BIT(port))); - /* Set CPU port number */ - if (priv->id == ID_MT7621) - mt7530_rmw(priv, MT753X_MFC, MT7530_CPU_MASK, MT7530_CPU_EN | - MT7530_CPU_PORT(port)); - /* Add the CPU port to the CPU port bitmap for MT7531 and the switch on * the MT7988 SoC. Any frames set for trapping to CPU port will be * trapped to the CPU port the user port is affine to. @@ -2947,6 +2942,33 @@ static int mt753x_set_mac_eee(struct dsa_switch *ds, int port, return 0; } +static void +mt753x_master_state_change(struct dsa_switch *ds, + const struct net_device *master, + bool operational) +{ + struct mt7530_priv *priv = ds->priv; + struct dsa_port *cpu_dp = master->dsa_ptr; + + /* Set the CPU port to trap frames to for MT7530. There can be only one + * CPU port due to MT7530_CPU_PORT having only 3 bits. Any frames set + * for trapping to CPU port will be trapped to the numerically smallest + * CPU port which is affine to the DSA conduit interface that is set up. + */ + if (priv->id != ID_MT7530 && priv->id != ID_MT7621) + return; + + if (operational) + priv->active_cpu_ports |= BIT(cpu_dp->index); + else + priv->active_cpu_ports &= ~BIT(cpu_dp->index); + + if (priv->active_cpu_ports) + mt7530_rmw(priv, MT753X_MFC, MT7530_CPU_EN | + MT7530_CPU_PORT_MASK, MT7530_CPU_EN | + MT7530_CPU_PORT(__ffs(priv->active_cpu_ports))); +} + static int mt7988_setup(struct dsa_switch *ds) { struct mt7530_priv *priv = ds->priv; @@ -2996,6 +3018,7 @@ const struct dsa_switch_ops mt7530_switch_ops = { .phylink_mac_link_up = mt753x_phylink_mac_link_up, .get_mac_eee = mt753x_get_mac_eee, .set_mac_eee = mt753x_set_mac_eee, + .master_state_change = mt753x_master_state_change, }; EXPORT_SYMBOL_GPL(mt7530_switch_ops); diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index fd2a2f726b8a..52e5d71a04d3 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -41,8 +41,8 @@ enum mt753x_id { #define MT753X_UNU_FFP(x) (((x) & 0xff) << 8) #define MT753X_UNU_FFP_MASK MT753X_UNU_FFP(~0) #define MT7530_CPU_EN BIT(7) -#define MT7530_CPU_PORT(x) ((x) << 4) -#define MT7530_CPU_MASK (0xf << 4) +#define MT7530_CPU_PORT(x) (((x) & 0x7) << 4) +#define MT7530_CPU_PORT_MASK MT7530_CPU_PORT(~0) #define MT7530_MIRROR_EN BIT(3) #define MT7530_MIRROR_PORT(x) ((x) & 0x7) #define MT7530_MIRROR_MASK 0x7 @@ -753,6 +753,7 @@ struct mt753x_info { * @irq_domain: IRQ domain of the switch irq_chip * @irq_enable: IRQ enable bits, synced to SYS_INT_EN * @create_sgmii: Pointer to function creating SGMII PCS instance(s) + * @active_cpu_ports: Holding the active CPU ports */ struct mt7530_priv { struct device *dev; @@ -780,6 +781,7 @@ struct mt7530_priv { struct irq_domain *irq_domain; u32 irq_enable; int (*create_sgmii)(struct mt7530_priv *priv); + unsigned long active_cpu_ports; }; struct mt7530_hw_vlan_entry { -- 2.39.2