Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1564482rdb; Sat, 2 Dec 2023 00:31:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXj8nF1Jv/5oMcw0kVYbL4nq38vn/twqhOMfVP4+lpePLT3OJLquITIDIiogd4g9zd+fgW X-Received: by 2002:a05:6870:c6a0:b0:1fb:75c:3ff1 with SMTP id cv32-20020a056870c6a000b001fb075c3ff1mr1362343oab.81.1701505887253; Sat, 02 Dec 2023 00:31:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701505887; cv=none; d=google.com; s=arc-20160816; b=DAEwNqt7GOxJ04/sfn9BbQSiVNZoMtp0zwiy/oqcMV2jRgy1nnv1LxSmK0A7kSp/ZH sK+JOJWnKfY4haGcWptRIIaQzx8AXOF7fA04z/RaLVDPke7qNI88qGXhqYZmQwu1ayP8 kF5EJ4X5KSUHBRzCJTby1KHaRVybacDdyc7bK2fB+GuxYgsswzJc+CNxyoG7WkmRTCvn 9bYFCcsxVYT+5qstD+muW3uSWuBiUnqefLzJ1LBHx+ZASncsykSprki5sw8eac8bwGiy SbZi1BkgTw+9lenTvNRNnniKiOZ1m90bFuKoivZyRsqtZFUnahmbAgAZZOFzQRzlgFfy cV9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=AepG7Sxs6UrlTw5J0jcbOX6uiYe5pZuBTrOV1pLs6ME=; fh=36eOmVBzPvbyNA3K3hrUShuUlCuu6eDRjhgELiPwakw=; b=Y0SItGYGTHKZzIVUho51AcoIX/Yh4HZqW1BfXTzUHJuQiU5xEBw8mR9J0WP72rYjQR yjEytYaYWVTQolsPGTYXJVlAlYl0jpMB8RWBeaXb1NrF8PJkf/sOwiUKjh1yOsCTUmL1 mUiX0nfR8nxpLEvpmK1BxtRpGFHUjDy+hk2EJox3zp8bpi/5NFgb1v+1I2x+swywL4q9 EvTTPvmUM5Old2h4Qh2ed1WP4HnuEHAKpNLFmC0SJ0QfcqEnZ3cWabSqSH+AuLjFS+6+ FdoAPgzoBAuQ1Z+FcHhnNIhdigGTouy+teMHY7IoyRJBXUmA90jSEu4ho2s/A1jkYo0K m9SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arinc9.com header.s=gm1 header.b=pxoYcgmX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arinc9.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id em21-20020a17090b015500b00263c23a5693si4660611pjb.13.2023.12.02.00.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 00:31:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@arinc9.com header.s=gm1 header.b=pxoYcgmX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arinc9.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 1063280AC45B; Sat, 2 Dec 2023 00:31:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbjLBI3y (ORCPT + 99 others); Sat, 2 Dec 2023 03:29:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbjLBI3x (ORCPT ); Sat, 2 Dec 2023 03:29:53 -0500 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C73D196; Sat, 2 Dec 2023 00:29:58 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 66A9820003; Sat, 2 Dec 2023 08:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arinc9.com; s=gm1; t=1701505797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AepG7Sxs6UrlTw5J0jcbOX6uiYe5pZuBTrOV1pLs6ME=; b=pxoYcgmX8xvCrfbGL5CbcvRtmQg/u+oFGkflBsXi9pLvQTIIG0gWUnkW2jkVsUrZkfJWwN 4beX9Ut7AitIw+I8urbjgmi5GKJkVnrsV1maxEkEmgJf/wPwIxVEsk/1WnA/3vrvgRRgH4 mq5oiyFl0Nkj8rzNV3P9tGuUqUi7LsaO9WrBgT7vFr+YpokyaCRPr2Bahk86afTvRhTul4 CAbwb9Etd/0PwIpIdu60zlzgb01rOS65pSi/Q8ldn0bc44iLgdAuYN31RVJY0EVV8ZWv0v BQ4aVE20Ueyo2mwhDdrV2y7dDT90s/DgFONEJ2OEo0/G567/3tPnYYNstmtE6A== Message-ID: Date: Sat, 2 Dec 2023 11:29:18 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next 01/15] net: dsa: mt7530: always trap frames to active CPU port on MT7530 Content-Language: en-US To: "Russell King (Oracle)" Cc: 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 , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Frank Wunderlich , Bartel Eerdekens , mithat.guner@xeront.com, erkin.bozoglu@xeront.com References: <20231118123205.266819-1-arinc.unal@arinc9.com> <20231118123205.266819-2-arinc.unal@arinc9.com> From: =?UTF-8?B?QXLEsW7DpyDDnE5BTA==?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-Sasl: arinc.unal@arinc9.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sat, 02 Dec 2023 00:31:00 -0800 (PST) On 18.11.2023 17:34, Russell King (Oracle) wrote: > On Sat, Nov 18, 2023 at 03:31:51PM +0300, Arınç ÜNAL wrote: >> + /* Set the CPU port to trap frames to for MT7530. Trapped frames will be >> + * forwarded to the numerically smallest CPU port which the DSA conduit >> + * interface its affine to is 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, MT7530_MFC, CPU_EN | CPU_PORT_MASK, CPU_EN | >> + CPU_PORT(__ffs(priv->active_cpu_ports))); > > I would be tempted to write this as: > > mask = BIT(cpu_dp->index); > > if (operational) > priv->active_cpu_ports |= mask; > else > priv->active_cpu_ports &= ~mask; > > Now, what happens when active_cpu_ports is zero? Doesn't that mean there > is no active CPU port? In which case, wouldn't disabling the CPU port > direction be appropriate, such as: > > if (priv->active_cpu_ports) > val = CPU_EN | CPU_PORT(__ffs(priv->active_cpu_ports)); > else > val = 0; > > mt7530_rmw(priv, MT7530_MFC, CPU_EN | CPU_PORT_MASK, val); > > ? In practice, it doesn't seem to matter. The CPU_EN bit enables the CPU port defined on CPU_PORT_MASK which is used for trapping frames. No active CPU ports would mean that all the DSA conduits are down. In that case, all the user ports will be down also. So there won't be any traffic. But disabling it is of course more appropriate here. > >> struct mt7530_priv { >> struct device *dev; >> @@ -786,6 +787,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; > > So this will be 32 or 64 bit in size. Presumably you know how many CPU > ports there can be, which looking at this code must be less than 8 as > CPU_PORT_MASK is only 3 bits in size. So, maybe use a u8, and check > that cpu_dp->index <= 7 ? Aren't there other mechanisms to check that cpu_dp->index is a valid port? At least with phylink_get_caps(), only ports lower than 7 will have proper interface modes allowed. Here's the code after you and Vladimir's review: static void mt753x_conduit_state_change(struct dsa_switch *ds, const struct net_device *conduit, bool operational) { struct dsa_port *cpu_dp = conduit->dsa_ptr; struct mt7530_priv *priv = ds->priv; u8 mask; int val; /* Set the CPU port to trap frames to for MT7530. Trapped frames will be * forwarded to the numerically smallest CPU port which the DSA conduit * interface its affine to is up. */ if (priv->id != ID_MT7530 && priv->id != ID_MT7621) return; mask = BIT(cpu_dp->index); if (operational) priv->active_cpu_ports |= mask; else priv->active_cpu_ports &= ~mask; if (priv->active_cpu_ports) val = CPU_EN | CPU_PORT(__ffs(priv->active_cpu_ports)); else val = 0; mt7530_rmw(priv, MT7530_MFC, CPU_EN | CPU_PORT_MASK, val); } struct mt7530_priv { [...] u8 active_cpu_ports; }; > > I would also suggest moving irq_enable after create_sgmii, to avoid > holes in the struct. Sorry, I've got no idea about this. Could you explain why would there possibly be holes in the struct with the current ordering of the members of the mt7530_priv structure? Arınç