@@ -78,18 +78,23 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
78
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
89
}
90
90
91
- static bool dsa_ds_find_port (struct dsa_switch * ds ,
92
- struct device_node * port )
91
+ static bool dsa_port_is_cpu (struct dsa_port * port )
92
+ {
93
+ return !!of_parse_phandle (port -> dn , "ethernet" , 0 );
94
+ }
95
+
96
+ static bool dsa_ds_find_port_dn (struct dsa_switch * ds ,
97
+ struct device_node * port )
93
98
{
94
99
u32 index ;
95
100
@@ -99,8 +104,8 @@ static bool dsa_ds_find_port(struct dsa_switch *ds,
99
104
return false;
100
105
}
101
106
102
- static struct dsa_switch * dsa_dst_find_port (struct dsa_switch_tree * dst ,
103
- struct device_node * port )
107
+ static struct dsa_switch * dsa_dst_find_port_dn (struct dsa_switch_tree * dst ,
108
+ struct device_node * port )
104
109
{
105
110
struct dsa_switch * ds ;
106
111
u32 index ;
@@ -110,7 +115,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
110
115
if (!ds )
111
116
continue ;
112
117
113
- if (dsa_ds_find_port (ds , port ))
118
+ if (dsa_ds_find_port_dn (ds , port ))
114
119
return ds ;
115
120
}
116
121
@@ -119,19 +124,19 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
119
124
120
125
static int dsa_port_complete (struct dsa_switch_tree * dst ,
121
126
struct dsa_switch * src_ds ,
122
- struct device_node * port ,
127
+ struct dsa_port * port ,
123
128
u32 src_port )
124
129
{
125
130
struct device_node * link ;
126
131
int index ;
127
132
struct dsa_switch * dst_ds ;
128
133
129
134
for (index = 0 ;; index ++ ) {
130
- link = of_parse_phandle (port , "link" , index );
135
+ link = of_parse_phandle (port -> dn , "link" , index );
131
136
if (!link )
132
137
break ;
133
138
134
- dst_ds = dsa_dst_find_port (dst , link );
139
+ dst_ds = dsa_dst_find_port_dn (dst , link );
135
140
of_node_put (link );
136
141
137
142
if (!dst_ds )
@@ -150,13 +155,13 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
150
155
*/
151
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
159
u32 index ;
155
160
int err ;
156
161
157
162
for (index = 0 ; index < DSA_MAX_PORTS ; index ++ ) {
158
- port = ds -> ports [index ]. dn ;
159
- if (!port )
163
+ port = & ds -> ports [index ];
164
+ if (!dsa_port_is_valid ( port ) )
160
165
continue ;
161
166
162
167
if (!dsa_port_is_dsa (port ))
@@ -196,7 +201,7 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst)
196
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
205
struct dsa_switch * ds )
201
206
{
202
207
int err ;
@@ -211,13 +216,13 @@ static int dsa_dsa_port_apply(struct device_node *port, u32 index,
211
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
220
struct dsa_switch * ds )
216
221
{
217
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
226
struct dsa_switch * ds )
222
227
{
223
228
int err ;
@@ -234,21 +239,21 @@ static int dsa_cpu_port_apply(struct device_node *port, u32 index,
234
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
243
struct dsa_switch * ds )
239
244
{
240
245
dsa_cpu_dsa_destroy (port );
241
246
ds -> cpu_port_mask &= ~BIT (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
251
struct dsa_switch * ds )
247
252
{
248
253
const char * name ;
249
254
int err ;
250
255
251
- name = of_get_property (port , "label" , NULL );
256
+ name = of_get_property (port -> dn , "label" , NULL );
252
257
if (!name )
253
258
name = "eth%d" ;
254
259
@@ -262,7 +267,7 @@ static int dsa_user_port_apply(struct device_node *port, u32 index,
262
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
271
struct dsa_switch * ds )
267
272
{
268
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
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
283
u32 index ;
279
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
315
for (index = 0 ; index < DSA_MAX_PORTS ; index ++ ) {
311
- port = ds -> ports [index ]. dn ;
312
- if (!port )
316
+ port = & ds -> ports [index ];
317
+ if (!dsa_port_is_valid ( port ) )
313
318
continue ;
314
319
315
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
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
345
u32 index ;
341
346
342
347
for (index = 0 ; index < DSA_MAX_PORTS ; index ++ ) {
343
- port = ds -> ports [index ]. dn ;
344
- if (!port )
348
+ port = & ds -> ports [index ];
349
+ if (!dsa_port_is_valid ( port ) )
345
350
continue ;
346
351
347
352
if (dsa_port_is_dsa (port )) {
@@ -425,15 +430,15 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
425
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
434
struct dsa_switch_tree * dst ,
430
435
struct dsa_switch * ds )
431
436
{
432
437
enum dsa_tag_protocol tag_protocol ;
433
438
struct net_device * ethernet_dev ;
434
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
442
if (!ethernet )
438
443
return - EINVAL ;
439
444
@@ -466,13 +471,13 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
466
471
467
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
475
u32 index ;
471
476
int err ;
472
477
473
478
for (index = 0 ; index < DSA_MAX_PORTS ; index ++ ) {
474
- port = ds -> ports [index ]. dn ;
475
- if (!port )
479
+ port = & ds -> ports [index ];
480
+ if (!dsa_port_is_valid ( port ) )
476
481
continue ;
477
482
478
483
if (dsa_port_is_cpu (port )) {
@@ -533,14 +538,14 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
533
538
* to have access to a correct value, just like what
534
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
542
ds -> enabled_port_mask |= 1 << reg ;
538
543
}
539
544
540
545
return 0 ;
541
546
}
542
547
543
- static int dsa_parse_member (struct device_node * np , u32 * tree , u32 * index )
548
+ static int dsa_parse_member_dn (struct device_node * np , u32 * tree , u32 * index )
544
549
{
545
550
int err ;
546
551
@@ -578,17 +583,19 @@ static struct device_node *dsa_get_ports(struct dsa_switch *ds,
578
583
return ports ;
579
584
}
580
585
581
- static int _dsa_register_switch (struct dsa_switch * ds , struct device_node * np )
586
+ static int _dsa_register_switch (struct dsa_switch * ds , struct device * dev )
582
587
{
583
- struct device_node * ports = dsa_get_ports ( ds , np ) ;
588
+ struct device_node * np = dev -> of_node ;
584
589
struct dsa_switch_tree * dst ;
590
+ struct device_node * ports ;
585
591
u32 tree , index ;
586
592
int i , err ;
587
593
588
- err = dsa_parse_member (np , & tree , & index );
594
+ err = dsa_parse_member_dn (np , & tree , & index );
589
595
if (err )
590
596
return err ;
591
597
598
+ ports = dsa_get_ports (ds , np );
592
599
if (IS_ERR (ports ))
593
600
return PTR_ERR (ports );
594
601
@@ -659,12 +666,12 @@ static int _dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
659
666
return err ;
660
667
}
661
668
662
- int dsa_register_switch (struct dsa_switch * ds , struct device_node * np )
669
+ int dsa_register_switch (struct dsa_switch * ds , struct device * dev )
663
670
{
664
671
int err ;
665
672
666
673
mutex_lock (& dsa2_mutex );
667
- err = _dsa_register_switch (ds , np );
674
+ err = _dsa_register_switch (ds , dev );
668
675
mutex_unlock (& dsa2_mutex );
669
676
670
677
return err ;
0 commit comments