Blob Blame History Raw
From: Jiri Pirko <jiri@mellanox.com>
Date: Mon, 27 Apr 2020 18:05:47 +0300
Subject: mlxsw: spectrum_acl_tcam: Position vchunk in a vregion list properly
Git-commit: 6ef4889fc0b3aa6ab928e7565935ac6f762cee6e
Patch-mainline: 5.7-rc5
References: networking-stable-20_05_12

Vregion helpers to get min and max priority depend on the correct
ordering of vchunks in the vregion list. However, the current code
always adds new chunk to the end of the list, no matter what the
priority is. Fix this by finding the correct place in the list and put
vchunk there.

[js] no virtual chunks and regions in 4.12, so adapt

Fixes: 22a677661f56 ("mlxsw: spectrum: Introduce ACL core with simple TCAM implementation")
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c
@@ -587,7 +587,9 @@ mlxsw_sp_acl_tcam_chunk_assoc(struct mlx
 			      struct mlxsw_afk_element_usage *elusage,
 			      struct mlxsw_sp_acl_tcam_chunk *chunk)
 {
+	struct mlxsw_sp_acl_tcam_chunk *chunk2;
 	struct mlxsw_sp_acl_tcam_region *region;
+	struct list_head *pos;
 	bool region_created = false;
 	bool need_split;
 	int err;
@@ -616,7 +618,14 @@ mlxsw_sp_acl_tcam_chunk_assoc(struct mlx
 	}
 
 	chunk->region = region;
-	list_add_tail(&chunk->list, &region->chunk_list);
+
+	/* Position the chunk inside the list according to priority */
+	list_for_each(pos, &region->chunk_list) {
+		chunk2 = list_entry(pos, typeof(*chunk2), list);
+		if (chunk2->priority > priority)
+			break;
+	}
+	list_add_tail(&chunk->list, pos);
 
 	if (!region_created)
 		return 0;