aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Fainelli <f.fainelli@gmail.com>2017-01-26 13:45:52 -0500
committerDavid S. Miller <davem@davemloft.net>2017-01-26 15:43:53 -0500
commit293784a8f856e854b4742be4aacf435062d91e9c (patch)
tree1fa42ba1ef912b78e184e5bbddc046ae8d0df2e8
parent55ed0ce0898e15fec30d2ca2a563d7934b082375 (diff)
net: dsa: Make most functions take a dsa_port argument
In preparation for allowing platform data, and therefore no valid device_node pointer, make most DSA functions takes a pointer to a dsa_port structure whenever possible. While at it, introduce a dsa_port_is_valid() helper function which checks whether port->dn is NULL or not at the moment. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/dsa/dsa.c15
-rw-r--r--net/dsa/dsa2.c61
-rw-r--r--net/dsa/dsa_priv.h4
3 files changed, 44 insertions, 36 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 1f3afeb673d6..07e863369e04 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -110,8 +110,9 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
110 110
111/* basic switch operations **************************************************/ 111/* basic switch operations **************************************************/
112int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, 112int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
113 struct device_node *port_dn, int port) 113 struct dsa_port *dport, int port)
114{ 114{
115 struct device_node *port_dn = dport->dn;
115 struct phy_device *phydev; 116 struct phy_device *phydev;
116 int ret, mode; 117 int ret, mode;
117 118
@@ -141,15 +142,15 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
141 142
142static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev) 143static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev)
143{ 144{
144 struct device_node *port_dn; 145 struct dsa_port *dport;
145 int ret, port; 146 int ret, port;
146 147
147 for (port = 0; port < DSA_MAX_PORTS; port++) { 148 for (port = 0; port < DSA_MAX_PORTS; port++) {
148 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) 149 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
149 continue; 150 continue;
150 151
151 port_dn = ds->ports[port].dn; 152 dport = &ds->ports[port];
152 ret = dsa_cpu_dsa_setup(ds, dev, port_dn, port); 153 ret = dsa_cpu_dsa_setup(ds, dev, dport, port);
153 if (ret) 154 if (ret)
154 return ret; 155 return ret;
155 } 156 }
@@ -364,8 +365,10 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
364 return ds; 365 return ds;
365} 366}
366 367
367void dsa_cpu_dsa_destroy(struct device_node *port_dn) 368void dsa_cpu_dsa_destroy(struct dsa_port *port)
368{ 369{
370 struct device_node *port_dn = port->dn;
371
369 if (of_phy_is_fixed_link(port_dn)) 372 if (of_phy_is_fixed_link(port_dn))
370 of_phy_deregister_fixed_link(port_dn); 373 of_phy_deregister_fixed_link(port_dn);
371} 374}
@@ -389,7 +392,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
389 for (port = 0; port < DSA_MAX_PORTS; port++) { 392 for (port = 0; port < DSA_MAX_PORTS; port++) {
390 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) 393 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
391 continue; 394 continue;
392 dsa_cpu_dsa_destroy(ds->ports[port].dn); 395 dsa_cpu_dsa_destroy(&ds->ports[port]);
393 396
394 /* Clearing a bit which is not set does no harm */ 397 /* Clearing a bit which is not set does no harm */
395 ds->cpu_port_mask |= ~(1 << port); 398 ds->cpu_port_mask |= ~(1 << port);
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 2cf489c5e90f..56c43ca7c049 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -78,14 +78,19 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
78 kref_put(&dst->refcount, dsa_free_dst); 78 kref_put(&dst->refcount, dsa_free_dst);
79} 79}
80 80
81static bool dsa_port_is_dsa(struct device_node *port) 81static bool dsa_port_is_valid(struct dsa_port *port)
82{ 82{
83 return !!of_parse_phandle(port, "link", 0); 83 return !!port->dn;
84} 84}
85 85
86static bool dsa_port_is_cpu(struct device_node *port) 86static bool dsa_port_is_dsa(struct dsa_port *port)
87{ 87{
88 return !!of_parse_phandle(port, "ethernet", 0); 88 return !!of_parse_phandle(port->dn, "link", 0);
89}
90
91static bool dsa_port_is_cpu(struct dsa_port *port)
92{
93 return !!of_parse_phandle(port->dn, "ethernet", 0);
89} 94}
90 95
91static bool dsa_ds_find_port(struct dsa_switch *ds, 96static bool dsa_ds_find_port(struct dsa_switch *ds,
@@ -119,7 +124,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
119 124
120static int dsa_port_complete(struct dsa_switch_tree *dst, 125static int dsa_port_complete(struct dsa_switch_tree *dst,
121 struct dsa_switch *src_ds, 126 struct dsa_switch *src_ds,
122 struct device_node *port, 127 struct dsa_port *port,
123 u32 src_port) 128 u32 src_port)
124{ 129{
125 struct device_node *link; 130 struct device_node *link;
@@ -127,7 +132,7 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
127 struct dsa_switch *dst_ds; 132 struct dsa_switch *dst_ds;
128 133
129 for (index = 0;; index++) { 134 for (index = 0;; index++) {
130 link = of_parse_phandle(port, "link", index); 135 link = of_parse_phandle(port->dn, "link", index);
131 if (!link) 136 if (!link)
132 break; 137 break;
133 138
@@ -150,13 +155,13 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
150 */ 155 */
151static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds) 156static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds)
152{ 157{
153 struct device_node *port; 158 struct dsa_port *port;
154 u32 index; 159 u32 index;
155 int err; 160 int err;
156 161
157 for (index = 0; index < DSA_MAX_PORTS; index++) { 162 for (index = 0; index < DSA_MAX_PORTS; index++) {
158 port = ds->ports[index].dn; 163 port = &ds->ports[index];
159 if (!port) 164 if (!dsa_port_is_valid(port))
160 continue; 165 continue;
161 166
162 if (!dsa_port_is_dsa(port)) 167 if (!dsa_port_is_dsa(port))
@@ -196,7 +201,7 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst)
196 return 0; 201 return 0;
197} 202}
198 203
199static int dsa_dsa_port_apply(struct device_node *port, u32 index, 204static int dsa_dsa_port_apply(struct dsa_port *port, u32 index,
200 struct dsa_switch *ds) 205 struct dsa_switch *ds)
201{ 206{
202 int err; 207 int err;
@@ -211,13 +216,13 @@ static int dsa_dsa_port_apply(struct device_node *port, u32 index,
211 return 0; 216 return 0;
212} 217}
213 218
214static void dsa_dsa_port_unapply(struct device_node *port, u32 index, 219static void dsa_dsa_port_unapply(struct dsa_port *port, u32 index,
215 struct dsa_switch *ds) 220 struct dsa_switch *ds)
216{ 221{
217 dsa_cpu_dsa_destroy(port); 222 dsa_cpu_dsa_destroy(port);
218} 223}
219 224
220static int dsa_cpu_port_apply(struct device_node *port, u32 index, 225static int dsa_cpu_port_apply(struct dsa_port *port, u32 index,
221 struct dsa_switch *ds) 226 struct dsa_switch *ds)
222{ 227{
223 int err; 228 int err;
@@ -234,7 +239,7 @@ static int dsa_cpu_port_apply(struct device_node *port, u32 index,
234 return 0; 239 return 0;
235} 240}
236 241
237static void dsa_cpu_port_unapply(struct device_node *port, u32 index, 242static void dsa_cpu_port_unapply(struct dsa_port *port, u32 index,
238 struct dsa_switch *ds) 243 struct dsa_switch *ds)
239{ 244{
240 dsa_cpu_dsa_destroy(port); 245 dsa_cpu_dsa_destroy(port);
@@ -242,13 +247,13 @@ static void dsa_cpu_port_unapply(struct device_node *port, u32 index,
242 247
243} 248}
244 249
245static int dsa_user_port_apply(struct device_node *port, u32 index, 250static int dsa_user_port_apply(struct dsa_port *port, u32 index,
246 struct dsa_switch *ds) 251 struct dsa_switch *ds)
247{ 252{
248 const char *name; 253 const char *name;
249 int err; 254 int err;
250 255
251 name = of_get_property(port, "label", NULL); 256 name = of_get_property(port->dn, "label", NULL);
252 if (!name) 257 if (!name)
253 name = "eth%d"; 258 name = "eth%d";
254 259
@@ -262,7 +267,7 @@ static int dsa_user_port_apply(struct device_node *port, u32 index,
262 return 0; 267 return 0;
263} 268}
264 269
265static void dsa_user_port_unapply(struct device_node *port, u32 index, 270static void dsa_user_port_unapply(struct dsa_port *port, u32 index,
266 struct dsa_switch *ds) 271 struct dsa_switch *ds)
267{ 272{
268 if (ds->ports[index].netdev) { 273 if (ds->ports[index].netdev) {
@@ -274,7 +279,7 @@ static void dsa_user_port_unapply(struct device_node *port, u32 index,
274 279
275static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) 280static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
276{ 281{
277 struct device_node *port; 282 struct dsa_port *port;
278 u32 index; 283 u32 index;
279 int err; 284 int err;
280 285
@@ -308,8 +313,8 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
308 } 313 }
309 314
310 for (index = 0; index < DSA_MAX_PORTS; index++) { 315 for (index = 0; index < DSA_MAX_PORTS; index++) {
311 port = ds->ports[index].dn; 316 port = &ds->ports[index];
312 if (!port) 317 if (!dsa_port_is_valid(port))
313 continue; 318 continue;
314 319
315 if (dsa_port_is_dsa(port)) { 320 if (dsa_port_is_dsa(port)) {
@@ -336,12 +341,12 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
336 341
337static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds) 342static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
338{ 343{
339 struct device_node *port; 344 struct dsa_port *port;
340 u32 index; 345 u32 index;
341 346
342 for (index = 0; index < DSA_MAX_PORTS; index++) { 347 for (index = 0; index < DSA_MAX_PORTS; index++) {
343 port = ds->ports[index].dn; 348 port = &ds->ports[index];
344 if (!port) 349 if (!dsa_port_is_valid(port))
345 continue; 350 continue;
346 351
347 if (dsa_port_is_dsa(port)) { 352 if (dsa_port_is_dsa(port)) {
@@ -425,7 +430,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
425 dst->applied = false; 430 dst->applied = false;
426} 431}
427 432
428static int dsa_cpu_parse(struct device_node *port, u32 index, 433static int dsa_cpu_parse(struct dsa_port *port, u32 index,
429 struct dsa_switch_tree *dst, 434 struct dsa_switch_tree *dst,
430 struct dsa_switch *ds) 435 struct dsa_switch *ds)
431{ 436{
@@ -433,7 +438,7 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
433 struct net_device *ethernet_dev; 438 struct net_device *ethernet_dev;
434 struct device_node *ethernet; 439 struct device_node *ethernet;
435 440
436 ethernet = of_parse_phandle(port, "ethernet", 0); 441 ethernet = of_parse_phandle(port->dn, "ethernet", 0);
437 if (!ethernet) 442 if (!ethernet)
438 return -EINVAL; 443 return -EINVAL;
439 444
@@ -466,13 +471,13 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
466 471
467static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) 472static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
468{ 473{
469 struct device_node *port; 474 struct dsa_port *port;
470 u32 index; 475 u32 index;
471 int err; 476 int err;
472 477
473 for (index = 0; index < DSA_MAX_PORTS; index++) { 478 for (index = 0; index < DSA_MAX_PORTS; index++) {
474 port = ds->ports[index].dn; 479 port = &ds->ports[index];
475 if (!port) 480 if (!dsa_port_is_valid(port))
476 continue; 481 continue;
477 482
478 if (dsa_port_is_cpu(port)) { 483 if (dsa_port_is_cpu(port)) {
@@ -533,7 +538,7 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
533 * to have access to a correct value, just like what 538 * to have access to a correct value, just like what
534 * net/dsa/dsa.c::dsa_switch_setup_one does. 539 * net/dsa/dsa.c::dsa_switch_setup_one does.
535 */ 540 */
536 if (!dsa_port_is_cpu(port)) 541 if (!dsa_port_is_cpu(&ds->ports[reg]))
537 ds->enabled_port_mask |= 1 << reg; 542 ds->enabled_port_mask |= 1 << reg;
538 } 543 }
539 544
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 63ae1484abae..16194a4bb2fe 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -50,8 +50,8 @@ struct dsa_slave_priv {
50 50
51/* dsa.c */ 51/* dsa.c */
52int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, 52int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
53 struct device_node *port_dn, int port); 53 struct dsa_port *dport, int port);
54void dsa_cpu_dsa_destroy(struct device_node *port_dn); 54void dsa_cpu_dsa_destroy(struct dsa_port *dport);
55const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol); 55const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
56int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds); 56int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds);
57void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds); 57void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds);