Commit 2aed49da authored by David S. Miller's avatar David S. Miller

Merge branch 'prestera-route-offloading'

Yevhen Orlov says:

====================
net: marvell: prestera: add basic routes offloading

Add support for blackhole and local routes for Marvell Prestera driver.
Subscribe on fib notifications and handle add/del.

Add features:
 - Support route adding.
   e.g.: "ip route add blackhole 7.7.1.1/24"
   e.g.: "ip route add local 9.9.9.9 dev sw1p30"
 - Support "rt_trap", "rt_offload", "rt_offload_failed" flags
 - Handle case, when route in "local" table overlaps route in "main" table
   example:
        ip ro add blackhole 7.7.7.7
        ip ro add local 7.7.7.7 dev sw1p30
        # blackhole route will be deoffloaded. rt_offload flag disappeared

Limitations:
 - Only "blackhole" and "local" routes supported. "nexthop" routes is TRAP
   for now and will be implemented soon.
 - Only "local" and "main" tables supported
====================
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>
parents 93d11e0d 4394fbcb
......@@ -281,8 +281,11 @@ struct prestera_router {
struct prestera_switch *sw;
struct list_head vr_list;
struct list_head rif_entry_list;
struct rhashtable fib_ht;
struct rhashtable kern_fib_cache_ht;
struct notifier_block inetaddr_nb;
struct notifier_block inetaddr_valid_nb;
struct notifier_block fib_nb;
};
struct prestera_rxtx_params {
......@@ -325,6 +328,8 @@ int prestera_port_cfg_mac_write(struct prestera_port *port,
struct prestera_port *prestera_port_dev_lower_find(struct net_device *dev);
void prestera_queue_work(struct work_struct *work);
int prestera_port_pvid_set(struct prestera_port *port, u16 vid);
bool prestera_netdev_check(const struct net_device *dev);
......
......@@ -55,6 +55,8 @@ enum prestera_cmd_type_t {
PRESTERA_CMD_TYPE_ROUTER_RIF_CREATE = 0x600,
PRESTERA_CMD_TYPE_ROUTER_RIF_DELETE = 0x601,
PRESTERA_CMD_TYPE_ROUTER_LPM_ADD = 0x610,
PRESTERA_CMD_TYPE_ROUTER_LPM_DELETE = 0x611,
PRESTERA_CMD_TYPE_ROUTER_VR_CREATE = 0x630,
PRESTERA_CMD_TYPE_ROUTER_VR_DELETE = 0x631,
......@@ -502,6 +504,15 @@ struct prestera_msg_iface {
u8 __pad[3];
};
struct prestera_msg_ip_addr {
union {
__be32 ipv4;
__be32 ipv6[4];
} u;
u8 v; /* e.g. PRESTERA_IPV4 */
u8 __pad[3];
};
struct prestera_msg_rif_req {
struct prestera_msg_cmd cmd;
struct prestera_msg_iface iif;
......@@ -518,6 +529,15 @@ struct prestera_msg_rif_resp {
u8 __pad[2];
};
struct prestera_msg_lpm_req {
struct prestera_msg_cmd cmd;
struct prestera_msg_ip_addr dst;
__le32 grp_id;
__le32 dst_len;
__le16 vr_id;
u8 __pad[2];
};
struct prestera_msg_vr_req {
struct prestera_msg_cmd cmd;
__le16 vr_id;
......@@ -601,9 +621,11 @@ static void prestera_hw_build_tests(void)
BUILD_BUG_ON(sizeof(struct prestera_msg_counter_stats) != 16);
BUILD_BUG_ON(sizeof(struct prestera_msg_rif_req) != 36);
BUILD_BUG_ON(sizeof(struct prestera_msg_vr_req) != 8);
BUILD_BUG_ON(sizeof(struct prestera_msg_lpm_req) != 36);
/* structure that are part of req/resp fw messages */
BUILD_BUG_ON(sizeof(struct prestera_msg_iface) != 16);
BUILD_BUG_ON(sizeof(struct prestera_msg_ip_addr) != 20);
/* check responses */
BUILD_BUG_ON(sizeof(struct prestera_msg_common_resp) != 8);
......@@ -1897,6 +1919,33 @@ int prestera_hw_vr_delete(struct prestera_switch *sw, u16 vr_id)
sizeof(req));
}
int prestera_hw_lpm_add(struct prestera_switch *sw, u16 vr_id,
__be32 dst, u32 dst_len, u32 grp_id)
{
struct prestera_msg_lpm_req req = {
.dst_len = __cpu_to_le32(dst_len),
.vr_id = __cpu_to_le16(vr_id),
.grp_id = __cpu_to_le32(grp_id),
.dst.u.ipv4 = dst
};
return prestera_cmd(sw, PRESTERA_CMD_TYPE_ROUTER_LPM_ADD, &req.cmd,
sizeof(req));
}
int prestera_hw_lpm_del(struct prestera_switch *sw, u16 vr_id,
__be32 dst, u32 dst_len)
{
struct prestera_msg_lpm_req req = {
.dst_len = __cpu_to_le32(dst_len),
.vr_id = __cpu_to_le16(vr_id),
.dst.u.ipv4 = dst
};
return prestera_cmd(sw, PRESTERA_CMD_TYPE_ROUTER_LPM_DELETE, &req.cmd,
sizeof(req));
}
int prestera_hw_rxtx_init(struct prestera_switch *sw,
struct prestera_rxtx_params *params)
{
......
......@@ -249,6 +249,12 @@ int prestera_hw_rif_delete(struct prestera_switch *sw, u16 rif_id,
int prestera_hw_vr_create(struct prestera_switch *sw, u16 *vr_id);
int prestera_hw_vr_delete(struct prestera_switch *sw, u16 vr_id);
/* LPM PI */
int prestera_hw_lpm_add(struct prestera_switch *sw, u16 vr_id,
__be32 dst, u32 dst_len, u32 grp_id);
int prestera_hw_lpm_del(struct prestera_switch *sw, u16 vr_id,
__be32 dst, u32 dst_len);
/* Event handlers */
int prestera_hw_event_handler_register(struct prestera_switch *sw,
enum prestera_event_type type,
......
......@@ -28,6 +28,12 @@
#define PRESTERA_MAC_ADDR_NUM_MAX 255
static struct workqueue_struct *prestera_wq;
static struct workqueue_struct *prestera_owq;
void prestera_queue_work(struct work_struct *work)
{
queue_work(prestera_owq, work);
}
int prestera_port_pvid_set(struct prestera_port *port, u16 vid)
{
......@@ -1024,12 +1030,17 @@ static int __init prestera_module_init(void)
if (!prestera_wq)
return -ENOMEM;
prestera_owq = alloc_ordered_workqueue("prestera_ordered", 0);
if (!prestera_owq)
return -ENOMEM;
return 0;
}
static void __exit prestera_module_exit(void)
{
destroy_workqueue(prestera_wq);
destroy_workqueue(prestera_owq);
}
module_init(prestera_module_init);
......
......@@ -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