From nobody Tue Dec 2 02:04:29 2025 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 77DA134D396 for ; Fri, 21 Nov 2025 11:36:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763724976; cv=none; b=SXCDvFbNOaRyNU5RBBQI17MYNWkFc/cBIJsfBpjsi5oecIgeC67A1CmetgJpmHlcmW2LiEhIZLYJVE6CKKtjHk7cm7FHgmGVyD53tlc8Z0Sy3Ivi7H6pgoRkM6isIG5Yjx5E3x870SMicDMvhEeBJtDrjFdSErEHI1aKO/OEOEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763724976; c=relaxed/simple; bh=J9bbhlK2abRtODzOWkRv049W2G9nmFT+wPa+YCN2ze8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EGutxZck6DlrRgNPoDDdXNfZc/gMUXvBJ1N6rUGn8fOm7sbrbkbdjLWotp5hGc43VdFW8R0XUQn6fWPFiFJZBOB6yAl41VZL7jY3qq7Z8iARcyEaxrGmkGs52uC1Hp1ydcr4DiNebEQSVFE1/CpA/yScVbfW6PsFXz1ZmtIQuu8= 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=lZFpOWqi; arc=none smtp.client-ip=209.85.128.48 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="lZFpOWqi" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-47789cd2083so11736955e9.2 for ; Fri, 21 Nov 2025 03:36:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763724971; x=1764329771; darn=vger.kernel.org; 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=Qu2kzCH7a9rdHz1PcQb+OvB7oiG265tCyETgvREK4Pg=; b=lZFpOWqiH4ECwnBabIfhUIKOfrK5+MQ/VuoGrwVDWN6b5jkWBA7pwzksh1L3HvZ8mD 7cyR1eqqmiRZIv27dV3IBqKbrBcITHgACfxicrtB82DHHxEOPwQ5acSl0Jado2QEHdaM d6FHc1wWGlDWWyj/wmkCmSsFH5S+PFZ8dQdDdIzX4QA5BRuAtI8ttlYAYRno8HYwxina MEatwBTkcUEuKfSKemZn7NrQ1qc7FP92VYLsbzdKMnoNO8Due/Gk5oaid4GAQNU8BCqu +idmTT9AoucpemXds3sSSNG+v2AYQ0l4Sjd19ZNEooHDWHIfoN7OlswEpN2gnB7DCCiN xUlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763724972; x=1764329772; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Qu2kzCH7a9rdHz1PcQb+OvB7oiG265tCyETgvREK4Pg=; b=BTGteG/o3F/9nqDYmDCb0NZ7hod9Nu9VZA5rGhTMxuRfF57hWNGYk58HZvHF/xOcTd VNYHAWCFYlk762DoJzvZZ0vKtTWjsADkw27U+SCFOU72WejhNs+XZ4WJaxBhHGJB0mnx 00+3m33n3ngs9tEKDnKCxkRHCAAholFt48j5cqepW4iA0p+fSAbphu/YgKj106swt7S9 2VHPRu20ZSN/MPce3Htlu/x2dIhejidodaRKoeUh2h932rZTxAFfLxZqoO37jWzW/ies YDO1+g442JZ58Y5oHt5NApGiSNvqclhq6wiL4N6TGzfQB6eF7H7IA31i0qf/boil/WRZ Xrvw== X-Forwarded-Encrypted: i=1; AJvYcCXgdL+IYjZEnfGEOa/A7uYsijuL4m7j0UXs7xdE8UQIQm5MZfFTtVB/u6haRtIK5TCZvb99IPdGjMbTH/c=@vger.kernel.org X-Gm-Message-State: AOJu0YxoBeaqMrAslldFgEyjXnSoo3btswFlrse7jC6I6uC7lGqBf75C /AjPXJAx3LjCPlot+YitnBfC8nUxRaOLks0ah8m5VB0dqgzGIOQi+/gD X-Gm-Gg: ASbGnct6Q2Q95Sh4GVWwKR+9yfSuyKkgLTlRZE9ccoHM/ESKBoCv1R7BwpwAoflwor/ P5RUhKsboWOBrHmIT/tzGmsW1ELvufYFsAhIQzaPVyg4QhKRvFKBV0Yf6LDQRsVO1L5PnQ3RgKD v6R5Puexe32qHSyq/WygyBAaIfhu9KD5mYDjP9kWa5opaHQyyRv3u1TIaSKQBM/HLW1L+NQ9MIZ NpO9Cs6Hxm2zDkuxMCOhridLHHXRndItc3T2WgyFbb+Y+GclYDYCWHDy38L7UenHDvfgJ8h80y2 a1jk9dY1IkeU+LTWAHM3LY7n95ltY7eOpMmUEVI+VquaN9y7hygGcNMP8BcLP7Nf/lKgxHSxbz4 pws31XS7PMH62YdiBRBcRiEffWoPALUe4239vLq0/gZqjkQBsrp7V2nQ1y1Iwr0lDeYJSGQOaiC zVQwSBSC8vGcoXA2ZedFTepPx2OgUx7M0UcYI= X-Google-Smtp-Source: AGHT+IHJfGnMJvpbU4mjRm3yacg24pgKSDc6DAnZqzokWG1QDvI/YfVxDvtrLFX3uGvN42B9PR/hpA== X-Received: by 2002:a05:600c:8b16:b0:475:dd8d:2f52 with SMTP id 5b1f17b1804b1-477c115dc85mr15823345e9.32.1763724971434; Fri, 21 Nov 2025 03:36:11 -0800 (PST) Received: from iku.Home ([2a06:5906:61b:2d00:9cce:8ab9:bc72:76cd]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477bf3558d5sm38732465e9.1.2025.11.21.03.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 03:36:10 -0800 (PST) From: Prabhakar X-Google-Original-From: Prabhakar To: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Simon Horman , Philipp Zabel , Russell King , Geert Uytterhoeven , Magnus Damm Cc: linux-renesas-soc@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar Subject: [PATCH net-next 07/11] net: dsa: rzn1-a5psw: Make switch topology configurable via OF data Date: Fri, 21 Nov 2025 11:35:33 +0000 Message-ID: <20251121113553.2955854-8-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251121113553.2955854-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20251121113553.2955854-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Move the switch topology description-the number of ports and the CPU-port index-out of hard-coded constants and into SoC-specific OF match data. The driver previously assumed a fixed 5-port layout with the last port acting as the CPU port. That assumption does not hold for newer Renesas variants, and embedding it in the code made the driver inflexible and error-prone. Introduce a small a5psw_of_data structure carrying both the total number of ports and the CPU-port identifier, and rely on this data everywhere the driver previously used fixed values. This ensures that port loops, PCS allocation, management-port setup, and bridge bookkeeping all reflect the actual hardware configuration. Making these attributes runtime-selectable allows the driver to support RZ/T2H and RZ/N2H SoCs which use different port counts and CPU-port assignments-without rewriting common logic or forking the driver, while preserving correct behaviour on existing RZN1 systems. Signed-off-by: Lad Prabhakar --- drivers/net/dsa/rzn1_a5psw.c | 26 +++++++++++++++++--------- drivers/net/dsa/rzn1_a5psw.h | 17 ++++++++++++++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/drivers/net/dsa/rzn1_a5psw.c b/drivers/net/dsa/rzn1_a5psw.c index 99098bc06efe..d957b6d40f05 100644 --- a/drivers/net/dsa/rzn1_a5psw.c +++ b/drivers/net/dsa/rzn1_a5psw.c @@ -382,13 +382,14 @@ static void a5psw_port_bridge_leave(struct dsa_switch= *ds, int port, struct dsa_bridge bridge) { struct a5psw *a5psw =3D ds->priv; + unsigned int cpu_port =3D a5psw->of_data->cpu_port; =20 a5psw->bridged_ports &=3D ~BIT(port); =20 a5psw_port_set_standalone(a5psw, port, true); =20 /* No more ports bridged */ - if (a5psw->bridged_ports =3D=3D BIT(A5PSW_CPU_PORT)) + if (a5psw->bridged_ports =3D=3D BIT(cpu_port)) a5psw->br_dev =3D NULL; } =20 @@ -924,20 +925,21 @@ static void a5psw_vlan_setup(struct a5psw *a5psw, int= port) static int a5psw_setup(struct dsa_switch *ds) { struct a5psw *a5psw =3D ds->priv; + unsigned int cpu_port =3D a5psw->of_data->cpu_port; int port, vlan, ret; struct dsa_port *dp; u32 reg; =20 - /* Validate that there is only 1 CPU port with index A5PSW_CPU_PORT */ + /* Validate that there is only 1 CPU port with index matching cpu_port */ dsa_switch_for_each_cpu_port(dp, ds) { - if (dp->index !=3D A5PSW_CPU_PORT) { + if (dp->index !=3D cpu_port) { dev_err(a5psw->dev, "Invalid CPU port\n"); return -EINVAL; } } =20 /* Configure management port */ - reg =3D A5PSW_CPU_PORT | A5PSW_MGMT_CFG_ENABLE; + reg =3D cpu_port | A5PSW_MGMT_CFG_ENABLE; a5psw_reg_writel(a5psw, A5PSW_MGMT_CFG, reg); =20 /* Set pattern 0 to forward all frame to mgmt port */ @@ -1147,7 +1149,7 @@ static void a5psw_pcs_free(struct a5psw *a5psw) { int i; =20 - for (i =3D 0; i < ARRAY_SIZE(a5psw->pcs); i++) { + for (i =3D 0; i < a5psw->of_data->nports - 1; i++) { if (a5psw->pcs[i]) miic_destroy(a5psw->pcs[i]); } @@ -1174,7 +1176,7 @@ static int a5psw_pcs_get(struct a5psw *a5psw) goto free_pcs; } =20 - if (reg >=3D ARRAY_SIZE(a5psw->pcs)) { + if (reg >=3D a5psw->of_data->nports - 1) { ret =3D -ENODEV; goto free_pcs; } @@ -1223,7 +1225,8 @@ static int a5psw_probe(struct platform_device *pdev) if (IS_ERR(a5psw->base)) return PTR_ERR(a5psw->base); =20 - a5psw->bridged_ports =3D BIT(A5PSW_CPU_PORT); + a5psw->of_data =3D of_device_get_match_data(dev); + a5psw->bridged_ports =3D BIT(a5psw->of_data->cpu_port); =20 ret =3D a5psw_pcs_get(a5psw); if (ret) @@ -1268,7 +1271,7 @@ static int a5psw_probe(struct platform_device *pdev) =20 ds =3D &a5psw->ds; ds->dev =3D dev; - ds->num_ports =3D A5PSW_PORTS_NUM; + ds->num_ports =3D a5psw->of_data->nports; ds->ops =3D &a5psw_switch_ops; ds->phylink_mac_ops =3D &a5psw_phylink_mac_ops; ds->priv =3D a5psw; @@ -1310,8 +1313,13 @@ static void a5psw_shutdown(struct platform_device *p= dev) platform_set_drvdata(pdev, NULL); } =20 +static const struct a5psw_of_data rzn1_of_data =3D { + .nports =3D 5, + .cpu_port =3D 4, +}; + static const struct of_device_id a5psw_of_mtable[] =3D { - { .compatible =3D "renesas,rzn1-a5psw", }, + { .compatible =3D "renesas,rzn1-a5psw", .data =3D &rzn1_of_data }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, a5psw_of_mtable); diff --git a/drivers/net/dsa/rzn1_a5psw.h b/drivers/net/dsa/rzn1_a5psw.h index 81be30d6c55f..d1b2cc5b43e6 100644 --- a/drivers/net/dsa/rzn1_a5psw.h +++ b/drivers/net/dsa/rzn1_a5psw.h @@ -195,8 +195,7 @@ #define A5PSW_aCarrierSenseErrors 0x924 =20 #define A5PSW_VLAN_TAG(prio, id) (((prio) << 12) | (id)) -#define A5PSW_PORTS_NUM 5 -#define A5PSW_CPU_PORT (A5PSW_PORTS_NUM - 1) +#define A5PSW_MAX_PORTS 4 #define A5PSW_MDIO_DEF_FREQ 2500000 #define A5PSW_MDIO_TIMEOUT 100 #define A5PSW_JUMBO_LEN (10 * SZ_1K) @@ -231,6 +230,16 @@ union lk_data { struct fdb_entry entry; }; =20 +/** + * struct a5psw_of_data - OF data structure + * @nports: Number of ports in the switch + * @cpu_port: CPU port number + */ +struct a5psw_of_data { + unsigned int nports; + unsigned int cpu_port; +}; + /** * struct a5psw - switch struct * @base: Base address of the switch @@ -238,6 +247,7 @@ union lk_data { * @clk: clk_switch clock * @ts: Timestamp clock * @dev: Device associated to the switch + * @of_data: Pointer to OF data * @mii_bus: MDIO bus struct * @mdio_freq: MDIO bus frequency requested * @pcs: Array of PCS connected to the switch ports (not for the CPU) @@ -254,8 +264,9 @@ struct a5psw { struct clk *clk; struct clk *ts; struct device *dev; + const struct a5psw_of_data *of_data; struct mii_bus *mii_bus; - struct phylink_pcs *pcs[A5PSW_PORTS_NUM - 1]; + struct phylink_pcs *pcs[A5PSW_MAX_PORTS]; struct dsa_switch ds; struct mutex lk_lock; spinlock_t reg_lock; --=20 2.52.0