diff mbox

[RESEND,net-next,mlxsw,10/18] mlxsw: spectrum_acl: Allow encoding a partial key

Message ID 20180717153657.16324-11-idosch@mellanox.com (mailing list archive)
State Changes Requested
Delegated to: Ido Schimmel
Headers show

Commit Message

Ido Schimmel July 17, 2018, 3:36 p.m. UTC
When working with 12 key blocks in the A-TCAM, rules are split into two
records, which constitute two lookups. The two records are linked using
a "large entry key ID". The ID is assigned to key blocks 6 to 11 and
resolved during the first lookup. The second lookup is performed using
the ID and the remaining key blocks.

Allow encoding a partial key so that it can be later used to check if an
ID can be reused.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 .../ethernet/mellanox/mlxsw/core_acl_flex_keys.c   | 32 ++++++++++++++++++++++
 .../ethernet/mellanox/mlxsw/core_acl_flex_keys.h   |  4 +++
 2 files changed, 36 insertions(+)
diff mbox

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c
index 5f8485c7640e..9b1b9a733f78 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c
@@ -487,3 +487,35 @@  void mlxsw_afk_encode(struct mlxsw_afk *mlxsw_afk,
 	}
 }
 EXPORT_SYMBOL(mlxsw_afk_encode);
+
+void mlxsw_afk_encode_range(struct mlxsw_afk *mlxsw_afk,
+			    struct mlxsw_afk_key_info *key_info,
+			    struct mlxsw_afk_element_values *values,
+			    char *key, int block_start, int block_end)
+{
+	char block_key[MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE];
+	const struct mlxsw_afk_element_inst *elinst;
+	enum mlxsw_afk_element element;
+	int block_index, i;
+
+	for (i = 0; i < key_info->blocks_count; i++) {
+		if (i < block_start || i > block_end)
+			continue;
+
+		memset(block_key, 0, MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE);
+
+		mlxsw_afk_element_usage_for_each(element, &values->elusage) {
+			elinst = mlxsw_afk_key_info_elinst_get(key_info,
+							       element,
+							       &block_index);
+			if (!elinst || block_index != i)
+				continue;
+
+			mlxsw_sp_afk_encode_one(elinst, block_key,
+						values->storage.key);
+		}
+
+		mlxsw_afk->ops->encode_block(block_key, i, key);
+	}
+}
+EXPORT_SYMBOL(mlxsw_afk_encode_range);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h
index 2ffde915349b..369555a647e0 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h
@@ -260,5 +260,9 @@  void mlxsw_afk_encode(struct mlxsw_afk *mlxsw_afk,
 		      struct mlxsw_afk_key_info *key_info,
 		      struct mlxsw_afk_element_values *values,
 		      char *key, char *mask);
+void mlxsw_afk_encode_range(struct mlxsw_afk *mlxsw_afk,
+			    struct mlxsw_afk_key_info *key_info,
+			    struct mlxsw_afk_element_values *values,
+			    char *key, int block_start, int block_end);
 
 #endif