🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19657

Re: [PATCH net-next v5 15/24] net: dsa: rzn1-a5psw: Get switch info via OF data

#19657
From: Clement Leger
Date: Fri, 20 Nov 2026 07:02
205 lines
15422 bytes

On 11/20/26 01:25, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> 
> The driver previously assumed a fixed 5-port layout and derived the CPU
> port and number of PCS instances from this. Newer Renesas variants use
> different port counts. Although the CPU port remains the last port, the
> fixed port/PCS topology hard coded in the driver no longer matches all
> hardware.
> 
> Introduce an a5psw_of_data struct holding the per SoC switch info, and
> use this match data in place of the previously embedded constants. This
> makes the port loops, PCS allocation, management-port setup, and other
> topology dependent code reflect the switch layout selected by the
> compatible string.
> 
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> ---
> v4->v5:
> - No change
> 
> v3->v4:
> - Added return value check for of_device_get_match_data
> 
> v2->v3:
> - Fixed typo in commit message: swicth -> switch
> 
> v1->v2:
> - Updated commit message
> - Renamed A5PSW_MAX_PORTS macro to A5PSW_MAX_NUM_PCS
> ---
>   drivers/net/dsa/rzn1_a5psw.c | 31 ++++++++++++++++++++++---------
>   drivers/net/dsa/rzn1_a5psw.h | 20 +++++++++++++++++---
>   2 files changed, 39 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/dsa/rzn1_a5psw.c b/drivers/net/dsa/rzn1_a5psw.c
> index bccfadc1d5e6..8d7cad90d613 100644
> --- a/drivers/net/dsa/rzn1_a5psw.c
> +++ b/drivers/net/dsa/rzn1_a5psw.c
> @@ -384,13 +384,14 @@ static void a5psw_port_bridge_leave(struct dsa_switch *ds, int port,
>   				    struct dsa_bridge bridge)
>   {
>   	struct a5psw *a5psw = ds->priv;
> +	unsigned int cpu_port = a5psw->of_data->cpu_port;
>   
>   	a5psw->bridged_ports &= ~BIT(port);
>   
>   	a5psw_port_set_standalone(a5psw, port, true);
>   
>   	/* No more ports bridged */
> -	if (a5psw->bridged_ports == BIT(A5PSW_CPU_PORT))
> +	if (a5psw->bridged_ports == BIT(cpu_port))
>   		a5psw->br_dev = NULL;
>   }
>   
> @@ -928,20 +929,21 @@ static void a5psw_vlan_setup(struct a5psw *a5psw, int port)
>   static int a5psw_setup(struct dsa_switch *ds)
>   {
>   	struct a5psw *a5psw = ds->priv;
> +	unsigned int cpu_port = a5psw->of_data->cpu_port;
>   	int port, vlan, ret;
>   	struct dsa_port *dp;
>   	u32 reg;
>   
> -	/* 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 != A5PSW_CPU_PORT) {
> +		if (dp->index != cpu_port) {
>   			dev_err(a5psw->dev, "Invalid CPU port\n");
>   			return -EINVAL;
>   		}
>   	}
>   
>   	/* Configure management port */
> -	reg = A5PSW_CPU_PORT | A5PSW_MGMT_CFG_ENABLE;
> +	reg = cpu_port | A5PSW_MGMT_CFG_ENABLE;
>   	a5psw_reg_writel(a5psw, A5PSW_MGMT_CFG, reg);
>   
>   	/* Set pattern 0 to forward all frame to mgmt port */
> @@ -1154,7 +1156,7 @@ static void a5psw_pcs_free(struct a5psw *a5psw)
>   {
>   	int i;
>   
> -	for (i = 0; i < ARRAY_SIZE(a5psw->pcs); i++) {
> +	for (i = 0; i < a5psw->of_data->npcs; i++) {
>   		if (a5psw->pcs[i])
>   			miic_destroy(a5psw->pcs[i]);
>   	}
> @@ -1181,7 +1183,7 @@ static int a5psw_pcs_get(struct a5psw *a5psw)
>   			goto free_pcs;
>   		}
>   
> -		if (reg >= ARRAY_SIZE(a5psw->pcs)) {
> +		if (reg >= a5psw->of_data->npcs) {
>   			ret = -ENODEV;
>   			goto free_pcs;
>   		}
> @@ -1228,11 +1230,16 @@ static int a5psw_probe(struct platform_device *pdev)
>   	a5psw->dev = dev;
>   	mutex_init(&a5psw->lk_lock);
>   	spin_lock_init(&a5psw->reg_lock);
> +
> +	a5psw->of_data = of_device_get_match_data(dev);
> +	if (!a5psw->of_data)
> +		return -ENODEV;
> +
>   	a5psw->base = devm_platform_ioremap_resource(pdev, 0);
>   	if (IS_ERR(a5psw->base))
>   		return PTR_ERR(a5psw->base);
>   
> -	a5psw->bridged_ports = BIT(A5PSW_CPU_PORT);
> +	a5psw->bridged_ports = BIT(a5psw->of_data->cpu_port);
>   
>   	ret = a5psw_pcs_get(a5psw);
>   	if (ret)
> @@ -1277,7 +1284,7 @@ static int a5psw_probe(struct platform_device *pdev)
>   
>   	ds = &a5psw->ds;
>   	ds->dev = dev;
> -	ds->num_ports = A5PSW_PORTS_NUM;
> +	ds->num_ports = a5psw->of_data->nports;
>   	ds->ops = &a5psw_switch_ops;
>   	ds->phylink_mac_ops = &a5psw_phylink_mac_ops;
>   	ds->priv = a5psw;
> @@ -1319,8 +1326,14 @@ static void a5psw_shutdown(struct platform_device *pdev)
>   	platform_set_drvdata(pdev, NULL);
>   }
>   
> +static const struct a5psw_of_data rzn1_of_data = {
> +	.nports = 5,
> +	.npcs = 4,
> +	.cpu_port = 4,
> +};
> +
>   static const struct of_device_id a5psw_of_mtable[] = {
> -	{ .compatible = "renesas,rzn1-a5psw", },
> +	{ .compatible = "renesas,rzn1-a5psw", .data = &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 9693f8503b0b..26d201931453 100644
> --- a/drivers/net/dsa/rzn1_a5psw.h
> +++ b/drivers/net/dsa/rzn1_a5psw.h
> @@ -195,8 +195,8 @@
>   #define A5PSW_aCarrierSenseErrors		0x924
>   
>   #define A5PSW_VLAN_TAG(prio, id)	(((prio) << 12) | (id))
> -#define A5PSW_PORTS_NUM			5
> -#define A5PSW_CPU_PORT			(A5PSW_PORTS_NUM - 1)
> +/* Maximum number of PCS instances (excludes CPU port) */
> +#define A5PSW_MAX_NUM_PCS			4
>   #define A5PSW_MDIO_DEF_FREQ		2500000
>   #define A5PSW_MDIO_TIMEOUT		100
>   #define A5PSW_JUMBO_LEN			(10 * SZ_1K)
> @@ -231,12 +231,25 @@ union lk_data {
>   	struct fdb_entry entry;
>   };
>   
> +/**
> + * struct a5psw_of_data - OF data structure
> + * @nports: Number of ports in the switch
> + * @npcs: Number of PCS connected to the switch
> + * @cpu_port: CPU port number
> + */
> +struct a5psw_of_data {
> +	unsigned int nports;
> +	unsigned int npcs;
> +	unsigned int cpu_port;
> +};
> +
>   /**
>    * struct a5psw - switch struct
>    * @base: Base address of the switch
>    * @hclk: hclk_switch clock
>    * @clk: clk_switch 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)
> @@ -252,8 +265,9 @@ struct a5psw {
>   	struct clk *hclk;
>   	struct clk *clk;
>   	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_NUM_PCS];
>   	struct dsa_switch ds;
>   	struct mutex lk_lock;
>   	spinlock_t reg_lock;

Hi Prabhakar,

LGTM,

Reviewed-by: Clément Léger <clement.leger@linux.dev>

Thanks,

Clément
Technical Details
Message-ID: <4f963eb4-e303-4173-b299-5fbc2685422b@linux.dev>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367726-linux-kernel-netdev=dewy.ru
References: <20261120002549.1908299-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20261120002549.1908299-16-prabhakar.mahadev-lad.rj@bp.renesas.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367726-linux-kernel-netdev=dewy.ru
From: clement.leger@linux.dev (Clement Leger)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v5 15/24] net: dsa: rzn1-a5psw: Get switch info
 via OF data
Date: Fri, 20 Nov 2026 08:02:03 +0100
Organization: Usenet Network
Message-ID: <4f963eb4-e303-4173-b299-5fbc2685422b@linux.dev>
References: <20261120002549.1908299-1-prabhakar.mahadev-lad.rj@bp.renesas.com>
 <20261120002549.1908299-16-prabhakar.mahadev-lad.rj@bp.renesas.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3089219"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VLchumrOWA9M38FDiaSs6LorzA4= sha256:R3jTUE6BkUt8XqySvaNy8njw5UwlybUMbLs/w5rKWz0=
	sha1:1lpoXfyOU6sYmDI9tSw282rmh5Y= sha256:kbckYxEFXWEfDPo7fMvZZgCs55Y+EoGQVqf/RxMdy80=
Content-Language: en-US
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 04B251158DD; Fri, 20 Nov 2026 10:02:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id pjd8LjKoPaiP;
	Fri, 20 Nov 2026 10:02:20 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-367726-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 0C3561158D9; Fri, 20 Nov 2026 10:02:12 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id A0C8E2060DB; Fri, 20 Nov 2026 07:02:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795158130;
	b=NtnRdgKXKdvf0Yk63QnBlrrBb7jW/OCpjH0u5xleqEe+2mYlnM4N/qK5Dp7UoyUAJCzz
	 KxHQYEUrs2Kiz6eYE9LOETaLengGlZugGb2UnZHyIDhWEBaVAC+j8at6KKnBhpJ1iR9hC
	 MnxTbxxGzvBfbCMxC8dQH9Nt+YIocdoboOk4fFbn7BvHkiQQeWTTxme5qHZ6PjsnV63Ll
	 FjT5a4LM/8OPhMlqOsAOLL2Zo4S3EhOnbhaAGFIURe+fNNU9kScrNUIjCrP2C2VkBEeXm
	 5qYt3kxZo/WWyEB/cya5m9b9os8oQbhNK5biuwA+R60GE06s5IVBLj7A5EPDmbyIT8g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795158130;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent:
	 Subject:To:Cc:References:Content-Language:From:In-Reply-To:
	 Content-Type:Content-Transfer-Encoding;
	bh=l1BTs0A8QSXm1yC/tpp+ztP9ZNRIwO6vSe5Y+Ng77GA=;
	b=Wh+4ugOqO96YYIiO3i1ZxQa+9+Wv2FbXqS/hTONCw1pZ/2GjGA6hls3PVydRj6S9vc2a
	 bwvnosQOmm2LdNxuT/S6h03dDsK/2EF9d4JoHCO3BpWX/kYi/rYt0J8nZXurYjb/QzD66
	 SldsPPMv5gFA1Tb6NviIX5u2OmxphJaV9B0Ygzf0hGJgjTo1gg3z5q5CTXGmUlLFPQRq3
	 qde3VtjTNH6e4DL+w8ftEfq+w2D1dXSULlBVilyWHqZArMOqSLZAqUR9oMv7x1aoiOZKs
	 WWtxzXlsuUerXRZK4RirqeD9TtVuMr/J+O7tizusBucukU7kayB8YtXoX1SFBUMJfiQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=kIKubPUZ;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 793AA606A338;
	Fri, 20 Nov 2026 07:02:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=kIKubPUZ
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.100
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795158129;
	b=F56kiH3nC7EfOSuG/eFkTi9lyVrgBWhv5PEuTEQ0ShFCtGK/Ez+rvIqryagDukKXSuou
	 L5lfMMLglunQseW4fq4XFUlHVzVk7bvsj1rLeU44/qqi+LRujxS7CNh5l/beiLD3T+H92
	 QVFPWlwt6kLwq6flJB/DwufOd0LCph02VxCBqnuFwG+CevswnFWCrRCtVS5deSk6ah9EQ
	 ARUc8CXTYZ8v3pJxVGKcIHw2GY0AZ/QmyL7w+hXkt8WXFxqPiZtNalayRthKYc60WGzjU
	 +B80TweghGhuJ05qKr1hybxzYrWepoX55oJXqb5himAfKPJ/eJXbMHN+/TGYcLbD0dw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795158129;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent:
	 Subject:To:Cc:References:Content-Language:From:In-Reply-To:
	 Content-Type:Content-Transfer-Encoding;
	bh=l1BTs0A8QSXm1yC/tpp+ztP9ZNRIwO6vSe5Y+Ng77GA=;
	b=f1UDq7ueSvvWS8U/POdGXs/VsCqjyfFOyCAWnsLJuNhQZA6MACvsp3c7bGxu+zzR3/sW
	 Af3fSv7sFRBJiXHkIjI3xahP2F7jrlcUw9Q5Hr/sK7C6GiJx9DPbj2NW4RTNtL9/h1mI3
	 gl1LiH5O/RKWBXW22ouFsdBcuZwbTZsm7UOQRhG5Rk60HZ8uXW0gniTZ3X7XIi1Z6XNNi
	 6HFki9HlJNXI6E+UugpP1oz8b4ANarajbfpZgoI/xB2gHOHjBoYy+fG7LJcg0smuxrVGl
	 I0GYKJhcQPI3WKUMMY5l8i0dPBuka/Tyk/kgeGeieBX6ZYdgP8Mo6FwC0X/XhKwwaTg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=kIKubPUZ;
	arc=none smtp.remote-ip=95.215.58.100
X-Received: from mta1.migadu.com (out-100.mta1.migadu.com [95.215.58.100])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B711606A325
	for <netdev@vger.kernel.org>; Fri, 20 Nov 2026 07:02:07 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4B711606A325
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=CDT94LdvtJ/SRa+/vKm1xT8CELiWa31ZDBoilrVpzCM=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1795158126; v=1; x=1795762926;
 b=kIKubPUZmtDUkASfHRdTytUKWXuPFoaMkh2E7tqaux04bhF9EF65tVQ79yyxfJeWMHRaE+jH
 Bjgym9gec7dqcR244ZLHt7HsF1IG3y41plXaiKyYnMmuIlNGaNkit8rtyqPhUQfTo1mD/KKn2Pl
 p8OJELoTbgq1RBQCZCe0iLsg=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 574a4a2f70d56532;
	Fri, 20 Nov 2026 07:02:06 +0000
X-Mizu-Trace-ID: 574a4a2f70d56532
X-Migadu-Flow: FLOW_OUT
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Cc: Florian Fainelli <f.fainelli@gmail.com>,
 Ralph Siemsen <ralph.siemsen@linaro.org>, linux-renesas-soc@vger.kernel.org,
 netdev@vger.kernel.org, devicetree@vger.kernel.org,
 Prabhakar <prabhakar.csengg+renesas@gmail.com>,
 Biju Das <biju.das.jz@bp.renesas.com>,
 Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
 Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
X-In-Reply-To: <20261120002549.1908299-16-prabhakar.mahadev-lad.rj@bp.renesas.com>