Linux Renesas SOC kernel development
 help / color / mirror / Atom feed
From: Clement Leger <clement.leger@linux.dev>
To: Prabhakar <prabhakar.csengg@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	Simon Horman <horms@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Magnus Damm <magnus.damm@gmail.com>
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>
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	[thread overview]
Message-ID: <4f963eb4-e303-4173-b299-5fbc2685422b@linux.dev> (raw)
In-Reply-To: <20261120002549.1908299-16-prabhakar.mahadev-lad.rj@bp.renesas.com>



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

  reply	other threads:[~2026-11-20  7:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  0:25 [PATCH net-next v5 00/24] Add ETHSW support for Renesas RZ/T2H and RZ/N2H SoCs Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 01/24] net: dsa: tag_rzn1_a5psw: Drop redundant ETH_P_DSA_A5PSW definition Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 02/24] net: dsa: tag_rzn1_a5psw: Add RZ/T2H ETHSW tag protocol support Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 03/24] net: dsa: Kconfig: Expand config description to cover RZ/T2H and RZ/N2H ETHSW Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 04/24] net: pcs: rzn1-miic: Select ETHSW port speed through SWCTRL Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 05/24] dt-bindings: net: dsa: renesas,rzn1-a5psw: Reject the "ports" node Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 06/24] dt-bindings: net: dsa: renesas,rzn1-a5psw: Limit port reg values Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 07/24] dt-bindings: net: dsa: renesas,rzn1-a5psw: Add RZ/T2H and RZ/N2H ETHSW support Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 08/24] net: dsa: rzn1-a5psw: Fix LK_LEARNCOUNT write mode encoding Prabhakar
2026-11-20  3:27   ` Andrew Lunn
2026-11-20  6:01   ` Clement Leger
2026-11-20  0:25 ` [PATCH net-next v5 09/24] net: dsa: rzn1-a5psw: Fix VLANTransmitted counter offset Prabhakar
2026-11-20  3:29   ` Andrew Lunn
2026-11-20  0:25 ` [PATCH net-next v5 10/24] net: dsa: rzn1-a5psw: Fix MDIO clock divider calculation Prabhakar
2026-11-20  6:51   ` Clement Leger
2026-11-20  0:25 ` [PATCH net-next v5 11/24] net: dsa: rzn1-a5psw: Set driver data in probe Prabhakar
2026-11-20  6:53   ` Clement Leger
2026-11-20  0:25 ` [PATCH net-next v5 12/24] net: dsa: rzn1-a5psw: Add support for optional reset control Prabhakar
2026-11-20  3:32   ` Andrew Lunn
2026-11-20  0:25 ` [PATCH net-next v5 13/24] net: dsa: rzn1-a5psw: Add support for optional timestamp clock Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 14/24] net: dsa: rzn1-a5psw: Make use dev_err_probe() Prabhakar
2026-11-20  6:58   ` Clement Leger
2026-11-20  0:25 ` [PATCH net-next v5 15/24] net: dsa: rzn1-a5psw: Get switch info via OF data Prabhakar
2026-11-20  7:02   ` Clement Leger [this message]
2026-11-20  0:25 ` [PATCH net-next v5 16/24] net: dsa: rzn1-a5psw: Choose tagging protocol based on compatible string Prabhakar
2026-11-20  7:03   ` Clement Leger
2026-11-20  0:25 ` [PATCH net-next v5 17/24] net: dsa: rzn1-a5psw: Add fixed frame length workaround for management port Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 18/24] net: dsa: rzn1-a5psw: Get pattern matcher register offsets from OF data Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 19/24] net: dsa: rzn1-a5psw: Get VLAN_RES field layout " Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 20/24] net: dsa: rzn1-a5psw: Get lookup table size " Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 21/24] net: dsa: rzn1-a5psw: Update CPU port comment for RZ/T2H Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 22/24] net: dsa: rzn1-a5psw: Keep MAC TX enabled on RZ/T2H Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 23/24] net: dsa: rzn1-a5psw: Add support for RZ/T2H Ethernet switch Prabhakar
2026-11-20  0:25 ` [PATCH net-next v5 24/24] net: dsa: Kconfig: Enable support for RZ/T2H and RZ/N2H SoCs Prabhakar
2026-11-20  0:28 ` [PATCH net-next v5 00/24] Add ETHSW support for Renesas " netdev-bot+sinfo
2026-11-20  3:14 ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4f963eb4-e303-4173-b299-5fbc2685422b@linux.dev \
    --to=clement.leger@linux.dev \
    --cc=andrew@lunn.ch \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=magnus.damm@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=prabhakar.csengg+renesas@gmail.com \
    --cc=prabhakar.csengg@gmail.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=ralph.siemsen@linaro.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox