Skip to content

Commit

Permalink
felix: Fix initialization of ioremap resources
Browse files Browse the repository at this point in the history
The caller of devm_ioremap_resource(), either accidentally
or by wrong assumption, is writing back derived resource data
to global static resource initialization tables that should
have been constant.  Meaning that after it computes the final
physical start address it saves the address for no reason
in the static tables.  This doesn't affect the first driver
probing after reboot, but it breaks consecutive driver reloads
(i.e. driver unbind & bind) because the initialization tables
no longer have the correct initial values.  So the next probe()
will map the device registers to wrong physical addresses,
causing ARM SError async exceptions.
This patch fixes all of the above.

Fixes: 5605194 ("net: dsa: ocelot: add driver for Felix switch family")
Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Claudiu Manoil authored and David S. Miller committed May 22, 2020
1 parent bd69722 commit b4024c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
23 changes: 11 additions & 12 deletions drivers/net/dsa/ocelot/felix.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
struct ocelot *ocelot = &felix->ocelot;
phy_interface_t *port_phy_modes;
resource_size_t switch_base;
struct resource res;
int port, i, err;

ocelot->num_phys_ports = num_phys_ports;
Expand Down Expand Up @@ -422,17 +423,16 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)

for (i = 0; i < TARGET_MAX; i++) {
struct regmap *target;
struct resource *res;

if (!felix->info->target_io_res[i].name)
continue;

res = &felix->info->target_io_res[i];
res->flags = IORESOURCE_MEM;
res->start += switch_base;
res->end += switch_base;
memcpy(&res, &felix->info->target_io_res[i], sizeof(res));
res.flags = IORESOURCE_MEM;
res.start += switch_base;
res.end += switch_base;

target = ocelot_regmap_init(ocelot, res);
target = ocelot_regmap_init(ocelot, &res);
if (IS_ERR(target)) {
dev_err(ocelot->dev,
"Failed to map device memory space\n");
Expand All @@ -453,7 +453,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;
void __iomem *port_regs;
struct resource *res;

ocelot_port = devm_kzalloc(ocelot->dev,
sizeof(struct ocelot_port),
Expand All @@ -465,12 +464,12 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
return -ENOMEM;
}

res = &felix->info->port_io_res[port];
res->flags = IORESOURCE_MEM;
res->start += switch_base;
res->end += switch_base;
memcpy(&res, &felix->info->port_io_res[port], sizeof(res));
res.flags = IORESOURCE_MEM;
res.start += switch_base;
res.end += switch_base;

port_regs = devm_ioremap_resource(ocelot->dev, res);
port_regs = devm_ioremap_resource(ocelot->dev, &res);
if (IS_ERR(port_regs)) {
dev_err(ocelot->dev,
"failed to map registers for port %d\n", port);
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/dsa/ocelot/felix.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

/* Platform-specific information */
struct felix_info {
struct resource *target_io_res;
struct resource *port_io_res;
struct resource *imdio_res;
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;
Expand Down
22 changes: 10 additions & 12 deletions drivers/net/dsa/ocelot/felix_vsc9959.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,8 @@ static const u32 *vsc9959_regmap[] = {
[GCB] = vsc9959_gcb_regmap,
};

/* Addresses are relative to the PCI device's base address and
* will be fixed up at ioremap time.
*/
static struct resource vsc9959_target_io_res[] = {
/* Addresses are relative to the PCI device's base address */
static const struct resource vsc9959_target_io_res[] = {
[ANA] = {
.start = 0x0280000,
.end = 0x028ffff,
Expand Down Expand Up @@ -379,7 +377,7 @@ static struct resource vsc9959_target_io_res[] = {
},
};

static struct resource vsc9959_port_io_res[] = {
static const struct resource vsc9959_port_io_res[] = {
{
.start = 0x0100000,
.end = 0x010ffff,
Expand Down Expand Up @@ -415,7 +413,7 @@ static struct resource vsc9959_port_io_res[] = {
/* Port MAC 0 Internal MDIO bus through which the SerDes acting as an
* SGMII/QSGMII MAC PCS can be found.
*/
static struct resource vsc9959_imdio_res = {
static const struct resource vsc9959_imdio_res = {
.start = 0x8030,
.end = 0x8040,
.name = "imdio",
Expand Down Expand Up @@ -1111,7 +1109,7 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
struct device *dev = ocelot->dev;
resource_size_t imdio_base;
void __iomem *imdio_regs;
struct resource *res;
struct resource res;
struct enetc_hw *hw;
struct mii_bus *bus;
int port;
Expand All @@ -1128,12 +1126,12 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
imdio_base = pci_resource_start(felix->pdev,
felix->info->imdio_pci_bar);

res = felix->info->imdio_res;
res->flags = IORESOURCE_MEM;
res->start += imdio_base;
res->end += imdio_base;
memcpy(&res, felix->info->imdio_res, sizeof(res));
res.flags = IORESOURCE_MEM;
res.start += imdio_base;
res.end += imdio_base;

imdio_regs = devm_ioremap_resource(dev, res);
imdio_regs = devm_ioremap_resource(dev, &res);
if (IS_ERR(imdio_regs)) {
dev_err(dev, "failed to map internal MDIO registers\n");
return PTR_ERR(imdio_regs);
Expand Down

0 comments on commit b4024c9

Please sign in to comment.