diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2017-01-26 13:45:52 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-01-26 15:43:53 -0500 |
commit | 293784a8f856e854b4742be4aacf435062d91e9c (patch) | |
tree | 1fa42ba1ef912b78e184e5bbddc046ae8d0df2e8 /net/dsa/dsa2.c | |
parent | 55ed0ce0898e15fec30d2ca2a563d7934b082375 (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>
Diffstat (limited to 'net/dsa/dsa2.c')
-rw-r--r-- | net/dsa/dsa2.c | 61 |
1 files changed, 33 insertions, 28 deletions
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 | ||
81 | static bool dsa_port_is_dsa(struct device_node *port) | 81 | static 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 | ||
86 | static bool dsa_port_is_cpu(struct device_node *port) | 86 | static 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 | |||
91 | static bool dsa_port_is_cpu(struct dsa_port *port) | ||
92 | { | ||
93 | return !!of_parse_phandle(port->dn, "ethernet", 0); | ||
89 | } | 94 | } |
90 | 95 | ||
91 | static bool dsa_ds_find_port(struct dsa_switch *ds, | 96 | static 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 | ||
120 | static int dsa_port_complete(struct dsa_switch_tree *dst, | 125 | static 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 | */ |
151 | static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds) | 156 | static 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 | ||
199 | static int dsa_dsa_port_apply(struct device_node *port, u32 index, | 204 | static 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 | ||
214 | static void dsa_dsa_port_unapply(struct device_node *port, u32 index, | 219 | static 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 | ||
220 | static int dsa_cpu_port_apply(struct device_node *port, u32 index, | 225 | static 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 | ||
237 | static void dsa_cpu_port_unapply(struct device_node *port, u32 index, | 242 | static 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 | ||
245 | static int dsa_user_port_apply(struct device_node *port, u32 index, | 250 | static 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 | ||
265 | static void dsa_user_port_unapply(struct device_node *port, u32 index, | 270 | static 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 | ||
275 | static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) | 280 | static 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 | ||
337 | static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds) | 342 | static 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 | ||
428 | static int dsa_cpu_parse(struct device_node *port, u32 index, | 433 | static 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 | ||
467 | static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) | 472 | static 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 | ||