]> git.baikalelectronics.ru Git - kernel.git/commitdiff
felix: Fix initialization of ioremap resources
authorClaudiu Manoil <claudiu.manoil@nxp.com>
Fri, 22 May 2020 08:54:34 +0000 (11:54 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 22 May 2020 21:24:46 +0000 (14:24 -0700)
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: 34efb4cbfb94 ("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>
drivers/net/dsa/ocelot/felix.c
drivers/net/dsa/ocelot/felix.h
drivers/net/dsa/ocelot/felix_vsc9959.c

index e2c6bf0e430e8a9e78d82506b23c5dc6968217ab..e8aae64db1caa30e65d0d4d7f13b573d4574d3c2 100644 (file)
@@ -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;
@@ -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");
@@ -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),
@@ -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);
index 9af106513e5308c2a4bad3d108c844af3ad9342e..730a8a90e1f79a20ce4d97fc71b5776c6135d577 100644 (file)
@@ -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;
index 8bf395f12b47760f7b3bd73c207f53955d34f815..5211f05ef2fbf48668f7931d5dfa6ad62700f73e 100644 (file)
@@ -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,
@@ -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,
@@ -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",
@@ -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;
@@ -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);