Skip to contentSkip to conversation

common/mlx5: share DevX resources creations

PATCH Superseded Michael Baum 2 participants 57 messages Dec 17, 2020 – Jan 12, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover common/mlx5: share DevX resources creations

Due to many instances of creating CQ SQ and RQ on DevX, they move to common.

Michael Baum (17):
net/mlx5: fix ASO SQ creation error flow common/mlx5: share DevX CQ creation
regex/mlx5: move DevX CQ creation to common vdpa/mlx5: move DevX CQ creation to common net/mlx5: move rearm and clock queue CQ creation to common net/mlx5: move ASO CQ creation to common net/mlx5: move Tx CQ creation to common net/mlx5: move Rx CQ creation to common common/mlx5: enhance page size configuration common/mlx5: share DevX SQ creation
regex/mlx5: move DevX SQ creation to common net/mlx5: move rearm and clock queue SQ creation to common net/mlx5: move Tx SQ creation to common net/mlx5: move ASO SQ creation to common common/mlx5: share DevX RQ creation
net/mlx5: move Rx RQ creation to common common/mlx5: remove doorbell allocation API

 drivers/common/mlx5/meson.build          |   1 +
 drivers/common/mlx5/mlx5_common.c        | 122 ------
 drivers/common/mlx5/mlx5_common.h        |  23 --
 drivers/common/mlx5/mlx5_common_devx.c   | 395 +++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h   |  56 +++
 drivers/common/mlx5/mlx5_devx_cmds.c     |  53 ++-
 drivers/net/mlx5/mlx5.c                  |   8 -
 drivers/net/mlx5/mlx5.h                  |  54 +--
 drivers/net/mlx5/mlx5_devx.c             | 643 +++++++------------------------
 drivers/net/mlx5/mlx5_flow_age.c         | 172 +++------
 drivers/net/mlx5/mlx5_rxtx.c             |   2 +-
 drivers/net/mlx5/mlx5_rxtx.h             |   8 -
 drivers/net/mlx5/mlx5_txpp.c             | 294 ++++----------
 drivers/regex/mlx5/mlx5_regex.c          |   6 -
 drivers/regex/mlx5/mlx5_regex.h          |  17 +-
 drivers/regex/mlx5/mlx5_regex_control.c  | 242 +++---------
 drivers/regex/mlx5/mlx5_regex_fastpath.c |  18 +-
 drivers/vdpa/mlx5/mlx5_vdpa.h            |  10 +-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c      |  81 ++--
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c      |   2 +-
 20 files changed, 839 insertions(+), 1368 deletions(-)
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.c
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.h
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/17 net/mlx5: fix ASO SQ creation error flow

In ASO SQ creation, the PMD allocates umem buffer for SQ.

When umem buffer allocation is fails, the MR and CQ memory are not freed what caused a memory leak.

Free it.

Fixes f935ed4b645a ("net/mlx5: support flow hit action for aging")
---
 drivers/net/mlx5/mlx5_flow_age.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_age.c +2 -1
index cea2cf7..0ea61be 100644
@@ -278,7 +278,8 @@
 				   sizeof(*sq->db_rec) * 2, 4096, socket);
 	if (!sq->umem_buf) {
 		DRV_LOG(ERR, "Can't allocate wqe buffer.");
-		return -ENOMEM;
+		rte_errno = ENOMEM;
+		goto error;
 	}
 	sq->wqe_umem = mlx5_glue->devx_umem_reg(ctx,
 						(void *)(uintptr_t)sq->umem_buf,
Signature · 1 line
1.8.3.1
#2 lore raw

v2 cover common/mlx5: share DevX resources creations

Due to many instances of creating CQ SQ and RQ on DevX, they move to common.

v1: Initial release
v2: Bug fix (sending wrong umem id to FW).

Michael Baum (17):
net/mlx5: fix ASO SQ creation error flow common/mlx5: share DevX CQ creation
regex/mlx5: move DevX CQ creation to common vdpa/mlx5: move DevX CQ creation to common net/mlx5: move rearm and clock queue CQ creation to common net/mlx5: move ASO CQ creation to common net/mlx5: move Tx CQ creation to common net/mlx5: move Rx CQ creation to common common/mlx5: enhance page size configuration common/mlx5: share DevX SQ creation
regex/mlx5: move DevX SQ creation to common net/mlx5: move rearm and clock queue SQ creation to common net/mlx5: move Tx SQ creation to common net/mlx5: move ASO SQ creation to common common/mlx5: share DevX RQ creation
net/mlx5: move Rx RQ creation to common common/mlx5: remove doorbell allocation API

 drivers/common/mlx5/meson.build          |   1 +
 drivers/common/mlx5/mlx5_common.c        | 122 ------
 drivers/common/mlx5/mlx5_common.h        |  23 --
 drivers/common/mlx5/mlx5_common_devx.c   | 395 +++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h   |  56 +++
 drivers/common/mlx5/mlx5_devx_cmds.c     |  53 ++-
 drivers/net/mlx5/mlx5.c                  |   8 -
 drivers/net/mlx5/mlx5.h                  |  54 +--
 drivers/net/mlx5/mlx5_devx.c             | 643 +++++++------------------------
 drivers/net/mlx5/mlx5_flow_age.c         | 172 +++------
 drivers/net/mlx5/mlx5_rxtx.c             |   2 +-
 drivers/net/mlx5/mlx5_rxtx.h             |   8 -
 drivers/net/mlx5/mlx5_txpp.c             | 294 ++++----------
 drivers/regex/mlx5/mlx5_regex.c          |   6 -
 drivers/regex/mlx5/mlx5_regex.h          |  17 +-
 drivers/regex/mlx5/mlx5_regex_control.c  | 242 +++---------
 drivers/regex/mlx5/mlx5_regex_fastpath.c |  18 +-
 drivers/vdpa/mlx5/mlx5_vdpa.h            |  10 +-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c      |  81 ++--
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c      |   2 +-
 20 files changed, 839 insertions(+), 1368 deletions(-)
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.c
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.h
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v2 1/17 net/mlx5: fix ASO SQ creation error flow

In ASO SQ creation, the PMD allocates umem buffer for SQ.

When umem buffer allocation is fails, the MR and CQ memory are not freed what caused a memory leak.

Free it.

Fixes f935ed4b645a ("net/mlx5: support flow hit action for aging")
---
 drivers/net/mlx5/mlx5_flow_age.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_age.c +2 -1
index cea2cf7..0ea61be 100644
@@ -278,7 +278,8 @@
 				   sizeof(*sq->db_rec) * 2, 4096, socket);
 	if (!sq->umem_buf) {
 		DRV_LOG(ERR, "Can't allocate wqe buffer.");
-		return -ENOMEM;
+		rte_errno = ENOMEM;
+		goto error;
 	}
 	sq->wqe_umem = mlx5_glue->devx_umem_reg(ctx,
 						(void *)(uintptr_t)sq->umem_buf,
Signature · 1 line
1.8.3.1
#4 lore raw

v3 cover common/mlx5: share DevX resources creations

Due to many instances of creating CQ SQ and RQ on DevX, they move to common.

v1: Initial release.
v2: Bug fix (sending wrong umem id to HW).
v3: Rebase + Bug fix (sending wrong CQE size to HW).

Michael Baum (19):
common/mlx5: fix completion queue entry size configuration net/mlx5: remove CQE padding device argument net/mlx5: fix ASO SQ creation error flow common/mlx5: share DevX CQ creation
regex/mlx5: move DevX CQ creation to common vdpa/mlx5: move DevX CQ creation to common net/mlx5: move rearm and clock queue CQ creation to common net/mlx5: move ASO CQ creation to common net/mlx5: move Tx CQ creation to common net/mlx5: move Rx CQ creation to common common/mlx5: enhance page size configuration common/mlx5: share DevX SQ creation
regex/mlx5: move DevX SQ creation to common net/mlx5: move rearm and clock queue SQ creation to common net/mlx5: move Tx SQ creation to common net/mlx5: move ASO SQ creation to common common/mlx5: share DevX RQ creation
net/mlx5: move Rx RQ creation to common common/mlx5: remove doorbell allocation API

 doc/guides/nics/mlx5.rst                        |  18 -
 drivers/common/mlx5/meson.build                 |   1 +
 drivers/common/mlx5/mlx5_common.c               | 122 -----
 drivers/common/mlx5/mlx5_common.h               |  23 -
 drivers/common/mlx5/mlx5_common_devx.c          | 387 ++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h          |  70 +++
 drivers/common/mlx5/mlx5_devx_cmds.c            |  57 +--
 drivers/common/mlx5/mlx5_devx_cmds.h            |   1 -
 drivers/common/mlx5/rte_common_mlx5_exports.def |  10 +-
 drivers/common/mlx5/version.map                 |  10 +-
 drivers/common/mlx5/windows/mlx5_win_ext.h      |   1 +
 drivers/net/mlx5/linux/mlx5_os.c                |  12 -
 drivers/net/mlx5/linux/mlx5_verbs.c             |   2 +-
 drivers/net/mlx5/mlx5.c                         |  14 -
 drivers/net/mlx5/mlx5.h                         |  55 +-
 drivers/net/mlx5/mlx5_devx.c                    | 645 +++++-------------------
 drivers/net/mlx5/mlx5_flow_age.c                | 173 ++-----
 drivers/net/mlx5/mlx5_rxtx.c                    |   2 +-
 drivers/net/mlx5/mlx5_rxtx.h                    |   8 -
 drivers/net/mlx5/mlx5_txpp.c                    | 290 +++--------
 drivers/net/mlx5/windows/mlx5_os.c              |   7 -
 drivers/regex/mlx5/mlx5_regex.c                 |   6 -
 drivers/regex/mlx5/mlx5_regex.h                 |  17 +-
 drivers/regex/mlx5/mlx5_regex_control.c         | 242 +++------
 drivers/regex/mlx5/mlx5_regex_fastpath.c        |  18 +-
 drivers/vdpa/mlx5/mlx5_vdpa.h                   |  10 +-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c             |  86 +---
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c             |   2 +-
 28 files changed, 859 insertions(+), 1430 deletions(-)
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.c
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.h
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v3 1/19 common/mlx5: fix completion queue entry size configuration

According to the current data-path implementation in the PMD the CQE size must follow the cache-line size.
So, the configuration of the CQE size should be depended in RTE_CACHE_LINE_SIZE.

Wrongly, part of the CQE creations didn't follow it exactly what caused an incompatibility between HW and SW in the data-path when working in 128B cache-line size systems.

Adjust the rule for any CQE creation.
Remove the cqe_size attribute from the DevX CQ creation command and set it inside the command translation according to the cache-line size.

Fixes 79a7e409a2f6 ("common/mlx5: prepare support of packet pacing")
Fixes 5cd0a83f413e ("common/mlx5: support more fields in DevX CQ create")
---
 drivers/common/mlx5/mlx5_devx_cmds.c | 4 ++--
 drivers/common/mlx5/mlx5_devx_cmds.h | 1 -
 drivers/net/mlx5/mlx5_devx.c         | 4 ----
 drivers/net/mlx5/mlx5_txpp.c         | 4 ----
 4 files changed, 2 insertions(+), 11 deletions(-)
drivers/common/mlx5/mlx5_devx_cmds.c +2 -2
index 12f51a9..59f0bcc 100644
@@ -1569,7 +1569,8 @@ struct mlx5_devx_obj *
 	} else {
 		MLX5_SET64(cqc, cqctx, dbr_addr, attr->db_addr);
 	}
-	MLX5_SET(cqc, cqctx, cqe_sz, attr->cqe_size);
+	MLX5_SET(cqc, cqctx, cqe_sz, (RTE_CACHE_LINE_SIZE == 128) ?
+				     MLX5_CQE_SIZE_128B : MLX5_CQE_SIZE_64B);
 	MLX5_SET(cqc, cqctx, cc, attr->use_first_only);
 	MLX5_SET(cqc, cqctx, oi, attr->overrun_ignore);
 	MLX5_SET(cqc, cqctx, log_cq_size, attr->log_cq_size);
@@ -1582,7 +1583,6 @@ struct mlx5_devx_obj *
 		 attr->mini_cqe_res_format);
 	MLX5_SET(cqc, cqctx, mini_cqe_res_format_ext,
 		 attr->mini_cqe_res_format_ext);
-	MLX5_SET(cqc, cqctx, cqe_sz, attr->cqe_size);
 	if (attr->q_umem_valid) {
 		MLX5_SET(create_cq_in, in, cq_umem_valid, attr->q_umem_valid);
 		MLX5_SET(create_cq_in, in, cq_umem_id, attr->q_umem_id);
drivers/common/mlx5/mlx5_devx_cmds.h +0 -1
index b335b7c..a14f3bf 100644
@@ -277,7 +277,6 @@ struct mlx5_devx_cq_attr {
 	uint32_t cqe_comp_en:1;
 	uint32_t mini_cqe_res_format:2;
 	uint32_t mini_cqe_res_format_ext:2;
-	uint32_t cqe_size:3;
 	uint32_t log_cq_size:5;
 	uint32_t log_page_size:5;
 	uint32_t uar_page_id;
drivers/net/mlx5/mlx5_devx.c +0 -4
index da3bb78..5c5bea6 100644
@@ -486,8 +486,6 @@
 			"Port %u Rx CQE compression is disabled for LRO.",
 			dev->data->port_id);
 	}
-	if (priv->config.cqe_pad)
-		cq_attr.cqe_size = MLX5_CQE_SIZE_128B;
 	log_cqe_n = log2above(cqe_n);
 	cq_size = sizeof(struct mlx5_cqe) * (1 << log_cqe_n);
 	buf = rte_calloc_socket(__func__, 1, cq_size, page_size,
@@ -1262,8 +1260,6 @@
 		DRV_LOG(ERR, "Failed to allocate CQ door-bell.");
 		goto error;
 	}
-	cq_attr.cqe_size = (sizeof(struct mlx5_cqe) == 128) ?
-			    MLX5_CQE_SIZE_128B : MLX5_CQE_SIZE_64B;
 	cq_attr.uar_page_id = mlx5_os_get_devx_uar_page_id(priv->sh->tx_uar);
 	cq_attr.eqn = priv->sh->eqn;
 	cq_attr.q_umem_valid = 1;
drivers/net/mlx5/mlx5_txpp.c +0 -4
index 726bdc6a..e998de3 100644
@@ -278,8 +278,6 @@
 		goto error;
 	}
 	/* Create completion queue object for Rearm Queue. */
-	cq_attr.cqe_size = (sizeof(struct mlx5_cqe) == 128) ?
-			    MLX5_CQE_SIZE_128B : MLX5_CQE_SIZE_64B;
 	cq_attr.uar_page_id = mlx5_os_get_devx_uar_page_id(sh->tx_uar);
 	cq_attr.eqn = sh->eqn;
 	cq_attr.q_umem_valid = 1;
@@ -516,8 +514,6 @@
 		goto error;
 	}
 	/* Create completion queue object for Clock Queue. */
-	cq_attr.cqe_size = (sizeof(struct mlx5_cqe) == 128) ?
-			    MLX5_CQE_SIZE_128B : MLX5_CQE_SIZE_64B;
 	cq_attr.use_first_only = 1;
 	cq_attr.overrun_ignore = 1;
 	cq_attr.uar_page_id = mlx5_os_get_devx_uar_page_id(sh->tx_uar);
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v3 2/19 net/mlx5: remove CQE padding device argument

In reply to Michael Baum

The data-path code doesn't take care on 'rxq_cqe_pad_en' and use padded CQE for any case when the system cache-line size is 128B.

This makes the argument redundant.

Remove it.

Fixes bc91e8db12cd ("net/mlx5: add 128B padding of Rx completion entry")
---
 doc/guides/nics/mlx5.rst            | 18 ------------------
 drivers/net/mlx5/linux/mlx5_os.c    | 12 ------------
 drivers/net/mlx5/linux/mlx5_verbs.c |  2 +-
 drivers/net/mlx5/mlx5.c             |  6 ------
 drivers/net/mlx5/mlx5.h             |  1 -
 drivers/net/mlx5/windows/mlx5_os.c  |  7 -------
 6 files changed, 1 insertion(+), 45 deletions(-)
doc/guides/nics/mlx5.rst +0 -18
index 3bda0f8..6950cc1 100644
@@ -448,24 +448,6 @@ Driver options
   - POWER9 and ARMv8 with ConnectX-4 Lx, ConnectX-5, ConnectX-6, ConnectX-6 Dx,
     ConnectX-6 Lx, BlueField and BlueField-2.
 
-- ``rxq_cqe_pad_en`` parameter [int]
-
-  A nonzero value enables 128B padding of CQE on RX side. The size of CQE
-  is aligned with the size of a cacheline of the core. If cacheline size is
-  128B, the CQE size is configured to be 128B even though the device writes
-  only 64B data on the cacheline. This is to avoid unnecessary cache
-  invalidation by device's two consecutive writes on to one cacheline.
-  However in some architecture, it is more beneficial to update entire
-  cacheline with padding the rest 64B rather than striding because
-  read-modify-write could drop performance a lot. On the other hand,
-  writing extra data will consume more PCIe bandwidth and could also drop
-  the maximum throughput. It is recommended to empirically set this
-  parameter. Disabled by default.
-
-  Supported on:
-
-  - CPU having 128B cacheline with ConnectX-5 and BlueField.
-
 - ``rxq_pkt_pad_en`` parameter [int]
 
   A nonzero value enables padding Rx packet to the size of cacheline on PCI
drivers/net/mlx5/linux/mlx5_os.c +0 -12
index 6812a1f..9ac1d46 100644
@@ -677,7 +677,6 @@
 	unsigned int hw_padding = 0;
 	unsigned int mps;
 	unsigned int cqe_comp;
-	unsigned int cqe_pad = 0;
 	unsigned int tunnel_en = 0;
 	unsigned int mpls_en = 0;
 	unsigned int swp = 0;
@@ -875,11 +874,6 @@
 	else
 		cqe_comp = 1;
 	config->cqe_comp = cqe_comp;
