[v3,2/2] net/mlx5: add test for external Rx queue

Message ID 20220628145841.3364471-3-michaelba@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: external RxQ tests |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Michael Baum June 28, 2022, 2:58 p.m. UTC
  Add mlx5 internal test for map and unmap external RxQs.
This patch adds to Testpmd app a runtime function to test the mapping
API.

For insert mapping use this command:

  testpmd> mlx5 port (port_id) ext_rxq map (sw_queue_id) (hw_queue_id)

For insert mapping use this command:

  testpmd> mlx5 port (port_id) ext_rxq unmap (sw_queue_id)

Signed-off-by: Michael Baum <michaelba@nvidia.com>
Reviewed-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 doc/guides/nics/mlx5.rst        |  19 ++++
 drivers/net/mlx5/mlx5_testpmd.c | 163 ++++++++++++++++++++++++++++++++
 2 files changed, 182 insertions(+)
  

Patch

diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index cd3a613640..9f2832e284 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -1840,3 +1840,22 @@  and its socket path is ``/var/run/import_ipc_socket``:
    Port 0 is attached. Now total ports is 1
    Done
 
+
+port map external Rx queue
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+External Rx queue indexes mapping management.
+
+Map HW queue index (32-bit) to ethdev queue index (16-bit) for external Rx queue::
+
+   testpmd> mlx5 port (port_id) ext_rxq map (sw_queue_id) (hw_queue_id)
+
+Unmap external Rx queue::
+
+   testpmd> mlx5 port (port_id) ext_rxq unmap (sw_queue_id)
+
+where:
+
+* ``sw_queue_id``: queue index in range [64536, 65535].
+  This range is the highest 1000 numbers.
+* ``hw_queue_id``: queue index given by HW in queue creation.
diff --git a/drivers/net/mlx5/mlx5_testpmd.c b/drivers/net/mlx5/mlx5_testpmd.c
index 463ee8e764..ed845834aa 100644
--- a/drivers/net/mlx5/mlx5_testpmd.c
+++ b/drivers/net/mlx5/mlx5_testpmd.c
@@ -401,6 +401,158 @@  static cmdline_parse_inst_t mlx5_cmd_operate_attach_port = {
 };
 #endif
 
