765-v5.17-05-net-next-net-dsa-first-set-up-shared-ports-then-non-shared-po.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. From 1e3f407f3cacc5dcfe27166c412ed9bc263d82bf Mon Sep 17 00:00:00 2001
  2. From: Vladimir Oltean <[email protected]>
  3. Date: Thu, 6 Jan 2022 01:11:16 +0200
  4. Subject: [PATCH 5/6] net: dsa: first set up shared ports, then non-shared
  5. ports
  6. After commit a57d8c217aad ("net: dsa: flush switchdev workqueue before
  7. tearing down CPU/DSA ports"), the port setup and teardown procedure
  8. became asymmetric.
  9. The fact of the matter is that user ports need the shared ports to be up
  10. before they can be used for CPU-initiated termination. And since we
  11. register net devices for the user ports, those won't be functional until
  12. we also call the setup for the shared (CPU, DSA) ports. But we may do
  13. that later, depending on the port numbering scheme of the hardware we
  14. are dealing with.
  15. It just makes sense that all shared ports are brought up before any user
  16. port is. I can't pinpoint any issue due to the current behavior, but
  17. let's change it nonetheless, for consistency's sake.
  18. Signed-off-by: Vladimir Oltean <[email protected]>
  19. Signed-off-by: David S. Miller <[email protected]>
  20. ---
  21. net/dsa/dsa2.c | 50 +++++++++++++++++++++++++++++++++++++-------------
  22. 1 file changed, 37 insertions(+), 13 deletions(-)
  23. --- a/net/dsa/dsa2.c
  24. +++ b/net/dsa/dsa2.c
  25. @@ -1021,23 +1021,28 @@ static void dsa_tree_teardown_switches(s
  26. dsa_switch_teardown(dp->ds);
  27. }
  28. -static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
  29. +/* Bring shared ports up first, then non-shared ports */
  30. +static int dsa_tree_setup_ports(struct dsa_switch_tree *dst)
  31. {
  32. struct dsa_port *dp;
  33. - int err;
  34. + int err = 0;
  35. list_for_each_entry(dp, &dst->ports, list) {
  36. - err = dsa_switch_setup(dp->ds);
  37. - if (err)
  38. - goto teardown;
  39. + if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) {
  40. + err = dsa_port_setup(dp);
  41. + if (err)
  42. + goto teardown;
  43. + }
  44. }
  45. list_for_each_entry(dp, &dst->ports, list) {
  46. - err = dsa_port_setup(dp);
  47. - if (err) {
  48. - err = dsa_port_reinit_as_unused(dp);
  49. - if (err)
  50. - goto teardown;
  51. + if (dsa_port_is_user(dp) || dsa_port_is_unused(dp)) {
  52. + err = dsa_port_setup(dp);
  53. + if (err) {
  54. + err = dsa_port_reinit_as_unused(dp);
  55. + if (err)
  56. + goto teardown;
  57. + }
  58. }
  59. }
  60. @@ -1046,7 +1051,21 @@ static int dsa_tree_setup_switches(struc
  61. teardown:
  62. dsa_tree_teardown_ports(dst);
  63. - dsa_tree_teardown_switches(dst);
  64. + return err;
  65. +}
  66. +
  67. +static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
  68. +{
  69. + struct dsa_port *dp;
  70. + int err = 0;
  71. +
  72. + list_for_each_entry(dp, &dst->ports, list) {
  73. + err = dsa_switch_setup(dp->ds);
  74. + if (err) {
  75. + dsa_tree_teardown_switches(dst);
  76. + break;
  77. + }
  78. + }
  79. return err;
  80. }
  81. @@ -1133,10 +1152,14 @@ static int dsa_tree_setup(struct dsa_swi
  82. if (err)
  83. goto teardown_cpu_ports;
  84. - err = dsa_tree_setup_master(dst);
  85. + err = dsa_tree_setup_ports(dst);
  86. if (err)
  87. goto teardown_switches;
  88. + err = dsa_tree_setup_master(dst);
  89. + if (err)
  90. + goto teardown_ports;
  91. +
  92. err = dsa_tree_setup_lags(dst);
  93. if (err)
  94. goto teardown_master;
  95. @@ -1149,8 +1172,9 @@ static int dsa_tree_setup(struct dsa_swi
  96. teardown_master:
  97. dsa_tree_teardown_master(dst);
  98. -teardown_switches:
  99. +teardown_ports:
  100. dsa_tree_teardown_ports(dst);
  101. +teardown_switches:
  102. dsa_tree_teardown_switches(dst);
  103. teardown_cpu_ports:
  104. dsa_tree_teardown_cpu_ports(dst);