Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4147605rwd; Sun, 11 Jun 2023 01:17:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4HbWItofykjEv9h5pkNdvlRJAWaFWs37WmWt7wUuas6pU4bZ4TZ4IOdgQmUT8jWtmxfDPU X-Received: by 2002:a17:907:9281:b0:95e:d3f5:3d47 with SMTP id bw1-20020a170907928100b0095ed3f53d47mr5839053ejc.48.1686471450269; Sun, 11 Jun 2023 01:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686471450; cv=none; d=google.com; s=arc-20160816; b=oe5RVlVonOp1l9X/TPjkg2/wzFI8kx1LmtsX+WTVtZYFYJh6TpECT5ACRyrc55fhek f4r5p2UWtZellmdtUvJfeY+D7zxmnjz9Q9xnIMX5loQqRz3tqF8yIxXx44/zMIBIKlyK ZDEUFmK0Ywl2tfjc1N2Rtxm03YWfiAR7vqJHSI+JSmQ7InZYvN5b9cH2QAC8MQQYP+rH eq71g6bF90E2eZEAq0q1CTvfsfs8lNB6GVIrcmZn6xncb/zzrXZxk08GQZs0+7U1Yzgr xDm0FyZYzCZcyw/p0SEOp/2V/H/cOFMMqBLFH2cXfeqL6Vpy3cgssDQAD+hoCxEiQMrg CfAg== 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=E8mfk1HF6L4tH///RyhbQqTPyEo53vj44BbOEOR1clM=; b=WrtmWRGl4j4YM+yDGMSuJ3Jce3EIyH0JZSXnbJ7WWVKwnE8jBep2fstxK18F+BlZa3 mviZ2zoUjkt8Ay6JoECEy7uRsGcwVvlYPksd8iZkw8kdjFnH6xJqrDgbkm5Jphk9d2pS ijnBHcwLujOdYq3PcLipIwg/pPoqNEpwJor8GtJPoJALRj8d8zkF5DV0w5AYcr44kvsV HnFUB062tWBZdaAjCwdYPl+sS40iXdSBqAA5KE0M2x+mr5U+KiYB5RprbECijXII1yLi GcvyIlcrvzzbYjB+R9WZfLEWi8wIhW/RriRaXDssde2JSPnRxaisOqJojp+IIR4qRfjn FUMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=GiCWLUvN; 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 ce17-20020a170906b25100b00965be3494fcsi3399889ejb.60.2023.06.11.01.17.05; Sun, 11 Jun 2023 01:17:30 -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=GiCWLUvN; 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 S231480AbjFKIQN (ORCPT + 99 others); Sun, 11 Jun 2023 04:16:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbjFKIQM (ORCPT ); Sun, 11 Jun 2023 04:16:12 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFD9F2D70; Sun, 11 Jun 2023 01:16:10 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f7ebb2b82cso34024475e9.2; Sun, 11 Jun 2023 01:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686471369; x=1689063369; 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=E8mfk1HF6L4tH///RyhbQqTPyEo53vj44BbOEOR1clM=; b=GiCWLUvNxgWvmtsJRAWk33c7K1+9tTJBbZRCmi7oDh91nORFu4xQP0gRIxMqx7jGO9 t44TlMeeI/yuFIKmJL4btdULtiwSrNfDRoefXhn3LzuS3SgABnM+ItiecX7+5Cjy86lS vuKVjvBmrz8fg49oOo9CS4FCKyAIFELUmCtZkDdqnmo9TOmxXg4HhMMrPWCiR8NvxRQC xNeH4noFGOyg04WpLsI4o3tJDRwIfg7q/Z8KNp7VRU9ZzeAMepcF5WmccX0tetBOoaUP DZhtNQDjUkTo6YCZIJZuBDtudhriI0mesH5XgeKUjTR1HUc4k99oSIdWoeN3Iq+O5hhg hQug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686471369; x=1689063369; 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=E8mfk1HF6L4tH///RyhbQqTPyEo53vj44BbOEOR1clM=; b=HNGDQkvZk7TZK9u82ONlqu6VxwxQv9xwswlS0Ry3KWrXC1Ts7R/nCZeDXRYHk+lx7N Y8qTFU+UBW7SkjclvGlMM6mMb7zaj0XauyIWXsaVxIfox/xxEpUxZPFRS4OcDguaz6g5 jUxOYwAzUABE7oNywAl4cHSYMTdKvrJazc88CXRkUEtQU5dX3oizATQBes4cgZZ0sUEr FSU+XlXiOW0S/z/7KAzFTMiV7oLjiZj6UeYjSEOTaP5a8Dk+BKm/iNXKF8Ym/eFFYNLl FpcOl2+8YXShKFIuduZL5esjS0ukq8qU5EvKwTYLV7C2kjck4e9FY9dZvvOJjfpVhORb wWNQ== X-Gm-Message-State: AC+VfDwfUH3a9Wn5lRPpVsUvXluGLvhXE/Y3Y1dobCmNBgDUpxITAZkK UsdzGXRs4dKs3+YfapwJap4= X-Received: by 2002:a05:600c:2310:b0:3f5:f83:4d84 with SMTP id 16-20020a05600c231000b003f50f834d84mr4490072wmo.31.1686471369274; Sun, 11 Jun 2023 01:16:09 -0700 (PDT) Received: from arinc9-Xeront.lan (178-147-169-233.haap.dm.cosmote.net. [178.147.169.233]) by smtp.gmail.com with ESMTPSA id s5-20020a7bc385000000b003f6132f95e6sm7748979wmj.35.2023.06.11.01.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 01:16:09 -0700 (PDT) From: "=?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?=" X-Google-Original-From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= To: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= , Daniel Golle , Landen Chao , DENG Qingfang , Sean Wang , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Russell King Cc: Landen Chao , Frank Wunderlich , Bartel Eerdekens , mithat.guner@xeront.com, erkin.bozoglu@xeront.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH net v2 2/7] net: dsa: mt7530: fix trapping frames with multiple CPU ports on MT7530 Date: Sun, 11 Jun 2023 11:15:42 +0300 Message-Id: <20230611081547.26747-2-arinc.unal@arinc9.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230611081547.26747-1-arinc.unal@arinc9.com> References: <20230611081547.26747-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 The CPU_PORT bits represent the CPU port to trap frames to for the MT7530 switch. This switch traps frames to the CPU port set on the CPU_PORT bits, regardless of the affinity of the user port which the frames are received from. 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. To fix this, implement ds->ops->master_state_change() on this subdriver and set the CPU_PORT bits to the CPU port which the DSA conduit interface its affine to is up. Introduce the active_cpu_ports field to store the information of the active CPU ports. Correct the macros, CPU_PORT is bits 4 through 6 of the register. Add comments to explain frame trapping for this switch. Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch") Suggested-by: Vladimir Oltean Signed-off-by: Arınç ÜNAL --- drivers/net/dsa/mt7530.c | 32 ++++++++++++++++++++++++++++---- drivers/net/dsa/mt7530.h | 6 ++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 8ab4718abb06..da75f9b312bc 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -1006,10 +1006,6 @@ mt753x_cpu_port_enable(struct dsa_switch *ds, int port) mt7530_set(priv, MT7530_MFC, BC_FFP(BIT(port)) | UNM_FFP(BIT(port)) | UNU_FFP(BIT(port))); - /* Set CPU port number */ - if (priv->id == ID_MT7621) - mt7530_rmw(priv, MT7530_MFC, CPU_MASK, CPU_EN | 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, which the frames are received @@ -3063,6 +3059,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 CPU_PORT having only 3 bits. Any frames received from + * a user port which are 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 up. + */ + if (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, MT7530_MFC, CPU_EN | CPU_PORT_MASK, CPU_EN | + CPU_PORT(__ffs(priv->active_cpu_ports))); +} + static int mt7988_pad_setup(struct dsa_switch *ds, phy_interface_t interface) { return 0; @@ -3117,6 +3140,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 e590cf43f3ae..28dbd131a535 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -41,8 +41,8 @@ enum mt753x_id { #define UNU_FFP(x) (((x) & 0xff) << 8) #define UNU_FFP_MASK UNU_FFP(~0) #define CPU_EN BIT(7) -#define CPU_PORT(x) ((x) << 4) -#define CPU_MASK (0xf << 4) +#define CPU_PORT_MASK GENMASK(6, 4) +#define CPU_PORT(x) FIELD_PREP(CPU_PORT_MASK, x) #define MIRROR_EN BIT(3) #define MIRROR_PORT(x) ((x) & 0x7) #define 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; @@ -779,6 +780,7 @@ struct mt7530_priv { struct irq_domain *irq_domain; u32 irq_enable; int (*create_sgmii)(struct mt7530_priv *priv, bool dual_sgmii); + unsigned long active_cpu_ports; }; struct mt7530_hw_vlan_entry { -- 2.39.2