raw/afu_mf: introduce AFU MF device driver
RE: [PATCH v7 5/5] raw/ifpga: add HE-HSSI AFU driver
In reply to Wei HuangHi Wei,
Quoted 564 lines
-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Thursday, June 09, 2022 15:37
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Zhang, Qi Z <[email protected]>; Huang, Wei <[email protected]>
Subject: [PATCH v7 5/5] raw/ifpga: add HE-HSSI AFU driverHE-HSSI is one of the host exerciser modules in OFS FPGA, which is used to test HSSI (High Speed Serial Interface).
This driver initialize the module and report test result.Signed-off-by Wei Huang <[email protected]>---
v2: move source files to ifpga and rename, refine code--- drivers/raw/ifpga/afu_pmd_he_hssi.c | 371 ++++++++++++++++++++++++++++++++++++ drivers/raw/ifpga/afu_pmd_he_hssi.h | 109 +++++++++++ drivers/raw/ifpga/meson.build | 3 +- drivers/raw/ifpga/rte_pmd_afu.h | 18 ++ 4 files changed, 500 insertions(+), 1 deletion(-) create mode 100644 drivers/raw/ifpga/afu_pmd_he_hssi.c create mode 100644 drivers/raw/ifpga/afu_pmd_he_hssi.hdrivers/raw/ifpga/afu_pmd_he_hssi.c new file +35
-0@@ -0,0 +1,371 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2022 Intel Corporation +*/ + +#include <errno.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <inttypes.h> +#include <unistd.h> +#include <fcntl.h> +#include <poll.h> +#include <sys/eventfd.h> +#include <sys/ioctl.h> + +#include <rte_eal.h> +#include <rte_malloc.h> +#include <rte_memcpy.h> +#include <rte_io.h> +#include <rte_vfio.h> +#include <rte_bus_pci.h> +#include <rte_bus_ifpga.h> +#include <rte_rawdev.h> + +#include "afu_pmd_core.h" +#include "afu_pmd_he_hssi.h" + +static int he_hssi_indirect_write (struct he_hssi_ctx *ctx,uint32_t addr, +uint32_t value) +{ +struct traffic_ctrl_cmd cmd; +struct traffic_ctrl_data data; +uint32_t i =0 ; + + IFPGA_RAWDEV_PMD_DEBUG("Indirect write 0x%x, value 0x%08x",addr,
drivers/raw/ifpga/afu_pmd_he_hssi.c new file +60
-0+value); + +if (!ctx) +return -EINVAL ; + + data.write_data = value; +rte_write64 (data.csr, ctx->addr +TRAFFIC_CTRL_DATA ); + + cmd.csr =0 ; + cmd.write_cmd =1 ; + cmd.afu_cmd_addr = addr; +rte_write64 (cmd.csr, ctx->addr +TRAFFIC_CTRL_CMD ); + +while (i <MAILBOX_TIMEOUT_MS ) { +rte_delay_ms (MAILBOX_POLL_INTERVAL_MS ); + cmd.csr =rte_read64 (ctx->addr +TRAFFIC_CTRL_CMD ); +if (cmd.ack_trans) +break ; + i +=MAILBOX_POLL_INTERVAL_MS ; + } +if (i >=MAILBOX_TIMEOUT_MS ) +return -ETIMEDOUT ; + + i =0 ; + cmd.csr =0 ; +while (i <MAILBOX_TIMEOUT_MS ) { + cmd.ack_trans =1 ; +rte_write64 (cmd.csr, ctx->addr +TRAFFIC_CTRL_CMD ); +rte_delay_ms (MAILBOX_POLL_INTERVAL_MS ); + cmd.csr =rte_read64 (ctx->addr +TRAFFIC_CTRL_CMD ); +if (!cmd.ack_trans) +break ; + i +=MAILBOX_POLL_INTERVAL_MS ; + } +if (i >=MAILBOX_TIMEOUT_MS ) +return -ETIMEDOUT ; + +return 0 ; +} + +static int he_hssi_indirect_read (struct he_hssi_ctx *ctx,uint32_t addr, +uint32_t *value) +{ +struct traffic_ctrl_cmd cmd; +struct traffic_ctrl_data data; +uint32_t i =0 ; + +if (!ctx) +return -EINVAL ; + + cmd.csr =0 ; + cmd.read_cmd =1 ; + cmd.afu_cmd_addr = addr; +rte_write64 (cmd.csr, ctx->addr +TRAFFIC_CTRL_CMD ); + +while (i <MAILBOX_TIMEOUT_MS ) { +rte_delay_ms (MAILBOX_POLL_INTERVAL_MS ); + cmd.csr =rte_read64 (ctx->addr +TRAFFIC_CTRL_CMD ); +if (cmd.ack_trans) { + data.csr = rte_read64(ctx->addr +
TRAFFIC_CTRL_DATA);drivers/raw/ifpga/afu_pmd_he_hssi.c new file +23
-0+ *value = data.read_data; +break ; + } + i +=MAILBOX_POLL_INTERVAL_MS ; + } +if (i >=MAILBOX_TIMEOUT_MS ) +return -ETIMEDOUT ; + + i =0 ; + cmd.csr =0 ; +while (i <MAILBOX_TIMEOUT_MS ) { + cmd.ack_trans =1 ; +rte_write64 (cmd.csr, ctx->addr +TRAFFIC_CTRL_CMD ); +rte_delay_ms (MAILBOX_POLL_INTERVAL_MS ); + cmd.csr =rte_read64 (ctx->addr +TRAFFIC_CTRL_CMD ); +if (!cmd.ack_trans) +break ; + i +=MAILBOX_POLL_INTERVAL_MS ; + } +if (i >=MAILBOX_TIMEOUT_MS ) +return -ETIMEDOUT ; + + IFPGA_RAWDEV_PMD_DEBUG("Indirect read 0x%x, value 0x%08x",addr, *value);
drivers/raw/ifpga/afu_pmd_he_hssi.c new file +249
-0+return 0 ; +} + +static void he_hssi_report (struct he_hssi_ctx *ctx) { +uint32_t val =0 ; +uint64_t v64 =0 ; +int ret =0 ; + + ret =he_hssi_indirect_read (ctx,TM_PKT_GOOD , &val); +if (ret) +return ; +printf ("Number of good packets received: %u\n" , val); + + ret =he_hssi_indirect_read (ctx,TM_PKT_BAD , &val); +if (ret) +return ; +printf ("Number of bad packets received: %u\n" , val); + + ret =he_hssi_indirect_read (ctx,TM_BYTE_CNT1 , &val); +if (ret) +return ; + v64 = val; + ret =he_hssi_indirect_read (ctx,TM_BYTE_CNT0 , &val); +if (ret) +return ; + v64 = (v64 <<32 ) | val; +printf ("Number of bytes received: %" PRIu64"\n" , v64); + + ret =he_hssi_indirect_read (ctx,TM_AVST_RX_ERR , &val); +if (ret) +return ; +if (val &ERR_VALID ) { +printf ("AVST rx error:" ); +if (val &OVERFLOW_ERR ) +printf (" overflow" ); +if (val &LENGTH_ERR ) +printf (" length" ); +if (val &OVERSIZE_ERR ) +printf (" oversize" ); +if (val &UNDERSIZE_ERR ) +printf (" undersize" ); +if (val &MAC_CRC_ERR ) +printf (" crc" ); +if (val &PHY_ERR ) +printf (" phy" ); +printf ("\n" ); + } + + ret =he_hssi_indirect_read (ctx,LOOPBACK_FIFO_STATUS , &val); +if (ret) +return ; +if (val & (ALMOST_EMPTY |ALMOST_FULL )) { +printf ("FIFO status:" ); +if (val &ALMOST_EMPTY ) +printf (" almost empty" ); +if (val &ALMOST_FULL ) +printf (" almost full" ); +printf ("\n" ); + } +} + +static int he_hssi_test (struct afu_rawdev *dev) { +struct he_hssi_priv *priv =NULL ; +struct rte_pmd_afu_he_hssi_cfg *cfg =NULL ; +struct he_hssi_ctx *ctx =NULL ; +struct traffic_ctrl_ch_sel sel; +uint32_t val =0 ; +uint32_t i =0 ; +int ret =0 ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_hssi_priv *)dev->priv; +if (!priv) +return -ENOENT ; + + cfg = &priv->he_hssi_cfg; + ctx = &priv->he_hssi_ctx; + + ret =he_hssi_indirect_write (ctx,TG_STOP_XFR ,0 ); +if (ret) +return ret; + + sel.channel_sel = cfg->port; +rte_write64 (sel.csr, ctx->addr +TRAFFIC_CTRL_CH_SEL ); + +if (cfg->he_loopback >=0 ) { + val = cfg->he_loopback ?1 :0 ; +IFPGA_RAWDEV_PMD_INFO ("%s HE loopback on port %u" , + val ?"Enable" :"Disable" , cfg->port); +return he_hssi_indirect_write (ctx,LOOPBACK_EN , val); + } + + ret =he_hssi_indirect_write (ctx,TG_NUM_PKT , cfg->num_packets); +if (ret) +return ret; + + ret =he_hssi_indirect_write (ctx,TG_PKT_LEN , cfg->packet_length); +if (ret) +return ret; + + val = cfg->src_addr &0xffffffff ; + ret =he_hssi_indirect_write (ctx,TG_SRC_MAC_L , val); +if (ret) +return ret; + val = (cfg->src_addr >>32 ) &0xffff ; + ret =he_hssi_indirect_write (ctx,TG_SRC_MAC_H , val); +if (ret) +return ret; + + val = cfg->dest_addr &0xffffffff ; + ret =he_hssi_indirect_write (ctx,TG_DST_MAC_L , val); +if (ret) +return ret; + val = (cfg->dest_addr >>32 ) &0xffff ; + ret =he_hssi_indirect_write (ctx,TG_DST_MAC_H , val); +if (ret) +return ret; + + val = cfg->random_length ?1 :0 ; + ret =he_hssi_indirect_write (ctx,TG_PKT_LEN_TYPE , val); +if (ret) +return ret; + + val = cfg->random_payload ?1 :0 ; + ret =he_hssi_indirect_write (ctx,TG_DATA_PATTERN , val); +if (ret) +return ret; + +for (i =0 ; i <TG_NUM_RND_SEEDS ; i++) { + ret =he_hssi_indirect_write (ctx,TG_RANDOM_SEED (i), + cfg->rnd_seed[i]); +if (ret) +return ret; + } + + ret =he_hssi_indirect_write (ctx,TG_START_XFR ,1 ); +if (ret) +return ret; + +while (i++ < cfg->timeout) { + ret =he_hssi_indirect_read (ctx,TG_PKT_XFRD , &val); +if (ret) +break ; +if (val == cfg->num_packets) +break ; +sleep (1 ); + } + +he_hssi_report (ctx); + +return ret; +} + +static int he_hssi_init (struct afu_rawdev *dev) { +struct he_hssi_priv *priv =NULL ; +struct he_hssi_ctx *ctx =NULL ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_hssi_priv *)dev->priv; +if (!priv) { + priv =rte_zmalloc (NULL ,sizeof (struct he_hssi_priv ),0 ); +if (!priv) +return -ENOMEM ; + dev->priv = priv; + } + + ctx = &priv->he_hssi_ctx; + ctx->addr = (uint8_t *)dev->addr; + +return 0 ; +} + +static int he_hssi_config (struct afu_rawdev *dev,void *config, +size_t config_size) +{ +struct he_hssi_priv *priv =NULL ; +struct rte_pmd_afu_he_hssi_cfg *cfg =NULL ; + +if (!dev || !config || !config_size) +return -EINVAL ; + + priv = (struct he_hssi_priv *)dev->priv; +if (!priv) +return -ENOENT ; + +if (config_size !=sizeof (struct rte_pmd_afu_he_hssi_cfg )) +return -EINVAL ; + + cfg = (struct rte_pmd_afu_he_hssi_cfg *)config; +if (cfg->port >=NUM_HE_HSSI_PORTS ) +return -EINVAL ; + +rte_memcpy (&priv->he_hssi_cfg, cfg,sizeof (priv->he_hssi_cfg)); + +return 0 ; +} + +static int he_hssi_close (struct afu_rawdev *dev) { +if (!dev) +return -EINVAL ; + +rte_free (dev->priv); + dev->priv =NULL ; + +return 0 ; +} + +static int he_hssi_dump (struct afu_rawdev *dev,FILE *f) { +struct he_hssi_priv *priv =NULL ; +struct he_hssi_ctx *ctx =NULL ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_hssi_priv *)dev->priv; +if (!priv) +return -ENOENT ; + +if (!f) + f = stdout; + + ctx = &priv->he_hssi_ctx; + +fprintf (f,"addr:\t\t%p\n" , (void *)ctx->addr); + +return 0 ; +} + +static struct afu_ops he_hssi_ops = { + .init = he_hssi_init, + .config = he_hssi_config, + .start =NULL , + .stop =NULL , + .test = he_hssi_test, + .close = he_hssi_close, + .dump = he_hssi_dump, + .reset =NULL +}; + +struct afu_rawdev_drv he_hssi_drv = { + .uuid = {HE_HSSI_UUID_L ,HE_HSSI_UUID_H }, + .ops = &he_hssi_ops +}; + +AFU_PMD_REGISTER (he_hssi_drv);drivers/raw/ifpga/afu_pmd_he_hssi.h new file +109
-0@@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2022 Intel Corporation +*/ + +#ifndef _AFU_PMD_HE_HSSI_H_ +#define _AFU_PMD_HE_HSSI_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "afu_pmd_core.h" +#include "rte_pmd_afu.h" + +#define HE_HSSI_UUID_L 0xbb370242ac130002 +#define HE_HSSI_UUID_H 0x823c334c98bf11ea +#define NUM_HE_HSSI_PORTS 8 + +/* HE-HSSI registers definition */ +#define TRAFFIC_CTRL_CMD 0x30 +#define TRAFFIC_CTRL_DATA 0x38 +#define TRAFFIC_CTRL_CH_SEL 0x40 +#define AFU_SCRATCHPAD 0x48 + +#define TG_NUM_PKT 0x3c00 +#define TG_PKT_LEN_TYPE 0x3c01 +#define TG_DATA_PATTERN 0x3c02 +#define TG_START_XFR 0x3c03 +#define TG_STOP_XFR 0x3c04 +#define TG_SRC_MAC_L 0x3c05 +#define TG_SRC_MAC_H 0x3c06 +#define TG_DST_MAC_L 0x3c07 +#define TG_DST_MAC_H 0x3c08 +#define TG_PKT_XFRD 0x3c09 +#define TG_NUM_RND_SEEDS 3 +#define TG_RANDOM_SEED (n) (0x3c0a + (n)) +#define TG_PKT_LEN 0x3c0d + +#define TM_NUM_PKT 0x3d00 +#define TM_PKT_GOOD 0x3d01 +#define TM_PKT_BAD 0x3d02 +#define TM_BYTE_CNT0 0x3d03 +#define TM_BYTE_CNT1 0x3d04 +#define TM_AVST_RX_ERR 0x3d07 +#define OVERFLOW_ERR (1 << 9) +#define LENGTH_ERR (1 << 8) +#define OVERSIZE_ERR (1 << 7) +#define UNDERSIZE_ERR (1 << 6) +#define MAC_CRC_ERR (1 << 5) +#define PHY_ERR (1 << 4) +#define ERR_VALID (1 << 3) + +#define LOOPBACK_EN 0x3e00 +#define LOOPBACK_FIFO_STATUS 0x3e01 +#define ALMOST_EMPTY (1 << 1) +#define ALMOST_FULL (1 << 0) + +#define MAILBOX_TIMEOUT_MS 100 +#define MAILBOX_POLL_INTERVAL_MS 10 + +struct traffic_ctrl_cmd { +union { +uint64_t csr; +struct { +uint32_t read_cmd:1 ; +uint32_t write_cmd:1 ; +uint32_t ack_trans:1 ; +uint32_t rsvd1:29 ; +uint32_t afu_cmd_addr:16 ; +uint32_t rsvd2:16 ; + }; + }; +}; + +struct traffic_ctrl_data { +union { +uint64_t csr; +struct { +uint32_t read_data; +uint32_t write_data; + }; + }; +}; + +struct traffic_ctrl_ch_sel { +union { +uint64_t csr; +struct { +uint32_t channel_sel:3 ; +uint32_t rsvd1:29 ; +uint32_t rsvd2; + }; + }; +}; + +struct he_hssi_ctx { +uint8_t *addr; +}; + +struct he_hssi_priv { +struct rte_pmd_afu_he_hssi_cfg he_hssi_cfg; +struct he_hssi_ctx he_hssi_ctx; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _AFU_PMD_HE_HSSI_H_ */ drivers/raw/ifpga/meson.build +2
-1@@ -14,7 +14,8 @@ deps += ['ethdev', 'rawdev', 'pci', 'bus_pci', 'kvargs', 'bus_vdev', 'bus_ifpga', 'net', 'net_i40e', 'net_ipn3ke'] sources = files('ifpga_rawdev.c', 'rte_pmd_ifpga.c', 'afu_pmd_core.c', - 'afu_pmd_n3000.c', 'afu_pmd_he_lpbk.c', 'afu_pmd_he_mem.c') + 'afu_pmd_n3000.c', 'afu_pmd_he_lpbk.c', 'afu_pmd_he_mem.c', + 'afu_pmd_he_hssi.c') includes += include_directories('base') includes += include_directories('../../net/ipn3ke')(quoted diff) +0
-0
b/drivers/raw/ifpga/rte_pmd_afu.hindex 213e854..b1cebbe 100644drivers/raw/ifpga/rte_pmd_afu.h +18
-1@@ -111,6 +111,24 @@ struct rte_pmd_afu_he_mem_tg_cfg {uint32_t channel_mask;/* mask of traffic generator channel */ }; +#define NUM_RND_SEEDS 3 + +/** +* HE-HSSI AFU configuration data structure. +*/ +struct rte_pmd_afu_he_hssi_cfg { +uint32_t port; +uint32_t timeout; +uint32_t num_packets; +uint32_t random_length; +uint32_t packet_length; +uint32_t random_payload; +uint32_t rnd_seed[NUM_RND_SEEDS ]; +uint64_t src_addr; +uint64_t dest_addr; +int he_loopback; +}; + #ifdef __cplusplus }#endif --
Quoted 1 line
1.8.3.1
v8 cover introduce AFU PMD driver of FPGA
In reply to Wei HuangThe first patch implements the framework of the AFU PMD driver based on raw device interfaces.
The subsequent patches implement the driver of some AFUs.
Changes from v7:
1. move driver description to ifpga.rst per Rosen comment.
2. rename function name according to DPDK program guide per Rosen comment.
Wei Huang (5):
raw/ifpga: introduce AFU driver framework
raw/ifpga: add N3000 AFU driver
raw/ifpga: add HE-LPBK AFU driver
raw/ifpga: add HE-MEM AFU driver
raw/ifpga: add HE-HSSI AFU driver
doc/guides/rawdevs/ifpga.rst | 98 ++ drivers/raw/ifpga/afu_pmd_core.c | 438 ++++++++ drivers/raw/ifpga/afu_pmd_core.h | 95 ++ drivers/raw/ifpga/afu_pmd_he_hssi.c | 371 +++++++ drivers/raw/ifpga/afu_pmd_he_hssi.h | 109 ++ drivers/raw/ifpga/afu_pmd_he_lpbk.c | 436 ++++++++ drivers/raw/ifpga/afu_pmd_he_lpbk.h | 126 +++ drivers/raw/ifpga/afu_pmd_he_mem.c | 183 ++++ drivers/raw/ifpga/afu_pmd_he_mem.h | 46 + drivers/raw/ifpga/afu_pmd_n3000.c | 2019 +++++++++++++++++++++++++++++++++++ drivers/raw/ifpga/afu_pmd_n3000.h | 339 ++++++ drivers/raw/ifpga/meson.build | 4 +- drivers/raw/ifpga/rte_pmd_afu.h | 136 +++ 13 files changed, 4399 insertions(+), 1 deletion(-) create mode 100644 drivers/raw/ifpga/afu_pmd_core.c create mode 100644 drivers/raw/ifpga/afu_pmd_core.h create mode 100644 drivers/raw/ifpga/afu_pmd_he_hssi.c create mode 100644 drivers/raw/ifpga/afu_pmd_he_hssi.h create mode 100644 drivers/raw/ifpga/afu_pmd_he_lpbk.c create mode 100644 drivers/raw/ifpga/afu_pmd_he_lpbk.h create mode 100644 drivers/raw/ifpga/afu_pmd_he_mem.c create mode 100644 drivers/raw/ifpga/afu_pmd_he_mem.h create mode 100644 drivers/raw/ifpga/afu_pmd_n3000.c create mode 100644 drivers/raw/ifpga/afu_pmd_n3000.h create mode 100644 drivers/raw/ifpga/rte_pmd_afu.h
Signature · 1 line
1.8.3.1
PATCH v8 1/5 raw/ifpga: introduce AFU driver framework
AFU (Acceleration Function Unit) is part of FPGA and enumerated by ifpga driver.
This driver implements common AFU device interfaces and exposes them to application as standard raw device APIs. Normally application can operate specified AFU as below,
1. call rte_rawdev_pmd_get_named_dev() to find AFU device.
2. call rte_rawdev_configure() to initialize AFU device.
3. call rte_rawdev_selftest() to test AFU device.
---
v2: fix typo
---
v3: fix build error in FreeBSD13-64, UB2004-32 and UB2204-32
---
v4: fix coding style issue and build error in FreeBSD13-64
---
v5: split patch into several patches
---
v6: move source files to ifpga and rename, use spinlock
---
v7: move driver description into ifpga.rst
--- doc/guides/rawdevs/ifpga.rst | 98 +++++++++ drivers/raw/ifpga/afu_pmd_core.c | 438 +++++++++++++++++++++++++++++++++++++++ drivers/raw/ifpga/afu_pmd_core.h | 76 +++++++ drivers/raw/ifpga/meson.build | 2 +- 4 files changed, 613 insertions(+), 1 deletion(-) create mode 100644 drivers/raw/ifpga/afu_pmd_core.c create mode 100644 drivers/raw/ifpga/afu_pmd_core.h
doc/guides/rawdevs/ifpga.rst +98 -0
@@ -102,6 +102,104 @@ The following device parameters are supported: identifies AFU Bit Stream file. +IFPGA AFU Driver +=================== + +AFU (Acceleration Function Unit) is a function or set of functions that perform +various acceleration task on FPGA platform. The image of AFU is called as GBS +(Green Bit Stream) which can be used by PR (Partial Reconfigure) tool to load +into the FPGA, different AFUs can be dynamically reloaded respectively. + +AFU has two main communication paths between the host: + +- FPGA to host transactions + + The FPGA accesses host memory using a 512 bits data path. This data path has + separate channels for read and write traffic allowing for simultaneous read + and write to occur. The read and write channels support bursts of 1, 2, and + 4 cache lines. + +- Host to FPGA (MMIO) transactions + + The host can access a 256 KB address space within the FPGA. This address space + contains Device Feature Header (DFHs) and the control and status registers of + the AFU hardware. + +AFU must implement the following registers: + +- AFU DFH - a 64-bit header at MMIO address offset 0x0 + +- AFU ID - a 128-bit UUID at MMIO address offset 0x2 + +The AFU is enumerated and recorded by IFPGA Rawdev Driver. Then AFU devices are +created with the help of IFPGA Bus Driver, AFU driver probe these AFU devices +and expose them as standard raw devices for application to access. + +Implementation details +---------------------- + +IFPGA Rawdev Driver identifies AFU in FPGA, AFU location (PF/VF address) and +UUID are taken by ifpga_rawdev_cfg vdev driver which hot plug AFU into IFPGA +Bus. + +IFPGA Bus takes AFU device scan and AFU driver probe. All AFU device driver +bind to AFU device by its dedicated UUID. To avoid unnecessary code duplication +and ensure maximum performance, AFU driver implements the common part of raw +device driver. Several specific AFU drivers are provided for reference. The +design is summarized by the following block diagram:: + + +---------------------------------------------------------------+ + | Application(s) | + +----------------------------.----------------------------------+ + | + +----------------------------'----------------------------------+ + | DPDK Framework (Rawdev APIs) | + +-----------------+------------------------------------+--------+ + | | + +-----------------'----------------+ | + | IFPGA AFU Driver | +--------'--------+ + | | | | + |+---------------+ +--------------+| | | + || AFU Dev1 PMD | | AFU Dev2 PMD || | | + |+-------+-------+ +-------+------+| | | + +--------|-----------------|-------+ | | + | | | | + +--------'------+ +-------'-------+ | IFPGA | + | AFU Dev1 | | AFU Dev2 | | Rawdev Driver | + +-------.-------+ +-------.-------+ | | + | | Rawdev | | + +-------'------------------'-------+ Ops | | + | IFPGA Bus |--------->| | + +-----------------.----------------+ +--------.--------+ + | | + Hot-plugin -->| | + | | + +-----------------'------------------+ +--------'--------+ + | ifpga_rawdev_cfg vdev driver | | Intel FpgaDev | + +------------------------------------+ +-----------------+ + +How to test AFU function +------------------------ + +Suppose AFU is found in FPGA at PCI address 31:00.0, then you can create +and test a AFU device by following steps in application. + +1. rte_vdev_init("ifpga_rawdev_cfg0", "ifpga=31:00.0,port=0") + +2. rawdev = rte_rawdev_pmd_get_named_dev("afu_0|31:00.0") + +3. rte_rawdev_configure(rawdev->dev_id, &cfg, sizeof(cfg)) + +4. rte_rawdev_selftest(rawdev->dev_id) + +5. rte_vdev_uninit("ifpga_rawdev_cfg0") + +AFU device name format used in rte_rawdev_pmd_get_named_dev is +"afu_[port]|[BDF]". Please refer to OPAE documentation for the meaning of +port. Each AFU device has specific configuration data, they are defined +in rte_pmd_afu.h. + + Open FPGA Stack =====================
drivers/raw/ifpga/afu_pmd_core.c new file +438 -0
438 lines not on this page · raw message
drivers/raw/ifpga/afu_pmd_core.h new file +76 -0
76 lines not on this page · raw message
drivers/raw/ifpga/meson.build +1 -1
@@ -13,7 +13,7 @@ objs = [base_objs] deps += ['ethdev', 'rawdev', 'pci', 'bus_pci', 'kvargs', 'bus_vdev', 'bus_ifpga', 'net', 'net_i40e', 'net_ipn3ke'] -sources = files('ifpga_rawdev.c', 'rte_pmd_ifpga.c') +sources = files('ifpga_rawdev.c', 'rte_pmd_ifpga.c', 'afu_pmd_core.c') includes += include_directories('base') includes += include_directories('../../net/ipn3ke')
Signature · 1 line
1.8.3.1
PATCH v8 2/5 raw/ifpga: add N3000 AFU driver
In reply to Wei HuangN3000 AFU includes NLB0 and DMA modules, NLB0 is used to test PCI bus and DMA is used to test local memory.
This driver initialize the modules and report test result.
---
v2: move source files to ifpga and rename, refine code
---
v3: fix Ubuntu 20.04 ARM build
---
v4: rename function name according to DPDK program guide
--- drivers/raw/ifpga/afu_pmd_core.h | 19 + drivers/raw/ifpga/afu_pmd_n3000.c | 2019 +++++++++++++++++++++++++++++++++++++ drivers/raw/ifpga/afu_pmd_n3000.h | 339 +++++++ drivers/raw/ifpga/meson.build | 3 +- drivers/raw/ifpga/rte_pmd_afu.h | 97 ++ 5 files changed, 2476 insertions(+), 1 deletion(-) create mode 100644 drivers/raw/ifpga/afu_pmd_n3000.c create mode 100644 drivers/raw/ifpga/afu_pmd_n3000.h create mode 100644 drivers/raw/ifpga/rte_pmd_afu.h
drivers/raw/ifpga/afu_pmd_core.h +19 -0
@@ -14,6 +14,7 @@#include <unistd.h> #include <rte_spinlock.h> +#include <rte_cycles.h> #include <rte_bus_ifpga.h> #include <rte_rawdev.h>
@@ -60,6 +61,24 @@ struct afu_rawdev {return rawdev ? (struct afu_rawdev *)rawdev->dev_private :NULL ; } +#define CLS_TO_SIZE (n) ((n) << 6)/* get size of n cache lines */ +#define SIZE_TO_CLS (s) ((s) >> 6)/* convert size to number of cache lines */ +#define MHZ (f) ((f) * 1000000) + +#define dsm_poll_timeout (addr, val, cond, invl, timeout) \ +({ \ + uint64_t __wait = 0; \ + uint64_t __invl = (invl); \ + uint64_t __timeout = (timeout); \ + for (; __wait <= __timeout; __wait += __invl) { \ + (val) = *(addr); \ + if (cond) \ + break; \ + rte_delay_ms(__invl); \ + } \ + (cond) ? 0 : 1; \ +}) +void afu_pmd_register (struct afu_rawdev_drv *driver);void afu_pmd_unregister (struct afu_rawdev_drv *driver);
drivers/raw/ifpga/afu_pmd_n3000.c new file +2019 -0
2,019 lines not on this page · raw message
drivers/raw/ifpga/afu_pmd_n3000.h new file +339 -0
339 lines not on this page · raw message
drivers/raw/ifpga/meson.build +2 -1
@@ -13,7 +13,8 @@ objs = [base_objs] deps += ['ethdev', 'rawdev', 'pci', 'bus_pci', 'kvargs', 'bus_vdev', 'bus_ifpga', 'net', 'net_i40e', 'net_ipn3ke'] -sources = files('ifpga_rawdev.c', 'rte_pmd_ifpga.c', 'afu_pmd_core.c') +sources = files('ifpga_rawdev.c', 'rte_pmd_ifpga.c', 'afu_pmd_core.c', + 'afu_pmd_n3000.c') includes += include_directories('base') includes += include_directories('../../net/ipn3ke')
drivers/raw/ifpga/rte_pmd_afu.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 3/5 raw/ifpga: add HE-LPBK AFU driver
In reply to Wei HuangHE-LPBK and HE-MEM-LPBK are host exerciser modules in OFS FPGA, HE-LPBK is used to test PCI bus and HE-MEM-LPBK is used to test local memory.
This driver initialize the modules and report test result.
---
v2: move source files to ifpga and rename, refine code
--- drivers/raw/ifpga/afu_pmd_he_lpbk.c | 436 ++++++++++++++++++++++++++++++++++++ drivers/raw/ifpga/afu_pmd_he_lpbk.h | 126 +++++++++++ drivers/raw/ifpga/meson.build | 2 +- drivers/raw/ifpga/rte_pmd_afu.h | 14 ++ 4 files changed, 577 insertions(+), 1 deletion(-) create mode 100644 drivers/raw/ifpga/afu_pmd_he_lpbk.c create mode 100644 drivers/raw/ifpga/afu_pmd_he_lpbk.h
drivers/raw/ifpga/afu_pmd_he_lpbk.c new file +436 -0
@@ -0,0 +1,436 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2022 Intel Corporation +*/ + +#include <errno.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <inttypes.h> +#include <unistd.h> +#include <fcntl.h> +#include <poll.h> +#include <sys/eventfd.h> +#include <sys/ioctl.h> + +#include <rte_eal.h> +#include <rte_malloc.h> +#include <rte_memcpy.h> +#include <rte_io.h> +#include <rte_vfio.h> +#include <rte_bus_pci.h> +#include <rte_bus_ifpga.h> +#include <rte_rawdev.h> + +#include "afu_pmd_core.h" +#include "afu_pmd_he_lpbk.h" + +static int he_lpbk_afu_config (struct afu_rawdev *dev) +{ +struct he_lpbk_priv *priv =NULL ; +struct rte_pmd_afu_he_lpbk_cfg *cfg =NULL ; +struct he_lpbk_csr_cfg v; + +if (!dev) +return -EINVAL ; + + priv = (struct he_lpbk_priv *)dev->priv; +if (!priv) +return -ENOENT ; + + cfg = &priv->he_lpbk_cfg; + + v.csr =0 ; + +if (cfg->cont) + v.cont =1 ; + + v.mode = cfg->mode; + v.trput_interleave = cfg->trput_interleave; +if (cfg->multi_cl ==4 ) + v.multicl_len =2 ; +else + v.multicl_len = cfg->multi_cl -1 ; + +IFPGA_RAWDEV_PMD_DEBUG ("cfg: 0x%08x" , v.csr); +rte_write32 (v.csr, priv->he_lpbk_ctx.addr +CSR_CFG ); + +return 0 ; +} + +static void he_lpbk_report (struct afu_rawdev *dev,uint32_t cl) +{ +struct he_lpbk_priv *priv =NULL ; +struct rte_pmd_afu_he_lpbk_cfg *cfg =NULL ; +struct he_lpbk_ctx *ctx =NULL ; +struct he_lpbk_dsm_status *stat =NULL ; +struct he_lpbk_status0 stat0; +struct he_lpbk_status1 stat1; +uint64_t swtest_msg =0 ; +uint64_t ticks =0 ; +uint64_t info =0 ; +double num, rd_bw, wr_bw; + +if (!dev || !dev->priv) +return ; + + priv = (struct he_lpbk_priv *)dev->priv; + cfg = &priv->he_lpbk_cfg; + ctx = &priv->he_lpbk_ctx; + + stat = ctx->status_ptr; + + swtest_msg =rte_read64 (ctx->addr +CSR_SWTEST_MSG ); + stat0.csr =rte_read64 (ctx->addr +CSR_STATUS0 ); + stat1.csr =rte_read64 (ctx->addr +CSR_STATUS1 ); + +if (cfg->cont) + ticks = stat->num_clocks - stat->start_overhead; +else + ticks = stat->num_clocks - + (stat->start_overhead + stat->end_overhead); + +if (cfg->freq_mhz ==0 ) { + info =rte_read64 (ctx->addr +CSR_HE_INFO0 ); +IFPGA_RAWDEV_PMD_INFO ("API version: %" PRIx64, info >>16 ); + cfg->freq_mhz = info &0xffff ; +if (cfg->freq_mhz ==0 ) { +IFPGA_RAWDEV_PMD_INFO ("Frequency of AFU clock is unknown." +" Assuming 350 MHz." ); + cfg->freq_mhz =350 ; + } + } + + num = (double )stat0.num_reads; + rd_bw = (num *CLS_TO_SIZE (1 ) *MHZ (cfg->freq_mhz)) / ticks; + num = (double )stat0.num_writes; + wr_bw = (num *CLS_TO_SIZE (1 ) *MHZ (cfg->freq_mhz)) / ticks; + +printf ("Cachelines Read_Count Write_Count Pend_Read Pend_Write " +"Clocks@%uMHz Rd_Bandwidth Wr_Bandwidth\n" , + cfg->freq_mhz); +printf ("%10u %10u %10u %10u %10u %12" PRIu64 +" %7.3f GB/s %7.3f GB/s\n" , + cl, stat0.num_reads, stat0.num_writes, + stat1.num_pend_reads, stat1.num_pend_writes, + ticks, rd_bw /1e9 , wr_bw /1e9 ); +printf ("Test Message: 0x%" PRIx64"\n" , swtest_msg); +} + +static int he_lpbk_test (struct afu_rawdev *dev) +{ +struct he_lpbk_priv *priv =NULL ; +struct rte_pmd_afu_he_lpbk_cfg *cfg =NULL ; +struct he_lpbk_ctx *ctx =NULL ; +struct he_lpbk_csr_ctl ctl; +uint32_t *ptr =NULL ; +uint32_t i, j, cl, val =0 ; +uint64_t sval =0 ; +int ret =0 ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_lpbk_priv *)dev->priv; +if (!priv) +return -ENOENT ; + + cfg = &priv->he_lpbk_cfg; + ctx = &priv->he_lpbk_ctx; + + ctl.csr =0 ; +rte_write32 (ctl.csr, ctx->addr +CSR_CTL ); +rte_delay_us (1000 ); + ctl.reset =1 ; +rte_write32 (ctl.csr, ctx->addr +CSR_CTL ); + +/* initialize DMA addresses */ +IFPGA_RAWDEV_PMD_DEBUG ("src_addr: 0x%" PRIx64, ctx->src_iova); +rte_write64 (SIZE_TO_CLS (ctx->src_iova), ctx->addr +CSR_SRC_ADDR ); + +IFPGA_RAWDEV_PMD_DEBUG ("dst_addr: 0x%" PRIx64, ctx->dest_iova); +rte_write64 (SIZE_TO_CLS (ctx->dest_iova), ctx->addr +CSR_DST_ADDR ); + +IFPGA_RAWDEV_PMD_DEBUG ("dsm_addr: 0x%" PRIx64, ctx->dsm_iova); +rte_write32 (SIZE_TO_CLS (ctx->dsm_iova), ctx->addr +CSR_AFU_DSM_BASEL ); +rte_write32 (SIZE_TO_CLS (ctx->dsm_iova) >>32 , + ctx->addr +CSR_AFU_DSM_BASEH ); + + ret =he_lpbk_afu_config (dev); +if (ret) +return ret; + +/* initialize src data */ + ptr = (uint32_t *)ctx->src_ptr; + j =CLS_TO_SIZE (cfg->end) >>2 ; +for (i =0 ; i < j; i++) + *ptr++ = i; + +/* start test */ +for (cl = cfg->begin; cl <= cfg->end; cl += cfg->multi_cl) { +memset (ctx->dest_ptr,0 ,CLS_TO_SIZE (cl)); +memset (ctx->dsm_ptr,0 ,DSM_SIZE ); + + ctl.csr =0 ; +rte_write32 (ctl.csr, ctx->addr +CSR_CTL ); +rte_delay_us (1000 ); + ctl.reset =1 ; +rte_write32 (ctl.csr, ctx->addr +CSR_CTL ); + +rte_write32 (cl -1 , ctx->addr +CSR_NUM_LINES ); + + ctl.start =1 ; +rte_write32 (ctl.csr, ctx->addr +CSR_CTL ); + +if (cfg->cont) { +rte_delay_ms (cfg->timeout *1000 ); + ctl.force_completion =1 ; +rte_write32 (ctl.csr, ctx->addr +CSR_CTL ); + ret =dsm_poll_timeout (&ctx->status_ptr->test_complete, + val, (val &0x1 ) ==1 ,DSM_POLL_INTERVAL , +DSM_TIMEOUT ); +if (ret) { +printf ("DSM poll timeout\n" ); + goto end; + } + }else { + ret =dsm_poll_timeout (&ctx->status_ptr->test_complete, + val, (val &0x1 ) ==1 ,DSM_POLL_INTERVAL , +DSM_TIMEOUT ); +if (ret) { +printf ("DSM poll timeout\n" ); + goto end; + } + ctl.force_completion =1 ; +rte_write32 (ctl.csr, ctx->addr +CSR_CTL ); + } + +he_lpbk_report (dev, cl); + + i =0 ; +while (i++ <100 ) { + sval =rte_read64 (ctx->addr +CSR_STATUS1 ); +if (sval ==0 ) +break ; +rte_delay_us (1000 ); + } + +if (cfg->mode ==NLB_MODE_LPBK ) { + ptr = (uint32_t *)ctx->dest_ptr; + j =CLS_TO_SIZE (cl) >>2 ; +for (i =0 ; i < j; i++) { +if (*ptr++ != i) { +IFPGA_RAWDEV_PMD_ERR ("Data mismatch @ %u" , i); +break ; + } + } + } + } + +end: +return 0 ; +} + +static int he_lpbk_ctx_release (struct afu_rawdev *dev) +{ +struct he_lpbk_priv *priv =NULL ; +struct he_lpbk_ctx *ctx =NULL ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_lpbk_priv *)dev->priv; +if (!priv) +return -ENOENT ; + + ctx = &priv->he_lpbk_ctx; + +rte_free (ctx->dsm_ptr); + ctx->dsm_ptr =NULL ; + ctx->status_ptr =NULL ; + +rte_free (ctx->src_ptr); + ctx->src_ptr =NULL ; + +rte_free (ctx->dest_ptr); + ctx->dest_ptr =NULL ; + +return 0 ; +} + +static int he_lpbk_ctx_init (struct afu_rawdev *dev) +{ +struct he_lpbk_priv *priv =NULL ; +struct he_lpbk_ctx *ctx =NULL ; +int ret =0 ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_lpbk_priv *)dev->priv; +if (!priv) +return -ENOENT ; + + ctx = &priv->he_lpbk_ctx; + ctx->addr = (uint8_t *)dev->addr; + + ctx->dsm_ptr = (uint8_t *)rte_zmalloc (NULL ,DSM_SIZE ,TEST_MEM_ALIGN ); +if (!ctx->dsm_ptr) +return -ENOMEM ; + ctx->dsm_iova =rte_malloc_virt2iova (ctx->dsm_ptr); +if (ctx->dsm_iova ==RTE_BAD_IOVA ) { + ret = -ENOMEM ; + goto release_dsm; + } + + ctx->src_ptr = (uint8_t *)rte_zmalloc (NULL ,NLB_BUF_SIZE , +TEST_MEM_ALIGN ); +if (!ctx->src_ptr) { + ret = -ENOMEM ; + goto release_dsm; + } + ctx->src_iova =rte_malloc_virt2iova (ctx->src_ptr); +if (ctx->src_iova ==RTE_BAD_IOVA ) { + ret = -ENOMEM ; + goto release_src; + } + + ctx->dest_ptr = (uint8_t *)rte_zmalloc (NULL ,NLB_BUF_SIZE , +TEST_MEM_ALIGN ); +if (!ctx->dest_ptr) { + ret = -ENOMEM ; + goto release_src; + } + ctx->dest_iova =rte_malloc_virt2iova (ctx->dest_ptr); +if (ctx->dest_iova ==RTE_BAD_IOVA ) { + ret = -ENOMEM ; + goto release_dest; + } + + ctx->status_ptr = (struct he_lpbk_dsm_status *)ctx->dsm_ptr; +return 0 ; + +release_dest: +rte_free (ctx->dest_ptr); + ctx->dest_ptr =NULL ; +release_src: +rte_free (ctx->src_ptr); + ctx->src_ptr =NULL ; +release_dsm: +rte_free (ctx->dsm_ptr); + ctx->dsm_ptr =NULL ; +return ret; +} + +static int he_lpbk_init (struct afu_rawdev *dev) +{ +if (!dev) +return -EINVAL ; + +if (!dev->priv) { + dev->priv =rte_zmalloc (NULL ,sizeof (struct he_lpbk_priv ),0 ); +if (!dev->priv) +return -ENOMEM ; + } + +return he_lpbk_ctx_init (dev); +} + +static int he_lpbk_config (struct afu_rawdev *dev,void *config, +size_t config_size) +{ +struct he_lpbk_priv *priv =NULL ; +struct rte_pmd_afu_he_lpbk_cfg *cfg =NULL ; + +if (!dev || !config || !config_size) +return -EINVAL ; + + priv = (struct he_lpbk_priv *)dev->priv; +if (!priv) +return -ENOENT ; + +if (config_size !=sizeof (struct rte_pmd_afu_he_lpbk_cfg )) +return -EINVAL ; + + cfg = (struct rte_pmd_afu_he_lpbk_cfg *)config; +if (cfg->mode >NLB_MODE_TRPUT ) +return -EINVAL ; +if ((cfg->multi_cl !=1 ) && (cfg->multi_cl !=2 ) && + (cfg->multi_cl !=4 )) +return -EINVAL ; +if ((cfg->begin <MIN_CACHE_LINES ) || (cfg->begin >MAX_CACHE_LINES )) +return -EINVAL ; +if ((cfg->end < cfg->begin) || (cfg->end >MAX_CACHE_LINES )) +return -EINVAL ; + +rte_memcpy (&priv->he_lpbk_cfg, cfg,sizeof (priv->he_lpbk_cfg)); + +return 0 ; +} + +static int he_lpbk_close (struct afu_rawdev *dev) +{ +if (!dev) +return -EINVAL ; + +he_lpbk_ctx_release (dev); + +rte_free (dev->priv); + dev->priv =NULL ; + +return 0 ; +} + +static int he_lpbk_dump (struct afu_rawdev *dev,FILE *f) +{ +struct he_lpbk_priv *priv =NULL ; +struct he_lpbk_ctx *ctx =NULL ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_lpbk_priv *)dev->priv; +if (!priv) +return -ENOENT ; + +if (!f) + f = stdout; + + ctx = &priv->he_lpbk_ctx; + +fprintf (f,"addr:\t\t%p\n" , (void *)ctx->addr); +fprintf (f,"dsm_ptr:\t%p\n" , (void *)ctx->dsm_ptr); +fprintf (f,"dsm_iova:\t0x%" PRIx64"\n" , ctx->dsm_iova); +fprintf (f,"src_ptr:\t%p\n" , (void *)ctx->src_ptr); +fprintf (f,"src_iova:\t0x%" PRIx64"\n" , ctx->src_iova); +fprintf (f,"dest_ptr:\t%p\n" , (void *)ctx->dest_ptr); +fprintf (f,"dest_iova:\t0x%" PRIx64"\n" , ctx->dest_iova); +fprintf (f,"status_ptr:\t%p\n" , (void *)ctx->status_ptr); + +return 0 ; +} + +static struct afu_ops he_lpbk_ops = { + .init = he_lpbk_init, + .config = he_lpbk_config, + .start =NULL , + .stop =NULL , + .test = he_lpbk_test, + .close = he_lpbk_close, + .dump = he_lpbk_dump, + .reset =NULL +}; + +struct afu_rawdev_drv he_lpbk_drv = { + .uuid = {HE_LPBK_UUID_L ,HE_LPBK_UUID_H }, + .ops = &he_lpbk_ops +}; + +AFU_PMD_REGISTER (he_lpbk_drv); + +struct afu_rawdev_drv he_mem_lpbk_drv = { + .uuid = {HE_MEM_LPBK_UUID_L ,HE_MEM_LPBK_UUID_H }, + .ops = &he_lpbk_ops +}; + +AFU_PMD_REGISTER (he_mem_lpbk_drv);
drivers/raw/ifpga/afu_pmd_he_lpbk.h new file +126 -0
126 lines not on this page · raw message
drivers/raw/ifpga/meson.build +1 -1
@@ -14,7 +14,7 @@ deps += ['ethdev', 'rawdev', 'pci', 'bus_pci', 'kvargs', 'bus_vdev', 'bus_ifpga', 'net', 'net_i40e', 'net_ipn3ke'] sources = files('ifpga_rawdev.c', 'rte_pmd_ifpga.c', 'afu_pmd_core.c', - 'afu_pmd_n3000.c') + 'afu_pmd_n3000.c', 'afu_pmd_he_lpbk.c') includes += include_directories('base') includes += include_directories('../../net/ipn3ke')
drivers/raw/ifpga/rte_pmd_afu.h +14 -0
@@ -90,6 +90,20 @@ struct rte_pmd_afu_n3000_cfg { }; }; +/** +* HE-LPBK & HE-MEM-LPBK AFU configuration data structure. +*/ +struct rte_pmd_afu_he_lpbk_cfg { +uint32_t mode; +uint32_t begin; +uint32_t end; +uint32_t multi_cl; +uint32_t cont; +uint32_t timeout; +uint32_t trput_interleave; +uint32_t freq_mhz; +}; + #ifdef __cplusplus }#endif
Signature · 1 line
1.8.3.1
PATCH v8 4/5 raw/ifpga: add HE-MEM AFU driver
In reply to Wei HuangHE-MEM is one of the host exerciser modules in OFS FPGA, which is used to test local memory with built-in traffic generator.
This driver initialize the module and report test result.
---
v2: move source files to ifpga and rename
--- drivers/raw/ifpga/afu_pmd_he_mem.c | 183 +++++++++++++++++++++++++++++++++++++ drivers/raw/ifpga/afu_pmd_he_mem.h | 46 ++++++++++ drivers/raw/ifpga/meson.build | 2 +- drivers/raw/ifpga/rte_pmd_afu.h | 7 ++ 4 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 drivers/raw/ifpga/afu_pmd_he_mem.c create mode 100644 drivers/raw/ifpga/afu_pmd_he_mem.h
drivers/raw/ifpga/afu_pmd_he_mem.c new file +183 -0
@@ -0,0 +1,183 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2022 Intel Corporation +*/ + +#include <errno.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <poll.h> +#include <sys/eventfd.h> +#include <sys/ioctl.h> + +#include <rte_eal.h> +#include <rte_malloc.h> +#include <rte_memcpy.h> +#include <rte_io.h> +#include <rte_vfio.h> +#include <rte_bus_pci.h> +#include <rte_bus_ifpga.h> +#include <rte_rawdev.h> + +#include "afu_pmd_core.h" +#include "afu_pmd_he_mem.h" + +static int he_mem_tg_test (struct afu_rawdev *dev) +{ +struct he_mem_tg_priv *priv =NULL ; +struct rte_pmd_afu_he_mem_tg_cfg *cfg =NULL ; +struct he_mem_tg_ctx *ctx =NULL ; +uint64_t value =0x12345678 ; +uint64_t cap =0 ; +uint64_t channel_mask =0 ; +int i, t =0 ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_mem_tg_priv *)dev->priv; +if (!priv) +return -ENOENT ; + + cfg = &priv->he_mem_tg_cfg; + ctx = &priv->he_mem_tg_ctx; + +IFPGA_RAWDEV_PMD_DEBUG ("Channel mask: 0x%x" , cfg->channel_mask); + +rte_write64 (value, ctx->addr +MEM_TG_SCRATCHPAD ); + cap =rte_read64 (ctx->addr +MEM_TG_SCRATCHPAD ); +IFPGA_RAWDEV_PMD_DEBUG ("Scratchpad value: 0x%" PRIx64, cap); +if (cap != value) { +IFPGA_RAWDEV_PMD_ERR ("Test scratchpad register failed" ); +return -EIO ; + } + + cap =rte_read64 (ctx->addr +MEM_TG_CTRL ); +IFPGA_RAWDEV_PMD_DEBUG ("Capability: 0x%" PRIx64, cap); + + channel_mask = cfg->channel_mask & cap; +/* start traffic generators */ +rte_write64 (channel_mask, ctx->addr +MEM_TG_CTRL ); + +/* check test status */ +while (t <MEM_TG_TIMEOUT_MS ) { + value =rte_read64 (ctx->addr +MEM_TG_STAT ); +for (i =0 ; i <NUM_MEM_TG_CHANNELS ; i++) { +if (channel_mask & (1 << i)) { +if (TGACTIVE (value, i)) +continue ; +printf ("TG channel %d test %s\n" , i, +TGPASS (value, i) ?"pass" : +TGTIMEOUT (value, i) ?"timeout" : +TGFAIL (value, i) ?"fail" :"error" ); + channel_mask &= ~(1 << i); + } + } +if (!channel_mask) +break ; +rte_delay_ms (MEM_TG_POLL_INTERVAL_MS ); + t +=MEM_TG_POLL_INTERVAL_MS ; + } + +if (channel_mask) { +IFPGA_RAWDEV_PMD_ERR ("Timeout 0x%04lx" , (unsigned long )value); +return channel_mask; + } + +return 0 ; +} + +static int he_mem_tg_init (struct afu_rawdev *dev) +{ +struct he_mem_tg_priv *priv =NULL ; +struct he_mem_tg_ctx *ctx =NULL ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_mem_tg_priv *)dev->priv; +if (!priv) { + priv =rte_zmalloc (NULL ,sizeof (struct he_mem_tg_priv ),0 ); +if (!priv) +return -ENOMEM ; + dev->priv = priv; + } + + ctx = &priv->he_mem_tg_ctx; + ctx->addr = (uint8_t *)dev->addr; + +return 0 ; +} + +static int he_mem_tg_config (struct afu_rawdev *dev,void *config, +size_t config_size) +{ +struct he_mem_tg_priv *priv =NULL ; + +if (!dev || !config || !config_size) +return -EINVAL ; + + priv = (struct he_mem_tg_priv *)dev->priv; +if (!priv) +return -ENOENT ; + +if (config_size !=sizeof (struct rte_pmd_afu_he_mem_tg_cfg )) +return -EINVAL ; + +rte_memcpy (&priv->he_mem_tg_cfg, config,sizeof (priv->he_mem_tg_cfg)); + +return 0 ; +} + +static int he_mem_tg_close (struct afu_rawdev *dev) +{ +if (!dev) +return -EINVAL ; + +rte_free (dev->priv); + dev->priv =NULL ; + +return 0 ; +} + +static int he_mem_tg_dump (struct afu_rawdev *dev,FILE *f) +{ +struct he_mem_tg_priv *priv =NULL ; +struct he_mem_tg_ctx *ctx =NULL ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_mem_tg_priv *)dev->priv; +if (!priv) +return -ENOENT ; + +if (!f) + f = stdout; + + ctx = &priv->he_mem_tg_ctx; + +fprintf (f,"addr:\t\t%p\n" , (void *)ctx->addr); + +return 0 ; +} + +static struct afu_ops he_mem_tg_ops = { + .init = he_mem_tg_init, + .config = he_mem_tg_config, + .start =NULL , + .stop =NULL , + .test = he_mem_tg_test, + .close = he_mem_tg_close, + .dump = he_mem_tg_dump, + .reset =NULL +}; + +struct afu_rawdev_drv he_mem_tg_drv = { + .uuid = {HE_MEM_TG_UUID_L ,HE_MEM_TG_UUID_H }, + .ops = &he_mem_tg_ops +}; + +AFU_PMD_REGISTER (he_mem_tg_drv);
drivers/raw/ifpga/afu_pmd_he_mem.h new file +46 -0
46 lines not on this page · raw message
drivers/raw/ifpga/meson.build +1 -1
@@ -14,7 +14,7 @@ deps += ['ethdev', 'rawdev', 'pci', 'bus_pci', 'kvargs', 'bus_vdev', 'bus_ifpga', 'net', 'net_i40e', 'net_ipn3ke'] sources = files('ifpga_rawdev.c', 'rte_pmd_ifpga.c', 'afu_pmd_core.c', - 'afu_pmd_n3000.c', 'afu_pmd_he_lpbk.c') + 'afu_pmd_n3000.c', 'afu_pmd_he_lpbk.c', 'afu_pmd_he_mem.c') includes += include_directories('base') includes += include_directories('../../net/ipn3ke')
drivers/raw/ifpga/rte_pmd_afu.h +7 -0
@@ -104,6 +104,13 @@ struct rte_pmd_afu_he_lpbk_cfg {uint32_t freq_mhz; }; +/** +* HE-MEM-TG AFU configuration data structure. +*/ +struct rte_pmd_afu_he_mem_tg_cfg { +uint32_t channel_mask;/* mask of traffic generator channel */ +}; + #ifdef __cplusplus }#endif
Signature · 1 line
1.8.3.1
PATCH v8 5/5 raw/ifpga: add HE-HSSI AFU driver
In reply to Wei HuangHE-HSSI is one of the host exerciser modules in OFS FPGA, which is used to test HSSI (High Speed Serial Interface). This driver initialize the module and report test result.
---
v2: move source files to ifpga and rename, refine code
--- drivers/raw/ifpga/afu_pmd_he_hssi.c | 371 ++++++++++++++++++++++++++++++++++++ drivers/raw/ifpga/afu_pmd_he_hssi.h | 109 +++++++++++ drivers/raw/ifpga/meson.build | 3 +- drivers/raw/ifpga/rte_pmd_afu.h | 18 ++ 4 files changed, 500 insertions(+), 1 deletion(-) create mode 100644 drivers/raw/ifpga/afu_pmd_he_hssi.c create mode 100644 drivers/raw/ifpga/afu_pmd_he_hssi.h
drivers/raw/ifpga/afu_pmd_he_hssi.c new file +371 -0
@@ -0,0 +1,371 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2022 Intel Corporation +*/ + +#include <errno.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <inttypes.h> +#include <unistd.h> +#include <fcntl.h> +#include <poll.h> +#include <sys/eventfd.h> +#include <sys/ioctl.h> + +#include <rte_eal.h> +#include <rte_malloc.h> +#include <rte_memcpy.h> +#include <rte_io.h> +#include <rte_vfio.h> +#include <rte_bus_pci.h> +#include <rte_bus_ifpga.h> +#include <rte_rawdev.h> + +#include "afu_pmd_core.h" +#include "afu_pmd_he_hssi.h" + +static int he_hssi_indirect_write (struct he_hssi_ctx *ctx,uint32_t addr, +uint32_t value) +{ +struct traffic_ctrl_cmd cmd; +struct traffic_ctrl_data data; +uint32_t i =0 ; + +IFPGA_RAWDEV_PMD_DEBUG ("Indirect write 0x%x, value 0x%08x" , addr, value); + +if (!ctx) +return -EINVAL ; + + data.write_data = value; +rte_write64 (data.csr, ctx->addr +TRAFFIC_CTRL_DATA ); + + cmd.csr =0 ; + cmd.write_cmd =1 ; + cmd.afu_cmd_addr = addr; +rte_write64 (cmd.csr, ctx->addr +TRAFFIC_CTRL_CMD ); + +while (i <MAILBOX_TIMEOUT_MS ) { +rte_delay_ms (MAILBOX_POLL_INTERVAL_MS ); + cmd.csr =rte_read64 (ctx->addr +TRAFFIC_CTRL_CMD ); +if (cmd.ack_trans) +break ; + i +=MAILBOX_POLL_INTERVAL_MS ; + } +if (i >=MAILBOX_TIMEOUT_MS ) +return -ETIMEDOUT ; + + i =0 ; + cmd.csr =0 ; +while (i <MAILBOX_TIMEOUT_MS ) { + cmd.ack_trans =1 ; +rte_write64 (cmd.csr, ctx->addr +TRAFFIC_CTRL_CMD ); +rte_delay_ms (MAILBOX_POLL_INTERVAL_MS ); + cmd.csr =rte_read64 (ctx->addr +TRAFFIC_CTRL_CMD ); +if (!cmd.ack_trans) +break ; + i +=MAILBOX_POLL_INTERVAL_MS ; + } +if (i >=MAILBOX_TIMEOUT_MS ) +return -ETIMEDOUT ; + +return 0 ; +} + +static int he_hssi_indirect_read (struct he_hssi_ctx *ctx,uint32_t addr, +uint32_t *value) +{ +struct traffic_ctrl_cmd cmd; +struct traffic_ctrl_data data; +uint32_t i =0 ; + +if (!ctx) +return -EINVAL ; + + cmd.csr =0 ; + cmd.read_cmd =1 ; + cmd.afu_cmd_addr = addr; +rte_write64 (cmd.csr, ctx->addr +TRAFFIC_CTRL_CMD ); + +while (i <MAILBOX_TIMEOUT_MS ) { +rte_delay_ms (MAILBOX_POLL_INTERVAL_MS ); + cmd.csr =rte_read64 (ctx->addr +TRAFFIC_CTRL_CMD ); +if (cmd.ack_trans) { + data.csr =rte_read64 (ctx->addr +TRAFFIC_CTRL_DATA ); + *value = data.read_data; +break ; + } + i +=MAILBOX_POLL_INTERVAL_MS ; + } +if (i >=MAILBOX_TIMEOUT_MS ) +return -ETIMEDOUT ; + + i =0 ; + cmd.csr =0 ; +while (i <MAILBOX_TIMEOUT_MS ) { + cmd.ack_trans =1 ; +rte_write64 (cmd.csr, ctx->addr +TRAFFIC_CTRL_CMD ); +rte_delay_ms (MAILBOX_POLL_INTERVAL_MS ); + cmd.csr =rte_read64 (ctx->addr +TRAFFIC_CTRL_CMD ); +if (!cmd.ack_trans) +break ; + i +=MAILBOX_POLL_INTERVAL_MS ; + } +if (i >=MAILBOX_TIMEOUT_MS ) +return -ETIMEDOUT ; + +IFPGA_RAWDEV_PMD_DEBUG ("Indirect read 0x%x, value 0x%08x" , addr, *value); +return 0 ; +} + +static void he_hssi_report (struct he_hssi_ctx *ctx) +{ +uint32_t val =0 ; +uint64_t v64 =0 ; +int ret =0 ; + + ret =he_hssi_indirect_read (ctx,TM_PKT_GOOD , &val); +if (ret) +return ; +printf ("Number of good packets received: %u\n" , val); + + ret =he_hssi_indirect_read (ctx,TM_PKT_BAD , &val); +if (ret) +return ; +printf ("Number of bad packets received: %u\n" , val); + + ret =he_hssi_indirect_read (ctx,TM_BYTE_CNT1 , &val); +if (ret) +return ; + v64 = val; + ret =he_hssi_indirect_read (ctx,TM_BYTE_CNT0 , &val); +if (ret) +return ; + v64 = (v64 <<32 ) | val; +printf ("Number of bytes received: %" PRIu64"\n" , v64); + + ret =he_hssi_indirect_read (ctx,TM_AVST_RX_ERR , &val); +if (ret) +return ; +if (val &ERR_VALID ) { +printf ("AVST rx error:" ); +if (val &OVERFLOW_ERR ) +printf (" overflow" ); +if (val &LENGTH_ERR ) +printf (" length" ); +if (val &OVERSIZE_ERR ) +printf (" oversize" ); +if (val &UNDERSIZE_ERR ) +printf (" undersize" ); +if (val &MAC_CRC_ERR ) +printf (" crc" ); +if (val &PHY_ERR ) +printf (" phy" ); +printf ("\n" ); + } + + ret =he_hssi_indirect_read (ctx,LOOPBACK_FIFO_STATUS , &val); +if (ret) +return ; +if (val & (ALMOST_EMPTY |ALMOST_FULL )) { +printf ("FIFO status:" ); +if (val &ALMOST_EMPTY ) +printf (" almost empty" ); +if (val &ALMOST_FULL ) +printf (" almost full" ); +printf ("\n" ); + } +} + +static int he_hssi_test (struct afu_rawdev *dev) +{ +struct he_hssi_priv *priv =NULL ; +struct rte_pmd_afu_he_hssi_cfg *cfg =NULL ; +struct he_hssi_ctx *ctx =NULL ; +struct traffic_ctrl_ch_sel sel; +uint32_t val =0 ; +uint32_t i =0 ; +int ret =0 ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_hssi_priv *)dev->priv; +if (!priv) +return -ENOENT ; + + cfg = &priv->he_hssi_cfg; + ctx = &priv->he_hssi_ctx; + + ret =he_hssi_indirect_write (ctx,TG_STOP_XFR ,0 ); +if (ret) +return ret; + + sel.channel_sel = cfg->port; +rte_write64 (sel.csr, ctx->addr +TRAFFIC_CTRL_CH_SEL ); + +if (cfg->he_loopback >=0 ) { + val = cfg->he_loopback ?1 :0 ; +IFPGA_RAWDEV_PMD_INFO ("%s HE loopback on port %u" , + val ?"Enable" :"Disable" , cfg->port); +return he_hssi_indirect_write (ctx,LOOPBACK_EN , val); + } + + ret =he_hssi_indirect_write (ctx,TG_NUM_PKT , cfg->num_packets); +if (ret) +return ret; + + ret =he_hssi_indirect_write (ctx,TG_PKT_LEN , cfg->packet_length); +if (ret) +return ret; + + val = cfg->src_addr &0xffffffff ; + ret =he_hssi_indirect_write (ctx,TG_SRC_MAC_L , val); +if (ret) +return ret; + val = (cfg->src_addr >>32 ) &0xffff ; + ret =he_hssi_indirect_write (ctx,TG_SRC_MAC_H , val); +if (ret) +return ret; + + val = cfg->dest_addr &0xffffffff ; + ret =he_hssi_indirect_write (ctx,TG_DST_MAC_L , val); +if (ret) +return ret; + val = (cfg->dest_addr >>32 ) &0xffff ; + ret =he_hssi_indirect_write (ctx,TG_DST_MAC_H , val); +if (ret) +return ret; + + val = cfg->random_length ?1 :0 ; + ret =he_hssi_indirect_write (ctx,TG_PKT_LEN_TYPE , val); +if (ret) +return ret; + + val = cfg->random_payload ?1 :0 ; + ret =he_hssi_indirect_write (ctx,TG_DATA_PATTERN , val); +if (ret) +return ret; + +for (i =0 ; i <TG_NUM_RND_SEEDS ; i++) { + ret =he_hssi_indirect_write (ctx,TG_RANDOM_SEED (i), + cfg->rnd_seed[i]); +if (ret) +return ret; + } + + ret =he_hssi_indirect_write (ctx,TG_START_XFR ,1 ); +if (ret) +return ret; + +while (i++ < cfg->timeout) { + ret =he_hssi_indirect_read (ctx,TG_PKT_XFRD , &val); +if (ret) +break ; +if (val == cfg->num_packets) +break ; +sleep (1 ); + } + +he_hssi_report (ctx); + +return ret; +} + +static int he_hssi_init (struct afu_rawdev *dev) +{ +struct he_hssi_priv *priv =NULL ; +struct he_hssi_ctx *ctx =NULL ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_hssi_priv *)dev->priv; +if (!priv) { + priv =rte_zmalloc (NULL ,sizeof (struct he_hssi_priv ),0 ); +if (!priv) +return -ENOMEM ; + dev->priv = priv; + } + + ctx = &priv->he_hssi_ctx; + ctx->addr = (uint8_t *)dev->addr; + +return 0 ; +} + +static int he_hssi_config (struct afu_rawdev *dev,void *config, +size_t config_size) +{ +struct he_hssi_priv *priv =NULL ; +struct rte_pmd_afu_he_hssi_cfg *cfg =NULL ; + +if (!dev || !config || !config_size) +return -EINVAL ; + + priv = (struct he_hssi_priv *)dev->priv; +if (!priv) +return -ENOENT ; + +if (config_size !=sizeof (struct rte_pmd_afu_he_hssi_cfg )) +return -EINVAL ; + + cfg = (struct rte_pmd_afu_he_hssi_cfg *)config; +if (cfg->port >=NUM_HE_HSSI_PORTS ) +return -EINVAL ; + +rte_memcpy (&priv->he_hssi_cfg, cfg,sizeof (priv->he_hssi_cfg)); + +return 0 ; +} + +static int he_hssi_close (struct afu_rawdev *dev) +{ +if (!dev) +return -EINVAL ; + +rte_free (dev->priv); + dev->priv =NULL ; + +return 0 ; +} + +static int he_hssi_dump (struct afu_rawdev *dev,FILE *f) +{ +struct he_hssi_priv *priv =NULL ; +struct he_hssi_ctx *ctx =NULL ; + +if (!dev) +return -EINVAL ; + + priv = (struct he_hssi_priv *)dev->priv; +if (!priv) +return -ENOENT ; + +if (!f) + f = stdout; + + ctx = &priv->he_hssi_ctx; + +fprintf (f,"addr:\t\t%p\n" , (void *)ctx->addr); + +return 0 ; +} + +static struct afu_ops he_hssi_ops = { + .init = he_hssi_init, + .config = he_hssi_config, + .start =NULL , + .stop =NULL , + .test = he_hssi_test, + .close = he_hssi_close, + .dump = he_hssi_dump, + .reset =NULL +}; + +struct afu_rawdev_drv he_hssi_drv = { + .uuid = {HE_HSSI_UUID_L ,HE_HSSI_UUID_H }, + .ops = &he_hssi_ops +}; + +AFU_PMD_REGISTER (he_hssi_drv);
drivers/raw/ifpga/afu_pmd_he_hssi.h new file +109 -0
109 lines not on this page · raw message
drivers/raw/ifpga/meson.build +2 -1
@@ -14,7 +14,8 @@ deps += ['ethdev', 'rawdev', 'pci', 'bus_pci', 'kvargs', 'bus_vdev', 'bus_ifpga', 'net', 'net_i40e', 'net_ipn3ke'] sources = files('ifpga_rawdev.c', 'rte_pmd_ifpga.c', 'afu_pmd_core.c', - 'afu_pmd_n3000.c', 'afu_pmd_he_lpbk.c', 'afu_pmd_he_mem.c') + 'afu_pmd_n3000.c', 'afu_pmd_he_lpbk.c', 'afu_pmd_he_mem.c', + 'afu_pmd_he_hssi.c') includes += include_directories('base') includes += include_directories('../../net/ipn3ke')
drivers/raw/ifpga/rte_pmd_afu.h +18 -0
@@ -111,6 +111,24 @@ struct rte_pmd_afu_he_mem_tg_cfg {uint32_t channel_mask;/* mask of traffic generator channel */ }; +#define NUM_RND_SEEDS 3 + +/** +* HE-HSSI AFU configuration data structure. +*/ +struct rte_pmd_afu_he_hssi_cfg { +uint32_t port; +uint32_t timeout; +uint32_t num_packets; +uint32_t random_length; +uint32_t packet_length; +uint32_t random_payload; +uint32_t rnd_seed[NUM_RND_SEEDS ]; +uint64_t src_addr; +uint64_t dest_addr; +int he_loopback; +}; + #ifdef __cplusplus }#endif
Signature · 1 line
1.8.3.1
Re: [PATCH v8 0/5] introduce AFU PMD driver of FPGA
In reply to Wei Huang16/06/2022 05:00, Wei Huang:
Quoted 8 lines
The first patch implements the framework of the AFU PMD driver based on raw device interfaces.
The subsequent patches implement the driver of some AFUs.Changes from v7:
1. move driver description toifpga.rstper Rosen comment.
2. rename function name according to DPDK program guide per Rosen comment.
Quoted 6 lines
Wei Huang (5):
raw/ifpga: introduce AFU driver framework
raw/ifpga: add N3000 AFU driver
raw/ifpga: add HE-LPBK AFU driver
raw/ifpga: add HE-MEM AFU driver
raw/ifpga: add HE-HSSI AFU driver
Applied with few minor improvements, thanks.