+/* Map HW queue index to rte queue index. */
+struct mlx5_cmd_map_ext_rxq {
+	cmdline_fixed_string_t mlx5;
+	cmdline_fixed_string_t port;
+	portid_t port_id;
+	cmdline_fixed_string_t ext_rxq;
+	cmdline_fixed_string_t map;
+	uint16_t sw_queue_id;
+	uint32_t hw_queue_id;
+};
+
+cmdline_parse_token_string_t mlx5_cmd_map_ext_rxq_mlx5 =
+	TOKEN_STRING_INITIALIZER(struct mlx5_cmd_map_ext_rxq, mlx5, "mlx5");
+cmdline_parse_token_string_t mlx5_cmd_map_ext_rxq_port =
+	TOKEN_STRING_INITIALIZER(struct mlx5_cmd_map_ext_rxq, port, "port");
+cmdline_parse_token_num_t mlx5_cmd_map_ext_rxq_port_id =
+	TOKEN_NUM_INITIALIZER(struct mlx5_cmd_map_ext_rxq, port_id, RTE_UINT16);
+cmdline_parse_token_string_t mlx5_cmd_map_ext_rxq_ext_rxq =
+	TOKEN_STRING_INITIALIZER(struct mlx5_cmd_map_ext_rxq, ext_rxq,
+				 "ext_rxq");
+cmdline_parse_token_string_t mlx5_cmd_map_ext_rxq_map =
+	TOKEN_STRING_INITIALIZER(struct mlx5_cmd_map_ext_rxq, map, "map");
+cmdline_parse_token_num_t mlx5_cmd_map_ext_rxq_sw_queue_id =
+	TOKEN_NUM_INITIALIZER(struct mlx5_cmd_map_ext_rxq, sw_queue_id,
+			      RTE_UINT16);
+cmdline_parse_token_num_t mlx5_cmd_map_ext_rxq_hw_queue_id =
+	TOKEN_NUM_INITIALIZER(struct mlx5_cmd_map_ext_rxq, hw_queue_id,
+			      RTE_UINT32);
+
+static void
+mlx5_cmd_map_ext_rxq_parsed(void *parsed_result,
+			    __rte_unused struct cmdline *cl,
+			    __rte_unused void *data)
+{
+	struct mlx5_cmd_map_ext_rxq *res = parsed_result;
+	int ret;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+	ret = rte_pmd_mlx5_external_rx_queue_id_map(res->port_id,
+						    res->sw_queue_id,
+						    res->hw_queue_id);
+	switch (ret) {
+	case 0:
+		break;
+	case -EINVAL:
+		fprintf(stderr, "invalid ethdev index (%u), out of range\n",
+			res->sw_queue_id);
+		break;
+	case -ENODEV:
+		fprintf(stderr, "invalid port_id %u\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		fprintf(stderr, "function not implemented or supported\n");
+		break;
+	case -EEXIST:
+		fprintf(stderr, "mapping with index %u already exists\n",
+			res->sw_queue_id);
+		break;
+	default:
+		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t mlx5_cmd_map_ext_rxq = {
+	.f = mlx5_cmd_map_ext_rxq_parsed,
+	.data = NULL,
+	.help_str = "mlx5 port <port_id> ext_rxq map <sw_queue_id> <hw_queue_id>",
+	.tokens = {
+		(void *)&mlx5_cmd_map_ext_rxq_mlx5,
+		(void *)&mlx5_cmd_map_ext_rxq_port,
+		(void *)&mlx5_cmd_map_ext_rxq_port_id,
+		(void *)&mlx5_cmd_map_ext_rxq_ext_rxq,
+		(void *)&mlx5_cmd_map_ext_rxq_map,
+		(void *)&mlx5_cmd_map_ext_rxq_sw_queue_id,
+		(void *)&mlx5_cmd_map_ext_rxq_hw_queue_id,
+		NULL,
+	}
+};
+
+/* Unmap HW queue index to rte queue index. */
+struct mlx5_cmd_unmap_ext_rxq {
+	cmdline_fixed_string_t mlx5;
+	cmdline_fixed_string_t port;
+	portid_t port_id;
+	cmdline_fixed_string_t ext_rxq;
+	cmdline_fixed_string_t unmap;
+	uint16_t queue_id;
+};
+
+cmdline_parse_token_string_t mlx5_cmd_unmap_ext_rxq_mlx5 =
+	TOKEN_STRING_INITIALIZER(struct mlx5_cmd_unmap_ext_rxq, mlx5, "mlx5");
+cmdline_parse_token_string_t mlx5_cmd_unmap_ext_rxq_port =
+	TOKEN_STRING_INITIALIZER(struct mlx5_cmd_unmap_ext_rxq, port, "port");
+cmdline_parse_token_num_t mlx5_cmd_unmap_ext_rxq_port_id =
+	TOKEN_NUM_INITIALIZER(struct mlx5_cmd_unmap_ext_rxq, port_id,
+			      RTE_UINT16);
+cmdline_parse_token_string_t mlx5_cmd_unmap_ext_rxq_ext_rxq =
+	TOKEN_STRING_INITIALIZER(struct mlx5_cmd_unmap_ext_rxq, ext_rxq,
+				 "ext_rxq");
+cmdline_parse_token_string_t mlx5_cmd_unmap_ext_rxq_unmap =
+	TOKEN_STRING_INITIALIZER(struct mlx5_cmd_unmap_ext_rxq, unmap, "unmap");
+cmdline_parse_token_num_t mlx5_cmd_unmap_ext_rxq_queue_id =
+	TOKEN_NUM_INITIALIZER(struct mlx5_cmd_unmap_ext_rxq, queue_id,
+			      RTE_UINT16);
+
+static void
+mlx5_cmd_unmap_ext_rxq_parsed(void *parsed_result,
+			      __rte_unused struct cmdline *cl,
+			      __rte_unused void *data)
+{
+	struct mlx5_cmd_unmap_ext_rxq *res = parsed_result;
+	int ret;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+	ret = rte_pmd_mlx5_external_rx_queue_id_unmap(res->port_id,
+						      res->queue_id);
+	switch (ret) {
+	case 0:
+		break;
+	case -EINVAL:
+		fprintf(stderr, "invalid rte_flow index (%u), "
+			"out of range, doesn't exist or still referenced\n",
+			res->queue_id);
+		break;
+	case -ENODEV:
+		fprintf(stderr, "invalid port_id %u\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		fprintf(stderr, "function not implemented or supported\n");
+		break;
+	default:
+		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t mlx5_cmd_unmap_ext_rxq = {
+	.f = mlx5_cmd_unmap_ext_rxq_parsed,
+	.data = NULL,
+	.help_str = "mlx5 port <port_id> ext_rxq unmap <queue_id>",
+	.tokens = {
+		(void *)&mlx5_cmd_unmap_ext_rxq_mlx5,
+		(void *)&mlx5_cmd_unmap_ext_rxq_port,
+		(void *)&mlx5_cmd_unmap_ext_rxq_port_id,
+		(void *)&mlx5_cmd_unmap_ext_rxq_ext_rxq,
+		(void *)&mlx5_cmd_unmap_ext_rxq_unmap,
+		(void *)&mlx5_cmd_unmap_ext_rxq_queue_id,
+		NULL,
+	}
+};
+
 static struct testpmd_driver_commands mlx5_driver_cmds = {
 	.commands = {
 		{
@@ -417,6 +569,17 @@  static struct testpmd_driver_commands mlx5_driver_cmds = {
 				"and add \"cmd_fd\" and \"pd_handle\" devargs before attaching\n\n",
 		},
 #endif
+		{
+			.ctx = &mlx5_cmd_map_ext_rxq,
+			.help = "mlx5 port (port_id) ext_rxq map (sw_queue_id) (hw_queue_id)\n"
+				"    Map HW queue index (32-bit) to ethdev"
+				" queue index (16-bit) for external RxQ\n\n",
+		},
+		{
+			.ctx = &mlx5_cmd_unmap_ext_rxq,
+			.help = "mlx5 port (port_id) ext_rxq unmap (sw_queue_id)\n"
+				"    Unmap external Rx queue ethdev index mapping\n\n",
+		},
 		{
 			.ctx = NULL,
 		},