* [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver
@ 2022-09-27 19:15 Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 1/5] net: dsa: felix: remove felix_info :: imdio_res Vladimir Oltean
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Vladimir Oltean @ 2022-09-27 19:15 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Colin Foster, Maxim Kochetkov
The Felix DSA driver controls NXP variations of Microchip switches.
Colin Foster is trying to add support in this driver for "genuine"
Microchip hardware, but some of the NXP-isms in this driver need to go
away before that happens cleanly.
https://patchwork.kernel.org/project/netdevbpf/cover/20220926002928.2744638-1-colin.foster@in-advantage.com/
The starting point was Colin's patch 08/14 "net: dsa: felix: update
init_regmap to be string-based", and this continues to be the central
theme here, but things are done differently.
In short (full explanations are in patches), the goal is for MFD-based
switches like Colin's SPI-controlled VSC7512 to be able to request a
regmap that was created 100% externally (by drivers/mfd/ocelot-core.c)
in a very simple way, that does not create dependencies on other
modules. That is dev_get_regmap(), and as input it wants a string, for
the resource name. So we rework the resource allocation in this driver
to be based on string names provided by the specific instantiation (in
Colin's case, ocelot_ext.c).
Patch set was boot-tested on NXP LS1028A.
Vladimir Oltean (5):
net: dsa: felix: remove felix_info :: imdio_res
net: dsa: felix: remove felix_info :: imdio_base
net: dsa: felix: remove felix_info :: init_regmap
net: dsa: felix: use DEFINE_RES_MEM_NAMED for resources
net: dsa: felix: update regmap requests to be string-based
drivers/net/dsa/ocelot/felix.c | 73 ++++++++----
drivers/net/dsa/ocelot/felix.h | 13 ++-
drivers/net/dsa/ocelot/felix_vsc9959.c | 136 +++++++---------------
drivers/net/dsa/ocelot/seville_vsc9953.c | 140 ++++++-----------------
4 files changed, 133 insertions(+), 229 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net-next 1/5] net: dsa: felix: remove felix_info :: imdio_res
2022-09-27 19:15 [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver Vladimir Oltean
@ 2022-09-27 19:15 ` Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 2/5] net: dsa: felix: remove felix_info :: imdio_base Vladimir Oltean
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Vladimir Oltean @ 2022-09-27 19:15 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Colin Foster, Maxim Kochetkov
The imdio_res is used only by vsc9959, which references its own
vsc9959_imdio_res through the common felix_info->imdio_res pointer.
Since the common code doesn't care about this resource (and it can't be
part of the common array of resources, either, because it belongs in a
different PCI BAR), just reference it directly.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/ocelot/felix.h | 1 -
drivers/net/dsa/ocelot/felix_vsc9959.c | 3 +--
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/net/dsa/ocelot/felix.h b/drivers/net/dsa/ocelot/felix.h
index e4fd5eef57a0..535a615f2b70 100644
--- a/drivers/net/dsa/ocelot/felix.h
+++ b/drivers/net/dsa/ocelot/felix.h
@@ -18,7 +18,6 @@
struct felix_info {
const struct resource *target_io_res;
const struct resource *port_io_res;
- const struct resource *imdio_res;
const struct reg_field *regfields;
const u32 *const *map;
const struct ocelot_ops *ops;
diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 2ec49e42b3f4..2234b4eccc1e 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -1021,7 +1021,7 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
return -ENOMEM;
}
- memcpy(&res, felix->info->imdio_res, sizeof(res));
+ memcpy(&res, &vsc9959_imdio_res, sizeof(res));
res.flags = IORESOURCE_MEM;
res.start += felix->imdio_base;
res.end += felix->imdio_base;
@@ -2592,7 +2592,6 @@ static const struct ocelot_ops vsc9959_ops = {
static const struct felix_info felix_info_vsc9959 = {
.target_io_res = vsc9959_target_io_res,
.port_io_res = vsc9959_port_io_res,
- .imdio_res = &vsc9959_imdio_res,
.regfields = vsc9959_regfields,
.map = vsc9959_regmap,
.ops = &vsc9959_ops,
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 2/5] net: dsa: felix: remove felix_info :: imdio_base
2022-09-27 19:15 [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 1/5] net: dsa: felix: remove felix_info :: imdio_res Vladimir Oltean
@ 2022-09-27 19:15 ` Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 3/5] net: dsa: felix: remove felix_info :: init_regmap Vladimir Oltean
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Vladimir Oltean @ 2022-09-27 19:15 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Colin Foster, Maxim Kochetkov
This address is only relevant for the vsc9959, which is a PCIe device
that holds its switch registers in a different PCIe BAR compared to the
registers for the internal MDIO controller.
Hide this aspect from the common felix driver and move the
pci_resource_start() call to the only place that needs it, which is in
vsc9959_mdio_bus_alloc().
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/ocelot/felix.h | 1 -
drivers/net/dsa/ocelot/felix_vsc9959.c | 9 ++++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/net/dsa/ocelot/felix.h b/drivers/net/dsa/ocelot/felix.h
index 535a615f2b70..4921f5cc8170 100644
--- a/drivers/net/dsa/ocelot/felix.h
+++ b/drivers/net/dsa/ocelot/felix.h
@@ -85,7 +85,6 @@ struct felix {
struct mii_bus *imdio;
struct phylink_pcs **pcs;
resource_size_t switch_base;
- resource_size_t imdio_base;
enum dsa_tag_protocol tag_proto;
const struct felix_tag_proto_ops *tag_proto_ops;
struct kthread_worker *xmit_worker;
diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 2234b4eccc1e..4ca9fbe197c7 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -1003,9 +1003,11 @@ static void vsc9959_wm_stat(u32 val, u32 *inuse, u32 *maxuse)
static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
{
+ struct pci_dev *pdev = to_pci_dev(ocelot->dev);
struct felix *felix = ocelot_to_felix(ocelot);
struct enetc_mdio_priv *mdio_priv;
struct device *dev = ocelot->dev;
+ resource_size_t imdio_base;
void __iomem *imdio_regs;
struct resource res;
struct enetc_hw *hw;
@@ -1021,10 +1023,12 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
return -ENOMEM;
}
+ imdio_base = pci_resource_start(pdev, VSC9959_IMDIO_PCI_BAR);
+
memcpy(&res, &vsc9959_imdio_res, sizeof(res));
res.flags = IORESOURCE_MEM;
- res.start += felix->imdio_base;
- res.end += felix->imdio_base;
+ res.start += imdio_base;
+ res.end += imdio_base;
imdio_regs = devm_ioremap_resource(dev, &res);
if (IS_ERR(imdio_regs))
@@ -2665,7 +2669,6 @@ static int felix_pci_probe(struct pci_dev *pdev,
ocelot->num_flooding_pgids = OCELOT_NUM_TC;
felix->info = &felix_info_vsc9959;
felix->switch_base = pci_resource_start(pdev, VSC9959_SWITCH_PCI_BAR);
- felix->imdio_base = pci_resource_start(pdev, VSC9959_IMDIO_PCI_BAR);
pci_set_master(pdev);
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 3/5] net: dsa: felix: remove felix_info :: init_regmap
2022-09-27 19:15 [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 1/5] net: dsa: felix: remove felix_info :: imdio_res Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 2/5] net: dsa: felix: remove felix_info :: imdio_base Vladimir Oltean
@ 2022-09-27 19:15 ` Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 4/5] net: dsa: felix: use DEFINE_RES_MEM_NAMED for resources Vladimir Oltean
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Vladimir Oltean @ 2022-09-27 19:15 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Colin Foster, Maxim Kochetkov
It turns out that the idea of having a customizable implementation of a
regmap creation from a resource is not exactly useful. The idea was for
the new MFD-based VSC7512 driver to use something that creates a SPI
regmap from a resource. But there are problems in actually getting those
resources (it involves getting them from MFD).
To avoid all that, we'll be getting resources by name, so this custom
init_regmap() method won't be needed. Remove it.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/ocelot/felix.c | 4 ++--
drivers/net/dsa/ocelot/felix.h | 2 --
drivers/net/dsa/ocelot/felix_vsc9959.c | 1 -
drivers/net/dsa/ocelot/seville_vsc9953.c | 1 -
4 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c
index d2a9d292160c..b7a66c151be3 100644
--- a/drivers/net/dsa/ocelot/felix.c
+++ b/drivers/net/dsa/ocelot/felix.c
@@ -1360,7 +1360,7 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
res.start += felix->switch_base;
res.end += felix->switch_base;
- target = felix->info->init_regmap(ocelot, &res);
+ target = ocelot_regmap_init(ocelot, &res);
if (IS_ERR(target)) {
dev_err(ocelot->dev,
"Failed to map device memory space\n");
@@ -1397,7 +1397,7 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
res.start += felix->switch_base;
res.end += felix->switch_base;
- target = felix->info->init_regmap(ocelot, &res);
+ target = ocelot_regmap_init(ocelot, &res);
if (IS_ERR(target)) {
dev_err(ocelot->dev,
"Failed to map memory space for port %d\n",
diff --git a/drivers/net/dsa/ocelot/felix.h b/drivers/net/dsa/ocelot/felix.h
index 4921f5cc8170..54322d0398fd 100644
--- a/drivers/net/dsa/ocelot/felix.h
+++ b/drivers/net/dsa/ocelot/felix.h
@@ -55,8 +55,6 @@ struct felix_info {
void (*tas_guard_bands_update)(struct ocelot *ocelot, int port);
void (*port_sched_speed_set)(struct ocelot *ocelot, int port,
u32 speed);
- struct regmap *(*init_regmap)(struct ocelot *ocelot,
- struct resource *res);
};
/* Methods for initializing the hardware resources specific to a tagging
diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 4ca9fbe197c7..e465e3f85467 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -2617,7 +2617,6 @@ static const struct felix_info felix_info_vsc9959 = {
.port_setup_tc = vsc9959_port_setup_tc,
.port_sched_speed_set = vsc9959_sched_speed_set,
.tas_guard_bands_update = vsc9959_tas_guard_bands_update,
- .init_regmap = ocelot_regmap_init,
};
static irqreturn_t felix_irq_handler(int irq, void *data)
diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c
index 5b29fa930627..e807db0dea98 100644
--- a/drivers/net/dsa/ocelot/seville_vsc9953.c
+++ b/drivers/net/dsa/ocelot/seville_vsc9953.c
@@ -1078,7 +1078,6 @@ static const struct felix_info seville_info_vsc9953 = {
.mdio_bus_free = vsc9953_mdio_bus_free,
.phylink_validate = vsc9953_phylink_validate,
.port_modes = vsc9953_port_modes,
- .init_regmap = ocelot_regmap_init,
};
static int seville_probe(struct platform_device *pdev)
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 4/5] net: dsa: felix: use DEFINE_RES_MEM_NAMED for resources
2022-09-27 19:15 [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver Vladimir Oltean
` (2 preceding siblings ...)
2022-09-27 19:15 ` [PATCH net-next 3/5] net: dsa: felix: remove felix_info :: init_regmap Vladimir Oltean
@ 2022-09-27 19:15 ` Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 5/5] net: dsa: felix: update init_regmap to be string-based Vladimir Oltean
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Vladimir Oltean @ 2022-09-27 19:15 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Colin Foster, Maxim Kochetkov
Use less verbose resource definitions in vsc9959 and vsc9953. This also
sets IORESOURCE_MEM in the constant array of resources, so we don't have
to do this from felix_init_structs() - in fact, in the future, we may
even support IORESOURCE_REG resources.
Note that this macro takes start and length as argument, and we had
start and end before. So transform end into length.
While at it, sort the resources according to their offset.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/ocelot/felix.c | 2 -
drivers/net/dsa/ocelot/felix_vsc9959.c | 104 ++++----------------
drivers/net/dsa/ocelot/seville_vsc9953.c | 120 ++++-------------------
3 files changed, 38 insertions(+), 188 deletions(-)
diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c
index b7a66c151be3..6a7643c31c46 100644
--- a/drivers/net/dsa/ocelot/felix.c
+++ b/drivers/net/dsa/ocelot/felix.c
@@ -1356,7 +1356,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
continue;
memcpy(&res, &felix->info->target_io_res[i], sizeof(res));
- res.flags = IORESOURCE_MEM;
res.start += felix->switch_base;
res.end += felix->switch_base;
@@ -1393,7 +1392,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
}
memcpy(&res, &felix->info->port_io_res[port], sizeof(res));
- res.flags = IORESOURCE_MEM;
res.start += felix->switch_base;
res.end += felix->switch_base;
diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index e465e3f85467..1872727e80df 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -478,99 +478,32 @@ static const u32 *vsc9959_regmap[TARGET_MAX] = {
/* Addresses are relative to the PCI device's base address */
static const struct resource vsc9959_target_io_res[TARGET_MAX] = {
- [ANA] = {
- .start = 0x0280000,
- .end = 0x028ffff,
- .name = "ana",
- },
- [QS] = {
- .start = 0x0080000,
- .end = 0x00800ff,
- .name = "qs",
- },
- [QSYS] = {
- .start = 0x0200000,
- .end = 0x021ffff,
- .name = "qsys",
- },
- [REW] = {
- .start = 0x0030000,
- .end = 0x003ffff,
- .name = "rew",
- },
- [SYS] = {
- .start = 0x0010000,
- .end = 0x001ffff,
- .name = "sys",
- },
- [S0] = {
- .start = 0x0040000,
- .end = 0x00403ff,
- .name = "s0",
- },
- [S1] = {
- .start = 0x0050000,
- .end = 0x00503ff,
- .name = "s1",
- },
- [S2] = {
- .start = 0x0060000,
- .end = 0x00603ff,
- .name = "s2",
- },
- [PTP] = {
- .start = 0x0090000,
- .end = 0x00900cb,
- .name = "ptp",
- },
- [GCB] = {
- .start = 0x0070000,
- .end = 0x00701ff,
- .name = "devcpu_gcb",
- },
+ [SYS] = DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
+ [REW] = DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
+ [S0] = DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
+ [S1] = DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
+ [S2] = DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
+ [GCB] = DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
+ [QS] = DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
+ [PTP] = DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
+ [QSYS] = DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
+ [ANA] = DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
};
static const struct resource vsc9959_port_io_res[] = {
- {
- .start = 0x0100000,
- .end = 0x010ffff,
- .name = "port0",
- },
- {
- .start = 0x0110000,
- .end = 0x011ffff,
- .name = "port1",
- },
- {
- .start = 0x0120000,
- .end = 0x012ffff,
- .name = "port2",
- },
- {
- .start = 0x0130000,
- .end = 0x013ffff,
- .name = "port3",
- },
- {
- .start = 0x0140000,
- .end = 0x014ffff,
- .name = "port4",
- },
- {
- .start = 0x0150000,
- .end = 0x015ffff,
- .name = "port5",
- },
+ DEFINE_RES_MEM_NAMED(0x0100000, 0x0010000, "port0"),
+ DEFINE_RES_MEM_NAMED(0x0110000, 0x0010000, "port1"),
+ DEFINE_RES_MEM_NAMED(0x0120000, 0x0010000, "port2"),
+ DEFINE_RES_MEM_NAMED(0x0130000, 0x0010000, "port3"),
+ DEFINE_RES_MEM_NAMED(0x0140000, 0x0010000, "port4"),
+ DEFINE_RES_MEM_NAMED(0x0150000, 0x0010000, "port5"),
};
/* Port MAC 0 Internal MDIO bus through which the SerDes acting as an
* SGMII/QSGMII MAC PCS can be found.
*/
-static const struct resource vsc9959_imdio_res = {
- .start = 0x8030,
- .end = 0x8040,
- .name = "imdio",
-};
+static const struct resource vsc9959_imdio_res =
+ DEFINE_RES_MEM_NAMED(0x8030, 0x8040, "imdio");
static const struct reg_field vsc9959_regfields[REGFIELD_MAX] = {
[ANA_ADVLEARN_VLAN_CHK] = REG_FIELD(ANA_ADVLEARN, 6, 6),
@@ -1026,7 +959,6 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
imdio_base = pci_resource_start(pdev, VSC9959_IMDIO_PCI_BAR);
memcpy(&res, &vsc9959_imdio_res, sizeof(res));
- res.flags = IORESOURCE_MEM;
res.start += imdio_base;
res.end += imdio_base;
diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c
index e807db0dea98..66237c4385ac 100644
--- a/drivers/net/dsa/ocelot/seville_vsc9953.c
+++ b/drivers/net/dsa/ocelot/seville_vsc9953.c
@@ -459,109 +459,29 @@ static const u32 *vsc9953_regmap[TARGET_MAX] = {
/* Addresses are relative to the device's base address */
static const struct resource vsc9953_target_io_res[TARGET_MAX] = {
- [ANA] = {
- .start = 0x0280000,
- .end = 0x028ffff,
- .name = "ana",
- },
- [QS] = {
- .start = 0x0080000,
- .end = 0x00800ff,
- .name = "qs",
- },
- [QSYS] = {
- .start = 0x0200000,
- .end = 0x021ffff,
- .name = "qsys",
- },
- [REW] = {
- .start = 0x0030000,
- .end = 0x003ffff,
- .name = "rew",
- },
- [SYS] = {
- .start = 0x0010000,
- .end = 0x001ffff,
- .name = "sys",
- },
- [S0] = {
- .start = 0x0040000,
- .end = 0x00403ff,
- .name = "s0",
- },
- [S1] = {
- .start = 0x0050000,
- .end = 0x00503ff,
- .name = "s1",
- },
- [S2] = {
- .start = 0x0060000,
- .end = 0x00603ff,
- .name = "s2",
- },
- [PTP] = {
- .start = 0x0090000,
- .end = 0x00900cb,
- .name = "ptp",
- },
- [GCB] = {
- .start = 0x0070000,
- .end = 0x00701ff,
- .name = "devcpu_gcb",
- },
+ [SYS] = DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
+ [REW] = DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
+ [S0] = DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
+ [S1] = DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
+ [S2] = DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
+ [GCB] = DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
+ [QS] = DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
+ [PTP] = DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
+ [QSYS] = DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
+ [ANA] = DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
};
static const struct resource vsc9953_port_io_res[] = {
- {
- .start = 0x0100000,
- .end = 0x010ffff,
- .name = "port0",
- },
- {
- .start = 0x0110000,
- .end = 0x011ffff,
- .name = "port1",
- },
- {
- .start = 0x0120000,
- .end = 0x012ffff,
- .name = "port2",
- },
- {
- .start = 0x0130000,
- .end = 0x013ffff,
- .name = "port3",
- },
- {
- .start = 0x0140000,
- .end = 0x014ffff,
- .name = "port4",
- },
- {
- .start = 0x0150000,
- .end = 0x015ffff,
- .name = "port5",
- },
- {
- .start = 0x0160000,
- .end = 0x016ffff,
- .name = "port6",
- },
- {
- .start = 0x0170000,
- .end = 0x017ffff,
- .name = "port7",
- },
- {
- .start = 0x0180000,
- .end = 0x018ffff,
- .name = "port8",
- },
- {
- .start = 0x0190000,
- .end = 0x019ffff,
- .name = "port9",
- },
+ DEFINE_RES_MEM_NAMED(0x0100000, 0x0010000, "port0"),
+ DEFINE_RES_MEM_NAMED(0x0110000, 0x0010000, "port1"),
+ DEFINE_RES_MEM_NAMED(0x0120000, 0x0010000, "port2"),
+ DEFINE_RES_MEM_NAMED(0x0130000, 0x0010000, "port3"),
+ DEFINE_RES_MEM_NAMED(0x0140000, 0x0010000, "port4"),
+ DEFINE_RES_MEM_NAMED(0x0150000, 0x0010000, "port5"),
+ DEFINE_RES_MEM_NAMED(0x0160000, 0x0010000, "port6"),
+ DEFINE_RES_MEM_NAMED(0x0170000, 0x0010000, "port7"),
+ DEFINE_RES_MEM_NAMED(0x0180000, 0x0010000, "port8"),
+ DEFINE_RES_MEM_NAMED(0x0190000, 0x0010000, "port9"),
};
static const struct reg_field vsc9953_regfields[REGFIELD_MAX] = {
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 5/5] net: dsa: felix: update init_regmap to be string-based
2022-09-27 19:15 [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver Vladimir Oltean
` (3 preceding siblings ...)
2022-09-27 19:15 ` [PATCH net-next 4/5] net: dsa: felix: use DEFINE_RES_MEM_NAMED for resources Vladimir Oltean
@ 2022-09-27 19:15 ` Vladimir Oltean
2022-09-27 19:27 ` Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 5/5] net: dsa: felix: update regmap requests " Vladimir Oltean
2022-09-29 2:50 ` [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver patchwork-bot+netdevbpf
6 siblings, 1 reply; 11+ messages in thread
From: Vladimir Oltean @ 2022-09-27 19:15 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Colin Foster, Maxim Kochetkov
Existing felix DSA drivers (vsc9959, vsc9953) are all switches that were
integrated in NXP SoCs, which makes them a bit unusual compared to the
usual Microchip branded Ocelot switches.
To be precise, looking at
Documentation/devicetree/bindings/net/mscc,vsc7514-switch.yaml, one can
see 21 memory regions for the "switch" node, and these correspond to the
"targets" of the switch IP, which are spread throughout the guts of that
SoC's memory space.
In NXP integrations, those targets still exist, but they were condensed
within a single memory region, with no other peripheral in between them,
so it made more sense for the driver to ioremap the entire memory space
of the switch, and then find the targets within that memory space via
some offsets hardcoded in the driver.
The effect of this design decision is that now, the felix driver expects
hardware instantiations to provide their own resource definitions, which
is kind of odd when considering a typical switch (those are retrieved
from device tree, using platform_get_resource() or similar).
Allow other hardware instantiations that share the felix driver to not
provide an array of resources in the future. Instead, make the common
denominator based on which regmaps are created be just the resource
"names". Each instantiation comes with its own array of names that are
mandatory for it, and with an optional array of resources.
If we can match the name from the array of mandatory resources to any
element in the list of hardcoded resources, use that. The advantage is
that this permits us to modify felix_request_regmap_by_name() in the
future to make felix->info->resources[] optional, and if absent, the
implementation can call dev_get_regmap() and this is something that is
compatible with MFD.
Co-developed-by: Colin Foster <colin.foster@in-advantage.com>
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/ocelot/felix.c | 71 +++++++++++++++++-------
drivers/net/dsa/ocelot/felix.h | 9 ++-
drivers/net/dsa/ocelot/felix_vsc9959.c | 43 ++++++++------
drivers/net/dsa/ocelot/seville_vsc9953.c | 43 ++++++++------
4 files changed, 112 insertions(+), 54 deletions(-)
diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c
index 6a7643c31c46..dd3a18cc89dd 100644
--- a/drivers/net/dsa/ocelot/felix.c
+++ b/drivers/net/dsa/ocelot/felix.c
@@ -1312,11 +1312,55 @@ static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes)
return err;
}
+static struct regmap *felix_request_regmap_by_name(struct felix *felix,
+ const char *resource_name)
+{
+ struct ocelot *ocelot = &felix->ocelot;
+ struct resource res;
+ int i;
+
+ for (i = 0; i < felix->info->num_resources; i++) {
+ if (strcmp(resource_name, felix->info->resources[i].name))
+ continue;
+
+ memcpy(&res, &felix->info->resources[i], sizeof(res));
+ res.start += felix->switch_base;
+ res.end += felix->switch_base;
+
+ return ocelot_regmap_init(ocelot, &res);
+ }
+
+ return ERR_PTR(-ENOENT);
+}
+
+static struct regmap *felix_request_regmap(struct felix *felix,
+ enum ocelot_target target)
+{
+ const char *resource_name = felix->info->resource_names[target];
+
+ /* If the driver didn't provide a resource name for the target,
+ * the resource is optional.
+ */
+ if (!resource_name)
+ return NULL;
+
+ return felix_request_regmap_by_name(felix, resource_name);
+}
+
+static struct regmap *felix_request_port_regmap(struct felix *felix, int port)
+{
+ char resource_name[32];
+
+ sprintf(resource_name, "port%d", port);
+
+ return felix_request_regmap_by_name(felix, resource_name);
+}
+
static int felix_init_structs(struct felix *felix, int num_phys_ports)
{
struct ocelot *ocelot = &felix->ocelot;
phy_interface_t *port_phy_modes;
- struct resource res;
+ struct regmap *target;
int port, i, err;
ocelot->num_phys_ports = num_phys_ports;
@@ -1350,19 +1394,11 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
}
for (i = 0; i < TARGET_MAX; i++) {
- struct regmap *target;
-
- if (!felix->info->target_io_res[i].name)
- continue;
-
- memcpy(&res, &felix->info->target_io_res[i], sizeof(res));
- res.start += felix->switch_base;
- res.end += felix->switch_base;
-
- target = ocelot_regmap_init(ocelot, &res);
+ target = felix_request_regmap(felix, i);
if (IS_ERR(target)) {
dev_err(ocelot->dev,
- "Failed to map device memory space\n");
+ "Failed to map device memory space: %pe\n",
+ target);
kfree(port_phy_modes);
return PTR_ERR(target);
}
@@ -1379,7 +1415,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
for (port = 0; port < num_phys_ports; port++) {
struct ocelot_port *ocelot_port;
- struct regmap *target;
ocelot_port = devm_kzalloc(ocelot->dev,
sizeof(struct ocelot_port),
@@ -1391,15 +1426,11 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
return -ENOMEM;
}
- memcpy(&res, &felix->info->port_io_res[port], sizeof(res));
- res.start += felix->switch_base;
- res.end += felix->switch_base;
-
- target = ocelot_regmap_init(ocelot, &res);
+ target = felix_request_port_regmap(felix, port);
if (IS_ERR(target)) {
dev_err(ocelot->dev,
- "Failed to map memory space for port %d\n",
- port);
+ "Failed to map memory space for port %d: %pe\n",
+ port, target);
kfree(port_phy_modes);
return PTR_ERR(target);
}
diff --git a/drivers/net/dsa/ocelot/felix.h b/drivers/net/dsa/ocelot/felix.h
index 54322d0398fd..c9c29999c336 100644
--- a/drivers/net/dsa/ocelot/felix.h
+++ b/drivers/net/dsa/ocelot/felix.h
@@ -16,8 +16,13 @@
/* Platform-specific information */
struct felix_info {
- const struct resource *target_io_res;
- const struct resource *port_io_res;
+ /* Hardcoded resources provided by the hardware instantiation. */
+ const struct resource *resources;
+ size_t num_resources;
+ /* Names of the mandatory resources that will be requested during
+ * probe. Must have TARGET_MAX elements, since it is indexed by target.
+ */
+ const char *const *resource_names;
const struct reg_field *regfields;
const u32 *const *map;
const struct ocelot_ops *ops;
diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 1872727e80df..12810fea2075 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -477,26 +477,36 @@ static const u32 *vsc9959_regmap[TARGET_MAX] = {
};
/* Addresses are relative to the PCI device's base address */
-static const struct resource vsc9959_target_io_res[TARGET_MAX] = {
- [SYS] = DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
- [REW] = DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
- [S0] = DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
- [S1] = DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
- [S2] = DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
- [GCB] = DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
- [QS] = DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
- [PTP] = DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
- [QSYS] = DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
- [ANA] = DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
-};
-
-static const struct resource vsc9959_port_io_res[] = {
+static const struct resource vsc9959_resources[] = {
+ DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
+ DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
+ DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
+ DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
+ DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
+ DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
+ DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
+ DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
DEFINE_RES_MEM_NAMED(0x0100000, 0x0010000, "port0"),
DEFINE_RES_MEM_NAMED(0x0110000, 0x0010000, "port1"),
DEFINE_RES_MEM_NAMED(0x0120000, 0x0010000, "port2"),
DEFINE_RES_MEM_NAMED(0x0130000, 0x0010000, "port3"),
DEFINE_RES_MEM_NAMED(0x0140000, 0x0010000, "port4"),
DEFINE_RES_MEM_NAMED(0x0150000, 0x0010000, "port5"),
+ DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
+ DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
+};
+
+static const char * const vsc9959_resource_names[TARGET_MAX] = {
+ [SYS] = "sys",
+ [REW] = "rew",
+ [S0] = "s0",
+ [S1] = "s1",
+ [S2] = "s2",
+ [GCB] = "devcpu_gcb",
+ [QS] = "qs",
+ [PTP] = "ptp",
+ [QSYS] = "qsys",
+ [ANA] = "ana",
};
/* Port MAC 0 Internal MDIO bus through which the SerDes acting as an
@@ -2526,8 +2536,9 @@ static const struct ocelot_ops vsc9959_ops = {
};
static const struct felix_info felix_info_vsc9959 = {
- .target_io_res = vsc9959_target_io_res,
- .port_io_res = vsc9959_port_io_res,
+ .resources = vsc9959_resources,
+ .num_resources = ARRAY_SIZE(vsc9959_resources),
+ .resource_names = vsc9959_resource_names,
.regfields = vsc9959_regfields,
.map = vsc9959_regmap,
.ops = &vsc9959_ops,
diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c
index 66237c4385ac..7af33b2c685d 100644
--- a/drivers/net/dsa/ocelot/seville_vsc9953.c
+++ b/drivers/net/dsa/ocelot/seville_vsc9953.c
@@ -458,20 +458,15 @@ static const u32 *vsc9953_regmap[TARGET_MAX] = {
};
/* Addresses are relative to the device's base address */
-static const struct resource vsc9953_target_io_res[TARGET_MAX] = {
- [SYS] = DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
- [REW] = DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
- [S0] = DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
- [S1] = DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
- [S2] = DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
- [GCB] = DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
- [QS] = DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
- [PTP] = DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
- [QSYS] = DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
- [ANA] = DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
-};
-
-static const struct resource vsc9953_port_io_res[] = {
+static const struct resource vsc9953_resources[] = {
+ DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
+ DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
+ DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
+ DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
+ DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
+ DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
+ DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
+ DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
DEFINE_RES_MEM_NAMED(0x0100000, 0x0010000, "port0"),
DEFINE_RES_MEM_NAMED(0x0110000, 0x0010000, "port1"),
DEFINE_RES_MEM_NAMED(0x0120000, 0x0010000, "port2"),
@@ -482,6 +477,21 @@ static const struct resource vsc9953_port_io_res[] = {
DEFINE_RES_MEM_NAMED(0x0170000, 0x0010000, "port7"),
DEFINE_RES_MEM_NAMED(0x0180000, 0x0010000, "port8"),
DEFINE_RES_MEM_NAMED(0x0190000, 0x0010000, "port9"),
+ DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
+ DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
+};
+
+static const char * const vsc9953_resource_names[TARGET_MAX] = {
+ [SYS] = "sys",
+ [REW] = "rew",
+ [S0] = "s0",
+ [S1] = "s1",
+ [S2] = "s2",
+ [GCB] = "devcpu_gcb",
+ [QS] = "qs",
+ [PTP] = "ptp",
+ [QSYS] = "qsys",
+ [ANA] = "ana",
};
static const struct reg_field vsc9953_regfields[REGFIELD_MAX] = {
@@ -980,8 +990,9 @@ static void vsc9953_mdio_bus_free(struct ocelot *ocelot)
}
static const struct felix_info seville_info_vsc9953 = {
- .target_io_res = vsc9953_target_io_res,
- .port_io_res = vsc9953_port_io_res,
+ .resources = vsc9953_resources,
+ .num_resources = ARRAY_SIZE(vsc9953_resources),
+ .resource_names = vsc9953_resource_names,
.regfields = vsc9953_regfields,
.map = vsc9953_regmap,
.ops = &vsc9953_ops,
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 5/5] net: dsa: felix: update regmap requests to be string-based
2022-09-27 19:15 [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver Vladimir Oltean
` (4 preceding siblings ...)
2022-09-27 19:15 ` [PATCH net-next 5/5] net: dsa: felix: update init_regmap to be string-based Vladimir Oltean
@ 2022-09-27 19:15 ` Vladimir Oltean
2022-09-27 20:28 ` Colin Foster
2022-09-29 2:50 ` [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver patchwork-bot+netdevbpf
6 siblings, 1 reply; 11+ messages in thread
From: Vladimir Oltean @ 2022-09-27 19:15 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Colin Foster, Maxim Kochetkov
Existing felix DSA drivers (vsc9959, vsc9953) are all switches that were
integrated in NXP SoCs, which makes them a bit unusual compared to the
usual Microchip branded Ocelot switches.
To be precise, looking at
Documentation/devicetree/bindings/net/mscc,vsc7514-switch.yaml, one can
see 21 memory regions for the "switch" node, and these correspond to the
"targets" of the switch IP, which are spread throughout the guts of that
SoC's memory space.
In NXP integrations, those targets still exist, but they were condensed
within a single memory region, with no other peripheral in between them,
so it made more sense for the driver to ioremap the entire memory space
of the switch, and then find the targets within that memory space via
some offsets hardcoded in the driver.
The effect of this design decision is that now, the felix driver expects
hardware instantiations to provide their own resource definitions, which
is kind of odd when considering a typical device (those are retrieved
from 'reg' properties in the device tree, using platform_get_resource()
or similar).
Allow other hardware instantiations that share the felix driver to not
provide a hardcoded array of resources in the future. Instead, make the
common denominator based on which regmaps are created be just the
resource "names". Each instantiation comes with its own array of names
that are mandatory for it, and with an optional array of resources.
So we split the resources in 2 arrays, one is what's requested and the
other is what's provided. There is one pool of provided resources, in
felix->info->resources (of length felix->info->num_resources). There are
2 different ways of requesting a resource. One is by enum ocelot_target
(this handles the global regmaps), and one is by int port (this handles
the per-port ones).
For the existing vsc9959 and vsc9953, it would be a bit stupid to
request something that's not provided, given that the 2 arrays are both
defined in the same place.
The advantage is that we can now modify felix_request_regmap_by_name()
to make felix->info->resources[] optional, and if absent, the
implementation can call dev_get_regmap() and this is something that is
compatible with MFD.
Co-developed-by: Colin Foster <colin.foster@in-advantage.com>
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/dsa/ocelot/felix.c | 71 +++++++++++++++++-------
drivers/net/dsa/ocelot/felix.h | 9 ++-
drivers/net/dsa/ocelot/felix_vsc9959.c | 43 ++++++++------
drivers/net/dsa/ocelot/seville_vsc9953.c | 43 ++++++++------
4 files changed, 112 insertions(+), 54 deletions(-)
diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c
index 6a7643c31c46..dd3a18cc89dd 100644
--- a/drivers/net/dsa/ocelot/felix.c
+++ b/drivers/net/dsa/ocelot/felix.c
@@ -1312,11 +1312,55 @@ static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes)
return err;
}
+static struct regmap *felix_request_regmap_by_name(struct felix *felix,
+ const char *resource_name)
+{
+ struct ocelot *ocelot = &felix->ocelot;
+ struct resource res;
+ int i;
+
+ for (i = 0; i < felix->info->num_resources; i++) {
+ if (strcmp(resource_name, felix->info->resources[i].name))
+ continue;
+
+ memcpy(&res, &felix->info->resources[i], sizeof(res));
+ res.start += felix->switch_base;
+ res.end += felix->switch_base;
+
+ return ocelot_regmap_init(ocelot, &res);
+ }
+
+ return ERR_PTR(-ENOENT);
+}
+
+static struct regmap *felix_request_regmap(struct felix *felix,
+ enum ocelot_target target)
+{
+ const char *resource_name = felix->info->resource_names[target];
+
+ /* If the driver didn't provide a resource name for the target,
+ * the resource is optional.
+ */
+ if (!resource_name)
+ return NULL;
+
+ return felix_request_regmap_by_name(felix, resource_name);
+}
+
+static struct regmap *felix_request_port_regmap(struct felix *felix, int port)
+{
+ char resource_name[32];
+
+ sprintf(resource_name, "port%d", port);
+
+ return felix_request_regmap_by_name(felix, resource_name);
+}
+
static int felix_init_structs(struct felix *felix, int num_phys_ports)
{
struct ocelot *ocelot = &felix->ocelot;
phy_interface_t *port_phy_modes;
- struct resource res;
+ struct regmap *target;
int port, i, err;
ocelot->num_phys_ports = num_phys_ports;
@@ -1350,19 +1394,11 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
}
for (i = 0; i < TARGET_MAX; i++) {
- struct regmap *target;
-
- if (!felix->info->target_io_res[i].name)
- continue;
-
- memcpy(&res, &felix->info->target_io_res[i], sizeof(res));
- res.start += felix->switch_base;
- res.end += felix->switch_base;
-
- target = ocelot_regmap_init(ocelot, &res);
+ target = felix_request_regmap(felix, i);
if (IS_ERR(target)) {
dev_err(ocelot->dev,
- "Failed to map device memory space\n");
+ "Failed to map device memory space: %pe\n",
+ target);
kfree(port_phy_modes);
return PTR_ERR(target);
}
@@ -1379,7 +1415,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
for (port = 0; port < num_phys_ports; port++) {
struct ocelot_port *ocelot_port;
- struct regmap *target;
ocelot_port = devm_kzalloc(ocelot->dev,
sizeof(struct ocelot_port),
@@ -1391,15 +1426,11 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
return -ENOMEM;
}
- memcpy(&res, &felix->info->port_io_res[port], sizeof(res));
- res.start += felix->switch_base;
- res.end += felix->switch_base;
-
- target = ocelot_regmap_init(ocelot, &res);
+ target = felix_request_port_regmap(felix, port);
if (IS_ERR(target)) {
dev_err(ocelot->dev,
- "Failed to map memory space for port %d\n",
- port);
+ "Failed to map memory space for port %d: %pe\n",
+ port, target);
kfree(port_phy_modes);
return PTR_ERR(target);
}
diff --git a/drivers/net/dsa/ocelot/felix.h b/drivers/net/dsa/ocelot/felix.h
index 54322d0398fd..c9c29999c336 100644
--- a/drivers/net/dsa/ocelot/felix.h
+++ b/drivers/net/dsa/ocelot/felix.h
@@ -16,8 +16,13 @@
/* Platform-specific information */
struct felix_info {
- const struct resource *target_io_res;
- const struct resource *port_io_res;
+ /* Hardcoded resources provided by the hardware instantiation. */
+ const struct resource *resources;
+ size_t num_resources;
+ /* Names of the mandatory resources that will be requested during
+ * probe. Must have TARGET_MAX elements, since it is indexed by target.
+ */
+ const char *const *resource_names;
const struct reg_field *regfields;
const u32 *const *map;
const struct ocelot_ops *ops;
diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 1872727e80df..12810fea2075 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -477,26 +477,36 @@ static const u32 *vsc9959_regmap[TARGET_MAX] = {
};
/* Addresses are relative to the PCI device's base address */
-static const struct resource vsc9959_target_io_res[TARGET_MAX] = {
- [SYS] = DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
- [REW] = DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
- [S0] = DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
- [S1] = DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
- [S2] = DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
- [GCB] = DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
- [QS] = DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
- [PTP] = DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
- [QSYS] = DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
- [ANA] = DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
-};
-
-static const struct resource vsc9959_port_io_res[] = {
+static const struct resource vsc9959_resources[] = {
+ DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
+ DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
+ DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
+ DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
+ DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
+ DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
+ DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
+ DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
DEFINE_RES_MEM_NAMED(0x0100000, 0x0010000, "port0"),
DEFINE_RES_MEM_NAMED(0x0110000, 0x0010000, "port1"),
DEFINE_RES_MEM_NAMED(0x0120000, 0x0010000, "port2"),
DEFINE_RES_MEM_NAMED(0x0130000, 0x0010000, "port3"),
DEFINE_RES_MEM_NAMED(0x0140000, 0x0010000, "port4"),
DEFINE_RES_MEM_NAMED(0x0150000, 0x0010000, "port5"),
+ DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
+ DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
+};
+
+static const char * const vsc9959_resource_names[TARGET_MAX] = {
+ [SYS] = "sys",
+ [REW] = "rew",
+ [S0] = "s0",
+ [S1] = "s1",
+ [S2] = "s2",
+ [GCB] = "devcpu_gcb",
+ [QS] = "qs",
+ [PTP] = "ptp",
+ [QSYS] = "qsys",
+ [ANA] = "ana",
};
/* Port MAC 0 Internal MDIO bus through which the SerDes acting as an
@@ -2526,8 +2536,9 @@ static const struct ocelot_ops vsc9959_ops = {
};
static const struct felix_info felix_info_vsc9959 = {
- .target_io_res = vsc9959_target_io_res,
- .port_io_res = vsc9959_port_io_res,
+ .resources = vsc9959_resources,
+ .num_resources = ARRAY_SIZE(vsc9959_resources),
+ .resource_names = vsc9959_resource_names,
.regfields = vsc9959_regfields,
.map = vsc9959_regmap,
.ops = &vsc9959_ops,
diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c
index 66237c4385ac..7af33b2c685d 100644
--- a/drivers/net/dsa/ocelot/seville_vsc9953.c
+++ b/drivers/net/dsa/ocelot/seville_vsc9953.c
@@ -458,20 +458,15 @@ static const u32 *vsc9953_regmap[TARGET_MAX] = {
};
/* Addresses are relative to the device's base address */
-static const struct resource vsc9953_target_io_res[TARGET_MAX] = {
- [SYS] = DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
- [REW] = DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
- [S0] = DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
- [S1] = DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
- [S2] = DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
- [GCB] = DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
- [QS] = DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
- [PTP] = DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
- [QSYS] = DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
- [ANA] = DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
-};
-
-static const struct resource vsc9953_port_io_res[] = {
+static const struct resource vsc9953_resources[] = {
+ DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
+ DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
+ DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
+ DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
+ DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
+ DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
+ DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
+ DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
DEFINE_RES_MEM_NAMED(0x0100000, 0x0010000, "port0"),
DEFINE_RES_MEM_NAMED(0x0110000, 0x0010000, "port1"),
DEFINE_RES_MEM_NAMED(0x0120000, 0x0010000, "port2"),
@@ -482,6 +477,21 @@ static const struct resource vsc9953_port_io_res[] = {
DEFINE_RES_MEM_NAMED(0x0170000, 0x0010000, "port7"),
DEFINE_RES_MEM_NAMED(0x0180000, 0x0010000, "port8"),
DEFINE_RES_MEM_NAMED(0x0190000, 0x0010000, "port9"),
+ DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
+ DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
+};
+
+static const char * const vsc9953_resource_names[TARGET_MAX] = {
+ [SYS] = "sys",
+ [REW] = "rew",
+ [S0] = "s0",
+ [S1] = "s1",
+ [S2] = "s2",
+ [GCB] = "devcpu_gcb",
+ [QS] = "qs",
+ [PTP] = "ptp",
+ [QSYS] = "qsys",
+ [ANA] = "ana",
};
static const struct reg_field vsc9953_regfields[REGFIELD_MAX] = {
@@ -980,8 +990,9 @@ static void vsc9953_mdio_bus_free(struct ocelot *ocelot)
}
static const struct felix_info seville_info_vsc9953 = {
- .target_io_res = vsc9953_target_io_res,
- .port_io_res = vsc9953_port_io_res,
+ .resources = vsc9953_resources,
+ .num_resources = ARRAY_SIZE(vsc9953_resources),
+ .resource_names = vsc9953_resource_names,
.regfields = vsc9953_regfields,
.map = vsc9953_regmap,
.ops = &vsc9953_ops,
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 5/5] net: dsa: felix: update init_regmap to be string-based
2022-09-27 19:15 ` [PATCH net-next 5/5] net: dsa: felix: update init_regmap to be string-based Vladimir Oltean
@ 2022-09-27 19:27 ` Vladimir Oltean
2022-09-27 23:51 ` Jakub Kicinski
0 siblings, 1 reply; 11+ messages in thread
From: Vladimir Oltean @ 2022-09-27 19:27 UTC (permalink / raw)
To: netdev@vger.kernel.org
Cc: Andrew Lunn, Vivien Didelot, Florian Fainelli, Claudiu Manoil,
Alexandre Belloni, UNGLinuxDriver@microchip.com, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Colin Foster,
Maxim Kochetkov
On Tue, Sep 27, 2022 at 10:15:20PM +0300, Vladimir Oltean wrote:
> Existing felix DSA drivers (vsc9959, vsc9953) are all switches that were
> integrated in NXP SoCs, which makes them a bit unusual compared to the
> usual Microchip branded Ocelot switches.
Damn, I did something stupid, I reworded the commit title for this, and
I didn't rm -rf the patch output folder first, so now this patch is a
duplicate of the other 5/5.
I know I'm going to get a lot of hate for reposting in a matter of
minutes, so I won't, but on the other hand, patchwork took the wrong
patch (this one) as part of the series, and the other one as "Untitled
series #681176". The code is the same, just the commit message differs.
Can that be fixed in post-production or something?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 5/5] net: dsa: felix: update regmap requests to be string-based
2022-09-27 19:15 ` [PATCH net-next 5/5] net: dsa: felix: update regmap requests " Vladimir Oltean
@ 2022-09-27 20:28 ` Colin Foster
0 siblings, 0 replies; 11+ messages in thread
From: Colin Foster @ 2022-09-27 20:28 UTC (permalink / raw)
To: Vladimir Oltean
Cc: netdev, Andrew Lunn, Vivien Didelot, Florian Fainelli,
Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Maxim Kochetkov
On Tue, Sep 27, 2022 at 10:15:21PM +0300, Vladimir Oltean wrote:
> +static struct regmap *felix_request_regmap_by_name(struct felix *felix,
> + const char *resource_name)
> +{
> + struct ocelot *ocelot = &felix->ocelot;
> + struct resource res;
> + int i;
> +
I like it. And a simple:
if (!felix->resources)
return dev_get_regmap(ocelot->dev->parent, resource_name);
here (with an appropriate comment) would be all I need in the MFD
scenario.
I'll share the names via macros for "reg", "ana", etc. by way of
linux/mfd/ocelot.h, unless you think felix / seville also want them.
Thanks Vladimir!
> + for (i = 0; i < felix->info->num_resources; i++) {
> + if (strcmp(resource_name, felix->info->resources[i].name))
> + continue;
> +
> + memcpy(&res, &felix->info->resources[i], sizeof(res));
> + res.start += felix->switch_base;
> + res.end += felix->switch_base;
> +
> + return ocelot_regmap_init(ocelot, &res);
> + }
> +
> + return ERR_PTR(-ENOENT);
> +}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 5/5] net: dsa: felix: update init_regmap to be string-based
2022-09-27 19:27 ` Vladimir Oltean
@ 2022-09-27 23:51 ` Jakub Kicinski
0 siblings, 0 replies; 11+ messages in thread
From: Jakub Kicinski @ 2022-09-27 23:51 UTC (permalink / raw)
To: Vladimir Oltean
Cc: netdev@vger.kernel.org, Andrew Lunn, Vivien Didelot,
Florian Fainelli, Claudiu Manoil, Alexandre Belloni,
UNGLinuxDriver@microchip.com, David S. Miller, Eric Dumazet,
Paolo Abeni, Colin Foster, Maxim Kochetkov
On Tue, 27 Sep 2022 19:27:36 +0000 Vladimir Oltean wrote:
> On Tue, Sep 27, 2022 at 10:15:20PM +0300, Vladimir Oltean wrote:
> > Existing felix DSA drivers (vsc9959, vsc9953) are all switches that were
> > integrated in NXP SoCs, which makes them a bit unusual compared to the
> > usual Microchip branded Ocelot switches.
>
> Damn, I did something stupid, I reworded the commit title for this, and
> I didn't rm -rf the patch output folder first, so now this patch is a
> duplicate of the other 5/5.
>
> I know I'm going to get a lot of hate for reposting in a matter of
> minutes, so I won't, but on the other hand, patchwork took the wrong
> patch (this one) as part of the series, and the other one as "Untitled
> series #681176". The code is the same, just the commit message differs.
>
> Can that be fixed in post-production or something?
Just replace the commit message with the other 5/5? Can do.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver
2022-09-27 19:15 [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver Vladimir Oltean
` (5 preceding siblings ...)
2022-09-27 19:15 ` [PATCH net-next 5/5] net: dsa: felix: update regmap requests " Vladimir Oltean
@ 2022-09-29 2:50 ` patchwork-bot+netdevbpf
6 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-09-29 2:50 UTC (permalink / raw)
To: Vladimir Oltean
Cc: netdev, andrew, vivien.didelot, f.fainelli, claudiu.manoil,
alexandre.belloni, UNGLinuxDriver, davem, edumazet, kuba, pabeni,
colin.foster, fido_max
Hello:
This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 27 Sep 2022 22:15:15 +0300 you wrote:
> The Felix DSA driver controls NXP variations of Microchip switches.
> Colin Foster is trying to add support in this driver for "genuine"
> Microchip hardware, but some of the NXP-isms in this driver need to go
> away before that happens cleanly.
> https://patchwork.kernel.org/project/netdevbpf/cover/20220926002928.2744638-1-colin.foster@in-advantage.com/
>
> The starting point was Colin's patch 08/14 "net: dsa: felix: update
> init_regmap to be string-based", and this continues to be the central
> theme here, but things are done differently.
>
> [...]
Here is the summary with links:
- [net-next,1/5] net: dsa: felix: remove felix_info :: imdio_res
https://git.kernel.org/netdev/net-next/c/5fc080de89f1
- [net-next,2/5] net: dsa: felix: remove felix_info :: imdio_base
https://git.kernel.org/netdev/net-next/c/1382ba68a053
- [net-next,3/5] net: dsa: felix: remove felix_info :: init_regmap
https://git.kernel.org/netdev/net-next/c/8f66c64bfca3
- [net-next,4/5] net: dsa: felix: use DEFINE_RES_MEM_NAMED for resources
https://git.kernel.org/netdev/net-next/c/044d447a801f
- [net-next,5/5] net: dsa: felix: update init_regmap to be string-based
https://git.kernel.org/netdev/net-next/c/1109b97b6161
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-09-29 2:50 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-27 19:15 [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 1/5] net: dsa: felix: remove felix_info :: imdio_res Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 2/5] net: dsa: felix: remove felix_info :: imdio_base Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 3/5] net: dsa: felix: remove felix_info :: init_regmap Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 4/5] net: dsa: felix: use DEFINE_RES_MEM_NAMED for resources Vladimir Oltean
2022-09-27 19:15 ` [PATCH net-next 5/5] net: dsa: felix: update init_regmap to be string-based Vladimir Oltean
2022-09-27 19:27 ` Vladimir Oltean
2022-09-27 23:51 ` Jakub Kicinski
2022-09-27 19:15 ` [PATCH net-next 5/5] net: dsa: felix: update regmap requests " Vladimir Oltean
2022-09-27 20:28 ` Colin Foster
2022-09-29 2:50 ` [PATCH net-next 0/5] Rework resource allocation in Felix DSA driver patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).