@@ -214,66 +214,59 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst)
214
214
return 0 ;
215
215
}
216
216
217
- static int dsa_dsa_port_apply (struct dsa_port * port , u32 index ,
218
- struct dsa_switch * ds )
217
+ static int dsa_dsa_port_apply (struct dsa_port * port )
219
218
{
219
+ struct dsa_switch * ds = port -> ds ;
220
220
int err ;
221
221
222
- err = dsa_cpu_dsa_setup (ds , ds -> dev , port , index );
222
+ err = dsa_cpu_dsa_setup (ds , ds -> dev , port , port -> index );
223
223
if (err ) {
224
224
dev_warn (ds -> dev , "Failed to setup dsa port %d: %d\n" ,
225
- index , err );
225
+ port -> index , err );
226
226
return err ;
227
227
}
228
228
229
- memset (& ds -> ports [index ].devlink_port , 0 ,
230
- sizeof (ds -> ports [index ].devlink_port ));
229
+ memset (& port -> devlink_port , 0 , sizeof (port -> devlink_port ));
231
230
232
- return devlink_port_register (ds -> devlink ,
233
- & ds -> ports [index ].devlink_port ,
234
- index );
231
+ return devlink_port_register (ds -> devlink , & port -> devlink_port ,
232
+ port -> index );
235
233
}
236
234
237
- static void dsa_dsa_port_unapply (struct dsa_port * port , u32 index ,
238
- struct dsa_switch * ds )
235
+ static void dsa_dsa_port_unapply (struct dsa_port * port )
239
236
{
240
- devlink_port_unregister (& ds -> ports [ index ]. devlink_port );
237
+ devlink_port_unregister (& port -> devlink_port );
241
238
dsa_cpu_dsa_destroy (port );
242
239
}
243
240
244
- static int dsa_cpu_port_apply (struct dsa_port * port , u32 index ,
245
- struct dsa_switch * ds )
241
+ static int dsa_cpu_port_apply (struct dsa_port * port )
246
242
{
243
+ struct dsa_switch * ds = port -> ds ;
247
244
int err ;
248
245
249
- err = dsa_cpu_dsa_setup (ds , ds -> dev , port , index );
246
+ err = dsa_cpu_dsa_setup (ds , ds -> dev , port , port -> index );
250
247
if (err ) {
251
248
dev_warn (ds -> dev , "Failed to setup cpu port %d: %d\n" ,
252
- index , err );
249
+ port -> index , err );
253
250
return err ;
254
251
}
255
252
256
- ds -> cpu_port_mask |= BIT (index );
257
-
258
- memset (& ds -> ports [index ].devlink_port , 0 ,
259
- sizeof (ds -> ports [index ].devlink_port ));
260
- err = devlink_port_register (ds -> devlink , & ds -> ports [index ].devlink_port ,
261
- index );
253
+ memset (& port -> devlink_port , 0 , sizeof (port -> devlink_port ));
254
+ err = devlink_port_register (ds -> devlink , & port -> devlink_port ,
255
+ port -> index );
262
256
return err ;
263
257
}
264
258
265
- static void dsa_cpu_port_unapply (struct dsa_port * port , u32 index ,
266
- struct dsa_switch * ds )
259
+ static void dsa_cpu_port_unapply (struct dsa_port * port )
267
260
{
268
- devlink_port_unregister (& ds -> ports [ index ]. devlink_port );
261
+ devlink_port_unregister (& port -> devlink_port );
269
262
dsa_cpu_dsa_destroy (port );
270
- ds -> cpu_port_mask &= ~BIT (index );
263
+ port -> ds -> cpu_port_mask &= ~BIT (port -> index );
271
264
272
265
}
273
266
274
- static int dsa_user_port_apply (struct dsa_port * port , u32 index ,
275
- struct dsa_switch * ds )
267
+ static int dsa_user_port_apply (struct dsa_port * port )
276
268
{
269
+ struct dsa_switch * ds = port -> ds ;
277
270
const char * name = port -> name ;
278
271
int err ;
279
272
@@ -282,35 +275,32 @@ static int dsa_user_port_apply(struct dsa_port *port, u32 index,
282
275
if (!name )
283
276
name = "eth%d" ;
284
277
285
- err = dsa_slave_create (ds , ds -> dev , index , name );
278
+ err = dsa_slave_create (ds , ds -> dev , port -> index , name );
286
279
if (err ) {
287
280
dev_warn (ds -> dev , "Failed to create slave %d: %d\n" ,
288
- index , err );
289
- ds -> ports [ index ]. netdev = NULL ;
281
+ port -> index , err );
282
+ port -> netdev = NULL ;
290
283
return err ;
291
284
}
292
285
293
- memset (& ds -> ports [index ].devlink_port , 0 ,
294
- sizeof (ds -> ports [index ].devlink_port ));
295
- err = devlink_port_register (ds -> devlink , & ds -> ports [index ].devlink_port ,
296
- index );
286
+ memset (& port -> devlink_port , 0 , sizeof (port -> devlink_port ));
287
+ err = devlink_port_register (ds -> devlink , & port -> devlink_port ,
288
+ port -> index );
297
289
if (err )
298
290
return err ;
299
291
300
- devlink_port_type_eth_set (& ds -> ports [index ].devlink_port ,
301
- ds -> ports [index ].netdev );
292
+ devlink_port_type_eth_set (& port -> devlink_port , port -> netdev );
302
293
303
294
return 0 ;
304
295
}
305
296
306
- static void dsa_user_port_unapply (struct dsa_port * port , u32 index ,
307
- struct dsa_switch * ds )
297
+ static void dsa_user_port_unapply (struct dsa_port * port )
308
298
{
309
- devlink_port_unregister (& ds -> ports [ index ]. devlink_port );
310
- if (ds -> ports [ index ]. netdev ) {
311
- dsa_slave_destroy (ds -> ports [ index ]. netdev );
312
- ds -> ports [ index ]. netdev = NULL ;
313
- ds -> enabled_port_mask &= ~(1 << index );
299
+ devlink_port_unregister (& port -> devlink_port );
300
+ if (port -> netdev ) {
301
+ dsa_slave_destroy (port -> netdev );
302
+ port -> netdev = NULL ;
303
+ port -> ds -> enabled_port_mask &= ~(1 << port -> index );
314
304
}
315
305
}
316
306
@@ -370,20 +360,20 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
370
360
continue ;
371
361
372
362
if (dsa_port_is_dsa (port )) {
373
- err = dsa_dsa_port_apply (port , index , ds );
363
+ err = dsa_dsa_port_apply (port );
374
364
if (err )
375
365
return err ;
376
366
continue ;
377
367
}
378
368
379
369
if (dsa_port_is_cpu (port )) {
380
- err = dsa_cpu_port_apply (port , index , ds );
370
+ err = dsa_cpu_port_apply (port );
381
371
if (err )
382
372
return err ;
383
373
continue ;
384
374
}
385
375
386
- err = dsa_user_port_apply (port , index , ds );
376
+ err = dsa_user_port_apply (port );
387
377
if (err )
388
378
continue ;
389
379
}
@@ -402,16 +392,16 @@ static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
402
392
continue ;
403
393
404
394
if (dsa_port_is_dsa (port )) {
405
- dsa_dsa_port_unapply (port , index , ds );
395
+ dsa_dsa_port_unapply (port );
406
396
continue ;
407
397
}
408
398
409
399
if (dsa_port_is_cpu (port )) {
410
- dsa_cpu_port_unapply (port , index , ds );
400
+ dsa_cpu_port_unapply (port );
411
401
continue ;
412
402
}
413
403
414
- dsa_user_port_unapply (port , index , ds );
404
+ dsa_user_port_unapply (port );
415
405
}
416
406
417
407
if (ds -> slave_mii_bus && ds -> ops -> phy_read )
@@ -444,7 +434,7 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
444
434
}
445
435
446
436
if (dst -> cpu_dp ) {
447
- err = dsa_cpu_port_ethtool_setup (dst -> cpu_dp -> ds );
437
+ err = dsa_cpu_port_ethtool_setup (dst -> cpu_dp );
448
438
if (err )
449
439
return err ;
450
440
}
@@ -485,7 +475,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
485
475
}
486
476
487
477
if (dst -> cpu_dp )
488
- dsa_cpu_port_ethtool_restore (dst -> cpu_dp -> ds );
478
+ dsa_cpu_port_ethtool_restore (dst -> cpu_dp );
489
479
490
480
pr_info ("DSA: tree %d unapplied\n" , dst -> tree );
491
481
dst -> applied = false;
@@ -530,6 +520,12 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
530
520
531
521
dst -> rcv = dst -> tag_ops -> rcv ;
532
522
523
+ /* Initialize cpu_port_mask now for drv->setup()
524
+ * to have access to a correct value, just like what
525
+ * net/dsa/dsa.c::dsa_switch_setup_one does.
526
+ */
527
+ ds -> cpu_port_mask |= BIT (index );
528
+
533
529
return 0 ;
534
530
}
535
531
@@ -541,14 +537,22 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
541
537
542
538
for (index = 0 ; index < ds -> num_ports ; index ++ ) {
543
539
port = & ds -> ports [index ];
544
- if (!dsa_port_is_valid (port ))
540
+ if (!dsa_port_is_valid (port ) ||
541
+ dsa_port_is_dsa (port ))
545
542
continue ;
546
543
547
544
if (dsa_port_is_cpu (port )) {
548
545
err = dsa_cpu_parse (port , index , dst , ds );
549
546
if (err )
550
547
return err ;
548
+ } else {
549
+ /* Initialize enabled_port_mask now for drv->setup()
550
+ * to have access to a correct value, just like what
551
+ * net/dsa/dsa.c::dsa_switch_setup_one does.
552
+ */
553
+ ds -> enabled_port_mask |= BIT (index );
551
554
}
555
+
552
556
}
553
557
554
558
pr_info ("DSA: switch %d %d parsed\n" , dst -> tree , ds -> index );
@@ -597,13 +601,6 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
597
601
return - EINVAL ;
598
602
599
603
ds -> ports [reg ].dn = port ;
600
-
601
- /* Initialize enabled_port_mask now for ops->setup()
602
- * to have access to a correct value, just like what
603
- * net/dsa/dsa.c::dsa_switch_setup_one does.
604
- */
605
- if (!dsa_port_is_cpu (& ds -> ports [reg ]))
606
- ds -> enabled_port_mask |= 1 << reg ;
607
604
}
608
605
609
606
return 0 ;
@@ -619,14 +616,6 @@ static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds)
619
616
continue ;
620
617
621
618
ds -> ports [i ].name = cd -> port_names [i ];
622
-
623
- /* Initialize enabled_port_mask now for drv->setup()
624
- * to have access to a correct value, just like what
625
- * net/dsa/dsa.c::dsa_switch_setup_one does.
626
- */
627
- if (!dsa_port_is_cpu (& ds -> ports [i ]))
628
- ds -> enabled_port_mask |= 1 << i ;
629
-
630
619
valid_name_found = true;
631
620
}
632
621
0 commit comments