Commit 7e99e347 authored by Vivien Didelot's avatar Vivien Didelot Committed by Jakub Kicinski

net: dsa: remove dsa_switch_alloc helper

Now that ports are dynamically listed in the fabric, there is no need
to provide a special helper to allocate the dsa_switch structure. This
will give more flexibility to drivers to embed this structure as they
wish in their private structure.
Signed-off-by: default avatarVivien Didelot <vivien.didelot@gmail.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
parent 05f294a8
...@@ -2341,10 +2341,13 @@ struct b53_device *b53_switch_alloc(struct device *base, ...@@ -2341,10 +2341,13 @@ struct b53_device *b53_switch_alloc(struct device *base,
struct dsa_switch *ds; struct dsa_switch *ds;
struct b53_device *dev; struct b53_device *dev;
ds = dsa_switch_alloc(base, DSA_MAX_PORTS); ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
if (!ds) if (!ds)
return NULL; return NULL;
ds->dev = base;
ds->num_ports = DSA_MAX_PORTS;
dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
if (!dev) if (!dev)
return NULL; return NULL;
......
...@@ -286,10 +286,13 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev) ...@@ -286,10 +286,13 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev)
dev_info(&mdiodev->dev, "%s: 0x%0x\n", dev_info(&mdiodev->dev, "%s: 0x%0x\n",
pdata->name, pdata->enabled_ports); pdata->name, pdata->enabled_ports);
ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS); ds = devm_kzalloc(&mdiodev->dev, sizeof(*ds), GFP_KERNEL);
if (!ds) if (!ds)
return -ENOMEM; return -ENOMEM;
ds->dev = &mdiodev->dev;
ds->num_ports = DSA_MAX_PORTS;
ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL); ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL);
if (!ps) if (!ps)
return -ENOMEM; return -ENOMEM;
......
...@@ -1283,10 +1283,12 @@ static int lan9303_register_switch(struct lan9303 *chip) ...@@ -1283,10 +1283,12 @@ static int lan9303_register_switch(struct lan9303 *chip)
{ {
int base; int base;
chip->ds = dsa_switch_alloc(chip->dev, LAN9303_NUM_PORTS); chip->ds = devm_kzalloc(chip->dev, sizeof(*chip->ds), GFP_KERNEL);
if (!chip->ds) if (!chip->ds)
return -ENOMEM; return -ENOMEM;
chip->ds->dev = chip->dev;
chip->ds->num_ports = LAN9303_NUM_PORTS;
chip->ds->priv = chip; chip->ds->priv = chip;
chip->ds->ops = &lan9303_switch_ops; chip->ds->ops = &lan9303_switch_ops;
base = chip->phy_addr_base; base = chip->phy_addr_base;
......
...@@ -1854,10 +1854,12 @@ static int gswip_probe(struct platform_device *pdev) ...@@ -1854,10 +1854,12 @@ static int gswip_probe(struct platform_device *pdev)
if (!priv->hw_info) if (!priv->hw_info)
return -EINVAL; return -EINVAL;
priv->ds = dsa_switch_alloc(dev, priv->hw_info->max_ports); priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL);
if (!priv->ds) if (!priv->ds)
return -ENOMEM; return -ENOMEM;
priv->ds->dev = dev;
priv->ds->num_ports = priv->hw_info->max_ports;
priv->ds->priv = priv; priv->ds->priv = priv;
priv->ds->ops = &gswip_switch_ops; priv->ds->ops = &gswip_switch_ops;
priv->dev = dev; priv->dev = dev;
......
...@@ -398,10 +398,13 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv) ...@@ -398,10 +398,13 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
struct dsa_switch *ds; struct dsa_switch *ds;
struct ksz_device *swdev; struct ksz_device *swdev;
ds = dsa_switch_alloc(base, DSA_MAX_PORTS); ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
if (!ds) if (!ds)
return NULL; return NULL;
ds->dev = base;
ds->num_ports = DSA_MAX_PORTS;
swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL); swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL);
if (!swdev) if (!swdev)
return NULL; return NULL;
......
...@@ -1632,10 +1632,13 @@ mt7530_probe(struct mdio_device *mdiodev) ...@@ -1632,10 +1632,13 @@ mt7530_probe(struct mdio_device *mdiodev)
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
priv->ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS); priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL);
if (!priv->ds) if (!priv->ds)
return -ENOMEM; return -ENOMEM;
priv->ds->dev = &mdiodev->dev;
priv->ds->num_ports = DSA_MAX_PORTS;
/* Use medatek,mcm property to distinguish hardware type that would /* Use medatek,mcm property to distinguish hardware type that would
* casues a little bit differences on power-on sequence. * casues a little bit differences on power-on sequence.
*/ */
......
...@@ -270,10 +270,12 @@ static int mv88e6060_probe(struct mdio_device *mdiodev) ...@@ -270,10 +270,12 @@ static int mv88e6060_probe(struct mdio_device *mdiodev)
dev_info(dev, "switch %s detected\n", name); dev_info(dev, "switch %s detected\n", name);
ds = dsa_switch_alloc(dev, MV88E6060_PORTS); ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
if (!ds) if (!ds)
return -ENOMEM; return -ENOMEM;
ds->dev = dev;
ds->num_ports = MV88E6060_PORTS;
ds->priv = priv; ds->priv = priv;
ds->dev = dev; ds->dev = dev;
ds->ops = &mv88e6060_switch_ops; ds->ops = &mv88e6060_switch_ops;
......
...@@ -4978,10 +4978,12 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip) ...@@ -4978,10 +4978,12 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
struct device *dev = chip->dev; struct device *dev = chip->dev;
struct dsa_switch *ds; struct dsa_switch *ds;
ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip)); ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
if (!ds) if (!ds)
return -ENOMEM; return -ENOMEM;
ds->dev = dev;
ds->num_ports = mv88e6xxx_num_ports(chip);
ds->priv = chip; ds->priv = chip;
ds->dev = dev; ds->dev = dev;
ds->ops = &mv88e6xxx_switch_ops; ds->ops = &mv88e6xxx_switch_ops;
......
...@@ -1077,10 +1077,13 @@ qca8k_sw_probe(struct mdio_device *mdiodev) ...@@ -1077,10 +1077,13 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
if (id != QCA8K_ID_QCA8337) if (id != QCA8K_ID_QCA8337)
return -ENODEV; return -ENODEV;
priv->ds = dsa_switch_alloc(&mdiodev->dev, QCA8K_NUM_PORTS); priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds),
QCA8K_NUM_PORTS);
if (!priv->ds) if (!priv->ds)
return -ENOMEM; return -ENOMEM;
priv->ds->dev = &mdiodev->dev;
priv->ds->num_ports = DSA_MAX_PORTS;
priv->ds->priv = priv; priv->ds->priv = priv;
priv->ops = qca8k_switch_ops; priv->ops = qca8k_switch_ops;
priv->ds->ops = &priv->ops; priv->ds->ops = &priv->ops;
......
...@@ -444,9 +444,12 @@ static int realtek_smi_probe(struct platform_device *pdev) ...@@ -444,9 +444,12 @@ static int realtek_smi_probe(struct platform_device *pdev)
return ret; return ret;
} }
smi->ds = dsa_switch_alloc(dev, smi->num_ports); smi->ds = devm_kzalloc(dev, sizeof(*smi->ds), GFP_KERNEL);
if (!smi->ds) if (!smi->ds)
return -ENOMEM; return -ENOMEM;
smi->ds->dev = dev;
smi->ds->num_ports = smi->num_ports;
smi->ds->priv = smi; smi->ds->priv = smi;
smi->ds->ops = var->ds_ops; smi->ds->ops = var->ds_ops;
......
...@@ -2047,10 +2047,12 @@ static int sja1105_probe(struct spi_device *spi) ...@@ -2047,10 +2047,12 @@ static int sja1105_probe(struct spi_device *spi)
dev_info(dev, "Probed switch chip: %s\n", priv->info->name); dev_info(dev, "Probed switch chip: %s\n", priv->info->name);
ds = dsa_switch_alloc(dev, SJA1105_NUM_PORTS); ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
if (!ds) if (!ds)
return -ENOMEM; return -ENOMEM;
ds->dev = dev;
ds->num_ports = SJA1105_NUM_PORTS;
ds->ops = &sja1105_switch_ops; ds->ops = &sja1105_switch_ops;
ds->priv = priv; ds->priv = priv;
priv->ds = ds; priv->ds = ds;
......
...@@ -1178,9 +1178,12 @@ int vsc73xx_probe(struct vsc73xx *vsc) ...@@ -1178,9 +1178,12 @@ int vsc73xx_probe(struct vsc73xx *vsc)
* We allocate 8 ports and avoid access to the nonexistant * We allocate 8 ports and avoid access to the nonexistant
* ports. * ports.
*/ */
vsc->ds = dsa_switch_alloc(dev, 8); vsc->ds = devm_kzalloc(dev, sizeof(*vsc->ds), GFP_KERNEL);
if (!vsc->ds) if (!vsc->ds)
return -ENOMEM; return -ENOMEM;
vsc->ds->dev = dev;
vsc->ds->num_ports = 8;
vsc->ds->priv = vsc; vsc->ds->priv = vsc;
vsc->ds->ops = &vsc73xx_ds_ops; vsc->ds->ops = &vsc73xx_ds_ops;
......
...@@ -577,7 +577,6 @@ static inline bool dsa_can_decode(const struct sk_buff *skb, ...@@ -577,7 +577,6 @@ static inline bool dsa_can_decode(const struct sk_buff *skb,
return false; return false;
} }
struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
void dsa_unregister_switch(struct dsa_switch *ds); void dsa_unregister_switch(struct dsa_switch *ds);
int dsa_register_switch(struct dsa_switch *ds); int dsa_register_switch(struct dsa_switch *ds);
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
......
...@@ -846,6 +846,12 @@ static int dsa_switch_probe(struct dsa_switch *ds) ...@@ -846,6 +846,12 @@ static int dsa_switch_probe(struct dsa_switch *ds)
struct device_node *np = ds->dev->of_node; struct device_node *np = ds->dev->of_node;
int err; int err;
if (!ds->dev)
return -ENODEV;
if (!ds->num_ports)
return -EINVAL;
if (np) if (np)
err = dsa_switch_parse_of(ds, np); err = dsa_switch_parse_of(ds, np);
else if (pdata) else if (pdata)
...@@ -859,21 +865,6 @@ static int dsa_switch_probe(struct dsa_switch *ds) ...@@ -859,21 +865,6 @@ static int dsa_switch_probe(struct dsa_switch *ds)
return dsa_switch_add(ds); return dsa_switch_add(ds);
} }
struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n)
{
struct dsa_switch *ds;
ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
if (!ds)
return NULL;
ds->dev = dev;
ds->num_ports = n;
return ds;
}
EXPORT_SYMBOL_GPL(dsa_switch_alloc);
int dsa_register_switch(struct dsa_switch *ds) int dsa_register_switch(struct dsa_switch *ds)
{ {
int err; int err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment