Skip to content

Commit 4283bce

Browse files
idoschdavem330
authored andcommitted
mlxsw: spectrum_router: Add support for route append
When a new route is appended, it's placed after existing routes sharing the same parameters (prefix, length, table ID, TOS and priority). While the device supports only one route with the same prefix and length in a single table, it's important to correctly place the appended route in the driver's cache, as when a route is deleted the next one is programmed into the device. Following the reception of an ENTRY_APPEND notification, resolve the FIB node corresponding to the prefix and length and correctly place the new entry in its entry list. Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9aecce1 commit 4283bce

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,14 +2105,38 @@ mlxsw_sp_fib4_node_entry_find(const struct mlxsw_sp_fib_node *fib_node,
21052105
return NULL;
21062106
}
21072107

2108+
static int mlxsw_sp_fib4_node_list_append(struct mlxsw_sp_fib_entry *fib_entry,
2109+
struct mlxsw_sp_fib_entry *new_entry)
2110+
{
2111+
struct mlxsw_sp_fib_node *fib_node;
2112+
2113+
if (WARN_ON(!fib_entry))
2114+
return -EINVAL;
2115+
2116+
fib_node = fib_entry->fib_node;
2117+
list_for_each_entry_from(fib_entry, &fib_node->entry_list, list) {
2118+
if (fib_entry->params.tb_id != new_entry->params.tb_id ||
2119+
fib_entry->params.tos != new_entry->params.tos ||
2120+
fib_entry->params.prio != new_entry->params.prio)
2121+
break;
2122+
}
2123+
2124+
list_add_tail(&new_entry->list, &fib_entry->list);
2125+
return 0;
2126+
}
2127+
21082128
static int
21092129
mlxsw_sp_fib4_node_list_insert(struct mlxsw_sp_fib_node *fib_node,
2110-
struct mlxsw_sp_fib_entry *new_entry)
2130+
struct mlxsw_sp_fib_entry *new_entry,
2131+
bool append)
21112132
{
21122133
struct mlxsw_sp_fib_entry *fib_entry;
21132134

21142135
fib_entry = mlxsw_sp_fib4_node_entry_find(fib_node, &new_entry->params);
21152136

2137+
if (append)
2138+
return mlxsw_sp_fib4_node_list_append(fib_entry, new_entry);
2139+
21162140
if (fib_entry) {
21172141
list_add_tail(&new_entry->list, &fib_entry->list);
21182142
} else {
@@ -2182,12 +2206,13 @@ mlxsw_sp_fib4_node_entry_del(struct mlxsw_sp *mlxsw_sp,
21822206
}
21832207

21842208
static int mlxsw_sp_fib4_node_entry_link(struct mlxsw_sp *mlxsw_sp,
2185-
struct mlxsw_sp_fib_entry *fib_entry)
2209+
struct mlxsw_sp_fib_entry *fib_entry,
2210+
bool append)
21862211
{
21872212
struct mlxsw_sp_fib_node *fib_node = fib_entry->fib_node;
21882213
int err;
21892214

2190-
err = mlxsw_sp_fib4_node_list_insert(fib_node, fib_entry);
2215+
err = mlxsw_sp_fib4_node_list_insert(fib_node, fib_entry, append);
21912216
if (err)
21922217
return err;
21932218

@@ -2217,7 +2242,8 @@ mlxsw_sp_fib4_node_entry_unlink(struct mlxsw_sp *mlxsw_sp,
22172242

22182243
static int
22192244
mlxsw_sp_router_fib4_add(struct mlxsw_sp *mlxsw_sp,
2220-
const struct fib_entry_notifier_info *fen_info)
2245+
const struct fib_entry_notifier_info *fen_info,
2246+
bool append)
22212247
{
22222248
struct mlxsw_sp_fib_entry *fib_entry;
22232249
struct mlxsw_sp_fib_node *fib_node;
@@ -2239,7 +2265,7 @@ mlxsw_sp_router_fib4_add(struct mlxsw_sp *mlxsw_sp,
22392265
goto err_fib4_entry_create;
22402266
}
22412267

2242-
err = mlxsw_sp_fib4_node_entry_link(mlxsw_sp, fib_entry);
2268+
err = mlxsw_sp_fib4_node_entry_link(mlxsw_sp, fib_entry, append);
22432269
if (err) {
22442270
dev_warn(mlxsw_sp->bus_info->dev, "Failed to link FIB entry to node\n");
22452271
goto err_fib4_node_entry_link;
@@ -2453,13 +2479,17 @@ static void mlxsw_sp_router_fib_event_work(struct work_struct *work)
24532479
struct mlxsw_sp_fib_event_work *fib_work =
24542480
container_of(work, struct mlxsw_sp_fib_event_work, work);
24552481
struct mlxsw_sp *mlxsw_sp = fib_work->mlxsw_sp;
2482+
bool append;
24562483
int err;
24572484

24582485
/* Protect internal structures from changes */
24592486
rtnl_lock();
24602487
switch (fib_work->event) {
2488+
case FIB_EVENT_ENTRY_APPEND: /* fall through */
24612489
case FIB_EVENT_ENTRY_ADD:
2462-
err = mlxsw_sp_router_fib4_add(mlxsw_sp, &fib_work->fen_info);
2490+
append = fib_work->event == FIB_EVENT_ENTRY_APPEND;
2491+
err = mlxsw_sp_router_fib4_add(mlxsw_sp, &fib_work->fen_info,
2492+
append);
24632493
if (err)
24642494
mlxsw_sp_router_fib4_abort(mlxsw_sp);
24652495
fib_info_put(fib_work->fen_info.fi);
@@ -2503,6 +2533,7 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
25032533
fib_work->event = event;
25042534

25052535
switch (event) {
2536+
case FIB_EVENT_ENTRY_APPEND: /* fall through */
25062537
case FIB_EVENT_ENTRY_ADD: /* fall through */
25072538
case FIB_EVENT_ENTRY_DEL:
25082539
memcpy(&fib_work->fen_info, ptr, sizeof(fib_work->fen_info));

0 commit comments

Comments
 (0)