From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 70B2FA0487 for ; Wed, 3 Jul 2019 18:21:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 33B0CF04; Wed, 3 Jul 2019 18:21:54 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 548A4271 for ; Wed, 3 Jul 2019 18:21:52 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91DEBC057F2E; Wed, 3 Jul 2019 16:21:48 +0000 (UTC) Received: from dhcp-25.97.bos.redhat.com (ovpn-118-63.phx2.redhat.com [10.3.118.63]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A96FF832AE; Wed, 3 Jul 2019 16:21:40 +0000 (UTC) From: Aaron Conole To: Bruce Richardson Cc: dev@dpdk.org, jiayu.hu@intel.com, Anatoly Burakov , Harry van Haaren References: <20190530212525.40370-1-bruce.richardson@intel.com> <20190702141230.31925-1-bruce.richardson@intel.com> <20190702141230.31925-8-bruce.richardson@intel.com> Date: Wed, 03 Jul 2019 12:21:39 -0400 In-Reply-To: <20190702141230.31925-8-bruce.richardson@intel.com> (Bruce Richardson's message of "Tue, 2 Jul 2019 15:12:28 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 03 Jul 2019 16:21:48 +0000 (UTC) Subject: Re: [dpdk-dev] [PATCH v5 7/9] raw/ioat: add configure, start and stop functions 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" Bruce Richardson writes: > Allow initializing a driver instance. Include selftest to validate these > functions. > > Signed-off-by: Bruce Richardson > Acked-by: Anatoly Burakov > Tested-by: Harry van Haaren > --- > > V4: Guarantee correct SUCCESS/FAILURE return values from test function > Use memzone rather than malloc for ring allocation so we can guarantee > contiguous memory. > V3: don't add a new descriptor format struct, reuse from rte_ioat_spec.h > V2: test cases placed in self-test routine > --- > app/test/test_rawdev.c | 3 +- > doc/guides/rawdevs/ioat_rawdev.rst | 32 +++++++++++ > drivers/raw/ioat/Makefile | 1 + > drivers/raw/ioat/ioat_rawdev.c | 82 +++++++++++++++++++++++++++++ > drivers/raw/ioat/ioat_rawdev_test.c | 41 +++++++++++++++ > drivers/raw/ioat/meson.build | 3 +- > drivers/raw/ioat/rte_ioat_rawdev.h | 2 + > 7 files changed, 162 insertions(+), 2 deletions(-) > create mode 100644 drivers/raw/ioat/ioat_rawdev_test.c > > diff --git a/app/test/test_rawdev.c b/app/test/test_rawdev.c > index 623117af9..524a9d5f3 100644 > --- a/app/test/test_rawdev.c > +++ b/app/test/test_rawdev.c > @@ -36,7 +36,8 @@ test_rawdev_selftest_ioat(void) > struct rte_rawdev_info info =3D { .dev_private =3D NULL }; > if (rte_rawdev_info_get(i, &info) =3D=3D 0 && > strstr(info.driver_name, "ioat") !=3D NULL) > - return TEST_SUCCESS; > + return rte_rawdev_selftest(i) =3D=3D 0 ? > + TEST_SUCCESS : TEST_FAILED; > } >=20=20 > printf("No IOAT rawdev found, skipping tests\n"); > diff --git a/doc/guides/rawdevs/ioat_rawdev.rst b/doc/guides/rawdevs/ioat= _rawdev.rst > index efed9c64c..a0594d2cb 100644 > --- a/doc/guides/rawdevs/ioat_rawdev.rst > +++ b/doc/guides/rawdevs/ioat_rawdev.rst > @@ -117,3 +117,35 @@ the ``dev_private`` field in the ``rte_rawdev_info``= struct should either > be NULL, or else be set to point to a structure of type > ``rte_ioat_rawdev_config``, in which case the size of the configured dev= ice > input ring will be returned in that structure. > + > +Device Configuration > +~~~~~~~~~~~~~~~~~~~~~ > + > +Configuring an IOAT rawdev device is done using the > +``rte_rawdev_configure()`` API, which takes the same structure parameters > +as the, previously referenced, ``rte_rawdev_info_get()`` API. The main > +difference is that, because the parameter is used as input rather than > +output, the ``dev_private`` structure element cannot be NULL, and must > +point to a valid ``rte_ioat_rawdev_config`` structure, containing the ri= ng > +size to be used by the device. The ring size must be a power of two, > +between 64 and 4096. > + > +The following code shows how the device is configured in > +``test_ioat_rawdev.c``: > + > +.. code-block:: C > + > + #define IOAT_TEST_RINGSIZE 512 > + struct rte_ioat_rawdev_config p =3D { .ring_size =3D -1 }; > + struct rte_rawdev_info info =3D { .dev_private =3D &p }; > + > + /* ... */ > + > + p.ring_size =3D IOAT_TEST_RINGSIZE; > + if (rte_rawdev_configure(dev_id, &info) !=3D 0) { > + printf("Error with rte_rawdev_configure()\n"); > + return -1; > + } > + > +Once configured, the device can then be made ready for use by calling the > +``rte_rawdev_start()`` API. > diff --git a/drivers/raw/ioat/Makefile b/drivers/raw/ioat/Makefile > index 1e10938f3..b1af9c666 100644 > --- a/drivers/raw/ioat/Makefile > +++ b/drivers/raw/ioat/Makefile > @@ -21,6 +21,7 @@ EXPORT_MAP :=3D rte_pmd_ioat_version.map >=20=20 > # library source files > SRCS-$(CONFIG_RTE_LIBRTE_PMD_IOAT_RAWDEV) +=3D ioat_rawdev.c > +SRCS-$(CONFIG_RTE_LIBRTE_PMD_IOAT_RAWDEV) +=3D ioat_rawdev_test.c >=20=20 > # export include files > SYMLINK-y-include +=3D rte_ioat_rawdev.h > diff --git a/drivers/raw/ioat/ioat_rawdev.c b/drivers/raw/ioat/ioat_rawde= v.c > index 2bfe2544d..0c91b3579 100644 > --- a/drivers/raw/ioat/ioat_rawdev.c > +++ b/drivers/raw/ioat/ioat_rawdev.c > @@ -34,6 +34,81 @@ static struct rte_pci_driver ioat_pmd_drv; > #define IOAT_PMD_ERR(fmt, args...) IOAT_PMD_LOG(ERR, fmt, ## args) > #define IOAT_PMD_WARN(fmt, args...) IOAT_PMD_LOG(WARNING, fmt, ## args) >=20=20 > +#define DESC_SZ sizeof(struct rte_ioat_generic_hw_desc) > +#define COMPLETION_SZ sizeof(__m128i) > + > +static int > +ioat_dev_configure(const struct rte_rawdev *dev, rte_rawdev_obj_t config) > +{ > + struct rte_ioat_rawdev_config *params =3D config; > + struct rte_ioat_rawdev *ioat =3D dev->dev_private; > + char mz_name[RTE_MEMZONE_NAMESIZE]; > + unsigned short i; > + > + if (dev->started) > + return -EBUSY; > + > + if (params =3D=3D NULL) > + return -EINVAL; > + > + if (params->ring_size > 4096 || params->ring_size < 64 || > + !rte_is_power_of_2(params->ring_size)) > + return -EINVAL; > + > + ioat->ring_size =3D params->ring_size; > + if (ioat->desc_ring !=3D NULL) { > + rte_memzone_free(ioat->desc_mz); > + ioat->desc_ring =3D NULL; > + ioat->desc_mz =3D NULL; > + } > + > + /* allocate one block of memory for both descriptors > + * and completion handles. > + */ > + snprintf(mz_name, sizeof(mz_name), "rawdev%u_desc_ring", dev->dev_id); > + ioat->desc_mz =3D rte_memzone_reserve(mz_name, > + (DESC_SZ + COMPLETION_SZ) * ioat->ring_size, > + dev->device->numa_node, RTE_MEMZONE_IOVA_CONTIG); > + if (ioat->desc_mz =3D=3D NULL) > + return -ENOMEM; > + ioat->desc_ring =3D ioat->desc_mz->addr; > + ioat->hdls =3D (void *)&ioat->desc_ring[ioat->ring_size]; > + > + ioat->ring_addr =3D ioat->desc_mz->iova; > + > + /* configure descriptor ring - each one points to next */ > + for (i =3D 0; i < ioat->ring_size; i++) { > + ioat->desc_ring[i].next =3D ioat->ring_addr + > + (((i + 1) % ioat->ring_size) * DESC_SZ); > + } > + > + return 0; > +} > + > +static int > +ioat_dev_start(struct rte_rawdev *dev) > +{ > + struct rte_ioat_rawdev *ioat =3D dev->dev_private; > + > + if (ioat->ring_size =3D=3D 0 || ioat->desc_ring =3D=3D NULL) > + return -EBUSY; > + > + /* inform hardware of where the descriptor ring is */ > + ioat->regs->chainaddr =3D ioat->ring_addr; > + /* inform hardware of where to write the status/completions */ > + ioat->regs->chancmp =3D ioat->status_addr; > + > + /* prime the status register to be set to the last element */ > + ioat->status =3D ioat->ring_addr + ((ioat->ring_size - 1) * DESC_SZ); > + return 0; > +} > + > +static void > +ioat_dev_stop(struct rte_rawdev *dev) > +{ > + RTE_SET_USED(dev); > +} > + > static void > ioat_dev_info_get(struct rte_rawdev *dev, rte_rawdev_obj_t dev_info) > { > @@ -44,11 +119,17 @@ ioat_dev_info_get(struct rte_rawdev *dev, rte_rawdev= _obj_t dev_info) > cfg->ring_size =3D ioat->ring_size; > } >=20=20 > +extern int ioat_rawdev_test(uint16_t dev_id); > + This signature doesn't match with the rte_rawdev_ops definition (which should be int(*func)(void)). It will generate an error as such: ../drivers/raw/ioat/ioat_rawdev.c:176:20: error: initialization from incomp= atible pointer type [-Werror=3Dincompatible-pointer-types] .dev_selftest =3D ioat_rawdev_test, ^ ../drivers/raw/ioat/ioat_rawdev.c:176:20: note: (near initialization for = =E2=80=98ioat_rawdev_ops.dev_selftest=E2=80=99) > static int > ioat_rawdev_create(const char *name, struct rte_pci_device *dev) > { > static const struct rte_rawdev_ops ioat_rawdev_ops =3D { > + .dev_configure =3D ioat_dev_configure, > + .dev_start =3D ioat_dev_start, > + .dev_stop =3D ioat_dev_stop, > .dev_info_get =3D ioat_dev_info_get, > + .dev_selftest =3D ioat_rawdev_test, > }; >=20=20 > struct rte_rawdev *rawdev =3D NULL; > @@ -154,6 +235,7 @@ ioat_rawdev_destroy(const char *name) > if (rdev->dev_private !=3D NULL) { > struct rte_ioat_rawdev *ioat =3D rdev->dev_private; > rdev->dev_private =3D NULL; > + rte_memzone_free(ioat->desc_mz); > rte_memzone_free(ioat->mz); > } >=20=20 > diff --git a/drivers/raw/ioat/ioat_rawdev_test.c b/drivers/raw/ioat/ioat_= rawdev_test.c > new file mode 100644 > index 000000000..5375da26c > --- /dev/null > +++ b/drivers/raw/ioat/ioat_rawdev_test.c > @@ -0,0 +1,41 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2019 Intel Corporation > + */ > + > +#include "rte_rawdev.h" > +#include "rte_ioat_rawdev.h" > + > +int ioat_rawdev_test(uint16_t dev_id); /* pre-define to keep compiler ha= ppy */ > + > +int > +ioat_rawdev_test(uint16_t dev_id) > +{ > +#define IOAT_TEST_RINGSIZE 512 > + struct rte_ioat_rawdev_config p =3D { .ring_size =3D -1 }; > + struct rte_rawdev_info info =3D { .dev_private =3D &p }; > + > + rte_rawdev_info_get(dev_id, &info); > + if (p.ring_size !=3D 0) { > + printf("Error, initial ring size is non-zero (%d)\n", > + (int)p.ring_size); > + return -1; > + } > + > + p.ring_size =3D IOAT_TEST_RINGSIZE; > + if (rte_rawdev_configure(dev_id, &info) !=3D 0) { > + printf("Error with rte_rawdev_configure()\n"); > + return -1; > + } > + rte_rawdev_info_get(dev_id, &info); > + if (p.ring_size !=3D IOAT_TEST_RINGSIZE) { > + printf("Error, ring size is not %d (%d)\n", > + IOAT_TEST_RINGSIZE, (int)p.ring_size); > + return -1; > + } > + > + if (rte_rawdev_start(dev_id) !=3D 0) { > + printf("Error with rte_rawdev_start()\n"); > + return -1; > + } > + return 0; > +} > diff --git a/drivers/raw/ioat/meson.build b/drivers/raw/ioat/meson.build > index ca23e23fc..40fff6654 100644 > --- a/drivers/raw/ioat/meson.build > +++ b/drivers/raw/ioat/meson.build > @@ -2,7 +2,8 @@ > # Copyright 2019 Intel Corporation >=20=20 > build =3D dpdk_conf.has('RTE_ARCH_X86') > -sources =3D files('ioat_rawdev.c') > +sources =3D files('ioat_rawdev.c', > + 'ioat_rawdev_test.c') > deps +=3D ['rawdev', 'bus_pci'] >=20=20 > install_headers('rte_ioat_rawdev.h', > diff --git a/drivers/raw/ioat/rte_ioat_rawdev.h b/drivers/raw/ioat/rte_io= at_rawdev.h > index 1d0dbdd2e..f2cf98cd9 100644 > --- a/drivers/raw/ioat/rte_ioat_rawdev.h > +++ b/drivers/raw/ioat/rte_ioat_rawdev.h > @@ -14,6 +14,7 @@ > * @b EXPERIMENTAL: these structures and APIs may change without prior n= otice > */ >=20=20 > +#include > #include > #include > #include > @@ -51,6 +52,7 @@ struct rte_ioat_rawdev { >=20=20 > unsigned short ring_size; > struct rte_ioat_generic_hw_desc *desc_ring; > + __m128i *hdls; /* completion handles for returning to user */ >=20=20 > /* to report completions, the device will write status back here */ > volatile uint64_t status __rte_cache_aligned;