From patchwork Thu Sep 17 06:34:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Rybchenko X-Patchwork-Id: 77997 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 456A7A04B6; Thu, 17 Sep 2020 08:37:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 37F851D588; Thu, 17 Sep 2020 08:35:41 +0200 (CEST) Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [148.163.129.52]) by dpdk.org (Postfix) with ESMTP id 2289D1D548 for ; Thu, 17 Sep 2020 08:35:23 +0200 (CEST) Received: from mx1-us1.ppe-hosted.com (unknown [10.7.65.62]) by dispatch1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTP id 934DE60066 for ; Thu, 17 Sep 2020 06:35:22 +0000 (UTC) Received: from us4-mdac16-70.ut7.mdlocal (unknown [10.7.64.189]) by mx1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTP id 8644D800A3 for ; Thu, 17 Sep 2020 06:35:22 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from mx1-us1.ppe-hosted.com (unknown [10.7.66.30]) by mx1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id 169B328004D for ; Thu, 17 Sep 2020 06:35:22 +0000 (UTC) Received: from webmail.solarflare.com (uk.solarflare.com [193.34.186.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mx1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id ABAD810005E for ; Thu, 17 Sep 2020 06:35:21 +0000 (UTC) Received: from ukex01.SolarFlarecom.com (10.17.10.4) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 17 Sep 2020 07:35:12 +0100 Received: from opal.uk.solarflarecom.com (10.17.10.1) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 17 Sep 2020 07:35:12 +0100 Received: from ukv-loginhost.uk.solarflarecom.com (ukv-loginhost.uk.solarflarecom.com [10.17.10.39]) by opal.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id 08H6ZCK9002509 for ; Thu, 17 Sep 2020 07:35:12 +0100 Received: from ukv-loginhost.uk.solarflarecom.com (localhost [127.0.0.1]) by ukv-loginhost.uk.solarflarecom.com (Postfix) with ESMTP id 849241613AB for ; Thu, 17 Sep 2020 07:35:12 +0100 (BST) From: Andrew Rybchenko To: Date: Thu, 17 Sep 2020 07:34:39 +0100 Message-ID: <1600324483-23153-14-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600324483-23153-1-git-send-email-arybchenko@solarflare.com> References: <1599556475-27820-1-git-send-email-arybchenko@solarflare.com> <1600324483-23153-1-git-send-email-arybchenko@solarflare.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.6.1012-25670.003 X-TM-AS-Result: No-7.265700-8.000000-10 X-TMASE-MatchedRID: klLfDUJzcbG/kNGHVZrsls50DGuIExk9UXlp1FHYSPVwkdIrVt8X1dN+ VO8UR4MhfGzuoVn0Vs6PQi9XuOWoOLQHnhaRx4GgMy+jMkhCdFbYuVu0X/rOkPYENPLTaMhvlSY jj5D227bG42pGgsfFnI2Ow18fgOyZKjPlgWuJZGwk/b03uBR3ULpKkQnaF6lazdATtc2zn0DlbG AwGirFMOJRsev36MRgiiiUp2zjfThf7y77NDsmYp4CIKY/Hg3AGdQnQSTrKGPEQdG7H66TyMdRT 5TQAJnASWt0iRbOvZk/863Ch77M8LV3TVOy7ItOvVBQZC5rCkGeqD9WtJkSIw== X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--7.265700-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.6.1012-25670.003 X-MDID: 1600324522-vj1Bzhi3Zt5P Subject: [dpdk-dev] [PATCH v2 13/17] net/sfc: add MCDI callbacks to allocate/free DMA memory X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Reviewed-by: Andy Moreton --- 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;