[dpdk-dev] [RFC 4/4] drivers/raw/ifpga_rawdev: Rawdev for Intel FPGA Device, it's a PCI Driver of FPGA Device Manager

Shreyansh Jain shreyansh.jain at nxp.com
Tue Mar 6 07:48:00 CET 2018


On Tue, Mar 6, 2018 at 7:13 AM, Rosen Xu <rosen.xu at intel.com> wrote:
> Signed-off-by: Rosen Xu <rosen.xu at intel.com>
> ---
>  drivers/raw/ifpga_rawdev/Makefile                  |  59 ++++
>  drivers/raw/ifpga_rawdev/ifpga_rawdev.c            | 343 +++++++++++++++++++++
>  drivers/raw/ifpga_rawdev/ifpga_rawdev.h            | 109 +++++++
>  drivers/raw/ifpga_rawdev/ifpga_rawdev_example.c    | 121 ++++++++

When rawdev skeleton driver was integrated, Thomas raised this point
of naming 'skeleton_rawdev' rather than just 'skeleton'.
So, rather than 'ifpga_rawdev' rather than 'ifpga'.
At that time I thought we could use <drivertype_driversubtype> as
model. But, frankly, to me it seems a bad choice now. Extra '_rawdev'
doesn't serve any purpose here.

So, feel free to change your naming to a more appropriate
"drivers/raw/ifpga/" or "drivers/raw/ifpga_sample" etc.

Probably I too can change the skeleton_rawdev to skeleton.

>  .../ifpga_rawdev/rte_pmd_ifpga_rawdev_version.map  |   4 +
>  5 files changed, 636 insertions(+)
>  create mode 100644 drivers/raw/ifpga_rawdev/Makefile
>  create mode 100644 drivers/raw/ifpga_rawdev/ifpga_rawdev.c
>  create mode 100644 drivers/raw/ifpga_rawdev/ifpga_rawdev.h
>  create mode 100644 drivers/raw/ifpga_rawdev/ifpga_rawdev_example.c
>  create mode 100644 drivers/raw/ifpga_rawdev/rte_pmd_ifpga_rawdev_version.map
>
> diff --git a/drivers/raw/ifpga_rawdev/Makefile b/drivers/raw/ifpga_rawdev/Makefile
> new file mode 100644
> index 0000000..3166fe2
> --- /dev/null
> +++ b/drivers/raw/ifpga_rawdev/Makefile
> @@ -0,0 +1,59 @@
> +#   BSD LICENSE
> +#
> +#   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
> +#   All rights reserved.
> +#
> +#   Redistribution and use in source and binary forms, with or without
> +#   modification, are permitted provided that the following conditions
> +#   are met:
> +#
> +#     * Redistributions of source code must retain the above copyright
> +#       notice, this list of conditions and the following disclaimer.
> +#     * Redistributions in binary form must reproduce the above copyright
> +#       notice, this list of conditions and the following disclaimer in
> +#       the documentation and/or other materials provided with the
> +#       distribution.
> +#     * Neither the name of Intel Corporation nor the names of its
> +#       contributors may be used to endorse or promote products derived
> +#       from this software without specific prior written permission.
> +#
> +#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> +#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> +#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> +#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> +#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> +#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> +#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> +#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> +#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> +#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> +#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> +

SPDX identifier in place of BSD boiler-plate.

> +include $(RTE_SDK)/mk/rte.vars.mk
> +
> +#
> +# library name
> +#
> +LIB = librte_pmd_ifpga_rawdev.a
> +
> +CFLAGS += -DALLOW_EXPERIMENTAL_API
> +CFLAGS += -O3
> +CFLAGS += $(WERROR_FLAGS)
> +CFLAGS += -I$(RTE_SDK)/drivers/bus/ifpga
> +CFLAGS += -I$(RTE_SDK)/drivers/raw/ifpga_rawdev
> +LDLIBS += -lrte_eal
> +LDLIBS += -lrte_rawdev
> +LDLIBS += -lrte_bus_vdev
> +LDLIBS += -lrte_kvargs
> +
> +EXPORT_MAP := rte_pmd_ifpga_rawdev_version.map
> +
> +LIBABIVER := 1
> +
> +#
> +# all source are stored in SRCS-y
> +#
> +SRCS-$(CONFIG_RTE_LIBRTE_PMD_SKELETON_RAWDEV) += ifpga_rawdev.c
> +SRCS-$(CONFIG_RTE_LIBRTE_PMD_SKELETON_RAWDEV) += ifpga_rawdev_example.c

