2022-08-25 20:43:05

by Yevhen Orlov

[permalink] [raw]
Subject: [PATCH net-next v4 0/9] net: marvell: prestera: add nexthop routes offloading

Add support for nexthop routes for Marvell Prestera driver.
Subscribe on NEIGH_UPDATE events.

Add features:
- Support connected route adding
e.g.: "ip address add 1.1.1.1/24 dev sw1p1"
e.g.: "ip route add 6.6.6/24 dev sw1p1"
- Support nexthop route adding
e.g.: "ip route add 5.5.5/24 via 1.1.1.2"
- Support ECMP route adding
e.g.: "ip route add 5.5.5/24 nexthop via 1.1.1.2 nexthop via 1.1.1.3"
- Support "offload" and "trap" flags per each nexthop
- Support "offload" flag for neighbours

Limitations:
- Only "local" and "main" tables supported
- Only generic interfaces supported for router (no bridges or vlans)

Flags meaning:
ip route add 5.5.5/24 nexthop via 2.2.2.2 nexthop via 2.2.2.3
ip route show
...
5.5.5.0/24 rt_offload
nexthop via 2.2.2.2 dev sw1p31 weight 1 trap
nexthop via 2.2.2.3 dev sw1p31 weight 1 trap
...
# When you just add route - lpm entry became occupied
# in HW ("rt_offload" flag), but related to nexthops neighbours
# still not resolved ("trap" flag).
#
# After some time...
ip route show
...
5.5.5.0/24 rt_offload
nexthop via 2.2.2.2 dev sw1p31 weight 1 offload
nexthop via 2.2.2.3 dev sw1p31 weight 1 offload
...
# You will see, that appropriate neighbours was resolved and nexthop
# entries occupied in HW too ("offload" flag)

Co-developed-by: Taras Chornyi <[email protected]>
Signed-off-by: Taras Chornyi <[email protected]>
Co-developed-by: Oleksandr Mazur <[email protected]>
Signed-off-by: Oleksandr Mazur <[email protected]>
Signed-off-by: Yevhen Orlov <[email protected]>

Changes for v2:
* Add more reviewers in CC
* Check if route nexthop or direct with fib_nh_gw_family instead of fib_nh_scope
This is needed after,
747c14307214 ("ip: fix dflt addr selection for connected nexthop"),
because direct route is now with the same scope as nexthop (RT_SCOPE_LINK)

Changes for v3:
* Resolve "unused functions" warnings, after
patch ("net: marvell: prestera: Add heplers to interact ... "), and before
patch ("net: marvell: prestera: Add neighbour cache accounting")

Changes for v4:
* Rebase to the latest master to resolve patch applying issues

Yevhen Orlov (9):
net: marvell: prestera: Add router nexthops ABI
net: marvell: prestera: Add cleanup of allocated fib_nodes
net: marvell: prestera: Add strict cleanup of fib arbiter
net: marvell: prestera: add delayed wq and flush wq on deinit
net: marvell: prestera: Add length macros for prestera_ip_addr
net: marvell: prestera: Add heplers to interact with fib_notifier_info
net: marvell: prestera: add stub handler neighbour events
net: marvell: prestera: Add neighbour cache accounting
net: marvell: prestera: Propogate nh state from hw to kernel

.../net/ethernet/marvell/prestera/prestera.h | 12 +
.../ethernet/marvell/prestera/prestera_hw.c | 130 ++
.../ethernet/marvell/prestera/prestera_hw.h | 11 +
.../ethernet/marvell/prestera/prestera_main.c | 11 +
.../marvell/prestera/prestera_router.c | 1140 ++++++++++++++++-
.../marvell/prestera/prestera_router_hw.c | 379 +++++-
.../marvell/prestera/prestera_router_hw.h | 76 +-
7 files changed, 1717 insertions(+), 42 deletions(-)

--
2.17.1


2022-08-25 21:05:18

by Yevhen Orlov

[permalink] [raw]
Subject: [PATCH net-next v4 6/9] net: marvell: prestera: Add heplers to interact with fib_notifier_info

This will be used to implement nexthops related logic in next patches.
Also try to keep ipv4/6 abstraction to be able to reuse helpers for ipv6
in the future.

Co-developed-by: Taras Chornyi <[email protected]>
Signed-off-by: Taras Chornyi <[email protected]>
Co-developed-by: Oleksandr Mazur <[email protected]>
Signed-off-by: Oleksandr Mazur <[email protected]>
Signed-off-by: Yevhen Orlov <[email protected]>
---
.../marvell/prestera/prestera_router.c | 101 ++++++++++++------
1 file changed, 67 insertions(+), 34 deletions(-)

diff --git a/drivers/net/ethernet/marvell/prestera/prestera_router.c b/drivers/net/ethernet/marvell/prestera/prestera_router.c
index fc118792487b..15958f83107e 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_router.c
+++ b/drivers/net/ethernet/marvell/prestera/prestera_router.c
@@ -7,6 +7,7 @@
#include <net/inet_dscp.h>
#include <net/switchdev.h>
#include <linux/rhashtable.h>
+#include <net/nexthop.h>

#include "prestera.h"
#include "prestera_router_hw.h"
@@ -26,9 +27,10 @@ struct prestera_kern_fib_cache {
} lpm_info; /* hold prepared lpm info */
/* Indicate if route is not overlapped by another table */
struct rhash_head ht_node; /* node of prestera_router */
- struct fib_info *fi;
- dscp_t kern_dscp;
- u8 kern_type;
+ union {
+ struct fib_notifier_info info; /* point to any of 4/6 */
+ struct fib_entry_notifier_info fen4_info;
+ };
bool reachable;
};

@@ -51,15 +53,41 @@ static u32 prestera_fix_tb_id(u32 tb_id)
}

static void
-prestera_util_fen_info2fib_cache_key(struct fib_entry_notifier_info *fen_info,
+prestera_util_fen_info2fib_cache_key(struct fib_notifier_info *info,
struct prestera_kern_fib_cache_key *key)
{
+ struct fib_entry_notifier_info *fen_info =
+ container_of(info, struct fib_entry_notifier_info, info);
+
memset(key, 0, sizeof(*key));
+ key->addr.v = PRESTERA_IPV4;
key->addr.u.ipv4 = cpu_to_be32(fen_info->dst);
key->prefix_len = fen_info->dst_len;
key->kern_tb_id = fen_info->tb_id;
}

+static unsigned char
+prestera_kern_fib_info_type(struct fib_notifier_info *info)
+{
+ struct fib6_entry_notifier_info *fen6_info;
+ struct fib_entry_notifier_info *fen4_info;
+
+ if (info->family == AF_INET) {
+ fen4_info = container_of(info, struct fib_entry_notifier_info,
+ info);
+ return fen4_info->fi->fib_type;
+ } else if (info->family == AF_INET6) {
+ fen6_info = container_of(info, struct fib6_entry_notifier_info,
+ info);
+ /* TODO: ECMP in ipv6 is several routes.
+ * Every route has single nh.
+ */
+ return fen6_info->rt->fib6_type;
+ }
+
+ return RTN_UNSPEC;
+}
+
static struct prestera_kern_fib_cache *
prestera_kern_fib_cache_find(struct prestera_switch *sw,
struct prestera_kern_fib_cache_key *key)
@@ -76,7 +104,7 @@ static void
prestera_kern_fib_cache_destroy(struct prestera_switch *sw,
struct prestera_kern_fib_cache *fib_cache)
{
- fib_info_put(fib_cache->fi);
+ fib_info_put(fib_cache->fen4_info.fi);
rhashtable_remove_fast(&sw->router->kern_fib_cache_ht,
&fib_cache->ht_node,
__prestera_kern_fib_cache_ht_params);
@@ -89,8 +117,10 @@ prestera_kern_fib_cache_destroy(struct prestera_switch *sw,
static struct prestera_kern_fib_cache *
prestera_kern_fib_cache_create(struct prestera_switch *sw,
struct prestera_kern_fib_cache_key *key,
- struct fib_info *fi, dscp_t dscp, u8 type)
+ struct fib_notifier_info *info)
{
+ struct fib_entry_notifier_info *fen_info =
+ container_of(info, struct fib_entry_notifier_info, info);
struct prestera_kern_fib_cache *fib_cache;
int err;

@@ -99,10 +129,8 @@ prestera_kern_fib_cache_create(struct prestera_switch *sw,
goto err_kzalloc;

memcpy(&fib_cache->key, key, sizeof(*key));
- fib_info_hold(fi);
- fib_cache->fi = fi;
- fib_cache->kern_dscp = dscp;
- fib_cache->kern_type = type;
+ fib_info_hold(fen_info->fi);
+ memcpy(&fib_cache->fen4_info, fen_info, sizeof(*fen_info));

err = rhashtable_insert_fast(&sw->router->kern_fib_cache_ht,
&fib_cache->ht_node,
@@ -113,7 +141,7 @@ prestera_kern_fib_cache_create(struct prestera_switch *sw,
return fib_cache;

err_ht_insert:
- fib_info_put(fi);
+ fib_info_put(fen_info->fi);
kfree(fib_cache);
err_kzalloc:
return NULL;
@@ -126,21 +154,25 @@ __prestera_k_arb_fib_lpm_offload_set(struct prestera_switch *sw,
{
struct fib_rt_info fri;

- if (fc->key.addr.v != PRESTERA_IPV4)
+ switch (fc->key.addr.v) {
+ case PRESTERA_IPV4:
+ fri.fi = fc->fen4_info.fi;
+ fri.tb_id = fc->key.kern_tb_id;
+ fri.dst = fc->key.addr.u.ipv4;
+ fri.dst_len = fc->key.prefix_len;
+ fri.dscp = fc->fen4_info.dscp;
+ fri.type = fc->fen4_info.type;
+ /* flags begin */
+ fri.offload = offload;
+ fri.trap = trap;
+ fri.offload_failed = fail;
+ /* flags end */
+ fib_alias_hw_flags_set(&init_net, &fri);
return;
-
- fri.fi = fc->fi;
- fri.tb_id = fc->key.kern_tb_id;
- fri.dst = fc->key.addr.u.ipv4;
- fri.dst_len = fc->key.prefix_len;
- fri.dscp = fc->kern_dscp;
- fri.type = fc->kern_type;
- /* flags begin */
- fri.offload = offload;
- fri.trap = trap;
- fri.offload_failed = fail;
- /* flags end */
- fib_alias_hw_flags_set(&init_net, &fri);
+ case PRESTERA_IPV6:
+ /* TODO */
+ return;
+ }
}

static int
@@ -149,7 +181,7 @@ __prestera_pr_k_arb_fc_lpm_info_calc(struct prestera_switch *sw,
{
memset(&fc->lpm_info, 0, sizeof(fc->lpm_info));

- switch (fc->fi->fib_type) {
+ switch (prestera_kern_fib_info_type(&fc->info)) {
case RTN_UNICAST:
fc->lpm_info.fib_type = PRESTERA_FIB_TYPE_TRAP;
break;
@@ -220,6 +252,8 @@ static int __prestera_k_arb_fc_apply(struct prestera_switch *sw,
}

switch (fc->lpm_info.fib_type) {
+ case PRESTERA_FIB_TYPE_UC_NH:
+ break;
case PRESTERA_FIB_TYPE_TRAP:
__prestera_k_arb_fib_lpm_offload_set(sw, fc, false,
false, fc->reachable);
@@ -274,14 +308,14 @@ __prestera_k_arb_util_fib_overlapped(struct prestera_switch *sw,
static int
prestera_k_arb_fib_evt(struct prestera_switch *sw,
bool replace, /* replace or del */
- struct fib_entry_notifier_info *fen_info)
+ struct fib_notifier_info *info)
{
struct prestera_kern_fib_cache *tfib_cache, *bfib_cache; /* top/btm */
struct prestera_kern_fib_cache_key fc_key;
struct prestera_kern_fib_cache *fib_cache;
int err;

- prestera_util_fen_info2fib_cache_key(fen_info, &fc_key);
+ prestera_util_fen_info2fib_cache_key(info, &fc_key);
fib_cache = prestera_kern_fib_cache_find(sw, &fc_key);
if (fib_cache) {
fib_cache->reachable = false;
@@ -304,10 +338,7 @@ prestera_k_arb_fib_evt(struct prestera_switch *sw,
}

if (replace) {
- fib_cache = prestera_kern_fib_cache_create(sw, &fc_key,
- fen_info->fi,
- fen_info->dscp,
- fen_info->type);
+ fib_cache = prestera_kern_fib_cache_create(sw, &fc_key, info);
if (!fib_cache) {
dev_err(sw->dev->dev, "fib_cache == NULL");
return -ENOENT;
@@ -512,13 +543,15 @@ static void __prestera_router_fib_event_work(struct work_struct *work)

switch (fib_work->event) {
case FIB_EVENT_ENTRY_REPLACE:
- err = prestera_k_arb_fib_evt(sw, true, &fib_work->fen_info);
+ err = prestera_k_arb_fib_evt(sw, true,
+ &fib_work->fen_info.info);
if (err)
goto err_out;

break;
case FIB_EVENT_ENTRY_DEL:
- err = prestera_k_arb_fib_evt(sw, false, &fib_work->fen_info);
+ err = prestera_k_arb_fib_evt(sw, false,
+ &fib_work->fen_info.info);
if (err)
goto err_out;

--
2.17.1