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 1162A42C04; Thu, 1 Jun 2023 17:07:32 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0421942D31; Thu, 1 Jun 2023 17:07:32 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 5AD3A4161A for ; Thu, 1 Jun 2023 17:07:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685632049; 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=HcINjpOmMoJyQENPDQt0eUXhT5mDpb6JUGbHp3/6lEs=; b=Bus4LT8ZssR1gTDxUPmiZDrPx2wLILlUAHTq1DHqtz2SX+2xSJ5FBMUJoxPJmhlhTRIFZM aQL1jnVm0xtbHjhqD0gwehog81k79eZgbFB+aVLR7ypkBDYnYU5uqgc/4qCzFT9QUt08Br UgkeHXm5FdDCtyf3ecA9S4ralgthagM= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-LHcXZX3HOG25TPW6CFO_3A-1; Thu, 01 Jun 2023 11:07:23 -0400 X-MC-Unique: LHcXZX3HOG25TPW6CFO_3A-1 Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-518d6f87a47so330599a12.3 for ; Thu, 01 Jun 2023 08:07:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632034; x=1688224034; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HcINjpOmMoJyQENPDQt0eUXhT5mDpb6JUGbHp3/6lEs=; b=bX9LP5BNDZfWgCGaSlMMAK563wSxTIGxQ9tyDTl0q1sGmoA9+eeoaesHn7wvk6iILD nrjVynVGwUlZ8uwpj73FW61Ynntl0A65+l5hp4YB4bz+EE9GMml/cfdSBvjuNXzyRZgz IpKuJe5fsODOEvcvuwkaHD5i1M6bFRKa7eGswjngurIp/6end76Ci7wUm2i+Ef6UJ3Vl sykdaEzp+HawTztk53hEBkjUHsl5hdFZ93LCWTYWYRbwEE3h/lnQt6/con7fLfbscdXM pkWrwlgIiJFPX1LPgqP2SHvrvm3ODmSrrqCVDeCtCsmL3w2DJw1aWK7N/cU34LVgQCrj jA9w== X-Gm-Message-State: AC+VfDxat2VQXgVljLHnUWMqJPhaeM030tXoY2KNmlY9sle/Qa7ITZA6 VbpMmq+wlyoyUqP4my2aV29ZDxkkgz+9qyTQ1g22CgWlJ+QymolZQgRyphLHRpmv33VvlzaMCdE 2qqlQxWCHwekoFI/NdHE= X-Received: by 2002:a17:902:bf4b:b0:1b1:af8e:d31d with SMTP id u11-20020a170902bf4b00b001b1af8ed31dmr461852pls.40.1685632034161; Thu, 01 Jun 2023 08:07:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4G8MZYZWVyN6DElNP3HQ7TffUH7eRlHMDI1gznFYTskHT9FwyewIJVfX6KlyNIyYuaKhrWUemv5YDIKZ78eEo= X-Received: by 2002:a17:902:bf4b:b0:1b1:af8e:d31d with SMTP id u11-20020a170902bf4b00b001b1af8ed31dmr461826pls.40.1685632033851; Thu, 01 Jun 2023 08:07:13 -0700 (PDT) MIME-Version: 1.0 References: <20230124140746.594066-1-nipun.gupta@amd.com> <20230525100821.12148-1-nipun.gupta@amd.com> <20230525100821.12148-3-nipun.gupta@amd.com> In-Reply-To: <20230525100821.12148-3-nipun.gupta@amd.com> From: David Marchand Date: Thu, 1 Jun 2023 17:07:02 +0200 Message-ID: Subject: Re: [PATCH v5 2/5] bus/cdx: add DMA map and unmap support To: Nipun Gupta Cc: dev@dpdk.org, thomas@monjalon.net, hkalra@marvell.com, anatoly.burakov@intel.com, stephen@networkplumber.org, ferruh.yigit@amd.com, harpreet.anand@amd.com, nikhil.agarwal@amd.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Thu, May 25, 2023 at 12:09=E2=80=AFPM Nipun Gupta = wrote: > > AMD CDX bus can use VFIO interface for mapping and unmapping > of DMA addresses in the IOMMU. This change adds the callback > support for map and unmap APIs as well as fetching the IOMMU > class. > > Signed-off-by: Nipun Gupta > Acked-by: Ferruh Yigit > --- > drivers/bus/cdx/cdx.c | 40 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 40 insertions(+) > > diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c > index 1ddb5a92f7..64ea879f3b 100644 > --- a/drivers/bus/cdx/cdx.c > +++ b/drivers/bus/cdx/cdx.c > @@ -502,12 +502,52 @@ cdx_find_device(const struct rte_device *start, rte= _dev_cmp_t cmp, > return NULL; > } > > +static int > +cdx_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t le= n) > +{ > + struct rte_cdx_device *cdx_dev =3D RTE_DEV_TO_CDX_DEV(dev); > + > + if (!cdx_dev) { > + rte_errno =3D EINVAL; > + return -1; > + } RTE_DEV_TO_CDX_DEV() applies an offset to dev. Checking dev !=3D NULL is probably a better check. But on the other hand, calling this dma_map op will be done through dev->bus->dma_map. So checking dev is useless too. > + > + return rte_vfio_container_dma_map(RTE_VFIO_DEFAULT_CONTAINER_FD, > + (uintptr_t)addr, iova, len); > +} > + > +static int > +cdx_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t = len) > +{ > + struct rte_cdx_device *cdx_dev =3D RTE_DEV_TO_CDX_DEV(dev); > + > + if (!cdx_dev) { > + rte_errno =3D EINVAL; > + return -1; > + } Idem. > + > + return rte_vfio_container_dma_unmap(RTE_VFIO_DEFAULT_CONTAINER_FD= , > + (uintptr_t)addr, iova, len); > +} > + > +static enum rte_iova_mode > +cdx_get_iommu_class(void) > +{ > + if (TAILQ_EMPTY(&rte_cdx_bus.device_list)) > + return RTE_IOVA_DC; > + > + return RTE_IOVA_VA; > +} > + > struct rte_cdx_bus rte_cdx_bus =3D { > .bus =3D { > .scan =3D cdx_scan, > .probe =3D cdx_probe, > .find_device =3D cdx_find_device, > .parse =3D cdx_parse, > + .dma_map =3D cdx_dma_map, > + .dma_unmap =3D cdx_dma_unmap, > + .get_iommu_class =3D cdx_get_iommu_class, > }, > .device_list =3D TAILQ_HEAD_INITIALIZER(rte_cdx_bus.device_list), > .driver_list =3D TAILQ_HEAD_INITIALIZER(rte_cdx_bus.driver_list), > -- > 2.17.1 > --=20 David Marchand