mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 04:31:50 +00:00
net: dsa: Have the switch driver allocate there own private memory
Now the switch devices have a dev pointer, make use of it for allocating the drivers private data structures using a devm_kzalloc(). Signed-off-by: Andrew Lunn <andrew@lunn.ch> Acked-by: Florian Fainelli <f.fainelli@gmail.com> Tested-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
bbb8d79399
commit
7543a6d535
@ -136,8 +136,15 @@ static int bcm_sf2_sw_get_sset_count(struct dsa_switch *ds)
|
||||
}
|
||||
|
||||
static char *bcm_sf2_sw_probe(struct device *dsa_dev, struct device *host_dev,
|
||||
int sw_addr)
|
||||
int sw_addr, void **_priv)
|
||||
{
|
||||
struct bcm_sf2_priv *priv;
|
||||
|
||||
priv = devm_kzalloc(dsa_dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return NULL;
|
||||
*_priv = priv;
|
||||
|
||||
return "Broadcom Starfighter 2";
|
||||
}
|
||||
|
||||
@ -1363,7 +1370,6 @@ static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
|
||||
|
||||
static struct dsa_switch_driver bcm_sf2_switch_driver = {
|
||||
.tag_protocol = DSA_TAG_PROTO_BRCM,
|
||||
.priv_size = sizeof(struct bcm_sf2_priv),
|
||||
.probe = bcm_sf2_sw_probe,
|
||||
.setup = bcm_sf2_sw_setup,
|
||||
.set_addr = bcm_sf2_sw_set_addr,
|
||||
|
@ -58,11 +58,12 @@ static int reg_write(struct dsa_switch *ds, int addr, int reg, u16 val)
|
||||
})
|
||||
|
||||
static char *mv88e6060_probe(struct device *dsa_dev, struct device *host_dev,
|
||||
int sw_addr)
|
||||
int sw_addr, void **priv)
|
||||
{
|
||||
struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
|
||||
int ret;
|
||||
|
||||
*priv = NULL;
|
||||
if (bus == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -30,10 +30,20 @@ static const struct mv88e6xxx_switch_id mv88e6123_table[] = {
|
||||
};
|
||||
|
||||
static char *mv88e6123_probe(struct device *dsa_dev, struct device *host_dev,
|
||||
int sw_addr)
|
||||
int sw_addr, void **priv)
|
||||
{
|
||||
return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6123_table,
|
||||
struct mv88e6xxx_priv_state *ps;
|
||||
char *name;
|
||||
|
||||
name = mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6123_table,
|
||||
ARRAY_SIZE(mv88e6123_table));
|
||||
if (name) {
|
||||
ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL);
|
||||
if (!ps)
|
||||
return NULL;
|
||||
*priv = ps;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static int mv88e6123_setup_global(struct dsa_switch *ds)
|
||||
@ -74,6 +84,8 @@ static int mv88e6123_setup(struct dsa_switch *ds)
|
||||
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
|
||||
int ret;
|
||||
|
||||
ps->ds = ds;
|
||||
|
||||
ret = mv88e6xxx_setup_common(ds);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@ -103,7 +115,6 @@ static int mv88e6123_setup(struct dsa_switch *ds)
|
||||
|
||||
struct dsa_switch_driver mv88e6123_switch_driver = {
|
||||
.tag_protocol = DSA_TAG_PROTO_EDSA,
|
||||
.priv_size = sizeof(struct mv88e6xxx_priv_state),
|
||||
.probe = mv88e6123_probe,
|
||||
.setup = mv88e6123_setup,
|
||||
.set_addr = mv88e6xxx_set_addr_indirect,
|
||||
|
@ -26,10 +26,20 @@ static const struct mv88e6xxx_switch_id mv88e6131_table[] = {
|
||||
};
|
||||
|
||||
static char *mv88e6131_probe(struct device *dsa_dev, struct device *host_dev,
|
||||
int sw_addr)
|
||||
int sw_addr, void **priv)
|
||||
{
|
||||
return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6131_table,
|
||||
struct mv88e6xxx_priv_state *ps;
|
||||
char *name;
|
||||
|
||||
name = mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6131_table,
|
||||
ARRAY_SIZE(mv88e6131_table));
|
||||
if (name) {
|
||||
ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL);
|
||||
if (!ps)
|
||||
return NULL;
|
||||
*priv = ps;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static int mv88e6131_setup_global(struct dsa_switch *ds)
|
||||
@ -92,6 +102,8 @@ static int mv88e6131_setup(struct dsa_switch *ds)
|
||||
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
|
||||
int ret;
|
||||
|
||||
ps->ds = ds;
|
||||
|
||||
ret = mv88e6xxx_setup_common(ds);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@ -160,7 +172,6 @@ mv88e6131_phy_write(struct dsa_switch *ds,
|
||||
|
||||
struct dsa_switch_driver mv88e6131_switch_driver = {
|
||||
.tag_protocol = DSA_TAG_PROTO_DSA,
|
||||
.priv_size = sizeof(struct mv88e6xxx_priv_state),
|
||||
.probe = mv88e6131_probe,
|
||||
.setup = mv88e6131_setup,
|
||||
.set_addr = mv88e6xxx_set_addr_direct,
|
||||
|
@ -25,10 +25,20 @@ static const struct mv88e6xxx_switch_id mv88e6171_table[] = {
|
||||
};
|
||||
|
||||
static char *mv88e6171_probe(struct device *dsa_dev, struct device *host_dev,
|
||||
int sw_addr)
|
||||
int sw_addr, void **priv)
|
||||
{
|
||||
return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6171_table,
|
||||
struct mv88e6xxx_priv_state *ps;
|
||||
char *name;
|
||||
|
||||
name = mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6171_table,
|
||||
ARRAY_SIZE(mv88e6171_table));
|
||||
if (name) {
|
||||
ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL);
|
||||
if (!ps)
|
||||
return NULL;
|
||||
*priv = ps;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static int mv88e6171_setup_global(struct dsa_switch *ds)
|
||||
@ -70,6 +80,8 @@ static int mv88e6171_setup(struct dsa_switch *ds)
|
||||
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
|
||||
int ret;
|
||||
|
||||
ps->ds = ds;
|
||||
|
||||
ret = mv88e6xxx_setup_common(ds);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@ -89,7 +101,6 @@ static int mv88e6171_setup(struct dsa_switch *ds)
|
||||
|
||||
struct dsa_switch_driver mv88e6171_switch_driver = {
|
||||
.tag_protocol = DSA_TAG_PROTO_EDSA,
|
||||
.priv_size = sizeof(struct mv88e6xxx_priv_state),
|
||||
.probe = mv88e6171_probe,
|
||||
.setup = mv88e6171_setup,
|
||||
.set_addr = mv88e6xxx_set_addr_indirect,
|
||||
|
@ -38,10 +38,20 @@ static const struct mv88e6xxx_switch_id mv88e6352_table[] = {
|
||||
};
|
||||
|
||||
static char *mv88e6352_probe(struct device *dsa_dev, struct device *host_dev,
|
||||
int sw_addr)
|
||||
int sw_addr, void **priv)
|
||||
{
|
||||
return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6352_table,
|
||||
struct mv88e6xxx_priv_state *ps;
|
||||
char *name;
|
||||
|
||||
name = mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6352_table,
|
||||
ARRAY_SIZE(mv88e6352_table));
|
||||
if (name) {
|
||||
ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL);
|
||||
if (!ps)
|
||||
return NULL;
|
||||
*priv = ps;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static int mv88e6352_setup_global(struct dsa_switch *ds)
|
||||
@ -82,6 +92,8 @@ static int mv88e6352_setup(struct dsa_switch *ds)
|
||||
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
|
||||
int ret;
|
||||
|
||||
ps->ds = ds;
|
||||
|
||||
ret = mv88e6xxx_setup_common(ds);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@ -303,7 +315,6 @@ static int mv88e6352_set_eeprom(struct dsa_switch *ds,
|
||||
|
||||
struct dsa_switch_driver mv88e6352_switch_driver = {
|
||||
.tag_protocol = DSA_TAG_PROTO_EDSA,
|
||||
.priv_size = sizeof(struct mv88e6xxx_priv_state),
|
||||
.probe = mv88e6352_probe,
|
||||
.setup = mv88e6352_setup,
|
||||
.set_addr = mv88e6xxx_set_addr_indirect,
|
||||
|
@ -281,7 +281,7 @@ static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
|
||||
|
||||
ps = container_of(ugly, struct mv88e6xxx_priv_state, ppu_work);
|
||||
if (mutex_trylock(&ps->ppu_mutex)) {
|
||||
struct dsa_switch *ds = ((struct dsa_switch *)ps) - 1;
|
||||
struct dsa_switch *ds = ps->ds;
|
||||
|
||||
if (mv88e6xxx_ppu_enable(ds) == 0)
|
||||
ps->ppu_disabled = 0;
|
||||
@ -2322,7 +2322,7 @@ static void mv88e6xxx_bridge_work(struct work_struct *work)
|
||||
int port;
|
||||
|
||||
ps = container_of(work, struct mv88e6xxx_priv_state, bridge_work);
|
||||
ds = ((struct dsa_switch *)ps) - 1;
|
||||
ds = ps->ds;
|
||||
|
||||
mutex_lock(&ps->smi_mutex);
|
||||
|
||||
@ -2670,6 +2670,8 @@ int mv88e6xxx_setup_common(struct dsa_switch *ds)
|
||||
{
|
||||
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
|
||||
|
||||
ps->ds = ds;
|
||||
|
||||
mutex_init(&ps->smi_mutex);
|
||||
|
||||
ps->id = REG_READ(REG_PORT(0), PORT_SWITCH_ID) & 0xfff0;
|
||||
|
@ -397,6 +397,9 @@ struct mv88e6xxx_priv_port {
|
||||
};
|
||||
|
||||
struct mv88e6xxx_priv_state {
|
||||
/* The dsa_switch this private structure is related to */
|
||||
struct dsa_switch *ds;
|
||||
|
||||
/* When using multi-chip addressing, this mutex protects
|
||||
* access to the indirect access registers. (In single-chip
|
||||
* mode, this mutex is effectively useless.)
|
||||
|
@ -129,6 +129,12 @@ struct dsa_switch {
|
||||
struct dsa_switch_tree *dst;
|
||||
int index;
|
||||
|
||||
/*
|
||||
* Give the switch driver somewhere to hang its private data
|
||||
* structure.
|
||||
*/
|
||||
void *priv;
|
||||
|
||||
/*
|
||||
* Tagging protocol understood by this switch
|
||||
*/
|
||||
@ -213,7 +219,7 @@ struct dsa_switch_driver {
|
||||
* Probing and setup.
|
||||
*/
|
||||
char *(*probe)(struct device *dsa_dev, struct device *host_dev,
|
||||
int sw_addr);
|
||||
int sw_addr, void **priv);
|
||||
int (*setup)(struct dsa_switch *ds);
|
||||
int (*set_addr)(struct dsa_switch *ds, u8 *addr);
|
||||
u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
|
||||
@ -342,7 +348,7 @@ struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
|
||||
|
||||
static inline void *ds_to_priv(struct dsa_switch *ds)
|
||||
{
|
||||
return (void *)(ds + 1);
|
||||
return ds->priv;
|
||||
}
|
||||
|
||||
static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
|
||||
|
@ -52,7 +52,7 @@ EXPORT_SYMBOL_GPL(unregister_switch_driver);
|
||||
|
||||
static struct dsa_switch_driver *
|
||||
dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
|
||||
char **_name)
|
||||
char **_name, void **priv)
|
||||
{
|
||||
struct dsa_switch_driver *ret;
|
||||
struct list_head *list;
|
||||
@ -67,7 +67,7 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
|
||||
|
||||
drv = list_entry(list, struct dsa_switch_driver, list);
|
||||
|
||||
name = drv->probe(parent, host_dev, sw_addr);
|
||||
name = drv->probe(parent, host_dev, sw_addr, priv);
|
||||
if (name != NULL) {
|
||||
ret = drv;
|
||||
break;
|
||||
@ -384,11 +384,12 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
|
||||
struct dsa_switch *ds;
|
||||
int ret;
|
||||
char *name;
|
||||
void *priv;
|
||||
|
||||
/*
|
||||
* Probe for switch model.
|
||||
*/
|
||||
drv = dsa_switch_probe(parent, host_dev, pd->sw_addr, &name);
|
||||
drv = dsa_switch_probe(parent, host_dev, pd->sw_addr, &name, &priv);
|
||||
if (drv == NULL) {
|
||||
netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n",
|
||||
index);
|
||||
@ -409,6 +410,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
|
||||
ds->index = index;
|
||||
ds->pd = pd;
|
||||
ds->drv = drv;
|
||||
ds->priv = priv;
|
||||
ds->tag_protocol = drv->tag_protocol;
|
||||
ds->master_dev = host_dev;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user