Skip to content

Commit 35225e4

Browse files
pmachatadavem330
authored andcommitted
mlxsw: spectrum_router: Make nexthops typed
In the router, some next hops may reference an encapsulating netdevice, such as GRE or IPIP. To properly offload these next hops, mlxsw needs to keep track of whether a given next hop is a regular Ethernet entry, or an IP-in-IP tunneling entry. To facilitate this book-keeping, add a type field to struct mlxsw_sp_nexthop. There is, as of this patch, only one next hop type: MLXSW_SP_NEXTHOP_TYPE_ETH. Follow-up patches will introduce the IP-in-IP variant. There are several places where next hops are initialized in the IPv4 path. Instead of replicating the logic at every one of them, factor it out to a function mlxsw_sp_nexthop4_type_init(). The corresponding fini is actually protocol-neutral, so put it to mlxsw_sp_nexthop_type_fini(), but create a corresponding protocoled _fini function that dispatches to the protocol-neutral one. The IPv6 path is simpler, but for symmetry with IPv4, create the same suite of functions with corresponding logic. Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f6050ee commit 35225e4

File tree

1 file changed

+95
-43
lines changed

1 file changed

+95
-43
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 95 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,10 @@ static void mlxsw_sp_neigh_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
16521652
}
16531653
}
16541654

1655+
enum mlxsw_sp_nexthop_type {
1656+
MLXSW_SP_NEXTHOP_TYPE_ETH,
1657+
};
1658+
16551659
struct mlxsw_sp_nexthop_key {
16561660
struct fib_nh *fib_nh;
16571661
};
@@ -1676,7 +1680,10 @@ struct mlxsw_sp_nexthop {
16761680
update:1; /* set indicates that MAC of this neigh should be
16771681
* updated in HW
16781682
*/
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+
};
16801687
};
16811688

16821689
struct mlxsw_sp_nexthop_group {
@@ -1964,9 +1971,9 @@ static int mlxsw_sp_nexthop_mac_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
19641971
}
19651972

19661973
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)
19701977
{
19711978
u32 adj_index = nh_grp->adj_index; /* base */
19721979
struct mlxsw_sp_nexthop *nh;
@@ -1982,8 +1989,12 @@ mlxsw_sp_nexthop_group_mac_update(struct mlxsw_sp *mlxsw_sp,
19821989
}
19831990

19841991
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+
}
19871998
if (err)
19881999
return err;
19892000
nh->update = 0;
@@ -2071,8 +2082,7 @@ mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
20712082
/* Nothing was added or removed, so no need to reallocate. Just
20722083
* update MAC on existing adjacency indexes.
20732084
*/
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);
20762086
if (err) {
20772087
dev_warn(mlxsw_sp->bus_info->dev, "Failed to update neigh MAC in adjacency table.\n");
20782088
goto set_trap;
@@ -2099,7 +2109,7 @@ mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
20992109
nh_grp->adj_index_valid = 1;
21002110
nh_grp->adj_index = adj_index;
21012111
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);
21032113
if (err) {
21042114
dev_warn(mlxsw_sp->bus_info->dev, "Failed to update neigh MAC in adjacency table.\n");
21052115
goto set_trap;
@@ -2287,14 +2297,55 @@ static bool mlxsw_sp_netdev_ipip_type(const struct mlxsw_sp *mlxsw_sp,
22872297
return false;
22882298
}
22892299

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+
22902342
static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp,
22912343
struct mlxsw_sp_nexthop_group *nh_grp,
22922344
struct mlxsw_sp_nexthop *nh,
22932345
struct fib_nh *fib_nh)
22942346
{
22952347
struct net_device *dev = fib_nh->nh_dev;
22962348
struct in_device *in_dev;
2297-
struct mlxsw_sp_rif *rif;
22982349
int err;
22992350

23002351
nh->nh_grp = nh_grp;
@@ -2312,28 +2363,21 @@ static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp,
23122363
fib_nh->nh_flags & RTNH_F_LINKDOWN)
23132364
return 0;
23142365

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);
23212367
if (err)
23222368
goto err_nexthop_neigh_init;
23232369

23242370
return 0;
23252371

23262372
err_nexthop_neigh_init:
2327-
mlxsw_sp_nexthop_rif_fini(nh);
23282373
mlxsw_sp_nexthop_remove(mlxsw_sp, nh);
23292374
return err;
23302375
}
23312376

23322377
static void mlxsw_sp_nexthop4_fini(struct mlxsw_sp *mlxsw_sp,
23332378
struct mlxsw_sp_nexthop *nh)
23342379
{
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);
23372381
mlxsw_sp_nexthop_remove(mlxsw_sp, nh);
23382382
}
23392383

@@ -2342,7 +2386,6 @@ static void mlxsw_sp_nexthop4_event(struct mlxsw_sp *mlxsw_sp,
23422386
{
23432387
struct mlxsw_sp_nexthop_key key;
23442388
struct mlxsw_sp_nexthop *nh;
2345-
struct mlxsw_sp_rif *rif;
23462389

23472390
if (mlxsw_sp->router->aborted)
23482391
return;
@@ -2352,18 +2395,12 @@ static void mlxsw_sp_nexthop4_event(struct mlxsw_sp *mlxsw_sp,
23522395
if (WARN_ON_ONCE(!nh))
23532396
return;
23542397

2355-
rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, fib_nh->nh_dev);
2356-
if (!rif)
2357-
return;
2358-
23592398
switch (event) {
23602399
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);
23632401
break;
23642402
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);
23672404
break;
23682405
}
23692406

@@ -2376,8 +2413,7 @@ static void mlxsw_sp_nexthop_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
23762413
struct mlxsw_sp_nexthop *nh, *tmp;
23772414

23782415
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);
23812417
mlxsw_sp_nexthop_group_refresh(mlxsw_sp, nh->nh_grp);
23822418
}
23832419
}
@@ -3487,22 +3523,16 @@ mlxsw_sp_fib6_entry_rt_find(const struct mlxsw_sp_fib6_entry *fib6_entry,
34873523
return NULL;
34883524
}
34893525

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)
34943530
{
34953531
struct net_device *dev = rt->dst.dev;
34963532
struct mlxsw_sp_rif *rif;
34973533
int err;
34983534

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;
35063536
rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, dev);
35073537
if (!rif)
35083538
return 0;
@@ -3519,11 +3549,33 @@ static int mlxsw_sp_nexthop6_init(struct mlxsw_sp *mlxsw_sp,
35193549
return err;
35203550
}
35213551

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+
35223575
static void mlxsw_sp_nexthop6_fini(struct mlxsw_sp *mlxsw_sp,
35233576
struct mlxsw_sp_nexthop *nh)
35243577
{
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);
35273579
}
35283580

35293581
static bool mlxsw_sp_rt6_is_gateway(const struct mlxsw_sp *mlxsw_sp,

0 commit comments

Comments
 (0)