fbd63a574300a5375440f1335ea4362ed3a2e784
[openwrt/staging/dedeckeh.git] /
1 From 1e3f407f3cacc5dcfe27166c412ed9bc263d82bf Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
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
7 After commit a57d8c217aad ("net: dsa: flush switchdev workqueue before
8 tearing down CPU/DSA ports"), the port setup and teardown procedure
9 became asymmetric.
10
11 The fact of the matter is that user ports need the shared ports to be up
12 before they can be used for CPU-initiated termination. And since we
13 register net devices for the user ports, those won't be functional until
14 we also call the setup for the shared (CPU, DSA) ports. But we may do
15 that later, depending on the port numbering scheme of the hardware we
16 are dealing with.
17
18 It just makes sense that all shared ports are brought up before any user
19 port is. I can't pinpoint any issue due to the current behavior, but
20 let's change it nonetheless, for consistency's sake.
21
22 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
23 Signed-off-by: David S. Miller <davem@davemloft.net>
24 ---
25 net/dsa/dsa2.c | 50 +++++++++++++++++++++++++++++++++++++-------------
26 1 file changed, 37 insertions(+), 13 deletions(-)
27
28 diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
29 index 52fb1958b535..ea0f02a24b8b 100644
30 --- a/net/dsa/dsa2.c
31 +++ b/net/dsa/dsa2.c
32 @@ -1003,23 +1003,28 @@ static void dsa_tree_teardown_switches(struct dsa_switch_tree *dst)
33 dsa_switch_teardown(dp->ds);
34 }
35
36 -static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
37 +/* Bring shared ports up first, then non-shared ports */
38 +static int dsa_tree_setup_ports(struct dsa_switch_tree *dst)
39 {
40 struct dsa_port *dp;
41 - int err;
42 + int err = 0;
43
44 list_for_each_entry(dp, &dst->ports, list) {
45 - err = dsa_switch_setup(dp->ds);
46 - if (err)
47 - goto teardown;
48 + if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) {
49 + err = dsa_port_setup(dp);
50 + if (err)
51 + goto teardown;
52 + }
53 }
54
55 list_for_each_entry(dp, &dst->ports, list) {
56 - err = dsa_port_setup(dp);
57 - if (err) {
58 - err = dsa_port_reinit_as_unused(dp);
59 - if (err)
60 - goto teardown;
61 + if (dsa_port_is_user(dp) || dsa_port_is_unused(dp)) {
62 + err = dsa_port_setup(dp);
63 + if (err) {
64 + err = dsa_port_reinit_as_unused(dp);
65 + if (err)
66 + goto teardown;
67 + }
68 }
69 }
70
71 @@ -1028,7 +1033,21 @@ static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
72 teardown:
73 dsa_tree_teardown_ports(dst);
74
75 - dsa_tree_teardown_switches(dst);
76 + return err;
77 +}
78 +
79 +static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
80 +{
81 + struct dsa_port *dp;
82 + int err = 0;
83 +
84 + list_for_each_entry(dp, &dst->ports, list) {
85 + err = dsa_switch_setup(dp->ds);
86 + if (err) {
87 + dsa_tree_teardown_switches(dst);
88 + break;
89 + }
90 + }
91
92 return err;
93 }
94 @@ -1115,10 +1134,14 @@ static int dsa_tree_setup(struct dsa_switch_tree *dst)
95 if (err)
96 goto teardown_cpu_ports;
97
98 - err = dsa_tree_setup_master(dst);
99 + err = dsa_tree_setup_ports(dst);
100 if (err)
101 goto teardown_switches;
102
103 + err = dsa_tree_setup_master(dst);
104 + if (err)
105 + goto teardown_ports;
106 +
107 err = dsa_tree_setup_lags(dst);
108 if (err)
109 goto teardown_master;
110 @@ -1131,8 +1154,9 @@ static int dsa_tree_setup(struct dsa_switch_tree *dst)
111
112 teardown_master:
113 dsa_tree_teardown_master(dst);
114 -teardown_switches:
115 +teardown_ports:
116 dsa_tree_teardown_ports(dst);
117 +teardown_switches:
118 dsa_tree_teardown_switches(dst);
119 teardown_cpu_ports:
120 dsa_tree_teardown_cpu_ports(dst);
121 --
122 2.34.1
123