DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH 10/14] net/sfc: add MCDI callbacks to allocate/free DMA memory
Date: Tue, 8 Sep 2020 10:14:31 +0100
Message-ID: <1599556475-27820-12-git-send-email-arybchenko@solarflare.com> (raw)
In-Reply-To: <1599556475-27820-1-git-send-email-arybchenko@solarflare.com>

Net driver should use rte_eth_dma_zone_reserve(), but it is ethdev
specific API which is not available for vDPA.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
---
 drivers/net/sfc/sfc_mcdi.c | 46 +++++++++++++++++++++++++++++++-------
 drivers/net/sfc/sfc_mcdi.h | 12 ++++++++++
 2 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/drivers/net/sfc/sfc_mcdi.c b/drivers/net/sfc/sfc_mcdi.c
index 928a08c0a2..5077fcddd6 100644
--- a/drivers/net/sfc/sfc_mcdi.c
+++ b/drivers/net/sfc/sfc_mcdi.c
@@ -278,16 +278,22 @@ sfc_efx_mcdi_ev_proxy_response(void *arg, uint32_t handle, efx_rc_t result)
 
 static int
 sfc_efx_mcdi_init(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi,
-		  uint32_t logtype, const char *log_prefix, efx_nic_t *nic)
+		  uint32_t logtype, const char *log_prefix, efx_nic_t *nic,
+		  const struct sfc_efx_mcdi_ops *ops, void *ops_cookie)
 {
 	size_t max_msg_size;
 	efx_mcdi_transport_t *emtp;
 	int rc;
 
+	if (ops->dma_alloc == NULL || ops->dma_free == NULL)
+		return EINVAL;
+
 	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_UNINITIALIZED);
 
 	rte_spinlock_init(&mcdi->lock);
 
+	mcdi->ops = ops;
+	mcdi->ops_cookie = ops_cookie;
 	mcdi->nic = nic;
 
 	mcdi->state = SFC_EFX_MCDI_INITIALIZED;
@@ -296,8 +302,7 @@ sfc_efx_mcdi_init(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi,
 	mcdi->log_prefix = log_prefix;
 
 	max_msg_size = sizeof(uint32_t) + MCDI_CTL_SDU_LEN_MAX_V2;
-	rc = sfc_dma_alloc(sa, "mcdi", 0, max_msg_size, sa->socket_id,
-			   &mcdi->mem);
+	rc = ops->dma_alloc(ops_cookie, "mcdi", max_msg_size, &mcdi->mem);
 	if (rc != 0)
 		goto fail_dma_alloc;
 
@@ -319,7 +324,7 @@ sfc_efx_mcdi_init(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi,
 
 fail_mcdi_init:
 	memset(emtp, 0, sizeof(*emtp));
-	sfc_dma_free(sa, &mcdi->mem);
+	ops->dma_free(ops_cookie, &mcdi->mem);
 
 fail_dma_alloc:
 	mcdi->state = SFC_EFX_MCDI_UNINITIALIZED;
@@ -327,7 +332,7 @@ sfc_efx_mcdi_init(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi,
 }
 
 static void
-sfc_efx_mcdi_fini(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi)
+sfc_efx_mcdi_fini(struct sfc_efx_mcdi *mcdi)
 {
 	efx_mcdi_transport_t *emtp;
 
@@ -345,9 +350,33 @@ sfc_efx_mcdi_fini(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi)
 
 	rte_spinlock_unlock(&mcdi->lock);
 
-	sfc_dma_free(sa, &mcdi->mem);
+	mcdi->ops->dma_free(mcdi->ops_cookie, &mcdi->mem);
+}
+
+static sfc_efx_mcdi_dma_alloc_cb sfc_mcdi_dma_alloc;
+static int
+sfc_mcdi_dma_alloc(void *cookie, const char *name, size_t len,
+		   efsys_mem_t *esmp)
+{
+	const struct sfc_adapter *sa = cookie;
+
+	return sfc_dma_alloc(sa, name, 0, len, sa->socket_id, esmp);
 }
 
+static sfc_efx_mcdi_dma_free_cb sfc_mcdi_dma_free;
+static void
+sfc_mcdi_dma_free(void *cookie, efsys_mem_t *esmp)
+{
+	const struct sfc_adapter *sa = cookie;
+
+	sfc_dma_free(sa, esmp);
+}
+
+static const struct sfc_efx_mcdi_ops sfc_mcdi_ops = {
+	.dma_alloc	= sfc_mcdi_dma_alloc,
+	.dma_free	= sfc_mcdi_dma_free,
+};
+
 int
 sfc_mcdi_init(struct sfc_adapter *sa)
 {
@@ -360,12 +389,13 @@ sfc_mcdi_init(struct sfc_adapter *sa)
 				       RTE_LOG_NOTICE);
 
 	return sfc_efx_mcdi_init(sa, &sa->mcdi, logtype,
-				 sa->priv.shared->log_prefix, sa->nic);
+				 sa->priv.shared->log_prefix, sa->nic,
+				 &sfc_mcdi_ops, sa);
 }
 
 void
 sfc_mcdi_fini(struct sfc_adapter *sa)
 {
 	sfc_log_init(sa, "entry");
-	sfc_efx_mcdi_fini(sa, &sa->mcdi);
+	sfc_efx_mcdi_fini(&sa->mcdi);
 }
