Skip to content

Commit b6a1d87

Browse files
idoschdavem330
authored andcommitted
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: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 20d1565 commit b6a1d87

File tree

1 file changed

+20
-121
lines changed

1 file changed

+20
-121
lines changed

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

Lines changed: 20 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,7 +3845,7 @@ static void mlxsw_sp_nexthop4_event(struct mlxsw_sp *mlxsw_sp,
38453845

38463846
key.fib_nh = fib_nh;
38473847
nh = mlxsw_sp_nexthop_lookup(mlxsw_sp, key);
3848-
if (WARN_ON_ONCE(!nh))
3848+
if (!nh)
38493849
return;
38503850

38513851
switch (event) {
@@ -4780,95 +4780,6 @@ static void mlxsw_sp_fib_node_put(struct mlxsw_sp *mlxsw_sp,
47804780
mlxsw_sp_vr_put(mlxsw_sp, vr);
47814781
}
47824782

4783-
static struct mlxsw_sp_fib4_entry *
4784-
mlxsw_sp_fib4_node_entry_find(const struct mlxsw_sp_fib_node *fib_node,
4785-
const struct mlxsw_sp_fib4_entry *new4_entry)
4786-
{
4787-
struct mlxsw_sp_fib4_entry *fib4_entry;
4788-
4789-
list_for_each_entry(fib4_entry, &fib_node->entry_list, common.list) {
4790-
if (fib4_entry->tb_id > new4_entry->tb_id)
4791-
continue;
4792-
if (fib4_entry->tb_id != new4_entry->tb_id)
4793-
break;
4794-
if (fib4_entry->tos > new4_entry->tos)
4795-
continue;
4796-
if (fib4_entry->prio >= new4_entry->prio ||
4797-
fib4_entry->tos < new4_entry->tos)
4798-
return fib4_entry;
4799-
}
4800-
4801-
return NULL;
4802-
}
4803-
4804-
static int
4805-
mlxsw_sp_fib4_node_list_append(struct mlxsw_sp_fib4_entry *fib4_entry,
4806-
struct mlxsw_sp_fib4_entry *new4_entry)
4807-
{
4808-
struct mlxsw_sp_fib_node *fib_node;
4809-
4810-
if (WARN_ON(!fib4_entry))
4811-
return -EINVAL;
4812-
4813-
fib_node = fib4_entry->common.fib_node;
4814-
list_for_each_entry_from(fib4_entry, &fib_node->entry_list,
4815-
common.list) {
4816-
if (fib4_entry->tb_id != new4_entry->tb_id ||
4817-
fib4_entry->tos != new4_entry->tos ||
4818-
fib4_entry->prio != new4_entry->prio)
4819-
break;
4820-
}
4821-
4822-
list_add_tail(&new4_entry->common.list, &fib4_entry->common.list);
4823-
return 0;
4824-
}
4825-
4826-
static int
4827-
mlxsw_sp_fib4_node_list_insert(struct mlxsw_sp_fib4_entry *new4_entry,
4828-
bool replace, bool append)
4829-
{
4830-
struct mlxsw_sp_fib_node *fib_node = new4_entry->common.fib_node;
4831-
struct mlxsw_sp_fib4_entry *fib4_entry;
4832-
4833-
fib4_entry = mlxsw_sp_fib4_node_entry_find(fib_node, new4_entry);
4834-
4835-
if (append)
4836-
return mlxsw_sp_fib4_node_list_append(fib4_entry, new4_entry);
4837-
if (replace && WARN_ON(!fib4_entry))
4838-
return -EINVAL;
4839-
4840-
/* Insert new entry before replaced one, so that we can later
4841-
* remove the second.
4842-
*/
4843-
if (fib4_entry) {
4844-
list_add_tail(&new4_entry->common.list,
4845-
&fib4_entry->common.list);
4846-
} else {
4847-
struct mlxsw_sp_fib4_entry *last;
4848-
4849-
list_for_each_entry(last, &fib_node->entry_list, common.list) {
4850-
if (new4_entry->tb_id > last->tb_id)
4851-
break;
4852-
fib4_entry = last;
4853-
}
4854-
4855-
if (fib4_entry)
4856-
list_add(&new4_entry->common.list,
4857-
&fib4_entry->common.list);
4858-
else
4859-
list_add(&new4_entry->common.list,
4860-
&fib_node->entry_list);
4861-
}
4862-
4863-
return 0;
4864-
}
4865-
4866-
static void
4867-
mlxsw_sp_fib4_node_list_remove(struct mlxsw_sp_fib4_entry *fib4_entry)
4868-
{
4869-
list_del(&fib4_entry->common.list);
4870-
}
4871-
48724783
static int mlxsw_sp_fib_node_entry_add(struct mlxsw_sp *mlxsw_sp,
48734784
struct mlxsw_sp_fib_entry *fib_entry)
48744785
{
@@ -4912,14 +4823,12 @@ static void mlxsw_sp_fib_node_entry_del(struct mlxsw_sp *mlxsw_sp,
49124823
}
49134824

49144825
static int mlxsw_sp_fib4_node_entry_link(struct mlxsw_sp *mlxsw_sp,
4915-
struct mlxsw_sp_fib4_entry *fib4_entry,
4916-
bool replace, bool append)
4826+
struct mlxsw_sp_fib4_entry *fib4_entry)
49174827
{
4828+
struct mlxsw_sp_fib_node *fib_node = fib4_entry->common.fib_node;
49184829
int err;
49194830

4920-
err = mlxsw_sp_fib4_node_list_insert(fib4_entry, replace, append);
4921-
if (err)
4922-
return err;
4831+
list_add(&fib4_entry->common.list, &fib_node->entry_list);
49234832

49244833
err = mlxsw_sp_fib_node_entry_add(mlxsw_sp, &fib4_entry->common);
49254834
if (err)
@@ -4928,7 +4837,7 @@ static int mlxsw_sp_fib4_node_entry_link(struct mlxsw_sp *mlxsw_sp,
49284837
return 0;
49294838

49304839
err_fib_node_entry_add:
4931-
mlxsw_sp_fib4_node_list_remove(fib4_entry);
4840+
list_del(&fib4_entry->common.list);
49324841
return err;
49334842
}
49344843

@@ -4937,20 +4846,19 @@ mlxsw_sp_fib4_node_entry_unlink(struct mlxsw_sp *mlxsw_sp,
49374846
struct mlxsw_sp_fib4_entry *fib4_entry)
49384847
{
49394848
mlxsw_sp_fib_node_entry_del(mlxsw_sp, &fib4_entry->common);
4940-
mlxsw_sp_fib4_node_list_remove(fib4_entry);
4849+
list_del(&fib4_entry->common.list);
49414850

49424851
if (fib4_entry->common.type == MLXSW_SP_FIB_ENTRY_TYPE_IPIP_DECAP)
49434852
mlxsw_sp_fib_entry_decap_fini(mlxsw_sp, &fib4_entry->common);
49444853
}
49454854

49464855
static void mlxsw_sp_fib4_entry_replace(struct mlxsw_sp *mlxsw_sp,
4947-
struct mlxsw_sp_fib4_entry *fib4_entry,
4948-
bool replace)
4856+
struct mlxsw_sp_fib4_entry *fib4_entry)
49494857
{
49504858
struct mlxsw_sp_fib_node *fib_node = fib4_entry->common.fib_node;
49514859
struct mlxsw_sp_fib4_entry *replaced;
49524860

4953-
if (!replace)
4861+
if (list_is_singular(&fib_node->entry_list))
49544862
return;
49554863

49564864
/* We inserted the new entry before replaced one */
@@ -4962,9 +4870,8 @@ static void mlxsw_sp_fib4_entry_replace(struct mlxsw_sp *mlxsw_sp,
49624870
}
49634871

49644872
static int
4965-
mlxsw_sp_router_fib4_add(struct mlxsw_sp *mlxsw_sp,
4966-
const struct fib_entry_notifier_info *fen_info,
4967-
bool replace, bool append)
4873+
mlxsw_sp_router_fib4_replace(struct mlxsw_sp *mlxsw_sp,
4874+
const struct fib_entry_notifier_info *fen_info)
49684875
{
49694876
struct mlxsw_sp_fib4_entry *fib4_entry;
49704877
struct mlxsw_sp_fib_node *fib_node;
@@ -4989,14 +4896,13 @@ mlxsw_sp_router_fib4_add(struct mlxsw_sp *mlxsw_sp,
49894896
goto err_fib4_entry_create;
49904897
}
49914898

4992-
err = mlxsw_sp_fib4_node_entry_link(mlxsw_sp, fib4_entry, replace,
4993-
append);
4899+
err = mlxsw_sp_fib4_node_entry_link(mlxsw_sp, fib4_entry);
49944900
if (err) {
49954901
dev_warn(mlxsw_sp->bus_info->dev, "Failed to link FIB entry to node\n");
49964902
goto err_fib4_node_entry_link;
49974903
}
49984904

4999-
mlxsw_sp_fib4_entry_replace(mlxsw_sp, fib4_entry, replace);
4905+
mlxsw_sp_fib4_entry_replace(mlxsw_sp, fib4_entry);
50004906

50014907
return 0;
50024908

@@ -6094,26 +6000,21 @@ static void mlxsw_sp_router_fib4_event_work(struct work_struct *work)
60946000
struct mlxsw_sp_fib_event_work *fib_work =
60956001
container_of(work, struct mlxsw_sp_fib_event_work, work);
60966002
struct mlxsw_sp *mlxsw_sp = fib_work->mlxsw_sp;
6097-
bool replace, append;
60986003
int err;
60996004

61006005
/* Protect internal structures from changes */
61016006
rtnl_lock();
61026007
mlxsw_sp_span_respin(mlxsw_sp);
61036008

61046009
switch (fib_work->event) {
6105-
case FIB_EVENT_ENTRY_REPLACE: /* fall through */
6106-
case FIB_EVENT_ENTRY_APPEND: /* fall through */
6107-
case FIB_EVENT_ENTRY_ADD:
6108-
replace = fib_work->event == FIB_EVENT_ENTRY_REPLACE;
6109-
append = fib_work->event == FIB_EVENT_ENTRY_APPEND;
6110-
err = mlxsw_sp_router_fib4_add(mlxsw_sp, &fib_work->fen_info,
6111-
replace, append);
6010+
case FIB_EVENT_ENTRY_REPLACE_TMP:
6011+
err = mlxsw_sp_router_fib4_replace(mlxsw_sp,
6012+
&fib_work->fen_info);
61126013
if (err)
61136014
mlxsw_sp_router_fib_abort(mlxsw_sp);
61146015
fib_info_put(fib_work->fen_info.fi);
61156016
break;
6116-
case FIB_EVENT_ENTRY_DEL:
6017+
case FIB_EVENT_ENTRY_DEL_TMP:
61176018
mlxsw_sp_router_fib4_del(mlxsw_sp, &fib_work->fen_info);
61186019
fib_info_put(fib_work->fen_info.fi);
61196020
break;
@@ -6210,10 +6111,8 @@ static void mlxsw_sp_router_fib4_event(struct mlxsw_sp_fib_event_work *fib_work,
62106111
struct fib_nh_notifier_info *fnh_info;
62116112

62126113
switch (fib_work->event) {
6213-
case FIB_EVENT_ENTRY_REPLACE: /* fall through */
6214-
case FIB_EVENT_ENTRY_APPEND: /* fall through */
6215-
case FIB_EVENT_ENTRY_ADD: /* fall through */
6216-
case FIB_EVENT_ENTRY_DEL:
6114+
case FIB_EVENT_ENTRY_REPLACE_TMP: /* fall through */
6115+
case FIB_EVENT_ENTRY_DEL_TMP:
62176116
fen_info = container_of(info, struct fib_entry_notifier_info,
62186117
info);
62196118
fib_work->fen_info = *fen_info;
@@ -6343,9 +6242,9 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
63436242
err = mlxsw_sp_router_fib_rule_event(event, info,
63446243
router->mlxsw_sp);
63456244
return notifier_from_errno(err);
6346-
case FIB_EVENT_ENTRY_ADD:
6245+
case FIB_EVENT_ENTRY_ADD: /* fall through */
63476246
case FIB_EVENT_ENTRY_REPLACE: /* fall through */
6348-
case FIB_EVENT_ENTRY_APPEND: /* fall through */
6247+
case FIB_EVENT_ENTRY_REPLACE_TMP:
63496248
if (router->aborted) {
63506249
NL_SET_ERR_MSG_MOD(info->extack, "FIB offload was aborted. Not configuring route");
63516250
return notifier_from_errno(-EINVAL);

0 commit comments

Comments
 (0)