From: Lad Prabhakar The driver hardcodes the switch port topology and uses a fixed DSA tag protocol. Store the number of ports, number of PCS instances, CPU port and tag protocol in per-SoC OF match data, and use those values in the driver. This allows variants with different port layouts or tag protocols to use the driver while preserving the existing RZ/N1 configuration. Signed-off-by: Lad Prabhakar Reviewed-by: Clément Léger --- v6: - Squashed patch #15 and #16 from v5 to limit the number of patches - Updated the commit message - Added reviewed-by tag v5: https://lore.kernel.org/all/20261120002549.1908299-16-prabhakar.mahadev-lad.rj@bp.renesas.com/ https://lore.kernel.org/all/20261120002549.1908299-17-prabhakar.mahadev-lad.rj@bp.renesas.com/ - New patch --- drivers/net/dsa/rzn1_a5psw.c | 36 ++++++++++++++++++++++++++---------- drivers/net/dsa/rzn1_a5psw.h | 22 +++++++++++++++++++--- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/drivers/net/dsa/rzn1_a5psw.c b/drivers/net/dsa/rzn1_a5psw.c index 679242c1a8be..a768b0545e02 100644 --- a/drivers/net/dsa/rzn1_a5psw.c +++ b/drivers/net/dsa/rzn1_a5psw.c @@ -99,7 +99,9 @@ static enum dsa_tag_protocol a5psw_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) { - return DSA_TAG_PROTO_RZN1_A5PSW; + struct a5psw *a5psw = ds->priv; + + return a5psw->of_data->tag_proto; } static void a5psw_port_pattern_set(struct a5psw *a5psw, int port, int pattern, @@ -390,13 +392,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 +931,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 */ @@ -1152,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]); } @@ -1179,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; } @@ -1226,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) @@ -1275,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; @@ -1317,8 +1326,15 @@ 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, + .tag_proto = DSA_TAG_PROTO_RZN1_A5PSW, +}; + 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..58690f5f3887 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,27 @@ 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 + * @tag_proto: DSA tag protocol used by the switch + */ +struct a5psw_of_data { + unsigned int nports; + unsigned int npcs; + unsigned int cpu_port; + enum dsa_tag_protocol tag_proto; +}; + /** * 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 +267,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; -- 2.56.1