@@ -1652,6 +1652,10 @@ static void mlxsw_sp_neigh_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
1652
1652
}
1653
1653
}
1654
1654
1655
+ enum mlxsw_sp_nexthop_type {
1656
+ MLXSW_SP_NEXTHOP_TYPE_ETH ,
1657
+ };
1658
+
1655
1659
struct mlxsw_sp_nexthop_key {
1656
1660
struct fib_nh * fib_nh ;
1657
1661
};
@@ -1676,7 +1680,10 @@ struct mlxsw_sp_nexthop {
1676
1680
update :1 ; /* set indicates that MAC of this neigh should be
1677
1681
* updated in HW
1678
1682
*/
1679
- struct mlxsw_sp_neigh_entry * neigh_entry ;
1683
+ enum mlxsw_sp_nexthop_type type ;
1684
+ union {
1685
+ struct mlxsw_sp_neigh_entry * neigh_entry ;
1686
+ };
1680
1687
};
1681
1688
1682
1689
struct mlxsw_sp_nexthop_group {
@@ -1964,9 +1971,9 @@ static int mlxsw_sp_nexthop_mac_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
1964
1971
}
1965
1972
1966
1973
static int
1967
- mlxsw_sp_nexthop_group_mac_update (struct mlxsw_sp * mlxsw_sp ,
1968
- struct mlxsw_sp_nexthop_group * nh_grp ,
1969
- bool reallocate )
1974
+ mlxsw_sp_nexthop_group_update (struct mlxsw_sp * mlxsw_sp ,
1975
+ struct mlxsw_sp_nexthop_group * nh_grp ,
1976
+ bool reallocate )
1970
1977
{
1971
1978
u32 adj_index = nh_grp -> adj_index ; /* base */
1972
1979
struct mlxsw_sp_nexthop * nh ;
@@ -1982,8 +1989,12 @@ mlxsw_sp_nexthop_group_mac_update(struct mlxsw_sp *mlxsw_sp,
1982
1989
}
1983
1990
1984
1991
if (nh -> update || reallocate ) {
1985
- err = mlxsw_sp_nexthop_mac_update (mlxsw_sp ,
1986
- adj_index , nh );
1992
+ switch (nh -> type ) {
1993
+ case MLXSW_SP_NEXTHOP_TYPE_ETH :
1994
+ err = mlxsw_sp_nexthop_mac_update
1995
+ (mlxsw_sp , adj_index , nh );
1996
+ break ;
1997
+ }
1987
1998
if (err )
1988
1999
return err ;
1989
2000
nh -> update = 0 ;
@@ -2071,8 +2082,7 @@ mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
2071
2082
/* Nothing was added or removed, so no need to reallocate. Just
2072
2083
* update MAC on existing adjacency indexes.
2073
2084
*/
2074
- err = mlxsw_sp_nexthop_group_mac_update (mlxsw_sp , nh_grp ,
2075
- false);
2085
+ err = mlxsw_sp_nexthop_group_update (mlxsw_sp , nh_grp , false);
2076
2086
if (err ) {
2077
2087
dev_warn (mlxsw_sp -> bus_info -> dev , "Failed to update neigh MAC in adjacency table.\n" );
2078
2088
goto set_trap ;
@@ -2099,7 +2109,7 @@ mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
2099
2109
nh_grp -> adj_index_valid = 1 ;
2100
2110
nh_grp -> adj_index = adj_index ;
2101
2111
nh_grp -> ecmp_size = ecmp_size ;
2102
- err = mlxsw_sp_nexthop_group_mac_update (mlxsw_sp , nh_grp , true);
2112
+ err = mlxsw_sp_nexthop_group_update (mlxsw_sp , nh_grp , true);
2103
2113
if (err ) {
2104
2114
dev_warn (mlxsw_sp -> bus_info -> dev , "Failed to update neigh MAC in adjacency table.\n" );
2105
2115
goto set_trap ;
@@ -2287,14 +2297,55 @@ static bool mlxsw_sp_netdev_ipip_type(const struct mlxsw_sp *mlxsw_sp,
2287
2297
return false;
2288
2298
}
2289
2299
2300
+ static void mlxsw_sp_nexthop_type_fini (struct mlxsw_sp * mlxsw_sp ,
2301
+ struct mlxsw_sp_nexthop * nh )
2302
+ {
2303
+ switch (nh -> type ) {
2304
+ case MLXSW_SP_NEXTHOP_TYPE_ETH :
2305
+ mlxsw_sp_nexthop_neigh_fini (mlxsw_sp , nh );
2306
+ mlxsw_sp_nexthop_rif_fini (nh );
2307
+ break ;
2308
+ }
2309
+ }
2310
+
2311
+ static int mlxsw_sp_nexthop4_type_init (struct mlxsw_sp * mlxsw_sp ,
2312
+ struct mlxsw_sp_nexthop * nh ,
2313
+ struct fib_nh * fib_nh )
2314
+ {
2315
+ struct net_device * dev = fib_nh -> nh_dev ;
2316
+ struct mlxsw_sp_rif * rif ;
2317
+ int err ;
2318
+
2319
+ nh -> type = MLXSW_SP_NEXTHOP_TYPE_ETH ;
2320
+ rif = mlxsw_sp_rif_find_by_dev (mlxsw_sp , dev );
2321
+ if (!rif )
2322
+ return 0 ;
2323
+
2324
+ mlxsw_sp_nexthop_rif_init (nh , rif );
2325
+ err = mlxsw_sp_nexthop_neigh_init (mlxsw_sp , nh );
2326
+ if (err )
2327
+ goto err_neigh_init ;
2328
+
2329
+ return 0 ;
2330
+
2331
+ err_neigh_init :
2332
+ mlxsw_sp_nexthop_rif_fini (nh );
2333
+ return err ;
2334
+ }
2335
+
2336
+ static void mlxsw_sp_nexthop4_type_fini (struct mlxsw_sp * mlxsw_sp ,
2337
+ struct mlxsw_sp_nexthop * nh )
2338
+ {
2339
+ mlxsw_sp_nexthop_type_fini (mlxsw_sp , nh );
2340
+ }
2341
+
2290
2342
static int mlxsw_sp_nexthop4_init (struct mlxsw_sp * mlxsw_sp ,
2291
2343
struct mlxsw_sp_nexthop_group * nh_grp ,
2292
2344
struct mlxsw_sp_nexthop * nh ,
2293
2345
struct fib_nh * fib_nh )
2294
2346
{
2295
2347
struct net_device * dev = fib_nh -> nh_dev ;
2296
2348
struct in_device * in_dev ;
2297
- struct mlxsw_sp_rif * rif ;
2298
2349
int err ;
2299
2350
2300
2351
nh -> nh_grp = nh_grp ;
@@ -2312,28 +2363,21 @@ static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp,
2312
2363
fib_nh -> nh_flags & RTNH_F_LINKDOWN )
2313
2364
return 0 ;
2314
2365
2315
- rif = mlxsw_sp_rif_find_by_dev (mlxsw_sp , dev );
2316
- if (!rif )
2317
- return 0 ;
2318
- mlxsw_sp_nexthop_rif_init (nh , rif );
2319
-
2320
- err = mlxsw_sp_nexthop_neigh_init (mlxsw_sp , nh );
2366
+ err = mlxsw_sp_nexthop4_type_init (mlxsw_sp , nh , fib_nh );
2321
2367
if (err )
2322
2368
goto err_nexthop_neigh_init ;
2323
2369
2324
2370
return 0 ;
2325
2371
2326
2372
err_nexthop_neigh_init :
2327
- mlxsw_sp_nexthop_rif_fini (nh );
2328
2373
mlxsw_sp_nexthop_remove (mlxsw_sp , nh );
2329
2374
return err ;
2330
2375
}
2331
2376
2332
2377
static void mlxsw_sp_nexthop4_fini (struct mlxsw_sp * mlxsw_sp ,
2333
2378
struct mlxsw_sp_nexthop * nh )
2334
2379
{
2335
- mlxsw_sp_nexthop_neigh_fini (mlxsw_sp , nh );
2336
- mlxsw_sp_nexthop_rif_fini (nh );
2380
+ mlxsw_sp_nexthop4_type_fini (mlxsw_sp , nh );
2337
2381
mlxsw_sp_nexthop_remove (mlxsw_sp , nh );
2338
2382
}
2339
2383
@@ -2342,7 +2386,6 @@ static void mlxsw_sp_nexthop4_event(struct mlxsw_sp *mlxsw_sp,
2342
2386
{
2343
2387
struct mlxsw_sp_nexthop_key key ;
2344
2388
struct mlxsw_sp_nexthop * nh ;
2345
- struct mlxsw_sp_rif * rif ;
2346
2389
2347
2390
if (mlxsw_sp -> router -> aborted )
2348
2391
return ;
@@ -2352,18 +2395,12 @@ static void mlxsw_sp_nexthop4_event(struct mlxsw_sp *mlxsw_sp,
2352
2395
if (WARN_ON_ONCE (!nh ))
2353
2396
return ;
2354
2397
2355
- rif = mlxsw_sp_rif_find_by_dev (mlxsw_sp , fib_nh -> nh_dev );
2356
- if (!rif )
2357
- return ;
2358
-
2359
2398
switch (event ) {
2360
2399
case FIB_EVENT_NH_ADD :
2361
- mlxsw_sp_nexthop_rif_init (nh , rif );
2362
- mlxsw_sp_nexthop_neigh_init (mlxsw_sp , nh );
2400
+ mlxsw_sp_nexthop4_type_init (mlxsw_sp , nh , fib_nh );
2363
2401
break ;
2364
2402
case FIB_EVENT_NH_DEL :
2365
- mlxsw_sp_nexthop_neigh_fini (mlxsw_sp , nh );
2366
- mlxsw_sp_nexthop_rif_fini (nh );
2403
+ mlxsw_sp_nexthop4_type_fini (mlxsw_sp , nh );
2367
2404
break ;
2368
2405
}
2369
2406
@@ -2376,8 +2413,7 @@ static void mlxsw_sp_nexthop_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
2376
2413
struct mlxsw_sp_nexthop * nh , * tmp ;
2377
2414
2378
2415
list_for_each_entry_safe (nh , tmp , & rif -> nexthop_list , rif_list_node ) {
2379
- mlxsw_sp_nexthop_neigh_fini (mlxsw_sp , nh );
2380
- mlxsw_sp_nexthop_rif_fini (nh );
2416
+ mlxsw_sp_nexthop_type_fini (mlxsw_sp , nh );
2381
2417
mlxsw_sp_nexthop_group_refresh (mlxsw_sp , nh -> nh_grp );
2382
2418
}
2383
2419
}
@@ -3487,22 +3523,16 @@ mlxsw_sp_fib6_entry_rt_find(const struct mlxsw_sp_fib6_entry *fib6_entry,
3487
3523
return NULL ;
3488
3524
}
3489
3525
3490
- static int mlxsw_sp_nexthop6_init (struct mlxsw_sp * mlxsw_sp ,
3491
- struct mlxsw_sp_nexthop_group * nh_grp ,
3492
- struct mlxsw_sp_nexthop * nh ,
3493
- const struct rt6_info * rt )
3526
+ static int mlxsw_sp_nexthop6_type_init (struct mlxsw_sp * mlxsw_sp ,
3527
+ struct mlxsw_sp_nexthop_group * nh_grp ,
3528
+ struct mlxsw_sp_nexthop * nh ,
3529
+ const struct rt6_info * rt )
3494
3530
{
3495
3531
struct net_device * dev = rt -> dst .dev ;
3496
3532
struct mlxsw_sp_rif * rif ;
3497
3533
int err ;
3498
3534
3499
- nh -> nh_grp = nh_grp ;
3500
- memcpy (& nh -> gw_addr , & rt -> rt6i_gateway , sizeof (nh -> gw_addr ));
3501
-
3502
- if (!dev )
3503
- return 0 ;
3504
- nh -> ifindex = dev -> ifindex ;
3505
-
3535
+ nh -> type = MLXSW_SP_NEXTHOP_TYPE_ETH ;
3506
3536
rif = mlxsw_sp_rif_find_by_dev (mlxsw_sp , dev );
3507
3537
if (!rif )
3508
3538
return 0 ;
@@ -3519,11 +3549,33 @@ static int mlxsw_sp_nexthop6_init(struct mlxsw_sp *mlxsw_sp,
3519
3549
return err ;
3520
3550
}
3521
3551
3552
+ static void mlxsw_sp_nexthop6_type_fini (struct mlxsw_sp * mlxsw_sp ,
3553
+ struct mlxsw_sp_nexthop * nh )
3554
+ {
3555
+ mlxsw_sp_nexthop_type_fini (mlxsw_sp , nh );
3556
+ }
3557
+
3558
+ static int mlxsw_sp_nexthop6_init (struct mlxsw_sp * mlxsw_sp ,
3559
+ struct mlxsw_sp_nexthop_group * nh_grp ,
3560
+ struct mlxsw_sp_nexthop * nh ,
3561
+ const struct rt6_info * rt )
3562
+ {
3563
+ struct net_device * dev = rt -> dst .dev ;
3564
+
3565
+ nh -> nh_grp = nh_grp ;
3566
+ memcpy (& nh -> gw_addr , & rt -> rt6i_gateway , sizeof (nh -> gw_addr ));
3567
+
3568
+ if (!dev )
3569
+ return 0 ;
3570
+ nh -> ifindex = dev -> ifindex ;
3571
+
3572
+ return mlxsw_sp_nexthop6_type_init (mlxsw_sp , nh_grp , nh , rt );
3573
+ }
3574
+
3522
3575
static void mlxsw_sp_nexthop6_fini (struct mlxsw_sp * mlxsw_sp ,
3523
3576
struct mlxsw_sp_nexthop * nh )
3524
3577
{
3525
- mlxsw_sp_nexthop_neigh_fini (mlxsw_sp , nh );
3526
- mlxsw_sp_nexthop_rif_fini (nh );
3578
+ mlxsw_sp_nexthop6_type_fini (mlxsw_sp , nh );
3527
3579
}
3528
3580
3529
3581
static bool mlxsw_sp_rt6_is_gateway (const struct mlxsw_sp * mlxsw_sp ,
0 commit comments