diff --git a/drivers/net/sfc/sfc_mcdi.h b/drivers/net/sfc/sfc_mcdi.h
index b93b268e32..ef24a8bc67 100644
--- a/drivers/net/sfc/sfc_mcdi.h
+++ b/drivers/net/sfc/sfc_mcdi.h
@@ -32,8 +32,20 @@ enum sfc_efx_mcdi_state {
 	SFC_EFX_MCDI_NSTATES
 };
 
+typedef int (sfc_efx_mcdi_dma_alloc_cb)(void *cookie, const char *name,
+					  size_t len, efsys_mem_t *esmp);
+
+typedef void (sfc_efx_mcdi_dma_free_cb)(void *cookie, efsys_mem_t *esmp);
+
+struct sfc_efx_mcdi_ops {
+	sfc_efx_mcdi_dma_alloc_cb	*dma_alloc;
+	sfc_efx_mcdi_dma_free_cb	*dma_free;
+};
+
 struct sfc_efx_mcdi {
 	rte_spinlock_t			lock;
+	const struct sfc_efx_mcdi_ops	*ops;
+	void				*ops_cookie;
 	efx_nic_t			*nic;
 	efsys_mem_t			mem;
 	enum sfc_efx_mcdi_state		state;
-- 
2.17.1


  parent reply	other threads:[~2020-09-08  9:18 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08  9:14 [dpdk-dev] [PATCH 00/14] net/sfc: factor out common driver library Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 01/14] net/iavf: downgrade error log Andrew Rybchenko
2020-09-08  9:26   ` Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 01/14] net/sfc: include header with debug helpers directly Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 02/14] net/sfc: introduce common driver library Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 03/14] net/sfc: add dedicated header file with MCDI interface Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 04/14] net/sfc: move MCDI helper interface to dedicated namespace Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 05/14] net/sfc: make MCDI logging helper macros local Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 06/14] net/sfc: start to make MCDI helpers interface shareable Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 07/14] net/sfc: use own logging helper macros Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 08/14] net/sfc: avoid usage of NIC pointer from adapter context Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 09/14] net/sfc: avoid panic in the case of MCDI timeout Andrew Rybchenko
2020-09-08  9:14 ` Andrew Rybchenko [this message]
2020-09-08  9:14 ` [dpdk-dev] [PATCH 11/14] net/sfc: add MCDI callback to schedule restart Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 12/14] net/sfc: add MCDI callback to poll management event queue Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 13/14] net/sfc: use MCDI control structure as libefx ops context Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 14/14] net/sfc: move MCDI helpers to common driver Andrew Rybchenko
2020-09-09 14:32 ` [dpdk-dev] [PATCH 00/14] net/sfc: factor out common driver library Ferruh Yigit
2020-09-17  6:21   ` Andrew Rybchenko
2020-09-17  6:34 ` [dpdk-dev] [PATCH v2 00/17] " Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 01/17] net/sfc/base: add missing extern storage-class specifiers Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 02/17] net/sfc/base: decorate libefx API functions Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 03/17] net/sfc/base: decorate libefx internal extern functions Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 04/17] net/sfc: include header with debug helpers directly Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 05/17] net/sfc: introduce common driver library Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 06/17] net/sfc: add dedicated header file with MCDI interface Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 07/17] net/sfc: move MCDI helper interface to dedicated namespace Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 08/17] net/sfc: make MCDI logging helper macros local Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 09/17] net/sfc: start to make MCDI helpers interface shareable Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 10/17] net/sfc: use own logging helper macros Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 11/17] net/sfc: avoid usage of NIC pointer from adapter context Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 12/17] net/sfc: avoid panic in the case of MCDI timeout Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 13/17] net/sfc: add MCDI callbacks to allocate/free DMA memory Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 14/17] net/sfc: add MCDI callback to schedule restart Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 15/17] net/sfc: add MCDI callback to poll management event queue Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 16/17] net/sfc: use MCDI control structure as libefx ops context Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 17/17] net/sfc: move MCDI helpers to common driver Andrew Rybchenko
2020-09-21 22:38   ` [dpdk-dev] [PATCH v2 00/17] net/sfc: factor out common driver library Ferruh Yigit

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=1599556475-27820-12-git-send-email-arybchenko@solarflare.com \
    --to=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    /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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git