From: Matan Azrad <matan@mellanox.com>
To: Shahaf Shuler <shahafs@mellanox.com>,
Yongseok Koh <yskoh@mellanox.com>,
Viacheslav Ovsiienko <viacheslavo@mellanox.com>
Cc: dev@dpdk.org, Dekel Peled <dekelp@mellanox.com>
Subject: [dpdk-dev] [PATCH 13/28] net/mlx5: allocate door-bells using new API
Date: Mon, 22 Jul 2019 09:13:00 +0000 [thread overview]
Message-ID: <1563786795-14027-14-git-send-email-matan@mellanox.com> (raw)
In-Reply-To: <1563786795-14027-1-git-send-email-matan@mellanox.com>
From: Dekel Peled <dekelp@mellanox.com>
When using DevX API, memory for door-bell records should be allocated
by PMD and registered using DevX API.
This patch implements the utility functions to support it:
- Add struct mlx5_devx_dbr_page, containing door-bells page data.
- Add list of struct mlx5_devx_dbr_page door-bell pages to device
private data.
- Implement function mlx5_alloc_dbr_page() to allocate page for
door-bell records, and register it using DevX API.
- Implement function mlx5_get_dbr(). to acquire a door-bell record
from the door-bells page, allocating a new page if needed.
- Implement function mlx5_release_dbr() to release a door-bell
record that is no longer needed, freeing the containing page if
it becomes empty.
Signed-off-by: Dekel Peled <dekelp@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
---
drivers/net/mlx5/mlx5.c | 119 +++++++++++++++++++++++++++++++++++++++++++
drivers/net/mlx5/mlx5.h | 21 ++++++++
drivers/net/mlx5/mlx5_rxtx.h | 1 +
3 files changed, 141 insertions(+)
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 8d0ebeb..6b878da 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -1312,6 +1312,125 @@ struct mlx5_dev_spawn_data {
}
/**
+ * Allocate page of door-bells and register it using DevX API.
+ *
+ * @param [in] dev
+ * Pointer to Ethernet device.
+ *
+ * @return
+ * Pointer to new page on success, NULL otherwise.
+ */
+static struct mlx5_devx_dbr_page *
+mlx5_alloc_dbr_page(struct rte_eth_dev *dev)
+{
+ struct mlx5_priv *priv = dev->data->dev_private;
+ struct mlx5_devx_dbr_page *page;
+
+ /* Allocate space for door-bell page and management data. */
+ page = rte_calloc_socket(__func__, 1, sizeof(struct mlx5_devx_dbr_page),
+ RTE_CACHE_LINE_SIZE, dev->device->numa_node);
+ if (!page) {
+ DRV_LOG(ERR, "port %u cannot allocate dbr page",
+ dev->data->port_id);
+ return NULL;
+ }
+ /* Register allocated memory. */
+ page->umem = mlx5_glue->devx_umem_reg(priv->sh->ctx, page->dbrs,
+ MLX5_DBR_PAGE_SIZE, 0);
+ if (!page->umem) {
+ DRV_LOG(ERR, "port %u cannot umem reg dbr page",
+ dev->data->port_id);
+ rte_free(page);
+ return NULL;
+ }
+ return page;
+}
+
+/**
+ * Find the next available door-bell, allocate new page if needed.
+ *
+ * @param [in] dev
+ * Pointer to Ethernet device.
+ * @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(struct rte_eth_dev *dev, struct mlx5_devx_dbr_page **dbr_page)
+{
+ struct mlx5_priv *priv = dev->data->dev_private;
+ struct mlx5_devx_dbr_page *page = NULL;
+ uint32_t i, j;
+
+ LIST_FOREACH(page, &priv->dbrpgs, next)
+ if (page->dbr_count < MLX5_DBR_PER_PAGE)
+ break;
+ if (!page) { /* No page with free door-bell exists. */
+ page = mlx5_alloc_dbr_page(dev);
+ if (!page) /* Failed to allocate new page. */
+ return (-1);
+ LIST_INSERT_HEAD(&priv->dbrpgs, 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. */
+ j = rte_bsf64(~page->dbr_bitmap[i]);
+ assert(i < (MLX5_DBR_PER_PAGE / 64));
+ page->dbr_bitmap[i] |= (1 << j);
+ page->dbr_count++;
+ *dbr_page = page;
+ return (((i * 64) + j) * sizeof(uint64_t));
+}
+
+/**
+ * Release a door-bell record.
+ *
+ * @param [in] dev
+ * Pointer to Ethernet device.
+ * @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 rte_eth_dev *dev, uint32_t umem_id, uint64_t offset)
+{
+ struct mlx5_priv *priv = dev->data->dev_private;
+ struct mlx5_devx_dbr_page *page = NULL;
+ int ret = 0;
+
+ LIST_FOREACH(page, &priv->dbrpgs, next)
+ /* Find the page this address belongs to. */
+ if (page->umem->umem_id == 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);
+ rte_free(page);
+ } else {
+ /* Mark in bitmap that this door-bell is not in use. */
+ int i = offset / 64;
+ int j = offset % 64;
+
+ page->dbr_bitmap[i] &= ~(1 << j);
+ }
+ return ret;
+}
+
+/**
* Spawn an Ethernet device from Verbs information.
*
* @param dpdk_dev
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 8d72b2d..1543aaf 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -36,6 +36,7 @@
#include "mlx5_mr.h"
#include "mlx5_autoconf.h"
#include "mlx5_defs.h"
+#include "mlx5_glue.h"
enum {
PCI_VENDOR_ID_MELLANOX = 0x15b3,
@@ -498,6 +499,21 @@ struct mlx5_flow_tbl_resource {
#define MLX5_MAX_TABLES_FDB 32
#define MLX5_GROUP_FACTOR 1
+#define MLX5_DBR_PAGE_SIZE 4096 /* Must be >= 512. */
+#define MLX5_DBR_SIZE 8
+#define MLX5_DBR_PER_PAGE (MLX5_DBR_PAGE_SIZE / MLX5_DBR_SIZE)
+#define MLX5_DBR_BITMAP_SIZE (MLX5_DBR_PER_PAGE / 64)
+
+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. */
+ struct mlx5dv_devx_umem *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];
+};
+
/*
* Shared Infiniband device context for Master/Representors
* which belong to same IB device with multiple IB ports.
@@ -617,6 +633,7 @@ struct mlx5_priv {
int nl_socket_rdma; /* Netlink socket (NETLINK_RDMA). */
int nl_socket_route; /* Netlink socket (NETLINK_ROUTE). */
uint32_t nl_sn; /* Netlink message sequence number. */
+ LIST_HEAD(dbrpage, mlx5_devx_dbr_page) dbrpgs; /* Door-bell pages. */
#ifndef RTE_ARCH_64
rte_spinlock_t uar_lock_cq; /* CQs share a common distinct UAR */
rte_spinlock_t uar_lock[MLX5_UAR_PAGE_NUM_MAX];
@@ -631,6 +648,10 @@ struct mlx5_priv {
int mlx5_getenv_int(const char *);
int mlx5_proc_priv_init(struct rte_eth_dev *dev);
+int64_t mlx5_get_dbr(struct rte_eth_dev *dev,
+ struct mlx5_devx_dbr_page **dbr_page);
+int32_t mlx5_release_dbr(struct rte_eth_dev *dev, uint32_t umem_id,
+ uint64_t offset);
/* mlx5_ethdev.c */
diff --git a/drivers/net/mlx5/mlx5_rxtx.h b/drivers/net/mlx5/mlx5_rxtx.h
index 2f688ac..436b453 100644
--- a/drivers/net/mlx5/mlx5_rxtx.h
+++ b/drivers/net/mlx5/mlx5_rxtx.h
@@ -29,6 +29,7 @@
#include <rte_spinlock.h>
#include <rte_io.h>
#include <rte_bus_pci.h>
+#include <rte_malloc.h>
#include "mlx5_utils.h"
#include "mlx5.h"
--
1.8.3.1
next prev parent reply other threads:[~2019-07-22 9:14 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-22 9:12 [dpdk-dev] [PATCH 00/28] net/mlx5: support LRO Matan Azrad
2019-07-22 9:12 ` [dpdk-dev] [PATCH 01/28] net/mlx5: remove redundant item from union Matan Azrad
2019-07-22 9:17 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 02/28] net/mlx5: add LRO APIs and initial settings Matan Azrad
2019-07-22 9:25 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 03/28] net/mlx5: support LRO caps query using devx API Matan Azrad
2019-07-22 9:17 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 04/28] net/mlx5: glue func for queue query using new API Matan Azrad
2019-07-22 9:18 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 05/28] net/mlx5: glue function for action " Matan Azrad
2019-07-22 9:18 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 06/28] net/mlx5: check conditions to enable LRO Matan Azrad
2019-07-22 9:18 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 07/28] net/mlx5: support Tx interface query using new API Matan Azrad
2019-07-22 9:19 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 08/28] net/mlx5: update Tx queue create for LRO Matan Azrad
2019-07-22 9:18 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 09/28] net/mlx5: create advanced RxQ object using new API Matan Azrad
2019-07-22 9:17 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 10/28] net/mlx5: modify " Matan Azrad
2019-07-22 9:20 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 11/28] net/mlx5: create advanced Rx " Matan Azrad
2019-07-22 9:20 ` Slava Ovsiienko
2019-07-22 9:12 ` [dpdk-dev] [PATCH 12/28] net/mlx5: create advanced RxQ table " Matan Azrad
2019-07-22 9:21 ` Slava Ovsiienko
2019-07-22 9:13 ` Matan Azrad [this message]
2019-07-22 9:20 ` [dpdk-dev] [PATCH 13/28] net/mlx5: allocate door-bells " Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 14/28] net/mlx5: rename RxQ verbs to general RxQ object Matan Azrad
2019-07-22 9:22 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 15/28] net/mlx5: rename verbs indirection table to obj Matan Azrad
2019-07-22 9:22 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 16/28] net/mlx5: rename hash RxQ verbs to general Matan Azrad
2019-07-22 9:22 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 17/28] net/mlx5: update queue state modify function Matan Azrad
2019-07-22 9:22 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 18/28] net/mlx5: store protection domain number on create Matan Azrad
2019-07-22 9:21 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 19/28] net/mlx5: func to create Rx verbs completion queue Matan Azrad
2019-07-22 9:23 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 20/28] net/mlx5: function to create Rx verbs work queue Matan Azrad
2019-07-22 9:21 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 21/28] net/mlx5: create advanced RxQ using new API Matan Azrad
2019-07-22 9:21 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 22/28] net/mlx5: support LRO with single RxQ object Matan Azrad
2019-07-22 9:22 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 23/28] net/mlx5: replace the external mbuf shared memory Matan Azrad
2019-07-22 9:21 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 24/28] net/mlx5: update LRO fields in completion entry Matan Azrad
2019-07-22 9:23 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 25/28] net/mlx5: handle LRO packets in Rx queue Matan Azrad
2019-07-22 9:26 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 26/28] net/mlx5: zero the LRO mbuf headroom Matan Azrad
2019-07-22 9:23 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 27/28] net/mlx5: adjust the maximum LRO message size Matan Azrad
2019-07-22 9:23 ` Slava Ovsiienko
2019-07-22 9:13 ` [dpdk-dev] [PATCH 28/28] doc: update MLX5 doc and release notes with LRO Matan Azrad
2019-07-22 9:23 ` Slava Ovsiienko
2019-07-22 10:42 ` [dpdk-dev] [PATCH 00/28] net/mlx5: support LRO Raslan Darawsheh
2019-07-22 12:48 ` Ferruh Yigit
2019-07-22 13:32 ` Matan Azrad
2019-07-22 14:51 ` [dpdk-dev] [PATCH v2 " Matan Azrad
2019-07-22 14:51 ` [dpdk-dev] [PATCH v2 01/28] net/mlx5: remove redundant item from union Matan Azrad
2019-07-23 10:53 ` Ferruh Yigit
2019-07-23 12:10 ` Matan Azrad
2019-07-22 14:51 ` [dpdk-dev] [PATCH v2 02/28] net/mlx5: add LRO APIs and initial settings Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 03/28] net/mlx5: support LRO caps query using devx API Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 04/28] net/mlx5: glue func for queue query using new API Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 05/28] net/mlx5: glue function for action " Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 06/28] net/mlx5: check conditions to enable LRO Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 07/28] net/mlx5: support Tx interface query using new API Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 08/28] net/mlx5: update Tx queue create for LRO Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 09/28] net/mlx5: create advanced RxQ object using new API Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 10/28] net/mlx5: modify " Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 11/28] net/mlx5: create advanced Rx " Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 12/28] net/mlx5: create advanced RxQ table " Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 13/28] net/mlx5: allocate door-bells " Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 14/28] net/mlx5: rename RxQ verbs to general RxQ object Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 15/28] net/mlx5: rename verbs indirection table to obj Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 16/28] net/mlx5: rename hash RxQ verbs to general Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 17/28] net/mlx5: update queue state modify function Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 18/28] net/mlx5: store protection domain number on create Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 19/28] net/mlx5: func to create Rx verbs completion queue Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 20/28] net/mlx5: function to create Rx verbs work queue Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 21/28] net/mlx5: create advanced RxQ using new API Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 22/28] net/mlx5: support LRO with single RxQ object Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 23/28] net/mlx5: replace the external mbuf shared memory Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 24/28] net/mlx5: update LRO fields in completion entry Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 25/28] net/mlx5: handle LRO packets in Rx queue Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 26/28] net/mlx5: zero the LRO mbuf headroom Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 27/28] net/mlx5: adjust the maximum LRO message size Matan Azrad
2019-07-22 14:52 ` [dpdk-dev] [PATCH v2 28/28] doc: update MLX5 doc and release notes with LRO Matan Azrad
2019-07-23 6:48 ` [dpdk-dev] [PATCH v2 00/28] net/mlx5: support LRO Raslan Darawsheh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1563786795-14027-14-git-send-email-matan@mellanox.com \
--to=matan@mellanox.com \
--cc=dekelp@mellanox.com \
--cc=dev@dpdk.org \
--cc=shahafs@mellanox.com \
--cc=viacheslavo@mellanox.com \
--cc=yskoh@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).