From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 517A229992A for ; Sat, 16 May 2026 03:47:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778903237; cv=none; b=SU59BafKGHQCyttKrGot1mm1+E2JDfuj4XIfewOsHsW+CfBCYxAh40MOFe1m6IACHgU32WVDnk3rbxOtrOkygdBFFRyuvqpJsiEtyR3OsJaqfWwVuEE1fcR2dJt/id2H51OvOaguoHsyYQtD0IltWA+7s14q8vZQAb1yAkRu7Ec= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778903237; c=relaxed/simple; bh=ftm9A2pazaly3ujJmyyLWE2kx9nI+iOOSiT6EuIzSXc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ji6dTqryW5knBdbuT9tMCJaRoD0d2CfkCj/eVyBjNTgRu6hM70ZtYVlfP4XdscdQN9Xj8Ft5vrHRdDfGVs5TTRKv3PuAiL6iHqKRa4OkyWuNu+ZRmYia4q4SFbZDXbzZkyYOZWzuMwpA6OzoxuS9ntlc7TcsIZGF/wx93VeI60k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=s7l99Ugm; arc=none smtp.client-ip=209.85.219.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s7l99Ugm" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-8b59772d441so8506196d6.0 for ; Fri, 15 May 2026 20:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778903235; x=1779508035; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Z+EAZsJ8T3e8lYxhL4SWBYpxdBnvWEKX6PuId/d7ZxY=; b=s7l99UgmRyp6Lx1D5RJq3CyaCzpH5yfw8Qi69LOSSH37lJeYiNbbEAAkyNu+13/D0j 7TawNkrSU5CjEfkhpKg/Gp0szVF993evJpuyyDRx1lRedarYXZIshte4FJokgqoj37nB RAHafF7Vs6gaaTA+z+ThyZoY0Gda8qqYvejrReZLY8Ur3WXsnpQwWDBwVigFVYfMDSp/ 75vvqexnMwMmMs3Uqjn7EA0z6K/62Ra+dOfJs9UnrN0QoSG9+58EI2TVZn7p6iZXP6FK Fx5FrS8X5d/cQkIlM5GBerWQQVJ0kIea8nwbzuJqCKO3V0Tz/KEPrZQD0HClptpsBpgd REUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778903235; x=1779508035; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Z+EAZsJ8T3e8lYxhL4SWBYpxdBnvWEKX6PuId/d7ZxY=; b=EG/vIoz5q4evL1rXM6mqvXQ1kuOCcjwSYTL+QvgGzHmY3zBYU/t0tZD1FwmTNlOojo +ienWDaZQNhgftK2jb3seAVgJqFKwCKc3NavuJd/Sfr6xXjVacz2AMovTAlwnQL3s+W9 wpR/GrtLL0hA9eECCWxqvxuzbQ5D7ky8HQR/OAoOsF+GQdlnhzRo80KAqCfExdAkXJyu Yf9hJuhyJJGJs28PI7WWQUOzM3adGgrB6G4pKpEiJxmgBlw6M7XIhNRkfCXTB5+Z6ZLj bCQvXLawUjc+r2aUZaB2YxeQhOOEB7LmKyxBEEuAsB6FRxjuuV1amu6s3lkJCjknkTnL 7jBw== X-Forwarded-Encrypted: i=1; AFNElJ+azJvlf7ycTCuHFVYGml64pVYDk3jHKniUrm2iAlWeHe0HbiokPxRZevtEtUzMubsBW2tOoH4Br6z//64=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ580qlpM+ZVqlBlwkf/W9oPJtH4jZKTIn51BdR4ed+gfusuhY 7TA8awfs6uXzOIIM3n4aOzPk3aha5EDPDaL2CtNp1zbdsvyhYkiWTdc9 X-Gm-Gg: Acq92OGSkI2VZ+NhRhxOEQaR6+6OSQ8O3IZSqopPISFSeqPlx5O5ng8BBBe0c/2Tngu L2kJ+/z1ipGGKmyOpfn7/5UT36FvL4b1SoQmjYRasTaTziUrz9gI79uko/Arz2YnvhMAcE0HWiH NFtmofCGCekZA/7ZB13mzNcv//0Z+wqeCkFHF7Ficx1A/hmo0IBYWkupq9JcCGc3Q0ow+U7BKdQ ZqQllXwJvfDctjY7lqZaeceEX2fNuy1ZeL5Sg8g7EucAqZmgCWLobhe76tLvEsefxsMT5F88BGl cfIg0HAMjxWSOaxYJ3xrhw5PH5gLBECKQvveDtXSNs4pCpHfJ+cLcGmuxIqpBUcN6YvffMFnutK wgd9NW++eWTjqxhmG/cHgqNt9jKAqVaj2sSuAUfB2r879Llqcky1gKMJmEctt0iyImBHKLD2Ttr CuGjlUq/I+rxv9pGvPJ1T1M19Fjtg99d42NMMl5ZVeJyTH8rlaqg== X-Received: by 2002:a05:6214:55c6:b0:8ca:e41:ab8 with SMTP id 6a1803df08f44-8ca0f63466bmr100980096d6.7.1778903235234; Fri, 15 May 2026 20:47:15 -0700 (PDT) Received: from tresc054937.tre-sc.gov.br ([187.65.210.13]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8c908d1d2e7sm70874546d6.16.2026.05.15.20.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 20:47:14 -0700 (PDT) From: Luiz Angelo Daros de Luca Date: Sat, 16 May 2026 00:46:18 -0300 Subject: [net-next PATCH v4 2/8] net: dsa: realtek: rtl8365mb: use dsa helpers for port iteration Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260516-realtek_forward-v4-2-8b6d6a1eefdc@gmail.com> References: <20260516-realtek_forward-v4-0-8b6d6a1eefdc@gmail.com> In-Reply-To: <20260516-realtek_forward-v4-0-8b6d6a1eefdc@gmail.com> To: Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Yury Norov , Rasmus Villemoes , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Abdulkader Alrezej , Luiz Angelo Daros de Luca X-Mailer: b4 0.15.2 Use dsa_switch_for_each_*() whenever possible. For port setup(), a new blocking setup phase was added for all ports, including unused ones, before the user and CPU port setup. CPU isolation includes all user ports as traffic was being blocked in some scenarios (suggested by Abdulkader Alrezej). The driver bails out if a DSA port is detected as the driver was not tested in a cascading setup. Suggested-by: Abdulkader Alrezej Reviewed-by: Linus Walleij Signed-off-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/rtl8365mb.c | 141 +++++++++++++++++++++++------------- 1 file changed, 91 insertions(+), 50 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c index 9cb0f0b9beb6..d1de9158870c 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -1540,18 +1540,15 @@ static void rtl8365mb_stats_setup(struct realtek_priv *priv) { struct rtl8365mb *mb = priv->chip_data; struct dsa_switch *ds = &priv->ds; - int i; + struct dsa_port *dp; /* Per-chip global mutex to protect MIB counter access, since doing * so requires accessing a series of registers in a particular order. */ mutex_init(&mb->mib_lock); - for (i = 0; i < priv->num_ports; i++) { - struct rtl8365mb_port *p = &mb->ports[i]; - - if (dsa_is_unused_port(ds, i)) - continue; + dsa_switch_for_each_available_port(dp, ds) { + struct rtl8365mb_port *p = &mb->ports[dp->index]; /* Per-port spinlock to protect the stats64 data */ spin_lock_init(&p->stats_lock); @@ -1567,13 +1564,10 @@ static void rtl8365mb_stats_teardown(struct realtek_priv *priv) { struct rtl8365mb *mb = priv->chip_data; struct dsa_switch *ds = &priv->ds; - int i; - - for (i = 0; i < priv->num_ports; i++) { - struct rtl8365mb_port *p = &mb->ports[i]; + struct dsa_port *dp; - if (dsa_is_unused_port(ds, i)) - continue; + dsa_switch_for_each_available_port(dp, ds) { + struct rtl8365mb_port *p = &mb->ports[dp->index]; cancel_delayed_work_sync(&p->mib_work); } @@ -1632,6 +1626,9 @@ static irqreturn_t rtl8365mb_irq(int irq, void *data) for_each_set_bit(line, &line_changes, priv->num_ports) { int child_irq = irq_find_mapping(priv->irqdomain, line); + if (!child_irq) + continue; + handle_nested_irq(child_irq); } @@ -1695,13 +1692,14 @@ static int rtl8365mb_irq_disable(struct realtek_priv *priv) static int rtl8365mb_irq_setup(struct realtek_priv *priv) { struct rtl8365mb *mb = priv->chip_data; + struct dsa_switch *ds = &priv->ds; struct device_node *intc; + struct dsa_port *dp; u32 irq_trig; int virq; int irq; u32 val; int ret; - int i; intc = of_get_child_by_name(priv->dev->of_node, "interrupt-controller"); if (!intc) { @@ -1727,8 +1725,8 @@ static int rtl8365mb_irq_setup(struct realtek_priv *priv) goto out_put_node; } - for (i = 0; i < priv->num_ports; i++) { - virq = irq_create_mapping(priv->irqdomain, i); + dsa_switch_for_each_available_port(dp, ds) { + virq = irq_create_mapping(priv->irqdomain, dp->index); if (!virq) { dev_err(priv->dev, "failed to create irq domain mapping\n"); @@ -1798,9 +1796,11 @@ static int rtl8365mb_irq_setup(struct realtek_priv *priv) mb->irq = 0; out_remove_irqdomain: - for (i = 0; i < priv->num_ports; i++) { - virq = irq_find_mapping(priv->irqdomain, i); - irq_dispose_mapping(virq); + dsa_switch_for_each_available_port(dp, ds) { + virq = irq_find_mapping(priv->irqdomain, dp->index); + + if (virq) + irq_dispose_mapping(virq); } irq_domain_remove(priv->irqdomain); @@ -1815,8 +1815,9 @@ static int rtl8365mb_irq_setup(struct realtek_priv *priv) static void rtl8365mb_irq_teardown(struct realtek_priv *priv) { struct rtl8365mb *mb = priv->chip_data; + struct dsa_switch *ds = &priv->ds; + struct dsa_port *dp; int virq; - int i; if (mb->irq) { free_irq(mb->irq, priv); @@ -1824,9 +1825,11 @@ static void rtl8365mb_irq_teardown(struct realtek_priv *priv) } if (priv->irqdomain) { - for (i = 0; i < priv->num_ports; i++) { - virq = irq_find_mapping(priv->irqdomain, i); - irq_dispose_mapping(virq); + dsa_switch_for_each_available_port(dp, ds) { + virq = irq_find_mapping(priv->irqdomain, dp->index); + + if (virq) + irq_dispose_mapping(virq); } irq_domain_remove(priv->irqdomain); @@ -1944,10 +1947,11 @@ static int rtl8365mb_setup(struct dsa_switch *ds) { struct realtek_priv *priv = ds->priv; struct rtl8365mb_cpu *cpu; - struct dsa_port *cpu_dp; + u32 downports_mask = 0; + u32 upports_mask = 0; struct rtl8365mb *mb; + struct dsa_port *dp; int ret; - int i; mb = priv->chip_data; cpu = &mb->cpu; @@ -1974,46 +1978,83 @@ static int rtl8365mb_setup(struct dsa_switch *ds) else if (ret) dev_info(priv->dev, "no interrupt support\n"); - /* Configure CPU tagging */ - dsa_switch_for_each_cpu_port(cpu_dp, ds) { - cpu->mask |= BIT(cpu_dp->index); + /* Start with all ports blocked, including unused ports */ + dsa_switch_for_each_port(dp, ds) { + struct rtl8365mb_port *p = &mb->ports[dp->index]; - if (cpu->trap_port == RTL8365MB_MAX_NUM_PORTS) - cpu->trap_port = cpu_dp->index; - } - cpu->enable = cpu->mask > 0; - ret = rtl8365mb_cpu_config(priv); - if (ret) - goto out_teardown_irq; - - /* Configure ports */ - for (i = 0; i < priv->num_ports; i++) { - struct rtl8365mb_port *p = &mb->ports[i]; + if (dsa_port_is_dsa(dp)) { + dev_err(ds->dev, "Cascading (DSA links) not supported"); + return -EOPNOTSUPP; + } - if (dsa_is_unused_port(ds, i)) - continue; + /* Set the initial STP state of all ports to DISABLED, otherwise + * ports will still forward frames to the CPU despite being + * administratively down by default. + */ + rtl8365mb_port_stp_state_set(ds, dp->index, BR_STATE_DISABLED); - /* Forward only to the CPU */ - ret = rtl8365mb_port_set_isolation(priv, i, cpu->mask); + /* Start with all port completely isolated */ + ret = rtl8365mb_port_set_isolation(priv, dp->index, 0); if (ret) goto out_teardown_irq; /* Disable learning */ - ret = rtl8365mb_port_set_learning(priv, i, false); + ret = rtl8365mb_port_set_learning(priv, dp->index, false); if (ret) goto out_teardown_irq; - /* Set the initial STP state of all ports to DISABLED, otherwise - * ports will still forward frames to the CPU despite being - * administratively down by default. - */ - rtl8365mb_port_stp_state_set(ds, i, BR_STATE_DISABLED); - /* Set up per-port private data */ p->priv = priv; - p->index = i; + p->index = dp->index; + + /* Collect CPU ports. If we support cascade switches, it should + * also include the upstream DSA ports. + */ + if (!dsa_port_is_cpu(dp)) + continue; + + upports_mask |= BIT(dp->index); + } + + /* Configure user ports */ + dsa_switch_for_each_port(dp, ds) { + if (!dsa_port_is_user(dp)) + continue; + + /* Forward only to the CPU */ + ret = rtl8365mb_port_set_isolation(priv, dp->index, upports_mask); + if (ret) + goto out_teardown_irq; + + /* If we support cascade switches, it should also include the + * downstream DSA ports. + */ + downports_mask |= BIT(dp->index); } + /* Configure CPU tagging */ + /* If we support cascade switches, it should also include the upstream + * DSA ports. + */ + dsa_switch_for_each_cpu_port(dp, ds) { + /* Use the first CPU port as trap_port */ + if (cpu->trap_port == RTL8365MB_MAX_NUM_PORTS) + cpu->trap_port = dp->index; + + /* Forward to all user ports */ + ret = rtl8365mb_port_set_isolation(priv, dp->index, + downports_mask); + if (ret) + goto out_teardown_irq; + } + + cpu->mask = upports_mask; + cpu->enable = cpu->mask > 0; + + ret = rtl8365mb_cpu_config(priv); + if (ret) + goto out_teardown_irq; + ret = rtl8365mb_port_change_mtu(ds, cpu->trap_port, ETH_DATA_LEN); if (ret) goto out_teardown_irq; -- 2.54.0