aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Lunn <andrew@lunn.ch>2016-04-12 20:40:40 -0400
committerDavid S. Miller <davem@davemloft.net>2016-04-13 18:15:23 -0400
commit7543a6d5359e371ce9434955dbe6a79f548ea321 (patch)
tree84401371308e64ff4ca525e410619e5e223e5112
parentbbb8d793994c894eef2a48a35fac6de3c6b4fa93 (diff)
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>
-rw-r--r--drivers/net/dsa/bcm_sf2.c10
-rw-r--r--drivers/net/dsa/mv88e6060.c3
-rw-r--r--drivers/net/dsa/mv88e6123.c17
-rw-r--r--drivers/net/dsa/mv88e6131.c17
-rw-r--r--drivers/net/dsa/mv88e6171.c17
-rw-r--r--drivers/net/dsa/mv88e6352.c17
-rw-r--r--drivers/net/dsa/mv88e6xxx.c6
-rw-r--r--drivers/net/dsa/mv88e6xxx.h3
-rw-r--r--include/net/dsa.h10
-rw-r--r--net/dsa/dsa.c8
10 files changed, 86 insertions, 22 deletions
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 18a79579141f..7d62802a66d5 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -136,8 +136,15 @@ static int bcm_sf2_sw_get_sset_count(struct dsa_switch *ds)
136} 136}
137 137
138static char *bcm_sf2_sw_probe(struct device *dsa_dev, struct device *host_dev, 138static char *bcm_sf2_sw_probe(struct device *dsa_dev, struct device *host_dev,
139 int sw_addr) 139 int sw_addr, void **_priv)
140{ 140{
141 struct bcm_sf2_priv *priv;
142
143 priv = devm_kzalloc(dsa_dev, sizeof(*priv), GFP_KERNEL);
144 if (!priv)
145 return NULL;
146 *_priv = priv;
147
141 return "Broadcom Starfighter 2"; 148 return "Broadcom Starfighter 2";
142} 149}
143 150
@@ -1363,7 +1370,6 @@ static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
1363 1370
1364static struct dsa_switch_driver bcm_sf2_switch_driver = { 1371static struct dsa_switch_driver bcm_sf2_switch_driver = {
1365 .tag_protocol = DSA_TAG_PROTO_BRCM, 1372 .tag_protocol = DSA_TAG_PROTO_BRCM,
1366 .priv_size = sizeof(struct bcm_sf2_priv),
1367 .probe = bcm_sf2_sw_probe, 1373 .probe = bcm_sf2_sw_probe,
1368 .setup = bcm_sf2_sw_setup, 1374 .setup = bcm_sf2_sw_setup,
1369 .set_addr = bcm_sf2_sw_set_addr, 1375 .set_addr = bcm_sf2_sw_set_addr,
diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c
index 34d0f9fe19db..41195f1417f1 100644
--- a/drivers/net/dsa/mv88e6060.c
+++ b/drivers/net/dsa/mv88e6060.c
@@ -58,11 +58,12 @@ static int reg_write(struct dsa_switch *ds, int addr, int reg, u16 val)
58 }) 58 })
59 59
60static char *mv88e6060_probe(struct device *dsa_dev, struct device *host_dev, 60static char *mv88e6060_probe(struct device *dsa_dev, struct device *host_dev,
61 int sw_addr) 61 int sw_addr, void **priv)
62{ 62{
63 struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev); 63 struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
64 int ret; 64 int ret;
65 65
66 *priv = NULL;
66 if (bus == NULL) 67 if (bus == NULL)
67 return NULL; 68 return NULL;
68 69
diff --git a/drivers/net/dsa/mv88e6123.c b/drivers/net/dsa/mv88e6123.c
index ede4c6f0b31a..bcab3ef22448 100644
--- a/drivers/net/dsa/mv88e6123.c
+++ b/drivers/net/dsa/mv88e6123.c
@@ -30,10 +30,20 @@ static const struct mv88e6xxx_switch_id mv88e6123_table[] = {
30}; 30};
31 31
32static char *mv88e6123_probe(struct device *dsa_dev, struct device *host_dev, 32static char *mv88e6123_probe(struct device *dsa_dev, struct device *host_dev,
33 int sw_addr) 33 int sw_addr, void **priv)
34{ 34{
35 return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6123_table, 35 struct mv88e6xxx_priv_state *ps;
36 char *name;
37
38 name = mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6123_table,
36 ARRAY_SIZE(mv88e6123_table)); 39 ARRAY_SIZE(mv88e6123_table));
40 if (name) {
41 ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL);
42 if (!ps)
43 return NULL;
44 *priv = ps;
45 }
46 return name;
37} 47}
38 48
39static int mv88e6123_setup_global(struct dsa_switch *ds) 49static int mv88e6123_setup_global(struct dsa_switch *ds)
@@ -74,6 +84,8 @@ static int mv88e6123_setup(struct dsa_switch *ds)
74 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 84 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
75 int ret; 85 int ret;
76 86
87 ps->ds = ds;
88
77 ret = mv88e6xxx_setup_common(ds); 89 ret = mv88e6xxx_setup_common(ds);
78 if (ret < 0) 90 if (ret < 0)
79 return ret; 91 return ret;
@@ -103,7 +115,6 @@ static int mv88e6123_setup(struct dsa_switch *ds)
103 115
104struct dsa_switch_driver mv88e6123_switch_driver = { 116struct dsa_switch_driver mv88e6123_switch_driver = {
105 .tag_protocol = DSA_TAG_PROTO_EDSA, 117 .tag_protocol = DSA_TAG_PROTO_EDSA,
106 .priv_size = sizeof(struct mv88e6xxx_priv_state),
107 .probe = mv88e6123_probe, 118 .probe = mv88e6123_probe,
108 .setup = mv88e6123_setup, 119 .setup = mv88e6123_setup,
109 .set_addr = mv88e6xxx_set_addr_indirect, 120 .set_addr = mv88e6xxx_set_addr_indirect,
diff --git a/drivers/net/dsa/mv88e6131.c b/drivers/net/dsa/mv88e6131.c
index bfadfd2cbb8d..b9f9b009f65a 100644
--- a/drivers/net/dsa/mv88e6131.c
+++ b/drivers/net/dsa/mv88e6131.c
@@ -26,10 +26,20 @@ static const struct mv88e6xxx_switch_id mv88e6131_table[] = {
26}; 26};
27 27
28static char *mv88e6131_probe(struct device *dsa_dev, struct device *host_dev, 28static char *mv88e6131_probe(struct device *dsa_dev, struct device *host_dev,
29 int sw_addr) 29 int sw_addr, void **priv)
30{ 30{
31 return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6131_table, 31 struct mv88e6xxx_priv_state *ps;
32 char *name;
33
34 name = mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6131_table,
32 ARRAY_SIZE(mv88e6131_table)); 35 ARRAY_SIZE(mv88e6131_table));
36 if (name) {
37 ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL);
38 if (!ps)
39 return NULL;
40 *priv = ps;
41 }
42 return name;
33} 43}
34 44
35static int mv88e6131_setup_global(struct dsa_switch *ds) 45static int mv88e6131_setup_global(struct dsa_switch *ds)
@@ -92,6 +102,8 @@ static int mv88e6131_setup(struct dsa_switch *ds)
92 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 102 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
93 int ret; 103 int ret;
94 104
105 ps->ds = ds;
106
95 ret = mv88e6xxx_setup_common(ds); 107 ret = mv88e6xxx_setup_common(ds);
96 if (ret < 0) 108 if (ret < 0)
97 return ret; 109 return ret;
@@ -160,7 +172,6 @@ mv88e6131_phy_write(struct dsa_switch *ds,
160 172
161struct dsa_switch_driver mv88e6131_switch_driver = { 173struct dsa_switch_driver mv88e6131_switch_driver = {
162 .tag_protocol = DSA_TAG_PROTO_DSA, 174 .tag_protocol = DSA_TAG_PROTO_DSA,
163 .priv_size = sizeof(struct mv88e6xxx_priv_state),
164 .probe = mv88e6131_probe, 175 .probe = mv88e6131_probe,
165 .setup = mv88e6131_setup, 176 .setup = mv88e6131_setup,
166 .set_addr = mv88e6xxx_set_addr_direct, 177 .set_addr = mv88e6xxx_set_addr_direct,
diff --git a/drivers/net/dsa/mv88e6171.c b/drivers/net/dsa/mv88e6171.c
index fb35d3ac1644..15200928cecc 100644
--- a/drivers/net/dsa/mv88e6171.c
+++ b/drivers/net/dsa/mv88e6171.c
@@ -25,10 +25,20 @@ static const struct mv88e6xxx_switch_id mv88e6171_table[] = {
25}; 25};
26 26
27static char *mv88e6171_probe(struct device *dsa_dev, struct device *host_dev, 27static char *mv88e6171_probe(struct device *dsa_dev, struct device *host_dev,
28 int sw_addr) 28 int sw_addr, void **priv)
29{ 29{
30 return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6171_table, 30 struct mv88e6xxx_priv_state *ps;
31 char *name;
32
33 name = mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6171_table,
31 ARRAY_SIZE(mv88e6171_table)); 34 ARRAY_SIZE(mv88e6171_table));
35 if (name) {
36 ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL);
37 if (!ps)
38 return NULL;
39 *priv = ps;
40 }
41 return name;
32} 42}
33 43
34static int mv88e6171_setup_global(struct dsa_switch *ds) 44static int mv88e6171_setup_global(struct dsa_switch *ds)
@@ -70,6 +80,8 @@ static int mv88e6171_setup(struct dsa_switch *ds)
70 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 80 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
71 int ret; 81 int ret;
72 82
83 ps->ds = ds;
84
73 ret = mv88e6xxx_setup_common(ds); 85 ret = mv88e6xxx_setup_common(ds);
74 if (ret < 0) 86 if (ret < 0)
75 return ret; 87 return ret;
@@ -89,7 +101,6 @@ static int mv88e6171_setup(struct dsa_switch *ds)
89 101
90struct dsa_switch_driver mv88e6171_switch_driver = { 102struct dsa_switch_driver mv88e6171_switch_driver = {
91 .tag_protocol = DSA_TAG_PROTO_EDSA, 103 .tag_protocol = DSA_TAG_PROTO_EDSA,
92 .priv_size = sizeof(struct mv88e6xxx_priv_state),
93 .probe = mv88e6171_probe, 104 .probe = mv88e6171_probe,
94 .setup = mv88e6171_setup, 105 .setup = mv88e6171_setup,
95 .set_addr = mv88e6xxx_set_addr_indirect, 106 .set_addr = mv88e6xxx_set_addr_indirect,
diff --git a/drivers/net/dsa/mv88e6352.c b/drivers/net/dsa/mv88e6352.c
index 577ab2cfa944..7081a78a67e1 100644
--- a/drivers/net/dsa/mv88e6352.c
+++ b/drivers/net/dsa/mv88e6352.c
@@ -38,10 +38,20 @@ static const struct mv88e6xxx_switch_id mv88e6352_table[] = {
38}; 38};
39 39
40static char *mv88e6352_probe(struct device *dsa_dev, struct device *host_dev, 40static char *mv88e6352_probe(struct device *dsa_dev, struct device *host_dev,
41 int sw_addr) 41 int sw_addr, void **priv)
42{ 42{
43 return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6352_table, 43 struct mv88e6xxx_priv_state *ps;
44 char *name;
45
46 name = mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6352_table,
44 ARRAY_SIZE(mv88e6352_table)); 47 ARRAY_SIZE(mv88e6352_table));
48 if (name) {
49 ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL);
50 if (!ps)
51 return NULL;
52 *priv = ps;
53 }
54 return name;
45} 55}
46 56
47static int mv88e6352_setup_global(struct dsa_switch *ds) 57static int mv88e6352_setup_global(struct dsa_switch *ds)
@@ -82,6 +92,8 @@ static int mv88e6352_setup(struct dsa_switch *ds)
82 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 92 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
83 int ret; 93 int ret;
84 94
95 ps->ds = ds;
96
85 ret = mv88e6xxx_setup_common(ds); 97 ret = mv88e6xxx_setup_common(ds);
86 if (ret < 0) 98 if (ret < 0)
87 return ret; 99 return ret;
@@ -303,7 +315,6 @@ static int mv88e6352_set_eeprom(struct dsa_switch *ds,
303 315
304struct dsa_switch_driver mv88e6352_switch_driver = { 316struct dsa_switch_driver mv88e6352_switch_driver = {
305 .tag_protocol = DSA_TAG_PROTO_EDSA, 317 .tag_protocol = DSA_TAG_PROTO_EDSA,
306 .priv_size = sizeof(struct mv88e6xxx_priv_state),
307 .probe = mv88e6352_probe, 318 .probe = mv88e6352_probe,
308 .setup = mv88e6352_setup, 319 .setup = mv88e6352_setup,
309 .set_addr = mv88e6xxx_set_addr_indirect, 320 .set_addr = mv88e6xxx_set_addr_indirect,
diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index 62320fca6712..085fc4a49eb2 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -281,7 +281,7 @@ static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
281 281
282 ps = container_of(ugly, struct mv88e6xxx_priv_state, ppu_work); 282 ps = container_of(ugly, struct mv88e6xxx_priv_state, ppu_work);
283 if (mutex_trylock(&ps->ppu_mutex)) { 283 if (mutex_trylock(&ps->ppu_mutex)) {
284 struct dsa_switch *ds = ((struct dsa_switch *)ps) - 1; 284 struct dsa_switch *ds = ps->ds;
285 285
286 if (mv88e6xxx_ppu_enable(ds) == 0) 286 if (mv88e6xxx_ppu_enable(ds) == 0)
287 ps->ppu_disabled = 0; 287 ps->ppu_disabled = 0;
@@ -2322,7 +2322,7 @@ static void mv88e6xxx_bridge_work(struct work_struct *work)
2322 int port; 2322 int port;
2323 2323
2324 ps = container_of(work, struct mv88e6xxx_priv_state, bridge_work); 2324 ps = container_of(work, struct mv88e6xxx_priv_state, bridge_work);
2325 ds = ((struct dsa_switch *)ps) - 1; 2325 ds = ps->ds;
2326 2326
2327 mutex_lock(&ps->smi_mutex); 2327 mutex_lock(&ps->smi_mutex);
2328 2328
@@ -2670,6 +2670,8 @@ int mv88e6xxx_setup_common(struct dsa_switch *ds)
2670{ 2670{
2671 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 2671 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2672 2672
2673 ps->ds = ds;
2674
2673 mutex_init(&ps->smi_mutex); 2675 mutex_init(&ps->smi_mutex);
2674 2676
2675 ps->id = REG_READ(REG_PORT(0), PORT_SWITCH_ID) & 0xfff0; 2677 ps->id = REG_READ(REG_PORT(0), PORT_SWITCH_ID) & 0xfff0;
diff --git a/drivers/net/dsa/mv88e6xxx.h b/drivers/net/dsa/mv88e6xxx.h
index 236bcaa606e7..0322e3e0e7d9 100644
--- a/drivers/net/dsa/mv88e6xxx.h
+++ b/drivers/net/dsa/mv88e6xxx.h
@@ -397,6 +397,9 @@ struct mv88e6xxx_priv_port {
397}; 397};
398 398
399struct mv88e6xxx_priv_state { 399struct mv88e6xxx_priv_state {
400 /* The dsa_switch this private structure is related to */
401 struct dsa_switch *ds;
402
400 /* When using multi-chip addressing, this mutex protects 403 /* When using multi-chip addressing, this mutex protects
401 * access to the indirect access registers. (In single-chip 404 * access to the indirect access registers. (In single-chip
402 * mode, this mutex is effectively useless.) 405 * mode, this mutex is effectively useless.)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 0f9f6f38f255..7bc7bd9b5ded 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -130,6 +130,12 @@ struct dsa_switch {
130 int index; 130 int index;
131 131
132 /* 132 /*
133 * Give the switch driver somewhere to hang its private data
134 * structure.
135 */
136 void *priv;
137
138 /*
133 * Tagging protocol understood by this switch 139 * Tagging protocol understood by this switch
134 */ 140 */
135 enum dsa_tag_protocol tag_protocol; 141 enum dsa_tag_protocol tag_protocol;
@@ -213,7 +219,7 @@ struct dsa_switch_driver {
213 * Probing and setup. 219 * Probing and setup.
214 */ 220 */
215 char *(*probe)(struct device *dsa_dev, struct device *host_dev, 221 char *(*probe)(struct device *dsa_dev, struct device *host_dev,
216 int sw_addr); 222 int sw_addr, void **priv);
217 int (*setup)(struct dsa_switch *ds); 223 int (*setup)(struct dsa_switch *ds);
218 int (*set_addr)(struct dsa_switch *ds, u8 *addr); 224 int (*set_addr)(struct dsa_switch *ds, u8 *addr);
219 u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 225 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);
342 348
343static inline void *ds_to_priv(struct dsa_switch *ds) 349static inline void *ds_to_priv(struct dsa_switch *ds)
344{ 350{
345 return (void *)(ds + 1); 351 return ds->priv;
346} 352}
347 353
348static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst) 354static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index c06275311cb2..7ef8a92a9e39 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -52,7 +52,7 @@ EXPORT_SYMBOL_GPL(unregister_switch_driver);
52 52
53static struct dsa_switch_driver * 53static struct dsa_switch_driver *
54dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr, 54dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
55 char **_name) 55 char **_name, void **priv)
56{ 56{
57 struct dsa_switch_driver *ret; 57 struct dsa_switch_driver *ret;
58 struct list_head *list; 58 struct list_head *list;
@@ -67,7 +67,7 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
67 67
68 drv = list_entry(list, struct dsa_switch_driver, list); 68 drv = list_entry(list, struct dsa_switch_driver, list);
69 69
70 name = drv->probe(parent, host_dev, sw_addr); 70 name = drv->probe(parent, host_dev, sw_addr, priv);
71 if (name != NULL) { 71 if (name != NULL) {
72 ret = drv; 72 ret = drv;
73 break; 73 break;
@@ -384,11 +384,12 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
384 struct dsa_switch *ds; 384 struct dsa_switch *ds;
385 int ret; 385 int ret;
386 char *name; 386 char *name;
387 void *priv;
387 388
388 /* 389 /*
389 * Probe for switch model. 390 * Probe for switch model.
390 */ 391 */
391 drv = dsa_switch_probe(parent, host_dev, pd->sw_addr, &name); 392 drv = dsa_switch_probe(parent, host_dev, pd->sw_addr, &name, &priv);
392 if (drv == NULL) { 393 if (drv == NULL) {
393 netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n", 394 netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n",
394 index); 395 index);
@@ -409,6 +410,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
409 ds->index = index; 410 ds->index = index;
410 ds->pd = pd; 411 ds->pd = pd;
411 ds->drv = drv; 412 ds->drv = drv;
413 ds->priv = priv;
412 ds->tag_protocol = drv->tag_protocol; 414 ds->tag_protocol = drv->tag_protocol;
413 ds->master_dev = host_dev; 415 ds->master_dev = host_dev;
414 416