Commit b6a1d871 authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

mlxsw: spectrum_router: Start using new IPv4 route notifications

With the new notifications mlxsw does not need to handle identical
routes itself, as this is taken care of by the core IPv4 code.

Instead, mlxsw only needs to take care of inserting and removing routes
from the device.

Convert mlxsw to use the new IPv4 route notifications and simplify the
code.
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 20d15652
...@@ -3845,7 +3845,7 @@ static void mlxsw_sp_nexthop4_event(struct mlxsw_sp *mlxsw_sp, ...@@ -3845,7 +3845,7 @@ static void mlxsw_sp_nexthop4_event(struct mlxsw_sp *mlxsw_sp,
key.fib_nh = fib_nh; key.fib_nh = fib_nh;
nh = mlxsw_sp_nexthop_lookup(mlxsw_sp, key); nh = mlxsw_sp_nexthop_lookup(mlxsw_sp, key);
if (WARN_ON_ONCE(!nh)) if (!nh)
return; return;
switch (event) { switch (event) {
...@@ -4780,95 +4780,6 @@ static void mlxsw_sp_fib_node_put(struct mlxsw_sp *mlxsw_sp, ...@@ -4780,95 +4780,6 @@ static void mlxsw_sp_fib_node_put(struct mlxsw_sp *mlxsw_sp,
mlxsw_sp_vr_put(mlxsw_sp, vr); mlxsw_sp_vr_put(mlxsw_sp, vr);
} }
static struct mlxsw_sp_fib4_entry *
mlxsw_sp_fib4_node_entry_find(const struct mlxsw_sp_fib_node *fib_node,
const struct mlxsw_sp_fib4_entry *new4_entry)
{
struct mlxsw_sp_fib4_entry *fib4_entry;
list_for_each_entry(fib4_entry, &fib_node->entry_list, common.list) {
if (fib4_entry->tb_id > new4_entry->tb_id)
continue;
if (fib4_entry->tb_id != new4_entry->tb_id)
break;
if (fib4_entry->tos > new4_entry->tos)
continue;
if (fib4_entry->prio >= new4_entry->prio ||
fib4_entry->tos < new4_entry->tos)
return fib4_entry;
}
return NULL;
}
static int
mlxsw_sp_fib4_node_list_append(struct mlxsw_sp_fib4_entry *fib4_entry,
struct mlxsw_sp_fib4_entry *new4_entry)
{
struct mlxsw_sp_fib_node *fib_node;
if (WARN_ON(!fib4_entry))
return -EINVAL;
fib_node = fib4_entry->common.fib_node;
list_for_each_entry_from(fib4_entry, &fib_node->entry_list,
common.list) {
if (fib4_entry->tb_id != new4_entry->tb_id ||
fib4_entry->tos != new4_entry->tos ||
fib4_entry->prio != new4_entry->prio)
break;
}
list_add_tail(&new4_entry->common.list, &fib4_entry->common.list);
return 0;
}
static int
mlxsw_sp_fib4_node_list_insert(struct mlxsw_sp_fib4_entry *new4_entry,
bool replace, bool append)
{
struct mlxsw_sp_fib_node *fib_node = new4_entry->common.fib_node;
struct mlxsw_sp_fib4_entry *fib4_entry;
fib4_entry = mlxsw_sp_fib4_node_entry_find(fib_node, new4_entry);
if (append)
return mlxsw_sp_fib4_node_list_append(fib4_entry, new4_entry);
if (replace && WARN_ON(!fib4_entry))
return -EINVAL;
/* Insert new entry before replaced one, so that we can later
* remove the second.
*/
if (fib4_entry) {
list_add_tail(&new4_entry->common.list,
&fib4_entry->common.list);
} else {
struct mlxsw_sp_fib4_entry *last;
list_for_each_entry(last, &fib_node->entry_list, common.list) {
if (new4_entry->tb_id > last->tb_id)
break;
fib4_entry = last;
}
if (fib4_entry)
list_add(&new4_entry->common.list,
&fib4_entry->common.list);
else
list_add(&new4_entry->common.list,
&fib_node->entry_list);
}
return 0;
}
static void
mlxsw_sp_fib4_node_list_remove(struct mlxsw_sp_fib4_entry *fib4_entry)
{
list_del(&fib4_entry->common.list);
}
static int mlxsw_sp_fib_node_entry_add(struct mlxsw_sp *mlxsw_sp, static int mlxsw_sp_fib_node_entry_add(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_fib_entry *fib_entry) struct mlxsw_sp_fib_entry *fib_entry)
{ {
...@@ -4912,14 +4823,12 @@ static void mlxsw_sp_fib_node_entry_del(struct mlxsw_sp *mlxsw_sp, ...@@ -4912,14 +4823,12 @@ static void mlxsw_sp_fib_node_entry_del(struct mlxsw_sp *mlxsw_sp,
} }
static int mlxsw_sp_fib4_node_entry_link(struct mlxsw_sp *mlxsw_sp, static int mlxsw_sp_fib4_node_entry_link(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_fib4_entry *fib4_entry, struct mlxsw_sp_fib4_entry *fib4_entry)
bool replace, bool append)
{ {
struct mlxsw_sp_fib_node *fib_node = fib4_entry->common.fib_node;
int err; int err;
err = mlxsw_sp_fib4_node_list_insert(fib4_entry, replace, append); list_add(&fib4_entry->common.list, &fib_node->entry_list);
if (err)
return err;
err = mlxsw_sp_fib_node_entry_add(mlxsw_sp, &fib4_entry->common); err = mlxsw_sp_fib_node_entry_add(mlxsw_sp, &fib4_entry->common);
if (err) if (err)
...@@ -4928,7 +4837,7 @@ static int mlxsw_sp_fib4_node_entry_link(struct mlxsw_sp *mlxsw_sp, ...@@ -4928,7 +4837,7 @@ static int mlxsw_sp_fib4_node_entry_link(struct mlxsw_sp *mlxsw_sp,
return 0; return 0;
err_fib_node_entry_add: err_fib_node_entry_add:
mlxsw_sp_fib4_node_list_remove(fib4_entry); list_del(&fib4_entry->common.list);
return err; return err;
} }
...@@ -4937,20 +4846,19 @@ mlxsw_sp_fib4_node_entry_unlink(struct mlxsw_sp *mlxsw_sp, ...@@ -4937,20 +4846,19 @@ mlxsw_sp_fib4_node_entry_unlink(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_fib4_entry *fib4_entry) struct mlxsw_sp_fib4_entry *fib4_entry)
{ {
mlxsw_sp_fib_node_entry_del(mlxsw_sp, &fib4_entry->common); mlxsw_sp_fib_node_entry_del(mlxsw_sp, &fib4_entry->common);
mlxsw_sp_fib4_node_list_remove(fib4_entry); list_del(&fib4_entry->common.list);
if (fib4_entry->common.type == MLXSW_SP_FIB_ENTRY_TYPE_IPIP_DECAP) if (fib4_entry->common.type == MLXSW_SP_FIB_ENTRY_TYPE_IPIP_DECAP)
mlxsw_sp_fib_entry_decap_fini(mlxsw_sp, &fib4_entry->common); mlxsw_sp_fib_entry_decap_fini(mlxsw_sp, &fib4_entry->common);
} }
static void mlxsw_sp_fib4_entry_replace(struct mlxsw_sp *mlxsw_sp, static void mlxsw_sp_fib4_entry_replace(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_fib4_entry *fib4_entry, struct mlxsw_sp_fib4_entry *fib4_entry)
bool replace)
{ {
struct mlxsw_sp_fib_node *fib_node = fib4_entry->common.fib_node; struct mlxsw_sp_fib_node *fib_node = fib4_entry->common.fib_node;
struct mlxsw_sp_fib4_entry *replaced; struct mlxsw_sp_fib4_entry *replaced;
if (!replace) if (list_is_singular(&fib_node->entry_list))
return; return;
/* We inserted the new entry before replaced one */ /* We inserted the new entry before replaced one */
...@@ -4962,9 +4870,8 @@ static void mlxsw_sp_fib4_entry_replace(struct mlxsw_sp *mlxsw_sp, ...@@ -4962,9 +4870,8 @@ static void mlxsw_sp_fib4_entry_replace(struct mlxsw_sp *mlxsw_sp,
} }
static int static int
mlxsw_sp_router_fib4_add(struct mlxsw_sp *mlxsw_sp, mlxsw_sp_router_fib4_replace(struct mlxsw_sp *mlxsw_sp,
const struct fib_entry_notifier_info *fen_info, const struct fib_entry_notifier_info *fen_info)
bool replace, bool append)
{ {
struct mlxsw_sp_fib4_entry *fib4_entry; struct mlxsw_sp_fib4_entry *fib4_entry;
struct mlxsw_sp_fib_node *fib_node; struct mlxsw_sp_fib_node *fib_node;
...@@ -4989,14 +4896,13 @@ mlxsw_sp_router_fib4_add(struct mlxsw_sp *mlxsw_sp, ...@@ -4989,14 +4896,13 @@ mlxsw_sp_router_fib4_add(struct mlxsw_sp *mlxsw_sp,
goto err_fib4_entry_create; goto err_fib4_entry_create;
} }
err = mlxsw_sp_fib4_node_entry_link(mlxsw_sp, fib4_entry, replace, err = mlxsw_sp_fib4_node_entry_link(mlxsw_sp, fib4_entry);
append);
if (err) { if (err) {
dev_warn(mlxsw_sp->bus_info->dev, "Failed to link FIB entry to node\n"); dev_warn(mlxsw_sp->bus_info->dev, "Failed to link FIB entry to node\n");
goto err_fib4_node_entry_link; goto err_fib4_node_entry_link;
} }
mlxsw_sp_fib4_entry_replace(mlxsw_sp, fib4_entry, replace); mlxsw_sp_fib4_entry_replace(mlxsw_sp, fib4_entry);
return 0; return 0;
...@@ -6094,7 +6000,6 @@ static void mlxsw_sp_router_fib4_event_work(struct work_struct *work) ...@@ -6094,7 +6000,6 @@ static void mlxsw_sp_router_fib4_event_work(struct work_struct *work)
struct mlxsw_sp_fib_event_work *fib_work = struct mlxsw_sp_fib_event_work *fib_work =
container_of(work, struct mlxsw_sp_fib_event_work, work); container_of(work, struct mlxsw_sp_fib_event_work, work);
struct mlxsw_sp *mlxsw_sp = fib_work->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = fib_work->mlxsw_sp;
bool replace, append;
int err; int err;
/* Protect internal structures from changes */ /* Protect internal structures from changes */
...@@ -6102,18 +6007,14 @@ static void mlxsw_sp_router_fib4_event_work(struct work_struct *work) ...@@ -6102,18 +6007,14 @@ static void mlxsw_sp_router_fib4_event_work(struct work_struct *work)
mlxsw_sp_span_respin(mlxsw_sp); mlxsw_sp_span_respin(mlxsw_sp);
switch (fib_work->event) { switch (fib_work->event) {
case FIB_EVENT_ENTRY_REPLACE: /* fall through */ case FIB_EVENT_ENTRY_REPLACE_TMP:
case FIB_EVENT_ENTRY_APPEND: /* fall through */ err = mlxsw_sp_router_fib4_replace(mlxsw_sp,
case FIB_EVENT_ENTRY_ADD: &fib_work->fen_info);
replace = fib_work->event == FIB_EVENT_ENTRY_REPLACE;
append = fib_work->event == FIB_EVENT_ENTRY_APPEND;
err = mlxsw_sp_router_fib4_add(mlxsw_sp, &fib_work->fen_info,
replace, append);
if (err) if (err)
mlxsw_sp_router_fib_abort(mlxsw_sp); mlxsw_sp_router_fib_abort(mlxsw_sp);
fib_info_put(fib_work->fen_info.fi); fib_info_put(fib_work->fen_info.fi);
break; break;
case FIB_EVENT_ENTRY_DEL: case FIB_EVENT_ENTRY_DEL_TMP:
mlxsw_sp_router_fib4_del(mlxsw_sp, &fib_work->fen_info); mlxsw_sp_router_fib4_del(mlxsw_sp, &fib_work->fen_info);
fib_info_put(fib_work->fen_info.fi); fib_info_put(fib_work->fen_info.fi);
break; break;
...@@ -6210,10 +6111,8 @@ static void mlxsw_sp_router_fib4_event(struct mlxsw_sp_fib_event_work *fib_work, ...@@ -6210,10 +6111,8 @@ static void mlxsw_sp_router_fib4_event(struct mlxsw_sp_fib_event_work *fib_work,
struct fib_nh_notifier_info *fnh_info; struct fib_nh_notifier_info *fnh_info;
switch (fib_work->event) { switch (fib_work->event) {
case FIB_EVENT_ENTRY_REPLACE: /* fall through */ case FIB_EVENT_ENTRY_REPLACE_TMP: /* fall through */
case FIB_EVENT_ENTRY_APPEND: /* fall through */ case FIB_EVENT_ENTRY_DEL_TMP:
case FIB_EVENT_ENTRY_ADD: /* fall through */
case FIB_EVENT_ENTRY_DEL:
fen_info = container_of(info, struct fib_entry_notifier_info, fen_info = container_of(info, struct fib_entry_notifier_info,
info); info);
fib_work->fen_info = *fen_info; fib_work->fen_info = *fen_info;
...@@ -6343,9 +6242,9 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb, ...@@ -6343,9 +6242,9 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
err = mlxsw_sp_router_fib_rule_event(event, info, err = mlxsw_sp_router_fib_rule_event(event, info,
router->mlxsw_sp); router->mlxsw_sp);
return notifier_from_errno(err); return notifier_from_errno(err);
case FIB_EVENT_ENTRY_ADD: case FIB_EVENT_ENTRY_ADD: /* fall through */
case FIB_EVENT_ENTRY_REPLACE: /* fall through */ case FIB_EVENT_ENTRY_REPLACE: /* fall through */
case FIB_EVENT_ENTRY_APPEND: /* fall through */ case FIB_EVENT_ENTRY_REPLACE_TMP:
if (router->aborted) { if (router->aborted) {
NL_SET_ERR_MSG_MOD(info->extack, "FIB offload was aborted. Not configuring route"); NL_SET_ERR_MSG_MOD(info->extack, "FIB offload was aborted. Not configuring route");
return notifier_from_errno(-EINVAL); return notifier_from_errno(-EINVAL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment