Commit 16de3db1 authored by Yevhen Orlov's avatar Yevhen Orlov Committed by David S. Miller

net: marvell: prestera: add hardware router objects accounting for lpm

Add new router_hw object "fib_node". For now it support only DROP and
TRAP mode.
Co-developed-by: default avatarTaras Chornyi <tchornyi@marvell.com>
Signed-off-by: default avatarTaras Chornyi <tchornyi@marvell.com>
Co-developed-by: default avatarOleksandr Mazur <oleksandr.mazur@plvision.eu>
Signed-off-by: default avatarOleksandr Mazur <oleksandr.mazur@plvision.eu>
Signed-off-by: default avatarYevhen Orlov <yevhen.orlov@plvision.eu>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 19787b93
......@@ -281,6 +281,7 @@ struct prestera_router {
struct prestera_switch *sw;
struct list_head vr_list;
struct list_head rif_entry_list;
struct rhashtable fib_ht;
struct notifier_block inetaddr_nb;
struct notifier_block inetaddr_valid_nb;
};
......
......@@ -9,23 +9,41 @@
#include "prestera_acl.h"
/* +--+
* +------->|vr|
* | +--+
* |
* +-+-------+
* |rif_entry|
* +---------+
* Rif is
* +------->|vr|<-+
* | +--+ |
* | |
* +-+-------+ +--+---+-+
* |rif_entry| |fib_node|
* +---------+ +--------+
* Rif is Fib - is exit point
* used as
* entry point
* for vr in hw
*/
#define PRESTERA_NHGR_UNUSED (0)
#define PRESTERA_NHGR_DROP (0xFFFFFFFF)
static const struct rhashtable_params __prestera_fib_ht_params = {
.key_offset = offsetof(struct prestera_fib_node, key),
.head_offset = offsetof(struct prestera_fib_node, ht_node),
.key_len = sizeof(struct prestera_fib_key),
.automatic_shrinking = true,
};
int prestera_router_hw_init(struct prestera_switch *sw)
{
int err;
err = rhashtable_init(&sw->router->fib_ht,
&__prestera_fib_ht_params);
if (err)
goto err_fib_ht_init;
INIT_LIST_HEAD(&sw->router->vr_list);
INIT_LIST_HEAD(&sw->router->rif_entry_list);
err_fib_ht_init:
return 0;
}
......@@ -33,6 +51,7 @@ void prestera_router_hw_fini(struct prestera_switch *sw)
{
WARN_ON(!list_empty(&sw->router->vr_list));
WARN_ON(!list_empty(&sw->router->rif_entry_list));
rhashtable_destroy(&sw->router->fib_ht);
}
static struct prestera_vr *__prestera_vr_find(struct prestera_switch *sw,
......@@ -212,3 +231,102 @@ prestera_rif_entry_create(struct prestera_switch *sw,
err_kzalloc:
return NULL;
}
struct prestera_fib_node *
prestera_fib_node_find(struct prestera_switch *sw, struct prestera_fib_key *key)
{
struct prestera_fib_node *fib_node;
fib_node = rhashtable_lookup_fast(&sw->router->fib_ht, key,
__prestera_fib_ht_params);
return IS_ERR(fib_node) ? NULL : fib_node;
}
static void __prestera_fib_node_destruct(struct prestera_switch *sw,
struct prestera_fib_node *fib_node)
{
struct prestera_vr *vr;
vr = fib_node->info.vr;
prestera_hw_lpm_del(sw, vr->hw_vr_id, fib_node->key.addr.u.ipv4,
fib_node->key.prefix_len);
switch (fib_node->info.type) {
case PRESTERA_FIB_TYPE_TRAP:
break;
case PRESTERA_FIB_TYPE_DROP:
break;
default:
pr_err("Unknown fib_node->info.type = %d",
fib_node->info.type);
}
prestera_vr_put(sw, vr);
}
void prestera_fib_node_destroy(struct prestera_switch *sw,
struct prestera_fib_node *fib_node)
{
__prestera_fib_node_destruct(sw, fib_node);
rhashtable_remove_fast(&sw->router->fib_ht, &fib_node->ht_node,
__prestera_fib_ht_params);
kfree(fib_node);
}
struct prestera_fib_node *
prestera_fib_node_create(struct prestera_switch *sw,
struct prestera_fib_key *key,
enum prestera_fib_type fib_type)
{
struct prestera_fib_node *fib_node;
u32 grp_id;
struct prestera_vr *vr;
int err;
fib_node = kzalloc(sizeof(*fib_node), GFP_KERNEL);
if (!fib_node)
goto err_kzalloc;
memcpy(&fib_node->key, key, sizeof(*key));
fib_node->info.type = fib_type;
vr = prestera_vr_get(sw, key->tb_id, NULL);
if (IS_ERR(vr))
goto err_vr_get;
fib_node->info.vr = vr;
switch (fib_type) {
case PRESTERA_FIB_TYPE_TRAP:
grp_id = PRESTERA_NHGR_UNUSED;
break;
case PRESTERA_FIB_TYPE_DROP:
grp_id = PRESTERA_NHGR_DROP;
break;
default:
pr_err("Unsupported fib_type %d", fib_type);
goto err_nh_grp_get;
}
err = prestera_hw_lpm_add(sw, vr->hw_vr_id, key->addr.u.ipv4,
key->prefix_len, grp_id);
if (err)
goto err_lpm_add;
err = rhashtable_insert_fast(&sw->router->fib_ht, &fib_node->ht_node,
__prestera_fib_ht_params);
if (err)
goto err_ht_insert;
return fib_node;
err_ht_insert:
prestera_hw_lpm_del(sw, vr->hw_vr_id, key->addr.u.ipv4,
key->prefix_len);
err_lpm_add:
err_nh_grp_get:
prestera_vr_put(sw, vr);
err_vr_get:
kfree(fib_node);
err_kzalloc:
return NULL;
}
......@@ -22,6 +22,42 @@ struct prestera_rif_entry {
struct list_head router_node; /* ht */
};
struct prestera_ip_addr {
union {
__be32 ipv4;
struct in6_addr ipv6;
} u;
enum {
PRESTERA_IPV4 = 0,
PRESTERA_IPV6
} v;
};
struct prestera_fib_key {
struct prestera_ip_addr addr;
u32 prefix_len;
u32 tb_id;
};
struct prestera_fib_info {
struct prestera_vr *vr;
struct list_head vr_node;
enum prestera_fib_type {
PRESTERA_FIB_TYPE_INVALID = 0,
/* It can be connected route
* and will be overlapped with neighbours
*/
PRESTERA_FIB_TYPE_TRAP,
PRESTERA_FIB_TYPE_DROP
} type;
};
struct prestera_fib_node {
struct rhash_head ht_node; /* node of prestera_vr */
struct prestera_fib_key key;
struct prestera_fib_info info; /* action related info */
};
struct prestera_rif_entry *
prestera_rif_entry_find(const struct prestera_switch *sw,
const struct prestera_rif_entry_key *k);
......@@ -31,6 +67,14 @@ struct prestera_rif_entry *
prestera_rif_entry_create(struct prestera_switch *sw,
struct prestera_rif_entry_key *k,
u32 tb_id, const unsigned char *addr);
struct prestera_fib_node *prestera_fib_node_find(struct prestera_switch *sw,
struct prestera_fib_key *key);
void prestera_fib_node_destroy(struct prestera_switch *sw,
struct prestera_fib_node *fib_node);
struct prestera_fib_node *
prestera_fib_node_create(struct prestera_switch *sw,
struct prestera_fib_key *key,
enum prestera_fib_type fib_type);
int prestera_router_hw_init(struct prestera_switch *sw);
void prestera_router_hw_fini(struct prestera_switch *sw);
......
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