Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'dsa-setup-stage'

Vivien Didelot says:

====================
net: dsa: setup stage

When probing a DSA switch, there is basically two stages.

The first stage is the parsing of the switch device, from either device
tree or platform data. It fetches the DSA tree to which it belongs, and
validates its ports. The switch device is then added to the tree, and
the second stage is called if this was the last switch of the tree.

The second stage is the setup of the tree, which validates that the tree
is complete, sets up the routing tables, the default CPU port for user
ports, sets up the switch drivers and finally the master interfaces,
which makes the whole switch fabric functional.

This patch series covers the second setup stage. The setup and teardown
of a switch tree have been separated into logical steps, and the probing
of a switch now simply parses and adds a switch to a tree.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+307 -390
+2 -2
include/net/dsa.h
··· 122 122 struct kref refcount; 123 123 124 124 /* Has this tree been applied to the hardware? */ 125 - bool applied; 125 + bool setup; 126 126 127 127 /* 128 128 * Configuration data for the platform device that owns ··· 190 190 struct dsa_switch *ds; 191 191 unsigned int index; 192 192 const char *name; 193 - struct dsa_port *cpu_dp; 193 + const struct dsa_port *cpu_dp; 194 194 struct device_node *dn; 195 195 unsigned int ageing_time; 196 196 u8 stp_state;
+272 -365
net/dsa/dsa2.c
··· 94 94 kref_put(&dst->refcount, dsa_tree_release); 95 95 } 96 96 97 - /* For platform data configurations, we need to have a valid name argument to 98 - * differentiate a disabled port from an enabled one 99 - */ 100 - static bool dsa_port_is_valid(struct dsa_port *port) 101 - { 102 - return port->type != DSA_PORT_TYPE_UNUSED; 103 - } 104 - 105 97 static bool dsa_port_is_dsa(struct dsa_port *port) 106 98 { 107 99 return port->type == DSA_PORT_TYPE_DSA; ··· 104 112 return port->type == DSA_PORT_TYPE_CPU; 105 113 } 106 114 107 - static bool dsa_ds_find_port_dn(struct dsa_switch *ds, 108 - struct device_node *port) 115 + static bool dsa_port_is_user(struct dsa_port *dp) 109 116 { 110 - u32 index; 111 - 112 - for (index = 0; index < ds->num_ports; index++) 113 - if (ds->ports[index].dn == port) 114 - return true; 115 - return false; 117 + return dp->type == DSA_PORT_TYPE_USER; 116 118 } 117 119 118 - static struct dsa_switch *dsa_dst_find_port_dn(struct dsa_switch_tree *dst, 119 - struct device_node *port) 120 + static struct dsa_port *dsa_tree_find_port_by_node(struct dsa_switch_tree *dst, 121 + struct device_node *dn) 120 122 { 121 123 struct dsa_switch *ds; 122 - u32 index; 124 + struct dsa_port *dp; 125 + int device, port; 123 126 124 - for (index = 0; index < DSA_MAX_SWITCHES; index++) { 125 - ds = dst->ds[index]; 127 + for (device = 0; device < DSA_MAX_SWITCHES; device++) { 128 + ds = dst->ds[device]; 126 129 if (!ds) 127 130 continue; 128 131 129 - if (dsa_ds_find_port_dn(ds, port)) 130 - return ds; 132 + for (port = 0; port < ds->num_ports; port++) { 133 + dp = &ds->ports[port]; 134 + 135 + if (dp->dn == dn) 136 + return dp; 137 + } 131 138 } 132 139 133 140 return NULL; 134 141 } 135 142 136 - static int dsa_port_complete(struct dsa_switch_tree *dst, 137 - struct dsa_switch *src_ds, 138 - struct dsa_port *port, 139 - u32 src_port) 143 + static bool dsa_port_setup_routing_table(struct dsa_port *dp) 140 144 { 141 - struct device_node *link; 142 - int index; 143 - struct dsa_switch *dst_ds; 144 - 145 - for (index = 0;; index++) { 146 - link = of_parse_phandle(port->dn, "link", index); 147 - if (!link) 148 - break; 149 - 150 - dst_ds = dsa_dst_find_port_dn(dst, link); 151 - of_node_put(link); 152 - 153 - if (!dst_ds) 154 - return 1; 155 - 156 - src_ds->rtable[dst_ds->index] = src_port; 157 - } 158 - 159 - return 0; 160 - } 161 - 162 - /* A switch is complete if all the DSA ports phandles point to ports 163 - * known in the tree. A return value of 1 means the tree is not 164 - * complete. This is not an error condition. A value of 0 is 165 - * success. 166 - */ 167 - static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds) 168 - { 169 - struct dsa_port *port; 170 - u32 index; 145 + struct dsa_switch *ds = dp->ds; 146 + struct dsa_switch_tree *dst = ds->dst; 147 + struct device_node *dn = dp->dn; 148 + struct of_phandle_iterator it; 149 + struct dsa_port *link_dp; 171 150 int err; 172 151 173 - for (index = 0; index < ds->num_ports; index++) { 174 - port = &ds->ports[index]; 175 - if (!dsa_port_is_valid(port)) 176 - continue; 152 + of_for_each_phandle(&it, err, dn, "link", NULL, 0) { 153 + link_dp = dsa_tree_find_port_by_node(dst, it.node); 154 + if (!link_dp) { 155 + of_node_put(it.node); 156 + return false; 157 + } 177 158 178 - if (!dsa_port_is_dsa(port)) 179 - continue; 180 - 181 - err = dsa_port_complete(dst, ds, port, index); 182 - if (err != 0) 183 - return err; 159 + ds->rtable[link_dp->ds->index] = dp->index; 184 160 } 185 161 186 - return 0; 162 + return true; 187 163 } 188 164 189 - /* A tree is complete if all the DSA ports phandles point to ports 190 - * known in the tree. A return value of 1 means the tree is not 191 - * complete. This is not an error condition. A value of 0 is 192 - * success. 193 - */ 194 - static int dsa_dst_complete(struct dsa_switch_tree *dst) 165 + static bool dsa_switch_setup_routing_table(struct dsa_switch *ds) 166 + { 167 + bool complete = true; 168 + struct dsa_port *dp; 169 + int i; 170 + 171 + for (i = 0; i < DSA_MAX_SWITCHES; i++) 172 + ds->rtable[i] = DSA_RTABLE_NONE; 173 + 174 + for (i = 0; i < ds->num_ports; i++) { 175 + dp = &ds->ports[i]; 176 + 177 + if (dsa_port_is_dsa(dp)) { 178 + complete = dsa_port_setup_routing_table(dp); 179 + if (!complete) 180 + break; 181 + } 182 + } 183 + 184 + return complete; 185 + } 186 + 187 + static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst) 195 188 { 196 189 struct dsa_switch *ds; 197 - u32 index; 198 - int err; 190 + bool complete = true; 191 + int device; 199 192 200 - for (index = 0; index < DSA_MAX_SWITCHES; index++) { 201 - ds = dst->ds[index]; 193 + for (device = 0; device < DSA_MAX_SWITCHES; device++) { 194 + ds = dst->ds[device]; 202 195 if (!ds) 203 196 continue; 204 197 205 - err = dsa_ds_complete(dst, ds); 206 - if (err != 0) 207 - return err; 198 + complete = dsa_switch_setup_routing_table(ds); 199 + if (!complete) 200 + break; 201 + } 202 + 203 + return complete; 204 + } 205 + 206 + static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst) 207 + { 208 + struct dsa_switch *ds; 209 + struct dsa_port *dp; 210 + int device, port; 211 + 212 + for (device = 0; device < DSA_MAX_SWITCHES; device++) { 213 + ds = dst->ds[device]; 214 + if (!ds) 215 + continue; 216 + 217 + for (port = 0; port < ds->num_ports; port++) { 218 + dp = &ds->ports[port]; 219 + 220 + if (dsa_port_is_cpu(dp)) 221 + return dp; 222 + } 223 + } 224 + 225 + return NULL; 226 + } 227 + 228 + static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst) 229 + { 230 + struct dsa_switch *ds; 231 + struct dsa_port *dp; 232 + int device, port; 233 + 234 + /* DSA currently only supports a single CPU port */ 235 + dst->cpu_dp = dsa_tree_find_first_cpu(dst); 236 + if (!dst->cpu_dp) { 237 + pr_warn("Tree has no master device\n"); 238 + return -EINVAL; 239 + } 240 + 241 + /* Assign the default CPU port to all ports of the fabric */ 242 + for (device = 0; device < DSA_MAX_SWITCHES; device++) { 243 + ds = dst->ds[device]; 244 + if (!ds) 245 + continue; 246 + 247 + for (port = 0; port < ds->num_ports; port++) { 248 + dp = &ds->ports[port]; 249 + 250 + if (dsa_port_is_user(dp)) 251 + dp->cpu_dp = dst->cpu_dp; 252 + } 208 253 } 209 254 210 255 return 0; 211 256 } 212 257 213 - static int dsa_dsa_port_apply(struct dsa_port *port) 258 + static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst) 214 259 { 215 - struct dsa_switch *ds = port->ds; 260 + /* DSA currently only supports a single CPU port */ 261 + dst->cpu_dp = NULL; 262 + } 263 + 264 + static int dsa_port_setup(struct dsa_port *dp) 265 + { 266 + struct dsa_switch *ds = dp->ds; 216 267 int err; 217 268 218 - err = dsa_port_fixed_link_register_of(port); 219 - if (err) { 220 - dev_warn(ds->dev, "Failed to setup dsa port %d: %d\n", 221 - port->index, err); 222 - return err; 223 - } 269 + memset(&dp->devlink_port, 0, sizeof(dp->devlink_port)); 224 270 225 - memset(&port->devlink_port, 0, sizeof(port->devlink_port)); 226 - 227 - return devlink_port_register(ds->devlink, &port->devlink_port, 228 - port->index); 229 - } 230 - 231 - static void dsa_dsa_port_unapply(struct dsa_port *port) 232 - { 233 - devlink_port_unregister(&port->devlink_port); 234 - dsa_port_fixed_link_unregister_of(port); 235 - } 236 - 237 - static int dsa_cpu_port_apply(struct dsa_port *port) 238 - { 239 - struct dsa_switch *ds = port->ds; 240 - int err; 241 - 242 - err = dsa_port_fixed_link_register_of(port); 243 - if (err) { 244 - dev_warn(ds->dev, "Failed to setup cpu port %d: %d\n", 245 - port->index, err); 246 - return err; 247 - } 248 - 249 - memset(&port->devlink_port, 0, sizeof(port->devlink_port)); 250 - err = devlink_port_register(ds->devlink, &port->devlink_port, 251 - port->index); 252 - return err; 253 - } 254 - 255 - static void dsa_cpu_port_unapply(struct dsa_port *port) 256 - { 257 - devlink_port_unregister(&port->devlink_port); 258 - dsa_port_fixed_link_unregister_of(port); 259 - } 260 - 261 - static int dsa_user_port_apply(struct dsa_port *port) 262 - { 263 - struct dsa_switch *ds = port->ds; 264 - int err; 265 - 266 - err = dsa_slave_create(port); 267 - if (err) { 268 - dev_warn(ds->dev, "Failed to create slave %d: %d\n", 269 - port->index, err); 270 - port->slave = NULL; 271 - return err; 272 - } 273 - 274 - memset(&port->devlink_port, 0, sizeof(port->devlink_port)); 275 - err = devlink_port_register(ds->devlink, &port->devlink_port, 276 - port->index); 271 + err = devlink_port_register(ds->devlink, &dp->devlink_port, dp->index); 277 272 if (err) 278 273 return err; 279 274 280 - devlink_port_type_eth_set(&port->devlink_port, port->slave); 275 + switch (dp->type) { 276 + case DSA_PORT_TYPE_UNUSED: 277 + break; 278 + case DSA_PORT_TYPE_CPU: 279 + case DSA_PORT_TYPE_DSA: 280 + err = dsa_port_fixed_link_register_of(dp); 281 + if (err) { 282 + dev_err(ds->dev, "failed to register fixed link for port %d.%d\n", 283 + ds->index, dp->index); 284 + return err; 285 + } 286 + 287 + break; 288 + case DSA_PORT_TYPE_USER: 289 + err = dsa_slave_create(dp); 290 + if (err) 291 + dev_err(ds->dev, "failed to create slave for port %d.%d\n", 292 + ds->index, dp->index); 293 + else 294 + devlink_port_type_eth_set(&dp->devlink_port, dp->slave); 295 + break; 296 + } 281 297 282 298 return 0; 283 299 } 284 300 285 - static void dsa_user_port_unapply(struct dsa_port *port) 301 + static void dsa_port_teardown(struct dsa_port *dp) 286 302 { 287 - devlink_port_unregister(&port->devlink_port); 288 - if (port->slave) { 289 - dsa_slave_destroy(port->slave); 290 - port->slave = NULL; 303 + devlink_port_unregister(&dp->devlink_port); 304 + 305 + switch (dp->type) { 306 + case DSA_PORT_TYPE_UNUSED: 307 + break; 308 + case DSA_PORT_TYPE_CPU: 309 + case DSA_PORT_TYPE_DSA: 310 + dsa_port_fixed_link_unregister_of(dp); 311 + break; 312 + case DSA_PORT_TYPE_USER: 313 + if (dp->slave) { 314 + dsa_slave_destroy(dp->slave); 315 + dp->slave = NULL; 316 + } 317 + break; 291 318 } 292 319 } 293 320 294 - static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) 321 + static int dsa_switch_setup(struct dsa_switch *ds) 295 322 { 296 - struct dsa_port *port; 297 - u32 index; 298 323 int err; 299 324 300 325 /* Initialize ds->phys_mii_mask before registering the slave MDIO bus ··· 352 343 return err; 353 344 } 354 345 355 - for (index = 0; index < ds->num_ports; index++) { 356 - port = &ds->ports[index]; 357 - if (!dsa_port_is_valid(port)) 358 - continue; 359 - 360 - if (dsa_port_is_dsa(port)) { 361 - err = dsa_dsa_port_apply(port); 362 - if (err) 363 - return err; 364 - continue; 365 - } 366 - 367 - if (dsa_port_is_cpu(port)) { 368 - err = dsa_cpu_port_apply(port); 369 - if (err) 370 - return err; 371 - continue; 372 - } 373 - 374 - err = dsa_user_port_apply(port); 375 - if (err) 376 - continue; 377 - } 378 - 379 346 return 0; 380 347 } 381 348 382 - static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds) 349 + static void dsa_switch_teardown(struct dsa_switch *ds) 383 350 { 384 - struct dsa_port *port; 385 - u32 index; 386 - 387 - for (index = 0; index < ds->num_ports; index++) { 388 - port = &ds->ports[index]; 389 - if (!dsa_port_is_valid(port)) 390 - continue; 391 - 392 - if (dsa_port_is_dsa(port)) { 393 - dsa_dsa_port_unapply(port); 394 - continue; 395 - } 396 - 397 - if (dsa_port_is_cpu(port)) { 398 - dsa_cpu_port_unapply(port); 399 - continue; 400 - } 401 - 402 - dsa_user_port_unapply(port); 403 - } 404 - 405 351 if (ds->slave_mii_bus && ds->ops->phy_read) 406 352 mdiobus_unregister(ds->slave_mii_bus); 407 353 ··· 370 406 371 407 } 372 408 373 - static int dsa_dst_apply(struct dsa_switch_tree *dst) 409 + static int dsa_tree_setup_switches(struct dsa_switch_tree *dst) 374 410 { 375 411 struct dsa_switch *ds; 376 - u32 index; 412 + struct dsa_port *dp; 413 + int device, port; 377 414 int err; 378 415 379 - for (index = 0; index < DSA_MAX_SWITCHES; index++) { 380 - ds = dst->ds[index]; 416 + for (device = 0; device < DSA_MAX_SWITCHES; device++) { 417 + ds = dst->ds[device]; 381 418 if (!ds) 382 419 continue; 383 420 384 - err = dsa_ds_apply(dst, ds); 421 + err = dsa_switch_setup(ds); 385 422 if (err) 386 423 return err; 424 + 425 + for (port = 0; port < ds->num_ports; port++) { 426 + dp = &ds->ports[port]; 427 + 428 + err = dsa_port_setup(dp); 429 + if (err) 430 + return err; 431 + } 387 432 } 388 - 389 - /* If we use a tagging format that doesn't have an ethertype 390 - * field, make sure that all packets from this point on get 391 - * sent to the tag format's receive function. 392 - */ 393 - wmb(); 394 - dst->cpu_dp->master->dsa_ptr = dst->cpu_dp; 395 - 396 - err = dsa_master_ethtool_setup(dst->cpu_dp->master); 397 - if (err) 398 - return err; 399 - 400 - dst->applied = true; 401 433 402 434 return 0; 403 435 } 404 436 405 - static void dsa_dst_unapply(struct dsa_switch_tree *dst) 437 + static void dsa_tree_teardown_switches(struct dsa_switch_tree *dst) 406 438 { 407 439 struct dsa_switch *ds; 408 - u32 index; 440 + struct dsa_port *dp; 441 + int device, port; 409 442 410 - if (!dst->applied) 411 - return; 412 - 413 - dsa_master_ethtool_restore(dst->cpu_dp->master); 414 - 415 - dst->cpu_dp->master->dsa_ptr = NULL; 416 - 417 - /* If we used a tagging format that doesn't have an ethertype 418 - * field, make sure that all packets from this point get sent 419 - * without the tag and go through the regular receive path. 420 - */ 421 - wmb(); 422 - 423 - for (index = 0; index < DSA_MAX_SWITCHES; index++) { 424 - ds = dst->ds[index]; 443 + for (device = 0; device < DSA_MAX_SWITCHES; device++) { 444 + ds = dst->ds[device]; 425 445 if (!ds) 426 446 continue; 427 447 428 - dsa_ds_unapply(dst, ds); 448 + for (port = 0; port < ds->num_ports; port++) { 449 + dp = &ds->ports[port]; 450 + 451 + dsa_port_teardown(dp); 452 + } 453 + 454 + dsa_switch_teardown(ds); 455 + } 456 + } 457 + 458 + static int dsa_tree_setup_master(struct dsa_switch_tree *dst) 459 + { 460 + struct dsa_port *cpu_dp = dst->cpu_dp; 461 + struct net_device *master = cpu_dp->master; 462 + 463 + /* DSA currently supports a single pair of CPU port and master device */ 464 + return dsa_master_setup(master, cpu_dp); 465 + } 466 + 467 + static void dsa_tree_teardown_master(struct dsa_switch_tree *dst) 468 + { 469 + struct dsa_port *cpu_dp = dst->cpu_dp; 470 + struct net_device *master = cpu_dp->master; 471 + 472 + return dsa_master_teardown(master); 473 + } 474 + 475 + static int dsa_tree_setup(struct dsa_switch_tree *dst) 476 + { 477 + bool complete; 478 + int err; 479 + 480 + if (dst->setup) { 481 + pr_err("DSA: tree %d already setup! Disjoint trees?\n", 482 + dst->index); 483 + return -EEXIST; 429 484 } 430 485 431 - dst->cpu_dp = NULL; 486 + complete = dsa_tree_setup_routing_table(dst); 487 + if (!complete) 488 + return 0; 432 489 433 - pr_info("DSA: tree %d unapplied\n", dst->index); 434 - dst->applied = false; 490 + err = dsa_tree_setup_default_cpu(dst); 491 + if (err) 492 + return err; 493 + 494 + err = dsa_tree_setup_switches(dst); 495 + if (err) 496 + return err; 497 + 498 + err = dsa_tree_setup_master(dst); 499 + if (err) 500 + return err; 501 + 502 + dst->setup = true; 503 + 504 + pr_info("DSA: tree %d setup\n", dst->index); 505 + 506 + return 0; 507 + } 508 + 509 + static void dsa_tree_teardown(struct dsa_switch_tree *dst) 510 + { 511 + if (!dst->setup) 512 + return; 513 + 514 + dsa_tree_teardown_master(dst); 515 + 516 + dsa_tree_teardown_switches(dst); 517 + 518 + dsa_tree_teardown_default_cpu(dst); 519 + 520 + pr_info("DSA: tree %d torn down\n", dst->index); 521 + 522 + dst->setup = false; 435 523 } 436 524 437 525 static void dsa_tree_remove_switch(struct dsa_switch_tree *dst, 438 526 unsigned int index) 439 527 { 528 + dsa_tree_teardown(dst); 529 + 440 530 dst->ds[index] = NULL; 441 531 dsa_tree_put(dst); 442 532 } ··· 499 481 struct dsa_switch *ds) 500 482 { 501 483 unsigned int index = ds->index; 484 + int err; 502 485 503 486 if (dst->ds[index]) 504 487 return -EBUSY; ··· 507 488 dsa_tree_get(dst); 508 489 dst->ds[index] = ds; 509 490 510 - return 0; 491 + err = dsa_tree_setup(dst); 492 + if (err) 493 + dsa_tree_remove_switch(dst, index); 494 + 495 + return err; 511 496 } 512 497 513 498 static int dsa_port_parse_user(struct dsa_port *dp, const char *name) ··· 551 528 dp->tag_ops = tag_ops; 552 529 dp->master = master; 553 530 dp->dst = dst; 554 - 555 - return 0; 556 - } 557 - 558 - static int dsa_cpu_parse(struct dsa_port *port, u32 index, 559 - struct dsa_switch_tree *dst, 560 - struct dsa_switch *ds) 561 - { 562 - if (!dst->cpu_dp) 563 - dst->cpu_dp = port; 564 - 565 - return 0; 566 - } 567 - 568 - static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) 569 - { 570 - struct dsa_port *port; 571 - u32 index; 572 - int err; 573 - 574 - for (index = 0; index < ds->num_ports; index++) { 575 - port = &ds->ports[index]; 576 - if (!dsa_port_is_valid(port) || 577 - dsa_port_is_dsa(port)) 578 - continue; 579 - 580 - if (dsa_port_is_cpu(port)) { 581 - err = dsa_cpu_parse(port, index, dst, ds); 582 - if (err) 583 - return err; 584 - } 585 - 586 - } 587 - 588 - pr_info("DSA: switch %d %d parsed\n", dst->index, ds->index); 589 - 590 - return 0; 591 - } 592 - 593 - static int dsa_dst_parse(struct dsa_switch_tree *dst) 594 - { 595 - struct dsa_switch *ds; 596 - struct dsa_port *dp; 597 - u32 index; 598 - int port; 599 - int err; 600 - 601 - for (index = 0; index < DSA_MAX_SWITCHES; index++) { 602 - ds = dst->ds[index]; 603 - if (!ds) 604 - continue; 605 - 606 - err = dsa_ds_parse(dst, ds); 607 - if (err) 608 - return err; 609 - } 610 - 611 - if (!dst->cpu_dp) { 612 - pr_warn("Tree has no master device\n"); 613 - return -EINVAL; 614 - } 615 - 616 - /* Assign the default CPU port to all ports of the fabric */ 617 - for (index = 0; index < DSA_MAX_SWITCHES; index++) { 618 - ds = dst->ds[index]; 619 - if (!ds) 620 - continue; 621 - 622 - for (port = 0; port < ds->num_ports; port++) { 623 - dp = &ds->ports[port]; 624 - if (!dsa_port_is_valid(dp) || 625 - dsa_port_is_dsa(dp) || 626 - dsa_port_is_cpu(dp)) 627 - continue; 628 - 629 - dp->cpu_dp = dst->cpu_dp; 630 - } 631 - } 632 - 633 - pr_info("DSA: tree %d parsed\n", dst->index); 634 531 635 532 return 0; 636 533 } ··· 711 768 return dsa_switch_parse_ports(ds, cd); 712 769 } 713 770 714 - static int _dsa_register_switch(struct dsa_switch *ds) 771 + static int dsa_switch_add(struct dsa_switch *ds) 772 + { 773 + struct dsa_switch_tree *dst = ds->dst; 774 + 775 + return dsa_tree_add_switch(dst, ds); 776 + } 777 + 778 + static int dsa_switch_probe(struct dsa_switch *ds) 715 779 { 716 780 struct dsa_chip_data *pdata = ds->dev->platform_data; 717 781 struct device_node *np = ds->dev->of_node; 718 - struct dsa_switch_tree *dst; 719 - unsigned int index; 720 - int i, err; 782 + int err; 721 783 722 784 if (np) 723 785 err = dsa_switch_parse_of(ds, np); ··· 734 786 if (err) 735 787 return err; 736 788 737 - index = ds->index; 738 - dst = ds->dst; 739 - 740 - /* Initialize the routing table */ 741 - for (i = 0; i < DSA_MAX_SWITCHES; ++i) 742 - ds->rtable[i] = DSA_RTABLE_NONE; 743 - 744 - err = dsa_tree_add_switch(dst, ds); 745 - if (err) 746 - return err; 747 - 748 - err = dsa_dst_complete(dst); 749 - if (err < 0) 750 - goto out_del_dst; 751 - 752 - /* Not all switches registered yet */ 753 - if (err == 1) 754 - return 0; 755 - 756 - if (dst->applied) { 757 - pr_info("DSA: Disjoint trees?\n"); 758 - return -EINVAL; 759 - } 760 - 761 - err = dsa_dst_parse(dst); 762 - if (err) 763 - goto out_del_dst; 764 - 765 - err = dsa_dst_apply(dst); 766 - if (err) { 767 - dsa_dst_unapply(dst); 768 - goto out_del_dst; 769 - } 770 - 771 - return 0; 772 - 773 - out_del_dst: 774 - dsa_tree_remove_switch(dst, index); 775 - 776 - return err; 789 + return dsa_switch_add(ds); 777 790 } 778 791 779 792 struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n) ··· 764 855 int err; 765 856 766 857 mutex_lock(&dsa2_mutex); 767 - err = _dsa_register_switch(ds); 858 + err = dsa_switch_probe(ds); 768 859 mutex_unlock(&dsa2_mutex); 769 860 770 861 return err; 771 862 } 772 863 EXPORT_SYMBOL_GPL(dsa_register_switch); 773 864 774 - static void _dsa_unregister_switch(struct dsa_switch *ds) 865 + static void dsa_switch_remove(struct dsa_switch *ds) 775 866 { 776 867 struct dsa_switch_tree *dst = ds->dst; 777 868 unsigned int index = ds->index; 778 - 779 - dsa_dst_unapply(dst); 780 869 781 870 dsa_tree_remove_switch(dst, index); 782 871 } ··· 782 875 void dsa_unregister_switch(struct dsa_switch *ds) 783 876 { 784 877 mutex_lock(&dsa2_mutex); 785 - _dsa_unregister_switch(ds); 878 + dsa_switch_remove(ds); 786 879 mutex_unlock(&dsa2_mutex); 787 880 } 788 881 EXPORT_SYMBOL_GPL(dsa_unregister_switch);
+2 -2
net/dsa/dsa_priv.h
··· 108 108 const unsigned char *addr, u16 vid); 109 109 110 110 /* master.c */ 111 - int dsa_master_ethtool_setup(struct net_device *dev); 112 - void dsa_master_ethtool_restore(struct net_device *dev); 111 + int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp); 112 + void dsa_master_teardown(struct net_device *dev); 113 113 114 114 static inline struct net_device *dsa_master_find_slave(struct net_device *dev, 115 115 int device, int port)
+2 -18
net/dsa/legacy.c
··· 593 593 if (!configured) 594 594 return -EPROBE_DEFER; 595 595 596 - /* 597 - * If we use a tagging format that doesn't have an ethertype 598 - * field, make sure that all packets from this point on get 599 - * sent to the tag format's receive function. 600 - */ 601 - wmb(); 602 - dev->dsa_ptr = dst->cpu_dp; 603 - 604 - return dsa_master_ethtool_setup(dst->cpu_dp->master); 596 + return dsa_master_setup(dst->cpu_dp->master, dst->cpu_dp); 605 597 } 606 598 607 599 static int dsa_probe(struct platform_device *pdev) ··· 658 666 { 659 667 int i; 660 668 661 - dsa_master_ethtool_restore(dst->cpu_dp->master); 662 - 663 - dst->cpu_dp->master->dsa_ptr = NULL; 664 - 665 - /* If we used a tagging format that doesn't have an ethertype 666 - * field, make sure that all packets from this point get sent 667 - * without the tag and go through the regular receive path. 668 - */ 669 - wmb(); 669 + dsa_master_teardown(dst->cpu_dp->master); 670 670 671 671 for (i = 0; i < dst->pd->nr_chips; i++) { 672 672 struct dsa_switch *ds = dst->ds[i];
+28 -2
net/dsa/master.c
··· 85 85 } 86 86 } 87 87 88 - int dsa_master_ethtool_setup(struct net_device *dev) 88 + static int dsa_master_ethtool_setup(struct net_device *dev) 89 89 { 90 90 struct dsa_port *cpu_dp = dev->dsa_ptr; 91 91 struct dsa_switch *ds = cpu_dp->ds; ··· 108 108 return 0; 109 109 } 110 110 111 - void dsa_master_ethtool_restore(struct net_device *dev) 111 + static void dsa_master_ethtool_teardown(struct net_device *dev) 112 112 { 113 113 struct dsa_port *cpu_dp = dev->dsa_ptr; 114 114 115 115 dev->ethtool_ops = cpu_dp->orig_ethtool_ops; 116 116 cpu_dp->orig_ethtool_ops = NULL; 117 + } 118 + 119 + int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) 120 + { 121 + /* If we use a tagging format that doesn't have an ethertype 122 + * field, make sure that all packets from this point on get 123 + * sent to the tag format's receive function. 124 + */ 125 + wmb(); 126 + 127 + dev->dsa_ptr = cpu_dp; 128 + 129 + return dsa_master_ethtool_setup(dev); 130 + } 131 + 132 + void dsa_master_teardown(struct net_device *dev) 133 + { 134 + dsa_master_ethtool_teardown(dev); 135 + 136 + dev->dsa_ptr = NULL; 137 + 138 + /* If we used a tagging format that doesn't have an ethertype 139 + * field, make sure that all packets from this point get sent 140 + * without the tag and go through the regular receive path. 141 + */ 142 + wmb(); 117 143 }
+1 -1
net/dsa/slave.c
··· 1147 1147 1148 1148 int dsa_slave_create(struct dsa_port *port) 1149 1149 { 1150 - struct dsa_port *cpu_dp = port->cpu_dp; 1150 + const struct dsa_port *cpu_dp = port->cpu_dp; 1151 1151 struct net_device *master = cpu_dp->master; 1152 1152 struct dsa_switch *ds = port->ds; 1153 1153 const char *name = port->name;