mlxsw: spectrum_dpipe: Add initial support for the router adjacency table
authorArkadi Sharshevsky <arkadis@mellanox.com>
Mon, 25 Sep 2017 08:32:26 +0000 (10:32 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 27 Sep 2017 03:04:35 +0000 (20:04 -0700)
Add initial support for router adjacency table. The table does lookup
based on the nexthop-group index and the local nexthop offset. After
locating the nexthop entry it sets the destination MAC address and the
egress RIF.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.h

index 9253273a5c0352178cf84f971434c1deacb5adfd..ca16f8924c0a32993066efb8da9724b16d7179b2 100644 (file)
@@ -841,6 +841,97 @@ static void mlxsw_sp_dpipe_host6_table_fini(struct mlxsw_sp *mlxsw_sp)
                                       MLXSW_SP_DPIPE_TABLE_NAME_HOST6);
 }
 
+static int mlxsw_sp_dpipe_table_adj_matches_dump(void *priv,
+                                                struct sk_buff *skb)
+{
+       struct devlink_dpipe_match match = {0};
+       int err;
+
+       match.type = DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT;
+       match.header = &mlxsw_sp_dpipe_header_metadata;
+       match.field_id = MLXSW_SP_DPIPE_FIELD_METADATA_ADJ_INDEX;
+
+       err = devlink_dpipe_match_put(skb, &match);
+       if (err)
+               return err;
+
+       match.type = DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT;
+       match.header = &mlxsw_sp_dpipe_header_metadata;
+       match.field_id = MLXSW_SP_DPIPE_FIELD_METADATA_ADJ_HASH_INDEX;
+
+       return devlink_dpipe_match_put(skb, &match);
+}
+
+static int mlxsw_sp_dpipe_table_adj_actions_dump(void *priv,
+                                                struct sk_buff *skb)
+{
+       struct devlink_dpipe_action action = {0};
+       int err;
+
+       action.type = DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY;
+       action.header = &devlink_dpipe_header_ethernet;
+       action.field_id = DEVLINK_DPIPE_FIELD_ETHERNET_DST_MAC;
+
+       err = devlink_dpipe_action_put(skb, &action);
+       if (err)
+               return err;
+
+       action.type = DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY;
+       action.header = &mlxsw_sp_dpipe_header_metadata;
+       action.field_id = MLXSW_SP_DPIPE_FIELD_METADATA_ERIF_PORT;
+
+       return devlink_dpipe_action_put(skb, &action);
+}
+
+static u64 mlxsw_sp_dpipe_table_adj_size(struct mlxsw_sp *mlxsw_sp)
+{
+       struct mlxsw_sp_nexthop *nh;
+       u64 size = 0;
+
+       mlxsw_sp_nexthop_for_each(nh, mlxsw_sp->router)
+               if (mlxsw_sp_nexthop_offload(nh) &&
+                   !mlxsw_sp_nexthop_group_has_ipip(nh))
+                       size++;
+       return size;
+}
+
+static u64
+mlxsw_sp_dpipe_table_adj_size_get(void *priv)
+{
+       struct mlxsw_sp *mlxsw_sp = priv;
+       u64 size;
+
+       rtnl_lock();
+       size = mlxsw_sp_dpipe_table_adj_size(mlxsw_sp);
+       rtnl_unlock();
+
+       return size;
+}
+
+static struct devlink_dpipe_table_ops mlxsw_sp_dpipe_table_adj_ops = {
+       .matches_dump = mlxsw_sp_dpipe_table_adj_matches_dump,
+       .actions_dump = mlxsw_sp_dpipe_table_adj_actions_dump,
+       .size_get = mlxsw_sp_dpipe_table_adj_size_get,
+};
+
+static int mlxsw_sp_dpipe_adj_table_init(struct mlxsw_sp *mlxsw_sp)
+{
+       struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
+
+       return devlink_dpipe_table_register(devlink,
+                                           MLXSW_SP_DPIPE_TABLE_NAME_ADJ,
+                                           &mlxsw_sp_dpipe_table_adj_ops,
+                                           mlxsw_sp, false);
+}
+
+static void mlxsw_sp_dpipe_adj_table_fini(struct mlxsw_sp *mlxsw_sp)
+{
+       struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
+
+       devlink_dpipe_table_unregister(devlink,
+                                      MLXSW_SP_DPIPE_TABLE_NAME_ADJ);
+}
+
 int mlxsw_sp_dpipe_init(struct mlxsw_sp *mlxsw_sp)
 {
        struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
@@ -861,8 +952,14 @@ int mlxsw_sp_dpipe_init(struct mlxsw_sp *mlxsw_sp)
        err = mlxsw_sp_dpipe_host6_table_init(mlxsw_sp);
        if (err)
                goto err_host6_table_init;
-       return 0;
 
+       err = mlxsw_sp_dpipe_adj_table_init(mlxsw_sp);
+       if (err)
+               goto err_adj_table_init;
+
+       return 0;
+err_adj_table_init:
+       mlxsw_sp_dpipe_host6_table_fini(mlxsw_sp);
 err_host6_table_init:
        mlxsw_sp_dpipe_host4_table_fini(mlxsw_sp);
 err_host4_table_init:
@@ -876,6 +973,7 @@ void mlxsw_sp_dpipe_fini(struct mlxsw_sp *mlxsw_sp)
 {
        struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
 
+       mlxsw_sp_dpipe_adj_table_fini(mlxsw_sp);
        mlxsw_sp_dpipe_host6_table_fini(mlxsw_sp);
        mlxsw_sp_dpipe_host4_table_fini(mlxsw_sp);
        mlxsw_sp_dpipe_erif_table_fini(mlxsw_sp);
index 283fde4e678391257588935adfe933c0b4974cd8..815d543cf114a57aa4b1056dd7f779c43172cf31 100644 (file)
@@ -56,5 +56,6 @@ static inline void mlxsw_sp_dpipe_fini(struct mlxsw_sp *mlxsw_sp)
 #define MLXSW_SP_DPIPE_TABLE_NAME_ERIF "mlxsw_erif"
 #define MLXSW_SP_DPIPE_TABLE_NAME_HOST4 "mlxsw_host4"
 #define MLXSW_SP_DPIPE_TABLE_NAME_HOST6 "mlxsw_host6"
+#define MLXSW_SP_DPIPE_TABLE_NAME_ADJ "mlxsw_adj"
 
 #endif /* _MLXSW_PIPELINE_H_*/