DPDK patches and discussions
 help / color / mirror / Atom feed
From: Srikanth Kaka <srikanth.k@oneconvergence.com>
To: Matan Azrad <matan@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Cc: dev@dpdk.org, Vag Singh <vag.singh@oneconvergence.com>,
	Anand Thulasiram <avelu@juniper.net>,
	Srikanth Kaka <srikanth.k@oneconvergence.com>
Subject: [dpdk-dev] [PATCH v2 14/41] net/mlx5: add open IB device routines
Date: Fri,  8 Oct 2021 00:13:23 +0530	[thread overview]
Message-ID: <20211007184350.73858-15-srikanth.k@oneconvergence.com> (raw)
In-Reply-To: <20211007184350.73858-1-srikanth.k@oneconvergence.com>

The mlx5_os_open_device(), mlx5_config_doorbell_mapping_env(),
mlx5_restore_doorbell_mapping_env(), mlx5_alloc_verbs_buf() and
mlx5_free_verbs_buf() are equivalent to Linux APIs of the same
name

Signed-off-by: Srikanth Kaka <srikanth.k@oneconvergence.com>
Signed-off-by: Vag Singh <vag.singh@oneconvergence.com>
Signed-off-by: Anand Thulasiram <avelu@juniper.net>
---
 drivers/net/mlx5/freebsd/mlx5_os.c | 155 +++++++++++++++++++++++++++++
 1 file changed, 155 insertions(+)

diff --git a/drivers/net/mlx5/freebsd/mlx5_os.c b/drivers/net/mlx5/freebsd/mlx5_os.c
index 1d8e627988..53f74b9d85 100644
--- a/drivers/net/mlx5/freebsd/mlx5_os.c
+++ b/drivers/net/mlx5/freebsd/mlx5_os.c
@@ -5,16 +5,28 @@
  */
 
 #include <stddef.h>
+#include <unistd.h>
+#include <string.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <errno.h>
 
+#include <rte_malloc.h>
+#include <ethdev_driver.h>
+#include <rte_eal_paging.h>
+
 #include <mlx5_glue.h>
+#include <mlx5_devx_cmds.h>
 #include <mlx5_common.h>
+#include <mlx5_common_mr.h>
 
 #include "mlx5_defs.h"
 #include "mlx5.h"
+#include "mlx5_common_os.h"
+#include "mlx5_rxtx.h"
 #include "mlx5_autoconf.h"
