From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, idosch@mellanox.com, yotamg@mellanox.com,
eladr@mellanox.com, nogahf@mellanox.com, ogerlitz@mellanox.com,
sfeldma@gmail.com, roopa@cumulusnetworks.com, andy@greyhouse.net,
dsa@cumulusnetworks.com, tgraf@suug.ch, jhs@mojatatu.com,
linville@tuxdriver.com, ivecera@redhat.com
Subject: [patch net-next 21/42] mlxsw: spectrum_router: Add virtual router management
Date: Fri, 1 Jul 2016 16:04:49 +0200 [thread overview]
Message-ID: <1467381910-3445-22-git-send-email-jiri@resnulli.us> (raw)
In-Reply-To: <1467381910-3445-1-git-send-email-jiri@resnulli.us>
From: Jiri Pirko <jiri@mellanox.com>
Virtual router is a construct used inside HW. In this implementation
we map kernel tables to virtual routers one to one. Introduce management
logic to create virtual routers when needed and destroy in case they are
no longer in use. According to that, call into LPM tree management.
Each virtual router is always bound to one LPM tree.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
---
drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 14 ++
.../net/ethernet/mellanox/mlxsw/spectrum_router.c | 228 +++++++++++++++++++++
2 files changed, 242 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index 5db57a7..5b40dfc 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -65,6 +65,8 @@
#define MLXSW_SP_LPM_TREE_MAX 22
#define MLXSW_SP_LPM_TREE_COUNT (MLXSW_SP_LPM_TREE_MAX - MLXSW_SP_LPM_TREE_MIN)
+#define MLXSW_SP_VIRTUAL_ROUTER_MAX 256
+
#define MLXSW_SP_PORT_BASE_SPEED 25000 /* Mb/s */
#define MLXSW_SP_BYTES_PER_CELL 96
@@ -183,8 +185,20 @@ struct mlxsw_sp_lpm_tree {
struct mlxsw_sp_prefix_usage prefix_usage;
};
+struct mlxsw_sp_fib;
+
+struct mlxsw_sp_vr {
+ u16 id; /* virtual router ID */
+ bool used;
+ enum mlxsw_sp_l3proto proto;
+ u32 tb_id; /* kernel fib table id */
+ struct mlxsw_sp_lpm_tree *lpm_tree;
+ struct mlxsw_sp_fib *fib;
+};
+
struct mlxsw_sp_router {
struct mlxsw_sp_lpm_tree lpm_trees[MLXSW_SP_LPM_TREE_COUNT];
+ struct mlxsw_sp_vr vrs[MLXSW_SP_VIRTUAL_ROUTER_MAX];
};
struct mlxsw_sp {
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 73fd85c..11dab74 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -47,12 +47,46 @@
for_each_set_bit(prefix, (prefix_usage)->b, MLXSW_SP_PREFIX_COUNT)
static bool
+mlxsw_sp_prefix_usage_subset(struct mlxsw_sp_prefix_usage *prefix_usage1,
+ struct mlxsw_sp_prefix_usage *prefix_usage2)
+{
+ unsigned char prefix;
+
+ mlxsw_sp_prefix_usage_for_each(prefix, prefix_usage1) {
+ if (!test_bit(prefix, prefix_usage2->b))
+ return false;
+ }
+ return true;
+}
+
+static bool
mlxsw_sp_prefix_usage_eq(struct mlxsw_sp_prefix_usage *prefix_usage1,
struct mlxsw_sp_prefix_usage *prefix_usage2)
{
return !memcmp(prefix_usage1, prefix_usage2, sizeof(*prefix_usage1));
}
+static bool
+mlxsw_sp_prefix_usage_none(struct mlxsw_sp_prefix_usage *prefix_usage)
+{
+ struct mlxsw_sp_prefix_usage prefix_usage_none = {{ 0 } };
+
+ return mlxsw_sp_prefix_usage_eq(prefix_usage, &prefix_usage_none);
+}
+
+static void
+mlxsw_sp_prefix_usage_cpy(struct mlxsw_sp_prefix_usage *prefix_usage1,
+ struct mlxsw_sp_prefix_usage *prefix_usage2)
+{
+ memcpy(prefix_usage1, prefix_usage2, sizeof(*prefix_usage1));
+}
+
+static void
+mlxsw_sp_prefix_usage_zero(struct mlxsw_sp_prefix_usage *prefix_usage)
+{
+ memset(prefix_usage, 0, sizeof(*prefix_usage));
+}
+
static void
mlxsw_sp_prefix_usage_set(struct mlxsw_sp_prefix_usage *prefix_usage,
unsigned char prefix_len)
@@ -307,6 +341,199 @@ static void mlxsw_sp_lpm_init(struct mlxsw_sp *mlxsw_sp)
}
}
+static struct mlxsw_sp_vr *mlxsw_sp_vr_find_unused(struct mlxsw_sp *mlxsw_sp)
+{
+ struct mlxsw_sp_vr *vr;
+ int i;
+
+ for (i = 0; i < MLXSW_SP_VIRTUAL_ROUTER_MAX; i++) {
+ vr = &mlxsw_sp->router.vrs[i];
+ if (!vr->used)
+ return vr;
+ }
+ return NULL;
+}
+
+static int mlxsw_sp_vr_lpm_tree_bind(struct mlxsw_sp *mlxsw_sp,
+ struct mlxsw_sp_vr *vr)
+{
+ char raltb_pl[MLXSW_REG_RALTB_LEN];
+
+ mlxsw_reg_raltb_pack(raltb_pl, vr->id, vr->proto, vr->lpm_tree->id);
+ return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(raltb), raltb_pl);
+}
+
+static int mlxsw_sp_vr_lpm_tree_unbind(struct mlxsw_sp *mlxsw_sp,
+ struct mlxsw_sp_vr *vr)
+{
+ char raltb_pl[MLXSW_REG_RALTB_LEN];
+
+ /* Bind to tree 0 which is default */
+ mlxsw_reg_raltb_pack(raltb_pl, vr->id, vr->proto, 0);
+ return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(raltb), raltb_pl);
+}
+
+static u32 mlxsw_sp_fix_tb_id(u32 tb_id)
+{
+ /* For our purpose, squash main and local table into one */
+ if (tb_id == RT_TABLE_LOCAL)
+ tb_id = RT_TABLE_MAIN;
+ return tb_id;
+}
+
+static struct mlxsw_sp_vr *mlxsw_sp_vr_find(struct mlxsw_sp *mlxsw_sp,
+ u32 tb_id,
+ enum mlxsw_sp_l3proto proto)
+{
+ struct mlxsw_sp_vr *vr;
+ int i;
+
+ tb_id = mlxsw_sp_fix_tb_id(tb_id);
+ for (i = 0; i < MLXSW_SP_VIRTUAL_ROUTER_MAX; i++) {
+ vr = &mlxsw_sp->router.vrs[i];
+ if (vr->used && vr->proto == proto && vr->tb_id == tb_id)
+ return vr;
+ }
+ return NULL;
+}
+
+static struct mlxsw_sp_vr *mlxsw_sp_vr_create(struct mlxsw_sp *mlxsw_sp,
+ unsigned char prefix_len,
+ u32 tb_id,
+ enum mlxsw_sp_l3proto proto)
+{
+ struct mlxsw_sp_prefix_usage req_prefix_usage;
+ struct mlxsw_sp_lpm_tree *lpm_tree;
+ struct mlxsw_sp_vr *vr;
+ int err;
+
+ vr = mlxsw_sp_vr_find_unused(mlxsw_sp);
+ if (!vr)
+ return ERR_PTR(-EBUSY);
+ vr->fib = mlxsw_sp_fib_create();
+ if (IS_ERR(vr->fib))
+ return ERR_CAST(vr->fib);
+
+ vr->proto = proto;
+ vr->tb_id = tb_id;
+ mlxsw_sp_prefix_usage_zero(&req_prefix_usage);
+ mlxsw_sp_prefix_usage_set(&req_prefix_usage, prefix_len);
+ lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, &req_prefix_usage,
+ proto, true);
+ if (IS_ERR(lpm_tree)) {
+ err = PTR_ERR(lpm_tree);
+ goto err_tree_get;
+ }
+ vr->lpm_tree = lpm_tree;
+ err = mlxsw_sp_vr_lpm_tree_bind(mlxsw_sp, vr);
+ if (err)
+ goto err_tree_bind;
+
+ vr->used = true;
+ return vr;
+
+err_tree_bind:
+ mlxsw_sp_lpm_tree_put(mlxsw_sp, vr->lpm_tree);
+err_tree_get:
+ mlxsw_sp_fib_destroy(vr->fib);
+
+ return ERR_PTR(err);
+}
+
+static void mlxsw_sp_vr_destroy(struct mlxsw_sp *mlxsw_sp,
+ struct mlxsw_sp_vr *vr)
+{
+ mlxsw_sp_vr_lpm_tree_unbind(mlxsw_sp, vr);
+ mlxsw_sp_lpm_tree_put(mlxsw_sp, vr->lpm_tree);
+ mlxsw_sp_fib_destroy(vr->fib);
+ vr->used = false;
+}
+
+static int
+mlxsw_sp_vr_lpm_tree_check(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_vr *vr,
+ struct mlxsw_sp_prefix_usage *req_prefix_usage)
+{
+ struct mlxsw_sp_lpm_tree *lpm_tree;
+
+ if (mlxsw_sp_prefix_usage_eq(req_prefix_usage,
+ &vr->lpm_tree->prefix_usage))
+ return 0;
+
+ lpm_tree = mlxsw_sp_lpm_tree_get(mlxsw_sp, req_prefix_usage,
+ vr->proto, false);
+ if (IS_ERR(lpm_tree)) {
+ /* We failed to get a tree according to the required
+ * prefix usage. However, the current tree might be still good
+ * for us if our requirement is subset of the prefixes used
+ * in the tree.
+ */
+ if (mlxsw_sp_prefix_usage_subset(req_prefix_usage,
+ &vr->lpm_tree->prefix_usage))
+ return 0;
+ return PTR_ERR(lpm_tree);
+ }
+
+ mlxsw_sp_vr_lpm_tree_unbind(mlxsw_sp, vr);
+ mlxsw_sp_lpm_tree_put(mlxsw_sp, vr->lpm_tree);
+ vr->lpm_tree = lpm_tree;
+ return mlxsw_sp_vr_lpm_tree_bind(mlxsw_sp, vr);
+}
+
+static struct mlxsw_sp_vr *mlxsw_sp_vr_get(struct mlxsw_sp *mlxsw_sp,
+ unsigned char prefix_len,
+ u32 tb_id,
+ enum mlxsw_sp_l3proto proto)
+{
+ struct mlxsw_sp_vr *vr;
+ int err;
+
+ tb_id = mlxsw_sp_fix_tb_id(tb_id);
+ vr = mlxsw_sp_vr_find(mlxsw_sp, tb_id, proto);
+ if (!vr) {
+ vr = mlxsw_sp_vr_create(mlxsw_sp, prefix_len, tb_id, proto);
+ if (IS_ERR(vr))
+ return vr;
+ } else {
+ struct mlxsw_sp_prefix_usage req_prefix_usage;
+
+ mlxsw_sp_prefix_usage_cpy(&req_prefix_usage,
+ &vr->fib->prefix_usage);
+ mlxsw_sp_prefix_usage_set(&req_prefix_usage, prefix_len);
+ /* Need to replace LPM tree in case new prefix is required. */
+ err = mlxsw_sp_vr_lpm_tree_check(mlxsw_sp, vr,
+ &req_prefix_usage);
+ if (err)
+ return ERR_PTR(err);
+ }
+ return vr;
+}
+
+static void mlxsw_sp_vr_put(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_vr *vr)
+{
+ /* Destroy virtual router entity in case the associated FIB is empty
+ * and allow it to be used for other tables in future. Otherwise,
+ * check if some prefix usage did not disappear and change tree if
+ * that is the case. Note that in case new, smaller tree cannot be
+ * allocated, the original one will be kept being used.
+ */
+ if (mlxsw_sp_prefix_usage_none(&vr->fib->prefix_usage))
+ mlxsw_sp_vr_destroy(mlxsw_sp, vr);
+ else
+ mlxsw_sp_vr_lpm_tree_check(mlxsw_sp, vr,
+ &vr->fib->prefix_usage);
+}
+
+static void mlxsw_sp_vrs_init(struct mlxsw_sp *mlxsw_sp)
+{
+ struct mlxsw_sp_vr *vr;
+ int i;
+
+ for (i = 0; i < MLXSW_SP_VIRTUAL_ROUTER_MAX; i++) {
+ vr = &mlxsw_sp->router.vrs[i];
+ vr->id = i;
+ }
+}
+
static int __mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
{
char rgcr_pl[MLXSW_REG_RGCR_LEN];
@@ -332,6 +559,7 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
if (err)
return err;
mlxsw_sp_lpm_init(mlxsw_sp);
+ mlxsw_sp_vrs_init(mlxsw_sp);
return 0;
}
--
2.5.5
next prev parent reply other threads:[~2016-07-01 14:23 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-01 14:04 [patch net-next 00/42] mlxsw: Implement IPV4 unicast routing Jiri Pirko
2016-07-01 14:04 ` [patch net-next 01/42] net: add dev arg to ndo_neigh_construct/destroy Jiri Pirko
2016-07-01 14:04 ` [patch net-next 02/42] net: introduce default neigh_construct/destroy ndo calls for L2 upper devices Jiri Pirko
2016-07-01 14:24 ` David Ahern
2016-07-02 7:28 ` Jiri Pirko
2016-07-01 14:04 ` [patch net-next 03/42] neigh: Send a notification when DELAY_PROBE_TIME changes Jiri Pirko
2016-07-01 14:04 ` [patch net-next 04/42] mlxsw: spectrum: Send untagged packets through a port netdev Jiri Pirko
2016-07-01 14:04 ` [patch net-next 05/42] mlxsw: spectrum: Remove VLANs configuration via SELF flag Jiri Pirko
2016-07-01 14:04 ` [patch net-next 06/42] mlxsw: spectrum: Sync PVID vPort LAG status Jiri Pirko
2016-07-01 14:04 ` [patch net-next 07/42] mlxsw: spectrum: Remove RIF from PVID vPort when joining / leaving LAG Jiri Pirko
2016-07-01 14:04 ` [patch net-next 08/42] mlxsw: reg: Add Router General Configuration Register Jiri Pirko
2016-07-01 14:04 ` [patch net-next 09/42] mlxsw: spectrum: Initialize ports at the end of init sequence Jiri Pirko
2016-07-01 14:04 ` [patch net-next 10/42] mlxsw: spectrum_router: Add basic ipv4 router initialization Jiri Pirko
2016-07-01 14:39 ` David Ahern
2016-07-01 17:58 ` Ido Schimmel
2016-07-01 14:04 ` [patch net-next 11/42] mlxsw: spectrum: Add router interface struct Jiri Pirko
2016-07-01 16:16 ` David Ahern
2016-07-01 18:37 ` Ido Schimmel
2016-07-01 14:04 ` [patch net-next 12/42] mlxsw: reg: Add FDB action to forward to router Jiri Pirko
2016-07-01 14:04 ` [patch net-next 13/42] mlxsw: reg: Add Router Interface Table Register Jiri Pirko
2016-07-01 14:04 ` [patch net-next 14/42] mlxsw: spectrum: Use action 'discard' when removing traps Jiri Pirko
2016-07-01 14:04 ` [patch net-next 15/42] mlxsw: spectrum: Add traps needed for router implementation Jiri Pirko
2016-07-01 14:04 ` [patch net-next 16/42] mlxsw: spectrum_router: Implement private fib Jiri Pirko
2016-07-01 14:04 ` [patch net-next 17/42] mlxsw: reg: Add Router Algorithmic LPM Tree Allocation Register definition Jiri Pirko
2016-07-01 14:04 ` [patch net-next 18/42] mlxsw: reg: Add Router Algorithmic LPM Structure Tree " Jiri Pirko
2016-07-01 14:04 ` [patch net-next 19/42] mlxsw: reg: Add Router Algorithmic LPM Tree Binding " Jiri Pirko
2016-07-01 14:04 ` [patch net-next 20/42] mlxsw: spectrum_router: Implement LPM trees management Jiri Pirko
2016-07-01 14:04 ` Jiri Pirko [this message]
2016-07-01 14:04 ` [patch net-next 22/42] mlxsw: reg: Add Router Algorithmic LPM Unicast Entry Register definition Jiri Pirko
2016-07-01 14:04 ` [patch net-next 23/42] mlxsw: spectrum_router: Implement fib4 add/del switchdev obj ops Jiri Pirko
2016-07-01 16:10 ` David Ahern
2016-07-02 6:30 ` Jiri Pirko
2016-07-01 14:04 ` [patch net-next 24/42] mlxsw: spectrum: Add couple of lower device helper functions Jiri Pirko
2016-07-01 14:04 ` [patch net-next 25/42] mlxsw: spectrum: Edit RIF properties based on netdev events Jiri Pirko
2016-07-01 14:04 ` [patch net-next 26/42] mlxsw: spectrum: Introduce support for router interfaces Jiri Pirko
2016-07-01 14:04 ` [patch net-next 27/42] mlxsw: spectrum: Unsplit the vFID range Jiri Pirko
2016-07-01 14:04 ` [patch net-next 28/42] mlxsw: spectrum: Configure FIDs based on bridge events Jiri Pirko
2016-07-01 14:04 ` [patch net-next 29/42] mlxsw: spectrum: Enable L3 interfaces on top of bridge devices Jiri Pirko
2016-07-01 14:04 ` [patch net-next 30/42] mlxsw: spectrum_router: Add private neigh table Jiri Pirko
2016-07-01 14:04 ` [patch net-next 31/42] mlxsw: reg: Add Router Algorithmic LPM Unicast Host Table register Jiri Pirko
2016-07-01 14:05 ` [patch net-next 32/42] mlxsw: reg: Add Router Algorithmic LPM Unicast Host Table Dump register Jiri Pirko
2016-07-01 14:05 ` [patch net-next 33/42] mlxsw: spectrum_router: Periodically update the kernel's neigh table Jiri Pirko
2016-07-01 14:05 ` [patch net-next 34/42] mlxsw: spectrum_router: Offload neighbours based on NUD state change Jiri Pirko
2016-07-01 14:05 ` [patch net-next 35/42] mlxsw: Add KVD sizes configuration into profile Jiri Pirko
2016-07-01 14:05 ` [patch net-next 36/42] mlxsw: spectrum: Define sizes of KVD areas Jiri Pirko
2016-07-01 14:05 ` [patch net-next 37/42] mlxsw: Introduce simplistic KVD linear area manager Jiri Pirko
2016-07-01 14:05 ` [patch net-next 38/42] mlxsw: reg: Add Router Adjacency Table register Jiri Pirko
2016-07-01 14:05 ` [patch net-next 39/42] mlxsw: reg: Add Router Algorithmic LPM ECMP Update Register Jiri Pirko
2016-07-01 14:05 ` [patch net-next 40/42] mlxsw: spectrum_router: Implement next-hop routing Jiri Pirko
2016-07-01 14:05 ` [patch net-next 41/42] mlxsw: spectrum_router: Add the nexthop neigh activity update Jiri Pirko
2016-07-01 14:05 ` [patch net-next 42/42] mlxsw: Add the unresolved next-hops probes Jiri Pirko
2016-07-01 19:27 ` [patch net-next 00/42] mlxsw: Implement IPV4 unicast routing David Miller
2016-07-02 6:31 ` Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1467381910-3445-22-git-send-email-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=andy@greyhouse.net \
--cc=davem@davemloft.net \
--cc=dsa@cumulusnetworks.com \
--cc=eladr@mellanox.com \
--cc=idosch@mellanox.com \
--cc=ivecera@redhat.com \
--cc=jhs@mojatatu.com \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.org \
--cc=nogahf@mellanox.com \
--cc=ogerlitz@mellanox.com \
--cc=roopa@cumulusnetworks.com \
--cc=sfeldma@gmail.com \
--cc=tgraf@suug.ch \
--cc=yotamg@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).