-#ifdef HAVE_IBV_MLX5_MOD_CQE_128B_PAD
-	/* Whether device supports 128B Rx CQE padding. */
-	cqe_pad = RTE_CACHE_LINE_SIZE == 128 &&
-		  (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_CQE_128B_PAD);
-#endif
 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
 	if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_TUNNEL_OFFLOADS) {
 		tunnel_en = ((dv_attr.tunnel_offloads_caps &
@@ -1116,12 +1110,6 @@
 		DRV_LOG(WARNING, "Rx CQE compression isn't supported");
 		config->cqe_comp = 0;
 	}
-	if (config->cqe_pad && !cqe_pad) {
-		DRV_LOG(WARNING, "Rx CQE padding isn't supported");
-		config->cqe_pad = 0;
-	} else if (config->cqe_pad) {
-		DRV_LOG(INFO, "Rx CQE padding is enabled");
-	}
 	if (config->devx) {
 		err = mlx5_devx_cmd_query_hca_attr(sh->ctx, &config->hca_attr);
 		if (err) {
drivers/net/mlx5/linux/mlx5_verbs.c +1 -1
index b52ae2e..318e39b 100644
@@ -234,7 +234,7 @@
 			dev->data->port_id);
 	}
 #ifdef HAVE_IBV_MLX5_MOD_CQE_128B_PAD
-	if (priv->config.cqe_pad) {
+	if (RTE_CACHE_LINE_SIZE == 128) {
 		cq_attr.mlx5.comp_mask |= MLX5DV_CQ_INIT_ATTR_MASK_FLAGS;
 		cq_attr.mlx5.flags |= MLX5DV_CQ_INIT_ATTR_FLAGS_CQE_PAD;
 	}
drivers/net/mlx5/mlx5.c +0 -6
index 023ef50..91492c5 100644
@@ -44,9 +44,6 @@
 /* Device parameter to enable RX completion queue compression. */
 #define MLX5_RXQ_CQE_COMP_EN "rxq_cqe_comp_en"
 
-/* Device parameter to enable RX completion entry padding to 128B. */
-#define MLX5_RXQ_CQE_PAD_EN "rxq_cqe_pad_en"
-
 /* Device parameter to enable padding Rx packet to cacheline size. */
 #define MLX5_RXQ_PKT_PAD_EN "rxq_pkt_pad_en"
 
@@ -1625,8 +1622,6 @@ struct mlx5_dev_ctx_shared *
 		}
 		config->cqe_comp = !!tmp;
 		config->cqe_comp_fmt = tmp;
-	} else if (strcmp(MLX5_RXQ_CQE_PAD_EN, key) == 0) {
-		config->cqe_pad = !!tmp;
 	} else if (strcmp(MLX5_RXQ_PKT_PAD_EN, key) == 0) {
 		config->hw_padding = !!tmp;
 	} else if (strcmp(MLX5_RX_MPRQ_EN, key) == 0) {
@@ -1755,7 +1750,6 @@ struct mlx5_dev_ctx_shared *
 {
 	const char **params = (const char *[]){
 		MLX5_RXQ_CQE_COMP_EN,
-		MLX5_RXQ_CQE_PAD_EN,
 		MLX5_RXQ_PKT_PAD_EN,
 		MLX5_RX_MPRQ_EN,
 		MLX5_RX_MPRQ_LOG_STRIDE_NUM,
drivers/net/mlx5/mlx5.h +0 -1
index 41034f5..92a5d04 100644
@@ -212,7 +212,6 @@ struct mlx5_dev_config {
 	unsigned int mpls_en:1; /* MPLS over GRE/UDP is enabled. */
 	unsigned int cqe_comp:1; /* CQE compression is enabled. */
 	unsigned int cqe_comp_fmt:3; /* CQE compression format. */
-	unsigned int cqe_pad:1; /* CQE padding is enabled. */
 	unsigned int tso:1; /* Whether TSO is supported. */
 	unsigned int rx_vec_en:1; /* Rx vector is enabled. */
 	unsigned int mr_ext_memseg_en:1;
drivers/net/mlx5/windows/mlx5_os.c +0 -7
index fdd69fd..b036432 100644
@@ -313,7 +313,6 @@
 	struct mlx5_priv *priv = NULL;
 	int err = 0;
 	unsigned int cqe_comp;
-	unsigned int cqe_pad = 0;
 	struct rte_ether_addr mac;
 	char name[RTE_ETH_NAME_MAX_LEN];
 	int own_domain_id = 0;
@@ -461,12 +460,6 @@
 		DRV_LOG(WARNING, "Rx CQE compression isn't supported.");
 		config->cqe_comp = 0;
 	}
-	if (config->cqe_pad && !cqe_pad) {
-		DRV_LOG(WARNING, "Rx CQE padding isn't supported.");
-		config->cqe_pad = 0;
-	} else if (config->cqe_pad) {
-		DRV_LOG(INFO, "Rx CQE padding is enabled.");
-	}
 	if (config->devx) {
 		err = mlx5_devx_cmd_query_hca_attr(sh->ctx, &config->hca_attr);
 		if (err) {
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v3 3/19 net/mlx5: fix ASO SQ creation error flow

In reply to Michael Baum

In ASO SQ creation, the PMD allocates umem buffer for SQ.

When umem buffer allocation is fails, the MR and CQ memory are not freed what caused a memory leak.

Free it.

Fixes f935ed4b645a ("net/mlx5: support flow hit action for aging")
---
 drivers/net/mlx5/mlx5_flow_age.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_age.c +2 -1
index 1f15f19..e867607 100644
@@ -279,7 +279,8 @@
 				   sizeof(*sq->db_rec) * 2, 4096, socket);
 	if (!sq->umem_buf) {
 		DRV_LOG(ERR, "Can't allocate wqe buffer.");
-		return -ENOMEM;
+		rte_errno = ENOMEM;
+		goto error;
 	}
 	sq->wqe_umem = mlx5_os_umem_reg(ctx,
 						(void *)(uintptr_t)sq->umem_buf,
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v3 4/19 common/mlx5: share DevX CQ creation

In reply to Michael Baum

The CQ object in DevX is created in several places and in several different drivers.
In all places almost all the details are the same, and in particular the allocations of the required resources.

Add a structure that contains all the resources, and provide creation and release functions for it.

---
 drivers/common/mlx5/meson.build                 |   1 +
 drivers/common/mlx5/mlx5_common_devx.c          | 155 ++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h          |  31 +++++
 drivers/common/mlx5/rte_common_mlx5_exports.def |   3 +
 drivers/common/mlx5/version.map                 |   3 +
 drivers/common/mlx5/windows/mlx5_win_ext.h      |   1 +
 6 files changed, 194 insertions(+)
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.c
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.h
drivers/common/mlx5/meson.build +1 -0
index 3dacc6f..26cee06 100644
@@ -16,6 +16,7 @@ sources += files(
 	'mlx5_common_mr.c',
 	'mlx5_malloc.c',
 	'mlx5_common_pci.c',
+	'mlx5_common_devx.c',
 )
 
 cflags_options = [
drivers/common/mlx5/mlx5_common_devx.c new file +155 -0

155 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_devx.h new file +31 -0
new file mode 100644
index 0000000..20d5da0
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 Mellanox Technologies, Ltd
+ */
+
+#ifndef RTE_PMD_MLX5_COMMON_DEVX_H_
+#define RTE_PMD_MLX5_COMMON_DEVX_H_
+
+#include "mlx5_devx_cmds.h"
+
+/* DevX Completion Queue structure. */
+struct mlx5_devx_cq {
+	struct mlx5_devx_obj *cq; /* The CQ DevX object. */
+	void *umem_obj; /* The CQ umem object. */
+	union {
+		volatile void *umem_buf;
+		volatile struct mlx5_cqe *cqes; /* The CQ ring buffer. */
+	};
+	volatile uint32_t *db_rec; /* The CQ doorbell record. */
+};
+
+/* mlx5_common_devx.c */
+
+__rte_internal
+void mlx5_devx_cq_destroy(struct mlx5_devx_cq *cq);
+
+__rte_internal
+int mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj,
+			uint16_t log_desc_n, struct mlx5_devx_cq_attr *attr,
+			int socket);
+
+#endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */
drivers/common/mlx5/rte_common_mlx5_exports.def +3 -0
index 65ae47a..d10db40 100644
@@ -35,6 +35,9 @@ EXPORTS
 	mlx5_devx_get_out_command_status
 	mlx5_devx_cmd_create_flow_hit_aso_obj
 
+    mlx5_devx_cq_create
+    mlx5_devx_cq_destroy
+
 	mlx5_get_dbr
 	mlx5_glue
 
drivers/common/mlx5/version.map +3 -0
index fb3952b..850202c 100644
@@ -43,6 +43,9 @@ INTERNAL {
 	mlx5_devx_get_out_command_status;
 	mlx5_devx_alloc_uar;
 
+    mlx5_devx_cq_create;
+    mlx5_devx_cq_destroy;
+
 	mlx5_get_ifname_sysfs;
 	mlx5_get_dbr;
 
drivers/common/mlx5/windows/mlx5_win_ext.h +1 -0
index 111af2e..60610df 100644
@@ -9,6 +9,7 @@
 extern "C" {
 #endif
 
+#include "mlx5_prm.h"
 #include "mlx5devx.h"
 
 typedef struct mlx5_context {
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH v3 5/19 regex/mlx5: move DevX CQ creation to common

In reply to Michael Baum

Using common function for DevX CQ creation.

---
 drivers/regex/mlx5/mlx5_regex.c          |  6 ---
 drivers/regex/mlx5/mlx5_regex.h          |  9 +---
 drivers/regex/mlx5/mlx5_regex_control.c  | 91 ++++++--------------------------
 drivers/regex/mlx5/mlx5_regex_fastpath.c |  4 +-
 4 files changed, 20 insertions(+), 90 deletions(-)
drivers/regex/mlx5/mlx5_regex.c +0 -6
index c91c444..c0d6331 100644
@@ -170,12 +170,6 @@
 		rte_errno = rte_errno ? rte_errno : EINVAL;
 		goto error;
 	}
-	ret = mlx5_glue->devx_query_eqn(ctx, 0, &priv->eqn);
-	if (ret) {
-		DRV_LOG(ERR, "can't query event queue number.");
-		rte_errno = ENOMEM;
-		goto error;
-	}
 	/*
 	 * This PMD always claims the write memory barrier on UAR
 	 * registers writings, it is safe to allocate UAR with any
drivers/regex/mlx5/mlx5_regex.h +2 -7
index 2c4877c..9f7a388 100644
@@ -12,6 +12,7 @@
 
 #include <mlx5_common.h>
 #include <mlx5_common_mr.h>
+#include <mlx5_common_devx.h>
 
 #include "mlx5_rxp.h"
 
@@ -30,13 +31,8 @@ struct mlx5_regex_sq {
 
 struct mlx5_regex_cq {
 	uint32_t log_nb_desc; /* Log 2 number of desc for this object. */
-	struct mlx5_devx_obj *obj; /* The CQ DevX object. */
-	int64_t dbr_offset; /* Door bell record offset. */
-	uint32_t dbr_umem; /* Door bell record umem id. */
-	volatile struct mlx5_cqe *cqe; /* The CQ ring buffer. */
-	struct mlx5dv_devx_umem *cqe_umem; /* CQ buffer umem. */
+	struct mlx5_devx_cq cq_obj; /* The CQ DevX object. */
 	size_t ci;
-	uint32_t *dbr;
 };
 
 struct mlx5_regex_qp {
@@ -75,7 +71,6 @@ struct mlx5_regex_priv {
 	struct mlx5_regex_db db[MLX5_RXP_MAX_ENGINES +
 				MLX5_RXP_EM_COUNT];
 	uint32_t nb_engines; /* Number of RegEx engines. */
-	uint32_t eqn; /* EQ number. */
 	struct mlx5dv_devx_uar *uar; /* UAR object. */
 	struct ibv_pd *pd;
 	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
drivers/regex/mlx5/mlx5_regex_control.c +16 -75

139 lines not on this page · raw message

drivers/regex/mlx5/mlx5_regex_fastpath.c +2 -2
index 5857617..255fd40 100644
@@ -224,7 +224,7 @@ struct mlx5_regex_job {
 	size_t next_cqe_offset;
 
 	next_cqe_offset =  (cq->ci & (cq_size_get(cq) - 1));
-	cqe = (volatile struct mlx5_cqe *)(cq->cqe + next_cqe_offset);
+	cqe = (volatile struct mlx5_cqe *)(cq->cq_obj.cqes + next_cqe_offset);
 	rte_io_wmb();
 
 	int ret = check_cqe(cqe, cq_size_get(cq), cq->ci);
@@ -285,7 +285,7 @@ struct mlx5_regex_job {
 		}
 		cq->ci = (cq->ci + 1) & 0xffffff;
 		rte_wmb();
-		cq->dbr[0] = rte_cpu_to_be_32(cq->ci);
+		cq->cq_obj.db_rec[0] = rte_cpu_to_be_32(cq->ci);
 		queue->free_sqs |= (1 << sqid);
 	}
 
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v3 6/19 vdpa/mlx5: move DevX CQ creation to common

In reply to Michael Baum

Using common function for DevX CQ creation.

---
 drivers/vdpa/mlx5/mlx5_vdpa.h       | 10 +----
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 86 +++++++++++--------------------------
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c |  2 +-
 3 files changed, 28 insertions(+), 70 deletions(-)
drivers/vdpa/mlx5/mlx5_vdpa.h +2 -8
index d039ada..ddee9dc 100644
@@ -22,6 +22,7 @@
 
 #include <mlx5_glue.h>
 #include <mlx5_devx_cmds.h>
+#include <mlx5_common_devx.h>
 #include <mlx5_prm.h>
 
 
@@ -46,13 +47,7 @@ struct mlx5_vdpa_cq {
 	uint32_t armed:1;
 	int callfd;
 	rte_spinlock_t sl;
-	struct mlx5_devx_obj *cq;
-	struct mlx5dv_devx_umem *umem_obj;
-	union {
-		volatile void *umem_buf;
-		volatile struct mlx5_cqe *cqes;
-	};
-	volatile uint32_t *db_rec;
+	struct mlx5_devx_cq cq_obj;
 	uint64_t errors;
 };
 
@@ -144,7 +139,6 @@ struct mlx5_vdpa_priv {
 	uint32_t gpa_mkey_index;
 	struct ibv_mr *null_mr;
 	struct rte_vhost_memory *vmem;
-	uint32_t eqn;
 	struct mlx5dv_devx_event_channel *eventc;
 	struct mlx5dv_devx_event_channel *err_chnl;
 	struct mlx5dv_devx_uar *uar;
drivers/vdpa/mlx5/mlx5_vdpa_event.c +25 -61

181 lines not on this page · raw message

drivers/vdpa/mlx5/mlx5_vdpa_virtq.c +1 -1
index 3e882e4..cc77314 100644
@@ -497,7 +497,7 @@
 		return -1;
 	if (vq.size != virtq->vq_size || vq.kickfd != virtq->intr_handle.fd)
 		return 1;
-	if (virtq->eqp.cq.cq) {
+	if (virtq->eqp.cq.cq_obj.cq) {
 		if (vq.callfd != virtq->eqp.cq.callfd)
 			return 1;
 	} else if (vq.callfd != -1) {
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v3 7/19 net/mlx5: move rearm and clock queue CQ creation to common

In reply to Michael Baum

Using common function for CQ creation at rearm queue and clock queue.

---
 drivers/net/mlx5/mlx5.h      |   9 +--
 drivers/net/mlx5/mlx5_rxtx.c |   2 +-
 drivers/net/mlx5/mlx5_txpp.c | 139 ++++++++++---------------------------------
 3 files changed, 36 insertions(+), 114 deletions(-)
drivers/net/mlx5/mlx5.h +2 -7
index 92a5d04..ba2a8c4 100644
@@ -26,6 +26,7 @@
 #include <mlx5_prm.h>
 #include <mlx5_common_mp.h>
 #include <mlx5_common_mr.h>
+#include <mlx5_common_devx.h>
 
 #include "mlx5_defs.h"
 #include "mlx5_utils.h"
@@ -616,13 +617,7 @@ struct mlx5_flow_id_pool {
 /* Tx pacing queue structure - for Clock and Rearm queues. */
 struct mlx5_txpp_wq {
 	/* Completion Queue related data.*/
-	struct mlx5_devx_obj *cq;
-	void *cq_umem;
-	union {
-		volatile void *cq_buf;
-		volatile struct mlx5_cqe *cqes;
-	};
-	volatile uint32_t *cq_dbrec;
+	struct mlx5_devx_cq cq_obj;
 	uint32_t cq_ci:24;
 	uint32_t arm_sn:2;
 	/* Send Queue related data.*/
drivers/net/mlx5/mlx5_rxtx.c +1 -1
index 65a1f99..3497765 100644
@@ -2325,7 +2325,7 @@ enum mlx5_txcmp_code {
 
 	qs = RTE_PTR_ADD(wqe, MLX5_WSEG_SIZE);
 	qs->max_index = rte_cpu_to_be_32(wci);
-	qs->qpn_cqn = rte_cpu_to_be_32(txq->sh->txpp.clock_queue.cq->id);
+	qs->qpn_cqn = rte_cpu_to_be_32(txq->sh->txpp.clock_queue.cq_obj.cq->id);
 	qs->reserved0 = RTE_BE32(0);
 	qs->reserved1 = RTE_BE32(0);
 }
drivers/net/mlx5/mlx5_txpp.c +33 -106

248 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#12 lore raw

PATCH v3 8/19 net/mlx5: move ASO CQ creation to common

In reply to Michael Baum

Use common function for ASO CQ creation.

---
 drivers/net/mlx5/mlx5.h          |  8 +---
 drivers/net/mlx5/mlx5_flow_age.c | 82 +++++++++-------------------------------
 2 files changed, 19 insertions(+), 71 deletions(-)
drivers/net/mlx5/mlx5.h +1 -7
index ba2a8c4..f889180 100644
@@ -467,13 +467,7 @@ struct mlx5_flow_counter_mng {
 struct mlx5_aso_cq {
 	uint16_t log_desc_n;
 	uint32_t cq_ci:24;
-	struct mlx5_devx_obj *cq;
-	struct mlx5dv_devx_umem *umem_obj;
-	union {
-		volatile void *umem_buf;
-		volatile struct mlx5_cqe *cqes;
-	};
-	volatile uint32_t *db_rec;
+	struct mlx5_devx_cq cq_obj;
 	uint64_t errors;
 };
 
drivers/net/mlx5/mlx5_flow_age.c +18 -64

168 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#13 lore raw

PATCH v3 9/19 net/mlx5: move Tx CQ creation to common

In reply to Michael Baum

Using common function for Tx CQ creation.

---
 drivers/net/mlx5/mlx5.h      |   6 +-
 drivers/net/mlx5/mlx5_devx.c | 178 +++++++------------------------------------
 2 files changed, 29 insertions(+), 155 deletions(-)
drivers/net/mlx5/mlx5.h +1 -5
index f889180..e61154b 100644
@@ -847,11 +847,7 @@ struct mlx5_txq_obj {
 		};
 		struct {
 			struct rte_eth_dev *dev;
-			struct mlx5_devx_obj *cq_devx;
-			void *cq_umem;
-			void *cq_buf;
-			int64_t cq_dbrec_offset;
-			struct mlx5_devx_dbr_page *cq_dbrec_page;
+			struct mlx5_devx_cq cq_obj;
 			struct mlx5_devx_obj *sq_devx;
 			void *sq_umem;
 			void *sq_buf;
drivers/net/mlx5/mlx5_devx.c +28 -150

220 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#14 lore raw

PATCH v3 10/19 net/mlx5: move Rx CQ creation to common

In reply to Michael Baum

Using common function for Rx CQ creation.

---
 drivers/net/mlx5/mlx5.c      |   8 ---
 drivers/net/mlx5/mlx5.h      |   3 +-
 drivers/net/mlx5/mlx5_devx.c | 142 +++++++++++++------------------------------
 drivers/net/mlx5/mlx5_rxtx.h |   4 --
 4 files changed, 42 insertions(+), 115 deletions(-)
drivers/net/mlx5/mlx5.c +0 -8
index 91492c5..c0a36d6 100644
@@ -936,14 +936,6 @@ struct mlx5_dev_ctx_shared *
 		goto error;
 	}
 	if (sh->devx) {
-		/* Query the EQN for this core. */
-		err = mlx5_glue->devx_query_eqn(sh->ctx, 0, &sh->eqn);
-		if (err) {
-			rte_errno = errno;
-			DRV_LOG(ERR, "Failed to query event queue number %d.",
-				rte_errno);
-			goto error;
-		}
 		err = mlx5_os_get_pdn(sh->pd, &sh->pdn);
 		if (err) {
 			DRV_LOG(ERR, "Fail to extract pdn from PD");
drivers/net/mlx5/mlx5.h +1 -2
index e61154b..079cbca 100644
@@ -683,7 +683,6 @@ struct mlx5_dev_ctx_shared {
 	uint16_t bond_dev; /* Bond primary device id. */
 	uint32_t devx:1; /* Opened with DV. */
 	uint32_t flow_hit_aso_en:1; /* Flow Hit ASO is supported. */
-	uint32_t eqn; /* Event Queue number. */
 	uint32_t max_port; /* Maximal IB device port index. */
 	void *ctx; /* Verbs/DV/DevX context. */
 	void *pd; /* Protection Domain. */
@@ -791,7 +790,7 @@ struct mlx5_rxq_obj {
 		};
 		struct {
 			struct mlx5_devx_obj *rq; /* DevX Rx Queue object. */
-			struct mlx5_devx_obj *devx_cq; /* DevX CQ object. */
+			struct mlx5_devx_cq cq_obj; /* DevX CQ object. */
 			void *devx_channel;
 		};
 	};
drivers/net/mlx5/mlx5_devx.c +41 -101

221 lines not on this page · raw message

drivers/net/mlx5/mlx5_rxtx.h +0 -4
index 1e9345a..aba9541 100644
@@ -196,11 +196,7 @@ struct mlx5_rxq_ctrl {
 	struct mlx5_devx_dbr_page *rq_dbrec_page;
 	uint64_t rq_dbr_offset;
 	/* Storing RQ door-bell information, needed when freeing door-bell. */
-	struct mlx5_devx_dbr_page *cq_dbrec_page;
-	uint64_t cq_dbr_offset;
-	/* Storing CQ door-bell information, needed when freeing door-bell. */
 	void *wq_umem; /* WQ buffer registration info. */
-	void *cq_umem; /* CQ buffer registration info. */
 	struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
 	uint32_t hairpin_status; /* Hairpin binding status. */
 };
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH v3 11/19 common/mlx5: enhance page size configuration

In reply to Michael Baum

The PRM calculates page size in 4K, so need to reduce the log_wq_pg_sz attribute.

---
 drivers/common/mlx5/mlx5_devx_cmds.c | 53 ++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 30 deletions(-)
drivers/common/mlx5/mlx5_devx_cmds.c +23 -30
index 59f0bcc..790a701 100644
@@ -268,9 +268,8 @@ struct mlx5_devx_obj *
 	MLX5_SET(mkc, mkc, mkey_7_0, attr->umem_id & 0xFF);
 	MLX5_SET(mkc, mkc, translations_octword_size, translation_size);
 	MLX5_SET(mkc, mkc, relaxed_ordering_write,
-		attr->relaxed_ordering_write);
-	MLX5_SET(mkc, mkc, relaxed_ordering_read,
-		attr->relaxed_ordering_read);
+		 attr->relaxed_ordering_write);
+	MLX5_SET(mkc, mkc, relaxed_ordering_read, attr->relaxed_ordering_read);
 	MLX5_SET64(mkc, mkc, start_addr, attr->addr);
 	MLX5_SET64(mkc, mkc, len, attr->size);
 	mkey->obj = mlx5_glue->devx_obj_create(ctx, in, in_size_dw * 4, out,
@@ -308,7 +307,7 @@ struct mlx5_devx_obj *
 	if (status) {
 		int syndrome = MLX5_GET(query_flow_counter_out, out, syndrome);
 
-		DRV_LOG(ERR, "Bad devX status %x, syndrome = %x", status,
+		DRV_LOG(ERR, "Bad DevX status %x, syndrome = %x", status,
 			syndrome);
 	}
 	return status;
@@ -374,8 +373,7 @@ struct mlx5_devx_obj *
 	syndrome = MLX5_GET(query_nic_vport_context_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query NIC vport context, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		return -1;
 	}
 	vctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
@@ -662,8 +660,7 @@ struct mlx5_devx_obj *
 	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		return -1;
 	}
 	hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
@@ -683,11 +680,11 @@ struct mlx5_devx_obj *
 		(cmd_hca_cap, hcattr, log_min_hairpin_wq_data_sz);
 	attr->vhca_id = MLX5_GET(cmd_hca_cap, hcattr, vhca_id);
 	attr->relaxed_ordering_write = MLX5_GET(cmd_hca_cap, hcattr,
-			relaxed_ordering_write);
+						relaxed_ordering_write);
 	attr->relaxed_ordering_read = MLX5_GET(cmd_hca_cap, hcattr,
-			relaxed_ordering_read);
+					       relaxed_ordering_read);
 	attr->access_register_user = MLX5_GET(cmd_hca_cap, hcattr,
-			access_register_user);
+					      access_register_user);
 	attr->eth_net_offloads = MLX5_GET(cmd_hca_cap, hcattr,
 					  eth_net_offloads);
 	attr->eth_virt = MLX5_GET(cmd_hca_cap, hcattr, eth_virt);
@@ -738,8 +735,7 @@ struct mlx5_devx_obj *
 			goto error;
 		if (status) {
 			DRV_LOG(DEBUG, "Failed to query devx QOS capabilities,"
-				" status %x, syndrome = %x",
-				status, syndrome);
+				" status %x, syndrome = %x", status, syndrome);
 			return -1;
 		}
 		hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
@@ -769,17 +765,14 @@ struct mlx5_devx_obj *
 		 MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
 		 MLX5_HCA_CAP_OPMOD_GET_CUR);
 
-	rc = mlx5_glue->devx_general_cmd(ctx,
-					 in, sizeof(in),
-					 out, sizeof(out));
+	rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out));
 	if (rc)
 		goto error;
 	status = MLX5_GET(query_hca_cap_out, out, status);
 	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		attr->log_max_ft_sampler_num = 0;
 		return -1;
 	}
@@ -796,9 +789,7 @@ struct mlx5_devx_obj *
 		 MLX5_GET_HCA_CAP_OP_MOD_ETHERNET_OFFLOAD_CAPS |
 		 MLX5_HCA_CAP_OPMOD_GET_CUR);
 
-	rc = mlx5_glue->devx_general_cmd(ctx,
-					 in, sizeof(in),
-					 out, sizeof(out));
+	rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out));
 	if (rc) {
 		attr->eth_net_offloads = 0;
 		goto error;
@@ -807,8 +798,7 @@ struct mlx5_devx_obj *
 	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		attr->eth_net_offloads = 0;
 		return -1;
 	}
@@ -927,7 +917,9 @@ struct mlx5_devx_obj *
 	MLX5_SET(wq, wq_ctx, hw_counter, wq_attr->hw_counter);
 	MLX5_SET(wq, wq_ctx, sw_counter, wq_attr->sw_counter);
 	MLX5_SET(wq, wq_ctx, log_wq_stride, wq_attr->log_wq_stride);
-	MLX5_SET(wq, wq_ctx, log_wq_pg_sz, wq_attr->log_wq_pg_sz);
+	if (wq_attr->log_wq_pg_sz > MLX5_ADAPTER_PAGE_SHIFT)
+		MLX5_SET(wq, wq_ctx, log_wq_pg_sz,
+			 wq_attr->log_wq_pg_sz - MLX5_ADAPTER_PAGE_SHIFT);
 	MLX5_SET(wq, wq_ctx, log_wq_sz, wq_attr->log_wq_sz);
 	MLX5_SET(wq, wq_ctx, dbr_umem_valid, wq_attr->dbr_umem_valid);
 	MLX5_SET(wq, wq_ctx, wq_umem_valid, wq_attr->wq_umem_valid);
@@ -1574,13 +1566,13 @@ struct mlx5_devx_obj *
 	MLX5_SET(cqc, cqctx, cc, attr->use_first_only);
 	MLX5_SET(cqc, cqctx, oi, attr->overrun_ignore);
 	MLX5_SET(cqc, cqctx, log_cq_size, attr->log_cq_size);
-	MLX5_SET(cqc, cqctx, log_page_size, attr->log_page_size -
-		 MLX5_ADAPTER_PAGE_SHIFT);
+	if (attr->log_page_size > MLX5_ADAPTER_PAGE_SHIFT)
+		MLX5_SET(cqc, cqctx, log_page_size,
+			 attr->log_page_size - MLX5_ADAPTER_PAGE_SHIFT);
 	MLX5_SET(cqc, cqctx, c_eqn, attr->eqn);
 	MLX5_SET(cqc, cqctx, uar_page, attr->uar_page_id);
 	MLX5_SET(cqc, cqctx, cqe_comp_en, !!attr->cqe_comp_en);
-	MLX5_SET(cqc, cqctx, mini_cqe_res_format,
-		 attr->mini_cqe_res_format);
+	MLX5_SET(cqc, cqctx, mini_cqe_res_format, attr->mini_cqe_res_format);
 	MLX5_SET(cqc, cqctx, mini_cqe_res_format_ext,
 		 attr->mini_cqe_res_format_ext);
 	if (attr->q_umem_valid) {
@@ -1809,8 +1801,9 @@ struct mlx5_devx_obj *
 	if (attr->uar_index) {
 		MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED);
 		MLX5_SET(qpc, qpc, uar_page, attr->uar_index);
-		MLX5_SET(qpc, qpc, log_page_size, attr->log_page_size -
-			 MLX5_ADAPTER_PAGE_SHIFT);
+		if (attr->log_page_size > MLX5_ADAPTER_PAGE_SHIFT)
+			MLX5_SET(qpc, qpc, log_page_size,
+				 attr->log_page_size - MLX5_ADAPTER_PAGE_SHIFT);
 		if (attr->sq_size) {
 			MLX5_ASSERT(RTE_IS_POWER_OF_2(attr->sq_size));
 			MLX5_SET(qpc, qpc, cqn_snd, attr->cqn);
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH v3 12/19 common/mlx5: share DevX SQ creation

In reply to Michael Baum

The SQ object in DevX is created in several places and in several different drivers.
In all places almost all the details are the same, and in particular the allocations of the required resources.

Add a structure that contains all the resources, and provide creation and release functions for it.

---
 drivers/common/mlx5/mlx5_common_devx.c          | 119 ++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h          |  27 +++++-
 drivers/common/mlx5/rte_common_mlx5_exports.def |   2 +
 drivers/common/mlx5/version.map                 |   2 +
 4 files changed, 148 insertions(+), 2 deletions(-)
drivers/common/mlx5/mlx5_common_devx.c +119 -0
index 3ec0dd5..58b75c3 100644
@@ -153,3 +153,122 @@
 	rte_errno = ret;
 	return -rte_errno;
 }
+
+/**
+ * Destroy DevX Send Queue.
+ *
+ * @param[in] sq
+ *   DevX SQ to destroy.
+ */
+void
+mlx5_devx_sq_destroy(struct mlx5_devx_sq *sq)
+{
+	if (sq->sq)
+		claim_zero(mlx5_devx_cmd_destroy(sq->sq));
+	if (sq->umem_obj)
+		claim_zero(mlx5_os_umem_dereg(sq->umem_obj));
+	if (sq->umem_buf)
+		mlx5_free((void *)(uintptr_t)sq->umem_buf);
+}
+
+/**
+ * Create Send Queue using DevX API.
+ *
+ * Get a pointer to partially initialized attributes structure, and updates the
+ * following fields:
+ *   wq_type
+ *   wq_umem_valid
+ *   wq_umem_id
+ *   wq_umem_offset
+ *   dbr_umem_valid
+ *   dbr_umem_id
+ *   dbr_addr
+ *   log_wq_stride
+ *   log_wq_sz
+ *   log_wq_pg_sz
+ * All other fields are updated by caller.
+ *
+ * @param[in] ctx
+ *   Context returned from mlx5 open_device() glue function.
+ * @param[in/out] sq_obj
+ *   Pointer to SQ to create.
+ * @param[in] log_wqbb_n
+ *   Log of number of WQBBs in queue.
+ * @param[in] attr
+ *   Pointer to SQ attributes structure.
+ * @param[in] socket
+ *   Socket to use for allocation.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj, uint16_t log_wqbb_n,
+		    struct mlx5_devx_create_sq_attr *attr, int socket)
+{
+	struct mlx5_devx_obj *sq = NULL;
+	struct mlx5dv_devx_umem *umem_obj = NULL;
+	void *umem_buf = NULL;
+	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
+	uint32_t umem_size, umem_dbrec;
+	uint16_t sq_size = 1 << log_wqbb_n;
+	int ret;
+
+	if (alignment == (size_t)-1) {
+		DRV_LOG(ERR, "Failed to get WQE buf alignment.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Allocate memory buffer for WQEs and doorbell record. */
+	umem_size = MLX5_WQE_SIZE * sq_size;
+	umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE);
+	umem_size += MLX5_DBR_SIZE;
+	umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size,
+			       alignment, socket);
+	if (!umem_buf) {
+		DRV_LOG(ERR, "Failed to allocate memory for SQ.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Register allocated buffer in user space with DevX. */
+	umem_obj = mlx5_os_umem_reg(ctx, (void *)(uintptr_t)umem_buf, umem_size,
+				    IBV_ACCESS_LOCAL_WRITE);
+	if (!umem_obj) {
+		DRV_LOG(ERR, "Failed to register umem for SQ.");
+		rte_errno = errno;
+		goto error;
+	}
+	/* Fill attributes for SQ object creation. */
+	attr->wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
+	attr->wq_attr.wq_umem_valid = 1;
+	attr->wq_attr.wq_umem_id = mlx5_os_get_umem_id(umem_obj);
+	attr->wq_attr.wq_umem_offset = 0;
+	attr->wq_attr.dbr_umem_valid = 1;
+	attr->wq_attr.dbr_umem_id = attr->wq_attr.wq_umem_id;
+	attr->wq_attr.dbr_addr = umem_dbrec;
+	attr->wq_attr.log_wq_stride = rte_log2_u32(MLX5_WQE_SIZE);
+	attr->wq_attr.log_wq_sz = log_wqbb_n;
+	attr->wq_attr.log_wq_pg_sz = MLX5_LOG_PAGE_SIZE;
+	/* Create send queue object with DevX. */
+	sq = mlx5_devx_cmd_create_sq(ctx, attr);
+	if (!sq) {
+		DRV_LOG(ERR, "Can't create DevX SQ object.");
+		rte_errno = ENOMEM;
+		goto error;
+	}
+	sq_obj->umem_buf = umem_buf;
+	sq_obj->umem_obj = umem_obj;
+	sq_obj->sq = sq;
+	sq_obj->db_rec = RTE_PTR_ADD(sq_obj->umem_buf, umem_dbrec);
+	return 0;
+error:
+	ret = rte_errno;
+	if (umem_obj)
+		claim_zero(mlx5_os_umem_dereg(umem_obj));
+	if (umem_buf)
+		mlx5_free((void *)(uintptr_t)umem_buf);
+	rte_errno = ret;
+	return -rte_errno;
+}
+
+
drivers/common/mlx5/mlx5_common_devx.h +25 -2
index 20d5da0..6b078b2 100644
@@ -7,6 +7,9 @@
 
 #include "mlx5_devx_cmds.h"
 
+/* The standard page size */
+#define MLX5_LOG_PAGE_SIZE 12
+
 /* DevX Completion Queue structure. */
 struct mlx5_devx_cq {
 	struct mlx5_devx_obj *cq; /* The CQ DevX object. */
@@ -18,6 +21,18 @@ struct mlx5_devx_cq {
 	volatile uint32_t *db_rec; /* The CQ doorbell record. */
 };
 
+/* DevX Send Queue structure. */
+struct mlx5_devx_sq {
+	struct mlx5_devx_obj *sq; /* The SQ DevX object. */
+	void *umem_obj; /* The SQ umem object. */
+	union {
+		volatile void *umem_buf;
+		volatile struct mlx5_wqe *wqes; /* The SQ ring buffer. */
+	};
+	volatile uint32_t *db_rec; /* The SQ doorbell record. */
+};
+
+
 /* mlx5_common_devx.c */
 
 __rte_internal
@@ -25,7 +40,15 @@ struct mlx5_devx_cq {
 
 __rte_internal
 int mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj,
-			uint16_t log_desc_n, struct mlx5_devx_cq_attr *attr,
-			int socket);
+			uint16_t log_desc_n,
+			struct mlx5_devx_cq_attr *attr, int socket);
+
+__rte_internal
+void mlx5_devx_sq_destroy(struct mlx5_devx_sq *sq);
+
+__rte_internal
+int mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj,
+			uint16_t log_wqbb_n,
+			struct mlx5_devx_create_sq_attr *attr, int socket);
 
 #endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */
drivers/common/mlx5/rte_common_mlx5_exports.def +2 -0
index d10db40..cfee96e 100644
@@ -37,6 +37,8 @@ EXPORTS
 
     mlx5_devx_cq_create
     mlx5_devx_cq_destroy
+    mlx5_devx_sq_create
+    mlx5_devx_sq_destroy
 
 	mlx5_get_dbr
 	mlx5_glue
drivers/common/mlx5/version.map +2 -0
index 850202c..3414588 100644
@@ -45,6 +45,8 @@ INTERNAL {
 
     mlx5_devx_cq_create;
     mlx5_devx_cq_destroy;
+    mlx5_devx_sq_create;
+    mlx5_devx_sq_destroy;
 
 	mlx5_get_ifname_sysfs;
 	mlx5_get_dbr;
Signature · 1 line
1.8.3.1
#17 lore raw

PATCH v3 13/19 regex/mlx5: move DevX SQ creation to common

In reply to Michael Baum

Using common function for DevX SQ creation.

---
 drivers/regex/mlx5/mlx5_regex.h          |   8 +-
 drivers/regex/mlx5/mlx5_regex_control.c  | 153 ++++++++++---------------------
 drivers/regex/mlx5/mlx5_regex_fastpath.c |  14 +--
 3 files changed, 55 insertions(+), 120 deletions(-)
drivers/regex/mlx5/mlx5_regex.h +1 -7
index 9f7a388..7e1b2a9 100644
@@ -18,15 +18,10 @@
 
 struct mlx5_regex_sq {
 	uint16_t log_nb_desc; /* Log 2 number of desc for this object. */
-	struct mlx5_devx_obj *obj; /* The SQ DevX object. */
-	int64_t dbr_offset; /* Door bell record offset. */
-	uint32_t dbr_umem; /* Door bell record umem id. */
-	uint8_t *wqe; /* The SQ ring buffer. */
-	struct mlx5dv_devx_umem *wqe_umem; /* SQ buffer umem. */
+	struct mlx5_devx_sq sq_obj; /* The SQ DevX object. */
 	size_t pi, db_pi;
 	size_t ci;
 	uint32_t sqn;
-	uint32_t *dbr;
 };
 
 struct mlx5_regex_cq {
@@ -73,7 +68,6 @@ struct mlx5_regex_priv {
 	uint32_t nb_engines; /* Number of RegEx engines. */
 	struct mlx5dv_devx_uar *uar; /* UAR object. */
 	struct ibv_pd *pd;
-	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
 	struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. */
 };
 
drivers/regex/mlx5/mlx5_regex_control.c +47 -106

188 lines not on this page · raw message

drivers/regex/mlx5/mlx5_regex_fastpath.c +7 -7
index 255fd40..cd0f9bd 100644
@@ -110,12 +110,12 @@ struct mlx5_regex_job {
 				  &priv->mr_scache, &qp->mr_ctrl,
 				  rte_pktmbuf_mtod(op->mbuf, uintptr_t),
 				  !!(op->mbuf->ol_flags & EXT_ATTACHED_MBUF));
-	uint8_t *wqe = (uint8_t *)sq->wqe + wqe_offset;
+	uint8_t *wqe = (uint8_t *)(uintptr_t)sq->sq_obj.wqes + wqe_offset;
 	int ds = 4; /*  ctrl + meta + input + output */
 
 	set_wqe_ctrl_seg((struct mlx5_wqe_ctrl_seg *)wqe, sq->pi,
-			 MLX5_OPCODE_MMO, MLX5_OPC_MOD_MMO_REGEX, sq->obj->id,
-			 0, ds, 0, 0);
+			 MLX5_OPCODE_MMO, MLX5_OPC_MOD_MMO_REGEX,
+			 sq->sq_obj.sq->id, 0, ds, 0, 0);
 	set_regex_ctrl_seg(wqe + 12, 0, op->group_id0, op->group_id1,
 			   op->group_id2,
 			   op->group_id3, 0);
@@ -137,12 +137,12 @@ struct mlx5_regex_job {
 {
 	size_t wqe_offset = (sq->db_pi & (sq_size_get(sq) - 1)) *
 		MLX5_SEND_WQE_BB;
-	uint8_t *wqe = (uint8_t *)sq->wqe + wqe_offset;
+	uint8_t *wqe = (uint8_t *)(uintptr_t)sq->sq_obj.wqes + wqe_offset;
 	((struct mlx5_wqe_ctrl_seg *)wqe)->fm_ce_se = MLX5_WQE_CTRL_CQ_UPDATE;
 	uint64_t *doorbell_addr =
 		(uint64_t *)((uint8_t *)uar->base_addr + 0x800);
 	rte_io_wmb();
-	sq->dbr[MLX5_SND_DBR] = rte_cpu_to_be_32((sq->db_pi + 1) &
+	sq->sq_obj.db_rec[MLX5_SND_DBR] = rte_cpu_to_be_32((sq->db_pi + 1) &
 						 MLX5_REGEX_MAX_WQE_INDEX);
 	rte_wmb();
 	*doorbell_addr = *(volatile uint64_t *)wqe;
@@ -301,7 +301,7 @@ struct mlx5_regex_job {
 	uint32_t job_id;
 	for (sqid = 0; sqid < queue->nb_obj; sqid++) {
 		struct mlx5_regex_sq *sq = &queue->sqs[sqid];
-		uint8_t *wqe = (uint8_t *)sq->wqe;
+		uint8_t *wqe = (uint8_t *)(uintptr_t)sq->sq_obj.wqes;
 		for (entry = 0 ; entry < sq_size_get(sq); entry++) {
 			job_id = sqid * sq_size_get(sq) + entry;
 			struct mlx5_regex_job *job = &queue->jobs[job_id];
@@ -334,7 +334,7 @@ struct mlx5_regex_job {
 		return -ENOMEM;
 
 	qp->metadata = mlx5_glue->reg_mr(pd, ptr,
-					 MLX5_REGEX_METADATA_SIZE*qp->nb_desc,
+					 MLX5_REGEX_METADATA_SIZE * qp->nb_desc,
 					 IBV_ACCESS_LOCAL_WRITE);
 	if (!qp->metadata) {
 		DRV_LOG(ERR, "Failed to register metadata");
Signature · 1 line
1.8.3.1
#18 lore raw

PATCH v3 14/19 net/mlx5: move rearm and clock queue SQ creation to common

In reply to Michael Baum

Using common function for DevX SQ creation for rearm and clock queue.

---
 drivers/net/mlx5/mlx5.h      |   8 +--
 drivers/net/mlx5/mlx5_txpp.c | 147 +++++++++++--------------------------------
 2 files changed, 36 insertions(+), 119 deletions(-)
drivers/net/mlx5/mlx5.h +1 -7
index 079cbca..0a0a943 100644
@@ -615,15 +615,9 @@ struct mlx5_txpp_wq {
 	uint32_t cq_ci:24;
 	uint32_t arm_sn:2;
 	/* Send Queue related data.*/
-	struct mlx5_devx_obj *sq;
-	void *sq_umem;
-	union {
-		volatile void *sq_buf;
-		volatile struct mlx5_wqe *wqes;
-	};
+	struct mlx5_devx_sq sq_obj;
 	uint16_t sq_size; /* Number of WQEs in the queue. */
 	uint16_t sq_ci; /* Next WQE to execute. */
-	volatile uint32_t *sq_dbrec;
 };
 
 /* Tx packet pacing internal timestamp. */
drivers/net/mlx5/mlx5_txpp.c +35 -112

275 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#19 lore raw

PATCH v3 15/19 net/mlx5: move Tx SQ creation to common

In reply to Michael Baum

Using common function for Tx SQ creation.

---
 drivers/net/mlx5/mlx5.h      |   8 +--
 drivers/net/mlx5/mlx5_devx.c | 162 ++++++++++---------------------------------
 2 files changed, 40 insertions(+), 130 deletions(-)
drivers/net/mlx5/mlx5.h +3 -5
index 0a0a943..62d7c89 100644
@@ -841,11 +841,9 @@ struct mlx5_txq_obj {
 		struct {
 			struct rte_eth_dev *dev;
 			struct mlx5_devx_cq cq_obj;
-			struct mlx5_devx_obj *sq_devx;
-			void *sq_umem;
-			void *sq_buf;
-			int64_t sq_dbrec_offset;
-			struct mlx5_devx_dbr_page *sq_dbrec_page;
+			/* DevX CQ object and its resources. */
+			struct mlx5_devx_sq sq_obj;
+			/* DevX SQ object and its resources. */
 		};
 	};
 };
drivers/net/mlx5/mlx5_devx.c +37 -125

221 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#20 lore raw

PATCH v3 16/19 net/mlx5: move ASO SQ creation to common

In reply to Michael Baum

Using common function for ASO SQ creation.

---
 drivers/common/mlx5/mlx5_common_devx.h |  1 +
 drivers/net/mlx5/mlx5.h                |  8 +--
 drivers/net/mlx5/mlx5_flow_age.c       | 94 ++++++++++------------------------
 3 files changed, 30 insertions(+), 73 deletions(-)
drivers/common/mlx5/mlx5_common_devx.h +1 -0
index 6b078b2..992ad8f 100644
@@ -28,6 +28,7 @@ struct mlx5_devx_sq {
 	union {
 		volatile void *umem_buf;
 		volatile struct mlx5_wqe *wqes; /* The SQ ring buffer. */
+		volatile struct mlx5_aso_wqe *aso_wqes;
 	};
 	volatile uint32_t *db_rec; /* The SQ doorbell record. */
 };
drivers/net/mlx5/mlx5.h +1 -7
index 62d7c89..a3fd8d5 100644
@@ -487,13 +487,7 @@ struct mlx5_aso_sq_elem {
 struct mlx5_aso_sq {
 	uint16_t log_desc_n;
 	struct mlx5_aso_cq cq;
-	struct mlx5_devx_obj *sq;
-	struct mlx5dv_devx_umem *wqe_umem; /* SQ buffer umem. */
-	union {
-		volatile void *umem_buf;
-		volatile struct mlx5_aso_wqe *wqes;
-	};
-	volatile uint32_t *db_rec;
+	struct mlx5_devx_sq sq_obj;
 	volatile uint64_t *uar_addr;
 	struct mlx5_aso_devx_mr mr;
 	uint16_t pi;
drivers/net/mlx5/mlx5_flow_age.c +28 -66

152 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#21 lore raw

PATCH v3 17/19 common/mlx5: share DevX RQ creation

In reply to Michael Baum

The RQ object in DevX is used currently only in net driver, but it share for future.

Add a structure that contains all the resources, and provide creation and release functions for it.

---
 drivers/common/mlx5/mlx5_common_devx.c          | 113 ++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h          |  15 ++++
 drivers/common/mlx5/rte_common_mlx5_exports.def |   2 +
 drivers/common/mlx5/version.map                 |   2 +
 4 files changed, 132 insertions(+)
drivers/common/mlx5/mlx5_common_devx.c +113 -0
index 58b75c3..d19be12 100644
@@ -271,4 +271,117 @@
 	return -rte_errno;
 }
 
+/**
+ * Destroy DevX Receive Queue.
+ *
+ * @param[in] rq
+ *   DevX RQ to destroy.
+ */
+void
+mlx5_devx_rq_destroy(struct mlx5_devx_rq *rq)
+{
+	if (rq->rq)
+		claim_zero(mlx5_devx_cmd_destroy(rq->rq));
+	if (rq->umem_obj)
+		claim_zero(mlx5_os_umem_dereg(rq->umem_obj));
+	if (rq->umem_buf)
+		mlx5_free((void *)(uintptr_t)rq->umem_buf);
+}
+
+/**
+ * Create Receive Queue using DevX API.
+ *
+ * Get a pointer to partially initialized attributes structure, and updates the
+ * following fields:
+ *   wq_umem_valid
+ *   wq_umem_id
+ *   wq_umem_offset
+ *   dbr_umem_valid
+ *   dbr_umem_id
+ *   dbr_addr
+ *   log_wq_pg_sz
+ * All other fields are updated by caller.
+ *
+ * @param[in] ctx
+ *   Context returned from mlx5 open_device() glue function.
+ * @param[in/out] rq_obj
+ *   Pointer to RQ to create.
+ * @param[in] wqe_size
+ *   Size of WQE structure.
+ * @param[in] log_wqbb_n
+ *   Log of number of WQBBs in queue.
+ * @param[in] attr
+ *   Pointer to RQ attributes structure.
+ * @param[in] socket
+ *   Socket to use for allocation.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_devx_rq_create(void *ctx, struct mlx5_devx_rq *rq_obj, uint32_t wqe_size,
+		    uint16_t log_wqbb_n,
+		    struct mlx5_devx_create_rq_attr *attr, int socket)
+{
+	struct mlx5_devx_obj *rq = NULL;
+	struct mlx5dv_devx_umem *umem_obj = NULL;
+	void *umem_buf = NULL;
+	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
+	uint32_t umem_size, umem_dbrec;
+	uint16_t rq_size = 1 << log_wqbb_n;
+	int ret;
+
+	if (alignment == (size_t)-1) {
+		DRV_LOG(ERR, "Failed to get WQE buf alignment.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Allocate memory buffer for WQEs and doorbell record. */
+	umem_size = wqe_size * rq_size;
+	umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE);
+	umem_size += MLX5_DBR_SIZE;
+	umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size,
+			       alignment, socket);
+	if (!umem_buf) {
+		DRV_LOG(ERR, "Failed to allocate memory for RQ.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Register allocated buffer in user space with DevX. */
+	umem_obj = mlx5_os_umem_reg(ctx, (void *)(uintptr_t)umem_buf,
+				    umem_size, 0);
+	if (!umem_obj) {
+		DRV_LOG(ERR, "Failed to register umem for RQ.");
+		rte_errno = errno;
+		goto error;
+	}
+	/* Fill attributes for RQ object creation. */
+	attr->wq_attr.wq_umem_valid = 1;
+	attr->wq_attr.wq_umem_id = mlx5_os_get_umem_id(umem_obj);
+	attr->wq_attr.wq_umem_offset = 0;
+	attr->wq_attr.dbr_umem_valid = 1;
+	attr->wq_attr.dbr_umem_id = attr->wq_attr.wq_umem_id;
+	attr->wq_attr.dbr_addr = umem_dbrec;
+	attr->wq_attr.log_wq_pg_sz = MLX5_LOG_PAGE_SIZE;
+	/* Create receive queue object with DevX. */
+	rq = mlx5_devx_cmd_create_rq(ctx, attr, socket);
+	if (!rq) {
+		DRV_LOG(ERR, "Can't create DevX RQ object.");
+		rte_errno = ENOMEM;
+		goto error;
+	}
+	rq_obj->umem_buf = umem_buf;
+	rq_obj->umem_obj = umem_obj;
+	rq_obj->rq = rq;
+	rq_obj->db_rec = RTE_PTR_ADD(rq_obj->umem_buf, umem_dbrec);
+	return 0;
+error:
+	ret = rte_errno;
+	if (umem_obj)
+		claim_zero(mlx5_os_umem_dereg(umem_obj));
+	if (umem_buf)
+		mlx5_free((void *)(uintptr_t)umem_buf);
+	rte_errno = ret;
+	return -rte_errno;
+}
 
drivers/common/mlx5/mlx5_common_devx.h +15 -0
index 992ad8f..aad0184 100644
@@ -33,6 +33,13 @@ struct mlx5_devx_sq {
 	volatile uint32_t *db_rec; /* The SQ doorbell record. */
 };
 
+/* DevX Receive Queue structure. */
+struct mlx5_devx_rq {
+	struct mlx5_devx_obj *rq; /* The RQ DevX object. */
+	void *umem_obj; /* The RQ umem object. */
+	volatile void *umem_buf;
+	volatile uint32_t *db_rec; /* The RQ doorbell record. */
+};
 
 /* mlx5_common_devx.c */
 
@@ -52,4 +59,12 @@ int mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj,
 			uint16_t log_wqbb_n,
 			struct mlx5_devx_create_sq_attr *attr, int socket);
 
+__rte_internal
+void mlx5_devx_rq_destroy(struct mlx5_devx_rq *rq);
+
+__rte_internal
+int mlx5_devx_rq_create(void *ctx, struct mlx5_devx_rq *rq_obj,
+			uint32_t wqe_size, uint16_t log_wqbb_n,
+			struct mlx5_devx_create_rq_attr *attr, int socket);
+
 #endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */
drivers/common/mlx5/rte_common_mlx5_exports.def +2 -0
index cfee96e..6e1ff50 100644
@@ -37,6 +37,8 @@ EXPORTS
 
     mlx5_devx_cq_create
     mlx5_devx_cq_destroy
+    mlx5_devx_rq_create
+    mlx5_devx_rq_destroy
     mlx5_devx_sq_create
     mlx5_devx_sq_destroy
 
drivers/common/mlx5/version.map +2 -0
index 3414588..dac9411 100644
@@ -45,6 +45,8 @@ INTERNAL {
 
     mlx5_devx_cq_create;
     mlx5_devx_cq_destroy;
+    mlx5_devx_rq_create;
+    mlx5_devx_rq_destroy;
     mlx5_devx_sq_create;
     mlx5_devx_sq_destroy;
 
Signature · 1 line
1.8.3.1
#22 lore raw

PATCH v3 18/19 net/mlx5: move Rx RQ creation to common

In reply to Michael Baum

Using common function for Rx RQ creation.

---
 drivers/net/mlx5/mlx5.h      |   4 +-
 drivers/net/mlx5/mlx5_devx.c | 177 +++++++++----------------------------------
 drivers/net/mlx5/mlx5_rxtx.h |   4 -
 3 files changed, 37 insertions(+), 148 deletions(-)
drivers/net/mlx5/mlx5.h +2 -2
index a3fd8d5..3836a96 100644
@@ -776,8 +776,9 @@ struct mlx5_rxq_obj {
 			void *ibv_cq; /* Completion Queue. */
 			void *ibv_channel;
 		};
+		struct mlx5_devx_obj *rq; /* DevX RQ object for hairpin. */
 		struct {
-			struct mlx5_devx_obj *rq; /* DevX Rx Queue object. */
+			struct mlx5_devx_rq rq_obj; /* DevX RQ object. */
 			struct mlx5_devx_cq cq_obj; /* DevX CQ object. */
 			void *devx_channel;
 		};
@@ -954,7 +955,6 @@ struct mlx5_priv {
 	/* Context for Verbs allocator. */
 	int nl_socket_rdma; /* Netlink socket (NETLINK_RDMA). */
 	int nl_socket_route; /* Netlink socket (NETLINK_ROUTE). */
-	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
 	struct mlx5_nl_vlan_vmwa_context *vmwa_context; /* VLAN WA context. */
 	struct mlx5_hlist *mreg_cp_tbl;
 	/* Hash table of Rx metadata register copy table. */
drivers/net/mlx5/mlx5_devx.c +35 -142

270 lines not on this page · raw message

drivers/net/mlx5/mlx5_rxtx.h +0 -4
index aba9541..7756ed3 100644
@@ -193,10 +193,6 @@ struct mlx5_rxq_ctrl {
 	uint32_t flow_tunnels_n[MLX5_FLOW_TUNNEL]; /* Tunnels counters. */
 	uint32_t wqn; /* WQ number. */
 	uint16_t dump_file_n; /* Number of dump files. */
-	struct mlx5_devx_dbr_page *rq_dbrec_page;
-	uint64_t rq_dbr_offset;
-	/* Storing RQ door-bell information, needed when freeing door-bell. */
-	void *wq_umem; /* WQ buffer registration info. */
 	struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
 	uint32_t hairpin_status; /* Hairpin binding status. */
 };
Signature · 1 line
1.8.3.1
#23 lore raw

PATCH v3 19/19 common/mlx5: remove doorbell allocation API

In reply to Michael Baum

The mlx5_devx_dbr_page structure was used to allocate and release the umem of the doorbells.
Since doorbell and buffer have used same umem, this structure is useless.

---
 drivers/common/mlx5/mlx5_common.c               | 122 ------------------------
 drivers/common/mlx5/mlx5_common.h               |  23 -----
 drivers/common/mlx5/rte_common_mlx5_exports.def |   3 -
 drivers/common/mlx5/version.map                 |   3 -
 4 files changed, 151 deletions(-)
drivers/common/mlx5/mlx5_common.c +0 -122
index a00ffcb..c26a2cf 100644
@@ -8,12 +8,10 @@
 
 #include <rte_errno.h>
 #include <rte_mempool.h>
-#include <rte_malloc.h>
 
 #include "mlx5_common.h"
 #include "mlx5_common_os.h"
 #include "mlx5_common_utils.h"
-#include "mlx5_malloc.h"
 #include "mlx5_common_pci.h"
 
 int mlx5_common_logtype;
@@ -126,126 +124,6 @@ static inline void mlx5_cpu_id(unsigned int level,
 }
 
 /**
- * Allocate page of door-bells and register it using DevX API.
- *
- * @param [in] ctx
- *   Pointer to the device context.
- *
- * @return
- *   Pointer to new page on success, NULL otherwise.
- */
-static struct mlx5_devx_dbr_page *
-mlx5_alloc_dbr_page(void *ctx)
-{
-	struct mlx5_devx_dbr_page *page;
-
-	/* Allocate space for door-bell page and management data. */
-	page = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
-			   sizeof(struct mlx5_devx_dbr_page),
-			   RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
-	if (!page) {
-		DRV_LOG(ERR, "cannot allocate dbr page");
-		return NULL;
-	}
-	/* Register allocated memory. */
-	page->umem = mlx5_os_umem_reg(ctx, page->dbrs,
-					      MLX5_DBR_PAGE_SIZE, 0);
-	if (!page->umem) {
-		DRV_LOG(ERR, "cannot umem reg dbr page");
-		mlx5_free(page);
-		return NULL;
-	}
-	return page;
-}
-
-/**
- * Find the next available door-bell, allocate new page if needed.
- *
- * @param [in] ctx
- *   Pointer to device context.
- * @param [in] head
- *   Pointer to the head of dbr pages list.
- * @param [out] dbr_page
- *   Door-bell page containing the page data.
- *
- * @return
- *   Door-bell address offset on success, a negative error value otherwise.
- */
-int64_t
-mlx5_get_dbr(void *ctx,  struct mlx5_dbr_page_list *head,
-	     struct mlx5_devx_dbr_page **dbr_page)
-{
-	struct mlx5_devx_dbr_page *page = NULL;
-	uint32_t i, j;
-
-	LIST_FOREACH(page, head, next)
-		if (page->dbr_count < MLX5_DBR_PER_PAGE)
-			break;
-	if (!page) { /* No page with free door-bell exists. */
-		page = mlx5_alloc_dbr_page(ctx);
-		if (!page) /* Failed to allocate new page. */
-			return (-1);
-		LIST_INSERT_HEAD(head, page, next);
-	}
-	/* Loop to find bitmap part with clear bit. */
-	for (i = 0;
-	     i < MLX5_DBR_BITMAP_SIZE && page->dbr_bitmap[i] == UINT64_MAX;
-	     i++)
-		; /* Empty. */
-	/* Find the first clear bit. */
-	MLX5_ASSERT(i < MLX5_DBR_BITMAP_SIZE);
-	j = rte_bsf64(~page->dbr_bitmap[i]);
-	page->dbr_bitmap[i] |= (UINT64_C(1) << j);
-	page->dbr_count++;
-	*dbr_page = page;
-	return (i * CHAR_BIT * sizeof(uint64_t) + j) * MLX5_DBR_SIZE;
-}
-
-/**
- * Release a door-bell record.
- *
- * @param [in] head
- *   Pointer to the head of dbr pages list.
- * @param [in] umem_id
- *   UMEM ID of page containing the door-bell record to release.
- * @param [in] offset
- *   Offset of door-bell record in page.
- *
- * @return
- *   0 on success, a negative error value otherwise.
- */
-int32_t
-mlx5_release_dbr(struct mlx5_dbr_page_list *head, uint32_t umem_id,
-		 uint64_t offset)
-{
-	struct mlx5_devx_dbr_page *page = NULL;
-	int ret = 0;
-
-	LIST_FOREACH(page, head, next)
-		/* Find the page this address belongs to. */
-		if (mlx5_os_get_umem_id(page->umem) == umem_id)
-			break;
-	if (!page)
-		return -EINVAL;
-	page->dbr_count--;
-	if (!page->dbr_count) {
-		/* Page not used, free it and remove from list. */
-		LIST_REMOVE(page, next);
-		if (page->umem)
-			ret = -mlx5_os_umem_dereg(page->umem);
-		mlx5_free(page);
-	} else {
-		/* Mark in bitmap that this door-bell is not in use. */
-		offset /= MLX5_DBR_SIZE;
-		int i = offset / 64;
-		int j = offset % 64;
-
-		page->dbr_bitmap[i] &= ~(UINT64_C(1) << j);
-	}
-	return ret;
-}
-
-/**
  * Allocate the User Access Region with DevX on specified device.
  *
  * @param [in] ctx
drivers/common/mlx5/mlx5_common.h +0 -23
index a484b74..e35188d 100644
@@ -220,21 +220,6 @@ enum mlx5_class {
 };
 
 #define MLX5_DBR_SIZE RTE_CACHE_LINE_SIZE
-#define MLX5_DBR_PER_PAGE 64
-/* Must be >= CHAR_BIT * sizeof(uint64_t) */
-#define MLX5_DBR_PAGE_SIZE (MLX5_DBR_PER_PAGE * MLX5_DBR_SIZE)
-/* Page size must be >= 512. */
-#define MLX5_DBR_BITMAP_SIZE (MLX5_DBR_PER_PAGE / (CHAR_BIT * sizeof(uint64_t)))
-
-struct mlx5_devx_dbr_page {
-	/* Door-bell records, must be first member in structure. */
-	uint8_t dbrs[MLX5_DBR_PAGE_SIZE];
-	LIST_ENTRY(mlx5_devx_dbr_page) next; /* Pointer to the next element. */
-	void *umem;
-	uint32_t dbr_count; /* Number of door-bell records in use. */
-	/* 1 bit marks matching door-bell is in use. */
-	uint64_t dbr_bitmap[MLX5_DBR_BITMAP_SIZE];
-};
 
 /* devX creation object */
 struct mlx5_devx_obj {
@@ -249,19 +234,11 @@ struct mlx5_klm {
 	uint64_t address;
 };
 
-LIST_HEAD(mlx5_dbr_page_list, mlx5_devx_dbr_page);
-
 __rte_internal
 void mlx5_translate_port_name(const char *port_name_in,
 			      struct mlx5_switch_info *port_info_out);
 void mlx5_glue_constructor(void);
 __rte_internal
-int64_t mlx5_get_dbr(void *ctx,  struct mlx5_dbr_page_list *head,
-		     struct mlx5_devx_dbr_page **dbr_page);
-__rte_internal
-int32_t mlx5_release_dbr(struct mlx5_dbr_page_list *head, uint32_t umem_id,
-			 uint64_t offset);
-__rte_internal
 void *mlx5_devx_alloc_uar(void *ctx, int mapping);
 extern uint8_t haswell_broadwell_cpu;
 
drivers/common/mlx5/rte_common_mlx5_exports.def +0 -3
index 6e1ff50..93bf4c4 100644
@@ -42,7 +42,6 @@ EXPORTS
     mlx5_devx_sq_create
     mlx5_devx_sq_destroy
 
-	mlx5_get_dbr
 	mlx5_glue
 
 	mlx5_malloc_mem_select
@@ -63,8 +62,6 @@ EXPORTS
 
 	mlx5_pci_driver_register
 
-	mlx5_release_dbr
-
 	mlx5_malloc
 	mlx5_realloc
 	mlx5_free
drivers/common/mlx5/version.map +0 -3
index dac9411..c666fdf 100644
@@ -51,7 +51,6 @@ INTERNAL {
     mlx5_devx_sq_destroy;
 
 	mlx5_get_ifname_sysfs;
-	mlx5_get_dbr;
 
 	mlx5_mp_init_primary;
 	mlx5_mp_uninit_primary;
@@ -93,8 +92,6 @@ INTERNAL {
 	mlx5_nl_vlan_vmwa_create;
 	mlx5_nl_vlan_vmwa_delete;
 
-	mlx5_release_dbr;
-
 	mlx5_translate_port_name;
 
 	mlx5_malloc_mem_select;
Signature · 1 line
1.8.3.1
#24 lore raw
In reply to Michael Baum

06/01/2021 09:19, Michael Baum:

Quoted 12 lines

Michael Baum (19):
common/mlx5: fix completion queue entry size configuration net/mlx5: remove CQE padding device argument net/mlx5: fix ASO SQ creation error flow common/mlx5: share DevX CQ creation
regex/mlx5: move DevX CQ creation to common vdpa/mlx5: move DevX CQ creation to common net/mlx5: move rearm and clock queue CQ creation to common net/mlx5: move ASO CQ creation to common net/mlx5: move Tx CQ creation to common net/mlx5: move Rx CQ creation to common common/mlx5: enhance page size configuration

Quoted 8 lines

common/mlx5: share DevX SQ creation
regex/mlx5: move DevX SQ creation to common net/mlx5: move rearm and clock queue SQ creation to common net/mlx5: move Tx SQ creation to common net/mlx5: move ASO SQ creation to common common/mlx5: share DevX RQ creation
net/mlx5: move Rx RQ creation to common common/mlx5: remove doorbell allocation API

Applied to next-net-mlx with indent fixed in symbol files (.map & .def), thanks.

#25 lore raw

PATCH v2 2/17 common/mlx5: share DevX CQ creation

In reply to Michael Baum

The CQ object in DevX is created in several places and in several different drivers.
In all places almost all the details are the same, and in particular the allocations of the required resources.

Add a structure that contains all the resources, and provide creation and release functions for it.

---
 drivers/common/mlx5/meson.build        |   1 +
 drivers/common/mlx5/mlx5_common_devx.c | 157 +++++++++++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h |  28 ++++++
 3 files changed, 186 insertions(+)
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.c
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.h
drivers/common/mlx5/meson.build +1 -0
index 3dacc6f..26cee06 100644
@@ -16,6 +16,7 @@ sources += files(
 	'mlx5_common_mr.c',
 	'mlx5_malloc.c',
 	'mlx5_common_pci.c',
+	'mlx5_common_devx.c',
 )
 
 cflags_options = [
drivers/common/mlx5/mlx5_common_devx.c new file +157 -0

157 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_devx.h new file +28 -0
new file mode 100644
index 0000000..31cb804
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 Mellanox Technologies, Ltd
+ */
+
+#ifndef RTE_PMD_MLX5_COMMON_DEVX_H_
+#define RTE_PMD_MLX5_COMMON_DEVX_H_
+
+#include "mlx5_devx_cmds.h"
+
+/* DevX Completion Queue structure. */
+struct mlx5_devx_cq {
+	struct mlx5_devx_obj *cq; /* The CQ DevX object. */
+	struct mlx5dv_devx_umem *umem_obj; /* The CQ umem object. */
+	union {
+		volatile void *umem_buf;
+		volatile struct mlx5_cqe *cqes; /* The CQ ring buffer. */
+	};
+	volatile uint32_t *db_rec; /* The CQ doorbell record. */
+};
+
+/* mlx5_common_devx.c */
+
+void mlx5_devx_cq_destroy(struct mlx5_devx_cq *cq);
+int mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj,
+			uint16_t log_desc_n, struct mlx5_devx_cq_attr *attr,
+			int socket);
+
+#endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */
Signature · 1 line
1.8.3.1
#26 lore raw

PATCH v2 3/17 regex/mlx5: move DevX CQ creation to common

In reply to Michael Baum

Using common function for DevX CQ creation.

---
 drivers/regex/mlx5/mlx5_regex.c          |  6 ---
 drivers/regex/mlx5/mlx5_regex.h          |  9 +---
 drivers/regex/mlx5/mlx5_regex_control.c  | 91 ++++++--------------------------
 drivers/regex/mlx5/mlx5_regex_fastpath.c |  4 +-
 4 files changed, 20 insertions(+), 90 deletions(-)
drivers/regex/mlx5/mlx5_regex.c +0 -6
index c91c444..c0d6331 100644
@@ -170,12 +170,6 @@
 		rte_errno = rte_errno ? rte_errno : EINVAL;
 		goto error;
 	}
-	ret = mlx5_glue->devx_query_eqn(ctx, 0, &priv->eqn);
-	if (ret) {
-		DRV_LOG(ERR, "can't query event queue number.");
-		rte_errno = ENOMEM;
-		goto error;
-	}
 	/*
 	 * This PMD always claims the write memory barrier on UAR
 	 * registers writings, it is safe to allocate UAR with any
drivers/regex/mlx5/mlx5_regex.h +2 -7
index 2c4877c..9f7a388 100644
@@ -12,6 +12,7 @@
 
 #include <mlx5_common.h>
 #include <mlx5_common_mr.h>
+#include <mlx5_common_devx.h>
 
 #include "mlx5_rxp.h"
 
@@ -30,13 +31,8 @@ struct mlx5_regex_sq {
 
 struct mlx5_regex_cq {
 	uint32_t log_nb_desc; /* Log 2 number of desc for this object. */
-	struct mlx5_devx_obj *obj; /* The CQ DevX object. */
-	int64_t dbr_offset; /* Door bell record offset. */
-	uint32_t dbr_umem; /* Door bell record umem id. */
-	volatile struct mlx5_cqe *cqe; /* The CQ ring buffer. */
-	struct mlx5dv_devx_umem *cqe_umem; /* CQ buffer umem. */
+	struct mlx5_devx_cq cq_obj; /* The CQ DevX object. */
 	size_t ci;
-	uint32_t *dbr;
 };
 
 struct mlx5_regex_qp {
@@ -75,7 +71,6 @@ struct mlx5_regex_priv {
 	struct mlx5_regex_db db[MLX5_RXP_MAX_ENGINES +
 				MLX5_RXP_EM_COUNT];
 	uint32_t nb_engines; /* Number of RegEx engines. */
-	uint32_t eqn; /* EQ number. */
 	struct mlx5dv_devx_uar *uar; /* UAR object. */
 	struct ibv_pd *pd;
 	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
drivers/regex/mlx5/mlx5_regex_control.c +16 -75

139 lines not on this page · raw message

drivers/regex/mlx5/mlx5_regex_fastpath.c +2 -2
index 5857617..255fd40 100644
@@ -224,7 +224,7 @@ struct mlx5_regex_job {
 	size_t next_cqe_offset;
 
 	next_cqe_offset =  (cq->ci & (cq_size_get(cq) - 1));
-	cqe = (volatile struct mlx5_cqe *)(cq->cqe + next_cqe_offset);
+	cqe = (volatile struct mlx5_cqe *)(cq->cq_obj.cqes + next_cqe_offset);
 	rte_io_wmb();
 
 	int ret = check_cqe(cqe, cq_size_get(cq), cq->ci);
@@ -285,7 +285,7 @@ struct mlx5_regex_job {
 		}
 		cq->ci = (cq->ci + 1) & 0xffffff;
 		rte_wmb();
-		cq->dbr[0] = rte_cpu_to_be_32(cq->ci);
+		cq->cq_obj.db_rec[0] = rte_cpu_to_be_32(cq->ci);
 		queue->free_sqs |= (1 << sqid);
 	}
 
Signature · 1 line
1.8.3.1
#27 lore raw

PATCH v2 4/17 vdpa/mlx5: move DevX CQ creation to common

In reply to Michael Baum

Using common function for DevX CQ creation.

---
 drivers/vdpa/mlx5/mlx5_vdpa.h       | 10 +----
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 81 +++++++++++--------------------------
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c |  2 +-
 3 files changed, 26 insertions(+), 67 deletions(-)
drivers/vdpa/mlx5/mlx5_vdpa.h +2 -8
index d039ada..ddee9dc 100644
@@ -22,6 +22,7 @@
 
 #include <mlx5_glue.h>
 #include <mlx5_devx_cmds.h>
+#include <mlx5_common_devx.h>
 #include <mlx5_prm.h>
 
 
@@ -46,13 +47,7 @@ struct mlx5_vdpa_cq {
 	uint32_t armed:1;
 	int callfd;
 	rte_spinlock_t sl;
-	struct mlx5_devx_obj *cq;
-	struct mlx5dv_devx_umem *umem_obj;
-	union {
-		volatile void *umem_buf;
-		volatile struct mlx5_cqe *cqes;
-	};
-	volatile uint32_t *db_rec;
+	struct mlx5_devx_cq cq_obj;
 	uint64_t errors;
 };
 
@@ -144,7 +139,6 @@ struct mlx5_vdpa_priv {
 	uint32_t gpa_mkey_index;
 	struct ibv_mr *null_mr;
 	struct rte_vhost_memory *vmem;
-	uint32_t eqn;
 	struct mlx5dv_devx_event_channel *eventc;
 	struct mlx5dv_devx_event_channel *err_chnl;
 	struct mlx5dv_devx_uar *uar;
drivers/vdpa/mlx5/mlx5_vdpa_event.c +23 -58

176 lines not on this page · raw message

drivers/vdpa/mlx5/mlx5_vdpa_virtq.c +1 -1
index 3e882e4..cc77314 100644
@@ -497,7 +497,7 @@
 		return -1;
 	if (vq.size != virtq->vq_size || vq.kickfd != virtq->intr_handle.fd)
 		return 1;
-	if (virtq->eqp.cq.cq) {
+	if (virtq->eqp.cq.cq_obj.cq) {
 		if (vq.callfd != virtq->eqp.cq.callfd)
 			return 1;
 	} else if (vq.callfd != -1) {
Signature · 1 line
1.8.3.1
#28 lore raw

PATCH v2 5/17 net/mlx5: move rearm and clock queue CQ creation to common

In reply to Michael Baum

Using common function for CQ creation at rearm queue and clock queue.

---
 drivers/net/mlx5/mlx5.h      |   9 +--
 drivers/net/mlx5/mlx5_rxtx.c |   2 +-
 drivers/net/mlx5/mlx5_txpp.c | 147 +++++++++++--------------------------------
 3 files changed, 40 insertions(+), 118 deletions(-)
drivers/net/mlx5/mlx5.h +2 -7
index 121d726..00ccaee 100644
@@ -26,6 +26,7 @@
 #include <mlx5_prm.h>
 #include <mlx5_common_mp.h>
 #include <mlx5_common_mr.h>
+#include <mlx5_common_devx.h>
 
 #include "mlx5_defs.h"
 #include "mlx5_utils.h"
@@ -612,13 +613,7 @@ struct mlx5_flow_id_pool {
 /* Tx pacing queue structure - for Clock and Rearm queues. */
 struct mlx5_txpp_wq {
 	/* Completion Queue related data.*/
-	struct mlx5_devx_obj *cq;
-	void *cq_umem;
-	union {
-		volatile void *cq_buf;
-		volatile struct mlx5_cqe *cqes;
-	};
-	volatile uint32_t *cq_dbrec;
+	struct mlx5_devx_cq cq_obj;
 	uint32_t cq_ci:24;
 	uint32_t arm_sn:2;
 	/* Send Queue related data.*/
drivers/net/mlx5/mlx5_rxtx.c +1 -1
index d12d746..dad24a3 100644
@@ -2277,7 +2277,7 @@ enum mlx5_txcmp_code {
 
 	qs = RTE_PTR_ADD(wqe, MLX5_WSEG_SIZE);
 	qs->max_index = rte_cpu_to_be_32(wci);
-	qs->qpn_cqn = rte_cpu_to_be_32(txq->sh->txpp.clock_queue.cq->id);
+	qs->qpn_cqn = rte_cpu_to_be_32(txq->sh->txpp.clock_queue.cq_obj.cq->id);
 	qs->reserved0 = RTE_BE32(0);
 	qs->reserved1 = RTE_BE32(0);
 }
drivers/net/mlx5/mlx5_txpp.c +37 -110

256 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#29 lore raw

PATCH v2 6/17 net/mlx5: move ASO CQ creation to common

In reply to Michael Baum

Use common function for ASO CQ creation.

---
 drivers/net/mlx5/mlx5.h          |  8 +---
 drivers/net/mlx5/mlx5_flow_age.c | 81 +++++++++-------------------------------
 2 files changed, 19 insertions(+), 70 deletions(-)
drivers/net/mlx5/mlx5.h +1 -7
index 00ccaee..e02faed 100644
@@ -463,13 +463,7 @@ struct mlx5_flow_counter_mng {
 struct mlx5_aso_cq {
 	uint16_t log_desc_n;
 	uint32_t cq_ci:24;
-	struct mlx5_devx_obj *cq;
-	struct mlx5dv_devx_umem *umem_obj;
-	union {
-		volatile void *umem_buf;
-		volatile struct mlx5_cqe *cqes;
-	};
-	volatile uint32_t *db_rec;
+	struct mlx5_devx_cq cq_obj;
 	uint64_t errors;
 };
 
drivers/net/mlx5/mlx5_flow_age.c +18 -63

167 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#30 lore raw

PATCH v2 7/17 net/mlx5: move Tx CQ creation to common

In reply to Michael Baum

Using common function for Tx CQ creation.

---
 drivers/net/mlx5/mlx5.h      |   6 +-
 drivers/net/mlx5/mlx5_devx.c | 182 +++++++------------------------------------
 2 files changed, 31 insertions(+), 157 deletions(-)
drivers/net/mlx5/mlx5.h +1 -5
index e02faed..2e75498 100644
@@ -843,11 +843,7 @@ struct mlx5_txq_obj {
 		};
 		struct {
 			struct rte_eth_dev *dev;
-			struct mlx5_devx_obj *cq_devx;
-			void *cq_umem;
-			void *cq_buf;
-			int64_t cq_dbrec_offset;
-			struct mlx5_devx_dbr_page *cq_dbrec_page;
+			struct mlx5_devx_cq cq_obj;
 			struct mlx5_devx_obj *sq_devx;
 			void *sq_umem;
 			void *sq_buf;
drivers/net/mlx5/mlx5_devx.c +30 -152

224 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#31 lore raw

PATCH v2 8/17 net/mlx5: move Rx CQ creation to common

In reply to Michael Baum

Using common function for Rx CQ creation.

---
 drivers/net/mlx5/mlx5.c      |   8 ---
 drivers/net/mlx5/mlx5.h      |   3 +-
 drivers/net/mlx5/mlx5_devx.c | 142 +++++++++++++------------------------------
 drivers/net/mlx5/mlx5_rxtx.h |   4 --
 4 files changed, 42 insertions(+), 115 deletions(-)
drivers/net/mlx5/mlx5.c +0 -8
index 52a8a25..3c7e5d2 100644
@@ -938,14 +938,6 @@ struct mlx5_dev_ctx_shared *
 		goto error;
 	}
 	if (sh->devx) {
-		/* Query the EQN for this core. */
-		err = mlx5_glue->devx_query_eqn(sh->ctx, 0, &sh->eqn);
-		if (err) {
-			rte_errno = errno;
-			DRV_LOG(ERR, "Failed to query event queue number %d.",
-				rte_errno);
-			goto error;
-		}
 		err = mlx5_os_get_pdn(sh->pd, &sh->pdn);
 		if (err) {
 			DRV_LOG(ERR, "Fail to extract pdn from PD");
drivers/net/mlx5/mlx5.h +1 -2
index 2e75498..9a59c26 100644
@@ -679,7 +679,6 @@ struct mlx5_dev_ctx_shared {
 	uint16_t bond_dev; /* Bond primary device id. */
 	uint32_t devx:1; /* Opened with DV. */
 	uint32_t flow_hit_aso_en:1; /* Flow Hit ASO is supported. */
-	uint32_t eqn; /* Event Queue number. */
 	uint32_t max_port; /* Maximal IB device port index. */
 	void *ctx; /* Verbs/DV/DevX context. */
 	void *pd; /* Protection Domain. */
@@ -787,7 +786,7 @@ struct mlx5_rxq_obj {
 		};
 		struct {
 			struct mlx5_devx_obj *rq; /* DevX Rx Queue object. */
-			struct mlx5_devx_obj *devx_cq; /* DevX CQ object. */
+			struct mlx5_devx_cq cq_obj; /* DevX CQ object. */
 			void *devx_channel;
 		};
 	};
drivers/net/mlx5/mlx5_devx.c +41 -101

221 lines not on this page · raw message

drivers/net/mlx5/mlx5_rxtx.h +0 -4
index 7989a50..6a71791 100644
@@ -196,11 +196,7 @@ struct mlx5_rxq_ctrl {
 	struct mlx5_devx_dbr_page *rq_dbrec_page;
 	uint64_t rq_dbr_offset;
 	/* Storing RQ door-bell information, needed when freeing door-bell. */
-	struct mlx5_devx_dbr_page *cq_dbrec_page;
-	uint64_t cq_dbr_offset;
-	/* Storing CQ door-bell information, needed when freeing door-bell. */
 	void *wq_umem; /* WQ buffer registration info. */
-	void *cq_umem; /* CQ buffer registration info. */
 	struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
 	uint32_t hairpin_status; /* Hairpin binding status. */
 };
Signature · 1 line
1.8.3.1
#32 lore raw

PATCH v2 9/17 common/mlx5: enhance page size configuration

In reply to Michael Baum

The PRM calculates page size in 4K, so need to reduce the log_wq_pg_sz attribute.

---
 drivers/common/mlx5/mlx5_devx_cmds.c | 53 ++++++++++++++++--------------------
 drivers/net/mlx5/mlx5_devx.c         | 13 +++++----
 2 files changed, 30 insertions(+), 36 deletions(-)
drivers/common/mlx5/mlx5_devx_cmds.c +23 -30
index 9c1d188..09e204b 100644
@@ -268,9 +268,8 @@ struct mlx5_devx_obj *
 	MLX5_SET(mkc, mkc, mkey_7_0, attr->umem_id & 0xFF);
 	MLX5_SET(mkc, mkc, translations_octword_size, translation_size);
 	MLX5_SET(mkc, mkc, relaxed_ordering_write,
-		attr->relaxed_ordering_write);
-	MLX5_SET(mkc, mkc, relaxed_ordering_read,
-		attr->relaxed_ordering_read);
+		 attr->relaxed_ordering_write);
+	MLX5_SET(mkc, mkc, relaxed_ordering_read, attr->relaxed_ordering_read);
 	MLX5_SET64(mkc, mkc, start_addr, attr->addr);
 	MLX5_SET64(mkc, mkc, len, attr->size);
 	mkey->obj = mlx5_glue->devx_obj_create(ctx, in, in_size_dw * 4, out,
@@ -308,7 +307,7 @@ struct mlx5_devx_obj *
 	if (status) {
 		int syndrome = MLX5_GET(query_flow_counter_out, out, syndrome);
 
-		DRV_LOG(ERR, "Bad devX status %x, syndrome = %x", status,
+		DRV_LOG(ERR, "Bad DevX status %x, syndrome = %x", status,
 			syndrome);
 	}
 	return status;
@@ -374,8 +373,7 @@ struct mlx5_devx_obj *
 	syndrome = MLX5_GET(query_nic_vport_context_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query NIC vport context, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		return -1;
 	}
 	vctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
@@ -662,8 +660,7 @@ struct mlx5_devx_obj *
 	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		return -1;
 	}
 	hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
@@ -683,11 +680,11 @@ struct mlx5_devx_obj *
 		(cmd_hca_cap, hcattr, log_min_hairpin_wq_data_sz);
 	attr->vhca_id = MLX5_GET(cmd_hca_cap, hcattr, vhca_id);
 	attr->relaxed_ordering_write = MLX5_GET(cmd_hca_cap, hcattr,
-			relaxed_ordering_write);
+						relaxed_ordering_write);
 	attr->relaxed_ordering_read = MLX5_GET(cmd_hca_cap, hcattr,
-			relaxed_ordering_read);
+					       relaxed_ordering_read);
 	attr->access_register_user = MLX5_GET(cmd_hca_cap, hcattr,
-			access_register_user);
+					      access_register_user);
 	attr->eth_net_offloads = MLX5_GET(cmd_hca_cap, hcattr,
 					  eth_net_offloads);
 	attr->eth_virt = MLX5_GET(cmd_hca_cap, hcattr, eth_virt);
@@ -730,8 +727,7 @@ struct mlx5_devx_obj *
 			goto error;
 		if (status) {
 			DRV_LOG(DEBUG, "Failed to query devx QOS capabilities,"
-				" status %x, syndrome = %x",
-				status, syndrome);
+				" status %x, syndrome = %x", status, syndrome);
 			return -1;
 		}
 		hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
@@ -761,17 +757,14 @@ struct mlx5_devx_obj *
 		 MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
 		 MLX5_HCA_CAP_OPMOD_GET_CUR);
 
-	rc = mlx5_glue->devx_general_cmd(ctx,
-					 in, sizeof(in),
-					 out, sizeof(out));
+	rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out));
 	if (rc)
 		goto error;
 	status = MLX5_GET(query_hca_cap_out, out, status);
 	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		attr->log_max_ft_sampler_num = 0;
 		return -1;
 	}
@@ -788,9 +781,7 @@ struct mlx5_devx_obj *
 		 MLX5_GET_HCA_CAP_OP_MOD_ETHERNET_OFFLOAD_CAPS |
 		 MLX5_HCA_CAP_OPMOD_GET_CUR);
 
-	rc = mlx5_glue->devx_general_cmd(ctx,
-					 in, sizeof(in),
-					 out, sizeof(out));
+	rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out));
 	if (rc) {
 		attr->eth_net_offloads = 0;
 		goto error;
@@ -799,8 +790,7 @@ struct mlx5_devx_obj *
 	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		attr->eth_net_offloads = 0;
 		return -1;
 	}
@@ -916,7 +906,9 @@ struct mlx5_devx_obj *
 	MLX5_SET(wq, wq_ctx, hw_counter, wq_attr->hw_counter);
 	MLX5_SET(wq, wq_ctx, sw_counter, wq_attr->sw_counter);
 	MLX5_SET(wq, wq_ctx, log_wq_stride, wq_attr->log_wq_stride);
-	MLX5_SET(wq, wq_ctx, log_wq_pg_sz, wq_attr->log_wq_pg_sz);
+	if (wq_attr->log_wq_pg_sz > MLX5_ADAPTER_PAGE_SHIFT)
+		MLX5_SET(wq, wq_ctx, log_wq_pg_sz,
+			 wq_attr->log_wq_pg_sz - MLX5_ADAPTER_PAGE_SHIFT);
 	MLX5_SET(wq, wq_ctx, log_wq_sz, wq_attr->log_wq_sz);
 	MLX5_SET(wq, wq_ctx, dbr_umem_valid, wq_attr->dbr_umem_valid);
 	MLX5_SET(wq, wq_ctx, wq_umem_valid, wq_attr->wq_umem_valid);
@@ -1562,13 +1554,13 @@ struct mlx5_devx_obj *
 	MLX5_SET(cqc, cqctx, cc, attr->use_first_only);
 	MLX5_SET(cqc, cqctx, oi, attr->overrun_ignore);
 	MLX5_SET(cqc, cqctx, log_cq_size, attr->log_cq_size);
-	MLX5_SET(cqc, cqctx, log_page_size, attr->log_page_size -
-		 MLX5_ADAPTER_PAGE_SHIFT);
+	if (attr->log_page_size > MLX5_ADAPTER_PAGE_SHIFT)
+		MLX5_SET(cqc, cqctx, log_page_size,
+			 attr->log_page_size - MLX5_ADAPTER_PAGE_SHIFT);
 	MLX5_SET(cqc, cqctx, c_eqn, attr->eqn);
 	MLX5_SET(cqc, cqctx, uar_page, attr->uar_page_id);
 	MLX5_SET(cqc, cqctx, cqe_comp_en, !!attr->cqe_comp_en);
-	MLX5_SET(cqc, cqctx, mini_cqe_res_format,
-		 attr->mini_cqe_res_format);
+	MLX5_SET(cqc, cqctx, mini_cqe_res_format, attr->mini_cqe_res_format);
 	MLX5_SET(cqc, cqctx, mini_cqe_res_format_ext,
 		 attr->mini_cqe_res_format_ext);
 	MLX5_SET(cqc, cqctx, cqe_sz, attr->cqe_size);
@@ -1798,8 +1790,9 @@ struct mlx5_devx_obj *
 	if (attr->uar_index) {
 		MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED);
 		MLX5_SET(qpc, qpc, uar_page, attr->uar_index);
-		MLX5_SET(qpc, qpc, log_page_size, attr->log_page_size -
-			 MLX5_ADAPTER_PAGE_SHIFT);
+		if (attr->log_page_size > MLX5_ADAPTER_PAGE_SHIFT)
+			MLX5_SET(qpc, qpc, log_page_size,
+				 attr->log_page_size - MLX5_ADAPTER_PAGE_SHIFT);
 		if (attr->sq_size) {
 			MLX5_ASSERT(RTE_IS_POWER_OF_2(attr->sq_size));
 			MLX5_SET(qpc, qpc, cqn_snd, attr->cqn);
drivers/net/mlx5/mlx5_devx.c +7 -6
index 6ad70f2..fe103a7 100644
@@ -320,7 +320,13 @@
 	uint32_t log_wqe_size = 0;
 	void *buf = NULL;
 	struct mlx5_devx_obj *rq;
+	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
 
+	if (alignment == (size_t)-1) {
+		DRV_LOG(ERR, "Failed to get mem page size");
+		rte_errno = ENOMEM;
+		return NULL;
+	}
 	/* Fill RQ attributes. */
 	rq_attr.mem_rq_type = MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE;
 	rq_attr.flush_in_error_en = 1;
@@ -347,15 +353,10 @@
 	log_wqe_size = log2above(wqe_size) + rxq_data->sges_n;
 	rq_attr.wq_attr.log_wq_stride = log_wqe_size;
 	rq_attr.wq_attr.log_wq_sz = rxq_data->elts_n - rxq_data->sges_n;
+	rq_attr.wq_attr.log_wq_pg_sz = log2above(alignment);
 	/* Calculate and allocate WQ memory space. */
 	wqe_size = 1 << log_wqe_size; /* round up power of two.*/
 	wq_size = wqe_n * wqe_size;
-	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
-	if (alignment == (size_t)-1) {
-		DRV_LOG(ERR, "Failed to get mem page size");
-		rte_errno = ENOMEM;
-		return NULL;
-	}
 	buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, wq_size,
 			  alignment, rxq_ctrl->socket);
 	if (!buf)
Signature · 1 line
1.8.3.1
#33 lore raw

PATCH v2 10/17 common/mlx5: share DevX SQ creation

In reply to Michael Baum

The SQ object in DevX is created in several places and in several different drivers.
In all places almost all the details are the same, and in particular the allocations of the required resources.

Add a structure that contains all the resources, and provide creation and release functions for it.

---
 drivers/common/mlx5/mlx5_common_devx.c | 122 +++++++++++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h |  20 +++++-
 2 files changed, 140 insertions(+), 2 deletions(-)
drivers/common/mlx5/mlx5_common_devx.c +122 -0
index 324c6ea..652bc9a 100644
@@ -155,3 +155,125 @@
 	rte_errno = ret;
 	return -rte_errno;
 }
+
+/**
+ * Destroy DevX Send Queue.
+ *
+ * @param[in] sq
+ *   DevX SQ to destroy.
+ */
+void
+mlx5_devx_sq_destroy(struct mlx5_devx_sq *sq)
+{
+	if (sq->sq)
+		claim_zero(mlx5_devx_cmd_destroy(sq->sq));
+	if (sq->umem_obj)
+		claim_zero(mlx5_glue->devx_umem_dereg(sq->umem_obj));
+	if (sq->umem_buf)
+		mlx5_free((void *)(uintptr_t)sq->umem_buf);
+}
+
+/**
+ * Create Send Queue using DevX API.
+ *
+ * Get a pointer to partially initialized attributes structure, and updates the
+ * following fields:
+ *   wq_type
+ *   wq_umem_valid
+ *   wq_umem_id
+ *   wq_umem_offset
+ *   dbr_umem_valid
+ *   dbr_umem_id
+ *   dbr_addr
+ *   log_wq_stride
+ *   log_wq_sz
+ *   log_wq_pg_sz
+ * All other fields are updated by caller.
+ *
+ * @param[in] ctx
+ *   Context returned from mlx5 open_device() glue function.
+ * @param[in/out] sq_obj
+ *   Pointer to SQ to create.
+ * @param[in] log_wqbb_n
+ *   Log of number of WQBBs in queue.
+ * @param[in] attr
+ *   Pointer to SQ attributes structure.
+ * @param[in] socket
+ *   Socket to use for allocation.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj, uint16_t log_wqbb_n,
+		    struct mlx5_devx_create_sq_attr *attr, int socket)
+{
+	struct mlx5_devx_obj *sq = NULL;
+	struct mlx5dv_devx_umem *umem_obj = NULL;
+	void *umem_buf = NULL;
+	size_t page_size = rte_mem_page_size();
+	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
+	uint32_t umem_size, umem_dbrec;
+	uint16_t sq_size = 1 << log_wqbb_n;
+	int ret;
+
+	if (page_size == (size_t)-1 || alignment == (size_t)-1) {
+		DRV_LOG(ERR, "Failed to get page_size.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Allocate memory buffer for WQEs and doorbell record. */
+	umem_size = MLX5_WQE_SIZE * sq_size;
+	umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE);
+	umem_size += MLX5_DBR_SIZE;
+	umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size,
+			       alignment, socket);
+	if (!umem_buf) {
+		DRV_LOG(ERR, "Failed to allocate memory for SQ.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Register allocated buffer in user space with DevX. */
+	umem_obj = mlx5_glue->devx_umem_reg(ctx, (void *)(uintptr_t)umem_buf,
+					    umem_size, IBV_ACCESS_LOCAL_WRITE);
+	if (!umem_obj) {
+		DRV_LOG(ERR, "Failed to register umem for SQ.");
+		rte_errno = errno;
+		goto error;
+	}
+	/* Fill attributes for SQ object creation. */
+	attr->wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
+	attr->wq_attr.wq_umem_valid = 1;
+	attr->wq_attr.wq_umem_id = mlx5_os_get_umem_id(umem_obj);
+	attr->wq_attr.wq_umem_offset = 0;
+	attr->wq_attr.dbr_umem_valid = 1;
+	attr->wq_attr.dbr_umem_id = attr->wq_attr.wq_umem_id;
+	attr->wq_attr.dbr_addr = umem_dbrec;
+	attr->wq_attr.log_wq_stride = rte_log2_u32(MLX5_WQE_SIZE);
+	attr->wq_attr.log_wq_sz = log_wqbb_n;
+	attr->wq_attr.log_wq_pg_sz = rte_log2_u32(page_size);
+	/* Create send queue object with DevX. */
+	sq = mlx5_devx_cmd_create_sq(ctx, attr);
+	if (!sq) {
+		DRV_LOG(ERR, "Can't create DevX SQ object.");
+		rte_errno = ENOMEM;
+		goto error;
+	}
+	sq_obj->umem_buf = umem_buf;
+	sq_obj->umem_obj = umem_obj;
+	sq_obj->sq = sq;
+	sq_obj->db_rec = RTE_PTR_ADD(sq_obj->umem_buf, umem_dbrec);
+	return 0;
+error:
+	ret = rte_errno;
+	if (sq)
+		claim_zero(mlx5_devx_cmd_destroy(sq));
+	if (umem_obj)
+		claim_zero(mlx5_glue->devx_umem_dereg(umem_obj));
+	if (umem_buf)
+		mlx5_free((void *)(uintptr_t)umem_buf);
+	rte_errno = ret;
+	return -rte_errno;
+}
+
+
drivers/common/mlx5/mlx5_common_devx.h +18 -2
index 31cb804..88d520b 100644
@@ -18,11 +18,27 @@ struct mlx5_devx_cq {
 	volatile uint32_t *db_rec; /* The CQ doorbell record. */
 };
 
+/* DevX Send Queue structure. */
+struct mlx5_devx_sq {
+	struct mlx5_devx_obj *sq; /* The SQ DevX object. */
+	struct mlx5dv_devx_umem *umem_obj; /* The SQ umem object. */
+	union {
+		volatile void *umem_buf;
+		volatile struct mlx5_wqe *wqes; /* The SQ ring buffer. */
+	};
+	volatile uint32_t *db_rec; /* The SQ doorbell record. */
+};
+
+
 /* mlx5_common_devx.c */
 
 void mlx5_devx_cq_destroy(struct mlx5_devx_cq *cq);
 int mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj,
-			uint16_t log_desc_n, struct mlx5_devx_cq_attr *attr,
-			int socket);
+			uint16_t log_desc_n,
+			struct mlx5_devx_cq_attr *attr, int socket);
+void mlx5_devx_sq_destroy(struct mlx5_devx_sq *sq);
+int mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj,
+			uint16_t log_wqbb_n,
+			struct mlx5_devx_create_sq_attr *attr, int socket);
 
 #endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */
Signature · 1 line
1.8.3.1
#34 lore raw

PATCH v2 11/17 regex/mlx5: move DevX SQ creation to common

In reply to Michael Baum

Using common function for DevX SQ creation.

---
 drivers/regex/mlx5/mlx5_regex.h          |   8 +-
 drivers/regex/mlx5/mlx5_regex_control.c  | 153 ++++++++++---------------------
 drivers/regex/mlx5/mlx5_regex_fastpath.c |  14 +--
 3 files changed, 55 insertions(+), 120 deletions(-)
drivers/regex/mlx5/mlx5_regex.h +1 -7
index 9f7a388..7e1b2a9 100644
@@ -18,15 +18,10 @@
 
 struct mlx5_regex_sq {
 	uint16_t log_nb_desc; /* Log 2 number of desc for this object. */
-	struct mlx5_devx_obj *obj; /* The SQ DevX object. */
-	int64_t dbr_offset; /* Door bell record offset. */
-	uint32_t dbr_umem; /* Door bell record umem id. */
-	uint8_t *wqe; /* The SQ ring buffer. */
-	struct mlx5dv_devx_umem *wqe_umem; /* SQ buffer umem. */
+	struct mlx5_devx_sq sq_obj; /* The SQ DevX object. */
 	size_t pi, db_pi;
 	size_t ci;
 	uint32_t sqn;
-	uint32_t *dbr;
 };
 
 struct mlx5_regex_cq {
@@ -73,7 +68,6 @@ struct mlx5_regex_priv {
 	uint32_t nb_engines; /* Number of RegEx engines. */
 	struct mlx5dv_devx_uar *uar; /* UAR object. */
 	struct ibv_pd *pd;
-	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
 	struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. */
 };
 
drivers/regex/mlx5/mlx5_regex_control.c +47 -106

188 lines not on this page · raw message

drivers/regex/mlx5/mlx5_regex_fastpath.c +7 -7
index 255fd40..cd0f9bd 100644
@@ -110,12 +110,12 @@ struct mlx5_regex_job {
 				  &priv->mr_scache, &qp->mr_ctrl,
 				  rte_pktmbuf_mtod(op->mbuf, uintptr_t),
 				  !!(op->mbuf->ol_flags & EXT_ATTACHED_MBUF));
-	uint8_t *wqe = (uint8_t *)sq->wqe + wqe_offset;
+	uint8_t *wqe = (uint8_t *)(uintptr_t)sq->sq_obj.wqes + wqe_offset;
 	int ds = 4; /*  ctrl + meta + input + output */
 
 	set_wqe_ctrl_seg((struct mlx5_wqe_ctrl_seg *)wqe, sq->pi,
-			 MLX5_OPCODE_MMO, MLX5_OPC_MOD_MMO_REGEX, sq->obj->id,
-			 0, ds, 0, 0);
+			 MLX5_OPCODE_MMO, MLX5_OPC_MOD_MMO_REGEX,
+			 sq->sq_obj.sq->id, 0, ds, 0, 0);
 	set_regex_ctrl_seg(wqe + 12, 0, op->group_id0, op->group_id1,
 			   op->group_id2,
 			   op->group_id3, 0);
@@ -137,12 +137,12 @@ struct mlx5_regex_job {
 {
 	size_t wqe_offset = (sq->db_pi & (sq_size_get(sq) - 1)) *
 		MLX5_SEND_WQE_BB;
-	uint8_t *wqe = (uint8_t *)sq->wqe + wqe_offset;
+	uint8_t *wqe = (uint8_t *)(uintptr_t)sq->sq_obj.wqes + wqe_offset;
 	((struct mlx5_wqe_ctrl_seg *)wqe)->fm_ce_se = MLX5_WQE_CTRL_CQ_UPDATE;
 	uint64_t *doorbell_addr =
 		(uint64_t *)((uint8_t *)uar->base_addr + 0x800);
 	rte_io_wmb();
-	sq->dbr[MLX5_SND_DBR] = rte_cpu_to_be_32((sq->db_pi + 1) &
+	sq->sq_obj.db_rec[MLX5_SND_DBR] = rte_cpu_to_be_32((sq->db_pi + 1) &
 						 MLX5_REGEX_MAX_WQE_INDEX);
 	rte_wmb();
 	*doorbell_addr = *(volatile uint64_t *)wqe;
@@ -301,7 +301,7 @@ struct mlx5_regex_job {
 	uint32_t job_id;
 	for (sqid = 0; sqid < queue->nb_obj; sqid++) {
 		struct mlx5_regex_sq *sq = &queue->sqs[sqid];
-		uint8_t *wqe = (uint8_t *)sq->wqe;
+		uint8_t *wqe = (uint8_t *)(uintptr_t)sq->sq_obj.wqes;
 		for (entry = 0 ; entry < sq_size_get(sq); entry++) {
 			job_id = sqid * sq_size_get(sq) + entry;
 			struct mlx5_regex_job *job = &queue->jobs[job_id];
@@ -334,7 +334,7 @@ struct mlx5_regex_job {
 		return -ENOMEM;
 
 	qp->metadata = mlx5_glue->reg_mr(pd, ptr,
-					 MLX5_REGEX_METADATA_SIZE*qp->nb_desc,
+					 MLX5_REGEX_METADATA_SIZE * qp->nb_desc,
 					 IBV_ACCESS_LOCAL_WRITE);
 	if (!qp->metadata) {
 		DRV_LOG(ERR, "Failed to register metadata");
Signature · 1 line
1.8.3.1
#35 lore raw

PATCH v2 12/17 net/mlx5: move rearm and clock queue SQ creation to common

In reply to Michael Baum

Using common function for DevX SQ creation for rearm and clock queue.

---
 drivers/net/mlx5/mlx5.h      |   8 +--
 drivers/net/mlx5/mlx5_txpp.c | 147 +++++++++++--------------------------------
 2 files changed, 36 insertions(+), 119 deletions(-)
drivers/net/mlx5/mlx5.h +1 -7
index 9a59c26..192a5a7 100644
@@ -611,15 +611,9 @@ struct mlx5_txpp_wq {
 	uint32_t cq_ci:24;
 	uint32_t arm_sn:2;
 	/* Send Queue related data.*/
-	struct mlx5_devx_obj *sq;
-	void *sq_umem;
-	union {
-		volatile void *sq_buf;
-		volatile struct mlx5_wqe *wqes;
-	};
+	struct mlx5_devx_sq sq_obj;
 	uint16_t sq_size; /* Number of WQEs in the queue. */
 	uint16_t sq_ci; /* Next WQE to execute. */
-	volatile uint32_t *sq_dbrec;
 };
 
 /* Tx packet pacing internal timestamp. */
drivers/net/mlx5/mlx5_txpp.c +35 -112

276 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#36 lore raw

PATCH v2 13/17 net/mlx5: move Tx SQ creation to common

In reply to Michael Baum

Using common function for Tx SQ creation.

---
 drivers/net/mlx5/mlx5.h      |   8 +--
 drivers/net/mlx5/mlx5_devx.c | 160 ++++++++++---------------------------------
 2 files changed, 40 insertions(+), 128 deletions(-)
drivers/net/mlx5/mlx5.h +3 -5
index 192a5a7..6977eac 100644
@@ -837,11 +837,9 @@ struct mlx5_txq_obj {
 		struct {
 			struct rte_eth_dev *dev;
 			struct mlx5_devx_cq cq_obj;
-			struct mlx5_devx_obj *sq_devx;
-			void *sq_umem;
-			void *sq_buf;
-			int64_t sq_dbrec_offset;
-			struct mlx5_devx_dbr_page *sq_dbrec_page;
+			/* DevX CQ object and its resources. */
+			struct mlx5_devx_sq sq_obj;
+			/* DevX SQ object and its resources. */
 		};
 	};
 };
drivers/net/mlx5/mlx5_devx.c +37 -123

221 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#37 lore raw

PATCH v2 14/17 net/mlx5: move ASO SQ creation to common

In reply to Michael Baum

Using common function for ASO SQ creation.

---
 drivers/common/mlx5/mlx5_common_devx.h |  1 +
 drivers/net/mlx5/mlx5.h                |  8 +--
 drivers/net/mlx5/mlx5_flow_age.c       | 94 ++++++++++------------------------
 3 files changed, 30 insertions(+), 73 deletions(-)
drivers/common/mlx5/mlx5_common_devx.h +1 -0
index 88d520b..8377d34 100644
@@ -25,6 +25,7 @@ struct mlx5_devx_sq {
 	union {
 		volatile void *umem_buf;
 		volatile struct mlx5_wqe *wqes; /* The SQ ring buffer. */
+		volatile struct mlx5_aso_wqe *aso_wqes;
 	};
 	volatile uint32_t *db_rec; /* The SQ doorbell record. */
 };
drivers/net/mlx5/mlx5.h +1 -7
index 6977eac..86ada23 100644
@@ -483,13 +483,7 @@ struct mlx5_aso_sq_elem {
 struct mlx5_aso_sq {
 	uint16_t log_desc_n;
 	struct mlx5_aso_cq cq;
-	struct mlx5_devx_obj *sq;
-	struct mlx5dv_devx_umem *wqe_umem; /* SQ buffer umem. */
-	union {
-		volatile void *umem_buf;
-		volatile struct mlx5_aso_wqe *wqes;
-	};
-	volatile uint32_t *db_rec;
+	struct mlx5_devx_sq sq_obj;
 	volatile uint64_t *uar_addr;
 	struct mlx5_aso_devx_mr mr;
 	uint16_t pi;
drivers/net/mlx5/mlx5_flow_age.c +28 -66

152 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#38 lore raw

PATCH v2 15/17 common/mlx5: share DevX RQ creation

In reply to Michael Baum

The RQ object in DevX is used currently only in net driver, but it share for future.

Add a structure that contains all the resources, and provide creation and release functions for it.

---
 drivers/common/mlx5/mlx5_common_devx.c | 116 +++++++++++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h |  11 ++++
 2 files changed, 127 insertions(+)
drivers/common/mlx5/mlx5_common_devx.c +116 -0
index 652bc9a..a66b838 100644
@@ -276,4 +276,120 @@
 	return -rte_errno;
 }
 
+/**
+ * Destroy DevX Receive Queue.
+ *
+ * @param[in] rq
+ *   DevX RQ to destroy.
+ */
+void
+mlx5_devx_rq_destroy(struct mlx5_devx_rq *rq)
+{
+	if (rq->rq)
+		claim_zero(mlx5_devx_cmd_destroy(rq->rq));
+	if (rq->umem_obj)
+		claim_zero(mlx5_glue->devx_umem_dereg(rq->umem_obj));
+	if (rq->umem_buf)
+		mlx5_free((void *)(uintptr_t)rq->umem_buf);
+}
+
+/**
+ * Create Receive Queue using DevX API.
+ *
+ * Get a pointer to partially initialized attributes structure, and updates the
+ * following fields:
+ *   wq_umem_valid
+ *   wq_umem_id
+ *   wq_umem_offset
+ *   dbr_umem_valid
+ *   dbr_umem_id
+ *   dbr_addr
+ *   log_wq_pg_sz
+ * All other fields are updated by caller.
+ *
+ * @param[in] ctx
+ *   Context returned from mlx5 open_device() glue function.
+ * @param[in/out] rq_obj
+ *   Pointer to RQ to create.
+ * @param[in] wqe_size
+ *   Size of WQE structure.
+ * @param[in] log_wqbb_n
+ *   Log of number of WQBBs in queue.
+ * @param[in] attr
+ *   Pointer to RQ attributes structure.
+ * @param[in] socket
+ *   Socket to use for allocation.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_devx_rq_create(void *ctx, struct mlx5_devx_rq *rq_obj, uint32_t wqe_size,
+		    uint16_t log_wqbb_n,
+		    struct mlx5_devx_create_rq_attr *attr, int socket)
+{
+	struct mlx5_devx_obj *rq = NULL;
+	struct mlx5dv_devx_umem *umem_obj = NULL;
+	void *umem_buf = NULL;
+	size_t page_size = rte_mem_page_size();
+	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
+	uint32_t umem_size, umem_dbrec;
+	uint16_t rq_size = 1 << log_wqbb_n;
+	int ret;
+
+	if (page_size == (size_t)-1 || alignment == (size_t)-1) {
+		DRV_LOG(ERR, "Failed to get page_size.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Allocate memory buffer for WQEs and doorbell record. */
+	umem_size = wqe_size * rq_size;
+	umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE);
+	umem_size += MLX5_DBR_SIZE;
+	umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size,
+			       alignment, socket);
+	if (!umem_buf) {
+		DRV_LOG(ERR, "Failed to allocate memory for RQ.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Register allocated buffer in user space with DevX. */
+	umem_obj = mlx5_glue->devx_umem_reg(ctx, (void *)(uintptr_t)umem_buf,
+					    umem_size, 0);
+	if (!umem_obj) {
+		DRV_LOG(ERR, "Failed to register umem for RQ.");
+		rte_errno = errno;
+		goto error;
+	}
+	/* Fill attributes for RQ object creation. */
+	attr->wq_attr.wq_umem_valid = 1;
+	attr->wq_attr.wq_umem_id = mlx5_os_get_umem_id(umem_obj);
+	attr->wq_attr.wq_umem_offset = 0;
+	attr->wq_attr.dbr_umem_valid = 1;
+	attr->wq_attr.dbr_umem_id = attr->wq_attr.wq_umem_id;
+	attr->wq_attr.dbr_addr = umem_dbrec;
+	attr->wq_attr.log_wq_pg_sz = rte_log2_u32(page_size);
+	/* Create receive queue object with DevX. */
+	rq = mlx5_devx_cmd_create_rq(ctx, attr, socket);
+	if (!rq) {
+		DRV_LOG(ERR, "Can't create DevX RQ object.");
+		rte_errno = ENOMEM;
+		goto error;
+	}
+	rq_obj->umem_buf = umem_buf;
+	rq_obj->umem_obj = umem_obj;
+	rq_obj->rq = rq;
+	rq_obj->db_rec = RTE_PTR_ADD(rq_obj->umem_buf, umem_dbrec);
+	return 0;
+error:
+	ret = rte_errno;
+	if (rq)
+		claim_zero(mlx5_devx_cmd_destroy(rq));
+	if (umem_obj)
+		claim_zero(mlx5_glue->devx_umem_dereg(umem_obj));
+	if (umem_buf)
+		mlx5_free((void *)(uintptr_t)umem_buf);
+	rte_errno = ret;
+	return -rte_errno;
+}
 
drivers/common/mlx5/mlx5_common_devx.h +11 -0
index 8377d34..1dafbf5 100644
@@ -30,6 +30,13 @@ struct mlx5_devx_sq {
 	volatile uint32_t *db_rec; /* The SQ doorbell record. */
 };
 
+/* DevX Receive Queue structure. */
+struct mlx5_devx_rq {
+	struct mlx5_devx_obj *rq; /* The RQ DevX object. */
+	struct mlx5dv_devx_umem *umem_obj; /* The RQ umem object. */
+	volatile void *umem_buf;
+	volatile uint32_t *db_rec; /* The RQ doorbell record. */
+};
 
 /* mlx5_common_devx.c */
 
@@ -41,5 +48,9 @@ int mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj,
 int mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj,
 			uint16_t log_wqbb_n,
 			struct mlx5_devx_create_sq_attr *attr, int socket);
+void mlx5_devx_rq_destroy(struct mlx5_devx_rq *rq);
+int mlx5_devx_rq_create(void *ctx, struct mlx5_devx_rq *rq_obj,
+			uint32_t wqe_size, uint16_t log_wqbb_n,
+			struct mlx5_devx_create_rq_attr *attr, int socket);
 
 #endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */
Signature · 1 line
1.8.3.1
#39 lore raw

PATCH v2 16/17 net/mlx5: move Rx RQ creation to common

In reply to Michael Baum

Using common function for Rx RQ creation.

---
 drivers/net/mlx5/mlx5.h      |   4 +-
 drivers/net/mlx5/mlx5_devx.c | 178 +++++++++----------------------------------
 drivers/net/mlx5/mlx5_rxtx.h |   4 -
 3 files changed, 37 insertions(+), 149 deletions(-)
drivers/net/mlx5/mlx5.h +2 -2
index 86ada23..5bf6886 100644
@@ -772,8 +772,9 @@ struct mlx5_rxq_obj {
 			void *ibv_cq; /* Completion Queue. */
 			void *ibv_channel;
 		};
+		struct mlx5_devx_obj *rq; /* DevX RQ object for hairpin. */
 		struct {
-			struct mlx5_devx_obj *rq; /* DevX Rx Queue object. */
+			struct mlx5_devx_rq rq_obj; /* DevX RQ object. */
 			struct mlx5_devx_cq cq_obj; /* DevX CQ object. */
 			void *devx_channel;
 		};
@@ -944,7 +945,6 @@ struct mlx5_priv {
 	/* Context for Verbs allocator. */
 	int nl_socket_rdma; /* Netlink socket (NETLINK_RDMA). */
 	int nl_socket_route; /* Netlink socket (NETLINK_ROUTE). */
-	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
 	struct mlx5_nl_vlan_vmwa_context *vmwa_context; /* VLAN WA context. */
 	struct mlx5_hlist *mreg_cp_tbl;
 	/* Hash table of Rx metadata register copy table. */
drivers/net/mlx5/mlx5_devx.c +35 -143

271 lines not on this page · raw message

drivers/net/mlx5/mlx5_rxtx.h +0 -4
index 6a71791..b0041c9 100644
@@ -193,10 +193,6 @@ struct mlx5_rxq_ctrl {
 	uint32_t flow_tunnels_n[MLX5_FLOW_TUNNEL]; /* Tunnels counters. */
 	uint32_t wqn; /* WQ number. */
 	uint16_t dump_file_n; /* Number of dump files. */
-	struct mlx5_devx_dbr_page *rq_dbrec_page;
-	uint64_t rq_dbr_offset;
-	/* Storing RQ door-bell information, needed when freeing door-bell. */
-	void *wq_umem; /* WQ buffer registration info. */
 	struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
 	uint32_t hairpin_status; /* Hairpin binding status. */
 };
Signature · 1 line
1.8.3.1
#40 lore raw

PATCH v2 17/17 common/mlx5: remove doorbell allocation API

In reply to Michael Baum

The mlx5_devx_dbr_page structure was used to allocate and release the umem of the doorbells.
Since doorbell and buffer have used same umem, this structure is useless.

---
 drivers/common/mlx5/mlx5_common.c | 122 --------------------------------------
 drivers/common/mlx5/mlx5_common.h |  23 -------
 2 files changed, 145 deletions(-)
drivers/common/mlx5/mlx5_common.c +0 -122
index 0445132..c26a2cf 100644
@@ -8,12 +8,10 @@
 
 #include <rte_errno.h>
 #include <rte_mempool.h>
-#include <rte_malloc.h>
 
 #include "mlx5_common.h"
 #include "mlx5_common_os.h"
 #include "mlx5_common_utils.h"
-#include "mlx5_malloc.h"
 #include "mlx5_common_pci.h"
 
 int mlx5_common_logtype;
@@ -126,126 +124,6 @@ static inline void mlx5_cpu_id(unsigned int level,
 }
 
 /**
- * Allocate page of door-bells and register it using DevX API.
- *
- * @param [in] ctx
- *   Pointer to the device context.
- *
- * @return
- *   Pointer to new page on success, NULL otherwise.
- */
-static struct mlx5_devx_dbr_page *
-mlx5_alloc_dbr_page(void *ctx)
-{
-	struct mlx5_devx_dbr_page *page;
-
-	/* Allocate space for door-bell page and management data. */
-	page = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
-			   sizeof(struct mlx5_devx_dbr_page),
-			   RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
-	if (!page) {
-		DRV_LOG(ERR, "cannot allocate dbr page");
-		return NULL;
-	}
-	/* Register allocated memory. */
-	page->umem = mlx5_glue->devx_umem_reg(ctx, page->dbrs,
-					      MLX5_DBR_PAGE_SIZE, 0);
-	if (!page->umem) {
-		DRV_LOG(ERR, "cannot umem reg dbr page");
-		mlx5_free(page);
-		return NULL;
-	}
-	return page;
-}
-
-/**
- * Find the next available door-bell, allocate new page if needed.
- *
- * @param [in] ctx
- *   Pointer to device context.
- * @param [in] head
- *   Pointer to the head of dbr pages list.
- * @param [out] dbr_page
- *   Door-bell page containing the page data.
- *
- * @return
- *   Door-bell address offset on success, a negative error value otherwise.
- */
-int64_t
-mlx5_get_dbr(void *ctx,  struct mlx5_dbr_page_list *head,
-	     struct mlx5_devx_dbr_page **dbr_page)
-{
-	struct mlx5_devx_dbr_page *page = NULL;
-	uint32_t i, j;
-
-	LIST_FOREACH(page, head, next)
-		if (page->dbr_count < MLX5_DBR_PER_PAGE)
-			break;
-	if (!page) { /* No page with free door-bell exists. */
-		page = mlx5_alloc_dbr_page(ctx);
-		if (!page) /* Failed to allocate new page. */
-			return (-1);
-		LIST_INSERT_HEAD(head, page, next);
-	}
-	/* Loop to find bitmap part with clear bit. */
-	for (i = 0;
-	     i < MLX5_DBR_BITMAP_SIZE && page->dbr_bitmap[i] == UINT64_MAX;
-	     i++)
-		; /* Empty. */
-	/* Find the first clear bit. */
-	MLX5_ASSERT(i < MLX5_DBR_BITMAP_SIZE);
-	j = rte_bsf64(~page->dbr_bitmap[i]);
-	page->dbr_bitmap[i] |= (UINT64_C(1) << j);
-	page->dbr_count++;
-	*dbr_page = page;
-	return (i * CHAR_BIT * sizeof(uint64_t) + j) * MLX5_DBR_SIZE;
-}
-
-/**
- * Release a door-bell record.
- *
- * @param [in] head
- *   Pointer to the head of dbr pages list.
- * @param [in] umem_id
- *   UMEM ID of page containing the door-bell record to release.
- * @param [in] offset
- *   Offset of door-bell record in page.
- *
- * @return
- *   0 on success, a negative error value otherwise.
- */
-int32_t
-mlx5_release_dbr(struct mlx5_dbr_page_list *head, uint32_t umem_id,
-		 uint64_t offset)
-{
-	struct mlx5_devx_dbr_page *page = NULL;
-	int ret = 0;
-
-	LIST_FOREACH(page, head, next)
-		/* Find the page this address belongs to. */
-		if (mlx5_os_get_umem_id(page->umem) == umem_id)
-			break;
-	if (!page)
-		return -EINVAL;
-	page->dbr_count--;
-	if (!page->dbr_count) {
-		/* Page not used, free it and remove from list. */
-		LIST_REMOVE(page, next);
-		if (page->umem)
-			ret = -mlx5_glue->devx_umem_dereg(page->umem);
-		mlx5_free(page);
-	} else {
-		/* Mark in bitmap that this door-bell is not in use. */
-		offset /= MLX5_DBR_SIZE;
-		int i = offset / 64;
-		int j = offset % 64;
-
-		page->dbr_bitmap[i] &= ~(UINT64_C(1) << j);
-	}
-	return ret;
-}
-
-/**
  * Allocate the User Access Region with DevX on specified device.
  *
  * @param [in] ctx
drivers/common/mlx5/mlx5_common.h +0 -23
index a484b74..e35188d 100644
@@ -220,21 +220,6 @@ enum mlx5_class {
 };
 
 #define MLX5_DBR_SIZE RTE_CACHE_LINE_SIZE
-#define MLX5_DBR_PER_PAGE 64
-/* Must be >= CHAR_BIT * sizeof(uint64_t) */
-#define MLX5_DBR_PAGE_SIZE (MLX5_DBR_PER_PAGE * MLX5_DBR_SIZE)
-/* Page size must be >= 512. */
-#define MLX5_DBR_BITMAP_SIZE (MLX5_DBR_PER_PAGE / (CHAR_BIT * sizeof(uint64_t)))
-
-struct mlx5_devx_dbr_page {
-	/* Door-bell records, must be first member in structure. */
-	uint8_t dbrs[MLX5_DBR_PAGE_SIZE];
-	LIST_ENTRY(mlx5_devx_dbr_page) next; /* Pointer to the next element. */
-	void *umem;
-	uint32_t dbr_count; /* Number of door-bell records in use. */
-	/* 1 bit marks matching door-bell is in use. */
-	uint64_t dbr_bitmap[MLX5_DBR_BITMAP_SIZE];
-};
 
 /* devX creation object */
 struct mlx5_devx_obj {
@@ -249,19 +234,11 @@ struct mlx5_klm {
 	uint64_t address;
 };
 
-LIST_HEAD(mlx5_dbr_page_list, mlx5_devx_dbr_page);
-
 __rte_internal
 void mlx5_translate_port_name(const char *port_name_in,
 			      struct mlx5_switch_info *port_info_out);
 void mlx5_glue_constructor(void);
 __rte_internal
-int64_t mlx5_get_dbr(void *ctx,  struct mlx5_dbr_page_list *head,
-		     struct mlx5_devx_dbr_page **dbr_page);
-__rte_internal
-int32_t mlx5_release_dbr(struct mlx5_dbr_page_list *head, uint32_t umem_id,
-			 uint64_t offset);
-__rte_internal
 void *mlx5_devx_alloc_uar(void *ctx, int mapping);
 extern uint8_t haswell_broadwell_cpu;
 
Signature · 1 line
1.8.3.1
#41 lore raw

PATCH 2/17 common/mlx5: share DevX CQ creation

In reply to Michael Baum

The CQ object in DevX is created in several places and in several different drivers.
In all places almost all the details are the same, and in particular the allocations of the required resources.

Add a structure that contains all the resources, and provide creation and release functions for it.

---
 drivers/common/mlx5/meson.build        |   1 +
 drivers/common/mlx5/mlx5_common_devx.c | 157 +++++++++++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h |  28 ++++++
 3 files changed, 186 insertions(+)
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.c
 create mode 100644 drivers/common/mlx5/mlx5_common_devx.h
drivers/common/mlx5/meson.build +1 -0
index 3dacc6f..26cee06 100644
@@ -16,6 +16,7 @@ sources += files(
 	'mlx5_common_mr.c',
 	'mlx5_malloc.c',
 	'mlx5_common_pci.c',
+	'mlx5_common_devx.c',
 )
 
 cflags_options = [
drivers/common/mlx5/mlx5_common_devx.c new file +157 -0

157 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_devx.h new file +28 -0
new file mode 100644
index 0000000..31cb804
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 Mellanox Technologies, Ltd
+ */
+
+#ifndef RTE_PMD_MLX5_COMMON_DEVX_H_
+#define RTE_PMD_MLX5_COMMON_DEVX_H_
+
+#include "mlx5_devx_cmds.h"
+
+/* DevX Completion Queue structure. */
+struct mlx5_devx_cq {
+	struct mlx5_devx_obj *cq; /* The CQ DevX object. */
+	struct mlx5dv_devx_umem *umem_obj; /* The CQ umem object. */
+	union {
+		volatile void *umem_buf;
+		volatile struct mlx5_cqe *cqes; /* The CQ ring buffer. */
+	};
+	volatile uint32_t *db_rec; /* The CQ doorbell record. */
+};
+
+/* mlx5_common_devx.c */
+
+void mlx5_devx_cq_destroy(struct mlx5_devx_cq *cq);
+int mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj,
+			uint16_t log_desc_n, struct mlx5_devx_cq_attr *attr,
+			int socket);
+
+#endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */
Signature · 1 line
1.8.3.1
#42 lore raw

PATCH 3/17 regex/mlx5: move DevX CQ creation to common

In reply to Michael Baum

Using common function for DevX CQ creation.

---
 drivers/regex/mlx5/mlx5_regex.c          |  6 ---
 drivers/regex/mlx5/mlx5_regex.h          |  9 +---
 drivers/regex/mlx5/mlx5_regex_control.c  | 91 ++++++--------------------------
 drivers/regex/mlx5/mlx5_regex_fastpath.c |  4 +-
 4 files changed, 20 insertions(+), 90 deletions(-)
drivers/regex/mlx5/mlx5_regex.c +0 -6
index c91c444..c0d6331 100644
@@ -170,12 +170,6 @@
 		rte_errno = rte_errno ? rte_errno : EINVAL;
 		goto error;
 	}
-	ret = mlx5_glue->devx_query_eqn(ctx, 0, &priv->eqn);
-	if (ret) {
-		DRV_LOG(ERR, "can't query event queue number.");
-		rte_errno = ENOMEM;
-		goto error;
-	}
 	/*
 	 * This PMD always claims the write memory barrier on UAR
 	 * registers writings, it is safe to allocate UAR with any
drivers/regex/mlx5/mlx5_regex.h +2 -7
index 2c4877c..9f7a388 100644
@@ -12,6 +12,7 @@
 
 #include <mlx5_common.h>
 #include <mlx5_common_mr.h>
+#include <mlx5_common_devx.h>
 
 #include "mlx5_rxp.h"
 
@@ -30,13 +31,8 @@ struct mlx5_regex_sq {
 
 struct mlx5_regex_cq {
 	uint32_t log_nb_desc; /* Log 2 number of desc for this object. */
-	struct mlx5_devx_obj *obj; /* The CQ DevX object. */
-	int64_t dbr_offset; /* Door bell record offset. */
-	uint32_t dbr_umem; /* Door bell record umem id. */
-	volatile struct mlx5_cqe *cqe; /* The CQ ring buffer. */
-	struct mlx5dv_devx_umem *cqe_umem; /* CQ buffer umem. */
+	struct mlx5_devx_cq cq_obj; /* The CQ DevX object. */
 	size_t ci;
-	uint32_t *dbr;
 };
 
 struct mlx5_regex_qp {
@@ -75,7 +71,6 @@ struct mlx5_regex_priv {
 	struct mlx5_regex_db db[MLX5_RXP_MAX_ENGINES +
 				MLX5_RXP_EM_COUNT];
 	uint32_t nb_engines; /* Number of RegEx engines. */
-	uint32_t eqn; /* EQ number. */
 	struct mlx5dv_devx_uar *uar; /* UAR object. */
 	struct ibv_pd *pd;
 	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
drivers/regex/mlx5/mlx5_regex_control.c +16 -75

139 lines not on this page · raw message

drivers/regex/mlx5/mlx5_regex_fastpath.c +2 -2
index 5857617..255fd40 100644
@@ -224,7 +224,7 @@ struct mlx5_regex_job {
 	size_t next_cqe_offset;
 
 	next_cqe_offset =  (cq->ci & (cq_size_get(cq) - 1));
-	cqe = (volatile struct mlx5_cqe *)(cq->cqe + next_cqe_offset);
+	cqe = (volatile struct mlx5_cqe *)(cq->cq_obj.cqes + next_cqe_offset);
 	rte_io_wmb();
 
 	int ret = check_cqe(cqe, cq_size_get(cq), cq->ci);
@@ -285,7 +285,7 @@ struct mlx5_regex_job {
 		}
 		cq->ci = (cq->ci + 1) & 0xffffff;
 		rte_wmb();
-		cq->dbr[0] = rte_cpu_to_be_32(cq->ci);
+		cq->cq_obj.db_rec[0] = rte_cpu_to_be_32(cq->ci);
 		queue->free_sqs |= (1 << sqid);
 	}
 
Signature · 1 line
1.8.3.1
#43 lore raw

PATCH 4/17 vdpa/mlx5: move DevX CQ creation to common

In reply to Michael Baum

Using common function for DevX CQ creation.

---
 drivers/vdpa/mlx5/mlx5_vdpa.h       | 10 +----
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 81 +++++++++++--------------------------
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c |  2 +-
 3 files changed, 26 insertions(+), 67 deletions(-)
drivers/vdpa/mlx5/mlx5_vdpa.h +2 -8
index d039ada..ddee9dc 100644
@@ -22,6 +22,7 @@
 
 #include <mlx5_glue.h>
 #include <mlx5_devx_cmds.h>
+#include <mlx5_common_devx.h>
 #include <mlx5_prm.h>
 
 
@@ -46,13 +47,7 @@ struct mlx5_vdpa_cq {
 	uint32_t armed:1;
 	int callfd;
 	rte_spinlock_t sl;
-	struct mlx5_devx_obj *cq;
-	struct mlx5dv_devx_umem *umem_obj;
-	union {
-		volatile void *umem_buf;
-		volatile struct mlx5_cqe *cqes;
-	};
-	volatile uint32_t *db_rec;
+	struct mlx5_devx_cq cq_obj;
 	uint64_t errors;
 };
 
@@ -144,7 +139,6 @@ struct mlx5_vdpa_priv {
 	uint32_t gpa_mkey_index;
 	struct ibv_mr *null_mr;
 	struct rte_vhost_memory *vmem;
-	uint32_t eqn;
 	struct mlx5dv_devx_event_channel *eventc;
 	struct mlx5dv_devx_event_channel *err_chnl;
 	struct mlx5dv_devx_uar *uar;
drivers/vdpa/mlx5/mlx5_vdpa_event.c +23 -58

176 lines not on this page · raw message

drivers/vdpa/mlx5/mlx5_vdpa_virtq.c +1 -1
index 3e882e4..cc77314 100644
@@ -497,7 +497,7 @@
 		return -1;
 	if (vq.size != virtq->vq_size || vq.kickfd != virtq->intr_handle.fd)
 		return 1;
-	if (virtq->eqp.cq.cq) {
+	if (virtq->eqp.cq.cq_obj.cq) {
 		if (vq.callfd != virtq->eqp.cq.callfd)
 			return 1;
 	} else if (vq.callfd != -1) {
Signature · 1 line
1.8.3.1
#44 lore raw

PATCH 5/17 net/mlx5: move rearm and clock queue CQ creation to common

In reply to Michael Baum

Using common function for CQ creation at rearm queue and clock queue.

---
 drivers/net/mlx5/mlx5.h      |   9 +--
 drivers/net/mlx5/mlx5_rxtx.c |   2 +-
 drivers/net/mlx5/mlx5_txpp.c | 147 +++++++++++--------------------------------
 3 files changed, 40 insertions(+), 118 deletions(-)
drivers/net/mlx5/mlx5.h +2 -7
index 121d726..00ccaee 100644
@@ -26,6 +26,7 @@
 #include <mlx5_prm.h>
 #include <mlx5_common_mp.h>
 #include <mlx5_common_mr.h>
+#include <mlx5_common_devx.h>
 
 #include "mlx5_defs.h"
 #include "mlx5_utils.h"
@@ -612,13 +613,7 @@ struct mlx5_flow_id_pool {
 /* Tx pacing queue structure - for Clock and Rearm queues. */
 struct mlx5_txpp_wq {
 	/* Completion Queue related data.*/
-	struct mlx5_devx_obj *cq;
-	void *cq_umem;
-	union {
-		volatile void *cq_buf;
-		volatile struct mlx5_cqe *cqes;
-	};
-	volatile uint32_t *cq_dbrec;
+	struct mlx5_devx_cq cq_obj;
 	uint32_t cq_ci:24;
 	uint32_t arm_sn:2;
 	/* Send Queue related data.*/
drivers/net/mlx5/mlx5_rxtx.c +1 -1
index d12d746..dad24a3 100644
@@ -2277,7 +2277,7 @@ enum mlx5_txcmp_code {
 
 	qs = RTE_PTR_ADD(wqe, MLX5_WSEG_SIZE);
 	qs->max_index = rte_cpu_to_be_32(wci);
-	qs->qpn_cqn = rte_cpu_to_be_32(txq->sh->txpp.clock_queue.cq->id);
+	qs->qpn_cqn = rte_cpu_to_be_32(txq->sh->txpp.clock_queue.cq_obj.cq->id);
 	qs->reserved0 = RTE_BE32(0);
 	qs->reserved1 = RTE_BE32(0);
 }
drivers/net/mlx5/mlx5_txpp.c +37 -110

256 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#45 lore raw

PATCH 6/17 net/mlx5: move ASO CQ creation to common

In reply to Michael Baum

Use common function for ASO CQ creation.

---
 drivers/net/mlx5/mlx5.h          |  8 +---
 drivers/net/mlx5/mlx5_flow_age.c | 81 +++++++++-------------------------------
 2 files changed, 19 insertions(+), 70 deletions(-)
drivers/net/mlx5/mlx5.h +1 -7
index 00ccaee..e02faed 100644
@@ -463,13 +463,7 @@ struct mlx5_flow_counter_mng {
 struct mlx5_aso_cq {
 	uint16_t log_desc_n;
 	uint32_t cq_ci:24;
-	struct mlx5_devx_obj *cq;
-	struct mlx5dv_devx_umem *umem_obj;
-	union {
-		volatile void *umem_buf;
-		volatile struct mlx5_cqe *cqes;
-	};
-	volatile uint32_t *db_rec;
+	struct mlx5_devx_cq cq_obj;
 	uint64_t errors;
 };
 
drivers/net/mlx5/mlx5_flow_age.c +18 -63

167 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#46 lore raw

PATCH 7/17 net/mlx5: move Tx CQ creation to common

In reply to Michael Baum

Using common function for Tx CQ creation.

---
 drivers/net/mlx5/mlx5.h      |   6 +-
 drivers/net/mlx5/mlx5_devx.c | 182 +++++++------------------------------------
 2 files changed, 31 insertions(+), 157 deletions(-)
drivers/net/mlx5/mlx5.h +1 -5
index e02faed..2e75498 100644
@@ -843,11 +843,7 @@ struct mlx5_txq_obj {
 		};
 		struct {
 			struct rte_eth_dev *dev;
-			struct mlx5_devx_obj *cq_devx;
-			void *cq_umem;
-			void *cq_buf;
-			int64_t cq_dbrec_offset;
-			struct mlx5_devx_dbr_page *cq_dbrec_page;
+			struct mlx5_devx_cq cq_obj;
 			struct mlx5_devx_obj *sq_devx;
 			void *sq_umem;
 			void *sq_buf;
drivers/net/mlx5/mlx5_devx.c +30 -152

224 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#47 lore raw

PATCH 8/17 net/mlx5: move Rx CQ creation to common

In reply to Michael Baum

Using common function for Rx CQ creation.

---
 drivers/net/mlx5/mlx5.c      |   8 ---
 drivers/net/mlx5/mlx5.h      |   3 +-
 drivers/net/mlx5/mlx5_devx.c | 142 +++++++++++++------------------------------
 drivers/net/mlx5/mlx5_rxtx.h |   4 --
 4 files changed, 42 insertions(+), 115 deletions(-)
drivers/net/mlx5/mlx5.c +0 -8
index 52a8a25..3c7e5d2 100644
@@ -938,14 +938,6 @@ struct mlx5_dev_ctx_shared *
 		goto error;
 	}
 	if (sh->devx) {
-		/* Query the EQN for this core. */
-		err = mlx5_glue->devx_query_eqn(sh->ctx, 0, &sh->eqn);
-		if (err) {
-			rte_errno = errno;
-			DRV_LOG(ERR, "Failed to query event queue number %d.",
-				rte_errno);
-			goto error;
-		}
 		err = mlx5_os_get_pdn(sh->pd, &sh->pdn);
 		if (err) {
 			DRV_LOG(ERR, "Fail to extract pdn from PD");
drivers/net/mlx5/mlx5.h +1 -2
index 2e75498..9a59c26 100644
@@ -679,7 +679,6 @@ struct mlx5_dev_ctx_shared {
 	uint16_t bond_dev; /* Bond primary device id. */
 	uint32_t devx:1; /* Opened with DV. */
 	uint32_t flow_hit_aso_en:1; /* Flow Hit ASO is supported. */
-	uint32_t eqn; /* Event Queue number. */
 	uint32_t max_port; /* Maximal IB device port index. */
 	void *ctx; /* Verbs/DV/DevX context. */
 	void *pd; /* Protection Domain. */
@@ -787,7 +786,7 @@ struct mlx5_rxq_obj {
 		};
 		struct {
 			struct mlx5_devx_obj *rq; /* DevX Rx Queue object. */
-			struct mlx5_devx_obj *devx_cq; /* DevX CQ object. */
+			struct mlx5_devx_cq cq_obj; /* DevX CQ object. */
 			void *devx_channel;
 		};
 	};
drivers/net/mlx5/mlx5_devx.c +41 -101

221 lines not on this page · raw message

drivers/net/mlx5/mlx5_rxtx.h +0 -4
index 7989a50..6a71791 100644
@@ -196,11 +196,7 @@ struct mlx5_rxq_ctrl {
 	struct mlx5_devx_dbr_page *rq_dbrec_page;
 	uint64_t rq_dbr_offset;
 	/* Storing RQ door-bell information, needed when freeing door-bell. */
-	struct mlx5_devx_dbr_page *cq_dbrec_page;
-	uint64_t cq_dbr_offset;
-	/* Storing CQ door-bell information, needed when freeing door-bell. */
 	void *wq_umem; /* WQ buffer registration info. */
-	void *cq_umem; /* CQ buffer registration info. */
 	struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
 	uint32_t hairpin_status; /* Hairpin binding status. */
 };
Signature · 1 line
1.8.3.1
#48 lore raw

PATCH 9/17 common/mlx5: enhance page size configuration

In reply to Michael Baum

The PRM calculates page size in 4K, so need to reduce the log_wq_pg_sz attribute.

---
 drivers/common/mlx5/mlx5_devx_cmds.c | 53 ++++++++++++++++--------------------
 drivers/net/mlx5/mlx5_devx.c         | 13 +++++----
 2 files changed, 30 insertions(+), 36 deletions(-)
drivers/common/mlx5/mlx5_devx_cmds.c +23 -30
index 9c1d188..09e204b 100644
@@ -268,9 +268,8 @@ struct mlx5_devx_obj *
 	MLX5_SET(mkc, mkc, mkey_7_0, attr->umem_id & 0xFF);
 	MLX5_SET(mkc, mkc, translations_octword_size, translation_size);
 	MLX5_SET(mkc, mkc, relaxed_ordering_write,
-		attr->relaxed_ordering_write);
-	MLX5_SET(mkc, mkc, relaxed_ordering_read,
-		attr->relaxed_ordering_read);
+		 attr->relaxed_ordering_write);
+	MLX5_SET(mkc, mkc, relaxed_ordering_read, attr->relaxed_ordering_read);
 	MLX5_SET64(mkc, mkc, start_addr, attr->addr);
 	MLX5_SET64(mkc, mkc, len, attr->size);
 	mkey->obj = mlx5_glue->devx_obj_create(ctx, in, in_size_dw * 4, out,
@@ -308,7 +307,7 @@ struct mlx5_devx_obj *
 	if (status) {
 		int syndrome = MLX5_GET(query_flow_counter_out, out, syndrome);
 
-		DRV_LOG(ERR, "Bad devX status %x, syndrome = %x", status,
+		DRV_LOG(ERR, "Bad DevX status %x, syndrome = %x", status,
 			syndrome);
 	}
 	return status;
@@ -374,8 +373,7 @@ struct mlx5_devx_obj *
 	syndrome = MLX5_GET(query_nic_vport_context_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query NIC vport context, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		return -1;
 	}
 	vctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
@@ -662,8 +660,7 @@ struct mlx5_devx_obj *
 	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		return -1;
 	}
 	hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
@@ -683,11 +680,11 @@ struct mlx5_devx_obj *
 		(cmd_hca_cap, hcattr, log_min_hairpin_wq_data_sz);
 	attr->vhca_id = MLX5_GET(cmd_hca_cap, hcattr, vhca_id);
 	attr->relaxed_ordering_write = MLX5_GET(cmd_hca_cap, hcattr,
-			relaxed_ordering_write);
+						relaxed_ordering_write);
 	attr->relaxed_ordering_read = MLX5_GET(cmd_hca_cap, hcattr,
-			relaxed_ordering_read);
+					       relaxed_ordering_read);
 	attr->access_register_user = MLX5_GET(cmd_hca_cap, hcattr,
-			access_register_user);
+					      access_register_user);
 	attr->eth_net_offloads = MLX5_GET(cmd_hca_cap, hcattr,
 					  eth_net_offloads);
 	attr->eth_virt = MLX5_GET(cmd_hca_cap, hcattr, eth_virt);
@@ -730,8 +727,7 @@ struct mlx5_devx_obj *
 			goto error;
 		if (status) {
 			DRV_LOG(DEBUG, "Failed to query devx QOS capabilities,"
-				" status %x, syndrome = %x",
-				status, syndrome);
+				" status %x, syndrome = %x", status, syndrome);
 			return -1;
 		}
 		hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
@@ -761,17 +757,14 @@ struct mlx5_devx_obj *
 		 MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
 		 MLX5_HCA_CAP_OPMOD_GET_CUR);
 
-	rc = mlx5_glue->devx_general_cmd(ctx,
-					 in, sizeof(in),
-					 out, sizeof(out));
+	rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out));
 	if (rc)
 		goto error;
 	status = MLX5_GET(query_hca_cap_out, out, status);
 	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		attr->log_max_ft_sampler_num = 0;
 		return -1;
 	}
@@ -788,9 +781,7 @@ struct mlx5_devx_obj *
 		 MLX5_GET_HCA_CAP_OP_MOD_ETHERNET_OFFLOAD_CAPS |
 		 MLX5_HCA_CAP_OPMOD_GET_CUR);
 
-	rc = mlx5_glue->devx_general_cmd(ctx,
-					 in, sizeof(in),
-					 out, sizeof(out));
+	rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out));
 	if (rc) {
 		attr->eth_net_offloads = 0;
 		goto error;
@@ -799,8 +790,7 @@ struct mlx5_devx_obj *
 	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
 	if (status) {
 		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
-			"status %x, syndrome = %x",
-			status, syndrome);
+			"status %x, syndrome = %x", status, syndrome);
 		attr->eth_net_offloads = 0;
 		return -1;
 	}
@@ -916,7 +906,9 @@ struct mlx5_devx_obj *
 	MLX5_SET(wq, wq_ctx, hw_counter, wq_attr->hw_counter);
 	MLX5_SET(wq, wq_ctx, sw_counter, wq_attr->sw_counter);
 	MLX5_SET(wq, wq_ctx, log_wq_stride, wq_attr->log_wq_stride);
-	MLX5_SET(wq, wq_ctx, log_wq_pg_sz, wq_attr->log_wq_pg_sz);
+	if (wq_attr->log_wq_pg_sz > MLX5_ADAPTER_PAGE_SHIFT)
+		MLX5_SET(wq, wq_ctx, log_wq_pg_sz,
+			 wq_attr->log_wq_pg_sz - MLX5_ADAPTER_PAGE_SHIFT);
 	MLX5_SET(wq, wq_ctx, log_wq_sz, wq_attr->log_wq_sz);
 	MLX5_SET(wq, wq_ctx, dbr_umem_valid, wq_attr->dbr_umem_valid);
 	MLX5_SET(wq, wq_ctx, wq_umem_valid, wq_attr->wq_umem_valid);
@@ -1562,13 +1554,13 @@ struct mlx5_devx_obj *
 	MLX5_SET(cqc, cqctx, cc, attr->use_first_only);
 	MLX5_SET(cqc, cqctx, oi, attr->overrun_ignore);
 	MLX5_SET(cqc, cqctx, log_cq_size, attr->log_cq_size);
-	MLX5_SET(cqc, cqctx, log_page_size, attr->log_page_size -
-		 MLX5_ADAPTER_PAGE_SHIFT);
+	if (attr->log_page_size > MLX5_ADAPTER_PAGE_SHIFT)
+		MLX5_SET(cqc, cqctx, log_page_size,
+			 attr->log_page_size - MLX5_ADAPTER_PAGE_SHIFT);
 	MLX5_SET(cqc, cqctx, c_eqn, attr->eqn);
 	MLX5_SET(cqc, cqctx, uar_page, attr->uar_page_id);
 	MLX5_SET(cqc, cqctx, cqe_comp_en, !!attr->cqe_comp_en);
-	MLX5_SET(cqc, cqctx, mini_cqe_res_format,
-		 attr->mini_cqe_res_format);
+	MLX5_SET(cqc, cqctx, mini_cqe_res_format, attr->mini_cqe_res_format);
 	MLX5_SET(cqc, cqctx, mini_cqe_res_format_ext,
 		 attr->mini_cqe_res_format_ext);
 	MLX5_SET(cqc, cqctx, cqe_sz, attr->cqe_size);
@@ -1798,8 +1790,9 @@ struct mlx5_devx_obj *
 	if (attr->uar_index) {
 		MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED);
 		MLX5_SET(qpc, qpc, uar_page, attr->uar_index);
-		MLX5_SET(qpc, qpc, log_page_size, attr->log_page_size -
-			 MLX5_ADAPTER_PAGE_SHIFT);
+		if (attr->log_page_size > MLX5_ADAPTER_PAGE_SHIFT)
+			MLX5_SET(qpc, qpc, log_page_size,
+				 attr->log_page_size - MLX5_ADAPTER_PAGE_SHIFT);
 		if (attr->sq_size) {
 			MLX5_ASSERT(RTE_IS_POWER_OF_2(attr->sq_size));
 			MLX5_SET(qpc, qpc, cqn_snd, attr->cqn);
drivers/net/mlx5/mlx5_devx.c +7 -6
index 6ad70f2..fe103a7 100644
@@ -320,7 +320,13 @@
 	uint32_t log_wqe_size = 0;
 	void *buf = NULL;
 	struct mlx5_devx_obj *rq;
+	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
 
+	if (alignment == (size_t)-1) {
+		DRV_LOG(ERR, "Failed to get mem page size");
+		rte_errno = ENOMEM;
+		return NULL;
+	}
 	/* Fill RQ attributes. */
 	rq_attr.mem_rq_type = MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE;
 	rq_attr.flush_in_error_en = 1;
@@ -347,15 +353,10 @@
 	log_wqe_size = log2above(wqe_size) + rxq_data->sges_n;
 	rq_attr.wq_attr.log_wq_stride = log_wqe_size;
 	rq_attr.wq_attr.log_wq_sz = rxq_data->elts_n - rxq_data->sges_n;
+	rq_attr.wq_attr.log_wq_pg_sz = log2above(alignment);
 	/* Calculate and allocate WQ memory space. */
 	wqe_size = 1 << log_wqe_size; /* round up power of two.*/
 	wq_size = wqe_n * wqe_size;
-	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
-	if (alignment == (size_t)-1) {
-		DRV_LOG(ERR, "Failed to get mem page size");
-		rte_errno = ENOMEM;
-		return NULL;
-	}
 	buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, wq_size,
 			  alignment, rxq_ctrl->socket);
 	if (!buf)
Signature · 1 line
1.8.3.1
#49 lore raw

PATCH 10/17 common/mlx5: share DevX SQ creation

In reply to Michael Baum

The SQ object in DevX is created in several places and in several different drivers.
In all places almost all the details are the same, and in particular the allocations of the required resources.

Add a structure that contains all the resources, and provide creation and release functions for it.

---
 drivers/common/mlx5/mlx5_common_devx.c | 122 +++++++++++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h |  20 +++++-
 2 files changed, 140 insertions(+), 2 deletions(-)
drivers/common/mlx5/mlx5_common_devx.c +122 -0
index 324c6ea..46404d8 100644
@@ -155,3 +155,125 @@
 	rte_errno = ret;
 	return -rte_errno;
 }
+
+/**
+ * Destroy DevX Send Queue.
+ *
+ * @param[in] sq
+ *   DevX SQ to destroy.
+ */
+void
+mlx5_devx_sq_destroy(struct mlx5_devx_sq *sq)
+{
+	if (sq->sq)
+		claim_zero(mlx5_devx_cmd_destroy(sq->sq));
+	if (sq->umem_obj)
+		claim_zero(mlx5_glue->devx_umem_dereg(sq->umem_obj));
+	if (sq->umem_buf)
+		mlx5_free((void *)(uintptr_t)sq->umem_buf);
+}
+
+/**
+ * Create Send Queue using DevX API.
+ *
+ * Get a pointer to partially initialized attributes structure, and updates the
+ * following fields:
+ *   wq_type
+ *   wq_umem_valid
+ *   wq_umem_id
+ *   wq_umem_offset
+ *   dbr_umem_valid
+ *   dbr_umem_id
+ *   dbr_addr
+ *   log_wq_stride
+ *   log_wq_sz
+ *   log_wq_pg_sz
+ * All other fields are updated by caller.
+ *
+ * @param[in] ctx
+ *   Context returned from mlx5 open_device() glue function.
+ * @param[in/out] sq_obj
+ *   Pointer to SQ to create.
+ * @param[in] log_wqbb_n
+ *   Log of number of WQBBs in queue.
+ * @param[in] attr
+ *   Pointer to SQ attributes structure.
+ * @param[in] socket
+ *   Socket to use for allocation.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj, uint16_t log_wqbb_n,
+		    struct mlx5_devx_create_sq_attr *attr, int socket)
+{
+	struct mlx5_devx_obj *sq = NULL;
+	struct mlx5dv_devx_umem *umem_obj = NULL;
+	void *umem_buf = NULL;
+	size_t page_size = rte_mem_page_size();
+	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
+	uint32_t umem_size, umem_dbrec;
+	uint16_t sq_size = 1 << log_wqbb_n;
+	int ret;
+
+	if (page_size == (size_t)-1 || alignment == (size_t)-1) {
+		DRV_LOG(ERR, "Failed to get page_size.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Allocate memory buffer for WQEs and doorbell record. */
+	umem_size = MLX5_WQE_SIZE * sq_size;
+	umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE);
+	umem_size += MLX5_DBR_SIZE;
+	umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size,
+			       alignment, socket);
+	if (!umem_buf) {
+		DRV_LOG(ERR, "Failed to allocate memory for SQ.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Register allocated buffer in user space with DevX. */
+	umem_obj = mlx5_glue->devx_umem_reg(ctx, (void *)(uintptr_t)umem_buf,
+					    umem_size, IBV_ACCESS_LOCAL_WRITE);
+	if (!umem_obj) {
+		DRV_LOG(ERR, "Failed to register umem for SQ.");
+		rte_errno = errno;
+		goto error;
+	}
+	/* Fill attributes for SQ object creation. */
+	attr->wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
+	attr->wq_attr.wq_umem_valid = 1;
+	attr->wq_attr.wq_umem_id = mlx5_os_get_umem_id(sq_obj->umem_obj);
+	attr->wq_attr.wq_umem_offset = 0;
+	attr->wq_attr.dbr_umem_valid = 1;
+	attr->wq_attr.dbr_umem_id = attr->wq_attr.wq_umem_id;
+	attr->wq_attr.dbr_addr = umem_dbrec;
+	attr->wq_attr.log_wq_stride = rte_log2_u32(MLX5_WQE_SIZE);
+	attr->wq_attr.log_wq_sz = log_wqbb_n;
+	attr->wq_attr.log_wq_pg_sz = rte_log2_u32(page_size);
+	/* Create send queue object with DevX. */
+	sq = mlx5_devx_cmd_create_sq(ctx, attr);
+	if (!sq) {
+		DRV_LOG(ERR, "Can't create DevX SQ object.");
+		rte_errno = ENOMEM;
+		goto error;
+	}
+	sq_obj->umem_buf = umem_buf;
+	sq_obj->umem_obj = umem_obj;
+	sq_obj->sq = sq;
+	sq_obj->db_rec = RTE_PTR_ADD(sq_obj->umem_buf, umem_dbrec);
+	return 0;
+error:
+	ret = rte_errno;
+	if (sq)
+		claim_zero(mlx5_devx_cmd_destroy(sq));
+	if (umem_obj)
+		claim_zero(mlx5_glue->devx_umem_dereg(umem_obj));
+	if (umem_buf)
+		mlx5_free((void *)(uintptr_t)umem_buf);
+	rte_errno = ret;
+	return -rte_errno;
+}
+
+
drivers/common/mlx5/mlx5_common_devx.h +18 -2
index 31cb804..88d520b 100644
@@ -18,11 +18,27 @@ struct mlx5_devx_cq {
 	volatile uint32_t *db_rec; /* The CQ doorbell record. */
 };
 
+/* DevX Send Queue structure. */
+struct mlx5_devx_sq {
+	struct mlx5_devx_obj *sq; /* The SQ DevX object. */
+	struct mlx5dv_devx_umem *umem_obj; /* The SQ umem object. */
+	union {
+		volatile void *umem_buf;
+		volatile struct mlx5_wqe *wqes; /* The SQ ring buffer. */
+	};
+	volatile uint32_t *db_rec; /* The SQ doorbell record. */
+};
+
+
 /* mlx5_common_devx.c */
 
 void mlx5_devx_cq_destroy(struct mlx5_devx_cq *cq);
 int mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj,
-			uint16_t log_desc_n, struct mlx5_devx_cq_attr *attr,
-			int socket);
+			uint16_t log_desc_n,
+			struct mlx5_devx_cq_attr *attr, int socket);
+void mlx5_devx_sq_destroy(struct mlx5_devx_sq *sq);
+int mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj,
+			uint16_t log_wqbb_n,
+			struct mlx5_devx_create_sq_attr *attr, int socket);
 
 #endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */
Signature · 1 line
1.8.3.1
#50 lore raw

PATCH 11/17 regex/mlx5: move DevX SQ creation to common

In reply to Michael Baum

Using common function for DevX SQ creation.

---
 drivers/regex/mlx5/mlx5_regex.h          |   8 +-
 drivers/regex/mlx5/mlx5_regex_control.c  | 153 ++++++++++---------------------
 drivers/regex/mlx5/mlx5_regex_fastpath.c |  14 +--
 3 files changed, 55 insertions(+), 120 deletions(-)
drivers/regex/mlx5/mlx5_regex.h +1 -7
index 9f7a388..7e1b2a9 100644
@@ -18,15 +18,10 @@
 
 struct mlx5_regex_sq {
 	uint16_t log_nb_desc; /* Log 2 number of desc for this object. */
-	struct mlx5_devx_obj *obj; /* The SQ DevX object. */
-	int64_t dbr_offset; /* Door bell record offset. */
-	uint32_t dbr_umem; /* Door bell record umem id. */
-	uint8_t *wqe; /* The SQ ring buffer. */
-	struct mlx5dv_devx_umem *wqe_umem; /* SQ buffer umem. */
+	struct mlx5_devx_sq sq_obj; /* The SQ DevX object. */
 	size_t pi, db_pi;
 	size_t ci;
 	uint32_t sqn;
-	uint32_t *dbr;
 };
 
 struct mlx5_regex_cq {
@@ -73,7 +68,6 @@ struct mlx5_regex_priv {
 	uint32_t nb_engines; /* Number of RegEx engines. */
 	struct mlx5dv_devx_uar *uar; /* UAR object. */
 	struct ibv_pd *pd;
-	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
 	struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. */
 };
 
drivers/regex/mlx5/mlx5_regex_control.c +47 -106

188 lines not on this page · raw message

drivers/regex/mlx5/mlx5_regex_fastpath.c +7 -7
index 255fd40..cd0f9bd 100644
@@ -110,12 +110,12 @@ struct mlx5_regex_job {
 				  &priv->mr_scache, &qp->mr_ctrl,
 				  rte_pktmbuf_mtod(op->mbuf, uintptr_t),
 				  !!(op->mbuf->ol_flags & EXT_ATTACHED_MBUF));
-	uint8_t *wqe = (uint8_t *)sq->wqe + wqe_offset;
+	uint8_t *wqe = (uint8_t *)(uintptr_t)sq->sq_obj.wqes + wqe_offset;
 	int ds = 4; /*  ctrl + meta + input + output */
 
 	set_wqe_ctrl_seg((struct mlx5_wqe_ctrl_seg *)wqe, sq->pi,
-			 MLX5_OPCODE_MMO, MLX5_OPC_MOD_MMO_REGEX, sq->obj->id,
-			 0, ds, 0, 0);
+			 MLX5_OPCODE_MMO, MLX5_OPC_MOD_MMO_REGEX,
+			 sq->sq_obj.sq->id, 0, ds, 0, 0);
 	set_regex_ctrl_seg(wqe + 12, 0, op->group_id0, op->group_id1,
 			   op->group_id2,
 			   op->group_id3, 0);
@@ -137,12 +137,12 @@ struct mlx5_regex_job {
 {
 	size_t wqe_offset = (sq->db_pi & (sq_size_get(sq) - 1)) *
 		MLX5_SEND_WQE_BB;
-	uint8_t *wqe = (uint8_t *)sq->wqe + wqe_offset;
+	uint8_t *wqe = (uint8_t *)(uintptr_t)sq->sq_obj.wqes + wqe_offset;
 	((struct mlx5_wqe_ctrl_seg *)wqe)->fm_ce_se = MLX5_WQE_CTRL_CQ_UPDATE;
 	uint64_t *doorbell_addr =
 		(uint64_t *)((uint8_t *)uar->base_addr + 0x800);
 	rte_io_wmb();
-	sq->dbr[MLX5_SND_DBR] = rte_cpu_to_be_32((sq->db_pi + 1) &
+	sq->sq_obj.db_rec[MLX5_SND_DBR] = rte_cpu_to_be_32((sq->db_pi + 1) &
 						 MLX5_REGEX_MAX_WQE_INDEX);
 	rte_wmb();
 	*doorbell_addr = *(volatile uint64_t *)wqe;
@@ -301,7 +301,7 @@ struct mlx5_regex_job {
 	uint32_t job_id;
 	for (sqid = 0; sqid < queue->nb_obj; sqid++) {
 		struct mlx5_regex_sq *sq = &queue->sqs[sqid];
-		uint8_t *wqe = (uint8_t *)sq->wqe;
+		uint8_t *wqe = (uint8_t *)(uintptr_t)sq->sq_obj.wqes;
 		for (entry = 0 ; entry < sq_size_get(sq); entry++) {
 			job_id = sqid * sq_size_get(sq) + entry;
 			struct mlx5_regex_job *job = &queue->jobs[job_id];
@@ -334,7 +334,7 @@ struct mlx5_regex_job {
 		return -ENOMEM;
 
 	qp->metadata = mlx5_glue->reg_mr(pd, ptr,
-					 MLX5_REGEX_METADATA_SIZE*qp->nb_desc,
+					 MLX5_REGEX_METADATA_SIZE * qp->nb_desc,
 					 IBV_ACCESS_LOCAL_WRITE);
 	if (!qp->metadata) {
 		DRV_LOG(ERR, "Failed to register metadata");
Signature · 1 line
1.8.3.1
#51 lore raw

PATCH 12/17 net/mlx5: move rearm and clock queue SQ creation to common

In reply to Michael Baum

Using common function for DevX SQ creation for rearm and clock queue.

---
 drivers/net/mlx5/mlx5.h      |   8 +--
 drivers/net/mlx5/mlx5_txpp.c | 147 +++++++++++--------------------------------
 2 files changed, 36 insertions(+), 119 deletions(-)
drivers/net/mlx5/mlx5.h +1 -7
index 9a59c26..192a5a7 100644
@@ -611,15 +611,9 @@ struct mlx5_txpp_wq {
 	uint32_t cq_ci:24;
 	uint32_t arm_sn:2;
 	/* Send Queue related data.*/
-	struct mlx5_devx_obj *sq;
-	void *sq_umem;
-	union {
-		volatile void *sq_buf;
-		volatile struct mlx5_wqe *wqes;
-	};
+	struct mlx5_devx_sq sq_obj;
 	uint16_t sq_size; /* Number of WQEs in the queue. */
 	uint16_t sq_ci; /* Next WQE to execute. */
-	volatile uint32_t *sq_dbrec;
 };
 
 /* Tx packet pacing internal timestamp. */
drivers/net/mlx5/mlx5_txpp.c +35 -112

276 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#52 lore raw

PATCH 13/17 net/mlx5: move Tx SQ creation to common

In reply to Michael Baum

Using common function for Tx SQ creation.

---
 drivers/net/mlx5/mlx5.h      |   8 +--
 drivers/net/mlx5/mlx5_devx.c | 160 ++++++++++---------------------------------
 2 files changed, 40 insertions(+), 128 deletions(-)
drivers/net/mlx5/mlx5.h +3 -5
index 192a5a7..6977eac 100644
@@ -837,11 +837,9 @@ struct mlx5_txq_obj {
 		struct {
 			struct rte_eth_dev *dev;
 			struct mlx5_devx_cq cq_obj;
-			struct mlx5_devx_obj *sq_devx;
-			void *sq_umem;
-			void *sq_buf;
-			int64_t sq_dbrec_offset;
-			struct mlx5_devx_dbr_page *sq_dbrec_page;
+			/* DevX CQ object and its resources. */
+			struct mlx5_devx_sq sq_obj;
+			/* DevX SQ object and its resources. */
 		};
 	};
 };
drivers/net/mlx5/mlx5_devx.c +37 -123

221 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#53 lore raw

PATCH 14/17 net/mlx5: move ASO SQ creation to common

In reply to Michael Baum

Using common function for ASO SQ creation.

---
 drivers/common/mlx5/mlx5_common_devx.h |  1 +
 drivers/net/mlx5/mlx5.h                |  8 +--
 drivers/net/mlx5/mlx5_flow_age.c       | 94 ++++++++++------------------------
 3 files changed, 30 insertions(+), 73 deletions(-)
drivers/common/mlx5/mlx5_common_devx.h +1 -0
index 88d520b..8377d34 100644
@@ -25,6 +25,7 @@ struct mlx5_devx_sq {
 	union {
 		volatile void *umem_buf;
 		volatile struct mlx5_wqe *wqes; /* The SQ ring buffer. */
+		volatile struct mlx5_aso_wqe *aso_wqes;
 	};
 	volatile uint32_t *db_rec; /* The SQ doorbell record. */
 };
drivers/net/mlx5/mlx5.h +1 -7
index 6977eac..86ada23 100644
@@ -483,13 +483,7 @@ struct mlx5_aso_sq_elem {
 struct mlx5_aso_sq {
 	uint16_t log_desc_n;
 	struct mlx5_aso_cq cq;
-	struct mlx5_devx_obj *sq;
-	struct mlx5dv_devx_umem *wqe_umem; /* SQ buffer umem. */
-	union {
-		volatile void *umem_buf;
-		volatile struct mlx5_aso_wqe *wqes;
-	};
-	volatile uint32_t *db_rec;
+	struct mlx5_devx_sq sq_obj;
 	volatile uint64_t *uar_addr;
 	struct mlx5_aso_devx_mr mr;
 	uint16_t pi;
drivers/net/mlx5/mlx5_flow_age.c +28 -66

152 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#54 lore raw

PATCH 15/17 common/mlx5: share DevX RQ creation

In reply to Michael Baum

The RQ object in DevX is used currently only in net driver, but it share for future.

Add a structure that contains all the resources, and provide creation and release functions for it.

---
 drivers/common/mlx5/mlx5_common_devx.c | 116 +++++++++++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common_devx.h |  11 ++++
 2 files changed, 127 insertions(+)
drivers/common/mlx5/mlx5_common_devx.c +116 -0
index 46404d8..0ac67bd 100644
@@ -276,4 +276,120 @@
 	return -rte_errno;
 }
 
+/**
+ * Destroy DevX Receive Queue.
+ *
+ * @param[in] rq
+ *   DevX RQ to destroy.
+ */
+void
+mlx5_devx_rq_destroy(struct mlx5_devx_rq *rq)
+{
+	if (rq->rq)
+		claim_zero(mlx5_devx_cmd_destroy(rq->rq));
+	if (rq->umem_obj)
+		claim_zero(mlx5_glue->devx_umem_dereg(rq->umem_obj));
+	if (rq->umem_buf)
+		mlx5_free((void *)(uintptr_t)rq->umem_buf);
+}
+
+/**
+ * Create Receive Queue using DevX API.
+ *
+ * Get a pointer to partially initialized attributes structure, and updates the
+ * following fields:
+ *   wq_umem_valid
+ *   wq_umem_id
+ *   wq_umem_offset
+ *   dbr_umem_valid
+ *   dbr_umem_id
+ *   dbr_addr
+ *   log_wq_pg_sz
+ * All other fields are updated by caller.
+ *
+ * @param[in] ctx
+ *   Context returned from mlx5 open_device() glue function.
+ * @param[in/out] rq_obj
+ *   Pointer to RQ to create.
+ * @param[in] wqe_size
+ *   Size of WQE structure.
+ * @param[in] log_wqbb_n
+ *   Log of number of WQBBs in queue.
+ * @param[in] attr
+ *   Pointer to RQ attributes structure.
+ * @param[in] socket
+ *   Socket to use for allocation.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_devx_rq_create(void *ctx, struct mlx5_devx_rq *rq_obj, uint32_t wqe_size,
+		    uint16_t log_wqbb_n,
+		    struct mlx5_devx_create_rq_attr *attr, int socket)
+{
+	struct mlx5_devx_obj *rq = NULL;
+	struct mlx5dv_devx_umem *umem_obj = NULL;
+	void *umem_buf = NULL;
+	size_t page_size = rte_mem_page_size();
+	size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
+	uint32_t umem_size, umem_dbrec;
+	uint16_t rq_size = 1 << log_wqbb_n;
+	int ret;
+
+	if (page_size == (size_t)-1 || alignment == (size_t)-1) {
+		DRV_LOG(ERR, "Failed to get page_size.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Allocate memory buffer for WQEs and doorbell record. */
+	umem_size = wqe_size * rq_size;
+	umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE);
+	umem_size += MLX5_DBR_SIZE;
+	umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size,
+			       alignment, socket);
+	if (!umem_buf) {
+		DRV_LOG(ERR, "Failed to allocate memory for RQ.");
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
+	/* Register allocated buffer in user space with DevX. */
+	umem_obj = mlx5_glue->devx_umem_reg(ctx, (void *)(uintptr_t)umem_buf,
+					    umem_size, 0);
+	if (!umem_obj) {
+		DRV_LOG(ERR, "Failed to register umem for RQ.");
+		rte_errno = errno;
+		goto error;
+	}
+	/* Fill attributes for RQ object creation. */
+	attr->wq_attr.wq_umem_valid = 1;
+	attr->wq_attr.wq_umem_id = mlx5_os_get_umem_id(rq_obj->umem_obj);
+	attr->wq_attr.wq_umem_offset = 0;
+	attr->wq_attr.dbr_umem_valid = 1;
+	attr->wq_attr.dbr_umem_id = attr->wq_attr.wq_umem_id;
+	attr->wq_attr.dbr_addr = umem_dbrec;
+	attr->wq_attr.log_wq_pg_sz = rte_log2_u32(page_size);
+	/* Create receive queue object with DevX. */
+	rq = mlx5_devx_cmd_create_rq(ctx, attr, socket);
+	if (!rq) {
+		DRV_LOG(ERR, "Can't create DevX RQ object.");
+		rte_errno = ENOMEM;
+		goto error;
+	}
+	rq_obj->umem_buf = umem_buf;
+	rq_obj->umem_obj = umem_obj;
+	rq_obj->rq = rq;
+	rq_obj->db_rec = RTE_PTR_ADD(rq_obj->umem_buf, umem_dbrec);
+	return 0;
+error:
+	ret = rte_errno;
+	if (rq)
+		claim_zero(mlx5_devx_cmd_destroy(rq));
+	if (umem_obj)
+		claim_zero(mlx5_glue->devx_umem_dereg(umem_obj));
+	if (umem_buf)
+		mlx5_free((void *)(uintptr_t)umem_buf);
+	rte_errno = ret;
+	return -rte_errno;
+}
 
drivers/common/mlx5/mlx5_common_devx.h +11 -0
index 8377d34..1dafbf5 100644
@@ -30,6 +30,13 @@ struct mlx5_devx_sq {
 	volatile uint32_t *db_rec; /* The SQ doorbell record. */
 };
 
+/* DevX Receive Queue structure. */
+struct mlx5_devx_rq {
+	struct mlx5_devx_obj *rq; /* The RQ DevX object. */
+	struct mlx5dv_devx_umem *umem_obj; /* The RQ umem object. */
+	volatile void *umem_buf;
+	volatile uint32_t *db_rec; /* The RQ doorbell record. */
+};
 
 /* mlx5_common_devx.c */
 
@@ -41,5 +48,9 @@ int mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj,
 int mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj,
 			uint16_t log_wqbb_n,
 			struct mlx5_devx_create_sq_attr *attr, int socket);
+void mlx5_devx_rq_destroy(struct mlx5_devx_rq *rq);
+int mlx5_devx_rq_create(void *ctx, struct mlx5_devx_rq *rq_obj,
+			uint32_t wqe_size, uint16_t log_wqbb_n,
+			struct mlx5_devx_create_rq_attr *attr, int socket);
 
 #endif /* RTE_PMD_MLX5_COMMON_DEVX_H_ */
Signature · 1 line
1.8.3.1
#55 lore raw

PATCH 16/17 net/mlx5: move Rx RQ creation to common

In reply to Michael Baum

Using common function for Rx RQ creation.

---
 drivers/net/mlx5/mlx5.h      |   4 +-
 drivers/net/mlx5/mlx5_devx.c | 178 +++++++++----------------------------------
 drivers/net/mlx5/mlx5_rxtx.h |   4 -
 3 files changed, 37 insertions(+), 149 deletions(-)
drivers/net/mlx5/mlx5.h +2 -2
index 86ada23..5bf6886 100644
@@ -772,8 +772,9 @@ struct mlx5_rxq_obj {
 			void *ibv_cq; /* Completion Queue. */
 			void *ibv_channel;
 		};
+		struct mlx5_devx_obj *rq; /* DevX RQ object for hairpin. */
 		struct {
-			struct mlx5_devx_obj *rq; /* DevX Rx Queue object. */
+			struct mlx5_devx_rq rq_obj; /* DevX RQ object. */
 			struct mlx5_devx_cq cq_obj; /* DevX CQ object. */
 			void *devx_channel;
 		};
@@ -944,7 +945,6 @@ struct mlx5_priv {
 	/* Context for Verbs allocator. */
 	int nl_socket_rdma; /* Netlink socket (NETLINK_RDMA). */
 	int nl_socket_route; /* Netlink socket (NETLINK_ROUTE). */
-	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
 	struct mlx5_nl_vlan_vmwa_context *vmwa_context; /* VLAN WA context. */
 	struct mlx5_hlist *mreg_cp_tbl;
 	/* Hash table of Rx metadata register copy table. */
drivers/net/mlx5/mlx5_devx.c +35 -143

271 lines not on this page · raw message

drivers/net/mlx5/mlx5_rxtx.h +0 -4
index 6a71791..b0041c9 100644
@@ -193,10 +193,6 @@ struct mlx5_rxq_ctrl {
 	uint32_t flow_tunnels_n[MLX5_FLOW_TUNNEL]; /* Tunnels counters. */
 	uint32_t wqn; /* WQ number. */
 	uint16_t dump_file_n; /* Number of dump files. */
-	struct mlx5_devx_dbr_page *rq_dbrec_page;
-	uint64_t rq_dbr_offset;
-	/* Storing RQ door-bell information, needed when freeing door-bell. */
-	void *wq_umem; /* WQ buffer registration info. */
 	struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
 	uint32_t hairpin_status; /* Hairpin binding status. */
 };
Signature · 1 line
1.8.3.1
#56 lore raw

PATCH 17/17 common/mlx5: remove doorbell allocation API

In reply to Michael Baum

The mlx5_devx_dbr_page structure was used to allocate and release the umem of the doorbells.
Since doorbell and buffer have used same umem, this structure is useless.

---
 drivers/common/mlx5/mlx5_common.c | 122 --------------------------------------
 drivers/common/mlx5/mlx5_common.h |  23 -------
 2 files changed, 145 deletions(-)
drivers/common/mlx5/mlx5_common.c +0 -122
index 0445132..c26a2cf 100644
@@ -8,12 +8,10 @@
 
 #include <rte_errno.h>
 #include <rte_mempool.h>
-#include <rte_malloc.h>
 
 #include "mlx5_common.h"
 #include "mlx5_common_os.h"
 #include "mlx5_common_utils.h"
-#include "mlx5_malloc.h"
 #include "mlx5_common_pci.h"
 
 int mlx5_common_logtype;
@@ -126,126 +124,6 @@ static inline void mlx5_cpu_id(unsigned int level,
 }
 
 /**
- * Allocate page of door-bells and register it using DevX API.
- *
- * @param [in] ctx
- *   Pointer to the device context.
- *
- * @return
- *   Pointer to new page on success, NULL otherwise.
- */
-static struct mlx5_devx_dbr_page *
-mlx5_alloc_dbr_page(void *ctx)
-{
-	struct mlx5_devx_dbr_page *page;
-
-	/* Allocate space for door-bell page and management data. */
-	page = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
-			   sizeof(struct mlx5_devx_dbr_page),
-			   RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
-	if (!page) {
-		DRV_LOG(ERR, "cannot allocate dbr page");
-		return NULL;
-	}
-	/* Register allocated memory. */
-	page->umem = mlx5_glue->devx_umem_reg(ctx, page->dbrs,
-					      MLX5_DBR_PAGE_SIZE, 0);
-	if (!page->umem) {
-		DRV_LOG(ERR, "cannot umem reg dbr page");
-		mlx5_free(page);
-		return NULL;
-	}
-	return page;
-}
-
-/**
- * Find the next available door-bell, allocate new page if needed.
- *
- * @param [in] ctx
- *   Pointer to device context.
- * @param [in] head
- *   Pointer to the head of dbr pages list.
- * @param [out] dbr_page
- *   Door-bell page containing the page data.
- *
- * @return
- *   Door-bell address offset on success, a negative error value otherwise.
- */
-int64_t
-mlx5_get_dbr(void *ctx,  struct mlx5_dbr_page_list *head,
-	     struct mlx5_devx_dbr_page **dbr_page)
-{
-	struct mlx5_devx_dbr_page *page = NULL;
-	uint32_t i, j;
-
-	LIST_FOREACH(page, head, next)
-		if (page->dbr_count < MLX5_DBR_PER_PAGE)
-			break;
-	if (!page) { /* No page with free door-bell exists. */
-		page = mlx5_alloc_dbr_page(ctx);
-		if (!page) /* Failed to allocate new page. */
-			return (-1);
-		LIST_INSERT_HEAD(head, page, next);
-	}
-	/* Loop to find bitmap part with clear bit. */
-	for (i = 0;
-	     i < MLX5_DBR_BITMAP_SIZE && page->dbr_bitmap[i] == UINT64_MAX;
-	     i++)
-		; /* Empty. */
-	/* Find the first clear bit. */
-	MLX5_ASSERT(i < MLX5_DBR_BITMAP_SIZE);
-	j = rte_bsf64(~page->dbr_bitmap[i]);
-	page->dbr_bitmap[i] |= (UINT64_C(1) << j);
-	page->dbr_count++;
-	*dbr_page = page;
-	return (i * CHAR_BIT * sizeof(uint64_t) + j) * MLX5_DBR_SIZE;
-}
-
-/**
- * Release a door-bell record.
- *
- * @param [in] head
- *   Pointer to the head of dbr pages list.
- * @param [in] umem_id
- *   UMEM ID of page containing the door-bell record to release.
- * @param [in] offset
- *   Offset of door-bell record in page.
- *
- * @return
- *   0 on success, a negative error value otherwise.
- */
-int32_t
-mlx5_release_dbr(struct mlx5_dbr_page_list *head, uint32_t umem_id,
-		 uint64_t offset)
-{
-	struct mlx5_devx_dbr_page *page = NULL;
-	int ret = 0;
-
-	LIST_FOREACH(page, head, next)
-		/* Find the page this address belongs to. */
-		if (mlx5_os_get_umem_id(page->umem) == umem_id)
-			break;
-	if (!page)
-		return -EINVAL;
-	page->dbr_count--;
-	if (!page->dbr_count) {
-		/* Page not used, free it and remove from list. */
-		LIST_REMOVE(page, next);
-		if (page->umem)
-			ret = -mlx5_glue->devx_umem_dereg(page->umem);
-		mlx5_free(page);
-	} else {
-		/* Mark in bitmap that this door-bell is not in use. */
-		offset /= MLX5_DBR_SIZE;
-		int i = offset / 64;
-		int j = offset % 64;
-
-		page->dbr_bitmap[i] &= ~(UINT64_C(1) << j);
-	}
-	return ret;
-}
-
-/**
  * Allocate the User Access Region with DevX on specified device.
  *
  * @param [in] ctx
drivers/common/mlx5/mlx5_common.h +0 -23
index a484b74..e35188d 100644
@@ -220,21 +220,6 @@ enum mlx5_class {
 };
 
 #define MLX5_DBR_SIZE RTE_CACHE_LINE_SIZE
-#define MLX5_DBR_PER_PAGE 64
-/* Must be >= CHAR_BIT * sizeof(uint64_t) */
-#define MLX5_DBR_PAGE_SIZE (MLX5_DBR_PER_PAGE * MLX5_DBR_SIZE)
-/* Page size must be >= 512. */
-#define MLX5_DBR_BITMAP_SIZE (MLX5_DBR_PER_PAGE / (CHAR_BIT * sizeof(uint64_t)))
-
-struct mlx5_devx_dbr_page {
-	/* Door-bell records, must be first member in structure. */
-	uint8_t dbrs[MLX5_DBR_PAGE_SIZE];
-	LIST_ENTRY(mlx5_devx_dbr_page) next; /* Pointer to the next element. */
-	void *umem;
-	uint32_t dbr_count; /* Number of door-bell records in use. */
-	/* 1 bit marks matching door-bell is in use. */
-	uint64_t dbr_bitmap[MLX5_DBR_BITMAP_SIZE];
-};
 
 /* devX creation object */
 struct mlx5_devx_obj {
@@ -249,19 +234,11 @@ struct mlx5_klm {
 	uint64_t address;
 };
 
-LIST_HEAD(mlx5_dbr_page_list, mlx5_devx_dbr_page);
-
 __rte_internal
 void mlx5_translate_port_name(const char *port_name_in,
 			      struct mlx5_switch_info *port_info_out);
 void mlx5_glue_constructor(void);
 __rte_internal
-int64_t mlx5_get_dbr(void *ctx,  struct mlx5_dbr_page_list *head,
-		     struct mlx5_devx_dbr_page **dbr_page);
-__rte_internal
-int32_t mlx5_release_dbr(struct mlx5_dbr_page_list *head, uint32_t umem_id,
-			 uint64_t offset);
-__rte_internal
 void *mlx5_devx_alloc_uar(void *ctx, int mapping);
 extern uint8_t haswell_broadwell_cpu;
 
Signature · 1 line
1.8.3.1