+#include "mlx5_mr.h"
+#include "mlx5_verbs.h"
 
 /**
  * Get mlx5 device attributes. The glue function query_device_ex() is called
@@ -86,6 +98,149 @@ mlx5_os_get_dev_attr(void *ctx, struct mlx5_dev_attr *device_attr)
 	return err;
 }
 
+/**
+ * Verbs callback to allocate a memory. This function should allocate the space
+ * according to the size provided residing inside a huge page.
+ * Please note that all allocation must respect the alignment from libmlx5
+ * (i.e. currently rte_mem_page_size()).
+ *
+ * @param[in] size
+ *   The size in bytes of the memory to allocate.
+ * @param[in] data
+ *   A pointer to the callback data.
+ *
+ * @return
+ *   Allocated buffer, NULL otherwise and rte_errno is set.
+ */
+static void *
+mlx5_alloc_verbs_buf(size_t size, void *data)
+{
+	struct mlx5_dev_ctx_shared *sh = data;
+	void *ret;
+	size_t alignment = rte_mem_page_size();
+	if (alignment == (size_t)-1) {
+		DRV_LOG(ERR, "Failed to get mem page size");
+		rte_errno = ENOMEM;
+		return NULL;
+	}
+
+	MLX5_ASSERT(data != NULL);
+	ret = mlx5_malloc(0, size, alignment, sh->numa_node);
+	if (!ret && size)
+		rte_errno = ENOMEM;
+	return ret;
+}
+
+/**
+ * Verbs callback to free a memory.
+ *
+ * @param[in] ptr
+ *   A pointer to the memory to free.
+ * @param[in] data
+ *   A pointer to the callback data.
+ */
+static void
+mlx5_free_verbs_buf(void *ptr, void *data __rte_unused)
+{
+	MLX5_ASSERT(data != NULL);
+	mlx5_free(ptr);
+}
+
+static int
+mlx5_config_doorbell_mapping_env(const struct mlx5_dev_config *config)
+{
+	char *env;
+	int value;
+
+	MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
+	/* Get environment variable to store. */
+	env = getenv(MLX5_SHUT_UP_BF);
+	value = env ? !!strcmp(env, "0") : MLX5_ARG_UNSET;
+	if (config->dbnc == MLX5_ARG_UNSET)
+		setenv(MLX5_SHUT_UP_BF, MLX5_SHUT_UP_BF_DEFAULT, 1);
+	else
+		setenv(MLX5_SHUT_UP_BF,
+		       config->dbnc == MLX5_TXDB_NCACHED ? "1" : "0", 1);
+	return value;
+}
+
+static void
+mlx5_restore_doorbell_mapping_env(int value)
+{
+	MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
+	/* Restore the original environment variable state. */
+	if (value == MLX5_ARG_UNSET)
+		unsetenv(MLX5_SHUT_UP_BF);
+	else
+		setenv(MLX5_SHUT_UP_BF, value ? "1" : "0", 1);
+}
+
+/**
+ * Function API to open IB device.
+ *
+ * This function calls the Linux glue APIs to open a device.
+ *
+ * @param[in] spawn
+ *   Pointer to the IB device attributes (name, port, etc).
+ * @param[out] config
+ *   Pointer to device configuration structure.
+ * @param[out] sh
+ *   Pointer to shared context structure.
+ *
+ * @return
+ *   0 on success, a positive error value otherwise.
+ */
+int
+mlx5_os_open_device(const struct mlx5_dev_spawn_data *spawn,
+		     const struct mlx5_dev_config *config,
+		     struct mlx5_dev_ctx_shared *sh)
+{
+	int dbmap_env;
+	int err = 0;
+
+	pthread_mutex_init(&sh->txpp.mutex, NULL);
+	/*
+	 * Configure environment variable "MLX5_BF_SHUT_UP"
+	 * before the device creation. The rdma_core library
+	 * checks the variable at device creation and
+	 * stores the result internally.
+	 */
+	dbmap_env = mlx5_config_doorbell_mapping_env(config);
+	/* Try to open IB device with DV first, then usual Verbs. */
+	errno = 0;
+	sh->ctx = mlx5_glue->dv_open_device(spawn->phys_dev);
+	if (sh->ctx) {
+		sh->devx = 1;
+		DRV_LOG(DEBUG, "DevX is supported");
+		/* The device is created, no need for environment. */
+		mlx5_restore_doorbell_mapping_env(dbmap_env);
+	} else {
+		/* The environment variable is still configured. */
+		sh->ctx = mlx5_glue->open_device(spawn->phys_dev);
+		err = errno ? errno : ENODEV;
+		/*
+		 * The environment variable is not needed anymore,
+		 * all device creation attempts are completed.
+		 */
+		mlx5_restore_doorbell_mapping_env(dbmap_env);
+		if (!sh->ctx)
+			return err;
+		DRV_LOG(DEBUG, "DevX is NOT supported");
+		err = 0;
+	}
+	if (!err && sh->ctx) {
+		/* Hint libmlx5 to use PMD allocator for data plane resources */
+		mlx5_glue->dv_set_context_attr(sh->ctx,
+			MLX5DV_CTX_ATTR_BUF_ALLOCATORS,
+			(void *)((uintptr_t)&(struct mlx5dv_ctx_allocators){
+				.alloc = &mlx5_alloc_verbs_buf,
+				.free = &mlx5_free_verbs_buf,
+				.data = sh,
+			}));
+	}
+	return err;
+}
+
 /**
  * Set the reg_mr and dereg_mr call backs
  *
-- 
2.30.2


  parent reply	other threads:[~2021-10-08 10:57 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 18:43 [dpdk-dev] [PATCH v2 00/41] add MLX5 FreeBSD support Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 01/41] common/mlx5: add glue files for FreeBSD Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 02/41] common/mlx5: add memory APIs Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 03/41] common/mlx5: add FreeBSD getter functions Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 04/41] common/mlx5: add mlx5_glue_constructor Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 05/41] common/mlx5: add meson support for FreeBSD Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 06/41] net/mlx5: implement device attribute getter Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 07/41] common/mlx5: retrieve the device index and name Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 08/41] common/mlx5: derive PCI addr from device path Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 09/41] net/mlx5: get the FreeBSD interface name Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 10/41] net/mlx5: socket for inter-process communication Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 11/41] common/mlx5: add mr reg/dereg API Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 12/41] net/mlx5: add helpers for MR & HW operations Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 13/41] net/mlx5: define MR callbacks Srikanth Kaka
2021-10-07 18:43 ` Srikanth Kaka [this message]
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 15/41] common/mlx5: add PF_INET socket interface Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 16/41] common/mlx5: add VLAN vmwa structures Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 17/41] net/mlx5: add vlan vmwa stub Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 18/41] net/mlx5: add get MAC Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 19/41] net/mlx5: add get MTU Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 20/41] net/mlx5: add OS MAC routines Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 21/41] net/mlx5: add set MTU routine Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 22/41] net/mlx5: add link state callbacks Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 23/41] net/mlx5: add link update callback Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 24/41] net/mlx5: read device clock Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 25/41] net/mlx5: handle async device events Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 26/41] net/mlx5: add callback to check dev is removed Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 27/41] net/mlx5: add flow control callbacks Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 28/41] net/mlx5: add module callbacks Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 29/41] net/mlx5: added stats support Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 30/41] net/mlx5: add stubs for bonding Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 31/41] net/mlx5: add stub to read hw counters Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 32/41] net/mlx5: add multiprocess support Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 33/41] net/mlx5: add initialization routines Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 34/41] net/mlx5: add flow workspace APIs Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 35/41] net/mlx5: add pci probe and dev spawn support Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 36/41] net/mlx5: set file descriptor as non-blocking Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 37/41] net/mlx5: add routine to extract pdn Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 38/41] net/mlx5: set promisc and allmulti modes Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 39/41] common/mlx5: add stub for mlx5_translate_port_name Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 40/41] net/mlx5: add meson support for FreeBSD Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 41/41] doc/mlx5: update docs with FreeBSD information Srikanth Kaka
2022-05-18  8:21 ` [dpdk-dev] [PATCH v2 00/41] add MLX5 FreeBSD support Thomas Monjalon

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=20211007184350.73858-15-srikanth.k@oneconvergence.com \
    --to=srikanth.k@oneconvergence.com \
    --cc=avelu@juniper.net \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=vag.singh@oneconvergence.com \
    --cc=viacheslavo@nvidia.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).