From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 12873A034F; Mon, 30 Aug 2021 11:16:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CAE9C4113D; Mon, 30 Aug 2021 11:16:45 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id C003640687 for ; Mon, 30 Aug 2021 11:16:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630315003; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NvnJbbDfOmWzlB63VpP95bpcfOTJ3Pl0ANfvEUAV5hQ=; b=SckEo+ySYLa/2waENDE9Q7e2b2BHTVMpuVfKWveG7LBi9Kogyee1FMjrI6EPFf6VAMS5GU qQxCOT/2iAfBC7pdYrLT9mH4Ly6k1oUov3Cr8tNm9HQgJiHHpf7TicAh3qt4yL+07Sb8Yw vVeLGUp4JYWC4pvVx8Gcud6g2jJ97ns= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-UYZdgWqXNYOQNq11qGxddQ-1; Mon, 30 Aug 2021 05:16:39 -0400 X-MC-Unique: UYZdgWqXNYOQNq11qGxddQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9A8087122E; Mon, 30 Aug 2021 09:16:38 +0000 (UTC) Received: from [10.39.208.15] (unknown [10.39.208.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EA07794B0; Mon, 30 Aug 2021 09:16:37 +0000 (UTC) To: Vijay Srivastava , dev@dpdk.org Cc: chenbo.xia@intel.com, andrew.rybchenko@oktetlabs.ru, Vijay Kumar Srivastava References: <20210706164418.32615-1-vsrivast@xilinx.com> <20210706164418.32615-3-vsrivast@xilinx.com> From: Maxime Coquelin Message-ID: Date: Mon, 30 Aug 2021 11:16:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210706164418.32615-3-vsrivast@xilinx.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 02/10] vdpa/sfc: add support for device initialization X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" On 7/6/21 6:44 PM, Vijay Srivastava wrote: > From: Vijay Kumar Srivastava > > Add HW initialization and vDPA device registration support. > > Signed-off-by: Vijay Kumar Srivastava > --- > doc/guides/vdpadevs/sfc.rst | 6 + > drivers/vdpa/sfc/meson.build | 3 + > drivers/vdpa/sfc/sfc_vdpa.c | 23 +++ > drivers/vdpa/sfc/sfc_vdpa.h | 49 +++++- > drivers/vdpa/sfc/sfc_vdpa_debug.h | 21 +++ > drivers/vdpa/sfc/sfc_vdpa_hw.c | 322 ++++++++++++++++++++++++++++++++++++++ > drivers/vdpa/sfc/sfc_vdpa_log.h | 3 + > drivers/vdpa/sfc/sfc_vdpa_mcdi.c | 74 +++++++++ > drivers/vdpa/sfc/sfc_vdpa_ops.c | 129 +++++++++++++++ > drivers/vdpa/sfc/sfc_vdpa_ops.h | 36 +++++ > 10 files changed, 665 insertions(+), 1 deletion(-) > create mode 100644 drivers/vdpa/sfc/sfc_vdpa_debug.h > create mode 100644 drivers/vdpa/sfc/sfc_vdpa_hw.c > create mode 100644 drivers/vdpa/sfc/sfc_vdpa_mcdi.c > create mode 100644 drivers/vdpa/sfc/sfc_vdpa_ops.c > create mode 100644 drivers/vdpa/sfc/sfc_vdpa_ops.h > ... > diff --git a/drivers/vdpa/sfc/sfc_vdpa_hw.c b/drivers/vdpa/sfc/sfc_vdpa_hw.c > new file mode 100644 > index 0000000..83f3696 > --- /dev/null > +++ b/drivers/vdpa/sfc/sfc_vdpa_hw.c > @@ -0,0 +1,322 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * > + * Copyright(c) 2020-2021 Xilinx, Inc. > + */ > + > +#include > + > +#include > +#include > +#include > + > +#include "efx.h" > +#include "sfc_vdpa.h" > +#include "sfc_vdpa_ops.h" > + > +extern uint32_t sfc_logtype_driver; > + > +#ifndef PAGE_SIZE > +#define PAGE_SIZE (sysconf(_SC_PAGESIZE)) > +#endif > + > +int > +sfc_vdpa_dma_alloc(struct sfc_vdpa_adapter *sva, const char *name, > + size_t len, efsys_mem_t *esmp) > +{ > + void *mcdi_buf; > + uint64_t mcdi_iova; > + size_t mcdi_buff_size; > + int ret; > + > + mcdi_buff_size = RTE_ALIGN_CEIL(len, PAGE_SIZE); > + > + sfc_vdpa_log_init(sva, "name=%s, len=%zu", name, len); > + > + mcdi_buf = rte_zmalloc(name, mcdi_buff_size, PAGE_SIZE); You might want to allocate on the same NUMA node the device is on? > + if (mcdi_buf == NULL) { > + sfc_vdpa_err(sva, "cannot reserve memory for %s: len=%#x: %s", > + name, (unsigned int)len, rte_strerror(rte_errno)); > + return -ENOMEM; > + } > + > + /* IOVA address for MCDI would be re-calculated if mapping > + * using default IOVA would fail. > + * TODO: Earlier there was no way to get valid IOVA range. > + * Recently a patch has been submitted to get the IOVA range > + * using ioctl. VFIO_IOMMU_GET_INFO. This patch is available > + * in the kernel version >= 5.4. Support to get the default > + * IOVA address for MCDI buffer using available IOVA range > + * would be added later. Meanwhile default IOVA for MCDI buffer > + * is kept at high mem at 2TB. In case of overlap new available > + * addresses would be searched and same would be used. > + */ > + mcdi_iova = SFC_VDPA_DEFAULT_MCDI_IOVA; > + > + do { > + ret = rte_vfio_container_dma_map(sva->vfio_container_fd, > + (uint64_t)mcdi_buf, mcdi_iova, > + mcdi_buff_size); > + if (ret == 0) > + break; > + > + mcdi_iova = mcdi_iova >> 1; > + if (mcdi_iova < mcdi_buff_size) { > + sfc_vdpa_err(sva, > + "DMA mapping failed for MCDI : %s", > + rte_strerror(rte_errno)); > + return ret; You leak mcdi_buf here if DMA map fails. > + } > + > + } while (ret < 0); > + > + esmp->esm_addr = mcdi_iova; > + esmp->esm_base = mcdi_buf; > + sva->mcdi_buff_size = mcdi_buff_size; > + > + sfc_vdpa_info(sva, > + "DMA name=%s len=%zu => virt=%p iova=%" PRIx64, > + name, len, esmp->esm_base, esmp->esm_addr); > + > + return 0; > +} > + Thanks, Maxime