This is a copy-paste issue - CONFIG_RTE_LIBRTE_PMD_SKELETON_RAWDEV

> +
> +include $(RTE_SDK)/mk/rte.lib.mk
> diff --git a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> new file mode 100644
> index 0000000..6046711
> --- /dev/null
> +++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c
> @@ -0,0 +1,343 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright 2016 NXP.

:) - should be Intel.
Even better - SPDX

> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of NXP nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +#include <string.h>
> +#include <dirent.h>
> +#include <sys/stat.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <fcntl.h>
> +#include <rte_log.h>
> +#include <rte_bus.h>
> +#include <rte_eal_memconfig.h>
> +#include <rte_malloc.h>
> +#include <rte_devargs.h>
> +#include <rte_memcpy.h>
> +#include <rte_ethdev.h>
> +#include <rte_pci.h>
> +#include <rte_bus_pci.h>
> +#include <rte_kvargs.h>
> +#include <rte_alarm.h>
> +
> +#include <rte_errno.h>
> +#include <rte_per_lcore.h>
> +#include <rte_memory.h>
> +#include <rte_memzone.h>
> +#include <rte_eal.h>
> +#include <rte_common.h>
> +
> +#include "rte_rawdev.h"
> +#include "rte_rawdev_pmd.h"
> +#include "rte_bus_ifpga.h"
> +#include "ifpga_rawdev.h"
> +
> +int ifpga_rawdev_logtype;
> +
> +#define PCI_VENDOR_ID_INTEL          0x8086
> +/* PCI Device ID */
> +#define PCIe_DEVICE_ID_RCiEP0_MCP    0xBCBD
> +#define PCIe_DEVICE_ID_RCiEP0_SKX_P  0xBCC0
> +#define PCIe_DEVICE_ID_RCiEP0_DCP    0x09C4
> +/* VF Device */
> +#define PCIe_DEVICE_ID_VF_MCP        0xBCBF
> +#define PCIe_DEVICE_ID_VF_SKX_P      0xBCC1
> +#define PCIe_DEVICE_ID_VF_DCP        0x09C5
> +#define RTE_MAX_RAW_DEVICE           10
> +
> +static const struct rte_pci_id pci_ifpga_map[] = {
> +       { RTE_PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIe_DEVICE_ID_RCiEP0_MCP) },
> +       { RTE_PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIe_DEVICE_ID_VF_MCP) },
> +       { RTE_PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIe_DEVICE_ID_RCiEP0_SKX_P) },
> +       { RTE_PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIe_DEVICE_ID_VF_SKX_P) },
> +       { RTE_PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIe_DEVICE_ID_RCiEP0_DCP) },
> +       { RTE_PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIe_DEVICE_ID_VF_DCP) },
> +       { .vendor_id = 0, /* sentinel */ },
> +};
> +
> +static void ifpga_rawdev_info_get(struct rte_rawdev *dev,
> +                                    rte_rawdev_obj_t dev_info)
> +{
> +       struct ifpga_rawdev *ifpga;
> +       struct rte_afu_device *afu_dev;
> +
> +       IFPGA_RAWDEV_PMD_FUNC_TRACE();
> +
> +       if (!dev_info) {
> +               IFPGA_RAWDEV_PMD_ERR("Invalid request");
> +               return;
> +       }
> +
> +       ifpga = ifpga_rawdev_get_priv(dev);
> +
> +       afu_dev = dev_info;
> +       //-------------------------------
> +       //Todo: fill afu_dev->rte_rawdev and afu_dev->rte_mem_resource
> +       //*get afu_dev->num_region from Rawdev
> +       //*get afu_dev->mem_resource from Rawdev
> +       //*get afu_dev->max_vfs from Rawdev
> +       //-------------------------------
> +
> +}
> +
> +static int ifpga_rawdev_start(struct rte_rawdev *dev)
> +{
> +       int ret = 0;
> +       struct ifpga_rawdev *ifpga;
> +       enum ifpga_rawdev_device_state fpga_state;
> +
> +       IFPGA_RAWDEV_PMD_FUNC_TRACE();
> +
> +       RTE_FUNC_PTR_OR_ERR_RET(dev, -EINVAL);
> +
> +       ifpga = ifpga_rawdev_get_priv(dev);
> +
> +       fpga_state = ifpga->fpga_state;
> +
> +       if (fpga_state == IFPGA_IDLE) {
> +               ret = ifpga_enumerate(&ifpga->hw);
> +               if (ret) {
> +                       ifpga->fpga_state = IFPGA_ERROR;
> +               IFPGA_RAWDEV_PMD_ERR("Failed to enumerate fme: %d", ret);
> +               ret = -EINVAL;
> +               return ret;
> +       }
> +       ifpga_fme_hw_init(&ifpga->hw);
> +               ifpga->fpga_state = IFPGA_READY;
> +       } else {
> +               IFPGA_RAWDEV_PMD_DEBUG("IFPGA is enumerated");
> +       }
> +
> +       return ret;
> +}
> +
> +static void ifpga_rawdev_stop(struct rte_rawdev *dev)
> +{
> +
> +}
> +static int ifpga_rawdev_close(struct rte_rawdev *dev)
> +{
> +       int ret = 0;
> +
> +
> +       return ret;
> +}
> +
> +static int ifpga_rawdev_reset(struct rte_rawdev *dev)
> +{
> +
> +
> +       return 0;
> +}
> +static int ifpga_rawdev_pr(struct rte_rawdev *dev,
> +                                        rte_rawdev_obj_t pr_conf)
> +{
> +       struct ifpga_rawdev *ifpga;
> +       struct ifpga_hw *hw;
> +       struct rte_afu_pr_conf *afu_pr_conf;
> +       int     ret;
> +       unsigned int     num_resource = 1;
> +
> +       IFPGA_RAWDEV_PMD_FUNC_TRACE();
> +
> +       ifpga = ifpga_rawdev_get_priv(dev);
> +
> +       if (!pr_conf)
> +               return -EINVAL;
> +
> +       afu_pr_conf = pr_conf;
> +
> +    hw = &ifpga->hw;
> +       ifpga_port_hw_init(hw, afu_pr_conf->afu_id.port);
> +       ifpga_get_afu_mmio_info(hw, afu_pr_conf->afu_id.port, &ifpga->pci_dev->mem_resource[0], &num_resource);
> +       ret=rte_fpga_do_pr(hw, afu_pr_conf->afu_id.port, afu_pr_conf->bs_path);
> +       if (ret) {
> +       printf("do pr error\n");
> +       return ret;
> +       }
> +
> +       return 0;
> +}
> +
> +static const struct rte_rawdev_ops ifpga_rawdev_ops = {
> +       .dev_info_get = ifpga_rawdev_info_get,
> +       .dev_configure = NULL,
> +       .dev_start = ifpga_rawdev_start,
> +       .dev_stop = ifpga_rawdev_stop,
> +       .dev_close = ifpga_rawdev_close,
> +       .dev_reset = ifpga_rawdev_reset,
> +
> +       .queue_def_conf = NULL,
> +       .queue_setup = NULL,
> +       .queue_release = NULL,
> +
> +       .attr_get = NULL,
> +       .attr_set = NULL,
> +
> +       .enqueue_bufs = NULL,
> +       .dequeue_bufs = NULL,
> +
> +       .dump = NULL,
> +
> +       .xstats_get = NULL,
> +       .xstats_get_names = NULL,
> +       .xstats_get_by_name = NULL,
> +       .xstats_reset = NULL,
> +
> +       .firmware_status_get = NULL,
> +       .firmware_version_get = NULL,
> +       .firmware_load = ifpga_rawdev_pr,
> +       .firmware_unload = NULL,
> +
> +       .dev_selftest = NULL,
> +};
> +
> +static int
> +ifpga_rawdev_create(struct rte_pci_device *pci_dev,
> +                                   int socket_id)
> +{
> +       int ret = 0;
> +       struct rte_rawdev *rawdev = NULL;
> +       struct ifpga_rawdev *ifpga = NULL;
> +       char name[RTE_RAWDEV_NAME_MAX_LEN];
> +
> +       if (!pci_dev) {
> +               IFPGA_RAWDEV_PMD_ERR("Invalid pci_dev of the device!");
> +               ret = -EINVAL;
> +               goto cleanup;
> +       }
> +
> +       memset(name, sizeof(name), 0);
> +       snprintf(name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%x:%x:%x", pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function);
> +
> +       IFPGA_RAWDEV_PMD_INFO("Init %s on NUMA node %d", name, rte_socket_id());
> +
> +       /* Allocate device structure */
> +       rawdev = rte_rawdev_pmd_allocate(name, sizeof(struct ifpga_rawdev),
> +                                        socket_id);
> +       if (rawdev == NULL) {
> +               IFPGA_RAWDEV_PMD_ERR("Unable to allocate rawdevice");
> +               ret = -EINVAL;
> +               goto cleanup;
> +       }
> +
> +       rawdev->dev_ops = &ifpga_rawdev_ops;
> +       rawdev->device = &pci_dev->device;
> +       rawdev->driver_name = pci_dev->device.driver->name;
> +
> +       ifpga = ifpga_rawdev_get_priv(rawdev);
> +       ifpga->pci_dev = pci_dev;
> +       ifpga->fpga_state = IFPGA_IDLE;
> +
> +       /* Initialize the shared code (base driver) */
> +       ret = opae_init_shared_code(&ifpga->hw);
> +       if (ret) {
> +               IFPGA_RAWDEV_PMD_ERR("Failed to init shared code (base driver): %d", ret);
> +               ret = -EINVAL;
> +               goto cleanup;
> +       }
> +
> +       return ret;
> +
> +cleanup:
> +       if (rawdev)
> +               rte_rawdev_pmd_release(rawdev);
> +
> +       return ret;
> +}
> +
> +static int
> +ifpga_rawdev_destroy(struct rte_pci_device *pci_dev)
> +{
> +       int ret;
> +       struct rte_rawdev *rdev;
> +       char name[RTE_RAWDEV_NAME_MAX_LEN];
> +
> +       if (!pci_dev) {
> +               IFPGA_RAWDEV_PMD_ERR("Invalid pci_dev of the device!");
> +               ret = -EINVAL;
> +               return ret;
> +       }
> +
> +       memset(name, sizeof(name), 0);
> +       snprintf(name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%x:%x:%x", pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function);
> +
> +       IFPGA_RAWDEV_PMD_INFO("Closing %s on NUMA node %d", name, rte_socket_id());
> +
> +       rdev = rte_rawdev_pmd_get_named_dev(name);
> +       if (!rdev) {
> +               IFPGA_RAWDEV_PMD_ERR("Invalid device name (%s)", name);
> +               return -EINVAL;
> +       }
> +
> +       /* rte_rawdev_close is called by pmd_release */
> +       ret = rte_rawdev_pmd_release(rdev);
> +       if (ret)
> +               IFPGA_RAWDEV_PMD_DEBUG("Device cleanup failed");
> +
> +       return 0;
> +}
> +
> +static int
> +ifpga_rawdev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
> +                          struct rte_pci_device *pci_dev)
> +{
> +       return ifpga_rawdev_create(pci_dev, rte_socket_id());
> +}
> +
> +static int ifpga_rawdev_pci_remove(struct rte_pci_device *pci_dev)
> +{
> +       return ifpga_rawdev_destroy(pci_dev);
> +}
> +
> +static struct rte_pci_driver rte_ifpga_rawdev_pmd = {
> +       .id_table  = pci_ifpga_map,
> +       .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
> +       .probe     = ifpga_rawdev_pci_probe,
> +       .remove    = ifpga_rawdev_pci_remove,
> +};

>From above, what I understand is that ifpga is a PCI device, but there
are certain functions which are not available in PCI rte layer and
thus you need a rawdev representation.
But I somehow feel that you could have worked without adding another
bus type (drivers/bus/ifpga).

- PCI devices are scanned by PCI bus. (which is still happening in
this RFC patches)
- When probing is done, this driver (rawdev/ifpga) would identify and
attach itself to those devices (using PCI ids for matching)
  No other driver would pass the probe because of PCI_TABLE
- and then using rawdev APIs, interact with the device.

Am I missing some obvious logic here which requires a new bus?

> +
> +RTE_PMD_REGISTER_PCI(ifpga_rawdev_pci_driver, rte_ifpga_rawdev_pmd);
> +RTE_PMD_REGISTER_PCI_TABLE(ifpga_rawdev_pci_driver, rte_ifpga_rawdev_pmd);
> +RTE_PMD_REGISTER_KMOD_DEP(ifpga_rawdev_pci_driver, "* igb_uio | uio_pci_generic | vfio-pci");
> +
> +RTE_INIT(ifpga_rawdev_init_log);
> +static void
> +ifpga_rawdev_init_log(void)
> +{
> +       ifpga_rawdev_logtype = rte_log_register("driver.raw.init");
> +       if (ifpga_rawdev_logtype >= 0)
> +               rte_log_set_level(ifpga_rawdev_logtype, RTE_LOG_NOTICE);
> +}
> +
> +void ifpga_rawdev_test(void)
> +{
> +    printf("ifpga_rawdev_test \n");
> +}
> diff --git a/drivers/raw/ifpga_rawdev/ifpga_rawdev.h b/drivers/raw/ifpga_rawdev/ifpga_rawdev.h
> new file mode 100644
> index 0000000..dfa63c6
> --- /dev/null
> +++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev.h
> @@ -0,0 +1,109 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2017 Intel Corporation. All rights reserved.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of Intel Corporation nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +#ifndef _IFPGA_RAWDEV_H_
> +#define _IFPGA_RAWDEV_H_
> +
> +/*++++++++++++++++++++++++++++++++++These functions should be implemented by OPAE++++++++++++++++++++++++++++++++++*/
> +struct ifpga_hw {
> +       void                 *pci_dev; //share code will not involve any DPDK defination
> +
> +       int                  fme;
> +       int                  port[4];
> +};
> +
> +static int opae_init_shared_code(struct ifpga_hw *hw)
> +{
> +    //init ifpga_hw
> +
> +    return 0;
> +}
> +static int ifpga_enumerate(struct ifpga_hw *hw)
> +{
> +       return 0;
> +}
> +static int ifpga_fme_hw_init(struct ifpga_hw *hw)
> +{
> +       return 0;
> +}
> +static int ifpga_port_hw_init(struct ifpga_hw *hw, int port_id)
> +{
> +    return 0;
> +}
> +static int ifpga_get_afu_mmio_info(struct ifpga_hw *hw, unsigned int port_id,
> +               struct rte_mem_resource *mem_resource,
> +               unsigned int *num_resource)
> +{
> +    return 0;
> +}
> +static int rte_fpga_do_pr(struct ifpga_hw *afu_dev, int port_id, const char *file_name)
> +{
> +    return 0;
> +}
> +/*++++++++++++++++++++++++++++++++++These functions should be implemented by OPAE++++++++++++++++++++++++++++++++++*/
> +
> +extern int ifpga_rawdev_logtype;
> +
> +#define IFPGA_RAWDEV_PMD_LOG(level, fmt, args...) \
> +       rte_log(RTE_LOG_ ## level, ifpga_rawdev_logtype, "%s(): " fmt "\n", \
> +               __func__, ##args)
> +
> +#define IFPGA_RAWDEV_PMD_FUNC_TRACE() IFPGA_RAWDEV_PMD_LOG(DEBUG, ">>")
> +
> +#define IFPGA_RAWDEV_PMD_DEBUG(fmt, args...) \
> +       IFPGA_RAWDEV_PMD_LOG(DEBUG, fmt, ## args)
> +#define IFPGA_RAWDEV_PMD_INFO(fmt, args...) \
> +       IFPGA_RAWDEV_PMD_LOG(INFO, fmt, ## args)
> +#define IFPGA_RAWDEV_PMD_ERR(fmt, args...) \
> +       IFPGA_RAWDEV_PMD_LOG(ERR, fmt, ## args)
> +#define IFPGA_RAWDEV_PMD_WARN(fmt, args...) \
> +       IFPGA_RAWDEV_PMD_LOG(WARNING, fmt, ## args)
> +
> +enum ifpga_rawdev_device_state {
> +       IFPGA_IDLE,
> +       IFPGA_READY,
> +       IFPGA_ERROR
> +};
> +
> +struct ifpga_rawdev {
> +       struct ifpga_hw hw;
> +       struct rte_pci_device *pci_dev;
> +       enum   ifpga_rawdev_device_state fpga_state;
> +};
> +
> +static inline struct ifpga_rawdev *
> +ifpga_rawdev_get_priv(const struct rte_rawdev *rawdev)
> +{
> +       return rawdev->dev_private;
> +}
> +
> +#endif /* _IFPGA_RAWDEV_H_ */
> diff --git a/drivers/raw/ifpga_rawdev/ifpga_rawdev_example.c b/drivers/raw/ifpga_rawdev/ifpga_rawdev_example.c
> new file mode 100644
> index 0000000..c506c0e
> --- /dev/null
> +++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev_example.c
> @@ -0,0 +1,121 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2017 Intel Corporation. All rights reserved.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of Intel Corporation nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <stdint.h>
> +#include <inttypes.h>
> +#include <sys/types.h>
> +#include <sys/queue.h>
> +#include <netinet/in.h>
> +#include <setjmp.h>
> +#include <stdarg.h>
> +#include <ctype.h>
> +#include <errno.h>
> +#include <getopt.h>
> +#include <signal.h>
> +#include <stdbool.h>
> +
> +#include <rte_common.h>
> +#include <rte_log.h>
> +#include <rte_malloc.h>
> +#include <rte_memory.h>
> +#include <rte_memcpy.h>
> +#include <rte_eal.h>
> +#include <rte_launch.h>
> +#include <rte_atomic.h>
> +#include <rte_cycles.h>
> +#include <rte_prefetch.h>
> +#include <rte_lcore.h>
> +#include <rte_per_lcore.h>
> +#include <rte_branch_prediction.h>
> +#include <rte_interrupts.h>
> +#include <rte_random.h>
> +#include <rte_debug.h>
> +#include <rte_ether.h>
> +#include <rte_ethdev.h>
> +#include <rte_mempool.h>
> +#include <rte_mbuf.h>
> +#include <rte_io.h>
> +
> +#include <rte_errno.h>
> +#include <rte_bus.h>
> +#include <rte_memzone.h>
> +
> +#include <rte_devargs.h>
> +#include <rte_pci.h>
> +#include <rte_bus_pci.h>
> +#include <rte_alarm.h>
> +
> +#include "rte_bus_ifpga.h"
> +#include "ifpga_logs.h"
> +
> +#define RTE_PMD_REGISTER_AFU(nm, afudrv)\
> +RTE_INIT(afudrvinitfn_ ##afudrv);\
> +static const char *afudrvinit_ ## nm ## _alias;\
> +static void afudrvinitfn_ ##afudrv(void)\
> +{\
> +       (afudrv).driver.name = RTE_STR(nm);\
> +       (afudrv).driver.alias = afudrvinit_ ## nm ## _alias;\
> +       rte_ifpga_driver_register(&afudrv);\
> +} \
> +RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
> +
> +#define RTE_PMD_REGISTER_AFU_ALIAS(nm, alias)\
> +static const char *afudrvinit_ ## nm ## _alias = RTE_STR(alias)
> +
> +static int afu_dev_probe(struct rte_afu_device *afu_dev)
> +{
> +       return 0;
> +}
> +static int afu_dev_remove(struct rte_afu_device *afu_dev)
> +{
> +       return 0;
> +}
> +
> +static struct rte_afu_driver afu_dev_driver = {
> +       .probe = afu_dev_probe,
> +       .remove = afu_dev_remove,
> +};
> +
> +RTE_PMD_REGISTER_AFU(net_afu_drv_example, afu_dev_driver);
> +RTE_PMD_REGISTER_AFU_ALIAS(net_afu_drv_example, afu_dev);
> +RTE_PMD_REGISTER_PARAM_STRING(net_afu_drv_example,
> +       "bdf=<string> "
> +       "port=<int> "
> +       "uudi_high=<int64> "
> +       "uuid_low=<int64> "
> +       "path=<string> "
> +       "pr_enable=<int>"
> +       "debug=<int>");
> diff --git a/drivers/raw/ifpga_rawdev/rte_pmd_ifpga_rawdev_version.map b/drivers/raw/ifpga_rawdev/rte_pmd_ifpga_rawdev_version.map
> new file mode 100644
> index 0000000..179140f
> --- /dev/null
> +++ b/drivers/raw/ifpga_rawdev/rte_pmd_ifpga_rawdev_version.map
> @@ -0,0 +1,4 @@
> +DPDK_18.02 {

Will be 18.05

> +
> +       local: *;
> +};
> --
> 1.8.3.1
>


More information about the dev mailing list