From 3cdf8c5d84eeb16a7687ac5c0d34ff959c365ae7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 Jun 2022 14:10:30 +0200 Subject: [PATCH 001/518] drivers: [FEATURE] dynamically alloc FDT buffer --- drivers/kernel/drivers/nfb/pci.c | 37 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index bd8c67b1..2eb16a02 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -25,6 +25,7 @@ #include "mi/mi.h" #include "ndp/ndp.h" +#define NFB_FDT_BURSTSIZE (16384) #define NFB_FDT_MAXSIZE (65536) #define NFB_FDT_FIXUP_NODE_NAME_LEN 16 @@ -472,8 +473,8 @@ static void *nfb_pci_read_fdt(struct pci_dev *pci) } buffer.out_pos = 0; - buffer.out_size = NFB_FDT_MAXSIZE; - buffer.out = kzalloc(NFB_FDT_MAXSIZE, GFP_KERNEL); + buffer.out_size = NFB_FDT_BURSTSIZE; + buffer.out = kzalloc(buffer.out_size, GFP_KERNEL); if (buffer.out == NULL) { ret = -ENOMEM; goto err_alloc_out_buffer; @@ -495,40 +496,62 @@ static void *nfb_pci_read_fdt(struct pci_dev *pci) } /* Initialize a single-call decoder */ - decoder = xz_dec_init(XZ_SINGLE, 0); + decoder = xz_dec_init(XZ_DYNALLOC, (u32)-1); if (decoder == NULL) { ret = -ENOMEM; goto err_dec_init; } /* Run DTB decompression */ - xzret = xz_dec_run(decoder, &buffer); + buffer.out_size = NFB_FDT_BURSTSIZE / 2; + buffer.out = NULL; + do { + buffer.out_size *= 2; + buffer.out = krealloc(buffer.out, buffer.out_size, GFP_KERNEL); + if (buffer.out == NULL) { + ret = -ENOMEM; + goto err_dec_run; + } + xzret = xz_dec_run(decoder, &buffer); + } while (xzret == XZ_OK); + if (xzret != XZ_STREAM_END) { ret = -EBADF; dev_err(&pci->dev, "Unable to decompress FDT, %d.\n", xzret); goto err_dec_run; } + if (fdt_check_header(buffer.out)) { ret = -EBADF; dev_err(&pci->dev, "FDT check header failed.\n"); goto err_fdt_check_header; } + /* Increase size for driver usage */ + buffer.out_size *= 4; + buffer.out = krealloc(buffer.out, buffer.out_size, GFP_KERNEL); + if (buffer.out == NULL) { + ret = -ENOMEM; + goto err_fdt_final_realloc; + } + xz_dec_end(decoder); kfree(buffer.in); fdt = buffer.out; - fdt_set_totalsize(fdt, NFB_FDT_MAXSIZE); + dev_info(&pci->dev, "FDT loaded, size: %u, allocated buffer size: %zu\n", fdt_totalsize(fdt), buffer.out_size); + fdt_set_totalsize(fdt, buffer.out_size); - dev_info(&pci->dev, "FDT loaded.\n"); return fdt; +err_fdt_final_realloc: err_fdt_check_header: err_dec_run: xz_dec_end(decoder); err_dec_init: err_read: - kfree(buffer.out); + if (buffer.out) + kfree(buffer.out); err_alloc_out_buffer: kfree(buffer.in); err_alloc_in_buffer: From 3cbc487d4f9ea3d7caea1a9c87f624923bbf509d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 16 Oct 2023 09:09:36 +0200 Subject: [PATCH 002/518] nfb-dma: [FEATURE] show usable items in HW (values counted from pointers) --- tools/dma/dma.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 2db4b328..ffa96253 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -254,11 +254,13 @@ void rxqueue_print_status(struct nc_rxqueue *q, const char *compatible, int inde printf("HW header pointer : 0x%08lX\n", s.hw_pointer); printf("Header pointer mask : 0x%08lX\n", s.pointer_mask); printf("* Header buffer size : "); print_size(s.pointer_mask ? s.pointer_mask + 1 : 0); printf("\n"); + printf("* Fillable headers in HW : 0x%08lX\n", (s.sw_pointer - s.hw_pointer - 1) & s.pointer_mask); printf("SW descriptor pointer : 0x%08lX\n", s.sd_pointer); printf("HW descriptor pointer : 0x%08lX\n", s.hd_pointer); printf("Descriptor pointer mask : 0x%08lX\n", s.desc_pointer_mask); printf("* Descriptor buffer size : "); print_size(s.desc_pointer_mask ? s.desc_pointer_mask + 1 : 0); printf("\n"); + printf("* Usable descriptors in HW : 0x%08lX\n", (s.sd_pointer - s.hd_pointer) & s.desc_pointer_mask); } else { printf("SW pointer : 0x%08lX\n", s.sw_pointer); printf("HW pointer : 0x%08lX\n", s.hw_pointer); @@ -316,15 +318,11 @@ void txqueue_print_status(struct nc_txqueue *q, const char *compatible, int inde s.stat_running ? "Running " : "Stopped "); if (s.have_dp) { - printf("SW header pointer : 0x%08lX\n", s.sw_pointer); - printf("HW header pointer : 0x%08lX\n", s.hw_pointer); - printf("Header pointer mask : 0x%08lX\n", s.pointer_mask); - printf("* Header buffer size : "); print_size(s.pointer_mask ? s.pointer_mask + 1 : 0); printf("\n"); - printf("SW descriptor pointer : 0x%08lX\n", s.sd_pointer); printf("HW descriptor pointer : 0x%08lX\n", s.hd_pointer); printf("Descriptor pointer mask : 0x%08lX\n", s.desc_pointer_mask); printf("* Descriptor buffer size : "); print_size(s.desc_pointer_mask ? s.desc_pointer_mask + 1 : 0); printf("\n"); + printf("* Usable descriptors in HW : 0x%08lX\n", (s.sd_pointer - s.hd_pointer) & s.desc_pointer_mask); } else { printf("SW pointer : 0x%08lX\n", s.sw_pointer); printf("HW pointer : 0x%08lX\n", s.hw_pointer); From 7eb5842dae7f8f12bed7ed1f6dfa865d987a81f2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 22 Aug 2023 16:03:09 +0200 Subject: [PATCH 003/518] libnfb_ext_python: [FIX] define abstract queues --- .../libnfb_ext_python/libnfb_ext_python.pyx | 5 +-- .../nfb/ext/python/__init__.py | 40 +++++++++++++++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx index 6d0b6a46..0dda8091 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx +++ b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx @@ -204,9 +204,8 @@ cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, i cdef object t try: - _ndp = wrap.nfb.ndp - _d = _ndp.rx if dir == 0 else _ndp.tx - queue = _d[index] + queue = wrap.nfb.queue_open(index, dir, flags) + assert queue is not None except: return -libc.errno.ENODEV diff --git a/ext/libnfb_ext_python/nfb/ext/python/__init__.py b/ext/libnfb_ext_python/nfb/ext/python/__init__.py index dbc0621c..86d16a81 100644 --- a/ext/libnfb_ext_python/nfb/ext/python/__init__.py +++ b/ext/libnfb_ext_python/nfb/ext/python/__init__.py @@ -1,19 +1,53 @@ "libnfb-ext for use in Python" -__all__ = ["AbstractNfbShim"] - +from abc import ABC, abstractmethod import importlib import fdt -class AbstractNfbShim: +class AbstractNdpQueue(ABC): + def start(self): + pass + def stop(self): + pass + +class AbstractNdpQueueRx(AbstractNdpQueue): + @abstractmethod + def burst_get(self, count): + pass + + def burst_put(self): + pass + + +class AbstractNdpQueueTx(AbstractNdpQueue): + @abstractmethod + def burst_get(self, pkts): + pass + + def burst_put(self): + pass + + def burst_flush(self): + pass + + +class AbstractNfb(ABC): def __init__(self, dtb): self._nfb_ext_python_fdt = fdt.parse_dtb(dtb) self._nfb_ext_python_dtb = dtb + def queue_open(self, index, dir, flags): + pass + + def close(self): + pass + + @abstractmethod def read(self, bus_node, comp_node, offset, size): return bytes([]) + @abstractmethod def write(self, bus_node, comp_node, offset, data): return 0 From 6174df08e27e71081b0ded0022a8e754a0b4e89b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 18 Oct 2023 11:02:41 +0200 Subject: [PATCH 004/518] drivers/nfb-pmci: [FIX] use read_poll_timeout_atomic on newer kernels --- drivers/configure.ac | 6 ++++++ drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index 9be96ff4..dd940c97 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -119,6 +119,12 @@ KERNEL_TRY_COMPILE([[ void test(void) {struct class *c = class_create(""); if (c) {} } ]],[AC_DEFINE([CONFIG_CLASS_CREATE_HAVE_ONE_PARAMETER], [1], [Define if class_create has only one parameter]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +AC_MSG_CHECKING([whether kernel has read_poll_timeout_atomic]) +KERNEL_TRY_COMPILE([[ +#include +int trd(off_t a) {return 0;} void test(void) {int ret; read_poll_timeout_atomic(trd, ret, (!ret), 1, 2, false, 0);} +]],[AC_DEFINE([CONFIG_HAVE_READ_POLL_TIMEOUT_ATOMIC], [1], [Define if kernel has read_poll_timeout_atomic]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) + AC_SUBST(KDIR) AC_SUBST(KSRC) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index 2b0543c5..62483442 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -66,6 +66,9 @@ #define PMCI_FIFO_MAX_WORDS (PMCI_FIFO_MAX_BYTES / 4) +#if !defined(CONFIG_HAVE_READ_POLL_TIMEOUT_ATOMIC) +#define read_poll_timeout_atomic read_poll_timeout +#endif struct indirect_ctx { struct device *dev; @@ -80,7 +83,7 @@ static int indirect_bus_clr_cmd(struct indirect_ctx *ctx) nfb_comp_write32(ctx->comp, ctx->offset + INDIRECT_CMD_OFF, 0); - ret = read_poll_timeout(nfb_comp_read32, cmd, (!cmd), INDIRECT_INT_US, INDIRECT_TIMEOUT_US, false, ctx->comp, (ctx->offset + INDIRECT_CMD_OFF)); + ret = read_poll_timeout_atomic(nfb_comp_read32, cmd, (!cmd), INDIRECT_INT_US, INDIRECT_TIMEOUT_US, false, ctx->comp, (ctx->offset + INDIRECT_CMD_OFF)); if (ret) dev_err(ctx->dev, "%s timed out on clearing cmd 0x%xn", __func__, cmd); @@ -104,7 +107,7 @@ static int indirect_bus_reg_read(void *context, unsigned int reg, nfb_comp_write32(ctx->comp, ctx->offset + INDIRECT_CMD_OFF, INDIRECT_CMD_RD); - ret = read_poll_timeout(nfb_comp_read32, cmd, (cmd & INDIRECT_CMD_ACK), INDIRECT_INT_US, INDIRECT_TIMEOUT_US, false, ctx->comp, (ctx->offset + INDIRECT_CMD_OFF)); + ret = read_poll_timeout_atomic(nfb_comp_read32, cmd, (cmd & INDIRECT_CMD_ACK), INDIRECT_INT_US, INDIRECT_TIMEOUT_US, false, ctx->comp, (ctx->offset + INDIRECT_CMD_OFF)); *val = nfb_comp_read32(ctx->comp, ctx->offset + INDIRECT_RD_OFF); @@ -135,7 +138,7 @@ static int indirect_bus_reg_write(void *context, unsigned int reg, nfb_comp_write32(ctx->comp, ctx->offset + INDIRECT_CMD_OFF, INDIRECT_CMD_WR); - ret = read_poll_timeout(nfb_comp_read32, cmd, (cmd & INDIRECT_CMD_ACK), INDIRECT_INT_US, INDIRECT_TIMEOUT_US, false, ctx->comp, (ctx->offset + INDIRECT_CMD_OFF)); + ret = read_poll_timeout_atomic(nfb_comp_read32, cmd, (cmd & INDIRECT_CMD_ACK), INDIRECT_INT_US, INDIRECT_TIMEOUT_US, false, ctx->comp, (ctx->offset + INDIRECT_CMD_OFF)); if (ret) dev_err(ctx->dev, "%s timed out on reg 0x%x cmd 0x%x\n", __func__, reg, cmd); @@ -197,7 +200,7 @@ pmci_get_write_space(struct pmci_device *pmci, u32 size) u32 count, val; int ret; - ret = read_poll_timeout(nfb_comp_read32, val, + ret = read_poll_timeout_atomic(nfb_comp_read32, val, FIELD_GET(PMCI_FLASH_FIFO_SPACE, val) == PMCI_FIFO_MAX_WORDS, PMCI_FLASH_INT_US, PMCI_FLASH_TIMEOUT_US, @@ -251,7 +254,7 @@ pmci_flash_bulk_read(struct intel_m10bmc *m10bmc, void *buf, /* First check of PMCI_FLASH_CTRL reg is too soon after write and doesn't have valid PMCI_FLASH_BUSY flag: */ nfb_comp_read32(pmci->comp, PMCI_FLASH_ADDR); - ret = read_poll_timeout(nfb_comp_read32, val, + ret = read_poll_timeout_atomic(nfb_comp_read32, val, !(val & PMCI_FLASH_BUSY), PMCI_FLASH_INT_US, PMCI_FLASH_TIMEOUT_US, false, pmci->comp, PMCI_FLASH_CTRL); From c8b3812b6ceeff5cb840ce104ef9e1fadc428a76 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 16 Oct 2023 09:34:28 +0200 Subject: [PATCH 005/518] nfb-dma: [FIX] be aware of DMA type for decoding control / status register --- tools/dma/dma.c | 55 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index ffa96253..8dc5f558 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -236,18 +236,30 @@ void rxqueue_print_status(struct nc_rxqueue *q, const char *compatible, int inde nc_rxqueue_read_status(q, &s); printf("Control reg : 0x%.8X", s._ctrl_raw); - printf(" | %s | %s", - s.ctrl_running ? "Run " : "Stop ", - s.ctrl_discard ? "Discard " : "Block "); - - printf(" | EpMsk %.2X | VFID %.2X |\n", (s._ctrl_raw >> 16) & 0xFF, (s._ctrl_raw >> 24) & 0xFF); + if (q->type == QUEUE_TYPE_NDP) { + printf(" | %s |", + s.ctrl_running ? "Run " : "Stop "); + } else if (q->type == QUEUE_TYPE_SZE) { + printf(" | %s | %s | EpMsk %.2X | VFID %.2X |", + s.ctrl_running ? "Run " : "Stop ", + s.ctrl_discard ? "Discard " : "Block ", + (s._ctrl_raw >> 16) & 0xFF, + (s._ctrl_raw >> 24) & 0xFF); + } + printf("\n"); printf("Status reg : 0x%.8X", s._stat_raw); - printf(" | %s | %s | %s | %s |\n", - s.stat_running ? "Running " : "Stopped ", - s.stat_desc_rdy ? "Desc RDY" : "Desc - ", - s.stat_data_rdy ? "Data RDY" : "Data - ", - s.stat_ring_rdy ? "SW RDY " : "SW Full "); + if (q->type == QUEUE_TYPE_NDP) { + printf(" | %s |", + s.stat_running ? "Running " : "Stopped "); + } else if (q->type == QUEUE_TYPE_SZE) { + printf(" | %s | %s | %s | %s |", + s.stat_running ? "Running " : "Stopped ", + s.stat_desc_rdy ? "Desc RDY" : "Desc - ", + s.stat_data_rdy ? "Data RDY" : "Data - ", + s.stat_ring_rdy ? "SW RDY " : "SW Full "); + } + printf("\n"); if (s.have_dp) { printf("SW header pointer : 0x%08lX\n", s.sw_pointer); @@ -308,14 +320,27 @@ void txqueue_print_status(struct nc_txqueue *q, const char *compatible, int inde if (verbose > 0) { nc_txqueue_read_status(q, &s); printf("Control reg : 0x%.8X", s._ctrl_raw); - printf(" | %s", - s.ctrl_running ? "Run " : "Stop "); - printf(" | EpMsk %.2X | VFID %.2X |\n", (s._ctrl_raw >> 16) & 0xFF, (s._ctrl_raw >> 24) & 0xFF); + if (q->type == QUEUE_TYPE_NDP) { + printf(" | %s |", + s.ctrl_running ? "Run " : "Stop "); + } else if (q->type == QUEUE_TYPE_SZE) { + printf(" | %s | EpMsk %.2X | VFID %.2X |", + s.ctrl_running ? "Run " : "Stop ", + (s._ctrl_raw >> 16) & 0xFF, + (s._ctrl_raw >> 24) & 0xFF); + } + printf("\n"); printf("Status reg : 0x%.8X", s._stat_raw); - printf(" | %s |\n", - s.stat_running ? "Running " : "Stopped "); + if (q->type == QUEUE_TYPE_NDP) { + printf(" | %s |", + s.stat_running ? "Running " : "Stopped "); + } else if (q->type == QUEUE_TYPE_SZE) { + printf(" | %s |", + s.stat_running ? "Running " : "Stopped "); + } + printf("\n"); if (s.have_dp) { printf("SW descriptor pointer : 0x%08lX\n", s.sd_pointer); From ac2236e7e65db00806a05c25bbf9d0f7c5cabac5 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 18 Oct 2023 16:30:38 +0200 Subject: [PATCH 006/518] bump version to 6.19.5 --- Changelog | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 6e741fa2..52b2a28e 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +* Wed Oct 18 2023 Martin Spinler - 6.19.5-1 +- [BUGFIX] fixed flashing of N6010 card on newer kernels +- [BUGFIX] correctly decode control / status register in nfb-dma + * Fri Oct 13 2023 Martin Spinler - 6.19.4-1 - [FEATURE] enable COPR build for DPDK version of ndp-tool - [BUGFIX] some fixes in MDIO diff --git a/VERSION b/VERSION index 3a8e58e6..0a61a6d5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.19.4 +6.19.5 From 38b01ff6fa0645fb292ce6f740b78a1956761298 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 18 Oct 2023 20:34:01 +0200 Subject: [PATCH 007/518] pynfb - class Eth: [FIX] handle better setattr() --- pynfb/nfb/eth.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pynfb/nfb/eth.py b/pynfb/nfb/eth.py index 713ae906..797ed5e1 100644 --- a/pynfb/nfb/eth.py +++ b/pynfb/nfb/eth.py @@ -60,6 +60,15 @@ def __getattr__(self, name): else: raise AttributeError + def __setattr__(self, name, value): + if name in ["link"]: + raise AttributeError(f"'Eth' object attribute '{name}' is read-only") + elif name in ["pma_local_loopback"]: + return setattr(self.pcspma, name, value) + else: + object.__setattr__(self, name, value) + + class Transceiver: """ Object representing a transciever interface From 159729c3fece7ce99aa4ac8817ca67c6bcaddf72 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 19 Oct 2023 08:07:35 +0200 Subject: [PATCH 008/518] pynfb - examples: [FIX] wrong keys used for dict returned by NdpQueue.stats_read() --- pynfb/examples/00-quick-reference.py | 2 +- pynfb/examples/02-data-transfer.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pynfb/examples/00-quick-reference.py b/pynfb/examples/00-quick-reference.py index 695414eb..2f62f09c 100644 --- a/pynfb/examples/00-quick-reference.py +++ b/pynfb/examples/00-quick-reference.py @@ -54,7 +54,7 @@ # 2.C NDP queues statistics txq.stats_reset() -assert txq.stats_read()["packets"] == 0 +assert txq.stats_read()["sent"] == 0 # 3.A Single Ethernet port manipulation eth = dev.eth[0] diff --git a/pynfb/examples/02-data-transfer.py b/pynfb/examples/02-data-transfer.py index 8afde5bf..371b421d 100644 --- a/pynfb/examples/02-data-transfer.py +++ b/pynfb/examples/02-data-transfer.py @@ -133,7 +133,7 @@ ####################### try: - # stats == {'packets': 4, 'bytes': 276} + # stats == {'sent': 4, 'sent_bytes': 276} stats = txq.stats_read() # Reset Queue statistics From 4956b01ee71aceaf309087e108c29b1a5427b49c Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 27 Feb 2023 16:49:17 +0100 Subject: [PATCH 009/518] build.sh [FEATURE]: add supported OS to arch distributions --- build.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index b90f2a53..f5315e3c 100755 --- a/build.sh +++ b/build.sh @@ -77,7 +77,7 @@ get_os_number() get_os_id() { - supported_os="ubuntu centos scientific arch fedora ol manjaro rocky" + supported_os="ubuntu centos scientific arch fedora ol manjaro rocky arcolinux" . /etc/os-release @@ -102,7 +102,7 @@ get_install_command() echo "apt-get -qy install" elif item_in_list "$os" "centos scientific fedora ol rocky"; then echo "yum -y install" - elif item_in_list "$os" "arch manjaro"; then + elif item_in_list "$os" "arch manjaro arcolinux"; then echo "pacman -S --needed" fi } @@ -128,7 +128,7 @@ get_prerequisities() ret="$ret make" ret="$ret gcc" ret="$ret rpm-build" - elif item_in_list "$os" "arch manjaro"; then + elif item_in_list "$os" "arch manjaro arcolinux"; then ret="$ret cmake" fi @@ -166,7 +166,7 @@ get_dependencies() else ret="$ret python3-Cython" fi - elif item_in_list "$os" "arch manjaro"; then + elif item_in_list "$os" "arch manjaro arcolinux"; then ret="$ret dtc" ret="$ret numactl" ret="$ret ncurses" From ca9dce72fa183da069a557a3c1f0d31dec3fd340 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Fri, 11 Aug 2023 14:13:24 +0200 Subject: [PATCH 010/518] NDP* [MAINTENANCE]: rename "version" attribute of nc_ndp-queue to "protocol" THe "version" keyword is too general to describe the features of the queue and version is also used to different DMA Controller versions with different features in HW on which a driver should adapt. --- drivers/kernel/drivers/nfb/ndp/ctrl.c | 7 +++++++ drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 1 + libnfb/include/netcope/ndp.h | 17 ++++++----------- libnfb/include/netcope/ndp_priv.h | 2 +- libnfb/include/netcope/ndp_rx.h | 8 ++++---- libnfb/include/netcope/ndp_tx.h | 12 ++++++------ 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl.c b/drivers/kernel/drivers/nfb/ndp/ctrl.c index 4f8d2371..e1327e81 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl.c @@ -354,6 +354,8 @@ static int ndp_ctrl_attach_ring(struct ndp_channel *channel) { int ret; int desc_count; + int node_offset; + void *fdt = channel->ndp->nfb->fdt; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); if (channel->ring.block_count == 0) @@ -386,6 +388,11 @@ static int ndp_ctrl_attach_ring(struct ndp_channel *channel) goto err_alloc_desc; } + node_offset = fdt_path_offset(fdt, channel->id.type == NDP_CHANNEL_TYPE_TX ? + "/drivers/ndp/tx_queues" : "/drivers/ndp/rx_queues"); + node_offset = fdt_subnode_offset(fdt, node_offset, dev_name(&channel->dev)); + fdt_setprop_u32(fdt, node_offset, "protocol", 1); + /* fill descs */ ndp_ctrl_desc(ctrl, ctrl->descriptor_ptr); diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index caa6777f..331d87a0 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -676,6 +676,7 @@ static int ndp_ctrl_attach_ring(struct ndp_channel *channel) "/drivers/ndp/tx_queues" : "/drivers/ndp/rx_queues"); node_offset = fdt_subnode_offset(fdt, node_offset, dev_name(&channel->dev)); + fdt_setprop_u32(fdt, node_offset, "protocol", 2); fdt_setprop_u64(fdt, node_offset, "hdr_mmap_base", ctrl->hdr_mmap_offset); fdt_setprop_u64(fdt, node_offset, "hdr_mmap_size", ctrl->hdr_buffer_size * 2); diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 70562e44..5037c2f8 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -169,6 +169,7 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu ret |= fdt_getprop64(fdt, fdt_offset, "size", &q->size); ret |= fdt_getprop64(fdt, fdt_offset, "mmap_size", &mmap_size); ret |= fdt_getprop64(fdt, fdt_offset, "mmap_base", &mmap_offset); + ret |= fdt_getprop32(fdt, fdt_offset, "protocol", &q->protocol); if (ret) { ret = EBADFD; @@ -180,13 +181,7 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu goto err_zero_mmap_size; } - if (fdt_getprop64(fdt, fdt_offset, "hdr_mmap_base", NULL) == 0) { - q->version = 2; - } else { - q->version = 1; - } - - if (q->version == 2) { + if (q->protocol == 2) { flags |= NDP_CHANNEL_FLAG_USE_HEADER | NDP_CHANNEL_FLAG_USE_OFFSET; } @@ -226,9 +221,9 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu q->sync.swptr = 0; q->sync.hwptr = 0; - if (q->version == 2) { + if (q->protocol == 2) { ret = nc_ndp_v2_open_queue(q, fdt, fdt_offset); - } else if (q->version == 1) { + } else if (q->protocol == 1) { ret = nc_ndp_v1_open_queue(q); } @@ -279,7 +274,7 @@ static int nc_ndp_queue_start(void *priv) if ((ret = _ndp_queue_start(q))) return ret; - if (q->channel.type == NDP_CHANNEL_TYPE_RX && q->version == 2 && (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) == 0) { + if (q->channel.type == NDP_CHANNEL_TYPE_RX && q->protocol == 2 && (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) == 0) { if ((ret = _ndp_queue_sync(q, &q->sync))) return ret; @@ -297,7 +292,7 @@ static int nc_ndp_queue_stop(void *priv) if ((ret = _ndp_queue_stop(q))) return ret; - if (q->version == 1) { + if (q->protocol == 1) { q->u.v1.bytes = 0; } return 0; diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index cfb697f7..b82c4d57 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -66,7 +66,7 @@ struct nc_ndp_queue { /* Control path */ struct ndp_queue *q; - uint32_t version; + uint32_t protocol; uint32_t flags; struct ndp_channel_request channel; diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index e343839c..5bfb7b4a 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -233,9 +233,9 @@ static inline unsigned nc_ndp_rx_burst_get(void *priv, struct ndp_packet *packet { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->version == 2) { + if (q->protocol == 2) { return nc_ndp_v2_rx_burst_get(priv, packets, count); - } else if (q->version == 1) { + } else if (q->protocol == 1) { return nc_ndp_v1_rx_burst_get(priv, packets, count); } return 0; @@ -245,9 +245,9 @@ static inline void nc_ndp_rx_burst_put(void *priv) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->version == 2) { + if (q->protocol == 2) { nc_ndp_v2_rx_unlock(priv); - } else if (q->version == 1) { + } else if (q->protocol == 1) { nc_ndp_v1_rx_burst_put(priv); } } diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index a3effac0..9acb00e1 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -257,9 +257,9 @@ static inline unsigned nc_ndp_tx_burst_get(void *priv, struct ndp_packet *packet { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->version == 2) { + if (q->protocol == 2) { return nc_ndp_v2_tx_burst_get(priv, packets, count); - } else if (q->version == 1) { + } else if (q->protocol == 1) { return nc_ndp_v1_tx_burst_get(priv, packets, count); } return 0; @@ -269,9 +269,9 @@ static inline void nc_ndp_tx_burst_put(void *priv) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->version == 2) { + if (q->protocol == 2) { nc_ndp_v2_tx_burst_put(priv); - } else if (q->version == 1) { + } else if (q->protocol == 1) { nc_ndp_v1_tx_burst_put(priv); } } @@ -280,9 +280,9 @@ static inline void nc_ndp_tx_burst_flush(void *priv) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->version == 2) { + if (q->protocol == 2) { nc_ndp_v2_tx_burst_flush(priv); - } else if (q->version == 1) { + } else if (q->protocol == 1) { nc_ndp_v1_tx_burst_flush(priv); } } From 0f3e523ea1afa9c8cd14b225a9ed8bd2baa86ea8 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Fri, 13 Oct 2023 14:22:02 +0200 Subject: [PATCH 011/518] dma_ctrl_ndp [MAINTENANCE]: change dma_addr_t to uint64_t For compatibility between driver and library. --- libnfb/include/netcope/dma_ctrl_ndp.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 6dba0b5e..c5fbf86b 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -80,15 +80,15 @@ struct nc_ndp_ctrl { }; struct nc_ndp_ctrl_start_params { - dma_addr_t desc_buffer; - dma_addr_t hdr_buffer; - dma_addr_t update_buffer; + uint64_t desc_buffer; + uint64_t hdr_buffer; + uint64_t update_buffer; uint32_t *update_buffer_virt; uint32_t nb_desc; uint32_t nb_hdr; }; -static inline struct nc_ndp_desc nc_ndp_rx_desc0(dma_addr_t phys) +static inline struct nc_ndp_desc nc_ndp_rx_desc0(uint64_t phys) { struct nc_ndp_desc desc; @@ -99,7 +99,7 @@ static inline struct nc_ndp_desc nc_ndp_rx_desc0(dma_addr_t phys) return desc; } -static inline struct nc_ndp_desc nc_ndp_rx_desc2(dma_addr_t phys, uint16_t len, int next) +static inline struct nc_ndp_desc nc_ndp_rx_desc2(uint64_t phys, uint16_t len, int next) { struct nc_ndp_desc desc; @@ -115,12 +115,12 @@ static inline struct nc_ndp_desc nc_ndp_rx_desc2(dma_addr_t phys, uint16_t len, return desc; } -static inline struct nc_ndp_desc nc_ndp_tx_desc0(dma_addr_t phys) +static inline struct nc_ndp_desc nc_ndp_tx_desc0(uint64_t phys) { return nc_ndp_rx_desc0(phys); } -static inline struct nc_ndp_desc nc_ndp_tx_desc2(dma_addr_t phys, uint16_t len, uint16_t meta, int next) +static inline struct nc_ndp_desc nc_ndp_tx_desc2(uint64_t phys, uint16_t len, uint16_t meta, int next) { struct nc_ndp_desc desc; From 44deefe03784918b683e9fcbc0f54a047f2c745e Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Wed, 11 Oct 2023 15:34:29 +0200 Subject: [PATCH 012/518] [MAINTENANCE]: move register map names and control parameters to dma_ctrl_ files The names of registers were unified. The different names of register maps created confusion if the same register was used both by drivers (ctrl.c) and by libnfb ({rx,tx}queue.h). Others parameters for transmission have also been moved do respective dma_ctrl_* files --- drivers/kernel/drivers/nfb/ndp/ctrl.c | 80 +++++++---------- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 13 ++- libnfb/include/netcope/dma_ctrl_ndp.h | 38 +++++--- libnfb/include/netcope/dma_ctrl_sze.h | 51 +++++++++++ libnfb/include/netcope/ndp.h | 3 +- libnfb/include/netcope/queue.h | 27 ++---- libnfb/include/netcope/rxqueue.h | 104 +++++++++------------- libnfb/include/netcope/txqueue.h | 87 ++++++++---------- 8 files changed, 199 insertions(+), 204 deletions(-) create mode 100644 libnfb/include/netcope/dma_ctrl_sze.h diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl.c b/drivers/kernel/drivers/nfb/ndp/ctrl.c index e1327e81..a9c5bb81 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl.c @@ -20,30 +20,10 @@ #include "ndp.h" #include "../nfb.h" -#define NDP_CTRL_UPDATE_SIZE (PAGE_SIZE) - -#define NDP_CTRL_REG_CONTROL 0x00 -#define NDP_CTRL_REG_CONTROL_STOP 0x0 -#define NDP_CTRL_REG_CONTROL_START 0x1 -#define NDP_CTRL_REG_CONTROL_DISCARD 0x2 - -#define NDP_CTRL_REG_STATUS 0x04 -#define NDP_CTRL_REG_STATUS_RUNNING 0x1 - -#define NDP_CTRL_REG_SWPTR 0x08 -#define NDP_CTRL_REG_HWPTR 0x0c -#define NDP_CTRL_REG_BUFSIZE 0x10 -#define NDP_CTRL_REG_IRQ 0x14 -#define NDP_CTRL_REG_DESC 0x20 -#define NDP_CTRL_REG_UPDATE 0x28 -#define NDP_CTRL_REG_IRQ_TIMEOUTE 0x1 -#define NDP_CTRL_REG_IRQ_PTRE 0x2 -#define NDP_CTRL_REG_IRQ_PTR(p) ((p) & ~0x3) -#define NDP_CTRL_REG_TIMEOUT 0x18 -#define NDP_CTRL_REG_TIMEOUT_NS(ns) ((ns) / 5) -#define NDP_CTRL_REG_MAXREQSIZE 0x1C - -#define NDP_CTRL_DESC_PTR 0x1 +#include + +#define SZE_CTRL_REG_IRQ_PTR(p) ((p) & ~0x3) +#define SZE_CTRL_REG_TIMEOUT_NS(ns) ((ns) / 5) struct ndp_ctrl { struct nfb_comp* comp; @@ -190,7 +170,7 @@ static int ndp_ctrl_desc(struct ndp_ctrl *ctrl, uint64_t *desc) /* one descriptor for round-trip */ if (desc) { - *(desc + desc_count) = cpu_to_le64((ctrl->descriptor_phys + second_stage_offset) | NDP_CTRL_DESC_PTR); + *(desc + desc_count) = cpu_to_le64((ctrl->descriptor_phys + second_stage_offset) | SZE_CTRL_DESC_PTR); } desc_count++; @@ -210,7 +190,7 @@ static void ndp_ctrl_set_swptr(struct ndp_channel *channel, uint64_t ptr) { struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); ptr = (ptr - ctrl->initial_offset) & channel->ptrmask; - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_SWPTR, ptr); + nfb_comp_write32(ctrl->comp, SZE_CTRL_REG_SW_POINTER, ptr); ctrl->swptr = ptr; } @@ -220,8 +200,8 @@ static int ndp_ctrl_start(struct ndp_channel *channel, uint64_t *hwptr) unsigned int param; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); - status = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_STATUS); - if (status & NDP_CTRL_REG_STATUS_RUNNING) { + status = nfb_comp_read32(ctrl->comp, SZE_CTRL_REG_STATUS); + if (status & SZE_CTRL_REG_STATUS_RUNNING) { dev_warn(ctrl->comp->nfb->dev, "NDP queue %s is in dirty state, can't be started\n", dev_name(&channel->dev)); return -1; @@ -234,28 +214,28 @@ static int ndp_ctrl_start(struct ndp_channel *channel, uint64_t *hwptr) *((uint64_t*) ctrl->update_ptr) = 0; /* Set address of first descriptor */ - nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_DESC, ctrl->descriptor_phys); + nfb_comp_write64(ctrl->comp, SZE_CTRL_REG_DESC_BASE, ctrl->descriptor_phys); /* Set address of RAM hwptr address */ - nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_UPDATE, ctrl->update_phys); + nfb_comp_write64(ctrl->comp, SZE_CTRL_REG_UPDATE_BASE, ctrl->update_phys); /* Set buffer size (mask) */ - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_BUFSIZE, channel->ptrmask); + nfb_comp_write32(ctrl->comp, SZE_CTRL_REG_BUFFER_SIZE, channel->ptrmask); /* Zero buffer ptr */ - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_SWPTR, 0); + nfb_comp_write32(ctrl->comp, SZE_CTRL_REG_SW_POINTER, 0); /* Timeout */ - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, timeout); + nfb_comp_write32(ctrl->comp, SZE_CTRL_REG_TIMEOUT, timeout); /* Max size */ param = channel->id.type == NDP_CHANNEL_TYPE_RX ? ndp_ctrl_rx_request_size : ndp_ctrl_tx_request_size; - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MAXREQSIZE, param); + nfb_comp_write32(ctrl->comp, SZE_CTRL_REG_MAX_REQUEST, param); /* Start controller */ - param = NDP_CTRL_REG_CONTROL_START; - param |= (ctrl->flags & NDP_CHANNEL_FLAG_DISCARD) ? NDP_CTRL_REG_CONTROL_DISCARD : 0; - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, param); + param = SZE_CTRL_REG_CONTROL_START; + param |= (ctrl->flags & NDP_CHANNEL_FLAG_DISCARD) ? SZE_CTRL_REG_CONTROL_DISCARD : 0; + nfb_comp_write32(ctrl->comp, SZE_CTRL_REG_CONTROL, param); *hwptr = ctrl->initial_offset; return 0; @@ -267,8 +247,8 @@ static uint64_t ndp_ctrl_get_flags(struct ndp_channel *channel) uint32_t reg; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); - reg = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_CONTROL); - if (reg & NDP_CTRL_REG_CONTROL_DISCARD) + reg = nfb_comp_read32(ctrl->comp, SZE_CTRL_REG_CONTROL); + if (reg & SZE_CTRL_REG_CONTROL_DISCARD) ret |= NDP_CHANNEL_FLAG_DISCARD; return ret; @@ -282,13 +262,13 @@ static uint64_t ndp_ctrl_set_flags(struct ndp_channel *channel, uint64_t flags) ctrl->flags = flags; - regwr = reg = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_CONTROL); - regwr &= ~(NDP_CTRL_REG_CONTROL_DISCARD); + regwr = reg = nfb_comp_read32(ctrl->comp, SZE_CTRL_REG_CONTROL); + regwr &= ~(SZE_CTRL_REG_CONTROL_DISCARD); - regwr |= (ctrl->flags & NDP_CHANNEL_FLAG_DISCARD) ? NDP_CTRL_REG_CONTROL_DISCARD : 0; + regwr |= (ctrl->flags & NDP_CHANNEL_FLAG_DISCARD) ? SZE_CTRL_REG_CONTROL_DISCARD : 0; if (reg != regwr) - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, regwr); + nfb_comp_write32(ctrl->comp, SZE_CTRL_REG_CONTROL, regwr); ret = flags; ret &= ~NDP_CHANNEL_FLAG_DISCARD; @@ -325,8 +305,8 @@ static int ndp_ctrl_stop(struct ndp_channel *channel, int force) } } - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, - NDP_CTRL_REG_CONTROL_STOP | NDP_CTRL_REG_CONTROL_DISCARD); + nfb_comp_write32(ctrl->comp, SZE_CTRL_REG_CONTROL, + SZE_CTRL_REG_CONTROL_STOP | SZE_CTRL_REG_CONTROL_DISCARD); if (channel->id.type == NDP_CHANNEL_TYPE_RX) { ndp_ctrl_set_swptr(channel, ndp_ctrl_get_hwptr(channel)); @@ -335,8 +315,8 @@ static int ndp_ctrl_stop(struct ndp_channel *channel, int force) cnt = 0; while (1) { uint32_t status; - status = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_STATUS); - if (dirty || !(status & NDP_CTRL_REG_STATUS_RUNNING)) + status = nfb_comp_read32(ctrl->comp, SZE_CTRL_REG_STATUS); + if (dirty || !(status & SZE_CTRL_REG_STATUS_RUNNING)) break; if (cnt++ > 100) { dev_warn(ctrl->comp->nfb->dev, @@ -361,7 +341,7 @@ static int ndp_ctrl_attach_ring(struct ndp_channel *channel) if (channel->ring.block_count == 0) return 0; - ctrl->update_ptr = dma_alloc_coherent(channel->ring.dev, NDP_CTRL_UPDATE_SIZE, + ctrl->update_ptr = dma_alloc_coherent(channel->ring.dev, SZE_CTRL_UPDATE_SIZE, &ctrl->update_phys, GFP_KERNEL); if (ctrl->update_ptr == NULL) { ret = -ENOMEM; @@ -402,7 +382,7 @@ static int ndp_ctrl_attach_ring(struct ndp_channel *channel) err_alloc_desc: err_desc_count: - dma_free_coherent(channel->ring.dev, NDP_CTRL_UPDATE_SIZE, + dma_free_coherent(channel->ring.dev, SZE_CTRL_UPDATE_SIZE, ctrl->update_ptr, ctrl->update_phys); err_alloc_update: return ret; @@ -422,7 +402,7 @@ static void ndp_ctrl_detach_ring(struct ndp_channel *channel) } if (ctrl->update_ptr) { - dma_free_coherent(channel->ring.dev, NDP_CTRL_UPDATE_SIZE, + dma_free_coherent(channel->ring.dev, SZE_CTRL_UPDATE_SIZE, ctrl->update_ptr, ctrl->update_phys); ctrl->update_ptr = NULL; } diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 331d87a0..a00ccabf 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -22,23 +22,20 @@ #include -#define NDP_CTRL_UPDATE_SIZE (4) - #define NDP_CTRL_TX_DESC_SIZE (sizeof(struct nc_ndp_desc)) #define NDP_CTRL_RX_DESC_SIZE (sizeof(struct nc_ndp_desc)) #define NDP_CTRL_RX_HDR_SIZE (sizeof(struct nc_ndp_hdr)) -#define NDP_TX_BURST (64u) #define NDP_CTRL_RX_DESC_BURST (64u) -#define NDP_CTRL_MODE_PACKET_SIMPLE 0 /* One desc per packet only, except desc type0 */ -#define NDP_CTRL_MODE_STREAM 1 /* More packets in one descriptor with 8B padding */ -#define NDP_CTRL_MODE_USER 2 /* User provides descriptors in offset + header buffer */ - -#define virt_to_phys_shift(x) (virt_to_phys(x) >> PAGE_SHIFT) +#define NDP_CTRL_MODE_PACKET_SIMPLE 0 /* One desc per packet only, except desc type0 */ +#define NDP_CTRL_MODE_STREAM 1 /* More packets in one descriptor with 8B padding */ +#define NDP_CTRL_MODE_USER 2 /* User provides descriptors in offset + header buffer */ #define NDP_CTRL_NEXT_SDP_AGE_MAX 16 +#define virt_to_phys_shift(x) (virt_to_phys(x) >> PAGE_SHIFT) + typedef uint64_t ndp_offset_t; /* Size of buffer for one packet in ring */ diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index c5fbf86b..d55b2a3a 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -2,9 +2,10 @@ /* * Network component library - DMA controller - NDP/v2 type * - * Copyright (C) 2020-2022 CESNET + * Copyright (C) 2020-2023 CESNET * Author(s): * Martin Spinler + * Vladislav Valek */ #ifndef NETCOPE_DMA_CTRL_NDP_H @@ -14,7 +15,6 @@ #define COMP_NC_DMA_CTRL_NDP_RX "netcope,dma_ctrl_ndp_rx" #define COMP_NC_DMA_CTRL_NDP_TX "netcope,dma_ctrl_ndp_tx" -#define NDP_CTRL_DESC_UPPER_ADDR(addr) (((uint64_t)addr) & 0xFFFFFFFFc0000000ull) #define NDP_CTRL_REG_CONTROL 0x00 #define NDP_CTRL_REG_CONTROL_STOP 0x0 @@ -24,13 +24,29 @@ #define NDP_CTRL_REG_SDP 0x10 #define NDP_CTRL_REG_SHP 0x14 #define NDP_CTRL_REG_HDP 0x18 -#define NDP_CTRL_REG_HHP 0x1c -#define NDP_CTRL_REG_TIMEOUT 0x20 -#define NDP_CTRL_REG_DESC 0x40 -#define NDP_CTRL_REG_HDR 0x48 -#define NDP_CTRL_REG_UPDATE 0x50 +#define NDP_CTRL_REG_HHP 0x1C +#define NDP_CTRL_REG_DESC_BASE 0x40 +#define NDP_CTRL_REG_HDR_BASE 0x48 +#define NDP_CTRL_REG_UPDATE_BASE 0x50 #define NDP_CTRL_REG_MDP 0x58 -#define NDP_CTRL_REG_MHP 0x5c +#define NDP_CTRL_REG_MHP 0x5C + +// --------------- NDP specific registers -------------- +#define NDP_CTRL_REG_TIMEOUT 0x20 + +// -------------- NDP Counters ----------------- +// Processed packets on TX +#define NDP_CTRL_REG_CNTR_SENT 0x60 +// Processed packets on RX +#define NDP_CTRL_REG_CNTR_RECV 0x60 +// Discarded packets +#define NDP_CTRL_REG_CNTR_DISC 0x70 + +// -------------- Data transmission parameters --------- +#define NDP_CTRL_UPDATE_SIZE 4 +#define NDP_PACKET_HEADER_SIZE 4 + +#define NDP_CTRL_DESC_UPPER_ADDR(addr) (((uint64_t)addr) & 0xFFFFFFFFc0000000ull) #define NDP_CTRL_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -259,13 +275,13 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl } /* Set address of first descriptor */ - nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_DESC, sp->desc_buffer); + nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_DESC_BASE, sp->desc_buffer); /* Set address of RAM hwptr address */ - nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_UPDATE, sp->update_buffer); + nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_UPDATE_BASE, sp->update_buffer); if (ctrl->dir == 0) - nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_HDR, sp->hdr_buffer); + nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_HDR_BASE, sp->hdr_buffer); /* Set buffer size (mask) */ nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MDP, ctrl->mdp); diff --git a/libnfb/include/netcope/dma_ctrl_sze.h b/libnfb/include/netcope/dma_ctrl_sze.h new file mode 100644 index 00000000..a920008f --- /dev/null +++ b/libnfb/include/netcope/dma_ctrl_sze.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * DMA Controller - SZE/v1 type + * + * Copyright (C) 2023-2023 CESNET + * Author(s): + * Vladislav Valek + */ + +#ifndef DMA_CTRL_SZE_H +#define DMA_CTRL_SZE_H + +#ifdef __cplusplus +extern "C" { +#endif + +// ----------------- Contro/status registers ---------- +#define SZE_CTRL_REG_CONTROL 0x00 + #define SZE_CTRL_REG_CONTROL_STOP 0x0 + #define SZE_CTRL_REG_CONTROL_START 0x1 + #define SZE_CTRL_REG_CONTROL_DISCARD 0x2 +#define SZE_CTRL_REG_STATUS 0x04 + #define SZE_CTRL_REG_STATUS_RUNNING 0x1 +#define SZE_CTRL_REG_SW_POINTER 0x08 +#define SZE_CTRL_REG_HW_POINTER 0x0C +#define SZE_CTRL_REG_BUFFER_SIZE 0x10 +#define SZE_CTRL_REG_IRQ 0x14 + #define SZE_CTRL_REG_IRQ_TIMEOUTE 0x1 + #define SZE_CTRL_REG_IRQ_PTRE 0x2 +#define SZE_CTRL_REG_TIMEOUT 0x18 +#define SZE_CTRL_REG_MAX_REQUEST 0x1C +#define SZE_CTRL_REG_DESC_BASE 0x20 +#define SZE_CTRL_REG_UPDATE_BASE 0x28 + +// ----------------- Counters ------------------------ +// Processed packets on TX +#define SZE_CTRL_REG_CNTR_SENT 0x30 +// Processed packets on RX +#define SZE_CTRL_REG_CNTR_RECV 0x30 +// Discarded packets +#define SZE_CTRL_REG_CNTR_DISC 0x38 + +// ---------------- Other parameters ----------------- +#define SZE_CTRL_UPDATE_SIZE (PAGE_SIZE) +#define SZE_CTRL_DESC_PTR 0x1 + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* DMA_CTRL_SZE_H */ diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 5037c2f8..0411bf70 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -13,8 +13,6 @@ #ifndef _NC_NDP_H_ #define _NC_NDP_H_ -#define NDP_PACKET_HEADER_SIZE 4 - void ndp_close_queue(struct ndp_queue *q); int _ndp_queue_sync(struct nc_ndp_queue *q, struct ndp_subscription_sync *sync); @@ -24,6 +22,7 @@ int _ndp_queue_stop(struct nc_ndp_queue *q); static int nc_ndp_queue_start(void *priv); static int nc_ndp_queue_stop(void *priv); +#include "dma_ctrl_ndp.h" #include "ndp_rx.h" #include "ndp_tx.h" diff --git a/libnfb/include/netcope/queue.h b/libnfb/include/netcope/queue.h index 6a9b8dfe..6e9cf444 100644 --- a/libnfb/include/netcope/queue.h +++ b/libnfb/include/netcope/queue.h @@ -14,6 +14,9 @@ extern "C" { #endif +#include "dma_ctrl_ndp.h" +#include "dma_ctrl_sze.h" + /* ~~~~[ DATA TYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ enum queue_type { QUEUE_TYPE_UNDEF = -1, @@ -21,26 +24,10 @@ enum queue_type { QUEUE_TYPE_NDP }; -#define DMA_CTRL_NDP_REG_CONTROL 0x00 -#define DMA_CTRL_NDP_REG_STATUS 0x04 -#define DMA_CTRL_NDP_REG_SDP 0x10 -#define DMA_CTRL_NDP_REG_SHP 0x14 -#define DMA_CTRL_NDP_REG_HDP 0x18 -#define DMA_CTRL_NDP_REG_HHP 0x1C -#define DMA_CTRL_NDP_REG_TIMEOUT 0x20 -#define DMA_CTRL_NDP_REG_DESC_BASE 0x40 -#define DMA_CTRL_NDP_REG_HDR_BASE 0x48 -#define DMA_CTRL_NDP_REG_UPDATE_BASE 0x4C -#define DMA_CTRL_NDP_REG_MDP 0x58 -#define DMA_CTRL_NDP_REG_MHP 0x5C - -#define DMA_CTRL_NDP_CNTR_CMD_RST 0 -#define DMA_CTRL_NDP_CNTR_CMD_STRB 1 -#define DMA_CTRL_NDP_CNTR_CMD_STRB_RST 2 - -/* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -/* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +// -------------- Counter control commands -------------------- +#define CNTR_CMD_RST 0 +#define CNTR_CMD_STRB 1 +#define CNTR_CMD_STRB_RST 2 #ifdef __cplusplus } // extern "C" diff --git a/libnfb/include/netcope/rxqueue.h b/libnfb/include/netcope/rxqueue.h index f3053863..f5d5644c 100644 --- a/libnfb/include/netcope/rxqueue.h +++ b/libnfb/include/netcope/rxqueue.h @@ -5,6 +5,7 @@ * Copyright (C) 2018-2022 CESNET * Author(s): * Martin Spinler + * Vladislav Valek */ #ifndef NETCOPE_RXQUEUE_H @@ -64,26 +65,6 @@ static inline void nc_rxqueue_read_counters(struct nc_rxqueue *rxq static inline void nc_rxqueue_read_status(struct nc_rxqueue *rxqueue, struct nc_rxqueue_status *status); /* ~~~~[ MACROS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -/* ~~~~[ REGISTERS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#define RXQUEUE_REG_CONTROL 0x00 -#define RXQUEUE_REG_STATUS 0x04 -#define RXQUEUE_REG_SW_POINTER 0x08 -#define RXQUEUE_REG_HW_POINTER 0x0C -#define RXQUEUE_REG_BUFFER_SIZE 0x10 -#define RXQUEUE_REG_TIMEOUT 0x18 -#define RXQUEUE_REG_MAX_REQUEST 0x1C -#define RXQUEUE_REG_DESC_BASE 0x20 -#define RXQUEUE_REG_POINTER_BASE 0x28 - -#define RXQUEUE_REG_RECEIVED 0x30 -#define RXQUEUE_REG_DISCARDED 0x38 - -#define RXQUEUE_REG_RESET 0x30 - -#define DMA_CTRL_NDP_RX_REG_RECEIVED 0x60 -#define DMA_CTRL_NDP_RX_REG_DISCARDED 0x70 - #define COMP_NETCOPE_RXQUEUE_SZE "netcope,dma_ctrl_sze_rx" #define COMP_NETCOPE_RXQUEUE_NDP "netcope,dma_ctrl_ndp_rx" @@ -130,9 +111,9 @@ static inline void nc_rxqueue_close(struct nc_rxqueue *rxqueue) static inline void nc_rxqueue_reset_counters(struct nc_rxqueue *rxqueue) { if (rxqueue->type == QUEUE_TYPE_NDP) { - nfb_comp_write32(nfb_user_to_comp(rxqueue), DMA_CTRL_NDP_RX_REG_RECEIVED, DMA_CTRL_NDP_CNTR_CMD_RST); + nfb_comp_write32(nfb_user_to_comp(rxqueue), NDP_CTRL_REG_CNTR_RECV, CNTR_CMD_RST); } else { - nfb_comp_write32(nfb_user_to_comp(rxqueue), RXQUEUE_REG_RESET, 1); + nfb_comp_write32(nfb_user_to_comp(rxqueue), SZE_CTRL_REG_CNTR_RECV, CNTR_CMD_STRB); } } @@ -140,16 +121,16 @@ static inline void _nc_rxqueue_read_counters(struct nc_rxqueue *rxqueue, struct { struct nfb_comp *comp = nfb_user_to_comp(rxqueue); if (rxqueue->type == QUEUE_TYPE_NDP) { - nfb_comp_write32(nfb_user_to_comp(rxqueue), DMA_CTRL_NDP_RX_REG_RECEIVED, cmd); - c->received = nfb_comp_read64(comp, DMA_CTRL_NDP_RX_REG_RECEIVED); - c->received_bytes = nfb_comp_read64(comp, DMA_CTRL_NDP_RX_REG_RECEIVED+8); - c->discarded = nfb_comp_read64(comp, DMA_CTRL_NDP_RX_REG_DISCARDED); - c->discarded_bytes = nfb_comp_read64(comp, DMA_CTRL_NDP_RX_REG_DISCARDED+8); + nfb_comp_write32(nfb_user_to_comp(rxqueue), NDP_CTRL_REG_CNTR_RECV, cmd); + c->received = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_RECV); + c->received_bytes = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_RECV+8); + c->discarded = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_DISC); + c->discarded_bytes = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_DISC+8); c->have_bytes = 1; } else { - c->received = nfb_comp_read64(comp, RXQUEUE_REG_RECEIVED); - c->discarded = nfb_comp_read64(comp, RXQUEUE_REG_DISCARDED); + c->received = nfb_comp_read64(comp, SZE_CTRL_REG_CNTR_RECV); c->received_bytes = 0; + c->discarded = nfb_comp_read64(comp, SZE_CTRL_REG_CNTR_DISC); c->discarded_bytes = 0; c->have_bytes = 0; } @@ -158,7 +139,7 @@ static inline void _nc_rxqueue_read_counters(struct nc_rxqueue *rxqueue, struct static inline int nc_rxqueue_read_and_reset_counters(struct nc_rxqueue *queue, struct nc_rxqueue_counters *c) { if (queue->type == QUEUE_TYPE_NDP) { - _nc_rxqueue_read_counters(queue, c, DMA_CTRL_NDP_CNTR_CMD_STRB_RST); + _nc_rxqueue_read_counters(queue, c, CNTR_CMD_STRB_RST); } else { return -ENXIO; } @@ -167,7 +148,7 @@ static inline int nc_rxqueue_read_and_reset_counters(struct nc_rxqueue *queue, s static inline void nc_rxqueue_read_counters(struct nc_rxqueue *queue, struct nc_rxqueue_counters *c) { - _nc_rxqueue_read_counters(queue, c, DMA_CTRL_NDP_CNTR_CMD_STRB); + _nc_rxqueue_read_counters(queue, c, CNTR_CMD_STRB); } static inline void nc_rxqueue_read_status(struct nc_rxqueue *rxqueue, struct nc_rxqueue_status *s) @@ -176,38 +157,37 @@ static inline void nc_rxqueue_read_status(struct nc_rxqueue *rxqueue, struct nc_ memset(s, 0, sizeof(*s)); if (rxqueue->type == QUEUE_TYPE_NDP) { - s->_ctrl_raw = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_CONTROL); - s->_stat_raw = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_STATUS); - s->sw_pointer = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_SHP); - s->hw_pointer = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_HHP); - s->pointer_mask = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_MHP); - s->sd_pointer = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_SDP); - s->hd_pointer = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_HDP); - s->desc_pointer_mask = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_MDP); - s->timeout = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_TIMEOUT); - s->max_request = 0; - s->desc_base = nfb_comp_read64(comp, DMA_CTRL_NDP_REG_DESC_BASE); - s->pointer_base = nfb_comp_read64(comp, DMA_CTRL_NDP_REG_UPDATE_BASE); - s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; - s->stat_running = (s->_stat_raw & 1) ? 1 : 0; - s->have_dp = 1; + s->_ctrl_raw = nfb_comp_read32(comp, NDP_CTRL_REG_CONTROL); + s->_stat_raw = nfb_comp_read32(comp, NDP_CTRL_REG_STATUS); + s->sw_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SHP); + s->hw_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HHP); + s->pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MHP); + s->sd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SDP); + s->hd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HDP); + s->desc_pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MDP); + s->timeout = nfb_comp_read32(comp, NDP_CTRL_REG_TIMEOUT); + s->max_request = 0; + s->desc_base = nfb_comp_read64(comp, NDP_CTRL_REG_DESC_BASE); + s->pointer_base = nfb_comp_read64(comp, NDP_CTRL_REG_UPDATE_BASE); + s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; + s->stat_running = (s->_stat_raw & 1) ? 1 : 0; } else { - s->_ctrl_raw = nfb_comp_read32(comp, RXQUEUE_REG_CONTROL); - s->_stat_raw = nfb_comp_read32(comp, RXQUEUE_REG_STATUS); - s->sw_pointer = nfb_comp_read32(comp, RXQUEUE_REG_SW_POINTER); - s->hw_pointer = nfb_comp_read32(comp, RXQUEUE_REG_HW_POINTER); - s->pointer_mask = nfb_comp_read32(comp, RXQUEUE_REG_BUFFER_SIZE); - s->timeout = nfb_comp_read32(comp, RXQUEUE_REG_TIMEOUT); - s->max_request = nfb_comp_read16(comp, RXQUEUE_REG_MAX_REQUEST); - s->desc_base = nfb_comp_read64(comp, RXQUEUE_REG_DESC_BASE); - s->pointer_base = nfb_comp_read64(comp, RXQUEUE_REG_POINTER_BASE); - s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; - s->ctrl_discard = (s->_ctrl_raw & 2) ? 1 : 0; - //s->ctrl_vfid = (reg >> 24) & 0xFF - s->stat_running = (s->_stat_raw & 1) ? 1 : 0; - s->stat_desc_rdy = (s->_stat_raw & 2) ? 1 : 0; - s->stat_data_rdy = (s->_stat_raw & 4) ? 1 : 0; - s->stat_ring_rdy = (s->_stat_raw & 8) ? 1 : 0; + s->_ctrl_raw = nfb_comp_read32(comp, SZE_CTRL_REG_CONTROL); + s->_stat_raw = nfb_comp_read32(comp, SZE_CTRL_REG_STATUS); + s->sw_pointer = nfb_comp_read32(comp, SZE_CTRL_REG_SW_POINTER); + s->hw_pointer = nfb_comp_read32(comp, SZE_CTRL_REG_HW_POINTER); + s->pointer_mask = nfb_comp_read32(comp, SZE_CTRL_REG_BUFFER_SIZE); + s->timeout = nfb_comp_read32(comp, SZE_CTRL_REG_TIMEOUT); + s->max_request = nfb_comp_read16(comp, SZE_CTRL_REG_MAX_REQUEST); + s->desc_base = nfb_comp_read64(comp, SZE_CTRL_REG_DESC_BASE); + s->pointer_base = nfb_comp_read64(comp, SZE_CTRL_REG_UPDATE_BASE); + s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; + s->ctrl_discard = (s->_ctrl_raw & 2) ? 1 : 0; + //s->ctrl_vfid = (reg >> 24) & 0xFF + s->stat_running = (s->_stat_raw & 1) ? 1 : 0; + s->stat_desc_rdy = (s->_stat_raw & 2) ? 1 : 0; + s->stat_data_rdy = (s->_stat_raw & 4) ? 1 : 0; + s->stat_ring_rdy = (s->_stat_raw & 8) ? 1 : 0; } } diff --git a/libnfb/include/netcope/txqueue.h b/libnfb/include/netcope/txqueue.h index b3e6c879..4072bf75 100644 --- a/libnfb/include/netcope/txqueue.h +++ b/libnfb/include/netcope/txqueue.h @@ -5,6 +5,7 @@ * Copyright (C) 2018-2022 CESNET * Author(s): * Martin Spinler + * Vladislav Valek */ #ifndef NETCOPE_TXQUEUE_H @@ -57,21 +58,6 @@ static inline int nc_txqueue_read_status(struct nc_txqueue *txque /* ~~~~[ MACROS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* ~~~~[ REGISTERS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#define TXQUEUE_REG_CONTROL 0x00 -#define TXQUEUE_REG_STATUS 0x04 -#define TXQUEUE_REG_SW_POINTER 0x08 -#define TXQUEUE_REG_HW_POINTER 0x0C -#define TXQUEUE_REG_BUFFER_SIZE 0x10 -#define TXQUEUE_REG_TIMEOUT 0x18 -#define TXQUEUE_REG_MAX_REQUEST 0x1C -#define TXQUEUE_REG_DESC_BASE 0x20 -#define TXQUEUE_REG_POINTER_BASE 0x28 - -#define TXQUEUE_REG_CNT_SENT 0x30 - -#define DMA_CTRL_NDP_TX_REG_SENT 0x60 - #define COMP_NETCOPE_TXQUEUE_SZE "netcope,dma_ctrl_sze_tx" #define COMP_NETCOPE_TXQUEUE_NDP "netcope,dma_ctrl_ndp_tx" @@ -118,9 +104,9 @@ static inline void nc_txqueue_close(struct nc_txqueue *txqueue) static inline void nc_txqueue_reset_counters(struct nc_txqueue *txqueue) { if (txqueue->type == QUEUE_TYPE_NDP) { - nfb_comp_write32(nfb_user_to_comp(txqueue), DMA_CTRL_NDP_TX_REG_SENT, 0); + nfb_comp_write32(nfb_user_to_comp(txqueue), NDP_CTRL_REG_CNTR_SENT, CNTR_CMD_RST); } else { - nfb_comp_write32(nfb_user_to_comp(txqueue), TXQUEUE_REG_CNT_SENT, 1); + nfb_comp_write32(nfb_user_to_comp(txqueue), SZE_CTRL_REG_CNTR_SENT, CNTR_CMD_STRB); } } @@ -129,21 +115,21 @@ static inline void _nc_txqueue_read_counters(struct nc_txqueue *txqueue, struct struct nfb_comp *comp = nfb_user_to_comp(txqueue); if (txqueue->type == QUEUE_TYPE_NDP) { - nfb_comp_write32(nfb_user_to_comp(txqueue), DMA_CTRL_NDP_TX_REG_SENT, cmd); - c->sent = nfb_comp_read64(comp, DMA_CTRL_NDP_TX_REG_SENT); - c->sent_bytes = nfb_comp_read64(comp, DMA_CTRL_NDP_TX_REG_SENT+8); - c->have_bytes = 1; + nfb_comp_write32(nfb_user_to_comp(txqueue), NDP_CTRL_REG_CNTR_SENT, cmd); + c->sent = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_SENT); + c->sent_bytes = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_SENT+8); + c->have_bytes = 1; } else { - c->sent = nfb_comp_read64(comp, TXQUEUE_REG_CNT_SENT); - c->sent_bytes = 0; - c->have_bytes = 0; + c->sent = nfb_comp_read64(comp, SZE_CTRL_REG_CNTR_SENT); + c->sent_bytes = 0; + c->have_bytes = 0; } } static inline int nc_txqueue_read_and_reset_counters(struct nc_txqueue *queue, struct nc_txqueue_counters *c) { if (queue->type == QUEUE_TYPE_NDP) { - _nc_txqueue_read_counters(queue, c, DMA_CTRL_NDP_CNTR_CMD_STRB_RST); + _nc_txqueue_read_counters(queue, c, CNTR_CMD_STRB_RST); } else { return -ENXIO; } @@ -152,7 +138,7 @@ static inline int nc_txqueue_read_and_reset_counters(struct nc_txqueue *queue, s static inline void nc_txqueue_read_counters(struct nc_txqueue *queue, struct nc_txqueue_counters *c) { - _nc_txqueue_read_counters(queue, c, DMA_CTRL_NDP_CNTR_CMD_STRB); + _nc_txqueue_read_counters(queue, c, CNTR_CMD_STRB); } static inline int nc_txqueue_read_status(struct nc_txqueue *txqueue, struct nc_txqueue_status *s) @@ -160,37 +146,36 @@ static inline int nc_txqueue_read_status(struct nc_txqueue *txqueue, struct nc_t struct nfb_comp *comp = nfb_user_to_comp(txqueue); memset(s, 0, sizeof(*s)); - if (txqueue->type == QUEUE_TYPE_NDP) { - s->_ctrl_raw = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_CONTROL); - s->_stat_raw = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_STATUS); - s->sw_pointer = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_SDP); - s->hw_pointer = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_HDP); - s->pointer_mask = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_MDP); - s->sd_pointer = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_SDP); - s->hd_pointer = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_HDP); - s->desc_pointer_mask = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_MDP); - s->timeout = nfb_comp_read32(comp, DMA_CTRL_NDP_REG_TIMEOUT); - s->max_request = 0; - s->desc_base = nfb_comp_read64(comp, DMA_CTRL_NDP_REG_DESC_BASE); - s->pointer_base = nfb_comp_read64(comp, DMA_CTRL_NDP_REG_UPDATE_BASE); + if (txqueue->type == QUEUE_TYPE_SZE) { + s->_ctrl_raw = nfb_comp_read32(comp, SZE_CTRL_REG_CONTROL); + s->_stat_raw = nfb_comp_read32(comp, SZE_CTRL_REG_STATUS); + s->sw_pointer = nfb_comp_read32(comp, SZE_CTRL_REG_SW_POINTER); + s->hw_pointer = nfb_comp_read32(comp, SZE_CTRL_REG_HW_POINTER); + s->pointer_mask = nfb_comp_read32(comp, SZE_CTRL_REG_BUFFER_SIZE); + s->timeout = nfb_comp_read32(comp, SZE_CTRL_REG_TIMEOUT); + s->max_request = nfb_comp_read16(comp, SZE_CTRL_REG_MAX_REQUEST); + s->desc_base = nfb_comp_read64(comp, SZE_CTRL_REG_DESC_BASE); + s->pointer_base = nfb_comp_read64(comp, SZE_CTRL_REG_UPDATE_BASE); + s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; s->stat_running = (s->_stat_raw & 1) ? 1 : 0; - s->have_dp = 1; - } else { - s->_ctrl_raw = nfb_comp_read32(comp, TXQUEUE_REG_CONTROL); - s->_stat_raw = nfb_comp_read32(comp, TXQUEUE_REG_STATUS); - s->sw_pointer = nfb_comp_read32(comp, TXQUEUE_REG_SW_POINTER); - s->hw_pointer = nfb_comp_read32(comp, TXQUEUE_REG_HW_POINTER); - s->pointer_mask = nfb_comp_read32(comp, TXQUEUE_REG_BUFFER_SIZE); - s->timeout = nfb_comp_read32(comp, TXQUEUE_REG_TIMEOUT); - s->max_request = nfb_comp_read16(comp, TXQUEUE_REG_MAX_REQUEST); - s->desc_base = nfb_comp_read64(comp, TXQUEUE_REG_DESC_BASE); - s->pointer_base = nfb_comp_read64(comp, TXQUEUE_REG_POINTER_BASE); + } else if (txqueue->type == QUEUE_TYPE_NDP) { + s->_ctrl_raw = nfb_comp_read32(comp, NDP_CTRL_REG_CONTROL); + s->_stat_raw = nfb_comp_read32(comp, NDP_CTRL_REG_STATUS); + s->sw_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SDP); + s->hw_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HDP); + s->pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MDP); + s->sd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SDP); + s->hd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HDP); + s->desc_pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MDP); + s->timeout = nfb_comp_read32(comp, NDP_CTRL_REG_TIMEOUT); + s->max_request = 0; + s->desc_base = nfb_comp_read64(comp, NDP_CTRL_REG_DESC_BASE); + s->pointer_base = nfb_comp_read64(comp, NDP_CTRL_REG_UPDATE_BASE); s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; s->stat_running = (s->_stat_raw & 1) ? 1 : 0; } - return 0; } From 89e3add36432867dfc2924f5a1270df4e97e3840 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Fri, 13 Oct 2023 11:47:48 +0200 Subject: [PATCH 013/518] dma.c [FEATURE]: add support for DMA CAlypte The DMA has a same set of registers as Medusa and the TX direction contains additional counters of discarded packets. --- libnfb/include/netcope/queue.h | 3 +- libnfb/include/netcope/rxqueue.h | 60 ++++++++++++++---- libnfb/include/netcope/txqueue.h | 74 ++++++++++++++++++---- tools/dma/dma.c | 101 +++++++++++++++++++++---------- 4 files changed, 184 insertions(+), 54 deletions(-) diff --git a/libnfb/include/netcope/queue.h b/libnfb/include/netcope/queue.h index 6e9cf444..0c73c331 100644 --- a/libnfb/include/netcope/queue.h +++ b/libnfb/include/netcope/queue.h @@ -21,7 +21,8 @@ extern "C" { enum queue_type { QUEUE_TYPE_UNDEF = -1, QUEUE_TYPE_SZE = 0, - QUEUE_TYPE_NDP + QUEUE_TYPE_NDP = 1, + QUEUE_TYPE_CALYPTE }; // -------------- Counter control commands -------------------- diff --git a/libnfb/include/netcope/rxqueue.h b/libnfb/include/netcope/rxqueue.h index f5d5644c..5334adcf 100644 --- a/libnfb/include/netcope/rxqueue.h +++ b/libnfb/include/netcope/rxqueue.h @@ -20,6 +20,7 @@ extern "C" { /* ~~~~[ DATA TYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ struct nc_rxqueue { enum queue_type type; + const char *name; }; struct nc_rxqueue_status { @@ -36,6 +37,7 @@ struct nc_rxqueue_status { unsigned long long desc_base; unsigned long long pointer_base; + unsigned long long hdr_base; unsigned ctrl_running : 1; unsigned ctrl_discard : 1; @@ -44,7 +46,6 @@ struct nc_rxqueue_status { unsigned stat_desc_rdy : 1; unsigned stat_data_rdy : 1; unsigned stat_ring_rdy : 1; - unsigned have_dp : 1; }; struct nc_rxqueue_counters { @@ -65,8 +66,9 @@ static inline void nc_rxqueue_read_counters(struct nc_rxqueue *rxq static inline void nc_rxqueue_read_status(struct nc_rxqueue *rxqueue, struct nc_rxqueue_status *status); /* ~~~~[ MACROS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#define COMP_NETCOPE_RXQUEUE_SZE "netcope,dma_ctrl_sze_rx" -#define COMP_NETCOPE_RXQUEUE_NDP "netcope,dma_ctrl_ndp_rx" +#define COMP_NETCOPE_RXQUEUE_SZE "netcope,dma_ctrl_sze_rx" +#define COMP_NETCOPE_RXQUEUE_NDP "netcope,dma_ctrl_ndp_rx" +#define COMP_NETCOPE_RXQUEUE_CALYPTE "cesnet,dma_ctrl_calypte_rx" #define RXQUEUE_COMP_LOCK (1 << 0) @@ -77,7 +79,8 @@ static inline struct nc_rxqueue *nc_rxqueue_open(struct nfb_device *dev, int fdt struct nfb_comp *comp; if (fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_RXQUEUE_SZE) && - fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_RXQUEUE_NDP)) + fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_RXQUEUE_NDP) && + fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_RXQUEUE_CALYPTE)) return NULL; comp = nfb_comp_open_ext(dev, fdt_offset, sizeof(struct nc_rxqueue)); @@ -85,7 +88,20 @@ static inline struct nc_rxqueue *nc_rxqueue_open(struct nfb_device *dev, int fdt return NULL; rxqueue = (struct nc_rxqueue *) nfb_comp_to_user(comp); - rxqueue->type = fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_RXQUEUE_SZE) ? QUEUE_TYPE_NDP : QUEUE_TYPE_SZE; + if (!fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_RXQUEUE_SZE)) { + rxqueue->type = QUEUE_TYPE_SZE; + rxqueue->name = "SZE"; + } else if (!fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_RXQUEUE_NDP)) { + rxqueue->type = QUEUE_TYPE_NDP; + rxqueue->name = "NDP"; + } else if (!fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_RXQUEUE_CALYPTE)) { + rxqueue->type = QUEUE_TYPE_CALYPTE; + rxqueue->name = "CALYPTE"; + } else { + rxqueue->type = QUEUE_TYPE_UNDEF; + rxqueue->name = "UNDEFINED"; + } + return rxqueue; } @@ -93,13 +109,19 @@ static inline struct nc_rxqueue *nc_rxqueue_open_index(struct nfb_device *dev, u enum queue_type type) { int fdt_offset; + if (type == QUEUE_TYPE_UNDEF) { - if (nfb_comp_count(dev, COMP_NETCOPE_RXQUEUE_SZE) > 0) + if (nfb_comp_count(dev, COMP_NETCOPE_RXQUEUE_SZE) > 0) { type = QUEUE_TYPE_SZE; - else + fdt_offset = nfb_comp_find(dev, COMP_NETCOPE_RXQUEUE_SZE, index); + } else if (nfb_comp_count(dev, COMP_NETCOPE_RXQUEUE_CALYPTE) > 0) { + type = QUEUE_TYPE_CALYPTE; + fdt_offset = nfb_comp_find(dev, COMP_NETCOPE_RXQUEUE_CALYPTE, index); + } else { type = QUEUE_TYPE_NDP; + fdt_offset = nfb_comp_find(dev, COMP_NETCOPE_RXQUEUE_NDP, index); + } } - fdt_offset = nfb_comp_find(dev, (type == QUEUE_TYPE_SZE) ? COMP_NETCOPE_RXQUEUE_SZE : COMP_NETCOPE_RXQUEUE_NDP, index); return nc_rxqueue_open(dev, fdt_offset); } @@ -110,7 +132,7 @@ static inline void nc_rxqueue_close(struct nc_rxqueue *rxqueue) static inline void nc_rxqueue_reset_counters(struct nc_rxqueue *rxqueue) { - if (rxqueue->type == QUEUE_TYPE_NDP) { + if (rxqueue->type == QUEUE_TYPE_NDP || rxqueue->type == QUEUE_TYPE_CALYPTE) { nfb_comp_write32(nfb_user_to_comp(rxqueue), NDP_CTRL_REG_CNTR_RECV, CNTR_CMD_RST); } else { nfb_comp_write32(nfb_user_to_comp(rxqueue), SZE_CTRL_REG_CNTR_RECV, CNTR_CMD_STRB); @@ -120,7 +142,7 @@ static inline void nc_rxqueue_reset_counters(struct nc_rxqueue *rxqueue) static inline void _nc_rxqueue_read_counters(struct nc_rxqueue *rxqueue, struct nc_rxqueue_counters *c, int cmd) { struct nfb_comp *comp = nfb_user_to_comp(rxqueue); - if (rxqueue->type == QUEUE_TYPE_NDP) { + if (rxqueue->type == QUEUE_TYPE_NDP || rxqueue->type == QUEUE_TYPE_CALYPTE) { nfb_comp_write32(nfb_user_to_comp(rxqueue), NDP_CTRL_REG_CNTR_RECV, cmd); c->received = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_RECV); c->received_bytes = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_RECV+8); @@ -138,7 +160,7 @@ static inline void _nc_rxqueue_read_counters(struct nc_rxqueue *rxqueue, struct static inline int nc_rxqueue_read_and_reset_counters(struct nc_rxqueue *queue, struct nc_rxqueue_counters *c) { - if (queue->type == QUEUE_TYPE_NDP) { + if (queue->type == QUEUE_TYPE_NDP || queue->type == QUEUE_TYPE_CALYPTE) { _nc_rxqueue_read_counters(queue, c, CNTR_CMD_STRB_RST); } else { return -ENXIO; @@ -171,6 +193,22 @@ static inline void nc_rxqueue_read_status(struct nc_rxqueue *rxqueue, struct nc_ s->pointer_base = nfb_comp_read64(comp, NDP_CTRL_REG_UPDATE_BASE); s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; s->stat_running = (s->_stat_raw & 1) ? 1 : 0; + } else if (rxqueue->type == QUEUE_TYPE_CALYPTE) { + s->_ctrl_raw = nfb_comp_read32(comp, NDP_CTRL_REG_CONTROL); + s->_stat_raw = nfb_comp_read32(comp, NDP_CTRL_REG_STATUS); + s->sw_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SHP); + s->hw_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HHP); + s->pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MHP); + s->sd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SDP); + s->hd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HDP); + s->desc_pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MDP); + s->timeout = 0; + s->max_request = 0; + s->desc_base = nfb_comp_read64(comp, NDP_CTRL_REG_DESC_BASE); + s->hdr_base = nfb_comp_read64(comp, NDP_CTRL_REG_HDR_BASE); + s->pointer_base = 0; + s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; + s->stat_running = (s->_stat_raw & 1) ? 1 : 0; } else { s->_ctrl_raw = nfb_comp_read32(comp, SZE_CTRL_REG_CONTROL); s->_stat_raw = nfb_comp_read32(comp, SZE_CTRL_REG_STATUS); diff --git a/libnfb/include/netcope/txqueue.h b/libnfb/include/netcope/txqueue.h index 4072bf75..6913d0f3 100644 --- a/libnfb/include/netcope/txqueue.h +++ b/libnfb/include/netcope/txqueue.h @@ -20,6 +20,7 @@ extern "C" { /* ~~~~[ DATA TYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ struct nc_txqueue { enum queue_type type; + const char *name; }; struct nc_txqueue_status { @@ -39,13 +40,16 @@ struct nc_txqueue_status { unsigned ctrl_running : 1; unsigned stat_running : 1; - unsigned have_dp : 1; }; struct nc_txqueue_counters { unsigned long long sent; unsigned long long sent_bytes; + unsigned long long discarded; + unsigned long long discarded_bytes; + unsigned have_bytes : 1; + unsigned have_tx_discard : 1; }; /* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -58,8 +62,9 @@ static inline int nc_txqueue_read_status(struct nc_txqueue *txque /* ~~~~[ MACROS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#define COMP_NETCOPE_TXQUEUE_SZE "netcope,dma_ctrl_sze_tx" -#define COMP_NETCOPE_TXQUEUE_NDP "netcope,dma_ctrl_ndp_tx" +#define COMP_NETCOPE_TXQUEUE_SZE "netcope,dma_ctrl_sze_tx" +#define COMP_NETCOPE_TXQUEUE_NDP "netcope,dma_ctrl_ndp_tx" +#define COMP_NETCOPE_TXQUEUE_CALYPTE "cesnet,dma_ctrl_calypte_tx" #define TXQUEUE_COMP_LOCK (1 << 0) @@ -70,7 +75,8 @@ static inline struct nc_txqueue *nc_txqueue_open(struct nfb_device *dev, int fdt struct nfb_comp *comp; if (fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_TXQUEUE_SZE) && - fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_TXQUEUE_NDP)) + fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_TXQUEUE_NDP) && + fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_TXQUEUE_CALYPTE)) return NULL; comp = nfb_comp_open_ext(dev, fdt_offset, sizeof(struct nc_txqueue)); @@ -78,21 +84,41 @@ static inline struct nc_txqueue *nc_txqueue_open(struct nfb_device *dev, int fdt return NULL; txqueue = (struct nc_txqueue *) nfb_comp_to_user(comp); - txqueue->type = fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_TXQUEUE_SZE) ? QUEUE_TYPE_NDP : QUEUE_TYPE_SZE; + if (!fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_TXQUEUE_SZE)) { + txqueue->type = QUEUE_TYPE_SZE; + txqueue->name = "SZE"; + } else if (!fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_TXQUEUE_NDP)) { + txqueue->type = QUEUE_TYPE_NDP; + txqueue->name = "NDP"; + } else if (!fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_TXQUEUE_CALYPTE)) { + txqueue->type = QUEUE_TYPE_CALYPTE; + txqueue->name = "CALYPTE"; + } else { + txqueue->type = QUEUE_TYPE_UNDEF; + txqueue->name = "UNDEFINED"; + } + return txqueue; } static inline struct nc_txqueue *nc_txqueue_open_index(struct nfb_device *dev, unsigned index, enum queue_type type) { - int fdt_offset; + int fdt_offset = -1; + if (type == QUEUE_TYPE_UNDEF) { - if (nfb_comp_count(dev, COMP_NETCOPE_TXQUEUE_SZE) > 0) + if (nfb_comp_count(dev, COMP_NETCOPE_TXQUEUE_SZE) > 0) { type = QUEUE_TYPE_SZE; - else + fdt_offset = nfb_comp_find(dev, COMP_NETCOPE_TXQUEUE_SZE, index); + } else if (nfb_comp_count(dev, COMP_NETCOPE_TXQUEUE_CALYPTE) > 0) { + type = QUEUE_TYPE_CALYPTE; + fdt_offset = nfb_comp_find(dev, COMP_NETCOPE_TXQUEUE_CALYPTE, index); + } else { type = QUEUE_TYPE_NDP; + fdt_offset = nfb_comp_find(dev, COMP_NETCOPE_TXQUEUE_NDP, index); + } } - fdt_offset = nfb_comp_find(dev, (type == QUEUE_TYPE_SZE) ? COMP_NETCOPE_TXQUEUE_SZE : COMP_NETCOPE_TXQUEUE_NDP, index); + return nc_txqueue_open(dev, fdt_offset); } @@ -103,7 +129,7 @@ static inline void nc_txqueue_close(struct nc_txqueue *txqueue) static inline void nc_txqueue_reset_counters(struct nc_txqueue *txqueue) { - if (txqueue->type == QUEUE_TYPE_NDP) { + if (txqueue->type == QUEUE_TYPE_NDP || txqueue->type == QUEUE_TYPE_CALYPTE) { nfb_comp_write32(nfb_user_to_comp(txqueue), NDP_CTRL_REG_CNTR_SENT, CNTR_CMD_RST); } else { nfb_comp_write32(nfb_user_to_comp(txqueue), SZE_CTRL_REG_CNTR_SENT, CNTR_CMD_STRB); @@ -118,17 +144,31 @@ static inline void _nc_txqueue_read_counters(struct nc_txqueue *txqueue, struct nfb_comp_write32(nfb_user_to_comp(txqueue), NDP_CTRL_REG_CNTR_SENT, cmd); c->sent = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_SENT); c->sent_bytes = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_SENT+8); + c->discarded = 0; + c->discarded_bytes = 0; c->have_bytes = 1; + c->have_tx_discard = 0; + } else if (txqueue->type == QUEUE_TYPE_CALYPTE) { + nfb_comp_write32(nfb_user_to_comp(txqueue), NDP_CTRL_REG_CNTR_SENT, cmd); + c->sent = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_SENT); + c->sent_bytes = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_SENT+8); + c->discarded = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_DISC); + c->discarded_bytes = nfb_comp_read64(comp, NDP_CTRL_REG_CNTR_DISC+8); + c->have_bytes = 1; + c->have_tx_discard = 1; } else { c->sent = nfb_comp_read64(comp, SZE_CTRL_REG_CNTR_SENT); c->sent_bytes = 0; + c->discarded = 0; + c->discarded_bytes = 0; c->have_bytes = 0; + c->have_tx_discard = 0; } } static inline int nc_txqueue_read_and_reset_counters(struct nc_txqueue *queue, struct nc_txqueue_counters *c) { - if (queue->type == QUEUE_TYPE_NDP) { + if (queue->type == QUEUE_TYPE_NDP || queue->type == QUEUE_TYPE_CALYPTE) { _nc_txqueue_read_counters(queue, c, CNTR_CMD_STRB_RST); } else { return -ENXIO; @@ -175,6 +215,18 @@ static inline int nc_txqueue_read_status(struct nc_txqueue *txqueue, struct nc_t s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; s->stat_running = (s->_stat_raw & 1) ? 1 : 0; + } else if (txqueue->type == QUEUE_TYPE_CALYPTE) { + s->_ctrl_raw = nfb_comp_read32(comp, NDP_CTRL_REG_CONTROL); + s->_stat_raw = nfb_comp_read32(comp, NDP_CTRL_REG_STATUS); + s->sw_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SHP); + s->hw_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HHP); + s->pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MHP); + s->sd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SDP); + s->hd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HDP); + s->desc_pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MDP); + + s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; + s->stat_running = (s->_stat_raw & 1) ? 1 : 0; } return 0; } diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 8dc5f558..38cda491 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -27,9 +27,13 @@ /*! Acceptable command line arguments */ /*! -d path to device file */ -/*! -i RX or TX index; -r use only RX; -t use only TX; */ +/*! -i RX or TX index */ +/*! -r use only RX; */ +/*! -t use only TX; */ /*! -R reset counters */ -/*! -h print help; -v verbose mode; -V version */ +/*! -h print help; */ +/*! -v verbose mode; */ +/*! -V version */ #define ARGUMENTS "d:i:q:rtRS:vh" @@ -45,10 +49,12 @@ enum commands { const char *rx_ctrl_name[] = { COMP_NETCOPE_RXQUEUE_SZE, COMP_NETCOPE_RXQUEUE_NDP, + COMP_NETCOPE_RXQUEUE_CALYPTE, }; const char *tx_ctrl_name[] = { COMP_NETCOPE_TXQUEUE_SZE, COMP_NETCOPE_TXQUEUE_NDP, + COMP_NETCOPE_TXQUEUE_CALYPTE, }; // this enum need to corespond with queries[] array @@ -59,6 +65,8 @@ enum queries { RX_DISCARDED_BYTES, TX_SENT, TX_SENT_BYTES, + TX_DISCARDED, + TX_DISCARDED_BYTES }; static const char * const queries[] = { "rx_received", @@ -66,7 +74,9 @@ static const char * const queries[] = { "rx_discarded", "rx_discarded_bytes", "tx_sent", - "tx_sent_bytes" + "tx_sent_bytes", + "tx_discarded", + "tx_discarded_bytes" }; /*! @@ -135,7 +145,7 @@ int query_print(struct nfb_device *dev, struct list_range index_range, char *queries, int size) { struct nc_rxqueue *rxq; - struct nc_txqueue *txq; + struct nc_txqueue *txq = NULL; struct nc_rxqueue_counters cr = {0, }; struct nc_txqueue_counters ct = {0, }; int rx_size = ndp_get_rx_queue_count(dev); @@ -172,6 +182,8 @@ int query_print(struct nfb_device *dev, struct list_range index_range, } break; case TX_SENT: case TX_SENT_BYTES: + case TX_DISCARDED: + case TX_DISCARDED_BYTES: if (txc_valid) break; @@ -210,6 +222,14 @@ int query_print(struct nfb_device *dev, struct list_range index_range, if (!ct.have_bytes) warnx("queue doesn't have byte counter"); printf("%llu\n", ct.sent_bytes); break; + case TX_DISCARDED: + if (!ct.have_tx_discard) + warnx("queue doesn't have TX discard counter"); + printf("%llu\n", ct.discarded); break; + case TX_DISCARDED_BYTES: + if (!ct.have_tx_discard) + warnx("queue doesn't have TX discard counter"); + printf("%llu\n", ct.discarded_bytes); break; default: break; } } @@ -223,20 +243,18 @@ int query_print(struct nfb_device *dev, struct list_range index_range, * * \param *tx_dma structure from which are data read */ -void rxqueue_print_status(struct nc_rxqueue *q, const char *compatible, int index, int verbose, enum commands cmd) +void rxqueue_print_status(struct nc_rxqueue *q, int index, int verbose, enum commands cmd) { - int packet = strstr(compatible, "_pac_") ? 1 : 0; - struct nc_rxqueue_status s; struct nc_rxqueue_counters c; + printf("------------------------------ RX%02d %s controller ----\n", index, q->name); - printf("------------------------------ RX%02d %s controller ----\n", index, packet ? "PAC" : "NDP"); if (verbose > 0) { nc_rxqueue_read_status(q, &s); printf("Control reg : 0x%.8X", s._ctrl_raw); - if (q->type == QUEUE_TYPE_NDP) { + if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { printf(" | %s |", s.ctrl_running ? "Run " : "Stop "); } else if (q->type == QUEUE_TYPE_SZE) { @@ -249,7 +267,7 @@ void rxqueue_print_status(struct nc_rxqueue *q, const char *compatible, int inde printf("\n"); printf("Status reg : 0x%.8X", s._stat_raw); - if (q->type == QUEUE_TYPE_NDP) { + if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { printf(" | %s |", s.stat_running ? "Running " : "Stopped "); } else if (q->type == QUEUE_TYPE_SZE) { @@ -261,7 +279,7 @@ void rxqueue_print_status(struct nc_rxqueue *q, const char *compatible, int inde } printf("\n"); - if (s.have_dp) { + if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { printf("SW header pointer : 0x%08lX\n", s.sw_pointer); printf("HW header pointer : 0x%08lX\n", s.hw_pointer); printf("Header pointer mask : 0x%08lX\n", s.pointer_mask); @@ -280,11 +298,13 @@ void rxqueue_print_status(struct nc_rxqueue *q, const char *compatible, int inde printf("* Buffer size : "); print_size(s.pointer_mask ? s.pointer_mask + 1 : 0); printf("\n"); } - //printf("Interrupt reg: 0x%.8X\n", (reg = nfb_comp_read32(comp, 0x14))); - printf("Timeout reg : 0x%08lX\n", s.timeout); + if (q->type == QUEUE_TYPE_SZE || q->type == QUEUE_TYPE_NDP) + printf("Timeout reg : 0x%08lX\n", s.timeout); - printf("Max request : 0x%04lX | ", s.max_request); - print_size(s.max_request); printf("\n"); + if (q->type == QUEUE_TYPE_SZE) { + printf("Max request : 0x%04lX | ", s.max_request); + print_size(s.max_request); printf("\n"); + } } if (cmd == CMD_COUNTER_READ_AND_RESET) { @@ -296,6 +316,7 @@ void rxqueue_print_status(struct nc_rxqueue *q, const char *compatible, int inde } else { nc_rxqueue_read_counters(q, &c); } + printf("Received : %llu\n", c.received); if (c.have_bytes) printf("Received bytes : %llu\n", c.received_bytes); @@ -305,23 +326,25 @@ void rxqueue_print_status(struct nc_rxqueue *q, const char *compatible, int inde if (verbose > 1) { printf("Desc base : 0x%.16llX\n", s.desc_base); - printf("Pointer base : 0x%.16llX\n", s.pointer_base); + if (q->type == QUEUE_TYPE_CALYPTE) + printf("Header base : 0x%.16llX\n", s.hdr_base); + else + printf("Pointer base : 0x%.16llX\n", s.pointer_base); } } -void txqueue_print_status(struct nc_txqueue *q, const char *compatible, int index, int verbose, enum commands cmd) +void txqueue_print_status(struct nc_txqueue *q, int index, int verbose, enum commands cmd) { - int packet = strstr(compatible, "_pac_") ? 1 : 0; - struct nc_txqueue_status s; struct nc_txqueue_counters c; - printf("------------------------------ TX%02d %s controller ----\n", index, packet ? "PAC" : "NDP"); + printf("------------------------------ TX%02d %s controller ----\n", index, q->name); + if (verbose > 0) { nc_txqueue_read_status(q, &s); printf("Control reg : 0x%.8X", s._ctrl_raw); - if (q->type == QUEUE_TYPE_NDP) { + if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { printf(" | %s |", s.ctrl_running ? "Run " : "Stop "); } else if (q->type == QUEUE_TYPE_SZE) { @@ -333,7 +356,7 @@ void txqueue_print_status(struct nc_txqueue *q, const char *compatible, int inde printf("\n"); printf("Status reg : 0x%.8X", s._stat_raw); - if (q->type == QUEUE_TYPE_NDP) { + if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { printf(" | %s |", s.stat_running ? "Running " : "Stopped "); } else if (q->type == QUEUE_TYPE_SZE) { @@ -342,7 +365,15 @@ void txqueue_print_status(struct nc_txqueue *q, const char *compatible, int inde } printf("\n"); - if (s.have_dp) { + if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { + if (q->type == QUEUE_TYPE_CALYPTE) { + printf("SW header pointer : 0x%08lX\n", s.sw_pointer); + printf("HW header pointer : 0x%08lX\n", s.hw_pointer); + printf("Header pointer mask : 0x%08lX\n", s.pointer_mask); + printf("* Header buffer size : "); print_size(s.pointer_mask ? s.pointer_mask + 1 : 0); printf("\n"); + printf("* Fillable headers in HW : 0x%08lX\n", (s.sw_pointer - s.hw_pointer - 1) & s.pointer_mask); + } + printf("SW descriptor pointer : 0x%08lX\n", s.sd_pointer); printf("HW descriptor pointer : 0x%08lX\n", s.hd_pointer); printf("Descriptor pointer mask : 0x%08lX\n", s.desc_pointer_mask); @@ -355,11 +386,13 @@ void txqueue_print_status(struct nc_txqueue *q, const char *compatible, int inde printf("* Buffer size : "); print_size(s.pointer_mask ? s.pointer_mask + 1 : 0); printf("\n"); } - //printf("Interrupt reg: 0x%.8X\n", (reg = nfb_comp_read32(comp, 0x14))); - printf("Timeout reg : 0x%08lX\n", s.timeout); + if (q->type == QUEUE_TYPE_SZE || q->type == QUEUE_TYPE_NDP) + printf("Timeout reg : 0x%08lX\n", s.timeout); - printf("Max request : 0x%04lX | ", s.max_request); - print_size(s.max_request); printf("\n"); + if (q->type == QUEUE_TYPE_SZE) { + printf("Max request : 0x%04lX | ", s.max_request); + print_size(s.max_request); printf("\n"); + } } if (cmd == CMD_COUNTER_READ_AND_RESET) { @@ -376,11 +409,15 @@ void txqueue_print_status(struct nc_txqueue *q, const char *compatible, int inde if (c.have_bytes) printf("Sent bytes : %llu\n", c.sent_bytes); - if (verbose > 1) { + if (c.have_tx_discard) { + printf("Discarded : %llu\n", c.discarded); + printf("Discarded bytes : %llu\n", c.discarded_bytes); + } + + if (verbose > 1 && q->type != QUEUE_TYPE_CALYPTE) { printf("Desc base : 0x%.16llX\n", s.desc_base); printf("Pointer base : 0x%.16llX\n", s.pointer_base); } - } /*! @@ -506,7 +543,7 @@ int main(int argc, char *argv[]) break; case CMD_COUNTER_READ_AND_RESET: case CMD_PRINT_STATUS: - rxqueue_print_status(rxq, rx_ctrl_name[ctrl], i, verbose, cmd); + rxqueue_print_status(rxq, i, verbose, cmd); printf("\n"); break; case CMD_SET_RING_SIZE: @@ -538,10 +575,12 @@ int main(int argc, char *argv[]) break; case CMD_COUNTER_READ_AND_RESET: case CMD_PRINT_STATUS: - txqueue_print_status(txq, tx_ctrl_name[ctrl], i, verbose, cmd); + txqueue_print_status(txq, i, verbose, cmd); printf("\n"); break; case CMD_SET_RING_SIZE: + if (txq->type == QUEUE_TYPE_CALYPTE) + err(errno, "TX Calypte controller does not support setting of ring buffer size."); set_ring_size(dev, 1, i, csize); break; default: From 04e05bf333ebf718f5bd978d37e836786fd2e819 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Wed, 20 Sep 2023 13:29:15 +0200 Subject: [PATCH 014/518] ndp_tx.h [STYLE]: reorganize functions for better readability --- libnfb/include/netcope/ndp_tx.h | 103 ++++++++++++++++---------------- 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index 9acb00e1..9a1ca416 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -143,6 +143,27 @@ static inline unsigned nc_ndp_v1_tx_burst_get(void *priv, struct ndp_packet *pac return cnt; } +static inline int nc_ndp_v1_tx_burst_put(void *priv) +{ + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + /* Publish written data if their size is bigger than quarter of buffer size */ + if (q->u.v1.swptr > q->size / 4) { + q->sync.hwptr = (q->sync.hwptr + q->u.v1.swptr) & (q->size-1); + nc_ndp_v1_tx_unlock(q); + } + return 0; +} + +static inline int nc_ndp_v1_tx_burst_flush(void *priv) +{ + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + q->sync.hwptr = (q->sync.hwptr + q->u.v1.swptr) & (q->size-1); + nc_ndp_v1_tx_unlock(q); + return 0; +} + static inline void nc_ndp_v2_tx_lock(void *priv) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; @@ -165,25 +186,6 @@ static inline void nc_ndp_v2_tx_lock(void *priv) q->u.v2.pkts_available = (q->sync.swptr - q->u.v2.rhp) & (q->u.v2.hdr_items-1); } -static inline int nc_ndp_v2_tx_burst_flush(void *priv) -{ - struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - - if (q->u.v2.rhp >= q->u.v2.hdr_items) { - q->u.v2.rhp -= q->u.v2.hdr_items; - q->u.v2.hdr -= q->u.v2.hdr_items; - q->u.v2.off -= q->u.v2.hdr_items; - } - q->sync.hwptr = q->u.v2.rhp; - q->sync.swptr = q->u.v2.rhp; - q->u.v2.pkts_available = 0; - - if (_ndp_queue_sync(q, &q->sync)) { - return -1; - } - return 0; -} - static inline unsigned nc_ndp_v2_tx_burst_get(void *priv, struct ndp_packet *packets, unsigned count) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; @@ -248,10 +250,36 @@ static inline unsigned nc_ndp_v2_tx_burst_get(void *priv, struct ndp_packet *pac return count; } -static inline int nc_ndp_v1_tx_burst_put(void *priv); -static inline int nc_ndp_v1_tx_burst_flush(void *priv); +static inline int nc_ndp_v2_tx_burst_flush(void *priv); + +static inline int nc_ndp_v2_tx_burst_put(void *priv) +{ + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; -static inline int nc_ndp_v2_tx_burst_put(void *priv); + if (((q->u.v2.rhp - q->sync.hwptr) & (q->u.v2.hdr_items-1)) > q->u.v2.hdr_items / 4) { + nc_ndp_v2_tx_burst_flush(priv); + } + return 0; +} + +static inline int nc_ndp_v2_tx_burst_flush(void *priv) +{ + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + if (q->u.v2.rhp >= q->u.v2.hdr_items) { + q->u.v2.rhp -= q->u.v2.hdr_items; + q->u.v2.hdr -= q->u.v2.hdr_items; + q->u.v2.off -= q->u.v2.hdr_items; + } + q->sync.hwptr = q->u.v2.rhp; + q->sync.swptr = q->u.v2.rhp; + q->u.v2.pkts_available = 0; + + if (_ndp_queue_sync(q, &q->sync)) { + return -1; + } + return 0; +} static inline unsigned nc_ndp_tx_burst_get(void *priv, struct ndp_packet *packets, unsigned count) { @@ -286,34 +314,3 @@ static inline void nc_ndp_tx_burst_flush(void *priv) nc_ndp_v1_tx_burst_flush(priv); } } - -static inline int nc_ndp_v1_tx_burst_put(void *priv) -{ - struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - - /* Publish written data if their size is bigger than quarter of buffer size */ - if (q->u.v1.swptr > q->size / 4) { - q->sync.hwptr = (q->sync.hwptr + q->u.v1.swptr) & (q->size-1); - nc_ndp_v1_tx_unlock(q); - } - return 0; -} - -static inline int nc_ndp_v2_tx_burst_put(void *priv) -{ - struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - - if (((q->u.v2.rhp - q->sync.hwptr) & (q->u.v2.hdr_items-1)) > q->u.v2.hdr_items / 4) { - nc_ndp_v2_tx_burst_flush(priv); - } - return 0; -} - -static inline int nc_ndp_v1_tx_burst_flush(void *priv) -{ - struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - - q->sync.hwptr = (q->sync.hwptr + q->u.v1.swptr) & (q->size-1); - nc_ndp_v1_tx_unlock(q); - return 0; -} From 4a0a4c454aaa2fd3c6c87dad5c2fe4361eeae313 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 3 Jul 2023 16:54:13 +0200 Subject: [PATCH 015/518] ndp_core_queue [MAINTENANCE]: rename type atribute to dir This is because the "type" keywords' meaning is too general for the description. This keyword could store both the direction (TX vs. RX) and type of DMA Controller (SZE vs. Medusa vs. Calypte), but was used only for the first one. That's why this renaming took place. --- libnfb/include/netcope/ndp.h | 12 ++++++------ libnfb/include/netcope/ndp_core.h | 12 ++++++------ libnfb/include/netcope/ndp_core_queue.h | 3 ++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 0411bf70..651d203c 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -26,9 +26,9 @@ static int nc_ndp_queue_stop(void *priv); #include "ndp_rx.h" #include "ndp_tx.h" -static inline int nc_nfb_fdt_queue_offset(const void *fdt, unsigned index, int type) +static inline int nc_nfb_fdt_queue_offset(const void *fdt, unsigned index, int dir) { - const char * dir_str = type ? "tx" : "rx"; + const char * dir_str = dir ? "tx" : "rx"; char path[64]; index &= 0x0FFFFFFF; @@ -141,7 +141,7 @@ static inline int nc_ndp_v2_open_queue(struct nc_ndp_queue *q, const void *fdt, return ret; } -static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queue *q, unsigned index, int type, ndp_open_flags_t ndp_flags) +static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queue *q, unsigned index, int dir, ndp_open_flags_t ndp_flags) { int ret = 0; int fdt_offset; @@ -156,7 +156,7 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu (void) ndp_flags; - fdt_offset = nc_nfb_fdt_queue_offset(fdt, index, type); + fdt_offset = nc_nfb_fdt_queue_offset(fdt, index, dir); /* Fetch controller parameters */ q->frame_size_min = q->frame_size_max = 0; @@ -187,7 +187,7 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu q->flags = flags; q->channel.index = index; - q->channel.type = type; + q->channel.type = dir; q->channel.flags = q->flags; #ifdef __KERNEL__ @@ -209,7 +209,7 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu /* Map the memory of buffer space. Driver ensures that the mmap_size * is 2 times larger than q->size and the buffer space is shadowed. * Due to this feature user normally needs not to check buffer boundary. */ - q->buffer = mmap(NULL, q->size * 2, PROT_READ | (type ? PROT_WRITE : 0), + q->buffer = mmap(NULL, q->size * 2, PROT_READ | (dir ? PROT_WRITE : 0), MAP_FILE | MAP_SHARED, q->fd, mmap_offset); if (q->buffer == MAP_FAILED) { goto err_mmap; diff --git a/libnfb/include/netcope/ndp_core.h b/libnfb/include/netcope/ndp_core.h index 39e1f707..067fa005 100644 --- a/libnfb/include/netcope/ndp_core.h +++ b/libnfb/include/netcope/ndp_core.h @@ -34,12 +34,12 @@ void nfb_nfree(int numa_node, void *ptr, size_t size) #endif } -void _ndp_queue_init(struct ndp_queue *q, struct nfb_device *dev, int numa, int type, int index) +void _ndp_queue_init(struct ndp_queue *q, struct nfb_device *dev, int numa, int dir, int index) { memset(q, 0, sizeof(struct ndp_queue)); q->numa = numa; - q->type = type; + q->dir = dir; q->dev = dev; q->index = index; @@ -50,7 +50,7 @@ void _ndp_queue_init(struct ndp_queue *q, struct nfb_device *dev, int numa, int #endif } -struct ndp_queue * ndp_queue_create(struct nfb_device *dev, int numa, int type, int index) +struct ndp_queue * ndp_queue_create(struct nfb_device *dev, int numa, int dir, int index) { struct ndp_queue *q; @@ -59,7 +59,7 @@ struct ndp_queue * ndp_queue_create(struct nfb_device *dev, int numa, int type, if (q == NULL) { goto err_nalloc; } - _ndp_queue_init(q, dev, numa, type, index); + _ndp_queue_init(q, dev, numa, dir, index); #ifdef __KERNEL__ q->alloc = 1; @@ -149,7 +149,7 @@ struct ndp_queue *ndp_open_queue(struct nfb_device *dev, unsigned index, int dir if (q->ops.control.start == NULL || q->ops.control.stop == NULL || q->ops.burst.tx.get == NULL || q->ops.burst.tx.put == NULL || - (q->ops.burst.tx.flush == NULL && q->type != NDP_CHANNEL_TYPE_RX)) { + (q->ops.burst.tx.flush == NULL && q->dir != NDP_CHANNEL_TYPE_RX)) { ret = -EINVAL; goto err_ops_invalid; } @@ -328,7 +328,7 @@ int ndp_queue_stop(struct ndp_queue *q) if (q->status == NDP_QUEUE_STOPPED) return EALREADY; - if (q->type == NDP_CHANNEL_TYPE_TX) + if (q->dir == NDP_CHANNEL_TYPE_TX) q->ops.burst.tx.flush(q->priv); ret = q->ops.control.stop(q->priv); diff --git a/libnfb/include/netcope/ndp_core_queue.h b/libnfb/include/netcope/ndp_core_queue.h index 023160cf..9eab369e 100644 --- a/libnfb/include/netcope/ndp_core_queue.h +++ b/libnfb/include/netcope/ndp_core_queue.h @@ -25,8 +25,9 @@ struct ndp_queue { struct nfb_device *dev; enum ndp_queue_status status; int numa; - uint16_t type; + uint16_t dir; uint16_t index; + #ifdef __KERNEL__ int alloc; #endif From 3e1ea0389779b59611b1ee193bf216727261bf2a Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 9 Oct 2023 14:52:47 +0200 Subject: [PATCH 016/518] ndp_priv.h [MAINTENANCE]: remove unused attributes ops and priv from nc_ndp_queue --- libnfb/include/netcope/ndp_priv.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index b82c4d57..3b9033b6 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -73,8 +73,6 @@ struct nc_ndp_queue { #ifdef __KERNEL__ struct ndp_subscriber *subscriber; #endif - struct ndp_queue_ops ops; - void *priv; }; #endif From 389eda7df41d10f274d48c0da07f178f9a3dba8c Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Fri, 30 Jun 2023 10:19:54 +0200 Subject: [PATCH 017/518] driver-NDP [FEATURE]: add support for DMA Calypte --- drivers/kernel/drivers/nfb/ndp/channel.c | 5 +- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 434 +++++++++++++++--- drivers/kernel/drivers/nfb/ndp/driver.c | 4 + drivers/kernel/drivers/nfb/ndp/ndp.h | 3 + drivers/kernel/drivers/nfb/ndp/subscription.c | 2 - libnfb/include/netcope/dma_ctrl_ndp.h | 133 +++++- 6 files changed, 500 insertions(+), 81 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/channel.c b/drivers/kernel/drivers/nfb/ndp/channel.c index 7573f817..d0c10f36 100644 --- a/drivers/kernel/drivers/nfb/ndp/channel.c +++ b/drivers/kernel/drivers/nfb/ndp/channel.c @@ -269,6 +269,8 @@ inline void ndp_channel_txsync(struct ndp_subscription *sub, struct ndp_subscrip } channel->hwptr = channel->ops->get_hwptr(channel); + if (channel->ops->get_free_space != NULL) + sync->size = channel->ops->get_free_space(channel); chlen = (channel->hwptr - channel->swptr - 1) & channel->ptrmask; /* Subscriber tries to lock LENGTH bytes */ @@ -284,6 +286,8 @@ inline void ndp_channel_txsync(struct ndp_subscription *sub, struct ndp_subscrip /* There is no locked subscriber */ channel->hwptr = channel->ops->get_hwptr(channel); + if (channel->ops->get_free_space != NULL) + sync->size = channel->ops->get_free_space(channel); chlen = (channel->hwptr - channel->swptr - 1) & channel->ptrmask; /* Subscriber tries to lock LENGTH bytes */ @@ -302,7 +306,6 @@ inline void ndp_channel_txsync(struct ndp_subscription *sub, struct ndp_subscrip } spin_unlock(&channel->lock); - sync->hwptr = sub->hwptr; sync->swptr = sub->swptr; } diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index a00ccabf..3c567af6 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -1,10 +1,11 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* - * NDP driver of the NFB platform - DMA controller - Medusa/v2 type + * NDP driver of the NFB platform - DMA controller - Medusa/v2 type, Calypte/v3 type * * Copyright (C) 2020-2022 CESNET * Author(s): * Martin Spinler + * Vladislav Valek */ #include @@ -22,9 +23,10 @@ #include -#define NDP_CTRL_TX_DESC_SIZE (sizeof(struct nc_ndp_desc)) -#define NDP_CTRL_RX_DESC_SIZE (sizeof(struct nc_ndp_desc)) -#define NDP_CTRL_RX_HDR_SIZE (sizeof(struct nc_ndp_hdr)) +#define NDP_CTRL_TX_DESC_SIZE (sizeof(struct nc_ndp_desc)) +#define NDP_CTRL_RX_DESC_SIZE (sizeof(struct nc_ndp_desc)) +#define NDP_CTRL_RX_NDP_HDR_SIZE (sizeof(struct nc_ndp_hdr)) +#define NDP_CTRL_RX_CALYPTE_HDR_SIZE (sizeof(struct nc_calypte_hdr)) #define NDP_CTRL_RX_DESC_BURST (64u) @@ -51,11 +53,19 @@ struct ndp_ctrl { /* INFO: virtual memory: shadowed */ struct nc_ndp_desc *desc_buffer_v; - struct nc_ndp_hdr *hdr_buffer_v; ndp_offset_t *off_buffer_v; + union { + struct { + struct nc_ndp_hdr *hdr_buffer; + } medusa; + struct { + struct nc_calypte_hdr *hdr_buffer; + uint64_t free_bytes; + } calypte; + } ts; + uint32_t next_sdp; - uint8_t next_sdp_age; uint32_t flags; @@ -65,8 +75,14 @@ struct ndp_ctrl { /* INFO: Use only for alloc / free */ int desc_count; int hdr_count; + + void *hdr_buffer; + void *hdr_buffer_v; + + uint8_t hdr_buff_en_rw_map; + uint8_t next_sdp_age; + struct nc_ndp_desc *desc_buffer; - struct nc_ndp_hdr *hdr_buffer; ndp_offset_t *off_buffer; uint32_t *update_buffer; resource_size_t update_buffer_phys; @@ -120,7 +136,7 @@ static const struct attribute_group *ndp_ctrl_attr_tx_groups[] = { int ndp_ctrl_v2_get_vmaps(struct ndp_channel *channel, void **hdr, void **off) { struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); - *hdr = ctrl->hdr_buffer_v; + *hdr = ctrl->ts.medusa.hdr_buffer; *off = ctrl->off_buffer_v; return ctrl->c.mhp + 1; } @@ -162,7 +178,7 @@ static void ndp_ctrl_user_fill_rx_descs(struct ndp_ctrl *ctrl) uint32_t sdp = ctrl->c.sdp; ndp_offset_t *off = ctrl->off_buffer_v + php; - struct nc_ndp_hdr *hdr = ctrl->hdr_buffer_v + php; + struct nc_ndp_hdr *hdr = ctrl->ts.medusa.hdr_buffer + php; struct nc_ndp_desc *desc = ctrl->desc_buffer_v + ctrl->next_sdp; uint32_t sdp_shift; uint64_t last_upper_addr = ctrl->c.last_upper_addr; @@ -228,13 +244,13 @@ static void ndp_ctrl_user_fill_rx_descs(struct ndp_ctrl *ctrl) } } -static void ndp_ctrl_rx_set_swptr(struct ndp_channel *channel, uint64_t ptr) +static void ndp_ctrl_medusa_rx_set_swptr(struct ndp_channel *channel, uint64_t ptr) { struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); uint32_t shp = ctrl->c.shp; - struct nc_ndp_hdr *hdr = ctrl->hdr_buffer_v + shp; + struct nc_ndp_hdr *hdr = ctrl->ts.medusa.hdr_buffer + shp; // struct nc_ndp_desc *desc_buffer = ctrl->desc_buffer_v + ctrl->sdp; if (ctrl->mode == NDP_CTRL_MODE_PACKET_SIMPLE) { @@ -273,6 +289,27 @@ static void ndp_ctrl_rx_set_swptr(struct ndp_channel *channel, uint64_t ptr) } } +static void ndp_ctrl_calypte_rx_set_swptr(struct ndp_channel *channel, uint64_t ptr) +{ + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + struct nc_calypte_hdr *hdr = ctrl->ts.calypte.hdr_buffer + ctrl->c.shp; + int count = (ptr - ctrl->c.shp) & ctrl->c.mhp; + + int new_sdp = 0; + unsigned i; + + for (i = 0; i < count; i++) { + new_sdp += (hdr[i].frame_len + NDP_RX_CALYPTE_BLOCK_SIZE - 1) / NDP_RX_CALYPTE_BLOCK_SIZE; + } + + ctrl->c.shp = ptr; + ctrl->c.sdp = (ctrl->c.sdp + new_sdp) & ctrl->c.mdp; + if (count) { + nc_ndp_ctrl_sp_flush(&ctrl->c); + } +} + static uint64_t ndp_ctrl_rx_get_hwptr(struct ndp_channel *channel) { int i; @@ -283,14 +320,17 @@ static uint64_t ndp_ctrl_rx_get_hwptr(struct ndp_channel *channel) hhp = ctrl->c.hhp; nc_ndp_ctrl_hhp_update(&ctrl->c); - hhp_new = ctrl->c.hhp; + if (ctrl->c.type == DMA_TYPE_CALYPTE) + return ctrl->c.hhp; + + hhp_new = ctrl->c.hhp; count = (hhp_new - hhp) & ctrl->c.mhp; if (ctrl->mode == NDP_CTRL_MODE_PACKET_SIMPLE) { /* Constant packet offsets in this mode */ } else if (ctrl->mode == NDP_CTRL_MODE_STREAM) { - struct nc_ndp_hdr *hdr = ctrl->hdr_buffer_v + hhp; + struct nc_ndp_hdr *hdr = ctrl->ts.medusa.hdr_buffer + hhp; ndp_offset_t *off = ctrl->off_buffer_v + hhp; for (i = 0; i < count; i++) { off[i+1] = off[i] + hdr[i].frame_len; @@ -306,9 +346,9 @@ static uint64_t ndp_ctrl_rx_get_hwptr(struct ndp_channel *channel) return hhp_new; } -static uint64_t ndp_ctrl_tx_get_hwptr(struct ndp_channel *channel); +static uint64_t ndp_ctrl_medusa_tx_get_hwptr(struct ndp_channel *channel); -static void ndp_ctrl_tx_set_swptr(struct ndp_channel *channel, uint64_t ptr) +static void ndp_ctrl_medusa_tx_set_swptr(struct ndp_channel *channel, uint64_t ptr) { int i; int count; @@ -330,7 +370,7 @@ static void ndp_ctrl_tx_set_swptr(struct ndp_channel *channel, uint64_t ptr) struct nc_ndp_hdr *hdr; off = ctrl->off_buffer_v + shp + i; - hdr = ctrl->hdr_buffer_v + shp + i; + hdr = ctrl->ts.medusa.hdr_buffer + shp + i; if (ctrl->mode == NDP_CTRL_MODE_USER) { addr = *off; @@ -341,7 +381,7 @@ static void ndp_ctrl_tx_set_swptr(struct ndp_channel *channel, uint64_t ptr) if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(addr) != last_upper_addr)) { while (ctrl->free_desc == 0) { usleep_range(10, 50); - ndp_ctrl_tx_get_hwptr(channel); + ndp_ctrl_medusa_tx_get_hwptr(channel); if (unlikely(ndp_kill_signal_pending(current))) { dirty = 1; @@ -360,7 +400,7 @@ static void ndp_ctrl_tx_set_swptr(struct ndp_channel *channel, uint64_t ptr) while (ctrl->free_desc == 0) { usleep_range(10, 50); - ndp_ctrl_tx_get_hwptr(channel); + ndp_ctrl_medusa_tx_get_hwptr(channel); if (ndp_kill_signal_pending(current)) { dirty = 1; break; @@ -386,7 +426,7 @@ static void ndp_ctrl_tx_set_swptr(struct ndp_channel *channel, uint64_t ptr) nc_ndp_ctrl_sdp_flush(&ctrl->c); } -static uint64_t ndp_ctrl_tx_get_hwptr(struct ndp_channel *channel) +static uint64_t ndp_ctrl_medusa_tx_get_hwptr(struct ndp_channel *channel) { uint32_t hdp; int i, count, free_hdrs = 0; @@ -410,13 +450,62 @@ static uint64_t ndp_ctrl_tx_get_hwptr(struct ndp_channel *channel) return ctrl->c.hhp; } +static uint64_t ndp_ctrl_calypte_tx_get_free_space(struct ndp_channel *channel) { + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + return ctrl->ts.calypte.free_bytes; +} + +static uint64_t ndp_ctrl_calypte_tx_get_hwptr(struct ndp_channel *channel) +{ + uint32_t hdp; + int count; + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + hdp = ctrl->c.hdp; + nc_ndp_ctrl_hp_update(&ctrl->c); + count = (ctrl->c.hdp - hdp) & ctrl->c.mdp; + + ctrl->ts.calypte.free_bytes += count; + return ctrl->c.hhp; +} + +static void ndp_ctrl_calypte_tx_set_swptr(struct ndp_channel *channel, uint64_t ptr) +{ + int i; + int count; + + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + uint32_t sdp = ctrl->c.sdp; + uint32_t shp = ctrl->c.shp; + wmb(); + + count = (ptr - shp) & ctrl->c.mhp; + + for (i = 0; i < count; i++) { + struct nc_calypte_hdr *hdr; + hdr = ctrl->ts.calypte.hdr_buffer + shp + i; + // Subtracting whole multiples of NDP_TX_CALYPTE_BLOCK_SIZE from the ctrl->free_bytes + ctrl->ts.calypte.free_bytes -= (hdr->frame_len + (NDP_TX_CALYPTE_BLOCK_SIZE -1)) & (~(NDP_TX_CALYPTE_BLOCK_SIZE -1)); + + // Rounding the SDP to the nearest higher multiple of NDP_TX_CALYPTE_BLOCK_SIZE + sdp = ((sdp + hdr->frame_len + (NDP_TX_CALYPTE_BLOCK_SIZE -1)) & (~(NDP_TX_CALYPTE_BLOCK_SIZE -1))) & ctrl->c.mdp; + } + + wmb(); + ctrl->c.sdp = sdp; + ctrl->c.shp = ptr; + nc_ndp_ctrl_sp_flush(&ctrl->c); +} + static uint64_t ndp_ctrl_get_flags(struct ndp_channel *channel) { uint64_t ret = 0; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); - ret |= NDP_CHANNEL_FLAG_USE_HEADER; - ret |= NDP_CHANNEL_FLAG_USE_OFFSET; + if (ctrl->c.type == DMA_TYPE_MEDUSA) { + ret |= NDP_CHANNEL_FLAG_USE_HEADER; + ret |= NDP_CHANNEL_FLAG_USE_OFFSET; + } ret |= ctrl->flags; @@ -428,9 +517,32 @@ static uint64_t ndp_ctrl_set_flags(struct ndp_channel *channel, uint64_t flags) return ndp_ctrl_get_flags(channel); } -static int ndp_ctrl_start(struct ndp_channel *channel, uint64_t *hwptr) +static int ndp_ctrl_start(struct ndp_ctrl *ctrl, struct nc_ndp_ctrl_start_params *sp) { int ret; + + ret = nc_ndp_ctrl_start(&ctrl->c, sp); + if (ret == -EALREADY) { + /* Try to stop */ + nc_ndp_ctrl_stop_force(&ctrl->c); + msleep(10); + ret = nc_ndp_ctrl_start(&ctrl->c, sp); + if (ret == 0) { + dev_err(ctrl->nfb->dev, "NDP queue %s was in dirty state, restart seems succesfull, " + "but errors can occur\n", dev_name(&ctrl->channel.dev)); + } else { + dev_err(ctrl->nfb->dev, "NDP queue %s is in dirty state, can't be started\n", dev_name(&ctrl->channel.dev)); + return -1; + } + } + + return ret; +} + +static int ndp_ctrl_medusa_start(struct ndp_channel *channel, uint64_t *hwptr) +{ + + int ret; struct nc_ndp_ctrl_start_params sp; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); @@ -442,22 +554,11 @@ static int ndp_ctrl_start(struct ndp_channel *channel, uint64_t *hwptr) sp.nb_desc = ctrl->desc_count; sp.nb_hdr = ctrl->hdr_count; - ret = nc_ndp_ctrl_start(&ctrl->c, &sp); - if (ret == -EALREADY) { - /* Try to stop */ - nc_ndp_ctrl_stop_force(&ctrl->c); - msleep(10); - ret = nc_ndp_ctrl_start(&ctrl->c, &sp); - if (ret == 0) { - dev_err(ctrl->nfb->dev, "NDP queue %s was in dirty state, restart seems succesfull, " - "but errors can occur\n", dev_name(&channel->dev)); - } else { - dev_err(ctrl->nfb->dev, "NDP queue %s is in dirty state, can't be started\n", dev_name(&channel->dev)); - return -1; - } - } else if (ret) { + ctrl->ts.medusa.hdr_buffer = ctrl->hdr_buffer_v; + + ret = ndp_ctrl_start(ctrl, &sp); + if (ret) return ret; - } ctrl->mps_last_offset = 0; ctrl->next_sdp = 0; @@ -495,6 +596,32 @@ static int ndp_ctrl_start(struct ndp_channel *channel, uint64_t *hwptr) return 0; } +static int ndp_ctrl_calypte_start(struct ndp_channel *channel, uint64_t *hwptr) +{ + int ret; + struct nc_ndp_ctrl_start_params sp; + + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + // Only one block is used, therefore the physical address of the first one in "blocks" + // list is used. + sp.data_buffer = channel->ring.blocks->phys; + sp.hdr_buffer = ctrl->hdr_buffer_phys; + sp.nb_data = ctrl->hdr_count; + sp.nb_hdr = ctrl->hdr_count; + + ctrl->ts.calypte.hdr_buffer = ctrl->hdr_buffer_v; + + ret = ndp_ctrl_start(ctrl, &sp); + if (ret) + return ret; + + ctrl->ts.calypte.free_bytes = ctrl->c.mdp; + + *hwptr = 0; + return 0; +} + static int ndp_ctrl_stop(struct ndp_channel *channel, int force) { int ret; @@ -526,13 +653,13 @@ static int ndp_ctrl_stop(struct ndp_channel *channel, int force) static int ndp_ctrl_hdr_mmap(struct vm_area_struct *vma, unsigned long offset, unsigned long size, void *priv) { - int ret; + int ret = -1; struct ndp_ctrl *ctrl = (struct ndp_ctrl*) priv; /* TODO: Check if channel is subscribed */ - /* Check permissions: read-only for RX */ - if (ctrl->channel.id.type == NDP_CHANNEL_TYPE_RX && (vma->vm_flags & (VM_WRITE | VM_READ)) != VM_READ) + //Check permissions: read-only for RX unless it is DMA Calypte + if (ctrl->channel.id.type == NDP_CHANNEL_TYPE_RX && (vma->vm_flags & (VM_WRITE | VM_READ)) != VM_READ && ctrl->hdr_buff_en_rw_map == 0) return -EINVAL; /* Allow mmap only for exact offset & size match */ @@ -592,7 +719,7 @@ void *ndp_ctrl_vmap_shadow(int size, void *virt) return ret; } -static int ndp_ctrl_attach_ring(struct ndp_channel *channel) +static int ndp_ctrl_medusa_attach_ring(struct ndp_channel *channel) { int ret = -ENOMEM; int node_offset; @@ -605,7 +732,7 @@ static int ndp_ctrl_attach_ring(struct ndp_channel *channel) return -EINVAL; ctrl->desc_count = channel->ring.size / buffer_size; - if (ctrl->desc_count * min(NDP_CTRL_RX_DESC_SIZE, NDP_CTRL_RX_HDR_SIZE) < PAGE_SIZE) { + if (ctrl->desc_count * min(NDP_CTRL_RX_DESC_SIZE, NDP_CTRL_RX_NDP_HDR_SIZE) < PAGE_SIZE) { /* Can't do shadow-map for this ring size */ return -EINVAL; } @@ -652,7 +779,7 @@ static int ndp_ctrl_attach_ring(struct ndp_channel *channel) } /* allocate header area */ - ctrl->hdr_buffer_size = ALIGN(ctrl->hdr_count * NDP_CTRL_RX_HDR_SIZE, PAGE_SIZE); + ctrl->hdr_buffer_size = ALIGN(ctrl->hdr_count * NDP_CTRL_RX_NDP_HDR_SIZE, PAGE_SIZE); ctrl->hdr_buffer = dma_alloc_coherent(dev, ctrl->hdr_buffer_size, &ctrl->hdr_buffer_phys, GFP_KERNEL); if (ctrl->hdr_buffer == NULL) { @@ -717,7 +844,155 @@ static int ndp_ctrl_attach_ring(struct ndp_channel *channel) return ret; } -static void ndp_ctrl_detach_ring(struct ndp_channel *channel) +static int ndp_ctrl_rx_calypte_attach_ring(struct ndp_channel *channel) +{ + int ret = -ENOMEM; + int node_offset; + void *fdt = channel->ndp->nfb->fdt; + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + struct device *dev = channel->ring.dev; + + if (channel->ring.size == 0) + return -EINVAL; + + if (channel->ring.block_count != 1) + return -EINVAL; + + ctrl->hdr_buff_en_rw_map = 1; + + ctrl->hdr_count = channel->ring.size / NDP_RX_CALYPTE_BLOCK_SIZE; + if (ctrl->hdr_count * min((uint16_t)NDP_RX_CALYPTE_BLOCK_SIZE, (uint16_t)NDP_CTRL_RX_CALYPTE_HDR_SIZE) < PAGE_SIZE) { + /* Can't do shadow-map for this ring size */ + return -EINVAL; + } + + channel->ptrmask = ctrl->hdr_count - 1; + + /* allocate header area */ + ctrl->hdr_buffer_size = ALIGN(ctrl->hdr_count * NDP_CTRL_RX_CALYPTE_HDR_SIZE, PAGE_SIZE); + ctrl->hdr_buffer = dma_alloc_coherent(dev, ctrl->hdr_buffer_size, + &ctrl->hdr_buffer_phys, GFP_KERNEL); + if (ctrl->hdr_buffer == NULL) { + return -EINVAL; + } + + ctrl->hdr_buffer_v = ndp_ctrl_vmap_shadow(ctrl->hdr_buffer_size, ctrl->hdr_buffer); + if (ctrl->hdr_buffer_v == NULL) { + goto err_vmap_hdr_buffer; + } + + ret = nfb_char_register_mmap(channel->ndp->nfb, ctrl->hdr_buffer_size * 2, &ctrl->hdr_mmap_offset, ndp_ctrl_hdr_mmap, ctrl); + if (ret) { + goto err_register_mmap_hdr; + } + + node_offset = fdt_path_offset(fdt, "/drivers/ndp/rx_queues"); + node_offset = fdt_subnode_offset(fdt, node_offset, dev_name(&channel->dev)); + + fdt_setprop_u32(fdt, node_offset, "protocol", 3); + fdt_setprop_u64(fdt, node_offset, "hdr_mmap_base", ctrl->hdr_mmap_offset); + fdt_setprop_u64(fdt, node_offset, "hdr_mmap_size", ctrl->hdr_buffer_size * 2); + + return 0; + +err_register_mmap_hdr: + vunmap(ctrl->hdr_buffer_v); + +err_vmap_hdr_buffer: + dma_free_coherent(dev, ctrl->hdr_buffer_size, + ctrl->hdr_buffer, ctrl->hdr_buffer_phys); + ctrl->hdr_buffer = NULL; + return ret; +} + +static int ndp_ctrl_tx_calypte_attach_ring(struct ndp_channel *channel) +{ + int ret = -ENOMEM; + int node_offset; + void *fdt = channel->ndp->nfb->fdt; + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + int ctrl_node_offset = -1; + unsigned long data_buffer_size = -1; + int buffer_offset = -1; + int proplen; + const fdt32_t *prop = NULL; + + struct device *dev = channel->ring.dev; + + node_offset = fdt_path_offset(fdt, "/drivers/ndp/tx_queues"); + node_offset = fdt_subnode_offset(fdt, node_offset, dev_name(&channel->dev)); + + // Find control node of the channel + ctrl_node_offset = fdt_node_offset_by_phandle_ref(fdt, node_offset, "ctrl"); + if (ctrl_node_offset < 0) + return -EBADFD; + + // Find mask for the data buffer + buffer_offset = fdt_node_offset_by_phandle_ref(fdt, ctrl_node_offset, "data_buff"); + if (buffer_offset < 0) + return -EBADFD; + + prop = fdt_getprop(fdt, buffer_offset, "reg", &proplen); + if (prop == NULL) + return -EBADFD; + + data_buffer_size = fdt32_to_cpu(prop[1]); + + // Find mask for the header buffer + buffer_offset = fdt_node_offset_by_phandle_ref(fdt, ctrl_node_offset, "hdr_buff"); + if (buffer_offset < 0) + return -EBADFD; + + prop = fdt_getprop(fdt, buffer_offset, "reg", &proplen); + if (prop == NULL) + return -EBADFD; + + ctrl->hdr_buffer_size = fdt32_to_cpu(prop[1]); + + /* Allocate header area */ + ctrl->hdr_buffer = dma_alloc_coherent(dev, ctrl->hdr_buffer_size, &ctrl->hdr_buffer_phys, GFP_KERNEL); + if (ctrl->hdr_buffer == NULL) { + goto err_alloc_hdr; + } + + ctrl->hdr_buffer_v = ndp_ctrl_vmap_shadow(ctrl->hdr_buffer_size, ctrl->hdr_buffer); + if (ctrl->hdr_buffer_v == NULL) { + goto err_vmap_hdr_buffer; + } + + ret = nfb_char_register_mmap(channel->ndp->nfb, ctrl->hdr_buffer_size * 2, &ctrl->hdr_mmap_offset, ndp_ctrl_hdr_mmap, ctrl); + if (ret) { + goto err_register_mmap_hdr; + } + + // Store read values of buffer sizes to structure variables + ctrl->c.mdp = (data_buffer_size/2 -1) & 0x0000FFFFul; + ctrl->c.mhp = (ctrl->hdr_buffer_size/(2*NDP_CTRL_RX_CALYPTE_HDR_SIZE) -1) & 0x0000FFFFul; + channel->ptrmask = ctrl->c.mhp; + + fdt_setprop_u32(fdt, node_offset, "protocol", 3); + fdt_setprop_u32(fdt, node_offset, "data_buff_size", data_buffer_size); + fdt_setprop_u32(fdt, node_offset, "hdr_buff_size", ctrl->hdr_buffer_size); + + fdt_setprop_u64(fdt, node_offset, "hdr_mmap_base", ctrl->hdr_mmap_offset); + fdt_setprop_u64(fdt, node_offset, "hdr_mmap_size", ctrl->hdr_buffer_size * 2); + + return 0; + +err_register_mmap_hdr: + vunmap(ctrl->hdr_buffer_v); + +err_vmap_hdr_buffer: + dma_free_coherent(dev, ctrl->hdr_buffer_size, + ctrl->hdr_buffer, ctrl->hdr_buffer_phys); + ctrl->hdr_buffer = NULL; + +err_alloc_hdr: + return ret; +} + +static void ndp_ctrl_medusa_detach_ring(struct ndp_channel *channel) { struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); struct device *dev = channel->ring.dev; @@ -748,6 +1023,19 @@ static void ndp_ctrl_detach_ring(struct ndp_channel *channel) } } +static void ndp_ctrl_calypte_detach_ring(struct ndp_channel *channel) +{ + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + struct device *dev = channel->ring.dev; + + if (ctrl->hdr_buffer) { + nfb_char_unregister_mmap(channel->ndp->nfb, ctrl->hdr_mmap_offset); + vunmap(ctrl->hdr_buffer_v); + dma_free_coherent(dev, ctrl->hdr_buffer_size, ctrl->hdr_buffer, ctrl->hdr_buffer_phys); + ctrl->hdr_buffer = NULL; + } +} + static void ndp_ctrl_destroy(struct device *dev) { struct ndp_channel *channel = container_of(dev, struct ndp_channel, dev); @@ -810,26 +1098,54 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i static struct ndp_channel_ops ndp_ctrl_rx_ops = { - .start = ndp_ctrl_start, + .start = ndp_ctrl_medusa_start, .stop = ndp_ctrl_stop, .get_hwptr = ndp_ctrl_rx_get_hwptr, - .set_swptr = ndp_ctrl_rx_set_swptr, + .set_swptr = ndp_ctrl_medusa_rx_set_swptr, .get_flags = ndp_ctrl_get_flags, .set_flags = ndp_ctrl_set_flags, - .attach_ring = ndp_ctrl_attach_ring, - .detach_ring = ndp_ctrl_detach_ring, + .attach_ring = ndp_ctrl_medusa_attach_ring, + .detach_ring = ndp_ctrl_medusa_detach_ring, + .get_free_space = NULL, }; static struct ndp_channel_ops ndp_ctrl_tx_ops = { - .start = ndp_ctrl_start, + .start = ndp_ctrl_medusa_start, + .stop = ndp_ctrl_stop, + .get_hwptr = ndp_ctrl_medusa_tx_get_hwptr, + .set_swptr = ndp_ctrl_medusa_tx_set_swptr, + .get_flags = ndp_ctrl_get_flags, + .set_flags = ndp_ctrl_set_flags, + .attach_ring = ndp_ctrl_medusa_attach_ring, + .detach_ring = ndp_ctrl_medusa_detach_ring, + .get_free_space = NULL, +}; + +static struct ndp_channel_ops ndp_ctrl_calypte_rx_ops = +{ + .start = ndp_ctrl_calypte_start, .stop = ndp_ctrl_stop, - .get_hwptr = ndp_ctrl_tx_get_hwptr, - .set_swptr = ndp_ctrl_tx_set_swptr, + .get_hwptr = ndp_ctrl_rx_get_hwptr, + .set_swptr = ndp_ctrl_calypte_rx_set_swptr, + .get_flags = ndp_ctrl_get_flags, + .set_flags = ndp_ctrl_set_flags, + .attach_ring = ndp_ctrl_rx_calypte_attach_ring, + .detach_ring = ndp_ctrl_calypte_detach_ring, + .get_free_space = NULL, +}; + +static struct ndp_channel_ops ndp_ctrl_calypte_tx_ops = +{ + .start = ndp_ctrl_calypte_start, + .stop = ndp_ctrl_stop, + .get_hwptr = ndp_ctrl_calypte_tx_get_hwptr, + .set_swptr = ndp_ctrl_calypte_tx_set_swptr, .get_flags = ndp_ctrl_get_flags, .set_flags = ndp_ctrl_set_flags, - .attach_ring = ndp_ctrl_attach_ring, - .detach_ring = ndp_ctrl_detach_ring, + .attach_ring = ndp_ctrl_tx_calypte_attach_ring, + .detach_ring = ndp_ctrl_calypte_detach_ring, + .get_free_space = ndp_ctrl_calypte_tx_get_free_space, }; struct ndp_channel *ndp_ctrl_v2_create_rx(struct ndp *ndp, int index, int node_offset) @@ -843,3 +1159,15 @@ struct ndp_channel *ndp_ctrl_v2_create_tx(struct ndp *ndp, int index, int node_o struct ndp_channel_id id = {.index = index, .type = NDP_CHANNEL_TYPE_TX}; return ndp_ctrl_create(ndp, id, ndp_ctrl_attr_tx_groups, &ndp_ctrl_tx_ops, node_offset); } + +struct ndp_channel *ndp_ctrl_v3_create_rx(struct ndp *ndp, int index, int node_offset) +{ + struct ndp_channel_id id = {.index = index, .type = NDP_CHANNEL_TYPE_RX}; + return ndp_ctrl_create(ndp, id, ndp_ctrl_attr_rx_groups, &ndp_ctrl_calypte_rx_ops, node_offset); +} + +struct ndp_channel *ndp_ctrl_v3_create_tx(struct ndp *ndp, int index, int node_offset) +{ + struct ndp_channel_id id = {.index = index, .type = NDP_CHANNEL_TYPE_TX}; + return ndp_ctrl_create(ndp, id, ndp_ctrl_attr_tx_groups, &ndp_ctrl_calypte_tx_ops, node_offset); +} diff --git a/drivers/kernel/drivers/nfb/ndp/driver.c b/drivers/kernel/drivers/nfb/ndp/driver.c index 1d1ccf71..ff6a049f 100644 --- a/drivers/kernel/drivers/nfb/ndp/driver.c +++ b/drivers/kernel/drivers/nfb/ndp/driver.c @@ -36,12 +36,16 @@ struct ndp_channel *ndp_ctrl_v1_create_rx(struct ndp *ndp, int index, int node_o struct ndp_channel *ndp_ctrl_v1_create_tx(struct ndp *ndp, int index, int node_offset); struct ndp_channel *ndp_ctrl_v2_create_rx(struct ndp *ndp, int index, int node_offset); struct ndp_channel *ndp_ctrl_v2_create_tx(struct ndp *ndp, int index, int node_offset); +struct ndp_channel *ndp_ctrl_v3_create_rx(struct ndp *ndp, int index, int node_offset); +struct ndp_channel *ndp_ctrl_v3_create_tx(struct ndp *ndp, int index, int node_offset); struct ndp_ctrl_create ndp_ctrls[] = { {.compatible = "netcope,dma_ctrl_sze_rx", .create = ndp_ctrl_v1_create_rx}, {.compatible = "netcope,dma_ctrl_sze_tx", .create = ndp_ctrl_v1_create_tx}, {.compatible = "netcope,dma_ctrl_ndp_rx", .create = ndp_ctrl_v2_create_rx}, {.compatible = "netcope,dma_ctrl_ndp_tx", .create = ndp_ctrl_v2_create_tx}, + {.compatible = "cesnet,dma_ctrl_calypte_rx", .create = ndp_ctrl_v3_create_rx}, + {.compatible = "cesnet,dma_ctrl_calypte_tx", .create = ndp_ctrl_v3_create_tx}, }; static void ndp_create_channels_from_ctrl(struct ndp *ndp, struct ndp_ctrl_create *ctrl) diff --git a/drivers/kernel/drivers/nfb/ndp/ndp.h b/drivers/kernel/drivers/nfb/ndp/ndp.h index 5c00178e..5a77b551 100644 --- a/drivers/kernel/drivers/nfb/ndp/ndp.h +++ b/drivers/kernel/drivers/nfb/ndp/ndp.h @@ -105,6 +105,7 @@ struct ndp_channel_ops { void (*set_swptr)(struct ndp_channel *channel, uint64_t ptr); uint64_t (*get_flags)(struct ndp_channel *channel); uint64_t (*set_flags)(struct ndp_channel *channel, uint64_t flags); + uint64_t (*get_free_space)(struct ndp_channel *channel); }; struct ndp_channel_id { @@ -232,6 +233,8 @@ int ndp_subscriber_poll(struct ndp_subscriber *subscriber, struct file *filp, st int ndp_channel_start(struct ndp_subscription *sub); int ndp_channel_stop(struct ndp_subscription *sub, int force); +void ndp_channel_txsync(struct ndp_subscription *sub, struct ndp_subscription_sync *sync); +void ndp_channel_rxsync(struct ndp_subscription *sub, struct ndp_subscription_sync *sync); void ndp_channel_sync(struct ndp_subscription *sub, struct ndp_subscription_sync *sync); extern struct ndp_channel *ndp_channel_create(struct ndp *ndp, struct ndp_channel_ops *ctrl_ops, diff --git a/drivers/kernel/drivers/nfb/ndp/subscription.c b/drivers/kernel/drivers/nfb/ndp/subscription.c index be319d3e..8ffde825 100644 --- a/drivers/kernel/drivers/nfb/ndp/subscription.c +++ b/drivers/kernel/drivers/nfb/ndp/subscription.c @@ -57,8 +57,6 @@ int ndp_subscription_start(struct ndp_subscription *sub, if (sub->channel->id.type == NDP_CHANNEL_TYPE_RX) { sync->hwptr = sub->hwptr; sync->swptr = sub->swptr; - } else { - } sub->status = NDP_SUB_STATUS_RUNNING; diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index d55b2a3a..f8b6e4e1 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* - * Network component library - DMA controller - NDP/v2 type + * Network component library - DMA controller - NDP/v2 type, CALYPTE/v3 type * * Copyright (C) 2020-2023 CESNET * Author(s): @@ -14,8 +14,13 @@ /* Compatible strings for Device Tree */ #define COMP_NC_DMA_CTRL_NDP_RX "netcope,dma_ctrl_ndp_rx" #define COMP_NC_DMA_CTRL_NDP_TX "netcope,dma_ctrl_ndp_tx" +#define COMP_NC_DMA_CTRL_CALYPTE_RX "cesnet,dma_ctrl_calypte_rx" +#define COMP_NC_DMA_CTRL_CALYPTE_TX "cesnet,dma_ctrl_calypte_tx" +#define DMA_TYPE_MEDUSA 2 +#define DMA_TYPE_CALYPTE 3 +// ---------------- NDP/Calypte common registers ------- #define NDP_CTRL_REG_CONTROL 0x00 #define NDP_CTRL_REG_CONTROL_STOP 0x0 #define NDP_CTRL_REG_CONTROL_START 0x1 @@ -34,7 +39,7 @@ // --------------- NDP specific registers -------------- #define NDP_CTRL_REG_TIMEOUT 0x20 -// -------------- NDP Counters ----------------- +// -------------- NDP/Calypte Counters ----------------- // Processed packets on TX #define NDP_CTRL_REG_CNTR_SENT 0x60 // Processed packets on RX @@ -46,6 +51,12 @@ #define NDP_CTRL_UPDATE_SIZE 4 #define NDP_PACKET_HEADER_SIZE 4 +#define NDP_CALYPTE_METADATA_NOT_VALID 0x400 +#define NDP_CALYPTE_METADATA_HDR_SIZE_MASK 0xff + +#define NDP_TX_CALYPTE_BLOCK_SIZE (32u) +#define NDP_RX_CALYPTE_BLOCK_SIZE (128u) + #define NDP_CTRL_DESC_UPPER_ADDR(addr) (((uint64_t)addr) & 0xFFFFFFFFc0000000ull) #define NDP_CTRL_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -79,6 +90,14 @@ struct nc_ndp_desc { }; } __attribute__((__packed__)); +struct nc_calypte_hdr { + uint16_t frame_len; + uint16_t frame_ptr; + unsigned valid : 1; + unsigned reserved: 7; + unsigned metadata : 24; +} __attribute__((__packed__)); + struct nc_ndp_ctrl { /* public members */ uint64_t last_upper_addr; @@ -93,13 +112,17 @@ struct nc_ndp_ctrl { struct nfb_comp *comp; uint32_t *update_buffer; uint32_t dir : 1; + + uint8_t type; }; struct nc_ndp_ctrl_start_params { uint64_t desc_buffer; + uint64_t data_buffer; uint64_t hdr_buffer; uint64_t update_buffer; uint32_t *update_buffer_virt; + uint32_t nb_data; uint32_t nb_desc; uint32_t nb_hdr; }; @@ -154,28 +177,45 @@ static inline struct nc_ndp_desc nc_ndp_tx_desc2(uint64_t phys, uint16_t len, ui static inline void nc_ndp_ctrl_hdp_update(struct nc_ndp_ctrl *ctrl) { + if (ctrl->type == DMA_TYPE_MEDUSA) { #ifdef __KERNEL__ - rmb(); + rmb(); #else #ifdef _RTE_CONFIG_H_ - rte_rmb(); - rte_wmb(); + rte_rmb(); + rte_wmb(); #endif #endif - ctrl->hdp = ((uint32_t*) ctrl->update_buffer)[0]; + ctrl->hdp = ((uint32_t*) ctrl->update_buffer)[0]; + } else if (ctrl->type == DMA_TYPE_CALYPTE) { + ctrl->hdp = (nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_HDP)) & ctrl->mdp; + } } static inline void nc_ndp_ctrl_hhp_update(struct nc_ndp_ctrl *ctrl) { + if (ctrl->type == DMA_TYPE_MEDUSA) { #ifdef __KERNEL__ - rmb(); + rmb(); #else #ifdef _RTE_CONFIG_H_ - rte_rmb(); - rte_wmb(); + rte_rmb(); + rte_wmb(); #endif #endif - ctrl->hhp = ((uint32_t*) ctrl->update_buffer)[1]; + ctrl->hhp = ((uint32_t*) ctrl->update_buffer)[1]; + } else if (ctrl->type == DMA_TYPE_CALYPTE) { + ctrl->hhp = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_HHP); + } +} + +static inline void nc_ndp_ctrl_hp_update(struct nc_ndp_ctrl *ctrl) +{ + uint64_t hwpointers; + + hwpointers = nfb_comp_read64(ctrl->comp, NDP_CTRL_REG_HDP); + ctrl->hdp = ((uint32_t)hwpointers) & ctrl->mdp; + ctrl->hhp = ((uint32_t)(hwpointers >> 32)) & ctrl->mhp; } static inline void nc_ndp_ctrl_sp_flush(struct nc_ndp_ctrl *ctrl) @@ -207,7 +247,12 @@ static inline int nc_ndp_ctrl_open(struct nfb_device* nfb, int fdt_offset, struc int ret; unsigned int i; - const char *compatible[] = {COMP_NC_DMA_CTRL_NDP_RX, COMP_NC_DMA_CTRL_NDP_TX}; + const char *compatible[] = { + COMP_NC_DMA_CTRL_NDP_RX, + COMP_NC_DMA_CTRL_NDP_TX, + COMP_NC_DMA_CTRL_CALYPTE_RX, + COMP_NC_DMA_CTRL_CALYPTE_TX + }; if (nfb == NULL) return -EINVAL; @@ -222,12 +267,17 @@ static inline int nc_ndp_ctrl_open(struct nfb_device* nfb, int fdt_offset, struc if (ret) return -EINVAL; + if (i < 2) + ctrl->type = DMA_TYPE_MEDUSA; + else + ctrl->type = DMA_TYPE_CALYPTE; + ctrl->comp = nfb_comp_open(nfb, fdt_offset); if (ctrl->comp == NULL) { return -ENODEV; } - ctrl->dir = i; + ctrl->dir = i % 2; return 0; } @@ -236,9 +286,19 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl { int ret; uint32_t status; + uint32_t nb_d = 0; + uint64_t d_buffer = 0; + + if (ctrl->type == DMA_TYPE_MEDUSA) { + nb_d = sp->nb_desc; + d_buffer = sp->desc_buffer; + } else if (ctrl->type == DMA_TYPE_CALYPTE) { + nb_d = sp->nb_data; + d_buffer = sp->data_buffer; + } /* Check for valid parameters: number of descs and hdrs must be pow2() */ - if ((sp->nb_desc & (sp->nb_desc - 1)) != 0) + if ((nb_d & (nb_d - 1)) != 0) return -EINVAL; if (ctrl->dir == 0 && (sp->nb_hdr & (sp->nb_hdr - 1)) != 0) return -EINVAL; @@ -248,11 +308,17 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl goto err_comp_lock; } - ctrl->update_buffer = sp->update_buffer_virt; + if (ctrl->type == DMA_TYPE_MEDUSA) + ctrl->update_buffer = sp->update_buffer_virt; - ctrl->mdp = sp->nb_desc - 1; - /* INFO: kernel driver is currently using this value for TX */ - ctrl->mhp = sp->nb_hdr - 1; + if (!(ctrl->type == DMA_TYPE_CALYPTE && ctrl->dir == 1)) { + ctrl->mdp = nb_d - 1; + /* INFO: kernel driver is currently using this value for TX */ + ctrl->mhp = sp->nb_hdr - 1; + } else { + ctrl->mdp = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MDP); + ctrl->mhp = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MHP); + } /* Set pointers to zero */ ctrl->sdp = 0; @@ -260,9 +326,11 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl ctrl->shp = 0; ctrl->hhp = 0; - ctrl->update_buffer[0] = 0; - if (ctrl->dir == 0) - ctrl->update_buffer[1] = 0; + if (ctrl->type == DMA_TYPE_MEDUSA) { + ctrl->update_buffer[0] = 0; + if (ctrl->dir == 0) + ctrl->update_buffer[1] = 0; + } /* INFO: driver must ensure first descriptor type is desc0 */ ctrl->last_upper_addr = 0xFFFFFFFFFFFFFFFFull; @@ -275,24 +343,29 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl } /* Set address of first descriptor */ - nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_DESC_BASE, sp->desc_buffer); + if (!(ctrl->type == DMA_TYPE_CALYPTE && ctrl->dir == 1)) + nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_DESC_BASE, d_buffer); /* Set address of RAM hwptr address */ - nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_UPDATE_BASE, sp->update_buffer); + if (ctrl->type == DMA_TYPE_MEDUSA) + nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_UPDATE_BASE, sp->update_buffer); if (ctrl->dir == 0) nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_HDR_BASE, sp->hdr_buffer); /* Set buffer size (mask) */ - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MDP, ctrl->mdp); - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MHP, ctrl->mhp); + if (!(ctrl->type == DMA_TYPE_CALYPTE && ctrl->dir == 1)) { + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MDP, ctrl->mdp); + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MHP, ctrl->mhp); + } /* Zero both buffer ptrs */ nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_SDP, 0); /* Timeout */ /* TODO: let user to configure tihs value */ - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, 0x4000); + if (ctrl->type == DMA_TYPE_MEDUSA) + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, 0x4000); /* Start controller */ nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, NDP_CTRL_REG_CONTROL_START); @@ -325,8 +398,18 @@ static inline int _nc_ndp_ctrl_stop(struct nc_ndp_ctrl *ctrl, int force) nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, NDP_CTRL_REG_CONTROL_STOP); + // Purpose: The RX DMA can pass some packets during the stop process. So HW pointers will surpass + // the SW pointers even when software is no longer accepting data. + if (ctrl->type == DMA_TYPE_CALYPTE && ctrl->dir == 0) { + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_SDP, + nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_HDP)); + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_SHP, + nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_HHP)); + } + if (ret == 0) ret = -EAGAIN; + do { status = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_STATUS); if (!(status & NDP_CTRL_REG_STATUS_RUNNING)) { From 94ffdb4033f39d5eb6c935a7416f2fb489abe79b Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 9 Oct 2023 14:46:17 +0200 Subject: [PATCH 018/518] libnfb-NDP [FEATURE]: add support for DMA Calypte The architecture of DMA Calypte is slightly different then its predecessor, DMA Medusa. With common RX direction, the TX is wastly different where the data are written directly to the FPGA by the host. The FPGA does not care of anything there. --- libnfb/include/netcope/ndp.h | 67 ++++++++++- libnfb/include/netcope/ndp_base.h | 17 ++- libnfb/include/netcope/ndp_calypte.h | 64 ++++++++++ libnfb/include/netcope/ndp_priv.h | 31 +++++ libnfb/include/netcope/ndp_rx.h | 95 ++++++++++++++- libnfb/include/netcope/ndp_tx.h | 173 ++++++++++++++++++++++++++- pynfb/nfb/libnfb.pyx | 2 + 7 files changed, 440 insertions(+), 9 deletions(-) create mode 100644 libnfb/include/netcope/ndp_calypte.h diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 651d203c..3710a48a 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -5,6 +5,7 @@ * Copyright (C) 2018-2022 CESNET * Author(s): * Martin Spinler + * Vladislav Valek */ #include @@ -141,6 +142,67 @@ static inline int nc_ndp_v2_open_queue(struct nc_ndp_queue *q, const void *fdt, return ret; } +static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, int fdt_offset) +{ +#ifndef __KERNEL__ + int prot; + int ret = 0; + size_t hdr_mmap_size = 0; + off_t hdr_mmap_offset = 0; + + size_t hdr_buff_size = 0; + size_t data_buff_size = 0; + + struct ndp_queue_ops *ops = ndp_queue_get_ops(q->q); +#endif + + q->u.v3.pkts_available = 0; + q->u.v3.sdp = 0; + q->u.v3.shp = 0; + +#ifndef __KERNEL__ + if (q->channel.type == NDP_CHANNEL_TYPE_RX) { + ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_size", &hdr_mmap_size); + ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_base", &hdr_mmap_offset); + + if (ret) + return -EBADFD; + } else { + ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_size", &hdr_mmap_size); + ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_base", &hdr_mmap_offset); + ret |= fdt_getprop32(fdt, fdt_offset, "data_buff_size", &data_buff_size); + ret |= fdt_getprop32(fdt, fdt_offset, "hdr_buff_size", &hdr_buff_size); + + if (ret) + return -EBADFD; + } + + if (q->channel.type == NDP_CHANNEL_TYPE_RX) { + ops->burst.rx.get = nc_ndp_v3_rx_burst_get; + ops->burst.rx.put = nc_ndp_v3_rx_burst_put; + } else { + ops->burst.tx.get = nc_ndp_v3_tx_burst_get; + ops->burst.tx.put = nc_ndp_v3_tx_burst_put; + ops->burst.tx.flush = nc_ndp_v3_tx_burst_flush; + } + + prot = PROT_READ | PROT_WRITE; + + q->u.v3.hdrs = mmap(NULL, hdr_mmap_size, prot, MAP_FILE | MAP_SHARED, q->fd, hdr_mmap_offset); + if (q->u.v3.hdrs == MAP_FAILED) { + return -EBADFD; + } + + if (q->channel.type == NDP_CHANNEL_TYPE_RX) { + q->u.v3.hdr_ptr_mask = ((hdr_mmap_size / 2) / sizeof(struct ndp_v3_packethdr)) - 1; // "- 1" to create a mask for AND operations + } else { + q->u.v3.data_ptr_mask = data_buff_size/2 -1; + q->u.v3.hdr_ptr_mask = hdr_buff_size/(2*sizeof(struct ndp_v3_packethdr)) -1; + } +#endif + return 0; +} + static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queue *q, unsigned index, int dir, ndp_open_flags_t ndp_flags) { int ret = 0; @@ -220,7 +282,9 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu q->sync.swptr = 0; q->sync.hwptr = 0; - if (q->protocol == 2) { + if (q->protocol == 3) { + ret = nc_ndp_v3_open_queue(q, fdt, fdt_offset); + } else if (q->protocol == 2) { ret = nc_ndp_v2_open_queue(q, fdt, fdt_offset); } else if (q->protocol == 1) { ret = nc_ndp_v1_open_queue(q); @@ -257,7 +321,6 @@ static inline void nc_ndp_queue_close(struct nc_ndp_queue *q) ndp_subscription_destroy(q->sub); q->sub = NULL; } - #else munmap(q->buffer, q->size * 2); #endif diff --git a/libnfb/include/netcope/ndp_base.h b/libnfb/include/netcope/ndp_base.h index ebe323ba..f03fafee 100644 --- a/libnfb/include/netcope/ndp_base.h +++ b/libnfb/include/netcope/ndp_base.h @@ -36,6 +36,8 @@ static inline unsigned min(unsigned a, unsigned b) #include +#include "ndp_calypte.h" + inline int _ndp_queue_sync(struct nc_ndp_queue *q, struct ndp_subscription_sync *sync) { #ifdef __KERNEL__ @@ -56,6 +58,7 @@ inline int _ndp_queue_start(struct nc_ndp_queue *q) #else if (ioctl(q->fd, NDP_IOC_START, &q->sync)) return errno; + return 0; #endif } @@ -66,6 +69,7 @@ inline int _ndp_queue_stop(struct nc_ndp_queue *q) ndp_subscription_stop(ndp_subscription_by_id(q->subscriber, q->sync.id), 1); #else int ret; + do { errno = 0; ret = ioctl(q->fd, NDP_IOC_STOP, &q->sync); @@ -84,6 +88,7 @@ int ndp_base_queue_open(struct nfb_device *dev, void *dev_priv, unsigned index, int32_t numa; struct nc_ndp_queue *q_nc; struct ndp_queue *q; + const void *fdt = nfb_get_fdt(dev); #ifdef __KERNEL__ struct ndp * ndp; #endif @@ -91,7 +96,7 @@ int ndp_base_queue_open(struct nfb_device *dev, void *dev_priv, unsigned index, (void) dev_priv; - fdt_offset = nc_nfb_fdt_queue_offset(nfb_get_fdt(dev), index, dir); + fdt_offset = nc_nfb_fdt_queue_offset(fdt, index, dir); if (fdt_getprop32(nfb_get_fdt(dev), fdt_offset, "numa", &numa)) { numa = -1; } @@ -121,13 +126,18 @@ int ndp_base_queue_open(struct nfb_device *dev, void *dev_priv, unsigned index, #endif ndp_queue_set_priv(q, q_nc); - if ((ret = nc_ndp_queue_open_init_ext(nfb_get_fdt(dev), q_nc, index, dir, flags))) { + if ((ret = nc_ndp_queue_open_init_ext(fdt, q_nc, index, dir, flags))) { goto err_open; } + // Open buffers (nfb_comp structures) for TX DMA Calypte + if ((ret = ndp_queue_calypte_open_buffers(dev, q_nc, fdt, fdt_offset))) + goto err_calypt_open_buffers; + *pq = q; return 0; +err_calypt_open_buffers: err_open: #ifdef __KERNEL__ ndp_subscriber_destroy(q_nc->subscriber); @@ -145,6 +155,9 @@ void ndp_base_queue_close(void *priv) struct nc_ndp_queue *q = priv; struct ndp_queue *ndp_q = q->q; + // Close buffers for TX DMA Calypte + ndp_queue_calypte_close_buffers(q); + nc_ndp_queue_close(q); #ifdef __KERNEL__ ndp_subscriber_destroy(q->subscriber); diff --git a/libnfb/include/netcope/ndp_calypte.h b/libnfb/include/netcope/ndp_calypte.h new file mode 100644 index 00000000..1eab837b --- /dev/null +++ b/libnfb/include/netcope/ndp_calypte.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Calypte queue - specific functions for this type of queue + * + * Copyright (C) 2023-2023 CESNET + * Author(s): + * Vladislav Valek + */ + +// Because the data in Calypte TX queue are written directly to the FPGA, the reference to the buffers is +// opened using this function. +static inline int ndp_queue_calypte_open_buffers(struct nfb_device *dev, struct nc_ndp_queue *q, const void *fdt, int fdt_offset) +{ +#ifndef __KERNEL__ + int ctrl_node_offset = -1; + int buffer_offset = -1; + + // Applies only for Calypte TX queue + if (!(q->protocol == 3 && q->channel.type == NDP_CHANNEL_TYPE_TX)) + return 0; + + ctrl_node_offset = fdt_node_offset_by_phandle_ref(fdt, fdt_offset, "ctrl"); + if (ctrl_node_offset < 0) + return -EBADFD; + + buffer_offset = fdt_node_offset_by_phandle_ref(fdt, ctrl_node_offset, "data_buff"); + if (buffer_offset < 0) + return -EBADFD; + + q->u.v3.tx_data_buff = nfb_comp_open(dev, buffer_offset); + if (q->u.v3.tx_data_buff == NULL) { + return -EBADFD; + } + + buffer_offset = fdt_node_offset_by_phandle_ref(fdt, ctrl_node_offset, "hdr_buff"); + if (buffer_offset < 0) + goto err_hdr_buff_find_tx; + + q->u.v3.tx_hdr_buff = nfb_comp_open(dev, buffer_offset); + if (q->u.v3.tx_hdr_buff == NULL) { + goto err_hdr_buff_open_tx; + } + + return 0; +err_hdr_buff_open_tx: +err_hdr_buff_find_tx: + nfb_comp_close(q->u.v3.tx_data_buff); + return -EBADFD; +#endif + return 0; +} + +static inline void ndp_queue_calypte_close_buffers(struct nc_ndp_queue *q) +{ +#ifndef __KERNEL__ + if (q->protocol == 3 && q->channel.type == NDP_CHANNEL_TYPE_TX) { + nfb_comp_close(q->u.v3.tx_data_buff); + nfb_comp_close(q->u.v3.tx_hdr_buff); + q->u.v3.tx_data_buff = NULL; + q->u.v3.tx_hdr_buff = NULL; + } +#endif + return; +} diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index 3b9033b6..003242c8 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -5,6 +5,7 @@ * Copyright (C) 2018-2022 CESNET * Author(s): * Martin Spinler + * Vladislav Valek */ #include @@ -27,6 +28,13 @@ struct ndp_v2_offsethdr { __u64 offset; }; +struct ndp_v3_packethdr { + __u16 frame_len; /**< size of the packet */ + __u16 frame_ptr; /**< index into the data array */ + __u8 valid : 1; /**< bit indicating the validity of the header/packet */ + unsigned reserved : 7; /**< bits reserved for future use */ + unsigned metadata:24; /**< user metadata */ +} __attribute((packed)); struct ndp_queue; @@ -52,6 +60,29 @@ struct nc_ndp_queue { struct ndp_v2_packethdr *hdr; struct ndp_v2_offsethdr *off; } v2; + + struct { + // DMA Calypte data and header buffer + struct nfb_comp *tx_hdr_buff; + struct nfb_comp *tx_data_buff; + + // Used to indicate the number of packets that are + // locked in the queue. It also means the number of free + // headers. + unsigned pkts_available; + uint32_t bytes_available; + unsigned pkts_to_send; + + uint32_t sdp; + uint32_t shp; + uint32_t data_ptr_mask; + uint32_t hdr_ptr_mask; + + // Packet descriptions + struct ndp_packet *packets; + // Buffer for headers + struct ndp_v3_packethdr *hdrs; + } v3; } u; int fd; diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index 5bfb7b4a..fcd331bf 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -5,6 +5,7 @@ * Copyright (C) 2018-2022 CESNET * Author(s): * Martin Spinler + * Vladislav Valek */ static inline int nc_ndp_v1_rx_lock(void *priv) @@ -229,11 +230,99 @@ static inline int nc_ndp_v2_rx_burst_put(void *priv) return nc_ndp_v2_rx_unlock(priv); } +static inline unsigned nc_ndp_v3_rx_lock(void *priv) +{ + int ret; + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + if ((ret = _ndp_queue_sync(q, &q->sync))) { + return ret; + } + + q->u.v3.pkts_available = (q->sync.hwptr - q->u.v3.shp) & (q->u.v3.hdr_ptr_mask); + + return 0; +} + +static inline int nc_ndp_v3_rx_unlock(void *priv) +{ + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + q->sync.swptr = q->u.v3.shp & (q->u.v3.hdr_ptr_mask); + return _ndp_queue_sync(q, &q->sync); +} + +static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *packets, unsigned count) +{ + unsigned i = 0; + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + struct ndp_v3_packethdr *hdr_base; + unsigned char *data_base; + + if (unlikely(q->u.v3.pkts_available < count)) { + nc_ndp_v3_rx_lock(q); + count = min(q->u.v3.pkts_available, count); + if (count == 0) + return 0; + } + + hdr_base = q->u.v3.hdrs + q->u.v3.shp; + data_base = q->buffer; + __builtin_prefetch(hdr_base); + __builtin_prefetch(data_base); + + for (i = 0; i < count; i++) { + unsigned packet_size; + unsigned header_size = 0; + struct ndp_v3_packethdr *hdr; + unsigned char *data; + + hdr = hdr_base + i; + + if (!hdr->valid) { + break; + } + + if (!(hdr->metadata & NDP_CALYPTE_METADATA_NOT_VALID)) + header_size = hdr->metadata & NDP_CALYPTE_METADATA_HDR_SIZE_MASK; + + packet_size = le16_to_cpu(hdr->frame_len) - header_size; + + data = data_base + hdr->frame_ptr * NDP_RX_CALYPTE_BLOCK_SIZE; + /* Assign pointer and length of header */ + packets[i].header = data; + packets[i].header_length = header_size; + + data += header_size; + + /* Assign pointer and length of data */ + packets[i].data = data; + packets[i].data_length = packet_size; + + hdr->valid = 0; + q->u.v3.sdp += (hdr->frame_len + (NDP_RX_CALYPTE_BLOCK_SIZE - 1)) & (~(NDP_RX_CALYPTE_BLOCK_SIZE -1)); + } + + q->u.v3.sdp &= q->u.v3.hdr_ptr_mask; + q->u.v3.shp = (q->u.v3.shp + count) & q->u.v3.hdr_ptr_mask; + q->u.v3.pkts_available -= count; + + return count; +} + +static inline int nc_ndp_v3_rx_burst_put(void *priv) +{ + return nc_ndp_v3_rx_unlock(priv); +} + static inline unsigned nc_ndp_rx_burst_get(void *priv, struct ndp_packet *packets, unsigned count) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->protocol == 2) { + if (q->protocol == 3) { + return nc_ndp_v3_rx_burst_get(priv, packets, count); + } else if (q->protocol == 2) { return nc_ndp_v2_rx_burst_get(priv, packets, count); } else if (q->protocol == 1) { return nc_ndp_v1_rx_burst_get(priv, packets, count); @@ -245,7 +334,9 @@ static inline void nc_ndp_rx_burst_put(void *priv) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->protocol == 2) { + if (q->protocol == 3) { + nc_ndp_v3_rx_unlock(priv); + } else if (q->protocol == 2) { nc_ndp_v2_rx_unlock(priv); } else if (q->protocol == 1) { nc_ndp_v1_rx_burst_put(priv); diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index 9a1ca416..fd599fd7 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -5,6 +5,7 @@ * Copyright (C) 2018-2022 CESNET * Author(s): * Martin Spinler + * Vladislav Valek */ #define NDP_TX_BURST_COPY_ATTEMPTS 1000 @@ -281,11 +282,173 @@ static inline int nc_ndp_v2_tx_burst_flush(void *priv) return 0; } +// Figure out, how many packets can be stored in a queue right now. +static inline void nc_ndp_v3_tx_lock(void *priv) +{ + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + signed offset; + int lock_valid = q->sync.swptr == q->sync.hwptr ? 0 : 1; + + // This assignment allows to determine the amount of free headers in the buffer + q->sync.swptr = (q->sync.hwptr - 1) & (q->u.v3.hdr_ptr_mask); + + if (_ndp_queue_sync(q, &q->sync)) + return; + + if (!lock_valid) { + offset = q->sync.hwptr - q->u.v3.shp; + + q->u.v3.shp += offset; + q->u.v3.hdrs += offset; + } + + q->u.v3.pkts_available = (q->sync.swptr - q->u.v3.shp) & (q->u.v3.hdr_ptr_mask); + q->u.v3.bytes_available = q->sync.size; +} + +static inline unsigned nc_ndp_v3_tx_burst_get(void *priv, struct ndp_packet *packets, unsigned count) +{ + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + unsigned i; + + // Pointer of buffer bases + unsigned char *data_base; + struct ndp_v3_packethdr *hdr_base; + + // Iterator pointers + uint32_t sdp_int; + + // All previously reserved packets need to be sent before new reservation takes place + if (unlikely(q->u.v3.pkts_to_send != 0)) + return 0; + + __builtin_prefetch(q->u.v3.hdrs); + + if (unlikely(q->u.v3.pkts_available < count)) { + // Figure out the current state of the queue in terms of its free space + nc_ndp_v3_tx_lock(q); + + if (unlikely(q->u.v3.pkts_available < count || count == 0)) + return 0; + } + + sdp_int = q->u.v3.sdp; + + data_base = q->buffer; + hdr_base = q->u.v3.hdrs; + + for (i = 0; i < count; i++) { + struct ndp_v3_packethdr *hdr; + unsigned packet_size; + unsigned header_size; + + hdr = hdr_base + i; + + header_size = packets[i].header_length; + packet_size = packets[i].data_length + header_size; + + if (unlikely(packet_size < q->frame_size_min)) { + /* Enlarge packets smaller than min size & clean remaining data */ + memset(data_base + sdp_int + header_size + packet_size, 0, q->frame_size_min - packet_size); + packet_size = q->frame_size_min; + } else if (unlikely(packet_size > q->frame_size_max)) { + /* Can't handle packets larger than max size */ + return 0; + } + + /* Write DMA TX header */ + hdr->metadata = 0; + hdr->frame_len = cpu_to_le16(packet_size); + hdr->frame_ptr = sdp_int & q->u.v3.data_ptr_mask; + + /* Set pointers, where user can write packet content */ + packets[i].header = data_base + sdp_int; + packets[i].data = data_base + sdp_int + header_size; + + // Ceil SDP to the multiple of NDP_TX_CALYPTE_BLOCK_SIZE + sdp_int = ((sdp_int + packet_size + (NDP_TX_CALYPTE_BLOCK_SIZE -1)) & (~(NDP_TX_CALYPTE_BLOCK_SIZE -1))); + } + + // For pointer synchronization + q->u.v3.hdrs += count; + q->u.v3.sdp = sdp_int & q->u.v3.data_ptr_mask; + q->u.v3.shp += count; + q->u.v3.pkts_available -= count; + + // For packet sending + q->u.v3.packets = packets; + q->u.v3.pkts_to_send += count; + return count; +} + +static inline int nc_ndp_v3_tx_burst_flush(void *priv) +{ + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + if (q->u.v3.shp >= (q->u.v3.hdr_ptr_mask +1)) { + q->u.v3.shp -= (q->u.v3.hdr_ptr_mask + 1); + q->u.v3.hdrs -= (q->u.v3.hdr_ptr_mask + 1); + } + + // Synchronize pointers after all packets in a burst have been sent + q->sync.swptr = q->u.v3.shp; + q->sync.hwptr = q->u.v3.shp; + q->u.v3.pkts_available = 0; + + if (_ndp_queue_sync(q, &q->sync)) + return -1; + + return 0; +} + +static inline int nc_ndp_v3_tx_burst_put(void *priv) +{ + struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + + unsigned i; + uint32_t frame_len_ceil; + struct ndp_packet *packet = q->u.v3.packets; + struct ndp_v3_packethdr *hdr = q->u.v3.hdrs - q->u.v3.pkts_to_send; + uint32_t shp = q->u.v3.shp - q->u.v3.pkts_to_send; + + + for (i = 0; i < q->u.v3.pkts_to_send; i++) { + + frame_len_ceil = (hdr[i].frame_len + (NDP_TX_CALYPTE_BLOCK_SIZE -1)) & (~(NDP_TX_CALYPTE_BLOCK_SIZE -1)); + + while (q->u.v3.bytes_available < frame_len_ceil) { + q->sync.hwptr = shp; + + if (_ndp_queue_sync(q, &q->sync)) + return -1; + + q->u.v3.bytes_available = q->sync.size; + } + + nfb_comp_write(q->u.v3.tx_data_buff, packet[i].header, hdr[i].frame_len, hdr[i].frame_ptr); + q->u.v3.bytes_available -= frame_len_ceil; + + + nfb_comp_write(q->u.v3.tx_hdr_buff, &hdr[i], 8, (uint64_t)shp*8); + // This below line needs to updated somewhere + shp = (shp + 1) & (q->u.v3.hdr_ptr_mask); + } + q->u.v3.packets -= q->u.v3.pkts_to_send; + q->u.v3.pkts_to_send = 0; + nc_ndp_v3_tx_burst_flush(priv); + + return 0; +} + static inline unsigned nc_ndp_tx_burst_get(void *priv, struct ndp_packet *packets, unsigned count) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->protocol == 2) { + if (q->protocol == 3) { + return nc_ndp_v3_tx_burst_get(priv, packets, count); + } else if (q->protocol == 2) { return nc_ndp_v2_tx_burst_get(priv, packets, count); } else if (q->protocol == 1) { return nc_ndp_v1_tx_burst_get(priv, packets, count); @@ -297,7 +460,9 @@ static inline void nc_ndp_tx_burst_put(void *priv) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->protocol == 2) { + if (q->protocol == 3) { + nc_ndp_v3_tx_burst_put(priv); + } else if (q->protocol == 2) { nc_ndp_v2_tx_burst_put(priv); } else if (q->protocol == 1) { nc_ndp_v1_tx_burst_put(priv); @@ -308,7 +473,9 @@ static inline void nc_ndp_tx_burst_flush(void *priv) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->protocol == 2) { + if (q->protocol == 3) { + nc_ndp_v3_tx_burst_flush(priv); + } else if (q->protocol == 2) { nc_ndp_v2_tx_burst_flush(priv); } else if (q->protocol == 1) { nc_ndp_v1_tx_burst_flush(priv); diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index ce0be3e6..bb7e3d3e 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -317,9 +317,11 @@ cdef class QueueManager: def __init__(self, nfb): compatibles = ([ + (NdpQueueRx, "cesnet,dma_ctrl_calypte_rx", 0), (NdpQueueRx, "netcope,dma_ctrl_ndp_rx", 0), (NdpQueueRx, "netcope,dma_ctrl_sze_rx", 0), ], [ + (NdpQueueTx, "cesnet,dma_ctrl_calypte_tx", 1), (NdpQueueTx, "netcope,dma_ctrl_ndp_tx", 1), (NdpQueueTx, "netcope,dma_ctrl_sze_tx", 1), ]) From 0556a2fde121b6aea7f8b7d10eb7d0da2b11425b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 17 Oct 2023 20:13:14 +0200 Subject: [PATCH 019/518] libnetcope/ndp: [FIX] uninitialized variable --- libnfb/include/netcope/ndp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 3710a48a..52ffd2e7 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -212,7 +212,7 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu int flags = 0; off_t mmap_offset; - size_t mmap_size; + size_t mmap_size = 0; struct ndp_queue_ops *ops = ndp_queue_get_ops(q->q); From 49c2c16268120a1f8e95d72bd036e5a61e013463 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 23 Oct 2023 17:10:10 +0200 Subject: [PATCH 020/518] pynfb - eth: [FIX] get_property instead of get_subnode was used for control-param subnode --- pynfb/nfb/eth.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pynfb/nfb/eth.py b/pynfb/nfb/eth.py index 797ed5e1..df043e5b 100644 --- a/pynfb/nfb/eth.py +++ b/pynfb/nfb/eth.py @@ -113,8 +113,7 @@ class PcsPma: def __init__(self, nfb, node): ctrl = nfb.fdt_get_phandle(node.get_property('control').value) - prop_ctrl_param = node.get_property('control-param') - ctrl_param = nfb.fdt_get_phandle(prop_ctrl_param.value) if prop_ctrl_param else None + ctrl_param = node.get_subnode('control-param') self.mdio = libnetcope.Mdio(nfb, ctrl, ctrl_param) # FIXME: Check and enable!!! self.mdio_portad = ctrl_param.get_property("dev").value if ctrl_param and ctrl_param.get_property("dev") else 0 From e9aab73d4f7966c47167b8f65b318e259ae6e675 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 23 Oct 2023 17:15:27 +0200 Subject: [PATCH 021/518] libnfb - mi: [FEATURE] prepare for MI bus debugging --- libnfb/src/nfb.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/libnfb/src/nfb.c b/libnfb/src/nfb.c index 00f7316c..4f2342ce 100644 --- a/libnfb/src/nfb.c +++ b/libnfb/src/nfb.c @@ -516,16 +516,46 @@ const struct nfb_device *nfb_comp_get_device(struct nfb_comp *comp) return comp->dev; } +//#define NFB_DEBUG_MI + +#ifdef NFB_DEBUG_MI +static void nfb_bus_mi_dump(const char *type, const void *buf, size_t nbyte, off_t offset) +{ + size_t i; + for (i = 0; i < nbyte; i++) { + if (i == 0) + fprintf(stderr, "libnfb: MI %s: % 4zdB -> [0x%08jx] |", type, nbyte, offset); + + fprintf(stderr, " %02x", ((unsigned char*)buf)[i]); + if (i % 4 == 3) + fprintf(stderr, " |"); + + if (i == nbyte - 1) + fprintf(stderr, "\n"); + else if (i % 16 == 15) + fprintf(stderr, "\nlibnfb: "); + } + +} +#endif + ssize_t nfb_comp_read(const struct nfb_comp *comp, void *buf, size_t nbyte, off_t offset) { + ssize_t ret; if (offset + nbyte > comp->size) return -1; if (comp->bus.type == NFB_BUS_TYPE_MI) { - return nfb_bus_mi_read(comp->bus.priv, buf, nbyte, offset + comp->base); + ret = nfb_bus_mi_read(comp->bus.priv, buf, nbyte, offset + comp->base); } else { - return comp->bus.ops.read(comp->bus.priv, buf, nbyte, offset + comp->base); + ret = comp->bus.ops.read(comp->bus.priv, buf, nbyte, offset + comp->base); } + +#ifdef NFB_DEBUG_MI + nfb_bus_mi_dump("Read ", buf, nbyte, offset); +#endif + + return ret; } ssize_t nfb_comp_write(const struct nfb_comp *comp, const void *buf, size_t nbyte, off_t offset) @@ -533,6 +563,10 @@ ssize_t nfb_comp_write(const struct nfb_comp *comp, const void *buf, size_t nbyt if (offset + nbyte > comp->size) return -1; +#ifdef NFB_DEBUG_MI + nfb_bus_mi_dump("Write", buf, nbyte, offset); +#endif + if (comp->bus.type == NFB_BUS_TYPE_MI) { return nfb_bus_mi_write(comp->bus.priv, buf, nbyte, offset + comp->base); } else { From affccd33836e62c11edede492686a946b7587ed0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 23 Oct 2023 11:10:28 +0200 Subject: [PATCH 022/518] libnetcope - dma_ctrl_ndp: [MAINTENANCE]: fix unnamed union warning --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 2 +- libnfb/include/netcope/dma_ctrl_ndp.h | 40 +++++++++++------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 3c567af6..86e86289 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -441,7 +441,7 @@ static uint64_t ndp_ctrl_medusa_tx_get_hwptr(struct ndp_channel *channel) desc = ctrl->desc_buffer_v + hdp; for (i = 0; i < count; i++) { - if (desc[i].type2.type == 2) + if (desc[i].d.type2.type == 2) free_hdrs++; } diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index f8b6e4e1..02c2c74c 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -87,7 +87,7 @@ struct nc_ndp_desc { int next0 : 1; unsigned type : 2; } type2; - }; + } d; } __attribute__((__packed__)); struct nc_calypte_hdr { @@ -131,9 +131,9 @@ static inline struct nc_ndp_desc nc_ndp_rx_desc0(uint64_t phys) { struct nc_ndp_desc desc; - desc.type0.phys = phys >> 30; - desc.type0.rsvd = 0; - desc.type0.type = 0; + desc.d.type0.phys = phys >> 30; + desc.d.type0.rsvd = 0; + desc.d.type0.type = 0; return desc; } @@ -142,14 +142,14 @@ static inline struct nc_ndp_desc nc_ndp_rx_desc2(uint64_t phys, uint16_t len, in { struct nc_ndp_desc desc; - desc.type2.type = 2; - desc.type2.phys = phys; - desc.type2.rsvd0 = 0; - desc.type2.int0 = 0; - desc.type2.len = len; - desc.type2.meta = 0; - desc.type2.shrd0 = 0; - desc.type2.next0 = next; + desc.d.type2.type = 2; + desc.d.type2.phys = phys; + desc.d.type2.rsvd0 = 0; + desc.d.type2.int0 = 0; + desc.d.type2.len = len; + desc.d.type2.meta = 0; + desc.d.type2.shrd0 = 0; + desc.d.type2.next0 = next; return desc; } @@ -163,14 +163,14 @@ static inline struct nc_ndp_desc nc_ndp_tx_desc2(uint64_t phys, uint16_t len, ui { struct nc_ndp_desc desc; - desc.type2.type = 2; - desc.type2.phys = phys; - desc.type2.rsvd0 = 0; - desc.type2.int0 = 0; - desc.type2.len = len; - desc.type2.meta = meta; - desc.type2.shrd0 = 0; - desc.type2.next0 = next; + desc.d.type2.type = 2; + desc.d.type2.phys = phys; + desc.d.type2.rsvd0 = 0; + desc.d.type2.int0 = 0; + desc.d.type2.len = len; + desc.d.type2.meta = meta; + desc.d.type2.shrd0 = 0; + desc.d.type2.next0 = next; return desc; } From 5c124d8d41c9cb1ba5591937eaa45a1a5e66f950 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 2 Nov 2023 10:35:53 +0100 Subject: [PATCH 023/518] drivers - PMCI: [HOTFIX] disable module if kernel doesn't have read_poll_timeout --- drivers/configure.ac | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index dd940c97..0e35e475 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -88,11 +88,13 @@ KERNEL_TRY_COMPILE([[ void test(void) {eth_hw_addr_set(NULL, NULL);} ]],[AC_DEFINE([CONFIG_HAVE_ETH_HW_ADDR_SET], [1], [Define if kernel have eth_hw_addr_set]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has regmap_reg_range]) +AC_MSG_CHECKING([whether kernel has regmap_reg_range and read_poll_timeout]) KERNEL_TRY_COMPILE([[ #include +#include static const struct regmap_range regmap_range_test[] = {regmap_reg_range(0,0)}; -]],[AC_DEFINE([CONFIG_NFB_ENABLE_PMCI], [1], [Define if kernel have regmap_reg_range]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +int trd(off_t a) {return 0;} void test(void) {int ret; read_poll_timeout(trd, ret, (!ret), 1, 2, false, 0);} +]],[AC_DEFINE([CONFIG_NFB_ENABLE_PMCI], [1], [Define if kernel have regmap_reg_range and read_poll_timeout]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) AC_MSG_CHECKING([whether kernel has devm_kstrdup_const]) KERNEL_TRY_COMPILE([[ From 49bd7a174240541b23c69af1da724e08fd11060d Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Fri, 27 Oct 2023 14:03:16 +0200 Subject: [PATCH 024/518] libnfb: [FIX] Fix PMA loopback operation for Intel E-Tile --- libnfb/include/netcope/mdio.h | 257 ++++++++++++++++++++++------------ 1 file changed, 171 insertions(+), 86 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index f9d0a258..ee3fd039 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -265,6 +265,7 @@ static inline void nc_mdio_etile_config(struct nc_mdio *mdio) /* The E-Tile EHIP doesn't contains configuration registers, thus */ /* the number of lanes&speed are determined by the MDIO register 1.7 */ val = mdio->mdio_read(comp, 0, 1, 7); + /* TBD: number of lanes can be read from PMA address 0x40010 */ if (val <= 0x1f) { /* 10GBASE */ mdio->pma_lanes = 1; mdio->speed = 10; @@ -921,23 +922,24 @@ static inline void nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int p uint32_t ret; int retries = 0; int locked = 0; + int sent = 0; /* Lock the attribute access interface */ while (!locked) { locked = nfb_comp_lock(comp, ATTR_IFC); } - /* Set PMA attribute code address and data */ - nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_VAL_L, code_val_l); - nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_VAL_H, code_val_h); - nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_ADDR_L, code_addr_l); - nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_ADDR_H, code_addr_h); - /* Issue PMA attribute code request */ - nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_REQ, 1); - /* Verify that PMA attribute code request has been sent */ - ret = nc_mdio_dmap_drp_read(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L); - if (((ret >> 7) & 0x01) != 1) { - return; + while (!sent) { + /* Set PMA attribute code address and data */ + nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_VAL_L, code_val_l); + nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_VAL_H, code_val_h); + nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_ADDR_L, code_addr_l); + nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_ADDR_H, code_addr_h); + /* Issue PMA attribute code request */ + nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_REQ, 1); + /* Verify that PMA attribute code request has been sent */ + sent = ((nc_mdio_dmap_drp_read(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L) >> 7) & 0x01); } /* Wait until PMA attribute code request is completed */ + retries = 0; do { ret = nc_mdio_dmap_drp_read(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_H); } while (((ret & 0x01) != 0) && (++retries < 10000)); @@ -962,82 +964,10 @@ static inline uint16_t nc_mdio_etile_pma_attribute_read(struct nc_mdio *mdio, in /* Perform RX+TX reset of E-tile Ethernet PHY */ static inline void nc_mdio_etile_reset(struct nfb_comp *comp, int prtad) { - /* see https://www.intel.com/content/www/us/en/docs/programmable/683468/23-2-24-1-0/phy-registers-67394.html */ - int locked = 0; - while (!locked) { - locked = nfb_comp_lock(comp, PCS_IFC); /* Lock access to PCS registers (reset active) */ - } + /* see https://www.intel.com/content/www/us/en/docs/programmable/683468/23-2/phy-configuration.html */ + /* see https://www.intel.com/content/www/us/en/docs/programmable/683468/23-2/reset.html */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // soft rx rst + soft tx rst nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x0); - nfb_comp_unlock(comp, PCS_IFC); -} - -/* Reset Etile RX Equalization parameters */ -static inline void nc_mdio_etile_reset_rxeq(struct nc_mdio *mdio, int prtad, int lane) -{ - /* see: https://www.intel.com/content/www/us/en/docs/programmable/683723/current/resetting-the-rx-equalization.html */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0xffff); /* reset RX DFE taps */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0d00); /* reset RF_P2 */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0000); - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0d01); /* reset RF_P1 */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0000); - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0d02); /* reset RF_P0 */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0000); - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x00ec, 0x0012); /* Load attributes into receiver */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x00ec, 0x0015); /* Load attributes into receiver */ -} - -/* Perform RX initial adaptation. PMA serial loopback must be active prior to this function usage */ -static inline void nc_mdio_etile_rxadapt(struct nc_mdio *mdio, int prtad, int lane) -{ - uint32_t ret; - int retries = 0; - - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0002, 0x0325); /* Enable PRBS data */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0x0001); /* Enable initial coarse adaptation */ - do { - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while (((ret & 0xff) != 0x80) && (++retries < 100000)); - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0002, 0x03ff); /* Disable PRBS */ -} - -/* Enable RX mission mode (= continuous) equalization. Initial adaptation should perform prior to using this function */ -static inline void nc_mdio_etile_rxrun(struct nc_mdio *mdio, int prtad, int lane) -{ - uint32_t ret; - int retries = 0; - - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0x0006); /* Run continuous adaptive equalization */ - do { - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while (((ret & 0xff) != 0xe2) && (++retries < 100000)); -} - -static inline void nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) -{ - int i; - struct nfb_comp *comp = nfb_user_to_comp(mdio); - int locked = 0; - - while (!locked) { - locked = nfb_comp_lock(comp, PCS_IFC); /* Lock access to PCS registers (reset active) */ - } - nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); /* Assert EHIP rx+tx soft reset */ - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_dmap_drp_write(comp, prtad, i+1, 0x400e2, 0x55); /* rx+tx PMA interface reset */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0301); /* Enable the loopback */ - nc_mdio_etile_reset_rxeq(mdio, prtad, i); /* Reset RX EQ */ - nc_mdio_etile_rxadapt(mdio, prtad, i); /* Run initial adaptation */ - if (!enable) { - nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0300); /* Disable loopback */ - nc_mdio_etile_rxrun(mdio, prtad, i); /* Run continuous equalization */ - } - nc_mdio_dmap_drp_write(comp, prtad, i+1, 0x400e2, 0x0); /* Deassert PMA interface reset */ - } - nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x0); // Deassert EHIP resets - nfb_comp_unlock(comp, PCS_IFC); } static inline void nc_mdio_etile_rsfec_off(struct nfb_comp *comp, int prtad, int lanes) @@ -1117,7 +1047,6 @@ static inline void nc_mdio_etile_rsfec_on(struct nfb_comp *comp, int prtad, int static inline void nc_mdio_fixup_etile_set_mode(struct nc_mdio *mdio, int prtad, uint16_t val) { struct nfb_comp *comp = nfb_user_to_comp(mdio); - if ((val == 0x2a) || (val == 0x2b)) { /* 100GBASE-LR4/ER4 - turn the FEC off */ nc_mdio_etile_rsfec_off(comp, prtad, 4); @@ -1129,6 +1058,162 @@ static inline void nc_mdio_fixup_etile_set_mode(struct nc_mdio *mdio, int prtad, mdio->mdio_write(comp, prtad, 1, 7, val); } +/* Reset Etile RX Equalization parameters */ +static inline void nc_mdio_etile_reset_rxeq(struct nc_mdio *mdio, int prtad, int lane) +{ + /* see: https://www.intel.com/content/www/us/en/docs/programmable/683723/current/resetting-the-rx-equalization.html */ + uint16_t ret; + int retries = 0; + /* Try to stop the continuous adaptation (call one-shot adapt) */ + do { + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0x0002); + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); + } while ((ret != 0x000a) && (++retries < 100000)); + /* Read Receiver Tuning Parameters */ + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); + retries = 0; + do { + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0xffff); /* reset RX DFE taps */ + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); + } while ((ret != 0x000a) && (++retries < 100000)); + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0d00); /* reset RF_P2 */ + retries = 0; + do { + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0000); + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); + } while ((ret != 0x002c) && (++retries < 100000)); + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0d01); /* reset RF_P1 */ + retries = 0; + do { + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0000); + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); + } while ((ret != 0x002c) && (++retries < 100000)); + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0d02); /* reset RF_P0 */ + retries = 0; + do { + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0000); + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); + } while ((ret != 0x002c) && (++retries < 100000)); + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x00ec, 0x0012); /* Load attributes into receiver */ + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x00ec, 0x0015); /* Load attributes into receiver */ + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); +} + +static inline void nc_mdio_etile_initadapt_start(struct nc_mdio *mdio, int prtad, int lane) +{ + /* Set Initial Adaptation Effort Level to full effort */ + // set readback [rcfg_etile $phy $channel 0x2C 0x118 0] + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0118); /* */ + //set readback [rcfg_etile $phy $channel 0x6C 0x01 0] + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0001); /* */ + //set readback [rcfg_etile $phy $channel 0x0A 0x01 0] + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0x0001); /* Run initial adaptive equalization */ +} + +static inline void nc_mdio_etile_initadapt_wait(struct nc_mdio *mdio, int prtad, int lane) +{ + uint16_t ret; + int retries = 0; + + /* Wait until the adaptation finishes */ + do { + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); + } while (((ret & 0xff) != 0x80) && (++retries < 100000)); +} + +/* Enable RX mission mode (= continuous) equalization. Initial adaptation should perform prior to using this function */ +static inline void nc_mdio_etile_rxrun(struct nc_mdio *mdio, int prtad, int lane) +{ + uint32_t ret; + int retries = 0; + + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0x0006); /* Run continuous adaptive equalization */ + do { + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); + ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); + } while (((ret & 0xff) != 0xe2) && (++retries < 100000)); +} + +/* Perform PMA analog reset on selected lane and load initial configuration */ +static inline void nc_mdio_etile_areset(struct nfb_comp *comp, int prtad, int lane) +{ + const uint32_t DRP_PAGE = lane + 1; + uint32_t ret; + int retries = 0; + + /* See https://www.intel.com/content/www/us/en/docs/programmable/683723/current/pma-analog-reset-92001.html */ + /* See https://www.intel.com/content/www/us/en/docs/programmable/683723/current/reconfiguring-pma-settings.html */ + nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x200, 0x00); /* Write 0x200[7:0] = 0x00. */ + nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x201, 0x00); /* Write 0x201[7:0] = 0x00. */ + nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x202, 0x00); /* Write 0x202[7:0] = 0x00. */ + nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x203, 0x81); /* Write 0x203[7:0] = 0x81. */ + /* Read 0x207 until it becomes 0x80. This indicates that the operation completed successfully. */ + do { + ret = nc_mdio_dmap_drp_read(comp, prtad, DRP_PAGE, 0x207); /* Wait until the PMA is loaded */ + } while (((ret & 0xff) != 0x80) && (++retries < 100000)); + /* Reload PMA settings (call PMA attribute sequencer) on all lanes */ + retries = 0; + nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x91, 0x01); /* Load initial PMA configuration */ + do { + ret = nc_mdio_dmap_drp_read(comp, prtad, DRP_PAGE, 0x91); /* Wait until the PMA is loaded */ + } while (((ret & 0x01) != 0x0) && (++retries < 100000)); +} + +static inline void nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) +{ + /* See https://www.intel.com/content/www/us/en/docs/programmable/683468/23-2/ethernet-adaptation-flow-with-non-external.html */ + int i; + struct nfb_comp *comp = nfb_user_to_comp(mdio); + int locked = 0; + uint32_t ret; + + while (!locked) { + locked = nfb_comp_lock(comp, PCS_IFC); /* Lock access to PCS registers (reset active) */ + } + /* 1. Assert RX/TX reset ports of the EHIP */ + nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // soft rx rst + soft tx rst + /* 2 + 3. Trigger PMA analog reset and reload PMA settings */ + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_areset(comp, prtad, i); + } + /* 4. Apply CSR reset */ + nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x7); // eio_sys_rst set + nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // eio_sys_rst clear + /* 5. Deassert TX reset */ + nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x4); // soft rx rst only + /* 6. skipped (PMA configuration not used) */ + /* 7a. Enable loopback on all channels */ + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_reset_rxeq(mdio, prtad, i); /* Reset the RX EQ */ + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0301); /* Enable the loopback */ + } + /* 7b. Start the initial adaptation on all channels */ + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_initadapt_start(mdio, prtad, i); + } + /* 7c. Check adaptation status on all channels */ + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_initadapt_wait(mdio, prtad, i); + } + /* 8-11. In mission mode, run the continuous equalization */ + if (!enable) { + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0300); /* Disable the loopback */ + nc_mdio_etile_rxrun(mdio, prtad, i); /* Run the eq */ + } + } + /* 12. Deassert RX reset ports of the EHIP (using mgmt) */ + nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x0); + /* Get current PMA mode from mgmt */ + ret = mdio->mdio_read(comp, prtad, 1, 7); + /* Apply the mode (turn the RS-FEC on or off) */ + nc_mdio_fixup_etile_set_mode(mdio, prtad, ret); + nfb_comp_unlock(comp, PCS_IFC); +} + static inline void nc_mdio_close(struct nc_mdio *m) { nfb_comp_close(nfb_user_to_comp(m)); From 677814b75178567dc5995a017088e5953353ed63 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 3 Nov 2023 08:38:31 +0100 Subject: [PATCH 025/518] pynfb - Mdio: [BREAKING] make prtad parameter as optional --- pynfb/nfb/eth.py | 4 ++-- pynfb/nfb/libnetcope.pyx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pynfb/nfb/eth.py b/pynfb/nfb/eth.py index df043e5b..f73fba17 100644 --- a/pynfb/nfb/eth.py +++ b/pynfb/nfb/eth.py @@ -118,8 +118,8 @@ def __init__(self, nfb, node): # FIXME: Check and enable!!! self.mdio_portad = ctrl_param.get_property("dev").value if ctrl_param and ctrl_param.get_property("dev") else 0 - def _read(self, dev, reg): return self.mdio.read(self.mdio_portad, dev, reg) - def _write(self, dev, reg, val): return self.mdio.write(self.mdio_portad, dev, reg, val) + def _read(self, dev, reg): return self.mdio.read(dev, reg, self.mdio_portad) + def _write(self, dev, reg, val): return self.mdio.write(dev, reg, val, self.mdio_portad) def _set_bit(self, dev, reg, bit, value=True): oldval = self._read(dev, reg) diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index c271f638..31122f15 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -169,10 +169,10 @@ cdef class Mdio: if self._mdio is not NULL: nc_mdio_close(self._mdio) - def read(self, prtad: int, devad: int, reg: int): + def read(self, devad: int, reg: int, prtad: int=0): return nc_mdio_read(self._mdio, prtad, devad, reg) - def write(self, prtad: int, devad: int, reg: int, val: int): + def write(self, devad: int, reg: int, val: int, prtad: int=0): nc_mdio_write(self._mdio, prtad, devad, reg, val) cdef class I2c: From ed659194aaa62d4905e4eec02eb7d0453c05db53 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 3 Nov 2023 08:40:32 +0100 Subject: [PATCH 026/518] pynfb: [FIX] examples --- pynfb/examples/00-quick-reference.py | 3 ++- pynfb/examples/01-basics.py | 4 ++-- pynfb/examples/04-mi-comp-wrap.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pynfb/examples/00-quick-reference.py b/pynfb/examples/00-quick-reference.py index 2f62f09c..a14528f8 100644 --- a/pynfb/examples/00-quick-reference.py +++ b/pynfb/examples/00-quick-reference.py @@ -71,7 +71,8 @@ val = eth.pmd.vendor_name eth.pcspma.mdio.write(1, 0, 1) -val = eth.pmd.mdio.read(1, 0) +if hasattr(eth.pmd, 'i2c'): + val = eth.pmd.i2c.read_reg(1, 0) # 3.C Aggregated Ethernet ports manipulation assert eth.link == eth.rxmac.link diff --git a/pynfb/examples/01-basics.py b/pynfb/examples/01-basics.py index a21c347c..f49a8181 100644 --- a/pynfb/examples/01-basics.py +++ b/pynfb/examples/01-basics.py @@ -51,9 +51,9 @@ # use fdt node directly comp = dev.comp_open(node) # use compatible string, default index of compatible component in DT is 0 -comp = dev.comp_open("netcope,idcomp") +comp = dev.comp_open("cesnet,ofm,mi_test_space") # use specific index of compatible component in DT -comp = dev.comp_open("netcope,idcomp", 0) +comp = dev.comp_open("cesnet,ofm,mi_test_space", 0) # write access diff --git a/pynfb/examples/04-mi-comp-wrap.py b/pynfb/examples/04-mi-comp-wrap.py index 0417b836..887f9339 100644 --- a/pynfb/examples/04-mi-comp-wrap.py +++ b/pynfb/examples/04-mi-comp-wrap.py @@ -8,7 +8,7 @@ class IdComp(nfb.BaseComp): - DT_COMPATIBLE = "netcope,idcomp" + DT_COMPATIBLE = "cesnet,ofm,mi_test_space" # MI registers addresses _REG_TEST = 0 From e00d215d4ceab808d27f8b5fb94c62a0b77abbc3 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 9 Nov 2023 08:08:08 +0100 Subject: [PATCH 027/518] drivers - NDP: [FEATURE] add ndp_ctrl_buffer_size module parameter This parameter allows user to set buffer size for one packet, which affects maximal size of RX/TX packet transmissible over NDP. --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 19 ++++++++++++++++--- drivers/kernel/drivers/nfb/ndp/ndp.h | 2 ++ drivers/kernel/drivers/nfb/ndp/ring.c | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 86e86289..5991fdc4 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -41,7 +41,7 @@ typedef uint64_t ndp_offset_t; /* Size of buffer for one packet in ring */ -static const int buffer_size = 4096; +static int buffer_size = 4096; struct ndp_ctrl { struct nc_ndp_ctrl c; @@ -728,12 +728,22 @@ static int ndp_ctrl_medusa_attach_ring(struct ndp_channel *channel) struct device *dev = channel->ring.dev; + const int min_buffer_items = PAGE_SIZE / min(NDP_CTRL_RX_DESC_SIZE, NDP_CTRL_RX_NDP_HDR_SIZE); + if (channel->ring.size == 0) return -EINVAL; + if (buffer_size == 0 || !ispow2(buffer_size)) { + dev_err(ctrl->nfb->dev, "NDP queue %s: ndp_ctrl_buffer_size value must be power of two, but is %d.\n", + dev_name(&channel->dev), buffer_size); + return -EINVAL; + } + ctrl->desc_count = channel->ring.size / buffer_size; - if (ctrl->desc_count * min(NDP_CTRL_RX_DESC_SIZE, NDP_CTRL_RX_NDP_HDR_SIZE) < PAGE_SIZE) { - /* Can't do shadow-map for this ring size */ + if (ctrl->desc_count < min_buffer_items) { + /* Can't do shadow-map for this desc/hdr ring size */ + dev_err(ctrl->nfb->dev, "NDP queue %s: descriptor buffer size must be at least %d items, but is %d.\n", + dev_name(&channel->dev), min_buffer_items, ctrl->desc_count); return -EINVAL; } @@ -1171,3 +1181,6 @@ struct ndp_channel *ndp_ctrl_v3_create_tx(struct ndp *ndp, int index, int node_o struct ndp_channel_id id = {.index = index, .type = NDP_CHANNEL_TYPE_TX}; return ndp_ctrl_create(ndp, id, ndp_ctrl_attr_tx_groups, &ndp_ctrl_calypte_tx_ops, node_offset); } + +module_param_cb(ndp_ctrl_buffer_size, &ndp_param_size_ops, &buffer_size, S_IRUGO); +MODULE_PARM_DESC(ndp_ctrl_buffer_size, "Size of buffer for one packet in NDP ring (max size of RX/TX packet) [4096]"); diff --git a/drivers/kernel/drivers/nfb/ndp/ndp.h b/drivers/kernel/drivers/nfb/ndp/ndp.h index 5a77b551..6be4fe18 100644 --- a/drivers/kernel/drivers/nfb/ndp/ndp.h +++ b/drivers/kernel/drivers/nfb/ndp/ndp.h @@ -193,6 +193,8 @@ int ndp_ring_mmap(struct vm_area_struct *vma, unsigned long offset, unsigned lon ssize_t ndp_channel_get_ring_size(struct device *dev, struct device_attribute *attr, char *buf); ssize_t ndp_channel_set_ring_size(struct device *dev, struct device_attribute *attr, const char *buf, size_t size); +extern const struct kernel_param_ops ndp_param_size_ops; + /* channel.c */ void ndp_channel_init(struct ndp_channel *channel, struct ndp_channel_id); int ndp_channel_add(struct ndp_channel *channel, struct ndp *ndp, uint32_t phandle); diff --git a/drivers/kernel/drivers/nfb/ndp/ring.c b/drivers/kernel/drivers/nfb/ndp/ring.c index 9fdfec1c..0b43fa67 100644 --- a/drivers/kernel/drivers/nfb/ndp/ring.c +++ b/drivers/kernel/drivers/nfb/ndp/ring.c @@ -338,7 +338,7 @@ static int ndp_param_size_set(const char *val, const struct kernel_param *kp) return 0; } -static const struct kernel_param_ops ndp_param_size_ops = { +const struct kernel_param_ops ndp_param_size_ops = { .set = ndp_param_size_set, .get = param_get_int, }; From 2292d2a2dee0678cbf9c93ecb4036baa294fd821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Ko=C5=A1a=C5=99?= Date: Mon, 13 Nov 2023 16:01:17 +0100 Subject: [PATCH 028/518] libnfb: Check err_code of fpga_image_status during fpga image loading via Intel BMC If error during loading FPGA image happened, err_code is set and progress is set to FPGA_IMAGE_PROG_IDLE in fpga_image_status. The value of err_code was not checked in libnfb function nfb_fw_load_fpga_image_load(). Therefore, in case of loading error the function still returned success. --- libnfb/src/boot/boot.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libnfb/src/boot/boot.c b/libnfb/src/boot/boot.c index 8f7b0d68..75f404e1 100644 --- a/libnfb/src/boot/boot.c +++ b/libnfb/src/boot/boot.c @@ -361,6 +361,10 @@ int nfb_fw_load_fpga_image_load(const struct nfb_device *dev, void *data, size_t ret = errno; goto err_ioctl_status; } + if (fs.err_code != 0) { + ret = fs.err_code; + goto err_ioctl_status; + } if (flags & NFB_FW_LOAD_FLAG_VERBOSE) { if (prev_progress != fs.progress) { if (text) { From bcca1ef6c8a8a353e29638c08fc45264195be625 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 14 Nov 2023 07:38:59 +0100 Subject: [PATCH 029/518] bump version to 6.20.0 --- Changelog | 6 ++++++ VERSION | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 52b2a28e..b1fba761 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,9 @@ +* Tue Nov 14 2023 Martin Spinler - 6.20.0-1 +- [FEATURE] base support for DMA Calypte controllers +- [BUGFIX] fixes E-Tile loopback operation +- [BUGFIX] better booting experience on N6010 card +- [BUGFIX] fixed some issues in Python NFB module + * Wed Oct 18 2023 Martin Spinler - 6.19.5-1 - [BUGFIX] fixed flashing of N6010 card on newer kernels - [BUGFIX] correctly decode control / status register in nfb-dma diff --git a/VERSION b/VERSION index 0a61a6d5..a7c176ac 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.19.5 +6.20.0 From 2481b30456d973e05857a2b0a1231bf8256fe24b Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Tue, 21 Nov 2023 09:06:45 +0100 Subject: [PATCH 030/518] doc: [FEAT] Add PCS remote loopback info into the nfb-eth doc --- doc/tools/nfb-eth.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/tools/nfb-eth.rst b/doc/tools/nfb-eth.rst index 995e2dd9..8b4d6c14 100644 --- a/doc/tools/nfb-eth.rst +++ b/doc/tools/nfb-eth.rst @@ -19,17 +19,17 @@ This is necessary especially for TX as the DMA/application core typically get st The tool can configure the maximum and minimum allowed packet length (**-L** and **-l** arguments) and MAC address based filtration (**-M**: *add*, *remove*, *show*, *clear, *fill* commands operates on MAC address table, *normal* (unicast), *broadcast*, *multicast*, and *promiscuous* sets the required mode). -PMA section -~~~~~~~~~~~ +PMA/PCS section +~~~~~~~~~~~~~~~ The **-P** argument is intended to configure Ethernet modes. -If no command is entered, PCS/PMA status is printed, including PMA type, speed and link status. +If no command is entered, PMA and PCS status is printed, including PMA type, speed and link status. Currently used PMA type can be configured with **-c** argument whereas the exact PMA identification string must be entered. List of PMA types can vary with used firmware/hardware and can be obtained in verbose output (**-v** argument), -together with list of PMA features. +together with list of PMA and PCS features. -The PMA features that can be activated with **-c** argument as well. +The PMA/PCS features that can be activated with **-c** argument as well. However the feature can be activated and deactivated with *+* or *-* prefixes of its name. For example: @@ -37,6 +37,7 @@ For example: - ``nfb-eth -Pv`` prints all supported PMA types/modes and features, - ``nfb-eth -Pc 100GBASE-LR4`` sets the PMA to 100GBASE-LR4 type, - ``nfb-eth -Pc "+PMA local loopback"`` enables local loopback feature on all PMAs. +- ``nfb-eth -Pc -i 0 "+PCS reverse loopback"`` enables remote loopback feature on the first PCS. Transceiver section ~~~~~~~~~~~~~~~~~~~ From 3467093b0637a32d293d63fe617d0f6af63b3178 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Wed, 22 Nov 2023 21:03:50 +0100 Subject: [PATCH 031/518] libnfb: [FIX] Fix RX EQ adaptation on return from loopback to mission mode on E-Tile; Code cleanup --- libnfb/include/netcope/mdio.h | 107 ++++++++++------------------------ 1 file changed, 32 insertions(+), 75 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index ee3fd039..f92cd7fe 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -684,6 +684,10 @@ static inline void nc_mdio_fixup_ftile_set_loopback(struct nc_mdio *mdio, int pr /* ~~~~[ Intel E-Tile ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #define ETILE_RSFEC_PAGE 9 +/* Adaptation modes */ +#define ETILE_ADAPT_MODE_INITIAL 0x1 +#define ETILE_ADAPT_MODE_ONESHOT 0x2 +#define ETILE_ADAPT_MODE_CONTINUOUS 0x6 /* 32-bit read operation from the RS-FEC registers */ static inline uint32_t nc_mdio_etile_rsfec_read(struct nfb_comp *comp, int prtad, uint32_t addr) @@ -927,6 +931,8 @@ static inline void nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int p while (!locked) { locked = nfb_comp_lock(comp, ATTR_IFC); } + /* Clear PMA attribute code request sent flag */ + nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L, 0x80); while (!sent) { /* Set PMA attribute code address and data */ nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_VAL_L, code_val_l); @@ -1058,61 +1064,17 @@ static inline void nc_mdio_fixup_etile_set_mode(struct nc_mdio *mdio, int prtad, mdio->mdio_write(comp, prtad, 1, 7, val); } -/* Reset Etile RX Equalization parameters */ -static inline void nc_mdio_etile_reset_rxeq(struct nc_mdio *mdio, int prtad, int lane) +/* Starts PMA adaptation on a lane. */ +/* Adaptation mode: 0x1 - initial; 0x2 = One shot; 0x6 = continuous (mission) */ +static inline void nc_mdio_etile_adapt_start(struct nc_mdio *mdio, int prtad, int lane, uint16_t mode) { - /* see: https://www.intel.com/content/www/us/en/docs/programmable/683723/current/resetting-the-rx-equalization.html */ - uint16_t ret; - int retries = 0; - /* Try to stop the continuous adaptation (call one-shot adapt) */ - do { - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0x0002); - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while ((ret != 0x000a) && (++retries < 100000)); - /* Read Receiver Tuning Parameters */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - retries = 0; - do { - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0xffff); /* reset RX DFE taps */ - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while ((ret != 0x000a) && (++retries < 100000)); - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0d00); /* reset RF_P2 */ - retries = 0; - do { - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0000); - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while ((ret != 0x002c) && (++retries < 100000)); - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0d01); /* reset RF_P1 */ - retries = 0; - do { - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0000); - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while ((ret != 0x002c) && (++retries < 100000)); - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0d02); /* reset RF_P0 */ - retries = 0; - do { - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0000); - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while ((ret != 0x002c) && (++retries < 100000)); - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x00ec, 0x0012); /* Load attributes into receiver */ - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x00ec, 0x0015); /* Load attributes into receiver */ - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); -} - -static inline void nc_mdio_etile_initadapt_start(struct nc_mdio *mdio, int prtad, int lane) -{ - /* Set Initial Adaptation Effort Level to full effort */ - // set readback [rcfg_etile $phy $channel 0x2C 0x118 0] + /* Set Adaptation Effort Level to full effort */ nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0118); /* */ - //set readback [rcfg_etile $phy $channel 0x6C 0x01 0] nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0001); /* */ - //set readback [rcfg_etile $phy $channel 0x0A 0x01 0] - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0x0001); /* Run initial adaptive equalization */ + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, mode); /* Run the adaptation */ } -static inline void nc_mdio_etile_initadapt_wait(struct nc_mdio *mdio, int prtad, int lane) +static inline void nc_mdio_etile_adapt_wait(struct nc_mdio *mdio, int prtad, int lane, uint8_t result) { uint16_t ret; int retries = 0; @@ -1121,20 +1083,7 @@ static inline void nc_mdio_etile_initadapt_wait(struct nc_mdio *mdio, int prtad, do { nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while (((ret & 0xff) != 0x80) && (++retries < 100000)); -} - -/* Enable RX mission mode (= continuous) equalization. Initial adaptation should perform prior to using this function */ -static inline void nc_mdio_etile_rxrun(struct nc_mdio *mdio, int prtad, int lane) -{ - uint32_t ret; - int retries = 0; - - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, 0x0006); /* Run continuous adaptive equalization */ - do { - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); - ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while (((ret & 0xff) != 0xe2) && (++retries < 100000)); + } while (((ret & 0xff) != result) && (++retries < 100000)); } /* Perform PMA analog reset on selected lane and load initial configuration */ @@ -1168,6 +1117,7 @@ static inline void nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int pr int i; struct nfb_comp *comp = nfb_user_to_comp(mdio); int locked = 0; + int retries = 0; uint32_t ret; while (!locked) { @@ -1182,27 +1132,34 @@ static inline void nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int pr /* 4. Apply CSR reset */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x7); // eio_sys_rst set nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // eio_sys_rst clear - /* 5. Deassert TX reset */ + /* 5a. Deassert TX reset */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x4); // soft rx rst only + /* 5b. Wait for TX ready */ + do { + ret = nc_mdio_dmap_drp_read(comp, prtad, 0, 0x322); + } while (((ret & 0x01) != 0x1) && (++retries < 100000)); /* 6. skipped (PMA configuration not used) */ - /* 7a. Enable loopback on all channels */ + /* 7a. Enable loopback and start the initial adaptation on all channels */ for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_reset_rxeq(mdio, prtad, i); /* Reset the RX EQ */ nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0301); /* Enable the loopback */ + nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL); } - /* 7b. Start the initial adaptation on all channels */ - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_initadapt_start(mdio, prtad, i); - } - /* 7c. Check adaptation status on all channels */ + /* 7b. Check adaptation status on all channels */ for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_initadapt_wait(mdio, prtad, i); + nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80); } - /* 8-11. In mission mode, run the continuous equalization */ + /* 8-11. In mission mode, run the initial and continuous equalization */ if (!enable) { for (i = 0; i < mdio->pma_lanes; i++) { nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0300); /* Disable the loopback */ - nc_mdio_etile_rxrun(mdio, prtad, i); /* Run the eq */ + nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL); /* Start the initial adaptation */ + } + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80); /* Check initial adaptation status */ + nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_CONTINUOUS); /* Start the continuous adaptation */ + } + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_adapt_wait(mdio, prtad, i, 0xE2); /* Check continuous adaptation status */ } } /* 12. Deassert RX reset ports of the EHIP (using mgmt) */ From 0bf6db8f32e289cdd0c9c998405390687790076a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 16 Nov 2023 09:58:12 +0100 Subject: [PATCH 032/518] pynfb: [FIX] remove cyclic reference to Nfb by NfbDeviceHandle class --- pynfb/nfb/libnetcope.pyx | 31 ++++++++++++++++++------- pynfb/nfb/libnfb.pxd | 8 +++++-- pynfb/nfb/libnfb.pyx | 49 ++++++++++++++++++++++++---------------- 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 31122f15..79567bef 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -11,12 +11,17 @@ from cpython.exc cimport PyErr_SetFromErrno import libnfb cimport libnfb +from libnfb cimport NfbDeviceHandle + + cdef class RxMac: + cdef NfbDeviceHandle _handle cdef nc_rxmac *_mac def __init__(self, libnfb.Nfb nfb, node): + self._handle = nfb._handle self._mac = NULL - self._mac = nc_rxmac_open(nfb._dev, nfb._fdt_path_offset(node)) + self._mac = nc_rxmac_open(self._handle._dev, nfb._fdt_path_offset(node)) if self._mac is NULL: PyErr_SetFromErrno(OSError) @@ -97,11 +102,13 @@ cdef class RxMac: } cdef class TxMac: + cdef NfbDeviceHandle _handle cdef nc_txmac *_mac def __init__(self, libnfb.Nfb nfb, node): + self._handle = nfb._handle self._mac = NULL - self._mac = nc_txmac_open(nfb._dev, nfb._fdt_path_offset(node)) + self._mac = nc_txmac_open(self._handle._dev, nfb._fdt_path_offset(node)) if self._mac is NULL: PyErr_SetFromErrno(OSError) @@ -157,11 +164,13 @@ cdef class TxMac: } cdef class Mdio: + cdef NfbDeviceHandle _handle cdef nc_mdio *_mdio def __init__(self, libnfb.Nfb nfb, node, param_node = None): + self._handle = nfb._handle self._mdio = NULL - self._mdio = nc_mdio_open(nfb._dev, nfb._fdt_path_offset(node), nfb._fdt_path_offset(param_node) if param_node else -1) + self._mdio = nc_mdio_open(self._handle._dev, nfb._fdt_path_offset(node), nfb._fdt_path_offset(param_node) if param_node else -1) if self._mdio is NULL: PyErr_SetFromErrno(OSError) @@ -176,11 +185,13 @@ cdef class Mdio: nc_mdio_write(self._mdio, prtad, devad, reg, val) cdef class I2c: + cdef NfbDeviceHandle _handle cdef nc_i2c_ctrl *_ctrl def __init__(self, libnfb.Nfb nfb, node, addr = 0xA0): + self._handle = nfb._handle self._ctrl = NULL - self._ctrl = nc_i2c_open(nfb._dev, nfb._fdt_path_offset(node)) + self._ctrl = nc_i2c_open(self._handle._dev, nfb._fdt_path_offset(node)) nc_i2c_set_addr(self._ctrl, addr) def __del__(self): @@ -206,6 +217,7 @@ cdef class I2c: ret = nc_i2c_write_reg(self._ctrl, reg, c_data8, len(data)) cdef class DmaCtrlNdp: + cdef NfbDeviceHandle _handle cdef nc_ndp_ctrl _ctrl cdef void *_ctrl_queue cdef nc_rxqueue *_ctrl_tx @@ -215,17 +227,20 @@ cdef class DmaCtrlNdp: def __init__(self, libnfb.Nfb nfb, node): cdef int ret + cdef nfb_device *dev + self._ctrl_queue = NULL - self.__nfb = nfb - ret = nc_ndp_ctrl_open(nfb._dev, nfb._fdt_path_offset(node), &self._ctrl) + self._handle = nfb._handle + dev = self._handle._dev + ret = nc_ndp_ctrl_open(dev, nfb._fdt_path_offset(node), &self._ctrl) if ret != 0: PyErr_SetFromErrno(OSError) if self._ctrl.dir == 0: - self._ctrl_queue = nc_rxqueue_open(nfb._dev, nfb._fdt_path_offset(node)) + self._ctrl_queue = nc_rxqueue_open(dev, nfb._fdt_path_offset(node)) else: #if self._ctrl.dir == 1: - self._ctrl_queue = nc_txqueue_open(nfb._dev, nfb._fdt_path_offset(node)) + self._ctrl_queue = nc_txqueue_open(dev, nfb._fdt_path_offset(node)) if self._ctrl_queue == NULL != 0: nc_ndp_ctrl_close(&self._ctrl) diff --git a/pynfb/nfb/libnfb.pxd b/pynfb/nfb/libnfb.pxd index f5dce494..ba6bcf28 100644 --- a/pynfb/nfb/libnfb.pxd +++ b/pynfb/nfb/libnfb.pxd @@ -127,11 +127,15 @@ cdef extern from "": cdef ndp_queue_ops* ndp_queue_get_ops(ndp_queue *q) +cdef class NfbDeviceHandle: + #cdef object __weakref__ + cdef nfb_device* _dev + cdef class Nfb: + cdef NfbDeviceHandle _handle + # Deprecated. Use _handle._dev cdef nfb_device* _dev cdef const void* _fdt - cdef const char* _fdtc - cdef public bytes _dtb cdef dict __dict__ diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index bb7e3d3e..8bbb7106 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -43,6 +43,16 @@ def open(path: str = '0') -> Nfb: eth.EthManager(dev) return dev +cdef class NfbDeviceHandle: + def __cinit__(self, path: str): + self._dev = nfb_open(path.encode()) + if self._dev is NULL: + PyErr_SetFromErrno(OSError) + + def __dealloc__(self): + if self._dev is not NULL: + nfb_close(self._dev) + cdef class Nfb: """ @@ -58,21 +68,22 @@ cdef class Nfb: default_device = '/dev/nfb0' - def __cinit__(self, path: str): - self._dev = nfb_open(path.encode()) - if self._dev is NULL: - PyErr_SetFromErrno(OSError) + def __init__(self, path: str): + cdef const char* _fdtc + + self._handle = NfbDeviceHandle(path) + # Deprecated. Use _handle._dev + self._dev = self._handle._dev - self._fdt = nfb_get_fdt(self._dev) - self._fdtc = self._fdt - self._dtb = self._fdtc[:c_fdt_totalsize(self._fdt)] - self.fdt = fdt.parse_dtb(self._dtb) + self._fdt = nfb_get_fdt(self._handle._dev) + fdtc = self._fdt + dtb = fdtc[:c_fdt_totalsize(self._fdt)] + self.fdt = fdt.parse_dtb(dtb) self.ndp = QueueManager(self) def __dealloc__(self): - if self._dev is not NULL: - nfb_close(self._dev) + pass def comp_open(self, comp: Union[str, fdt.items.Node], index: cython.int = 0) -> Comp: """ @@ -85,7 +96,7 @@ cdef class Nfb: cdef int fdt_offset if isinstance(comp, str): - fdt_offset = nfb_comp_find(self._dev, comp.encode(), index) + fdt_offset = nfb_comp_find(self._handle._dev, comp.encode(), index) elif isinstance(comp, fdt.items.Node): fdt_offset = self._fdt_path_offset(comp) else: @@ -133,10 +144,10 @@ cdef class Comp: """ cdef nfb_comp* _comp - cdef Nfb _nfb_dev + cdef NfbDeviceHandle _nfb_dev def __cinit__(self, Nfb nfb_dev, int fdt_offset): - self._nfb_dev = nfb_dev + self._nfb_dev = nfb_dev._handle self._comp = nfb_comp_open(self._nfb_dev._dev, fdt_offset) if self._comp is NULL: PyErr_SetFromErrno(OSError) @@ -460,16 +471,14 @@ cdef class NdpQueue: Object representing a NDP queue """ + cdef NfbDeviceHandle _handle cdef ndp_queue *_q - cdef nfb_device *_dev cdef dict __dict__ - cdef Nfb _nfb cdef int _index cdef bool _running def __init__(self, nfb: Nfb, node, index: int): - self._nfb = nfb - self._dev = nfb._dev + self._handle = nfb._handle self._index = index self._q = NULL self._running = False @@ -478,7 +487,7 @@ cdef class NdpQueue: cdef _check_running(self): if not self._running: if self._q is NULL: - p1, p2 = self._nfb._dev, self._index + p1, p2 = self._handle._dev, self._index self._q = ndp_open_tx_queue(p1, p2) if self._dir else ndp_open_rx_queue(p1, p2) if self._q is NULL: PyErr_SetFromErrno(OSError) @@ -513,7 +522,7 @@ cdef class NdpQueueRx(NdpQueue): def __init__(self, nfb: Nfb, node, index): self._dir = 0 NdpQueue.__init__(self, nfb, node, index) - self._nc_queue = libnetcope.nc_rxqueue_open(nfb._dev, nfb._fdt_path_offset(node)) + self._nc_queue = libnetcope.nc_rxqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) def stats_reset(self): """Reset statistic counters""" @@ -625,7 +634,7 @@ cdef class NdpQueueTx(NdpQueue): def __init__(self, nfb: Nfb, node, index): self._dir = 1 NdpQueue.__init__(self, nfb, node, index) - self._nc_queue = libnetcope.nc_txqueue_open(nfb._dev, nfb._fdt_path_offset(node)) + self._nc_queue = libnetcope.nc_txqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) def stats_reset(self): """Reset statistic counters""" From a3f85d48ed3472205a5a0f387407b11145e97b62 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 16 Nov 2023 10:06:41 +0100 Subject: [PATCH 033/518] pynfb: [FIX] use __dealloc__ instead of __del__ for closing libnetcope components --- pynfb/nfb/libnetcope.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 79567bef..a4c3b174 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -25,7 +25,7 @@ cdef class RxMac: if self._mac is NULL: PyErr_SetFromErrno(OSError) - def __del__(self): + def __dealloc__(self): if self._mac is not NULL: nc_rxmac_close(self._mac) @@ -112,7 +112,7 @@ cdef class TxMac: if self._mac is NULL: PyErr_SetFromErrno(OSError) - def __del__(self): + def __dealloc__(self): if self._mac is not NULL: nc_txmac_close(self._mac) @@ -174,7 +174,7 @@ cdef class Mdio: if self._mdio is NULL: PyErr_SetFromErrno(OSError) - def __del__(self): + def __dealloc__(self): if self._mdio is not NULL: nc_mdio_close(self._mdio) @@ -194,7 +194,7 @@ cdef class I2c: self._ctrl = nc_i2c_open(self._handle._dev, nfb._fdt_path_offset(node)) nc_i2c_set_addr(self._ctrl, addr) - def __del__(self): + def __dealloc__(self): if self._ctrl is not NULL: nc_i2c_close(self._ctrl) @@ -247,7 +247,7 @@ cdef class DmaCtrlNdp: self._ctrl.comp = NULL PyErr_SetFromErrno(OSError) - def __del__(self): + def __dealloc__(self): if self._ctrl.comp is not NULL: if self._ctrl_queue: if self._ctrl.dir == 0: From 448fd1a254abb84e84b5f93f9fa4a9cbb4be2139 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 20 Nov 2023 09:37:07 +0100 Subject: [PATCH 034/518] pynfb: [FIX] dealloc queues --- pynfb/nfb/libnfb.pyx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 8bbb7106..49830060 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -484,6 +484,13 @@ cdef class NdpQueue: self._running = False self._node = node + def __dealloc__(self): + if self._q is not NULL: + if self._dir: + ndp_close_tx_queue(self._q) + else: + ndp_close_rx_queue(self._q) + cdef _check_running(self): if not self._running: if self._q is NULL: @@ -523,6 +530,12 @@ cdef class NdpQueueRx(NdpQueue): self._dir = 0 NdpQueue.__init__(self, nfb, node, index) self._nc_queue = libnetcope.nc_rxqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) + if self._nc_queue is NULL: + PyErr_SetFromErrno(OSError) + + def __dealloc__(self): + if self._nc_queue is not NULL: + libnetcope.nc_rxqueue_close(self._nc_queue) def stats_reset(self): """Reset statistic counters""" @@ -635,6 +648,12 @@ cdef class NdpQueueTx(NdpQueue): self._dir = 1 NdpQueue.__init__(self, nfb, node, index) self._nc_queue = libnetcope.nc_txqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) + if self._nc_queue is NULL: + PyErr_SetFromErrno(OSError) + + def __dealloc__(self): + if self._nc_queue is not NULL: + libnetcope.nc_txqueue_close(self._nc_queue) def stats_reset(self): """Reset statistic counters""" From 7af5168a4a9548a77ed520a83f9c73d2f848a8e6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Mar 2023 08:12:27 +0100 Subject: [PATCH 035/518] drivers - MI [FEATURE]: read attribute from DT to enable memory map There is and attribute in DT by each MI bus to specify if it should be mapped as Write Combine. This mapping is needed for DMA Calypte TX buffers. The mapping is then decided according to that. --- drivers/kernel/drivers/nfb/mi/mi.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/mi/mi.c b/drivers/kernel/drivers/nfb/mi/mi.c index e738b0a7..7c817e1e 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.c +++ b/drivers/kernel/drivers/nfb/mi/mi.c @@ -89,8 +89,10 @@ int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) struct nfb_pci_device *pci_device; int pci_index, bar; + uint32_t is_wc_mapped = 0; const void *prop; + int proplen; char nodename[16]; prop = fdt_getprop(nfb->fdt, node_offset, "resource", NULL); @@ -101,6 +103,9 @@ int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) if (ret != 2) return -EINVAL; + prop = fdt_getprop(nfb->fdt, node_offset, "map-as-wc", &proplen); + is_wc_mapped = prop && proplen == 0; + /* Find corresponding PCI device in list */ ret = -ENODEV; list_for_each_entry(pci_device, &nfb->pci_devices, pci_device_list) { @@ -134,12 +139,18 @@ int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) /* Map PCI memory region */ mi_node->mem_phys = pci_resource_start(pci_device->pci, mi_node->bar); mi_node->mem_len = pci_resource_len(pci_device->pci, mi_node->bar); + if (request_mem_region(mi_node->mem_phys, mi_node->mem_len, "nfb") == NULL) { dev_err(&nfb->pci->dev, "unable to grab memory region 0x%llx-0x%llx\n", (u64)mi_node->mem_phys, (u64)(mi_node->mem_phys + mi_node->mem_len - 1)); goto err_request_mem_region; } - mi_node->mem_virt = ioremap(mi_node->mem_phys, mi_node->mem_len); + + if (is_wc_mapped) + mi_node->mem_virt = ioremap_wc(mi_node->mem_phys, mi_node->mem_len); + else + mi_node->mem_virt = ioremap(mi_node->mem_phys, mi_node->mem_len); + if (mi_node->mem_virt == NULL) { dev_err(&nfb->pci->dev, "unable to remap memory region 0x%llx-0x%llx\n", (u64)mi_node->mem_phys, (u64)(mi_node->mem_phys + mi_node->mem_len - 1)); From c97a82ee81f900351b1cf9c4de73616284eac210 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Mar 2023 08:03:40 +0100 Subject: [PATCH 036/518] libnfb - MI bus: add support for 32B/16B AVX2 memory write instructions --- libnfb/CMakeLists.txt | 1 + libnfb/src/bus/mi.c | 141 +++++++++++++++++++++++++++++------------- 2 files changed, 98 insertions(+), 44 deletions(-) diff --git a/libnfb/CMakeLists.txt b/libnfb/CMakeLists.txt index 89deccde..a2ede570 100644 --- a/libnfb/CMakeLists.txt +++ b/libnfb/CMakeLists.txt @@ -56,6 +56,7 @@ foreach(NFB IN ITEMS nfb nfb_static) VERSION ${GIT_VERSION} SOVERSION ${GIT_VERSION_MAJOR} ) + set_source_files_properties(src/bus/mi.c PROPERTIES COMPILE_FLAGS -mavx2) endforeach() install(TARGETS nfb nfb_static diff --git a/libnfb/src/bus/mi.c b/libnfb/src/bus/mi.c index a8dcb823..f7b710f5 100644 --- a/libnfb/src/bus/mi.c +++ b/libnfb/src/bus/mi.c @@ -16,9 +16,13 @@ #include #include #include +#include #include +#include +#include + #include "../nfb.h" struct nfb_bus_mi_priv @@ -26,6 +30,7 @@ struct nfb_bus_mi_priv size_t mmap_size; off_t mmap_offset; void * space; + bool is_wc_mapped; }; /* @@ -34,84 +39,125 @@ struct nfb_bus_mi_priv * Here is a workaround for these issues */ -static inline void nfb_bus_mi_memcopy(void *dst, const void *src, size_t nbyte, size_t offset) +#define _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr) \ +do { \ + if (nbyte == (size)) { \ + if (wc_instr) \ + wc_used = true; \ + return wc_used; \ + } \ + (src) = (const mtype *) (src) + 1; \ + (dst) = (mtype *) (dst) + 1; \ + nbyte -= size; \ +} while (0) + +#define _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, size, src, dst, mtype, load, store, wc_used, wc_instr) \ +do { \ + mtype tmp; \ + while (nbyte >= (size)) { \ + tmp = load(src); \ + store(dst, tmp); \ + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ + } \ +} while (0) + +#define _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, size, src, dst, mtype, stream, wc_used, wc_instr) \ +do { \ + while (nbyte >= (size)) { \ + stream(dst, *(const mtype *) src); \ + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ + } \ +} while (0) + +#define _NFB_BUS_MI_MEMCPY_CYCLE_AS(nbyte, size, src, dst, mtype, wc_used, wc_instr) \ +do { \ + while (nbyte >= (size)) { \ + *(mtype *) dst = *(const mtype *) src; \ + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ + } \ +} while (0) + + +static inline bool nfb_bus_mi_memcopy(void *dst, const void *src, size_t nbyte, size_t offset) { + bool wc_used = false; + if (nbyte == 4) { *(uint32_t *) dst = *(const uint32_t *) src; - return; + return false; } else if (nbyte == 8) { *(uint64_t *) dst = *(const uint64_t *) src; - return; + return false; } + /* The offset variable is just for alignment check. The dst variable is alredy offseted. */ /* Align access on 4/8B boundary first */ if (offset & 0x03) { if (offset & 0x01 && nbyte >= 1) { *(uint8_t *) dst = *(const uint8_t *) src; - if (nbyte == 1) - return; - src = ((const uint8_t *) src + 1); - dst = ((uint8_t *) dst + 1); - nbyte -= 1; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 1, src, dst, uint8_t, wc_used, false); offset += 1; } if (offset & 0x02 && nbyte >= 2) { *(uint16_t *) dst = *(const uint16_t *) src; - if (nbyte == 2) - return; - src = ((const uint16_t *) src + 1); - dst = ((uint16_t *) dst + 1); - nbyte -= 2; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 2, src, dst, uint16_t, wc_used, false); offset += 2; } } - #ifdef MI_ACCESS_ALIGN32 + if (offset & 0x04 && nbyte >= 4) { *(uint32_t *) dst = *(const uint32_t *) src; - if (nbyte == 4) - return; - src = ((const uint32_t *) src + 1); - dst = ((uint32_t *) dst + 1); - nbyte -= 4; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 4, src, dst, uint32_t, wc_used, false); offset += 4; } - #endif - /* Loop with 64b accesses */ - while (nbyte >= 8) { - *(uint64_t *) dst = *(const uint64_t *) src; - if (nbyte == 8) - return; - src = ((const uint64_t *) src + 1); - dst = ((uint64_t *) dst + 1); - nbyte -= 8; + bool src256a = ((uintptr_t) src & 0x1F) ? false : true; + bool dst256a = ((uintptr_t) dst & 0x1F) ? false : true; + bool src128a = ((uintptr_t) src & 0x0F) ? false : true; + bool dst128a = ((uintptr_t) dst & 0x0F) ? false : true; + + + /* The _mm_stream* instructions are using the non-temporal hint. + * The non-temporal hint is implemented by using a write combining (WC) memory type protocol. + * The WC protocol uses a weakly-ordered memory consistency model, fencing operation should be used. */ + + if (src256a && dst256a) { + _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, 32, src, dst, __m256i, _mm256_stream_si256, wc_used, true); + } else if (src256a && !dst256a) { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 32, src, dst, __m256i, _mm256_stream_load_si256, _mm256_storeu_si256, wc_used, false); + } else if (!src256a && dst256a) { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 32, src, dst, __m256i, _mm256_loadu_si256, _mm256_store_si256, wc_used, false); + } else { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 32, src, dst, __m256i, _mm256_loadu_si256, _mm256_storeu_si256, wc_used, false); + } + + if (src128a && dst128a) { + _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, 16, src, dst, __m128i, _mm_stream_si128, wc_used, true); + } else if (src128a && !dst128a) { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_load_si128, _mm_storeu_si128, wc_used, false); + } else if (!src128a && dst128a) { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_loadu_si128, _mm_stream_si128, wc_used, false); + } else { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_loadu_si128, _mm_storeu_si128, wc_used, false); } + _NFB_BUS_MI_MEMCPY_CYCLE_AS(nbyte, 8, src, dst, uint64_t, wc_used, false); + /* Access the remaining bytes */ if (nbyte >= 4) { *(uint32_t *) dst = *(const uint32_t *) src; - if (nbyte == 4) - return; - src = ((const uint32_t *) src + 1); - dst = ((uint32_t *) dst + 1); - nbyte -= 4; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 4, src, dst, uint32_t, wc_used, false); } if (nbyte >= 2) { *(uint16_t *) dst = *(const uint16_t *) src; - if (nbyte == 2) - return; - src = ((const uint16_t *) src + 1); - dst = ((uint16_t *) dst + 1); - nbyte -= 2; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 2, src, dst, uint16_t, wc_used, false); } if (nbyte >= 1) { *(uint8_t *) dst = *(const uint8_t *) src; - if (nbyte == 1) - return; - src = ((const uint8_t *) src + 1); - dst = ((uint8_t *) dst + 1); - nbyte -= 1; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 1, src, dst, uint8_t, wc_used, false); } + + return wc_used; } ssize_t nfb_bus_mi_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) @@ -123,8 +169,12 @@ ssize_t nfb_bus_mi_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) ssize_t nfb_bus_mi_write(void *bus_priv, const void *buf, size_t nbyte, off_t offset) { + bool do_fence; struct nfb_bus_mi_priv *bus = bus_priv; - nfb_bus_mi_memcopy((uint8_t*) bus->space + offset, buf, nbyte, offset); + do_fence = nfb_bus_mi_memcopy((uint8_t*) bus->space + offset, buf, nbyte, offset); + + if (bus->is_wc_mapped || do_fence) + _mm_mfence(); return nbyte; } @@ -159,6 +209,9 @@ int nfb_bus_open_mi(void *dev_priv, int bus_node, int comp_node, void **bus_priv goto err_priv_alloc; } + prop = fdt_getprop(fdt, bus_node, "map-as-wc", &proplen); + bus->is_wc_mapped = prop && proplen == 0; + /* Find MI driver node in FDT */ fdt_offset = fdt_path_offset(fdt, path); if (fdt_offset < 0) { From 3bc3c74b4a7006d7c4023fa6c071c415323e3e4f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 22 Nov 2023 15:31:40 +0100 Subject: [PATCH 037/518] libnetcope - DMA Calypte: [FIX] wrong pointer mask used --- libnfb/include/netcope/ndp_priv.h | 6 +++--- libnfb/include/netcope/ndp_rx.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index 003242c8..c34f3299 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -69,9 +69,9 @@ struct nc_ndp_queue { // Used to indicate the number of packets that are // locked in the queue. It also means the number of free // headers. - unsigned pkts_available; - uint32_t bytes_available; - unsigned pkts_to_send; + uint32_t pkts_available; + uint32_t pkts_to_send; + uint64_t bytes_available; uint32_t sdp; uint32_t shp; diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index fcd331bf..d66df7c9 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -301,10 +301,10 @@ static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *pac packets[i].data_length = packet_size; hdr->valid = 0; - q->u.v3.sdp += (hdr->frame_len + (NDP_RX_CALYPTE_BLOCK_SIZE - 1)) & (~(NDP_RX_CALYPTE_BLOCK_SIZE -1)); + q->u.v3.sdp += (hdr->frame_len + NDP_RX_CALYPTE_BLOCK_SIZE - 1) / NDP_RX_CALYPTE_BLOCK_SIZE; } - q->u.v3.sdp &= q->u.v3.hdr_ptr_mask; + q->u.v3.sdp &= q->u.v3.data_ptr_mask; q->u.v3.shp = (q->u.v3.shp + count) & q->u.v3.hdr_ptr_mask; q->u.v3.pkts_available -= count; From 6d3f4bf93ce14ab4ec45b398fb067641c3a6add0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 22 Nov 2023 09:13:21 +0100 Subject: [PATCH 038/518] drivers - NDP: [FEATURE] add USERSPACE flag for disable pointer syncing with kernel --- drivers/kernel/include/linux/nfb/ndp.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/kernel/include/linux/nfb/ndp.h b/drivers/kernel/include/linux/nfb/ndp.h index d996ea6b..a2402370 100644 --- a/drivers/kernel/include/linux/nfb/ndp.h +++ b/drivers/kernel/include/linux/nfb/ndp.h @@ -25,6 +25,8 @@ #define NDP_CHANNEL_FLAG_USE_HEADER 0x04 /* Use offset buffer for specifying data positions in main buffer */ #define NDP_CHANNEL_FLAG_USE_OFFSET 0x08 +/* Do not sync pointers with kernel (library manages the pointers itself); must be used together with flag EXCLUSIVE */ +#define NDP_CHANNEL_FLAG_USERSPACE 0x10 /** * struct ndp_channel_request From 4756cc8c721ae84b924ae75d51e1a01f85ecb7c0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 22 Nov 2023 09:42:52 +0100 Subject: [PATCH 039/518] drivers - NDP: [FEATURE] add USERSPACE flag support to DMA calypte --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 5991fdc4..e72d3491 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -514,7 +514,20 @@ static uint64_t ndp_ctrl_get_flags(struct ndp_channel *channel) static uint64_t ndp_ctrl_set_flags(struct ndp_channel *channel, uint64_t flags) { - return ndp_ctrl_get_flags(channel); + uint64_t ret; + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + ret = ndp_ctrl_get_flags(channel); + + if (ctrl->c.type == DMA_TYPE_CALYPTE) { + if (flags & NDP_CHANNEL_FLAG_USERSPACE) { + ret |= NDP_CHANNEL_FLAG_USERSPACE; + ctrl->flags |= NDP_CHANNEL_FLAG_USERSPACE; + } else { + ctrl->flags &= ~NDP_CHANNEL_FLAG_USERSPACE; + } + } + + return ret; } static int ndp_ctrl_start(struct ndp_ctrl *ctrl, struct nc_ndp_ctrl_start_params *sp) @@ -628,6 +641,13 @@ static int ndp_ctrl_stop(struct ndp_channel *channel, int force) int cnt = 0; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + if (ctrl->c.type == DMA_TYPE_CALYPTE && ctrl->c.dir != 0 && ctrl->flags & NDP_CHANNEL_FLAG_USERSPACE) { + nc_ndp_ctrl_hp_update(&ctrl->c); + ctrl->c.sdp = ctrl->c.hdp; + ctrl->c.shp = ctrl->c.hhp; + nc_ndp_ctrl_sp_flush(&ctrl->c); + } + while (cnt < 10 || (!ndp_kill_signal_pending(current) && !force)) { ret = nc_ndp_ctrl_stop(&ctrl->c); if (ret == 0) { @@ -648,6 +668,9 @@ static int ndp_ctrl_stop(struct ndp_channel *channel, int force) "This may be due to firmware error.\n", dev_name(&channel->dev), cnt * 10); } + + ctrl->flags &= ~NDP_CHANNEL_FLAG_USERSPACE; + return 0; } From f6d7da95b8005a62db81205f93f398ad33910039 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 22 Nov 2023 10:00:06 +0100 Subject: [PATCH 040/518] drivers - NDP RX Calypte: [OPT] check for header valid flag instead of polling register --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index e72d3491..30fe63d5 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -319,10 +319,20 @@ static uint64_t ndp_ctrl_rx_get_hwptr(struct ndp_channel *channel) struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); hhp = ctrl->c.hhp; - nc_ndp_ctrl_hhp_update(&ctrl->c); - if (ctrl->c.type == DMA_TYPE_CALYPTE) + if (ctrl->c.type == DMA_TYPE_CALYPTE) { + struct nc_calypte_hdr *hdr_base; + uint32_t hwptr = ctrl->c.hhp; + do { + hdr_base = ctrl->ts.calypte.hdr_buffer + hwptr; + if (hdr_base->valid == 0) + break; + hwptr++; + } while (hwptr < ctrl->hdr_buffer_size * 2); + ctrl->c.hhp = hwptr & channel->ptrmask; return ctrl->c.hhp; + } + nc_ndp_ctrl_hhp_update(&ctrl->c); hhp_new = ctrl->c.hhp; count = (hhp_new - hhp) & ctrl->c.mhp; @@ -615,6 +625,7 @@ static int ndp_ctrl_calypte_start(struct ndp_channel *channel, uint64_t *hwptr) struct nc_ndp_ctrl_start_params sp; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + struct nc_calypte_hdr *hdr_base; // Only one block is used, therefore the physical address of the first one in "blocks" // list is used. @@ -625,6 +636,11 @@ static int ndp_ctrl_calypte_start(struct ndp_channel *channel, uint64_t *hwptr) ctrl->ts.calypte.hdr_buffer = ctrl->hdr_buffer_v; + for (ret = 0; ret < ctrl->hdr_count; ret++) { + hdr_base = ctrl->ts.calypte.hdr_buffer + ret; + hdr_base->valid = 0; + } + ret = ndp_ctrl_start(ctrl, &sp); if (ret) return ret; From 70e919465c1f134bb3eaeb2259758a9d3b34ee8d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 29 Nov 2023 15:16:36 +0100 Subject: [PATCH 041/518] NDP: [FEATURE] allow nc_ndp_queue* to use the nfb_device handle --- libnfb/include/netcope/ndp_base.h | 1 + libnfb/include/netcope/ndp_priv.h | 1 + 2 files changed, 2 insertions(+) diff --git a/libnfb/include/netcope/ndp_base.h b/libnfb/include/netcope/ndp_base.h index f03fafee..bb4fb53c 100644 --- a/libnfb/include/netcope/ndp_base.h +++ b/libnfb/include/netcope/ndp_base.h @@ -114,6 +114,7 @@ int ndp_base_queue_open(struct nfb_device *dev, void *dev_priv, unsigned index, } q_nc->q = q; + q_nc->dev = dev; #ifdef __KERNEL__ ndp = (struct ndp *) dev->list_drivers[NFB_DRIVER_NDP].priv; q_nc->subscriber = ndp_subscriber_create(ndp); diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index c34f3299..d1810ab4 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -97,6 +97,7 @@ struct nc_ndp_queue { /* Control path */ struct ndp_queue *q; + struct nfb_device *dev; uint32_t protocol; uint32_t flags; From d044942fa8ae02dab898b894b0cdb52d5a4c9a4c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 21 Nov 2023 09:29:58 +0100 Subject: [PATCH 042/518] NDP Calypte: [OPT] add exclusive userspace synchronization --- libnfb/include/netcope/ndp.h | 49 +++++++++++- libnfb/include/netcope/ndp_priv.h | 12 +++ libnfb/include/netcope/ndp_rx.h | 62 ++++++++++++-- libnfb/include/netcope/ndp_tx.h | 129 +++++++++++++++++++++++++++--- 4 files changed, 233 insertions(+), 19 deletions(-) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 52ffd2e7..55f13be0 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -142,7 +142,7 @@ static inline int nc_ndp_v2_open_queue(struct nc_ndp_queue *q, const void *fdt, return ret; } -static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, int fdt_offset) +static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, int fdt_offset, int ctrl_offset, int dir) { #ifndef __KERNEL__ int prot; @@ -161,6 +161,19 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, q->u.v3.shp = 0; #ifndef __KERNEL__ + q->u.v3.uspace_shp = 0; + q->u.v3.uspace_hhp = 0; + q->u.v3.uspace_hdp = 0; + q->u.v3.uspace_sdp = 0; + q->u.v3.uspace_free = 0; + q->u.v3.uspace_acc = 0; + + if (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) { + q->u.v3.comp = nfb_comp_open(q->dev, ctrl_offset); + if (q->u.v3.comp == NULL) + return -ENODEV; + } + if (q->channel.type == NDP_CHANNEL_TYPE_RX) { ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_size", &hdr_mmap_size); ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_base", &hdr_mmap_offset); @@ -200,6 +213,22 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, q->u.v3.hdr_ptr_mask = hdr_buff_size/(2*sizeof(struct ndp_v3_packethdr)) -1; } #endif + +#ifndef __KERNEL__ + if (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) { + q->u.v3.uspace_hdrs = q->u.v3.hdrs; + } +#endif + return 0; +} + +static inline int nc_ndp_v3_close_queue(struct nc_ndp_queue *q) +{ +#ifndef __KERNEL__ + if (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) { + nfb_comp_close(q->u.v3.comp); + } +#endif return 0; } @@ -283,7 +312,7 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu q->sync.hwptr = 0; if (q->protocol == 3) { - ret = nc_ndp_v3_open_queue(q, fdt, fdt_offset); + ret = nc_ndp_v3_open_queue(q, fdt, fdt_offset, ctrl_offset, dir); } else if (q->protocol == 2) { ret = nc_ndp_v2_open_queue(q, fdt, fdt_offset); } else if (q->protocol == 1) { @@ -316,6 +345,10 @@ static inline int nc_ndp_queue_open_init(const void *fdt, struct nc_ndp_queue *q static inline void nc_ndp_queue_close(struct nc_ndp_queue *q) { + if (q->protocol == 3) { + nc_ndp_v3_close_queue(q); + } + #ifdef __KERNEL__ if (q->sub) { ndp_subscription_destroy(q->sub); @@ -343,6 +376,18 @@ static int nc_ndp_queue_start(void *priv) q->u.v2.rhp = q->sync.hwptr; } +#ifndef __KERNEL__ + if (q->protocol == 3 && q->flags & NDP_CHANNEL_FLAG_USERSPACE) { + q->u.v3.uspace_mdp = nfb_comp_read32(q->u.v3.comp, NDP_CTRL_REG_MDP); + q->u.v3.uspace_mhp = nfb_comp_read32(q->u.v3.comp, NDP_CTRL_REG_MHP); + + /* This is used in TX only */ + /* Should be the same */ + q->u.v3.uspace_free = (q->u.v3.uspace_mdp + 1) - NDP_TX_CALYPTE_BLOCK_SIZE; + //q->u.v3.uspace_free = q->u.v3.uspace_mdp & ~(NDP_TX_CALYPTE_BLOCK_SIZE-1) + } +#endif + return ret; } diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index d1810ab4..a56eb5b3 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -82,6 +82,18 @@ struct nc_ndp_queue { struct ndp_packet *packets; // Buffer for headers struct ndp_v3_packethdr *hdrs; +#ifndef __KERNEL__ + struct ndp_v3_packethdr *uspace_hdrs; + struct nfb_comp *comp; + uint32_t uspace_shp; + uint32_t uspace_hhp; + uint32_t uspace_sdp; + uint32_t uspace_hdp; + uint32_t uspace_mhp; + uint32_t uspace_mdp; + uint32_t uspace_free; + uint32_t uspace_acc; +#endif } v3; } u; diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index d66df7c9..7bc47c6c 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -230,26 +230,78 @@ static inline int nc_ndp_v2_rx_burst_put(void *priv) return nc_ndp_v2_rx_unlock(priv); } +static inline void _ndp_queue_rx_sync_v3_us(struct nc_ndp_queue *q) +{ +#ifndef __KERNEL__ + struct ndp_v3_packethdr *hdr_base; + + if (q->sync.swptr != q->u.v3.uspace_shp) { +#if 0 + q->u.v3.uspace_shp = q->sync.swptr & q->u.v3.hdr_ptr_mask; + nfb_comp_write64(q->u.v3.comp, NDP_CTRL_REG_SDP, q->u.v3.sdp | (((uint64_t) q->u.v3.uspace_shp) << 32)); +#else + unsigned i; + unsigned count_blks = 0; + unsigned count = (q->sync.swptr - q->u.v3.uspace_shp) & q->u.v3.uspace_mhp; + + hdr_base = q->u.v3.hdrs + q->u.v3.uspace_shp; + for (i = 0; i < count; i++) { + count_blks += (hdr_base[i].frame_len + NDP_RX_CALYPTE_BLOCK_SIZE - 1) / NDP_RX_CALYPTE_BLOCK_SIZE; + } + + q->u.v3.uspace_shp = q->sync.swptr; + q->u.v3.uspace_sdp = (q->u.v3.uspace_sdp + count_blks) & q->u.v3.uspace_mdp; + q->u.v3.uspace_acc += count; + + /* TODO: magic number */ + if (q->u.v3.uspace_acc >= 32) { + q->u.v3.uspace_acc = 0; + ////nc_ndp_ctrl_sp_flush(q->u.v3.comp); + nfb_comp_write64(q->u.v3.comp, NDP_CTRL_REG_SDP, q->u.v3.uspace_sdp | (((uint64_t) q->u.v3.uspace_shp) << 32)); + } +#endif + } + + do { + hdr_base = q->u.v3.hdrs + q->u.v3.uspace_hhp; + if (hdr_base->valid == 0) + break; + q->u.v3.uspace_hhp = (q->u.v3.uspace_hhp + 1) & q->u.v3.uspace_mhp; + } while (1); + q->sync.hwptr = q->u.v3.uspace_hhp; +#endif +} + static inline unsigned nc_ndp_v3_rx_lock(void *priv) { - int ret; + int ret = 0; struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if ((ret = _ndp_queue_sync(q, &q->sync))) { - return ret; + if (q->flags & NDP_CHANNEL_FLAG_USERSPACE) { + _ndp_queue_rx_sync_v3_us(q); + } else { + if ((ret = _ndp_queue_sync(q, &q->sync))) { + return ret; + } } q->u.v3.pkts_available = (q->sync.hwptr - q->u.v3.shp) & (q->u.v3.hdr_ptr_mask); - return 0; + return ret; } static inline int nc_ndp_v3_rx_unlock(void *priv) { + int ret = 0; struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; q->sync.swptr = q->u.v3.shp & (q->u.v3.hdr_ptr_mask); - return _ndp_queue_sync(q, &q->sync); + if (q->flags & NDP_CHANNEL_FLAG_USERSPACE) { + _ndp_queue_rx_sync_v3_us(q); + } else { + ret = _ndp_queue_sync(q, &q->sync); + } + return ret; } static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *packets, unsigned count) diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index fd599fd7..18d74aa5 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -282,6 +282,80 @@ static inline int nc_ndp_v2_tx_burst_flush(void *priv) return 0; } +static inline void _ndp_queue_tx_sync_v3_us(struct nc_ndp_queue *q) +{ +#ifndef __KERNEL__ + uint64_t hwpointers; + uint32_t hdp; + uint32_t hhp; + + uint32_t count; + + uint32_t new_hwptr = q->sync.hwptr; + { + uint32_t i; + uint32_t frame_space; + uint32_t sdp = q->u.v3.uspace_sdp; + uint32_t shp = q->u.v3.uspace_shp; + struct ndp_v3_packethdr *hdr; + + count = (new_hwptr - shp) & q->u.v3.uspace_mhp; + + for (i = 0; i < count; i++) { + hdr = q->u.v3.uspace_hdrs + shp + i; + frame_space = (hdr->frame_len + (NDP_TX_CALYPTE_BLOCK_SIZE - 1)) & (~(NDP_TX_CALYPTE_BLOCK_SIZE - 1)); + q->u.v3.uspace_free -= frame_space; + sdp += frame_space; + } + + if (count) { + q->u.v3.uspace_sdp = sdp & q->u.v3.uspace_mdp; + q->u.v3.uspace_shp = new_hwptr; + + q->u.v3.uspace_acc += count; + /* TODO: magic number */ + if (q->u.v3.uspace_acc >= 32) { + q->u.v3.uspace_acc = 0; + nfb_comp_write64(q->u.v3.comp, NDP_CTRL_REG_SDP, q->u.v3.uspace_sdp | (((uint64_t) q->u.v3.uspace_shp) << 32)); + } + } + } + + { + uint32_t hdp_prev; + hdp_prev = q->u.v3.uspace_hdp; + + uint32_t chlen = (q->u.v3.uspace_hhp - q->u.v3.uspace_shp - 1) & q->u.v3.uspace_mhp; + /* TODO: magic number */ + if (chlen < 512 || q->u.v3.uspace_free <= 4096) { + hwpointers = nfb_comp_read64(q->u.v3.comp, NDP_CTRL_REG_HDP); + hdp = ((uint32_t)hwpointers); + hhp = ((uint32_t)(hwpointers >> 32)); + + count = (hdp - hdp_prev) & q->u.v3.uspace_mdp; + q->u.v3.uspace_hdp = hdp; + q->u.v3.uspace_hhp = hhp; + + q->u.v3.uspace_free += count; + } + } + + { + uint32_t len; + uint32_t chlen = (q->u.v3.uspace_hhp - q->u.v3.uspace_shp - 1) & q->u.v3.uspace_mhp; + + /* Subscriber tries to lock LENGTH items */ + len = (q->sync.swptr - q->sync.hwptr /*swptr_new - hwptr_new*/) & q->u.v3.uspace_mhp; + len = min(len, chlen); + + q->sync.hwptr = q->u.v3.uspace_hhp; + q->sync.swptr = (q->sync.hwptr + len) & q->u.v3.uspace_mhp; + + q->sync.size = q->u.v3.uspace_free; + } +#endif +} + // Figure out, how many packets can be stored in a queue right now. static inline void nc_ndp_v3_tx_lock(void *priv) { @@ -293,8 +367,12 @@ static inline void nc_ndp_v3_tx_lock(void *priv) // This assignment allows to determine the amount of free headers in the buffer q->sync.swptr = (q->sync.hwptr - 1) & (q->u.v3.hdr_ptr_mask); - if (_ndp_queue_sync(q, &q->sync)) - return; + if (q->flags & NDP_CHANNEL_FLAG_USERSPACE) { + _ndp_queue_tx_sync_v3_us(q); + } else { + if (_ndp_queue_sync(q, &q->sync)) + return; + } if (!lock_valid) { offset = q->sync.hwptr - q->u.v3.shp; @@ -307,6 +385,19 @@ static inline void nc_ndp_v3_tx_lock(void *priv) q->u.v3.bytes_available = q->sync.size; } +static inline int nc_ndp_v3_tx_request_space(struct nc_ndp_queue *q, uint32_t shp) +{ + q->sync.hwptr = shp; + if (q->flags & NDP_CHANNEL_FLAG_USERSPACE) { + _ndp_queue_tx_sync_v3_us(q); + } else { + if (_ndp_queue_sync(q, &q->sync)) + return -1; + } + q->u.v3.bytes_available = q->sync.size; + return 0; +} + static inline unsigned nc_ndp_v3_tx_burst_get(void *priv, struct ndp_packet *packets, unsigned count) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; @@ -393,12 +484,30 @@ static inline int nc_ndp_v3_tx_burst_flush(void *priv) } // Synchronize pointers after all packets in a burst have been sent - q->sync.swptr = q->u.v3.shp; - q->sync.hwptr = q->u.v3.shp; - q->u.v3.pkts_available = 0; - if (_ndp_queue_sync(q, &q->sync)) - return -1; + /* TX is flushed anyway by writing of header */ + if (q->flags & NDP_CHANNEL_FLAG_USERSPACE) { +#ifndef __KERNEL__ + if (q->sync.hwptr == q->u.v3.shp) + return 0; + + q->sync.hwptr = q->u.v3.shp; + /* Always request more data (no noeed for real 'unlock all') */ + q->sync.swptr = (q->u.v3.shp + 64) & q->u.v3.hdr_ptr_mask; + + _ndp_queue_tx_sync_v3_us(q); + + q->u.v3.pkts_available = (q->sync.swptr - q->sync.hwptr) & (q->u.v3.hdr_ptr_mask); + q->u.v3.bytes_available = q->sync.size; +#endif + } else { + q->sync.swptr = q->u.v3.shp; + q->sync.hwptr = q->u.v3.shp; + q->u.v3.pkts_available = 0; + + if (_ndp_queue_sync(q, &q->sync)) + return -1; + } return 0; } @@ -419,12 +528,8 @@ static inline int nc_ndp_v3_tx_burst_put(void *priv) frame_len_ceil = (hdr[i].frame_len + (NDP_TX_CALYPTE_BLOCK_SIZE -1)) & (~(NDP_TX_CALYPTE_BLOCK_SIZE -1)); while (q->u.v3.bytes_available < frame_len_ceil) { - q->sync.hwptr = shp; - - if (_ndp_queue_sync(q, &q->sync)) + if (nc_ndp_v3_tx_request_space(q, shp)) return -1; - - q->u.v3.bytes_available = q->sync.size; } nfb_comp_write(q->u.v3.tx_data_buff, packet[i].header, hdr[i].frame_len, hdr[i].frame_ptr); From b4274ec63ba698e9d6d329f95133a8c238ba09dc Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 1 Dec 2023 10:25:36 +0100 Subject: [PATCH 043/518] libnfb: [FEATURE] add NDP_OPEN_FLAG_USERSPACE --- libnfb/include/netcope/ndp.h | 2 +- libnfb/include/netcope/ndp_core.h | 7 ++++++- libnfb/include/nfb/ndp.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 55f13be0..cd9e751e 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -238,7 +238,7 @@ static inline int nc_ndp_queue_open_init_ext(const void *fdt, struct nc_ndp_queu int fdt_offset; int ctrl_offset; int ctrl_params_offset; - int flags = 0; + int flags = ndp_flags; off_t mmap_offset; size_t mmap_size = 0; diff --git a/libnfb/include/netcope/ndp_core.h b/libnfb/include/netcope/ndp_core.h index 067fa005..9fc4d14e 100644 --- a/libnfb/include/netcope/ndp_core.h +++ b/libnfb/include/netcope/ndp_core.h @@ -127,11 +127,16 @@ static void nfb_queue_remove(struct ndp_queue *q) #endif } -struct ndp_queue *ndp_open_queue(struct nfb_device *dev, unsigned index, int dir, int flags) +struct ndp_queue *ndp_open_queue(struct nfb_device *dev, unsigned index, int dir, int in_flags) { int ret; + int flags = 0; struct ndp_queue *q = NULL; + if (in_flags & NDP_OPEN_FLAG_USERSPACE) { + flags |= NDP_CHANNEL_FLAG_EXCLUSIVE | NDP_CHANNEL_FLAG_USERSPACE; + } + #ifndef __KERNEL__ if (!dev->ops.ndp_queue_open || !dev->ops.ndp_queue_close) { ret = -ENXIO; diff --git a/libnfb/include/nfb/ndp.h b/libnfb/include/nfb/ndp.h index b034f100..6a9f3168 100644 --- a/libnfb/include/nfb/ndp.h +++ b/libnfb/include/nfb/ndp.h @@ -93,6 +93,7 @@ enum ndp_print_option { */ typedef int ndp_open_flags_t; #define NDP_OPEN_FLAG_NO_BUFFER (1 << 0) /*!< Open queue (RX or TX) in NO_BUFFER mode where packet data space is supplied by the user and not by the driver */ +#define NDP_OPEN_FLAG_USERSPACE (1 << 1) /* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ From e1fd588bb50e5ba3be1f8b2450dc784723aab0ec Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 22 Nov 2023 08:54:40 +0100 Subject: [PATCH 044/518] ndp-tool: [FEATURE] add Performance mode (-P); do not use delay/sleep when idle --- tools/ndptool/common.h | 1 + tools/ndptool/loopback.c | 6 ++++-- tools/ndptool/loopback_hw.c | 3 ++- tools/ndptool/main.c | 7 ++++++- tools/ndptool/read.c | 3 ++- tools/ndptool/receive.c | 3 ++- tools/ndptool/transmit.c | 6 ++++-- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index 07394e3f..f4e0a6ba 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -162,6 +162,7 @@ struct ndp_tool_params { long long unsigned limit_bytes; int verbose; + unsigned use_delay_nsec: 1; }; struct thread_data { diff --git a/tools/ndptool/loopback.c b/tools/ndptool/loopback.c index 4e0f4e4f..9b730f26 100644 --- a/tools/ndptool/loopback.c +++ b/tools/ndptool/loopback.c @@ -164,7 +164,8 @@ static int ndp_mode_loopback_loop(struct ndp_tool_params *p) if (cnt_rx == 0) { ndp_tx_burst_flush(tx); - delay_nsecs(1); + if (p->use_delay_nsec) + delay_nsecs(1); continue; } @@ -172,7 +173,8 @@ static int ndp_mode_loopback_loop(struct ndp_tool_params *p) packets_tx[i].data_length = packets_rx[i].data_length; cnt_tx = ndp_tx_burst_get(tx, packets_tx, cnt_rx); while (cnt_tx != cnt_rx && !stop) { - delay_nsecs(1); + if (p->use_delay_nsec) + delay_nsecs(1); cnt_tx = ndp_tx_burst_get(tx, packets_tx, cnt_rx); } for (i = 0; i < cnt_tx; i++) diff --git a/tools/ndptool/loopback_hw.c b/tools/ndptool/loopback_hw.c index d00b3452..f11f4d0b 100644 --- a/tools/ndptool/loopback_hw.c +++ b/tools/ndptool/loopback_hw.c @@ -392,7 +392,8 @@ static int ndp_mode_loopback_hw_loop(struct ndp_tool_params *p) return ret; if (0 && p->queue_index==0) printf("TX stall\n"); - delay_nsecs(1); + if (p->use_delay_nsec) + delay_nsecs(1); cnt = ndp_tx_burst_get(tx,packets,tx_burst_size); } diff --git a/tools/ndptool/main.c b/tools/ndptool/main.c index efea75bd..15f9c423 100644 --- a/tools/ndptool/main.c +++ b/tools/ndptool/main.c @@ -24,7 +24,7 @@ #include "common.h" -#define ARGUMENTS "d:i:hD:I:Rqp:b:B:" +#define ARGUMENTS "d:i:hD:I:Rqp:b:B:P" volatile int stop = 0; volatile int stats = 0; @@ -72,6 +72,7 @@ static void usage(char *me, int mode_preset) printf(" -b bytes Stop receiving or transmitting after bytes\n"); printf(" -B size Read and write packets in bursts of [default: RX=%u, TX=%u]\n", RX_BURST, TX_BURST); + printf(" -P Performance mode (do not use delay/sleep when idle)\n"); printf("Packet output parameters: (available for one queue only)\n"); printf(" -D dump Dump packet content to stdout (char, all, header, data)\n"); @@ -155,6 +156,7 @@ int main(int argc, char *argv[]) params.pcap_filename = NULL; params.limit_bytes = 0; params.limit_packets = 0; + params.use_delay_nsec = 1; list_range_init(&queue_range); @@ -232,6 +234,9 @@ int main(int argc, char *argv[]) case 'q': quiet = true; break; + case 'P': + params.use_delay_nsec = 0; + break; case 'h': usage(argv[0], strmode == argv[1]); exit(0); diff --git a/tools/ndptool/read.c b/tools/ndptool/read.c index f3fea381..6571300b 100644 --- a/tools/ndptool/read.c +++ b/tools/ndptool/read.c @@ -140,7 +140,8 @@ static int ndp_mode_read_loop(struct ndp_tool_params *p) update_stats(packets, cnt, si); if (cnt == 0) { - delay_nsecs(1); + if (p->use_delay_nsec) + delay_nsecs(1); continue; } ndp_rx_burst_put(rx); diff --git a/tools/ndptool/receive.c b/tools/ndptool/receive.c index ba680b65..a93fd217 100644 --- a/tools/ndptool/receive.c +++ b/tools/ndptool/receive.c @@ -163,7 +163,8 @@ static int ndp_mode_receive_loop(struct ndp_tool_params *p) update_stats(packets, cnt, si); if (cnt == 0) { - delay_nsecs(1); + if (p->use_delay_nsec) + delay_nsecs(1); continue; } diff --git a/tools/ndptool/transmit.c b/tools/ndptool/transmit.c index a45cb357..f8fb1fbc 100644 --- a/tools/ndptool/transmit.c +++ b/tools/ndptool/transmit.c @@ -224,7 +224,8 @@ static int ndp_mode_transmit_loop(struct ndp_tool_params *p, struct pcap_src *sr cnt = ndp_tx_burst_get(tx, packets, pkts_ready); while (cnt == 0 && !stop) { - delay_nsecs(1); + if (p->use_delay_nsec) + delay_nsecs(1); cnt = ndp_tx_burst_get(tx, packets, pkts_ready); } @@ -254,7 +255,8 @@ static int ndp_mode_transmit_loop(struct ndp_tool_params *p, struct pcap_src *sr /* We have to pause sending packets for a while */ //update_stats(packets, 0, si); ndp_tx_burst_flush(tx); - delay_nsecs(1); + if (p->use_delay_nsec) + delay_nsecs(1); } else { break; } From 03bf5abafa8a2c960c2b873bbaad7e3b41c102f4 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 1 Dec 2023 10:05:34 +0100 Subject: [PATCH 045/518] ndp-tool: [FEATURE] add userspace mode as -U parameter --- tools/ndptool/common.h | 1 + tools/ndptool/generate.c | 2 +- tools/ndptool/loopback.c | 4 ++-- tools/ndptool/loopback_hw.c | 4 ++-- tools/ndptool/main.c | 7 ++++++- tools/ndptool/read.c | 2 +- tools/ndptool/receive.c | 2 +- tools/ndptool/transmit.c | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index f4e0a6ba..484e9897 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -163,6 +163,7 @@ struct ndp_tool_params { int verbose; unsigned use_delay_nsec: 1; + unsigned use_userspace_flag: 1; }; struct thread_data { diff --git a/tools/ndptool/generate.c b/tools/ndptool/generate.c index 41ade4cc..334eb858 100644 --- a/tools/ndptool/generate.c +++ b/tools/ndptool/generate.c @@ -72,7 +72,7 @@ static int ndp_mode_generate_prepare(struct ndp_tool_params *p) goto err_nfb_open; } - p->tx = ndp_open_tx_queue(p->dev, p->queue_index); + p->tx = ndp_open_tx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); if (p->tx == NULL) { warnx("ndp_open_tx_queue(%d) failed.", p->queue_index); goto err_ndp_open_tx; diff --git a/tools/ndptool/loopback.c b/tools/ndptool/loopback.c index 9b730f26..1e815bb1 100644 --- a/tools/ndptool/loopback.c +++ b/tools/ndptool/loopback.c @@ -72,13 +72,13 @@ static int ndp_mode_loopback_prepare(struct ndp_tool_params *p) goto err_nfb_open; } - p->rx = ndp_open_rx_queue(p->dev, p->queue_index); + p->rx = ndp_open_rx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); if (p->rx == NULL) { warnx("ndp_open_rx_queue(%d) failed.", p->queue_index); goto err_ndp_open_rx; } - p->tx = ndp_open_tx_queue(p->dev, p->queue_index); + p->tx = ndp_open_tx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); if (p->tx == NULL) { warnx("ndp_open_tx_queue(%d) failed.", p->queue_index); goto err_ndp_open_tx; diff --git a/tools/ndptool/loopback_hw.c b/tools/ndptool/loopback_hw.c index f11f4d0b..e4df6ee4 100644 --- a/tools/ndptool/loopback_hw.c +++ b/tools/ndptool/loopback_hw.c @@ -122,13 +122,13 @@ static int ndp_mode_loopback_hw_prepare(struct ndp_tool_params *p) goto err_nfb_open; } - p->rx = ndp_open_rx_queue(p->dev, p->queue_index); + p->rx = ndp_open_rx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); if (p->rx == NULL) { warnx("ndp_open_rx_queue(%d) failed.", p->queue_index); goto err_ndp_open_rx; } - p->tx = ndp_open_tx_queue(p->dev, p->queue_index); + p->tx = ndp_open_tx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); if (p->tx == NULL) { warnx("ndp_open_tx_queue(%d) failed.", p->queue_index); goto err_ndp_open_tx; diff --git a/tools/ndptool/main.c b/tools/ndptool/main.c index 15f9c423..9f34d05d 100644 --- a/tools/ndptool/main.c +++ b/tools/ndptool/main.c @@ -24,7 +24,7 @@ #include "common.h" -#define ARGUMENTS "d:i:hD:I:Rqp:b:B:P" +#define ARGUMENTS "d:i:hD:I:Rqp:b:B:PU" volatile int stop = 0; volatile int stats = 0; @@ -73,6 +73,7 @@ static void usage(char *me, int mode_preset) printf(" -B size Read and write packets in bursts of [default: RX=%u, TX=%u]\n", RX_BURST, TX_BURST); printf(" -P Performance mode (do not use delay/sleep when idle)\n"); + printf(" -U Userspace mode (do not sync with kernel/NDP driver)\n"); printf("Packet output parameters: (available for one queue only)\n"); printf(" -D dump Dump packet content to stdout (char, all, header, data)\n"); @@ -156,6 +157,7 @@ int main(int argc, char *argv[]) params.pcap_filename = NULL; params.limit_bytes = 0; params.limit_packets = 0; + params.use_userspace_flag = 0; params.use_delay_nsec = 1; list_range_init(&queue_range); @@ -237,6 +239,9 @@ int main(int argc, char *argv[]) case 'P': params.use_delay_nsec = 0; break; + case 'U': + params.use_userspace_flag = 1; + break; case 'h': usage(argv[0], strmode == argv[1]); exit(0); diff --git a/tools/ndptool/read.c b/tools/ndptool/read.c index 6571300b..49beffd5 100644 --- a/tools/ndptool/read.c +++ b/tools/ndptool/read.c @@ -75,7 +75,7 @@ static int ndp_mode_read_prepare(struct ndp_tool_params *p) goto err_nfb_open; } - p->rx = ndp_open_rx_queue(p->dev, p->queue_index); + p->rx = ndp_open_rx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); if (p->rx == NULL) { warnx("ndp_open_rx_queue(%d) failed.", p->queue_index); goto err_ndp_open_rx; diff --git a/tools/ndptool/receive.c b/tools/ndptool/receive.c index a93fd217..cfaee6a2 100644 --- a/tools/ndptool/receive.c +++ b/tools/ndptool/receive.c @@ -85,7 +85,7 @@ static int ndp_mode_receive_prepare(struct ndp_tool_params *p) goto err_nfb_open; } - p->rx = ndp_open_rx_queue(p->dev, p->queue_index); + p->rx = ndp_open_rx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); if (p->rx == NULL) { warnx("ndp_open_rx_queue(%d) failed.", p->queue_index); goto err_ndp_open_rx; diff --git a/tools/ndptool/transmit.c b/tools/ndptool/transmit.c index f8fb1fbc..f23c7e0c 100644 --- a/tools/ndptool/transmit.c +++ b/tools/ndptool/transmit.c @@ -119,7 +119,7 @@ static int ndp_mode_transmit_prepare(struct ndp_tool_params *p, struct pcap_src goto err_nfb_open; } - p->tx = ndp_open_tx_queue(p->dev, p->queue_index); + p->tx = ndp_open_tx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); if (p->tx == NULL) { warnx("ndp_open_tx_queue(%d) failed.", p->queue_index); goto err_ndp_open_tx; From a3f80ac825341c1b9714bb8b41f8f9dde0ddc41d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 18 Dec 2023 16:25:35 +0100 Subject: [PATCH 046/518] libnetcope: [FIX] convert types correctly for cpp without -fpermissive --- libnfb/include/netcope/adc_sensors.h | 0 libnfb/include/netcope/dma_ctrl_ndp.h | 4 ++-- libnfb/include/netcope/eth.h | 4 ++-- libnfb/include/netcope/idcomp.h | 6 +++--- libnfb/include/netcope/ieee802_3.h | 4 ++++ libnfb/include/netcope/info.h | 10 +++++----- libnfb/include/netcope/mac.h | 4 ++-- libnfb/include/netcope/mdio.h | 2 +- libnfb/include/netcope/nic_rss.h | 4 ++-- libnfb/include/netcope/rxmac.h | 8 ++++---- libnfb/include/netcope/txmac.h | 3 ++- 11 files changed, 27 insertions(+), 22 deletions(-) mode change 100755 => 100644 libnfb/include/netcope/adc_sensors.h mode change 100755 => 100644 libnfb/include/netcope/idcomp.h diff --git a/libnfb/include/netcope/adc_sensors.h b/libnfb/include/netcope/adc_sensors.h old mode 100755 new mode 100644 diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 02c2c74c..fcc088c0 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -457,13 +457,13 @@ static inline int nc_ndp_ctrl_get_mtu(struct nc_ndp_ctrl *ctrl, unsigned int *mi ctrl_offset = fdt_path_offset(fdt, nfb_comp_path(ctrl->comp)); ctrl_params_offset = fdt_node_offset_by_phandle_ref(fdt, ctrl_offset, "params"); - prop = fdt_getprop(fdt, ctrl_params_offset, "frame_size_min", &proplen); + prop = (const fdt32_t*) fdt_getprop(fdt, ctrl_params_offset, "frame_size_min", &proplen); if (proplen == sizeof(*prop)) *min = fdt32_to_cpu(*prop); else ret -= 1; - prop = fdt_getprop(fdt, ctrl_params_offset, "frame_size_max", &proplen); + prop = (const fdt32_t*) fdt_getprop(fdt, ctrl_params_offset, "frame_size_max", &proplen); if (proplen == sizeof(*prop)) *max = fdt32_to_cpu(*prop); else diff --git a/libnfb/include/netcope/eth.h b/libnfb/include/netcope/eth.h index 0566dcc6..3696dcac 100644 --- a/libnfb/include/netcope/eth.h +++ b/libnfb/include/netcope/eth.h @@ -34,11 +34,11 @@ static inline int nc_eth_get_pcspma_control_node(const void *fdt, int nodeoffset int proplen; const fdt32_t *prop32; - prop32 = fdt_getprop(fdt, nodeoffset, "pcspma", &proplen); + prop32 = (const fdt32_t*) fdt_getprop(fdt, nodeoffset, "pcspma", &proplen); if (proplen == sizeof(*prop32)) node_pcspma = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*prop32)); - prop32 = fdt_getprop(fdt, node_pcspma, "control", &proplen); + prop32 = (const fdt32_t*) fdt_getprop(fdt, node_pcspma, "control", &proplen); if (proplen == sizeof(*prop32)) node_ctrl = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*prop32)); diff --git a/libnfb/include/netcope/idcomp.h b/libnfb/include/netcope/idcomp.h old mode 100755 new mode 100644 index 6256f2fd..3288cabc --- a/libnfb/include/netcope/idcomp.h +++ b/libnfb/include/netcope/idcomp.h @@ -63,7 +63,7 @@ static inline void nc_idcomp_repeater_set(struct nfb_device *dev, unsigned index node = nfb_comp_find(dev, COMP_NETCOPE_ETH, index); if (node >= 0) { - prop32 = fdt_getprop(nfb_get_fdt(dev), node, "repeater-reg-index", &len); + prop32 = (const fdt32_t*) fdt_getprop(nfb_get_fdt(dev), node, "repeater-reg-index", &len); if (len == sizeof(*prop32)) index = fdt32_to_cpu(*prop32); } @@ -92,7 +92,7 @@ static inline enum nc_idcomp_repeater nc_idcomp_repeater_get(struct nfb_device * node = nfb_comp_find(dev, COMP_NETCOPE_ETH, index); if (node >= 0) { - prop32 = fdt_getprop(nfb_get_fdt(dev), node, "repeater-reg-index", &len); + prop32 = (const fdt32_t*) fdt_getprop(nfb_get_fdt(dev), node, "repeater-reg-index", &len); if (len == sizeof(*prop32)) index = fdt32_to_cpu(*prop32); } @@ -105,7 +105,7 @@ static inline enum nc_idcomp_repeater nc_idcomp_repeater_get(struct nfb_device * nfb_comp_close(comp); - return (reg >> (index * 2)) & 3; + return (enum nc_idcomp_repeater) ((reg >> (index * 2)) & 3); } #ifdef __cplusplus diff --git a/libnfb/include/netcope/ieee802_3.h b/libnfb/include/netcope/ieee802_3.h index e943754c..7e145ee9 100644 --- a/libnfb/include/netcope/ieee802_3.h +++ b/libnfb/include/netcope/ieee802_3.h @@ -80,4 +80,8 @@ static inline int ieee802_3_get_pcs_speed_value(struct mdio_if_info *if_info) } } +#ifdef __cplusplus +} // extern "C" +#endif + #endif /* NETCOPE_IEEE802_3_H */ diff --git a/libnfb/include/netcope/info.h b/libnfb/include/netcope/info.h index 461380a5..43ed7914 100644 --- a/libnfb/include/netcope/info.h +++ b/libnfb/include/netcope/info.h @@ -102,7 +102,7 @@ static inline int nc_get_composed_device_info_by_pci(struct nfb_device *dev, prop = fdt_getprop(fdt, subnode, "pci-slot", NULL); if (device_found == 0) { info->ep_index++; - if (pciname && prop && strcmp(prop, pciname) == 0) { + if (pciname && prop && strcmp((const char*) prop, pciname) == 0) { device_found = 1; } } @@ -229,7 +229,7 @@ static inline int nc_ifc_map_info_create_ordinary(struct nfb_device *nfb, struct fdt_for_each_compatible_node(fdt, node, COMP_NETCOPE_ETH) { /* Alloc interface info for each Ethernet channel */ - info = realloc(mi->ifc, sizeof(*info) * (ifc + 1)); + info = (struct nc_ifc_info *) realloc(mi->ifc, sizeof(*info) * (ifc + 1)); if (info == NULL) { goto err_alloc; } @@ -247,7 +247,7 @@ static inline int nc_ifc_map_info_create_ordinary(struct nfb_device *nfb, struct info->eth_cnt = 1; /* Assign Ethernet channel to interface */ - eth_info = realloc(mi->eth, sizeof(*eth_info) * (eth + 1)); + eth_info = (struct nc_ifc_eth_map_info*) realloc(mi->eth, sizeof(*eth_info) * (eth + 1)); if (eth_info == NULL) { goto err_alloc; } @@ -289,7 +289,7 @@ static inline int nc_ifc_map_info_create_ordinary(struct nfb_device *nfb, struct } if (ifc == 0) { - info = realloc(mi->ifc, sizeof(*info) * (ifc + 1)); + info = (struct nc_ifc_info*) realloc(mi->ifc, sizeof(*info) * (ifc + 1)); if (info == NULL) { goto err_alloc; } @@ -320,7 +320,7 @@ static inline int nc_ifc_map_info_create_ordinary(struct nfb_device *nfb, struct mi->rxq_cnt = ndp_get_rx_queue_count(nfb); mi->txq_cnt = ndp_get_tx_queue_count(nfb); - mi->rxq = malloc(sizeof(*mi->rxq) * (mi->rxq_cnt + mi->txq_cnt)); + mi->rxq = (struct nc_ifc_queue_map_info*) malloc(sizeof(*mi->rxq) * (mi->rxq_cnt + mi->txq_cnt)); if (mi->rxq == NULL) { goto err_alloc; } diff --git a/libnfb/include/netcope/mac.h b/libnfb/include/netcope/mac.h index 57160b1a..8233ddf8 100644 --- a/libnfb/include/netcope/mac.h +++ b/libnfb/include/netcope/mac.h @@ -53,7 +53,7 @@ nc_ifc_get_default_mac(struct nfb_device *dev, unsigned ifc_nr, uint8_t *addr_by fdt = nfb_get_fdt(dev); node = fdt_path_offset(fdt, "/board/"); - prop = fdt_getprop(fdt, node, "board-name", &len); + prop = (const char*) fdt_getprop(fdt, node, "board-name", &len); if (prop == NULL) return -ENODEV; @@ -80,7 +80,7 @@ nc_ifc_get_default_mac(struct nfb_device *dev, unsigned ifc_nr, uint8_t *addr_by if (type == -1) return -ENODEV; - prop32 = fdt_getprop(fdt, node, "serial-number", &len); + prop32 = (const uint32_t*) fdt_getprop(fdt, node, "serial-number", &len); if (len < 0) return -ENODEV; diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index f92cd7fe..1cc127c6 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -293,7 +293,7 @@ static inline struct nc_mdio *nc_mdio_open(const struct nfb_device *dev, int fdt int e_tile = 0; int f_tile = 0; - prop = fdt_getprop(nfb_get_fdt(dev), fdt_offset_ctrlparam, "ip-name", &proplen); + prop = (const char*) fdt_getprop(nfb_get_fdt(dev), fdt_offset_ctrlparam, "ip-name", &proplen); if (proplen > 0) { if (strcmp(prop, "E_TILE") == 0) { e_tile = 1; diff --git a/libnfb/include/netcope/nic_rss.h b/libnfb/include/netcope/nic_rss.h index feabb57b..f6ab32ff 100644 --- a/libnfb/include/netcope/nic_rss.h +++ b/libnfb/include/netcope/nic_rss.h @@ -37,12 +37,12 @@ static inline struct nc_nic_rss *nc_nic_rss_open(struct nfb_device *dev, int fdt rss = (struct nc_nic_rss*) nfb_comp_to_user(comp); - prop = fdt_getprop(nfb_get_fdt(dev), fdt_offset, "reta_capacity", &proplen); + prop = (const fdt32_t*) fdt_getprop(nfb_get_fdt(dev), fdt_offset, "reta_capacity", &proplen); if (proplen != sizeof(*prop)) goto err_prop; rss->reta_capacity = fdt32_to_cpu(*prop); - prop = fdt_getprop(nfb_get_fdt(dev), fdt_offset, "key_size", &proplen); + prop = (const fdt32_t*) fdt_getprop(nfb_get_fdt(dev), fdt_offset, "key_size", &proplen); if (proplen != sizeof(*prop)) goto err_prop; rss->key_size = fdt32_to_cpu(*prop); diff --git a/libnfb/include/netcope/rxmac.h b/libnfb/include/netcope/rxmac.h index 050ef796..765bc1e7 100644 --- a/libnfb/include/netcope/rxmac.h +++ b/libnfb/include/netcope/rxmac.h @@ -218,13 +218,13 @@ static inline struct nc_rxmac *nc_rxmac_open(struct nfb_device *dev, int fdt_off mac = (struct nc_rxmac *) nfb_comp_to_user(comp); - prop = fdt_getprop(nfb_get_fdt(dev), fdt_offset, "version", &proplen); + prop = (const fdt32_t*) fdt_getprop(nfb_get_fdt(dev), fdt_offset, "version", &proplen); if (proplen == sizeof(*prop)) version = fdt32_to_cpu(*prop); mac->has_counter_below_64 = version >= 0x00000002; - prop = fdt_getprop(nfb_get_fdt(dev), fdt_offset, "mtu", &proplen); + prop = (const fdt32_t*) fdt_getprop(nfb_get_fdt(dev), fdt_offset, "mtu", &proplen); if (proplen == sizeof(*prop)) mac->mtu = fdt32_to_cpu(*prop); @@ -282,7 +282,7 @@ static inline int nc_rxmac_read_status(struct nc_rxmac *mac, struct nc_rxmac_sta s->enabled = nfb_comp_read32(comp, RXMAC_REG_ENABLE); s->error_mask = nfb_comp_read32(comp, RXMAC_REG_ERROR_MASK); - s->mac_filter = nfb_comp_read32(comp, RXMAC_REG_MAC_FILTER); + s->mac_filter = (enum nc_rxmac_mac_filter) nfb_comp_read32(comp, RXMAC_REG_MAC_FILTER); s->frame_length_min = nfb_comp_read32(comp, RXMAC_REG_FRAME_LEN_MIN); s->frame_length_max = nfb_comp_read32(comp, RXMAC_REG_FRAME_LEN_MAX); @@ -295,7 +295,7 @@ static inline int nc_rxmac_read_status(struct nc_rxmac *mac, struct nc_rxmac_sta s->frame_length_max_capable = mac->mtu; - s->speed = (reg >> 4) & 0x7; + s->speed = (enum nc_mac_speed) ((reg >> 4) & 0x7); switch (s->speed) { case MAC_SPEED_10G: case MAC_SPEED_40G: diff --git a/libnfb/include/netcope/txmac.h b/libnfb/include/netcope/txmac.h index c85fc6a3..47668c31 100644 --- a/libnfb/include/netcope/txmac.h +++ b/libnfb/include/netcope/txmac.h @@ -10,6 +10,7 @@ #ifndef NETCOPE_TXMAC_H #define NETCOPE_TXMAC_H + #ifdef __cplusplus extern "C" { #endif @@ -124,7 +125,7 @@ static inline int nc_txmac_read_status(struct nc_txmac *mac, struct nc_txmac_sta s->enabled = nfb_comp_read32(comp, TXMAC_REG_ENABLE); reg = nfb_comp_read32(comp, TXMAC_REG_STATUS); - s->speed = (reg >> 4) & 0x7; + s->speed = (enum nc_mac_speed) ((reg >> 4) & 0x7); switch (s->speed) { case MAC_SPEED_10G: case MAC_SPEED_40G: From 390a828c69f040ecb457253be820cfa30d945119 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 19 Dec 2023 06:45:11 +0100 Subject: [PATCH 047/518] bump version to 6.20.1 --- Changelog | 5 +++++ VERSION | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index b1fba761..69bdf5db 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +* Tue Dec 19 2023 Martin Spinler - 6.20.1-1 +- [BUGFIX] fixes pynfb circular reference in Nfb class +- [BUGFIX] fixes E-Tile RX EQ adaptation on return from loopback +- [BUGFIX] convert types explicitly for c++ build without -fpermissive + * Tue Nov 14 2023 Martin Spinler - 6.20.0-1 - [FEATURE] base support for DMA Calypte controllers - [BUGFIX] fixes E-Tile loopback operation diff --git a/VERSION b/VERSION index a7c176ac..00825aa9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.20.0 +6.20.1 From abff8c3d6b63f4494a5917c4a9bf50d58e778492 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 12 Jan 2024 15:49:27 +0100 Subject: [PATCH 048/518] drivers: [FEATURE] enable common QSPI Flash memories --- drivers/kernel/drivers/nfb/boot/flash.c | 98 ++++++++++++++----------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/flash.c b/drivers/kernel/drivers/nfb/boot/flash.c index 7e02a910..d1f943c9 100644 --- a/drivers/kernel/drivers/nfb/boot/flash.c +++ b/drivers/kernel/drivers/nfb/boot/flash.c @@ -35,8 +35,6 @@ #include "sdm.h" -#define QSPI_OVERRIDE_COMMANDS - inline uint16_t nfb_boot_flash_read16(struct nfb_boot *boot) { int i = 0; @@ -341,13 +339,13 @@ static ssize_t axi_qspi_transfer(struct spi_nor *nor, uint8_t opcode, loff_t add memcpy(tx + 1 + addr_width, tx_buf, len); memset(rx, 0, t.len); -#ifdef QSPI_OVERRIDE_COMMANDS - ret = xilinx_spi_txrx_bufs_continuous(boot->spi, &t); -#else - xilinx_spi_chipselect(boot->spi, 1); - ret = xilinx_spi_txrx_bufs(boot->spi, &t); - xilinx_spi_chipselect(boot->spi, 0); -#endif + if (1 || NFB_IS_TIVOLI(boot->nfb)) { + ret = xilinx_spi_txrx_bufs_continuous(boot->spi, &t); + } else { + xilinx_spi_chipselect(boot->spi, 1); + ret = xilinx_spi_txrx_bufs(boot->spi, &t); + xilinx_spi_chipselect(boot->spi, 0); + } if (rx_buf) memcpy(rx_buf, rx + 1 + addr_width + rx_dummy, len); @@ -364,11 +362,14 @@ static int axi_qspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) static int axi_qspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) { -#ifdef QSPI_OVERRIDE_COMMANDS - if (opcode == SPINOR_OP_EN4B) { - return 0; + struct nfb_boot *boot = (struct nfb_boot *)nor->priv; + + if (NFB_IS_TIVOLI(boot->nfb)) { + if (opcode == SPINOR_OP_EN4B) { + return 0; + } } -#endif + axi_qspi_transfer(nor, opcode, 0, 0, 0, len, NULL, buf); return 0; } @@ -379,16 +380,19 @@ static ssize_t axi_qspi_read(struct spi_nor *nor, loff_t from, size_t len, u_cha ssize_t ret; int addr_width = nor->addr_width; int read_dummy = nor->read_dummy; -#ifdef QSPI_OVERRIDE_COMMANDS - uint8_t segment = from / (16*1024*1024); - addr_width = 3; - read_dummy = 4; - axi_qspi_write_reg(nor, SPINOR_OP_WREN, 0, 0); - axi_qspi_write_reg(nor, SPINOR_OP_WREAR, (uint8_t*)&segment, 1); - ret = axi_qspi_transfer(nor, SPINOR_OP_READ_1_1_4, from, addr_width, read_dummy, len, buf, NULL); -#else - ret = axi_qspi_transfer(nor, nor->read_opcode, from, nor->addr_width, nor->read_dummy, len, buf, NULL); -#endif + + struct nfb_boot *boot = (struct nfb_boot *)nor->priv; + + if (NFB_IS_TIVOLI(boot->nfb)) { + uint8_t segment = from / (16*1024*1024); + addr_width = 3; + read_dummy = 4; + axi_qspi_write_reg(nor, SPINOR_OP_WREN, 0, 0); + axi_qspi_write_reg(nor, SPINOR_OP_WREAR, (uint8_t*)&segment, 1); + ret = axi_qspi_transfer(nor, SPINOR_OP_READ_1_1_4, from, addr_width, read_dummy, len, buf, NULL); + } else { + ret = axi_qspi_transfer(nor, nor->read_opcode, from, nor->addr_width, nor->read_dummy, len, buf, NULL); + } if (ret <= 0) return ret; @@ -399,33 +403,38 @@ static ssize_t axi_qspi_write(struct spi_nor *nor, loff_t to, size_t len, const { ssize_t ret; int addr_width = nor->addr_width; -#ifdef QSPI_OVERRIDE_COMMANDS - uint8_t segment = to / (16 * 1024 * 1024); - addr_width = 3; - axi_qspi_write_reg(nor, SPINOR_OP_WREAR, (uint8_t*)&segment, 1); - axi_qspi_write_reg(nor, SPINOR_OP_WREN, 0, 0); - ret = axi_qspi_transfer(nor, SPINOR_OP_PP_1_1_4, to, 3, 0, len, NULL, buf); -#else - ret = axi_qspi_transfer(nor, nor->program_opcode, to, addr_width, 0, len, NULL, buf); -#endif + + struct nfb_boot *boot = (struct nfb_boot *)nor->priv; + + if (NFB_IS_TIVOLI(boot->nfb)) { + uint8_t segment = to / (16 * 1024 * 1024); + addr_width = 3; + axi_qspi_write_reg(nor, SPINOR_OP_WREAR, (uint8_t*)&segment, 1); + axi_qspi_write_reg(nor, SPINOR_OP_WREN, 0, 0); + ret = axi_qspi_transfer(nor, SPINOR_OP_PP_1_1_4, to, 3, 0, len, NULL, buf); + } else { + ret = axi_qspi_transfer(nor, nor->program_opcode, to, addr_width, 0, len, NULL, buf); + } if (ret <= 0) return ret; return max_t(ssize_t, 0, ret - 1 - addr_width); } -#ifdef QSPI_OVERRIDE_COMMANDS static int axi_qspi_erase(struct spi_nor *nor, loff_t off) { int addr_width = nor->addr_width; - uint8_t segment = off / (16*1024*1024); - addr_width = 3; - axi_qspi_write_reg(nor, SPINOR_OP_WREN, 0, 0); - axi_qspi_write_reg(nor, SPINOR_OP_WREAR, (uint8_t*)&segment, 1); + struct nfb_boot *boot = (struct nfb_boot *)nor->priv; + + if (NFB_IS_TIVOLI(boot->nfb)) { + uint8_t segment = off / (16*1024*1024); + addr_width = 3; + axi_qspi_write_reg(nor, SPINOR_OP_WREN, 0, 0); + axi_qspi_write_reg(nor, SPINOR_OP_WREAR, (uint8_t*)&segment, 1); + } axi_qspi_write_reg(nor, SPINOR_OP_WREN, 0, 0); axi_qspi_transfer(nor, SPINOR_OP_SE, off, addr_width, 0, 0, 0, 0); return 0; } -#endif int nfb_boot_mtd_init(struct nfb_boot *nfb_boot) { @@ -479,17 +488,20 @@ int nfb_boot_mtd_init(struct nfb_boot *nfb_boot) nor->erase = sdm_qspi_erase; nor->mtd.name = "sdm_qspi_nor"; } else { + nor->mtd.name = "axi_qspi_nor"; + nor->read = axi_qspi_read; nor->read_reg = axi_qspi_read_reg; nor->write = axi_qspi_write; nor->write_reg = axi_qspi_write_reg; -#ifdef QSPI_OVERRIDE_COMMANDS - nor->erase = axi_qspi_erase; -#endif - nor->mtd.name = "axi_qspi_nor"; + if (NFB_IS_TIVOLI(nfb_boot->nfb)) { + nor->erase = axi_qspi_erase; + + /* Workaround for HW bug? Dummy read */ + axi_qspi_read_reg(nor, SPINOR_OP_RDFSR, (uint8_t*)&ret, 1); + } - /* Workaround for HW bug? Dummy read */ axi_qspi_read_reg(nor, SPINOR_OP_RDFSR, (uint8_t*)&ret, 1); } From d3263f71aee3feb1ff856aa88214b54b1d0c6538 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 12 Jan 2024 15:53:33 +0100 Subject: [PATCH 049/518] drivers: [FEATURE] add suppport for Alveo cards - Alveo U200, U250, U55C - Alveo UL3524 --- drivers/kernel/drivers/nfb/pci.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 2eb16a02..c5bd72bf 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -310,6 +310,23 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) n6010_binary_slot_prepare(fdt, subnode, "\x00\x00\x01\x00", "\xff\xff\xff\xff", 4); subnode = nfb_fdt_create_binary_slot(fdt, node, "image0", "fpga_user1", 0, 3, -1, 0, 0); n6010_binary_slot_prepare(fdt, subnode, "\x00\x00\x00\x00", "\xff\xff\xff\xff", 4); + } else if (!strcmp(card_name, "ALVEO_U200") || !strcmp(card_name, "ALVEO_U250") || !strcmp(card_name, "ALVEO_U55C")) { + prop32 = cpu_to_fdt32(1); + fdt_appendprop(fdt, node, "num_flash", &prop32, sizeof(prop32)); + prop32 = cpu_to_fdt32(128 * 1024 * 1024); + fdt_appendprop(fdt, node, "mtd_size", &prop32, sizeof(prop32)); + + nfb_fdt_create_binary_slot(fdt, node, "image0", "application0" , 0, 0, 0, 0x01002000, 0x04000000); + + nfb_fdt_create_boot_type(fdt, node, "SPI", 4); + } else if (!strcmp(card_name, "ALVEO_UL3524")) { + prop32 = cpu_to_fdt32(1); + fdt_appendprop(fdt, node, "num_flash", &prop32, sizeof(prop32)); + prop32 = cpu_to_fdt32(256 * 1024 * 1024); + fdt_appendprop(fdt, node, "mtd_size", &prop32, sizeof(prop32)); + nfb_fdt_create_binary_slot(fdt, node, "image0", "application0" , 0, 0, 0, 0x01002000, 0x04000000); + + nfb_fdt_create_boot_type(fdt, node, "SPI", 4); } } } From 4eb3fa8c18f8bf2ba2b83fd4750c2b933e61cfc1 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 Feb 2024 11:10:28 +0100 Subject: [PATCH 050/518] drivers: [FIX] constant sized array --- drivers/kernel/drivers/nfb/boot/sdm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/sdm.c b/drivers/kernel/drivers/nfb/boot/sdm.c index daf82580..a326bd0a 100644 --- a/drivers/kernel/drivers/nfb/boot/sdm.c +++ b/drivers/kernel/drivers/nfb/boot/sdm.c @@ -395,8 +395,9 @@ int sdm_qspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) struct nfb_boot *boot = (struct nfb_boot *)nor->priv; // max number of bytes to read - int len_base = 8; - u8 buf_base[len_base]; + #define SDM_QSPI_RR_LEN_BASE 8 + int len_base = SDM_QSPI_RR_LEN_BASE; + u8 buf_base[SDM_QSPI_RR_LEN_BASE]; int vendor_id; int device_id; From f9f35f933c1bd97ad3175a2da453646a73f87605 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 Feb 2024 12:51:00 +0100 Subject: [PATCH 051/518] build: [MAINTENANCE] update version of 3rdparty archive --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index f5315e3c..10cc2209 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ AUTOINSTALL=true # whether dependencies should be installed with '-y' RELTYPE=Release # Release type (Debug/Release) FILENAME_3RDPARTY="3rdparty.tar.gz" -SRC_3RDPARTY_VERSION="v6.19.0" +SRC_3RDPARTY_VERSION="v6.19.5" URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_VERSION/$FILENAME_3RDPARTY" EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" From 8ece402ce6ed11d79a8cfdba763bad0c5ffbdc4e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 Feb 2024 17:38:17 +0100 Subject: [PATCH 052/518] libnetcope: [FIX] unused parameter in ndp.h --- libnfb/include/netcope/ndp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index cd9e751e..d7804ac1 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -144,6 +144,7 @@ static inline int nc_ndp_v2_open_queue(struct nc_ndp_queue *q, const void *fdt, static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, int fdt_offset, int ctrl_offset, int dir) { + (void)dir; #ifndef __KERNEL__ int prot; int ret = 0; From 07c518afee785f827827bb3e91c93874636ba88c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 Feb 2024 17:40:06 +0100 Subject: [PATCH 053/518] build.sh: [MAINTENANCE] simplify OS check for RPM build --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 10cc2209..30a5a8fc 100755 --- a/build.sh +++ b/build.sh @@ -304,7 +304,7 @@ for opt in "$@"; do rm -rf "$SCRIPT_PATH/$BUILDDIR" ;; --rpm) - if [ "$os" != "centos" ] && [ "$os" != "scientific" ] && [ "$os" != "fedora" ] && [ "$os" != "ol" ] ; then + if ! item_in_list "$os" "centos scientific fedora ol rocky"; then echo >&2 "ERROR: Cannot build RPM package on other OS than CentOS" exit 1 fi @@ -312,7 +312,7 @@ for opt in "$@"; do $cpack -G RPM --config ./CPackConfig.cmake ;; --rpm-dpdk) - if [ "$os" != "centos" ] && [ "$os" != "scientific" ] && [ "$os" != "fedora" ] && [ "$os" != "ol" ] ; then + if ! item_in_list "$os" "centos scientific fedora ol rocky"; then echo >&2 "ERROR: Cannot build RPM package on other OS than CentOS" exit 1 fi From 24cd958d327217c41345e51494eadb5b25a1b019 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 27 Feb 2024 12:07:43 +0100 Subject: [PATCH 054/518] bump version to 6.21.0 --- Changelog | 5 +++++ VERSION | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 69bdf5db..648389ab 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +* Tue Feb 27 2024 Martin Spinler - 6.21.0-1 +- [OPT] added performance and userspace mode in ndp-tool +- [OPT] some optimalitazions for DMA Calypte controllers +- [FEATURE] added support for some Alveo cards + * Tue Dec 19 2023 Martin Spinler - 6.20.1-1 - [BUGFIX] fixes pynfb circular reference in Nfb class - [BUGFIX] fixes E-Tile RX EQ adaptation on return from loopback diff --git a/VERSION b/VERSION index 00825aa9..7ecad140 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.20.1 +6.21.0 From a12e5fbd5303986c3e9230b5c5429ca6cbef6899 Mon Sep 17 00:00:00 2001 From: David Vodak Date: Mon, 4 Mar 2024 08:16:35 +0100 Subject: [PATCH 055/518] ndptools: [FEATURE] support SIGTERM handling for ndp-tools Since there was no handling, terminating ndp-tools would result in return value 1: $ ndp-read # is going to be terminated by SIGTERM $ echo $? 1 Now it behaves just like when handling SIGINT: $ ndp-read # is going to be terminated by SIGTERM ----------------------------------- NDP read stats ---- Packets : 0 Bytes : 0 Avg speed [Mpps] : 0.000 Avg speed L1 [Mb/s] : 0.000 Avg speed L2 [Mb/s] : 0.000 Time : 9.283 $ echo $? 0 --- tools/ndptool/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/ndptool/main.c b/tools/ndptool/main.c index 9f34d05d..b3fece19 100644 --- a/tools/ndptool/main.c +++ b/tools/ndptool/main.c @@ -40,7 +40,7 @@ struct ndptool_module *module = NULL; */ static void sig_usr(int signo) { - if (signo == SIGINT) { + if (signo == SIGINT || signo == SIGTERM) { stop = 1; } else if (signo == SIGUSR1) { stats = 1; @@ -288,6 +288,7 @@ int main(int argc, char *argv[]) } /* register SIGINT signal */ signal(SIGINT, sig_usr); + signal(SIGTERM, sig_usr); signal(SIGUSR1, sig_usr); /* Use single queue = don't use threads (at this moment) */ From 2c04a5d609d0eed495e4ba7370a281502ed29b25 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 8 Feb 2024 12:51:48 +0100 Subject: [PATCH 056/518] nfb-meter: [FEATURE] first version of tool for performance monitoring --- CMakeLists.txt | 3 + python/nfb-tools/CMakeLists.txt | 40 +++ python/nfb-tools/nfb-tools.cmake | 28 ++ python/nfb-tools/nfbmeter/__init__.py | 0 python/nfb-tools/nfbmeter/busdebug.py | 70 ++++ python/nfb-tools/nfbmeter/eventcounter.py | 134 ++++++++ python/nfb-tools/nfbmeter/nfbmeter.py | 397 ++++++++++++++++++++++ python/nfb-tools/nfbmeter/probes.py | 57 ++++ python/nfb-tools/nfbmeter/utils.py | 24 ++ python/nfb-tools/pyproject.toml | 10 + python/nfb-tools/setup.py | 11 + python/nfb-tools/setup.py.in | 11 + 12 files changed, 785 insertions(+) create mode 100644 python/nfb-tools/CMakeLists.txt create mode 100644 python/nfb-tools/nfb-tools.cmake create mode 100644 python/nfb-tools/nfbmeter/__init__.py create mode 100644 python/nfb-tools/nfbmeter/busdebug.py create mode 100644 python/nfb-tools/nfbmeter/eventcounter.py create mode 100755 python/nfb-tools/nfbmeter/nfbmeter.py create mode 100644 python/nfb-tools/nfbmeter/probes.py create mode 100644 python/nfb-tools/nfbmeter/utils.py create mode 100644 python/nfb-tools/pyproject.toml create mode 100644 python/nfb-tools/setup.py create mode 100644 python/nfb-tools/setup.py.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 55c7642c..5193a865 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,9 @@ add_subdirectory(tools-debug) add_subdirectory(tools-misc) add_subdirectory(utils) add_subdirectory(pynfb) +add_subdirectory(python/nfb-tools) + +include(python/nfb-tools/nfb-tools.cmake) configure_file(package/preinst.in package/preinst @ONLY) configure_file(package/postinst.in package/postinst @ONLY) diff --git a/python/nfb-tools/CMakeLists.txt b/python/nfb-tools/CMakeLists.txt new file mode 100644 index 00000000..7169ebc6 --- /dev/null +++ b/python/nfb-tools/CMakeLists.txt @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# CMake build file for NFB python tools +# +# Copyright (C) 2022 CESNET +# Author(s): +# Martin Spinler +# +# SPDX-License-Identifier: BSD-3-Clause + +import sys +import logging +import subprocess +import time +import os +import csv +import signal +import datetime +import argparse +import json +import re +import types +import yaml +from types import SimpleNamespace + +from os import linesep + +import nfb +import nfb.libnfb as libnfb +#import ofm + +#import busdebug +#import eventcounter + +import re +import curses + +from .utils import * +from .probes import * + + +class MeterManager(): + # Rename dict keys with this map> new_key: orig_key (nk: ok) + remaps = { + 'rxmac': {'packets': 'p', 'received': 'r', 'octets': 'b', 'discarded': 'd', 'overflowed': 'o'}, + 'rxdma': {'received': 'p', 'received_bytes': 'b', 'discarded': 'dp', 'discarded_bytes': 'db'}, + 'eventcounter': {'cycles': 'c', 'events': 'e', 'wraps': 'w'}, + 'busdebugprobe': {"words": 'w', "wait": 'i', "dst_hold": 'dh', "src_hold": 'sh', + 'sop_cnt': 'sc', 'eop_cnt': 'ec', + } + } + + def __init__(self, dev, config): + self._dev = dev + self._config = config + + self._rxmac = [eth.rxmac for eth in self._dev.eth] + self._rxdma = [dma for dma in self._dev.ndp.rx] + + self._bdc = {} + self._ech = {} + for p in self._config['probes']: + cfg = SimpleNamespace(**p) + if cfg.type == "event_counter_histogram": + probe = EventCounterHistogram(dev, cfg) + self._ech.update({cfg.id: probe}) + if cfg.type == "busdebug": + probe = BusDebugProbe(dev, cfg) + self._bdc.update({cfg.id: probe}) + + def init(self): + for probe in self._ech.values(): + probe.calibrate() + + for probe in self._ech.values(): + probe.start(True) + + self.lock() + self.strobe() + self._prev_sample = self.read() + self.unlock() + + self._items = { + "rxmac": [f"rm{i}" for i, _ in enumerate(self._rxmac)], + "rxdma": [f"rd{i}" for i, _ in enumerate(self._rxdma)], + "busdebugprobe": [ + *[f"{bd.id}_{bd.probe_name[p]}" for i, bd in enumerate(self._bdc.values()) for p in range(bd.nr_probes)], + ], + "eventcounter_histogram": list(self._ech.keys()), + } + + def read(self): + sample = SimpleNamespace() + sample.timestamp = time.time() + data = sample.data = {} + + for i, mac in enumerate(self._rxmac): + data[f"rm{i}"] = mac.stats_read() + + for i, dma in enumerate(self._rxdma): + data[f"rd{i}"] = dma.stats_read() + + for i, bd in enumerate(self._bdc.values()): + for p in range(bd.nr_probes): + data[f"{bd.id}_{bd.probe_name[p]}"] = bd.stats_read(p) + + for i, (id, ech) in enumerate(self._ech.items()): + data[id] = ech.stats_read_captured() + + return sample + + def measure(self): + self.lock() + self.strobe() + + sc = self.read() + sp = self._prev_sample + + rel = SimpleNamespace() + rel.timestamp = sc.timestamp + rel.interval = sc.timestamp - sp.timestamp + rel.data = {} + + # Compute difference of particular keys of all items with absolute value (no counter reset between two measurements) + diffable_items = self._items['rxmac'] + self._items['rxdma'] + self._items['busdebugprobe'] + for ic, ip, ik in [(sc.data[item], sp.data[item], item) for item in diffable_items]: + rel.data[ik] = {key: (ic[key] - ip[key]) for key in ic.keys()} + + # EventCounter does reset every time, is already relative + for ic, ik in [(sc.data[item], item) for item in self._items['eventcounter_histogram']]: + rel.data[ik] = ic + + self.unlock() + self._prev_sample = sc + return rel + + def to_json(self, m: SimpleNamespace): + """minimize measurement and convert to json""" + + ret = {} + ret['tp'] = 'm' # type of the record + + ret.update(vars(m)) + + if False and "remap": + ret['data'].update({ + **{unit_name: { + nk: m.data[unit_name][ok] for ok, nk in remap.items() + # if unit[ok] != 0 # Compress even more and do not include items with zero value + } for unit_type, remap in self.remaps.items() + for unit_name in self._items[unit_type] + } + }) + + x = json.dumps(ret) + return x + + def lock(self): + pass + + def unlock(self): + pass + + def strobe(self): + pass + + +def get_basic_info(dev): + info = SimpleNamespace() + t = dev.fdt.get_node("/firmware").get_property("build-time").value + info.build_time = datetime.datetime.fromtimestamp(t) + for item in ["project-version", "build-revision", "card-name", "project-name", "project-variant"]: + try: + setattr(info, item.replace("-", "_"), dev.fdt.get_node("/firmware").get_property(item).value) + except: + pass + + info.rxq_nr = len(dev.ndp.rx) + info.txq_nr = len(dev.ndp.tx) + #info.dts = dev.fdt.to_dts(tabsize=0) + return info + +def info_to_json(info): + ret = vars(info) + ret['tp'] = "info" # type of the record + ret['ver'] = "0.1.0" + ret['build_time'] = str(ret['build_time']) + return json.dumps(vars(info)) + +class MeterDisplay(): + def __init__(self, meter, config): + self._meter = meter + self._config = config + + if not self._config.get("display"): + self._config["display"] = [] + + def _display_rxmac(self, o, m, stdscr, items): + stdscr.addstr(o, 0, "RxMAC stats") + for i, it in enumerate(items['rxmac']): + item = m.data[it] + values = {s.title(): item[s] for s in ['packets', 'received', 'discarded', 'overflowed']} + for w, (text, val) in enumerate(values.items()): + stdscr.addstr(o+w+1, 2, text) + stdscr.addstr(o+w+1, i*12+12, f"{val:>10}") + return 6 + + def _display_rxdma(self, o, m, stdscr, items): + rows, cols = stdscr.getmaxyx() + dma_total_rcvd = sum(map(lambda x: m.data[x]['received'], items['rxdma'])) + dma_total_disc = sum(map(lambda x: m.data[x]['discarded'], items['rxdma'])) + dma_total = dma_total_rcvd + dma_total_disc + stdscr.addstr(o, 0, f"Rx DMA | Total: {dma_total:>11} | Received: {dma_total_rcvd:>11} | Discarded: {dma_total_disc:>11}") + for i, it in enumerate(items['rxdma']): + item = m.data[it] + stdscr.addstr(o+1, 2, f"% Received") + stdscr.addstr(o+2, 2, f"% Discarded") + + if (i+1)*12 + 12 >= cols: + continue + + pct_rcvd = int(item['received']*1000 / dma_total)/10 if dma_total != 0 else '-' + pct_disc = int(item['discarded']*1000 / dma_total)/10 if dma_total != 0 else '-' + + stdscr.addstr(o+1, i*6+14, f"{pct_rcvd:>6}") + stdscr.addstr(o+2, i*6+14, f"{pct_disc:>6}") + + return 4 + + def _display_busdebug(self, o, m, stdscr, config): + for i, it in enumerate(config.probes): + include = config.include if hasattr(config, "include") else self._meter._bdc[it].probe_name + for j, pname in enumerate(include): + item = m.data[f"{it}_{pname}"] + cycles, words, wait, dst_hold, src_hold = (item[x] for x in ['cycles', 'words', 'wait', 'dst_hold', 'src_hold']) + + words, wait, dst_hold, src_hold = \ + (int(x * 1000 / cycles) / 10 for x in [words, wait, dst_hold, src_hold]) + + stdscr.addstr(o+2+j, 0 , pname) + stdscr.addstr(o+1, 0, "%") + values = {"Words": words, "Idle": wait, "DST H": dst_hold, "SRC H": src_hold} + for w, (text, value) in enumerate(values.items()): + stdscr.addstr(o+1, 5+w*6 + i*30, text) + stdscr.addstr(o+2+j, 5+w*6 + i*30, f"{value:>5}") + return j + 4 + + def _display_histogram(self, o, m, stdscr, config): + prev_bins_names = None + probes = config.probes + + for i, it in enumerate(probes): + histograms = m.data[it] + ech = self._meter._ech[it] + + horiz = hasattr(config, 'style') and config.style == 'horizontal' + + #if prev_bins_names != histograms.keys(): + if prev_bins_names == None: + prev_bins_names = histograms.keys() + for j, bin_name in enumerate(prev_bins_names): + x, y = (2, j + 1) if horiz else (j*8+14, i) + stdscr.addstr(o+y, x, f"{bin_name:>8}") + + x, y = (i*8+12, o) if horiz else (2, o+i+1) + stdscr.addstr(y, x, ech.name) + + vals = histograms.values() + total = sum(vals) + for j, bin_value in enumerate(vals): + pct = int(bin_value*1000 / total) / 10 if total != 0 else '-' + x, y = (i*8+12, j + 1) if horiz else (j*8+14, i + 1) + stdscr.addstr(o+y, x, f"{pct:>8}") + + return 2 + len(prev_bins_names) if horiz else 1 + len(probes) + + def display(self, stdscr, m): + self._o = 0 + self._s = stdscr + + rows, cols = stdscr.getmaxyx() + items = self._meter._items + o = 0 + stdscr.addstr(o, 0, f"Time diff: {m.interval}") + o += 1 + + for config in self._config["display"]: + config = SimpleNamespace(**config) + if hasattr(config, "name"): + stdscr.addstr(o, 0, config.name) + + if config.type == "histogram": + o += self._display_histogram(o, m, stdscr, config) + + if config.type == "busdebug": + o += self._display_busdebug(o, m, stdscr, config) + + if config.type == "rxdma": + o += self._display_rxdma(o, m, stdscr, items) + + if config.type == "rxmac": + o += self._display_rxmac(o, m, stdscr, items) + + stdscr.refresh() + + +def meter_loop(stdscr, args, meter, logger, display): + print_once = True + t_toolstart = time.time() + t_start = time.time() + + m = meter.measure() + time.sleep(args.interval) + + while args.period == None or ((t_toolstart + args.period > t_start) if args.period is not None else True) or print_once: + t_start = time.time() + m = meter.measure() + logging.debug(meter.to_json(m)) + logger.writelines(meter.to_json(m) + linesep) + + if print_once: + if args.verbose: + print("First measurement:\n" + meter.to_json(m) + "\n") + print_once = False + time.sleep(args.interval) + + display.display(stdscr, m) + if isinstance(stdscr, NoCurses): + print("-" * 60) + + +def main(): + # Argument parsing + arguments = argparse.ArgumentParser(description='NFB universal measurement tool') + arguments.add_argument("-d", "--device", action="store", default=libnfb.Nfb.default_device) + arguments.add_argument("-l", "--logfile", action="store", default="/tmp/nfb-meter-stats_{pcislot}.txt") + arguments.add_argument("-v", "--verbose", action="store_true") + arguments.add_argument("-I", "--interval", action="store", default=1, type=float) + arguments.add_argument("-D", "--display", action="store", default=None, help='display mode') + arguments.add_argument("-P", "--period", action="store", default=None, type=float) + arguments.add_argument("-c", "--config", action="store", default=None) + args = arguments.parse_args() + + dev = nfb.open(args.device) + pcislot = dev.fdt.get_node("/system/device/endpoint0").get_property("pci-slot").value + + fn = args.logfile.format(pcislot=pcislot) + print(f"Logging to {fn}") + + bi = get_basic_info(dev) + logging.basicConfig(format='%(message)s', filename=fn, level=logging.DEBUG)#, encoding='utf-8') + logging.debug(info_to_json(bi)) + + info = SimpleNamespace() + t = dev.fdt.get_node("/firmware").get_property("build-time").value + for item in ["project-version", "build-revision", "card-name", "project-name", "project-variant"]: + try: + setattr(info, item.replace("-", "_"), dev.fdt.get_node("/firmware").get_property(item).value) + except: + pass + + # Load probe configuration + defcfg_path = "/usr/share/ndk-fw/" + defcfg_name = "nfb-meter-cfg" + + if args.config is None: + try: + args.config = f"{defcfg_path}{info.card_name}-{info.project_name}-{info.project_variant}-{info.project_version}-{defcfg_name}.yaml" + except: + raise Exception("Can't deduce default config filename, specify config file explicitly.") + + try: + with open(args.config) as stream: + config = yaml.safe_load(stream) + except: + raise Exception("Can't load configuration file.") + + assert config['version'] == "0.1", "Incorrect version of config file" + + # Init MeterManager and MeterDisplay + meter = MeterManager(dev, config) + meter.init() + + display = MeterDisplay(meter, config) + + # Log base informations + logging.debug(json.dumps({'tp':'units', **meter._items})) + if args.verbose: + print("Units:\n" + json.dumps({'tp':'units', **meter._items})) + print() + + # Run measurement loop + with open(fn, mode="a") as logger: + logger.write(info_to_json(get_basic_info(dev)) + linesep) + meter.unlock() + + wrapper = curses.wrapper if args.display else nocurses_wrapper + wrapper(meter_loop, args, meter, logger, display) + +if __name__ == '__main__': + main() diff --git a/python/nfb-tools/nfbmeter/probes.py b/python/nfb-tools/nfbmeter/probes.py new file mode 100644 index 00000000..c61e28dc --- /dev/null +++ b/python/nfb-tools/nfbmeter/probes.py @@ -0,0 +1,57 @@ +from .eventcounter import EventCounter as EvCntr +from .busdebug import BusDebugCtl + +from types import SimpleNamespace + +class Probe: + def __init__(self, dev, cfg): + self._dev = dev + self._cfg = cfg + self.name = self._cfg.name + self.id = self._cfg.id + + +class BusDebugProbe(BusDebugCtl, Probe): + def __init__(self, dev, cfg): + self._cfg_data = data = SimpleNamespace(**cfg.data) + super().__init__(dev=dev, node=dev.fdt.get_node(data.node)) + Probe.__init__(self, dev, cfg) + + +class EventCounterHistogram(Probe): + _calibration_groups = {} + + def __init__(self, dev, cfg): + super().__init__(dev, cfg) + + self._ec = [] + self._names = [] + cfg = self._cfg + self._cfg_data = data = SimpleNamespace(**cfg.data) + for bin in data.bins: + bin = SimpleNamespace(**bin) + ec = EvCntr(dev=dev, node=dev.fdt.get_node(bin.node)) + + cg = EventCounterHistogram._calibration_groups + if data.calibration_group not in cg: + cg.update({data.calibration_group: []}) + cg[data.calibration_group].append(ec) + + self._ec.append(ec) + self._names.append(bin.name) + + def calibrate(self): + ref = EventCounterHistogram._calibration_groups[self._cfg_data.calibration_group][0] + for ec in self._ec: + ec.calibrate(ref) + + def start(self, capture: bool = True): + for ec in self._ec: + ec.start(capture) + + def stats_read_captured(self): + s = [] + for ec in self._ec: + s.append(ec.stats_read_captured()) + return {self._names[i]: s[i]['events'] for i, ec in enumerate(self._ec)} + diff --git a/python/nfb-tools/nfbmeter/utils.py b/python/nfb-tools/nfbmeter/utils.py new file mode 100644 index 00000000..147e7d3a --- /dev/null +++ b/python/nfb-tools/nfbmeter/utils.py @@ -0,0 +1,24 @@ +import termios + +class NoCurses(): + def __init__(self): + self._buffers = [] + + def getmaxyx(self): + #return termios.tcgetwinsize(fd) + return 64, 180 + + def refresh(self): + for line in self._buffers: + print(line.rstrip()) + + def addstr(self, row, col, text): + y, x = self.getmaxyx() + while row >= len(self._buffers): + self._buffers.append(" " * x) + + orig = self._buffers[row] + self._buffers[row] = orig[:col] + text + orig[col+len(text):] + +def nocurses_wrapper(fn, *args, **kwargs): + fn(NoCurses(), *args, **kwargs) diff --git a/python/nfb-tools/pyproject.toml b/python/nfb-tools/pyproject.toml new file mode 100644 index 00000000..caa679c6 --- /dev/null +++ b/python/nfb-tools/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "nfb-tools" +version = "0.1.0" +dependencies = [] + +[project.scripts] +nfb-meter = "nfbmeter.nfbmeter:main" + +[tool.setuptools] +packages = ["nfbmeter"] diff --git a/python/nfb-tools/setup.py b/python/nfb-tools/setup.py new file mode 100644 index 00000000..835cdfce --- /dev/null +++ b/python/nfb-tools/setup.py @@ -0,0 +1,11 @@ +from setuptools import setup + +setup( + packages=["nfbmeter"], + package_dir={'nfbmeter': 'nfbmeter'}, + entry_points={ + 'console_scripts': [ + 'nfb-meter=nfbmeter.nfbmeter:main', + ], + }, +) diff --git a/python/nfb-tools/setup.py.in b/python/nfb-tools/setup.py.in new file mode 100644 index 00000000..05828a59 --- /dev/null +++ b/python/nfb-tools/setup.py.in @@ -0,0 +1,11 @@ +from setuptools import setup + +setup( + packages=["nfbmeter"], + package_dir={'nfbmeter': '${CMAKE_CURRENT_SOURCE_DIR}/nfbmeter'}, + entry_points={ + 'console_scripts': [ + 'nfb-meter = nfbmeter.nfbmeter:main', + ], + }, +) From c42569ef77206b2a0049131b572780e070fefc25 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 4 Mar 2024 08:55:58 +0100 Subject: [PATCH 057/518] bump version to 6.21.1 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 648389ab..e5f20004 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Mon Mar 4 2024 Martin Spinler - 6.21.1-1 +- [FEATURE] added nfb-meter python tool + * Tue Feb 27 2024 Martin Spinler - 6.21.0-1 - [OPT] added performance and userspace mode in ndp-tool - [OPT] some optimalitazions for DMA Calypte controllers diff --git a/VERSION b/VERSION index 7ecad140..476d3ceb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.21.0 +6.21.1 From bded43405d475849cdc693732a203ae772711447 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 5 Mar 2024 19:38:13 +0100 Subject: [PATCH 058/518] build: [MAINTENANCE] update version of 3rdparty archive --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 30a5a8fc..85a7ef7d 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ AUTOINSTALL=true # whether dependencies should be installed with '-y' RELTYPE=Release # Release type (Debug/Release) FILENAME_3RDPARTY="3rdparty.tar.gz" -SRC_3RDPARTY_VERSION="v6.19.5" +SRC_3RDPARTY_VERSION="v6.21.0" URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_VERSION/$FILENAME_3RDPARTY" EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" From 887ffaf755a328267b0276553e40c90e1e5be6b5 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 Feb 2024 18:52:41 +0100 Subject: [PATCH 059/518] nfb-xvc: [FEATURE] use libpci instead of driver The nfb-xvc now supports driverless access through the libpci library. Minimal version of the libpci is 3.6.3; for older systems (like RHEL7) is used the original mechanism. For libpci access the device parameter -d must be in PCI BDF format. The xvc kernel driver is disabled and doesn't built by default. For usage of nfb-xvc on older systems must be therefore manually enabled. --- CMakeLists.txt | 4 ++-- build.sh | 4 ++++ drivers/kernel/drivers/Makefile | 4 +++- jenkins/centos7.Dockerfile | 2 +- jenkins/oraclelinux8.Dockerfile | 2 +- jenkins/ubuntu.Dockerfile | 2 +- tools-debug/CMakeLists.txt | 13 +++++++++++-- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5193a865..0da2a51e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,14 +51,14 @@ configure_file(package/prerm.in package/prerm @ONLY) configure_file(package/postrm.in package/postrm @ONLY) set(RPM_DEP_LIST - dkms gcc kernel-devel libarchive libfdt-devel make numactl ncurses + dkms gcc kernel-devel libarchive libfdt-devel make numactl ncurses pciutils-libs ) set(RPM_PYTHON_DEP_LIST nfb-framework python3-fdt ) set(DEB_DEP_LIST - dkms gcc libarchive-dev libfdt-dev libncurses-dev libnuma-dev linux-headers make + dkms gcc libarchive-dev libfdt-dev libncurses-dev libnuma-dev linux-headers make libpci3 ) set(DEB_PYTHON_DEP_LIST nfb-framework diff --git a/build.sh b/build.sh index 85a7ef7d..22cc144e 100755 --- a/build.sh +++ b/build.sh @@ -153,6 +153,7 @@ get_dependencies() ret="$ret python3-dev" ret="$ret python3-setuptools" ret="$ret cython3" + ret="$ret libpci-dev" elif item_in_list "$os" "centos scientific fedora ol rocky"; then ret="$ret libfdt-devel" ret="$ret numactl-devel" @@ -160,6 +161,8 @@ get_dependencies() ret="$ret libarchive-devel" ret="$ret libconfig" ret="$ret libconfig-devel" + ret="$ret pciutils-devel pciutils-libs" + ret="$ret python3-devel" ret="$ret python3-setuptools" if [ "$os_version" = "7" ]; then ret="$ret python36-Cython" @@ -172,6 +175,7 @@ get_dependencies() ret="$ret ncurses" ret="$ret libarchive" ret="$ret libconfig" + ret="$ret pciutils" fi echo $ret diff --git a/drivers/kernel/drivers/Makefile b/drivers/kernel/drivers/Makefile index 04210ac3..e73f8459 100644 --- a/drivers/kernel/drivers/Makefile +++ b/drivers/kernel/drivers/Makefile @@ -10,4 +10,6 @@ include $(DRIVER_TOPDIR)/Makefile.conf obj-$(CONFIG_NFB) += nfb/ -obj-$(CONFIG_NFB_XVC) += xvc/ + +# The nfb-xvc now uses the libpci and doesn't needs xvc kernel driver anymore. +#obj-$(CONFIG_NFB_XVC) += xvc/ diff --git a/jenkins/centos7.Dockerfile b/jenkins/centos7.Dockerfile index 3af39365..016c9977 100644 --- a/jenkins/centos7.Dockerfile +++ b/jenkins/centos7.Dockerfile @@ -7,6 +7,6 @@ RUN /usr/sbin/useradd jenkins -u 1000 -g 991 RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers RUN yum install -y epel-release git make gcc rpm-build autoconf automake sudo curl -RUN yum install -y libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel python3-devel python36-Cython +RUN yum install -y libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel python3-devel python36-Cython pciutils-devel pciutils-libs RUN yum install -y cmake3 RUN yum clean all diff --git a/jenkins/oraclelinux8.Dockerfile b/jenkins/oraclelinux8.Dockerfile index e13d656b..503d2917 100644 --- a/jenkins/oraclelinux8.Dockerfile +++ b/jenkins/oraclelinux8.Dockerfile @@ -11,7 +11,7 @@ RUN dnf config-manager --set-enabled ol8_codeready_builder; RUN dnf copr enable @CESNET/dpdk-nfb RUN yum install -y epel-release git make gcc rpm-build autoconf automake sudo curl -RUN yum install -y libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel python3-devel python3-Cython +RUN yum install -y libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel python3-devel python3-Cython pciutils-devel pciutils-libs RUN yum install -y cmake RUN yum install -y wget diff --git a/jenkins/ubuntu.Dockerfile b/jenkins/ubuntu.Dockerfile index beaa939f..00e6459f 100644 --- a/jenkins/ubuntu.Dockerfile +++ b/jenkins/ubuntu.Dockerfile @@ -8,6 +8,6 @@ RUN /usr/sbin/useradd jenkins -u 1000 -g 991 RUN apt-get update RUN DEBIAN_FRONTEND=noninteractive TZ=Europe/Prague apt-get -y install tzdata RUN apt-get install -y git sudo make curl cmake pkg-config file -RUN apt-get install -y autoconf automake libfdt-dev libnuma-dev libncurses-dev libarchive-dev libconfig-dev python3-dev python3-setuptools cython3 +RUN apt-get install -y autoconf automake libfdt-dev libnuma-dev libncurses-dev libarchive-dev libconfig-dev python3-dev python3-setuptools cython3 libpci-dev pciutils RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers diff --git a/tools-debug/CMakeLists.txt b/tools-debug/CMakeLists.txt index 8f2be9a9..895c74b9 100644 --- a/tools-debug/CMakeLists.txt +++ b/tools-debug/CMakeLists.txt @@ -11,23 +11,32 @@ cmake_minimum_required(VERSION 3.12) cmake_policy(VERSION 3.12) include(GNUInstallDirs) +find_package(PkgConfig) + ndk_check_build_dependency(FDT_LIBRARIES fdt FDT_INCLUDE_DIRS libfdt.h libfdt) +pkg_check_modules(LIBPCI libpci>=3.6.3) + link_libraries(nfb ${FDT_LIBRARIES}) add_executable(nfb-busdebugctl busdebugctl/busdebugctl.c) add_executable(nfb-busdump busdump/busdump.c) add_executable(nfb-busreplay busreplay/busreplay.c) - add_executable(nfb-xvc nfb-xvc/xvc_pcie.c nfb-xvc/xvcserver.c) set (PIE_TARGETS nfb-busdebugctl nfb-busdump nfb-busreplay nfb-xvc) + +if (${LIBPCI_FOUND}) + target_compile_definitions(nfb-xvc PUBLIC USE_LIBPCI) + target_link_libraries(nfb-xvc PRIVATE pci) +endif() + foreach(PIE_TARGET IN LISTS PIE_TARGETS) set_property(TARGET ${PIE_TARGET} PROPERTY POSITION_INDEPENDENT_CODE TRUE) endforeach() install( - TARGETS nfb-busdebugctl nfb-busdump nfb-busreplay nfb-xvc + TARGETS ${PIE_TARGETS} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT DebugTools ) From 32a8fffd5279ef88da0281c6db0e3dc3e633c227 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 6 Mar 2024 08:36:18 +0100 Subject: [PATCH 060/518] libnfb: [MAINTENANCE] fix warning for bitfield type --- libnfb/include/netcope/dma_ctrl_ndp.h | 15 +++++++++------ libnfb/include/netcope/ndp_priv.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index fcc088c0..5eab8e01 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -73,16 +73,17 @@ struct nc_ndp_hdr { struct nc_ndp_desc { union { struct __attribute__((__packed__)) { - uint64_t phys : 34; - uint32_t rsvd : 28; + unsigned phys_lo : 32; + unsigned phys_hi : 2; + unsigned rsvd : 28; unsigned type : 2; } type0; struct __attribute__((__packed__)) { - uint64_t phys : 30; + unsigned phys : 30; int int0 : 1; int rsvd0 : 1; - uint16_t len : 16; - uint16_t meta : 12; + unsigned len : 16; + unsigned meta : 12; int shrd0 : 1; int next0 : 1; unsigned type : 2; @@ -131,7 +132,9 @@ static inline struct nc_ndp_desc nc_ndp_rx_desc0(uint64_t phys) { struct nc_ndp_desc desc; - desc.d.type0.phys = phys >> 30; + desc.d.type0.phys_lo = phys >> (30); + desc.d.type0.phys_hi = phys >> (30 + 32); + desc.d.type0.rsvd = 0; desc.d.type0.type = 0; diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index a56eb5b3..b463109d 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -31,7 +31,7 @@ struct ndp_v2_offsethdr { struct ndp_v3_packethdr { __u16 frame_len; /**< size of the packet */ __u16 frame_ptr; /**< index into the data array */ - __u8 valid : 1; /**< bit indicating the validity of the header/packet */ + unsigned valid : 1; /**< bit indicating the validity of the header/packet */ unsigned reserved : 7; /**< bits reserved for future use */ unsigned metadata:24; /**< user metadata */ } __attribute((packed)); From 6e7ac36170686bae0ed368c61e4396dfeff25e0d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 7 Mar 2024 08:33:58 +0100 Subject: [PATCH 061/518] build: [FIX] update Arch packaging dependencies --- build.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.sh b/build.sh index 22cc144e..4f38978e 100755 --- a/build.sh +++ b/build.sh @@ -176,6 +176,10 @@ get_dependencies() ret="$ret libarchive" ret="$ret libconfig" ret="$ret pciutils" + ret="$ret python-setuptools" + ret="$ret cython" + # for packaging + ret="$ret fakeroot pkgconfig" fi echo $ret From 15e639435dea706896469cc5d0a23ccc7a92de19 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 11 Mar 2024 13:10:45 +0100 Subject: [PATCH 062/518] drivers - NDP: replace usleep by udelay in Medusa driver --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 30fe63d5..16092bf3 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -390,7 +390,7 @@ static void ndp_ctrl_medusa_tx_set_swptr(struct ndp_channel *channel, uint64_t p } if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(addr) != last_upper_addr)) { while (ctrl->free_desc == 0) { - usleep_range(10, 50); + udelay(10); ndp_ctrl_medusa_tx_get_hwptr(channel); if (unlikely(ndp_kill_signal_pending(current))) { @@ -409,7 +409,7 @@ static void ndp_ctrl_medusa_tx_set_swptr(struct ndp_channel *channel, uint64_t p } while (ctrl->free_desc == 0) { - usleep_range(10, 50); + udelay(10); ndp_ctrl_medusa_tx_get_hwptr(channel); if (ndp_kill_signal_pending(current)) { dirty = 1; From 46af15aa7641d903dcf4821b790426f87094d15a Mon Sep 17 00:00:00 2001 From: David Vodak Date: Tue, 19 Mar 2024 14:11:07 +0100 Subject: [PATCH 063/518] ndp-tool: [MAINTENANCE] extract adjust_tx_throughput function --- tools/ndptool/common.c | 37 +++++++++++++++++++++++++++++++++++++ tools/ndptool/common.h | 3 +++ tools/ndptool/transmit.c | 32 +------------------------------- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/tools/ndptool/common.c b/tools/ndptool/common.c index 70446a3d..d30a7ef5 100644 --- a/tools/ndptool/common.c +++ b/tools/ndptool/common.c @@ -56,3 +56,40 @@ void delay_nsecs(unsigned int ns) } return; } + +void adjust_tx_throughput(unsigned status_num_of_loops, unsigned long long throughput_mbps, + bool use_delay_nsec, struct stats_info *si, struct ndp_queue *tx) +{ + unsigned status_loop = status_num_of_loops; + struct timeval status_time; + + /* zero Mbps = unlimited throughput */ + if (throughput_mbps != 0) { + /* Check throughput only every N cycles */ + if (status_loop != 0) { + status_loop--; + } else { + status_loop = status_num_of_loops; + do { + /* calculate elapsed time and expected bits */ + gettimeofday(&status_time, NULL); + double elapsed_time = ((status_time.tv_sec - si->startTime.tv_sec) * 1000000) + (status_time.tv_usec - si->startTime.tv_usec); + double expected_bits = elapsed_time * throughput_mbps; + + /* total number of transferred bits by this thread */ + double transferred_bits = si->thread_total_bytes_cnt * 8; + + /* check threshold */ + if (expected_bits / transferred_bits < 1.0) { + /* We have to pause sending packets for a while */ + //update_stats(packets, 0, si); + ndp_tx_burst_flush(tx); + if (use_delay_nsec) + delay_nsecs(1); + } else { + break; + } + } while(true); + } + } +} diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index 484e9897..7ddbf199 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -199,6 +199,9 @@ extern unsigned TX_BURST; void delay_usecs(unsigned int us); void delay_nsecs(unsigned int ns); +void adjust_tx_throughput(unsigned status_num_of_loops, unsigned long long throughput_mbps, + bool use_delay_nsec, struct stats_info *si, struct ndp_queue *tx); + void update_stats(struct ndp_packet *packets, int count, struct stats_info *si); void update_stats_thread(struct ndp_packet *packets, int count, struct stats_info *si); diff --git a/tools/ndptool/transmit.c b/tools/ndptool/transmit.c index f23c7e0c..523552ad 100644 --- a/tools/ndptool/transmit.c +++ b/tools/ndptool/transmit.c @@ -175,12 +175,10 @@ static int ndp_mode_transmit_loop(struct ndp_tool_params *p, struct pcap_src *sr struct ndp_packet packets[burst_size]; struct ndp_queue *tx = p->tx; struct stats_info *si = &p->si; - struct timeval status_time; bool min_invalid = false; /* Check throughput only every N cycles */ unsigned status_num_of_loops = p->mode.transmit.mbps / 10000u; - unsigned status_loop = status_num_of_loops; update_stats_t update_stats = p->update_stats; @@ -234,35 +232,7 @@ static int ndp_mode_transmit_loop(struct ndp_tool_params *p, struct pcap_src *sr update_stats(packets, pkts_filled, si); ndp_tx_burst_put(tx); - /* zero Mbps = unlimited throughput */ - if (p->mode.transmit.mbps != 0) { - /* Check throughput only every N cycles */ - if (status_loop != 0) { - status_loop--; - } else { - status_loop = status_num_of_loops; - do { - /* calculate elapsed time and expected bits */ - gettimeofday(&status_time, NULL); - double elapsed_time = ((status_time.tv_sec - si->startTime.tv_sec) * 1000000) + (status_time.tv_usec - si->startTime.tv_usec); - double expected_bits = elapsed_time * p->mode.transmit.mbps; - - /* total number of transferred bits by this thread */ - double transferred_bits = si->thread_total_bytes_cnt * 8; - - /* check threshold */ - if (expected_bits / transferred_bits < 1.0) { - /* We have to pause sending packets for a while */ - //update_stats(packets, 0, si); - ndp_tx_burst_flush(tx); - if (p->use_delay_nsec) - delay_nsecs(1); - } else { - break; - } - } while(true); - } - } + adjust_tx_throughput(status_num_of_loops, p->mode.transmit.mbps, p->use_delay_nsec, si, tx); } ndp_tx_burst_flush(tx); return 0; From 228aba23b37d9a115277a7f52f348f87e13c8fa2 Mon Sep 17 00:00:00 2001 From: David Vodak Date: Wed, 20 Mar 2024 15:17:18 +0100 Subject: [PATCH 064/518] ndp-tool: [FEATURE] support long args --- tools/ndptool/common.h | 4 +++- tools/ndptool/generate.c | 3 ++- tools/ndptool/loopback_hw.c | 3 ++- tools/ndptool/main.c | 12 ++++++++++-- tools/ndptool/modules.c | 8 ++++---- tools/ndptool/receive.c | 3 ++- tools/ndptool/transmit.c | 3 ++- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index 7ddbf199..b8313abf 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -182,11 +183,12 @@ struct ndptool_module { void (*print_help)(void); int (*init)(struct ndp_tool_params *p); int (*check)(struct ndp_tool_params *p); - int (*parse_opt)(struct ndp_tool_params *p, int opt, char *optarg); + int (*parse_opt)(struct ndp_tool_params *p, int opt, char *optarg, int option_index); int (*run_single)(struct ndp_tool_params *p); void *(*run_thread)(void *tmp); void (*destroy)(struct ndp_tool_params *p); void (*stats_cb)(struct stats_info *si); + struct option *long_options; }; extern volatile int stop; diff --git a/tools/ndptool/generate.c b/tools/ndptool/generate.c index 334eb858..040c4b98 100644 --- a/tools/ndptool/generate.c +++ b/tools/ndptool/generate.c @@ -219,7 +219,8 @@ void ndp_mode_generate_print_help() /* printf(" -T content Packet content [george, dns]\n"); */ } -int ndp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg) +int ndp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, + int option_index __attribute__((unused))) { switch (opt) { case 's': diff --git a/tools/ndptool/loopback_hw.c b/tools/ndptool/loopback_hw.c index e4df6ee4..b39098fd 100644 --- a/tools/ndptool/loopback_hw.c +++ b/tools/ndptool/loopback_hw.c @@ -480,7 +480,8 @@ void ndp_mode_loopback_hw_print_latency(struct stats_info *si){ printf("Avg latency (ms) : % 24.3f\n", (si->latency_sum/si->packet_cnt)/1000.0f); } -int ndp_mode_loopback_hw_parseopt(struct ndp_tool_params *p, int32_t opt, char *optarg) +int ndp_mode_loopback_hw_parseopt(struct ndp_tool_params *p, int32_t opt, char *optarg, + int option_index __attribute__((unused))) { switch (opt) { case 's': diff --git a/tools/ndptool/main.c b/tools/ndptool/main.c index b3fece19..959b384f 100644 --- a/tools/ndptool/main.c +++ b/tools/ndptool/main.c @@ -123,6 +123,8 @@ void ndp_loop_thread_destroy(struct thread_data *thread_data) int main(int argc, char *argv[]) { + struct option default_long_options[] = {{0, 0, 0, 0}}; + struct option *long_options; unsigned i; int opt; int qri, qrc; @@ -144,6 +146,8 @@ int main(int argc, char *argv[]) const char *strmode; char *args; + int option_index = 0; + int ret = 0; memset(¶ms, 0, sizeof(params)); @@ -198,8 +202,12 @@ int main(int argc, char *argv[]) strcpy(args, ARGUMENTS); strcat(args, module->args); + long_options = module->long_options == NULL + ? default_long_options + : module->long_options; + /* argument handling */ - while ((opt = getopt(argc, argv, args)) >= 0) { + while ((opt = getopt_long(argc, argv, args, long_options, &option_index)) >= 0) { switch (opt) { case 'd': params.nfb_path = optarg; @@ -254,7 +262,7 @@ int main(int argc, char *argv[]) errx(-1, "Cannot parse packet limit parameter"); break; default: - if (module->parse_opt == NULL || module->parse_opt(¶ms, opt, optarg)) + if (module->parse_opt == NULL || module->parse_opt(¶ms, opt, optarg, option_index)) errx(-1, "Unknown parameter"); } } diff --git a/tools/ndptool/modules.c b/tools/ndptool/modules.c index e54c163a..3fa8bdca 100644 --- a/tools/ndptool/modules.c +++ b/tools/ndptool/modules.c @@ -62,10 +62,10 @@ void ndp_mode_transmit_print_help(void); void ndp_mode_loopback_hw_print_help(void); void ndp_mode_loopback_hw_print_latency(struct stats_info *si); -int ndp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg); -int ndp_mode_receive_parseopt(struct ndp_tool_params *p, int opt, char *optarg); -int ndp_mode_transmit_parseopt(struct ndp_tool_params *p, int opt, char *optarg); -int ndp_mode_loopback_hw_parseopt(struct ndp_tool_params *p, int opt, char *optarg); +int ndp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); +int ndp_mode_receive_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); +int ndp_mode_transmit_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); +int ndp_mode_loopback_hw_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); int ndp_mode_generate_check(struct ndp_tool_params *p); int ndp_mode_receive_check(struct ndp_tool_params *p); diff --git a/tools/ndptool/receive.c b/tools/ndptool/receive.c index cfaee6a2..a38811c0 100644 --- a/tools/ndptool/receive.c +++ b/tools/ndptool/receive.c @@ -196,7 +196,8 @@ void ndp_mode_receive_print_help() printf(" -r trim Maximum number of bytes per packet to save\n"); } -int ndp_mode_receive_parseopt(struct ndp_tool_params *p, int opt, char *optarg) +int ndp_mode_receive_parseopt(struct ndp_tool_params *p, int opt, char *optarg, + int option_index __attribute__((unused))) { switch (opt) { case 'f': diff --git a/tools/ndptool/transmit.c b/tools/ndptool/transmit.c index 523552ad..0a31123e 100644 --- a/tools/ndptool/transmit.c +++ b/tools/ndptool/transmit.c @@ -259,7 +259,8 @@ void ndp_mode_transmit_print_help() printf(" -L bytes Minimal allowed frame length\n"); } -int ndp_mode_transmit_parseopt(struct ndp_tool_params *p, int opt, char *optarg) +int ndp_mode_transmit_parseopt(struct ndp_tool_params *p, int opt, char *optarg, + int option_index __attribute__((unused))) { switch (opt) { case 'f': From aabc279cc6c18a9a37efe6bbef18b365d50121d3 Mon Sep 17 00:00:00 2001 From: David Vodak Date: Tue, 19 Mar 2024 14:41:44 +0100 Subject: [PATCH 065/518] ndp-tool: [FEATURE] adjust tx throughput of ndp-generate --- tools/ndptool/common.h | 1 + tools/ndptool/generate.c | 21 ++++++++++++++++++++- tools/ndptool/modules.c | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index b8313abf..d7ba62fc 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -71,6 +71,7 @@ struct ndp_mode_generate_params { int srand; bool clear_data; fwmode_t mode; + unsigned long long mbps; /*!< Replay packets at a given Mbps */ }; /*! diff --git a/tools/ndptool/generate.c b/tools/ndptool/generate.c index 040c4b98..9cc591cc 100644 --- a/tools/ndptool/generate.c +++ b/tools/ndptool/generate.c @@ -128,6 +128,9 @@ static int ndp_mode_generate_loop(struct ndp_tool_params *p) const bool limit_bytes = p->limit_bytes > 0 ? true : false; const bool limit_packets = p->limit_packets > 0 ? true : false; + /* Check throughput only every N cycles */ + unsigned status_num_of_loops = p->mode.generate.mbps / 10000u; + /* Clear length of packet header */ for (i = 0; i < burst_size; i++) { packets[i].flags = 0; @@ -200,6 +203,8 @@ static int ndp_mode_generate_loop(struct ndp_tool_params *p) /* Release packet descriptors */ ndp_tx_burst_put(tx); + + adjust_tx_throughput(status_num_of_loops, p->mode.generate.mbps, p->use_delay_nsec, si, tx); } return 0; @@ -208,6 +213,7 @@ static int ndp_mode_generate_loop(struct ndp_tool_params *p) int ndp_mode_generate_init(struct ndp_tool_params *p) { list_range_init(&p->mode.generate.range); + p->mode.generate.mbps = 0; return 0; } @@ -216,13 +222,22 @@ void ndp_mode_generate_print_help() printf("Generate parameters:\n"); printf(" -s size Packet size - list or random from range, e.g \"64,128-256\"\n"); printf(" -C Clear packet data before send\n"); + printf(" --speed Mbps Replay packets at a given speed\n"); /* printf(" -T content Packet content [george, dns]\n"); */ } int ndp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, - int option_index __attribute__((unused))) + int option_index) { switch (opt) { + case 0: + if (!strcmp(module->long_options[option_index].name, "speed")) { + if (nc_strtoull(optarg, &p->mode.generate.mbps)) + errx(-1, "Cannot parse --speed parameter"); + } else { + errx(-1, "Unknown long option"); + } + break; case 's': if (list_range_parse(&p->mode.generate.range, optarg) < 0) errx(-1, "Cannot parse size range"); @@ -230,6 +245,10 @@ int ndp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, case 'C': p->mode.generate.clear_data = 1; break; + case 'S': + if (nc_strtoull(optarg, &p->mode.generate.mbps)) + errx(-1, "Cannot parse mbps parameter"); + break; default: return -1; } diff --git a/tools/ndptool/modules.c b/tools/ndptool/modules.c index 3fa8bdca..cf4f5109 100644 --- a/tools/ndptool/modules.c +++ b/tools/ndptool/modules.c @@ -90,6 +90,11 @@ void *ndp_mode_loopback_hw_thread(void *tmp); void ndp_mode_generate_destroy(struct ndp_tool_params *p); void ndp_mode_loopback_hw_destroy(struct ndp_tool_params *p); +struct option long_options_speed[] = { + {"speed", required_argument, 0, 0}, + {0, 0, 0, 0}, +}; + struct ndptool_module modules[] = { [NDP_MODULE_READ] = { .name = "read", @@ -109,6 +114,7 @@ struct ndptool_module modules[] = { .run_single = ndp_mode_generate, .run_thread = ndp_mode_generate_thread, .destroy = ndp_mode_generate_destroy, + .long_options = long_options_speed, }, [NDP_MODULE_RECEIVE] = { .name = "receive", From ee73ff8a282748f129aa2767922ae61e440f2c36 Mon Sep 17 00:00:00 2001 From: David Vodak Date: Wed, 20 Mar 2024 15:42:57 +0100 Subject: [PATCH 066/518] ndp-tool: [FEATURE] use --speed longopt in ndp-transmit --- tools/ndptool/modules.c | 1 + tools/ndptool/transmit.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/ndptool/modules.c b/tools/ndptool/modules.c index cf4f5109..e8dfd3df 100644 --- a/tools/ndptool/modules.c +++ b/tools/ndptool/modules.c @@ -137,6 +137,7 @@ struct ndptool_module modules[] = { .check = ndp_mode_transmit_check, .run_single = ndp_mode_transmit, .run_thread = ndp_mode_transmit_thread, + .long_options = long_options_speed, }, [NDP_MODULE_LOOPBACK] = { .name = "loopback", diff --git a/tools/ndptool/transmit.c b/tools/ndptool/transmit.c index 0a31123e..6cc9b386 100644 --- a/tools/ndptool/transmit.c +++ b/tools/ndptool/transmit.c @@ -257,12 +257,21 @@ void ndp_mode_transmit_print_help() printf(" -m Load PCAP file for each thread. -f parameter should contain %%t for thread_id or %%d fo dma_id\n"); printf(" -s Mbps Replay packets at a given speed\n"); printf(" -L bytes Minimal allowed frame length\n"); + printf(" --speed Mbps Replay packets at a given speed\n"); } int ndp_mode_transmit_parseopt(struct ndp_tool_params *p, int opt, char *optarg, - int option_index __attribute__((unused))) + int option_index) { switch (opt) { + case 0: + if (!strcmp(module->long_options[option_index].name, "speed")) { + if (nc_strtoull(optarg, &p->mode.transmit.mbps)) + errx(-1, "Cannot parse --speed parameter"); + } else { + errx(-1, "Unknown long option"); + } + break; case 'f': p->pcap_filename = optarg; break; From 64bc9a64873038e3f2fce0d1cf90a8734206545e Mon Sep 17 00:00:00 2001 From: David Vodak Date: Wed, 20 Mar 2024 15:46:55 +0100 Subject: [PATCH 067/518] ndp-tool: [MAINTENANCE] deprecate -s flag of ndp-transmit The -s flag is also used in ndp-generate but for different feature. --- tools/ndptool/transmit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ndptool/transmit.c b/tools/ndptool/transmit.c index 6cc9b386..a141dbf7 100644 --- a/tools/ndptool/transmit.c +++ b/tools/ndptool/transmit.c @@ -255,7 +255,7 @@ void ndp_mode_transmit_print_help() printf(" -l loops Loop over the PCAP file times (0 for forever)\n"); printf(" -Z Do not preload file in cache (slower, consumes less memory)\n"); printf(" -m Load PCAP file for each thread. -f parameter should contain %%t for thread_id or %%d fo dma_id\n"); - printf(" -s Mbps Replay packets at a given speed\n"); + printf(" -s Mbps Replay packets at a given speed (deprecated, --speed long opt should be used instead)\n"); printf(" -L bytes Minimal allowed frame length\n"); printf(" --speed Mbps Replay packets at a given speed\n"); } From ebebb424421923971b4df05e955e9baaf0bd9d1e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Mar 2024 09:46:52 +0100 Subject: [PATCH 068/518] build - drivers: add softclean target for preserving config.h --- drivers/Makefile.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/Makefile.in b/drivers/Makefile.in index dbd6da13..03e611b0 100644 --- a/drivers/Makefile.in +++ b/drivers/Makefile.in @@ -39,13 +39,15 @@ INSTALL_HEADERS = nfb.h ndp.h boot.h DKMS_DIRNAME = $(PACKAGE_NAME)-$(PACKAGE_VERSION) DKMS_FILES = dkms.conf Makefile Makefile.conf -.PHONY: all clean +.PHONY: all clean softclean all: $(KBUILD) modules -clean: +softclean: $(KBUILD) clean + +clean: softclean rm -f config.h .PHONY: install modules_install headers_install From b6d93d28fb92b4fd5391f6bad3c17f85a7efc477 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 19 Mar 2024 14:52:09 +0100 Subject: [PATCH 069/518] drivers: [FIX] allow generic cards with no nfb_pci_dev entry --- drivers/kernel/drivers/nfb/boot/boot.c | 10 +++++----- drivers/kernel/drivers/nfb/char.c | 2 +- drivers/kernel/drivers/nfb/misc.c | 5 +++-- drivers/kernel/drivers/nfb/nfb.h | 1 + drivers/kernel/drivers/nfb/pci.c | 25 +++++++++++++++++++------ 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 039c5f1a..568b80ab 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -60,7 +60,7 @@ static void nfb_boot_read_serial_number(struct nfb_device *nfb, struct nfb_boot int ret; /* some cards don't have MTD or they don't support reading serial numbers */ - if (nfb->nfb_pci_dev->idstruct_mtd == -1 || + if (nfb->nfb_pci_dev == NULL || nfb->nfb_pci_dev->idstruct_mtd == -1 || nfb->nfb_pci_dev->idstruct_serialno_addr == -1) return; @@ -92,7 +92,7 @@ static void nfb_boot_read_card_subtype(struct nfb_device *nfb, struct nfb_boot * int i; /* some cards don't have and don't support reading subtype */ - if (nfb->nfb_pci_dev->idstruct_mtd == -1 || + if (nfb->nfb_pci_dev == NULL || nfb->nfb_pci_dev->idstruct_mtd == -1 || nfb->nfb_pci_dev->idstruct_subtype_addr == -1) return; @@ -273,7 +273,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) boot->sdm_boot_en = 0; fdt_offset = fdt_node_offset_by_compatible(nfb->fdt, -1, "netcope,intel_sdm_controller"); if (fdt_offset >= 0) { - boot->sdm = sdm_init(nfb, fdt_offset, nfb->nfb_pci_dev->name); + boot->sdm = sdm_init(nfb, fdt_offset, nfb->pci_name); prop32 = fdt_getprop(nfb->fdt, fdt_offset, "boot_en", &len); if (boot->sdm && len == sizeof(*prop32) && fdt32_to_cpu(*prop32) != 0) { @@ -356,10 +356,10 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) /* Backward compatibility with firmware, which doesn't have card-name property in DT */ fdt_offset = fdt_path_offset(nfb->fdt, "/firmware"); if (fdt_getprop(nfb->fdt, fdt_offset, "card-name", &len) == NULL) - fdt_setprop_string(nfb->fdt, fdt_offset, "card-name", nfb->nfb_pci_dev->name); + fdt_setprop_string(nfb->fdt, fdt_offset, "card-name", nfb->pci_name); fdt_offset = fdt_path_offset(nfb->fdt, "/board"); - fdt_setprop_string(nfb->fdt, fdt_offset, "board-name", nfb->nfb_pci_dev->name); + fdt_setprop_string(nfb->fdt, fdt_offset, "board-name", nfb->pci_name); fdt_setprop_u32(nfb->fdt, fdt_offset, "serial-number", nfb->serial); dev_info(&nfb->pci->dev, "nfb_boot: Attached successfully\n"); diff --git a/drivers/kernel/drivers/nfb/char.c b/drivers/kernel/drivers/nfb/char.c index 0586ceff..41452954 100644 --- a/drivers/kernel/drivers/nfb/char.c +++ b/drivers/kernel/drivers/nfb/char.c @@ -39,7 +39,7 @@ static ssize_t nfb_char_get_serial(struct device *dev, struct device_attribute * static ssize_t nfb_char_get_cardname(struct device *dev, struct device_attribute *attr, char *buf) { struct nfb_device *nfb = dev_get_drvdata(dev); - return scnprintf(buf, PAGE_SIZE, "%s\n", nfb->nfb_pci_dev->name); + return scnprintf(buf, PAGE_SIZE, "%s\n", nfb->pci_name); } static ssize_t nfb_char_get_pcislot(struct device *dev, struct device_attribute *attr, char *buf) { diff --git a/drivers/kernel/drivers/nfb/misc.c b/drivers/kernel/drivers/nfb/misc.c index 1ba641b0..c72b54f3 100644 --- a/drivers/kernel/drivers/nfb/misc.c +++ b/drivers/kernel/drivers/nfb/misc.c @@ -30,8 +30,9 @@ int nfb_net_set_dev_addr(struct nfb_device *nfb, struct net_device *dev, int ind addr[0] = 0x00; addr[1] = 0x11; addr[2] = 0x17; - - addr[3] = reverse(nfb->nfb_pci_dev->card_type_id, 8); + addr[3] = 0; + if (nfb->nfb_pci_dev) + addr[3] = reverse(nfb->nfb_pci_dev->card_type_id, 8); addr[4] = (nfb->serial << snshift) >> 8; addr[5] = ((nfb->serial << snshift) & 0xF0) | (index & 0x0F); #ifdef CONFIG_HAVE_ETH_HW_ADDR_SET diff --git a/drivers/kernel/drivers/nfb/nfb.h b/drivers/kernel/drivers/nfb/nfb.h index dbb12742..25de4c71 100644 --- a/drivers/kernel/drivers/nfb/nfb.h +++ b/drivers/kernel/drivers/nfb/nfb.h @@ -113,6 +113,7 @@ struct nfb_device { enum nfb_device_status status; const struct nfb_pci_dev *nfb_pci_dev; /* Card-type specific data (driver-defined */ + const char *pci_name; struct device *dev; /* Linux generic 'device' (related to /sys files) */ rwlock_t fdt_lock; /* Lock for DeviceTree modification */ void *fdt; /* DeviceTree description */ diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index c5bd72bf..626f5248 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -28,6 +28,7 @@ #define NFB_FDT_BURSTSIZE (16384) #define NFB_FDT_MAXSIZE (65536) #define NFB_FDT_FIXUP_NODE_NAME_LEN 16 +#define NFB_CARD_NAME_GENERIC "COMBO-GENERIC" static bool fallback_fdt = 1; static bool fallback_fdt_boot = 0; @@ -36,6 +37,7 @@ static bool flash_recovery_ro = 1; struct list_head global_pci_device_list; extern struct nfb_driver_ops nfb_registered_drivers[NFB_DRIVERS_MAX]; +static const char *const nfb_card_name_generic = NFB_CARD_NAME_GENERIC; const struct nfb_pci_dev nfb_device_infos [] = { @@ -59,7 +61,7 @@ const struct nfb_pci_dev nfb_device_infos [] = { [NFB_CARD_TIVOLI] = { "TIVOLI", -1, -1, -1, 0x0B }, - [NFB_CARD_COMBO_GENERIC]= { "COMBO-GENERIC", -1, -1, -1, 0x0C }, + [NFB_CARD_COMBO_GENERIC]= { nfb_card_name_generic, -1, -1, -1, 0x0C }, [NFB_CARD_COMBO400G1] = { "COMBO-400G1", -1, -1, -1, 0x0D }, [NFB_CARD_AGI_FH400G] = { "AGI-FH400G", -1, -1, -1, 0x0E }, @@ -164,8 +166,8 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) uint32_t prop32; struct nfb_pci_device *pci_device = NULL; - const char *name = nfb->nfb_pci_dev->name; - const char *card_name = ""; + const char *name; + const char *card_name; void *fdt = nfb->fdt; enum pci_bus_speed speed; @@ -181,6 +183,8 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) "cesnet,pmci", }; + name = nfb->pci_name; + node = fdt_path_offset(fdt, "/"); node = fdt_add_subnode(fdt, node, "system"); node = fdt_add_subnode(fdt, node, "device"); @@ -203,6 +207,8 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) node = fdt_path_offset(fdt, "/firmware"); card_name = fdt_getprop(fdt, node, "card-name", &proplen); + if (proplen <= 0) + card_name = ""; for (node = -1, i = 0; i < ARRAY_SIZE(boot_ctrl_compatibles); i++) { node = fdt_node_offset_by_compatible(fdt, -1, boot_ctrl_compatibles[i]); @@ -291,7 +297,7 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) nfb_fdt_create_binary_slot(fdt, node, "image0", "configuration", 0, 1, 0, 0x00000000, 0x08000000); nfb_fdt_create_boot_type(fdt, node, "INTEL-AVST", 0); - } else if (!strcmp(name, "COMBO-GENERIC")) { + } else if (!strcmp(name, nfb_card_name_generic)) { if (!strcmp(card_name, "IA-420F")) { prop32 = cpu_to_fdt32(1); fdt_appendprop(fdt, node, "num_flash", &prop32, sizeof(prop32)); @@ -823,7 +829,11 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) goto err_nfb_create; } nfb->pci = pci; + nfb->pci_name = nfb_card_name_generic; nfb->nfb_pci_dev = (struct nfb_pci_dev*) id->driver_data; + if (nfb->nfb_pci_dev) + nfb->pci_name = nfb->nfb_pci_dev->name; + nfb->dsn = nfb_pci_read_dsn(pci); pci_device = nfb_pci_attach_endpoint(nfb, pci, 0); @@ -832,8 +842,11 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) goto err_attach_device; } - while ((bus = pci_find_next_bus(bus))) { - nfb_pci_attach_all_slaves(nfb, bus); + /* Do not scan more endpoints for generic cards */ + if (strcmp(nfb->pci_name, nfb_card_name_generic)) { + while ((bus = pci_find_next_bus(bus))) { + nfb_pci_attach_all_slaves(nfb, bus); + } } /* Initialize interrupts */ From e3cba59bd88d7f7c8a9b1616d7c165c9e029f614 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 14 Feb 2024 10:55:57 +0100 Subject: [PATCH 070/518] drivers: [FEATURE] allow user to inject FDT --- drivers/kernel/drivers/nfb/misc.c | 251 ++++++++++++++++++++++++++++++ drivers/kernel/drivers/nfb/misc.h | 17 ++ drivers/kernel/drivers/nfb/pci.c | 28 +++- 3 files changed, 293 insertions(+), 3 deletions(-) create mode 100644 drivers/kernel/drivers/nfb/misc.h diff --git a/drivers/kernel/drivers/nfb/misc.c b/drivers/kernel/drivers/nfb/misc.c index c72b54f3..5b2153c8 100644 --- a/drivers/kernel/drivers/nfb/misc.c +++ b/drivers/kernel/drivers/nfb/misc.c @@ -9,7 +9,14 @@ #include #include +#include +#include +#include + #include "nfb.h" +#include "misc.h" + +#define NFB_FDT_BURSTSIZE (16384) uint64_t reverse(const uint64_t n, const uint64_t k) { @@ -43,3 +50,247 @@ int nfb_net_set_dev_addr(struct nfb_device *nfb, struct net_device *dev, int ind return 0; } + +struct dtb_inject { + char busname[32]; + char busaddr[32]; + size_t len; + size_t off; + unsigned long crc32; + void * fdt; +}; + +static struct dtb_inject * dtb_inject_temp = NULL; +static struct dtb_inject * dtb_inject_valid = NULL; +static DEFINE_SPINLOCK(dtb_inject_lock); + +void * nfb_dtb_inject_get_pci(const char *pci_dev) +{ + void * fdt = NULL; + struct dtb_inject* dtb; + size_t size; + + dtb = xchg_acquire(&dtb_inject_valid, NULL); + if (dtb == NULL) + goto err_no_valid_dtb; + + if (strcmp(dtb->busname, "pci") || strcmp(dtb->busaddr, pci_dev)) { + /* The bus or the busaddr doesn't match, try return the dtb */ + if (cmpxchg(&dtb_inject_valid, NULL, dtb)) { + kfree(dtb->fdt); + kfree(dtb); + } + goto err_busaddr_not_match; + } + + /* Resize FDT to be editable */ + size = max_t(size_t, fdt_totalsize(dtb->fdt), NFB_FDT_BURSTSIZE) * 4; + + fdt = krealloc(dtb->fdt, size, GFP_KERNEL); + if (fdt == NULL) + goto err_realloc; + + fdt_set_totalsize(fdt, size); + + /* dtb->fdt is freed by the caller */ + kfree(dtb); + pr_info("nfb: using injected fdt on device %s\n", pci_dev); + return fdt; + +err_realloc: + kfree(dtb->fdt); + kfree(dtb); +err_busaddr_not_match: +err_no_valid_dtb: + return NULL; +} + +static ssize_t dtb_inject_meta_store(struct device_driver *driver, const char * buffer, size_t length) +{ + char *tmp_buf; + ssize_t ret = -EINVAL; + unsigned long value = 0; + struct dtb_inject* dtb; + + tmp_buf = kmalloc(length+1, GFP_KERNEL); + if (tmp_buf == NULL) + return -ENOMEM; + + memcpy(tmp_buf, buffer, length); + tmp_buf[length] = '\0'; + + spin_lock(&dtb_inject_lock); + + /* invalidate and free already valid dtb_inject */ + dtb = xchg_acquire(&dtb_inject_valid, NULL); + if (dtb) { + kfree(dtb->fdt); + kfree(dtb); + } + + dtb = dtb_inject_temp; + if (dtb == NULL) { + dtb = dtb_inject_temp = kzalloc(sizeof(*dtb), GFP_KERNEL); + if (dtb == NULL) { + ret = -ENOMEM; + goto err_dtballoc; + } + } else if (dtb->fdt) { + kfree(dtb->fdt); + dtb->fdt = NULL; + } + dtb->off = 0; + dtb->len = 0; + dtb->busname[0] = '\0'; + dtb->busaddr[0] = '\0'; + + sscanf(tmp_buf, "len=%lu crc32=%lu busname=%31s busaddr=%31s", &value, + &dtb->crc32, dtb->busname, dtb->busaddr); + if (value == 0 || value > 1048576 || + strlen(dtb->busname) <= 0 || + strlen(dtb->busaddr) <= 0) { + ret = -EINVAL; + goto err_value; + } + + dtb->fdt = kzalloc(value, GFP_KERNEL); + if (dtb->fdt == NULL) { + ret = -ENOMEM; + goto err_value; + } + + dtb->len = value; + spin_unlock(&dtb_inject_lock); + kfree(tmp_buf); + return length; + +err_value: +err_dtballoc: + spin_unlock(&dtb_inject_lock); + kfree(tmp_buf); + return ret; +} + +static ssize_t dtb_inject_meta_show(struct device_driver *driver, char * buffer) +{ + int ret = 0; + struct dtb_inject* dtb; + + spin_lock(&dtb_inject_lock); + dtb = dtb_inject_temp; + if (dtb) + ret = scnprintf(buffer, PAGE_SIZE, + "len=%lu crc32=%lum busname=%s busaddr=%s\n", + dtb->len, dtb->crc32, dtb->busname, dtb->busaddr); + spin_unlock(&dtb_inject_lock); + return ret; +} + +static ssize_t dtb_inject_store(struct device_driver *file, const char * buffer, size_t length) +{ + uint32_t csum; + ssize_t ret = -ENOMEM; + struct dtb_inject* dtb; + + spin_lock(&dtb_inject_lock); + dtb = dtb_inject_temp; + + if (dtb == NULL) + goto err_no_dtb; + + if (dtb->len < dtb->off + length) + length = dtb->len - dtb->off; + if (length == 0) + goto err_zero_len; + + memcpy(dtb->fdt + dtb->off, buffer, length); + dtb->off += length; + + if (dtb->off == dtb->len) { + /* The DTB upload is here complete */ + csum = crc32(0x80000000 ^ 0xffffffff, dtb->fdt, dtb->len); + if ((csum ^ 0xffffffff) != dtb->crc32) + goto err_fdt; + + if (dtb->len < sizeof(struct fdt_header) || fdt_check_header(dtb->fdt)) + goto err_fdt; + + if (dtb->len < fdt_totalsize(dtb->fdt)) + goto err_fdt; + + if (fdt_path_offset(dtb->fdt, "/firmware/") < 0 || + fdt_path_offset(dtb->fdt, "/system/") >= 0 || + fdt_path_offset(dtb->fdt, "/board/") >= 0 || + fdt_path_offset(dtb->fdt, "/drivers/") >= 0) { + ret = -EBADF; + goto err_fdt; + } + + /* Mark dtb_inject as valid DTB */ + dtb = xchg_acquire(&dtb_inject_valid, dtb); + if (dtb) { + /* FDT in dtb_inject_valid must be always valid */ + kfree(dtb->fdt); + kfree(dtb); + } + + /* dtb was moved from dtb_inject_temp to dtb_inject_valid */ + dtb_inject_temp = NULL; + } + spin_unlock(&dtb_inject_lock); + pr_info("nfb: fdt injected sucessfully, waiting for device\n"); + return length; + +err_fdt: + pr_warn("nfb: error while checking injected fdt\n"); +err_zero_len: +err_no_dtb: + spin_unlock(&dtb_inject_lock); + return ret; +} + +static DRIVER_ATTR_WO(dtb_inject); +static DRIVER_ATTR_RW(dtb_inject_meta); + +int nfb_dtb_inject_init(struct pci_driver * nfb_driver) +{ + int ret; + + ret = driver_create_file(&nfb_driver->driver, &driver_attr_dtb_inject); + if (ret) + goto err_create_inject; + + ret = driver_create_file(&nfb_driver->driver, &driver_attr_dtb_inject_meta); + if (ret) + goto err_create_inject_len; + + return 0; + +// driver_remove_file(&nfb_driver->driver, &driver_attr_dtb_inject_len); +err_create_inject_len: + driver_remove_file(&nfb_driver->driver, &driver_attr_dtb_inject); +err_create_inject: + return ret; + +} + +void nfb_dtb_inject_exit(struct pci_driver * nfb_driver) +{ + struct dtb_inject* dtb; + driver_remove_file(&nfb_driver->driver, &driver_attr_dtb_inject_meta); + driver_remove_file(&nfb_driver->driver, &driver_attr_dtb_inject); + + /* reset / consume valid dtb_inject */ + dtb = xchg_acquire(&dtb_inject_valid, NULL); + if (dtb) { + kfree(dtb->fdt); + kfree(dtb); + } + + dtb = dtb_inject_temp; + if (dtb) { + if (dtb->fdt) + kfree(dtb->fdt); + kfree(dtb); + } +} diff --git a/drivers/kernel/drivers/nfb/misc.h b/drivers/kernel/drivers/nfb/misc.h new file mode 100644 index 00000000..0c9f2d61 --- /dev/null +++ b/drivers/kernel/drivers/nfb/misc.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Header for misc functionality of the NFB platform + * + * Copyright (C) 2017-2024 CESNET + * Author(s): + * Martin Spinler + */ + +#ifndef NFB_MISC_H +#define NFB_MISC_H + +int nfb_dtb_inject_init(struct pci_driver * nfb_driver); +void nfb_dtb_inject_exit(struct pci_driver * nfb_driver); +void * nfb_dtb_inject_get_pci(const char *pci_name); + +#endif // NFB_MISC_H diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 626f5248..7bebaa1f 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -22,6 +22,7 @@ #include "nfb.h" #include "pci.h" +#include "misc.h" #include "mi/mi.h" #include "ndp/ndp.h" @@ -791,6 +792,8 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) struct nfb_device *nfb; struct nfb_pci_device *pci_device = NULL; + void * nfb_dtb_inject = nfb_dtb_inject_get_pci(pci_name(pci)); + if (pci_is_root_bus(pci->bus)) { dev_err(&pci->dev, "attaching an nfb card to the root PCI bus is not supported\n"); ret = -EOPNOTSUPP; @@ -818,7 +821,7 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) /* Check presence of driver_data parameter */ ret = nfb_pci_read_enpoint_id(pci); - if ((struct nfb_pci_dev*) id->driver_data == NULL || ret > 0) { + if (((struct nfb_pci_dev*) id->driver_data == NULL || ret > 0) && nfb_dtb_inject == NULL) { dev_info(&pci->dev, "successfully initialized only for DMA transfers\n"); return 0; } @@ -861,8 +864,11 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) pci->irq = -1; } - /* Populate device tree */ - nfb->fdt = nfb_pci_read_fdt(pci); + nfb->fdt = nfb_dtb_inject; + if (nfb->fdt == NULL) { + /* Populate device tree */ + nfb->fdt = nfb_pci_read_fdt(pci); + } if (IS_ERR(nfb->fdt)) { ret = PTR_ERR(nfb->fdt); dev_err(&pci->dev, "unable to read firmware description - DTB\n"); @@ -872,6 +878,7 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) else nfb->fdt = NULL; } + /* Create fallback or modify existing FDT to support booting */ if (fallback_fdt) nfb_pci_create_fallback_fdt(nfb); @@ -974,6 +981,19 @@ int nfb_pci_init(void) int ret; INIT_LIST_HEAD(&global_pci_device_list); ret = pci_register_driver(&nfb_driver); + if (ret) + goto err_register; + + ret = nfb_dtb_inject_init(&nfb_driver); + if (ret) + goto err_inject_init; + + return ret; + + //nfb_dtb_inject_exit(); +err_inject_init: + pci_unregister_driver(&nfb_driver); +err_register: return ret; } @@ -984,6 +1004,8 @@ void nfb_pci_exit(void) { struct nfb_pci_device *pci_device, *temp; + nfb_dtb_inject_exit(&nfb_driver); + pci_unregister_driver(&nfb_driver); list_for_each_entry_safe(pci_device, temp, &global_pci_device_list, global_pci_device_list) { From 6130c372d85bfd7e64f6c02b9cc19ebdaa302025 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 14 Feb 2024 16:14:02 +0100 Subject: [PATCH 071/518] tool boot: [FEATURE] add -I parameter for injecting DTB --- build.sh | 3 + libnfb/include/nfb/nfb.h | 1 + tools/CMakeLists.txt | 2 +- tools/boot/boot.c | 170 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 174 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 4f38978e..179ea9c0 100755 --- a/build.sh +++ b/build.sh @@ -154,6 +154,7 @@ get_dependencies() ret="$ret python3-setuptools" ret="$ret cython3" ret="$ret libpci-dev" + ret="$ret zlib1g zlib1g-dev" elif item_in_list "$os" "centos scientific fedora ol rocky"; then ret="$ret libfdt-devel" ret="$ret numactl-devel" @@ -162,6 +163,7 @@ get_dependencies() ret="$ret libconfig" ret="$ret libconfig-devel" ret="$ret pciutils-devel pciutils-libs" + ret="$ret zlib zlib-devel" ret="$ret python3-devel" ret="$ret python3-setuptools" if [ "$os_version" = "7" ]; then @@ -176,6 +178,7 @@ get_dependencies() ret="$ret libarchive" ret="$ret libconfig" ret="$ret pciutils" + ret="$ret zlib" ret="$ret python-setuptools" ret="$ret cython" # for packaging diff --git a/libnfb/include/nfb/nfb.h b/libnfb/include/nfb/nfb.h index 5ce75739..e4539793 100644 --- a/libnfb/include/nfb/nfb.h +++ b/libnfb/include/nfb/nfb.h @@ -56,6 +56,7 @@ struct nfb_comp; * device handle to be passed to other functions. */ struct nfb_device *nfb_open(const char *path); +struct nfb_device *nfb_open_ext(const char *devname, int oflags); /*! * \brief Close the NFB device diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 8882cf85..51100c45 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -33,7 +33,7 @@ add_executable(nfb-info info/info.c) target_compile_definitions(nfb-info PRIVATE PACKAGE_VERSION="${PACKAGE_VERSION}-${GIT_VERSION_RELEASE}") add_executable(nfb-boot boot/boot.c) -target_link_libraries(nfb-boot PRIVATE ${ARCHIVE_LIBRARIES}) +target_link_libraries(nfb-boot PRIVATE ${ARCHIVE_LIBRARIES} z) add_executable(nfb-bus bus/bus.c) diff --git a/tools/boot/boot.c b/tools/boot/boot.c index 1c1d11ca..3fc70893 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -22,11 +22,12 @@ #include #include +#include #include /* define input arguments of tool */ -#define ARGUMENTS "d:w:f:b:F:i:lqvh" +#define ARGUMENTS "d:w:f:b:F:i:I:lqvh" #define PRINT_WARNING_WHEN_USING_BITSTREAM 0 #define REQUIRE_FORCE_WHEN_USING_BITSTREAM 0 @@ -52,6 +53,7 @@ enum commands { CMD_BOOT, CMD_WRITE, CMD_QUICK_BOOT, + CMD_INJECT_DTB, }; void usage(const char *me) @@ -63,6 +65,8 @@ void usage(const char *me) printf("-f slot file Write configuration from file to device slot and boot device\n"); printf("-b slot file Quick boot, see below\n"); printf("-i file Print information about configuration file\n"); + printf("-I dtb Inject DTB to PCI device\n"); + printf(" The device arg should be in BDF+domain notation: dddd:BB:DD.F\n"); printf("-q Do not show boot progress\n"); printf("-v Be verbose\n"); printf("-l Print list of available slots\n"); @@ -74,6 +78,163 @@ void usage(const char *me) printf("If is not equal, do the write + boot action, as with parameter -f\n"); } +int inject_fdt(const char *device, const char *dtb_filename, int flags) +{ + size_t ret; + char buf[512]; + + FILE *f; + void *dtb; + const void *fdt; + int fdt_offset; + size_t dtb_size; + struct nfb_device *dev = NULL; + + char pci_dev[32] = {0}; + uint32_t csum; + + (void) flags; + + /* Read DTB */ + f = fopen(dtb_filename, "r"); + if (f == NULL) { + ret = -ENOENT; + goto err_dtb_open; + } + + fseek(f, 0L, SEEK_END); + dtb_size = ftell(f); + fseek(f, 0L, SEEK_SET); + + dtb = malloc(dtb_size); + if (dtb == NULL) { + fclose(f); + ret = -ENOMEM; + goto err_dtb_alloc; + } + + ret = fread(dtb, 1, dtb_size, f); + fclose(f); + if (ret != dtb_size) { + ret = -EBADF; + goto err_dtb_read; + } + + csum = crc32(0x80000000, dtb, dtb_size); + + + /* Try to open the NFB device associated with PCIe slot */ + /* - try as classic NFB path */ + dev = nfb_open(device); + if (dev == NULL) { + /* - try as BDF notation */ + snprintf(buf, sizeof(buf), "/dev/nfb/by-pci-slot/%s", device); + dev = nfb_open(buf); + /* If dev is still invalid, assume the device is not attached to kernel driver */ + } + + if (dev) { + fdt = nfb_get_fdt(dev); + fdt_offset = fdt_path_offset(fdt, "/system/device/endpoint0"); + strncpy(pci_dev, fdt_getprop(fdt, fdt_offset, "pci-slot", NULL), sizeof(pci_dev)-1); + + nfb_close(dev); + + /* Open the device in exclusive mode: ensure no other userspace tool is running */ + dev = nfb_open_ext(device, O_APPEND); + if (!dev) { + warnx("Can't open the NFB device in exclusive mode!"); + ret = errno; + goto err_open_dev; + } + + /* This is not optimal as there is a time gap when other tool can open the device */ + nfb_close(dev); + } else { + /* Can't open NFB device: assume the device is in the BDF format */ + strncpy(pci_dev, device, sizeof(pci_dev)-1); + } + + ret = -EBADF; + + snprintf(buf, sizeof(buf), "/sys/bus/pci/devices/%s/", pci_dev); + if (access(buf, F_OK) != 0) { + ret = -EINVAL; + warnx("The device path doesn't exists: %s", buf); + goto err_unbind; + } + + /* Unbind device from any driver */ + snprintf(buf, sizeof(buf), "/sys/bus/pci/devices/%s/driver/unbind", pci_dev); + /* If the device is not bound, it is not error */ + if (access(buf, F_OK) == 0) { + if (access(buf, W_OK) != 0) { + ret = -EACCES; + warnx("Insufficient privileges"); + goto err_unbind; + } + snprintf(buf, sizeof(buf), "echo %s > /sys/bus/pci/devices/%s/driver/unbind", pci_dev, pci_dev); + if (system(buf)) { + warnx("device unbind from driver failed"); + goto err_unbind; + } + } + + /* Write device tree metadata */ + snprintf(buf, sizeof(buf), + "echo \"len=%lu crc32=%lu busname=%s busaddr=%s\" > /sys/bus/pci/drivers/nfb/dtb_inject_meta", + dtb_size, (long unsigned) csum, "pci", pci_dev); + if (system(buf)) { + warnx("dtb metadata write failed"); + goto err_dtb_write; + } + + /* Write device tree */ + f = fopen("/sys/bus/pci/drivers/nfb/dtb_inject", "wb"); + if (f == NULL) { + ret = -EBADF; + goto err_dtb_write; + } + ret = fwrite(dtb, dtb_size, 1, f); + fclose(f); + if (ret != 1) { + ret = -EBADF; + goto err_dtb_write; + } + + ret = -EBADF; + + /* Probe device into NFB driver */ + snprintf(buf, sizeof(buf), "echo nfb > /sys/bus/pci/devices/%s/driver_override", pci_dev); + if (system(buf)) { + warnx("driver override failed"); + goto err_dtb_write; + } + + snprintf(buf, sizeof(buf), "echo %s > /sys/bus/pci/drivers_probe", pci_dev); + if (system(buf)) { + warnx("drivers probe failed"); + goto err_dtb_write; + } + + snprintf(buf, sizeof(buf), "echo > /sys/bus/pci/devices/%s/driver_override", pci_dev); + if (system(buf)) { + warnx("driver override restore failed"); + } + + return 0; + + +err_dtb_write: +err_open_dev: +err_unbind: +err_dtb_read: + free(dtb); +err_dtb_alloc: +err_dtb_open: + return ret; +} + ssize_t archive_read_first_file_with_extension(const char *filename, const char *ext, void **outp) { int ret; @@ -518,6 +679,10 @@ int main(int argc, char *argv[]) cmd = CMD_PRINT_INFO; filename = optarg; break; + case 'I': + cmd = CMD_INJECT_DTB; + filename = optarg; + break; case 'q': flags |= FLAG_QUIET; break; @@ -559,6 +724,9 @@ int main(int argc, char *argv[]) case CMD_QUICK_BOOT: ret = do_quick_boot(path, slot, filename, flags); break; + case CMD_INJECT_DTB: + ret = inject_fdt(path, filename, flags); + break; case CMD_UNKNOWN: warnx("no command"); ret = -1; From 661d9f364d8799b751fe35e181757b0115bafbc8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 15 Mar 2024 09:58:03 +0100 Subject: [PATCH 072/518] tool bootstrap: [FEATURE] add tool for bootstrapping cards The tool generates bootstrap dtb for nfb driver. It can be injected with nfb-boot -d XXXX:BB:DD.F -I dtb_to_inject.dtb Currently only the card with OFS DFL is supported (e.g. N6010). --- python/nfb-tools/nfbbootstrap/__main__.py | 3 + python/nfb-tools/nfbbootstrap/dfl.py | 118 ++++++++++++++++++ .../nfb-tools/nfbbootstrap/nfb_bootstrap.py | 47 +++++++ python/nfb-tools/nfbbootstrap/pypcie/LICENSE | 21 ++++ .../nfb-tools/nfbbootstrap/pypcie/__init__.py | 0 python/nfb-tools/nfbbootstrap/pypcie/bar.py | 87 +++++++++++++ .../nfb-tools/nfbbootstrap/pypcie/device.py | 86 +++++++++++++ python/nfb-tools/pyproject.toml | 3 +- python/nfb-tools/setup.py.in | 11 +- 9 files changed, 373 insertions(+), 3 deletions(-) create mode 100644 python/nfb-tools/nfbbootstrap/__main__.py create mode 100644 python/nfb-tools/nfbbootstrap/dfl.py create mode 100755 python/nfb-tools/nfbbootstrap/nfb_bootstrap.py create mode 100644 python/nfb-tools/nfbbootstrap/pypcie/LICENSE create mode 100644 python/nfb-tools/nfbbootstrap/pypcie/__init__.py create mode 100755 python/nfb-tools/nfbbootstrap/pypcie/bar.py create mode 100644 python/nfb-tools/nfbbootstrap/pypcie/device.py diff --git a/python/nfb-tools/nfbbootstrap/__main__.py b/python/nfb-tools/nfbbootstrap/__main__.py new file mode 100644 index 00000000..10f54252 --- /dev/null +++ b/python/nfb-tools/nfbbootstrap/__main__.py @@ -0,0 +1,3 @@ +from .nfb_bootstrap import main + +main() diff --git a/python/nfb-tools/nfbbootstrap/dfl.py b/python/nfb-tools/nfbbootstrap/dfl.py new file mode 100644 index 00000000..7e96b5ef --- /dev/null +++ b/python/nfb-tools/nfbbootstrap/dfl.py @@ -0,0 +1,118 @@ +from .pypcie.bar import Bar +from .pypcie.device import Device + + +FEATURE_FME_GUID = [0xf9e17764, 0x82fe38f0, 0x4a5246e3, 0xbfaf2ae9] + +FEATURE_ID_AFU = 0xff + +DFH_TYPE_AFU = 1 +DFH_TYPE_PRIVATE = 3 +DFH_TYPE_FIU = 4 + +DFH_TYPE_FIU_FME = 0 +DFH_TYPE_FIU_PORT = 1 + +FEATURE_ID_FIU_HEADER = 0xfe +FEATURE_ID_AFU = 0xff + +FME_HDR_CAP = 0x30 + +NEXT_AFU = 0x18 + + +def bit(b): + return (1 << b) + +def bitmask(b): + return (1 << b) - 1 + +def bitmask(b): + return (1 << b) - 1 + +def bit_get(val, b): + return (val >> b) & 1 + +def field_get(val, bto, bfrom): + return (val >> bfrom) & bitmask(bto - bfrom) + + +def feature_id(value): + id = field_get(12, 0, value) + type = field_get(64, 60, value) + + if type == DFH_TYPE_FIU: + return FEATURE_ID_FIU_HEADER + elif type == DFH_TYPE_PRIVATE: + return id + elif type == DFH_TYPE_AFU: + return FEATURE_ID_AFU + + +def parse_dfl_from(bar, offset, out_dict, verbose): + # read BAR 0, offset 0x1004 + while offset != None: + guid = [] + cfg_qword = bar.read64(offset+0) + + dfh_id = field_get(cfg_qword, 12, 0) + dfh_type = field_get(cfg_qword, 64, 60) + dfh_ver = field_get(cfg_qword, 60, 52) + dfh_next = field_get(cfg_qword, 40, 16) + eol = bit_get(cfg_qword, 40) + + dfh_types = {DFH_TYPE_AFU: "AFU", DFH_TYPE_FIU: "FIU", DFH_TYPE_PRIVATE: "PRIV"} + dfh_type_s = dfh_types[dfh_type] if dfh_type in dfh_types else "Unknown" + for i in range(4): + guid.append(bar.read32(offset + 8 + i*4)) + + if verbose: + print(f"DFL: ITEM on offset {hex(offset)}: {dfh_type_s}, ID: {dfh_id}, version {dfh_ver}, next: {hex(dfh_next)}, eol: {eol}", "GUID:", [hex(x) for x in guid]) + if dfh_type == DFH_TYPE_FIU: + fme_next_afuq = bar.read64(offset + NEXT_AFU) + fme_next_afu = field_get(fme_next_afuq, 24, 0) + + if dfh_id == DFH_TYPE_FIU_FME: + fme_cfg_qword = bar.read64(offset + FME_HDR_CAP) + fme_ports = field_get(fme_cfg_qword, 20, 17) + for p in range(fme_ports): + fme_port_cfg_qword = bar.read64(offset + FME_HDR_CAP + 8*p) + port_impl = bit_get(fme_port_cfg_qword, 60) + port_dfh_offset = field_get(fme_port_cfg_qword, 24, 0) + port_dfh_bar = field_get(fme_port_cfg_qword, 35, 32) + + if verbose: + print("DFL: FME port ", port_impl, hex(fme_port_cfg_qword), hex(port_dfh_offset), hex(port_dfh_bar)) + + if not port_impl: + continue + parse_dfl_from(bar, port_dfh_offset, out_dict, verbose) + + elif dfh_id == DFH_TYPE_FIU_PORT: + if verbose: + print("DFL: FIU port") + else: + print(f"DFL: unknown FIU {dfh_id}") + elif dfh_type == DFH_TYPE_PRIVATE: + out_dict[dfh_id] = (offset, dfh_next) + else: + if verbose: + print(f"DFL: ITEM {dfh_type} {dfh_id}") + + if eol or dfh_next == 0: + break + offset += dfh_next + + +def parse_dfl(device, verbose): + """ + Return features found in device as dict of {feature_number: (base_address, size)}. + For feature list see: + https://github.com/OFS/dfl-feature-id/blob/main/dfl-feature-ids.rst + """ + + dev = Device(device) + bar = dev.bar[0] + features = {} + parse_dfl_from(bar, 0, features, verbose) + return features diff --git a/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py new file mode 100755 index 00000000..f6009161 --- /dev/null +++ b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +import argparse +import fdt + +from .dfl import parse_dfl + + +def main(): + parser = argparse.ArgumentParser(prog='nfb-bootstrap', + description='Bootstrap factory firmare to NDK platform') + + parser.add_argument('-d', '--device', help='Device specifier, e.g. 0000:03:00.0') + parser.add_argument('-c', '--card', help='Card name, e.g. "N6010"') + parser.add_argument('--dtb', action='store', default='nfb-bootstrap.dtb', help='Output DTB filename') + parser.add_argument('-v', '--verbose', action='store_true') + + args = parser.parse_args() + + dt = fdt.FDT() + n_fw = fdt.Node('firmware') + dt.add_item(n_fw) + + if args.card: + n_fw.append(fdt.PropStrings('card-name', args.card)) + + n_mi = fdt.Node('mi_bus0') + n_mi.append(fdt.PropStrings('compatible', "netcope,bus,mi")) + n_mi.append(fdt.PropStrings('resource', "PCI0,BAR0")) + n_fw.append(n_mi) + + if args.card in ['N6010']: + features = parse_dfl(args.device, args.verbose) + + # Search for the 'PMCI Subsystem' feature + if features.get(0x12): + pmci_reg = features.get(0x12) + + n_pmci = fdt.Node('pmci') + n_mi.append(n_pmci) + n_pmci.append(fdt.PropWords('reg', *pmci_reg)) + n_pmci.append(fdt.PropStrings("compatible", "cesnet,pmci")) + + with open(args.dtb, "wb") as f: + f.write(dt.to_dtb(version=17)) + +if __name__ == "__main__": + main() diff --git a/python/nfb-tools/nfbbootstrap/pypcie/LICENSE b/python/nfb-tools/nfbbootstrap/pypcie/LICENSE new file mode 100644 index 00000000..d8b30e57 --- /dev/null +++ b/python/nfb-tools/nfbbootstrap/pypcie/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Heiko Engel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/python/nfb-tools/nfbbootstrap/pypcie/__init__.py b/python/nfb-tools/nfbbootstrap/pypcie/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/python/nfb-tools/nfbbootstrap/pypcie/bar.py b/python/nfb-tools/nfbbootstrap/pypcie/bar.py new file mode 100755 index 00000000..675af337 --- /dev/null +++ b/python/nfb-tools/nfbbootstrap/pypcie/bar.py @@ -0,0 +1,87 @@ +# SPDX-License-Identifier: MIT +# +# Copyright (c) 2021 Heiko Engel + +import os +from mmap import mmap, PROT_READ, PROT_WRITE, PAGESIZE +from struct import pack, unpack + + +class Bar(object): + """ Create a Bar instance that ``mmap()`` s a PCIe device BAR. + + :param str filename: sysfs filename for the corresponding resourceX file. + + """ + + def __init__(self, filename: str): + self.__map = None + self.__stat = os.stat(filename) + fd = os.open(filename, os.O_RDWR) + self.__map = mmap(fd, 0, prot=PROT_READ | PROT_WRITE) + os.close(fd) + + def __del__(self): + if self.__map is not None: + self.__map.close() + + def __check_offset(self, offset: int): + """ Check if the given offset is properly DW-aligned and the access + falls within the BAR size. + + """ + if offset & 0x3: + raise ValueError("unaligned access to offset 0x%x" % (offset)) + if offset + 3 > self.size: + raise ValueError("offset (0x%x) exceeds BAR size (0x%x)" % + (offset, self.size)) + + def read32(self, offset: int): + """ Read a 32 bit / double word value from offset. + + :param int offset: BAR byte offset to read from. + :returns: Double word read from the given BAR offset. + :rtype: double word / 32 bit unsigned long / int + + """ + self.__check_offset(offset) + reg = self.__map[offset:offset+4] + return unpack("=Python3.8 + + @property + def size(self): + """ + Get the size of the BAR. + + :returns: BAR size in bytes. + :rtype: int + """ + return self.__stat.st_size diff --git a/python/nfb-tools/nfbbootstrap/pypcie/device.py b/python/nfb-tools/nfbbootstrap/pypcie/device.py new file mode 100644 index 00000000..cb6d88ec --- /dev/null +++ b/python/nfb-tools/nfbbootstrap/pypcie/device.py @@ -0,0 +1,86 @@ +# SPDX-License-Identifier: MIT +# +# Copyright (c) 2021 Heiko Engel + +import os +from .bar import Bar + + +class Device(object): + """ Create a Device object for a PCIe device. + + :param str pciid: PCI bus ID as string, e.g. "0000:03:00.0" + + """ + + __base = "/sys/bus/pci/devices/" + + def __init__(self, pciid: str): + self.__base = os.path.join(self.__base, str(pciid)) + if not os.access(self.__base, os.F_OK): + raise ValueError("Device not found: %s" % (self.__base)) + self.bar = [None] * 6 + for barnum in range(0, 6): + resfile = os.path.join(self.__base, "resource%d" % (barnum)) + if os.access(resfile, os.F_OK): + self.bar[barnum] = Bar(resfile) + + def __get_attr__(self, attr: str, attr_type: type): + """ Read a sysfs attribute and convert the received string to the + given attribute type. + + :param str attr: attribute name + :param type attr_type: data type the attribute is casted to. + :returns: attribute value + :rtype: attr_type + + """ + path = os.path.join(self.__base, attr) + if not os.access(path, os.F_OK): + raise ValueError("Cannot read attribute %s" % (attr)) + with open(path) as f: + val = f.read()[:-1] # strip newline + if attr_type is int: + return attr_type(val, 0) + else: + return attr_type(val) + + def vendor(self) -> int: + """ Get the PCI vendor ID. + + :returns: PCI vendor ID + :rtype: int + """ + return self.__get_attr__("vendor", int) + + def device(self) -> int: + """ Get the PCI device ID. + + :returns: PCI device ID + :rtype: int + """ + return self.__get_attr__("device", int) + + def revision(self) -> int: + """ Get the PCI revision Number. + + :returns: PCI revision Number + :rtype: int + """ + return self.__get_attr__("revision", int) + + def subsystem_vendor(self) -> int: + """ Get the PCI subsystem vendor ID. + + :returns: PCI subsystem vendor ID + :rtype: int + """ + return self.__get_attr__("subsystem_vendor", int) + + def subsystem_device(self) -> int: + """ Get the PCI subsystem device ID. + + :returns: PCI subsystem device ID + :rtype: int + """ + return self.__get_attr__("subsystem_device", int) diff --git a/python/nfb-tools/pyproject.toml b/python/nfb-tools/pyproject.toml index caa679c6..4ddd7bba 100644 --- a/python/nfb-tools/pyproject.toml +++ b/python/nfb-tools/pyproject.toml @@ -1,10 +1,11 @@ [project] name = "nfb-tools" -version = "0.1.0" +version = "0.2.0" dependencies = [] [project.scripts] nfb-meter = "nfbmeter.nfbmeter:main" +nfb-bootstrap = "nfbbootstrap.nfb_bootstrap:main" [tool.setuptools] packages = ["nfbmeter"] diff --git a/python/nfb-tools/setup.py.in b/python/nfb-tools/setup.py.in index 05828a59..c64406e5 100644 --- a/python/nfb-tools/setup.py.in +++ b/python/nfb-tools/setup.py.in @@ -1,11 +1,18 @@ from setuptools import setup setup( - packages=["nfbmeter"], - package_dir={'nfbmeter': '${CMAKE_CURRENT_SOURCE_DIR}/nfbmeter'}, + packages=[ + "nfbmeter", + "nfbbootstrap", "nfbbootstrap.pypcie", + ], + package_dir={ + 'nfbmeter': '${CMAKE_CURRENT_SOURCE_DIR}/nfbmeter', + 'nfbbootstrap': '${CMAKE_CURRENT_SOURCE_DIR}/nfbbootstrap', + }, entry_points={ 'console_scripts': [ 'nfb-meter = nfbmeter.nfbmeter:main', + 'nfb-bootstrap = nfbbootstrap.nfb_bootstrap:main', ], }, ) From d2237b3c1244fca6c695884a099806fa9499e9ba Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 2 Apr 2024 08:03:55 +0200 Subject: [PATCH 073/518] drivers - N6010: [FIX] add own log driver --- build.sh | 2 +- drivers/kernel/drivers/nfb/Makefile | 2 +- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 179ea9c0..c86018eb 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ AUTOINSTALL=true # whether dependencies should be installed with '-y' RELTYPE=Release # Release type (Debug/Release) FILENAME_3RDPARTY="3rdparty.tar.gz" -SRC_3RDPARTY_VERSION="v6.21.0" +SRC_3RDPARTY_VERSION="v6.21.1" URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_VERSION/$FILENAME_3RDPARTY" EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index 98370cd6..a980087e 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -16,7 +16,7 @@ nfb-objs += mi/mi.o nfb-objs += ndp/ctrl.o ndp/ctrl_ndp.o ndp/channel.o ndp/subscription.o ndp/subscriber.o ndp/ring.o ndp/char.o ndp/driver.o ndp/kndp.o nfb-objs += ndp_netdev/core.o nfb-objs += boot/flash.o boot/reload.o boot/boot.o boot/gecko.o boot/sdm.o -nfb-objs += ../mfd/intel-m10-bmc-core.o ../fpga/fpga-image-load.o ../fpga/intel-m10-bmc-sec-update.o ../hwmon/intel-m10-bmc-hwmon.o boot/nfb-pmci.o +nfb-objs += ../mfd/intel-m10-bmc-core.o ../fpga/fpga-image-load.o ../fpga/intel-m10-bmc-sec-update.o ../hwmon/intel-m10-bmc-hwmon.o ../mfd/intel-m10-bmc-log.o boot/nfb-pmci.o nfb-objs += net/driver.o net/device.o net/ethtool.o net/sysfs.o nfb-objs += qdr/qdr.o nfb-objs += misc.o lock.o bus.o char.o pci.o core.o diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index 62483442..d0f36257 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -378,6 +378,7 @@ void nfb_pmci_detach(struct nfb_boot *boot) extern struct platform_driver nfb_intel_m10bmc_sec_driver; extern struct platform_driver nfb_intel_m10bmc_hwmon_driver; +extern struct platform_driver nfb_intel_m10bmc_log_driver; struct platform_driver nfb_intel_m10bmc = { .driver = { @@ -388,6 +389,9 @@ struct platform_driver nfb_intel_m10bmc = { int nfb_pmci_init() { int ret; + ret = platform_driver_register(&nfb_intel_m10bmc_log_driver); + if (ret) + goto err_log; ret = platform_driver_register(&nfb_intel_m10bmc_sec_driver); if (ret) @@ -408,6 +412,8 @@ int nfb_pmci_init() err_hwmon: platform_driver_unregister(&nfb_intel_m10bmc_sec_driver); err_sec: + platform_driver_unregister(&nfb_intel_m10bmc_log_driver); +err_log: return ret; } @@ -417,6 +423,7 @@ void nfb_pmci_exit() platform_driver_unregister(&nfb_intel_m10bmc); platform_driver_unregister(&nfb_intel_m10bmc_hwmon_driver); platform_driver_unregister(&nfb_intel_m10bmc_sec_driver); + platform_driver_unregister(&nfb_intel_m10bmc_log_driver); } #endif From aad872d87f849cb6230f2dd653b94355c17db874 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 2 Apr 2024 10:36:07 +0200 Subject: [PATCH 074/518] drivers - PMCI: read SN from flash --- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index d0f36257..79de03a9 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -298,11 +298,14 @@ static struct regmap_config m10bmc_pmci_regmap_config = { int nfb_pmci_attach(struct nfb_boot *boot) { + char * pmci_bom_info, *snc; + struct nfb_device *nfb = boot->nfb; struct pmci_device *pmci; int fdt_offset; int ret = 0; + int sn; pmci = kzalloc(sizeof(*pmci), GFP_KERNEL); if (!pmci) { @@ -348,6 +351,23 @@ int nfb_pmci_attach(struct nfb_boot *boot) goto err_m10bmc_init; boot->pmci = pmci; + + /* Read SN */ + if (pmci->m10bmc.ops.flash_read) { + pmci_bom_info = kzalloc(PMCI_BOM_INFO_SIZE+1+1, GFP_KERNEL); + if (pmci_bom_info) { + pmci_bom_info[0] = '\n'; + pmci_bom_info[PMCI_BOM_INFO_SIZE+1] = 0; + pmci->m10bmc.ops.flash_read(&pmci->m10bmc, pmci_bom_info+1, PMCI_BOM_INFO_ADDR, PMCI_BOM_INFO_SIZE); + while ((snc = strstr(pmci_bom_info, "\nSN,"))) { + if (sscanf(snc, "\nSN,%d\n", &sn) == 1) { + boot->nfb->serial = sn; + break; + } + } + kfree(pmci_bom_info); + } + } return ret; err_m10bmc_init: From 8e8df8cfbc1136d0898ecafdfdc6c26f7c61faa9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 2 Apr 2024 15:58:16 +0200 Subject: [PATCH 075/518] tool dma: [FEATURE] print sum of counters The sum of counters over selected/all queues can be now printed with switch -T. --- tools/dma/dma.c | 291 +++++++++++++++++++++++++++++------------------- 1 file changed, 178 insertions(+), 113 deletions(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 38cda491..1be27e12 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -35,7 +35,7 @@ /*! -v verbose mode; */ /*! -V version */ -#define ARGUMENTS "d:i:q:rtRS:vh" +#define ARGUMENTS "d:i:q:rtRS:Tvh" enum commands { CMD_PRINT_STATUS, @@ -88,9 +88,11 @@ void usage(const char *me, int verbose) printf("Usage: %s [-rtRvh] [-i index] [-d path]\n", me); printf("-d path Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); printf("-i indexes Controllers numbers to use - list or range, e.g. \"0-5,7\" [default: all]\n"); - printf("-r Use RX DMA controllers\n"); - printf("-t Use TX DMA controllers\n"); + printf("-r Use RX DMA queues\n"); + printf("-t Use TX DMA queues\n"); printf("-R Resets packet counters (use -RR for read & reset)\n"); + printf("-T Print the sum of all counters of selected queues\n" + " (use -TT to print each queue separately)\n"); printf("-S size Set kernel ring buffer size (can be with K/M/G suffix)\n"); printf("-q query Get specific informations%s\n", verbose ? "" : " (-v for more info)"); if (verbose) { @@ -238,185 +240,198 @@ int query_print(struct nfb_device *dev, struct list_range index_range, return 0; } +void rxqueue_get_status(struct nc_rxqueue *q, struct nc_rxqueue_status *s, struct nc_rxqueue_counters *c, enum commands cmd) +{ + if (s) { + nc_rxqueue_read_status(q, s); + } + + if (c) { + if (cmd == CMD_COUNTER_READ_AND_RESET) { + if (nc_rxqueue_read_and_reset_counters(q, c) == -ENXIO) { + warnx("controller doesn't support atomic read & reset, command will be done non-atomically"); + nc_rxqueue_read_counters(q, c); + nc_rxqueue_reset_counters(q); + } + } else { + nc_rxqueue_read_counters(q, c); + } + } +} + /*! * \brief Print values from TX_DMA_INFO structure * * \param *tx_dma structure from which are data read */ -void rxqueue_print_status(struct nc_rxqueue *q, int index, int verbose, enum commands cmd) +void rxqueue_print_status(struct nc_rxqueue *q, int index, int verbose, struct nc_rxqueue_status *s, struct nc_rxqueue_counters *c) { - struct nc_rxqueue_status s; - struct nc_rxqueue_counters c; - printf("------------------------------ RX%02d %s controller ----\n", index, q->name); - if (verbose > 0) { - nc_rxqueue_read_status(q, &s); - - printf("Control reg : 0x%.8X", s._ctrl_raw); + if (s && verbose > 0) { + printf("Control reg : 0x%.8X", s->_ctrl_raw); if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { printf(" | %s |", - s.ctrl_running ? "Run " : "Stop "); + s->ctrl_running ? "Run " : "Stop "); } else if (q->type == QUEUE_TYPE_SZE) { printf(" | %s | %s | EpMsk %.2X | VFID %.2X |", - s.ctrl_running ? "Run " : "Stop ", - s.ctrl_discard ? "Discard " : "Block ", - (s._ctrl_raw >> 16) & 0xFF, - (s._ctrl_raw >> 24) & 0xFF); + s->ctrl_running ? "Run " : "Stop ", + s->ctrl_discard ? "Discard " : "Block ", + (s->_ctrl_raw >> 16) & 0xFF, + (s->_ctrl_raw >> 24) & 0xFF); } printf("\n"); - printf("Status reg : 0x%.8X", s._stat_raw); + printf("Status reg : 0x%.8X", s->_stat_raw); if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { printf(" | %s |", - s.stat_running ? "Running " : "Stopped "); + s->stat_running ? "Running " : "Stopped "); } else if (q->type == QUEUE_TYPE_SZE) { printf(" | %s | %s | %s | %s |", - s.stat_running ? "Running " : "Stopped ", - s.stat_desc_rdy ? "Desc RDY" : "Desc - ", - s.stat_data_rdy ? "Data RDY" : "Data - ", - s.stat_ring_rdy ? "SW RDY " : "SW Full "); + s->stat_running ? "Running " : "Stopped ", + s->stat_desc_rdy ? "Desc RDY" : "Desc - ", + s->stat_data_rdy ? "Data RDY" : "Data - ", + s->stat_ring_rdy ? "SW RDY " : "SW Full "); } printf("\n"); if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { - printf("SW header pointer : 0x%08lX\n", s.sw_pointer); - printf("HW header pointer : 0x%08lX\n", s.hw_pointer); - printf("Header pointer mask : 0x%08lX\n", s.pointer_mask); - printf("* Header buffer size : "); print_size(s.pointer_mask ? s.pointer_mask + 1 : 0); printf("\n"); - printf("* Fillable headers in HW : 0x%08lX\n", (s.sw_pointer - s.hw_pointer - 1) & s.pointer_mask); - - printf("SW descriptor pointer : 0x%08lX\n", s.sd_pointer); - printf("HW descriptor pointer : 0x%08lX\n", s.hd_pointer); - printf("Descriptor pointer mask : 0x%08lX\n", s.desc_pointer_mask); - printf("* Descriptor buffer size : "); print_size(s.desc_pointer_mask ? s.desc_pointer_mask + 1 : 0); printf("\n"); - printf("* Usable descriptors in HW : 0x%08lX\n", (s.sd_pointer - s.hd_pointer) & s.desc_pointer_mask); + printf("SW header pointer : 0x%08lX\n", s->sw_pointer); + printf("HW header pointer : 0x%08lX\n", s->hw_pointer); + printf("Header pointer mask : 0x%08lX\n", s->pointer_mask); + printf("* Header buffer size : "); print_size(s->pointer_mask ? s->pointer_mask + 1 : 0); printf("\n"); + printf("* Fillable headers in HW : 0x%08lX\n", (s->sw_pointer - s->hw_pointer - 1) & s->pointer_mask); + + printf("SW descriptor pointer : 0x%08lX\n", s->sd_pointer); + printf("HW descriptor pointer : 0x%08lX\n", s->hd_pointer); + printf("Descriptor pointer mask : 0x%08lX\n", s->desc_pointer_mask); + printf("* Descriptor buffer size : "); print_size(s->desc_pointer_mask ? s->desc_pointer_mask + 1 : 0); printf("\n"); + printf("* Usable descriptors in HW : 0x%08lX\n", (s->sd_pointer - s->hd_pointer) & s->desc_pointer_mask); } else { - printf("SW pointer : 0x%08lX\n", s.sw_pointer); - printf("HW pointer : 0x%08lX\n", s.hw_pointer); - printf("Pointer mask : 0x%08lX\n", s.pointer_mask); - printf("* Buffer size : "); print_size(s.pointer_mask ? s.pointer_mask + 1 : 0); printf("\n"); + printf("SW pointer : 0x%08lX\n", s->sw_pointer); + printf("HW pointer : 0x%08lX\n", s->hw_pointer); + printf("Pointer mask : 0x%08lX\n", s->pointer_mask); + printf("* Buffer size : "); print_size(s->pointer_mask ? s->pointer_mask + 1 : 0); printf("\n"); } if (q->type == QUEUE_TYPE_SZE || q->type == QUEUE_TYPE_NDP) - printf("Timeout reg : 0x%08lX\n", s.timeout); + printf("Timeout reg : 0x%08lX\n", s->timeout); if (q->type == QUEUE_TYPE_SZE) { - printf("Max request : 0x%04lX | ", s.max_request); - print_size(s.max_request); printf("\n"); + printf("Max request : 0x%04lX | ", s->max_request); + print_size(s->max_request); printf("\n"); } } - if (cmd == CMD_COUNTER_READ_AND_RESET) { - if (nc_rxqueue_read_and_reset_counters(q, &c) == -ENXIO) { - warnx("controller doesn't support atomic read & reset, command will be done non-atomically"); - nc_rxqueue_read_counters(q, &c); - nc_rxqueue_reset_counters(q); - } - } else { - nc_rxqueue_read_counters(q, &c); + if (c) { + printf("Received : %llu\n", c->received); + if (c->have_bytes) + printf("Received bytes : %llu\n", c->received_bytes); + printf("Discarded : %llu\n", c->discarded); + if (c->have_bytes) + printf("Discarded bytes : %llu\n", c->discarded_bytes); } - - printf("Received : %llu\n", c.received); - if (c.have_bytes) - printf("Received bytes : %llu\n", c.received_bytes); - printf("Discarded : %llu\n", c.discarded); - if (c.have_bytes) - printf("Discarded bytes : %llu\n", c.discarded_bytes); - - if (verbose > 1) { - printf("Desc base : 0x%.16llX\n", s.desc_base); + if (s && verbose > 1) { + printf("Desc base : 0x%.16llX\n", s->desc_base); if (q->type == QUEUE_TYPE_CALYPTE) - printf("Header base : 0x%.16llX\n", s.hdr_base); + printf("Header base : 0x%.16llX\n", s->hdr_base); else - printf("Pointer base : 0x%.16llX\n", s.pointer_base); + printf("Pointer base : 0x%.16llX\n", s->pointer_base); } } -void txqueue_print_status(struct nc_txqueue *q, int index, int verbose, enum commands cmd) +void txqueue_get_status(struct nc_txqueue *q, struct nc_txqueue_status *s, struct nc_txqueue_counters *c, enum commands cmd) { - struct nc_txqueue_status s; - struct nc_txqueue_counters c; + if (s) { + nc_txqueue_read_status(q, s); + } + + if (c) { + if (cmd == CMD_COUNTER_READ_AND_RESET) { + if (nc_txqueue_read_and_reset_counters(q, c) == -ENXIO) { + warnx("controller doesn't support atomic read & reset, command will be done non-atomically"); + nc_txqueue_read_counters(q, c); + nc_txqueue_reset_counters(q); + } + } else { + nc_txqueue_read_counters(q, c); + } + } +} +void txqueue_print_status(struct nc_txqueue *q, int index, int verbose, struct nc_txqueue_status *s, struct nc_txqueue_counters *c) +{ printf("------------------------------ TX%02d %s controller ----\n", index, q->name); - if (verbose > 0) { - nc_txqueue_read_status(q, &s); - printf("Control reg : 0x%.8X", s._ctrl_raw); + if (s && verbose > 0) { + printf("Control reg : 0x%.8X", s->_ctrl_raw); if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { printf(" | %s |", - s.ctrl_running ? "Run " : "Stop "); + s->ctrl_running ? "Run " : "Stop "); } else if (q->type == QUEUE_TYPE_SZE) { printf(" | %s | EpMsk %.2X | VFID %.2X |", - s.ctrl_running ? "Run " : "Stop ", - (s._ctrl_raw >> 16) & 0xFF, - (s._ctrl_raw >> 24) & 0xFF); + s->ctrl_running ? "Run " : "Stop ", + (s->_ctrl_raw >> 16) & 0xFF, + (s->_ctrl_raw >> 24) & 0xFF); } printf("\n"); - printf("Status reg : 0x%.8X", s._stat_raw); + printf("Status reg : 0x%.8X", s->_stat_raw); if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { printf(" | %s |", - s.stat_running ? "Running " : "Stopped "); + s->stat_running ? "Running " : "Stopped "); } else if (q->type == QUEUE_TYPE_SZE) { printf(" | %s |", - s.stat_running ? "Running " : "Stopped "); + s->stat_running ? "Running " : "Stopped "); } printf("\n"); if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { if (q->type == QUEUE_TYPE_CALYPTE) { - printf("SW header pointer : 0x%08lX\n", s.sw_pointer); - printf("HW header pointer : 0x%08lX\n", s.hw_pointer); - printf("Header pointer mask : 0x%08lX\n", s.pointer_mask); - printf("* Header buffer size : "); print_size(s.pointer_mask ? s.pointer_mask + 1 : 0); printf("\n"); - printf("* Fillable headers in HW : 0x%08lX\n", (s.sw_pointer - s.hw_pointer - 1) & s.pointer_mask); + printf("SW header pointer : 0x%08lX\n", s->sw_pointer); + printf("HW header pointer : 0x%08lX\n", s->hw_pointer); + printf("Header pointer mask : 0x%08lX\n", s->pointer_mask); + printf("* Header buffer size : "); print_size(s->pointer_mask ? s->pointer_mask + 1 : 0); printf("\n"); + printf("* Fillable headers in HW : 0x%08lX\n", (s->sw_pointer - s->hw_pointer - 1) & s->pointer_mask); } - printf("SW descriptor pointer : 0x%08lX\n", s.sd_pointer); - printf("HW descriptor pointer : 0x%08lX\n", s.hd_pointer); - printf("Descriptor pointer mask : 0x%08lX\n", s.desc_pointer_mask); - printf("* Descriptor buffer size : "); print_size(s.desc_pointer_mask ? s.desc_pointer_mask + 1 : 0); printf("\n"); - printf("* Usable descriptors in HW : 0x%08lX\n", (s.sd_pointer - s.hd_pointer) & s.desc_pointer_mask); + printf("SW descriptor pointer : 0x%08lX\n", s->sd_pointer); + printf("HW descriptor pointer : 0x%08lX\n", s->hd_pointer); + printf("Descriptor pointer mask : 0x%08lX\n", s->desc_pointer_mask); + printf("* Descriptor buffer size : "); print_size(s->desc_pointer_mask ? s->desc_pointer_mask + 1 : 0); printf("\n"); + printf("* Usable descriptors in HW : 0x%08lX\n", (s->sd_pointer - s->hd_pointer) & s->desc_pointer_mask); } else { - printf("SW pointer : 0x%08lX\n", s.sw_pointer); - printf("HW pointer : 0x%08lX\n", s.hw_pointer); - printf("Pointer mask : 0x%08lX\n", s.pointer_mask); - printf("* Buffer size : "); print_size(s.pointer_mask ? s.pointer_mask + 1 : 0); printf("\n"); + printf("SW pointer : 0x%08lX\n", s->sw_pointer); + printf("HW pointer : 0x%08lX\n", s->hw_pointer); + printf("Pointer mask : 0x%08lX\n", s->pointer_mask); + printf("* Buffer size : "); print_size(s->pointer_mask ? s->pointer_mask + 1 : 0); printf("\n"); } if (q->type == QUEUE_TYPE_SZE || q->type == QUEUE_TYPE_NDP) - printf("Timeout reg : 0x%08lX\n", s.timeout); + printf("Timeout reg : 0x%08lX\n", s->timeout); if (q->type == QUEUE_TYPE_SZE) { - printf("Max request : 0x%04lX | ", s.max_request); - print_size(s.max_request); printf("\n"); - } - } - - if (cmd == CMD_COUNTER_READ_AND_RESET) { - if (nc_txqueue_read_and_reset_counters(q, &c) == -ENXIO) { - warnx("controller doesn't support atomic read & reset, command will be done non-atomically"); - nc_txqueue_read_counters(q, &c); - nc_txqueue_reset_counters(q); + printf("Max request : 0x%04lX | ", s->max_request); + print_size(s->max_request); printf("\n"); } - } else { - nc_txqueue_read_counters(q, &c); } - printf("Sent : %llu\n", c.sent); - if (c.have_bytes) - printf("Sent bytes : %llu\n", c.sent_bytes); + if (c) { + printf("Sent : %llu\n", c->sent); + if (c->have_bytes) + printf("Sent bytes : %llu\n", c->sent_bytes); - if (c.have_tx_discard) { - printf("Discarded : %llu\n", c.discarded); - printf("Discarded bytes : %llu\n", c.discarded_bytes); + if (c->have_tx_discard) { + printf("Discarded : %llu\n", c->discarded); + if (c->have_bytes) + printf("Discarded bytes : %llu\n", c->discarded_bytes); + } } - if (verbose > 1 && q->type != QUEUE_TYPE_CALYPTE) { - printf("Desc base : 0x%.16llX\n", s.desc_base); - printf("Pointer base : 0x%.16llX\n", s.pointer_base); + if (s && verbose > 1 && q->type != QUEUE_TYPE_CALYPTE) { + printf("Desc base : 0x%.16llX\n", s->desc_base); + printf("Pointer base : 0x%.16llX\n", s->pointer_base); } } @@ -437,6 +452,7 @@ int main(int argc, char *argv[]) int dir = -1; enum commands cmd = CMD_PRINT_STATUS; int verbose = 0; + int sum = 0; int ret; const char *query = NULL; @@ -452,6 +468,14 @@ int main(int argc, char *argv[]) struct nc_txqueue *txq; struct list_range index_range; + struct nc_rxqueue_counters cntr_rx; + struct nc_txqueue_counters cntr_tx; + struct nc_rxqueue_counters sum_rx = {0, }; + struct nc_txqueue_counters sum_tx = {0, }; + + struct nc_rxqueue_status stat_rx; + struct nc_txqueue_status stat_tx; + list_range_init(&index_range); while ((c = getopt(argc, argv, ARGUMENTS)) != -1) { @@ -485,6 +509,9 @@ int main(int argc, char *argv[]) case 'r': dir = 0; break; + case 'T': + sum++; + break; case 'S': cmd = CMD_SET_RING_SIZE; csize = optarg; @@ -543,8 +570,16 @@ int main(int argc, char *argv[]) break; case CMD_COUNTER_READ_AND_RESET: case CMD_PRINT_STATUS: - rxqueue_print_status(rxq, i, verbose, cmd); - printf("\n"); + rxqueue_get_status(rxq, verbose ? &stat_rx : NULL, &cntr_rx, cmd); + if (sum != 1) { + rxqueue_print_status(rxq, i, verbose, verbose ? &stat_rx : NULL, &cntr_rx); + printf("\n"); + } + sum_rx.received += cntr_rx.received; + sum_rx.received_bytes += cntr_rx.received_bytes; + + sum_rx.discarded += cntr_rx.discarded; + sum_rx.discarded_bytes += cntr_rx.discarded_bytes; break; case CMD_SET_RING_SIZE: set_ring_size(dev, 0, i, csize); @@ -575,8 +610,13 @@ int main(int argc, char *argv[]) break; case CMD_COUNTER_READ_AND_RESET: case CMD_PRINT_STATUS: - txqueue_print_status(txq, i, verbose, cmd); - printf("\n"); + txqueue_get_status(txq, verbose ? &stat_tx : NULL, &cntr_tx, cmd); + if (sum != 1) { + txqueue_print_status(txq, i, verbose, verbose ? &stat_tx : NULL, &cntr_tx); + printf("\n"); + } + sum_tx.sent += cntr_tx.sent; + sum_tx.sent_bytes += cntr_tx.sent_bytes; break; case CMD_SET_RING_SIZE: if (txq->type == QUEUE_TYPE_CALYPTE) @@ -594,6 +634,31 @@ int main(int argc, char *argv[]) } } + if (sum && (dir == -1 || dir == 0)) { + printf("------------------------------ RX SUM -----------------\n"); + printf("Received : %llu\n", sum_rx.received); + if (cntr_rx.have_bytes) + printf("Received bytes : %llu\n", sum_rx.received_bytes); + printf("Discarded : %llu\n", sum_rx.discarded); + if (cntr_rx.have_bytes) + printf("Discarded bytes : %llu\n", sum_rx.discarded_bytes); + printf("\n"); + } + + if (sum && (dir == -1 || dir == 1)) { + printf("------------------------------ TX SUM -----------------\n"); + printf("Sent : %llu\n", sum_tx.sent); + if (cntr_tx.have_bytes) + printf("Sent bytes : %llu\n", sum_tx.sent_bytes); + + if (cntr_tx.have_tx_discard) { + printf("Discarded : %llu\n", sum_tx.discarded); + if (sum_tx.have_bytes) + printf("Discarded bytes : %llu\n", sum_tx.discarded_bytes); + } + printf("\n"); + } + nfb_close(dev); list_range_destroy(&index_range); From ee678898559d44a10ed394ac7c907f6946abb816 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 4 Apr 2024 06:51:39 +0200 Subject: [PATCH 076/518] bump version to 6.22.0 --- Changelog | 10 ++++++++++ VERSION | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index e5f20004..3548850d 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,13 @@ +* Thu Apr 4 2024 Martin Spinler - 6.22.0-1 +- [FEATURE] convert nfb-xvc to pure userspace with libpci +- [FEATURE] print sum of counters in nfb-dma +- [FEATURE] read serial number from PMCI/BMC (N6010) +- [FEATURE] bootstrap tool for easy use of card with factory firmware (N6010) +- [FEATURE] allow to inject DTB with nfb-boot tool +- [FEATURE] allow to specify approximate Tx speed in ndp-generate +- [BUGFIX] allow coexistence with newer OFS drivers +- [BUGFIX] remove sleep while atomic in DMA Medusa driver + * Mon Mar 4 2024 Martin Spinler - 6.21.1-1 - [FEATURE] added nfb-meter python tool diff --git a/VERSION b/VERSION index 476d3ceb..fe675047 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.21.1 +6.22.0 From a9d881c4d93fe98d809901f4fd7176b7cd4d450a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 4 Apr 2024 09:07:23 +0200 Subject: [PATCH 077/518] drivers - boot: [FIX] enable coexistence PMCI and SDM This allows to read temperature. --- drivers/kernel/drivers/nfb/boot/boot.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 568b80ab..e950a982 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -262,12 +262,8 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) boot->nfb = nfb; #ifdef CONFIG_NFB_ENABLE_PMCI - ret = nfb_pmci_attach(boot); - if (ret == 0 && boot->pmci) - goto have_boot_controller; #endif - /* Cards with Intel FPGA (Stratix10, Agilex) use Secure Device Manager for QSPI Flash access and Boot */ boot->sdm = NULL; boot->sdm_boot_en = 0; @@ -292,7 +288,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) fdt_offset = fdt_node_offset_by_compatible(nfb->fdt, -1, "netcope,boot_controller"); // FIXME: better create some general boot controller interface if (fdt_offset < 0) { - if (boot->sdm_boot_en == 0) { + if (boot->sdm_boot_en == 0 && boot->pmci == NULL) { ret = -ENODEV; dev_warn(&nfb->pci->dev, "nfb_boot: No boot_controller found in FDT.\n"); goto err_nocomp; @@ -302,13 +298,10 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) } boot->comp = nfb_comp_open(nfb, fdt_offset); - if (!boot->comp) { + if (!boot->comp && boot->pmci == NULL) { ret = -ENODEV; goto err_comp_open; } -#ifdef CONFIG_NFB_ENABLE_PMCI -have_boot_controller: -#endif prop32 = fdt_getprop(nfb->fdt, fdt_offset, "num_flash", &len); if (len == sizeof(*prop32)) From 7a7f4b716a9543a3e205c980b5f80895c199f488 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 4 Apr 2024 18:18:17 +0200 Subject: [PATCH 078/518] libnfb - open: [FIX] check whole path string In the short path feature (for example "nfb-info -d 1" for the "/dev/nfb1") we must check if the device path string was completely parsed. User can specify the device in other manner (e.g. "-d 0000:17:00.0"), which can be acceptable form for some functions. But in this case the sscanf has successfully parsed just "0000" as a valid number and nfb_open used it in snprintf("/dev/nfb%d", nr), which can lead to unwanted device. --- libnfb/src/nfb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/src/nfb.c b/libnfb/src/nfb.c index 4f2342ce..8ab27dde 100644 --- a/libnfb/src/nfb.c +++ b/libnfb/src/nfb.c @@ -80,7 +80,7 @@ struct nfb_device *nfb_open_ext(const char *devname, int oflag) libnfb_ext_get_ops_t* get_ops; - if (sscanf(devname, "%u", &index) == 1) { + if (sscanf(devname, "%u%n", &index, &ret) >= 1 && (size_t) ret == strlen(devname)) { ret = snprintf(path, PATH_LEN, "/dev/nfb%u", index); if (ret >= PATH_LEN || ret < 0) { errno = ENODEV; From a46088840f1b78fa2fa6119eb7a46b7837cbeb14 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 5 Apr 2024 09:05:26 +0200 Subject: [PATCH 079/518] python nfb-tools: [FIX] missing nfb-bootstrap in setup.py --- python/nfb-tools/setup.py | 16 ++++++++++++++-- python/nfb-tools/setup.py.in | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/python/nfb-tools/setup.py b/python/nfb-tools/setup.py index 835cdfce..6fe24d51 100644 --- a/python/nfb-tools/setup.py +++ b/python/nfb-tools/setup.py @@ -1,11 +1,23 @@ from setuptools import setup setup( - packages=["nfbmeter"], - package_dir={'nfbmeter': 'nfbmeter'}, + name='nfbtools', + packages=[ + "nfbmeter", + "nfbbootstrap", "nfbbootstrap.pypcie", + ], + package_dir={ + 'nfbmeter': 'nfbmeter', + 'nfbbootstrap': 'nfbbootstrap', + }, entry_points={ 'console_scripts': [ 'nfb-meter=nfbmeter.nfbmeter:main', + 'nfb-bootstrap = nfbbootstrap.nfb_bootstrap:main', ], }, + install_requires=[ + "fdt", + "pyyaml", + ] ) diff --git a/python/nfb-tools/setup.py.in b/python/nfb-tools/setup.py.in index c64406e5..942dba51 100644 --- a/python/nfb-tools/setup.py.in +++ b/python/nfb-tools/setup.py.in @@ -1,6 +1,7 @@ from setuptools import setup setup( + name='nfbtools', packages=[ "nfbmeter", "nfbbootstrap", "nfbbootstrap.pypcie", From 4bececc3404fcd9f9d9c844226210042760a724f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 4 Apr 2024 15:41:05 +0200 Subject: [PATCH 080/518] nfb-eth: [FIX] throw error if the repeater can't be configured --- libnfb/include/netcope/idcomp.h | 5 +++-- tools/eth/main.c | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libnfb/include/netcope/idcomp.h b/libnfb/include/netcope/idcomp.h index 3288cabc..9ad732df 100644 --- a/libnfb/include/netcope/idcomp.h +++ b/libnfb/include/netcope/idcomp.h @@ -52,7 +52,7 @@ static inline int nc_idcomp_sysmon_get_temp(struct nfb_device *dev, int32_t *val return 0; } -static inline void nc_idcomp_repeater_set(struct nfb_device *dev, unsigned index, enum nc_idcomp_repeater status) +static inline int nc_idcomp_repeater_set(struct nfb_device *dev, unsigned index, enum nc_idcomp_repeater status) { int node; int len; @@ -71,7 +71,7 @@ static inline void nc_idcomp_repeater_set(struct nfb_device *dev, unsigned index node = fdt_node_offset_by_compatible(nfb_get_fdt(dev), -1, "netcope,idcomp"); comp = nfb_comp_open(dev, node); if (!comp) - return; + return -ENODEV; reg = nfb_comp_read32(comp, IDCOMP_REG_REPEATER); val = status << (index * 2); @@ -80,6 +80,7 @@ static inline void nc_idcomp_repeater_set(struct nfb_device *dev, unsigned index nfb_comp_write32(comp, IDCOMP_REG_REPEATER, reg); nfb_comp_close(comp); + return 0; } static inline enum nc_idcomp_repeater nc_idcomp_repeater_get(struct nfb_device *dev, unsigned index) diff --git a/tools/eth/main.c b/tools/eth/main.c index 7288a66e..84163b49 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -310,7 +310,9 @@ int main(int argc, char *argv[]) if (list_range_empty(&index_range) || list_range_contains(&index_range, p.index)) { if (p.command == CMD_SET_REPEATER) { used++; - nc_idcomp_repeater_set(dev, p.index, repeater_status); + if (nc_idcomp_repeater_set(dev, p.index, repeater_status)) { + errx(EXIT_FAILURE, "Can't set repeater mode. Use loopback features in PCS/PMA section"); + } } else { if (p.command == CMD_PRINT_STATUS) { if (used++) @@ -363,10 +365,10 @@ int main(int argc, char *argv[]) used++; repeater_status = nc_idcomp_repeater_get(dev, p.index); switch (repeater_status) { - case IDCOMP_REPEATER_NORMAL: repeater_str = "Normal (transmit data from application)"; break; - case IDCOMP_REPEATER_REPEAT: repeater_str = "Repeat (transmit data from RXMAC)"; break; - case IDCOMP_REPEATER_IDLE: repeater_str = "Idle (transmit disabled)"; break; - default: repeater_str = "Unknown"; break; + case IDCOMP_REPEATER_NORMAL: repeater_str = "Normal (transmit data from application)"; break; + case IDCOMP_REPEATER_REPEAT: repeater_str = "Repeat (transmit data from RXMAC)"; break; + case IDCOMP_REPEATER_IDLE: repeater_str = "Idle (transmit disabled)"; break; + default: repeater_str = "Unknown (use the PCS/PMA features)"; break; } printf("Repeater status : %s\n", repeater_str); } From 683cce134422593a3c42e0190c0081778f6a5d7d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 4 Apr 2024 15:44:36 +0200 Subject: [PATCH 081/518] nfb-eth: [DOC] better examples and loopback modes --- tools/eth/main.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tools/eth/main.c b/tools/eth/main.c index 84163b49..52d5afe2 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -84,13 +84,26 @@ void usage(const char *progname, int verbose) printf(" example of usage: '-q rx_link,tx_octets,pma_speed'\n"); } - printf("-v Increase verbosity\n"); + printf("-v Increase verbosity (including help)\n"); printf("-h Show this text\n"); + printf("\n"); printf("Examples:\n"); - printf("%s -Pv\n" - " Print all supported PMA types/modes and features.\n", progname); - printf("%s -Pc \"+PMA local loopback\"\n" - " Enable local loopback on all PMAs.\n", progname); + printf("%s -Pv " "Print all supported PCS/PMA types/modes and features\n", progname); + printf("%s -Pc 100GBASE-SR4 " "Change the link type/mode\n", progname); + printf("%s -Pc \"+25G RS-FEC Enable\" " "Enable the RS-FEC feature (can affect the link type/mode)\n", progname); + printf("%s -Pc \"+PMA local loopback\" " "Receive exactly the same data sent by the device (for transceiver-less testing)\n", progname); + printf("%*s " "(discards data from the link, far-end still should receive the sent data)\n", (int)strlen(progname), ""); + printf("%s -Pc \"+PCS reverse loopback\" " "Transmit received data back to far-end (\"repeater\" functionality)\n", progname); + printf("%*s " "(application still receives the data from the link)\n", (int)strlen(progname), ""); + printf("%s -Pc -Reset " "Unreset the PCS/PMA\n", progname); + if (verbose) { + printf("\n"); + printf("Loopback cheatsheet: " "App -> Tx MAC -> /--> Tx PCS --o--> /--> Tx PMA --o--> Link\n"); + printf("(A) \"PCS reverse loopback\" " " ^ | ^ | \n"); + printf("(B) \"PCS local loopback\" " " (A) (B) (C) (D) \n"); + printf("(C) \"PMA remote loopback\" " " | v | v \n"); + printf("(D) \"PMA local loopback\" " "App <- Rx MAC <--o--- Rx PCS <-/ <--o--- Rx PMA <-/ <- Link\n"); + } } int main(int argc, char *argv[]) From cba0558db188075726cdec05616bf32415f19db8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 5 Apr 2024 11:01:35 +0200 Subject: [PATCH 082/518] bump version to 6.22.1 --- Changelog | 5 +++++ VERSION | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 3548850d..02f8f1bc 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +* Fri Apr 5 2024 Martin Spinler - 6.22.1-1 +- [BUGFIX] enable coexistence PMCI and SDM (read temperature on N6010) +- [BUGFIX] check whole path string in libnfb for short path feature +- [BUGFIX] throw error in nfb-eth if the repeater can't be configured + * Thu Apr 4 2024 Martin Spinler - 6.22.0-1 - [FEATURE] convert nfb-xvc to pure userspace with libpci - [FEATURE] print sum of counters in nfb-dma diff --git a/VERSION b/VERSION index fe675047..261151bf 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.22.0 +6.22.1 From 10283e924a78891d2f3dcd4458e9ff76931b03d8 Mon Sep 17 00:00:00 2001 From: Richard Hyros Date: Fri, 5 Apr 2024 12:40:55 +0200 Subject: [PATCH 083/518] drivers - net: [FIX] net multiple devices don't try to open same queues --- drivers/kernel/drivers/nfb/net/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/net/device.c b/drivers/kernel/drivers/nfb/net/device.c index 5624f2d4..462d8a31 100644 --- a/drivers/kernel/drivers/nfb/net/device.c +++ b/drivers/kernel/drivers/nfb/net/device.c @@ -537,7 +537,7 @@ static int nfb_net_transmission_on(struct net_device *netdev) netq->numa = dev_to_node(channel->ring.dev); #endif - netq->ndpq = queue = ndp_open_queue(ndp->nfb, channel->id.index, channel->id.type, 0); + netq->ndpq = queue = ndp_open_queue(ndp->nfb, channel->id.index + (count + offset) * priv->index, channel->id.type, 0); if (queue == NULL) { printk(KERN_ERR "%s: %s - failed to init queue %s (error: %d)\n", __func__, netdev->name, dev_name(&channel->dev), ret); From 93471825dff8085760bebb4e006b7e64641ee83f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 8 Apr 2024 12:01:29 +0200 Subject: [PATCH 084/518] drivers: [FIX] some compiler versions doesn't handle const char* well --- drivers/kernel/drivers/nfb/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 7bebaa1f..ca648547 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -62,7 +62,7 @@ const struct nfb_pci_dev nfb_device_infos [] = { [NFB_CARD_TIVOLI] = { "TIVOLI", -1, -1, -1, 0x0B }, - [NFB_CARD_COMBO_GENERIC]= { nfb_card_name_generic, -1, -1, -1, 0x0C }, + [NFB_CARD_COMBO_GENERIC]= { NFB_CARD_NAME_GENERIC, -1, -1, -1, 0x0C }, [NFB_CARD_COMBO400G1] = { "COMBO-400G1", -1, -1, -1, 0x0D }, [NFB_CARD_AGI_FH400G] = { "AGI-FH400G", -1, -1, -1, 0x0E }, From f283270ab686178c4957992ba69e63d66b999c80 Mon Sep 17 00:00:00 2001 From: Richard Hyros Date: Fri, 12 Apr 2024 08:05:26 +0200 Subject: [PATCH 085/518] driver: [FIX] ndp_ctrl_v2_get_vmaps() no longer returns unitilized values when used with net driver --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 16092bf3..ec9d446f 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -133,12 +133,17 @@ static const struct attribute_group *ndp_ctrl_attr_tx_groups[] = { NULL, }; +/// @brief Function sets `hdr` and `off` with information from `channel`. Returns header count. +/// @param channel +/// @param hdr buffer of headers +/// @param off offset into the buffer +/// @return Header count int ndp_ctrl_v2_get_vmaps(struct ndp_channel *channel, void **hdr, void **off) { struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); - *hdr = ctrl->ts.medusa.hdr_buffer; + *hdr = ctrl->hdr_buffer_v; *off = ctrl->off_buffer_v; - return ctrl->c.mhp + 1; + return ctrl->hdr_count; } static void ndp_ctrl_mps_fill_rx_descs(struct ndp_ctrl *ctrl, uint64_t count) From 87ab14f56e102f9ce1bdae5350c3ae7fd8db857e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 12 Apr 2024 10:06:37 +0200 Subject: [PATCH 086/518] drivers - boot: move pci error register handling to boot/reload.c PCI error registers are only accessed on card reboot, so placement in the reload.c file makes better sense. The values are now saved before each card reboot, which reflects runtime system / user changes. --- drivers/kernel/drivers/nfb/boot/reload.c | 28 ++++++++++++++++++++++++ drivers/kernel/drivers/nfb/pci.c | 24 -------------------- drivers/kernel/drivers/nfb/pci.h | 1 - 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index 7f666165..3dac18a3 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -76,6 +76,8 @@ static void nfb_boot_reload_linkup(struct nfb_pci_device *card) static int nfb_boot_reload_rescan(struct nfb_pci_device *card) { + struct pci_dev *bus_dev; + pci_lock_rescan_remove(); pci_rescan_bus(card->bus->parent); pci_unlock_rescan_remove(); @@ -84,10 +86,36 @@ static int nfb_boot_reload_rescan(struct nfb_pci_device *card) if (card->pci == NULL) { return -ENODEV; } + + bus_dev = card->pci->bus->self; + + dev_info(&bus_dev->dev, "restoring errors on PCI bridge\n"); + pci_write_config_word(bus_dev, PCI_COMMAND, card->bridge_command); + pci_write_config_word(bus_dev, bus_dev->pcie_cap + PCI_EXP_DEVCTL, card->bridge_devctl); + pci_dev_put(card->pci); return 0; } +/* + * nfb_pci_errors_disable - disable errors that can occur on hot reboot (firmware reload) + * @card: struct nfb_pci_device instance + */ +static int nfb_pci_errors_disable(struct nfb_pci_device *card) +{ + struct pci_dev *bridge = card->bus->self; + dev_info(&card->bus->self->dev, "disabling errors on PCI bridge\n"); + + /* save state of error registers */ + pci_read_config_word(bridge, PCI_COMMAND, &card->bridge_command); + pci_read_config_word(bridge, bridge->pcie_cap + PCI_EXP_DEVCTL, &card->bridge_devctl); + + pci_write_config_word(bridge, PCI_COMMAND, card->bridge_command & ~PCI_COMMAND_SERR); + pci_write_config_word(bridge, bridge->pcie_cap + PCI_EXP_DEVCTL, + card->bridge_devctl & ~(PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_FERE)); + return 0; +} + int nfb_boot_ioctl_error_disable(struct nfb_boot *nfb_boot) { int ret; diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index ca648547..8793571a 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -645,20 +645,6 @@ static void nfb_pci_tuneup(struct pci_dev *pdev) pci_write_config_word(pdev, exp_cap + PCI_EXP_DEVCTL, devctl); } -/* - * nfb_pci_errors_disable - disable errors that can occur on hot reboot (firmware reload) - * @card: struct nfb_pci_device instance - */ -int nfb_pci_errors_disable(struct nfb_pci_device *card) -{ - struct pci_dev *bridge = card->bus->self; - dev_info(&card->bus->self->dev, "disabling errors on PCI bridge\n"); - pci_write_config_word(bridge, PCI_COMMAND, card->bridge_command & ~PCI_COMMAND_SERR); - pci_write_config_word(bridge, bridge->pcie_cap + PCI_EXP_DEVCTL, - card->bridge_devctl & ~(PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_FERE)); - return 0; -} - /* * nfb_pci_attach_endpoint - Attach PCI device to NFB device * @nfb: NFB device @@ -670,7 +656,6 @@ struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct pc { int device_found = 0; struct nfb_pci_device *pci_device = NULL; - struct pci_dev *bus_dev = pci->bus->self; //mutex_lock(); list_for_each_entry(pci_device, &global_pci_device_list, global_pci_device_list) { @@ -693,15 +678,6 @@ struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct pc pci_device->nfb = NULL; strcpy(pci_device->pci_name, pci_name(pci)); list_add(&pci_device->global_pci_device_list, &global_pci_device_list); - - /* This is a new device, save state of error registers */ - pci_read_config_word(bus_dev, PCI_COMMAND, &pci_device->bridge_command); - pci_read_config_word(bus_dev, bus_dev->pcie_cap + PCI_EXP_DEVCTL, &pci_device->bridge_devctl); - } else { - /* This device is already in list, restore error registers */ - dev_info(&bus_dev->dev, "restoring errors on PCI bridge\n"); - pci_write_config_word(bus_dev, PCI_COMMAND, pci_device->bridge_command); - pci_write_config_word(bus_dev, bus_dev->pcie_cap + PCI_EXP_DEVCTL, pci_device->bridge_devctl); } pci_device->pci = pci; diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 55d7de07..8c827bbe 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -75,7 +75,6 @@ struct nfb_pci_device { uint16_t bridge_devctl; }; -int nfb_pci_errors_disable(struct nfb_pci_device *card); void nfb_pci_detach_endpoint(struct nfb_device *nfb, struct pci_dev *pci); struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct pci_dev *pci, int index); void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus); From 4f3e1725876aea7eb8d64a4c2b33c434d491a813 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 16 Apr 2024 14:01:49 +0200 Subject: [PATCH 087/518] drivers - boot: [HOTFIX] disable nfb_pci_detach_endpoint nfb_pci_detach_endpoint currently doesn't work as it should and even isn't used on proper places. It will be fixed in next commits. --- drivers/kernel/drivers/nfb/boot/reload.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index 3dac18a3..ce9e5fe0 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -136,7 +136,7 @@ int nfb_boot_reload(void *arg) struct nfb_boot *boot; struct nfb_device *nfb; struct list_head slaves; - struct nfb_pci_device *master; + struct nfb_pci_device *master = NULL; struct nfb_pci_device *slave, *temp; struct device *mbus_dev; @@ -153,10 +153,10 @@ int nfb_boot_reload(void *arg) /* Remove PCIe slaves */ list_for_each_entry_safe(slave, temp, &nfb->pci_devices, pci_device_list) { - if (slave->index == 0) + if (slave->index == 0) { + master = slave; continue; - - nfb_pci_detach_endpoint(nfb, slave->pci); + } list_add(&slave->reload_list, &slaves); @@ -166,15 +166,11 @@ int nfb_boot_reload(void *arg) } - master = list_first_entry(&nfb->pci_devices, struct nfb_pci_device, pci_device_list); - /* Prepare master PCIe for removal */ ret = nfb_boot_reload_prepare_remove(master); if (ret) goto err_reload_prepare_remove; - nfb_pci_detach_endpoint(nfb, master->pci); - /* Workaround: Close all MTDs within BootFPGA */ nfb_boot_mtd_destroy(boot); From cbf14fad25ef3708da15000952841edeb6768689 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 23 Apr 2024 07:19:28 +0200 Subject: [PATCH 088/518] drivers - ndp: warn on possible suboptimal allocation of ndp_channel Allocation of the NDP channel can be suboptimal, if the PCI device is not known (not attached to the driver) during NDP submodule attach, as there is no clue to which NUMA node the subsidiary device will be connected. This can occur only for "late" attached sub devices. --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 10 +++++++++- drivers/kernel/drivers/nfb/ndp/ndp.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 16092bf3..34f8c41f 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -1104,7 +1104,7 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i struct ndp_ctrl *ctrl; struct nfb_pci_device *pci_device; - struct device *dev = &ndp->nfb->pci->dev; + struct device *dev = NULL; prop = fdt_getprop(ndp->nfb->fdt, node_offset, "pcie", &proplen); if (proplen >= sizeof(*prop)) { @@ -1118,6 +1118,14 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i } } + if (dev == NULL) { + dev = &ndp->nfb->pci->dev; + if (!ndp->dev_node_warn) { + dev_warn(ndp->nfb->dev, "can't find exact pci_device for NDP queue, this can affect performance on NUMA systems\n"); + ndp->dev_node_warn = 1; + } + } + ctrl = kzalloc_node(sizeof(*ctrl), GFP_KERNEL, dev_to_node(dev)); if (ctrl == NULL) { ret = -ENOMEM; diff --git a/drivers/kernel/drivers/nfb/ndp/ndp.h b/drivers/kernel/drivers/nfb/ndp/ndp.h index 6be4fe18..c94216eb 100644 --- a/drivers/kernel/drivers/nfb/ndp/ndp.h +++ b/drivers/kernel/drivers/nfb/ndp/ndp.h @@ -177,6 +177,8 @@ struct ndp { struct mutex lock; struct device dev; + + int dev_node_warn : 1; }; /* driver.c */ From c5e671455a53c9aa9124350fef8fded54e5718d8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 12 Apr 2024 10:45:50 +0200 Subject: [PATCH 089/518] drivers - pci: extract nfb_pci_is_attachable --- drivers/kernel/drivers/nfb/pci.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 8793571a..24de641a 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -645,6 +645,21 @@ static void nfb_pci_tuneup(struct pci_dev *pdev) pci_write_config_word(pdev, exp_cap + PCI_EXP_DEVCTL, devctl); } +static int nfb_pci_is_attachable(struct nfb_device *nfb, struct pci_dev* pci) +{ + if (nfb == NULL || pci == NULL) + return 0; + + /* Device is the same as main */ + if (nfb->pci == pci) + return 0; + + if (nfb->pci->vendor != pci->vendor) + return 0; + + return 1; +} + /* * nfb_pci_attach_endpoint - Attach PCI device to NFB device * @nfb: NFB device @@ -728,7 +743,8 @@ void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus) } list_for_each_entry(slave, &bus->devices, bus_list) { - if (slave->vendor != nfb->pci->vendor || slave == nfb->pci) + /* prevent device create for unintended devices */ + if (!nfb_pci_is_attachable(nfb, slave)) continue; slave_dsn = nfb_pci_read_dsn(slave); if (nfb->dsn == slave_dsn) { From fc12ab7277696937aa45d22b99dda7106396b0b6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 12 Apr 2024 10:58:28 +0200 Subject: [PATCH 090/518] drivers - pci: limit subsidiary devices only to specific device IDs Only specific cards can hold more subsidiary devices. Moreover such main device can only attach the sub devices with specific Device ID. This behaviour is safer in case of the DSN collision between various cards. --- drivers/kernel/drivers/nfb/pci.c | 26 ++++++++++++++------------ drivers/kernel/drivers/nfb/pci.h | 2 ++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 24de641a..e997466b 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -48,13 +48,13 @@ const struct nfb_pci_dev nfb_device_infos [] = { [NFB_CARD_NFB40G2] = { "NFB-40G2", 0, 0x00000004, 0x00000000, 0x01 }, [NFB_CARD_NFB40G2_SG3] = { "NFB-40G2_SG3", 0, 0x00000004, 0x00000000, 0x03 }, - [NFB_CARD_NFB100G] = { "NFB-100G", 0, 0x00000004, -1, 0x02 }, + [NFB_CARD_NFB100G] = { "NFB-100G", 0, 0x00000004, -1, 0x02, 0xc1c0 }, - [NFB_CARD_NFB100G2] = { "NFB-100G2", 0, 0x01fc0004, 0x01fc0000, 0x00 }, - [NFB_CARD_NFB100G2Q] = { "NFB-100G2Q", 0, 0x01fc0004, 0x01fc0000, 0x05 }, - [NFB_CARD_NFB100G2C] = { "NFB-100G2C", 0, 0x01fc0004, 0x01fc0000, 0x08 }, + [NFB_CARD_NFB100G2] = { "NFB-100G2", 0, 0x01fc0004, 0x01fc0000, 0x00, 0xc2c0 }, + [NFB_CARD_NFB100G2Q] = { "NFB-100G2Q", 0, 0x01fc0004, 0x01fc0000, 0x05, 0xc2c0 }, + [NFB_CARD_NFB100G2C] = { "NFB-100G2C", 0, 0x01fc0004, 0x01fc0000, 0x08, 0xc2c0 }, - [NFB_CARD_NFB200G2QL] = { "NFB-200G2QL", 0, 0x03fc0004, -1, 0x06 }, + [NFB_CARD_NFB200G2QL] = { "NFB-200G2QL", 0, 0x03fc0004, -1, 0x06, 0xc251 }, [NFB_CARD_FB1CGG] = { "FB1CGG", 0, 0x00000002, 0x00000001, 0x07 }, [NFB_CARD_FB2CGG3] = { "FB2CGG3", 0, 0x00000002, 0x00000001, 0x09 }, @@ -62,8 +62,8 @@ const struct nfb_pci_dev nfb_device_infos [] = { [NFB_CARD_TIVOLI] = { "TIVOLI", -1, -1, -1, 0x0B }, - [NFB_CARD_COMBO_GENERIC]= { NFB_CARD_NAME_GENERIC, -1, -1, -1, 0x0C }, - [NFB_CARD_COMBO400G1] = { "COMBO-400G1", -1, -1, -1, 0x0D }, + [NFB_CARD_COMBO_GENERIC]= { NFB_CARD_NAME_GENERIC, -1, -1, -1, 0x0C, /* sub_device is forbidden */ }, + [NFB_CARD_COMBO400G1] = { "COMBO-400G1", -1, -1, -1, 0x0D, 0xc400 }, [NFB_CARD_AGI_FH400G] = { "AGI-FH400G", -1, -1, -1, 0x0E }, /* Last item */ { NULL, -1, -1, -1, 0x00 }, @@ -657,6 +657,11 @@ static int nfb_pci_is_attachable(struct nfb_device *nfb, struct pci_dev* pci) if (nfb->pci->vendor != pci->vendor) return 0; + if (nfb->nfb_pci_dev == NULL || + nfb->nfb_pci_dev->sub_device_id == 0 || + nfb->nfb_pci_dev->sub_device_id != pci->device) + return 0; + return 1; } @@ -837,11 +842,8 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) goto err_attach_device; } - /* Do not scan more endpoints for generic cards */ - if (strcmp(nfb->pci_name, nfb_card_name_generic)) { - while ((bus = pci_find_next_bus(bus))) { - nfb_pci_attach_all_slaves(nfb, bus); - } + while ((bus = pci_find_next_bus(bus))) { + nfb_pci_attach_all_slaves(nfb, bus); } /* Initialize interrupts */ diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 8c827bbe..0baecfad 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -39,6 +39,7 @@ enum nfb_devices { * @idstruct_serialno_addr: Address (in the MTD) where card serial number can be found * @idstruct_subtype_addr: Address (in the MTD) where card type can be found * @card_type_id: Card type number + * @sub_device_id: Device ID for subsidiary device * * This structure is associated with PCI ID (through * &struct pci_device_id->driver_data) and embedded in &struct nfb_device to provide @@ -53,6 +54,7 @@ struct nfb_pci_dev { size_t idstruct_serialno_addr; size_t idstruct_subtype_addr; int card_type_id; + unsigned short sub_device_id; }; struct nfb_pci_device { From 782608d12cc03f94c37898cf7d2b09b4b94fbf8a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 12 Apr 2024 10:33:32 +0200 Subject: [PATCH 091/518] drivers - pci: split nfb_pci_probe to nfb_pci_probe_base --- drivers/kernel/drivers/nfb/pci.c | 50 ++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index e997466b..4f2ce823 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -777,20 +777,9 @@ void nfb_pci_detach_all_slaves(struct nfb_device *nfb) } } -/* - * nfb_probe - called when kernel founds new NFB PCI device - * @pci: PCI device - * @id: PCI device identification structure - */ -int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) +static int nfb_pci_probe_base(struct pci_dev *pci) { - int ret = 0; - struct pci_bus *bus = NULL; - struct nfb_device *nfb; - struct nfb_pci_device *pci_device = NULL; - - void * nfb_dtb_inject = nfb_dtb_inject_get_pci(pci_name(pci)); - + int ret; if (pci_is_root_bus(pci->bus)) { dev_err(&pci->dev, "attaching an nfb card to the root PCI bus is not supported\n"); ret = -EOPNOTSUPP; @@ -815,6 +804,34 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) pci_set_master(pci); nfb_pci_tuneup(pci); + return 0; + +err_pci_set_consistent_dma_mask: +err_pci_set_dma_mask: + pci_disable_device(pci); +err_pci_enable_device: +err_root_pci_bus: + return ret; +} + +/* + * nfb_probe - called when kernel founds new NFB PCI device + * @pci: PCI device + * @id: PCI device identification structure + */ +int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) +{ + int ret = 0; + struct pci_bus *bus = NULL; + struct nfb_device *nfb; + struct nfb_pci_device *pci_device = NULL; + void * nfb_dtb_inject; + + ret = nfb_pci_probe_base(pci); + if (ret) + goto err_nfb_pci_probe_base; + + nfb_dtb_inject = nfb_dtb_inject_get_pci(pci_name(pci)); /* Check presence of driver_data parameter */ ret = nfb_pci_read_enpoint_id(pci); @@ -900,12 +917,7 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) err_attach_device: nfb_destroy(nfb); err_nfb_create: - -err_pci_set_consistent_dma_mask: -err_pci_set_dma_mask: - pci_disable_device(pci); -err_pci_enable_device: -err_root_pci_bus: +err_nfb_pci_probe_base: return ret; } From f7b10a0513762c491903832f8f87e8ca1ac91fa3 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 15 Apr 2024 07:32:31 +0200 Subject: [PATCH 092/518] drivers - pci: split nfb_pci_probe to nfb_pci_probe_main --- drivers/kernel/drivers/nfb/pci.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 4f2ce823..1263ed78 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -814,17 +814,16 @@ static int nfb_pci_probe_base(struct pci_dev *pci) return ret; } +static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *id, void * nfb_dtb_inject); + /* * nfb_probe - called when kernel founds new NFB PCI device * @pci: PCI device * @id: PCI device identification structure */ -int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) +static int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) { int ret = 0; - struct pci_bus *bus = NULL; - struct nfb_device *nfb; - struct nfb_pci_device *pci_device = NULL; void * nfb_dtb_inject; ret = nfb_pci_probe_base(pci); @@ -840,6 +839,20 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) return 0; } + ret = nfb_pci_probe_main(pci, id, nfb_dtb_inject); + return ret; + +err_nfb_pci_probe_base: + return ret; +} + +static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *id, void * nfb_dtb_inject) +{ + int ret = 0; + struct pci_bus *bus = NULL; + struct nfb_pci_device *pci_device; + struct nfb_device *nfb; + nfb = nfb_create(); if (IS_ERR(nfb)) { ret = PTR_ERR(nfb); @@ -917,7 +930,6 @@ int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) err_attach_device: nfb_destroy(nfb); err_nfb_create: -err_nfb_pci_probe_base: return ret; } From 3d86809d1c2676bd819ec72bbf243af4ce2ac036 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 15 Apr 2024 07:47:50 +0200 Subject: [PATCH 093/518] drivers - pci: extract _nfb_pci_device_create --- drivers/kernel/drivers/nfb/pci.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 1263ed78..8324899a 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -665,6 +665,26 @@ static int nfb_pci_is_attachable(struct nfb_device *nfb, struct pci_dev* pci) return 1; } +struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) +{ + struct nfb_pci_device *pci_device = NULL; + + pci_device = kzalloc(sizeof(*pci_device), GFP_KERNEL); + if (pci_device == NULL) { + return NULL; + } + + INIT_LIST_HEAD(&pci_device->global_pci_device_list); + INIT_LIST_HEAD(&pci_device->pci_device_list); + INIT_LIST_HEAD(&pci_device->reload_list); + + strcpy(pci_device->pci_name, pci_name(pci)); + + list_add(&pci_device->global_pci_device_list, &global_pci_device_list); + + return pci_device; +} + /* * nfb_pci_attach_endpoint - Attach PCI device to NFB device * @nfb: NFB device @@ -686,18 +706,10 @@ struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct pc } if (!device_found) { - pci_device = kmalloc(sizeof(*pci_device), GFP_KERNEL); + pci_device = _nfb_pci_device_create(pci); if (pci_device == NULL) { return NULL; } - - INIT_LIST_HEAD(&pci_device->global_pci_device_list); - INIT_LIST_HEAD(&pci_device->pci_device_list); - INIT_LIST_HEAD(&pci_device->reload_list); - - pci_device->nfb = NULL; - strcpy(pci_device->pci_name, pci_name(pci)); - list_add(&pci_device->global_pci_device_list, &global_pci_device_list); } pci_device->pci = pci; From 4b7a576961b586d0e39c2b2d3eaba7a1b893e1ad Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 15 Apr 2024 08:11:03 +0200 Subject: [PATCH 094/518] drivers - pci: add nfb_pci_device_find_or_create --- drivers/kernel/drivers/nfb/pci.c | 54 +++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 8324899a..60ce0e6a 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -665,6 +665,19 @@ static int nfb_pci_is_attachable(struct nfb_device *nfb, struct pci_dev* pci) return 1; } +struct nfb_pci_device *_nfb_pci_device_find(struct pci_dev *pci) +{ + struct nfb_pci_device *pci_device = NULL; + + list_for_each_entry(pci_device, &global_pci_device_list, global_pci_device_list) { + if (strcmp(pci_device->pci_name, pci_name(pci)) == 0) { + return pci_device; + } + } + + return NULL; +} + struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) { struct nfb_pci_device *pci_device = NULL; @@ -685,6 +698,26 @@ struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) return pci_device; } +struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) +{ + struct nfb_pci_device * pci_device; + + pci_device = _nfb_pci_device_find(pci); + if (pci_device == NULL) { + pci_device = _nfb_pci_device_create(pci); + if (pci_device == NULL) + goto err_nfb_pci_device_create; + } + + pci_device->pci = pci; + pci_device->bus = pci->bus; + + return pci_device; + +err_nfb_pci_device_create: + return NULL; +} + /* * nfb_pci_attach_endpoint - Attach PCI device to NFB device * @nfb: NFB device @@ -694,32 +727,17 @@ struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) */ struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct pci_dev *pci, int index) { - int device_found = 0; struct nfb_pci_device *pci_device = NULL; - //mutex_lock(); - list_for_each_entry(pci_device, &global_pci_device_list, global_pci_device_list) { - if (strcmp(pci_device->pci_name, pci_name(pci)) == 0) { - device_found = 1; - break; - } - } - - if (!device_found) { - pci_device = _nfb_pci_device_create(pci); - if (pci_device == NULL) { - return NULL; - } - } + pci_device = nfb_pci_device_find_or_create(pci); + if (pci_device == NULL) + return NULL; - pci_device->pci = pci; - pci_device->bus = pci->bus; pci_device->nfb = nfb; pci_device->index = index; list_add(&pci_device->pci_device_list, &nfb->pci_devices); - //mutex_unlock(); return pci_device; } From b0b60fc6b41847a89b7fbe4fab5d68aef02c950c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 15 Apr 2024 08:37:57 +0200 Subject: [PATCH 095/518] drivers - pci: move nfb_pci_device_create outside nfb_pci_attach_endpoint --- drivers/kernel/drivers/nfb/pci.c | 23 ++++++++++++----------- drivers/kernel/drivers/nfb/pci.h | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 60ce0e6a..2a9f0edf 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -725,14 +725,8 @@ struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) * @index: Index of PCI device within one NFB device * return: struct nfb_pci_device instance pointer or NULL */ -struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct pci_dev *pci, int index) +struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct nfb_pci_device *pci_device, int index) { - struct nfb_pci_device *pci_device = NULL; - - pci_device = nfb_pci_device_find_or_create(pci); - if (pci_device == NULL) - return NULL; - pci_device->nfb = nfb; pci_device->index = index; @@ -772,6 +766,7 @@ void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus) uint64_t slave_dsn; struct pci_bus *child_bus; struct pci_dev *slave; + struct nfb_pci_device *pci_device; list_for_each_entry(child_bus, &bus->children, node) { nfb_pci_attach_all_slaves(nfb, child_bus); @@ -781,13 +776,17 @@ void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus) /* prevent device create for unintended devices */ if (!nfb_pci_is_attachable(nfb, slave)) continue; + pci_device = nfb_pci_device_find_or_create(slave); + if (pci_device == NULL) + continue; + slave_dsn = nfb_pci_read_dsn(slave); if (nfb->dsn == slave_dsn) { ret = nfb_pci_read_enpoint_id(slave); if (ret == -1) ret = 1; dev_info(&nfb->pci->dev, "Found PCI slave %d device with name %s by DSN\n", ret, pci_name(slave)); - nfb_pci_attach_endpoint(nfb, slave, ret); + nfb_pci_attach_endpoint(nfb, pci_device, ret); } } } @@ -896,12 +895,14 @@ static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *i nfb->dsn = nfb_pci_read_dsn(pci); - pci_device = nfb_pci_attach_endpoint(nfb, pci, 0); + pci_device = nfb_pci_device_find_or_create(pci); if (pci_device == NULL) { ret = -1; - goto err_attach_device; + goto err_nfb_pci_device_find_or_create; } + nfb_pci_attach_endpoint(nfb, pci_device, 0); + while ((bus = pci_find_next_bus(bus))) { nfb_pci_attach_all_slaves(nfb, bus); } @@ -957,7 +958,7 @@ static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *i free_irq(pci->irq, nfb); pci_disable_msi(pci); //err_pci_enable_msi: -err_attach_device: +err_nfb_pci_device_find_or_create: nfb_destroy(nfb); err_nfb_create: return ret; diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 0baecfad..54d5354a 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -78,7 +78,7 @@ struct nfb_pci_device { }; void nfb_pci_detach_endpoint(struct nfb_device *nfb, struct pci_dev *pci); -struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct pci_dev *pci, int index); +struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct nfb_pci_device *pci_device, int index); void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus); void nfb_pci_detach_all_slaves(struct nfb_device *nfb); From 65995a7e07d43fb513e202d9131370f1da1e2c37 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 15 Apr 2024 09:51:41 +0200 Subject: [PATCH 096/518] drivers - pci: change pci_drvdata from nfb_device to nfb_pci_device --- drivers/kernel/drivers/nfb/pci.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 2a9f0edf..d9e675d1 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -940,7 +940,7 @@ static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *i nfb_fdt_fixups(nfb); - pci_set_drvdata(pci, nfb); + pci_set_drvdata(pci, pci_device); /* Publish NFB object */ ret = nfb_probe(nfb); @@ -970,10 +970,14 @@ static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *i */ void nfb_pci_remove(struct pci_dev *pci) { - struct nfb_device *nfb = (struct nfb_device *) pci_get_drvdata(pci); - if (nfb == NULL) + struct nfb_pci_device *pci_device = (struct nfb_pci_device *) pci_get_drvdata(pci); + struct nfb_device *nfb; + + if (pci_device == NULL) goto disable_device; + nfb = pci_device->nfb; + /* At first detach all drivers */ nfb_remove(nfb); kfree(nfb->fdt); @@ -991,10 +995,16 @@ void nfb_pci_remove(struct pci_dev *pci) static int nfb_pci_sriov_configure(struct pci_dev *dev, int numvfs) { - struct nfb_device *nfb = (struct nfb_device *) pci_get_drvdata(dev); + struct nfb_pci_device *pci_device = (struct nfb_pci_device *) pci_get_drvdata(dev); + struct nfb_device *nfb; int i; int ret = 0; + if (pci_device == NULL) + return -ENODEV; + + nfb = pci_device->nfb; + if (numvfs == 0) { pci_disable_sriov(dev); } else { From 73b4c39ee5068e1bd9f261ef374b615dbbb543b6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 15 Apr 2024 12:19:02 +0200 Subject: [PATCH 097/518] drivers - pci: add and use nfb_pci_device->attach_lock in main dev probe --- drivers/kernel/drivers/nfb/pci.c | 9 +++++++++ drivers/kernel/drivers/nfb/pci.h | 1 + 2 files changed, 10 insertions(+) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index d9e675d1..c922bd52 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -690,6 +690,7 @@ struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) INIT_LIST_HEAD(&pci_device->global_pci_device_list); INIT_LIST_HEAD(&pci_device->pci_device_list); INIT_LIST_HEAD(&pci_device->reload_list); + mutex_init(&pci_device->attach_lock); strcpy(pci_device->pci_name, pci_name(pci)); @@ -709,6 +710,8 @@ struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) goto err_nfb_pci_device_create; } + mutex_lock(&pci_device->attach_lock); + pci_device->pci = pci; pci_device->bus = pci->bus; @@ -788,6 +791,7 @@ void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus) dev_info(&nfb->pci->dev, "Found PCI slave %d device with name %s by DSN\n", ret, pci_name(slave)); nfb_pci_attach_endpoint(nfb, pci_device, ret); } + mutex_unlock(&pci_device->attach_lock); } } @@ -948,6 +952,8 @@ static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *i goto err_nfb_probe; } + mutex_unlock(&pci_device->attach_lock); + dev_info(&pci->dev, "successfully initialized\n"); return 0; @@ -957,6 +963,9 @@ static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *i err_nfb_read_fdt: free_irq(pci->irq, nfb); pci_disable_msi(pci); + + mutex_unlock(&pci_device->attach_lock); + //err_pci_enable_msi: err_nfb_pci_device_find_or_create: nfb_destroy(nfb); diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 54d5354a..9238f489 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -61,6 +61,7 @@ struct nfb_pci_device { struct list_head global_pci_device_list; struct list_head pci_device_list; struct list_head reload_list; + struct mutex attach_lock; struct pci_dev *pci; struct nfb_device *nfb; From 61c87dc1ac2aa3a3dd20b24c80b6842385c416a0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 16 Apr 2024 07:13:31 +0200 Subject: [PATCH 098/518] drivers - pci: add and use global_pci_device_list_lock --- drivers/kernel/drivers/nfb/pci.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index c922bd52..aaaebd92 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -35,6 +35,7 @@ static bool fallback_fdt = 1; static bool fallback_fdt_boot = 0; static bool flash_recovery_ro = 1; +struct mutex global_pci_device_list_lock; struct list_head global_pci_device_list; extern struct nfb_driver_ops nfb_registered_drivers[NFB_DRIVERS_MAX]; @@ -703,6 +704,8 @@ struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) { struct nfb_pci_device * pci_device; + mutex_lock(&global_pci_device_list_lock); + pci_device = _nfb_pci_device_find(pci); if (pci_device == NULL) { pci_device = _nfb_pci_device_create(pci); @@ -712,12 +715,15 @@ struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) mutex_lock(&pci_device->attach_lock); + mutex_unlock(&global_pci_device_list_lock); + pci_device->pci = pci; pci_device->bus = pci->bus; return pci_device; err_nfb_pci_device_create: + mutex_unlock(&global_pci_device_list_lock); return NULL; } @@ -1048,6 +1054,8 @@ int nfb_pci_init(void) { int ret; INIT_LIST_HEAD(&global_pci_device_list); + mutex_init(&global_pci_device_list_lock); + ret = pci_register_driver(&nfb_driver); if (ret) goto err_register; From 6e07e77a91970369e26c6d7f628c0ea241205d1a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 17 Apr 2024 15:08:18 +0200 Subject: [PATCH 099/518] drivers - pci: assign pci_device as drvdata for sub devices as well --- drivers/kernel/drivers/nfb/boot/reload.c | 2 +- drivers/kernel/drivers/nfb/pci.c | 82 ++++++++++++++---------- drivers/kernel/drivers/nfb/pci.h | 1 + 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index ce9e5fe0..54808f9b 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -153,7 +153,7 @@ int nfb_boot_reload(void *arg) /* Remove PCIe slaves */ list_for_each_entry_safe(slave, temp, &nfb->pci_devices, pci_device_list) { - if (slave->index == 0) { + if (slave->is_probed_as_main) { master = slave; continue; } diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index aaaebd92..ef43dc08 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -810,7 +810,7 @@ void nfb_pci_detach_all_slaves(struct nfb_device *nfb) struct nfb_pci_device *pci_device, *temp; list_for_each_entry_safe(pci_device, temp, &nfb->pci_devices, pci_device_list) { - if (pci_device->index > 0) { + if (!pci_device->is_probed_as_main) { nfb_pci_detach_endpoint(nfb, pci_device->pci); } } @@ -853,7 +853,7 @@ static int nfb_pci_probe_base(struct pci_dev *pci) return ret; } -static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *id, void * nfb_dtb_inject); +static int nfb_pci_probe_main(struct nfb_pci_device *pci_device, const struct pci_device_id *id, void * nfb_dtb_inject); /* * nfb_probe - called when kernel founds new NFB PCI device @@ -864,32 +864,57 @@ static int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) { int ret = 0; void * nfb_dtb_inject; + struct nfb_pci_device *pci_device; ret = nfb_pci_probe_base(pci); if (ret) goto err_nfb_pci_probe_base; + pci_device = nfb_pci_device_find_or_create(pci); + if (pci_device == NULL) { + ret = -ENOMEM; + goto err_nfb_pci_device_find_or_create; + } + + pci_set_drvdata(pci, pci_device); + nfb_dtb_inject = nfb_dtb_inject_get_pci(pci_name(pci)); /* Check presence of driver_data parameter */ ret = nfb_pci_read_enpoint_id(pci); if (((struct nfb_pci_dev*) id->driver_data == NULL || ret > 0) && nfb_dtb_inject == NULL) { dev_info(&pci->dev, "successfully initialized only for DMA transfers\n"); - return 0; + } else { + pci_device->is_probed_as_main = 1; + + ret = nfb_pci_probe_main(pci_device, id, nfb_dtb_inject); + if (ret) + goto err_nfb_pci_probe_main; } - ret = nfb_pci_probe_main(pci, id, nfb_dtb_inject); - return ret; + mutex_unlock(&pci_device->attach_lock); + return 0; + +//err_nfb_pci_probe_sub: +// goto err_nfb_pci_probe; + +err_nfb_pci_probe_main: + pci_device->is_probed_as_main = 0; + goto err_nfb_pci_probe; +err_nfb_pci_probe: + mutex_unlock(&pci_device->attach_lock); + +err_nfb_pci_device_find_or_create: err_nfb_pci_probe_base: return ret; } -static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *id, void * nfb_dtb_inject) +static int nfb_pci_probe_main(struct nfb_pci_device *pci_device, const struct pci_device_id *id, void * nfb_dtb_inject) { int ret = 0; + struct pci_dev *pci = pci_device->pci; struct pci_bus *bus = NULL; - struct nfb_pci_device *pci_device; struct nfb_device *nfb; nfb = nfb_create(); @@ -905,12 +930,6 @@ static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *i nfb->dsn = nfb_pci_read_dsn(pci); - pci_device = nfb_pci_device_find_or_create(pci); - if (pci_device == NULL) { - ret = -1; - goto err_nfb_pci_device_find_or_create; - } - nfb_pci_attach_endpoint(nfb, pci_device, 0); while ((bus = pci_find_next_bus(bus))) { @@ -950,16 +969,12 @@ static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *i nfb_fdt_fixups(nfb); - pci_set_drvdata(pci, pci_device); - /* Publish NFB object */ ret = nfb_probe(nfb); if (ret) { goto err_nfb_probe; } - mutex_unlock(&pci_device->attach_lock); - dev_info(&pci->dev, "successfully initialized\n"); return 0; @@ -970,10 +985,7 @@ static int nfb_pci_probe_main(struct pci_dev *pci, const struct pci_device_id *i free_irq(pci->irq, nfb); pci_disable_msi(pci); - mutex_unlock(&pci_device->attach_lock); - //err_pci_enable_msi: -err_nfb_pci_device_find_or_create: nfb_destroy(nfb); err_nfb_create: return ret; @@ -988,22 +1000,26 @@ void nfb_pci_remove(struct pci_dev *pci) struct nfb_pci_device *pci_device = (struct nfb_pci_device *) pci_get_drvdata(pci); struct nfb_device *nfb; - if (pci_device == NULL) - goto disable_device; - nfb = pci_device->nfb; - /* At first detach all drivers */ - nfb_remove(nfb); - kfree(nfb->fdt); + mutex_lock(&pci_device->attach_lock); - /* Free all mappings */ - if (pci->irq != -1) - free_irq(pci->irq, nfb); - pci_disable_msi(pci); - nfb_destroy(nfb); + if (pci_device->is_probed_as_main) { + pci_device->is_probed_as_main = 0; + + /* At first detach all drivers */ + nfb_remove(nfb); + kfree(nfb->fdt); + + /* Free all mappings */ + if (pci->irq != -1) + free_irq(pci->irq, nfb); + pci_disable_msi(pci); + nfb_destroy(nfb); + } + + mutex_unlock(&pci_device->attach_lock); -disable_device: pci_disable_device(pci); dev_info(&pci->dev, "disabled\n"); } @@ -1015,7 +1031,7 @@ static int nfb_pci_sriov_configure(struct pci_dev *dev, int numvfs) int i; int ret = 0; - if (pci_device == NULL) + if (!pci_device->is_probed_as_main) return -ENODEV; nfb = pci_device->nfb; diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 9238f489..12967878 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -68,6 +68,7 @@ struct nfb_pci_device { struct pci_bus *bus; int index; /* 0: master, > 0: slaves */ + int is_probed_as_main: 1; int devfn; int cap; From 7fba1deecbfc63338a84474b25d35a260904b3ea Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 16 Apr 2024 08:15:51 +0200 Subject: [PATCH 100/518] drivers - pci: read DSN and endpoint_id in pci_device_create Read the endpoint identification on its discovery. Also invalidate the identification on PCI remove, as it could hypothetically change afterwards. --- drivers/kernel/drivers/nfb/pci.c | 39 +++++++++++++++++++++----------- drivers/kernel/drivers/nfb/pci.h | 4 +++- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index ef43dc08..456e106e 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -666,6 +666,18 @@ static int nfb_pci_is_attachable(struct nfb_device *nfb, struct pci_dev* pci) return 1; } +static int nfb_pci_device_is_attachable(struct nfb_device *nfb, struct nfb_pci_device *sub) +{ + if (nfb == NULL || sub == NULL) + return 0; + + + if (nfb->dsn == 0 || nfb->dsn != sub->dsn) + return 0; + + return 1; +} + struct nfb_pci_device *_nfb_pci_device_find(struct pci_dev *pci) { struct nfb_pci_device *pci_device = NULL; @@ -720,6 +732,12 @@ struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) pci_device->pci = pci; pci_device->bus = pci->bus; + if (!pci_device->index_valid) { + pci_device->dsn = nfb_pci_read_dsn(pci); + pci_device->index = nfb_pci_read_enpoint_id(pci); + pci_device->index_valid = 1; + } + return pci_device; err_nfb_pci_device_create: @@ -737,7 +755,6 @@ struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct nfb_pci_device *pci_device, int index) { pci_device->nfb = nfb; - pci_device->index = index; list_add(&pci_device->pci_device_list, &nfb->pci_devices); @@ -771,8 +788,6 @@ void nfb_pci_detach_endpoint(struct nfb_device *nfb, struct pci_dev *pci) */ void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus) { - int ret; - uint64_t slave_dsn; struct pci_bus *child_bus; struct pci_dev *slave; struct nfb_pci_device *pci_device; @@ -789,13 +804,9 @@ void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus) if (pci_device == NULL) continue; - slave_dsn = nfb_pci_read_dsn(slave); - if (nfb->dsn == slave_dsn) { - ret = nfb_pci_read_enpoint_id(slave); - if (ret == -1) - ret = 1; - dev_info(&nfb->pci->dev, "Found PCI slave %d device with name %s by DSN\n", ret, pci_name(slave)); - nfb_pci_attach_endpoint(nfb, pci_device, ret); + if (nfb_pci_device_is_attachable(nfb, pci_device)) { + dev_info(&nfb->pci->dev, "Found PCI sub device %d with name %s by DSN\n", pci_device->index, pci_name(slave)); + nfb_pci_attach_endpoint(nfb, pci_device, pci_device->index); } mutex_unlock(&pci_device->attach_lock); } @@ -881,8 +892,7 @@ static int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) nfb_dtb_inject = nfb_dtb_inject_get_pci(pci_name(pci)); /* Check presence of driver_data parameter */ - ret = nfb_pci_read_enpoint_id(pci); - if (((struct nfb_pci_dev*) id->driver_data == NULL || ret > 0) && nfb_dtb_inject == NULL) { + if (((struct nfb_pci_dev*) id->driver_data == NULL || pci_device->index > 0) && nfb_dtb_inject == NULL) { dev_info(&pci->dev, "successfully initialized only for DMA transfers\n"); } else { pci_device->is_probed_as_main = 1; @@ -903,6 +913,7 @@ static int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) goto err_nfb_pci_probe; err_nfb_pci_probe: + pci_device->index_valid = 0; mutex_unlock(&pci_device->attach_lock); err_nfb_pci_device_find_or_create: @@ -928,7 +939,7 @@ static int nfb_pci_probe_main(struct nfb_pci_device *pci_device, const struct pc if (nfb->nfb_pci_dev) nfb->pci_name = nfb->nfb_pci_dev->name; - nfb->dsn = nfb_pci_read_dsn(pci); + nfb->dsn = pci_device->dsn; nfb_pci_attach_endpoint(nfb, pci_device, 0); @@ -1018,6 +1029,8 @@ void nfb_pci_remove(struct pci_dev *pci) nfb_destroy(nfb); } + pci_device->index_valid = 0; + mutex_unlock(&pci_device->attach_lock); pci_disable_device(pci); diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 12967878..923fd86b 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -67,7 +67,9 @@ struct nfb_pci_device { struct nfb_device *nfb; struct pci_bus *bus; - int index; /* 0: master, > 0: slaves */ + uint64_t dsn; + int index; /* 0: main device, > 0: subsidiary devices */ + int index_valid: 1; /* index (and dsn) is valid: freshly readen */ int is_probed_as_main: 1; int devfn; From 70d68737cd42db1749fed1df6e1a58fb0485ce92 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 16 Apr 2024 10:44:36 +0200 Subject: [PATCH 101/518] drivers - pci: allow early removal of pcie endpoint The subsidiary device can now be manually removed correctly by the user. --- drivers/kernel/drivers/nfb/pci.c | 20 ++++++++++++++++---- drivers/kernel/drivers/nfb/pci.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 456e106e..210b5121 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -816,14 +816,18 @@ void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus) * nfb_pci_detach_all_slaves - Detach all slave endpoints from NFB device * @nfb: NFB device */ -void nfb_pci_detach_all_slaves(struct nfb_device *nfb) +void nfb_pci_detach_endpoints(struct nfb_device *nfb, struct nfb_pci_device *self) { struct nfb_pci_device *pci_device, *temp; list_for_each_entry_safe(pci_device, temp, &nfb->pci_devices, pci_device_list) { - if (!pci_device->is_probed_as_main) { - nfb_pci_detach_endpoint(nfb, pci_device->pci); - } + if (pci_device != self) + mutex_lock(&pci_device->attach_lock); + + nfb_pci_detach_endpoint(nfb, pci_device->pci); + + if (pci_device != self) + mutex_unlock(&pci_device->attach_lock); } } @@ -893,6 +897,7 @@ static int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) /* Check presence of driver_data parameter */ if (((struct nfb_pci_dev*) id->driver_data == NULL || pci_device->index > 0) && nfb_dtb_inject == NULL) { + pci_device->is_probed_as_sub = 1; dev_info(&pci->dev, "successfully initialized only for DMA transfers\n"); } else { pci_device->is_probed_as_main = 1; @@ -1026,7 +1031,14 @@ void nfb_pci_remove(struct pci_dev *pci) if (pci->irq != -1) free_irq(pci->irq, nfb); pci_disable_msi(pci); + nfb_pci_detach_endpoints(nfb, pci_device); + nfb_destroy(nfb); + } else if (pci_device->is_probed_as_sub) { + if (nfb) { + nfb_pci_detach_endpoint(nfb, pci_device->pci); + } + pci_device->is_probed_as_sub = 0; } pci_device->index_valid = 0; diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 923fd86b..a372e3b4 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -71,6 +71,7 @@ struct nfb_pci_device { int index; /* 0: main device, > 0: subsidiary devices */ int index_valid: 1; /* index (and dsn) is valid: freshly readen */ int is_probed_as_main: 1; + int is_probed_as_sub: 1; int devfn; int cap; From d6d7e47939c2a57a9d6565d4c69132b9aea1d5c0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 16 Apr 2024 10:45:46 +0200 Subject: [PATCH 102/518] drivers - pci: allow late attaching of pcie endpoint The subsidiary device can now be manually added correctly by the user. Original mechanism does attach the devices before nfb_probe. If the sub devices doesn't exists in this stage yet for some reason, they will stay unusable (e.g. BAR isn't mapped to MI). Late attaching allows to overcome this issue, it is done by the sub devices: the sub device tries to find its main device and attach to it. Due to possible probe concurrency and locks, it is necessary to rescan subdevices after main device probe too. Original mechanism remains unchanged, as the subdrivers can't handle late attached devices yet. --- drivers/kernel/drivers/nfb/pci.c | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 210b5121..144aa282 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -36,6 +36,7 @@ static bool fallback_fdt_boot = 0; static bool flash_recovery_ro = 1; struct mutex global_pci_device_list_lock; +struct mutex global_try_attach_lock; struct list_head global_pci_device_list; extern struct nfb_driver_ops nfb_registered_drivers[NFB_DRIVERS_MAX]; @@ -671,6 +672,8 @@ static int nfb_pci_device_is_attachable(struct nfb_device *nfb, struct nfb_pci_d if (nfb == NULL || sub == NULL) return 0; + if (sub->nfb) + return 0; if (nfb->dsn == 0 || nfb->dsn != sub->dsn) return 0; @@ -831,6 +834,45 @@ void nfb_pci_detach_endpoints(struct nfb_device *nfb, struct nfb_pci_device *sel } } +void nfb_pci_try_attach(struct nfb_pci_device *self) +{ + struct nfb_device * nfb; + struct nfb_pci_device *pci_device; + mutex_lock(&global_try_attach_lock); + mutex_lock(&global_pci_device_list_lock); + mutex_lock(&self->attach_lock); + + if (self->is_probed_as_main) { + nfb = self->nfb; + list_for_each_entry(pci_device, &global_pci_device_list, global_pci_device_list) { + if (mutex_trylock(&pci_device->attach_lock)) { + if (pci_device->is_probed_as_sub && + nfb_pci_is_attachable(nfb, pci_device->pci) && + nfb_pci_device_is_attachable(nfb, pci_device)) { + nfb_pci_attach_endpoint(nfb, pci_device, pci_device->index); + } + mutex_unlock(&pci_device->attach_lock); + } + } + } else if (self->is_probed_as_sub) { + list_for_each_entry(pci_device, &global_pci_device_list, global_pci_device_list) { + if (mutex_trylock(&pci_device->attach_lock)) { + nfb = pci_device->nfb; + if (pci_device->is_probed_as_main && + nfb_pci_is_attachable(nfb, self->pci) && + nfb_pci_device_is_attachable(nfb, self)) { + nfb_pci_attach_endpoint(nfb, self, self->index); + } + mutex_unlock(&pci_device->attach_lock); + } + } + } + + mutex_unlock(&self->attach_lock); + mutex_unlock(&global_pci_device_list_lock); + mutex_unlock(&global_try_attach_lock); +} + static int nfb_pci_probe_base(struct pci_dev *pci) { int ret; @@ -908,6 +950,8 @@ static int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) } mutex_unlock(&pci_device->attach_lock); + + nfb_pci_try_attach(pci_device); return 0; //err_nfb_pci_probe_sub: @@ -1096,6 +1140,7 @@ int nfb_pci_init(void) int ret; INIT_LIST_HEAD(&global_pci_device_list); mutex_init(&global_pci_device_list_lock); + mutex_init(&global_try_attach_lock); ret = pci_register_driver(&nfb_driver); if (ret) From 20d4fd79136b0e47366717c09e7ed94382803be8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 16 Apr 2024 10:52:32 +0200 Subject: [PATCH 103/518] drivers - core: introduce probe_endpoint/remove_endpoint ops The probe_endpoint/remove_endpoint callbacks are used to inform subdrivers of late/early probed/removed devices. --- drivers/kernel/drivers/nfb/core.c | 26 ++++++++++++++++++++++++++ drivers/kernel/drivers/nfb/nfb.h | 7 +++++++ drivers/kernel/drivers/nfb/pci.c | 3 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/kernel/drivers/nfb/core.c b/drivers/kernel/drivers/nfb/core.c index cc112598..9e0fca69 100644 --- a/drivers/kernel/drivers/nfb/core.c +++ b/drivers/kernel/drivers/nfb/core.c @@ -104,6 +104,32 @@ void nfb_detach_drivers(struct nfb_device* nfb) mutex_unlock(&nfb_driver_register_mutex); } +void nfb_probe_endpoint_late(struct nfb_device *nfb, struct nfb_pci_device *pci_device) +{ + int i; + mutex_lock(&nfb_driver_register_mutex); + + for (i = 0; i < NFB_DRIVERS_MAX; i++) { + if (nfb->list_drivers[i].status == NFB_DRIVER_STATUS_OK && nfb_registered_drivers[i].remove_endpoint) { + nfb_registered_drivers[i].probe_endpoint(nfb->list_drivers[i].priv, pci_device); + } + } + + mutex_unlock(&nfb_driver_register_mutex); +} + +void nfb_remove_endpoint_early(struct nfb_device *nfb, struct nfb_pci_device *pci_device) +{ + int i; + mutex_lock(&nfb_driver_register_mutex); + for (i = NFB_DRIVERS_MAX - 1; i >= 0; i--) { + if (nfb->list_drivers[i].status == NFB_DRIVER_STATUS_OK && nfb_registered_drivers[i].remove_endpoint) { + nfb_registered_drivers[i].remove_endpoint(nfb->list_drivers[i].priv, pci_device); + } + } + mutex_unlock(&nfb_driver_register_mutex); +} + /* * nfb_create - alloc and init NFB structure * return: NFB device structure diff --git a/drivers/kernel/drivers/nfb/nfb.h b/drivers/kernel/drivers/nfb/nfb.h index 25de4c71..94e86ddf 100644 --- a/drivers/kernel/drivers/nfb/nfb.h +++ b/drivers/kernel/drivers/nfb/nfb.h @@ -44,6 +44,10 @@ struct nfb_driver_ops { void (*release)(void *priv, void *app_priv, struct file *file); long (*ioctl)(void *priv, void *app_priv, struct file *file, unsigned int cmd, unsigned long arg); void (*numvfs_change)(void *priv, int numvfs); + /* probe_endpoint is called only for subsidiary devices probed after main device probing */ + void (*probe_endpoint)(void *priv, struct nfb_pci_device *pci_device); + /* remove_endpoint is called only for subsidiary devices removed before the main device removal */ + void (*remove_endpoint)(void *priv, struct nfb_pci_device *pci_device); unsigned int ioc_type; }; @@ -144,6 +148,9 @@ void nfb_nfree(int numa_node, void *ptr, size_t size); void *nfb_get_priv_for_attach_fn(struct nfb_device *nfb, nfb_driver_ops_attach_t attach); +void nfb_probe_endpoint_late(struct nfb_device *nfb, struct nfb_pci_device *pci_device); +void nfb_remove_endpoint_early(struct nfb_device *nfb, struct nfb_pci_device *pci_device); + void nfb_bus_register(struct nfb_device *nfb, struct nfb_bus *bus); void nfb_bus_unregister(struct nfb_device *nfb, struct nfb_bus *bus); diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 144aa282..85b977ae 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -850,6 +850,7 @@ void nfb_pci_try_attach(struct nfb_pci_device *self) nfb_pci_is_attachable(nfb, pci_device->pci) && nfb_pci_device_is_attachable(nfb, pci_device)) { nfb_pci_attach_endpoint(nfb, pci_device, pci_device->index); + nfb_probe_endpoint_late(nfb, pci_device); } mutex_unlock(&pci_device->attach_lock); } @@ -862,6 +863,7 @@ void nfb_pci_try_attach(struct nfb_pci_device *self) nfb_pci_is_attachable(nfb, self->pci) && nfb_pci_device_is_attachable(nfb, self)) { nfb_pci_attach_endpoint(nfb, self, self->index); + nfb_probe_endpoint_late(nfb, self); } mutex_unlock(&pci_device->attach_lock); } @@ -1080,6 +1082,7 @@ void nfb_pci_remove(struct pci_dev *pci) nfb_destroy(nfb); } else if (pci_device->is_probed_as_sub) { if (nfb) { + nfb_remove_endpoint_early(nfb, pci_device); nfb_pci_detach_endpoint(nfb, pci_device->pci); } pci_device->is_probed_as_sub = 0; From fee07f59f9fd90be45c26c592a464101b2759bf6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 16 Apr 2024 15:00:04 +0200 Subject: [PATCH 104/518] drivers - mi: remove compatibility branch --- drivers/kernel/drivers/nfb/mi/mi.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/drivers/kernel/drivers/nfb/mi/mi.c b/drivers/kernel/drivers/nfb/mi/mi.c index 7c817e1e..570be0d0 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.c +++ b/drivers/kernel/drivers/nfb/mi/mi.c @@ -168,15 +168,6 @@ int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) snprintf(nodename, sizeof(nodename), "PCI%d,BAR%d", pci_index, bar); -#define NFB_MI_PATH_COMPATIBILITY -#ifdef NFB_MI_PATH_COMPATIBILITY - if (pci_index == 0 && bar == 0) { - node_offset = fdt_path_offset(nfb->fdt, "/drivers/mi"); - fdt_setprop_u64(nfb->fdt, node_offset, "mmap_base", mi_node->mmap_offset); - fdt_setprop_u64(nfb->fdt, node_offset, "mmap_size", mi_node->mem_len); - } -#endif - node_offset = fdt_path_offset(nfb->fdt, "/drivers/mi"); node_offset = fdt_add_subnode(nfb->fdt, node_offset, nodename); fdt_setprop_u64(nfb->fdt, node_offset, "mmap_base", mi_node->mmap_offset); From 74ff517a9bd060e44d658e354d3414253a51f998 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 16 Apr 2024 15:48:05 +0200 Subject: [PATCH 105/518] drivers - mi: split nfb_mi_attach/detach_bus to nfb_mi_map/unmap --- drivers/kernel/drivers/nfb/mi/mi.c | 162 ++++++++++++++++++----------- drivers/kernel/drivers/nfb/mi/mi.h | 2 + 2 files changed, 104 insertions(+), 60 deletions(-) diff --git a/drivers/kernel/drivers/nfb/mi/mi.c b/drivers/kernel/drivers/nfb/mi/mi.c index 570be0d0..28eefac7 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.c +++ b/drivers/kernel/drivers/nfb/mi/mi.c @@ -23,6 +23,8 @@ static bool mi_debug = 0; ssize_t nfb_bus_mi_read(struct nfb_bus *bus, void *buf, size_t nbyte, off_t offset) { struct nfb_mi_node *mi_node = bus->priv; + if (mi_node->mem_virt == NULL) + return -EBADF; if (nbyte == sizeof(uint64_t)) *((uint64_t*)buf) = readq(mi_node->mem_virt + offset); @@ -41,6 +43,8 @@ ssize_t nfb_bus_mi_read(struct nfb_bus *bus, void *buf, size_t nbyte, off_t offs ssize_t nfb_bus_mi_write(struct nfb_bus *bus, const void *buf, size_t nbyte, off_t offset) { struct nfb_mi_node *mi_node = bus->priv; + if (mi_node->mem_virt == NULL) + return -EBADF; if (nbyte == sizeof(uint64_t)) writeq(*((uint64_t*)buf), mi_node->mem_virt + offset); @@ -81,15 +85,90 @@ int nfb_mi_mmap(struct vm_area_struct *vma, unsigned long offset, unsigned long return -ENOENT; } +int nfb_mi_map(struct nfb_device *nfb, struct nfb_mi_node *mi_node, struct nfb_pci_device *pci_device) +{ + int ret; + char nodename[64]; + int node_offset; + + /* Map PCI memory region */ + mi_node->mem_phys = pci_resource_start(pci_device->pci, mi_node->bar); + mi_node->mem_len = pci_resource_len(pci_device->pci, mi_node->bar); + + if (request_mem_region(mi_node->mem_phys, mi_node->mem_len, "nfb") == NULL) { + dev_err(&nfb->pci->dev, "unable to grab memory region 0x%llx-0x%llx\n", + (u64)mi_node->mem_phys, (u64)(mi_node->mem_phys + mi_node->mem_len - 1)); + goto err_request_mem_region; + } + + if (mi_node->is_wc_mapped) + mi_node->mem_virt = ioremap_wc(mi_node->mem_phys, mi_node->mem_len); + else + mi_node->mem_virt = ioremap(mi_node->mem_phys, mi_node->mem_len); + + if (mi_node->mem_virt == NULL) { + dev_err(&nfb->pci->dev, "unable to remap memory region 0x%llx-0x%llx\n", + (u64)mi_node->mem_phys, (u64)(mi_node->mem_phys + mi_node->mem_len - 1)); + goto err_ioremap; + } + + ret = nfb_char_register_mmap(nfb, mi_node->mem_len, &mi_node->mmap_offset, nfb_mi_mmap, mi_node->mi); + if (ret) { + goto err_nfb_char_register_mmap; + } + + /* update Device tree */ + if (mi_debug) { + node_offset = fdt_path_offset(nfb->fdt, mi_node->bus.path); + fdt_setprop_u64(nfb->fdt, node_offset, "reg", mi_node->mem_len); + } + + snprintf(nodename, sizeof(nodename), "/drivers/mi/PCI%d,BAR%d", mi_node->pci_index, mi_node->bar); + node_offset = fdt_path_offset(nfb->fdt, nodename); + + fdt_setprop_u64(nfb->fdt, node_offset, "mmap_base", mi_node->mmap_offset); + fdt_setprop_u64(nfb->fdt, node_offset, "mmap_size", mi_node->mem_len); + + return 0; + +err_nfb_char_register_mmap: + iounmap(mi_node->mem_virt); + mi_node->mem_virt = NULL; +err_ioremap: + release_mem_region(mi_node->mem_phys, mi_node->mem_len); +err_request_mem_region: + return -EBADF; +} + +void nfb_mi_unmap(struct nfb_device *nfb, struct nfb_mi_node *mi) +{ + char nodename[64]; + int node_offset; + + if (mi->mem_virt) { + nfb_char_unregister_mmap(nfb, mi->mmap_offset); + + iounmap(mi->mem_virt); + release_mem_region(mi->mem_phys, mi->mem_len); + mi->mem_virt = 0; + + snprintf(nodename, sizeof(nodename), "/drivers/mi/PCI%d,BAR%d", mi->pci_index, mi->bar); + node_offset = fdt_path_offset(nfb->fdt, nodename); + + fdt_setprop_u64(nfb->fdt, node_offset, "mmap_base", 0); + fdt_setprop_u64(nfb->fdt, node_offset, "mmap_size", 0); + } +} + int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) { int ret; + int mapped = 0; struct nfb_mi *mi = priv; struct nfb_mi_node *mi_node; struct nfb_pci_device *pci_device; int pci_index, bar; - uint32_t is_wc_mapped = 0; const void *prop; int proplen; @@ -103,29 +182,18 @@ int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) if (ret != 2) return -EINVAL; - prop = fdt_getprop(nfb->fdt, node_offset, "map-as-wc", &proplen); - is_wc_mapped = prop && proplen == 0; - - /* Find corresponding PCI device in list */ - ret = -ENODEV; - list_for_each_entry(pci_device, &nfb->pci_devices, pci_device_list) { - if (pci_device->index == pci_index) { - ret = 0; - break; - } - } - if (ret) - return ret; - ret = -ENODEV; - mi_node = kmalloc(sizeof(*mi_node), GFP_KERNEL); + mi_node = kzalloc(sizeof(*mi_node), GFP_KERNEL); if (!mi_node) return -ENOMEM; INIT_LIST_HEAD(&mi_node->nfb_mi_list); + mi_node->mi = mi; mi_node->bar = bar; mi_node->pci_index = pci_index; + prop = fdt_getprop(nfb->fdt, node_offset, "map-as-wc", &proplen); + mi_node->is_wc_mapped = prop && proplen == 0; /* Init bus structure and fill DT path */ INIT_LIST_HEAD(&mi_node->bus.bus_list); @@ -136,55 +204,34 @@ int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) if (fdt_get_path(nfb->fdt, node_offset, mi_node->bus.path, sizeof(mi_node->bus.path)) < 0) goto err_fdt_get_path; - /* Map PCI memory region */ - mi_node->mem_phys = pci_resource_start(pci_device->pci, mi_node->bar); - mi_node->mem_len = pci_resource_len(pci_device->pci, mi_node->bar); - - if (request_mem_region(mi_node->mem_phys, mi_node->mem_len, "nfb") == NULL) { - dev_err(&nfb->pci->dev, "unable to grab memory region 0x%llx-0x%llx\n", - (u64)mi_node->mem_phys, (u64)(mi_node->mem_phys + mi_node->mem_len - 1)); - goto err_request_mem_region; - } - - if (is_wc_mapped) - mi_node->mem_virt = ioremap_wc(mi_node->mem_phys, mi_node->mem_len); - else - mi_node->mem_virt = ioremap(mi_node->mem_phys, mi_node->mem_len); - - if (mi_node->mem_virt == NULL) { - dev_err(&nfb->pci->dev, "unable to remap memory region 0x%llx-0x%llx\n", - (u64)mi_node->mem_phys, (u64)(mi_node->mem_phys + mi_node->mem_len - 1)); - goto err_ioremap; - } - - ret = nfb_char_register_mmap(nfb, mi_node->mem_len, &mi_node->mmap_offset, nfb_mi_mmap, mi); - if (ret) { - goto err_nfb_char_register_mmap; - } - - if (mi_debug) { - fdt_setprop_u64(nfb->fdt, node_offset, "reg", mi_node->mem_len); - } + if (mi_debug) + fdt_setprop_u64(nfb->fdt, node_offset, "reg", 0); snprintf(nodename, sizeof(nodename), "PCI%d,BAR%d", pci_index, bar); node_offset = fdt_path_offset(nfb->fdt, "/drivers/mi"); node_offset = fdt_add_subnode(nfb->fdt, node_offset, nodename); - fdt_setprop_u64(nfb->fdt, node_offset, "mmap_base", mi_node->mmap_offset); - fdt_setprop_u64(nfb->fdt, node_offset, "mmap_size", mi_node->mem_len); + fdt_setprop_u64(nfb->fdt, node_offset, "mmap_base", 0); + fdt_setprop_u64(nfb->fdt, node_offset, "mmap_size", 0); list_add(&mi_node->nfb_mi_list, &mi->node_list); - dev_info(&nfb->pci->dev, "nfb_mi: MI%d on PCI%d attached successfully\n", bar, pci_index); nfb_bus_register(nfb, &mi_node->bus); + /* Find corresponding PCI device in list */ + list_for_each_entry(pci_device, &nfb->pci_devices, pci_device_list) { + if (pci_device->index == mi_node->pci_index) { + mapped = nfb_mi_map(nfb, mi_node, pci_device); + mapped = mapped == 0 ? 1 : -1; + break; + } + } + + dev_info(&nfb->pci->dev, "nfb_mi: MI%d on PCI%d map: %s\n", bar, pci_index, + (mapped == 1 ? "successfull" : (mapped == -1 ? "failed" : "postponed"))); + return ret; -err_nfb_char_register_mmap: - iounmap(mi_node->mem_virt); -err_ioremap: - release_mem_region(mi_node->mem_phys, mi_node->mem_len); -err_request_mem_region: err_fdt_get_path: kfree(mi_node); return ret; @@ -230,7 +277,7 @@ int nfb_mi_attach(struct nfb_device *nfb, void **priv) struct nfb_mi *mi; int node_offset = -1; - mi = kmalloc(sizeof(*mi), GFP_KERNEL); + mi = kzalloc(sizeof(*mi), GFP_KERNEL); if (!mi) return -ENOMEM; @@ -270,12 +317,7 @@ void nfb_mi_detach_bus(struct nfb_device *nfb, struct nfb_mi* nfb_mi, int node_o list_for_each_entry(mi, &nfb_mi->node_list, nfb_mi_list) { if (mi->bar == bar && mi->pci_index == pci_index) { nfb_bus_unregister(nfb, &mi->bus); - - nfb_char_unregister_mmap(nfb, mi->mmap_offset); - - iounmap(mi->mem_virt); - release_mem_region(mi->mem_phys, mi->mem_len); - + nfb_mi_unmap(nfb, mi); list_del(&mi->nfb_mi_list); dev_info(&nfb->pci->dev, "nfb_mi: MI%d on PCI%d detached\n", bar, pci_index); diff --git a/drivers/kernel/drivers/nfb/mi/mi.h b/drivers/kernel/drivers/nfb/mi/mi.h index df5d3649..03e529be 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.h +++ b/drivers/kernel/drivers/nfb/mi/mi.h @@ -16,6 +16,7 @@ struct nfb_mi { struct nfb_mi_node { struct list_head nfb_mi_list; + struct nfb_mi *mi; resource_size_t mem_phys; resource_size_t mem_len; @@ -26,6 +27,7 @@ struct nfb_mi_node { size_t mmap_offset; struct nfb_bus bus; + int is_wc_mapped; }; int nfb_mi_attach(struct nfb_device* nfb, void **priv); From a492d2c9e27554e6c18428b36397bdc841d928e3 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 16 Apr 2024 16:05:34 +0200 Subject: [PATCH 106/518] drivers - mi: add probe/remove_endpoint callbacks --- drivers/kernel/drivers/nfb/core.c | 2 ++ drivers/kernel/drivers/nfb/mi/mi.c | 25 +++++++++++++++++++++++++ drivers/kernel/drivers/nfb/mi/mi.h | 5 +++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/core.c b/drivers/kernel/drivers/nfb/core.c index 9e0fca69..8ad1b14e 100644 --- a/drivers/kernel/drivers/nfb/core.c +++ b/drivers/kernel/drivers/nfb/core.c @@ -298,6 +298,8 @@ static struct nfb_driver_ops embedded_driver_ops[] = { { .attach = nfb_mi_attach, .detach = nfb_mi_detach, + .probe_endpoint = nfb_mi_probe_endpoint, + .remove_endpoint = nfb_mi_remove_endpoint, }, { .attach = nfb_boot_attach, diff --git a/drivers/kernel/drivers/nfb/mi/mi.c b/drivers/kernel/drivers/nfb/mi/mi.c index 28eefac7..0e7b8ad6 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.c +++ b/drivers/kernel/drivers/nfb/mi/mi.c @@ -272,6 +272,30 @@ int nfb_mi_attach_node(struct nfb_device *nfb, void *priv, int base_offset) return 0; } +void nfb_mi_probe_endpoint(void *priv, struct nfb_pci_device *pci_device) +{ + struct nfb_mi *nfb_mi = priv; + struct nfb_mi_node *mi; + + list_for_each_entry(mi, &nfb_mi->node_list, nfb_mi_list) { + if (mi->pci_index == pci_device->index) { + nfb_mi_map(nfb_mi->nfb, mi, pci_device); + } + } +} + +void nfb_mi_remove_endpoint(void *priv, struct nfb_pci_device *pci_device) +{ + struct nfb_mi *nfb_mi = priv; + struct nfb_mi_node *mi; + + list_for_each_entry(mi, &nfb_mi->node_list, nfb_mi_list) { + if (mi->pci_index == pci_device->index) { + nfb_mi_unmap(nfb_mi->nfb, mi); + } + } +} + int nfb_mi_attach(struct nfb_device *nfb, void **priv) { struct nfb_mi *mi; @@ -282,6 +306,7 @@ int nfb_mi_attach(struct nfb_device *nfb, void **priv) return -ENOMEM; INIT_LIST_HEAD(&mi->node_list); + mi->nfb = nfb; *priv = mi; diff --git a/drivers/kernel/drivers/nfb/mi/mi.h b/drivers/kernel/drivers/nfb/mi/mi.h index 03e529be..114c826d 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.h +++ b/drivers/kernel/drivers/nfb/mi/mi.h @@ -12,6 +12,7 @@ struct nfb_mi { struct list_head node_list; + struct nfb_device *nfb; }; struct nfb_mi_node { @@ -33,7 +34,7 @@ struct nfb_mi_node { int nfb_mi_attach(struct nfb_device* nfb, void **priv); void nfb_mi_detach(struct nfb_device* nfb, void *priv); -int nfb_mi_attach_node(struct nfb_device* nfb, void *priv, int node_offset); -void nfb_mi_detach_node(struct nfb_device* nfb, void *priv, int node_offset); +void nfb_mi_probe_endpoint(void *priv, struct nfb_pci_device *pci_device); +void nfb_mi_remove_endpoint(void *priv, struct nfb_pci_device *pci_device); #endif //NFB_MI_H From 340d84feab294960b16e7e1790fe9865e910cc64 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 19 Apr 2024 09:07:08 +0200 Subject: [PATCH 107/518] drivers - bus: add nfb_comp_count and nfb_comp_find --- drivers/kernel/drivers/nfb/bus.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/kernel/drivers/nfb/bus.c b/drivers/kernel/drivers/nfb/bus.c index cc3aef5a..a69ddcdf 100644 --- a/drivers/kernel/drivers/nfb/bus.c +++ b/drivers/kernel/drivers/nfb/bus.c @@ -15,6 +15,44 @@ struct nfb_bus *nfb_bus_match(const struct nfb_device *nfb, int nodeoffset); +int nfb_comp_count(const struct nfb_device *dev, const char *compatible) +{ + const void *fdt; + int node_offset; + unsigned count = 0; + + if (!dev || !compatible) + return -1; + + fdt = nfb_get_fdt(dev); + + fdt_for_each_compatible_node(fdt, node_offset, compatible) { + count++; + } + + return count; +} + +int nfb_comp_find(const struct nfb_device *dev, const char *compatible, unsigned index) +{ + const void *fdt; + int node_offset; + unsigned count = 0; + + if (!dev || !compatible) + return -1; + + fdt = nfb_get_fdt(dev); + + fdt_for_each_compatible_node(fdt, node_offset, compatible) { + if (count == index) + return node_offset; + count++; + } + + return node_offset; +} + struct nfb_comp *nfb_comp_open_ext(const struct nfb_device *nfb, int nodeoffset, size_t user_size) { int ret; From 3067112e49ca4780103b5acccb492745a1a5c9a3 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 19 Apr 2024 09:14:41 +0200 Subject: [PATCH 108/518] drivers - pci: populate DT with /system/device/endpoint nodes for each MI bus This includes endpoints not attached to the driver. --- drivers/kernel/drivers/nfb/pci.c | 42 ++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 85b977ae..2b4c0f93 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -28,7 +28,7 @@ #define NFB_FDT_BURSTSIZE (16384) #define NFB_FDT_MAXSIZE (65536) -#define NFB_FDT_FIXUP_NODE_NAME_LEN 16 +#define NFB_FDT_FIXUP_NODE_NAME_LEN 64 #define NFB_CARD_NAME_GENERIC "COMBO-GENERIC" static bool fallback_fdt = 1; @@ -164,11 +164,15 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) static const char *flag_fb_select_flash = "fb_select_flash"; static const char *flag_flash_set_async = "flash_set_async"; - int i; + int i, nodes; + int ret; int node, subnode; + const void *prop; uint32_t prop32; struct nfb_pci_device *pci_device = NULL; + int node_offset; + int pci_index, bar; const char *name; const char *card_name; void *fdt = nfb->fdt; @@ -196,9 +200,13 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) fdt_setprop_u32(fdt, node, "card-id", nfb->minor); list_for_each_entry(pci_device, &nfb->pci_devices, pci_device_list) { - snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "endpoint%d", pci_device->index); - node = fdt_path_offset(fdt, "/system/device"); - node = fdt_add_subnode(fdt, node, node_name); + snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "/system/device/endpoint%d", pci_device->index); + node = fdt_path_offset(fdt, node_name); + if (node < 0) { + snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "endpoint%d", pci_device->index); + node = fdt_path_offset(fdt, "/system/device"); + node = fdt_add_subnode(fdt, node, node_name); + } fdt_setprop_string(fdt, node, "pci-slot", pci_name(pci_device->pci)); fdt_setprop_u32(fdt, node, "numa-node", dev_to_node(&pci_device->pci->dev)); @@ -208,7 +216,31 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) fdt_setprop_u32(fdt, node, "pcie-link-width", width); } + /* Populate endpoint nodes for each MI bus, if they don't exists */ + nodes = nfb_comp_count(nfb, "netcope,bus,mi"); + for (i = 0; i < nodes; i++) { + node_offset = nfb_comp_find(nfb, "netcope,bus,mi", i); + + prop = fdt_getprop(nfb->fdt, node_offset, "resource", &proplen); + if (prop == NULL || proplen <= 0 || ((const char*)prop)[proplen-1] != 0) + continue; + + ret = sscanf(prop, "PCI%d,BAR%d", &pci_index, &bar); + if (ret != 2) + continue; + + snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "/system/device/endpoint%d", pci_index); + node_offset = fdt_path_offset(fdt, node_name); + + if (node_offset < 0) { + snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "endpoint%d", pci_index); + node_offset = fdt_path_offset(fdt, "/system/device"); + node = fdt_add_subnode(fdt, node_offset, node_name); + } + } + node = fdt_path_offset(fdt, "/firmware"); + card_name = fdt_getprop(fdt, node, "card-name", &proplen); if (proplen <= 0) card_name = ""; From e4bdde064c2b24dd8bfb53836de261e0759e8934 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 19 Apr 2024 10:55:20 +0200 Subject: [PATCH 109/518] drivers - pci: split nfb_fdt_fixups to nfb_pci_fdt_update_endpoints --- drivers/kernel/drivers/nfb/pci.c | 151 +++++++++++++++++-------------- 1 file changed, 81 insertions(+), 70 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 2b4c0f93..e355fd05 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -155,6 +155,64 @@ static inline void n6010_binary_slot_prepare(void *fdt, int node, const char *mo fdt_appendprop(fdt, subnode, "modify-mask", mod_mask, mod_len); } +static void nfb_pci_fdt_update_endpoints(struct nfb_device *nfb) +{ + int pci_index, bar; + int i, node, nodes, node_offset; + const void *prop; + int proplen; + + char node_name[NFB_FDT_FIXUP_NODE_NAME_LEN]; + struct nfb_pci_device *pci_device = NULL; + void *fdt = nfb->fdt; + + enum pci_bus_speed speed; + enum pcie_link_width width; + + /* Populate endpoint nodes for each MI bus, if they don't exists */ + nodes = nfb_comp_count(nfb, "netcope,bus,mi"); + for (i = nodes-1; i >= 0; i--) { + node_offset = nfb_comp_find(nfb, "netcope,bus,mi", i); + + prop = fdt_getprop(nfb->fdt, node_offset, "resource", &proplen); + if (prop == NULL || proplen <= 0 || ((const char*)prop)[proplen-1] != 0) + continue; + + proplen = sscanf(prop, "PCI%d,BAR%d", &pci_index, &bar); + if (proplen != 2) + continue; + + snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "/system/device/endpoint%d", pci_index); + node_offset = fdt_path_offset(fdt, node_name); + + if (node_offset < 0) { + snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "endpoint%d", pci_index); + node_offset = fdt_path_offset(fdt, "/system/device"); + node = fdt_add_subnode(fdt, node_offset, node_name); + } + } + + list_for_each_entry(pci_device, &nfb->pci_devices, pci_device_list) { + snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "/system/device/endpoint%d", pci_device->index); + node = fdt_path_offset(fdt, node_name); + if (node < 0) { + snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "endpoint%d", pci_device->index); + node = fdt_path_offset(fdt, "/system/device"); + + node = fdt_add_subnode(fdt, node, node_name); + } + + if (pci_device->is_probed_as_main || pci_device->is_probed_as_sub) { + fdt_setprop_string(fdt, node, "pci-slot", pci_name(pci_device->pci)); + fdt_setprop_u32(fdt, node, "numa-node", dev_to_node(&pci_device->pci->dev)); + + pcie_bandwidth_available(pci_device->pci, NULL, &speed, &width); + fdt_setprop_u32(fdt, node, "pci-speed", speed); + fdt_setprop_u32(fdt, node, "pcie-link-width", width); + } + } +} + /* * nfb_fdt_fixups - Fix the FDT: Create missing nodes and properties * @nfb: NFB device @@ -164,24 +222,13 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) static const char *flag_fb_select_flash = "fb_select_flash"; static const char *flag_flash_set_async = "flash_set_async"; - int i, nodes; - int ret; + int i; int node, subnode; - const void *prop; uint32_t prop32; - struct nfb_pci_device *pci_device = NULL; - int node_offset; - int pci_index, bar; const char *name; const char *card_name; void *fdt = nfb->fdt; - - enum pci_bus_speed speed; - enum pcie_link_width width; - - char node_name[NFB_FDT_FIXUP_NODE_NAME_LEN]; - int proplen; static const char * boot_ctrl_compatibles[] = { @@ -199,46 +246,6 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) /* Add index of device in system */ fdt_setprop_u32(fdt, node, "card-id", nfb->minor); - list_for_each_entry(pci_device, &nfb->pci_devices, pci_device_list) { - snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "/system/device/endpoint%d", pci_device->index); - node = fdt_path_offset(fdt, node_name); - if (node < 0) { - snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "endpoint%d", pci_device->index); - node = fdt_path_offset(fdt, "/system/device"); - node = fdt_add_subnode(fdt, node, node_name); - } - - fdt_setprop_string(fdt, node, "pci-slot", pci_name(pci_device->pci)); - fdt_setprop_u32(fdt, node, "numa-node", dev_to_node(&pci_device->pci->dev)); - - pcie_bandwidth_available(pci_device->pci, NULL, &speed, &width); - fdt_setprop_u32(fdt, node, "pci-speed", speed); - fdt_setprop_u32(fdt, node, "pcie-link-width", width); - } - - /* Populate endpoint nodes for each MI bus, if they don't exists */ - nodes = nfb_comp_count(nfb, "netcope,bus,mi"); - for (i = 0; i < nodes; i++) { - node_offset = nfb_comp_find(nfb, "netcope,bus,mi", i); - - prop = fdt_getprop(nfb->fdt, node_offset, "resource", &proplen); - if (prop == NULL || proplen <= 0 || ((const char*)prop)[proplen-1] != 0) - continue; - - ret = sscanf(prop, "PCI%d,BAR%d", &pci_index, &bar); - if (ret != 2) - continue; - - snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "/system/device/endpoint%d", pci_index); - node_offset = fdt_path_offset(fdt, node_name); - - if (node_offset < 0) { - snprintf(node_name, NFB_FDT_FIXUP_NODE_NAME_LEN, "endpoint%d", pci_index); - node_offset = fdt_path_offset(fdt, "/system/device"); - node = fdt_add_subnode(fdt, node_offset, node_name); - } - } - node = fdt_path_offset(fdt, "/firmware"); card_name = fdt_getprop(fdt, node, "card-name", &proplen); @@ -887,6 +894,7 @@ void nfb_pci_try_attach(struct nfb_pci_device *self) mutex_unlock(&pci_device->attach_lock); } } + nfb_pci_fdt_update_endpoints(nfb); } else if (self->is_probed_as_sub) { list_for_each_entry(pci_device, &global_pci_device_list, global_pci_device_list) { if (mutex_trylock(&pci_device->attach_lock)) { @@ -896,6 +904,7 @@ void nfb_pci_try_attach(struct nfb_pci_device *self) nfb_pci_device_is_attachable(nfb, self)) { nfb_pci_attach_endpoint(nfb, self, self->index); nfb_probe_endpoint_late(nfb, self); + nfb_pci_fdt_update_endpoints(nfb); } mutex_unlock(&pci_device->attach_lock); } @@ -1024,24 +1033,6 @@ static int nfb_pci_probe_main(struct nfb_pci_device *pci_device, const struct pc nfb->dsn = pci_device->dsn; - nfb_pci_attach_endpoint(nfb, pci_device, 0); - - while ((bus = pci_find_next_bus(bus))) { - nfb_pci_attach_all_slaves(nfb, bus); - } - - /* Initialize interrupts */ - ret = pci_enable_msi(pci); - if (ret) { - dev_info(&pci->dev, "unable to enable MSI\n"); - //goto err_pci_enable_msi; - } else { - ret = request_irq(pci->irq, nfb_interrupt, IRQF_SHARED, "nfb", nfb); - } - if (ret) { - pci->irq = -1; - } - nfb->fdt = nfb_dtb_inject; if (nfb->fdt == NULL) { /* Populate device tree */ @@ -1063,6 +1054,26 @@ static int nfb_pci_probe_main(struct nfb_pci_device *pci_device, const struct pc nfb_fdt_fixups(nfb); + nfb_pci_attach_endpoint(nfb, pci_device, 0); + + while ((bus = pci_find_next_bus(bus))) { + nfb_pci_attach_all_slaves(nfb, bus); + } + + nfb_pci_fdt_update_endpoints(nfb); + + /* Initialize interrupts */ + ret = pci_enable_msi(pci); + if (ret) { + dev_info(&pci->dev, "unable to enable MSI\n"); + //goto err_pci_enable_msi; + } else { + ret = request_irq(pci->irq, nfb_interrupt, IRQF_SHARED, "nfb", nfb); + } + if (ret) { + pci->irq = -1; + } + /* Publish NFB object */ ret = nfb_probe(nfb); if (ret) { From d994b16b02fcf1e3b731d0fd14c7be851aa17896 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 19 Apr 2024 09:00:48 +0200 Subject: [PATCH 110/518] tools - info: print all BAR size --- tools/info/info.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) mode change 100755 => 100644 tools/info/info.c diff --git a/tools/info/info.c b/tools/info/info.c old mode 100755 new mode 100644 index ca84d985..cb8c3390 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -192,14 +192,30 @@ const char *pci_speed_string(enum pci_bus_speed speed) "Unknown speed"; } +void print_size(unsigned long size) +{ + static const char *units[] = { + "B", "KiB", "MiB", "GiB"}; + unsigned int i = 0; + while (size >= 1024 && i < NC_ARRAY_SIZE(units)) { + size >>= 10; + i++; + } + printf("%lu %s", size, units[i]); +} + void print_endpoint_info(struct nfb_device *dev, int fdt_offset) { int len; + int bar; int dev_id = -1; + uint64_t bar_size; const void *prop; const uint32_t *prop32; + const uint64_t *prop64; const void *fdt; const char* node_name; + char nodename[64]; fdt = nfb_get_fdt(dev); @@ -225,6 +241,21 @@ void print_endpoint_info(struct nfb_device *dev, int fdt_offset) prop32 = fdt_getprop(fdt, fdt_offset, "numa-node", &len); if (len == sizeof(*prop32)) printf(" * NUMA node : %i\n", fdt32_to_cpu(*prop32)); + + for (bar = 0; bar < 6; bar++) { + snprintf(nodename, sizeof(nodename), "/drivers/mi/PCI%d,BAR%d", dev_id, bar); + fdt_offset = fdt_path_offset(fdt, nodename); + if (fdt_offset >= 0) { + prop64 = fdt_getprop(fdt, fdt_offset, "mmap_size", &len); + if (len != sizeof(*prop64)) + continue; + bar_size = fdt64_to_cpu(*prop64); + printf(" * MI BAR %d size : %s", bar, bar_size == 0 ? "unmapped!" : ""); + if (bar_size) + print_size(bar_size); + printf("\n"); + } + } } void print_common_info(struct nfb_device *dev, int verbose) From d062a5553cda41a60bb344fa4456feaa3a0ae18c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 24 Apr 2024 12:40:58 +0200 Subject: [PATCH 111/518] drivers - mi: fix reversed comparison of mmap regions The boundary of mmap for MI was checked opposite. --- drivers/kernel/drivers/nfb/mi/mi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/mi/mi.c b/drivers/kernel/drivers/nfb/mi/mi.c index 0e7b8ad6..a09828bd 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.c +++ b/drivers/kernel/drivers/nfb/mi/mi.c @@ -67,7 +67,7 @@ int nfb_mi_mmap(struct vm_area_struct *vma, unsigned long offset, unsigned long //struct nfb_app *app = (struct nfb_app*) vma->vm_private_data; list_for_each_entry(mi_node, &mi->node_list, nfb_mi_list) { - if (mi_node->mmap_offset >= offset && mi_node->mmap_offset + mi_node->mem_len <= offset + size) { + if (mi_node->mmap_offset <= offset && mi_node->mmap_offset + mi_node->mem_len >= offset + size) { #ifdef pgprot_noncached vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); #endif From 505cb9d984efa13aef4e04415d22164b6dc01cf7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 25 Apr 2024 12:46:06 +0000 Subject: [PATCH 112/518] build: [FIX] Debian packaging --- CMakeLists.txt | 9 ++++++++- pynfb/CMakeLists.txt | 9 ++++++--- python/nfb-tools/nfb-tools.cmake | 15 +++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0da2a51e..544f3620 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,6 @@ add_subdirectory(utils) add_subdirectory(pynfb) add_subdirectory(python/nfb-tools) -include(python/nfb-tools/nfb-tools.cmake) configure_file(package/preinst.in package/preinst @ONLY) configure_file(package/postinst.in package/postinst @ONLY) @@ -132,12 +131,20 @@ set(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}") set(CPACK_DEBIAN_PACKAGE_RELEASE "${GIT_VERSION_DEBRELEASE}") set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}-${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}.deb") +set(CPACK_DEBIAN_MAIN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") +set(CPACK_DEBIAN_MAIN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}") +set(CPACK_DEBIAN_MAIN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") +set(CPACK_DEBIAN_MAIN_FILE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}-${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}.deb") + set(CPACK_DEBIAN_DEBUGTOOLS_PACKAGE_NAME "nfb-framework-debug") set(CPACK_DEBIAN_DEBUGTOOLS_FILE_NAME "nfb-framework-debug-${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}.deb") set(CPACK_DEBIAN_PYTHON_PACKAGE_NAME "python3-nfb") set(CPACK_DEBIAN_PYTHON_FILE_NAME "python3-nfb-${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}.deb") string(JOIN ", " CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEP_LIST}) string(JOIN ", " CPACK_DEBIAN_PYTHON_PACKAGE_DEPENDS ${DEB_PYTHON_DEP_LIST}) + +include(python/nfb-tools/nfb-tools.cmake) + set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_BINARY_DIR}/package/preinst" diff --git a/pynfb/CMakeLists.txt b/pynfb/CMakeLists.txt index 393e8144..d146b340 100644 --- a/pynfb/CMakeLists.txt +++ b/pynfb/CMakeLists.txt @@ -27,11 +27,14 @@ add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/setup_timestamp COMMAND ${Python_EXECUTABLE} ARGS ${SETUP_PY} install --root ${SETUP_OUTPUT} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/setup_timestamp - DEPENDS ${SETUP_DEPS}) + DEPENDS ${SETUP_DEPS} +) -add_custom_target(target ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup_timestamp) +add_custom_target(python_nfb ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup_timestamp) install( DIRECTORY ${SETUP_OUTPUT}/ DESTINATION "/" # FIXME may cause issues with other cpack generators - COMPONENT python) + COMPONENT python + USE_SOURCE_PERMISSIONS +) diff --git a/python/nfb-tools/nfb-tools.cmake b/python/nfb-tools/nfb-tools.cmake index 0cc4cc1c..31c9f7cb 100644 --- a/python/nfb-tools/nfb-tools.cmake +++ b/python/nfb-tools/nfb-tools.cmake @@ -1,20 +1,23 @@ -set(RPM_PYTHON_DEP_LIST +set(RPM_PYTHONTOOLS_DEP_LIST python3-fdt python3-nfb python3-yaml # python3-ofm ) -set(DEB_PYTHON_DEP_LIST -# python3-nfb -# python3-yaml +set(DEB_PYTHONTOOLS_DEP_LIST + python3-nfb + python3-yaml # python-ofm ) set(CPACK_RPM_pythontools_PACKAGE_NAME "python3-nfb-tools") -string(JOIN " " CPACK_RPM_pythontools_PACKAGE_REQUIRES ${RPM_PYTHON_DEP_LIST}) -string(JOIN ", " CPACK_DEBIAN_pythontools_PACKAGE_DEPENDS ${DEB_PYTHON_DEP_LIST}) +string(JOIN " " CPACK_RPM_pythontools_PACKAGE_REQUIRES ${RPM_PYTHONTOOLS_DEP_LIST}) + +string(JOIN ", " CPACK_DEBIAN_PYTHONTOOLS_PACKAGE_DEPENDS ${DEB_PYTHONTOOLS_DEP_LIST}) +set(CPACK_DEBIAN_PYTHONTOOLS_PACKAGE_NAME "python3-nfb-tools") +set(CPACK_DEBIAN_PYTHONTOOLS_FILE_NAME "python3-nfb-tools-${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}.deb") #set(RPM_PYTHON_DEP_LIST # ofm #) From d8b4a67d94865c5c9a0abd790af34b83088d7838 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 2 May 2024 07:45:03 +0200 Subject: [PATCH 113/518] build: [FIX] missing libconfig-dev for Debian --- build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sh b/build.sh index c86018eb..30759479 100755 --- a/build.sh +++ b/build.sh @@ -150,6 +150,7 @@ get_dependencies() ret="$ret libnuma-dev" ret="$ret libncurses-dev" ret="$ret libarchive-dev" + ret="$ret libconfig-dev" ret="$ret python3-dev" ret="$ret python3-setuptools" ret="$ret cython3" From ba1e385242a708d7f63768d35be3d1b066c18c33 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 24 Apr 2024 09:52:25 +0200 Subject: [PATCH 114/518] pynfb: [FIX] don't fail when nc_queue open returns NULL The Nfb object initialization opens all queues on the device. However opening a nc_queue on unprobed subsidiary endpoint will fail. This fix let the Queue init phase pass, but throws an Exception on subsequent access to the nc_queue. The Nfb will be then at least partially usable. --- pynfb/nfb/libnfb.pyx | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 49830060..a38712e5 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -530,15 +530,26 @@ cdef class NdpQueueRx(NdpQueue): self._dir = 0 NdpQueue.__init__(self, nfb, node, index) self._nc_queue = libnetcope.nc_rxqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) - if self._nc_queue is NULL: - PyErr_SetFromErrno(OSError) def __dealloc__(self): if self._nc_queue is not NULL: libnetcope.nc_rxqueue_close(self._nc_queue) + def _check_nc_queue(self): + if not self.is_accessible(): + raise Exception("nc_queue is invalid") + + def is_accessible(self): + """ Check if the control registers are accessible """ + return self._nc_queue is not NULL + + def is_available(self): + """ Check if the queue can transfer data """ + raise NotImplementedError() + def stats_reset(self): """Reset statistic counters""" + self._check_nc_queue() libnetcope.nc_rxqueue_reset_counters(self._nc_queue) def stats_read(self) -> dict: @@ -549,6 +560,7 @@ cdef class NdpQueueRx(NdpQueue): """ cdef libnetcope.nc_rxqueue_counters counters + self._check_nc_queue() libnetcope.nc_rxqueue_read_counters(self._nc_queue, &counters) return { @@ -648,15 +660,26 @@ cdef class NdpQueueTx(NdpQueue): self._dir = 1 NdpQueue.__init__(self, nfb, node, index) self._nc_queue = libnetcope.nc_txqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) - if self._nc_queue is NULL: - PyErr_SetFromErrno(OSError) def __dealloc__(self): if self._nc_queue is not NULL: libnetcope.nc_txqueue_close(self._nc_queue) + def _check_nc_queue(self): + if self._nc_queue is NULL: + raise Exception("nc_queue is invalid") + + def is_accessible(self): + """ Check if the control registers are accessible """ + return self._nc_queue is not NULL + + def is_available(self): + """ Check if the queue can transfer data """ + raise NotImplementedError() + def stats_reset(self): """Reset statistic counters""" + self._check_nc_queue() libnetcope.nc_txqueue_reset_counters(self._nc_queue) def stats_read(self): @@ -667,6 +690,7 @@ cdef class NdpQueueTx(NdpQueue): """ cdef libnetcope.nc_txqueue_counters counters + self._check_nc_queue() libnetcope.nc_txqueue_read_counters(self._nc_queue, &counters) return { From c3a8f28b95c1bb082dd0d1e04edd380b8abb1467 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 3 May 2024 09:47:18 +0200 Subject: [PATCH 115/518] python nfb-meter: [FIX] enable sparse DMA channels --- python/nfb-tools/nfbmeter/__main__.py | 3 +++ python/nfb-tools/nfbmeter/nfbmeter.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 python/nfb-tools/nfbmeter/__main__.py diff --git a/python/nfb-tools/nfbmeter/__main__.py b/python/nfb-tools/nfbmeter/__main__.py new file mode 100644 index 00000000..b6f87275 --- /dev/null +++ b/python/nfb-tools/nfbmeter/__main__.py @@ -0,0 +1,3 @@ +from . import nfbmeter + +nfbmeter.main() diff --git a/python/nfb-tools/nfbmeter/nfbmeter.py b/python/nfb-tools/nfbmeter/nfbmeter.py index cac85a4e..71d3a8ed 100755 --- a/python/nfb-tools/nfbmeter/nfbmeter.py +++ b/python/nfb-tools/nfbmeter/nfbmeter.py @@ -51,11 +51,11 @@ def __init__(self, dev, config): self._config = config self._rxmac = [eth.rxmac for eth in self._dev.eth] - self._rxdma = [dma for dma in self._dev.ndp.rx] + self._rxdma = {i: dma for i, dma in enumerate(self._dev.ndp.rx) if dma.is_accessible()} self._bdc = {} self._ech = {} - for p in self._config['probes']: + for p in self._config.get('probes', []): cfg = SimpleNamespace(**p) if cfg.type == "event_counter_histogram": probe = EventCounterHistogram(dev, cfg) @@ -78,7 +78,7 @@ def init(self): self._items = { "rxmac": [f"rm{i}" for i, _ in enumerate(self._rxmac)], - "rxdma": [f"rd{i}" for i, _ in enumerate(self._rxdma)], + "rxdma": [f"rd{i}" for i in self._rxdma.keys()], "busdebugprobe": [ *[f"{bd.id}_{bd.probe_name[p]}" for i, bd in enumerate(self._bdc.values()) for p in range(bd.nr_probes)], ], @@ -93,7 +93,7 @@ def read(self): for i, mac in enumerate(self._rxmac): data[f"rm{i}"] = mac.stats_read() - for i, dma in enumerate(self._rxdma): + for i, dma in self._rxdma.items(): data[f"rd{i}"] = dma.stats_read() for i, bd in enumerate(self._bdc.values()): From 8e7e3c31c2f6786c4e31bc2f7b915bbcaeb517e8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 May 2024 07:26:27 +0200 Subject: [PATCH 116/518] python: fix linter errors --- libnfb/include/netcope/dma_ctrl_ndp.h | 2 ++ pynfb/examples/02-data-transfer.py | 2 +- pynfb/nfb/eth.py | 2 +- pynfb/nfb/libnetcope.pyx | 2 ++ python/nfb-tools/nfbbootstrap/dfl.py | 10 +++----- python/nfb-tools/nfbmeter/busdebug.py | 2 +- python/nfb-tools/nfbmeter/eventcounter.py | 1 - python/nfb-tools/nfbmeter/nfbmeter.py | 29 ++++++++--------------- python/nfb-tools/nfbmeter/utils.py | 2 -- 9 files changed, 20 insertions(+), 32 deletions(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 5eab8e01..8e72c8d4 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -298,6 +298,8 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl } else if (ctrl->type == DMA_TYPE_CALYPTE) { nb_d = sp->nb_data; d_buffer = sp->data_buffer; + } else { + return -ENODEV; } /* Check for valid parameters: number of descs and hdrs must be pow2() */ diff --git a/pynfb/examples/02-data-transfer.py b/pynfb/examples/02-data-transfer.py index 371b421d..cb55274b 100644 --- a/pynfb/examples/02-data-transfer.py +++ b/pynfb/examples/02-data-transfer.py @@ -138,5 +138,5 @@ # Reset Queue statistics txq.stats_reset() -except: +except Exception: pass diff --git a/pynfb/nfb/eth.py b/pynfb/nfb/eth.py index f73fba17..37dfd438 100644 --- a/pynfb/nfb/eth.py +++ b/pynfb/nfb/eth.py @@ -86,7 +86,7 @@ def __init__(self, nfb, node): if "QSFPP": prop = node_ctrl_param.get_property("i2c-addr") i2c_addr = prop.value if prop else 0xA0 - self.i2c = libnetcope.I2c(nfb, ctrl, i2c_addr); + self.i2c = libnetcope.I2c(nfb, ctrl, i2c_addr) # FIXME: only valid for specific QSFP+ @property diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index a4c3b174..66558b5f 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -331,12 +331,14 @@ cdef class DmaCtrlNdp: self.ub_view = update_buffer_p ub_ptr = &self.ub_view[0] + sp.data_buffer = 0 sp.desc_buffer = desc_buffer sp.hdr_buffer = hdr_buffer sp.update_buffer = update_buffer sp.update_buffer_virt = ub_ptr sp.nb_desc = nb_desc sp.nb_hdr = nb_hdr + sp.nb_data = 0 self._ctrl.shp = 0 self._ctrl.sdp = 0 diff --git a/python/nfb-tools/nfbbootstrap/dfl.py b/python/nfb-tools/nfbbootstrap/dfl.py index 7e96b5ef..e823683f 100644 --- a/python/nfb-tools/nfbbootstrap/dfl.py +++ b/python/nfb-tools/nfbbootstrap/dfl.py @@ -1,4 +1,3 @@ -from .pypcie.bar import Bar from .pypcie.device import Device @@ -27,9 +26,6 @@ def bit(b): def bitmask(b): return (1 << b) - 1 -def bitmask(b): - return (1 << b) - 1 - def bit_get(val, b): return (val >> b) & 1 @@ -51,7 +47,7 @@ def feature_id(value): def parse_dfl_from(bar, offset, out_dict, verbose): # read BAR 0, offset 0x1004 - while offset != None: + while offset is not None: guid = [] cfg_qword = bar.read64(offset+0) @@ -69,8 +65,8 @@ def parse_dfl_from(bar, offset, out_dict, verbose): if verbose: print(f"DFL: ITEM on offset {hex(offset)}: {dfh_type_s}, ID: {dfh_id}, version {dfh_ver}, next: {hex(dfh_next)}, eol: {eol}", "GUID:", [hex(x) for x in guid]) if dfh_type == DFH_TYPE_FIU: - fme_next_afuq = bar.read64(offset + NEXT_AFU) - fme_next_afu = field_get(fme_next_afuq, 24, 0) + #fme_next_afuq = bar.read64(offset + NEXT_AFU) + #fme_next_afu = field_get(fme_next_afuq, 24, 0) if dfh_id == DFH_TYPE_FIU_FME: fme_cfg_qword = bar.read64(offset + FME_HDR_CAP) diff --git a/python/nfb-tools/nfbmeter/busdebug.py b/python/nfb-tools/nfbmeter/busdebug.py index d5a3b017..1f320250 100644 --- a/python/nfb-tools/nfbmeter/busdebug.py +++ b/python/nfb-tools/nfbmeter/busdebug.py @@ -56,7 +56,7 @@ def bus_enable(self, pid): def stats_read(self, pid): # TODO Check: atomic read / strobe? - data = self._comp.read(po(pid, self._WORD_CNT_LOW), self._NAME); + data = self._comp.read(po(pid, self._WORD_CNT_LOW), self._NAME) cntr = {} for i, n in enumerate(["words", "wait", "dst_hold", "src_hold", "sop_cnt", "eop_cnt"]): cntr[n] = int.from_bytes(data[i*8:i*8+8], byteorder='little') diff --git a/python/nfb-tools/nfbmeter/eventcounter.py b/python/nfb-tools/nfbmeter/eventcounter.py index 2fc27730..c792925f 100644 --- a/python/nfb-tools/nfbmeter/eventcounter.py +++ b/python/nfb-tools/nfbmeter/eventcounter.py @@ -1,6 +1,5 @@ import nfb import time -from collections import deque class EventCounter(nfb.BaseComp): diff --git a/python/nfb-tools/nfbmeter/nfbmeter.py b/python/nfb-tools/nfbmeter/nfbmeter.py index 71d3a8ed..1fdbd781 100755 --- a/python/nfb-tools/nfbmeter/nfbmeter.py +++ b/python/nfb-tools/nfbmeter/nfbmeter.py @@ -4,18 +4,11 @@ # # SPDX-License-Identifier: BSD-3-Clause -import sys import logging -import subprocess import time -import os -import csv -import signal import datetime import argparse import json -import re -import types import yaml from types import SimpleNamespace @@ -28,11 +21,10 @@ #import busdebug #import eventcounter -import re import curses -from .utils import * -from .probes import * +from .utils import nocurses_wrapper, NoCurses +from .probes import EventCounterHistogram, BusDebugProbe class MeterManager(): @@ -168,7 +160,7 @@ def get_basic_info(dev): for item in ["project-version", "build-revision", "card-name", "project-name", "project-variant"]: try: setattr(info, item.replace("-", "_"), dev.fdt.get_node("/firmware").get_property(item).value) - except: + except Exception: pass info.rxq_nr = len(dev.ndp.rx) @@ -209,8 +201,8 @@ def _display_rxdma(self, o, m, stdscr, items): stdscr.addstr(o, 0, f"Rx DMA | Total: {dma_total:>11} | Received: {dma_total_rcvd:>11} | Discarded: {dma_total_disc:>11}") for i, it in enumerate(items['rxdma']): item = m.data[it] - stdscr.addstr(o+1, 2, f"% Received") - stdscr.addstr(o+2, 2, f"% Discarded") + stdscr.addstr(o+1, 2, "% Received") + stdscr.addstr(o+2, 2, "% Discarded") if (i+1)*12 + 12 >= cols: continue @@ -252,7 +244,7 @@ def _display_histogram(self, o, m, stdscr, config): horiz = hasattr(config, 'style') and config.style == 'horizontal' #if prev_bins_names != histograms.keys(): - if prev_bins_names == None: + if prev_bins_names is None: prev_bins_names = histograms.keys() for j, bin_name in enumerate(prev_bins_names): x, y = (2, j + 1) if horiz else (j*8+14, i) @@ -308,7 +300,7 @@ def meter_loop(stdscr, args, meter, logger, display): m = meter.measure() time.sleep(args.interval) - while args.period == None or ((t_toolstart + args.period > t_start) if args.period is not None else True) or print_once: + while args.period is None or ((t_toolstart + args.period > t_start) if args.period is not None else True) or print_once: t_start = time.time() m = meter.measure() logging.debug(meter.to_json(m)) @@ -348,11 +340,10 @@ def main(): logging.debug(info_to_json(bi)) info = SimpleNamespace() - t = dev.fdt.get_node("/firmware").get_property("build-time").value for item in ["project-version", "build-revision", "card-name", "project-name", "project-variant"]: try: setattr(info, item.replace("-", "_"), dev.fdt.get_node("/firmware").get_property(item).value) - except: + except Exception: pass # Load probe configuration @@ -362,13 +353,13 @@ def main(): if args.config is None: try: args.config = f"{defcfg_path}{info.card_name}-{info.project_name}-{info.project_variant}-{info.project_version}-{defcfg_name}.yaml" - except: + except Exception: raise Exception("Can't deduce default config filename, specify config file explicitly.") try: with open(args.config) as stream: config = yaml.safe_load(stream) - except: + except Exception: raise Exception("Can't load configuration file.") assert config['version'] == "0.1", "Incorrect version of config file" diff --git a/python/nfb-tools/nfbmeter/utils.py b/python/nfb-tools/nfbmeter/utils.py index 147e7d3a..671aa761 100644 --- a/python/nfb-tools/nfbmeter/utils.py +++ b/python/nfb-tools/nfbmeter/utils.py @@ -1,5 +1,3 @@ -import termios - class NoCurses(): def __init__(self): self._buffers = [] From d42043a1abdc5a10b60ef6a55f0aac30c4d4cee3 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 May 2024 08:00:08 +0200 Subject: [PATCH 117/518] libnetcope - dma_ctrl_ndp: add function nc_ndp_rx_desc3 --- libnfb/include/netcope/dma_ctrl_ndp.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 8e72c8d4..57006e68 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -88,6 +88,13 @@ struct nc_ndp_desc { int next0 : 1; unsigned type : 2; } type2; + struct __attribute__((__packed__)) { + unsigned phys0 : 30; + int int0 : 1; + int int1 : 1; + unsigned phys1 : 30; + unsigned type : 2; + } type3; } d; } __attribute__((__packed__)); @@ -157,6 +164,19 @@ static inline struct nc_ndp_desc nc_ndp_rx_desc2(uint64_t phys, uint16_t len, in return desc; } +static inline struct nc_ndp_desc nc_ndp_rx_desc3(uint64_t phys0, uint64_t phys1) +{ + struct nc_ndp_desc desc; + + desc.d.type3.type = 3; + desc.d.type3.phys0 = phys0; + desc.d.type3.phys1 = phys1; + desc.d.type3.int0 = 0; + desc.d.type3.int1 = 0; + + return desc; +} + static inline struct nc_ndp_desc nc_ndp_tx_desc0(uint64_t phys) { return nc_ndp_rx_desc0(phys); From c2fee45dff2de1a8de88e370a3e77c2ba9f22047 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 8 Feb 2024 13:09:06 +0100 Subject: [PATCH 118/518] nfb-dma: [FIX] access DMA ctrl regs even without NDP channel associated --- tools/dma/dma.c | 53 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 1be27e12..d7f16789 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -170,18 +170,19 @@ int query_print(struct nfb_device *dev, struct list_range index_range, break; rxc_valid = 1; - if (ndp_rx_queue_is_available(dev, i)) { - rxq = nc_rxqueue_open_index(dev, i, QUEUE_TYPE_UNDEF); - if (rxq == NULL) { + rxq = nc_rxqueue_open_index(dev, i, QUEUE_TYPE_UNDEF); + if (rxq == NULL) { + if (ndp_rx_queue_is_available(dev, i)) { warnx("problem opening rx_queue"); - return EXIT_FAILURE; + } else { + warnx("rx_queue doesn't exist"); } - nc_rxqueue_read_counters(rxq, &cr); - nc_rxqueue_close(rxq); - } else { - warnx("rx_queue doesn't exist"); return EXIT_FAILURE; - } break; + } + nc_rxqueue_read_counters(rxq, &cr); + nc_rxqueue_close(rxq); + break; + case TX_SENT: case TX_SENT_BYTES: case TX_DISCARDED: @@ -190,19 +191,21 @@ int query_print(struct nfb_device *dev, struct list_range index_range, break; txc_valid = 1; - if (ndp_tx_queue_is_available(dev, i)) { - txq = nc_txqueue_open_index(dev, i, QUEUE_TYPE_UNDEF); - if (txq == NULL) { + txq = nc_txqueue_open_index(dev, i, QUEUE_TYPE_UNDEF); + if (txq == NULL) { + if (ndp_tx_queue_is_available(dev, i)) { warnx("problem opening tx_queue"); - return EXIT_FAILURE; + + } else { + warnx("tx_queue doesn't exist"); } - nc_txqueue_read_counters(txq, &ct); - nc_txqueue_close(txq); - } else { - warnx("tx_queue doesn't exist"); return EXIT_FAILURE; - } break; - default: break; + } + nc_txqueue_read_counters(txq, &ct); + nc_txqueue_close(txq); + break; + + default: break; } switch (queries[j]) { @@ -559,10 +562,8 @@ int main(int argc, char *argv[]) i = 0; fdt_for_each_compatible_node(nfb_get_fdt(dev), fdt_offset, rx_ctrl_name[ctrl]) { if (list_range_empty(&index_range) || list_range_contains(&index_range, i)) { - if (ndp_rx_queue_is_available(dev, i)) { - rxq = nc_rxqueue_open(dev, fdt_offset); - if (rxq == NULL) - continue; + rxq = nc_rxqueue_open(dev, fdt_offset); + if (rxq) { switch (cmd) { case CMD_COUNTER_RESET: @@ -600,10 +601,8 @@ int main(int argc, char *argv[]) i = 0; fdt_for_each_compatible_node(nfb_get_fdt(dev), fdt_offset, tx_ctrl_name[ctrl]) { if (list_range_empty(&index_range) || list_range_contains(&index_range, i)) { - if (ndp_tx_queue_is_available(dev, i)) { - txq = nc_txqueue_open(dev, fdt_offset); - if (txq == NULL) - continue; + txq = nc_txqueue_open(dev, fdt_offset); + if (txq) { switch (cmd) { case CMD_COUNTER_RESET: nc_txqueue_reset_counters(txq); From 65816225a956a8184b3af5d6648d5662dbd11425 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 May 2024 08:41:58 +0200 Subject: [PATCH 119/518] drivers - ndp: [MAINTENANCE] remove duplicated hdr_buffer in ctrl struct --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 32 +++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index ec9d446f..1efc452f 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -56,6 +56,9 @@ struct ndp_ctrl { ndp_offset_t *off_buffer_v; union { + struct { + void *hdr_buffer_v; + } common; struct { struct nc_ndp_hdr *hdr_buffer; } medusa; @@ -77,7 +80,6 @@ struct ndp_ctrl { int hdr_count; void *hdr_buffer; - void *hdr_buffer_v; uint8_t hdr_buff_en_rw_map; uint8_t next_sdp_age; @@ -141,7 +143,7 @@ static const struct attribute_group *ndp_ctrl_attr_tx_groups[] = { int ndp_ctrl_v2_get_vmaps(struct ndp_channel *channel, void **hdr, void **off) { struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); - *hdr = ctrl->hdr_buffer_v; + *hdr = ctrl->ts.common.hdr_buffer_v; *off = ctrl->off_buffer_v; return ctrl->hdr_count; } @@ -582,8 +584,6 @@ static int ndp_ctrl_medusa_start(struct ndp_channel *channel, uint64_t *hwptr) sp.nb_desc = ctrl->desc_count; sp.nb_hdr = ctrl->hdr_count; - ctrl->ts.medusa.hdr_buffer = ctrl->hdr_buffer_v; - ret = ndp_ctrl_start(ctrl, &sp); if (ret) return ret; @@ -639,8 +639,6 @@ static int ndp_ctrl_calypte_start(struct ndp_channel *channel, uint64_t *hwptr) sp.nb_data = ctrl->hdr_count; sp.nb_hdr = ctrl->hdr_count; - ctrl->ts.calypte.hdr_buffer = ctrl->hdr_buffer_v; - for (ret = 0; ret < ctrl->hdr_count; ret++) { hdr_base = ctrl->ts.calypte.hdr_buffer + ret; hdr_base->valid = 0; @@ -840,8 +838,8 @@ static int ndp_ctrl_medusa_attach_ring(struct ndp_channel *channel) goto err_alloc_hdr; } - ctrl->hdr_buffer_v = ndp_ctrl_vmap_shadow(ctrl->hdr_buffer_size, ctrl->hdr_buffer); - if (ctrl->hdr_buffer_v == NULL) { + ctrl->ts.common.hdr_buffer_v = ndp_ctrl_vmap_shadow(ctrl->hdr_buffer_size, ctrl->hdr_buffer); + if (ctrl->ts.common.hdr_buffer_v == NULL) { goto err_vmap_hdr_buffer; } @@ -867,7 +865,7 @@ static int ndp_ctrl_medusa_attach_ring(struct ndp_channel *channel) //nfb_char_unregister_mmap(channel->ndp->nfb, ctrl->hdr_mmap_offset); err_register_mmap_hdr: - vunmap(ctrl->hdr_buffer_v); + vunmap(ctrl->ts.common.hdr_buffer_v); err_vmap_hdr_buffer: dma_free_coherent(dev, ctrl->hdr_buffer_size, ctrl->hdr_buffer, ctrl->hdr_buffer_phys); @@ -931,8 +929,8 @@ static int ndp_ctrl_rx_calypte_attach_ring(struct ndp_channel *channel) return -EINVAL; } - ctrl->hdr_buffer_v = ndp_ctrl_vmap_shadow(ctrl->hdr_buffer_size, ctrl->hdr_buffer); - if (ctrl->hdr_buffer_v == NULL) { + ctrl->ts.common.hdr_buffer_v = ndp_ctrl_vmap_shadow(ctrl->hdr_buffer_size, ctrl->hdr_buffer); + if (ctrl->ts.common.hdr_buffer_v == NULL) { goto err_vmap_hdr_buffer; } @@ -951,7 +949,7 @@ static int ndp_ctrl_rx_calypte_attach_ring(struct ndp_channel *channel) return 0; err_register_mmap_hdr: - vunmap(ctrl->hdr_buffer_v); + vunmap(ctrl->ts.common.hdr_buffer_v); err_vmap_hdr_buffer: dma_free_coherent(dev, ctrl->hdr_buffer_size, @@ -1010,8 +1008,8 @@ static int ndp_ctrl_tx_calypte_attach_ring(struct ndp_channel *channel) goto err_alloc_hdr; } - ctrl->hdr_buffer_v = ndp_ctrl_vmap_shadow(ctrl->hdr_buffer_size, ctrl->hdr_buffer); - if (ctrl->hdr_buffer_v == NULL) { + ctrl->ts.common.hdr_buffer_v = ndp_ctrl_vmap_shadow(ctrl->hdr_buffer_size, ctrl->hdr_buffer); + if (ctrl->ts.common.hdr_buffer_v == NULL) { goto err_vmap_hdr_buffer; } @@ -1035,7 +1033,7 @@ static int ndp_ctrl_tx_calypte_attach_ring(struct ndp_channel *channel) return 0; err_register_mmap_hdr: - vunmap(ctrl->hdr_buffer_v); + vunmap(ctrl->ts.common.hdr_buffer_v); err_vmap_hdr_buffer: dma_free_coherent(dev, ctrl->hdr_buffer_size, @@ -1053,7 +1051,7 @@ static void ndp_ctrl_medusa_detach_ring(struct ndp_channel *channel) if (ctrl->hdr_buffer) { nfb_char_unregister_mmap(channel->ndp->nfb, ctrl->hdr_mmap_offset); - vunmap(ctrl->hdr_buffer_v); + vunmap(ctrl->ts.common.hdr_buffer_v); dma_free_coherent(dev, ctrl->hdr_buffer_size, ctrl->hdr_buffer, ctrl->hdr_buffer_phys); ctrl->hdr_buffer = NULL; } @@ -1084,7 +1082,7 @@ static void ndp_ctrl_calypte_detach_ring(struct ndp_channel *channel) if (ctrl->hdr_buffer) { nfb_char_unregister_mmap(channel->ndp->nfb, ctrl->hdr_mmap_offset); - vunmap(ctrl->hdr_buffer_v); + vunmap(ctrl->ts.common.hdr_buffer_v); dma_free_coherent(dev, ctrl->hdr_buffer_size, ctrl->hdr_buffer, ctrl->hdr_buffer_phys); ctrl->hdr_buffer = NULL; } From f31e0c9b543b036ef1b72093932b4571a37f340c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 May 2024 08:48:58 +0200 Subject: [PATCH 120/518] build: [FIX] add zlib-dev to gitlab-ci --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 50617eb2..1ebbdc1d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ pages: stage: deploy script: - apk add -U make doxygen musl-dev py3-setuptools - - apk add -U gcc cmake dtc-dev numactl-dev ncurses-dev libarchive-dev libconfig libconfig-dev automake autoconf curl git cython python3-dev dtc-dev linux-headers + - apk add -U gcc cmake dtc-dev numactl-dev ncurses-dev libarchive-dev libconfig libconfig-dev automake autoconf curl git cython python3-dev dtc-dev linux-headers zlib-dev - pip install -U sphinx - pip install -U sphinx-rtd-theme - pip install -U breathe From 6ff0191a2c4d9a228ff2b1f110611c65086eca71 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 May 2024 08:59:23 +0200 Subject: [PATCH 121/518] pynfb: [FIX] missing definition in libnetcope.pxd --- pynfb/nfb/libnetcope.pxd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pynfb/nfb/libnetcope.pxd b/pynfb/nfb/libnetcope.pxd index 76267986..356f8ac1 100644 --- a/pynfb/nfb/libnetcope.pxd +++ b/pynfb/nfb/libnetcope.pxd @@ -166,9 +166,11 @@ cdef extern from "": cdef struct nc_ndp_ctrl_start_params: dma_addr_t desc_buffer + dma_addr_t data_buffer; dma_addr_t hdr_buffer dma_addr_t update_buffer uint32_t *update_buffer_virt + uint32_t nb_data; uint32_t nb_desc uint32_t nb_hdr From caac00996ab2dac15f9e0fd1ea5dc18eb63185b7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 23 Oct 2023 12:42:06 +0200 Subject: [PATCH 122/518] build: enable gRPC extension if dependencies are installed --- ext/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index 9c4e37cd..6ac50d68 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -9,7 +9,10 @@ cmake_minimum_required(VERSION 3.12) cmake_policy(VERSION 3.12) -OPTION (LIB_GRPC "Add library for grpc" OFF) -if (LIB_GRPC) +find_program(_PROTOBUF_PROTOC protoc) +find_library(_GRPC_LIB grpc) +if (EXISTS ${_PROTOBUF_PROTOC} AND EXISTS ${_GRPC_LIB}) add_subdirectory(libnfb_ext_grpc) +else() + message(STATUS "library grpc or binary protoc not found, gRPC features disabled") endif() From 5dda16140a6d1840191a18e950f42d3d5c905a80 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 24 Jul 2023 10:17:45 +0200 Subject: [PATCH 123/518] libnfb-ext-grpc: [FIX] packaging --- CMakeLists.txt | 2 ++ ext/libnfb_ext_grpc/CMakeLists.txt | 10 +++++++++- package/PKGBUILD | 18 ++++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 544f3620..82003934 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,8 @@ set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/") set(CPACK_RPM_FILE_NAME RPM-DEFAULT) set(CPACK_RPM_Main_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") set(CPACK_RPM_DebugTools_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-debug") +set(CPACK_RPM_NfbExtGrpc_PACKAGE_NAME "nfb-ext-grpc") + # FIXME: use real Python version set(CPACK_RPM_python_PACKAGE_NAME "python3-nfb") set(CPACK_RPM_SPEC_MORE_DEFINE "%define __python python3") diff --git a/ext/libnfb_ext_grpc/CMakeLists.txt b/ext/libnfb_ext_grpc/CMakeLists.txt index bdc70004..acf387d1 100644 --- a/ext/libnfb_ext_grpc/CMakeLists.txt +++ b/ext/libnfb_ext_grpc/CMakeLists.txt @@ -77,10 +77,18 @@ set_target_properties(nfb-ext-grpc PROPERTIES OUTPUT_NAME nfb-ext-grpc VERSION ${GIT_VERSION} SOVERSION ${GIT_VERSION_MAJOR} + PUBLIC_HEADER ${PROTO_FILES} ) install(TARGETS nfb-ext-grpc + COMPONENT NfbExtGrpc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT DebugTools + PUBLIC_HEADER + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nfb/ext/protobuf/ +) + +install(TARGETS nfb-grpc-server + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT NfbExtGrpc ) diff --git a/package/PKGBUILD b/package/PKGBUILD index 066d8ce7..588d1099 100644 --- a/package/PKGBUILD +++ b/package/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Martin Spinler -pkgname=('nfb-framework' 'python-nfb') -pkgver=6.17.4 +pkgname=('nfb-framework' 'python-nfb' 'nfb-framework-debug' 'nfb-ext-grpc') +pkgver=6.19.5 pkgrel=1 pkgdesc="Software bundle for CESNET NDK firmware platform" url='https://github.com/CESNET/ndk-sw' @@ -11,6 +11,10 @@ source=("nfb-framework::git+https://github.com/CESNET/ndk-sw.git") #source=("nfb-framework"::"git+file://$HOME/ndk/swbase") md5sums=('SKIP') +depends=('dtc') +# grpc can be omitted, resulting in empty grpc package +makedepends=('grpc') + pkgver() { cat $srcdir/${pkgname}/VERSION } @@ -27,6 +31,16 @@ build() { package_nfb-framework() { DESTDIR="$pkgdir" cmake --install build --component Main } + +package_nfb-framework-debug() { + DESTDIR="$pkgdir" cmake --install build --component DebugTools +} + package_python-nfb() { DESTDIR="$pkgdir" cmake --install build --component python } + +package_nfb-ext-grpc() { + depends=('grpc') + DESTDIR="$pkgdir" cmake --install build --component NfbExtGrpc +} From ff89b97cda556f8ed2a34ac7f542f9bebbcc16d7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 10 May 2024 08:40:57 +0200 Subject: [PATCH 124/518] bump version to 6.22.3 --- Changelog | 5 +++++ VERSION | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 02f8f1bc..40b8ae0e 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +* Fri May 10 2024 Martin Spinler - 6.22.3-1 +- [BUGFIX] Debian packaging +- [BUGFIX] pynfb DMA fixes +- [BUGFIX] net driver fixes + * Fri Apr 5 2024 Martin Spinler - 6.22.1-1 - [BUGFIX] enable coexistence PMCI and SDM (read temperature on N6010) - [BUGFIX] check whole path string in libnfb for short path feature diff --git a/VERSION b/VERSION index 261151bf..f81896d2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.22.1 +6.22.3 From 4b49eff89978903d778b2ac694629b03dba67002 Mon Sep 17 00:00:00 2001 From: David Vodak Date: Mon, 13 May 2024 10:34:50 +0200 Subject: [PATCH 125/518] tool info: [FEATURE] query project-variant --- tools/info/info.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/info/info.c b/tools/info/info.c index ca84d985..37fa865a 100755 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -38,6 +38,7 @@ enum commands { // this enum need to corespond with queries[] array enum queries { QUERY_PROJECT, + QUERY_PROJECT_VARIANT, QUERY_PROJECT_VERSION, QUERY_BUILD, QUERY_RX, @@ -50,6 +51,7 @@ enum queries { }; static const char * const queries[] = { "project", + "project-variant", "project-version", "build", "rx", @@ -68,6 +70,7 @@ void usage(const char *progname, int verbose) printf("-q query Get specific informations%s\n", verbose ? "" : " (-v for more info)"); if (verbose) { printf(" * project Project name\n"); + printf(" * project-variant Project variant\n"); printf(" * project-version Project version\n"); printf(" * build Build time\n"); printf(" * rx RX queues\n"); @@ -112,6 +115,7 @@ int print_specific_info(struct nfb_device *dev, int query) /* FDT String properties */ switch (query) { case QUERY_PROJECT: prop = fdt_getprop(fdt, fdt_offset, "project-name", &len); break; + case QUERY_PROJECT_VARIANT: prop = fdt_getprop(fdt, fdt_offset, "project-variant", &len); break; case QUERY_PROJECT_VERSION: prop = fdt_getprop(fdt, fdt_offset, "project-version", &len); break; case QUERY_CARD: prop = fdt_getprop(fdt, fdt_offset, "card-name", &len); break; case QUERY_PCI: From 07cfc14ceb143b0021c99a74215ed16be3414ebc Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 30 May 2024 16:13:52 +0200 Subject: [PATCH 126/518] build: [FIX] set cmake Python FIND variables Set FIND_STRATEGY to LOCATION and FIND_UNVERSIONED_NAMES to FIRST. The LOCATION is set automatically for cmake_policy 3.15 This will use actual/system-default Python version for packaging. --- CMakeLists.txt | 4 ++-- drivers/CMakeLists.txt | 4 ++-- ext/CMakeLists.txt | 4 ++-- ext/libnfb_ext_grpc/CMakeLists.txt | 4 ++-- libnfb/CMakeLists.txt | 4 ++-- pynfb/CMakeLists.txt | 5 +++-- python/nfb-tools/CMakeLists.txt | 5 +++-- tools-debug/CMakeLists.txt | 4 ++-- tools-misc/CMakeLists.txt | 4 ++-- tools/CMakeLists.txt | 6 +++--- utils/CMakeLists.txt | 4 ++-- 11 files changed, 25 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82003934..fd5b4633 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,8 @@ # Martin Spinler # -cmake_minimum_required(VERSION 3.12) -cmake_policy(VERSION 3.12) +cmake_minimum_required(VERSION 3.15) +cmake_policy(VERSION 3.15) project(libnfb-ext-grpc C CXX) include(GNUInstallDirs) diff --git a/libnfb/CMakeLists.txt b/libnfb/CMakeLists.txt index a2ede570..f334cf0d 100644 --- a/libnfb/CMakeLists.txt +++ b/libnfb/CMakeLists.txt @@ -7,8 +7,8 @@ # Author(s): # Martin Spinler Date: Thu, 30 May 2024 10:58:33 +0200 Subject: [PATCH 127/518] drivers - boot PMCI: [FIX] break while loop even if serial number is not parsed --- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index 79de03a9..f771ad9c 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -359,10 +359,9 @@ int nfb_pmci_attach(struct nfb_boot *boot) pmci_bom_info[0] = '\n'; pmci_bom_info[PMCI_BOM_INFO_SIZE+1] = 0; pmci->m10bmc.ops.flash_read(&pmci->m10bmc, pmci_bom_info+1, PMCI_BOM_INFO_ADDR, PMCI_BOM_INFO_SIZE); - while ((snc = strstr(pmci_bom_info, "\nSN,"))) { + if ((snc = strstr(pmci_bom_info, "\nSN,"))) { if (sscanf(snc, "\nSN,%d\n", &sn) == 1) { boot->nfb->serial = sn; - break; } } kfree(pmci_bom_info); From 4b6567203a62025e7823f1bcf0941a7734fae608 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 30 May 2024 15:18:29 +0200 Subject: [PATCH 128/518] drivers: [FEATURE] allow card serial number to be string --- drivers/kernel/drivers/nfb/boot/boot.c | 6 +++++- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 11 ++++++++++- drivers/kernel/drivers/nfb/char.c | 3 +++ drivers/kernel/drivers/nfb/core.c | 2 ++ drivers/kernel/drivers/nfb/nfb.h | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index e950a982..13104f86 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -353,7 +353,11 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) fdt_offset = fdt_path_offset(nfb->fdt, "/board"); fdt_setprop_string(nfb->fdt, fdt_offset, "board-name", nfb->pci_name); - fdt_setprop_u32(nfb->fdt, fdt_offset, "serial-number", nfb->serial); + if (nfb->serial_str) { + fdt_setprop_string(nfb->fdt, fdt_offset, "serial-number-string", nfb->serial_str); + } else { + fdt_setprop_string(nfb->fdt, fdt_offset, "serial-number", nfb->serial); + } dev_info(&nfb->pci->dev, "nfb_boot: Attached successfully\n"); diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index f771ad9c..6e31c364 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -298,7 +298,7 @@ static struct regmap_config m10bmc_pmci_regmap_config = { int nfb_pmci_attach(struct nfb_boot *boot) { - char * pmci_bom_info, *snc; + char * pmci_bom_info, *snc, *snc_end; struct nfb_device *nfb = boot->nfb; struct pmci_device *pmci; @@ -362,6 +362,15 @@ int nfb_pmci_attach(struct nfb_boot *boot) if ((snc = strstr(pmci_bom_info, "\nSN,"))) { if (sscanf(snc, "\nSN,%d\n", &sn) == 1) { boot->nfb->serial = sn; + } else { + snc_end = strstr(snc+1, "\n"); + if (snc_end) { + snc_end[0] = 0; + snc += strlen("\nSN,"); + while (isspace(snc[0])) + snc += 1; + boot->nfb->serial_str = kstrdup(snc, GFP_KERNEL); + } } } kfree(pmci_bom_info); diff --git a/drivers/kernel/drivers/nfb/char.c b/drivers/kernel/drivers/nfb/char.c index 41452954..65179380 100644 --- a/drivers/kernel/drivers/nfb/char.c +++ b/drivers/kernel/drivers/nfb/char.c @@ -34,6 +34,9 @@ struct spinlock open_lock; static ssize_t nfb_char_get_serial(struct device *dev, struct device_attribute *attr, char *buf) { struct nfb_device *nfb = dev_get_drvdata(dev); + if (nfb->serial_str) { + return scnprintf(buf, PAGE_SIZE, "%s\n", nfb->serial_str); + } return scnprintf(buf, PAGE_SIZE, "%lld\n", nfb->serial); } static ssize_t nfb_char_get_cardname(struct device *dev, struct device_attribute *attr, char *buf) diff --git a/drivers/kernel/drivers/nfb/core.c b/drivers/kernel/drivers/nfb/core.c index cc112598..de5e8258 100644 --- a/drivers/kernel/drivers/nfb/core.c +++ b/drivers/kernel/drivers/nfb/core.c @@ -147,6 +147,8 @@ struct nfb_device *nfb_create(void) */ void nfb_destroy(struct nfb_device *nfb) { + if (nfb->serial_str) + kfree(nfb->serial_str); kfree(nfb); } diff --git a/drivers/kernel/drivers/nfb/nfb.h b/drivers/kernel/drivers/nfb/nfb.h index 25de4c71..be6a29fa 100644 --- a/drivers/kernel/drivers/nfb/nfb.h +++ b/drivers/kernel/drivers/nfb/nfb.h @@ -108,6 +108,7 @@ struct nfb_lock_item { struct nfb_device { struct pci_dev *pci; /* Associated PCI device (master) */ int minor; /* Minor number assigned to this device (used for X in /dev/nfbX) */ + const char *serial_str; /* String version of serial number. If is NULL, the 'serial' member should be used. */ uint64_t serial; /* Card serial number */ uint64_t dsn; /* FPGA chip unique identifier */ enum nfb_device_status status; From d3a980fb941136d0d908d7c9cc3c4b702a48bc1e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 30 May 2024 17:09:32 +0200 Subject: [PATCH 129/518] tool info: [FEATURE] allow card serial number to be string --- tools/info/info.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/info/info.c b/tools/info/info.c index 37fa865a..dfe23a21 100755 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -255,9 +255,14 @@ void print_common_info(struct nfb_device *dev, int verbose) if (len > 0) printf("Board name : %s\n", (const char *)prop); - prop32 = fdt_getprop(fdt, fdt_offset, "serial-number", &len); - if (len == sizeof(*prop32)) - printf("Serial number : %d\n", fdt32_to_cpu(*prop32)); + prop = fdt_getprop(fdt, fdt_offset, "serial-number-string", &len); + if (len > 0) { + printf("Serial number : %s\n", (const char *)prop); + } else { + prop32 = fdt_getprop(fdt, fdt_offset, "serial-number", &len); + if (len == sizeof(*prop32)) + printf("Serial number : %d\n", fdt32_to_cpu(*prop32)); + } prop64 = fdt_getprop(fdt, fdt_offset, "fpga-uid", &len); if (verbose > 1 && len == sizeof(*prop64)) From 0795a3686612c8238e55e3bbfdf582c39a9113b9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 4 Jun 2024 17:10:23 +0200 Subject: [PATCH 130/518] bump version to 6.22.4 --- Changelog | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 40b8ae0e..adfba44e 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +* Tue Jun 4 2024 Martin Spinler - 6.22.4-1 +- [FEATURE] allow non-numeric serial numbers +- [BUGFIX] fix driver freeze on N6010 with non-numeric serial number + * Fri May 10 2024 Martin Spinler - 6.22.3-1 - [BUGFIX] Debian packaging - [BUGFIX] pynfb DMA fixes diff --git a/VERSION b/VERSION index f81896d2..e5c55c9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.22.3 +6.22.4 From a949b22ffd8e6a37e90dfd554022c6d09d89ca5e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 5 Jun 2024 08:37:54 +0200 Subject: [PATCH 131/518] drivers - boot: [FIX] serial number conversion to DT --- drivers/kernel/drivers/nfb/boot/boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 13104f86..b5211bd6 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -356,7 +356,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) if (nfb->serial_str) { fdt_setprop_string(nfb->fdt, fdt_offset, "serial-number-string", nfb->serial_str); } else { - fdt_setprop_string(nfb->fdt, fdt_offset, "serial-number", nfb->serial); + fdt_setprop_u32(nfb->fdt, fdt_offset, "serial-number", nfb->serial); } dev_info(&nfb->pci->dev, "nfb_boot: Attached successfully\n"); From 6019ceb26d57bf238fbbf3513c4184ead091edb8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 5 Jun 2024 08:39:52 +0200 Subject: [PATCH 132/518] bump version to 6.22.5 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index adfba44e..5f04b72d 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Wed Jun 5 2024 Martin Spinler - 6.22.5-1 +- [BUGFIX] fix driver bug with numeric serial number + * Tue Jun 4 2024 Martin Spinler - 6.22.4-1 - [FEATURE] allow non-numeric serial numbers - [BUGFIX] fix driver freeze on N6010 with non-numeric serial number diff --git a/VERSION b/VERSION index e5c55c9e..092002f9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.22.4 +6.22.5 From 4a203f7556424c95ada3f8872a5217a33721aebe Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Jun 2024 21:33:32 +0200 Subject: [PATCH 133/518] drivers - boot: [FIX] add missing header for isspace --- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index 6e31c364..f658897d 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -23,6 +23,8 @@ #include #include +#include + #include "boot.h" #include "../nfb.h" #include "../pci.h" From fa834a8a61d7eac2814524e22c349e268e1c7416 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Fri, 7 Jun 2024 14:54:24 +0200 Subject: [PATCH 134/518] tool eth [BUGFIX]: Report Undefined PCS lane mapping for intel based Ethernet PHYs with activated RS-FEC --- tools/eth/pcspma.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/eth/pcspma.c b/tools/eth/pcspma.c index a1a1e3a9..e4b9edef 100644 --- a/tools/eth/pcspma.c +++ b/tools/eth/pcspma.c @@ -126,7 +126,7 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * uint32_t reg; uint32_t reg2; - int lines; + int lines, fec_lines = 0; uint32_t low_bits; int i, j; @@ -166,8 +166,8 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * } /* RS-FEC registers */ - lines = ieee802_3_get_fec_lines(active); - if ((lines > 0) && (pma_speed < 200000)) { /* RS-FEC Clause 91, 108 or 134 - RSFEC reg located in 1.200 - 1.300 */ + fec_lines = ieee802_3_get_fec_lines(active); + if ((fec_lines > 0) && (pma_speed < 200000)) { /* RS-FEC Clause 91, 108 or 134 - RSFEC reg located in 1.200 - 1.300 */ reg = nc_mdio_read_dword(mdio, portaddr, 1, 201); printf("RS-FEC status : %s%s%s\n", // reg & (1 << 0) ? "FEC bypass corection ability | " : "", @@ -179,19 +179,19 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * printf("RS-FEC uncorrected cws : %u\n", nc_mdio_read_dword(mdio, portaddr, 1, 204)); printf("RS-FEC symbol errors ->\n"); - for (i = 0; i < lines; i++) { + for (i = 0; i < fec_lines; i++) { printf(" * Lane %d : %u\n", i, nc_mdio_read_dword(mdio, portaddr, 1, 210 + i * 2)); } printf("RS-FEC lane mapping :"); reg = nc_mdio_read(mdio, portaddr, 1, 206); - for (i = 0; i < lines; i++) { + for (i = 0; i < fec_lines; i++) { printf(" %d", ((reg >> (i*2)) & 0x3)); } printf("\n"); reg = nc_mdio_read(mdio, portaddr, 1, 201); printf("RS-FEC AM lock :"); - for (i = 0; i < lines; i++) { + for (i = 0; i < fec_lines; i++) { printf((reg & (1 << (i + 8))) ? " L" : " X"); } printf("\n"); @@ -208,7 +208,7 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * printf("RS-FEC uncorrected cws : %u\n", nc_mdio_read_dword(mdio, portaddr, 3, 804)); printf("RS-FEC symbol errors ->\n"); - for (i = 0; i < lines; i++) { + for (i = 0; i < fec_lines; i++) { printf(" * Lane %d : %u\n", i, nc_mdio_read_dword(mdio, portaddr, 3, 600 + i * 2)); } } @@ -287,9 +287,16 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * } printf("\nLane mapping \n"); - // Lane mapping register for each line starting from -> 400 to 420 - for (i = 0; i < lines; i++) { - printf(" %2d", nc_mdio_read(mdio, portaddr, 3, 400 + i) & 0x3F); + if (((fec_lines > 0) && ((mdio -> pcspma_is_e_tile) || (mdio -> pcspma_is_f_tile)))) { + // Intel PCS/PMAs are not reporting PCS lane mapping when the RS-FEC is active + for (i = 0; i < lines; i++) { + printf(" U"); + } + } else { + // Lane mapping register for each line starting from -> 400 to 420 + for (i = 0; i < lines; i++) { + printf(" %2d", nc_mdio_read(mdio, portaddr, 3, 400 + i) & 0x3F); + } } // BIP counters not defined for speeds above 100 From b08dec02872dad750bbc5ec139bef026de8a3e99 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 27 Jun 2024 10:36:58 +0200 Subject: [PATCH 135/518] bump version to 6.22.6 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 5f04b72d..946cfa09 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Thu Jun 27 2024 Martin Spinler - 6.22.6-1 +- [BUGFIX] fix driver bug with include file + * Wed Jun 5 2024 Martin Spinler - 6.22.5-1 - [BUGFIX] fix driver bug with numeric serial number diff --git a/VERSION b/VERSION index 092002f9..4e8c9697 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.22.5 +6.22.6 From 0691eee1ecd60cd2dbaf8d07464e5f22db2a7533 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Wed, 26 Jun 2024 15:58:58 +0200 Subject: [PATCH 136/518] tool eth [BUGFIX]: Introduce nc_pcs_lane_map_valid() function to check if the lane map is valid --- libnfb/include/netcope/mdio.h | 31 +++++++++++++++++++++++++++++++ tools/eth/pcspma.c | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 1cc127c6..f37f3ecb 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -45,6 +45,14 @@ enum mdio_pma_enc { MDIO_PMA_ENC_PAM4 = 1, }; +enum mdio_fec_mode { + MDIO_FEC_NONE = 0, // No FEC + MDIO_FEC_FIRECODE = 1, // Firecode (CL 74) + MDIO_FEC_CL91 = 2, // RS(528,514) (Clause 91) + MDIO_FEC_CL134 = 3, // RS(544,514) (Clause 134) + MDIO_FEC_ETC = 4 // Ethernet Technology Consortium RS(272,258) +}; + struct nc_mdio { int (*mdio_read)(struct nfb_comp *dev, int prtad, int devad, uint16_t addr); int (*mdio_write)(struct nfb_comp *dev, int prtad, int devad, uint16_t addr, uint16_t val); @@ -52,6 +60,7 @@ struct nc_mdio { int pcspma_is_f_tile; int pma_lanes; /* Number of PMA lanes */ enum mdio_pma_enc link_encoding; /* Line modulation */ + enum mdio_fec_mode fec_mode; /* Firecode/Clause91/Clause134/ETC */ int speed; /* Speed in Gbps */ }; @@ -230,9 +239,22 @@ static inline struct nc_mdio *nc_mdio_open (const struct nfb_device *dev, int fd static inline void nc_mdio_close(struct nc_mdio *mdio); static inline int nc_mdio_read (struct nc_mdio *mdio, int prtad, int devad, uint16_t addr); static inline int nc_mdio_write(struct nc_mdio *mdio, int prtad, int devad, uint16_t addr, uint16_t val); +static inline int nc_pcs_lane_map_valid(struct nc_mdio *mdio); +static inline uint32_t nc_mdio_etile_rsfec_read(struct nfb_comp *comp, int prtad, uint32_t addr); /* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +/* Get PCS lane map validity */ +static inline int nc_pcs_lane_map_valid(struct nc_mdio *mdio) +{ + /* The PCS lane map is not valid on Intel E-Tile and F-Tile when the FEC is active */ + if (mdio->pcspma_is_e_tile || mdio->pcspma_is_f_tile) { + return (mdio->fec_mode == MDIO_FEC_NONE); + } else { + return 1; + } +} + /* Get F-tile EHIP configuration and fill corresponding fields in the nc_mdio structure */ static inline void nc_mdio_ftile_config(struct nc_mdio *mdio) { @@ -243,6 +265,7 @@ static inline void nc_mdio_ftile_config(struct nc_mdio *mdio) reg = nc_mdio_dmap_drp_read(comp, 0, 0, EHIP_CFG_REG); mdio->pma_lanes = ((reg >> 21) & 0xf); mdio->link_encoding = ((reg >> 9) & 0x1) ? MDIO_PMA_ENC_PAM4 : MDIO_PMA_ENC_NRZ; + mdio->fec_mode = ((reg >> 10) & 0x7); switch ((reg >> 5) & 0x7) { case 0: mdio->speed = 10; break; @@ -282,6 +305,12 @@ static inline void nc_mdio_etile_config(struct nc_mdio *mdio) mdio->pma_lanes = 0; mdio->speed = 0; } + /* Get FEC mode */ + /* The E-Tile supports RS-FEC according clause 91 only. The FEC is active */ + /* when bit 0 of the rsfec_top_rx_cfg register (0x14) is set */ + val = nc_mdio_etile_rsfec_read(comp, 0, 0x14); + mdio->fec_mode = ((val & 0x1) ? MDIO_FEC_CL91 : MDIO_FEC_NONE); + } static inline struct nc_mdio *nc_mdio_open(const struct nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam) @@ -1056,9 +1085,11 @@ static inline void nc_mdio_fixup_etile_set_mode(struct nc_mdio *mdio, int prtad, if ((val == 0x2a) || (val == 0x2b)) { /* 100GBASE-LR4/ER4 - turn the FEC off */ nc_mdio_etile_rsfec_off(comp, prtad, 4); + mdio->fec_mode = MDIO_FEC_NONE; } else if ((val == 0x2f) || (val == 0x2e)) { /* 100GBASE-SR4/CR4 - turn the FEC on */ nc_mdio_etile_rsfec_on(comp, prtad, 4); + mdio->fec_mode = MDIO_FEC_CL91; } /* Update the mode in HW Eth mgmt too */ mdio->mdio_write(comp, prtad, 1, 7, val); diff --git a/tools/eth/pcspma.c b/tools/eth/pcspma.c index e4b9edef..e80a977d 100644 --- a/tools/eth/pcspma.c +++ b/tools/eth/pcspma.c @@ -287,7 +287,7 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * } printf("\nLane mapping \n"); - if (((fec_lines > 0) && ((mdio -> pcspma_is_e_tile) || (mdio -> pcspma_is_f_tile)))) { + if (!nc_pcs_lane_map_valid(mdio)) { // Intel PCS/PMAs are not reporting PCS lane mapping when the RS-FEC is active for (i = 0; i < lines; i++) { printf(" U"); From 3f3234d89a59aa8a5f1049bc54d7789252d4910b Mon Sep 17 00:00:00 2001 From: Jakub Cabal Date: Thu, 11 Jul 2024 09:54:25 +0200 Subject: [PATCH 137/518] DOC: [MAINTENANCE] Add install guide to README.md file --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index b4842874..6095e82a 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,43 @@ The prebuilt RPM packages can be obtained via [Copr](https://copr.fedorainfraclo `sudo dnf install nfb-framework` +## Install guide + +We recommend using the Oracle Linux 8/9 operating system with Red Hat compatible kernel (RHCK), which we use for internal development. +Here is a [link to instructions on how to switch the default UEK kernel to the RHCK kernel on Oracle Linux](https://blogs.oracle.com/linux/post/changing-the-default-kernel-in-oracle-linux-its-as-simple-as-1-2-3). +For other operating systems, the installation procedure may be slightly different. + +1. First, you must enable the EPEL repositories that contain the required dependencies (libfdt-devel, etc.). + + Instructions for Oracle Linux 8: + + `sudo dnf config-manager -y --set-enabled ol8_codeready_builder` + + `sudo dnf install -y oracle-epel-release-el8` + + Instructions for Oracle Linux 9: + + `sudo dnf config-manager -y --set-enabled ol9_codeready_builder` + + `sudo dnf install -y oracle-epel-release-el9` + +2. Install the linux-headers package for your kernel. + + `sudo dnf install -y kernel-headers-$(uname -r)` + +3. Enable our COPR repository containing the necessary packages. + + `sudo dnf copr enable -y @CESNET/nfb-framework` + +4. Install the nfb-framework package, which contains NFB driver and SW tools. + + `sudo dnf install nfb-framework` + +5. Optionally, you can install a package containing the NFB Python API. + + `sudo dnf install python3-nfb` + + ## Build instructions 1. Clone the repository from GitHub. From bc9296666f7893caf10652537e0d7020c9e120e4 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 12:43:51 +0200 Subject: [PATCH 138/518] libnfb - MI bus: [MAINTENANCE] split nfb_bus_mi_memcopy to pre-inter-post --- libnfb/src/bus/mi.c | 107 +++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/libnfb/src/bus/mi.c b/libnfb/src/bus/mi.c index f7b710f5..20f2b17e 100644 --- a/libnfb/src/bus/mi.c +++ b/libnfb/src/bus/mi.c @@ -41,81 +41,91 @@ struct nfb_bus_mi_priv #define _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr) \ do { \ - if (nbyte == (size)) { \ + if (*nbyte == (size)) { \ if (wc_instr) \ - wc_used = true; \ - return wc_used; \ + *wc_used = true; \ + return true; \ } \ - (src) = (const mtype *) (src) + 1; \ - (dst) = (mtype *) (dst) + 1; \ - nbyte -= size; \ + *(src) = (const mtype *) *(src) + 1; \ + *(dst) = (mtype *) *(dst) + 1; \ + *nbyte -= (size); \ } while (0) #define _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, size, src, dst, mtype, load, store, wc_used, wc_instr) \ do { \ mtype tmp; \ - while (nbyte >= (size)) { \ - tmp = load(src); \ - store(dst, tmp); \ + while (*nbyte >= (size)) { \ + tmp = load(*(src)); \ + store(*(dst), tmp); \ _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ } \ } while (0) #define _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, size, src, dst, mtype, stream, wc_used, wc_instr) \ do { \ - while (nbyte >= (size)) { \ - stream(dst, *(const mtype *) src); \ + while (*nbyte >= (size)) { \ + stream(*(dst), *(const mtype *) *(src)); \ _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ } \ } while (0) #define _NFB_BUS_MI_MEMCPY_CYCLE_AS(nbyte, size, src, dst, mtype, wc_used, wc_instr) \ do { \ - while (nbyte >= (size)) { \ - *(mtype *) dst = *(const mtype *) src; \ + while (*nbyte >= (size)) { \ + *(mtype *) *(dst) = *(const mtype *) *(src); \ _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ } \ } while (0) -static inline bool nfb_bus_mi_memcopy(void *dst, const void *src, size_t nbyte, size_t offset) +static inline bool nfb_bus_mi_memcopy_simple(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) { - bool wc_used = false; + (void) offset; + (void) wc_used; if (nbyte == 4) { *(uint32_t *) dst = *(const uint32_t *) src; - return false; + return true; } else if (nbyte == 8) { *(uint64_t *) dst = *(const uint64_t *) src; - return false; + return true; } + return false; +} +static inline bool nfb_bus_mi_memcopy_prelude(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) +{ /* The offset variable is just for alignment check. The dst variable is alredy offseted. */ /* Align access on 4/8B boundary first */ - if (offset & 0x03) { - if (offset & 0x01 && nbyte >= 1) { - *(uint8_t *) dst = *(const uint8_t *) src; + if (*offset & 0x03) { + if (*offset & 0x01 && *nbyte >= 1) { + *(uint8_t *) *dst = *(const uint8_t *) *src; _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 1, src, dst, uint8_t, wc_used, false); - offset += 1; + *offset += 1; } - if (offset & 0x02 && nbyte >= 2) { - *(uint16_t *) dst = *(const uint16_t *) src; + if (*offset & 0x02 && *nbyte >= 2) { + *(uint16_t *) *dst = *(const uint16_t *) *src; _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 2, src, dst, uint16_t, wc_used, false); - offset += 2; + *offset += 2; } } - if (offset & 0x04 && nbyte >= 4) { - *(uint32_t *) dst = *(const uint32_t *) src; + if (*offset & 0x04 && *nbyte >= 4) { + *(uint32_t *) *dst = *(const uint32_t *) *src; _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 4, src, dst, uint32_t, wc_used, false); - offset += 4; + *offset += 4; } + return false; +} - bool src256a = ((uintptr_t) src & 0x1F) ? false : true; - bool dst256a = ((uintptr_t) dst & 0x1F) ? false : true; - bool src128a = ((uintptr_t) src & 0x0F) ? false : true; - bool dst128a = ((uintptr_t) dst & 0x0F) ? false : true; +static inline bool nfb_bus_mi_memcopy_interlude_avx_sse2(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) +{ + (void) offset; + bool src256a = ((uintptr_t) *src & 0x1F) ? false : true; + bool dst256a = ((uintptr_t) *dst & 0x1F) ? false : true; + bool src128a = ((uintptr_t) *src & 0x0F) ? false : true; + bool dst128a = ((uintptr_t) *dst & 0x0F) ? false : true; /* The _mm_stream* instructions are using the non-temporal hint. * The non-temporal hint is implemented by using a write combining (WC) memory type protocol. @@ -141,22 +151,45 @@ static inline bool nfb_bus_mi_memcopy(void *dst, const void *src, size_t nbyte, _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_loadu_si128, _mm_storeu_si128, wc_used, false); } + return false; +} + +static inline bool nfb_bus_mi_memcopy_postlude(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) +{ + (void) offset; + _NFB_BUS_MI_MEMCPY_CYCLE_AS(nbyte, 8, src, dst, uint64_t, wc_used, false); /* Access the remaining bytes */ - if (nbyte >= 4) { - *(uint32_t *) dst = *(const uint32_t *) src; + if (*nbyte >= 4) { + *(uint32_t *) *dst = *(const uint32_t *) *src; _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 4, src, dst, uint32_t, wc_used, false); } - if (nbyte >= 2) { - *(uint16_t *) dst = *(const uint16_t *) src; + if (*nbyte >= 2) { + *(uint16_t *) *dst = *(const uint16_t *) *src; _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 2, src, dst, uint16_t, wc_used, false); } - if (nbyte >= 1) { - *(uint8_t *) dst = *(const uint8_t *) src; + if (*nbyte >= 1) { + *(uint8_t *) *dst = *(const uint8_t *) *src; _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 1, src, dst, uint8_t, wc_used, false); } + return false; +} + +static inline bool nfb_bus_mi_memcopy(void *dst, const void *src, size_t nbyte, size_t offset) +{ + bool wc_used = false; + if (nfb_bus_mi_memcopy_simple(dst, src, nbyte, offset, &wc_used)) + return wc_used; + + if (nfb_bus_mi_memcopy_prelude(&dst, &src, &nbyte, &offset, &wc_used)) + return wc_used; + if (nfb_bus_mi_memcopy_interlude_avx_sse2(&dst, &src, &nbyte, &offset, &wc_used)) + return wc_used; + if (nfb_bus_mi_memcopy_postlude(&dst, &src, &nbyte, &offset, &wc_used)) + return wc_used; + return wc_used; } From a16ad37a2613bbc0cd110c0cda201f53fc037209 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 13:11:28 +0200 Subject: [PATCH 139/518] libnfb - MI BUS: [MAINTENANCE] nfb_bus_mi_memcopy - move wc_used to function parameters and return nbytes --- libnfb/src/bus/mi.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/libnfb/src/bus/mi.c b/libnfb/src/bus/mi.c index 20f2b17e..1d9522f2 100644 --- a/libnfb/src/bus/mi.c +++ b/libnfb/src/bus/mi.c @@ -177,38 +177,43 @@ static inline bool nfb_bus_mi_memcopy_postlude(void **dst, const void **src, siz return false; } -static inline bool nfb_bus_mi_memcopy(void *dst, const void *src, size_t nbyte, size_t offset) +static inline ssize_t nfb_bus_mi_memcopy(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) { - bool wc_used = false; - if (nfb_bus_mi_memcopy_simple(dst, src, nbyte, offset, &wc_used)) - return wc_used; + ssize_t ret = nbyte; + if (nfb_bus_mi_memcopy_simple(dst, src, nbyte, offset, wc_used)) + return ret; + + if (nfb_bus_mi_memcopy_prelude(&dst, &src, &nbyte, &offset, wc_used)) + return ret; + if (nfb_bus_mi_memcopy_interlude_avx_sse2(&dst, &src, &nbyte, &offset, wc_used)) + return ret; + if (nfb_bus_mi_memcopy_postlude(&dst, &src, &nbyte, &offset, wc_used)) + return ret; + + return ret; - if (nfb_bus_mi_memcopy_prelude(&dst, &src, &nbyte, &offset, &wc_used)) - return wc_used; - if (nfb_bus_mi_memcopy_interlude_avx_sse2(&dst, &src, &nbyte, &offset, &wc_used)) - return wc_used; - if (nfb_bus_mi_memcopy_postlude(&dst, &src, &nbyte, &offset, &wc_used)) - return wc_used; - return wc_used; } ssize_t nfb_bus_mi_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) { + ssize_t ret; + bool wc_used = false; struct nfb_bus_mi_priv *bus = bus_priv; - nfb_bus_mi_memcopy(buf, (uint8_t*) bus->space + offset, nbyte, offset); - return nbyte; + ret = nfb_bus_mi_memcopy(buf, (uint8_t*) bus->space + offset, nbyte, offset, &wc_used); + return ret; } ssize_t nfb_bus_mi_write(void *bus_priv, const void *buf, size_t nbyte, off_t offset) { - bool do_fence; + ssize_t ret; + bool wc_used = false; struct nfb_bus_mi_priv *bus = bus_priv; - do_fence = nfb_bus_mi_memcopy((uint8_t*) bus->space + offset, buf, nbyte, offset); + ret = nfb_bus_mi_memcopy((uint8_t*) bus->space + offset, buf, nbyte, offset, &wc_used); - if (bus->is_wc_mapped || do_fence) + if (bus->is_wc_mapped || wc_used) _mm_mfence(); - return nbyte; + return ret; } #define DRIVER_MI_PATH "/drivers/mi/" From 71e9711accbfd7e79e880f91adba719da7b2716d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 13:15:04 +0200 Subject: [PATCH 140/518] libnfb - MI bus: [MAINTENANCE] create nfb_bus_mi_memcopy templating system --- libnfb/src/bus/mi.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/libnfb/src/bus/mi.c b/libnfb/src/bus/mi.c index 1d9522f2..53c12c8b 100644 --- a/libnfb/src/bus/mi.c +++ b/libnfb/src/bus/mi.c @@ -78,6 +78,29 @@ do { \ } while (0) +#define __NFB_BUS_MI_MEMCOPY_TEMPLATE(impl) \ +static inline ssize_t _nfb_bus_mi_memcopy_rd_##impl(void *bus_priv, void *buf, size_t nbyte, off_t offset) \ +{ \ + ssize_t ret; \ + bool wc_used = false; \ + struct nfb_bus_mi_priv *bus = bus_priv; \ + ret = nfb_bus_mi_memcopy_##impl(buf, (uint8_t*) bus->space + offset, nbyte, offset, &wc_used); \ + return ret; \ +} \ +\ +static inline ssize_t _nfb_bus_mi_memcopy_wr_##impl(void *bus_priv, const void *buf, size_t nbyte, off_t offset) \ +{ \ + ssize_t ret; \ + bool wc_used = false; \ + struct nfb_bus_mi_priv *bus = bus_priv; \ + ret = nfb_bus_mi_memcopy_##impl((uint8_t*) bus->space + offset, buf, nbyte, offset, &wc_used); \ +\ + if (bus->is_wc_mapped || wc_used) \ + _mm_mfence(); \ + return ret; \ +} + + static inline bool nfb_bus_mi_memcopy_simple(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) { (void) offset; @@ -177,7 +200,7 @@ static inline bool nfb_bus_mi_memcopy_postlude(void **dst, const void **src, siz return false; } -static inline ssize_t nfb_bus_mi_memcopy(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) +static inline ssize_t nfb_bus_mi_memcopy_avx2_sse2(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) { ssize_t ret = nbyte; if (nfb_bus_mi_memcopy_simple(dst, src, nbyte, offset, wc_used)) @@ -195,25 +218,16 @@ static inline ssize_t nfb_bus_mi_memcopy(void *dst, const void *src, size_t nbyt } +__NFB_BUS_MI_MEMCOPY_TEMPLATE(avx2_sse2) + ssize_t nfb_bus_mi_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) { - ssize_t ret; - bool wc_used = false; - struct nfb_bus_mi_priv *bus = bus_priv; - ret = nfb_bus_mi_memcopy(buf, (uint8_t*) bus->space + offset, nbyte, offset, &wc_used); - return ret; + return _nfb_bus_mi_memcopy_rd_avx2_sse2(bus_priv, buf, nbyte, offset); } ssize_t nfb_bus_mi_write(void *bus_priv, const void *buf, size_t nbyte, off_t offset) { - ssize_t ret; - bool wc_used = false; - struct nfb_bus_mi_priv *bus = bus_priv; - ret = nfb_bus_mi_memcopy((uint8_t*) bus->space + offset, buf, nbyte, offset, &wc_used); - - if (bus->is_wc_mapped || wc_used) - _mm_mfence(); - return ret; + return _nfb_bus_mi_memcopy_wr_avx2_sse2(bus_priv, buf, nbyte, offset); } #define DRIVER_MI_PATH "/drivers/mi/" From 4a58eebfa0854b70901f96cd48ec5177c982bd43 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 14:19:56 +0200 Subject: [PATCH 141/518] libnfb - MI bus: [FIX] use optimized nfb_bus_mi_memcopy only for supported CPU --- libnfb/src/bus/mi.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/libnfb/src/bus/mi.c b/libnfb/src/bus/mi.c index 53c12c8b..03d1d8e4 100644 --- a/libnfb/src/bus/mi.c +++ b/libnfb/src/bus/mi.c @@ -214,11 +214,24 @@ static inline ssize_t nfb_bus_mi_memcopy_avx2_sse2(void *dst, const void *src, s return ret; return ret; +} +static inline ssize_t nfb_bus_mi_memcopy_noopt(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) +{ + ssize_t ret = nbyte; + if (nfb_bus_mi_memcopy_simple(dst, src, nbyte, offset, wc_used)) + return ret; + + if (nfb_bus_mi_memcopy_prelude(&dst, &src, &nbyte, &offset, wc_used)) + return ret; + if (nfb_bus_mi_memcopy_postlude(&dst, &src, &nbyte, &offset, wc_used)) + return ret; + return ret; } __NFB_BUS_MI_MEMCOPY_TEMPLATE(avx2_sse2) +__NFB_BUS_MI_MEMCOPY_TEMPLATE(noopt) ssize_t nfb_bus_mi_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) { @@ -295,8 +308,18 @@ int nfb_bus_open_mi(void *dev_priv, int bus_node, int comp_node, void **bus_priv } *bus_priv = bus; - ops->read = nfb_bus_mi_read; - ops->write = nfb_bus_mi_write; + + ops->read = _nfb_bus_mi_memcopy_rd_noopt; + ops->write = _nfb_bus_mi_memcopy_wr_noopt; + + if ( + __builtin_cpu_supports("avx") && + __builtin_cpu_supports("avx2") && + __builtin_cpu_supports("sse2") && + 1 ) { + ops->read = nfb_bus_mi_read; + ops->write = nfb_bus_mi_write; + } return 0; From 1334c042a16c707876db29f9680803161985c767 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 21:44:30 +0200 Subject: [PATCH 142/518] libnfb-ext-python: [FIX] fdt: double free The libnfb-extension must not dealloc the fdt buffer, this is responsibility of the libnfb itfself. --- ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx index 0dda8091..ae304180 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx +++ b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx @@ -45,7 +45,8 @@ cdef void nfb_ext_python_close(void *priv): _wrap = priv wrap = _wrap - free(wrap.fdt) + # The libnfb is responsible for freeing fdt + #free(wrap.fdt) Py_DECREF(wrap) cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset): From 4fe6ceb3736fb0cd81b3ae8ef5f272c804f56de9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 09:10:11 +0200 Subject: [PATCH 143/518] libnfb: [FEATURE] use LIBNFB_BUS_DEBUG environment variable for bus access debugging --- libnfb/src/nfb.c | 31 ++++++++++++++++--------------- libnfb/src/nfb.h | 1 + 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libnfb/src/nfb.c b/libnfb/src/nfb.c index 8ab27dde..2d727a88 100644 --- a/libnfb/src/nfb.c +++ b/libnfb/src/nfb.c @@ -370,9 +370,13 @@ int nfb_bus_open(struct nfb_comp *comp, int fdt_offset, int comp_offset) comp->bus.type = 0; ret = comp->dev->ops.bus_open_mi(comp->dev->priv, fdt_offset, comp_offset, &comp->bus.priv, &comp->bus.ops); + + if (getenv("LIBNFB_BUS_DEBUG")) + comp->bus_debug = 1; + /* INFO: Shortcut only for direct access MI bus (into PCI BAR): speed optimization * uses direct call to nfb_bus_mi_read/write in nfb_comp_read/write */ - if (comp->bus.ops.read == nfb_bus_mi_read) + if (comp->bus.ops.read == nfb_bus_mi_read && comp->bus_debug == 0) comp->bus.type = NFB_BUS_TYPE_MI; return ret; @@ -419,6 +423,7 @@ struct nfb_comp *nfb_comp_open_ext(const struct nfb_device *dev, int fdt_offset, comp->dev = dev; comp->base = fdt32_to_cpu(prop[0]); comp->size = fdt32_to_cpu(prop[1]); + comp->bus_debug = 0; comp->path = user_size + (char*)(comp + 1); strcpy(comp->path, path); @@ -516,9 +521,6 @@ const struct nfb_device *nfb_comp_get_device(struct nfb_comp *comp) return comp->dev; } -//#define NFB_DEBUG_MI - -#ifdef NFB_DEBUG_MI static void nfb_bus_mi_dump(const char *type, const void *buf, size_t nbyte, off_t offset) { size_t i; @@ -537,7 +539,6 @@ static void nfb_bus_mi_dump(const char *type, const void *buf, size_t nbyte, off } } -#endif ssize_t nfb_comp_read(const struct nfb_comp *comp, void *buf, size_t nbyte, off_t offset) { @@ -549,27 +550,27 @@ ssize_t nfb_comp_read(const struct nfb_comp *comp, void *buf, size_t nbyte, off_ ret = nfb_bus_mi_read(comp->bus.priv, buf, nbyte, offset + comp->base); } else { ret = comp->bus.ops.read(comp->bus.priv, buf, nbyte, offset + comp->base); - } -#ifdef NFB_DEBUG_MI - nfb_bus_mi_dump("Read ", buf, nbyte, offset); -#endif + if (comp->bus_debug) + nfb_bus_mi_dump("Read ", buf, nbyte, offset + comp->base); + } return ret; } ssize_t nfb_comp_write(const struct nfb_comp *comp, const void *buf, size_t nbyte, off_t offset) { + ssize_t ret; if (offset + nbyte > comp->size) return -1; -#ifdef NFB_DEBUG_MI - nfb_bus_mi_dump("Write", buf, nbyte, offset); -#endif - if (comp->bus.type == NFB_BUS_TYPE_MI) { - return nfb_bus_mi_write(comp->bus.priv, buf, nbyte, offset + comp->base); + ret = nfb_bus_mi_write(comp->bus.priv, buf, nbyte, offset + comp->base); } else { - return comp->bus.ops.write(comp->bus.priv, buf, nbyte, offset + comp->base); + ret = comp->bus.ops.write(comp->bus.priv, buf, nbyte, offset + comp->base); + if (comp->bus_debug) + nfb_bus_mi_dump("Write", buf, nbyte, offset + comp->base); } + + return ret; } diff --git a/libnfb/src/nfb.h b/libnfb/src/nfb.h index 3785a761..b0ad8502 100644 --- a/libnfb/src/nfb.h +++ b/libnfb/src/nfb.h @@ -52,6 +52,7 @@ struct nfb_comp { char *path; /*!< Component's path in the Device Tree */ off_t base; /*!< Component's offset in the bus address space */ size_t size; /*!< Component's size in the bus address space */ + int bus_debug; }; From 5c6b5802cd218710e9b0c6a2bfb26727f37121cb Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 08:15:33 +0200 Subject: [PATCH 144/518] libnetcope - mdio: [MAINTENANCE] rename nc_pcs_lane_map_valid to nc_mdio_pcs_lane_map_valid --- libnfb/include/netcope/mdio.h | 4 ++-- tools/eth/pcspma.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index f37f3ecb..9b1093f4 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -239,13 +239,13 @@ static inline struct nc_mdio *nc_mdio_open (const struct nfb_device *dev, int fd static inline void nc_mdio_close(struct nc_mdio *mdio); static inline int nc_mdio_read (struct nc_mdio *mdio, int prtad, int devad, uint16_t addr); static inline int nc_mdio_write(struct nc_mdio *mdio, int prtad, int devad, uint16_t addr, uint16_t val); -static inline int nc_pcs_lane_map_valid(struct nc_mdio *mdio); +static inline int nc_mdio_pcs_lane_map_valid(struct nc_mdio *mdio); static inline uint32_t nc_mdio_etile_rsfec_read(struct nfb_comp *comp, int prtad, uint32_t addr); /* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* Get PCS lane map validity */ -static inline int nc_pcs_lane_map_valid(struct nc_mdio *mdio) +static inline int nc_mdio_pcs_lane_map_valid(struct nc_mdio *mdio) { /* The PCS lane map is not valid on Intel E-Tile and F-Tile when the FEC is active */ if (mdio->pcspma_is_e_tile || mdio->pcspma_is_f_tile) { diff --git a/tools/eth/pcspma.c b/tools/eth/pcspma.c index e80a977d..c87a257e 100644 --- a/tools/eth/pcspma.c +++ b/tools/eth/pcspma.c @@ -287,7 +287,7 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * } printf("\nLane mapping \n"); - if (!nc_pcs_lane_map_valid(mdio)) { + if (!nc_mdio_pcs_lane_map_valid(mdio)) { // Intel PCS/PMAs are not reporting PCS lane mapping when the RS-FEC is active for (i = 0; i < lines; i++) { printf(" U"); From 1aa13a61f67fca32ccea6f208eba67d14ac1f3c8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 08:18:03 +0200 Subject: [PATCH 145/518] libnetcope - mdio: [MAINTENANCE] remove nc_mdio_etile_rsfec_read from public API --- libnfb/include/netcope/mdio.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 9b1093f4..928224f2 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -240,7 +240,6 @@ static inline void nc_mdio_close(struct nc_mdio *mdio); static inline int nc_mdio_read (struct nc_mdio *mdio, int prtad, int devad, uint16_t addr); static inline int nc_mdio_write(struct nc_mdio *mdio, int prtad, int devad, uint16_t addr, uint16_t val); static inline int nc_mdio_pcs_lane_map_valid(struct nc_mdio *mdio); -static inline uint32_t nc_mdio_etile_rsfec_read(struct nfb_comp *comp, int prtad, uint32_t addr); /* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -279,6 +278,8 @@ static inline void nc_mdio_ftile_config(struct nc_mdio *mdio) } } +static inline uint32_t nc_mdio_etile_rsfec_read(struct nfb_comp *comp, int prtad, uint32_t addr); + /* Get E-tile Ethernet configuration and fill corresponding fields in the nc_mdio structure */ static inline void nc_mdio_etile_config(struct nc_mdio *mdio) { From 63d4ec8dd2c6b999f8ff8f0043f4ec82fbd44b24 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 08:05:46 +0200 Subject: [PATCH 146/518] libnetcope - mdio: [MAINTENANCE] split nc_mdio_open to nc_mdio_open_no_init and nc_mdio_init User can defer the configuration accesses to the latest moment. --- libnfb/include/netcope/mdio.h | 70 +++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 928224f2..d2be4d0a 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -236,6 +236,8 @@ static inline uint32_t _ftile_pcs_base(int speed) /* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ static inline struct nc_mdio *nc_mdio_open (const struct nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam); +static inline struct nc_mdio *nc_mdio_open_no_init(const struct nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam); +static inline void nc_mdio_init(struct nc_mdio *mdio); static inline void nc_mdio_close(struct nc_mdio *mdio); static inline int nc_mdio_read (struct nc_mdio *mdio, int prtad, int devad, uint16_t addr); static inline int nc_mdio_write(struct nc_mdio *mdio, int prtad, int devad, uint16_t addr, uint16_t val); @@ -314,53 +316,57 @@ static inline void nc_mdio_etile_config(struct nc_mdio *mdio) } -static inline struct nc_mdio *nc_mdio_open(const struct nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam) +static inline struct nc_mdio *nc_mdio_open_no_init(const struct nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam) { + struct nc_mdio mdio_tmp; struct nc_mdio *mdio; struct nfb_comp *comp; const char *prop; int proplen = 0; - int e_tile = 0; - int f_tile = 0; + + if (0) { + } else if ((comp = nc_mdio_ctrl_open_ext(dev, fdt_offset, sizeof(struct nc_mdio)))) { + mdio_tmp.mdio_read = nc_mdio_ctrl_read; + mdio_tmp.mdio_write = nc_mdio_ctrl_write; + } else if ((comp = nc_mdio_dmap_open_ext(dev, fdt_offset, sizeof(struct nc_mdio)))) { + mdio_tmp.mdio_read = nc_mdio_dmap_read; + mdio_tmp.mdio_write = nc_mdio_dmap_write; + } else { + return NULL; + } + + mdio = (struct nc_mdio *) nfb_comp_to_user(comp); + *mdio = mdio_tmp; prop = (const char*) fdt_getprop(nfb_get_fdt(dev), fdt_offset_ctrlparam, "ip-name", &proplen); if (proplen > 0) { if (strcmp(prop, "E_TILE") == 0) { - e_tile = 1; + mdio->pcspma_is_e_tile = 1; } else if (strcmp(prop, "F_TILE") == 0) { - f_tile = 1; + mdio->pcspma_is_f_tile = 1; } } - comp = nc_mdio_ctrl_open_ext(dev, fdt_offset, sizeof(struct nc_mdio)); - if (comp) { - mdio = (struct nc_mdio *) nfb_comp_to_user(comp); - mdio->mdio_read = nc_mdio_ctrl_read; - mdio->mdio_write = nc_mdio_ctrl_write; - mdio->pcspma_is_e_tile = e_tile; - mdio->pcspma_is_f_tile = f_tile; - if (f_tile) - nc_mdio_ftile_config(mdio); - if (e_tile) - nc_mdio_etile_config(mdio); - return mdio; - } + return mdio; +} - comp = nc_mdio_dmap_open_ext(dev, fdt_offset, sizeof(struct nc_mdio)); - if (comp) { - mdio = (struct nc_mdio *) nfb_comp_to_user(comp); - mdio->mdio_read = nc_mdio_dmap_read; - mdio->mdio_write = nc_mdio_dmap_write; - mdio->pcspma_is_e_tile = e_tile; - mdio->pcspma_is_f_tile = f_tile; - if (f_tile) - nc_mdio_ftile_config(mdio); - if (e_tile) - nc_mdio_etile_config(mdio); - return mdio; - } +static inline void nc_mdio_init(struct nc_mdio *mdio) +{ + if (mdio->pcspma_is_f_tile) + nc_mdio_ftile_config(mdio); + if (mdio->pcspma_is_e_tile) + nc_mdio_etile_config(mdio); +} + +static inline struct nc_mdio *nc_mdio_open(const struct nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam) +{ + struct nc_mdio *mdio; + mdio = nc_mdio_open_no_init(dev, fdt_offset, fdt_offset_ctrlparam); + if (mdio == NULL) + return NULL; - return NULL; + nc_mdio_init(mdio); + return mdio; } static inline void nc_mdio_ftile_reset(struct nc_mdio *mdio, int prtad, int rx, int enable) From 4e623a215d2800f99a0da2e5d6231059b26e2251 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 18 Jul 2024 08:35:03 +0200 Subject: [PATCH 147/518] pynfb: [OPT] initialize Mdio only if neccessary This avoids configuration accesses on Nfb device initialization. --- pynfb/nfb/libnetcope.pxd | 4 +++- pynfb/nfb/libnetcope.pyx | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pynfb/nfb/libnetcope.pxd b/pynfb/nfb/libnetcope.pxd index 356f8ac1..b89e28c8 100644 --- a/pynfb/nfb/libnetcope.pxd +++ b/pynfb/nfb/libnetcope.pxd @@ -105,7 +105,9 @@ cdef extern from "": cdef struct nc_mdio: pass - nc_mdio *nc_mdio_open (const nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam); + nc_mdio *nc_mdio_open(const nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam); + nc_mdio *nc_mdio_open_no_init(const nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam); + void nc_mdio_init(nc_mdio *mdio); void nc_mdio_close(nc_mdio *mdio); int nc_mdio_read (nc_mdio *mdio, int prtad, int devad, uint16_t addr); int nc_mdio_write(nc_mdio *mdio, int prtad, int devad, uint16_t addr, uint16_t val); diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 66558b5f..576d9527 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -166,11 +166,13 @@ cdef class TxMac: cdef class Mdio: cdef NfbDeviceHandle _handle cdef nc_mdio *_mdio + cdef bool _inited def __init__(self, libnfb.Nfb nfb, node, param_node = None): self._handle = nfb._handle self._mdio = NULL - self._mdio = nc_mdio_open(self._handle._dev, nfb._fdt_path_offset(node), nfb._fdt_path_offset(param_node) if param_node else -1) + self._mdio = nc_mdio_open_no_init(self._handle._dev, nfb._fdt_path_offset(node), nfb._fdt_path_offset(param_node) if param_node else -1) + self._inited = False if self._mdio is NULL: PyErr_SetFromErrno(OSError) @@ -178,10 +180,17 @@ cdef class Mdio: if self._mdio is not NULL: nc_mdio_close(self._mdio) + def _init(self): + if not self._inited: + self._inited = True + nc_mdio_init(self._mdio) + def read(self, devad: int, reg: int, prtad: int=0): + self._init() return nc_mdio_read(self._mdio, prtad, devad, reg) def write(self, devad: int, reg: int, val: int, prtad: int=0): + self._init() nc_mdio_write(self._mdio, prtad, devad, reg, val) cdef class I2c: From 3364228f621e2fe9ea0c3d52752818d26f879e6e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 19 Jul 2024 07:37:30 +0200 Subject: [PATCH 148/518] pynfb: [OPT] use nc_rxmac_get_link for link state check in RxMac --- pynfb/nfb/libnetcope.pxd | 1 + pynfb/nfb/libnetcope.pyx | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pynfb/nfb/libnetcope.pxd b/pynfb/nfb/libnetcope.pxd index b89e28c8..1923cdfa 100644 --- a/pynfb/nfb/libnetcope.pxd +++ b/pynfb/nfb/libnetcope.pxd @@ -72,6 +72,7 @@ cdef extern from "": void nc_rxmac_close(nc_rxmac *mac); void nc_rxmac_enable(nc_rxmac *mac); void nc_rxmac_disable(nc_rxmac *mac); + int nc_rxmac_get_link(nc_rxmac *mac); int nc_rxmac_read_status(nc_rxmac *mac, nc_rxmac_status *status); int nc_rxmac_read_counters(nc_rxmac *mac, nc_rxmac_counters *counters, nc_rxmac_etherstats *stats); int nc_rxmac_reset_counters(nc_rxmac *mac); diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 576d9527..3fad6b35 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -31,9 +31,7 @@ cdef class RxMac: @property def link(self): - cdef nc_rxmac_status status - assert nc_rxmac_read_status(self._mac, &status) == 0 - return True if status.link_up else False + return False if nc_rxmac_get_link(self._mac) == 0 else True @property def enabled(self): From 71721b6dc37a03a795663390ea5917af58e85b81 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 22 Jul 2024 16:54:42 +0200 Subject: [PATCH 149/518] build - Jenkins tests: [FIX] disable CentOS7 due to EOL --- jenkins/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 30c4f742..cd83de91 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -1,6 +1,6 @@ def projectpath = "ndk/swbase" def osreleasevers = [ - ["centos", "centos7", "7.9.2009", "rpm"], +// ["centos", "centos7", "7.9.2009", "rpm"], ["oraclelinux", "oraclelinux8", "8", "rpm"], ["ubuntu", "ubuntu", "focal", "deb"] ] From 449e3118a2275a1828443b640d30ef728f2fa2cc Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 22 Jul 2024 16:43:05 +0200 Subject: [PATCH 150/518] libnetcope - nccommon: [FIX] initial declaration in for --- libnfb/include/netcope/nccommon.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libnfb/include/netcope/nccommon.h b/libnfb/include/netcope/nccommon.h index f90d7d59..dcd491cb 100644 --- a/libnfb/include/netcope/nccommon.h +++ b/libnfb/include/netcope/nccommon.h @@ -228,6 +228,7 @@ static inline int list_range_empty(struct list_range *lr) static inline int nc_query_parse(const char *query, const char* const* choices, int size, char **index) { + int i; int len; char hit; char *query_act, *query_orig; @@ -243,7 +244,7 @@ static inline int nc_query_parse(const char *query, const char* const* choices, len = strchr(query_act,',') ? (strchr(query_act,',') - query_act) : 0; if (len) query_act[len] = '\0'; - for (int i=0; i Date: Tue, 16 Jan 2024 07:24:50 +0100 Subject: [PATCH 151/518] tools - mi-test: [FEATURE] add tool for testing MI bus --- tools-debug/CMakeLists.txt | 7 +- tools-debug/nfb-mi-test/mi-test-plot.py | 35 ++ tools-debug/nfb-mi-test/nfb-mi-test.c | 577 ++++++++++++++++++++++++ 3 files changed, 618 insertions(+), 1 deletion(-) create mode 100644 tools-debug/nfb-mi-test/mi-test-plot.py create mode 100644 tools-debug/nfb-mi-test/nfb-mi-test.c diff --git a/tools-debug/CMakeLists.txt b/tools-debug/CMakeLists.txt index a0806204..acbaef73 100644 --- a/tools-debug/CMakeLists.txt +++ b/tools-debug/CMakeLists.txt @@ -23,8 +23,13 @@ add_executable(nfb-busdebugctl busdebugctl/busdebugctl.c) add_executable(nfb-busdump busdump/busdump.c) add_executable(nfb-busreplay busreplay/busreplay.c) add_executable(nfb-xvc nfb-xvc/xvc_pcie.c nfb-xvc/xvcserver.c) +add_executable(nfb-mi-test nfb-mi-test/nfb-mi-test.c) -set (PIE_TARGETS nfb-busdebugctl nfb-busdump nfb-busreplay nfb-xvc) +set_source_files_properties(nfb-mi-test/nfb-mi-test.c PROPERTIES COMPILE_FLAGS -mavx2) + + + +set (PIE_TARGETS nfb-busdebugctl nfb-busdump nfb-busreplay nfb-xvc nfb-mi-test) if (${LIBPCI_FOUND}) target_compile_definitions(nfb-xvc PUBLIC USE_LIBPCI) diff --git a/tools-debug/nfb-mi-test/mi-test-plot.py b/tools-debug/nfb-mi-test/mi-test-plot.py new file mode 100644 index 00000000..719b5715 --- /dev/null +++ b/tools-debug/nfb-mi-test/mi-test-plot.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import plotly.express as px +import plotly.graph_objects as go + +import pandas as pd + +names = ['length', 'src_offset', 'dst_offset', 'throughput'] + +#data = pd.read_csv('mi-test.csv', names=names) +#fig = px.line_3d(data, x='length', y='src_offset', z='throughput', color='dst_offset', title='MI Bandwidth') +#fig.update_scenes(camera_projection_type='orthographic') + +fig = go.Figure() +files = { + "MI write": "mi-test-wr.csv", + "MI read": "mi-test-rd.csv", + "MI write+read": "mi-test.csv", +} +for name, csv in files.items(): + fig.add_traces( + px.line(pd.read_csv(csv, names=names), x="length", y="throughput") + .update_traces(line_color=None, showlegend=True, name=name) + .data + ) + +fig.update_layout( + title={ + 'text': 'MI performance test', + 'xanchor': 'center', + 'x': 0.5, + }, xaxis_title="MI transaction length [B]", yaxis_title="Throughput [MBps]") + +fig.write_image("mi-test.png", width=1024, height=768) +#fig.show() diff --git a/tools-debug/nfb-mi-test/nfb-mi-test.c b/tools-debug/nfb-mi-test/nfb-mi-test.c new file mode 100644 index 00000000..3ea08beb --- /dev/null +++ b/tools-debug/nfb-mi-test/nfb-mi-test.c @@ -0,0 +1,577 @@ +/* + * MI test tool + * + * Copyright (C) CESNET, 2024 + * Author(s): + * Martin Spinler + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#define DATA_SIZE 8192 +//#define DATA_SIZE 128 + +char data1[DATA_SIZE]; +char data2[DATA_SIZE]; +char datar[DATA_SIZE]; +__m256i datam[DATA_SIZE/32]; + +struct timespec start, stop; + +struct mi_test_params { + struct nfb_comp * comp; + int verbose; + int trans_mask; /* 1 -> write, 2 -> read, 3 -> write + read */ + unsigned mi_off_min; + unsigned mi_off_max; + unsigned long long transaction_count; + unsigned long long iteration_count; + + struct list_range length_range; + struct list_range addr_range; + struct list_range src_off_range; + struct list_range dst_off_range; +}; + +void mstart() { + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); +} + +double mstop() { + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop); + double result = (stop.tv_sec - start.tv_sec) * 1e6 + (stop.tv_nsec - start.tv_nsec) / 1e3; + return result; +} + +void randomize_data(void) +{ + int i; + + srand(time(NULL)); + for (i = 0; i < DATA_SIZE; i++) { + data1[i] = rand(); + data2[i] = rand(); + } + memcpy(datam, data1, sizeof(datam)); +} + +enum commands { + CMD_USAGE, + CMD_TEST_RANDOM, + CMD_TEST_LINEAR, + CMD_TEST_PERFORMANCE, +}; + +#define ARGUMENTS "Cc:d:t:l:R:S:D:T:I:rwhv" + +void usage(const char *progname) +{ + printf("Usage: %s [-hv] [-d path]\n", progname); + printf("-d path Path to device [default: %s]\n", NFB_PATH_DEV(0)); + printf("-c compatible Compatible string of component to use in test\n"); + printf("-t test Select test: random, linear, performance [default: random]\n"); + printf("-r Use only reads\n"); + printf("-w Use only writes\n"); + printf("-l length Use specified length (can be range)\n"); + printf("-T count Transaction count\n"); + printf("-I count Iteration count\n"); + printf("-C CSV output (for performance test)\n"); + printf("-R range Use specified address space range (min-max) [default: all]\n"); + printf("-S range Use specified RAM offset range [default: 0]\n"); + printf("-D range Use specified MI offset range [default: 0]\n"); + printf("-h Show this text\n"); + printf("-v Increase verbosity\n"); +} + +void print_transaction(int type, unsigned off_mi, unsigned off_ram, unsigned size, uint8_t *data, double speed) +{ + int j; + char * dir = (type == 3 ? "W+R" : (type == 2 ? "R/O" : (type == 1 ? "W/O": "-/-"))); + printf("Transaction: %s, MI offset: %04x, RAM offset: %04x, length: % 4d B", dir, off_mi, off_ram, size); + if (speed) + printf(", speed: % 14.4lf MBps", speed); + if (data) { + printf(" | "); + for (j = off_mi; j < off_mi + size; j++) { + printf("%02x ", data[j]); + } + } + printf("\n"); +} + +void print_stats(double time, uint64_t count, uint64_t bytes) +{ + printf("Total time: %f s, transactions: %llu, bytes: %llu, average speed: %.3lf MBps\n", + time / 1000000, count, bytes, ((double)bytes)/time); +} + +int check_integrity(uint8_t*src, uint8_t*dst, int off_mi, int off_ram, int size) +{ + if (memcmp(src, dst, size)) { + fprintf(stderr, "Read failed: MI offset %04x, RAM offset: %04x, length: % 4d\n", off_mi, off_ram, size); + return 1; + } + return 0; +} + +int do_test_random(struct mi_test_params *p) +{ + int ret = 0; + unsigned int rseed = 15451; + int rnd; + const unsigned long long TRANSACTION_COUNT = p->transaction_count == 0 ? 100000 : p->transaction_count; + unsigned long long i; + + unsigned long long bytes = 0; + unsigned long long duals = 0; + + double time; + + const int space = p->mi_off_max - p->mi_off_min; + + + int size, addr, trans; + + char *data; + + mstart(); + for (i = 0; i < TRANSACTION_COUNT; i++) { + rnd = nc_fast_rand(&rseed); + + data = (rnd % 2) == 0 ? data1 : data2; + rnd /= 2; + + trans = (rnd % 3) + 1; + rnd /= 4; + + addr = rnd % space; + + rnd = nc_fast_rand(&rseed); + + size = (rnd % (space - addr)) + 1; + + trans &= p->trans_mask; + if (trans == 0) + trans = p->trans_mask; + + if (trans & 1) + nfb_comp_write(p->comp, &data[addr], size, p->mi_off_min + addr); + + if (trans & 2) + nfb_comp_read(p->comp, &datar[addr], size, p->mi_off_min + addr); + + bytes += size; + + if (trans == 3) { + duals += 1; + ret |= check_integrity(data + addr, datar + addr, p->mi_off_min + addr, addr, size); + } + + if (p->verbose > 1) { + print_transaction(trans, p->mi_off_min + addr, addr, size, p->verbose > 2 ? &data[addr] : NULL, 0); + } + } + + time = mstop(); + + if (p->verbose > 0) { + print_stats(time, TRANSACTION_COUNT + duals, bytes); + } + return ret; +} + +void performance_test_single(struct mi_test_params *p, struct nfb_comp *comp, int verb, int count, int size, int src_off, int dst_off, double *time, uint64_t *transactions, uint64_t *bytes) +{ + int i; + int trans = p->trans_mask; + + double throughput; + char *data; + + data = (char*) datam; + data += src_off; + + mstart(); + for (i = 0; i < count; i++) { + if (trans & 1) + nfb_comp_write(comp, data, size, dst_off); + + if (trans & 2) + nfb_comp_read(comp, datar, size, dst_off); + } + *time = mstop(); + + *transactions = count; + *bytes = count * (uint64_t) size; + if (trans == 3) { + *transactions *= 2; + *bytes *= 2; + } + + throughput = ((double)*bytes) / *time; + + if (verb > 1) { + print_transaction(trans, dst_off, src_off, size, verb > 2 ? data : NULL, throughput); + } else if (verb == -1) { + printf("% 4d, % 3d, % 3d, % 11lf\n", size, dst_off, src_off, throughput); + } +} + +void do_test_performance(struct mi_test_params *p) +{ + const uint8_t src_offs[] = {0}; + const uint8_t dst_offs[] = {0}; + + uint64_t it = 0; + double time = 0; + uint64_t transactions = 0; + uint64_t bytes = 0; + + double otime = 0; + + double ptime; + uint64_t ptransactions; + uint64_t pbytes; + const int PI = 0 /* + 1000 */; + int doi, soi, len; + int src_off, dst_off; + + unsigned max_size = p->mi_off_max - p->mi_off_min; + + if (list_range_empty(&p->length_range)) + list_range_add_range(&p->length_range, 1, 256); + + if (list_range_empty(&p->src_off_range)) + list_range_add_number(&p->src_off_range, 0); + + if (list_range_empty(&p->dst_off_range)) + list_range_add_number(&p->dst_off_range, 0); + + + it = p->iteration_count == 0 ? 100000 : p->iteration_count; + + for (doi = 0; doi <= 32/*sizeof(dst_offs)*/; doi++) { + if (!list_range_contains(&p->dst_off_range, doi)) + continue; + + for (soi = 0; soi <= 32/*sizeof(src_offs)*/; soi++) { + if (!list_range_contains(&p->src_off_range, soi)) + continue; + + for (len = 1; len <= max_size; len++) { + if (!list_range_contains(&p->length_range, len)) + continue; + + if (PI) { + it = PI; + /* first probe test duration */ + performance_test_single(p, p->comp, 0, it, len, 0, 0, &ptime, &ptransactions, &pbytes); + + /* approximate to 100 ms for each test */ + it = (100 * 1000) / (ptime / it); + otime = ptime; + } + + src_off = soi /*src_offs[soi]*/; + dst_off = doi /*dst_offs[doi]*/; + + if (len > max_size - dst_off) + continue; + + performance_test_single(p, p->comp, p->verbose, it, len, src_off, dst_off, &ptime, &ptransactions, &pbytes); + bytes += pbytes; + transactions += ptransactions; + time += ptime; + if (p->verbose > 2) + printf("Iterations: % 10d, time: %10.0f us | Probing iterations: % 08d Probing time %10.0f us\n", it, ptime, PI, otime); + } + } + } + + if (p->verbose > 0) { + print_stats(time, transactions, bytes); + } +} + +int do_test_linear(struct mi_test_params *p) +{ + int ret; + int j; + unsigned rl; + uint64_t bytes = 0; + uint64_t total = 0; + char *data; + int trans; + double time; + + int si_min = 0x0; + int di_min = 0x0; + int si_max = 0x100; + int di_max = 0x100; + + int sp, dp; + int ii, si, di, l; + + ret = 0; + + if (p->addr_range.items == 1) { + di_min = si_min = p->addr_range.min[0]; + di_max = si_max = p->addr_range.max[0]; + } + + if (list_range_empty(&p->length_range)) { + list_range_add_range(&p->length_range, 1, di_max); + } + + p->iteration_count = p->iteration_count == 0 ? 1 : p->iteration_count; + + trans = p->trans_mask; + + mstart(); + for (ii = 0; ii < p->iteration_count; ii++) { + for (si = si_min; si < si_max; si++) { + sp = 0; + for (di = di_min; di < di_max; di++) { + dp = 0; + for (l = di_min + 1; l < di_max + 1; l++) { + if (p->transaction_count != 0 && total >= p->transaction_count) + break; + + if (!list_range_contains(&p->length_range, l)) + continue; + + data = l % 2 ? data1 : data2; + + rl = l; + if (rl > di_max - di) + rl = di_max - di; + + /* Skip already performed transactions */ + if (rl != l) + continue; + + if (trans & 1) + nfb_comp_write(p->comp, data+si, rl, di); + if (trans & 2) + nfb_comp_read(p->comp, datar+si, rl, di); + + if (trans == 3) { + ret |= check_integrity(data+si, datar+si, si, di, rl); + } + + if (p->verbose > 1) { + if (p->verbose > 2 || sp == 0) { + if (p->verbose > 3 || dp == 0) { + sp = 1; + dp = 1; + print_transaction(trans, si, di, rl, p->verbose > 4 ? datar+si : NULL, 0); + } + } + } + + bytes += rl; + total++; + } + } + } + } + time = mstop(); + + if (trans == 3) { + total *= 2; + bytes *= 2; + } + + if (p->verbose > 0) { + print_stats(time, total, bytes); + } + return ret; +} + +int main(int argc, char *argv[]) +{ + int c; + int ret = EXIT_SUCCESS; + + char *path = NFB_PATH_DEV(0); + + const char *compatible = "cesnet,ofm,mi_test_space"; + + struct mi_test_params params; + struct nfb_device *dev; + struct nfb_comp *comp; + + int fdt_offset; + int proplen; + const uint32_t *prop; + + enum commands command = CMD_TEST_RANDOM; + + params.verbose = 0; + + params.trans_mask = 3; + + params.mi_off_min = 0; + params.mi_off_max = 0x80000000; + params.transaction_count = 0; + params.iteration_count = 0; + + list_range_init(¶ms.length_range); + list_range_init(¶ms.addr_range); + list_range_init(¶ms.src_off_range); + list_range_init(¶ms.dst_off_range); + + while ((c = getopt(argc, argv, ARGUMENTS)) != -1) { + switch (c) { + case 'd': + path = optarg; + break; + case 'c': + compatible = optarg; + break; + case 'r': + params.trans_mask = 2; + break; + case 'w': + params.trans_mask = 1; + break; + case 't': + if (strcmp(optarg, "random") == 0) { + command = CMD_TEST_RANDOM; + } else if (strcmp(optarg, "linear") == 0) { + command = CMD_TEST_LINEAR; + } else if (strcmp(optarg, "performance") == 0) { + command = CMD_TEST_PERFORMANCE; + } else { + errx(1, "unknown argument -%c", optopt); + usage(argv[0]); + return -1; + } + break; + case 'T': + if (nc_strtoull(optarg, ¶ms.transaction_count)) + errx(-1, "Cannot parse transaction count parameter"); + break; + case 'I': + if (nc_strtoull(optarg, ¶ms.iteration_count)) + errx(-1, "Cannot parse transaction count parameter"); + break; + case 'l': + if (list_range_parse(¶ms.length_range, optarg) < 0) + errx(EXIT_FAILURE, "Cannot parse length range argument."); + break; + case 'h': + command = CMD_USAGE; + break; + case 'v': + params.verbose = params.verbose < 0 ? 1 : params.verbose + 1; + break; + case 'C': + params.verbose = -1; + break; + case 'R': + if (list_range_parse(¶ms.addr_range, optarg) < 0 || params.addr_range.items != 1) + errx(EXIT_FAILURE, "Cannot parse address space range."); + break; + case 'S': + if (list_range_parse(¶ms.src_off_range, optarg) < 0) + errx(EXIT_FAILURE, "Cannot parse source offset range."); + break; + case 'D': + if (list_range_parse(¶ms.dst_off_range, optarg) < 0) + errx(EXIT_FAILURE, "Cannot parse destination offset range."); + break; + default: + errx(1, "unknown argument -%c", optopt); + } + } + + if (command == CMD_USAGE) { + usage(argv[0]); + list_range_destroy(¶ms.length_range); + list_range_destroy(¶ms.addr_range); + list_range_destroy(¶ms.src_off_range); + list_range_destroy(¶ms.dst_off_range); + return 0; + } + argc -= optind; + argv += optind; + + if (argc) + errx(1, "stray arguments"); + + dev = nfb_open(path); + if (!dev) + errx(1, "can't open device file"); + + fdt_offset = nfb_comp_find(dev, compatible, 0); + + prop = fdt_getprop(nfb_get_fdt(dev), fdt_offset, "reg", &proplen); + if (proplen != sizeof(*prop) * 2) { + errno = EBADFD; + return -1; + } + + if (fdt32_to_cpu(prop[1]) < params.mi_off_max) + params.mi_off_max = fdt32_to_cpu(prop[1]); + + if (params.mi_off_min > params.mi_off_max) + params.mi_off_min = params.mi_off_max; + + if (params.mi_off_max - params.mi_off_min > DATA_SIZE) { + params.mi_off_max = params.mi_off_min + DATA_SIZE; + warnx("Internal buffer size is not sufficient, testing only part of MI address space"); + } + + comp = nfb_comp_open(dev, fdt_offset); + + if (comp == NULL) { + errx(1, "Can't open MI bus component with compatible: %s", compatible); + } + + params.comp = comp; + + randomize_data(); + + /* Force map page to userspace before time sensitive tests */ + if (params.trans_mask & 1) { + nfb_comp_write(comp, data1, 1, 0); + } else { + nfb_comp_read(comp, datar, 1, 0); + } + + if (command == CMD_TEST_RANDOM) + do_test_random(¶ms); + else if (command == CMD_TEST_PERFORMANCE) + do_test_performance(¶ms); + else if (command == CMD_TEST_LINEAR) + do_test_linear(¶ms); + + nfb_comp_close(comp); + nfb_close(dev); + + list_range_destroy(¶ms.length_range); + list_range_destroy(¶ms.addr_range); + list_range_destroy(¶ms.src_off_range); + list_range_destroy(¶ms.dst_off_range); + return ret; +} From c1447e804cb6599a2ccd8e80b68a20f95042fc36 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 22 Jul 2024 17:22:24 +0200 Subject: [PATCH 152/518] nfb-mi-test: [FIX] some build warnings --- tools-debug/nfb-mi-test/nfb-mi-test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools-debug/nfb-mi-test/nfb-mi-test.c b/tools-debug/nfb-mi-test/nfb-mi-test.c index 3ea08beb..0122fbf0 100644 --- a/tools-debug/nfb-mi-test/nfb-mi-test.c +++ b/tools-debug/nfb-mi-test/nfb-mi-test.c @@ -86,7 +86,7 @@ enum commands { void usage(const char *progname) { printf("Usage: %s [-hv] [-d path]\n", progname); - printf("-d path Path to device [default: %s]\n", NFB_PATH_DEV(0)); + printf("-d path Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); printf("-c compatible Compatible string of component to use in test\n"); printf("-t test Select test: random, linear, performance [default: random]\n"); printf("-r Use only reads\n"); @@ -118,7 +118,7 @@ void print_transaction(int type, unsigned off_mi, unsigned off_ram, unsigned siz printf("\n"); } -void print_stats(double time, uint64_t count, uint64_t bytes) +void print_stats(double time, long long unsigned count, long long unsigned bytes) { printf("Total time: %f s, transactions: %llu, bytes: %llu, average speed: %.3lf MBps\n", time / 1000000, count, bytes, ((double)bytes)/time); @@ -412,7 +412,7 @@ int main(int argc, char *argv[]) int c; int ret = EXIT_SUCCESS; - char *path = NFB_PATH_DEV(0); + char *path = NFB_DEFAULT_DEV_PATH; const char *compatible = "cesnet,ofm,mi_test_space"; From ef9f5c01bf8d050caa2f6cd570f1435c0463be26 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Jun 2024 19:59:54 +0200 Subject: [PATCH 153/518] python nfb-tools: [FIX] dependency --- python/nfb-tools/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/nfb-tools/pyproject.toml b/python/nfb-tools/pyproject.toml index 4ddd7bba..018656cd 100644 --- a/python/nfb-tools/pyproject.toml +++ b/python/nfb-tools/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "nfb-tools" version = "0.2.0" -dependencies = [] +dependencies = ["pyyaml"] [project.scripts] nfb-meter = "nfbmeter.nfbmeter:main" From 7e264860797d65a767f205285ed9e99b55d24fbf Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 4 Oct 2023 10:26:29 +0200 Subject: [PATCH 154/518] tool info: [FEATURE] print list of available devices --- tools/info/info.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/tools/info/info.c b/tools/info/info.c index 8b186e98..b555b7bf 100644 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -15,24 +15,30 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include -#define ARGUMENTS "d:q:hvV" +#define ARGUMENTS "d:q:hlvV" #define BUFFER_SIZE 64 +#define NFB_PATH_MAXLEN 64 +#define NFB_BASE_DEV_PATH "/dev/nfb/" + enum commands { CMD_PRINT_STATUS, CMD_USAGE, CMD_VERSION, + CMD_LIST, }; // this enum need to corespond with queries[] array @@ -96,6 +102,81 @@ void print_version() #endif } +void print_device_list() +{ + int ret; + int len; + int fdt_offset; + + DIR * d; + struct dirent *dir; + struct nc_composed_device_info info; + struct nfb_device *dev; + + char path[128]; + char lpath[PATH_MAX]; + + const void *fdt; + const char *prop; + const uint32_t *prop32; + + d = opendir(NFB_BASE_DEV_PATH "by-pci-slot/"); + if (d == NULL) + return; + + printf("ID Base path PCI address Card name Serial number Firmware info - project\n"); + + while ((dir = readdir(d)) != NULL) { + ret = snprintf(path, NFB_PATH_MAXLEN, NFB_BASE_DEV_PATH "by-pci-slot/%s", dir->d_name); + if (ret <= 0 || ret == NFB_PATH_MAXLEN) { + continue; + } + + realpath(path, lpath); + + dev = nfb_open(path); + if (dev) { + fdt = nfb_get_fdt(dev); + fdt_offset = fdt_path_offset(fdt, "/firmware/"); + + ret = nc_get_composed_device_info_by_pci(dev, NULL, &info); + + prop = fdt_getprop(fdt, fdt_offset, "card-name", &len); + printf("% 2d %-10s %s %-16s", + ret == 0 ? info.nfb_id : -1, + lpath, dir->d_name, len > 0 ? prop : ""); + + + fdt_offset = fdt_path_offset(fdt, "/board/"); + prop = fdt_getprop(fdt, fdt_offset, "serial-number-string", &len); + if (len > 0) { + printf(" %-16s", prop); + } else { + prop32 = fdt_getprop(fdt, fdt_offset, "serial-number", &len); + if (len == sizeof(*prop32)) + printf(" %-16d", fdt32_to_cpu(*prop32)); + else + printf(" %16s", ""); + } + + fdt_offset = fdt_path_offset(fdt, "/firmware/"); + prop = fdt_getprop(fdt, fdt_offset, "project-name", &len); + if (len > 0) + printf("%s", prop); + prop = fdt_getprop(fdt, fdt_offset, "project-variant", &len); + if (len > 0) + printf(" %s", prop); + prop = fdt_getprop(fdt, fdt_offset, "project-version", &len); + if (len > 0) + printf(" %s", prop); + + printf("\n"); + + nfb_close(dev); + } + } +} + int print_specific_info(struct nfb_device *dev, int query) { int unknown = 0; @@ -411,6 +492,9 @@ int main(int argc, char *argv[]) case 'h': command = CMD_USAGE; break; + case 'l': + command = CMD_LIST; + break; case 'v': verbose++; break; @@ -431,7 +515,11 @@ int main(int argc, char *argv[]) } else if (command == CMD_VERSION) { print_version(); return 0; + } else if (command == CMD_LIST) { + print_device_list(); + return 0; } + argc -= optind; argv += optind; From a2959da2718cc1fe0140d55793abb15e52a19226 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 1 Aug 2024 14:05:06 +0200 Subject: [PATCH 155/518] drivers: [MAINTENANCE] fix source files mode --- drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c | 0 drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.h | 0 drivers/kernel/drivers/nfb/hwmon/nfb_hwmon_transceiver.h | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c mode change 100755 => 100644 drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.h mode change 100755 => 100644 drivers/kernel/drivers/nfb/hwmon/nfb_hwmon_transceiver.h diff --git a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c old mode 100755 new mode 100644 diff --git a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.h b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.h old mode 100755 new mode 100644 diff --git a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon_transceiver.h b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon_transceiver.h old mode 100755 new mode 100644 From 7925452a4f798060c1c44c9f36d4d743c44b2dff Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 1 Aug 2024 14:37:55 +0200 Subject: [PATCH 156/518] python: [FIX] fix Python package versioning For pynfb separate from nfb-framework versioning. For nfb-tools add version 0.2.0 --- pynfb/setup.py.in | 2 +- python/nfb-tools/setup.py | 1 + python/nfb-tools/setup.py.in | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pynfb/setup.py.in b/pynfb/setup.py.in index bfd3a055..d16161c6 100644 --- a/pynfb/setup.py.in +++ b/pynfb/setup.py.in @@ -4,7 +4,7 @@ from Cython.Build import cythonize setup( name = "nfb", - version='${PACKAGE_VERSION}', + version = "0.1.0", author = "Martin Spinler", author_email = "spinler@cesnet.cz", ext_package = "nfb", diff --git a/python/nfb-tools/setup.py b/python/nfb-tools/setup.py index 6fe24d51..d9ea922f 100644 --- a/python/nfb-tools/setup.py +++ b/python/nfb-tools/setup.py @@ -2,6 +2,7 @@ setup( name='nfbtools', + version = "0.2.0", packages=[ "nfbmeter", "nfbbootstrap", "nfbbootstrap.pypcie", diff --git a/python/nfb-tools/setup.py.in b/python/nfb-tools/setup.py.in index 942dba51..153c2e35 100644 --- a/python/nfb-tools/setup.py.in +++ b/python/nfb-tools/setup.py.in @@ -2,6 +2,7 @@ from setuptools import setup setup( name='nfbtools', + version = "0.2.0", packages=[ "nfbmeter", "nfbbootstrap", "nfbbootstrap.pypcie", From 0b67453814eac962935d9e4fae90edf43d334537 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 1 Aug 2024 14:40:52 +0200 Subject: [PATCH 157/518] python tools: [FIX] unify differences in setup.py and pyproject.toml Package name in pyproject.toml X setup.py: nfbtools X nfb-tools --- python/nfb-tools/pyproject.toml | 7 +++++-- python/nfb-tools/setup.py | 3 ++- python/nfb-tools/setup.py.in | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/python/nfb-tools/pyproject.toml b/python/nfb-tools/pyproject.toml index 018656cd..856ada04 100644 --- a/python/nfb-tools/pyproject.toml +++ b/python/nfb-tools/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "nfb-tools" +name = "nfbtools" version = "0.2.0" dependencies = ["pyyaml"] @@ -8,4 +8,7 @@ nfb-meter = "nfbmeter.nfbmeter:main" nfb-bootstrap = "nfbbootstrap.nfb_bootstrap:main" [tool.setuptools] -packages = ["nfbmeter"] +packages = [ + "nfbmeter", + "nfbbootstrap", +] diff --git a/python/nfb-tools/setup.py b/python/nfb-tools/setup.py index d9ea922f..c7af59aa 100644 --- a/python/nfb-tools/setup.py +++ b/python/nfb-tools/setup.py @@ -5,7 +5,8 @@ version = "0.2.0", packages=[ "nfbmeter", - "nfbbootstrap", "nfbbootstrap.pypcie", + "nfbbootstrap", + "nfbbootstrap.pypcie", ], package_dir={ 'nfbmeter': 'nfbmeter', diff --git a/python/nfb-tools/setup.py.in b/python/nfb-tools/setup.py.in index 153c2e35..5a12726f 100644 --- a/python/nfb-tools/setup.py.in +++ b/python/nfb-tools/setup.py.in @@ -5,7 +5,8 @@ setup( version = "0.2.0", packages=[ "nfbmeter", - "nfbbootstrap", "nfbbootstrap.pypcie", + "nfbbootstrap", + "nfbbootstrap.pypcie", ], package_dir={ 'nfbmeter': '${CMAKE_CURRENT_SOURCE_DIR}/nfbmeter', From 7449fcfc42c49e3c2c38cd635729170bc57e6ce4 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 1 Aug 2024 14:45:00 +0200 Subject: [PATCH 158/518] python: [FIX] fix dependencies --- ext/libnfb_ext_python/setup.py | 1 + pynfb/setup.py | 1 + python/nfb-tools/pyproject.toml | 5 ++++- python/nfb-tools/setup.py | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/libnfb_ext_python/setup.py b/ext/libnfb_ext_python/setup.py index 2e0c4b81..f6a6f7c4 100644 --- a/ext/libnfb_ext_python/setup.py +++ b/ext/libnfb_ext_python/setup.py @@ -24,4 +24,5 @@ ), py_modules=["libnfb_ext_python"], packages=find_namespace_packages(include=["nfb.*"]), + install_requires=['nfb'], ) diff --git a/pynfb/setup.py b/pynfb/setup.py index d9fa7740..95324104 100644 --- a/pynfb/setup.py +++ b/pynfb/setup.py @@ -31,4 +31,5 @@ package_data = { 'nfb': ['*.pxd'], }, + install_requires=['fdt'], ) diff --git a/python/nfb-tools/pyproject.toml b/python/nfb-tools/pyproject.toml index 856ada04..8709bc44 100644 --- a/python/nfb-tools/pyproject.toml +++ b/python/nfb-tools/pyproject.toml @@ -1,7 +1,10 @@ [project] name = "nfbtools" version = "0.2.0" -dependencies = ["pyyaml"] +dependencies = [ + "nfb", + "pyyaml", +] [project.scripts] nfb-meter = "nfbmeter.nfbmeter:main" diff --git a/python/nfb-tools/setup.py b/python/nfb-tools/setup.py index c7af59aa..02b7785c 100644 --- a/python/nfb-tools/setup.py +++ b/python/nfb-tools/setup.py @@ -19,7 +19,7 @@ ], }, install_requires=[ - "fdt", + "nfb", "pyyaml", ] ) From 7bf8f5baa3a953d94ae0a9310e293406999968c4 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 31 Jul 2024 17:15:21 +0200 Subject: [PATCH 159/518] python: [MAINTENANCE] sanitize requirements for easy installation Use pyproject.toml for build-system requirements. For Python versions that doesn't supports PEP-518 is the alternative requirements.txt file. --- ext/libnfb_ext_python/pyproject.toml | 7 +++++++ ext/libnfb_ext_python/readme.rst | 10 ++++++++++ ext/libnfb_ext_python/requirements.txt | 3 +++ pynfb/pyproject.toml | 6 ++++++ pynfb/requirements.txt | 2 ++ 5 files changed, 28 insertions(+) create mode 100644 ext/libnfb_ext_python/pyproject.toml create mode 100644 ext/libnfb_ext_python/readme.rst create mode 100644 ext/libnfb_ext_python/requirements.txt create mode 100644 pynfb/pyproject.toml create mode 100644 pynfb/requirements.txt diff --git a/ext/libnfb_ext_python/pyproject.toml b/ext/libnfb_ext_python/pyproject.toml new file mode 100644 index 00000000..d979ab84 --- /dev/null +++ b/ext/libnfb_ext_python/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = [ + "setuptools >= 40.1.0", + "Cython", + "nfb", +] +build-backend = "setuptools.build_meta" diff --git a/ext/libnfb_ext_python/readme.rst b/ext/libnfb_ext_python/readme.rst new file mode 100644 index 00000000..f75daba9 --- /dev/null +++ b/ext/libnfb_ext_python/readme.rst @@ -0,0 +1,10 @@ +Installation +------------ + +libnfb_ext_python package requires nfb package for build. +The wanted nfb package is probably not available in ordinary way, so +local (venv) installation via pip can be done for example like this: + +# current directory is root of this git repository +$ pip wheel -w ./localwhldir ./pynfb/ +$ pip install --find-links ./localwhldir ./ext/libnfb_ext_python/ diff --git a/ext/libnfb_ext_python/requirements.txt b/ext/libnfb_ext_python/requirements.txt new file mode 100644 index 00000000..460695d5 --- /dev/null +++ b/ext/libnfb_ext_python/requirements.txt @@ -0,0 +1,3 @@ +setuptools >= 40.1.0 +Cython +nfb diff --git a/pynfb/pyproject.toml b/pynfb/pyproject.toml new file mode 100644 index 00000000..99dd3e6c --- /dev/null +++ b/pynfb/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools", + "Cython", +] +build-backend = "setuptools.build_meta" diff --git a/pynfb/requirements.txt b/pynfb/requirements.txt new file mode 100644 index 00000000..fa248522 --- /dev/null +++ b/pynfb/requirements.txt @@ -0,0 +1,2 @@ +setuptools +Cython From 0ce0ae8e589722bb0e0814246e39e235039d000b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 1 Aug 2024 15:42:03 +0200 Subject: [PATCH 160/518] build: [FEATURE] automatically download and extract default 3rdparty source files --- build.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 30759479..e7ffeb39 100755 --- a/build.sh +++ b/build.sh @@ -223,7 +223,14 @@ get_dpdk_dependencies() get_3rdparty_code() { curl -L $URL_3RDPARTY --output $FILENAME_3RDPARTY - tar -xf $FILENAME_3RDPARTY + tar -xf $FILENAME_3RDPARTY -C $SCRIPT_PATH/ +} + +try_get_3rdparty_code() +{ + if [ ! -e $SCRIPT_PATH/drivers/kernel/drivers/fdt/fdt.h ]; then + get_3rdparty_code + fi } install_dependencies() @@ -238,6 +245,7 @@ install_dependencies() Build() { + try_get_3rdparty_code mkdir -p "$SCRIPT_PATH/$BUILDDIR" cd "$SCRIPT_PATH/$BUILDDIR" $cmake -DCMAKE_BUILD_TYPE=$RELTYPE .. @@ -246,6 +254,7 @@ Build() Build_dpdk() { + try_get_3rdparty_code mkdir -p "$SCRIPT_PATH/$BUILDDIR" cd "$SCRIPT_PATH/$BUILDDIR" $cmake -DCMAKE_BUILD_TYPE=$RELTYPE -DUSE_DPDK=true .. From b8876868fd9767e251529b8cc0ee56a095a7050a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 1 Aug 2024 16:04:28 +0200 Subject: [PATCH 161/518] tools-debug - mi-test: [FIX] get rid of printf type warning --- tools-debug/nfb-mi-test/nfb-mi-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools-debug/nfb-mi-test/nfb-mi-test.c b/tools-debug/nfb-mi-test/nfb-mi-test.c index 0122fbf0..2cd8048b 100644 --- a/tools-debug/nfb-mi-test/nfb-mi-test.c +++ b/tools-debug/nfb-mi-test/nfb-mi-test.c @@ -302,7 +302,7 @@ void do_test_performance(struct mi_test_params *p) transactions += ptransactions; time += ptime; if (p->verbose > 2) - printf("Iterations: % 10d, time: %10.0f us | Probing iterations: % 08d Probing time %10.0f us\n", it, ptime, PI, otime); + printf("Iterations: % 10ld, time: %10.0f us | Probing iterations: % 08d Probing time %10.0f us\n", it, ptime, PI, otime); } } } From bbc9f053cb983977d81004e81a3bd129fc5d624f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 1 Aug 2024 15:54:21 +0200 Subject: [PATCH 162/518] pynfb - libnfb: [MAINTENANCE] rename __batched to _batched --- pynfb/nfb/libnfb.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index a38712e5..630c48a1 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -24,7 +24,7 @@ else: time_ns = time.time_ns -def __batched(iterable, n): +def _batched(iterable, n): it = iter(iterable) batch = tuple(islice(it, n)) while batch: @@ -705,7 +705,7 @@ cdef class NdpQueueTx(NdpQueue): cdef const char* c_pkt cdef const char* c_hdr - for burst in __batched(pkts, 64): + for burst in _batched(pkts, 64): in_cnt = len(burst) for i in range(in_cnt): pkt, hdr, flags = burst[i] From cd5fc1ef535369d44862f417993e10ba1cd24ab1 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 5 Aug 2024 13:23:50 +0200 Subject: [PATCH 163/518] PKGBUILD [FEATURE]: update version --- package/PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/PKGBUILD b/package/PKGBUILD index 588d1099..fab26a1a 100644 --- a/package/PKGBUILD +++ b/package/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Martin Spinler pkgname=('nfb-framework' 'python-nfb' 'nfb-framework-debug' 'nfb-ext-grpc') -pkgver=6.19.5 +pkgver=6.22.6 pkgrel=1 pkgdesc="Software bundle for CESNET NDK firmware platform" url='https://github.com/CESNET/ndk-sw' From c305e5e9bc4d713269443d215bd93c38b8b8811e Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 5 Aug 2024 13:09:09 +0200 Subject: [PATCH 164/518] PKGBUILD [BUGFIX]: remove nfb-framework-debug from package list This is because it gets already installed as a part of nfb-framework which is already in the list. Otherwise, the makepkg command ends up with with the "duplicate target" error message. --- package/PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/PKGBUILD b/package/PKGBUILD index fab26a1a..b427e886 100644 --- a/package/PKGBUILD +++ b/package/PKGBUILD @@ -1,5 +1,5 @@ # Maintainer: Martin Spinler -pkgname=('nfb-framework' 'python-nfb' 'nfb-framework-debug' 'nfb-ext-grpc') +pkgname=('nfb-framework' 'python-nfb' 'nfb-ext-grpc') pkgver=6.22.6 pkgrel=1 pkgdesc="Software bundle for CESNET NDK firmware platform" From 81968b3655d279fe59a45469e2397f25db2289b9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 25 Jul 2024 08:46:12 +0200 Subject: [PATCH 165/518] pynfb: [FEATURE] add get_temperature() --- pynfb/nfb/libnetcope.pxd | 12 +++++++++++- pynfb/nfb/libnetcope.pyx | 2 +- pynfb/nfb/libnfb.pyx | 11 ++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pynfb/nfb/libnetcope.pxd b/pynfb/nfb/libnetcope.pxd index 1923cdfa..90691b5a 100644 --- a/pynfb/nfb/libnetcope.pxd +++ b/pynfb/nfb/libnetcope.pxd @@ -1,4 +1,4 @@ -from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int32_t from libcpp cimport bool from posix.types cimport off_t @@ -126,6 +126,16 @@ cdef extern from "": int nc_i2c_write_reg(nc_i2c_ctrl *ctrl, uint8_t reg, const uint8_t *data, unsigned size); void nc_i2c_close(nc_i2c_ctrl *ctrl); +cdef extern from "": + cdef struct nfb_boot_ioc_sensor: + pass + +cdef extern from "": + int nfb_sensor_get(nfb_device *dev, nfb_boot_ioc_sensor *s) + +cdef extern from "": + int nc_adc_sensors_get_temp(const nfb_device *dev, int32_t *val) + cdef extern from "": cdef struct nc_rxqueue: pass diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 3fad6b35..fb90f6f2 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -3,7 +3,7 @@ import time import cython from libc.stdlib cimport malloc -from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int32_t from libcpp cimport bool from cpython.exc cimport PyErr_SetFromErrno diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 630c48a1..87fa1c5d 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -6,7 +6,7 @@ from itertools import islice from typing import Union, Optional, List, Tuple from libc.stdlib cimport malloc -from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int32_t from libcpp cimport bool from cpython.ref cimport PyObject @@ -137,6 +137,15 @@ cdef class Nfb: return self.fdt.get_node(path) return None + def get_temperature(self, units="celsius"): + cdef int32_t int32 = 0 + assert units == "celsius" + + ret = libnetcope.nc_adc_sensors_get_temp(self._handle._dev, &int32) + if ret < 0: + raise IOError + return int(int32) / 1000 + cdef class Comp: """ From 75a117c32a6a8453a943299b80bfd2c71ba340a6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 25 Jul 2024 10:48:08 +0200 Subject: [PATCH 166/518] pynfb: [FEATURE] add is_present() to the eth.Transceiver class, move Transceiver to libnetcope --- pynfb/nfb/eth.py | 33 +---------------------- pynfb/nfb/libnetcope.pxd | 3 +++ pynfb/nfb/libnetcope.pyx | 56 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/pynfb/nfb/eth.py b/pynfb/nfb/eth.py index 37dfd438..d61f2c74 100644 --- a/pynfb/nfb/eth.py +++ b/pynfb/nfb/eth.py @@ -42,7 +42,7 @@ def __init__(self, nfb, node): self.rxmac = libnetcope.RxMac(nfb, nfb.fdt_get_phandle(node.get_property('rxmac').value)) self.txmac = libnetcope.TxMac(nfb, nfb.fdt_get_phandle(node.get_property('txmac').value)) self.pcspma = PcsPma(nfb, nfb.fdt_get_phandle(node.get_property('pcspma').value)) - self.pmd = Transceiver(nfb, nfb.fdt_get_phandle(node.get_property('pmd').value)) + self.pmd = libnetcope.Transceiver(nfb, nfb.fdt_get_phandle(node.get_property('pmd').value)) def _common_action(self, action, *args, **kwargs): return [ @@ -69,38 +69,7 @@ def __setattr__(self, name, value): object.__setattr__(self, name, value) -class Transceiver: - """ - Object representing a transciever interface - - :ivar I2c i2c: I2c bus handle (only with QSFP+ modules) - """ - def __init__(self, nfb, node): - status = nfb.fdt_get_phandle(node.get_property('status-reg').value) - self.comp_status = nfb.comp_open(status) - - ctrl = nfb.fdt_get_phandle(node.get_property('control').value) - node_ctrl_param = node.get_subnode('control-param') - - # FIXME - if "QSFPP": - prop = node_ctrl_param.get_property("i2c-addr") - i2c_addr = prop.value if prop else 0xA0 - self.i2c = libnetcope.I2c(nfb, ctrl, i2c_addr) - # FIXME: only valid for specific QSFP+ - @property - def vendor_name(self) -> str: - "vendor of the transceiver" - return self.i2c.read_reg(148, 16).decode() - @property - def vendor_pn(self) -> str: - "product number of the transceiver" - return self.i2c.read_reg(168, 16).decode() - @property - def vendor_sn(self) -> str: - "serial number of the transceiver" - return self.i2c.read_reg(196, 16).decode() class PcsPma: diff --git a/pynfb/nfb/libnetcope.pxd b/pynfb/nfb/libnetcope.pxd index 90691b5a..ba019d00 100644 --- a/pynfb/nfb/libnetcope.pxd +++ b/pynfb/nfb/libnetcope.pxd @@ -116,6 +116,9 @@ cdef extern from "": cdef extern from "": int nc_eth_get_pcspma_control_node(const void *fdt, int nodeoffset, int *node_control_param) +cdef extern from "": + int nc_transceiver_statusreg_is_present(const nfb_comp * comp) + cdef extern from "": cdef struct nc_i2c_ctrl: pass diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index fb90f6f2..1697a124 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -11,7 +11,7 @@ from cpython.exc cimport PyErr_SetFromErrno import libnfb cimport libnfb -from libnfb cimport NfbDeviceHandle +from libnfb cimport NfbDeviceHandle, nfb_comp_open, nfb_comp_close cdef class RxMac: @@ -393,3 +393,57 @@ cdef class DmaCtrlNdp: if txc.have_bytes: ret['sent_bytes'] = txc.sent return ret + + +cdef class Transceiver: + cdef NfbDeviceHandle _handle + cdef nfb_comp *_comp_status + cdef dict __dict__ + + """ + Object representing a transceiver interface + + :ivar I2c i2c: I2c bus handle (only with QSFP+ modules) + """ + def __init__(self, libnfb.Nfb nfb, node): + self._comp_status = NULL + + self._nfb = nfb + self._handle = nfb._handle + status = nfb.fdt_get_phandle(node.get_property('status-reg').value) + fdt_offset = self._nfb._fdt_path_offset(status) + self._comp_status = nfb_comp_open(self._handle._dev, fdt_offset) + if self._comp_status is NULL: + PyErr_SetFromErrno(OSError) + + ctrl = nfb.fdt_get_phandle(node.get_property('control').value) + node_ctrl_param = node.get_subnode('control-param') + + # FIXME + if "QSFPP": + prop = node_ctrl_param.get_property("i2c-addr") + i2c_addr = prop.value if prop else 0xA0 + self.i2c = I2c(nfb, ctrl, i2c_addr) + + def __dealloc__(self): + if self._comp_status is not NULL: + nfb_comp_close(self._comp_status) + + + def is_present(self) -> bool: + return nc_transceiver_statusreg_is_present(self._comp_status) != 0 + + + # FIXME: only valid for specific QSFP+ + @property + def vendor_name(self) -> str: + "vendor of the transceiver" + return self.i2c.read_reg(148, 16).decode() + @property + def vendor_pn(self) -> str: + "product number of the transceiver" + return self.i2c.read_reg(168, 16).decode() + @property + def vendor_sn(self) -> str: + "serial number of the transceiver" + return self.i2c.read_reg(196, 16).decode() From 44c7b07d018909482fd7a74f80d92fa12c608fcd Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 25 Jul 2024 17:07:35 +0200 Subject: [PATCH 167/518] pynfb - Transceiver: [FIX] strip vendor name, pn and sn attributes --- pynfb/nfb/libnetcope.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 1697a124..20968db5 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -438,12 +438,12 @@ cdef class Transceiver: @property def vendor_name(self) -> str: "vendor of the transceiver" - return self.i2c.read_reg(148, 16).decode() + return self.i2c.read_reg(148, 16).decode().strip() @property def vendor_pn(self) -> str: "product number of the transceiver" - return self.i2c.read_reg(168, 16).decode() + return self.i2c.read_reg(168, 16).decode().strip() @property def vendor_sn(self) -> str: "serial number of the transceiver" - return self.i2c.read_reg(196, 16).decode() + return self.i2c.read_reg(196, 16).decode().strip() From b056a42dcb084739b22e59ca05f126215a6bb430 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 6 Aug 2024 12:44:26 +0200 Subject: [PATCH 168/518] pynfb: [FIX] add kernel headers for pynfb build --- .gitlab-ci.yml | 2 +- pynfb/setup.py | 25 +++++++++++++++++-------- pynfb/setup.py.in | 18 ++++++++++++++++-- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1ebbdc1d..3559d35d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,7 +15,7 @@ pages: - pip install -U fdt cython - sh build.sh --prepare - sh build.sh --make - - "(cd pynfb; python3 setup.py build_ext --inplace -I ../libnfb/include -L ../cmake-build/libnfb)" + - "(cd pynfb; python3 setup.py build_ext --inplace -I ../libnfb/include:../drivers/kernel/include -L ../cmake-build/libnfb)" - LD_LIBRARY_PATH=$(pwd)/cmake-build/libnfb/ sphinx-build -b html doc/ public artifacts: paths: diff --git a/pynfb/setup.py b/pynfb/setup.py index 95324104..bf1af1c7 100644 --- a/pynfb/setup.py +++ b/pynfb/setup.py @@ -1,9 +1,24 @@ from setuptools import Extension, setup from Cython.Build import cythonize +import pathlib + # This setup.py uses the system default path for includes/libraries, # so the nfb-framework package must be already installed. # If isn't installed, define include_dirs and library_dirs as in setup.py.in +ext_extra_args = dict( + include_dirs=[ + str(pathlib.Path(__file__).parent / pathlib.Path("../libnfb/include")), + str(pathlib.Path(__file__).parent / pathlib.Path("../drivers/kernel/include")), + ], + library_dirs=[ + str(pathlib.Path(__file__).parent / pathlib.Path("../cmake-build/libnfb")), + ], +) + +libnfb_ext_extra_args = libnetcope_ext_extra_args = dict() +#libnfb_ext_extra_args = libnetcope_ext_extra_args = ext_extra_args + setup( name = "nfb", @@ -13,14 +28,8 @@ ext_package = "nfb", ext_modules = cythonize( [ - Extension("libnfb", ["nfb/libnfb.pyx"], libraries=["nfb", "fdt"], -# include_dirs=[str(pathlib.Path(__file__).parent / pathlib.Path("../libnfb/include"))], -# library_dirs=[str(pathlib.Path(__file__).parent / pathlib.Path("../cmake-build/libnfb"))], - ), - Extension("libnetcope", ["nfb/libnetcope.pyx"], libraries=["nfb", "fdt"], -# include_dirs=[str(pathlib.Path(__file__).parent / pathlib.Path("../libnfb/include"))], -# library_dirs=[str(pathlib.Path(__file__).parent / pathlib.Path("../cmake-build/libnfb"))], - ), + Extension("libnfb", ["nfb/libnfb.pyx"], libraries=["nfb", "fdt"], **libnfb_ext_extra_args), + Extension("libnetcope", ["nfb/libnetcope.pyx"], libraries=["nfb", "fdt"], **libnetcope_ext_extra_args), ], include_path=['nfb'], compiler_directives={'embedsignature': True, 'binding': False}, diff --git a/pynfb/setup.py.in b/pynfb/setup.py.in index d16161c6..c423b306 100644 --- a/pynfb/setup.py.in +++ b/pynfb/setup.py.in @@ -2,6 +2,19 @@ from setuptools import Extension, setup from Cython.Build import cythonize +ext_extra_args = dict( + include_dirs=[ + '${CMAKE_CURRENT_SOURCE_DIR}/../libnfb/include', + '${CMAKE_CURRENT_SOURCE_DIR}/../drivers/kernel/include', + ], + library_dirs=[ + '${CMAKE_BINARY_DIR}/libnfb' + ], +) + +libnfb_ext_extra_args = libnetcope_ext_extra_args = ext_extra_args + + setup( name = "nfb", version = "0.1.0", @@ -10,8 +23,8 @@ setup( ext_package = "nfb", ext_modules = cythonize( [ - Extension("libnfb", ["${CMAKE_CURRENT_SOURCE_DIR}/nfb/libnfb.pyx"], libraries=["nfb", "fdt"], include_dirs=['${CMAKE_CURRENT_SOURCE_DIR}/../libnfb/include'], library_dirs=['${CMAKE_BINARY_DIR}/libnfb']), - Extension("libnetcope", ["${CMAKE_CURRENT_SOURCE_DIR}/nfb/libnetcope.pyx"], libraries=["nfb", "fdt"], include_dirs=['${CMAKE_CURRENT_SOURCE_DIR}/../libnfb/include'], library_dirs=['${CMAKE_BINARY_DIR}/libnfb']), + Extension("libnfb", ["${CMAKE_CURRENT_SOURCE_DIR}/nfb/libnfb.pyx"], libraries=["nfb", "fdt"], **libnfb_ext_extra_args), + Extension("libnetcope", ["${CMAKE_CURRENT_SOURCE_DIR}/nfb/libnetcope.pyx"], libraries=["nfb", "fdt"], **libnetcope_ext_extra_args), ], include_path=['${CMAKE_CURRENT_SOURCE_DIR}/nfb'], compiler_directives={'embedsignature': True, 'binding': False}, @@ -22,4 +35,5 @@ setup( package_data = { 'nfb': ['*.pxd'], }, + install_requires=['fdt'], ) From 28e769e907aa746feb1b12ce8d4c7404801b3afc Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 7 Aug 2024 15:12:22 +0200 Subject: [PATCH 169/518] libnfb_ext_python: [MAINTENANCE] legacy unspecified noexcept was deprecated, use explicit noexcept New versions of cython doesn't allow cdef functions without noexcept. Requirements are updated to minimal cython version 0.29.33. --- .../libnfb_ext_python/libnfb_ext_python.pxd | 18 ++++----- .../libnfb_ext_python/libnfb_ext_python.pyx | 37 ++++++++++--------- ext/libnfb_ext_python/pyproject.toml | 4 +- ext/libnfb_ext_python/requirements.txt | 4 +- ext/libnfb_ext_python/setup.py | 2 +- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd index c826e948..4121651c 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd +++ b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd @@ -18,19 +18,19 @@ cdef extern from "": cdef api const char *nfb_pynfb_prefix cdef public api: - int pynfb_ext_get_ops(const char *devname, libnfb_ext_ops* ops) + int pynfb_ext_get_ops(const char *devname, libnfb_ext_ops* ops) noexcept - int nfb_ext_python_open(const char *devname, int oflag, void **priv, void **fdt) - void nfb_ext_python_close(void *priv) + int nfb_ext_python_open(const char *devname, int oflag, void **priv, void **fdt) noexcept + void nfb_ext_python_close(void *priv) noexcept - int nfb_pynfb_bus_open(void *dev_priv, int bus_node, int comp_node, void ** bus_priv, libnfb_bus_ext_ops* ops) - void nfb_pynfb_bus_close(void *bus_priv) + int nfb_pynfb_bus_open(void *dev_priv, int bus_node, int comp_node, void ** bus_priv, libnfb_bus_ext_ops* ops) noexcept + void nfb_pynfb_bus_close(void *bus_priv) noexcept - ssize_t nfb_pynfb_bus_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) - ssize_t nfb_pynfb_bus_write(void *bus_priv, const void *buf, size_t nbyte, off_t offset) + ssize_t nfb_pynfb_bus_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) noexcept + ssize_t nfb_pynfb_bus_write(void *bus_priv, const void *buf, size_t nbyte, off_t offset) noexcept - cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq) - cdef int nfb_pyndp_queue_close(ndp_queue *q) + cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq) noexcept + cdef int nfb_pyndp_queue_close(ndp_queue *q) noexcept cdef int pyndp_start(void *priv) cdef int pyndp_stop(void *priv) diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx index ae304180..35784a16 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx +++ b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx @@ -5,7 +5,7 @@ cdef class __NfbWrapper: cdef object nfb cdef list bus -cdef int nfb_ext_python_open(const char *devname, int oflag, void **priv, void **fdt): +cdef int nfb_ext_python_open(const char *devname, int oflag, void **priv, void **fdt) noexcept: cdef int ret cdef uint64_t addr cdef object nfb @@ -36,7 +36,7 @@ cdef int nfb_ext_python_open(const char *devname, int oflag, void **priv, void * return 0 -cdef void nfb_ext_python_close(void *priv): +cdef void nfb_ext_python_close(void *priv) noexcept: cdef PyObject* _wrap cdef __NfbWrapper wrap cdef object nfb @@ -49,7 +49,7 @@ cdef void nfb_ext_python_close(void *priv): #free(wrap.fdt) Py_DECREF(wrap) -cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset): +cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset) noexcept: cdef PyObject* _bus = p cdef object bus = _bus cdef bytes data @@ -61,7 +61,7 @@ cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset): return nbyte -cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t offset): +cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t offset) noexcept: cdef PyObject* _bus = p cdef object bus = _bus cdef const char* c_data = buf @@ -72,7 +72,7 @@ cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t o return nbyte -cdef int nfb_pynfb_bus_open(void *dev_priv, int bus_offset, int comp_offset, void ** bus_priv, libnfb_bus_ext_ops* ops): +cdef int nfb_pynfb_bus_open(void *dev_priv, int bus_offset, int comp_offset, void ** bus_priv, libnfb_bus_ext_ops* ops) noexcept: cdef PyObject* _wrap = dev_priv cdef __NfbWrapper wrap = _wrap @@ -104,7 +104,7 @@ cdef int nfb_pynfb_bus_open(void *dev_priv, int bus_offset, int comp_offset, voi return 0 -cdef void nfb_pynfb_bus_close(void *priv): +cdef void nfb_pynfb_bus_close(void *priv) noexcept: cdef PyObject* _bus = priv cdef object bus = _bus @@ -112,7 +112,7 @@ cdef void nfb_pynfb_bus_close(void *priv): # NDP functions -cdef int pyndp_start(void *priv): +cdef int pyndp_start(void *priv) noexcept: cdef object t = priv queue, temp = t @@ -120,7 +120,7 @@ cdef int pyndp_start(void *priv): return 0 -cdef int pyndp_stop(void *priv): +cdef int pyndp_stop(void *priv) noexcept: cdef object t = priv queue, temp = t @@ -128,7 +128,7 @@ cdef int pyndp_stop(void *priv): return 0 -cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count): +cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count) noexcept: cdef object t = priv cdef uint8_t* c_data @@ -151,7 +151,7 @@ cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count return cnt -cdef int pyndp_rx_burst_put(void *priv): +cdef int pyndp_rx_burst_put(void *priv) noexcept: cdef object t = priv queue, temp = t @@ -159,7 +159,7 @@ cdef int pyndp_rx_burst_put(void *priv): return 0 -cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count): +cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count) noexcept: cdef object t = priv queue, temp = t @@ -178,7 +178,7 @@ cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count return len(prep) -cdef int pyndp_tx_burst_put(void *priv): +cdef int pyndp_tx_burst_put(void *priv) noexcept: cdef object t = priv queue, temp = t @@ -186,7 +186,7 @@ cdef int pyndp_tx_burst_put(void *priv): return 0 -cdef int pyndp_tx_burst_flush(void *priv): +cdef int pyndp_tx_burst_flush(void *priv) noexcept: cdef object t = priv queue, temp = t @@ -194,7 +194,7 @@ cdef int pyndp_tx_burst_flush(void *priv): return 0 -cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq): +cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq) noexcept: cdef PyObject* _wrap = dev_priv cdef __NfbWrapper wrap = _wrap @@ -234,20 +234,21 @@ cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, i return 0 -cdef int nfb_pyndp_queue_close(ndp_queue *q): +cdef int nfb_pyndp_queue_close(ndp_queue *q) noexcept: cdef object t = ndp_queue_get_priv(q) queue, temp = t Py_DECREF(t) + return 0 -cdef int nfb_pynfb_comp_lock(const nfb_comp *comp, uint32_t features): +cdef int nfb_pynfb_comp_lock(const nfb_comp *comp, uint32_t features) noexcept: # TODO return 1; -cdef void nfb_pynfb_comp_unlock(const nfb_comp *comp, uint32_t features): +cdef void nfb_pynfb_comp_unlock(const nfb_comp *comp, uint32_t features) noexcept: pass -cdef int pynfb_ext_get_ops(const char *devname, libnfb_ext_ops* ops): +cdef int pynfb_ext_get_ops(const char *devname, libnfb_ext_ops* ops) noexcept: if strncmp(devname, nfb_pynfb_prefix, strlen(nfb_pynfb_prefix)) != 0: return 0 diff --git a/ext/libnfb_ext_python/pyproject.toml b/ext/libnfb_ext_python/pyproject.toml index d979ab84..2264294d 100644 --- a/ext/libnfb_ext_python/pyproject.toml +++ b/ext/libnfb_ext_python/pyproject.toml @@ -1,7 +1,7 @@ [build-system] requires = [ - "setuptools >= 40.1.0", - "Cython", + "setuptools>=40.1.0", + "Cython>=0.29.33", "nfb", ] build-backend = "setuptools.build_meta" diff --git a/ext/libnfb_ext_python/requirements.txt b/ext/libnfb_ext_python/requirements.txt index 460695d5..201a7353 100644 --- a/ext/libnfb_ext_python/requirements.txt +++ b/ext/libnfb_ext_python/requirements.txt @@ -1,3 +1,3 @@ -setuptools >= 40.1.0 -Cython +setuptools>=40.1.0 +Cython>=0.29.33 nfb diff --git a/ext/libnfb_ext_python/setup.py b/ext/libnfb_ext_python/setup.py index f6a6f7c4..d88350d8 100644 --- a/ext/libnfb_ext_python/setup.py +++ b/ext/libnfb_ext_python/setup.py @@ -20,7 +20,7 @@ ), ], include_path=["libnfb_ext_python"], - compiler_directives={"embedsignature": True, "binding": False, **({} if Cython.__version__ <= '0.29' else {"legacy_implicit_noexcept": True})}, + compiler_directives={"embedsignature": True, "binding": False}, ), py_modules=["libnfb_ext_python"], packages=find_namespace_packages(include=["nfb.*"]), From b84480309c920c73f849be5c2cdbfae9ba3a37f1 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 9 Aug 2024 14:32:46 +0200 Subject: [PATCH 170/518] libnfb: [FEATURE] introduce const char *nfb_default_dev_path() It reads default device path from LIBNFB_DEFAULT_DEV env. variable or uses default "/dev/nfb0" and returns the value. --- libnfb/include/nfb/nfb.h | 9 +++++++++ libnfb/src/nfb.c | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/libnfb/include/nfb/nfb.h b/libnfb/include/nfb/nfb.h index e4539793..7ecac20e 100644 --- a/libnfb/include/nfb/nfb.h +++ b/libnfb/include/nfb/nfb.h @@ -44,6 +44,15 @@ struct nfb_comp; /* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~[ DEVICE ] ~~~~ */ + +/*! + * \brief Get default device path, when user doesn't specify one. + * \return + * - path + * + */ +const char * nfb_default_dev_path(void); + /*! * \brief Open the NFB device * \param[in] path Path to the NFB device file diff --git a/libnfb/src/nfb.c b/libnfb/src/nfb.c index 2d727a88..1b4897af 100644 --- a/libnfb/src/nfb.c +++ b/libnfb/src/nfb.c @@ -65,6 +65,15 @@ void *nfb_comp_to_user(struct nfb_comp *ptr) return (void *)(ptr + 1); } +const char * nfb_default_dev_path() +{ + const char *devname = getenv("LIBNFB_DEFAULT_DEV"); + if (devname == NULL) { + devname = "/dev/nfb0"; + } + return devname; +} + struct nfb_device *nfb_open_ext(const char *devname, int oflag) { int ret; From 2eb78f556cb141cebf00bfdc64c74e78ca57776d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 9 Aug 2024 14:56:25 +0200 Subject: [PATCH 171/518] libnfb - nfb_open: [FEATURE] use default device path when the input is NULL --- libnfb/src/nfb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libnfb/src/nfb.c b/libnfb/src/nfb.c index 1b4897af..c3e4da25 100644 --- a/libnfb/src/nfb.c +++ b/libnfb/src/nfb.c @@ -89,6 +89,9 @@ struct nfb_device *nfb_open_ext(const char *devname, int oflag) libnfb_ext_get_ops_t* get_ops; + if (devname == NULL) + devname = nfb_default_dev_path(); + if (sscanf(devname, "%u%n", &index, &ret) >= 1 && (size_t) ret == strlen(devname)) { ret = snprintf(path, PATH_LEN, "/dev/nfb%u", index); if (ret >= PATH_LEN || ret < 0) { From 9041d1b17780d345b3aee44ab75644ade8bfa0ca Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 9 Aug 2024 15:22:31 +0200 Subject: [PATCH 172/518] tools: [MAINTENANCE] replace NFB_DEFAULT_DEV_PATH with nfb_default_dev_path() --- doc/examples/csr.c | 4 ++-- ext/libnfb_ext_grpc/nfb_grpc_server.cc | 2 +- tools-debug/busdebugctl/busdebugctl.c | 2 +- tools-debug/busdump/busdump.c | 2 +- tools-debug/busreplay/busreplay.c | 2 +- tools-debug/nfb-mi-test/nfb-mi-test.c | 4 ++-- tools-misc/nfb-flash-read/flashread.c | 2 +- tools-misc/nfb-spi-max/max-spi.c | 4 ++-- tools/boot/boot.c | 4 ++-- tools/bus/bus.c | 4 ++-- tools/dma/dma.c | 4 ++-- tools/eth/main.c | 4 ++-- tools/info/info.c | 4 ++-- tools/mdio/mdio.c | 4 ++-- 14 files changed, 23 insertions(+), 23 deletions(-) diff --git a/doc/examples/csr.c b/doc/examples/csr.c index 20938cab..99f17b51 100644 --- a/doc/examples/csr.c +++ b/doc/examples/csr.c @@ -12,13 +12,13 @@ int main(int argc, char *argv[]) int node; /* This is the path to device node, you can use - - #define macro: NFB_DEFAULT_DEV_PATH + - NULL or default: nfb_default_dev_path() - full path: "/dev/nfb0" or its shortcut: "0" - persistent path: "/dev/nfb/by-pci-slot/0000:03:00.0" "/dev/nfb/by-serial-no/COMBO-400G1/15432" */ - const char *path = NFB_DEFAULT_DEV_PATH; + const char *path = nfb_default_dev_path(); struct nfb_device *dev; struct nfb_comp *comp; diff --git a/ext/libnfb_ext_grpc/nfb_grpc_server.cc b/ext/libnfb_ext_grpc/nfb_grpc_server.cc index 3f911cc1..8d24eede 100644 --- a/ext/libnfb_ext_grpc/nfb_grpc_server.cc +++ b/ext/libnfb_ext_grpc/nfb_grpc_server.cc @@ -121,7 +121,7 @@ void RunServer(const std::string& path, const std::string& addr) int main(int argc, char** argv) { - const char * path = NFB_DEFAULT_DEV_PATH; + const char * path = nfb_default_dev_path(); const char * addr = "127.0.0.1:50051"; int opt; diff --git a/tools-debug/busdebugctl/busdebugctl.c b/tools-debug/busdebugctl/busdebugctl.c index c9173651..00901bcd 100644 --- a/tools-debug/busdebugctl/busdebugctl.c +++ b/tools-debug/busdebugctl/busdebugctl.c @@ -255,7 +255,7 @@ int main(int argc, char *argv[]) { bool ifc_name = false; /* interface identificator is name (true) or ID (false) */ bool name_found = false; bool all = false; /* indicates to affect all interfaces */ - char *file = NFB_DEFAULT_DEV_PATH; /* default NFB device */ + const char *file = nfb_default_dev_path(); /* default NFB device */ int c; /* temp variable for getopt */ long tmp; /* temp variable */ int probes; diff --git a/tools-debug/busdump/busdump.c b/tools-debug/busdump/busdump.c index 1015e31b..0671ac88 100644 --- a/tools-debug/busdump/busdump.c +++ b/tools-debug/busdump/busdump.c @@ -60,7 +60,7 @@ void usage() { int main(int argc, char *argv[]) { uint32_t tmp; - char *dev_file = NFB_DEFAULT_DEV_PATH, *out_file = NULL; + const char *dev_file = nfb_default_dev_path(), *out_file = NULL; struct nfb_device *dev = NULL; int enable = 0, disable = 0, comp_id = 0; struct nfb_comp *comp = NULL; diff --git a/tools-debug/busreplay/busreplay.c b/tools-debug/busreplay/busreplay.c index dce4dc41..45c808d7 100644 --- a/tools-debug/busreplay/busreplay.c +++ b/tools-debug/busreplay/busreplay.c @@ -60,7 +60,7 @@ void usage() { int main(int argc, char *argv[]) { uint32_t tmp; - char *dev_file = NFB_DEFAULT_DEV_PATH, *out_file = NULL; + const char *dev_file = nfb_default_dev_path(), *out_file = NULL; struct nfb_device *dev = NULL; int enable = 0, disable = 0, comp_id = 0; struct nfb_comp *comp = NULL; diff --git a/tools-debug/nfb-mi-test/nfb-mi-test.c b/tools-debug/nfb-mi-test/nfb-mi-test.c index 2cd8048b..1ddc8c0e 100644 --- a/tools-debug/nfb-mi-test/nfb-mi-test.c +++ b/tools-debug/nfb-mi-test/nfb-mi-test.c @@ -86,7 +86,7 @@ enum commands { void usage(const char *progname) { printf("Usage: %s [-hv] [-d path]\n", progname); - printf("-d path Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); + printf("-d path Path to device [default: %s]\n", nfb_default_dev_path()); printf("-c compatible Compatible string of component to use in test\n"); printf("-t test Select test: random, linear, performance [default: random]\n"); printf("-r Use only reads\n"); @@ -412,7 +412,7 @@ int main(int argc, char *argv[]) int c; int ret = EXIT_SUCCESS; - char *path = NFB_DEFAULT_DEV_PATH; + const char *path = nfb_default_dev_path(); const char *compatible = "cesnet,ofm,mi_test_space"; diff --git a/tools-misc/nfb-flash-read/flashread.c b/tools-misc/nfb-flash-read/flashread.c index 25ea39c2..378670e4 100644 --- a/tools-misc/nfb-flash-read/flashread.c +++ b/tools-misc/nfb-flash-read/flashread.c @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) int index = 0; size_t bs; size_t size = 0, address = 0; - char *path = NFB_DEFAULT_DEV_PATH; + const char *path = nfb_default_dev_path(); char *buffer; struct nfb_device *dev; diff --git a/tools-misc/nfb-spi-max/max-spi.c b/tools-misc/nfb-spi-max/max-spi.c index 18fda272..782ff26e 100644 --- a/tools-misc/nfb-spi-max/max-spi.c +++ b/tools-misc/nfb-spi-max/max-spi.c @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) int do_write_ff; int c, verbose; uint32_t spi_base; - char *file; + const char *file; char *cmdstr; int cmd, i; @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) count = 1; do_write_ff = 0; verbose = 0; - file = NFB_DEFAULT_DEV_PATH; + file = nfb_default_dev_path(); spi_base = CTRL_BASE; cmd = CMD_FLASH_RD; diff --git a/tools/boot/boot.c b/tools/boot/boot.c index 3fc70893..038bc522 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -59,7 +59,7 @@ enum commands { void usage(const char *me) { printf("Usage: %s [-d device] [-b id file] [-f id file] [-F id] [-w id file] [-i file] [-hlqv]\n", me); - printf("-d device Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); + printf("-d device Path to device [default: %s]\n", nfb_default_dev_path()); printf("-F slot Boot device from selected slot\n"); printf("-w slot file Write configuration from file to device slot\n"); printf("-f slot file Write configuration from file to device slot and boot device\n"); @@ -633,7 +633,7 @@ int main(int argc, char *argv[]) int c; long slot = -1; char *slot_arg = NULL; - char *path = NFB_DEFAULT_DEV_PATH; + const char *path = nfb_default_dev_path(); char path_by_pci[PATH_MAX]; char *filename = NULL; int ret = 0; diff --git a/tools/bus/bus.c b/tools/bus/bus.c index 5ef12151..be85f0d5 100644 --- a/tools/bus/bus.c +++ b/tools/bus/bus.c @@ -32,7 +32,7 @@ enum command_t {CMD_NONE, CMD_PRINT_COMPONENTS} command; void usage(const char *me) { printf("Usage: %s [-alh] [-d device] [-p path] [-c compatible] [-i index] [-n count] addr [val]\n", me); - printf("-d device Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); + printf("-d device Path to device [default: %s]\n", nfb_default_dev_path()); printf("-p path Use component with specified path in Device Tree \n"); printf("-c compatible Set compatible string to use [default: \"netcope,bus,mi\"]\n"); printf("-i index Set index of component specified with compatible [default: 0]\n"); @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) { int c; int node; - char *path = NFB_DEFAULT_DEV_PATH; + const char *path = nfb_default_dev_path(); struct nfb_device *dev; struct nfb_comp *comp; diff --git a/tools/dma/dma.c b/tools/dma/dma.c index d7f16789..562795a2 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -86,7 +86,7 @@ static const char * const queries[] = { void usage(const char *me, int verbose) { printf("Usage: %s [-rtRvh] [-i index] [-d path]\n", me); - printf("-d path Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); + printf("-d path Path to device [default: %s]\n", nfb_default_dev_path()); printf("-i indexes Controllers numbers to use - list or range, e.g. \"0-5,7\" [default: all]\n"); printf("-r Use RX DMA queues\n"); printf("-t Use TX DMA queues\n"); @@ -464,7 +464,7 @@ int main(int argc, char *argv[]) int size; char c; - char *file = NFB_DEFAULT_DEV_PATH; + const char *file = nfb_default_dev_path(); struct nfb_device *dev; struct nc_rxqueue *rxq; diff --git a/tools/eth/main.c b/tools/eth/main.c index 52d5afe2..c2347029 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -34,7 +34,7 @@ void usage(const char *progname, int verbose) " [-M mac_cmd] [opt_param]\n", progname); printf("Only one command may be used at a time.\n"); - printf("-d path Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); + printf("-d path Path to device [default: %s]\n", nfb_default_dev_path()); printf("-i indexes Interfaces numbers to use - list or range, e.g. \"0-5,7\" [default: all]\n"); printf("-r Use RXMAC [default]\n"); printf("-t Use TXMAC [default]\n"); @@ -108,7 +108,7 @@ void usage(const char *progname, int verbose) int main(int argc, char *argv[]) { - char *file = NFB_DEFAULT_DEV_PATH; + const char *file = nfb_default_dev_path(); struct nfb_device *dev; const char *query = NULL; char *queries_index = NULL; diff --git a/tools/info/info.c b/tools/info/info.c index b555b7bf..dd2fb0d8 100644 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -72,7 +72,7 @@ static const char * const queries[] = { void usage(const char *progname, int verbose) { printf("Usage: %s [-hv] [-d path]\n", progname); - printf("-d path Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); + printf("-d path Path to device [default: %s]\n", nfb_default_dev_path()); printf("-q query Get specific informations%s\n", verbose ? "" : " (-v for more info)"); if (verbose) { printf(" * project Project name\n"); @@ -475,7 +475,7 @@ int main(int argc, char *argv[]) int c; int ret = EXIT_SUCCESS; - char *path = NFB_DEFAULT_DEV_PATH; + const char *path = nfb_default_dev_path(); struct nfb_device *dev; const char *query = NULL; char *index; diff --git a/tools/mdio/mdio.c b/tools/mdio/mdio.c index 4020a19a..a5a38f88 100644 --- a/tools/mdio/mdio.c +++ b/tools/mdio/mdio.c @@ -25,7 +25,7 @@ enum command_t {CMD_NONE, CMD_PRINT_COMPONENTS} command; void usage(char *tool) { printf("Usage: %s [-h] [-d device] [-l] [-i mdio_index] [-p port_addr] reg [value]\n", tool); - printf("-d device Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); + printf("-d device Path to device [default: %s]\n", nfb_default_dev_path()); printf("-i index Set index of MDIO component [default: 0]\n"); printf("-p port_addr Access to specific port on MDIO controller [default: 0]\n"); printf("reg Device and register address in format D.R\n"); @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) int index = 0; int do_write = 0; int port_addr = 0, dev_addr, reg_addr; - char *path = NFB_DEFAULT_DEV_PATH; + const char *path = nfb_default_dev_path(); uint16_t val = 0; int node; From d0ba8161b78a4078b5c17e9b11437e045974e92d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 9 Aug 2024 15:28:12 +0200 Subject: [PATCH 173/518] pynfb: [MAINTENANCE] use nfb_default_dev_path() --- pynfb/nfb/libnfb.pxd | 1 + pynfb/nfb/libnfb.pyx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pynfb/nfb/libnfb.pxd b/pynfb/nfb/libnfb.pxd index ba6bcf28..c740ddfb 100644 --- a/pynfb/nfb/libnfb.pxd +++ b/pynfb/nfb/libnfb.pxd @@ -21,6 +21,7 @@ cdef extern from "": cdef struct nfb_comp: pass + const char* nfb_default_dev_path() nfb_device* nfb_open(const char* path) void nfb_close(nfb_device* dev) diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 87fa1c5d..6f0a3406 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -66,7 +66,7 @@ cdef class Nfb: :ivar EthManager eth: Ethernet manager object. Exist only when using :func:`nfb.open` """ - default_device = '/dev/nfb0' + default_device = nfb_default_dev_path().decode() def __init__(self, path: str): cdef const char* _fdtc From 75f1c6b7e960102980d948a5dab321e49684e916 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 7 Aug 2024 15:21:53 +0200 Subject: [PATCH 174/518] pynfb: [FEATURE] sanitize names in API - add read_ prefixed function to all transceivers attributes - add is_link function for EthManager / RxMAC - rename get_temperature to read_temperature - rename Nfb.default_device to Nfb.default_dev_path - rename stats_reset/stats_read to reset_stats/read_stats (original function is still present, but deprecated) - rename stats names for rxmac: packets -> total received -> passed octets -> passed_bytes discarded -> errors +dropped = errors + overflowed - rename stats names for txmac: packets -> total octets -> total_bytes discarded -> errors sent -> passed +dropped = errors - rename stats names for RX dma: received -> passed (+bytes) discarded -> dropped (+bytes) - rename stats names for TX dma: sent -> passed (+bytes) --- pynfb/examples/00-quick-reference.py | 10 ++--- pynfb/examples/02-data-transfer.py | 4 +- pynfb/examples/03-eth.py | 29 ++++++------ pynfb/nfb/__init__.py | 6 ++- pynfb/nfb/eth.py | 7 +-- pynfb/nfb/libnetcope.pyx | 67 +++++++++++++++++++++------- pynfb/nfb/libnfb.pyx | 40 ++++++++++------- 7 files changed, 106 insertions(+), 57 deletions(-) diff --git a/pynfb/examples/00-quick-reference.py b/pynfb/examples/00-quick-reference.py index a14528f8..9060aae3 100644 --- a/pynfb/examples/00-quick-reference.py +++ b/pynfb/examples/00-quick-reference.py @@ -53,8 +53,8 @@ msgs_q = ndp.recvmsg(cnt=1, i=0, timeout=1) # 2.C NDP queues statistics -txq.stats_reset() -assert txq.stats_read()["sent"] == 0 +txq.reset_stats() +assert txq.read_stats()["passed"] == 0 # 3.A Single Ethernet port manipulation eth = dev.eth[0] @@ -63,8 +63,8 @@ for mac in [eth.rxmac, eth.txmac]: mac.enable(enable=True) mac.disable() - mac.stats_reset() - assert mac.stats_read()["packets"] == 0 + mac.reset_stats() + assert mac.read_stats()["total"] == 0 # 3.B PCS/PMA management and Transceiver manipulation eth.pcspma.pma_local_loopback = True @@ -75,7 +75,7 @@ val = eth.pmd.i2c.read_reg(1, 0) # 3.C Aggregated Ethernet ports manipulation -assert eth.link == eth.rxmac.link +assert eth.is_link() == eth.rxmac.is_link() dev.eth.enable(enable=False, i=1) dev.eth.disable(i=[0, 1]) diff --git a/pynfb/examples/02-data-transfer.py b/pynfb/examples/02-data-transfer.py index cb55274b..6bd76132 100644 --- a/pynfb/examples/02-data-transfer.py +++ b/pynfb/examples/02-data-transfer.py @@ -134,9 +134,9 @@ try: # stats == {'sent': 4, 'sent_bytes': 276} - stats = txq.stats_read() + stats = txq.read_stats() # Reset Queue statistics - txq.stats_reset() + txq.reset_stats() except Exception: pass diff --git a/pynfb/examples/03-eth.py b/pynfb/examples/03-eth.py index 61804a77..eaeb7e09 100644 --- a/pynfb/examples/03-eth.py +++ b/pynfb/examples/03-eth.py @@ -28,18 +28,18 @@ mac.disable() # check for link status -link_ready = eth.rxmac.link +link_ready = eth.rxmac.is_link() # read RxMAC / TxMAC statistic counters -# rx_stats == {'packets': 0, 'received': 0, 'discarded': 0, 'overflowed': 0, 'octets': 0} -rx_stats = eth.rxmac.stats_read() +# rx_stats == {'total': 0, 'passed': 0, 'passed_bytes': 0, 'dropped': 0, 'overflowed': 0, 'errors': 0} +rx_stats = eth.rxmac.read_stats() -# tx_stats == {'packets': 0, 'octets': 0, 'discarded': 0, 'sent': 0} -tx_stats = eth.txmac.stats_read() +# tx_stats == {'total': 0, 'total_bytes': 0, 'passed': 0, 'dropped': 0, 'errors': 0} +tx_stats = eth.txmac.read_stats() # reset RxMAC / TxMAC statistic counters for mac in [eth.rxmac, eth.txmac]: - mac.stats_reset() + mac.reset_stats() # 3.B PCS/PMA management and Transceiver manipulation @@ -53,12 +53,13 @@ # read 16b value from register 1.7: val = 0 val = eth.pcspma.mdio.read(1, 7) -# None if transceiver isn't present, else an object pmd = eth.pmd -# getters, e.g: val = "FINISAIR CORP." -val = pmd.vendor_name -val = pmd.vendor_pn -val = pmd.vendor_sn +pmd.is_present() in [True, False] + +# val = "FINISAIR CORP." +val = pmd.read_vendor_name() +val = pmd.read_vendor_pn() +val = pmd.read_vendor_sn() if hasattr(pmd, "mdio"): val = pmd.mdio.read(3, 0) elif hasattr(pmd, "i2c"): @@ -70,10 +71,10 @@ # shortcuts to both RxMAC + TxMAC functions eth.enable(False) -eth.stats_reset() +eth.reset_stats() # rxmac link status shortcut -assert eth.link == eth.rxmac.link +assert eth.is_link() == eth.rxmac.is_link() # all Ethernet ports @@ -81,4 +82,4 @@ # selected Ethernet ports dev.eth.enable(i=[0, 1]) dev.eth.enable(False, i=0) -dev.eth.stats_reset() +dev.eth.reset_stats() diff --git a/pynfb/nfb/__init__.py b/pynfb/nfb/__init__.py index 25bb5611..8fd8fd09 100644 --- a/pynfb/nfb/__init__.py +++ b/pynfb/nfb/__init__.py @@ -1,6 +1,6 @@ "Software for control of the CESNET NDK based FPGA acceleration cards" -__all__ = ["open", "eth", "BaseComp"] +__all__ = ["open", "eth", "BaseComp", "default_dev_path"] from . import libnfb from . import eth @@ -10,6 +10,8 @@ import fdt from typing import Optional +default_dev_path = libnfb.Nfb.default_dev_path + class BaseComp(libnfb.AbstractBaseComp): """ @@ -21,6 +23,6 @@ class BaseComp(libnfb.AbstractBaseComp): :ivar libnfb.Comp _comp: Component object """ - def __init__(self, dev=libnfb.Nfb.default_device, node: Optional[fdt.Node]=None, index: int=0): + def __init__(self, dev=default_dev_path, node: Optional[fdt.Node]=None, index: int=0): super().__init__(dev, node, index) self._comp = self._dev.comp_open(self._node) diff --git a/pynfb/nfb/eth.py b/pynfb/nfb/eth.py index d61f2c74..7c9f6dd6 100644 --- a/pynfb/nfb/eth.py +++ b/pynfb/nfb/eth.py @@ -1,5 +1,6 @@ from . import libnetcope + class EthManager: """Object which encapsulates all Ethernet interfaces into nfb""" @@ -23,7 +24,7 @@ def _common_action(self, action, *args, **kwargs): return [getattr(eth, action)(*args, **kwargs) for eth in eths] def __getattr__(self, name): - if name in ["enable", "disable", "stats_reset"]: + if name in ["enable", "disable", "stats_reset", "reset_stats", "is_link"]: return lambda *args, **kwargs: self._common_action(name, *args, **kwargs) else: raise AttributeError @@ -51,9 +52,9 @@ def _common_action(self, action, *args, **kwargs): ] def __getattr__(self, name): - if name in ["link"]: + if name in ["link", "is_link"]: return self.rxmac.__getattribute__(name) - elif name in ["enable", "disable", "stats_reset"]: + elif name in ["enable", "disable", "stats_reset", "reset_stats"]: return lambda *args, **kwargs: self._common_action(name, *args, **kwargs) elif name in ["pma_local_loopback"]: return getattr(self.pcspma, name) diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 20968db5..65a59654 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -56,11 +56,20 @@ cdef class RxMac: def is_enabled(self): return self.enabled + def is_link(self): + return self.link + def stats_reset(self): + self.reset_stats() + + def reset_stats(self): """Reset statistic counters""" nc_rxmac_reset_counters(self._mac) def stats_read(self, etherstats: bool = False): + return self.read_stats(etherstats) + + def read_stats(self, etherstats: bool = False): """ Read statistic counters @@ -92,13 +101,19 @@ cdef class RxMac: 'pkts512to1023Octets': es.pkts512to1023Octets, 'pkts1024to1518Octets': es.pkts1024to1518Octets, } if etherstats else { - 'packets': counters.cnt_total, - 'received': counters.cnt_received, - 'octets': counters.cnt_octets, - 'discarded': counters.cnt_erroneous, - 'overflowed': counters.cnt_overflowed, + 'total': counters.cnt_total, + #'total_bytes': counters.cnt_total_octets, + 'passed': counters.cnt_received, + 'passed_bytes': counters.cnt_octets, + 'dropped': (counters.cnt_erroneous + counters.cnt_overflowed), + 'overflowed': counters.cnt_overflowed, + 'errors': counters.cnt_erroneous, + # 'crc_errors': counters.cnt_crc_errors, + # 'length_errors': counters.cnt_len_errors, + # 'filtered': counters.cnt_filtered, } + cdef class TxMac: cdef NfbDeviceHandle _handle cdef nc_txmac *_mac @@ -138,10 +153,16 @@ cdef class TxMac: return self.enabled def stats_reset(self): + self.reset_stats() + + def reset_stats(self): """Reset statistic counters""" nc_txmac_reset_counters(self._mac) def stats_read(self): + return self.read_stats() + + def read_stats(self): """ Read statistic counters @@ -155,12 +176,14 @@ cdef class TxMac: if ret: return {} return { - 'packets': counters.cnt_total, - 'octets': counters.cnt_octets, - 'discarded': counters.cnt_erroneous, - 'sent': counters.cnt_sent, + 'total': counters.cnt_total, + 'total_bytes': counters.cnt_octets, + 'passed': counters.cnt_sent, + 'dropped': counters.cnt_erroneous, + 'errors': counters.cnt_erroneous, } + cdef class Mdio: cdef NfbDeviceHandle _handle cdef nc_mdio *_mdio @@ -191,6 +214,7 @@ cdef class Mdio: self._init() nc_mdio_write(self._mdio, prtad, devad, reg, val) + cdef class I2c: cdef NfbDeviceHandle _handle cdef nc_i2c_ctrl *_ctrl @@ -223,6 +247,7 @@ cdef class I2c: c_data8 = data ret = nc_i2c_write_reg(self._ctrl, reg, c_data8, len(data)) + cdef class DmaCtrlNdp: cdef NfbDeviceHandle _handle cdef nc_ndp_ctrl _ctrl @@ -382,16 +407,16 @@ cdef class DmaCtrlNdp: ret = {} if self._ctrl.dir == 0: nc_rxqueue_read_counters( self._ctrl_queue, &rxc) - ret['received'] = rxc.received - ret['discarded'] = rxc.discarded + ret['passed'] = rxc.received + ret['dropped'] = rxc.discarded if rxc.have_bytes: - ret['received_bytes'] = txc.received_bytes - ret['discarded_bytes'] = txc.discarded_bytes + ret['passed_bytes'] = txc.received_bytes + ret['dropped_bytes'] = txc.discarded_bytes else: nc_txqueue_read_counters( self._ctrl_queue, &txc) - ret['sent'] = txc.sent + ret['passed'] = txc.sent if txc.have_bytes: - ret['sent_bytes'] = txc.sent + ret['passed_bytes'] = txc.sent return ret @@ -447,3 +472,15 @@ cdef class Transceiver: def vendor_sn(self) -> str: "serial number of the transceiver" return self.i2c.read_reg(196, 16).decode().strip() + + def read_vendor_name(self) -> str: + "vendor of the transceiver" + return self.vendor_name + + def read_vendor_pn(self) -> str: + "product number of the transceiver" + return self.vendor_pn + + def read_vendor_sn(self) -> str: + "serial number of the transceiver" + return self.vendor_sn diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 6f0a3406..8efe8731 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -66,7 +66,7 @@ cdef class Nfb: :ivar EthManager eth: Ethernet manager object. Exist only when using :func:`nfb.open` """ - default_device = nfb_default_dev_path().decode() + default_dev_path = nfb_default_dev_path().decode() def __init__(self, path: str): cdef const char* _fdtc @@ -81,6 +81,8 @@ cdef class Nfb: self.fdt = fdt.parse_dtb(dtb) self.ndp = QueueManager(self) + # TODO: use Nfb.dma only for statistic, not for transfers + self.dma = self.ndp def __dealloc__(self): pass @@ -137,7 +139,7 @@ cdef class Nfb: return self.fdt.get_node(path) return None - def get_temperature(self, units="celsius"): + def read_temperature(self, units="celsius"): cdef int32_t int32 = 0 assert units == "celsius" @@ -314,7 +316,7 @@ cdef class AbstractBaseComp: DT_COMPATIBLE = None - def __init__(self, dev=Nfb.default_device, node: Optional[fdt.Node]=None, index: int=0): + def __init__(self, dev=Nfb.default_dev_path, node: Optional[fdt.Node]=None, index: int=0): assert self.DT_COMPATIBLE is not None, "DT_COMPATIBLE must be set in derived class" self._dev = dev if isinstance(dev, Nfb) else open(dev) @@ -522,9 +524,15 @@ cdef class NdpQueue: self._running = False def stats_read(self): - raise NotImplementedError() + return self.read_stats() def stats_reset(self): + self.reset_stats() + + def read_stats(self): + raise NotImplementedError() + + def reset_stats(self): raise NotImplementedError() @@ -556,16 +564,16 @@ cdef class NdpQueueRx(NdpQueue): """ Check if the queue can transfer data """ raise NotImplementedError() - def stats_reset(self): + def reset_stats(self): """Reset statistic counters""" self._check_nc_queue() libnetcope.nc_rxqueue_reset_counters(self._nc_queue) - def stats_read(self) -> dict: + def read_stats(self) -> dict: """ Read statistic counters - :return: Dictionary with counters values: 'received', 'received_bytes', 'discarded', 'discarded_bytes'. + :return: Dictionary with counters values: 'passed', 'passed_bytes', 'dropped', 'dropped_bytes'. """ cdef libnetcope.nc_rxqueue_counters counters @@ -573,10 +581,10 @@ cdef class NdpQueueRx(NdpQueue): libnetcope.nc_rxqueue_read_counters(self._nc_queue, &counters) return { - 'received': counters.received, - 'received_bytes': counters.received_bytes, - 'discarded': counters.discarded, - 'discarded_bytes': counters.discarded_bytes, + 'passed': counters.received, + 'passed_bytes': counters.received_bytes, + 'dropped': counters.discarded, + 'dropped_bytes': counters.discarded_bytes, } cdef _recvmsg(self, cnt: int = -1, timeout: int = 0): @@ -686,16 +694,16 @@ cdef class NdpQueueTx(NdpQueue): """ Check if the queue can transfer data """ raise NotImplementedError() - def stats_reset(self): + def reset_stats(self): """Reset statistic counters""" self._check_nc_queue() libnetcope.nc_txqueue_reset_counters(self._nc_queue) - def stats_read(self): + def read_stats(self): """ Read statistic counters - :return: Dictionary with counters values: 'sent', 'sent_bytes'. + :return: Dictionary with counters values: 'passed', 'passed_bytes'. """ cdef libnetcope.nc_txqueue_counters counters @@ -703,8 +711,8 @@ cdef class NdpQueueTx(NdpQueue): libnetcope.nc_txqueue_read_counters(self._nc_queue, &counters) return { - 'sent': counters.sent, - 'sent_bytes': counters.sent_bytes, + 'passed': counters.sent, + 'passed_bytes': counters.sent_bytes, } cdef _sendmsg(self, pkts: List[Tuple[bytes, bytes, int]]): # -> None: From 92b27c099555e91feef4c17a890a28728d2a14d1 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 9 Aug 2024 16:58:49 +0200 Subject: [PATCH 175/518] bump version to 6.23.0 --- Changelog | 9 +++++++++ VERSION | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 946cfa09..9e9ba9a5 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,12 @@ +* Fri Aug 9 2024 Martin Spinler - 6.23.0-1 +- [FEATURE] drivers: allow early removal and late attach of PCI endpoint +- [FEATURE] libnfb: use LIBNFB_BUS_DEBUG env. variable for MI read/write logging +- [FEATURE] libnfb: use LIBNFB_DEFAULT_DEV env. variable for specifying default device +- [FEATURE] nfb-info: print BAR size, print list of all available devices +- [FEATURE] nfb-mi-test: tool for testing and benchmarking MI accesses +- [FEATURE] pynfb: lot of sanitized names, improvements, fixes and optimalizations +- [BUGFIX] libnfb: fallback mi_memcpy variant for processors without AVX2 + * Thu Jun 27 2024 Martin Spinler - 6.22.6-1 - [BUGFIX] fix driver bug with include file diff --git a/VERSION b/VERSION index 4e8c9697..0b31cc63 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.22.6 +6.23.0 From 1328217118656a89d0673204e9b47e24f1858659 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 13 Aug 2024 10:12:14 +0200 Subject: [PATCH 176/518] drivers - pci: [FIX] force set pci_index 0, when the value is invalid --- drivers/kernel/drivers/nfb/pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index e355fd05..debe33f2 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -986,6 +986,10 @@ static int nfb_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) dev_info(&pci->dev, "successfully initialized only for DMA transfers\n"); } else { pci_device->is_probed_as_main = 1; + /* backward compatibility: some firmware doesn't have correct index, + this is needed for MI and DMA endpoint pairing */ + if (pci_device->index < 0) + pci_device->index = 0; ret = nfb_pci_probe_main(pci_device, id, nfb_dtb_inject); if (ret) From fee2fce154e9dc77eb2989f1bd91dca1514cd216 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 13 Aug 2024 10:40:45 +0200 Subject: [PATCH 177/518] bump version to 6.23.1 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 9e9ba9a5..4d54d4ed 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Tue Aug 13 2024 Martin Spinler - 6.23.1-1 +- [BUGFIX] drivers: backward compatibility for firmware without valid endpoint index + * Fri Aug 9 2024 Martin Spinler - 6.23.0-1 - [FEATURE] drivers: allow early removal and late attach of PCI endpoint - [FEATURE] libnfb: use LIBNFB_BUS_DEBUG env. variable for MI read/write logging diff --git a/VERSION b/VERSION index 0b31cc63..4f05c0a6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.23.0 +6.23.1 From cce49fd574414502a47213d3be13e13736444659 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 19 Aug 2024 13:53:18 +0200 Subject: [PATCH 178/518] libnetcope - mdio: [FIX] initialize struct nc_mdio --- libnfb/include/netcope/mdio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index d2be4d0a..c34854be 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -318,7 +318,7 @@ static inline void nc_mdio_etile_config(struct nc_mdio *mdio) static inline struct nc_mdio *nc_mdio_open_no_init(const struct nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam) { - struct nc_mdio mdio_tmp; + struct nc_mdio mdio_tmp = {0}; struct nc_mdio *mdio; struct nfb_comp *comp; const char *prop; From 84e349333654998d1c6d6c8914b62e88e4c29429 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 19 Aug 2024 14:15:14 +0200 Subject: [PATCH 179/518] bump version to 6.23.2 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 4d54d4ed..992546f5 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Mon Aug 19 2024 Martin Spinler - 6.23.2-1 +- [BUGFIX] mdio (PCS/PMA): initialize struct nc_mdio with zeros + * Tue Aug 13 2024 Martin Spinler - 6.23.1-1 - [BUGFIX] drivers: backward compatibility for firmware without valid endpoint index diff --git a/VERSION b/VERSION index 4f05c0a6..ab9897ec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.23.1 +6.23.2 From 2e5eea9bc0760e34cf4dee4190ff194fa48ab629 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 23 Aug 2024 09:57:04 +0200 Subject: [PATCH 180/518] libnfb-ext-python: [FIX] remove assert in read function --- .../libnfb_ext_python/libnfb_ext_python.pyx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx index 35784a16..9762d98d 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx +++ b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx @@ -53,13 +53,18 @@ cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset) cdef PyObject* _bus = p cdef object bus = _bus cdef bytes data + cdef ssize_t ret nfb, comp_node, bus_node = bus data = nfb.read(bus_node, comp_node, offset, nbyte) - assert len(data) == int(nbyte) - memcpy(buf, data, nbyte) + ret = len(data) + if ret > int(nbyte): + ret = -1 - return nbyte + if ret > 0: + memcpy(buf, data, ret) + + return ret cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t offset) noexcept: cdef PyObject* _bus = p From b1a9b67f307fbb7aaaadb767b8ed1cc8a074de89 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 28 Aug 2024 15:57:14 +0200 Subject: [PATCH 181/518] nfb-meter: [FIX] update to new pynfb API --- python/nfb-tools/nfbmeter/busdebug.py | 2 +- python/nfb-tools/nfbmeter/eventcounter.py | 4 +-- python/nfb-tools/nfbmeter/nfbmeter.py | 31 ++++++++++++----------- python/nfb-tools/nfbmeter/probes.py | 4 +-- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/python/nfb-tools/nfbmeter/busdebug.py b/python/nfb-tools/nfbmeter/busdebug.py index 1f320250..21b310fd 100644 --- a/python/nfb-tools/nfbmeter/busdebug.py +++ b/python/nfb-tools/nfbmeter/busdebug.py @@ -54,7 +54,7 @@ def bus_drop(self, pid): def bus_enable(self, pid): self._comp.write32(po(pid, self._BUS_CTRLREG), 0) - def stats_read(self, pid): + def read_stats(self, pid): # TODO Check: atomic read / strobe? data = self._comp.read(po(pid, self._WORD_CNT_LOW), self._NAME) cntr = {} diff --git a/python/nfb-tools/nfbmeter/eventcounter.py b/python/nfb-tools/nfbmeter/eventcounter.py index c792925f..6d3ab962 100644 --- a/python/nfb-tools/nfbmeter/eventcounter.py +++ b/python/nfb-tools/nfbmeter/eventcounter.py @@ -103,8 +103,8 @@ def stats_flush_captured(self): self._comp.write32(self._REG_CAPTURE_FIFO, 0) #print(f"FIFO size: {cnt}") - #def stats_read_captured(self, count: int = 0, wait: bool = False): - def stats_read_captured(self): + #def read_stats_captured(self, count: int = 0, wait: bool = False): + def read_stats_captured(self): ret = None ret = {"cycles": 0, "events": 0, "wraps": 0} # What's better to return? valid = True diff --git a/python/nfb-tools/nfbmeter/nfbmeter.py b/python/nfb-tools/nfbmeter/nfbmeter.py index 1fdbd781..923b979e 100755 --- a/python/nfb-tools/nfbmeter/nfbmeter.py +++ b/python/nfb-tools/nfbmeter/nfbmeter.py @@ -30,8 +30,8 @@ class MeterManager(): # Rename dict keys with this map> new_key: orig_key (nk: ok) remaps = { - 'rxmac': {'packets': 'p', 'received': 'r', 'octets': 'b', 'discarded': 'd', 'overflowed': 'o'}, - 'rxdma': {'received': 'p', 'received_bytes': 'b', 'discarded': 'dp', 'discarded_bytes': 'db'}, + 'rxmac': {'total': 'p', 'passed': 'r', 'passed_bytes': 'b', 'errors': 'd', 'overflowed': 'o'}, + 'rxdma': {'passed': 'p', 'passed_bytes': 'b', 'dropped': 'd', 'dropped_bytes': 'db'}, 'eventcounter': {'cycles': 'c', 'events': 'e', 'wraps': 'w'}, 'busdebugprobe': {"words": 'w', "wait": 'i', "dst_hold": 'dh', "src_hold": 'sh', 'sop_cnt': 'sc', 'eop_cnt': 'ec', @@ -83,17 +83,17 @@ def read(self): data = sample.data = {} for i, mac in enumerate(self._rxmac): - data[f"rm{i}"] = mac.stats_read() + data[f"rm{i}"] = mac.read_stats() for i, dma in self._rxdma.items(): - data[f"rd{i}"] = dma.stats_read() + data[f"rd{i}"] = dma.read_stats() for i, bd in enumerate(self._bdc.values()): for p in range(bd.nr_probes): - data[f"{bd.id}_{bd.probe_name[p]}"] = bd.stats_read(p) + data[f"{bd.id}_{bd.probe_name[p]}"] = bd.read_stats(p) for i, (id, ech) in enumerate(self._ech.items()): - data[id] = ech.stats_read_captured() + data[id] = ech.read_stats_captured() return sample @@ -187,7 +187,7 @@ def _display_rxmac(self, o, m, stdscr, items): stdscr.addstr(o, 0, "RxMAC stats") for i, it in enumerate(items['rxmac']): item = m.data[it] - values = {s.title(): item[s] for s in ['packets', 'received', 'discarded', 'overflowed']} + values = {s.title(): item[s] for s in ['total', 'passed', 'errors', 'overflowed']} for w, (text, val) in enumerate(values.items()): stdscr.addstr(o+w+1, 2, text) stdscr.addstr(o+w+1, i*12+12, f"{val:>10}") @@ -195,20 +195,21 @@ def _display_rxmac(self, o, m, stdscr, items): def _display_rxdma(self, o, m, stdscr, items): rows, cols = stdscr.getmaxyx() - dma_total_rcvd = sum(map(lambda x: m.data[x]['received'], items['rxdma'])) - dma_total_disc = sum(map(lambda x: m.data[x]['discarded'], items['rxdma'])) + dma_total_rcvd = sum(map(lambda x: m.data[x]['passed'], items['rxdma'])) + dma_total_disc = sum(map(lambda x: m.data[x]['dropped'], items['rxdma'])) dma_total = dma_total_rcvd + dma_total_disc - stdscr.addstr(o, 0, f"Rx DMA | Total: {dma_total:>11} | Received: {dma_total_rcvd:>11} | Discarded: {dma_total_disc:>11}") + stdscr.addstr(o, 0, f"Rx DMA | Total: {dma_total:>11} | Passed: {dma_total_rcvd:>11} | Dropped: {dma_total_disc:>11}") + for i, it in enumerate(items['rxdma']): item = m.data[it] - stdscr.addstr(o+1, 2, "% Received") - stdscr.addstr(o+2, 2, "% Discarded") + stdscr.addstr(o+1, 2, "% Passed") + stdscr.addstr(o+2, 2, "% Dropped") if (i+1)*12 + 12 >= cols: continue - pct_rcvd = int(item['received']*1000 / dma_total)/10 if dma_total != 0 else '-' - pct_disc = int(item['discarded']*1000 / dma_total)/10 if dma_total != 0 else '-' + pct_rcvd = int(item['passed']*1000 / dma_total)/10 if dma_total != 0 else '-' + pct_disc = int(item['dropped']*1000 / dma_total)/10 if dma_total != 0 else '-' stdscr.addstr(o+1, i*6+14, f"{pct_rcvd:>6}") stdscr.addstr(o+2, i*6+14, f"{pct_disc:>6}") @@ -320,7 +321,7 @@ def meter_loop(stdscr, args, meter, logger, display): def main(): # Argument parsing arguments = argparse.ArgumentParser(description='NFB universal measurement tool') - arguments.add_argument("-d", "--device", action="store", default=libnfb.Nfb.default_device) + arguments.add_argument("-d", "--device", action="store", default=libnfb.Nfb.default_dev_path) arguments.add_argument("-l", "--logfile", action="store", default="/tmp/nfb-meter-stats_{pcislot}.txt") arguments.add_argument("-v", "--verbose", action="store_true") arguments.add_argument("-I", "--interval", action="store", default=1, type=float) diff --git a/python/nfb-tools/nfbmeter/probes.py b/python/nfb-tools/nfbmeter/probes.py index c61e28dc..62e3395e 100644 --- a/python/nfb-tools/nfbmeter/probes.py +++ b/python/nfb-tools/nfbmeter/probes.py @@ -49,9 +49,9 @@ def start(self, capture: bool = True): for ec in self._ec: ec.start(capture) - def stats_read_captured(self): + def read_stats_captured(self): s = [] for ec in self._ec: - s.append(ec.stats_read_captured()) + s.append(ec.read_stats_captured()) return {self._names[i]: s[i]['events'] for i, ec in enumerate(self._ec)} From dd95500be577107417e207b7b2e73b8601ad2c85 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 3 Jun 2024 10:35:13 +0200 Subject: [PATCH 182/518] nfb-meter: [MAINTENANCE] cleanup code --- python/nfb-tools/nfbmeter/busdebug.py | 4 +- python/nfb-tools/nfbmeter/eventcounter.py | 6 +- python/nfb-tools/nfbmeter/nfbmeter.py | 146 ++++++++++++---------- python/nfb-tools/nfbmeter/probes.py | 4 +- python/nfb-tools/nfbmeter/utils.py | 1 + 5 files changed, 88 insertions(+), 73 deletions(-) diff --git a/python/nfb-tools/nfbmeter/busdebug.py b/python/nfb-tools/nfbmeter/busdebug.py index 21b310fd..c1002519 100644 --- a/python/nfb-tools/nfbmeter/busdebug.py +++ b/python/nfb-tools/nfbmeter/busdebug.py @@ -4,6 +4,7 @@ def po(probe_id, reg): return probe_id << 6 | reg + class BusDebugCtl(nfb.BaseComp): DT_COMPATIBLE = "netcope,streaming_debug_master" @@ -34,7 +35,7 @@ def __init__(self, *args, **kwargs): self.probe_name = [] for i in range(self._nr_probes): self.probe_name.append(self._comp.read(po(i, self._NAME), 4).decode()) - + @property def nr_probes(self): return self._nr_probes @@ -67,4 +68,3 @@ def read_stats(self, pid): #cntr['valid'] = cntr['cycles'] - cntr['src_hold'] #cntr['transfer'] = cntr['cycles'] - cntr['src_hold'] return cntr - diff --git a/python/nfb-tools/nfbmeter/eventcounter.py b/python/nfb-tools/nfbmeter/eventcounter.py index 6d3ab962..bd38109a 100644 --- a/python/nfb-tools/nfbmeter/eventcounter.py +++ b/python/nfb-tools/nfbmeter/eventcounter.py @@ -23,7 +23,7 @@ def __init__(self, *args, **kwargs): self._cycles = None - def calibrate(self, reference: "EventCounter"=None): + def calibrate(self, reference: "EventCounter" = None): if isinstance(reference, EventCounter): self.__interval_max = reference.__interval_max self.__freq = reference.__freq @@ -95,7 +95,7 @@ def start(self, capture: bool = True): def stats_flush_captured(self): valid = self._REG_CAPTURE_FIFO_VLD_MASK - cnt = 0 + cnt = 0 while valid: valid = valid & self._comp.read32(self._REG_CAPTURE_FIFO) if valid: @@ -109,7 +109,7 @@ def read_stats_captured(self): ret = {"cycles": 0, "events": 0, "wraps": 0} # What's better to return? valid = True while valid: - reg = self._comp.read32(self._REG_CAPTURE_FIFO) + reg = self._comp.read32(self._REG_CAPTURE_FIFO) self._comp.write32(self._REG_CAPTURE_FIFO, 0) valid = reg & self._REG_CAPTURE_FIFO_VLD_MASK value = reg & self._REG_CAPTURE_FIFO_DATA_MASK diff --git a/python/nfb-tools/nfbmeter/nfbmeter.py b/python/nfb-tools/nfbmeter/nfbmeter.py index 923b979e..986318b9 100755 --- a/python/nfb-tools/nfbmeter/nfbmeter.py +++ b/python/nfb-tools/nfbmeter/nfbmeter.py @@ -33,9 +33,7 @@ class MeterManager(): 'rxmac': {'total': 'p', 'passed': 'r', 'passed_bytes': 'b', 'errors': 'd', 'overflowed': 'o'}, 'rxdma': {'passed': 'p', 'passed_bytes': 'b', 'dropped': 'd', 'dropped_bytes': 'db'}, 'eventcounter': {'cycles': 'c', 'events': 'e', 'wraps': 'w'}, - 'busdebugprobe': {"words": 'w', "wait": 'i', "dst_hold": 'dh', "src_hold": 'sh', - 'sop_cnt': 'sc', 'eop_cnt': 'ec', - } + 'busdebugprobe': {"words": 'w', "wait": 'i', "dst_hold": 'dh', "src_hold": 'sh', 'sop_cnt': 'sc', 'eop_cnt': 'ec'} } def __init__(self, dev, config): @@ -49,12 +47,14 @@ def __init__(self, dev, config): self._ech = {} for p in self._config.get('probes', []): cfg = SimpleNamespace(**p) - if cfg.type == "event_counter_histogram": - probe = EventCounterHistogram(dev, cfg) - self._ech.update({cfg.id: probe}) - if cfg.type == "busdebug": - probe = BusDebugProbe(dev, cfg) - self._bdc.update({cfg.id: probe}) + types = { + "event_counter_histogram": (EventCounterHistogram, self._ech), + "busdebug": (BusDebugProbe, self._bdc), + } + if cfg.type in types: + cls, dic = types[cfg.type] + probe = cls(dev, cfg) + dic.update({cfg.id: probe}) def init(self): for probe in self._ech.values(): @@ -132,11 +132,11 @@ def to_json(self, m: SimpleNamespace): if False and "remap": ret['data'].update({ - **{unit_name: { + **{ + unit_name: { nk: m.data[unit_name][ok] for ok, nk in remap.items() - # if unit[ok] != 0 # Compress even more and do not include items with zero value } for unit_type, remap in self.remaps.items() - for unit_name in self._items[unit_type] + for unit_name in self._items[unit_type] } }) @@ -168,6 +168,7 @@ def get_basic_info(dev): #info.dts = dev.fdt.to_dts(tabsize=0) return info + def info_to_json(info): ret = vars(info) ret['tp'] = "info" # type of the record @@ -175,6 +176,7 @@ def info_to_json(info): ret['build_time'] = str(ret['build_time']) return json.dumps(vars(info)) + class MeterDisplay(): def __init__(self, meter, config): self._meter = meter @@ -183,40 +185,42 @@ def __init__(self, meter, config): if not self._config.get("display"): self._config["display"] = [] - def _display_rxmac(self, o, m, stdscr, items): - stdscr.addstr(o, 0, "RxMAC stats") + def addstr(self, y, x, text): + try: + self._s.addstr(y, x, text) + except Exception: + pass + + def _display_rxmac(self, o, m, items): + self.addstr(o, 0, "RxMAC stats") for i, it in enumerate(items['rxmac']): item = m.data[it] values = {s.title(): item[s] for s in ['total', 'passed', 'errors', 'overflowed']} for w, (text, val) in enumerate(values.items()): - stdscr.addstr(o+w+1, 2, text) - stdscr.addstr(o+w+1, i*12+12, f"{val:>10}") + self.addstr(o+w+1, 2, text) + self.addstr(o+w+1, i*12+12, f"{val:>10}") return 6 - def _display_rxdma(self, o, m, stdscr, items): - rows, cols = stdscr.getmaxyx() + def _display_rxdma(self, o, m, items): dma_total_rcvd = sum(map(lambda x: m.data[x]['passed'], items['rxdma'])) dma_total_disc = sum(map(lambda x: m.data[x]['dropped'], items['rxdma'])) dma_total = dma_total_rcvd + dma_total_disc - stdscr.addstr(o, 0, f"Rx DMA | Total: {dma_total:>11} | Passed: {dma_total_rcvd:>11} | Dropped: {dma_total_disc:>11}") + self.addstr(o+1, 0, f"Rx DMA | Total: {dma_total:>11} | Passed: {dma_total_rcvd:>11} | Dropped: {dma_total_disc:>11}") + self.addstr(o+1, 2, "% Passed") + self.addstr(o+2, 2, "% Dropped") for i, it in enumerate(items['rxdma']): item = m.data[it] - stdscr.addstr(o+1, 2, "% Passed") - stdscr.addstr(o+2, 2, "% Dropped") - - if (i+1)*12 + 12 >= cols: - continue pct_rcvd = int(item['passed']*1000 / dma_total)/10 if dma_total != 0 else '-' pct_disc = int(item['dropped']*1000 / dma_total)/10 if dma_total != 0 else '-' - stdscr.addstr(o+1, i*6+14, f"{pct_rcvd:>6}") - stdscr.addstr(o+2, i*6+14, f"{pct_disc:>6}") + self.addstr(o+1, i*6+14, f"{pct_rcvd:>6}") + self.addstr(o+2, i*6+14, f"{pct_disc:>6}") return 4 - def _display_busdebug(self, o, m, stdscr, config): + def _display_busdebug(self, o, m, config): for i, it in enumerate(config.probes): include = config.include if hasattr(config, "include") else self._meter._bdc[it].probe_name for j, pname in enumerate(include): @@ -226,15 +230,15 @@ def _display_busdebug(self, o, m, stdscr, config): words, wait, dst_hold, src_hold = \ (int(x * 1000 / cycles) / 10 for x in [words, wait, dst_hold, src_hold]) - stdscr.addstr(o+2+j, 0 , pname) - stdscr.addstr(o+1, 0, "%") + self.addstr(o+2+j, 0, pname) + self.addstr(o+1, 0, "%") values = {"Words": words, "Idle": wait, "DST H": dst_hold, "SRC H": src_hold} for w, (text, value) in enumerate(values.items()): - stdscr.addstr(o+1, 5+w*6 + i*30, text) - stdscr.addstr(o+2+j, 5+w*6 + i*30, f"{value:>5}") + self.addstr(o+1, 5+w*6 + i*30, text) + self.addstr(o+2+j, 5+w*6 + i*30, f"{value:>5}") return j + 4 - def _display_histogram(self, o, m, stdscr, config): + def _display_histogram(self, o, m, config): prev_bins_names = None probes = config.probes @@ -249,17 +253,17 @@ def _display_histogram(self, o, m, stdscr, config): prev_bins_names = histograms.keys() for j, bin_name in enumerate(prev_bins_names): x, y = (2, j + 1) if horiz else (j*8+14, i) - stdscr.addstr(o+y, x, f"{bin_name:>8}") + self.addstr(o+y, x, f"{bin_name:>8}") x, y = (i*8+12, o) if horiz else (2, o+i+1) - stdscr.addstr(y, x, ech.name) + self.addstr(y, x, ech.name) vals = histograms.values() total = sum(vals) for j, bin_value in enumerate(vals): pct = int(bin_value*1000 / total) / 10 if total != 0 else '-' x, y = (i*8+12, j + 1) if horiz else (j*8+14, i + 1) - stdscr.addstr(o+y, x, f"{pct:>8}") + self.addstr(o+y, x, f"{pct:>8}") return 2 + len(prev_bins_names) if horiz else 1 + len(probes) @@ -267,30 +271,31 @@ def display(self, stdscr, m): self._o = 0 self._s = stdscr - rows, cols = stdscr.getmaxyx() items = self._meter._items o = 0 - stdscr.addstr(o, 0, f"Time diff: {m.interval}") + self.addstr(o, 0, f"Time diff: {m.interval}") o += 1 for config in self._config["display"]: config = SimpleNamespace(**config) if hasattr(config, "name"): - stdscr.addstr(o, 0, config.name) + self.addstr(o, 0, config.name) if config.type == "histogram": - o += self._display_histogram(o, m, stdscr, config) + o += self._display_histogram(o, m, config) if config.type == "busdebug": - o += self._display_busdebug(o, m, stdscr, config) + o += self._display_busdebug(o, m, config) if config.type == "rxdma": - o += self._display_rxdma(o, m, stdscr, items) + o += self._display_rxdma(o, m, items) if config.type == "rxmac": - o += self._display_rxmac(o, m, stdscr, items) + o += self._display_rxmac(o, m, items) stdscr.refresh() + if isinstance(stdscr, NoCurses): + print("-" * 60) def meter_loop(stdscr, args, meter, logger, display): @@ -314,8 +319,32 @@ def meter_loop(stdscr, args, meter, logger, display): time.sleep(args.interval) display.display(stdscr, m) - if isinstance(stdscr, NoCurses): - print("-" * 60) + + +def get_wrapper(args): + return curses.wrapper if args.display else nocurses_wrapper + + +def get_config(args, **kwargs): + defcfg_path = "/usr/share/ndk-fw/" + defcfg_name = "nfb-meter-cfg" + info = SimpleNamespace(**kwargs) + + if args.config is None: + try: + args.config = f"{defcfg_path}{info.card_name}-{info.project_name}-{info.project_variant}-{info.project_version}-{defcfg_name}.yaml" + except Exception: + raise Exception("Can't deduce default config filename, specify config file explicitly.") + + try: + with open(args.config) as stream: + config = yaml.safe_load(stream) + except Exception: + raise Exception("Can't load configuration file.") + + assert config['version'] == "0.1", "Incorrect version of config file" + + return config def main(): @@ -337,7 +366,7 @@ def main(): print(f"Logging to {fn}") bi = get_basic_info(dev) - logging.basicConfig(format='%(message)s', filename=fn, level=logging.DEBUG)#, encoding='utf-8') + logging.basicConfig(format='%(message)s', filename=fn, level=logging.DEBUG) # encoding='utf-8') logging.debug(info_to_json(bi)) info = SimpleNamespace() @@ -347,23 +376,8 @@ def main(): except Exception: pass - # Load probe configuration - defcfg_path = "/usr/share/ndk-fw/" - defcfg_name = "nfb-meter-cfg" - - if args.config is None: - try: - args.config = f"{defcfg_path}{info.card_name}-{info.project_name}-{info.project_variant}-{info.project_version}-{defcfg_name}.yaml" - except Exception: - raise Exception("Can't deduce default config filename, specify config file explicitly.") - - try: - with open(args.config) as stream: - config = yaml.safe_load(stream) - except Exception: - raise Exception("Can't load configuration file.") - - assert config['version'] == "0.1", "Incorrect version of config file" + # Load probe configuration + config = get_config(args, **vars(info)) # Init MeterManager and MeterDisplay meter = MeterManager(dev, config) @@ -372,9 +386,9 @@ def main(): display = MeterDisplay(meter, config) # Log base informations - logging.debug(json.dumps({'tp':'units', **meter._items})) + logging.debug(json.dumps({'tp': 'units', **meter._items})) if args.verbose: - print("Units:\n" + json.dumps({'tp':'units', **meter._items})) + print("Units:\n" + json.dumps({'tp': 'units', **meter._items})) print() # Run measurement loop @@ -382,8 +396,8 @@ def main(): logger.write(info_to_json(get_basic_info(dev)) + linesep) meter.unlock() - wrapper = curses.wrapper if args.display else nocurses_wrapper - wrapper(meter_loop, args, meter, logger, display) + get_wrapper(args)(meter_loop, args, meter, logger, display) + if __name__ == '__main__': main() diff --git a/python/nfb-tools/nfbmeter/probes.py b/python/nfb-tools/nfbmeter/probes.py index 62e3395e..0680b33c 100644 --- a/python/nfb-tools/nfbmeter/probes.py +++ b/python/nfb-tools/nfbmeter/probes.py @@ -3,6 +3,7 @@ from types import SimpleNamespace + class Probe: def __init__(self, dev, cfg): self._dev = dev @@ -36,7 +37,7 @@ def __init__(self, dev, cfg): if data.calibration_group not in cg: cg.update({data.calibration_group: []}) cg[data.calibration_group].append(ec) - + self._ec.append(ec) self._names.append(bin.name) @@ -54,4 +55,3 @@ def read_stats_captured(self): for ec in self._ec: s.append(ec.read_stats_captured()) return {self._names[i]: s[i]['events'] for i, ec in enumerate(self._ec)} - diff --git a/python/nfb-tools/nfbmeter/utils.py b/python/nfb-tools/nfbmeter/utils.py index 671aa761..26dd5b48 100644 --- a/python/nfb-tools/nfbmeter/utils.py +++ b/python/nfb-tools/nfbmeter/utils.py @@ -18,5 +18,6 @@ def addstr(self, row, col, text): orig = self._buffers[row] self._buffers[row] = orig[:col] + text + orig[col+len(text):] + def nocurses_wrapper(fn, *args, **kwargs): fn(NoCurses(), *args, **kwargs) From 33cad378a55e7cf6aa3ab6852c51606128a2da6f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 28 Aug 2024 15:41:23 +0200 Subject: [PATCH 183/518] nfb-meter: [FEATURE] split 'busdebugprobe' item in 'units' to probe and subprobe name --- python/nfb-tools/nfbmeter/nfbmeter.py | 30 +++++++++++++++++---------- python/nfb-tools/nfbmeter/version.py | 1 + 2 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 python/nfb-tools/nfbmeter/version.py diff --git a/python/nfb-tools/nfbmeter/nfbmeter.py b/python/nfb-tools/nfbmeter/nfbmeter.py index 986318b9..326fe444 100755 --- a/python/nfb-tools/nfbmeter/nfbmeter.py +++ b/python/nfb-tools/nfbmeter/nfbmeter.py @@ -23,6 +23,7 @@ import curses +from . import version from .utils import nocurses_wrapper, NoCurses from .probes import EventCounterHistogram, BusDebugProbe @@ -71,9 +72,11 @@ def init(self): self._items = { "rxmac": [f"rm{i}" for i, _ in enumerate(self._rxmac)], "rxdma": [f"rd{i}" for i in self._rxdma.keys()], - "busdebugprobe": [ - *[f"{bd.id}_{bd.probe_name[p]}" for i, bd in enumerate(self._bdc.values()) for p in range(bd.nr_probes)], - ], + "busdebugprobe": { + f"{bd.id}": { + bd.probe_name[p]: f"{bd.id}_{bd.probe_name[p]}" for p in range(bd.nr_probes) + } for bd in self._bdc.values() + }, "eventcounter_histogram": list(self._ech.keys()), } @@ -110,7 +113,8 @@ def measure(self): rel.data = {} # Compute difference of particular keys of all items with absolute value (no counter reset between two measurements) - diffable_items = self._items['rxmac'] + self._items['rxdma'] + self._items['busdebugprobe'] + diffable_bdb = [name for bdp in self._items['busdebugprobe'].values() for name in bdp.values()] + diffable_items = self._items['rxmac'] + self._items['rxdma'] + diffable_bdb for ic, ip, ik in [(sc.data[item], sp.data[item], item) for item in diffable_items]: rel.data[ik] = {key: (ic[key] - ip[key]) for key in ic.keys()} @@ -172,7 +176,7 @@ def get_basic_info(dev): def info_to_json(info): ret = vars(info) ret['tp'] = "info" # type of the record - ret['ver'] = "0.1.0" + ret['ver'] = version.version ret['build_time'] = str(ret['build_time']) return json.dumps(vars(info)) @@ -222,15 +226,19 @@ def _display_rxdma(self, o, m, items): def _display_busdebug(self, o, m, config): for i, it in enumerate(config.probes): - include = config.include if hasattr(config, "include") else self._meter._bdc[it].probe_name - for j, pname in enumerate(include): - item = m.data[f"{it}_{pname}"] + if hasattr(config, "include"): + include = {name: f"{it}_{name}" for name in config.include} + else: + include = self._items['busdebugprobe'][it] + + for j, (desc, pname) in enumerate(include.items()): + item = m.data[pname] cycles, words, wait, dst_hold, src_hold = (item[x] for x in ['cycles', 'words', 'wait', 'dst_hold', 'src_hold']) words, wait, dst_hold, src_hold = \ (int(x * 1000 / cycles) / 10 for x in [words, wait, dst_hold, src_hold]) - self.addstr(o+2+j, 0, pname) + self.addstr(o+2+j, 0, desc) self.addstr(o+1, 0, "%") values = {"Words": words, "Idle": wait, "DST H": dst_hold, "SRC H": src_hold} for w, (text, value) in enumerate(values.items()): @@ -244,7 +252,6 @@ def _display_histogram(self, o, m, config): for i, it in enumerate(probes): histograms = m.data[it] - ech = self._meter._ech[it] horiz = hasattr(config, 'style') and config.style == 'horizontal' @@ -256,7 +263,8 @@ def _display_histogram(self, o, m, config): self.addstr(o+y, x, f"{bin_name:>8}") x, y = (i*8+12, o) if horiz else (2, o+i+1) - self.addstr(y, x, ech.name) + pb = [p for p in self._config['probes'] if p['id'] == it][0] + self.addstr(y, x, pb['name']) vals = histograms.values() total = sum(vals) diff --git a/python/nfb-tools/nfbmeter/version.py b/python/nfb-tools/nfbmeter/version.py new file mode 100644 index 00000000..181e9f09 --- /dev/null +++ b/python/nfb-tools/nfbmeter/version.py @@ -0,0 +1 @@ +version = "0.2.0" From 3c5ad57a41e4e48117b92e08ce4f7f92db0baba5 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 28 Aug 2024 18:46:51 +0200 Subject: [PATCH 184/518] nfb-meter: [MAINTENANCE]: introduce log migration from 0.1.0 to 0.2.0 --- python/nfb-tools/nfbmeter/migrations.py | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 python/nfb-tools/nfbmeter/migrations.py diff --git a/python/nfb-tools/nfbmeter/migrations.py b/python/nfb-tools/nfbmeter/migrations.py new file mode 100644 index 00000000..789e6093 --- /dev/null +++ b/python/nfb-tools/nfbmeter/migrations.py @@ -0,0 +1,59 @@ +# Copyright (C) 2023 CESNET z. s. p. o. +# Author: Martin Spinler +# +# SPDX-License-Identifier: BSD-3-Clause +from . import version + + +def v010_to_v020_units(items, state): + items = items.copy() + if 'busdebugprobe' in items: + bdps_orig = items['busdebugprobe'] + bdps = items['busdebugprobe'] = {} + for bd in bdps_orig: + name, pname = bd.rsplit("_", 1) + if name not in bdps: + bdps.update({name: {}}) + bdps[name].update({pname: f"{name}_{pname}"}) + + state['units'] = items + return items + + +def v010_to_v020_m(m, state): + units = state['units'] + for k, v in m['data'].items(): + if k in units['rxmac']: + kmap = {'packets': 'total', 'received': 'passed', 'octets': 'passed_bytes', 'discarded': 'errors'} + for k_old, k_new in kmap.items(): + v[k_new] = v.pop(k_old) + if k in units['rxdma']: + kmap = {'received': 'passed', 'discarded': 'dropped', 'received_bytes': 'passed_bytes', 'discarded_bytes': 'dropped_bytes'} + for k_old, k_new in kmap.items(): + v[k_new] = v.pop(k_old) + return m + + +def migrate_lines(m, fixups): + if m['tp'] == 'info': + if fixups is None or m['ver'] == version.version: + fixups = { + '__state__': {}, + 'units': lambda m, s: m, + 'm': lambda m, s: m, + } + + if m['ver'] == "0.1.0": + fixups['units'] = v010_to_v020_units + fixups['m'] = v010_to_v020_m + else: + raise NotImplementedError + + elif m['tp'] == 'units': + assert fixups is not None + m = fixups['units'](m, fixups['__state__']) + elif m['tp'] == 'm': + assert fixups is not None + m = fixups['m'](m, fixups['__state__']) + + return m, fixups From 11bfaa481f1b48057cce6383d1b0cce983dfb3cb Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 28 Aug 2024 18:46:58 +0200 Subject: [PATCH 185/518] nfb-meter: [FEATURE] add offline mode --- python/nfb-tools/nfbmeter/nfbmeter.py | 46 ++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/python/nfb-tools/nfbmeter/nfbmeter.py b/python/nfb-tools/nfbmeter/nfbmeter.py index 326fe444..58031677 100755 --- a/python/nfb-tools/nfbmeter/nfbmeter.py +++ b/python/nfb-tools/nfbmeter/nfbmeter.py @@ -24,6 +24,7 @@ import curses from . import version +from .migrations import migrate_lines from .utils import nocurses_wrapper, NoCurses from .probes import EventCounterHistogram, BusDebugProbe @@ -182,8 +183,8 @@ def info_to_json(info): class MeterDisplay(): - def __init__(self, meter, config): - self._meter = meter + def __init__(self, items, config): + self._items = items self._config = config if not self._config.get("display"): @@ -279,7 +280,7 @@ def display(self, stdscr, m): self._o = 0 self._s = stdscr - items = self._meter._items + items = self._items o = 0 self.addstr(o, 0, f"Time diff: {m.interval}") o += 1 @@ -306,6 +307,38 @@ def display(self, stdscr, m): print("-" * 60) +def display_loop(stdscr, args): + fixups = None + config = None + items = None + display = None + + lines = open(args.load_logfile).readlines() + + for ln in lines: + try: + m = json.loads(ln) + except Exception: + continue + m, fixups = migrate_lines(m, fixups) + + if m['tp'] == 'info': + config = get_config(args, **m) + + if m['tp'] == 'units': + items = m.copy() + + if display is None and items is not None and config is not None: + display = MeterDisplay(items, config) + + if m['tp'] == 'm': + if display is None: + continue + + time.sleep(1) + display.display(stdscr, SimpleNamespace(**m)) + + def meter_loop(stdscr, args, meter, logger, display): print_once = True t_toolstart = time.time() @@ -360,6 +393,7 @@ def main(): arguments = argparse.ArgumentParser(description='NFB universal measurement tool') arguments.add_argument("-d", "--device", action="store", default=libnfb.Nfb.default_dev_path) arguments.add_argument("-l", "--logfile", action="store", default="/tmp/nfb-meter-stats_{pcislot}.txt") + arguments.add_argument("-L", "--load_logfile", action="store") arguments.add_argument("-v", "--verbose", action="store_true") arguments.add_argument("-I", "--interval", action="store", default=1, type=float) arguments.add_argument("-D", "--display", action="store", default=None, help='display mode') @@ -367,6 +401,10 @@ def main(): arguments.add_argument("-c", "--config", action="store", default=None) args = arguments.parse_args() + if args.load_logfile: + get_wrapper(args)(display_loop, args) + exit(0) + dev = nfb.open(args.device) pcislot = dev.fdt.get_node("/system/device/endpoint0").get_property("pci-slot").value @@ -391,7 +429,7 @@ def main(): meter = MeterManager(dev, config) meter.init() - display = MeterDisplay(meter, config) + display = MeterDisplay(meter._items, config) # Log base informations logging.debug(json.dumps({'tp': 'units', **meter._items})) From 2f8dd4eaf6753612ce4c3c038331c1cdb8335712 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 29 Aug 2024 08:00:26 +0200 Subject: [PATCH 186/518] bump version to 6.23.3 --- Changelog | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 992546f5..81d8dd0d 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +* Thu Aug 29 2024 Martin Spinler - 6.23.3-1 +- [FEATURE] nfb-meter: add offline mode +- [BUGFIX] nfb-meter: update to new pynfb names + * Mon Aug 19 2024 Martin Spinler - 6.23.2-1 - [BUGFIX] mdio (PCS/PMA): initialize struct nc_mdio with zeros diff --git a/VERSION b/VERSION index ab9897ec..2e0cb2e4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.23.2 +6.23.3 From d95cc50b24d6fe2bcff65daca5f327b000d137b5 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 29 Aug 2024 09:50:30 -0400 Subject: [PATCH 187/518] tool - ndp: [FIX] do not clear main counters in multithread stats This allows to correctly check packet limits. --- tools/ndptool/common.h | 10 ++++++---- tools/ndptool/stats.c | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index d7ba62fc..48c14c7e 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -48,16 +48,18 @@ typedef enum fastwrite_mode { struct stats_info { unsigned long long packet_cnt; unsigned long long bytes_cnt; - + unsigned long long last_packet_cnt; + unsigned long long last_bytes_cnt; + unsigned long long last_update; unsigned long long progress_counter; unsigned long long sampling; - char progress_letter; - enum progress_type progress_type; - unsigned long long thread_packet_cnt; unsigned long long thread_bytes_cnt; unsigned long long thread_total_bytes_cnt; void *priv; + + char progress_letter; + enum progress_type progress_type; bool incremental; struct timeval startTime; diff --git a/tools/ndptool/stats.c b/tools/ndptool/stats.c index 447f4884..ff39d838 100644 --- a/tools/ndptool/stats.c +++ b/tools/ndptool/stats.c @@ -245,15 +245,17 @@ void update_stats_thread(struct ndp_packet *packets, int count, struct stats_inf { update_print_progress(packets, count, si); - if (si->packet_cnt > 100000 || count == 0) { + si->last_update += count; + if (si->last_update > 100000 || count == 0) { /* Update global stats */ pthread_spin_lock(&((struct thread_data *)si->priv)->lock); - si->thread_packet_cnt += si->packet_cnt; - si->thread_bytes_cnt += si->bytes_cnt; + si->thread_packet_cnt += (si->packet_cnt - si->last_packet_cnt); + si->thread_bytes_cnt += (si->bytes_cnt - si->last_bytes_cnt); pthread_spin_unlock(&((struct thread_data *)si->priv)->lock); - si->packet_cnt = 0; - si->bytes_cnt = 0; + si->last_packet_cnt = si->packet_cnt; + si->last_bytes_cnt = si->bytes_cnt; + si->last_update = 0; } } From aa34698f68ae4751d0e4e87b52d83bfa2e17b4e8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 30 Aug 2024 10:37:16 +0200 Subject: [PATCH 188/518] tools: [MAINTENANCE] replace NFB_DEFAULT_DEV_PATH with nfb_default_dev_path() --- tools-misc/nfb-flash-ident/flashident.c | 2 +- tools/ndptool/main.c | 4 ++-- tools/tsu/tsu.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools-misc/nfb-flash-ident/flashident.c b/tools-misc/nfb-flash-ident/flashident.c index 970f7b53..dbd7373a 100644 --- a/tools-misc/nfb-flash-ident/flashident.c +++ b/tools-misc/nfb-flash-ident/flashident.c @@ -209,7 +209,7 @@ int main(int argc, char *argv[]) int fdt_offset; const char *card_name; char *file = NULL; - char *path = NFB_DEFAULT_DEV_PATH; + const char *path = nfb_default_dev_path(); void *buffer; void *fip; diff --git a/tools/ndptool/main.c b/tools/ndptool/main.c index 959b384f..4d8c2714 100644 --- a/tools/ndptool/main.c +++ b/tools/ndptool/main.c @@ -65,7 +65,7 @@ static void usage(char *me, int mode_preset) } printf("Common parameters:\n"); - printf(" -d path Path to device [default: %s]\n", NFB_DEFAULT_DEV_PATH); + printf(" -d path Path to device [default: %s]\n", nfb_default_dev_path()); printf(" -i indexes Queues numbers to use - list or range, e.g. \"0-5,7\" [default: all]\n"); printf(" -h Show this text\n"); printf(" -p packets Stop receiving or transmitting after packets\n"); @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) memset(¶ms, 0, sizeof(params)); - params.nfb_path = NFB_DEFAULT_DEV_PATH; + params.nfb_path = nfb_default_dev_path(); params.queue_index = -1; params.si.progress_type = PT_NONE; params.si.sampling = 1; diff --git a/tools/tsu/tsu.c b/tools/tsu/tsu.c index 45944fe6..08a5cbbe 100644 --- a/tools/tsu/tsu.c +++ b/tools/tsu/tsu.c @@ -431,7 +431,7 @@ void usage() { printf("Usage: %s [-Dh] [-d path] [-i index]\n", PROGNAME); printf("-c source Select CLK source (higher the number -> more accurate CLK source)\n"); - printf("-d path Use device file, instead of default %s\n", NFB_DEFAULT_DEV_PATH); + printf("-d path Use device file, instead of default %s\n", nfb_default_dev_path()); printf("-i index Set index of the TSU component [default: 0]\n"); printf("-D Debug mode (run in foreground)\n"); printf("-h Show this text\n"); @@ -439,7 +439,7 @@ void usage() int main(int argc, char *argv[]) { - char *path = NFB_DEFAULT_DEV_PATH; + const char *path = nfb_default_dev_path(); char c; long param; int index = 0; From 71becc957e9fddf20b4cfd41f6b93c5b547ed147 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 30 Aug 2024 12:02:20 +0200 Subject: [PATCH 189/518] nfb-meter: [FIX] set correct line offset in RxDMA probe display --- python/nfb-tools/nfbmeter/nfbmeter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/nfb-tools/nfbmeter/nfbmeter.py b/python/nfb-tools/nfbmeter/nfbmeter.py index 58031677..d4c13441 100755 --- a/python/nfb-tools/nfbmeter/nfbmeter.py +++ b/python/nfb-tools/nfbmeter/nfbmeter.py @@ -210,7 +210,7 @@ def _display_rxdma(self, o, m, items): dma_total_rcvd = sum(map(lambda x: m.data[x]['passed'], items['rxdma'])) dma_total_disc = sum(map(lambda x: m.data[x]['dropped'], items['rxdma'])) dma_total = dma_total_rcvd + dma_total_disc - self.addstr(o+1, 0, f"Rx DMA | Total: {dma_total:>11} | Passed: {dma_total_rcvd:>11} | Dropped: {dma_total_disc:>11}") + self.addstr(o+0, 0, f"Rx DMA | Total: {dma_total:>11} | Passed: {dma_total_rcvd:>11} | Dropped: {dma_total_disc:>11}") self.addstr(o+1, 2, "% Passed") self.addstr(o+2, 2, "% Dropped") From 3a2eadd117223ad10fd0986e68198204323ff477 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 6 Sep 2024 17:32:35 +0200 Subject: [PATCH 190/518] drivers: [FIX] add missing nfb_pci_fdt_update_endpoints --- drivers/kernel/drivers/nfb/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index debe33f2..37d5ae2e 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -202,7 +202,9 @@ static void nfb_pci_fdt_update_endpoints(struct nfb_device *nfb) node = fdt_add_subnode(fdt, node, node_name); } - if (pci_device->is_probed_as_main || pci_device->is_probed_as_sub) { + /* In this moment, the device is prepared to provide all info, + even the attached but not yet probed subdevice. */ + if (pci_device->is_probed_as_main || (pci_device->is_probed_as_sub | 1)) { fdt_setprop_string(fdt, node, "pci-slot", pci_name(pci_device->pci)); fdt_setprop_u32(fdt, node, "numa-node", dev_to_node(&pci_device->pci->dev)); From f29ba7d1cbd16f595237c199c2ed04600843e24e Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Tue, 17 Sep 2024 14:23:56 +0200 Subject: [PATCH 191/518] libnetcope - mdio: [FIX] Disable accessing RSFEC subsystem for 10/40GE PMA's causing DRP bus stuck --- libnfb/include/netcope/mdio.h | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index c34854be..bfba60a3 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -28,6 +28,8 @@ extern "C" { #define FTILE_PCS_BASE_200G 0x4000 #define FTILE_PCS_BASE_400G 0x5000 +#define ETILE_RSFEC_PAGE 9 + /* MDIO component lock features */ #define DRP_IFC (1 << 0) #define ATTR_IFC (1 << 2) @@ -58,6 +60,7 @@ struct nc_mdio { int (*mdio_write)(struct nfb_comp *dev, int prtad, int devad, uint16_t addr, uint16_t val); int pcspma_is_e_tile; int pcspma_is_f_tile; + int rsfec_supported; int pma_lanes; /* Number of PMA lanes */ enum mdio_pma_enc link_encoding; /* Line modulation */ enum mdio_fec_mode fec_mode; /* Firecode/Clause91/Clause134/ETC */ @@ -278,13 +281,16 @@ static inline void nc_mdio_ftile_config(struct nc_mdio *mdio) case 6: mdio->speed = 400; break; default: mdio->speed = 0; break; } + mdio->rsfec_supported = (((mdio->speed == 10) || (mdio->speed == 40)) ? 0 : 1); } -static inline uint32_t nc_mdio_etile_rsfec_read(struct nfb_comp *comp, int prtad, uint32_t addr); - /* Get E-tile Ethernet configuration and fill corresponding fields in the nc_mdio structure */ static inline void nc_mdio_etile_config(struct nc_mdio *mdio) { + /* Get FEC mode: The E-Tile supports RS-FEC according clause 91 only. The FEC is active */ + /* when bit 0 of the rsfec_top_rx_cfg register (0x14) is set */ + #define get_fec_mode ((nc_mdio_dmap_drp_read(comp, 0, ETILE_RSFEC_PAGE, 0x14) & 0x1) ? MDIO_FEC_CL91 : MDIO_FEC_NONE) + struct nfb_comp *comp = nfb_user_to_comp(mdio); uint32_t val; @@ -295,25 +301,29 @@ static inline void nc_mdio_etile_config(struct nc_mdio *mdio) if (val <= 0x1f) { /* 10GBASE */ mdio->pma_lanes = 1; mdio->speed = 10; + mdio->rsfec_supported = 0; + mdio->fec_mode = MDIO_FEC_NONE; } else if (val <= 0x26) { /* 40GBASE */ mdio->pma_lanes = 4; mdio->speed = 40; + mdio->rsfec_supported = 0; + mdio->fec_mode = MDIO_FEC_NONE; } else if (val <= 0x2f) { /* 100GBASE */ mdio->pma_lanes = 4; mdio->speed = 100; + mdio->rsfec_supported = 1; + mdio->fec_mode = get_fec_mode; } else if (val <= 0x3a) { /* 25GBASE */ mdio->pma_lanes = 1; mdio->speed = 25; + mdio->rsfec_supported = 1; + mdio->fec_mode = get_fec_mode; } else { /* other modes are not supported on E-Tile now */ mdio->pma_lanes = 0; mdio->speed = 0; + mdio->rsfec_supported = 0; + mdio->fec_mode = MDIO_FEC_NONE; } - /* Get FEC mode */ - /* The E-Tile supports RS-FEC according clause 91 only. The FEC is active */ - /* when bit 0 of the rsfec_top_rx_cfg register (0x14) is set */ - val = nc_mdio_etile_rsfec_read(comp, 0, 0x14); - mdio->fec_mode = ((val & 0x1) ? MDIO_FEC_CL91 : MDIO_FEC_NONE); - } static inline struct nc_mdio *nc_mdio_open_no_init(const struct nfb_device *dev, int fdt_offset, int fdt_offset_ctrlparam) @@ -719,7 +729,6 @@ static inline void nc_mdio_fixup_ftile_set_loopback(struct nc_mdio *mdio, int pr /* ~~~~[ Intel E-Tile ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#define ETILE_RSFEC_PAGE 9 /* Adaptation modes */ #define ETILE_ADAPT_MODE_INITIAL 0x1 #define ETILE_ADAPT_MODE_ONESHOT 0x2 @@ -901,7 +910,7 @@ static inline uint16_t nc_mdio_fixup_etile_pcs_read(struct nc_mdio *mdio, int pr return nc_mdio_dmap_drp_read(comp, prtad, 0, etile_reg); } /* Register not found in tables */ - if (devad == 1) { /* PMA & RSFEC registers */ + if ((devad == 1) && (mdio->rsfec_supported)) { /* PMA & RSFEC registers */ switch (addr) { case 200: return _get_etile_r1200(comp, prtad); case 201: return _get_etile_r1201(comp, prtad); From 5f2ec7be7c419ff842ca6525c4f0aaed3dec070a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 4 Sep 2024 19:02:43 +0200 Subject: [PATCH 192/518] pynfb: [FEATURE] introduce add_close_cb, check_handle and close_handle in NfbDeviceHandle This mechanism can be used to force close the device handle and all subhandles as well. --- pynfb/nfb/libnfb.pxd | 2 ++ pynfb/nfb/libnfb.pyx | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pynfb/nfb/libnfb.pxd b/pynfb/nfb/libnfb.pxd index c740ddfb..c50eed7e 100644 --- a/pynfb/nfb/libnfb.pxd +++ b/pynfb/nfb/libnfb.pxd @@ -131,6 +131,8 @@ cdef extern from "": cdef class NfbDeviceHandle: #cdef object __weakref__ cdef nfb_device* _dev + cdef list _close_cbs + cdef class Nfb: cdef NfbDeviceHandle _handle diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 8efe8731..3baa1d13 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -48,10 +48,25 @@ cdef class NfbDeviceHandle: self._dev = nfb_open(path.encode()) if self._dev is NULL: PyErr_SetFromErrno(OSError) + self._close_cbs = [] def __dealloc__(self): + self.close_handle() + + def close_handle(self): if self._dev is not NULL: + for cb in reversed(self._close_cbs): + cb() + self._close_cbs.clear() nfb_close(self._dev) + self._dev = NULL + + def check_handle(self): + if self._dev is NULL: + raise ReferenceError + + def add_close_cb(self, cb): + self._close_cbs.append(cb) cdef class Nfb: From 890d73bf4640d014911a0550dfdef837a198d2e6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 5 Sep 2024 08:59:28 +0200 Subject: [PATCH 193/518] pynfb: [FEATURE] check handles for all libnfb/libnetcope API Check Nfb handle on init, check user handle on access and register callback for close main nfb handle to invalidate user handle. --- pynfb/nfb/libnetcope.pyx | 91 +++++++++++++++++++++++++++++++++++++++- pynfb/nfb/libnfb.pyx | 68 ++++++++++++++++++++++++++---- 2 files changed, 150 insertions(+), 9 deletions(-) diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 65a59654..6f775440 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -20,28 +20,42 @@ cdef class RxMac: def __init__(self, libnfb.Nfb nfb, node): self._handle = nfb._handle + self._handle.check_handle() self._mac = NULL self._mac = nc_rxmac_open(self._handle._dev, nfb._fdt_path_offset(node)) if self._mac is NULL: PyErr_SetFromErrno(OSError) + self._handle.add_close_cb(self._close_handle) + def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._mac is not NULL: nc_rxmac_close(self._mac) + self._mac = NULL + + def _check_handle(self): + if self._mac is NULL: + raise ReferenceError @property def link(self): + self._check_handle() return False if nc_rxmac_get_link(self._mac) == 0 else True @property def enabled(self): cdef nc_rxmac_status status + self._check_handle() assert nc_rxmac_read_status(self._mac, &status) == 0 return True if status.enabled else False @enabled.setter def enabled(self, enable): enabled = self.enabled + self._check_handle() if not enabled and enable: nc_rxmac_enable(self._mac) elif enabled and not enable: @@ -64,6 +78,7 @@ cdef class RxMac: def reset_stats(self): """Reset statistic counters""" + self._check_handle() nc_rxmac_reset_counters(self._mac) def stats_read(self, etherstats: bool = False): @@ -80,6 +95,7 @@ cdef class RxMac: cdef nc_rxmac_counters counters cdef nc_rxmac_etherstats es + self._check_handle() nc_rxmac_counters_initialize(&counters, &es) cdef int ret = nc_rxmac_read_counters(self._mac, &counters, &es) assert ret == 0 @@ -120,24 +136,37 @@ cdef class TxMac: def __init__(self, libnfb.Nfb nfb, node): self._handle = nfb._handle + self._handle.check_handle() self._mac = NULL self._mac = nc_txmac_open(self._handle._dev, nfb._fdt_path_offset(node)) if self._mac is NULL: PyErr_SetFromErrno(OSError) + self._handle.add_close_cb(self._close_handle) + def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._mac is not NULL: nc_txmac_close(self._mac) + self._mac = NULL + + def _check_handle(self): + if self._mac is NULL: + raise ReferenceError @property def enabled(self): cdef nc_txmac_status status + self._check_handle() assert nc_txmac_read_status(self._mac, &status) == 0 return True if status.enabled else False @enabled.setter def enabled(self, enable): enabled = self.enabled + self._check_handle() if not enabled and enable: nc_txmac_enable(self._mac) elif enabled and not enable: @@ -157,6 +186,7 @@ cdef class TxMac: def reset_stats(self): """Reset statistic counters""" + self._check_handle() nc_txmac_reset_counters(self._mac) def stats_read(self): @@ -170,6 +200,7 @@ cdef class TxMac: """ cdef nc_txmac_counters counters + self._check_handle() ret = nc_txmac_read_counters(self._mac, &counters) assert ret == 0 # INFO: this hides uninialized variables warning @@ -191,17 +222,29 @@ cdef class Mdio: def __init__(self, libnfb.Nfb nfb, node, param_node = None): self._handle = nfb._handle + self._handle.check_handle() self._mdio = NULL self._mdio = nc_mdio_open_no_init(self._handle._dev, nfb._fdt_path_offset(node), nfb._fdt_path_offset(param_node) if param_node else -1) self._inited = False if self._mdio is NULL: PyErr_SetFromErrno(OSError) + self._handle.add_close_cb(self._close_handle) + def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._mdio is not NULL: nc_mdio_close(self._mdio) + self._mdio = NULL + + def _check_handle(self): + if self._mdio is NULL: + raise ReferenceError def _init(self): + self._check_handle() if not self._inited: self._inited = True nc_mdio_init(self._mdio) @@ -221,18 +264,31 @@ cdef class I2c: def __init__(self, libnfb.Nfb nfb, node, addr = 0xA0): self._handle = nfb._handle + self._handle.check_handle() self._ctrl = NULL self._ctrl = nc_i2c_open(self._handle._dev, nfb._fdt_path_offset(node)) nc_i2c_set_addr(self._ctrl, addr) + self._handle.add_close_cb(self._close_handle) + def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._ctrl is not NULL: nc_i2c_close(self._ctrl) + self._ctrl = NULL + + def _check_handle(self): + if self._ctrl is NULL: + raise ReferenceError def read_reg(self, reg, size): cdef int cnt cdef unsigned char* c_data + self._check_handle() + cnt = size c_data = malloc(cnt) if c_data == NULL: @@ -244,6 +300,8 @@ cdef class I2c: def write_reg(self, reg: int, data: bytes): cdef const uint8_t* c_data8 + self._check_handle() + c_data8 = data ret = nc_i2c_write_reg(self._ctrl, reg, c_data8, len(data)) @@ -264,6 +322,7 @@ cdef class DmaCtrlNdp: self._ctrl_queue = NULL self._handle = nfb._handle + self._handle.check_handle() dev = self._handle._dev ret = nc_ndp_ctrl_open(dev, nfb._fdt_path_offset(node), &self._ctrl) if ret != 0: @@ -274,12 +333,17 @@ cdef class DmaCtrlNdp: else: #if self._ctrl.dir == 1: self._ctrl_queue = nc_txqueue_open(dev, nfb._fdt_path_offset(node)) - if self._ctrl_queue == NULL != 0: + if self._ctrl_queue == NULL: nc_ndp_ctrl_close(&self._ctrl) self._ctrl.comp = NULL PyErr_SetFromErrno(OSError) + self._handle.add_close_cb(self._close_handle) + def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._ctrl.comp is not NULL: if self._ctrl_queue: if self._ctrl.dir == 0: @@ -288,6 +352,11 @@ cdef class DmaCtrlNdp: nc_txqueue_close( self._ctrl_queue) self._ctrl_queue = NULL nc_ndp_ctrl_close(&self._ctrl) + #self._ctrl.comp = NULL # already done by nc_ndp_ctrl_close + + def _check_handle(self): + if self._ctrl.comp is NULL: + raise ReferenceError @property def mdp(self): @@ -334,6 +403,7 @@ cdef class DmaCtrlNdp: cdef uint32_t imin cdef uint32_t imax + self._check_handle() ret = nc_ndp_ctrl_get_mtu(&self._ctrl, &imin, &imax) if ret: raise ValueError() @@ -375,27 +445,33 @@ cdef class DmaCtrlNdp: self._ctrl.shp = 0 self._ctrl.sdp = 0 + self._check_handle() ret = nc_ndp_ctrl_start(&self._ctrl, &sp) if ret: PyErr_SetFromErrno(OSError) def flush_sp(self): + self._check_handle() nc_ndp_ctrl_sp_flush(&self._ctrl) def flush_sdp(self): + self._check_handle() nc_ndp_ctrl_sdp_flush(&self._ctrl) def stop(self, force = False): + self._check_handle() if force: nc_ndp_ctrl_stop_force(&self._ctrl) else: nc_ndp_ctrl_stop(&self._ctrl) def update_hdp(self): + self._check_handle() nc_ndp_ctrl_hdp_update(&self._ctrl) return self._ctrl.hdp def update_hhp(self): + self._check_handle() if self._ctrl.dir != 0: raise NotImplementedError() nc_ndp_ctrl_hhp_update(&self._ctrl) @@ -404,6 +480,7 @@ cdef class DmaCtrlNdp: def read_stats(self): cdef nc_rxqueue_counters rxc cdef nc_txqueue_counters txc + self._check_handle() ret = {} if self._ctrl.dir == 0: nc_rxqueue_read_counters( self._ctrl_queue, &rxc) @@ -435,12 +512,15 @@ cdef class Transceiver: self._nfb = nfb self._handle = nfb._handle + self._handle.check_handle() status = nfb.fdt_get_phandle(node.get_property('status-reg').value) fdt_offset = self._nfb._fdt_path_offset(status) self._comp_status = nfb_comp_open(self._handle._dev, fdt_offset) if self._comp_status is NULL: PyErr_SetFromErrno(OSError) + self._handle.add_close_cb(self._close_handle) + ctrl = nfb.fdt_get_phandle(node.get_property('control').value) node_ctrl_param = node.get_subnode('control-param') @@ -451,14 +531,21 @@ cdef class Transceiver: self.i2c = I2c(nfb, ctrl, i2c_addr) def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._comp_status is not NULL: nfb_comp_close(self._comp_status) + self._comp_status = NULL + def _check_handle(self): + if self._comp_status is NULL: + raise ReferenceError def is_present(self) -> bool: + self._check_handle() return nc_transceiver_statusreg_is_present(self._comp_status) != 0 - # FIXME: only valid for specific QSFP+ @property def vendor_name(self) -> str: diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 3baa1d13..12fec31d 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -112,6 +112,8 @@ cdef class Nfb: """ cdef int fdt_offset + + self._handle.check_handle() if isinstance(comp, str): fdt_offset = nfb_comp_find(self._handle._dev, comp.encode(), index) elif isinstance(comp, fdt.items.Node): @@ -158,6 +160,7 @@ cdef class Nfb: cdef int32_t int32 = 0 assert units == "celsius" + self._handle.check_handle() ret = libnetcope.nc_adc_sensors_get_temp(self._handle._dev, &int32) if ret < 0: raise IOError @@ -174,13 +177,23 @@ cdef class Comp: def __cinit__(self, Nfb nfb_dev, int fdt_offset): self._nfb_dev = nfb_dev._handle + self._nfb_dev.check_handle() self._comp = nfb_comp_open(self._nfb_dev._dev, fdt_offset) if self._comp is NULL: PyErr_SetFromErrno(OSError) + self._nfb_dev.add_close_cb(self._close_handle) def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._comp is not NULL: nfb_comp_close(self._comp) + self._comp = NULL + + def _check_handle(self): + if self._comp is NULL: + raise ReferenceError def read(self, addr: int, count: int): """ @@ -191,7 +204,10 @@ cdef class Comp: """ cdef unsigned char *b = malloc(count) - cdef ret = nfb_comp_read(self._comp, b, count, addr) + cdef ssize_t ret + self._check_handle() + + ret = nfb_comp_read(self._comp, b, count, addr) assert ret == count return b[:count] @@ -203,7 +219,10 @@ cdef class Comp: :param data: Data bytes to be written """ cdef const char* b = data - cdef ret = nfb_comp_write(self._comp, b, len(data), addr) + cdef ssize_t ret + self._check_handle() + + ret = nfb_comp_write(self._comp, b, len(data), addr) assert ret == len(data) return None @@ -511,20 +530,31 @@ cdef class NdpQueue: self._node = node def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._q is not NULL: if self._dir: ndp_close_tx_queue(self._q) else: ndp_close_rx_queue(self._q) + self._q = NULL + + def _check_handle(self): + if self._q is NULL: + raise ReferenceError cdef _check_running(self): - if not self._running: + if self._q is NULL: + self._handle.check_handle() + p1, p2 = self._handle._dev, self._index + self._q = ndp_open_tx_queue(p1, p2) if self._dir else ndp_open_rx_queue(p1, p2) if self._q is NULL: - p1, p2 = self._handle._dev, self._index - self._q = ndp_open_tx_queue(p1, p2) if self._dir else ndp_open_rx_queue(p1, p2) - if self._q is NULL: - PyErr_SetFromErrno(OSError) + PyErr_SetFromErrno(OSError) + self._handle.add_close_cb(self._close_handle) + + if not self._running: assert ndp_queue_start(self._q) == 0 self._running = True @@ -535,6 +565,7 @@ cdef class NdpQueue: def stop(self): """ Stop the queue""" if self._running: + self._check_handle() assert ndp_queue_stop(self._q) == 0 self._running = False @@ -562,10 +593,21 @@ cdef class NdpQueueRx(NdpQueue): self._dir = 0 NdpQueue.__init__(self, nfb, node, index) self._nc_queue = libnetcope.nc_rxqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) + self._handle.add_close_cb(self._close_handle) def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._nc_queue is not NULL: libnetcope.nc_rxqueue_close(self._nc_queue) + self._nc_queue = NULL + super()._close_handle() + + def _check_handle(self): + super()._check_handle() + if self._nc_queue is NULL: + raise ReferenceError def _check_nc_queue(self): if not self.is_accessible(): @@ -692,10 +734,21 @@ cdef class NdpQueueTx(NdpQueue): self._dir = 1 NdpQueue.__init__(self, nfb, node, index) self._nc_queue = libnetcope.nc_txqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) + self._handle.add_close_cb(self._close_handle) def __dealloc__(self): + self._close_handle() + + def _close_handle(self): if self._nc_queue is not NULL: libnetcope.nc_txqueue_close(self._nc_queue) + self._nc_queue = NULL + super()._close_handle() + + def _check_handle(self): + super()._check_handle() + if self._nc_queue is NULL: + raise ReferenceError def _check_nc_queue(self): if self._nc_queue is NULL: @@ -800,4 +853,5 @@ cdef class NdpQueueTx(NdpQueue): def flush(self): """Flush the prepared packet/messages""" + self._check_running() ndp_tx_burst_flush(self._q) From ada281b033241f121a20e14dbac6976af911b18d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 5 Sep 2024 09:05:38 +0200 Subject: [PATCH 194/518] pynfb: [FEATURE] introduce context manager on Nfb The context manager will ensure closing the nfb_device handle and all opened subhandles as well. There is also a Nfb._close_handle() function which does the same, but context manager should be used instead. --- pynfb/nfb/libnfb.pyx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 12fec31d..a6a23cd1 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -102,6 +102,16 @@ cdef class Nfb: def __dealloc__(self): pass + def __enter__(self): + self._handle.check_handle() + return self + + def __exit__(self, *exc): + self._close_handle() + + def _close_handle(self): + self._handle.close_handle() + def comp_open(self, comp: Union[str, fdt.items.Node], index: cython.int = 0) -> Comp: """ Create component handle from a component instance inside the NFB From fcaa099b687084c7f76866937eceee274dd98901 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 25 Sep 2024 13:38:17 +0200 Subject: [PATCH 195/518] pynfb: [FIX] rewrite all dealloc to del --- pynfb/nfb/libnetcope.pyx | 12 ++++++------ pynfb/nfb/libnfb.pyx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 6f775440..7aea1ea0 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -28,7 +28,7 @@ cdef class RxMac: self._handle.add_close_cb(self._close_handle) - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): @@ -144,7 +144,7 @@ cdef class TxMac: self._handle.add_close_cb(self._close_handle) - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): @@ -231,7 +231,7 @@ cdef class Mdio: self._handle.add_close_cb(self._close_handle) - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): @@ -271,7 +271,7 @@ cdef class I2c: self._handle.add_close_cb(self._close_handle) - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): @@ -340,7 +340,7 @@ cdef class DmaCtrlNdp: self._handle.add_close_cb(self._close_handle) - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): @@ -530,7 +530,7 @@ cdef class Transceiver: i2c_addr = prop.value if prop else 0xA0 self.i2c = I2c(nfb, ctrl, i2c_addr) - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index a6a23cd1..2b10e7ce 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -50,7 +50,7 @@ cdef class NfbDeviceHandle: PyErr_SetFromErrno(OSError) self._close_cbs = [] - def __dealloc__(self): + def __del__(self): self.close_handle() def close_handle(self): From 14a228ec785d95c5def484f0daa7ba0cd78e4d72 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 25 Sep 2024 16:28:28 +0200 Subject: [PATCH 196/518] Jenkins: [FIX] change ol8 default user id/number --- jenkins/oraclelinux8.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/oraclelinux8.Dockerfile b/jenkins/oraclelinux8.Dockerfile index 503d2917..0d2dcbd4 100644 --- a/jenkins/oraclelinux8.Dockerfile +++ b/jenkins/oraclelinux8.Dockerfile @@ -3,7 +3,7 @@ ARG OSNAME=centos FROM $OSNAME:$OSRELEASEVER as default RUN /usr/sbin/groupadd -f -g 991 jenkins -RUN /usr/sbin/useradd jenkins -u 1000 -g 991 +RUN /usr/sbin/useradd jenkins -u 1001 -g 991 RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm From aa318372f80b8805ffd869792baa0b75298246a9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 26 Sep 2024 08:24:01 +0200 Subject: [PATCH 197/518] bump version to 6.23.4 --- Changelog | 7 +++++++ VERSION | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 81d8dd0d..d4709e2f 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,10 @@ +* Thu Sep 26 2024 Martin Spinler - 6.23.4-1 +- [FEATURE] pynfb: introduce context manager for device, which ensures closing +- [BUGFIX] ndp-tool: correctly check limits in multithread mode +- [BUGFIX] tools: use LIBNFB_DEFAULT_DEV in all tools +- [BUGFIX] drivers: fill info for all endpoints, including not attached +- [BUGFIX] libnetcope: disable RSFEC accesses on PMA without RSFEC support + * Thu Aug 29 2024 Martin Spinler - 6.23.3-1 - [FEATURE] nfb-meter: add offline mode - [BUGFIX] nfb-meter: update to new pynfb names diff --git a/VERSION b/VERSION index 2e0cb2e4..67403209 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.23.3 +6.23.4 From fcd3e71c0f6b429f51dac28e766c73b208f49334 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 26 Sep 2024 16:15:19 +0200 Subject: [PATCH 198/518] pynfb: bump version to 0.2.0 --- pynfb/setup.py | 2 +- pynfb/setup.py.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pynfb/setup.py b/pynfb/setup.py index bf1af1c7..6116a085 100644 --- a/pynfb/setup.py +++ b/pynfb/setup.py @@ -22,7 +22,7 @@ setup( name = "nfb", - version = "0.1.0", + version = "0.2.0", author = "Martin Spinler", author_email = "spinler@cesnet.cz", ext_package = "nfb", diff --git a/pynfb/setup.py.in b/pynfb/setup.py.in index c423b306..af360322 100644 --- a/pynfb/setup.py.in +++ b/pynfb/setup.py.in @@ -17,7 +17,7 @@ libnfb_ext_extra_args = libnetcope_ext_extra_args = ext_extra_args setup( name = "nfb", - version = "0.1.0", + version = "0.2.0", author = "Martin Spinler", author_email = "spinler@cesnet.cz", ext_package = "nfb", From 367ebaf825e5d69dbf72ce35d38a439d29a400bc Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 1 Oct 2024 14:56:46 +0200 Subject: [PATCH 199/518] libnfb - nfb_comp_lock: [FIX] check errno instead of the ioctl return value The ioctl return value is always -1 for unsuccessful request. Therefore particular error must be obtained by errno. This commit fixes the nfb_comp_lock behaviour: now the while loop retries to lock endlessly - acting similar as spinlocks. This behaviour is intended for easy use in the userspace code (there is currently a limit of 100 retries / 100ms in the kernel driver, ensuring some deadlock prevention). However this behaviour is not suitable for all cases, which will be covered better by try-lock-like mechanism. --- libnfb/src/nfb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/src/nfb.c b/libnfb/src/nfb.c index c3e4da25..20a3db4a 100644 --- a/libnfb/src/nfb.c +++ b/libnfb/src/nfb.c @@ -479,7 +479,7 @@ int nfb_base_comp_lock(const struct nfb_comp *comp, uint32_t features) lock.features = features; while ((ret = ioctl(comp->dev->fd, NFB_LOCK_IOC_TRY_LOCK, &lock)) != 0) { - if (ret != EBUSY) + if (ret == -1 && errno != EBUSY) break; usleep(50); From ecbe7217e8f6297a5409173625d1730f7ad4d61d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 1 Oct 2024 18:21:20 +0200 Subject: [PATCH 200/518] libnfb: [FEATURE] add nfb_comp_trylock --- libnfb/include/nfb/nfb.h | 11 ++++++++ libnfb/src/nfb.c | 58 ++++++++++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/libnfb/include/nfb/nfb.h b/libnfb/include/nfb/nfb.h index 7ecac20e..b021b286 100644 --- a/libnfb/include/nfb/nfb.h +++ b/libnfb/include/nfb/nfb.h @@ -227,6 +227,17 @@ const struct nfb_device *nfb_comp_get_device(struct nfb_comp *component); */ int nfb_comp_lock(const struct nfb_comp *component, uint32_t features); +/*! + * \brief Try to lock a component feature, return at the latest after defined time value + * \param[in] component Component handle + * \param[in] features Bitmask of user-defined features to lock + * \param[in] timeout Maximum time to wait in milliseconds, -1 for eternity + * \return + * - 0 on successful lock (!) + * - Negative error code otherwise + */ +int nfb_comp_trylock(const struct nfb_comp *component, uint32_t features, int timeout); + /*! * \brief Unlock a component feature * \param[in] component Component handle diff --git a/libnfb/src/nfb.c b/libnfb/src/nfb.c index 20a3db4a..ad21dc02 100644 --- a/libnfb/src/nfb.c +++ b/libnfb/src/nfb.c @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -462,12 +463,50 @@ void nfb_comp_close(struct nfb_comp *comp) free(comp); } -int nfb_comp_lock(const struct nfb_comp *comp, uint32_t features) +int nfb_comp_trylock(const struct nfb_comp *comp, uint32_t features, int timeout) { + struct timespec start, end; + int64_t diff; + int ret = 0; + if (!comp) - return -1; + return -EINVAL; + + if (timeout > 0) + clock_gettime(CLOCK_MONOTONIC, &start); + + do { + ret = comp->dev->ops.comp_lock(comp, features); + if (ret == 1) { + /* Successful lock: return OK */ + return 0; + } else if (ret != 0 && ret != -EBUSY) { + /* Unsuccessful lock with specific error value: terminate function with error code */ + return ret; + } else if (timeout == 0) { + /* No timeout: return immediately with BUSY error value */ + return -EBUSY; + } else { + /* Generic unsuccessful lock: try lock again until timeout */ + usleep(50); + if (timeout > 0) { + clock_gettime(CLOCK_MONOTONIC, &end); + diff = 1000000000L * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec; + } + } + } while (timeout == -1 || (timeout > 0 && diff < timeout * 1000000L)); + + return -ETIMEDOUT; +} + +int nfb_comp_lock(const struct nfb_comp *comp, uint32_t features) +{ + int ret; - return comp->dev->ops.comp_lock(comp, features); + ret = nfb_comp_trylock(comp, features, -1); + if (ret == 0) + return 1; + return 0; } int nfb_base_comp_lock(const struct nfb_comp *comp, uint32_t features) @@ -479,13 +518,16 @@ int nfb_base_comp_lock(const struct nfb_comp *comp, uint32_t features) lock.features = features; while ((ret = ioctl(comp->dev->fd, NFB_LOCK_IOC_TRY_LOCK, &lock)) != 0) { - if (ret == -1 && errno != EBUSY) - break; - - usleep(50); + if (ret == -1) { + if (errno == EINTR) { + continue; + } else { + return -errno; + } + } } - return (ret == 0); + return 1; } void nfb_comp_unlock(const struct nfb_comp *comp, uint32_t features) From 477648210fbd10ea9ea38b0c96cfb7875abcde0f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 1 Oct 2024 18:36:25 +0200 Subject: [PATCH 201/518] drivers: [FEATURE] add nfb_comp_trylock --- drivers/kernel/drivers/nfb/bus.c | 36 ++++++++++++++++++++++++-------- drivers/kernel/drivers/nfb/nfb.h | 1 + 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/drivers/kernel/drivers/nfb/bus.c b/drivers/kernel/drivers/nfb/bus.c index a69ddcdf..e3281429 100644 --- a/drivers/kernel/drivers/nfb/bus.c +++ b/drivers/kernel/drivers/nfb/bus.c @@ -130,24 +130,42 @@ struct nfb_device *nfb_comp_get_device(struct nfb_comp *comp) return comp->nfb; } -int nfb_comp_lock(struct nfb_comp *comp, uint32_t features) +int nfb_comp_trylock(struct nfb_comp *comp, uint32_t features, int timeout) { + int ret; int cnt = 0; struct nfb_lock lock; lock.path = comp->path; lock.features = features; - while (nfb_lock_try_lock(comp->nfb, &comp->nfb->kernel_app, lock) != 0) { - msleep(1); - cnt++; - if (cnt > 100) { - dev_warn(comp->nfb->dev, "Can't lock comp %s within 100 ms\n", comp->path); - return 0; + do { + ret = nfb_lock_try_lock(comp->nfb, &comp->nfb->kernel_app, lock); + if (ret == 0) { + return ret; + } else if (ret != -EBUSY) { + return ret; + } else if (timeout == 0) { + return -EBUSY; + } else { + udelay(50); } - } + } while (timeout * 20 > cnt++); + + dev_warn(comp->nfb->dev, "Can't lock comp %s within %d ms\n", comp->path, timeout); + + return -ETIMEDOUT; +} + +int nfb_comp_lock(struct nfb_comp *comp, uint32_t features) +{ + int ret; + + ret = nfb_comp_trylock(comp, features, 100); + if (ret == 0) + return 1; - return 1; + return 0; } void nfb_comp_unlock(struct nfb_comp *comp, uint32_t features) diff --git a/drivers/kernel/drivers/nfb/nfb.h b/drivers/kernel/drivers/nfb/nfb.h index d786befc..48c51630 100644 --- a/drivers/kernel/drivers/nfb/nfb.h +++ b/drivers/kernel/drivers/nfb/nfb.h @@ -169,6 +169,7 @@ struct nfb_device *nfb_comp_get_device(struct nfb_comp *comp); #define nfb_user_to_comp(ptr) (((struct nfb_comp *) ptr) - 1) #define nfb_comp_to_user(ptr) (((struct nfb_comp *) ptr) + 1) +int nfb_comp_trylock(struct nfb_comp *comp, uint32_t features, int timeout); int nfb_comp_lock(struct nfb_comp *comp, uint32_t features); void nfb_comp_unlock(struct nfb_comp *comp, uint32_t features); From 5dae966c1967367227561eafe14836ff9aab0e3c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 1 Oct 2024 18:38:24 +0200 Subject: [PATCH 202/518] libnetcope - dma_ctrl_ndp [FIX]: use nfb_comp_trylock instead of nfb_comp_lock The nc_ndp_ctrl_start locks the firmware component for exclusive access. This lock is however not intended to be held for a short time, so the usage of basic nfb_comp_lock is improper. Instead of potentially endless lock loop is better to use nfb_comp_trylock and check for -EBUSY return value immediately and only once. --- libnfb/include/netcope/dma_ctrl_ndp.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 57006e68..bcef16ab 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -20,6 +20,8 @@ #define DMA_TYPE_MEDUSA 2 #define DMA_TYPE_CALYPTE 3 +#define COMP_NC_DMA_CTRL_LOCK 1 + // ---------------- NDP/Calypte common registers ------- #define NDP_CTRL_REG_CONTROL 0x00 #define NDP_CTRL_REG_CONTROL_STOP 0x0 @@ -328,8 +330,11 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl if (ctrl->dir == 0 && (sp->nb_hdr & (sp->nb_hdr - 1)) != 0) return -EINVAL; - if (!nfb_comp_lock(ctrl->comp, 1)) { - ret = -EEXIST; + + ret = nfb_comp_trylock(ctrl->comp, COMP_NC_DMA_CTRL_LOCK, 0); + if (ret != 0) { + if (ret == -EBUSY) + ret = -EEXIST; goto err_comp_lock; } @@ -397,7 +402,7 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl return 0; err_comp_running: - nfb_comp_unlock(ctrl->comp, 1); + nfb_comp_unlock(ctrl->comp, COMP_NC_DMA_CTRL_LOCK); err_comp_lock: return ret; } @@ -448,7 +453,7 @@ static inline int _nc_ndp_ctrl_stop(struct nc_ndp_ctrl *ctrl, int force) /* TODO: read hdp/hhp from register and wait for same value in update buffer */ - nfb_comp_unlock(ctrl->comp, 1); + nfb_comp_unlock(ctrl->comp, COMP_NC_DMA_CTRL_LOCK); return ret; err_busy: From fe4263547eccf511029a9a29305dd096b0344d3b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 1 Oct 2024 18:40:33 +0200 Subject: [PATCH 203/518] drivers - sdm: [MAINTENANCE] use nfb_comp_trylock instead of nfb_comp_lock --- drivers/kernel/drivers/nfb/boot/sdm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/boot/sdm.c b/drivers/kernel/drivers/nfb/boot/sdm.c index a326bd0a..7de157eb 100644 --- a/drivers/kernel/drivers/nfb/boot/sdm.c +++ b/drivers/kernel/drivers/nfb/boot/sdm.c @@ -299,7 +299,7 @@ static int sdm_send_header(struct sdm *sdm, const uint32_t cmd_code, const uint3 */ static int sdm_try_lock(struct nfb_comp *comp) { - if (!nfb_comp_lock(comp, SDM_COMP_LOCK)) { + if (nfb_comp_trylock(comp, SDM_COMP_LOCK, 100)) { return -EAGAIN; } return 0; From d1e37fb6092bb47ca71484c9a322aa15c119d0ef Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 1 Oct 2024 17:27:03 +0200 Subject: [PATCH 204/518] libnetcope: [FIX] unify the return value after unsuccessful nfb_comp_lock to -EAGAIN --- libnfb/include/netcope/mdio.h | 36 ++++++++++++++++-------------- libnfb/include/netcope/mdio_ctrl.h | 9 ++++++-- libnfb/include/netcope/rxmac.h | 4 ++-- libnfb/include/netcope/txmac.h | 4 ++-- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index bfba60a3..d35302c4 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -714,7 +714,7 @@ static inline uint16_t nc_mdio_fixup_ftile_pcs_read(struct nc_mdio *mdio, int pr return mdio->mdio_read(comp, prtad, devad, addr); /* Unknown address: try to read the MGMT */ } -static inline void nc_mdio_fixup_ftile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) +static inline int nc_mdio_fixup_ftile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) { int i; uint16_t data = enable ? 0x6 : 0x0; // enable or disable loopback? @@ -725,6 +725,7 @@ static inline void nc_mdio_fixup_ftile_set_loopback(struct nc_mdio *mdio, int pr nc_mdio_ftile_fgt_attribute_write(mdio, prtad, data, i, 0x40); } nc_mdio_ftile_reset(mdio, prtad, 1, 0); // deassert RX reset + return 0; } /* ~~~~[ Intel E-Tile ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -945,7 +946,7 @@ static inline uint16_t nc_mdio_fixup_etile_pcs_read(struct nc_mdio *mdio, int pr return mdio->mdio_read(comp, prtad, devad, addr); /* Unknown address: try to read the MGMT */ } -static inline void nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int prtad, uint16_t lane, uint16_t code_addr, uint16_t code_val) +static inline int nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int prtad, uint16_t lane, uint16_t code_addr, uint16_t code_val) { uint32_t page = lane + 1; // page number corresponds to lane number + 1 @@ -970,12 +971,12 @@ static inline void nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int p uint32_t ret; int retries = 0; - int locked = 0; int sent = 0; + /* Lock the attribute access interface */ - while (!locked) { - locked = nfb_comp_lock(comp, ATTR_IFC); - } + if (!nfb_comp_lock(comp, ATTR_IFC)) + return -EAGAIN; + /* Clear PMA attribute code request sent flag */ nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L, 0x80); while (!sent) { @@ -998,6 +999,7 @@ static inline void nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int p nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L, 0x80); nfb_comp_unlock(comp, ATTR_IFC); + return 0; } @@ -1158,18 +1160,18 @@ static inline void nc_mdio_etile_areset(struct nfb_comp *comp, int prtad, int la } while (((ret & 0x01) != 0x0) && (++retries < 100000)); } -static inline void nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) +static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) { /* See https://www.intel.com/content/www/us/en/docs/programmable/683468/23-2/ethernet-adaptation-flow-with-non-external.html */ int i; struct nfb_comp *comp = nfb_user_to_comp(mdio); - int locked = 0; int retries = 0; uint32_t ret; - while (!locked) { - locked = nfb_comp_lock(comp, PCS_IFC); /* Lock access to PCS registers (reset active) */ - } + /* Lock access to PCS registers (reset active) */ + if (!nfb_comp_lock(comp, ATTR_IFC)) + return -EAGAIN; + /* 1. Assert RX/TX reset ports of the EHIP */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // soft rx rst + soft tx rst /* 2 + 3. Trigger PMA analog reset and reload PMA settings */ @@ -1216,6 +1218,7 @@ static inline void nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int pr /* Apply the mode (turn the RS-FEC on or off) */ nc_mdio_fixup_etile_set_mode(mdio, prtad, ret); nfb_comp_unlock(comp, PCS_IFC); + return 0; } static inline void nc_mdio_close(struct nc_mdio *m) @@ -1228,7 +1231,6 @@ static inline int nc_mdio_read(struct nc_mdio *mdio, int prtad, int devad, uint1 struct nfb_comp *comp = nfb_user_to_comp(mdio); uint16_t (*nc_mdio_fixup_rsfec_read)(struct nc_mdio *mdio, int devad, int prtad, uint16_t reg) = NULL; uint16_t val; - int locked = 0; /* Select correct set of FIXUP functions */ if (mdio->pcspma_is_e_tile) { @@ -1255,10 +1257,10 @@ static inline int nc_mdio_read(struct nc_mdio *mdio, int prtad, int devad, uint1 (addr == 33) || (addr == 44) || (addr == 45)) { - while (!locked) { - locked = nfb_comp_lock(comp, (PCS_IFC | ATTR_IFC) ); /* Lock access to PCS regs */ - } - val = nc_mdio_fixup_rsfec_read(mdio, prtad, devad, addr); + /* Lock access to PCS regs */ + if (!nfb_comp_lock(comp, PCS_IFC | ATTR_IFC)) + return -EAGAIN; + val = nc_mdio_fixup_rsfec_read(mdio, prtad, devad, addr); nfb_comp_unlock(comp, (PCS_IFC | ATTR_IFC)); /* Unlock access to PCS regs */ return val; } @@ -1271,7 +1273,7 @@ static inline int nc_mdio_write(struct nc_mdio *mdio, int prtad, int devad, uint { struct nfb_comp *comp = nfb_user_to_comp(mdio); void (*nc_mdio_fixup_set_mode)(struct nc_mdio *mdio, int prtad, uint16_t val) = NULL; - void (*nc_mdio_fixup_set_loopback)(struct nc_mdio *mdio, int prtad, int enable) = NULL; + int (*nc_mdio_fixup_set_loopback)(struct nc_mdio *mdio, int prtad, int enable) = NULL; /* Select correct set of FIXUP functions */ if (mdio->pcspma_is_e_tile) { diff --git a/libnfb/include/netcope/mdio_ctrl.h b/libnfb/include/netcope/mdio_ctrl.h index 306abaf4..66e24ac0 100644 --- a/libnfb/include/netcope/mdio_ctrl.h +++ b/libnfb/include/netcope/mdio_ctrl.h @@ -108,7 +108,10 @@ static inline struct nfb_comp *nc_mdio_ctrl_open_ext(const struct nfb_device *de static inline int nc_mdio_ctrl_read(struct nfb_comp *comp, int prtad, int devad, uint16_t addr) { int data; - nfb_comp_lock(comp, MDIO_COMP_LOCK); + + if (!nfb_comp_lock(comp, MDIO_COMP_LOCK)) + return -EAGAIN; + _mdio_ctrl_send(comp, MDIO_CTRL_EDF, MDIO_CTRL_OP_ADDR, prtad, devad, addr); _mdio_ctrl_wait(comp); _mdio_ctrl_send(comp, MDIO_CTRL_EDF, MDIO_CTRL_OP_EDF_READ, prtad, devad, 0); @@ -121,7 +124,9 @@ static inline int nc_mdio_ctrl_read(struct nfb_comp *comp, int prtad, int devad, static inline int nc_mdio_ctrl_write(struct nfb_comp *comp, int prtad, int devad, uint16_t addr, uint16_t data) { - nfb_comp_lock(comp, MDIO_COMP_LOCK); + if (!nfb_comp_lock(comp, MDIO_COMP_LOCK)) + return -EAGAIN; + _mdio_ctrl_send(comp, MDIO_CTRL_EDF, MDIO_CTRL_OP_ADDR, prtad, devad, addr); _mdio_ctrl_wait(comp); _mdio_ctrl_send(comp, MDIO_CTRL_EDF, MDIO_CTRL_OP_WRITE, prtad, devad, data); diff --git a/libnfb/include/netcope/rxmac.h b/libnfb/include/netcope/rxmac.h index 765bc1e7..dc8e6fca 100644 --- a/libnfb/include/netcope/rxmac.h +++ b/libnfb/include/netcope/rxmac.h @@ -278,7 +278,7 @@ static inline int nc_rxmac_read_status(struct nc_rxmac *mac, struct nc_rxmac_sta uint32_t reg; if (!nfb_comp_lock(comp, RXMAC_COMP_LOCK)) - return -1; + return -EAGAIN; s->enabled = nfb_comp_read32(comp, RXMAC_REG_ENABLE); s->error_mask = nfb_comp_read32(comp, RXMAC_REG_ERROR_MASK); @@ -314,7 +314,7 @@ static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_c struct nfb_comp *comp = nfb_user_to_comp(mac); if (!nfb_comp_lock(comp, RXMAC_COMP_LOCK)) - return -1; + return -EAGAIN; nfb_comp_write32(comp, RXMAC_REG_CONTROL, RXMAC_CMD_STROBE); diff --git a/libnfb/include/netcope/txmac.h b/libnfb/include/netcope/txmac.h index 47668c31..85539913 100644 --- a/libnfb/include/netcope/txmac.h +++ b/libnfb/include/netcope/txmac.h @@ -118,7 +118,7 @@ static inline int nc_txmac_read_status(struct nc_txmac *mac, struct nc_txmac_sta uint32_t reg; if (!nfb_comp_lock(comp, TXMAC_COMP_LOCK)) - return -1; + return -EAGAIN; nfb_comp_write32(comp, TXMAC_REG_CONTROL, TXMAC_CMD_STROBE); @@ -145,7 +145,7 @@ static inline int nc_txmac_read_counters(struct nc_txmac *mac, struct nc_txmac_c struct nfb_comp *comp = nfb_user_to_comp(mac); if (!nfb_comp_lock(comp, TXMAC_COMP_LOCK)) - return -1; + return -EAGAIN; nfb_comp_write32(comp, TXMAC_REG_CONTROL, TXMAC_CMD_STROBE); From bf8d60078f87ad282c5f398bce7ae4541858a4fd Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 2 Oct 2024 12:11:36 +0200 Subject: [PATCH 205/518] pynfb - comp: add lock and unlock methods --- pynfb/nfb/libnfb.pxd | 5 +++++ pynfb/nfb/libnfb.pyx | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pynfb/nfb/libnfb.pxd b/pynfb/nfb/libnfb.pxd index c50eed7e..29a489c3 100644 --- a/pynfb/nfb/libnfb.pxd +++ b/pynfb/nfb/libnfb.pxd @@ -34,6 +34,11 @@ cdef extern from "": ssize_t nfb_comp_write(const nfb_comp *comp, const void *buf, size_t nbyte, off_t offset) ssize_t nfb_comp_read(const nfb_comp *comp, void *buf, size_t nbyte, off_t offset) + int nfb_comp_trylock(const nfb_comp *comp, uint32_t features, int timeout) + int nfb_comp_lock(const nfb_comp *comp, uint32_t features) + void nfb_comp_unlock(const nfb_comp *comp, uint32_t features) + + cdef extern from "": cdef struct nfb_device: pass diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 2b10e7ce..a3a5eeb8 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -8,6 +8,7 @@ from typing import Union, Optional, List, Tuple from libc.stdlib cimport malloc from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int32_t from libcpp cimport bool +cimport libc.errno from cpython.ref cimport PyObject from cpython.exc cimport PyErr_SetFromErrno @@ -347,6 +348,20 @@ cdef class Comp: time.sleep(delay) return True + def lock(self, features:int, timeout: Optional[int]=None): + if timeout is None: + timeout = -1 + ret = nfb_comp_trylock(self._comp, features, timeout) + if ret == -libc.errno.ETIMEDOUT: + raise TimeoutError() + elif ret == -libc.errno.EBUSY: + raise BlockingIOError() + elif ret != 0: + raise OSError() + + def unlock(self, features: int): + nfb_comp_unlock(self._comp, features) + cdef class AbstractBaseComp: """ From f96cb60b12a73149176b5fcfc95d35516c2e9fec Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 3 Oct 2024 08:42:40 +0200 Subject: [PATCH 206/518] pynfb: [FIX] loop read_temperature while returns EBUSY This hides the TimeoutError. --- libnfb/src/info.c | 8 +++++++- pynfb/nfb/libnfb.pyx | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libnfb/src/info.c b/libnfb/src/info.c index 769368c7..c3592d90 100644 --- a/libnfb/src/info.c +++ b/libnfb/src/info.c @@ -15,5 +15,11 @@ int nfb_sensor_get(struct nfb_device *dev, struct nfb_boot_ioc_sensor *s) { - return ioctl(dev->fd, NFB_BOOT_IOC_SENSOR_READ, s); + int ret; + + ret = ioctl(dev->fd, NFB_BOOT_IOC_SENSOR_READ, s); + if (ret == -1) + return -errno; + + return ret; } diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index a3a5eeb8..f187d2c3 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -8,7 +8,7 @@ from typing import Union, Optional, List, Tuple from libc.stdlib cimport malloc from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int32_t from libcpp cimport bool -cimport libc.errno +from libc.errno cimport EBUSY, ETIMEDOUT, EAGAIN from cpython.ref cimport PyObject from cpython.exc cimport PyErr_SetFromErrno @@ -172,9 +172,13 @@ cdef class Nfb: assert units == "celsius" self._handle.check_handle() - ret = libnetcope.nc_adc_sensors_get_temp(self._handle._dev, &int32) + + ret = -EAGAIN + while ret == -EAGAIN: + ret = libnetcope.nc_adc_sensors_get_temp(self._handle._dev, &int32) if ret < 0: raise IOError + return int(int32) / 1000 @@ -352,9 +356,9 @@ cdef class Comp: if timeout is None: timeout = -1 ret = nfb_comp_trylock(self._comp, features, timeout) - if ret == -libc.errno.ETIMEDOUT: + if ret == -ETIMEDOUT: raise TimeoutError() - elif ret == -libc.errno.EBUSY: + elif ret == -EBUSY: raise BlockingIOError() elif ret != 0: raise OSError() From 17fe9dc18da2a5c57e7381935974853a92cc14d2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 3 Oct 2024 10:24:48 +0200 Subject: [PATCH 207/518] bump version to 6.23.5 --- Changelog | 5 +++++ VERSION | 2 +- pynfb/setup.py | 2 +- pynfb/setup.py.in | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Changelog b/Changelog index d4709e2f..8d5ce012 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +* Thu Oct 3 2024 Martin Spinler - 6.23.5-1 +- [FEATURE] pynfb: add lock/unlock methods to Comp +- [FEATURE] libnfb: add nfb_comp_trylock +- [FIX] libnfb: loop in nfb_comp_lock while lock is busy + * Thu Sep 26 2024 Martin Spinler - 6.23.4-1 - [FEATURE] pynfb: introduce context manager for device, which ensures closing - [BUGFIX] ndp-tool: correctly check limits in multithread mode diff --git a/VERSION b/VERSION index 67403209..b3b46191 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.23.4 +6.23.5 diff --git a/pynfb/setup.py b/pynfb/setup.py index 6116a085..c4b292b6 100644 --- a/pynfb/setup.py +++ b/pynfb/setup.py @@ -22,7 +22,7 @@ setup( name = "nfb", - version = "0.2.0", + version = "0.2.1", author = "Martin Spinler", author_email = "spinler@cesnet.cz", ext_package = "nfb", diff --git a/pynfb/setup.py.in b/pynfb/setup.py.in index af360322..47146a0e 100644 --- a/pynfb/setup.py.in +++ b/pynfb/setup.py.in @@ -17,7 +17,7 @@ libnfb_ext_extra_args = libnetcope_ext_extra_args = ext_extra_args setup( name = "nfb", - version = "0.2.0", + version = "0.2.1", author = "Martin Spinler", author_email = "spinler@cesnet.cz", ext_package = "nfb", From 15caec4ba2fc1b0b24503b41de389d8ac3afcdf2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 4 Oct 2024 08:31:19 +0200 Subject: [PATCH 208/518] tool - boot: [FIX] enable both of device forms for the DTB inject --- tools/boot/boot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/boot/boot.c b/tools/boot/boot.c index 038bc522..d305313b 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -81,7 +81,7 @@ void usage(const char *me) int inject_fdt(const char *device, const char *dtb_filename, int flags) { size_t ret; - char buf[512]; + char buf[512] = {0}; FILE *f; void *dtb; @@ -141,7 +141,7 @@ int inject_fdt(const char *device, const char *dtb_filename, int flags) nfb_close(dev); /* Open the device in exclusive mode: ensure no other userspace tool is running */ - dev = nfb_open_ext(device, O_APPEND); + dev = nfb_open_ext(strlen(buf) == 0 ? device : buf, O_APPEND); if (!dev) { warnx("Can't open the NFB device in exclusive mode!"); ret = errno; From aabbf46429df5769d08bb53cc3956d3bd2ec0224 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 4 Oct 2024 15:40:26 +0200 Subject: [PATCH 209/518] libnetcope - MDIO: [FIX] remove recursive lock of ATTR_IFC The nfb_comp_lock doesn't supports recursive locking. This bug only became apparent after fixing nfb_comp_lock. --- libnfb/include/netcope/mdio.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index d35302c4..606a7f2b 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -946,6 +946,7 @@ static inline uint16_t nc_mdio_fixup_etile_pcs_read(struct nc_mdio *mdio, int pr return mdio->mdio_read(comp, prtad, devad, addr); /* Unknown address: try to read the MGMT */ } +/* Beware, this is internal function and must be accessed with ATTR_IFC feature already locked! */ static inline int nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int prtad, uint16_t lane, uint16_t code_addr, uint16_t code_val) { uint32_t page = lane + 1; // page number corresponds to lane number + 1 @@ -973,10 +974,6 @@ static inline int nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int pr int retries = 0; int sent = 0; - /* Lock the attribute access interface */ - if (!nfb_comp_lock(comp, ATTR_IFC)) - return -EAGAIN; - /* Clear PMA attribute code request sent flag */ nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L, 0x80); while (!sent) { @@ -997,8 +994,6 @@ static inline int nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int pr } while (((ret & 0x01) != 0) && (++retries < 10000)); /* Clear PMA attribute code request sent flag */ nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L, 0x80); - - nfb_comp_unlock(comp, ATTR_IFC); return 0; } @@ -1115,6 +1110,7 @@ static inline void nc_mdio_fixup_etile_set_mode(struct nc_mdio *mdio, int prtad, /* Starts PMA adaptation on a lane. */ /* Adaptation mode: 0x1 - initial; 0x2 = One shot; 0x6 = continuous (mission) */ +/* Beware, this is internal function and must be accessed with ATTR_IFC feature already locked! */ static inline void nc_mdio_etile_adapt_start(struct nc_mdio *mdio, int prtad, int lane, uint16_t mode) { /* Set Adaptation Effort Level to full effort */ @@ -1123,6 +1119,7 @@ static inline void nc_mdio_etile_adapt_start(struct nc_mdio *mdio, int prtad, in nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, mode); /* Run the adaptation */ } +/* Beware, this is internal function and must be accessed with ATTR_IFC feature already locked! */ static inline void nc_mdio_etile_adapt_wait(struct nc_mdio *mdio, int prtad, int lane, uint8_t result) { uint16_t ret; @@ -1266,7 +1263,6 @@ static inline int nc_mdio_read(struct nc_mdio *mdio, int prtad, int devad, uint1 } } return mdio->mdio_read(comp, prtad, devad, addr); - } static inline int nc_mdio_write(struct nc_mdio *mdio, int prtad, int devad, uint16_t addr, uint16_t val) From 6deb7c8943821587e28983a9467be268dfd9d22d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 4 Oct 2024 15:43:42 +0200 Subject: [PATCH 210/518] bump version to 6.23.6 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 8d5ce012..6b7196cc 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Fri Oct 4 2024 Martin Spinler - 6.23.6-1 +- [BUGFIX] libnfb - MDIO: fix deadlock due to recursive lock + * Thu Oct 3 2024 Martin Spinler - 6.23.5-1 - [FEATURE] pynfb: add lock/unlock methods to Comp - [FEATURE] libnfb: add nfb_comp_trylock diff --git a/VERSION b/VERSION index b3b46191..95d8fb1b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.23.5 +6.23.6 From 280c8ebf8fddd6a519ffaf55dfcd70ea06e879ae Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 7 Oct 2024 09:15:19 +0200 Subject: [PATCH 211/518] libnfb - NDP [FIX]: silence Valgrind because of uninitialized memory --- drivers/kernel/include/linux/nfb/ndp.h | 2 +- libnfb/include/netcope/ndp_base.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/include/linux/nfb/ndp.h b/drivers/kernel/include/linux/nfb/ndp.h index a2402370..b62e3d6e 100644 --- a/drivers/kernel/include/linux/nfb/ndp.h +++ b/drivers/kernel/include/linux/nfb/ndp.h @@ -56,7 +56,7 @@ struct ndp_channel_request { */ struct ndp_subscription_sync { void *id; - __u32 flags; // timeout, interrupts? + __u32 flags; // timeout, interrupts? FIXME: unaligned __u64 size; __u64 hwptr; __u64 swptr; diff --git a/libnfb/include/netcope/ndp_base.h b/libnfb/include/netcope/ndp_base.h index bb4fb53c..58be6da3 100644 --- a/libnfb/include/netcope/ndp_base.h +++ b/libnfb/include/netcope/ndp_base.h @@ -112,6 +112,7 @@ int ndp_base_queue_open(struct nfb_device *dev, void *dev_priv, unsigned index, ret = -ENOMEM; goto err_nc_ndp_queue_alloc; } + memset(q_nc, 0, sizeof(struct nc_ndp_queue)); q_nc->q = q; q_nc->dev = dev; From dc555f07cc2387072b60366dab6f7e2dc7d5a1c6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 14 Oct 2024 14:53:07 +0200 Subject: [PATCH 212/518] libnfb: [FEATURE] report errors when accessing outside component space Report errors to stderr for failing nfb_comp_readXX / nfb_comp_writeXX, which doesn't return the success or failure value. --- libnfb/include/nfb/nfb.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libnfb/include/nfb/nfb.h b/libnfb/include/nfb/nfb.h index b021b286..1f542f20 100644 --- a/libnfb/include/nfb/nfb.h +++ b/libnfb/include/nfb/nfb.h @@ -11,6 +11,7 @@ #define LIBNFB_H #include +#include #include #include #include @@ -273,16 +274,28 @@ ssize_t nfb_comp_read(const struct nfb_comp *comp, void *buf, size_t nbyte, off_ */ ssize_t nfb_comp_write(const struct nfb_comp *comp, const void *buf, size_t nbyte, off_t offset); +static inline void nfb_comp_access_error(struct nfb_comp *comp, int write, size_t nbyte, off_t offset) +{ + fprintf(stderr, "libnfb: nfb_comp_%s%zu error accessing %s at offset: %04jx\n", + write ? "write" : "read", nbyte * 8, nfb_comp_path(comp), offset); +} + #define __nfb_comp_write(bits) \ static inline void nfb_comp_write##bits(struct nfb_comp *comp, off_t offset, uint##bits##_t val) \ { \ - nfb_comp_write(comp, &val, sizeof(val), offset); \ + int ret = nfb_comp_write(comp, &val, sizeof(val), offset); \ + if (ret != sizeof(val)) { \ + nfb_comp_access_error(comp, 1, sizeof(val), offset); \ + } \ } #define __nfb_comp_read(bits) \ static inline uint##bits##_t nfb_comp_read##bits(struct nfb_comp *comp, off_t offset) \ { \ uint##bits##_t val = 0; \ - nfb_comp_read(comp, &val, sizeof(val), offset); \ + int ret = nfb_comp_read(comp, &val, sizeof(val), offset); \ + if (ret != sizeof(val)) { \ + nfb_comp_access_error(comp, 0, sizeof(val), offset); \ + } \ return val; \ } From a0dd897254c8960533edf71b351b5dd8fa7341c8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 14 Oct 2024 15:07:20 +0200 Subject: [PATCH 213/518] drivers: [FEATURE] report errors when accessing outside component space Report errors to kernel log for failing nfb_comp_readXX / nfb_comp_writeXX, which doesn't return the success or failure value. --- drivers/kernel/drivers/nfb/nfb.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/nfb.h b/drivers/kernel/drivers/nfb/nfb.h index 48c51630..76949465 100644 --- a/drivers/kernel/drivers/nfb/nfb.h +++ b/drivers/kernel/drivers/nfb/nfb.h @@ -186,16 +186,28 @@ static inline ssize_t nfb_comp_write(struct nfb_comp *comp, const void *buf, siz return comp->bus->write(comp->bus, buf, nbyte, comp->offset + offset); } +static inline void nfb_comp_access_error(struct nfb_comp *comp, int write, size_t nbyte, off_t offset) +{ + dev_warn(comp->nfb->dev, "nfb_comp_%s%zu error accessing %s at offset: %04llx\n", + write ? "write" : "read", nbyte * 8, comp->path, (unsigned long long) offset); +} + #define __nfb_comp_write(bits) \ static inline void nfb_comp_write##bits(struct nfb_comp *comp, off_t offset, uint##bits##_t val) \ { \ - nfb_comp_write(comp, &val, sizeof(val), offset); \ + int ret = nfb_comp_write(comp, &val, sizeof(val), offset); \ + if (ret != sizeof(val)) { \ + nfb_comp_access_error(comp, 1, sizeof(val), offset); \ + } \ } #define __nfb_comp_read(bits) \ static inline uint##bits##_t nfb_comp_read##bits(struct nfb_comp *comp, off_t offset) \ { \ uint##bits##_t val = 0; \ - nfb_comp_read(comp, &val, sizeof(val), offset); \ + int ret = nfb_comp_read(comp, &val, sizeof(val), offset); \ + if (ret != sizeof(val)) { \ + nfb_comp_access_error(comp, 1, sizeof(val), offset); \ + } \ return val; \ } From 0c28b0ee08099650d7f1f6eb10b244d722aba0a0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 14 Oct 2024 14:02:02 +0200 Subject: [PATCH 214/518] tool - bus: [FEATURE] introduce byte mode for read & writes --- tools/bus/bus.c | 139 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 116 insertions(+), 23 deletions(-) diff --git a/tools/bus/bus.c b/tools/bus/bus.c index be85f0d5..25f98e79 100644 --- a/tools/bus/bus.c +++ b/tools/bus/bus.c @@ -22,13 +22,33 @@ #include #include -#define ARGUMENTS "d:p:c:i:n:w:alh" +#define ARGUMENTS "d:p:c:i:n:w:ablh" #define BUFFER_SIZE 256 int verbose = 0; enum command_t {CMD_NONE, CMD_PRINT_COMPONENTS} command; +int xdigittoint(const char c) +{ + if (c > 'f') + return -1; + if (c >= 'a') + return c - 'a' + 10; + + if (c > 'F') + return -1; + if (c >= 'A') + return c - 'A' + 10; + + if (c > '9') + return -1; + if (c >= '0') + return c - '0'; + + return -1; +} + void usage(const char *me) { printf("Usage: %s [-alh] [-d device] [-p path] [-c compatible] [-i index] [-n count] addr [val]\n", me); @@ -36,12 +56,20 @@ void usage(const char *me) printf("-p path Use component with specified path in Device Tree \n"); printf("-c compatible Set compatible string to use [default: \"netcope,bus,mi\"]\n"); printf("-i index Set index of component specified with compatible [default: 0]\n"); - printf("-n count Read 'count' (dec) 32bit values [default: 1]\n"); + printf("-n count Read 'count' (dec) of N-byte values [default: 1]\n"); printf("-a Print address\n"); + printf("-b Switch from dword mode (N=4) to byte mode (N=1)\n"); printf("-l List of available components\n"); printf("-h Show this text\n"); printf("addr Hexadecimal offset in selected component\n"); printf("val Write value 'val' (hex), same as -w val\n"); + printf("\n"); + printf("The input and output format differ depending on the selected mode:\n"); + printf(" - dword mode (default): hexadecimal number(s); LSB corresponds to the lower adress\n"); + printf(" - byte mode (with -b): hexadecimal char stream; leftmost byte corresponds to the lowest address\n"); + printf("\n"); + printf("Examples:\n"); + printf("%s -b 2 010203 Write 3 bytes to address 2\n", me); } void print_component_list(const void *fdt, int node_offset) @@ -70,6 +98,7 @@ void print_component_list(const void *fdt, int node_offset) int main(int argc, char *argv[]) { + int ret; int c; int node; const char *path = nfb_default_dev_path(); @@ -80,10 +109,17 @@ int main(int argc, char *argv[]) long param; unsigned offset; int show_address = 0; - int do_write = 0; + int use_32b = 1; int index = 0; - int count = 1; - unsigned data; + long count = 1; + char xc1, xc2; + /* print newline each N bytes in read dword mode */ + unsigned newline_span = 32; + char spacer; + + const char *wdata = NULL; + uint8_t *data; + uint32_t data32; const char *compatible_mi = "netcope,bus,mi"; const char *compatible = compatible_mi; @@ -91,6 +127,9 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, ARGUMENTS)) != -1) { switch (c) { + case 'b': + use_32b = 0; + break; case 'd': path = optarg; break; @@ -101,12 +140,12 @@ int main(int argc, char *argv[]) dtpath = optarg; break; case 'n': - count = strtoul(optarg, NULL, 10); - if (count < 0) + if (nc_strtol(optarg, &count)) errx(1, "invalid count"); break; case 'a': show_address = 1; + newline_span = 16; break; case 'i': if (nc_strtol(optarg, ¶m) || param < 0) { @@ -121,8 +160,7 @@ int main(int argc, char *argv[]) usage(argv[0]); return 0; case 'w': - data = strtoul(optarg, NULL, 16); - do_write = 1; + wdata = optarg; break; default: errx(1, "unknown argument -%c", optopt); @@ -151,11 +189,51 @@ int main(int argc, char *argv[]) offset = strtoul(argv[0], NULL, 16); if (argc == 2) { - if (do_write) + if (wdata) errx(1, "inconsistent usage"); - data = strtoul(argv[1], NULL, 16); - do_write = 1; + wdata = argv[1]; + } + + /* dword mode supports only one write */ + if (use_32b && wdata) + count = 1; + + if (use_32b) { + count *= 4; + } else if (wdata) { + count = strlen(wdata); + if (count & 1) + errx(1, "Incomplete input data (1 hex byte = 2 characters)"); + + /* Skip optional leading 0x */ + if (count >= 2 && (strncmp(wdata, "0x", 2) == 0 || strncmp(wdata, "0X", 2) == 0)) { + wdata += 2; + count -= 2; + } + + count /= 2; + } + + data = malloc(count); + if (data == NULL) + errx(1, "Memory allocation error"); + + if (wdata) { + /* Parse input string and fill to the data buffer */ + if (use_32b) { + data32 = strtoul(wdata, NULL, 16); + memcpy(data, &data32, count); + } else { + for (i = 0; i < count; i++) { + xc1 = xdigittoint(wdata[i * 2 + 0]); + xc2 = xdigittoint(wdata[i * 2 + 1]); + if (xc1 < 0 || xc2 < 0) + errx(1, "Non hexadecimal value at input"); + + data[i] = (xc1 << 4) | (xc2 << 0); + } + } } dev = nfb_open(path); @@ -175,20 +253,35 @@ int main(int argc, char *argv[]) errx(1, "Can't open component, check for valid FDT"); } - if (do_write) { - nfb_comp_write32(comp, offset, data); + if (wdata) { + ret = nfb_comp_write(comp, data, count, offset); + if (ret != count) + errx(1, "An error while write"); } else { - for (i = 0; i < count; i++) { - data = nfb_comp_read32(comp, offset + i * 4); - - if (show_address && (i % 4) == 0) - printf("%08x: ", offset + i * 4); - /*else if (index && (i % 8) == 0) - printf("%02x: ", i);*/ - printf("%08x%c", data, - (((i + 1) % (show_address ? 4 : 8)) == 0 || i == (count - 1) ? '\n' : ' ')); + ret = nfb_comp_read(comp, data, count, offset); + if (ret != count) + errx(1, "An error while read"); + + if (use_32b) { + for (i = 0; i < count; i += 4) { + spacer = (i % newline_span) ? ' ' : '\n'; + if (i) + printf("%c", spacer); + + if (show_address && spacer == '\n') + printf("%08x: ", offset + i * 4); + + memcpy(&data32, data + i, 4); + printf("%08x", data32); + } + } else { + for (i = 0; i < count; i++) { + printf("%02x", data[i]); + } } + printf("\n"); } + free(data); nfb_comp_close(comp); nfb_close(dev); From 09aa85e4bff6f5e6b9573990b5ac300d45641d8b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 14 Oct 2024 14:02:45 +0200 Subject: [PATCH 215/518] tool - bus: [FIX] check boundary of component address space --- tools/bus/bus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/bus/bus.c b/tools/bus/bus.c index 25f98e79..e7d18ff8 100644 --- a/tools/bus/bus.c +++ b/tools/bus/bus.c @@ -253,6 +253,11 @@ int main(int argc, char *argv[]) errx(1, "Can't open component, check for valid FDT"); } + /* Check boundaries with zero-sized write. */ + if (nfb_comp_write(comp, NULL, 0, offset + count) != 0) { + errx(1, "Required address space is outside the component range"); + } + if (wdata) { ret = nfb_comp_write(comp, data, count, offset); if (ret != count) From cd91cb0bb7ae0859b4bb43f644dc704621de923d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 23 Oct 2024 17:29:13 +0200 Subject: [PATCH 216/518] pynfb / libnfb_ext_python: move cdefs to ext and remove nfb dependency --- .../libnfb_ext_python/libnfb_ext_python.pxd | 82 ++++++++++++++++++- ext/libnfb_ext_python/pyproject.toml | 1 - ext/libnfb_ext_python/requirements.txt | 1 - ext/libnfb_ext_python/setup.py | 2 +- pynfb/nfb/libnfb.pxd | 64 --------------- 5 files changed, 82 insertions(+), 68 deletions(-) diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd index 4121651c..ac6a29d0 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd +++ b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd @@ -9,11 +9,91 @@ from cpython.ref cimport PyObject, Py_INCREF, Py_DECREF from libc.stdio cimport printf cimport libc.errno -from nfb.libnfb cimport * cdef extern from "": int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) +cdef extern from "": + cdef struct nfb_device: + pass + + cdef struct nfb_comp: + pass + + cdef struct ndp_packet: + unsigned char *data + unsigned char *header + unsigned data_length + unsigned header_length + uint16_t flags + + cdef struct ndp_queue: + pass + +cdef extern from "": + ctypedef ssize_t nfb_bus_read_func(void *p, void *buf, size_t nbyte, off_t offset) + ctypedef ssize_t nfb_bus_write_func(void *p, const void *buf, size_t nbyte, off_t offset) + + ctypedef int libnfb_ext_ops_open(const char *devname, int oflag, void **priv, void **fdt) + ctypedef void libnfb_ext_ops_close(void *priv) + ctypedef int libnfb_ext_ops_bus_open_mi(void *dev_priv, int bus_node, int comp_node, void ** bus_priv, libnfb_bus_ext_ops* ops) + ctypedef void libnfb_ext_ops_bus_close_mi(void *bus_priv) + ctypedef int libnfb_ext_ops_comp_lock(const nfb_comp *comp, uint32_t features) + ctypedef void libnfb_ext_ops_comp_unlock(const nfb_comp *comp, uint32_t features) + + ctypedef int libnfb_ext_ops_ndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq) + ctypedef int libnfb_ext_ops_ndp_queue_close(ndp_queue *q) + + ctypedef unsigned ndp_rx_burst_get_t(void *priv, ndp_packet *packets, unsigned count) + ctypedef int ndp_rx_burst_put_t(void *priv) + + ctypedef unsigned ndp_tx_burst_get_t(void *priv, ndp_packet *packets, unsigned count) + ctypedef int ndp_tx_burst_put_t(void *priv) + ctypedef int ndp_tx_burst_flush_t(void *priv) + + struct libnfb_ext_ops: + libnfb_ext_ops_open open + libnfb_ext_ops_close close + libnfb_ext_ops_bus_open_mi bus_open_mi + libnfb_ext_ops_bus_close_mi bus_close_mi + libnfb_ext_ops_comp_lock comp_lock + libnfb_ext_ops_comp_unlock comp_unlock + + libnfb_ext_ops_ndp_queue_open ndp_queue_open + libnfb_ext_ops_ndp_queue_close ndp_queue_close + + cdef struct libnfb_bus_ext_ops: + nfb_bus_read_func *read + nfb_bus_write_func *write + + ctypedef struct ndp_queue_ops_burst_tx: + ndp_tx_burst_get_t get + ndp_tx_burst_put_t put + ndp_tx_burst_flush_t flush + ctypedef struct ndp_queue_ops_burst_rx: + ndp_rx_burst_get_t get + ndp_rx_burst_put_t put + + ctypedef union ndp_queue_ops_burst: + ndp_queue_ops_burst_rx rx + ndp_queue_ops_burst_tx tx + + ctypedef struct ndp_queue_ops_control: + int (*start)(void *priv) + int (*stop)(void *priv) + + cdef struct ndp_queue_ops: + ndp_queue_ops_burst burst + ndp_queue_ops_control control + + cdef ndp_queue * ndp_queue_create(nfb_device *dev, int numa, int type, int index) + cdef void ndp_queue_destroy(ndp_queue* q) + + cdef void* ndp_queue_get_priv(ndp_queue *q) + cdef void ndp_queue_set_priv(ndp_queue *q, void *priv) + + cdef ndp_queue_ops* ndp_queue_get_ops(ndp_queue *q) + cdef api const char *nfb_pynfb_prefix diff --git a/ext/libnfb_ext_python/pyproject.toml b/ext/libnfb_ext_python/pyproject.toml index 2264294d..cc8e56ce 100644 --- a/ext/libnfb_ext_python/pyproject.toml +++ b/ext/libnfb_ext_python/pyproject.toml @@ -2,6 +2,5 @@ requires = [ "setuptools>=40.1.0", "Cython>=0.29.33", - "nfb", ] build-backend = "setuptools.build_meta" diff --git a/ext/libnfb_ext_python/requirements.txt b/ext/libnfb_ext_python/requirements.txt index 201a7353..d70d5c27 100644 --- a/ext/libnfb_ext_python/requirements.txt +++ b/ext/libnfb_ext_python/requirements.txt @@ -1,3 +1,2 @@ setuptools>=40.1.0 Cython>=0.29.33 -nfb diff --git a/ext/libnfb_ext_python/setup.py b/ext/libnfb_ext_python/setup.py index d88350d8..affb85df 100644 --- a/ext/libnfb_ext_python/setup.py +++ b/ext/libnfb_ext_python/setup.py @@ -24,5 +24,5 @@ ), py_modules=["libnfb_ext_python"], packages=find_namespace_packages(include=["nfb.*"]), - install_requires=['nfb'], + install_requires=['fdt'], ) diff --git a/pynfb/nfb/libnfb.pxd b/pynfb/nfb/libnfb.pxd index 29a489c3..00fba8d2 100644 --- a/pynfb/nfb/libnfb.pxd +++ b/pynfb/nfb/libnfb.pxd @@ -68,70 +68,6 @@ cdef extern from "": int ndp_queue_start(ndp_queue *queue) int ndp_queue_stop(ndp_queue *queue) -cdef extern from "": - ctypedef ssize_t nfb_bus_read_func(void *p, void *buf, size_t nbyte, off_t offset) - ctypedef ssize_t nfb_bus_write_func(void *p, const void *buf, size_t nbyte, off_t offset) - - ctypedef int libnfb_ext_ops_open(const char *devname, int oflag, void **priv, void **fdt) - ctypedef void libnfb_ext_ops_close(void *priv) - ctypedef int libnfb_ext_ops_bus_open_mi(void *dev_priv, int bus_node, int comp_node, void ** bus_priv, libnfb_bus_ext_ops* ops) - ctypedef void libnfb_ext_ops_bus_close_mi(void *bus_priv) - ctypedef int libnfb_ext_ops_comp_lock(const nfb_comp *comp, uint32_t features) - ctypedef void libnfb_ext_ops_comp_unlock(const nfb_comp *comp, uint32_t features) - - ctypedef int libnfb_ext_ops_ndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq) - ctypedef int libnfb_ext_ops_ndp_queue_close(ndp_queue *q) - - ctypedef unsigned ndp_rx_burst_get_t(void *priv, ndp_packet *packets, unsigned count) - ctypedef int ndp_rx_burst_put_t(void *priv) - - ctypedef unsigned ndp_tx_burst_get_t(void *priv, ndp_packet *packets, unsigned count) - ctypedef int ndp_tx_burst_put_t(void *priv) - ctypedef int ndp_tx_burst_flush_t(void *priv) - - struct libnfb_ext_ops: - libnfb_ext_ops_open open - libnfb_ext_ops_close close - libnfb_ext_ops_bus_open_mi bus_open_mi - libnfb_ext_ops_bus_close_mi bus_close_mi - libnfb_ext_ops_comp_lock comp_lock - libnfb_ext_ops_comp_unlock comp_unlock - - libnfb_ext_ops_ndp_queue_open ndp_queue_open - libnfb_ext_ops_ndp_queue_close ndp_queue_close - - cdef struct libnfb_bus_ext_ops: - nfb_bus_read_func *read - nfb_bus_write_func *write - - ctypedef struct ndp_queue_ops_burst_tx: - ndp_tx_burst_get_t get - ndp_tx_burst_put_t put - ndp_tx_burst_flush_t flush - ctypedef struct ndp_queue_ops_burst_rx: - ndp_rx_burst_get_t get - ndp_rx_burst_put_t put - - ctypedef union ndp_queue_ops_burst: - ndp_queue_ops_burst_rx rx - ndp_queue_ops_burst_tx tx - - ctypedef struct ndp_queue_ops_control: - int (*start)(void *priv) - int (*stop)(void *priv) - - cdef struct ndp_queue_ops: - ndp_queue_ops_burst burst - ndp_queue_ops_control control - - cdef ndp_queue * ndp_queue_create(nfb_device *dev, int numa, int type, int index) - cdef void ndp_queue_destroy(ndp_queue* q) - - cdef void* ndp_queue_get_priv(ndp_queue *q) - cdef void ndp_queue_set_priv(ndp_queue *q, void *priv) - - cdef ndp_queue_ops* ndp_queue_get_ops(ndp_queue *q) - cdef class NfbDeviceHandle: #cdef object __weakref__ From 51d67fc4a80d016f8e057f92a494f2ee2fe4d0d2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 29 Oct 2024 19:35:15 +0100 Subject: [PATCH 217/518] [MAINTENANCE]: sanitize licstrings Now it corresponds to README.md and real intention. --- configure.ac | 4 +--- drivers/Makefile.conf | 4 +--- drivers/Makefile.in | 2 +- drivers/configure.ac | 2 +- drivers/kernel/drivers/Makefile | 2 +- drivers/kernel/drivers/nfb/Makefile | 2 +- drivers/kernel/drivers/nfb/boot/boot.c | 2 +- drivers/kernel/drivers/nfb/boot/boot.h | 2 +- drivers/kernel/drivers/nfb/boot/flash.c | 2 +- drivers/kernel/drivers/nfb/boot/gecko.c | 2 +- drivers/kernel/drivers/nfb/boot/gecko.h | 2 +- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 2 +- drivers/kernel/drivers/nfb/boot/nfb-pmci.h | 2 +- drivers/kernel/drivers/nfb/boot/reload.c | 2 +- drivers/kernel/drivers/nfb/boot/sdm.c | 2 +- drivers/kernel/drivers/nfb/boot/sdm.h | 2 +- drivers/kernel/drivers/nfb/bus.c | 2 +- drivers/kernel/drivers/nfb/char.c | 2 +- drivers/kernel/drivers/nfb/core.c | 2 +- drivers/kernel/drivers/nfb/fdt.h | 2 +- drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c | 2 +- drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.h | 2 +- drivers/kernel/drivers/nfb/hwmon/nfb_hwmon_transceiver.h | 2 +- drivers/kernel/drivers/nfb/lock.c | 2 +- drivers/kernel/drivers/nfb/mi/mi.c | 2 +- drivers/kernel/drivers/nfb/mi/mi.h | 2 +- drivers/kernel/drivers/nfb/misc.c | 2 +- drivers/kernel/drivers/nfb/misc.h | 2 +- drivers/kernel/drivers/nfb/ndp/channel.c | 2 +- drivers/kernel/drivers/nfb/ndp/char.c | 2 +- drivers/kernel/drivers/nfb/ndp/ctrl.c | 2 +- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 2 +- drivers/kernel/drivers/nfb/ndp/driver.c | 2 +- drivers/kernel/drivers/nfb/ndp/kndp.c | 2 +- drivers/kernel/drivers/nfb/ndp/kndp.h | 2 +- drivers/kernel/drivers/nfb/ndp/ndp.h | 2 +- drivers/kernel/drivers/nfb/ndp/ring.c | 2 +- drivers/kernel/drivers/nfb/ndp/subscriber.c | 2 +- drivers/kernel/drivers/nfb/ndp/subscription.c | 2 +- drivers/kernel/drivers/nfb/ndp_netdev/core.c | 2 +- drivers/kernel/drivers/nfb/ndp_netdev/core.h | 2 +- drivers/kernel/drivers/nfb/net/compat.h | 2 +- drivers/kernel/drivers/nfb/net/device.c | 2 +- drivers/kernel/drivers/nfb/net/driver.c | 2 +- drivers/kernel/drivers/nfb/net/ethtool.c | 2 +- drivers/kernel/drivers/nfb/net/net.h | 2 +- drivers/kernel/drivers/nfb/net/sysfs.c | 2 +- drivers/kernel/drivers/nfb/nfb.h | 2 +- drivers/kernel/drivers/nfb/pci.c | 2 +- drivers/kernel/drivers/nfb/pci.h | 2 +- drivers/kernel/drivers/nfb/qdr/qdr.c | 2 +- drivers/kernel/drivers/nfb/qdr/qdr.h | 2 +- drivers/kernel/include/linux/nfb/boot.h | 2 +- drivers/kernel/include/linux/nfb/ndp.h | 2 +- drivers/kernel/include/linux/nfb/nfb.h | 2 +- ext/libnfb_ext_grpc/CMakeLists.txt | 2 +- libnfb/include/netcope/dma_ctrl_ndp.h | 2 +- libnfb/src/ndp/ndp.c | 2 +- python/nfb-tools/CMakeLists.txt | 2 +- tools-debug/CMakeLists.txt | 2 +- tools-debug/busdebugctl/busdebugctl.c | 2 +- tools-debug/busdump/busdump.c | 2 +- tools-debug/busreplay/busreplay.c | 2 +- tools-debug/nfb-mi-test/nfb-mi-test.c | 3 +-- tools-misc/CMakeLists.txt | 2 +- tools-misc/nfb-flash-ident/flashident.c | 2 +- tools-misc/nfb-flash-read/flashread.c | 2 +- tools-misc/nfb-spi-max/max-spi.c | 2 +- tools/CMakeLists.txt | 2 +- tools/boot/boot.c | 2 +- tools/bus/bus.c | 2 +- tools/dma/dma.c | 2 +- tools/eth/cfp2.c | 2 +- tools/eth/eth.h | 2 +- tools/eth/ieee802_3.c | 2 +- tools/eth/ieee802_3.h | 2 +- tools/eth/main.c | 2 +- tools/eth/mdio.h | 2 +- tools/eth/pcspma.c | 2 +- tools/eth/qsfpp.c | 2 +- tools/eth/query.c | 2 +- tools/eth/rxmac.c | 2 +- tools/eth/transceiver.c | 2 +- tools/eth/txmac.c | 2 +- tools/info/info.c | 2 +- tools/mdio/mdio.c | 2 +- tools/ndptool/common.c | 2 +- tools/ndptool/common.h | 2 +- tools/ndptool/generate.c | 2 +- tools/ndptool/loopback.c | 2 +- tools/ndptool/loopback_hw.c | 2 +- tools/ndptool/main.c | 2 +- tools/ndptool/modules.c | 2 +- tools/ndptool/pcap.c | 2 +- tools/ndptool/pcap.h | 2 +- tools/ndptool/read.c | 2 +- tools/ndptool/receive.c | 2 +- tools/ndptool/stats.c | 2 +- tools/ndptool/structured_packet.h | 2 +- tools/ndptool/transmit.c | 2 +- tools/tsu/tsu.c | 2 +- 101 files changed, 101 insertions(+), 106 deletions(-) diff --git a/configure.ac b/configure.ac index 4e3673b0..588f205a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,12 +1,10 @@ +# SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 # # NFB framework configure script # # Copyright (C) 2018 CESNET # Author(s): # Martin Spinler -# -# SPDX-License-Identifier: GPL-2.0 -# # ----[ SECTION: Autoconf setup ]---- # AC_PREREQ([2.63]) diff --git a/drivers/Makefile.conf b/drivers/Makefile.conf index 243b4c4d..8c291f96 100644 --- a/drivers/Makefile.conf +++ b/drivers/Makefile.conf @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 # # Configuration Makefile for NFB driver # @@ -5,9 +6,6 @@ # # Author(s): # Martin Spinler -# -# SPDX-License-Identifier: GPL-2.0 -# CONFIG_MODULES = y CONFIG_NFB = m diff --git a/drivers/Makefile.in b/drivers/Makefile.in index 03e611b0..8a518770 100644 --- a/drivers/Makefile.in +++ b/drivers/Makefile.in @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 # # NFB driver Makefile # diff --git a/drivers/configure.ac b/drivers/configure.ac index 0e35e475..e6a61b68 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 # # Configure script for NFB driver # diff --git a/drivers/kernel/drivers/Makefile b/drivers/kernel/drivers/Makefile index e73f8459..8ae716f4 100644 --- a/drivers/kernel/drivers/Makefile +++ b/drivers/kernel/drivers/Makefile @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 # # Makefile for NFB driver # diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index a980087e..6f6fc815 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 # # NFB driver Makefile # diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index b5211bd6..4b4bf7d4 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Boot driver module header of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/boot/boot.h b/drivers/kernel/drivers/nfb/boot/boot.h index 923dab84..72c2858d 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.h +++ b/drivers/kernel/drivers/nfb/boot/boot.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Boot driver module header of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/boot/flash.c b/drivers/kernel/drivers/nfb/boot/flash.c index d1f943c9..8c449d91 100644 --- a/drivers/kernel/drivers/nfb/boot/flash.c +++ b/drivers/kernel/drivers/nfb/boot/flash.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Boot driver of the NFB platform - flash module * diff --git a/drivers/kernel/drivers/nfb/boot/gecko.c b/drivers/kernel/drivers/nfb/boot/gecko.c index a223dd41..f25d80fb 100644 --- a/drivers/kernel/drivers/nfb/boot/gecko.c +++ b/drivers/kernel/drivers/nfb/boot/gecko.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Boot driver of the NFB platform - gecko module * diff --git a/drivers/kernel/drivers/nfb/boot/gecko.h b/drivers/kernel/drivers/nfb/boot/gecko.h index 84c82f87..a435b9ec 100644 --- a/drivers/kernel/drivers/nfb/boot/gecko.h +++ b/drivers/kernel/drivers/nfb/boot/gecko.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Boot driver of the NFB platform - gecko module * diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index f658897d..552246f4 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Boot driver module for Intel M10 BMC * diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.h b/drivers/kernel/drivers/nfb/boot/nfb-pmci.h index 005defc4..7203a871 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.h +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Boot driver module header for Intel M10 BMC * diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index 54808f9b..c2ff8c34 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Boot driver of the NFB platform - reload module * diff --git a/drivers/kernel/drivers/nfb/boot/sdm.c b/drivers/kernel/drivers/nfb/boot/sdm.c index 7de157eb..c371b90c 100644 --- a/drivers/kernel/drivers/nfb/boot/sdm.c +++ b/drivers/kernel/drivers/nfb/boot/sdm.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * sdm.c: SDM Client commands implementation * diff --git a/drivers/kernel/drivers/nfb/boot/sdm.h b/drivers/kernel/drivers/nfb/boot/sdm.h index 185880f6..da436b4a 100644 --- a/drivers/kernel/drivers/nfb/boot/sdm.h +++ b/drivers/kernel/drivers/nfb/boot/sdm.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * sdm.h: SDM Client commands header file * diff --git a/drivers/kernel/drivers/nfb/bus.c b/drivers/kernel/drivers/nfb/bus.c index e3281429..eff3b21b 100644 --- a/drivers/kernel/drivers/nfb/bus.c +++ b/drivers/kernel/drivers/nfb/bus.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Component and bus driver module of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/char.c b/drivers/kernel/drivers/nfb/char.c index 65179380..43c6ac37 100644 --- a/drivers/kernel/drivers/nfb/char.c +++ b/drivers/kernel/drivers/nfb/char.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Char driver module of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/core.c b/drivers/kernel/drivers/nfb/core.c index 85c3774d..3bcb97ec 100644 --- a/drivers/kernel/drivers/nfb/core.c +++ b/drivers/kernel/drivers/nfb/core.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Core driver module of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/fdt.h b/drivers/kernel/drivers/nfb/fdt.h index a30c725f..9a561ed8 100644 --- a/drivers/kernel/drivers/nfb/fdt.h +++ b/drivers/kernel/drivers/nfb/fdt.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * libfdt extension of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c index 4c0fb84d..43746653 100644 --- a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c +++ b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * HWMon driver module of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.h b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.h index e07e0905..6a09b231 100644 --- a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.h +++ b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * HWMon driver module header of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon_transceiver.h b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon_transceiver.h index f44d7050..a2308e6e 100644 --- a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon_transceiver.h +++ b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon_transceiver.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * HWMon helper library - transciever sensors functions * diff --git a/drivers/kernel/drivers/nfb/lock.c b/drivers/kernel/drivers/nfb/lock.c index b2b9def5..8720a723 100644 --- a/drivers/kernel/drivers/nfb/lock.c +++ b/drivers/kernel/drivers/nfb/lock.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * MI bus driver module of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/mi/mi.c b/drivers/kernel/drivers/nfb/mi/mi.c index a09828bd..f3654c98 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.c +++ b/drivers/kernel/drivers/nfb/mi/mi.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * MI bus driver of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/mi/mi.h b/drivers/kernel/drivers/nfb/mi/mi.h index 114c826d..a0848337 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.h +++ b/drivers/kernel/drivers/nfb/mi/mi.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * MI driver header of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/misc.c b/drivers/kernel/drivers/nfb/misc.c index 5b2153c8..9c6d56ec 100644 --- a/drivers/kernel/drivers/nfb/misc.c +++ b/drivers/kernel/drivers/nfb/misc.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Misc functions of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/misc.h b/drivers/kernel/drivers/nfb/misc.h index 0c9f2d61..8284c9ae 100644 --- a/drivers/kernel/drivers/nfb/misc.h +++ b/drivers/kernel/drivers/nfb/misc.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Header for misc functionality of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/ndp/channel.c b/drivers/kernel/drivers/nfb/ndp/channel.c index d0c10f36..d2cbe19f 100644 --- a/drivers/kernel/drivers/nfb/ndp/channel.c +++ b/drivers/kernel/drivers/nfb/ndp/channel.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - transmission channel module * diff --git a/drivers/kernel/drivers/nfb/ndp/char.c b/drivers/kernel/drivers/nfb/ndp/char.c index 729cf053..1262e3ab 100644 --- a/drivers/kernel/drivers/nfb/ndp/char.c +++ b/drivers/kernel/drivers/nfb/ndp/char.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - char module * diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl.c b/drivers/kernel/drivers/nfb/ndp/ctrl.c index a9c5bb81..a04ac454 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - DMA controller - SZE/v1 type * diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 5c00a016..0455baa0 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - DMA controller - Medusa/v2 type, Calypte/v3 type * diff --git a/drivers/kernel/drivers/nfb/ndp/driver.c b/drivers/kernel/drivers/nfb/ndp/driver.c index ff6a049f..b9aebbed 100644 --- a/drivers/kernel/drivers/nfb/ndp/driver.c +++ b/drivers/kernel/drivers/nfb/ndp/driver.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - main module * diff --git a/drivers/kernel/drivers/nfb/ndp/kndp.c b/drivers/kernel/drivers/nfb/ndp/kndp.c index cccd0481..407830c4 100644 --- a/drivers/kernel/drivers/nfb/ndp/kndp.c +++ b/drivers/kernel/drivers/nfb/ndp/kndp.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - sync module * diff --git a/drivers/kernel/drivers/nfb/ndp/kndp.h b/drivers/kernel/drivers/nfb/ndp/kndp.h index 7371ef33..a2821d50 100644 --- a/drivers/kernel/drivers/nfb/ndp/kndp.h +++ b/drivers/kernel/drivers/nfb/ndp/kndp.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - public header * diff --git a/drivers/kernel/drivers/nfb/ndp/ndp.h b/drivers/kernel/drivers/nfb/ndp/ndp.h index c94216eb..b3c9b9dc 100644 --- a/drivers/kernel/drivers/nfb/ndp/ndp.h +++ b/drivers/kernel/drivers/nfb/ndp/ndp.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - private header * diff --git a/drivers/kernel/drivers/nfb/ndp/ring.c b/drivers/kernel/drivers/nfb/ndp/ring.c index 0b43fa67..861502d9 100644 --- a/drivers/kernel/drivers/nfb/ndp/ring.c +++ b/drivers/kernel/drivers/nfb/ndp/ring.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - ring buffer module * diff --git a/drivers/kernel/drivers/nfb/ndp/subscriber.c b/drivers/kernel/drivers/nfb/ndp/subscriber.c index 940ba2d6..2cc9f15a 100644 --- a/drivers/kernel/drivers/nfb/ndp/subscriber.c +++ b/drivers/kernel/drivers/nfb/ndp/subscriber.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - subscriber module * diff --git a/drivers/kernel/drivers/nfb/ndp/subscription.c b/drivers/kernel/drivers/nfb/ndp/subscription.c index 8ffde825..7cdf9a5d 100644 --- a/drivers/kernel/drivers/nfb/ndp/subscription.c +++ b/drivers/kernel/drivers/nfb/ndp/subscription.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP driver of the NFB platform - subscription module * diff --git a/drivers/kernel/drivers/nfb/ndp_netdev/core.c b/drivers/kernel/drivers/nfb/ndp_netdev/core.c index 6c959ac6..1d1b505e 100644 --- a/drivers/kernel/drivers/nfb/ndp_netdev/core.c +++ b/drivers/kernel/drivers/nfb/ndp_netdev/core.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP backend network interface driver of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/ndp_netdev/core.h b/drivers/kernel/drivers/nfb/ndp_netdev/core.h index 0f8b660a..dd410b1d 100644 --- a/drivers/kernel/drivers/nfb/ndp_netdev/core.h +++ b/drivers/kernel/drivers/nfb/ndp_netdev/core.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP backend network interface driver of the NFB platform - main header * diff --git a/drivers/kernel/drivers/nfb/net/compat.h b/drivers/kernel/drivers/nfb/net/compat.h index 1294241f..7a0b5aaf 100644 --- a/drivers/kernel/drivers/nfb/net/compat.h +++ b/drivers/kernel/drivers/nfb/net/compat.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * NDP backend network interface driver of the NFB platform - compatibility hdr * diff --git a/drivers/kernel/drivers/nfb/net/device.c b/drivers/kernel/drivers/nfb/net/device.c index 462d8a31..4df3eab3 100644 --- a/drivers/kernel/drivers/nfb/net/device.c +++ b/drivers/kernel/drivers/nfb/net/device.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Network interface driver of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/net/driver.c b/drivers/kernel/drivers/nfb/net/driver.c index d7ad297f..544da90c 100644 --- a/drivers/kernel/drivers/nfb/net/driver.c +++ b/drivers/kernel/drivers/nfb/net/driver.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Network interface driver of the NFB platform - core * diff --git a/drivers/kernel/drivers/nfb/net/ethtool.c b/drivers/kernel/drivers/nfb/net/ethtool.c index 60d5192e..6594addf 100644 --- a/drivers/kernel/drivers/nfb/net/ethtool.c +++ b/drivers/kernel/drivers/nfb/net/ethtool.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Network interface driver of the NFB platform - ethtool support * diff --git a/drivers/kernel/drivers/nfb/net/net.h b/drivers/kernel/drivers/nfb/net/net.h index 4501857b..7b364c9a 100644 --- a/drivers/kernel/drivers/nfb/net/net.h +++ b/drivers/kernel/drivers/nfb/net/net.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Network interface driver of the NFB platform - main header * diff --git a/drivers/kernel/drivers/nfb/net/sysfs.c b/drivers/kernel/drivers/nfb/net/sysfs.c index 37e909ec..75b66761 100644 --- a/drivers/kernel/drivers/nfb/net/sysfs.c +++ b/drivers/kernel/drivers/nfb/net/sysfs.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Network interface driver of the NFB platform - sysfs support * diff --git a/drivers/kernel/drivers/nfb/nfb.h b/drivers/kernel/drivers/nfb/nfb.h index 76949465..b371ffe0 100644 --- a/drivers/kernel/drivers/nfb/nfb.h +++ b/drivers/kernel/drivers/nfb/nfb.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Main driver private header of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 37d5ae2e..3df1d11b 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * PCI driver module of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index a372e3b4..ce1f7a55 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * PCI driver module header of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/qdr/qdr.c b/drivers/kernel/drivers/nfb/qdr/qdr.c index d4f914e7..2d7297c8 100644 --- a/drivers/kernel/drivers/nfb/qdr/qdr.c +++ b/drivers/kernel/drivers/nfb/qdr/qdr.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * QDR driver module of the NFB platform * diff --git a/drivers/kernel/drivers/nfb/qdr/qdr.h b/drivers/kernel/drivers/nfb/qdr/qdr.h index adc084a5..1c837758 100644 --- a/drivers/kernel/drivers/nfb/qdr/qdr.h +++ b/drivers/kernel/drivers/nfb/qdr/qdr.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * QDR driver module of the NFB platform - header file * diff --git a/drivers/kernel/include/linux/nfb/boot.h b/drivers/kernel/include/linux/nfb/boot.h index 51e96577..52d8cb4f 100644 --- a/drivers/kernel/include/linux/nfb/boot.h +++ b/drivers/kernel/include/linux/nfb/boot.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ /* * NFB driver Boot component public header * diff --git a/drivers/kernel/include/linux/nfb/ndp.h b/drivers/kernel/include/linux/nfb/ndp.h index b62e3d6e..96585f2a 100644 --- a/drivers/kernel/include/linux/nfb/ndp.h +++ b/drivers/kernel/include/linux/nfb/ndp.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ /* * Interface to the NDP interface * diff --git a/drivers/kernel/include/linux/nfb/nfb.h b/drivers/kernel/include/linux/nfb/nfb.h index 74d7826a..480289f8 100644 --- a/drivers/kernel/include/linux/nfb/nfb.h +++ b/drivers/kernel/include/linux/nfb/nfb.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ /* * NFB driver public header file * diff --git a/ext/libnfb_ext_grpc/CMakeLists.txt b/ext/libnfb_ext_grpc/CMakeLists.txt index 64e5285f..7f34d2f0 100644 --- a/ext/libnfb_ext_grpc/CMakeLists.txt +++ b/ext/libnfb_ext_grpc/CMakeLists.txt @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: BSD-3-Clause # # CMake build file for NFB debug tools # diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index bcef16ab..d7ca227e 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ /* * Network component library - DMA controller - NDP/v2 type, CALYPTE/v3 type * diff --git a/libnfb/src/ndp/ndp.c b/libnfb/src/ndp/ndp.c index 0facca39..a2095b8a 100644 --- a/libnfb/src/ndp/ndp.c +++ b/libnfb/src/ndp/ndp.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * NDP driver of the NFB platform - sync module * diff --git a/python/nfb-tools/CMakeLists.txt b/python/nfb-tools/CMakeLists.txt index c83ee1b3..839913b1 100644 --- a/python/nfb-tools/CMakeLists.txt +++ b/python/nfb-tools/CMakeLists.txt @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: BSD-3-Clause # # CMake build file for NFB python tools # diff --git a/tools-debug/CMakeLists.txt b/tools-debug/CMakeLists.txt index acbaef73..8552d361 100644 --- a/tools-debug/CMakeLists.txt +++ b/tools-debug/CMakeLists.txt @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: BSD-3-Clause # # CMake build file for NFB debug tools # diff --git a/tools-debug/busdebugctl/busdebugctl.c b/tools-debug/busdebugctl/busdebugctl.c index 00901bcd..f3b76087 100644 --- a/tools-debug/busdebugctl/busdebugctl.c +++ b/tools-debug/busdebugctl/busdebugctl.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /*! * \file busdebugctl.c * \brief Tool for controlling the data streaming bus debuging master and connected probes. (STREAMING_DEBUG) diff --git a/tools-debug/busdump/busdump.c b/tools-debug/busdump/busdump.c index 0671ac88..0081a4fb 100644 --- a/tools-debug/busdump/busdump.c +++ b/tools-debug/busdump/busdump.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /*! * \file busdump.c * \brief Tool to read dumped Frame Link Unaligned data from firmware diff --git a/tools-debug/busreplay/busreplay.c b/tools-debug/busreplay/busreplay.c index 45c808d7..0a2e0c95 100644 --- a/tools-debug/busreplay/busreplay.c +++ b/tools-debug/busreplay/busreplay.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /*! * \file busreplay.c * \brief Tool to write dumped Frame Link Unaligned data into firmware diff --git a/tools-debug/nfb-mi-test/nfb-mi-test.c b/tools-debug/nfb-mi-test/nfb-mi-test.c index 1ddc8c0e..cdc0709a 100644 --- a/tools-debug/nfb-mi-test/nfb-mi-test.c +++ b/tools-debug/nfb-mi-test/nfb-mi-test.c @@ -1,11 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * MI test tool * * Copyright (C) CESNET, 2024 * Author(s): * Martin Spinler - * - * SPDX-License-Identifier: GPL-2.0 */ #include diff --git a/tools-misc/CMakeLists.txt b/tools-misc/CMakeLists.txt index 0799b465..b18c167a 100644 --- a/tools-misc/CMakeLists.txt +++ b/tools-misc/CMakeLists.txt @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: BSD-3-Clause # # CMake build file for NFB miscellaneous tools # diff --git a/tools-misc/nfb-flash-ident/flashident.c b/tools-misc/nfb-flash-ident/flashident.c index dbd7373a..f4b6cf37 100644 --- a/tools-misc/nfb-flash-ident/flashident.c +++ b/tools-misc/nfb-flash-ident/flashident.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Board identification tool * diff --git a/tools-misc/nfb-flash-read/flashread.c b/tools-misc/nfb-flash-read/flashread.c index 378670e4..a00fbda8 100644 --- a/tools-misc/nfb-flash-read/flashread.c +++ b/tools-misc/nfb-flash-read/flashread.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Flash/MTD memory read tool * diff --git a/tools-misc/nfb-spi-max/max-spi.c b/tools-misc/nfb-spi-max/max-spi.c index 782ff26e..cb7aef0f 100644 --- a/tools-misc/nfb-spi-max/max-spi.c +++ b/tools-misc/nfb-spi-max/max-spi.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Tool for access MAX chip over SPI on specific boards * diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index cd9a39c5..a6decd58 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: BSD-3-Clause # # CMake build file for NFB tools # diff --git a/tools/boot/boot.c b/tools/boot/boot.c index d305313b..54ed37c1 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Flash and boot tool * diff --git a/tools/bus/bus.c b/tools/bus/bus.c index e7d18ff8..e60bf74c 100644 --- a/tools/bus/bus.c +++ b/tools/bus/bus.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Firmware bus tool * diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 562795a2..271ac111 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * DMA controller status tool * diff --git a/tools/eth/cfp2.c b/tools/eth/cfp2.c index 765edadf..38c53237 100644 --- a/tools/eth/cfp2.c +++ b/tools/eth/cfp2.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - CFP2 control * diff --git a/tools/eth/eth.h b/tools/eth/eth.h index 840ef680..b2872403 100644 --- a/tools/eth/eth.h +++ b/tools/eth/eth.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - private header * diff --git a/tools/eth/ieee802_3.c b/tools/eth/ieee802_3.c index e3eaee87..e7d43b35 100644 --- a/tools/eth/ieee802_3.c +++ b/tools/eth/ieee802_3.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - IEEE 802.3 registers * diff --git a/tools/eth/ieee802_3.h b/tools/eth/ieee802_3.h index 1dec01ae..fb7df72c 100644 --- a/tools/eth/ieee802_3.h +++ b/tools/eth/ieee802_3.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - IEEE 802.3 registers header file * diff --git a/tools/eth/main.c b/tools/eth/main.c index c2347029..6218e037 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool * diff --git a/tools/eth/mdio.h b/tools/eth/mdio.h index 340e8eb1..cd580c18 100644 --- a/tools/eth/mdio.h +++ b/tools/eth/mdio.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - private MDIO header * diff --git a/tools/eth/pcspma.c b/tools/eth/pcspma.c index c87a257e..7aa13a10 100644 --- a/tools/eth/pcspma.c +++ b/tools/eth/pcspma.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - PCS/PMA control * diff --git a/tools/eth/qsfpp.c b/tools/eth/qsfpp.c index 1bc4f7ef..c4d296a6 100644 --- a/tools/eth/qsfpp.c +++ b/tools/eth/qsfpp.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - QSFP+ control * diff --git a/tools/eth/query.c b/tools/eth/query.c index b8c281b4..afa51e48 100644 --- a/tools/eth/query.c +++ b/tools/eth/query.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - query interface * diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index f77a2a4e..3d8f2f17 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - RX MAC control * diff --git a/tools/eth/transceiver.c b/tools/eth/transceiver.c index 7224df0d..70bc1e28 100644 --- a/tools/eth/transceiver.c +++ b/tools/eth/transceiver.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - transceiver control * diff --git a/tools/eth/txmac.c b/tools/eth/txmac.c index 27b2fe7e..8f79ba47 100644 --- a/tools/eth/txmac.c +++ b/tools/eth/txmac.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Ethernet interface configuration tool - TX MAC control * diff --git a/tools/info/info.c b/tools/info/info.c index dd2fb0d8..d51dbd05 100644 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Basic information tool * diff --git a/tools/mdio/mdio.c b/tools/mdio/mdio.c index a5a38f88..7b7bac88 100644 --- a/tools/mdio/mdio.c +++ b/tools/mdio/mdio.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * MDIO control tool * diff --git a/tools/ndptool/common.c b/tools/ndptool/common.c index d30a7ef5..8a6e67da 100644 --- a/tools/ndptool/common.c +++ b/tools/ndptool/common.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - common code * diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index 48c14c7e..d34bc271 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - common code header * diff --git a/tools/ndptool/generate.c b/tools/ndptool/generate.c index 9cc591cc..0f44ddb3 100644 --- a/tools/ndptool/generate.c +++ b/tools/ndptool/generate.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - generate module * diff --git a/tools/ndptool/loopback.c b/tools/ndptool/loopback.c index 1e815bb1..b6e710eb 100644 --- a/tools/ndptool/loopback.c +++ b/tools/ndptool/loopback.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - loopback module * diff --git a/tools/ndptool/loopback_hw.c b/tools/ndptool/loopback_hw.c index b39098fd..fdceafe9 100644 --- a/tools/ndptool/loopback_hw.c +++ b/tools/ndptool/loopback_hw.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - loopback module * diff --git a/tools/ndptool/main.c b/tools/ndptool/main.c index 4d8c2714..aa9ad8da 100644 --- a/tools/ndptool/main.c +++ b/tools/ndptool/main.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool * diff --git a/tools/ndptool/modules.c b/tools/ndptool/modules.c index e8dfd3df..cf41f597 100644 --- a/tools/ndptool/modules.c +++ b/tools/ndptool/modules.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - modules * diff --git a/tools/ndptool/pcap.c b/tools/ndptool/pcap.c index e3c3cb77..783a2e15 100644 --- a/tools/ndptool/pcap.c +++ b/tools/ndptool/pcap.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - PCAP file handling * diff --git a/tools/ndptool/pcap.h b/tools/ndptool/pcap.h index d7e00bb2..a04e83da 100644 --- a/tools/ndptool/pcap.h +++ b/tools/ndptool/pcap.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - PCAP file handling header * diff --git a/tools/ndptool/read.c b/tools/ndptool/read.c index 49beffd5..e5f5fb6c 100644 --- a/tools/ndptool/read.c +++ b/tools/ndptool/read.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - read module * diff --git a/tools/ndptool/receive.c b/tools/ndptool/receive.c index a38811c0..0fc6ee62 100644 --- a/tools/ndptool/receive.c +++ b/tools/ndptool/receive.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - receive module * diff --git a/tools/ndptool/stats.c b/tools/ndptool/stats.c index ff39d838..a34bee21 100644 --- a/tools/ndptool/stats.c +++ b/tools/ndptool/stats.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - statistics * diff --git a/tools/ndptool/structured_packet.h b/tools/ndptool/structured_packet.h index 6fc51a3c..d47dab34 100644 --- a/tools/ndptool/structured_packet.h +++ b/tools/ndptool/structured_packet.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - structured packet manipulations * diff --git a/tools/ndptool/transmit.c b/tools/ndptool/transmit.c index a141dbf7..2425ce44 100644 --- a/tools/ndptool/transmit.c +++ b/tools/ndptool/transmit.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Data transmission tool - transmit module * diff --git a/tools/tsu/tsu.c b/tools/tsu/tsu.c index 08a5cbbe..e35ec1c4 100644 --- a/tools/tsu/tsu.c +++ b/tools/tsu/tsu.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * TSU time synchronisation tool * From 05208018f8d4a63a41320eff5d29a9e67480943c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 4 Nov 2024 15:32:23 +0100 Subject: [PATCH 218/518] drivers - pci: split nfb_pci_read_fdt to nfb_pci_copy_fdt --- drivers/kernel/drivers/nfb/pci.c | 66 ++++++++++++++++++++++++-------- drivers/kernel/drivers/nfb/pci.h | 1 + 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 3df1d11b..42429ba6 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -500,7 +500,6 @@ static int nfb_pci_read_enpoint_id(struct pci_dev *pci) */ static void *nfb_pci_read_fdt(struct pci_dev *pci) { - void * fdt; int i; int ret; int cap_dtb; @@ -594,24 +593,13 @@ static void *nfb_pci_read_fdt(struct pci_dev *pci) goto err_fdt_check_header; } - /* Increase size for driver usage */ - buffer.out_size *= 4; - buffer.out = krealloc(buffer.out, buffer.out_size, GFP_KERNEL); - if (buffer.out == NULL) { - ret = -ENOMEM; - goto err_fdt_final_realloc; - } - xz_dec_end(decoder); kfree(buffer.in); - fdt = buffer.out; - dev_info(&pci->dev, "FDT loaded, size: %u, allocated buffer size: %zu\n", fdt_totalsize(fdt), buffer.out_size); - fdt_set_totalsize(fdt, buffer.out_size); + fdt_set_totalsize(buffer.out, buffer.out_size); - return fdt; + return buffer.out; -err_fdt_final_realloc: err_fdt_check_header: err_dec_run: xz_dec_end(decoder); @@ -627,6 +615,43 @@ static void *nfb_pci_read_fdt(struct pci_dev *pci) return ERR_PTR(ret); } +static void *nfb_pci_copy_fdt(struct nfb_pci_device *pci_device) +{ + const int FDT_SIZE_MULTIPLIER = 4; + + int ret; + size_t len_orig, len; + void * fdt; + + if (pci_device->fdt == NULL) { + ret = -EINVAL; + goto err_no_fdt; + } + len_orig = fdt_totalsize(pci_device->fdt); + if (len_orig == 0) { + ret = -EINVAL; + goto err_no_fdtlen; + } + + len = len_orig * FDT_SIZE_MULTIPLIER; + + fdt = kzalloc(len, GFP_KERNEL); + if (fdt == NULL) { + ret = -ENOMEM; + goto err_fdt_malloc; + } + memcpy(fdt, pci_device->fdt, len_orig); + + dev_info(&pci_device->pci->dev, "FDT loaded, size: %u, allocated buffer size: %zu\n", fdt_totalsize(fdt), len); + fdt_set_totalsize(fdt, len); + return fdt; + +err_fdt_malloc: +err_no_fdtlen: +err_no_fdt: + return ERR_PTR(ret); +} + /* * nfb_interrupt - interrupt callback for NFB device * @irq: interrupt vector @@ -758,6 +783,7 @@ struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) { + void *fdt; struct nfb_pci_device * pci_device; mutex_lock(&global_pci_device_list_lock); @@ -780,6 +806,14 @@ struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) pci_device->dsn = nfb_pci_read_dsn(pci); pci_device->index = nfb_pci_read_enpoint_id(pci); pci_device->index_valid = 1; + + if (pci_device->fdt) { + kfree(pci_device->fdt); + pci_device->fdt = NULL; + } + fdt = nfb_pci_read_fdt(pci); + if (!IS_ERR(fdt)) + pci_device->fdt = fdt; } return pci_device; @@ -1042,7 +1076,7 @@ static int nfb_pci_probe_main(struct nfb_pci_device *pci_device, const struct pc nfb->fdt = nfb_dtb_inject; if (nfb->fdt == NULL) { /* Populate device tree */ - nfb->fdt = nfb_pci_read_fdt(pci); + nfb->fdt = nfb_pci_copy_fdt(pci_device); } if (IS_ERR(nfb->fdt)) { ret = PTR_ERR(nfb->fdt); @@ -1224,6 +1258,8 @@ void nfb_pci_exit(void) list_for_each_entry_safe(pci_device, temp, &global_pci_device_list, global_pci_device_list) { list_del(&pci_device->global_pci_device_list); + if (pci_device->fdt) + kfree(pci_device->fdt); kfree(pci_device); } } diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index ce1f7a55..cd99f304 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -80,6 +80,7 @@ struct nfb_pci_device { uint16_t bridge_command; uint16_t bridge_devctl; + void * fdt; }; void nfb_pci_detach_endpoint(struct nfb_device *nfb, struct pci_dev *pci); From 02aae6b839baaa9d5f6d28cbc865d0e0f546a400 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 24 Oct 2024 19:05:36 +0200 Subject: [PATCH 219/518] drivers - pci: [FEATURE] check subdevices by card_name (and DSN) --- drivers/kernel/drivers/nfb/pci.c | 38 +++++++++++++++++++++++++++----- drivers/kernel/drivers/nfb/pci.h | 1 + 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 42429ba6..17d58949 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -715,6 +715,8 @@ static void nfb_pci_tuneup(struct pci_dev *pdev) static int nfb_pci_is_attachable(struct nfb_device *nfb, struct pci_dev* pci) { + struct nfb_pci_device *pci_device, *main_pci_device; + if (nfb == NULL || pci == NULL) return 0; @@ -725,10 +727,18 @@ static int nfb_pci_is_attachable(struct nfb_device *nfb, struct pci_dev* pci) if (nfb->pci->vendor != pci->vendor) return 0; - if (nfb->nfb_pci_dev == NULL || - nfb->nfb_pci_dev->sub_device_id == 0 || - nfb->nfb_pci_dev->sub_device_id != pci->device) - return 0; + if (nfb->nfb_pci_dev != NULL && nfb->nfb_pci_dev->sub_device_id != 0) { + if (nfb->nfb_pci_dev->sub_device_id != pci->device) + return 0; + } else { + pci_device = (struct nfb_pci_device *) pci_get_drvdata(pci); + main_pci_device = (struct nfb_pci_device *) pci_get_drvdata(nfb->pci); + + if (!main_pci_device || !main_pci_device->card_name || !pci_device || !pci_device->card_name || + strcmp(main_pci_device->card_name, pci_device->card_name)) { + return 0; + } + } return 1; } @@ -783,6 +793,9 @@ struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) { + int proplen; + int node; + const char *card_name; void *fdt; struct nfb_pci_device * pci_device; @@ -811,9 +824,20 @@ struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) kfree(pci_device->fdt); pci_device->fdt = NULL; } + + if (pci_device->card_name) { + kfree(pci_device->card_name); + pci_device->card_name = NULL; + } + fdt = nfb_pci_read_fdt(pci); - if (!IS_ERR(fdt)) + if (!IS_ERR(fdt)) { pci_device->fdt = fdt; + node = fdt_path_offset(fdt, "/firmware"); + card_name = fdt_getprop(fdt, node, "card-name", &proplen); + if (proplen > 0) + pci_device->card_name = kstrdup(card_name, GFP_KERNEL); + } } return pci_device; @@ -1260,6 +1284,10 @@ void nfb_pci_exit(void) list_del(&pci_device->global_pci_device_list); if (pci_device->fdt) kfree(pci_device->fdt); + + if (pci_device->card_name) + kfree(pci_device->card_name); + kfree(pci_device); } } diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index cd99f304..7285b142 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -81,6 +81,7 @@ struct nfb_pci_device { uint16_t bridge_command; uint16_t bridge_devctl; void * fdt; + const char * card_name; }; void nfb_pci_detach_endpoint(struct nfb_device *nfb, struct pci_dev *pci); From 40a9fb5b49d480aeeb82bbbd3df6232374aa0f83 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 5 Nov 2024 18:17:43 +0100 Subject: [PATCH 220/518] libnfb, tools: [FIX] disable mavx2/sse when compiler support is missing --- libnfb/CMakeLists.txt | 10 +++++++++- libnfb/src/bus/mi.c | 14 ++++++++++++++ tools-debug/CMakeLists.txt | 10 +++++++++- tools-debug/nfb-mi-test/nfb-mi-test.c | 8 +++++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/libnfb/CMakeLists.txt b/libnfb/CMakeLists.txt index f334cf0d..d37bb701 100644 --- a/libnfb/CMakeLists.txt +++ b/libnfb/CMakeLists.txt @@ -13,6 +13,7 @@ project(libnfb LANGUAGES C) include(GNUInstallDirs) include(CheckSymbolExists) include(CheckIncludeFile) +include(CheckCCompilerFlag) include(${CMAKE_CURRENT_LIST_DIR}/../functions.cmake) find_package(PkgConfig) @@ -25,6 +26,11 @@ set(CMAKE_REQUIRED_LIBRARIES "numa") ndk_check_build_dependency(NUMA_LIBRARIES numa NUMA_INCLUDE_DIRS numa.h) ndk_check_build_dependency(FDT_LIBRARIES fdt FDT_INCLUDE_DIRS libfdt.h libfdt) +check_c_compiler_flag("-mavx2" CONFIG_HAVE_MAVX2) +if (${CONFIG_HAVE_MAVX2}) + add_compile_definitions(CONFIG_HAVE_MAVX2) +endif() + find_path(NFB_DRIVER_INCLUDE_DIRS NAMES nfb.h PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../drivers/kernel/include @@ -56,7 +62,9 @@ foreach(NFB IN ITEMS nfb nfb_static) VERSION ${GIT_VERSION} SOVERSION ${GIT_VERSION_MAJOR} ) - set_source_files_properties(src/bus/mi.c PROPERTIES COMPILE_FLAGS -mavx2) + if (${CONFIG_HAVE_MAVX2}) + set_source_files_properties(src/bus/mi.c PROPERTIES COMPILE_FLAGS -mavx2) + endif() endforeach() install(TARGETS nfb nfb_static diff --git a/libnfb/src/bus/mi.c b/libnfb/src/bus/mi.c index 03d1d8e4..ba30552a 100644 --- a/libnfb/src/bus/mi.c +++ b/libnfb/src/bus/mi.c @@ -20,11 +20,19 @@ #include +#ifdef CONFIG_HAVE_MAVX2 #include #include +#endif #include "../nfb.h" + +#ifndef CONFIG_HAVE_MAVX2 +#define _mm_mfence() do {} while(0) +#endif + + struct nfb_bus_mi_priv { size_t mmap_size; @@ -141,6 +149,7 @@ static inline bool nfb_bus_mi_memcopy_prelude(void **dst, const void **src, size return false; } +#ifdef CONFIG_HAVE_MAVX2 static inline bool nfb_bus_mi_memcopy_interlude_avx_sse2(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) { (void) offset; @@ -176,6 +185,7 @@ static inline bool nfb_bus_mi_memcopy_interlude_avx_sse2(void **dst, const void return false; } +#endif static inline bool nfb_bus_mi_memcopy_postlude(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) { @@ -208,8 +218,10 @@ static inline ssize_t nfb_bus_mi_memcopy_avx2_sse2(void *dst, const void *src, s if (nfb_bus_mi_memcopy_prelude(&dst, &src, &nbyte, &offset, wc_used)) return ret; +#ifdef CONFIG_HAVE_MAVX2 if (nfb_bus_mi_memcopy_interlude_avx_sse2(&dst, &src, &nbyte, &offset, wc_used)) return ret; +#endif if (nfb_bus_mi_memcopy_postlude(&dst, &src, &nbyte, &offset, wc_used)) return ret; @@ -313,9 +325,11 @@ int nfb_bus_open_mi(void *dev_priv, int bus_node, int comp_node, void **bus_priv ops->write = _nfb_bus_mi_memcopy_wr_noopt; if ( +#ifdef CONFIG_HAVE_MAVX2 __builtin_cpu_supports("avx") && __builtin_cpu_supports("avx2") && __builtin_cpu_supports("sse2") && +#endif 1 ) { ops->read = nfb_bus_mi_read; ops->write = nfb_bus_mi_write; diff --git a/tools-debug/CMakeLists.txt b/tools-debug/CMakeLists.txt index 8552d361..e6c8ace3 100644 --- a/tools-debug/CMakeLists.txt +++ b/tools-debug/CMakeLists.txt @@ -10,6 +10,7 @@ cmake_minimum_required(VERSION 3.15) cmake_policy(VERSION 3.15) include(GNUInstallDirs) +include(CheckCCompilerFlag) find_package(PkgConfig) @@ -17,6 +18,11 @@ ndk_check_build_dependency(FDT_LIBRARIES fdt FDT_INCLUDE_DIRS libfdt.h libfdt) pkg_check_modules(LIBPCI libpci>=3.6.3) +check_c_compiler_flag("-mavx2" CONFIG_HAVE_MAVX2) +if (${CONFIG_HAVE_MAVX2}) + add_compile_definitions(CONFIG_HAVE_MAVX2) +endif() + link_libraries(nfb ${FDT_LIBRARIES}) add_executable(nfb-busdebugctl busdebugctl/busdebugctl.c) @@ -25,8 +31,10 @@ add_executable(nfb-busreplay busreplay/busreplay.c) add_executable(nfb-xvc nfb-xvc/xvc_pcie.c nfb-xvc/xvcserver.c) add_executable(nfb-mi-test nfb-mi-test/nfb-mi-test.c) -set_source_files_properties(nfb-mi-test/nfb-mi-test.c PROPERTIES COMPILE_FLAGS -mavx2) +if (${CONFIG_HAVE_MAVX2}) + set_source_files_properties(nfb-mi-test/nfb-mi-test.c PROPERTIES COMPILE_FLAGS -mavx2) +endif() set (PIE_TARGETS nfb-busdebugctl nfb-busdump nfb-busreplay nfb-xvc nfb-mi-test) diff --git a/tools-debug/nfb-mi-test/nfb-mi-test.c b/tools-debug/nfb-mi-test/nfb-mi-test.c index cdc0709a..d5eef598 100644 --- a/tools-debug/nfb-mi-test/nfb-mi-test.c +++ b/tools-debug/nfb-mi-test/nfb-mi-test.c @@ -22,9 +22,11 @@ #include #include +#ifdef CONFIG_HAVE_MAVX2 #include #include #include +#endif #define DATA_SIZE 8192 //#define DATA_SIZE 128 @@ -32,7 +34,11 @@ char data1[DATA_SIZE]; char data2[DATA_SIZE]; char datar[DATA_SIZE]; -__m256i datam[DATA_SIZE/32]; +#ifdef CONFIG_HAVE_MAVX2 +__m256i datam[DATA_SIZE / 32]; +#else +uint64_t datam[DATA_SIZE / sizeof(uint64_t)]; +#endif struct timespec start, stop; From 69bc0cb901f6db8a631b115ab36be457494979a3 Mon Sep 17 00:00:00 2001 From: David Vodak Date: Wed, 6 Nov 2024 12:43:46 +0100 Subject: [PATCH 221/518] pynfb: [MAINTENANCE] remove empty __dealloc__ method --- pynfb/nfb/libnfb.pyx | 3 --- 1 file changed, 3 deletions(-) diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index f187d2c3..5720dcc7 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -100,9 +100,6 @@ cdef class Nfb: # TODO: use Nfb.dma only for statistic, not for transfers self.dma = self.ndp - def __dealloc__(self): - pass - def __enter__(self): self._handle.check_handle() return self From 0a0d2eb5acddcd672f48d386de5961f380774494 Mon Sep 17 00:00:00 2001 From: David Vodak Date: Wed, 6 Nov 2024 12:44:39 +0100 Subject: [PATCH 222/518] pynfb: [BUGFIX] rewrite __dealloc__ methods to __del__ According to cython documentation, __dealloc__ methods should only deallocate the memory and should not touch the object in any other way, nor should they call a method since the object may be partialy destroyed[1]. [1] https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html#finalization-methods-dealloc-and-del --- pynfb/nfb/libnfb.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 5720dcc7..9f04f0a9 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -195,7 +195,7 @@ cdef class Comp: PyErr_SetFromErrno(OSError) self._nfb_dev.add_close_cb(self._close_handle) - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): @@ -555,7 +555,7 @@ cdef class NdpQueue: self._running = False self._node = node - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): @@ -621,7 +621,7 @@ cdef class NdpQueueRx(NdpQueue): self._nc_queue = libnetcope.nc_rxqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) self._handle.add_close_cb(self._close_handle) - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): @@ -762,7 +762,7 @@ cdef class NdpQueueTx(NdpQueue): self._nc_queue = libnetcope.nc_txqueue_open(self._handle._dev, nfb._fdt_path_offset(node)) self._handle.add_close_cb(self._close_handle) - def __dealloc__(self): + def __del__(self): self._close_handle() def _close_handle(self): From 9ed6cb149bd0d3321dfa78af0736701ec0ebacfb Mon Sep 17 00:00:00 2001 From: Vlastimil Kosar Date: Mon, 4 Nov 2024 16:10:05 +0100 Subject: [PATCH 223/518] nfb-boot: [HOTFIX] Add 1s sleep before performing write in do_quick_boot() for Silicom N6010 Silicom N6010 sometimes requires aditional sleep time after boot, before fw flashing can be performed. --- tools/boot/boot.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/boot/boot.c b/tools/boot/boot.c index 54ed37c1..0093fb32 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -577,6 +577,21 @@ int do_boot(const char *path, int slot) return ret; } +int card_requires_sleep(const void *fdt) { + int fdt_offset; + const void *prop; + int len; + + fdt_offset = fdt_path_offset(fdt, "/firmware/"); + prop = fdt_getprop(fdt, fdt_offset, "card-name", &len); + if (prop != NULL) { + if (!strcmp(prop, "N6010")) { + return 1; + } + } + return 0; +} + int do_quick_boot(const char *path, int slot, const char *filename, int flags) { int ret; @@ -609,6 +624,9 @@ int do_quick_boot(const char *path, int slot, const char *filename, int flags) warnx("can't check firmware equality, write enforced"); if (diff != DIFF_SAME) { + if (card_requires_sleep(nfb_get_fdt(dev))) { + usleep(1000000); + } ret = do_write_with_dev(dev, slot, filename, fdt, flags); if (ret) { nfb_close(dev); From c5e7e208db0aae98fb390fd57d308a831e62722a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 8 Nov 2024 22:17:48 +0100 Subject: [PATCH 224/518] libnfb: [FEATURE] support extension new style with libnfb-ext: prefix --- libnfb/src/nfb.c | 145 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 105 insertions(+), 40 deletions(-) diff --git a/libnfb/src/nfb.c b/libnfb/src/nfb.c index ad21dc02..4dd500ae 100644 --- a/libnfb/src/nfb.c +++ b/libnfb/src/nfb.c @@ -75,21 +75,111 @@ const char * nfb_default_dev_path() return devname; } -struct nfb_device *nfb_open_ext(const char *devname, int oflag) +int load_lib_extension(const char * lib_name, const char * dev_name, struct nfb_device *dev) { - int ret; - int ext_ops_loaded = 0; - struct nfb_device *dev; - char path[PATH_LEN]; - unsigned index; - - char *ext_name; + int ret = 0; struct libnfb_ext_abi_version *ext_abi_version; struct libnfb_ext_abi_version current_abi_version = libnfb_ext_abi_version_current; libnfb_ext_get_ops_t* get_ops; + dev->ext_lib = dlopen(lib_name, RTLD_NOW); + if (dev->ext_lib == NULL) { + fprintf(stderr, "libnfb fatal: can't open extension library '%s': %s\n", lib_name, dlerror()); + ret = -ENOENT; + goto err_dlopen; + } + + *(void**)(&get_ops) = dlsym(dev->ext_lib, "libnfb_ext_get_ops"); + *(void**)(&ext_abi_version) = dlsym(dev->ext_lib, "libnfb_ext_abi_version"); + if (ext_abi_version == NULL) { + fprintf(stderr, "libnfb fatal: extension doesn't have libnfb_ext_abi_version symbol.\n"); + ret = -EBADF; + goto err_no_abi; + } + + if (ext_abi_version->major != current_abi_version.major) { + fprintf(stderr, "libnfb fatal: extension ABI major version doesn't match.\n"); + ret = -EBADF; + goto err_abi_mismatch; + } + + if (ext_abi_version->minor != current_abi_version.minor) { + fprintf(stderr, "libnfb warning: extension ABI minor version doesn't match.\n"); + } + + if (get_ops == NULL) { + ret = -EBADF; + goto err_no_ops; + } + + ret = get_ops(dev_name, &dev->ops); + if (ret <= 0) { + dlclose(dev->ext_lib); + dev->ext_lib = NULL; + } + return ret; + +err_no_ops: +err_abi_mismatch: +err_no_abi: + dlclose(dev->ext_lib); + dev->ext_lib = NULL; +err_dlopen: + return ret; +} + +int load_extension(const char **devname, struct nfb_device *dev) +{ + int ret; + char *lib_name = NULL; + const char *dev_name = *devname; + const char *ext_name = NULL; + const char *ext_name_end = NULL; + + const char *LIBNFB_EXT_PREFIX = "libnfb-ext:"; + const char *LIBNFB_EXT_PATTERN = "libnfb-ext-"; + + /* Check for prefix */ + if (strstr(dev_name, LIBNFB_EXT_PREFIX) == dev_name) { + ext_name = dev_name + strlen(LIBNFB_EXT_PREFIX); + ext_name_end = strchr(ext_name, ':'); + /* Check for pattern: deprecated */ + } else if (strstr(dev_name, LIBNFB_EXT_PATTERN)) { + ext_name = dev_name; + ext_name_end = strchr(dev_name, ':'); + } + + if (ext_name == NULL) + return 0; + + /* No colon means whole string for library name and empty device name */ + if (ext_name_end == NULL) { + ext_name_end = ext_name + strlen(ext_name); + dev_name = ext_name_end; + } else { + dev_name = ext_name_end + 1; + } + + lib_name = strndup(ext_name, (ext_name_end - ext_name)); + if (!lib_name) + return -ENOMEM; + ret = load_lib_extension(lib_name, dev_name, dev); + free(lib_name); + + *devname = dev_name; + + return ret; +} + +struct nfb_device *nfb_open_ext(const char *devname, int oflag) +{ + int ret; + struct nfb_device *dev; + char path[PATH_LEN]; + unsigned index; + if (devname == NULL) devname = nfb_default_dev_path(); @@ -111,38 +201,10 @@ struct nfb_device *nfb_open_ext(const char *devname, int oflag) memset(dev, 0, sizeof(struct nfb_device)); dev->fd = -1; - ext_name = strchr(devname, ':'); - if (ext_name && strstr(devname, "libnfb-ext-")) { - ext_name = strndup(devname, (ext_name - devname)); - devname = strchr(devname, ':') + 1; - dev->ext_lib = dlopen(ext_name, RTLD_NOW); - if (dev->ext_lib) { - *(void**)(&get_ops) = dlsym(dev->ext_lib, "libnfb_ext_get_ops"); - *(void**)(&ext_abi_version) = dlsym(dev->ext_lib, "libnfb_ext_abi_version"); - if (ext_abi_version == NULL) { - fprintf(stderr, "libnfb fatal: extension doesn't have libnfb_ext_abi_version symbol.\n"); - } else { - if (ext_abi_version->major != current_abi_version.major) { - fprintf(stderr, "libnfb fatal: extension ABI major version doesn't match.\n"); - } else { - if (ext_abi_version->minor != current_abi_version.minor) { - fprintf(stderr, "libnfb warning: extension ABI minor version doesn't match.\n"); - } - - if (get_ops) { - ret = get_ops(devname, &dev->ops); - if (ret > 0) - ext_ops_loaded = 1; - } - } - } - } else { - fprintf(stderr, "libnfb fatal: can't open extension library '%s': %s\n", ext_name, dlerror()); - } - free(ext_name); - } - - if (!ext_ops_loaded) { + ret = load_extension(&devname, dev); + if (ret < 0) { + goto err_ext_load; + } else if (ret == 0) { dev->ops = nfb_base_ops; } @@ -177,6 +239,9 @@ struct nfb_device *nfb_open_ext(const char *devname, int oflag) free(dev->fdt); err_ops: err_open: +err_ext_load: + if (dev->ext_lib) + dlclose(dev->ext_lib); free(dev); err_malloc_dev: return NULL; From 53203c7e27acf68debbe3e8c29d5e41511c99d2f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 7 Nov 2024 08:06:33 +0100 Subject: [PATCH 225/518] libnfb-ext-python: [MAINTENANCE] fix package name and binary path --- ext/libnfb_ext_python/nfb/ext/python/__init__.py | 6 ++---- .../ext/python/ext_entry.c} | 4 ++-- .../ext/python/shim.pxd} | 2 -- .../ext/python/shim.pyx} | 14 +++++++++----- ext/libnfb_ext_python/setup.py | 13 ++++++------- 5 files changed, 19 insertions(+), 20 deletions(-) rename ext/libnfb_ext_python/{libnfb_ext_python/libnfb_ext_python_shim.c => nfb/ext/python/ext_entry.c} (82%) rename ext/libnfb_ext_python/{libnfb_ext_python/libnfb_ext_python.pxd => nfb/ext/python/shim.pxd} (99%) rename ext/libnfb_ext_python/{libnfb_ext_python/libnfb_ext_python.pyx => nfb/ext/python/shim.pyx} (92%) diff --git a/ext/libnfb_ext_python/nfb/ext/python/__init__.py b/ext/libnfb_ext_python/nfb/ext/python/__init__.py index 86d16a81..04b28862 100644 --- a/ext/libnfb_ext_python/nfb/ext/python/__init__.py +++ b/ext/libnfb_ext_python/nfb/ext/python/__init__.py @@ -4,6 +4,7 @@ import importlib import fdt +from . import shim class AbstractNdpQueue(ABC): def start(self): @@ -52,7 +53,4 @@ def write(self, bus_node, comp_node, offset, data): return 0 def path(self): - __libnfb_ext_python = importlib.import_module( - "libnfb-ext-python.libnfb_ext_python" - ) - return __libnfb_ext_python.__file__ + ":pynfb:" + str(id(self)) + return shim.get_libnfb_ext_path(self) diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python_shim.c b/ext/libnfb_ext_python/nfb/ext/python/ext_entry.c similarity index 82% rename from ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python_shim.c rename to ext/libnfb_ext_python/nfb/ext/python/ext_entry.c index 3b68c1e7..2695a91d 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python_shim.c +++ b/ext/libnfb_ext_python/nfb/ext/python/ext_entry.c @@ -6,13 +6,13 @@ #include -#include "libnfb_ext_python_api.h" +#include "shim_api.h" struct libnfb_ext_abi_version libnfb_ext_abi_version = libnfb_ext_abi_version_current; int libnfb_ext_get_ops(const char *devname, struct libnfb_ext_ops *ops) { - if (import_libnfb_ext_python()) + if (import_shim()) return 0; return pynfb_ext_get_ops(devname, ops); diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd b/ext/libnfb_ext_python/nfb/ext/python/shim.pxd similarity index 99% rename from ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd rename to ext/libnfb_ext_python/nfb/ext/python/shim.pxd index ac6a29d0..416224f5 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pxd +++ b/ext/libnfb_ext_python/nfb/ext/python/shim.pxd @@ -95,8 +95,6 @@ cdef extern from "": cdef ndp_queue_ops* ndp_queue_get_ops(ndp_queue *q) -cdef api const char *nfb_pynfb_prefix - cdef public api: int pynfb_ext_get_ops(const char *devname, libnfb_ext_ops* ops) noexcept diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx b/ext/libnfb_ext_python/nfb/ext/python/shim.pyx similarity index 92% rename from ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx rename to ext/libnfb_ext_python/nfb/ext/python/shim.pyx index 9762d98d..db9791cf 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx +++ b/ext/libnfb_ext_python/nfb/ext/python/shim.pyx @@ -1,4 +1,11 @@ -cdef api const char *nfb_pynfb_prefix = "pynfb:" +cdef api const char *libnfb_ext_compatible_pattern = "libnfb-ext-compat_pattern:" + +def get_libnfb_ext_path(nfb): + # early version of libnfb relies on a pattern "libnfb-ext-" somewhere in device string/path + base = __file__ + ":" + libnfb_ext_compatible_pattern.decode() + # new extension identification string must have a "libnfb-ext:" prefix (backward incompatible) + #base = "libnfb-ext:" + __file__ + ":" + return base + str(id(nfb)) cdef class __NfbWrapper: cdef char * fdt @@ -13,7 +20,7 @@ cdef int nfb_ext_python_open(const char *devname, int oflag, void **priv, void * cdef PyObject* _nfb cdef __NfbWrapper wrap - addr = strtoull(devname + strlen(nfb_pynfb_prefix), NULL, 10) + addr = strtoull(devname + strlen(libnfb_ext_compatible_pattern), NULL, 10) _nfb = addr nfb = _nfb @@ -254,9 +261,6 @@ cdef void nfb_pynfb_comp_unlock(const nfb_comp *comp, uint32_t features) noexcep pass cdef int pynfb_ext_get_ops(const char *devname, libnfb_ext_ops* ops) noexcept: - if strncmp(devname, nfb_pynfb_prefix, strlen(nfb_pynfb_prefix)) != 0: - return 0 - ops.open = nfb_ext_python_open ops.close = nfb_ext_python_close ops.bus_open_mi = nfb_pynfb_bus_open diff --git a/ext/libnfb_ext_python/setup.py b/ext/libnfb_ext_python/setup.py index affb85df..474c2222 100644 --- a/ext/libnfb_ext_python/setup.py +++ b/ext/libnfb_ext_python/setup.py @@ -3,26 +3,25 @@ from setuptools import Extension, setup, find_namespace_packages setup( - name="libnfb_ext_python", + name="libnfb-ext-python", version="0.1.0", author="Martin Spinler", author_email="spinler@cesnet.cz", - ext_package="libnfb-ext-python", + ext_package="nfb.ext.python", ext_modules=cythonize( [ Extension( - "libnfb_ext_python", + "shim", [ - "libnfb_ext_python/libnfb_ext_python.pyx", - "libnfb_ext_python/libnfb_ext_python_shim.c", + "nfb/ext/python/shim.pyx", + "nfb/ext/python/ext_entry.c", ], libraries=["nfb", "fdt"], ), ], - include_path=["libnfb_ext_python"], + include_path=["nfb/ext/python"], compiler_directives={"embedsignature": True, "binding": False}, ), - py_modules=["libnfb_ext_python"], packages=find_namespace_packages(include=["nfb.*"]), install_requires=['fdt'], ) From 7ccb23922a087f4eb327dea816adba15a8017af5 Mon Sep 17 00:00:00 2001 From: "David Benes (FEKT)" Date: Tue, 12 Nov 2024 12:35:02 +0000 Subject: [PATCH 226/518] A2700: [FEATURE] Add Terasic card into supported devices --- drivers/kernel/drivers/nfb/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 37d5ae2e..fe868f65 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -342,7 +342,7 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) nfb_fdt_create_boot_type(fdt, node, "INTEL-AVST", 0); } else if (!strcmp(name, nfb_card_name_generic)) { - if (!strcmp(card_name, "IA-420F")) { + if (!strcmp(card_name, "IA-420F") || !strcmp(card_name, "TERASIC-A2700")) { prop32 = cpu_to_fdt32(1); fdt_appendprop(fdt, node, "num_flash", &prop32, sizeof(prop32)); prop32 = cpu_to_fdt32(256 * 1024 * 1024); From a89ce0eab2de29062318188d8047799f1a7bcbfc Mon Sep 17 00:00:00 2001 From: Radek Isa Date: Tue, 12 Nov 2024 14:00:29 +0000 Subject: [PATCH 227/518] LIB-EXT-GRPC: [BUGFIX] use FOUND instead of DIR variable in cmake for gRPC --- ext/libnfb_ext_grpc/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/libnfb_ext_grpc/CMakeLists.txt b/ext/libnfb_ext_grpc/CMakeLists.txt index 7f34d2f0..706a2134 100644 --- a/ext/libnfb_ext_grpc/CMakeLists.txt +++ b/ext/libnfb_ext_grpc/CMakeLists.txt @@ -13,14 +13,14 @@ project(libnfb-ext-grpc C CXX) include(GNUInstallDirs) find_package(Protobuf CONFIG) +find_package(gRPC QUIET) set(PROTO_FILES nfb_grpc.proto) add_library(nfb-ext-grpc SHARED nfb_grpc_client.cc) add_executable(nfb-grpc-server nfb_grpc_server.cc) -if (EXISTS ${Protobuf_DIR}) - find_package(gRPC CONFIG) +if (${gRPC_FOUND}) include_directories(${Protobuf_INCLUDE_DIRS}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) From c83172682b436ba49f9715205b8208cbbda2c00e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 13 Nov 2024 11:38:10 +0100 Subject: [PATCH 228/518] [CI]: fix Jenkins ol8 build --- jenkins/oraclelinux8.Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jenkins/oraclelinux8.Dockerfile b/jenkins/oraclelinux8.Dockerfile index 0d2dcbd4..9f99f125 100644 --- a/jenkins/oraclelinux8.Dockerfile +++ b/jenkins/oraclelinux8.Dockerfile @@ -2,8 +2,7 @@ ARG OSRELEASEVER=8 ARG OSNAME=centos FROM $OSNAME:$OSRELEASEVER as default -RUN /usr/sbin/groupadd -f -g 991 jenkins -RUN /usr/sbin/useradd jenkins -u 1001 -g 991 +RUN /usr/sbin/useradd jenkins RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm From 4cd809de044d98d37b6df934d04b602dc0ccfb1d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 13 Nov 2024 17:10:58 +0100 Subject: [PATCH 229/518] bump version to 6.24.0 --- Changelog | 11 +++++++++++ VERSION | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 6b7196cc..057e34f0 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,14 @@ +* Wed Nov 13 2024 Martin Spinler - 6.24.0-1 +- [FEATURE] drivers: add support for Terasic A2700 card +- [FEATURE] drivers: check subdevices by card_name (and DSN) in all PCI endpoint FDTs +- [FEATURE] nfb-bus: introduce byte mode for read & writes +- [FEATURE] libnfb, drivers: report errors when accessing outside component space +- [FEATURE] libnfb: support library extension with device prefix "libnfb-ext:" +- [HOTFIX] nfb-boot: quick boot on N6010 +- [FIX] libnfb, tools: disable mavx2/sse when compiler support is missing +- [FIX] pynfb: rewrite __dealloc__ methods to __del__ +- [MAINTENANCE] libnfb-ext-python: fix package name and binary path + * Fri Oct 4 2024 Martin Spinler - 6.23.6-1 - [BUGFIX] libnfb - MDIO: fix deadlock due to recursive lock diff --git a/VERSION b/VERSION index 95d8fb1b..2496b04b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.23.6 +6.24.0 From e20786f92d4542d8adc4436776eefea55613f480 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 23 Jul 2024 12:56:42 +0200 Subject: [PATCH 230/518] drivers: [FIX] use strlcpy instead of strscpy --- drivers/kernel/drivers/nfb/net/ethtool.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/kernel/drivers/nfb/net/ethtool.c b/drivers/kernel/drivers/nfb/net/ethtool.c index 6594addf..11dfb7f0 100644 --- a/drivers/kernel/drivers/nfb/net/ethtool.c +++ b/drivers/kernel/drivers/nfb/net/ethtool.c @@ -105,11 +105,11 @@ static void nfb_net_get_drvinfo(struct net_device *netdev, struct ethtool_drvinf proj_str = fdt_getprop(nfbdev->fdt, fdt_offset, "project-name", &proj_len); rev_str = fdt_getprop(nfbdev->fdt, fdt_offset, "build-revision", &rev_len); - strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); - strlcpy(drvinfo->version, PACKAGE_VERSION, sizeof(drvinfo->version)); + strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); + strscpy(drvinfo->version, PACKAGE_VERSION, sizeof(drvinfo->version)); if (proj_len > 0) { - strlcpy(drvinfo->fw_version, proj_str, sizeof(drvinfo->fw_version)); + strscpy(drvinfo->fw_version, proj_str, sizeof(drvinfo->fw_version)); strlcat(drvinfo->fw_version, " ", sizeof(drvinfo->fw_version)); } @@ -117,7 +117,7 @@ static void nfb_net_get_drvinfo(struct net_device *netdev, struct ethtool_drvinf strlcat(drvinfo->fw_version, rev_str, sizeof(drvinfo->fw_version)); } - strlcpy(drvinfo->bus_info, pci_name(nfbdev->pci), sizeof(drvinfo->bus_info)); + strscpy(drvinfo->bus_info, pci_name(nfbdev->pci), sizeof(drvinfo->bus_info)); drvinfo->n_stats = NFB_NET_STATS_LEN; } From 514d06b5c841fd0bd07a4fda39df560ee1d44449 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 13 Nov 2024 14:27:01 +0100 Subject: [PATCH 231/518] drivers: [FIX] include vmalloc for vmap/vunmap --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 0455baa0..470c3a49 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "../fdt/libfdt.h" #include "../nfb.h" From 4e8c92ba58dc689f99e3899ede55d5d60317326f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 23 Jul 2024 12:49:18 +0200 Subject: [PATCH 232/518] drivers: [MAINTENANCE] reflect SPI controller name change --- drivers/configure.ac | 7 +++++++ drivers/kernel/drivers/nfb/boot/boot.c | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index e6a61b68..8e2cd099 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -127,6 +127,13 @@ KERNEL_TRY_COMPILE([[ int trd(off_t a) {return 0;} void test(void) {int ret; read_poll_timeout_atomic(trd, ret, (!ret), 1, 2, false, 0);} ]],[AC_DEFINE([CONFIG_HAVE_READ_POLL_TIMEOUT_ATOMIC], [1], [Define if kernel has read_poll_timeout_atomic]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +AC_MSG_CHECKING([whether kernel has struct spi_controller]) +KERNEL_TRY_COMPILE([[ +#include +struct spi_controller *sc; +void test(void); +void test(void) {spi_get_chipselect(NULL, 0);}]],[AC_DEFINE([CONFIG_HAVE_SPI_CONTROLLER], [1], [Define if kernel has struct spi_controller]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) + AC_SUBST(KDIR) AC_SUBST(KSRC) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 4b4bf7d4..7f480563 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -246,7 +246,11 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) const void *prop; const uint32_t *prop32; struct nfb_boot *boot; +#ifdef CONFIG_HAVE_SPI_CONTROLLER + struct spi_controller *spi_master; +#else struct spi_master *spi_master; +#endif fdt_offset = fdt_path_offset(nfb->fdt, "/"); fdt_offset = fdt_add_subnode(nfb->fdt, fdt_offset, "board"); @@ -376,12 +380,16 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) void nfb_boot_detach(struct nfb_device* nfb, void *priv) { struct nfb_boot *boot = priv; +#ifdef CONFIG_HAVE_SPI_CONTROLLER + struct spi_controller *master; +#else struct spi_master *master; +#endif nfb_boot_mtd_destroy(boot); if (boot->spi) { - master = boot->spi->master; + master = boot->spi->controller; spi_dev_put(boot->spi); nfb_xilinx_spi_remove(master); } From 5f1b2fceb8515f1d6056959399410396e645f5a9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 13 Nov 2024 15:08:39 +0100 Subject: [PATCH 233/518] drivers: [MAINTENANCE] support simplified eventfd_signal function --- drivers/configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/configure.ac b/drivers/configure.ac index 8e2cd099..598e6ff9 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -134,6 +134,12 @@ struct spi_controller *sc; void test(void); void test(void) {spi_get_chipselect(NULL, 0);}]],[AC_DEFINE([CONFIG_HAVE_SPI_CONTROLLER], [1], [Define if kernel has struct spi_controller]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +AC_MSG_CHECKING([whether kernel has simplified eventfd_signal]) +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {eventfd_signal(NULL);}]],[AC_DEFINE([CONFIG_HAVE_SIMPLIFIED_EVENTFD_SIGNAL], [1], [Define if kernel has simplified eventfd_signal]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) + AC_SUBST(KDIR) AC_SUBST(KSRC) From 47e9509a60c02c3453a0b733bd83d9d87bfa96e0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 13 Nov 2024 14:12:57 +0100 Subject: [PATCH 234/518] drivers: [MAINTENANCE] make functions static whenever is possible --- drivers/configure.ac | 12 ++++++++++-- drivers/kernel/drivers/nfb/boot/boot.c | 2 +- drivers/kernel/drivers/nfb/boot/gecko.c | 1 + drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 2 +- drivers/kernel/drivers/nfb/char.c | 16 ++++++++-------- drivers/kernel/drivers/nfb/core.c | 10 +++++----- drivers/kernel/drivers/nfb/mi/mi.c | 18 +++++++++--------- drivers/kernel/drivers/nfb/misc.c | 2 +- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 2 +- drivers/kernel/drivers/nfb/ndp/driver.c | 7 ------- drivers/kernel/drivers/nfb/ndp/kndp.h | 5 ++++- drivers/kernel/drivers/nfb/ndp/ndp.h | 11 +++++++++++ drivers/kernel/drivers/nfb/ndp/ring.c | 6 +++--- drivers/kernel/drivers/nfb/ndp/subscriber.c | 4 ++-- drivers/kernel/drivers/nfb/ndp_netdev/core.c | 6 +++--- drivers/kernel/drivers/nfb/net/device.c | 12 ++++++------ drivers/kernel/drivers/nfb/net/driver.c | 14 +++++++------- drivers/kernel/drivers/nfb/pci.c | 14 +++++++------- libnfb/include/netcope/ndp.h | 1 + 19 files changed, 81 insertions(+), 64 deletions(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index 598e6ff9..eee9cd64 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -79,12 +79,14 @@ struct timespec ts; AC_MSG_CHECKING([whether kernel has netif_rx_ni]) KERNEL_TRY_COMPILE([[ #include +void test(void); void test(void) {netif_rx_ni(NULL);} ]],[AC_DEFINE([CONFIG_HAVE_NETIF_RX_NI], [1], [Define if kernel have netif_rx_ni]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) AC_MSG_CHECKING([whether kernel has eth_hw_addr_set]) KERNEL_TRY_COMPILE([[ #include +void test(void); void test(void) {eth_hw_addr_set(NULL, NULL);} ]],[AC_DEFINE([CONFIG_HAVE_ETH_HW_ADDR_SET], [1], [Define if kernel have eth_hw_addr_set]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) @@ -92,13 +94,15 @@ AC_MSG_CHECKING([whether kernel has regmap_reg_range and read_poll_timeout]) KERNEL_TRY_COMPILE([[ #include #include +void test(void); static const struct regmap_range regmap_range_test[] = {regmap_reg_range(0,0)}; -int trd(off_t a) {return 0;} void test(void) {int ret; read_poll_timeout(trd, ret, (!ret), 1, 2, false, 0);} +static int trd(off_t a) {return 0;} void test(void) {int ret; read_poll_timeout(trd, ret, (!ret), 1, 2, false, 0);} ]],[AC_DEFINE([CONFIG_NFB_ENABLE_PMCI], [1], [Define if kernel have regmap_reg_range and read_poll_timeout]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) AC_MSG_CHECKING([whether kernel has devm_kstrdup_const]) KERNEL_TRY_COMPILE([[ #include +void test(void); struct device dev; void test(void) {devm_kstrdup_const(&dev, "test", GFP_KERNEL);} ]],[AC_DEFINE([CONFIG_NFB_ENABLE_HWMON], [1], [Define if kernel has devm_kstrdup_const()]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) @@ -106,25 +110,29 @@ void test(void) {devm_kstrdup_const(&dev, "test", GFP_KERNEL);} AC_MSG_CHECKING([whether kernel has vm_flags_set]) KERNEL_TRY_COMPILE([[ #include +void test(void); void test(void) {vm_flags_set(NULL, 0);} ]],[AC_DEFINE([CONFIG_HAVE_VM_FLAGS_SET], [1], [Define if kernel has vm_flags_set()]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) AC_MSG_CHECKING([whether struct ptp_clock_info has adjfreq]) KERNEL_TRY_COMPILE([[ #include +void test(void); void test(void) {struct ptp_clock_info ci; ci.ajdfreq = NULL;} ]],[AC_DEFINE([CONFIG_HAVE_PTP_CLOCK_INFO_ADJFREQ], [1], [Define if struct ptp_clock_info has adjfreq]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) AC_MSG_CHECKING([whether class_create has only one parameter]) KERNEL_TRY_COMPILE([[ #include +void test(void); void test(void) {struct class *c = class_create(""); if (c) {} } ]],[AC_DEFINE([CONFIG_CLASS_CREATE_HAVE_ONE_PARAMETER], [1], [Define if class_create has only one parameter]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) AC_MSG_CHECKING([whether kernel has read_poll_timeout_atomic]) KERNEL_TRY_COMPILE([[ #include -int trd(off_t a) {return 0;} void test(void) {int ret; read_poll_timeout_atomic(trd, ret, (!ret), 1, 2, false, 0);} +void test(void); +static int trd(off_t a) {return 0;} void test(void) {int ret; read_poll_timeout_atomic(trd, ret, (!ret), 1, 2, false, 0);} ]],[AC_DEFINE([CONFIG_HAVE_READ_POLL_TIMEOUT_ATOMIC], [1], [Define if kernel has read_poll_timeout_atomic]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) AC_MSG_CHECKING([whether kernel has struct spi_controller]) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 7f480563..3682ea98 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -133,7 +133,7 @@ static void nfb_boot_read_card_subtype(struct nfb_device *nfb, struct nfb_boot * } } -long nfb_boot_ioctl_reload(struct nfb_boot *boot, int * __user _image) +static long nfb_boot_ioctl_reload(struct nfb_boot *boot, int * __user _image) { int image; int node; diff --git a/drivers/kernel/drivers/nfb/boot/gecko.c b/drivers/kernel/drivers/nfb/boot/gecko.c index f25d80fb..f29e8862 100644 --- a/drivers/kernel/drivers/nfb/boot/gecko.c +++ b/drivers/kernel/drivers/nfb/boot/gecko.c @@ -14,6 +14,7 @@ #include #include +#include "gecko.h" #include "../nfb.h" #include "../pci.h" diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index 552246f4..034119ae 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -157,7 +157,7 @@ static const struct regmap_bus indirect_bus = { .reg_read = indirect_bus_reg_read, }; -struct regmap *nfb_devm_regmap_init_indirect_register(struct device *dev, +static struct regmap *nfb_devm_regmap_init_indirect_register(struct device *dev, off_t offset, struct nfb_comp *comp, struct regmap_config *cfg) { struct indirect_ctx *ctx; diff --git a/drivers/kernel/drivers/nfb/char.c b/drivers/kernel/drivers/nfb/char.c index 43c6ac37..5adf5ada 100644 --- a/drivers/kernel/drivers/nfb/char.c +++ b/drivers/kernel/drivers/nfb/char.c @@ -17,8 +17,8 @@ #include #include "nfb.h" +#include "ndp/ndp.h" -int ndp_char_poll(void *priv, void *app_priv, struct file *filp, struct poll_table_struct *wait); /* Global variables */ static int nfb_major; @@ -165,7 +165,7 @@ int nfb_char_unregister_mmap(struct nfb_device *nfb, size_t offset) * @inode: inode of chardev * @file: file pointer in user application */ -int nfb_char_open(struct inode *inode, struct file *file) +static int nfb_char_open(struct inode *inode, struct file *file) { int i; int size; @@ -254,7 +254,7 @@ int nfb_char_open(struct inode *inode, struct file *file) * @inode: inode of chardev * @file: file pointer in user application */ -int nfb_char_release(struct inode *inode, struct file *file) +static int nfb_char_release(struct inode *inode, struct file *file) { int i; struct nfb_app *app = file->private_data; @@ -277,7 +277,7 @@ int nfb_char_release(struct inode *inode, struct file *file) return 0; } -loff_t nfb_char_llseek(struct file *file, loff_t off, int whence) +static loff_t nfb_char_llseek(struct file *file, loff_t off, int whence) { struct nfb_app *app = file->private_data; loff_t newpos; @@ -303,7 +303,7 @@ loff_t nfb_char_llseek(struct file *file, loff_t off, int whence) return newpos; } -ssize_t nfb_char_read(struct file *file, char __user *buffer, size_t length, loff_t *offset) +static ssize_t nfb_char_read(struct file *file, char __user *buffer, size_t length, loff_t *offset) { struct nfb_app *app = file->private_data; int ret = 0; @@ -328,7 +328,7 @@ ssize_t nfb_char_read(struct file *file, char __user *buffer, size_t length, lof * @file: file pointer in user application * @vma: pointer to describing vm_area_struct */ -int nfb_char_mmap(struct file *file, struct vm_area_struct *vma) +static int nfb_char_mmap(struct file *file, struct vm_area_struct *vma) { int ret = -EINVAL; struct nfb_app *app = file->private_data; @@ -361,7 +361,7 @@ int nfb_char_mmap(struct file *file, struct vm_area_struct *vma) * @cmd: type of IOC command * @arg: argument for IOC command */ -long nfb_char_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +static long nfb_char_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int i; int ret = -ENXIO; @@ -391,7 +391,7 @@ long nfb_char_ioctl(struct file *file, unsigned int cmd, unsigned long arg) * @file: file pointer in user application * @wait: struct poll_table_struct */ -unsigned int nfb_char_poll(struct file *file, struct poll_table_struct *wait) +static unsigned int nfb_char_poll(struct file *file, struct poll_table_struct *wait) { struct nfb_app *app = file->private_data; struct nfb_device *nfb = app->nfb; diff --git a/drivers/kernel/drivers/nfb/core.c b/drivers/kernel/drivers/nfb/core.c index 3bcb97ec..8a063552 100644 --- a/drivers/kernel/drivers/nfb/core.c +++ b/drivers/kernel/drivers/nfb/core.c @@ -51,7 +51,7 @@ void *nfb_get_priv_for_attach_fn(struct nfb_device *nfb, nfb_driver_ops_attach_t * nfb_attach_drivers - attach embedded drivers to NFB device * @nfb: NFB device structure */ -void nfb_attach_driver(struct nfb_device* nfb, int i) +static void nfb_attach_driver(struct nfb_device* nfb, int i) { int ret; @@ -61,7 +61,7 @@ void nfb_attach_driver(struct nfb_device* nfb, int i) } } -void nfb_detach_driver(struct nfb_device *nfb, int i) +static void nfb_detach_driver(struct nfb_device *nfb, int i) { if (nfb->list_drivers[i].status == NFB_DRIVER_STATUS_OK) { nfb_registered_drivers[i].detach(nfb, nfb->list_drivers[i].priv); @@ -69,7 +69,7 @@ void nfb_detach_driver(struct nfb_device *nfb, int i) nfb->list_drivers[i].status = NFB_DRIVER_STATUS_NONE; } -void nfb_attach_drivers_early(struct nfb_device* nfb) +static void nfb_attach_drivers_early(struct nfb_device* nfb) { int i; mutex_lock(&nfb_driver_register_mutex); @@ -79,7 +79,7 @@ void nfb_attach_drivers_early(struct nfb_device* nfb) mutex_unlock(&nfb_driver_register_mutex); } -void nfb_attach_drivers(struct nfb_device* nfb) +static void nfb_attach_drivers(struct nfb_device* nfb) { int i; mutex_lock(&nfb_driver_register_mutex); @@ -93,7 +93,7 @@ void nfb_attach_drivers(struct nfb_device* nfb) * nfb_detach_drivers - detach embedded drivers from NFB device * @nfb: NFB device structure */ -void nfb_detach_drivers(struct nfb_device* nfb) +static void nfb_detach_drivers(struct nfb_device* nfb) { int i; diff --git a/drivers/kernel/drivers/nfb/mi/mi.c b/drivers/kernel/drivers/nfb/mi/mi.c index f3654c98..eb73d4e2 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.c +++ b/drivers/kernel/drivers/nfb/mi/mi.c @@ -20,7 +20,7 @@ static bool mi_debug = 0; -ssize_t nfb_bus_mi_read(struct nfb_bus *bus, void *buf, size_t nbyte, off_t offset) +static ssize_t nfb_bus_mi_read(struct nfb_bus *bus, void *buf, size_t nbyte, off_t offset) { struct nfb_mi_node *mi_node = bus->priv; if (mi_node->mem_virt == NULL) @@ -40,7 +40,7 @@ ssize_t nfb_bus_mi_read(struct nfb_bus *bus, void *buf, size_t nbyte, off_t offs return nbyte; } -ssize_t nfb_bus_mi_write(struct nfb_bus *bus, const void *buf, size_t nbyte, off_t offset) +static ssize_t nfb_bus_mi_write(struct nfb_bus *bus, const void *buf, size_t nbyte, off_t offset) { struct nfb_mi_node *mi_node = bus->priv; if (mi_node->mem_virt == NULL) @@ -60,7 +60,7 @@ ssize_t nfb_bus_mi_write(struct nfb_bus *bus, const void *buf, size_t nbyte, off return nbyte; } -int nfb_mi_mmap(struct vm_area_struct *vma, unsigned long offset, unsigned long size, void *priv) +static int nfb_mi_mmap(struct vm_area_struct *vma, unsigned long offset, unsigned long size, void *priv) { struct nfb_mi* mi = (struct nfb_mi*) priv; struct nfb_mi_node *mi_node; @@ -85,7 +85,7 @@ int nfb_mi_mmap(struct vm_area_struct *vma, unsigned long offset, unsigned long return -ENOENT; } -int nfb_mi_map(struct nfb_device *nfb, struct nfb_mi_node *mi_node, struct nfb_pci_device *pci_device) +static int nfb_mi_map(struct nfb_device *nfb, struct nfb_mi_node *mi_node, struct nfb_pci_device *pci_device) { int ret; char nodename[64]; @@ -140,7 +140,7 @@ int nfb_mi_map(struct nfb_device *nfb, struct nfb_mi_node *mi_node, struct nfb_p return -EBADF; } -void nfb_mi_unmap(struct nfb_device *nfb, struct nfb_mi_node *mi) +static void nfb_mi_unmap(struct nfb_device *nfb, struct nfb_mi_node *mi) { char nodename[64]; int node_offset; @@ -160,7 +160,7 @@ void nfb_mi_unmap(struct nfb_device *nfb, struct nfb_mi_node *mi) } } -int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) +static int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) { int ret; int mapped = 0; @@ -237,7 +237,7 @@ int nfb_mi_attach_bus(struct nfb_device *nfb, void *priv, int node_offset) return ret; } -int nfb_mi_attach_node(struct nfb_device *nfb, void *priv, int base_offset) +static int nfb_mi_attach_node(struct nfb_device *nfb, void *priv, int base_offset) { int base_depth; int supernode_offset; @@ -319,7 +319,7 @@ int nfb_mi_attach(struct nfb_device *nfb, void **priv) return 0; } -void nfb_mi_detach_bus(struct nfb_device *nfb, struct nfb_mi* nfb_mi, int node_offset) +static void nfb_mi_detach_bus(struct nfb_device *nfb, struct nfb_mi* nfb_mi, int node_offset) { int ret; int pci_index, bar; @@ -351,7 +351,7 @@ void nfb_mi_detach_bus(struct nfb_device *nfb, struct nfb_mi* nfb_mi, int node_o } } -void nfb_mi_detach_node(struct nfb_device *nfb, void *priv, int base_offset) +static void nfb_mi_detach_node(struct nfb_device *nfb, void *priv, int base_offset) { int base_depth; int supernode_offset; diff --git a/drivers/kernel/drivers/nfb/misc.c b/drivers/kernel/drivers/nfb/misc.c index 9c6d56ec..5bd9eed3 100644 --- a/drivers/kernel/drivers/nfb/misc.c +++ b/drivers/kernel/drivers/nfb/misc.c @@ -18,7 +18,7 @@ #define NFB_FDT_BURSTSIZE (16384) -uint64_t reverse(const uint64_t n, const uint64_t k) +static uint64_t reverse(const uint64_t n, const uint64_t k) { uint64_t i, r = 0; for (i = 0; i < k; ++i) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 470c3a49..1e5ababd 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -741,7 +741,7 @@ static int ndp_ctrl_off_mmap(struct vm_area_struct *vma, unsigned long offset, u return ret; } -void *ndp_ctrl_vmap_shadow(int size, void *virt) +static void *ndp_ctrl_vmap_shadow(int size, void *virt) { int i; int page_count; diff --git a/drivers/kernel/drivers/nfb/ndp/driver.c b/drivers/kernel/drivers/nfb/ndp/driver.c index b9aebbed..7df2b0d2 100644 --- a/drivers/kernel/drivers/nfb/ndp/driver.c +++ b/drivers/kernel/drivers/nfb/ndp/driver.c @@ -32,13 +32,6 @@ struct ndp_ctrl_create { struct ndp_channel* (*create)(struct ndp *ndp, int index, int node_offset); }; -struct ndp_channel *ndp_ctrl_v1_create_rx(struct ndp *ndp, int index, int node_offset); -struct ndp_channel *ndp_ctrl_v1_create_tx(struct ndp *ndp, int index, int node_offset); -struct ndp_channel *ndp_ctrl_v2_create_rx(struct ndp *ndp, int index, int node_offset); -struct ndp_channel *ndp_ctrl_v2_create_tx(struct ndp *ndp, int index, int node_offset); -struct ndp_channel *ndp_ctrl_v3_create_rx(struct ndp *ndp, int index, int node_offset); -struct ndp_channel *ndp_ctrl_v3_create_tx(struct ndp *ndp, int index, int node_offset); - struct ndp_ctrl_create ndp_ctrls[] = { {.compatible = "netcope,dma_ctrl_sze_rx", .create = ndp_ctrl_v1_create_rx}, {.compatible = "netcope,dma_ctrl_sze_tx", .create = ndp_ctrl_v1_create_tx}, diff --git a/drivers/kernel/drivers/nfb/ndp/kndp.h b/drivers/kernel/drivers/nfb/ndp/kndp.h index a2821d50..142ddaea 100644 --- a/drivers/kernel/drivers/nfb/ndp/kndp.h +++ b/drivers/kernel/drivers/nfb/ndp/kndp.h @@ -13,8 +13,11 @@ #include struct ndp_queue; -int ndp_ctrl_v2_get_vmaps(struct ndp_channel *channel, void **hdr, void **off); struct ndp_queue *ndp_open_queue(struct nfb_device *dev, unsigned index, int dir, int flags); void ndp_close_queue(struct ndp_queue *q); + +typedef int ndp_open_flags_t; +int ndp_base_queue_open(struct nfb_device *dev, void *dev_priv, unsigned index, int dir, ndp_open_flags_t flags, struct ndp_queue ** pq); +void ndp_base_queue_close(void *priv); diff --git a/drivers/kernel/drivers/nfb/ndp/ndp.h b/drivers/kernel/drivers/nfb/ndp/ndp.h index b3c9b9dc..8f8d7d59 100644 --- a/drivers/kernel/drivers/nfb/ndp/ndp.h +++ b/drivers/kernel/drivers/nfb/ndp/ndp.h @@ -307,4 +307,15 @@ static inline int ndp_kill_signal_pending(struct task_struct *p) return ret; } +struct ndp_channel *ndp_ctrl_v1_create_rx(struct ndp *ndp, int index, int node_offset); +struct ndp_channel *ndp_ctrl_v1_create_tx(struct ndp *ndp, int index, int node_offset); +struct ndp_channel *ndp_ctrl_v2_create_rx(struct ndp *ndp, int index, int node_offset); +struct ndp_channel *ndp_ctrl_v2_create_tx(struct ndp *ndp, int index, int node_offset); +struct ndp_channel *ndp_ctrl_v3_create_rx(struct ndp *ndp, int index, int node_offset); +struct ndp_channel *ndp_ctrl_v3_create_tx(struct ndp *ndp, int index, int node_offset); + +int ndp_ctrl_v2_get_vmaps(struct ndp_channel *channel, void **hdr, void **off); + +int ndp_char_poll(void *priv, void *app_priv, struct file *filp, struct poll_table_struct *wait); + #endif diff --git a/drivers/kernel/drivers/nfb/ndp/ring.c b/drivers/kernel/drivers/nfb/ndp/ring.c index 861502d9..899e5aa8 100644 --- a/drivers/kernel/drivers/nfb/ndp/ring.c +++ b/drivers/kernel/drivers/nfb/ndp/ring.c @@ -95,7 +95,7 @@ void ndp_block_free(struct device *dev, struct ndp_block *blocks, } } -void ndp_channel_update_fdt(struct ndp_channel *channel) +static void ndp_channel_update_fdt(struct ndp_channel *channel) { int node; int fdt_offset; @@ -126,7 +126,7 @@ void ndp_channel_update_fdt(struct ndp_channel *channel) * @size: block size (must be PAGE_SIZE aligned) * */ -int ndp_channel_ring_alloc(struct device *dev, +static int ndp_channel_ring_alloc(struct device *dev, struct ndp_channel *channel, size_t count, size_t size) { int i, j, k; @@ -182,7 +182,7 @@ int ndp_channel_ring_alloc(struct device *dev, * @channel: channel for deallocation * */ -void ndp_channel_ring_free(struct ndp_channel * channel) +static void ndp_channel_ring_free(struct ndp_channel * channel) { if (channel->ring.vmap) vunmap(channel->ring.vmap); diff --git a/drivers/kernel/drivers/nfb/ndp/subscriber.c b/drivers/kernel/drivers/nfb/ndp/subscriber.c index 2cc9f15a..0ade016b 100644 --- a/drivers/kernel/drivers/nfb/ndp/subscriber.c +++ b/drivers/kernel/drivers/nfb/ndp/subscriber.c @@ -24,7 +24,7 @@ #include "ndp.h" -size_t ndp_subscriber_new_data(struct ndp_subscriber *subscriber) +static size_t ndp_subscriber_new_data(struct ndp_subscriber *subscriber) { size_t ret = 0, max; struct ndp_subscription *sub, *max_sub; @@ -47,7 +47,7 @@ size_t ndp_subscriber_new_data(struct ndp_subscriber *subscriber) return ret; } -enum hrtimer_restart ndp_subscriber_poll_timer(struct hrtimer *timer) +static enum hrtimer_restart ndp_subscriber_poll_timer(struct hrtimer *timer) { int ret; struct ndp_subscriber *subscriber = container_of(timer, struct ndp_subscriber, poll_timer); diff --git a/drivers/kernel/drivers/nfb/ndp_netdev/core.c b/drivers/kernel/drivers/nfb/ndp_netdev/core.c index 1d1b505e..78b45260 100644 --- a/drivers/kernel/drivers/nfb/ndp_netdev/core.c +++ b/drivers/kernel/drivers/nfb/ndp_netdev/core.c @@ -212,7 +212,7 @@ static int nfb_ndp_netdev_close(struct net_device *ndev) * nfb_ndp_netdev_xmit_dma - transmit packet * @skb: structure containing packet data */ -netdev_tx_t nfb_ndp_netdev_xmit_dma(struct sk_buff *skb, struct net_device *dev) +static netdev_tx_t nfb_ndp_netdev_xmit_dma(struct sk_buff *skb, struct net_device *dev) { int ret; unsigned cnt; @@ -342,7 +342,7 @@ const struct attribute_group *nfb_ndp_netdev_attr_groups[] = { * nfb_ndp_netdev_create - creates and registers new network device in the system * @index: index of network interface */ -struct nfb_ndp_netdev *nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *eth, int index) +static struct nfb_ndp_netdev *nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *eth, int index) { struct nfb_device *nfb = eth->nfb; struct nfb_ndp_netdev *ethdev; @@ -404,7 +404,7 @@ struct nfb_ndp_netdev *nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *eth, int /** * nfb_ndp_netdev_destroy - remove network device from the system */ -void nfb_ndp_netdev_destroy(struct nfb_ndp_netdev *ethdev) +static void nfb_ndp_netdev_destroy(struct nfb_ndp_netdev *ethdev) { unregister_netdev(ethdev->ndev); device_del(ðdev->device); diff --git a/drivers/kernel/drivers/nfb/net/device.c b/drivers/kernel/drivers/nfb/net/device.c index 4df3eab3..9521349b 100644 --- a/drivers/kernel/drivers/nfb/net/device.c +++ b/drivers/kernel/drivers/nfb/net/device.c @@ -220,8 +220,8 @@ static void nfb_net_service_task(struct work_struct *work) clear_bit(NFBNET_SERVICE_SCHED, &priv->state); } - -u32 nfb_net_get_link(struct net_device *netdev) +#if 0 +static u32 nfb_net_get_link(struct net_device *netdev) { struct nfb_net_device *priv = netdev_priv(netdev); @@ -231,7 +231,7 @@ u32 nfb_net_get_link(struct net_device *netdev) return 0; } - +#endif static void nfb_set_rx_mode(struct net_device *netdev) { @@ -600,7 +600,7 @@ static int nfb_net_transmission_on(struct net_device *netdev) } -netdev_tx_t nfb_start_xmit(struct sk_buff *skb, struct net_device *netdev) +static netdev_tx_t nfb_start_xmit(struct sk_buff *skb, struct net_device *netdev) { struct nfb_net_device *priv = netdev_priv(netdev); struct nfb_net_queue *txq = &priv->txqs[skb->queue_mapping]; @@ -709,7 +709,7 @@ static const struct net_device_ops netdev_ops = { }; -int nfb_net_queues_init(struct net_device *netdev) +static int nfb_net_queues_init(struct net_device *netdev) { struct nfb_net_device *priv = netdev_priv(netdev); @@ -758,7 +758,7 @@ int nfb_net_queues_init(struct net_device *netdev) } -void nfb_net_queues_deinit(struct net_device *netdev) +static void nfb_net_queues_deinit(struct net_device *netdev) { struct nfb_net_device *priv = netdev_priv(netdev); diff --git a/drivers/kernel/drivers/nfb/net/driver.c b/drivers/kernel/drivers/nfb/net/driver.c index 544da90c..809528b4 100644 --- a/drivers/kernel/drivers/nfb/net/driver.c +++ b/drivers/kernel/drivers/nfb/net/driver.c @@ -34,7 +34,7 @@ static inline uint64_t fr_64b_to_ns(uint64_t fr) return fr / 18446744073llu; } -int nfb_tsu_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) +static int nfb_tsu_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) { struct nfb_net *net = container_of(ptp, struct nfb_net, ptp_info); uint64_t inc_prev, inc; @@ -51,13 +51,13 @@ int nfb_tsu_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) } #ifdef HAVE_PTP_CLOCK_INFO_ADJFREQ -int nfb_tsu_adjfreq(struct ptp_clock_info *ptp, s32 delta) +static int nfb_tsu_adjfreq(struct ptp_clock_info *ptp, s32 delta) { return -EOPNOTSUPP; } #endif -int nfb_tsu_adjtime(struct ptp_clock_info *ptp, s64 delta) +static int nfb_tsu_adjtime(struct ptp_clock_info *ptp, s64 delta) { struct nfb_net *net = container_of(ptp, struct nfb_net, ptp_info); struct nc_tsu_time rtr = nc_tsu_get_rtr(net->ptp_tsu_comp); @@ -71,7 +71,7 @@ int nfb_tsu_adjtime(struct ptp_clock_info *ptp, s64 delta) return 0; } -int nfb_tsu_gettimex64(struct ptp_clock_info *ptp, struct timespec64 *ts, +static int nfb_tsu_gettimex64(struct ptp_clock_info *ptp, struct timespec64 *ts, struct ptp_system_timestamp *sts) { struct nfb_net *net = container_of(ptp, struct nfb_net, ptp_info); @@ -107,7 +107,7 @@ int nfb_tsu_gettimex64(struct ptp_clock_info *ptp, struct timespec64 *ts, return 0; } -int nfb_tsu_settime64(struct ptp_clock_info *p, const struct timespec64 *ts) +static int nfb_tsu_settime64(struct ptp_clock_info *p, const struct timespec64 *ts) { struct nfb_net *net = container_of(p, struct nfb_net, ptp_info); struct nc_tsu_time rtr; @@ -118,13 +118,13 @@ int nfb_tsu_settime64(struct ptp_clock_info *p, const struct timespec64 *ts) // printk("PTP TSU settime: %lld . %lld\n", ts->tv_sec, ts->tv_nsec); return 0; } -int nfb_tsu_enable(struct ptp_clock_info *ptp, +static int nfb_tsu_enable(struct ptp_clock_info *ptp, struct ptp_clock_request *request, int on) { printk("PTP TSU enable: not supported\n"); return -EOPNOTSUPP; } -int nfb_tsu_verify(struct ptp_clock_info *ptp, unsigned int pin, +static int nfb_tsu_verify(struct ptp_clock_info *ptp, unsigned int pin, enum ptp_pin_function func, unsigned int chan) { printk("PTP TSU verify: not supported\n"); diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 47ad3f07..558a2f01 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -657,7 +657,7 @@ static void *nfb_pci_copy_fdt(struct nfb_pci_device *pci_device) * @irq: interrupt vector * @pnfb: pointer to NFB device */ -irqreturn_t nfb_interrupt(int irq, void *pnfb) +static irqreturn_t nfb_interrupt(int irq, void *pnfb) { //struct nfb_device *nfb = (struct nfb_device *) pnfb; return IRQ_NONE; @@ -757,7 +757,7 @@ static int nfb_pci_device_is_attachable(struct nfb_device *nfb, struct nfb_pci_d return 1; } -struct nfb_pci_device *_nfb_pci_device_find(struct pci_dev *pci) +static struct nfb_pci_device *_nfb_pci_device_find(struct pci_dev *pci) { struct nfb_pci_device *pci_device = NULL; @@ -770,7 +770,7 @@ struct nfb_pci_device *_nfb_pci_device_find(struct pci_dev *pci) return NULL; } -struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) +static struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) { struct nfb_pci_device *pci_device = NULL; @@ -791,7 +791,7 @@ struct nfb_pci_device *_nfb_pci_device_create(struct pci_dev *pci) return pci_device; } -struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) +static struct nfb_pci_device *nfb_pci_device_find_or_create(struct pci_dev *pci) { int proplen; int node; @@ -918,7 +918,7 @@ void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus) * nfb_pci_detach_all_slaves - Detach all slave endpoints from NFB device * @nfb: NFB device */ -void nfb_pci_detach_endpoints(struct nfb_device *nfb, struct nfb_pci_device *self) +static void nfb_pci_detach_endpoints(struct nfb_device *nfb, struct nfb_pci_device *self) { struct nfb_pci_device *pci_device, *temp; @@ -933,7 +933,7 @@ void nfb_pci_detach_endpoints(struct nfb_device *nfb, struct nfb_pci_device *sel } } -void nfb_pci_try_attach(struct nfb_pci_device *self) +static void nfb_pci_try_attach(struct nfb_pci_device *self) { struct nfb_device * nfb; struct nfb_pci_device *pci_device; @@ -1164,7 +1164,7 @@ static int nfb_pci_probe_main(struct nfb_pci_device *pci_device, const struct pc * nfb_remove - called when kernel removes NFB device * @pci: PCI device object */ -void nfb_pci_remove(struct pci_dev *pci) +static void nfb_pci_remove(struct pci_dev *pci) { struct nfb_pci_device *pci_device = (struct nfb_pci_device *) pci_get_drvdata(pci); struct nfb_device *nfb; diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index d7804ac1..c9985d0d 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -19,6 +19,7 @@ void ndp_close_queue(struct ndp_queue *q); int _ndp_queue_sync(struct nc_ndp_queue *q, struct ndp_subscription_sync *sync); int _ndp_queue_start(struct nc_ndp_queue *q); int _ndp_queue_stop(struct nc_ndp_queue *q); +void _ndp_queue_init(struct ndp_queue *q, struct nfb_device *dev, int numa, int dir, int index); static int nc_ndp_queue_start(void *priv); static int nc_ndp_queue_stop(void *priv); From dcf8daf06c9e4258241c174ee58d0edbedb2858d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 13 Nov 2024 17:30:16 +0100 Subject: [PATCH 235/518] build: [MAINTENANCE] update 3rdparty.tar.gz to 6.24.0 --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index e7ffeb39..b5e51e27 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ AUTOINSTALL=true # whether dependencies should be installed with '-y' RELTYPE=Release # Release type (Debug/Release) FILENAME_3RDPARTY="3rdparty.tar.gz" -SRC_3RDPARTY_VERSION="v6.21.1" +SRC_3RDPARTY_VERSION="v6.24.0" URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_VERSION/$FILENAME_3RDPARTY" EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" From 85085d0f9be9b25306dec2368c0c243300450c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 20 Nov 2024 14:02:34 +0000 Subject: [PATCH 236/518] build: [FIX] Make configure.ac work with sh implementation that doesn't support [[ ]] operator. --- drivers/configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index eee9cd64..a728f456 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -9,7 +9,7 @@ DEFAULT_PACKAGE_NAME="nfb" AC_PREREQ([2.63]) -AC_INIT(m4_esyscmd([ if [[ -z $CMAKE_PACKAGE_NAME ]]; then echo -n $DEFAULT_PACKAGE_NAME; else echo -n $CMAKE_PACKAGE_NAME; fi;]), m4_esyscmd([ if [[ -z $CMAKE_PACKAGE_VERSION ]]; then cut -f1 ../VERSION | tr -d '\n'; else echo -n $CMAKE_PACKAGE_VERSION; fi;])) +AC_INIT(m4_esyscmd([ if [ -z $CMAKE_PACKAGE_NAME ]; then echo -n $DEFAULT_PACKAGE_NAME; else echo -n $CMAKE_PACKAGE_NAME; fi;]), m4_esyscmd([ if [ -z $CMAKE_PACKAGE_VERSION ]; then cut -f1 ../VERSION | tr -d '\n'; else echo -n $CMAKE_PACKAGE_VERSION; fi;])) AC_CONFIG_HEADERS(config.h) From e8a9e4e58735174da7a514d444148eaa2fb45aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Ko=C5=A1a=C5=99?= Date: Tue, 2 Jan 2024 20:05:03 +0100 Subject: [PATCH 237/518] drivers: [FEATURE] Add basic support for NFB boot via SPI access to BMC on FPGA card Silicom N5014 Basic support for FPGA card Silicom N5014 without firmware reload. --- drivers/kernel/drivers/nfb/Makefile | 2 +- drivers/kernel/drivers/nfb/boot/boot.c | 17 +- drivers/kernel/drivers/nfb/boot/boot.h | 2 + drivers/kernel/drivers/nfb/boot/nfb-common.h | 21 + drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 24 +- drivers/kernel/drivers/nfb/boot/nfb-pmci.h | 7 +- drivers/kernel/drivers/nfb/boot/nfb-spi.c | 422 +++++++++++++++++++ drivers/kernel/drivers/nfb/boot/nfb-spi.h | 41 ++ drivers/kernel/drivers/nfb/boot/reload.c | 3 + drivers/kernel/drivers/nfb/pci.c | 6 + 10 files changed, 527 insertions(+), 18 deletions(-) create mode 100644 drivers/kernel/drivers/nfb/boot/nfb-common.h create mode 100644 drivers/kernel/drivers/nfb/boot/nfb-spi.c create mode 100644 drivers/kernel/drivers/nfb/boot/nfb-spi.h diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index 6f6fc815..e9d20d04 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -16,7 +16,7 @@ nfb-objs += mi/mi.o nfb-objs += ndp/ctrl.o ndp/ctrl_ndp.o ndp/channel.o ndp/subscription.o ndp/subscriber.o ndp/ring.o ndp/char.o ndp/driver.o ndp/kndp.o nfb-objs += ndp_netdev/core.o nfb-objs += boot/flash.o boot/reload.o boot/boot.o boot/gecko.o boot/sdm.o -nfb-objs += ../mfd/intel-m10-bmc-core.o ../fpga/fpga-image-load.o ../fpga/intel-m10-bmc-sec-update.o ../hwmon/intel-m10-bmc-hwmon.o ../mfd/intel-m10-bmc-log.o boot/nfb-pmci.o +nfb-objs += ../mfd/intel-m10-bmc-core.o ../fpga/fpga-image-load.o ../fpga/intel-m10-bmc-sec-update.o ../hwmon/intel-m10-bmc-hwmon.o ../mfd/intel-m10-bmc-log.o boot/nfb-pmci.o boot/nfb-spi.o nfb-objs += net/driver.o net/device.o net/ethtool.o net/sysfs.o nfb-objs += qdr/qdr.o nfb-objs += misc.o lock.o bus.o char.o pci.o core.o diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 3682ea98..30250a1b 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -267,6 +267,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) boot->nfb = nfb; #ifdef CONFIG_NFB_ENABLE_PMCI ret = nfb_pmci_attach(boot); + ret = nfb_spi_attach(boot); #endif /* Cards with Intel FPGA (Stratix10, Agilex) use Secure Device Manager for QSPI Flash access and Boot */ boot->sdm = NULL; @@ -292,7 +293,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) fdt_offset = fdt_node_offset_by_compatible(nfb->fdt, -1, "netcope,boot_controller"); // FIXME: better create some general boot controller interface if (fdt_offset < 0) { - if (boot->sdm_boot_en == 0 && boot->pmci == NULL) { + if (boot->sdm_boot_en == 0 && boot->pmci == NULL && boot->m10bmc_spi == NULL) { ret = -ENODEV; dev_warn(&nfb->pci->dev, "nfb_boot: No boot_controller found in FDT.\n"); goto err_nocomp; @@ -302,7 +303,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) } boot->comp = nfb_comp_open(nfb, fdt_offset); - if (!boot->comp && boot->pmci == NULL) { + if (!boot->comp && boot->pmci == NULL && boot->m10bmc_spi == NULL) { ret = -ENODEV; goto err_comp_open; } @@ -371,6 +372,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) err_nocomp: #ifdef CONFIG_NFB_ENABLE_PMCI nfb_pmci_detach(boot); + nfb_spi_detach(boot); #endif kfree(boot); err_kmalloc: @@ -400,6 +402,8 @@ void nfb_boot_detach(struct nfb_device* nfb, void *priv) #ifdef CONFIG_NFB_ENABLE_PMCI if (boot->pmci) nfb_pmci_detach(boot); + if (boot->m10bmc_spi) + nfb_spi_detach(boot); #endif kfree(boot); } @@ -407,7 +411,13 @@ void nfb_boot_detach(struct nfb_device* nfb, void *priv) int nfb_boot_init() { #ifdef CONFIG_NFB_ENABLE_PMCI - return nfb_pmci_init(); + int ret; + ret = nfb_pmci_init(); + if (ret) + goto err_pmci; + ret = nfb_spi_init(); +err_pmci: + return ret; #else return 0; #endif @@ -417,6 +427,7 @@ void nfb_boot_exit() { #ifdef CONFIG_NFB_ENABLE_PMCI nfb_pmci_exit(); + nfb_spi_exit(); #endif } diff --git a/drivers/kernel/drivers/nfb/boot/boot.h b/drivers/kernel/drivers/nfb/boot/boot.h index 72c2858d..1f5e3e39 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.h +++ b/drivers/kernel/drivers/nfb/boot/boot.h @@ -24,12 +24,14 @@ #include "sdm.h" #include "nfb-pmci.h" +#include "nfb-spi.h" struct nfb_boot { struct nfb_comp *comp; struct spi_device *spi; struct nfb_device *nfb; struct pmci_device *pmci; + struct m10bmc_spi_nfb_device *m10bmc_spi; int num_image; diff --git a/drivers/kernel/drivers/nfb/boot/nfb-common.h b/drivers/kernel/drivers/nfb/boot/nfb-common.h new file mode 100644 index 00000000..2c6f9e85 --- /dev/null +++ b/drivers/kernel/drivers/nfb/boot/nfb-common.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Boot driver module header for Intel M10 BMC via SPI core. + * Support for Silicom N5014. + * + * Copyright (C) 2024 BrnoLogic + * Author(s): + * Vlastimil Kosar + */ + +#ifndef NFB_BOOT_COMMON_H +#define NFB_BOOT_COMMON_H + +struct m10bmc_sec; + +struct image_load { + const char *name; + int (*load_image)(struct m10bmc_sec *sec); +}; + +#endif diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index 034119ae..b84c5bbb 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -423,17 +423,23 @@ int nfb_pmci_init() if (ret) goto err_log; - ret = platform_driver_register(&nfb_intel_m10bmc_sec_driver); - if (ret) - goto err_sec; + if (driver_find(nfb_intel_m10bmc_sec_driver.driver.name, &platform_bus_type) == NULL) { + ret = platform_driver_register(&nfb_intel_m10bmc_sec_driver); + if (ret) + goto err_sec; + } - ret = platform_driver_register(&nfb_intel_m10bmc_hwmon_driver); - if (ret) - goto err_hwmon; + if (driver_find(nfb_intel_m10bmc_hwmon_driver.driver.name, &platform_bus_type) == NULL) { + ret = platform_driver_register(&nfb_intel_m10bmc_hwmon_driver); + if (ret) + goto err_hwmon; + } - ret = platform_driver_register(&nfb_intel_m10bmc); - if (ret) - goto err_pdr; + if (driver_find(nfb_intel_m10bmc.driver.name, &platform_bus_type) == NULL) { + ret = platform_driver_register(&nfb_intel_m10bmc); + if (ret) + goto err_pdr; + } return 0; diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.h b/drivers/kernel/drivers/nfb/boot/nfb-pmci.h index 7203a871..7fa8d9a7 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.h +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.h @@ -9,6 +9,8 @@ #include +#include "nfb-common.h" + #ifndef NFB_BOOT_PMCI_H #define NFB_BOOT_PMCI_H @@ -21,11 +23,6 @@ void nfb_pmci_detach(struct nfb_boot *boot); struct m10bmc_sec; -struct image_load { - const char *name; - int (*load_image)(struct m10bmc_sec *sec); -}; - struct pmci_device { struct intel_m10bmc m10bmc; struct nfb_comp * comp; diff --git a/drivers/kernel/drivers/nfb/boot/nfb-spi.c b/drivers/kernel/drivers/nfb/boot/nfb-spi.c new file mode 100644 index 00000000..726616ba --- /dev/null +++ b/drivers/kernel/drivers/nfb/boot/nfb-spi.c @@ -0,0 +1,422 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Boot driver module for Intel M10 BMC via SPI core. + * Support for Silicom N5014. + * + * Derived from intel-m10-bmc-spi.c and spi-altera-dfl.c from N5014 DFL drivers. + * Those files are under GPL 2.0 and are authored respecively by: + * intel-m10-bmc-spi.c: + * Intel MAX 10 Board Management Controller chip + * Copyright (C) 2018-2021 Intel Corporation. All rights reserved. + * spi-altera-dfl.c: + * DFL bus driver for Altera SPI Master + * Copyright (C) 2020 Intel Corporation, Inc. + * Authors: + * Matthew Gerlach + * + * Copyright (C) 2024 BrnoLogic + * Author(s): + * Vlastimil Kosar + */ + +#include +#ifdef CONFIG_NFB_ENABLE_PMCI + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "boot.h" +#include "../nfb.h" +#include "../pci.h" +#include "../mi/mi.h" + +#include + +#include + +#include +#include + +#include "nfb-spi.h" + +#define SPI_CORE_PARAMETER 0x8 +#define SHIFT_MODE BIT_ULL(1) +#define SHIFT_MODE_MSB 0 +#define SHIFT_MODE_LSB 1 +#define DATA_WIDTH GENMASK_ULL(7, 2) +#define NUM_CHIPSELECT GENMASK_ULL(13, 8) +#define CLK_POLARITY BIT_ULL(14) +#define CLK_PHASE BIT_ULL(15) +#define PERIPHERAL_ID GENMASK_ULL(47, 32) +#define SPI_CLK GENMASK_ULL(31, 22) +#define SPI_INDIRECT_ACC_OFST 0x10 + +#define INDIRECT_ADDR (SPI_INDIRECT_ACC_OFST+0x0) +#define INDIRECT_WR BIT_ULL(8) +#define INDIRECT_RD BIT_ULL(9) +#define INDIRECT_RD_DATA (SPI_INDIRECT_ACC_OFST+0x8) +#define INDIRECT_DATA_MASK GENMASK_ULL(31, 0) +#define INDIRECT_DEBUG BIT_ULL(32) +#define INDIRECT_WR_DATA (SPI_INDIRECT_ACC_OFST+0x10) +#define INDIRECT_TIMEOUT 10000 + +struct indirect_ctx { + struct device *dev; + struct nfb_comp *comp; + off_t offset; +}; + +static int indirect_bus_reg_read(void *context, unsigned int reg, + unsigned int *val) +{ + struct indirect_ctx *ctx = context; + int loops; + u32 v; + + nfb_comp_write32(ctx->comp, ctx->offset + INDIRECT_ADDR, (reg >> 2) | INDIRECT_RD); + + loops = 0; + while ((nfb_comp_read32(ctx->comp, ctx->offset + INDIRECT_ADDR) & INDIRECT_RD) && + (loops++ < INDIRECT_TIMEOUT)) + cpu_relax(); + + if (loops >= INDIRECT_TIMEOUT) { + dev_err(ctx->dev, "%s timed out on reg 0x%x with loops %d\n", __func__, reg, loops); + return -ETIME; + } + + v = nfb_comp_read32(ctx->comp, ctx->offset + INDIRECT_RD_DATA); + *val = v & INDIRECT_DATA_MASK; + + return 0; +} + +static int indirect_bus_reg_write(void *context, unsigned int reg, + unsigned int val) +{ + struct indirect_ctx *ctx = context; + int loops; + + nfb_comp_write32(ctx->comp, ctx->offset + INDIRECT_WR_DATA, val); + nfb_comp_write32(ctx->comp, ctx->offset + INDIRECT_ADDR, (reg >> 2) | INDIRECT_WR); + + loops = 0; + while ((nfb_comp_read32(ctx->comp, ctx->offset + INDIRECT_ADDR) & INDIRECT_WR) && + (loops++ < INDIRECT_TIMEOUT)) + cpu_relax(); + + if (loops >= INDIRECT_TIMEOUT) { + dev_err(ctx->dev, "%s timed out on reg 0x%x with loops %d\n", __func__, reg, loops); + return -ETIME; + } + + return 0; +} + +static struct regmap_config indirect_regbus_cfg = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .fast_io = true, + .max_register = 24, + + .reg_write = indirect_bus_reg_write, + .reg_read = indirect_bus_reg_read, +}; + +static void config_spi_host(struct nfb_comp *comp, off_t offset, struct spi_controller *host) +{ + u64 v; + + v = nfb_comp_read64(comp, offset + SPI_CORE_PARAMETER); + + host->mode_bits = SPI_CS_HIGH; + if (FIELD_GET(CLK_POLARITY, v)) + host->mode_bits |= SPI_CPOL; + if (FIELD_GET(CLK_PHASE, v)) + host->mode_bits |= SPI_CPHA; + + host->num_chipselect = FIELD_GET(NUM_CHIPSELECT, v); + host->bits_per_word_mask = + SPI_BPW_RANGE_MASK(1, FIELD_GET(DATA_WIDTH, v)); +} + +static struct regmap *nfb_devm_regmap_init_indirect_register(struct device *dev, + off_t offset, struct nfb_comp *comp, struct regmap_config *cfg) +{ + struct indirect_ctx *ctx; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + + if (!ctx) + return NULL; + + ctx->dev = dev; + ctx->comp = comp; + ctx->offset = offset; + + return devm_regmap_init(dev, /*&indirect_bus*/NULL, ctx, cfg); +} + +static const struct regmap_range m10bmc_spi_regmap_range[] = { + regmap_reg_range(M10BMC_LEGACY_BUILD_VER, M10BMC_LEGACY_BUILD_VER), + regmap_reg_range(M10BMC_SYS_BASE, M10BMC_SYS_END), + regmap_reg_range(M10BMC_FLASH_BASE, M10BMC_FLASH_END), +}; + +static const struct regmap_access_table m10_access_table = { + .yes_ranges = m10bmc_spi_regmap_range, + .n_yes_ranges = ARRAY_SIZE(m10bmc_spi_regmap_range), +}; + +static struct regmap_config m10bmc_spi_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .wr_table = &m10_access_table, + .rd_table = &m10_access_table, + .max_register = M10BMC_MEM_END, +}; + +int nfb_spi_attach(struct nfb_boot *boot) +{ + struct nfb_device *nfb = boot->nfb; + struct m10bmc_spi_nfb_device *m10bmc_spi; + struct spi_board_info board_info = { 0 }; + struct spi_controller *host; + struct altera_spi *hw; + struct spi_device *spi_dev; + + int fdt_offset; + int ret = 0; + + m10bmc_spi = kzalloc(sizeof(*m10bmc_spi), GFP_KERNEL); + if (!m10bmc_spi) { + ret = -ENOMEM; + goto err_alloc_spi; + } + + fdt_offset = fdt_node_offset_by_compatible(nfb->fdt, -1, "brnologic,m10bmc_spi"); + m10bmc_spi->comp = nfb_comp_open(nfb, fdt_offset); + if (m10bmc_spi->comp == NULL) { + ret = -ENODEV; + goto err_nfb_comp; + } + + m10bmc_spi->pd = platform_device_register_resndata(nfb->dev, "nfb-spi-m10bmc", nfb->minor, NULL, 0, m10bmc_spi, sizeof(m10bmc_spi)); + if (IS_ERR(m10bmc_spi->pd)) { + ret = PTR_ERR(m10bmc_spi->pd); + goto err_pd_register; + } + + m10bmc_spi->m10bmc.dev = &m10bmc_spi->pd->dev; + m10bmc_spi->m10bmc.type = M10_N5014; + m10bmc_spi->m10bmc.flash_ops = NULL; + + host = spi_alloc_master(&m10bmc_spi->pd->dev, sizeof(struct altera_spi)); + if (!host) { + ret = -ENOMEM; + goto err_alloc_master; + } + + + host->bus_num = -1; + + hw = spi_controller_get_devdata(host); + + hw->dev = &m10bmc_spi->pd->dev; + + config_spi_host(m10bmc_spi->comp, 0, host); + dev_dbg(&m10bmc_spi->pd->dev, "%s cs %u bpm 0x%x mode 0x%x\n", __func__, + host->num_chipselect, host->bits_per_word_mask, + host->mode_bits); + + hw->regmap = nfb_devm_regmap_init_indirect_register(&m10bmc_spi->pd->dev, + 0, m10bmc_spi->comp, + &indirect_regbus_cfg); + if (IS_ERR(hw->regmap)) { + ret = PTR_ERR(hw->regmap); + goto err_regmap_register; + } + + hw->irq = -EINVAL; + + altera_spi_init_host(host); + + ret = devm_spi_register_controller(&m10bmc_spi->pd->dev, host); + if (ret) { + dev_err(&m10bmc_spi->pd->dev, "%s failed to register spi host %d\n", __func__, ret); + goto err_spi_register_ctrl; + } + + strscpy(board_info.modalias, "nfb-m10-n5014", SPI_NAME_SIZE); + board_info.max_speed_hz = 12500000; + board_info.bus_num = 0; + board_info.chip_select = 0; + + spi_dev = spi_new_device(host, &board_info); + if (!spi_dev) { + dev_err(&m10bmc_spi->pd->dev, "%s failed to create SPI device: %s\n", + __func__, board_info.modalias); + } + + m10bmc_spi->m10bmc.regmap = devm_regmap_init_spi_avmm(spi_dev, &m10bmc_spi_regmap_config); + if (IS_ERR(m10bmc_spi->m10bmc.regmap)) { + ret = PTR_ERR(m10bmc_spi->m10bmc.regmap); + dev_err(&m10bmc_spi->pd->dev, "%s Failed to allocate regmap: %d\n", __func__, ret); + goto err_regmap_register_avmm; + } + + ret = devm_device_add_groups(&m10bmc_spi->pd->dev, nfb_m10bmc_dev_groups); + if (ret) + goto err_dev_addgroups; + + msleep(10); + + ret = m10bmc_dev_init(&m10bmc_spi->m10bmc); + if (ret) + goto err_m10bmc_init; + + m10bmc_spi->host = host; + boot->m10bmc_spi = m10bmc_spi; + return ret; + +err_spi_register_ctrl: +err_regmap_register: + spi_controller_put(host); +err_m10bmc_init: +err_dev_addgroups: +err_regmap_register_avmm: +err_alloc_master: + platform_device_unregister(m10bmc_spi->pd); +err_pd_register: + nfb_comp_close(m10bmc_spi->comp); +err_nfb_comp: + kfree(m10bmc_spi); +err_alloc_spi: + return ret; +} + +void nfb_spi_detach(struct nfb_boot *boot) +{ + struct m10bmc_spi_nfb_device *m10bmc_spi = boot->m10bmc_spi; + if (m10bmc_spi == NULL) + return; + + platform_device_unregister(m10bmc_spi->pd); + + nfb_comp_close(m10bmc_spi->comp); + kfree(m10bmc_spi); + boot->m10bmc_spi = NULL; +} + +extern struct platform_driver nfb_intel_m10bmc_sec_driver; +extern struct platform_driver nfb_intel_m10bmc_hwmon_driver; + +struct platform_driver nfb_intel_m10bmc_spi = { + .driver = { + .name = "nfb-spi-m10bmc", + }, +}; + +static int nfb_intel_m10_bmc_spi_probe(struct spi_device *spi) +{ + struct device *dev = &spi->dev; + int ret = 0; + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) && RHEL_RELEASE_CODE < 0x803 + ret = device_add_groups(dev, nfb_m10bmc_dev_groups); + if (ret) + return ret; + #endif + return ret; +} + +static const struct spi_device_id nfb_m10bmc_spi_id[] = { +// { "m10-n3000", M10_N3000 }, +// { "m10-d5005", M10_D5005 }, +// { "m10-n5010", M10_N5010 }, + { "nfb-m10-n5014", M10_N5014 }, + { } +}; +MODULE_DEVICE_TABLE(spi, nfb_m10bmc_spi_id); + +static struct spi_driver nfb_intel_m10bmc_spi_dev = { + .driver = { + .name = "nfb-intel-m10-bmc-spi-dev", +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0) || RHEL_RELEASE_CODE >= 0x803 + .dev_groups = nfb_m10bmc_dev_groups, +#endif + }, + .probe = nfb_intel_m10_bmc_spi_probe, + .id_table = nfb_m10bmc_spi_id, +}; + +int nfb_spi_init() +{ + int ret; + + if (driver_find(nfb_intel_m10bmc_sec_driver.driver.name, &platform_bus_type) == NULL) { + ret = platform_driver_register(&nfb_intel_m10bmc_sec_driver); + if (ret) + goto err_sec; + } + + if (driver_find(nfb_intel_m10bmc_hwmon_driver.driver.name, &platform_bus_type) == NULL) { + ret = platform_driver_register(&nfb_intel_m10bmc_hwmon_driver); + if (ret) + goto err_hwmon; + } + + if (driver_find(nfb_intel_m10bmc_spi_dev.driver.name, &spi_bus_type) == NULL) { + ret = spi_register_driver(&nfb_intel_m10bmc_spi_dev); + if (ret) + goto err_spi_driver; + } + + if (driver_find(nfb_intel_m10bmc_spi.driver.name, &platform_bus_type) == NULL) { + ret = platform_driver_register(&nfb_intel_m10bmc_spi); + if (ret) + goto err_pdr; + } + + return 0; + +err_pdr: + spi_unregister_driver(&nfb_intel_m10bmc_spi_dev); +err_spi_driver: + platform_driver_unregister(&nfb_intel_m10bmc_hwmon_driver); +err_hwmon: + platform_driver_unregister(&nfb_intel_m10bmc_sec_driver); +err_sec: + return ret; + +} + +void nfb_spi_exit() +{ + if (driver_find(nfb_intel_m10bmc_spi.driver.name, &platform_bus_type) != NULL) { + platform_driver_unregister(&nfb_intel_m10bmc_spi); + } + if (driver_find(nfb_intel_m10bmc_spi_dev.driver.name, &spi_bus_type) != NULL) { + spi_unregister_driver(&nfb_intel_m10bmc_spi_dev); + } + if (driver_find(nfb_intel_m10bmc_hwmon_driver.driver.name, &platform_bus_type) != NULL) { + platform_driver_unregister(&nfb_intel_m10bmc_hwmon_driver); + } + if (driver_find(nfb_intel_m10bmc_sec_driver.driver.name, &platform_bus_type) != NULL) { + platform_driver_unregister(&nfb_intel_m10bmc_sec_driver); + } +} + +#endif diff --git a/drivers/kernel/drivers/nfb/boot/nfb-spi.h b/drivers/kernel/drivers/nfb/boot/nfb-spi.h new file mode 100644 index 00000000..6da744a5 --- /dev/null +++ b/drivers/kernel/drivers/nfb/boot/nfb-spi.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Boot driver module header for Intel M10 BMC via SPI core. + * Support for Silicom N5014. + * + * Copyright (C) 2024 BrnoLogic + * Author(s): + * Vlastimil Kosar + */ + +#include + +#include "nfb-common.h" + +#ifndef NFB_BOOT_SPI_H +#define NFB_BOOT_SPI_H + +struct nfb_boot; + +int nfb_spi_init(void); +void nfb_spi_exit(void); +int nfb_spi_attach(struct nfb_boot *boot); +void nfb_spi_detach(struct nfb_boot *boot); + +struct m10bmc_sec; + +struct m10bmc_spi_nfb_device { + struct intel_m10bmc m10bmc; + struct nfb_comp * comp; + + struct platform_device *pd; + + struct fpga_image_load *imgld; + struct image_load* image_load; + + struct m10bmc_sec *sec; + + struct spi_controller *host; +}; + +#endif diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index c2ff8c34..efc7b2f6 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -179,6 +179,9 @@ int nfb_boot_reload(void *arg) if (boot->pmci) { boot->pmci->image_load[boot->num_image].load_image(boot->pmci->sec); reload_time_ms = 5000; + } else if (boot->m10bmc_spi) { + boot->m10bmc_spi->image_load[boot->num_image].load_image(boot->m10bmc_spi->sec); + reload_time_ms = 5000; } else if (boot->sdm && boot->sdm_boot_en) { sdm_rsu_image_update(boot->sdm, boot->num_image); } else if (boot->comp) { diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 558a2f01..3066ca24 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -237,6 +237,7 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) "netcope,boot_controller", "netcope,intel_sdm_controller", "cesnet,pmci", + "brnologic,m10bmc_spi", }; name = nfb->pci_name; @@ -360,6 +361,11 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) n6010_binary_slot_prepare(fdt, subnode, "\x00\x00\x01\x00", "\xff\xff\xff\xff", 4); subnode = nfb_fdt_create_binary_slot(fdt, node, "image0", "fpga_user1", 0, 3, -1, 0, 0); n6010_binary_slot_prepare(fdt, subnode, "\x00\x00\x00\x00", "\xff\xff\xff\xff", 4); + } else if (!strcmp(card_name, "N5014")) { + subnode = nfb_fdt_create_binary_slot(fdt, node, "image1", "fpga_factory", 1, 0, -1, 0, 0); + n6010_binary_slot_prepare(fdt, subnode, "\x03\x00\x00\x00", "\xff\xff\xff\xff", 4); + subnode = nfb_fdt_create_binary_slot(fdt, node, "image0", "fpga_user", 0, 1, -1, 0, 0); + n6010_binary_slot_prepare(fdt, subnode, "\x00\x00\x00\x00", "\xff\xff\xff\xff", 4); } else if (!strcmp(card_name, "ALVEO_U200") || !strcmp(card_name, "ALVEO_U250") || !strcmp(card_name, "ALVEO_U55C")) { prop32 = cpu_to_fdt32(1); fdt_appendprop(fdt, node, "num_flash", &prop32, sizeof(prop32)); From 95948e200ac6461726c9332760bdd442cdc3dce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Ko=C5=A1a=C5=99?= Date: Mon, 15 Jan 2024 15:39:36 +0100 Subject: [PATCH 238/518] libnfb: [FEATURE] Check fdt for SPI BMC and select appropriate image format --- libnfb/src/boot/boot.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libnfb/src/boot/boot.c b/libnfb/src/boot/boot.c index 75f404e1..e54ad24a 100644 --- a/libnfb/src/boot/boot.c +++ b/libnfb/src/boot/boot.c @@ -231,6 +231,12 @@ ssize_t nfb_fw_read_for_dev(const struct nfb_device *dev, FILE *fd, void **data) return ret; } + fdt_for_each_compatible_node(fdt, node, "brnologic,m10bmc_spi") { + format = BITSTREAM_FORMAT_NATIVE; + ret = nfb_fw_open_rpd(fd, data, format); + return ret; + } + /* For Intel Stratix 10 and Agilex FPGAs */ fdt_for_each_compatible_node(fdt, node, "netcope,intel_sdm_controller") { prop32 = fdt_getprop(fdt, node, "boot_en", &proplen); From 245e428ee6b90d449b1ce2038166c07ea84b535c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Ko=C5=A1a=C5=99?= Date: Fri, 19 Jan 2024 20:34:27 +0100 Subject: [PATCH 239/518] drivers: [FEATURE] Add support for firmware reload on Silicom N5014. Special reload for Silicom N5014 is used. The N5014 card includes a PCIe switch chip, FPGA and two Intel E810 Ethernet chips. Removing and rescanning only the FPGA chip doesn't work correctly. Therefore, the whole card is removed from the PCIe and then is rescanned after reload finished. NOTE: The on-board Intel E810 eth devices may move to another PCIE bus number during rescan, leading to different enpxxxx name. --- drivers/kernel/drivers/nfb/boot/reload.c | 88 +++++++++++++++++++++++- drivers/kernel/drivers/nfb/pci.h | 1 + 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index efc7b2f6..fb8fb42a 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -97,32 +97,114 @@ static int nfb_boot_reload_rescan(struct nfb_pci_device *card) return 0; } +static int nfb_boot_n5014_reload_rescan(struct nfb_pci_device *card) { + struct pci_dev *root; + struct pci_dev *bus_dev; + struct pci_bus *b = NULL; + int reload_time_ms = 5000; + int ext_cap_pos; + + root = pcie_find_root_port(card->pci); + if (root == NULL) { + dev_err(&card->bus->self->dev, "Cannot find PCIE root port!\n"); + return -ENODEV; + } + + // Stop and remove PCIE bus from root port + pci_stop_and_remove_bus_device_locked(root); + + // Wait for a while before rescaning the bus + msleep(reload_time_ms); + + // First try to rescan bus + pci_lock_rescan_remove(); + while ((b = pci_find_next_bus(b)) != NULL) + pci_rescan_bus(b); + pci_unlock_rescan_remove(); + + // Wait again for all devices after the PCIe bridge to appear + msleep(reload_time_ms); + + // Second try to rescan bus + pci_lock_rescan_remove(); + while ((b = pci_find_next_bus(b)) != NULL) + pci_rescan_bus(b); + pci_unlock_rescan_remove(); + + card->pci = pci_get_slot(card->bus, card->devfn); + if (card->pci == NULL) { + return -ENODEV; + } + + bus_dev = card->pci->bus->self; + root = pcie_find_root_port(bus_dev); + if (root == NULL) { + dev_err(&card->bus->self->dev, "Cannot find PCIE root port!\n"); + return -ENODEV; + } + + // Restore errors + dev_info(&bus_dev->dev, "nfb: restoring errors on PCI bridge\n"); + ext_cap_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR); + pci_write_config_word(bus_dev, PCI_COMMAND, card->bridge_command); + pci_write_config_word(bus_dev, bus_dev->pcie_cap + PCI_EXP_DEVCTL, card->bridge_devctl); + if (ext_cap_pos) { + pci_write_config_dword(root, ext_cap_pos + PCI_ERR_ROOT_COMMAND, card->bridge_root_aer_cmd); + } + + pci_dev_put(card->pci); + + pr_info("nfb: firmware reload done\n"); + return 0; +} + /* * nfb_pci_errors_disable - disable errors that can occur on hot reboot (firmware reload) * @card: struct nfb_pci_device instance */ -static int nfb_pci_errors_disable(struct nfb_pci_device *card) +static int nfb_pci_errors_disable(struct nfb_pci_device *card, int use_root_port_cmds) { struct pci_dev *bridge = card->bus->self; + struct pci_dev *root = pcie_find_root_port(bridge); + int ext_cap_pos = 0; + dev_info(&card->bus->self->dev, "disabling errors on PCI bridge\n"); /* save state of error registers */ pci_read_config_word(bridge, PCI_COMMAND, &card->bridge_command); pci_read_config_word(bridge, bridge->pcie_cap + PCI_EXP_DEVCTL, &card->bridge_devctl); + if (use_root_port_cmds) { + if (root == NULL) { + dev_err(&card->bus->self->dev, "Cannot find PCIE root port!\n"); + return -ENODEV; + } + ext_cap_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR); + } + if (ext_cap_pos) { + pci_read_config_dword(root, ext_cap_pos + PCI_ERR_ROOT_COMMAND, &card->bridge_root_aer_cmd); + } pci_write_config_word(bridge, PCI_COMMAND, card->bridge_command & ~PCI_COMMAND_SERR); pci_write_config_word(bridge, bridge->pcie_cap + PCI_EXP_DEVCTL, card->bridge_devctl & ~(PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_FERE)); + if (ext_cap_pos) { + pci_write_config_dword(root, ext_cap_pos + PCI_ERR_ROOT_COMMAND, 0); + } return 0; } int nfb_boot_ioctl_error_disable(struct nfb_boot *nfb_boot) { int ret; + int use_root_port_cmds = 0; struct nfb_pci_device *card; + if (nfb_boot->m10bmc_spi) { + use_root_port_cmds = 1; + } + list_for_each_entry(card, &nfb_boot->nfb->pci_devices, pci_device_list) { - ret = nfb_pci_errors_disable(card); + ret = nfb_pci_errors_disable(card, use_root_port_cmds); if (ret) return ret; } @@ -181,7 +263,7 @@ int nfb_boot_reload(void *arg) reload_time_ms = 5000; } else if (boot->m10bmc_spi) { boot->m10bmc_spi->image_load[boot->num_image].load_image(boot->m10bmc_spi->sec); - reload_time_ms = 5000; + return nfb_boot_n5014_reload_rescan(master); } else if (boot->sdm && boot->sdm_boot_en) { sdm_rsu_image_update(boot->sdm, boot->num_image); } else if (boot->comp) { diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 7285b142..23465a6b 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -80,6 +80,7 @@ struct nfb_pci_device { uint16_t bridge_command; uint16_t bridge_devctl; + uint32_t bridge_root_aer_cmd; void * fdt; const char * card_name; }; From df1f032aeb65a46e360802a5f45d7afcfcad7b52 Mon Sep 17 00:00:00 2001 From: Vlastimil Kosar Date: Thu, 29 Feb 2024 19:32:13 +0100 Subject: [PATCH 240/518] drivers: [BUGFIX] Do not attach generic NFB hwmon diver on Silicom N5014 --- drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c index 43746653..5a38dd29 100644 --- a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c +++ b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c @@ -269,6 +269,14 @@ int nfb_hwmon_attach(struct nfb_device *nfb, void **priv) int i; fdt = nfb_get_fdt(nfb); + fdt_offset = fdt_path_offset(fdt, "/firmware/"); + prop = fdt_getprop(fdt, fdt_offset, "card-name", &name_len); + if(!strcmp(prop, "N5014")) { + dev_info(&nfb->pci->dev, "nfb_hwmon: Generic NFB hwmon skipped for N5014.\n"); + *priv = NULL; + return 0; + } + fdt_offset = fdt_path_offset(fdt, "/board/"); prop = fdt_getprop(fdt, fdt_offset, "board-name", &name_len); From 435f46a1537d5a9c373739e823df645e3668469d Mon Sep 17 00:00:00 2001 From: Vlastimil Kosar Date: Mon, 22 Jan 2024 19:33:12 +0100 Subject: [PATCH 241/518] drivers: [FEATURE] Add support for older kernels without spi-altera-core and regmap-spi-avmm or with disabled spi-altera Use in driver version of spi-altera-core and regmap-spi-avmm if kernel is too old to support them or if support for spi-altera is disabled. --- drivers/configure.ac | 14 +++++++++ drivers/kernel/drivers/nfb/Makefile | 6 ++++ drivers/kernel/drivers/nfb/boot/nfb-spi.c | 38 +++++++++++++---------- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index a728f456..84145a4f 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -142,6 +142,20 @@ struct spi_controller *sc; void test(void); void test(void) {spi_get_chipselect(NULL, 0);}]],[AC_DEFINE([CONFIG_HAVE_SPI_CONTROLLER], [1], [Define if kernel has struct spi_controller]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +AC_MSG_CHECKING([whether kernel has altera_spi_init_master]) +KERNEL_TRY_COMPILE([[ +#include +struct spi_controller sc; +void test(void); +void test(void) {altera_spi_init_master(&sc);}]],[AC_DEFINE([CONFIG_HAVE_SPI_INIT_MASTER], [1], [Define if kernel has altera_spi_init_master]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) + +AC_MSG_CHECKING([whether kernel has altera_spi_init_host]) +KERNEL_TRY_COMPILE([[ +#include +struct spi_controller sc; +void test(void); +void test(void) {altera_spi_init_host(&sc);}]],[AC_DEFINE([CONFIG_HAVE_SPI_INIT_HOST], [1], [Define if kernel has altera_spi_init_host]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) + AC_MSG_CHECKING([whether kernel has simplified eventfd_signal]) KERNEL_TRY_COMPILE([[ #include diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index e9d20d04..318383fc 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -16,6 +16,12 @@ nfb-objs += mi/mi.o nfb-objs += ndp/ctrl.o ndp/ctrl_ndp.o ndp/channel.o ndp/subscription.o ndp/subscriber.o ndp/ring.o ndp/char.o ndp/driver.o ndp/kndp.o nfb-objs += ndp_netdev/core.o nfb-objs += boot/flash.o boot/reload.o boot/boot.o boot/gecko.o boot/sdm.o +ifndef CONFIG_REGMAP_SPI_AVMM +nfb-objs += ../base/regmap/regmap-spi-avmm.o +endif +ifndef CONFIG_SPI_ALTERA_CORE +nfb-objs += ../spi/spi-altera-core.o +endif nfb-objs += ../mfd/intel-m10-bmc-core.o ../fpga/fpga-image-load.o ../fpga/intel-m10-bmc-sec-update.o ../hwmon/intel-m10-bmc-hwmon.o ../mfd/intel-m10-bmc-log.o boot/nfb-pmci.o boot/nfb-spi.o nfb-objs += net/driver.o net/device.o net/ethtool.o net/sysfs.o nfb-objs += qdr/qdr.o diff --git a/drivers/kernel/drivers/nfb/boot/nfb-spi.c b/drivers/kernel/drivers/nfb/boot/nfb-spi.c index 726616ba..d01db32a 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-spi.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-spi.c @@ -13,7 +13,7 @@ * Copyright (C) 2020 Intel Corporation, Inc. * Authors: * Matthew Gerlach - * + * * Copyright (C) 2024 BrnoLogic * Author(s): * Vlastimil Kosar @@ -46,7 +46,9 @@ #include #include -#include + +#include "../../spi/altera.h" +#include "../../base/regmap/regmap.h" #include "nfb-spi.h" @@ -95,7 +97,7 @@ static int indirect_bus_reg_read(void *context, unsigned int reg, dev_err(ctx->dev, "%s timed out on reg 0x%x with loops %d\n", __func__, reg, loops); return -ETIME; } - + v = nfb_comp_read32(ctx->comp, ctx->offset + INDIRECT_RD_DATA); *val = v & INDIRECT_DATA_MASK; @@ -110,7 +112,7 @@ static int indirect_bus_reg_write(void *context, unsigned int reg, nfb_comp_write32(ctx->comp, ctx->offset + INDIRECT_WR_DATA, val); nfb_comp_write32(ctx->comp, ctx->offset + INDIRECT_ADDR, (reg >> 2) | INDIRECT_WR); - + loops = 0; while ((nfb_comp_read32(ctx->comp, ctx->offset + INDIRECT_ADDR) & INDIRECT_WR) && (loops++ < INDIRECT_TIMEOUT)) @@ -120,7 +122,7 @@ static int indirect_bus_reg_write(void *context, unsigned int reg, dev_err(ctx->dev, "%s timed out on reg 0x%x with loops %d\n", __func__, reg, loops); return -ETIME; } - + return 0; } @@ -197,7 +199,7 @@ int nfb_spi_attach(struct nfb_boot *boot) struct spi_controller *host; struct altera_spi *hw; struct spi_device *spi_dev; - + int fdt_offset; int ret = 0; @@ -229,14 +231,14 @@ int nfb_spi_attach(struct nfb_boot *boot) ret = -ENOMEM; goto err_alloc_master; } - - + + host->bus_num = -1; hw = spi_controller_get_devdata(host); hw->dev = &m10bmc_spi->pd->dev; - + config_spi_host(m10bmc_spi->comp, 0, host); dev_dbg(&m10bmc_spi->pd->dev, "%s cs %u bpm 0x%x mode 0x%x\n", __func__, host->num_chipselect, host->bits_per_word_mask, @@ -251,9 +253,11 @@ int nfb_spi_attach(struct nfb_boot *boot) } hw->irq = -EINVAL; - +#ifdef CONFIG_HAVE_SPI_INIT_MASTER + altera_spi_init_master(host); +#else altera_spi_init_host(host); - +#endif ret = devm_spi_register_controller(&m10bmc_spi->pd->dev, host); if (ret) { dev_err(&m10bmc_spi->pd->dev, "%s failed to register spi host %d\n", __func__, ret); @@ -264,20 +268,20 @@ int nfb_spi_attach(struct nfb_boot *boot) board_info.max_speed_hz = 12500000; board_info.bus_num = 0; board_info.chip_select = 0; - + spi_dev = spi_new_device(host, &board_info); if (!spi_dev) { dev_err(&m10bmc_spi->pd->dev, "%s failed to create SPI device: %s\n", __func__, board_info.modalias); } - + m10bmc_spi->m10bmc.regmap = devm_regmap_init_spi_avmm(spi_dev, &m10bmc_spi_regmap_config); if (IS_ERR(m10bmc_spi->m10bmc.regmap)) { ret = PTR_ERR(m10bmc_spi->m10bmc.regmap); dev_err(&m10bmc_spi->pd->dev, "%s Failed to allocate regmap: %d\n", __func__, ret); goto err_regmap_register_avmm; } - + ret = devm_device_add_groups(&m10bmc_spi->pd->dev, nfb_m10bmc_dev_groups); if (ret) goto err_dev_addgroups; @@ -332,13 +336,13 @@ struct platform_driver nfb_intel_m10bmc_spi = { static int nfb_intel_m10_bmc_spi_probe(struct spi_device *spi) { - struct device *dev = &spi->dev; int ret = 0; - #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) && RHEL_RELEASE_CODE < 0x803 +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) && RHEL_RELEASE_CODE < 0x803 + struct device *dev = &spi->dev; ret = device_add_groups(dev, nfb_m10bmc_dev_groups); if (ret) return ret; - #endif +#endif return ret; } From edcad08f3d90a2d5eb29653f2ad1623f2eba8f62 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 26 Nov 2024 14:31:30 +0100 Subject: [PATCH 242/518] tool info: [FEATURE] add query for pci-path/pp and default-dev/dd --- tools/info/info.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/info/info.c b/tools/info/info.c index d51dbd05..d9f4be0c 100644 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -53,6 +53,10 @@ enum queries { QUERY_PORT, QUERY_CARD, QUERY_PCI, + QUERY_PCIPATH, + QUERY_PCIPATH_S, + QUERY_DEFAULT_DEV, + QUERY_DEFAULT_DEV_S, QUERY_NUMA, }; static const char * const queries[] = { @@ -66,6 +70,10 @@ static const char * const queries[] = { "port", "card", "pci", + "pci-path", + "pp", + "default-dev", + "dd", "numa" }; @@ -85,6 +93,8 @@ void usage(const char *progname, int verbose) printf(" * port Ethernet ports\n"); printf(" * card Card name\n"); printf(" * pci PCI slot\n"); + printf(" * pci-path / pp Fixed path to device\n"); + printf(" * default-dev / dd Command for setting as default device in current shell\n"); printf(" * numa NUMA node\n"); printf(" example of usage: '-q project,build,card'\n"); } @@ -187,12 +197,27 @@ int print_specific_info(struct nfb_device *dev, int query) const uint32_t *prop32; const void *fdt; + const char *prefix = ""; + char buffer[BUFFER_SIZE]; time_t build_time; fdt = nfb_get_fdt(dev); fdt_offset = fdt_path_offset(fdt, "/firmware/"); + switch (query) { + case QUERY_PCIPATH: + case QUERY_PCIPATH_S: + prefix = "/dev/nfb/by-pci-slot/"; + query = QUERY_PCI; + break; + case QUERY_DEFAULT_DEV: + case QUERY_DEFAULT_DEV_S: + prefix = "export LIBNFB_DEFAULT_DEV=/dev/nfb/by-pci-slot/"; + query = QUERY_PCI; + break; + } + /* FDT String properties */ switch (query) { case QUERY_PROJECT: prop = fdt_getprop(fdt, fdt_offset, "project-name", &len); break; @@ -210,7 +235,7 @@ int print_specific_info(struct nfb_device *dev, int query) if (len <= 0) return -1; - printf("%s", (const char *)prop); + printf("%s%s", prefix, (const char *)prop); return 0; } From bf3ce11ded78af6f24f07a2f0ec19ccb42a62908 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Nov 2024 17:40:33 +0100 Subject: [PATCH 243/518] libnetcope - dma_ctrl_ndp: [FEATURE] introduce nc_ndp_ctrl_medusa_get_max_ptr_mask --- libnfb/include/netcope/dma_ctrl_ndp.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index d7ca227e..45d43de9 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -407,6 +407,21 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl return ret; } +static inline void nc_ndp_ctrl_medusa_get_max_ptr_mask(struct nc_ndp_ctrl *ctrl, uint32_t* dp, uint32_t* hp) +{ + uint32_t orig; + + orig = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MHP); + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MHP, 0xFFFFFFFF); + *hp = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MHP) / 2; + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MHP, orig); + + orig = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MDP); + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MDP, 0xFFFFFFFF); + *dp = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MDP) / 2; + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MDP, orig); +} + static inline int _nc_ndp_ctrl_stop(struct nc_ndp_ctrl *ctrl, int force) { int ret = 0; From 458f2b8fb8060c48e219e1bba9814507a1900694 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Nov 2024 16:34:27 +0100 Subject: [PATCH 244/518] drivers - NDP: [MAINTENANCE] split tx_set_swptr to ndp_ctrl_medusa_tx_wait_for_free_desc --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 41 +++++++++++------------ 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 1e5ababd..78190dd7 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -366,11 +366,25 @@ static uint64_t ndp_ctrl_rx_get_hwptr(struct ndp_channel *channel) static uint64_t ndp_ctrl_medusa_tx_get_hwptr(struct ndp_channel *channel); +inline int ndp_ctrl_medusa_tx_wait_for_free_desc(struct ndp_channel *channel, int count) +{ + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + while (ctrl->free_desc < count) { + udelay(10); + ndp_ctrl_medusa_tx_get_hwptr(channel); + + if (unlikely(ndp_kill_signal_pending(current))) { + return 1; + } + } + return 0; +} + static void ndp_ctrl_medusa_tx_set_swptr(struct ndp_channel *channel, uint64_t ptr) { int i; int count; - int dirty = 0; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); ssize_t block_size = channel->ring.blocks[0].size; @@ -396,19 +410,11 @@ static void ndp_ctrl_medusa_tx_set_swptr(struct ndp_channel *channel, uint64_t p addr = channel->ring.blocks[*off / block_size].phys; addr += *off % block_size; } + + if (ndp_ctrl_medusa_tx_wait_for_free_desc(channel, 2)) + break; + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(addr) != last_upper_addr)) { - while (ctrl->free_desc == 0) { - udelay(10); - ndp_ctrl_medusa_tx_get_hwptr(channel); - - if (unlikely(ndp_kill_signal_pending(current))) { - dirty = 1; - break; - } - } - if (unlikely(dirty)) { - break; - } last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(addr); ctrl->c.last_upper_addr = last_upper_addr; desc[sdp] = nc_ndp_tx_desc0(addr); @@ -416,15 +422,6 @@ static void ndp_ctrl_medusa_tx_set_swptr(struct ndp_channel *channel, uint64_t p ctrl->free_desc--; } - while (ctrl->free_desc == 0) { - udelay(10); - ndp_ctrl_medusa_tx_get_hwptr(channel); - if (ndp_kill_signal_pending(current)) { - dirty = 1; - break; - } - } - desc[sdp] = nc_ndp_tx_desc2(addr, hdr->frame_len, hdr->meta, 0); sdp++; ctrl->free_desc--; From 7c8c32a6006775541a7162f6623b9b72ef940ba2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Nov 2024 13:07:37 +0100 Subject: [PATCH 245/518] drivers - NDP: [MAINTENANCE] work with ndp_channel directly --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 78190dd7..d535823f 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -1103,6 +1103,7 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i int proplen; int device_index; struct ndp_ctrl *ctrl; + struct ndp_channel *channel; struct nfb_pci_device *pci_device; struct device *dev = NULL; @@ -1132,12 +1133,13 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i ret = -ENOMEM; goto err_alloc_ctrl; } - ndp_channel_init(&ctrl->channel, id); + channel = &ctrl->channel; + ndp_channel_init(channel, id); - ctrl->channel.dev.groups = attrs; - ctrl->channel.dev.release = ndp_ctrl_destroy; - ctrl->channel.ops = ops; - ctrl->channel.ring.dev = dev; + channel->dev.groups = attrs; + channel->dev.release = ndp_ctrl_destroy; + channel->ops = ops; + channel->ring.dev = dev; ctrl->nfb = ndp->nfb; @@ -1145,7 +1147,7 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i if (ret) goto err_ctrl_open; - return &ctrl->channel; + return channel; // nc_ndp_ctrl_close(&ctrl->c); err_ctrl_open: From b22d29ac0cd0f8660d0d2dfad26c2dc3d48c8edd Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Nov 2024 16:51:10 +0100 Subject: [PATCH 246/518] drivers - NDP: [MAINTENANCE] move DEVICE_ATTR and attr groups --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 62 +++++++++++------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index d535823f..65dbfb94 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -105,37 +105,6 @@ struct ndp_packet { uint16_t len; }; -/* Attributes for sysfs - declarations */ -static DEVICE_ATTR(ring_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_channel_get_ring_size, ndp_channel_set_ring_size); - -static struct attribute *ndp_ctrl_rx_attrs[] = { - &dev_attr_ring_size.attr, - NULL, -}; - -static struct attribute *ndp_ctrl_tx_attrs[] = { - &dev_attr_ring_size.attr, - NULL, -}; - -static struct attribute_group ndp_ctrl_attr_rx_group = { - .attrs = ndp_ctrl_rx_attrs, -}; - -static struct attribute_group ndp_ctrl_attr_tx_group = { - .attrs = ndp_ctrl_tx_attrs, -}; - -static const struct attribute_group *ndp_ctrl_attr_rx_groups[] = { - &ndp_ctrl_attr_rx_group, - NULL, -}; - -static const struct attribute_group *ndp_ctrl_attr_tx_groups[] = { - &ndp_ctrl_attr_tx_group, - NULL, -}; - /// @brief Function sets `hdr` and `off` with information from `channel`. Returns header count. /// @param channel /// @param hdr buffer of headers @@ -1208,6 +1177,37 @@ static struct ndp_channel_ops ndp_ctrl_calypte_tx_ops = .get_free_space = ndp_ctrl_calypte_tx_get_free_space, }; +/* Attributes for sysfs - declarations */ +static DEVICE_ATTR(ring_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_channel_get_ring_size, ndp_channel_set_ring_size); + +static struct attribute *ndp_ctrl_rx_attrs[] = { + &dev_attr_ring_size.attr, + NULL, +}; + +static struct attribute *ndp_ctrl_tx_attrs[] = { + &dev_attr_ring_size.attr, + NULL, +}; + +static struct attribute_group ndp_ctrl_attr_rx_group = { + .attrs = ndp_ctrl_rx_attrs, +}; + +static struct attribute_group ndp_ctrl_attr_tx_group = { + .attrs = ndp_ctrl_tx_attrs, +}; + +static const struct attribute_group *ndp_ctrl_attr_rx_groups[] = { + &ndp_ctrl_attr_rx_group, + NULL, +}; + +static const struct attribute_group *ndp_ctrl_attr_tx_groups[] = { + &ndp_ctrl_attr_tx_group, + NULL, +}; + struct ndp_channel *ndp_ctrl_v2_create_rx(struct ndp *ndp, int index, int node_offset) { struct ndp_channel_id id = {.index = index, .type = NDP_CHANNEL_TYPE_RX}; From 72db5a313ca9871e07a23d5a3d4e7212b422b8b4 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 21 Nov 2024 08:02:28 +0100 Subject: [PATCH 247/518] drivers - NDP: [MAINTENANCE] split Calypte DEVICE_ATTRs --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 34 +++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 65dbfb94..d2cd796d 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -1180,6 +1180,8 @@ static struct ndp_channel_ops ndp_ctrl_calypte_tx_ops = /* Attributes for sysfs - declarations */ static DEVICE_ATTR(ring_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_channel_get_ring_size, ndp_channel_set_ring_size); +static struct device_attribute dev_attr_calypte_ring_size = __ATTR(ring_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_channel_get_ring_size, ndp_channel_set_ring_size); + static struct attribute *ndp_ctrl_rx_attrs[] = { &dev_attr_ring_size.attr, NULL, @@ -1208,6 +1210,34 @@ static const struct attribute_group *ndp_ctrl_attr_tx_groups[] = { NULL, }; +static struct attribute *ndp_ctrl_calypte_rx_attrs[] = { + &dev_attr_calypte_ring_size.attr, + NULL, +}; + +static struct attribute *ndp_ctrl_calypte_tx_attrs[] = { + &dev_attr_calypte_ring_size.attr, + NULL, +}; + +static struct attribute_group ndp_ctrl_calypte_attr_rx_group = { + .attrs = ndp_ctrl_calypte_rx_attrs, +}; + +static struct attribute_group ndp_ctrl_calypte_attr_tx_group = { + .attrs = ndp_ctrl_calypte_tx_attrs, +}; + +static const struct attribute_group *ndp_ctrl_calypte_attr_rx_groups[] = { + &ndp_ctrl_calypte_attr_rx_group, + NULL, +}; + +static const struct attribute_group *ndp_ctrl_calypte_attr_tx_groups[] = { + &ndp_ctrl_calypte_attr_tx_group, + NULL, +}; + struct ndp_channel *ndp_ctrl_v2_create_rx(struct ndp *ndp, int index, int node_offset) { struct ndp_channel_id id = {.index = index, .type = NDP_CHANNEL_TYPE_RX}; @@ -1223,13 +1253,13 @@ struct ndp_channel *ndp_ctrl_v2_create_tx(struct ndp *ndp, int index, int node_o struct ndp_channel *ndp_ctrl_v3_create_rx(struct ndp *ndp, int index, int node_offset) { struct ndp_channel_id id = {.index = index, .type = NDP_CHANNEL_TYPE_RX}; - return ndp_ctrl_create(ndp, id, ndp_ctrl_attr_rx_groups, &ndp_ctrl_calypte_rx_ops, node_offset); + return ndp_ctrl_create(ndp, id, ndp_ctrl_calypte_attr_rx_groups, &ndp_ctrl_calypte_rx_ops, node_offset); } struct ndp_channel *ndp_ctrl_v3_create_tx(struct ndp *ndp, int index, int node_offset) { struct ndp_channel_id id = {.index = index, .type = NDP_CHANNEL_TYPE_TX}; - return ndp_ctrl_create(ndp, id, ndp_ctrl_attr_tx_groups, &ndp_ctrl_calypte_tx_ops, node_offset); + return ndp_ctrl_create(ndp, id, ndp_ctrl_calypte_attr_tx_groups, &ndp_ctrl_calypte_tx_ops, node_offset); } module_param_cb(ndp_ctrl_buffer_size, &ndp_param_size_ops, &buffer_size, S_IRUGO); From 44015a0fb254184e275fb9f693ce124d70dd926f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Nov 2024 12:21:38 +0100 Subject: [PATCH 248/518] drivers - NDP: [FEATURE] introduce req_block_(count/size) in ndp_channel The ring will be created with parameters specified by req_block_*. Default values are taken from ndp_ring_size / ndp_ring_block_size. When the controller needs other values, sets the req_block_count and req_block_size before calling ndp_channel_add(). Modification of these values after ndp_channel_add() can be applied by ndp_channel_ring_resize(). --- drivers/kernel/drivers/nfb/ndp/channel.c | 6 +-- drivers/kernel/drivers/nfb/ndp/ndp.h | 6 ++- drivers/kernel/drivers/nfb/ndp/ring.c | 54 +++++++++++++++++------- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/channel.c b/drivers/kernel/drivers/nfb/ndp/channel.c index d2cbe19f..23465a3e 100644 --- a/drivers/kernel/drivers/nfb/ndp/channel.c +++ b/drivers/kernel/drivers/nfb/ndp/channel.c @@ -56,6 +56,8 @@ void ndp_channel_init(struct ndp_channel *channel, struct ndp_channel_id id) device_initialize(&channel->dev); dev_set_name(&channel->dev, channel->id.type == NDP_CHANNEL_TYPE_TX ? "tx%d" :"rx%d", channel->id.index); dev_set_drvdata(&channel->dev, channel); + + ndp_channel_ring_req_block_update_by_size(channel, ndp_ring_size); } int ndp_channel_add(struct ndp_channel *channel, struct ndp *ndp, uint32_t phandle) @@ -71,9 +73,7 @@ int ndp_channel_add(struct ndp_channel *channel, struct ndp *ndp, uint32_t phand node_offset = fdt_add_subnode(ndp->nfb->fdt, node_offset, dev_name(&channel->dev)); fdt_setprop_u32(ndp->nfb->fdt, node_offset, "ctrl", phandle); - if (ndp_ring_size < ndp_ring_block_size) - ndp_ring_block_size = ndp_ring_size; - ndp_channel_ring_create(channel, channel->ring.dev, ndp_ring_size / ndp_ring_block_size, ndp_ring_block_size); + ndp_channel_ring_create(channel, channel->ring.dev, channel->req_block_count, channel->req_block_size); ret = device_add(&channel->dev); if (ret) diff --git a/drivers/kernel/drivers/nfb/ndp/ndp.h b/drivers/kernel/drivers/nfb/ndp/ndp.h index 8f8d7d59..ebe2e9f6 100644 --- a/drivers/kernel/drivers/nfb/ndp/ndp.h +++ b/drivers/kernel/drivers/nfb/ndp/ndp.h @@ -147,6 +147,9 @@ struct ndp_channel { struct device dev; struct ndp *ndp; struct ndp_channel_id id; + + size_t req_block_count; + size_t req_block_size; }; /** @@ -211,7 +214,8 @@ extern void ndp_close(struct ndp_subscriber *app); int ndp_channel_ring_create(struct ndp_channel *channel, struct device *dev, size_t block_count, size_t block_size); void ndp_channel_ring_destroy(struct ndp_channel *channel); -int ndp_channel_ring_resize(struct ndp_channel *channel, size_t size); +int ndp_channel_ring_resize(struct ndp_channel *channel); +int ndp_channel_ring_req_block_update_by_size(struct ndp_channel *channel, unsigned long long req_size); ssize_t ndp_channel_get_discard(struct device *dev, struct device_attribute *attr, char *buf); ssize_t ndp_channel_set_discard(struct device *dev, struct device_attribute *attr, const char *buf, size_t size); diff --git a/drivers/kernel/drivers/nfb/ndp/ring.c b/drivers/kernel/drivers/nfb/ndp/ring.c index 899e5aa8..cb1ddd2d 100644 --- a/drivers/kernel/drivers/nfb/ndp/ring.c +++ b/drivers/kernel/drivers/nfb/ndp/ring.c @@ -12,9 +12,29 @@ #include "ndp.h" #include "../nfb.h" -unsigned long ndp_ring_size = 4 * 1024 * 1024; -unsigned long ndp_ring_block_size = 4 * 1024 * 1024; +#define NDP_RING_BLOCK_SIZE_DEFAULT (4 * 1024 * 1024) +#define NDP_RING_BLOCK_COUNT_DEFAULT (1) +#define NDP_RING_SIZE_DEFAULT (NDP_RING_BLOCK_SIZE_DEFAULT * NDP_RING_BLOCK_COUNT_DEFAULT) + +unsigned long ndp_ring_size = NDP_RING_SIZE_DEFAULT; +unsigned long ndp_ring_block_size = NDP_RING_BLOCK_SIZE_DEFAULT; + +int ndp_channel_ring_req_block_update_by_size(struct ndp_channel *channel, unsigned long long req_size) +{ + if (!ispow2(req_size) || req_size < PAGE_SIZE) + return -EINVAL; + + channel->req_block_size = ndp_ring_block_size; + if (req_size < channel->req_block_size) + channel->req_block_size = req_size; + + if (channel->req_block_size == 0 || !ispow2(channel->req_block_size)) + channel->req_block_size = NDP_RING_BLOCK_SIZE_DEFAULT; + + channel->req_block_count = req_size / channel->req_block_size; + return 0; +} ssize_t ndp_channel_get_ring_size(struct device *dev, struct device_attribute *attr, char *buf) { @@ -30,7 +50,11 @@ ssize_t ndp_channel_set_ring_size(struct device *dev, struct ndp_channel *channel = dev_get_drvdata(dev); value = memparse(buf, NULL); - ret = ndp_channel_ring_resize(channel, value); + + ret = ndp_channel_ring_req_block_update_by_size(channel, value); + if (ret) + return ret; + ret = ndp_channel_ring_resize(channel); if (ret) return ret; @@ -51,6 +75,9 @@ struct ndp_block *ndp_block_alloc(struct device *dev, struct ndp_block *block; struct ndp_block *blocks; + if (count == 0 || size == 0) + return NULL; + blocks = kmalloc_node(count * sizeof(struct ndp_block), GFP_KERNEL, dev_to_node(dev)); if (blocks == NULL) goto err_alloc_struct; @@ -284,20 +311,17 @@ void ndp_channel_ring_destroy(struct ndp_channel *channel) } } -int ndp_channel_ring_resize(struct ndp_channel *channel, size_t size) +int ndp_channel_ring_resize(struct ndp_channel *channel) { int ret = -EBUSY; struct device *dev; - size_t original_size; - size_t block_count; - - original_size = channel->ring.size; - - if (!ispow2(size)) - return -EINVAL; + size_t orig_block_size = 0; + size_t orig_block_count; - block_count = size / ndp_ring_block_size; + orig_block_count = channel->ring.block_count; + if (orig_block_count) + orig_block_size = channel->ring.blocks[0].size; mutex_lock(&channel->mutex); @@ -314,7 +338,7 @@ int ndp_channel_ring_resize(struct ndp_channel *channel, size_t size) ndp_channel_ring_destroy(channel); /* Create new ring */ - ret = ndp_channel_ring_create(channel, dev, block_count, ndp_ring_block_size); + ret = ndp_channel_ring_create(channel, dev, channel->req_block_count, channel->req_block_size); if (ret) goto err_ring_create; @@ -323,8 +347,8 @@ int ndp_channel_ring_resize(struct ndp_channel *channel, size_t size) return 0; err_ring_create: - if (original_size) - ndp_channel_ring_create(channel, dev, original_size / ndp_ring_block_size, ndp_ring_block_size); + if (orig_block_count) + ndp_channel_ring_create(channel, dev, orig_block_count, orig_block_size); err_nodev: err_started: mutex_unlock(&channel->mutex); From 15530c4c9006528486b617e17f117ef13f5f3b50 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Nov 2024 13:06:45 +0100 Subject: [PATCH 249/518] drivers - NDP: [FEATURE] allow to set initial_offset and unaligned buffer_size The main idea is to walk through ring for every packet and compute offsets and block indexes dynamically. This requires little more state information than one buffer index. --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 200 ++++++++++++++++++---- 1 file changed, 163 insertions(+), 37 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index d2cd796d..8d57b628 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -39,17 +39,42 @@ #define virt_to_phys_shift(x) (virt_to_phys(x) >> PAGE_SHIFT) +#define NDP_CTRL_DEFAULT_BUFFER_SIZE 4096 +#define NDP_CTRL_DEFAULT_INITIAL_OFFSET 0 + +extern unsigned long ndp_ring_size; + +static const uint32_t mps_non_first_block_max_offset = PAGE_SIZE; + typedef uint64_t ndp_offset_t; /* Size of buffer for one packet in ring */ -static int buffer_size = 4096; +static unsigned long ndp_ctrl_buffer_size = NDP_CTRL_DEFAULT_BUFFER_SIZE; +static unsigned long ndp_ctrl_initial_offset = NDP_CTRL_DEFAULT_INITIAL_OFFSET; + +struct ndp_ctrl_cfg { + uint32_t buffer_count; + uint32_t buffer_size; + uint32_t block_count; + uint32_t block_size; + uint32_t initial_offset; +}; + +/* buffer/ring pointers for walkthrough in packet-simple mode */ +struct ndp_ctrl_state_mps { + struct ndp_ctrl_cfg cfg; /* read-only after attach_ring */ + uint32_t block_offset; + uint32_t block_index; + uint32_t buffer_index; +}; struct ndp_ctrl { struct nc_ndp_ctrl c; uint32_t php; /* Pushed header pointer (converted to descriptors) */ uint32_t free_desc; + struct ndp_ctrl_state_mps mps; + struct ndp_ctrl_cfg cfg; /* applied at next attach_ring / ndp_channel_rinng_resize call */ - uint64_t mps_last_offset; uint32_t mode; /* INFO: virtual memory: shadowed */ @@ -105,6 +130,97 @@ struct ndp_packet { uint16_t len; }; +static inline void ndp_ctrl_medusa_mps_meta_first(struct ndp_ctrl_state_mps *s) +{ + s->buffer_index = 0; + s->block_offset = s->cfg.initial_offset; + s->block_index = 0; +} + +static inline void ndp_ctrl_medusa_mps_meta_init(struct ndp_ctrl_state_mps *s, uint32_t block_size, uint32_t block_count, uint32_t buffer_size, size_t buffer_count, uint32_t initial_offset) +{ + s->cfg.block_size = block_size; + s->cfg.block_count = block_count; + s->cfg.buffer_size = buffer_size; + s->cfg.buffer_count = buffer_count; + s->cfg.initial_offset = initial_offset; + ndp_ctrl_medusa_mps_meta_first(s); +} + +/* Walk through ring for every packet. + * returns -1 on ring wrap + * 1 on block increment (without ring wrap) + * 0 otherwise + */ +static inline int ndp_ctrl_medusa_mps_inc(struct ndp_ctrl_state_mps *s) +{ + s->buffer_index++; + if (s->buffer_index == s->cfg.buffer_count) { + /* wrap ring to first buffer */ + ndp_ctrl_medusa_mps_meta_first(s); + return -1; + } else { + /* move offset to next buffer */ + s->block_offset += s->cfg.buffer_size; + if (s->block_offset + s->cfg.buffer_size > s->cfg.block_size) { + /* this offset crosses the current block and therefore cannot be used; advance to next block */ + s->block_index++; + /* do not reset block_offset, ideally continue with the same value, + * but use some reasonable maximum offset in the block */ + s->block_offset %= mps_non_first_block_max_offset; + if (s->block_index == s->cfg.block_count) { + /* wrap ring block (initial offset is larger than block_size) */ + s->block_index = 0; + } + return 1; + } + } + return 0; +} + +/* Check buffer configuration and compute block_count for ring allocation. + * Optionally resize the ring with new configuration. + */ +static int ndp_ctrl_medusa_req_block_update(struct ndp_ctrl *ctrl, int do_resize, size_t buffer_size, size_t buffer_count, size_t initial_offset) +{ + int ret = 0; + /* optimization - enable shadowed mmap, which needs at least PAGE_SIZE space */ + const int min_buffer_items = PAGE_SIZE / min(NDP_CTRL_RX_DESC_SIZE, NDP_CTRL_RX_NDP_HDR_SIZE); + + struct ndp_ctrl_state_mps s; + + if (buffer_size == 0 || buffer_count < min_buffer_items) + return -EINVAL; + + /* walk through (virtual) ring to obtain parameters + * - the inc with buffer_count = 0 never wraps/resets buffer_index + * - the inc with block_count = 0 never wraps/resets block_index + */ + ndp_ctrl_medusa_mps_meta_init(&s, ctrl->channel.req_block_size, 0, buffer_size, 0, initial_offset); + while (s.buffer_index < buffer_count) { + ndp_ctrl_medusa_mps_inc(&s); + } + /* Check if last buffer(s) fits into offseted first block. + * This save one block for some configurations. */ + if (s.block_offset <= s.cfg.initial_offset) + s.block_index--; + + s.cfg.block_count = s.block_index + 1; + s.cfg.buffer_count = s.buffer_index; + + ctrl->cfg = s.cfg; + ctrl->channel.req_block_count = s.cfg.block_count; + + if (do_resize) { + ret = ndp_channel_ring_resize(&ctrl->channel); + } + + if (ret) + return ret; + + return 0; +} + /// @brief Function sets `hdr` and `off` with information from `channel`. Returns header count. /// @param channel /// @param hdr buffer of headers @@ -123,14 +239,14 @@ static void ndp_ctrl_mps_fill_rx_descs(struct ndp_ctrl *ctrl, uint64_t count) int i; uint32_t sdp = ctrl->c.sdp; struct nc_ndp_desc *desc = ctrl->desc_buffer_v + sdp; - ssize_t block_size = ctrl->channel.ring.blocks[0].size; uint64_t last_upper_addr = ctrl->c.last_upper_addr; /* TODO: Table of prepared descriptor bursts with all meta (desc. count etc) */ for (i = 0; i < count; i++) { dma_addr_t addr; - addr = ctrl->channel.ring.blocks[ctrl->mps_last_offset / block_size].phys; - addr += ctrl->mps_last_offset % block_size; + + addr = ctrl->channel.ring.blocks[ctrl->mps.block_index].phys; + addr += ctrl->mps.block_offset; if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(addr) != last_upper_addr)) { last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(addr); @@ -138,10 +254,9 @@ static void ndp_ctrl_mps_fill_rx_descs(struct ndp_ctrl *ctrl, uint64_t count) desc[i] = nc_ndp_rx_desc0(addr); continue; } - desc[i] = nc_ndp_rx_desc2(addr, buffer_size, 0); - ctrl->mps_last_offset += buffer_size; - if (ctrl->mps_last_offset >= ctrl->channel.ring.size) - ctrl->mps_last_offset = 0; + desc[i] = nc_ndp_rx_desc2(addr, ctrl->mps.cfg.buffer_size, 0); + + ndp_ctrl_medusa_mps_inc(&ctrl->mps); } ctrl->c.sdp = (sdp + count) & ctrl->c.mdp; } @@ -356,7 +471,6 @@ static void ndp_ctrl_medusa_tx_set_swptr(struct ndp_channel *channel, uint64_t p int count; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); - ssize_t block_size = channel->ring.blocks[0].size; uint64_t last_upper_addr = ctrl->c.last_upper_addr; uint32_t sdp = ctrl->c.sdp; uint32_t shp = ctrl->c.shp; @@ -376,8 +490,8 @@ static void ndp_ctrl_medusa_tx_set_swptr(struct ndp_channel *channel, uint64_t p if (ctrl->mode == NDP_CTRL_MODE_USER) { addr = *off; } else { - addr = channel->ring.blocks[*off / block_size].phys; - addr += *off % block_size; + addr = channel->ring.blocks[ctrl->mps.block_index].phys; + addr += ctrl->mps.block_offset; } if (ndp_ctrl_medusa_tx_wait_for_free_desc(channel, 2)) @@ -394,6 +508,8 @@ static void ndp_ctrl_medusa_tx_set_swptr(struct ndp_channel *channel, uint64_t p desc[sdp] = nc_ndp_tx_desc2(addr, hdr->frame_len, hdr->meta, 0); sdp++; ctrl->free_desc--; + + ndp_ctrl_medusa_mps_inc(&ctrl->mps); } /* if (unlikely(dirty)) { @@ -538,12 +654,13 @@ static int ndp_ctrl_start(struct ndp_ctrl *ctrl, struct nc_ndp_ctrl_start_params static int ndp_ctrl_medusa_start(struct ndp_channel *channel, uint64_t *hwptr) { - int ret; struct nc_ndp_ctrl_start_params sp; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + ndp_offset_t *off; + sp.update_buffer_virt = ctrl->update_buffer; sp.desc_buffer = ctrl->desc_buffer_phys; sp.hdr_buffer = ctrl->hdr_buffer_phys; @@ -555,19 +672,18 @@ static int ndp_ctrl_medusa_start(struct ndp_channel *channel, uint64_t *hwptr) if (ret) return ret; - ctrl->mps_last_offset = 0; ctrl->next_sdp = 0; ctrl->mode = NDP_CTRL_MODE_PACKET_SIMPLE; if (ctrl->mode == NDP_CTRL_MODE_PACKET_SIMPLE) { - int i; - ndp_offset_t *off; - /* Constant packet offsets in this mode */ - for (i = 0, off = ctrl->off_buffer_v; i < ctrl->desc_buffer_size / NDP_CTRL_RX_DESC_SIZE; i++, off++) { - *off = i * buffer_size; - } + off = ctrl->off_buffer_v; + + ndp_ctrl_medusa_mps_meta_first(&ctrl->mps); + do { + *(off++) = (ctrl->mps.block_index * ctrl->mps.cfg.block_size) + ctrl->mps.block_offset; + } while (ndp_ctrl_medusa_mps_inc(&ctrl->mps) != -1); } else if (ctrl->mode == NDP_CTRL_MODE_USER) { if (channel->id.type == NDP_CHANNEL_TYPE_RX) { ctrl->free_desc = ctrl->c.mhp; @@ -737,29 +853,21 @@ static int ndp_ctrl_medusa_attach_ring(struct ndp_channel *channel) struct device *dev = channel->ring.dev; - const int min_buffer_items = PAGE_SIZE / min(NDP_CTRL_RX_DESC_SIZE, NDP_CTRL_RX_NDP_HDR_SIZE); - if (channel->ring.size == 0) return -EINVAL; - if (buffer_size == 0 || !ispow2(buffer_size)) { - dev_err(ctrl->nfb->dev, "NDP queue %s: ndp_ctrl_buffer_size value must be power of two, but is %d.\n", - dev_name(&channel->dev), buffer_size); - return -EINVAL; - } - - ctrl->desc_count = channel->ring.size / buffer_size; - if (ctrl->desc_count < min_buffer_items) { - /* Can't do shadow-map for this desc/hdr ring size */ - dev_err(ctrl->nfb->dev, "NDP queue %s: descriptor buffer size must be at least %d items, but is %d.\n", - dev_name(&channel->dev), min_buffer_items, ctrl->desc_count); + /* just check already requested ring parameters */ + if (ndp_ctrl_medusa_req_block_update(ctrl, 0, ctrl->cfg.buffer_size, ctrl->cfg.buffer_count, ctrl->cfg.initial_offset)) return -EINVAL; - } - ctrl->hdr_count = ctrl->desc_count; + /* apply configuration */ + ctrl->mps.cfg = ctrl->cfg; + + ctrl->desc_count = ctrl->hdr_count = ctrl->mps.cfg.buffer_count; channel->ptrmask = ctrl->hdr_count - 1; + /* allocate update buffer */ ctrl->update_buffer = dma_alloc_coherent(dev, ALIGN(NDP_CTRL_UPDATE_SIZE, PAGE_SIZE), &ctrl->update_buffer_phys, GFP_KERNEL); if (ctrl->update_buffer == NULL) { @@ -826,7 +934,7 @@ static int ndp_ctrl_medusa_attach_ring(struct ndp_channel *channel) fdt_setprop_u64(fdt, node_offset, "off_mmap_base", ctrl->off_mmap_offset); fdt_setprop_u64(fdt, node_offset, "off_mmap_size", ctrl->off_buffer_size * 2); - fdt_setprop_u32(fdt, node_offset, "buffer_size", buffer_size); + fdt_setprop_u32(fdt, node_offset, "buffer_size", ctrl->mps.cfg.buffer_size); return 0; @@ -1064,6 +1172,9 @@ static void ndp_ctrl_destroy(struct device *dev) kfree(ctrl); } +static struct ndp_channel_ops ndp_ctrl_tx_ops; +static struct ndp_channel_ops ndp_ctrl_rx_ops; + static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_id id, const struct attribute_group **attrs, struct ndp_channel_ops *ops, int node_offset) { @@ -1076,6 +1187,9 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i struct nfb_pci_device *pci_device; struct device *dev = NULL; + size_t ndp_buffer_size; + + int is_medusa = (ops == &ndp_ctrl_rx_ops || ops == &ndp_ctrl_tx_ops); prop = fdt_getprop(ndp->nfb->fdt, node_offset, "pcie", &proplen); if (proplen >= sizeof(*prop)) { @@ -1116,6 +1230,15 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i if (ret) goto err_ctrl_open; + if (is_medusa) { + /* Set initial parameters for ring */ + ndp_buffer_size = ndp_ctrl_buffer_size == 0 ? NDP_CTRL_DEFAULT_BUFFER_SIZE : ndp_ctrl_buffer_size, + ndp_ctrl_medusa_req_block_update(ctrl, 0, + ndp_buffer_size, + ndp_ring_size / ndp_buffer_size, + (id.index + 1) * ndp_ctrl_initial_offset); + } + return channel; // nc_ndp_ctrl_close(&ctrl->c); @@ -1262,5 +1385,8 @@ struct ndp_channel *ndp_ctrl_v3_create_tx(struct ndp *ndp, int index, int node_o return ndp_ctrl_create(ndp, id, ndp_ctrl_calypte_attr_tx_groups, &ndp_ctrl_calypte_tx_ops, node_offset); } -module_param_cb(ndp_ctrl_buffer_size, &ndp_param_size_ops, &buffer_size, S_IRUGO); +module_param_cb(ndp_ctrl_buffer_size, &ndp_param_size_ops, &ndp_ctrl_buffer_size, S_IRUGO); MODULE_PARM_DESC(ndp_ctrl_buffer_size, "Size of buffer for one packet in NDP ring (max size of RX/TX packet) [4096]"); + +module_param_cb(ndp_ctrl_initial_offset, &ndp_param_size_ops, &ndp_ctrl_initial_offset, S_IRUGO); +MODULE_PARM_DESC(ndp_ctrl_initial_offset, "Offset for the first buffer (packet) in ring in bytes; will be multiplied by (channel_index + 1) [0]"); From f8411ca26229567ca952ca83623226e5a035ded7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Nov 2024 16:55:12 +0100 Subject: [PATCH 250/518] drivers - NDP: [FEATURE] add DEVICE_ATTR for ring configuration Added buffer_size, initial_offset and buffer_count attributes. Also ring_size was modified, because now has little different meaning. --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 114 +++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 8d57b628..91af587c 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -221,6 +221,109 @@ static int ndp_ctrl_medusa_req_block_update(struct ndp_ctrl *ctrl, int do_resize return 0; } +static ssize_t ndp_ctrl_get_buffer_size(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + return scnprintf(buf, PAGE_SIZE, "%u\n", ctrl->cfg.buffer_size); +} + +static ssize_t ndp_ctrl_set_buffer_size(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + int ret = -1; + unsigned long long value; + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + value = memparse(buf, NULL); + + ndp_ctrl_medusa_req_block_update(ctrl, 1, value, ctrl->cfg.buffer_count, ctrl->cfg.initial_offset); + if (ret) + return ret; + + return size; +} + +static ssize_t ndp_ctrl_get_buffer_count(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + return scnprintf(buf, PAGE_SIZE, "%u\n", ctrl->cfg.buffer_count); +} + +static ssize_t ndp_ctrl_set_buffer_count(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + int ret = -1; + unsigned long long value; + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + value = memparse(buf, NULL); + + ndp_ctrl_medusa_req_block_update(ctrl, 1, ctrl->cfg.buffer_size, value, ctrl->cfg.initial_offset); + if (ret) + return ret; + + return size; +} + +static ssize_t ndp_ctrl_get_initial_offset(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + return scnprintf(buf, PAGE_SIZE, "%u\n", ctrl->cfg.initial_offset); +} + +static ssize_t ndp_ctrl_set_initial_offset(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + int ret = -1; + unsigned long long value; + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + value = memparse(buf, NULL); + + ret = ndp_ctrl_medusa_req_block_update(ctrl, 1, ctrl->cfg.buffer_size, ctrl->cfg.buffer_count, value); + if (ret) + return ret; + + return size; +} + +static ssize_t ndp_ctrl_get_ring_size(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + return scnprintf(buf, PAGE_SIZE, "%u\n", ctrl->cfg.buffer_size * ctrl->cfg.buffer_count); +} + +static ssize_t ndp_ctrl_set_ring_size(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + int ret = -1; + unsigned long long value; + unsigned long buffer_count = 1; + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + value = memparse(buf, NULL); + + while (buffer_count * 2 <= value / ctrl->cfg.buffer_size) + buffer_count *= 2; + + ret = ndp_ctrl_medusa_req_block_update(ctrl, 1, ctrl->cfg.buffer_size, value, ctrl->cfg.initial_offset); + if (ret) + return ret; + + return size; +} + /// @brief Function sets `hdr` and `off` with information from `channel`. Returns header count. /// @param channel /// @param hdr buffer of headers @@ -1301,17 +1404,26 @@ static struct ndp_channel_ops ndp_ctrl_calypte_tx_ops = }; /* Attributes for sysfs - declarations */ -static DEVICE_ATTR(ring_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_channel_get_ring_size, ndp_channel_set_ring_size); +static DEVICE_ATTR(ring_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_ctrl_get_ring_size, ndp_ctrl_set_ring_size); +static DEVICE_ATTR(buffer_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_ctrl_get_buffer_size, ndp_ctrl_set_buffer_size); +static DEVICE_ATTR(buffer_count, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_ctrl_get_buffer_count, ndp_ctrl_set_buffer_count); +static DEVICE_ATTR(initial_offset, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_ctrl_get_initial_offset, ndp_ctrl_set_initial_offset); static struct device_attribute dev_attr_calypte_ring_size = __ATTR(ring_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_channel_get_ring_size, ndp_channel_set_ring_size); static struct attribute *ndp_ctrl_rx_attrs[] = { &dev_attr_ring_size.attr, + &dev_attr_buffer_size.attr, + &dev_attr_buffer_count.attr, + &dev_attr_initial_offset.attr, NULL, }; static struct attribute *ndp_ctrl_tx_attrs[] = { &dev_attr_ring_size.attr, + &dev_attr_buffer_size.attr, + &dev_attr_buffer_count.attr, + &dev_attr_initial_offset.attr, NULL, }; From 2a19c66859f33258e558c1c0bf95182abe279715 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 27 Nov 2024 12:11:25 +0100 Subject: [PATCH 251/518] drivers - NDP: [OPT] set default initial offset to 64B --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 91af587c..3b054307 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -40,7 +40,7 @@ #define virt_to_phys_shift(x) (virt_to_phys(x) >> PAGE_SHIFT) #define NDP_CTRL_DEFAULT_BUFFER_SIZE 4096 -#define NDP_CTRL_DEFAULT_INITIAL_OFFSET 0 +#define NDP_CTRL_DEFAULT_INITIAL_OFFSET 64 extern unsigned long ndp_ring_size; @@ -1501,4 +1501,4 @@ module_param_cb(ndp_ctrl_buffer_size, &ndp_param_size_ops, &ndp_ctrl_buffer_size MODULE_PARM_DESC(ndp_ctrl_buffer_size, "Size of buffer for one packet in NDP ring (max size of RX/TX packet) [4096]"); module_param_cb(ndp_ctrl_initial_offset, &ndp_param_size_ops, &ndp_ctrl_initial_offset, S_IRUGO); -MODULE_PARM_DESC(ndp_ctrl_initial_offset, "Offset for the first buffer (packet) in ring in bytes; will be multiplied by (channel_index + 1) [0]"); +MODULE_PARM_DESC(ndp_ctrl_initial_offset, "Offset for the first buffer (packet) in ring in bytes; will be multiplied by (channel_index + 1) [64]"); From 56d8c2aa1f72deb4d7a905016d59d8f06041267e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Nov 2024 17:41:11 +0100 Subject: [PATCH 252/518] drivers - NDP: [FIX] check for FW pointer maximum size in Medusa --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 3b054307..cf6050c5 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -105,6 +105,9 @@ struct ndp_ctrl { int desc_count; int hdr_count; + uint32_t max_hp_mask; + uint32_t max_dp_mask; + void *hdr_buffer; uint8_t hdr_buff_en_rw_map; @@ -189,7 +192,7 @@ static int ndp_ctrl_medusa_req_block_update(struct ndp_ctrl *ctrl, int do_resize struct ndp_ctrl_state_mps s; - if (buffer_size == 0 || buffer_count < min_buffer_items) + if (buffer_size == 0 || buffer_count < min_buffer_items || buffer_count > ctrl->max_dp_mask + 1) return -EINVAL; /* walk through (virtual) ring to obtain parameters @@ -1334,6 +1337,8 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i goto err_ctrl_open; if (is_medusa) { + nc_ndp_ctrl_medusa_get_max_ptr_mask(&ctrl->c, &ctrl->max_dp_mask, &ctrl->max_hp_mask); + /* Set initial parameters for ring */ ndp_buffer_size = ndp_ctrl_buffer_size == 0 ? NDP_CTRL_DEFAULT_BUFFER_SIZE : ndp_ctrl_buffer_size, ndp_ctrl_medusa_req_block_update(ctrl, 0, From ba92db4d915b84ac36710bb1a0ce80988453da26 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 20 Nov 2024 17:42:28 +0100 Subject: [PATCH 253/518] tool dma: [FEATURE] allow to set buffer_size, buffer_count and initial_offset --- tools/dma/dma.c | 56 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 271ac111..85566cc3 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -27,15 +27,19 @@ /*! Acceptable command line arguments */ /*! -d path to device file */ +/*! -B buffer size */ +/*! -C buffer count */ /*! -i RX or TX index */ /*! -r use only RX; */ /*! -t use only TX; */ /*! -R reset counters */ +/*! -S ring size */ +/*! -O initial offset*/ /*! -h print help; */ /*! -v verbose mode; */ /*! -V version */ -#define ARGUMENTS "d:i:q:rtRS:Tvh" +#define ARGUMENTS "d:i:q:rtRS:B:C:O:Tvh" enum commands { CMD_PRINT_STATUS, @@ -43,6 +47,9 @@ enum commands { CMD_COUNTER_RESET, CMD_COUNTER_READ_AND_RESET, CMD_SET_RING_SIZE, + CMD_SET_BUFFER_SIZE, + CMD_SET_BUFFER_COUNT, + CMD_SET_INITIAL_OFFSET, CMD_QUERY, }; @@ -93,7 +100,10 @@ void usage(const char *me, int verbose) printf("-R Resets packet counters (use -RR for read & reset)\n"); printf("-T Print the sum of all counters of selected queues\n" " (use -TT to print each queue separately)\n"); - printf("-S size Set kernel ring buffer size (can be with K/M/G suffix)\n"); + printf("-S ring_size Set kernel ring buffer size (can be with K/M/G suffix)\n"); + printf("-B buffer_size Set kernel buffer size (for single packet; DMA Medusa only)\n"); + printf("-C buffer_count Set kernel buffer count (replacement for ring_size; DMA Medusa only)\n"); + printf("-O initial_off Set initial offset in ring buffer (first buffer offset; DMA Medusa only)\n"); printf("-q query Get specific informations%s\n", verbose ? "" : " (-v for more info)"); if (verbose) { for (unsigned i = 0; i < NC_ARRAY_SIZE(queries); i++) { @@ -106,18 +116,18 @@ void usage(const char *me, int verbose) printf("-h Show this text\n"); } -int set_ring_size(struct nfb_device *dev, int dir, int index, const char* csize) +int set_ring_size(struct nfb_device *dev, int dir, int index, const char* csize, const char *target) { FILE *f; char path_buffer[128]; snprintf(path_buffer, sizeof(path_buffer), - "/sys/class/nfb/nfb%d/ndp/%cx%d/ring_size", - nfb_get_system_id(dev), dir == 0 ? 'r' : 't', index); + "/sys/class/nfb/nfb%d/ndp/%cx%d/%s", + nfb_get_system_id(dev), dir == 0 ? 'r' : 't', index, target); f = fopen(path_buffer, "wb"); if (f == NULL) - err(errno, "Can't set ring size"); + err(errno, "Can't set %s", target); fwrite(csize, 1, strlen(csize) + 1, f); fclose(f); return 0; @@ -519,6 +529,18 @@ int main(int argc, char *argv[]) cmd = CMD_SET_RING_SIZE; csize = optarg; break; + case 'B': + cmd = CMD_SET_BUFFER_SIZE; + csize = optarg; + break; + case 'C': + cmd = CMD_SET_BUFFER_COUNT; + csize = optarg; + break; + case 'O': + cmd = CMD_SET_INITIAL_OFFSET; + csize = optarg; + break; default: err(-EINVAL, "Unknown argument -%c", optopt); } @@ -583,7 +605,16 @@ int main(int argc, char *argv[]) sum_rx.discarded_bytes += cntr_rx.discarded_bytes; break; case CMD_SET_RING_SIZE: - set_ring_size(dev, 0, i, csize); + set_ring_size(dev, 0, i, csize, "ring_size"); + break; + case CMD_SET_BUFFER_SIZE: + set_ring_size(dev, 0, i, csize, "buffer_size"); + break; + case CMD_SET_BUFFER_COUNT: + set_ring_size(dev, 0, i, csize, "buffer_count"); + break; + case CMD_SET_INITIAL_OFFSET: + set_ring_size(dev, 0, i, csize, "initial_offset"); break; default: @@ -620,7 +651,16 @@ int main(int argc, char *argv[]) case CMD_SET_RING_SIZE: if (txq->type == QUEUE_TYPE_CALYPTE) err(errno, "TX Calypte controller does not support setting of ring buffer size."); - set_ring_size(dev, 1, i, csize); + set_ring_size(dev, 1, i, csize, "ring_size"); + break; + case CMD_SET_BUFFER_SIZE: + set_ring_size(dev, 1, i, csize, "buffer_size"); + break; + case CMD_SET_BUFFER_COUNT: + set_ring_size(dev, 1, i, csize, "buffer_count"); + break; + case CMD_SET_INITIAL_OFFSET: + set_ring_size(dev, 1, i, csize, "initial_offset"); break; default: break; From c5aa1080d19868da332b376e9b1cd31ebf67dac9 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Tue, 12 Nov 2024 11:03:50 +0100 Subject: [PATCH 254/518] perf(libnfb/calypte_tx): remove unnecessary MI write to optimize latency This applies to the TX DMA Calypte call to synchronize pointers in the userspace since writing the value of write pointer to the hardware is not necessary unless the controller needs to be shut down. --- libnfb/include/netcope/ndp_tx.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index 18d74aa5..9f27fc9f 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -316,7 +316,6 @@ static inline void _ndp_queue_tx_sync_v3_us(struct nc_ndp_queue *q) /* TODO: magic number */ if (q->u.v3.uspace_acc >= 32) { q->u.v3.uspace_acc = 0; - nfb_comp_write64(q->u.v3.comp, NDP_CTRL_REG_SDP, q->u.v3.uspace_sdp | (((uint64_t) q->u.v3.uspace_shp) << 32)); } } } From 03db323690dfe8baa5cc28499d736e92dbb88e11 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Tue, 12 Nov 2024 14:37:04 +0100 Subject: [PATCH 255/518] ci: add Dockerfile for Oracle Linux 9 --- jenkins/Jenkinsfile | 3 ++- jenkins/oraclelinux9.Dockerfile | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 jenkins/oraclelinux9.Dockerfile diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index cd83de91..51d9b938 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -1,7 +1,8 @@ def projectpath = "ndk/swbase" def osreleasevers = [ // ["centos", "centos7", "7.9.2009", "rpm"], - ["oraclelinux", "oraclelinux8", "8", "rpm"], + ["oraclelinux", "oraclelinux8", "8", "rpm"], + ["oraclelinux", "oraclelinux9", "9", "rpm"], ["ubuntu", "ubuntu", "focal", "deb"] ] def dockertarget = "default" diff --git a/jenkins/oraclelinux9.Dockerfile b/jenkins/oraclelinux9.Dockerfile new file mode 100644 index 00000000..2b3aebce --- /dev/null +++ b/jenkins/oraclelinux9.Dockerfile @@ -0,0 +1,18 @@ +ARG OSRELEASEVER=9 +ARG OSNAME=centos +FROM $OSNAME:$OSRELEASEVER as default + +RUN /usr/sbin/useradd jenkins +RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers + +RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm +RUN dnf config-manager --set-enabled ol9_codeready_builder; +RUN dnf copr enable @CESNET/dpdk-nfb + +RUN yum install -y epel-release git make gcc rpm-build autoconf automake sudo curl +RUN yum install -y libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel python3-devel pciutils-devel pciutils-libs +RUN yum install -y cmake +RUN yum install -y wget + +RUN yum clean all +RUN pip install cython From d0d103888322e829eb13809565db1aeb6d674f6e Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Wed, 27 Nov 2024 15:36:42 +0100 Subject: [PATCH 256/518] fix(pynfb/NdpQueueTx): fix argument type passed to sendmsg The zip method in Python returns "zip" type so the pkts argument of the "sendmsg" and "_sendmsg" methods has been changed to Iterable --- pynfb/nfb/libnfb.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 9f04f0a9..41f5d625 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -3,7 +3,7 @@ import time import cython from itertools import islice -from typing import Union, Optional, List, Tuple +from typing import Union, Optional, List, Tuple, Iterable from libc.stdlib cimport malloc from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int32_t @@ -809,7 +809,7 @@ cdef class NdpQueueTx(NdpQueue): 'passed_bytes': counters.sent_bytes, } - cdef _sendmsg(self, pkts: List[Tuple[bytes, bytes, int]]): # -> None: + cdef _sendmsg(self, pkts: Iterable[Tuple[bytes, bytes, int]]): # -> None: cdef int cnt cdef int icnt cdef ndp_packet ndppkt[64] @@ -859,7 +859,7 @@ cdef class NdpQueueTx(NdpQueue): self.sendmsg(zip(pkts, hdrs, flags), flush) - def sendmsg(self, pkts: List[Tuple[bytes, bytes, int]], flush: bool = True) -> None: + def sendmsg(self, pkts: Iterable[Tuple[bytes, bytes, int]], flush: bool = True) -> None: """ Send burst of messages From 8def48b3728647c26471df84c23180c5b18792dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Ko=C5=A1a=C5=99?= Date: Wed, 27 Nov 2024 20:05:07 +0100 Subject: [PATCH 257/518] build: [FIX] Add check whether kernel has ctrl member in struct spi_bitbang This check is used in the 3rd party code. Fixes build on Ubuntu 24.04 LTS with 6.8 kernel. --- drivers/configure.ac | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/configure.ac b/drivers/configure.ac index 84145a4f..c2c782f6 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -142,6 +142,13 @@ struct spi_controller *sc; void test(void); void test(void) {spi_get_chipselect(NULL, 0);}]],[AC_DEFINE([CONFIG_HAVE_SPI_CONTROLLER], [1], [Define if kernel has struct spi_controller]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +AC_MSG_CHECKING([whether kernel has ctrl in struct spi_bitbang]) +KERNEL_TRY_COMPILE([[ +#include +struct spi_bitbang sb; +void test(void); +void test(void) {sb.ctrl = NULL;}]],[AC_DEFINE([CONFIG_HAVE_SPI_BITBANG_CTRL], [1], [Define if kernel has ctrl in struct spi_bitbang]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) + AC_MSG_CHECKING([whether kernel has altera_spi_init_master]) KERNEL_TRY_COMPILE([[ #include From e8047f4fa2a775cda45d0ab8ee2ff0d34657363d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Ko=C5=A1a=C5=99?= Date: Wed, 27 Nov 2024 21:26:57 +0100 Subject: [PATCH 258/518] build: [FIX] Add specific check if ALTERA SPI is enabled in autoconf This fixes situation when kernel contains support for Altera SPI, but the support is disabled and kernel headers for Altera SPI are shipped. In this situation the previous check implementation detected support, however build of nfb driver failed in modpost stage. --- drivers/configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/configure.ac b/drivers/configure.ac index c2c782f6..eccec15d 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -154,6 +154,9 @@ KERNEL_TRY_COMPILE([[ #include struct spi_controller sc; void test(void); +#if !IS_ENABLED(CONFIG_SPI_ALTERA) +#error CONFIG_SPI_ALTERA is not enabled, failing altera_spi_init_master test explicitly +#endif void test(void) {altera_spi_init_master(&sc);}]],[AC_DEFINE([CONFIG_HAVE_SPI_INIT_MASTER], [1], [Define if kernel has altera_spi_init_master]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) AC_MSG_CHECKING([whether kernel has altera_spi_init_host]) @@ -161,6 +164,9 @@ KERNEL_TRY_COMPILE([[ #include struct spi_controller sc; void test(void); +#if !IS_ENABLED(CONFIG_SPI_ALTERA) +#error CONFIG_SPI_ALTERA is not enabled, failing altera_spi_init_host test explicitly +#endif void test(void) {altera_spi_init_host(&sc);}]],[AC_DEFINE([CONFIG_HAVE_SPI_INIT_HOST], [1], [Define if kernel has altera_spi_init_host]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) AC_MSG_CHECKING([whether kernel has simplified eventfd_signal]) From 9a7f156de8e70cbc0d3910a9290b8d6df3be6389 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 2 Dec 2024 14:28:33 +0100 Subject: [PATCH 259/518] fix(tool - bus): print correct address --- tools/bus/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bus/bus.c b/tools/bus/bus.c index e60bf74c..817c44ee 100644 --- a/tools/bus/bus.c +++ b/tools/bus/bus.c @@ -274,7 +274,7 @@ int main(int argc, char *argv[]) printf("%c", spacer); if (show_address && spacer == '\n') - printf("%08x: ", offset + i * 4); + printf("%08x: ", offset + i); memcpy(&data32, data + i, 4); printf("%08x", data32); From 01abd1679511e48145b1708ec23a9b29a2f460a4 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 3 Dec 2024 09:35:34 +0100 Subject: [PATCH 260/518] fix(libnfb - rxmac): use correct value for pkts in etherStats This should be "Total number of packets received (including bad packets)" --- libnfb/include/netcope/rxmac.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libnfb/include/netcope/rxmac.h b/libnfb/include/netcope/rxmac.h index dc8e6fca..8d5239fa 100644 --- a/libnfb/include/netcope/rxmac.h +++ b/libnfb/include/netcope/rxmac.h @@ -112,9 +112,9 @@ static inline void nc_rxmac_set_error_mask(struct nc_rxmac *mac, uns #define RXMAC_REG_CNT_ES_CRC_ERR_LO 0x0100 #define RXMAC_REG_CNT_ES_CRC_ERR_HI 0x0138 -/* Total received packets over set MTU (etherStatsPkts) */ -#define RXMAC_REG_CNT_ES_PKTS_LO 0x0104 -#define RXMAC_REG_CNT_ES_PKTS_HI 0x013C +/* Total received packets over set MTU */ +#define RXMAC_REG_CNT_ES_OVERSIZE_LO 0x0104 +#define RXMAC_REG_CNT_ES_OVERSIZE_HI 0x013C /* Total received packets below set minimal length */ #define RXMAC_REG_CNT_ES_UNDERSIZE_LO 0x0108 @@ -313,13 +313,19 @@ static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_c { struct nfb_comp *comp = nfb_user_to_comp(mac); + unsigned long long cnt_total = 0; + if (!nfb_comp_lock(comp, RXMAC_COMP_LOCK)) return -EAGAIN; nfb_comp_write32(comp, RXMAC_REG_CONTROL, RXMAC_CMD_STROBE); + if (c || s) { + cnt_total = RXMAC_READ_CNT(comp, PACKETS); + } + if (c) { - c->cnt_total = RXMAC_READ_CNT(comp, PACKETS); + c->cnt_total = cnt_total; c->cnt_received = RXMAC_READ_CNT(comp, RECEIVED); c->cnt_overflowed = RXMAC_READ_CNT(comp, OVERFLOW); c->cnt_erroneous = RXMAC_READ_CNT(comp, DISCARDED) - c->cnt_overflowed; @@ -328,7 +334,7 @@ static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_c if (s) { s->octets = RXMAC_READ_CNT(comp, ES_OCTETS); - s->pkts = RXMAC_READ_CNT(comp, ES_PKTS); + s->pkts = cnt_total; s->broadcastPkts = RXMAC_READ_CNT(comp, ES_BCAST); s->multicastPkts = RXMAC_READ_CNT(comp, ES_MCAST); s->CRCAlignErrors = RXMAC_READ_CNT(comp, ES_CRC_ERR); From 6b66e6ba5fa37015eb92b202ca97f01736b22754 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 3 Dec 2024 09:35:39 +0100 Subject: [PATCH 261/518] feat(libnfb - rxmac, tool - eth): add underMinPkts and overMaxPkts to etherstats --- libnfb/include/netcope/rxmac.h | 7 ++++++- tools/eth/rxmac.c | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libnfb/include/netcope/rxmac.h b/libnfb/include/netcope/rxmac.h index 8d5239fa..1973921c 100644 --- a/libnfb/include/netcope/rxmac.h +++ b/libnfb/include/netcope/rxmac.h @@ -66,6 +66,8 @@ struct nc_rxmac_etherstats { unsigned long long pkts256to511Octets; /*!< Total number of received packets that were between 256 and 511 bytes long */ unsigned long long pkts512to1023Octets; /*!< Total number of received packets that were between 512 and 1023 bytes long */ unsigned long long pkts1024to1518Octets; /*!< Total number of received packets that were between 1024 and 1518 bytes long */ + unsigned long long underMinPkts; /*!< Total number of received packets that were shorter than configured minimum */ + unsigned long long overMaxPkts; /*!< Total number of received packets that were longer than configured maximum */ }; struct nc_rxmac_status { @@ -341,8 +343,11 @@ static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_c if (mac->has_counter_below_64) { s->undersizePkts = RXMAC_READ_CNT(comp, ES_FRAMES_BELOW_64); } else { - s->undersizePkts = RXMAC_READ_CNT(comp, ES_UNDERSIZE); + s->undersizePkts = 0; } + + s->underMinPkts = RXMAC_READ_CNT(comp, ES_UNDERSIZE); + s->overMaxPkts = RXMAC_READ_CNT(comp, ES_OVERSIZE); s->oversizePkts = RXMAC_READ_CNT(comp, ES_FRAMES_OVER_1518); s->fragments = RXMAC_READ_CNT(comp, ES_FRAGMENTS); s->jabbers = RXMAC_READ_CNT(comp, ES_JABBERS); diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index 3d8f2f17..4a0b29f4 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -96,7 +96,6 @@ void rxmac_print_ether_stats(struct nc_rxmac *rxmac) } printf("---------------------------- RXMAC etherStatsTable ----\n"); -// printf("etherStatsDropEvents : %llu\n") printf("etherStatsOctets : %llu\n", s.octets); printf("etherStatsPkts : %llu\n", s.pkts); printf("etherStatsBroadcastPkts : %llu\n", s.broadcastPkts); @@ -104,16 +103,16 @@ void rxmac_print_ether_stats(struct nc_rxmac *rxmac) printf("etherStatsCRCAlignErrors : %llu\n", s.CRCAlignErrors); printf("etherStatsUndersizePkts : %llu\n", s.undersizePkts); printf("etherStatsOversizePkts : %llu\n", s.oversizePkts); -// printf("etherStatsOversizePkts : %llu\n"); printf("etherStatsFragments : %llu\n", s.fragments); printf("etherStatsJabbers : %llu\n", s.jabbers); -// printf("etherStatsCollisions : %llu\n"); printf("etherStatsPkts64Octets : %llu\n", s.pkts64Octets); printf("etherStatsPkts65to127Octets : %llu\n", s.pkts65to127Octets); printf("etherStatsPkts128to255Octets : %llu\n", s.pkts128to255Octets); printf("etherStatsPkts256to511Octets : %llu\n", s.pkts256to511Octets); printf("etherStatsPkts512to1023Octets : %llu\n", s.pkts512to1023Octets); printf("etherStatsPkts1024to1518Octets: %llu\n", s.pkts1024to1518Octets); + printf("underMinPkts : %llu\n", s.underMinPkts); + printf("overMaxPkts : %llu\n", s.overMaxPkts); } int clear_mac_addresses(struct nc_rxmac *rxmac) From e6d99b8df0ac04883c73d01a381b703cbe6d3c0c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 3 Dec 2024 09:35:41 +0100 Subject: [PATCH 262/518] feat(tool - eth): allow user to set RxMAC error mask with parameter -m --- tools/eth/eth.h | 2 +- tools/eth/main.c | 5 ++--- tools/eth/rxmac.c | 20 ++++++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/eth/eth.h b/tools/eth/eth.h index b2872403..2e1d3678 100644 --- a/tools/eth/eth.h +++ b/tools/eth/eth.h @@ -58,7 +58,7 @@ enum commands { CMD_USAGE, CMD_ENABLE, CMD_RESET, - CMD_SET_MASK, + CMD_SET_ERROR_MASK, CMD_SET_PMA_TYPE, CMD_SET_PMA_FEATURE, CMD_SET_MAX_LENGTH, diff --git a/tools/eth/main.c b/tools/eth/main.c index 6218e037..293786b9 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -45,7 +45,7 @@ void usage(const char *progname, int verbose) printf("-S Show etherStats counters\n"); printf("-l length Minimal allowed frame length\n"); printf("-L length Maximal allowed frame length\n"); -/* printf("-m mask Set error mask 0-31\n"); */ + printf("-m mask Set RXMAC error bitmask value (integer; use -v to view current configuration)\n"); printf("-c type Set PMA type/mode by name or enable/disable feature (+feat/-feat)\n"); printf("-p repeater_cfg Set transmit data source%s\n", verbose ? "" : " (-hv for more info)"); if (verbose) { @@ -212,10 +212,9 @@ int main(int argc, char *argv[]) p.param < 0 || p.param > 31) { errx(EXIT_FAILURE, "Wrong error mask."); } - p.command = CMD_SET_MASK; + p.command = CMD_SET_ERROR_MASK; cmds++; break; - case 'M': switch (tolower(optarg[0])) { case 's': p.command = CMD_SHOW_MACS; break; diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index 4a0b29f4..5c724bc1 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -55,14 +55,15 @@ void rxmac_print_status(struct nc_rxmac *rxmac, struct eth_params *p) return; printf("------------------------------ RXMAC Configuration ----\n"); - printf("Frame error from MII [1] : %s", (s.error_mask & 0x00000001) ? "enabled\n" : "disabled\n"); - printf("CRC check [2] : %s", (s.error_mask & 0x00000002) ? "enabled\n" : "disabled\n"); - printf("Minimum frame length [4] : %s\n" - "* length : %d B\n", + printf("Error mask register : 0x%02x\n", s.error_mask); + printf(" * Frame error from MII [0]: %s\n", (s.error_mask & 0x00000001) ? "enabled" : "disabled"); + printf(" * CRC check [1]: %s\n", (s.error_mask & 0x00000002) ? "enabled" : "disabled"); + printf(" * Minimum frame length [2]: %s\n" + " * length : %d B\n", (s.error_mask & 0x00000004) ? "enabled" : "disabled", s.frame_length_min); - printf("MTU frame length [8] : %s\n" - "* length : %d B", + printf(" * MTU frame length [3]: %s\n" + " * length : %d B", (s.error_mask & 0x00000008) ? "enabled" : "disabled", s.frame_length_max); @@ -78,8 +79,8 @@ void rxmac_print_status(struct nc_rxmac *rxmac, struct eth_params *p) case RXMAC_MAC_FILTER_TABLE_BCAST: text = "Filter by MAC address table, allow broadcast"; break; case RXMAC_MAC_FILTER_TABLE_BCAST_MCAST:text = "Filter by MAC address table, allow broadcast + multicast"; break; } - printf("MAC address check [16] : %s\n" - "* mode : %s\n", + printf(" * MAC address check [4]: %s\n" + " * mode : %s\n", (s.error_mask & 0x00000010) ? "enabled" : "disabled", text); printf("MAC address table size : %d\n", s.mac_addr_count); } @@ -237,6 +238,9 @@ int rxmac_execute_operation(struct nc_rxmac *rxmac, struct eth_params *p) nc_rxmac_set_frame_length(rxmac, p->param, p->command == CMD_SET_MAX_LENGTH ? RXMAC_FRAME_LENGTH_MAX : RXMAC_FRAME_LENGTH_MIN); break; + case CMD_SET_ERROR_MASK: + nc_rxmac_set_error_mask(rxmac, p->param); + break; case CMD_SHOW_MACS: ret = show_mac_addresses(rxmac); break; From 5925f3ad3e639a9c6fc76acf0a9de76fe49caaf7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 14 Oct 2024 15:53:27 +0200 Subject: [PATCH 263/518] fix(libnetcope - ndp): count queues in no-driver mode This fixes DPDK simulation, which doesn't uses the kernel driver. --- libnfb/include/netcope/ndp_core.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libnfb/include/netcope/ndp_core.h b/libnfb/include/netcope/ndp_core.h index 9fc4d14e..e9ca9578 100644 --- a/libnfb/include/netcope/ndp_core.h +++ b/libnfb/include/netcope/ndp_core.h @@ -9,6 +9,8 @@ #include #include +#include +#include void *nfb_nalloc(int numa_node, size_t size) { @@ -244,12 +246,24 @@ static inline int fdt_get_subnode_count(const void *fdt, const char *path) #ifndef __KERNEL__ int ndp_get_rx_queue_count(const struct nfb_device *dev) { - return fdt_get_subnode_count(dev->fdt, "/drivers/ndp/rx_queues"); + if (fdt_path_offset(dev->fdt, "/driver/ndp/") >= 0) { + return fdt_get_subnode_count(dev->fdt, "/drivers/ndp/rx_queues"); + } else { + return + nfb_comp_count(dev, COMP_NETCOPE_RXQUEUE_NDP) + + nfb_comp_count(dev, COMP_NETCOPE_RXQUEUE_CALYPTE); + } } int ndp_get_tx_queue_count(const struct nfb_device *dev) { - return fdt_get_subnode_count(dev->fdt, "/drivers/ndp/tx_queues"); + if (fdt_path_offset(dev->fdt, "/driver/ndp/") >= 0) { + return fdt_get_subnode_count(dev->fdt, "/drivers/ndp/tx_queues"); + } else { + return + nfb_comp_count(dev, COMP_NETCOPE_TXQUEUE_NDP) + + nfb_comp_count(dev, COMP_NETCOPE_TXQUEUE_CALYPTE); + } } int ndp_queue_is_available(const struct nfb_device *dev, unsigned index, int dir) From 94e150a9cbbf69451aed8167bf806059631a4f9a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 17 Dec 2024 14:34:03 +0100 Subject: [PATCH 264/518] docs: add module dependency loading before insmod command in README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6095e82a..91c5dc73 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ For other operating systems, the installation procedure may be slightly differen 6. Load Linux driver manually. + `sudo modprobe spi-altera-core regmap-spi-avmm` + `sudo insmod drivers/kernel/drivers/nfb/nfb.ko` From 31a8457b04c7fa2931216f40490c91ef816a9093 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 11 Dec 2024 13:01:13 +0100 Subject: [PATCH 265/518] feat(build): use TGZ packaging as fallback --- CMakeLists.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd5b4633..aaefeaa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,9 @@ set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "Main") #check_function_exists(cmake_host_system_information HAVE_HSI) #cmake_host_system_information(RESULT DISTRIB_ID_LIKE QUERY DISTRIB_ID_LIKE) + +set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/") + if (EXISTS "/etc/debian_version") set(PLATFORM "Debian") set(CPACK_GENERATOR "DEB" ) @@ -25,8 +28,12 @@ elseif (EXISTS "/etc/centos-release" OR EXISTS "/etc/sl-release" OR EXISTS "/etc set(PLATFORM "Centos") set(CPACK_GENERATOR "RPM") else () - message(WARNING "Failed to determine platform, cannot build package") - set(CPACK_GENERATOR "Invalid" ) + message(WARNING "Failed to determine platform, using TGZ for packaging") + set(CPACK_GENERATOR "TGZ") + set(CPACK_ARCHIVE_COMPONENT_INSTALL 1) + + set(CPACK_SET_DESTDIR "ON") + unset(CPACK_PACKAGING_INSTALL_PREFIX) endif () set(PACKAGE_NAME "${PROJECT_NAME}") @@ -80,8 +87,6 @@ set(CPACK_PACKAGE_CONTACT "spinler@cesnet.cz") set(CPACK_PACKAGE_RELOCATABLE OFF) set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_LIST_DIR}/package/description.txt") -set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/") - # RPM (CentOS) package settings set(CPACK_RPM_FILE_NAME RPM-DEFAULT) set(CPACK_RPM_Main_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") From dad566914c63822bf010780349a88a8cf2b88449 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 Jan 2025 08:01:38 +0100 Subject: [PATCH 266/518] bump version to 6.25.0 --- Changelog | 14 ++++++++++++++ VERSION | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 057e34f0..59bf5dfb 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,17 @@ +* Tue Jan 7 2025 Martin Spinler - 6.25.0-1 +- [FEATURE] drivers: add support for newer kernels +- [FEATURE] drivers: add support for Silicom N5014 card +- [FEATURE] nfb-info: add query for pci-path/pp and default-dev/dd +- [FEATURE] nfb-dma: allow to set buffer_size, buffer_count and initial_offset +- [FEATURE] nfb-eth: allow user to set RxMAC error mask with parameter -m +- [FEATURE] libnfb/nfb-eth: add underMinPkts and overMaxPkts to etherstats +- [FIX] libnfb: use correct value for pkts in RxMAC etherStats +- [FIX] libnfb: count queues in no-driver mode +- [FIX] pynfb: fix argument type passed to sendmsg +- [FIX] drivers: check for FW pointer maximum size in DMA Medusa +- [OPT] drivers: set default initial offset to 64B for DMA Medusa +- [OPT] latency optimalitazion for DMA Calypte controllers + * Wed Nov 13 2024 Martin Spinler - 6.24.0-1 - [FEATURE] drivers: add support for Terasic A2700 card - [FEATURE] drivers: check subdevices by card_name (and DSN) in all PCI endpoint FDTs diff --git a/VERSION b/VERSION index 2496b04b..961b1c8e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.24.0 +6.25.0 From 5258c1957a17bcb2e80e59c8e245f700510ae393 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 Jan 2025 13:25:53 +0100 Subject: [PATCH 267/518] refactor(libnfb-ext-grpc)!: rename rpcs and messages --- ext/libnfb_ext_grpc/CMakeLists.txt | 18 +- ext/libnfb_ext_grpc/client.cc | 274 ++++++++++++++++++ ext/libnfb_ext_grpc/nfb.proto | 58 ++++ ext/libnfb_ext_grpc/nfb_grpc.proto | 39 --- ext/libnfb_ext_grpc/nfb_grpc_client.cc | 227 --------------- .../{nfb_grpc_server.cc => server.cc} | 53 ++-- 6 files changed, 366 insertions(+), 303 deletions(-) create mode 100644 ext/libnfb_ext_grpc/client.cc create mode 100644 ext/libnfb_ext_grpc/nfb.proto delete mode 100644 ext/libnfb_ext_grpc/nfb_grpc.proto delete mode 100644 ext/libnfb_ext_grpc/nfb_grpc_client.cc rename ext/libnfb_ext_grpc/{nfb_grpc_server.cc => server.cc} (69%) diff --git a/ext/libnfb_ext_grpc/CMakeLists.txt b/ext/libnfb_ext_grpc/CMakeLists.txt index 706a2134..11cbb6b5 100644 --- a/ext/libnfb_ext_grpc/CMakeLists.txt +++ b/ext/libnfb_ext_grpc/CMakeLists.txt @@ -15,10 +15,10 @@ include(GNUInstallDirs) find_package(Protobuf CONFIG) find_package(gRPC QUIET) -set(PROTO_FILES nfb_grpc.proto) +set(PROTO_FILES nfb.proto) -add_library(nfb-ext-grpc SHARED nfb_grpc_client.cc) -add_executable(nfb-grpc-server nfb_grpc_server.cc) +add_library(nfb-ext-grpc SHARED client.cc) +add_executable(nfb-grpc-server server.cc) if (${gRPC_FOUND}) @@ -45,10 +45,10 @@ else() get_filename_component(nfb_proto ${PROTO_FILES} ABSOLUTE) get_filename_component(nfb_proto_path "${nfb_proto}" PATH) - set(nfb_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/nfb_grpc.pb.cc") - set(nfb_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/nfb_grpc.pb.h") - set(nfb_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/nfb_grpc.grpc.pb.cc") - set(nfb_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/nfb_grpc.grpc.pb.h") + set(nfb_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/nfb.pb.cc") + set(nfb_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/nfb.pb.h") + set(nfb_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/nfb.grpc.pb.cc") + set(nfb_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/nfb.grpc.pb.h") add_custom_command( OUTPUT "${nfb_proto_srcs}" "${nfb_proto_hdrs}" "${nfb_grpc_srcs}" "${nfb_grpc_hdrs}" @@ -71,7 +71,7 @@ target_sources(nfb-ext-grpc PRIVATE ${PROTO_OUT_FILES}) target_sources(nfb-grpc-server PRIVATE ${PROTO_OUT_FILES}) target_link_libraries(nfb-ext-grpc ${Protobuf_LIBRARIES} ${gRPC_LIB_PREFIX}grpc++ nfb fdt) -target_link_libraries(nfb-grpc-server ${Protobuf_LIBRARIES} ${gRPC_LIB_PREFIX}grpc++ nfb) +target_link_libraries(nfb-grpc-server ${Protobuf_LIBRARIES} ${gRPC_LIB_PREFIX}grpc++ nfb fdt) set_target_properties(nfb-ext-grpc PROPERTIES OUTPUT_NAME nfb-ext-grpc @@ -85,7 +85,7 @@ install(TARGETS nfb-ext-grpc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nfb/ext/protobuf/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nfb/ext/protobuf/v1/ ) install(TARGETS nfb-grpc-server diff --git a/ext/libnfb_ext_grpc/client.cc b/ext/libnfb_ext_grpc/client.cc new file mode 100644 index 00000000..bb1bcdbc --- /dev/null +++ b/ext/libnfb_ext_grpc/client.cc @@ -0,0 +1,274 @@ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +extern "C" { +#include +} + +#include +#include + +using grpc::Channel; +using grpc::ClientContext; +using grpc::ClientReader; +using grpc::ClientReaderWriter; +using grpc::ClientWriter; +using grpc::Status; + +using google::protobuf::Empty; + +using nfb::ext::protobuf::v1::Nfb; +using nfb::ext::protobuf::v1::FdtResponse; +using nfb::ext::protobuf::v1::ReadCompRequest; +using nfb::ext::protobuf::v1::WriteCompRequest; +using nfb::ext::protobuf::v1::ReadCompResponse; +using nfb::ext::protobuf::v1::WriteCompResponse; + + +class NfbClient +{ + void *m_fdt; + std::string m_path; + +public: + NfbClient(std::string path, std::shared_ptr channel) : + stub_(Nfb::NewStub(channel)), + m_fdt(NULL), + m_path(path) + { + } + + void *get_fdt() + { + if (m_fdt) + return m_fdt; + + static const int EXTRA_LEN = 16384; + int node; + size_t len; + Empty fdt_req; + FdtResponse fdt; + + ClientContext context; + Status status = stub_->GetFdt(&context, fdt_req, &fdt); + + if (!status.ok()) { + throw std::runtime_error("gRPC client: GetFdt failed"); + } + + len = fdt.fdt().length(); + + m_fdt = malloc(len + EXTRA_LEN); + if (m_fdt == NULL) + throw std::bad_alloc(); + + memcpy(m_fdt, fdt.fdt().c_str(), len); + fdt_set_totalsize(m_fdt, len + EXTRA_LEN); + + /* Create node with extension metadata */ + node = fdt_path_offset(m_fdt, "/drivers"); + if (node < 0) { + node = fdt_path_offset(m_fdt, "/"); + node = fdt_add_subnode(m_fdt, node, "drivers"); + } + + node = fdt_add_subnode(m_fdt, node, "libnfb-ext"); + fdt_setprop_string(m_fdt, node, "devname", m_path.c_str()); + + return m_fdt; + } + + std::unique_ptr stub_; +}; + +class NfbBus +{ + int comp_node; + off_t m_base; + NfbClient *m_dev; + + std::string m_comp_path; +public: + + NfbBus(NfbClient *dev, int bus_node, int comp_node) : + m_dev(dev) + { + void *fdt; + static const int MAX_PATH_LEN = 512; + char path[MAX_PATH_LEN]; + int proplen; + const fdt32_t *prop; + + fdt = dev->get_fdt(); + prop = (fdt32_t*) fdt_getprop(fdt, comp_node, "reg", &proplen); + if (proplen != sizeof(*prop) * 2) { + throw std::length_error("wrong size of reg property"); + } + m_base = fdt32_to_cpu(prop[0]); + + if (fdt_get_path(fdt, comp_node, path, MAX_PATH_LEN) != 0) { + throw std::length_error("DT Path is over maximum length"); + } + m_comp_path = std::string(path); + } + + ssize_t comp_read(void *buffer, int nbyte, int offset) + { + ReadCompRequest req; + ReadCompResponse resp; + + req.set_path(m_comp_path); + req.set_nbyte(nbyte); + req.set_offset(offset - m_base); + + ClientContext context; + Status status = m_dev->stub_->ReadComp(&context, req, &resp); + + if (!status.ok()) { + return -1; + } + + memcpy(buffer, resp.data().c_str(), resp.data().length()); + return resp.data().length(); + } + + ssize_t comp_write(const void *buffer, int nbyte, int offset) { + WriteCompRequest req; + WriteCompResponse resp; + + req.set_path(m_comp_path); + req.set_nbyte(nbyte); + req.set_offset(offset - m_base); + req.set_data(std::string((const char*)buffer, nbyte)); + + ClientContext context; + Status status = m_dev->stub_->WriteComp(&context, req, &resp); + + if (!status.ok()) { + return -1; + } + + return nbyte; + } +}; + + +extern "C" { + + +static const char *nfb_grpc_prefix = "grpc:"; + +static int nfb_grpc_open(const char *devname, int oflag, void **priv, void **fdt) +{ + NfbClient *nfb; + + devname += strlen(nfb_grpc_prefix); + try { + nfb = new NfbClient( + devname, + grpc::CreateChannel( + devname, + grpc::InsecureChannelCredentials() + ) + ); + } catch(...) { + return -ENODEV; + } + + try { + *fdt = nfb->get_fdt(); + } catch(...) { + delete nfb; + return -ENODEV; + } + + *priv = nfb; + return 0; +} + +static void nfb_grpc_close(void *dev_priv) +{ + NfbClient *nfb = (NfbClient *)dev_priv; + delete nfb; +} + +static ssize_t nfb_bus_grpc_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) +{ + NfbBus *bus = (NfbBus *) bus_priv; + return bus->comp_read(buf, nbyte, offset); +} + +static ssize_t nfb_bus_grpc_write(void *bus_priv, const void *buf, size_t nbyte, off_t offset) +{ + NfbBus *bus = (NfbBus *) bus_priv; + return bus->comp_write(buf, nbyte, offset); +} + +static int nfb_grpc_bus_open(void *dev_priv, int bus_node, int comp_node, void ** bus_priv, struct libnfb_bus_ext_ops* ops) +{ + NfbClient* dev = (NfbClient *) dev_priv; + NfbBus *bus; + try { + bus = new NfbBus(dev, bus_node, comp_node); + } catch (...) { + return -EBADF; + } + + ops->read = nfb_bus_grpc_read; + ops->write = nfb_bus_grpc_write; + *bus_priv = bus; + return 0; +} + +static void nfb_grpc_bus_close(void *bus_priv) +{ + NfbBus *bus = (NfbBus *) bus_priv; + delete bus; +} + +static int nfb_grpc_comp_lock(const struct nfb_comp *comp, uint32_t features) +{ + /* TODO */ + return 1; +} + +static void nfb_grpc_comp_unlock(const struct nfb_comp *comp, uint32_t features) +{ + /* TODO */ +} + +struct libnfb_ext_abi_version libnfb_ext_abi_version = libnfb_ext_abi_version_current; + +static struct libnfb_ext_ops nfb_grpc_ops = { + .open = nfb_grpc_open, + .close = nfb_grpc_close, + .bus_open_mi = nfb_grpc_bus_open, + .bus_close_mi = nfb_grpc_bus_close, + .comp_lock = nfb_grpc_comp_lock, + .comp_unlock = nfb_grpc_comp_unlock, +}; + +int libnfb_ext_get_ops(const char *devname, struct libnfb_ext_ops *ops) +{ + if (strncmp(devname, nfb_grpc_prefix, strlen(nfb_grpc_prefix)) == 0) { + *ops = nfb_grpc_ops; + return 1; + } else { + return 0; + } +} + +} diff --git a/ext/libnfb_ext_grpc/nfb.proto b/ext/libnfb_ext_grpc/nfb.proto new file mode 100644 index 00000000..b3d46a55 --- /dev/null +++ b/ext/libnfb_ext_grpc/nfb.proto @@ -0,0 +1,58 @@ +syntax = "proto3"; + +import "google/protobuf/empty.proto"; + +package nfb.ext.protobuf.v1; + +// Extension for the libnfb +service Nfb { + // Obtain FDT from the device + rpc GetFdt(google.protobuf.Empty) returns (FdtResponse) {} + // Read data from a component + rpc ReadComp(ReadCompRequest) returns (ReadCompResponse) {} + // Write data to a component + rpc WriteComp(WriteCompRequest) returns (WriteCompResponse) {} +} + +// Initial request for the FDT +// Initial response with the FDT +message FdtResponse { + // Raw Flattened Device Tree + bytes fdt = 1; +} + +// Component data read request +message ReadCompRequest { + // FDT path of the accessed component + string path = 1; + // Number of bytes to read + int32 nbyte = 2; + // Starting offset relative to base address of the component + int32 offset = 3; +} + +// Component data read response +message ReadCompResponse { + // Status of the read operation + int32 status = 1; + // Data readen from the component + bytes data = 2; +} + +// Component data write request +message WriteCompRequest { + // FDT path of the accessed component + string path = 1; + // Number of bytes to write + int32 nbyte = 2; + // Starting offset relative to base address of the component + int32 offset = 3; + // Data to be writen into the component + bytes data = 4; +} + +// Component data write response +message WriteCompResponse { + // Status of the write operation + int32 status = 1; +} diff --git a/ext/libnfb_ext_grpc/nfb_grpc.proto b/ext/libnfb_ext_grpc/nfb_grpc.proto deleted file mode 100644 index c0849425..00000000 --- a/ext/libnfb_ext_grpc/nfb_grpc.proto +++ /dev/null @@ -1,39 +0,0 @@ -syntax = "proto3"; - -package nfb_grpc; - -service Nfb { - rpc Nfb_fdt_get(nfb_rpc_device) returns (nfb_fdt) {} - rpc Nfb_comp_read(nfb_read_req) returns (nfb_read_resp) {} - rpc Nfb_comp_write(nfb_write_req) returns (nfb_write_resp) {} -} - -message nfb_rpc_device { - string path = 1; -} - -message nfb_fdt { - bytes fdt = 1; -} - -message nfb_read_req { - int32 fdt_offset = 1; - int32 nbyte = 2; - int32 offset = 3; -} - -message nfb_read_resp { - int32 status = 1; - bytes data = 2; -} - -message nfb_write_req { - int32 fdt_offset = 1; - int32 nbyte = 2; - int32 offset = 3; - bytes data = 4; -} - -message nfb_write_resp { - int32 status = 1; -} diff --git a/ext/libnfb_ext_grpc/nfb_grpc_client.cc b/ext/libnfb_ext_grpc/nfb_grpc_client.cc deleted file mode 100644 index 7d95b623..00000000 --- a/ext/libnfb_ext_grpc/nfb_grpc_client.cc +++ /dev/null @@ -1,227 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -extern "C" { -#include -} - -#include -#include - -using grpc::Channel; -using grpc::ClientContext; -using grpc::ClientReader; -using grpc::ClientReaderWriter; -using grpc::ClientWriter; -using grpc::Status; - -using nfb_grpc::Nfb; -using nfb_grpc::nfb_fdt; -using nfb_grpc::nfb_rpc_device; -using nfb_grpc::nfb_read_req; -using nfb_grpc::nfb_write_req; -using nfb_grpc::nfb_read_resp; -using nfb_grpc::nfb_write_resp; - - -class NfbClient { - void *m_fdt; - public: - NfbClient(std::shared_ptr channel) - : stub_(Nfb::NewStub(channel)), m_fdt(NULL) { - } - - void* get_fdt() { - if (m_fdt) - return m_fdt; - void *raw_fdt; - nfb_rpc_device dev; - nfb_fdt fdt; - - ClientContext context; - Status status = stub_->Nfb_fdt_get(&context, dev, &fdt); - - if (!status.ok()) { - std::cout << "GetFeature rpc failed." << std::endl; - return NULL; - } - - raw_fdt = malloc(fdt.fdt().length()); - if (raw_fdt == NULL) - return NULL; - - memcpy(raw_fdt, fdt.fdt().c_str(), fdt.fdt().length()); - - m_fdt = raw_fdt; - return raw_fdt; - } - - int nfb_comp_read(int fdt_offset, void *buffer, int nbyte, int offset) { - nfb_read_req req; - nfb_read_resp resp; - - req.set_fdt_offset(fdt_offset); - req.set_nbyte(nbyte); - req.set_offset(offset); - - ClientContext context; - Status status = stub_->Nfb_comp_read(&context, req, &resp); - - if (!status.ok()) { - std::cout << "grpc nfb_comp_read failed." << std::endl; - return 0; - } - - memcpy(buffer, resp.data().c_str(), resp.data().length()); - return resp.data().length(); - } - - int nfb_comp_write(int fdt_offset, const void *buffer, int nbyte, int offset) { - nfb_write_req req; - nfb_write_resp resp; - - req.set_fdt_offset(fdt_offset); - req.set_nbyte(nbyte); - req.set_offset(offset); - req.set_data(std::string((const char*)buffer, nbyte)); - - ClientContext context; - Status status = stub_->Nfb_comp_write(&context, req, &resp); - - if (!status.ok()) { - std::cout << "grpc nfb_comp_write failed." << std::endl; - return 0; - } - - return resp.status(); - } - - std::unique_ptr stub_; -}; - - -extern "C" { - -struct nfb_grpc_bus_priv { - int comp_node; - off_t base; - NfbClient *nfb; -}; - -static const char *nfb_grpc_prefix = "grpc:"; - -static int nfb_grpc_open(const char *devname, int oflag, void **priv, void **fdt) -{ - - NfbClient *nfb = new NfbClient( - grpc::CreateChannel(devname + strlen(nfb_grpc_prefix), - grpc::InsecureChannelCredentials()) - ); - - *fdt = nfb->get_fdt(); - if (*fdt == NULL) { - delete nfb; - return -ENODEV; - } - - *priv = nfb; - return 0; -} - -static void nfb_grpc_close(void *dev_priv) -{ - NfbClient *nfb = (NfbClient *)dev_priv; - delete nfb; -} - -static ssize_t nfb_bus_grpc_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) -{ - struct nfb_grpc_bus_priv *bus = (struct nfb_grpc_bus_priv *)bus_priv; - return bus->nfb->nfb_comp_read(bus->comp_node, buf, nbyte, offset - bus->base); -} - -static ssize_t nfb_bus_grpc_write(void *bus_priv, const void *buf, size_t nbyte, off_t offset) -{ - struct nfb_grpc_bus_priv *bus = (struct nfb_grpc_bus_priv *)bus_priv; - return bus->nfb->nfb_comp_write(bus->comp_node, buf, nbyte, offset - bus->base); -} - -static int nfb_grpc_bus_open(void *dev_priv, int bus_node, int comp_node, void ** bus_priv, struct libnfb_bus_ext_ops* ops) -{ - NfbClient* dev = (NfbClient *) dev_priv; - struct nfb_grpc_bus_priv *bus; - - int proplen; - const fdt32_t *prop; - - prop = (fdt32_t*) fdt_getprop(dev->get_fdt(), comp_node, "reg", &proplen); - if (proplen != sizeof(*prop) * 2) { - return -EBADFD; - } - - bus = (struct nfb_grpc_bus_priv *) malloc(sizeof(*bus)); - if (bus == NULL) - return -ENOMEM; - - bus->nfb = dev; - bus->comp_node = comp_node; - bus->base = fdt32_to_cpu(prop[0]); - - ops->read = nfb_bus_grpc_read; - ops->write = nfb_bus_grpc_write; - *bus_priv = bus; - - return 0; -} - -static void nfb_grpc_bus_close(void *bus_priv) -{ - free(bus_priv); -} - -static int nfb_grpc_comp_lock(const struct nfb_comp *comp, uint32_t features) -{ - /* TODO */ - return 1; -} - -static void nfb_grpc_comp_unlock(const struct nfb_comp *comp, uint32_t features) -{ - /* TODO */ -} - -struct libnfb_ext_abi_version libnfb_ext_abi_version = libnfb_ext_abi_version_current; - -static struct libnfb_ext_ops nfb_grpc_ops = { - .open = nfb_grpc_open, - .close = nfb_grpc_close, - .bus_open_mi = nfb_grpc_bus_open, - .bus_close_mi = nfb_grpc_bus_close, - .comp_lock = nfb_grpc_comp_lock, - .comp_unlock = nfb_grpc_comp_unlock, -}; - -int libnfb_ext_get_ops(const char *devname, struct libnfb_ext_ops *ops) -{ - if (strncmp(devname, nfb_grpc_prefix, strlen(nfb_grpc_prefix)) == 0) { - *ops = nfb_grpc_ops; - return 1; - } else { - return 0; - } -} - -} diff --git a/ext/libnfb_ext_grpc/nfb_grpc_server.cc b/ext/libnfb_ext_grpc/server.cc similarity index 69% rename from ext/libnfb_ext_grpc/nfb_grpc_server.cc rename to ext/libnfb_ext_grpc/server.cc index 8d24eede..757b533f 100644 --- a/ext/libnfb_ext_grpc/nfb_grpc_server.cc +++ b/ext/libnfb_ext_grpc/server.cc @@ -5,18 +5,16 @@ #include #include +extern "C" { #include +} #include #include #include #include #include -#ifdef BAZEL_BUILD -#include "examples/protos/route_guide.grpc.pb.h" -#else -#include "nfb_grpc.grpc.pb.h" -#endif +#include "nfb.grpc.pb.h" #include @@ -28,16 +26,20 @@ using grpc::ServerReaderWriter; using grpc::ServerWriter; using grpc::Status; -using nfb_grpc::Nfb; -using nfb_grpc::nfb_fdt; -using nfb_grpc::nfb_rpc_device; -using nfb_grpc::nfb_read_req; -using nfb_grpc::nfb_write_req; -using nfb_grpc::nfb_read_resp; -using nfb_grpc::nfb_write_resp; +using google::protobuf::Empty; + +using nfb::ext::protobuf::v1::Nfb; +using nfb::ext::protobuf::v1::FdtResponse; +using nfb::ext::protobuf::v1::ReadCompRequest; +using nfb::ext::protobuf::v1::WriteCompRequest; +using nfb::ext::protobuf::v1::ReadCompResponse; +using nfb::ext::protobuf::v1::WriteCompResponse; class NfbServerImpl final : public Nfb::Service { + struct nfb_device * m_dev; + const void *m_fdt; + public: explicit NfbServerImpl(const std::string& path) { @@ -45,29 +47,26 @@ class NfbServerImpl final : public Nfb::Service if (m_dev == NULL) { throw std::system_error(errno, std::system_category()); } + m_fdt = nfb_get_fdt(m_dev); } - Status Nfb_fdt_get(ServerContext* context, const nfb_rpc_device* dev, nfb_fdt* fdt) override + Status GetFdt(ServerContext* context, const Empty* req, FdtResponse* res) override { - const void * raw_fdt = nfb_get_fdt(m_dev); - int size = fdt_totalsize(raw_fdt); - - fdt->set_fdt(raw_fdt, size); - + res->set_fdt(m_fdt, fdt_totalsize(m_fdt)); return Status::OK; } - Status Nfb_comp_read(ServerContext* context, const nfb_read_req* req, nfb_read_resp* resp) override + Status ReadComp(ServerContext* context, const ReadCompRequest* req, ReadCompResponse* resp) override { - struct nfb_comp * comp = nfb_comp_open(m_dev, req->fdt_offset()); + struct nfb_comp * comp; uint8_t * data; int nbyte; + comp = nfb_comp_open(m_dev, fdt_path_offset(m_fdt, req->path().c_str())); if (comp == NULL) { throw std::system_error(errno, std::system_category()); } - //data = (uint8_t*) malloc(req->nbyte()); data = new uint8_t[req->nbyte()]; nbyte = nfb_comp_read(comp, data, req->nbyte(), req->offset()); @@ -80,11 +79,12 @@ class NfbServerImpl final : public Nfb::Service return Status::OK; } - Status Nfb_comp_write(ServerContext* context, const nfb_write_req* req, nfb_write_resp* resp) override + Status WriteComp(ServerContext* context, const WriteCompRequest* req, WriteCompResponse* resp) override { - struct nfb_comp * comp = nfb_comp_open(m_dev, req->fdt_offset()); + struct nfb_comp * comp; int nbyte; + comp = nfb_comp_open(m_dev, fdt_path_offset(m_fdt, req->path().c_str())); if (comp == NULL) { throw std::system_error(errno, std::system_category()); } @@ -101,12 +101,9 @@ class NfbServerImpl final : public Nfb::Service { nfb_close(m_dev); } - -private: - struct nfb_device * m_dev; }; -void RunServer(const std::string& path, const std::string& addr) +void run_server(const std::string& path, const std::string& addr) { std::string server_address(addr); NfbServerImpl service(path); @@ -134,7 +131,7 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } } - RunServer(path, addr); + run_server(path, addr); return 0; } From 1c64bc5620ed17fa8db1aba09a6d87de877f3508 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 Jan 2025 13:25:55 +0100 Subject: [PATCH 268/518] feat(libnfb-ext-grpc): add dma.proto --- ext/libnfb_ext_grpc/CMakeLists.txt | 27 +++++++++++++++++++-------- ext/libnfb_ext_grpc/dma.proto | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 ext/libnfb_ext_grpc/dma.proto diff --git a/ext/libnfb_ext_grpc/CMakeLists.txt b/ext/libnfb_ext_grpc/CMakeLists.txt index 11cbb6b5..dd5a5c2a 100644 --- a/ext/libnfb_ext_grpc/CMakeLists.txt +++ b/ext/libnfb_ext_grpc/CMakeLists.txt @@ -15,8 +15,11 @@ include(GNUInstallDirs) find_package(Protobuf CONFIG) find_package(gRPC QUIET) -set(PROTO_FILES nfb.proto) +set(PROTO_NFB nfb.proto) +set(PROTO_DMA dma.proto) +set(PROTO_FILES ${PROTO_NFB} ${PROTO_DMA}) +add_library(nfb-ext-proto INTERFACE ${PROTO_FILES}) add_library(nfb-ext-grpc SHARED client.cc) add_executable(nfb-grpc-server server.cc) @@ -25,8 +28,8 @@ if (${gRPC_FOUND}) include_directories(${Protobuf_INCLUDE_DIRS}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) - target_sources(nfb-ext-grpc PRIVATE ${PROTO_FILES}) - target_sources(nfb-grpc-server PRIVATE ${PROTO_FILES}) + target_sources(nfb-ext-grpc PRIVATE ${PROTO_NFB}) + target_sources(nfb-grpc-server PRIVATE ${PROTO_NFB}) get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION) protobuf_generate(TARGET nfb-ext-grpc LANGUAGE cpp) @@ -42,8 +45,8 @@ else() find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) find_program(_PROTOBUF_PROTOC protoc) - get_filename_component(nfb_proto ${PROTO_FILES} ABSOLUTE) - get_filename_component(nfb_proto_path "${nfb_proto}" PATH) + get_filename_component(nfb_proto_abs ${PROTO_NFB} ABSOLUTE) + get_filename_component(nfb_proto_path "${nfb_proto_abs}" PATH) set(nfb_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/nfb.pb.cc") set(nfb_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/nfb.pb.h") @@ -57,8 +60,8 @@ else() --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" -I "${nfb_proto_path}" --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" - "${nfb_proto}" - DEPENDS "${nfb_proto}") + "${nfb_proto_abs}" + DEPENDS "${nfb_proto_abs}") include_directories("${CMAKE_CURRENT_BINARY_DIR}") @@ -77,13 +80,21 @@ set_target_properties(nfb-ext-grpc PROPERTIES OUTPUT_NAME nfb-ext-grpc VERSION ${GIT_VERSION} SOVERSION ${GIT_VERSION_MAJOR} - PUBLIC_HEADER ${PROTO_FILES} +) + +set_target_properties(nfb-ext-proto + PROPERTIES + PUBLIC_HEADER "${PROTO_FILES}" ) install(TARGETS nfb-ext-grpc COMPONENT NfbExtGrpc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +install(TARGETS nfb-ext-proto + COMPONENT NfbExtGrpc PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nfb/ext/protobuf/v1/ ) diff --git a/ext/libnfb_ext_grpc/dma.proto b/ext/libnfb_ext_grpc/dma.proto new file mode 100644 index 00000000..0e212e41 --- /dev/null +++ b/ext/libnfb_ext_grpc/dma.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; + +import "google/protobuf/empty.proto"; + +package nfb.ext.protobuf.v1; + +// Direct Memory Access +service Dma { + rpc RqStream (stream DmaResponse) returns (stream DmaRequest) {} + rpc Logout(google.protobuf.Empty) returns (google.protobuf.Empty) {} +} + +enum DmaOperation { + DMA_READ = 0; + DMA_WRITE = 1; +} + +message DmaRequest { + DmaOperation type = 1; + int64 addr = 2; + int32 nbyte = 3; + bytes data = 4; +} + +message DmaResponse { + int32 status = 1; + bytes data = 2; +} From 1cba09f6b54dcb5e60f66770b90c53bb39c29b61 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 Jan 2025 13:25:56 +0100 Subject: [PATCH 269/518] feat(libnfb-ext-grpc): add Python package with generated protobuf/grpc files --- ext/libnfb_ext_grpc/python/MANIFEST.in | 1 + ext/libnfb_ext_grpc/python/pyproject.toml | 22 ++++++++++++++++++++++ ext/libnfb_ext_grpc/python/setup.cfg | 8 ++++++++ ext/libnfb_ext_grpc/python/setup.py | 9 +++++++++ 4 files changed, 40 insertions(+) create mode 100644 ext/libnfb_ext_grpc/python/MANIFEST.in create mode 100644 ext/libnfb_ext_grpc/python/pyproject.toml create mode 100644 ext/libnfb_ext_grpc/python/setup.cfg create mode 100644 ext/libnfb_ext_grpc/python/setup.py diff --git a/ext/libnfb_ext_grpc/python/MANIFEST.in b/ext/libnfb_ext_grpc/python/MANIFEST.in new file mode 100644 index 00000000..c2ad0840 --- /dev/null +++ b/ext/libnfb_ext_grpc/python/MANIFEST.in @@ -0,0 +1 @@ +graft nfb/ext/protobuf diff --git a/ext/libnfb_ext_grpc/python/pyproject.toml b/ext/libnfb_ext_grpc/python/pyproject.toml new file mode 100644 index 00000000..70dba641 --- /dev/null +++ b/ext/libnfb_ext_grpc/python/pyproject.toml @@ -0,0 +1,22 @@ +[build-system] +requires = ["setuptools", "setuptools-grpc"] +build-backend = "setuptools.build_meta" + +[project] +name = "libnfb_ext_grpc" +version = "0.1.0" +authors = [{name = "Martin Spinler", email="spinler@cesnet.cz"}] +description = "Python wrapper for libnfb gRPC extension" +classifiers=[ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", +] +dependencies = [ + "protobuf", + "grpcio", +] + +[tool.setuptools] +packages = [ + "nfb", +] diff --git a/ext/libnfb_ext_grpc/python/setup.cfg b/ext/libnfb_ext_grpc/python/setup.cfg new file mode 100644 index 00000000..662f6f3d --- /dev/null +++ b/ext/libnfb_ext_grpc/python/setup.cfg @@ -0,0 +1,8 @@ +[build_grpc] +proto_files = + nfb/ext/protobuf/v1/nfb.proto + nfb/ext/protobuf/v1/dma.proto +grpc_files = + nfb/ext/protobuf/v1/nfb.proto + nfb/ext/protobuf/v1/dma.proto +proto_path = .. diff --git a/ext/libnfb_ext_grpc/python/setup.py b/ext/libnfb_ext_grpc/python/setup.py new file mode 100644 index 00000000..eaa24ade --- /dev/null +++ b/ext/libnfb_ext_grpc/python/setup.py @@ -0,0 +1,9 @@ +from setuptools import setup +from setuptools.command.build import build + +class custom_build(build): + sub_commands = [ + ('build_grpc', None), + ] + build.sub_commands + +setup(cmdclass={'build': custom_build}) From 6729dc6cdfcb19f6d30c784cbaf69c746320bb05 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 Jan 2025 13:25:56 +0100 Subject: [PATCH 270/518] feat(libnfb-ext-grpc): add virtual address space DMA plugin The DMA virtual address plugin connects to the Dma service and performs requests from server (DMA read & writes) in the virtual address of the userspace process. The DMA is unsafe and must be explicitly enabled in device string like: -d libnfb-ext-grpc.so:grpc+dma_vas:localhost:50051 --- ext/libnfb_ext_grpc/CMakeLists.txt | 38 ++++++-- ext/libnfb_ext_grpc/client.cc | 122 ++++++++++++++++++++------ ext/libnfb_ext_grpc/client_dma_vas.cc | 92 +++++++++++++++++++ ext/libnfb_ext_grpc/client_dma_vas.hh | 70 +++++++++++++++ 4 files changed, 291 insertions(+), 31 deletions(-) create mode 100644 ext/libnfb_ext_grpc/client_dma_vas.cc create mode 100644 ext/libnfb_ext_grpc/client_dma_vas.hh diff --git a/ext/libnfb_ext_grpc/CMakeLists.txt b/ext/libnfb_ext_grpc/CMakeLists.txt index dd5a5c2a..e3941f3c 100644 --- a/ext/libnfb_ext_grpc/CMakeLists.txt +++ b/ext/libnfb_ext_grpc/CMakeLists.txt @@ -20,15 +20,14 @@ set(PROTO_DMA dma.proto) set(PROTO_FILES ${PROTO_NFB} ${PROTO_DMA}) add_library(nfb-ext-proto INTERFACE ${PROTO_FILES}) -add_library(nfb-ext-grpc SHARED client.cc) +add_library(nfb-ext-grpc SHARED client.cc client_dma_vas.cc) add_executable(nfb-grpc-server server.cc) if (${gRPC_FOUND}) - include_directories(${Protobuf_INCLUDE_DIRS}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) - target_sources(nfb-ext-grpc PRIVATE ${PROTO_NFB}) + target_sources(nfb-ext-grpc PRIVATE ${PROTO_NFB} ${PROTO_DMA}) target_sources(nfb-grpc-server PRIVATE ${PROTO_NFB}) get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION) @@ -45,6 +44,7 @@ else() find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) find_program(_PROTOBUF_PROTOC protoc) + # NFB proto get_filename_component(nfb_proto_abs ${PROTO_NFB} ABSOLUTE) get_filename_component(nfb_proto_path "${nfb_proto_abs}" PATH) @@ -65,13 +65,39 @@ else() include_directories("${CMAKE_CURRENT_BINARY_DIR}") - set(PROTO_OUT_FILES ${nfb_grpc_srcs} ${nfb_grpc_hdrs} ${nfb_proto_srcs} ${nfb_proto_hdrs}) + # DMA proto + get_filename_component(dma_proto_abs ${PROTO_DMA} ABSOLUTE) + get_filename_component(dma_proto_path "${dma_proto_abs}" PATH) + + set(dma_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/dma.pb.cc") + set(dma_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/dma.pb.h") + set(dma_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/dma.grpc.pb.cc") + set(dma_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/dma.grpc.pb.h") + + add_custom_command( + OUTPUT "${dma_proto_srcs}" "${dma_proto_hdrs}" "${dma_grpc_srcs}" "${dma_grpc_hdrs}" + COMMAND ${_PROTOBUF_PROTOC} + ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" + -I "${dma_proto_path}" + --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" + "${dma_proto_abs}" + DEPENDS "${dma_proto_abs}") + + + set(NFB_PROTO_OUT_FILES + ${nfb_grpc_srcs} ${nfb_grpc_hdrs} ${nfb_proto_srcs} ${nfb_proto_hdrs} + ) + set(DMA_PROTO_OUT_FILES + ${dma_grpc_srcs} ${dma_grpc_hdrs} ${dma_proto_srcs} ${dma_proto_hdrs} + ) + set(gRPC_LIB_PREFIX "") set(Protobuf_LIBRARIES "protobuf") endif() -target_sources(nfb-ext-grpc PRIVATE ${PROTO_OUT_FILES}) -target_sources(nfb-grpc-server PRIVATE ${PROTO_OUT_FILES}) +target_sources(nfb-ext-grpc PRIVATE ${NFB_PROTO_OUT_FILES} ${DMA_PROTO_OUT_FILES}) +target_sources(nfb-grpc-server PRIVATE ${NFB_PROTO_OUT_FILES}) target_link_libraries(nfb-ext-grpc ${Protobuf_LIBRARIES} ${gRPC_LIB_PREFIX}grpc++ nfb fdt) target_link_libraries(nfb-grpc-server ${Protobuf_LIBRARIES} ${gRPC_LIB_PREFIX}grpc++ nfb fdt) diff --git a/ext/libnfb_ext_grpc/client.cc b/ext/libnfb_ext_grpc/client.cc index bb1bcdbc..dfeb8d0b 100644 --- a/ext/libnfb_ext_grpc/client.cc +++ b/ext/libnfb_ext_grpc/client.cc @@ -21,6 +21,9 @@ extern "C" { #include #include +#include "client_dma_vas.hh" + + using grpc::Channel; using grpc::ClientContext; using grpc::ClientReader; @@ -44,6 +47,8 @@ class NfbClient std::string m_path; public: + std::unique_ptr stub_; + NfbClient(std::string path, std::shared_ptr channel) : stub_(Nfb::NewStub(channel)), m_fdt(NULL), @@ -90,20 +95,18 @@ class NfbClient return m_fdt; } - - std::unique_ptr stub_; }; class NfbBus { int comp_node; off_t m_base; - NfbClient *m_dev; + std::shared_ptr m_dev; std::string m_comp_path; public: - NfbBus(NfbClient *dev, int bus_node, int comp_node) : + NfbBus(std::shared_ptr & dev, int bus_node, int comp_node) : m_dev(dev) { void *fdt; @@ -168,41 +171,107 @@ class NfbBus extern "C" { +static const int NG_FLAG_DDMA = (1 << 0); + +int parse_devname(const char *devname, int *flags) +{ + const char *orig_devname = devname; + + const char *c_prefix = "grpc"; + const char *c_ddma = "+dma_vas"; + + /* Check for plugin prefix */ + if (strncmp(devname, c_prefix, strlen(c_prefix)) != 0) + return -1; + + devname += strlen(c_prefix); + /* Check for next parameter availability */ + if (strlen(devname) == 0) + return -1; + + while (strlen(devname) > 0) { + if (devname[0] == ':') { /* next value is address / real devname */ + devname += 1; + break; + } else if (strncmp(devname, c_ddma, strlen(c_ddma)) == 0) { + devname += strlen(c_ddma); + *flags |= NG_FLAG_DDMA; + } else { + return -1; + } + } + return devname - orig_devname; +} + + +struct nfb_grpc_dev { + std::shared_ptr nfb; + std::shared_ptr dma; + std::string path; +}; -static const char *nfb_grpc_prefix = "grpc:"; +static std::map> nfb_grpc_dma_clients; static int nfb_grpc_open(const char *devname, int oflag, void **priv, void **fdt) { - NfbClient *nfb; + int ret; + int flags = 0; + + struct nfb_grpc_dev *dev; + std::string path; + std::shared_ptr channel; + std::shared_ptr nfb; + std::shared_ptr dma; + + ret = parse_devname(devname, &flags); + if (ret < 0) + return -EINVAL; + + devname += ret; - devname += strlen(nfb_grpc_prefix); try { - nfb = new NfbClient( - devname, - grpc::CreateChannel( - devname, - grpc::InsecureChannelCredentials() - ) + path = devname; + channel = grpc::CreateChannel( + path, + grpc::InsecureChannelCredentials() + ); + + nfb = std::make_shared( + path, + channel ); - } catch(...) { - return -ENODEV; - } - try { *fdt = nfb->get_fdt(); - } catch(...) { - delete nfb; + + if (flags & NG_FLAG_DDMA) { + /* If in current process exists DMA connection, do not create new one */ + if (nfb_grpc_dma_clients.count(path) == 0 || !(dma = nfb_grpc_dma_clients[path].lock())) { + dma = std::make_shared(channel); + nfb_grpc_dma_clients[path] = dma; + } + } + dev = new struct nfb_grpc_dev; + dev->nfb = nfb; + dev->dma = dma; + dev->path = path; + *priv = dev; + } catch (...) { return -ENODEV; } - *priv = nfb; return 0; } static void nfb_grpc_close(void *dev_priv) { - NfbClient *nfb = (NfbClient *)dev_priv; - delete nfb; + struct nfb_grpc_dev *dev = (struct nfb_grpc_dev*) dev_priv; + std::string path = dev->path; + std::shared_ptr dma; + delete dev; + + if (nfb_grpc_dma_clients.count(path) != 0 && !(dma = nfb_grpc_dma_clients[path].lock())) { + nfb_grpc_dma_clients.erase(path); + } } static ssize_t nfb_bus_grpc_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) @@ -219,10 +288,11 @@ static ssize_t nfb_bus_grpc_write(void *bus_priv, const void *buf, size_t nbyte, static int nfb_grpc_bus_open(void *dev_priv, int bus_node, int comp_node, void ** bus_priv, struct libnfb_bus_ext_ops* ops) { - NfbClient* dev = (NfbClient *) dev_priv; + struct nfb_grpc_dev *dev = (struct nfb_grpc_dev*) dev_priv; + NfbBus *bus; try { - bus = new NfbBus(dev, bus_node, comp_node); + bus = new NfbBus(dev->nfb, bus_node, comp_node); } catch (...) { return -EBADF; } @@ -263,7 +333,9 @@ static struct libnfb_ext_ops nfb_grpc_ops = { int libnfb_ext_get_ops(const char *devname, struct libnfb_ext_ops *ops) { - if (strncmp(devname, nfb_grpc_prefix, strlen(nfb_grpc_prefix)) == 0) { + int flags = 0; + + if (parse_devname(devname, &flags) >= 0) { *ops = nfb_grpc_ops; return 1; } else { diff --git a/ext/libnfb_ext_grpc/client_dma_vas.cc b/ext/libnfb_ext_grpc/client_dma_vas.cc new file mode 100644 index 00000000..8aa360e5 --- /dev/null +++ b/ext/libnfb_ext_grpc/client_dma_vas.cc @@ -0,0 +1,92 @@ +/* + * file : client_dma_vas.cc + * Copyright (C) 2024 CESNET z. s. p. o.b + * description: gRPC client - plugin for virtual address space DMA + * author : Radek Iša + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "client_dma_vas.hh" + + +DmaAccess::DmaAccess(pb_dma::Dma::Stub* stub) : bind(true) +{ + stub->async()->RqStream(&context, this); + StartRead(&req); + StartCall(); +} + +void DmaAccess::OnWriteDone(bool ok) +{ + if (ok) { + bool next_write; + resp_que.lock(); + resp_que.pop(); + next_write = (resp_que.size() > 0); + if (next_write) { + resp = resp_que.front(); + } + resp_que.unlock(); + + if (next_write) { + StartWrite(&resp); + } + } +} + +void DmaAccess::OnReadDone(bool ok) +{ + bool first_write; + pb_dma::DmaResponse resp_act; + + if (ok) { + StartRead(&req); + + // Memory access + pb_dma::DmaOperation req_type = req.type(); + resp_act.set_status(0); + if (req_type == pb_dma::DmaOperation::DMA_READ) { + resp_act.set_data((void*)(req.addr()), req.nbyte()); + } else { + memcpy((void*)(req.addr()), req.data().c_str(), req.data().size()); + resp_act.clear_data(); + } + + // push to queue + resp_que.lock(); + first_write = (resp_que.size() == 0); + resp_que.push(resp_act); + resp_que.unlock(); + + if (first_write) { + resp = resp_act; + StartWrite(&resp); + } + } +} + +void DmaAccess::OnDone(const grpc::Status& s) +{ + status = s; + bind = false; +} + +grpc::Status DmaAccess::Await() +{ + while (bind) { + std::this_thread::sleep_for(std::chrono::milliseconds(300)); + } + return status; +} diff --git a/ext/libnfb_ext_grpc/client_dma_vas.hh b/ext/libnfb_ext_grpc/client_dma_vas.hh new file mode 100644 index 00000000..513b4f2c --- /dev/null +++ b/ext/libnfb_ext_grpc/client_dma_vas.hh @@ -0,0 +1,70 @@ +/* + * file : client_dma_vas.hh + * Copyright (C) 2024 CESNET z. s. p. o.b + * description: gRPC client - plugin for virtual address space DMA + * author : Radek Iša + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef __CLIENT_DMA_VAS_HH__ +#define __CLIENT_DMA_VAS_HH__ + +#include +#include + +#include + + +namespace pb_dma = nfb::ext::protobuf::v1; + +template class fifo_lock : public std::queue +{ +private: + std::mutex mux; + +public: + void lock() { mux.lock(); } + + void unlock() { mux.unlock(); } +}; + +namespace pb_dma = nfb::ext::protobuf::v1; + +class DmaAccess : public grpc::ClientBidiReactor +{ +protected: + grpc::ClientContext context; + grpc::Status status; + + fifo_lock resp_que; + bool bind; + pb_dma::DmaRequest req; + pb_dma::DmaResponse resp; + + void OnWriteDone(bool ok) override; + void OnReadDone(bool ok) override; + void OnDone(const grpc::Status &s) override; +public: + DmaAccess(pb_dma::Dma::Stub* stub); + + grpc::Status Await(); +}; + +class NfbDmaClient +{ +public: + DmaAccess* process; + std::unique_ptr stub; + std::shared_ptr channel; + +public: + NfbDmaClient(std::shared_ptr channel) : + channel(channel) + { + this->stub = pb_dma::Dma::NewStub(this->channel); + this->process = new DmaAccess(this->stub.get()); + } +}; + +#endif From 96ee2ec525bd91ce7a630bb42b2037c2a82a0172 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 Jan 2025 13:25:57 +0100 Subject: [PATCH 271/518] chore(libnfb-ext-grpc): move proto files to target path --- ext/libnfb_ext_grpc/CMakeLists.txt | 4 ++-- ext/libnfb_ext_grpc/client.cc | 2 +- ext/libnfb_ext_grpc/client_dma_vas.hh | 2 +- ext/libnfb_ext_grpc/{ => nfb/ext/protobuf/v1}/dma.proto | 0 ext/libnfb_ext_grpc/{ => nfb/ext/protobuf/v1}/nfb.proto | 0 ext/libnfb_ext_grpc/server.cc | 3 ++- 6 files changed, 6 insertions(+), 5 deletions(-) rename ext/libnfb_ext_grpc/{ => nfb/ext/protobuf/v1}/dma.proto (100%) rename ext/libnfb_ext_grpc/{ => nfb/ext/protobuf/v1}/nfb.proto (100%) diff --git a/ext/libnfb_ext_grpc/CMakeLists.txt b/ext/libnfb_ext_grpc/CMakeLists.txt index e3941f3c..ff411df1 100644 --- a/ext/libnfb_ext_grpc/CMakeLists.txt +++ b/ext/libnfb_ext_grpc/CMakeLists.txt @@ -15,8 +15,8 @@ include(GNUInstallDirs) find_package(Protobuf CONFIG) find_package(gRPC QUIET) -set(PROTO_NFB nfb.proto) -set(PROTO_DMA dma.proto) +set(PROTO_NFB nfb/ext/protobuf/v1/nfb.proto) +set(PROTO_DMA nfb/ext/protobuf/v1/dma.proto) set(PROTO_FILES ${PROTO_NFB} ${PROTO_DMA}) add_library(nfb-ext-proto INTERFACE ${PROTO_FILES}) diff --git a/ext/libnfb_ext_grpc/client.cc b/ext/libnfb_ext_grpc/client.cc index dfeb8d0b..32411fc4 100644 --- a/ext/libnfb_ext_grpc/client.cc +++ b/ext/libnfb_ext_grpc/client.cc @@ -12,7 +12,7 @@ #include #include -#include +#include "nfb/ext/protobuf/v1/nfb.grpc.pb.h" extern "C" { #include diff --git a/ext/libnfb_ext_grpc/client_dma_vas.hh b/ext/libnfb_ext_grpc/client_dma_vas.hh index 513b4f2c..bc105cc5 100644 --- a/ext/libnfb_ext_grpc/client_dma_vas.hh +++ b/ext/libnfb_ext_grpc/client_dma_vas.hh @@ -13,7 +13,7 @@ #include #include -#include +#include "nfb/ext/protobuf/v1/dma.grpc.pb.h" namespace pb_dma = nfb::ext::protobuf::v1; diff --git a/ext/libnfb_ext_grpc/dma.proto b/ext/libnfb_ext_grpc/nfb/ext/protobuf/v1/dma.proto similarity index 100% rename from ext/libnfb_ext_grpc/dma.proto rename to ext/libnfb_ext_grpc/nfb/ext/protobuf/v1/dma.proto diff --git a/ext/libnfb_ext_grpc/nfb.proto b/ext/libnfb_ext_grpc/nfb/ext/protobuf/v1/nfb.proto similarity index 100% rename from ext/libnfb_ext_grpc/nfb.proto rename to ext/libnfb_ext_grpc/nfb/ext/protobuf/v1/nfb.proto diff --git a/ext/libnfb_ext_grpc/server.cc b/ext/libnfb_ext_grpc/server.cc index 757b533f..eb138eb4 100644 --- a/ext/libnfb_ext_grpc/server.cc +++ b/ext/libnfb_ext_grpc/server.cc @@ -14,10 +14,11 @@ extern "C" { #include #include #include -#include "nfb.grpc.pb.h" #include +#include "nfb/ext/protobuf/v1/nfb.grpc.pb.h" + using grpc::Server; using grpc::ServerBuilder; using grpc::ServerContext; From abbae17f384ac8a64dfa63839202c02a7ff38163 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 Jan 2025 13:25:58 +0100 Subject: [PATCH 272/518] feat(libnfb-ext-grpc): add Python gRPC server --- .../python/nfb/ext/grpc/__init__.py | 0 .../python/nfb/ext/grpc/server.py | 45 +++++++++++++++++++ ext/libnfb_ext_grpc/python/pyproject.toml | 9 ++-- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 ext/libnfb_ext_grpc/python/nfb/ext/grpc/__init__.py create mode 100644 ext/libnfb_ext_grpc/python/nfb/ext/grpc/server.py diff --git a/ext/libnfb_ext_grpc/python/nfb/ext/grpc/__init__.py b/ext/libnfb_ext_grpc/python/nfb/ext/grpc/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ext/libnfb_ext_grpc/python/nfb/ext/grpc/server.py b/ext/libnfb_ext_grpc/python/nfb/ext/grpc/server.py new file mode 100644 index 00000000..077d0749 --- /dev/null +++ b/ext/libnfb_ext_grpc/python/nfb/ext/grpc/server.py @@ -0,0 +1,45 @@ +import grpc +from concurrent import futures + +import nfb +from nfb.libnfb import Nfb +from nfb.ext.protobuf.v1 import nfb_pb2_grpc +from nfb.ext.protobuf.v1 import nfb_pb2 + + +class Servicer(nfb_pb2_grpc.NfbServicer): + def __init__(self, dev: Nfb): + self._dev = dev + + def GetFdt(self, request, context): + return nfb_pb2.FdtResponse(fdt=self._dev.fdt.to_dtb()) + + def ReadComp(self, request, context): + comp = self._dev.comp_open(self._dev.fdt.get_node(request.path)) + data = comp.read(request.offset, request.nbyte) + return nfb_pb2.ReadCompResponse(data=bytes(data), status=0) + + def WriteComp(self, request, context): + comp = self._dev.comp_open(self._dev.fdt.get_node(request.path)) + comp.write(request.offset, bytes(request.data)) + return nfb_pb2.WriteCompResponse(status=0) + + +def Server(servicer, addr='127.0.0.1', port=50051): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=4)) + nfb_pb2_grpc.add_NfbServicer_to_server(servicer, server) + server.add_insecure_port(f'{addr}:{port}') + server.start() + + server.__path = f'libnfb-ext-grpc.so:grpc:{addr}:{port}' + server.path = lambda : server.__path + return server + + +def run_server(servicer=None, **kwargs): + if servicer is None: + servicer = Servicer + svc = servicer(nfb.open()) + server = Server(svc, **kwargs) + # server.shutdown() + # server.close() diff --git a/ext/libnfb_ext_grpc/python/pyproject.toml b/ext/libnfb_ext_grpc/python/pyproject.toml index 70dba641..597c26a6 100644 --- a/ext/libnfb_ext_grpc/python/pyproject.toml +++ b/ext/libnfb_ext_grpc/python/pyproject.toml @@ -16,7 +16,8 @@ dependencies = [ "grpcio", ] -[tool.setuptools] -packages = [ - "nfb", -] +[project.scripts] +nfb-python-grpc-server = "nfb.ext.grpc.server:main" + +[tool.setuptools.packages.find] +include = ["nfb*"] From 42f4590f1e115f03bf1ab9e828519f3f197bf3f8 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Wed, 22 Jan 2025 10:53:50 +0100 Subject: [PATCH 273/518] refactor(libnetcope-ndp): remove check of metadata validity The metadata are valid if their size of is non-zero. --- libnfb/include/netcope/dma_ctrl_ndp.h | 3 +-- libnfb/include/netcope/ndp_rx.h | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 45d43de9..fedfb59b 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -53,8 +53,7 @@ #define NDP_CTRL_UPDATE_SIZE 4 #define NDP_PACKET_HEADER_SIZE 4 -#define NDP_CALYPTE_METADATA_NOT_VALID 0x400 -#define NDP_CALYPTE_METADATA_HDR_SIZE_MASK 0xff +#define NDP_CALYPTE_METADATA_HDR_SIZE_MASK 0xff #define NDP_TX_CALYPTE_BLOCK_SIZE (32u) #define NDP_RX_CALYPTE_BLOCK_SIZE (128u) diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index 7bc47c6c..39f2b53d 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -336,9 +336,7 @@ static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *pac break; } - if (!(hdr->metadata & NDP_CALYPTE_METADATA_NOT_VALID)) - header_size = hdr->metadata & NDP_CALYPTE_METADATA_HDR_SIZE_MASK; - + header_size = hdr->metadata & NDP_CALYPTE_METADATA_HDR_SIZE_MASK; packet_size = le16_to_cpu(hdr->frame_len) - header_size; data = data_base + hdr->frame_ptr * NDP_RX_CALYPTE_BLOCK_SIZE; From f6a8c81c4f732833e1187eb0238fb1c05dda4a34 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Wed, 22 Jan 2025 15:42:50 +0100 Subject: [PATCH 274/518] fix(libnetcope-ndp): add check of the header lentgh The header length needs to be masked in order to limit maximum header size but the check also needs to be done because otherwise, a user can overwrite some packet data. The header size mask is currently set to xFF. --- libnfb/include/netcope/ndp_tx.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index 9f27fc9f..245a3e39 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -436,7 +436,10 @@ static inline unsigned nc_ndp_v3_tx_burst_get(void *priv, struct ndp_packet *pac hdr = hdr_base + i; - header_size = packets[i].header_length; + if (unlikely(packets[i].header_length > NDP_CALYPTE_METADATA_HDR_SIZE_MASK)) + return 0; + + header_size = packets[i].header_length & NDP_CALYPTE_METADATA_HDR_SIZE_MASK; packet_size = packets[i].data_length + header_size; if (unlikely(packet_size < q->frame_size_min)) { From f1fc4837bb697061bfc9e4f44c138f13a37a315c Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Wed, 22 Jan 2025 15:44:06 +0100 Subject: [PATCH 275/518] feat(libnetcope-ndp): pass header size to DMA hdr metadata These metadata contain a length of a packet and allow the user to add a custom header that travels with the data. --- libnfb/include/netcope/ndp_tx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index 245a3e39..bdd82111 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -452,7 +452,7 @@ static inline unsigned nc_ndp_v3_tx_burst_get(void *priv, struct ndp_packet *pac } /* Write DMA TX header */ - hdr->metadata = 0; + hdr->metadata = cpu_to_le16(header_size); hdr->frame_len = cpu_to_le16(packet_size); hdr->frame_ptr = sdp_int & q->u.v3.data_ptr_mask; From ec81e28304c6b6155a3a6bafbf48629131c32dfa Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Wed, 22 Jan 2025 15:45:47 +0100 Subject: [PATCH 276/518] fix(libnetcope-ndp): mask DMA hdr metadata to obtain APP hdr size The app header travels with the data and is also stored in the data buffer and its size can be retrieved by reading and masing of DMA hdr metadata. --- libnfb/include/netcope/ndp_rx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index 39f2b53d..04c05480 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -336,7 +336,7 @@ static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *pac break; } - header_size = hdr->metadata & NDP_CALYPTE_METADATA_HDR_SIZE_MASK; + header_size = le16_to_cpu(hdr->metadata) & NDP_CALYPTE_METADATA_HDR_SIZE_MASK; packet_size = le16_to_cpu(hdr->frame_len) - header_size; data = data_base + hdr->frame_ptr * NDP_RX_CALYPTE_BLOCK_SIZE; From 5fede18e8633f48385e25f9f9c86c1b4d802c717 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 27 Jan 2025 07:55:32 +0100 Subject: [PATCH 277/518] feat(libnetcope): add BittWare BMC SPI controller support --- libnfb/include/netcope/bittware_bmc_spi.h | 599 ++++++++++++++++++++++ 1 file changed, 599 insertions(+) create mode 100644 libnfb/include/netcope/bittware_bmc_spi.h diff --git a/libnfb/include/netcope/bittware_bmc_spi.h b/libnfb/include/netcope/bittware_bmc_spi.h new file mode 100644 index 00000000..658290dd --- /dev/null +++ b/libnfb/include/netcope/bittware_bmc_spi.h @@ -0,0 +1,599 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Network component library - SPI controller for BittWare BMC IP + * + * Copyright (C) 2025 CESNET + * Author(s): + * Martin Spinler + */ + +#ifndef BW_BMC_SPI_H +#define BW_BMC_SPI_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ~~~~[ DATA TYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +struct nc_bw_bmc { + unsigned char * buffer; + unsigned int buffer_len; + unsigned int recv_len; + unsigned int pos; + int throttle_write: 1; +}; + + +/* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +static inline struct nc_bw_bmc *nc_bw_bmc_open(const struct nfb_device *dev, int fdt_offset, unsigned char*buffer, unsigned int len); +static inline void nc_bw_bmc_close(struct nc_bw_bmc *spi); +static inline int nc_bw_bmc_send_mctp(struct nc_bw_bmc *spi); +static inline int nc_bw_bmc_send_mctp_ext(struct nc_bw_bmc *spi, const unsigned char *bytes, int len, int last, int wait_for_status); +static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned char* bytes, unsigned int len, unsigned int *readen); + + +/* ~~~~[ REGISTERS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#define NC_BW_BMC_SPI_WR_CSR 0x0000 +#define NC_BW_BMC_SPI_RD_CSR 0x0004 +#define NC_BW_BMC_SPI_WR_FIFO 0x0008 +#define NC_BW_BMC_SPI_RD_FIFO 0x000C +#define NC_BW_BMC_SPI_SYS_CSR 0x0010 + + +#define COMP_NETCOPE_BW_BMC_SPI "bittware,bmc" + +static inline void nc_bw_bmc_write32(struct nfb_comp *comp, uint32_t offset, uint32_t val) +{ + struct nc_bw_bmc * spi = (struct nc_bw_bmc*) nfb_comp_to_user(comp); + nfb_comp_write32(comp, offset, val); + if (spi->throttle_write) + nfb_comp_read32(comp, NC_BW_BMC_SPI_WR_FIFO); +} + +/* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +static inline struct nc_bw_bmc *nc_bw_bmc_open(const struct nfb_device *dev, int fdt_offset, unsigned char*buffer, unsigned int len) +{ + int size; + struct nc_bw_bmc *spi; + struct nfb_comp *comp; + const void *prop; + const void *fdt = nfb_get_fdt(dev); + int retries = 0; + + uint32_t status; + if (len == 0) + return NULL; + if (fdt_node_check_compatible(fdt, fdt_offset, COMP_NETCOPE_BW_BMC_SPI)) + return NULL; + + size = sizeof(*spi); + if (buffer == NULL) + size += len; + + comp = nfb_comp_open_ext(dev, fdt_offset, size); + if (!comp) + return NULL; + + spi = (struct nc_bw_bmc*) nfb_comp_to_user(comp); + spi->buffer = buffer ? buffer : (unsigned char*) (spi + 1); + spi->buffer_len = len; + spi->pos = 0; + spi->recv_len = 0; + + prop = fdt_getprop(fdt, fdt_offset, "throttle_write", NULL); + spi->throttle_write = prop ? 1 : 0; + + retries = 0; + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_RD_FIFO); + while (status != 0xdeadbeef && ++retries < 1000) { +#ifdef __KERNEL__ + udelay(1000); +#else + usleep(1000); +#endif + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_RD_FIFO); + } + + retries = 0; + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_SYS_CSR); + while ((status & (1 << 1)) == 0 && ++retries < 1000) { +#ifdef __KERNEL__ + udelay(1000); +#else + usleep(1000); +#endif + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_SYS_CSR); + } + + nfb_comp_read32(comp, NC_BW_BMC_SPI_WR_CSR); + //nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_SYS_CSR, 1 << 0); + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_WR_CSR, 1 << 12); + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_RD_CSR, 1 << 14); + + return spi; +} + +static inline void nc_bw_bmc_close(struct nc_bw_bmc *spi) +{ + nfb_comp_close(nfb_user_to_comp(spi)); +} + +/* send raw mctp: header must be in bytes already (hdr, dst, src, flags) */ +static inline int nc_bw_bmc_send_mctp_ext(struct nc_bw_bmc *spi, const unsigned char *bytes, int len, int last, int wait_for_status) +{ + int retries = 0; + struct nfb_comp * comp = nfb_user_to_comp(spi); + int i; + uint32_t status; + + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_RD_CSR); + if (status & 1) { + /* Previous command doesn't red the data */ + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_RD_CSR, 1 << 14); /* Read FIFO Reset */ + } + + if (len == 0) + return 0; + + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_WR_FIFO, 0x11); /* MCTP command */ + + for (i = 0; i < len - 1; i++) { + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_WR_FIFO, bytes[i]); + } + status = bytes[i]; + status |= (last ? 0x100 : 0); + + nfb_comp_write32(comp, NC_BW_BMC_SPI_WR_FIFO, status); + if (!wait_for_status) + return 0; + if (spi->throttle_write) + nfb_comp_read32(comp, NC_BW_BMC_SPI_WR_FIFO); + + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_WR_CSR); + if (status & (1 << 13)) { + /* Write FIFO Overflow */ + return -ENOBUFS; + } + while ((status & (1 << 0)) == 0 && ++retries < 100000) { +#ifdef __KERNEL__ + udelay(10); +#else + usleep(10); +#endif + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_WR_CSR); + } + if (retries >= 100000) + return -EPIPE; + + status = status >> 24; + if (status != 0x20) { + /* 0x20: MCTP Success + * 0x21: MCTP Invalid Length + * 0x22: MCTP Invalid Source + * 0x23: MCTP Invalid Message + * 0xF0: Unrecognized Command + */ + return -EOPNOTSUPP; + } + + return 0; +} + +static inline int nc_bw_bmc_send_mctp(struct nc_bw_bmc *spi) +{ + return nc_bw_bmc_send_mctp_ext(spi, spi->buffer, spi->pos, 1, 1); +} + +static inline int nc_bw_bmc_min(int a, int b) { + return a < b ? a : b; +} + +static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned char* data, unsigned int len, unsigned int *readen) +{ + struct nfb_comp * comp = nfb_user_to_comp(spi); + + unsigned int i; + int retries = 0; + uint32_t status; + uint32_t bytes; + + *readen = 0; + + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_RD_CSR); + while ((status & 1) == 0 && ++retries < 100000) { +#ifdef __KERNEL__ + udelay(10); +#else + usleep(10); +#endif + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_RD_CSR); + } + if (retries >= 100000) + return -EPIPE; + + bytes = (status >> 2) & 0x7FF; + if (bytes == 0) + return -EBADF; + + /* Output data buffer must be sufficient */ + if (--bytes > len) + return bytes; + + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_RD_FIFO); + if ((status & 0xFF) != 0x11) { + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_RD_CSR, 1 << 14); /* Read FIFO Reset */ + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_RD_CSR, 1 << 1); /* Read Transfer Complete */ + return -EBADF; + } + + if (status & 0x100) + return bytes; + + for (i = 0; i < len; i++) { + status = nfb_comp_read32(comp, NC_BW_BMC_SPI_RD_FIFO); + if (status == 0xDEADBEEF) { + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_RD_CSR, 1 << 1); /* Read Transfer Complete */ + return -EBADF; + } + + data[i] = status & 0xFF; + (*readen)++; + + if (status & 0x100) + break; + } + + /* Data continues */ + if (!(status & 0x100) || bytes > *readen) + return bytes - *readen; + + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_RD_CSR, 1 << 1); /* Read Transfer Complete */ + + return 0; +} + +static inline int nc_bw_bmc_receive_mctp(struct nc_bw_bmc *spi) +{ + return nc_bw_bmc_receive_mctp_ext(spi, spi->buffer, spi->buffer_len, &spi->recv_len); +} + +static inline int nc_bw_bmc_mctp_header_default(struct nc_bw_bmc *spi) +{ + int i = 0; + if (spi->buffer_len < 4) + return -ENOMEM; + spi->buffer[i++] = 0x01; /* hdr */ + spi->buffer[i++] = 0x00; /* dst */ + spi->buffer[i++] = 0x69; /* src */ + spi->buffer[i++] = 0xc8; /* 7:0 = som, eom, seq:2, to, tag:3 */ + spi->pos = i; + return 0; +} + +static inline int nc_bw_bmc_pldm_vndr(struct nc_bw_bmc *spi, int vndr_type) +{ + int i = spi->pos; + if (spi->buffer_len < spi->pos + 4) + return -ENOMEM; + spi->buffer[i++] = 0x01; /* MCTP type: PLDM */ + spi->buffer[i++] = 0x80; + spi->buffer[i++] = 0x3f; + spi->buffer[i++] = vndr_type; + spi->pos = i; + return 0; +} + +static inline int nc_bw_bmc_push(struct nc_bw_bmc *spi, const void *val, unsigned len) +{ + if (spi->buffer_len < spi->pos + len) + return -ENOMEM; + memcpy(spi->buffer + spi->pos, val, len); + spi->pos += len; + return 0; +} + +static inline int nc_bw_bmc_push_uint8(struct nc_bw_bmc *spi, uint8_t val) +{ + return nc_bw_bmc_push(spi, &val, sizeof(val)); +} + +static inline int nc_bw_bmc_push_uint16(struct nc_bw_bmc *spi, uint16_t val) +{ + /* TODO: add support for big-endian */ + return nc_bw_bmc_push(spi, &val, sizeof(val)); +} + +static inline int nc_bw_bmc_push_uint32(struct nc_bw_bmc *spi, uint32_t val) +{ + /* TODO: add support for big-endian */ + return nc_bw_bmc_push(spi, &val, sizeof(val)); +} + +static inline int nc_bw_bmc_pop_mctp_header(struct nc_bw_bmc *spi) +{ + if (spi->recv_len < 4) + return -ENOMEM; + spi->pos = 4; + return 0; +} + +static inline int nc_bw_bmc_pop_pldm_header(struct nc_bw_bmc *spi) +{ + if (spi->recv_len < spi->pos + 4) + return -ENOMEM; + spi->pos += 4; + return 0; +} + +static inline int nc_bw_bmc_pop(struct nc_bw_bmc *spi, void *buffer, unsigned len) +{ + if (spi->recv_len < spi->pos + len) + return -ENOMEM; + if (buffer) + memcpy(buffer, spi->buffer + spi->pos, len); + spi->pos += len; + return 0; +} + +static inline int nc_bw_bmc_pop_uint8(struct nc_bw_bmc *spi, uint8_t *val) +{ + return nc_bw_bmc_pop(spi, val, sizeof(*val)); +} + +static inline int nc_bw_bmc_pop_uint32(struct nc_bw_bmc *spi, uint32_t *val) +{ + /* TODO: add support for big-endian */ + return nc_bw_bmc_pop(spi, val, sizeof(*val)); +} + +static inline int nc_bw_bmc_download_file(struct nc_bw_bmc *spi, const char *path, unsigned char *buffer, unsigned int len) +{ + int ret = 0; + const uint32_t data_length = 512; + + uint32_t offset = 0; + + uint32_t out_offset = -1; + uint32_t response_count; + uint8_t cc; + + do { + ret |= nc_bw_bmc_mctp_header_default(spi); + ret |= nc_bw_bmc_pldm_vndr(spi, 0x14); + + ret |= nc_bw_bmc_push_uint32(spi, offset); + ret |= nc_bw_bmc_push_uint32(spi, data_length); + ret |= nc_bw_bmc_push_uint32(spi, strlen(path)); + ret |= nc_bw_bmc_push(spi, path, strlen(path)); + + if (ret) + return ret; + + ret = nc_bw_bmc_send_mctp(spi); + if (ret) + return ret; + + ret = nc_bw_bmc_receive_mctp(spi); + if (ret) + return ret; + + ret |= nc_bw_bmc_pop_mctp_header(spi); + ret |= nc_bw_bmc_pop_pldm_header(spi); + ret |= nc_bw_bmc_pop_uint8(spi, &cc); + ret |= nc_bw_bmc_pop_uint32(spi, &out_offset); + ret |= nc_bw_bmc_pop_uint32(spi, &response_count); + + ret |= nc_bw_bmc_pop(spi, buffer + offset, nc_bw_bmc_min(len - offset, response_count)); + + if (ret) + return ret; + + if (cc != 0) + return -ECANCELED; + + offset += response_count; + } while (response_count == data_length); + + return offset; +} + +static inline int nc_bw_bmc_file_unlink(struct nc_bw_bmc *spi, const char *path) +{ + int ret = 0; + uint8_t cc; + + ret |= nc_bw_bmc_mctp_header_default(spi); + ret |= nc_bw_bmc_pldm_vndr(spi, 0x18); + + ret |= nc_bw_bmc_push_uint16(spi, strlen(path)); + ret |= nc_bw_bmc_push(spi, path, strlen(path)); + + if (ret) + return ret; + + ret = nc_bw_bmc_send_mctp(spi); + if (ret) + return ret; + + ret = nc_bw_bmc_receive_mctp(spi); + if (ret) + return ret; + + ret |= nc_bw_bmc_pop_mctp_header(spi); + ret |= nc_bw_bmc_pop_pldm_header(spi); + ret |= nc_bw_bmc_pop_uint8(spi, &cc); + + if (ret) + return ret; + + if (cc != 0) + return -ECANCELED; + + return 0; +} + +static inline int nc_bw_bmc_file_move(struct nc_bw_bmc *spi, const char *src, const char *dst) +{ + int ret = 0; + uint8_t cc = 0; + + ret = 0; + ret |= nc_bw_bmc_mctp_header_default(spi); + ret |= nc_bw_bmc_pldm_vndr(spi, 0x19); + + ret |= nc_bw_bmc_push_uint16(spi, strlen(src)); + ret |= nc_bw_bmc_push_uint16(spi, strlen(dst)); + ret |= nc_bw_bmc_push(spi, src, strlen(src)); + ret |= nc_bw_bmc_push(spi, dst, strlen(dst)); + if (ret) + return -1; + + ret = nc_bw_bmc_send_mctp(spi); + if (ret) + return -1; + + ret = nc_bw_bmc_receive_mctp(spi); + if (ret) + return -1; + + ret |= nc_bw_bmc_pop_mctp_header(spi); + ret |= nc_bw_bmc_pop_pldm_header(spi); + ret |= nc_bw_bmc_pop_uint8(spi, &cc); + + if (ret) + return -1; + + if (cc != 0) + return -ECANCELED; + + return 0; +} + +static inline int nc_bw_bmc_file_upload(struct nc_bw_bmc *spi, const char *path, const void *data, unsigned len) +{ + int ret = 0; + uint32_t data_length = 512; + + uint32_t offset = 0; + + uint8_t cc = 0; + + do { + data_length = nc_bw_bmc_min(len, data_length); + + ret |= nc_bw_bmc_mctp_header_default(spi); + ret |= nc_bw_bmc_pldm_vndr(spi, 0x13); + + ret |= nc_bw_bmc_push_uint32(spi, strlen(path)); + ret |= nc_bw_bmc_push_uint32(spi, offset); + ret |= nc_bw_bmc_push_uint32(spi, data_length); + ret |= nc_bw_bmc_push(spi, path, strlen(path)); + + ret |= nc_bw_bmc_push(spi, (unsigned char*)data + offset, data_length); + + ret = nc_bw_bmc_send_mctp(spi); + if (ret) + return ret; + + ret = nc_bw_bmc_receive_mctp(spi); + if (ret) + return ret; + + ret |= nc_bw_bmc_pop_mctp_header(spi); + ret |= nc_bw_bmc_pop_pldm_header(spi); + ret |= nc_bw_bmc_pop_uint8(spi, &cc); + + if (ret) + return ret; + + if (cc != 0) + return -ECANCELED; + + offset += data_length; + } while (offset != len); + + return 0; +} + +static inline int nc_bw_bmc_fpga_load_ext(struct nc_bw_bmc *spi, const void *data, unsigned len, unsigned flash_offset, void (*cb)(void*, unsigned current_offset), void *cb_priv) +{ + int ret = 0; + uint32_t data_length = 512; + + uint32_t offset = 0; + + uint8_t cc = 0; + uint8_t transfer_flag = 0; + + if (cb) + cb(cb_priv, 0); + + do { + data_length = nc_bw_bmc_min(len - offset, data_length); + + if (offset == 0) { + transfer_flag = (len == data_length + offset ? 0x05 : 0x00); + } else { + transfer_flag = (len == data_length + offset ? 0x04 : 0x01); + } + ret |= nc_bw_bmc_mctp_header_default(spi); + ret |= nc_bw_bmc_pldm_vndr(spi, 0x17); + + ret |= nc_bw_bmc_push_uint8(spi, transfer_flag); + ret |= nc_bw_bmc_push_uint32(spi, flash_offset); + ret |= nc_bw_bmc_push_uint16(spi, data_length); + + ret |= nc_bw_bmc_push(spi, (unsigned char*)data + offset, data_length); + + ret = nc_bw_bmc_send_mctp(spi); + if (ret) + return ret; + + ret = nc_bw_bmc_receive_mctp(spi); + if (ret) + return ret; + + ret |= nc_bw_bmc_pop_mctp_header(spi); + ret |= nc_bw_bmc_pop_pldm_header(spi); + ret |= nc_bw_bmc_pop_uint8(spi, &cc); + + if (ret) + return ret; + + if (cc != 0) + return -ECANCELED; + + offset += data_length; + if (cb) + cb(cb_priv, offset); + } while (offset != len); + + return 0; +} + +int nc_bw_bmc_send_reload(struct nc_bw_bmc * spi, const char *filename) +{ + int ret = 0; + int offset = 0; + static const char *target_path = "/fpga/load/name"; + + ret |= nc_bw_bmc_mctp_header_default(spi); + ret |= nc_bw_bmc_pldm_vndr(spi, 0x13); + + ret |= nc_bw_bmc_push_uint32(spi, strlen(target_path)); + ret |= nc_bw_bmc_push_uint32(spi, offset); + ret |= nc_bw_bmc_push_uint32(spi, strlen(filename) + 1); + + ret |= nc_bw_bmc_push(spi, target_path, strlen(target_path)); + ret |= nc_bw_bmc_push(spi, filename, strlen(filename) + 1); + + nc_bw_bmc_send_mctp_ext(spi, spi->buffer, spi->pos, 1, 0); + return 0; +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* BW_BMC_SPI_H */ From b445209cdada50d2de5211ea0c55f7dee0781f37 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 3 Feb 2025 08:49:08 +0100 Subject: [PATCH 278/518] feat(drivers): make nfb_fdt_create_binary_slot public --- drivers/kernel/drivers/nfb/pci.c | 4 ++-- drivers/kernel/drivers/nfb/pci.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 3066ca24..b75ce7a8 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -33,7 +33,7 @@ static bool fallback_fdt = 1; static bool fallback_fdt_boot = 0; -static bool flash_recovery_ro = 1; +bool flash_recovery_ro = 1; struct mutex global_pci_device_list_lock; struct mutex global_try_attach_lock; @@ -107,7 +107,7 @@ MODULE_DEVICE_TABLE(pci, nfb_ids); /* * nfb_fdt_create_binary_slot - add one binary slot to DT for Flash access and booting */ -static int nfb_fdt_create_binary_slot(void *fdt, int node, char *name, char *title, int id, +int nfb_fdt_create_binary_slot(void *fdt, int node, const char *name, const char *title, int id, int boot_id, int mtd, int base, int size) { int fdt_offset, fdt_subnode_offset; diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 23465a6b..73a06bae 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -90,4 +90,7 @@ struct nfb_pci_device *nfb_pci_attach_endpoint(struct nfb_device *nfb, struct nf void nfb_pci_attach_all_slaves(struct nfb_device *nfb, struct pci_bus *bus); void nfb_pci_detach_all_slaves(struct nfb_device *nfb); +int nfb_fdt_create_binary_slot(void *fdt, int node, const char *name, const char *title, int id, + int boot_id, int mtd, int base, int size); + #endif // NFB_PCI_H From 6b254e66501d8f2e03e29717ce25321317c78d53 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 3 Feb 2025 08:45:03 +0100 Subject: [PATCH 279/518] feat(drivers - boot): add NFB_BOOT_IOC_LOAD ioctl and nfb_boot_load --- drivers/kernel/drivers/nfb/boot/boot.c | 97 +++++++++++++++++++++++++ drivers/kernel/drivers/nfb/boot/boot.h | 1 + drivers/kernel/include/linux/nfb/boot.h | 27 +++++++ 3 files changed, 125 insertions(+) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 30250a1b..aa7a683e 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -210,6 +210,100 @@ int nfb_boot_get_sensor_ioc(struct nfb_boot *boot, struct nfb_boot_ioc_sensor __ return 0; } +int nfb_boot_load(struct nfb_boot *boot, + struct nfb_boot_ioc_load __user *_load, + void *app_priv) +{ + struct nfb_boot_ioc_load load; + struct nfb_boot_ioc_load load_orig; + + int ret = 0; + char * buf = NULL; + char * name; + char * node; + unsigned char * data; + + if (copy_from_user(&load, _load, sizeof(load))) + return -EFAULT; + + /* Copy fields from user */ + + if (mutex_trylock(&boot->load_mutex) == 0) + return -EBUSY; + + load_orig = load; + + if (load.name_size != 0 || load.node_size != 0 || load.data_size != 0) { + buf = vmalloc(load.name_size + load.node_size + load.data_size); + if (buf == NULL) { + ret = -ENOMEM; + goto err_vmalloc; + } + } + + /* get filename */ + name = buf; + ret = strncpy_from_user(name, load.name, load.name_size); + if (load.name_size != 0 && ret != load.name_size - 1) { + ret = -EINVAL; + goto err_copy_items; + } + load.name = name; + + /* get FDT node path */ + node = name + load.name_size; + ret = strncpy_from_user(node, load.node, load.node_size); + if (load.node_size != 0 && ret != load.node_size - 1) { + ret = -EINVAL; + goto err_copy_items; + } + load.node = node; + + /* get data */ + data = node + load.node_size; + ret = copy_from_user(data, load.data, load.data_size); + if (ret != 0) { + ret = -EINVAL; + goto err_copy_items; + } + load.data = data; + + /* call the subdriver */ + ret = -ENXIO; + if (ret) { + goto err_load; + } + +#if 0 + /* Copy "return" values */ + load_orig.phase = load.phase; + load_orig.progress = load.progress; + if (copy_to_user(_load, &load_orig, sizeof(load_orig))) + return -EFAULT; +#else + load.name = load_orig.name; + load.node = load_orig.node; + load.data = load_orig.data; + + if (copy_to_user(_load, &load, sizeof(load))) { + ret = -EFAULT; + goto err_copy_to_user; + } +#endif + + vfree(buf); + mutex_unlock(&boot->load_mutex); + return ret; + +err_copy_to_user: +err_load: +err_copy_items: + vfree(buf); +err_vmalloc: + mutex_unlock(&boot->load_mutex); + return ret; +} + long nfb_boot_ioctl(void *priv, void *app_priv, struct file *file, unsigned int cmd, unsigned long arg) { struct nfb_boot *nfb_boot = priv; @@ -233,6 +327,8 @@ long nfb_boot_ioctl(void *priv, void *app_priv, struct file *file, unsigned int return nfb_boot_ioctl_mtd_erase(nfb_boot, argp); case NFB_BOOT_IOC_SENSOR_READ: return nfb_boot_get_sensor_ioc(nfb_boot, argp); + case NFB_BOOT_IOC_LOAD: + return nfb_boot_load(nfb_boot, argp, app_priv); default: return -ENOTTY; } @@ -265,6 +361,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) *priv = boot; boot->nfb = nfb; + mutex_init(&boot->load_mutex); #ifdef CONFIG_NFB_ENABLE_PMCI ret = nfb_pmci_attach(boot); ret = nfb_spi_attach(boot); diff --git a/drivers/kernel/drivers/nfb/boot/boot.h b/drivers/kernel/drivers/nfb/boot/boot.h index 1f5e3e39..687578f9 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.h +++ b/drivers/kernel/drivers/nfb/boot/boot.h @@ -47,6 +47,7 @@ struct nfb_boot { int mtd_bit; unsigned long mtd_size; int fb_active_flash; + struct mutex load_mutex; }; struct mtd_info *cfi_probe(struct map_info *map); diff --git a/drivers/kernel/include/linux/nfb/boot.h b/drivers/kernel/include/linux/nfb/boot.h index 52d8cb4f..ac0d7fd1 100644 --- a/drivers/kernel/include/linux/nfb/boot.h +++ b/drivers/kernel/include/linux/nfb/boot.h @@ -57,6 +57,30 @@ struct nfb_boot_ioc_sensor { long value; }; + +#define NFB_BOOT_IOC_LOAD_CMD_NONE 0 +#define NFB_BOOT_IOC_LOAD_CMD_ERASE (1 << 0) +#define NFB_BOOT_IOC_LOAD_CMD_WRITE (1 << 1) +#define NFB_BOOT_IOC_LOAD_CMD_PRIORITY (1 << 2) + +#define NFB_BOOT_IOC_LOAD_FLAG_USE_ID (1 << 0) +#define NFB_BOOT_IOC_LOAD_FLAG_USE_NODE (1 << 1) + +struct nfb_boot_ioc_load +{ + __u64 cmd; /* bitmask: erase, write */ + __u64 flags; + __u64 id; + __u64 data_size; + + __u32 node_size; /* \0 must be included */ + __u32 name_size; /* \0 must be included */ + char *data; + char *node; /* device tree path to unit / image */ + const char *name; /* name of the image */ +}; + + /* * Ioctl definitions */ @@ -71,4 +95,7 @@ struct nfb_boot_ioc_sensor { #define NFB_BOOT_IOC_SENSOR_READ _IOR(NFB_BOOT_IOC, 5, struct nfb_boot_ioc_sensor) +#define NFB_BOOT_IOC_LOAD _IOWR(NFB_BOOT_IOC, 6, struct nfb_boot_ioc_load) + + #endif /* _LINUX_NFB_BOOT_H_ */ From 152f5bb011a20e543d0c312918ccd781b613811c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 4 Feb 2025 12:43:57 +0100 Subject: [PATCH 280/518] feat(drivers - boot_load_status): add progress indicator via sysfs file --- drivers/kernel/drivers/nfb/boot/boot.c | 7 +++++++ drivers/kernel/drivers/nfb/boot/boot.h | 9 +++++++++ drivers/kernel/drivers/nfb/char.c | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index aa7a683e..2514855e 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -210,6 +210,13 @@ int nfb_boot_get_sensor_ioc(struct nfb_boot *boot, struct nfb_boot_ioc_sensor __ return 0; } +ssize_t nfb_boot_load_get_status(struct nfb_boot *boot, char *buf) +{ + return scnprintf(buf, PAGE_SIZE, "0,%u,%u,%u,%u,%u,%u\n", + boot->load.start_ops, boot->load.done_ops, boot->load.pending_ops, + boot->load.current_op, boot->load.current_op_progress_max, boot->load.current_op_progress); +} + int nfb_boot_load(struct nfb_boot *boot, struct nfb_boot_ioc_load __user *_load, void *app_priv) diff --git a/drivers/kernel/drivers/nfb/boot/boot.h b/drivers/kernel/drivers/nfb/boot/boot.h index 687578f9..a4ca3d8f 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.h +++ b/drivers/kernel/drivers/nfb/boot/boot.h @@ -48,6 +48,14 @@ struct nfb_boot { unsigned long mtd_size; int fb_active_flash; struct mutex load_mutex; + struct boot_load { + unsigned start_ops; + unsigned done_ops; + unsigned pending_ops; + unsigned current_op; + unsigned current_op_progress_max; + unsigned current_op_progress; + } load; }; struct mtd_info *cfi_probe(struct map_info *map); @@ -80,6 +88,7 @@ int nfb_boot_ioctl_error_disable(struct nfb_boot *nfb_boot); int nfb_boot_reload(void *arg); int nfb_boot_get_sensor_ioc(struct nfb_boot *boot, struct nfb_boot_ioc_sensor __user *); +ssize_t nfb_boot_load_get_status(struct nfb_boot *boot, char *buf); #define NFB_BOOT_FLAG_FB_SELECT_FLASH 1 #define NFB_BOOT_FLAG_FLASH_SET_ASYNC 2 diff --git a/drivers/kernel/drivers/nfb/char.c b/drivers/kernel/drivers/nfb/char.c index 5adf5ada..e97ec4d3 100644 --- a/drivers/kernel/drivers/nfb/char.c +++ b/drivers/kernel/drivers/nfb/char.c @@ -19,6 +19,8 @@ #include "nfb.h" #include "ndp/ndp.h" +#include "boot/boot.h" + /* Global variables */ static int nfb_major; @@ -50,15 +52,28 @@ static ssize_t nfb_char_get_pcislot(struct device *dev, struct device_attribute return scnprintf(buf, PAGE_SIZE, "%s\n", pci_name(nfb->pci)); } +static ssize_t nfb_boot_get_load_status(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct nfb_device *nfb = dev_get_drvdata(dev); + struct nfb_boot *nfb_boot = nfb_get_priv_for_attach_fn(nfb, nfb_boot_attach); + + if (nfb_boot == NULL) + return scnprintf(buf, PAGE_SIZE, "\n"); + + return nfb_boot_load_get_status(nfb_boot, buf); +} + /* Attributes for sysfs - declarations */ DEVICE_ATTR(serial, S_IRUGO, nfb_char_get_serial, NULL); DEVICE_ATTR(cardname, S_IRUGO, nfb_char_get_cardname, NULL); DEVICE_ATTR(pcislot, S_IRUGO, nfb_char_get_pcislot, NULL); +DEVICE_ATTR(boot_load_status, S_IRUGO, nfb_boot_get_load_status, NULL); struct attribute *nfb_char_attrs[] = { &dev_attr_serial.attr, &dev_attr_cardname.attr, &dev_attr_pcislot.attr, + &dev_attr_boot_load_status.attr, NULL, }; From d43ed3ea8864eb203e175922ddf7fe68350d1fe4 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 3 Feb 2025 07:21:21 +0100 Subject: [PATCH 281/518] feat(drivers - boot): add BittWare BMC SPI controller support --- drivers/kernel/drivers/nfb/Makefile | 2 +- drivers/kernel/drivers/nfb/boot/boot.c | 14 +- drivers/kernel/drivers/nfb/boot/boot.h | 3 + drivers/kernel/drivers/nfb/boot/bw-bmc.c | 553 +++++++++++++++++++ drivers/kernel/drivers/nfb/boot/nfb-bw-bmc.h | 15 + drivers/kernel/drivers/nfb/boot/reload.c | 2 + 6 files changed, 585 insertions(+), 4 deletions(-) create mode 100644 drivers/kernel/drivers/nfb/boot/bw-bmc.c create mode 100644 drivers/kernel/drivers/nfb/boot/nfb-bw-bmc.h diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index 318383fc..829fe9f6 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -15,7 +15,7 @@ nfb-objs += ../spi/spi-xilinx.o nfb-objs += mi/mi.o nfb-objs += ndp/ctrl.o ndp/ctrl_ndp.o ndp/channel.o ndp/subscription.o ndp/subscriber.o ndp/ring.o ndp/char.o ndp/driver.o ndp/kndp.o nfb-objs += ndp_netdev/core.o -nfb-objs += boot/flash.o boot/reload.o boot/boot.o boot/gecko.o boot/sdm.o +nfb-objs += boot/flash.o boot/reload.o boot/boot.o boot/gecko.o boot/sdm.o boot/bw-bmc.o ifndef CONFIG_REGMAP_SPI_AVMM nfb-objs += ../base/regmap/regmap-spi-avmm.o endif diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 2514855e..fe93dc0f 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -276,7 +276,12 @@ int nfb_boot_load(struct nfb_boot *boot, load.data = data; /* call the subdriver */ - ret = -ENXIO; + if (boot->bw_bmc) { + ret = nfb_boot_bw_bmc_load(boot, &load); + } else { + ret = -ENXIO; + } + if (ret) { goto err_load; } @@ -373,6 +378,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) ret = nfb_pmci_attach(boot); ret = nfb_spi_attach(boot); #endif + ret = nfb_boot_bw_bmc_attach(boot); /* Cards with Intel FPGA (Stratix10, Agilex) use Secure Device Manager for QSPI Flash access and Boot */ boot->sdm = NULL; boot->sdm_boot_en = 0; @@ -397,7 +403,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) fdt_offset = fdt_node_offset_by_compatible(nfb->fdt, -1, "netcope,boot_controller"); // FIXME: better create some general boot controller interface if (fdt_offset < 0) { - if (boot->sdm_boot_en == 0 && boot->pmci == NULL && boot->m10bmc_spi == NULL) { + if (boot->sdm_boot_en == 0 && boot->pmci == NULL && boot->m10bmc_spi == NULL && boot->bw_bmc == NULL) { ret = -ENODEV; dev_warn(&nfb->pci->dev, "nfb_boot: No boot_controller found in FDT.\n"); goto err_nocomp; @@ -407,7 +413,7 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) } boot->comp = nfb_comp_open(nfb, fdt_offset); - if (!boot->comp && boot->pmci == NULL && boot->m10bmc_spi == NULL) { + if (!boot->comp && boot->pmci == NULL && boot->m10bmc_spi == NULL && boot->bw_bmc == NULL) { ret = -ENODEV; goto err_comp_open; } @@ -503,6 +509,8 @@ void nfb_boot_detach(struct nfb_device* nfb, void *priv) if (boot->comp) nfb_comp_close(boot->comp); sdm_free(boot->sdm); + + nfb_boot_bw_bmc_detach(boot); #ifdef CONFIG_NFB_ENABLE_PMCI if (boot->pmci) nfb_pmci_detach(boot); diff --git a/drivers/kernel/drivers/nfb/boot/boot.h b/drivers/kernel/drivers/nfb/boot/boot.h index a4ca3d8f..f91b859c 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.h +++ b/drivers/kernel/drivers/nfb/boot/boot.h @@ -25,6 +25,7 @@ #include "sdm.h" #include "nfb-pmci.h" #include "nfb-spi.h" +#include "nfb-bw-bmc.h" struct nfb_boot { struct nfb_comp *comp; @@ -33,6 +34,8 @@ struct nfb_boot { struct pmci_device *pmci; struct m10bmc_spi_nfb_device *m10bmc_spi; + void *bw_bmc; + int num_image; int num_flash; diff --git a/drivers/kernel/drivers/nfb/boot/bw-bmc.c b/drivers/kernel/drivers/nfb/boot/bw-bmc.c new file mode 100644 index 00000000..2cba6d9a --- /dev/null +++ b/drivers/kernel/drivers/nfb/boot/bw-bmc.c @@ -0,0 +1,553 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * Boot driver module for BittWare BMC + * + * Copyright (C) 2017-2022 CESNET + * Author(s): + * Martin Spinler + */ + +#include + +#include "../nfb.h" +#include "../pci.h" + +#include "boot.h" + +#include + +#include + +extern bool flash_recovery_ro; + +struct bw_file_entry { + int id; + unsigned offset; + int size; + int priority; + const char *name; + + const char *_title; + int _empty; +}; + +static int bw_file_entry_sort_by_offset(const void *lhs, const void *rhs) +{ + const struct bw_file_entry *l = lhs; + const struct bw_file_entry *r = rhs; + + if (l->offset < r->offset) + return -1; + if (l->offset > r->offset) + return 1; + return 0; +} + +int nfb_boot_bw_bmc_parse_partition(struct bw_file_entry *p, char **buffer) +{ + const char *bbeg; + char *bend; + + char name_prefix[] = "0x00000000-"; + + bbeg = *buffer; + + /* parse id */ + if (sscanf(bbeg, "%d,", &p->id) != 1) + return 1; + + bend = strstr(bbeg, ","); + if (bend == NULL) + return 2; + + /* parse name */ + bbeg = bend + 1; + bend = strstr(bbeg, ","); + if (bend == NULL) + return 3; + + + bend[0] = 0; + p->name = bbeg; + + + /* parse offset */ + bbeg = bend + 1; + if (sscanf(bbeg, "%x,", &p->offset) != 1) + return 4; + + bend = strstr(bbeg, ","); + if (bend == NULL) + return 5; + + /* parse size */ + bbeg = bend + 1; + if (sscanf(bbeg, "%d,", &p->size) != 1) + return 6; + + bend = strstr(bbeg, ","); + if (bend == NULL) + return 7; + + /* parse priority */ + bbeg = bend + 1; + if (sscanf(bbeg, "%d,", &p->priority) != 1) + return 8; + + bend = strstr(bbeg, "\n"); + if (bend == NULL) + return 9; + + bend += 1; + + p->_title = p->name; + + snprintf(name_prefix, sizeof(name_prefix), "0x%08x-", p->offset); + if (strncmp(p->name, name_prefix, strlen(name_prefix)) == 0) { + p->_title += strlen(name_prefix); + } + + *buffer = bend; + return 0; +} + +static inline void nfb_boot_bw_bmc_add_partition(void *fdt, int node, int *id, struct bw_file_entry *p, unsigned *flag) +{ + int tmp; + char node_name[32]; + + int i = *id; + + if (p->_empty) { + sprintf(node_name, "empty%d", i); + *id = i + 1; + } else { + if (p->offset == 0) { + i = 1; + *flag |= 1; + } else if ((*flag & 2) == 0) { + i = 0; + *flag |= 2; + } else { + *id = i + 1; + } + + sprintf(node_name, "image%d", i); + } + + tmp = nfb_fdt_create_binary_slot(fdt, node, node_name, p->_title, i, p->_empty ? -1 : i, -1, p->offset, p->size); + if (p->_empty) { + fdt_setprop(fdt, tmp, "empty", NULL, 0); + } else { + fdt_setprop_u32(fdt, tmp, "priority", p->priority); + fdt_setprop_string(fdt, tmp, "filename", p->name); + } + + if (i == 1 && flash_recovery_ro) { + tmp = fdt_subnode_offset(fdt, tmp, "control-param"); + fdt_setprop(fdt, tmp, "ro", NULL, 0); + } +} + +int nfb_boot_bw_bmc_load_partition_table(struct nfb_boot *boot) +{ + static const int buffer_size = 16384; + + void *fdt; + char *buffer; + char *bbeg; + + /* ID 1 is reserved for image at offset 0x0: power-on (RO) + * ID 0 is for first image after ID 1 */ + int id = 2; + int i; + int ret; + int node; + unsigned max_size = 0, add_flag = 0; + + int p_cnt = 0; + struct bw_file_entry *p = NULL, *p_buffer = NULL; + struct bw_file_entry pe; + + const char * fw_table = "/fpga/table.csv"; + const char *card_name; + + fdt = nfb_get_fdt(boot->nfb); + node = fdt_path_offset(fdt, "/firmware"); + card_name = fdt_getprop(fdt, node, "card-name", NULL); + + if (card_name == NULL) { + return -ENODEV; + } else if (strcmp(card_name, "IA-440I") == 0) { + max_size = 0x10000000; + } else { + return -ENODEV; + } + + node = nfb_comp_find(boot->nfb, "bittware,bmc", 0); + if (node < 0) + return -ENODEV; + + node = fdt_add_subnode(fdt, node, "images"); + + buffer = kmalloc(buffer_size, GFP_KERNEL); + if (buffer == NULL) + return -ENOMEM; + + /* Download Flash partition table */ + ret = nc_bw_bmc_download_file(boot->bw_bmc, fw_table, buffer, buffer_size); + if (ret < 0) { + ret = -EPIPE; + goto err_dl_file; + } else if ((unsigned)ret >= buffer_size) { + ret = -ENOMEM; + goto err_dl_file_small; + } + buffer[ret] = 0; + + pe.name = pe._title = ""; + pe.offset = 0; + pe._empty = 1; + + bbeg = buffer; + do { + p = p_buffer; + p_buffer = krealloc(p_buffer, (p_cnt + 1) * sizeof(*p), GFP_KERNEL); + if (p_buffer == NULL) { + kfree(p); + ret = -ENOMEM; + goto err_parse; + } + + p = p_buffer + p_cnt; + p->_empty = 0; + ret = nfb_boot_bw_bmc_parse_partition(p, &bbeg); + if (ret == 0) { + p_cnt++; + + } + } while (ret == 0); + + sort(p_buffer, p_cnt, sizeof(*p), &bw_file_entry_sort_by_offset, NULL); + for (i = 0; i < p_cnt; i++) { + p = p_buffer + i; + + if (pe.offset < p->offset) { + /* TODO: align offset */ + pe.size = p->offset - pe.offset; + nfb_boot_bw_bmc_add_partition(fdt, node, &id, &pe, &add_flag); + } + + nfb_boot_bw_bmc_add_partition(fdt, node, &id, p, &add_flag); + + pe.offset = p->offset + p->size; + pe.offset = (pe.offset + 0xFFF) & ~0xFFF; + } + + if (pe.offset < max_size) { + pe.size = max_size - pe.offset; + nfb_boot_bw_bmc_add_partition(fdt, node, &id, &pe, &add_flag); + } + kfree(buffer); + return 0; + +err_parse: +err_dl_file_small: +err_dl_file: + kfree(buffer); + return ret; +} + +int nfb_boot_bw_bmc_update_binary_slots(struct nfb_boot *boot) +{ + void *fdt; + int node; + + fdt = nfb_get_fdt(boot->nfb); + node = nfb_comp_find(boot->nfb, "bittware,bmc", 0); + node = fdt_subnode_offset(fdt, node, "images"); + if (node >= 0) + fdt_del_node(fdt, node); + + nfb_boot_bw_bmc_load_partition_table(boot); + return 0; +} + +int nfb_boot_bw_bmc_attach(struct nfb_boot* boot) +{ + int node = -1; + + boot->bw_bmc = NULL; + + node = nfb_comp_find(boot->nfb, "bittware,bmc", 0); + if (node < 0) + return -ENODEV; + + boot->bw_bmc = nc_bw_bmc_open(boot->nfb, node, NULL, 2048); + if (boot->bw_bmc == NULL) + return -ENODEV; + + nfb_boot_bw_bmc_load_partition_table(boot); + + return 0; +} + +void nfb_boot_bw_bmc_detach(struct nfb_boot* boot) +{ + if (boot->bw_bmc) { + nc_bw_bmc_close(boot->bw_bmc); + boot->bw_bmc = NULL; + } +} + +void nfb_boot_bw_bmc_load_cb(void *priv, unsigned offset) +{ + struct nfb_boot* boot = priv; + boot->load.current_op_progress = offset; + + if ((offset & 0x1FFFF) == 0) + cond_resched(); +} + +int nfb_boot_bw_bmc_set_priority(struct nfb_boot *boot, struct nfb_boot_ioc_load *load) +{ + int ret = 0; + int i; + int node; + int proplen; + const uint32_t *prop32; + uint64_t id, prio_pid, prio_val; + size_t prio_size = 0, prio_add; + unsigned char *prio_data = NULL, *prio_data_tmp; + const size_t sz_prio_item = sizeof(prio_pid) + sizeof(prio_val); + const char *prop; + + void *fdt = nfb_get_fdt(boot->nfb); + + if (load->data_size % sz_prio_item) + return -EINVAL; + + fdt_for_each_compatible_node(fdt, node, "netcope,binary_slot") { + prop32 = fdt_getprop(fdt, node, "id", &proplen); + if (proplen != sizeof(*prop32)) + continue; + id = fdt32_to_cpu(*prop32); + + for (i = 0; i < load->data_size / sz_prio_item; i++) { + prio_pid = *(uint64_t*) (load->data + i * sz_prio_item); + prio_val = *(uint64_t*) (load->data + i * sz_prio_item + sizeof(prio_pid)); + if (id == prio_pid) { + prop = fdt_getprop(fdt, node, "filename", &proplen); + if (prop == NULL) { + ret = -ENODEV; + break; + } + prio_add = strlen(prop) + 1 + 1 + 1; + prio_data_tmp = prio_data; + prio_data = krealloc(prio_data, prio_size + prio_add, GFP_KERNEL); + if (prio_data == NULL) { + kfree(prio_data_tmp); + ret = -ENOMEM; + break; + } + + strcpy(prio_data + prio_size, prop); + prio_data[prio_size + prio_add - 2] = (uint8_t) prio_val; + prio_data[prio_size + prio_add - 1] = '\n'; + prio_size += prio_add; + } + } + if (ret) + break; + } + if (ret) { + if (prio_data) + kfree(prio_data); + return ret; + } + + prio_add = 1 + 1 + 1; + prio_data_tmp = prio_data; + prio_data = krealloc(prio_data, prio_size + prio_add, GFP_KERNEL); + if (prio_data == NULL) { + kfree(prio_data_tmp); + return -ENOMEM; + } + + prio_data[prio_size+prio_add-3] = '\0'; + prio_data[prio_size+prio_add-2] = (uint8_t) 255; + prio_data[prio_size+prio_add-1] = '\n'; + prio_size += prio_add; + + ret = nc_bw_bmc_file_upload(boot->bw_bmc, "/fpga/priority.txt", prio_data, prio_size); + kfree(prio_data); + + return ret; +} + +int nfb_boot_bw_bmc_load(struct nfb_boot *boot, + struct nfb_boot_ioc_load *load/*, + struct nfb_boot_app_priv * app_priv*/) +{ + #define NFB_BOOT_BW_BMC_PATH_PREFIX "/fpga/" + + char load_path[] = NFB_BOOT_BW_BMC_PATH_PREFIX "00000000"; + + int ret = 0; + char * buf; + int node_image, node_cp, node_parent, node_next, node_next_cp; + + uint32_t offset, offset_next, size, size_next; + void *fdt; + const void *prop; + + unsigned buf_size; + const char *name; + + int update_nodes = 0; + + if (load->cmd == NFB_BOOT_IOC_LOAD_CMD_PRIORITY) { + ret = nfb_boot_bw_bmc_set_priority(boot, load); + if (ret) + return ret; + nfb_boot_bw_bmc_update_binary_slots(boot); + return 0; + } + + fdt = nfb_get_fdt(boot->nfb); + node_image = fdt_path_offset(fdt, load->node); + node_parent = fdt_parent_offset(fdt, node_image); + + node_cp = fdt_subnode_offset(fdt, node_image, "control-param"); + ret = fdt_getprop32(fdt, node_cp, "base", &offset); + if (ret) + return -EINVAL; + ret = fdt_getprop32(fdt, node_cp, "size", &size); + if (ret) + return -EINVAL; + + fdt_for_each_subnode(node_next, fdt, node_parent) { + if (node_next == node_image) + continue; + + node_next_cp = fdt_subnode_offset(fdt, node_next, "control-param"); + + ret = fdt_getprop32(fdt, node_next_cp, "base", &offset_next); + if (ret) + return -EINVAL; + ret = fdt_getprop32(fdt, node_next_cp, "size", &size_next); + if (ret) + return -EINVAL; + prop = fdt_getprop(fdt, node_next, "empty", NULL); + + if (((offset + size + 0xFFF) & ~0xFFF) == offset_next && prop != NULL) { + /* Next image is empty, its space can be used as well */ + size += size_next; + break; + } + } + + if (size < load->data_size) + return -ENOMEM; + + name = fdt_getprop(fdt, node_image, "filename", NULL); + if (name == NULL) + return -EINVAL; + + prop = fdt_getprop(fdt, node_image, "empty", NULL); + + boot->load.start_ops = load->cmd; + boot->load.pending_ops = load->cmd; + + /* execute requested commands */ + if (load->cmd & NFB_BOOT_IOC_LOAD_CMD_ERASE) { + boot->load.current_op = NFB_BOOT_IOC_LOAD_CMD_ERASE; + + boot->load.current_op_progress_max = 1; + boot->load.current_op_progress = 0; + + buf_size = strlen(NFB_BOOT_BW_BMC_PATH_PREFIX) + strlen(name) + 1; + buf = kzalloc(buf_size, GFP_KERNEL); + if (buf == NULL) { + ret = -ENOMEM; + goto err_cmd; + } + + snprintf(buf, buf_size, NFB_BOOT_BW_BMC_PATH_PREFIX "%s", name); + + ret = nc_bw_bmc_file_unlink(boot->bw_bmc, buf); + kfree(buf); + if (ret) + goto err_cmd; + + update_nodes |= NFB_BOOT_IOC_LOAD_CMD_ERASE; + boot->load.current_op_progress = 1; + } else if (prop == NULL) { + /* This slot is not empty, must be erased! */ + ret = -EINVAL; + goto err_cmd; + } + + if (load->cmd & NFB_BOOT_IOC_LOAD_CMD_WRITE) { + boot->load.current_op = NFB_BOOT_IOC_LOAD_CMD_WRITE; + + boot->load.current_op_progress_max = load->data_size; + ret = nc_bw_bmc_fpga_load_ext(boot->bw_bmc, load->data, load->data_size, offset, nfb_boot_bw_bmc_load_cb, boot); + if (ret) + goto err_cmd; + + buf_size = strlen(NFB_BOOT_BW_BMC_PATH_PREFIX "0x00000000-") + load->name_size; + buf = kzalloc(buf_size, GFP_KERNEL); + if (buf == NULL) { + ret = -ENOMEM; + goto err_cmd; + } + snprintf(load_path, sizeof(load_path), NFB_BOOT_BW_BMC_PATH_PREFIX "%08x", offset); + snprintf(buf, buf_size, NFB_BOOT_BW_BMC_PATH_PREFIX "0x%08x-%s", offset, load->name); + + ret = nc_bw_bmc_file_move(boot->bw_bmc, load_path, buf); + kfree(buf); + if (ret) + goto err_cmd; + + update_nodes |= NFB_BOOT_IOC_LOAD_CMD_WRITE; + } + + boot->load.current_op = NFB_BOOT_IOC_LOAD_CMD_NONE; + + if (update_nodes) + nfb_boot_bw_bmc_update_binary_slots(boot); + + return 0; + +err_cmd: + boot->load.current_op = NFB_BOOT_IOC_LOAD_CMD_NONE; + if (update_nodes) + nfb_boot_bw_bmc_update_binary_slots(boot); + return ret; +} + +int nfb_boot_bw_bmc_reload(struct nfb_boot *boot) +{ + int node; + + int proplen; + const fdt32_t *prop32; + const void *filename = NULL; + + fdt_for_each_compatible_node(boot->nfb->fdt, node, "netcope,binary_slot") { + prop32 = fdt_getprop(boot->nfb->fdt, node, "boot_id", &proplen); + if (proplen != sizeof(*prop32)) + continue; + + if (fdt32_to_cpu(*prop32) == boot->num_image) { + filename = fdt_getprop(boot->nfb->fdt, node, "filename", &proplen); + break; + } + } + + if (filename == NULL) + return -ENODEV; + + return nc_bw_bmc_send_reload(boot->bw_bmc, filename); +} diff --git a/drivers/kernel/drivers/nfb/boot/nfb-bw-bmc.h b/drivers/kernel/drivers/nfb/boot/nfb-bw-bmc.h new file mode 100644 index 00000000..d664d633 --- /dev/null +++ b/drivers/kernel/drivers/nfb/boot/nfb-bw-bmc.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * Boot driver module header for BittWare BMC + * + * Copyright (C) 2017-2022 CESNET + * Author(s): + * Martin Spinler + */ + +int nfb_boot_bw_bmc_attach(struct nfb_boot* boot); +void nfb_boot_bw_bmc_detach(struct nfb_boot* boot); +int nfb_boot_bw_bmc_load(struct nfb_boot *nfb_boot, + struct nfb_boot_ioc_load __user *_load/*, + struct nfb_boot_app_priv * app_priv*/); +int nfb_boot_bw_bmc_reload(struct nfb_boot *boot); diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index fb8fb42a..827e1ced 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -264,6 +264,8 @@ int nfb_boot_reload(void *arg) } else if (boot->m10bmc_spi) { boot->m10bmc_spi->image_load[boot->num_image].load_image(boot->m10bmc_spi->sec); return nfb_boot_n5014_reload_rescan(master); + } else if (boot->bw_bmc) { + nfb_boot_bw_bmc_reload(boot); } else if (boot->sdm && boot->sdm_boot_en) { sdm_rsu_image_update(boot->sdm, boot->num_image); } else if (boot->comp) { From 4178179c58beaf15f1f24fc68f3e7a8c7c7b3b59 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Feb 2025 10:35:58 +0100 Subject: [PATCH 282/518] feat(libnfb - boot): add nfb_fw_load_ext_name --- libnfb/include/nfb/boot.h | 1 + libnfb/src/boot/boot.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libnfb/include/nfb/boot.h b/libnfb/include/nfb/boot.h index 922862fa..95ad0efb 100644 --- a/libnfb/include/nfb/boot.h +++ b/libnfb/include/nfb/boot.h @@ -29,6 +29,7 @@ int nfb_mtd_erase(struct nfb_device *dev, int index, size_t addr, siz int nfb_fw_boot(const char *devname, unsigned int image); int nfb_fw_load(const struct nfb_device *dev, unsigned int image, void *data, size_t size); int nfb_fw_load_ext(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags); +int nfb_fw_load_ext_name(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags, const char *filename); ssize_t nfb_fw_read_for_dev(const struct nfb_device *dev, FILE *fd, void **data); diff --git a/libnfb/src/boot/boot.c b/libnfb/src/boot/boot.c index e54ad24a..f4cbd5b7 100644 --- a/libnfb/src/boot/boot.c +++ b/libnfb/src/boot/boot.c @@ -403,7 +403,7 @@ int nfb_fw_load_fpga_image_load(const struct nfb_device *dev, void *data, size_t return ret; } -int nfb_fw_load_ext(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags) +int nfb_fw_load_ext_name(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags, const char *filename) { int node = -1; int fdt_offset = -1; @@ -513,6 +513,11 @@ int nfb_fw_load_ext(const struct nfb_device *dev, unsigned int image, void *data return 0; } +int nfb_fw_load_ext(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags) +{ + return nfb_fw_load_ext_name(dev, image, data, size, flags, NULL); +} + void nfb_fw_print_slots(const struct nfb_device *dev) { int id; From 6fe62c65b8205e0faad75678117eba6c90019636 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 3 Feb 2025 11:08:00 +0100 Subject: [PATCH 283/518] feat(libnfb - boot): add support for NFB_BOOT_IOC_LOAD --- libnfb/src/boot/boot.c | 73 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/libnfb/src/boot/boot.c b/libnfb/src/boot/boot.c index f4cbd5b7..95318e52 100644 --- a/libnfb/src/boot/boot.c +++ b/libnfb/src/boot/boot.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -231,6 +232,12 @@ ssize_t nfb_fw_read_for_dev(const struct nfb_device *dev, FILE *fd, void **data) return ret; } + fdt_for_each_compatible_node(fdt, node, "bittware,bmc") { + format = BITSTREAM_FORMAT_NATIVE; + ret = nfb_fw_open_rpd(fd, data, format); + return ret; + } + fdt_for_each_compatible_node(fdt, node, "brnologic,m10bmc_spi") { format = BITSTREAM_FORMAT_NATIVE; ret = nfb_fw_open_rpd(fd, data, format); @@ -403,8 +410,70 @@ int nfb_fw_load_fpga_image_load(const struct nfb_device *dev, void *data, size_t return ret; } +int nfb_fw_load_boot_load(const struct nfb_device *dev, void *data, size_t size, int flags, int slot_fdt_offset, const char *filename) +{ + const int FDT_MAX_PATH_LENGTH = 512; + + int ret; + int node_cp; + struct nfb_boot_ioc_load load; + const void *fdt = nfb_get_fdt(dev); + + char node_path[FDT_MAX_PATH_LENGTH]; + + int32_t id = -1; + uint32_t offset = 0xDEADBEEF; + const void *prop; + + char *fn = NULL; + + ret = fdt_get_path(fdt, slot_fdt_offset, node_path, sizeof(node_path)); + if (ret < 0) + return -EINVAL; + + //prop32 = fdt_getprop(fdt, node, "id", &proplen); + fdt_getprop32(fdt, slot_fdt_offset, "id", &id); + if (id == -1) + return -EINVAL; + prop = fdt_getprop(fdt, slot_fdt_offset, "empty", NULL); + + node_cp = fdt_subnode_offset(fdt, slot_fdt_offset, "control-param"); + fdt_getprop32(fdt, node_cp, "base", &offset); + + fn = strdup(filename ? filename : "cesnet-ndk-image.rbf"); + if (fn == NULL) { + return -ENOMEM; + } + + if (flags & NFB_FW_LOAD_FLAG_VERBOSE) { + printf("Bitstream size: %lu B\n", size); + } + + load.node = node_path; + load.node_size = strlen(load.node) + 1; + + load.name = basename(fn); + load.name_size = strlen(load.name) + 1; + + load.data = data; + load.data_size = size; + + load.id = id; + load.cmd = NFB_BOOT_IOC_LOAD_CMD_WRITE | (prop == NULL ? NFB_BOOT_IOC_LOAD_CMD_ERASE : 0); + load.flags = NFB_BOOT_IOC_LOAD_FLAG_USE_NODE; + + ret = ioctl(dev->fd, NFB_BOOT_IOC_LOAD, &load); + if (ret != 0) + ret = -errno; + + free(fn); + + return ret; +} + int nfb_fw_load_ext_name(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags, const char *filename) { + int ret; int node = -1; int fdt_offset = -1; int proplen; @@ -448,6 +517,10 @@ int nfb_fw_load_ext_name(const struct nfb_device *dev, unsigned int image, void } } + ret = nfb_fw_load_boot_load(dev, data, size, flags, node, filename); + if (ret != -ENXIO) + return ret; + prop = fdt_getprop(fdt, fdt_offset, "bitstream-offset", &proplen); if (proplen == sizeof(*prop)) { size -= fdt32_to_cpu(*prop); From c8f6c84ad7181632c59e6867576ce55a85aca49c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 5 Feb 2025 21:38:05 +0100 Subject: [PATCH 284/518] feat(libnfb - boot): add nfb_fw_load_progress functions --- libnfb/include/nfb/boot.h | 4 ++ libnfb/src/boot/boot.c | 92 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/libnfb/include/nfb/boot.h b/libnfb/include/nfb/boot.h index 95ad0efb..d82368c0 100644 --- a/libnfb/include/nfb/boot.h +++ b/libnfb/include/nfb/boot.h @@ -43,6 +43,10 @@ void nfb_fw_close(void *data); void nfb_fw_print_slots(const struct nfb_device *dev); +void *nfb_fw_load_progress_init(struct nfb_device *dev); +void nfb_fw_load_progress_destroy(void *priv); +void nfb_fw_load_progress_print(void *priv); + int nfb_sensor_get(struct nfb_device *dev, struct nfb_boot_ioc_sensor *s); #ifdef __cplusplus diff --git a/libnfb/src/boot/boot.c b/libnfb/src/boot/boot.c index 95318e52..6e991ce1 100644 --- a/libnfb/src/boot/boot.c +++ b/libnfb/src/boot/boot.c @@ -471,6 +471,98 @@ int nfb_fw_load_boot_load(const struct nfb_device *dev, void *data, size_t size, return ret; } +struct boot_load_progress { + char path[PATH_MAX]; + unsigned op; + unsigned done; + unsigned progress; +}; + +struct boot_load_status { + unsigned start_ops; + unsigned done_ops; + unsigned pending_ops; + unsigned current_op; + unsigned current_op_progress_max; + unsigned current_op_progress; +} bs; + +void *nfb_fw_load_progress_init(struct nfb_device *dev) +{ + int node; + const void *fdt = nfb_get_fdt(dev); + const void *prop; + struct boot_load_progress *lp; + + lp = calloc(1, sizeof(*lp)); + if (lp == NULL) { + return NULL; + } + + node = fdt_path_offset(fdt, "/system/device/endpoint0"); + prop = fdt_getprop(fdt, node, "pci-slot", NULL); + snprintf(lp->path, sizeof(lp->path), "/sys/bus/pci/devices/%s/nfb/nfb%d/boot_load_status", (const char*)prop, nfb_get_system_id(dev)); + + return lp; +} + +void nfb_fw_load_progress_destroy(void *priv) +{ + struct boot_load_progress *lp = priv; + if (lp != NULL) { + if (lp->op) { + nfb_fw_load_progress_print(priv); + } + free(lp); + } +} + +void nfb_fw_load_progress_print(void *priv) +{ + FILE *file; + int n; + + struct boot_load_progress *lp = priv; + struct boot_load_status bs; + + if (lp == NULL) + return; + + file = fopen(lp->path, "r"); + if (file == NULL) + return; + + n = fscanf(file, "0,%u,%u,%u,%u,%u,%u", &bs.start_ops, &bs.done_ops, &bs.pending_ops, + &bs.current_op, &bs.current_op_progress_max, &bs.current_op_progress); + + fclose(file); + if (n != 6) + return; + + if (bs.current_op_progress_max) { + lp->progress = bs.current_op_progress * 100ull / bs.current_op_progress_max; + } else { + lp->progress = 0; + } + + if (bs.current_op != lp->op) { + lp->progress = 100; + } + + if ((lp->done & lp->op) == 0) { + if (lp->op == NFB_BOOT_IOC_LOAD_CMD_WRITE) { + nfb_fw_print_progress("Writing image: %3d%%", lp->progress); + } + } + + if (lp->progress == 100) { + lp->done |= lp->op; + } + if (bs.current_op != lp->op) { + lp->op = bs.current_op; + } +} + int nfb_fw_load_ext_name(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags, const char *filename) { int ret; From 2b9e73dd61fa1aa7e3edc0373d723e9167b82d26 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Feb 2025 10:59:16 +0100 Subject: [PATCH 285/518] feat(libnfb - boot): add nfb_fw_delete --- libnfb/include/nfb/boot.h | 2 ++ libnfb/src/boot/boot.c | 60 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/libnfb/include/nfb/boot.h b/libnfb/include/nfb/boot.h index d82368c0..728a3a70 100644 --- a/libnfb/include/nfb/boot.h +++ b/libnfb/include/nfb/boot.h @@ -31,6 +31,8 @@ int nfb_fw_load(const struct nfb_device *dev, unsigned int image, void *data, si int nfb_fw_load_ext(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags); int nfb_fw_load_ext_name(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags, const char *filename); +int nfb_fw_delete(const struct nfb_device *dev, unsigned int image); + ssize_t nfb_fw_read_for_dev(const struct nfb_device *dev, FILE *fd, void **data); /* deprecated: nfb_fw_open */ diff --git a/libnfb/src/boot/boot.c b/libnfb/src/boot/boot.c index 6e991ce1..8951949a 100644 --- a/libnfb/src/boot/boot.c +++ b/libnfb/src/boot/boot.c @@ -29,6 +29,8 @@ #include "boot.h" +static const int FDT_MAX_PATH_LENGTH = 512; + int nfb_fw_boot(const char *devname, unsigned int image) { int ret; @@ -412,8 +414,6 @@ int nfb_fw_load_fpga_image_load(const struct nfb_device *dev, void *data, size_t int nfb_fw_load_boot_load(const struct nfb_device *dev, void *data, size_t size, int flags, int slot_fdt_offset, const char *filename) { - const int FDT_MAX_PATH_LENGTH = 512; - int ret; int node_cp; struct nfb_boot_ioc_load load; @@ -683,6 +683,62 @@ int nfb_fw_load_ext(const struct nfb_device *dev, unsigned int image, void *data return nfb_fw_load_ext_name(dev, image, data, size, flags, NULL); } +int nfb_fw_delete(const struct nfb_device *dev, unsigned int image) +{ + int ret; + int node; + const fdt32_t *prop; + const void *fdt; + int proplen; + int fdt_offset = -1; + + struct nfb_boot_ioc_load load; + + char node_path[FDT_MAX_PATH_LENGTH]; + const char *title; + + fdt = nfb_get_fdt(dev); + + fdt_for_each_compatible_node(fdt, node, "netcope,binary_slot") { + prop = fdt_getprop(fdt, node, "id", &proplen); + + if (proplen != sizeof(*prop)) + continue; + if (fdt32_to_cpu(*prop) == image) { + fdt_offset = node; + break; + } + } + if (fdt_offset < 0) + return ENODEV; + + ret = fdt_get_path(fdt, fdt_offset, node_path, sizeof(node_path)); + if (ret < 0) + return -EINVAL; + + title = fdt_getprop(fdt, node, "title", &proplen); + if (title == NULL) + return -EINVAL; + + load.node = node_path; + load.node_size = strlen(load.node) + 1; + + load.name = title; + load.name_size = strlen(load.name) + 1; + + load.data = NULL; + load.data_size = 0; + + load.id = image; + load.cmd = NFB_BOOT_IOC_LOAD_CMD_ERASE; + load.flags = 0; + + ret = ioctl(dev->fd, NFB_BOOT_IOC_LOAD, &load); + if (ret != 0) + ret = errno; + return ret; +} + void nfb_fw_print_slots(const struct nfb_device *dev) { int id; From b2685521418c044e8866354d8684883bb44ec086 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 12 Feb 2025 11:04:15 +0100 Subject: [PATCH 286/518] feat(libnfb - boot): add nfb_fw_set_priority --- libnfb/include/nfb/boot.h | 1 + libnfb/src/boot/boot.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/libnfb/include/nfb/boot.h b/libnfb/include/nfb/boot.h index 728a3a70..c9e0989d 100644 --- a/libnfb/include/nfb/boot.h +++ b/libnfb/include/nfb/boot.h @@ -32,6 +32,7 @@ int nfb_fw_load_ext(const struct nfb_device *dev, unsigned int image, void *data int nfb_fw_load_ext_name(const struct nfb_device *dev, unsigned int image, void *data, size_t size, int flags, const char *filename); int nfb_fw_delete(const struct nfb_device *dev, unsigned int image); +int nfb_fw_set_priority(const struct nfb_device *dev, unsigned int *id_list, unsigned int *prio_list, size_t item_count); ssize_t nfb_fw_read_for_dev(const struct nfb_device *dev, FILE *fd, void **data); diff --git a/libnfb/src/boot/boot.c b/libnfb/src/boot/boot.c index 8951949a..65e64767 100644 --- a/libnfb/src/boot/boot.c +++ b/libnfb/src/boot/boot.c @@ -739,6 +739,41 @@ int nfb_fw_delete(const struct nfb_device *dev, unsigned int image) return ret; } +int nfb_fw_set_priority(const struct nfb_device *dev, unsigned int *id_list, unsigned int *prio_list, size_t item_count) +{ + unsigned i; + int ret; + struct nfb_boot_ioc_load load = {0}; + + uint64_t *prio_pid; + uint64_t *prio_val; + const size_t sz_prio_item = sizeof(*prio_pid) + sizeof(*prio_val); + + load.cmd = NFB_BOOT_IOC_LOAD_CMD_PRIORITY; + + load.data_size = item_count * sizeof(uint64_t) * 2; + load.data = malloc(load.data_size); + if (load.data == NULL) + return -ENOMEM; + for (i = 0; i < item_count; i++) { + prio_pid = (uint64_t*) (load.data + i * sz_prio_item); + prio_val = (uint64_t*) (load.data + i * sz_prio_item + sizeof(prio_pid)); + + *prio_pid = id_list[i]; + if (prio_list != NULL) + *prio_val = prio_list[i]; + else + *prio_val = i; + } + + ret = ioctl(dev->fd, NFB_BOOT_IOC_LOAD, &load); + if (ret != 0) + ret = errno; + free(load.data); + + return ret; +} + void nfb_fw_print_slots(const struct nfb_device *dev) { int id; From ca56563943b2608c881d0de75371c286fcd1eb2c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 12 Feb 2025 09:50:36 +0100 Subject: [PATCH 287/518] feat(libnfb - boot): show priority in slots --- libnfb/src/boot/boot.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libnfb/src/boot/boot.c b/libnfb/src/boot/boot.c index 65e64767..3f261872 100644 --- a/libnfb/src/boot/boot.c +++ b/libnfb/src/boot/boot.c @@ -782,6 +782,7 @@ void nfb_fw_print_slots(const struct nfb_device *dev) const void *fdt; const char *module; const char *title; + const uint32_t *priority; const fdt32_t *prop; fdt = nfb_get_fdt(dev); @@ -801,6 +802,11 @@ void nfb_fw_print_slots(const struct nfb_device *dev) if (proplen <= 0) continue; - printf("%d: %s (%s)\n", id, title, module); + priority = fdt_getprop(fdt, node, "priority", &proplen); + + printf("%d: %s (%s)", id, title, module); + if (priority) + printf(" [%d]", fdt32_to_cpu(*priority)); + printf("\n"); } } From 85a91f4542bd193d672314c14c92482024b3903c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 5 Feb 2025 21:40:47 +0100 Subject: [PATCH 288/518] feat(tool - boot): show progress for boot_load --- tools/CMakeLists.txt | 4 ++++ tools/boot/boot.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a6decd58..ca06bd66 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -60,6 +60,10 @@ foreach(PIE_TARGET IN LISTS PIE_TARGETS) set_property(TARGET ${PIE_TARGET} PROPERTY POSITION_INDEPENDENT_CODE TRUE) endforeach() +target_link_libraries(nfb-boot + PRIVATE ${CMAKE_THREAD_LIBS_INIT} +) + target_compile_options(ndp-tool PRIVATE -O3 -funroll-loops) target_link_libraries(ndp-tool PRIVATE ${NUMA_LIBRARIES} ${NCURSES_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} diff --git a/tools/boot/boot.c b/tools/boot/boot.c index 0093fb32..395b956a 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -56,6 +57,12 @@ enum commands { CMD_INJECT_DTB, }; +struct progress_state { + void *priv; + int done; +}; + + void usage(const char *me) { printf("Usage: %s [-d device] [-b id file] [-f id file] [-F id] [-w id file] [-i file] [-hlqv]\n", me); @@ -445,6 +452,17 @@ int print_info(const char *filename, int verbose) return 0; } +static void *show_progress(void *arg) +{ + struct progress_state *ps = arg; + do { + nfb_fw_load_progress_print(ps->priv); + usleep(200000); + } while (ps->done == 0); + + return NULL; +} + int do_write_with_dev(struct nfb_device *dev, int slot, const char *filename, const void *fdt, int flags) { unsigned int i; @@ -461,6 +479,9 @@ int do_write_with_dev(struct nfb_device *dev, int slot, const char *filename, co ".bin", }; + pthread_t pt; + struct progress_state ps; + if (fdt == NULL) { /* RAW bitsream is supplied */ @@ -508,7 +529,20 @@ int do_write_with_dev(struct nfb_device *dev, int slot, const char *filename, co goto err_nfb_fw_open; } + if ((flags & FLAG_QUIET) == 0 ) { + ps.done = 0; + ps.priv = nfb_fw_load_progress_init(dev); + pthread_create(&pt, NULL, show_progress, &ps); + } + ret = nfb_fw_load_ext(dev, slot, data, size, flags & FLAG_QUIET ? 0 : NFB_FW_LOAD_FLAG_VERBOSE); + + if ((flags & FLAG_QUIET) == 0 ) { + ps.done = 1; + pthread_join(pt, NULL); + nfb_fw_load_progress_destroy(ps.priv); + } + switch (ret) { case 0: break; From 08b85136e468ee8831fd989ae08e0e61985080bc Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Feb 2025 10:36:30 +0100 Subject: [PATCH 289/518] feat(tool - boot): use nfb_fw_load_ext_name --- tools/boot/boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/boot/boot.c b/tools/boot/boot.c index 395b956a..d7684914 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -535,7 +535,7 @@ int do_write_with_dev(struct nfb_device *dev, int slot, const char *filename, co pthread_create(&pt, NULL, show_progress, &ps); } - ret = nfb_fw_load_ext(dev, slot, data, size, flags & FLAG_QUIET ? 0 : NFB_FW_LOAD_FLAG_VERBOSE); + ret = nfb_fw_load_ext_name(dev, slot, data, size, flags & FLAG_QUIET ? 0 : NFB_FW_LOAD_FLAG_VERBOSE, filename); if ((flags & FLAG_QUIET) == 0 ) { ps.done = 1; From 38475f04eed31e4087d5c5614e6760b2e7afbc83 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Feb 2025 11:00:21 +0100 Subject: [PATCH 290/518] feat(tool - boot): introduce "delete slot" command --- tools/boot/boot.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/boot/boot.c b/tools/boot/boot.c index d7684914..4a3d1207 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -28,7 +28,7 @@ #include /* define input arguments of tool */ -#define ARGUMENTS "d:w:f:b:F:i:I:lqvh" +#define ARGUMENTS "d:D:w:f:b:F:i:I:lqvh" #define PRINT_WARNING_WHEN_USING_BITSTREAM 0 #define REQUIRE_FORCE_WHEN_USING_BITSTREAM 0 @@ -55,6 +55,7 @@ enum commands { CMD_WRITE, CMD_QUICK_BOOT, CMD_INJECT_DTB, + CMD_DELETE, }; struct progress_state { @@ -71,6 +72,7 @@ void usage(const char *me) printf("-w slot file Write configuration from file to device slot\n"); printf("-f slot file Write configuration from file to device slot and boot device\n"); printf("-b slot file Quick boot, see below\n"); + printf("-D slot Delete device slot\n"); printf("-i file Print information about configuration file\n"); printf("-I dtb Inject DTB to PCI device\n"); printf(" The device arg should be in BDF+domain notation: dddd:BB:DD.F\n"); @@ -385,6 +387,22 @@ int print_slots(const char *path) return 0; } +int do_delete(const char *path, int slot) +{ + int ret; + struct nfb_device *dev; + + dev = nfb_open(path); + if (dev == NULL) { + warn("can't open device file"); + return -ENODEV; + } + + ret = nfb_fw_delete(dev, slot); + nfb_close(dev); + return ret; +} + int print_info(const char *filename, int verbose) { static const int BUFFER_SIZE = 64; @@ -727,6 +745,10 @@ int main(int argc, char *argv[]) cmd = CMD_BOOT; slot_arg = optarg; break; + case 'D': + cmd = CMD_DELETE; + slot_arg = optarg; + break; case 'i': cmd = CMD_PRINT_INFO; filename = optarg; @@ -779,6 +801,9 @@ int main(int argc, char *argv[]) case CMD_INJECT_DTB: ret = inject_fdt(path, filename, flags); break; + case CMD_DELETE: + ret = do_delete(path, slot); + break; case CMD_UNKNOWN: warnx("no command"); ret = -1; From 395b6782dfa2df42d5b77e30ba4cba9b03e7bdf7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 12 Feb 2025 11:09:06 +0100 Subject: [PATCH 291/518] feat(tool - boot): introduce "set priority" command --- tools/boot/boot.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/tools/boot/boot.c b/tools/boot/boot.c index 4a3d1207..8e8ead15 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -28,7 +28,7 @@ #include /* define input arguments of tool */ -#define ARGUMENTS "d:D:w:f:b:F:i:I:lqvh" +#define ARGUMENTS "d:D:P:w:f:b:F:i:I:lqvh" #define PRINT_WARNING_WHEN_USING_BITSTREAM 0 #define REQUIRE_FORCE_WHEN_USING_BITSTREAM 0 @@ -56,6 +56,7 @@ enum commands { CMD_QUICK_BOOT, CMD_INJECT_DTB, CMD_DELETE, + CMD_SET_PRIORITY, }; struct progress_state { @@ -73,6 +74,7 @@ void usage(const char *me) printf("-f slot file Write configuration from file to device slot and boot device\n"); printf("-b slot file Quick boot, see below\n"); printf("-D slot Delete device slot\n"); + printf("-P slot_list Set priority for slots, eg: 0,4,1\n"); printf("-i file Print information about configuration file\n"); printf("-I dtb Inject DTB to PCI device\n"); printf(" The device arg should be in BDF+domain notation: dddd:BB:DD.F\n"); @@ -403,6 +405,52 @@ int do_delete(const char *path, int slot) return ret; } +int do_set_priority(const char *path, char* priority) +{ + size_t i; + int ret; + struct nfb_device *dev; + struct list_range lr; + unsigned int *id_list, *prio_list; + + list_range_init(&lr); + ret = list_range_parse(&lr, priority); + if (ret <= 0) { + warn("can't parse priority list"); + return -EINVAL; + } + + dev = nfb_open(path); + if (dev == NULL) { + warn("can't open device file"); + return -ENODEV; + } + + id_list = malloc(ret * (sizeof(*id_list) + sizeof(*prio_list))); + if (id_list == NULL) + return -ENOMEM; + + prio_list = id_list + ret; + + for (i = 0; i < lr.items; i++) { + if (lr.min[i] != lr.max[i]) { + ret = -EINVAL; + goto err_param; + } + id_list[i] = lr.min[i]; + prio_list[i] = i; + } + + ret = nfb_fw_set_priority(dev, id_list, prio_list, ret); + nfb_close(dev); + return ret; + +err_param: + free(id_list); + nfb_close(dev); + return ret; +} + int print_info(const char *filename, int verbose) { static const int BUFFER_SIZE = 64; @@ -703,6 +751,7 @@ int main(int argc, char *argv[]) int c; long slot = -1; char *slot_arg = NULL; + char *prio_arg = NULL; const char *path = nfb_default_dev_path(); char path_by_pci[PATH_MAX]; char *filename = NULL; @@ -749,6 +798,10 @@ int main(int argc, char *argv[]) cmd = CMD_DELETE; slot_arg = optarg; break; + case 'P': + cmd = CMD_SET_PRIORITY; + prio_arg = optarg; + break; case 'i': cmd = CMD_PRINT_INFO; filename = optarg; @@ -804,6 +857,9 @@ int main(int argc, char *argv[]) case CMD_DELETE: ret = do_delete(path, slot); break; + case CMD_SET_PRIORITY: + ret = do_set_priority(path, prio_arg); + break; case CMD_UNKNOWN: warnx("no command"); ret = -1; From b9f45ed726802e0caf2b37fa5bd37b6ce0042467 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 7 Feb 2025 16:43:28 +0100 Subject: [PATCH 292/518] feat(nfb-bootstrap): add support for BittWare IA-440I --- python/nfb-tools/nfbbootstrap/nfb_bootstrap.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py index f6009161..511886e2 100755 --- a/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py +++ b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py @@ -39,6 +39,14 @@ def main(): n_mi.append(n_pmci) n_pmci.append(fdt.PropWords('reg', *pmci_reg)) n_pmci.append(fdt.PropStrings("compatible", "cesnet,pmci")) + elif args.card in ['IA-440I']: + reg = [0x2000, 0x44] + + n_bmc = fdt.Node('bmc') + n_mi.append(n_bmc) + n_bmc.append(fdt.PropWords('reg', *reg)) + n_bmc.append(fdt.PropStrings("compatible", "bittware,bmc")) + n_bmc.append(fdt.Property("throttle_write")) with open(args.dtb, "wb") as f: f.write(dt.to_dtb(version=17)) From eac3eea2041fef824439a19999a65aaf60b16e0e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 14 Jan 2025 10:32:45 +0100 Subject: [PATCH 293/518] feat(pynfb): add type hints --- pynfb/examples/00-quick-reference.py | 6 +- pynfb/examples/01-basics.py | 3 +- pynfb/examples/02-data-transfer.py | 4 +- pynfb/examples/03-eth.py | 10 ++-- pynfb/nfb/__init__.py | 6 +- pynfb/nfb/eth.py | 85 ++++++++++++++-------------- pynfb/nfb/libnetcope.pyi | 50 ++++++++++++++++ pynfb/nfb/libnfb.pyi | 75 ++++++++++++++++++++++++ pynfb/nfb/libnfb.pyx | 33 ++++++----- pynfb/nfb/py.typed | 0 pynfb/pyproject.toml | 4 ++ pynfb/setup.py | 16 +++--- 12 files changed, 214 insertions(+), 78 deletions(-) create mode 100644 pynfb/nfb/libnetcope.pyi create mode 100644 pynfb/nfb/libnfb.pyi create mode 100644 pynfb/nfb/py.typed diff --git a/pynfb/examples/00-quick-reference.py b/pynfb/examples/00-quick-reference.py index 9060aae3..1311634c 100644 --- a/pynfb/examples/00-quick-reference.py +++ b/pynfb/examples/00-quick-reference.py @@ -20,8 +20,8 @@ comp.write16(0x04, 0xFFFF) comp.write(0x12, bytes([0xDE, 0xAD, 0xBE])) -val = comp.read64(0x04) -val = comp.read(0x12, 3) +val_i = comp.read64(0x04) +val_b = comp.read(0x12, 3) # 2.A Data transmission ndp = dev.ndp @@ -60,7 +60,7 @@ eth = dev.eth[0] link_ready = eth.rxmac.link -for mac in [eth.rxmac, eth.txmac]: +for mac in (eth.rxmac, eth.txmac): mac.enable(enable=True) mac.disable() mac.reset_stats() diff --git a/pynfb/examples/01-basics.py b/pynfb/examples/01-basics.py index f49a8181..09efcaa6 100644 --- a/pynfb/examples/01-basics.py +++ b/pynfb/examples/01-basics.py @@ -40,7 +40,8 @@ node = dev.fdt_get_phandle(phandle) # show full path of node in DT -print(node.path + "/" + node.name) +if node is not None: + print(node.path + "/" + node.name) # 1.C Component manipulation diff --git a/pynfb/examples/02-data-transfer.py b/pynfb/examples/02-data-transfer.py index 6bd76132..eb54d8eb 100644 --- a/pynfb/examples/02-data-transfer.py +++ b/pynfb/examples/02-data-transfer.py @@ -76,7 +76,7 @@ pkts = rxq.recv(cnt=1, timeout=2) # receive specific count of frames, wait indefinitely -#rxq.recv(cnt=1, timeout=None) +# rxq.recv(cnt=1, timeout=None) # receive list of messages # message is a tuple(pkt: bytes, hdr: bytes, flags: int) @@ -118,7 +118,7 @@ # receive pending frames on first three queues ndp.recv(i=[0, 1, 2]) # receive specific count of frames from any queues, wait indefinitely -#ndp.recv(timeout=None) +# ndp.recv(timeout=None) # receive pending messages from all queues, return value is list of tuple(tuple(pkt: bytes, hdr: bytes, flags: int), queue_index: int) msgs = rxq.recvmsg() diff --git a/pynfb/examples/03-eth.py b/pynfb/examples/03-eth.py index eaeb7e09..0a9c4e12 100644 --- a/pynfb/examples/03-eth.py +++ b/pynfb/examples/03-eth.py @@ -22,7 +22,7 @@ eth = dev.eth[0] # enable or disable RxMAC / TxMAC -for mac in [eth.rxmac, eth.txmac]: +for mac in (eth.rxmac, eth.txmac): mac.enable() mac.enable(False) mac.disable() @@ -38,7 +38,7 @@ tx_stats = eth.txmac.read_stats() # reset RxMAC / TxMAC statistic counters -for mac in [eth.rxmac, eth.txmac]: +for mac in (eth.rxmac, eth.txmac): mac.reset_stats() @@ -51,7 +51,7 @@ # disable loopback in register 1.7 eth.pcspma.mdio.write(1, 7, 0) # read 16b value from register 1.7: val = 0 -val = eth.pcspma.mdio.read(1, 7) +val_b = eth.pcspma.mdio.read(1, 7) pmd = eth.pmd pmd.is_present() in [True, False] @@ -61,9 +61,9 @@ val = pmd.read_vendor_pn() val = pmd.read_vendor_sn() if hasattr(pmd, "mdio"): - val = pmd.mdio.read(3, 0) + val_i = pmd.mdio.read(3, 0) elif hasattr(pmd, "i2c"): - val = pmd.i2c.read_reg(148, 16) + val_i = pmd.i2c.read_reg(148, 16) # 3.C Shortcuts for Ethernet ports manipulation diff --git a/pynfb/nfb/__init__.py b/pynfb/nfb/__init__.py index 8fd8fd09..dbb1539d 100644 --- a/pynfb/nfb/__init__.py +++ b/pynfb/nfb/__init__.py @@ -5,10 +5,10 @@ from . import libnfb from . import eth -from .libnfb import open +from .libnfb import open, Nfb import fdt -from typing import Optional +from typing import Optional, Union default_dev_path = libnfb.Nfb.default_dev_path @@ -23,6 +23,6 @@ class BaseComp(libnfb.AbstractBaseComp): :ivar libnfb.Comp _comp: Component object """ - def __init__(self, dev=default_dev_path, node: Optional[fdt.Node]=None, index: int=0): + def __init__(self, dev: Union[str, Nfb] = Nfb.default_dev_path, node: Optional[fdt.Node] = None, index: int = 0): super().__init__(dev, node, index) self._comp = self._dev.comp_open(self._node) diff --git a/pynfb/nfb/eth.py b/pynfb/nfb/eth.py index 7c9f6dd6..41a78a82 100644 --- a/pynfb/nfb/eth.py +++ b/pynfb/nfb/eth.py @@ -1,33 +1,7 @@ +import fdt +from typing import Any, Iterable, Iterator, List from . import libnetcope - - -class EthManager: - """Object which encapsulates all Ethernet interfaces into nfb""" - - def __init__(self, nfb): - self._eth = [Eth(nfb, node) for i, node in enumerate(nfb.fdt_get_compatible("netcope,eth"))] - nfb.eth = self - - def __iter__(self): - return self._eth.__iter__() - - def __getitem__(self, index): - return self._eth[index] #TODO: self._eth.__getitem(index) - - def _common_action(self, action, *args, **kwargs): - eths = self - if 'i' in kwargs: - indexes = [kwargs['i']] if isinstance(kwargs['i'], int) else kwargs['i'] - eths = [e for i, e in enumerate(self) if i in indexes] - del kwargs['i'] - - return [getattr(eth, action)(*args, **kwargs) for eth in eths] - - def __getattr__(self, name): - if name in ["enable", "disable", "stats_reset", "reset_stats", "is_link"]: - return lambda *args, **kwargs: self._common_action(name, *args, **kwargs) - else: - raise AttributeError +from . import libnfb class Eth: @@ -39,19 +13,19 @@ class Eth: :ivar Transceiver pmd: Transceiver object """ - def __init__(self, nfb, node): + def __init__(self, nfb: libnfb.Nfb, node: fdt.Node) -> None: self.rxmac = libnetcope.RxMac(nfb, nfb.fdt_get_phandle(node.get_property('rxmac').value)) self.txmac = libnetcope.TxMac(nfb, nfb.fdt_get_phandle(node.get_property('txmac').value)) self.pcspma = PcsPma(nfb, nfb.fdt_get_phandle(node.get_property('pcspma').value)) self.pmd = libnetcope.Transceiver(nfb, nfb.fdt_get_phandle(node.get_property('pmd').value)) - def _common_action(self, action, *args, **kwargs): + def _common_action(self, action: str, *args: Any, **kwargs: Any) -> List[Any]: return [ getattr(self.rxmac, action)(*args, **kwargs), getattr(self.txmac, action)(*args, **kwargs), ] - def __getattr__(self, name): + def __getattr__(self, name: str) -> Any: if name in ["link", "is_link"]: return self.rxmac.__getattribute__(name) elif name in ["enable", "disable", "stats_reset", "reset_stats"]: @@ -61,7 +35,7 @@ def __getattr__(self, name): else: raise AttributeError - def __setattr__(self, name, value): + def __setattr__(self, name: str, value: Any) -> None: if name in ["link"]: raise AttributeError(f"'Eth' object attribute '{name}' is read-only") elif name in ["pma_local_loopback"]: @@ -70,7 +44,32 @@ def __setattr__(self, name, value): object.__setattr__(self, name, value) +class EthManager: + """Object which encapsulates all Ethernet interfaces into nfb""" + + def __init__(self, nfb: libnfb.Nfb): + self._eth = [Eth(nfb, node) for i, node in enumerate(nfb.fdt_get_compatible("netcope,eth"))] + + def __iter__(self) -> Iterator[Eth]: + return self._eth.__iter__() + def __getitem__(self, index: int) -> Eth: + return self._eth[index] # TODO: self._eth.__getitem(index) + + def _common_action(self, action: str, *args: Any, **kwargs: Any) -> List[Any]: + eths: Iterable[Eth] = iter(self) + if 'i' in kwargs: + indexes = [kwargs['i']] if isinstance(kwargs['i'], int) else kwargs['i'] + eths = [e for i, e in enumerate(eths) if i in indexes] + del kwargs['i'] + + return [getattr(eth, action)(*args, **kwargs) for eth in eths] + + def __getattr__(self, name: str) -> Any: + if name in ["enable", "disable", "stats_reset", "reset_stats", "is_link"]: + return lambda *args, **kwargs: self._common_action(name, *args, **kwargs) + else: + raise AttributeError class PcsPma: @@ -81,32 +80,36 @@ class PcsPma: :ivar int mdio_portad: Port address of PCS/PMA on MDIO bus """ - def __init__(self, nfb, node): + def __init__(self, nfb: libnfb.Nfb, node: fdt.Node): ctrl = nfb.fdt_get_phandle(node.get_property('control').value) ctrl_param = node.get_subnode('control-param') self.mdio = libnetcope.Mdio(nfb, ctrl, ctrl_param) # FIXME: Check and enable!!! self.mdio_portad = ctrl_param.get_property("dev").value if ctrl_param and ctrl_param.get_property("dev") else 0 - def _read(self, dev, reg): return self.mdio.read(dev, reg, self.mdio_portad) - def _write(self, dev, reg, val): return self.mdio.write(dev, reg, val, self.mdio_portad) + def _read(self, dev: int, reg: int) -> int: + return self.mdio.read(dev, reg, self.mdio_portad) + + def _write(self, dev: int, reg: int, val: int) -> None: + return self.mdio.write(dev, reg, val, self.mdio_portad) - def _set_bit(self, dev, reg, bit, value=True): + def _set_bit(self, dev: int, reg: int, bit: int, value: bool = True) -> None: oldval = self._read(dev, reg) newval = (oldval | bit) if value else (oldval & ~bit) if newval != oldval: self._write(dev, reg, newval) - def _clr_bit(self, dev, reg, bit): + def _clr_bit(self, dev: int, reg: int, bit: int) -> None: self._set_bit(dev, reg, bit, False) - def _bit(self, dev, reg, bit): + def _bit(self, dev: int, reg: int, bit: int) -> bool: return True if (self._read(dev, reg) & bit) else False @property - def pma_local_loopback(self): + def pma_local_loopback(self) -> bool: """Get or set loopback on local side of PMA module""" return self._bit(1, 0, 0x1) @pma_local_loopback.setter - def pma_local_loopback(self, value): self._set_bit(1, 0, 0x1, value) + def pma_local_loopback(self, value: bool) -> None: + self._set_bit(1, 0, 0x1, value) diff --git a/pynfb/nfb/libnetcope.pyi b/pynfb/nfb/libnetcope.pyi new file mode 100644 index 00000000..ea86c340 --- /dev/null +++ b/pynfb/nfb/libnetcope.pyi @@ -0,0 +1,50 @@ +import fdt +from typing import Optional + +from . import libnfb + + +class RxMac: + def __init__(self, nfb: libnfb.Nfb, node: fdt.Node) -> None: ... + @property + def link(self) -> bool: ... + @property + def enabled(self) -> bool: ... + @enabled.setter + def enabled(self, enable: bool) -> None: ... + def enable(self, enable: bool = True) -> None: ... + def disable(self) -> None: ... + def is_enabled(self) -> bool: ... + def is_link(self) -> bool: ... + def reset_stats(self) -> None: ... + def read_stats(self, etherstats: bool = False) -> dict[str, int]: ... + +class TxMac: + def __init__(self, nfb: libnfb.Nfb, node: fdt.Node) -> None: ... + @property + def enabled(self) -> bool: ... + @enabled.setter + def enabled(self, enable: bool) -> None: ... + def enable(self, enable: bool = True) -> None: ... + def disable(self) -> None: ... + def is_enabled(self) -> bool: ... + def reset_stats(self) -> None: ... + def read_stats(self, etherstats: bool = False) -> dict[str, int]: ... + +class Transceiver: + def __init__(self, nfb: libnfb.Nfb , node: fdt.Node) -> None: ... + def is_present(self) -> bool: ... + @property + def vendor_name(self) -> str: ... + @property + def vendor_pn(self) -> str: ... + @property + def vendor_sn(self) -> str: ... + def read_vendor_name(self) -> str: ... + def read_vendor_pn(self) -> str: ... + def read_vendor_sn(self) -> str: ... + +class Mdio: + def __init__(self, nfb: libnfb.Nfb, node: fdt.Node, param_node: Optional[fdt.Node] = None) -> None: ... + def read(self, devad: int, reg: int, prtad: int = 0) -> int: ... + def write(self, devad: int, reg: int, val: int, prtad: int = 0) -> None: ... diff --git a/pynfb/nfb/libnfb.pyi b/pynfb/nfb/libnfb.pyi new file mode 100644 index 00000000..8a8f2b24 --- /dev/null +++ b/pynfb/nfb/libnfb.pyi @@ -0,0 +1,75 @@ +import fdt +from collections.abc import Iterable +from typing import Optional, Union, List, Tuple + +from . import eth as mod_eth + + +def open(path: Optional[str] = None) -> Nfb: ... + +class Nfb: + default_dev_path: str + fdt: fdt.Fdt + ndp: QueueManager + eth: mod_eth.EthManager + + def __init__(self, path: str) -> None: ... + def fdt_get_compatible(self, compatible: str) -> list[fdt.items.Node]: ... + def comp_open(self, comp: str | fdt.items.Node, index: int=0) -> Comp: ... + def fdt_get_phandle(self, phandle: int) -> Optional[fdt.items.Node]: ... + def read_temperature(self, units: str = "celsius") -> float: ... + +class AbstractBaseComp: + def __init__(self, dev: str | Nfb = Nfb.default_dev_path, node: Optional[fdt.Node]=None, index: int=0): + self._dev: Nfb + self._node: fdt.Node + +class Comp: + def __init__(self, dev: str | Nfb, node: Optional[fdt.Node], index: int): + self._dev: Nfb + self._node: fdt.Node + + def read(self, addr: int, count: int) -> bytes: ... + def write(self, addr: int, data: bytes) -> None: ... + def read8(self, addr: int) -> int: ... + def read16(self, addr: int) -> int: ... + def read32(self, addr: int) -> int: ... + def read64(self, addr: int) -> int: ... + def write8(self, addr: int, data: int) -> None: ... + def write16(self, addr: int, data: int) -> None: ... + def write32(self, addr: int, data: int) -> None: ... + def write64(self, addr: int, data: int) -> None: ... + def set_bit(self, addr: int, bit: int, value: bool = True, width: int = 32) -> None: ... + def get_bit(self, addr: int, bit: int, width: int = 32) -> bool: ... + def clr_bit(self, addr: int, bit: int, width: int = 32) -> None: ... + def wait_for_bit(self, addr: int, bit: int, timeout: float = 5.0, delay: float = 0.01, level: bool = True, width: int = 32) -> bool: ... + def lock(self, features: int, timeout: Optional[int] = None) -> None: ... + def unlock(self, features: int) -> None: ... + +class NdpQueue: + def start(self) -> None: ... + def stop(self) -> None: ... + def read_stats(self) -> dict[str, int]: ... + def reset_stats(self) -> None: ... + +class NdpQueueRx(NdpQueue): + def recv(self, cnt: int = -1, timeout: float = 0, i: Optional[Union[int, List[int]]] = None) -> list[Tuple[bytes, int]]: ... + def recvmsg(self, cnt: int = -1, timeout: float = 0, i: Optional[Union[int, List[int]]] = None) -> list[Tuple[Tuple[bytes, bytes, int], int]]: ... + +class NdpQueueTx(NdpQueue): + def send(self, pkts: Union[bytes, List[bytes]], hdrs: Optional[Union[bytes, List[bytes]]] = None, flags: Optional[Union[int, List[int]]] = None, flush: bool = True) -> None: ... + def sendmsg(self, pkts: Tuple[bytes, bytes, int] | List[Tuple[bytes, bytes, int]], flush: bool = True) -> None: ... + def flush(self) -> None: ... + +class QueueManager: + def __init__(self, nfb: Nfb) -> None: + self.rx: list[NdpQueueRx] + self.tx: list[NdpQueueTx] + + def start(self, i: Optional[Union[int, List[int]]] = None) -> None: ... + def stop(self, i: Optional[Union[int, List[int]]] = None) -> None: ... + def send(self, pkts: Union[bytes, Iterable[bytes]], hdrs: Optional[Union[bytes, Iterable[bytes]]] = None, flags: Optional[Union[int, Iterable[int]]] = None, flush: bool = True, i: Optional[Union[int, List[int]]] = None) -> None: ... + def sendmsg(self, pkts: Tuple[bytes, bytes, int] | Iterable[Tuple[bytes, bytes, int]], flush: bool = True, i: Optional[Union[int, List[int]]] = None) -> None: ... + def flush(self, i: Optional[Iterable[int] | int] = None) -> None: ... + def recv(self, cnt: int = -1, timeout: float = 0, i: Optional[Union[int, List[int]]] = None) -> list[Tuple[bytes, int]]: ... + def recvmsg(self, cnt: int = -1, timeout: float = 0, i: Optional[Union[int, List[int]]] = None) -> list[Tuple[Tuple[bytes, bytes, int], int]]: ... diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 41f5d625..678603ed 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -33,16 +33,15 @@ def _batched(iterable, n): batch = tuple(islice(it, n)) -def open(path: str = '0') -> Nfb: +def open(path: Optional[str] = None) -> Nfb: """Open a handle to NFB device in system :param path: Path to device node, default leads to ``/dev/nfb0`` :return: The :class:`libnfb.Nfb` object, enhanced by :class:`eth.EthManager` """ - dev = Nfb(path) - eth.EthManager(dev) - return dev + return Nfb(path) + cdef class NfbDeviceHandle: def __cinit__(self, path: str): @@ -84,9 +83,12 @@ cdef class Nfb: default_dev_path = nfb_default_dev_path().decode() - def __init__(self, path: str): + def __init__(self, path: Optional[str] = None): cdef const char* _fdtc + if path is None: + path = self.default_dev_path + self._handle = NfbDeviceHandle(path) # Deprecated. Use _handle._dev self._dev = self._handle._dev @@ -96,6 +98,7 @@ cdef class Nfb: dtb = fdtc[:c_fdt_totalsize(self._fdt)] self.fdt = fdt.parse_dtb(dtb) + self.eth = eth.EthManager(self) self.ndp = QueueManager(self) # TODO: use Nfb.dma only for statistic, not for transfers self.dma = self.ndp @@ -164,7 +167,7 @@ cdef class Nfb: return self.fdt.get_node(path) return None - def read_temperature(self, units="celsius"): + def read_temperature(self, units: str = "celsius") -> float: cdef int32_t int32 = 0 assert units == "celsius" @@ -328,7 +331,7 @@ cdef class Comp: reg = getattr(self, f"read{width}")(addr) return True if (reg & (1 << bit)) else False - def wait_for_bit(self, addr, bit, timeout=5.0, delay=0.01, level=True, width=32): + def wait_for_bit(self, addr, bit, timeout=5.0, delay=0.01, level=True, width=32) -> bool: """ Wait for bit in comenent register @@ -415,8 +418,8 @@ cdef class QueueManager: for d in compatibles ) - def _get_q(self, q, tx = False): - if q == None: + def _get_q(self, q, tx = False) -> list[int]: + if q is None: q = [i for i in range(len(self.tx if tx else self.rx))] elif isinstance(q, int): q = [q] @@ -463,7 +466,7 @@ cdef class QueueManager: for qi in self._get_q(i, True): self.tx[qi].send(pkts, hdrs, flags, flush) - def sendmsg(self, pkts: List[Tuple[bytes, bytes, int]], flush: bool = True, i: Optional[Union[int, List[int]]] = None) -> None: + def sendmsg(self, pkts: Union[List[Tuple[bytes, bytes, int]], Tuple[bytes, bytes, int]], flush: bool = True, i: Optional[Union[int, List[int]]] = None) -> None: """ Send burst of messages to multiple queues @@ -474,7 +477,7 @@ cdef class QueueManager: for qi in self._get_q(i, True): self.tx[qi].sendmsg(pkts, flush) - def flush(self, i = None): + def flush(self, i: Optional[Iterable[int] | int] = None): """ Flush the prepared packets/messages on multiple queues @@ -805,8 +808,8 @@ cdef class NdpQueueTx(NdpQueue): libnetcope.nc_txqueue_read_counters(self._nc_queue, &counters) return { - 'passed': counters.sent, - 'passed_bytes': counters.sent_bytes, + 'passed': counters.sent, + 'passed_bytes': counters.sent_bytes, } cdef _sendmsg(self, pkts: Iterable[Tuple[bytes, bytes, int]]): # -> None: @@ -834,7 +837,7 @@ cdef class NdpQueueTx(NdpQueue): memcpy(ndppkt[i].header, c_hdr, len(hdr)) ndp_tx_burst_put(self._q) - def send(self, pkts: Union[bytes, List[bytes]], hdrs: Optional[Union[bytes, List[bytes]]] = None, flags: Optional[Union[int, List[int]]] = None, flush: bool = True) -> None: + def send(self, pkts: Union[bytes, Iterable[bytes]], hdrs: Optional[Union[bytes, Iterable[bytes]]] = None, flags: Optional[Union[int, Iterable[int]]] = None, flush: bool = True) -> None: """ Send a packet or burst of packets @@ -859,7 +862,7 @@ cdef class NdpQueueTx(NdpQueue): self.sendmsg(zip(pkts, hdrs, flags), flush) - def sendmsg(self, pkts: Iterable[Tuple[bytes, bytes, int]], flush: bool = True) -> None: + def sendmsg(self, pkts: Union[Tuple[bytes, bytes, int], Iterable[Tuple[bytes, bytes, int]]], flush: bool = True) -> None: """ Send burst of messages diff --git a/pynfb/nfb/py.typed b/pynfb/nfb/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/pynfb/pyproject.toml b/pynfb/pyproject.toml index 99dd3e6c..be783440 100644 --- a/pynfb/pyproject.toml +++ b/pynfb/pyproject.toml @@ -4,3 +4,7 @@ requires = [ "Cython", ] build-backend = "setuptools.build_meta" + +[[tool.mypy.overrides]] +module = "fdt" +ignore_missing_imports = true diff --git a/pynfb/setup.py b/pynfb/setup.py index c4b292b6..4ff67338 100644 --- a/pynfb/setup.py +++ b/pynfb/setup.py @@ -17,16 +17,16 @@ ) libnfb_ext_extra_args = libnetcope_ext_extra_args = dict() -#libnfb_ext_extra_args = libnetcope_ext_extra_args = ext_extra_args +# libnfb_ext_extra_args = libnetcope_ext_extra_args = ext_extra_args setup( - name = "nfb", - version = "0.2.1", - author = "Martin Spinler", - author_email = "spinler@cesnet.cz", - ext_package = "nfb", - ext_modules = cythonize( + name="nfb", + version="0.2.1", + author="Martin Spinler", + author_email="spinler@cesnet.cz", + ext_package="nfb", + ext_modules=cythonize( [ Extension("libnfb", ["nfb/libnfb.pyx"], libraries=["nfb", "fdt"], **libnfb_ext_extra_args), Extension("libnetcope", ["nfb/libnetcope.pyx"], libraries=["nfb", "fdt"], **libnetcope_ext_extra_args), @@ -37,7 +37,7 @@ py_modules=['nfb'], packages=['nfb'], package_dir={'nfb': 'nfb'}, - package_data = { + package_data={ 'nfb': ['*.pxd'], }, install_requires=['fdt'], From 02fde84709681061ae59b906905f51067773ec4c Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Tue, 18 Feb 2025 09:48:52 +0100 Subject: [PATCH 294/518] fix(libnfb): add missing packet flags for v3 queue --- libnfb/include/netcope/ndp_priv.h | 6 ++++-- libnfb/include/netcope/ndp_rx.h | 3 ++- libnfb/include/netcope/ndp_tx.h | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index b463109d..a2461fec 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -32,8 +32,10 @@ struct ndp_v3_packethdr { __u16 frame_len; /**< size of the packet */ __u16 frame_ptr; /**< index into the data array */ unsigned valid : 1; /**< bit indicating the validity of the header/packet */ - unsigned reserved : 7; /**< bits reserved for future use */ - unsigned metadata:24; /**< user metadata */ + unsigned reserved1 : 7; /**< bits reserved for future use */ + unsigned header_size : 8; /**< size of application header (optional)*/ + unsigned flags : 4; /**< packet specific flags */ + unsigned reserved2 : 12; /**< bits reserved for future use*/ } __attribute((packed)); struct ndp_queue; diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index 04c05480..3539d445 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -336,13 +336,14 @@ static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *pac break; } - header_size = le16_to_cpu(hdr->metadata) & NDP_CALYPTE_METADATA_HDR_SIZE_MASK; + header_size = le16_to_cpu(hdr->header_size) & NDP_CALYPTE_METADATA_HDR_SIZE_MASK; packet_size = le16_to_cpu(hdr->frame_len) - header_size; data = data_base + hdr->frame_ptr * NDP_RX_CALYPTE_BLOCK_SIZE; /* Assign pointer and length of header */ packets[i].header = data; packets[i].header_length = header_size; + packets[i].flags = hdr->flags & 0xF; data += header_size; diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index bdd82111..f228ec11 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -452,9 +452,10 @@ static inline unsigned nc_ndp_v3_tx_burst_get(void *priv, struct ndp_packet *pac } /* Write DMA TX header */ - hdr->metadata = cpu_to_le16(header_size); + hdr->header_size = cpu_to_le16(header_size); hdr->frame_len = cpu_to_le16(packet_size); hdr->frame_ptr = sdp_int & q->u.v3.data_ptr_mask; + hdr->flags = packets[i].flags & 0xF; /* Set pointers, where user can write packet content */ packets[i].header = data_base + sdp_int; From 63405b2bb346190d52ac9e5570368f3aaaa6352e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bene=C5=A1?= Date: Thu, 20 Feb 2025 14:13:50 +0100 Subject: [PATCH 295/518] feat(drivers): add support for Alveo x3522 --- drivers/kernel/drivers/nfb/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 3066ca24..efc3bceb 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -375,7 +375,7 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) nfb_fdt_create_binary_slot(fdt, node, "image0", "application0" , 0, 0, 0, 0x01002000, 0x04000000); nfb_fdt_create_boot_type(fdt, node, "SPI", 4); - } else if (!strcmp(card_name, "ALVEO_UL3524")) { + } else if (!strcmp(card_name, "ALVEO_UL3524") || !strcmp(card_name, "ALVEO_X3522")) { prop32 = cpu_to_fdt32(1); fdt_appendprop(fdt, node, "num_flash", &prop32, sizeof(prop32)); prop32 = cpu_to_fdt32(256 * 1024 * 1024); From 710d971ee67c93f3d990265e5f7c6274ac30ce07 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 24 Feb 2025 08:26:29 +0000 Subject: [PATCH 296/518] fixup! 5fede18e --- libnfb/include/netcope/bittware_bmc_spi.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libnfb/include/netcope/bittware_bmc_spi.h b/libnfb/include/netcope/bittware_bmc_spi.h index 658290dd..daf0bbd6 100644 --- a/libnfb/include/netcope/bittware_bmc_spi.h +++ b/libnfb/include/netcope/bittware_bmc_spi.h @@ -30,7 +30,7 @@ static inline struct nc_bw_bmc *nc_bw_bmc_open(const struct nfb_device *dev, int static inline void nc_bw_bmc_close(struct nc_bw_bmc *spi); static inline int nc_bw_bmc_send_mctp(struct nc_bw_bmc *spi); static inline int nc_bw_bmc_send_mctp_ext(struct nc_bw_bmc *spi, const unsigned char *bytes, int len, int last, int wait_for_status); -static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned char* bytes, unsigned int len, unsigned int *readen); +static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned char* bytes, unsigned int len, unsigned int *received); /* ~~~~[ REGISTERS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -189,7 +189,7 @@ static inline int nc_bw_bmc_min(int a, int b) { return a < b ? a : b; } -static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned char* data, unsigned int len, unsigned int *readen) +static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned char* data, unsigned int len, unsigned int *received) { struct nfb_comp * comp = nfb_user_to_comp(spi); @@ -198,7 +198,7 @@ static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned cha uint32_t status; uint32_t bytes; - *readen = 0; + *received = 0; status = nfb_comp_read32(comp, NC_BW_BMC_SPI_RD_CSR); while ((status & 1) == 0 && ++retries < 100000) { @@ -238,15 +238,15 @@ static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned cha } data[i] = status & 0xFF; - (*readen)++; + (*received)++; if (status & 0x100) break; } /* Data continues */ - if (!(status & 0x100) || bytes > *readen) - return bytes - *readen; + if (!(status & 0x100) || bytes > *received) + return bytes - *received; nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_RD_CSR, 1 << 1); /* Read Transfer Complete */ From cc4ed69321b25d78f203f2e7e218b3d45bff7348 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 25 Feb 2025 06:22:04 +0100 Subject: [PATCH 297/518] bump version to 6.26.0 --- Changelog | 10 ++++++++++ VERSION | 2 +- pynfb/setup.py | 2 +- pynfb/setup.py.in | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Changelog b/Changelog index 59bf5dfb..3b3f7f81 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,13 @@ +* Tue Feb 25 2025 Martin Spinler - 6.26.0-1 +- [FEATURE]: add boot load interface (ia-440i) - load, delete, set priority +- [FEATURE]: add support for BittWare ia-440i (drivers/boot, nfb-bootstrap) +- [FEATURE] drivers: add support for Alveo x3552 card +- [FEATURE] pynfb: add type hints +- [FEATURE] libnfb/NDP: add missing packet flags for v3 queue +- [FEATURE] gRPC: add virtual address space DMA plugin (dma.proto) +- [FEATURE] gRPC: add Python package with generated protobuf/grpc files +- [MAINTENANCE] gRPC: rename rpcs and messages + * Tue Jan 7 2025 Martin Spinler - 6.25.0-1 - [FEATURE] drivers: add support for newer kernels - [FEATURE] drivers: add support for Silicom N5014 card diff --git a/VERSION b/VERSION index 961b1c8e..4c6a35fb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.25.0 +6.26.0 diff --git a/pynfb/setup.py b/pynfb/setup.py index 4ff67338..f22712ba 100644 --- a/pynfb/setup.py +++ b/pynfb/setup.py @@ -22,7 +22,7 @@ setup( name="nfb", - version="0.2.1", + version="0.2.2", author="Martin Spinler", author_email="spinler@cesnet.cz", ext_package="nfb", diff --git a/pynfb/setup.py.in b/pynfb/setup.py.in index 47146a0e..da04d428 100644 --- a/pynfb/setup.py.in +++ b/pynfb/setup.py.in @@ -17,7 +17,7 @@ libnfb_ext_extra_args = libnetcope_ext_extra_args = ext_extra_args setup( name = "nfb", - version = "0.2.1", + version = "0.2.2", author = "Martin Spinler", author_email = "spinler@cesnet.cz", ext_package = "nfb", From fc73ddde4072e84d8a9f15c36681f4342e566046 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 25 Feb 2025 16:57:31 +0100 Subject: [PATCH 298/518] fix(boot - BittWare BMC): check for name only when erasing --- drivers/kernel/drivers/nfb/boot/bw-bmc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/bw-bmc.c b/drivers/kernel/drivers/nfb/boot/bw-bmc.c index 2cba6d9a..35d38a8a 100644 --- a/drivers/kernel/drivers/nfb/boot/bw-bmc.c +++ b/drivers/kernel/drivers/nfb/boot/bw-bmc.c @@ -450,10 +450,6 @@ int nfb_boot_bw_bmc_load(struct nfb_boot *boot, if (size < load->data_size) return -ENOMEM; - name = fdt_getprop(fdt, node_image, "filename", NULL); - if (name == NULL) - return -EINVAL; - prop = fdt_getprop(fdt, node_image, "empty", NULL); boot->load.start_ops = load->cmd; @@ -461,6 +457,14 @@ int nfb_boot_bw_bmc_load(struct nfb_boot *boot, /* execute requested commands */ if (load->cmd & NFB_BOOT_IOC_LOAD_CMD_ERASE) { + name = fdt_getprop(fdt, node_image, "filename", NULL); + /* a) Can't erase already empty partition. + * b) If isn't empty, the filename must be set. */ + if (prop != NULL || name == NULL) { + ret = -EINVAL; + goto err_cmd; + } + boot->load.current_op = NFB_BOOT_IOC_LOAD_CMD_ERASE; boot->load.current_op_progress_max = 1; From 066298d53d79e972a052bf2b36021e85f3fcd618 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 27 Feb 2025 08:53:28 +0100 Subject: [PATCH 299/518] fix(driver - NDP): check for non-zero value of buffer_size (division by 0) --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index cf6050c5..e3c43372 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -317,6 +317,9 @@ static ssize_t ndp_ctrl_set_ring_size(struct device *dev, value = memparse(buf, NULL); + if (ctrl->cfg.buffer_size == 0) + return -EINVAL; + while (buffer_count * 2 <= value / ctrl->cfg.buffer_size) buffer_count *= 2; From 039cb4d2aa4057c8ae17e8479f30f028f51354f7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 27 Feb 2025 11:06:31 +0100 Subject: [PATCH 300/518] chore(tool - info): show -l argument (print list of available devices) in help --- tools/info/info.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/info/info.c b/tools/info/info.c index d9f4be0c..14bd7b7a 100644 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -98,6 +98,7 @@ void usage(const char *progname, int verbose) printf(" * numa NUMA node\n"); printf(" example of usage: '-q project,build,card'\n"); } + printf("-l Print list of available devices\n"); printf("-v Increase verbosity\n"); printf("-V Show version\n"); printf("-h Show this text\n"); From 589fb4e97d7aab0b6e719d041e91da4f94096ed6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 28 Feb 2025 07:53:15 +0100 Subject: [PATCH 301/518] fix(libnetcope - dma_ctrl_ndp): verify written pointer mask in start --- libnfb/include/netcope/dma_ctrl_ndp.h | 40 +++++++++++++++++++-------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index fedfb59b..39dfb859 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -266,6 +266,26 @@ static inline void nc_ndp_ctrl_sdp_flush(struct nc_ndp_ctrl *ctrl) nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_SDP, ctrl->sdp); } +static inline void _nc_ndp_ctrl_medusa_get_max_ptr_mask(struct nc_ndp_ctrl *ctrl, uint32_t* dp, uint32_t* hp, int set_orig) +{ + uint64_t orig; + uint64_t val_max; + + if (set_orig) + orig = nfb_comp_read64(ctrl->comp, NDP_CTRL_REG_MDP); + + val_max = 0xFFFFFFFFFFFFFFFFull; + nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_MDP, val_max); + val_max = nfb_comp_read64(ctrl->comp, NDP_CTRL_REG_MDP); + + if (set_orig) + nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_MDP, orig); + + /* TODO: LE/BE */ + *dp = ((val_max >> 0) & 0xFFFFFFFF) >> 1; + *hp = ((val_max >> 32) & 0xFFFFFFFF) >> 1; +} + static inline int nc_ndp_ctrl_open(struct nfb_device* nfb, int fdt_offset, struct nc_ndp_ctrl *ctrl) { int ret; @@ -313,6 +333,8 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl uint32_t nb_d = 0; uint64_t d_buffer = 0; + uint32_t mdp_max, mhp_max; + if (ctrl->type == DMA_TYPE_MEDUSA) { nb_d = sp->nb_desc; d_buffer = sp->desc_buffer; @@ -384,6 +406,11 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl /* Set buffer size (mask) */ if (!(ctrl->type == DMA_TYPE_CALYPTE && ctrl->dir == 1)) { + _nc_ndp_ctrl_medusa_get_max_ptr_mask(ctrl, &mdp_max, &mhp_max, 0); + if (ctrl->mdp > mdp_max || ctrl->mhp > mhp_max) { + ret = -ENOMEM; + goto err_mask_mismatch; + } nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MDP, ctrl->mdp); nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MHP, ctrl->mhp); } @@ -400,6 +427,7 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, NDP_CTRL_REG_CONTROL_START); return 0; +err_mask_mismatch: err_comp_running: nfb_comp_unlock(ctrl->comp, COMP_NC_DMA_CTRL_LOCK); err_comp_lock: @@ -408,17 +436,7 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl static inline void nc_ndp_ctrl_medusa_get_max_ptr_mask(struct nc_ndp_ctrl *ctrl, uint32_t* dp, uint32_t* hp) { - uint32_t orig; - - orig = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MHP); - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MHP, 0xFFFFFFFF); - *hp = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MHP) / 2; - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MHP, orig); - - orig = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MDP); - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MDP, 0xFFFFFFFF); - *dp = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_MDP) / 2; - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_MDP, orig); + _nc_ndp_ctrl_medusa_get_max_ptr_mask(ctrl, dp, hp, 1); } static inline int _nc_ndp_ctrl_stop(struct nc_ndp_ctrl *ctrl, int force) From 70d39b29cebf2d389fe01de58eceef29d612a6b8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 28 Feb 2025 07:53:58 +0100 Subject: [PATCH 302/518] Revert "drivers - NDP: [FIX] check for FW pointer maximum size in Medusa" This reverts commit 56d8c2aa1f72deb4d7a905016d59d8f06041267e. --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index e3c43372..cbfd5d00 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -105,9 +105,6 @@ struct ndp_ctrl { int desc_count; int hdr_count; - uint32_t max_hp_mask; - uint32_t max_dp_mask; - void *hdr_buffer; uint8_t hdr_buff_en_rw_map; @@ -192,7 +189,7 @@ static int ndp_ctrl_medusa_req_block_update(struct ndp_ctrl *ctrl, int do_resize struct ndp_ctrl_state_mps s; - if (buffer_size == 0 || buffer_count < min_buffer_items || buffer_count > ctrl->max_dp_mask + 1) + if (buffer_size == 0 || buffer_count < min_buffer_items) return -EINVAL; /* walk through (virtual) ring to obtain parameters @@ -1340,8 +1337,6 @@ static struct ndp_channel *ndp_ctrl_create(struct ndp *ndp, struct ndp_channel_i goto err_ctrl_open; if (is_medusa) { - nc_ndp_ctrl_medusa_get_max_ptr_mask(&ctrl->c, &ctrl->max_dp_mask, &ctrl->max_hp_mask); - /* Set initial parameters for ring */ ndp_buffer_size = ndp_ctrl_buffer_size == 0 ? NDP_CTRL_DEFAULT_BUFFER_SIZE : ndp_ctrl_buffer_size, ndp_ctrl_medusa_req_block_update(ctrl, 0, From af4e15f29197e0814d672a57aed3ec43f20ef362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Thu, 27 Feb 2025 12:58:14 +0000 Subject: [PATCH 303/518] fix(build - ubuntu docker): add missing dpkg-shlibdeps tool --- jenkins/ubuntu.Dockerfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/jenkins/ubuntu.Dockerfile b/jenkins/ubuntu.Dockerfile index 00e6459f..0af00492 100644 --- a/jenkins/ubuntu.Dockerfile +++ b/jenkins/ubuntu.Dockerfile @@ -1,13 +1,12 @@ ARG OSRELEASEVER=focal ARG OSNAME=ubuntu -FROM $OSNAME:$OSRELEASEVER as default +FROM $OSNAME:$OSRELEASEVER AS default RUN /usr/sbin/groupadd -f -g 991 jenkins RUN /usr/sbin/useradd jenkins -u 1000 -g 991 -RUN apt-get update -RUN DEBIAN_FRONTEND=noninteractive TZ=Europe/Prague apt-get -y install tzdata -RUN apt-get install -y git sudo make curl cmake pkg-config file -RUN apt-get install -y autoconf automake libfdt-dev libnuma-dev libncurses-dev libarchive-dev libconfig-dev python3-dev python3-setuptools cython3 libpci-dev pciutils +RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Europe/Prague apt-get -y install tzdata +RUN apt-get update && apt-get install -y git sudo make curl cmake pkg-config file +RUN apt-get update && apt-get install -y autoconf automake libfdt-dev libnuma-dev libncurses-dev libarchive-dev libconfig-dev python3-dev python3-setuptools cython3 libpci-dev pciutils dpkg-dev RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers From 4b1f70f3c422e1df564005f568047d432ee422e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Fri, 28 Feb 2025 08:41:19 +0000 Subject: [PATCH 304/518] maintinance(build - ubuntu docker): update the container version to 22.04 jammy --- jenkins/Jenkinsfile | 4 ++-- jenkins/ubuntu.Dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 51d9b938..92e44f96 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -3,7 +3,7 @@ def osreleasevers = [ // ["centos", "centos7", "7.9.2009", "rpm"], ["oraclelinux", "oraclelinux8", "8", "rpm"], ["oraclelinux", "oraclelinux9", "9", "rpm"], - ["ubuntu", "ubuntu", "focal", "deb"] + ["ubuntu", "ubuntu", "jammy", "deb"] ] def dockertarget = "default" @@ -50,7 +50,7 @@ checkout scm } } - if (osreleasever != '7.9.2009' && osreleasever != 'focal') { + if (osreleasever != '7.9.2009' && osname != 'ubuntu') { stage("Build dpdk RPMs") { sh './build.sh --purge' sh 'sudo ./build.sh --bootstrap-dpdk' diff --git a/jenkins/ubuntu.Dockerfile b/jenkins/ubuntu.Dockerfile index 0af00492..b91f683c 100644 --- a/jenkins/ubuntu.Dockerfile +++ b/jenkins/ubuntu.Dockerfile @@ -1,4 +1,4 @@ -ARG OSRELEASEVER=focal +ARG OSRELEASEVER=jammy ARG OSNAME=ubuntu FROM $OSNAME:$OSRELEASEVER AS default From b69d8c5f2beee8b0c156bcd95f89d1711b55317a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Thu, 27 Feb 2025 15:59:37 +0000 Subject: [PATCH 305/518] fix(build - cpack): give dpkg-shlibdeps the path to libnfb at package build time --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aaefeaa0..0d847a69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,8 @@ # Martin Spinler Date: Fri, 28 Feb 2025 09:50:17 +0100 Subject: [PATCH 306/518] fix(drivers - NDP): check for return value in sysfs set_buffer_size/count --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index cbfd5d00..80252286 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -239,7 +239,7 @@ static ssize_t ndp_ctrl_set_buffer_size(struct device *dev, value = memparse(buf, NULL); - ndp_ctrl_medusa_req_block_update(ctrl, 1, value, ctrl->cfg.buffer_count, ctrl->cfg.initial_offset); + ret = ndp_ctrl_medusa_req_block_update(ctrl, 1, value, ctrl->cfg.buffer_count, ctrl->cfg.initial_offset); if (ret) return ret; @@ -264,7 +264,7 @@ static ssize_t ndp_ctrl_set_buffer_count(struct device *dev, value = memparse(buf, NULL); - ndp_ctrl_medusa_req_block_update(ctrl, 1, ctrl->cfg.buffer_size, value, ctrl->cfg.initial_offset); + ret = ndp_ctrl_medusa_req_block_update(ctrl, 1, ctrl->cfg.buffer_size, value, ctrl->cfg.initial_offset); if (ret) return ret; From f5a05564f6e1514ec65869e0e2d452c39820f455 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 28 Feb 2025 09:56:08 +0100 Subject: [PATCH 307/518] fix(tool - dma): report value errors when setting buffer parameters Switch from fopen/fwrite/fclose to open/write/close as the f* functions can't handle error values when accessing the kernel/sysfs file. --- tools/dma/dma.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 85566cc3..b3d431e3 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -118,18 +119,23 @@ void usage(const char *me, int verbose) int set_ring_size(struct nfb_device *dev, int dir, int index, const char* csize, const char *target) { - FILE *f; + int fd; char path_buffer[128]; + ssize_t ret, sz; snprintf(path_buffer, sizeof(path_buffer), "/sys/class/nfb/nfb%d/ndp/%cx%d/%s", nfb_get_system_id(dev), dir == 0 ? 'r' : 't', index, target); - f = fopen(path_buffer, "wb"); - if (f == NULL) + fd = open(path_buffer, O_RDWR); + if (fd == -1) err(errno, "Can't set %s", target); - fwrite(csize, 1, strlen(csize) + 1, f); - fclose(f); + sz = strlen(csize) + 1; + ret = write(fd, csize, sz); + if (ret != sz) { + err(ret, "Can't set %s", target); + } + close(fd); return 0; } From 82bb3e8bd3b172659104366299d2f401f0005027 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 3 Mar 2025 07:15:06 +0100 Subject: [PATCH 308/518] chore(examples): fix missing include err.h --- doc/examples/csr.c | 1 + doc/examples/ndp.c | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/examples/csr.c b/doc/examples/csr.c index 99f17b51..c160549c 100644 --- a/doc/examples/csr.c +++ b/doc/examples/csr.c @@ -1,3 +1,4 @@ +#include #include #define SUPERCORE_REG_CMD 0x00 diff --git a/doc/examples/ndp.c b/doc/examples/ndp.c index d67a6150..1e262b4d 100644 --- a/doc/examples/ndp.c +++ b/doc/examples/ndp.c @@ -1,4 +1,5 @@ #include +#include #include #include From 4a8db3d38b2997d0e681eb113355ef38c67d042d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 3 Mar 2025 08:49:39 +0100 Subject: [PATCH 309/518] bump version to 6.26.1 --- Changelog | 11 +++++++++++ VERSION | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 3b3f7f81..26fb9568 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,14 @@ +* Mon Mar 3 2025 Martin Spinler - 6.26.1-1 +- [FIX] BittWare BMC: check for name only when erasing +- [FIX] NDP driver: check for non-zero value of buffer_size (division by 0) +- [FIX] NDP driver: check for return value in sysfs set_buffer_size/count +- [FIX] libnetcope - dma_ctrl_ndp: verify written pointer mask in start +- [FIX] nfb-info: show -l argument (print list of available devices) in help +- [FIX] nfb-dma: report value errors when setting buffer parameters +- [FIX] build - ubuntu: add missing dpkg-shlibdeps tool +- [FIX] build - cpack: give dpkg-shlibdeps the path to libnfb at package build time +- [MAINTENANCE]: build - ubuntu docker: update the container version to 22.04 jammy + * Tue Feb 25 2025 Martin Spinler - 6.26.0-1 - [FEATURE]: add boot load interface (ia-440i) - load, delete, set priority - [FEATURE]: add support for BittWare ia-440i (drivers/boot, nfb-bootstrap) diff --git a/VERSION b/VERSION index 4c6a35fb..0e10c8e2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.26.0 +6.26.1 From df7b7474dfddcc48b2e782aad657419c9ff397a8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 4 Mar 2025 13:28:21 +0100 Subject: [PATCH 310/518] fix(DMA Medusa): check for valid MHP value only for RX --- libnfb/include/netcope/dma_ctrl_ndp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 39dfb859..6a3ac60d 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -407,7 +407,7 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl /* Set buffer size (mask) */ if (!(ctrl->type == DMA_TYPE_CALYPTE && ctrl->dir == 1)) { _nc_ndp_ctrl_medusa_get_max_ptr_mask(ctrl, &mdp_max, &mhp_max, 0); - if (ctrl->mdp > mdp_max || ctrl->mhp > mhp_max) { + if (ctrl->mdp > mdp_max || (ctrl->dir == 0 && ctrl->mhp > mhp_max)) { ret = -ENOMEM; goto err_mask_mismatch; } From b8d01aa923af3b932326ad7e2e3a87336086282b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 4 Mar 2025 14:03:23 +0100 Subject: [PATCH 311/518] fix(NDP): use computed buffer_count value in set_ring_size. Use computed buffer_count instead of direct value from userspace, which means ring size. --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 80252286..33b022e4 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -320,7 +320,7 @@ static ssize_t ndp_ctrl_set_ring_size(struct device *dev, while (buffer_count * 2 <= value / ctrl->cfg.buffer_size) buffer_count *= 2; - ret = ndp_ctrl_medusa_req_block_update(ctrl, 1, ctrl->cfg.buffer_size, value, ctrl->cfg.initial_offset); + ret = ndp_ctrl_medusa_req_block_update(ctrl, 1, ctrl->cfg.buffer_size, buffer_count, ctrl->cfg.initial_offset); if (ret) return ret; From 7481854b8309bf530f826943623c832cc1941fe8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 5 Mar 2025 10:00:11 +0100 Subject: [PATCH 312/518] bump version to 6.26.2 --- Changelog | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 26fb9568..8e92dd22 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +* Wed Mar 5 2025 Martin Spinler - 6.26.2-1 +- [FIX] NDP driver: use buffer_count in set_ring_size instead of total buffer_size +- [FIX] libnetcope - dma_ctrl_ndp: check for valid header pointer mask only in RX + * Mon Mar 3 2025 Martin Spinler - 6.26.1-1 - [FIX] BittWare BMC: check for name only when erasing - [FIX] NDP driver: check for non-zero value of buffer_size (division by 0) diff --git a/VERSION b/VERSION index 0e10c8e2..dde9f42f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.26.1 +6.26.2 From aebc969697fa8a6f4a705327b6dff6b4c8615d12 Mon Sep 17 00:00:00 2001 From: Jan Privara Date: Wed, 26 Feb 2025 16:08:04 +0100 Subject: [PATCH 313/518] feat(drivers): add support for nt200a02 --- drivers/kernel/drivers/nfb/pci.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 2503eb92..5ecd8064 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -382,6 +382,15 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) fdt_appendprop(fdt, node, "mtd_size", &prop32, sizeof(prop32)); nfb_fdt_create_binary_slot(fdt, node, "image0", "application0" , 0, 0, 0, 0x01002000, 0x04000000); + nfb_fdt_create_boot_type(fdt, node, "SPI", 4); + } else if (!strcmp(card_name, "NT200A02")) { + prop32 = cpu_to_fdt32(1); + fdt_appendprop(fdt, node, "num_flash", &prop32, sizeof(prop32)); + prop32 = cpu_to_fdt32(64 * 1024 * 1024); + fdt_appendprop(fdt, node, "mtd_size", &prop32, sizeof(prop32)); + + nfb_fdt_create_binary_slot(fdt, node, "image0", "application0" , 0, 0, 0, 0x00000000, 0x04000000); + nfb_fdt_create_boot_type(fdt, node, "SPI", 4); } } From 77c8f8586d04024712cd161d3c3271678a7f0dc6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 11 Mar 2025 11:36:14 +0100 Subject: [PATCH 314/518] fix(libnfb-ext-grpc): use experimental prefix on grpc++ < 1.41 --- ext/libnfb_ext_grpc/CMakeLists.txt | 43 +++++++++++++++++---------- ext/libnfb_ext_grpc/client_dma_vas.cc | 4 +++ ext/libnfb_ext_grpc/client_dma_vas.hh | 4 +++ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/ext/libnfb_ext_grpc/CMakeLists.txt b/ext/libnfb_ext_grpc/CMakeLists.txt index ff411df1..a480efd8 100644 --- a/ext/libnfb_ext_grpc/CMakeLists.txt +++ b/ext/libnfb_ext_grpc/CMakeLists.txt @@ -12,9 +12,12 @@ cmake_policy(VERSION 3.15) project(libnfb-ext-grpc C CXX) include(GNUInstallDirs) +find_package(PkgConfig) find_package(Protobuf CONFIG) find_package(gRPC QUIET) +pkg_check_modules(GRPC141 QUIET "grpc++<1.41") + set(PROTO_NFB nfb/ext/protobuf/v1/nfb.proto) set(PROTO_DMA nfb/ext/protobuf/v1/dma.proto) set(PROTO_FILES ${PROTO_NFB} ${PROTO_DMA}) @@ -46,19 +49,22 @@ else() # NFB proto get_filename_component(nfb_proto_abs ${PROTO_NFB} ABSOLUTE) - get_filename_component(nfb_proto_path "${nfb_proto_abs}" PATH) + get_filename_component(nfb_proto_path "${nfb_proto_abs}" DIRECTORY) + get_filename_component(nfb_proto_path_rel ${PROTO_NFB} DIRECTORY) + + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${nfb_proto_path_rel}/") - set(nfb_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/nfb.pb.cc") - set(nfb_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/nfb.pb.h") - set(nfb_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/nfb.grpc.pb.cc") - set(nfb_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/nfb.grpc.pb.h") + set(nfb_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/${nfb_proto_path_rel}/nfb.pb.cc") + set(nfb_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${nfb_proto_path_rel}/nfb.pb.h") + set(nfb_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/${nfb_proto_path_rel}/nfb.grpc.pb.cc") + set(nfb_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${nfb_proto_path_rel}/nfb.grpc.pb.h") add_custom_command( OUTPUT "${nfb_proto_srcs}" "${nfb_proto_hdrs}" "${nfb_grpc_srcs}" "${nfb_grpc_hdrs}" COMMAND ${_PROTOBUF_PROTOC} - ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" - --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" - -I "${nfb_proto_path}" + ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}/${nfb_proto_path_rel}" + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}/${nfb_proto_path_rel}" + -I "${CMAKE_CURRENT_SOURCE_DIR}/${nfb_proto_path_rel}" --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" "${nfb_proto_abs}" DEPENDS "${nfb_proto_abs}") @@ -67,19 +73,20 @@ else() # DMA proto get_filename_component(dma_proto_abs ${PROTO_DMA} ABSOLUTE) - get_filename_component(dma_proto_path "${dma_proto_abs}" PATH) + get_filename_component(dma_proto_path "${dma_proto_abs}" DIRECTORY) + get_filename_component(dma_proto_path_rel ${PROTO_DMA} DIRECTORY) - set(dma_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/dma.pb.cc") - set(dma_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/dma.pb.h") - set(dma_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/dma.grpc.pb.cc") - set(dma_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/dma.grpc.pb.h") + set(dma_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/${dma_proto_path_rel}/dma.pb.cc") + set(dma_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${dma_proto_path_rel}/dma.pb.h") + set(dma_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/${dma_proto_path_rel}/dma.grpc.pb.cc") + set(dma_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${dma_proto_path_rel}/dma.grpc.pb.h") add_custom_command( OUTPUT "${dma_proto_srcs}" "${dma_proto_hdrs}" "${dma_grpc_srcs}" "${dma_grpc_hdrs}" COMMAND ${_PROTOBUF_PROTOC} - ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" - --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" - -I "${dma_proto_path}" + ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}/${dma_proto_path_rel}" + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}/${dma_proto_path_rel}" + -I "${CMAKE_CURRENT_SOURCE_DIR}/${dma_proto_path_rel}" --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" "${dma_proto_abs}" DEPENDS "${dma_proto_abs}") @@ -113,6 +120,10 @@ set_target_properties(nfb-ext-proto PUBLIC_HEADER "${PROTO_FILES}" ) +if(${GRPC141_FOUND}) + target_compile_definitions(nfb-ext-grpc PUBLIC GRPC_ASYNC_EXPERIMENTAL) +endif() + install(TARGETS nfb-ext-grpc COMPONENT NfbExtGrpc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/ext/libnfb_ext_grpc/client_dma_vas.cc b/ext/libnfb_ext_grpc/client_dma_vas.cc index 8aa360e5..d1033b35 100644 --- a/ext/libnfb_ext_grpc/client_dma_vas.cc +++ b/ext/libnfb_ext_grpc/client_dma_vas.cc @@ -23,7 +23,11 @@ DmaAccess::DmaAccess(pb_dma::Dma::Stub* stub) : bind(true) { +#ifdef GRPC_ASYNC_EXPERIMENTAL + stub->experimental_async()->RqStream(&context, this); +#else stub->async()->RqStream(&context, this); +#endif StartRead(&req); StartCall(); } diff --git a/ext/libnfb_ext_grpc/client_dma_vas.hh b/ext/libnfb_ext_grpc/client_dma_vas.hh index bc105cc5..6e7c86b4 100644 --- a/ext/libnfb_ext_grpc/client_dma_vas.hh +++ b/ext/libnfb_ext_grpc/client_dma_vas.hh @@ -31,7 +31,11 @@ public: namespace pb_dma = nfb::ext::protobuf::v1; +#ifdef GRPC_ASYNC_EXPERIMENTAL +class DmaAccess : public grpc::experimental::ClientBidiReactor +#else class DmaAccess : public grpc::ClientBidiReactor +#endif { protected: grpc::ClientContext context; From c3fbf7b8266c8b13748adf92eabf7a4647130dc5 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 13 Mar 2025 15:31:50 +0100 Subject: [PATCH 315/518] fix(libnfb - ndp): count SZE in ndp_get_queue_count This fixes 5925f3ad --- libnfb/include/netcope/ndp_core.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libnfb/include/netcope/ndp_core.h b/libnfb/include/netcope/ndp_core.h index e9ca9578..c4482764 100644 --- a/libnfb/include/netcope/ndp_core.h +++ b/libnfb/include/netcope/ndp_core.h @@ -250,6 +250,7 @@ int ndp_get_rx_queue_count(const struct nfb_device *dev) return fdt_get_subnode_count(dev->fdt, "/drivers/ndp/rx_queues"); } else { return + nfb_comp_count(dev, COMP_NETCOPE_RXQUEUE_SZE) + nfb_comp_count(dev, COMP_NETCOPE_RXQUEUE_NDP) + nfb_comp_count(dev, COMP_NETCOPE_RXQUEUE_CALYPTE); } @@ -261,6 +262,7 @@ int ndp_get_tx_queue_count(const struct nfb_device *dev) return fdt_get_subnode_count(dev->fdt, "/drivers/ndp/tx_queues"); } else { return + nfb_comp_count(dev, COMP_NETCOPE_TXQUEUE_SZE) + nfb_comp_count(dev, COMP_NETCOPE_TXQUEUE_NDP) + nfb_comp_count(dev, COMP_NETCOPE_TXQUEUE_CALYPTE); } From f6b50d956e5b3a98a24a140e463c2535132ea7ca Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 13 Mar 2025 16:40:15 +0100 Subject: [PATCH 316/518] bump version to 6.26.3 --- Changelog | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 8e92dd22..c0af24ab 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +* Thu Mar 13 2025 Martin Spinler - 6.26.3-1 +- [FIX] libnfb: count queues in no-driver mode - add SZE queues +- [FIX] libnfb-ext-grpc: use experimental prefix on grpc++ < 1.41 + * Wed Mar 5 2025 Martin Spinler - 6.26.2-1 - [FIX] NDP driver: use buffer_count in set_ring_size instead of total buffer_size - [FIX] libnetcope - dma_ctrl_ndp: check for valid header pointer mask only in RX diff --git a/VERSION b/VERSION index dde9f42f..7eeb87d9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.26.2 +6.26.3 From 84488456fb83f5e095ea2765432573479a9ed190 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 17 Mar 2025 10:41:50 +0100 Subject: [PATCH 317/518] chore(Jenkinsfile): run createrepo after copying artifacts --- jenkins/Jenkinsfile | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 92e44f96..36112875 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -1,21 +1,21 @@ def projectpath = "ndk/swbase" def osreleasevers = [ // ["centos", "centos7", "7.9.2009", "rpm"], - ["oraclelinux", "oraclelinux8", "8", "rpm"], - ["oraclelinux", "oraclelinux9", "9", "rpm"], - ["ubuntu", "ubuntu", "jammy", "deb"] - ] + ["oraclelinux", "oraclelinux8", "8", "rpm"], + ["oraclelinux", "oraclelinux9", "9", "rpm"], + ["ubuntu", "ubuntu", "jammy", "deb"] +] def dockertarget = "default" node('docker') { -cleanWs() -checkout scm + cleanWs() + checkout scm - for (int i = 0; i < osreleasevers.size(); ++i) { - def osname = osreleasevers[i][0]; - def dockerfile = osreleasevers[i][1]; - def osreleasever = osreleasevers[i][2]; - def pkg = osreleasevers[i][3]; + for (ver in osreleasevers) { + def osname = ver[0] + def dockerfile = ver[1] + def osreleasever = ver[2] + def pkg = ver[3] stage("Prepare docker for ${osname}:${osreleasever}") { buildImage = docker.build("swbase-${osname}-${osreleasever}-${dockertarget}", "-f jenkins/${dockerfile}.Dockerfile --target ${dockertarget} --build-arg OSRELEASEVER=${osreleasever} --build-arg OSNAME=${osname} .") @@ -85,5 +85,14 @@ node { mkdir -p ${CI_SNAPSHOTS_PATH}/${projectpath}/${BRANCH_NAME} rsync -ur --chmod=g+w artifacts/* ${CI_SNAPSHOTS_PATH}/${projectpath}/${BRANCH_NAME} """ + + for (ver in osreleasevers) { + def osname = ver[0] + def osreleasever = ver[2] + def pkg = ver[3] + if (pkg == "rpm") { + sh """createrepo --update ${CI_SNAPSHOTS_PATH}/${projectpath}/${BRANCH_NAME}/${osname}-${osreleasever}""" + } + } } } From bb2e84fd771eb10de1f1cde25b35790eaf0123b6 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Mon, 24 Mar 2025 12:33:37 +0100 Subject: [PATCH 318/518] fix(libnetcope - mdio): add new PMA types to configure f-tile Eth phys correctly Fix PMA mode switching on 400G cards based on Intel F-Tile FPGA --- libnfb/include/netcope/mdio.h | 50 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 606a7f2b..830a7d9c 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -472,6 +472,43 @@ static inline void nc_mdio_ftile_fgt_attribute_write(struct nc_mdio *mdio, int p } while ((service_req != 0 || reset != 0) && ++retries < 1000); } + +static inline int _get_media_type(uint16_t pma_type) +/* Return f-tile media type constant for given PMA type */ +{ + static const int OPTIC = 0x14; + static const int METAL = 0x10; + + switch (pma_type) { + + case 0x63: return OPTIC; /* 400GBASE-ER8 */ + case 0x62: return OPTIC; /* 400GBASE-LR4-6 */ + case 0x61: return OPTIC; /* 400GBASE-FR4 */ + case 0x60: return OPTIC; /* 400GBASE-SR4.2 */ + case 0x5f: return OPTIC; /* 400GBASE-SR8 */ + case 0x5c: return OPTIC; /* 400GBASE-LR8 */ + case 0x5b: return OPTIC; /* 400GBASE-FR8 */ + case 0x5a: return OPTIC; /* 400GBASE-DR4 */ + case 0x59: return OPTIC; /* 400GBASE-SR16 */ + case 0x58: return OPTIC; /* 200GBASE-ER4 */ + case 0x55: return OPTIC; /* 200GBASE-LR4 */ + case 0x54: return OPTIC; /* 200GBASE-FR4 */ + case 0x53: return OPTIC; /* 200GBASE-DR4 */ + case 0x52: return OPTIC; /* 200GBASE-SR4 */ + case 0x4e: return OPTIC; /* 100GBASE-ZR */ + case 0x4d: return OPTIC; /* 100GBASE-LR */ + case 0x4c: return OPTIC; /* 100GBASE-FR */ + case 0x4b: return OPTIC; /* 100GBASE-DR */ + case 0x4a: return OPTIC; /* 100GBASE-SR2 */ + case 0x45: return OPTIC; /* 50GBASE-ER */ + case 0x44: return OPTIC; /* 50GBASE-LR */ + case 0x43: return OPTIC; /* 50GBASE-FR */ + case 0x42: return OPTIC; /* 50GBASE-SR */ + default: return METAL; /* All -CR and -KR types */ + } +} + + static inline void nc_mdio_fixup_ftile_set_mode(struct nc_mdio *mdio, int prtad, uint16_t val) { int i; @@ -479,19 +516,8 @@ static inline void nc_mdio_fixup_ftile_set_mode(struct nc_mdio *mdio, int prtad, if (mdio->link_encoding == MDIO_PMA_ENC_NRZ) return; /* Not necessary to change media mode for NRZ modes */ - if ( - (val == 0x5B || val == 0x5C) || /* 400GBASE-R8 */ - (val == 0x5F) || /* 400GBASE-SR8 */ - (val >= 0x52 && val <= 0x55) || /* 200GBASE-R4 */ - (val == 0x4A) || /* 100GBASE-R2 */ - (val >= 0x42 && val <= 0x45)) /* 50GBASE-R1 */ - { - media_type = 0x14; // optical - /* all other media types */ - } else { - media_type = 0x10; // default = -CR - } + media_type = _get_media_type(val); for (i = 0; i < mdio->pma_lanes; i++) { nc_mdio_ftile_fgt_attribute_write(mdio, prtad, media_type, i, 0x64); } From 585b17049b2f6a9d123fbfbd5cb9ae4377340bbd Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Mon, 24 Mar 2025 15:53:54 +0100 Subject: [PATCH 319/518] fix(ieee802.3): unify 400GBASE-SR4-2 PMA mode string --- tools/eth/ieee802_3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/eth/ieee802_3.c b/tools/eth/ieee802_3.c index e7d43b35..a2ccc645 100644 --- a/tools/eth/ieee802_3.c +++ b/tools/eth/ieee802_3.c @@ -118,7 +118,7 @@ static const struct pma_pmd_type_t ieee802_3_pma_pmd_type[] = { {0x5D, "400GBASE-KR4", -1, 16 | IEEE802_3_FLAG_FEC_MANDATORY}, {0x5E, "400GBASE-CR4", -1, 16 | IEEE802_3_FLAG_FEC_MANDATORY}, {0x5F, "400GBASE-SR8", -1, 16 | IEEE802_3_FLAG_FEC_MANDATORY}, - {0x60, "400GBASE-SR4.2", -1, 16 | IEEE802_3_FLAG_FEC_MANDATORY}, + {0x60, "400GBASE-SR4-2", -1, 16 | IEEE802_3_FLAG_FEC_MANDATORY}, {0x61, "400GBASE-FR4", -1, 16 | IEEE802_3_FLAG_FEC_MANDATORY}, {0x62, "400GBASE-LR4-6", -1, 16 | IEEE802_3_FLAG_FEC_MANDATORY}, {0x63, "400GBASE-ER8", -1, 16 | IEEE802_3_FLAG_FEC_MANDATORY}, From ca2f96e127fc6c64004d350d9740c4157bbe92f7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 2 Apr 2025 13:04:40 +0200 Subject: [PATCH 320/518] fix(tsu): use nfb_comp_trylock --- libnfb/include/netcope/tsu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/tsu.h b/libnfb/include/netcope/tsu.h index e36c8e9e..3ee63b06 100644 --- a/libnfb/include/netcope/tsu.h +++ b/libnfb/include/netcope/tsu.h @@ -238,7 +238,7 @@ static inline unsigned nc_tsu_get_frequency(struct nc_tsu *tsu) static inline int nc_tsu_lock(struct nc_tsu *tsu) { - return nfb_comp_lock(nfb_user_to_comp(tsu), TSU_LOCK_MODIFY); + return nfb_comp_trylock(nfb_user_to_comp(tsu), TSU_LOCK_MODIFY, 100) == 0 ? 1 : 0; } static inline void nc_tsu_unlock(struct nc_tsu *tsu) From 65887f4b0d68c90bc6b7ce02d23919fa7b63e6d9 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Tue, 25 Mar 2025 16:00:51 +0100 Subject: [PATCH 321/518] fix(nfb-eth): wait for QSFP ready before reading monitor data --- tools/eth/qsfpp.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/eth/qsfpp.c b/tools/eth/qsfpp.c index c4d296a6..669dafa4 100644 --- a/tools/eth/qsfpp.c +++ b/tools/eth/qsfpp.c @@ -18,6 +18,7 @@ /* I2C registers addresses */ #define SFF8636_IDENTIFIER 0 #define SFF8636_REV_COMPLIANCE 1 +#define SFF8636_STATUS 2 #define SFF8636_TEMPERATURE 22 #define SFF8636_RX_INPUT_POWER 34 #define SFF8636_STXDISABLE 86 @@ -409,6 +410,15 @@ void sff8636_print(struct nc_i2c_ctrl *ctrl) uint8_t i; uint8_t reg = 0xFF; uint16_t reg16 = 0; + int retries = 0; + int ret; + + /* Wait for Data Ready (max 2 sec according specs) */ + /* TODO: this should be done in qsfp_i2c_common functions */ + /* TODO: use nfb_comp_read32_poll_timeout, as this implemenation is time unstable */ + do { + ret = nc_i2c_read_reg(ctrl, SFF8636_STATUS, ®, 1); + } while (ret == 1 && ((reg & 0x01) == 0x1) && (++retries < 10000)); reg16 = qsfp_i2c_read16(ctrl, SFF8636_TEMPERATURE); printf("Temperature : %.2f C\n", ((float) reg16) / 256); From 019f8c9a08305159b5389dd5c4777893d0759ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Thu, 20 Mar 2025 08:03:05 +0100 Subject: [PATCH 322/518] fix(tool - nfb-tsu): Reduce number of card accesses --- tools/tsu/tsu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/tsu/tsu.c b/tools/tsu/tsu.c index e35ec1c4..db60c2b3 100644 --- a/tools/tsu/tsu.c +++ b/tools/tsu/tsu.c @@ -37,7 +37,8 @@ int logfile; #define CONVERGEIN 10.0 #define MAX_DIVERGENCE 600 // maximun divegence in sec - will reset card time if reached #define SYSTEM_TIME_TIMEOUT 10000 -#define GET_SYSTEM_TIME_REPEAT 10000 +#define GET_SYSTEM_TIME_REPEAT 5 +#define GET_SYSTEM_TIME_SPINUP 40000 #define INC_MAX 2.980215192E-08 #define PROGNAME "nfb-tsu" @@ -231,7 +232,12 @@ int get_tsu_sys_timespecx_with_mindiff(struct timespecx *tsu_time, struct timesp min = SYSTEM_TIME_TIMEOUT; - // try to get time more times to filter when get_system gets stuck + // spin up CPU before trying for real + for (j = 0; j < GET_SYSTEM_TIME_SPINUP; j++) { + sys_get_time(&sys_tsx); + } + + // try GET_SYSTEM_TIME_REPEAT times, save the best result for (j = 0; j < GET_SYSTEM_TIME_REPEAT; j++) { tsu_get_time(&tsu0_fp); sys_get_time(&sys_fp); From 31c13475a200ee910da4c1b14613e6d467ac6d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Thu, 20 Mar 2025 08:15:48 +0100 Subject: [PATCH 323/518] chore(tool - nfb-tsu): remove redundant time format lf_p --- tools/tsu/tsu.c | 59 ++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/tools/tsu/tsu.c b/tools/tsu/tsu.c index db60c2b3..58c22ba6 100644 --- a/tools/tsu/tsu.c +++ b/tools/tsu/tsu.c @@ -69,18 +69,6 @@ struct tclock { struct tclock ptm_clock; -typedef struct { - uint32_t l_ui; - uint32_t l_uf; -} l_fp; - -#define FP2TX(f, t) \ - do { \ - (t).tv_sec = (f).l_ui; \ - (t).tv_xsec = ((f).l_uf >> 2); \ - } while (0) - - static inline double xs2us(int32_t x) { return (double) x * 1.0e6 / XANOSEC; @@ -123,34 +111,34 @@ void print_tsx(const char* prefix, struct timespecx tsx, const char * suffix) printf("%s", suffix); } -void sys_get_time(l_fp *fp) +void sys_get_time(struct timespecx *tsx) { struct timespec ts; - double tmp; + long double tmp; clock_gettime(CLOCK_REALTIME, &ts); - tmp = ts.tv_nsec / 1000000000.; - fp->l_uf = (unsigned) (tmp * FRAC); - fp->l_ui = ts.tv_sec; + tmp = ts.tv_nsec / 1000000000.L; + tsx->tv_xsec = (uint32_t) (tmp * XANOSEC); + tsx->tv_sec = ts.tv_sec; } -static inline void tsu_get_time(l_fp *time) +static inline void tsu_get_time(struct timespecx *time) { struct nc_tsu_time tsu_time; tsu_time = nc_tsu_get_rtr(tsu_comp); - time->l_ui = tsu_time.sec; - time->l_uf = tsu_time.fraction >> 32; + time->tv_sec = tsu_time.sec; + time->tv_xsec = tsu_time.fraction >> 34; } -static inline void tsu_set_time(l_fp *time) +static inline void tsu_set_time(struct timespecx *time) { struct nc_tsu_time tsu_time; - tsu_time.sec = time->l_ui; - tsu_time.fraction = time->l_uf; - tsu_time.fraction <<= 32; + tsu_time.sec = time->tv_sec; + tsu_time.fraction = time->tv_xsec; + tsu_time.fraction <<= 34; nc_tsu_set_rtr(tsu_comp, tsu_time); } @@ -228,7 +216,6 @@ int get_tsu_sys_timespecx_with_mindiff(struct timespecx *tsu_time, struct timesp long double min, current; struct timespecx tsu0_tsx, tsu1_tsx, sys_tsx; - l_fp tsu0_fp, tsu1_fp, sys_fp; min = SYSTEM_TIME_TIMEOUT; @@ -239,13 +226,9 @@ int get_tsu_sys_timespecx_with_mindiff(struct timespecx *tsu_time, struct timesp // try GET_SYSTEM_TIME_REPEAT times, save the best result for (j = 0; j < GET_SYSTEM_TIME_REPEAT; j++) { - tsu_get_time(&tsu0_fp); - sys_get_time(&sys_fp); - tsu_get_time(&tsu1_fp); - - FP2TX(tsu0_fp, tsu0_tsx); - FP2TX(tsu1_fp, tsu1_tsx); - FP2TX(sys_fp, sys_tsx); + tsu_get_time(&tsu0_tsx); + sys_get_time(&sys_tsx); + tsu_get_time(&tsu1_tsx); current = tsx_diff_us(tsu1_tsx, tsu0_tsx); if (current < min) { @@ -342,11 +325,11 @@ void engine_system(struct tclock *cl) /* comparison: systime - RTR time */ diff = tsx_diff(sys_time, tsu_time); if (abs(diff.tv_sec) > MAX_DIVERGENCE) { - l_fp fp; + struct timespecx tsx; printf("Time diverged too much - reseting TSU time to system time\n"); - sys_get_time(&fp); - tsu_set_time(&fp); + sys_get_time(&tsx); + tsu_set_time(&tsx); usleep(SLEEPTIME); continue; } @@ -365,7 +348,7 @@ void engine_system(struct tclock *cl) void tsu_init(struct tclock *cl) { - l_fp fp; + struct timespecx tsx; /* syslog init */ openlog(PROGNAME, LOG_PERROR, LOG_DAEMON); @@ -387,8 +370,8 @@ void tsu_init(struct tclock *cl) nc_tsu_set_inc(tsu_comp, cl->incr); /* init TSU time to current system time */ - sys_get_time(&fp); - tsu_set_time(&fp); + sys_get_time(&tsx); + tsu_set_time(&tsx); nc_tsu_enable(tsu_comp); syslog(LOG_INFO, "TSU enabled - start generating valid timestamps"); From 5facdff859a80fe93d618821a917b0286d005c7f Mon Sep 17 00:00:00 2001 From: Daniel Kondys Date: Wed, 16 Apr 2025 10:17:10 +0200 Subject: [PATCH 324/518] docs(tools): add a directory for images with two diagrams (examples) for the nfb-busdebugctl doc --- doc/tools/img/nfb-busdebugctl_example1.drawio.svg | 4 ++++ doc/tools/img/nfb-busdebugctl_example2.drawio.svg | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 doc/tools/img/nfb-busdebugctl_example1.drawio.svg create mode 100644 doc/tools/img/nfb-busdebugctl_example2.drawio.svg diff --git a/doc/tools/img/nfb-busdebugctl_example1.drawio.svg b/doc/tools/img/nfb-busdebugctl_example1.drawio.svg new file mode 100644 index 00000000..66d15e9b --- /dev/null +++ b/doc/tools/img/nfb-busdebugctl_example1.drawio.svg @@ -0,0 +1,4 @@ + + + +
A
B
C
Backpressure (DST_RDY)
Data + control signals
\ No newline at end of file diff --git a/doc/tools/img/nfb-busdebugctl_example2.drawio.svg b/doc/tools/img/nfb-busdebugctl_example2.drawio.svg new file mode 100644 index 00000000..7ba71dc6 --- /dev/null +++ b/doc/tools/img/nfb-busdebugctl_example2.drawio.svg @@ -0,0 +1,4 @@ + + + +
Debug Master
MI
Debug Probe
Debug Probe
RX
RX
TX
TX
A
RX
TX
B
RX
TX
C
RX
TX
Debug Probe
RX
TX
Debug Probe
RX
TX
SW
nfb-busdebugctl
Backpressure (DST_RDY)
Data + control signals
\ No newline at end of file From 5afd4fbd5d314f8b80c12e53759341893a3e01e9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 17 Apr 2025 13:11:58 +0200 Subject: [PATCH 325/518] chore(GH pages): update base image for doc generating --- .github/workflows/doc.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 6f5bdf4f..35525f14 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -10,13 +10,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup and build run: | - sudo apt-get install python3-pip doxygen git - sudo apt-get install autoconf automake libfdt-dev libnuma-dev libncurses-dev libarchive-dev libconfig-dev python3-dev python3-setuptools cython3 + sudo apt-get update + sudo apt-get -y install python3-pip doxygen git cmake rsync graphviz + sudo apt-get -y install autoconf automake libfdt-dev libnuma-dev libncurses-dev libarchive-dev libconfig-dev python3-dev python3-setuptools cython3 pip3 install sphinx sphinx_rtd_theme breathe fdt bash build.sh --prepare (mkdir cmake-build; cd cmake-build; cmake --install-prefix=/usr/ ..; make; sudo make install) @@ -24,7 +25,7 @@ jobs: sphinx-build -M html doc public touch public/html/.nojekyll - name: Deploy - uses: JamesIves/github-pages-deploy-action@4.1.4 + uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages folder: public/html From 029ec2507d3413b8e882f2d59aef6fd3d6641c7c Mon Sep 17 00:00:00 2001 From: Daniel Kondys Date: Fri, 11 Apr 2025 18:28:31 +0200 Subject: [PATCH 326/518] docs(tools): add documentation of the nfb-busdebugctl tool --- doc/tools/nfb-busdebugctl.rst | 147 ++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 doc/tools/nfb-busdebugctl.rst diff --git a/doc/tools/nfb-busdebugctl.rst b/doc/tools/nfb-busdebugctl.rst new file mode 100644 index 00000000..2b0b8b8e --- /dev/null +++ b/doc/tools/nfb-busdebugctl.rst @@ -0,0 +1,147 @@ +.. _nfb_busdebugctl: + +nfb-busdebugctl +--------------- + +This tool can be very useful for debugging streaming buses (typically MFB and MVB in the NDK). +It communicates with the Streaming Debug components in the FW - Streaming Debug Master and Probe. +The Debug Probes are (need to be) inserted into the pipeline between neighboring components. +More info can be found in the documentation for STREAMING_DEBUG_MASTER. + +The Streaming Debug system (Master+Probe) in the FW (must be integrated first) provides counts of: + +- `Data words`: A data word is transferred from one FW component (the Source), which has valid data prepared to send to the neighboring component (the Destination/Sink), which is ready to accept it (SRC_RDY='1', DST_RDY='1'). +- `Wait cycles`: A wait cycle is when the Source does not have valid data prepared to send to the Destination, however, this Destination component is not ready to accept new data anyway (SRC_RDY='0', DST_RDY='0'). +- `Destination hold cycles`: The Source has valid data prepared to send to the Destination, but the Destination is not ready to accept new data (SRC_RDY='1', DST_RDY='0'). +- `Source hold cycles`: The Source does not have valid data prepared to send to the Destination, which is (would be) able to accept them (SRC_RDY='0', DST_RDY='1'). +- `Started transactions`: the number of started transactions (SRC_RDY='1', DST_RDY='1', SOP='1') - should be similar to the number of Ended transactions; both give a rough estimate of the number of processed packets. +- `Ended transactions`: the number of ended transactions (SRC_RDY='1', DST_RDY='1', EOP='1') - should be similar to the number of Started transactions; both give a rough estimate of the number of processed packets. + +Parameters +~~~~~~~~~~ + +.. code-block:: console + + $ nfb-busdebugctl -h + Usage: nfb-busdebugctl [-ABDElhV] [-d path] [-e 0|1] [-i probe] [-n probe] + + Only one command may be used at a time. + -d path Path to device file to use + -e 0|1 Start(1)/Stop(0) counters (start also resets their values) + -i probe Select probe using "master_index:probe_id" (default "0:0") + -n probe Select probe using "probe_name" + -A Print status or affect all probes + -B Block data on probed bus + -D Drop data on probed bus + -E Enable normal functionality on probed bus + -l List available probes + -h Show this text + -V Show version + +Counters start counting immediately after boot/power up. +Keep in mind that the counter of `Source hold cycles` will probably never show zero, as there is always some delay before the first data arrives. +This is the expected behavior. +To reset the counters, use parameter "-e": `-e0` to stop the counters, `-e1` to reset their values and enable them. + +Parameters "-i" and "-n" identify one of the Probes + +- `-i 0:1`: using two numbers in format **x:y** where **x** is the ID of the Master and **y** is the ID of one of the Master's Probes. + Beware that the behavior of this parameter is not very consistent. +- `-n XYZA`: This one uses a four-letter string (name) that has been assigned to the Probe in the FW design (as a generic parameter). + These Probe names and their connections can be obtained either from their instantiation in the FW or its documentation - if provided. + Notice that multiple Probes of different Masters have the same name (common for multi-stream pipelines where one Master is per one stream). + See the output of `nfb-busdebugctl -l` below. + +All available Probes can be listed using `nfb-busdebugctl -l`. +Both forms of Probe identification ("-i", "-n") are used in the output. + +.. code-block:: console + + $ nfb-busdebugctl -l + 0:0 - RXEH + 0:1 - RXED + 0:2 - HFEO + 0:3 - RSSO + 0:4 - FLTO + 0:5 - PFIO + 0:6 - TXCH + 0:7 - TXCD + 0:8 - RXDH + 0:9 - RXDD + 1:0 - RXEH + 1:1 - RXED + 1:2 - HFEO + 1:3 - RSSO + ... + +This FW design contains two (identical) 100G streams (pipelines), and the Master+Probes have been instantiated per each stream. +Notice how the Probe names are the same for both Masters. + +Parameters "-B", "-D", and "-E" are used for advanced features for "Bus Control", see documentation of Streaming Debug. +TL;DR: if the Master is set accordingly and the Probes are connected appropriately, use: + +- `-B XYZA` to block traffic at the selected Probe, +- `-D XYZA` to drop traffic at the selected Probe, and +- `-E XYZA` to return the selected Probe to its flow-through state. + +.. warning:: + Beware that the "Bus Control" feature is often not needed, which is reflected by the connection of Probes in the FW (see documentation of the Streaming Debug components). Hence, these three parameters may not work. + +How to use +~~~~~~~~~~ + +This tool is typically used when locating a place that either decreases throughput (bottleneck) or blocks all traffic (design is stuck). +The most common way to identify this is to issue the `nfb-busdebugctl -A` command and watch the `Destination hold cycles` counter of all Probes. +It is recommended to analyze the difference in these counters over a (short) period of time: + +.. code-block:: console + + $ nfb-busdebugctl -A > first_sample.txt + $ nfb-busdebugctl -A > second_sample.txt + $ vimdiff first_sample.txt second_sample.txt + +This creates a bounded interval, which nullifies idle clock cycles before any data are transmitted and other potentially unwanted effects. + +How to read the probed data +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The following diagram is borrowed from the documentation of the Streaming Debug components. +It shows a simple pipeline of three FW components (modules): A, B, and C. + +.. _figure1: + +.. image:: img/nfb-busdebugctl_example1.drawio.svg + :align: center + :width: 60 % + + An example of a stream pipeline where component A sends data to comp B and B to C (blue lines) and where C uses backpressure to pause data from B and B to A (red lines). + +When performing analysis, watch for incrementing counters of the `Destination hold cycles`. +These are the ones that indicate that something is holding back the traffic. +When viewing the difference between the samples of `nfb-busdebugctl -A`, three scenarios can occur. +The `Destination hold cycles` counter is incremented on: + +#. all Probes in the pipeline -> the blocking occurs somewhere further downstream of the probed pipeline. +#. none of the Probes in the pipeline -> the blocking occurs somewhere before the probed pipeline. +#. only some of the Probes in the pipeline -> the blocking is done by a component in the probed pipeline. + +The third point indicates an inefficiency in the pipeline. +How to determine which component is at flaw? +This is best explained using a picture. +The following picture builds on the example above, showing the same pipeline with connected Debug Probes. + +.. _figure2: + +.. image:: img/nfb-busdebugctl_example2.drawio.svg + :align: center + :width: 60 % + + Debug Probes on the input and output of the pipeline and in between the components A, B, and C. + +If the `Destination hold cycles` counters increment on Probes: + +#. on the input before component A, and +#. between components A and B + +then this would indicate that component C is the one blocking the traffic. + From 3be9a0f6ec31874bdddb5e737ae8dc0bfa22ea9b Mon Sep 17 00:00:00 2001 From: Daniel Kondys Date: Fri, 11 Apr 2025 18:29:14 +0200 Subject: [PATCH 327/518] docs(tools): integrate documentation of the nfb-busdebugctl tool --- doc/tools/nfb-tools.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/tools/nfb-tools.rst b/doc/tools/nfb-tools.rst index 083ea036..d57d2af1 100644 --- a/doc/tools/nfb-tools.rst +++ b/doc/tools/nfb-tools.rst @@ -49,3 +49,8 @@ NFB tools .. include:: nfb-tsu.rst :start-line: 5 :end-line: 6 + +.. rubric:: :ref:`nfb-busdebugctl` +.. include:: nfb-busdebugctl.rst + :start-line: 5 + :end-line: 6 From 8a74b0f609c6f4050406150a86b259458168865a Mon Sep 17 00:00:00 2001 From: Daniel Kondys Date: Wed, 23 Apr 2025 07:24:02 +0200 Subject: [PATCH 328/518] docs(tools): augment the documentation of the nfb-busdebugctl tool by adding references to the Streaming Debug FW components --- doc/tools/nfb-busdebugctl.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/tools/nfb-busdebugctl.rst b/doc/tools/nfb-busdebugctl.rst index 2b0b8b8e..d608ee5e 100644 --- a/doc/tools/nfb-busdebugctl.rst +++ b/doc/tools/nfb-busdebugctl.rst @@ -6,7 +6,7 @@ nfb-busdebugctl This tool can be very useful for debugging streaming buses (typically MFB and MVB in the NDK). It communicates with the Streaming Debug components in the FW - Streaming Debug Master and Probe. The Debug Probes are (need to be) inserted into the pipeline between neighboring components. -More info can be found in the documentation for STREAMING_DEBUG_MASTER. +More info can be found in the documentation for `STREAMING_DEBUG_MASTER `_. The Streaming Debug system (Master+Probe) in the FW (must be integrated first) provides counts of: @@ -77,7 +77,7 @@ Both forms of Probe identification ("-i", "-n") are used in the output. This FW design contains two (identical) 100G streams (pipelines), and the Master+Probes have been instantiated per each stream. Notice how the Probe names are the same for both Masters. -Parameters "-B", "-D", and "-E" are used for advanced features for "Bus Control", see documentation of Streaming Debug. +Parameters "-B", "-D", and "-E" are used for advanced features for "Bus Control", see documentation of `Streaming Debug `_. TL;DR: if the Master is set accordingly and the Probes are connected appropriately, use: - `-B XYZA` to block traffic at the selected Probe, @@ -85,7 +85,7 @@ TL;DR: if the Master is set accordingly and the Probes are connected appropriate - `-E XYZA` to return the selected Probe to its flow-through state. .. warning:: - Beware that the "Bus Control" feature is often not needed, which is reflected by the connection of Probes in the FW (see documentation of the Streaming Debug components). Hence, these three parameters may not work. + Beware that the "Bus Control" feature is often not needed, which is reflected by the connection of Probes in the FW (see documentation of the `Streaming Debug components `_). Hence, these three parameters may not work. How to use ~~~~~~~~~~ @@ -105,7 +105,7 @@ This creates a bounded interval, which nullifies idle clock cycles before any da How to read the probed data ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The following diagram is borrowed from the documentation of the Streaming Debug components. +The following diagram is borrowed from the documentation of the `Streaming Debug components `_. It shows a simple pipeline of three FW components (modules): A, B, and C. .. _figure1: From 941acdfddb3f0e7f37e1a60babb4389442ff04d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 19 Feb 2025 15:50:19 +0100 Subject: [PATCH 329/518] feat(build - parallel configure): Make kernel flag checking parallel --- drivers/configure.ac | 165 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 131 insertions(+), 34 deletions(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index eccec15d..d961cc38 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -11,9 +11,60 @@ DEFAULT_PACKAGE_NAME="nfb" AC_PREREQ([2.63]) AC_INIT(m4_esyscmd([ if [ -z $CMAKE_PACKAGE_NAME ]; then echo -n $DEFAULT_PACKAGE_NAME; else echo -n $CMAKE_PACKAGE_NAME; fi;]), m4_esyscmd([ if [ -z $CMAKE_PACKAGE_VERSION ]; then cut -f1 ../VERSION | tr -d '\n'; else echo -n $CMAKE_PACKAGE_VERSION; fi;])) +AC_ARG_ENABLE([parallel-config], AS_HELP_STRING([--disable-parallel-config], [Disable parallel checking of configure flags])) + AC_CONFIG_HEADERS(config.h) AC_DEFUN([KERNEL_TRY_COMPILE],[ +AS_IF([test "x$enable_parallel_config" != "xno"], +[ +test_cnt=$((test_cnt+1)) # increment test counter before running in subshell +{ # run as a background job in the subshell +$( +# prepare the test enviroment +mkdir -p .test${test_cnt} >/dev/null 2>&1 +if ! test -d .test${test_cnt}; then + AC_MSG_FAILURE([Failed to enter .test${test_cnt} directory]) +fi +cd .test${test_cnt} +echo KDIR=$KDIR >Makefile +cat >>Makefile <>Makefile +echo '$1' >test.c +# run the test, save the output to temp file and exit code to $retval +make >./make_out 2>&1 +retval=$? +# log the results +exec 200>../flock_lockfile +flock -x 200 +echo '---------------------------start test parallel--------------------------' >&AS_MESSAGE_LOG_FD +$2 # checking whether ... +echo 'Using this program for test:' >&AS_MESSAGE_LOG_FD +cat test.c >&AS_MESSAGE_LOG_FD +printf '\nUsing this Makefile for test:\n' >&AS_MESSAGE_LOG_FD +cat Makefile >&AS_MESSAGE_LOG_FD +printf '\nMakefile output:\n' >&AS_MESSAGE_LOG_FD +cat ./make_out >&AS_MESSAGE_LOG_FD +cd .. # back to work directory to handle results +if test $retval -eq 0; then + $3 # result yes; define config value +else + $4 # result no +fi +echo '^^^^^^^^^^^^^^^^^^^^^^^^^^^^end test parallel^^^^^^^^^^^^^^^^^^^^^^^^^^^' >&AS_MESSAGE_LOG_FD +flock -u 200 +# cleanup +rm -rf .test${test_cnt}/ >/dev/null 2>/dev/null +) +} & +],[ # ELSE mkdir .test >/dev/null 2>&1 if ! test -d .test; then AC_MSG_FAILURE([Failed to enter .test directory]) @@ -31,6 +82,8 @@ EOF echo -e '\t$(KBUILD) test.s' >>Makefile echo '$1' >test.c +echo '---------------------------start test sequential--------------------------' >&AS_MESSAGE_LOG_FD +$2 # checking whether ... echo 'Using this program for test:' >&AS_MESSAGE_LOG_FD cat test.c >&AS_MESSAGE_LOG_FD cat Makefile >&AS_MESSAGE_LOG_FD @@ -39,12 +92,14 @@ retval=$? cd .. rm -rf .test/ >/dev/null 2>/dev/null if test $retval -eq 0; then - $2 + $3 # result yes; define config value else - $3 + $4 # result no; true fi -]) +echo '^^^^^^^^^^^^^^^^^^^^^^^^^^^^end test sequential^^^^^^^^^^^^^^^^^^^^^^^^^^^' >&AS_MESSAGE_LOG_FD +] # ENDIF +)]) # KERNEL_TRY_COMPILE # Kernel build dir KSRC="" @@ -57,10 +112,15 @@ test -d $KDIR || AC_MSG_FAILURE($KDIR does not exist) AC_MSG_RESULT($KDIR) # Is kernel build dir usable? -AC_MSG_CHECKING([whether kernel build dir is usable]) -KERNEL_TRY_COMPILE([],[AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no]) +KERNEL_TRY_COMPILE([],[AC_MSG_CHECKING([whether kernel build dir is usable])],[AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no]) AC_MSG_FAILURE([Unusable kernel build dir. Install kernel sources.])]) +# wait for this check before running parallel tests for symbols, don't continue with unusable kernel dir +wait $! +if test ! $? -eq 0; then + exit $? +fi + # Kernel source dir AC_MSG_CHECKING([for kernel source dir]) AC_ARG_WITH([source], AS_HELP_STRING([--with-source=DIR],[use this kernel source dir]), @@ -70,86 +130,110 @@ AC_ARG_WITH([source], AS_HELP_STRING([--with-source=DIR],[use this kernel source AC_MSG_RESULT($KSRC) # Tests for symbols -AC_MSG_CHECKING([whether kernel has struct timespec]) +AC_MSG_NOTICE([Starting the check for kernel symbols, see config.log for detailed results.]) KERNEL_TRY_COMPILE([[ #include struct timespec ts; -]],[AC_DEFINE([CONFIG_HAVE_TIMESPEC], [1], [Define if kernel have struct timespec]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +]], +[AC_MSG_CHECKING([whether kernel has struct timespec])], +[AC_DEFINE([CONFIG_HAVE_TIMESPEC], [1], [Define if kernel have struct timespec]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has netif_rx_ni]) KERNEL_TRY_COMPILE([[ #include void test(void); void test(void) {netif_rx_ni(NULL);} -]],[AC_DEFINE([CONFIG_HAVE_NETIF_RX_NI], [1], [Define if kernel have netif_rx_ni]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +]], +[AC_MSG_CHECKING([whether kernel has netif_rx_ni])], +[AC_DEFINE([CONFIG_HAVE_NETIF_RX_NI], [1], [Define if kernel have netif_rx_ni]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has eth_hw_addr_set]) KERNEL_TRY_COMPILE([[ #include void test(void); void test(void) {eth_hw_addr_set(NULL, NULL);} -]],[AC_DEFINE([CONFIG_HAVE_ETH_HW_ADDR_SET], [1], [Define if kernel have eth_hw_addr_set]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +]], +[AC_MSG_CHECKING([whether kernel has eth_hw_addr_set])], +[AC_DEFINE([CONFIG_HAVE_ETH_HW_ADDR_SET], [1], [Define if kernel have eth_hw_addr_set]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has regmap_reg_range and read_poll_timeout]) KERNEL_TRY_COMPILE([[ #include #include void test(void); static const struct regmap_range regmap_range_test[] = {regmap_reg_range(0,0)}; static int trd(off_t a) {return 0;} void test(void) {int ret; read_poll_timeout(trd, ret, (!ret), 1, 2, false, 0);} -]],[AC_DEFINE([CONFIG_NFB_ENABLE_PMCI], [1], [Define if kernel have regmap_reg_range and read_poll_timeout]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +]], +[AC_MSG_CHECKING([whether kernel has regmap_reg_range and read_poll_timeout])], +[AC_DEFINE([CONFIG_NFB_ENABLE_PMCI], [1], [Define if kernel have regmap_reg_range and read_poll_timeout]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has devm_kstrdup_const]) KERNEL_TRY_COMPILE([[ #include void test(void); struct device dev; void test(void) {devm_kstrdup_const(&dev, "test", GFP_KERNEL);} -]],[AC_DEFINE([CONFIG_NFB_ENABLE_HWMON], [1], [Define if kernel has devm_kstrdup_const()]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +]], +[AC_MSG_CHECKING([whether kernel has devm_kstrdup_const])], +[AC_DEFINE([CONFIG_NFB_ENABLE_HWMON], [1], [Define if kernel has devm_kstrdup_const()]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has vm_flags_set]) KERNEL_TRY_COMPILE([[ #include void test(void); void test(void) {vm_flags_set(NULL, 0);} -]],[AC_DEFINE([CONFIG_HAVE_VM_FLAGS_SET], [1], [Define if kernel has vm_flags_set()]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +]], +[AC_MSG_CHECKING([whether kernel has vm_flags_set])], +[AC_DEFINE([CONFIG_HAVE_VM_FLAGS_SET], [1], [Define if kernel has vm_flags_set()]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether struct ptp_clock_info has adjfreq]) KERNEL_TRY_COMPILE([[ #include void test(void); void test(void) {struct ptp_clock_info ci; ci.ajdfreq = NULL;} -]],[AC_DEFINE([CONFIG_HAVE_PTP_CLOCK_INFO_ADJFREQ], [1], [Define if struct ptp_clock_info has adjfreq]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +]], +[AC_MSG_CHECKING([whether struct ptp_clock_info has adjfreq])], +[AC_DEFINE([CONFIG_HAVE_PTP_CLOCK_INFO_ADJFREQ], [1], [Define if struct ptp_clock_info has adjfreq]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether class_create has only one parameter]) KERNEL_TRY_COMPILE([[ #include void test(void); void test(void) {struct class *c = class_create(""); if (c) {} } -]],[AC_DEFINE([CONFIG_CLASS_CREATE_HAVE_ONE_PARAMETER], [1], [Define if class_create has only one parameter]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +]], +[AC_MSG_CHECKING([whether class_create has only one parameter])], +[AC_DEFINE([CONFIG_CLASS_CREATE_HAVE_ONE_PARAMETER], [1], [Define if class_create has only one parameter]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has read_poll_timeout_atomic]) KERNEL_TRY_COMPILE([[ #include void test(void); static int trd(off_t a) {return 0;} void test(void) {int ret; read_poll_timeout_atomic(trd, ret, (!ret), 1, 2, false, 0);} -]],[AC_DEFINE([CONFIG_HAVE_READ_POLL_TIMEOUT_ATOMIC], [1], [Define if kernel has read_poll_timeout_atomic]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +]], +[AC_MSG_CHECKING([whether kernel has read_poll_timeout_atomic])], +[AC_DEFINE([CONFIG_HAVE_READ_POLL_TIMEOUT_ATOMIC], [1], [Define if kernel has read_poll_timeout_atomic]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has struct spi_controller]) KERNEL_TRY_COMPILE([[ #include struct spi_controller *sc; void test(void); -void test(void) {spi_get_chipselect(NULL, 0);}]],[AC_DEFINE([CONFIG_HAVE_SPI_CONTROLLER], [1], [Define if kernel has struct spi_controller]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +void test(void) {spi_get_chipselect(NULL, 0);} +]], +[AC_MSG_CHECKING([whether kernel has struct spi_controller])], +[AC_DEFINE([CONFIG_HAVE_SPI_CONTROLLER], [1], [Define if kernel has struct spi_controller]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has ctrl in struct spi_bitbang]) KERNEL_TRY_COMPILE([[ #include struct spi_bitbang sb; void test(void); -void test(void) {sb.ctrl = NULL;}]],[AC_DEFINE([CONFIG_HAVE_SPI_BITBANG_CTRL], [1], [Define if kernel has ctrl in struct spi_bitbang]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +void test(void) {sb.ctrl = NULL;} +]], +[AC_MSG_CHECKING([whether kernel has ctrl in struct spi_bitbang])], +[AC_DEFINE([CONFIG_HAVE_SPI_BITBANG_CTRL], [1], [Define if kernel has ctrl in struct spi_bitbang]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has altera_spi_init_master]) KERNEL_TRY_COMPILE([[ #include struct spi_controller sc; @@ -157,9 +241,12 @@ void test(void); #if !IS_ENABLED(CONFIG_SPI_ALTERA) #error CONFIG_SPI_ALTERA is not enabled, failing altera_spi_init_master test explicitly #endif -void test(void) {altera_spi_init_master(&sc);}]],[AC_DEFINE([CONFIG_HAVE_SPI_INIT_MASTER], [1], [Define if kernel has altera_spi_init_master]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +void test(void) {altera_spi_init_master(&sc);} +]], +[AC_MSG_CHECKING([whether kernel has altera_spi_init_master])], +[AC_DEFINE([CONFIG_HAVE_SPI_INIT_MASTER], [1], [Define if kernel has altera_spi_init_master]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has altera_spi_init_host]) KERNEL_TRY_COMPILE([[ #include struct spi_controller sc; @@ -167,15 +254,25 @@ void test(void); #if !IS_ENABLED(CONFIG_SPI_ALTERA) #error CONFIG_SPI_ALTERA is not enabled, failing altera_spi_init_host test explicitly #endif -void test(void) {altera_spi_init_host(&sc);}]],[AC_DEFINE([CONFIG_HAVE_SPI_INIT_HOST], [1], [Define if kernel has altera_spi_init_host]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +void test(void) {altera_spi_init_host(&sc);} +]], +[AC_MSG_CHECKING([whether kernel has altera_spi_init_host])], +[AC_DEFINE([CONFIG_HAVE_SPI_INIT_HOST], [1], [Define if kernel has altera_spi_init_host]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) -AC_MSG_CHECKING([whether kernel has simplified eventfd_signal]) KERNEL_TRY_COMPILE([[ #include void test(void); -void test(void) {eventfd_signal(NULL);}]],[AC_DEFINE([CONFIG_HAVE_SIMPLIFIED_EVENTFD_SIGNAL], [1], [Define if kernel has simplified eventfd_signal]) AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) +void test(void) {eventfd_signal(NULL);} +]], +[AC_MSG_CHECKING([whether kernel has simplified eventfd_signal])], +[AC_DEFINE([CONFIG_HAVE_SIMPLIFIED_EVENTFD_SIGNAL], [1], [Define if kernel has simplified eventfd_signal]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +# wait for the jobs to finnish, remove file used for locking if it exists +wait +rm -rf flock_lockfile >/dev/null 2>/dev/null AC_SUBST(KDIR) AC_SUBST(KSRC) - AC_OUTPUT From 7ce017b34b919ab7369cc38405af0062727281b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Thu, 17 Apr 2025 13:38:53 +0200 Subject: [PATCH 330/518] fix(build - configure): delete useless Cmake configure step --- drivers/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index f194d4c1..49b4c420 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -66,10 +66,6 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/Makefile.in ${CMAKE_CURRENT_LIST_DIR}/M configure_file(${CMAKE_CURRENT_LIST_DIR}/Makefile.in ${CMAKE_CURRENT_BINARY_DIR}/configured/Makefile @ONLY) configure_file(${CMAKE_CURRENT_LIST_DIR}/dkms.conf.in ${CMAKE_CURRENT_BINARY_DIR}/configured/dkms.conf @ONLY) - -message(STATUS "Configuring ${CMAKE_CURRENT_LIST_DIR}") -execute_process(COMMAND "${CMAKE_CURRENT_LIST_DIR}/configure") - install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/kernel/include/linux DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} From e54f190c80c75733e4d205d18719e5169ec8b84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Thu, 17 Apr 2025 14:31:16 +0200 Subject: [PATCH 331/518] feat(build - parallel make): Add make -j to build.sh script --- build.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index b5e51e27..a88e49e6 100755 --- a/build.sh +++ b/build.sh @@ -249,7 +249,7 @@ Build() mkdir -p "$SCRIPT_PATH/$BUILDDIR" cd "$SCRIPT_PATH/$BUILDDIR" $cmake -DCMAKE_BUILD_TYPE=$RELTYPE .. - make + $make_command } Build_dpdk() @@ -258,13 +258,14 @@ Build_dpdk() mkdir -p "$SCRIPT_PATH/$BUILDDIR" cd "$SCRIPT_PATH/$BUILDDIR" $cmake -DCMAKE_BUILD_TYPE=$RELTYPE -DUSE_DPDK=true .. - make + $make_command } # ----[ MAIN function ]------------------------------------------------------- # cmake=cmake cpack=cpack +make_command="make -j" os=$(get_os_id) if item_in_list "$os" "centos scientific fedora"; then From 88b6e9adf6279e8c53d310a89b92b7fdb6736f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 30 Apr 2025 08:47:01 +0200 Subject: [PATCH 332/518] feat(README - parallel config): Add information about --disable-parallel-config parameter to the README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 91c5dc73..ade3a57b 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,9 @@ For other operating systems, the installation procedure may be slightly differen `sudo insmod drivers/kernel/drivers/nfb/nfb.ko` +> Default behavior of the configure script is to run its compatibility checks in parallel.\ +This can be turned off by passing --disable-parallel-config parameter\ +`cd drivers; ./configure --disable-parallel-config; make; cd ..` ## License From 7840e3843065707e59c9b2a5f047e21560b30197 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 30 Apr 2025 19:11:36 +0200 Subject: [PATCH 333/518] fix(ndp-RX): remove double sync on queue start The packets received by the driver between these two synces were ignored in libnfb and even not freed. This could have caused performance issues (buffer was effectively smaller) or even blockage of packet receive. --- libnfb/include/netcope/ndp.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index c9985d0d..cf32dae9 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -372,9 +372,6 @@ static int nc_ndp_queue_start(void *priv) return ret; if (q->channel.type == NDP_CHANNEL_TYPE_RX && q->protocol == 2 && (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) == 0) { - if ((ret = _ndp_queue_sync(q, &q->sync))) - return ret; - q->u.v2.rhp = q->sync.hwptr; } From 1ad64a43b16959a8deb30d4eb01d0e7d023570c1 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 May 2025 10:06:29 +0200 Subject: [PATCH 334/518] bump version to 6.26.4 --- Changelog | 5 +++++ VERSION | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index c0af24ab..34a31545 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +* Mon May 5 2025 Martin Spinler - 6.26.4-1 +- [FIX] libnfb/NDP: remove double sync on queue start causing performance loss / blockage +- [FIX] nfb-eth: wait for QSFP ready when reading monitoring data +- [FIX] nfb-tsu: use correct lock function + * Thu Mar 13 2025 Martin Spinler - 6.26.3-1 - [FIX] libnfb: count queues in no-driver mode - add SZE queues - [FIX] libnfb-ext-grpc: use experimental prefix on grpc++ < 1.41 diff --git a/VERSION b/VERSION index 7eeb87d9..30bfaeb1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.26.3 +6.26.4 From 87df4f5c35822abbbda71e9a4d2b23190a5a10a9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 3 Mar 2025 12:54:24 +0100 Subject: [PATCH 335/518] chore(ndp-tool): deduplicate open/close code --- tools/ndptool/common.c | 72 +++++++++++++++++++++++++++++++++++++ tools/ndptool/common.h | 4 +++ tools/ndptool/generate.c | 33 ++--------------- tools/ndptool/loopback.c | 50 ++------------------------ tools/ndptool/loopback_hw.c | 50 +++----------------------- tools/ndptool/read.c | 34 ++---------------- tools/ndptool/receive.c | 35 ++++-------------- tools/ndptool/transmit.c | 34 ++++-------------- 8 files changed, 103 insertions(+), 209 deletions(-) diff --git a/tools/ndptool/common.c b/tools/ndptool/common.c index 8a6e67da..59760466 100644 --- a/tools/ndptool/common.c +++ b/tools/ndptool/common.c @@ -93,3 +93,75 @@ void adjust_tx_throughput(unsigned status_num_of_loops, unsigned long long throu } } } + +int ndp_mode_common_prepare(struct ndp_tool_params *p, int rx, int tx) +{ + int ret = -ENODEV; + + /* Open device and queues */ + p->dev = nfb_open(p->nfb_path); + if (p->dev == NULL) { + warnx("nfb_open() for queue %d failed.", p->queue_index); + return ret; + } + + if (rx) { + p->rx = ndp_open_rx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); + if (p->rx == NULL) { + warnx("ndp_open_rx_queue(%d) failed.", p->queue_index); + goto err_ndp_open_rx; + } + } + + if (tx) { + p->tx = ndp_open_tx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); + if (p->tx == NULL) { + warnx("ndp_open_tx_queue(%d) failed.", p->queue_index); + goto err_ndp_open_tx; + } + } + + /* Start queues */ + if (tx) { + ret = ndp_queue_start(p->tx); + if (ret != 0) { + warnx("ndp_tx_queue_start(%d) failed.", p->queue_index); + goto err_ndp_start_tx; + } + } + if (rx) { + ret = ndp_queue_start(p->rx); + if (ret != 0) { + warnx("ndp_rx_queue_start(%d) failed.", p->queue_index); + goto err_ndp_start_rx; + } + } + return 0; + +err_ndp_start_rx: + if (tx) + ndp_queue_stop(p->tx); +err_ndp_start_tx: + if (tx) + ndp_close_tx_queue(p->tx); +err_ndp_open_tx: + if (rx) + ndp_close_rx_queue(p->rx); +err_ndp_open_rx: + nfb_close(p->dev); + return ret; +} + +void ndp_mode_common_close(struct ndp_tool_params *p, int rx, int tx) +{ + if (rx) + ndp_queue_stop(p->rx); + if (tx) + ndp_queue_stop(p->tx); + if (rx) + ndp_close_tx_queue(p->rx); + if (tx) + ndp_close_tx_queue(p->tx); + + nfb_close(p->dev); +} diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index d34bc271..3701df13 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -215,6 +216,9 @@ void update_stats_loop_thread(int interval, struct thread_data **pdata, int thre void gather_stats_info(struct stats_info *si, struct stats_info *thread); void print_stats(struct stats_info *si); +int ndp_mode_common_prepare(struct ndp_tool_params *p, int rx, int tx); +void ndp_mode_common_close(struct ndp_tool_params *p, int rx, int tx); + enum ndp_modules { NDP_MODULE_READ, NDP_MODULE_GENERATE, diff --git a/tools/ndptool/generate.c b/tools/ndptool/generate.c index 0f44ddb3..570d17f2 100644 --- a/tools/ndptool/generate.c +++ b/tools/ndptool/generate.c @@ -62,48 +62,21 @@ void *ndp_mode_generate_thread(void *tmp) static int ndp_mode_generate_prepare(struct ndp_tool_params *p) { - int ret = -1; + int ret; p->si.progress_letter = 'G'; /* Open device and queues */ - p->dev = nfb_open(p->nfb_path); - if (p->dev == NULL){ - warnx("nfb_open() for queue %d failed.", p->queue_index); - goto err_nfb_open; - } - - p->tx = ndp_open_tx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); - if (p->tx == NULL) { - warnx("ndp_open_tx_queue(%d) failed.", p->queue_index); - goto err_ndp_open_tx; - } - - /* Start queues */ - ret = ndp_queue_start(p->tx); - if (ret != 0) { - warnx("ndp_tx_queue_start(%d) failed.", p->queue_index); - goto err_ndp_start_tx; - } + ret = ndp_mode_common_prepare(p, 0, 1); gettimeofday(&p->si.startTime, NULL); - return 0; - - /* Error handling */ -err_ndp_start_tx: - ndp_close_tx_queue(p->tx); -err_ndp_open_tx: - nfb_close(p->dev); -err_nfb_open: return ret; } static int ndp_mode_generate_exit(struct ndp_tool_params *p) { gettimeofday(&p->si.endTime, NULL); - ndp_queue_stop(p->tx); - ndp_close_tx_queue(p->tx); - nfb_close(p->dev); + ndp_mode_common_close(p, 0, 1); return 0; } diff --git a/tools/ndptool/loopback.c b/tools/ndptool/loopback.c index b6e710eb..9f1a154b 100644 --- a/tools/ndptool/loopback.c +++ b/tools/ndptool/loopback.c @@ -62,65 +62,21 @@ void *ndp_mode_loopback_thread(void *tmp) static int ndp_mode_loopback_prepare(struct ndp_tool_params *p) { - int ret = -1; + int ret; p->si.progress_letter = 'L'; /* Open device and queues */ - p->dev = nfb_open(p->nfb_path); - if (p->dev == NULL){ - warnx("nfb_open() for queue %d failed.", p->queue_index); - goto err_nfb_open; - } - - p->rx = ndp_open_rx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); - if (p->rx == NULL) { - warnx("ndp_open_rx_queue(%d) failed.", p->queue_index); - goto err_ndp_open_rx; - } - - p->tx = ndp_open_tx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); - if (p->tx == NULL) { - warnx("ndp_open_tx_queue(%d) failed.", p->queue_index); - goto err_ndp_open_tx; - } - - /* Start queues */ - ret = ndp_queue_start(p->tx); - if (ret != 0) { - warnx("ndp_tx_queue_start(%d) failed.", p->queue_index); - goto err_ndp_start_tx; - } - ret = ndp_queue_start(p->rx); - if (ret != 0) { - warnx("ndp_rx_queue_start(%d) failed.", p->queue_index); - goto err_ndp_start_rx; - } + ret = ndp_mode_common_prepare(p, 1, 1); gettimeofday(&p->si.startTime, NULL); - return 0; - - /* Error handling */ -err_ndp_start_rx: - ndp_queue_stop(p->tx); -err_ndp_start_tx: - ndp_close_tx_queue(p->tx); -err_ndp_open_tx: - ndp_close_rx_queue(p->rx); -err_ndp_open_rx: - nfb_close(p->dev); -err_nfb_open: return ret; } static int ndp_mode_loopback_exit(struct ndp_tool_params *p) { gettimeofday(&p->si.endTime, NULL); - ndp_queue_stop(p->rx); - ndp_queue_stop(p->tx); - ndp_close_rx_queue(p->rx); - ndp_close_tx_queue(p->tx); - nfb_close(p->dev); + ndp_mode_common_close(p, 1, 1); return 0; } diff --git a/tools/ndptool/loopback_hw.c b/tools/ndptool/loopback_hw.c index fdceafe9..648f5d33 100644 --- a/tools/ndptool/loopback_hw.c +++ b/tools/ndptool/loopback_hw.c @@ -101,7 +101,7 @@ static int pregenerate(struct ndp_mode_loopback_hw_params *p) static int ndp_mode_loopback_hw_prepare(struct ndp_tool_params *p) { - int ret = -1; + int ret; struct timeval seed_time; /* Pregenerate packet sizes and IDs */ @@ -112,53 +112,15 @@ static int ndp_mode_loopback_hw_prepare(struct ndp_tool_params *p) warnx("pregenerate() for queue %d failed.", p->queue_index); goto err_pregen; } - ret = -1; p->si.progress_letter = 'L'; - /* Open device and queues */ - p->dev = nfb_open(p->nfb_path); - if (p->dev == NULL) { - warnx("nfb_open() for queue %d failed.", p->queue_index); - goto err_nfb_open; - } - - p->rx = ndp_open_rx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); - if (p->rx == NULL) { - warnx("ndp_open_rx_queue(%d) failed.", p->queue_index); - goto err_ndp_open_rx; - } - - p->tx = ndp_open_tx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); - if (p->tx == NULL) { - warnx("ndp_open_tx_queue(%d) failed.", p->queue_index); - goto err_ndp_open_tx; - } - /* Start queues */ - ret = ndp_queue_start(p->tx); - if (ret != 0) { - warnx("ndp_tx_queue_start(%d) failed.", p->queue_index); - goto err_ndp_start_tx; - } - ret = ndp_queue_start(p->rx); - if (ret != 0) { - warnx("ndp_rx_queue_start(%d) failed.", p->queue_index); - goto err_ndp_start_rx; - } + ret = ndp_mode_common_prepare(p, 1, 1); gettimeofday(&p->si.startTime, NULL); - return 0; + return ret; /* Error handling */ -err_ndp_start_rx: - ndp_queue_stop(p->tx); -err_ndp_start_tx: - ndp_close_tx_queue(p->tx); -err_ndp_open_tx: - ndp_close_rx_queue(p->rx); -err_ndp_open_rx: - nfb_close(p->dev); -err_nfb_open: err_pregen: return ret; } @@ -166,11 +128,7 @@ static int ndp_mode_loopback_hw_prepare(struct ndp_tool_params *p) static int ndp_mode_loopback_hw_exit(struct ndp_tool_params *p) { gettimeofday(&p->si.endTime, NULL); - ndp_queue_stop(p->rx); - ndp_queue_stop(p->tx); - ndp_close_tx_queue(p->rx); - ndp_close_tx_queue(p->tx); - //nfb_close(p->dev); + ndp_mode_common_close(p, 1, 1); return 0; } diff --git a/tools/ndptool/read.c b/tools/ndptool/read.c index e5f5fb6c..84980ca5 100644 --- a/tools/ndptool/read.c +++ b/tools/ndptool/read.c @@ -64,49 +64,21 @@ void *ndp_mode_read_thread(void *tmp) static int ndp_mode_read_prepare(struct ndp_tool_params *p) { - int ret = -1; + int ret; p->si.progress_letter = 'R'; - /* Open device and queues */ - p->dev = nfb_open(p->nfb_path); - if (p->dev == NULL){ - warnx("nfb_open() for queue %d failed.", p->queue_index); - goto err_nfb_open; - } - - p->rx = ndp_open_rx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); - if (p->rx == NULL) { - warnx("ndp_open_rx_queue(%d) failed.", p->queue_index); - goto err_ndp_open_rx; - } - - /* Start queues */ - ret = ndp_queue_start(p->rx); - if (ret != 0) { - warnx("ndp_rx_queue_start(%d) failed.", p->queue_index); - goto err_ndp_start_rx; - } + ret = ndp_mode_common_prepare(p, 1, 0); gettimeofday(&p->si.startTime, NULL); - return 0; - - /* Error handling */ -err_ndp_start_rx: - ndp_close_rx_queue(p->rx); -err_ndp_open_rx: - nfb_close(p->dev); -err_nfb_open: return ret; } static int ndp_mode_read_exit(struct ndp_tool_params *p) { gettimeofday(&p->si.endTime, NULL); - ndp_queue_stop(p->rx); - ndp_close_rx_queue(p->rx); - nfb_close(p->dev); + ndp_mode_common_close(p, 1, 0); return 0; } diff --git a/tools/ndptool/receive.c b/tools/ndptool/receive.c index 0fc6ee62..e2670350 100644 --- a/tools/ndptool/receive.c +++ b/tools/ndptool/receive.c @@ -74,28 +74,13 @@ void *ndp_mode_receive_thread(void *tmp) static int ndp_mode_receive_prepare(struct ndp_tool_params *p) { - int ret = -1; + int ret; p->si.progress_letter = 'R'; - /* Open device and queues */ - p->dev = nfb_open(p->nfb_path); - if (p->dev == NULL){ - warnx("nfb_open() for queue %d failed.", p->queue_index); - goto err_nfb_open; - } - - p->rx = ndp_open_rx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); - if (p->rx == NULL) { - warnx("ndp_open_rx_queue(%d) failed.", p->queue_index); - goto err_ndp_open_rx; - } - - /* Start queues */ - ret = ndp_queue_start(p->rx); - if (ret != 0) { - warnx("ndp_rx_queue_start(%d) failed.", p->queue_index); - goto err_ndp_start_rx; + ret = ndp_mode_common_prepare(p, 1, 0); + if (ret) { + goto err_common_prepare; } p->pcap_file = pcap_write_begin(p->pcap_filename); @@ -113,21 +98,15 @@ static int ndp_mode_receive_prepare(struct ndp_tool_params *p) fclose(p->pcap_file); p->pcap_file = NULL; err_init_pcap_file: - ndp_queue_stop(p->rx); -err_ndp_start_rx: - ndp_close_rx_queue(p->rx); -err_ndp_open_rx: - nfb_close(p->dev); -err_nfb_open: + ndp_mode_common_close(p, 1, 0); +err_common_prepare: return ret; } static int ndp_mode_receive_exit(struct ndp_tool_params *p) { gettimeofday(&p->si.endTime, NULL); - ndp_queue_stop(p->rx); - ndp_close_rx_queue(p->rx); - nfb_close(p->dev); + ndp_mode_common_close(p, 1, 0); fclose(p->pcap_file); return 0; } diff --git a/tools/ndptool/transmit.c b/tools/ndptool/transmit.c index 2425ce44..710a521a 100644 --- a/tools/ndptool/transmit.c +++ b/tools/ndptool/transmit.c @@ -112,24 +112,9 @@ static int ndp_mode_transmit_prepare(struct ndp_tool_params *p, struct pcap_src int ret = -1; p->si.progress_letter = 'T'; - /* Open device and queues */ - p->dev = nfb_open(p->nfb_path); - if (p->dev == NULL){ - warnx("nfb_open() for queue %d failed.", p->queue_index); - goto err_nfb_open; - } - - p->tx = ndp_open_tx_queue_ext(p->dev, p->queue_index, p->use_userspace_flag ? NDP_OPEN_FLAG_USERSPACE : 0); - if (p->tx == NULL) { - warnx("ndp_open_tx_queue(%d) failed.", p->queue_index); - goto err_ndp_open_tx; - } - - /* Start queues */ - ret = ndp_queue_start(p->tx); - if (ret != 0) { - warnx("ndp_tx_queue_start(%d) failed.", p->queue_index); - goto err_ndp_start_tx; + ret = ndp_mode_common_prepare(p, 0, 1); + if (ret) { + goto err_common_prepare; } ret = pcap_src_open(p, src); @@ -146,12 +131,8 @@ static int ndp_mode_transmit_prepare(struct ndp_tool_params *p, struct pcap_src /* Error handling */ pcap_src_close(src); err_pcap_src_open: - ndp_queue_stop(p->tx); -err_ndp_start_tx: - ndp_close_tx_queue(p->tx); -err_ndp_open_tx: - nfb_close(p->dev); -err_nfb_open: + ndp_mode_common_close(p, 0, 1); +err_common_prepare: return ret; } @@ -159,9 +140,8 @@ static int ndp_mode_transmit_exit(struct ndp_tool_params *p, struct pcap_src *sr { gettimeofday(&p->si.endTime, NULL); pcap_src_close(src); - ndp_queue_stop(p->tx); - ndp_close_tx_queue(p->tx); - nfb_close(p->dev); + + ndp_mode_common_close(p, 0, 1); return 0; } From d0f6c4f3990dfe47c09d3fa34e80a9bb5d6885a3 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 26 Feb 2025 15:09:21 +0100 Subject: [PATCH 336/518] chore(NDP / DMA Calypte): move assigments up/down to minimize ifdefs --- libnfb/include/netcope/ndp.h | 81 ++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index cf32dae9..7d803ae7 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -109,17 +109,6 @@ static inline int nc_ndp_v2_open_queue(struct nc_ndp_queue *q, const void *fdt, prot = PROT_READ; prot |= q->channel.type == NDP_CHANNEL_TYPE_TX ? PROT_WRITE : 0; -#endif - if (q->channel.type == NDP_CHANNEL_TYPE_RX) { - ops->burst.rx.get = nc_ndp_v2_rx_burst_get; - ops->burst.rx.put = nc_ndp_v2_rx_burst_put; - } else { - ops->burst.tx.get = nc_ndp_v2_tx_burst_get; - ops->burst.tx.put = nc_ndp_v2_tx_burst_put; - ops->burst.tx.flush = nc_ndp_v2_tx_burst_flush; - } - -#ifndef __KERNEL__ q->u.v2.hdr = mmap(NULL, hdr_mmap_size, prot, MAP_FILE | MAP_SHARED, q->fd, hdr_mmap_offset); if (q->u.v2.hdr == MAP_FAILED) { goto err_mmap_hdr; @@ -132,6 +121,16 @@ static inline int nc_ndp_v2_open_queue(struct nc_ndp_queue *q, const void *fdt, q->u.v2.hdr_items = hdr_mmap_size / 2 / sizeof(struct ndp_v2_packethdr); #endif + + if (q->channel.type == NDP_CHANNEL_TYPE_RX) { + ops->burst.rx.get = nc_ndp_v2_rx_burst_get; + ops->burst.rx.put = nc_ndp_v2_rx_burst_put; + } else { + ops->burst.tx.get = nc_ndp_v2_tx_burst_get; + ops->burst.tx.put = nc_ndp_v2_tx_burst_put; + ops->burst.tx.flush = nc_ndp_v2_tx_burst_flush; + } + return 0; #ifndef __KERNEL__ @@ -145,7 +144,6 @@ static inline int nc_ndp_v2_open_queue(struct nc_ndp_queue *q, const void *fdt, static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, int fdt_offset, int ctrl_offset, int dir) { - (void)dir; #ifndef __KERNEL__ int prot; int ret = 0; @@ -155,8 +153,10 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, size_t hdr_buff_size = 0; size_t data_buff_size = 0; - struct ndp_queue_ops *ops = ndp_queue_get_ops(q->q); #endif + struct ndp_queue_ops *ops = ndp_queue_get_ops(q->q); + + (void)dir; q->u.v3.pkts_available = 0; q->u.v3.sdp = 0; @@ -170,26 +170,37 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, q->u.v3.uspace_free = 0; q->u.v3.uspace_acc = 0; + ret = 0; + ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_size", &hdr_mmap_size); + ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_base", &hdr_mmap_offset); + if (q->channel.type == NDP_CHANNEL_TYPE_TX) { + ret |= fdt_getprop32(fdt, fdt_offset, "data_buff_size", &data_buff_size); + ret |= fdt_getprop32(fdt, fdt_offset, "hdr_buff_size", &hdr_buff_size); + } + if (ret) + return -EBADFD; + + prot = PROT_READ | PROT_WRITE; + + q->u.v3.hdrs = mmap(NULL, hdr_mmap_size, prot, MAP_FILE | MAP_SHARED, q->fd, hdr_mmap_offset); + if (q->u.v3.hdrs == MAP_FAILED) { + return -EBADFD; + } + if (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) { + q->u.v3.uspace_hdrs = q->u.v3.hdrs; + q->u.v3.comp = nfb_comp_open(q->dev, ctrl_offset); if (q->u.v3.comp == NULL) return -ENODEV; } +#endif if (q->channel.type == NDP_CHANNEL_TYPE_RX) { - ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_size", &hdr_mmap_size); - ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_base", &hdr_mmap_offset); - - if (ret) - return -EBADFD; + q->u.v3.hdr_ptr_mask = ((hdr_mmap_size / 2) / sizeof(struct ndp_v3_packethdr)) - 1; // "- 1" to create a mask for AND operations } else { - ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_size", &hdr_mmap_size); - ret |= fdt_getprop64(fdt, fdt_offset, "hdr_mmap_base", &hdr_mmap_offset); - ret |= fdt_getprop32(fdt, fdt_offset, "data_buff_size", &data_buff_size); - ret |= fdt_getprop32(fdt, fdt_offset, "hdr_buff_size", &hdr_buff_size); - - if (ret) - return -EBADFD; + q->u.v3.hdr_ptr_mask = hdr_buff_size / (2 * sizeof(struct ndp_v3_packethdr)) - 1; + q->u.v3.data_ptr_mask = data_buff_size / 2 - 1; } if (q->channel.type == NDP_CHANNEL_TYPE_RX) { @@ -201,26 +212,6 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, ops->burst.tx.flush = nc_ndp_v3_tx_burst_flush; } - prot = PROT_READ | PROT_WRITE; - - q->u.v3.hdrs = mmap(NULL, hdr_mmap_size, prot, MAP_FILE | MAP_SHARED, q->fd, hdr_mmap_offset); - if (q->u.v3.hdrs == MAP_FAILED) { - return -EBADFD; - } - - if (q->channel.type == NDP_CHANNEL_TYPE_RX) { - q->u.v3.hdr_ptr_mask = ((hdr_mmap_size / 2) / sizeof(struct ndp_v3_packethdr)) - 1; // "- 1" to create a mask for AND operations - } else { - q->u.v3.data_ptr_mask = data_buff_size/2 -1; - q->u.v3.hdr_ptr_mask = hdr_buff_size/(2*sizeof(struct ndp_v3_packethdr)) -1; - } -#endif - -#ifndef __KERNEL__ - if (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) { - q->u.v3.uspace_hdrs = q->u.v3.hdrs; - } -#endif return 0; } From a0b4f539cdc1e62f5628a2fbc15a7806e5b29000 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 26 Feb 2025 15:11:22 +0100 Subject: [PATCH 337/518] feat(NDP / DMA Calypte): propagate metadata in kernel through ndp_ctrl_v3_get_vmaps --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 18 ++++++++++++++---- drivers/kernel/drivers/nfb/ndp/ndp.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 33b022e4..69b8f589 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -120,6 +120,7 @@ struct ndp_ctrl { unsigned long desc_buffer_size; unsigned long off_buffer_size; unsigned long hdr_buffer_size; + unsigned long data_buffer_size; size_t hdr_mmap_offset; size_t off_mmap_offset; @@ -340,6 +341,16 @@ int ndp_ctrl_v2_get_vmaps(struct ndp_channel *channel, void **hdr, void **off) return ctrl->hdr_count; } +int ndp_ctrl_v3_get_vmaps(struct ndp_channel *channel, void **hdr, size_t * hdr_mmap_size, size_t * data_buf_size, size_t * hdr_buf_size) +{ + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + *hdr = ctrl->ts.common.hdr_buffer_v; + *hdr_mmap_size = ctrl->hdr_buffer_size * 2; + *hdr_buf_size = ctrl->hdr_buffer_size; + *data_buf_size = ctrl->data_buffer_size; + return ctrl->hdr_count; +} + static void ndp_ctrl_mps_fill_rx_descs(struct ndp_ctrl *ctrl, uint64_t count) { int i; @@ -1146,7 +1157,6 @@ static int ndp_ctrl_tx_calypte_attach_ring(struct ndp_channel *channel) void *fdt = channel->ndp->nfb->fdt; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); int ctrl_node_offset = -1; - unsigned long data_buffer_size = -1; int buffer_offset = -1; int proplen; const fdt32_t *prop = NULL; @@ -1170,7 +1180,7 @@ static int ndp_ctrl_tx_calypte_attach_ring(struct ndp_channel *channel) if (prop == NULL) return -EBADFD; - data_buffer_size = fdt32_to_cpu(prop[1]); + ctrl->data_buffer_size = fdt32_to_cpu(prop[1]); // Find mask for the header buffer buffer_offset = fdt_node_offset_by_phandle_ref(fdt, ctrl_node_offset, "hdr_buff"); @@ -1200,12 +1210,12 @@ static int ndp_ctrl_tx_calypte_attach_ring(struct ndp_channel *channel) } // Store read values of buffer sizes to structure variables - ctrl->c.mdp = (data_buffer_size/2 -1) & 0x0000FFFFul; + ctrl->c.mdp = (ctrl->data_buffer_size/2 -1) & 0x0000FFFFul; ctrl->c.mhp = (ctrl->hdr_buffer_size/(2*NDP_CTRL_RX_CALYPTE_HDR_SIZE) -1) & 0x0000FFFFul; channel->ptrmask = ctrl->c.mhp; fdt_setprop_u32(fdt, node_offset, "protocol", 3); - fdt_setprop_u32(fdt, node_offset, "data_buff_size", data_buffer_size); + fdt_setprop_u32(fdt, node_offset, "data_buff_size", ctrl->data_buffer_size); fdt_setprop_u32(fdt, node_offset, "hdr_buff_size", ctrl->hdr_buffer_size); fdt_setprop_u64(fdt, node_offset, "hdr_mmap_base", ctrl->hdr_mmap_offset); diff --git a/drivers/kernel/drivers/nfb/ndp/ndp.h b/drivers/kernel/drivers/nfb/ndp/ndp.h index ebe2e9f6..3c6d62d9 100644 --- a/drivers/kernel/drivers/nfb/ndp/ndp.h +++ b/drivers/kernel/drivers/nfb/ndp/ndp.h @@ -319,6 +319,7 @@ struct ndp_channel *ndp_ctrl_v3_create_rx(struct ndp *ndp, int index, int node_o struct ndp_channel *ndp_ctrl_v3_create_tx(struct ndp *ndp, int index, int node_offset); int ndp_ctrl_v2_get_vmaps(struct ndp_channel *channel, void **hdr, void **off); +int ndp_ctrl_v3_get_vmaps(struct ndp_channel *channel, void **hdr, size_t * hdr_size, size_t * data_buf_size, size_t * hdr_buf_size); int ndp_char_poll(void *priv, void *app_priv, struct file *filp, struct poll_table_struct *wait); From 5b98be728462f96fb3344fe5298e95e5891ba7cf Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 26 Feb 2025 15:18:41 +0100 Subject: [PATCH 338/518] feat(NDP / DMA Calypte): use ndp_ctrl_v3_get_vmaps in kernel open_queue --- libnfb/include/netcope/ndp.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 7d803ae7..3e57408d 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -144,15 +144,14 @@ static inline int nc_ndp_v2_open_queue(struct nc_ndp_queue *q, const void *fdt, static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, int fdt_offset, int ctrl_offset, int dir) { -#ifndef __KERNEL__ - int prot; - int ret = 0; size_t hdr_mmap_size = 0; - off_t hdr_mmap_offset = 0; - size_t hdr_buff_size = 0; size_t data_buff_size = 0; +#ifndef __KERNEL__ + off_t hdr_mmap_offset = 0; + int prot; + int ret; #endif struct ndp_queue_ops *ops = ndp_queue_get_ops(q->q); @@ -162,7 +161,12 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, q->u.v3.sdp = 0; q->u.v3.shp = 0; -#ifndef __KERNEL__ +#ifdef __KERNEL__ + ndp_ctrl_v3_get_vmaps( + q->sub->channel, (void**)&q->u.v3.hdrs, + &hdr_mmap_size, &hdr_buff_size, &data_buff_size); + +#else q->u.v3.uspace_shp = 0; q->u.v3.uspace_hhp = 0; q->u.v3.uspace_hdp = 0; From ca2ae6dcdc7543caee13f4e358aca0c36ce52934 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 18 Feb 2025 07:49:54 +0100 Subject: [PATCH 339/518] fix(NDP / DMA Calypte): open TX buffer components in kernel space too --- libnfb/include/netcope/ndp_calypte.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libnfb/include/netcope/ndp_calypte.h b/libnfb/include/netcope/ndp_calypte.h index 1eab837b..547965f8 100644 --- a/libnfb/include/netcope/ndp_calypte.h +++ b/libnfb/include/netcope/ndp_calypte.h @@ -11,7 +11,6 @@ // opened using this function. static inline int ndp_queue_calypte_open_buffers(struct nfb_device *dev, struct nc_ndp_queue *q, const void *fdt, int fdt_offset) { -#ifndef __KERNEL__ int ctrl_node_offset = -1; int buffer_offset = -1; @@ -46,19 +45,16 @@ static inline int ndp_queue_calypte_open_buffers(struct nfb_device *dev, struct err_hdr_buff_find_tx: nfb_comp_close(q->u.v3.tx_data_buff); return -EBADFD; -#endif return 0; } static inline void ndp_queue_calypte_close_buffers(struct nc_ndp_queue *q) { -#ifndef __KERNEL__ if (q->protocol == 3 && q->channel.type == NDP_CHANNEL_TYPE_TX) { nfb_comp_close(q->u.v3.tx_data_buff); nfb_comp_close(q->u.v3.tx_hdr_buff); q->u.v3.tx_data_buff = NULL; q->u.v3.tx_hdr_buff = NULL; } -#endif return; } From 3cb48ec9c89a6b5e2a018f365c82eacc25cafdaf Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 26 Feb 2025 15:31:26 +0100 Subject: [PATCH 340/518] fix(NDP / DMA Calypte): assign hwptr value to shp initial value on start / first sync This fixes an issue, when another process opened the queue and already received some packets, then current process joins NDP buffer and gets the old packets / garbage. With this fix the current process begins receiving from the correct (potentially non-zero) shp pointer. The shp equals to hwptr means empty NDP buffer (no old packets). --- libnfb/include/netcope/ndp.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 3e57408d..c6bdf0a1 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -361,13 +361,22 @@ static int nc_ndp_queue_start(void *priv) struct nc_ndp_queue *q = priv; int ret; + int shared_q = 1; + + if (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) + shared_q = 0; + q->sync.flags = 0; if ((ret = _ndp_queue_start(q))) return ret; - if (q->channel.type == NDP_CHANNEL_TYPE_RX && q->protocol == 2 && (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) == 0) { - q->u.v2.rhp = q->sync.hwptr; + if (q->channel.type == NDP_CHANNEL_TYPE_RX && shared_q) { + if (q->protocol == 2) + q->u.v2.rhp = q->sync.hwptr; + else if (q->protocol == 3) { + q->u.v3.shp = q->sync.hwptr; + } } #ifndef __KERNEL__ From da3201ea0a97992d9c9c57de85a1cecc4fe8da80 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 3 Mar 2025 13:23:56 +0100 Subject: [PATCH 341/518] fix(NDP / DMA Calypte): clear header valid flag inside proper function --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 1 + libnfb/include/netcope/ndp_rx.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 69b8f589..bbd7b542 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -509,6 +509,7 @@ static void ndp_ctrl_calypte_rx_set_swptr(struct ndp_channel *channel, uint64_t unsigned i; for (i = 0; i < count; i++) { + hdr[i].valid = 0; new_sdp += (hdr[i].frame_len + NDP_RX_CALYPTE_BLOCK_SIZE - 1) / NDP_RX_CALYPTE_BLOCK_SIZE; } diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index 3539d445..3631f889 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -246,6 +246,7 @@ static inline void _ndp_queue_rx_sync_v3_us(struct nc_ndp_queue *q) hdr_base = q->u.v3.hdrs + q->u.v3.uspace_shp; for (i = 0; i < count; i++) { + hdr_base[i].valid = 0; count_blks += (hdr_base[i].frame_len + NDP_RX_CALYPTE_BLOCK_SIZE - 1) / NDP_RX_CALYPTE_BLOCK_SIZE; } @@ -351,7 +352,6 @@ static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *pac packets[i].data = data; packets[i].data_length = packet_size; - hdr->valid = 0; q->u.v3.sdp += (hdr->frame_len + NDP_RX_CALYPTE_BLOCK_SIZE - 1) / NDP_RX_CALYPTE_BLOCK_SIZE; } From ca5ebb2002460e2d8c98ae33a0a0e5a07fdf1190 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 4 Mar 2025 11:08:04 +0100 Subject: [PATCH 342/518] fix(NDP / DMA Calypte): do not rely on cached metadata in tx_burst_put Buffer pointer from the ndp_packet structure filled in the tx_burst_get can't be used, because the NDP API doesn't require user to hold the values inside ndp_packet between tx_burst_get and tx_burst_put. For example, when the ndp_packet is allocated on stack and the get/put functions are called in different functions, values inside ndp_packet* are overwritten and invalid. This fix preallocates space of constant size for metadata. --- libnfb/include/netcope/ndp_calypte.h | 38 +++++++++++++++++++++------- libnfb/include/netcope/ndp_priv.h | 5 ++-- libnfb/include/netcope/ndp_tx.h | 10 +++----- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/libnfb/include/netcope/ndp_calypte.h b/libnfb/include/netcope/ndp_calypte.h index 547965f8..cdcbccb0 100644 --- a/libnfb/include/netcope/ndp_calypte.h +++ b/libnfb/include/netcope/ndp_calypte.h @@ -11,6 +11,7 @@ // opened using this function. static inline int ndp_queue_calypte_open_buffers(struct nfb_device *dev, struct nc_ndp_queue *q, const void *fdt, int fdt_offset) { + int ret = -EBADFD; int ctrl_node_offset = -1; int buffer_offset = -1; @@ -18,6 +19,8 @@ static inline int ndp_queue_calypte_open_buffers(struct nfb_device *dev, struct if (!(q->protocol == 3 && q->channel.type == NDP_CHANNEL_TYPE_TX)) return 0; + q->u.v3.tx_pkts_cnt = 256; + ctrl_node_offset = fdt_node_offset_by_phandle_ref(fdt, fdt_offset, "ctrl"); if (ctrl_node_offset < 0) return -EBADFD; @@ -40,21 +43,38 @@ static inline int ndp_queue_calypte_open_buffers(struct nfb_device *dev, struct goto err_hdr_buff_open_tx; } +#ifdef __KERNEL__ + q->u.v3.tx_pkts = kzalloc(sizeof(void*) * q->u.v3.tx_pkts_cnt, GFP_KERNEL); +#else + q->u.v3.tx_pkts = malloc(sizeof(void*) * q->u.v3.tx_pkts_cnt); +#endif + if (q->u.v3.tx_pkts == NULL) { + ret = -ENOMEM; + goto err_alloc_tx_pkts; + } + return 0; + +err_alloc_tx_pkts: + nfb_comp_close(q->u.v3.tx_hdr_buff); err_hdr_buff_open_tx: err_hdr_buff_find_tx: nfb_comp_close(q->u.v3.tx_data_buff); - return -EBADFD; - return 0; + return ret; } static inline void ndp_queue_calypte_close_buffers(struct nc_ndp_queue *q) { - if (q->protocol == 3 && q->channel.type == NDP_CHANNEL_TYPE_TX) { - nfb_comp_close(q->u.v3.tx_data_buff); - nfb_comp_close(q->u.v3.tx_hdr_buff); - q->u.v3.tx_data_buff = NULL; - q->u.v3.tx_hdr_buff = NULL; - } - return; + if (!(q->protocol == 3 && q->channel.type == NDP_CHANNEL_TYPE_TX)) + return; + + nfb_comp_close(q->u.v3.tx_data_buff); + nfb_comp_close(q->u.v3.tx_hdr_buff); + q->u.v3.tx_data_buff = NULL; + q->u.v3.tx_hdr_buff = NULL; +#ifdef __KERNEL__ + kfree(q->u.v3.tx_pkts); +#else + free(q->u.v3.tx_pkts); +#endif } diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index a2461fec..13c3b609 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -80,10 +80,11 @@ struct nc_ndp_queue { uint32_t data_ptr_mask; uint32_t hdr_ptr_mask; - // Packet descriptions - struct ndp_packet *packets; // Buffer for headers struct ndp_v3_packethdr *hdrs; + /* Store metadata for use in tx_burst_put */ + void ** tx_pkts; + uint64_t tx_pkts_cnt; /* Number of tx_pkts items */ #ifndef __KERNEL__ struct ndp_v3_packethdr *uspace_hdrs; struct nfb_comp *comp; diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index f228ec11..3f4ce08c 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -411,7 +411,7 @@ static inline unsigned nc_ndp_v3_tx_burst_get(void *priv, struct ndp_packet *pac uint32_t sdp_int; // All previously reserved packets need to be sent before new reservation takes place - if (unlikely(q->u.v3.pkts_to_send != 0)) + if (unlikely(q->u.v3.pkts_to_send != 0 || q->u.v3.tx_pkts_cnt < count)) return 0; __builtin_prefetch(q->u.v3.hdrs); @@ -458,6 +458,7 @@ static inline unsigned nc_ndp_v3_tx_burst_get(void *priv, struct ndp_packet *pac hdr->flags = packets[i].flags & 0xF; /* Set pointers, where user can write packet content */ + q->u.v3.tx_pkts[i] = data_base + sdp_int; packets[i].header = data_base + sdp_int; packets[i].data = data_base + sdp_int + header_size; @@ -472,7 +473,6 @@ static inline unsigned nc_ndp_v3_tx_burst_get(void *priv, struct ndp_packet *pac q->u.v3.pkts_available -= count; // For packet sending - q->u.v3.packets = packets; q->u.v3.pkts_to_send += count; return count; } @@ -481,7 +481,7 @@ static inline int nc_ndp_v3_tx_burst_flush(void *priv) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; - if (q->u.v3.shp >= (q->u.v3.hdr_ptr_mask +1)) { + if (q->u.v3.shp >= (q->u.v3.hdr_ptr_mask + 1)) { q->u.v3.shp -= (q->u.v3.hdr_ptr_mask + 1); q->u.v3.hdrs -= (q->u.v3.hdr_ptr_mask + 1); } @@ -521,7 +521,6 @@ static inline int nc_ndp_v3_tx_burst_put(void *priv) unsigned i; uint32_t frame_len_ceil; - struct ndp_packet *packet = q->u.v3.packets; struct ndp_v3_packethdr *hdr = q->u.v3.hdrs - q->u.v3.pkts_to_send; uint32_t shp = q->u.v3.shp - q->u.v3.pkts_to_send; @@ -535,7 +534,7 @@ static inline int nc_ndp_v3_tx_burst_put(void *priv) return -1; } - nfb_comp_write(q->u.v3.tx_data_buff, packet[i].header, hdr[i].frame_len, hdr[i].frame_ptr); + nfb_comp_write(q->u.v3.tx_data_buff, q->u.v3.tx_pkts[i], hdr[i].frame_len, hdr[i].frame_ptr); q->u.v3.bytes_available -= frame_len_ceil; @@ -543,7 +542,6 @@ static inline int nc_ndp_v3_tx_burst_put(void *priv) // This below line needs to updated somewhere shp = (shp + 1) & (q->u.v3.hdr_ptr_mask); } - q->u.v3.packets -= q->u.v3.pkts_to_send; q->u.v3.pkts_to_send = 0; nc_ndp_v3_tx_burst_flush(priv); From 2da886b898270b31bd1767547237ab3de0cb1b61 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 4 Mar 2025 15:39:00 +0100 Subject: [PATCH 343/518] fix(NDP / DMA Calypte): call tx_burst_put inside tx_burst_flush This ensures default behavior of shortcut flush usage withou put. --- libnfb/include/netcope/ndp_tx.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index 3f4ce08c..51b6805f 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -397,6 +397,8 @@ static inline int nc_ndp_v3_tx_request_space(struct nc_ndp_queue *q, uint32_t sh return 0; } +static inline int nc_ndp_v3_tx_burst_put(void *priv); + static inline unsigned nc_ndp_v3_tx_burst_get(void *priv, struct ndp_packet *packets, unsigned count) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; @@ -481,6 +483,11 @@ static inline int nc_ndp_v3_tx_burst_flush(void *priv) { struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + if (q->u.v3.pkts_to_send > 0) { + /* the tx_burst_put internally calls tx_burst_flush */ + return nc_ndp_v3_tx_burst_put(q); + } + if (q->u.v3.shp >= (q->u.v3.hdr_ptr_mask + 1)) { q->u.v3.shp -= (q->u.v3.hdr_ptr_mask + 1); q->u.v3.hdrs -= (q->u.v3.hdr_ptr_mask + 1); @@ -524,7 +531,6 @@ static inline int nc_ndp_v3_tx_burst_put(void *priv) struct ndp_v3_packethdr *hdr = q->u.v3.hdrs - q->u.v3.pkts_to_send; uint32_t shp = q->u.v3.shp - q->u.v3.pkts_to_send; - for (i = 0; i < q->u.v3.pkts_to_send; i++) { frame_len_ceil = (hdr[i].frame_len + (NDP_TX_CALYPTE_BLOCK_SIZE -1)) & (~(NDP_TX_CALYPTE_BLOCK_SIZE -1)); From 50dc5072ea5de092a530f9dd63e3f10b02e7aadc Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 4 Mar 2025 14:57:18 +0100 Subject: [PATCH 344/518] hotfix(drivers - reload): detach slow-exiting drivers before reload Some drivers need access to card registers on their detach. This is problem on cards which reloads immediately without timeout. This patch enables detaching specific drivers early, before issuing the reload command. --- drivers/kernel/drivers/nfb/boot/reload.c | 1 + drivers/kernel/drivers/nfb/core.c | 12 +++++++++++- drivers/kernel/drivers/nfb/nfb.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index 827e1ced..74e8a2dd 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -255,6 +255,7 @@ int nfb_boot_reload(void *arg) /* Workaround: Close all MTDs within BootFPGA */ nfb_boot_mtd_destroy(boot); + nfb_detach_driver_before_reload(nfb); reload_time_ms = 2000; /* Send reload-fw command to BootFPGA component */ diff --git a/drivers/kernel/drivers/nfb/core.c b/drivers/kernel/drivers/nfb/core.c index 8a063552..ffc4408d 100644 --- a/drivers/kernel/drivers/nfb/core.c +++ b/drivers/kernel/drivers/nfb/core.c @@ -89,6 +89,16 @@ static void nfb_attach_drivers(struct nfb_device* nfb) mutex_unlock(&nfb_driver_register_mutex); } +void nfb_detach_driver_before_reload(struct nfb_device* nfb) +{ + int i; + for (i = NFB_DRIVERS_MAX - 1; i >= 0; i--) { + if ((nfb_registered_drivers[i].attach == nfb_ndp_netdev_attach) || + (nfb_registered_drivers[i].attach == nfb_net_attach)) { + nfb_detach_driver(nfb, i); + } + } +} /* * nfb_detach_drivers - detach embedded drivers from NFB device * @nfb: NFB device structure @@ -296,7 +306,7 @@ void nfb_driver_unregister(struct nfb_driver_ops ops) EXPORT_SYMBOL_GPL(nfb_driver_unregister); static struct nfb_driver_ops embedded_driver_ops[] = { - /* INFO: Synchronize position of NDP driver with NFB_DRIVIER_NDP value! */ + /* INFO: Synchronize position of NDP driver with NFB_DRIVER_NDP value! */ { .attach = nfb_mi_attach, .detach = nfb_mi_detach, diff --git a/drivers/kernel/drivers/nfb/nfb.h b/drivers/kernel/drivers/nfb/nfb.h index b371ffe0..ab0ceb3a 100644 --- a/drivers/kernel/drivers/nfb/nfb.h +++ b/drivers/kernel/drivers/nfb/nfb.h @@ -148,6 +148,7 @@ void *nfb_nalloc(int numa_node, size_t size); void nfb_nfree(int numa_node, void *ptr, size_t size); void *nfb_get_priv_for_attach_fn(struct nfb_device *nfb, nfb_driver_ops_attach_t attach); +void nfb_detach_driver_before_reload(struct nfb_device* nfb); void nfb_probe_endpoint_late(struct nfb_device *nfb, struct nfb_pci_device *pci_device); void nfb_remove_endpoint_early(struct nfb_device *nfb, struct nfb_pci_device *pci_device); From 180c1d56805c82a9732c2e01244546e1b74c0352 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 17 Apr 2025 13:39:12 +0200 Subject: [PATCH 345/518] feat(drivers - ndp_netdev): enable dynamic netdev management --- drivers/kernel/drivers/nfb/ndp_netdev/core.c | 158 ++++++++++++++++--- drivers/kernel/drivers/nfb/ndp_netdev/core.h | 1 + 2 files changed, 141 insertions(+), 18 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp_netdev/core.c b/drivers/kernel/drivers/nfb/ndp_netdev/core.c index 78b45260..f61e51d3 100644 --- a/drivers/kernel/drivers/nfb/ndp_netdev/core.c +++ b/drivers/kernel/drivers/nfb/ndp_netdev/core.c @@ -22,6 +22,7 @@ #include #include #include +#include static bool ndp_netdev_enable = 0; @@ -342,12 +343,23 @@ const struct attribute_group *nfb_ndp_netdev_attr_groups[] = { * nfb_ndp_netdev_create - creates and registers new network device in the system * @index: index of network interface */ -static struct nfb_ndp_netdev *nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *eth, int index) +static int nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *eth, int index) { struct nfb_device *nfb = eth->nfb; struct nfb_ndp_netdev *ethdev; struct net_device *ndev; - int ret; + int ret = 0; + char name[64]; + + snprintf(name, sizeof(name), "nfb%ud%u", nfb->minor, index); + + mutex_lock(ð->list_ethdev_mutex); + list_for_each_entry(ethdev, ð->list_ethdev, list_item) { + if (strcmp(name, dev_name(ðdev->device)) == 0) { + ret = -EEXIST; + goto err_exist; + } + } ndev = alloc_etherdev(sizeof(*ethdev)); if (!ndev) { @@ -365,7 +377,7 @@ static struct nfb_ndp_netdev *nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *e device_initialize(ðdev->device); ethdev->device.parent = ð->dev; ethdev->device.groups = nfb_ndp_netdev_attr_groups; - dev_set_name(ðdev->device, "nfb%ud%u", nfb->minor, index); + dev_set_name(ðdev->device, name); dev_set_drvdata(ðdev->device, ethdev); ret = device_add(ðdev->device); if (ret) @@ -375,7 +387,7 @@ static struct nfb_ndp_netdev *nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *e ndev->netdev_ops = &ndp_netdev_ops; SET_NETDEV_DEV(ndev, &nfb->pci->dev); - snprintf(ndev->name, IFNAMSIZ-1, "nfb%ud%u", nfb->minor, index); + snprintf(ndev->name, IFNAMSIZ-1, name); nfb_net_set_dev_addr(nfb, ndev, index); ret = register_netdev(ndev); @@ -390,7 +402,10 @@ static struct nfb_ndp_netdev *nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *e if (ndp_netdev_carrier) netif_carrier_on(ndev); - return ethdev; + list_add_tail(ðdev->list_item, ð->list_ethdev); + + mutex_unlock(ð->list_ethdev_mutex); + return 0; unregister_netdev(ethdev->ndev); err_register_netdev: @@ -398,7 +413,9 @@ static struct nfb_ndp_netdev *nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *e err_device_add: free_netdev(ndev); err_alloc: - return NULL; +err_exist: + mutex_unlock(ð->list_ethdev_mutex); + return ret; } /** @@ -406,11 +423,119 @@ static struct nfb_ndp_netdev *nfb_ndp_netdev_create(struct nfb_mod_ndp_netdev *e */ static void nfb_ndp_netdev_destroy(struct nfb_ndp_netdev *ethdev) { + list_del(ðdev->list_item); + unregister_netdev(ethdev->ndev); device_del(ðdev->device); free_netdev(ethdev->ndev); } +enum { + Opt_index, + Opt_cmd, + Opt_err, +}; + +static const match_table_t tokens = { + {Opt_index, "index=%d"}, + {Opt_cmd, "cmd=%s"}, + {Opt_err, NULL}, +}; + +static ssize_t ndp_netdev_get_cmd(struct device *dev, struct device_attribute *attr, char *buf) +{ + return 0; +} + +static ssize_t ndp_netdev_set_cmd(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + struct nfb_mod_ndp_netdev * eth = dev_get_drvdata(dev); + struct nfb_ndp_netdev *ethdev, *tmp; + + char *options, *options_iter; + char *p; + substring_t args[MAX_OPT_ARGS]; + int ret; + + int index = -1; + char *cmd = NULL; + char name[64]; + + if (buf[size - 1] != 0) + return -EINVAL; + + options = options_iter = kstrdup(buf, GFP_KERNEL); + if (!options) + return -ENOMEM; + + while ((p = strsep(&options_iter, ",")) != NULL) { + int token; + + if (!*p) + continue; + token = match_token(p, tokens, args); + switch (token) { + case Opt_index: + ret = match_int(&args[0], &index); + if (ret) + goto err_parser; + break; + case Opt_cmd: + cmd = match_strdup(&args[0]); + break; + default: + continue; + } + } + + if (cmd == NULL || index == -1) { + ret = -EINVAL; + goto err_parser; + } + + if (strcmp(cmd, "add") == 0 && index != -1) { + ret = nfb_ndp_netdev_create(eth, index); + } else if (strcmp(cmd, "del") == 0) { + ret = -ENODEV; + snprintf(name, sizeof(name), "nfb%ud%u", eth->nfb->minor, index); + + mutex_lock(ð->list_ethdev_mutex); + list_for_each_entry_safe(ethdev, tmp, ð->list_ethdev, list_item) { + if (strcmp(name, dev_name(ðdev->device)) == 0) { + nfb_ndp_netdev_destroy(ethdev); + ret = 0; + break; + } + } + mutex_unlock(ð->list_ethdev_mutex); + } else { + ret = -ENXIO; + } + +err_parser: + kfree(cmd); + kfree(options); + return ret ? ret : size; +} + +/* Attributes for sysfs - declarations */ +static DEVICE_ATTR(cmd, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_netdev_get_cmd, ndp_netdev_set_cmd); + +static struct attribute *ndp_netdev_attrs[] = { + &dev_attr_cmd.attr, + NULL, +}; + +static struct attribute_group ndp_netdev_attr_group = { + .attrs = ndp_netdev_attrs, +}; + +static const struct attribute_group *ndp_netdev_attr_groups[] = { + &ndp_netdev_attr_group, + NULL, +}; + /** * nfb_ndp_netdev_attach - initializes this submodule * @@ -421,18 +546,12 @@ int nfb_ndp_netdev_attach(struct nfb_device *nfb, void **priv) int ret = 0; int index; struct nfb_mod_ndp_netdev * eth; - struct nfb_ndp_netdev *ethdev; int rx; int tx; int proplen; const fdt64_t *proprx, *proptx; - if (!ndp_netdev_enable) { - *priv = NULL; - return 0; - } - eth = kzalloc(sizeof(*eth), GFP_KERNEL); if (!eth) { ret = -ENOMEM; @@ -442,11 +561,13 @@ int nfb_ndp_netdev_attach(struct nfb_device *nfb, void **priv) INIT_LIST_HEAD(ð->list_ethdev); eth->nfb = nfb; *priv = eth; + mutex_init(ð->list_ethdev_mutex); device_initialize(ð->dev); eth->dev.parent = eth->nfb->dev; dev_set_name(ð->dev, "ndp_netdev"); dev_set_drvdata(ð->dev, eth); + eth->dev.groups = ndp_netdev_attr_groups; ret = device_add(ð->dev); if (ret) goto err_device_add; @@ -457,14 +578,14 @@ int nfb_ndp_netdev_attach(struct nfb_device *nfb, void **priv) tx = fdt_path_offset(nfb->fdt, "/drivers/ndp/tx_queues"); rx = fdt_first_subnode(nfb->fdt, rx), tx = fdt_first_subnode(nfb->fdt, tx); - while (rx >= 0 && tx >= 0) { + while (rx >= 0 && tx >= 0 && ndp_netdev_enable) { /* Check if queue is available (both rx + tx)*/ proprx = fdt_getprop(nfb->fdt, rx, "mmap_size", &proplen); proptx = fdt_getprop(nfb->fdt, tx, "mmap_size", &proplen); if (proprx && proptx && fdt64_to_cpu(*proprx) && fdt64_to_cpu(*proptx)) { - ethdev = nfb_ndp_netdev_create(eth, index); - if (ethdev) - list_add_tail(ðdev->list_item, ð->list_ethdev); + ret = nfb_ndp_netdev_create(eth, index); + if (ret) + dev_warn(&nfb->pci->dev, "ndp_netdev: Can't create netdev for index %d, skipping\n", index); index++; } rx = fdt_next_subnode(nfb->fdt, rx); @@ -473,7 +594,7 @@ int nfb_ndp_netdev_attach(struct nfb_device *nfb, void **priv) dev_info(&nfb->pci->dev, "ndp_netdev: Attached successfully (%d NDP based ETH interfaces)\n", index); - return ret; + return 0; device_del(ð->dev); err_device_add: @@ -495,10 +616,11 @@ void nfb_ndp_netdev_detach(struct nfb_device *nfb, void *priv) if (eth == NULL) return; + mutex_lock(ð->list_ethdev_mutex); list_for_each_entry_safe(ethdev, tmp, ð->list_ethdev, list_item) { - list_del(ðdev->list_item); nfb_ndp_netdev_destroy(ethdev); } + mutex_unlock(ð->list_ethdev_mutex); device_del(ð->dev); diff --git a/drivers/kernel/drivers/nfb/ndp_netdev/core.h b/drivers/kernel/drivers/nfb/ndp_netdev/core.h index dd410b1d..5a3cf72f 100644 --- a/drivers/kernel/drivers/nfb/ndp_netdev/core.h +++ b/drivers/kernel/drivers/nfb/ndp_netdev/core.h @@ -18,6 +18,7 @@ struct nfb_mod_ndp_netdev { struct nfb_device *nfb; + struct mutex list_ethdev_mutex; struct list_head list_ethdev; struct device dev; }; From 3dfd6e802f94f7005b081f65636ab55fb58ec37f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 17 Apr 2025 13:44:58 +0200 Subject: [PATCH 346/518] feat(tool - dma): enable dynamic netdev management --- tools/dma/dma.c | 61 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index b3d431e3..0b879939 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -40,7 +40,7 @@ /*! -v verbose mode; */ /*! -V version */ -#define ARGUMENTS "d:i:q:rtRS:B:C:O:Tvh" +#define ARGUMENTS "d:i:q:rtRS:B:C:N:O:Tvh" enum commands { CMD_PRINT_STATUS, @@ -51,6 +51,7 @@ enum commands { CMD_SET_BUFFER_SIZE, CMD_SET_BUFFER_COUNT, CMD_SET_INITIAL_OFFSET, + CMD_NETDEV, CMD_QUERY, }; @@ -112,9 +113,13 @@ void usage(const char *me, int verbose) } printf(" example of usage: '-q rx_received,tx_sent'\n"); } - + printf("-N netdev_drv Perform a netdev command (add,del) on the selected indexes\n"); printf("-v Increase verbosity\n"); printf("-h Show this text\n"); + printf("\nExamples:\n"); + printf("nfb-dma -i0 -N ndp_netdev add Create NDP based netdev\n"); +// printf("nfb-dma -i0-7 -N xdp add,id=1,eth=0,eth=1 Create XDP based netdev with rxq-txq pairs 0-7 and use also ethernet interface 0+1\n"); +// printf("nfb-dma -i0-7 -N xdp del,id=1 Delete XDP based netdev with id=1\n"); } int set_ring_size(struct nfb_device *dev, int dir, int index, const char* csize, const char *target) @@ -139,6 +144,43 @@ int set_ring_size(struct nfb_device *dev, int dir, int index, const char* csize, return 0; } +int cmd_ndp_netdev(struct nfb_device *dev, const char *ndd, const char *cmd, struct list_range *index_range) +{ + int fd; + char buffer[128]; + ssize_t ret = 0, sz = 0; + + snprintf(buffer, sizeof(buffer), + "/sys/class/nfb/nfb%d/%s/cmd", + nfb_get_system_id(dev), ndd); + + fd = open(buffer, O_RDWR); + if (fd == -1) + err(errno, "Can't perform ndp_netdev %s", cmd); + + if (strcmp(ndd, "ndp_netdev") == 0) { + if (index_range->items == 1 && index_range->min[0] == index_range->max[0]) { + sz = snprintf(buffer, sizeof(buffer), "cmd=%s,index=%d", cmd, index_range->min[0]); + } else { + ret = -EINVAL; + } + } + + if (sz == 0) { + ret = -ENXIO; + } else { + sz++; + ret = write(fd, buffer, sz); + } + + if (ret != sz) { + err(ret, "Can't perform ndp_netdev %s", cmd); + } + close(fd); + return ret < 0 ? ret : 0; +} + + /*! * \brief Convert and display number of bits in kB or MB * @@ -481,6 +523,7 @@ int main(int argc, char *argv[]) char c; const char *file = nfb_default_dev_path(); + const char *netdev_cmd = ""; struct nfb_device *dev; struct nc_rxqueue *rxq; @@ -547,6 +590,10 @@ int main(int argc, char *argv[]) cmd = CMD_SET_INITIAL_OFFSET; csize = optarg; break; + case 'N': + cmd = CMD_NETDEV; + netdev_cmd = optarg; + break; default: err(-EINVAL, "Unknown argument -%c", optopt); } @@ -561,8 +608,10 @@ int main(int argc, char *argv[]) argc -= optind; argv += optind; - if (argc) { - err(errno, "Stray arguments"); + if (cmd == CMD_NETDEV && argc < 1) { + err(errno, "Missing netdev command argument"); + } else if ((cmd == CMD_NETDEV && argc > 1) || (cmd != CMD_NETDEV && argc)) { + err(errno, "Stray arguments %d", argc); } dev = nfb_open(file); @@ -570,6 +619,10 @@ int main(int argc, char *argv[]) err(errno, "Can't open NFB device"); } + if (cmd == CMD_NETDEV) { + return cmd_ndp_netdev(dev, netdev_cmd, argv[0], &index_range); + } + if (query) { size = nc_query_parse(query, queries, NC_ARRAY_SIZE(queries), &queries_index); if (size <= 0) { From f37394570fc4bd78237bee6e33ed9eb9646f57ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 9 Apr 2025 08:34:18 +0200 Subject: [PATCH 347/518] feat(ndptool - add xdp-read): add XDP equivalent of ndp-read --- tools/CMakeLists.txt | 7 +- tools/ndptool/common.h | 27 +++- tools/ndptool/main.c | 27 ++-- tools/ndptool/modules.c | 22 +++- tools/ndptool/xdp/xdp_common.c | 121 +++++++++++++++++ tools/ndptool/xdp/xdp_common.h | 76 +++++++++++ tools/ndptool/xdp/xdp_read.c | 229 +++++++++++++++++++++++++++++++++ 7 files changed, 487 insertions(+), 22 deletions(-) create mode 100644 tools/ndptool/xdp/xdp_common.c create mode 100644 tools/ndptool/xdp/xdp_common.h create mode 100644 tools/ndptool/xdp/xdp_read.c diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index ca06bd66..f440b594 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -23,6 +23,8 @@ find_package(PkgConfig) pkg_check_modules(NCURSES REQUIRED ncurses) pkg_check_modules(ARCHIVE REQUIRED libarchive) +pkg_check_modules(XDP REQUIRED libxdp) +pkg_check_modules(BPF REQUIRED libbpf) ndk_check_build_dependency(FDT_LIBRARIES fdt FDT_INCLUDE_DIRS libfdt.h libfdt) ndk_check_build_dependency(NUMA_LIBRARIES numa NUMA_INCLUDE_DIRS numa.h) @@ -53,6 +55,7 @@ add_executable(ndp-tool ndptool/common.c ndptool/generate.c ndptool/loopback.c ndptool/loopback_hw.c ndptool/main.c ndptool/modules.c ndptool/pcap.c ndptool/read.c ndptool/receive.c ndptool/stats.c ndptool/transmit.c + ndptool/xdp/xdp_common.c ndptool/xdp/xdp_read.c ) set (PIE_TARGETS nfb-info nfb-boot nfb-bus nfb-dma nfb-eth nfb-tsu nfb-mdio ndp-tool) @@ -66,10 +69,10 @@ target_link_libraries(nfb-boot target_compile_options(ndp-tool PRIVATE -O3 -funroll-loops) target_link_libraries(ndp-tool - PRIVATE ${NUMA_LIBRARIES} ${NCURSES_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + PRIVATE ${NUMA_LIBRARIES} ${NCURSES_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${BPF_LIBRARIES} ${XDP_LIBRARIES} ) -set(NDP_TARGETS receive read transmit loopback loopback-hw generate) +set(NDP_TARGETS receive read transmit loopback loopback-hw generate xdp-read) foreach(NDP_TARGET IN LISTS NDP_TARGETS) add_custom_target(ndp-${NDP_TARGET} ALL DEPENDS ndp-tool diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index 3701df13..cbe33b47 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -140,6 +140,18 @@ struct ndp_mode_dpdk_params { unsigned long min_len; /*!< Minimal allowed frame length that can be transferred. */ }; +struct ndp_mode_xdp_params { + // queue indexes as user passed them into the programm + struct list_range queue_range; + unsigned socket_cnt; + // struct xdp_program *prog; + // array of sockets + struct ndp_mode_xdp_xsk_data *queue_data_arr; + + // ndp compatibility params + struct ndp_mode_generate_params generate; +}; + typedef void (*update_stats_t)(struct ndp_packet *packets, int count, struct stats_info *si); struct ndp_tool_params { @@ -158,6 +170,7 @@ struct ndp_tool_params { struct ndp_mode_receive_params receive; struct ndp_mode_loopback_hw_params loopback_hw; struct ndp_mode_dpdk_params dpdk; + struct ndp_mode_xdp_params xdp; } mode; const char *pcap_filename; @@ -226,11 +239,15 @@ enum ndp_modules { NDP_MODULE_TRANSMIT, NDP_MODULE_LOOPBACK, NDP_MODULE_LOOPBACK_HW, - NDP_MODULE_DPDK_GENERATE, - NDP_MODULE_DPDK_READ, - NDP_MODULE_DPDK_LOOPBACK, - NDP_MODULE_DPDK_RECEIVE, - NDP_MODULE_DPDK_TRANSMIT, + XDP_MODULE_READ, + XDP_MODULE_GENERATE, +#ifdef USE_DPDK + DPDK_MODULE_GENERATE, + DPDK_MODULE_READ, + DPDK_MODULE_LOOPBACK, + DPDK_MODULE_RECEIVE, + DPDK_MODULE_TRANSMIT, +#endif /* NONE module must be last! */ NDP_MODULE_NONE, }; diff --git a/tools/ndptool/main.c b/tools/ndptool/main.c index aa9ad8da..efd7b383 100644 --- a/tools/ndptool/main.c +++ b/tools/ndptool/main.c @@ -168,7 +168,9 @@ int main(int argc, char *argv[]) /* Check if tool was executed from symlink */ if (strncmp(basename(argv[0]), "ndp-", 4) == 0 && - strcmp(basename(argv[0]), "ndp-tool") != 0 && strcmp(basename(argv[0]), "ndp-tool-dpdk") != 0) { + strcmp(basename(argv[0]), "ndp-tool") != 0 && + strcmp(basename(argv[0]), "ndp-tool-dpdk") != 0 && + strcmp(basename(argv[0]), "ndp-tool-xdp") != 0) { strmode = basename(argv[0]) + 4; } else if (argc < 2) { errx(-1, "No mode selected"); @@ -282,11 +284,14 @@ int main(int argc, char *argv[]) rx_queues = ndp_get_rx_queue_count(dev); tx_queues = ndp_get_tx_queue_count(dev); #ifdef USE_DPDK - if (mode == NDP_MODULE_DPDK_GENERATE || mode == NDP_MODULE_DPDK_READ || mode == NDP_MODULE_DPDK_LOOPBACK - || mode == NDP_MODULE_DPDK_RECEIVE || mode == NDP_MODULE_DPDK_TRANSMIT) { + if (mode == DPDK_MODULE_GENERATE || mode == DPDK_MODULE_READ || mode == DPDK_MODULE_LOOPBACK + || mode == DPDK_MODULE_RECEIVE || mode == DPDK_MODULE_TRANSMIT) { params.mode.dpdk.queue_range = queue_range; } #endif // USE_DPDK + if (mode == XDP_MODULE_READ) + params.mode.xdp.queue_range = queue_range; + if (module->check) ret = module->check(¶ms); @@ -310,9 +315,10 @@ int main(int argc, char *argv[]) switch (mode) { case NDP_MODULE_READ: case NDP_MODULE_RECEIVE: + case XDP_MODULE_READ: #ifdef USE_DPDK - case NDP_MODULE_DPDK_READ: - case NDP_MODULE_DPDK_RECEIVE: + case DPDK_MODULE_READ: + case DPDK_MODULE_RECEIVE: #endif // USE_DPDK if (ndp_rx_queue_is_available(dev, i)) list_range_add_number(&queue_range, i); @@ -320,8 +326,8 @@ int main(int argc, char *argv[]) case NDP_MODULE_GENERATE: case NDP_MODULE_TRANSMIT: #ifdef USE_DPDK - case NDP_MODULE_DPDK_GENERATE: - case NDP_MODULE_DPDK_TRANSMIT: + case DPDK_MODULE_GENERATE: + case DPDK_MODULE_TRANSMIT: #endif // USE_DPDK if (ndp_tx_queue_is_available(dev, i)) list_range_add_number(&queue_range, i); @@ -329,7 +335,7 @@ int main(int argc, char *argv[]) case NDP_MODULE_LOOPBACK_HW: case NDP_MODULE_LOOPBACK: #ifdef USE_DPDK - case NDP_MODULE_DPDK_LOOPBACK: + case DPDK_MODULE_LOOPBACK: #endif // USE_DPDK if (ndp_rx_queue_is_available(dev, i) && ndp_tx_queue_is_available(dev, i)) list_range_add_number(&queue_range, i); @@ -365,8 +371,9 @@ int main(int argc, char *argv[]) thread_data[i]->thread_id = i; } #ifdef USE_DPDK - if (mode == NDP_MODULE_DPDK_GENERATE || mode == NDP_MODULE_DPDK_READ || - mode == NDP_MODULE_DPDK_LOOPBACK || mode == NDP_MODULE_DPDK_RECEIVE || mode == NDP_MODULE_DPDK_TRANSMIT) { + if (mode == DPDK_MODULE_GENERATE || mode == DPDK_MODULE_READ || + mode == DPDK_MODULE_LOOPBACK || mode == DPDK_MODULE_RECEIVE || + mode == DPDK_MODULE_TRANSMIT) { #else if (false) { #endif // USE_DPDK diff --git a/tools/ndptool/modules.c b/tools/ndptool/modules.c index cf41f597..b4bc0654 100644 --- a/tools/ndptool/modules.c +++ b/tools/ndptool/modules.c @@ -90,6 +90,10 @@ void *ndp_mode_loopback_hw_thread(void *tmp); void ndp_mode_generate_destroy(struct ndp_tool_params *p); void ndp_mode_loopback_hw_destroy(struct ndp_tool_params *p); +int xdp_mode_read(struct ndp_tool_params *p); +int xdp_mode_read_check(struct ndp_tool_params *p); +void *xdp_mode_read_thread(void *tmp); + struct option long_options_speed[] = { {"speed", required_argument, 0, 0}, {0, 0, 0, 0}, @@ -159,8 +163,16 @@ struct ndptool_module modules[] = { .destroy = ndp_mode_loopback_hw_destroy, .flags = 0, }, + [XDP_MODULE_READ] = { + .name = "xdp-read", + .short_help = "Read packets using XDP", + .args = "", + .check = xdp_mode_read_check, + .run_single = xdp_mode_read, + .run_thread = xdp_mode_read_thread, + }, #ifdef USE_DPDK - [NDP_MODULE_DPDK_GENERATE] = { + [DPDK_MODULE_GENERATE] = { .name = "dpdk-generate", .short_help = "dpdk version of generate app", .print_help = dpdk_generate_print_help, @@ -172,7 +184,7 @@ struct ndptool_module modules[] = { .run_thread = dpdk_generate_run_thread, .destroy = dpdk_generate_destroy, }, - [NDP_MODULE_DPDK_READ] = { + [DPDK_MODULE_READ] = { .name = "dpdk-read", .short_help = "dpdk version of read app", .print_help = dpdk_read_print_help, @@ -184,7 +196,7 @@ struct ndptool_module modules[] = { .run_thread = dpdk_read_run_thread, .destroy = dpdk_read_destroy, }, - [NDP_MODULE_DPDK_LOOPBACK] = { + [DPDK_MODULE_LOOPBACK] = { .name = "dpdk-loopback", .short_help = "dpdk version of loopback app", .print_help = dpdk_loopback_print_help, @@ -196,7 +208,7 @@ struct ndptool_module modules[] = { .run_thread = dpdk_loopback_run_thread, .destroy = dpdk_loopback_destroy, }, - [NDP_MODULE_DPDK_RECEIVE] = { + [DPDK_MODULE_RECEIVE] = { .name = "dpdk-receive", .short_help = "dpdk version of receive app", .print_help = dpdk_receive_print_help, @@ -208,7 +220,7 @@ struct ndptool_module modules[] = { .run_thread = dpdk_receive_run_thread, .destroy = dpdk_receive_destroy, }, - [NDP_MODULE_DPDK_TRANSMIT] = { + [DPDK_MODULE_TRANSMIT] = { .name = "dpdk-transmit", .short_help = "dpdk version of transmit app", .print_help = dpdk_transmit_print_help, diff --git a/tools/ndptool/xdp/xdp_common.c b/tools/ndptool/xdp/xdp_common.c new file mode 100644 index 00000000..e3c401e0 --- /dev/null +++ b/tools/ndptool/xdp/xdp_common.c @@ -0,0 +1,121 @@ +#include +#include + +#include + +#include "xdp_common.h" + +#define PATH_BUFF 128 + +static void xdp_mode_common_sysfs_int(const char *sysfs_path, const char *postfix, int *ret) { + FILE *file; + char path[PATH_BUFF]; + int err; + err = snprintf(path, sizeof(path), "%s%s", sysfs_path, postfix); + if (err < 0 || err >= PATH_BUFF) { + fprintf(stderr,"Failed to parse sysfs path\n"); + exit(-1); + } + if (!(file = fopen(path , "r"))) { + fprintf(stderr,"Failed to open %s; Is the XDP driver loaded?\n", path); + exit(-1); + } + err = fscanf(file, "%d", ret); + if(err == EOF) { + fprintf(stderr,"Failed to read %s\n", path); + fclose(file); + exit(-1); + } + fclose(file); +} + +static void xdp_mode_common_sysfs_ifname(const char *sysfs_path, const char *postfix, char *ret) { + FILE *file; + char path[PATH_BUFF]; + int err; + err = snprintf(path, sizeof(path), "%s%s", sysfs_path, postfix); + if (err < 0 || err >= PATH_BUFF) { + fprintf(stderr,"Failed to parse sysfs path\n"); + exit(-1); + } + if (!(file = fopen(path , "r"))) { + fprintf(stderr,"Failed to open %s; Is the XDP driver loaded?\n", path); + exit(-1); + } + err = fscanf(file, "%s", ret); + if(err == EOF) { + fprintf(stderr,"Failed to read %s\n", path); + fclose(file); + exit(-1); + } + fclose(file); +} + +void xdp_mode_common_parse_queues(struct ndp_tool_params *p) { + struct nfb_device *nfb; + struct ndp_mode_xdp_params *params = &p->mode.xdp; + struct list_range *queue_range = ¶ms->queue_range; + int queue_count; + int ret, nfb_system_id, channel_total; + char sysfs_path[PATH_BUFF]; + + // get nfb system id + if(!(nfb = nfb_open(p->nfb_path))) { + fprintf(stderr,"Failed to open nfb\n"); + exit(-1); + } + nfb_system_id = nfb_get_system_id(nfb); + nfb_close(nfb); + + // read xdp module sysfs + ret = snprintf(sysfs_path, sizeof(sysfs_path), "/sys/class/nfb/nfb%d/nfb_xdp", nfb_system_id); + if (ret < 0 || ret >= PATH_BUFF) { + fprintf(stderr,"Failed to get sysfs path\n"); + exit(-1); + } + xdp_mode_common_sysfs_int(sysfs_path, "/channel_total", &channel_total); + + // Open all queues if no range provided + if(!(queue_count = list_range_count(queue_range))) { + queue_count = channel_total; + list_range_add_range(queue_range, 0, channel_total); + } + + // Allocate the channel data structs + if(!(params->queue_data_arr = calloc(queue_count, sizeof(struct ndp_mode_xdp_xsk_data)))) { + fprintf(stderr,"Failed to alloc xdp xsk_data\n"); + exit(-1); + } + + // read channel sysfs + int data_idx = 0; + for (int ch_idx = 0; ch_idx < channel_total; ch_idx++) { + // Skip unwanted channels + if (!list_range_contains(queue_range, ch_idx)) + continue; + + // Parse the path + ret = snprintf(sysfs_path, sizeof(sysfs_path), "/sys/class/nfb/nfb%d/nfb_xdp/channel%d", + nfb_system_id, ch_idx); + if (ret < 0 || ret >= PATH_BUFF) { + fprintf(stderr,"Failed to parse sysfs path for channel %d\n", ch_idx); + exit(-1); + } + + // Fill the structs + params->queue_data_arr[data_idx].nfb_qid = ch_idx; + xdp_mode_common_sysfs_int(sysfs_path, "/index", ¶ms->queue_data_arr[data_idx].eth_qid); + xdp_mode_common_sysfs_ifname(sysfs_path, "/ifname", params->queue_data_arr[data_idx].ifname); + xdp_mode_common_sysfs_int(sysfs_path, "/status", ¶ms->queue_data_arr[data_idx].alive); + if(!params->queue_data_arr[data_idx].alive) + fprintf(stderr, "The queue %d is not open. Is there an XDP netdevice coresponding to this queue? nfb-dma can be used to manage netdevices.\n", ch_idx); + + data_idx++; + } + + params->socket_cnt = queue_count; + if(!params->socket_cnt) { + fprintf(stderr,"No queues found\n"); + exit(-1); + } +} \ No newline at end of file diff --git a/tools/ndptool/xdp/xdp_common.h b/tools/ndptool/xdp/xdp_common.h new file mode 100644 index 00000000..9d0f8f3a --- /dev/null +++ b/tools/ndptool/xdp/xdp_common.h @@ -0,0 +1,76 @@ +#ifndef XDP_COMMON_H +#define XDP_COMOD_H + +// libxdp +#include +#include +// IF_NAMESIZE +#include + +#include "../common.h" + +#define NUM_FRAMES 4096 + +struct xsk_info { + struct xsk_socket *xsk; + char ifname[IF_NAMESIZE]; + unsigned queue_id; + struct xsk_ring_cons rx_ring; + struct xsk_ring_prod tx_ring; + struct xsk_socket_config xsk_cfg; +}; + +struct umem_info { + struct xsk_umem *umem; + void *umem_area; + unsigned long long size; + struct xsk_ring_prod fill_ring; + struct xsk_ring_cons comp_ring; + struct xsk_umem_config umem_cfg; +}; + +struct ndp_mode_xdp_xsk_data { + int alive; + int eth_qid; + int nfb_qid; + char ifname[IF_NAMESIZE]; + struct umem_info umem_info; + struct xsk_info xsk_info; +}; + +struct addr_stack { + uint64_t addresses[NUM_FRAMES]; + unsigned addr_cnt; +}; + +// Get address from stack +static inline uint64_t alloc_addr(struct addr_stack *stack) { + if (stack->addr_cnt == 0) { + fprintf(stderr, "BUG out of adresses\n"); + exit(1); + } + uint64_t addr = stack->addresses[--stack->addr_cnt]; + stack->addresses[stack->addr_cnt] = 0; + return addr; +} + +// Put adress to stack +static inline void free_addr(struct addr_stack *stack, uint64_t address) { + if (stack->addr_cnt == NUM_FRAMES) { + fprintf(stderr, "BUG counting adresses\n"); + exit(1); + } + stack->addresses[stack->addr_cnt++] = address; +} + +// Fill the stack with addresses into the umem +static inline void init_addr(struct addr_stack *stack, unsigned frame_size) { + for(unsigned i = 0; i < NUM_FRAMES; i++) { + stack->addresses[i] = i * frame_size; + } + stack->addr_cnt = NUM_FRAMES; +} + +void xdp_mode_common_parse_queues(struct ndp_tool_params *p); + +#endif // XDP_COMMON_H \ No newline at end of file diff --git a/tools/ndptool/xdp/xdp_read.c b/tools/ndptool/xdp/xdp_read.c new file mode 100644 index 00000000..a6064e13 --- /dev/null +++ b/tools/ndptool/xdp/xdp_read.c @@ -0,0 +1,229 @@ +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "xdp_common.h" +#include "../pcap.h" + +#include +#include +#include // IF_NAMESIZE +#include + +static int xdp_mode_read_prepare(struct ndp_tool_params *p); +static int xdp_mode_read_loop(struct ndp_tool_params *p); +static int xdp_mode_read_exit(struct ndp_tool_params *p); + +int xdp_mode_read(struct ndp_tool_params *p) +{ + int ret; + + p->update_stats = update_stats; + + ret = xdp_mode_read_prepare(p); + if (ret) + return ret; + ret = xdp_mode_read_loop(p); + p->update_stats(0, 0, &p->si); + xdp_mode_read_exit(p); + return ret; +} + +int xdp_mode_read_check(struct ndp_tool_params *p) { + struct ndp_mode_xdp_params *params = &p->mode.xdp; + + uint32_t pagesize = getpagesize(); + int ret; + unsigned i; + + xdp_mode_common_parse_queues(p); + + // Create UMEM and XSK for each queue + for (i = 0; i < params->socket_cnt; i++) { + // Skip unopen queues + if(!params->queue_data_arr[i].alive) + continue; + + // UMEM + struct umem_info *uinfo = ¶ms->queue_data_arr[i].umem_info; + uinfo->size = NUM_FRAMES * pagesize; + uinfo->umem_cfg.comp_size = NUM_FRAMES; + uinfo->umem_cfg.fill_size = NUM_FRAMES; + uinfo->umem_cfg.flags = 0; + uinfo->umem_cfg.frame_headroom = 0; + uinfo->umem_cfg.frame_size = pagesize; + if(posix_memalign(&uinfo->umem_area, pagesize, uinfo->size)) { + fprintf(stderr, "Failed to get allocate umem buff for queue %d\n", params->queue_data_arr[i].eth_qid); + params->queue_data_arr[i].alive = false; + continue; + } + + if((ret = xsk_umem__create(&uinfo->umem, uinfo->umem_area, uinfo->size, &uinfo->fill_ring, &uinfo->comp_ring, &uinfo->umem_cfg))) { + fprintf(stderr, "Failed to create umem for queue %d; ret: %d\n", params->queue_data_arr[i].eth_qid, ret); + free(uinfo->umem_area); + params->queue_data_arr[i].alive = false; + continue; + } + + // XSK + struct xsk_info *xinfo = ¶ms->queue_data_arr[i].xsk_info; + xinfo->queue_id = params->queue_data_arr[i].eth_qid; + xinfo->xsk_cfg.rx_size = NUM_FRAMES; + xinfo->xsk_cfg.tx_size = NUM_FRAMES; + xinfo->xsk_cfg.bind_flags = XDP_ZEROCOPY; + + strcpy(xinfo->ifname, params->queue_data_arr[i].ifname); + if((ret = xsk_socket__create(&xinfo->xsk, xinfo->ifname, xinfo->queue_id, uinfo->umem, &xinfo->rx_ring, &xinfo->tx_ring, &xinfo->xsk_cfg))) { + fprintf(stderr, "Failed to create xsocket for queue %d; ret: %d\n", params->queue_data_arr[i].eth_qid, ret); + xsk_umem__delete(uinfo->umem); + free(uinfo->umem_area); + params->queue_data_arr[i].alive = false; + continue; + } + + params->queue_data_arr[i].alive = true; + } + return 0; +} + +void *xdp_mode_read_thread(void *tmp) +{ + struct thread_data *thread_data = (struct thread_data *)tmp; + struct ndp_tool_params *p = &thread_data->params; + + p->update_stats = update_stats_thread; + + thread_data->ret = xdp_mode_read_prepare(p); + if (thread_data->ret) { + thread_data->state = TS_FINISHED; + return NULL; + } + + thread_data->state = TS_RUNNING; + thread_data->ret = xdp_mode_read_loop(p); + p->update_stats(0, 0, &p->si); + xdp_mode_read_exit(p); + thread_data->state = TS_FINISHED; + + return NULL; +} + +static int xdp_mode_read_prepare(struct ndp_tool_params *p) +{ + p->si.progress_letter = 'R'; + gettimeofday(&p->si.startTime, NULL); + return 0; +} + +static int xdp_mode_read_exit(struct ndp_tool_params *p) +{ + gettimeofday(&p->si.endTime, NULL); + return 0; +} + +static int xdp_mode_read_loop(struct ndp_tool_params *p) +{ + unsigned cnt; + unsigned burst_size = RX_BURST; + + struct ndp_packet packets[burst_size]; + struct stats_info *si = &p->si; + update_stats_t update_stats = p->update_stats; + struct ndp_mode_xdp_params *params = &p->mode.xdp; + struct ndp_mode_xdp_xsk_data *xsk_data = NULL; + struct xsk_ring_prod *fill_ring; + struct xsk_ring_cons *rx_ring; + struct addr_stack stack; + + // Find socket data and check if socket is alive + for (unsigned i = 0; i < params->socket_cnt; i++) { + if(p->queue_index == params->queue_data_arr[i].nfb_qid) { + xsk_data = ¶ms->queue_data_arr[i]; + } + } + if(!xsk_data) { + fprintf(stderr,"Failed to match socket data for queue: %d\n", p->queue_index); + return -1; + } + if(!xsk_data->alive) { + fprintf(stderr,"Socket for queue: %d failed to initialize\n", p->queue_index); + return -1; + } + + // Clear length of packet header + for (unsigned i = 0; i < burst_size; i++) { + packets[i].flags = 0; + packets[i].header_length = 0; + } + + fill_ring = &xsk_data->umem_info.fill_ring; + rx_ring = &xsk_data->xsk_info.rx_ring; + + // Fill the adress stack with adresses into the umem + init_addr(&stack, xsk_data->umem_info.umem_cfg.frame_size); + + // The receive loop + while (!stop) { + // Fill RX + unsigned rx_idx = 0; + unsigned fill_idx = 0; + unsigned reservable = xsk_prod_nb_free(fill_ring, stack.addr_cnt); + reservable = reservable < stack.addr_cnt ? reservable : stack.addr_cnt; + if (reservable > burst_size) { + unsigned reserved = xsk_ring_prod__reserve(fill_ring, reservable, &fill_idx); + for(unsigned i = 0; i < reserved; i++) { + *xsk_ring_prod__fill_addr(fill_ring, fill_idx++) = alloc_addr(&stack); + } + xsk_ring_prod__submit(fill_ring, reserved); + } + + // Check limits if there is one (0 means loop forever) + if (p->limit_packets > 0) { + // Limit reached + if (si->packet_cnt == p->limit_packets) { + break; + } + // Limit will be reached in one burst + if (si->packet_cnt + burst_size > p->limit_packets) { + burst_size = p->limit_packets - si->packet_cnt; + } + } + if (p->limit_bytes > 0 && si->bytes_cnt > p->limit_bytes) { + break; + } + + // Receive packets + cnt = xsk_ring_cons__peek(rx_ring, burst_size, &rx_idx); + if (cnt == 0) { + if (p->use_delay_nsec) + delay_nsecs(1); + continue; + } + + // Process packets + for(unsigned i = 0; i < cnt; i++) { + struct xdp_desc const *desc = xsk_ring_cons__rx_desc(rx_ring, rx_idx++); + packets[i].data = xsk_umem__get_data(xsk_data->umem_info.umem_area, desc->addr); + packets[i].data_length = desc->len; + free_addr(&stack, desc->addr); + } + update_stats(packets, cnt, si); + + // Mark done + xsk_ring_cons__release(rx_ring, cnt); + } + + if(xsk_data->alive) { + xsk_socket__delete(xsk_data->xsk_info.xsk); + xsk_umem__delete(xsk_data->umem_info.umem); + free(xsk_data->umem_info.umem_area); + xsk_data->alive = false; + } + return 0; +} From d5251b6d954c996252da5df9d59f49c6b51f4d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 9 Apr 2025 08:36:32 +0200 Subject: [PATCH 348/518] feat(ndptool - add xdp-generate): add XDP equivalent of ndp-generate --- tools/CMakeLists.txt | 4 +- tools/ndptool/main.c | 3 +- tools/ndptool/modules.c | 21 ++ tools/ndptool/xdp/xdp_generate.c | 334 +++++++++++++++++++++++++++++++ 4 files changed, 359 insertions(+), 3 deletions(-) create mode 100644 tools/ndptool/xdp/xdp_generate.c diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f440b594..3905d0a9 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -55,7 +55,7 @@ add_executable(ndp-tool ndptool/common.c ndptool/generate.c ndptool/loopback.c ndptool/loopback_hw.c ndptool/main.c ndptool/modules.c ndptool/pcap.c ndptool/read.c ndptool/receive.c ndptool/stats.c ndptool/transmit.c - ndptool/xdp/xdp_common.c ndptool/xdp/xdp_read.c + ndptool/xdp/xdp_common.c ndptool/xdp/xdp_read.c ndptool/xdp/xdp_generate.c ) set (PIE_TARGETS nfb-info nfb-boot nfb-bus nfb-dma nfb-eth nfb-tsu nfb-mdio ndp-tool) @@ -72,7 +72,7 @@ target_link_libraries(ndp-tool PRIVATE ${NUMA_LIBRARIES} ${NCURSES_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${BPF_LIBRARIES} ${XDP_LIBRARIES} ) -set(NDP_TARGETS receive read transmit loopback loopback-hw generate xdp-read) +set(NDP_TARGETS receive read transmit loopback loopback-hw generate xdp-read xdp-generate) foreach(NDP_TARGET IN LISTS NDP_TARGETS) add_custom_target(ndp-${NDP_TARGET} ALL DEPENDS ndp-tool diff --git a/tools/ndptool/main.c b/tools/ndptool/main.c index efd7b383..1cb7ada7 100644 --- a/tools/ndptool/main.c +++ b/tools/ndptool/main.c @@ -289,7 +289,7 @@ int main(int argc, char *argv[]) params.mode.dpdk.queue_range = queue_range; } #endif // USE_DPDK - if (mode == XDP_MODULE_READ) + if (mode == XDP_MODULE_READ || mode == XDP_MODULE_GENERATE) params.mode.xdp.queue_range = queue_range; if (module->check) @@ -325,6 +325,7 @@ int main(int argc, char *argv[]) break; case NDP_MODULE_GENERATE: case NDP_MODULE_TRANSMIT: + case XDP_MODULE_GENERATE: #ifdef USE_DPDK case DPDK_MODULE_GENERATE: case DPDK_MODULE_TRANSMIT: diff --git a/tools/ndptool/modules.c b/tools/ndptool/modules.c index b4bc0654..d226acda 100644 --- a/tools/ndptool/modules.c +++ b/tools/ndptool/modules.c @@ -94,6 +94,14 @@ int xdp_mode_read(struct ndp_tool_params *p); int xdp_mode_read_check(struct ndp_tool_params *p); void *xdp_mode_read_thread(void *tmp); +int xdp_mode_generate_init(struct ndp_tool_params *p); +void xdp_mode_generate_print_help(void); +int xdp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); +int xdp_mode_generate_check(struct ndp_tool_params *p); +int xdp_mode_generate(struct ndp_tool_params *p); +void *xdp_mode_generate_thread(void *tmp); +void xdp_mode_generate_destroy(struct ndp_tool_params *p); + struct option long_options_speed[] = { {"speed", required_argument, 0, 0}, {0, 0, 0, 0}, @@ -171,6 +179,19 @@ struct ndptool_module modules[] = { .run_single = xdp_mode_read, .run_thread = xdp_mode_read_thread, }, + [XDP_MODULE_GENERATE] = { + .name = "xdp-generate", + .short_help = "Generate packets using XDP", + .print_help = xdp_mode_generate_print_help, + .init = xdp_mode_generate_init, + .args = "s:C", + .parse_opt = xdp_mode_generate_parseopt, + .check = xdp_mode_generate_check, + .run_single = xdp_mode_generate, + .run_thread = xdp_mode_generate_thread, + .destroy = xdp_mode_generate_destroy, + .long_options = long_options_speed, + }, #ifdef USE_DPDK [DPDK_MODULE_GENERATE] = { .name = "dpdk-generate", diff --git a/tools/ndptool/xdp/xdp_generate.c b/tools/ndptool/xdp/xdp_generate.c new file mode 100644 index 00000000..1108b92c --- /dev/null +++ b/tools/ndptool/xdp/xdp_generate.c @@ -0,0 +1,334 @@ +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "xdp_common.h" + +static int xdp_mode_generate_prepare(struct ndp_tool_params *p); +static int xdp_mode_generate_loop(struct ndp_tool_params *p); +static int xdp_mode_generate_exit(struct ndp_tool_params *p); + +int xdp_mode_generate(struct ndp_tool_params *p) +{ + int ret; + + p->update_stats = update_stats; + + ret = xdp_mode_generate_prepare(p); + if (ret) + return ret; + ret = xdp_mode_generate_loop(p); + xdp_mode_generate_exit(p); + return ret; +} + +void *xdp_mode_generate_thread(void *tmp) +{ + struct thread_data *thread_data = (struct thread_data *)tmp; + struct ndp_tool_params *p = &thread_data->params; + + p->update_stats = update_stats_thread; + + thread_data->ret = xdp_mode_generate_prepare(p); + if (thread_data->ret) { + thread_data->state = TS_FINISHED; + return NULL; + } + + thread_data->state = TS_RUNNING; + thread_data->ret = xdp_mode_generate_loop(p); + p->update_stats(0, 0, &p->si); + xdp_mode_generate_exit(p); + thread_data->state = TS_FINISHED; + + return NULL; +} + +static int xdp_mode_generate_prepare(struct ndp_tool_params *p) +{ + p->si.progress_letter = 'G'; + gettimeofday(&p->si.startTime, NULL); + + return 0; +} + +static int xdp_mode_generate_exit(struct ndp_tool_params *p) +{ + gettimeofday(&p->si.endTime, NULL); + return 0; +} + +static int xdp_mode_generate_loop(struct ndp_tool_params *p) +{ + unsigned burst_size = TX_BURST; + struct ndp_packet packets[burst_size]; + struct stats_info *si = &p->si; + update_stats_t update_stats = p->update_stats; + struct ndp_mode_xdp_params *params = &p->mode.xdp; + struct ndp_mode_xdp_xsk_data *xsk_data = NULL; + struct xsk_ring_cons *comp_ring; + struct xsk_ring_prod *tx_ring; + struct addr_stack stack; + + int gen_index = 0; + + unsigned long long bytes_cnt = 0; + unsigned long long packets_rem = p->limit_packets; + + const bool clear_data = p->mode.xdp.generate.clear_data; + const bool limit_bytes = p->limit_bytes > 0 ? true : false; + const bool limit_packets = p->limit_packets > 0 ? true : false; + + + // Clear length of packet header + for (unsigned i = 0; i < burst_size; i++) { + packets[i].flags = 0; + packets[i].header_length = 0; + } + + // OPT: Set the constant values in packet for one packet length + if (p->mode.xdp.generate.range.items == 1 && p->mode.xdp.generate.range.max[0] == 0) { + gen_index = -1; + for (unsigned i = 0; i < burst_size; i++) { + packets[i].data_length = p->mode.xdp.generate.range.min[0]; + } + } + + // find socket data and check if socket is alive + for (unsigned i = 0; i < params->socket_cnt; i++) { + if(p->queue_index == params->queue_data_arr[i].nfb_qid) { + xsk_data = ¶ms->queue_data_arr[i]; + } + } + if(!xsk_data) { + fprintf(stderr,"Failed to match socket data for queue: %d\n", p->queue_index); + return -1; + } + if(!xsk_data->alive) { + fprintf(stderr,"Socket for queue: %d failed to initialize\n", p->queue_index); + return -1; + } + comp_ring = &xsk_data->umem_info.comp_ring; + tx_ring = &xsk_data->xsk_info.tx_ring; + + // Fill the address stack with addresses into the umem + init_addr(&stack, xsk_data->umem_info.umem_cfg.frame_size); + + while (!stop) { + if (limit_packets > 0) { + // Packet limit was reached in previous burst + if (packets_rem == 0) { + break; + } + // Packet limit will be reached in one burst + if (packets_rem < burst_size) { + burst_size = packets_rem; + } + } + + if (limit_bytes > 0) { + if (bytes_cnt >= p->limit_bytes) { + break; + } + } + + // Fill parameters for packets to send + if (gen_index != -1) { + for (unsigned i = 0; i < burst_size; i++) { + packets[i].data_length = p->mode.xdp.generate.range.min[gen_index]; + if (p->mode.xdp.generate.range.max[gen_index]) + packets[i].data_length += nc_fast_rand(&p->mode.xdp.generate.srand) % p->mode.xdp.generate.range.max[gen_index]; + if ((unsigned) ++gen_index == p->mode.xdp.generate.range.items) + gen_index = 0; + } + } + + unsigned idx_tx = 0; + unsigned collected; + unsigned cnt; + // Collect sent buffers + do { + collected = xsk_ring_cons__peek(comp_ring, burst_size, &idx_tx); + for (unsigned i = 0; i < collected; i++) { + free_addr(&stack, *xsk_ring_cons__comp_addr(comp_ring, idx_tx++)); + } + xsk_ring_cons__release(comp_ring, collected); + } while(collected || stack.addr_cnt < burst_size); + + // Reserve descriptors + cnt = xsk_ring_prod__reserve(tx_ring, burst_size, &idx_tx); + while (cnt != burst_size) { + if (stop) + return 0; + delay_nsecs(1); + cnt = xsk_ring_prod__reserve(tx_ring, burst_size, &idx_tx); + } + + // Fill the descriptors + for (unsigned i = 0; i < burst_size; i++) { + uint64_t addr = alloc_addr(&stack); + struct xdp_desc *desc = xsk_ring_prod__tx_desc(tx_ring, idx_tx++); + // fill the xdp desc + desc->addr = addr; + desc->len = packets[i].data_length; + void *data = xsk_umem__get_data(xsk_data->umem_info.umem_area, desc->addr); + // update the packets structure for compatibility with ndptool + packets[i].data = data; + } + if (clear_data) { + for (unsigned i = 0; i < cnt; i++) { + memset(packets[i].data, 0, packets[i].data_length); + } + } + + // Update limits + packets_rem -= cnt; + if (limit_bytes) { + for (unsigned i = 0; i < cnt; i++) { + bytes_cnt += packets[i].data_length; + } + } + + // Update stats + update_stats(packets, cnt, si); + + // Release packet descriptors + xsk_ring_prod__submit(tx_ring, cnt); + } + + if(xsk_data->alive) { + xsk_socket__delete(xsk_data->xsk_info.xsk); + xsk_umem__delete(xsk_data->umem_info.umem); + free(xsk_data->umem_info.umem_area); + xsk_data->alive = false; + } + return 0; +} + +int xdp_mode_generate_init(struct ndp_tool_params *p) +{ + list_range_init(&p->mode.xdp.generate.range); + p->mode.xdp.generate.mbps = 0; + return 0; +} + +void xdp_mode_generate_print_help() +{ + printf("Generate parameters:\n"); + printf(" -s size Packet size - list or random from range, e.g \"64,128-256\"\n"); + printf(" -C Clear packet data before send\n"); + printf(" --speed Mbps Replay packets at a given speed\n"); +} + +int xdp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, + int option_index) +{ + switch (opt) { + case 0: + if (!strcmp(module->long_options[option_index].name, "speed")) { + if (nc_strtoull(optarg, &p->mode.xdp.generate.mbps)) + errx(-1, "Cannot parse --speed parameter"); + } else { + errx(-1, "Unknown long option"); + } + break; + case 's': + if (list_range_parse(&p->mode.xdp.generate.range, optarg) < 0) + errx(-1, "Cannot parse size range"); + break; + case 'C': + p->mode.xdp.generate.clear_data = 1; + break; + case 'S': + if (nc_strtoull(optarg, &p->mode.xdp.generate.mbps)) + errx(-1, "Cannot parse mbps parameter"); + break; + default: + return -1; + } + return 0; +} + +int xdp_mode_generate_check(struct ndp_tool_params *p) +{ + struct ndp_mode_xdp_params *params = &p->mode.xdp; + + uint32_t pagesize = getpagesize(); + int ret; + unsigned i; + // Compatibility params + if (list_range_empty(&p->mode.xdp.generate.range)) { + errx(-1, "Unspecified size parameter"); + } + + // Convert random ranges from [min, max] to [min, delta + 1] + // So that min + rand(seed) % (delta + 1) randomizes the lengths + for (i = 0; i < p->mode.xdp.generate.range.items; i++) { + p->mode.xdp.generate.range.max[i] -= p->mode.xdp.generate.range.min[i]; + if (p->mode.xdp.generate.range.max[i]) + p->mode.xdp.generate.range.max[i]++; + } + + xdp_mode_common_parse_queues(p); + + // create UMEM and XSK for each queue + for (i = 0; i < params->socket_cnt; i++) { + // Skip unopen queues + if(!params->queue_data_arr[i].alive) + continue; + + // UMEM + struct umem_info *uinfo = ¶ms->queue_data_arr[i].umem_info; + uinfo->size = NUM_FRAMES * pagesize; + uinfo->umem_cfg.comp_size = NUM_FRAMES; + uinfo->umem_cfg.fill_size = NUM_FRAMES; + uinfo->umem_cfg.flags = 0; + uinfo->umem_cfg.frame_headroom = 0; + uinfo->umem_cfg.frame_size = pagesize; + + if(posix_memalign(&uinfo->umem_area, pagesize, uinfo->size)) { + fprintf(stderr, "Failed to get allocate umem buff for queue %d\n", params->queue_data_arr[i].eth_qid); + params->queue_data_arr[i].alive = false; + continue; + } + + if((ret = xsk_umem__create(&uinfo->umem, uinfo->umem_area, uinfo->size, &uinfo->fill_ring, &uinfo->comp_ring, &uinfo->umem_cfg))) { + fprintf(stderr, "Failed to create umem for queue %d; ret: %d\n", params->queue_data_arr[i].eth_qid, ret); + free(uinfo->umem_area); + params->queue_data_arr[i].alive = false; + continue; + } + + // XSK + struct xsk_info *xinfo = ¶ms->queue_data_arr[i].xsk_info; + xinfo->queue_id = params->queue_data_arr[i].eth_qid; + xinfo->xsk_cfg.rx_size = NUM_FRAMES; + xinfo->xsk_cfg.tx_size = NUM_FRAMES; + xinfo->xsk_cfg.bind_flags = XDP_ZEROCOPY; + // xinfo->xsk_cfg.bind_flags |= XDP_USE_NEED_WAKEUP; + xinfo->xsk_cfg.libxdp_flags = XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD; + + strcpy(xinfo->ifname, params->queue_data_arr[i].ifname); + if((ret = xsk_socket__create(&xinfo->xsk, xinfo->ifname, xinfo->queue_id, uinfo->umem, &xinfo->rx_ring, &xinfo->tx_ring, &xinfo->xsk_cfg))) { + fprintf(stderr, "Failed to create xsocket for queue %d; ret: %d\n", params->queue_data_arr[i].eth_qid, ret); + xsk_umem__delete(uinfo->umem); + free(uinfo->umem_area); + params->queue_data_arr[i].alive = false; + continue; + } + + params->queue_data_arr[i].alive = true; + } + return 0; +} + +void xdp_mode_generate_destroy(struct ndp_tool_params *p) +{ + list_range_destroy(&p->mode.xdp.generate.range); +} From 5c761ef50f94a695c03db94c5238831ada2ad5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 9 Apr 2025 14:34:07 +0200 Subject: [PATCH 349/518] feat(ndptool - make XDP compilation optional): Introduce USE_XDP to work alongside USE_DPDK for optional compilation of ndptool --- CMakeLists.txt | 14 +++++++++ build.sh | 50 +++++++++++++++++++++++++++++ tools/CMakeLists.txt | 59 +++++++++++++++++++++++++++++----- tools/ndptool/common.h | 6 ++-- tools/ndptool/main.c | 10 ++++-- tools/ndptool/modules.c | 70 ++++++++++++++++++++++------------------- 6 files changed, 164 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d847a69..5323cbbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,8 @@ set(DEB_PYTHON_DEP_LIST # Common package settings if(USE_DPDK) set(CPACK_PACKAGE_NAME "temp-${PROJECT_NAME}+ndp_tools_dpdk") +elseif(USE_XDP) + set(CPACK_PACKAGE_NAME "temp-${PROJECT_NAME}+ndp_tools_xdp") else() set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") endif() @@ -126,6 +128,12 @@ if(USE_DPDK) set (CPACK_RPM_SOURCE_PKG_BUILD_PARAMS "-DUSE_DPDK=true") endif() +if(USE_XDP) + set(CPACK_RPM_ndp-tool-xdp_PACKAGE_NAME "ndp-tool-xdp") + set(CPACK_RPM_ndp-tool-xdp_PACKAGE_REQUIRES "nfb-framework, libxdp, libbpf") + set (CPACK_RPM_SOURCE_PKG_BUILD_PARAMS "-DUSE_XDP=true") +endif() + set(CPACK_RPM_Main_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/preinst") set(CPACK_RPM_Main_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/prerm") set(CPACK_RPM_Main_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/postinst") @@ -150,6 +158,12 @@ set(CPACK_DEBIAN_PYTHON_FILE_NAME "python3-nfb-${CPACK_DEBIAN_PACKAGE_VERSION}-$ string(JOIN ", " CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEP_LIST}) string(JOIN ", " CPACK_DEBIAN_PYTHON_PACKAGE_DEPENDS ${DEB_PYTHON_DEP_LIST}) +if(USE_XDP) + set(CPACK_DEBIAN_NDP-TOOL-XDP_PACKAGE_NAME "ndp-tool-xdp") + set(CPACK_DEBIAN_NDP-TOOL-XDP_FILE_NAME "ndp-tool-xdp-${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}.deb") + set(CPACK_DEBIAN_NDP-TOOL-XDP_PACKAGE_DEPENDS "nfb-framework, libxdp1, libbpf1") +endif() + include(python/nfb-tools/nfb-tools.cmake) set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS "../${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}/${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") diff --git a/build.sh b/build.sh index a88e49e6..10b0df6e 100755 --- a/build.sh +++ b/build.sh @@ -220,6 +220,22 @@ get_dpdk_dependencies() fi } +get_xdp_dependencies() +{ + os=$(get_os_id) + os_version=$(get_os_version) + os_number=$(get_os_number) + ret="" + if item_in_list "$os" "ubuntu"; then + ret="$ret libbpf-dev" + ret="$ret libxdp-dev" + elif item_in_list "$os" "centos scientific fedora ol rocky"; then + ret="$ret libbpf-devel" + ret="$ret libxdp-devel" + fi + echo $ret +} + get_3rdparty_code() { curl -L $URL_3RDPARTY --output $FILENAME_3RDPARTY @@ -261,6 +277,15 @@ Build_dpdk() $make_command } +Build_xdp() +{ + try_get_3rdparty_code + mkdir -p "$SCRIPT_PATH/$BUILDDIR" + cd "$SCRIPT_PATH/$BUILDDIR" + $cmake -DCMAKE_BUILD_TYPE=$RELTYPE -DUSE_XDP=true .. + $make_command +} + # ----[ MAIN function ]------------------------------------------------------- # cmake=cmake @@ -308,6 +333,12 @@ for opt in "$@"; do echo ">> Installing package build dependencies ..." $install_cmd $deps ;; + --bootstrap-xdp) + install_cmd=$(get_install_command) + deps=$(get_xdp_dependencies) + echo ">> Installing package build dependencies ..." + $install_cmd $deps + ;; --prepare) echo ">> Downloading and extractiong 3rd party code ..." get_3rdparty_code @@ -318,6 +349,9 @@ for opt in "$@"; do --make-dpdk) Build_dpdk ;; + --make-xdp) + Build_xdp + ;; --clean) cd "$SCRIPT_PATH/$BUILDDIR" || continue make clean @@ -340,6 +374,14 @@ for opt in "$@"; do fi Build_dpdk $cpack -G RPM --config ./CPackConfig.cmake + ;; + --rpm-xdp) + if ! item_in_list "$os" "centos scientific fedora ol rocky"; then + echo >&2 "ERROR: Cannot build RPM package on other OS than CentOS" + exit 1 + fi + Build_xdp + $cpack -G RPM --config ./CPackConfig.cmake ;; --deb) if [ "$os" != "ubuntu" ]; then @@ -349,5 +391,13 @@ for opt in "$@"; do Build $cpack -G DEB --config ./CPackConfig.cmake ;; + --deb-xdp) + if [ "$os" != "ubuntu" ]; then + echo >&2 "ERROR: Cannot build DEB package on other OS than Ubuntu" + exit 1 + fi + Build_xdp + $cpack -G DEB --config ./CPackConfig.cmake + ;; esac done diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 3905d0a9..74e1b847 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -23,8 +23,6 @@ find_package(PkgConfig) pkg_check_modules(NCURSES REQUIRED ncurses) pkg_check_modules(ARCHIVE REQUIRED libarchive) -pkg_check_modules(XDP REQUIRED libxdp) -pkg_check_modules(BPF REQUIRED libbpf) ndk_check_build_dependency(FDT_LIBRARIES fdt FDT_INCLUDE_DIRS libfdt.h libfdt) ndk_check_build_dependency(NUMA_LIBRARIES numa NUMA_INCLUDE_DIRS numa.h) @@ -54,9 +52,7 @@ add_executable(nfb-mdio mdio/mdio.c) add_executable(ndp-tool ndptool/common.c ndptool/generate.c ndptool/loopback.c ndptool/loopback_hw.c ndptool/main.c ndptool/modules.c ndptool/pcap.c - ndptool/read.c ndptool/receive.c ndptool/stats.c ndptool/transmit.c - ndptool/xdp/xdp_common.c ndptool/xdp/xdp_read.c ndptool/xdp/xdp_generate.c -) + ndptool/read.c ndptool/receive.c ndptool/stats.c ndptool/transmit.c) set (PIE_TARGETS nfb-info nfb-boot nfb-bus nfb-dma nfb-eth nfb-tsu nfb-mdio ndp-tool) foreach(PIE_TARGET IN LISTS PIE_TARGETS) @@ -68,11 +64,12 @@ target_link_libraries(nfb-boot ) target_compile_options(ndp-tool PRIVATE -O3 -funroll-loops) + target_link_libraries(ndp-tool - PRIVATE ${NUMA_LIBRARIES} ${NCURSES_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${BPF_LIBRARIES} ${XDP_LIBRARIES} -) + PRIVATE ${NUMA_LIBRARIES} ${NCURSES_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + +set(NDP_TARGETS receive read transmit loopback loopback-hw generate) -set(NDP_TARGETS receive read transmit loopback loopback-hw generate xdp-read xdp-generate) foreach(NDP_TARGET IN LISTS NDP_TARGETS) add_custom_target(ndp-${NDP_TARGET} ALL DEPENDS ndp-tool @@ -137,3 +134,49 @@ if(USE_DPDK) else() message("ndp-tool: DPDK portion of the app not enabled use -DUSE_DPDK=true with cmake if you want to compile with DPDK") endif() + +if(USE_XDP) + message("ndp-tool: XDP portion of the app is enabled use -UUSE_XDP with cmake if you don't want to compile with XDP") + pkg_check_modules(XDP REQUIRED libxdp) + pkg_check_modules(BPF REQUIRED libbpf) + + add_executable(ndp-tool-xdp + ndptool/common.c ndptool/generate.c ndptool/loopback.c + ndptool/loopback_hw.c ndptool/main.c ndptool/modules.c ndptool/pcap.c + ndptool/read.c ndptool/receive.c ndptool/stats.c ndptool/transmit.c + ndptool/xdp/xdp_common.c ndptool/xdp/xdp_read.c ndptool/xdp/xdp_generate.c + ) + + set_property(TARGET ndp-tool-xdp PROPERTY POSITION_INDEPENDENT_CODE TRUE) + + set(XDP_TARGETS xdp-generate xdp-read) + + target_compile_options(ndp-tool-xdp PRIVATE -O3 -funroll-loops) + target_link_libraries(ndp-tool-xdp + PRIVATE ${NUMA_LIBRARIES} ${NCURSES_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${BPF_LIBRARIES} ${XDP_LIBRARIES} + ) + target_compile_definitions(ndp-tool-xdp PRIVATE USE_XDP) + + foreach(XDP_TARGET IN LISTS XDP_TARGETS) + add_custom_target(ndp-${XDP_TARGET} + ALL DEPENDS ndp-tool-xdp + COMMAND ${CMAKE_COMMAND} -E create_symlink ndp-tool-xdp ndp-${XDP_TARGET} + ) + endforeach() + + install( + TARGETS ndp-tool-xdp + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ndp-tool-xdp + ) + + foreach(XDP_TARGET IN LISTS XDP_TARGETS) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/ndp-${XDP_TARGET} + DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ndp-tool-xdp + ) + endforeach() +else() + message("ndp-tool: XDP portion of the app not enabled use -DUSE_XDP=true with cmake if you want to compile with XDP") +endif() diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index cbe33b47..59d9aad8 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -239,14 +239,16 @@ enum ndp_modules { NDP_MODULE_TRANSMIT, NDP_MODULE_LOOPBACK, NDP_MODULE_LOOPBACK_HW, - XDP_MODULE_READ, - XDP_MODULE_GENERATE, #ifdef USE_DPDK DPDK_MODULE_GENERATE, DPDK_MODULE_READ, DPDK_MODULE_LOOPBACK, DPDK_MODULE_RECEIVE, DPDK_MODULE_TRANSMIT, +#endif +#ifdef USE_XDP + XDP_MODULE_READ, + XDP_MODULE_GENERATE, #endif /* NONE module must be last! */ NDP_MODULE_NONE, diff --git a/tools/ndptool/main.c b/tools/ndptool/main.c index 1cb7ada7..e9f5cb2b 100644 --- a/tools/ndptool/main.c +++ b/tools/ndptool/main.c @@ -289,8 +289,10 @@ int main(int argc, char *argv[]) params.mode.dpdk.queue_range = queue_range; } #endif // USE_DPDK +#ifdef USE_XDP if (mode == XDP_MODULE_READ || mode == XDP_MODULE_GENERATE) params.mode.xdp.queue_range = queue_range; +#endif // USE_XDP if (module->check) ret = module->check(¶ms); @@ -315,21 +317,25 @@ int main(int argc, char *argv[]) switch (mode) { case NDP_MODULE_READ: case NDP_MODULE_RECEIVE: - case XDP_MODULE_READ: #ifdef USE_DPDK case DPDK_MODULE_READ: case DPDK_MODULE_RECEIVE: #endif // USE_DPDK +#ifdef USE_XDP + case XDP_MODULE_READ: +#endif // USE_XDP if (ndp_rx_queue_is_available(dev, i)) list_range_add_number(&queue_range, i); break; case NDP_MODULE_GENERATE: case NDP_MODULE_TRANSMIT: - case XDP_MODULE_GENERATE: #ifdef USE_DPDK case DPDK_MODULE_GENERATE: case DPDK_MODULE_TRANSMIT: #endif // USE_DPDK +#ifdef USE_XDP + case XDP_MODULE_GENERATE: +#endif // USE_XDP if (ndp_tx_queue_is_available(dev, i)) list_range_add_number(&queue_range, i); break; diff --git a/tools/ndptool/modules.c b/tools/ndptool/modules.c index d226acda..22d205a3 100644 --- a/tools/ndptool/modules.c +++ b/tools/ndptool/modules.c @@ -51,6 +51,20 @@ void *dpdk_transmit_run_thread(void *tmp); void dpdk_transmit_print_help(); #endif // USE_DPDK +#ifdef USE_XDP +int xdp_mode_read(struct ndp_tool_params *p); +int xdp_mode_read_check(struct ndp_tool_params *p); +void *xdp_mode_read_thread(void *tmp); + +int xdp_mode_generate_init(struct ndp_tool_params *p); +void xdp_mode_generate_print_help(void); +int xdp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); +int xdp_mode_generate_check(struct ndp_tool_params *p); +int xdp_mode_generate(struct ndp_tool_params *p); +void *xdp_mode_generate_thread(void *tmp); +void xdp_mode_generate_destroy(struct ndp_tool_params *p); +#endif // USE_XDP + int ndp_mode_generate_init(struct ndp_tool_params *p); int ndp_mode_receive_init(struct ndp_tool_params *p); int ndp_mode_transmit_init(struct ndp_tool_params *p); @@ -90,18 +104,6 @@ void *ndp_mode_loopback_hw_thread(void *tmp); void ndp_mode_generate_destroy(struct ndp_tool_params *p); void ndp_mode_loopback_hw_destroy(struct ndp_tool_params *p); -int xdp_mode_read(struct ndp_tool_params *p); -int xdp_mode_read_check(struct ndp_tool_params *p); -void *xdp_mode_read_thread(void *tmp); - -int xdp_mode_generate_init(struct ndp_tool_params *p); -void xdp_mode_generate_print_help(void); -int xdp_mode_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); -int xdp_mode_generate_check(struct ndp_tool_params *p); -int xdp_mode_generate(struct ndp_tool_params *p); -void *xdp_mode_generate_thread(void *tmp); -void xdp_mode_generate_destroy(struct ndp_tool_params *p); - struct option long_options_speed[] = { {"speed", required_argument, 0, 0}, {0, 0, 0, 0}, @@ -171,27 +173,6 @@ struct ndptool_module modules[] = { .destroy = ndp_mode_loopback_hw_destroy, .flags = 0, }, - [XDP_MODULE_READ] = { - .name = "xdp-read", - .short_help = "Read packets using XDP", - .args = "", - .check = xdp_mode_read_check, - .run_single = xdp_mode_read, - .run_thread = xdp_mode_read_thread, - }, - [XDP_MODULE_GENERATE] = { - .name = "xdp-generate", - .short_help = "Generate packets using XDP", - .print_help = xdp_mode_generate_print_help, - .init = xdp_mode_generate_init, - .args = "s:C", - .parse_opt = xdp_mode_generate_parseopt, - .check = xdp_mode_generate_check, - .run_single = xdp_mode_generate, - .run_thread = xdp_mode_generate_thread, - .destroy = xdp_mode_generate_destroy, - .long_options = long_options_speed, - }, #ifdef USE_DPDK [DPDK_MODULE_GENERATE] = { .name = "dpdk-generate", @@ -254,6 +235,29 @@ struct ndptool_module modules[] = { .destroy = dpdk_transmit_destroy, }, #endif // USE_DPDK +#ifdef USE_XDP + [XDP_MODULE_READ] = { + .name = "xdp-read", + .short_help = "Read packets using XDP", + .args = "", + .check = xdp_mode_read_check, + .run_single = xdp_mode_read, + .run_thread = xdp_mode_read_thread, + }, + [XDP_MODULE_GENERATE] = { + .name = "xdp-generate", + .short_help = "Generate packets using XDP", + .print_help = xdp_mode_generate_print_help, + .init = xdp_mode_generate_init, + .args = "s:C", + .parse_opt = xdp_mode_generate_parseopt, + .check = xdp_mode_generate_check, + .run_single = xdp_mode_generate, + .run_thread = xdp_mode_generate_thread, + .destroy = xdp_mode_generate_destroy, + .long_options = long_options_speed, + }, +#endif // USE_XDP [NDP_MODULE_NONE] = { .name = NULL, }, From b4b8409b1389d0532dc7441a3be32277a23bce17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 9 Apr 2025 14:44:45 +0200 Subject: [PATCH 350/518] fix(ndptool DPDK missing parameter): fix ndptool-dpdk module parseopt funcions missing parameter that was added in 228aba23 --- tools/ndptool/dpdk/dpdk_generate.c | 3 ++- tools/ndptool/dpdk/dpdk_loopback.c | 3 ++- tools/ndptool/dpdk/dpdk_read.c | 3 ++- tools/ndptool/dpdk/dpdk_receive.c | 3 ++- tools/ndptool/dpdk/dpdk_transmit.c | 3 ++- tools/ndptool/modules.c | 10 +++++----- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/ndptool/dpdk/dpdk_generate.c b/tools/ndptool/dpdk/dpdk_generate.c index bd4b656e..ca32512d 100644 --- a/tools/ndptool/dpdk/dpdk_generate.c +++ b/tools/ndptool/dpdk/dpdk_generate.c @@ -567,7 +567,8 @@ void dpdk_generate_destroy(struct ndp_tool_params *p) } -int dpdk_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg) +int dpdk_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, + int option_index __attribute__((unused))) { wordexp_t *args = &p->mode.dpdk.args; diff --git a/tools/ndptool/dpdk/dpdk_loopback.c b/tools/ndptool/dpdk/dpdk_loopback.c index 6540f463..81fe42f3 100644 --- a/tools/ndptool/dpdk/dpdk_loopback.c +++ b/tools/ndptool/dpdk/dpdk_loopback.c @@ -545,7 +545,8 @@ void dpdk_loopback_destroy(struct ndp_tool_params *p) rte_eal_cleanup(); } -int dpdk_loopback_parseopt(struct ndp_tool_params *p, int opt, char *optarg) +int dpdk_loopback_parseopt(struct ndp_tool_params *p, int opt, char *optarg, + int option_index __attribute__((unused))) { wordexp_t *args = &p->mode.dpdk.args; diff --git a/tools/ndptool/dpdk/dpdk_read.c b/tools/ndptool/dpdk/dpdk_read.c index b9d2bbd8..a5381826 100644 --- a/tools/ndptool/dpdk/dpdk_read.c +++ b/tools/ndptool/dpdk/dpdk_read.c @@ -516,7 +516,8 @@ void dpdk_read_destroy(struct ndp_tool_params *p) rte_eal_cleanup(); } -int dpdk_read_parseopt(struct ndp_tool_params *p, int opt, char *optarg) +int dpdk_read_parseopt(struct ndp_tool_params *p, int opt, char *optarg, + int option_index __attribute__((unused))) { wordexp_t *args = &p->mode.dpdk.args; diff --git a/tools/ndptool/dpdk/dpdk_receive.c b/tools/ndptool/dpdk/dpdk_receive.c index 68063948..4079ce68 100644 --- a/tools/ndptool/dpdk/dpdk_receive.c +++ b/tools/ndptool/dpdk/dpdk_receive.c @@ -561,7 +561,8 @@ void dpdk_receive_destroy(struct ndp_tool_params *p) rte_eal_cleanup(); } -int dpdk_receive_parseopt(struct ndp_tool_params *p, int opt, char *optarg) +int dpdk_receive_parseopt(struct ndp_tool_params *p, int opt, char *optarg, + int option_index __attribute__((unused))) { wordexp_t *args = &p->mode.dpdk.args; diff --git a/tools/ndptool/dpdk/dpdk_transmit.c b/tools/ndptool/dpdk/dpdk_transmit.c index d2b549ae..cddc88ec 100644 --- a/tools/ndptool/dpdk/dpdk_transmit.c +++ b/tools/ndptool/dpdk/dpdk_transmit.c @@ -628,7 +628,8 @@ void dpdk_transmit_destroy(struct ndp_tool_params *p) rte_eal_cleanup(); } -int dpdk_transmit_parseopt(struct ndp_tool_params *p, int opt, char *optarg) +int dpdk_transmit_parseopt(struct ndp_tool_params *p, int opt, char *optarg, + int option_index __attribute__((unused))) { wordexp_t *args = &p->mode.dpdk.args; diff --git a/tools/ndptool/modules.c b/tools/ndptool/modules.c index 22d205a3..ada8936c 100644 --- a/tools/ndptool/modules.c +++ b/tools/ndptool/modules.c @@ -12,7 +12,7 @@ #ifdef USE_DPDK int dpdk_generate_init(struct ndp_tool_params *p); int dpdk_generate_check(struct ndp_tool_params *p); -int dpdk_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg); +int dpdk_generate_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); int dpdk_generate_run_single(struct ndp_tool_params *p); void dpdk_generate_destroy(struct ndp_tool_params *p); void *dpdk_generate_run_thread(void *tmp); @@ -20,7 +20,7 @@ void dpdk_generate_print_help(); int dpdk_read_init(struct ndp_tool_params *p); int dpdk_read_check(struct ndp_tool_params *p); -int dpdk_read_parseopt(struct ndp_tool_params *p, int opt, char *optarg); +int dpdk_read_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); int dpdk_read_run_single(struct ndp_tool_params *p); void dpdk_read_destroy(struct ndp_tool_params *p); void *dpdk_read_run_thread(void *tmp); @@ -28,7 +28,7 @@ void dpdk_read_print_help(); int dpdk_loopback_init(struct ndp_tool_params *p); int dpdk_loopback_check(struct ndp_tool_params *p); -int dpdk_loopback_parseopt(struct ndp_tool_params *p, int opt, char *optarg); +int dpdk_loopback_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); int dpdk_loopback_run_single(struct ndp_tool_params *p); void dpdk_loopback_destroy(struct ndp_tool_params *p); void *dpdk_loopback_run_thread(void *tmp); @@ -36,7 +36,7 @@ void dpdk_loopback_print_help(); int dpdk_receive_init(struct ndp_tool_params *p); int dpdk_receive_check(struct ndp_tool_params *p); -int dpdk_receive_parseopt(struct ndp_tool_params *p, int opt, char *optarg); +int dpdk_receive_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); int dpdk_receive_run_single(struct ndp_tool_params *p); void dpdk_receive_destroy(struct ndp_tool_params *p); void *dpdk_receive_run_thread(void *tmp); @@ -44,7 +44,7 @@ void dpdk_receive_print_help(); int dpdk_transmit_init(struct ndp_tool_params *p); int dpdk_transmit_check(struct ndp_tool_params *p); -int dpdk_transmit_parseopt(struct ndp_tool_params *p, int opt, char *optarg); +int dpdk_transmit_parseopt(struct ndp_tool_params *p, int opt, char *optarg, int option_index); int dpdk_transmit_run_single(struct ndp_tool_params *p); void dpdk_transmit_destroy(struct ndp_tool_params *p); void *dpdk_transmit_run_thread(void *tmp); From 11b7acfecdaaed43ca052d48ea68c99924328372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Thu, 10 Apr 2025 10:50:33 +0200 Subject: [PATCH 351/518] feat(ndptool - xdp): Add xdp package to Jenkins pipeline --- jenkins/Jenkinsfile | 28 ++++++++++++++++++- ...ntu.Dockerfile => ubuntu_jammy.Dockerfile} | 0 jenkins/ubuntu_noble.Dockerfile | 13 +++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) rename jenkins/{ubuntu.Dockerfile => ubuntu_jammy.Dockerfile} (100%) create mode 100644 jenkins/ubuntu_noble.Dockerfile diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 36112875..0992356c 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -3,7 +3,8 @@ def osreleasevers = [ // ["centos", "centos7", "7.9.2009", "rpm"], ["oraclelinux", "oraclelinux8", "8", "rpm"], ["oraclelinux", "oraclelinux9", "9", "rpm"], - ["ubuntu", "ubuntu", "jammy", "deb"] + ["ubuntu", "ubuntu_jammy", "jammy", "deb"], + ["ubuntu", "ubuntu_noble", "noble", "deb"] ] def dockertarget = "default" @@ -72,6 +73,31 @@ node('docker') { } } } + + if (osreleasever == 'jammy') { + // ubuntu 22.04 lts doesnt have libxdp in its repositories + } else { + stage("Build xdp RPMs") { + sh './build.sh --purge' + sh 'sudo ./build.sh --bootstrap-xdp' + sh "./build.sh --${pkg}-xdp" + } + + stage("Test to install xdp package") { + dir('cmake-build') { + if (pkg == 'rpm') { + sh 'sudo yum localinstall -y ndp-tool-xdp-*.rpm' + } else if (pkg == 'deb') { + /* Commented out due to missing specific kernel-headers */ + //sh 'sudo apt-get install -y -f ./*.deb' + } + sh "mkdir -p ${osname}-${osreleasever}" + sh "mv *.${pkg} ${osname}-${osreleasever}/" + archiveArtifacts artifacts: "${osname}-${osreleasever}/*.${pkg}" + sh 'find . -maxdepth 1 -type f -delete' + } + } + } } } } diff --git a/jenkins/ubuntu.Dockerfile b/jenkins/ubuntu_jammy.Dockerfile similarity index 100% rename from jenkins/ubuntu.Dockerfile rename to jenkins/ubuntu_jammy.Dockerfile diff --git a/jenkins/ubuntu_noble.Dockerfile b/jenkins/ubuntu_noble.Dockerfile new file mode 100644 index 00000000..a4a3e63c --- /dev/null +++ b/jenkins/ubuntu_noble.Dockerfile @@ -0,0 +1,13 @@ +ARG OSRELEASEVER=noble +ARG OSNAME=ubuntu +FROM $OSNAME:$OSRELEASEVER AS default +# since 24.04 LTS there is default user 'ubuntu' with uid 1000 +RUN userdel -r ubuntu +RUN /usr/sbin/groupadd -f -g 991 jenkins +RUN /usr/sbin/useradd jenkins -u 1000 -g 991 + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Europe/Prague apt-get -y install tzdata +RUN apt-get update && apt-get install -y git sudo make curl cmake pkg-config file +RUN apt-get update && apt-get install -y autoconf automake libfdt-dev libnuma-dev libncurses-dev libarchive-dev libconfig-dev python3-dev python3-setuptools cython3 libpci-dev pciutils dpkg-dev + +RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers \ No newline at end of file From e7f5bfad456f96739a93e525b58a03095f534133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 31 Jul 2024 08:08:57 +0200 Subject: [PATCH 352/518] feat(xdp driver): Add first version of XDP driver --- drivers/Makefile.conf | 2 + drivers/configure.ac | 62 ++ drivers/kernel/drivers/nfb/Makefile | 5 + drivers/kernel/drivers/nfb/core.c | 7 + drivers/kernel/drivers/nfb/xdp/channel.c | 307 +++++++++ drivers/kernel/drivers/nfb/xdp/channel.h | 52 ++ drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h | 210 +++++++ .../kernel/drivers/nfb/xdp/ctrl_xdp_common.c | 348 +++++++++++ .../kernel/drivers/nfb/xdp/ctrl_xdp_common.h | 154 +++++ drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c | 565 +++++++++++++++++ drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c | 588 ++++++++++++++++++ drivers/kernel/drivers/nfb/xdp/driver.c | 141 +++++ drivers/kernel/drivers/nfb/xdp/driver.h | 29 + drivers/kernel/drivers/nfb/xdp/ethdev.c | 316 ++++++++++ drivers/kernel/drivers/nfb/xdp/ethdev.h | 43 ++ 15 files changed, 2829 insertions(+) create mode 100644 drivers/kernel/drivers/nfb/xdp/channel.c create mode 100644 drivers/kernel/drivers/nfb/xdp/channel.h create mode 100644 drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h create mode 100644 drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c create mode 100644 drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h create mode 100644 drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c create mode 100644 drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c create mode 100644 drivers/kernel/drivers/nfb/xdp/driver.c create mode 100644 drivers/kernel/drivers/nfb/xdp/driver.h create mode 100644 drivers/kernel/drivers/nfb/xdp/ethdev.c create mode 100644 drivers/kernel/drivers/nfb/xdp/ethdev.h diff --git a/drivers/Makefile.conf b/drivers/Makefile.conf index 8c291f96..b3797de6 100644 --- a/drivers/Makefile.conf +++ b/drivers/Makefile.conf @@ -10,3 +10,5 @@ CONFIG_MODULES = y CONFIG_NFB = m CONFIG_NFB_XVC = m +# uncomment to enable XDP functionality +#CONFIG_NFB_XDP = y diff --git a/drivers/configure.ac b/drivers/configure.ac index d961cc38..748c58fd 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -269,6 +269,68 @@ void test(void) {eventfd_signal(NULL);} [AC_DEFINE([CONFIG_HAVE_SIMPLIFIED_EVENTFD_SIGNAL], [1], [Define if kernel has simplified eventfd_signal]) AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) +# XDP +KERNEL_TRY_COMPILE([[ +#include +]], +[AC_MSG_CHECKING([whether kernel has net/page_pool/helpers.h])], +[AC_DEFINE([CONFIG_HAVE_PAGE_POOL_HELPERS], [1], [Define if kernel has net/page_pool/helpers.h]) AC_MSG_RESULT([yes])] +,[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {netif_napi_add_tx_weight(NULL, NULL, NULL, NAPI_POLL_WEIGHT);} +]], +[AC_MSG_CHECKING([whether kernel has netif_napi_add_tx_weight])], +[AC_DEFINE([CONFIG_HAVE_NETIF_NAPI_ADD_TX_WEIGHT], [1], [Define if kernel has netif_napi_add_tx_weight]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {netif_napi_add(NULL, NULL, NULL, NAPI_POLL_WEIGHT);} +]], +[AC_MSG_CHECKING([whether kernel has netif_napi_add with weight argument])], +[AC_DEFINE([CONFIG_HAVE_NETIF_NAPI_ADD_WITH_WEIGHT], [1], [Define if kernel has netif_napi_add with weight argument]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {xsk_buff_alloc_batch(NULL, NULL, 64);} +]], +[AC_MSG_CHECKING([whether kernel has xsk_buff_alloc_batch])], +[AC_DEFINE([CONFIG_HAVE_XSK_BUFF_ALLOC_BATCH], [1], [Define if kernel has xsk_buff_alloc_batch]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {xsk_buff_set_size(NULL, 512);} +]], +[AC_MSG_CHECKING([whether kernel has xsk_buff_set_size])], +[AC_DEFINE([CONFIG_HAVE_XSK_BUFF_SET_SIZE], [1], [Define if kernel has xsk_buff_set_size]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +xdp_features_t val; +void test(void); +void test(void) {xdp_set_features_flag(NULL, val);} +]], +[AC_MSG_CHECKING([whether kernel has xdp_set_features_flag])], +[AC_DEFINE([CONFIG_HAVE_XDP_SET_FEATURES_FLAG], [1], [Define if kernel has xdp_set_features_flag]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +xdp_features_t val; +]], +[AC_MSG_CHECKING([whether kernel has xdp_features_t])], +[AC_DEFINE([CONFIG_HAVE_XDP_FEATURES_T], [1], [Define if kernel has xdp_features_t]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + # wait for the jobs to finnish, remove file used for locking if it exists wait rm -rf flock_lockfile >/dev/null 2>/dev/null diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index 829fe9f6..6afb6008 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -7,6 +7,8 @@ # Author(s): # Martin Spinler +include $(DRIVER_TOPDIR)/Makefile.conf + nfb-objs += ../fdt/fdt.o ../fdt/fdt_ro.o ../fdt/fdt_rw.o ../fdt/fdt_wip.o ../fdt/fdt_sw.o ../fdt/fdt_empty_tree.o nfb-objs += ../cfi/cfi_cmdset_0001.o ../cfi/cfi_cmdset_0002.o ../cfi/cfi_cmdset_0020.o ../cfi/cfi_probe.o ../cfi/cfi_util.o ../cfi/chipreg.o ../cfi/gen_probe.o ../cfi/mtdcore.o nfb-objs += ../spi-nor/spi-nor.o @@ -28,4 +30,7 @@ nfb-objs += qdr/qdr.o nfb-objs += misc.o lock.o bus.o char.o pci.o core.o nfb-objs += hwmon/nfb_hwmon.o +ccflags-$(CONFIG_NFB_XDP) += -DCONFIG_NFB_ENABLE_XDP +nfb-$(CONFIG_NFB_XDP) += xdp/driver.o xdp/ethdev.o xdp/ctrl_xdp_common.o xdp/ctrl_xdp_pp.o xdp/ctrl_xdp_xsk.o xdp/channel.o + obj-m += nfb.o diff --git a/drivers/kernel/drivers/nfb/core.c b/drivers/kernel/drivers/nfb/core.c index ffc4408d..58a024c1 100644 --- a/drivers/kernel/drivers/nfb/core.c +++ b/drivers/kernel/drivers/nfb/core.c @@ -26,6 +26,7 @@ #include "boot/boot.h" #include "ndp_netdev/core.h" #include "hwmon/nfb_hwmon.h" +#include "xdp/driver.h" MODULE_VERSION(PACKAGE_VERSION); MODULE_AUTHOR("CESNET; Martin Spinler "); @@ -343,6 +344,12 @@ static struct nfb_driver_ops embedded_driver_ops[] = { .attach = nfb_hwmon_attach, .detach = nfb_hwmon_detach, }, +#ifdef CONFIG_NFB_ENABLE_XDP + { + .attach = nfb_xdp_attach, + .detach = nfb_xdp_detach, + }, +#endif #ifdef CONFIG_NFB_ENABLE_PMCI { .attach = nfb_fpga_image_load_attach, diff --git a/drivers/kernel/drivers/nfb/xdp/channel.c b/drivers/kernel/drivers/nfb/xdp/channel.c new file mode 100644 index 00000000..5ec32bac --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/channel.c @@ -0,0 +1,307 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - channel module + * channel corresponds to one RX/TX queue pair + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#include "ctrl_xdp.h" +#include "channel.h" +#include "ethdev.h" + +static int nfb_xdp_rx_thread(void *rxqptr) +{ + struct nfb_ethdev *ethdev; + struct net_device *netdev; + struct nfb_xdp_queue *rxq; + struct nfb_xdp_channel *channel; + struct napi_struct *napi; + int ret; + + rxq = rxqptr; + channel = container_of(rxq, struct nfb_xdp_channel, rxq); + ethdev = channel->ethdev; + netdev = ethdev->netdev; + ret = 0; + if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { + napi = &rxq->napi_pp; + } else { + napi = &rxq->napi_xsk; + } + + while (!kthread_should_stop()) { + local_bh_disable(); + napi_schedule(napi); + local_bh_enable(); + while (!kthread_should_stop() && test_bit(NAPI_STATE_SCHED, &napi->state)) + usleep_range(10, 20); + } + return ret; +} + +static int nfb_xdp_tx_thread(void *txqptr) +{ + struct nfb_ethdev *ethdev; + struct net_device *netdev; + struct nfb_xdp_queue *txq; + struct nfb_xdp_channel *channel; + int ret; + + txq = txqptr; + channel = container_of(txq, struct nfb_xdp_channel, txq); + ethdev = channel->ethdev; + netdev = ethdev->netdev; + ret = 0; + + if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) // In page pool mode tx exits + return ret; + + while (!kthread_should_stop()) { + local_bh_disable(); + napi_schedule(&txq->napi_xsk); + local_bh_enable(); + while (!kthread_should_stop() && test_bit(NAPI_STATE_SCHED, &txq->napi_xsk.state)) + usleep_range(10, 20); + } + return ret; +} + +static int channel_create_threads(struct nfb_xdp_channel *channel) +{ + int ret = 0; + struct net_device *netdev = channel->ethdev->netdev; + + channel->rxq.thread = kthread_create_on_node(nfb_xdp_rx_thread, &channel->rxq, channel->numa, "%s/%u", netdev->name, channel->nfb_index); + if (IS_ERR(channel->rxq.thread)) { + printk(KERN_ERR "nfb: %s - failed to create rx thread (error: %ld, channel: %d)\n", + netdev->name, PTR_ERR(channel->rxq.thread), channel->nfb_index); + ret = PTR_ERR(channel->rxq.thread); + goto err_kthread_rx; + } + // increment reference counter to kthread so the thread can exit on error and kthread_stop() won't crash + // put_task_struct() must be called after kthread_stop() + get_task_struct(channel->rxq.thread); + // Wake up thread + if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { + napi_enable(&channel->rxq.napi_pp); + } else { + napi_enable(&channel->rxq.napi_xsk); + } + wake_up_process(channel->rxq.thread); + + // Create TX thread for each queue + channel->txq.thread = kthread_create_on_node(nfb_xdp_tx_thread, &channel->txq, channel->numa, "%s/%u", netdev->name, channel->nfb_index); + if (IS_ERR(channel->txq.thread)) { + printk(KERN_ERR "nfb: %s - failed to create tx thread (error: %ld, channel: %d)\n", + netdev->name, PTR_ERR(channel->txq.thread), channel->nfb_index); + ret = PTR_ERR(channel->txq.thread); + goto err_kthread_tx; + } + // increment reference counter to struct_task so the thread can exit on error and kthread_stop() won't crash + // put_task_struct() must be called after kthread_stop() on driver detach + get_task_struct(channel->txq.thread); + if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { + // pagepool doesn't use tx napi + } else { + napi_enable(&channel->txq.napi_xsk); + } + netif_tx_start_queue(netdev_get_tx_queue(netdev, channel->index)); + // Wake up thread + wake_up_process(channel->txq.thread); + + return 0; + +err_kthread_tx: + // collect rx thread + if (channel->rxq.thread != NULL) { + kthread_stop(channel->rxq.thread); + // This invalidates the task_struct reference + put_task_struct(channel->rxq.thread); + channel->rxq.thread = NULL; + } +err_kthread_rx: + return ret; +} + +int channel_start_pp(struct nfb_xdp_channel *channel) +{ + struct nfb_ethdev *ethdev = channel->ethdev; + struct net_device *netdev = ethdev->netdev; + struct nfb_xdp_queue *rxq = &channel->rxq; + struct nfb_xdp_queue *txq = &channel->txq; + int ret = 0; + + mutex_lock(&channel->state_mutex); + { + if (test_bit(NFB_STATUS_IS_RUNNING, &channel->status)) { + ret = -EBUSY; + goto err_channel_running; + } + + if (!(rxq->ctrl = nfb_xctrl_alloc_pp(netdev, channel->index, NFB_XDP_DESC_CNT, NFB_XCTRL_RX))) { + ret = -ENOMEM; + printk(KERN_ERR "nfb: %s - failed to alloc rx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); + goto err_alloc_rx; + } + + if (!(txq->ctrl = nfb_xctrl_alloc_pp(netdev, channel->index, NFB_XDP_DESC_CNT, NFB_XCTRL_TX))) { + ret = -ENOMEM; + printk(KERN_ERR "nfb: %s - failed to alloc tx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); + goto err_alloc_tx; + } + + if ((ret = nfb_xctrl_start(rxq->ctrl))) { + printk(KERN_ERR "nfb: %s - failed to start rx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); + goto err_start_rx; + } + + if ((ret = nfb_xctrl_start(txq->ctrl))) { + printk(KERN_ERR "nfb: %s - failed to start tx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); + goto err_start_tx; + } + + if ((ret = channel_create_threads(channel))) { + printk(KERN_ERR "nfb: %s - failed to create queue threads %d (error: %d)\n", netdev->name, channel->nfb_index, ret); + goto err_threads; + } + set_bit(NFB_STATUS_IS_RUNNING, &channel->status); + } + mutex_unlock(&channel->state_mutex); + return ret; + +err_threads: +err_start_tx: +err_start_rx: + nfb_xctrl_destroy_pp(txq->ctrl); +err_alloc_tx: + nfb_xctrl_destroy_pp(rxq->ctrl); +err_alloc_rx: +err_channel_running: + mutex_unlock(&channel->state_mutex); + return ret; +} + +int channel_start_xsk(struct nfb_xdp_channel *channel) +{ + struct nfb_ethdev *ethdev = channel->ethdev; + struct net_device *netdev = ethdev->netdev; + struct nfb_xdp_queue *rxq = &channel->rxq; + struct nfb_xdp_queue *txq = &channel->txq; + int ret = 0; + + mutex_lock(&channel->state_mutex); + { + if (test_bit(NFB_STATUS_IS_RUNNING, &channel->status)) { + ret = -EBUSY; + goto err_channel_running; + } + + if (!(rxq->ctrl = nfb_xctrl_alloc_xsk(netdev, channel->index, channel->pool, NFB_XCTRL_RX))) { + ret = -ENOMEM; + printk(KERN_ERR "nfb: %s - failed to alloc rx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); + goto err_alloc_rx; + } + + if (!(txq->ctrl = nfb_xctrl_alloc_xsk(netdev, channel->index, channel->pool, NFB_XCTRL_TX))) { + ret = -ENOMEM; + printk(KERN_ERR "nfb: %s - failed to alloc tx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); + goto err_alloc_tx; + } + + if ((ret = nfb_xctrl_start(rxq->ctrl))) { + printk(KERN_ERR "nfb: %s - failed to start rx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); + goto err_start_rx; + } + + if ((ret = nfb_xctrl_start(txq->ctrl))) { + printk(KERN_ERR "nfb: %s - failed to start tx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); + goto err_start_tx; + } + + if ((ret = channel_create_threads(channel))) { + goto err_threads; + } + + set_bit(NFB_STATUS_IS_RUNNING, &channel->status); + } + mutex_unlock(&channel->state_mutex); + + return ret; + +err_threads: +err_start_tx: +err_start_rx: + nfb_xctrl_destroy_xsk(txq->ctrl); +err_alloc_tx: + nfb_xctrl_destroy_xsk(rxq->ctrl); +err_alloc_rx: +err_channel_running: + mutex_unlock(&channel->state_mutex); + return ret; +} + +int channel_stop(struct nfb_xdp_channel *channel) +{ + struct nfb_xdp_queue *rxq = &channel->rxq; + struct nfb_xdp_queue *txq = &channel->txq; + struct net_device *netdev = channel->ethdev->netdev; + int ret = 0; + + mutex_lock(&channel->state_mutex); + { + if (!test_bit(NFB_STATUS_IS_RUNNING, &channel->status)) { + ret = -EINVAL; + goto err_channel_not_running; + } + + // Collect rx thread + if (rxq->thread != NULL) { + kthread_stop(rxq->thread); + // This invalidates the task_struct reference + put_task_struct(rxq->thread); + rxq->thread = NULL; + } + if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { // base XDP operation + napi_disable(&rxq->napi_pp); + while (napi_disable_pending(&rxq->napi_pp)) + ; + } else { // AF_XDP operation + napi_disable(&rxq->napi_xsk); + while (napi_disable_pending(&rxq->napi_xsk)) + ; + } + + // Collect tx thread + netif_tx_stop_queue(netdev_get_tx_queue(netdev, channel->index)); + if (channel->txq.thread != NULL) { + kthread_stop(channel->txq.thread); + put_task_struct(channel->txq.thread); + channel->txq.thread = NULL; + } + if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { // base XDP operation + // No napi + } else { // AF_XDP operation + napi_disable(&txq->napi_xsk); + while (napi_disable_pending(&txq->napi_xsk)) + ; + } + + if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { + nfb_xctrl_destroy_pp(rxq->ctrl); + nfb_xctrl_destroy_pp(txq->ctrl); + } else { + nfb_xctrl_destroy_xsk(rxq->ctrl); + nfb_xctrl_destroy_xsk(txq->ctrl); + } + clear_bit(NFB_STATUS_IS_RUNNING, &channel->status); + } + mutex_unlock(&channel->state_mutex); + return ret; + +err_channel_not_running: + mutex_unlock(&channel->state_mutex); + return ret; +} diff --git a/drivers/kernel/drivers/nfb/xdp/channel.h b/drivers/kernel/drivers/nfb/xdp/channel.h new file mode 100644 index 00000000..299447dc --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/channel.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - header file for channel + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#ifndef NFB_XDP_CHANNEL_H +#define NFB_XDP_CHANNEL_H + +#include + +#define NFB_XDP_DESC_CNT 8192 + +struct nfb_xdp_queue { + // dma controller + struct xctrl *ctrl; + + // queue thread + struct task_struct *thread; + + // napi structs - so far only xsk mode uses tx napi + struct napi_struct napi_pp; + struct napi_struct napi_xsk; +}; + +// structure describing one queue pair +#define NFB_STATUS_IS_XSK BIT(0) +#define NFB_STATUS_IS_RUNNING BIT(1) +struct nfb_xdp_channel { + struct nfb_ethdev *ethdev; // reference to ETH device holding this channel + u16 index; // In the context of ETH device + u16 nfb_index; // In the context of the card + int numa; // numa node of the pci device + + struct nfb_xdp_queue txq; + struct nfb_xdp_queue rxq; + + // Synchronize the state of rx and tx queue switching + struct mutex state_mutex; + unsigned long status; + + struct xsk_buff_pool *pool; +}; + +int channel_start_pp(struct nfb_xdp_channel *channel); +int channel_start_xsk(struct nfb_xdp_channel *channel); +int channel_stop(struct nfb_xdp_channel *channel); + +#endif // NFB_XDP_CHANNEL_H diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h new file mode 100644 index 00000000..0d291204 --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h @@ -0,0 +1,210 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - ctrl header + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#ifndef CTRL_XDP_H +#define CTRL_XDP_H +#include +#include + +#include "../nfb.h" +#include "../../../../../libnfb/include/netcope/dma_ctrl_ndp.h" + +#define NFB_XDP_CTRL_PACKET_BURST 64 + +enum xdp_ctrl_type { + NFB_XCTRL_RX, + NFB_XCTRL_TX, +}; + +enum xdp_ctrl_tx_buff_type { + NFB_XCTRL_BUFF_DESC_TYPE0 = 0, // used with desc type0; no freeing required + NFB_XCTRL_BUFF_FRAME_PP, // used with page pool, no dma unmap + NFB_XCTRL_BUFF_FRAME, // used with frames which needs to be unmapped + NFB_XCTRL_BUFF_SKB, // used for linux netdev tx ndo + NFB_XCTRL_BUFF_XSK, // used for counting the xsk frames +}; + +// Used for freeing tx buffers after tx completes +struct xctrl_tx_buffer { + enum xdp_ctrl_tx_buff_type type; + union { + struct sk_buff *skb; + struct xdp_frame *frame; + // for counting xsk completions + // when we drop packet on tx this is more than 1 + u32 num_of_xsk_completions; + }; + dma_addr_t dma; + u32 len; +}; + +// TODO: clean up +#define XCTRL_STATUS_IS_RUNNING BIT(0) +struct xctrl { + enum xdp_ctrl_type type; + union { + struct { + /** RX - Driver handles allocation of pages for rx through page_pool + * Array of pages that is 1:1 with hardware header buffer. + * => if controller gets 24 headers at index i then page_ring[i] + * is the start of 24 pages that hold data ready to be used + */ + union { + // for page_pool operation + struct { + struct xdp_buff **xdp_ring; + struct page_pool *pool; + } pp; + // for xsk operation + struct { + struct xdp_buff **xdp_ring; + struct xsk_buff_pool *pool; + } xsk; + }; + u32 php; // RX - processed header pointers + // hdr_buff is only used on rx + u32 nb_hdr; + void *hdr_buffer_cpu; + dma_addr_t hdr_buffer_dma; + struct xdp_rxq_info rxq_info; + } rx; + struct { + /** TX - Driver does't handle allocation on tx + * Array of either xdp frames or skbs + * There are limited number of ways packet can end up on tx. + * 1. from linux kernel stack + * => dma map skb -> send to nic -> return from nic -> dma unmap -> dev_kfree_skb(skb); + * 2. from XDP_TX - packet is on rx page_pool page + * => get page dma -> send to nic -> return from nic -> recycle to page pool. + * 3. from XDP_REDIRECT - we get xdp_frame from XDP core. XDP core handles the deallocation. + * => dma map frame -> send to nic -> return from nic -> dma unmap -> xdp_return_frame() + * TODO: checkout xdp_return_frame_bulk() + */ + struct xctrl_tx_buffer *buffers; + u32 fdp; // TX - freed descriptor pointers + spinlock_t tx_lock; // TODO: checkout __netif_tx_lock() + // used for counting completed tx frames + // in XSK mode driver needs to return the frames + // in the same order as it got them + // So we count num of frames we can return from tx_buffer + u32 completed_xsk_tx; // num of frames ready to be returned to userspace on tx_buffer_free + u32 last_napi_xsk_drops; // if we drop packets on tx we add them for completion with the next packet + } tx; + }; + + // common control buffers + void *update_buffer_virt; + dma_addr_t update_buffer_dma; + + u32 nb_desc; + void *desc_buffer_virt; + dma_addr_t desc_buffer_dma; + + unsigned long status; // status of xctrl, used to check if underliing controller is running + struct nc_ndp_ctrl c; // underlying controller + struct device *dma_dev; // device used for dma allocation + + // queue id in context of nfb device + u32 nfb_queue_id; + // queue id in context of a port + u32 netdev_queue_id; + u32 tu_min; + u32 tu_max; +}; + +/** + * @brief Allocates struct xdp_ctrl for basic XDP operation. + * Use nfb_xdp_ctrl_destroy() for cleanup + * + * @param netdev + * @param nfb_queue_id + * @param desc_cnt + * @param type + * @return struct xdp_ctrl* + */ +struct xctrl *nfb_xctrl_alloc_pp(struct net_device *netdev, u32 queue_id, u32 desc_cnt, enum xdp_ctrl_type type); + +/** + * @brief Cleans up struct xdp_ctrl + * + * @param ctrl + */ +void nfb_xctrl_destroy_pp(struct xctrl *ctrl); + +/** + * @brief Allocates struct xdp_ctrl for AF_XDP operation. + * Use nfb_xdp_ctrl_destroy() for cleanup + * + * @param netdev + * @param nfb_queue_id + * @param desc_cnt + * @param type + * @return struct xdp_ctrl* + */ +struct xctrl *nfb_xctrl_alloc_xsk(struct net_device *netdev, u32 nfb_queue_id, struct xsk_buff_pool *pool, enum xdp_ctrl_type type); + +/** + * @brief Cleans up struct xdp_ctrl + * + * @param ctrl + */ +void nfb_xctrl_destroy_xsk(struct xctrl *ctrl); + +/** + * @brief Starts the DMA + * + * @param ctrl + * @param sp + * @return int + */ +int nfb_xctrl_start(struct xctrl *ctrl); + +/* netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb, + * struct net_device *dev); + * Called when a packet needs to be transmitted. + * Returns NETDEV_TX_OK. Can return NETDEV_TX_BUSY, but you should stop + * the queue before that can happen; it's for obsolete devices and weird + * corner cases, but the stack really does a non-trivial amount + * of useless work if you return NETDEV_TX_BUSY. + * Required; cannot be NULL. + */ +netdev_tx_t nfb_xctrl_start_xmit(struct sk_buff *skb, struct net_device *netdev); + +/* int (*ndo_xdp_xmit)(struct net_device *dev, int n, struct xdp_frame **xdp, + * u32 flags); + * This function is used to submit @n XDP packets for transmit on a + * netdevice. Returns number of frames successfully transmitted, frames + * that got dropped are freed/returned via xdp_return_frame(). + * Returns negative number, means general error invoking ndo, meaning + * no frames were xmit'ed and core-caller will free all frames. + */ +int nfb_xctrl_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdp, u32 flags); + +/* int (*ndo_bpf)(struct net_device *dev, struct netdev_bpf *bpf); + * This function is used to set or query state related to XDP on the + * netdevice and manage BPF offload. See definition of + * enum bpf_netdev_command for details. + */ +int nfb_xdp(struct net_device *dev, struct netdev_bpf *xdp); + +/* int (*ndo_xsk_wakeup)(struct net_device *dev, u32 queue_id, u32 flags); + * This function is used to wake up the softirq, ksoftirqd or kthread + * responsible for sending and/or receiving packets on a specific + * queue id bound to an AF_XDP socket. The flags field specifies if + * only RX, only Tx, or both should be woken up using the flags + * XDP_WAKEUP_RX and XDP_WAKEUP_TX. + */ +int nfb_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags); + +// Napi poll functions +int nfb_xctrl_napi_poll_pp(struct napi_struct *napi, int budget); +int nfb_xctrl_napi_poll_rx_xsk(struct napi_struct *napi, int budget); +int nfb_xctrl_napi_poll_tx_xsk(struct napi_struct *napi, int budget); + +#endif // CTRL_XDP_H diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c new file mode 100644 index 00000000..991ae93e --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c @@ -0,0 +1,348 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - common ctrl module + * contains functions common to both XDP modes + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#include "ctrl_xdp_common.h" +#include +#include + +int nfb_xctrl_start(struct xctrl *ctrl) +{ + int ret; + // NOTE: I decided to duplicate these values in struct xctrl + // just for the sake of readability. + // This can be changed if desired. + struct nc_ndp_ctrl_start_params sp = { + .desc_buffer = ctrl->desc_buffer_dma, + .update_buffer = ctrl->update_buffer_dma, + .update_buffer_virt = ctrl->update_buffer_virt, + .nb_desc = ctrl->nb_desc, + }; + // rx only params + if (ctrl->type == NFB_XCTRL_RX) { + sp.hdr_buffer = ctrl->rx.hdr_buffer_dma; + sp.nb_hdr = ctrl->rx.nb_hdr; + } + ret = nc_ndp_ctrl_start(&ctrl->c, &sp); + if (!ret) { + set_bit(XCTRL_STATUS_IS_RUNNING, &ctrl->status); + } + return ret; +} + +netdev_tx_t nfb_xctrl_start_xmit(struct sk_buff *skb, struct net_device *netdev) +{ + struct nfb_ethdev *ethdev = netdev_priv(netdev); + struct nfb_xdp_channel *channel = ðdev->channels[skb->queue_mapping]; + struct nfb_xdp_queue *txq = &channel->txq; + struct xctrl *ctrl = txq->ctrl; + + dma_addr_t dma; + u32 len; + u32 min_len = ETH_ZLEN; + u32 sdp; + u32 mdp; + + struct nc_ndp_desc *descs; + u64 last_upper_addr; + u32 free_desc; + u32 ret; + + spin_lock(&ctrl->tx.tx_lock); + { + nc_ndp_ctrl_hdp_update(&ctrl->c); + nfb_xctrl_tx_free_buffers(ctrl); + + sdp = ctrl->c.sdp; + mdp = ctrl->c.mdp; + free_desc = (ctrl->c.hdp - sdp - 1) & mdp; + descs = ctrl->desc_buffer_virt; + + if (skb_linearize(skb)) { + printk(KERN_ERR "nfb: %s failed to linearize skb. queue: %u\n", __func__, channel->nfb_index); + goto free_locked; + } + + len = max(min_len, skb->len); + if (skb_padto(skb, min_len)) { + // skb is freed on error + printk(KERN_ERR "nfb: %s skb too small and zero padding failed. queue: %u\n", __func__, channel->nfb_index); + goto freed_locked; + } + + dma = dma_map_single(ctrl->dma_dev, skb->data, len, DMA_TO_DEVICE); + if ((ret = dma_mapping_error(ctrl->dma_dev, dma))) { + printk(KERN_ERR "nfb: %s failed to dma map skb. queue: %u err: %d\n", __func__, channel->nfb_index, ret); + goto free_locked; + } + + last_upper_addr = ctrl->c.last_upper_addr; + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { + if (unlikely(free_desc < 2)) { + dev_warn(ethdev->nfb->dev, "nfb: %s busy warning. Packets are dropped. queue: %u\n", __func__, channel->nfb_index); + goto free_locked_unmap; + } + + last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); + ctrl->c.last_upper_addr = last_upper_addr; + + descs[sdp] = nc_ndp_tx_desc0(dma); + + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; + free_desc--; + sdp = (sdp + 1) & mdp; + } + + if (unlikely(free_desc == 0)) { + dev_warn(ethdev->nfb->dev, "nfb: %s busy warning. Packets are dropped. queue: %u\n", __func__, channel->nfb_index); + goto free_locked_unmap; + } + + free_desc--; + + // TODO: + // If socket uses up all it's allocated skbs before first skb is freed + // then socket can no longer send another packet + // and tx completition is not called causing socket to deadlock + // skb_orphan releases skb from socket pool so it is a working temporary solution + // tx timeout should still be introduced + skb_orphan(skb); + + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_SKB; + ctrl->tx.buffers[sdp].skb = skb; + ctrl->tx.buffers[sdp].dma = dma; + ctrl->tx.buffers[sdp].len = len; + + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + sdp = (sdp + 1) & mdp; + ctrl->c.sdp = sdp; + + // NOTE: Calling dma_map_single with DMA_TO_DEVICE should do the sync for dev + // Calling unmap should do the sync for cpu + // Therefore the sync functions are only really needed when using DMA_BIDIRECTINAL + // dma_sync_single_for_device(ctrl->dma_dev, dma, len, DMA_TO_DEVICE); + nc_ndp_ctrl_sdp_flush(&ctrl->c); + } + spin_unlock(&ctrl->tx.tx_lock); + + return NETDEV_TX_OK; + +free_locked_unmap: + dma_unmap_single(ctrl->dma_dev, dma, len, DMA_TO_DEVICE); +free_locked: + dev_kfree_skb(skb); +freed_locked: + spin_unlock(&ctrl->tx.tx_lock); + + // NOTE: It is possible to return NETDEV_TX_BUSY + // Kernel then tries to xmit packet again + // It is slow and it is possible to completely + // freeze system this way on error. + return NETDEV_TX_OK; +} + +int nfb_xctrl_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdp, u32 flags) +{ + struct nfb_ethdev *ethdev = netdev_priv(dev); + u32 qid; + struct nfb_xdp_channel *channel; + struct nfb_xdp_queue *txq; + struct xctrl *ctrl; + struct xdp_frame *frame; + int cnt = 0; + + if (n == 0) { + return 0; + } + + // There doesn't seem to be a good way to decide which queue to use for tx other than semi random + qid = smp_processor_id() % ethdev->channel_count; + channel = ðdev->channels[qid]; + txq = &channel->txq; + ctrl = txq->ctrl; + spin_lock(&ctrl->tx.tx_lock); + { + // reclaim tx buffers + nc_ndp_ctrl_hdp_update(&ctrl->c); + nfb_xctrl_tx_free_buffers(ctrl); + // process tx + for (cnt = 0; cnt < n; cnt++) { + frame = xdp[cnt]; + if (unlikely(nfb_xctrl_tx_submit_frame_needs_lock(ctrl, frame))) { + // on error caller frees the frames (see ndo_xdp_xmit docs) + break; + } + } + // flush + nc_ndp_ctrl_sdp_flush(&ctrl->c); + } + spin_unlock(&ctrl->tx.tx_lock); + if (cnt != n) { + printk(KERN_WARNING "%s didn't manage to tx all packets; %d packets dropped\n", __func__, n - cnt); + } + return cnt; +} + +// TODO: currently the prog pointer is held in the netdev_priv. +// Maybe for performance there should be pointer inside each queue struct. +/** + * @brief Replaces pointer to xdp prog. + * + * @param netdev + * @param prog + * @return int + */ +static int nfb_xdp_setup_prog(struct net_device *netdev, struct bpf_prog *prog) +{ + struct nfb_ethdev *ethdev = netdev_priv(netdev); + struct bpf_prog *old_prog; + + // Swap program pointer + spin_lock(ðdev->prog_lock); + { + old_prog = rcu_replace_pointer(ethdev->prog, prog, lockdep_is_held(ðdev->prog_lock)); + } + spin_unlock(ðdev->prog_lock); + synchronize_rcu(); + + if (old_prog) { + bpf_prog_put(old_prog); + } + printk(KERN_INFO "nfb: XDP program swaped\n"); + return 0; +} + +/** + * @brief This is called when xsocket closes. Function must reallocate queue and restart ctrl on the fly. + * This is also called on driver detach and AFTER close function. Meaning there can be race conditions. + * That is why mutex is used. + * + * @param dev + * @param pool + * @param qid + * @return int + */ +static int nfb_setup_xsk_pool(struct net_device *dev, struct xsk_buff_pool *pool, u16 qid) +{ + struct nfb_ethdev *ethdev = netdev_priv(dev); + struct nfb_xdp_channel *channel = ðdev->channels[qid]; + u32 nfb_queue_id = channel->nfb_index; + int ret = 0; + + // printk(KERN_DEBUG "LOG: inside %s\n", __func__); + if ((ret = xsk_pool_dma_map(pool, ðdev->nfb->pci->dev, DMA_ATTR_SKIP_CPU_SYNC))) { + printk(KERN_ERR "nfb: Failed to switch queue %d pool could't be mapped err: %d\n", nfb_queue_id, ret); + goto exit; + } + + channel_stop(channel); + set_bit(NFB_STATUS_IS_XSK, &channel->status); + channel->pool = pool; + if ((ret = channel_start_xsk(channel))) { + printk(KERN_WARNING "nfb: Failed to start channel %d, channel unusable\n", nfb_queue_id); + goto unmap; + } + printk("nfb: channel %d switched to AF_XDP operation\n", nfb_queue_id); + + return ret; + +unmap: + xsk_pool_dma_unmap(pool, DMA_ATTR_SKIP_CPU_SYNC); +exit: + return ret; +} + +/** + * @brief This is called when xsocket closes. Function must reallocate queue and restart ctrl on the fly. + * This is also called on driver detach and AFTER close function. Meaning there can be race conditions. + * That is why mutex is used inside channel stop. + * + * @param dev + * @param pool + * @param qid + * @return int + */ +static int nfb_teardown_xsk_pool(struct net_device *dev, struct xsk_buff_pool *pool, u16 qid) +{ + struct nfb_ethdev *ethdev = netdev_priv(dev); + struct nfb_xdp_channel *channel = ðdev->channels[qid]; + struct xsk_buff_pool *old_pool = NULL; + u32 nfb_queue_id = channel->nfb_index; + u32 ret = 0; + + channel_stop(channel); + clear_bit(NFB_STATUS_IS_XSK, &channel->status); + if ((ret = channel_start_pp(channel))) { + printk(KERN_WARNING "nfb: Failed to start channel %d, channel unusable\n", nfb_queue_id); + goto unmap; + } + + printk("nfb: channel %d switched to XDP operation\n", nfb_queue_id); +unmap: + old_pool = xchg(&channel->pool, NULL); + if (!old_pool) { + xsk_pool_dma_unmap(old_pool, DMA_ATTR_SKIP_CPU_SYNC); + channel->pool = NULL; + } + return ret; +} + +/* int (*ndo_bpf)(struct net_device *dev, struct netdev_bpf *bpf); + * This function is used to set or query state related to XDP on the + * netdevice and manage BPF offload. See definition of + * enum bpf_netdev_command for details. + */ +int nfb_xdp(struct net_device *dev, struct netdev_bpf *xdp) +{ + int ret; + switch (xdp->command) { + case XDP_SETUP_PROG: + return nfb_xdp_setup_prog(dev, xdp->prog); + case XDP_SETUP_XSK_POOL: + if (xdp->xsk.pool) { + ret = nfb_setup_xsk_pool(dev, xdp->xsk.pool, xdp->xsk.queue_id); + } else { + ret = nfb_teardown_xsk_pool(dev, xdp->xsk.pool, xdp->xsk.queue_id); + } + return ret; + default: + printk(KERN_ERR "nfb: either bad or unsupported XDP command: %d\n", xdp->command); + return -EINVAL; + } +} + +/* int (*ndo_xsk_wakeup)(struct net_device *dev, u32 queue_id, u32 flags); + * This function is used to wake up the softirq, ksoftirqd or kthread + * responsible for sending and/or receiving packets on a specific + * queue id bound to an AF_XDP socket. The flags field specifies if + * only RX, only Tx, or both should be woken up using the flags + * XDP_WAKEUP_RX and XDP_WAKEUP_TX. + */ +int nfb_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags) +{ + struct nfb_ethdev *ethdev = netdev_priv(dev); + struct nfb_xdp_channel *channel = ðdev->channels[queue_id]; + struct nfb_xdp_queue *txq = &channel->txq; + struct nfb_xdp_queue *rxq = &channel->rxq; + + if (flags & XDP_WAKEUP_TX) { + local_bh_disable(); + if (!napi_if_scheduled_mark_missed(&txq->napi_xsk)) + napi_schedule(&txq->napi_xsk); + local_bh_enable(); + } + if (flags & XDP_WAKEUP_RX) { + local_bh_disable(); + if (!napi_if_scheduled_mark_missed(&rxq->napi_xsk)) + napi_schedule(&rxq->napi_xsk); + local_bh_enable(); + } + + return 0; +} diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h new file mode 100644 index 00000000..3fe17c51 --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h @@ -0,0 +1,154 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - common ctrl header + * contains functions common to both XDP modes + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#ifndef CTRL_XDP_COMMON_H +#define CTRL_XDP_COMMON_H + +#include "ctrl_xdp.h" +#include "ethdev.h" +#include "channel.h" + +#ifdef CONFIG_HAVE_PAGE_POOL_HELPERS +#include +#else +#include +#endif + +// TODO: to make the logic easier this could be split into pp and xsk version of the function +/** + * @brief Reclaims buffers from tx + * + * @param ctrl + */ +static inline void nfb_xctrl_tx_free_buffers(struct xctrl *ctrl) +{ + u32 i; + u32 hdp = ctrl->c.hdp; + u32 mdp = ctrl->c.mdp; + u32 fdp = ctrl->tx.fdp; + + for (i = fdp; i != hdp; i++, i &= mdp) { + switch (ctrl->tx.buffers[i].type) { + case NFB_XCTRL_BUFF_FRAME_PP: // xdp buff to be recycled to page pool + // xdp_return_buff definition is missing in 4.18.0-477.10.1.el8_8.x86_64 + // xdp_return_buff(ctrl->tx.buffers[i].buff); + xdp_return_frame(ctrl->tx.buffers[i].frame); + break; + case NFB_XCTRL_BUFF_XSK: + ctrl->tx.completed_xsk_tx += ctrl->tx.buffers[i].num_of_xsk_completions; + break; + case NFB_XCTRL_BUFF_SKB: + dma_unmap_single(ctrl->dma_dev, ctrl->tx.buffers[i].dma, ctrl->tx.buffers[i].len, DMA_TO_DEVICE); + dev_kfree_skb(ctrl->tx.buffers[i].skb); + break; + case NFB_XCTRL_BUFF_FRAME: // redirectedd frame - can be from another device all together + // TODO check out xdp_return_frame_bulk() + dma_unmap_single(ctrl->dma_dev, ctrl->tx.buffers[i].dma, ctrl->tx.buffers[i].len, DMA_TO_DEVICE); + xdp_return_frame(ctrl->tx.buffers[i].frame); + break; + case NFB_XCTRL_BUFF_DESC_TYPE0: + break; + default: + printk(KERN_ERR "Tried to freed non existing type on tx completion. This is a driver bug.\n"); + BUG(); + break; + } + ctrl->tx.buffers[i].type = NFB_XCTRL_BUFF_DESC_TYPE0; + } + ctrl->tx.fdp = hdp; +} + +/** + * @brief Submits and maps frame onto tx. Not as straight forward as i would have liked -> check note + * @note + * spin_lock(&lock) + * nc_ndp_ctrl_hdp_update(&ctrl->c); + * nfb_xctrl_tx_free_buffers(ctrl); + * for (;;) + * nfb_xctrl_tx_submit_frame_needs_lock() + * nc_ndp_ctrl_sdp_flush() + * spin_unlock(&lock) + * @param ctrl + * @param frame + * @return 0 on success + */ +static inline int nfb_xctrl_tx_submit_frame_needs_lock(struct xctrl *ctrl, struct xdp_frame *frame) +{ + dma_addr_t dma; + u32 free_desc; + u32 len; + u16 min_len = ETH_ZLEN; + int ret = 0; + + // ctrl vars + u64 last_upper_addr = ctrl->c.last_upper_addr; + u32 sdp = ctrl->c.sdp; + u32 mdp = ctrl->c.mdp; + struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; + + free_desc = (ctrl->c.hdp - sdp - 1) & mdp; + + // Handle small frames + len = max(frame->len, min_len); + // Here we don't know where the frames came from. (Could be different driver all together) + // Therefore if we cannot make the frame bigger we would have to alloc a new one. -ENOTSUPP + if (frame->len < min_len) { // Usable frame space is smaller than min_len. + if (unlikely(frame->frame_sz - frame->headroom < min_len)) { + ret = -ENOTSUPP; + goto exit; + } + memset(frame->data + frame->len, 0, min_len - frame->len); + } + + dma = dma_map_single(ctrl->dma_dev, frame->data, len, DMA_TO_DEVICE); + if (unlikely(ret = dma_mapping_error(ctrl->dma_dev, dma))) { + printk(KERN_ERR "nfb: %s failed to map frame\n", __func__); + goto exit; + } + + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { + if (unlikely(free_desc < 2)) { + printk(KERN_ERR "nfb: %s busy warning\n", __func__); + dma_unmap_single(ctrl->dma_dev, dma, len, DMA_TO_DEVICE); + ret = -EBUSY; + goto exit; + } + + last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); + ctrl->c.last_upper_addr = last_upper_addr; + + descs[sdp] = nc_ndp_tx_desc0(dma); + + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; + free_desc--; + sdp = (sdp + 1) & mdp; + } + + if (unlikely(free_desc == 0)) { + printk(KERN_ERR "nfb: nfb_xctrl_xmit busy warning\n"); + dma_unmap_single(ctrl->dma_dev, dma, len, DMA_TO_DEVICE); + ret = -EBUSY; + goto exit; + } + + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_FRAME; + ctrl->tx.buffers[sdp].frame = frame; + ctrl->tx.buffers[sdp].dma = dma; + ctrl->tx.buffers[sdp].len = len; + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + sdp = (sdp + 1) & mdp; + + // update ctrl state + ctrl->c.sdp = sdp; +exit: + return ret; +} + +#endif // CTRL_XDP_COMMON_H diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c new file mode 100644 index 00000000..a8a5d1c3 --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c @@ -0,0 +1,565 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - ctrl module for default XDP operation + * uses page pool API to allocate memory + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#include +#include +#include +#include +#include + +#include "ctrl_xdp_common.h" + +/** + * @brief Tries to rexmit pp page. Frees page on fail via xdp_return_buff (gets the page_pool from mem info) + * + * @param ctrl + * @param xdp + * @return int + */ +static inline int nfb_xctrl_rexmit_pp(struct xctrl *ctrl, struct xdp_buff *xdp) +{ + dma_addr_t dma; + u32 free_desc; + u32 len; + u32 min_len = ETH_ZLEN; + int ret = 0; + + // ctrl vars + struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; + u32 sdp = ctrl->c.sdp; + u32 mdp = ctrl->c.mdp; + u64 last_upper_addr = ctrl->c.last_upper_addr; + + // handle small packets + len = max((u32)(xdp->data_end - xdp->data), min_len); + // it is assumed here that we have whole page and that the headroom is XDP_PACKET_HEADROOM + if (xdp->data_end - xdp->data < min_len) { + memset(xdp->data_end, 0, ETH_ZLEN); + } + + spin_lock(&ctrl->tx.tx_lock); + { + // Reclaim tx buffers + nc_ndp_ctrl_hdp_update(&ctrl->c); + nfb_xctrl_tx_free_buffers(ctrl); + + free_desc = (ctrl->tx.fdp - sdp - 1) & mdp; + + dma = page_pool_get_dma_addr(virt_to_page(xdp->data_hard_start)) + XDP_PACKET_HEADROOM; + + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { + if (unlikely(free_desc < 2)) { + printk(KERN_ERR "nfb: %s busy warning\n", __func__); + ret = -EBUSY; + goto exit_free; + } + + last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); + ctrl->c.last_upper_addr = last_upper_addr; + descs[sdp] = nc_ndp_tx_desc0(dma); + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; + free_desc--; + sdp = (sdp + 1) & mdp; + } + + if (unlikely(free_desc == 0)) { + printk(KERN_ERR "nfb: %s busy warning\n", __func__); + ret = -EBUSY; + goto exit_free; + } + + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_FRAME_PP; + // Here the xdp buffer is located on the ctrl.rx.xdp_ring + // converting buff to frame writes the metadata into XDP_PACKET_HEADROOM + // this frees the ctrl.rx.xdp_ring buffer to be reused + ctrl->tx.buffers[sdp].frame = xdp_convert_buff_to_frame(xdp); + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + dma_sync_single_for_device(ctrl->dma_dev, dma, len, DMA_BIDIRECTIONAL); + sdp = (sdp + 1) & mdp; + + // update ctrl + ctrl->c.sdp = sdp; + +exit_free: + if (unlikely(ret)) { + // xdp_return_buff definition is missing in 4.18.0-477.10.1.el8_8.x86_64 + // xdp_return_buff(xdp); + xdp_return_frame(xdp_convert_buff_to_frame(xdp)); + } + + // Flush counters when done + nc_ndp_ctrl_sdp_flush(&ctrl->c); + } + spin_unlock(&ctrl->tx.tx_lock); + return ret; +} + +/** + * @brief Page pool operation to fill card with rx descriptors. + * + * @param ctrl + * @param pool struct page_pool + * @return int number of descriptors fileld + */ +static inline int nfb_xctrl_rx_fill_pp(struct xctrl *ctrl) +{ + const u32 batch_size = NFB_XDP_CTRL_PACKET_BURST; + + // ctrl vars + u64 last_upper_addr = ctrl->c.last_upper_addr; + u32 mdp = ctrl->c.mdp; + u32 sdp = ctrl->c.sdp; + u32 mhp = ctrl->c.mhp; + u32 php = ctrl->rx.php; + + // NOTE: XDP should have reserved tailroom for passing the page to the network stack + const u32 frame_len = PAGE_SIZE - SKB_DATA_ALIGN(XDP_PACKET_HEADROOM + sizeof(struct skb_shared_info)); + struct page_pool *pool = ctrl->rx.pp.pool; + struct page *page; + dma_addr_t dma; + struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; + u32 free_desc, free_hdrs; + u32 i; + + // Check if refill needed + nc_ndp_ctrl_hdp_update(&ctrl->c); + free_hdrs = (ctrl->c.shp - php - 1) & mhp; + free_desc = (ctrl->c.hdp - sdp - 1) & mdp; + if (free_hdrs < batch_size || free_desc < batch_size) + return 0; + + // Alloc buffers and send them to card + for (i = 0; i < batch_size; i++) { + if (!(page = page_pool_dev_alloc_pages(pool))) { + printk(KERN_WARNING "nfb: failed to allocate page from page pool\n"); + break; + } + dma = page_pool_get_dma_addr(page) + XDP_PACKET_HEADROOM; + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { + if (unlikely(free_desc == 0)) { + page_pool_put_full_page(pool, page, false); + break; + } + last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); + ctrl->c.last_upper_addr = last_upper_addr; + descs[sdp] = nc_ndp_rx_desc0(dma); + sdp = (sdp + 1) & mdp; + free_desc--; + } + if (unlikely(free_desc == 0)) { + page_pool_put_full_page(pool, page, false); + break; + } + xdp_init_buff(ctrl->rx.pp.xdp_ring[php], PAGE_SIZE, &ctrl->rx.rxq_info); + xdp_prepare_buff(ctrl->rx.pp.xdp_ring[php], page_to_virt(page), XDP_PACKET_HEADROOM, 0, false); + descs[sdp] = nc_ndp_rx_desc2(dma, frame_len, 0); + sdp = (sdp + 1) & mdp; + php = (php + 1) & mhp; + free_desc--; + } + + // update ctrl state + ctrl->rx.php = php; + ctrl->c.sdp = sdp; + + return i; +} + +/** + * @brief XDP handler + * + * @param prog + * @param xdp + * @param rxq + * @return result + */ +static inline void nfb_xctrl_handle_pp(struct bpf_prog *prog, struct xdp_buff *xdp, struct nfb_xdp_queue *rxq) +{ + unsigned act; + int ret; + struct bpf_prog *xdp_prog; + struct nfb_xdp_channel *channel = container_of(rxq, struct nfb_xdp_channel, rxq); + struct nfb_ethdev *ethdev = channel->ethdev; + struct sk_buff *skb; + + rcu_read_lock(); + xdp_prog = rcu_dereference(prog); + if (xdp_prog) { + act = bpf_prog_run_xdp(xdp_prog, xdp); + } else { + act = XDP_PASS; + } + + switch (act) { + case XDP_PASS: + // NOTE: This function does a lot of things internally, check it's implementation + // if you ever want to add support for fragmented packets + skb = xdp_build_skb_from_frame(xdp_convert_buff_to_frame(xdp), ethdev->netdev); + if (IS_ERR_OR_NULL(skb)) { + printk(KERN_DEBUG "SKB build failed\n"); + goto aborted; + } + // receive packet onto queue it arriverd on + skb_record_rx_queue(skb, channel->index); + // TODO: gro_receive is supposed to be a free + // performance boost but it is quite bad for + // debugging because you cannot check if all packet + // received are the same as sent + // napi_gro_receive(napi, skb); + // Send packet to the kernel network stack, it will be freed via xdp_return_frame + netif_receive_skb(skb); + // TODO: future extension + // if (netif_receive_skb(skb) != NET_RX_DROP) { + // ctrl.stats = ... + // } else { + // ctrl.stats = ... + // } + break; + case XDP_TX: + // returned via xdp_return_frame on tx reclaim; + nfb_xctrl_rexmit_pp(channel->txq.ctrl, xdp); + break; + case XDP_REDIRECT: + // redirected packet is internally returned via xdp_return_frame + ret = xdp_do_redirect(ethdev->netdev, xdp, xdp_prog); + if (unlikely(ret)) { + printk(KERN_ERR "nfb: xdp_do_redirect error ret: %d\n", ret); + goto aborted; + } + break; + default: + fallthrough; + case XDP_ABORTED: +aborted: + printk(KERN_ERR "nfb: %s packet aborted\n", __func__); + fallthrough; + case XDP_DROP: + // TODO: add this into autoconf + // xdp_return_buff definition is missing in 4.18.0-477.10.1.el8_8.x86_64 + // xdp_return_buff(xdp); + xdp_return_frame(xdp_convert_buff_to_frame(xdp)); + break; + } + rcu_read_unlock(); +} + +static inline u16 nfb_xctrl_rx_pp(struct xctrl *ctrl, struct xdp_buff **buffs, u16 nb_pkts) +{ + struct nc_ndp_hdr *hdrs = ctrl->rx.hdr_buffer_cpu; + struct nc_ndp_hdr *hdr; + u32 i; + u16 nb_rx; + u32 shp = ctrl->c.shp; + u32 mhp = ctrl->c.mhp; + + // fill the card with empty buffers + while (nfb_xctrl_rx_fill_pp(ctrl)) + ; + nc_ndp_ctrl_sdp_flush(&ctrl->c); + + // Get the amount of packets ready to be processed + nc_ndp_ctrl_hhp_update(&ctrl->c); + nb_rx = (ctrl->c.hhp - shp) & mhp; + if (nb_pkts < nb_rx) + nb_rx = nb_pkts; + + // ready packets for receive + for (i = 0; i < nb_rx; ++i) { + hdr = &hdrs[shp]; + buffs[i] = ctrl->rx.pp.xdp_ring[shp]; + dma_sync_single_for_cpu(ctrl->dma_dev, page_pool_get_dma_addr(virt_to_page(buffs[i]->data_hard_start)), PAGE_SIZE, DMA_BIDIRECTIONAL); + buffs[i]->data_end = buffs[i]->data + hdr->frame_len; + // NOTE: Right now fragmented buffers are not supported + // Setting this is important if SKB is to be built from pagepool page without copying + // xdp_get_shared_info_from_buff(buffs[i])->nr_frags = 0; + shp = (shp + 1) & mhp; + } + + // update ctrl state + ctrl->c.shp = shp; + + return nb_rx; +} + +int nfb_xctrl_napi_poll_pp(struct napi_struct *napi, int budget) +{ + struct nfb_xdp_queue *rxq = container_of(napi, struct nfb_xdp_queue, napi_pp); + struct xctrl *ctrl = rxq->ctrl; + struct net_device *netdev = napi->dev; + struct nfb_ethdev *ethdev = netdev_priv(netdev); + unsigned received, i = 0; + struct xdp_buff *xdp[NAPI_POLL_WEIGHT]; + + if (unlikely(budget > NAPI_POLL_WEIGHT)) { + printk(KERN_ERR "nfb: NAPI budget is bigger than weight. This is a driver bug.\n"); + BUG(); + } + + received = nfb_xctrl_rx_pp(ctrl, xdp, budget); + for (i = 0; i < received; i++) { + nfb_xctrl_handle_pp(ethdev->prog, xdp[i], rxq); + } + // flush sdp and shp after software processing is done + nc_ndp_ctrl_sp_flush(&ctrl->c); + + // Flushes redirect maps + xdp_do_flush(); + + // Work not done -> reschedule if budget remains + if (received == budget) + return budget; + + // Work done -> finish + napi_complete_done(napi, received); + return received; +} + +// TODO: asynchronous stopping (waiting synchronously for timeout is terrible) +static void nfb_xctrl_stop_pp(struct xctrl *ctrl) +{ + int cnt, i = 0; + int err; + u32 count; + u32 shp = ctrl->c.shp; + u32 mhp = ctrl->c.mhp; + u32 status; + + do { + status = nfb_comp_read32(ctrl->c.comp, NDP_CTRL_REG_STATUS); + if (status & NDP_CTRL_REG_STATUS_RUNNING) { + err = nc_ndp_ctrl_stop(&ctrl->c); + if (err != -EAGAIN && err != -EINPROGRESS) + break; + + if (ctrl->type == NFB_XCTRL_RX) { + // receive packets from card and try again + nc_ndp_ctrl_hhp_update(&ctrl->c); + count = (ctrl->c.hhp - shp) & mhp; + for (i = 0; i < count; ++i) { + // Returns pages to page_pool + // xdp_return_buff definition is missing in 4.18.0-477.10.1.el8_8.x86_64 + // xdp_return_buff(ctrl->rx.pp.xdp_ring[shp]); + xdp_return_frame(xdp_convert_buff_to_frame(ctrl->rx.pp.xdp_ring[shp])); + shp = (shp + 1) & mhp; + } + ctrl->c.shp = shp; + nc_ndp_ctrl_sp_flush(&ctrl->c); + err = nc_ndp_ctrl_stop(&ctrl->c); + if (err != -EAGAIN && err != -EINPROGRESS) + break; + } + mdelay(1); + } + } while (cnt++ < 100); + + if (err) { + err = nc_ndp_ctrl_stop_force(&ctrl->c); + printk("nfb: queue id %u didn't stop in 100 msecs; Force stopping dma ctrl; This might damage firmware.\n", ctrl->nfb_queue_id); + } +} + +struct xctrl *nfb_xctrl_alloc_pp(struct net_device *netdev, u32 queue_id, u32 desc_cnt, enum xdp_ctrl_type type) +{ + struct nfb_ethdev *ethdev = netdev_priv(netdev); + struct nfb_device *nfb = ethdev->nfb; + struct nfb_xdp_channel *channel = ðdev->channels[queue_id]; + struct nfb_xdp_queue *queue; + struct xctrl *ctrl; + int fdt_offset; + u32 i; + struct xdp_buff *buffs; + + struct page_pool_params ppp = { + .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .dev = &nfb->pci->dev, + .dma_dir = DMA_BIDIRECTIONAL, + .max_len = PAGE_SIZE, + .offset = 0, + .order = 0, + .pool_size = desc_cnt, + }; + int err; + + // Finding the fdt offset + switch (type) { + case NFB_XCTRL_RX: + queue = &channel->rxq; + fdt_offset = nfb_comp_find(nfb, "netcope,dma_ctrl_ndp_rx", channel->nfb_index); + break; + case NFB_XCTRL_TX: + queue = &channel->txq; + fdt_offset = nfb_comp_find(nfb, "netcope,dma_ctrl_ndp_tx", channel->nfb_index); + break; + default: + err = -EINVAL; + goto fdt_offset_fail; + break; + } + if (fdt_offset < 0) { + err = -ENODEV; + goto fdt_offset_fail; + } + + ppp.nid = channel->numa; + + // Allocating struct + if (!(ctrl = kzalloc_node(sizeof(struct xctrl), GFP_KERNEL, channel->numa))) { + err = -ENOMEM; + goto ctrl_alloc_fail; + } + + ctrl->type = type; + ctrl->nfb_queue_id = channel->nfb_index; + ctrl->netdev_queue_id = channel->index; + ctrl->dma_dev = &nfb->pci->dev; + ctrl->nb_desc = desc_cnt; + + // Allocating control buffers + switch (type) { + case NFB_XCTRL_RX: + if (!(ctrl->rx.pp.xdp_ring = kzalloc_node(sizeof(struct xdp_buff *) * desc_cnt, GFP_KERNEL, channel->numa))) { + err = -ENOMEM; + goto buff_alloc_fail; + } + if (!(buffs = kzalloc_node(sizeof(struct xdp_buff) * desc_cnt, GFP_KERNEL, channel->numa))) { + err = -ENOMEM; + goto buffs_alloc_fail; + } + break; + case NFB_XCTRL_TX: + spin_lock_init(&ctrl->tx.tx_lock); + if (!(ctrl->tx.buffers = kzalloc_node(sizeof(struct xctrl_tx_buffer) * desc_cnt, GFP_KERNEL, channel->numa))) { + err = -ENOMEM; + goto buff_alloc_fail; + } + break; + default: + err = -EINVAL; + goto fdt_offset_fail; + break; + } + + // Allocating DMA buffers + if (!(ctrl->desc_buffer_virt = dma_alloc_coherent(ctrl->dma_dev, ctrl->nb_desc * sizeof(struct nc_ndp_desc), &ctrl->desc_buffer_dma, GFP_KERNEL))) { + err = -ENOMEM; + goto dma_data_fail; + } + if (!(ctrl->update_buffer_virt = dma_alloc_coherent(ctrl->dma_dev, sizeof(u32) * 2, &ctrl->update_buffer_dma, GFP_KERNEL))) { + err = -ENOMEM; + goto dma_update_fail; + } + + if (type == NFB_XCTRL_RX) { + ctrl->rx.nb_hdr = desc_cnt; + if (!(ctrl->rx.hdr_buffer_cpu = dma_alloc_coherent(ctrl->dma_dev, ctrl->rx.nb_hdr * sizeof(struct nc_ndp_hdr), &ctrl->rx.hdr_buffer_dma, GFP_KERNEL))) { + err = -ENOMEM; + goto dma_hdr_fail; + } + } + + // creating page pool and info + if (type == NFB_XCTRL_RX) { + if (!(ctrl->rx.pp.pool = page_pool_create(&ppp))) { + printk(KERN_ERR "nfb: Failed to create pagepool\n"); + err = -ENOMEM; + goto pp_alloc_fail; + } + if ((err = xdp_rxq_info_reg(&ctrl->rx.rxq_info, netdev, channel->index, 0))) { + printk(KERN_ERR "nfb: rx_info register fail with: %d\n", err); + goto meminfo_reg_fail; + } + if ((err = xdp_rxq_info_reg_mem_model(&ctrl->rx.rxq_info, MEM_TYPE_PAGE_POOL, ctrl->rx.pp.pool))) { + printk(KERN_ERR "nfb: mem_model register fail with: %d\n", err); + goto meminfo_model_fail; + } + + for (i = 0; i < desc_cnt; i++) { + ctrl->rx.pp.xdp_ring[i] = &buffs[i]; + } + } + + // Opening controller + if ((err = nc_ndp_ctrl_open(nfb, fdt_offset, &ctrl->c))) { + goto ndp_ctrl_open_fail; + } + + return ctrl; + +ndp_ctrl_open_fail: + if (type == NFB_XCTRL_RX) { + xdp_rxq_info_unreg_mem_model(&ctrl->rx.rxq_info); + } +meminfo_model_fail: + if (type == NFB_XCTRL_RX) { + xdp_rxq_info_unreg(&ctrl->rx.rxq_info); + } +meminfo_reg_fail: + if (type == NFB_XCTRL_RX) { + page_pool_destroy(ctrl->rx.pp.pool); + } +pp_alloc_fail: + if (type == NFB_XCTRL_RX) { + dma_free_coherent(ctrl->dma_dev, ctrl->rx.nb_hdr * sizeof(struct nc_ndp_hdr), ctrl->rx.hdr_buffer_cpu, ctrl->rx.hdr_buffer_dma); + } +dma_hdr_fail: + dma_free_coherent(ctrl->dma_dev, sizeof(u32) * 2, ctrl->update_buffer_virt, ctrl->update_buffer_dma); +dma_update_fail: + dma_free_coherent(ctrl->dma_dev, ctrl->nb_desc * sizeof(struct nc_ndp_desc), ctrl->desc_buffer_virt, ctrl->desc_buffer_dma); +dma_data_fail: + kfree(buffs); +buffs_alloc_fail: + switch (type) { + case NFB_XCTRL_RX: + kfree(ctrl->rx.pp.xdp_ring); + break; + case NFB_XCTRL_TX: + kfree(ctrl->tx.buffers); + break; + default: + break; + } +buff_alloc_fail: + kfree(ctrl); +ctrl_alloc_fail: +fdt_offset_fail: + printk(KERN_ERR "nfb: Error opening dma ctrl on queue %d; %d", channel->nfb_index, err); + return NULL; +} + +void nfb_xctrl_destroy_pp(struct xctrl *ctrl) +{ + if (test_bit(XCTRL_STATUS_IS_RUNNING, &ctrl->status)) { + nfb_xctrl_stop_pp(ctrl); + } + nc_ndp_ctrl_close(&ctrl->c); + dma_free_coherent(ctrl->dma_dev, ctrl->nb_desc * sizeof(struct nc_ndp_desc), ctrl->desc_buffer_virt, ctrl->desc_buffer_dma); + dma_free_coherent(ctrl->dma_dev, sizeof(u32) * 2, ctrl->update_buffer_virt, ctrl->update_buffer_dma); + switch (ctrl->type) { + case NFB_XCTRL_RX: + dma_free_coherent(ctrl->dma_dev, ctrl->rx.nb_hdr * sizeof(struct nc_ndp_hdr), ctrl->rx.hdr_buffer_cpu, ctrl->rx.hdr_buffer_dma); + // Unreg_mem_model calls page_pool_destroy internally + // page_pool_destroy(ctrl->rx.pp.pool); + xdp_rxq_info_unreg_mem_model(&ctrl->rx.rxq_info); + xdp_rxq_info_unreg(&ctrl->rx.rxq_info); + kfree(ctrl->rx.pp.xdp_ring[0]); + kfree(ctrl->rx.pp.xdp_ring); + break; + case NFB_XCTRL_TX: + // free all enqueued tx buffers + ctrl->c.hdp = ctrl->c.sdp; + nfb_xctrl_tx_free_buffers(ctrl); + kfree(ctrl->tx.buffers); + break; + default: + break; + } + kfree(ctrl); + ctrl = NULL; +} diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c new file mode 100644 index 00000000..3b648e37 --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c @@ -0,0 +1,588 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - ctrl module for AF_XDP / zero-copy operation + * memory is allocated from the userspace + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#include "ctrl_xdp_common.h" +#include + +// NOTE: This is not zero copy operation, the correct way to rexmit a frame +// in XSK mode is through the userspace from RX ring to TX ring. +/** + * @brief Tries to rexmit xsk buffer. Frees buffer on fail via xdp_return_frame(); + * + * @param ctrl + * @param xdp + * @return 0 on success + */ +static inline int nfb_xctrl_rexmit_xsk(struct xctrl *ctrl, struct xdp_buff *xdp) +{ + int ret = 0; + struct xdp_frame *frame; + // xdp_convert_buff_to_frame frees the xsk on success and doesn't free on failure + // this is af_xdp slow fallback + if (unlikely(!(frame = xdp_convert_buff_to_frame(xdp)))) { + xdp_return_frame(frame); + ret = -ENOMEM; + goto exit; + } + spin_lock(&ctrl->tx.tx_lock); + { + // reclaim tx buffers + nc_ndp_ctrl_hdp_update(&ctrl->c); + nfb_xctrl_tx_free_buffers(ctrl); + // process tx + ret = nfb_xctrl_tx_submit_frame_needs_lock(ctrl, frame); + if (unlikely(ret)) { + xdp_return_frame(frame); + } + // flush + nc_ndp_ctrl_sdp_flush(&ctrl->c); + } + spin_unlock(&ctrl->tx.tx_lock); +exit: + return ret; +} + +#ifndef CONFIG_HAVE_XSK_BUFF_ALLOC_BATCH +static inline u32 xsk_buff_alloc_batch(struct xsk_buff_pool *pool, struct xdp_buff **xdp, u32 max) +{ + unsigned i = 0; + do { + xdp[i] = xsk_buff_alloc(pool); + } while (xdp[i++] && i < max); + return i; +} +#endif + +/** + * @brief XSK pool operation to fill card with rx descriptors. + * + * @param ctrl + * @param pool struct xsk_buff_pool + * @return int number of descriptors fileld + */ +static inline int nfb_xctrl_rx_fill_xsk(struct xctrl *ctrl) +{ + const u32 batch_size = NFB_XDP_CTRL_PACKET_BURST; + + // ctrl vars + u64 last_upper_addr = ctrl->c.last_upper_addr; + u32 mdp = ctrl->c.mdp; + u32 sdp = ctrl->c.sdp; + u32 mhp = ctrl->c.mhp; + u32 php = ctrl->rx.php; + + // helper vars + u32 frame_len; + struct xsk_buff_pool *pool = ctrl->rx.xsk.pool; + struct xdp_buff *buffs[NFB_XDP_CTRL_PACKET_BURST]; + dma_addr_t dma; + struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; + u32 free_desc, free_hdrs; + u32 real_count, i; + + // Check if refill needed + nc_ndp_ctrl_hdp_update(&ctrl->c); + free_hdrs = (ctrl->c.shp - php - 1) & mhp; + free_desc = (ctrl->c.hdp - sdp - 1) & mdp; + if (free_hdrs < batch_size || free_desc < batch_size) + return 0; + + // Alloc xsk buffers + frame_len = xsk_pool_get_rx_frame_size(pool); // internaly calculates with XDP_PACKET_HEADROOM + real_count = xsk_buff_alloc_batch(pool, buffs, batch_size); + for (i = 0; i < real_count; i++) { + dma = xsk_buff_xdp_get_dma(buffs[i]); // Takes XDP_PACKET_HEADROOM into account + + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { + if (unlikely(free_desc == 0)) { + break; + } + last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); + ctrl->c.last_upper_addr = last_upper_addr; + descs[sdp] = nc_ndp_rx_desc0(dma); + sdp = (sdp + 1) & mdp; + free_desc--; + } + if (unlikely(free_desc == 0)) { + break; + } + ctrl->rx.xsk.xdp_ring[php] = buffs[i]; + descs[sdp] = nc_ndp_rx_desc2(dma, frame_len, 0); + sdp = (sdp + 1) & mdp; + php = (php + 1) & mhp; + free_desc--; + } + + // if the loop quits because there was too little free descriptors + // the remaining buffers have to be freed + for (; i < real_count; i++) { + xsk_buff_free(buffs[i]); + } + + // update ctrl state + ctrl->rx.php = php; + ctrl->c.sdp = sdp; + return i; +} + +/** + * @brief XDP handler + * + * @param prog + * @param xdp + * @param rxq + * @return result + */ +static inline void nfb_xctrl_handle_xsk(struct bpf_prog *prog, struct xdp_buff *xdp, struct nfb_xdp_queue *rxq) +{ + unsigned act; + int ret; + struct xdp_frame *frame; + struct sk_buff *skb; + struct bpf_prog *xdp_prog; + struct nfb_xdp_channel *channel = container_of(rxq, struct nfb_xdp_channel, rxq); + struct nfb_ethdev *ethdev = channel->ethdev; + + rcu_read_lock(); + xdp_prog = rcu_dereference(prog); + if (xdp_prog) { + act = bpf_prog_run_xdp(xdp_prog, xdp); + } else { + act = XDP_PASS; + } + switch (act) { + case XDP_PASS: + // This allocates memory => AF_XDP slow fallback for normal operation + frame = xdp_convert_buff_to_frame(xdp); + if (unlikely(!frame)) { + printk(KERN_DEBUG "SKB build failed\n"); + goto aborted; + } + // NOTE: This function does a lot of things internally, check it's implementation + // if you ever want to add support for fragmented packets + skb = xdp_build_skb_from_frame(frame, ethdev->netdev); + if (unlikely(IS_ERR_OR_NULL(skb))) { + printk(KERN_DEBUG "SKB build failed\n"); + goto aborted; + } + // receive packet onto queue it arriverd on + skb_record_rx_queue(skb, channel->index); + // TODO gro_receive is supposed to be a free + // performance boost but it is quite bad for + // debugging because you cannot check if all packet + // received are the same as sent + // napi_gro_receive(napi, skb); + netif_receive_skb(skb); + // TODO: future extension + // if (netif_receive_skb(skb) != NET_RX_DROP) { + // ctrl.stats = ... + // } else { + // ctrl.stats = ... + // } + break; + case XDP_TX: + // returned on tx reclaim; + nfb_xctrl_rexmit_xsk(channel->txq.ctrl, xdp); + break; + case XDP_REDIRECT: + // either redirected to userspace or returned internally + ret = xdp_do_redirect(ethdev->netdev, xdp, xdp_prog); + if (unlikely(ret)) { + printk(KERN_ERR "nfb: xdp_do_redirect error ret: %d\n", ret); + } + break; + default: + fallthrough; + case XDP_ABORTED: +aborted: + printk(KERN_ERR "nfb: %s packet aborted\n", __func__); + fallthrough; + case XDP_DROP: + xsk_buff_free(xdp); + break; + } + rcu_read_unlock(); +} + +#ifndef CONFIG_HAVE_XSK_BUFF_SET_SIZE +static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size) +{ + xdp->data = xdp->data_hard_start + XDP_PACKET_HEADROOM; + xdp->data_meta = xdp->data; + xdp->data_end = xdp->data + size; +} +#endif + +static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, struct xdp_buff **buffs, u16 nb_pkts) +{ + struct xdp_buff *buff; + struct nc_ndp_hdr *hdrs = ctrl->rx.hdr_buffer_cpu; + struct nc_ndp_hdr *hdr; + u32 i; + u16 nb_rx; + u32 shp = ctrl->c.shp; + u32 mhp = ctrl->c.mhp; + + // fill the card with empty buffers + while (nfb_xctrl_rx_fill_xsk(ctrl)) + ; + nc_ndp_ctrl_sdp_flush(&ctrl->c); + + // get the amount of packets ready to be processed + nc_ndp_ctrl_hhp_update(&ctrl->c); + nb_rx = (ctrl->c.hhp - shp) & mhp; + if (nb_pkts < nb_rx) + nb_rx = nb_pkts; + + // ready packets for receive + for (i = 0; i < nb_rx; ++i) { + buff = ctrl->rx.xsk.xdp_ring[shp]; + hdr = &hdrs[shp]; + xsk_buff_set_size(buff, hdr->frame_len); // sets the actual data size after receive + xsk_buff_dma_sync_for_cpu(buff, ctrl->rx.xsk.pool); + buffs[i] = buff; + shp = (shp + 1) & mhp; + } + + // update ctrl state + ctrl->c.shp = shp; + return nb_rx; +} + +int nfb_xctrl_napi_poll_rx_xsk(struct napi_struct *napi, int budget) +{ + struct nfb_xdp_queue *rxq = container_of(napi, struct nfb_xdp_queue, napi_xsk); + struct xctrl *ctrl = rxq->ctrl; + struct net_device *netdev = napi->dev; + struct nfb_ethdev *ethdev = netdev_priv(netdev); + unsigned received, i = 0; + struct xdp_buff *xdp[NAPI_POLL_WEIGHT]; + + if (unlikely(budget > NAPI_POLL_WEIGHT)) { + printk(KERN_ERR "nfb: NAPI budget is bigger than weight. This is a driver bug.\n"); + BUG(); + } + + received = nfb_xctrl_rx_xsk(ctrl, xdp, budget); + for (i = 0; i < received; i++) { + if (unlikely(PAGE_SIZE < xdp[i]->data_end - xdp[i]->data_hard_start)) { + printk(KERN_ERR "nfb: XSK got packet too large, current max size: %lu\n", PAGE_SIZE - (xdp[i]->data - xdp[i]->data_hard_start)); + xsk_buff_free(xdp[i]); + continue; + } + nfb_xctrl_handle_xsk(ethdev->prog, xdp[i], rxq); + } + // flush sdp and shp after software processing is done + nc_ndp_ctrl_sp_flush(&ctrl->c); + + // Flushes redirect maps + xdp_do_flush(); + + // Work not done -> reschedule if budget remains + if (received == budget) + return budget; + + // Work done -> finish + napi_complete_done(napi, received); + return received; +} + +int nfb_xctrl_napi_poll_tx_xsk(struct napi_struct *napi, int budget) +{ + struct nfb_xdp_queue *txq = container_of(napi, struct nfb_xdp_queue, napi_xsk); + struct nfb_xdp_channel *channel = container_of(txq, struct nfb_xdp_channel, txq); + struct xctrl *ctrl = txq->ctrl; + struct xsk_buff_pool *pool = channel->pool; + struct xdp_desc *buffs; + u32 free_desc; + u32 ready, i = 0; + dma_addr_t dma; + void *data; + u32 len; + u32 min_len = ETH_ZLEN; + + u64 last_upper_addr = ctrl->c.last_upper_addr; + u32 sdp = ctrl->c.sdp; + u32 mdp = ctrl->c.mdp; + struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; + + spin_lock(&ctrl->tx.tx_lock); + { + // free the completed buffers + nc_ndp_ctrl_hdp_update(&ctrl->c); + nfb_xctrl_tx_free_buffers(ctrl); + xsk_tx_completed(pool, ctrl->tx.completed_xsk_tx); + ctrl->tx.completed_xsk_tx = 0; + + free_desc = (ctrl->tx.fdp - sdp - 1) & mdp; + + ready = xsk_tx_peek_release_desc_batch(pool, budget); + if (!ready) { + goto out; + } + + buffs = pool->tx_descs; + for (i = 0; i < ready; i++) { + data = xsk_buff_raw_get_data(pool, buffs[i].addr); + dma = xsk_buff_raw_get_dma(pool, buffs[i].addr); + len = buffs[i].len; + + // TODO: There should be a len check. using pool.frame_len somewhere when setting up the xsk queue + if (len < min_len) { // Usable frame space is smaller than min_len. + // printk(KERN_DEBUG "TX: %s memsetting len: %d to %d\n", __func__, len, min_len); + memset(data + len, 0, min_len - len); + len = min_len; + } + + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { + if (unlikely(free_desc < 2)) { + printk(KERN_ERR "nfb: %s busy warning\n", __func__); + goto out; + } + + last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); + ctrl->c.last_upper_addr = last_upper_addr; + descs[sdp] = nc_ndp_tx_desc0(dma); + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; + free_desc--; + sdp = (sdp + 1) & mdp; + } + + if (unlikely(free_desc == 0)) { + printk(KERN_ERR "nfb: nfb_xctrl_xmit busy warning\n"); + goto out; + } + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_XSK; + ctrl->tx.buffers[sdp].num_of_xsk_completions = 1 + ctrl->tx.last_napi_xsk_drops; + ctrl->tx.last_napi_xsk_drops = 0; + ctrl->tx.buffers[sdp].dma = dma; + ctrl->tx.buffers[sdp].len = len; + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + xsk_buff_raw_dma_sync_for_device(pool, dma, len); + free_desc--; + sdp = (sdp + 1) & mdp; + } +out: + // update ctrl + ctrl->tx.last_napi_xsk_drops += ready - i; + ctrl->c.sdp = sdp; + + // flush counters when done + nc_ndp_ctrl_sdp_flush(&ctrl->c); + } + spin_unlock(&ctrl->tx.tx_lock); + + // Work not done -> reschedule if budget remains + if (i == budget) + return budget; + + // Work done -> finish + napi_complete_done(napi, i); + return i; +} + +static void nfb_xctrl_stop_xsk(struct xctrl *ctrl) +{ + int cnt, i = 0; + int err; + u32 count; + u32 shp = ctrl->c.shp; + u32 mhp = ctrl->c.mhp; + struct xdp_buff *xdp; + + do { + err = nc_ndp_ctrl_stop(&ctrl->c); + if (err != -EAGAIN && err != -EINPROGRESS) + break; + + // receive packets from card and try again + nc_ndp_ctrl_hhp_update(&ctrl->c); + count = (ctrl->c.hhp - shp) & mhp; + for (i = 0; i < count; ++i) { + xdp = ctrl->rx.xsk.xdp_ring[shp]; + xsk_buff_free(xdp); + shp = (shp + 1) & mhp; + } + ctrl->c.shp = shp; + nc_ndp_ctrl_sp_flush(&ctrl->c); + mdelay(1); + } while (cnt++ < 100); + + if (err) { + err = nc_ndp_ctrl_stop_force(&ctrl->c); + printk(KERN_WARNING "nfb: queue id %u didn't stop in 100 msecs; Force stopping dma ctrl; This might damage firmware.\n", ctrl->nfb_queue_id); + } +} + +struct xctrl *nfb_xctrl_alloc_xsk(struct net_device *netdev, u32 queue_id, struct xsk_buff_pool *pool, enum xdp_ctrl_type type) +{ + struct nfb_ethdev *ethdev = netdev_priv(netdev); + struct nfb_xdp_channel *channel = ðdev->channels[queue_id]; + struct nfb_device *nfb = ethdev->nfb; + struct nfb_xdp_queue *queue; + struct xctrl *ctrl; + int fdt_offset; + + int err; + // Finding the fdt offset + switch (type) { + case NFB_XCTRL_RX: + queue = &channel->rxq; + fdt_offset = nfb_comp_find(nfb, "netcope,dma_ctrl_ndp_rx", channel->nfb_index); + break; + case NFB_XCTRL_TX: + queue = &channel->txq; + fdt_offset = nfb_comp_find(nfb, "netcope,dma_ctrl_ndp_tx", channel->nfb_index); + break; + default: + err = -EINVAL; + goto fdt_offset_fail; + break; + } + if (fdt_offset < 0) { + err = -ENODEV; + goto fdt_offset_fail; + } + + // Allocating struct + if (!(ctrl = kzalloc_node(sizeof(struct xctrl), GFP_KERNEL, channel->numa))) { + err = -ENOMEM; + goto ctrl_alloc_fail; + } + + ctrl->type = type; + ctrl->nfb_queue_id = channel->nfb_index; + ctrl->netdev_queue_id = channel->index; + ctrl->dma_dev = &nfb->pci->dev; + ctrl->nb_desc = pool->heads_cnt * 2; + + // Allocating control buffers + switch (type) { + case NFB_XCTRL_RX: + if (!(ctrl->rx.xsk.xdp_ring = kzalloc_node(sizeof(struct xdp_buff *) * ctrl->nb_desc, GFP_KERNEL, channel->numa))) { + err = -ENOMEM; + goto buff_alloc_fail; + } + break; + case NFB_XCTRL_TX: + spin_lock_init(&ctrl->tx.tx_lock); + if (!(ctrl->tx.buffers = kzalloc_node(sizeof(struct xctrl_tx_buffer) * ctrl->nb_desc, GFP_KERNEL, channel->numa))) { + err = -ENOMEM; + goto buff_alloc_fail; + } + break; + default: + err = -EINVAL; + goto buff_alloc_fail; + break; + } + + // Allocating DMA buffers + if (!(ctrl->desc_buffer_virt = dma_alloc_coherent(ctrl->dma_dev, ctrl->nb_desc * sizeof(struct nc_ndp_desc), &ctrl->desc_buffer_dma, GFP_KERNEL))) { + err = -ENOMEM; + goto dma_data_fail; + } + if (!(ctrl->update_buffer_virt = dma_alloc_coherent(ctrl->dma_dev, sizeof(u32) * 2, &ctrl->update_buffer_dma, GFP_KERNEL))) { + err = -ENOMEM; + goto dma_update_fail; + } + + if (type == NFB_XCTRL_RX) { + ctrl->rx.nb_hdr = ctrl->nb_desc; + if (!(ctrl->rx.hdr_buffer_cpu = dma_alloc_coherent(ctrl->dma_dev, ctrl->rx.nb_hdr * sizeof(struct nc_ndp_hdr), &ctrl->rx.hdr_buffer_dma, GFP_KERNEL))) { + err = -ENOMEM; + goto dma_hdr_fail; + } + } + + // creating info + if (type == NFB_XCTRL_RX) { + ctrl->rx.xsk.pool = pool; + if ((err = xdp_rxq_info_reg(&ctrl->rx.rxq_info, netdev, channel->index, 0))) { + printk(KERN_ERR "nfb: rx_info register fail with: %d\n", err); + goto meminfo_reg_fail; + } + if ((err = xdp_rxq_info_reg_mem_model(&ctrl->rx.rxq_info, MEM_TYPE_XSK_BUFF_POOL, NULL))) { + printk(KERN_ERR "nfb: mem_model register fail with: %d\n", err); + goto meminfo_model_fail; + } + + xsk_pool_set_rxq_info(pool, &ctrl->rx.rxq_info); + } + + // Opening controller + if ((err = nc_ndp_ctrl_open(nfb, fdt_offset, &ctrl->c))) { + goto ndp_ctrl_open_fail; + } + + return ctrl; + +ndp_ctrl_open_fail: + if (type == NFB_XCTRL_RX) { + xdp_rxq_info_unreg_mem_model(&ctrl->rx.rxq_info); + } +meminfo_model_fail: + if (type == NFB_XCTRL_RX) { + xdp_rxq_info_unreg(&ctrl->rx.rxq_info); + } +meminfo_reg_fail: + if (type == NFB_XCTRL_RX) { + dma_free_coherent(ctrl->dma_dev, ctrl->rx.nb_hdr * sizeof(struct nc_ndp_hdr), ctrl->rx.hdr_buffer_cpu, ctrl->rx.hdr_buffer_dma); + } +dma_hdr_fail: + dma_free_coherent(ctrl->dma_dev, sizeof(u32) * 2, ctrl->update_buffer_virt, ctrl->update_buffer_dma); +dma_update_fail: + dma_free_coherent(ctrl->dma_dev, ctrl->nb_desc * sizeof(struct nc_ndp_desc), ctrl->desc_buffer_virt, ctrl->desc_buffer_dma); +dma_data_fail: + switch (type) { + case NFB_XCTRL_RX: + kfree(ctrl->rx.xsk.xdp_ring); + break; + case NFB_XCTRL_TX: + kfree(ctrl->tx.buffers); + break; + default: + break; + } +buff_alloc_fail: + kfree(ctrl); +ctrl_alloc_fail: +fdt_offset_fail: + printk(KERN_ERR "nfb: Error opening dma ctrl on queue %d; %d", channel->nfb_index, err); + return NULL; +} + +void nfb_xctrl_destroy_xsk(struct xctrl *ctrl) +{ + if (test_bit(XCTRL_STATUS_IS_RUNNING, &ctrl->status)) { + nfb_xctrl_stop_xsk(ctrl); + } + nc_ndp_ctrl_close(&ctrl->c); + dma_free_coherent(ctrl->dma_dev, ctrl->nb_desc * sizeof(struct nc_ndp_desc), ctrl->desc_buffer_virt, ctrl->desc_buffer_dma); + dma_free_coherent(ctrl->dma_dev, sizeof(u32) * 2, ctrl->update_buffer_virt, ctrl->update_buffer_dma); + switch (ctrl->type) { + case NFB_XCTRL_RX: + dma_free_coherent(ctrl->dma_dev, ctrl->rx.nb_hdr * sizeof(struct nc_ndp_hdr), ctrl->rx.hdr_buffer_cpu, ctrl->rx.hdr_buffer_dma); + xdp_rxq_info_unreg_mem_model(&ctrl->rx.rxq_info); + xdp_rxq_info_unreg(&ctrl->rx.rxq_info); + kfree(ctrl->rx.xsk.xdp_ring); + break; + case NFB_XCTRL_TX: + // free all enqueued tx buffers + ctrl->c.hdp = ctrl->c.sdp; + nfb_xctrl_tx_free_buffers(ctrl); + kfree(ctrl->tx.buffers); + break; + default: + break; + } + kfree(ctrl); + ctrl = NULL; +} diff --git a/drivers/kernel/drivers/nfb/xdp/driver.c b/drivers/kernel/drivers/nfb/xdp/driver.c new file mode 100644 index 00000000..de2d3af7 --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/driver.c @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - main driver module + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#include +#include +#include + +#include + +#include "../nfb.h" +#include + +#include "driver.h" +#include "ethdev.h" + +#define COMP_NETCOPE_RX "netcope,dma_ctrl_ndp_rx" +#define COMP_NETCOPE_TX "netcope,dma_ctrl_ndp_tx" + +static bool xdp_enable = 0; + +int nfb_xdp_attach(struct nfb_device *nfb, void **priv) +{ + struct nfb_xdp *module; + struct nfb_ethdev *ethdev, *tmp; + u16 ethc, rxqc, txqc; + int fdt_offset; + u16 i; + int ret; + + if (!xdp_enable) { + return 0; + } + + // count the ports and queues + ethc = nfb_comp_count(nfb, COMP_NETCOPE_ETH); + if (ethc <= 0) { + dev_warn(&nfb->pci->dev, "nfb_xdp: No eth interfaces available\n"); + return -EINVAL; + } + + rxqc = nfb_comp_count(nfb, COMP_NETCOPE_RX); + if (rxqc <= 0) { + dev_warn(&nfb->pci->dev, "nfb_xdp: No RX queues available\n"); + return -EINVAL; + } + + txqc = nfb_comp_count(nfb, COMP_NETCOPE_TX); + if (txqc <= 0) { + dev_warn(&nfb->pci->dev, "nfb_xdp: No TX queues available\n"); + return -EINVAL; + } + + // sanity checks; we expect there will be the same amount of queue pairs for each eth port + if (rxqc != txqc) { + dev_warn(&nfb->pci->dev, "nfb_xdp: TX and RX queue count differs, xdp operates with queue pairs TXc: %u, RXc: %u\n", txqc, rxqc); + return -EINVAL; + } + if (rxqc % ethc != 0) { + dev_warn(&nfb->pci->dev, "nfb_xdp: Queue pairs are not divisible by ports, don't know how to initilize TXc: %u, RXc: %u, ETHc: %u\n", txqc, rxqc, ethc); + return -EINVAL; + } + + module = kzalloc(sizeof(*module), GFP_KERNEL); + if (!module) { + dev_warn(&nfb->pci->dev, "nfb_xdp: Failed to alloc module\n"); + return -ENOMEM; + } + *priv = module; + + INIT_LIST_HEAD(&module->list_devices); + + module->ethc = ethc; + module->rxqc = rxqc; + module->txqc = txqc; + module->nfb = nfb; + + memset(&module->dev, 0, sizeof(struct device)); + device_initialize(&module->dev); + module->dev.parent = nfb->dev; + dev_set_name(&module->dev, "nfb_xdp"); + dev_set_drvdata(&module->dev, module); + ret = device_add(&module->dev); + if (ret) { + goto err_dev_add; + } + + i = 0; + fdt_for_each_compatible_node(nfb->fdt, fdt_offset, COMP_NETCOPE_ETH) { + ethdev = create_ethdev(module, fdt_offset, i); + if (!ethdev) { + dev_warn(&nfb->pci->dev, "nfb_xdp: failed to create eth port\n"); + goto err_ethdev; + } + list_add_tail(ðdev->list, &module->list_devices); + i++; + } + + if (i != ethc) { + dev_warn(&nfb->pci->dev, "nfb_xdp: failed to create eth port\n"); + goto err_ethdev; + } + + dev_info(&nfb->pci->dev, "nfb_xdp: attached\n"); + return 0; + +err_ethdev: + list_for_each_entry_safe(ethdev, tmp, &module->list_devices, list) { + destroy_ethdev(ethdev); + } +err_dev_add: + kfree(module); + *priv = NULL; + return ret; +} + +void nfb_xdp_detach(struct nfb_device *nfb, void *priv) +{ + struct nfb_xdp *module = priv; + struct nfb_ethdev *ethdev, *tmp; + + if (!module) { + return; + } + + list_for_each_entry_safe(ethdev, tmp, &module->list_devices, list) { + destroy_ethdev(ethdev); + } + + device_del(&module->dev); + kfree(module); + dev_info(&nfb->pci->dev, "nfb_xdp: detached\n"); +} + +module_param(xdp_enable, bool, S_IRUGO); +MODULE_PARM_DESC(xdp_enable, "Creates XDP capable netdevice for each Ethernet interface [no]"); diff --git a/drivers/kernel/drivers/nfb/xdp/driver.h b/drivers/kernel/drivers/nfb/xdp/driver.h new file mode 100644 index 00000000..59e350bc --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/driver.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - public header + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#ifndef NFB_XDP_DRIVER_H +#define NFB_XDP_DRIVER_H + +#include "../nfb.h" + +int nfb_xdp_attach(struct nfb_device *nfb, void **priv); +void nfb_xdp_detach(struct nfb_device *nfb, void *priv); + +// struct holding xdp driver module info +struct nfb_xdp { + struct nfb_device *nfb; /*Top level structure describing nfb device*/ + struct device dev; /*device describing nfb_xdp module*/ + struct list_head list_devices; /*List of eth devices*/ + + u16 ethc; /* Number of ETH ports*/ + u16 rxqc; /* Absolute number of rx queues */ + u16 txqc; /* Absolute number of tx queues */ +}; + +#endif // NFB_XDP_DRIVER_H diff --git a/drivers/kernel/drivers/nfb/xdp/ethdev.c b/drivers/kernel/drivers/nfb/xdp/ethdev.c new file mode 100644 index 00000000..39092830 --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/ethdev.c @@ -0,0 +1,316 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - ethdev module + * ethdev corresponds to single physical port on NIC and linux network interface + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#include +#include +#include + +#include "../nfb.h" + +#include +#include +#include + +#include "driver.h" +#include "ethdev.h" +#include "channel.h" +#include "ctrl_xdp.h" + +static int nfb_xdp_channels_init(struct net_device *netdev) +{ + int i, ret = 0; + struct nfb_ethdev *ethdev = netdev_priv(netdev); + // printk("LOG: %s called", __func__); + ethdev->channels = kzalloc(sizeof(*ethdev->channels) * ethdev->channel_count, GFP_KERNEL); + if (!ethdev->channels) { + ret = -ENOMEM; + goto err_channel_alloc; + } + + for (i = 0; i < ethdev->channel_count; i++) { + mutex_init(ðdev->channels[i].state_mutex); + ethdev->channels[i].ethdev = ethdev; + ethdev->channels[i].index = i; + ethdev->channels[i].nfb_index = i + ethdev->channel_count * ethdev->index; + ethdev->channels[i].numa = dev_to_node(ðdev->nfb->pci->dev); +#ifdef CONFIG_HAVE_NETIF_NAPI_ADD_WITH_WEIGHT + netif_napi_add(netdev, ðdev->channels[i].rxq.napi_pp, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); + netif_napi_add(netdev, ðdev->channels[i].rxq.napi_xsk, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); +#else + netif_napi_add_weight(netdev, ðdev->channels[i].rxq.napi_pp, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); + netif_napi_add_weight(netdev, ðdev->channels[i].rxq.napi_xsk, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); +#endif +#ifdef CONFIG_HAVE_NETIF_NAPI_ADD_TX_WEIGHT + netif_napi_add_tx_weight(netdev, ðdev->channels[i].txq.napi_xsk, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); +#else + netif_tx_napi_add(netdev, ðdev->channels[i].txq.napi_xsk, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); +#endif + } + +err_channel_alloc: + return ret; +} + +static void nfb_xdp_channels_deinit(struct net_device *netdev) +{ + u32 i; + struct nfb_ethdev *ethdev = netdev_priv(netdev); + // printk("LOG: %s called", __func__); + for (i = 0; i < ethdev->channel_count; i++) { + netif_napi_del(ðdev->channels[i].rxq.napi_pp); + netif_napi_del(ðdev->channels[i].rxq.napi_xsk); + netif_napi_del(ðdev->channels[i].txq.napi_xsk); + } + kfree(ethdev->channels); +} + +#ifndef CONFIG_HAVE_XDP_SET_FEATURES_FLAG +#ifdef CONFIG_HAVE_XDP_FEATURES_T +static void xdp_set_features_flag(struct net_device *dev, xdp_features_t val) +{ + if (dev->xdp_features == val) + return; + + dev->xdp_features = val; + + if (dev->reg_state == NETREG_REGISTERED) + call_netdevice_notifiers(NETDEV_XDP_FEAT_CHANGE, dev); +} +#endif +#endif + +static void nfb_stop_channels(struct net_device *netdev) +{ + struct nfb_ethdev *ethdev = netdev_priv(netdev); + struct nfb_xdp_channel *channel; + unsigned i; + struct bpf_prog *old_prog; + // printk("LOG: %s called", __func__); + spin_lock(ðdev->prog_lock); + old_prog = rcu_replace_pointer(ethdev->prog, NULL, lockdep_is_held(ðdev->prog_lock)); + if (old_prog) { + bpf_prog_put(old_prog); + } + spin_unlock(ðdev->prog_lock); + synchronize_rcu(); + + // Stop all TX queues + netif_tx_stop_all_queues(netdev); + + // disable mac + if (ethdev->nc_rxmac) + nc_rxmac_disable(ethdev->nc_rxmac); + if (ethdev->nc_txmac) + nc_txmac_disable(ethdev->nc_txmac); + + // Stop all threads + for (i = 0; i < ethdev->channel_count; i++) { + channel = ðdev->channels[i]; + channel_stop(channel); + } +} + +static int nfb_start_channels(struct net_device *netdev) +{ + struct nfb_ethdev *ethdev = netdev_priv(netdev); + struct nfb_xdp_channel *channel; + int i, ret; + +#ifdef CONFIG_HAVE_XDP_FEATURES_T + // TODO: + // Support segmented packets + // set XDP capabilities for netdevice + // Only works on newer kernels + xdp_features_t val; + val = NETDEV_XDP_ACT_BASIC + | NETDEV_XDP_ACT_REDIRECT + | NETDEV_XDP_ACT_XSK_ZEROCOPY + // | NETDEV_XDP_ACT_RX_SG + | NETDEV_XDP_ACT_NDO_XMIT + // | NETDEV_XDP_ACT_NDO_XMIT_SG + ; + xdp_set_features_flag(netdev, val); +#endif + + // Threads take care of setting up and tearing down the queues as XDP demands the abillity to do that on the fly + for (i = 0; i < ethdev->channel_count; i++) { + channel = ðdev->channels[i]; + if ((ret = channel_start_pp(channel))) { + goto err_channel_start; + } + } + + // enable mac + if (ethdev->nc_rxmac) + nc_rxmac_enable(ethdev->nc_rxmac); + if (ethdev->nc_txmac) + nc_txmac_enable(ethdev->nc_txmac); + + return ret; +err_channel_start: + printk(KERN_ERR "nfb: failed to start channels\n"); + nfb_stop_channels(netdev); + return ret; +} + +static int nfb_xdp_open(struct net_device *netdev) +{ + int ret; + struct nfb_ethdev *ethdev = netdev_priv(netdev); + // printk("LOG: %s called", __func__); + ret = nfb_start_channels(netdev); + schedule_work(ðdev->link_work); + mod_timer(ðdev->link_timer, jiffies + HZ * 1); + return ret; +} + +static int nfb_xdp_stop(struct net_device *netdev) +{ + // printk("LOG: %s called\n", __func__); + nfb_stop_channels(netdev); + return 0; +} + +static const struct net_device_ops netdev_ops = { + .ndo_open = nfb_xdp_open, + .ndo_stop = nfb_xdp_stop, + .ndo_start_xmit = nfb_xctrl_start_xmit, + // .ndo_get_stats64 = nfb_xdp_get_stats, + .ndo_bpf = nfb_xdp, + .ndo_xdp_xmit = nfb_xctrl_xdp_xmit, + .ndo_xsk_wakeup = nfb_xsk_wakeup, +}; + +void destroy_ethdev(struct nfb_ethdev *ethdev) +{ + struct net_device *netdev = ethdev->netdev; + // printk("LOG: %s called\n", __func__); + netif_carrier_off(netdev); + unregister_netdev(netdev); // calls nfb_xdp_stop + del_timer_sync(ðdev->link_timer); + cancel_work_sync(ðdev->link_work); + + // close mac components + if (ethdev->nc_rxmac) + nc_rxmac_close(ethdev->nc_rxmac); + if (ethdev->nc_txmac) + nc_txmac_close(ethdev->nc_txmac); + + nfb_xdp_channels_deinit(netdev); + free_netdev(netdev); +} + +static void link_work_handler(struct work_struct *work) +{ + struct nfb_ethdev *ethdev = container_of(work, struct nfb_ethdev, link_work); + int ok; + if (ethdev->nc_rxmac) { + ok = netif_carrier_ok(ethdev->netdev); + if (nc_rxmac_get_link(ethdev->nc_rxmac)) { + if (!ok) { + netif_carrier_on(ethdev->netdev); + } + } else { + if (ok) { + netif_carrier_off(ethdev->netdev); + } + } + } +} + +static void link_timer_callback(struct timer_list *timer) +{ + struct nfb_ethdev *ethdev = container_of(timer, struct nfb_ethdev, link_timer); + schedule_work(ðdev->link_work); + mod_timer(ðdev->link_timer, jiffies + HZ * 1); +} + +struct nfb_ethdev *create_ethdev(struct nfb_xdp *module, int fdt_offset, u16 index) +{ + struct nfb_device *nfb = module->nfb; + struct nfb_ethdev *ethdev; + struct net_device *netdev; + int fdt_comp; + int ret; + + // allocate net_device + netdev = alloc_etherdev_mqs(sizeof(*ethdev), module->txqc / module->ethc, module->rxqc / module->ethc); + if (!netdev) { + ret = -ENOMEM; + goto err_alloc_etherdev; + } + + // sets napi to threaded mode allowing for scheduler control + // without this mode scheduler cannot really work with napi + // so multiple napi softirqs can end up on the same cpu + ret = dev_set_threaded(netdev, true); + if (ret) + printk(KERN_WARNING "nfb: Couldn't set NAPI threaded mode.\n"); + + // Set the name of the interface + snprintf(netdev->name, IFNAMSIZ - 1, "nfb%up%u", nfb->minor, index); + + // Initialize nfb_ethdev struct + ethdev = netdev_priv(netdev); + ethdev->index = index; + ethdev->channel_count = module->rxqc / module->ethc; + ethdev->module = module; + ethdev->nfb = nfb; + ethdev->netdev = netdev; + + // Initialize channels + ret = nfb_xdp_channels_init(netdev); + if (ret) + goto err_channels_init; + + // NOTE: nc_mac_enable ~ nfb-eth -e1 + // open mac component + fdt_comp = nc_eth_get_rxmac_node(nfb->fdt, fdt_offset); + ethdev->nc_rxmac = nc_rxmac_open(nfb, fdt_comp); + if (IS_ERR(ethdev->nc_rxmac)) + ethdev->nc_rxmac = NULL; + + fdt_comp = nc_eth_get_txmac_node(nfb->fdt, fdt_offset); + ethdev->nc_txmac = nc_txmac_open(nfb, fdt_comp); + if (IS_ERR(ethdev->nc_txmac)) + ethdev->nc_txmac = NULL; + + // init periodical checking of link status + INIT_WORK(ðdev->link_work, link_work_handler); + timer_setup(ðdev->link_timer, link_timer_callback, 0); + netdev->netdev_ops = &netdev_ops; + + SET_NETDEV_DEV(netdev, &nfb->pci->dev); + + // set mac address + nfb_net_set_dev_addr(nfb, netdev, index); + // NOTE: Register netdev with all tx queues stopped. + // Otherwise tx can be called when queues are not ready. + netif_tx_stop_all_queues(netdev); + // carrier needs to be manually set down on init else its the state will show up as UNKNOWN + netif_carrier_off(netdev); + ret = register_netdev(netdev); // calls nfb_xdp_open + if (ret) { + goto err_register_netdev; + } + + return ethdev; + +err_register_netdev: + nfb_xdp_channels_deinit(netdev); + if (ethdev->nc_rxmac) + nc_rxmac_close(ethdev->nc_rxmac); + if (ethdev->nc_txmac) + nc_txmac_close(ethdev->nc_txmac); +err_channels_init: + free_netdev(netdev); +err_alloc_etherdev: + return NULL; +} diff --git a/drivers/kernel/drivers/nfb/xdp/ethdev.h b/drivers/kernel/drivers/nfb/xdp/ethdev.h new file mode 100644 index 00000000..c8e99dd1 --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/ethdev.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - header file for ethdev + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#ifndef NFB_XDP_ETHDEV_H +#define NFB_XDP_ETHDEV_H + +#include +#include "../nfb.h" + +// structure describing one ETH port +struct nfb_ethdev { + struct list_head list; /*List of eth devices*/ + struct nfb_device *nfb; /* Top level driver struct */ + struct nfb_xdp *module; /* module info */ + struct net_device *netdev; + + int index; /* index of ETH port */ + + u16 channel_count; + struct nfb_xdp_channel *channels; + + // work setting interface up or down based on the state of the mac + struct timer_list link_timer; + struct work_struct link_work; + + // nfb components + struct nc_rxmac *nc_rxmac; + struct nc_txmac *nc_txmac; + + // prog is rcu protected pointer + struct bpf_prog *prog; /* xdp prog */ + spinlock_t prog_lock; +}; + +struct nfb_ethdev *create_ethdev(struct nfb_xdp *module, int fdt_offset, u16 index); +void destroy_ethdev(struct nfb_ethdev *ethdev); +#endif // NFB_XDP_ETHDEV From ff9190d89af533d307975bd47b984f5cc276ece8 Mon Sep 17 00:00:00 2001 From: Richard Hyros Date: Wed, 12 Feb 2025 13:46:26 +0100 Subject: [PATCH 353/518] feat(xdp driver): add XDP docs --- doc/driver/xdp.rst | 470 +++++++++++++++++++++++++++++++++++++++++++++ doc/index.rst | 7 +- 2 files changed, 476 insertions(+), 1 deletion(-) create mode 100644 doc/driver/xdp.rst diff --git a/doc/driver/xdp.rst b/doc/driver/xdp.rst new file mode 100644 index 00000000..3ce20959 --- /dev/null +++ b/doc/driver/xdp.rst @@ -0,0 +1,470 @@ +XDP submodule +============== +The NFB driver supports XDP as an alternative to NDP API and DPDK. The XDP submodule is under development, and the NFB driver doesn't compile with it by default. + +How to enable +============= +In order to compile with the XDP submodule, the variable ``CONFIG_NFB_XDP = y`` has to be set in ``drivers/Makefile.conf``. + +.. code-block:: Makefile + :emphasize-lines: 6 + + # drivers/Makefile.conf + CONFIG_MODULES = y + CONFIG_NFB = m + CONFIG_NFB_XVC = m + # uncomment to enable XDP functionality + CONFIG_NFB_XDP = y + +Next, the driver needs to be configure-d and make-d + +.. code-block:: shell + + $ cd drivers; ./configure; make; cd .. + +Then, you enable the driver by setting the module parametr ``xdp_enable=yes`` when inserting the module. + +.. code-block:: shell + + $ sudo rmmod nfb + $ sudo insmod drivers/kernel/drivers/nfb/nfb.ko xdp_enable=yes + +In order to see if the driver successfully initialized, check the system log. +The ``nfb_xdp: Successfully attached`` message should be present. In case of errors, you can try rebooting the desing, by running ``nfb-boot -F``. + +.. code-block:: shell + :emphasize-lines: 9 + + $ dmesg + ... + [ 4933.960744] nfb 0000:03:00.0: FDT loaded, size: 16384, allocated buffer size: 65536 + [ 4933.961000] nfb 0000:03:00.0: unable to enable MSI + [ 4933.961311] nfb 0000:03:00.0: nfb_mi: MI0 on PCI0 map: successfull + [ 4933.964620] nfb 0000:03:00.0: nfb_boot: Attached successfully + [ 4934.024800] nfb 0000:03:00.0: nfb_ndp: attached successfully + [ 4934.024884] nfb 0000:03:00.0: nfb_qdr: Attached successfully (0 QDR controllers) + [ 4934.028473] nfb 0000:03:00.0: nfb_xdp: Successfully attached + [ 4934.028478] nfb 0000:03:00.0: successfully initialized + [ 4934.028685] pcieport 0000:00:02.0: restoring errors on PCI bridge + [ 4934.028688] pcieport 0000:00:02.0: firmware reload done + ... + +Lastly, you add the add the XDP netdev with the help of ``nfb-dma`` tool. + +To add a single XDP netdevice with all queues open + +.. code-block:: shell + + $ sudo nfb-dma -N nfb_xdp add,id=1 + +How to test +=========== + + + +Basic XDP vs AF_XDP / XDP zero-copy mode overview +================================================= +Basic XDP +--------- +When the XDP driver is inserted, and the XDP network interfaces are created via ``nfb-dma``, this starts up the queues on those network interfaces. + +In this mode, the driver acts as a usual network driver. When the XDP program is loaded onto the interface, the driver executes it on each received packet and handles the result accordingly. + +The driver in this mode allocates its own memory for the packet buffers using Page Pool API. + +**This mode only expands the basic network driver functionality by running the XDP program.** + +AF_XDP / XDP zero-copy +---------------------- +AF_XDP mode requires a specialized userspace app. This app allocates the memory block used for XDP buffers called UMEM and four XDP descriptor rings to go with it. +The app then registers those objects with the system through system calls. The app opens the AF_XDP socket. + +For an AF_XDP application to work, the XDP program has to be loaded into the kernel. This is usually done from the C code as a part of the app initialization process. The XDP program will work in tandem with the app in the userspace. +The main purpose of this XDP program is to return an XDP_REDIRECT action onto the AF_XDP socket opened by the userspace application. +The reference to the socket is passed to the XDP program from the userspace by using an eBPF map of type BPF_MAP_TYPE_XSKMAP. + +For a more complete explanation, please refer to the docs: https://docs.kernel.org/networking/af_xdp.html + +- These steps are usually done indirectly by using some helper library like ``libxdp``. + +The driver then has to switch the network channel (AF_XDP works with RX/TX queue pairs) chosen by the userspace application to AF_XDP mode. +This is done on the fly, and it basically means stopping the DMA channel, mapping the memory from the userspace, and starting the DMA channel again. + +In this mode, the driver works with memory allocated by userspace, and the userspace app has exclusive control over the network channel it works with. + +When the AF_XDP socket is closed, the channel is switched back to the normal XDP mode. + +**While running in this mode, the true zero-copy operation is achieved as long as the XDP program passes the packets to the userspace through AF_XDP socket. +XDP actions other than XDP_REDIRECT to userspace will be handled by copying.** + +XDP quickstart +============== +This section tells the bare minimum someone needs to know to compile and load an XDP program onto the interface. + +XDP return actions +------------------ +The XDP program returns an XDP action for each received packet. Those actions are: + +- XDP_PASS - passes the packet to the network stack + - Copy for XDP and AF_XDP +- XDP_TX - transmits the packet from the same interface it was received on + - zero-copy with XDP + - Copy for AF_XDP (the correct way to do this is through redirect to the userspace app) +- XDP_DROP - drops the packet + - Recycles the buffer for XDP and AF_XDP +- XDP_REDIRECT - redirects the packet + - Onto network interface - copy + - To a different CPU - for load balancing purposes + - **To userspace - this is AF_XDP zero-copy operation** + +XDP attach modes +---------------- +XDP program can be attached in different ways, **this has performance implications**. + +- Generic XDP (Generic mode, SKB mode) - The XDP program is run **after** driver passes the packet into the network stack. + This makes the XDP execution indifferent to driver support, but it means there will be little to no benefit to performance. + - This mode should be used only for testing purposes + +- Native XDP (Native mode) - The XDP program is run as a first thing on the receive path, and the driver handles the XDP actions. + - This is what should be used and is the main goal of this XDP kernel module + +- Offloaded XDP - The XDP program is loaded and executed on the network card. + - This is not supported by the NDK + + +Prerequisites +------------- +.. code-block:: shell + + $ sudo dnf install clang libbpf libbpf-devel libxdp libxdp-devel xdp-tools + +``clang`` eBPF compiler is implemented as LLVM backend - clang is used on the front + +``libbpf`` Library for writing eBPF (XDP is a subset of eBPF) programs in C; https://github.com/libbpf/libbpf + +``libxdp`` Library that simplifies writing AF_XDP programs and contains helpers for attaching XDP programs to the interface; https://github.com/xdp-project/xdp-tools/blob/main/lib/libxdp/README.org + +``xdp-tools`` Collection of tools for loading and testing XDP programs + + +The most simple XDP program +--------------------------- +A program that drops all packets + +.. code-block:: C + + #include + #include + + SEC("xdp_drop") + int xdp_drop_prog(struct xdp_md *ctx) + { + return XDP_DROP; + } + +Compiling the XDP program +------------------------- +.. code-block:: shell + + $ clang -O2 -g -Wall -target bpf -c xdp_drop.c -o xdp_drop.o + +Loading the XDP program +----------------------- +- Easiest way is to use ``xdp-loader`` program, which comes as a part of ``xdp-tools``. +- ``libxdp`` contains helper functions for loading XDP programs from C code and interacting with eBPF maps. + +Listing the interfaces and loaded programs: +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: shell + + $ sudo xdp-loader status + +Loading the program in native mode: +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: shell + + $ sudo xdp-loader load IFNAME xdp_drop.o + +Loading the program in generic mode: +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: shell + + $ sudo xdp-loader load -m skb IFNAME xdp_drop.o + +Unloading the program: +^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: shell + + $ sudo xdp-loader unload IFNAME --all + +AF_XDP quickstart +================= +This section explains the basics of writing AF_XDP program using ``libxdp`` in a form of short code snippets. + +For an example how to work with the NDK look at the ``ndp-tool`` application located in the swbase repository: + +https://github.com/CESNET/ndk-sw/tree/main/tools/ndptool + +The interensting files are ``xdp_read.c`` for RX - this is the simplest example of ``libxdp`` application. +And ``xdp_common.c`` for the NDK FPGA ``sysfs`` API, that can be used to easily map the firmware queue indexes to netdev channel indexes. + +The XDP program +--------------- + +The ``libxdp`` library ships default XDP program for AF_XDP operation, +this program is loaded and the reference to the AF_XDP socket is placed to the ``BPF_MAP_TYPE_XSKMAP`` automatically, +unless ``XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD`` flag is set. +This simplifies the setup. If you would like to create your own XDP program for AF_XDP operation, +for an example to preprocess packets before redirecting them to userspace, please follow the ``libxdp`` README. + +You can check the default program here: https://github.com/xdp-project/xdp-tools/blob/main/lib/libxdp/xsk_def_xdp_prog.c + +The userspace application +------------------------- + +Loading the program, putting the socket reference to the ``BPF_MAP_TYPE_XSKMAP`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This is taken care of by ``libxdp``, if you want to use custom XDP program, please follow the ``libxdp`` README. + +Creating UMEM +^^^^^^^^^^^^^ +The userspace has to allocate a large block of memory called UMEM. + +It is standard that one frame (here corresponding to one packet) is of the size PAGE_SIZE. + +Function posix_memalign() assures that each frame is located on its own page. + +It is possible to allocate DPDK style hugepages via ``mmap`` and flag ``MAP_HUGETLB``, +but this is not used in the example and requires to reserve the hugepages beforehand. + +The UMEM configuration can be skipped by passing ``NULL`` as the last argument of the ``xsk_umem__create()`` function, +but the default ring size is 2048 descriptors, which can lead to performance issues, +from testing it is good to have as much descriptors as there are UMEM frames. + +.. code-block:: C + + // UMEM configuration + struct umem_info *uinfo = ¶ms->queue_data_arr[i].umem_info; + uinfo->size = NUM_FRAMES * pagesize; + uinfo->umem_cfg.comp_size = NUM_FRAMES; + uinfo->umem_cfg.fill_size = NUM_FRAMES; + uinfo->umem_cfg.flags = 0; + uinfo->umem_cfg.frame_headroom = 0; + uinfo->umem_cfg.frame_size = pagesize; + // UMEM memory area + if(posix_memalign(&uinfo->umem_area, pagesize, uinfo->size)) { + fprintf(stderr, "Failed to get allocate umem buff for queue %d\n", params->queue_data_arr[i].eth_qid); + ... + } + // Registering UMEM + if((ret = xsk_umem__create(&uinfo->umem, uinfo->umem_area, uinfo->size, &uinfo->fill_ring, &uinfo->comp_ring, &uinfo->umem_cfg))) { + fprintf(stderr, "Failed to create umem for queue %d; ret: %d\n", params->queue_data_arr[i].eth_qid, ret); + ... + } + +Address stack +^^^^^^^^^^^^^ + +The userspace app needs to keep track of which frames are in its possession. +The address in this contex means **offset into the UMEM**. + +In this example, keeping track of free frames is done through a stack of addresses. + +The full code is located in ``xdp_common.h``. + +.. code-block:: C + + struct addr_stack { + uint64_t addresses[NUM_FRAMES]; + unsigned addr_cnt; + }; + + // Get address from stack + static inline uint64_t alloc_addr(struct addr_stack *stack) { + if (stack->addr_cnt == 0) { + fprintf(stderr, "BUG out of adresses\n"); + exit(1); + } + uint64_t addr = stack->addresses[--stack->addr_cnt]; + stack->addresses[stack->addr_cnt] = 0; + return addr; + } + + // Put adress to stack + static inline void free_addr(struct addr_stack *stack, uint64_t address) { + if (stack->addr_cnt == NUM_FRAMES) { + fprintf(stderr, "BUG counting adresses\n"); + exit(1); + } + stack->addresses[stack->addr_cnt++] = address; + } + + // Fill the stack with addresses into the umem + static inline void init_addr(struct addr_stack *stack, unsigned frame_size) { + for(unsigned i = 0; i < NUM_FRAMES; i++) { + stack->addresses[i] = i * frame_size; + } + stack->addr_cnt = NUM_FRAMES; + } + +NDK FPGA sysfs interface +^^^^^^^^^^^^^^^^^^^^^^^^ + +To use XDP driver you first need to add the XDP interface via ``nfb-dma`` tool. +This creates an issue when writing applications, because the firmware DMA queues can be mapped to any number of XDP interfaces. +The AF_XDP socket needs to know the name of the interface and the index of the queue in the context of the interface. +For this purpose the XDP driver makes this information available via the ``sysfs`` interface. +When the XDP driver is loaded the ``/sys/class/nfb/nfb#/nfb_xdp/`` directory is made available. +Inside this directory: + +``channel_total`` - tells you how many XDP channels there are, this information is parsed from the device tree at driver startup. + +``eth_count`` - tells you how many physical interfaces there are, this information is parsed from the device tree at driver startup. + +``channel#`` - directories corespond to the XDP channels - These contain files corresponding to the state of the channel. + + ``├── status`` - 1 if the queue was assigned to interface via ``nfb-dma`` else 0 + + ``├── ifname`` - Name of the interface the channel was mapped to via ``nfb-dma``, else 'NOT_OPEN' + + ``└── index`` - Index in the context of the interface the channel was mapped to via ``nfb-dma``, else -1 + +Example: + +We have ``NDK-MINIMAL`` firmware with 16 DMA queue pairs. We add one XDP interface which uses firmware DMA queue pairs 5, 6. +The ``dmesg`` command says ``nfb 0000:21:00.0 enp33s0: renamed from nfb0x1`` because system predictible interface naming is enabled: + +.. code-block:: shell + + $ sudo nfb-dma -N nfb_xdp add,id=1 -i5-6 + +Then the simplified structure looks like this: + +.. code-block:: shell + + $ tree + . + ├── channel0 + │   ├── ifname NOT_OPEN + │   ├── index -1 + │   └── status 0 + ... + ├── channel5 + │   ├── ifname enp33s0 + │   ├── index 0 + │   └── status 1 + ├── channel6 + │   ├── ifname enp33s0 + │   ├── index 1 + │   └── status 1 + ├── channel7 + │   ├── ifname NOT_OPEN + │   ├── index -1 + │   └── status 0 + ... + ├── channel_total 16 + ├── cmd + └── eth_count 2 + +By reading the files we can get the correct values for opening the AF_XDP socket. + +The DMA queue pair 5 is mapped to enp33s0 as the first channel (index 0). + +``xsk_socket__create(..., "enp33s0", 0, ..., ..., ..., ...)`` + +To delete the XDP interface: + +.. code-block:: shell + + $ sudo nfb-dma -N nfb_xdp del,id=1 + +Creating socket +^^^^^^^^^^^^^^^ + +The ifname and queue_id in the context of the XDP interface can be acquired via sysfs. +The XSK configuration can be skipped by passing ``NULL`` as the last argument of the ``xsk_socket__create()`` function, +but the default ring size is 2048 descriptors, which can lead to performance issues, +from testing it is good to have as much descriptors as there are UMEM frames. + +.. code-block:: C + + // XSK configuration + struct xsk_info *xinfo = ¶ms->queue_data_arr[i].xsk_info; + xinfo->xsk_cfg.rx_size = NUM_FRAMES; + xinfo->xsk_cfg.tx_size = NUM_FRAMES; + xinfo->xsk_cfg.bind_flags = XDP_ZEROCOPY; + // The name of the interface together with the queue_id (in context of the interface) + // Can be best acquired via the sysfs interface of NDK platform + strcpy(xinfo->ifname, params->queue_data_arr[i].ifname); + xinfo->queue_id = params->queue_data_arr[i].eth_qid; + if((ret = xsk_socket__create(&xinfo->xsk, xinfo->ifname, xinfo->queue_id, uinfo->umem, &xinfo->rx_ring, &xinfo->tx_ring, &xinfo->xsk_cfg))) { + fprintf(stderr, "Failed to create xsocket for queue %d; ret: %d\n", params->queue_data_arr[i].eth_qid, ret); + ... + } + +The main loop +^^^^^^^^^^^^^ +The fill part (from userspace to kernel): + +``xsk_ring_prod__reserve()`` reserves slots on the fill ring + +``xsk_ring_prod__fill_addr()`` is used to place the frames into the ring + +``xsk_ring_prod__submit()`` signals, that the filling is done, and kernel now owns the frames + +The recieve part (from kernel to userspace): + +``xsk_ring_cons__peek()`` returns the number of packets ready to be processed and gives ownership to userspace + +``xsk_ring_cons__rx_desc()`` holds the information about packet (its length and adress of data start) + +``xsk_ring_cons__release()`` returns the RX ring slots back to the kernel so they can be filled with new packets + +.. code-block:: C + + // The receive loop + while (run) { + ... + // Fill rx + unsigned rx_idx = 0; + unsigned fill_idx = 0; + unsigned reservable = xsk_prod_nb_free(fill_ring, stack.addr_cnt); + reservable = reservable < stack.addr_cnt ? reservable : stack.addr_cnt; + if (reservable > burst_size) { + unsigned reserved = xsk_ring_prod__reserve(fill_ring, reservable, &fill_idx); + for(unsigned i = 0; i < reserved; i++) { + *xsk_ring_prod__fill_addr(fill_ring, fill_idx++) = alloc_addr(&stack); + } + xsk_ring_prod__submit(fill_ring, reserved); + } + ... + // Receive packets + cnt = xsk_ring_cons__peek(rx_ring, burst_size, &rx_idx); + // Process packets + for(unsigned i = 0; i < cnt; i++) { + struct xdp_desc const *desc = xsk_ring_cons__rx_desc(rx_ring, rx_idx++); + packets[i].data = xsk_umem__get_data(xsk_data->umem_info.umem_area, desc->addr); + packets[i].data_length = desc->len; + free_addr(&stack, desc->addr); + } + // Mark done + xsk_ring_cons__release(rx_ring, cnt); + } + +Common issues +^^^^^^^^^^^^^ + +No traffic: + +Make sure the firmware interfaces are enabled: ``nfb-eth -e1`` + +Useful links +------------ +Useful AF_XDP enabled apps +^^^^^^^^^^^^^^^^^^^^^^^^^^ +- tcpreplay - since release v4.5.1; https://github.com/appneta/tcpreplay + +Libxdp README +^^^^^^^^^^^^^ +For ``libxdp`` API refer to: https://github.com/xdp-project/xdp-tools/tree/main/lib/libxdp \ No newline at end of file diff --git a/doc/index.rst b/doc/index.rst index 3b1846fd..5706a390 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -65,8 +65,13 @@ well as process data (network traffic) at very high speeds. .. toctree:: - :maxdepth: 1 :caption: Linux driver Modules Userspace access + +.. toctree:: + :maxdepth: 2 + :caption: XDP submodule + + XDP submodule From 87ab738b0b08d45f028835aaa0a89976ac661391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Thu, 3 Apr 2025 15:52:29 +0200 Subject: [PATCH 354/518] feat(xdp driver): add dynamic xdp device handling --- drivers/kernel/drivers/nfb/Makefile | 2 +- drivers/kernel/drivers/nfb/xdp/driver.c | 52 ++-- drivers/kernel/drivers/nfb/xdp/driver.h | 14 +- drivers/kernel/drivers/nfb/xdp/ethdev.c | 318 +++++++++++++--------- drivers/kernel/drivers/nfb/xdp/ethdev.h | 21 +- drivers/kernel/drivers/nfb/xdp/sysfs.c | 335 ++++++++++++++++++++++++ drivers/kernel/drivers/nfb/xdp/sysfs.h | 18 ++ 7 files changed, 586 insertions(+), 174 deletions(-) create mode 100644 drivers/kernel/drivers/nfb/xdp/sysfs.c create mode 100644 drivers/kernel/drivers/nfb/xdp/sysfs.h diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index 6afb6008..bc7925ee 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -31,6 +31,6 @@ nfb-objs += misc.o lock.o bus.o char.o pci.o core.o nfb-objs += hwmon/nfb_hwmon.o ccflags-$(CONFIG_NFB_XDP) += -DCONFIG_NFB_ENABLE_XDP -nfb-$(CONFIG_NFB_XDP) += xdp/driver.o xdp/ethdev.o xdp/ctrl_xdp_common.o xdp/ctrl_xdp_pp.o xdp/ctrl_xdp_xsk.o xdp/channel.o +nfb-$(CONFIG_NFB_XDP) += xdp/driver.o xdp/ethdev.o xdp/ctrl_xdp_common.o xdp/ctrl_xdp_pp.o xdp/ctrl_xdp_xsk.o xdp/channel.o xdp/sysfs.o obj-m += nfb.o diff --git a/drivers/kernel/drivers/nfb/xdp/driver.c b/drivers/kernel/drivers/nfb/xdp/driver.c index de2d3af7..29ab4387 100644 --- a/drivers/kernel/drivers/nfb/xdp/driver.c +++ b/drivers/kernel/drivers/nfb/xdp/driver.c @@ -18,6 +18,7 @@ #include "driver.h" #include "ethdev.h" +#include "sysfs.h" #define COMP_NETCOPE_RX "netcope,dma_ctrl_ndp_rx" #define COMP_NETCOPE_TX "netcope,dma_ctrl_ndp_tx" @@ -27,10 +28,7 @@ static bool xdp_enable = 0; int nfb_xdp_attach(struct nfb_device *nfb, void **priv) { struct nfb_xdp *module; - struct nfb_ethdev *ethdev, *tmp; u16 ethc, rxqc, txqc; - int fdt_offset; - u16 i; int ret; if (!xdp_enable) { @@ -40,29 +38,29 @@ int nfb_xdp_attach(struct nfb_device *nfb, void **priv) // count the ports and queues ethc = nfb_comp_count(nfb, COMP_NETCOPE_ETH); if (ethc <= 0) { - dev_warn(&nfb->pci->dev, "nfb_xdp: No eth interfaces available\n"); + dev_warn(&nfb->pci->dev, "nfb_xdp: Failed to attach: No eth interfaces available\n"); return -EINVAL; } rxqc = nfb_comp_count(nfb, COMP_NETCOPE_RX); if (rxqc <= 0) { - dev_warn(&nfb->pci->dev, "nfb_xdp: No RX queues available\n"); + dev_warn(&nfb->pci->dev, "nfb_xdp: Failed to attach: No RX queues available\n"); return -EINVAL; } txqc = nfb_comp_count(nfb, COMP_NETCOPE_TX); if (txqc <= 0) { - dev_warn(&nfb->pci->dev, "nfb_xdp: No TX queues available\n"); + dev_warn(&nfb->pci->dev, "nfb_xdp: Failed to attach: No TX queues available\n"); return -EINVAL; } // sanity checks; we expect there will be the same amount of queue pairs for each eth port if (rxqc != txqc) { - dev_warn(&nfb->pci->dev, "nfb_xdp: TX and RX queue count differs, xdp operates with queue pairs TXc: %u, RXc: %u\n", txqc, rxqc); + dev_warn(&nfb->pci->dev, "nfb_xdp: Failed to attach: TX and RX queue count differs, xdp operates with queue pairs TXc: %u, RXc: %u\n", txqc, rxqc); return -EINVAL; } if (rxqc % ethc != 0) { - dev_warn(&nfb->pci->dev, "nfb_xdp: Queue pairs are not divisible by ports, don't know how to initilize TXc: %u, RXc: %u, ETHc: %u\n", txqc, rxqc, ethc); + dev_warn(&nfb->pci->dev, "nfb_xdp: Failed to attach: Queue pairs are not divisible by ports, don't know how to initilize TXc: %u, RXc: %u, ETHc: %u\n", txqc, rxqc, ethc); return -EINVAL; } @@ -76,8 +74,7 @@ int nfb_xdp_attach(struct nfb_device *nfb, void **priv) INIT_LIST_HEAD(&module->list_devices); module->ethc = ethc; - module->rxqc = rxqc; - module->txqc = txqc; + module->channelc = rxqc; module->nfb = nfb; memset(&module->dev, 0, sizeof(struct device)); @@ -85,35 +82,25 @@ int nfb_xdp_attach(struct nfb_device *nfb, void **priv) module->dev.parent = nfb->dev; dev_set_name(&module->dev, "nfb_xdp"); dev_set_drvdata(&module->dev, module); + nfb_xdp_sysfs_init_module_attributes(module); ret = device_add(&module->dev); if (ret) { + dev_warn(&nfb->pci->dev, "nfb_xdp: Failed to add kernel device\n"); goto err_dev_add; } - i = 0; - fdt_for_each_compatible_node(nfb->fdt, fdt_offset, COMP_NETCOPE_ETH) { - ethdev = create_ethdev(module, fdt_offset, i); - if (!ethdev) { - dev_warn(&nfb->pci->dev, "nfb_xdp: failed to create eth port\n"); - goto err_ethdev; - } - list_add_tail(ðdev->list, &module->list_devices); - i++; - } - - if (i != ethc) { - dev_warn(&nfb->pci->dev, "nfb_xdp: failed to create eth port\n"); - goto err_ethdev; + ret = nfb_xdp_sysfs_init_channels(module); + if (ret) { + dev_warn(&nfb->pci->dev, "nfb_xdp: Failed to init sysfs\n"); + goto err_channel_sysfs; } - dev_info(&nfb->pci->dev, "nfb_xdp: attached\n"); + dev_info(&nfb->pci->dev, "nfb_xdp: Successfully attached\n"); return 0; -err_ethdev: - list_for_each_entry_safe(ethdev, tmp, &module->list_devices, list) { - destroy_ethdev(ethdev); - } +err_channel_sysfs: err_dev_add: + put_device(&module->dev); kfree(module); *priv = NULL; return ret; @@ -122,16 +109,13 @@ int nfb_xdp_attach(struct nfb_device *nfb, void **priv) void nfb_xdp_detach(struct nfb_device *nfb, void *priv) { struct nfb_xdp *module = priv; - struct nfb_ethdev *ethdev, *tmp; if (!module) { return; } - list_for_each_entry_safe(ethdev, tmp, &module->list_devices, list) { - destroy_ethdev(ethdev); - } - + nfb_xdp_sysfs_deinit_channels(module); + destroy_ethdev(module, -1); device_del(&module->dev); kfree(module); dev_info(&nfb->pci->dev, "nfb_xdp: detached\n"); diff --git a/drivers/kernel/drivers/nfb/xdp/driver.h b/drivers/kernel/drivers/nfb/xdp/driver.h index 59e350bc..23633533 100644 --- a/drivers/kernel/drivers/nfb/xdp/driver.h +++ b/drivers/kernel/drivers/nfb/xdp/driver.h @@ -17,13 +17,15 @@ void nfb_xdp_detach(struct nfb_device *nfb, void *priv); // struct holding xdp driver module info struct nfb_xdp { - struct nfb_device *nfb; /*Top level structure describing nfb device*/ - struct device dev; /*device describing nfb_xdp module*/ - struct list_head list_devices; /*List of eth devices*/ + struct nfb_device *nfb; // Top level structure describing nfb device + struct device dev; // Device describing nfb_xdp module, used with sysfs + struct mutex list_mutex; // Mutex for list_devices + struct list_head list_devices; // List of virtual ETH devices - u16 ethc; /* Number of ETH ports*/ - u16 rxqc; /* Absolute number of rx queues */ - u16 txqc; /* Absolute number of tx queues */ + u16 ethc; // Number of physical ETH ports + u16 channelc; // Number of usable channels + + struct device *channel_sysfsdevs; // Channel devices for sysfs }; #endif // NFB_XDP_DRIVER_H diff --git a/drivers/kernel/drivers/nfb/xdp/ethdev.c b/drivers/kernel/drivers/nfb/xdp/ethdev.c index 39092830..2cb9a28f 100644 --- a/drivers/kernel/drivers/nfb/xdp/ethdev.c +++ b/drivers/kernel/drivers/nfb/xdp/ethdev.c @@ -22,36 +22,44 @@ #include "ethdev.h" #include "channel.h" #include "ctrl_xdp.h" +#include "sysfs.h" -static int nfb_xdp_channels_init(struct net_device *netdev) +static int nfb_xdp_channels_init(struct net_device *netdev, unsigned *channel_indexes, unsigned channel_count) { - int i, ret = 0; + int nfb_idx = 0, map_idx = 0, ch_idx = 0, ret = 0; struct nfb_ethdev *ethdev = netdev_priv(netdev); - // printk("LOG: %s called", __func__); - ethdev->channels = kzalloc(sizeof(*ethdev->channels) * ethdev->channel_count, GFP_KERNEL); + struct nfb_xdp *module = ethdev->module; + + ethdev->channels = kzalloc(sizeof(*ethdev->channels) * channel_count, GFP_KERNEL); if (!ethdev->channels) { ret = -ENOMEM; goto err_channel_alloc; } - for (i = 0; i < ethdev->channel_count; i++) { - mutex_init(ðdev->channels[i].state_mutex); - ethdev->channels[i].ethdev = ethdev; - ethdev->channels[i].index = i; - ethdev->channels[i].nfb_index = i + ethdev->channel_count * ethdev->index; - ethdev->channels[i].numa = dev_to_node(ðdev->nfb->pci->dev); + // Map the queues - lowest index to lowest index. + for (nfb_idx = 0; nfb_idx < module->channelc; nfb_idx++) { + for (ch_idx = 0; ch_idx < channel_count; ch_idx++) { + if(nfb_idx == channel_indexes[ch_idx]) { + mutex_init(ðdev->channels[map_idx].state_mutex); + ethdev->channels[map_idx].ethdev = ethdev; + ethdev->channels[map_idx].index = map_idx; + ethdev->channels[map_idx].nfb_index = nfb_idx; + ethdev->channels[map_idx].numa = dev_to_node(ðdev->nfb->pci->dev); #ifdef CONFIG_HAVE_NETIF_NAPI_ADD_WITH_WEIGHT - netif_napi_add(netdev, ðdev->channels[i].rxq.napi_pp, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); - netif_napi_add(netdev, ðdev->channels[i].rxq.napi_xsk, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); + netif_napi_add(netdev, ðdev->channels[map_idx].rxq.napi_pp, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); + netif_napi_add(netdev, ðdev->channels[map_idx].rxq.napi_xsk, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); #else - netif_napi_add_weight(netdev, ðdev->channels[i].rxq.napi_pp, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); - netif_napi_add_weight(netdev, ðdev->channels[i].rxq.napi_xsk, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); + netif_napi_add_weight(netdev, ðdev->channels[map_idx].rxq.napi_pp, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); + netif_napi_add_weight(netdev, ðdev->channels[map_idx].rxq.napi_xsk, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); #endif #ifdef CONFIG_HAVE_NETIF_NAPI_ADD_TX_WEIGHT - netif_napi_add_tx_weight(netdev, ðdev->channels[i].txq.napi_xsk, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); + netif_napi_add_tx_weight(netdev, ðdev->channels[map_idx].txq.napi_xsk, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); #else - netif_tx_napi_add(netdev, ðdev->channels[i].txq.napi_xsk, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); + netif_tx_napi_add(netdev, ðdev->channels[map_idx].txq.napi_xsk, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); #endif + map_idx++; + } + } } err_channel_alloc: @@ -62,7 +70,7 @@ static void nfb_xdp_channels_deinit(struct net_device *netdev) { u32 i; struct nfb_ethdev *ethdev = netdev_priv(netdev); - // printk("LOG: %s called", __func__); + for (i = 0; i < ethdev->channel_count; i++) { netif_napi_del(ðdev->channels[i].rxq.napi_pp); netif_napi_del(ðdev->channels[i].rxq.napi_xsk); @@ -92,7 +100,7 @@ static void nfb_stop_channels(struct net_device *netdev) struct nfb_xdp_channel *channel; unsigned i; struct bpf_prog *old_prog; - // printk("LOG: %s called", __func__); + spin_lock(ðdev->prog_lock); old_prog = rcu_replace_pointer(ethdev->prog, NULL, lockdep_is_held(ðdev->prog_lock)); if (old_prog) { @@ -104,12 +112,6 @@ static void nfb_stop_channels(struct net_device *netdev) // Stop all TX queues netif_tx_stop_all_queues(netdev); - // disable mac - if (ethdev->nc_rxmac) - nc_rxmac_disable(ethdev->nc_rxmac); - if (ethdev->nc_txmac) - nc_txmac_disable(ethdev->nc_txmac); - // Stop all threads for (i = 0; i < ethdev->channel_count; i++) { channel = ðdev->channels[i]; @@ -143,20 +145,10 @@ static int nfb_start_channels(struct net_device *netdev) for (i = 0; i < ethdev->channel_count; i++) { channel = ðdev->channels[i]; if ((ret = channel_start_pp(channel))) { - goto err_channel_start; + printk(KERN_ERR "nfb: failed to start channels\n"); } } - // enable mac - if (ethdev->nc_rxmac) - nc_rxmac_enable(ethdev->nc_rxmac); - if (ethdev->nc_txmac) - nc_txmac_enable(ethdev->nc_txmac); - - return ret; -err_channel_start: - printk(KERN_ERR "nfb: failed to start channels\n"); - nfb_stop_channels(netdev); return ret; } @@ -164,7 +156,6 @@ static int nfb_xdp_open(struct net_device *netdev) { int ret; struct nfb_ethdev *ethdev = netdev_priv(netdev); - // printk("LOG: %s called", __func__); ret = nfb_start_channels(netdev); schedule_work(ðdev->link_work); mod_timer(ðdev->link_timer, jiffies + HZ * 1); @@ -173,7 +164,6 @@ static int nfb_xdp_open(struct net_device *netdev) static int nfb_xdp_stop(struct net_device *netdev) { - // printk("LOG: %s called\n", __func__); nfb_stop_channels(netdev); return 0; } @@ -188,32 +178,58 @@ static const struct net_device_ops netdev_ops = { .ndo_xsk_wakeup = nfb_xsk_wakeup, }; -void destroy_ethdev(struct nfb_ethdev *ethdev) +// Destroy xdp netdev, index == -1 means destroy everything +int destroy_ethdev(struct nfb_xdp *module, int index) { - struct net_device *netdev = ethdev->netdev; - // printk("LOG: %s called\n", __func__); - netif_carrier_off(netdev); - unregister_netdev(netdev); // calls nfb_xdp_stop - del_timer_sync(ðdev->link_timer); - cancel_work_sync(ðdev->link_work); - - // close mac components - if (ethdev->nc_rxmac) - nc_rxmac_close(ethdev->nc_rxmac); - if (ethdev->nc_txmac) - nc_txmac_close(ethdev->nc_txmac); + int i, ret; + struct nfb_ethdev *ethdev, *tmp; + struct net_device *netdev; - nfb_xdp_channels_deinit(netdev); - free_netdev(netdev); + ret = -ENODEV; + mutex_lock(&module->list_mutex); + { + list_for_each_entry_safe(ethdev, tmp, &module->list_devices, list) { + if(index == ethdev->index || index == -1) { + ret = 0; + netdev = ethdev->netdev; + list_del(ðdev->list); + del_timer_sync(ðdev->link_timer); + cancel_work_sync(ðdev->link_work); + netif_carrier_off(netdev); + // close mac components + for (i = 0; i < ethdev->mac_count; i++) { + if(ethdev->nc_rxmacs[i]) + nc_rxmac_close(ethdev->nc_rxmacs[i]); + } + kfree(ethdev->nc_rxmacs); + // calls nfb_xdp_stop + unregister_netdev(netdev); + nfb_xdp_channels_deinit(netdev); + free_netdev(netdev); + } + } + } + mutex_unlock(&module->list_mutex); + return ret; } static void link_work_handler(struct work_struct *work) { struct nfb_ethdev *ethdev = container_of(work, struct nfb_ethdev, link_work); - int ok; - if (ethdev->nc_rxmac) { + int ok, link, i; + + if(ethdev->mac_count) { + // Check if all the opened macs are up + link = 1; + for (i = 0; i < ethdev->mac_count; i++) { + if (ethdev->nc_rxmacs[i]) { + if(!nc_rxmac_get_link(ethdev->nc_rxmacs[i])) { + link = 0; + } + } + } ok = netif_carrier_ok(ethdev->netdev); - if (nc_rxmac_get_link(ethdev->nc_rxmac)) { + if (link) { if (!ok) { netif_carrier_on(ethdev->netdev); } @@ -232,85 +248,141 @@ static void link_timer_callback(struct timer_list *timer) mod_timer(ðdev->link_timer, jiffies + HZ * 1); } -struct nfb_ethdev *create_ethdev(struct nfb_xdp *module, int fdt_offset, u16 index) +int create_ethdev(struct nfb_xdp *module, u16 index, unsigned * channel_indexes, unsigned channel_count) { struct nfb_device *nfb = module->nfb; - struct nfb_ethdev *ethdev; + struct nfb_ethdev *ethdev, *tmp; struct net_device *netdev; - int fdt_comp; + int i, j, mac_idx; + int fdt_offset; int ret; + unsigned channel_index; + + mutex_lock(&module->list_mutex); + { + // Check if index and queues are not already in use + list_for_each_entry_safe(ethdev, tmp, &module->list_devices, list) { + if(ethdev->index == index) { + dev_warn(&module->dev, "Failed to add XDP device, another device of index %d already exists.\n", index); + ret = -EINVAL; + goto err_sanity; + } + for (i = 0; i < channel_count; i++) { + for (j = 0; j < ethdev->channel_count; j++) { + if(channel_indexes[i] == ethdev->channels[j].nfb_index) { + dev_warn(&module->dev, "Failed to add XDP device, queue %d is already used by another XDP device.\n", i); + ret = -EINVAL; + goto err_sanity; + } + } + } + } - // allocate net_device - netdev = alloc_etherdev_mqs(sizeof(*ethdev), module->txqc / module->ethc, module->rxqc / module->ethc); - if (!netdev) { - ret = -ENOMEM; - goto err_alloc_etherdev; - } + // Allocate net_device + netdev = alloc_etherdev_mqs(sizeof(*ethdev), channel_count, channel_count); + if (!netdev) { + dev_warn(&module->dev, "Failed to add XDP device, error allocating netdevice\n"); + ret = -ENOMEM; + goto err_alloc_etherdev; + } - // sets napi to threaded mode allowing for scheduler control - // without this mode scheduler cannot really work with napi - // so multiple napi softirqs can end up on the same cpu - ret = dev_set_threaded(netdev, true); - if (ret) - printk(KERN_WARNING "nfb: Couldn't set NAPI threaded mode.\n"); - - // Set the name of the interface - snprintf(netdev->name, IFNAMSIZ - 1, "nfb%up%u", nfb->minor, index); - - // Initialize nfb_ethdev struct - ethdev = netdev_priv(netdev); - ethdev->index = index; - ethdev->channel_count = module->rxqc / module->ethc; - ethdev->module = module; - ethdev->nfb = nfb; - ethdev->netdev = netdev; - - // Initialize channels - ret = nfb_xdp_channels_init(netdev); - if (ret) - goto err_channels_init; - - // NOTE: nc_mac_enable ~ nfb-eth -e1 - // open mac component - fdt_comp = nc_eth_get_rxmac_node(nfb->fdt, fdt_offset); - ethdev->nc_rxmac = nc_rxmac_open(nfb, fdt_comp); - if (IS_ERR(ethdev->nc_rxmac)) - ethdev->nc_rxmac = NULL; - - fdt_comp = nc_eth_get_txmac_node(nfb->fdt, fdt_offset); - ethdev->nc_txmac = nc_txmac_open(nfb, fdt_comp); - if (IS_ERR(ethdev->nc_txmac)) - ethdev->nc_txmac = NULL; - - // init periodical checking of link status - INIT_WORK(ðdev->link_work, link_work_handler); - timer_setup(ðdev->link_timer, link_timer_callback, 0); - netdev->netdev_ops = &netdev_ops; - - SET_NETDEV_DEV(netdev, &nfb->pci->dev); - - // set mac address - nfb_net_set_dev_addr(nfb, netdev, index); - // NOTE: Register netdev with all tx queues stopped. - // Otherwise tx can be called when queues are not ready. - netif_tx_stop_all_queues(netdev); - // carrier needs to be manually set down on init else its the state will show up as UNKNOWN - netif_carrier_off(netdev); - ret = register_netdev(netdev); // calls nfb_xdp_open - if (ret) { - goto err_register_netdev; - } + // sets napi to threaded mode allowing for scheduler control + // without this mode scheduler cannot really work with napi + // so multiple napi softirqs can end up on the same cpu + ret = dev_set_threaded(netdev, true); + if (ret) + dev_warn(&module->dev, "Failed to allocate netdevice\n"); + + // Set the name of the interface + snprintf(netdev->name, IFNAMSIZ, "nfb%ux%u", nfb->minor, index); + + // Initialize nfb_ethdev struct + ethdev = netdev_priv(netdev); + ethdev->index = index; + ethdev->channel_count = channel_count; + ethdev->module = module; + ethdev->nfb = nfb; + ethdev->netdev = netdev; + + // Initialize channels + if ((ret = nfb_xdp_channels_init(netdev,channel_indexes, channel_count))) { + dev_warn(&module->dev, "Failed to add XDP device, error initializing channels\n"); + goto err_channels_init; + } + + // NOTE: nc_mac_enable ~ nfb-eth -e1 + // NOTE: XDP netdevice can have multiple macs, to set link all relevant macs need to be considered. + // open rx mac component + if(!(ethdev->nc_rxmacs = kzalloc(sizeof(struct nc_rxmac *) * module->ethc, GFP_KERNEL))) { + ret = -ENOMEM; + goto macs_alloc_error; + } + + for (mac_idx = 0; mac_idx < module->ethc; mac_idx++) { + for (i = 0; i < channel_count; i++) { + channel_index = channel_indexes[i]; + // If channel with the mac index is found, open the mac and test for next one + if (mac_idx == channel_index / (module->channelc / module->ethc)) { + if((fdt_offset = nfb_comp_find(nfb, "netcope,rxmac", mac_idx) < 0)) { + ethdev->nc_rxmacs[ethdev->mac_count] = NULL; + dev_warn(&module->dev, "Failed to add XDP device, error finding mac offset\n"); + ret = -ENODEV; + goto macs_open_error; + } + + ethdev->nc_rxmacs[ethdev->mac_count] = nc_rxmac_open(nfb, fdt_offset); + if (IS_ERR(ethdev->nc_rxmacs[ethdev->mac_count])) { + ethdev->nc_rxmacs[ethdev->mac_count] = NULL; + dev_warn(&module->dev, "Failed to add XDP device, error opening mac\n"); + ret = -ENODEV; + goto macs_open_error; + } + ethdev->mac_count++; + break; + } + } + } - return ethdev; + + SET_NETDEV_DEV(netdev, &nfb->pci->dev); + + // set mac address + nfb_net_set_dev_addr(nfb, netdev, index); + // NOTE: Register netdev with all tx queues stopped. + // Otherwise tx can be called when queues are not ready. + netif_tx_stop_all_queues(netdev); + // carrier needs to be manually set down on init else its state will show up as UNKNOWN + netif_carrier_off(netdev); + // Init periodical checking of link status + INIT_WORK(ðdev->link_work, link_work_handler); + timer_setup(ðdev->link_timer, link_timer_callback, 0); + netdev->netdev_ops = &netdev_ops; + + // calls nfb_xdp_open + if ((ret = register_netdev(netdev))) { + dev_warn(&module->dev, "Failed to add XDP device, error registering netdevice.\n"); + goto err_register_netdev; + } + list_add_tail(ðdev->list, &module->list_devices); + } + mutex_unlock(&module->list_mutex); + return ret; err_register_netdev: + del_timer_sync(ðdev->link_timer); + cancel_work_sync(ðdev->link_work); +macs_open_error: +macs_alloc_error: + for (i = 0; i < ethdev->mac_count; i++) { + if(ethdev->nc_rxmacs[i]) + nc_rxmac_close(ethdev->nc_rxmacs[i]); + } + kfree(ethdev->nc_rxmacs); nfb_xdp_channels_deinit(netdev); - if (ethdev->nc_rxmac) - nc_rxmac_close(ethdev->nc_rxmac); - if (ethdev->nc_txmac) - nc_txmac_close(ethdev->nc_txmac); err_channels_init: free_netdev(netdev); err_alloc_etherdev: - return NULL; +err_sanity: + mutex_unlock(&module->list_mutex); + return ret; } diff --git a/drivers/kernel/drivers/nfb/xdp/ethdev.h b/drivers/kernel/drivers/nfb/xdp/ethdev.h index c8e99dd1..3e7a837f 100644 --- a/drivers/kernel/drivers/nfb/xdp/ethdev.h +++ b/drivers/kernel/drivers/nfb/xdp/ethdev.h @@ -13,14 +13,15 @@ #include #include "../nfb.h" -// structure describing one ETH port +// structure describing one ETH device struct nfb_ethdev { - struct list_head list; /*List of eth devices*/ - struct nfb_device *nfb; /* Top level driver struct */ - struct nfb_xdp *module; /* module info */ + struct list_head list; // List of eth devices + struct nfb_device *nfb; // Top level driver struct + struct nfb_xdp *module; // module info struct net_device *netdev; + struct device sysfsdev; - int index; /* index of ETH port */ + int index; // index of ETH device u16 channel_count; struct nfb_xdp_channel *channels; @@ -30,14 +31,14 @@ struct nfb_ethdev { struct work_struct link_work; // nfb components - struct nc_rxmac *nc_rxmac; - struct nc_txmac *nc_txmac; + u16 mac_count; // XDP netdevice can span multiple physical interfaces + struct nc_rxmac **nc_rxmacs; // prog is rcu protected pointer - struct bpf_prog *prog; /* xdp prog */ + struct bpf_prog *prog; // xdp prog spinlock_t prog_lock; }; -struct nfb_ethdev *create_ethdev(struct nfb_xdp *module, int fdt_offset, u16 index); -void destroy_ethdev(struct nfb_ethdev *ethdev); +int create_ethdev(struct nfb_xdp *module, u16 index, unsigned * channel_indexes, unsigned channel_count); +int destroy_ethdev(struct nfb_xdp *module, int index); #endif // NFB_XDP_ETHDEV diff --git a/drivers/kernel/drivers/nfb/xdp/sysfs.c b/drivers/kernel/drivers/nfb/xdp/sysfs.c new file mode 100644 index 00000000..68f21dab --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/sysfs.c @@ -0,0 +1,335 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - sysfs + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#include "sysfs.h" +#include "driver.h" +#include "channel.h" + +#include +#include +#include + +// ---------------- SYSFS file for dynamic adding and removing of XDP netdevs ------------ + +static ssize_t cmd_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + return 0; +} +static ssize_t cmd_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + enum { + Opt_cmd, + Opt_id, + Opt_qidxs, + Opt_err, + }; + const match_table_t tokens = { + {Opt_cmd, "cmd=%s"}, + {Opt_id, "id=%d"}, + {Opt_qidxs, "qidxs=%s"}, + {Opt_err, NULL}, + }; + struct nfb_xdp *module = dev_get_drvdata(dev); + + char *options_iter, *options; + char *p; + substring_t args[MAX_OPT_ARGS]; + int ret; + int i = 0; + + int index = -1; + char *cmd = NULL; + char *queue_string, *queue_string_iter = NULL; + char *q; + unsigned queue_index_iter; + unsigned queue_count = 0; + unsigned *queue_indexes = NULL; + + + if (buf[size - 1] != 0) + return -EINVAL; + + options_iter = options = kstrdup(buf, GFP_KERNEL); + if (!options) + return -ENOMEM; + + while ((p = strsep(&options_iter, ",")) != NULL) { + int token; + + if (!*p) + continue; + token = match_token(p, tokens, args); + switch (token) { + case Opt_id: + ret = match_int(&args[0], &index); + if (ret) + goto err_parser; + break; + case Opt_cmd: + cmd = match_strdup(&args[0]); + break; + case Opt_qidxs: + queue_string = queue_string_iter = match_strdup(&args[0]); + if (!queue_string) { + ret = -ENOMEM; + goto err_parser; + } + break; + default: + continue; + } + } + + if (cmd == NULL || index == -1) { + ret = -EINVAL; + goto err_parser; + } + + if (strcmp(cmd, "add") == 0 && index != -1) { + if (queue_string) { + for (i = 0; (q = strsep(&queue_string_iter , ":")) != NULL; i++) { + // If the ':' is ending, break + if (*q == '\0') + break; + + // Validate queue string + if(sscanf(q, "%u", &queue_index_iter) == 1) { + if (!(queue_indexes = krealloc(queue_indexes, sizeof(*queue_indexes) * ++queue_count, GFP_KERNEL))) { + ret = -ENOMEM; + goto err_parser; + } + queue_indexes[i] = queue_index_iter; + } else { + ret = -EINVAL; + goto err_parser; + } + } + } else { // If no queues were provided, use all queues + queue_count = module->channelc; + if (!(queue_indexes = kmalloc(sizeof(*queue_indexes) * queue_count, GFP_KERNEL))) { + ret = -ENOMEM; + goto err_parser; + } + for (i = 0; i < queue_count; i++) { + queue_indexes[i] = i; + } + } + ret = create_ethdev(module, index, queue_indexes, queue_count); + } else if (strcmp(cmd, "del") == 0) { + ret = destroy_ethdev(module, index); + } else { + ret = -ENXIO; + } + +err_parser: + kfree(queue_indexes); + kfree(cmd); + kfree(queue_string); + kfree(options); + return ret ? ret : size; +} +static DEVICE_ATTR_RW(cmd); + +// -------------------- SYSFS files for the MODULE - top level information --------------- + +static ssize_t channel_total_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct nfb_xdp *module = dev_get_drvdata(dev); + return sysfs_emit(buf, "%d\n", module->channelc); +} +static DEVICE_ATTR_RO(channel_total); + +static ssize_t eth_count_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct nfb_xdp *module = dev_get_drvdata(dev); + return sysfs_emit(buf, "%d\n", module->ethc); +} +static DEVICE_ATTR_RO(eth_count); + +struct attribute *nfb_module_attrs[] = { + &dev_attr_cmd.attr, + &dev_attr_channel_total.attr, + &dev_attr_eth_count.attr, + NULL, +}; +ATTRIBUTE_GROUPS(nfb_module); + +void nfb_xdp_sysfs_init_module_attributes(struct nfb_xdp *module) +{ + struct device *dev = &module->dev; + dev->groups = nfb_module_groups; +} + +void nfb_xdp_sysfs_deinit_module(struct nfb_ethdev *ethdev) +{ + return; +} + +// --------------------------- SYSFS files for each channel -------------------------------- +struct channel_sysfs_drvdata { + struct nfb_xdp *module; + unsigned channel_index; +}; + +static ssize_t status_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct channel_sysfs_drvdata *drvdata = dev_get_drvdata(dev); + struct nfb_xdp *module = drvdata->module; + unsigned channel_index = drvdata->channel_index; + struct nfb_ethdev *ethdev, *tmp; + + bool open = false; + int i; + int ret; + + mutex_lock(&module->list_mutex); + { + list_for_each_entry_safe(ethdev, tmp, &module->list_devices, list) { + for(i = 0; i < ethdev->channel_count; i++) { + if (ethdev->channels[i].nfb_index == channel_index) { + open = true; + break; + } + } + } + ret = sysfs_emit(buf, "%d\n", open); + } + mutex_unlock(&module->list_mutex); + return ret; +} +static DEVICE_ATTR_RO(status); + +static ssize_t ifname_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct channel_sysfs_drvdata *drvdata = dev_get_drvdata(dev); + struct nfb_xdp *module = drvdata->module; + unsigned channel_index = drvdata->channel_index; + struct nfb_ethdev *ethdev, *tmp; + + bool open = false; + int i; + int ret; + + mutex_lock(&module->list_mutex); + { + list_for_each_entry_safe(ethdev, tmp, &module->list_devices, list) { + for(i = 0; i < ethdev->channel_count; i++) { + if (ethdev->channels[i].nfb_index == channel_index) { + open = true; + ret = sysfs_emit(buf, "%s\n", netdev_name(ethdev->netdev)); + break; + } + } + } + + if (!open) { + ret = sysfs_emit(buf, "%s\n", "NOT_OPEN"); + } + } + mutex_unlock(&module->list_mutex); + return ret; +} +static DEVICE_ATTR_RO(ifname); + +static ssize_t index_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct channel_sysfs_drvdata *drvdata = dev_get_drvdata(dev); + struct nfb_xdp *module = drvdata->module; + unsigned channel_index = drvdata->channel_index; + struct nfb_ethdev *ethdev, *tmp; + + bool open = false; + int i; + int ret; + + mutex_lock(&module->list_mutex); + { + list_for_each_entry_safe(ethdev, tmp, &module->list_devices, list) { + for(i = 0; i < ethdev->channel_count; i++) { + if (ethdev->channels[i].nfb_index == channel_index) { + open = true; + ret = sysfs_emit(buf, "%d\n", ethdev->channels[i].index); + break; + } + } + } + if (!open) { + ret = sysfs_emit(buf, "%d\n", -1); + } + } + mutex_unlock(&module->list_mutex); + return ret; +} +static DEVICE_ATTR_RO(index); + +struct attribute *nfb_channel_attrs[] = { + &dev_attr_status.attr, + &dev_attr_ifname.attr, + &dev_attr_index.attr, + NULL, +}; +ATTRIBUTE_GROUPS(nfb_channel); + +int nfb_xdp_sysfs_init_channels(struct nfb_xdp *module) +{ + struct device *dev; + struct channel_sysfs_drvdata *drvdata; + + int ret; + int ch_idx; + + if (!(module->channel_sysfsdevs = kzalloc(sizeof(*module->channel_sysfsdevs) * module->channelc, GFP_KERNEL))) { + return -ENOMEM; + } + + for (ch_idx = 0; ch_idx < module->channelc; ch_idx++) { + dev = &module->channel_sysfsdevs[ch_idx]; + if (!(drvdata = kzalloc(sizeof(*module->channel_sysfsdevs) * module->channelc, GFP_KERNEL))) { + ret = -ENOMEM; + goto err; + } + drvdata->module = module; + drvdata->channel_index = ch_idx; + + device_initialize(dev); + dev->parent = &module->dev; + dev->groups = nfb_channel_groups; + dev_set_name(dev, "channel%d", ch_idx); + dev_set_drvdata(dev, drvdata); + ret = device_add(dev); + if (ret) { + put_device(dev); + goto err; + } + } + + return ret; + +err: + for (; ch_idx >= 0; --ch_idx) { + drvdata = dev_get_drvdata(&module->channel_sysfsdevs[ch_idx]); + put_device(&module->channel_sysfsdevs[ch_idx]); + kfree(drvdata); + } + kfree(module->channel_sysfsdevs); + return ret; +} + +void nfb_xdp_sysfs_deinit_channels(struct nfb_xdp *module) { + struct channel_sysfs_drvdata *drvdata; + int ch_idx; + + for (ch_idx = 0; ch_idx < module->channelc; ch_idx++) { + drvdata = dev_get_drvdata(&module->channel_sysfsdevs[ch_idx]); + device_del(&module->channel_sysfsdevs[ch_idx]); + kfree(drvdata); + } + kfree(module->channel_sysfsdevs); +} \ No newline at end of file diff --git a/drivers/kernel/drivers/nfb/xdp/sysfs.h b/drivers/kernel/drivers/nfb/xdp/sysfs.h new file mode 100644 index 00000000..a01a4b2b --- /dev/null +++ b/drivers/kernel/drivers/nfb/xdp/sysfs.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * XDP driver of the NFB platform - header file for sysfs + * + * Copyright (C) 2017-2025 CESNET + * Author(s): + * Richard Hyros + */ + +#ifndef NFB_XDP_SYSFS_H +#define NFB_XDP_SYSFS_H +#include "ethdev.h" + +void nfb_xdp_sysfs_init_module_attributes(struct nfb_xdp *module); +int nfb_xdp_sysfs_init_channels(struct nfb_xdp *module); +void nfb_xdp_sysfs_deinit_channels(struct nfb_xdp *module); + +#endif // NFB_XDP_SYSFS_H \ No newline at end of file From 003fcd5525cadd6d3f386ffaf335876e97acd296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Tue, 20 May 2025 08:55:27 +0200 Subject: [PATCH 355/518] feat(nfb-dma): add dynamic xdp device handling --- tools/dma/dma.c | 52 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 0b879939..3b05533a 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -118,8 +118,8 @@ void usage(const char *me, int verbose) printf("-h Show this text\n"); printf("\nExamples:\n"); printf("nfb-dma -i0 -N ndp_netdev add Create NDP based netdev\n"); -// printf("nfb-dma -i0-7 -N xdp add,id=1,eth=0,eth=1 Create XDP based netdev with rxq-txq pairs 0-7 and use also ethernet interface 0+1\n"); -// printf("nfb-dma -i0-7 -N xdp del,id=1 Delete XDP based netdev with id=1\n"); + printf("nfb-dma -i0-7 -N nfb_xdp add,id=1 Create XDP based netdev with rxq-txq pairs 0-7\n"); + printf("nfb-dma -N nfb_xdp del,id=1 Delete XDP based netdev with id=1\n"); } int set_ring_size(struct nfb_device *dev, int dir, int index, const char* csize, const char *target) @@ -147,10 +147,15 @@ int set_ring_size(struct nfb_device *dev, int dir, int index, const char* csize, int cmd_ndp_netdev(struct nfb_device *dev, const char *ndd, const char *cmd, struct list_range *index_range) { int fd; - char buffer[128]; + unsigned buff_len = 256; + char *buffer; ssize_t ret = 0, sz = 0; - snprintf(buffer, sizeof(buffer), + if (!(buffer = calloc(buff_len, sizeof(*buffer)))) { + return -ENOMEM; + } + + snprintf(buffer, buff_len, "/sys/class/nfb/nfb%d/%s/cmd", nfb_get_system_id(dev), ndd); @@ -160,10 +165,45 @@ int cmd_ndp_netdev(struct nfb_device *dev, const char *ndd, const char *cmd, str if (strcmp(ndd, "ndp_netdev") == 0) { if (index_range->items == 1 && index_range->min[0] == index_range->max[0]) { - sz = snprintf(buffer, sizeof(buffer), "cmd=%s,index=%d", cmd, index_range->min[0]); + sz = snprintf(buffer, buff_len, "cmd=%s,index=%d", cmd, index_range->min[0]); } else { ret = -EINVAL; } + } else if (strcmp(ndd, "nfb_xdp") == 0) { + sz = snprintf(buffer, buff_len, "cmd=%s,qidxs=", cmd); + if (sz < 0 || sz >= buff_len) { + ret = -EINVAL; + goto err; + } + + // Get maximum index of the queue + int max = -1; + for (size_t i = 0; i < index_range->items; i++) { + if (max < index_range->max[i]) { + max = index_range->max[i]; + } + } + + char idx_buff[16]; + // Write the queues in format 1:2:5:6: for Qs 1, 2, 5, 6 + for (int i = 0; i < max + 1; i++) { + if (list_range_contains(index_range, i)) { + sz = snprintf(idx_buff, sizeof(idx_buff), "%d:", i); + if (sz < 0 || sz >= (ssize_t) sizeof(idx_buff)) { + ret = -EINVAL; + goto err; + } + if (strlen(buffer) + strlen(idx_buff) >= buff_len) { + buff_len *= 2; + if(!(buffer = realloc(buffer, buff_len))) { + ret = -ENOMEM; + goto err; + } + } + strcat(buffer, idx_buff); + } + } + sz = strlen(buffer); } if (sz == 0) { @@ -176,6 +216,8 @@ int cmd_ndp_netdev(struct nfb_device *dev, const char *ndd, const char *cmd, str if (ret != sz) { err(ret, "Can't perform ndp_netdev %s", cmd); } +err: + free(buffer); close(fd); return ret < 0 ? ret : 0; } From 9435fbf3188ecd6a4966f0d509261da5cea4d3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Fri, 23 May 2025 12:25:33 +0200 Subject: [PATCH 356/518] fix(xdp driver): dynamically add and del napi --- drivers/kernel/drivers/nfb/xdp/channel.c | 80 ++++++++++++------- drivers/kernel/drivers/nfb/xdp/channel.h | 3 +- .../kernel/drivers/nfb/xdp/ctrl_xdp_common.c | 10 +-- drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c | 2 +- drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c | 4 +- drivers/kernel/drivers/nfb/xdp/ethdev.c | 24 +----- 6 files changed, 61 insertions(+), 62 deletions(-) diff --git a/drivers/kernel/drivers/nfb/xdp/channel.c b/drivers/kernel/drivers/nfb/xdp/channel.c index 5ec32bac..fdcb3118 100644 --- a/drivers/kernel/drivers/nfb/xdp/channel.c +++ b/drivers/kernel/drivers/nfb/xdp/channel.c @@ -25,12 +25,8 @@ static int nfb_xdp_rx_thread(void *rxqptr) channel = container_of(rxq, struct nfb_xdp_channel, rxq); ethdev = channel->ethdev; netdev = ethdev->netdev; + napi = &rxq->napi; ret = 0; - if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { - napi = &rxq->napi_pp; - } else { - napi = &rxq->napi_xsk; - } while (!kthread_should_stop()) { local_bh_disable(); @@ -48,12 +44,14 @@ static int nfb_xdp_tx_thread(void *txqptr) struct net_device *netdev; struct nfb_xdp_queue *txq; struct nfb_xdp_channel *channel; + struct napi_struct *napi; int ret; txq = txqptr; channel = container_of(txq, struct nfb_xdp_channel, txq); ethdev = channel->ethdev; netdev = ethdev->netdev; + napi = &txq->napi; ret = 0; if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) // In page pool mode tx exits @@ -61,9 +59,9 @@ static int nfb_xdp_tx_thread(void *txqptr) while (!kthread_should_stop()) { local_bh_disable(); - napi_schedule(&txq->napi_xsk); + napi_schedule(napi); local_bh_enable(); - while (!kthread_should_stop() && test_bit(NAPI_STATE_SCHED, &txq->napi_xsk.state)) + while (!kthread_should_stop() && test_bit(NAPI_STATE_SCHED, &napi->state)) usleep_range(10, 20); } return ret; @@ -74,6 +72,7 @@ static int channel_create_threads(struct nfb_xdp_channel *channel) int ret = 0; struct net_device *netdev = channel->ethdev->netdev; + // Create RX thread for each queue channel->rxq.thread = kthread_create_on_node(nfb_xdp_rx_thread, &channel->rxq, channel->numa, "%s/%u", netdev->name, channel->nfb_index); if (IS_ERR(channel->rxq.thread)) { printk(KERN_ERR "nfb: %s - failed to create rx thread (error: %ld, channel: %d)\n", @@ -81,15 +80,12 @@ static int channel_create_threads(struct nfb_xdp_channel *channel) ret = PTR_ERR(channel->rxq.thread); goto err_kthread_rx; } - // increment reference counter to kthread so the thread can exit on error and kthread_stop() won't crash + // Increment reference counter to kthread so the thread can exit on error and kthread_stop() won't crash // put_task_struct() must be called after kthread_stop() get_task_struct(channel->rxq.thread); + // Enable napi + napi_enable(&channel->rxq.napi); // Wake up thread - if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { - napi_enable(&channel->rxq.napi_pp); - } else { - napi_enable(&channel->rxq.napi_xsk); - } wake_up_process(channel->rxq.thread); // Create TX thread for each queue @@ -103,10 +99,11 @@ static int channel_create_threads(struct nfb_xdp_channel *channel) // increment reference counter to struct_task so the thread can exit on error and kthread_stop() won't crash // put_task_struct() must be called after kthread_stop() on driver detach get_task_struct(channel->txq.thread); + // Enable napi if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { // pagepool doesn't use tx napi } else { - napi_enable(&channel->txq.napi_xsk); + napi_enable(&channel->txq.napi); } netif_tx_start_queue(netdev_get_tx_queue(netdev, channel->index)); // Wake up thread @@ -122,6 +119,10 @@ static int channel_create_threads(struct nfb_xdp_channel *channel) put_task_struct(channel->rxq.thread); channel->rxq.thread = NULL; } + napi_disable(&channel->rxq.napi); + while (napi_disable_pending(&channel->rxq.napi)) + ; + err_kthread_rx: return ret; } @@ -141,6 +142,13 @@ int channel_start_pp(struct nfb_xdp_channel *channel) goto err_channel_running; } +#ifdef CONFIG_HAVE_NETIF_NAPI_ADD_WITH_WEIGHT + netif_napi_add(netdev, &rxq->napi, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); +#else + netif_napi_add_weight(netdev, &rxq->napi, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); +#endif + memset(&txq->napi, 0, sizeof(&txq->napi)); + if (!(rxq->ctrl = nfb_xctrl_alloc_pp(netdev, channel->index, NFB_XDP_DESC_CNT, NFB_XCTRL_RX))) { ret = -ENOMEM; printk(KERN_ERR "nfb: %s - failed to alloc rx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); @@ -163,6 +171,7 @@ int channel_start_pp(struct nfb_xdp_channel *channel) goto err_start_tx; } + clear_bit(NFB_STATUS_IS_XSK, &channel->status); if ((ret = channel_create_threads(channel))) { printk(KERN_ERR "nfb: %s - failed to create queue threads %d (error: %d)\n", netdev->name, channel->nfb_index, ret); goto err_threads; @@ -179,6 +188,8 @@ int channel_start_pp(struct nfb_xdp_channel *channel) err_alloc_tx: nfb_xctrl_destroy_pp(rxq->ctrl); err_alloc_rx: + netif_napi_del(&rxq->napi); + memset(&rxq->napi, 0, sizeof(rxq->napi)); err_channel_running: mutex_unlock(&channel->state_mutex); return ret; @@ -199,6 +210,17 @@ int channel_start_xsk(struct nfb_xdp_channel *channel) goto err_channel_running; } +#ifdef CONFIG_HAVE_NETIF_NAPI_ADD_WITH_WEIGHT + netif_napi_add(netdev, &rxq->napi, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); +#else + netif_napi_add_weight(netdev, &rxq->napi, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); +#endif +#ifdef CONFIG_HAVE_NETIF_NAPI_ADD_TX_WEIGHT + netif_napi_add_tx_weight(netdev, &txq->napi, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); +#else + netif_tx_napi_add(netdev, &txq->napi, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); +#endif + if (!(rxq->ctrl = nfb_xctrl_alloc_xsk(netdev, channel->index, channel->pool, NFB_XCTRL_RX))) { ret = -ENOMEM; printk(KERN_ERR "nfb: %s - failed to alloc rx queue %d (error: %d)\n", netdev->name, channel->nfb_index, ret); @@ -221,10 +243,10 @@ int channel_start_xsk(struct nfb_xdp_channel *channel) goto err_start_tx; } + set_bit(NFB_STATUS_IS_XSK, &channel->status); if ((ret = channel_create_threads(channel))) { goto err_threads; } - set_bit(NFB_STATUS_IS_RUNNING, &channel->status); } mutex_unlock(&channel->state_mutex); @@ -238,6 +260,10 @@ int channel_start_xsk(struct nfb_xdp_channel *channel) err_alloc_tx: nfb_xctrl_destroy_xsk(rxq->ctrl); err_alloc_rx: + netif_napi_del(&rxq->napi); + memset(&rxq->napi, 0, sizeof(rxq->napi)); + netif_napi_del(&txq->napi); + memset(&txq->napi, 0, sizeof(txq->napi)); err_channel_running: mutex_unlock(&channel->state_mutex); return ret; @@ -264,15 +290,10 @@ int channel_stop(struct nfb_xdp_channel *channel) put_task_struct(rxq->thread); rxq->thread = NULL; } - if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { // base XDP operation - napi_disable(&rxq->napi_pp); - while (napi_disable_pending(&rxq->napi_pp)) - ; - } else { // AF_XDP operation - napi_disable(&rxq->napi_xsk); - while (napi_disable_pending(&rxq->napi_xsk)) - ; - } + napi_disable(&rxq->napi); + while (napi_disable_pending(&rxq->napi)) + ; + netif_napi_del(&rxq->napi); // Collect tx thread netif_tx_stop_queue(netdev_get_tx_queue(netdev, channel->index)); @@ -281,12 +302,13 @@ int channel_stop(struct nfb_xdp_channel *channel) put_task_struct(channel->txq.thread); channel->txq.thread = NULL; } - if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { // base XDP operation - // No napi - } else { // AF_XDP operation - napi_disable(&txq->napi_xsk); - while (napi_disable_pending(&txq->napi_xsk)) + if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { + // Only xsk uses tx napi + } else { + napi_disable(&txq->napi); + while (napi_disable_pending(&txq->napi)) ; + netif_napi_del(&txq->napi); } if (!test_bit(NFB_STATUS_IS_XSK, &channel->status)) { diff --git a/drivers/kernel/drivers/nfb/xdp/channel.h b/drivers/kernel/drivers/nfb/xdp/channel.h index 299447dc..7feefedb 100644 --- a/drivers/kernel/drivers/nfb/xdp/channel.h +++ b/drivers/kernel/drivers/nfb/xdp/channel.h @@ -22,8 +22,7 @@ struct nfb_xdp_queue { struct task_struct *thread; // napi structs - so far only xsk mode uses tx napi - struct napi_struct napi_pp; - struct napi_struct napi_xsk; + struct napi_struct napi; }; // structure describing one queue pair diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c index 991ae93e..198e335d 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c @@ -242,7 +242,6 @@ static int nfb_setup_xsk_pool(struct net_device *dev, struct xsk_buff_pool *pool } channel_stop(channel); - set_bit(NFB_STATUS_IS_XSK, &channel->status); channel->pool = pool; if ((ret = channel_start_xsk(channel))) { printk(KERN_WARNING "nfb: Failed to start channel %d, channel unusable\n", nfb_queue_id); @@ -277,7 +276,6 @@ static int nfb_teardown_xsk_pool(struct net_device *dev, struct xsk_buff_pool *p u32 ret = 0; channel_stop(channel); - clear_bit(NFB_STATUS_IS_XSK, &channel->status); if ((ret = channel_start_pp(channel))) { printk(KERN_WARNING "nfb: Failed to start channel %d, channel unusable\n", nfb_queue_id); goto unmap; @@ -333,14 +331,14 @@ int nfb_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags) if (flags & XDP_WAKEUP_TX) { local_bh_disable(); - if (!napi_if_scheduled_mark_missed(&txq->napi_xsk)) - napi_schedule(&txq->napi_xsk); + if (!napi_if_scheduled_mark_missed(&txq->napi)) + napi_schedule(&txq->napi); local_bh_enable(); } if (flags & XDP_WAKEUP_RX) { local_bh_disable(); - if (!napi_if_scheduled_mark_missed(&rxq->napi_xsk)) - napi_schedule(&rxq->napi_xsk); + if (!napi_if_scheduled_mark_missed(&rxq->napi)) + napi_schedule(&rxq->napi); local_bh_enable(); } diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c index a8a5d1c3..3b00b15d 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c @@ -290,7 +290,7 @@ static inline u16 nfb_xctrl_rx_pp(struct xctrl *ctrl, struct xdp_buff **buffs, u int nfb_xctrl_napi_poll_pp(struct napi_struct *napi, int budget) { - struct nfb_xdp_queue *rxq = container_of(napi, struct nfb_xdp_queue, napi_pp); + struct nfb_xdp_queue *rxq = container_of(napi, struct nfb_xdp_queue, napi); struct xctrl *ctrl = rxq->ctrl; struct net_device *netdev = napi->dev; struct nfb_ethdev *ethdev = netdev_priv(netdev); diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c index 3b648e37..2cab9839 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c @@ -258,7 +258,7 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, struct xdp_buff **buffs, int nfb_xctrl_napi_poll_rx_xsk(struct napi_struct *napi, int budget) { - struct nfb_xdp_queue *rxq = container_of(napi, struct nfb_xdp_queue, napi_xsk); + struct nfb_xdp_queue *rxq = container_of(napi, struct nfb_xdp_queue, napi); struct xctrl *ctrl = rxq->ctrl; struct net_device *netdev = napi->dev; struct nfb_ethdev *ethdev = netdev_priv(netdev); @@ -296,7 +296,7 @@ int nfb_xctrl_napi_poll_rx_xsk(struct napi_struct *napi, int budget) int nfb_xctrl_napi_poll_tx_xsk(struct napi_struct *napi, int budget) { - struct nfb_xdp_queue *txq = container_of(napi, struct nfb_xdp_queue, napi_xsk); + struct nfb_xdp_queue *txq = container_of(napi, struct nfb_xdp_queue, napi); struct nfb_xdp_channel *channel = container_of(txq, struct nfb_xdp_channel, txq); struct xctrl *ctrl = txq->ctrl; struct xsk_buff_pool *pool = channel->pool; diff --git a/drivers/kernel/drivers/nfb/xdp/ethdev.c b/drivers/kernel/drivers/nfb/xdp/ethdev.c index 2cb9a28f..aae4441a 100644 --- a/drivers/kernel/drivers/nfb/xdp/ethdev.c +++ b/drivers/kernel/drivers/nfb/xdp/ethdev.c @@ -45,18 +45,6 @@ static int nfb_xdp_channels_init(struct net_device *netdev, unsigned *channel_in ethdev->channels[map_idx].index = map_idx; ethdev->channels[map_idx].nfb_index = nfb_idx; ethdev->channels[map_idx].numa = dev_to_node(ðdev->nfb->pci->dev); -#ifdef CONFIG_HAVE_NETIF_NAPI_ADD_WITH_WEIGHT - netif_napi_add(netdev, ðdev->channels[map_idx].rxq.napi_pp, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); - netif_napi_add(netdev, ðdev->channels[map_idx].rxq.napi_xsk, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); -#else - netif_napi_add_weight(netdev, ðdev->channels[map_idx].rxq.napi_pp, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); - netif_napi_add_weight(netdev, ðdev->channels[map_idx].rxq.napi_xsk, nfb_xctrl_napi_poll_rx_xsk, NAPI_POLL_WEIGHT); -#endif -#ifdef CONFIG_HAVE_NETIF_NAPI_ADD_TX_WEIGHT - netif_napi_add_tx_weight(netdev, ðdev->channels[map_idx].txq.napi_xsk, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); -#else - netif_tx_napi_add(netdev, ðdev->channels[map_idx].txq.napi_xsk, nfb_xctrl_napi_poll_tx_xsk, NAPI_POLL_WEIGHT); -#endif map_idx++; } } @@ -68,14 +56,7 @@ static int nfb_xdp_channels_init(struct net_device *netdev, unsigned *channel_in static void nfb_xdp_channels_deinit(struct net_device *netdev) { - u32 i; struct nfb_ethdev *ethdev = netdev_priv(netdev); - - for (i = 0; i < ethdev->channel_count; i++) { - netif_napi_del(ðdev->channels[i].rxq.napi_pp); - netif_napi_del(ðdev->channels[i].rxq.napi_xsk); - netif_napi_del(ðdev->channels[i].txq.napi_xsk); - } kfree(ethdev->channels); } @@ -305,12 +286,11 @@ int create_ethdev(struct nfb_xdp *module, u16 index, unsigned * channel_indexes, ethdev->netdev = netdev; // Initialize channels - if ((ret = nfb_xdp_channels_init(netdev,channel_indexes, channel_count))) { + if ((ret = nfb_xdp_channels_init(netdev, channel_indexes, channel_count))) { dev_warn(&module->dev, "Failed to add XDP device, error initializing channels\n"); goto err_channels_init; } - - // NOTE: nc_mac_enable ~ nfb-eth -e1 + // NOTE: XDP netdevice can have multiple macs, to set link all relevant macs need to be considered. // open rx mac component if(!(ethdev->nc_rxmacs = kzalloc(sizeof(struct nc_rxmac *) * module->ethc, GFP_KERNEL))) { From 1c2682d60feeeaf7bcf3125b2e8ed9cd624d3319 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 May 2025 09:54:10 +0200 Subject: [PATCH 357/518] feat(nfb-eth): do not print spaces in QSFP+ --- tools/eth/qsfpp.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/eth/qsfpp.c b/tools/eth/qsfpp.c index 669dafa4..29ce6d03 100644 --- a/tools/eth/qsfpp.c +++ b/tools/eth/qsfpp.c @@ -295,15 +295,19 @@ const char *cmis_mit(uint8_t reg) * @param count Maximal number of characters */ -void qsfp_i2c_text_print(struct nc_i2c_ctrl *i2c, uint8_t reg, unsigned count) +int qsfp_i2c_text_print(struct nc_i2c_ctrl *i2c, uint8_t reg, unsigned count) { + FILE *fout = stdout; /* INFO: Some modules doesn't supports continuous reads, disable burst mode */ const unsigned BURST = 1; char text[BURST + 1]; int ret; + int rcnt = 0; unsigned cnt; unsigned i = 0; + int j; + int spaces = 0; while (count) { cnt = count < BURST ? count : BURST; @@ -313,14 +317,22 @@ void qsfp_i2c_text_print(struct nc_i2c_ctrl *i2c, uint8_t reg, unsigned count) break; text[ret] = 0; - printf("%s", text); + for (j = 0; j < ret; j++) { + if (text[j] == ' ') { + spaces++; + } else { + rcnt += fprintf(fout, "%*s%c", spaces, "", text[j]); + spaces = 0; + } + } + count -= cnt; i += cnt; if (strlen(text) < cnt) break; } - printf("\n"); + return rcnt; } #if 0 From 3c6e6b0f82e5824b2bbcb8abe8e398907aafdca2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 13 Jan 2025 10:52:53 +0100 Subject: [PATCH 358/518] feat(libnetcope): add NI library for unified formatted output of normalized items --- libnfb/include/netcope/ni.h | 20 ++ libnfb/include/netcope/ni/conf_default.h | 254 +++++++++++++++++ libnfb/include/netcope/ni/core.h | 185 +++++++++++++ libnfb/include/netcope/ni/plugin_json.h | 246 +++++++++++++++++ libnfb/include/netcope/ni/plugin_user.h | 329 +++++++++++++++++++++++ 5 files changed, 1034 insertions(+) create mode 100644 libnfb/include/netcope/ni.h create mode 100644 libnfb/include/netcope/ni/conf_default.h create mode 100644 libnfb/include/netcope/ni/core.h create mode 100644 libnfb/include/netcope/ni/plugin_json.h create mode 100644 libnfb/include/netcope/ni/plugin_user.h diff --git a/libnfb/include/netcope/ni.h b/libnfb/include/netcope/ni.h new file mode 100644 index 00000000..061a1ef6 --- /dev/null +++ b/libnfb/include/netcope/ni.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Library for unified formated output of normalized items: default configuration + * + * Copyright (C) 2025 CESNET + * Author(s): + * Martin Spinler + */ + +#ifndef __NETCOPE_NI__ +#define __NETCOPE_NI__ + +#include "ni/core.h" + +#include "ni/plugin_user.h" +#include "ni/plugin_json.h" + +#include "ni/conf_default.h" + +#endif // __NETCOPE_NI__ diff --git a/libnfb/include/netcope/ni/conf_default.h b/libnfb/include/netcope/ni/conf_default.h new file mode 100644 index 00000000..4ab3df1b --- /dev/null +++ b/libnfb/include/netcope/ni/conf_default.h @@ -0,0 +1,254 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Library for unified formated output of normalized items: default configuration (json + user) + * + * Copyright (C) 2025 CESNET + * Author(s): + * Martin Spinler + */ + +#ifndef __NETCOPE_NI_DEFAULT__ +#define __NETCOPE_NI_DEFAULT__ + + +/* + * Default configuration for NI library with USER and JSON output plugins. + * + * This file prepares ready-to-use structures (struct ni_context_item_default, + * struct ni_common_item_callbacks) and access functions. Also prepares basic + * set of ni_item_* functions generated by macro NI_DEFAULT_ITEMS(). + * + * Usage: + * 1) create enum value for all output items, + * 2) create ni_context_item_default array and fill + * both JSON and USER members (see plugin file for details), + * 3) generate ni_item output functions through NI_DEFAULT_ITEMS() macro: + * a) for usage with custom callbacks use `NI_DEFAULT_ITEMS(cbs_struct_type, ci_accessor.)` + * where cbs_struc_type is custom structure type with callbacks and ci_accessor + * is the name of cbs_struct_type member which has assigned ni_common_item_callbacks value, + * b) otherwise use `NI_DEFAULT_ITEMS(ni_common_item_callbacks, )` + * 4) use `ni_init_root_context_default`, pass a value from enum ni_context_defaults, + * items in ni_context_defaults and + * a) selected-plugin-specific callback struct pointer for usage with custom callbacks + * b) for no custom callbacks use &ni_common_item_callbacks[selected_ni_context_default_plugin]. + * 5) use structural functions (ni_section/ni_endsection, ni_list/ni_endlist) or ni_item_* value-print functions + * to produce output. + */ + +enum ni_context_defaults { + NI_DRC_USER = 0, + NI_DRC_JSON, +}; + +struct ni_context_item_default { + struct ni_json_item json; + struct ni_user_item user; +}; + +static inline void* ni_get_item_default_json(void *items, int item_index) +{ + struct ni_context_item_default * ni_items = items; + if (items == NULL) + return NULL; + return &ni_items[item_index].json; +} + +static inline void* ni_get_item_default_user(void *items, int item_index) +{ + struct ni_context_item_default * ni_items = items; + if (items == NULL) + return NULL; + + return &ni_items[item_index].user; +} + +static const struct ni_callbacks ni_cb_json = { + .init = ni_json_init, + .close = ni_json_close, + .section = ni_json_section, + .endsection = ni_json_endsection, + .list = ni_json_list, + .endlist = ni_json_endlist, + .prelude = ni_json_prelude, + .postlude = ni_json_postlude, +}; + +static const struct ni_callbacks ni_cb_user = { + .init = ni_user_init, + .section = ni_user_section, + .endsection = ni_user_endsection, + .list = ni_user_list, + .endlist = ni_user_endlist, + .prelude = ni_user_prelude, + .postlude = ni_user_postlude, +}; + +/* Common print functions */ +static int ni_def_print_str_user(void *priv, int item, const char *val) +{ + struct ni_user_cbp *p = priv; + (void) item; + return fprintf(p->f, "%*s", p->align, val); +} + +static int ni_def_print_str_json(void *priv, int item, const char *val) +{ + struct ni_json_cbp *p = priv; + (void) item; + /* TODO: escape quotes */ + return fprintf(p->f, "\"%s\"", val); +} + +static int ni_def_print_xreg_user(void *priv, int item, uint64_t val) +{ + struct ni_user_cbp *p = priv; + int ret = 0; + (void) item; + + ret += fprintf(p->f, "0x%0*" PRIX64, p->width, val); + + if (p->align > ret) + ret += fprintf(p->f, "%*s", p->align - ret, ""); + return ret; +} + +static int ni_def_print_xreg_json(void *priv, int item, uint64_t val) +{ + struct ni_json_cbp *p = priv; + (void) item; + return fprintf(p->f, "%lu", val); +} + +static int ni_def_print_double_user(void *priv, int item, double val) +{ + struct ni_user_cbp *p = priv; + (void) item; + return fprintf(p->f, "%*.*f", p->align, p->decim, val); +} + +static int ni_def_print_double_json(void *priv, int item, double val) +{ + struct ni_json_cbp *p = priv; + (void) item; + return fprintf(p->f, "%.*f", p->decim, val); +} + +static int ni_def_print_int_user(void *priv, int item, int val) +{ + struct ni_user_cbp *p = priv; + (void) item; + return fprintf(p->f, "%*d", p->width, val); +} + +static int ni_def_print_int_json(void *priv, int item, int val) +{ + struct ni_json_cbp *p = priv; + (void) item; + return fprintf(p->f, "%d", val); +} + +static int ni_def_print_uint64_t_user(void *priv, int item, uint64_t val) +{ + struct ni_user_cbp *p = priv; + (void) item; + return fprintf(p->f, "%*"PRIu64, p->width, val); +} + +static int ni_def_print_uint64_t_json(void *priv, int item, uint64_t val) +{ + struct ni_json_cbp *p = priv; + (void) item; + return fprintf(p->f, "%"PRIu64, val); +} + +struct ni_common_item_callbacks { + int (*print_str)(void *priv, int item, const char *); + int (*print_xreg)(void *priv, int item, uint64_t); + int (*print_double)(void *priv, int item, double); + int (*print_int)(void *priv, int item, int); + int (*print_uint64_t)(void *priv, int item, uint64_t); +}; + + +#define NI_CIC_USER \ + [NI_DRC_USER] = {\ + .print_str = ni_def_print_str_user,\ + .print_xreg = ni_def_print_xreg_user,\ + .print_double = ni_def_print_double_user,\ + .print_int = ni_def_print_int_user,\ + .print_uint64_t = ni_def_print_uint64_t_user,\ + } + +#define NI_CIC_JSON \ + [NI_DRC_JSON] = {\ + .print_str = ni_def_print_str_json,\ + .print_xreg = ni_def_print_xreg_json,\ + .print_double = ni_def_print_double_json,\ + .print_int = ni_def_print_int_json,\ + .print_uint64_t = ni_def_print_uint64_t_json,\ + } + +static const struct ni_common_item_callbacks ni_common_item_callbacks[] = { + NI_CIC_USER, + NI_CIC_JSON, +}; + +static inline struct ni_context *ni_init_root_context_default(int ni_drc, struct ni_context_item_default *items, const void *custom_item_cbs) +{ + static struct ni_callbacks cb_user = ni_cb_user; + static struct ni_callbacks cb_json = ni_cb_json; + + const struct ni_callbacks *cb = NULL; + struct ni_common_init_params cip; + + cip.items = items; + if (ni_drc == NI_DRC_JSON) { + cb = &cb_json; + cip.get = ni_get_item_default_json; + } else if (ni_drc == NI_DRC_USER) { + cb = &cb_user; + cip.get = ni_get_item_default_user; + } else { + return NULL; + } + + return ni_init_root_context(cb, NULL, &cip, custom_item_cbs); +} + +#define _NI_FDT_PROPS(name, ni_name, type, LEN_COND)\ +static inline int ni_fdt_prop_##name(struct ni_context *ctx, int item, const void *fdt, int fdt_offset, const char* prop_name, int *len)\ +{\ + int ilen;\ + type prop;\ +\ + prop = fdt_getprop(fdt, fdt_offset, prop_name, &ilen);\ + if (ilen LEN_COND)\ + ni_item_##ni_name(ctx, item, prop);\ + if (len)\ + *len = ilen;\ + return ilen;\ +} + +#define _NI_FDT_PROPD(name, ni_name, type, LEN_COND, conv)\ +static inline int ni_fdt_prop_##name(struct ni_context *ctx, int item, const void *fdt, int fdt_offset, const char* prop_name)\ +{\ + int ilen;\ + type *prop;\ +\ + prop = fdt_getprop(fdt, fdt_offset, prop_name, &ilen);\ + if (ilen LEN_COND)\ + ni_item_##ni_name(ctx, item, conv(*prop));\ + return ilen;\ +} + +#define NI_DEFAULT_ITEMS(cbtype, accessor) \ + NI_ITEM_CB(double, double, cbtype, accessor print_double)\ + NI_ITEM_CB(int, int, cbtype, accessor print_int)\ + NI_ITEM_CB(uint64_t, uint64_t, cbtype, accessor print_uint64_t)\ + NI_ITEM_CB(str, const char*, cbtype, accessor print_str)\ + NI_ITEM_CB(uint64_tx, uint64_t, cbtype, accessor print_xreg)\ + _NI_FDT_PROPS(str, str, const char*, >= 0)\ + _NI_FDT_PROPD(32, int, const uint32_t, == sizeof(uint32_t), fdt32_to_cpu)\ + _NI_FDT_PROPD(uint64_tx, uint64_tx, const uint64_t, == sizeof(uint64_t), fdt64_to_cpu)\ + +#endif // __NETCOPE_NI_DEFAULT__ diff --git a/libnfb/include/netcope/ni/core.h b/libnfb/include/netcope/ni/core.h new file mode 100644 index 00000000..80ddf259 --- /dev/null +++ b/libnfb/include/netcope/ni/core.h @@ -0,0 +1,185 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Library for unified formated output of normalized items: core + * + * Copyright (C) 2025 CESNET + * Author(s): + * Martin Spinler + */ + +#ifndef __NETCOPE_NI_CORE__ +#define __NETCOPE_NI_CORE__ + + +/* + * Core implementation for unified formated output consist of: + * + * struct ni_callback - exposes base interface to be implemented in each output plugin + * + * struct ni_context *ni_init_root_context(ni_callbacks, items, init_params, item_cbs) + * void ni_close_root_context(ni_context) + * + * void ni_section(c, i) / void ni_endsection(c, i) + * void ni_list(c, i) / void ni_endlist(c, i) + * Functions for generating structural elements. + * args: + * c (struct ni_context*): context handle + * i (int): item index to be produced + * + * NI_ITEM_CB(name, type, cb_t, vp_n) + * Common macro for generating value-print function (ni_item_*) + * args: + * name: suffix for generated ni_item_ function + * type: type of accepted value + * cb_t: type of struct with value print callbacks + * vp_n: function name inside cb_t for value print + * + * Generated function ni_item_name(c, i, v) + * args: + * c (struct ni_context *): context handle + * i (int): item index to be produced + * v (_generic_): value to be produced + * + */ + + +struct ni_common_init_params { + void *items; + void* (*get)(void *items, int item_index); +}; + +struct ni_callbacks { + int (*init)(void *init_params, struct ni_common_init_params *cip, void **priv); + void (*close)(void *priv); + + /* produce plugin-specific output before producing item output + * + * args: + * priv: plugin private data + * item: custom data structure for specified item + * cb_priv: pointer to handle which will be passed to value-print callback + * ret: + * -1: do not print value + * -2: do not call postlude + * >= 0: print value, call postlude + */ + int (*prelude)(void *priv, int item, void **cb_priv); + + /* produce plugin-specific output after producing item output + * args: + * item: custom data structure for specified item + * value_length: length of item produced output + */ + void (*postlude)(void *priv, int item, int value_length); + + /* produce structural element output */ + void (*section)(void *priv, int item); + void (*endsection)(void *priv, int item); + void (*list)(void *priv, int item); + void (*endlist)(void *priv, int item); +}; + +struct ni_context { + const struct ni_callbacks *cbs; + void *priv; + const void *item_cbs; +}; + + +typedef struct ni_context_item ni_context_item_t; + + +static inline struct ni_context *ni_init_root_context(const struct ni_callbacks * cbs, void *init_params, struct ni_common_init_params * cip, const void *item_cbs) +{ + int ret = 0; + struct ni_context *ctx; + + if (cbs == NULL || item_cbs == NULL) + return NULL; + + ctx = malloc(sizeof *ctx); + if (ctx == NULL) + return NULL; + + ctx->cbs = cbs; + ctx->item_cbs = item_cbs; + if (ctx->cbs->init) + ret = ctx->cbs->init(init_params, cip, &ctx->priv); + if (ret) { + free(ctx); + return NULL; + } + return ctx; +} + +static inline void ni_close_root_context(struct ni_context *ctx) +{ + if (ctx) { + if (ctx->cbs->close) { + ctx->cbs->close(ctx->priv); + } + free(ctx); + } +} + +static inline void ni_section(struct ni_context *ctx, int item) +{ + if (ctx && ctx->cbs->section) { + ctx->cbs->section(ctx->priv, item); + } +} + +static inline void ni_endsection(struct ni_context *ctx, int item) +{ + if (ctx && ctx->cbs->endsection) { + ctx->cbs->endsection(ctx->priv, item); + } +} + +static inline void ni_list(struct ni_context *ctx, int item) +{ + if (ctx && ctx->cbs->list) { + ctx->cbs->list(ctx->priv, item); + } +} + +static inline void ni_endlist(struct ni_context *ctx, int item) +{ + if (ctx && ctx->cbs->endlist) { + ctx->cbs->endlist(ctx->priv, item); + } +} + +#define NI_ITEM_CB(name, type, cb_t, cb_n)\ +static inline void ni_item_##name(struct ni_context * ctx, int item, type value)\ +{\ + int _ret;\ + int _len = 0;\ + const struct cb_t * cbs;\ + void * cb_priv = NULL;\ +\ + if (ctx == NULL)\ + return;\ + cbs = ctx->item_cbs;\ +\ + _ret = ctx->cbs->prelude(ctx->priv, item, &cb_priv);\ + if (_ret == -1) {\ + return;\ + } else if (_ret >= 0) {\ + _len = cbs->cb_n(cb_priv, item, value);\ + }\ + ctx->cbs->postlude(ctx->priv, item, _len);\ +} + +/* Common helpers */ +#define _ni_enc_int8_t(x, bit)\ + ((x) >= 0 ?\ + ((((unsigned long long)(+(x))) & 0x7F) << (bit)) :\ + ((((unsigned long long)(-(x))) & 0x7F) << (bit)) | (1ll << ((bit) + 7))) + +#define _ni_dec_int8_t(x, bit)\ + ((x) & (1ll << ((bit) + 7)) ?\ + -((((signed long long)(x)) >> (bit)) & 0x7F) :\ + +((((signed long long)(x)) >> (bit)) & 0x7F)) + +#endif // __NETCOPE_NI_CORE__ diff --git a/libnfb/include/netcope/ni/plugin_json.h b/libnfb/include/netcope/ni/plugin_json.h new file mode 100644 index 00000000..405b026f --- /dev/null +++ b/libnfb/include/netcope/ni/plugin_json.h @@ -0,0 +1,246 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Library for unified formated output of normalized items: JSON output plugin + * + * Copyright (C) 2025 CESNET + * Author(s): + * Martin Spinler + */ + +#ifndef __NETCOPE_NI_JSON__ +#define __NETCOPE_NI_JSON__ + +#define _NI_JSON_TYPE_COMMON 0 +#define _NI_JSON_TYPE_ARRAY 1 +#define _NI_JSON_TYPE_OBJECT 2 + +#define _NI_JSON_FLAG_NOKEY (1 << 0) + +struct ni_json_item { + const char *key; + unsigned long long flags; +}; + +/* Predefined shortcuts for specifying items */ +/* Default item */ +#define ni_json_k(key) {key, 0} + +/* No-output item */ +#define ni_json_n {NULL, 0} + +/* Item with no key (e.g. array item) */ +#define ni_json_e {NULL, _NI_JSON_FLAG_NOKEY} + +/* Item with specific flags */ +#define ni_json_f(key, flags) {key, flags} + +#define ni_json_f_decim(x) _ni_enc_int8_t(x, 32) +#define ni_json_f_decim_dec(x) _ni_dec_int8_t(x, 32) + + +/* Internals */ +struct ni_json_stack_state { + int current_index; /* Current item index in array / object */ + int current_type; + const char *nip; +}; + +struct ni_json_cbp { + FILE *f; + int item; + int8_t decim; +}; + +struct ni_json_priv { + struct ni_json_cbp cbp; /* data for item callback */ + struct ni_common_init_params ip; + void *items; + + /* constants */ + const char *nls; + + int use_nls; + int indent_size; + + /* variables */ + const char *label; + const char *delim; /* delimiter between key (label) and value */ + const char *vc; /* value container: put value inside of */ + const char *pfx; + const char *nl; + int align; + int ind; + + int indent; + + /* internals */ + struct ni_json_stack_state *s; + struct ni_json_stack_state stack_states[]; +}; + +static inline int ni_json_init(void *init_params, struct ni_common_init_params *cip, void **ppriv) +{ + const int stack_size = 16; + + struct ni_json_priv *ctx; + + (void) init_params; + + if(cip->get == NULL || cip->items == NULL) + return -EINVAL; + + ctx = malloc(sizeof(struct ni_json_priv) + sizeof(struct ni_json_stack_state) * stack_size); + if (ctx == NULL) + return -ENOMEM; + *ppriv = ctx; + ctx->ip = *cip; + + ctx->use_nls = 1; + ctx->nls = "\n"; + ctx->indent_size = 4; + + ctx->indent = 0; + ctx->s = &ctx->stack_states[0]; + + ctx->s->current_type = _NI_JSON_TYPE_COMMON; + ctx->s->current_index = 0; + ctx->s->nip = ""; + return 0; +} + +static inline void ni_json_close(void *priv) +{ + struct ni_json_priv *ctx = priv; + (void)ctx; + + printf("\n"); +} + +static inline void ni_json_section(void *priv, int item_index) +{ + struct ni_json_priv *ctx = priv; + struct ni_json_item *item = ctx->ip.get(ctx->ip.items, item_index); + const char *pfx = ctx->s->nip; + int ct; + + if (item->key == NULL && item->flags == 0) + return; + + ctx->s->current_index++; + ct = ctx->s->current_type; + + ctx->s++; + ctx->s->current_index = 0; + ctx->s->current_type = _NI_JSON_TYPE_OBJECT; + + ctx->s->nip = ctx->use_nls ? "\n" : ""; + if (ct != _NI_JSON_TYPE_OBJECT) { + printf("%s%*s%s{%s", pfx, ctx->indent * ctx->indent_size, "", "", ""); + } else { + printf("%s%*s\"%s\": {%s", pfx, ctx->indent * ctx->indent_size, "", item->key, ""); + } + + ctx->indent++; +} + +static inline void ni_json_endsection(void *priv, int item_index) +{ + struct ni_json_priv *ctx = priv; + struct ni_json_item *item = ctx->ip.get(ctx->ip.items, item_index); + (void) item; + + if (item->key == NULL && item->flags == 0) + return; + + ctx->indent--; + if (ctx->s->current_index == 0) + printf("}"); + else + printf("%s%*s}", ctx->nls, ctx->indent * ctx->indent_size, ""); + + ctx->s--; + + if (ctx->s->current_type == _NI_JSON_TYPE_ARRAY || ctx->s->current_type == _NI_JSON_TYPE_OBJECT) + ctx->s->nip = ctx->use_nls ? ",\n" : ", "; +} + +static inline void ni_json_list(void *priv, int item_index) +{ + struct ni_json_priv *ctx = priv; + struct ni_json_item *item = ctx->ip.get(ctx->ip.items, item_index); + const char *pfx = ctx->s->nip; + int ct; + + if (item->key == NULL && item->flags == 0) + return; + + ctx->s->current_index++; + ct = ctx->s->current_type; + + ctx->s++; + ctx->s->current_index = 0; + ctx->s->current_type = _NI_JSON_TYPE_ARRAY; + + ctx->s->nip = ctx->use_nls ? "\n" : ""; + if (ct != _NI_JSON_TYPE_OBJECT || item->key == NULL) { + printf("%s%*s%s[%s", pfx, ctx->indent * ctx->indent_size, "", "", ""); + } else { + printf("%s%*s\"%s\": [%s", pfx, ctx->indent * ctx->indent_size, "", item->key, ""); + } + ctx->indent++; +} + +static inline void ni_json_endlist(void*priv, int item_index) +{ + struct ni_json_priv *ctx = priv; + struct ni_json_item *item = ctx->ip.get(ctx->ip.items, item_index); + + if (item->key == NULL && item->flags == 0) + return; + + ctx->indent--; + if (ctx->s->current_index == 0) + printf("]"); + else + printf("%s%*s]", ctx->nls, ctx->indent * ctx->indent_size, ""); + ctx->s--; + + if (ctx->s->current_type == _NI_JSON_TYPE_ARRAY || ctx->s->current_type == _NI_JSON_TYPE_OBJECT) + ctx->s->nip = ctx->use_nls ? ",\n" : ", "; +} + +static inline int ni_json_prelude(void *priv, int item_index, void **cb_priv) +{ + struct ni_json_priv *ctx = priv; + struct ni_json_item *item = ctx->ip.get(ctx->ip.items, item_index); + + ctx->label = item->key; + ctx->ind = ctx->use_nls ? ctx->indent * ctx->indent_size : 0; + *cb_priv = &ctx->cbp; + + if (ctx->label == NULL && item->flags == 0) { + return -1; + } + ctx->cbp.f = stdout; + ctx->cbp.decim = ni_json_f_decim_dec(item->flags); + + if (ctx->s->current_type != _NI_JSON_TYPE_ARRAY) + printf("%s%*s\"%s\": ", ctx->s->nip, ctx->ind, "", ctx->label); + else + printf("%s%*s%s", ctx->s->nip, ctx->ind, "", ""); + + ctx->s->nip = ctx->use_nls ? ",\n" : ", "; + return 0; +} + +static inline void ni_json_postlude(void *priv, int item_index, int value_length) +{ + struct ni_json_priv *ctx = priv; + struct ni_json_item *item = ctx->ip.get(ctx->ip.items, item_index); + (void) value_length; + (void) item; + + ctx->s->current_index++; +} + +#endif // __NETCOPE_NI_JSON__ diff --git a/libnfb/include/netcope/ni/plugin_user.h b/libnfb/include/netcope/ni/plugin_user.h new file mode 100644 index 00000000..02eb73f0 --- /dev/null +++ b/libnfb/include/netcope/ni/plugin_user.h @@ -0,0 +1,329 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Library for unified formated output of normalized items: user readable output plugin + * + * Copyright (C) 2025 CESNET + * Author(s): + * Martin Spinler + */ + +#ifndef __NETCOPE_NI_USER__ +#define __NETCOPE_NI_USER__ + +#define ni_user_f_align(x) _ni_enc_int8_t(x, 32) +#define ni_user_f_align_dec(x) _ni_dec_int8_t(x, 32) + +#define ni_user_f_decim(x) _ni_enc_int8_t(x, 40) +#define ni_user_f_decim_dec(x) _ni_dec_int8_t(x, 40) + +#define ni_user_f_width(x) _ni_enc_int8_t(x, 48) +#define ni_user_f_width_dec(x) _ni_dec_int8_t(x, 48) + +#define NI_USER_ITEM_F_NO_NEWLINE (1 << 0) +#define NI_USER_ITEM_F_NO_DELIMITER (1 << 1) +#define NI_USER_ITEM_F_NO_ALIGN (1 << 2) +#define NI_USER_ITEM_F_NO_VALUE (1 << 3) +#define NI_USER_ITEM_F_SEC_LABEL (1 << 4) +#define NI_USER_LIST_F_ENDLINE (1 << 5) +#define NI_USER_LIST_F_NO_LABEL (1 << 6) +#define NI_USER_LIST_F_NO_VALUE NI_USER_ITEM_F_NO_VALUE + +struct ni_user_item { + const char *label; + unsigned long long flags; + const char *vp; /* Value prefix */ + const char *vs; /* Value suffix */ +}; + +#define ni_user_n \ + {NULL, 0, NULL, NULL} + +/* label only */ +#define ni_user_l(label) \ + {label, 0, NULL, NULL} + +#define ni_user_f(key, flags) \ + {key, (flags), NULL, NULL} + +#define ni_user_v(key, flags, vp, vs) \ + {key, (flags), vp, vs} + + +/* Internals */ + +struct ni_user_stack_state { + struct ni_user_item *item; + int seg; /* 0, 1=section (header), 2=list */ + int current_index; /* Current index in array / dict */ +}; + +struct ni_user_cbp { + FILE *f; + int8_t align; + int8_t width; + int8_t decim; +}; + + +struct ni_user_priv { + struct ni_user_cbp cbp; /* data for item callback */ + struct ni_common_init_params ip; + + int clo; /* current line offset*/ + + const char *vs; /* value suffix */ + const char *nl; + char *buffer; + size_t buffer_size; + FILE *f; /* current output */ + FILE *fb; /* buffer file */ + FILE *fo; /* stdout */ + + struct ni_user_stack_state *s; + struct ni_user_stack_state stack_states[]; +}; + +static const char *_ni_user_helper_dash = + "-----------------------------------------------------------" + "-----------------------------------------------------------"; + +static inline int ni_user_init(void *init_params, struct ni_common_init_params *cip, void **ppriv) +{ + struct ni_user_priv * ctx; + const int stack_size = 16; + (void) init_params; + + if(cip->get == NULL || cip->items == NULL) + return -EINVAL; + + ctx = malloc(sizeof(struct ni_user_priv) + sizeof(struct ni_user_stack_state) * stack_size + 4096); + if (ctx == NULL) + return -ENOMEM; + + *ppriv = ctx; + ctx->ip = *cip; + + ctx->clo = 0; + + ctx->buffer = (void*) (ctx + 1); + ctx->buffer += sizeof(struct ni_user_stack_state) * stack_size; + + ctx->fb = open_memstream(&ctx->buffer, &ctx->buffer_size); + ctx->fo = stdout; + + ctx->f = ctx->fo; + + ctx->s = &ctx->stack_states[0]; + ctx->s->item = NULL; + ctx->s->seg = 0; + ctx->s->current_index = 0; + + return 0; +} + +static inline void ni_user_flush_f(struct ni_user_priv *ctx) +{ + int db, de; + const char *sp = " "; + + long pos = ftell(ctx->fb); + if (pos) { + db = 55 - pos - 2 - 4; + de = 4; + + fflush(ctx->fb); + ctx->buffer[pos] = 0; + fprintf(ctx->fo, "%.*s%s%s%s%.*s\n", db, _ni_user_helper_dash, sp, ctx->buffer, sp, de, _ni_user_helper_dash); + fflush(ctx->fo); + fseek(ctx->fb, 0, SEEK_SET); + + ctx->clo = 0; + } + + ctx->f = ctx->fo; +} + +static inline void ni_user_section(void *priv, int item_index) +{ + struct ni_user_priv *ctx = priv; + struct ni_user_item *item = ctx->ip.get(ctx->ip.items, item_index); + + const char *between = ""; + if (ctx->s->current_index && ctx->s->seg == 2 && ctx->s->item && ctx->s->item->vp) { + between = ctx->s->item->vp; + fprintf(ctx->f, "%s", between); + } + + ctx->s->current_index++; + + ctx->s++; + ctx->s->item = item; + ctx->s->current_index = 0; + ctx->s->seg = 0; + + if (item->label == NULL) + return; + + ni_user_flush_f(ctx); + + ctx->f = ctx->fb; + ctx->clo += fprintf(ctx->f, "%s", item->label); +} + +static inline void ni_user_endsection(void *priv, int item_index) +{ + struct ni_user_priv *ctx = priv; + struct ni_user_item *item = ctx->ip.get(ctx->ip.items, item_index); + + (void)item; + ni_user_flush_f(ctx); + + ctx->s--; +} + +static inline void ni_user_list(void *priv, int item_index) +{ + struct ni_user_priv *ctx = priv; + struct ni_user_item *item = ctx->ip.get(ctx->ip.items, item_index); + + if (item->flags & NI_USER_LIST_F_NO_LABEL) + return; + + ctx->s->current_index++; + ctx->s++; + ctx->s->current_index = 0; + ctx->s->seg = 2; + ctx->s->item = item; + + if (item->label) { + ctx->clo += fprintf(ctx->f, "%s", item->label); + + if ((item->flags & NI_USER_LIST_F_NO_VALUE)) { + const char *delim = ":"; + int align = 27 - ctx->clo; + ctx->clo += fprintf(ctx->f, "%*s%s ", align, "", delim); + } else { + fprintf(ctx->f, "\n"); + ctx->clo = 0; + } + } +} + +static inline void ni_user_endlist(void *priv, int item_index) +{ + struct ni_user_priv *ctx = priv; + struct ni_user_item *item = ctx->ip.get(ctx->ip.items, item_index); + + if (item->flags & NI_USER_LIST_F_NO_LABEL) { + fseek(ctx->fb, 0, SEEK_SET); + return; + } + + ni_user_flush_f(ctx); + if (item->flags & NI_USER_LIST_F_ENDLINE) { + fprintf(ctx->f, "\n"); + ctx->clo = 0; + } + + ctx->s--; +} + +static inline int ni_user_prelude(void *priv, int item_index, void **cb_priv) +{ + struct ni_user_priv *ctx = priv; + struct ni_user_item *item = ctx->ip.get(ctx->ip.items, item_index); + int ret; + int align = 0; + const char *delim; + const char *label; + const char *vp; /* value prefix */ + + /* Alignment: + * 0 : align value (if is default for current mode) to default (first) column [default] + * -1: do not align value + * 1 : align value to first column + */ + + *cb_priv = &ctx->cbp; + + ctx->cbp.align = ni_user_f_align_dec(item->flags); + ctx->cbp.decim = ni_user_f_decim_dec(item->flags); + ctx->cbp.width = ni_user_f_width_dec(item->flags); + + align = ctx->cbp.align; + + ctx->nl = "\n"; + label = item->label; + + delim = ": "; + + if (item->flags & NI_USER_ITEM_F_NO_NEWLINE) + ctx->nl = ""; + if (item->flags & NI_USER_ITEM_F_NO_DELIMITER) + delim = ""; + if (item->flags & NI_USER_ITEM_F_NO_ALIGN) + align = -1; + + if (item->flags == 0 && item->label == NULL) + return -1; + + if (!(item->flags & NI_USER_ITEM_F_SEC_LABEL)) { + ni_user_flush_f(ctx); + } + ctx->cbp.f = ctx->f; + + const char *between = ""; + if (ctx->s->current_index && ctx->s->seg == 2 && ctx->s->item && ctx->s->item->vp) { + between = ctx->s->item->vp; + fprintf(ctx->f, "%s", between); + } + int xalign = ni_user_f_align_dec(ctx->s->item->flags); + if (xalign && ctx->s->seg == 2 && ctx->s->current_index % xalign == 0 && ctx->s->current_index != 0) { + //align = 27 - ctx->clo; + fprintf(ctx->f, "\n%*s",29, ""); + ctx->clo = 0; + } + ctx->s->current_index++; + + vp = item->vp ? item->vp : ""; + ctx->vs = item->vs ? item->vs : ""; + label = item->label ? item->label : ""; + + ret = fprintf(ctx->f, "%s", label); + ctx->clo += ret; + + if (align == 0) + align = 27 - ctx->clo; + if (align == -1) + align = 0; + + ret = fprintf(ctx->f, "%*s%s%s", align, "", delim, vp); + ctx->clo += ret; + + if (item->flags & NI_USER_ITEM_F_NO_VALUE) + return -2; + + return 0; +} + +static inline void ni_user_postlude(void *priv, int item_index, int value_length) +{ + struct ni_user_priv *ctx = priv; + struct ni_user_item *item = ctx->ip.get(ctx->ip.items, item_index); + + int skip_vs = 0; //item->flags & 8; + int ret; + + (void) item; + + ret = fprintf(ctx->f, "%s%s", skip_vs ? "" : ctx->vs, ctx->nl); + + ctx->clo += ret + value_length; + + if (strcmp(ctx->nl, "\n") == 0) { + ctx->clo = 0; + } +} + + +#endif // __NETCOPE_NI_USER__ From d8f503a0829105955fc02cd61a7e9bb283ae9436 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 30 Apr 2025 15:07:45 +0200 Subject: [PATCH 359/518] feat(nfb-info): use NI (normalized item) library for output --- tools/info/info.c | 376 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 262 insertions(+), 114 deletions(-) diff --git a/tools/info/info.c b/tools/info/info.c index 14bd7b7a..532283fa 100644 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -27,7 +27,9 @@ #include #include -#define ARGUMENTS "d:q:hlvV" +#include + +#define ARGUMENTS "d:q:hjlvV" #define BUFFER_SIZE 64 @@ -99,11 +101,150 @@ void usage(const char *progname, int verbose) printf(" example of usage: '-q project,build,card'\n"); } printf("-l Print list of available devices\n"); + printf("-j Print output in JSON\n"); printf("-v Increase verbosity\n"); printf("-V Show version\n"); printf("-h Show this text\n"); } +NI_DEFAULT_ITEMS(ni_common_item_callbacks, ) + + +enum NI_ITEMS { + NI_SEC_ROOT = 0, + NI_SEC0_BOARD_INFO, + NI_BOARD_NAME, + NI_SERIAL_NUMBER, + NI_FPGA_UNIQUE_ID, + NI_NET_IFCS, + NI_LIST_NET_IFCS, + NI_SEC1_NET_IFCS, + NI_IFC_ID, + NI_IFC_TYPE, + NI_TEMPERATURE, + NI_SEC0_FIRMWARE, + NI_CARD_NAME, + NI_PROJECT_NAME, + NI_PROJECT_VARIANT, + NI_PROJECT_VERSION, + NI_BUILT_TIME, + NI_BUILT_TIMESTAMP, + NI_BUILD_TOOL, + NI_BUILD_AUTHOR, + NI_RX_QUEUES_ALL, + NI_RX_QUEUES_EQ_AV, + NI_RX_QUEUES_NEQ_AV, + NI_TX_QUEUES_ALL, + NI_TX_QUEUES_EQ_AV, + NI_TX_QUEUES_NEQ_AV, + NI_ETH_CHANNELS, + NI_LIST_ETH_CHANNELS, + NI_SEC1_ETH_CHANNELS, + NI_ETH_CHANNEL_ID, + NI_ETH_CHANNEL_TYPE, + NI_SEC0_SYSTEM, + NI_SEC1_PCIEP, + NI_LIST_PCIEP, + NI_PCI_ID, + NI_PCI_SLOT, + NI_PCI_LINK_SPEED, + NI_PCI_LINK_WIDTH, + NI_NUMA, + NI_LIST_PCI_BAR, + NI_SEC2_PCI_BAR, + NI_BAR_ID, + NI_BAR_SIZE_STR, + NI_BAR_SIZE, + + /* Card list */ + NI_LIST_NFB, + NI_SEC_LIST_NFB, + NI_L_NFB_ID, + NI_L_LPATH, + NI_L_BFN, + NI_L_CARD_NAME, + NI_L_SN, + NI_L_PROJECT_NAME, + NI_L_PROJECT_VAR, + NI_L_PROJECT_VER, + NI_L_PROJECT_END, +}; + +#define NUF_N (NI_USER_ITEM_F_NO_NEWLINE) +#define NUF_NDA (NI_USER_ITEM_F_NO_NEWLINE | NI_USER_ITEM_F_NO_DELIMITER | NI_USER_ITEM_F_NO_ALIGN) +#define NUF_DA (NI_USER_ITEM_F_NO_DELIMITER | NI_USER_ITEM_F_NO_ALIGN) +#define NUF_DAV (NI_USER_ITEM_F_NO_DELIMITER | NI_USER_ITEM_F_NO_ALIGN | NI_USER_ITEM_F_NO_VALUE) +#define NUFA(x) ni_user_f_align(x) +#define NUFW(x) ni_user_f_width(x) +#define NJFD(x) ni_json_f_decim(x) + +struct ni_context_item_default ni_items[] = { + [NI_SEC_ROOT] = {ni_json_e, ni_user_n}, + + [NI_SEC0_BOARD_INFO] = {ni_json_k("board"), ni_user_l("Board info")}, + [NI_BOARD_NAME] = {ni_json_k("board_name"), ni_user_l("Board name")}, + [NI_SERIAL_NUMBER] = {ni_json_k("serial_number"), ni_user_l("Serial number")}, + [NI_FPGA_UNIQUE_ID] = {ni_json_k("fpga_unique_id"), ni_user_l("FPGA unique ID")}, + [NI_NET_IFCS] = {ni_json_k("network_interfaces"), ni_user_l("Network interfaces")}, + + [NI_LIST_NET_IFCS] = {ni_json_k("interfaces"), ni_user_n}, + [NI_SEC1_NET_IFCS] = {ni_json_e, ni_user_n}, + [NI_IFC_ID] = {ni_json_k("id"), ni_user_f(" * Interface ", NUF_NDA)}, + [NI_IFC_TYPE] = {ni_json_k("type"), ni_user_f("", 0)}, + [NI_TEMPERATURE] = {ni_json_f("temperature", NJFD(1)), ni_user_v("Temperature", ni_user_f_decim(1), NULL, " C")}, + [NI_SEC0_FIRMWARE] = {ni_json_k("firmware"), ni_user_l("Firmware info")}, + [NI_CARD_NAME] = {ni_json_k("card_name"), ni_user_l("Card name")}, + [NI_PROJECT_NAME] = {ni_json_k("project_name"), ni_user_l("Project name")}, + [NI_PROJECT_VARIANT] = {ni_json_k("project_variant"), ni_user_l("Project variant")}, + [NI_PROJECT_VERSION] = {ni_json_k("project_version"), ni_user_l("Project version")}, + [NI_BUILT_TIME] = {ni_json_n, ni_user_l("Built at")}, + [NI_BUILT_TIMESTAMP] = {ni_json_k("build_time"), ni_user_n}, + [NI_BUILD_TOOL] = {ni_json_k("build_tool"), ni_user_l("Build tool")}, + [NI_BUILD_AUTHOR] = {ni_json_k("build_author"), ni_user_l("Build author")}, + + [NI_RX_QUEUES_ALL] = {ni_json_k("rx_queues"), ni_user_f("RX queues", NUF_N)}, + [NI_RX_QUEUES_EQ_AV] = {ni_json_k("rx_queues_available"), ni_user_f(NULL, NUF_DAV)}, + [NI_RX_QUEUES_NEQ_AV] = {ni_json_k("rx_queues_available"), ni_user_v(" (only", NUF_DA, NULL, "available)")}, + + [NI_TX_QUEUES_ALL] = {ni_json_k("tx_queues"), ni_user_f("TX queues", NUF_N)}, + [NI_TX_QUEUES_EQ_AV] = {ni_json_k("tx_queues_available"), ni_user_f(NULL, NUF_DAV)}, + [NI_TX_QUEUES_NEQ_AV] = {ni_json_k("tx_queues_available"), ni_user_v(" (only", NUF_DA, NULL, " available)")}, + + [NI_ETH_CHANNELS] = {ni_json_n, ni_user_l("ETH channels")}, + [NI_LIST_ETH_CHANNELS] = {ni_json_k("eth_channels"), ni_user_l(NULL)}, + [NI_SEC1_ETH_CHANNELS] = {ni_json_e, ni_user_l(NULL)}, + [NI_ETH_CHANNEL_ID] = {ni_json_k("id"), ni_user_f(" * Channel ", NUF_NDA)}, + [NI_ETH_CHANNEL_TYPE] = {ni_json_k("type"), ni_user_l("")}, + + [NI_SEC0_SYSTEM] = {ni_json_k("system"), ni_user_l("System info")}, + [NI_SEC1_PCIEP] = {ni_json_e, ni_user_l(NULL)}, + [NI_LIST_PCIEP] = {ni_json_k("pci"), ni_user_l(NULL)}, + [NI_PCI_ID] = {ni_json_k("id"), ni_user_v("PCIe Endpoint ", NUF_DA, NULL, ":")}, + [NI_PCI_SLOT] = {ni_json_k("pci_bdf"), ni_user_l(" * PCI slot")}, + [NI_PCI_LINK_SPEED] = {ni_json_k("pci_link_speed_str"), ni_user_l(" * PCI link speed")}, + [NI_PCI_LINK_WIDTH] = {ni_json_k("pci_link_width"), ni_user_v(" * PCI link width", 0, "x", NULL)}, + [NI_NUMA] = {ni_json_k("numa"), ni_user_l(" * NUMA node")}, + [NI_LIST_PCI_BAR] = {ni_json_k("bar"), ni_user_l(NULL)}, + [NI_SEC2_PCI_BAR] = {ni_json_e, ni_user_l(NULL)}, + [NI_BAR_ID] = {ni_json_k("id"), ni_user_v(" * MI BAR ", NUF_NDA, NULL, " size ")}, + [NI_BAR_SIZE_STR] = {ni_json_n, ni_user_f("", 0)}, + [NI_BAR_SIZE] = {ni_json_k("size"), ni_user_n}, + + /* Card list */ + [NI_LIST_NFB] = {ni_json_k("card_list"), + ni_user_v("ID Base path PCI address Card name Serial number Firmware info - project", 0, NULL, "\n")}, + [NI_SEC_LIST_NFB] = {ni_json_e, ni_user_v(NULL, 0, NULL, " ")}, + [NI_L_NFB_ID] = {ni_json_k("id"), ni_user_f("", NUF_NDA | NUFW(2))}, + [NI_L_LPATH] = {ni_json_k("path"), ni_user_v("", NUF_NDA | NUFA(-10), " ", NULL)}, + [NI_L_BFN] = {ni_json_k("pci_bdf"), ni_user_v("", NUF_NDA | NUFA(-12), " ", NULL)}, + [NI_L_CARD_NAME] = {ni_json_k("card_name"), ni_user_v("", NUF_NDA | NUFA(-16), " ", NULL)}, + [NI_L_SN] = {ni_json_k("serial_number"), ni_user_v("", NUF_NDA | NUFA(-14), " ", NULL)}, + [NI_L_PROJECT_NAME] = {ni_json_k("project_name"), ni_user_v("", NUF_NDA | NUFA(0), " ", NULL)}, + [NI_L_PROJECT_VAR] = {ni_json_k("project_variant"), ni_user_v("", NUF_NDA | NUFA(0), " ", NULL)}, + [NI_L_PROJECT_VER] = {ni_json_k("project_version"), ni_user_v("", NUF_NDA | NUFA(0), " ", NULL)}, + [NI_L_PROJECT_END] = {ni_json_n, ni_user_f("", NUF_DAV)}, +}; + void print_version() { #ifdef PACKAGE_VERSION @@ -113,7 +254,7 @@ void print_version() #endif } -void print_device_list() +void print_device_list(struct ni_context *ctx) { int ret; int len; @@ -124,7 +265,7 @@ void print_device_list() struct nc_composed_device_info info; struct nfb_device *dev; - char path[128]; + char path[NFB_PATH_MAXLEN]; char lpath[PATH_MAX]; const void *fdt; @@ -132,14 +273,10 @@ void print_device_list() const uint32_t *prop32; d = opendir(NFB_BASE_DEV_PATH "by-pci-slot/"); - if (d == NULL) - return; - - printf("ID Base path PCI address Card name Serial number Firmware info - project\n"); - - while ((dir = readdir(d)) != NULL) { + ni_list(ctx, NI_LIST_NFB); + while (d && (dir = readdir(d)) != NULL) { ret = snprintf(path, NFB_PATH_MAXLEN, NFB_BASE_DEV_PATH "by-pci-slot/%s", dir->d_name); - if (ret <= 0 || ret == NFB_PATH_MAXLEN) { + if (ret <= 0 || ret >= NFB_PATH_MAXLEN) { continue; } @@ -147,45 +284,43 @@ void print_device_list() dev = nfb_open(path); if (dev) { + ni_section(ctx, NI_SEC_LIST_NFB); + fdt = nfb_get_fdt(dev); fdt_offset = fdt_path_offset(fdt, "/firmware/"); ret = nc_get_composed_device_info_by_pci(dev, NULL, &info); - prop = fdt_getprop(fdt, fdt_offset, "card-name", &len); - printf("% 2d %-10s %s %-16s", - ret == 0 ? info.nfb_id : -1, - lpath, dir->d_name, len > 0 ? prop : ""); - + ni_item_int(ctx, NI_L_NFB_ID, ret == 0 ? info.nfb_id : -1); + ni_item_str(ctx, NI_L_LPATH, lpath); + ni_item_str(ctx, NI_L_BFN, dir->d_name); + ni_fdt_prop_str(ctx, NI_L_CARD_NAME, fdt, fdt_offset, "card-name", &len); fdt_offset = fdt_path_offset(fdt, "/board/"); - prop = fdt_getprop(fdt, fdt_offset, "serial-number-string", &len); - if (len > 0) { - printf(" %-16s", prop); + + prop = NULL; + prop32 = fdt_getprop(fdt, fdt_offset, "serial-number", &len); + if (len == sizeof(*prop32)) { + snprintf(path, NFB_PATH_MAXLEN, "%d", fdt32_to_cpu(*prop32)); + prop = path; } else { - prop32 = fdt_getprop(fdt, fdt_offset, "serial-number", &len); - if (len == sizeof(*prop32)) - printf(" %-16d", fdt32_to_cpu(*prop32)); - else - printf(" %16s", ""); + prop = fdt_getprop(fdt, fdt_offset, "serial-number-string", &len); } + if (prop) + ni_item_str(ctx, NI_L_SN, prop); fdt_offset = fdt_path_offset(fdt, "/firmware/"); - prop = fdt_getprop(fdt, fdt_offset, "project-name", &len); - if (len > 0) - printf("%s", prop); - prop = fdt_getprop(fdt, fdt_offset, "project-variant", &len); - if (len > 0) - printf(" %s", prop); - prop = fdt_getprop(fdt, fdt_offset, "project-version", &len); - if (len > 0) - printf(" %s", prop); - - printf("\n"); - + ni_fdt_prop_str(ctx, NI_L_PROJECT_NAME, fdt, fdt_offset, "project-name", &len); + ni_fdt_prop_str(ctx, NI_L_PROJECT_VAR, fdt, fdt_offset, "project-variant", &len); + ni_fdt_prop_str(ctx, NI_L_PROJECT_VER, fdt, fdt_offset, "project-version", &len); + ni_item_int(ctx, NI_L_PROJECT_END, 0); nfb_close(dev); + + ni_endsection(ctx, NI_SEC_LIST_NFB); } } + + ni_endlist(ctx, NI_LIST_NFB); } int print_specific_info(struct nfb_device *dev, int query) @@ -303,7 +438,7 @@ const char *pci_speed_string(enum pci_bus_speed speed) "Unknown speed"; } -void print_size(unsigned long size) +void sprint_size(char *str, unsigned long size) { static const char *units[] = { "B", "KiB", "MiB", "GiB"}; @@ -312,16 +447,15 @@ void print_size(unsigned long size) size >>= 10; i++; } - printf("%lu %s", size, units[i]); + sprintf(str, "%lu %s", size, units[i]); } -void print_endpoint_info(struct nfb_device *dev, int fdt_offset) +void print_endpoint_info(struct nfb_device *dev, int fdt_offset, struct ni_context *ctx) { int len; int bar; int dev_id = -1; uint64_t bar_size; - const void *prop; const uint32_t *prop32; const uint64_t *prop64; const void *fdt; @@ -335,41 +469,39 @@ void print_endpoint_info(struct nfb_device *dev, int fdt_offset) dev_id = strtoul(node_name+8, NULL, 10); } - printf("PCIe Endpoint %d:\n", dev_id); - - prop = fdt_getprop(fdt, fdt_offset, "pci-slot", &len); - if (prop) - printf(" * PCI slot : %s\n", (const char*)prop); + ni_item_int(ctx, NI_PCI_ID, dev_id); + ni_fdt_prop_str(ctx, NI_PCI_SLOT, fdt, fdt_offset, "pci-slot", &len); prop32 = fdt_getprop(fdt, fdt_offset, "pci-speed", &len); if (prop32) - printf(" * PCI speed : %s\n", pci_speed_string(fdt32_to_cpu(*prop32))); - - prop32 = fdt_getprop(fdt, fdt_offset, "pcie-link-width", &len); - if (prop32) - printf(" * PCI link width : x%d\n", fdt32_to_cpu(*prop32)); - - prop32 = fdt_getprop(fdt, fdt_offset, "numa-node", &len); - if (len == sizeof(*prop32)) - printf(" * NUMA node : %i\n", fdt32_to_cpu(*prop32)); + ni_item_str(ctx, NI_PCI_LINK_SPEED, pci_speed_string(fdt32_to_cpu(*prop32))); + ni_fdt_prop_32(ctx, NI_PCI_LINK_WIDTH, fdt, fdt_offset, "pcie-link-width"); + ni_fdt_prop_32(ctx, NI_NUMA, fdt, fdt_offset, "numa-node"); + ni_list(ctx, NI_LIST_PCI_BAR); for (bar = 0; bar < 6; bar++) { snprintf(nodename, sizeof(nodename), "/drivers/mi/PCI%d,BAR%d", dev_id, bar); fdt_offset = fdt_path_offset(fdt, nodename); if (fdt_offset >= 0) { + ni_section(ctx, NI_SEC2_PCI_BAR); + prop64 = fdt_getprop(fdt, fdt_offset, "mmap_size", &len); if (len != sizeof(*prop64)) continue; bar_size = fdt64_to_cpu(*prop64); - printf(" * MI BAR %d size : %s", bar, bar_size == 0 ? "unmapped!" : ""); + ni_item_int(ctx, NI_BAR_ID, bar); if (bar_size) - print_size(bar_size); - printf("\n"); + sprint_size(nodename, bar_size); + ni_item_str(ctx, NI_BAR_SIZE_STR, (bar_size == 0 ? "unmapped!" : nodename)); + ni_item_int(ctx, NI_BAR_SIZE, bar_size); + + ni_endsection(ctx, NI_SEC2_PCI_BAR); } } + ni_endlist(ctx, NI_LIST_PCI_BAR); } -void print_common_info(struct nfb_device *dev, int verbose) +void print_common_info(struct nfb_device *dev, int verbose, struct ni_context *ctx) { int i; int len; @@ -379,121 +511,124 @@ void print_common_info(struct nfb_device *dev, int verbose) int32_t val = 0; const void *prop; const uint32_t *prop32; - const uint64_t *prop64; const void *fdt; char buffer[BUFFER_SIZE]; time_t build_time; fdt = nfb_get_fdt(dev); - printf("--------------------------------------- Board info ----\n"); + + ni_section(ctx, NI_SEC0_BOARD_INFO); fdt_offset = fdt_path_offset(fdt, "/board/"); - prop = fdt_getprop(fdt, fdt_offset, "board-name", &len); - if (len > 0) - printf("Board name : %s\n", (const char *)prop); - prop = fdt_getprop(fdt, fdt_offset, "serial-number-string", &len); - if (len > 0) { - printf("Serial number : %s\n", (const char *)prop); + ni_fdt_prop_str(ctx, NI_BOARD_NAME, fdt, fdt_offset, "board-name", &len); + + prop = NULL; + prop32 = fdt_getprop(fdt, fdt_offset, "serial-number", &len); + if (len == sizeof(*prop32)) { + snprintf(buffer, BUFFER_SIZE, "%d", fdt32_to_cpu(*prop32)); + prop = buffer; } else { - prop32 = fdt_getprop(fdt, fdt_offset, "serial-number", &len); - if (len == sizeof(*prop32)) - printf("Serial number : %d\n", fdt32_to_cpu(*prop32)); + prop = fdt_getprop(fdt, fdt_offset, "serial-number-string", &len); } + if (prop) + ni_item_str(ctx, NI_SERIAL_NUMBER, prop); + - prop64 = fdt_getprop(fdt, fdt_offset, "fpga-uid", &len); - if (verbose > 1 && len == sizeof(*prop64)) - printf("FPGA unique ID : 0x%" PRIx64 "\n", fdt64_to_cpu(*prop64)); + if (verbose > 1) + ni_fdt_prop_uint64_tx(ctx, NI_FPGA_UNIQUE_ID, fdt, fdt_offset, "fpga-uid"); i = 0; fdt_for_each_compatible_node(fdt, node, "netcope,transceiver") { i++; } - printf("Network interfaces : %d\n", i); + ni_item_int(ctx, NI_NET_IFCS, i); + if (verbose) { + ni_list(ctx, NI_LIST_NET_IFCS); i = 0; fdt_for_each_compatible_node(fdt, node, "netcope,transceiver") { + ni_section(ctx, NI_SEC1_NET_IFCS); prop = fdt_getprop(fdt, node, "type", &len); - printf(" * Interface %d : %s\n", i, - len > 0 ? (const char *) prop : "Unknown"); + ni_item_int(ctx, NI_IFC_ID, i); + ni_item_str(ctx, NI_IFC_TYPE, len > 0 ? (const char *) prop : "Unknown"); i++; + ni_endsection(ctx, NI_SEC1_NET_IFCS); } + ni_endlist(ctx, NI_LIST_NET_IFCS); } if (verbose) { nc_adc_sensors_get_temp(dev, &val); - printf("Temperature : %.1f C\n", val / 1000.0f); + ni_item_double(ctx, NI_TEMPERATURE, val / 1000.0f); } - printf("------------------------------------ Firmware info ----\n"); + ni_endsection(ctx, NI_SEC0_BOARD_INFO); - fdt_offset = fdt_path_offset(fdt, "/firmware/"); + ni_section(ctx, NI_SEC0_FIRMWARE); - prop = fdt_getprop(fdt, fdt_offset, "card-name", &len); - if (len > 0) - printf("Card name : %s\n", (const char *)prop); - - prop = fdt_getprop(fdt, fdt_offset, "project-name", &len); - if (len > 0) - printf("Project name : %s\n", (const char *)prop); - - prop = fdt_getprop(fdt, fdt_offset, "project-variant", &len); - if (len > 0) - printf("Project variant : %s\n", (const char *)prop); + fdt_offset = fdt_path_offset(fdt, "/firmware/"); - prop = fdt_getprop(fdt, fdt_offset, "project-version", &len); - if (len > 0) - printf("Project version : %s\n", (const char *)prop); + ni_fdt_prop_str(ctx, NI_CARD_NAME, fdt, fdt_offset, "card-name", &len); + ni_fdt_prop_str(ctx, NI_PROJECT_NAME, fdt, fdt_offset, "project-name", &len); + ni_fdt_prop_str(ctx, NI_PROJECT_VARIANT, fdt, fdt_offset, "project-variant", &len); + ni_fdt_prop_str(ctx, NI_PROJECT_VERSION, fdt, fdt_offset, "project-version", &len); prop32 = fdt_getprop(fdt, fdt_offset, "build-time", &len); if (len == sizeof(*prop32)) { build_time = fdt32_to_cpu(*prop32); strftime(buffer, BUFFER_SIZE, "%Y-%m-%d %H:%M:%S", localtime(&build_time)); - printf("Built at : %s\n", buffer); + ni_item_str(ctx, NI_BUILT_TIME, buffer); + ni_item_int(ctx, NI_BUILT_TIMESTAMP, build_time); } - prop = fdt_getprop(fdt, fdt_offset, "build-tool", &len); - if (len > 0) - printf("Build tool : %s\n", (const char *)prop); - - prop = fdt_getprop(fdt, fdt_offset, "build-author", &len); - if (len > 0) - printf("Build author : %s\n", (const char *)prop); + ni_fdt_prop_str(ctx, NI_BUILD_TOOL, fdt, fdt_offset, "build-tool", &len); + ni_fdt_prop_str(ctx, NI_BUILD_AUTHOR, fdt, fdt_offset, "build-author", &len); count1 = ndp_get_rx_queue_count(dev); count2 = ndp_get_rx_queue_available_count(dev); - if (count1 != count2) - printf("RX queues : %d (only %d available)\n", count1, count2); - else - printf("RX queues : %d\n", count1); + + ni_item_int(ctx, NI_RX_QUEUES_ALL, count1); + ni_item_int(ctx, count1 == count2 ? NI_RX_QUEUES_EQ_AV: NI_RX_QUEUES_NEQ_AV, count2); count1 = ndp_get_tx_queue_count(dev); count2 = ndp_get_tx_queue_available_count(dev); - if (count1 != count2) - printf("TX queues : %d (only %d available)\n", count1, count2); - else - printf("TX queues : %d\n", count1); - printf("ETH channels : %d\n", nc_eth_get_count(dev)); + ni_item_int(ctx, NI_TX_QUEUES_ALL, count1); + ni_item_int(ctx, count1 == count2 ? NI_TX_QUEUES_EQ_AV: NI_TX_QUEUES_NEQ_AV, count2); + + ni_item_int(ctx, NI_ETH_CHANNELS, nc_eth_get_count(dev)); if (verbose) { i = 0; + ni_list(ctx, NI_LIST_ETH_CHANNELS); fdt_for_each_compatible_node(fdt, node, COMP_NETCOPE_ETH) { + ni_section(ctx, NI_SEC1_ETH_CHANNELS); fdt_offset = fdt_node_offset_by_phandle_ref(fdt, node, "pcspma"); prop = fdt_getprop(fdt, fdt_offset, "type", &len); - printf(" * Channel %d : %s\n", i, - len > 0 ? (const char *) prop : "Unknown"); + ni_item_int(ctx, NI_ETH_CHANNEL_ID, i); + ni_item_str(ctx, NI_ETH_CHANNEL_TYPE, len > 0 ? (const char *) prop : "Unknown"); i++; + + ni_endsection(ctx, NI_SEC1_ETH_CHANNELS); } + ni_endlist(ctx, NI_LIST_ETH_CHANNELS); } + ni_endsection(ctx, NI_SEC0_FIRMWARE); - printf("-------------------------------------- System info ----\n"); + ni_section(ctx, NI_SEC0_SYSTEM); fdt_offset = fdt_path_offset(fdt, "/system/device/"); + ni_list(ctx, NI_LIST_PCIEP); fdt_for_each_subnode(node, fdt, fdt_offset) { - print_endpoint_info(dev, node); + ni_section(ctx, NI_SEC1_PCIEP); + print_endpoint_info(dev, node, ctx); + ni_endsection(ctx, NI_SEC1_PCIEP); } + ni_endlist(ctx, NI_LIST_PCIEP); + + ni_endsection(ctx, NI_SEC0_SYSTEM); } int main(int argc, char *argv[]) @@ -506,6 +641,7 @@ int main(int argc, char *argv[]) const char *query = NULL; char *index; int size; + int js = NI_DRC_USER; enum commands command = CMD_PRINT_STATUS; int verbose = 0; @@ -527,6 +663,9 @@ int main(int argc, char *argv[]) case 'q': query = optarg; break; + case 'j': + js = NI_DRC_JSON; + break; case 'V': command = CMD_VERSION; break; @@ -542,7 +681,10 @@ int main(int argc, char *argv[]) print_version(); return 0; } else if (command == CMD_LIST) { - print_device_list(); + struct ni_context *ctx; + ctx = ni_init_root_context_default(js, ni_items, &ni_common_item_callbacks[js]); + print_device_list(ctx); + ni_close_root_context(ctx); return 0; } @@ -573,7 +715,13 @@ int main(int argc, char *argv[]) } free(index); } else { - print_common_info(dev, verbose); + struct ni_context *ctx; + ctx = ni_init_root_context_default(js, ni_items, &ni_common_item_callbacks[js]); + + ni_section(ctx, NI_SEC_ROOT); + print_common_info(dev, verbose, ctx); + ni_endsection(ctx, NI_SEC_ROOT); + ni_close_root_context(ctx); } nfb_close(dev); From bebbd1eb14500d5c3a94dbb05af74d5c2b41e21b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 30 Apr 2025 15:08:04 +0200 Subject: [PATCH 360/518] feat(nfb-dma): use NI (normalized item) library for output --- tools/dma/dma.c | 469 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 361 insertions(+), 108 deletions(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 0b879939..d26433b9 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,8 @@ #include #include +#include + /*! Program version */ #define VERSION "1.0: dmactl.c" @@ -30,7 +33,9 @@ /*! -d path to device file */ /*! -B buffer size */ /*! -C buffer count */ +/*! -N netdev command */ /*! -i RX or TX index */ +/*! -j JSON output */ /*! -r use only RX; */ /*! -t use only TX; */ /*! -R reset counters */ @@ -40,7 +45,8 @@ /*! -v verbose mode; */ /*! -V version */ -#define ARGUMENTS "d:i:q:rtRS:B:C:N:O:Tvh" + +#define ARGUMENTS "d:i:q:rtRS:B:C:N:O:Tjvh" enum commands { CMD_PRINT_STATUS, @@ -88,6 +94,227 @@ static const char * const queries[] = { "tx_discarded_bytes" }; +enum NI_ITEMS { + NI_SEC_ROOT = 0, + NI_LIST_ALL, + + NI_LIST_RXQ, + NI_SEC_RXQ, + NI_LIST_TXQ, + NI_SEC_TXQ, + + NI_CTRL_INDEX, + NI_CTRL_NAME, + NI_CTRL_REG_CTL, + NI_CTRL_REG_CTL_R, + NI_CTRL_REG_CTL_RN, + NI_CTRL_REG_CTL_D_RX, + NI_CTRL_REG_CTL_E, + NI_CTRL_REG_CTL_V, + NI_CTRL_REG_STA, + NI_CTRL_REG_STA_R, + NI_CTRL_REG_STA_RN, + NI_CTRL_REG_STA_DE, + NI_CTRL_REG_STA_DA, + NI_CTRL_REG_STA_RI, + + NI_CTRL_REG_SHP, + NI_CTRL_REG_HHP, + NI_CTRL_REG_MHP, + NI_CTRL_REG_SDP, + NI_CTRL_REG_HDP, + NI_CTRL_REG_MDP, + NI_CTRL_REG_SP, + NI_CTRL_REG_HP, + NI_CTRL_REG_MP, + NI_CTRL_HBS, + NI_CTRL_FB, + NI_CTRL_DBS, + NI_CTRL_BS, + NI_CTRL_FD, + + NI_CTRL_REG_TO, + NI_CTRL_REG_MR, + NI_CTRL_MR, + + NI_CTRL_REG_RECV, + NI_CTRL_REG_RECV_B, + NI_CTRL_REG_DISC, + NI_CTRL_REG_DISC_B, + NI_CTRL_REG_SENT, + NI_CTRL_REG_SENT_B, + + NI_CTRL_REG_DESC_B, + NI_CTRL_REG_HDR_B, + NI_CTRL_REG_PTR_B, + + NI_SEC_RXSUM, + NI_SEC_TXSUM, +}; + +#define NUF_N (NI_USER_ITEM_F_NO_NEWLINE) +#define NUF_NDA (NI_USER_ITEM_F_NO_NEWLINE | NI_USER_ITEM_F_NO_DELIMITER | NI_USER_ITEM_F_NO_ALIGN) +#define NUF_DA (NI_USER_ITEM_F_NO_DELIMITER | NI_USER_ITEM_F_NO_ALIGN) +#define NUF_DAV (NI_USER_ITEM_F_NO_DELIMITER | NI_USER_ITEM_F_NO_ALIGN | NI_USER_ITEM_F_NO_VALUE) +#define NUF_SL (NI_USER_ITEM_F_SEC_LABEL) +#define NUFW(x) ni_user_f_width(x) + + +struct ni_context_item_default ni_items[] = { + [NI_SEC_ROOT] = {ni_json_e, ni_user_n}, + + [NI_LIST_ALL] = {ni_json_n, ni_user_v(NULL, 0, "\n", NULL)}, + [NI_LIST_RXQ] = {ni_json_k("rxq"), ni_user_f(NULL, NI_USER_LIST_F_NO_LABEL)}, + [NI_SEC_RXQ] = {ni_json_e, ni_user_l("RX")}, + [NI_CTRL_INDEX] = {ni_json_k("id"), ni_user_f(" ", NUF_NDA | NUF_SL)}, + [NI_CTRL_NAME] = {ni_json_k("type"), ni_user_v(" ", NUF_NDA | NUF_SL, NULL, " controller")}, + [NI_CTRL_REG_CTL] = {ni_json_k("reg_control"), ni_user_f("Control reg", NUF_N | NUFW(8))}, + [NI_CTRL_REG_CTL_R] = {ni_json_k("run"), ni_user_v(NULL, NUF_DA | NUFW(-8), " | ", " |")}, + [NI_CTRL_REG_CTL_RN] = {ni_json_k("run"), ni_user_v(NULL, NUF_NDA | NUFW(-8), " | ", NULL)}, + [NI_CTRL_REG_CTL_D_RX] = {ni_json_k("discard"), ni_user_v(NULL, NUF_NDA | NUFW(-8), " | ", NULL)}, + [NI_CTRL_REG_CTL_E] = {ni_json_k("pciep_mask"), ni_user_v(NULL, NUF_NDA | NUFW(2), " | EpMsk ", NULL)}, + [NI_CTRL_REG_CTL_V] = {ni_json_k("vfid"), ni_user_v(NULL, NUF_DA | NUFW(2), " | VFID ", " |")}, + [NI_CTRL_REG_STA] = {ni_json_k("reg_status"), ni_user_f("Status reg", NUF_N | NUFW(8))}, + [NI_CTRL_REG_STA_R] = {ni_json_k("running"), ni_user_v(NULL, NUF_DA | NUFW(-8), " | ", " |")}, + [NI_CTRL_REG_STA_RN] = {ni_json_k("running"), ni_user_v(NULL, NUF_NDA | NUFW(-8), " | ", NULL)}, + [NI_CTRL_REG_STA_DE] = {ni_json_k("desc_rdy"), ni_user_v(NULL, NUF_NDA | NUFW(-8), " | ", NULL)}, + [NI_CTRL_REG_STA_DA] = {ni_json_k("data_rdy"), ni_user_v(NULL, NUF_NDA | NUFW(-8), " | ", NULL)}, + [NI_CTRL_REG_STA_RI] = {ni_json_k("ring_rdy"), ni_user_v(NULL, NUF_DA | NUFW(-8), " | ", " |")}, + + [NI_CTRL_REG_SHP] = {ni_json_k("shp"), ni_user_f("SW header pointer", NUFW(8))}, + [NI_CTRL_REG_HHP] = {ni_json_k("hhp"), ni_user_f("HW header pointer", NUFW(8))}, + [NI_CTRL_REG_MHP] = {ni_json_k("mhp"), ni_user_f("Header pointer mask", NUFW(8))}, + [NI_CTRL_HBS] = {ni_json_k("hdr_buffer_size"), ni_user_f("* Header buffer size", NUFW(-8))}, + [NI_CTRL_FB] = {ni_json_k("hdr_buffer_free"), ni_user_f("* Fillable headers in HW", NUFW(8))}, + [NI_CTRL_REG_SDP] = {ni_json_k("sdp"), ni_user_f("SW descriptor pointer", NUFW(8))}, + [NI_CTRL_REG_HDP] = {ni_json_k("hdp"), ni_user_f("HW descriptor pointer", NUFW(8))}, + [NI_CTRL_REG_MDP] = {ni_json_k("mdp"), ni_user_f("Descriptor pointer mask", NUFW(8))}, + [NI_CTRL_DBS] = {ni_json_k("desc_buffer_size"), ni_user_f("* Descriptor buffer size", NUFW(8))}, + [NI_CTRL_FD] = {ni_json_k("desc_free"), ni_user_f("* Usable descriptors in HW", NUFW(8))}, + + [NI_CTRL_REG_SP] = {ni_json_k("sw_ptr"), ni_user_f("SW pointer", NUFW(8))}, + [NI_CTRL_REG_HP] = {ni_json_k("hw_ptr"), ni_user_f("HW pointer", NUFW(8))}, + [NI_CTRL_REG_MP] = {ni_json_k("ptr_mask"), ni_user_f("Pointer mask", NUFW(8))}, + [NI_CTRL_BS] = {ni_json_k("buffer_size"), ni_user_l("* Buffer size")}, + [NI_CTRL_REG_TO] = {ni_json_k("timeout"), ni_user_f("Timeout reg", NUFW(8))}, + [NI_CTRL_REG_MR] = {ni_json_k("max_request_size"), ni_user_f("Max request", NUF_N | NUFW(8))}, + [NI_CTRL_MR] = {ni_json_n, ni_user_v("", NUF_DA | NUFW(-8), " | ", NULL)}, + + [NI_CTRL_REG_RECV] = {ni_json_k("pass"), ni_user_l("Received")}, + [NI_CTRL_REG_RECV_B] = {ni_json_k("pass_bytes"), ni_user_l("Received bytes")}, + [NI_CTRL_REG_DISC] = {ni_json_k("drop"), ni_user_l("Discarded")}, + [NI_CTRL_REG_DISC_B] = {ni_json_k("drop_bytes"), ni_user_l("Discarded bytes")}, + [NI_CTRL_REG_SENT] = {ni_json_k("pass"), ni_user_l("Sent")}, + [NI_CTRL_REG_SENT_B] = {ni_json_k("pass_bytes"), ni_user_l("Sent bytes")}, + + [NI_CTRL_REG_DESC_B] = {ni_json_k("descriptor_base"), ni_user_f("Desc base", NUFW(16))}, + [NI_CTRL_REG_HDR_B] = {ni_json_k("hdr_base"), ni_user_f("Header base", NUFW(16))}, + [NI_CTRL_REG_PTR_B] = {ni_json_k("ptr_base"), ni_user_f("Pointer base", NUFW(16))}, + + [NI_LIST_TXQ] = {ni_json_k("txq"), ni_user_f(NULL, NI_USER_LIST_F_NO_LABEL)}, + [NI_SEC_TXQ] = {ni_json_e, ni_user_l("TX")}, + + [NI_SEC_RXSUM] = {ni_json_k("rxq_sum"), ni_user_l("RX SUM")}, + [NI_SEC_TXSUM] = {ni_json_k("txq_sum"), ni_user_l("TX SUM")}, +}; + +int fprint_size(FILE * f, unsigned long size); + +int fprint_size_user(void *priv, int item, unsigned long size) +{ + struct ni_user_cbp *p = priv; + (void) item; + return fprint_size(p->f, size); +} + +int fprint_size_json(void *priv, int item, unsigned long size) +{ + struct ni_json_cbp *p = priv; + (void) item; + return fprintf(p->f, "%lu", size); +} + +int print_ctrl_reg_user(void *priv, int item, int val) +{ + struct ni_user_cbp *p = priv; + const char *res = NULL; + + switch (item) { + case NI_CTRL_REG_CTL_RN: + case NI_CTRL_REG_CTL_R: res = val ? "Run" : "Stop"; break; + + case NI_CTRL_REG_STA_RN: + case NI_CTRL_REG_STA_R: res = val ? "Running" : "Stopped"; break; + + case NI_CTRL_REG_STA_DE: res = val ? "Desc RDY" : "Desc -"; break; + case NI_CTRL_REG_STA_DA: res = val ? "Data RDY" : "Data -"; break; + case NI_CTRL_REG_STA_RI: res = val ? "SW RDY" : "SW full"; break; + case NI_CTRL_REG_CTL_D_RX: res = val ? "Discard" : "Block"; break; + } + + if (res) + return fprintf(p->f, "%*s", p->width, res); + return 0; +} + +int print_ctrl_reg_json(void *priv, int item, int val) +{ + struct ni_user_cbp *p = priv; + (void) item; + return fprintf(p->f, val ? "true": "false"); +} + +static int print_xreg_user(void *priv, int item, uint64_t val) +{ + struct ni_user_cbp *p = priv; + int ret = 0; + (void) item; + + ret += fprintf(p->f, "%0*" PRIX64, p->width, val); + + if (p->align > ret) + ret += fprintf(p->f, "%*s", p->align - ret, ""); + return ret; +} + +static int print_xreg_json(void *priv, int item, uint64_t val) +{ + struct ni_json_cbp *p = priv; + (void) item; + return fprintf(p->f, "%lu", val); +} + +struct ni_dma_item_f_t { + struct ni_common_item_callbacks c; + int (*print_size)(void *, int, unsigned long); + int (*print_xreg)(void *, int, uint64_t); + int (*print_ctrl_reg)(void *, int, int); +}; + +struct ni_dma_item_f_t ni_dma_item_f[] = { + [NI_DRC_USER] = { + .c = ni_common_item_callbacks[NI_DRC_USER], + .print_size = fprint_size_user, + .print_xreg = print_xreg_user, + .print_ctrl_reg = print_ctrl_reg_user, + }, + [NI_DRC_JSON] = { + .c = ni_common_item_callbacks[NI_DRC_JSON], + .print_size = fprint_size_json, + .print_xreg = print_xreg_json, + .print_ctrl_reg = print_ctrl_reg_json, + }, +}; + +NI_DEFAULT_ITEMS(ni_dma_item_f_t, c.) + +#define NI_DMA_ITEM(name, type, cbcall) NI_ITEM_CB(name, type, ni_dma_item_f_t, cbcall) + +NI_DMA_ITEM(str_size, long long, print_size) +NI_DMA_ITEM(ctrl_reg, int, print_ctrl_reg) +NI_DMA_ITEM(xreg, uint64_t, print_xreg) + + /*! * \brief Display usage of program */ @@ -114,6 +341,7 @@ void usage(const char *me, int verbose) printf(" example of usage: '-q rx_received,tx_sent'\n"); } printf("-N netdev_drv Perform a netdev command (add,del) on the selected indexes\n"); + printf("-j Print output in JSON\n"); printf("-v Increase verbosity\n"); printf("-h Show this text\n"); printf("\nExamples:\n"); @@ -186,7 +414,7 @@ int cmd_ndp_netdev(struct nfb_device *dev, const char *ndd, const char *cmd, str * * \param size size of buffer */ -void print_size(unsigned long size) +int fprint_size(FILE * f, unsigned long size) { static const char *units[] = { "B", "KiB", "MiB", "GiB"}; @@ -195,7 +423,12 @@ void print_size(unsigned long size) size >>= 10; i++; } - printf("%lu %s", size, units[i]); + return fprintf(f, "%lu %s", size, units[i]); +} + +int print_size(unsigned long size) +{ + return fprint_size(stdout, size); } /*! @@ -325,79 +558,78 @@ void rxqueue_get_status(struct nc_rxqueue *q, struct nc_rxqueue_status *s, struc * * \param *tx_dma structure from which are data read */ -void rxqueue_print_status(struct nc_rxqueue *q, int index, int verbose, struct nc_rxqueue_status *s, struct nc_rxqueue_counters *c) +void rxqueue_print_status(struct ni_context *ctx, struct nc_rxqueue *q, int index, int verbose, struct nc_rxqueue_status *s, struct nc_rxqueue_counters *c) { - printf("------------------------------ RX%02d %s controller ----\n", index, q->name); + ni_item_int(ctx, NI_CTRL_INDEX, index); + ni_item_str(ctx, NI_CTRL_NAME, q->name); if (s && verbose > 0) { - printf("Control reg : 0x%.8X", s->_ctrl_raw); + ni_item_uint64_tx(ctx, NI_CTRL_REG_CTL, s->_ctrl_raw); + if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { - printf(" | %s |", - s->ctrl_running ? "Run " : "Stop "); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_CTL_R, s->ctrl_running); } else if (q->type == QUEUE_TYPE_SZE) { - printf(" | %s | %s | EpMsk %.2X | VFID %.2X |", - s->ctrl_running ? "Run " : "Stop ", - s->ctrl_discard ? "Discard " : "Block ", - (s->_ctrl_raw >> 16) & 0xFF, - (s->_ctrl_raw >> 24) & 0xFF); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_CTL_RN, s->ctrl_running); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_CTL_D_RX, s->ctrl_discard); + ni_item_xreg(ctx, NI_CTRL_REG_CTL_E, (s->_ctrl_raw >> 16) & 0xFF); + ni_item_xreg(ctx, NI_CTRL_REG_CTL_V, (s->_ctrl_raw >> 24) & 0xFF); } - printf("\n"); - printf("Status reg : 0x%.8X", s->_stat_raw); + ni_item_uint64_tx(ctx, NI_CTRL_REG_STA, s->_stat_raw); + if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { - printf(" | %s |", - s->stat_running ? "Running " : "Stopped "); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_STA_R, s->stat_running); } else if (q->type == QUEUE_TYPE_SZE) { - printf(" | %s | %s | %s | %s |", - s->stat_running ? "Running " : "Stopped ", - s->stat_desc_rdy ? "Desc RDY" : "Desc - ", - s->stat_data_rdy ? "Data RDY" : "Data - ", - s->stat_ring_rdy ? "SW RDY " : "SW Full "); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_STA_RN, s->stat_running); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_STA_DE, s->stat_desc_rdy); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_STA_DA, s->stat_data_rdy); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_STA_RI, s->stat_ring_rdy); } - printf("\n"); if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { - printf("SW header pointer : 0x%08lX\n", s->sw_pointer); - printf("HW header pointer : 0x%08lX\n", s->hw_pointer); - printf("Header pointer mask : 0x%08lX\n", s->pointer_mask); - printf("* Header buffer size : "); print_size(s->pointer_mask ? s->pointer_mask + 1 : 0); printf("\n"); - printf("* Fillable headers in HW : 0x%08lX\n", (s->sw_pointer - s->hw_pointer - 1) & s->pointer_mask); - - printf("SW descriptor pointer : 0x%08lX\n", s->sd_pointer); - printf("HW descriptor pointer : 0x%08lX\n", s->hd_pointer); - printf("Descriptor pointer mask : 0x%08lX\n", s->desc_pointer_mask); - printf("* Descriptor buffer size : "); print_size(s->desc_pointer_mask ? s->desc_pointer_mask + 1 : 0); printf("\n"); - printf("* Usable descriptors in HW : 0x%08lX\n", (s->sd_pointer - s->hd_pointer) & s->desc_pointer_mask); + ni_item_uint64_tx(ctx, NI_CTRL_REG_SHP, s->sw_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_HHP, s->hw_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_MHP, s->pointer_mask); + + ni_item_str_size(ctx, NI_CTRL_HBS, (s->pointer_mask ? s->pointer_mask + 1 : 0)); + ni_item_uint64_tx(ctx, NI_CTRL_FB, (s->sw_pointer - s->hw_pointer - 1) & s->pointer_mask); + + ni_item_uint64_tx(ctx, NI_CTRL_REG_SDP, s->sd_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_HDP, s->hd_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_MDP, s->desc_pointer_mask); + + ni_item_str_size(ctx, NI_CTRL_DBS, s->desc_pointer_mask ? s->desc_pointer_mask + 1 : 0); + ni_item_uint64_tx(ctx, NI_CTRL_FD, (s->sd_pointer - s->hd_pointer) & s->desc_pointer_mask); } else { - printf("SW pointer : 0x%08lX\n", s->sw_pointer); - printf("HW pointer : 0x%08lX\n", s->hw_pointer); - printf("Pointer mask : 0x%08lX\n", s->pointer_mask); - printf("* Buffer size : "); print_size(s->pointer_mask ? s->pointer_mask + 1 : 0); printf("\n"); + ni_item_uint64_tx(ctx, NI_CTRL_REG_SP, s->sw_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_HP, s->hw_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_MP, s->pointer_mask); + ni_item_str_size(ctx, NI_CTRL_BS, s->pointer_mask ? s->pointer_mask + 1 : 0); } if (q->type == QUEUE_TYPE_SZE || q->type == QUEUE_TYPE_NDP) - printf("Timeout reg : 0x%08lX\n", s->timeout); + ni_item_uint64_tx(ctx, NI_CTRL_REG_TO, s->timeout); if (q->type == QUEUE_TYPE_SZE) { - printf("Max request : 0x%04lX | ", s->max_request); - print_size(s->max_request); printf("\n"); + ni_item_uint64_tx(ctx, NI_CTRL_REG_MR, s->max_request); + ni_item_str_size(ctx, NI_CTRL_MR, s->max_request); } } if (c) { - printf("Received : %llu\n", c->received); + ni_item_uint64_t(ctx, NI_CTRL_REG_RECV, c->received); if (c->have_bytes) - printf("Received bytes : %llu\n", c->received_bytes); - printf("Discarded : %llu\n", c->discarded); + ni_item_uint64_t(ctx, NI_CTRL_REG_RECV_B, c->received_bytes); + ni_item_uint64_t(ctx, NI_CTRL_REG_DISC, c->discarded); if (c->have_bytes) - printf("Discarded bytes : %llu\n", c->discarded_bytes); + ni_item_uint64_t(ctx, NI_CTRL_REG_DISC_B, c->discarded_bytes); } if (s && verbose > 1) { - printf("Desc base : 0x%.16llX\n", s->desc_base); + ni_item_uint64_tx(ctx, NI_CTRL_REG_DESC_B, s->desc_base); if (q->type == QUEUE_TYPE_CALYPTE) - printf("Header base : 0x%.16llX\n", s->hdr_base); + ni_item_uint64_tx(ctx, NI_CTRL_REG_HDR_B, s->hdr_base); else - printf("Pointer base : 0x%.16llX\n", s->pointer_base); + ni_item_uint64_tx(ctx, NI_CTRL_REG_PTR_B, s->pointer_base); } } @@ -420,79 +652,70 @@ void txqueue_get_status(struct nc_txqueue *q, struct nc_txqueue_status *s, struc } } -void txqueue_print_status(struct nc_txqueue *q, int index, int verbose, struct nc_txqueue_status *s, struct nc_txqueue_counters *c) +void txqueue_print_status(struct ni_context *ctx, struct nc_txqueue *q, int index, int verbose, struct nc_txqueue_status *s, struct nc_txqueue_counters *c) { - printf("------------------------------ TX%02d %s controller ----\n", index, q->name); + ni_item_int(ctx, NI_CTRL_INDEX, index); + ni_item_str(ctx, NI_CTRL_NAME, q->name); if (s && verbose > 0) { - printf("Control reg : 0x%.8X", s->_ctrl_raw); + ni_item_uint64_tx(ctx, NI_CTRL_REG_CTL, s->_ctrl_raw); if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { - printf(" | %s |", - s->ctrl_running ? "Run " : "Stop "); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_CTL_R, s->ctrl_running); } else if (q->type == QUEUE_TYPE_SZE) { - printf(" | %s | EpMsk %.2X | VFID %.2X |", - s->ctrl_running ? "Run " : "Stop ", - (s->_ctrl_raw >> 16) & 0xFF, - (s->_ctrl_raw >> 24) & 0xFF); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_CTL_RN, s->ctrl_running); + ni_item_xreg(ctx, NI_CTRL_REG_CTL_E, (s->_ctrl_raw >> 16) & 0xFF); + ni_item_xreg(ctx, NI_CTRL_REG_CTL_V, (s->_ctrl_raw >> 24) & 0xFF); } - printf("\n"); - printf("Status reg : 0x%.8X", s->_stat_raw); - if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { - printf(" | %s |", - s->stat_running ? "Running " : "Stopped "); - } else if (q->type == QUEUE_TYPE_SZE) { - printf(" | %s |", - s->stat_running ? "Running " : "Stopped "); - } - printf("\n"); + ni_item_uint64_tx(ctx, NI_CTRL_REG_STA, s->_stat_raw); + ni_item_ctrl_reg(ctx, NI_CTRL_REG_STA_R, s->stat_running); if (q->type == QUEUE_TYPE_NDP || q->type == QUEUE_TYPE_CALYPTE) { if (q->type == QUEUE_TYPE_CALYPTE) { - printf("SW header pointer : 0x%08lX\n", s->sw_pointer); - printf("HW header pointer : 0x%08lX\n", s->hw_pointer); - printf("Header pointer mask : 0x%08lX\n", s->pointer_mask); - printf("* Header buffer size : "); print_size(s->pointer_mask ? s->pointer_mask + 1 : 0); printf("\n"); - printf("* Fillable headers in HW : 0x%08lX\n", (s->sw_pointer - s->hw_pointer - 1) & s->pointer_mask); + ni_item_uint64_tx(ctx, NI_CTRL_REG_SHP, s->sw_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_HHP, s->hw_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_MHP, s->pointer_mask); + ni_item_str_size(ctx, NI_CTRL_HBS, (s->pointer_mask ? s->pointer_mask + 1 : 0)); + ni_item_uint64_tx(ctx, NI_CTRL_FB, (s->sw_pointer - s->hw_pointer - 1) & s->pointer_mask); } - printf("SW descriptor pointer : 0x%08lX\n", s->sd_pointer); - printf("HW descriptor pointer : 0x%08lX\n", s->hd_pointer); - printf("Descriptor pointer mask : 0x%08lX\n", s->desc_pointer_mask); - printf("* Descriptor buffer size : "); print_size(s->desc_pointer_mask ? s->desc_pointer_mask + 1 : 0); printf("\n"); - printf("* Usable descriptors in HW : 0x%08lX\n", (s->sd_pointer - s->hd_pointer) & s->desc_pointer_mask); + ni_item_uint64_tx(ctx, NI_CTRL_REG_SDP, s->sd_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_HDP, s->hd_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_MDP, s->desc_pointer_mask); + ni_item_str_size(ctx, NI_CTRL_DBS, s->desc_pointer_mask ? s->desc_pointer_mask + 1 : 0); + ni_item_uint64_tx(ctx, NI_CTRL_FD, (s->sd_pointer - s->hd_pointer) & s->desc_pointer_mask); } else { - printf("SW pointer : 0x%08lX\n", s->sw_pointer); - printf("HW pointer : 0x%08lX\n", s->hw_pointer); - printf("Pointer mask : 0x%08lX\n", s->pointer_mask); - printf("* Buffer size : "); print_size(s->pointer_mask ? s->pointer_mask + 1 : 0); printf("\n"); + ni_item_uint64_tx(ctx, NI_CTRL_REG_SP, s->sw_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_HP, s->hw_pointer); + ni_item_uint64_tx(ctx, NI_CTRL_REG_MP, s->pointer_mask); + ni_item_str_size(ctx, NI_CTRL_BS, s->pointer_mask ? s->pointer_mask + 1 : 0); } if (q->type == QUEUE_TYPE_SZE || q->type == QUEUE_TYPE_NDP) - printf("Timeout reg : 0x%08lX\n", s->timeout); + ni_item_uint64_tx(ctx, NI_CTRL_REG_TO, s->timeout); if (q->type == QUEUE_TYPE_SZE) { - printf("Max request : 0x%04lX | ", s->max_request); - print_size(s->max_request); printf("\n"); + ni_item_uint64_tx(ctx, NI_CTRL_REG_MR, s->max_request); + ni_item_str_size(ctx, NI_CTRL_MR, s->max_request); } } if (c) { - printf("Sent : %llu\n", c->sent); + ni_item_uint64_t(ctx, NI_CTRL_REG_SENT, c->sent); if (c->have_bytes) - printf("Sent bytes : %llu\n", c->sent_bytes); + ni_item_uint64_t(ctx, NI_CTRL_REG_SENT_B, c->sent_bytes); if (c->have_tx_discard) { - printf("Discarded : %llu\n", c->discarded); + ni_item_uint64_t(ctx, NI_CTRL_REG_DISC, c->discarded); if (c->have_bytes) - printf("Discarded bytes : %llu\n", c->discarded_bytes); + ni_item_uint64_t(ctx, NI_CTRL_REG_DISC_B, c->discarded_bytes); } } if (s && verbose > 1 && q->type != QUEUE_TYPE_CALYPTE) { - printf("Desc base : 0x%.16llX\n", s->desc_base); - printf("Pointer base : 0x%.16llX\n", s->pointer_base); + ni_item_uint64_tx(ctx, NI_CTRL_REG_DESC_B, s->desc_base); + ni_item_uint64_tx(ctx, NI_CTRL_REG_PTR_B, s->pointer_base); } } @@ -514,6 +737,7 @@ int main(int argc, char *argv[]) enum commands cmd = CMD_PRINT_STATUS; int verbose = 0; int sum = 0; + int js = NI_DRC_USER; int ret; const char *query = NULL; @@ -561,6 +785,9 @@ int main(int argc, char *argv[]) if (list_range_parse(&index_range, optarg) < 0) errx(EXIT_FAILURE, "Cannot parse interface number."); break; + case 'j': + js = NI_DRC_JSON; + break; case 'q': cmd = CMD_QUERY; query = optarg; @@ -638,14 +865,25 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } + struct ni_context *ctx = NULL; + if (cmd == CMD_COUNTER_READ_AND_RESET || cmd == CMD_PRINT_STATUS) { + ctx = ni_init_root_context_default(js, ni_items, &ni_dma_item_f[js]); + } + + ni_section(ctx, NI_SEC_ROOT); + + ni_list(ctx, NI_LIST_ALL); if (dir == -1 || dir == 0) { + if (sum != 1) + ni_list(ctx, NI_LIST_RXQ); for (ctrl = 0; ctrl < NC_ARRAY_SIZE(rx_ctrl_name); ctrl++) { i = 0; fdt_for_each_compatible_node(nfb_get_fdt(dev), fdt_offset, rx_ctrl_name[ctrl]) { if (list_range_empty(&index_range) || list_range_contains(&index_range, i)) { + if (sum != 1) + ni_section(ctx, NI_SEC_RXQ); rxq = nc_rxqueue_open(dev, fdt_offset); if (rxq) { - switch (cmd) { case CMD_COUNTER_RESET: nc_rxqueue_reset_counters(rxq); @@ -654,8 +892,7 @@ int main(int argc, char *argv[]) case CMD_PRINT_STATUS: rxqueue_get_status(rxq, verbose ? &stat_rx : NULL, &cntr_rx, cmd); if (sum != 1) { - rxqueue_print_status(rxq, i, verbose, verbose ? &stat_rx : NULL, &cntr_rx); - printf("\n"); + rxqueue_print_status(ctx, rxq, i, verbose, verbose ? &stat_rx : NULL, &cntr_rx); } sum_rx.received += cntr_rx.received; sum_rx.received_bytes += cntr_rx.received_bytes; @@ -681,16 +918,24 @@ int main(int argc, char *argv[]) } nc_rxqueue_close(rxq); } + if (sum != 1) + ni_endsection(ctx, NI_SEC_RXQ); } i++; } } + if (sum != 1) + ni_endlist(ctx, NI_LIST_RXQ); } if (dir == -1 || dir == 1) { + if (sum != 1) + ni_list(ctx, NI_LIST_TXQ); for (ctrl = 0; ctrl < NC_ARRAY_SIZE(tx_ctrl_name); ctrl++) { i = 0; fdt_for_each_compatible_node(nfb_get_fdt(dev), fdt_offset, tx_ctrl_name[ctrl]) { if (list_range_empty(&index_range) || list_range_contains(&index_range, i)) { + if (sum != 1) + ni_section(ctx, NI_SEC_TXQ); txq = nc_txqueue_open(dev, fdt_offset); if (txq) { switch (cmd) { @@ -701,8 +946,7 @@ int main(int argc, char *argv[]) case CMD_PRINT_STATUS: txqueue_get_status(txq, verbose ? &stat_tx : NULL, &cntr_tx, cmd); if (sum != 1) { - txqueue_print_status(txq, i, verbose, verbose ? &stat_tx : NULL, &cntr_tx); - printf("\n"); + txqueue_print_status(ctx, txq, i, verbose, verbose ? &stat_tx : NULL, &cntr_tx); } sum_tx.sent += cntr_tx.sent; sum_tx.sent_bytes += cntr_tx.sent_bytes; @@ -726,37 +970,46 @@ int main(int argc, char *argv[]) } nc_txqueue_close(txq); } + if (sum != 1) + ni_endsection(ctx, NI_SEC_TXQ); } i++; } } + if (sum != 1) + ni_endlist(ctx, NI_LIST_TXQ); } if (sum && (dir == -1 || dir == 0)) { - printf("------------------------------ RX SUM -----------------\n"); - printf("Received : %llu\n", sum_rx.received); + ni_section(ctx, NI_SEC_RXSUM); + ni_item_uint64_t(ctx, NI_CTRL_REG_RECV, sum_rx.received); if (cntr_rx.have_bytes) - printf("Received bytes : %llu\n", sum_rx.received_bytes); - printf("Discarded : %llu\n", sum_rx.discarded); + ni_item_uint64_t(ctx, NI_CTRL_REG_RECV_B, sum_rx.received_bytes); + ni_item_uint64_t(ctx, NI_CTRL_REG_DISC, sum_rx.discarded); if (cntr_rx.have_bytes) - printf("Discarded bytes : %llu\n", sum_rx.discarded_bytes); - printf("\n"); + ni_item_uint64_t(ctx, NI_CTRL_REG_DISC_B, sum_rx.discarded_bytes); + ni_endsection(ctx, NI_SEC_RXSUM); } if (sum && (dir == -1 || dir == 1)) { - printf("------------------------------ TX SUM -----------------\n"); - printf("Sent : %llu\n", sum_tx.sent); + ni_section(ctx, NI_SEC_TXSUM); + ni_item_uint64_t(ctx, NI_CTRL_REG_SENT, sum_tx.sent); if (cntr_tx.have_bytes) - printf("Sent bytes : %llu\n", sum_tx.sent_bytes); + ni_item_uint64_t(ctx, NI_CTRL_REG_SENT_B, sum_tx.sent_bytes); if (cntr_tx.have_tx_discard) { - printf("Discarded : %llu\n", sum_tx.discarded); - if (sum_tx.have_bytes) - printf("Discarded bytes : %llu\n", sum_tx.discarded_bytes); + ni_item_uint64_t(ctx, NI_CTRL_REG_DISC, sum_tx.discarded); + if (cntr_tx.have_bytes) + ni_item_uint64_t(ctx, NI_CTRL_REG_DISC_B, sum_tx.discarded_bytes); } - printf("\n"); + ni_endsection(ctx, NI_SEC_TXSUM); } + ni_endlist(ctx, NI_LIST_ALL); + + ni_endsection(ctx, NI_SEC_ROOT); + ni_close_root_context(ctx); + nfb_close(dev); list_range_destroy(&index_range); From 5bb70884bf17dc67a38e2e5a5e7487105d16fa10 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 May 2025 09:52:55 +0200 Subject: [PATCH 361/518] feat(nfb-eth): use NI (normalized item) library for output --- tools/eth/cfp2.c | 72 ++++--- tools/eth/eth.h | 211 +++++++++++++++++++- tools/eth/ieee802_3.c | 11 +- tools/eth/ieee802_3.h | 1 + tools/eth/main.c | 423 +++++++++++++++++++++++++++++++++++++--- tools/eth/pcspma.c | 230 +++++++++++++--------- tools/eth/qsfpp.c | 154 +++++++++------ tools/eth/rxmac.c | 129 ++++++------ tools/eth/transceiver.c | 43 ++-- tools/eth/txmac.c | 35 ++-- 10 files changed, 972 insertions(+), 337 deletions(-) diff --git a/tools/eth/cfp2.c b/tools/eth/cfp2.c index 38c53237..6d8ec152 100644 --- a/tools/eth/cfp2.c +++ b/tools/eth/cfp2.c @@ -14,11 +14,15 @@ #include #include +#include "eth.h" + #define TEMPERATURE 0xA02F #define VEN_NAME_FIRST 0x8021 #define VEN_NAME_LAST 0x8031 #define VEN_PN_FIRST 0x8034 #define VEN_PN_LAST 0x8044 +#define VEN_SN_FIRST 0x8044 +#define VEN_SN_LAST 0x8054 #define CONNECTOR 0x8002 #define COMPLIANCE 0x8003 #define HW_REV 0x8068 @@ -74,18 +78,39 @@ const char *cfp2_get_connector(uint8_t reg) * @param first First register * @param last Last register (not printed) */ -void cfp2_print_text(struct nc_mdio *mdio, int first, int last, int mdev) +int print_mdio_text(FILE *fout, struct mdio_if_mdev *mdio_if, int item) { uint8_t c; + int cnt = 0; int i; + int first = 0, last = 0; + + switch (item) { + case NI_MDIO_VNDR_NAME: first = VEN_NAME_FIRST; last = VEN_NAME_LAST; break; + case NI_MDIO_SN: first = VEN_SN_FIRST; last = VEN_SN_LAST; break; + case NI_MDIO_PN: first = VEN_PN_FIRST; last = VEN_PN_LAST; break; + } + for (i = first; i < last; i++) { - c = nc_mdio_read(mdio, mdev, 1, i); + c = nc_mdio_read(mdio_if->mdio, mdio_if->mdev, 1, i); if (!c) { break; } - printf("%c", c); + cnt += fprintf(fout, "%c", c); } - printf("\n"); + return cnt; +} + +int print_mdio_text_user(void *priv, int item, struct mdio_if_mdev *mdio_if) +{ + struct ni_user_cbp *p = priv; + return print_mdio_text(p->f, mdio_if, item); +} + +int print_mdio_text_json(void *priv, int item, struct mdio_if_mdev *mdio_if) +{ + struct ni_json_cbp *p = priv; + return print_mdio_text(p->f, mdio_if, item); } /** @@ -127,7 +152,7 @@ int cfp_present(struct nfb_device *dev __attribute__((unused)), int nodeoffset _ * @param ifc Interface device * @param space Interface space */ -void cfp2_print(struct nfb_device *dev, int nodeoffset, int control_params_node) +void cfp2_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node) { (void) control_params_node; /* unused */ @@ -136,6 +161,7 @@ void cfp2_print(struct nfb_device *dev, int nodeoffset, int control_params_node) uint16_t reg16; const void *fdt = nfb_get_fdt(dev); + double pwr; int node_ctrl; int node_ctrlparam; @@ -144,6 +170,7 @@ void cfp2_print(struct nfb_device *dev, int nodeoffset, int control_params_node) int proplen; struct nc_mdio *mdio; + struct mdio_if_mdev mdio_if; int mdev = 0; prop32 = fdt_getprop(fdt, nodeoffset, "control", &proplen); @@ -162,39 +189,38 @@ void cfp2_print(struct nfb_device *dev, int nodeoffset, int control_params_node) return; } - reg16 = nc_mdio_read(mdio, mdev, 1, TEMPERATURE); - - printf("Temperature : %.2f C\n", ((float) reg16) / 256); + mdio_if.mdio = mdio; + mdio_if.mdev = mdev; - printf("Vendor name : "); - cfp2_print_text(mdio, VEN_NAME_FIRST, VEN_NAME_LAST, mdev); + reg16 = nc_mdio_read(mdio, mdev, 1, TEMPERATURE); - printf("Vendor serial number : "); - cfp2_print_text(mdio, 0x8044, 0x8054, mdev); + ni_item_double(ctx, NI_SFF8636_TEMP, ((float) reg16) / 256); - printf("Vendor PN : "); - cfp2_print_text(mdio, VEN_PN_FIRST, VEN_PN_LAST, mdev); + ni_item_mdio_text(ctx, NI_MDIO_VNDR_NAME, &mdio_if); + ni_item_mdio_text(ctx, NI_MDIO_SN, &mdio_if); + ni_item_mdio_text(ctx, NI_MDIO_PN, &mdio_if); reg8 = nc_mdio_read(mdio, mdev, 1, COMPLIANCE); - printf("Compliance : %s\n", cfp2_get_compliance(reg8, &channels)); + ni_item_str(ctx, NI_TRN_COMPLIANCE, cfp2_get_compliance(reg8, &channels)); reg8 = nc_mdio_read(mdio, mdev, 1, CONNECTOR); - printf("Connector : %s\n", cfp2_get_connector(reg8)); + ni_item_str(ctx, NI_TRN_CONNECTOR, cfp2_get_connector(reg8)); reg8 = nc_mdio_read(mdio, mdev, 1, HW_REV); - printf("HW spec. rev. : %.2f\n", ((float) reg8) / 10); + ni_item_double(ctx, NI_MDIO_HW_REV, ((float) reg8) / 10); reg8 = nc_mdio_read(mdio, mdev, 1, MGMT_REV); - printf("Managenent ifc. spec. rev : %.2f\n", ((float) reg8) / 10); + ni_item_double(ctx, NI_MDIO_MGMT_REV, ((float) reg8) / 10); - printf("\nRX input power\n"); + ni_list(ctx, NI_LIST_TRN_RX_IN_PWR); for (i = 0; i < channels; i++) { reg16 = nc_mdio_read(mdio, mdev, 1, RX_IN + i); - printf(" * Lane %2d : %.2f %s (%.2f dBm)\n", i + 1, - (reg16 < 10000) ? ((float)reg16) / 10 : ((float) reg16) / 10000 , - (reg16 < 10000) ? "uW" : "mW", 10 * log10(((float) reg16) / 10000)); - } + pwr = ((float)reg16) / 10000000; + ni_item_int(ctx, NI_TRANS_RX_IN_PWR_L, i + 1); + ni_item_pwr(ctx, NI_TRANS_RX_IN_PWR_V, pwr); + } + ni_endlist(ctx, NI_LIST_TRN_RX_IN_PWR); } /** diff --git a/tools/eth/eth.h b/tools/eth/eth.h index 2e1d3678..9ee414d6 100644 --- a/tools/eth/eth.h +++ b/tools/eth/eth.h @@ -11,13 +11,18 @@ #define NFBTOOL_ETH_H #include +#include -#include +#include + +#include #include #include +#include #include "mdio.h" + // this enum need to corespond with queries[] array enum queries { RX_STATUS, @@ -35,6 +40,7 @@ enum queries { PMA_TYPE, PMA_SPEED, }; + static const char * const queries[] = { "rx_status", "rx_octets", @@ -83,13 +89,24 @@ struct eth_params { const char *string; }; -int rxmac_execute_operation(struct nc_rxmac *rxmac, struct eth_params *p); -int txmac_execute_operation(struct nc_txmac *txmac, struct eth_params *p); -int pcspma_execute_operation(struct nfb_device *dev, int eth_node, struct eth_params *p); +struct mdio_if_mdev { + struct nc_mdio *mdio; + int mdev; +}; + +int rxmac_execute_operation(struct ni_context *ctx, struct nc_rxmac *rxmac, struct eth_params *p); +int txmac_execute_operation(struct ni_context *ctx, struct nc_txmac *txmac, struct eth_params *p); +int pcspma_execute_operation(struct ni_context *ctx, struct nfb_device *dev, int eth_node, struct eth_params *p); int transceiver_execute_operation(struct nfb_device *dev, int node_transceiver, struct eth_params *p); int transceiver_execute_operation_for_eth(struct nfb_device *dev, int node_eth, struct eth_params *p); -int transceiver_print(struct nfb_device *dev, int transceiver_node, int index); -void transceiver_print_short_info(struct nfb_device *dev, int node, struct eth_params *p); +int transceiver_print(struct ni_context *ctx, struct nfb_device *dev, int transceiver_node, int index); +void transceiver_print_short_info(struct ni_context *ctx, struct nfb_device *dev, int node, struct eth_params *p); + +int print_json_qsfp_i2c_text(void *, int item, struct nc_i2c_ctrl*); +int print_user_qsfp_i2c_text(void *, int item, struct nc_i2c_ctrl*); +int print_mdio_text_user(void *priv, int item, struct mdio_if_mdev *mdio_if); +int print_mdio_text_json(void *priv, int item, struct mdio_if_mdev *mdio_if); + int query_print(const void *fdt, int node, char *queries, int size, struct nfb_device *dev, int index); @@ -104,4 +121,186 @@ static inline struct mdio_if_info nfb_eth_create_mdio_info(struct nc_mdio *mdio, }; } + +enum NI_ITEMS { + NI_SEC_ROOT = 0, + NI_LIST_ETH, + NI_SEC_ETH, + NI_SEC_ETH_ID, + + NI_ETH_REPEATER, + NI_SEC_PMA, + NI_PMA_LINK_STA0, + NI_PMA_LINK_STA1, + NI_PMA_SPEED, + NI_PMA_TFAULT, + NI_PMA_RFAULT, + NI_PMA_TYPE, + NI_LIST_PMA_TYPES_AV, + + NI_SEC_PMA_TYPES, + NI_PMA_TYPES_NAME, + NI_PMA_TYPES_ACTIVE, + + NI_LIST_PMA_FEATS_AV, + NI_SEC_PMA_FEAT, + NI_PMA_FEAT_NAME, + NI_PMA_FEAT_ACTIVE, + NI_SEC_PCS, + NI_PCS_LINK_STA0, + NI_PCS_LINK_STA1, + NI_PCS_SPEED, + NI_PCS_TFAULT, + NI_PCS_RFAULT, + + NI_LIST_PCS_FEATS_AV, + NI_PCS_GLB_BLK_LCK0, + NI_PCS_GLB_BLK_LCK1, + + NI_PCS_GLB_HIGH_BER0, + NI_PCS_GLB_HIGH_BER1, + NI_PCS_BER_CNT, + NI_PCS_LANES_ALIGNED, + NI_PCS_BLK_ERR, + NI_LIST_PCS_BLK_LCKS, + NI_PCS_BLK_LCK, + NI_LIST_AM_LCKS, + NI_PCS_AM_LCK, + NI_LIST_LANE_MAP, + NI_PCS_LANE_MAP, + NI_LIST_BIP_ERR_CNT, + NI_BIP_ERR_CNT, + + NI_SEC_RXMAC, + NI_RXM_ENABLED, + NI_RXM_LINK, + NI_RXM_HFIFO_OVF, + NI_RXM_RECV_O, + NI_RXM_PROCESSED, + NI_RXM_RECEIVED, + NI_RXM_ERRONEOUS, + NI_RXM_OVERFLOWED, + NI_SEC_RXMAC_CONF, + NI_RXM_ERR_MASK_REG, + NI_RXM_ERR_FRAME, + NI_RXM_ERR_CRC, + NI_RXM_ERR_MIN_LEN, + NI_RXM_MIN_LEN, + NI_RXM_ERR_MAX_LEN, + NI_RXM_MAX_LEN, + NI_RXM_MAX_LEN_CAP, + NI_RXM_ERR_MAC_CHECK, + NI_RXM_ERR_MAC_MODE, + NI_RXM_MAC_MAX_COUNT, + + NI_SEC_RXMAC_S, + NI_SEC_RXMAC_ES, + NI_RXM_ES_OCTS, + NI_RXM_ES_PKTS, + NI_RXM_ES_BCST, + NI_RXM_ES_MCST, + NI_RXM_ES_CRCE, + NI_RXM_ES_UNDR, + NI_RXM_ES_OVER, + NI_RXM_ES_FRAG, + NI_RXM_ES_JABB, + NI_RXM_ES_64, + NI_RXM_ES_65_127, + NI_RXM_ES_128_255, + NI_RXM_ES_256_511, + NI_RXM_ES_512_1023, + NI_RXM_ES_1024_1518, + NI_RXM_ES_UNDR_SET, + NI_RXM_ES_OVER_SET, + + NI_SEC_TXMAC, + NI_SEC_TXMAC_S, + NI_TXM_ENABLED, + NI_TXM_SENT_O, + NI_TXM_PROCESSED, + NI_TXM_SENT, + NI_TXM_ERRONEOUS, + + NI_TRANS_PRSNT, + NI_TRANS_PRSNT_UNK, + NI_TRANS_CAGE_TYPE, + NI_TRANS_CAGE_ID, + NI_LIST_TRN_LANES, + NI_TRANS_LANE, + + NI_LIST_TRN_RX_IN_PWR, + NI_TRANS_RX_IN_PWR_L, + NI_TRANS_RX_IN_PWR_V, + NI_LIST_TRN_STX_DIS, + NI_TRANS_STX_DIS_L, + NI_TRANS_STX_DIS_V, + + NI_LIST_TRANS, + NI_SEC_TRN, + NI_TRN_NAME, + NI_TRN_INDEX, + NI_MOD_IDENT, + NI_SFF8636_TEMP, + NI_SFF8636_VNDR_NAME, + NI_SFF8636_VNDR_SN, + NI_SFF8636_VNDR_PN, + NI_SFF8636_REVISION, + NI_SFF8636_WL, + NI_SFF8636_WL_TOL, + NI_TRN_COMPLIANCE, + NI_TRN_CONNECTOR, + NI_TRN_CMIS_VER_MAJ, + NI_TRN_CMIS_VER_MIN, + NI_TRN_CMIS_GLB_STAT, + NI_TRN_CMIS_VNDR_NAME, + NI_TRN_CMIS_VNDR_SN, + NI_TRN_CMIS_VNDR_PN, + NI_TRN_CMIS_MED_T, + NI_TRN_CMIS_IFC_T, + + NI_MDIO_VNDR_NAME, + NI_MDIO_SN, + NI_MDIO_PN, + NI_MDIO_HW_REV, + NI_MDIO_MGMT_REV, + + NI_SEC_RSFEC_STATUS, + NI_SEC_RSFEC119_STATUS, + NI_RSFEC_STATUS_BCA, + NI_RSFEC_STATUS_BIA, + NI_RSFEC_STATUS_SER, + NI_RSFEC_STATUS_FLA, + NI_RSFEC_STATUS_PLA, + NI_RSFEC_STATUS_DSER, + NI_RSFEC_STATUS_RDSER, + NI_RSFEC_STATUS_LDSER, + NI_RSFEC_CORRECTED, + NI_RSFEC_UNCORRECTED, + NI_LIST_RSFEC_SYM_ERR, + NI_RSFEC_SYM_ERR_L, + NI_RSFEC_SYM_ERR_V, + + NI_LIST_RSFEC_LANE_MAP, + NI_RSFEC_LANE_MAP, + NI_LIST_RSFEC_AM_LOCK, + NI_RSFEC_AM_LOCK, +}; + +struct ni_eth_item_f_t { + struct ni_common_item_callbacks c; + int (*print_ctrl_reg)(void *, int, int); + int (*print_qsfp_i2c_text)(void *, int, struct nc_i2c_ctrl*); + int (*print_pwr)(void *, int, double); + int (*print_mdio_text)(void *, int, struct mdio_if_mdev *mdio); +}; + +NI_DEFAULT_ITEMS(ni_eth_item_f_t, c.) + +#define NI_ETH_ITEM(name, type, cbcall) NI_ITEM_CB(name, type, ni_eth_item_f_t, cbcall) + +NI_ETH_ITEM(ctrl_reg, int, print_ctrl_reg) +NI_ETH_ITEM(qsfp_i2c_text, struct nc_i2c_ctrl *, print_qsfp_i2c_text) +NI_ETH_ITEM(mdio_text, struct mdio_if_mdev*, print_mdio_text) +NI_ETH_ITEM(pwr, double, print_pwr) + #endif /* NFBTOOL_ETH_H */ diff --git a/tools/eth/ieee802_3.c b/tools/eth/ieee802_3.c index a2ccc645..6b6b770d 100644 --- a/tools/eth/ieee802_3.c +++ b/tools/eth/ieee802_3.c @@ -444,13 +444,18 @@ int ieee802_3_get_pcs_lines(struct mdio_if_info *if_info) } } +int ieee802_3_get_pcs_pma_link_status(struct mdio_if_info *if_info, int devad) +{ + int reg = if_info->mdio_read(if_info->dev, if_info->prtad, devad, 1); + return reg < 0 ? -1 : !!(reg & 0x4); +} + const char *ieee802_3_get_pcs_pma_link_status_string(struct mdio_if_info *if_info, int devad) { - int reg; - reg = if_info->mdio_read(if_info->dev, if_info->prtad, devad, 1); + int reg = ieee802_3_get_pcs_pma_link_status(if_info, devad); if (reg < 0) return "Unknown"; - return (reg & 0x4) ? "UP" : "DOWN"; + return reg ? "UP" : "DOWN"; } int ieee802_3_get_fec_lines(const char *string) diff --git a/tools/eth/ieee802_3.h b/tools/eth/ieee802_3.h index fb7df72c..a1d49f48 100644 --- a/tools/eth/ieee802_3.h +++ b/tools/eth/ieee802_3.h @@ -25,6 +25,7 @@ const char *ieee802_3_get_pcs_speed_string(struct mdio_if_info *if_info); const char *ieee802_3_get_pma_speed_string(struct mdio_if_info *if_info); const char *ieee802_3_get_pcs_pma_link_status_string(struct mdio_if_info *if_info, int devad); +int ieee802_3_get_pcs_pma_link_status(struct mdio_if_info *if_info, int devad); int ieee802_3_get_pcs_lines(struct mdio_if_info *if_info); int ieee802_3_get_fec_lines(const char *type); diff --git a/tools/eth/main.c b/tools/eth/main.c index 293786b9..b9cb5c74 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -19,13 +20,363 @@ #include "eth.h" -#define ARGUMENTS ":hd:i:q:e:rtRSl:L:p:m:u:a:c:M:ovPT" +#define ARGUMENTS ":hd:i:q:e:rtRSl:L:p:m:u:a:c:M:ojvPT" #define RXMAC 1 #define TXMAC 2 #define PCSPMA 4 #define TRANSCEIVER 8 + +#define NUF_N (NI_USER_ITEM_F_NO_NEWLINE) +#define NUF_NDA (NI_USER_ITEM_F_NO_NEWLINE | NI_USER_ITEM_F_NO_DELIMITER | NI_USER_ITEM_F_NO_ALIGN) +#define NUF_DA (NI_USER_ITEM_F_NO_DELIMITER | NI_USER_ITEM_F_NO_ALIGN) +#define NUF_VE (NI_USER_LIST_F_NO_VALUE | NI_USER_LIST_F_ENDLINE) +#define NUF_SL (NI_USER_ITEM_F_SEC_LABEL) + +#define NUFA(x) ni_user_f_align(x) +#define NUFW(x) ni_user_f_width(x) +#define NUFD(x) ni_user_f_decim(x) +#define NUFC NUFW(20) + +#define NJFD(x) ni_json_f_decim(x) + +static struct ni_context_item_default ni_items[] = { + [NI_SEC_ROOT] = {ni_json_e, ni_user_n}, + [NI_LIST_ETH] = {ni_json_k("eth"), ni_user_v(NULL, 0, "\n", NULL)}, /* FIXME: no newline for 128 */ + [NI_SEC_ETH] = {ni_json_e, ni_user_f("Ethernet interface", NUF_SL | NUFW(-4))}, + [NI_SEC_ETH_ID] = {ni_json_k("id"), ni_user_v(" ", NUF_NDA | NUF_SL | NUFW(0), NULL, NULL)}, + [NI_SEC_PMA] = {ni_json_k("pma"), ni_user_l("PMA regs")}, + [NI_PMA_LINK_STA0] = {ni_json_k("link_status_latch"), ni_user_f("Link status", NUF_N | NUFW(-4))}, + [NI_PMA_LINK_STA1] = {ni_json_k("link_status"), ni_user_v(NULL, NUF_DA | NUFW(-4), " | ", NULL)}, + [NI_PMA_SPEED] = {ni_json_k("speed_str"), ni_user_l("Speed")}, + [NI_SEC_PCS] = {ni_json_k("pcs"), ni_user_l("PCS regs")}, + [NI_PCS_LINK_STA0] = {ni_json_k("link_status_latch"), ni_user_f("Link status", NUF_N | NUFW(-4))}, + [NI_PCS_LINK_STA1] = {ni_json_k("link_status"), ni_user_v(NULL, NUF_DA | NUFW(-4), " | ", NULL)}, + [NI_PCS_SPEED] = {ni_json_k("speed_str"), ni_user_l("Speed")}, + + [NI_ETH_REPEATER] = {ni_json_k("repeater"), ni_user_l("Repeater status")}, + + [NI_PCS_RFAULT] = {ni_json_k("receive_fault"), ni_user_l("Receive fault")}, + [NI_PCS_TFAULT] = {ni_json_k("transmit_fault"), ni_user_l("Transmit fault")}, + [NI_PMA_RFAULT] = {ni_json_k("receive_fault"), ni_user_l("Receive fault")}, + [NI_PMA_TFAULT] = {ni_json_k("transmit_fault"), ni_user_l("Transmit fault")}, + [NI_PMA_TYPE] = {ni_json_k("type"), ni_user_l("PMA type")}, + [NI_LIST_PMA_FEATS_AV] = {ni_json_k("available_features"), ni_user_f("Supported PMA features ->", 0)}, + + [NI_LIST_PCS_FEATS_AV] = {ni_json_k("available_features"), ni_user_f("Supported PCS features ->", 0)}, + + + [NI_PCS_GLB_BLK_LCK0] = {ni_json_k("global_block_lock_latch"),ni_user_f("Global block lock", NUF_N | NUFW(-4))}, + [NI_PCS_GLB_BLK_LCK1] = {ni_json_k("global_block_lock"), ni_user_v(NULL, NUF_DA | NUFW(-4), " | ", NULL)}, + + [NI_PCS_GLB_HIGH_BER0] = {ni_json_k("global_high_ber_latch"), ni_user_f("Global high BER", NUF_N | NUFW(-4))}, + [NI_PCS_GLB_HIGH_BER1] = {ni_json_k("global_high_ber"), ni_user_v(NULL, NUF_DA | NUFW(-4), " | ", NULL)}, + [NI_PCS_BER_CNT] = {ni_json_k("ber_counter"), ni_user_l("BER counter")}, + [NI_PCS_BLK_ERR] = {ni_json_k("error_blocks"), ni_user_l("Errored blocks")}, + [NI_PCS_LANES_ALIGNED] = {ni_json_k("lanes_aligned"), ni_user_l("PCS lanes aligned")}, + + [NI_LIST_PCS_BLK_LCKS] = {ni_json_k("block_lock"), ni_user_v("Block lock for lanes", NUF_VE | NUFA(10), "", NULL)}, + [NI_PCS_BLK_LCK] = {ni_json_e, ni_user_f(NULL, NUF_NDA | NUFW(6))}, + + [NI_LIST_AM_LCKS] = {ni_json_k("am_lock"), ni_user_v("AM lock", NUF_VE | NUFA(10), "", NULL)}, + [NI_PCS_AM_LCK] = {ni_json_e, ni_user_f(NULL, NUF_NDA | NUFW(6))}, + + [NI_LIST_LANE_MAP] = {ni_json_k("lane_map"), ni_user_f("Lane mapping", NUF_VE | NUFA(10))}, + [NI_PCS_LANE_MAP] = {ni_json_e, ni_user_f(NULL, NUF_NDA | NUFW(6))}, + + [NI_LIST_BIP_ERR_CNT] = {ni_json_k("bip_error_counters"), ni_user_f("BIP error counters", NUF_VE | NUFA(10))}, + [NI_BIP_ERR_CNT] = {ni_json_e, ni_user_f(NULL, NUF_NDA | NUFW(6))}, + + [NI_LIST_PMA_TYPES_AV] = {ni_json_k("available_types"), ni_user_f("Supported PMA types ->", 0)}, + [NI_SEC_PMA_TYPES] = {ni_json_n, ni_user_f(NULL, 256)}, + [NI_PMA_TYPES_NAME] = {ni_json_k("name"), ni_user_l("")}, + [NI_PMA_TYPES_ACTIVE] = {ni_json_n, ni_user_f(" * ", NUF_NDA)}, + + [NI_SEC_PMA_FEAT] = {ni_json_e, ni_user_n}, + [NI_PMA_FEAT_NAME] = {ni_json_k("name"), ni_user_l("")}, + [NI_PMA_FEAT_ACTIVE] = {ni_json_k("active"), ni_user_f(" * ", NUF_NDA)}, + + [NI_SEC_RXMAC] = {ni_json_k("rxmac"), ni_user_l("RXMAC Status")}, + [NI_RXM_ENABLED] = {ni_json_k("enabled"), ni_user_l("RXMAC status")}, + [NI_RXM_LINK] = {ni_json_k("link"), ni_user_l("Link status")}, + [NI_RXM_HFIFO_OVF] = {ni_json_k("hfifo_overflow"), ni_user_l("HFIFO overflow occurred")}, + + [NI_SEC_RXMAC_S] = {ni_json_k("stats"), ni_user_n}, + [NI_RXM_RECV_O] = {ni_json_k("pass_octets"), ni_user_f("Received octets", NUFC)}, + [NI_RXM_PROCESSED] = {ni_json_k("total"), ni_user_f("Processed", NUFC)}, + [NI_RXM_RECEIVED] = {ni_json_k("pass"), ni_user_f("Received", NUFC)}, + [NI_RXM_ERRONEOUS] = {ni_json_k("erroneous"), ni_user_f("Erroneous", NUFC)}, + [NI_RXM_OVERFLOWED] = {ni_json_k("overflowed"), ni_user_f("Overflowed", NUFC)}, + + [NI_SEC_RXMAC_CONF] = {ni_json_k("config"), ni_user_l("RXMAC configuration")}, + [NI_RXM_ERR_MASK_REG] = {ni_json_k("err_mask_reg"), ni_user_l("Error mask register")}, + + [NI_RXM_ERR_FRAME] = {ni_json_k("err_mask_frame_err"), ni_user_l(" * Frame error from MII [0]")}, + [NI_RXM_ERR_CRC] = {ni_json_k("err_mask_crc_check"), ni_user_l(" * CRC check [1]")}, + [NI_RXM_ERR_MIN_LEN] = {ni_json_k("err_mask_min_length"), ni_user_l(" * Minimal frame length [2]")}, + [NI_RXM_MIN_LEN] = {ni_json_k("pkt_min_length"), ni_user_l(" * length")}, + [NI_RXM_ERR_MAX_LEN] = {ni_json_k("err_mask_max_length"), ni_user_l(" * Maximal frame length [3]")}, + [NI_RXM_MAX_LEN] = {ni_json_k("pkt_max_length"), ni_user_l(" * length")}, + [NI_RXM_MAX_LEN_CAP] = {ni_json_k("pkt_max_length_capable"), ni_user_l(" * capable length")}, + [NI_RXM_ERR_MAC_CHECK] = {ni_json_k("err_mask_mac_addr_check"),ni_user_l(" * MAC address check [4]")}, + [NI_RXM_ERR_MAC_MODE] = {ni_json_k("err_mask_mac_addr_mode"), ni_user_l(" * mode")}, + [NI_RXM_MAC_MAX_COUNT] = {ni_json_k("mac_addr_count"), ni_user_l("MAC address table size")}, + + [NI_SEC_RXMAC_ES] = {ni_json_k("etherstats"), ni_user_l("RXMAC etherStatsTable")}, + [NI_RXM_ES_OCTS] = {ni_json_k("octets"), ni_user_f("etherStatsOctets", NUFC)}, + [NI_RXM_ES_PKTS] = {ni_json_k("pkts"), ni_user_f("etherStatsPkts", NUFC)}, + [NI_RXM_ES_BCST] = {ni_json_k("broadcast"), ni_user_f("etherStatsBroadcastPkts", NUFC)}, + [NI_RXM_ES_MCST] = {ni_json_k("multicast"), ni_user_f("etherStatsMulticastPkts", NUFC)}, + [NI_RXM_ES_CRCE] = {ni_json_k("crc_align_errors"), ni_user_f("etherStatsCRCAlignErrors", NUFC)}, + [NI_RXM_ES_UNDR] = {ni_json_k("undersize"), ni_user_f("etherStatsUndersizePkts", NUFC)}, + [NI_RXM_ES_OVER] = {ni_json_k("oversize"), ni_user_f("etherStatsOversizePkts", NUFC)}, + [NI_RXM_ES_FRAG] = {ni_json_k("fragments"), ni_user_f("etherStatsFragments", NUFC)}, + [NI_RXM_ES_JABB] = {ni_json_k("jabbers"), ni_user_f("etherStatsJabbers", NUFC)}, + [NI_RXM_ES_64] = {ni_json_k("pkts64"), ni_user_f("etherStatsPkts64Octets", NUFC)}, + [NI_RXM_ES_65_127] = {ni_json_k("pkts65to127"), ni_user_f("etherStatsPkts65to127Octets", NUFC)}, + [NI_RXM_ES_128_255] = {ni_json_k("pkts128to255"), ni_user_f("etherStatsPkts128to255Octets", NUFC)}, + [NI_RXM_ES_256_511] = {ni_json_k("pkts256to511"), ni_user_f("etherStatsPkts256to511Octets", NUFC)}, + [NI_RXM_ES_512_1023] = {ni_json_k("pkts512to1023"), ni_user_f("etherStatsPkts512to1023Octets", NUFC)}, + [NI_RXM_ES_1024_1518] = {ni_json_k("pkts1024to1518"), ni_user_f("etherStatsPkts1024to1518Octets", NUFC)}, + [NI_RXM_ES_UNDR_SET] = {ni_json_k("conf_undersize"), ni_user_f("underMinPkts", NUFC)}, + [NI_RXM_ES_OVER_SET] = {ni_json_k("conf_oversize"), ni_user_f("overMaxPkts", NUFC)}, + + [NI_SEC_TXMAC] = {ni_json_k("txmac"), ni_user_l("TXMAC status")}, + [NI_TXM_ENABLED] = {ni_json_k("enabled"), ni_user_l("TXMAC status")}, + [NI_SEC_TXMAC_S] = {ni_json_k("stats"), ni_user_n}, + [NI_TXM_SENT_O] = {ni_json_k("sent_octets"), ni_user_f("Transmitted octets", NUFC)}, + [NI_TXM_PROCESSED] = {ni_json_k("processed"), ni_user_f("Processed", NUFC)}, + [NI_TXM_SENT] = {ni_json_k("sent"), ni_user_f("Transmitted", NUFC)}, + [NI_TXM_ERRONEOUS] = {ni_json_k("erroneous"), ni_user_f("Erroneous", NUFC)}, + + /* Still Eth section */ + [NI_TRANS_PRSNT] = {ni_json_k("present"), ni_user_l("Transceiver status")}, + [NI_TRANS_PRSNT_UNK] = {ni_json_n, ni_user_l("Transceiver status")}, + [NI_TRANS_CAGE_TYPE] = {ni_json_k("cage_type"), ni_user_f("Transceiver cage", NUF_N)}, + [NI_TRANS_CAGE_ID] = {ni_json_k("cage_id"), ni_user_v(NULL, NUF_DA, "-", NULL)}, + [NI_LIST_TRN_LANES] = {ni_json_k("lanes"), ni_user_v("Transceiver lane(s)", NUF_VE, "|", "\n")}, + [NI_TRANS_LANE] = {ni_json_e, ni_user_v(NULL, NUF_NDA, NULL, NULL)}, + + /* Trans section */ + [NI_LIST_TRANS] = {ni_json_k("transceivers"), ni_user_v(NULL, 0, "\n", NULL)}, + + [NI_SEC_TRN] = {ni_json_n, ni_user_l("")}, + [NI_TRN_INDEX] = {ni_json_k("id"), ni_user_f("", NUF_NDA | NUF_SL | NUFW(2))}, + [NI_TRN_NAME] = {ni_json_k("name"), ni_user_v("", NUF_NDA | NUF_SL, NULL, "")}, + [NI_MOD_IDENT] = {ni_json_k("identifier"), ni_user_l("Module identifier")}, + [NI_TRN_COMPLIANCE] = {ni_json_k("compliance"), ni_user_l("Compliance")}, + [NI_TRN_CONNECTOR] = {ni_json_k("connector"), ni_user_l("Connector")}, + [NI_SFF8636_VNDR_NAME] = {ni_json_k("vendor_name"), ni_user_l("Vendor name")}, + [NI_SFF8636_VNDR_SN] = {ni_json_k("vendor_serial_number"), ni_user_l("Vendor serial number")}, + [NI_SFF8636_VNDR_PN] = {ni_json_k("vendor_part_number"), ni_user_l("Vendor part number")}, + [NI_SFF8636_REVISION] = {ni_json_k("revision"), ni_user_l("Revision")}, + [NI_SFF8636_TEMP] = {ni_json_f("temperature", NJFD(2)), ni_user_v("Temperature", NUFD(2), NULL, " C")}, + [NI_SFF8636_WL] = {ni_json_f("wavelength", NJFD(2)), ni_user_v("Wavelength", NUF_N | NUFD(2) , NULL, " nm")}, + [NI_SFF8636_WL_TOL] = {ni_json_f("wavelength_tolerance", NJFD(2)), ni_user_v(" ", NUF_DA |NUFD(2), "+-", " nm")}, + + [NI_LIST_TRN_RX_IN_PWR] = {ni_json_k("rx_input_power"), ni_user_l("RX input power")}, + [NI_TRANS_RX_IN_PWR_L] = {ni_json_n, ni_user_f(" * Lane ", NUF_NDA)}, + [NI_TRANS_RX_IN_PWR_V] = {ni_json_e, ni_user_f("", NUFD(2) | NUFW(1))}, + + [NI_LIST_TRN_STX_DIS] = {ni_json_k("stx_disable"), ni_user_l("Software TX disable")}, + [NI_TRANS_STX_DIS_L] = {ni_json_n, ni_user_f(" * Lane ", NUF_NDA)}, + [NI_TRANS_STX_DIS_V] = {ni_json_e, ni_user_l("")}, + + [NI_TRN_CMIS_VER_MAJ] = {ni_json_k("cmis_version_major"), ni_user_f("CMIS version", NUF_N)}, + [NI_TRN_CMIS_VER_MIN] = {ni_json_k("cmis_version_minor"), ni_user_v("", NUF_DA, ".", NULL)}, + [NI_TRN_CMIS_GLB_STAT] = {ni_json_k("cmis_module_state"), ni_user_l("Module state")}, + [NI_TRN_CMIS_VNDR_NAME] = {ni_json_k("vendor_name"), ni_user_l("Vendor name")}, + [NI_TRN_CMIS_VNDR_SN] = {ni_json_k("vendor_serial_number"), ni_user_l("Vendor serial number")}, + [NI_TRN_CMIS_VNDR_PN] = {ni_json_k("vendor_part_number"), ni_user_l("Vendor part number")}, + [NI_TRN_CMIS_MED_T] = {ni_json_k("media_type"), ni_user_l("Media type")}, + [NI_TRN_CMIS_IFC_T] = {ni_json_k("interface_type"), ni_user_l("Media interface technology")}, + [NI_MDIO_VNDR_NAME] = {ni_json_k("vendor_name"), ni_user_l("Vendor name")}, + [NI_MDIO_SN] = {ni_json_k("vendor_serial_number"), ni_user_l("Vendor serial number")}, + [NI_MDIO_PN] = {ni_json_k("vendor_part_number"), ni_user_l("Vendor part number")}, + [NI_MDIO_HW_REV] = {ni_json_k("hw_spec_rev"), ni_user_f("HW spec. rev.", NUFD(1))}, + [NI_MDIO_MGMT_REV] = {ni_json_k("mgmt_spec_rev"), ni_user_f("Management ifc. spec. rev.", NUFD(1))}, + + [NI_SEC_RSFEC_STATUS] = {ni_json_k("rsfec"), ni_user_l("RS-FEC status")}, + [NI_SEC_RSFEC119_STATUS]= {ni_json_k("rsfec_cl119"), ni_user_l("RS-FEC status")}, + [NI_RSFEC_STATUS_BCA] = {ni_json_k("bypass_correction"), ni_user_l("RS-FEC bypass correction ability")}, + [NI_RSFEC_STATUS_BIA] = {ni_json_k("bypass_indication"), ni_user_l("RS-FEC bypass indication ability")}, + [NI_RSFEC_STATUS_SER] = {ni_json_k("high_ser"), ni_user_l("RS-FEC high SER")}, + [NI_RSFEC_STATUS_FLA] = {ni_json_k("lanes_aligned"), ni_user_l("RS-FEC lanes aligned")}, + [NI_RSFEC_STATUS_PLA] = {ni_json_k("pcs_lanes_aligned"), ni_user_l("PCS lanes aligned")}, + [NI_RSFEC_STATUS_DSER] = {ni_json_k("degraded_ser"), ni_user_l("RS-FEC degraded SER")}, + [NI_RSFEC_STATUS_RDSER] = {ni_json_k("remote_degraded_ser"), ni_user_l("Remote degraded SER")}, + [NI_RSFEC_STATUS_LDSER] = {ni_json_k("local_degraded_ser"), ni_user_l("Local degraded SER")}, + + [NI_RSFEC_CORRECTED] = {ni_json_k("corrected_cws"), ni_user_l("RS-FEC corrected cws")}, + [NI_RSFEC_UNCORRECTED] = {ni_json_k("uncorrected_cws"), ni_user_l("RS-FEC uncorrected cws")}, + + [NI_LIST_RSFEC_SYM_ERR] = {ni_json_k("symbol_errors"), ni_user_l("RS-FEC symbol errors ->")}, + [NI_RSFEC_SYM_ERR_L] = {ni_json_n, ni_user_f(" * Lane ", NUF_NDA)}, + [NI_RSFEC_SYM_ERR_V] = {ni_json_e, ni_user_l("")}, + + [NI_LIST_RSFEC_LANE_MAP]= {ni_json_k("lane_map"), ni_user_v("RS-FEC lane mapping", NUF_VE, " ", NULL)}, + [NI_RSFEC_LANE_MAP] = {ni_json_e, ni_user_f("", NUF_NDA)}, + + [NI_LIST_RSFEC_AM_LOCK] = {ni_json_k("am_lock"), ni_user_v("RS-FEC AM lock", NUF_VE, " ", NULL)}, + [NI_RSFEC_AM_LOCK] = {ni_json_e, ni_user_f(NULL, NUF_NDA)}, +}; + +int print_ctrl_reg_json(void *priv, int item, int val) +{ + struct ni_json_cbp *p = priv; + const char *res = NULL; + + switch (item) { + case NI_PCS_LANE_MAP: + if (val == -1) + return fprintf(p->f, "null"); + return fprintf(p->f, "%d", val); + case NI_ETH_REPEATER: + switch (val) { + case IDCOMP_REPEATER_NORMAL: res = "\"normal\""; break; + case IDCOMP_REPEATER_REPEAT: res = "\"repeat\""; break; + case IDCOMP_REPEATER_IDLE: res = "\"idle\""; break; + default: res = "\"unknown\""; break; + } + break; + case NI_RXM_ERR_MAC_MODE: + switch(val) { + case RXMAC_MAC_FILTER_PROMISCUOUS: res = "\"promiscuous\""; break; + case RXMAC_MAC_FILTER_TABLE: res = "\"normal\""; break; + case RXMAC_MAC_FILTER_TABLE_BCAST: res = "\"broadcast\""; break; + case RXMAC_MAC_FILTER_TABLE_BCAST_MCAST:res = "\"multicast\""; break; + } + break; + default: + res = val ? "true": "false"; + break; + } + return fprintf(p->f, res); +} + +int print_ctrl_reg_user(void *priv, int item, int val) +{ + struct ni_user_cbp *p = priv; + const char *res = NULL; + + switch (item) { + case NI_PCS_GLB_BLK_LCK0: + case NI_PCS_GLB_BLK_LCK1: + case NI_PCS_GLB_HIGH_BER0: + case NI_PCS_GLB_HIGH_BER1: + case NI_PCS_LANES_ALIGNED: + case NI_PMA_RFAULT: + case NI_PMA_TFAULT: + case NI_PCS_RFAULT: + case NI_PCS_TFAULT: res = val ? "Yes" : "No"; break; + + case NI_RXM_ENABLED: + case NI_TXM_ENABLED: res = val ? "ENABLED" : "DISABLED"; break; + + case NI_PMA_LINK_STA0: + case NI_PMA_LINK_STA1: + case NI_PCS_LINK_STA0: + case NI_PCS_LINK_STA1: + case NI_RXM_LINK: res = val ? "UP" : "DOWN"; break; + + case NI_RSFEC_STATUS_BCA: + case NI_RSFEC_STATUS_BIA: + case NI_RSFEC_STATUS_SER: + case NI_RSFEC_STATUS_FLA: + case NI_RSFEC_STATUS_PLA: + case NI_RSFEC_STATUS_DSER: + case NI_RSFEC_STATUS_RDSER: + case NI_RSFEC_STATUS_LDSER: + case NI_RXM_HFIFO_OVF: res = val ? "True" : "False"; break; + + case NI_TRANS_PRSNT: res = val ? "OK" : "Not plugged"; break; + + case NI_TRANS_STX_DIS_V: res = val ? "active" : "inactive"; break; + + case NI_PMA_TYPES_ACTIVE: + case NI_PMA_FEAT_ACTIVE: res = val ? "[active]" : ""; break; + + case NI_RXM_ERR_FRAME: + case NI_RXM_ERR_CRC: + case NI_RXM_ERR_MIN_LEN: + case NI_RXM_ERR_MAX_LEN: + case NI_RXM_ERR_MAC_CHECK: res = val ? "enabled" : "disabled"; break; + + case NI_PCS_AM_LCK: + case NI_RSFEC_AM_LOCK: + case NI_PCS_BLK_LCK: res = val ? "L" : "X"; break; + + case NI_PCS_LANE_MAP: + if (val == -1) { + res = "U"; + } else { + return fprintf(p->f, "%*d", p->width, val); + } + break; + + case NI_ETH_REPEATER: + switch (val) { + case IDCOMP_REPEATER_NORMAL: res = "Normal (transmit data from application)"; break; + case IDCOMP_REPEATER_REPEAT: res = "Repeat (transmit data from RXMAC)"; break; + case IDCOMP_REPEATER_IDLE: res = "Idle (transmit disabled)"; break; + default: res = "Unknown (use the PCS/PMA features)"; break; + } + break; + case NI_RXM_ERR_MAC_MODE: + switch(val) { + case RXMAC_MAC_FILTER_PROMISCUOUS: res = "Promiscuous mode"; break; + case RXMAC_MAC_FILTER_TABLE: res = "Filter by MAC address table"; break; + case RXMAC_MAC_FILTER_TABLE_BCAST: res = "Filter by MAC address table, allow broadcast"; break; + case RXMAC_MAC_FILTER_TABLE_BCAST_MCAST:res = "Filter by MAC address table, allow broadcast + multicast"; break; + } + break; + } + if (res) + return fprintf(p->f, "%*s", p->width, res); + + return 0; +} + +int print_pwr_json(void *priv, int item, double val) +{ + struct ni_json_cbp *p = priv; + (void) item; + return fprintf(p->f, "%.8f", val); +} + +int print_pwr_user(void *priv, int item, double val) +{ + struct ni_user_cbp *p = priv; + int uw; + (void) item; + + val *= 1000; /* from W to mW */ + uw = val < 1; + return fprintf(p->f, "%.2f %s (%.2f dBm)", + uw ? val * 1000 : val, + uw ? "uW" : "mW", + 10 * log10(val)); +} + +struct ni_eth_item_f_t ni_eth_item_f[] = { + [NI_DRC_JSON] = { + .c = ni_common_item_callbacks[NI_DRC_JSON], + .print_ctrl_reg = print_ctrl_reg_json, + .print_qsfp_i2c_text = print_json_qsfp_i2c_text, + .print_mdio_text = print_mdio_text_json, + .print_pwr = print_pwr_json, + }, + [NI_DRC_USER] = { + .c = ni_common_item_callbacks[NI_DRC_USER], + .print_ctrl_reg = print_ctrl_reg_user, + .print_qsfp_i2c_text = print_user_qsfp_i2c_text, + .print_mdio_text = print_mdio_text_user, + .print_pwr = print_pwr_user, + }, +}; + + // TODO add usage for queries void usage(const char *progname, int verbose) { @@ -84,6 +435,7 @@ void usage(const char *progname, int verbose) printf(" example of usage: '-q rx_link,tx_octets,pma_speed'\n"); } + printf("-j Print output in JSON\n"); printf("-v Increase verbosity (including help)\n"); printf("-h Show this text\n"); printf("\n"); @@ -119,6 +471,7 @@ int main(int argc, char *argv[]) int ret; char cmds = 0; int used = 0; + int js = NI_DRC_USER; unsigned mv[6]; int use = 0; @@ -130,7 +483,6 @@ int main(int argc, char *argv[]) struct list_range index_range; enum nc_idcomp_repeater repeater_status = IDCOMP_REPEATER_NORMAL; - const char *repeater_str; p.command = CMD_PRINT_STATUS; p.verbose = 0; @@ -146,6 +498,9 @@ int main(int argc, char *argv[]) case 'v': p.verbose++; break; + case 'j': + js = NI_DRC_JSON; + break; case 'h': p.command = CMD_USAGE; break; @@ -315,11 +670,20 @@ int main(int argc, char *argv[]) use &= TRANSCEIVER; } - fdt_for_each_compatible_node(fdt, node, COMP_NETCOPE_ETH) { - if (use & TRANSCEIVER) - continue; + struct ni_context *ctx = NULL; + if (p.command == CMD_PRINT_STATUS) { + ctx = ni_init_root_context_default(js, ni_items, &ni_eth_item_f[js]); + } + + ni_section(ctx, NI_SEC_ROOT); + if ((use & TRANSCEIVER) == 0) { + ni_list(ctx, NI_LIST_ETH); + fdt_for_each_compatible_node(fdt, node, COMP_NETCOPE_ETH) { if (list_range_empty(&index_range) || list_range_contains(&index_range, p.index)) { + ni_section(ctx, NI_SEC_ETH); + ni_item_int(ctx, NI_SEC_ETH_ID, p.index); + if (p.command == CMD_SET_REPEATER) { used++; if (nc_idcomp_repeater_set(dev, p.index, repeater_status)) { @@ -327,13 +691,16 @@ int main(int argc, char *argv[]) } } else { if (p.command == CMD_PRINT_STATUS) { - if (used++) - printf("\n"); - printf("----------------------------- Ethernet interface %d ----\n", p.index); + used++; p2 = p; p2.command = CMD_PRINT_SPEED; - pcspma_execute_operation(dev, node, &p2); - transceiver_print_short_info(dev, node, &p); + pcspma_execute_operation(ctx, dev, node, &p2); + transceiver_print_short_info(ctx, dev, node, &p); + + if (p.verbose) { + repeater_status = nc_idcomp_repeater_get(dev, p.index); + ni_item_ctrl_reg(ctx, NI_ETH_REPEATER, repeater_status); + } } if (p.command == CMD_QUERY) { @@ -354,7 +721,7 @@ int main(int argc, char *argv[]) if (!rxmac) { warnx("Cannot open RXMAC for ETH%d", p.index); } else { - if (rxmac_execute_operation(rxmac, &p) != 0) + if (rxmac_execute_operation(ctx, rxmac, &p) != 0) warnx("Cannot perform a command on RXMAC%d", p.index); nc_rxmac_close(rxmac); } @@ -367,58 +734,54 @@ int main(int argc, char *argv[]) if (!txmac) { warnx("Cannot open TXMAC for ETH%d", p.index); } else { - if (txmac_execute_operation(txmac, &p) != 0) + if (txmac_execute_operation(ctx, txmac, &p) != 0) warnx("Cannot perform a command on TXMAC%d", p.index); nc_txmac_close(txmac); } } - if (p.command == CMD_PRINT_STATUS && (use & RXMAC || use & TXMAC)) { - used++; - repeater_status = nc_idcomp_repeater_get(dev, p.index); - switch (repeater_status) { - case IDCOMP_REPEATER_NORMAL: repeater_str = "Normal (transmit data from application)"; break; - case IDCOMP_REPEATER_REPEAT: repeater_str = "Repeat (transmit data from RXMAC)"; break; - case IDCOMP_REPEATER_IDLE: repeater_str = "Idle (transmit disabled)"; break; - default: repeater_str = "Unknown (use the PCS/PMA features)"; break; - } - printf("Repeater status : %s\n", repeater_str); - } - if (p.command == CMD_PRINT_STATUS) { used++; if (use & PCSPMA) - pcspma_execute_operation(dev, node, &p); + pcspma_execute_operation(ctx, dev, node, &p); } else if (use & PCSPMA) { used++; - ret = pcspma_execute_operation(dev, node, &p); + ret = pcspma_execute_operation(ctx, dev, node, &p); if (ret) warnx("PCS/PMA command failed"); } } - + ni_endsection(ctx, NI_SEC_ETH); } p.index++; } + ni_endlist(ctx, NI_LIST_ETH); + } if (use & TRANSCEIVER) { + ni_list(ctx, NI_LIST_TRANS); fdt_for_each_compatible_node(fdt, node, "netcope,transceiver") { if (list_range_empty(&index_range) || list_range_contains(&index_range, p.index)) { + ni_section(ctx, NI_SEC_TRN); if (p.command == CMD_PRINT_STATUS) { - if (used++) - printf("\n"); - transceiver_print(dev, node, p.index); + used++; + transceiver_print(ctx, dev, node, p.index); } else { used++; ret = transceiver_execute_operation(dev, node, &p); if (ret) warnx("Transceiver command failed"); } + ni_endsection(ctx, NI_SEC_TRN); } p.index++; } + ni_endlist(ctx, NI_LIST_TRANS); } + ni_endsection(ctx, NI_SEC_ROOT); + ni_close_root_context(ctx); + if (!used) { warnx("No such interface"); } diff --git a/tools/eth/pcspma.c b/tools/eth/pcspma.c index 7aa13a10..1864eb52 100644 --- a/tools/eth/pcspma.c +++ b/tools/eth/pcspma.c @@ -44,28 +44,38 @@ static const struct phy_feature_t pcs_feature_table [] = { {NULL, 0, 0, 0, 0}, }; -void pcspma_print_speed(struct nc_mdio *mdio, int portaddr, uint8_t mdev) +void pcspma_print_speed(struct ni_context *ctx, struct nc_mdio *mdio, int portaddr, uint8_t mdev) { struct mdio_if_info mdio_info = nfb_eth_create_mdio_info(mdio, portaddr); - printf("Speed : %s\n", - mdev == 1 ? ieee802_3_get_pma_speed_string(&mdio_info) : ieee802_3_get_pcs_speed_string(&mdio_info)); + + if (mdev == 1) + ni_item_str(ctx, NI_PMA_SPEED, ieee802_3_get_pma_speed_string(&mdio_info)); + else + ni_item_str(ctx, NI_PCS_SPEED, ieee802_3_get_pcs_speed_string(&mdio_info)); } -void print_pcspma_common(struct nc_mdio *mdio, int portaddr, uint8_t mdev) +void print_pcspma_common(struct ni_context *ctx, struct nc_mdio *mdio, int portaddr, uint8_t mdev) { uint32_t reg; struct mdio_if_info mdio_info = nfb_eth_create_mdio_info(mdio, portaddr); - printf("Link status : %s | %s\n", - ieee802_3_get_pcs_pma_link_status_string(&mdio_info, mdev), - ieee802_3_get_pcs_pma_link_status_string(&mdio_info, mdev)); - pcspma_print_speed(mdio, portaddr, mdev); - reg = nc_mdio_read(mdio, portaddr, mdev, 8); - // specification, mask 0x800 or 0x400 - printf("Transmit Fault : %s\n", (reg & 0x800) ? "Yes" : "No"); - // specification, mask 0x400 or 0x200 - printf("Receive Fault : %s\n", (reg & 0x400) ? "Yes" : "No"); + + if (mdev == 1) { + ni_item_ctrl_reg(ctx, NI_PMA_LINK_STA0, ieee802_3_get_pcs_pma_link_status(&mdio_info, mdev)); + ni_item_ctrl_reg(ctx, NI_PMA_LINK_STA1, ieee802_3_get_pcs_pma_link_status(&mdio_info, mdev)); + ni_item_str(ctx, NI_PMA_SPEED, ieee802_3_get_pma_speed_string(&mdio_info)); + + ni_item_ctrl_reg(ctx, NI_PMA_TFAULT, reg & 0x800); + ni_item_ctrl_reg(ctx, NI_PMA_RFAULT, reg & 0x400); + } else { + ni_item_ctrl_reg(ctx, NI_PCS_LINK_STA0, ieee802_3_get_pcs_pma_link_status(&mdio_info, mdev)); + ni_item_ctrl_reg(ctx, NI_PCS_LINK_STA1, ieee802_3_get_pcs_pma_link_status(&mdio_info, mdev)); + ni_item_str(ctx, NI_PCS_SPEED, ieee802_3_get_pcs_speed_string(&mdio_info)); + + ni_item_ctrl_reg(ctx, NI_PCS_TFAULT, reg & 0x800); + ni_item_ctrl_reg(ctx, NI_PCS_RFAULT, reg & 0x400); + } } int pcspma_set_type(struct nc_mdio *mdio, int portaddr, struct eth_params *p) @@ -110,18 +120,22 @@ static inline uint32_t nc_mdio_read_dword(struct nc_mdio *mdio, int prtad, int d } struct cb_print_pma_pmd_type_priv { + struct ni_context *ctx; const char *active; }; -void print_pma_pmd_type(void *p, const char *str) +static void print_pma_pmd_type(void *p, const char *str) { struct cb_print_pma_pmd_type_priv *priv = p; - const char * active = strcmp(str, priv->active) ? str_active[0] : str_active[1]; + int active = !strcmp(str, priv->active); - printf(" * %s : %s\n", active, str); + ni_section(priv->ctx, NI_SEC_PMA_TYPES); + ni_item_ctrl_reg(priv->ctx, NI_PMA_TYPES_ACTIVE, active); + ni_item_str(priv->ctx, NI_PMA_TYPES_NAME, str); + ni_endsection(priv->ctx, NI_SEC_PMA_TYPES); } -void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params *p) +void pcspma_print_status(struct ni_context *ctx, struct nc_mdio *mdio, int portaddr, struct eth_params *p) { uint32_t reg; uint32_t reg2; @@ -135,92 +149,90 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * struct mdio_if_info mdio_info = nfb_eth_create_mdio_info(mdio, portaddr); int pma_speed = ieee802_3_get_pma_speed_value(&mdio_info); - //printf("--------------------------------------- PMA %d regs ----\n", p->index); - printf("----------------------------------------- PMA regs ----\n"); - print_pcspma_common(mdio, portaddr, 1); + ni_section(ctx, NI_SEC_PMA); + print_pcspma_common(ctx, mdio, portaddr, 1); reg = nc_mdio_read(mdio, portaddr, 1, 7); active = ieee802_3_get_pma_pmd_type_string(&mdio_info); - printf("PMA type : %s\n", active); + ni_item_str(ctx, NI_PMA_TYPE, active); if (p->verbose) { struct cb_print_pma_pmd_type_priv cb_ppptp; const struct phy_feature_t *item; - printf("Supported PMA types ->\n"); - cb_ppptp.active = active; - ieee802_3_get_supported_pma_pmd_types_string(&mdio_info, print_pma_pmd_type, &cb_ppptp); + cb_ppptp.ctx = ctx; - printf("Supported PMA features ->\n"); + ni_list(ctx, NI_LIST_PMA_TYPES_AV); + ieee802_3_get_supported_pma_pmd_types_string(&mdio_info, print_pma_pmd_type, &cb_ppptp); + ni_endlist(ctx, NI_LIST_PMA_TYPES_AV); + ni_list(ctx, NI_LIST_PMA_FEATS_AV); for (item = pma_feature_table; item->name; item++) { if (item->ability_bit != -1) { reg = nc_mdio_read(mdio, portaddr, 1, item->ability_reg); } if (reg & (1 << item->ability_bit) || p->verbose > 1) { + ni_section(ctx, NI_SEC_PMA_FEAT); reg = nc_mdio_read(mdio, portaddr, 1, item->control_reg); - printf(" * %s : %s\n", str_active[reg & (1 << item->control_bit) ? 1 : 0], item->name); + ni_item_ctrl_reg(ctx, NI_PMA_FEAT_ACTIVE, reg & (1 << item->control_bit)); + ni_item_str(ctx, NI_PMA_FEAT_NAME, item->name); + ni_endsection(ctx, NI_SEC_PMA_FEAT); } } + ni_endlist(ctx, NI_LIST_PMA_FEATS_AV); + } + + ni_endsection(ctx, NI_SEC_PMA); + if (pma_speed < 200000) { /* RS-FEC Clause 91, 108 or 134 - RSFEC reg located in 1.200 - 1.300 */ /* RS-FEC registers */ fec_lines = ieee802_3_get_fec_lines(active); - if ((fec_lines > 0) && (pma_speed < 200000)) { /* RS-FEC Clause 91, 108 or 134 - RSFEC reg located in 1.200 - 1.300 */ + if (fec_lines > 0) { reg = nc_mdio_read_dword(mdio, portaddr, 1, 201); - printf("RS-FEC status : %s%s%s\n", -// reg & (1 << 0) ? "FEC bypass corection ability | " : "", -// reg & (1 << 1) ? "FEC bypass indication ability | " : "", - reg & (1 << 2) ? "RS-FEC high SER | " : "", - reg & (1 << 14) ? "RS-FEC lanes aligned | " : "", - reg & (1 << 15) ? "PCS lanes aligned | " : ""); - printf("RS-FEC corrected cws : %u\n", nc_mdio_read_dword(mdio, portaddr, 1, 202)); - printf("RS-FEC uncorrected cws : %u\n", nc_mdio_read_dword(mdio, portaddr, 1, 204)); - - printf("RS-FEC symbol errors ->\n"); + + ni_section(ctx, NI_SEC_RSFEC_STATUS); +// ni_item_ctrl_reg(ctx, NI_RSFEC_STATUS_BCA, reg & (1 << 0)); +// ni_item_ctrl_reg(ctx, NI_RSFEC_STATUS_BIA, reg & (1 << 1)); + ni_item_ctrl_reg(ctx, NI_RSFEC_STATUS_SER, reg & (1 << 2)); + ni_item_ctrl_reg(ctx, NI_RSFEC_STATUS_FLA, reg & (1 << 14)); + ni_item_ctrl_reg(ctx, NI_RSFEC_STATUS_PLA, reg & (1 << 15)); + + ni_item_int(ctx, NI_RSFEC_CORRECTED, nc_mdio_read_dword(mdio, portaddr, 1, 202)); + ni_item_int(ctx, NI_RSFEC_UNCORRECTED, nc_mdio_read_dword(mdio, portaddr, 1, 204)); + + ni_list(ctx, NI_LIST_RSFEC_SYM_ERR); for (i = 0; i < fec_lines; i++) { - printf(" * Lane %d : %u\n", i, nc_mdio_read_dword(mdio, portaddr, 1, 210 + i * 2)); + ni_item_int(ctx, NI_RSFEC_SYM_ERR_L, i); + ni_item_int(ctx, NI_RSFEC_SYM_ERR_V, nc_mdio_read_dword(mdio, portaddr, 1, 210 + i * 2)); } - printf("RS-FEC lane mapping :"); + ni_endlist(ctx, NI_LIST_RSFEC_SYM_ERR); + + ni_list(ctx, NI_LIST_RSFEC_LANE_MAP); reg = nc_mdio_read(mdio, portaddr, 1, 206); for (i = 0; i < fec_lines; i++) { - printf(" %d", ((reg >> (i*2)) & 0x3)); + ni_item_int(ctx, NI_RSFEC_LANE_MAP, ((reg >> (i*2)) & 0x3)); } - printf("\n"); + ni_endlist(ctx, NI_LIST_RSFEC_LANE_MAP); reg = nc_mdio_read(mdio, portaddr, 1, 201); - printf("RS-FEC AM lock :"); - for (i = 0; i < fec_lines; i++) { - printf((reg & (1 << (i + 8))) ? " L" : " X"); - } - printf("\n"); - } - /* RS-FEC integrated in PCS clause 119 (not bypassable) */ - if (pma_speed >= 200000) { - reg = nc_mdio_read_dword(mdio, portaddr, 3, 801); - printf("RS-FEC status : %s%s%s%s\n", - reg & (1 << 2) ? "RS-FEC high SER | " : "", - reg & (1 << 4) ? "RS-FEC degraded SER | " : "", - reg & (1 << 5) ? "Remote degraded SER | " : "", - reg & (1 << 6) ? "Local degraded SER" : ""); - printf("RS-FEC corrected cws : %u\n", nc_mdio_read_dword(mdio, portaddr, 3, 802)); - printf("RS-FEC uncorrected cws : %u\n", nc_mdio_read_dword(mdio, portaddr, 3, 804)); - - printf("RS-FEC symbol errors ->\n"); + ni_list(ctx, NI_LIST_RSFEC_AM_LOCK); for (i = 0; i < fec_lines; i++) { - printf(" * Lane %d : %u\n", i, nc_mdio_read_dword(mdio, portaddr, 3, 600 + i * 2)); + ni_item_ctrl_reg(ctx, NI_RSFEC_AM_LOCK, (reg & (1 << (i + 8)))); } + ni_endlist(ctx, NI_LIST_RSFEC_AM_LOCK); + + ni_endsection(ctx, NI_SEC_RSFEC_STATUS); } } - //printf("--------------------------------------- PCS %d regs ----\n", p->index); - printf("----------------------------------------- PCS regs ----\n"); - print_pcspma_common(mdio, portaddr, 3); + ni_section(ctx, NI_SEC_PCS); + print_pcspma_common(ctx, mdio, portaddr, 3); if (p->verbose) { const struct phy_feature_t *item; - printf("Supported PCS features ->\n"); + ni_list(ctx, NI_LIST_PCS_FEATS_AV); for (item = pcs_feature_table; item->name; item++) { if (item->ability_bit != -1) { @@ -229,51 +241,56 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * if (reg & (1 << item->ability_bit) || p->verbose > 1) { reg = nc_mdio_read(mdio, portaddr, 3, item->control_reg); - printf(" * %s : %s\n", str_active[reg & (1 << item->control_bit) ? 1 : 0], item->name); + ni_section(ctx, NI_SEC_PMA_FEAT); + ni_item_ctrl_reg(ctx, NI_PMA_FEAT_ACTIVE, reg & (1 << item->control_bit)); + ni_item_str(ctx, NI_PMA_FEAT_NAME, item->name); + ni_endsection(ctx, NI_SEC_PMA_FEAT); } } + ni_endlist(ctx, NI_LIST_PCS_FEATS_AV); + // PCS status reg 1 -> 32 reg = nc_mdio_read(mdio, portaddr, 3, 32); // PCS status reg 2 -> 33 reg2 = nc_mdio_read(mdio, portaddr, 3, 33); - if (pma_speed <= 100000) /* Block lock not defined above 100G */ - printf("Global Block Lock : %s | %s\n", - (reg & 0x0001) ? "Yes" : "No", - (reg2 & 0x8000) ? "Yes" : "No"); - printf("Global High BER : %s | %s\n", - (reg & 0x0002) ? "Yes" : "No", - (reg2 & 0x4000) ? "Yes":"No"); + if (pma_speed <= 100000) { /* Block lock not defined above 100G */ + ni_item_ctrl_reg(ctx, NI_PCS_GLB_BLK_LCK0, reg & 0x0001); + ni_item_ctrl_reg(ctx, NI_PCS_GLB_BLK_LCK1, reg & 0x8000); + } + ni_item_ctrl_reg(ctx, NI_PCS_GLB_HIGH_BER0, reg & 0x0002); + ni_item_ctrl_reg(ctx, NI_PCS_GLB_HIGH_BER1, reg & 0x4000); + // BER counter register -> 44 reg = nc_mdio_read(mdio, portaddr, 3, 44); low_bits = ((reg2 >> 8) & 0x003F); - printf("BER counter : %u\n", - ((reg & 0xFFFF) << 6) | low_bits); + ni_item_int(ctx, NI_PCS_BER_CNT, ((reg & 0xFFFF) << 6) | low_bits); + low_bits = (reg2 & 0x00FF); // Error blocks register -> 45 reg = nc_mdio_read(mdio, portaddr, 3, 45); - printf("Errored blocks : %u\n", - ((reg & 0x3FFF) << 8) | low_bits); + ni_item_int(ctx, NI_PCS_BLK_ERR, ((reg & 0x3FFF) << 8) | low_bits); lines = ieee802_3_get_pcs_lines(&mdio_info); if (lines > 1) { reg = nc_mdio_read(mdio, portaddr, 3, 50); - printf("PCS lanes aligned : %s\n", - (reg & 0x1000) ? "Yes" : "No"); - printf("\nBlock status for lines :"); + ni_item_ctrl_reg(ctx, NI_PCS_LANES_ALIGNED, reg & 0x1000); + + ni_list(ctx, NI_LIST_PCS_BLK_LCKS); // Block status register first half (8 lines) -> 50 // second half (12 lines) -> 51 // total 20 lines (max for 100G) - for (i = 0, j =0; i < lines; i++) { + for (i = 0, j = 0; i < lines; i++) { if (i == 8) { reg = nc_mdio_read(mdio, portaddr, 3, 51); j = 0; } - printf((reg & (1 << j)) ? " L" : " X"); + ni_item_ctrl_reg(ctx, NI_PCS_BLK_LCK, (reg & (1 << j))); j++; } + ni_endlist(ctx, NI_LIST_PCS_BLK_LCKS); - printf("\nAM lock :"); + ni_list(ctx, NI_LIST_AM_LCKS); // AM lock register first half (8 lines) -> 52 // second half (12 lines) -> 53 reg = nc_mdio_read(mdio, portaddr, 3, 52); @@ -282,39 +299,64 @@ void pcspma_print_status(struct nc_mdio *mdio, int portaddr, struct eth_params * reg = nc_mdio_read(mdio, portaddr, 3, 53); j = 0; } - printf((reg & (1 << j)) ? " L" : " X"); + ni_item_ctrl_reg(ctx, NI_PCS_AM_LCK, (reg & (1 << j))); j++; } + ni_endlist(ctx, NI_LIST_AM_LCKS); - printf("\nLane mapping \n"); + ni_list(ctx, NI_LIST_LANE_MAP); if (!nc_mdio_pcs_lane_map_valid(mdio)) { // Intel PCS/PMAs are not reporting PCS lane mapping when the RS-FEC is active for (i = 0; i < lines; i++) { - printf(" U"); + ni_item_ctrl_reg(ctx, NI_PCS_LANE_MAP, -1); } } else { // Lane mapping register for each line starting from -> 400 to 420 for (i = 0; i < lines; i++) { - printf(" %2d", nc_mdio_read(mdio, portaddr, 3, 400 + i) & 0x3F); + ni_item_ctrl_reg(ctx, NI_PCS_LANE_MAP, nc_mdio_read(mdio, portaddr, 3, 400 + i) & 0x3F); } } + ni_endlist(ctx, NI_LIST_LANE_MAP); // BIP counters not defined for speeds above 100 if (pma_speed <= 100000) { - printf("\nBIP error counter\n"); + ni_list(ctx, NI_LIST_BIP_ERR_CNT); // BIP counter register for each line starting from -> 200 to 220 for (i = 0; i < lines; i++) { - if (i == 10) - printf("\n"); - printf(" %5d", nc_mdio_read(mdio, portaddr, 3, 200 + i)); + ni_item_int(ctx, NI_BIP_ERR_CNT, nc_mdio_read(mdio, portaddr, 3, 200 + i)); } + ni_endlist(ctx, NI_LIST_BIP_ERR_CNT); + } + } + + /* RS-FEC integrated in PCS clause 119 (not bypassable) */ + if (pma_speed >= 200000) { + fec_lines = ieee802_3_get_fec_lines(active); + reg = nc_mdio_read_dword(mdio, portaddr, 3, 801); + + ni_section(ctx, NI_SEC_RSFEC119_STATUS); + ni_item_ctrl_reg(ctx, NI_RSFEC_STATUS_SER, reg & (1 << 2)); + ni_item_ctrl_reg(ctx, NI_RSFEC_STATUS_DSER, reg & (1 << 4)); + ni_item_ctrl_reg(ctx, NI_RSFEC_STATUS_RDSER, reg & (1 << 5)); + ni_item_ctrl_reg(ctx, NI_RSFEC_STATUS_LDSER, reg & (1 << 6)); + + ni_item_int(ctx, NI_RSFEC_CORRECTED, nc_mdio_read_dword(mdio, portaddr, 3, 802)); + ni_item_int(ctx, NI_RSFEC_UNCORRECTED, nc_mdio_read_dword(mdio, portaddr, 3, 804)); + + ni_list(ctx, NI_LIST_RSFEC_SYM_ERR); + for (i = 0; i < fec_lines; i++) { + ni_item_int(ctx, NI_RSFEC_SYM_ERR_L, i); + ni_item_int(ctx, NI_RSFEC_SYM_ERR_V, nc_mdio_read_dword(mdio, portaddr, 3, 600 + i * 2)); } - printf("\n"); + ni_endlist(ctx, NI_LIST_RSFEC_SYM_ERR); + + ni_endsection(ctx, NI_SEC_RSFEC119_STATUS); } } + ni_endsection(ctx, NI_SEC_PCS); } -int pcspma_execute_operation(struct nfb_device *dev, int eth_node, struct eth_params *p) +int pcspma_execute_operation(struct ni_context *ctx, struct nfb_device *dev, int eth_node, struct eth_params *p) { int ret = 0; @@ -345,10 +387,10 @@ int pcspma_execute_operation(struct nfb_device *dev, int eth_node, struct eth_pa switch (p->command) { case CMD_PRINT_SPEED: - pcspma_print_speed(mdio, portaddr, 1); + pcspma_print_speed(ctx, mdio, portaddr, 1); break; case CMD_PRINT_STATUS: - pcspma_print_status(mdio, portaddr, p); + pcspma_print_status(ctx, mdio, portaddr, p); break; case CMD_SET_PMA_TYPE: ret = pcspma_set_type(mdio, portaddr, p); diff --git a/tools/eth/qsfpp.c b/tools/eth/qsfpp.c index 29ce6d03..472b308c 100644 --- a/tools/eth/qsfpp.c +++ b/tools/eth/qsfpp.c @@ -12,8 +12,8 @@ #include #include -#include -#include + +#include "eth.h" /* I2C registers addresses */ #define SFF8636_IDENTIFIER 0 @@ -69,24 +69,24 @@ static inline uint16_t qsfp_i2c_read16(struct nc_i2c_ctrl *ctrl, uint8_t reg) * * @param reg Register */ -void qsfpp_print_compliance(uint32_t reg) +const char *qsfpp_get_compliance(uint32_t reg) { if (reg & 0x1) { - printf("40G Active Cable (XLPPI)\n"); + return "40G Active Cable (XLPPI)"; } else if (reg & 0x2) { - printf("40GBASE-LR4\n"); + return "40GBASE-LR4"; } else if (reg & 0x4) { - printf("40GBASE-SR4\n"); + return "40GBASE-SR4"; } else if (reg & 0x8) { - printf("40GBASE-CR4\n"); + return "40GBASE-CR4"; } else if (reg & 0x10) { - printf("10GBASE-SR\n"); + return "10GBASE-SR"; } else if (reg & 0x20) { - printf("10GBASE-LR\n"); + return "10GBASE-LR"; } else if (reg & 0x40) { - printf("10GBASE-LRM\n"); + return "10GBASE-LRM"; } else { - printf("Reserved\n"); + return "Reserved"; } } @@ -295,9 +295,8 @@ const char *cmis_mit(uint8_t reg) * @param count Maximal number of characters */ -int qsfp_i2c_text_print(struct nc_i2c_ctrl *i2c, uint8_t reg, unsigned count) +int qsfp_i2c_text_print(FILE *fout, struct nc_i2c_ctrl *i2c, uint8_t reg, unsigned count) { - FILE *fout = stdout; /* INFO: Some modules doesn't supports continuous reads, disable burst mode */ const unsigned BURST = 1; char text[BURST + 1]; @@ -335,6 +334,40 @@ int qsfp_i2c_text_print(struct nc_i2c_ctrl *i2c, uint8_t reg, unsigned count) return rcnt; } +int _print_qsfp_i2c_text(FILE*out, struct nc_i2c_ctrl*ctrl, int item, int json) +{ + int ret = 0; + int base = 0; + int size = 0; + switch (item) { + case NI_SFF8636_VNDR_NAME: size = 16; base = SFF8636_VENDOR_NAME; break; + case NI_SFF8636_VNDR_SN: size = 16; base = SFF8636_VENDOR_SN; break; + case NI_SFF8636_VNDR_PN: size = 16; base = SFF8636_VENDOR_PN; break; + case NI_SFF8636_REVISION: size = 2; base = SFF8636_REVISION; break; + case NI_TRN_CMIS_VNDR_NAME: size = 16; base = CMIS_VENDOR_NAME; break; + case NI_TRN_CMIS_VNDR_SN: size = 16; base = CMIS_VENDOR_SN; break; + case NI_TRN_CMIS_VNDR_PN: size = 16; base = CMIS_VENDOR_PN; break; + } + if (size == 0) + return 0; + ret += fprintf(out, json ? "\"": ""); + ret += qsfp_i2c_text_print(out, ctrl, base, size); + ret += fprintf(out, json ? "\"": ""); + return ret; +} + +int print_json_qsfp_i2c_text(void *priv, int item, struct nc_i2c_ctrl *ctrl) +{ + struct ni_json_cbp *p = priv; + return _print_qsfp_i2c_text(p->f, ctrl, item, 1); +} + +int print_user_qsfp_i2c_text(void *priv, int item, struct nc_i2c_ctrl *ctrl) +{ + struct ni_user_cbp *p = priv; + return _print_qsfp_i2c_text(p->f, ctrl, item, 0); +} + #if 0 /** * \brief Fallback mode - determine plugged transceiver by reading first register @@ -354,8 +387,8 @@ int qsfp_present(struct nc_i2c_ctrl *i2c, int mdev __attribute__((unused)) ) } #endif -void sff8636_print(struct nc_i2c_ctrl *ctrl); -void cmis_print(struct nc_i2c_ctrl *ctrl); +void sff8636_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl); +void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl); struct nc_i2c_ctrl *qsfpp_i2c_open(struct nfb_device *dev, int nodeoffset, int node_params) { @@ -392,7 +425,7 @@ struct nc_i2c_ctrl *qsfpp_i2c_open(struct nfb_device *dev, int nodeoffset, int n * @param ifc Interface device * @param space Interface space */ -void qsfpp_print(struct nfb_device *dev, int nodeoffset, int node_params) +void qsfpp_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int node_params) { uint8_t reg = 0xFF; struct nc_i2c_ctrl *ctrl; @@ -404,19 +437,20 @@ void qsfpp_print(struct nfb_device *dev, int nodeoffset, int node_params) } nc_i2c_read_reg(ctrl, SFF8636_IDENTIFIER, ®, 1); - printf("Module identifier : %s\n", qsfp_get_identifier(reg)); + ni_item_str(ctx, NI_MOD_IDENT, qsfp_get_identifier(reg)); if (reg == 0x18) { - cmis_print(ctrl); + cmis_print(ctx, ctrl); } else { - sff8636_print(ctrl); + sff8636_print(ctx, ctrl); } nc_i2c_close(ctrl); } -void sff8636_print(struct nc_i2c_ctrl *ctrl) +void sff8636_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl) { + const char *text; const int CHANNELS = 4; uint8_t i; @@ -424,6 +458,7 @@ void sff8636_print(struct nc_i2c_ctrl *ctrl) uint16_t reg16 = 0; int retries = 0; int ret; + double pwr; /* Wait for Data Ready (max 2 sec according specs) */ /* TODO: this should be done in qsfp_i2c_common functions */ @@ -433,100 +468,95 @@ void sff8636_print(struct nc_i2c_ctrl *ctrl) } while (ret == 1 && ((reg & 0x01) == 0x1) && (++retries < 10000)); reg16 = qsfp_i2c_read16(ctrl, SFF8636_TEMPERATURE); - printf("Temperature : %.2f C\n", ((float) reg16) / 256); - - printf("Vendor name : "); - qsfp_i2c_text_print(ctrl, SFF8636_VENDOR_NAME, 16); - printf("Vendor serial number : "); - qsfp_i2c_text_print(ctrl, SFF8636_VENDOR_SN, 16); - - printf("Vendor PN : "); - qsfp_i2c_text_print(ctrl, SFF8636_VENDOR_PN, 16); + ni_item_double(ctx, NI_SFF8636_TEMP, ((float) reg16) / 256); + ni_item_qsfp_i2c_text(ctx, NI_SFF8636_VNDR_NAME, ctrl); + ni_item_qsfp_i2c_text(ctx, NI_SFF8636_VNDR_SN, ctrl); + ni_item_qsfp_i2c_text(ctx, NI_SFF8636_VNDR_PN, ctrl); nc_i2c_read_reg(ctrl, SFF8636_COMPLIANCE, ®, 1); - printf("Compliance : "); if (reg & 0x80) { nc_i2c_read_reg(ctrl, SFF8636_LINK_CODES, ®, 1); - printf("%s\n", sff8024_get_ext_compliance(reg)); + text = sff8024_get_ext_compliance(reg); } else { - qsfpp_print_compliance(reg); + text = qsfpp_get_compliance(reg); } + ni_item_str(ctx, NI_TRN_COMPLIANCE, text); nc_i2c_read_reg(ctrl, SFF8636_CONNECTOR, ®, 1); - printf("Connector : %s\n", sff8024_get_connector(reg)); - - printf("Revision : "); - qsfp_i2c_text_print(ctrl, SFF8636_REVISION, 2); + ni_item_str(ctx, NI_TRN_CONNECTOR, sff8024_get_connector(reg)); + ni_item_qsfp_i2c_text(ctx, NI_SFF8636_REVISION, ctrl); reg16 = qsfp_i2c_read16(ctrl, SFF8636_WAVELENGTH); - printf("Wavelength : %.2f nm ", ((float) reg16) / 20); + ni_item_double(ctx, NI_SFF8636_WL, ((float) reg16) / 20); reg16 = qsfp_i2c_read16(ctrl, SFF8636_WAVELENGTH_TOL); - printf("+- %.2f nm\n", ((float) reg16) / 200); + ni_item_double(ctx, NI_SFF8636_WL_TOL, ((float) reg16) / 200); - printf("\nRX input power\n"); + ni_list(ctx, NI_LIST_TRN_RX_IN_PWR); for (i = 0; i < CHANNELS; i++) { reg16 = qsfp_i2c_read16(ctrl, SFF8636_RX_INPUT_POWER + i * 2); - printf(" * Lane %d : %.2f %s (%.2f dBm)\n", i + 1, - (reg16 < 10000) ? ((float)reg16) / 10 : ((float) reg16) / 10000 , - (reg16 < 10000) ? "uW" : "mW", 10 * log10(((float) reg16) / 10000)); + pwr = ((float)reg16) / 10000000; + + ni_item_int(ctx, NI_TRANS_RX_IN_PWR_L, i + 1); + ni_item_pwr(ctx, NI_TRANS_RX_IN_PWR_V, pwr); } + ni_endlist(ctx, NI_LIST_TRN_RX_IN_PWR); nc_i2c_read_reg(ctrl, SFF8636_STXDISABLE, ®, 1); - printf("\nSoftware TX disable\n"); + ni_list(ctx, NI_LIST_TRN_STX_DIS); for (i = 0; i < CHANNELS; i++) { - printf(" * Lane %d : %sactive\n", i + 1, (reg & (1 << i)) ? "" : "in"); + ni_item_int(ctx, NI_TRANS_STX_DIS_L, i + 1); + ni_item_ctrl_reg(ctx, NI_TRANS_STX_DIS_V, (reg & (1 << i))); } + ni_endlist(ctx, NI_LIST_TRN_STX_DIS); } -void cmis_print(struct nc_i2c_ctrl *ctrl) +void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl) { int channel_cnt = 8; uint8_t i; uint8_t reg = 0; uint16_t reg16 = 0; + double pwr; nc_i2c_write_reg(ctrl, CMIS_PAGE_SELECT, ®, 1); nc_i2c_read_reg(ctrl, CMIS_REVISION, ®, 1); - printf("CMIS version : %d.%d\n", reg >> 4, reg & 0xF); + ni_item_int(ctx, NI_TRN_CMIS_VER_MAJ, reg >> 4); + ni_item_int(ctx, NI_TRN_CMIS_VER_MIN, reg & 0xF); nc_i2c_read_reg(ctrl, CMIS_GLOBAL_STATUS, ®, 1); - printf("Module state : %s\n", cmis_module_state((reg >> 1) & 0x7)); + ni_item_str(ctx, NI_TRN_CMIS_GLB_STAT, cmis_module_state((reg >> 1) & 0x7)); reg16 = qsfp_i2c_read16(ctrl, CMIS_TEMPERATURE); - printf("Temperature : %.2f C\n", ((float) reg16) / 256); - - printf("Vendor name : "); - qsfp_i2c_text_print(ctrl, CMIS_VENDOR_NAME, 16); - - printf("Vendor serial number : "); - qsfp_i2c_text_print(ctrl, CMIS_VENDOR_SN, 16); + ni_item_double(ctx, NI_SFF8636_TEMP, ((float) reg16) / 256); - printf("Vendor PN : "); - qsfp_i2c_text_print(ctrl, CMIS_VENDOR_PN, 16); + ni_item_qsfp_i2c_text(ctx, NI_TRN_CMIS_VNDR_NAME, ctrl); + ni_item_qsfp_i2c_text(ctx, NI_TRN_CMIS_VNDR_SN, ctrl); + ni_item_qsfp_i2c_text(ctx, NI_TRN_CMIS_VNDR_PN, ctrl); nc_i2c_read_reg(ctrl, CMIS_MEDIA_TYPE, ®, 1); - printf("Media Type : %s\n", cmis_mtf(reg)); + ni_item_str(ctx, NI_TRN_CMIS_MED_T, cmis_mtf(reg)); nc_i2c_read_reg(ctrl, CMIS_MEDIA_INTERFACE_T, ®, 1); - printf("Media Interface Technology : %s\n", cmis_mit(reg)); + ni_item_str(ctx, NI_TRN_CMIS_IFC_T, cmis_mit(reg)); if (nc_i2c_read_reg(ctrl, CMIS_HOST_LANE_COUNT, ®, 1) == 1) { channel_cnt = reg & 0x0F; } - printf("RX input power\n"); + ni_list(ctx, NI_LIST_TRN_RX_IN_PWR); for (i = 0; i < channel_cnt; i++) { reg = 0x11; nc_i2c_write_reg(ctrl, CMIS_PAGE_SELECT, ®, 1); reg16 = qsfp_i2c_read16(ctrl, CMIS_OPTICAL_POWER_RX + i * 2); - printf(" * Lane %d : %.2f %s (%.2f dBm)\n", i + 1, - (reg16 < 10000) ? ((float)reg16) / 10 : ((float) reg16) / 10000 , - (reg16 < 10000) ? "uW" : "mW", 10 * log10(((float) reg16) / 10000)); + pwr = ((float)reg16) / 10000000; + ni_item_int(ctx, NI_TRANS_RX_IN_PWR_L, i + 1); + ni_item_pwr(ctx, NI_TRANS_RX_IN_PWR_V, pwr); } + ni_endlist(ctx, NI_LIST_TRN_RX_IN_PWR); } /** diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index 5c724bc1..7e6ecf96 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -17,10 +17,9 @@ #define CNT_FMT "20llu" -void rxmac_print_status(struct nc_rxmac *rxmac, struct eth_params *p) +void rxmac_print_status(struct ni_context *ctx, struct nc_rxmac *rxmac, struct eth_params *p) { int ret; - const char *text = NULL; struct nc_rxmac_status s; struct nc_rxmac_counters c; @@ -32,60 +31,41 @@ void rxmac_print_status(struct nc_rxmac *rxmac, struct eth_params *p) if (ret) return; - printf("------------------------------------- RXMAC Status ----\n"); -#if 0 - switch (s.speed) { - case MAC_SPEED_10G: text = "10 Gb/s"; break; - case MAC_SPEED_40G: text = "40 Gb/s"; break; - case MAC_SPEED_100G: text = "100 Gb/s"; break; - default: text = "Unknown"; break; + ni_section(ctx, NI_SEC_RXMAC); + + ni_item_ctrl_reg(ctx, NI_RXM_ENABLED, s.enabled); + ni_item_ctrl_reg(ctx, NI_RXM_LINK, s.link_up); + ni_item_ctrl_reg(ctx, NI_RXM_HFIFO_OVF, s.overflow); + + ni_section(ctx, NI_SEC_RXMAC_S); + ni_item_uint64_t(ctx, NI_RXM_RECV_O, c.cnt_octets); + ni_item_uint64_t(ctx, NI_RXM_PROCESSED, c.cnt_total); + ni_item_uint64_t(ctx, NI_RXM_RECEIVED, c.cnt_received); + ni_item_uint64_t(ctx, NI_RXM_ERRONEOUS, c.cnt_erroneous); + ni_item_uint64_t(ctx, NI_RXM_OVERFLOWED, c.cnt_overflowed); + ni_endsection(ctx, NI_SEC_RXMAC_S); + + if (p->verbose) { + ni_section(ctx, NI_SEC_RXMAC_CONF); + ni_item_uint64_tx(ctx, NI_RXM_ERR_MASK_REG, s.error_mask); + ni_item_ctrl_reg(ctx, NI_RXM_ERR_FRAME, s.error_mask & 0x1); + ni_item_ctrl_reg(ctx, NI_RXM_ERR_CRC, s.error_mask & 0x2); + ni_item_ctrl_reg(ctx, NI_RXM_ERR_MIN_LEN, s.error_mask & 0x4); + ni_item_uint64_t(ctx, NI_RXM_MIN_LEN, s.frame_length_min); + ni_item_ctrl_reg(ctx, NI_RXM_ERR_MAX_LEN, s.error_mask & 0x8); + ni_item_uint64_t(ctx, NI_RXM_MAX_LEN, s.frame_length_max); + if (s.frame_length_max_capable) + ni_item_uint64_t(ctx, NI_RXM_MAX_LEN_CAP, s.frame_length_max_capable); + ni_item_ctrl_reg(ctx, NI_RXM_ERR_MAC_CHECK, s.error_mask & 0x10); + ni_item_ctrl_reg(ctx, NI_RXM_ERR_MAC_MODE, s.mac_filter); + ni_item_uint64_t(ctx, NI_RXM_MAC_MAX_COUNT, s.mac_addr_count); + + ni_endsection(ctx, NI_SEC_RXMAC_CONF); } - printf("RXMAC speed : %s\n", text); -#endif - printf("RXMAC status : %s\n", s.enabled ? "ENABLED" : "DISABLED"); - printf("Link status : %s\n", s.link_up ? "UP" : "DOWN"); - printf("HFIFO overflow occurred : %s\n", s.overflow ? "True" : "False"); - printf("Received octets : %" CNT_FMT "\n", c.cnt_octets); - printf("Processed : %" CNT_FMT "\n", c.cnt_total); - printf("Received : %" CNT_FMT "\n", c.cnt_received); - printf("Erroneous : %" CNT_FMT "\n", c.cnt_erroneous); - printf("Overflowed : %" CNT_FMT "\n", c.cnt_overflowed); - - if (!p->verbose) - return; - - printf("------------------------------ RXMAC Configuration ----\n"); - printf("Error mask register : 0x%02x\n", s.error_mask); - printf(" * Frame error from MII [0]: %s\n", (s.error_mask & 0x00000001) ? "enabled" : "disabled"); - printf(" * CRC check [1]: %s\n", (s.error_mask & 0x00000002) ? "enabled" : "disabled"); - printf(" * Minimum frame length [2]: %s\n" - " * length : %d B\n", - (s.error_mask & 0x00000004) ? "enabled" : "disabled", - s.frame_length_min); - printf(" * MTU frame length [3]: %s\n" - " * length : %d B", - (s.error_mask & 0x00000008) ? "enabled" : "disabled", - s.frame_length_max); - - if (s.frame_length_max_capable == 0) { - printf(" (max unknown)\n"); - } else { - printf(" (max %d B)\n", s.frame_length_max_capable); - } - - switch (s.mac_filter) { - case RXMAC_MAC_FILTER_PROMISCUOUS: text = "Promiscuous mode"; break; - case RXMAC_MAC_FILTER_TABLE: text = "Filter by MAC address table"; break; - case RXMAC_MAC_FILTER_TABLE_BCAST: text = "Filter by MAC address table, allow broadcast"; break; - case RXMAC_MAC_FILTER_TABLE_BCAST_MCAST:text = "Filter by MAC address table, allow broadcast + multicast"; break; - } - printf(" * MAC address check [4]: %s\n" - " * mode : %s\n", - (s.error_mask & 0x00000010) ? "enabled" : "disabled", text); - printf("MAC address table size : %d\n", s.mac_addr_count); + ni_endsection(ctx, NI_SEC_RXMAC); } -void rxmac_print_ether_stats(struct nc_rxmac *rxmac) +void rxmac_print_ether_stats(struct ni_context *ctx, struct nc_rxmac *rxmac) { int ret; struct nc_rxmac_etherstats s; @@ -96,24 +76,25 @@ void rxmac_print_ether_stats(struct nc_rxmac *rxmac) return; } - printf("---------------------------- RXMAC etherStatsTable ----\n"); - printf("etherStatsOctets : %llu\n", s.octets); - printf("etherStatsPkts : %llu\n", s.pkts); - printf("etherStatsBroadcastPkts : %llu\n", s.broadcastPkts); - printf("etherStatsMulticastPkts : %llu\n", s.multicastPkts); - printf("etherStatsCRCAlignErrors : %llu\n", s.CRCAlignErrors); - printf("etherStatsUndersizePkts : %llu\n", s.undersizePkts); - printf("etherStatsOversizePkts : %llu\n", s.oversizePkts); - printf("etherStatsFragments : %llu\n", s.fragments); - printf("etherStatsJabbers : %llu\n", s.jabbers); - printf("etherStatsPkts64Octets : %llu\n", s.pkts64Octets); - printf("etherStatsPkts65to127Octets : %llu\n", s.pkts65to127Octets); - printf("etherStatsPkts128to255Octets : %llu\n", s.pkts128to255Octets); - printf("etherStatsPkts256to511Octets : %llu\n", s.pkts256to511Octets); - printf("etherStatsPkts512to1023Octets : %llu\n", s.pkts512to1023Octets); - printf("etherStatsPkts1024to1518Octets: %llu\n", s.pkts1024to1518Octets); - printf("underMinPkts : %llu\n", s.underMinPkts); - printf("overMaxPkts : %llu\n", s.overMaxPkts); + ni_section(ctx, NI_SEC_RXMAC_ES); + ni_item_uint64_t(ctx, NI_RXM_ES_OCTS, s.octets); + ni_item_uint64_t(ctx, NI_RXM_ES_PKTS, s.pkts); + ni_item_uint64_t(ctx, NI_RXM_ES_BCST, s.broadcastPkts); + ni_item_uint64_t(ctx, NI_RXM_ES_MCST, s.multicastPkts); + ni_item_uint64_t(ctx, NI_RXM_ES_CRCE, s.CRCAlignErrors); + ni_item_uint64_t(ctx, NI_RXM_ES_UNDR, s.undersizePkts); + ni_item_uint64_t(ctx, NI_RXM_ES_OVER, s.oversizePkts); + ni_item_uint64_t(ctx, NI_RXM_ES_FRAG, s.fragments); + ni_item_uint64_t(ctx, NI_RXM_ES_JABB, s.jabbers); + ni_item_uint64_t(ctx, NI_RXM_ES_64, s.pkts64Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_65_127, s.pkts65to127Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_128_255, s.pkts128to255Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_256_511, s.pkts256to511Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_512_1023, s.pkts512to1023Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_1024_1518, s.pkts1024to1518Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_UNDR_SET, s.underMinPkts); + ni_item_uint64_t(ctx, NI_RXM_ES_OVER_SET, s.overMaxPkts); + ni_endsection(ctx, NI_SEC_RXMAC_ES); } int clear_mac_addresses(struct nc_rxmac *rxmac) @@ -214,15 +195,15 @@ int remove_mac_address(struct nc_rxmac *rxmac, unsigned long long mac_address) return 0; } -int rxmac_execute_operation(struct nc_rxmac *rxmac, struct eth_params *p) +int rxmac_execute_operation(struct ni_context *ctx, struct nc_rxmac *rxmac, struct eth_params *p) { int ret = 0; switch (p->command) { case CMD_PRINT_STATUS: - rxmac_print_status(rxmac, p); + rxmac_print_status(ctx, rxmac, p); if (p->ether_stats) - rxmac_print_ether_stats(rxmac); + rxmac_print_ether_stats(ctx, rxmac); break; case CMD_RESET: nc_rxmac_reset_counters(rxmac); diff --git a/tools/eth/transceiver.c b/tools/eth/transceiver.c index 70bc1e28..6c0a568e 100644 --- a/tools/eth/transceiver.c +++ b/tools/eth/transceiver.c @@ -19,12 +19,12 @@ #include "eth.h" -void qsfpp_print(struct nfb_device *dev, int nodeoffset, int control_params_node); -void cfp2_print(struct nfb_device *dev, int nodeoffset, int control_params_node); +void qsfpp_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node); +void cfp2_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node); int qsfpp_stxdisable(struct nfb_device *dev, int nodeoffset, int node_params, int disable, int channels); -typedef void transc_print_t(struct nfb_device *dev, int nodeoffset, int control_params_node); +typedef void transc_print_t(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node); typedef int transc_plug_t(struct nfb_device *dev, int nodeoffset); struct transceiver_t { @@ -58,7 +58,7 @@ int transceiver_is_present(struct nfb_device *dev, int node) return ret; } -void transceiver_print_short_info(struct nfb_device *dev, int node, struct eth_params *p) +void transceiver_print_short_info(struct ni_context *ctx, struct nfb_device *dev, int node, struct eth_params *p) { int node_transceiver_by_phandle; int node_transceiver; @@ -84,24 +84,24 @@ void transceiver_print_short_info(struct nfb_device *dev, int node, struct eth_p if (proplen < 0) prop = "Unknown"; - printf("Transceiver status : %s\n", - (present < 0 ? "Unknown" : - (present > 0 ? "OK" : "Not plugged"))); + if (present < 0) + ni_item_str(ctx, NI_TRANS_PRSNT_UNK, "Unknown"); + else + ni_item_ctrl_reg(ctx, NI_TRANS_PRSNT, present); - printf("Transceiver cage : %s-%d\n", prop, index); + ni_item_str(ctx, NI_TRANS_CAGE_TYPE, prop); + ni_item_int(ctx, NI_TRANS_CAGE_ID, index); node_params = fdt_subnode_offset(fdt, node, "pmd-params"); if (node_params >= 0 && p->verbose) { prop32 = fdt_getprop(fdt, node_params, "lines", &proplen); if (prop32) { - printf("Transceiver lane(s) : "); + ni_list(ctx, NI_LIST_TRN_LANES); while (proplen > 0) { - printf("%d", fdt32_to_cpu(*prop32)); + ni_item_int(ctx, NI_TRANS_LANE, fdt32_to_cpu(*prop32)); proplen -= sizeof(*prop32); prop32++; - if (proplen) - printf("|"); } - printf("\n"); + ni_endlist(ctx, NI_LIST_TRN_LANES); } } break; @@ -110,14 +110,13 @@ void transceiver_print_short_info(struct nfb_device *dev, int node, struct eth_p } } -int transceiver_print(struct nfb_device *dev, int node_transceiver, int index) +int transceiver_print(struct ni_context *ctx, struct nfb_device *dev, int node_transceiver, int index) { const struct transceiver_t *transceiver; const char *property; int proplen; int present; const void *fdt; - unsigned i; fdt = nfb_get_fdt(dev); @@ -132,14 +131,14 @@ int transceiver_print(struct nfb_device *dev, int node_transceiver, int index) transceiver++; } - for (i = 0; i < 47 - strlen(property); i++) - printf("-"); - printf(" %s-%d ----\n", property, index++); + ni_item_str(ctx, NI_TRN_NAME, property); + ni_item_int(ctx, NI_TRN_INDEX, index); present = transceiver_is_present(dev, node_transceiver); - printf("Transceiver status : %s\n", - (present < 0 ? "Unknown" : - (present > 0 ? "OK" : "Not plugged"))); + if (present < 0) + ni_item_str(ctx, NI_TRANS_PRSNT_UNK, "Unknown"); + else + ni_item_ctrl_reg(ctx, NI_TRANS_PRSNT, present); if (transceiver->type == NULL || present == 0) return -ENODEV; @@ -150,7 +149,7 @@ int transceiver_print(struct nfb_device *dev, int node_transceiver, int index) return -EOPNOTSUPP; } - transceiver->print_status(dev, node_transceiver, fdt_subnode_offset(fdt, node_transceiver, "control-param")); + transceiver->print_status(ctx, dev, node_transceiver, fdt_subnode_offset(fdt, node_transceiver, "control-param")); return 0; } diff --git a/tools/eth/txmac.c b/tools/eth/txmac.c index 8f79ba47..f37d1a47 100644 --- a/tools/eth/txmac.c +++ b/tools/eth/txmac.c @@ -15,14 +15,9 @@ #include "eth.h" -#define CNT_FMT "20llu" - -void txmac_print_status(struct nc_txmac *txmac, struct eth_params *p __attribute__((unused)) ) +void txmac_print_status(struct ni_context *ctx, struct nc_txmac *txmac, struct eth_params *p __attribute__((unused)) ) { int ret; -#if 0 - const char *text; -#endif struct nc_txmac_status s; struct nc_txmac_counters c; @@ -34,28 +29,22 @@ void txmac_print_status(struct nc_txmac *txmac, struct eth_params *p __attribute if (ret) return; - printf("------------------------------------- TXMAC Status ----\n"); -#if 0 - switch (s.speed) { - case MAC_SPEED_10G: text = "10 Gb/s"; break; - case MAC_SPEED_40G: text = "40 Gb/s"; break; - case MAC_SPEED_100G: text = "100 Gb/s"; break; - default: text = "Unknown"; break; - } - printf("TXMAC speed : %s\n", text); -#endif - printf("TXMAC status : %s\n", s.enabled ? "ENABLED" : "DISABLED"); - printf("Transmitted octets : %" CNT_FMT "\n", c.cnt_octets); - printf("Processed : %" CNT_FMT "\n", c.cnt_total); - printf("Transmitted : %" CNT_FMT "\n", c.cnt_sent); - printf("Erroneous : %" CNT_FMT "\n", c.cnt_erroneous); + ni_section(ctx, NI_SEC_TXMAC); + ni_item_ctrl_reg(ctx, NI_TXM_ENABLED, s.enabled); + ni_section(ctx, NI_SEC_TXMAC_S); + ni_item_uint64_t(ctx, NI_TXM_SENT_O, c.cnt_octets); + ni_item_uint64_t(ctx, NI_TXM_PROCESSED, c.cnt_total); + ni_item_uint64_t(ctx, NI_TXM_SENT, c.cnt_sent); + ni_item_uint64_t(ctx, NI_TXM_ERRONEOUS, c.cnt_erroneous); + ni_endsection(ctx, NI_SEC_TXMAC_S); + ni_endsection(ctx, NI_SEC_TXMAC); } -int txmac_execute_operation(struct nc_txmac *txmac, struct eth_params *p) +int txmac_execute_operation(struct ni_context *ctx, struct nc_txmac *txmac, struct eth_params *p) { switch (p->command) { case CMD_PRINT_STATUS: - txmac_print_status(txmac, p); + txmac_print_status(ctx, txmac, p); break; case CMD_RESET: nc_txmac_reset_counters(txmac); From 523fa07e4c0fd52833a5f523c3d707e627db1d71 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 12 May 2025 16:06:31 +0200 Subject: [PATCH 362/518] doc: describe JSON output --- doc/tools/nfb-dma.rst | 86 ++++++++++++++++++++ doc/tools/nfb-eth.rst | 174 +++++++++++++++++++++++++++++++++++++++++ doc/tools/nfb-info.rst | 80 +++++++++++++++++++ 3 files changed, 340 insertions(+) diff --git a/doc/tools/nfb-dma.rst b/doc/tools/nfb-dma.rst index e369b713..a26a300c 100644 --- a/doc/tools/nfb-dma.rst +++ b/doc/tools/nfb-dma.rst @@ -9,3 +9,89 @@ For the RX direction (C2H transfers) it is typically number of received and disc For the TX direction (H2C transfers) it is typically only number of transmitted packets and bytes. Verbose mode shows the extended info that includes SW/HW pointers and status information about queue. + +.. code-block:: python + + { + "rxq": [ + { + "id": 0, + "type": "CALYPTE", # DMA controller type (CALYPTE, NDP, SZE) + "pass": 0, + "pass_bytes": 0, # not present for type SZE + "drop": 0, + "drop_bytes": 0, # not present for type SZE + + # items below present only in verbose mode + "reg_control": 0, + "run": False, # controller is commanded to work + "reg_status": 0, + "running": False, # controler is working + + # items below present only in verbose mode for type CALYPTE or NDP + "sdp": 0, # software descriptor pointer + "hdp": 0, # hardware descriptor pointer + "mdp": 0, # mask for descriptor pointer + "desc_buffer_size": 0, # descriptor buffer size (in items) + "desc_free": 0, # free items in descriptor buffer + "shp": 0, # software header pointer + "hhp": 0, # hardware header pointer + "mhp": 0, # mask for header pointer + "hdr_buffer_size": 0, # header buffer size (in items) + "hdr_buffer_free": 0, # free items in header buffer + + # items below present only in verbose mode for type NDP + "timeout": 16384 + + # items below present only in verbose mode for type SZE + "pciep_mask": 0, + "vfid": 0, + "sw_ptr": 0, + "hw_ptr": 0, + "ptr_mask": 0, + "buffer_size": 0, + "timeout": 0, + "max_request_size": 0 + } + ], + "txq": [ + { + "id": 0, + "type": "CALYPTE", + "pass": 0, + "pass_bytes": 0, # not present for type SZE + "drop": 0, # present only for type CALYPTE + "drop_bytes": 0, # present only for type CALYPTE + + # items below present only in verbose mode + "reg_control": 0, + "run": False, + "reg_status": 0, + "running": False, + + # items below present only in verbose mode for type CALYPTE or NDP + "sdp": 0, + "hdp": 0, + "mdp": 8191, + "desc_buffer_size": 8192, + "desc_free": 0, + + # items below present only in verbose mode for type CALYPTE + "shp": 0, + "hhp": 0, + "mhp": 1023, + "hdr_buffer_size": 1024, + "hdr_buffer_free": 1023, + + # items below present only in verbose mode for type SZE + "pciep_mask": 0, + "vfid": 0, + "sw_ptr": 0, + "hw_ptr": 0, + "ptr_mask": 0, + "buffer_size": 0, + "timeout": 0, + "max_request_size": 0 + } + ] + } diff --git a/doc/tools/nfb-eth.rst b/doc/tools/nfb-eth.rst index 8b4d6c14..8ddf9e62 100644 --- a/doc/tools/nfb-eth.rst +++ b/doc/tools/nfb-eth.rst @@ -44,3 +44,177 @@ Transceiver section Prints transceiver information (if plugged) obtained from port management interface (MDIO or I2C), including vendor, compliance, temperature, signal strength and more. + + +JSON output +~~~~~~~~~~~ + +.. code-block:: python + + { + "eth": { # list of selected/all Ethernet channels + [ + "id": 1, # ID of this ethernet channel in firmware + #"speed": 100000, # speed (in Mbps) + "speed_str": "100 Gb/s", # speed (string) + "transceiver_id": 0, # ID of used transceiver (cage) + "transceiver_lanes": [ # list of electrical lane numbers used in transceiver for this Ethernet channel + 0, 1, 2, 3 + ], + + "rxmac": { # processing unit for incoming frames; only present for nfb-eth tool in RxMAC or MAC mode + "enabled": False, # receive enablement + "link_up": False, # link is estabilished for receive + "stats": { # base statistics + "total": 0, # total number of frames received from Ethernet (including bad frames) + "total_octets": 0, # total number of octets received from Ethernet (including bad frames) + "pass": 0, # number of frames passed to firmware application + "pass_octets": 0, # number of octets passed to firmware application + "drop": 0, # number of dropped frames (drop == total - pass) + "drop_disabled": 0, # number of frames dropped due to disabled RxMAC state + "drop_filtered": 0, # ... due to MAC address filter + "drop_overflow": 0, # ... due to backpressure from firmwarove application (incl. backpressure from DMA) + "drop_err": 0, # ... due to one or more errors (drop_err <= drop_err_len + drop_err_crc + drop_err_mii) + "drop_err_len": 0, # ... due to frame length out of configured range + "drop_err_crc": 0, # ... due to cyclic redundancy check error + "drop_err_mii": 0, # ... due to bad framing on MII + }, + "etherstats": { # extended stats based on RFC 1271; only present for nfb-eth tool in etherStats mode + "octets": 0, # = rxmac.stats.total_octets + "pkts": 0, # = rxmac.stats.total + "broadcast": 0, + "multicast": 0, + "crc_align_errors": 0, + "under64": 0, # RFC 1271 name: "etherStatsUndersize" + "over1518": 0, # RFC 1271 name: "etherStatsOversize" + "fragments": 0, + "jabbers": 0, + "pkts64octets": 0, + "pkts65to127octets": 0, + "pkts128to255octets": 0, + "pkts256to511octets": 0, + "pkts512to1023octets": 0, + "pkts1024to1518octets": 0, + "pkts1519to2047octets": 0, + "pkts2048to4095octets": 0, + "pkts4096to8191octets": 0, + "oversize": 0, # number of frames with length over last bin resolution (not RFC 1271 name "oversize") + "conf_undersize": 0, # number of frames shorter than minimal configured length (rxmac.config.min_length) + "conf_oversize": 0 # number of frames longer than maximal configured length (rxmac.config.max_length) + }, + "config": { + "err_mask_frame_err": True, # enable drop due to framing error + "err_mask_crc_check": True, # enable drop due to cyclic redundancy check error + "err_mask_min_length": True, # enable drop due to frame length shorter than minimal configured length + "err_mask_max_length": True, # enable drop due to frame length shorter than maximal configured length + "err_mask_mac_addr_check": True,# enable drop due to MAC address filter + "err_mask_mac_addr_mode": "promiscuous", # MAC address filter mode (promiscuous, normal, broadcast, multicast) + "cfg_min_length": 64, # configured minimal frame length + "cfg_max_length": 1526, # configured maximal frame length + "max_length_capable": 4096, # maximal frame length handled by this RxMAC (max_length_capable >= max_length) + "mac_addr_count": 16 # maximal number of configurable MAC addresses + } + }, + "txmac": { # processing unit for outgoing frames; only present for nfb-eth tool in TxMAC or MAC mode + "enabled": False, # transmit enablement + "stats": { # base statistics + "total": 0, # total number of frames received from firmware application + #"total_octets": 0, # total number of octets received from firmware application + "pass": 0, # total number of sent frames on Ethernet + "pass_octets": 0, # total number of sent octets on Ethernet + "drop": 0, # total number of dropped frames + "drop_disabled": 0, # total number of frames dropped due to disabled TxMAC state (txmac.disabled == True) + "drop_link_down": 0, # ... due to not estabilished link + #"drop_err": 0, # ... due to an error (currently: drop_err == drop_err_len) + "drop_err_len": 0 # ... due to frame lenght out of range + } + }, + "pma": { # physical medium attachment; only present for nfb-eth tool in PCS/PMA mode + "link_status_latch": True, # PMA link is estabilished all the time from previous status read + "link_status": True, # PMA link is estabilished + "speed_str": "100 Gb/s", + "transmit_fault": False, + "receive_fault": True, + "type": "100GBASE-LR4", # current link mode + "available_types": [ # list of all link modes supported in firmware + "100GBASE-SR4", + ... + ], + "available_features": [ # list of all features supported in firmware + { + "active": False, + "name": "PMA local loopback" + }, + ... + ] + }, + "rsfec": { # Reed-Solomon Forward Error Correction; only present for nfb-eth tool in PCS/PMA mode and for PMA type 100GBASE-SR4 or similar (clause 91 and 108) + "high_ser": False, + "lanes_aligned": False, + "pcs_lanes_aligned": True, + "corrected_cws": 0, + "uncorrected_cws": 0, + "symbol_errors": [ + 0, + ... + ], + "lane_map": [ + 0, + ... + ], + "am_lock": [ + False, + ... + ] + }, + "pcs": { # physical coding sublayer; only present for nfb-eth tool in PCS/PMA mode + "link_status_latch": False, + "link_status": False, + "speed_str": "100 Gb/s", + "transmit_fault": False, + "receive_fault": True, + "available_features": [ + { + "active": False, + "name": "PCS reverse loopback" + } + ], + "global_block_lock_latch": False, + "global_block_lock": False, + "global_high_ber_latch": False, + "global_high_ber": False, + "ber_counter": 0, + "error_blocks": 0, + "lanes_aligned": False, + "block_lock": [ + False, + ... + ], + "am_lock": [ + False, + ... + ], + "lane_map": [ + 0, + ... + ], + "bip_error_counters": [ + 0, + ... + ], + "rsfec_cl119": { # Reed-Solomon Forward Error Correction; only present for nfb-eth tool in PCS/PMA mode and for PMA type 200/400G or similar (clause 119) + "high_ser": False, + "degraded_ser": False, + "remote_degraded_ser": False, + "local_degraded_ser": False, + "corrected_cws": 19063599, + "uncorrected_cws": 0, + "symbol_errors": [ + 121928, + ... + ] + } + } + ] + } + } diff --git a/doc/tools/nfb-info.rst b/doc/tools/nfb-info.rst index 7492baae..62a9cfb1 100644 --- a/doc/tools/nfb-info.rst +++ b/doc/tools/nfb-info.rst @@ -45,3 +45,83 @@ different card-name labels. :ref:`nfb-boot` compares card-name labels and ensures and refuses to flash firmware with unequal card-name. + + +JSON output +~~~~~~~~~~~ + +.. code-block:: python + + { # only present in default mode + { + "board": { + "board_name": "FB1CGG", + "serial_number": "317", + "network_interfaces": 2, + "interfaces": [ # only present in verbose mode + { + "id": 0, + "type": "QSFP" + }, + { + "id": 1, + "type": "QSFP" + } + ], + "temperature": 54.2 # only present in verbose mode + }, + "firmware": { + "card_name": "FB2CGG3", + "project_name": "NDK_HFT", + "project_variant": "10G2", + "project_version": "0.2.1", + "build_time": "2024-04-04 15:38:44", + "build_tool": "Vivado v2022.2 (64-bit)", + "build_author": "cabal@cesnet.cz", + "rx_queues": 16, # all RX queues in firmware + "rx_queues_available": 16, # only usable RX queues (e.g. corresponding PCI endpoint is connected) + "tx_queues": 16, + "tx_queues_available": 16, + "eth_channels": [ # only present in verbose mode + { + "id": 0, + "type": "10G" + } + ] + }, + "system": { + "pci": [ # list of PCI endpoints + { + "id": 0, + "pci_bdf": "0000:03:00.0", + "pci_link_speed_str": "8 GT/s", + "pci_link_width": 8, + "numa": 0, + "bar": [ + { + "id": 0, + "size": 67108864 + }, + { + "id": 2, + "size": 16777216 + } + ] + } + ] + } + } + + [ # only present in card list mode + { + "id": 2, + "path": "/dev/nfb2", + "pci_bdf": "0000:81:00.0", + "card_name": "FB2CGHH", + "serial_number": "144", + "project_name": "NDK_MINIMAL", + "project_variant": "100G2", + "project_version": "0.5.6" + }, + ... + ] From 29ed355a647e40d0ec1683a00499862987399915 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 13 May 2025 15:35:15 +0200 Subject: [PATCH 363/518] feat(libnetcope - i2c): separate i2c_controller from i2c_ctrl This enables alternative I2C controllers. --- libnfb/include/netcope/i2c_controller.h | 297 ++++++++++++++++++++++++ libnfb/include/netcope/i2c_ctrl.h | 284 ++++------------------ 2 files changed, 342 insertions(+), 239 deletions(-) create mode 100644 libnfb/include/netcope/i2c_controller.h diff --git a/libnfb/include/netcope/i2c_controller.h b/libnfb/include/netcope/i2c_controller.h new file mode 100644 index 00000000..9717896a --- /dev/null +++ b/libnfb/include/netcope/i2c_controller.h @@ -0,0 +1,297 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Network component library - I2C controller + * + * Copyright (C) 2018-2022 CESNET + * Author(s): + * Martin Peresini + * Martin Spinler + */ + +#ifndef NETCOPE_I2CCTRL_H +#define NETCOPE_I2CCTRL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ~~~~[ DATA TYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +struct nc_i2c_controller { + uint8_t addr; + uint16_t prescale; + int bytes; /* Obsolete */ + unsigned int prescale_init : 1; +}; + +/* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +static inline struct nc_i2c_controller *nc_i2c_controller_open(const struct nfb_device *dev, int fdt_offset); +static inline int nc_i2c_controller_read_reg(void *ctrl, uint8_t reg, uint8_t *data, unsigned size); +static inline int nc_i2c_controller_write_reg(void *ctrl, uint8_t reg, const uint8_t *data, unsigned size); +static inline void nc_i2c_controller_close(void *ctrl); + +/* Obsolete */ +#if 0 +static inline int nc_i2c_controller_read(struct nc_i2c_controller *ctrl, uint32_t reg, uint32_t *data); +static inline int nc_i2c_controller_write(struct nc_i2c_controller *ctrl, uint32_t reg, uint32_t data); +#endif + +/* ~~~~[ DEFINES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#define I2C_CTRL_REG_CONTROL 0 +#define I2C_CTRL_REG_DATA 4 + +#define I2C_COMP_LOCK (1 << 0) + +/* INFO: register mapping differs from OC original */ +#define I2C_CTRL_REG_CR 4 +#define I2C_CTRL_REG_SR 4 +#define I2C_CTRL_REG_RR 5 +#define I2C_CTRL_REG_TR 5 + +#define I2C_CTRL_REG_CR_STA (1 << 7) +#define I2C_CTRL_REG_CR_STO (1 << 6) +#define I2C_CTRL_REG_CR_RD (1 << 5) +#define I2C_CTRL_REG_CR_WR (1 << 4) +#define I2C_CTRL_REG_CR_ACK (1 << 3) +#define I2C_CTRL_REG_CR_IACK (1 << 0) + +#define I2C_CTRL_REG_SR_nRXACK (1 << 7) +#define I2C_CTRL_REG_SR_BUSY (1 << 6) +#define I2C_CTRL_REG_SR_AL (1 << 5) +#define I2C_CTRL_REG_SR_TIP (1 << 1) +#define I2C_CTRL_REG_SR_IF (1 << 0) + +/** + * brief Function is used as delay between signals sent to i2c bus HW. + */ +static uint8_t _nc_i2c_controller_wait_for_ready(struct nc_i2c_controller *ctrl) +{ + uint8_t status_reg; + struct nfb_comp *comp; + + comp = nfb_user_to_comp(ctrl); + + while ((status_reg = nfb_comp_read8(comp, I2C_CTRL_REG_SR)) & I2C_CTRL_REG_SR_TIP); + + return status_reg; +} + +/* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +static inline struct nc_i2c_controller *nc_i2c_controller_open_ext(const struct nfb_device *dev, int fdt_offset, size_t custom_data_sz, void **custom_data) +{ + struct nfb_comp *comp; + struct nc_i2c_controller *ctrl; + + if (fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, "netcope,i2c")) + return NULL; + + comp = nfb_comp_open_ext(dev, fdt_offset, sizeof(*ctrl) + custom_data_sz); + if (comp == NULL) + return NULL; + + ctrl = (struct nc_i2c_controller *) nfb_comp_to_user(comp); + + ctrl->addr = 0xAC; + ctrl->bytes = 2; + ctrl->prescale_init = 0; + + /* INFO: The first opener should init the controller and the last shutter should deinit it. + * Unfornatelly there is currently not a counted-semaphore-like mechanism in nfb lock API. + * The workaround is to init and deinit the controller in each read / write access. */ +// nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, 0x800000 | ctrl->prescale); + + if (custom_data) { + *custom_data = &ctrl[1]; + } + + return ctrl; +} + +static inline struct nc_i2c_controller *nc_i2c_controller_open(const struct nfb_device *dev, int fdt_offset) +{ + return nc_i2c_controller_open_ext(dev, fdt_offset, 0, NULL); +} + +static inline void nc_i2c_controller_close(void *p) +{ + struct nc_i2c_controller *ctrl = p; + struct nfb_comp *comp; + + comp = nfb_user_to_comp(ctrl); + +// nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, 0x0); + nfb_comp_close(comp); +} + + +#if 0 +static inline int nc_i2c_controller_read(struct nc_i2c_controller *ctrl, uint32_t reg, uint32_t *data) +{ + int ret, i; + uint8_t data8[4] = {0xFF, 0xFF, 0xFF, 0xFF}; + + *data = 0xFFFFFFFF; + ret = nc_i2c_controller_read_reg(ctrl, reg, data8, ctrl->bytes); + if (ret != ctrl->bytes) + return -1; + for (i = 0; i < ctrl->bytes && (unsigned) i < sizeof(data8); i++) { + *data |= data8[i] << (i * 8); + } + return 0; +} + +static inline int nc_i2c_controller_write(struct nc_i2c_controller *ctrl, uint32_t reg, uint32_t data) +{ + int ret, i; + uint8_t data8[4]; + + for (i = 0; i < ctrl->bytes && (unsigned) i < sizeof(data8); i++) { + data8[i] = data >> (8 * i); + } + ret = nc_i2c_controller_write_reg(ctrl, reg, data8, ctrl->bytes); + return ret == ctrl->bytes ? 0 : -1; +} +#endif + +static inline int _nc_i2c_controller_write_byte(struct nc_i2c_controller *ctrl, uint8_t data, uint8_t flags) +{ + struct nfb_comp *comp; + uint8_t sr = 0; + + comp = nfb_user_to_comp(ctrl); + nfb_comp_write32(comp, I2C_CTRL_REG_DATA, (((uint32_t)data) << 8) | flags); + sr = _nc_i2c_controller_wait_for_ready(ctrl); + + if (sr & I2C_CTRL_REG_SR_nRXACK && (flags & I2C_CTRL_REG_CR_STO) == 0) + return 1; + return 0; +} + +static inline void __nc_i2c_controller_prescale_init(struct nc_i2c_controller *ctrl) +{ + if (ctrl->prescale_init == 0) { + ctrl->prescale_init = 1; + ctrl->prescale = nfb_comp_read16(nfb_user_to_comp(ctrl), I2C_CTRL_REG_CONTROL); + if (ctrl->prescale == 0) + ctrl->prescale = 0x00f9; + } + +} + +static inline int nc_i2c_controller_read_reg(void *p, uint8_t reg, uint8_t *data, unsigned size) +{ + struct nc_i2c_controller *ctrl = p; + unsigned i; + int ret; + struct nfb_comp *comp; + uint8_t flags; + int retries = 0; + + if (size == 0) + return 0; + + comp = nfb_user_to_comp(ctrl); + + /* lock I2C access */ + if (!nfb_comp_lock(comp, I2C_COMP_LOCK)) + return -EAGAIN; + + __nc_i2c_controller_prescale_init(ctrl); + + /* Init HW controller */ + nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, 0x800000 | ctrl->prescale); + +retry: + _nc_i2c_controller_wait_for_ready(ctrl); + + ret = 0; + ret |= _nc_i2c_controller_write_byte(ctrl, ctrl->addr, I2C_CTRL_REG_CR_WR | I2C_CTRL_REG_CR_STA); + ret |= _nc_i2c_controller_write_byte(ctrl, reg, I2C_CTRL_REG_CR_WR | I2C_CTRL_REG_CR_STO); + + ret |= _nc_i2c_controller_write_byte(ctrl, ctrl->addr | 1, I2C_CTRL_REG_CR_WR | I2C_CTRL_REG_CR_STA); + + for (i = 0, flags = I2C_CTRL_REG_CR_RD; i < size; i++) { + if (i == size - 1) + flags |= I2C_CTRL_REG_CR_ACK | I2C_CTRL_REG_CR_STO; + + ret |= _nc_i2c_controller_write_byte(ctrl, 0, flags); + + if (ret) + continue; + + data[i] = nfb_comp_read32(comp, I2C_CTRL_REG_DATA) >> 8; + } + + if (ret && retries++ < 0) { + goto retry; + } + + /* Deinit HW controller */ + nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, ctrl->prescale); + + nfb_comp_unlock(comp, I2C_COMP_LOCK); + + if (ret) + return -EIO; + + return i; +} + +static inline int nc_i2c_controller_write_reg(void *p, uint8_t reg, const uint8_t *data, unsigned size) +{ + struct nc_i2c_controller *ctrl = p; + unsigned i; + int ret; + struct nfb_comp *comp; + uint8_t flags; + + if (size == 0) + return 0; + + comp = nfb_user_to_comp(ctrl); + + /* lock I2C access */ + if (!nfb_comp_lock(comp, I2C_COMP_LOCK)) + return -EAGAIN; + + __nc_i2c_controller_prescale_init(ctrl); + + /* Init HW controller */ + nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, 0x800000 | ctrl->prescale); + + _nc_i2c_controller_wait_for_ready(ctrl); + + ret = 0; + ret |= _nc_i2c_controller_write_byte(ctrl, ctrl->addr, I2C_CTRL_REG_CR_WR | I2C_CTRL_REG_CR_STA); + ret |= _nc_i2c_controller_write_byte(ctrl, reg, I2C_CTRL_REG_CR_WR); + + for (i = 0, flags = I2C_CTRL_REG_CR_WR; i < size; i++) { + if (i == size - 1) + flags |= I2C_CTRL_REG_CR_STO; + + ret |= _nc_i2c_controller_write_byte(ctrl, data[i], flags); + } + + /* Deinit HW controller */ + nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, ctrl->prescale); + + nfb_comp_unlock(comp, I2C_COMP_LOCK); + + if (ret) + return -EIO; + + return i; +} + +static inline void nc_i2c_controller_set_addr(void *p, uint8_t address) +{ + struct nc_i2c_controller *ctrl = p; + + ctrl->addr = address; +} + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* NETCOPE_I2CCTRL_H */ diff --git a/libnfb/include/netcope/i2c_ctrl.h b/libnfb/include/netcope/i2c_ctrl.h index ab3e3a4f..aceff7f2 100644 --- a/libnfb/include/netcope/i2c_ctrl.h +++ b/libnfb/include/netcope/i2c_ctrl.h @@ -1,15 +1,14 @@ /* SPDX-License-Identifier: BSD-3-Clause */ /* - * Network component library - I2C controller + * Network component library - common I2C API * - * Copyright (C) 2018-2022 CESNET + * Copyright (C) 2025 CESNET * Author(s): - * Martin Peresini * Martin Spinler */ -#ifndef NETCOPE_I2CCTRL_H -#define NETCOPE_I2CCTRL_H +#ifndef NETCOPE_I2C_H +#define NETCOPE_I2C_H #ifdef __cplusplus extern "C" { @@ -17,12 +16,24 @@ extern "C" { /* ~~~~[ DATA TYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ struct nc_i2c_ctrl { - uint8_t addr; - uint16_t prescale; - int bytes; /* Obsolete */ - unsigned int prescale_init : 1; + void *priv; + + void (*set_addr)(void *ctrl, uint8_t address); + int (*read_reg)(void *ctrl, uint8_t reg, uint8_t *data, unsigned size); + int (*write_reg)(void *ctrl, uint8_t reg, const uint8_t *data, unsigned size); + void (*close)(void *ctrl); }; +#ifdef __cplusplus +} // extern "C" +#endif + +#include "i2c_controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + /* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ static inline struct nc_i2c_ctrl *nc_i2c_open(const struct nfb_device *dev, int fdt_offset); static inline void nc_i2c_set_addr(struct nc_i2c_ctrl *ctrl, uint8_t address); @@ -30,260 +41,55 @@ static inline int nc_i2c_read_reg(struct nc_i2c_ctrl *ctrl, uint8_t reg, uint8_t static inline int nc_i2c_write_reg(struct nc_i2c_ctrl *ctrl, uint8_t reg, const uint8_t *data, unsigned size); static inline void nc_i2c_close(struct nc_i2c_ctrl *ctrl); -/* Obsolete */ -static inline int nc_i2c_read(struct nc_i2c_ctrl *ctrl, uint32_t reg, uint32_t *data); -static inline int nc_i2c_write(struct nc_i2c_ctrl *ctrl, uint32_t reg, uint32_t data); - -/* ~~~~[ DEFINES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#define I2C_CTRL_REG_CONTROL 0 -#define I2C_CTRL_REG_DATA 4 - -#define I2C_COMP_LOCK (1 << 0) - -/* INFO: register mapping differs from OC original */ -#define I2C_CTRL_REG_CR 4 -#define I2C_CTRL_REG_SR 4 -#define I2C_CTRL_REG_RR 5 -#define I2C_CTRL_REG_TR 5 - -#define I2C_CTRL_REG_CR_STA (1 << 7) -#define I2C_CTRL_REG_CR_STO (1 << 6) -#define I2C_CTRL_REG_CR_RD (1 << 5) -#define I2C_CTRL_REG_CR_WR (1 << 4) -#define I2C_CTRL_REG_CR_ACK (1 << 3) -#define I2C_CTRL_REG_CR_IACK (1 << 0) - -#define I2C_CTRL_REG_SR_nRXACK (1 << 7) -#define I2C_CTRL_REG_SR_BUSY (1 << 6) -#define I2C_CTRL_REG_SR_AL (1 << 5) -#define I2C_CTRL_REG_SR_TIP (1 << 1) -#define I2C_CTRL_REG_SR_IF (1 << 0) - -/** - * brief Function is used as delay between signals sent to i2c bus HW. - */ -static uint8_t _nc_i2c_wait_for_ready(struct nc_i2c_ctrl *ctrl) -{ - uint8_t status_reg; - struct nfb_comp *comp; - - comp = nfb_user_to_comp(ctrl); - - while ((status_reg = nfb_comp_read8(comp, I2C_CTRL_REG_SR)) & I2C_CTRL_REG_SR_TIP); - - return status_reg; -} /* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ static inline struct nc_i2c_ctrl *nc_i2c_open(const struct nfb_device *dev, int fdt_offset) { - struct nfb_comp *comp; - struct nc_i2c_ctrl *ctrl; - - if (fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, "netcope,i2c")) - return NULL; - - comp = nfb_comp_open_ext(dev, fdt_offset, sizeof(*ctrl)); - if (comp == NULL) - return NULL; - - ctrl = (struct nc_i2c_ctrl *) nfb_comp_to_user(comp); - - ctrl->addr = 0xAC; - ctrl->bytes = 2; - ctrl->prescale_init = 0; - - /* INFO: The first opener should init the controller and the last shutter should deinit it. - * Unfornatelly there is currently not a counted-semaphore-like mechanism in nfb lock API. - * The workaround is to init and deinit the controller in each read / write access. */ -// nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, 0x800000 | ctrl->prescale); - - return ctrl; -} - -static inline void nc_i2c_close(struct nc_i2c_ctrl *ctrl) -{ - struct nfb_comp *comp; - - comp = nfb_user_to_comp(ctrl); + void *priv = NULL; + struct nc_i2c_ctrl *i2c = NULL; + + if (fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, "netcope,i2c") == 0) { + priv = nc_i2c_controller_open_ext(dev, fdt_offset, sizeof(*i2c), (void**) &i2c); + if (priv == NULL) + return NULL; + + i2c->priv = priv; + i2c->set_addr = nc_i2c_controller_set_addr; + i2c->read_reg = nc_i2c_controller_read_reg; + i2c->write_reg = nc_i2c_controller_write_reg; + i2c->close = nc_i2c_controller_close; + } -// nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, 0x0); - nfb_comp_close(comp); + return i2c; } static inline void nc_i2c_set_addr(struct nc_i2c_ctrl *ctrl, uint8_t address) { - ctrl->addr = address; -} - -static inline void i2c_set_addr(struct nc_i2c_ctrl *ctrl, unsigned address) -{ - nc_i2c_set_addr(ctrl, address); -} - -static inline void i2c_set_data_bytes(struct nc_i2c_ctrl *ctrl, unsigned count) -{ - if (count > 0 && count <= 4) - ctrl->bytes = count; -} - -static inline int nc_i2c_read(struct nc_i2c_ctrl *ctrl, uint32_t reg, uint32_t *data) -{ - int ret, i; - uint8_t data8[4] = {0xFF, 0xFF, 0xFF, 0xFF}; - - *data = 0xFFFFFFFF; - ret = nc_i2c_read_reg(ctrl, reg, data8, ctrl->bytes); - if (ret != ctrl->bytes) - return -1; - for (i = 0; i < ctrl->bytes && (unsigned) i < sizeof(data8); i++) { - *data |= data8[i] << (i * 8); - } - return 0; -} - -static inline int nc_i2c_write(struct nc_i2c_ctrl *ctrl, uint32_t reg, uint32_t data) -{ - int ret, i; - uint8_t data8[4]; - - for (i = 0; i < ctrl->bytes && (unsigned) i < sizeof(data8); i++) { - data8[i] = data >> (8 * i); - } - ret = nc_i2c_write_reg(ctrl, reg, data8, ctrl->bytes); - return ret == ctrl->bytes ? 0 : -1; + ctrl->set_addr(ctrl->priv, address); } -static inline int _nc_i2c_write_byte(struct nc_i2c_ctrl *ctrl, uint8_t data, uint8_t flags) +static inline int nc_i2c_read_reg(struct nc_i2c_ctrl *ctrl, uint8_t reg, uint8_t *data, unsigned size) { - struct nfb_comp *comp; - uint8_t sr = 0; - - comp = nfb_user_to_comp(ctrl); - nfb_comp_write32(comp, I2C_CTRL_REG_DATA, (((uint32_t)data) << 8) | flags); - sr = _nc_i2c_wait_for_ready(ctrl); - - if (sr & I2C_CTRL_REG_SR_nRXACK && (flags & I2C_CTRL_REG_CR_STO) == 0) - return 1; - return 0; + return ctrl->read_reg(ctrl->priv, reg, data, size); } -static inline void __nc_i2c_prescale_init(struct nc_i2c_ctrl *ctrl) +static inline int nc_i2c_write_reg(struct nc_i2c_ctrl *ctrl, uint8_t reg, const uint8_t *data, unsigned size) { - if (ctrl->prescale_init == 0) { - ctrl->prescale_init = 1; - ctrl->prescale = nfb_comp_read16(nfb_user_to_comp(ctrl), I2C_CTRL_REG_CONTROL); - if (ctrl->prescale == 0) - ctrl->prescale = 0x00f9; - } - + return ctrl->write_reg(ctrl->priv, reg, data, size); } -static inline int nc_i2c_read_reg(struct nc_i2c_ctrl *ctrl, uint8_t reg, uint8_t *data, unsigned size) +static inline void nc_i2c_close(struct nc_i2c_ctrl *ctrl) { - unsigned i; - int ret; - struct nfb_comp *comp; - uint8_t flags; - int retries = 0; - - if (size == 0) - return 0; - - comp = nfb_user_to_comp(ctrl); - - /* lock I2C access */ - if (!nfb_comp_lock(comp, I2C_COMP_LOCK)) - return -EAGAIN; - - __nc_i2c_prescale_init(ctrl); - - /* Init HW controller */ - nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, 0x800000 | ctrl->prescale); - -retry: - _nc_i2c_wait_for_ready(ctrl); - - ret = 0; - ret |= _nc_i2c_write_byte(ctrl, ctrl->addr, I2C_CTRL_REG_CR_WR | I2C_CTRL_REG_CR_STA); - ret |= _nc_i2c_write_byte(ctrl, reg, I2C_CTRL_REG_CR_WR | I2C_CTRL_REG_CR_STO); - - ret |= _nc_i2c_write_byte(ctrl, ctrl->addr | 1, I2C_CTRL_REG_CR_WR | I2C_CTRL_REG_CR_STA); - - for (i = 0, flags = I2C_CTRL_REG_CR_RD; i < size; i++) { - if (i == size - 1) - flags |= I2C_CTRL_REG_CR_ACK | I2C_CTRL_REG_CR_STO; - - ret |= _nc_i2c_write_byte(ctrl, 0, flags); - - if (ret) - continue; - - data[i] = nfb_comp_read32(comp, I2C_CTRL_REG_DATA) >> 8; - } - - if (ret && retries++ < 0) { - goto retry; - } - - /* Deinit HW controller */ - nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, ctrl->prescale); - - nfb_comp_unlock(comp, I2C_COMP_LOCK); - - if (ret) - return -EIO; - - return i; + ctrl->close(ctrl->priv); } -static inline int nc_i2c_write_reg(struct nc_i2c_ctrl *ctrl, uint8_t reg, const uint8_t *data, unsigned size) +static inline void i2c_set_addr(struct nc_i2c_ctrl *ctrl, unsigned address) { - unsigned i; - int ret; - struct nfb_comp *comp; - uint8_t flags; - - if (size == 0) - return 0; - - comp = nfb_user_to_comp(ctrl); - - /* lock I2C access */ - if (!nfb_comp_lock(comp, I2C_COMP_LOCK)) - return -EAGAIN; - - __nc_i2c_prescale_init(ctrl); - - /* Init HW controller */ - nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, 0x800000 | ctrl->prescale); - - _nc_i2c_wait_for_ready(ctrl); - - ret = 0; - ret |= _nc_i2c_write_byte(ctrl, ctrl->addr, I2C_CTRL_REG_CR_WR | I2C_CTRL_REG_CR_STA); - ret |= _nc_i2c_write_byte(ctrl, reg, I2C_CTRL_REG_CR_WR); - - for (i = 0, flags = I2C_CTRL_REG_CR_WR; i < size; i++) { - if (i == size - 1) - flags |= I2C_CTRL_REG_CR_STO; - - ret |= _nc_i2c_write_byte(ctrl, data[i], flags); - } - - /* Deinit HW controller */ - nfb_comp_write32(comp, I2C_CTRL_REG_CONTROL, ctrl->prescale); - - nfb_comp_unlock(comp, I2C_COMP_LOCK); - - if (ret) - return -EIO; - - return i; + nc_i2c_set_addr(ctrl, address); } #ifdef __cplusplus } // extern "C" #endif -#endif /* NETCOPE_I2CCTRL_H */ +#endif /* NETCOPE_I2C_H */ From b293ac5be509fbad7db99c7aa229c96bc822c948 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 29 May 2025 08:33:22 +0200 Subject: [PATCH 364/518] feat(libnetcope - bw_bmc): add support for I2C R/W to the BittWare BMC --- libnfb/include/netcope/bittware_bmc_spi.h | 99 +++++++++++++++++++---- 1 file changed, 85 insertions(+), 14 deletions(-) diff --git a/libnfb/include/netcope/bittware_bmc_spi.h b/libnfb/include/netcope/bittware_bmc_spi.h index daf0bbd6..0ff1eea1 100644 --- a/libnfb/include/netcope/bittware_bmc_spi.h +++ b/libnfb/include/netcope/bittware_bmc_spi.h @@ -27,6 +27,7 @@ struct nc_bw_bmc { /* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ static inline struct nc_bw_bmc *nc_bw_bmc_open(const struct nfb_device *dev, int fdt_offset, unsigned char*buffer, unsigned int len); +static inline struct nc_bw_bmc *nc_bw_bmc_open_ext(const struct nfb_device *dev, int fdt_offset, unsigned char*buffer, unsigned int len, int extra_sz, void **extra); static inline void nc_bw_bmc_close(struct nc_bw_bmc *spi); static inline int nc_bw_bmc_send_mctp(struct nc_bw_bmc *spi); static inline int nc_bw_bmc_send_mctp_ext(struct nc_bw_bmc *spi, const unsigned char *bytes, int len, int last, int wait_for_status); @@ -43,6 +44,9 @@ static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned cha #define COMP_NETCOPE_BW_BMC_SPI "bittware,bmc" +#define NC_BW_BMC_LOCK 1 + + static inline void nc_bw_bmc_write32(struct nfb_comp *comp, uint32_t offset, uint32_t val) { struct nc_bw_bmc * spi = (struct nc_bw_bmc*) nfb_comp_to_user(comp); @@ -52,7 +56,7 @@ static inline void nc_bw_bmc_write32(struct nfb_comp *comp, uint32_t offset, uin } /* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -static inline struct nc_bw_bmc *nc_bw_bmc_open(const struct nfb_device *dev, int fdt_offset, unsigned char*buffer, unsigned int len) +static inline struct nc_bw_bmc *nc_bw_bmc_open_ext(const struct nfb_device *dev, int fdt_offset, unsigned char*buffer, unsigned int len, int extra_sz, void**extra) { int size; struct nc_bw_bmc *spi; @@ -62,6 +66,7 @@ static inline struct nc_bw_bmc *nc_bw_bmc_open(const struct nfb_device *dev, int int retries = 0; uint32_t status; + if (len == 0) return NULL; if (fdt_node_check_compatible(fdt, fdt_offset, COMP_NETCOPE_BW_BMC_SPI)) @@ -71,12 +76,18 @@ static inline struct nc_bw_bmc *nc_bw_bmc_open(const struct nfb_device *dev, int if (buffer == NULL) size += len; + size += extra_sz; + comp = nfb_comp_open_ext(dev, fdt_offset, size); if (!comp) return NULL; spi = (struct nc_bw_bmc*) nfb_comp_to_user(comp); - spi->buffer = buffer ? buffer : (unsigned char*) (spi + 1); + if (extra) { + *extra = &spi[1]; + } + + spi->buffer = buffer ? buffer : (unsigned char*) (&spi[1]) + extra_sz; spi->buffer_len = len; spi->pos = 0; spi->recv_len = 0; @@ -114,13 +125,28 @@ static inline struct nc_bw_bmc *nc_bw_bmc_open(const struct nfb_device *dev, int return spi; } +static inline struct nc_bw_bmc *nc_bw_bmc_open(const struct nfb_device *dev, int fdt_offset, unsigned char *buffer, unsigned int len) +{ + return nc_bw_bmc_open_ext(dev, fdt_offset, buffer, len, 0, NULL); +} + static inline void nc_bw_bmc_close(struct nc_bw_bmc *spi) { nfb_comp_close(nfb_user_to_comp(spi)); } +static inline int nc_bw_bmc_lock(struct nc_bw_bmc *spi) +{ + return nfb_comp_trylock(nfb_user_to_comp(spi), NC_BW_BMC_LOCK, 100) == 0 ? 1 : 0; +} + +static inline void nc_bw_bmc_unlock(struct nc_bw_bmc *spi) +{ + nfb_comp_unlock(nfb_user_to_comp(spi), NC_BW_BMC_LOCK); +} + /* send raw mctp: header must be in bytes already (hdr, dst, src, flags) */ -static inline int nc_bw_bmc_send_mctp_ext(struct nc_bw_bmc *spi, const unsigned char *bytes, int len, int last, int wait_for_status) +static inline int _nc_bw_bmc_send_raw_frame(struct nc_bw_bmc *spi, const unsigned char *bytes, int len, int last, int wait_for_status, int cmd, uint32_t expected_status) { int retries = 0; struct nfb_comp * comp = nfb_user_to_comp(spi); @@ -136,7 +162,7 @@ static inline int nc_bw_bmc_send_mctp_ext(struct nc_bw_bmc *spi, const unsigned if (len == 0) return 0; - nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_WR_FIFO, 0x11); /* MCTP command */ + nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_WR_FIFO, cmd); /* MCTP command */ for (i = 0; i < len - 1; i++) { nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_WR_FIFO, bytes[i]); @@ -147,6 +173,7 @@ static inline int nc_bw_bmc_send_mctp_ext(struct nc_bw_bmc *spi, const unsigned nfb_comp_write32(comp, NC_BW_BMC_SPI_WR_FIFO, status); if (!wait_for_status) return 0; + if (spi->throttle_write) nfb_comp_read32(comp, NC_BW_BMC_SPI_WR_FIFO); @@ -167,29 +194,53 @@ static inline int nc_bw_bmc_send_mctp_ext(struct nc_bw_bmc *spi, const unsigned return -EPIPE; status = status >> 24; - if (status != 0x20) { - /* 0x20: MCTP Success - * 0x21: MCTP Invalid Length - * 0x22: MCTP Invalid Source - * 0x23: MCTP Invalid Message - * 0xF0: Unrecognized Command - */ + if (status != expected_status) { return -EOPNOTSUPP; } return 0; } +static inline int nc_bw_bmc_send_mctp_ext(struct nc_bw_bmc *spi, const unsigned char *bytes, int len, int last, int wait_for_status) +{ + /* Command: + * 0x11: MCTP + * + * Expected status: + * 0x20: MCTP Success + * 0x21: MCTP Invalid Length + * 0x22: MCTP Invalid Source + * 0x23: MCTP Invalid Message + * 0xF0: Unrecognized Command + */ + return _nc_bw_bmc_send_raw_frame(spi, bytes, len, last, wait_for_status, 0x11, 0x20); +} + static inline int nc_bw_bmc_send_mctp(struct nc_bw_bmc *spi) { return nc_bw_bmc_send_mctp_ext(spi, spi->buffer, spi->pos, 1, 1); } +static inline int nc_bw_bmc_send_i2c(struct nc_bw_bmc * spi, const unsigned char *bytes, int len) +{ + /* Command: + * 0x22: I2C + * + * Expected status: + * 0x10: I2C Success + * 0x11: I2C NACK + * 0x12: I2C Timeout + * 0x13: I2C Invalid Length + * 0xF0: Unrecognized Command + */ + return _nc_bw_bmc_send_raw_frame(spi, bytes, len, 1, 1, 0x22, 0x10); +} + static inline int nc_bw_bmc_min(int a, int b) { return a < b ? a : b; } -static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned char* data, unsigned int len, unsigned int *received) +static inline int _nc_bw_bmc_receive(struct nc_bw_bmc *spi, unsigned char* data, unsigned int len, unsigned int *received, uint32_t expected_status) { struct nfb_comp * comp = nfb_user_to_comp(spi); @@ -221,7 +272,7 @@ static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned cha return bytes; status = nfb_comp_read32(comp, NC_BW_BMC_SPI_RD_FIFO); - if ((status & 0xFF) != 0x11) { + if ((status & 0xFF) != expected_status) { nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_RD_CSR, 1 << 14); /* Read FIFO Reset */ nc_bw_bmc_write32(comp, NC_BW_BMC_SPI_RD_CSR, 1 << 1); /* Read Transfer Complete */ return -EBADF; @@ -253,11 +304,31 @@ static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned cha return 0; } +static inline int nc_bw_bmc_receive_mctp_ext(struct nc_bw_bmc *spi, unsigned char* data, unsigned int len, unsigned int *received) +{ + /* 0x11: MCTP Response */ + return _nc_bw_bmc_receive(spi, data, len, received, 0x11); +} + static inline int nc_bw_bmc_receive_mctp(struct nc_bw_bmc *spi) { return nc_bw_bmc_receive_mctp_ext(spi, spi->buffer, spi->buffer_len, &spi->recv_len); } +static inline int nc_bw_bmc_receive_i2c(struct nc_bw_bmc *spi, unsigned char* data, unsigned int len) +{ + int ret; + unsigned int received; + /* 0x24: I2C Response */ + ret = _nc_bw_bmc_receive(spi, data, len, &received, 0x24); + if (ret < 0) + return ret; + + if (received != len) + return -EIO; + return 0; +} + static inline int nc_bw_bmc_mctp_header_default(struct nc_bw_bmc *spi) { int i = 0; @@ -572,7 +643,7 @@ static inline int nc_bw_bmc_fpga_load_ext(struct nc_bw_bmc *spi, const void *dat return 0; } -int nc_bw_bmc_send_reload(struct nc_bw_bmc * spi, const char *filename) +static inline int nc_bw_bmc_send_reload(struct nc_bw_bmc * spi, const char *filename) { int ret = 0; int offset = 0; From a706e6c7cbed30ead77aadbbc05b235520fe76b9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 29 May 2025 08:40:19 +0200 Subject: [PATCH 365/518] feat(libnetcope - i2c): add I2C support for BittWare BMC --- libnfb/include/netcope/i2c_bw_bmc.h | 126 ++++++++++++++++++++++++++++ libnfb/include/netcope/i2c_ctrl.h | 12 +++ 2 files changed, 138 insertions(+) create mode 100644 libnfb/include/netcope/i2c_bw_bmc.h diff --git a/libnfb/include/netcope/i2c_bw_bmc.h b/libnfb/include/netcope/i2c_bw_bmc.h new file mode 100644 index 00000000..8326a44f --- /dev/null +++ b/libnfb/include/netcope/i2c_bw_bmc.h @@ -0,0 +1,126 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Network component library - I2C controller + * + * Copyright (C) 2018-2022 CESNET + * Author(s): + * Martin Peresini + * Martin Spinler + */ + +#ifndef NETCOPE_I2C_BW_BMC_H +#define NETCOPE_I2C_BW_BMC_H + +#include "bittware_bmc_spi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* ~~~~[ DATA TYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +struct nc_i2c_bw_bmc_ctrl { + struct nc_bw_bmc *bmc; + uint8_t addr; +}; + +/* ~~~~[ PROTOTYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +static inline struct nc_i2c_bw_bmc_ctrl *nc_i2c_bw_bmc_open_ext(const struct nfb_device *dev, int fdt_offset, size_t custom_data_sz, void **custom_data); +static inline void nc_i2c_bw_bmc_set_addr(void *, uint8_t address); +static inline int nc_i2c_bw_bmc_read_reg(void *, uint8_t reg, uint8_t *data, unsigned size); +static inline int nc_i2c_bw_bmc_write_reg(void *, uint8_t reg, const uint8_t *data, unsigned size); +static inline void nc_i2c_bw_bmc_close(void *); + +/* ~~~~[ REGISTERS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#define I2C_COMP_LOCK (1 << 0) + +/* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +static inline struct nc_i2c_bw_bmc_ctrl *nc_i2c_bw_bmc_open_ext(const struct nfb_device *dev, int fdt_offset, size_t custom_data_sz, void **custom_data) +{ + struct nc_bw_bmc *bmc; + struct nc_i2c_bw_bmc_ctrl *ctrl = NULL; + + bmc = nc_bw_bmc_open_ext(dev, fdt_offset, NULL, 256, sizeof(*ctrl) + custom_data_sz, (void**) &ctrl); + if (bmc == NULL) + return NULL; + + ctrl->bmc = bmc; + ctrl->addr = 0xAC; + + if (custom_data) + *custom_data = &ctrl[1]; + + return ctrl; +} + +static inline void nc_i2c_bw_bmc_close(void *p) +{ + struct nc_i2c_bw_bmc_ctrl *ctrl = p; + + nc_bw_bmc_close(ctrl->bmc); +} + +static inline void nc_i2c_bw_bmc_set_addr(void *p, uint8_t address) +{ + struct nc_i2c_bw_bmc_ctrl *ctrl = p; + ctrl->addr = address; +} + +static inline int nc_i2c_bw_bmc_read_reg(void *p, uint8_t reg, uint8_t *data, unsigned size) +{ + struct nc_i2c_bw_bmc_ctrl *ctrl = p; + + int ret = 0; + + uint8_t wdata[3]; + + if (size == 0) + return 0; + + /* lock I2C access */ + if (!nc_bw_bmc_lock(ctrl->bmc)) + return -EAGAIN; + + wdata[0] = ctrl->addr / 2; + wdata[1] = size; + wdata[2] = reg; + + ret = nc_bw_bmc_send_i2c(ctrl->bmc, wdata, 3); + if (ret != 0) { + nc_bw_bmc_unlock(ctrl->bmc); + return ret; + } + + ret = nc_bw_bmc_receive_i2c(ctrl->bmc, data, size); + if (ret != 0) { + nc_bw_bmc_unlock(ctrl->bmc); + return ret; + } + + nc_bw_bmc_unlock(ctrl->bmc); + + return size; +} + +static inline int nc_i2c_bw_bmc_write_reg(void *p, uint8_t reg, const uint8_t *data, unsigned size) +{ + int ret; + struct nc_i2c_bw_bmc_ctrl *ctrl = p; + + if (!nc_bw_bmc_lock(ctrl->bmc)) + return -EAGAIN; + + nc_bw_bmc_push_uint8(ctrl->bmc, ctrl->addr / 2); + nc_bw_bmc_push_uint8(ctrl->bmc, 0); + nc_bw_bmc_push_uint8(ctrl->bmc, reg); + nc_bw_bmc_push(ctrl->bmc, data, size); + + ret = _nc_bw_bmc_send_raw_frame(ctrl->bmc, ctrl->bmc->buffer, ctrl->bmc->pos, 1, 1, 0x22, 0x10); + nc_bw_bmc_unlock(ctrl->bmc); + return ret; +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* NETCOPE_I2C_BW_BMC_H */ diff --git a/libnfb/include/netcope/i2c_ctrl.h b/libnfb/include/netcope/i2c_ctrl.h index aceff7f2..557665b6 100644 --- a/libnfb/include/netcope/i2c_ctrl.h +++ b/libnfb/include/netcope/i2c_ctrl.h @@ -29,6 +29,7 @@ struct nc_i2c_ctrl { #endif #include "i2c_controller.h" +#include "i2c_bw_bmc.h" #ifdef __cplusplus extern "C" { @@ -58,6 +59,17 @@ static inline struct nc_i2c_ctrl *nc_i2c_open(const struct nfb_device *dev, int i2c->read_reg = nc_i2c_controller_read_reg; i2c->write_reg = nc_i2c_controller_write_reg; i2c->close = nc_i2c_controller_close; + } else if (fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, "bittware,bmc") == 0) { + priv = nc_i2c_bw_bmc_open_ext(dev, fdt_offset, sizeof(*i2c), (void **) &i2c); + + if (priv == NULL) + return NULL; + + i2c->priv = priv; + i2c->set_addr = nc_i2c_bw_bmc_set_addr; + i2c->read_reg = nc_i2c_bw_bmc_read_reg; + i2c->write_reg = nc_i2c_bw_bmc_write_reg; + i2c->close = nc_i2c_bw_bmc_close; } return i2c; From d99af24b0b4e0f252f0ff9545f8d77ce5cb6b268 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 29 May 2025 16:16:42 +0200 Subject: [PATCH 366/518] fix(drivers): use libnfb MI memcpy functionality in driver too This commit removes the memcpy_*io unsuitable behaviour (for example writes divided to 1B accesses). Patch involves the "noopt" version, because the AVX instructions are undesired in Linux kernel. --- drivers/kernel/drivers/nfb/mi/mi.c | 31 ++--- libnfb/include/netcope/mi.h | 187 +++++++++++++++++++++++++++++ libnfb/src/bus/mi.c | 172 +------------------------- 3 files changed, 195 insertions(+), 195 deletions(-) create mode 100644 libnfb/include/netcope/mi.h diff --git a/drivers/kernel/drivers/nfb/mi/mi.c b/drivers/kernel/drivers/nfb/mi/mi.c index eb73d4e2..db2f0600 100644 --- a/drivers/kernel/drivers/nfb/mi/mi.c +++ b/drivers/kernel/drivers/nfb/mi/mi.c @@ -18,46 +18,29 @@ #include "../nfb.h" #include "mi.h" +#include + + static bool mi_debug = 0; static ssize_t nfb_bus_mi_read(struct nfb_bus *bus, void *buf, size_t nbyte, off_t offset) { struct nfb_mi_node *mi_node = bus->priv; + bool wc_used = false; if (mi_node->mem_virt == NULL) return -EBADF; - if (nbyte == sizeof(uint64_t)) - *((uint64_t*)buf) = readq(mi_node->mem_virt + offset); - else if (nbyte == sizeof(uint32_t)) - *((uint32_t*)buf) = readl(mi_node->mem_virt + offset); - else if (nbyte == sizeof(uint16_t)) - *((uint16_t*)buf) = readw(mi_node->mem_virt + offset); - else if (nbyte == sizeof(uint8_t)) - *((uint8_t*)buf) = readb(mi_node->mem_virt + offset); - else - memcpy_fromio(buf, mi_node->mem_virt + offset, nbyte); - - return nbyte; + return nfb_bus_mi_memcopy_noopt(buf, mi_node->mem_virt + offset, nbyte, offset, &wc_used); } static ssize_t nfb_bus_mi_write(struct nfb_bus *bus, const void *buf, size_t nbyte, off_t offset) { struct nfb_mi_node *mi_node = bus->priv; + bool wc_used = false; if (mi_node->mem_virt == NULL) return -EBADF; - if (nbyte == sizeof(uint64_t)) - writeq(*((uint64_t*)buf), mi_node->mem_virt + offset); - else if (nbyte == sizeof(uint32_t)) - writel(*((uint32_t*)buf), mi_node->mem_virt + offset); - else if (nbyte == sizeof(uint16_t)) - writew(*((uint16_t*)buf), mi_node->mem_virt + offset); - else if (nbyte == sizeof(uint8_t)) - writeb(*((uint8_t*)buf), mi_node->mem_virt + offset); - else - memcpy_toio(mi_node->mem_virt + offset, buf, nbyte); - - return nbyte; + return nfb_bus_mi_memcopy_noopt(mi_node->mem_virt + offset, buf, nbyte, offset, &wc_used); } static int nfb_mi_mmap(struct vm_area_struct *vma, unsigned long offset, unsigned long size, void *priv) diff --git a/libnfb/include/netcope/mi.h b/libnfb/include/netcope/mi.h new file mode 100644 index 00000000..ab6ed9c3 --- /dev/null +++ b/libnfb/include/netcope/mi.h @@ -0,0 +1,187 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * libnfb - boot module - memory interface module + * + * Copyright (C) 2017-2022 CESNET + * Author(s): + * Martin Spinler + */ + + +/* + * INFO1: Some CPU/machines hangs on high frequency bus access with size < 32bits + * INFO2: Also Valgrind does ugly accesses with classic memcpy function + * Here is a workaround for these issues + */ + +#define _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr) \ +do { \ + if (*nbyte == (size)) { \ + if (wc_instr) \ + *wc_used = true; \ + return true; \ + } \ + *(src) = (const mtype *) *(src) + 1; \ + *(dst) = (mtype *) *(dst) + 1; \ + *nbyte -= (size); \ +} while (0) + +#define _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, size, src, dst, mtype, load, store, wc_used, wc_instr) \ +do { \ + mtype tmp; \ + while (*nbyte >= (size)) { \ + tmp = load(*(src)); \ + store(*(dst), tmp); \ + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ + } \ +} while (0) + +#define _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, size, src, dst, mtype, stream, wc_used, wc_instr) \ +do { \ + while (*nbyte >= (size)) { \ + stream(*(dst), *(const mtype *) *(src)); \ + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ + } \ +} while (0) + +#define _NFB_BUS_MI_MEMCPY_CYCLE_AS(nbyte, size, src, dst, mtype, wc_used, wc_instr) \ +do { \ + while (*nbyte >= (size)) { \ + *(mtype *) *(dst) = *(const mtype *) *(src); \ + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ + } \ +} while (0) + + +static inline bool nfb_bus_mi_memcopy_simple(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) +{ + (void) offset; + (void) wc_used; + + if (nbyte == 4) { + *(uint32_t *) dst = *(const uint32_t *) src; + return true; + } else if (nbyte == 8) { + *(uint64_t *) dst = *(const uint64_t *) src; + return true; + } + return false; +} + +static inline bool nfb_bus_mi_memcopy_prelude(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) +{ + /* The offset variable is just for alignment check. The dst variable is alredy offseted. */ + /* Align access on 4/8B boundary first */ + if (*offset & 0x03) { + if (*offset & 0x01 && *nbyte >= 1) { + *(uint8_t *) *dst = *(const uint8_t *) *src; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 1, src, dst, uint8_t, wc_used, false); + *offset += 1; + } + if (*offset & 0x02 && *nbyte >= 2) { + *(uint16_t *) *dst = *(const uint16_t *) *src; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 2, src, dst, uint16_t, wc_used, false); + *offset += 2; + } + } + + if (*offset & 0x04 && *nbyte >= 4) { + *(uint32_t *) *dst = *(const uint32_t *) *src; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 4, src, dst, uint32_t, wc_used, false); + *offset += 4; + } + return false; +} + +#ifdef CONFIG_HAVE_MAVX2 +static inline bool nfb_bus_mi_memcopy_interlude_avx_sse2(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) +{ + (void) offset; + + bool src256a = ((uintptr_t) *src & 0x1F) ? false : true; + bool dst256a = ((uintptr_t) *dst & 0x1F) ? false : true; + bool src128a = ((uintptr_t) *src & 0x0F) ? false : true; + bool dst128a = ((uintptr_t) *dst & 0x0F) ? false : true; + + /* The _mm_stream* instructions are using the non-temporal hint. + * The non-temporal hint is implemented by using a write combining (WC) memory type protocol. + * The WC protocol uses a weakly-ordered memory consistency model, fencing operation should be used. */ + + if (src256a && dst256a) { + _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, 32, src, dst, __m256i, _mm256_stream_si256, wc_used, true); + } else if (src256a && !dst256a) { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 32, src, dst, __m256i, _mm256_stream_load_si256, _mm256_storeu_si256, wc_used, false); + } else if (!src256a && dst256a) { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 32, src, dst, __m256i, _mm256_loadu_si256, _mm256_store_si256, wc_used, false); + } else { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 32, src, dst, __m256i, _mm256_loadu_si256, _mm256_storeu_si256, wc_used, false); + } + + if (src128a && dst128a) { + _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, 16, src, dst, __m128i, _mm_stream_si128, wc_used, true); + } else if (src128a && !dst128a) { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_load_si128, _mm_storeu_si128, wc_used, false); + } else if (!src128a && dst128a) { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_loadu_si128, _mm_stream_si128, wc_used, false); + } else { + _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_loadu_si128, _mm_storeu_si128, wc_used, false); + } + + return false; +} +#endif + +static inline bool nfb_bus_mi_memcopy_postlude(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) +{ + (void) offset; + + _NFB_BUS_MI_MEMCPY_CYCLE_AS(nbyte, 8, src, dst, uint64_t, wc_used, false); + + /* Access the remaining bytes */ + if (*nbyte >= 4) { + *(uint32_t *) *dst = *(const uint32_t *) *src; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 4, src, dst, uint32_t, wc_used, false); + } + if (*nbyte >= 2) { + *(uint16_t *) *dst = *(const uint16_t *) *src; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 2, src, dst, uint16_t, wc_used, false); + } + if (*nbyte >= 1) { + *(uint8_t *) *dst = *(const uint8_t *) *src; + _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 1, src, dst, uint8_t, wc_used, false); + } + + return false; +} + +static inline ssize_t nfb_bus_mi_memcopy_avx2_sse2(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) +{ + ssize_t ret = nbyte; + if (nfb_bus_mi_memcopy_simple(dst, src, nbyte, offset, wc_used)) + return ret; + + if (nfb_bus_mi_memcopy_prelude(&dst, &src, &nbyte, &offset, wc_used)) + return ret; +#ifdef CONFIG_HAVE_MAVX2 + if (nfb_bus_mi_memcopy_interlude_avx_sse2(&dst, &src, &nbyte, &offset, wc_used)) + return ret; +#endif + if (nfb_bus_mi_memcopy_postlude(&dst, &src, &nbyte, &offset, wc_used)) + return ret; + + return ret; +} + +static inline ssize_t nfb_bus_mi_memcopy_noopt(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) +{ + ssize_t ret = nbyte; + if (nfb_bus_mi_memcopy_simple(dst, src, nbyte, offset, wc_used)) + return ret; + + if (nfb_bus_mi_memcopy_prelude(&dst, &src, &nbyte, &offset, wc_used)) + return ret; + if (nfb_bus_mi_memcopy_postlude(&dst, &src, &nbyte, &offset, wc_used)) + return ret; + + return ret; +} diff --git a/libnfb/src/bus/mi.c b/libnfb/src/bus/mi.c index ba30552a..bd94b925 100644 --- a/libnfb/src/bus/mi.c +++ b/libnfb/src/bus/mi.c @@ -46,44 +46,7 @@ struct nfb_bus_mi_priv * INFO2: Also Valgrind does ugly accesses with classic memcpy function * Here is a workaround for these issues */ - -#define _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr) \ -do { \ - if (*nbyte == (size)) { \ - if (wc_instr) \ - *wc_used = true; \ - return true; \ - } \ - *(src) = (const mtype *) *(src) + 1; \ - *(dst) = (mtype *) *(dst) + 1; \ - *nbyte -= (size); \ -} while (0) - -#define _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, size, src, dst, mtype, load, store, wc_used, wc_instr) \ -do { \ - mtype tmp; \ - while (*nbyte >= (size)) { \ - tmp = load(*(src)); \ - store(*(dst), tmp); \ - _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ - } \ -} while (0) - -#define _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, size, src, dst, mtype, stream, wc_used, wc_instr) \ -do { \ - while (*nbyte >= (size)) { \ - stream(*(dst), *(const mtype *) *(src)); \ - _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ - } \ -} while (0) - -#define _NFB_BUS_MI_MEMCPY_CYCLE_AS(nbyte, size, src, dst, mtype, wc_used, wc_instr) \ -do { \ - while (*nbyte >= (size)) { \ - *(mtype *) *(dst) = *(const mtype *) *(src); \ - _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, size, src, dst, mtype, wc_used, wc_instr); \ - } \ -} while (0) +#include #define __NFB_BUS_MI_MEMCOPY_TEMPLATE(impl) \ @@ -109,139 +72,6 @@ static inline ssize_t _nfb_bus_mi_memcopy_wr_##impl(void *bus_priv, const void * } -static inline bool nfb_bus_mi_memcopy_simple(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) -{ - (void) offset; - (void) wc_used; - - if (nbyte == 4) { - *(uint32_t *) dst = *(const uint32_t *) src; - return true; - } else if (nbyte == 8) { - *(uint64_t *) dst = *(const uint64_t *) src; - return true; - } - return false; -} - -static inline bool nfb_bus_mi_memcopy_prelude(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) -{ - /* The offset variable is just for alignment check. The dst variable is alredy offseted. */ - /* Align access on 4/8B boundary first */ - if (*offset & 0x03) { - if (*offset & 0x01 && *nbyte >= 1) { - *(uint8_t *) *dst = *(const uint8_t *) *src; - _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 1, src, dst, uint8_t, wc_used, false); - *offset += 1; - } - if (*offset & 0x02 && *nbyte >= 2) { - *(uint16_t *) *dst = *(const uint16_t *) *src; - _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 2, src, dst, uint16_t, wc_used, false); - *offset += 2; - } - } - - if (*offset & 0x04 && *nbyte >= 4) { - *(uint32_t *) *dst = *(const uint32_t *) *src; - _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 4, src, dst, uint32_t, wc_used, false); - *offset += 4; - } - return false; -} - -#ifdef CONFIG_HAVE_MAVX2 -static inline bool nfb_bus_mi_memcopy_interlude_avx_sse2(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) -{ - (void) offset; - - bool src256a = ((uintptr_t) *src & 0x1F) ? false : true; - bool dst256a = ((uintptr_t) *dst & 0x1F) ? false : true; - bool src128a = ((uintptr_t) *src & 0x0F) ? false : true; - bool dst128a = ((uintptr_t) *dst & 0x0F) ? false : true; - - /* The _mm_stream* instructions are using the non-temporal hint. - * The non-temporal hint is implemented by using a write combining (WC) memory type protocol. - * The WC protocol uses a weakly-ordered memory consistency model, fencing operation should be used. */ - - if (src256a && dst256a) { - _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, 32, src, dst, __m256i, _mm256_stream_si256, wc_used, true); - } else if (src256a && !dst256a) { - _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 32, src, dst, __m256i, _mm256_stream_load_si256, _mm256_storeu_si256, wc_used, false); - } else if (!src256a && dst256a) { - _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 32, src, dst, __m256i, _mm256_loadu_si256, _mm256_store_si256, wc_used, false); - } else { - _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 32, src, dst, __m256i, _mm256_loadu_si256, _mm256_storeu_si256, wc_used, false); - } - - if (src128a && dst128a) { - _NFB_BUS_MI_MEMCPY_CYCLE_ST(nbyte, 16, src, dst, __m128i, _mm_stream_si128, wc_used, true); - } else if (src128a && !dst128a) { - _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_load_si128, _mm_storeu_si128, wc_used, false); - } else if (!src128a && dst128a) { - _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_loadu_si128, _mm_stream_si128, wc_used, false); - } else { - _NFB_BUS_MI_MEMCPY_CYCLE_LS(nbyte, 16, src, dst, __m128i, _mm_loadu_si128, _mm_storeu_si128, wc_used, false); - } - - return false; -} -#endif - -static inline bool nfb_bus_mi_memcopy_postlude(void **dst, const void **src, size_t *nbyte, size_t *offset, bool *wc_used) -{ - (void) offset; - - _NFB_BUS_MI_MEMCPY_CYCLE_AS(nbyte, 8, src, dst, uint64_t, wc_used, false); - - /* Access the remaining bytes */ - if (*nbyte >= 4) { - *(uint32_t *) *dst = *(const uint32_t *) *src; - _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 4, src, dst, uint32_t, wc_used, false); - } - if (*nbyte >= 2) { - *(uint16_t *) *dst = *(const uint16_t *) *src; - _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 2, src, dst, uint16_t, wc_used, false); - } - if (*nbyte >= 1) { - *(uint8_t *) *dst = *(const uint8_t *) *src; - _NFB_BUS_MI_MEMCPY_CYCLE_ITER(nbyte, 1, src, dst, uint8_t, wc_used, false); - } - - return false; -} - -static inline ssize_t nfb_bus_mi_memcopy_avx2_sse2(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) -{ - ssize_t ret = nbyte; - if (nfb_bus_mi_memcopy_simple(dst, src, nbyte, offset, wc_used)) - return ret; - - if (nfb_bus_mi_memcopy_prelude(&dst, &src, &nbyte, &offset, wc_used)) - return ret; -#ifdef CONFIG_HAVE_MAVX2 - if (nfb_bus_mi_memcopy_interlude_avx_sse2(&dst, &src, &nbyte, &offset, wc_used)) - return ret; -#endif - if (nfb_bus_mi_memcopy_postlude(&dst, &src, &nbyte, &offset, wc_used)) - return ret; - - return ret; -} - -static inline ssize_t nfb_bus_mi_memcopy_noopt(void *dst, const void *src, size_t nbyte, size_t offset, bool *wc_used) -{ - ssize_t ret = nbyte; - if (nfb_bus_mi_memcopy_simple(dst, src, nbyte, offset, wc_used)) - return ret; - - if (nfb_bus_mi_memcopy_prelude(&dst, &src, &nbyte, &offset, wc_used)) - return ret; - if (nfb_bus_mi_memcopy_postlude(&dst, &src, &nbyte, &offset, wc_used)) - return ret; - - return ret; -} - __NFB_BUS_MI_MEMCOPY_TEMPLATE(avx2_sse2) __NFB_BUS_MI_MEMCOPY_TEMPLATE(noopt) From cad1f2d42fa0f01ffa01c86013c463d11c17e05e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 30 May 2025 15:33:46 +0200 Subject: [PATCH 367/518] fix(pynfb - eth): use None for unavailable Eth Devicetree subnodes on init --- pynfb/nfb/eth.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pynfb/nfb/eth.py b/pynfb/nfb/eth.py index 41a78a82..4a7a8784 100644 --- a/pynfb/nfb/eth.py +++ b/pynfb/nfb/eth.py @@ -14,10 +14,11 @@ class Eth: """ def __init__(self, nfb: libnfb.Nfb, node: fdt.Node) -> None: - self.rxmac = libnetcope.RxMac(nfb, nfb.fdt_get_phandle(node.get_property('rxmac').value)) - self.txmac = libnetcope.TxMac(nfb, nfb.fdt_get_phandle(node.get_property('txmac').value)) - self.pcspma = PcsPma(nfb, nfb.fdt_get_phandle(node.get_property('pcspma').value)) - self.pmd = libnetcope.Transceiver(nfb, nfb.fdt_get_phandle(node.get_property('pmd').value)) + sn = {pn: node.get_property(pn) for pn in ['rxmac', 'txmac', 'pcspma', 'pmd']} + self.rxmac = libnetcope.RxMac(nfb, nfb.fdt_get_phandle(sn['rxmac'].value)) if sn['rxmac'] else None + self.txmac = libnetcope.TxMac(nfb, nfb.fdt_get_phandle(sn['txmac'].value)) if sn['txmac'] else None + self.pcspma = PcsPma(nfb, nfb.fdt_get_phandle(sn['pcspma'].value)) if sn['pcspma'] else None + self.pmd = libnetcope.Transceiver(nfb, nfb.fdt_get_phandle(sn['pmd'].value)) if sn['pmd'] else None def _common_action(self, action: str, *args: Any, **kwargs: Any) -> List[Any]: return [ From c105ab27c35334a683f95be2f8aa2e704d9390f7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 30 May 2025 16:28:30 +0200 Subject: [PATCH 368/518] chore(style): cleanup code style --- doc/conf.py | 11 +++-------- doc/tools/nfb-busdebugctl.rst | 6 ++---- doc/tools/nfb-tools.rst | 1 + examples/pynfb/read_temp.py | 19 +++++++++++-------- .../python/nfb/ext/grpc/server.py | 3 ++- ext/libnfb_ext_grpc/python/setup.py | 2 ++ .../nfb/ext/python/__init__.py | 4 +++- ext/libnfb_ext_python/setup.py | 1 - pynfb/examples/00-quick-reference.py | 2 +- pynfb/examples/01-basics.py | 2 +- pynfb/examples/02-data-transfer.py | 2 +- pynfb/examples/03-eth.py | 2 +- pynfb/examples/04-mi-comp-wrap.py | 2 +- python/nfb-tools/nfbbootstrap/dfl.py | 9 ++++++--- .../nfb-tools/nfbbootstrap/nfb_bootstrap.py | 1 + python/nfb-tools/nfbmeter/eventcounter.py | 2 +- python/nfb-tools/setup.py | 4 ++-- 17 files changed, 39 insertions(+), 34 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 345e07be..27b77fa4 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,4 +1,5 @@ -import subprocess, os, sys +import subprocess + extensions = [ 'sphinx.ext.autodoc', @@ -16,7 +17,7 @@ subprocess.call('make clean', shell=True) subprocess.call('cd ../libnfb/doc/; doxygen', shell=True) -breathe_projects = { "libnfb": "../libnfb/doc/xml/" } +breathe_projects = {"libnfb": "../libnfb/doc/xml/"} breathe_default_project = "libnfb" html_theme = "sphinx_rtd_theme" @@ -24,14 +25,8 @@ kerneldoc_bin = '../../linux/scripts/kernel-doc' kerneldoc_srctree = '../drivers/' -sys.path.append('../../linux/Documentation/sphinx') -sys.path.append('../pynfb/') - project = 'NFB Software User Guide' copyright = '2022, CESNET z.s.p.o.' author = 'CESNET TMC' release = '6.16.0' - -from nfb import libnfb -from nfb import libnetcope diff --git a/doc/tools/nfb-busdebugctl.rst b/doc/tools/nfb-busdebugctl.rst index d608ee5e..606c2149 100644 --- a/doc/tools/nfb-busdebugctl.rst +++ b/doc/tools/nfb-busdebugctl.rst @@ -108,9 +108,8 @@ How to read the probed data The following diagram is borrowed from the documentation of the `Streaming Debug components `_. It shows a simple pipeline of three FW components (modules): A, B, and C. -.. _figure1: -.. image:: img/nfb-busdebugctl_example1.drawio.svg +.. figure:: img/nfb-busdebugctl_example1.drawio.svg :align: center :width: 60 % @@ -130,9 +129,8 @@ How to determine which component is at flaw? This is best explained using a picture. The following picture builds on the example above, showing the same pipeline with connected Debug Probes. -.. _figure2: -.. image:: img/nfb-busdebugctl_example2.drawio.svg +.. figure:: img/nfb-busdebugctl_example2.drawio.svg :align: center :width: 60 % diff --git a/doc/tools/nfb-tools.rst b/doc/tools/nfb-tools.rst index d57d2af1..b4b175e4 100644 --- a/doc/tools/nfb-tools.rst +++ b/doc/tools/nfb-tools.rst @@ -14,6 +14,7 @@ NFB tools nfb-mdio nfb-dma nfb-tsu + nfb-busdebugctl .. rubric:: :ref:`nfb-info` .. include:: nfb-info.rst diff --git a/examples/pynfb/read_temp.py b/examples/pynfb/read_temp.py index 4f25236f..49aba60c 100755 --- a/examples/pynfb/read_temp.py +++ b/examples/pynfb/read_temp.py @@ -1,14 +1,17 @@ -#!/usr/bin/python +#!/usr/bin/env python import nfb + class TempComp(nfb.NFBComp): - def __init__(self, dev): - nfb.NFBComp.__init__(self, dev.getComp("netcope,idcomp", 0)) - def getTemp(self): - self.write32(0x44, 0) - reg = self.read16(0x80) - return (reg * 0.0076900482177734375 - 273.15) - + def __init__(self, dev): + nfb.NFBComp.__init__(self, dev.getComp("netcope,idcomp", 0)) + + def getTemp(self): + self.write32(0x44, 0) + reg = self.read16(0x80) + return (reg * 0.0076900482177734375 - 273.15) + + #dev = nfb.NFBDevice("/dev/nfb0") #comp = dev.getComp("netcope,bus,mi", 0) #print("Read SWID:", hex(comp.read32(4))) diff --git a/ext/libnfb_ext_grpc/python/nfb/ext/grpc/server.py b/ext/libnfb_ext_grpc/python/nfb/ext/grpc/server.py index 077d0749..271e62e4 100644 --- a/ext/libnfb_ext_grpc/python/nfb/ext/grpc/server.py +++ b/ext/libnfb_ext_grpc/python/nfb/ext/grpc/server.py @@ -32,7 +32,7 @@ def Server(servicer, addr='127.0.0.1', port=50051): server.start() server.__path = f'libnfb-ext-grpc.so:grpc:{addr}:{port}' - server.path = lambda : server.__path + server.path = lambda: server.__path return server @@ -43,3 +43,4 @@ def run_server(servicer=None, **kwargs): server = Server(svc, **kwargs) # server.shutdown() # server.close() + return server diff --git a/ext/libnfb_ext_grpc/python/setup.py b/ext/libnfb_ext_grpc/python/setup.py index eaa24ade..e52884d8 100644 --- a/ext/libnfb_ext_grpc/python/setup.py +++ b/ext/libnfb_ext_grpc/python/setup.py @@ -1,9 +1,11 @@ from setuptools import setup from setuptools.command.build import build + class custom_build(build): sub_commands = [ ('build_grpc', None), ] + build.sub_commands + setup(cmdclass={'build': custom_build}) diff --git a/ext/libnfb_ext_python/nfb/ext/python/__init__.py b/ext/libnfb_ext_python/nfb/ext/python/__init__.py index 04b28862..9e8167c1 100644 --- a/ext/libnfb_ext_python/nfb/ext/python/__init__.py +++ b/ext/libnfb_ext_python/nfb/ext/python/__init__.py @@ -1,17 +1,19 @@ "libnfb-ext for use in Python" from abc import ABC, abstractmethod -import importlib import fdt from . import shim + class AbstractNdpQueue(ABC): def start(self): pass + def stop(self): pass + class AbstractNdpQueueRx(AbstractNdpQueue): @abstractmethod def burst_get(self, count): diff --git a/ext/libnfb_ext_python/setup.py b/ext/libnfb_ext_python/setup.py index 474c2222..20e71086 100644 --- a/ext/libnfb_ext_python/setup.py +++ b/ext/libnfb_ext_python/setup.py @@ -1,4 +1,3 @@ -import Cython from Cython.Build import cythonize from setuptools import Extension, setup, find_namespace_packages diff --git a/pynfb/examples/00-quick-reference.py b/pynfb/examples/00-quick-reference.py index 1311634c..4a4c9326 100644 --- a/pynfb/examples/00-quick-reference.py +++ b/pynfb/examples/00-quick-reference.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 ############################################# # Python NFB API examples - quick reference # diff --git a/pynfb/examples/01-basics.py b/pynfb/examples/01-basics.py index 09efcaa6..dcd05b8f 100644 --- a/pynfb/examples/01-basics.py +++ b/pynfb/examples/01-basics.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 #################################### # Python NFB API examples - basics # diff --git a/pynfb/examples/02-data-transfer.py b/pynfb/examples/02-data-transfer.py index eb54d8eb..d3841d66 100644 --- a/pynfb/examples/02-data-transfer.py +++ b/pynfb/examples/02-data-transfer.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 ########################################### # Python NFB API examples - data transfer # diff --git a/pynfb/examples/03-eth.py b/pynfb/examples/03-eth.py index 0a9c4e12..5e3b4331 100644 --- a/pynfb/examples/03-eth.py +++ b/pynfb/examples/03-eth.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 ############################################ # Python NFB API examples - Ethernet ports # diff --git a/pynfb/examples/04-mi-comp-wrap.py b/pynfb/examples/04-mi-comp-wrap.py index 887f9339..6d60bc72 100644 --- a/pynfb/examples/04-mi-comp-wrap.py +++ b/pynfb/examples/04-mi-comp-wrap.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 ########################################## # Python NFB API examples - MI comp wrap # diff --git a/python/nfb-tools/nfbbootstrap/dfl.py b/python/nfb-tools/nfbbootstrap/dfl.py index e823683f..38c5e3ae 100644 --- a/python/nfb-tools/nfbbootstrap/dfl.py +++ b/python/nfb-tools/nfbbootstrap/dfl.py @@ -23,12 +23,15 @@ def bit(b): return (1 << b) + def bitmask(b): return (1 << b) - 1 + def bit_get(val, b): return (val >> b) & 1 + def field_get(val, bto, bfrom): return (val >> bfrom) & bitmask(bto - bfrom) @@ -38,11 +41,11 @@ def feature_id(value): type = field_get(64, 60, value) if type == DFH_TYPE_FIU: - return FEATURE_ID_FIU_HEADER + return FEATURE_ID_FIU_HEADER elif type == DFH_TYPE_PRIVATE: - return id + return id elif type == DFH_TYPE_AFU: - return FEATURE_ID_AFU + return FEATURE_ID_AFU def parse_dfl_from(bar, offset, out_dict, verbose): diff --git a/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py index 511886e2..b2d106b8 100755 --- a/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py +++ b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py @@ -51,5 +51,6 @@ def main(): with open(args.dtb, "wb") as f: f.write(dt.to_dtb(version=17)) + if __name__ == "__main__": main() diff --git a/python/nfb-tools/nfbmeter/eventcounter.py b/python/nfb-tools/nfbmeter/eventcounter.py index bd38109a..680bb6a3 100644 --- a/python/nfb-tools/nfbmeter/eventcounter.py +++ b/python/nfb-tools/nfbmeter/eventcounter.py @@ -106,7 +106,7 @@ def stats_flush_captured(self): #def read_stats_captured(self, count: int = 0, wait: bool = False): def read_stats_captured(self): ret = None - ret = {"cycles": 0, "events": 0, "wraps": 0} # What's better to return? + ret = {"cycles": 0, "events": 0, "wraps": 0} # What's better to return? valid = True while valid: reg = self._comp.read32(self._REG_CAPTURE_FIFO) diff --git a/python/nfb-tools/setup.py b/python/nfb-tools/setup.py index 02b7785c..d848acae 100644 --- a/python/nfb-tools/setup.py +++ b/python/nfb-tools/setup.py @@ -2,7 +2,7 @@ setup( name='nfbtools', - version = "0.2.0", + version="0.2.0", packages=[ "nfbmeter", "nfbbootstrap", @@ -15,7 +15,7 @@ entry_points={ 'console_scripts': [ 'nfb-meter=nfbmeter.nfbmeter:main', - 'nfb-bootstrap = nfbbootstrap.nfb_bootstrap:main', + 'nfb-bootstrap=nfbbootstrap.nfb_bootstrap:main', ], }, install_requires=[ From cef7cdcb821ffc11e61c70e659c5b770a0503d0c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 30 May 2025 16:23:26 +0200 Subject: [PATCH 369/518] ci: add style checkers --- .gitlab-ci.yml | 8 ++++++- tests/ci/check.gitlab-ci.yaml | 40 +++++++++++++++++++++++++++++++++++ tests/ci/pycodestyle.sh | 2 ++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/ci/check.gitlab-ci.yaml create mode 100755 tests/ci/pycodestyle.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3559d35d..455bcab8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,17 @@ +stages: + - check + - deploy + variables: GIT_STRATEGY: clone GIT_SUBMODULE_STRATEGY: recursive -image: python:3.7-alpine +include: + - local: "tests/ci/check.gitlab-ci.yaml" pages: stage: deploy + image: python:3.9-alpine script: - apk add -U make doxygen musl-dev py3-setuptools - apk add -U gcc cmake dtc-dev numactl-dev ncurses-dev libarchive-dev libconfig libconfig-dev automake autoconf curl git cython python3-dev dtc-dev linux-headers zlib-dev diff --git a/tests/ci/check.gitlab-ci.yaml b/tests/ci/check.gitlab-ci.yaml new file mode 100644 index 00000000..729e9227 --- /dev/null +++ b/tests/ci/check.gitlab-ci.yaml @@ -0,0 +1,40 @@ +variables: + BASE_COMMIT_SHA: $CI_COMMIT_SHA + +workflow: + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + variables: + BASE_COMMIT_SHA: $CI_MERGE_REQUEST_DIFF_BASE_SHA + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + variables: + BASE_COMMIT_SHA: $CI_COMMIT_SHA + +editorconfig: + stage: check + needs: [] + image: mstruebing/editorconfig-checker + script: [ec] + +pycodestyle: + stage: check + needs: [] + image: + name: python:3.11-slim + entrypoint: [""] + before_script: + - pip install flake8 + script: + - sh tests/ci/pycodestyle.sh + +commitlint: + stage: check + needs: [] + image: registry.hub.docker.com/library/node:alpine + variables: + GIT_DEPTH: 0 + before_script: + - apk add --no-cache git + - npm install --save-dev @commitlint/config-conventional @commitlint/cli + script: + - npx commitlint --extends '@commitlint/config-conventional' --from "${BASE_COMMIT_SHA}" --to "${CI_COMMIT_SHA}" diff --git a/tests/ci/pycodestyle.sh b/tests/ci/pycodestyle.sh new file mode 100755 index 00000000..551df7f5 --- /dev/null +++ b/tests/ci/pycodestyle.sh @@ -0,0 +1,2 @@ +#!/bin/sh +flake8 --statistics --extend-ignore=E221,E261,E265,E501 From 8a713664db42ca283f25b948915200e072aee5ae Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 30 May 2025 17:02:44 +0200 Subject: [PATCH 370/518] fix(nfb/ext.h): add missing header --- libnfb/include/nfb/ext.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libnfb/include/nfb/ext.h b/libnfb/include/nfb/ext.h index d685a77b..7b67f004 100644 --- a/libnfb/include/nfb/ext.h +++ b/libnfb/include/nfb/ext.h @@ -12,6 +12,7 @@ #ifndef __KERNEL__ #include +#include #endif #ifdef __cplusplus From 460e36d2a3306fbf902385de6de6a6a56acbef1a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 5 Jun 2025 14:54:37 +0200 Subject: [PATCH 371/518] fix(ndp.h): make packet parameter to the ndp_packet_flag_header_id_get constant --- libnfb/include/nfb/ndp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/nfb/ndp.h b/libnfb/include/nfb/ndp.h index 6a9f3168..f0c42450 100644 --- a/libnfb/include/nfb/ndp.h +++ b/libnfb/include/nfb/ndp.h @@ -63,7 +63,7 @@ static inline void ndp_packet_flag_header_id_set(struct ndp_packet *p, uint8_t i p->flags = (p->flags & ~0x3) | (id & 0x3); } -static inline uint8_t ndp_packet_flag_header_id_get(struct ndp_packet *p) +static inline uint8_t ndp_packet_flag_header_id_get(const struct ndp_packet *p) { return p->flags & 0x3; } From 458b78b66341bdc9ec8f2d11887520090d00daf0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 9 Jun 2025 15:42:14 +0200 Subject: [PATCH 372/518] bump version to 6.27.0 --- Changelog | 7 +++++++ VERSION | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 34a31545..5ce12e7a 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,10 @@ +* Mon Jun 9 2025 Martin Spinler - 6.27.0-1 +- [FEATURE]: add I2C / QSFP support for BittWare BMC (ia-440i) +- [FEATURE] nfb-dma/driver: add dynamic netdev management for ndp_netdev +- [OPT] driver: check kernel configure flags in parallel +- [FIX] MI driver: use libnfb MI memcpy functionality in kernel driver too (fixes memcpy_*io) +- [FIX] NDP Calypte: lot of fixes and improvements + * Mon May 5 2025 Martin Spinler - 6.26.4-1 - [FIX] libnfb/NDP: remove double sync on queue start causing performance loss / blockage - [FIX] nfb-eth: wait for QSFP ready when reading monitoring data diff --git a/VERSION b/VERSION index 30bfaeb1..9cd1a39f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.26.4 +6.27.0 From ce88a426dc35ec2e0a8e71f9d036ce5feaa35470 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 4 Dec 2024 08:27:42 +0100 Subject: [PATCH 373/518] docs(libnetcope - rxmac): fix description --- libnfb/include/netcope/rxmac.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libnfb/include/netcope/rxmac.h b/libnfb/include/netcope/rxmac.h index 1973921c..116335a4 100644 --- a/libnfb/include/netcope/rxmac.h +++ b/libnfb/include/netcope/rxmac.h @@ -55,7 +55,7 @@ struct nc_rxmac_etherstats { unsigned long long pkts; /*!< Total number of packets received (including bad packets) */ unsigned long long broadcastPkts; /*!< Total number of good broadcast packets received */ unsigned long long multicastPkts; /*!< Total number of good multicast packets received */ - unsigned long long CRCAlignErrors; /*!< Total number of received packets that were between 64 and 1518 bytes long and had FCS error */ + unsigned long long CRCAlignErrors; /*!< Total number of received packets that had FCS error; not exactly etherStatsCRCAlignErrors (condition: were between 64 and 1518 bytes long) */ unsigned long long undersizePkts; /*!< Total number of received packets that were shorter than 64 bytes and OK */ unsigned long long oversizePkts; /*!< Total number of received packets that were longer than 1518 bytes and OK */ unsigned long long fragments; /*!< Total number of received packets that were shorter than 64 bytes and had FCS error */ @@ -66,8 +66,8 @@ struct nc_rxmac_etherstats { unsigned long long pkts256to511Octets; /*!< Total number of received packets that were between 256 and 511 bytes long */ unsigned long long pkts512to1023Octets; /*!< Total number of received packets that were between 512 and 1023 bytes long */ unsigned long long pkts1024to1518Octets; /*!< Total number of received packets that were between 1024 and 1518 bytes long */ - unsigned long long underMinPkts; /*!< Total number of received packets that were shorter than configured minimum */ - unsigned long long overMaxPkts; /*!< Total number of received packets that were longer than configured maximum */ + unsigned long long underMinPkts; /*!< Total number of received packets that were shorter than configured minimum (not in etherStats) */ + unsigned long long overMaxPkts; /*!< Total number of received packets that were longer than configured maximum (not in etherStats) */ }; struct nc_rxmac_status { From 1e2ffdfd9d8ffb4ddea11dd39f7f2126fa040da2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 4 Dec 2024 08:39:50 +0100 Subject: [PATCH 374/518] perf(libnetcope - rxmac/txmac): read all registers at once Status / statistics read now uses temporary register buffer for burst read, the value pairing is done in memory. This approach generates less count of read requests, which improves latency and system load. --- libnfb/include/netcope/rxmac.h | 232 ++++++++++++++++----------------- libnfb/include/netcope/txmac.h | 30 ++++- 2 files changed, 142 insertions(+), 120 deletions(-) diff --git a/libnfb/include/netcope/rxmac.h b/libnfb/include/netcope/rxmac.h index 116335a4..09d921d3 100644 --- a/libnfb/include/netcope/rxmac.h +++ b/libnfb/include/netcope/rxmac.h @@ -101,78 +101,6 @@ static inline void nc_rxmac_set_error_mask(struct nc_rxmac *mac, uns /* ~~~~[ REGISTERS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #define RXMAC_REG_CNT_PACKETS_LO 0x0000 #define RXMAC_REG_CNT_PACKETS_HI 0x0010 -#define RXMAC_REG_CNT_RECEIVED_LO 0x0004 -#define RXMAC_REG_CNT_RECEIVED_HI 0x0014 -#define RXMAC_REG_CNT_DISCARDED_LO 0x0008 -#define RXMAC_REG_CNT_DISCARDED_HI 0x0018 -#define RXMAC_REG_CNT_OVERFLOW_LO 0x000C -#define RXMAC_REG_CNT_OVERFLOW_HI 0x001C -#define RXMAC_REG_CNT_OCTETS_LO 0x003C -#define RXMAC_REG_CNT_OCTETS_HI 0x0040 - -/* Total received packets with bad CRC (etherStatsCRCAlignErrors) */ -#define RXMAC_REG_CNT_ES_CRC_ERR_LO 0x0100 -#define RXMAC_REG_CNT_ES_CRC_ERR_HI 0x0138 - -/* Total received packets over set MTU */ -#define RXMAC_REG_CNT_ES_OVERSIZE_LO 0x0104 -#define RXMAC_REG_CNT_ES_OVERSIZE_HI 0x013C - -/* Total received packets below set minimal length */ -#define RXMAC_REG_CNT_ES_UNDERSIZE_LO 0x0108 -#define RXMAC_REG_CNT_ES_UNDERSIZE_HI 0x0140 - -/* Total received packets with broadcast address (etherStatsBroadcastPkts) */ -#define RXMAC_REG_CNT_ES_BCAST_LO 0x010C -#define RXMAC_REG_CNT_ES_BCAST_HI 0x0144 - -/* Total received packets with multicast address (etherStatsMulticastPkts) */ -#define RXMAC_REG_CNT_ES_MCAST_LO 0x0110 -#define RXMAC_REG_CNT_ES_MCAST_HI 0x0148 - -/* Total received fragment frames (etherStatsFragments) */ -#define RXMAC_REG_CNT_ES_FRAGMENTS_LO 0x0114 -#define RXMAC_REG_CNT_ES_FRAGMENTS_HI 0x014C - -/* Total received jabber frames (etherStatsJabbers) */ -#define RXMAC_REG_CNT_ES_JABBERS_LO 0x0118 -#define RXMAC_REG_CNT_ES_JABBERS_HI 0x0150 - -/* Total transfered octets (etherStatsOctets) */ -#define RXMAC_REG_CNT_ES_OCTETS_LO 0x011C -#define RXMAC_REG_CNT_ES_OCTETS_HI 0x0154 - -/* Total received frames with length 64B (etherStatsPkts64Octets) */ -#define RXMAC_REG_CNT_ES_FRAMES_64_LO 0x0120 -#define RXMAC_REG_CNT_ES_FRAMES_64_HI 0x0158 - -/* Total received frames with length from 65B to 127B (etherStatsPkts65to127Octets) */ -#define RXMAC_REG_CNT_ES_FRAMES_65_127_LO 0x0124 -#define RXMAC_REG_CNT_ES_FRAMES_65_127_HI 0x015C - -/* Total received frames with length from 128B to 255B (etherStatsPkts128to255Octets) */ -#define RXMAC_REG_CNT_ES_FRAMES_128_255_LO 0x0128 -#define RXMAC_REG_CNT_ES_FRAMES_128_255_HI 0x0160 - -/* Total received frames with length from 256B to 511B (etherStatsPkts256to511Octets) */ -#define RXMAC_REG_CNT_ES_FRAMES_256_511_LO 0x012C -#define RXMAC_REG_CNT_ES_FRAMES_256_511_HI 0x0164 - -/* Total received frames with length from 512B to 1023B (etherStatsPkts512to1023Octets) */ -#define RXMAC_REG_CNT_ES_FRAMES_512_1023_LO 0x0130 -#define RXMAC_REG_CNT_ES_FRAMES_512_1023_HI 0x0168 - -/* Total received frames with length from 1024B to 1518B (etherStatsPkts1024to1518Octets) */ -#define RXMAC_REG_CNT_ES_FRAMES_1024_1518_LO 0x0134 -#define RXMAC_REG_CNT_ES_FRAMES_1024_1518_HI 0x016C - -/* Total received frames with length above 1518B (etherStatsOversizePkts) */ -#define RXMAC_REG_CNT_ES_FRAMES_OVER_1518_LO 0x0170 -#define RXMAC_REG_CNT_ES_FRAMES_OVER_1518_HI 0x0174 - -/* Total received frames with length below 64B (etherStatsUndersizePkts) */ -#define RXMAC_REG_CNT_ES_FRAMES_BELOW_64_LO 0x0178 -#define RXMAC_REG_CNT_ES_FRAMES_BELOW_64_HI 0x017C #define RXMAC_REG_ENABLE 0x0020 #define RXMAC_REG_ERROR_MASK 0x0024 @@ -194,10 +122,84 @@ enum nc_rxmac_cmds { RXMAC_CMD_RESET = 0x02, }; +union _nc_rxmac_reg_status_buffer { + /* Register range: 0x0020 - 0x003C */ + struct __attribute__((packed)) { + uint32_t enabled; + uint32_t error_mask; + uint32_t status; + uint32_t control; + uint32_t frame_length_min; + uint32_t frame_length_max; + uint32_t mac_filter; + } r1; +}; + +union _nc_rxmac_reg_buffer { + /* Register range: 0x0000 - 0x0020 */ + struct __attribute__((packed)) { + uint32_t total_l; + uint32_t received_l; + uint32_t discarded_l; + uint32_t overflowed_l; + uint32_t total_h; + uint32_t received_h; + uint32_t discarded_h; + uint32_t overflowed_h; + } r1; + + /* Register range: 0x003C - 0x0040 */ + struct __attribute__((packed)) { + uint32_t octets_l; + uint32_t octets_h; + } r2; + + /* Register range: 0x0100 - 0x0180 */ + struct __attribute__((packed)) { + uint32_t CRCAlignErrors_l; + uint32_t oversize_l; + uint32_t undersize_l; + uint32_t broadcastPkts_l; + uint32_t multicastPkts_l; + uint32_t fragments_l; + uint32_t jabbers_l; + uint32_t octets_l; + uint32_t pkts64Octets_l; + uint32_t pkts65to127Octets_l; + uint32_t pkts128to255Octets_l; + uint32_t pkts256to511Octets_l; + uint32_t pkts512to1023Octets_l; + uint32_t pkts1024to1518Octets_l; + uint32_t CRCAlignErrors_h; + uint32_t oversize_h; + uint32_t undersize_h; + uint32_t broadcastPkts_h; + uint32_t multicastPkts_h; + uint32_t fragments_h; + uint32_t jabbers_h; + uint32_t octets_h; + uint32_t pkts64Octets_h; + uint32_t pkts65to127Octets_h; + uint32_t pkts128to255Octets_h; + uint32_t pkts256to511Octets_h; + uint32_t pkts512to1023Octets_h; + uint32_t pkts1024to1518Octets_h; + uint32_t over1518_l; + uint32_t over1518_h; + uint32_t below64_l; + uint32_t below64_h; + } e1; +}; + #define RXMAC_READ_CNT(comp, name) \ (((uint64_t)nfb_comp_read32((comp), RXMAC_REG_CNT_##name##_HI)) << 32 | \ nfb_comp_read32((comp), RXMAC_REG_CNT_##name##_LO)) +#define _NC_RXMAC_REG_BUFFER_PAIR(s, name) ( \ + (((uint64_t)((s).name##_h)) << 32) | \ + (((uint64_t)((s).name##_l)) << 0) \ + ) + #define COMP_NETCOPE_RXMAC "netcope,rxmac" #define RXMAC_COMP_LOCK (1 << 0) @@ -277,27 +279,28 @@ static inline int nc_rxmac_get_link(struct nc_rxmac *mac) static inline int nc_rxmac_read_status(struct nc_rxmac *mac, struct nc_rxmac_status *s) { struct nfb_comp *comp = nfb_user_to_comp(mac); - uint32_t reg; + union _nc_rxmac_reg_status_buffer buf; if (!nfb_comp_lock(comp, RXMAC_COMP_LOCK)) return -EAGAIN; - s->enabled = nfb_comp_read32(comp, RXMAC_REG_ENABLE); - s->error_mask = nfb_comp_read32(comp, RXMAC_REG_ERROR_MASK); - s->mac_filter = (enum nc_rxmac_mac_filter) nfb_comp_read32(comp, RXMAC_REG_MAC_FILTER); - s->frame_length_min = nfb_comp_read32(comp, RXMAC_REG_FRAME_LEN_MIN); - s->frame_length_max = nfb_comp_read32(comp, RXMAC_REG_FRAME_LEN_MAX); + nfb_comp_read(comp, &buf.r1, sizeof(buf.r1), 0x0020); - reg = nfb_comp_read32(comp, RXMAC_REG_STATUS); - __nc_rxmac_update_mac_addr_count(mac, reg); + s->enabled = buf.r1.enabled; + s->error_mask = buf.r1.error_mask; + s->mac_filter = (enum nc_rxmac_mac_filter) buf.r1.mac_filter; + s->frame_length_min = buf.r1.frame_length_min; + s->frame_length_max = buf.r1.frame_length_max; - s->link_up = (reg & RXMAC_REG_STATUS_LINK) ? 1 : 0; - s->overflow = (reg & RXMAC_REG_STATUS_OVER) ? 1 : 0; + __nc_rxmac_update_mac_addr_count(mac, buf.r1.status); + + s->link_up = (buf.r1.status & RXMAC_REG_STATUS_LINK) ? 1 : 0; + s->overflow = (buf.r1.status & RXMAC_REG_STATUS_OVER) ? 1 : 0; s->mac_addr_count = nc_rxmac_mac_address_count(mac); s->frame_length_max_capable = mac->mtu; - s->speed = (enum nc_mac_speed) ((reg >> 4) & 0x7); + s->speed = (enum nc_mac_speed) ((buf.r1.status >> 4) & 0x7); switch (s->speed) { case MAC_SPEED_10G: case MAC_SPEED_40G: @@ -314,49 +317,46 @@ static inline int nc_rxmac_read_status(struct nc_rxmac *mac, struct nc_rxmac_sta static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_counters *c, struct nc_rxmac_etherstats *s) { struct nfb_comp *comp = nfb_user_to_comp(mac); - - unsigned long long cnt_total = 0; + union _nc_rxmac_reg_buffer buf; if (!nfb_comp_lock(comp, RXMAC_COMP_LOCK)) return -EAGAIN; nfb_comp_write32(comp, RXMAC_REG_CONTROL, RXMAC_CMD_STROBE); - if (c || s) { - cnt_total = RXMAC_READ_CNT(comp, PACKETS); - } - if (c) { - c->cnt_total = cnt_total; - c->cnt_received = RXMAC_READ_CNT(comp, RECEIVED); - c->cnt_overflowed = RXMAC_READ_CNT(comp, OVERFLOW); - c->cnt_erroneous = RXMAC_READ_CNT(comp, DISCARDED) - c->cnt_overflowed; - c->cnt_octets = RXMAC_READ_CNT(comp, OCTETS); + nfb_comp_read(comp, &buf.r1, sizeof(buf.r1), 0x0000); + c->cnt_total = _NC_RXMAC_REG_BUFFER_PAIR(buf.r1, total); + c->cnt_received = _NC_RXMAC_REG_BUFFER_PAIR(buf.r1, received); + c->cnt_overflowed = _NC_RXMAC_REG_BUFFER_PAIR(buf.r1, overflowed); + c->cnt_erroneous = _NC_RXMAC_REG_BUFFER_PAIR(buf.r1, discarded) - c->cnt_overflowed; + + nfb_comp_read(comp, &buf.r2, sizeof(buf.r2), 0x003C); + c->cnt_octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.r2, octets); } if (s) { - s->octets = RXMAC_READ_CNT(comp, ES_OCTETS); - s->pkts = cnt_total; - s->broadcastPkts = RXMAC_READ_CNT(comp, ES_BCAST); - s->multicastPkts = RXMAC_READ_CNT(comp, ES_MCAST); - s->CRCAlignErrors = RXMAC_READ_CNT(comp, ES_CRC_ERR); - if (mac->has_counter_below_64) { - s->undersizePkts = RXMAC_READ_CNT(comp, ES_FRAMES_BELOW_64); - } else { - s->undersizePkts = 0; - } - - s->underMinPkts = RXMAC_READ_CNT(comp, ES_UNDERSIZE); - s->overMaxPkts = RXMAC_READ_CNT(comp, ES_OVERSIZE); - s->oversizePkts = RXMAC_READ_CNT(comp, ES_FRAMES_OVER_1518); - s->fragments = RXMAC_READ_CNT(comp, ES_FRAGMENTS); - s->jabbers = RXMAC_READ_CNT(comp, ES_JABBERS); - s->pkts64Octets = RXMAC_READ_CNT(comp, ES_FRAMES_64); - s->pkts65to127Octets = RXMAC_READ_CNT(comp, ES_FRAMES_65_127); - s->pkts128to255Octets = RXMAC_READ_CNT(comp, ES_FRAMES_128_255); - s->pkts256to511Octets = RXMAC_READ_CNT(comp, ES_FRAMES_256_511); - s->pkts512to1023Octets = RXMAC_READ_CNT(comp, ES_FRAMES_512_1023); - s->pkts1024to1518Octets = RXMAC_READ_CNT(comp, ES_FRAMES_1024_1518); + nfb_comp_read(comp, &buf.e1, sizeof(buf.e1), 0x0100); + + s->pkts = c ? c->cnt_total : RXMAC_READ_CNT(comp, PACKETS); + s->undersizePkts = mac->has_counter_below_64 ? _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, below64) : 0; + + s->CRCAlignErrors = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, CRCAlignErrors); + s->broadcastPkts = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, broadcastPkts); + s->multicastPkts = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, multicastPkts); + s->fragments = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, fragments); + s->jabbers = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, jabbers); + s->octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, octets); + s->pkts64Octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, pkts64Octets); + s->pkts65to127Octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, pkts65to127Octets); + s->pkts128to255Octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, pkts128to255Octets); + s->pkts256to511Octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, pkts256to511Octets); + s->pkts512to1023Octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, pkts512to1023Octets); + s->pkts1024to1518Octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, pkts1024to1518Octets); + s->oversizePkts = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, over1518); + + s->underMinPkts = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, undersize); + s->overMaxPkts = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, oversize); } nfb_comp_unlock(comp, RXMAC_COMP_LOCK); diff --git a/libnfb/include/netcope/txmac.h b/libnfb/include/netcope/txmac.h index 85539913..80802800 100644 --- a/libnfb/include/netcope/txmac.h +++ b/libnfb/include/netcope/txmac.h @@ -69,10 +69,29 @@ enum nc_txmac_cmds { ((uint64_t)nfb_comp_read32((comp), TXMAC_REG_CNT_##name##_HI) << 32 | \ nfb_comp_read32((comp), TXMAC_REG_CNT_##name##_LO)) +#define _NC_TXMAC_REG_BUFFER_PAIR(s, name) ( \ + (((uint64_t)((s).name##_h)) << 32) | \ + (((uint64_t)((s).name##_l)) << 0) \ + ) + #define COMP_NETCOPE_TXMAC "netcope,txmac" #define TXMAC_COMP_LOCK (1 << 0) +union _nc_txmac_reg_buffer { + /* Register range: 0x0000 - 0x0020 */ + struct __attribute__((packed)) { + uint32_t total_l; + uint32_t octets_l; + uint32_t discarded_l; + uint32_t sent_l; + uint32_t total_h; + uint32_t octets_h; + uint32_t discarded_h; + uint32_t sent_h; + } r1; +}; + /* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ static inline struct nc_txmac *nc_txmac_open(struct nfb_device *dev, int fdt_offset) { @@ -143,16 +162,19 @@ static inline int nc_txmac_read_status(struct nc_txmac *mac, struct nc_txmac_sta static inline int nc_txmac_read_counters(struct nc_txmac *mac, struct nc_txmac_counters *counters) { struct nfb_comp *comp = nfb_user_to_comp(mac); + union _nc_txmac_reg_buffer buf; if (!nfb_comp_lock(comp, TXMAC_COMP_LOCK)) return -EAGAIN; nfb_comp_write32(comp, TXMAC_REG_CONTROL, TXMAC_CMD_STROBE); - counters->cnt_total = TXMAC_READ_CNT(comp, PACKETS); - counters->cnt_sent = TXMAC_READ_CNT(comp, SENT); - counters->cnt_erroneous = TXMAC_READ_CNT(comp, DISCARDED); - counters->cnt_octets = TXMAC_READ_CNT(comp, OCTETS); + nfb_comp_read(comp, &buf.r1, sizeof(buf.r1), 0x0000); + + counters->cnt_total = _NC_TXMAC_REG_BUFFER_PAIR(buf.r1, total); + counters->cnt_octets = _NC_TXMAC_REG_BUFFER_PAIR(buf.r1, octets); + counters->cnt_sent = _NC_TXMAC_REG_BUFFER_PAIR(buf.r1, sent); + counters->cnt_erroneous = _NC_TXMAC_REG_BUFFER_PAIR(buf.r1, discarded); nfb_comp_unlock(comp, TXMAC_COMP_LOCK); return 0; From 5b0599fb16757cdb63c50784a6f1bd53b915d5e7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 7 Apr 2025 12:37:48 +0200 Subject: [PATCH 375/518] feat(libnetcope - MAC): add statistic counters for version 3 --- libnfb/include/netcope/rxmac.h | 80 +++++++++++++++++++++++++++++----- libnfb/include/netcope/txmac.h | 53 +++++++++++++++++++--- 2 files changed, 115 insertions(+), 18 deletions(-) diff --git a/libnfb/include/netcope/rxmac.h b/libnfb/include/netcope/rxmac.h index 09d921d3..9a95de4b 100644 --- a/libnfb/include/netcope/rxmac.h +++ b/libnfb/include/netcope/rxmac.h @@ -40,14 +40,22 @@ struct nc_rxmac { unsigned has_counter_below_64 : 1; unsigned mac_addr_count_valid : 1; + unsigned has_ext_drop_counters: 1; }; struct nc_rxmac_counters { unsigned long long cnt_total; /*!< All processed frames */ + unsigned long long cnt_total_octets; /*!< All processed bytes */ unsigned long long cnt_octets; /*!< Correct octets */ unsigned long long cnt_received; /*!< Correct frames */ - unsigned long long cnt_erroneous; /*!< Discarded frames due to error */ - unsigned long long cnt_overflowed; /*!< Discarded frames due to buffer overflow */ + unsigned long long cnt_drop; /*!< All discarded frames (multiple discard reasons can occur at once) */ + unsigned long long cnt_overflowed; /*!< Discarded frames due to buffer overflow (subset of cnt_drop) */ + unsigned long long cnt_drop_disabled; /*!< Frames droped due to disabled MAC (subset of cnt_drop) */ + unsigned long long cnt_drop_filtered; /*!< Frames droped due to MAC address filter (subset of cnt_drop) */ + unsigned long long cnt_erroneous; /*!< Discarded frames due to error (subset of cnt_drop; multiple errors below can occur at once) */ + unsigned long long cnt_err_length; /*!< Frames droped due to MTU mismatch (subset of cnt_erroneous)*/ + unsigned long long cnt_err_crc; /*!< Frames droped due to bad CRC (subset of cnt_erroneous)*/ + unsigned long long cnt_err_mii; /*!< Frames droped due to errors on MII (subset of cnt_erroneous)*/ }; struct nc_rxmac_etherstats { @@ -68,6 +76,10 @@ struct nc_rxmac_etherstats { unsigned long long pkts1024to1518Octets; /*!< Total number of received packets that were between 1024 and 1518 bytes long */ unsigned long long underMinPkts; /*!< Total number of received packets that were shorter than configured minimum (not in etherStats) */ unsigned long long overMaxPkts; /*!< Total number of received packets that were longer than configured maximum (not in etherStats) */ + unsigned long long pkts1519to2047Octets; /*!< Total number of received packets that were between 1519 and 2047 bytes long */ + unsigned long long pkts2048to4095Octets; /*!< Total number of received packets that were between 2048 and 4095 bytes long */ + unsigned long long pkts4096to8191Octets; /*!< Total number of received packets that were between 4096 and 8191 bytes long */ + unsigned long long pktsOverBinsOctets; /*!< Total number of received packets that were 8192 or more bytes long */ }; struct nc_rxmac_status { @@ -102,6 +114,9 @@ static inline void nc_rxmac_set_error_mask(struct nc_rxmac *mac, uns #define RXMAC_REG_CNT_PACKETS_LO 0x0000 #define RXMAC_REG_CNT_PACKETS_HI 0x0010 +#define RXMAC_REG_CNT_ES_OCTETS_LO 0x011C +#define RXMAC_REG_CNT_ES_OCTETS_HI 0x0154 + #define RXMAC_REG_ENABLE 0x0020 #define RXMAC_REG_ERROR_MASK 0x0024 #define RXMAC_REG_STATUS 0x0028 @@ -150,8 +165,7 @@ union _nc_rxmac_reg_buffer { /* Register range: 0x003C - 0x0040 */ struct __attribute__((packed)) { - uint32_t octets_l; - uint32_t octets_h; + uint64_t octets; } r2; /* Register range: 0x0100 - 0x0180 */ @@ -184,11 +198,24 @@ union _nc_rxmac_reg_buffer { uint32_t pkts256to511Octets_h; uint32_t pkts512to1023Octets_h; uint32_t pkts1024to1518Octets_h; - uint32_t over1518_l; - uint32_t over1518_h; - uint32_t below64_l; - uint32_t below64_h; + uint64_t over1518; + uint64_t below64; + /* 0x0180 */ + uint64_t pkts1519to2047Octets; + uint64_t pkts2048to4095Octets; + uint64_t pkts4096to8191Octets; + uint64_t pkts8192plusOctets; } e1; + + /* Register range: 0x01A0 - 0x01D0 */ + struct __attribute__((packed)) { + uint64_t drop_filtered; + uint64_t err; + uint64_t drop_disabled; + uint64_t err_mii; + uint64_t err_crc; + uint64_t err_length; + } r3; }; #define RXMAC_READ_CNT(comp, name) \ @@ -227,6 +254,7 @@ static inline struct nc_rxmac *nc_rxmac_open(struct nfb_device *dev, int fdt_off version = fdt32_to_cpu(*prop); mac->has_counter_below_64 = version >= 0x00000002; + mac->has_ext_drop_counters = version >= 0x00000003; prop = (const fdt32_t*) fdt_getprop(nfb_get_fdt(dev), fdt_offset, "mtu", &proplen); @@ -329,17 +357,35 @@ static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_c c->cnt_total = _NC_RXMAC_REG_BUFFER_PAIR(buf.r1, total); c->cnt_received = _NC_RXMAC_REG_BUFFER_PAIR(buf.r1, received); c->cnt_overflowed = _NC_RXMAC_REG_BUFFER_PAIR(buf.r1, overflowed); - c->cnt_erroneous = _NC_RXMAC_REG_BUFFER_PAIR(buf.r1, discarded) - c->cnt_overflowed; + c->cnt_drop = _NC_RXMAC_REG_BUFFER_PAIR(buf.r1, discarded); nfb_comp_read(comp, &buf.r2, sizeof(buf.r2), 0x003C); - c->cnt_octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.r2, octets); + c->cnt_octets = buf.r2.octets; + + if (mac->has_ext_drop_counters) { + nfb_comp_read(comp, &buf.r3, sizeof(buf.r3), 0x01A0); + c->cnt_err_length = buf.r3.err_length; + c->cnt_err_crc = buf.r3.err_crc; + c->cnt_err_mii = buf.r3.err_mii; + c->cnt_drop_disabled = buf.r3.drop_disabled; + c->cnt_drop_filtered = buf.r3.drop_filtered; + + c->cnt_erroneous = buf.r3.err; + } else { + c->cnt_err_length = 0; + c->cnt_err_crc = 0; + c->cnt_err_mii = 0; + c->cnt_drop_disabled = 0; + c->cnt_drop_filtered = 0; + + c->cnt_erroneous = c->cnt_drop - c->cnt_overflowed; + } } if (s) { nfb_comp_read(comp, &buf.e1, sizeof(buf.e1), 0x0100); s->pkts = c ? c->cnt_total : RXMAC_READ_CNT(comp, PACKETS); - s->undersizePkts = mac->has_counter_below_64 ? _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, below64) : 0; s->CRCAlignErrors = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, CRCAlignErrors); s->broadcastPkts = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, broadcastPkts); @@ -353,10 +399,20 @@ static inline int nc_rxmac_read_counters(struct nc_rxmac *mac, struct nc_rxmac_c s->pkts256to511Octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, pkts256to511Octets); s->pkts512to1023Octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, pkts512to1023Octets); s->pkts1024to1518Octets = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, pkts1024to1518Octets); - s->oversizePkts = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, over1518); s->underMinPkts = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, undersize); s->overMaxPkts = _NC_RXMAC_REG_BUFFER_PAIR(buf.e1, oversize); + + s->undersizePkts = mac->has_counter_below_64 ? buf.e1.below64 : 0; + s->oversizePkts = buf.e1.over1518; + s->pkts1519to2047Octets = buf.e1.pkts1519to2047Octets; + s->pkts2048to4095Octets = buf.e1.pkts2048to4095Octets; + s->pkts4096to8191Octets = buf.e1.pkts4096to8191Octets; + s->pktsOverBinsOctets = buf.e1.pkts8192plusOctets; + } + + if (c) { + c->cnt_total_octets = s ? s->octets : RXMAC_READ_CNT(comp, ES_OCTETS); } nfb_comp_unlock(comp, RXMAC_COMP_LOCK); diff --git a/libnfb/include/netcope/txmac.h b/libnfb/include/netcope/txmac.h index 80802800..ddb4f8eb 100644 --- a/libnfb/include/netcope/txmac.h +++ b/libnfb/include/netcope/txmac.h @@ -19,14 +19,20 @@ extern "C" { /* ~~~~[ DATA TYPES ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ struct nc_txmac { - int _unused; + unsigned has_ext_drop_counters : 1; }; struct nc_txmac_counters { - unsigned long long cnt_total; /*!< All processed frames */ - unsigned long long cnt_octets; /*!< Correct octets */ - unsigned long long cnt_sent; /*!< Correct frames */ - unsigned long long cnt_erroneous; /*!< Discarded frames */ + unsigned long long cnt_total; /*!< All processed frames */ + unsigned long long cnt_octets; /*!< Correct octets */ + unsigned long long cnt_sent; /*!< Correct frames */ + unsigned long long cnt_drop; /*!< All discarded frames (multiple discard reasons can occur at once) */ + unsigned long long cnt_total_octets; /*!< All processed bytes */ + + unsigned long long cnt_drop_disabled; /*!< Frames droped due to disabled MAC */ + unsigned long long cnt_drop_link; /*!< Frames droped due to link down */ + unsigned long long cnt_erroneous; /*!< Discarded frames due to error (subset of cnt_drop; multiple errors below can occur at once) */ + unsigned long long cnt_err_length; /*!< Frames droped due to MTU mismatch */ }; struct nc_txmac_status { @@ -90,6 +96,14 @@ union _nc_txmac_reg_buffer { uint32_t discarded_h; uint32_t sent_h; } r1; + + /* Register range: 0x0040 - 0x0060 */ + struct __attribute__((packed)) { + uint64_t total_octets; + uint64_t drop_link; + uint64_t err_length; + uint64_t drop_disabled; + } r2; }; /* ~~~~[ IMPLEMENTATION ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -97,6 +111,9 @@ static inline struct nc_txmac *nc_txmac_open(struct nfb_device *dev, int fdt_off { struct nc_txmac *mac; struct nfb_comp *comp; + const fdt32_t *prop; + int proplen; + unsigned version = 0; if (fdt_node_check_compatible(nfb_get_fdt(dev), fdt_offset, COMP_NETCOPE_TXMAC)) return NULL; @@ -107,6 +124,12 @@ static inline struct nc_txmac *nc_txmac_open(struct nfb_device *dev, int fdt_off mac = (struct nc_txmac *) nfb_comp_to_user(comp); + prop = (const fdt32_t*) fdt_getprop(nfb_get_fdt(dev), fdt_offset, "version", &proplen); + if (proplen == sizeof(*prop)) + version = fdt32_to_cpu(*prop); + + mac->has_ext_drop_counters = version >= 0x00000003; + return mac; } @@ -174,7 +197,25 @@ static inline int nc_txmac_read_counters(struct nc_txmac *mac, struct nc_txmac_c counters->cnt_total = _NC_TXMAC_REG_BUFFER_PAIR(buf.r1, total); counters->cnt_octets = _NC_TXMAC_REG_BUFFER_PAIR(buf.r1, octets); counters->cnt_sent = _NC_TXMAC_REG_BUFFER_PAIR(buf.r1, sent); - counters->cnt_erroneous = _NC_TXMAC_REG_BUFFER_PAIR(buf.r1, discarded); + counters->cnt_drop = _NC_TXMAC_REG_BUFFER_PAIR(buf.r1, discarded); + + if (mac->has_ext_drop_counters) { + nfb_comp_read(comp, &buf.r2, sizeof(buf.r2), 0x0040); + + counters->cnt_total_octets = buf.r2.total_octets; + counters->cnt_drop_disabled = buf.r2.drop_disabled; + counters->cnt_drop_link = buf.r2.drop_link; + counters->cnt_err_length = buf.r2.err_length; + + counters->cnt_erroneous = counters->cnt_err_length; + } else { + counters->cnt_total_octets = 0; + counters->cnt_drop_disabled = 0; + counters->cnt_drop_link = 0; + counters->cnt_err_length = 0; + + counters->cnt_erroneous = counters->cnt_drop; + } nfb_comp_unlock(comp, TXMAC_COMP_LOCK); return 0; From 1bf515fa99c5d3afd242ed5e8a594099efa4a839 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 11 Jun 2025 21:03:07 +0200 Subject: [PATCH 376/518] fix(nfb-eth): use reg2 for BER values --- tools/eth/pcspma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/eth/pcspma.c b/tools/eth/pcspma.c index 1864eb52..a6dcd177 100644 --- a/tools/eth/pcspma.c +++ b/tools/eth/pcspma.c @@ -256,10 +256,10 @@ void pcspma_print_status(struct ni_context *ctx, struct nc_mdio *mdio, int porta reg2 = nc_mdio_read(mdio, portaddr, 3, 33); if (pma_speed <= 100000) { /* Block lock not defined above 100G */ ni_item_ctrl_reg(ctx, NI_PCS_GLB_BLK_LCK0, reg & 0x0001); - ni_item_ctrl_reg(ctx, NI_PCS_GLB_BLK_LCK1, reg & 0x8000); + ni_item_ctrl_reg(ctx, NI_PCS_GLB_BLK_LCK1, reg2 & 0x8000); } ni_item_ctrl_reg(ctx, NI_PCS_GLB_HIGH_BER0, reg & 0x0002); - ni_item_ctrl_reg(ctx, NI_PCS_GLB_HIGH_BER1, reg & 0x4000); + ni_item_ctrl_reg(ctx, NI_PCS_GLB_HIGH_BER1, reg2 & 0x4000); // BER counter register -> 44 reg = nc_mdio_read(mdio, portaddr, 3, 44); From bb2cded2b89b79527f01f8502e398684b03ccadd Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 7 Apr 2025 12:39:41 +0200 Subject: [PATCH 377/518] feat(tool - eth)!: use statistic counters for MAC version 3 This commit also changes names of the counters. --- tools/eth/eth.h | 34 ++++++++++++++++++++++++---------- tools/eth/main.c | 45 ++++++++++++++++++++++++++++++++++----------- tools/eth/rxmac.c | 31 +++++++++++++++++++++++++------ tools/eth/txmac.c | 24 ++++++++++++++++++------ 4 files changed, 101 insertions(+), 33 deletions(-) diff --git a/tools/eth/eth.h b/tools/eth/eth.h index 9ee414d6..9bcecade 100644 --- a/tools/eth/eth.h +++ b/tools/eth/eth.h @@ -172,14 +172,18 @@ enum NI_ITEMS { NI_BIP_ERR_CNT, NI_SEC_RXMAC, + + NI_MAC_TOTAL, + NI_MAC_TOTAL_O, + NI_MAC_DROP, + NI_RXM_ENABLED, NI_RXM_LINK, NI_RXM_HFIFO_OVF, - NI_RXM_RECV_O, - NI_RXM_PROCESSED, - NI_RXM_RECEIVED, - NI_RXM_ERRONEOUS, + NI_RXM_PASS_O, + NI_RXM_PASS, NI_RXM_OVERFLOWED, + NI_SEC_RXMAC_CONF, NI_RXM_ERR_MASK_REG, NI_RXM_ERR_FRAME, @@ -193,7 +197,7 @@ enum NI_ITEMS { NI_RXM_ERR_MAC_MODE, NI_RXM_MAC_MAX_COUNT, - NI_SEC_RXMAC_S, + NI_SEC_MAC_S, NI_SEC_RXMAC_ES, NI_RXM_ES_OCTS, NI_RXM_ES_PKTS, @@ -210,16 +214,26 @@ enum NI_ITEMS { NI_RXM_ES_256_511, NI_RXM_ES_512_1023, NI_RXM_ES_1024_1518, + NI_RXM_ES_1519_2047, + NI_RXM_ES_2048_4095, + NI_RXM_ES_4096_8191, + NI_RXM_ES_OVER_BINS, NI_RXM_ES_UNDR_SET, NI_RXM_ES_OVER_SET, NI_SEC_TXMAC, - NI_SEC_TXMAC_S, NI_TXM_ENABLED, - NI_TXM_SENT_O, - NI_TXM_PROCESSED, - NI_TXM_SENT, - NI_TXM_ERRONEOUS, + NI_TXM_PASS_O, + NI_TXM_PASS, + NI_TXM_DROP, + + NI_MAC_DROP_DISABLED, + NI_MAC_DROP_FILTERED, + NI_MAC_DROP_LINK, + NI_MAC_DROP_ERR, + NI_MAC_DROP_ERR_LEN, + NI_MAC_DROP_ERR_CRC, + NI_MAC_DROP_ERR_MII, NI_TRANS_PRSNT, NI_TRANS_PRSNT_UNK, diff --git a/tools/eth/main.c b/tools/eth/main.c index b9cb5c74..3a1c756e 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -41,6 +41,8 @@ #define NJFD(x) ni_json_f_decim(x) +#define COMPAT_NAMES 1 + static struct ni_context_item_default ni_items[] = { [NI_SEC_ROOT] = {ni_json_e, ni_user_n}, [NI_LIST_ETH] = {ni_json_k("eth"), ni_user_v(NULL, 0, "\n", NULL)}, /* FIXME: no newline for 128 */ @@ -102,12 +104,25 @@ static struct ni_context_item_default ni_items[] = { [NI_RXM_LINK] = {ni_json_k("link"), ni_user_l("Link status")}, [NI_RXM_HFIFO_OVF] = {ni_json_k("hfifo_overflow"), ni_user_l("HFIFO overflow occurred")}, - [NI_SEC_RXMAC_S] = {ni_json_k("stats"), ni_user_n}, - [NI_RXM_RECV_O] = {ni_json_k("pass_octets"), ni_user_f("Received octets", NUFC)}, - [NI_RXM_PROCESSED] = {ni_json_k("total"), ni_user_f("Processed", NUFC)}, - [NI_RXM_RECEIVED] = {ni_json_k("pass"), ni_user_f("Received", NUFC)}, - [NI_RXM_ERRONEOUS] = {ni_json_k("erroneous"), ni_user_f("Erroneous", NUFC)}, - [NI_RXM_OVERFLOWED] = {ni_json_k("overflowed"), ni_user_f("Overflowed", NUFC)}, + [NI_SEC_MAC_S] = {ni_json_k("stats"), ni_user_n}, + [NI_MAC_TOTAL_O] = {ni_json_k("total_octets"), ni_user_f("Total octets", NUFC)}, + [NI_MAC_DROP] = {ni_json_k("drop"), ni_user_f("Dropped frames", NUFC)}, + [NI_MAC_TOTAL] = {ni_json_k("total"), ni_user_f( + COMPAT_NAMES ? "Processed" : + "Total frames", NUFC)}, + [NI_MAC_DROP_ERR] = {ni_json_k("drop_err"), ni_user_f( + COMPAT_NAMES ? "Erroneous" : + " * Errors", NUFC)}, + + [NI_RXM_PASS_O] = {ni_json_k("pass_octets"), ni_user_f( + COMPAT_NAMES ? "Received octets" : + "Passed octets", NUFC)}, + [NI_RXM_PASS] = {ni_json_k("pass"), ni_user_f( + COMPAT_NAMES ? "Received" : + "Passed frames", NUFC)}, + [NI_RXM_OVERFLOWED] = {ni_json_k("drop_overflow"), ni_user_f( + COMPAT_NAMES ? "Overflowed" : + " * Buffer overflow", NUFC)}, [NI_SEC_RXMAC_CONF] = {ni_json_k("config"), ni_user_l("RXMAC configuration")}, [NI_RXM_ERR_MASK_REG] = {ni_json_k("err_mask_reg"), ni_user_l("Error mask register")}, @@ -144,11 +159,19 @@ static struct ni_context_item_default ni_items[] = { [NI_SEC_TXMAC] = {ni_json_k("txmac"), ni_user_l("TXMAC status")}, [NI_TXM_ENABLED] = {ni_json_k("enabled"), ni_user_l("TXMAC status")}, - [NI_SEC_TXMAC_S] = {ni_json_k("stats"), ni_user_n}, - [NI_TXM_SENT_O] = {ni_json_k("sent_octets"), ni_user_f("Transmitted octets", NUFC)}, - [NI_TXM_PROCESSED] = {ni_json_k("processed"), ni_user_f("Processed", NUFC)}, - [NI_TXM_SENT] = {ni_json_k("sent"), ni_user_f("Transmitted", NUFC)}, - [NI_TXM_ERRONEOUS] = {ni_json_k("erroneous"), ni_user_f("Erroneous", NUFC)}, + [NI_TXM_PASS_O] = {ni_json_k("pass_octets"), ni_user_f( + COMPAT_NAMES ? "Transmitted octets" : + "Passed octets", NUFC)}, + [NI_TXM_PASS] = {ni_json_k("pass"), ni_user_f( + COMPAT_NAMES ? "Transmitted" : + "Passed frames", NUFC)}, + + [NI_MAC_DROP_DISABLED] = {ni_json_k("drop_disabled"), ni_user_f(" * MAC disabled", NUFC)}, + [NI_MAC_DROP_FILTERED] = {ni_json_k("drop_filtered"), ni_user_f(" * MAC filtered", NUFC)}, + [NI_MAC_DROP_LINK] = {ni_json_k("drop_link_down"), ni_user_f(" * Link down", NUFC)}, + [NI_MAC_DROP_ERR_LEN] = {ni_json_k("drop_err_length"), ni_user_f(" * Length error", NUFC)}, + [NI_MAC_DROP_ERR_CRC] = {ni_json_k("drop_err_crc"), ni_user_f(" * CRC error", NUFC)}, + [NI_MAC_DROP_ERR_MII] = {ni_json_k("drop_err_mii"), ni_user_f(" * MII error", NUFC)}, /* Still Eth section */ [NI_TRANS_PRSNT] = {ni_json_k("present"), ni_user_l("Transceiver status")}, diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index 7e6ecf96..7a3d2e59 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -37,13 +37,26 @@ void rxmac_print_status(struct ni_context *ctx, struct nc_rxmac *rxmac, struct e ni_item_ctrl_reg(ctx, NI_RXM_LINK, s.link_up); ni_item_ctrl_reg(ctx, NI_RXM_HFIFO_OVF, s.overflow); - ni_section(ctx, NI_SEC_RXMAC_S); - ni_item_uint64_t(ctx, NI_RXM_RECV_O, c.cnt_octets); - ni_item_uint64_t(ctx, NI_RXM_PROCESSED, c.cnt_total); - ni_item_uint64_t(ctx, NI_RXM_RECEIVED, c.cnt_received); - ni_item_uint64_t(ctx, NI_RXM_ERRONEOUS, c.cnt_erroneous); + ni_section(ctx, NI_SEC_MAC_S); + ni_item_uint64_t(ctx, NI_MAC_TOTAL_O, c.cnt_total_octets); + ni_item_uint64_t(ctx, NI_RXM_PASS_O, c.cnt_octets); + ni_item_uint64_t(ctx, NI_MAC_TOTAL, c.cnt_total); + ni_item_uint64_t(ctx, NI_RXM_PASS, c.cnt_received); + + ni_item_uint64_t(ctx, NI_MAC_DROP, c.cnt_drop); + if (rxmac->has_ext_drop_counters) { + ni_item_uint64_t(ctx, NI_MAC_DROP_DISABLED, c.cnt_drop_disabled); + ni_item_uint64_t(ctx, NI_MAC_DROP_FILTERED, c.cnt_drop_filtered); + } ni_item_uint64_t(ctx, NI_RXM_OVERFLOWED, c.cnt_overflowed); - ni_endsection(ctx, NI_SEC_RXMAC_S); + ni_item_uint64_t(ctx, NI_MAC_DROP_ERR, c.cnt_erroneous); + if (rxmac->has_ext_drop_counters) { + ni_item_uint64_t(ctx, NI_MAC_DROP_ERR_LEN, c.cnt_err_length); + ni_item_uint64_t(ctx, NI_MAC_DROP_ERR_CRC, c.cnt_err_crc); + ni_item_uint64_t(ctx, NI_MAC_DROP_ERR_MII, c.cnt_err_mii); + } + + ni_endsection(ctx, NI_SEC_MAC_S); if (p->verbose) { ni_section(ctx, NI_SEC_RXMAC_CONF); @@ -92,6 +105,12 @@ void rxmac_print_ether_stats(struct ni_context *ctx, struct nc_rxmac *rxmac) ni_item_uint64_t(ctx, NI_RXM_ES_256_511, s.pkts256to511Octets); ni_item_uint64_t(ctx, NI_RXM_ES_512_1023, s.pkts512to1023Octets); ni_item_uint64_t(ctx, NI_RXM_ES_1024_1518, s.pkts1024to1518Octets); + if (rxmac->has_ext_drop_counters) { + ni_item_uint64_t(ctx, NI_RXM_ES_1519_2047, s.pkts128to255Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_2048_4095, s.pkts256to511Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_4096_8191, s.pkts512to1023Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_OVER_BINS, s.pktsOverBinsOctets); + } ni_item_uint64_t(ctx, NI_RXM_ES_UNDR_SET, s.underMinPkts); ni_item_uint64_t(ctx, NI_RXM_ES_OVER_SET, s.overMaxPkts); ni_endsection(ctx, NI_SEC_RXMAC_ES); diff --git a/tools/eth/txmac.c b/tools/eth/txmac.c index f37d1a47..41f7ab21 100644 --- a/tools/eth/txmac.c +++ b/tools/eth/txmac.c @@ -31,12 +31,24 @@ void txmac_print_status(struct ni_context *ctx, struct nc_txmac *txmac, struct e ni_section(ctx, NI_SEC_TXMAC); ni_item_ctrl_reg(ctx, NI_TXM_ENABLED, s.enabled); - ni_section(ctx, NI_SEC_TXMAC_S); - ni_item_uint64_t(ctx, NI_TXM_SENT_O, c.cnt_octets); - ni_item_uint64_t(ctx, NI_TXM_PROCESSED, c.cnt_total); - ni_item_uint64_t(ctx, NI_TXM_SENT, c.cnt_sent); - ni_item_uint64_t(ctx, NI_TXM_ERRONEOUS, c.cnt_erroneous); - ni_endsection(ctx, NI_SEC_TXMAC_S); + ni_section(ctx, NI_SEC_MAC_S); + if (txmac->has_ext_drop_counters) { + ni_item_uint64_t(ctx, NI_MAC_TOTAL_O, c.cnt_total_octets); + } + ni_item_uint64_t(ctx, NI_TXM_PASS_O, c.cnt_octets); + ni_item_uint64_t(ctx, NI_MAC_TOTAL, c.cnt_total); + ni_item_uint64_t(ctx, NI_TXM_PASS, c.cnt_sent); + ni_item_uint64_t(ctx, NI_MAC_DROP, c.cnt_drop); + if (txmac->has_ext_drop_counters) { + ni_item_uint64_t(ctx, NI_MAC_DROP_DISABLED, c.cnt_drop_disabled); + ni_item_uint64_t(ctx, NI_MAC_DROP_LINK, c.cnt_drop_link); + } + ni_item_uint64_t(ctx, NI_MAC_DROP_ERR, c.cnt_erroneous); + if (txmac->has_ext_drop_counters) { + ni_item_uint64_t(ctx, NI_MAC_DROP_ERR_LEN, c.cnt_err_length); + } + + ni_endsection(ctx, NI_SEC_MAC_S); ni_endsection(ctx, NI_SEC_TXMAC); } From 045584924b915d05b53dc0937f3a53a00600b066 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 15 Apr 2025 07:19:33 +0200 Subject: [PATCH 378/518] chore(tools - eth): show HFIFO overflow info only in verbose --- tools/eth/rxmac.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index 7a3d2e59..2261d2d0 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -35,7 +35,10 @@ void rxmac_print_status(struct ni_context *ctx, struct nc_rxmac *rxmac, struct e ni_item_ctrl_reg(ctx, NI_RXM_ENABLED, s.enabled); ni_item_ctrl_reg(ctx, NI_RXM_LINK, s.link_up); - ni_item_ctrl_reg(ctx, NI_RXM_HFIFO_OVF, s.overflow); + + if (p->verbose) { + ni_item_ctrl_reg(ctx, NI_RXM_HFIFO_OVF, s.overflow); + } ni_section(ctx, NI_SEC_MAC_S); ni_item_uint64_t(ctx, NI_MAC_TOTAL_O, c.cnt_total_octets); From b3804b8af8354f6be8c29a5f42af2b66fb464f78 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 19 Jun 2025 08:26:31 +0200 Subject: [PATCH 379/518] feat(nfb-info): print build-revision --- tools/info/info.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/info/info.c b/tools/info/info.c index 532283fa..bff783cb 100644 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -131,6 +131,7 @@ enum NI_ITEMS { NI_BUILT_TIMESTAMP, NI_BUILD_TOOL, NI_BUILD_AUTHOR, + NI_BUILD_REVISION, NI_RX_QUEUES_ALL, NI_RX_QUEUES_EQ_AV, NI_RX_QUEUES_NEQ_AV, @@ -201,14 +202,15 @@ struct ni_context_item_default ni_items[] = { [NI_BUILT_TIMESTAMP] = {ni_json_k("build_time"), ni_user_n}, [NI_BUILD_TOOL] = {ni_json_k("build_tool"), ni_user_l("Build tool")}, [NI_BUILD_AUTHOR] = {ni_json_k("build_author"), ni_user_l("Build author")}, + [NI_BUILD_REVISION] = {ni_json_k("build_revision"), ni_user_l("Build revision")}, [NI_RX_QUEUES_ALL] = {ni_json_k("rx_queues"), ni_user_f("RX queues", NUF_N)}, [NI_RX_QUEUES_EQ_AV] = {ni_json_k("rx_queues_available"), ni_user_f(NULL, NUF_DAV)}, - [NI_RX_QUEUES_NEQ_AV] = {ni_json_k("rx_queues_available"), ni_user_v(" (only", NUF_DA, NULL, "available)")}, + [NI_RX_QUEUES_NEQ_AV] = {ni_json_k("rx_queues_available"), ni_user_v(" (only ", NUF_DA, NULL, " available)")}, [NI_TX_QUEUES_ALL] = {ni_json_k("tx_queues"), ni_user_f("TX queues", NUF_N)}, [NI_TX_QUEUES_EQ_AV] = {ni_json_k("tx_queues_available"), ni_user_f(NULL, NUF_DAV)}, - [NI_TX_QUEUES_NEQ_AV] = {ni_json_k("tx_queues_available"), ni_user_v(" (only", NUF_DA, NULL, " available)")}, + [NI_TX_QUEUES_NEQ_AV] = {ni_json_k("tx_queues_available"), ni_user_v(" (only ", NUF_DA, NULL, " available)")}, [NI_ETH_CHANNELS] = {ni_json_n, ni_user_l("ETH channels")}, [NI_LIST_ETH_CHANNELS] = {ni_json_k("eth_channels"), ni_user_l(NULL)}, @@ -585,6 +587,7 @@ void print_common_info(struct nfb_device *dev, int verbose, struct ni_context *c ni_fdt_prop_str(ctx, NI_BUILD_TOOL, fdt, fdt_offset, "build-tool", &len); ni_fdt_prop_str(ctx, NI_BUILD_AUTHOR, fdt, fdt_offset, "build-author", &len); + ni_fdt_prop_str(ctx, NI_BUILD_REVISION, fdt, fdt_offset, "build-revision", &len); count1 = ndp_get_rx_queue_count(dev); count2 = ndp_get_rx_queue_available_count(dev); From ac2331f207623ed8d1453fa5220854e6bc2964bd Mon Sep 17 00:00:00 2001 From: Richard Hyros Date: Mon, 23 Jun 2025 14:15:18 +0200 Subject: [PATCH 380/518] fix(xdp driver): Fix use of undefined variable --- drivers/kernel/drivers/nfb/xdp/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/xdp/sysfs.c b/drivers/kernel/drivers/nfb/xdp/sysfs.c index 68f21dab..5fc59e65 100644 --- a/drivers/kernel/drivers/nfb/xdp/sysfs.c +++ b/drivers/kernel/drivers/nfb/xdp/sysfs.c @@ -46,7 +46,7 @@ static ssize_t cmd_store(struct device *dev, int index = -1; char *cmd = NULL; - char *queue_string, *queue_string_iter = NULL; + char *queue_string = NULL, *queue_string_iter = NULL; char *q; unsigned queue_index_iter; unsigned queue_count = 0; From 3cd6317f2556ca48901e52d9b865866f3b70586f Mon Sep 17 00:00:00 2001 From: Richard Hyros Date: Mon, 23 Jun 2025 14:15:46 +0200 Subject: [PATCH 381/518] fix(xdp driver): Fix wrong argument passed to sizeof --- drivers/kernel/drivers/nfb/xdp/channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/xdp/channel.c b/drivers/kernel/drivers/nfb/xdp/channel.c index fdcb3118..5c5befc3 100644 --- a/drivers/kernel/drivers/nfb/xdp/channel.c +++ b/drivers/kernel/drivers/nfb/xdp/channel.c @@ -147,7 +147,7 @@ int channel_start_pp(struct nfb_xdp_channel *channel) #else netif_napi_add_weight(netdev, &rxq->napi, nfb_xctrl_napi_poll_pp, NAPI_POLL_WEIGHT); #endif - memset(&txq->napi, 0, sizeof(&txq->napi)); + memset(&txq->napi, 0, sizeof(txq->napi)); if (!(rxq->ctrl = nfb_xctrl_alloc_pp(netdev, channel->index, NFB_XDP_DESC_CNT, NFB_XCTRL_RX))) { ret = -ENOMEM; From ebe65143b4c573111992fd8680db84d531b04e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Thu, 10 Apr 2025 16:11:17 +0200 Subject: [PATCH 382/518] feat(xdptool - xdp copr): Make xdp package buildable from COPR --- .copr/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.copr/Makefile b/.copr/Makefile index 78777cc2..e4312bfa 100644 --- a/.copr/Makefile +++ b/.copr/Makefile @@ -5,4 +5,9 @@ srpm: srpm-dpdk: ./build.sh --prepare; mkdir build; cd build; cmake3 -DUSE_DPDK=true ..; cpack3 -G RPM --config ./CPackSourceConfig.cmake; cd /workdir; cp ./ndk-sw/build/_CPack_Packages/Linux-Source/RPM/SOURCES/*.tar.gz .; cp ./ndk-sw/build/_CPack_Packages/Linux-Source/RPM/SPECS/*.spec . - cd /workdir; sed -i 's/\%define _srcrpmdir \%_topdir\/SRPMS//g' ./*.spec \ No newline at end of file + cd /workdir; sed -i 's/\%define _srcrpmdir \%_topdir\/SRPMS//g' ./*.spec + +srpm-xdp: + ./build.sh --prepare; mkdir build; cd build; cmake3 -DUSE_XDP=true ..; cpack3 -G RPM --config ./CPackSourceConfig.cmake; + cd /workdir; cp ./ndk-sw/build/_CPack_Packages/Linux-Source/RPM/SOURCES/*.tar.gz .; cp ./ndk-sw/build/_CPack_Packages/Linux-Source/RPM/SPECS/*.spec . + cd /workdir; sed -i 's/\%define _srcrpmdir \%_topdir\/SRPMS//g' ./*.spec From e7fe4805b7126337f70bf47731ef781d6e07365a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 25 Jun 2025 17:28:20 +0200 Subject: [PATCH 383/518] chore(repo): now .gitignore includes files from the 3rd party repo, autoreconf, configure, kbuild --- .gitignore | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.gitignore b/.gitignore index 905ff3ee..a33c9253 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,11 @@ cmake-build/ # Ignore `foo' files produced by Autoconf from their `foo.in' templates drivers/Makefile drivers/dkms.conf +drivers/config.h +drivers/config.h.in +drivers/config.log +drivers/config.status +drivers/configure mk/common.mk spec/netcope-common.spec utils/netcope-common.pc @@ -42,15 +47,43 @@ nfb-xvc *.o.d *.o.cmd *.ko.cmd +*.mod *.mod.o *.mod.c +*.mod.cmd *.ko modules.order +.modules.order.cmd Module.symvers +.Module.symvers.cmd .tmp_versions +drivers/src/ +drivers/tmp # Ignore any build/ directory build/ # Ignore files with Git version information .gitversion + +# Ignore python generated files +pynfb/nfb/libnetcope.c +pynfb/nfb/libnfb.c + +# Ignore 3rd party code +drivers/kernel/drivers/base/ +drivers/kernel/drivers/cfi/ +drivers/kernel/drivers/fdt/ +drivers/kernel/drivers/fpga/ +drivers/kernel/drivers/hwmon/ +drivers/kernel/drivers/mfd/ +drivers/kernel/drivers/spi/ +drivers/kernel/drivers/spi-nor/ +drivers/kernel/drivers/xvc/ +drivers/kernel/include/linux/fpga/ +drivers/kernel/include/linux/mfd/ +drivers/kernel/include/uapi/linux/nfb-fpga-image-load.h +drivers/kernel/include/nfb-compat.h + +# Ignore other common stuff +.vscode/ From fc3bdf75ce184a26209ac2e2c45c9525f6145abb Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 27 Jun 2025 11:03:17 +0200 Subject: [PATCH 384/518] fix(drivers - Tivoli): force switch flash before issuing FPGA reload This hotfix seems to fix an issue, when writing & booting image to power-on partition by nfb-boot -f1 firmware.nfw. --- drivers/kernel/drivers/nfb/boot/boot.h | 2 ++ drivers/kernel/drivers/nfb/boot/flash.c | 2 +- drivers/kernel/drivers/nfb/boot/reload.c | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.h b/drivers/kernel/drivers/nfb/boot/boot.h index f91b859c..3c39ad19 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.h +++ b/drivers/kernel/drivers/nfb/boot/boot.h @@ -78,6 +78,8 @@ int nfb_boot_ioctl_mtd_info(struct nfb_boot *nfb_boot, struct nfb_boot_ioc_mtd_info __user *_ioc_mtd_info); int nfb_mtd_read(struct nfb_device *dev, int index, size_t addr, void *data, size_t size); +void nfb_boot_flash_fb_switch_flash(struct nfb_boot *boot, int flash); + int nfb_boot_init(void); void nfb_boot_exit(void); diff --git a/drivers/kernel/drivers/nfb/boot/flash.c b/drivers/kernel/drivers/nfb/boot/flash.c index 8c449d91..3825a81e 100644 --- a/drivers/kernel/drivers/nfb/boot/flash.c +++ b/drivers/kernel/drivers/nfb/boot/flash.c @@ -53,7 +53,7 @@ inline uint16_t nfb_boot_flash_read16(struct nfb_boot *boot) return ret; } -static inline void nfb_boot_flash_fb_switch_flash(struct nfb_boot *boot, int flash) +void nfb_boot_flash_fb_switch_flash(struct nfb_boot *boot, int flash) { if (boot->fb_active_flash != flash) { boot->fb_active_flash = flash; diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index 74e8a2dd..82cb94d3 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -272,6 +272,11 @@ int nfb_boot_reload(void *arg) } else if (boot->comp) { if (boot->controller_type == 3) { uint64_t cmd = (0x7l << 60) | (7l << 48) | boot->num_image; + + /* HOTFIX: force switch flash */ + nfb_boot_flash_fb_switch_flash(boot, 1); + nfb_boot_flash_fb_switch_flash(boot, 0); + nfb_comp_write64(boot->comp, 0, cmd); } else { nfb_comp_write32(boot->comp, 0, boot->num_image); From 264d5ca7a1f6bd283760ddd9ae51ad962f3611ec Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 16 Jun 2025 13:12:34 +0200 Subject: [PATCH 385/518] fix(drivers): use static definitions for functions --- drivers/kernel/drivers/nfb/boot/boot.c | 2 +- drivers/kernel/drivers/nfb/boot/bw-bmc.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index fe93dc0f..e6b1130b 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -217,7 +217,7 @@ ssize_t nfb_boot_load_get_status(struct nfb_boot *boot, char *buf) boot->load.current_op, boot->load.current_op_progress_max, boot->load.current_op_progress); } -int nfb_boot_load(struct nfb_boot *boot, +static int nfb_boot_load(struct nfb_boot *boot, struct nfb_boot_ioc_load __user *_load, void *app_priv) { diff --git a/drivers/kernel/drivers/nfb/boot/bw-bmc.c b/drivers/kernel/drivers/nfb/boot/bw-bmc.c index 35d38a8a..84154824 100644 --- a/drivers/kernel/drivers/nfb/boot/bw-bmc.c +++ b/drivers/kernel/drivers/nfb/boot/bw-bmc.c @@ -43,7 +43,7 @@ static int bw_file_entry_sort_by_offset(const void *lhs, const void *rhs) return 0; } -int nfb_boot_bw_bmc_parse_partition(struct bw_file_entry *p, char **buffer) +static int nfb_boot_bw_bmc_parse_partition(struct bw_file_entry *p, char **buffer) { const char *bbeg; char *bend; @@ -149,7 +149,7 @@ static inline void nfb_boot_bw_bmc_add_partition(void *fdt, int node, int *id, s } } -int nfb_boot_bw_bmc_load_partition_table(struct nfb_boot *boot) +static int nfb_boot_bw_bmc_load_partition_table(struct nfb_boot *boot) { static const int buffer_size = 16384; @@ -258,7 +258,7 @@ int nfb_boot_bw_bmc_load_partition_table(struct nfb_boot *boot) return ret; } -int nfb_boot_bw_bmc_update_binary_slots(struct nfb_boot *boot) +static int nfb_boot_bw_bmc_update_binary_slots(struct nfb_boot *boot) { void *fdt; int node; @@ -300,7 +300,7 @@ void nfb_boot_bw_bmc_detach(struct nfb_boot* boot) } } -void nfb_boot_bw_bmc_load_cb(void *priv, unsigned offset) +static void nfb_boot_bw_bmc_load_cb(void *priv, unsigned offset) { struct nfb_boot* boot = priv; boot->load.current_op_progress = offset; @@ -309,7 +309,7 @@ void nfb_boot_bw_bmc_load_cb(void *priv, unsigned offset) cond_resched(); } -int nfb_boot_bw_bmc_set_priority(struct nfb_boot *boot, struct nfb_boot_ioc_load *load) +static int nfb_boot_bw_bmc_set_priority(struct nfb_boot *boot, struct nfb_boot_ioc_load *load) { int ret = 0; int i; From b9d16ab02815b6bdace7028d3986b139f498ed1e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 16 Jun 2025 13:13:21 +0200 Subject: [PATCH 386/518] fix(drivers - configure): typo in spi_bitbang.ctlr --- drivers/configure.ac | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index 748c58fd..36d6a7c7 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -225,10 +225,11 @@ void test(void) {spi_get_chipselect(NULL, 0);} [AC_MSG_RESULT([no])]) KERNEL_TRY_COMPILE([[ +#include #include struct spi_bitbang sb; void test(void); -void test(void) {sb.ctrl = NULL;} +void test(void) {sb.ctlr = NULL;} ]], [AC_MSG_CHECKING([whether kernel has ctrl in struct spi_bitbang])], [AC_DEFINE([CONFIG_HAVE_SPI_BITBANG_CTRL], [1], [Define if kernel has ctrl in struct spi_bitbang]) AC_MSG_RESULT([yes])], From 140e43077bba87755749f3c64a93370a5ae5da0f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 16 Jun 2025 14:37:34 +0200 Subject: [PATCH 387/518] fix(drivers): use spi_alloc_host --- drivers/kernel/drivers/nfb/boot/nfb-spi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-spi.c b/drivers/kernel/drivers/nfb/boot/nfb-spi.c index d01db32a..fda25c20 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-spi.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-spi.c @@ -226,7 +226,11 @@ int nfb_spi_attach(struct nfb_boot *boot) m10bmc_spi->m10bmc.type = M10_N5014; m10bmc_spi->m10bmc.flash_ops = NULL; - host = spi_alloc_master(&m10bmc_spi->pd->dev, sizeof(struct altera_spi)); +#ifdef CONFIG_HAVE_SPI_CONTROLLER + host = spi_alloc_host(&m10bmc_spi->pd->dev, sizeof(struct altera_spi)); +#else + host = spi_alloc_master(&m10bmc_spi->pd->dev, sizeof(struct altera_spi)); +#endif if (!host) { ret = -ENOMEM; goto err_alloc_master; From 4fe3bcfc314dc923d1924abdddbc0ad24468c7fc Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 16 Jun 2025 13:15:51 +0200 Subject: [PATCH 388/518] feat(drivers - configure): add tests and defines for newer kernels - asm/unaligned.h moved to linux/unaligned.h - return type of platform_driver.remove changed from int to void - removed devm_device_add_groups (use device_add_groups) - del_timer_sync renamed to timer_delete_sync - hrtimer_init renamed to hrtimer_setup --- drivers/configure.ac | 45 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index 36d6a7c7..a885cacd 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -270,7 +270,6 @@ void test(void) {eventfd_signal(NULL);} [AC_DEFINE([CONFIG_HAVE_SIMPLIFIED_EVENTFD_SIGNAL], [1], [Define if kernel has simplified eventfd_signal]) AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) -# XDP KERNEL_TRY_COMPILE([[ #include ]], @@ -331,6 +330,50 @@ xdp_features_t val; [AC_MSG_CHECKING([whether kernel has xdp_features_t])], [AC_DEFINE([CONFIG_HAVE_XDP_FEATURES_T], [1], [Define if kernel has xdp_features_t]) AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) +KERNEL_TRY_COMPILE([[ +#include +]], +[AC_MSG_CHECKING([whether kernel has linux/unaligned.h])], +[AC_DEFINE([CONFIG_HAVE_LINUX_UNALIGNED], [1], [Define if kernel has linux/unaligned.h]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +static void t_remove(struct platform_device *pdev) {} +struct platform_driver pd = { +.remove = t_remove, +}; +]], +[AC_MSG_CHECKING([whether kernel has platfom_driver remove as void return type])], +[AC_DEFINE([CONFIG_HAVE_PLATFORM_DRIVER_REMOVE_VOID], [1], [Define if kernel has platform_driver remove as void]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {devm_device_add_groups(NULL, NULL);} +]], +[AC_MSG_CHECKING([whether kernel has devm_device_add_groups])], +[AC_DEFINE([CONFIG_HAVE_DEVM_DEVICE_ADD_GROUPS], [1], [Define if kernel has devm_evice_add_groups]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {timer_delete_sync(NULL);} +]], +[AC_MSG_CHECKING([whether kernel has timer_delete_sync])], +[AC_DEFINE([CONFIG_HAVE_TIMER_DELETE_SYNC], [1], [Define if kernel has timer_delete_sync]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {hrtimer_setup(NULL, NULL, 0, 0);} +]], +[AC_MSG_CHECKING([whether kernel has hrtimer_setup])], +[AC_DEFINE([CONFIG_HAVE_HRTIMER_SETUP], [1], [Define if kernel has httimer_setup]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) # wait for the jobs to finnish, remove file used for locking if it exists wait From be33230b995bf0b4c0e239a257670490d144f720 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 16 Jun 2025 13:17:21 +0200 Subject: [PATCH 389/518] fix(drivers): apply new config-compatibility flags --- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 4 ++++ drivers/kernel/drivers/nfb/boot/nfb-spi.c | 4 ++++ drivers/kernel/drivers/nfb/ndp/subscriber.c | 6 ++++++ drivers/kernel/drivers/nfb/net/device.c | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index b84c5bbb..c8461160 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -344,7 +344,11 @@ int nfb_pmci_attach(struct nfb_boot *boot) goto err_regmap_register; } +#ifdef CONFIG_HAVE_DEVM_DEVICE_ADD_GROUPS ret = devm_device_add_groups(&pmci->pd->dev, nfb_m10bmc_dev_groups); +#else + ret = device_add_groups(&pmci->pd->dev, nfb_m10bmc_dev_groups); +#endif if (ret) goto err_dev_addgroups; diff --git a/drivers/kernel/drivers/nfb/boot/nfb-spi.c b/drivers/kernel/drivers/nfb/boot/nfb-spi.c index fda25c20..643eb946 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-spi.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-spi.c @@ -286,7 +286,11 @@ int nfb_spi_attach(struct nfb_boot *boot) goto err_regmap_register_avmm; } +#ifdef CONFIG_HAVE_DEVM_DEVICE_ADD_GROUPS ret = devm_device_add_groups(&m10bmc_spi->pd->dev, nfb_m10bmc_dev_groups); +#else + ret = device_add_groups(&m10bmc_spi->pd->dev, nfb_m10bmc_dev_groups); +#endif if (ret) goto err_dev_addgroups; diff --git a/drivers/kernel/drivers/nfb/ndp/subscriber.c b/drivers/kernel/drivers/nfb/ndp/subscriber.c index 0ade016b..f4fb3a7e 100644 --- a/drivers/kernel/drivers/nfb/ndp/subscriber.c +++ b/drivers/kernel/drivers/nfb/ndp/subscriber.c @@ -22,6 +22,8 @@ #include #include +#include + #include "ndp.h" static size_t ndp_subscriber_new_data(struct ndp_subscriber *subscriber) @@ -85,8 +87,12 @@ struct ndp_subscriber *ndp_subscriber_create(struct ndp *ndp) INIT_LIST_HEAD(&subscriber->list_head); INIT_LIST_HEAD(&subscriber->list_head_subscriptions); init_waitqueue_head(&subscriber->poll_wait); +#ifdef CONFIG_HAVE_HRTIMER_SETUP + hrtimer_setup(&subscriber->poll_timer, ndp_subscriber_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); +#else hrtimer_init(&subscriber->poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); subscriber->poll_timer.function = ndp_subscriber_poll_timer; +#endif clear_bit(NDP_WAKE_RX, &subscriber->wake_reason); mutex_lock(&ndp->lock); diff --git a/drivers/kernel/drivers/nfb/net/device.c b/drivers/kernel/drivers/nfb/net/device.c index 9521349b..d05092a2 100644 --- a/drivers/kernel/drivers/nfb/net/device.c +++ b/drivers/kernel/drivers/nfb/net/device.c @@ -692,7 +692,11 @@ static int nfb_net_close(struct net_device *netdev) // Disable transmission nfb_net_transmission_off(netdev); +#ifdef CONFIG_HAVE_TIMER_DELETE_SYNC + timer_delete_sync(&priv->service_timer); +#else del_timer_sync(&priv->service_timer); +#endif return 0; } From cea5526c7a3341303bef7426b1177e7b4ed9fab3 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 16 Jun 2025 14:43:04 +0200 Subject: [PATCH 390/518] chore: use 3rdparty version v6.26.4 --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 10b0df6e..48a91067 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ AUTOINSTALL=true # whether dependencies should be installed with '-y' RELTYPE=Release # Release type (Debug/Release) FILENAME_3RDPARTY="3rdparty.tar.gz" -SRC_3RDPARTY_VERSION="v6.24.0" +SRC_3RDPARTY_VERSION="v6.26.4" URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_VERSION/$FILENAME_3RDPARTY" EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" From 53284f989829756660d76b54a12a08581fea4e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 25 Jun 2025 10:42:08 +0000 Subject: [PATCH 391/518] fix(drivers - build): switch all EXTRA_CFLAGS to ccflags-y --- drivers/CMakeLists.txt | 2 +- drivers/Makefile.in | 4 ++-- drivers/configure.ac | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 49b4c420..f0cdd301 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -38,7 +38,7 @@ function(kernel_try_compile C_CONTENT RES CHECK_TEXT) file(WRITE "${TEST_DIR}/Makefile" "KDIR=${KDIR} KBUILD=$(MAKE) -C $(KDIR) M=${TEST_DIR} -EXTRA_CFLAGS+=-Werror +ccflags-y+=-Werror obj-m := test.o all: $(KBUILD) test.s diff --git a/drivers/Makefile.in b/drivers/Makefile.in index 8a518770..c8b30f23 100644 --- a/drivers/Makefile.in +++ b/drivers/Makefile.in @@ -27,11 +27,11 @@ CONFIG += $(shell find kernel -name Makefile) KBUILD = $(MAKE) -C $(KDIR) \ M=$(TOPDIR)/kernel/drivers \ DRIVER_TOPDIR=$(TOPDIR) \ - EXTRA_CFLAGS="\ + $(ccflags-y)="\ -I$(TOPDIR) \ -I$(TOPDIR)/kernel/include \ -I$(TOPDIR)/kernel/drivers/fdt \ - $(LIBNFB_CFLAGS) $(EXTRA_CFLAGS) \ + $(LIBNFB_CFLAGS) $(ccflags-y) \ " INSTALL_HEADERS = nfb.h ndp.h boot.h diff --git a/drivers/configure.ac b/drivers/configure.ac index a885cacd..fac0b443 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -30,7 +30,7 @@ cd .test${test_cnt} echo KDIR=$KDIR >Makefile cat >>Makefile <Makefile cat >>Makefile < Date: Wed, 25 Jun 2025 16:11:17 +0200 Subject: [PATCH 392/518] fix(drivers - build): do not use ccflags as a variable name passed to the KBUILD via argument --- drivers/Makefile.in | 4 ++-- drivers/kernel/drivers/nfb/Makefile | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/Makefile.in b/drivers/Makefile.in index c8b30f23..468a1a61 100644 --- a/drivers/Makefile.in +++ b/drivers/Makefile.in @@ -27,11 +27,11 @@ CONFIG += $(shell find kernel -name Makefile) KBUILD = $(MAKE) -C $(KDIR) \ M=$(TOPDIR)/kernel/drivers \ DRIVER_TOPDIR=$(TOPDIR) \ - $(ccflags-y)="\ + CUSTOM_CFLAGS="\ -I$(TOPDIR) \ -I$(TOPDIR)/kernel/include \ -I$(TOPDIR)/kernel/drivers/fdt \ - $(LIBNFB_CFLAGS) $(ccflags-y) \ + $(LIBNFB_CFLAGS)\ " INSTALL_HEADERS = nfb.h ndp.h boot.h diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index bc7925ee..907a8c21 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -9,6 +9,8 @@ include $(DRIVER_TOPDIR)/Makefile.conf +ccflags-y := $(CUSTOM_CFLAGS) + nfb-objs += ../fdt/fdt.o ../fdt/fdt_ro.o ../fdt/fdt_rw.o ../fdt/fdt_wip.o ../fdt/fdt_sw.o ../fdt/fdt_empty_tree.o nfb-objs += ../cfi/cfi_cmdset_0001.o ../cfi/cfi_cmdset_0002.o ../cfi/cfi_cmdset_0020.o ../cfi/cfi_probe.o ../cfi/cfi_util.o ../cfi/chipreg.o ../cfi/gen_probe.o ../cfi/mtdcore.o nfb-objs += ../spi-nor/spi-nor.o From 30d490194742fad062770fae9446a93b33ef9d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 25 Jun 2025 16:22:24 +0200 Subject: [PATCH 393/518] chore(drivers - build): switch from *-objs to *-y syntax when adding module sources to kbuild --- drivers/kernel/drivers/nfb/Makefile | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index 907a8c21..b88fb8ef 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -11,26 +11,26 @@ include $(DRIVER_TOPDIR)/Makefile.conf ccflags-y := $(CUSTOM_CFLAGS) -nfb-objs += ../fdt/fdt.o ../fdt/fdt_ro.o ../fdt/fdt_rw.o ../fdt/fdt_wip.o ../fdt/fdt_sw.o ../fdt/fdt_empty_tree.o -nfb-objs += ../cfi/cfi_cmdset_0001.o ../cfi/cfi_cmdset_0002.o ../cfi/cfi_cmdset_0020.o ../cfi/cfi_probe.o ../cfi/cfi_util.o ../cfi/chipreg.o ../cfi/gen_probe.o ../cfi/mtdcore.o -nfb-objs += ../spi-nor/spi-nor.o -nfb-objs += ../spi/spi-xilinx.o +nfb-y += ../fdt/fdt.o ../fdt/fdt_ro.o ../fdt/fdt_rw.o ../fdt/fdt_wip.o ../fdt/fdt_sw.o ../fdt/fdt_empty_tree.o +nfb-y += ../cfi/cfi_cmdset_0001.o ../cfi/cfi_cmdset_0002.o ../cfi/cfi_cmdset_0020.o ../cfi/cfi_probe.o ../cfi/cfi_util.o ../cfi/chipreg.o ../cfi/gen_probe.o ../cfi/mtdcore.o +nfb-y += ../spi-nor/spi-nor.o +nfb-y += ../spi/spi-xilinx.o -nfb-objs += mi/mi.o -nfb-objs += ndp/ctrl.o ndp/ctrl_ndp.o ndp/channel.o ndp/subscription.o ndp/subscriber.o ndp/ring.o ndp/char.o ndp/driver.o ndp/kndp.o -nfb-objs += ndp_netdev/core.o -nfb-objs += boot/flash.o boot/reload.o boot/boot.o boot/gecko.o boot/sdm.o boot/bw-bmc.o +nfb-y += mi/mi.o +nfb-y += ndp/ctrl.o ndp/ctrl_ndp.o ndp/channel.o ndp/subscription.o ndp/subscriber.o ndp/ring.o ndp/char.o ndp/driver.o ndp/kndp.o +nfb-y += ndp_netdev/core.o +nfb-y += boot/flash.o boot/reload.o boot/boot.o boot/gecko.o boot/sdm.o boot/bw-bmc.o ifndef CONFIG_REGMAP_SPI_AVMM -nfb-objs += ../base/regmap/regmap-spi-avmm.o +nfb-y += ../base/regmap/regmap-spi-avmm.o endif ifndef CONFIG_SPI_ALTERA_CORE -nfb-objs += ../spi/spi-altera-core.o +nfb-y += ../spi/spi-altera-core.o endif -nfb-objs += ../mfd/intel-m10-bmc-core.o ../fpga/fpga-image-load.o ../fpga/intel-m10-bmc-sec-update.o ../hwmon/intel-m10-bmc-hwmon.o ../mfd/intel-m10-bmc-log.o boot/nfb-pmci.o boot/nfb-spi.o -nfb-objs += net/driver.o net/device.o net/ethtool.o net/sysfs.o -nfb-objs += qdr/qdr.o -nfb-objs += misc.o lock.o bus.o char.o pci.o core.o -nfb-objs += hwmon/nfb_hwmon.o +nfb-y += ../mfd/intel-m10-bmc-core.o ../fpga/fpga-image-load.o ../fpga/intel-m10-bmc-sec-update.o ../hwmon/intel-m10-bmc-hwmon.o ../mfd/intel-m10-bmc-log.o boot/nfb-pmci.o boot/nfb-spi.o +nfb-y += net/driver.o net/device.o net/ethtool.o net/sysfs.o +nfb-y += qdr/qdr.o +nfb-y += misc.o lock.o bus.o char.o pci.o core.o +nfb-y += hwmon/nfb_hwmon.o ccflags-$(CONFIG_NFB_XDP) += -DCONFIG_NFB_ENABLE_XDP nfb-$(CONFIG_NFB_XDP) += xdp/driver.o xdp/ethdev.o xdp/ctrl_xdp_common.o xdp/ctrl_xdp_pp.o xdp/ctrl_xdp_xsk.o xdp/channel.o xdp/sysfs.o From b90802315f94c3e87c507876d41663160981be06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 25 Jun 2025 10:45:22 +0000 Subject: [PATCH 394/518] feat(drivers - configure): add xsk_buff_dma_sync_for_cpu test flag --- drivers/configure.ac | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/configure.ac b/drivers/configure.ac index fac0b443..439f9287 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -375,6 +375,15 @@ void test(void) {hrtimer_setup(NULL, NULL, 0, 0);} [AC_DEFINE([CONFIG_HAVE_HRTIMER_SETUP], [1], [Define if kernel has httimer_setup]) AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {xsk_buff_dma_sync_for_cpu(NULL);} +]], +[AC_MSG_CHECKING([whether kernel has one argument xsk_buff_dma_sync_for_cpu])], +[AC_DEFINE([CONFIG_HAVE_ONE_ARG_XSK_BUFF_DMA_SYNC], [1], [Define if kernel has httimer_setup]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + # wait for the jobs to finnish, remove file used for locking if it exists wait rm -rf flock_lockfile >/dev/null 2>/dev/null From 02c00c756e80433ee207c976dc1ed365a53fd24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 25 Jun 2025 10:46:28 +0000 Subject: [PATCH 395/518] fix(xdp driver): apply the newly added configure flags --- drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c | 4 ++++ drivers/kernel/drivers/nfb/xdp/ethdev.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c index 2cab9839..3123ad15 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c @@ -246,7 +246,11 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, struct xdp_buff **buffs, buff = ctrl->rx.xsk.xdp_ring[shp]; hdr = &hdrs[shp]; xsk_buff_set_size(buff, hdr->frame_len); // sets the actual data size after receive +#ifdef CONFIG_HAVE_ONE_ARG_XSK_BUFF_DMA_SYNC + xsk_buff_dma_sync_for_cpu(buff); +#else xsk_buff_dma_sync_for_cpu(buff, ctrl->rx.xsk.pool); +#endif buffs[i] = buff; shp = (shp + 1) & mhp; } diff --git a/drivers/kernel/drivers/nfb/xdp/ethdev.c b/drivers/kernel/drivers/nfb/xdp/ethdev.c index aae4441a..9f15ccd5 100644 --- a/drivers/kernel/drivers/nfb/xdp/ethdev.c +++ b/drivers/kernel/drivers/nfb/xdp/ethdev.c @@ -174,7 +174,11 @@ int destroy_ethdev(struct nfb_xdp *module, int index) ret = 0; netdev = ethdev->netdev; list_del(ðdev->list); +#ifdef CONFIG_HAVE_TIMER_DELETE_SYNC + timer_delete_sync(ðdev->link_timer); +#else del_timer_sync(ðdev->link_timer); +#endif cancel_work_sync(ðdev->link_work); netif_carrier_off(netdev); // close mac components @@ -349,7 +353,11 @@ int create_ethdev(struct nfb_xdp *module, u16 index, unsigned * channel_indexes, return ret; err_register_netdev: +#ifdef CONFIG_HAVE_TIMER_DELETE_SYNC + timer_delete_sync(ðdev->link_timer); +#else del_timer_sync(ðdev->link_timer); +#endif cancel_work_sync(ðdev->link_work); macs_open_error: macs_alloc_error: From 8d0276c24a6b819f85a86777f10bbad04fea8996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Wed, 25 Jun 2025 10:47:20 +0000 Subject: [PATCH 396/518] fix(xdp driver): remove unused function --- drivers/kernel/drivers/nfb/xdp/sysfs.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/kernel/drivers/nfb/xdp/sysfs.c b/drivers/kernel/drivers/nfb/xdp/sysfs.c index 5fc59e65..ba879fc7 100644 --- a/drivers/kernel/drivers/nfb/xdp/sysfs.c +++ b/drivers/kernel/drivers/nfb/xdp/sysfs.c @@ -167,11 +167,6 @@ void nfb_xdp_sysfs_init_module_attributes(struct nfb_xdp *module) dev->groups = nfb_module_groups; } -void nfb_xdp_sysfs_deinit_module(struct nfb_ethdev *ethdev) -{ - return; -} - // --------------------------- SYSFS files for each channel -------------------------------- struct channel_sysfs_drvdata { struct nfb_xdp *module; From 1766d5b49c8212df9110c3df0cdabd0b92b21261 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 30 Jun 2025 15:21:39 +0200 Subject: [PATCH 397/518] fix(pynfb - i2c): check for NULL handle from nc_i2c_open --- pynfb/nfb/libnetcope.pyx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 7aea1ea0..9955f89b 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -267,6 +267,8 @@ cdef class I2c: self._handle.check_handle() self._ctrl = NULL self._ctrl = nc_i2c_open(self._handle._dev, nfb._fdt_path_offset(node)) + if self._ctrl == NULL: + PyErr_SetFromErrno(OSError) nc_i2c_set_addr(self._ctrl, addr) self._handle.add_close_cb(self._close_handle) From b952082cccd293a37310afd2f1c3974f243a646d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 3 Jul 2025 16:23:19 +0200 Subject: [PATCH 398/518] fix(tool - eth): use empty item for transceiver list in JSON instead of null --- tools/eth/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/eth/main.c b/tools/eth/main.c index 3a1c756e..228d06bf 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -184,7 +184,7 @@ static struct ni_context_item_default ni_items[] = { /* Trans section */ [NI_LIST_TRANS] = {ni_json_k("transceivers"), ni_user_v(NULL, 0, "\n", NULL)}, - [NI_SEC_TRN] = {ni_json_n, ni_user_l("")}, + [NI_SEC_TRN] = {ni_json_e, ni_user_l("")}, [NI_TRN_INDEX] = {ni_json_k("id"), ni_user_f("", NUF_NDA | NUF_SL | NUFW(2))}, [NI_TRN_NAME] = {ni_json_k("name"), ni_user_v("", NUF_NDA | NUF_SL, NULL, "")}, [NI_MOD_IDENT] = {ni_json_k("identifier"), ni_user_l("Module identifier")}, From 681686af6e3695484a9c5a9436500744ce7e9b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Tue, 8 Jul 2025 11:27:24 +0200 Subject: [PATCH 399/518] fix(ndp tool): fix include guard --- tools/ndptool/xdp/xdp_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ndptool/xdp/xdp_common.h b/tools/ndptool/xdp/xdp_common.h index 9d0f8f3a..e86a8109 100644 --- a/tools/ndptool/xdp/xdp_common.h +++ b/tools/ndptool/xdp/xdp_common.h @@ -1,5 +1,5 @@ #ifndef XDP_COMMON_H -#define XDP_COMOD_H +#define XDP_COMMON_H // libxdp #include From 98c6c1cea39f8574194ae89a013c09d09b569ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Fri, 27 Jun 2025 13:47:32 +0200 Subject: [PATCH 400/518] feat(xdp driver): add xdp and af xdp sg support --- drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h | 23 +- .../kernel/drivers/nfb/xdp/ctrl_xdp_common.c | 135 ++++--- .../kernel/drivers/nfb/xdp/ctrl_xdp_common.h | 178 ++++++--- drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c | 214 +++++----- drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c | 376 ++++++++++++------ drivers/kernel/drivers/nfb/xdp/ethdev.c | 10 +- 6 files changed, 579 insertions(+), 357 deletions(-) diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h index 0d291204..403ef923 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h @@ -15,7 +15,14 @@ #include "../nfb.h" #include "../../../../../libnfb/include/netcope/dma_ctrl_ndp.h" +// Values taken from the ndk-app-minimal fw +#define NFB_XDP_MTU_MIN 64 +#define NFB_XDP_MTU_MAX 16383 +// Default AF_XDP value, can be made larger or smaller +#define NFB_MAX_AF_XDP_FRAGS CONFIG_MAX_SKB_FRAGS + 1 + #define NFB_XDP_CTRL_PACKET_BURST 64 +#define NFB_PP_MAX_FRAME_LEN PAGE_SIZE - XDP_PACKET_HEADROOM - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) enum xdp_ctrl_type { NFB_XCTRL_RX, @@ -28,6 +35,8 @@ enum xdp_ctrl_tx_buff_type { NFB_XCTRL_BUFF_FRAME, // used with frames which needs to be unmapped NFB_XCTRL_BUFF_SKB, // used for linux netdev tx ndo NFB_XCTRL_BUFF_XSK, // used for counting the xsk frames + NFB_XCTRL_BUFF_XSK_REXMIT, // used for RX xsks which were retransmited + NFB_XCTRL_BUFF_BUG, // used for debugging }; // Used for freeing tx buffers after tx completes @@ -36,9 +45,7 @@ struct xctrl_tx_buffer { union { struct sk_buff *skb; struct xdp_frame *frame; - // for counting xsk completions - // when we drop packet on tx this is more than 1 - u32 num_of_xsk_completions; + struct xdp_buff *xsk; }; dma_addr_t dma; u32 len; @@ -47,7 +54,6 @@ struct xctrl_tx_buffer { // TODO: clean up #define XCTRL_STATUS_IS_RUNNING BIT(0) struct xctrl { - enum xdp_ctrl_type type; union { struct { /** RX - Driver handles allocation of pages for rx through page_pool @@ -67,8 +73,11 @@ struct xctrl { struct xsk_buff_pool *pool; } xsk; }; - u32 php; // RX - processed header pointers + // u32 php; // RX - processed header pointers // hdr_buff is only used on rx + u32 mbp; // Mask buffer pointer + u32 pbp; // Processed buffer pointer + u32 fbp; // Filled buffer pointer u32 nb_hdr; void *hdr_buffer_cpu; dma_addr_t hdr_buffer_dma; @@ -87,17 +96,15 @@ struct xctrl { * TODO: checkout xdp_return_frame_bulk() */ struct xctrl_tx_buffer *buffers; - u32 fdp; // TX - freed descriptor pointers spinlock_t tx_lock; // TODO: checkout __netif_tx_lock() // used for counting completed tx frames // in XSK mode driver needs to return the frames // in the same order as it got them // So we count num of frames we can return from tx_buffer u32 completed_xsk_tx; // num of frames ready to be returned to userspace on tx_buffer_free - u32 last_napi_xsk_drops; // if we drop packets on tx we add them for completion with the next packet } tx; }; - + enum xdp_ctrl_type type; // common control buffers void *update_buffer_virt; dma_addr_t update_buffer_dma; diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c index 198e335d..3eadf3b2 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.c @@ -45,7 +45,6 @@ netdev_tx_t nfb_xctrl_start_xmit(struct sk_buff *skb, struct net_device *netdev) dma_addr_t dma; u32 len; - u32 min_len = ETH_ZLEN; u32 sdp; u32 mdp; @@ -54,26 +53,30 @@ netdev_tx_t nfb_xctrl_start_xmit(struct sk_buff *skb, struct net_device *netdev) u32 free_desc; u32 ret; + skb_frag_t *frag; + u32 nr_frags = skb_shinfo(skb)->nr_frags; + u32 i, j; + struct xctrl_tx_buffer *tx_buff; + spin_lock(&ctrl->tx.tx_lock); { - nc_ndp_ctrl_hdp_update(&ctrl->c); - nfb_xctrl_tx_free_buffers(ctrl); - sdp = ctrl->c.sdp; mdp = ctrl->c.mdp; - free_desc = (ctrl->c.hdp - sdp - 1) & mdp; descs = ctrl->desc_buffer_virt; - if (skb_linearize(skb)) { - printk(KERN_ERR "nfb: %s failed to linearize skb. queue: %u\n", __func__, channel->nfb_index); + // Max 2 descriptors per frag and head will be used + // One to update the addr and second with data + free_desc = (ctrl->c.hdp - sdp - 1) & mdp; + if(free_desc < (nr_frags + 1) * 2) { + printk(KERN_WARNING "nfb: %s TX busy warning, packet dropped\n", __func__); goto free_locked; } - len = max(min_len, skb->len); - if (skb_padto(skb, min_len)) { - // skb is freed on error - printk(KERN_ERR "nfb: %s skb too small and zero padding failed. queue: %u\n", __func__, channel->nfb_index); - goto freed_locked; + if (skb->len < ETH_ZLEN) { + skb_padto(skb, ETH_ZLEN); + len = ETH_ZLEN; + } else { + len = skb_headlen(skb); } dma = dma_map_single(ctrl->dma_dev, skb->data, len, DMA_TO_DEVICE); @@ -84,62 +87,82 @@ netdev_tx_t nfb_xctrl_start_xmit(struct sk_buff *skb, struct net_device *netdev) last_upper_addr = ctrl->c.last_upper_addr; if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { - if (unlikely(free_desc < 2)) { - dev_warn(ethdev->nfb->dev, "nfb: %s busy warning. Packets are dropped. queue: %u\n", __func__, channel->nfb_index); - goto free_locked_unmap; - } - last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); ctrl->c.last_upper_addr = last_upper_addr; - descs[sdp] = nc_ndp_tx_desc0(dma); - ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; - free_desc--; sdp = (sdp + 1) & mdp; } - if (unlikely(free_desc == 0)) { - dev_warn(ethdev->nfb->dev, "nfb: %s busy warning. Packets are dropped. queue: %u\n", __func__, channel->nfb_index); - goto free_locked_unmap; - } - - free_desc--; - - // TODO: - // If socket uses up all it's allocated skbs before first skb is freed - // then socket can no longer send another packet - // and tx completition is not called causing socket to deadlock - // skb_orphan releases skb from socket pool so it is a working temporary solution - // tx timeout should still be introduced - skb_orphan(skb); - ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_SKB; ctrl->tx.buffers[sdp].skb = skb; ctrl->tx.buffers[sdp].dma = dma; ctrl->tx.buffers[sdp].len = len; - - descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + + if (!nr_frags) { // Single buffer + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + } else { // Multi buffer + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 1); + } sdp = (sdp + 1) & mdp; + + // FRAG PROCESSING + for (i = 0; i < nr_frags; ++i) { + frag = &skb_shinfo(skb)->frags[i]; + len = skb_frag_size(frag); + dma = skb_frag_dma_map(ctrl->dma_dev, frag, 0, len, DMA_TO_DEVICE); + if ((ret = dma_mapping_error(ctrl->dma_dev, dma))) { + printk(KERN_ERR "nfb: %s failed to dma map skb. queue: %u err: %d\n", __func__, channel->nfb_index, ret); + goto free_locked_unmap; + } + + last_upper_addr = ctrl->c.last_upper_addr; + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { + last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); + ctrl->c.last_upper_addr = last_upper_addr; + descs[sdp] = nc_ndp_tx_desc0(dma); + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; + sdp = (sdp + 1) & mdp; + } + + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_SKB; + ctrl->tx.buffers[sdp].skb = NULL; + ctrl->tx.buffers[sdp].dma = dma; + ctrl->tx.buffers[sdp].len = len; + + if (i == nr_frags - 1) { // Last frag + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + } else { // Middle frag + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 1); + } + sdp = (sdp + 1) & mdp; + } + + // Update counters ctrl->c.sdp = sdp; - // NOTE: Calling dma_map_single with DMA_TO_DEVICE should do the sync for dev - // Calling unmap should do the sync for cpu - // Therefore the sync functions are only really needed when using DMA_BIDIRECTINAL - // dma_sync_single_for_device(ctrl->dma_dev, dma, len, DMA_TO_DEVICE); - nc_ndp_ctrl_sdp_flush(&ctrl->c); + // Only flush when finnished + if(!netdev_xmit_more()) { + nc_ndp_ctrl_sdp_flush(&ctrl->c); + } } spin_unlock(&ctrl->tx.tx_lock); return NETDEV_TX_OK; free_locked_unmap: - dma_unmap_single(ctrl->dma_dev, dma, len, DMA_TO_DEVICE); + // Reset sdp and unmap everything that was mapped (i frags + 1 head) + sdp = ctrl->c.sdp; + for (j = 0; j < i + 1; j++) { + tx_buff = &ctrl->tx.buffers[sdp]; + if (tx_buff->type == NFB_XCTRL_BUFF_SKB) + dma_unmap_single(ctrl->dma_dev, tx_buff->dma, tx_buff->len, DMA_TO_DEVICE); + + sdp = (sdp + 1) & mdp; + } free_locked: dev_kfree_skb(skb); -freed_locked: spin_unlock(&ctrl->tx.tx_lock); - // NOTE: It is possible to return NETDEV_TX_BUSY // Kernel then tries to xmit packet again // It is slow and it is possible to completely @@ -157,34 +180,29 @@ int nfb_xctrl_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdp, u3 struct xdp_frame *frame; int cnt = 0; - if (n == 0) { - return 0; - } - // There doesn't seem to be a good way to decide which queue to use for tx other than semi random + // NOTE: If the interrupts are implemented use the affinity logic. qid = smp_processor_id() % ethdev->channel_count; channel = ðdev->channels[qid]; txq = &channel->txq; ctrl = txq->ctrl; spin_lock(&ctrl->tx.tx_lock); { - // reclaim tx buffers - nc_ndp_ctrl_hdp_update(&ctrl->c); - nfb_xctrl_tx_free_buffers(ctrl); - // process tx + // Process tx for (cnt = 0; cnt < n; cnt++) { frame = xdp[cnt]; - if (unlikely(nfb_xctrl_tx_submit_frame_needs_lock(ctrl, frame))) { - // on error caller frees the frames (see ndo_xdp_xmit docs) + if (unlikely(nfb_xctrl_tx_submit_frame_needs_lock(ctrl, frame, false))) { + // On error caller frees the frames (see ndo_xdp_xmit docs) break; } } - // flush - nc_ndp_ctrl_sdp_flush(&ctrl->c); + // Flush + if (flags & XDP_XMIT_FLUSH) + nc_ndp_ctrl_sdp_flush(&ctrl->c); } spin_unlock(&ctrl->tx.tx_lock); if (cnt != n) { - printk(KERN_WARNING "%s didn't manage to tx all packets; %d packets dropped\n", __func__, n - cnt); + printk(KERN_ERR "%s Didn't manage to tx all packets; %d packets dropped, busy warning.\n", __func__, n - cnt); } return cnt; } @@ -235,7 +253,6 @@ static int nfb_setup_xsk_pool(struct net_device *dev, struct xsk_buff_pool *pool u32 nfb_queue_id = channel->nfb_index; int ret = 0; - // printk(KERN_DEBUG "LOG: inside %s\n", __func__); if ((ret = xsk_pool_dma_map(pool, ðdev->nfb->pci->dev, DMA_ATTR_SKIP_CPU_SYNC))) { printk(KERN_ERR "nfb: Failed to switch queue %d pool could't be mapped err: %d\n", nfb_queue_id, ret); goto exit; diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h index 3fe17c51..f8cc122d 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h @@ -27,14 +27,19 @@ * * @param ctrl */ -static inline void nfb_xctrl_tx_free_buffers(struct xctrl *ctrl) +static inline void nfb_xctrl_tx_free_buffers(struct xctrl *ctrl, bool cleanup) { u32 i; - u32 hdp = ctrl->c.hdp; u32 mdp = ctrl->c.mdp; - u32 fdp = ctrl->tx.fdp; + u32 hdp_old = ctrl->c.hdp; + u32 hdp_new; - for (i = fdp; i != hdp; i++, i &= mdp) { + if(!cleanup) // When cleaning up the queues we no longer have the underliing controller running + nc_ndp_ctrl_hdp_update(&ctrl->c); + + hdp_new = ctrl->c.hdp; + + for (i = hdp_old; i != hdp_new; i++, i &= mdp) { switch (ctrl->tx.buffers[i].type) { case NFB_XCTRL_BUFF_FRAME_PP: // xdp buff to be recycled to page pool // xdp_return_buff definition is missing in 4.18.0-477.10.1.el8_8.x86_64 @@ -42,16 +47,23 @@ static inline void nfb_xctrl_tx_free_buffers(struct xctrl *ctrl) xdp_return_frame(ctrl->tx.buffers[i].frame); break; case NFB_XCTRL_BUFF_XSK: - ctrl->tx.completed_xsk_tx += ctrl->tx.buffers[i].num_of_xsk_completions; + ctrl->tx.completed_xsk_tx += 1; + break; + case NFB_XCTRL_BUFF_XSK_REXMIT: + xsk_buff_free(ctrl->tx.buffers[i].xsk); break; case NFB_XCTRL_BUFF_SKB: dma_unmap_single(ctrl->dma_dev, ctrl->tx.buffers[i].dma, ctrl->tx.buffers[i].len, DMA_TO_DEVICE); - dev_kfree_skb(ctrl->tx.buffers[i].skb); + if(ctrl->tx.buffers[i].skb) + dev_kfree_skb(ctrl->tx.buffers[i].skb); + break; - case NFB_XCTRL_BUFF_FRAME: // redirectedd frame - can be from another device all together + case NFB_XCTRL_BUFF_FRAME: // Redirected frame - can be from another device all together // TODO check out xdp_return_frame_bulk() dma_unmap_single(ctrl->dma_dev, ctrl->tx.buffers[i].dma, ctrl->tx.buffers[i].len, DMA_TO_DEVICE); - xdp_return_frame(ctrl->tx.buffers[i].frame); + if(ctrl->tx.buffers[i].frame) + xdp_return_frame(ctrl->tx.buffers[i].frame); + break; case NFB_XCTRL_BUFF_DESC_TYPE0: break; @@ -60,17 +72,14 @@ static inline void nfb_xctrl_tx_free_buffers(struct xctrl *ctrl) BUG(); break; } - ctrl->tx.buffers[i].type = NFB_XCTRL_BUFF_DESC_TYPE0; + ctrl->tx.buffers[i].type = NFB_XCTRL_BUFF_BUG; } - ctrl->tx.fdp = hdp; } /** * @brief Submits and maps frame onto tx. Not as straight forward as i would have liked -> check note * @note * spin_lock(&lock) - * nc_ndp_ctrl_hdp_update(&ctrl->c); - * nfb_xctrl_tx_free_buffers(ctrl); * for (;;) * nfb_xctrl_tx_submit_frame_needs_lock() * nc_ndp_ctrl_sdp_flush() @@ -79,76 +88,153 @@ static inline void nfb_xctrl_tx_free_buffers(struct xctrl *ctrl) * @param frame * @return 0 on success */ -static inline int nfb_xctrl_tx_submit_frame_needs_lock(struct xctrl *ctrl, struct xdp_frame *frame) +static inline int nfb_xctrl_tx_submit_frame_needs_lock(struct xctrl *ctrl, struct xdp_frame *frame, bool pp) { dma_addr_t dma; - u32 free_desc; u32 len; - u16 min_len = ETH_ZLEN; + u32 sdp; + u32 mdp; + + struct nc_ndp_desc *descs; + u64 last_upper_addr; + u32 free_desc; int ret = 0; - // ctrl vars - u64 last_upper_addr = ctrl->c.last_upper_addr; - u32 sdp = ctrl->c.sdp; - u32 mdp = ctrl->c.mdp; - struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; + skb_frag_t *frag; + + u32 nr_frags = xdp_get_shared_info_from_frame(frame)->nr_frags; + u32 i, j; + struct xctrl_tx_buffer *tx_buff; + sdp = ctrl->c.sdp; + mdp = ctrl->c.mdp; + descs = ctrl->desc_buffer_virt; + + // Max 2 descriptors per frag and head will be used + // One to update the addr and second with data free_desc = (ctrl->c.hdp - sdp - 1) & mdp; + if(free_desc < (nr_frags + 1) * 2) { + printk(KERN_WARNING "nfb: submit_frame TX busy warning, packet dropped\n"); + ret = -EBUSY; + goto exit; + } // Handle small frames - len = max(frame->len, min_len); // Here we don't know where the frames came from. (Could be different driver all together) // Therefore if we cannot make the frame bigger we would have to alloc a new one. -ENOTSUPP - if (frame->len < min_len) { // Usable frame space is smaller than min_len. - if (unlikely(frame->frame_sz - frame->headroom < min_len)) { + if (frame->len < ETH_ZLEN) { + // Usable frame space is smaller than min_len. + if (unlikely(frame->frame_sz - frame->headroom < ETH_ZLEN)) { + printk(KERN_WARNING "nfb: submit_frame TX got frame too small, packet dropped\n"); ret = -ENOTSUPP; goto exit; } - memset(frame->data + frame->len, 0, min_len - frame->len); - } - - dma = dma_map_single(ctrl->dma_dev, frame->data, len, DMA_TO_DEVICE); - if (unlikely(ret = dma_mapping_error(ctrl->dma_dev, dma))) { - printk(KERN_ERR "nfb: %s failed to map frame\n", __func__); - goto exit; + memset(frame->data + frame->len, 0, ETH_ZLEN - frame->len); + len = ETH_ZLEN; + } else { + len = frame->len; } - if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { - if (unlikely(free_desc < 2)) { - printk(KERN_ERR "nfb: %s busy warning\n", __func__); - dma_unmap_single(ctrl->dma_dev, dma, len, DMA_TO_DEVICE); - ret = -EBUSY; + // If page_pool, then the page is already mapped + if (!pp) { + dma = dma_map_single(ctrl->dma_dev, frame->data, len, DMA_TO_DEVICE); + if (unlikely(ret = dma_mapping_error(ctrl->dma_dev, dma))) { + printk(KERN_ERR "nfb: %s failed to map frame\n", __func__); goto exit; } + } else { + dma = page_pool_get_dma_addr(virt_to_page(frame->data)) + XDP_PACKET_HEADROOM; + } + last_upper_addr = ctrl->c.last_upper_addr; + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); ctrl->c.last_upper_addr = last_upper_addr; - descs[sdp] = nc_ndp_tx_desc0(dma); - ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; - free_desc--; sdp = (sdp + 1) & mdp; } - if (unlikely(free_desc == 0)) { - printk(KERN_ERR "nfb: nfb_xctrl_xmit busy warning\n"); - dma_unmap_single(ctrl->dma_dev, dma, len, DMA_TO_DEVICE); - ret = -EBUSY; - goto exit; + if (!pp) { // Unmapped at reclaim + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_FRAME; + } else { // Returned to page_pool + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_FRAME_PP; } - - ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_FRAME; ctrl->tx.buffers[sdp].frame = frame; ctrl->tx.buffers[sdp].dma = dma; ctrl->tx.buffers[sdp].len = len; descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + + if (!xdp_frame_has_frags(frame)) { // Single buffer + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + } else { // Multi buffer + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 1); + } sdp = (sdp + 1) & mdp; - // update ctrl state + // FRAG PROCESSING + for(i = 0; i < nr_frags; ++i) { + frag = &xdp_get_shared_info_from_frame(frame)->frags[i]; + len = skb_frag_size(frag); + + // If page_pool, then the page is already mapped + if (!pp) { + dma = skb_frag_dma_map(ctrl->dma_dev, frag, 0, len, DMA_TO_DEVICE); + if (unlikely(ret = dma_mapping_error(ctrl->dma_dev, dma))) { + printk(KERN_ERR "nfb: %s failed to map frame\n", __func__); + if(!pp) { + goto unmap_exit; + } else { + goto exit; + } + } + } else { + dma = page_pool_get_dma_addr(skb_frag_page(frag)) + skb_frag_off(frag); + } + + last_upper_addr = ctrl->c.last_upper_addr; + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { + last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); + ctrl->c.last_upper_addr = last_upper_addr; + descs[sdp] = nc_ndp_tx_desc0(dma); + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; + sdp = (sdp + 1) & mdp; + } + + if (!pp) { + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_FRAME; + ctrl->tx.buffers[sdp].frame = NULL; + } else { + // Already completed by calling xdp_return_frame on the first fragment + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; + } + ctrl->tx.buffers[sdp].dma = dma; + ctrl->tx.buffers[sdp].len = len; + + if (i == nr_frags - 1) { // Last frag + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + } else { // Middle frag + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 1); + } + sdp = (sdp + 1) & mdp; + } + + // Update ctrl state ctrl->c.sdp = sdp; exit: return ret; + +unmap_exit: + // Reset sdp and unmap everything that was mapped (i frags + 1 head) + sdp = ctrl->c.sdp; + for (j = 0; j < i + 1; j++) { + tx_buff = &ctrl->tx.buffers[sdp]; + if (tx_buff->type == NFB_XCTRL_BUFF_FRAME) + dma_unmap_single(ctrl->dma_dev, tx_buff->dma, tx_buff->len, DMA_TO_DEVICE); + + sdp = (sdp + 1) & mdp; + } + return ret; } #endif // CTRL_XDP_COMMON_H diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c index 3b00b15d..ec3cd80d 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c @@ -25,79 +25,24 @@ */ static inline int nfb_xctrl_rexmit_pp(struct xctrl *ctrl, struct xdp_buff *xdp) { - dma_addr_t dma; - u32 free_desc; - u32 len; - u32 min_len = ETH_ZLEN; int ret = 0; - - // ctrl vars - struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; - u32 sdp = ctrl->c.sdp; - u32 mdp = ctrl->c.mdp; - u64 last_upper_addr = ctrl->c.last_upper_addr; - - // handle small packets - len = max((u32)(xdp->data_end - xdp->data), min_len); - // it is assumed here that we have whole page and that the headroom is XDP_PACKET_HEADROOM - if (xdp->data_end - xdp->data < min_len) { - memset(xdp->data_end, 0, ETH_ZLEN); + struct xdp_frame *frame; + // xdp_convert_buff_to_frame doesn't free on failure + if (unlikely(!(frame = xdp_convert_buff_to_frame(xdp)))) { + xdp_return_frame(frame); + ret = -ENOMEM; + goto exit; } - spin_lock(&ctrl->tx.tx_lock); { - // Reclaim tx buffers - nc_ndp_ctrl_hdp_update(&ctrl->c); - nfb_xctrl_tx_free_buffers(ctrl); - - free_desc = (ctrl->tx.fdp - sdp - 1) & mdp; - - dma = page_pool_get_dma_addr(virt_to_page(xdp->data_hard_start)) + XDP_PACKET_HEADROOM; - - if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { - if (unlikely(free_desc < 2)) { - printk(KERN_ERR "nfb: %s busy warning\n", __func__); - ret = -EBUSY; - goto exit_free; - } - - last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); - ctrl->c.last_upper_addr = last_upper_addr; - descs[sdp] = nc_ndp_tx_desc0(dma); - ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; - free_desc--; - sdp = (sdp + 1) & mdp; - } - - if (unlikely(free_desc == 0)) { - printk(KERN_ERR "nfb: %s busy warning\n", __func__); - ret = -EBUSY; - goto exit_free; - } - - ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_FRAME_PP; - // Here the xdp buffer is located on the ctrl.rx.xdp_ring - // converting buff to frame writes the metadata into XDP_PACKET_HEADROOM - // this frees the ctrl.rx.xdp_ring buffer to be reused - ctrl->tx.buffers[sdp].frame = xdp_convert_buff_to_frame(xdp); - descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); - dma_sync_single_for_device(ctrl->dma_dev, dma, len, DMA_BIDIRECTIONAL); - sdp = (sdp + 1) & mdp; - - // update ctrl - ctrl->c.sdp = sdp; - -exit_free: + // Process tx + ret = nfb_xctrl_tx_submit_frame_needs_lock(ctrl, frame, true); if (unlikely(ret)) { - // xdp_return_buff definition is missing in 4.18.0-477.10.1.el8_8.x86_64 - // xdp_return_buff(xdp); - xdp_return_frame(xdp_convert_buff_to_frame(xdp)); + xdp_return_frame(frame); } - - // Flush counters when done - nc_ndp_ctrl_sdp_flush(&ctrl->c); } spin_unlock(&ctrl->tx.tx_lock); +exit: return ret; } @@ -112,31 +57,29 @@ static inline int nfb_xctrl_rx_fill_pp(struct xctrl *ctrl) { const u32 batch_size = NFB_XDP_CTRL_PACKET_BURST; - // ctrl vars + // Ctrl vars u64 last_upper_addr = ctrl->c.last_upper_addr; - u32 mdp = ctrl->c.mdp; + const u32 mdp = ctrl->c.mdp; u32 sdp = ctrl->c.sdp; - u32 mhp = ctrl->c.mhp; - u32 php = ctrl->rx.php; + const u32 mbp = ctrl->rx.mbp; + u32 fbp = ctrl->rx.fbp; - // NOTE: XDP should have reserved tailroom for passing the page to the network stack - const u32 frame_len = PAGE_SIZE - SKB_DATA_ALIGN(XDP_PACKET_HEADROOM + sizeof(struct skb_shared_info)); struct page_pool *pool = ctrl->rx.pp.pool; struct page *page; dma_addr_t dma; struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; - u32 free_desc, free_hdrs; - u32 i; + u32 free_desc, free_buffs; + u32 filled; // Check if refill needed nc_ndp_ctrl_hdp_update(&ctrl->c); - free_hdrs = (ctrl->c.shp - php - 1) & mhp; + free_buffs = (ctrl->rx.pbp - fbp - 1) & mbp; free_desc = (ctrl->c.hdp - sdp - 1) & mdp; - if (free_hdrs < batch_size || free_desc < batch_size) + if (free_buffs < batch_size || free_desc < batch_size) return 0; // Alloc buffers and send them to card - for (i = 0; i < batch_size; i++) { + for (filled = 0; filled < batch_size; filled++) { if (!(page = page_pool_dev_alloc_pages(pool))) { printk(KERN_WARNING "nfb: failed to allocate page from page pool\n"); break; @@ -144,7 +87,7 @@ static inline int nfb_xctrl_rx_fill_pp(struct xctrl *ctrl) dma = page_pool_get_dma_addr(page) + XDP_PACKET_HEADROOM; if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { if (unlikely(free_desc == 0)) { - page_pool_put_full_page(pool, page, false); + page_pool_put_full_page(pool, page, true); break; } last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); @@ -154,22 +97,26 @@ static inline int nfb_xctrl_rx_fill_pp(struct xctrl *ctrl) free_desc--; } if (unlikely(free_desc == 0)) { - page_pool_put_full_page(pool, page, false); + page_pool_put_full_page(pool, page, true); break; } - xdp_init_buff(ctrl->rx.pp.xdp_ring[php], PAGE_SIZE, &ctrl->rx.rxq_info); - xdp_prepare_buff(ctrl->rx.pp.xdp_ring[php], page_to_virt(page), XDP_PACKET_HEADROOM, 0, false); - descs[sdp] = nc_ndp_rx_desc2(dma, frame_len, 0); + + // Init the buffer + xdp_init_buff(ctrl->rx.pp.xdp_ring[fbp], PAGE_SIZE, &ctrl->rx.rxq_info); + xdp_prepare_buff(ctrl->rx.pp.xdp_ring[fbp], page_to_virt(page), XDP_PACKET_HEADROOM, 0, false); + xdp_buff_clear_frags_flag(ctrl->rx.pp.xdp_ring[fbp]); + xdp_get_shared_info_from_buff(ctrl->rx.pp.xdp_ring[fbp])->nr_frags = 0; + + descs[sdp] = nc_ndp_rx_desc2(dma, NFB_PP_MAX_FRAME_LEN, 1); sdp = (sdp + 1) & mdp; - php = (php + 1) & mhp; + fbp = (fbp + 1) & mbp; free_desc--; } - // update ctrl state - ctrl->rx.php = php; + // Update ctrl state + ctrl->rx.fbp = fbp; ctrl->c.sdp = sdp; - - return i; + return filled; } /** @@ -180,7 +127,7 @@ static inline int nfb_xctrl_rx_fill_pp(struct xctrl *ctrl) * @param rxq * @return result */ -static inline void nfb_xctrl_handle_pp(struct bpf_prog *prog, struct xdp_buff *xdp, struct nfb_xdp_queue *rxq) +static inline void nfb_xctrl_handle_pp(struct bpf_prog *prog, struct xdp_buff *xdp, struct nfb_xdp_queue *rxq, struct napi_struct *napi) { unsigned act; int ret; @@ -199,14 +146,13 @@ static inline void nfb_xctrl_handle_pp(struct bpf_prog *prog, struct xdp_buff *x switch (act) { case XDP_PASS: - // NOTE: This function does a lot of things internally, check it's implementation - // if you ever want to add support for fragmented packets + // TODO: This function does a lot of steps some of which might not be entirely necessary. skb = xdp_build_skb_from_frame(xdp_convert_buff_to_frame(xdp), ethdev->netdev); if (IS_ERR_OR_NULL(skb)) { printk(KERN_DEBUG "SKB build failed\n"); goto aborted; } - // receive packet onto queue it arriverd on + // Receive packet onto queue it arriverd on skb_record_rx_queue(skb, channel->index); // TODO: gro_receive is supposed to be a free // performance boost but it is quite bad for @@ -223,11 +169,11 @@ static inline void nfb_xctrl_handle_pp(struct bpf_prog *prog, struct xdp_buff *x // } break; case XDP_TX: - // returned via xdp_return_frame on tx reclaim; + // Returned via xdp_return_frame on tx reclaim; nfb_xctrl_rexmit_pp(channel->txq.ctrl, xdp); break; case XDP_REDIRECT: - // redirected packet is internally returned via xdp_return_frame + // Redirected packet is internally returned via xdp_return_frame ret = xdp_do_redirect(ethdev->netdev, xdp, xdp_prog); if (unlikely(ret)) { printk(KERN_ERR "nfb: xdp_do_redirect error ret: %d\n", ret); @@ -250,16 +196,23 @@ static inline void nfb_xctrl_handle_pp(struct bpf_prog *prog, struct xdp_buff *x rcu_read_unlock(); } -static inline u16 nfb_xctrl_rx_pp(struct xctrl *ctrl, struct xdp_buff **buffs, u16 nb_pkts) +static inline u16 nfb_xctrl_rx_pp(struct xctrl *ctrl, u16 nb_pkts, struct nfb_ethdev *ethdev, struct nfb_xdp_queue *rxq, struct napi_struct *napi) { + u32 len_remain; struct nc_ndp_hdr *hdrs = ctrl->rx.hdr_buffer_cpu; struct nc_ndp_hdr *hdr; u32 i; u16 nb_rx; u32 shp = ctrl->c.shp; - u32 mhp = ctrl->c.mhp; + const u32 mhp = ctrl->c.mhp; + u32 pbp = ctrl->rx.pbp; + const u32 mbp = ctrl->rx.mbp; + + struct xdp_buff *head; + struct xdp_buff *frag; + struct skb_shared_info *sinfo; - // fill the card with empty buffers + // Fill the card with empty buffers while (nfb_xctrl_rx_fill_pp(ctrl)) ; nc_ndp_ctrl_sdp_flush(&ctrl->c); @@ -270,20 +223,50 @@ static inline u16 nfb_xctrl_rx_pp(struct xctrl *ctrl, struct xdp_buff **buffs, u if (nb_pkts < nb_rx) nb_rx = nb_pkts; - // ready packets for receive + // Ready packets for receive for (i = 0; i < nb_rx; ++i) { + // Get one packet (can be fragmented) hdr = &hdrs[shp]; - buffs[i] = ctrl->rx.pp.xdp_ring[shp]; - dma_sync_single_for_cpu(ctrl->dma_dev, page_pool_get_dma_addr(virt_to_page(buffs[i]->data_hard_start)), PAGE_SIZE, DMA_BIDIRECTIONAL); - buffs[i]->data_end = buffs[i]->data + hdr->frame_len; - // NOTE: Right now fragmented buffers are not supported - // Setting this is important if SKB is to be built from pagepool page without copying - // xdp_get_shared_info_from_buff(buffs[i])->nr_frags = 0; shp = (shp + 1) & mhp; + len_remain = hdr->frame_len; + + // Get the first fragment (head) + head = ctrl->rx.pp.xdp_ring[pbp]; + pbp = (pbp + 1) & mbp; + dma_sync_single_for_cpu(ctrl->dma_dev, page_pool_get_dma_addr(virt_to_page(head->data_hard_start)), PAGE_SIZE, DMA_BIDIRECTIONAL); + + // Process head + if (len_remain > NFB_PP_MAX_FRAME_LEN) { // Is fragmented + head->data_end = head->data + NFB_PP_MAX_FRAME_LEN; + len_remain -= NFB_PP_MAX_FRAME_LEN; + xdp_buff_set_frags_flag(head); + sinfo = xdp_get_shared_info_from_buff(head); + sinfo->xdp_frags_size = len_remain; + } else { // Not fragmented + head->data_end = head->data + len_remain; + len_remain -= len_remain; + } + + // Process frags + while (len_remain) { + frag = ctrl->rx.pp.xdp_ring[pbp]; + pbp = (pbp + 1) & mbp; + dma_sync_single_for_cpu(ctrl->dma_dev, page_pool_get_dma_addr(virt_to_page(frag->data_hard_start)), PAGE_SIZE, DMA_BIDIRECTIONAL); + if (len_remain > NFB_PP_MAX_FRAME_LEN) { // Not last fragment + skb_frag_fill_page_desc(&sinfo->frags[sinfo->nr_frags++], virt_to_page(frag->data_hard_start), XDP_PACKET_HEADROOM, NFB_PP_MAX_FRAME_LEN); + len_remain -= NFB_PP_MAX_FRAME_LEN; + } else { // Last fragment + skb_frag_fill_page_desc(&sinfo->frags[sinfo->nr_frags++], virt_to_page(frag->data_hard_start), XDP_PACKET_HEADROOM, len_remain); + len_remain -= len_remain; + } + } + + nfb_xctrl_handle_pp(ethdev->prog, head, rxq, napi); } - // update ctrl state + // Update ctrl state ctrl->c.shp = shp; + ctrl->rx.pbp = pbp; return nb_rx; } @@ -291,22 +274,22 @@ static inline u16 nfb_xctrl_rx_pp(struct xctrl *ctrl, struct xdp_buff **buffs, u int nfb_xctrl_napi_poll_pp(struct napi_struct *napi, int budget) { struct nfb_xdp_queue *rxq = container_of(napi, struct nfb_xdp_queue, napi); + struct nfb_xdp_channel *channel = container_of(rxq, struct nfb_xdp_channel, rxq); struct xctrl *ctrl = rxq->ctrl; struct net_device *netdev = napi->dev; struct nfb_ethdev *ethdev = netdev_priv(netdev); - unsigned received, i = 0; - struct xdp_buff *xdp[NAPI_POLL_WEIGHT]; - - if (unlikely(budget > NAPI_POLL_WEIGHT)) { - printk(KERN_ERR "nfb: NAPI budget is bigger than weight. This is a driver bug.\n"); - BUG(); + unsigned received; + + struct xctrl *txctrl = channel->txq.ctrl; + if(spin_trylock(&txctrl->tx.tx_lock)) { + // Flush the sdp since the XDP_TX could have enqueued some packets + nc_ndp_ctrl_sdp_flush(&txctrl->c); + nfb_xctrl_tx_free_buffers(txctrl, false); + spin_unlock(&txctrl->tx.tx_lock); } - received = nfb_xctrl_rx_pp(ctrl, xdp, budget); - for (i = 0; i < received; i++) { - nfb_xctrl_handle_pp(ethdev->prog, xdp[i], rxq); - } - // flush sdp and shp after software processing is done + received = nfb_xctrl_rx_pp(ctrl, budget, ethdev, rxq, napi); + // Flush rx sdp and shp after software processing is done nc_ndp_ctrl_sp_flush(&ctrl->c); // Flushes redirect maps @@ -428,6 +411,7 @@ struct xctrl *nfb_xctrl_alloc_pp(struct net_device *netdev, u32 queue_id, u32 de err = -ENOMEM; goto buff_alloc_fail; } + ctrl->rx.mbp = ctrl->nb_desc - 1; if (!(buffs = kzalloc_node(sizeof(struct xdp_buff) * desc_cnt, GFP_KERNEL, channel->numa))) { err = -ENOMEM; goto buffs_alloc_fail; @@ -554,7 +538,7 @@ void nfb_xctrl_destroy_pp(struct xctrl *ctrl) case NFB_XCTRL_TX: // free all enqueued tx buffers ctrl->c.hdp = ctrl->c.sdp; - nfb_xctrl_tx_free_buffers(ctrl); + nfb_xctrl_tx_free_buffers(ctrl, true); kfree(ctrl->tx.buffers); break; default: diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c index 3123ad15..7419b695 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c @@ -11,41 +11,91 @@ #include "ctrl_xdp_common.h" #include -// NOTE: This is not zero copy operation, the correct way to rexmit a frame -// in XSK mode is through the userspace from RX ring to TX ring. /** - * @brief Tries to rexmit xsk buffer. Frees buffer on fail via xdp_return_frame(); + * @brief Tries to rexmit xsk buffer. * * @param ctrl * @param xdp * @return 0 on success */ -static inline int nfb_xctrl_rexmit_xsk(struct xctrl *ctrl, struct xdp_buff *xdp) +static inline int nfb_xctrl_rexmit_xsk(struct xctrl *ctrl, struct xsk_buff_pool *pool, struct xdp_buff *xdp) { int ret = 0; - struct xdp_frame *frame; - // xdp_convert_buff_to_frame frees the xsk on success and doesn't free on failure - // this is af_xdp slow fallback - if (unlikely(!(frame = xdp_convert_buff_to_frame(xdp)))) { - xdp_return_frame(frame); - ret = -ENOMEM; - goto exit; - } + u32 free_desc; + dma_addr_t dma; + void *data; + u32 len; + + u64 last_upper_addr; + u32 sdp; + u32 mdp; + u32 n_frags, i; + + struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; + struct xdp_buff *frags[NFB_MAX_AF_XDP_FRAGS]; + + // Prepare frags + n_frags = 0; + frags[0] = xdp; // First frag + do { + len = frags[n_frags]->data_end - frags[n_frags]->data; + if (unlikely(len < ETH_ZLEN)) { // Pad the frag to min len + memset(data + len, 0, ETH_ZLEN - len); + len = ETH_ZLEN; + frags[n_frags]->data_end = frags[n_frags]->data + len; + } + ++n_frags; + } while((frags[n_frags] = xsk_buff_get_frag(xdp))); + spin_lock(&ctrl->tx.tx_lock); { - // reclaim tx buffers - nc_ndp_ctrl_hdp_update(&ctrl->c); - nfb_xctrl_tx_free_buffers(ctrl); - // process tx - ret = nfb_xctrl_tx_submit_frame_needs_lock(ctrl, frame); - if (unlikely(ret)) { - xdp_return_frame(frame); + sdp = ctrl->c.sdp; + mdp = ctrl->c.mdp; + free_desc = (ctrl->c.hdp - sdp - 1) & mdp; + + // Max 2 descriptors per frag will be used + // One to update the addr and second with data + if(free_desc < n_frags * 2) { + printk(KERN_ERR "nfb: XDP_TX busy warning, packet dropped\n"); + for (i = 0; i < n_frags; i++) + xsk_buff_free(frags[i]); + + ret = -EBUSY; + goto out; } - // flush - nc_ndp_ctrl_sdp_flush(&ctrl->c); + + for (i = 0; i < n_frags; i++) { + data = frags[i]->data; + dma = xsk_buff_xdp_get_dma(frags[i]); + len = frags[i]->data_end - frags[i]->data; + + last_upper_addr = ctrl->c.last_upper_addr; + if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { + last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); + ctrl->c.last_upper_addr = last_upper_addr; + descs[sdp] = nc_ndp_tx_desc0(dma); + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; + sdp = (sdp + 1) & mdp; + } + + ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_XSK_REXMIT; + ctrl->tx.buffers[sdp].xsk = frags[i]; + ctrl->tx.buffers[sdp].dma = dma; + ctrl->tx.buffers[sdp].len = len; + if(i == n_frags - 1) { // Last part of the packet + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + } else { // Another fragment incomming + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 1); + } + xsk_buff_raw_dma_sync_for_device(pool, dma, len); + sdp = (sdp + 1) & mdp; + } + + // Update ctrl + ctrl->c.sdp = sdp; +out: } spin_unlock(&ctrl->tx.tx_lock); -exit: return ret; } @@ -71,35 +121,37 @@ static inline int nfb_xctrl_rx_fill_xsk(struct xctrl *ctrl) { const u32 batch_size = NFB_XDP_CTRL_PACKET_BURST; - // ctrl vars + // Ctrl vars u64 last_upper_addr = ctrl->c.last_upper_addr; - u32 mdp = ctrl->c.mdp; + const u32 mdp = ctrl->c.mdp; u32 sdp = ctrl->c.sdp; - u32 mhp = ctrl->c.mhp; - u32 php = ctrl->rx.php; + const u32 mbp = ctrl->rx.mbp; + u32 fbp = ctrl->rx.fbp; - // helper vars u32 frame_len; struct xsk_buff_pool *pool = ctrl->rx.xsk.pool; struct xdp_buff *buffs[NFB_XDP_CTRL_PACKET_BURST]; dma_addr_t dma; struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; - u32 free_desc, free_hdrs; - u32 real_count, i; + u32 free_desc, free_buffs; + u32 real_count, filled; + + // TODO: check if there is a better way to know if SG was enabled in the userspace AF_XDP + bool sg_enabled = pool->umem->flags & XDP_UMEM_SG_FLAG; // Check if refill needed nc_ndp_ctrl_hdp_update(&ctrl->c); - free_hdrs = (ctrl->c.shp - php - 1) & mhp; + free_buffs = (ctrl->rx.pbp - fbp - 1) & mbp; free_desc = (ctrl->c.hdp - sdp - 1) & mdp; - if (free_hdrs < batch_size || free_desc < batch_size) + if (free_buffs < batch_size || free_desc < batch_size) return 0; // Alloc xsk buffers - frame_len = xsk_pool_get_rx_frame_size(pool); // internaly calculates with XDP_PACKET_HEADROOM + // Internaly calculates with XDP_PACKET_HEADROOM, shared info is not used + frame_len = xsk_pool_get_rx_frame_size(pool); real_count = xsk_buff_alloc_batch(pool, buffs, batch_size); - for (i = 0; i < real_count; i++) { - dma = xsk_buff_xdp_get_dma(buffs[i]); // Takes XDP_PACKET_HEADROOM into account - + for (filled = 0; filled < real_count; filled++) { + dma = xsk_buff_xdp_get_dma(buffs[filled]); // Takes XDP_PACKET_HEADROOM into account if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { if (unlikely(free_desc == 0)) { break; @@ -113,23 +165,54 @@ static inline int nfb_xctrl_rx_fill_xsk(struct xctrl *ctrl) if (unlikely(free_desc == 0)) { break; } - ctrl->rx.xsk.xdp_ring[php] = buffs[i]; - descs[sdp] = nc_ndp_rx_desc2(dma, frame_len, 0); + ctrl->rx.xsk.xdp_ring[fbp] = buffs[filled]; + descs[sdp] = nc_ndp_rx_desc2(dma, frame_len, sg_enabled); sdp = (sdp + 1) & mdp; - php = (php + 1) & mhp; + fbp = (fbp + 1) & mbp; free_desc--; } - // if the loop quits because there was too little free descriptors + // If the loop quits because there was too little free descriptors // the remaining buffers have to be freed - for (; i < real_count; i++) { - xsk_buff_free(buffs[i]); + for (; filled < real_count; filled++) { + xsk_buff_free(buffs[filled]); } - // update ctrl state - ctrl->rx.php = php; + // Update ctrl state + ctrl->rx.fbp = fbp; ctrl->c.sdp = sdp; - return i; + return filled; +} + +static inline struct sk_buff *nfb_napi_build_skb_from_xsk(struct xdp_buff *xdp, struct napi_struct *napi) { + struct sk_buff *skb; + u32 n_frags, i; + u32 len; + struct xdp_buff *frags[NFB_MAX_AF_XDP_FRAGS]; + + frags[0] = xdp; // First frag + len = xdp->data_end - xdp->data; + for (n_frags = 1; (frags[n_frags] = xsk_buff_get_frag(xdp)); n_frags++) { + len += frags[n_frags]->data_end - frags[n_frags]->data; + } + + // Alloc skb + skb = napi_alloc_skb(napi, len); + if (unlikely(!skb)) { + printk(KERN_ERR "%s: Failed to allocate SKB of len %u\n", __func__, len); + for (i = 0; i < n_frags; i++) + xsk_buff_free(frags[i]); + + goto out; + } + + // Memcpy data + for (i = 0; i < n_frags; i++) { + skb_put_data(skb, frags[i]->data, frags[i]->data_end - frags[i]->data); + xsk_buff_free(frags[i]); // Free the copied buffer + } +out: + return skb; } /** @@ -144,12 +227,16 @@ static inline void nfb_xctrl_handle_xsk(struct bpf_prog *prog, struct xdp_buff * { unsigned act; int ret; - struct xdp_frame *frame; struct sk_buff *skb; struct bpf_prog *xdp_prog; struct nfb_xdp_channel *channel = container_of(rxq, struct nfb_xdp_channel, rxq); struct nfb_ethdev *ethdev = channel->ethdev; + // Non zero copy redirect not supported with AF_XDP_SG as of (6.15) + // xdp_do_redirect calls xdp_convert_zc_to_xdp_frame which can only copy one page of data + struct bpf_redirect_info *ri = bpf_net_ctx_get_ri(); + enum bpf_map_type map_type = ri->map_type; + rcu_read_lock(); xdp_prog = rcu_dereference(prog); if (xdp_prog) { @@ -160,20 +247,15 @@ static inline void nfb_xctrl_handle_xsk(struct bpf_prog *prog, struct xdp_buff * switch (act) { case XDP_PASS: // This allocates memory => AF_XDP slow fallback for normal operation - frame = xdp_convert_buff_to_frame(xdp); - if (unlikely(!frame)) { - printk(KERN_DEBUG "SKB build failed\n"); - goto aborted; - } - // NOTE: This function does a lot of things internally, check it's implementation - // if you ever want to add support for fragmented packets - skb = xdp_build_skb_from_frame(frame, ethdev->netdev); + // All frags are freed on success and fail + skb = nfb_napi_build_skb_from_xsk(xdp, &rxq->napi); if (unlikely(IS_ERR_OR_NULL(skb))) { printk(KERN_DEBUG "SKB build failed\n"); - goto aborted; + break; } - // receive packet onto queue it arriverd on + // Receive packet onto queue it arriverd on skb_record_rx_queue(skb, channel->index); + skb->protocol = eth_type_trans(skb, channel->pool->netdev); // TODO gro_receive is supposed to be a free // performance boost but it is quite bad for // debugging because you cannot check if all packet @@ -188,14 +270,22 @@ static inline void nfb_xctrl_handle_xsk(struct bpf_prog *prog, struct xdp_buff * // } break; case XDP_TX: - // returned on tx reclaim; - nfb_xctrl_rexmit_xsk(channel->txq.ctrl, xdp); + // Returned on tx reclaim or freed on error; + nfb_xctrl_rexmit_xsk(channel->txq.ctrl, channel->pool, xdp); break; case XDP_REDIRECT: - // either redirected to userspace or returned internally - ret = xdp_do_redirect(ethdev->netdev, xdp, xdp_prog); - if (unlikely(ret)) { - printk(KERN_ERR "nfb: xdp_do_redirect error ret: %d\n", ret); + // Non zero copy redirect not supported with AF_XDP_SG as of (6.15) + // xdp_do_redirect calls xdp_convert_zc_to_xdp_frame which can only copy one page of data + ri = bpf_net_ctx_get_ri(); + map_type = ri->map_type; + if (unlikely(map_type != BPF_MAP_TYPE_XSKMAP)) { + printk(KERN_ERR "nfb: Only redirect to userspace supported in AF_XDP mode, dropping packet.\n"); + goto aborted; + } else { + if(unlikely((ret = xdp_do_redirect(ethdev->netdev, xdp, xdp_prog)))) { + printk(KERN_ERR "nfb: xdp_do_redirect error ret: %d\n", ret); + goto aborted; + } } break; default: @@ -220,70 +310,113 @@ static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size) } #endif -static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, struct xdp_buff **buffs, u16 nb_pkts) +static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_ethdev *ethdev, struct nfb_xdp_queue *rxq, struct napi_struct *napi) { - struct xdp_buff *buff; + u32 len_remain; + struct xdp_buff *head; + struct xdp_buff *frag; struct nc_ndp_hdr *hdrs = ctrl->rx.hdr_buffer_cpu; struct nc_ndp_hdr *hdr; u32 i; u16 nb_rx; u32 shp = ctrl->c.shp; - u32 mhp = ctrl->c.mhp; + const u32 mhp = ctrl->c.mhp; + u32 pbp = ctrl->rx.pbp; + const u32 mbp = ctrl->rx.mbp; + const u32 frame_size = xsk_pool_get_rx_frame_size(ctrl->rx.xsk.pool); - // fill the card with empty buffers + // Fill the card with empty buffers while (nfb_xctrl_rx_fill_xsk(ctrl)) ; nc_ndp_ctrl_sdp_flush(&ctrl->c); - // get the amount of packets ready to be processed + // Get the amount of packets ready to be processed nc_ndp_ctrl_hhp_update(&ctrl->c); nb_rx = (ctrl->c.hhp - shp) & mhp; if (nb_pkts < nb_rx) nb_rx = nb_pkts; - // ready packets for receive + // Ready packets for receive for (i = 0; i < nb_rx; ++i) { - buff = ctrl->rx.xsk.xdp_ring[shp]; + // Get one packet (can be fragmented) hdr = &hdrs[shp]; - xsk_buff_set_size(buff, hdr->frame_len); // sets the actual data size after receive + shp = (shp + 1) & mhp; + len_remain = hdr->frame_len; + + // Get the first fragment (head) + head = ctrl->rx.xsk.xdp_ring[pbp]; + pbp = (pbp + 1) & mbp; #ifdef CONFIG_HAVE_ONE_ARG_XSK_BUFF_DMA_SYNC - xsk_buff_dma_sync_for_cpu(buff); + xsk_buff_dma_sync_for_cpu(head); #else - xsk_buff_dma_sync_for_cpu(buff, ctrl->rx.xsk.pool); + xsk_buff_dma_sync_for_cpu(head, ctrl->rx.xsk.pool); #endif - buffs[i] = buff; - shp = (shp + 1) & mhp; + // Process head + if (len_remain > frame_size) { // Is fragmented + xsk_buff_set_size(head, frame_size); + len_remain -= frame_size; + xdp_buff_set_frags_flag(head); + } else { // Not fragmented + xsk_buff_set_size(head, len_remain); + len_remain -= len_remain; + } + + // Process frags + while(len_remain) { + frag = ctrl->rx.xsk.xdp_ring[pbp]; + pbp = (pbp + 1) & mbp; +#ifdef CONFIG_HAVE_ONE_ARG_XSK_BUFF_DMA_SYNC + xsk_buff_dma_sync_for_cpu(frag); +#else + xsk_buff_dma_sync_for_cpu(buff_curr, ctrl->rx.xsk.pool); +#endif + if (len_remain > frame_size) { // Not last fragment + xsk_buff_set_size(frag, frame_size); + len_remain -= frame_size; + } else { // Last fragment + xsk_buff_set_size(frag, len_remain); + len_remain -= len_remain; + } + xsk_buff_add_frag(frag); + } + + nfb_xctrl_handle_xsk(ethdev->prog, head, rxq); } // update ctrl state ctrl->c.shp = shp; + ctrl->rx.pbp = pbp; + return nb_rx; } int nfb_xctrl_napi_poll_rx_xsk(struct napi_struct *napi, int budget) { struct nfb_xdp_queue *rxq = container_of(napi, struct nfb_xdp_queue, napi); + struct nfb_xdp_channel *channel = container_of(rxq, struct nfb_xdp_channel, rxq); + struct xsk_buff_pool *pool = channel->pool; struct xctrl *ctrl = rxq->ctrl; + struct net_device *netdev = napi->dev; struct nfb_ethdev *ethdev = netdev_priv(netdev); - unsigned received, i = 0; - struct xdp_buff *xdp[NAPI_POLL_WEIGHT]; - - if (unlikely(budget > NAPI_POLL_WEIGHT)) { - printk(KERN_ERR "nfb: NAPI budget is bigger than weight. This is a driver bug.\n"); - BUG(); + unsigned received; + + // TODO: maybe look at splitting the reclaim for the XDP_TX action to move to rx napi and rest move to tx + // The issue is that calling the xsk_buff_free from TX reclaim + // while calling it from for an example XDP_PASS skb build corrupts the xsk_buff list + // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv + // The tx reclaim needs to be in rx napi because rx napi calls xsk_buff_free + struct xctrl *txctrl = channel->txq.ctrl; + if(spin_trylock(&txctrl->tx.tx_lock)) { + // Free the completed tx buffers + nfb_xctrl_tx_free_buffers(txctrl, false); + xsk_tx_completed(pool, txctrl->tx.completed_xsk_tx); + txctrl->tx.completed_xsk_tx = 0; + spin_unlock(&txctrl->tx.tx_lock); } - received = nfb_xctrl_rx_xsk(ctrl, xdp, budget); - for (i = 0; i < received; i++) { - if (unlikely(PAGE_SIZE < xdp[i]->data_end - xdp[i]->data_hard_start)) { - printk(KERN_ERR "nfb: XSK got packet too large, current max size: %lu\n", PAGE_SIZE - (xdp[i]->data - xdp[i]->data_hard_start)); - xsk_buff_free(xdp[i]); - continue; - } - nfb_xctrl_handle_xsk(ethdev->prog, xdp[i], rxq); - } - // flush sdp and shp after software processing is done + received = nfb_xctrl_rx_xsk(ctrl, budget, ethdev, rxq, napi); + // Flush sdp and shp after software processing is done nc_ndp_ctrl_sp_flush(&ctrl->c); // Flushes redirect maps @@ -310,22 +443,24 @@ int nfb_xctrl_napi_poll_tx_xsk(struct napi_struct *napi, int budget) dma_addr_t dma; void *data; u32 len; - u32 min_len = ETH_ZLEN; - u64 last_upper_addr = ctrl->c.last_upper_addr; - u32 sdp = ctrl->c.sdp; - u32 mdp = ctrl->c.mdp; + u64 last_upper_addr; + u32 sdp; + u32 mdp; struct nc_ndp_desc *descs = ctrl->desc_buffer_virt; spin_lock(&ctrl->tx.tx_lock); { - // free the completed buffers - nc_ndp_ctrl_hdp_update(&ctrl->c); - nfb_xctrl_tx_free_buffers(ctrl); - xsk_tx_completed(pool, ctrl->tx.completed_xsk_tx); - ctrl->tx.completed_xsk_tx = 0; - - free_desc = (ctrl->tx.fdp - sdp - 1) & mdp; + sdp = ctrl->c.sdp; + mdp = ctrl->c.mdp; + + // Max 2 descriptors per frag will be used + // One to update the addr and second with data + free_desc = (ctrl->c.hdp - sdp - 1) & mdp; + if(free_desc < budget * 2) { + printk(KERN_WARNING "nfb: AF_XDP TX busy warning, skipped one poll\n"); + goto out; + } ready = xsk_tx_peek_release_desc_batch(pool, budget); if (!ready) { @@ -338,47 +473,33 @@ int nfb_xctrl_napi_poll_tx_xsk(struct napi_struct *napi, int budget) dma = xsk_buff_raw_get_dma(pool, buffs[i].addr); len = buffs[i].len; - // TODO: There should be a len check. using pool.frame_len somewhere when setting up the xsk queue - if (len < min_len) { // Usable frame space is smaller than min_len. - // printk(KERN_DEBUG "TX: %s memsetting len: %d to %d\n", __func__, len, min_len); - memset(data + len, 0, min_len - len); - len = min_len; + if (len < ETH_ZLEN) { // Packet is too small + memset(data + len, 0, ETH_ZLEN - len); + len = ETH_ZLEN; } + last_upper_addr = ctrl->c.last_upper_addr; if (unlikely(NDP_CTRL_DESC_UPPER_ADDR(dma) != last_upper_addr)) { - if (unlikely(free_desc < 2)) { - printk(KERN_ERR "nfb: %s busy warning\n", __func__); - goto out; - } - last_upper_addr = NDP_CTRL_DESC_UPPER_ADDR(dma); ctrl->c.last_upper_addr = last_upper_addr; descs[sdp] = nc_ndp_tx_desc0(dma); ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_DESC_TYPE0; - free_desc--; sdp = (sdp + 1) & mdp; } - if (unlikely(free_desc == 0)) { - printk(KERN_ERR "nfb: nfb_xctrl_xmit busy warning\n"); - goto out; - } ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_XSK; - ctrl->tx.buffers[sdp].num_of_xsk_completions = 1 + ctrl->tx.last_napi_xsk_drops; - ctrl->tx.last_napi_xsk_drops = 0; - ctrl->tx.buffers[sdp].dma = dma; - ctrl->tx.buffers[sdp].len = len; - descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + if(xsk_is_eop_desc(&buffs[i])) { // Last part of the packet + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); + } else { // Another fragment incomming + descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 1); + } xsk_buff_raw_dma_sync_for_device(pool, dma, len); - free_desc--; sdp = (sdp + 1) & mdp; } -out: - // update ctrl - ctrl->tx.last_napi_xsk_drops += ready - i; + // Update ctrl ctrl->c.sdp = sdp; - - // flush counters when done +out: + // Flush counters when done (Maybe frames were enqueued by XDP_TX) nc_ndp_ctrl_sdp_flush(&ctrl->c); } spin_unlock(&ctrl->tx.tx_lock); @@ -470,6 +591,7 @@ struct xctrl *nfb_xctrl_alloc_xsk(struct net_device *netdev, u32 queue_id, struc // Allocating control buffers switch (type) { case NFB_XCTRL_RX: + ctrl->rx.mbp = ctrl->nb_desc - 1; if (!(ctrl->rx.xsk.xdp_ring = kzalloc_node(sizeof(struct xdp_buff *) * ctrl->nb_desc, GFP_KERNEL, channel->numa))) { err = -ENOMEM; goto buff_alloc_fail; @@ -581,7 +703,7 @@ void nfb_xctrl_destroy_xsk(struct xctrl *ctrl) case NFB_XCTRL_TX: // free all enqueued tx buffers ctrl->c.hdp = ctrl->c.sdp; - nfb_xctrl_tx_free_buffers(ctrl); + nfb_xctrl_tx_free_buffers(ctrl, true); kfree(ctrl->tx.buffers); break; default: diff --git a/drivers/kernel/drivers/nfb/xdp/ethdev.c b/drivers/kernel/drivers/nfb/xdp/ethdev.c index 9f15ccd5..f801efe7 100644 --- a/drivers/kernel/drivers/nfb/xdp/ethdev.c +++ b/drivers/kernel/drivers/nfb/xdp/ethdev.c @@ -115,12 +115,18 @@ static int nfb_start_channels(struct net_device *netdev) val = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | NETDEV_XDP_ACT_XSK_ZEROCOPY - // | NETDEV_XDP_ACT_RX_SG + | NETDEV_XDP_ACT_RX_SG | NETDEV_XDP_ACT_NDO_XMIT - // | NETDEV_XDP_ACT_NDO_XMIT_SG + | NETDEV_XDP_ACT_NDO_XMIT_SG ; xdp_set_features_flag(netdev, val); #endif + // Default value + netdev->xdp_zc_max_segs = NFB_MAX_AF_XDP_FRAGS; + netdev->min_mtu = NFB_XDP_MTU_MIN; + netdev->max_mtu = NFB_XDP_MTU_MAX; + netdev->mtu = NFB_XDP_MTU_MAX; + netdev->features |= NETIF_F_SG; // Threads take care of setting up and tearing down the queues as XDP demands the abillity to do that on the fly for (i = 0; i < ethdev->channel_count; i++) { From caa16bc915c0e04b9fadb954b421b235858463c5 Mon Sep 17 00:00:00 2001 From: Richard Hyros Date: Tue, 8 Jul 2025 09:28:19 +0200 Subject: [PATCH 401/518] fix(xdp driver): add fixes for kernel 4.18 --- drivers/configure.ac | 33 ++++++++++++++ drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h | 2 +- .../kernel/drivers/nfb/xdp/ctrl_xdp_common.h | 4 ++ drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c | 15 ++++++- drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c | 44 ++++++++++++++++--- drivers/kernel/drivers/nfb/xdp/ethdev.c | 2 + 6 files changed, 90 insertions(+), 10 deletions(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index 439f9287..3e05b38b 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -384,6 +384,39 @@ void test(void) {xsk_buff_dma_sync_for_cpu(NULL);} [AC_DEFINE([CONFIG_HAVE_ONE_ARG_XSK_BUFF_DMA_SYNC], [1], [Define if kernel has httimer_setup]) AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) {u32 flag = NETDEV_XDP_ACT_RX_SG; +printk("%u", flag);} +]], +[AC_MSG_CHECKING([whether kernel supports basic XDP SG])], +[AC_DEFINE([CONFIG_HAVE_XDP_SG], [1], [Define if kernel supports basic XDP SG]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) { + struct net_device netdev; + netdev.xdp_zc_max_segs = 42;} +]], +[AC_MSG_CHECKING([whether kernel supports AF_XDP SG])], +[AC_DEFINE([CONFIG_HAVE_AF_XDP_SG], [1], [Define if kernel supports AF_XDP SG]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) { + struct bpf_redirect_info *ri; + ri = bpf_net_ctx_get_ri(); + } +]], +[AC_MSG_CHECKING([whether kernel has bpf_net_ctx_get_ri])], +[AC_DEFINE([CONFIG_HAVE_BPF_NET_CTX_GET_RI], [1], [Define if kernel has bpf_net_ctx_get_ri]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + # wait for the jobs to finnish, remove file used for locking if it exists wait rm -rf flock_lockfile >/dev/null 2>/dev/null diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h index 403ef923..3afaf66a 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp.h @@ -19,7 +19,7 @@ #define NFB_XDP_MTU_MIN 64 #define NFB_XDP_MTU_MAX 16383 // Default AF_XDP value, can be made larger or smaller -#define NFB_MAX_AF_XDP_FRAGS CONFIG_MAX_SKB_FRAGS + 1 +#define NFB_MAX_AF_XDP_FRAGS MAX_SKB_FRAGS + 1 #define NFB_XDP_CTRL_PACKET_BURST 64 #define NFB_PP_MAX_FRAME_LEN PAGE_SIZE - XDP_PACKET_HEADROOM - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h index f8cc122d..4af80645 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_common.h @@ -165,7 +165,11 @@ static inline int nfb_xctrl_tx_submit_frame_needs_lock(struct xctrl *ctrl, struc ctrl->tx.buffers[sdp].len = len; descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); +#ifndef CONFIG_HAVE_XDP_SG + if (true) { // Single buffer +#else if (!xdp_frame_has_frags(frame)) { // Single buffer +#endif descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); } else { // Multi buffer descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 1); diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c index ec3cd80d..c93e981d 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_pp.c @@ -104,10 +104,13 @@ static inline int nfb_xctrl_rx_fill_pp(struct xctrl *ctrl) // Init the buffer xdp_init_buff(ctrl->rx.pp.xdp_ring[fbp], PAGE_SIZE, &ctrl->rx.rxq_info); xdp_prepare_buff(ctrl->rx.pp.xdp_ring[fbp], page_to_virt(page), XDP_PACKET_HEADROOM, 0, false); - xdp_buff_clear_frags_flag(ctrl->rx.pp.xdp_ring[fbp]); xdp_get_shared_info_from_buff(ctrl->rx.pp.xdp_ring[fbp])->nr_frags = 0; - +#ifdef CONFIG_HAVE_XDP_SG + xdp_buff_clear_frags_flag(ctrl->rx.pp.xdp_ring[fbp]); descs[sdp] = nc_ndp_rx_desc2(dma, NFB_PP_MAX_FRAME_LEN, 1); +#else + descs[sdp] = nc_ndp_rx_desc2(dma, NFB_PP_MAX_FRAME_LEN, 0); +#endif sdp = (sdp + 1) & mdp; fbp = (fbp + 1) & mbp; free_desc--; @@ -209,8 +212,10 @@ static inline u16 nfb_xctrl_rx_pp(struct xctrl *ctrl, u16 nb_pkts, struct nfb_et const u32 mbp = ctrl->rx.mbp; struct xdp_buff *head; +#ifdef CONFIG_HAVE_XDP_SG struct xdp_buff *frag; struct skb_shared_info *sinfo; +#endif // Fill the card with empty buffers while (nfb_xctrl_rx_fill_pp(ctrl)) @@ -236,17 +241,22 @@ static inline u16 nfb_xctrl_rx_pp(struct xctrl *ctrl, u16 nb_pkts, struct nfb_et dma_sync_single_for_cpu(ctrl->dma_dev, page_pool_get_dma_addr(virt_to_page(head->data_hard_start)), PAGE_SIZE, DMA_BIDIRECTIONAL); // Process head +#ifndef CONFIG_HAVE_XDP_SG + if (false) { +#else if (len_remain > NFB_PP_MAX_FRAME_LEN) { // Is fragmented head->data_end = head->data + NFB_PP_MAX_FRAME_LEN; len_remain -= NFB_PP_MAX_FRAME_LEN; xdp_buff_set_frags_flag(head); sinfo = xdp_get_shared_info_from_buff(head); sinfo->xdp_frags_size = len_remain; +#endif } else { // Not fragmented head->data_end = head->data + len_remain; len_remain -= len_remain; } +#ifdef CONFIG_HAVE_XDP_SG // Process frags while (len_remain) { frag = ctrl->rx.pp.xdp_ring[pbp]; @@ -260,6 +270,7 @@ static inline u16 nfb_xctrl_rx_pp(struct xctrl *ctrl, u16 nb_pkts, struct nfb_et len_remain -= len_remain; } } +#endif nfb_xctrl_handle_pp(ethdev->prog, head, rxq, napi); } diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c index 7419b695..c41c927d 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c @@ -45,7 +45,11 @@ static inline int nfb_xctrl_rexmit_xsk(struct xctrl *ctrl, struct xsk_buff_pool frags[n_frags]->data_end = frags[n_frags]->data + len; } ++n_frags; +#ifdef CONFIG_HAVE_AF_XDP_SG } while((frags[n_frags] = xsk_buff_get_frag(xdp))); +#else + } while(false); +#endif spin_lock(&ctrl->tx.tx_lock); { @@ -93,8 +97,8 @@ static inline int nfb_xctrl_rexmit_xsk(struct xctrl *ctrl, struct xsk_buff_pool // Update ctrl ctrl->c.sdp = sdp; -out: } +out: spin_unlock(&ctrl->tx.tx_lock); return ret; } @@ -136,8 +140,12 @@ static inline int nfb_xctrl_rx_fill_xsk(struct xctrl *ctrl) u32 free_desc, free_buffs; u32 real_count, filled; +#ifdef CONFIG_HAVE_AF_XDP_SG // TODO: check if there is a better way to know if SG was enabled in the userspace AF_XDP bool sg_enabled = pool->umem->flags & XDP_UMEM_SG_FLAG; +#else + const bool sg_enabled = false; +#endif // Check if refill needed nc_ndp_ctrl_hdp_update(&ctrl->c); @@ -192,9 +200,13 @@ static inline struct sk_buff *nfb_napi_build_skb_from_xsk(struct xdp_buff *xdp, frags[0] = xdp; // First frag len = xdp->data_end - xdp->data; +#ifdef CONFIG_HAVE_AF_XDP_SG for (n_frags = 1; (frags[n_frags] = xsk_buff_get_frag(xdp)); n_frags++) { len += frags[n_frags]->data_end - frags[n_frags]->data; } +#else + n_frags = 1; +#endif // Alloc skb skb = napi_alloc_skb(napi, len); @@ -234,8 +246,8 @@ static inline void nfb_xctrl_handle_xsk(struct bpf_prog *prog, struct xdp_buff * // Non zero copy redirect not supported with AF_XDP_SG as of (6.15) // xdp_do_redirect calls xdp_convert_zc_to_xdp_frame which can only copy one page of data - struct bpf_redirect_info *ri = bpf_net_ctx_get_ri(); - enum bpf_map_type map_type = ri->map_type; + struct bpf_redirect_info *ri; + enum bpf_map_type map_type; rcu_read_lock(); xdp_prog = rcu_dereference(prog); @@ -276,7 +288,11 @@ static inline void nfb_xctrl_handle_xsk(struct bpf_prog *prog, struct xdp_buff * case XDP_REDIRECT: // Non zero copy redirect not supported with AF_XDP_SG as of (6.15) // xdp_do_redirect calls xdp_convert_zc_to_xdp_frame which can only copy one page of data +#ifdef CONFIG_HAVE_BPF_NET_CTX_GET_RI ri = bpf_net_ctx_get_ri(); +#else + ri = this_cpu_ptr(&bpf_redirect_info); +#endif map_type = ri->map_type; if (unlikely(map_type != BPF_MAP_TYPE_XSKMAP)) { printk(KERN_ERR "nfb: Only redirect to userspace supported in AF_XDP mode, dropping packet.\n"); @@ -313,8 +329,6 @@ static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size) static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_ethdev *ethdev, struct nfb_xdp_queue *rxq, struct napi_struct *napi) { u32 len_remain; - struct xdp_buff *head; - struct xdp_buff *frag; struct nc_ndp_hdr *hdrs = ctrl->rx.hdr_buffer_cpu; struct nc_ndp_hdr *hdr; u32 i; @@ -323,7 +337,12 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e const u32 mhp = ctrl->c.mhp; u32 pbp = ctrl->rx.pbp; const u32 mbp = ctrl->rx.mbp; + + struct xdp_buff *head; +#ifdef CONFIG_HAVE_XDP_SG + struct xdp_buff *frag; const u32 frame_size = xsk_pool_get_rx_frame_size(ctrl->rx.xsk.pool); +#endif // Fill the card with empty buffers while (nfb_xctrl_rx_fill_xsk(ctrl)) @@ -351,16 +370,22 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e #else xsk_buff_dma_sync_for_cpu(head, ctrl->rx.xsk.pool); #endif + +#ifndef CONFIG_HAVE_XDP_SG + if (false) { +#else // Process head if (len_remain > frame_size) { // Is fragmented xsk_buff_set_size(head, frame_size); len_remain -= frame_size; xdp_buff_set_frags_flag(head); +#endif } else { // Not fragmented xsk_buff_set_size(head, len_remain); len_remain -= len_remain; } - + +#ifdef CONFIG_HAVE_XDP_SG // Process frags while(len_remain) { frag = ctrl->rx.xsk.xdp_ring[pbp]; @@ -368,7 +393,7 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e #ifdef CONFIG_HAVE_ONE_ARG_XSK_BUFF_DMA_SYNC xsk_buff_dma_sync_for_cpu(frag); #else - xsk_buff_dma_sync_for_cpu(buff_curr, ctrl->rx.xsk.pool); + xsk_buff_dma_sync_for_cpu(frag, ctrl->rx.xsk.pool); #endif if (len_remain > frame_size) { // Not last fragment xsk_buff_set_size(frag, frame_size); @@ -379,6 +404,7 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e } xsk_buff_add_frag(frag); } +#endif nfb_xctrl_handle_xsk(ethdev->prog, head, rxq); } @@ -488,7 +514,11 @@ int nfb_xctrl_napi_poll_tx_xsk(struct napi_struct *napi, int budget) } ctrl->tx.buffers[sdp].type = NFB_XCTRL_BUFF_XSK; +#ifndef CONFIG_HAVE_AF_XDP_SG + if(true) { +#else if(xsk_is_eop_desc(&buffs[i])) { // Last part of the packet +#endif descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 0); } else { // Another fragment incomming descs[sdp] = nc_ndp_tx_desc2(dma, len, 0, 1); diff --git a/drivers/kernel/drivers/nfb/xdp/ethdev.c b/drivers/kernel/drivers/nfb/xdp/ethdev.c index f801efe7..f950e6e7 100644 --- a/drivers/kernel/drivers/nfb/xdp/ethdev.c +++ b/drivers/kernel/drivers/nfb/xdp/ethdev.c @@ -122,7 +122,9 @@ static int nfb_start_channels(struct net_device *netdev) xdp_set_features_flag(netdev, val); #endif // Default value +#ifdef CONFIG_HAVE_AF_XDP_SG netdev->xdp_zc_max_segs = NFB_MAX_AF_XDP_FRAGS; +#endif netdev->min_mtu = NFB_XDP_MTU_MIN; netdev->max_mtu = NFB_XDP_MTU_MAX; netdev->mtu = NFB_XDP_MTU_MAX; From ccf58c00f5da72b378e1f9fb4cd7e5b058c7729d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Tue, 8 Jul 2025 12:49:04 +0200 Subject: [PATCH 402/518] fix(xdp driver): add fixes for kernel 6.15 --- drivers/configure.ac | 17 ++++++++++++++--- drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index 3e05b38b..290f90ef 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -409,14 +409,25 @@ KERNEL_TRY_COMPILE([[ #include void test(void); void test(void) { - struct bpf_redirect_info *ri; - ri = bpf_net_ctx_get_ri(); - } + struct bpf_redirect_info *ri; + ri = bpf_net_ctx_get_ri(); +} ]], [AC_MSG_CHECKING([whether kernel has bpf_net_ctx_get_ri])], [AC_DEFINE([CONFIG_HAVE_BPF_NET_CTX_GET_RI], [1], [Define if kernel has bpf_net_ctx_get_ri]) AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) { + xsk_buff_add_frag(NULL); +} +]], +[AC_MSG_CHECKING([whether kernel has one arg xsk_buff_add_frag])], +[AC_DEFINE([CONFIG_HAVE_ONE_ARG_XSK_BUFF_ADD_FRAG], [1], [Define if kernel has one arg xsk_buff_add_frag]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + # wait for the jobs to finnish, remove file used for locking if it exists wait rm -rf flock_lockfile >/dev/null 2>/dev/null diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c index c41c927d..be5575d7 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c @@ -343,6 +343,9 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e struct xdp_buff *frag; const u32 frame_size = xsk_pool_get_rx_frame_size(ctrl->rx.xsk.pool); #endif +#ifndef CONFIG_HAVE_ONE_ARG_XSK_BUFF_ADD_FRAG + struct xdp_buff_xsk *xsk_struct; +#endif // Fill the card with empty buffers while (nfb_xctrl_rx_fill_xsk(ctrl)) @@ -394,7 +397,7 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e xsk_buff_dma_sync_for_cpu(frag); #else xsk_buff_dma_sync_for_cpu(frag, ctrl->rx.xsk.pool); -#endif +#endif // CONFIG_HAVE_ONE_ARG_XSK_BUFF_DMA_SYNC if (len_remain > frame_size) { // Not last fragment xsk_buff_set_size(frag, frame_size); len_remain -= frame_size; @@ -402,9 +405,17 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e xsk_buff_set_size(frag, len_remain); len_remain -= len_remain; } +#ifdef CONFIG_HAVE_ONE_ARG_XSK_BUFF_ADD_FRAG xsk_buff_add_frag(frag); +#else + // Revert the behavior of xsk_buff_add_frag to not touch the shared info struct (pre 6.14) + // This saves 384 bytes in each AF_XDP frame for AFAIK no sideeffects + // This also allows to defer setup needed for the creation of skb to the last moment + xsk_struct = container_of(frag, struct xdp_buff_xsk, xdp); + list_add_tail(&xsk_struct->list_node, &xsk_struct->pool->xskb_list); +#endif // CONFIG_HAVE_ONE_ARG_XSK_BUFF_ADD_FRAG } -#endif +#endif // CONFIG_HAVE_XDP_SG nfb_xctrl_handle_xsk(ethdev->prog, head, rxq); } From 35e973f74f5a47a4461d4b3b292437c19b714e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hyro=C5=A1?= Date: Tue, 8 Jul 2025 14:11:11 +0200 Subject: [PATCH 403/518] fix(xdp driver): add fixes for kernel 5.15 --- drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c index be5575d7..3e3bdc3e 100644 --- a/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c +++ b/drivers/kernel/drivers/nfb/xdp/ctrl_xdp_xsk.c @@ -339,13 +339,13 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e const u32 mbp = ctrl->rx.mbp; struct xdp_buff *head; -#ifdef CONFIG_HAVE_XDP_SG +#ifdef CONFIG_HAVE_AF_XDP_SG struct xdp_buff *frag; const u32 frame_size = xsk_pool_get_rx_frame_size(ctrl->rx.xsk.pool); -#endif #ifndef CONFIG_HAVE_ONE_ARG_XSK_BUFF_ADD_FRAG struct xdp_buff_xsk *xsk_struct; -#endif +#endif // CONFIG_HAVE_ONE_ARG_XSK_BUFF_ADD_FRAG +#endif // CONFIG_HAVE_AF_XDP_SG // Fill the card with empty buffers while (nfb_xctrl_rx_fill_xsk(ctrl)) @@ -374,7 +374,7 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e xsk_buff_dma_sync_for_cpu(head, ctrl->rx.xsk.pool); #endif -#ifndef CONFIG_HAVE_XDP_SG +#ifndef CONFIG_HAVE_AF_XDP_SG if (false) { #else // Process head @@ -388,7 +388,7 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e len_remain -= len_remain; } -#ifdef CONFIG_HAVE_XDP_SG +#ifdef CONFIG_HAVE_AF_XDP_SG // Process frags while(len_remain) { frag = ctrl->rx.xsk.xdp_ring[pbp]; @@ -415,7 +415,7 @@ static inline u16 nfb_xctrl_rx_xsk(struct xctrl *ctrl, u16 nb_pkts, struct nfb_e list_add_tail(&xsk_struct->list_node, &xsk_struct->pool->xskb_list); #endif // CONFIG_HAVE_ONE_ARG_XSK_BUFF_ADD_FRAG } -#endif // CONFIG_HAVE_XDP_SG +#endif // CONFIG_HAVE_AF_XDP_SG nfb_xctrl_handle_xsk(ethdev->prog, head, rxq); } From a9738a1919d0edb457936cc6b995739f7045c92b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 14 Jul 2025 20:35:33 +0200 Subject: [PATCH 404/518] bump version to 6.28.0 --- Changelog | 8 ++++++++ VERSION | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 5ce12e7a..56215b78 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,11 @@ +* Mon Jul 14 2025 Martin Spinler - 6.28.0-1 +- [FEATURE] drivers: add XDP driver (needs to be enabled in configure) +- [FEATURE] tools: add XDP example tools (xdp-read, xdp-generate) +- [FEATURE] tools: add JSON output to nfb-info, nfb-dma, nfb-eth +- [FEATURE] nfb-eth: add items for RxMAC-v3 statistic counters +- [FIX] card FB2CGHH (Tivoli): - force switch flash before FPGA reload +- [MAINTENANCE] nfb-eth: rename and unify labels for statistic counters in nfb-eth + * Mon Jun 9 2025 Martin Spinler - 6.27.0-1 - [FEATURE]: add I2C / QSFP support for BittWare BMC (ia-440i) - [FEATURE] nfb-dma/driver: add dynamic netdev management for ndp_netdev diff --git a/VERSION b/VERSION index 9cd1a39f..2ece8e17 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.27.0 +6.28.0 From 1bf4f9ac891c976bf0d52bc2b848eed995a1dadf Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 15 Jul 2025 21:31:13 +0200 Subject: [PATCH 405/518] fix(nfb-eth): update counter names for real --- tools/eth/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/eth/main.c b/tools/eth/main.c index 228d06bf..4433fa7f 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -41,7 +41,7 @@ #define NJFD(x) ni_json_f_decim(x) -#define COMPAT_NAMES 1 +#define COMPAT_NAMES 0 static struct ni_context_item_default ni_items[] = { [NI_SEC_ROOT] = {ni_json_e, ni_user_n}, From c641200c1f7d3e10e24a7da992f97a34d16aedc8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 15 Jul 2025 21:34:08 +0200 Subject: [PATCH 406/518] bump version to 6.28.1 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 56215b78..83f00423 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Tue Jul 15 2025 Martin Spinler - 6.28.1-1 +- [FIX] nfb-eth: really rename and unify labels for statistic counters in nfb-eth + * Mon Jul 14 2025 Martin Spinler - 6.28.0-1 - [FEATURE] drivers: add XDP driver (needs to be enabled in configure) - [FEATURE] tools: add XDP example tools (xdp-read, xdp-generate) diff --git a/VERSION b/VERSION index 2ece8e17..8993da97 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.28.0 +6.28.1 From 1a025ab4dda0bae5489e988245bff86ec868d856 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 28 Jul 2025 13:14:00 +0200 Subject: [PATCH 407/518] fix(tool - eth): show new etherStats items --- tools/eth/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/eth/main.c b/tools/eth/main.c index 4433fa7f..d5e73672 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -154,6 +154,10 @@ static struct ni_context_item_default ni_items[] = { [NI_RXM_ES_256_511] = {ni_json_k("pkts256to511"), ni_user_f("etherStatsPkts256to511Octets", NUFC)}, [NI_RXM_ES_512_1023] = {ni_json_k("pkts512to1023"), ni_user_f("etherStatsPkts512to1023Octets", NUFC)}, [NI_RXM_ES_1024_1518] = {ni_json_k("pkts1024to1518"), ni_user_f("etherStatsPkts1024to1518Octets", NUFC)}, + [NI_RXM_ES_1519_2047] = {ni_json_k("pkts1519to2047"), ni_user_f("etherStatsPkts1519to2047Octets", NUFC)}, + [NI_RXM_ES_2048_4095] = {ni_json_k("pkts2048to4095"), ni_user_f("etherStatsPkts2048to4095Octets", NUFC)}, + [NI_RXM_ES_4096_8191] = {ni_json_k("pkts4096to8191"), ni_user_f("etherStatsPkts4096to8191Octets", NUFC)}, + [NI_RXM_ES_OVER_BINS] = {ni_json_k("pktsOverBins"), ni_user_f("etherStatsPktsOverBins", NUFC)}, [NI_RXM_ES_UNDR_SET] = {ni_json_k("conf_undersize"), ni_user_f("underMinPkts", NUFC)}, [NI_RXM_ES_OVER_SET] = {ni_json_k("conf_oversize"), ni_user_f("overMaxPkts", NUFC)}, From 7de8996675fa31c5b27a607008d388ad1358636a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 28 Jul 2025 13:16:01 +0200 Subject: [PATCH 408/518] bump version to 6.28.2 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 83f00423..68101298 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Mon Jul 28 2025 Martin Spinler - 6.28.2-1 +- [FIX] nfb-eth: show new etherStats items + * Tue Jul 15 2025 Martin Spinler - 6.28.1-1 - [FIX] nfb-eth: really rename and unify labels for statistic counters in nfb-eth diff --git a/VERSION b/VERSION index 8993da97..bb9f64b0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.28.1 +6.28.2 From e468f4e0528d8609d704ab52a9c78288f160c07c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 30 Jul 2025 14:46:32 +0200 Subject: [PATCH 409/518] fix(tool - eth): use correct fields for extended stats --- tools/eth/rxmac.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index 2261d2d0..726367ba 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -109,9 +109,9 @@ void rxmac_print_ether_stats(struct ni_context *ctx, struct nc_rxmac *rxmac) ni_item_uint64_t(ctx, NI_RXM_ES_512_1023, s.pkts512to1023Octets); ni_item_uint64_t(ctx, NI_RXM_ES_1024_1518, s.pkts1024to1518Octets); if (rxmac->has_ext_drop_counters) { - ni_item_uint64_t(ctx, NI_RXM_ES_1519_2047, s.pkts128to255Octets); - ni_item_uint64_t(ctx, NI_RXM_ES_2048_4095, s.pkts256to511Octets); - ni_item_uint64_t(ctx, NI_RXM_ES_4096_8191, s.pkts512to1023Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_1519_2047, s.pkts1519to2047Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_2048_4095, s.pkts2048to4095Octets); + ni_item_uint64_t(ctx, NI_RXM_ES_4096_8191, s.pkts4096to8191Octets); ni_item_uint64_t(ctx, NI_RXM_ES_OVER_BINS, s.pktsOverBinsOctets); } ni_item_uint64_t(ctx, NI_RXM_ES_UNDR_SET, s.underMinPkts); From d9a18a00833201e3fff59b5bbb9ef0f2a70b10a6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 30 Jul 2025 14:48:37 +0200 Subject: [PATCH 410/518] bump version to 6.28.3 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 68101298..75cf620a 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Wed Jul 30 2025 Martin Spinler - 6.28.3-1 +- [FIX] nfb-eth: show correct values in new etherStats items + * Mon Jul 28 2025 Martin Spinler - 6.28.2-1 - [FIX] nfb-eth: show new etherStats items diff --git a/VERSION b/VERSION index bb9f64b0..3b4b6fd2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.28.2 +6.28.3 From 6809e0b2319a841135c51a15a1a7598dd963eff2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 15 Aug 2025 15:03:28 +0200 Subject: [PATCH 411/518] feat: support more variants of IA-440i in boot driver --- drivers/kernel/drivers/nfb/boot/bw-bmc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/boot/bw-bmc.c b/drivers/kernel/drivers/nfb/boot/bw-bmc.c index 84154824..862f8eea 100644 --- a/drivers/kernel/drivers/nfb/boot/bw-bmc.c +++ b/drivers/kernel/drivers/nfb/boot/bw-bmc.c @@ -178,7 +178,9 @@ static int nfb_boot_bw_bmc_load_partition_table(struct nfb_boot *boot) if (card_name == NULL) { return -ENODEV; - } else if (strcmp(card_name, "IA-440I") == 0) { + } else if (strncmp(card_name, "IA-440I", 7) == 0) { + /* TODO: check Flash Configuration from VPD (I2C EEPROM @ 0x57, offset 50): + * 0 means "Default" */ max_size = 0x10000000; } else { return -ENODEV; From 2b1ca4a84f71ffc6d0bd6ba704671e3b5c5553ea Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 21 Aug 2025 14:32:42 +0200 Subject: [PATCH 412/518] fix: update PKGBUILD for Arch distro --- package/PKGBUILD | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package/PKGBUILD b/package/PKGBUILD index b427e886..2cf65512 100644 --- a/package/PKGBUILD +++ b/package/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Martin Spinler -pkgname=('nfb-framework' 'python-nfb' 'nfb-ext-grpc') -pkgver=6.22.6 +pkgname=('nfb-framework' 'python-nfb' 'nfb-framework-debug' 'nfb-ext-grpc' 'python-nfb-tools') +pkgver=6.28.3 pkgrel=1 pkgdesc="Software bundle for CESNET NDK firmware platform" url='https://github.com/CESNET/ndk-sw' @@ -39,6 +39,9 @@ package_nfb-framework-debug() { package_python-nfb() { DESTDIR="$pkgdir" cmake --install build --component python } +package_python-nfb-tools() { + DESTDIR="$pkgdir" cmake --install build --component pythontools +} package_nfb-ext-grpc() { depends=('grpc') From 6208942a91941eefa9470914b6a3632033206404 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 21 Aug 2025 14:38:46 +0200 Subject: [PATCH 413/518] bump version to 6.28.4 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 75cf620a..85090c9e 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Thu Aug 21 2025 Martin Spinler - 6.28.4-1 +- [FEATURE]: add support for different varians of ia-440i card + * Wed Jul 30 2025 Martin Spinler - 6.28.3-1 - [FIX] nfb-eth: show correct values in new etherStats items diff --git a/VERSION b/VERSION index 3b4b6fd2..3290bcf4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.28.3 +6.28.4 From 0121515158df73d5ed9b824c6f570058ad1c8b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bene=C5=A1?= Date: Tue, 17 Jun 2025 11:55:40 +0200 Subject: [PATCH 414/518] feat(drivers): add support for fb2cdg1 --- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 13 ++++++++++++- drivers/kernel/drivers/nfb/pci.c | 2 +- tools/boot/boot.c | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index c8461160..99fee39c 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -309,6 +309,17 @@ int nfb_pmci_attach(struct nfb_boot *boot) int ret = 0; int sn; + void *fdt; + int node; + const char *card_name; + + fdt = nfb_get_fdt(boot->nfb); + node = fdt_path_offset(fdt, "/firmware"); + card_name = fdt_getprop(fdt, node, "card-name", NULL); + if (card_name == NULL) { + return -ENODEV; + } + pmci = kzalloc(sizeof(*pmci), GFP_KERNEL); if (!pmci) { ret = -ENOMEM; @@ -333,7 +344,7 @@ int nfb_pmci_attach(struct nfb_boot *boot) mutex_init(&pmci->flash_ops.mux_lock); pmci->m10bmc.dev = &pmci->pd->dev; - pmci->m10bmc.type = M10_N6000; + pmci->m10bmc.type = !strcmp(card_name, "FB2CDG1") ? M10_FB2CDG1 : M10_N6000; pmci->m10bmc.flash_ops = &pmci->flash_ops; pmci->m10bmc.regmap = nfb_devm_regmap_init_indirect_register(&pmci->pd->dev, diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 5ecd8064..6186142a 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -354,7 +354,7 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) nfb_fdt_create_binary_slot(fdt, node, "image1", "recovery" , 1, 0, 0, 0x00210000, 0x02000000-0x210000); nfb_fdt_create_binary_slot(fdt, node, "image0", "application0" , 0, 1, 0, 0x02000000, 0x04000000); //nfb_fdt_create_boot_type(fdt, node, "BPI", 16); - } else if (!strcmp(card_name, "N6010")) { + } else if (!strcmp(card_name, "N6010") || !strcmp(card_name, "FB2CDG1")) { subnode = nfb_fdt_create_binary_slot(fdt, node, "image2", "fpga_factory", 2, 2, -1, 0, 0); n6010_binary_slot_prepare(fdt, subnode, "\x03\x00\x00\x00", "\xff\xff\xff\xff", 4); subnode = nfb_fdt_create_binary_slot(fdt, node, "image1", "fpga_user2", 1, 4, -1, 0, 0); diff --git a/tools/boot/boot.c b/tools/boot/boot.c index 8e8ead15..dfd4cc3d 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -685,7 +685,7 @@ int card_requires_sleep(const void *fdt) { fdt_offset = fdt_path_offset(fdt, "/firmware/"); prop = fdt_getprop(fdt, fdt_offset, "card-name", &len); if (prop != NULL) { - if (!strcmp(prop, "N6010")) { + if (!strcmp(prop, "N6010") || !strcmp(prop, "FB2CDG1")) { return 1; } } From 6213deaba01a2eef79d2fc6d7213c2e0c6c2c65a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Oct 2025 08:51:50 +0200 Subject: [PATCH 415/518] chore: use 3rdparty version v6.28.4 --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 48a91067..ed146f59 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ AUTOINSTALL=true # whether dependencies should be installed with '-y' RELTYPE=Release # Release type (Debug/Release) FILENAME_3RDPARTY="3rdparty.tar.gz" -SRC_3RDPARTY_VERSION="v6.26.4" +SRC_3RDPARTY_VERSION="v6.28.4" URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_VERSION/$FILENAME_3RDPARTY" EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" From 6e10f5c6fb2fa30ce19de2f4e586aaf847783f2b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Oct 2025 08:54:04 +0200 Subject: [PATCH 416/518] bump version to 6.28.5 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 85090c9e..555f4452 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Wed Oct 15 2025 Martin Spinler - 6.28.5-1 +- [FEATURE]: add support for fb2cdg1 + * Thu Aug 21 2025 Martin Spinler - 6.28.4-1 - [FEATURE]: add support for different varians of ia-440i card diff --git a/VERSION b/VERSION index 3290bcf4..db774514 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.28.4 +6.28.5 From c6527aea88424584f0331c403fe5a858fcacaf41 Mon Sep 17 00:00:00 2001 From: David Vodak Date: Fri, 31 Oct 2025 14:45:12 +0100 Subject: [PATCH 417/518] feat(tool - boot): add missing --force option The command was ready for this feature, it even told user to use this option, but it was not yet implemented. --- tools/boot/boot.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/boot/boot.c b/tools/boot/boot.c index dfd4cc3d..a94ea7e5 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -82,6 +82,7 @@ void usage(const char *me) printf("-v Be verbose\n"); printf("-l Print list of available slots\n"); printf("-h Print this help message\n"); + printf("--force Force writing bitstream to the card, USE WITH CAUTION!\n"); printf("\n"); printf("Quick boot:\n"); printf("Boot the device from selected slot and check if the signature\n"); @@ -759,12 +760,24 @@ int main(int argc, char *argv[]) int flags = 0; int verbose = 0; enum commands cmd = CMD_UNKNOWN; + const struct option long_options[] = { + {"force", no_argument, 0, 0}, + {0, 0, 0, 0} + }; + int option_index = 0; if (!isatty(fileno(stdout))) flags |= FLAG_QUIET; - while ((c = getopt(argc, argv, ARGUMENTS)) != -1) { + while ((c = getopt_long(argc, argv, ARGUMENTS, long_options, &option_index)) >= 0) { switch (c) { + case 0: + if (!strcmp(long_options[option_index].name, "force")) { + flags |= FLAG_FORCE; + } else { + errx(-1, "Unknown long option"); + } + break; case 'h': cmd = CMD_USAGE; break; From 79117cf684089f609deb54bee5d25c163d02c1fa Mon Sep 17 00:00:00 2001 From: David Vodak Date: Mon, 3 Nov 2025 17:38:36 +0100 Subject: [PATCH 418/518] chore(tool - boot): improve warning --- tools/boot/boot.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/boot/boot.c b/tools/boot/boot.c index a94ea7e5..a1512141 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -352,7 +352,12 @@ int check_boot_success(const char *path_by_pci, int cmd, const char *filename) dev = nfb_open(path_by_pci); if (dev == NULL) { - warnx("can't open device file after boot; can be caused by a corrupted configuration file or unsupported hotplug on this platform"); + warnx( + "can't open device file after boot; " + "can be caused by a corrupted configuration file, " + "unsupported hotplug on this platform " + "or changed PCIe address of the main device" + ); } else { if (cmd == CMD_WRITE_AND_BOOT) { archive_read_first_file_with_extension(filename, ".dtb", &fdt); From 820bf18e7108cc262bcf206d52ab832b2afd0340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Ko=C5=A1a=C5=99?= Date: Tue, 4 Nov 2025 20:03:59 +0100 Subject: [PATCH 419/518] fix(net driver): add fix for kernel 6.17 --- drivers/configure.ac | 17 +++++++++++++++++ drivers/kernel/drivers/nfb/net/device.c | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/drivers/configure.ac b/drivers/configure.ac index 290f90ef..70af1056 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -366,6 +366,23 @@ void test(void) {timer_delete_sync(NULL);} [AC_DEFINE([CONFIG_HAVE_TIMER_DELETE_SYNC], [1], [Define if kernel has timer_delete_sync]) AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) +KERNEL_TRY_COMPILE([[ +#include +struct priv_device { + int stuff; + struct timer_list service_timer; +}; +void test(void); +void test(void) { + struct priv_device dev; + struct timer_list *t = &dev.service_timer; + struct priv_device *priv = timer_container_of(priv, t, service_timer); +} +]], +[AC_MSG_CHECKING([whether kernel has timer_container_of])], +[AC_DEFINE([CONFIG_HAS_TIMER_CONTAINER_OF], [1], [Define if kernel has timer_container_of]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + KERNEL_TRY_COMPILE([[ #include void test(void); diff --git a/drivers/kernel/drivers/nfb/net/device.c b/drivers/kernel/drivers/nfb/net/device.c index d05092a2..6d570c4f 100644 --- a/drivers/kernel/drivers/nfb/net/device.c +++ b/drivers/kernel/drivers/nfb/net/device.c @@ -182,7 +182,11 @@ static void nfb_net_mac_off(struct net_device *netdev) #ifdef CONFIG_HAS_TIMER_SETUP static void nfb_net_service_timer(struct timer_list *t) { +#ifdef CONFIG_HAS_TIMER_CONTAINER_OF + struct nfb_net_device *priv = timer_container_of(priv, t, service_timer); +#else struct nfb_net_device *priv = from_timer(priv, t, service_timer); +#endif #else static void nfb_net_service_timer(unsigned long data) { From b00546672b528c2fcf0d9595e76533e4f7dcd130 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Nov 2025 10:44:18 +0100 Subject: [PATCH 420/518] fix(drivers): error handling in nfb_pci_probe_main --- drivers/kernel/drivers/nfb/pci.c | 54 ++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 6186142a..8bb93358 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -219,7 +219,7 @@ static void nfb_pci_fdt_update_endpoints(struct nfb_device *nfb) * nfb_fdt_fixups - Fix the FDT: Create missing nodes and properties * @nfb: NFB device */ -static void nfb_fdt_fixups(struct nfb_device *nfb) +static int nfb_fdt_fixups(struct nfb_device *nfb) { static const char *flag_fb_select_flash = "fb_select_flash"; static const char *flag_flash_set_async = "flash_set_async"; @@ -262,7 +262,7 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) } if (node < 0) - return; + return 0; /* Add binary slots to DT for coresponding partitions for Flash access and booting */ /* TODO - move definition to firmware FDT */ @@ -394,17 +394,20 @@ static void nfb_fdt_fixups(struct nfb_device *nfb) nfb_fdt_create_boot_type(fdt, node, "SPI", 4); } } + return 0; } /* * nfb_pci_create_fallback_fdt - Create empty DT with MI bus and boot controller for firmware with no DT support * @nfb: NFB device */ -static void nfb_pci_create_fallback_fdt(struct nfb_device *nfb) +static int nfb_pci_create_fallback_fdt(struct nfb_device *nfb) { int node; if (nfb->fdt == NULL) { nfb->fdt = kzalloc(NFB_FDT_MAXSIZE, GFP_KERNEL); + if (nfb->fdt == NULL) + return -ENOMEM; fdt_create_empty_tree(nfb->fdt, NFB_FDT_MAXSIZE); } @@ -427,6 +430,7 @@ static void nfb_pci_create_fallback_fdt(struct nfb_device *nfb) fdt_setprop_string(nfb->fdt, node, "compatible", "netcope,boot_controller"); fdt_setprop_u64(nfb->fdt, node, "reg", 0x0000200000000008l); } + return 0; } /* @@ -630,7 +634,7 @@ static void *nfb_pci_read_fdt(struct pci_dev *pci) return ERR_PTR(ret); } -static void *nfb_pci_copy_fdt(struct nfb_pci_device *pci_device) +static int nfb_pci_copy_fdt(struct nfb_pci_device *pci_device, void **fdtp) { const int FDT_SIZE_MULTIPLIER = 4; @@ -659,12 +663,13 @@ static void *nfb_pci_copy_fdt(struct nfb_pci_device *pci_device) dev_info(&pci_device->pci->dev, "FDT loaded, size: %u, allocated buffer size: %zu\n", fdt_totalsize(fdt), len); fdt_set_totalsize(fdt, len); - return fdt; + *fdtp = fdt; + return 0; err_fdt_malloc: err_no_fdtlen: err_no_fdt: - return ERR_PTR(ret); + return ret; } /* @@ -1112,26 +1117,26 @@ static int nfb_pci_probe_main(struct nfb_pci_device *pci_device, const struct pc nfb->dsn = pci_device->dsn; - nfb->fdt = nfb_dtb_inject; - if (nfb->fdt == NULL) { - /* Populate device tree */ - nfb->fdt = nfb_pci_copy_fdt(pci_device); - } - if (IS_ERR(nfb->fdt)) { - ret = PTR_ERR(nfb->fdt); - dev_err(&pci->dev, "unable to read firmware description - DTB\n"); - - if (!fallback_fdt) - goto err_nfb_read_fdt; - else - nfb->fdt = NULL; + /* Populate device tree */ + if (nfb_dtb_inject) { + nfb->fdt = nfb_dtb_inject; + ret = 0; + } else { + ret = nfb_pci_copy_fdt(pci_device, &nfb->fdt); + if (ret) + dev_err(&pci->dev, "unable to read firmware description - DTB\n"); } /* Create fallback or modify existing FDT to support booting */ if (fallback_fdt) - nfb_pci_create_fallback_fdt(nfb); + ret = nfb_pci_create_fallback_fdt(nfb); - nfb_fdt_fixups(nfb); + if (nfb->fdt == NULL) + goto err_nfb_read_fdt; + + ret = nfb_fdt_fixups(nfb); + if (ret) + goto err_nfb_fdt_fixups; nfb_pci_attach_endpoint(nfb, pci_device, 0); @@ -1163,13 +1168,14 @@ static int nfb_pci_probe_main(struct nfb_pci_device *pci_device, const struct pc return 0; /* Error handling */ + //nfb_remove(nfb); err_nfb_probe: - kfree(nfb->fdt); -err_nfb_read_fdt: free_irq(pci->irq, nfb); pci_disable_msi(pci); - //err_pci_enable_msi: +err_nfb_fdt_fixups: + kfree(nfb->fdt); +err_nfb_read_fdt: nfb_destroy(nfb); err_nfb_create: return ret; From 3ec8067803d01fbb5a05cf343eacf80a83d991c5 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Nov 2025 13:36:57 +0100 Subject: [PATCH 421/518] feat(drivers): store card_name into struct nfb_device --- drivers/kernel/drivers/nfb/boot/boot.c | 5 ----- drivers/kernel/drivers/nfb/core.c | 2 ++ drivers/kernel/drivers/nfb/nfb.h | 1 + drivers/kernel/drivers/nfb/pci.c | 11 +++++++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index e6b1130b..0fa5a4b4 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -461,11 +461,6 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) nfb_boot_read_card_subtype(nfb, boot); } - /* Backward compatibility with firmware, which doesn't have card-name property in DT */ - fdt_offset = fdt_path_offset(nfb->fdt, "/firmware"); - if (fdt_getprop(nfb->fdt, fdt_offset, "card-name", &len) == NULL) - fdt_setprop_string(nfb->fdt, fdt_offset, "card-name", nfb->pci_name); - fdt_offset = fdt_path_offset(nfb->fdt, "/board"); fdt_setprop_string(nfb->fdt, fdt_offset, "board-name", nfb->pci_name); if (nfb->serial_str) { diff --git a/drivers/kernel/drivers/nfb/core.c b/drivers/kernel/drivers/nfb/core.c index 58a024c1..118247c2 100644 --- a/drivers/kernel/drivers/nfb/core.c +++ b/drivers/kernel/drivers/nfb/core.c @@ -186,6 +186,8 @@ void nfb_destroy(struct nfb_device *nfb) { if (nfb->serial_str) kfree(nfb->serial_str); + if (nfb->card_name) + kfree(nfb->card_name); kfree(nfb); } diff --git a/drivers/kernel/drivers/nfb/nfb.h b/drivers/kernel/drivers/nfb/nfb.h index ab0ceb3a..6a773360 100644 --- a/drivers/kernel/drivers/nfb/nfb.h +++ b/drivers/kernel/drivers/nfb/nfb.h @@ -112,6 +112,7 @@ struct nfb_lock_item { struct nfb_device { struct pci_dev *pci; /* Associated PCI device (master) */ int minor; /* Minor number assigned to this device (used for X in /dev/nfbX) */ + const char *card_name; /* Card name obtained from the Device Tree (not NULL) */ const char *serial_str; /* String version of serial number. If is NULL, the 'serial' member should be used. */ uint64_t serial; /* Card serial number */ uint64_t dsn; /* FPGA chip unique identifier */ diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index 8bb93358..c910b855 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -252,8 +252,15 @@ static int nfb_fdt_fixups(struct nfb_device *nfb) node = fdt_path_offset(fdt, "/firmware"); card_name = fdt_getprop(fdt, node, "card-name", &proplen); - if (proplen <= 0) - card_name = ""; + if (card_name == NULL) { + /* Backward compatibility with firmware, which doesn't have card-name property in DT */ + card_name = nfb->pci_name; + fdt_setprop_string(nfb->fdt, node, "card-name", card_name); + } + + nfb->card_name = kstrdup(card_name, GFP_KERNEL); + if (nfb->card_name == NULL) + return -ENOMEM; for (node = -1, i = 0; i < ARRAY_SIZE(boot_ctrl_compatibles); i++) { node = fdt_node_offset_by_compatible(fdt, -1, boot_ctrl_compatibles[i]); From b3aacb1d91df87645d3f9d59dfa3d2c95e29fed2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Nov 2025 09:47:30 +0100 Subject: [PATCH 422/518] fix(drivers - IA-440): increase PCIe Link up wait time on reload The BittWare IA-440 card needs more time to settle PCIe link after boot. --- drivers/kernel/drivers/nfb/boot/boot.c | 3 +++ drivers/kernel/drivers/nfb/boot/boot.h | 2 ++ drivers/kernel/drivers/nfb/boot/bw-bmc.c | 4 ++++ drivers/kernel/drivers/nfb/boot/reload.c | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 0fa5a4b4..b577cee6 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -373,6 +373,9 @@ int nfb_boot_attach(struct nfb_device *nfb, void **priv) *priv = boot; boot->nfb = nfb; + + boot->reload_link_up_time = 600; + mutex_init(&boot->load_mutex); #ifdef CONFIG_NFB_ENABLE_PMCI ret = nfb_pmci_attach(boot); diff --git a/drivers/kernel/drivers/nfb/boot/boot.h b/drivers/kernel/drivers/nfb/boot/boot.h index 3c39ad19..2c2e1abd 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.h +++ b/drivers/kernel/drivers/nfb/boot/boot.h @@ -59,6 +59,8 @@ struct nfb_boot { unsigned current_op_progress_max; unsigned current_op_progress; } load; + + unsigned int reload_link_up_time; }; struct mtd_info *cfi_probe(struct map_info *map); diff --git a/drivers/kernel/drivers/nfb/boot/bw-bmc.c b/drivers/kernel/drivers/nfb/boot/bw-bmc.c index 862f8eea..135052f2 100644 --- a/drivers/kernel/drivers/nfb/boot/bw-bmc.c +++ b/drivers/kernel/drivers/nfb/boot/bw-bmc.c @@ -291,6 +291,10 @@ int nfb_boot_bw_bmc_attach(struct nfb_boot* boot) nfb_boot_bw_bmc_load_partition_table(boot); + if (strncmp(boot->nfb->card_name, "IA-440I", 7) == 0) { + boot->reload_link_up_time = 2500; + } + return 0; } diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index 82cb94d3..51464ace 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -306,7 +306,7 @@ int nfb_boot_reload(void *arg) /* * Wait some time until the Link Up */ - msleep(600); + msleep(boot->reload_link_up_time); /* Rescan PCIe slaves */ for (i = 0; i < 2; i++) { From 6978764d176af1221dc467f0cde615903d7962e6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 6 Nov 2025 13:59:57 +0100 Subject: [PATCH 423/518] chore(drivers - card_name): use card_name from struct nfb_device --- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 9 +-------- drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c | 6 ++---- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index 99fee39c..570666fd 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -310,15 +310,8 @@ int nfb_pmci_attach(struct nfb_boot *boot) int sn; void *fdt; - int node; - const char *card_name; fdt = nfb_get_fdt(boot->nfb); - node = fdt_path_offset(fdt, "/firmware"); - card_name = fdt_getprop(fdt, node, "card-name", NULL); - if (card_name == NULL) { - return -ENODEV; - } pmci = kzalloc(sizeof(*pmci), GFP_KERNEL); if (!pmci) { @@ -344,7 +337,7 @@ int nfb_pmci_attach(struct nfb_boot *boot) mutex_init(&pmci->flash_ops.mux_lock); pmci->m10bmc.dev = &pmci->pd->dev; - pmci->m10bmc.type = !strcmp(card_name, "FB2CDG1") ? M10_FB2CDG1 : M10_N6000; + pmci->m10bmc.type = !strcmp(boot->nfb->card_name, "FB2CDG1") ? M10_FB2CDG1 : M10_N6000; pmci->m10bmc.flash_ops = &pmci->flash_ops; pmci->m10bmc.regmap = nfb_devm_regmap_init_indirect_register(&pmci->pd->dev, diff --git a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c index 5a38dd29..648dde96 100644 --- a/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c +++ b/drivers/kernel/drivers/nfb/hwmon/nfb_hwmon.c @@ -268,15 +268,13 @@ int nfb_hwmon_attach(struct nfb_device *nfb, void **priv) int ret; int i; - fdt = nfb_get_fdt(nfb); - fdt_offset = fdt_path_offset(fdt, "/firmware/"); - prop = fdt_getprop(fdt, fdt_offset, "card-name", &name_len); - if(!strcmp(prop, "N5014")) { + if (!strcmp(nfb->card_name, "N5014")) { dev_info(&nfb->pci->dev, "nfb_hwmon: Generic NFB hwmon skipped for N5014.\n"); *priv = NULL; return 0; } + fdt = nfb_get_fdt(nfb); fdt_offset = fdt_path_offset(fdt, "/board/"); prop = fdt_getprop(fdt, fdt_offset, "board-name", &name_len); From d0b80761a67719f72a359796c5a4008aad067b20 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 12 Nov 2025 14:44:13 +0100 Subject: [PATCH 424/518] bump version to 6.28.6 --- Changelog | 5 +++++ VERSION | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 555f4452..3fe56b93 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +* Wed Nov 12 2025 Martin Spinler - 6.28.6-1 +- [FEATURE] drivers: add support for newer kernels +- [FIX] nfb-boot: add missing --force option +- [FIX] ia-440i: increase PCIe Link up wait time on reload + * Wed Oct 15 2025 Martin Spinler - 6.28.5-1 - [FEATURE]: add support for fb2cdg1 diff --git a/VERSION b/VERSION index db774514..88a1e4ec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.28.5 +6.28.6 From 5a79da69f4a690b428a359407205d94b567358d2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 13 Nov 2025 15:46:34 +0100 Subject: [PATCH 425/518] fix(drivers - reload): use mutex to reload one card at a time Rescanning more PCIe ports simultaneously leads to device lost. --- drivers/kernel/drivers/nfb/boot/boot.c | 13 ++++++++----- drivers/kernel/drivers/nfb/boot/reload.c | 12 ++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index b577cee6..2b6996a1 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -47,6 +47,8 @@ static bool boot_enable = 1; +struct mutex boot_reload_mutex; + extern const struct nfb_pci_dev nfb_device_infos []; /* @@ -520,14 +522,15 @@ void nfb_boot_detach(struct nfb_device* nfb, void *priv) int nfb_boot_init() { + mutex_init(&boot_reload_mutex); #ifdef CONFIG_NFB_ENABLE_PMCI - int ret; + int ret; ret = nfb_pmci_init(); - if (ret) - goto err_pmci; - ret = nfb_spi_init(); + if (ret) + goto err_pmci; + ret = nfb_spi_init(); err_pmci: - return ret; + return ret; #else return 0; #endif diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index 51464ace..5d74e159 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -28,6 +28,7 @@ #include "../pci.h" static bool boot_linkdown_enable = 0; +extern struct mutex boot_reload_mutex; void nfb_boot_mtd_destroy(struct nfb_boot *nfb_boot); @@ -229,6 +230,8 @@ int nfb_boot_reload(void *arg) mbus_dev = &nfb->pci->bus->self->dev; + dev_info(mbus_dev, "acquiring mutex for reload on %s\n", pci_name(nfb->pci)); + mutex_lock(&boot_reload_mutex); dev_info(mbus_dev, "reloading firmware on %s\n", pci_name(nfb->pci)); INIT_LIST_HEAD(&slaves); @@ -264,7 +267,8 @@ int nfb_boot_reload(void *arg) reload_time_ms = 5000; } else if (boot->m10bmc_spi) { boot->m10bmc_spi->image_load[boot->num_image].load_image(boot->m10bmc_spi->sec); - return nfb_boot_n5014_reload_rescan(master); + ret = nfb_boot_n5014_reload_rescan(master); + goto alternative_reload_done; } else if (boot->bw_bmc) { nfb_boot_bw_bmc_reload(boot); } else if (boot->sdm && boot->sdm_boot_en) { @@ -327,12 +331,16 @@ int nfb_boot_reload(void *arg) dev_err(mbus_dev, "unable to find master PCI device after FW reload!\n"); dev_info(mbus_dev, "firmware reload done\n"); - return 0; + ret = 0; +alternative_reload_done: + mutex_unlock(&boot_reload_mutex); + return ret; err_reload_prepare_remove: list_for_each_entry_safe(slave, temp, &slaves, reload_list) { list_del_init(&slave->reload_list); } + mutex_unlock(&boot_reload_mutex); return ret; } From e2f4a4fa373184650070f6cd4bda3d168429583b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 13 Nov 2025 16:23:28 +0100 Subject: [PATCH 426/518] fix(drivers - reload): mask Surprise Down uncorrectable error --- drivers/kernel/drivers/nfb/boot/reload.c | 43 +++++++++++++++--------- drivers/kernel/drivers/nfb/pci.h | 1 + 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index 5d74e159..a95aae6d 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -78,6 +78,7 @@ static void nfb_boot_reload_linkup(struct nfb_pci_device *card) static int nfb_boot_reload_rescan(struct nfb_pci_device *card) { struct pci_dev *bus_dev; + int ext_cap_pos; pci_lock_rescan_remove(); pci_rescan_bus(card->bus->parent); @@ -94,6 +95,11 @@ static int nfb_boot_reload_rescan(struct nfb_pci_device *card) pci_write_config_word(bus_dev, PCI_COMMAND, card->bridge_command); pci_write_config_word(bus_dev, bus_dev->pcie_cap + PCI_EXP_DEVCTL, card->bridge_devctl); + ext_cap_pos = pci_find_ext_capability(bus_dev, PCI_EXT_CAP_ID_ERR); + if (ext_cap_pos) { + pci_write_config_dword(bus_dev, ext_cap_pos + PCI_ERR_UNCOR_MASK, card->bridge_root_aer_mask); + } + pci_dev_put(card->pci); return 0; } @@ -103,7 +109,7 @@ static int nfb_boot_n5014_reload_rescan(struct nfb_pci_device *card) { struct pci_dev *bus_dev; struct pci_bus *b = NULL; int reload_time_ms = 5000; - int ext_cap_pos; + int root_ext_cap_pos; root = pcie_find_root_port(card->pci); if (root == NULL) { @@ -146,11 +152,11 @@ static int nfb_boot_n5014_reload_rescan(struct nfb_pci_device *card) { // Restore errors dev_info(&bus_dev->dev, "nfb: restoring errors on PCI bridge\n"); - ext_cap_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR); + root_ext_cap_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR); pci_write_config_word(bus_dev, PCI_COMMAND, card->bridge_command); pci_write_config_word(bus_dev, bus_dev->pcie_cap + PCI_EXP_DEVCTL, card->bridge_devctl); - if (ext_cap_pos) { - pci_write_config_dword(root, ext_cap_pos + PCI_ERR_ROOT_COMMAND, card->bridge_root_aer_cmd); + if (root_ext_cap_pos) { + pci_write_config_dword(root, root_ext_cap_pos + PCI_ERR_ROOT_COMMAND, card->bridge_root_aer_cmd); } pci_dev_put(card->pci); @@ -167,30 +173,37 @@ static int nfb_pci_errors_disable(struct nfb_pci_device *card, int use_root_port { struct pci_dev *bridge = card->bus->self; struct pci_dev *root = pcie_find_root_port(bridge); + int root_ext_cap_pos = 0; int ext_cap_pos = 0; dev_info(&card->bus->self->dev, "disabling errors on PCI bridge\n"); + if (use_root_port_cmds && root == NULL) { + dev_err(&card->bus->self->dev, "cannot find PCIe root port!\n"); + return -ENODEV; + } /* save state of error registers */ pci_read_config_word(bridge, PCI_COMMAND, &card->bridge_command); pci_read_config_word(bridge, bridge->pcie_cap + PCI_EXP_DEVCTL, &card->bridge_devctl); - if (use_root_port_cmds) { - if (root == NULL) { - dev_err(&card->bus->self->dev, "Cannot find PCIE root port!\n"); - return -ENODEV; - } - ext_cap_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR); - } - if (ext_cap_pos) { - pci_read_config_dword(root, ext_cap_pos + PCI_ERR_ROOT_COMMAND, &card->bridge_root_aer_cmd); - } pci_write_config_word(bridge, PCI_COMMAND, card->bridge_command & ~PCI_COMMAND_SERR); pci_write_config_word(bridge, bridge->pcie_cap + PCI_EXP_DEVCTL, card->bridge_devctl & ~(PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_FERE)); + + ext_cap_pos = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR); if (ext_cap_pos) { - pci_write_config_dword(root, ext_cap_pos + PCI_ERR_ROOT_COMMAND, 0); + pci_read_config_dword(bridge, ext_cap_pos + PCI_ERR_UNCOR_MASK, &card->bridge_root_aer_mask); + pci_write_config_dword(bridge, ext_cap_pos + PCI_ERR_UNCOR_MASK, card->bridge_root_aer_mask | (PCI_ERR_UNC_SURPDN)); } + + if (use_root_port_cmds) { + root_ext_cap_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR); + if (root_ext_cap_pos) { + pci_read_config_dword(root, root_ext_cap_pos + PCI_ERR_ROOT_COMMAND, &card->bridge_root_aer_cmd); + pci_write_config_dword(root, root_ext_cap_pos + PCI_ERR_ROOT_COMMAND, 0); + } + } + return 0; } diff --git a/drivers/kernel/drivers/nfb/pci.h b/drivers/kernel/drivers/nfb/pci.h index 73a06bae..aedfe102 100644 --- a/drivers/kernel/drivers/nfb/pci.h +++ b/drivers/kernel/drivers/nfb/pci.h @@ -81,6 +81,7 @@ struct nfb_pci_device { uint16_t bridge_command; uint16_t bridge_devctl; uint32_t bridge_root_aer_cmd; + uint32_t bridge_root_aer_mask; void * fdt; const char * card_name; }; From 4965315378cd8a4867c6a8bd827894c218338f8b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 13 Nov 2025 17:09:57 +0100 Subject: [PATCH 427/518] fix(drivers - reload): reflect default value of boot_linkdown_enable in description --- drivers/kernel/drivers/nfb/boot/reload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/boot/reload.c b/drivers/kernel/drivers/nfb/boot/reload.c index a95aae6d..18789174 100644 --- a/drivers/kernel/drivers/nfb/boot/reload.c +++ b/drivers/kernel/drivers/nfb/boot/reload.c @@ -359,4 +359,4 @@ int nfb_boot_reload(void *arg) module_param(boot_linkdown_enable, bool, S_IRUGO); -MODULE_PARM_DESC(boot_linkdown_enable, "Shut the PCIe downstream link down during boot [yes]"); +MODULE_PARM_DESC(boot_linkdown_enable, "Shut the PCIe downstream link down during boot [no]"); From 42074bbdc9056e5f7421fae9b16ad37be1f10465 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Wed, 19 Nov 2025 10:28:03 +0100 Subject: [PATCH 428/518] feat(ieee802.3): check PMA/PMD type compatibility when trying to configure it --- tools/eth/ieee802_3.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/eth/ieee802_3.c b/tools/eth/ieee802_3.c index 6b6b770d..5b999f0b 100644 --- a/tools/eth/ieee802_3.c +++ b/tools/eth/ieee802_3.c @@ -297,6 +297,29 @@ const char *ieee802_3_get_pma_pmd_type_string(struct mdio_if_info *if_info) return "Unknown"; } +struct cb_match_pma_pmd_type_priv { + const char *name; + int matched; +}; + +static void match_pma_pmd_type(void *p, const char *str) +{ + struct cb_match_pma_pmd_type_priv *priv = p; + int matched = 0; + matched = !strcmp(str, priv->name); + priv->matched |= matched; +} + +/* Check if requested mode is in list of supported PMA/PMD types */ +int check_supported_pma_pmd_type_string(struct mdio_if_info *if_info, const char *req) +{ + struct cb_match_pma_pmd_type_priv cb_mpptp; + cb_mpptp.name = req; + cb_mpptp.matched = 0; + ieee802_3_get_supported_pma_pmd_types_string(if_info, match_pma_pmd_type, &cb_mpptp); + return cb_mpptp.matched; +} + int ieee802_3_set_pma_pmd_type_string(struct mdio_if_info *if_info, const char *string) { int reg = -1; @@ -309,6 +332,10 @@ int ieee802_3_set_pma_pmd_type_string(struct mdio_if_info *if_info, const char * if (!table) return -1; + if (!check_supported_pma_pmd_type_string(if_info, table->name)) { + return -2; + } + if_info->mdio_write(if_info->dev, if_info->prtad, 1, 7, table->nr); if (table->flags & IEEE802_3_FLAG_FEC_VARIANT) { From 54acca79882c332e5cd4809621dd9b1430f679a7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 19 Nov 2025 11:05:39 +0100 Subject: [PATCH 429/518] fix(libnetcope): check for DMA controller version --- libnfb/include/netcope/dma_ctrl_ndp.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 6a3ac60d..95283d3d 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -290,6 +290,9 @@ static inline int nc_ndp_ctrl_open(struct nfb_device* nfb, int fdt_offset, struc { int ret; unsigned int i; + unsigned version = 0; + const fdt32_t *prop; + int proplen; const char *compatible[] = { COMP_NC_DMA_CTRL_NDP_RX, @@ -311,10 +314,21 @@ static inline int nc_ndp_ctrl_open(struct nfb_device* nfb, int fdt_offset, struc if (ret) return -EINVAL; - if (i < 2) + prop = (const fdt32_t*) fdt_getprop(nfb_get_fdt(nfb), fdt_offset, "version", &proplen); + if (proplen != sizeof(*prop)) + return -EBADF; + + version = fdt32_to_cpu(*prop); + + if (i < 2) { ctrl->type = DMA_TYPE_MEDUSA; - else + if (version >= 0x00030000) + return -ENOSYS; + } else { ctrl->type = DMA_TYPE_CALYPTE; + if (version >= 0x00020000) + return -ENOSYS; + } ctrl->comp = nfb_comp_open(nfb, fdt_offset); if (ctrl->comp == NULL) { From 5a0dd898933b59c0e1933f87fbe86ad978eeb7d4 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 19 Nov 2025 11:11:13 +0100 Subject: [PATCH 430/518] chore(drivers): resolve C90 warning --- drivers/kernel/drivers/nfb/boot/boot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/boot.c b/drivers/kernel/drivers/nfb/boot/boot.c index 2b6996a1..2a4ca03f 100644 --- a/drivers/kernel/drivers/nfb/boot/boot.c +++ b/drivers/kernel/drivers/nfb/boot/boot.c @@ -522,9 +522,9 @@ void nfb_boot_detach(struct nfb_device* nfb, void *priv) int nfb_boot_init() { + int ret = 0; mutex_init(&boot_reload_mutex); #ifdef CONFIG_NFB_ENABLE_PMCI - int ret; ret = nfb_pmci_init(); if (ret) goto err_pmci; @@ -532,7 +532,7 @@ int nfb_boot_init() err_pmci: return ret; #else - return 0; + return ret; #endif } From 0251c64062b9f06b6e59a061a11936d4bb001b58 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Wed, 19 Nov 2025 11:40:37 +0100 Subject: [PATCH 431/518] feat(tool - eth): print user-friendly error messages when setting PMA/PCS features --- tools/eth/ieee802_3.c | 9 +++++---- tools/eth/main.c | 14 ++++++++++++-- tools/eth/pcspma.c | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/eth/ieee802_3.c b/tools/eth/ieee802_3.c index 5b999f0b..b3bbc453 100644 --- a/tools/eth/ieee802_3.c +++ b/tools/eth/ieee802_3.c @@ -10,6 +10,7 @@ #include #include +#include #include @@ -326,14 +327,14 @@ int ieee802_3_set_pma_pmd_type_string(struct mdio_if_info *if_info, const char * const struct pma_pmd_type_t *table = ieee802_3_pma_pmd_type; if (string == NULL) - return -1; + return -EINVAL; table = _find_pma_pmd_type_by_string(table, string); if (!table) - return -1; + return -EINVAL; if (!check_supported_pma_pmd_type_string(if_info, table->name)) { - return -2; + return -ENOTSUP; } if_info->mdio_write(if_info->dev, if_info->prtad, 1, 7, table->nr); @@ -489,6 +490,6 @@ int ieee802_3_get_fec_lines(const char *string) { const struct pma_pmd_type_t *t = _find_pma_pmd_type_by_string(ieee802_3_pma_pmd_type, string); if (!t) - return -1; + return -EINVAL; return t->flags & IEEE802_3_FLAG_LINES_MASK; } diff --git a/tools/eth/main.c b/tools/eth/main.c index d5e73672..6362f896 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -491,6 +492,7 @@ int main(int argc, char *argv[]) struct nfb_device *dev; const char *query = NULL; char *queries_index = NULL; + const char *errmsg = ""; int size = 0; const void *fdt; @@ -774,8 +776,16 @@ int main(int argc, char *argv[]) } else if (use & PCSPMA) { used++; ret = pcspma_execute_operation(ctx, dev, node, &p); - if (ret) - warnx("PCS/PMA command failed"); + if (ret == -ENOTSUP) { + errmsg = "mode not supported by the current PCS/PMA"; + } else if (ret == -EINVAL) { + errmsg = "unknown feature or PMA mode"; + } else { + errmsg = strerror(-ret); + } + if (ret) { + warnx("PCS/PMA command failed: %s", errmsg); + } } } ni_endsection(ctx, NI_SEC_ETH); diff --git a/tools/eth/pcspma.c b/tools/eth/pcspma.c index a6dcd177..038212cc 100644 --- a/tools/eth/pcspma.c +++ b/tools/eth/pcspma.c @@ -110,7 +110,7 @@ int pcspma_set_feature(struct nc_mdio *mdio, int portaddr, struct eth_params *p) pcs_item++; } - return -1; + return -EINVAL; } static inline uint32_t nc_mdio_read_dword(struct nc_mdio *mdio, int prtad, int devad, uint16_t addr) From 874a09e93fc5964082d2aecc716d4f2adae125c7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 19 Nov 2025 11:58:37 +0100 Subject: [PATCH 432/518] chore(nfb-eth): describe more "Command not implemented" warning message --- tools/eth/rxmac.c | 2 +- tools/eth/txmac.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/eth/rxmac.c b/tools/eth/rxmac.c index 726367ba..48b56789 100644 --- a/tools/eth/rxmac.c +++ b/tools/eth/rxmac.c @@ -264,7 +264,7 @@ int rxmac_execute_operation(struct ni_context *ctx, struct nc_rxmac *rxmac, stru nc_rxmac_mac_filter_enable(rxmac, p->param); break; default: - warnx("RXMAC: Command not implemented"); + warnx("RXMAC %d: Command not implemented; try to specify target unit, for example just TXMAC: -t", p->index); break; } return ret; diff --git a/tools/eth/txmac.c b/tools/eth/txmac.c index 41f7ab21..cd43c3c0 100644 --- a/tools/eth/txmac.c +++ b/tools/eth/txmac.c @@ -68,7 +68,7 @@ int txmac_execute_operation(struct ni_context *ctx, struct nc_txmac *txmac, stru nc_txmac_disable(txmac); break; default: - warnx("TXMAC: Command not implemented"); + warnx("TXMAC %d: Command not implemented; try to specify target unit, for example just RXMAC: -r", p->index); break; } return 0; From ab3a64880a9277258701f48a0cdb6e0c8915cae2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 19 Nov 2025 12:29:59 +0100 Subject: [PATCH 433/518] bump version to 6.28.7 --- Changelog | 5 +++++ VERSION | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 3fe56b93..11d5de02 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +* Wed Nov 19 2025 Martin Spinler - 6.28.7-1 +- [FIX] boot: disable reloading more cards at same time +- [FIX] libnfb/NDP: check version of DMA controllers +- [FIX] nfb-eth: check PMA/PMD type compatibility + * Wed Nov 12 2025 Martin Spinler - 6.28.6-1 - [FEATURE] drivers: add support for newer kernels - [FIX] nfb-boot: add missing --force option diff --git a/VERSION b/VERSION index 88a1e4ec..a546a04d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.28.6 +6.28.7 From 8999c3763f6c922804269a60f813b2855dfbb79b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 19 Nov 2025 17:18:06 +0100 Subject: [PATCH 434/518] fix(bittware I2C): reset buffer position on write command --- libnfb/include/netcope/bittware_bmc_spi.h | 5 +++++ libnfb/include/netcope/i2c_bw_bmc.h | 1 + 2 files changed, 6 insertions(+) diff --git a/libnfb/include/netcope/bittware_bmc_spi.h b/libnfb/include/netcope/bittware_bmc_spi.h index 0ff1eea1..350a0761 100644 --- a/libnfb/include/netcope/bittware_bmc_spi.h +++ b/libnfb/include/netcope/bittware_bmc_spi.h @@ -329,6 +329,11 @@ static inline int nc_bw_bmc_receive_i2c(struct nc_bw_bmc *spi, unsigned char* da return 0; } +static inline void nc_bw_bmc_buffer_init(struct nc_bw_bmc *spi) +{ + spi->pos = 0; +} + static inline int nc_bw_bmc_mctp_header_default(struct nc_bw_bmc *spi) { int i = 0; diff --git a/libnfb/include/netcope/i2c_bw_bmc.h b/libnfb/include/netcope/i2c_bw_bmc.h index 8326a44f..c801e8cd 100644 --- a/libnfb/include/netcope/i2c_bw_bmc.h +++ b/libnfb/include/netcope/i2c_bw_bmc.h @@ -109,6 +109,7 @@ static inline int nc_i2c_bw_bmc_write_reg(void *p, uint8_t reg, const uint8_t *d if (!nc_bw_bmc_lock(ctrl->bmc)) return -EAGAIN; + nc_bw_bmc_buffer_init(ctrl->bmc); nc_bw_bmc_push_uint8(ctrl->bmc, ctrl->addr / 2); nc_bw_bmc_push_uint8(ctrl->bmc, 0); nc_bw_bmc_push_uint8(ctrl->bmc, reg); From 10a1e80becfbcff7cd0a5e6f94e0be7837d65bc5 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 20 Nov 2025 08:15:40 +0100 Subject: [PATCH 435/518] bump version to 6.28.8 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 11d5de02..6d8f73d6 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Thu Nov 20 2025 Martin Spinler - 6.28.8-1 +- [FIX] BittWare BMC (ia-440i): initialize buffer for I2C write + * Wed Nov 19 2025 Martin Spinler - 6.28.7-1 - [FIX] boot: disable reloading more cards at same time - [FIX] libnfb/NDP: check version of DMA controllers diff --git a/VERSION b/VERSION index a546a04d..d2811ed0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.28.7 +6.28.8 From c2689fd23932a84109d331804b2f877a209b61de Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Wed, 1 Oct 2025 20:48:07 +0200 Subject: [PATCH 436/518] refactor(ndp_rx): remove unused macro branch --- libnfb/include/netcope/ndp_rx.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index 3631f889..9049746c 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -236,10 +236,6 @@ static inline void _ndp_queue_rx_sync_v3_us(struct nc_ndp_queue *q) struct ndp_v3_packethdr *hdr_base; if (q->sync.swptr != q->u.v3.uspace_shp) { -#if 0 - q->u.v3.uspace_shp = q->sync.swptr & q->u.v3.hdr_ptr_mask; - nfb_comp_write64(q->u.v3.comp, NDP_CTRL_REG_SDP, q->u.v3.sdp | (((uint64_t) q->u.v3.uspace_shp) << 32)); -#else unsigned i; unsigned count_blks = 0; unsigned count = (q->sync.swptr - q->u.v3.uspace_shp) & q->u.v3.uspace_mhp; @@ -260,7 +256,6 @@ static inline void _ndp_queue_rx_sync_v3_us(struct nc_ndp_queue *q) ////nc_ndp_ctrl_sp_flush(q->u.v3.comp); nfb_comp_write64(q->u.v3.comp, NDP_CTRL_REG_SDP, q->u.v3.uspace_sdp | (((uint64_t) q->u.v3.uspace_shp) << 32)); } -#endif } do { From 84ab0298bbfbcea666e56d612c6cd5792e8f670f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 27 Nov 2025 08:30:50 +0100 Subject: [PATCH 437/518] feat(libnfb info): add rx_stream to nc_ifc_eth_map_info --- libnfb/include/netcope/info.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libnfb/include/netcope/info.h b/libnfb/include/netcope/info.h index 43ed7914..e582a52f 100644 --- a/libnfb/include/netcope/info.h +++ b/libnfb/include/netcope/info.h @@ -177,6 +177,7 @@ struct nc_ifc_eth_map_info { int node_rxmac; /* FDT node of RxMAC */ int node_txmac; /* FDT node of TxMAC */ + int rx_stream; /* Stream ID in NDK application core */ int port; /* Port ID/index on card, -1 for virtual ifcs */ int channel; /* Channel ID/index within port (first channel when Eth channel uses multiple lanes) */ int lane; /* Channel ID/index within card (first lane when Eth channel uses multiple lanes) */ @@ -202,6 +203,8 @@ static inline int nc_ifc_map_info_create_ordinary(struct nfb_device *nfb, struct int i, q; int ret; const void *fdt; + const fdt32_t *prop32; + int proplen; int node; int ifc = 0; @@ -286,6 +289,13 @@ static inline int nc_ifc_map_info_create_ordinary(struct nfb_device *nfb, struct } } } + + /* Fallback for not tagged firmware */ + eth_info->rx_stream = eth_info->port; + + prop32 = (const fdt32_t*) fdt_getprop(fdt, node, "rx_stream", &proplen); + if (proplen == sizeof(*prop32)) + eth_info->rx_stream = fdt32_to_cpu(*prop32); } if (ifc == 0) { From 89c60c03b989947bc658ccc2a6bfadd3e76bf018 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Thu, 20 Nov 2025 11:17:46 +0100 Subject: [PATCH 438/518] feat(ndp-calypte)!: update supported version --- libnfb/include/netcope/dma_ctrl_ndp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 95283d3d..19222eae 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -326,7 +326,7 @@ static inline int nc_ndp_ctrl_open(struct nfb_device* nfb, int fdt_offset, struc return -ENOSYS; } else { ctrl->type = DMA_TYPE_CALYPTE; - if (version >= 0x00020000) + if (version < 0x00020000 || version >= 0x00030000) return -ENOSYS; } From cee323147b42c1c803975dd9a7bc104fdb798af9 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 13 Oct 2025 16:05:18 +0200 Subject: [PATCH 439/518] feat(ndp-calypte)!: add flipping of valid flag The Valid Flag present in the DMA header within DMA Calypte module was previously set to 1 every time a new packet has arrived which required the clearing of the flags of packets that were already read. This change introduces flag flipping which considers both 0 and 1 to be valid values based of which run through a buffer is considered. Upon starting of a channel, the valid value is 1 whereas upon header pointer rollover, this value flips to 0 which is then considered as a valid value for a second run through the buffer. Upon next pointer rollover, the valid value flips back to 1 and so on. Because of that, the header buffer is mapped as READ_ONLY since hardware performs flag flip on its own. --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 12 ++++++++--- libnfb/include/netcope/ndp.h | 4 +++- libnfb/include/netcope/ndp_priv.h | 1 + libnfb/include/netcope/ndp_rx.h | 25 ++++++++++++++++++----- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index bbd7b542..0a20af63 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -91,6 +91,7 @@ struct ndp_ctrl { struct { struct nc_calypte_hdr *hdr_buffer; uint64_t free_bytes; + uint8_t valid_flag; } calypte; } ts; @@ -509,7 +510,6 @@ static void ndp_ctrl_calypte_rx_set_swptr(struct ndp_channel *channel, uint64_t unsigned i; for (i = 0; i < count; i++) { - hdr[i].valid = 0; new_sdp += (hdr[i].frame_len + NDP_RX_CALYPTE_BLOCK_SIZE - 1) / NDP_RX_CALYPTE_BLOCK_SIZE; } @@ -535,9 +535,14 @@ static uint64_t ndp_ctrl_rx_get_hwptr(struct ndp_channel *channel) uint32_t hwptr = ctrl->c.hhp; do { hdr_base = ctrl->ts.calypte.hdr_buffer + hwptr; - if (hdr_base->valid == 0) + if ((hdr_base->valid & 0x01) == (ctrl->ts.calypte.valid_flag ^ 1)) break; - hwptr++; + hwptr += 1; + + if ((hwptr & channel->ptrmask) == 0) { + ctrl->ts.calypte.valid_flag ^= 1; + } + } while (hwptr < ctrl->hdr_buffer_size * 2); ctrl->c.hhp = hwptr & channel->ptrmask; return ctrl->c.hhp; @@ -850,6 +855,7 @@ static int ndp_ctrl_calypte_start(struct ndp_channel *channel, uint64_t *hwptr) return ret; ctrl->ts.calypte.free_bytes = ctrl->c.mdp; + ctrl->ts.calypte.valid_flag = 1; *hwptr = 0; return 0; diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index c6bdf0a1..9d063a8b 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -184,7 +184,8 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, if (ret) return -EBADFD; - prot = PROT_READ | PROT_WRITE; + prot = PROT_READ; + prot |= q->channel.type == NDP_CHANNEL_TYPE_TX ? PROT_WRITE : 0; q->u.v3.hdrs = mmap(NULL, hdr_mmap_size, prot, MAP_FILE | MAP_SHARED, q->fd, hdr_mmap_offset); if (q->u.v3.hdrs == MAP_FAILED) { @@ -201,6 +202,7 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, #endif if (q->channel.type == NDP_CHANNEL_TYPE_RX) { + q->u.v3.valid_flag = 1; q->u.v3.hdr_ptr_mask = ((hdr_mmap_size / 2) / sizeof(struct ndp_v3_packethdr)) - 1; // "- 1" to create a mask for AND operations } else { q->u.v3.hdr_ptr_mask = hdr_buff_size / (2 * sizeof(struct ndp_v3_packethdr)) - 1; diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index 13c3b609..eae8978a 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -85,6 +85,7 @@ struct nc_ndp_queue { /* Store metadata for use in tx_burst_put */ void ** tx_pkts; uint64_t tx_pkts_cnt; /* Number of tx_pkts items */ + uint8_t valid_flag; #ifndef __KERNEL__ struct ndp_v3_packethdr *uspace_hdrs; struct nfb_comp *comp; diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index 9049746c..537dd2b9 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -234,6 +234,7 @@ static inline void _ndp_queue_rx_sync_v3_us(struct nc_ndp_queue *q) { #ifndef __KERNEL__ struct ndp_v3_packethdr *hdr_base; + uint8_t vld_flag = q->u.v3.valid_flag; if (q->sync.swptr != q->u.v3.uspace_shp) { unsigned i; @@ -242,7 +243,6 @@ static inline void _ndp_queue_rx_sync_v3_us(struct nc_ndp_queue *q) hdr_base = q->u.v3.hdrs + q->u.v3.uspace_shp; for (i = 0; i < count; i++) { - hdr_base[i].valid = 0; count_blks += (hdr_base[i].frame_len + NDP_RX_CALYPTE_BLOCK_SIZE - 1) / NDP_RX_CALYPTE_BLOCK_SIZE; } @@ -253,17 +253,21 @@ static inline void _ndp_queue_rx_sync_v3_us(struct nc_ndp_queue *q) /* TODO: magic number */ if (q->u.v3.uspace_acc >= 32) { q->u.v3.uspace_acc = 0; - ////nc_ndp_ctrl_sp_flush(q->u.v3.comp); nfb_comp_write64(q->u.v3.comp, NDP_CTRL_REG_SDP, q->u.v3.uspace_sdp | (((uint64_t) q->u.v3.uspace_shp) << 32)); } } do { hdr_base = q->u.v3.hdrs + q->u.v3.uspace_hhp; - if (hdr_base->valid == 0) + if ((hdr_base->valid & 0x01) == (vld_flag ^ 1)) break; q->u.v3.uspace_hhp = (q->u.v3.uspace_hhp + 1) & q->u.v3.uspace_mhp; + + if (q->u.v3.uspace_hhp == 0) { + vld_flag ^= 1; + } } while (1); + q->sync.hwptr = q->u.v3.uspace_hhp; #endif } @@ -291,12 +295,19 @@ static inline int nc_ndp_v3_rx_unlock(void *priv) int ret = 0; struct nc_ndp_queue *q = (struct nc_ndp_queue*) priv; + uint64_t old_swptr = q->sync.swptr; + q->sync.swptr = q->u.v3.shp & (q->u.v3.hdr_ptr_mask); if (q->flags & NDP_CHANNEL_FLAG_USERSPACE) { _ndp_queue_rx_sync_v3_us(q); } else { ret = _ndp_queue_sync(q, &q->sync); } + + // When pointer wraps around, flip the valid flag. + if (q->sync.swptr < old_swptr) { + q->u.v3.valid_flag ^= 1; + } return ret; } @@ -307,6 +318,7 @@ static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *pac struct ndp_v3_packethdr *hdr_base; unsigned char *data_base; + uint8_t vld_flag = q->u.v3.valid_flag; if (unlikely(q->u.v3.pkts_available < count)) { nc_ndp_v3_rx_lock(q); @@ -328,10 +340,13 @@ static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *pac hdr = hdr_base + i; - if (!hdr->valid) { - break; + if ((q->u.v3.shp + i) > q->u.v3.hdr_ptr_mask) { + vld_flag ^= 1; } + if ((hdr->valid & 0x01) == (vld_flag ^ 1)) + break; + header_size = le16_to_cpu(hdr->header_size) & NDP_CALYPTE_METADATA_HDR_SIZE_MASK; packet_size = le16_to_cpu(hdr->frame_len) - header_size; From e15c24f23235a92a4f4e3de762634d9cd909a08a Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Tue, 14 Oct 2025 15:51:21 +0200 Subject: [PATCH 440/518] feat(ndp-calypte)!: add support for Medusa-style update buffer The Update buffer plays the same role as in the Medusa DMA architecture. It is a reserved space where hardware sends its values of HHP and HDP which are then read by the software. This removes the necessity of reading these values from the hardware using expensive MMIO accesses. --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 71 ++++++++++++++++++++++- libnfb/include/netcope/dma_ctrl_ndp.h | 69 +++++++++------------- libnfb/include/netcope/ndp.h | 27 ++++++++- libnfb/include/netcope/ndp_priv.h | 1 + libnfb/include/netcope/ndp_tx.h | 7 +-- libnfb/include/netcope/rxqueue.h | 4 +- libnfb/include/netcope/txqueue.h | 2 + tools/dma/dma.c | 14 ++--- 8 files changed, 136 insertions(+), 59 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 0a20af63..36afa5cb 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -122,9 +122,11 @@ struct ndp_ctrl { unsigned long off_buffer_size; unsigned long hdr_buffer_size; unsigned long data_buffer_size; + unsigned long update_buffer_size; size_t hdr_mmap_offset; size_t off_mmap_offset; + size_t upd_mmap_offset; }; struct ndp_packet { @@ -840,6 +842,8 @@ static int ndp_ctrl_calypte_start(struct ndp_channel *channel, uint64_t *hwptr) // Only one block is used, therefore the physical address of the first one in "blocks" // list is used. + sp.update_buffer_virt = ctrl->update_buffer; + sp.update_buffer = ctrl->update_buffer_phys; sp.data_buffer = channel->ring.blocks->phys; sp.hdr_buffer = ctrl->hdr_buffer_phys; sp.nb_data = ctrl->hdr_count; @@ -867,7 +871,8 @@ static int ndp_ctrl_stop(struct ndp_channel *channel, int force) int cnt = 0; struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); - if (ctrl->c.type == DMA_TYPE_CALYPTE && ctrl->c.dir != 0 && ctrl->flags & NDP_CHANNEL_FLAG_USERSPACE) { + // For a TX Calypte channel that is in userspace (NOTE: suspiciously simple change) + if (ctrl->c.type == DMA_TYPE_CALYPTE) { nc_ndp_ctrl_hp_update(&ctrl->c); ctrl->c.sdp = ctrl->c.hdp; ctrl->c.shp = ctrl->c.hhp; @@ -947,6 +952,24 @@ static int ndp_ctrl_off_mmap(struct vm_area_struct *vma, unsigned long offset, u return ret; } +static int ndp_ctrl_upd_mmap(struct vm_area_struct *vma, unsigned long offset, unsigned long size, void *priv) +{ + int ret = -1; + struct ndp_ctrl *ctrl = (struct ndp_ctrl*) priv; + + //Check permissions: read-only for RX + if ((vma->vm_flags & (VM_WRITE | VM_READ)) != VM_READ) + return -EINVAL; + + /* Allow mmap only for exact offset & size match */ + if (offset != ctrl->upd_mmap_offset || size != ctrl->update_buffer_size) { + return -EINVAL; + } + + ret = remap_pfn_range(vma, vma->vm_start, virt_to_phys_shift(ctrl->update_buffer), size, vma->vm_page_prot); + return ret; +} + static void *ndp_ctrl_vmap_shadow(int size, void *virt) { int i; @@ -1120,12 +1143,19 @@ static int ndp_ctrl_rx_calypte_attach_ring(struct ndp_channel *channel) channel->ptrmask = ctrl->hdr_count - 1; + ctrl->update_buffer_size = ALIGN(NDP_CTRL_UPDATE_SIZE, PAGE_SIZE); + ctrl->update_buffer = dma_alloc_coherent(dev, ctrl->update_buffer_size, + &ctrl->update_buffer_phys, GFP_KERNEL); + if (ctrl->update_buffer == NULL) { + return -EINVAL; + } + /* allocate header area */ ctrl->hdr_buffer_size = ALIGN(ctrl->hdr_count * NDP_CTRL_RX_CALYPTE_HDR_SIZE, PAGE_SIZE); ctrl->hdr_buffer = dma_alloc_coherent(dev, ctrl->hdr_buffer_size, &ctrl->hdr_buffer_phys, GFP_KERNEL); if (ctrl->hdr_buffer == NULL) { - return -EINVAL; + goto err_hdr_buff_map; } ctrl->ts.common.hdr_buffer_v = ndp_ctrl_vmap_shadow(ctrl->hdr_buffer_size, ctrl->hdr_buffer); @@ -1154,6 +1184,12 @@ static int ndp_ctrl_rx_calypte_attach_ring(struct ndp_channel *channel) dma_free_coherent(dev, ctrl->hdr_buffer_size, ctrl->hdr_buffer, ctrl->hdr_buffer_phys); ctrl->hdr_buffer = NULL; + +err_hdr_buff_map: + dma_free_coherent(dev, ALIGN(NDP_CTRL_UPDATE_SIZE, PAGE_SIZE), + ctrl->update_buffer, ctrl->update_buffer_phys); + ctrl->update_buffer = NULL; + return ret; } @@ -1198,9 +1234,22 @@ static int ndp_ctrl_tx_calypte_attach_ring(struct ndp_channel *channel) if (prop == NULL) return -EBADFD; - ctrl->hdr_buffer_size = fdt32_to_cpu(prop[1]); + ctrl->update_buffer_size = ALIGN(NDP_CTRL_UPDATE_SIZE, PAGE_SIZE); + ctrl->update_buffer = dma_alloc_coherent(dev, ctrl->update_buffer_size, + &ctrl->update_buffer_phys, GFP_KERNEL); + if (ctrl->update_buffer == NULL) { + return -EINVAL; + } + + ret = nfb_char_register_mmap(channel->ndp->nfb, ctrl->update_buffer_size, + &ctrl->upd_mmap_offset, ndp_ctrl_upd_mmap, ctrl); + if (ret) { + goto err_register_mmap_upd; + } + /* Allocate header area */ + ctrl->hdr_buffer_size = fdt32_to_cpu(prop[1]); ctrl->hdr_buffer = dma_alloc_coherent(dev, ctrl->hdr_buffer_size, &ctrl->hdr_buffer_phys, GFP_KERNEL); if (ctrl->hdr_buffer == NULL) { goto err_alloc_hdr; @@ -1228,8 +1277,13 @@ static int ndp_ctrl_tx_calypte_attach_ring(struct ndp_channel *channel) fdt_setprop_u64(fdt, node_offset, "hdr_mmap_base", ctrl->hdr_mmap_offset); fdt_setprop_u64(fdt, node_offset, "hdr_mmap_size", ctrl->hdr_buffer_size * 2); + fdt_setprop_u64(fdt, node_offset, "upd_mmap_base", ctrl->upd_mmap_offset); + fdt_setprop_u64(fdt, node_offset, "upd_mmap_size", ctrl->update_buffer_size); + return 0; +err_register_mmap_upd: + nfb_char_unregister_mmap(channel->ndp->nfb, ctrl->hdr_mmap_offset); err_register_mmap_hdr: vunmap(ctrl->ts.common.hdr_buffer_v); @@ -1239,6 +1293,10 @@ static int ndp_ctrl_tx_calypte_attach_ring(struct ndp_channel *channel) ctrl->hdr_buffer = NULL; err_alloc_hdr: + dma_free_coherent(dev, ctrl->update_buffer_size, + ctrl->update_buffer, ctrl->update_buffer_phys); + ctrl->update_buffer = NULL; + return ret; } @@ -1284,6 +1342,13 @@ static void ndp_ctrl_calypte_detach_ring(struct ndp_channel *channel) dma_free_coherent(dev, ctrl->hdr_buffer_size, ctrl->hdr_buffer, ctrl->hdr_buffer_phys); ctrl->hdr_buffer = NULL; } + + if (ctrl->update_buffer) { + nfb_char_unregister_mmap(channel->ndp->nfb, ctrl->upd_mmap_offset); + dma_free_coherent(dev, ctrl->update_buffer_size, + ctrl->update_buffer, ctrl->update_buffer_phys); + ctrl->update_buffer = NULL; + } } static void ndp_ctrl_destroy(struct device *dev) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 19222eae..fb2699aa 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -32,14 +32,13 @@ #define NDP_CTRL_REG_SHP 0x14 #define NDP_CTRL_REG_HDP 0x18 #define NDP_CTRL_REG_HHP 0x1C +#define NDP_CTRL_REG_TIMEOUT 0x20 #define NDP_CTRL_REG_DESC_BASE 0x40 #define NDP_CTRL_REG_HDR_BASE 0x48 #define NDP_CTRL_REG_UPDATE_BASE 0x50 #define NDP_CTRL_REG_MDP 0x58 #define NDP_CTRL_REG_MHP 0x5C -// --------------- NDP specific registers -------------- -#define NDP_CTRL_REG_TIMEOUT 0x20 // -------------- NDP/Calypte Counters ----------------- // Processed packets on TX @@ -201,45 +200,42 @@ static inline struct nc_ndp_desc nc_ndp_tx_desc2(uint64_t phys, uint16_t len, ui static inline void nc_ndp_ctrl_hdp_update(struct nc_ndp_ctrl *ctrl) { - if (ctrl->type == DMA_TYPE_MEDUSA) { #ifdef __KERNEL__ - rmb(); + rmb(); #else #ifdef _RTE_CONFIG_H_ - rte_rmb(); - rte_wmb(); + rte_rmb(); + rte_wmb(); #endif #endif - ctrl->hdp = ((uint32_t*) ctrl->update_buffer)[0]; - } else if (ctrl->type == DMA_TYPE_CALYPTE) { - ctrl->hdp = (nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_HDP)) & ctrl->mdp; - } + ctrl->hdp = ((uint32_t*) ctrl->update_buffer)[0]; } static inline void nc_ndp_ctrl_hhp_update(struct nc_ndp_ctrl *ctrl) { - if (ctrl->type == DMA_TYPE_MEDUSA) { #ifdef __KERNEL__ - rmb(); + rmb(); #else #ifdef _RTE_CONFIG_H_ - rte_rmb(); - rte_wmb(); + rte_rmb(); + rte_wmb(); #endif #endif - ctrl->hhp = ((uint32_t*) ctrl->update_buffer)[1]; - } else if (ctrl->type == DMA_TYPE_CALYPTE) { - ctrl->hhp = nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_HHP); - } + ctrl->hhp = ((uint32_t*) ctrl->update_buffer)[1]; } static inline void nc_ndp_ctrl_hp_update(struct nc_ndp_ctrl *ctrl) { - uint64_t hwpointers; - - hwpointers = nfb_comp_read64(ctrl->comp, NDP_CTRL_REG_HDP); - ctrl->hdp = ((uint32_t)hwpointers) & ctrl->mdp; - ctrl->hhp = ((uint32_t)(hwpointers >> 32)) & ctrl->mhp; +#ifdef __KERNEL__ + rmb(); +#else +#ifdef _RTE_CONFIG_H_ + rte_rmb(); + rte_wmb(); +#endif +#endif + ctrl->hdp = ((uint32_t*) ctrl->update_buffer)[0]; + ctrl->hhp = ((uint32_t*) ctrl->update_buffer)[1]; } static inline void nc_ndp_ctrl_sp_flush(struct nc_ndp_ctrl *ctrl) @@ -373,8 +369,7 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl goto err_comp_lock; } - if (ctrl->type == DMA_TYPE_MEDUSA) - ctrl->update_buffer = sp->update_buffer_virt; + ctrl->update_buffer = sp->update_buffer_virt; if (!(ctrl->type == DMA_TYPE_CALYPTE && ctrl->dir == 1)) { ctrl->mdp = nb_d - 1; @@ -391,11 +386,9 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl ctrl->shp = 0; ctrl->hhp = 0; - if (ctrl->type == DMA_TYPE_MEDUSA) { - ctrl->update_buffer[0] = 0; - if (ctrl->dir == 0) - ctrl->update_buffer[1] = 0; - } + ctrl->update_buffer[0] = 0; + if (ctrl->dir == 0 || ctrl->type == DMA_TYPE_CALYPTE) + ctrl->update_buffer[1] = 0; /* INFO: driver must ensure first descriptor type is desc0 */ ctrl->last_upper_addr = 0xFFFFFFFFFFFFFFFFull; @@ -412,8 +405,7 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_DESC_BASE, d_buffer); /* Set address of RAM hwptr address */ - if (ctrl->type == DMA_TYPE_MEDUSA) - nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_UPDATE_BASE, sp->update_buffer); + nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_UPDATE_BASE, sp->update_buffer); if (ctrl->dir == 0) nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_HDR_BASE, sp->hdr_buffer); @@ -434,8 +426,7 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl /* Timeout */ /* TODO: let user to configure tihs value */ - if (ctrl->type == DMA_TYPE_MEDUSA) - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, 0x4000); + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, 0x4000); /* Start controller */ nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, NDP_CTRL_REG_CONTROL_START); @@ -460,6 +451,8 @@ static inline int _nc_ndp_ctrl_stop(struct nc_ndp_ctrl *ctrl, int force) uint32_t status; uint32_t hdp_new; + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, NDP_CTRL_REG_CONTROL_STOP); + if (ctrl->dir != 0) { hdp_new = ctrl->hdp; nc_ndp_ctrl_hdp_update(ctrl); @@ -472,15 +465,11 @@ static inline int _nc_ndp_ctrl_stop(struct nc_ndp_ctrl *ctrl, int force) } } - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, NDP_CTRL_REG_CONTROL_STOP); - // Purpose: The RX DMA can pass some packets during the stop process. So HW pointers will surpass // the SW pointers even when software is no longer accepting data. if (ctrl->type == DMA_TYPE_CALYPTE && ctrl->dir == 0) { - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_SDP, - nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_HDP)); - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_SHP, - nfb_comp_read32(ctrl->comp, NDP_CTRL_REG_HHP)); + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_SDP, ctrl->hdp); + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_SHP, ctrl->hhp); } if (ret == 0) diff --git a/libnfb/include/netcope/ndp.h b/libnfb/include/netcope/ndp.h index 9d063a8b..93f0e91b 100644 --- a/libnfb/include/netcope/ndp.h +++ b/libnfb/include/netcope/ndp.h @@ -150,6 +150,8 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, #ifndef __KERNEL__ off_t hdr_mmap_offset = 0; + off_t upd_mmap_offset = 0; + size_t upd_mmap_size = 0; int prot; int ret; #endif @@ -180,6 +182,8 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, if (q->channel.type == NDP_CHANNEL_TYPE_TX) { ret |= fdt_getprop32(fdt, fdt_offset, "data_buff_size", &data_buff_size); ret |= fdt_getprop32(fdt, fdt_offset, "hdr_buff_size", &hdr_buff_size); + ret |= fdt_getprop64(fdt, fdt_offset, "upd_mmap_size", &upd_mmap_size); + ret |= fdt_getprop64(fdt, fdt_offset, "upd_mmap_base", &upd_mmap_offset); } if (ret) return -EBADFD; @@ -192,12 +196,22 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, return -EBADFD; } + if (q->channel.type == NDP_CHANNEL_TYPE_TX) { + q->u.v3.update_buff = mmap(NULL, upd_mmap_size, PROT_READ, MAP_SHARED, q->fd, upd_mmap_offset); + if (q->u.v3.update_buff == MAP_FAILED) { + ret = -EBADFD; + goto err_mmap_upd; + } + } + if (q->flags & NDP_CHANNEL_FLAG_EXCLUSIVE) { q->u.v3.uspace_hdrs = q->u.v3.hdrs; q->u.v3.comp = nfb_comp_open(q->dev, ctrl_offset); - if (q->u.v3.comp == NULL) - return -ENODEV; + if (q->u.v3.comp == NULL) { + ret = -ENODEV; + goto err_comp_open; + } } #endif @@ -219,6 +233,15 @@ static inline int nc_ndp_v3_open_queue(struct nc_ndp_queue *q, const void *fdt, } return 0; + +#ifndef __KERNEL__ +err_comp_open: + if (q->channel.type == NDP_CHANNEL_TYPE_TX) + munmap(q->u.v3.update_buff, upd_mmap_size); +err_mmap_upd: + munmap(q->u.v3.hdrs, hdr_mmap_size); + return ret; +#endif } static inline int nc_ndp_v3_close_queue(struct nc_ndp_queue *q) diff --git a/libnfb/include/netcope/ndp_priv.h b/libnfb/include/netcope/ndp_priv.h index eae8978a..ec9e8d8b 100644 --- a/libnfb/include/netcope/ndp_priv.h +++ b/libnfb/include/netcope/ndp_priv.h @@ -89,6 +89,7 @@ struct nc_ndp_queue { #ifndef __KERNEL__ struct ndp_v3_packethdr *uspace_hdrs; struct nfb_comp *comp; + uint32_t *update_buff; uint32_t uspace_shp; uint32_t uspace_hhp; uint32_t uspace_sdp; diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index 51b6805f..54b2e1c8 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -285,7 +285,6 @@ static inline int nc_ndp_v2_tx_burst_flush(void *priv) static inline void _ndp_queue_tx_sync_v3_us(struct nc_ndp_queue *q) { #ifndef __KERNEL__ - uint64_t hwpointers; uint32_t hdp; uint32_t hhp; @@ -327,9 +326,9 @@ static inline void _ndp_queue_tx_sync_v3_us(struct nc_ndp_queue *q) uint32_t chlen = (q->u.v3.uspace_hhp - q->u.v3.uspace_shp - 1) & q->u.v3.uspace_mhp; /* TODO: magic number */ if (chlen < 512 || q->u.v3.uspace_free <= 4096) { - hwpointers = nfb_comp_read64(q->u.v3.comp, NDP_CTRL_REG_HDP); - hdp = ((uint32_t)hwpointers); - hhp = ((uint32_t)(hwpointers >> 32)); + __builtin_prefetch(q->u.v3.update_buff); + hdp = ((uint32_t*) q->u.v3.update_buff)[0]; + hhp = ((uint32_t*) q->u.v3.update_buff)[1]; count = (hdp - hdp_prev) & q->u.v3.uspace_mdp; q->u.v3.uspace_hdp = hdp; diff --git a/libnfb/include/netcope/rxqueue.h b/libnfb/include/netcope/rxqueue.h index 5334adcf..6afdbc9e 100644 --- a/libnfb/include/netcope/rxqueue.h +++ b/libnfb/include/netcope/rxqueue.h @@ -202,11 +202,11 @@ static inline void nc_rxqueue_read_status(struct nc_rxqueue *rxqueue, struct nc_ s->sd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SDP); s->hd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HDP); s->desc_pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MDP); - s->timeout = 0; + s->timeout = nfb_comp_read32(comp, NDP_CTRL_REG_TIMEOUT); s->max_request = 0; s->desc_base = nfb_comp_read64(comp, NDP_CTRL_REG_DESC_BASE); s->hdr_base = nfb_comp_read64(comp, NDP_CTRL_REG_HDR_BASE); - s->pointer_base = 0; + s->pointer_base = nfb_comp_read64(comp, NDP_CTRL_REG_UPDATE_BASE); s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; s->stat_running = (s->_stat_raw & 1) ? 1 : 0; } else { diff --git a/libnfb/include/netcope/txqueue.h b/libnfb/include/netcope/txqueue.h index 6913d0f3..e276e2a0 100644 --- a/libnfb/include/netcope/txqueue.h +++ b/libnfb/include/netcope/txqueue.h @@ -224,6 +224,8 @@ static inline int nc_txqueue_read_status(struct nc_txqueue *txqueue, struct nc_t s->sd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_SDP); s->hd_pointer = nfb_comp_read32(comp, NDP_CTRL_REG_HDP); s->desc_pointer_mask = nfb_comp_read32(comp, NDP_CTRL_REG_MDP); + s->timeout = nfb_comp_read32(comp, NDP_CTRL_REG_TIMEOUT); + s->pointer_base = nfb_comp_read64(comp, NDP_CTRL_REG_UPDATE_BASE); s->ctrl_running = (s->_ctrl_raw & 1) ? 1 : 0; s->stat_running = (s->_stat_raw & 1) ? 1 : 0; diff --git a/tools/dma/dma.c b/tools/dma/dma.c index 1d51ddee..c5c111b0 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -649,8 +649,7 @@ void rxqueue_print_status(struct ni_context *ctx, struct nc_rxqueue *q, int inde ni_item_str_size(ctx, NI_CTRL_BS, s->pointer_mask ? s->pointer_mask + 1 : 0); } - if (q->type == QUEUE_TYPE_SZE || q->type == QUEUE_TYPE_NDP) - ni_item_uint64_tx(ctx, NI_CTRL_REG_TO, s->timeout); + ni_item_uint64_tx(ctx, NI_CTRL_REG_TO, s->timeout); if (q->type == QUEUE_TYPE_SZE) { ni_item_uint64_tx(ctx, NI_CTRL_REG_MR, s->max_request); @@ -670,8 +669,7 @@ void rxqueue_print_status(struct ni_context *ctx, struct nc_rxqueue *q, int inde ni_item_uint64_tx(ctx, NI_CTRL_REG_DESC_B, s->desc_base); if (q->type == QUEUE_TYPE_CALYPTE) ni_item_uint64_tx(ctx, NI_CTRL_REG_HDR_B, s->hdr_base); - else - ni_item_uint64_tx(ctx, NI_CTRL_REG_PTR_B, s->pointer_base); + ni_item_uint64_tx(ctx, NI_CTRL_REG_PTR_B, s->pointer_base); } } @@ -734,8 +732,7 @@ void txqueue_print_status(struct ni_context *ctx, struct nc_txqueue *q, int inde ni_item_str_size(ctx, NI_CTRL_BS, s->pointer_mask ? s->pointer_mask + 1 : 0); } - if (q->type == QUEUE_TYPE_SZE || q->type == QUEUE_TYPE_NDP) - ni_item_uint64_tx(ctx, NI_CTRL_REG_TO, s->timeout); + ni_item_uint64_tx(ctx, NI_CTRL_REG_TO, s->timeout); if (q->type == QUEUE_TYPE_SZE) { ni_item_uint64_tx(ctx, NI_CTRL_REG_MR, s->max_request); @@ -755,8 +752,9 @@ void txqueue_print_status(struct ni_context *ctx, struct nc_txqueue *q, int inde } } - if (s && verbose > 1 && q->type != QUEUE_TYPE_CALYPTE) { - ni_item_uint64_tx(ctx, NI_CTRL_REG_DESC_B, s->desc_base); + if (s && verbose > 1) { + if (q->type != QUEUE_TYPE_CALYPTE) + ni_item_uint64_tx(ctx, NI_CTRL_REG_DESC_B, s->desc_base); ni_item_uint64_tx(ctx, NI_CTRL_REG_PTR_B, s->pointer_base); } } From efb104cea57d67c92efbdf45db7762f057501c78 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 20 Oct 2025 17:22:25 +0200 Subject: [PATCH 441/518] feat(dma-registers): add EXPER register for Peer-to-Peer transfers This register has been introduced to DMA Calypte for experimental features and now it contains only one functional bit (bit 0) which enables a Peer-to-peer transfer for the specific DMA channel. This register is cleared when the communication is done between a software and a DMA controller since enabling Peer-to-peer introduces custom pointer translation which whould lead to a malformation of data. --- libnfb/include/netcope/dma_ctrl_ndp.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index fb2699aa..50e19d71 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -39,6 +39,8 @@ #define NDP_CTRL_REG_MDP 0x58 #define NDP_CTRL_REG_MHP 0x5C +// ---------------- Calypte specific registers ------- +#define NDP_CTRL_REG_EXPER 0x08 // -------------- NDP/Calypte Counters ----------------- // Processed packets on TX @@ -424,6 +426,10 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl /* Zero both buffer ptrs */ nfb_comp_write64(ctrl->comp, NDP_CTRL_REG_SDP, 0); + // Since this is a software initializing the queue, the Peer-to-Peer mode has to be disabled + if (ctrl->type == DMA_TYPE_CALYPTE) + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_EXPER, 0); + /* Timeout */ /* TODO: let user to configure tihs value */ nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, 0x4000); From 74cea3665972bece9343de37d622edc9473f076f Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 20 Oct 2025 17:22:00 +0200 Subject: [PATCH 442/518] feat(tools): create Peer-to-Peer control tool This tool is an experimental one which enables two devices with DMA Calypte modules to communicated in a Peer-to-peer manner (i.e. without CPU participating in the copying of data). HOWTO for this tool's control can be find in its help. --- python/ndp-tools/ndp-ptp/ndp-ptp.py | 380 ++++++++++++++++++++++++++++ 1 file changed, 380 insertions(+) create mode 100755 python/ndp-tools/ndp-ptp/ndp-ptp.py diff --git a/python/ndp-tools/ndp-ptp/ndp-ptp.py b/python/ndp-tools/ndp-ptp/ndp-ptp.py new file mode 100755 index 00000000..c0bce118 --- /dev/null +++ b/python/ndp-tools/ndp-ptp/ndp-ptp.py @@ -0,0 +1,380 @@ +#!/usr/bin/env python3 + +# SPDX-License-Identifier: Apache-2.0 +# +# Experimental tool connecting pairs of (RX,TX) channels in a Peer-to-Peer manner +# +# Copyright (C) 2025-2025 Universitaet Heidelberg, Institut fuer Technische Informatik (ZITI) +# Author(s): +# Vladislav Valek + +# TODO: Currently, this tool supports only one-endpoint devices. A support +# for multi-endpoint devices (like bifurcated ones) is a subject of future development. + +import sys +import re +import argparse + +from time import sleep + +import nfb + +from ofm.comp.mfb_tools.debug.gen_loop_switch import GenLoopSwitch +from ofm.utils import convert_units + + +class P2PChain: + + _REG_CONTROL = 0x00 + _REG_STATUS = 0x04 + _REG_EXPER = 0x08 + _REG_SDP = 0x10 + _REG_SHP = 0x14 + _REG_TIMEOUT = 0x20 + _REG_DESC_BASE = 0x40 + _REG_HDR_BASE = 0x48 + _REG_UPDATE_BASE = 0x50 + _REG_MDP = 0x58 + _REG_MHP = 0x5C + + def __init__(self, trans_dev, recv_dev, qcount, full_dpx_en=False): + self.trans_dev = trans_dev + self.recv_dev = recv_dev + self.trans_bars = self._findDevBarAddrs(trans_dev) + self.recv_bars = self._findDevBarAddrs(recv_dev) + self.trans_qs = trans_dev.fdt_get_compatible("cesnet,dma_ctrl_calypte_rx") + self.recv_qs = recv_dev.fdt_get_compatible("cesnet,dma_ctrl_calypte_tx") + + if full_dpx_en: + self.dpx_trans_qs = recv_dev.fdt_get_compatible("cesnet,dma_ctrl_calypte_rx") + self.dpx_recv_qs = trans_dev.fdt_get_compatible("cesnet,dma_ctrl_calypte_tx") + + self.qcount = qcount + self.lowest_qcount = min(len(self.trans_qs), len(self.recv_qs)) + + def _getNodeOffset(self, node): + # NOTE: assumes properties #address-cells = 1 and #size-cells = 1 + prop = node.get_property("reg") + return prop.value + + def _findDevBarAddrs(self, dev): + bdf_str = dev.fdt.get_property("pci-slot", "/system/device/endpoint0")[0] + pattern = re.compile(r"^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-7]$") + + if pattern.match(bdf_str) is None: + raise ValueError(f"Invalid BDF identifier: {bdf_str}") + + path = f"/sys/bus/pci/devices/{bdf_str}/resource" + bars = [] + try: + with open(path, "r") as f: + for line in f: + start, _, _ = line.strip().split() + bars.append(int(start, 16)) + except FileNotFoundError: + raise RuntimeError(f"Device {bdf_str} not found in sysfs") + + return bars + + def _chanStart(self, comp): + comp.set_bit(self._REG_CONTROL, 0) + return comp.wait_for_bit(self._REG_STATUS, 0) + + def _setupReceiver(self, trans_bar0, recv_q, trans_q, recv_dev): + recv_q_comp = recv_dev.comp_open(recv_q) + + ptr_offs = trans_bar0 + self._getNodeOffset(trans_q) + self._REG_SDP + print(f"Writing RX UPD Buff addr: {ptr_offs:x} to remote {recv_q.name}") + recv_q_comp.write64(self._REG_UPDATE_BASE, ptr_offs) + recv_q_comp.set_bit(self._REG_EXPER, 0) + recv_q_comp.write32(self._REG_TIMEOUT, 0x4000) + recv_q_comp.write64(self._REG_SDP, 0) + + return self._chanStart(recv_q_comp) + + def _setupTransmitter(self, recv_bar0, recv_bar2, trans_q, recv_q, trans_dev, recv_dev): + trans_q_comp = trans_dev.comp_open(trans_q) + recv_q_comp = recv_dev.comp_open(recv_q) + + ptr_offs = recv_bar0 + self._getNodeOffset(recv_q) + self._REG_SDP + print(f"Writing TX UPD Buff addr: {ptr_offs:x} to local {trans_q.name}") + trans_q_comp.write64(self._REG_UPDATE_BASE, ptr_offs) + + dbuff_phandle = recv_q.get_property("data_buff").value + dbuff_node = recv_dev.fdt_get_phandle(dbuff_phandle) + dbuff_offs = recv_bar2 + self._getNodeOffset(dbuff_node) + print(f"Writing TX DATA Buff addr: {dbuff_offs:x} to local {trans_q.name}") + trans_q_comp.write64(self._REG_DESC_BASE, dbuff_offs) + + hbuff_phandle = recv_q.get_property("hdr_buff").value + hbuff_node = recv_dev.fdt_get_phandle(hbuff_phandle) + hbuff_offs = recv_bar2 + self._getNodeOffset(hbuff_node) + print(f"Writing TX DATA Buff addr: {hbuff_offs:x} to local {trans_q.name}") + trans_q_comp.write64(self._REG_HDR_BASE, hbuff_offs) + + mhp = recv_q_comp.read16(self._REG_MHP) + mdp = recv_q_comp.read16(self._REG_MDP) + + trans_q_comp.write16(self._REG_MHP, mhp) + # Data pointer for TX controller is in bytes whereas RX controller + # advances in 128-byte blocks + trans_q_comp.write16(self._REG_MDP, mdp // 128) + trans_q_comp.set_bit(self._REG_EXPER, 0) + trans_q_comp.write32(self._REG_TIMEOUT, 0x4000) + trans_q_comp.write64(self._REG_SDP, 0) + + return self._chanStart(trans_q_comp) + + def _stopQPair(self, qidx, egress=True): + ret = True + recv_queue = self.recv_qs[qidx] if egress else self.dpx_recv_qs[qidx] + trans_queue = self.trans_qs[qidx] if egress else self.dpx_trans_qs[qidx] + trans_dev = self.trans_dev if egress else self.recv_dev + recv_dev = self.recv_dev if egress else self.trans_dev + + trans_q_comp = trans_dev.comp_open(trans_queue) + recv_q_comp = recv_dev.comp_open(recv_queue) + + trans_q_comp.clr_bit(self._REG_CONTROL, 0) + recv_q_comp.clr_bit(self._REG_CONTROL, 0) + + ret &= recv_q_comp.wait_for_bit(self._REG_STATUS, 0, level=False) + if not ret: + print("Failed to stop {} receiver {}".format("remote" if egress else "local", qidx)) + + ret &= trans_q_comp.wait_for_bit(self._REG_STATUS, 0, level=False) + if not ret: + print("Failed to stop {} transmitter {}".format("local" if egress else "remote", qidx)) + + return ret + + def _startQPair(self, qidx, egress=True): + recv_queue = self.recv_qs[qidx] if egress else self.dpx_recv_qs[qidx] + trans_queue = self.trans_qs[qidx] if egress else self.dpx_trans_qs[qidx] + trans_bars = self.trans_bars if egress else self.recv_bars + recv_bars = self.recv_bars if egress else self.trans_bars + trans_dev = self.trans_dev if egress else self.recv_dev + recv_dev = self.recv_dev if egress else self.trans_dev + + ret = self._setupReceiver(trans_bars[0], recv_queue, trans_queue, recv_dev) + if not ret: + print("Failed to start {} receiver {}".format("remote" if egress else "local", qidx)) + return ret + + ret = self._setupTransmitter(recv_bars[0], recv_bars[2], trans_queue, recv_queue, trans_dev, recv_dev) + if not ret: + print("Failed to start {} transmitter {}".format("local" if egress else "remote", qidx)) + return ret + + return ret + + def stopChans(self, full_dpx_en=False): + """Stops all channels in active qpairs + + All of the channels get stopped regardless if the stop attempt succeded or not. A warning + is issued if the attempt has ended in unsuccess + + Args: + full_dpx_en: disable qpairs in the oposite direction too + """ + + for qidx in range(self.qcount): + ret = self._stopQPair(qidx) + if not ret: + print(f"Failed to stop egress qpair {qidx}") + + if full_dpx_en: + ret = self._stopQPair(qidx, False) + if not ret: + print(f"Failed to stop ingress qpair {qidx}") + + def startChans(self, full_dpx_en=False): + """Starts all selected channels + + A start attempt is done on every channel. If an attempt ends up + unsuccessful, all previously enabled channels get shutdown and an error + is returned. + + Args: + full_dpx_en: disable qpairs in the oposite direction too + + Returns: + True if all channels were successfully enabled, otherwise False + """ + + ret = False + + for qidx in range(self.qcount): + ret = self._startQPair(qidx) + if not ret: + print(f"Failed to start egress qpair {qidx}") + self.stopChans() + return ret + + if full_dpx_en: + ret = self._startQPair(qidx, False) + if not ret: + print(f"Failed to ingress qpair {qidx}") + return ret + + return ret + + +def parseParams(): + help_dict = { + "transmitter" : "transmitting (local) device", + "receiver" : "receiving (remote) device", + "channels" : "specify the amount of communicating channels", + "loopback" : "enables loopback in the remote device which sends data back over the same" + " amount of channels", + "local_gen" : "enables local MFB generator generating packets of the specified size", + "remote_gen" : "enables remote MFB generator generating packets of the specified size", + "measure" : "continuously measures throughput on both sides of the P2P chain", + "freq" : "clock frequency of the domain where speed meters are located", + } + + ptp_desc = """ + This script allows to connect two devices with DMA Calypte modules in a + Peer-to-Peer (P2P) manner, meaning without the CPU involved in + facilitating the data copy. + """ + + examples = """ + Examples: + 1) Unidirectional connect from device 1 to 2 + ndp-ptp.py -t1 -r2 + + 2) Bidirectional connect from device 1 to 2 with packet generation and loopback + of data back from device 2 + ndp-ptp.py -t1 -r2 -g1024 -l + + 3) Bidirectional connect from device 1 to 2 with packet generation in both directions. + Enable measurement over 4 channels + ndp-ptp.py -t1 -r2 -g1024 -a512 -m -c4 + """ + + arg_parser = argparse.ArgumentParser( + prog="ndp-ptp", + formatter_class=argparse.RawDescriptionHelpFormatter, + description=ptp_desc, + epilog=examples + ) + + arg_parser.add_argument("-t", "--transmitter", default=nfb.default_dev_path, help=help_dict["transmitter"]) + arg_parser.add_argument("-r", "--receiver", default=nfb.default_dev_path, help=help_dict["receiver"]) + arg_parser.add_argument("-c", "--channels", type=int, default=1, help=help_dict["channels"]) + arg_parser.add_argument("-l", "--lbk", action="store_true", help=help_dict["loopback"]) + arg_parser.add_argument("-g", "--local-gen", type=int, default=None, help=help_dict["local_gen"]) + arg_parser.add_argument("-a", "--remote-gen", type=int, default=None, help=help_dict["remote_gen"]) + arg_parser.add_argument("-m", "--measure", action="store_true", help=help_dict["measure"]) + arg_parser.add_argument("-f", "--freq", type=int, default=200000000, help=help_dict["freq"]) + args = arg_parser.parse_args() + print(args) + + assert args.channels > 0, f"Invalid amount of channels: {args.channels}!" + + if args.local_gen is not None: + assert args.local_gen >= 60 and args.local_gen <= 4096, \ + f"Invalid packet size for local packet generator: {args.local_gen}!" + + if args.remote_gen is not None: + assert args.remote_gen >= 60 and args.remote_gen <= 4096, \ + f"Invalid packet size for remote packet generator: {args.remote_gen}!" + assert args.local_gen is not None, \ + "Remote generator can be activated only if the local generator is active!" + + return args + + +def main(): + args = parseParams() + + single_dev = False + full_dpx_en = args.lbk or (args.remote_gen is not None) + + # A device where RX DMA is activated + trans_dev = nfb.open(path=args.transmitter) + if args.transmitter == args.receiver: + recv_dev = trans_dev + single_dev = True + full_dpx_en = False + else: + # A device where TX DMA is activated + recv_dev = nfb.open(path=args.receiver) + + ptp_chain = P2PChain(trans_dev, recv_dev, args.channels, full_dpx_en) + + print(f"Transmitter -> BAR0: {ptp_chain.trans_bars[0]:x}, BAR2: {ptp_chain.trans_bars[2]:x}") + print(f"Receiver -> BAR0: {ptp_chain.recv_bars[0]:x}, BAR2: {ptp_chain.recv_bars[2]:x}") + + if not ptp_chain.startChans(full_dpx_en): + print("Exiting...") + sys.exit(-1) + + trans_gls = GenLoopSwitch(dev=args.transmitter, index=0) + recv_gls = GenLoopSwitch(dev=args.receiver, index=0) + + if args.lbk and not single_dev: + recv_gls.l2r.input = 3 + + if args.local_gen is not None: + trans_gls.l2r.gen_start(True, args.local_gen, 0, args.channels-1) + + if not args.lbk and args.remote_gen is not None and not single_dev: + recv_gls.l2r.gen_start(True, args.remote_gen, 0, args.channels-1) + + if args.measure and args.local_gen is not None: + sms = [trans_gls.l2r.tx_sm, recv_gls.r2l.rx_sm] + if full_dpx_en: + sms += [recv_gls.l2r.tx_sm, trans_gls.r2l.rx_sm] + + try: + while True: + sm_speeds = [] + + for sm_comp in sms: + sm_comp.clear_data() + bps, _ = GenLoopSwitch.sm_measure(sm_comp, freq=args.freq) + b_speed, b_unit = convert_units(bps) + sm_speeds.append(f"{b_speed:>6.02f} {b_unit}bps") + + diagram = f"""\ + =================================================================================== + Local device Remote device + +-----+ + | GEN | ---> {sm_speeds[0]} ---------------------> {sm_speeds[1]} ----> X + +-----+\ +""" + if full_dpx_en: + mode = "LBK" if args.lbk else "GEN" + diagram += f""" + +-----+ + X <--- {sm_speeds[3]} <--------------------- {sm_speeds[2]} <---- | {mode} | + +-----+ +""" + print(diagram) + sleep(1) + + except KeyboardInterrupt: + print("Interrupt caught, stopping...") + else: + try: + while True: + sleep(1) + except KeyboardInterrupt: + print("Interrupt caught, stopping..") + + if not args.lbk and args.remote_gen is not None and not single_dev: + recv_gls.l2r.gen_stop() + + if args.local_gen is not None: + trans_gls.l2r.gen_stop() + + if args.lbk and not single_dev: + recv_gls.l2r.input = 0 + + ptp_chain.stopChans(full_dpx_en) + + +if __name__ == "__main__": + main() From db188242761b219b784f74c6baf84f345ef16b03 Mon Sep 17 00:00:00 2001 From: Vladislav Valek Date: Mon, 1 Dec 2025 15:52:47 +0100 Subject: [PATCH 443/518] ci(pycodestyle): unify ignored rules with ndk-fpga --- tests/ci/pycodestyle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ci/pycodestyle.sh b/tests/ci/pycodestyle.sh index 551df7f5..50405ab7 100755 --- a/tests/ci/pycodestyle.sh +++ b/tests/ci/pycodestyle.sh @@ -1,2 +1,2 @@ #!/bin/sh -flake8 --statistics --extend-ignore=E221,E261,E265,E501 +flake8 --statistics --extend-ignore=E221,E261,E265,E266,E501,T201,T202,B902,F821,E203 From 938710cceb6d26f18939098e879244e64a6ab979 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 2 Dec 2025 17:31:56 +0100 Subject: [PATCH 444/518] bump version to 6.29.0 --- Changelog | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 6d8f73d6..d645a630 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +* Tue Dec 2 2025 Martin Spinler - 6.29.0-1 +- [FEATURE] add rx_stream to nc_ifc_eth_map_info +- [OPT] dma-calypte: optimize performance for throughput/latency (compatible just with version 2.0) + * Thu Nov 20 2025 Martin Spinler - 6.28.8-1 - [FIX] BittWare BMC (ia-440i): initialize buffer for I2C write diff --git a/VERSION b/VERSION index d2811ed0..94ae9e99 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.28.8 +6.29.0 From b8d833d3d4af5078cbcbaf1dffaf5dae763891de Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 2 Dec 2025 17:42:06 +0100 Subject: [PATCH 445/518] fix(FB2CDG1): enable variant in card name --- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 2 +- drivers/kernel/drivers/nfb/pci.c | 2 +- tools/boot/boot.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index 570666fd..02bfb2e8 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -337,7 +337,7 @@ int nfb_pmci_attach(struct nfb_boot *boot) mutex_init(&pmci->flash_ops.mux_lock); pmci->m10bmc.dev = &pmci->pd->dev; - pmci->m10bmc.type = !strcmp(boot->nfb->card_name, "FB2CDG1") ? M10_FB2CDG1 : M10_N6000; + pmci->m10bmc.type = !strncmp(boot->nfb->card_name, "FB2CDG1", 7) ? M10_FB2CDG1 : M10_N6000; pmci->m10bmc.flash_ops = &pmci->flash_ops; pmci->m10bmc.regmap = nfb_devm_regmap_init_indirect_register(&pmci->pd->dev, diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index c910b855..a8775dd7 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -361,7 +361,7 @@ static int nfb_fdt_fixups(struct nfb_device *nfb) nfb_fdt_create_binary_slot(fdt, node, "image1", "recovery" , 1, 0, 0, 0x00210000, 0x02000000-0x210000); nfb_fdt_create_binary_slot(fdt, node, "image0", "application0" , 0, 1, 0, 0x02000000, 0x04000000); //nfb_fdt_create_boot_type(fdt, node, "BPI", 16); - } else if (!strcmp(card_name, "N6010") || !strcmp(card_name, "FB2CDG1")) { + } else if (!strcmp(card_name, "N6010") || !strncmp(card_name, "FB2CDG1", 7)) { subnode = nfb_fdt_create_binary_slot(fdt, node, "image2", "fpga_factory", 2, 2, -1, 0, 0); n6010_binary_slot_prepare(fdt, subnode, "\x03\x00\x00\x00", "\xff\xff\xff\xff", 4); subnode = nfb_fdt_create_binary_slot(fdt, node, "image1", "fpga_user2", 1, 4, -1, 0, 0); diff --git a/tools/boot/boot.c b/tools/boot/boot.c index a1512141..b3c0a1e5 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -691,7 +691,7 @@ int card_requires_sleep(const void *fdt) { fdt_offset = fdt_path_offset(fdt, "/firmware/"); prop = fdt_getprop(fdt, fdt_offset, "card-name", &len); if (prop != NULL) { - if (!strcmp(prop, "N6010") || !strcmp(prop, "FB2CDG1")) { + if (!strcmp(prop, "N6010") || !strncmp(prop, "FB2CDG1", 7)) { return 1; } } From 57bb05c6ac09a9fc9c667f3cfd6daa271309981d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 4 Dec 2025 14:26:22 +0100 Subject: [PATCH 446/518] fix: change printf first argument to a literal constant --- tools/eth/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/eth/main.c b/tools/eth/main.c index 6362f896..ad1a609f 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -280,7 +280,7 @@ int print_ctrl_reg_json(void *priv, int item, int val) res = val ? "true": "false"; break; } - return fprintf(p->f, res); + return fprintf(p->f, "%s", res); } int print_ctrl_reg_user(void *priv, int item, int val) From 51270034173f7fabd9c9b11a77737bca1a2f54e1 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 5 Dec 2025 17:59:37 +0100 Subject: [PATCH 447/518] fix(nccommon): enable range to be specified as one item with n-n --- libnfb/include/netcope/nccommon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/nccommon.h b/libnfb/include/netcope/nccommon.h index dcd491cb..76b6d09f 100644 --- a/libnfb/include/netcope/nccommon.h +++ b/libnfb/include/netcope/nccommon.h @@ -134,7 +134,7 @@ static inline int list_range_add_number(struct list_range *lr, int x) static inline int list_range_add_range(struct list_range *lr, int x, int y) { - if (y <= x) + if (y < x) return -1; lr->min = realloc(lr->min, (lr->items + 1) * sizeof(*lr->min)); From 78f95c4ec0590566932cea607eba5f6e361304b6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 4 Dec 2025 14:28:02 +0100 Subject: [PATCH 448/518] feat: add timeout to dma_ctrl_ndp_start_params structure --- libnfb/include/netcope/dma_ctrl_ndp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 50e19d71..17d306d6 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -135,6 +135,7 @@ struct nc_ndp_ctrl_start_params { uint32_t nb_data; uint32_t nb_desc; uint32_t nb_hdr; + uint32_t timeout; }; static inline struct nc_ndp_desc nc_ndp_rx_desc0(uint64_t phys) @@ -431,8 +432,7 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_EXPER, 0); /* Timeout */ - /* TODO: let user to configure tihs value */ - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, 0x4000); + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, sp->timeout ? sp->timeout : 0x4000); /* Start controller */ nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, NDP_CTRL_REG_CONTROL_START); From f6c3e63d9d2d94716211bedd40cf473ee8029dae Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 4 Dec 2025 14:29:01 +0100 Subject: [PATCH 449/518] feat(drivers - NDP): enable to set timeout in NDP Medusa --- drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c index 36afa5cb..7ef4862e 100644 --- a/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c +++ b/drivers/kernel/drivers/nfb/ndp/ctrl_ndp.c @@ -98,6 +98,7 @@ struct ndp_ctrl { uint32_t next_sdp; uint32_t flags; + uint32_t timeout; struct ndp_channel channel; struct nfb_device *nfb; @@ -300,6 +301,28 @@ static ssize_t ndp_ctrl_set_initial_offset(struct device *dev, return size; } +static ssize_t ndp_ctrl_get_timeout(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + return scnprintf(buf, PAGE_SIZE, "%u\n", ctrl->timeout); +} + +static ssize_t ndp_ctrl_set_timeout(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + unsigned long long value; + struct ndp_channel *channel = dev_get_drvdata(dev); + struct ndp_ctrl *ctrl = container_of(channel, struct ndp_ctrl, channel); + + value = memparse(buf, NULL); + + ctrl->timeout = value; + + return size; +} + static ssize_t ndp_ctrl_get_ring_size(struct device *dev, struct device_attribute *attr, char *buf) { struct ndp_channel *channel = dev_get_drvdata(dev); @@ -792,6 +815,7 @@ static int ndp_ctrl_medusa_start(struct ndp_channel *channel, uint64_t *hwptr) sp.update_buffer = ctrl->update_buffer_phys; sp.nb_desc = ctrl->desc_count; sp.nb_hdr = ctrl->hdr_count; + sp.timeout = ctrl->timeout; ret = ndp_ctrl_start(ctrl, &sp); if (ret) @@ -1493,6 +1517,7 @@ static DEVICE_ATTR(ring_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_ctrl_get_ring static DEVICE_ATTR(buffer_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_ctrl_get_buffer_size, ndp_ctrl_set_buffer_size); static DEVICE_ATTR(buffer_count, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_ctrl_get_buffer_count, ndp_ctrl_set_buffer_count); static DEVICE_ATTR(initial_offset, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_ctrl_get_initial_offset, ndp_ctrl_set_initial_offset); +static DEVICE_ATTR(timeout, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_ctrl_get_timeout, ndp_ctrl_set_timeout); static struct device_attribute dev_attr_calypte_ring_size = __ATTR(ring_size, (S_IRUGO | S_IWGRP | S_IWUSR), ndp_channel_get_ring_size, ndp_channel_set_ring_size); @@ -1501,6 +1526,7 @@ static struct attribute *ndp_ctrl_rx_attrs[] = { &dev_attr_buffer_size.attr, &dev_attr_buffer_count.attr, &dev_attr_initial_offset.attr, + &dev_attr_timeout.attr, NULL, }; @@ -1509,6 +1535,7 @@ static struct attribute *ndp_ctrl_tx_attrs[] = { &dev_attr_buffer_size.attr, &dev_attr_buffer_count.attr, &dev_attr_initial_offset.attr, + &dev_attr_timeout.attr, NULL, }; From 66c9c6db4c75d830f68e60928fd2d7fb5a012dc0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 19 Nov 2025 11:40:57 +0100 Subject: [PATCH 450/518] feat(nfb-dma): allow to set custom timeout for DMA controller --- tools/dma/dma.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/dma/dma.c b/tools/dma/dma.c index c5c111b0..c4c26931 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -46,7 +46,7 @@ /*! -V version */ -#define ARGUMENTS "d:i:q:rtRS:B:C:N:O:Tjvh" +#define ARGUMENTS "d:i:q:rtRS:B:C:N:O:I:Tjvh" enum commands { CMD_PRINT_STATUS, @@ -57,6 +57,7 @@ enum commands { CMD_SET_BUFFER_SIZE, CMD_SET_BUFFER_COUNT, CMD_SET_INITIAL_OFFSET, + CMD_SET_TIMEOUT, CMD_NETDEV, CMD_QUERY, }; @@ -333,6 +334,7 @@ void usage(const char *me, int verbose) printf("-B buffer_size Set kernel buffer size (for single packet; DMA Medusa only)\n"); printf("-C buffer_count Set kernel buffer count (replacement for ring_size; DMA Medusa only)\n"); printf("-O initial_off Set initial offset in ring buffer (first buffer offset; DMA Medusa only)\n"); + printf("-I timeout Set timeout value to DMA register\n"); printf("-q query Get specific informations%s\n", verbose ? "" : " (-v for more info)"); if (verbose) { for (unsigned i = 0; i < NC_ARRAY_SIZE(queries); i++) { @@ -857,6 +859,10 @@ int main(int argc, char *argv[]) cmd = CMD_SET_INITIAL_OFFSET; csize = optarg; break; + case 'I': + cmd = CMD_SET_TIMEOUT; + csize = optarg; + break; case 'N': cmd = CMD_NETDEV; netdev_cmd = optarg; @@ -940,6 +946,9 @@ int main(int argc, char *argv[]) sum_rx.discarded += cntr_rx.discarded; sum_rx.discarded_bytes += cntr_rx.discarded_bytes; break; + case CMD_SET_TIMEOUT: + set_ring_size(dev, 0, i, csize, "timeout"); + break; case CMD_SET_RING_SIZE: set_ring_size(dev, 0, i, csize, "ring_size"); break; @@ -991,6 +1000,9 @@ int main(int argc, char *argv[]) sum_tx.sent += cntr_tx.sent; sum_tx.sent_bytes += cntr_tx.sent_bytes; break; + case CMD_SET_TIMEOUT: + set_ring_size(dev, 1, i, csize, "timeout"); + break; case CMD_SET_RING_SIZE: if (txq->type == QUEUE_TYPE_CALYPTE) err(errno, "TX Calypte controller does not support setting of ring buffer size."); From 35dc1fd0f7309321bd6457905c61922c2c803b7d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 11 Dec 2025 15:36:48 +0100 Subject: [PATCH 451/518] opt(DMA Medusa): use 2048 for timeout reg value --- libnfb/include/netcope/dma_ctrl_ndp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/dma_ctrl_ndp.h b/libnfb/include/netcope/dma_ctrl_ndp.h index 17d306d6..10961d4a 100644 --- a/libnfb/include/netcope/dma_ctrl_ndp.h +++ b/libnfb/include/netcope/dma_ctrl_ndp.h @@ -432,7 +432,7 @@ static inline int nc_ndp_ctrl_start(struct nc_ndp_ctrl *ctrl, struct nc_ndp_ctrl nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_EXPER, 0); /* Timeout */ - nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, sp->timeout ? sp->timeout : 0x4000); + nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_TIMEOUT, sp->timeout ? sp->timeout : 0x800); /* Start controller */ nfb_comp_write32(ctrl->comp, NDP_CTRL_REG_CONTROL, NDP_CTRL_REG_CONTROL_START); From e24f248195440ef252e2a6fb0bab6d347fcd19a6 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 2 Jan 2026 08:46:14 +0100 Subject: [PATCH 452/518] fix(libnetcope - ni): free memory on close (memory leak) --- libnfb/include/netcope/ni/conf_default.h | 1 + libnfb/include/netcope/ni/plugin_json.h | 2 +- libnfb/include/netcope/ni/plugin_user.h | 13 +++++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libnfb/include/netcope/ni/conf_default.h b/libnfb/include/netcope/ni/conf_default.h index 4ab3df1b..c9c94eec 100644 --- a/libnfb/include/netcope/ni/conf_default.h +++ b/libnfb/include/netcope/ni/conf_default.h @@ -75,6 +75,7 @@ static const struct ni_callbacks ni_cb_json = { static const struct ni_callbacks ni_cb_user = { .init = ni_user_init, + .close = ni_user_close, .section = ni_user_section, .endsection = ni_user_endsection, .list = ni_user_list, diff --git a/libnfb/include/netcope/ni/plugin_json.h b/libnfb/include/netcope/ni/plugin_json.h index 405b026f..3421de47 100644 --- a/libnfb/include/netcope/ni/plugin_json.h +++ b/libnfb/include/netcope/ni/plugin_json.h @@ -111,7 +111,7 @@ static inline int ni_json_init(void *init_params, struct ni_common_init_params * static inline void ni_json_close(void *priv) { struct ni_json_priv *ctx = priv; - (void)ctx; + free(ctx); printf("\n"); } diff --git a/libnfb/include/netcope/ni/plugin_user.h b/libnfb/include/netcope/ni/plugin_user.h index 02eb73f0..e62d91fa 100644 --- a/libnfb/include/netcope/ni/plugin_user.h +++ b/libnfb/include/netcope/ni/plugin_user.h @@ -96,7 +96,7 @@ static inline int ni_user_init(void *init_params, struct ni_common_init_params * if(cip->get == NULL || cip->items == NULL) return -EINVAL; - ctx = malloc(sizeof(struct ni_user_priv) + sizeof(struct ni_user_stack_state) * stack_size + 4096); + ctx = malloc(sizeof(struct ni_user_priv) + sizeof(struct ni_user_stack_state) * stack_size); if (ctx == NULL) return -ENOMEM; @@ -105,9 +105,6 @@ static inline int ni_user_init(void *init_params, struct ni_common_init_params * ctx->clo = 0; - ctx->buffer = (void*) (ctx + 1); - ctx->buffer += sizeof(struct ni_user_stack_state) * stack_size; - ctx->fb = open_memstream(&ctx->buffer, &ctx->buffer_size); ctx->fo = stdout; @@ -143,6 +140,14 @@ static inline void ni_user_flush_f(struct ni_user_priv *ctx) ctx->f = ctx->fo; } +static inline void ni_user_close(void *priv) +{ + struct ni_user_priv *ctx = priv; + fclose(ctx->fb); + free(ctx->buffer); + free(ctx); +} + static inline void ni_user_section(void *priv, int item_index) { struct ni_user_priv *ctx = priv; From e61f2768ccb581bfbedda4eeb7f29edeb5493ed2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 2 Jan 2026 08:48:04 +0100 Subject: [PATCH 453/518] chore(tools - info): sort cards by id --- tools/info/info.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/tools/info/info.c b/tools/info/info.c index bff783cb..fa7e39b8 100644 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -256,14 +256,25 @@ void print_version() #endif } +int filter_nfbs(const struct dirent *dir) +{ + size_t i; + for (i = 0; i < strlen(dir->d_name); i++) { + if (!isdigit(dir->d_name[i])) + return 0; + } + return 1; +} + void print_device_list(struct ni_context *ctx) { int ret; int len; - int fdt_offset; + int fdt_offset, fdt_off_slot; + int cnt, i; - DIR * d; struct dirent *dir; + struct dirent **namelist; struct nc_composed_device_info info; struct nfb_device *dev; @@ -274,28 +285,25 @@ void print_device_list(struct ni_context *ctx) const char *prop; const uint32_t *prop32; - d = opendir(NFB_BASE_DEV_PATH "by-pci-slot/"); ni_list(ctx, NI_LIST_NFB); - while (d && (dir = readdir(d)) != NULL) { - ret = snprintf(path, NFB_PATH_MAXLEN, NFB_BASE_DEV_PATH "by-pci-slot/%s", dir->d_name); - if (ret <= 0 || ret >= NFB_PATH_MAXLEN) { - continue; - } - - realpath(path, lpath); + cnt = scandir("/dev/nfb/", &namelist, filter_nfbs, alphasort); + for (i = 0; i < cnt; i++) { + dir = namelist[i]; - dev = nfb_open(path); + snprintf(lpath, PATH_MAX, "/dev/nfb%s", dir->d_name); + dev = nfb_open(lpath); if (dev) { ni_section(ctx, NI_SEC_LIST_NFB); fdt = nfb_get_fdt(dev); fdt_offset = fdt_path_offset(fdt, "/firmware/"); + fdt_off_slot = fdt_path_offset(fdt, "/system/device/endpoint0/"); ret = nc_get_composed_device_info_by_pci(dev, NULL, &info); ni_item_int(ctx, NI_L_NFB_ID, ret == 0 ? info.nfb_id : -1); ni_item_str(ctx, NI_L_LPATH, lpath); - ni_item_str(ctx, NI_L_BFN, dir->d_name); + ni_fdt_prop_str(ctx, NI_L_BFN, fdt, fdt_off_slot, "pci-slot", &len); ni_fdt_prop_str(ctx, NI_L_CARD_NAME, fdt, fdt_offset, "card-name", &len); fdt_offset = fdt_path_offset(fdt, "/board/"); @@ -320,7 +328,10 @@ void print_device_list(struct ni_context *ctx) ni_endsection(ctx, NI_SEC_LIST_NFB); } + free(dir); } + if (cnt >= 0) + free(namelist); ni_endlist(ctx, NI_LIST_NFB); } From 96ba43d07c3ac96932237070dfe5e1314627ac75 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 2 Jan 2026 17:28:46 +0100 Subject: [PATCH 454/518] feat(drivers - bw-bmc): set fallback boot priority for first image --- drivers/kernel/drivers/nfb/boot/bw-bmc.c | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/kernel/drivers/nfb/boot/bw-bmc.c b/drivers/kernel/drivers/nfb/boot/bw-bmc.c index 135052f2..92d375dc 100644 --- a/drivers/kernel/drivers/nfb/boot/bw-bmc.c +++ b/drivers/kernel/drivers/nfb/boot/bw-bmc.c @@ -391,6 +391,44 @@ static int nfb_boot_bw_bmc_set_priority(struct nfb_boot *boot, struct nfb_boot_i return ret; } +static void set_fallback_priority(struct nfb_boot * boot) +{ + int ret; + void *fdt = nfb_get_fdt(boot->nfb); + int node; + int32_t id = -1; + int32_t priority = -1; + + struct nfb_boot_ioc_load load; + + uint64_t prio_data[2]; + + fdt_for_each_compatible_node(fdt, node, "netcope,binary_slot") { + ret = fdt_getprop32(fdt, node, "priority", &priority); + if (ret == 0 && priority != -1) { + break; + } + id = -1; + + ret = fdt_getprop32(fdt, node, "id", &id); + if (ret == 0 && id == 1) { + break; + } + } + + if (priority == -1) { + if (id == 1) { + prio_data[0] = id; + prio_data[1] = 0; + load.data_size = sizeof(prio_data); + load.data = (char*) prio_data; + + ret = nfb_boot_bw_bmc_set_priority(boot, &load); + nfb_boot_bw_bmc_update_binary_slots(boot); + } + } +} + int nfb_boot_bw_bmc_load(struct nfb_boot *boot, struct nfb_boot_ioc_load *load/*, struct nfb_boot_app_priv * app_priv*/) @@ -528,6 +566,8 @@ int nfb_boot_bw_bmc_load(struct nfb_boot *boot, if (update_nodes) nfb_boot_bw_bmc_update_binary_slots(boot); + set_fallback_priority(boot); + return 0; err_cmd: From 5862f47b6aa8378b48a051ec3dd8a9733a5958a2 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 2 Jan 2026 10:49:50 +0100 Subject: [PATCH 455/518] chore(nfb-eth): reorganize transceiver code --- tools/eth/cfp2.c | 3 +- tools/eth/eth.h | 2 +- tools/eth/main.c | 2 +- tools/eth/pcspma.c | 1 + tools/eth/qsfpp.c | 58 +++++++++++++++++++--------- tools/eth/transceiver.c | 85 ++++++++++++++++++++++------------------- 6 files changed, 90 insertions(+), 61 deletions(-) diff --git a/tools/eth/cfp2.c b/tools/eth/cfp2.c index 6d8ec152..d4592e27 100644 --- a/tools/eth/cfp2.c +++ b/tools/eth/cfp2.c @@ -152,9 +152,10 @@ int cfp_present(struct nfb_device *dev __attribute__((unused)), int nodeoffset _ * @param ifc Interface device * @param space Interface space */ -void cfp2_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node) +void cfp2_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node, struct eth_params *p) { (void) control_params_node; /* unused */ + (void) p; int i, channels; uint8_t reg8; diff --git a/tools/eth/eth.h b/tools/eth/eth.h index 9bcecade..91ea61d2 100644 --- a/tools/eth/eth.h +++ b/tools/eth/eth.h @@ -99,7 +99,7 @@ int txmac_execute_operation(struct ni_context *ctx, struct nc_txmac *txmac, stru int pcspma_execute_operation(struct ni_context *ctx, struct nfb_device *dev, int eth_node, struct eth_params *p); int transceiver_execute_operation(struct nfb_device *dev, int node_transceiver, struct eth_params *p); int transceiver_execute_operation_for_eth(struct nfb_device *dev, int node_eth, struct eth_params *p); -int transceiver_print(struct ni_context *ctx, struct nfb_device *dev, int transceiver_node, int index); +int transceiver_print(struct ni_context *ctx, struct nfb_device *dev, int transceiver_node, struct eth_params *p); void transceiver_print_short_info(struct ni_context *ctx, struct nfb_device *dev, int node, struct eth_params *p); int print_json_qsfp_i2c_text(void *, int item, struct nc_i2c_ctrl*); diff --git a/tools/eth/main.c b/tools/eth/main.c index ad1a609f..f76c514e 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -802,7 +802,7 @@ int main(int argc, char *argv[]) ni_section(ctx, NI_SEC_TRN); if (p.command == CMD_PRINT_STATUS) { used++; - transceiver_print(ctx, dev, node, p.index); + transceiver_print(ctx, dev, node, &p); } else { used++; ret = transceiver_execute_operation(dev, node, &p); diff --git a/tools/eth/pcspma.c b/tools/eth/pcspma.c index 038212cc..0b6d60e0 100644 --- a/tools/eth/pcspma.c +++ b/tools/eth/pcspma.c @@ -169,6 +169,7 @@ void pcspma_print_status(struct ni_context *ctx, struct nc_mdio *mdio, int porta ni_list(ctx, NI_LIST_PMA_FEATS_AV); for (item = pma_feature_table; item->name; item++) { + reg = 0; if (item->ability_bit != -1) { reg = nc_mdio_read(mdio, portaddr, 1, item->ability_reg); } diff --git a/tools/eth/qsfpp.c b/tools/eth/qsfpp.c index 472b308c..d9b69a33 100644 --- a/tools/eth/qsfpp.c +++ b/tools/eth/qsfpp.c @@ -22,6 +22,7 @@ #define SFF8636_TEMPERATURE 22 #define SFF8636_RX_INPUT_POWER 34 #define SFF8636_STXDISABLE 86 +#define SFF8636_PAGE_SELECT 127 #define SFF8636_CONNECTOR 130 #define SFF8636_COMPLIANCE 131 #define SFF8636_VENDOR_NAME 148 @@ -39,7 +40,6 @@ #define CMIS_HOST_LANE_COUNT 88 #define CMIS_BANK_SELECT 126 -#define CMIS_PAGE_SELECT 127 /* PAGE 0x00 */ #define CMIS_VENDOR_NAME 129 @@ -50,6 +50,8 @@ /* PAGE 0x11 */ #define CMIS_OPTICAL_POWER_RX 186 +#define SFF_ID_IS_CMIS(reg) (reg == 0x18) + static inline uint16_t qsfp_i2c_read16(struct nc_i2c_ctrl *ctrl, uint8_t reg) { uint16_t reg16 = 0; @@ -387,8 +389,13 @@ int qsfp_present(struct nc_i2c_ctrl *i2c, int mdev __attribute__((unused)) ) } #endif -void sff8636_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl); -void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl); +static void sff_select_page(struct nc_i2c_ctrl *ctrl, uint8_t page) +{ + nc_i2c_write_reg(ctrl, SFF8636_PAGE_SELECT, &page, 1); +} + +static void sff8636_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl, struct eth_params *p); +static void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl, struct eth_params *p); struct nc_i2c_ctrl *qsfpp_i2c_open(struct nfb_device *dev, int nodeoffset, int node_params) { @@ -425,8 +432,9 @@ struct nc_i2c_ctrl *qsfpp_i2c_open(struct nfb_device *dev, int nodeoffset, int n * @param ifc Interface device * @param space Interface space */ -void qsfpp_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int node_params) +void qsfpp_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int node_params, struct eth_params *p) { + int ret; uint8_t reg = 0xFF; struct nc_i2c_ctrl *ctrl; @@ -436,19 +444,21 @@ void qsfpp_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, return; } - nc_i2c_read_reg(ctrl, SFF8636_IDENTIFIER, ®, 1); + ret = nc_i2c_read_reg(ctrl, SFF8636_IDENTIFIER, ®, 1); + if (ret <= 0) + return; ni_item_str(ctx, NI_MOD_IDENT, qsfp_get_identifier(reg)); - if (reg == 0x18) { - cmis_print(ctx, ctrl); + if (SFF_ID_IS_CMIS(reg)) { + cmis_print(ctx, ctrl, p); } else { - sff8636_print(ctx, ctrl); + sff8636_print(ctx, ctrl, p); } nc_i2c_close(ctrl); } -void sff8636_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl) +static void sff8636_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl, struct eth_params *p) { const char *text; const int CHANNELS = 4; @@ -460,6 +470,8 @@ void sff8636_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl) int ret; double pwr; + (void) p; + /* Wait for Data Ready (max 2 sec according specs) */ /* TODO: this should be done in qsfp_i2c_common functions */ /* TODO: use nfb_comp_read32_poll_timeout, as this implemenation is time unstable */ @@ -513,16 +525,18 @@ void sff8636_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl) ni_endlist(ctx, NI_LIST_TRN_STX_DIS); } -void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl) +static void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl, struct eth_params *p) { int channel_cnt = 8; uint8_t i; - uint8_t reg = 0; + uint8_t reg; uint16_t reg16 = 0; double pwr; - nc_i2c_write_reg(ctrl, CMIS_PAGE_SELECT, ®, 1); + (void) p; + + sff_select_page(ctrl, 0); nc_i2c_read_reg(ctrl, CMIS_REVISION, ®, 1); ni_item_int(ctx, NI_TRN_CMIS_VER_MAJ, reg >> 4); @@ -550,7 +564,7 @@ void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl) ni_list(ctx, NI_LIST_TRN_RX_IN_PWR); for (i = 0; i < channel_cnt; i++) { - reg = 0x11; nc_i2c_write_reg(ctrl, CMIS_PAGE_SELECT, ®, 1); + sff_select_page(ctrl, 0x11); reg16 = qsfp_i2c_read16(ctrl, CMIS_OPTICAL_POWER_RX + i * 2); pwr = ((float)reg16) / 10000000; ni_item_int(ctx, NI_TRANS_RX_IN_PWR_L, i + 1); @@ -568,16 +582,24 @@ void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl) int qsfpp_stxdisable(struct nfb_device *dev, int nodeoffset, int node_params, int disable, int channels) { - int ret = 0; - uint8_t reg = 0x18; + int ret; + uint8_t reg; struct nc_i2c_ctrl *ctrl = qsfpp_i2c_open(dev, nodeoffset, node_params); if (ctrl == NULL) return -ENODEV; - nc_i2c_read_reg(ctrl, SFF8636_IDENTIFIER, ®, 1); - if (reg == 0x18) { - ret = -ENOTSUP; + ret = nc_i2c_read_reg(ctrl, SFF8636_IDENTIFIER, ®, 1); + if (ret <= 0) + return ret; + + ret = 0; + if (SFF_ID_IS_CMIS(reg)) { + /* This assumes OutputDisableTxSupported=1 and TxDisableIsModuleWide=1 */ + sff_select_page(ctrl, 0x10); + nc_i2c_read_reg(ctrl, 130, ®, 1); + reg = disable ? (reg | channels) : (reg & ~channels); + nc_i2c_write_reg(ctrl, 130, ®, 1); } else { channels &= 0x0F; diff --git a/tools/eth/transceiver.c b/tools/eth/transceiver.c index 6c0a568e..40d1725e 100644 --- a/tools/eth/transceiver.c +++ b/tools/eth/transceiver.c @@ -19,12 +19,13 @@ #include "eth.h" -void qsfpp_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node); -void cfp2_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node); +void qsfpp_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node, struct eth_params *p); +void cfp2_print(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node, struct eth_params *p); int qsfpp_stxdisable(struct nfb_device *dev, int nodeoffset, int node_params, int disable, int channels); +int qsfpp_set_feature(struct nfb_device *dev, int nodeoffset, int node_params, struct eth_params *p, int channels); -typedef void transc_print_t(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node); +typedef void transc_print_t(struct ni_context *ctx, struct nfb_device *dev, int nodeoffset, int control_params_node, struct eth_params *p); typedef int transc_plug_t(struct nfb_device *dev, int nodeoffset); struct transceiver_t { @@ -110,7 +111,7 @@ void transceiver_print_short_info(struct ni_context *ctx, struct nfb_device *dev } } -int transceiver_print(struct ni_context *ctx, struct nfb_device *dev, int node_transceiver, int index) +int transceiver_print(struct ni_context *ctx, struct nfb_device *dev, int node_transceiver, struct eth_params *p) { const struct transceiver_t *transceiver; const char *property; @@ -132,7 +133,7 @@ int transceiver_print(struct ni_context *ctx, struct nfb_device *dev, int node_t } ni_item_str(ctx, NI_TRN_NAME, property); - ni_item_int(ctx, NI_TRN_INDEX, index); + ni_item_int(ctx, NI_TRN_INDEX, p->index); present = transceiver_is_present(dev, node_transceiver); if (present < 0) @@ -149,7 +150,7 @@ int transceiver_print(struct ni_context *ctx, struct nfb_device *dev, int node_t return -EOPNOTSUPP; } - transceiver->print_status(ctx, dev, node_transceiver, fdt_subnode_offset(fdt, node_transceiver, "control-param")); + transceiver->print_status(ctx, dev, node_transceiver, fdt_subnode_offset(fdt, node_transceiver, "control-param"), p); return 0; } @@ -160,7 +161,7 @@ int _transceiver_execute_operation(struct nfb_device *dev, int node_transceiver, uint8_t ch; int proplen; - int node_params; + int node_params, off_ctrlparam; const void *fdt; const fdt32_t *prop32; const char *property; @@ -175,46 +176,50 @@ int _transceiver_execute_operation(struct nfb_device *dev, int node_transceiver, if (!present) return 0; - switch (p->command) { - case CMD_SET_PMA_FEATURE: - if (!strcmp(p->string, "Software TX disable")) { - if (strcmp((char *)property, "QSFP") != 0 && strcmp((char *)property, "QSFP28") != 0) { - warnx("Transceiver: Command not implemented"); - return -EOPNOTSUPP; - } + /* Select specific lane(s) in transceiver */ + if (eth_node >= 0) { + node_params = fdt_subnode_offset(fdt, eth_node, "pmd-params"); + if (node_params < 0) { + warnx("Transceiver: No pmd-params node in Device Tree"); + return -1; + } - if (eth_node >= 0) { - node_params = fdt_subnode_offset(fdt, eth_node, "pmd-params"); - if (node_params < 0) { - warnx("Transceiver: No pmd-params node in Device Tree"); - return -1; - } + prop32 = fdt_getprop(fdt, node_params, "lines", &proplen); + if (!prop32) { + warnx("Transceiver: No lines property in Device Tree"); + return -1; + } - prop32 = fdt_getprop(fdt, node_params, "lines", &proplen); - if (!prop32) { - warnx("Transceiver: No lines property in Device Tree"); - return -1; - } + ch = 0x0; + while (proplen > 0) { + ch |= (1 << fdt32_to_cpu(*prop32)); + proplen -= sizeof(*prop32); + prop32++; + } + } else { + /* bitmask of all 4 QSFP channels */ + ch = 0x0F; + } - ch = 0x0; - while (proplen > 0) { - ch |= (1 << fdt32_to_cpu(*prop32)); - proplen -= sizeof(*prop32); - prop32++; - } - } else { - /* bitmask of all 4 QSFP channels */ - ch = 0x0F; - } + off_ctrlparam = fdt_subnode_offset(fdt, node_transceiver, "control-param"); - ret = qsfpp_stxdisable(dev, node_transceiver, fdt_subnode_offset(fdt, node_transceiver, "control-param"), p->param, ch); - if (ret) { - warnx("Transceiver: Command failed"); - return ret; - } + if (strcmp((char *)property, "QSFP") != 0 && strcmp((char *)property, "QSFP28") != 0) { + warnx("Transceiver: Command not implemented"); + return -EOPNOTSUPP; + } + + switch (p->command) { + case CMD_SET_PMA_FEATURE: + if (!strcmp(p->string, "Software TX disable")) { + ret = qsfpp_stxdisable(dev, node_transceiver, off_ctrlparam, p->param, ch); } else { warnx("Transceiver: Command not implemented"); } + + if (ret) { + warnx("Transceiver: Command failed"); + return ret; + } break; default: From a60677a98742b9c9fe77fe1e5d6b6ac7b5e35c48 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 Jan 2026 13:35:18 +0100 Subject: [PATCH 456/518] feat(EXPERIMENTAL - nfb-eth): show or set features of transceiver --- tools/eth/eth.h | 5 ++ tools/eth/main.c | 6 ++ tools/eth/qsfpp.c | 165 ++++++++++++++++++++++++++++++++++++++++ tools/eth/transceiver.c | 2 +- 4 files changed, 177 insertions(+), 1 deletion(-) diff --git a/tools/eth/eth.h b/tools/eth/eth.h index 91ea61d2..3ba5630a 100644 --- a/tools/eth/eth.h +++ b/tools/eth/eth.h @@ -272,6 +272,11 @@ enum NI_ITEMS { NI_TRN_CMIS_MED_T, NI_TRN_CMIS_IFC_T, + NI_LIST_TRN_FEATS_AV, + NI_SEC_TRN_FEAT, + NI_TRN_FEAT_ACTIVE, + NI_TRN_FEAT_NAME, + NI_MDIO_VNDR_NAME, NI_MDIO_SN, NI_MDIO_PN, diff --git a/tools/eth/main.c b/tools/eth/main.c index f76c514e..a874f3ef 100644 --- a/tools/eth/main.c +++ b/tools/eth/main.c @@ -225,6 +225,11 @@ static struct ni_context_item_default ni_items[] = { [NI_MDIO_HW_REV] = {ni_json_k("hw_spec_rev"), ni_user_f("HW spec. rev.", NUFD(1))}, [NI_MDIO_MGMT_REV] = {ni_json_k("mgmt_spec_rev"), ni_user_f("Management ifc. spec. rev.", NUFD(1))}, + [NI_LIST_TRN_FEATS_AV] = {ni_json_k("available_features"), ni_user_f("Supported transceiver features ->", 0)}, + [NI_SEC_TRN_FEAT] = {ni_json_e, ni_user_n}, + [NI_TRN_FEAT_NAME] = {ni_json_k("name"), ni_user_l("")}, + [NI_TRN_FEAT_ACTIVE] = {ni_json_k("active"), ni_user_f(" * ", NUF_NDA)}, + [NI_SEC_RSFEC_STATUS] = {ni_json_k("rsfec"), ni_user_l("RS-FEC status")}, [NI_SEC_RSFEC119_STATUS]= {ni_json_k("rsfec_cl119"), ni_user_l("RS-FEC status")}, [NI_RSFEC_STATUS_BCA] = {ni_json_k("bypass_correction"), ni_user_l("RS-FEC bypass correction ability")}, @@ -322,6 +327,7 @@ int print_ctrl_reg_user(void *priv, int item, int val) case NI_TRANS_STX_DIS_V: res = val ? "active" : "inactive"; break; + case NI_TRN_FEAT_ACTIVE: case NI_PMA_TYPES_ACTIVE: case NI_PMA_FEAT_ACTIVE: res = val ? "[active]" : ""; break; diff --git a/tools/eth/qsfpp.c b/tools/eth/qsfpp.c index d9b69a33..d5c8be67 100644 --- a/tools/eth/qsfpp.c +++ b/tools/eth/qsfpp.c @@ -52,6 +52,83 @@ #define SFF_ID_IS_CMIS(reg) (reg == 0x18) +struct trn_ability { + int page; + int byte; + int bit; + int bitlen; +}; + +#define COND_TYPE_STOP 0 +#define COND_TYPE_INC 1 +#define COND_TYPE_ABILITY_SET 2 +#define COND_TYPE_ABILITY_CLR 3 +#define COND_TYPE_COMP_VAL_COND_GE 4 +//#define COND_TYPE_COMP_VAL_ABIL_GE 5 + +struct trn_feature_condition { + int type; + int next; /* index to feature_conds[] */ + + union { + int ability; /* index to trn_abilities[] */ + //int value; /* value to compare */ + } p; +}; + +struct trn_feature { + const char *name; + int control_page; + int control_byte; + int control_bit; + + int condition; /* index to *_feature_table[] */ + int cond_value; +}; + +#define C_S .p.ability = 0 + +struct trn_ability trn_abilities[] = { + [0x00] = {0x01, 151, 0, 1}, /* TxDisableIsModuleWide */ + [0x01] = {0x01, 155, 0, 1}, /* OutputDisableTxSupported */ + [0x02] = {0x00, CMIS_HOST_LANE_COUNT, 0, 4}, +}; + +static const struct trn_feature_condition feature_conds[] = { + [0x00] = {0, 0, C_S}, /* Special node next-ref value: stop */ + [0x01] = {1, 0, C_S}, /* Special node next-ref value: continue to cur_index+1 */ + [0x10] = {2, 0x12, .p.ability = 0x00}, + [0x11] = {3, 0x12, .p.ability = 0x00}, + [0x12] = {2, 0, .p.ability = 0x01}, + [0x13] = {4, 0x11, .p.ability = 0x02}, +}; + +#define FCN .cond_value = 0 + +static const struct trn_feature sff8636_feature_table [] = { + {NULL, 0, 0, 0, 0, FCN}, +}; + +#if 0 +static const struct trn_feature cmis_feature_table_ro [] = { + {"TxDisableIsModuleWide", 0x01, 151, 0, 0}, +}; +#endif + + +static const struct trn_feature cmis_feature_table [] = { + {"OutputDisableTx", 0x10, 130, 0, 0x10, FCN}, + {"OutputDisableTx1", 0x10, 130, 0, 0x13, 1}, + {"OutputDisableTx2", 0x10, 130, 1, 0x13, 2}, + {"OutputDisableTx3", 0x10, 130, 2, 0x13, 3}, + {"OutputDisableTx4", 0x10, 130, 3, 0x13, 4}, + {"OutputDisableTx5", 0x10, 130, 4, 0x13, 5}, + {"OutputDisableTx6", 0x10, 130, 5, 0x13, 6}, + {"OutputDisableTx7", 0x10, 130, 6, 0x13, 7}, + {"OutputDisableTx8", 0x10, 130, 7, 0x13, 8}, + {NULL, 0, 0, 0, 0, FCN}, +}; + static inline uint16_t qsfp_i2c_read16(struct nc_i2c_ctrl *ctrl, uint8_t reg) { uint16_t reg16 = 0; @@ -533,6 +610,11 @@ static void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl, struct uint8_t reg; uint16_t reg16 = 0; double pwr; + int cond_pass; + + const struct trn_feature *item; + const struct trn_feature_condition * cond, *cond_next; + const struct trn_ability * ability; (void) p; @@ -571,6 +653,49 @@ static void cmis_print(struct ni_context *ctx, struct nc_i2c_ctrl *ctrl, struct ni_item_pwr(ctx, NI_TRANS_RX_IN_PWR_V, pwr); } ni_endlist(ctx, NI_LIST_TRN_RX_IN_PWR); + + if (p->verbose) { + ni_list(ctx, NI_LIST_TRN_FEATS_AV); + for (item = cmis_feature_table; item->name; item++) { + reg = 0; + cond_next = &feature_conds[item->condition]; + cond_pass = 1; + do { + cond = cond_next; + if (cond->type == COND_TYPE_ABILITY_SET || cond->type == COND_TYPE_ABILITY_CLR) { + ability = &trn_abilities[cond->p.ability]; + sff_select_page(ctrl, ability->page); + nc_i2c_read_reg(ctrl, ability->byte, ®, 1); + if (((reg & (1 << ability->bit)) == 0 && cond->type == COND_TYPE_ABILITY_SET) || + ((reg & (1 << ability->bit)) != 0 && cond->type == COND_TYPE_ABILITY_CLR)) + cond_pass = 0; + } else if (cond->type == COND_TYPE_COMP_VAL_COND_GE) { + ability = &trn_abilities[cond->p.ability]; + sff_select_page(ctrl, ability->page); + nc_i2c_read_reg(ctrl, ability->byte, ®, 1); + + reg >>= ability->bit; + reg &= (1 << (ability->bitlen)) - 1; + + if (!(reg >= item->cond_value)) + cond_pass = 0; + } + + cond_next = cond->next == 0 ? NULL: (cond->next == 1 ? cond + 1 : &feature_conds[cond->next]); + } while (cond_pass == 1 && cond_next); + + if (cond_pass) { + ni_section(ctx, NI_SEC_TRN_FEAT); + sff_select_page(ctrl, item->control_page); + nc_i2c_read_reg(ctrl, item->control_byte, ®, 1); + + ni_item_ctrl_reg(ctx, NI_TRN_FEAT_ACTIVE, reg & (1 << item->control_bit)); + ni_item_str(ctx, NI_TRN_FEAT_NAME, item->name); + ni_endsection(ctx, NI_SEC_TRN_FEAT); + } + } + ni_endlist(ctx, NI_LIST_TRN_FEATS_AV); + } } /** @@ -611,3 +736,43 @@ int qsfpp_stxdisable(struct nfb_device *dev, int nodeoffset, int node_params, in nc_i2c_close(ctrl); return ret; } + +int qsfpp_set_feature(struct nfb_device *dev, int nodeoffset, int node_params, struct eth_params *p, int channels) +{ + int ret = -EINVAL; + uint8_t reg; + + const struct trn_feature *item; + + struct nc_i2c_ctrl *ctrl = qsfpp_i2c_open(dev, nodeoffset, node_params); + + (void) channels; + + if (ctrl == NULL) + return -ENODEV; + + ret = nc_i2c_read_reg(ctrl, SFF8636_IDENTIFIER, ®, 1); + if (ret <= 0) + return ret; + + if (SFF_ID_IS_CMIS(reg)) { + item = cmis_feature_table; + } else { + item = sff8636_feature_table; + } + + while (item->name) { + if (!strcmp(p->string, item->name)) { + sff_select_page(ctrl, item->control_page); + nc_i2c_read_reg(ctrl, item->control_byte, ®, 1); + reg = p->param ? (reg | item->control_bit) : (reg & ~item->control_bit); + nc_i2c_write_reg(ctrl, item->control_byte, ®, 1); + ret = 0; + break; + } + item++; + } + + nc_i2c_close(ctrl); + return ret; +} diff --git a/tools/eth/transceiver.c b/tools/eth/transceiver.c index 40d1725e..8729aaf5 100644 --- a/tools/eth/transceiver.c +++ b/tools/eth/transceiver.c @@ -213,7 +213,7 @@ int _transceiver_execute_operation(struct nfb_device *dev, int node_transceiver, if (!strcmp(p->string, "Software TX disable")) { ret = qsfpp_stxdisable(dev, node_transceiver, off_ctrlparam, p->param, ch); } else { - warnx("Transceiver: Command not implemented"); + ret = qsfpp_set_feature(dev, node_transceiver, off_ctrlparam, p, ch); } if (ret) { From 6723897e713498d3b2e8ab17c4c745e2b881a9f6 Mon Sep 17 00:00:00 2001 From: Denis Kurka Date: Mon, 5 Jan 2026 12:21:34 +0100 Subject: [PATCH 457/518] feat(boot - bittware bmc): add support for ia-860m card --- drivers/kernel/drivers/nfb/boot/bw-bmc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/boot/bw-bmc.c b/drivers/kernel/drivers/nfb/boot/bw-bmc.c index 92d375dc..04b0ae8a 100644 --- a/drivers/kernel/drivers/nfb/boot/bw-bmc.c +++ b/drivers/kernel/drivers/nfb/boot/bw-bmc.c @@ -178,7 +178,8 @@ static int nfb_boot_bw_bmc_load_partition_table(struct nfb_boot *boot) if (card_name == NULL) { return -ENODEV; - } else if (strncmp(card_name, "IA-440I", 7) == 0) { + } else if (strncmp(card_name, "IA-440I", 7) == 0 || + strncmp(card_name, "IA-860M", 7) == 0) { /* TODO: check Flash Configuration from VPD (I2C EEPROM @ 0x57, offset 50): * 0 means "Default" */ max_size = 0x10000000; @@ -291,7 +292,8 @@ int nfb_boot_bw_bmc_attach(struct nfb_boot* boot) nfb_boot_bw_bmc_load_partition_table(boot); - if (strncmp(boot->nfb->card_name, "IA-440I", 7) == 0) { + if (strncmp(boot->nfb->card_name, "IA-440I", 7) == 0 || + strncmp(boot->nfb->card_name, "IA-860M", 7) == 0) { boot->reload_link_up_time = 2500; } From 97d22bbde8108d457d82120fd4bef3e50bb8aead Mon Sep 17 00:00:00 2001 From: Denis Kurka Date: Mon, 5 Jan 2026 12:22:09 +0100 Subject: [PATCH 458/518] feat(nfb-bootstrap): add support for bittware ia-860m --- python/nfb-tools/nfbbootstrap/nfb_bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py index b2d106b8..3739df58 100755 --- a/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py +++ b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py @@ -39,7 +39,7 @@ def main(): n_mi.append(n_pmci) n_pmci.append(fdt.PropWords('reg', *pmci_reg)) n_pmci.append(fdt.PropStrings("compatible", "cesnet,pmci")) - elif args.card in ['IA-440I']: + elif args.card in ['IA-440I', 'IA-860M']: reg = [0x2000, 0x44] n_bmc = fdt.Node('bmc') From 44d2f94e1944c1cecfc7c37142832effa596097e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 5 Jan 2026 17:46:30 +0100 Subject: [PATCH 459/518] bump version to 6.30.0 --- Changelog | 8 ++++++++ VERSION | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index d645a630..50315d8a 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,11 @@ +* Mon Jan 5 2026 Martin Spinler - 6.30.0-1 +- [FEATURE]: add support for different varians of FB2CDG1 card +- [FEATURE]: introduce support for BittWare IA-860m card +- [FEATURE]: set fallback boot priority for first image in BittWare BMC +- [FEATURE]: show or set features of transceiver (experimental; currently OutputDisableTx for QSFP-DD only) +- [FEATURE]: allow to set custom timeout for DMA Medusa +- [OPT]: set better timeout value for DMA Medusa + * Tue Dec 2 2025 Martin Spinler - 6.29.0-1 - [FEATURE] add rx_stream to nc_ifc_eth_map_info - [OPT] dma-calypte: optimize performance for throughput/latency (compatible just with version 2.0) diff --git a/VERSION b/VERSION index 94ae9e99..137f5acd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.29.0 +6.30.0 From 977b44b8b1091f6041f13d1adc8032902e9cc082 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 6 Feb 2026 15:45:50 +0100 Subject: [PATCH 460/518] fix(tools): use int type for getopt values --- tools/bus/bus.c | 2 +- tools/dma/dma.c | 2 +- tools/tsu/tsu.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/bus/bus.c b/tools/bus/bus.c index 817c44ee..7e35e8e6 100644 --- a/tools/bus/bus.c +++ b/tools/bus/bus.c @@ -112,7 +112,7 @@ int main(int argc, char *argv[]) int use_32b = 1; int index = 0; long count = 1; - char xc1, xc2; + int xc1, xc2; /* print newline each N bytes in read dword mode */ unsigned newline_span = 32; char spacer; diff --git a/tools/dma/dma.c b/tools/dma/dma.c index c4c26931..f08f8fc1 100644 --- a/tools/dma/dma.c +++ b/tools/dma/dma.c @@ -787,7 +787,7 @@ int main(int argc, char *argv[]) char *queries_index; int size; - char c; + int c; const char *file = nfb_default_dev_path(); const char *netdev_cmd = ""; diff --git a/tools/tsu/tsu.c b/tools/tsu/tsu.c index 58c22ba6..7a6af91f 100644 --- a/tools/tsu/tsu.c +++ b/tools/tsu/tsu.c @@ -429,7 +429,7 @@ void usage() int main(int argc, char *argv[]) { const char *path = nfb_default_dev_path(); - char c; + int c; long param; int index = 0; From 48bfe2b3ac4f1239acb67c11e0922c8d77ce1d8c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 6 Feb 2026 15:48:54 +0100 Subject: [PATCH 461/518] fix(libnfb): do not use optimized bus functions on unsupported platforms --- libnfb/src/bus/mi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libnfb/src/bus/mi.c b/libnfb/src/bus/mi.c index bd94b925..38762e14 100644 --- a/libnfb/src/bus/mi.c +++ b/libnfb/src/bus/mi.c @@ -159,8 +159,10 @@ int nfb_bus_open_mi(void *dev_priv, int bus_node, int comp_node, void **bus_priv __builtin_cpu_supports("avx") && __builtin_cpu_supports("avx2") && __builtin_cpu_supports("sse2") && +#else + 0 && #endif - 1 ) { + 1) { ops->read = nfb_bus_mi_read; ops->write = nfb_bus_mi_write; } From f2eb88cc0eb0d3f9a30bedd3a285202b10580216 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 6 Feb 2026 16:02:03 +0100 Subject: [PATCH 462/518] fix(mi): use splitted access on arm for 8B unaligned address access --- libnfb/include/netcope/mi.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libnfb/include/netcope/mi.h b/libnfb/include/netcope/mi.h index ab6ed9c3..5e7844f9 100644 --- a/libnfb/include/netcope/mi.h +++ b/libnfb/include/netcope/mi.h @@ -62,7 +62,17 @@ static inline bool nfb_bus_mi_memcopy_simple(void *dst, const void *src, size_t *(uint32_t *) dst = *(const uint32_t *) src; return true; } else if (nbyte == 8) { +#if defined(__arm__) || defined(__aarch64__) + if ((((uintptr_t)src) & 0x3F) == ((((uintptr_t)src) + 4) & 0x3F)) { + *(uint64_t *)dst = *(const uint64_t *)src; + } else { + /* Unaligned access */ + *(((uint32_t *)dst) + 0) = *(((const uint32_t *) src) + 0); + *(((uint32_t *)dst) + 1) = *(((const uint32_t *) src) + 1); + } +#else *(uint64_t *) dst = *(const uint64_t *) src; +#endif return true; } return false; From 049732c1ffa6d48628778bb56e18b941594f883e Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 6 Feb 2026 16:16:16 +0100 Subject: [PATCH 463/518] fix(drivers): support newer kernels with ida_simple_get replaced by ida_alloc --- drivers/configure.ac | 18 +++++++++++++++--- drivers/kernel/drivers/nfb/char.c | 10 +++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/configure.ac b/drivers/configure.ac index 70af1056..c9ad95b6 100644 --- a/drivers/configure.ac +++ b/drivers/configure.ac @@ -59,7 +59,7 @@ else $4 # result no fi echo '^^^^^^^^^^^^^^^^^^^^^^^^^^^^end test parallel^^^^^^^^^^^^^^^^^^^^^^^^^^^' >&AS_MESSAGE_LOG_FD -flock -u 200 +flock -u 200 # cleanup rm -rf .test${test_cnt}/ >/dev/null 2>/dev/null ) @@ -425,7 +425,7 @@ void test(void) { KERNEL_TRY_COMPILE([[ #include void test(void); -void test(void) { +void test(void) { struct bpf_redirect_info *ri; ri = bpf_net_ctx_get_ri(); } @@ -437,7 +437,7 @@ void test(void) { KERNEL_TRY_COMPILE([[ #include void test(void); -void test(void) { +void test(void) { xsk_buff_add_frag(NULL); } ]], @@ -445,6 +445,18 @@ void test(void) { [AC_DEFINE([CONFIG_HAVE_ONE_ARG_XSK_BUFF_ADD_FRAG], [1], [Define if kernel has one arg xsk_buff_add_frag]) AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) +KERNEL_TRY_COMPILE([[ +#include +void test(void); +void test(void) { + struct ida ida; + ida_simple_get(&ida, 0, 0, GFP_KERNEL); +} +]], +[AC_MSG_CHECKING([whether kernel has ida_simple_get])], +[AC_DEFINE([CONFIG_HAVE_IDA_SIMPLE_GET], [1], [Define if kernel has ida_simple_get]) AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + # wait for the jobs to finnish, remove file used for locking if it exists wait rm -rf flock_lockfile >/dev/null 2>/dev/null diff --git a/drivers/kernel/drivers/nfb/char.c b/drivers/kernel/drivers/nfb/char.c index e97ec4d3..ec3cf7ab 100644 --- a/drivers/kernel/drivers/nfb/char.c +++ b/drivers/kernel/drivers/nfb/char.c @@ -437,7 +437,11 @@ int nfb_char_create(struct nfb_device *nfb) { int ret = -ENOMEM; +#ifdef CONFIG_HAVE_IDA_SIMPLE_GET nfb->minor = ret = ida_simple_get(&nfb_minor, 0, NFB_CARD_COUNT_MAX, GFP_KERNEL); +#else + nfb->minor = ret = ida_alloc(&nfb_minor, GFP_KERNEL); +#endif if (nfb->minor < 0) { printk("NFB driver: unable to allocate new minor: %d\n", ret); goto err_ida_simple_get; @@ -445,7 +449,7 @@ int nfb_char_create(struct nfb_device *nfb) return 0; /* Error handling */ -// ida_simple_remove(&nfb_minor, nfb->minor); +// ida_free(&nfb_minor, nfb->minor); err_ida_simple_get: return ret; } @@ -478,7 +482,11 @@ int nfb_char_probe(struct nfb_device *nfb) void nfb_char_remove(struct nfb_device* nfb) { device_destroy(nfb_class, MKDEV(nfb_major, nfb->minor)); +#ifdef CONFIG_HAVE_IDA_SIMPLE_GET ida_simple_remove(&nfb_minor, nfb->minor); +#else + ida_free(&nfb_minor, nfb->minor); +#endif } /* From f891b4d308ba83650934df1926f61fce9f0b7595 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 6 Feb 2026 10:27:11 +0100 Subject: [PATCH 464/518] feat(libnetcope-rss): add defines for RSS hash function bits --- libnfb/include/netcope/nic_rss.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libnfb/include/netcope/nic_rss.h b/libnfb/include/netcope/nic_rss.h index f6ab32ff..b5b184e3 100644 --- a/libnfb/include/netcope/nic_rss.h +++ b/libnfb/include/netcope/nic_rss.h @@ -16,6 +16,27 @@ extern "C" { #define COMP_CESNET_NIC_RSS "cesnet,nic_rss" +#define NC_NIC_RSS_BIT(nr) (1 << (nr)) + +#define NC_NIC_RSS_HF_IPV4 NC_NIC_RSS_BIT(2) +#define NC_NIC_RSS_HF_FRAG_IPV4 NC_NIC_RSS_BIT(3) +#define NC_NIC_RSS_HF_NONFRAG_IPV4_TCP NC_NIC_RSS_BIT(4) +#define NC_NIC_RSS_HF_NONFRAG_IPV4_UDP NC_NIC_RSS_BIT(5) +#define NC_NIC_RSS_HF_NONFRAG_IPV4_SCTP NC_NIC_RSS_BIT(6) +#define NC_NIC_RSS_HF_NONFRAG_IPV4_OTHER NC_NIC_RSS_BIT(7) +#define NC_NIC_RSS_HF_IPV6 NC_NIC_RSS_BIT(8) +#define NC_NIC_RSS_HF_FRAG_IPV6 NC_NIC_RSS_BIT(9) +#define NC_NIC_RSS_HF_NONFRAG_IPV6_TCP NC_NIC_RSS_BIT(10) +#define NC_NIC_RSS_HF_NONFRAG_IPV6_UDP NC_NIC_RSS_BIT(11) +#define NC_NIC_RSS_HF_NONFRAG_IPV6_SCTP NC_NIC_RSS_BIT(12) +#define NC_NIC_RSS_HF_NONFRAG_IPV6_OTHER NC_NIC_RSS_BIT(13) +#define NC_NIC_RSS_HF_C_VLAN NC_NIC_RSS_BIT(26) +#define NC_NIC_RSS_HF_ESP NC_NIC_RSS_BIT(27) +#define NC_NIC_RSS_HF_AH NC_NIC_RSS_BIT(28) +#define NC_NIC_RSS_HF_L2TPV3 NC_NIC_RSS_BIT(29) +#define NC_NIC_RSS_HF_PFCP NC_NIC_RSS_BIT(30) +#define NC_NIC_RSS_HF_PPPOE NC_NIC_RSS_BIT(31) + struct nc_nic_rss { int reta_capacity; int key_size; @@ -100,7 +121,7 @@ static inline int nc_nic_rss_read_key(struct nc_nic_rss *rss, int channel, unsig return 0; } -static inline int nc_nic_rss_set_input(struct nc_nic_rss *rss, int channel, int fn) +static inline int nc_nic_rss_set_input(struct nc_nic_rss *rss, int channel, uint32_t fn) { struct nfb_comp *comp = nfb_user_to_comp(rss); uint32_t val = 0; @@ -117,7 +138,7 @@ static inline int nc_nic_rss_set_input(struct nc_nic_rss *rss, int channel, int return 0; } -static inline int nc_nic_rss_get_input(struct nc_nic_rss *rss, int channel, int *fn) +static inline int nc_nic_rss_get_input(struct nc_nic_rss *rss, int channel, uint32_t *fn) { struct nfb_comp *comp = nfb_user_to_comp(rss); uint32_t val = 0; From a49e772a5ef182ef90be22c09e64a326cbac2393 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 6 Feb 2026 17:18:19 +0100 Subject: [PATCH 465/518] chore: use 3rdparty version v6.30.0 --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index ed146f59..74724556 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ AUTOINSTALL=true # whether dependencies should be installed with '-y' RELTYPE=Release # Release type (Debug/Release) FILENAME_3RDPARTY="3rdparty.tar.gz" -SRC_3RDPARTY_VERSION="v6.28.4" +SRC_3RDPARTY_VERSION="v6.30.0" URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_VERSION/$FILENAME_3RDPARTY" EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" From 4ea57e995e8945f525dc4d764d9eedaa5b123ac8 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 6 Feb 2026 17:23:21 +0100 Subject: [PATCH 466/518] bump version to 6.30.1 --- Changelog | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 50315d8a..d0e5f73b 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +* Fri Feb 6 2026 Martin Spinler - 6.30.1-1 +- [FEATURE] drivers: add support for newer kernels +- [FIX] libnfb: do not use optimized bus functions on unsupported platforms + * Mon Jan 5 2026 Martin Spinler - 6.30.0-1 - [FEATURE]: add support for different varians of FB2CDG1 card - [FEATURE]: introduce support for BittWare IA-860m card diff --git a/VERSION b/VERSION index 137f5acd..306b5efd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.30.0 +6.30.1 From 3226e201ea734584f8a75e92ac6d82186dddffe2 Mon Sep 17 00:00:00 2001 From: David Vodak Date: Wed, 11 Feb 2026 12:57:02 +0100 Subject: [PATCH 467/518] feat(tool - boot): warn the user about invalid device tree file --- tools/boot/boot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/boot/boot.c b/tools/boot/boot.c index b3c0a1e5..0d6a11ac 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -110,6 +110,7 @@ int inject_fdt(const char *device, const char *dtb_filename, int flags) /* Read DTB */ f = fopen(dtb_filename, "r"); if (f == NULL) { + warnx("can't read device tree file"); ret = -ENOENT; goto err_dtb_open; } From bef4b58cf17d7a69a095935e0e42c3045246f303 Mon Sep 17 00:00:00 2001 From: Martin Pavelek Date: Mon, 15 Dec 2025 12:38:34 +0100 Subject: [PATCH 468/518] feat: enable recovery flash partition for Alveo UL3524 and X3522 --- drivers/kernel/drivers/nfb/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/pci.c b/drivers/kernel/drivers/nfb/pci.c index a8775dd7..1f2b0584 100644 --- a/drivers/kernel/drivers/nfb/pci.c +++ b/drivers/kernel/drivers/nfb/pci.c @@ -387,7 +387,8 @@ static int nfb_fdt_fixups(struct nfb_device *nfb) fdt_appendprop(fdt, node, "num_flash", &prop32, sizeof(prop32)); prop32 = cpu_to_fdt32(256 * 1024 * 1024); fdt_appendprop(fdt, node, "mtd_size", &prop32, sizeof(prop32)); - nfb_fdt_create_binary_slot(fdt, node, "image0", "application0" , 0, 0, 0, 0x01002000, 0x04000000); + nfb_fdt_create_binary_slot(fdt, node, "image1", "recovery" , 1, 0, 0, 0x01002000, 0x04000000); + nfb_fdt_create_binary_slot(fdt, node, "image0", "application0" , 0, 1, 0, 0x08000000, 0x04000000); nfb_fdt_create_boot_type(fdt, node, "SPI", 4); } else if (!strcmp(card_name, "NT200A02")) { From ee32411d2657b153e530e6cd3bc6a99af25c59b7 Mon Sep 17 00:00:00 2001 From: Vlastimil Kosar Date: Thu, 26 Feb 2026 20:49:18 +0100 Subject: [PATCH 469/518] fix(libnetcope-rss): use shifted channel ID --- libnfb/include/netcope/nic_rss.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnfb/include/netcope/nic_rss.h b/libnfb/include/netcope/nic_rss.h index b5b184e3..fc9d231c 100644 --- a/libnfb/include/netcope/nic_rss.h +++ b/libnfb/include/netcope/nic_rss.h @@ -131,7 +131,7 @@ static inline int nc_nic_rss_set_input(struct nc_nic_rss *rss, int channel, uint val |= channel << 16; - nfb_comp_write32(comp, 0x00, channel); + nfb_comp_write32(comp, 0x00, val); nfb_comp_write32(comp, 0x10, fn); nfb_comp_unlock(comp, 1); @@ -148,7 +148,7 @@ static inline int nc_nic_rss_get_input(struct nc_nic_rss *rss, int channel, uint val |= channel << 16; - nfb_comp_write32(comp, 0x00, channel); + nfb_comp_write32(comp, 0x00, val); val = nfb_comp_read32(comp, 0x10); if (fn) *fn = val; From 3a15d0cb969a38365e2606c5003513660928594c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 20 Mar 2026 14:07:03 +0100 Subject: [PATCH 470/518] fix(ndp_rx - calypte): fix valid_flag logic The problematic logic was switching the vld_flag every time when accessing to shadowed area, not just once at boundary. The check of valid_flag is not needed anymore, because is done in sync function. --- libnfb/include/netcope/ndp_rx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfb/include/netcope/ndp_rx.h b/libnfb/include/netcope/ndp_rx.h index 537dd2b9..0a745da8 100644 --- a/libnfb/include/netcope/ndp_rx.h +++ b/libnfb/include/netcope/ndp_rx.h @@ -340,7 +340,7 @@ static inline unsigned nc_ndp_v3_rx_burst_get(void *priv, struct ndp_packet *pac hdr = hdr_base + i; - if ((q->u.v3.shp + i) > q->u.v3.hdr_ptr_mask) { + if ((q->u.v3.shp + i) == (q->u.v3.hdr_ptr_mask + 1)) { vld_flag ^= 1; } From 467924a0c284a9cccd390a90947901086be82382 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 20 Mar 2026 14:45:46 +0100 Subject: [PATCH 471/518] fix(ndp - calypte tx): use memory barier between data and header write --- libnfb/include/netcope/ndp_tx.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index 54b2e1c8..bfc7b891 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -541,8 +541,9 @@ static inline int nc_ndp_v3_tx_burst_put(void *priv) nfb_comp_write(q->u.v3.tx_data_buff, q->u.v3.tx_pkts[i], hdr[i].frame_len, hdr[i].frame_ptr); q->u.v3.bytes_available -= frame_len_ceil; - - +#ifdef __KERNEL__ + wmb(); +#endif nfb_comp_write(q->u.v3.tx_hdr_buff, &hdr[i], 8, (uint64_t)shp*8); // This below line needs to updated somewhere shp = (shp + 1) & (q->u.v3.hdr_ptr_mask); From 44dc4fe8a1cd30dba27a7f8795f59af6748d32fc Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Fri, 13 Feb 2026 14:23:49 +0100 Subject: [PATCH 472/518] fix(libnetcope - mdio): rework E-tile PMA loopback Fix generating of random frames on channels 1-3 during resetting channel 0. --- libnfb/include/netcope/mdio.h | 151 ++++++++++++++++++++++++---------- 1 file changed, 106 insertions(+), 45 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 830a7d9c..83eecbaa 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -1155,38 +1155,105 @@ static inline void nc_mdio_etile_adapt_wait(struct nc_mdio *mdio, int prtad, int do { nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while (((ret & 0xff) != result) && (++retries < 100000)); + } while (((ret & 0xff) != result) && (++retries < 1000000)); +} + +/* Reload PMA settings (call PMA attribute sequencer) on all lanes */ +static inline void nc_mdio_etile_pma_reload(struct nc_mdio *mdio, int prtad) +{ + struct nfb_comp *comp = nfb_user_to_comp(mdio); + uint32_t ret; + int i; + int retries = 0; + + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_dmap_drp_write(comp, prtad, i+1, 0x91, 0x01); /* Load initial PMA configuration */ + do { + ret = nc_mdio_dmap_drp_read(comp, prtad, i+1, 0x91); /* Wait until the PMA is loaded */ + } while (((ret & 0x01) != 0x0) && (++retries < 100000)); + } } /* Perform PMA analog reset on selected lane and load initial configuration */ -static inline void nc_mdio_etile_areset(struct nfb_comp *comp, int prtad, int lane) +static inline void nc_mdio_etile_areset(struct nc_mdio *mdio, int prtad) { - const uint32_t DRP_PAGE = lane + 1; + uint32_t drp_page; + struct nfb_comp *comp = nfb_user_to_comp(mdio); uint32_t ret; int retries = 0; + int i; - /* See https://www.intel.com/content/www/us/en/docs/programmable/683723/current/pma-analog-reset-92001.html */ - /* See https://www.intel.com/content/www/us/en/docs/programmable/683723/current/reconfiguring-pma-settings.html */ - nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x200, 0x00); /* Write 0x200[7:0] = 0x00. */ - nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x201, 0x00); /* Write 0x201[7:0] = 0x00. */ - nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x202, 0x00); /* Write 0x202[7:0] = 0x00. */ - nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x203, 0x81); /* Write 0x203[7:0] = 0x81. */ - /* Read 0x207 until it becomes 0x80. This indicates that the operation completed successfully. */ - do { - ret = nc_mdio_dmap_drp_read(comp, prtad, DRP_PAGE, 0x207); /* Wait until the PMA is loaded */ - } while (((ret & 0xff) != 0x80) && (++retries < 100000)); - /* Reload PMA settings (call PMA attribute sequencer) on all lanes */ - retries = 0; - nc_mdio_dmap_drp_write(comp, prtad, DRP_PAGE, 0x91, 0x01); /* Load initial PMA configuration */ - do { - ret = nc_mdio_dmap_drp_read(comp, prtad, DRP_PAGE, 0x91); /* Wait until the PMA is loaded */ - } while (((ret & 0x01) != 0x0) && (++retries < 100000)); + for (i = 0; i < mdio->pma_lanes; i++) { + drp_page = i + 1; + /* See https://www.intel.com/content/www/us/en/docs/programmable/683723/current/pma-analog-reset-92001.html */ + /* See https://www.intel.com/content/www/us/en/docs/programmable/683723/current/reconfiguring-pma-settings.html */ + nc_mdio_dmap_drp_write(comp, prtad, drp_page, 0x200, 0x00); /* Write 0x200[7:0] = 0x00. */ + nc_mdio_dmap_drp_write(comp, prtad, drp_page, 0x201, 0x00); /* Write 0x201[7:0] = 0x00. */ + nc_mdio_dmap_drp_write(comp, prtad, drp_page, 0x202, 0x00); /* Write 0x202[7:0] = 0x00. */ + nc_mdio_dmap_drp_write(comp, prtad, drp_page, 0x203, 0x81); /* Write 0x203[7:0] = 0x81. */ + /* Read 0x207 until it becomes 0x80. This indicates that the operation completed successfully. */ + do { + ret = nc_mdio_dmap_drp_read(comp, prtad, drp_page, 0x207); /* Wait until the PMA is loaded */ + } while (((ret & 0xff) != 0x80) && (++retries < 100000)); + /* Reload PMA settings (call PMA attribute sequencer) */ + nc_mdio_etile_pma_reload(mdio, prtad); + } } -static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) +/* Perform E-Tile PMA eq reset on all lanes */ +/* See https://docs.altera.com/r/LEDjdyYU7FsuGYiol85v1g/IRveQVjlH8J4wwpJ6PwiWg */ +static inline void nc_mdio_etile_eq_reset(struct nc_mdio *mdio, int prtad) { - /* See https://www.intel.com/content/www/us/en/docs/programmable/683468/23-2/ethernet-adaptation-flow-with-non-external.html */ int i; + for (i = 0; i < mdio->pma_lanes; i++) { + /* Reset the receiver (RX) tuning DFE taps */ + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x000a, 0xffff); + /* Reset RF_P2, RF_P1, and RF_P0 to default values. */ + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x002c, 0x0d00); + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x006c, 0x0000); + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x002c, 0x0d01); + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x006c, 0x0000); + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x002c, 0x0d02); + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x006c, 0x0000); + } +} + +/* Enable E-tile PMA loopback and perform the initial adaptation */ +static inline void nc_mdio_etile_loopback_enable(struct nc_mdio *mdio, int prtad) +{ + int i; + /* Enable loopback and start the initial adaptation on all channels */ + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0301); /* Enable the loopback */ + nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL); + } + /* Check adaptation status on all channels */ + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80); + } +} + +/* Bring the E-Tile PMA into the mission (non-loopback) mode */ +static inline void nc_mdio_etile_mission_mode(struct nc_mdio *mdio, int prtad) +{ + int i; + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0300); /* Disable the loopback */ + nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL); /* Start the initial adaptation */ + } + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80); /* Check initial adaptation status */ + nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_CONTINUOUS); /* Start the continuous adaptation */ + } + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_adapt_wait(mdio, prtad, i, 0xE2); /* Check continuous adaptation status */ + } +} + +/* Enable/disable E-Tile PMA loopback and initialize the link */ +/* See https://docs.altera.com/r/docs/683468/23.2/e-tile-hard-ip-user-guide-e-tile-hard-ip-for-ethernet-and-e-tile-cpri-phy-ips/ethernet-adaptation-flow-with-non-external-aib-clocking */ +static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) +{ struct nfb_comp *comp = nfb_user_to_comp(mdio); int retries = 0; uint32_t ret; @@ -1198,9 +1265,8 @@ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prt /* 1. Assert RX/TX reset ports of the EHIP */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // soft rx rst + soft tx rst /* 2 + 3. Trigger PMA analog reset and reload PMA settings */ - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_areset(comp, prtad, i); - } + /* Note: to avoid PMA reset which disturbs all channels in the quad, EQ reset is performed instead */ + nc_mdio_etile_eq_reset(mdio, prtad); /* 4. Apply CSR reset */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x7); // eio_sys_rst set nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // eio_sys_rst clear @@ -1209,33 +1275,28 @@ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prt /* 5b. Wait for TX ready */ do { ret = nc_mdio_dmap_drp_read(comp, prtad, 0, 0x322); - } while (((ret & 0x01) != 0x1) && (++retries < 100000)); + } while (((ret & 0x01) != 0x1) && (++retries < 1000000)); /* 6. skipped (PMA configuration not used) */ - /* 7a. Enable loopback and start the initial adaptation on all channels */ - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0301); /* Enable the loopback */ - nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL); - } - /* 7b. Check adaptation status on all channels */ - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80); - } + /* 7. Enable loopback (and perform the adaptation) */ + nc_mdio_etile_loopback_enable(mdio, prtad); /* 8-11. In mission mode, run the initial and continuous equalization */ if (!enable) { - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0300); /* Disable the loopback */ - nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL); /* Start the initial adaptation */ - } - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80); /* Check initial adaptation status */ - nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_CONTINUOUS); /* Start the continuous adaptation */ - } - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_adapt_wait(mdio, prtad, i, 0xE2); /* Check continuous adaptation status */ - } + nc_mdio_etile_mission_mode(mdio, prtad); } /* 12. Deassert RX reset ports of the EHIP (using mgmt) */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x0); + /* Check RX status and restore PMA configuration, if the link is still down in loopback mode */ + if (enable) { + retries = 0; + do { + ret = nc_mdio_dmap_drp_read(comp, prtad, 0, 0x326); + } while (((ret & 0x01) != 0x1) && (++retries < 100000)); + if ((ret & 0x01) == 0x0) { + /* RX still not ready - reload the PMA configuration */ + nc_mdio_etile_pma_reload(mdio, prtad); + nc_mdio_etile_loopback_enable(mdio, prtad); + } + } /* Get current PMA mode from mgmt */ ret = mdio->mdio_read(comp, prtad, 1, 7); /* Apply the mode (turn the RS-FEC on or off) */ From 531a7241941a00600c9aa106806fc3174869ec79 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 27 Mar 2026 07:55:40 +0100 Subject: [PATCH 473/518] feat(driver - net): add net_rx_thread_nodata_check_interval_us module parameter --- drivers/kernel/drivers/nfb/ndp_netdev/core.c | 5 ++++- drivers/kernel/drivers/nfb/net/device.c | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/kernel/drivers/nfb/ndp_netdev/core.c b/drivers/kernel/drivers/nfb/ndp_netdev/core.c index f61e51d3..087b60ce 100644 --- a/drivers/kernel/drivers/nfb/ndp_netdev/core.c +++ b/drivers/kernel/drivers/nfb/ndp_netdev/core.c @@ -28,6 +28,8 @@ static bool ndp_netdev_enable = 0; static bool ndp_netdev_carrier = 0; +extern unsigned int net_rx_thread_nodata_check_interval_us; + /** * nfb_ndp_netdev_rx_thread - thread function for receiving data, works in a poll mode @@ -53,7 +55,8 @@ static int nfb_ndp_netdev_rx_thread(void *data) /* no new data, sleep and then try again */ if (cnt == 0) { - usleep_range(995, 1005); + usleep_range(net_rx_thread_nodata_check_interval_us+1, + net_rx_thread_nodata_check_interval_us+2); continue; } diff --git a/drivers/kernel/drivers/nfb/net/device.c b/drivers/kernel/drivers/nfb/net/device.c index 6d570c4f..eb849ab3 100644 --- a/drivers/kernel/drivers/nfb/net/device.c +++ b/drivers/kernel/drivers/nfb/net/device.c @@ -65,6 +65,10 @@ static int net_txqs_offset = 0; module_param(net_txqs_offset, int, S_IRUGO); MODULE_PARM_DESC(net_txqs_offset, "Default TX DMA queues offset [0]"); +unsigned int net_rx_thread_nodata_check_interval_us = 1000; +module_param(net_rx_thread_nodata_check_interval_us, uint, S_IRUGO); +MODULE_PARM_DESC(net_rx_thread_nodata_check_interval_us, "Default TX DMA queues offset [1000]us"); + static void nfb_net_link_status(struct net_device *netdev) { @@ -425,7 +429,8 @@ static int nfb_net_rx_thread(void *rxqptr) // If no data, sleep and try again if (received == 0) { - usleep_range(995, 1005); + usleep_range(net_rx_thread_nodata_check_interval_us+1, + net_rx_thread_nodata_check_interval_us+2); continue; } From d572c0a089a519ba5a7b09716a86c1894c43762f Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 27 Mar 2026 08:14:34 +0100 Subject: [PATCH 474/518] bump version to 6.30.2 --- Changelog | 8 ++++++++ VERSION | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index d0e5f73b..cfa5ec33 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,11 @@ +* Fri Mar 27 2026 Martin Spinler - 6.30.2-1 +- [FEATURE] Alveo UL3524 and X3522: enable recovery flash partition +- [FEATURE] netdev: add net_rx_thread_nodata_check_interval_us module parameter +- [FIX] dma-calypte: use memory barier between data and header write +- [FIX] dma-calypte: fix valid_flag logic +- [FIX] mdio: rework E-tile PMA loopback +- [FIX] libnetcope-rss: use shifted channel ID + * Fri Feb 6 2026 Martin Spinler - 6.30.1-1 - [FEATURE] drivers: add support for newer kernels - [FIX] libnfb: do not use optimized bus functions on unsupported platforms diff --git a/VERSION b/VERSION index 306b5efd..79418097 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.30.1 +6.30.2 From 62467bb0e3205b601de003e7a68c9b5c91f0cd9d Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Wed, 1 Apr 2026 15:38:53 +0200 Subject: [PATCH 475/518] chore(libnetcope - mdio): introduce the _drp_wait_until() A utility function to make the code more readable. --- libnfb/include/netcope/mdio.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 83eecbaa..a1f92a49 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -1035,13 +1035,27 @@ static inline uint16_t nc_mdio_etile_pma_attribute_read(struct nc_mdio *mdio, in return rcode; } +/* Wait until the value of the "reg" register reaches "val". DRP page 0 only! */ +static inline int _drp_wait_until(struct nfb_comp *comp, int prtad, uint32_t reg, uint32_t mask, uint32_t val, int max_retries) +{ + uint32_t ret; + int retries = 0; + do { + ret = nc_mdio_dmap_drp_read(comp, prtad, 0, reg); // read the requested DRP register + } while (((ret & mask) != val) && (++retries < max_retries)); + return (ret & mask) == val; +} + /* Perform RX+TX reset of E-tile Ethernet PHY */ static inline void nc_mdio_etile_reset(struct nfb_comp *comp, int prtad) { /* see https://www.intel.com/content/www/us/en/docs/programmable/683468/23-2/phy-configuration.html */ /* see https://www.intel.com/content/www/us/en/docs/programmable/683468/23-2/reset.html */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // soft rx rst + soft tx rst + _drp_wait_until(comp, prtad, 0x32c, 0x6, 0x6, 100000); /* Wait until bits[2:1] of 0x32c -> 0x06 */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x0); + _drp_wait_until(comp, prtad, 0x32c, 0x3f, 0, 100000); /* Wait until bits[5:0] of 0x32c -> 0x00 */ + } static inline void nc_mdio_etile_rsfec_off(struct nfb_comp *comp, int prtad, int lanes) @@ -1273,9 +1287,7 @@ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prt /* 5a. Deassert TX reset */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x4); // soft rx rst only /* 5b. Wait for TX ready */ - do { - ret = nc_mdio_dmap_drp_read(comp, prtad, 0, 0x322); - } while (((ret & 0x01) != 0x1) && (++retries < 1000000)); + _drp_wait_until(comp, prtad, 0x322, 0x01, 1, 1000000); /* Wait until bit[0] of 0x322 becomes 1 */ /* 6. skipped (PMA configuration not used) */ /* 7. Enable loopback (and perform the adaptation) */ nc_mdio_etile_loopback_enable(mdio, prtad); From fa2384605211695ef753be469e84f7c33ad858d6 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Wed, 1 Apr 2026 15:51:22 +0200 Subject: [PATCH 476/518] fix(libnetcope - mdio): wait for the resets to take effect while configuring the e-tile loopback --- libnfb/include/netcope/mdio.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index a1f92a49..ee30d1c1 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -1278,14 +1278,20 @@ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prt /* 1. Assert RX/TX reset ports of the EHIP */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // soft rx rst + soft tx rst + _drp_wait_until(comp, prtad, 0x32c, 0x6, 0x6, 100000); /* Wait until bits[2:1] of 0x32c becomes 0x06 */ /* 2 + 3. Trigger PMA analog reset and reload PMA settings */ /* Note: to avoid PMA reset which disturbs all channels in the quad, EQ reset is performed instead */ nc_mdio_etile_eq_reset(mdio, prtad); /* 4. Apply CSR reset */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x7); // eio_sys_rst set nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // eio_sys_rst clear + /* Wait until the reset sequence starts */ + _drp_wait_until(comp, prtad, 0x32c, 0x01, 1, 10000); /* Wait until bit[0] of 0x32c becomes 1 */ + /* Wait until the reset sequence finishes */ + _drp_wait_until(comp, prtad, 0x32c, 0x01, 0, 100000); /* Wait until bit[0] of 0x32c becomes 0 */ /* 5a. Deassert TX reset */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x4); // soft rx rst only + _drp_wait_until(comp, prtad, 0x32c, 0x12, 0, 1000000); /* Wait until bits[4,1] of 0x32c become 0 */ /* 5b. Wait for TX ready */ _drp_wait_until(comp, prtad, 0x322, 0x01, 1, 1000000); /* Wait until bit[0] of 0x322 becomes 1 */ /* 6. skipped (PMA configuration not used) */ @@ -1297,6 +1303,7 @@ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prt } /* 12. Deassert RX reset ports of the EHIP (using mgmt) */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x0); + _drp_wait_until(comp, prtad, 0x32c, 0x3f, 0, 100000); /* Wait until bits[5:0] of 0x32c -> 0x00 */ /* Check RX status and restore PMA configuration, if the link is still down in loopback mode */ if (enable) { retries = 0; From 76fb2b1b28e854d142c89db2e37da4adfc74e1cc Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Wed, 1 Apr 2026 16:03:53 +0200 Subject: [PATCH 477/518] feat(libnetcope - mdio): recover the link when turning on loopback on e-tile Perform hard reset of the e-tile Eth block and retry the loopback setting process, if the link doesn't start. --- libnfb/include/netcope/mdio.h | 41 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index ee30d1c1..9d500d39 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -1264,6 +1264,24 @@ static inline void nc_mdio_etile_mission_mode(struct nc_mdio *mdio, int prtad) } } +/* Performs Eth system reset */ +static inline void nc_mdio_etile_eth_sysrst(struct nc_mdio *mdio, int prtad) +{ + int i; + struct nfb_comp *comp = nfb_user_to_comp(mdio); + + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0011, 0x0003); /* Recalibrate the PMA on next enable */ + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0001, 0x0000); /* Disable the PMA */ + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0001, 0x0007); /* Enable the PMA */ + } + nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x7); // eio_sys_rst set + /* Wait until the reset sequence starts */ + _drp_wait_until(comp, prtad, 0x32c, 0x01, 1, 10000); /* Wait until bit[0] of 0x32c becomes 1 */ + /* Wait until the reset sequence finishes */ + _drp_wait_until(comp, prtad, 0x32c, 0x01, 0, 100000); /* Wait until bit[0] of 0x32c -> 0 */ +} + /* Enable/disable E-Tile PMA loopback and initialize the link */ /* See https://docs.altera.com/r/docs/683468/23.2/e-tile-hard-ip-user-guide-e-tile-hard-ip-for-ethernet-and-e-tile-cpri-phy-ips/ethernet-adaptation-flow-with-non-external-aib-clocking */ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) @@ -1271,11 +1289,12 @@ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prt struct nfb_comp *comp = nfb_user_to_comp(mdio); int retries = 0; uint32_t ret; + uint32_t status_reg = (mdio->rsfec_supported ? 0x329 : 0x326); /* RX status register */ /* Lock access to PCS registers (reset active) */ if (!nfb_comp_lock(comp, ATTR_IFC)) return -EAGAIN; - +retry: /* 1. Assert RX/TX reset ports of the EHIP */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // soft rx rst + soft tx rst _drp_wait_until(comp, prtad, 0x32c, 0x6, 0x6, 100000); /* Wait until bits[2:1] of 0x32c becomes 0x06 */ @@ -1304,22 +1323,18 @@ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prt /* 12. Deassert RX reset ports of the EHIP (using mgmt) */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x0); _drp_wait_until(comp, prtad, 0x32c, 0x3f, 0, 100000); /* Wait until bits[5:0] of 0x32c -> 0x00 */ - /* Check RX status and restore PMA configuration, if the link is still down in loopback mode */ - if (enable) { - retries = 0; - do { - ret = nc_mdio_dmap_drp_read(comp, prtad, 0, 0x326); - } while (((ret & 0x01) != 0x1) && (++retries < 100000)); - if ((ret & 0x01) == 0x0) { - /* RX still not ready - reload the PMA configuration */ - nc_mdio_etile_pma_reload(mdio, prtad); - nc_mdio_etile_loopback_enable(mdio, prtad); - } - } /* Get current PMA mode from mgmt */ ret = mdio->mdio_read(comp, prtad, 1, 7); /* Apply the mode (turn the RS-FEC on or off) */ nc_mdio_fixup_etile_set_mode(mdio, prtad, ret); + /* In the loopback mode, check link status and retry the process, if the link is still down */ + if (enable && (++retries < 3)) { + if (!_drp_wait_until(comp, prtad, status_reg, 0x01, 1, 1000000)) { + /* RX still not ready - perform hard reset and retry */ + nc_mdio_etile_eth_sysrst(mdio, prtad); + goto retry; + } + } nfb_comp_unlock(comp, PCS_IFC); return 0; } From b0505ff421819a29de9f85cd05406a560adc1db5 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 7 Apr 2026 11:05:45 +0200 Subject: [PATCH 478/518] bump version to 6.30.3 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index cfa5ec33..faf75f46 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Wed Apr 7 2026 Martin Spinler - 6.30.3-1 +- [FIX] mdio: fix E-tile PMA loopback on 100G + * Fri Mar 27 2026 Martin Spinler - 6.30.2-1 - [FEATURE] Alveo UL3524 and X3522: enable recovery flash partition - [FEATURE] netdev: add net_rx_thread_nodata_check_interval_us module parameter diff --git a/VERSION b/VERSION index 79418097..6c4bf5b4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.30.2 +6.30.3 From ec9634f6986a72aa7cfa3b59e93af78549f4d734 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 22 Apr 2026 16:22:26 +0200 Subject: [PATCH 479/518] fix(libnfb_ext_python): use 'with gil' in callback functions (ext_ops) --- .../nfb/ext/python/ext_entry.c | 15 ++++++-- ext/libnfb_ext_python/nfb/ext/python/shim.pxd | 30 ++++++++-------- ext/libnfb_ext_python/nfb/ext/python/shim.pyx | 34 +++++++++---------- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/ext/libnfb_ext_python/nfb/ext/python/ext_entry.c b/ext/libnfb_ext_python/nfb/ext/python/ext_entry.c index 2695a91d..e93eb2c5 100644 --- a/ext/libnfb_ext_python/nfb/ext/python/ext_entry.c +++ b/ext/libnfb_ext_python/nfb/ext/python/ext_entry.c @@ -12,8 +12,17 @@ struct libnfb_ext_abi_version libnfb_ext_abi_version = libnfb_ext_abi_version_cu int libnfb_ext_get_ops(const char *devname, struct libnfb_ext_ops *ops) { - if (import_shim()) - return 0; + int ret; + PyGILState_STATE gstate = PyGILState_Ensure(); - return pynfb_ext_get_ops(devname, ops); + ret = import_shim(); + if (ret) { + ret = -EBADFD; + goto out; + } + + ret = pynfb_ext_get_ops(devname, ops); +out: + PyGILState_Release(gstate); + return ret; } diff --git a/ext/libnfb_ext_python/nfb/ext/python/shim.pxd b/ext/libnfb_ext_python/nfb/ext/python/shim.pxd index 416224f5..0be2a7a9 100644 --- a/ext/libnfb_ext_python/nfb/ext/python/shim.pxd +++ b/ext/libnfb_ext_python/nfb/ext/python/shim.pxd @@ -98,24 +98,24 @@ cdef extern from "": cdef public api: int pynfb_ext_get_ops(const char *devname, libnfb_ext_ops* ops) noexcept - int nfb_ext_python_open(const char *devname, int oflag, void **priv, void **fdt) noexcept - void nfb_ext_python_close(void *priv) noexcept + int nfb_ext_python_open(const char *devname, int oflag, void **priv, void **fdt) noexcept with gil + void nfb_ext_python_close(void *priv) noexcept with gil - int nfb_pynfb_bus_open(void *dev_priv, int bus_node, int comp_node, void ** bus_priv, libnfb_bus_ext_ops* ops) noexcept - void nfb_pynfb_bus_close(void *bus_priv) noexcept + int nfb_pynfb_bus_open(void *dev_priv, int bus_node, int comp_node, void ** bus_priv, libnfb_bus_ext_ops* ops) noexcept with gil + void nfb_pynfb_bus_close(void *bus_priv) noexcept with gil - ssize_t nfb_pynfb_bus_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) noexcept - ssize_t nfb_pynfb_bus_write(void *bus_priv, const void *buf, size_t nbyte, off_t offset) noexcept + ssize_t nfb_pynfb_bus_read(void *bus_priv, void *buf, size_t nbyte, off_t offset) noexcept with gil + ssize_t nfb_pynfb_bus_write(void *bus_priv, const void *buf, size_t nbyte, off_t offset) noexcept with gil - cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq) noexcept - cdef int nfb_pyndp_queue_close(ndp_queue *q) noexcept + cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq) noexcept with gil + cdef int nfb_pyndp_queue_close(ndp_queue *q) noexcept with gil - cdef int pyndp_start(void *priv) - cdef int pyndp_stop(void *priv) + cdef int pyndp_start(void *priv) with gil + cdef int pyndp_stop(void *priv) with gil - cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count) - cdef int pyndp_rx_burst_put(void *priv) + cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count) with gil + cdef int pyndp_rx_burst_put(void *priv) with gil - cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count) - cdef int pyndp_tx_burst_put(void *priv) - cdef int pyndp_tx_burst_flush(void *priv) + cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count) with gil + cdef int pyndp_tx_burst_put(void *priv) with gil + cdef int pyndp_tx_burst_flush(void *priv) with gil diff --git a/ext/libnfb_ext_python/nfb/ext/python/shim.pyx b/ext/libnfb_ext_python/nfb/ext/python/shim.pyx index db9791cf..61b3930e 100644 --- a/ext/libnfb_ext_python/nfb/ext/python/shim.pyx +++ b/ext/libnfb_ext_python/nfb/ext/python/shim.pyx @@ -12,7 +12,7 @@ cdef class __NfbWrapper: cdef object nfb cdef list bus -cdef int nfb_ext_python_open(const char *devname, int oflag, void **priv, void **fdt) noexcept: +cdef int nfb_ext_python_open(const char *devname, int oflag, void **priv, void **fdt) noexcept with gil: cdef int ret cdef uint64_t addr cdef object nfb @@ -43,7 +43,7 @@ cdef int nfb_ext_python_open(const char *devname, int oflag, void **priv, void * return 0 -cdef void nfb_ext_python_close(void *priv) noexcept: +cdef void nfb_ext_python_close(void *priv) noexcept with gil: cdef PyObject* _wrap cdef __NfbWrapper wrap cdef object nfb @@ -56,7 +56,7 @@ cdef void nfb_ext_python_close(void *priv) noexcept: #free(wrap.fdt) Py_DECREF(wrap) -cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset) noexcept: +cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset) noexcept with gil: cdef PyObject* _bus = p cdef object bus = _bus cdef bytes data @@ -73,7 +73,7 @@ cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset) return ret -cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t offset) noexcept: +cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t offset) noexcept with gil: cdef PyObject* _bus = p cdef object bus = _bus cdef const char* c_data = buf @@ -84,7 +84,7 @@ cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t o return nbyte -cdef int nfb_pynfb_bus_open(void *dev_priv, int bus_offset, int comp_offset, void ** bus_priv, libnfb_bus_ext_ops* ops) noexcept: +cdef int nfb_pynfb_bus_open(void *dev_priv, int bus_offset, int comp_offset, void ** bus_priv, libnfb_bus_ext_ops* ops) noexcept with gil: cdef PyObject* _wrap = dev_priv cdef __NfbWrapper wrap = _wrap @@ -116,7 +116,7 @@ cdef int nfb_pynfb_bus_open(void *dev_priv, int bus_offset, int comp_offset, voi return 0 -cdef void nfb_pynfb_bus_close(void *priv) noexcept: +cdef void nfb_pynfb_bus_close(void *priv) noexcept with gil: cdef PyObject* _bus = priv cdef object bus = _bus @@ -124,7 +124,7 @@ cdef void nfb_pynfb_bus_close(void *priv) noexcept: # NDP functions -cdef int pyndp_start(void *priv) noexcept: +cdef int pyndp_start(void *priv) noexcept with gil: cdef object t = priv queue, temp = t @@ -132,7 +132,7 @@ cdef int pyndp_start(void *priv) noexcept: return 0 -cdef int pyndp_stop(void *priv) noexcept: +cdef int pyndp_stop(void *priv) noexcept with gil: cdef object t = priv queue, temp = t @@ -140,7 +140,7 @@ cdef int pyndp_stop(void *priv) noexcept: return 0 -cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count) noexcept: +cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count) noexcept with gil: cdef object t = priv cdef uint8_t* c_data @@ -163,7 +163,7 @@ cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count return cnt -cdef int pyndp_rx_burst_put(void *priv) noexcept: +cdef int pyndp_rx_burst_put(void *priv) noexcept with gil: cdef object t = priv queue, temp = t @@ -171,7 +171,7 @@ cdef int pyndp_rx_burst_put(void *priv) noexcept: return 0 -cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count) noexcept: +cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count) noexcept with gil: cdef object t = priv queue, temp = t @@ -190,7 +190,7 @@ cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count return len(prep) -cdef int pyndp_tx_burst_put(void *priv) noexcept: +cdef int pyndp_tx_burst_put(void *priv) noexcept with gil: cdef object t = priv queue, temp = t @@ -198,7 +198,7 @@ cdef int pyndp_tx_burst_put(void *priv) noexcept: return 0 -cdef int pyndp_tx_burst_flush(void *priv) noexcept: +cdef int pyndp_tx_burst_flush(void *priv) noexcept with gil: cdef object t = priv queue, temp = t @@ -206,7 +206,7 @@ cdef int pyndp_tx_burst_flush(void *priv) noexcept: return 0 -cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq) noexcept: +cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, int dir, int flags, ndp_queue ** pq) noexcept with gil: cdef PyObject* _wrap = dev_priv cdef __NfbWrapper wrap = _wrap @@ -246,18 +246,18 @@ cdef int nfb_pyndp_queue_open(nfb_device *dev, void *dev_priv, unsigned index, i return 0 -cdef int nfb_pyndp_queue_close(ndp_queue *q) noexcept: +cdef int nfb_pyndp_queue_close(ndp_queue *q) noexcept with gil: cdef object t = ndp_queue_get_priv(q) queue, temp = t Py_DECREF(t) return 0 -cdef int nfb_pynfb_comp_lock(const nfb_comp *comp, uint32_t features) noexcept: +cdef int nfb_pynfb_comp_lock(const nfb_comp *comp, uint32_t features) noexcept with gil: # TODO return 1; -cdef void nfb_pynfb_comp_unlock(const nfb_comp *comp, uint32_t features) noexcept: +cdef void nfb_pynfb_comp_unlock(const nfb_comp *comp, uint32_t features) noexcept with gil: pass cdef int pynfb_ext_get_ops(const char *devname, libnfb_ext_ops* ops) noexcept: From 1b4d069accc698fb8ccf6d993219a0634f680577 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 22 Apr 2026 16:24:00 +0200 Subject: [PATCH 480/518] feat(pynfb): add handle (CContextNfbDeviceHandle) attribute to Nfb --- pynfb/nfb/libnfb.pyx | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pynfb/nfb/libnfb.pyx b/pynfb/nfb/libnfb.pyx index 678603ed..ccc0be0a 100644 --- a/pynfb/nfb/libnfb.pyx +++ b/pynfb/nfb/libnfb.pyx @@ -6,7 +6,7 @@ from itertools import islice from typing import Union, Optional, List, Tuple, Iterable from libc.stdlib cimport malloc -from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int32_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int32_t, uintptr_t from libcpp cimport bool from libc.errno cimport EBUSY, ETIMEDOUT, EAGAIN @@ -69,6 +69,30 @@ cdef class NfbDeviceHandle: self._close_cbs.append(cb) +cdef class CContextNfbDeviceHandle: + cdef NfbDeviceHandle _nfb_dev + cdef int _inside_ctx + + def __cinit__(self, Nfb nfb_dev): + self._nfb_dev = nfb_dev._handle + self._nfb_dev.check_handle() + self._inside_ctx = 0 + self._nfb_dev.add_close_cb(self._close_handle_cb) + + def _close_handle_cb(self): + if self._inside_ctx != 0: + # Context was active when the nfb_close happend + raise ReferenceError + + def __enter__(self) -> uintptr_t: + self._nfb_dev.check_handle() + self._inside_ctx += 1 + return self._nfb_dev._dev + + def __exit__(self, *exc): + self._inside_ctx -= 1 + + cdef class Nfb: """ Nfb class instance represents handle to NFB device in system @@ -103,6 +127,8 @@ cdef class Nfb: # TODO: use Nfb.dma only for statistic, not for transfers self.dma = self.ndp + self.libnfb_handle = CContextNfbDeviceHandle(self) + def __enter__(self): self._handle.check_handle() return self From c50c09465ab266f83cf48d0b81fdb26a8c8fb4c9 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 25 May 2026 08:58:16 +0200 Subject: [PATCH 481/518] fix(drivers): support newer kernels --- build.sh | 2 +- drivers/kernel/drivers/nfb/Makefile | 2 -- drivers/kernel/drivers/nfb/boot/nfb-spi.c | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index 74724556..8cb7e365 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ AUTOINSTALL=true # whether dependencies should be installed with '-y' RELTYPE=Release # Release type (Debug/Release) FILENAME_3RDPARTY="3rdparty.tar.gz" -SRC_3RDPARTY_VERSION="v6.30.0" +SRC_3RDPARTY_VERSION="v6.30.4" URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_VERSION/$FILENAME_3RDPARTY" EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" diff --git a/drivers/kernel/drivers/nfb/Makefile b/drivers/kernel/drivers/nfb/Makefile index b88fb8ef..89e4cdde 100644 --- a/drivers/kernel/drivers/nfb/Makefile +++ b/drivers/kernel/drivers/nfb/Makefile @@ -20,9 +20,7 @@ nfb-y += mi/mi.o nfb-y += ndp/ctrl.o ndp/ctrl_ndp.o ndp/channel.o ndp/subscription.o ndp/subscriber.o ndp/ring.o ndp/char.o ndp/driver.o ndp/kndp.o nfb-y += ndp_netdev/core.o nfb-y += boot/flash.o boot/reload.o boot/boot.o boot/gecko.o boot/sdm.o boot/bw-bmc.o -ifndef CONFIG_REGMAP_SPI_AVMM nfb-y += ../base/regmap/regmap-spi-avmm.o -endif ifndef CONFIG_SPI_ALTERA_CORE nfb-y += ../spi/spi-altera-core.o endif diff --git a/drivers/kernel/drivers/nfb/boot/nfb-spi.c b/drivers/kernel/drivers/nfb/boot/nfb-spi.c index 643eb946..9b9d5502 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-spi.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-spi.c @@ -48,7 +48,7 @@ #include #include "../../spi/altera.h" -#include "../../base/regmap/regmap.h" +#include "../../base/regmap/nfb_regmap.h" #include "nfb-spi.h" @@ -279,7 +279,7 @@ int nfb_spi_attach(struct nfb_boot *boot) __func__, board_info.modalias); } - m10bmc_spi->m10bmc.regmap = devm_regmap_init_spi_avmm(spi_dev, &m10bmc_spi_regmap_config); + m10bmc_spi->m10bmc.regmap = nfb_devm_regmap_init_spi_avmm(spi_dev, &m10bmc_spi_regmap_config); if (IS_ERR(m10bmc_spi->m10bmc.regmap)) { ret = PTR_ERR(m10bmc_spi->m10bmc.regmap); dev_err(&m10bmc_spi->pd->dev, "%s Failed to allocate regmap: %d\n", __func__, ret); From 55b6436d1310dfc6bc4f0ab7cc45e3dba91c4279 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 25 May 2026 14:51:54 +0200 Subject: [PATCH 482/518] bump version to 6.30.4 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6c4bf5b4..ae24c904 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.30.3 +6.30.4 From ac6d5a3657a1d1b3236792b423597904d0be92ac Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Tue, 23 Jun 2026 11:46:38 +0200 Subject: [PATCH 483/518] feat(python): add distribution files --- ext/libnfb_ext_grpc/python/LICENSE | 29 ++++++++ ext/libnfb_ext_grpc/python/MANIFEST.in | 2 +- .../python/nfb/ext/protobuf/__init__.py | 0 .../python/nfb/ext/protobuf/v1/__init__.py | 0 ext/libnfb_ext_grpc/python/pyproject.toml | 35 +++++++--- ext/libnfb_ext_grpc/python/readme.md | 31 +++++++++ ext/libnfb_ext_grpc/python/setup.py | 27 +++++++- ext/libnfb_ext_python/LICENSE | 29 ++++++++ ext/libnfb_ext_python/MANIFEST.in | 3 + ext/libnfb_ext_python/pyproject.toml | 31 +++++++++ pynfb/LICENSE | 29 ++++++++ pynfb/MANIFEST.in | 3 + pynfb/README.md | 66 +++++++++++++++++++ pynfb/pyproject.toml | 31 +++++++++ 14 files changed, 306 insertions(+), 10 deletions(-) create mode 100644 ext/libnfb_ext_grpc/python/LICENSE create mode 100644 ext/libnfb_ext_grpc/python/nfb/ext/protobuf/__init__.py create mode 100644 ext/libnfb_ext_grpc/python/nfb/ext/protobuf/v1/__init__.py create mode 100644 ext/libnfb_ext_grpc/python/readme.md create mode 100644 ext/libnfb_ext_python/LICENSE create mode 100644 ext/libnfb_ext_python/MANIFEST.in create mode 100644 pynfb/LICENSE create mode 100644 pynfb/MANIFEST.in create mode 100644 pynfb/README.md diff --git a/ext/libnfb_ext_grpc/python/LICENSE b/ext/libnfb_ext_grpc/python/LICENSE new file mode 100644 index 00000000..923fed16 --- /dev/null +++ b/ext/libnfb_ext_grpc/python/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2003-2022 CESNET +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 the copyright holder 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 HOLDER 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. diff --git a/ext/libnfb_ext_grpc/python/MANIFEST.in b/ext/libnfb_ext_grpc/python/MANIFEST.in index c2ad0840..4bf56e5b 100644 --- a/ext/libnfb_ext_grpc/python/MANIFEST.in +++ b/ext/libnfb_ext_grpc/python/MANIFEST.in @@ -1 +1 @@ -graft nfb/ext/protobuf +include readme.md LICENSE diff --git a/ext/libnfb_ext_grpc/python/nfb/ext/protobuf/__init__.py b/ext/libnfb_ext_grpc/python/nfb/ext/protobuf/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ext/libnfb_ext_grpc/python/nfb/ext/protobuf/v1/__init__.py b/ext/libnfb_ext_grpc/python/nfb/ext/protobuf/v1/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ext/libnfb_ext_grpc/python/pyproject.toml b/ext/libnfb_ext_grpc/python/pyproject.toml index 597c26a6..f4cb113d 100644 --- a/ext/libnfb_ext_grpc/python/pyproject.toml +++ b/ext/libnfb_ext_grpc/python/pyproject.toml @@ -4,20 +4,39 @@ build-backend = "setuptools.build_meta" [project] name = "libnfb_ext_grpc" -version = "0.1.0" -authors = [{name = "Martin Spinler", email="spinler@cesnet.cz"}] +version = "0.1.1" description = "Python wrapper for libnfb gRPC extension" -classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: OS Independent", -] +readme = "readme.md" +license = "BSD-3-Clause" +license-files = ["LICENSE"] +authors = [{name = "Martin Spinler", email = "spinler@cesnet.cz"}] +requires-python = ">=3.8" dependencies = [ "protobuf", "grpcio", + "nfb", +] +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3", + "Topic :: System :: Hardware", + "Topic :: System :: Networking", ] +[project.urls] +Homepage = "https://github.com/CESNET/ndk-sw" +Documentation = "https://cesnet.github.io/ndk-sw/" +Repository = "https://github.com/CESNET/ndk-sw" +"Bug Tracker" = "https://github.com/CESNET/ndk-sw/issues" + [project.scripts] nfb-python-grpc-server = "nfb.ext.grpc.server:main" -[tool.setuptools.packages.find] -include = ["nfb*"] +[tool.setuptools] +packages = [ + "nfb.ext.grpc", + "nfb.ext.protobuf", + "nfb.ext.protobuf.v1", +] diff --git a/ext/libnfb_ext_grpc/python/readme.md b/ext/libnfb_ext_grpc/python/readme.md new file mode 100644 index 00000000..5eedc9b4 --- /dev/null +++ b/ext/libnfb_ext_grpc/python/readme.md @@ -0,0 +1,31 @@ +# libnfb_ext_grpc + +Python wrapper for the libnfb gRPC extension. + +This package provides a gRPC server that exposes NFB device operations +(register access, FDT retrieval) over the network, allowing remote control +of NFB/NDK FPGA cards. + +## Prerequisites + +The **nfb-framework** package (providing `libnfb`, the NFB kernel driver, +and the required headers) must be installed first. See the +[NDK software documentation](https://cesnet.github.io/ndk-sw/) for details. + +## Installation + +```bash +pip install libnfb_ext_grpc +``` + +## Usage + +Start the gRPC server: + +```bash +nfb-python-grpc-server +``` + +## License + +BSD 3-Clause License. See [LICENSE](LICENSE) for details. diff --git a/ext/libnfb_ext_grpc/python/setup.py b/ext/libnfb_ext_grpc/python/setup.py index e52884d8..81e762b5 100644 --- a/ext/libnfb_ext_grpc/python/setup.py +++ b/ext/libnfb_ext_grpc/python/setup.py @@ -1,5 +1,28 @@ +import os + from setuptools import setup from setuptools.command.build import build +from setuptools_grpc.build_grpc import build_grpc + + +# The protobuf files are provided by the nfb-framework package. +# Detect the proto directory: prefer in-tree (../) for development builds, +# fall back to the system install path (/usr/include). +def _detect_proto_path(): + candidates = [ + os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."), # in-tree + "/usr/include", # system-installed + ] + for d in candidates: + if os.path.isfile(os.path.join(d, "nfb/ext/protobuf/v1/nfb.proto")): + return d + return "." + + +class custom_build_grpc(build_grpc): + def finalize_options(self): + self.proto_path = _detect_proto_path() + super().finalize_options() class custom_build(build): @@ -8,4 +31,6 @@ class custom_build(build): ] + build.sub_commands -setup(cmdclass={'build': custom_build}) +setup( + cmdclass={'build': custom_build, 'build_grpc': custom_build_grpc}, +) diff --git a/ext/libnfb_ext_python/LICENSE b/ext/libnfb_ext_python/LICENSE new file mode 100644 index 00000000..923fed16 --- /dev/null +++ b/ext/libnfb_ext_python/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2003-2022 CESNET +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 the copyright holder 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 HOLDER 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. diff --git a/ext/libnfb_ext_python/MANIFEST.in b/ext/libnfb_ext_python/MANIFEST.in new file mode 100644 index 00000000..3db0fc2a --- /dev/null +++ b/ext/libnfb_ext_python/MANIFEST.in @@ -0,0 +1,3 @@ +# Include Cython source and C headers in sdist +recursive-include nfb/ext/python *.pyx *.pxd *.h *.c +include readme.rst LICENSE diff --git a/ext/libnfb_ext_python/pyproject.toml b/ext/libnfb_ext_python/pyproject.toml index cc8e56ce..8c6c53ff 100644 --- a/ext/libnfb_ext_python/pyproject.toml +++ b/ext/libnfb_ext_python/pyproject.toml @@ -4,3 +4,34 @@ requires = [ "Cython>=0.29.33", ] build-backend = "setuptools.build_meta" + +[project] +name = "libnfb-ext-python" +version = "0.1.1" +description = "Python extension for libnfb — implement NFB device backends in Python" +readme = "readme.rst" +license = "BSD-3-Clause" +license-files = ["LICENSE"] +authors = [ + { name = "Martin Spinler", email = "spinler@cesnet.cz" }, +] +requires-python = ">=3.8" +dependencies = [ + "fdt", + "nfb", +] +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3", + "Programming Language :: Cython", + "Topic :: System :: Hardware", + "Topic :: System :: Hardware :: Hardware Drivers", +] + +[project.urls] +Homepage = "https://github.com/CESNET/ndk-sw" +Documentation = "https://cesnet.github.io/ndk-sw/" +Repository = "https://github.com/CESNET/ndk-sw" +"Bug Tracker" = "https://github.com/CESNET/ndk-sw/issues" diff --git a/pynfb/LICENSE b/pynfb/LICENSE new file mode 100644 index 00000000..923fed16 --- /dev/null +++ b/pynfb/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2003-2022 CESNET +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 the copyright holder 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 HOLDER 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. diff --git a/pynfb/MANIFEST.in b/pynfb/MANIFEST.in new file mode 100644 index 00000000..aac1dd02 --- /dev/null +++ b/pynfb/MANIFEST.in @@ -0,0 +1,3 @@ +# Include Cython source files in sdist +recursive-include nfb *.pyx *.pxd *.pyi py.typed +include README.md LICENSE diff --git a/pynfb/README.md b/pynfb/README.md new file mode 100644 index 00000000..bd5e9ae4 --- /dev/null +++ b/pynfb/README.md @@ -0,0 +1,66 @@ +# pynfb + +Python API for control of the CESNET NDK based FPGA acceleration cards. + +This package provides Python bindings (via Cython) over `libnfb` and the +Netcope library, enabling register access, packet transmission (NDP queues), +and Ethernet MAC management on NFB/NDK FPGA cards. + +## Prerequisites + +`pynfb` is a source distribution — it compiles Cython extensions at install +time and links against the system-installed `libnfb` and `libfdt` shared +libraries. The **nfb-framework** package (providing `libnfb`, the NFB kernel +driver, and the required headers) must be installed first. + +> **Minimum version:** pynfb 0.3.0 requires nfb-framework >= 6.28. +> The pynfb version is independent from the nfb-framework version. + +### Fedora / RHEL / Oracle Linux (RPM) + +Enable the COPR repository and install nfb-framework: + +```bash +sudo dnf copr enable @CESNET/nfb-framework +sudo dnf install nfb-framework +``` + +You also need the development files for building: + +```bash +sudo dnf install libfdt-devel python3-Cython gcc +``` + +### Build from source + +See the [NDK software build instructions](https://github.com/CESNET/ndk-sw#build-instructions) +for compiling `libnfb` and the kernel driver from source. + +## Installation + +Once the prerequisites are in place: + +```bash +pip install nfb +``` + +## Quick start + +```python +import nfb + +dev = nfb.open() # opens /dev/nfb0 +comp = dev.comp_open("netcope,my_comp", 0) +comp.write32(0x100, 0xDEADBEEF) +val = comp.read32(0x100) +``` + +## Documentation + +- [NFB Software User Guide](https://cesnet.github.io/ndk-sw/) +- [Python quick start](https://cesnet.github.io/ndk-sw/python/quick.html) +- [Python examples](https://cesnet.github.io/ndk-sw/python/examples.html) + +## License + +BSD 3-Clause License. See [LICENSE](LICENSE) for details. diff --git a/pynfb/pyproject.toml b/pynfb/pyproject.toml index be783440..6a2e0913 100644 --- a/pynfb/pyproject.toml +++ b/pynfb/pyproject.toml @@ -5,6 +5,37 @@ requires = [ ] build-backend = "setuptools.build_meta" +[project] +name = "nfb" +version = "0.3.0" +description = "Python API for control of the CESNET NDK based FPGA acceleration cards" +readme = "README.md" +license = "BSD-3-Clause" +license-files = ["LICENSE"] +authors = [ + { name = "Martin Spinler", email = "spinler@cesnet.cz" }, +] +requires-python = ">=3.8" +dependencies = [ + "fdt", +] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3", + "Programming Language :: Cython", + "Topic :: System :: Hardware", + "Topic :: System :: Hardware :: Hardware Drivers", + "Topic :: System :: Networking", +] + +[project.urls] +Homepage = "https://github.com/CESNET/ndk-sw" +Documentation = "https://cesnet.github.io/ndk-sw/" +Repository = "https://github.com/CESNET/ndk-sw" +"Bug Tracker" = "https://github.com/CESNET/ndk-sw/issues" + [[tool.mypy.overrides]] module = "fdt" ignore_missing_imports = true From 090d5db38520548f2b7917b463671614a77e5db2 Mon Sep 17 00:00:00 2001 From: Richard Hyros Date: Thu, 9 Jul 2026 10:17:58 +0200 Subject: [PATCH 484/518] fix(ndp-tools-dpdk): remove deprecated macro --- tools/ndptool/dpdk/dpdk_generate.c | 4 ++-- tools/ndptool/dpdk/dpdk_transmit.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/ndptool/dpdk/dpdk_generate.c b/tools/ndptool/dpdk/dpdk_generate.c index ca32512d..5d63485d 100644 --- a/tools/ndptool/dpdk/dpdk_generate.c +++ b/tools/ndptool/dpdk/dpdk_generate.c @@ -159,10 +159,10 @@ int dpdk_generate_loop(void *params) ret = rte_pktmbuf_alloc_bulk(pool, packets, brst_size); if (ret < 0){ cnt = 0; - RTE_LOG(DEBUG, MBUF, "rte_pktmbuf_alloc_bulk() failed\n"); + fprintf(stderr, "rte_pktmbuf_alloc_bulk() failed\n"); while(rte_pktmbuf_alloc_bulk(pool, packets, brst_size)) { if (cnt > 100) { - RTE_LOG(CRIT, MBUF, "THREAD %d: rte_pktmbuf_alloc_bulk() failed 100 times in a row, killing the thread\n", rte_lcore_id()); + fprintf(stderr, "THREAD %d: rte_pktmbuf_alloc_bulk() failed 100 times in a row, killing the thread\n", rte_lcore_id()); goto alloc_fail; } ++cnt; diff --git a/tools/ndptool/dpdk/dpdk_transmit.c b/tools/ndptool/dpdk/dpdk_transmit.c index cddc88ec..41c1005e 100644 --- a/tools/ndptool/dpdk/dpdk_transmit.c +++ b/tools/ndptool/dpdk/dpdk_transmit.c @@ -212,10 +212,10 @@ int dpdk_transmit_loop(void *params) ret = rte_pktmbuf_alloc_bulk(pool, packets, pkts_ready); if (ret < 0){ cnt = 0; - RTE_LOG(DEBUG, MBUF, "rte_pktmbuf_alloc_bulk() failed\n"); + fprintf(stderr, "rte_pktmbuf_alloc_bulk() failed\n"); while(rte_pktmbuf_alloc_bulk(pool, packets, pkts_ready)) { if (cnt > 100) { - RTE_LOG(CRIT, MBUF, "THREAD %d: rte_pktmbuf_alloc_bulk() failed 100 times in a row, killing the thread\n", rte_lcore_id()); + fprintf(stderr, "THREAD %d: rte_pktmbuf_alloc_bulk() failed 100 times in a row, killing the thread\n", rte_lcore_id()); goto alloc_fail; } ++cnt; @@ -226,7 +226,7 @@ int dpdk_transmit_loop(void *params) for (i = 0; i < (unsigned) pkts_ready; i++) { pckt_address = (unsigned char *) rte_pktmbuf_append(packets[i], statpackets[i].data_length); if (pckt_address == NULL) { - RTE_LOG(CRIT, MBUF, "THREAD %d: rte_pktmbuf_append() failed, killing the thread\n", rte_lcore_id()); + fprintf(stderr, "THREAD %d: rte_pktmbuf_append() failed, killing the thread\n", rte_lcore_id()); goto alloc_fail; } statpackets[i].data = pckt_address; From cb9d2c0c578018f60fd5ac41344457a0c9353d30 Mon Sep 17 00:00:00 2001 From: Yaroslav Marushchenko Date: Fri, 10 Jul 2026 08:32:23 +0000 Subject: [PATCH 485/518] ci: add Dockerfile for Oracle Linux 10 --- build.sh | 14 ++++++++++---- jenkins/Jenkinsfile | 1 + jenkins/oraclelinux10.Dockerfile | 18 ++++++++++++++++++ tools/CMakeLists.txt | 2 +- 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 jenkins/oraclelinux10.Dockerfile diff --git a/build.sh b/build.sh index 8cb7e365..0305109d 100755 --- a/build.sh +++ b/build.sh @@ -16,6 +16,7 @@ URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_V EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" EPEL9_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-9/group_CESNET-dpdk-nfb-epel-9.repo" +EPEL10_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-10/group_CESNET-dpdk-nfb-epel-10.repo" DPDK_NFB_REPO_LOCAL="/etc/yum.repos.d/_copr:copr.fedorainfracloud.org:group_CESNET:dpdk-nfb.repo" # ----[ USEFUL VARIABLES ]---------------------------------------------------- # @@ -196,7 +197,7 @@ get_dpdk_dependencies() os_number=$(get_os_number) if item_in_list "$os" "centos scientific fedora ol rocky"; then - if item_in_list "$os_number" "8 9" ; then + if item_in_list "$os_number" "8 9 10" ; then if [ "$os_number" = "8" ] ; then if ! wget "${EPEL8_DPDK_NFB_REPO_REMOTE}" -O "${DPDK_NFB_REPO_LOCAL}"; then echo >&2 "Could not obtain repository ${EPEL8_DPDK_NFB_REPO_REMOTE}" @@ -206,7 +207,12 @@ get_dpdk_dependencies() if ! wget "${EPEL9_DPDK_NFB_REPO_REMOTE}" -O "${DPDK_NFB_REPO_LOCAL}"; then echo >&2 "Could not obtain repository ${EPEL9_DPDK_NFB_REPO_REMOTE}" return 1 - fi + fi + elif [ "$os_number" = "10" ] ; then + if ! wget "${EPEL10_DPDK_NFB_REPO_REMOTE}" -O "${DPDK_NFB_REPO_LOCAL}"; then + echo >&2 "Could not obtain repository ${EPEL10_DPDK_NFB_REPO_REMOTE}" + return 1 + fi fi ret="" ret="$ret dpdk-nfb" @@ -214,8 +220,8 @@ get_dpdk_dependencies() ret="$ret dpdk-nfb-tools" echo $ret fi - else - echo >&2 "ERROR: NFB DPDK libraries only exist for redhat 8 and redhat 9 derived linux" + else + echo >&2 "ERROR: NFB DPDK libraries only exist for redhat 8/9/10 derived linux" exit 1 fi } diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 0992356c..26fba72d 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -3,6 +3,7 @@ def osreleasevers = [ // ["centos", "centos7", "7.9.2009", "rpm"], ["oraclelinux", "oraclelinux8", "8", "rpm"], ["oraclelinux", "oraclelinux9", "9", "rpm"], + ["oraclelinux", "oraclelinux10", "10", "rpm"], ["ubuntu", "ubuntu_jammy", "jammy", "deb"], ["ubuntu", "ubuntu_noble", "noble", "deb"] ] diff --git a/jenkins/oraclelinux10.Dockerfile b/jenkins/oraclelinux10.Dockerfile new file mode 100644 index 00000000..af4079f5 --- /dev/null +++ b/jenkins/oraclelinux10.Dockerfile @@ -0,0 +1,18 @@ +ARG OSRELEASEVER=10 +ARG OSNAME=centos +FROM $OSNAME:$OSRELEASEVER as default + +RUN /usr/sbin/useradd jenkins +RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers + +RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm +RUN dnf config-manager --set-enabled ol10_codeready_builder; +RUN dnf copr enable @CESNET/dpdk-nfb + +RUN yum install -y epel-release git make gcc rpm-build autoconf automake sudo curl +RUN yum install -y libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel python3-devel pciutils-devel pciutils-libs +RUN yum install -y cmake +RUN yum install -y wget + +RUN yum clean all +RUN pip install cython setuptools diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 74e1b847..e2af4e78 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -105,7 +105,7 @@ if(USE_DPDK) set(DPDK_TARGETS dpdk-generate dpdk-read dpdk-loopback dpdk-receive dpdk-transmit) - target_compile_options(ndp-tool-dpdk PRIVATE -O3 -funroll-loops ${DPDK_CFLAGS}) + target_compile_options(ndp-tool-dpdk PRIVATE -O3 -funroll-loops -Wno-pedantic ${DPDK_CFLAGS}) target_link_libraries(ndp-tool-dpdk PRIVATE ${NUMA_LIBRARIES} ${NCURSES_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${DPDK_LDFLAGS} ) From 73439ee089f7a1577f2d2246330b8535f9266865 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 10 Jul 2026 11:01:15 +0200 Subject: [PATCH 486/518] fix(ci): update commitlint script --- tests/ci/check.gitlab-ci.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/ci/check.gitlab-ci.yaml b/tests/ci/check.gitlab-ci.yaml index 729e9227..7f37fe6d 100644 --- a/tests/ci/check.gitlab-ci.yaml +++ b/tests/ci/check.gitlab-ci.yaml @@ -8,7 +8,7 @@ workflow: BASE_COMMIT_SHA: $CI_MERGE_REQUEST_DIFF_BASE_SHA - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH variables: - BASE_COMMIT_SHA: $CI_COMMIT_SHA + BASE_COMMIT_SHA: $CI_COMMIT_BEFORE_SHA editorconfig: stage: check @@ -37,4 +37,11 @@ commitlint: - apk add --no-cache git - npm install --save-dev @commitlint/config-conventional @commitlint/cli script: - - npx commitlint --extends '@commitlint/config-conventional' --from "${BASE_COMMIT_SHA}" --to "${CI_COMMIT_SHA}" + - | + if [ -z "${BASE_COMMIT_SHA}" ] || \ + [ "${BASE_COMMIT_SHA}" = "0000000000000000000000000000000000000000" ] || \ + [ "${BASE_COMMIT_SHA}" = "${CI_COMMIT_SHA}" ]; then + npx commitlint --extends '@commitlint/config-conventional' --from "${CI_COMMIT_SHA}^" --to "${CI_COMMIT_SHA}" + else + npx commitlint --extends '@commitlint/config-conventional' --from "${BASE_COMMIT_SHA}" --to "${CI_COMMIT_SHA}" + fi From 6d8ca9a0988a3bfb44c4f1e1f544e65f9c7ae65c Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Jul 2026 08:27:02 +0200 Subject: [PATCH 487/518] fix(ndp-tool): store status_loop in stats_info struct This will handle better limit mbps >= 10000. --- tools/ndptool/common.c | 7 +++---- tools/ndptool/common.h | 1 + tools/ndptool/generate.c | 1 + tools/ndptool/transmit.c | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/ndptool/common.c b/tools/ndptool/common.c index 59760466..af2d32a5 100644 --- a/tools/ndptool/common.c +++ b/tools/ndptool/common.c @@ -60,16 +60,15 @@ void delay_nsecs(unsigned int ns) void adjust_tx_throughput(unsigned status_num_of_loops, unsigned long long throughput_mbps, bool use_delay_nsec, struct stats_info *si, struct ndp_queue *tx) { - unsigned status_loop = status_num_of_loops; struct timeval status_time; /* zero Mbps = unlimited throughput */ if (throughput_mbps != 0) { /* Check throughput only every N cycles */ - if (status_loop != 0) { - status_loop--; + if (si->status_loop != 0) { + si->status_loop--; } else { - status_loop = status_num_of_loops; + si->status_loop = status_num_of_loops; do { /* calculate elapsed time and expected bits */ gettimeofday(&status_time, NULL); diff --git a/tools/ndptool/common.h b/tools/ndptool/common.h index 59d9aad8..8df64977 100644 --- a/tools/ndptool/common.h +++ b/tools/ndptool/common.h @@ -57,6 +57,7 @@ struct stats_info { unsigned long long thread_packet_cnt; unsigned long long thread_bytes_cnt; unsigned long long thread_total_bytes_cnt; + unsigned status_loop; void *priv; char progress_letter; diff --git a/tools/ndptool/generate.c b/tools/ndptool/generate.c index 570d17f2..4cb1db2d 100644 --- a/tools/ndptool/generate.c +++ b/tools/ndptool/generate.c @@ -103,6 +103,7 @@ static int ndp_mode_generate_loop(struct ndp_tool_params *p) /* Check throughput only every N cycles */ unsigned status_num_of_loops = p->mode.generate.mbps / 10000u; + si->status_loop = status_num_of_loops; /* Clear length of packet header */ for (i = 0; i < burst_size; i++) { diff --git a/tools/ndptool/transmit.c b/tools/ndptool/transmit.c index 710a521a..d3da8c87 100644 --- a/tools/ndptool/transmit.c +++ b/tools/ndptool/transmit.c @@ -168,6 +168,7 @@ static int ndp_mode_transmit_loop(struct ndp_tool_params *p, struct pcap_src *sr } si->thread_total_bytes_cnt = 0; + si->status_loop = status_num_of_loops; while (!stop) { /* check limits if there is one (0 means loop forever) */ if (p->limit_packets > 0) { From a0364e6ebeebf84993397b5eed8cf77c0d7922d7 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Jul 2026 09:13:29 +0200 Subject: [PATCH 488/518] chore: handle unused variables --- libnfb/include/netcope/bittware_bmc_spi.h | 8 +++++++- libnfb/include/netcope/ndp_tx.h | 4 ++-- pynfb/nfb/libnetcope.pyx | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libnfb/include/netcope/bittware_bmc_spi.h b/libnfb/include/netcope/bittware_bmc_spi.h index 350a0761..a46b06a1 100644 --- a/libnfb/include/netcope/bittware_bmc_spi.h +++ b/libnfb/include/netcope/bittware_bmc_spi.h @@ -664,7 +664,13 @@ static inline int nc_bw_bmc_send_reload(struct nc_bw_bmc * spi, const char *file ret |= nc_bw_bmc_push(spi, target_path, strlen(target_path)); ret |= nc_bw_bmc_push(spi, filename, strlen(filename) + 1); - nc_bw_bmc_send_mctp_ext(spi, spi->buffer, spi->pos, 1, 0); + if (ret) + return -ENOMEM; + + ret = nc_bw_bmc_send_mctp_ext(spi, spi->buffer, spi->pos, 1, 0); + if (ret) + return -EBADF; + return 0; } diff --git a/libnfb/include/netcope/ndp_tx.h b/libnfb/include/netcope/ndp_tx.h index bfc7b891..11a36df7 100644 --- a/libnfb/include/netcope/ndp_tx.h +++ b/libnfb/include/netcope/ndp_tx.h @@ -79,7 +79,7 @@ static inline unsigned nc_ndp_v1_tx_burst_get(void *priv, struct ndp_packet *pac uint16_t packet_size; uint16_t header_size; unsigned cnt = 0; - size_t burst_size = 0; + /*size_t burst_size = 0;*/ unsigned long long bytes; unsigned char *data; @@ -135,7 +135,7 @@ static inline unsigned nc_ndp_v1_tx_burst_get(void *priv, struct ndp_packet *pac swptr += packet_size; bytes -= packet_size; - burst_size += packet_size; + /*burst_size += packet_size;*/ cnt++; } q->u.v1.data = data; diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 9955f89b..7f144f65 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -443,6 +443,7 @@ cdef class DmaCtrlNdp: sp.nb_desc = nb_desc sp.nb_hdr = nb_hdr sp.nb_data = 0 + sp.timeout = 0 self._ctrl.shp = 0 self._ctrl.sdp = 0 From 50e403d7b9cd3138191620aa6cb710affa885894 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 10 Jul 2026 11:13:16 +0200 Subject: [PATCH 489/518] chore: bump version to v6.30.5 --- Changelog | 8 ++++++++ VERSION | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index faf75f46..f182aef3 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,11 @@ +* Wed Jul 15 2026 Martin Spinler - 6.30.5-1 +- [FEATURE] python: add distribution files and upload to pip +- [FIX] ndp-tool: handle better TX speed limitation + +* Mon May 25 2026 Martin Spinler - 6.30.4-1 +- [FEATURE] drivers: add support for newer kernels +- [FEATURE] python: use 'with gil' in callback functions + * Wed Apr 7 2026 Martin Spinler - 6.30.3-1 - [FIX] mdio: fix E-tile PMA loopback on 100G diff --git a/VERSION b/VERSION index ae24c904..3fc9e5ac 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.30.4 +6.30.5 From cdb5ab4f808960e8cfe9d991f5da2bf784028022 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Jul 2026 09:32:05 +0200 Subject: [PATCH 490/518] fix(pynfb): add missing timeout field --- pynfb/nfb/libnetcope.pxd | 1 + 1 file changed, 1 insertion(+) diff --git a/pynfb/nfb/libnetcope.pxd b/pynfb/nfb/libnetcope.pxd index ba019d00..b0409096 100644 --- a/pynfb/nfb/libnetcope.pxd +++ b/pynfb/nfb/libnetcope.pxd @@ -189,6 +189,7 @@ cdef extern from "": uint32_t nb_data; uint32_t nb_desc uint32_t nb_hdr + uint32_t timeout; cdef struct nc_ndp_ctrl: uint64_t last_upper_addr From d59a206c19b24e8ef8e7138d30ad5234aa0a6b94 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Jul 2026 09:33:00 +0200 Subject: [PATCH 491/518] chore: bump version to v6.30.6 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index f182aef3..3fde56dc 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Wed Jul 15 2026 Martin Spinler - 6.30.6-1 +- [FIX] pynfb: add missing timeout field + * Wed Jul 15 2026 Martin Spinler - 6.30.5-1 - [FEATURE] python: add distribution files and upload to pip - [FIX] ndp-tool: handle better TX speed limitation diff --git a/VERSION b/VERSION index 3fc9e5ac..714153f8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.30.5 +6.30.6 From ccece1f1ddf810b235c0499367396bd680fc0449 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Jul 2026 09:40:20 +0200 Subject: [PATCH 492/518] fix(ci): use cmake instead of cmake3 for copr build --- .copr/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.copr/Makefile b/.copr/Makefile index e4312bfa..66923ccc 100644 --- a/.copr/Makefile +++ b/.copr/Makefile @@ -1,13 +1,13 @@ srpm: - dnf -y install cmake3 git curl gcc make rpm-build libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel - ./build.sh --prepare; mkdir build; cd build; cmake3 ..; cpack3 -G RPM --config ./CPackSourceConfig.cmake; cp *.src.rpm $(outdir) + dnf -y install cmake git curl gcc make rpm-build libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel + ./build.sh --prepare; mkdir build; cd build; cmake ..; cpack -G RPM --config ./CPackSourceConfig.cmake; cp *.src.rpm $(outdir) srpm-dpdk: - ./build.sh --prepare; mkdir build; cd build; cmake3 -DUSE_DPDK=true ..; cpack3 -G RPM --config ./CPackSourceConfig.cmake; + ./build.sh --prepare; mkdir build; cd build; cmake -DUSE_DPDK=true ..; cpack -G RPM --config ./CPackSourceConfig.cmake; cd /workdir; cp ./ndk-sw/build/_CPack_Packages/Linux-Source/RPM/SOURCES/*.tar.gz .; cp ./ndk-sw/build/_CPack_Packages/Linux-Source/RPM/SPECS/*.spec . cd /workdir; sed -i 's/\%define _srcrpmdir \%_topdir\/SRPMS//g' ./*.spec srpm-xdp: - ./build.sh --prepare; mkdir build; cd build; cmake3 -DUSE_XDP=true ..; cpack3 -G RPM --config ./CPackSourceConfig.cmake; + ./build.sh --prepare; mkdir build; cd build; cmake -DUSE_XDP=true ..; cpack -G RPM --config ./CPackSourceConfig.cmake; cd /workdir; cp ./ndk-sw/build/_CPack_Packages/Linux-Source/RPM/SOURCES/*.tar.gz .; cp ./ndk-sw/build/_CPack_Packages/Linux-Source/RPM/SPECS/*.spec . cd /workdir; sed -i 's/\%define _srcrpmdir \%_topdir\/SRPMS//g' ./*.spec From fa04425f1cc7469eda17333ead3fc8c0e83a1bdc Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 15 Jul 2026 09:42:14 +0200 Subject: [PATCH 493/518] chore: bump version to v6.30.7 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 3fde56dc..0da80553 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Wed Jul 15 2026 Martin Spinler - 6.30.7-1 +- [FIX] use cmake instead of cmake3 for COPR build + * Wed Jul 15 2026 Martin Spinler - 6.30.6-1 - [FIX] pynfb: add missing timeout field diff --git a/VERSION b/VERSION index 714153f8..016e5b55 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.30.6 +6.30.7 From 36d9296d0e0e04318a821b767be19b7fcb700433 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 27 Jul 2026 13:52:36 +0200 Subject: [PATCH 494/518] fix(libnfb-ext-python): check for BaseException in backend functions This handles exceptions like asyncio.CancelledError used in cocotb. --- ext/libnfb_ext_python/nfb/ext/python/shim.pyx | 88 +++++++++++++------ ext/libnfb_ext_python/pyproject.toml | 2 +- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/ext/libnfb_ext_python/nfb/ext/python/shim.pyx b/ext/libnfb_ext_python/nfb/ext/python/shim.pyx index 61b3930e..103710c0 100644 --- a/ext/libnfb_ext_python/nfb/ext/python/shim.pyx +++ b/ext/libnfb_ext_python/nfb/ext/python/shim.pyx @@ -62,8 +62,12 @@ cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset) cdef bytes data cdef ssize_t ret - nfb, comp_node, bus_node = bus - data = nfb.read(bus_node, comp_node, offset, nbyte) + try: + nfb, comp_node, bus_node = bus + data = nfb.read(bus_node, comp_node, offset, nbyte) + except BaseException: + return -1 + ret = len(data) if ret > int(nbyte): ret = -1 @@ -79,8 +83,11 @@ cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t o cdef const char* c_data = buf cdef bytes data = c_data[:nbyte] - nfb, comp_node, bus_node = bus - nfb.write(bus_node, comp_node, offset, data) + try: + nfb, comp_node, bus_node = bus + nfb.write(bus_node, comp_node, offset, data) + except BaseException: + return -1 return nbyte @@ -127,16 +134,22 @@ cdef void nfb_pynfb_bus_close(void *priv) noexcept with gil: cdef int pyndp_start(void *priv) noexcept with gil: cdef object t = priv - queue, temp = t - queue.start() + try: + queue, temp = t + queue.start() + except BaseException: + return -1 return 0 cdef int pyndp_stop(void *priv) noexcept with gil: cdef object t = priv - queue, temp = t - queue.stop() + try: + queue, temp = t + queue.stop() + except BaseException: + return -1 return 0 @@ -146,9 +159,17 @@ cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count cdef uint8_t* c_data cdef uint8_t* c_hdr - queue, temp = t + cdef object queue + cdef object pkts + cdef unsigned cnt + cdef unsigned i + + try: + queue, temp = t + pkts = queue.burst_get(count) + except BaseException: + return 0 - pkts = queue.burst_get(count) cnt = min(len(pkts), count) for i in range(cnt): pkt, hdr, flags = pkts[i] @@ -166,23 +187,33 @@ cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count cdef int pyndp_rx_burst_put(void *priv) noexcept with gil: cdef object t = priv - queue, temp = t - queue.burst_put() + try: + queue, temp = t + queue.burst_put() + except BaseException: + return -1 return 0 cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count) noexcept with gil: cdef object t = priv - queue, temp = t + cdef object queue + cdef object pkts + cdef object prep + cdef unsigned i - pkts = [] - for i in range(count): - pkts.append(( - int(packets[i].data_length), - int(packets[i].header_length), - int(packets[i].flags), - )) - prep = queue.burst_get(pkts) + try: + queue, temp = t + pkts = [] + for i in range(count): + pkts.append(( + int(packets[i].data_length), + int(packets[i].header_length), + int(packets[i].flags), + )) + prep = queue.burst_get(pkts) + except BaseException: + return 0 for i in range(len(prep)): packets[i].data = prep[i][0] @@ -193,16 +224,23 @@ cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count cdef int pyndp_tx_burst_put(void *priv) noexcept with gil: cdef object t = priv - queue, temp = t - queue.burst_put() + try: + queue, temp = t + queue.burst_put() + except BaseException: + return -1 return 0 cdef int pyndp_tx_burst_flush(void *priv) noexcept with gil: cdef object t = priv - queue, temp = t - queue.burst_flush() + try: + queue, temp = t + queue.burst_flush() + except BaseException: + return -1 + return 0 diff --git a/ext/libnfb_ext_python/pyproject.toml b/ext/libnfb_ext_python/pyproject.toml index 8c6c53ff..df3d266a 100644 --- a/ext/libnfb_ext_python/pyproject.toml +++ b/ext/libnfb_ext_python/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "libnfb-ext-python" -version = "0.1.1" +version = "0.1.2" description = "Python extension for libnfb — implement NFB device backends in Python" readme = "readme.rst" license = "BSD-3-Clause" From faf0fc613518546a5f304507c26951116feb8d5b Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 30 Jul 2026 14:50:18 +0200 Subject: [PATCH 495/518] feat(pynfb): support DMA Calypte --- pynfb/nfb/libnetcope.pxd | 9 +++++++++ pynfb/nfb/libnetcope.pyx | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/pynfb/nfb/libnetcope.pxd b/pynfb/nfb/libnetcope.pxd index b0409096..2c7fb941 100644 --- a/pynfb/nfb/libnetcope.pxd +++ b/pynfb/nfb/libnetcope.pxd @@ -180,6 +180,13 @@ cdef extern from "": unsigned reserved unsigned free_desc + cdef struct nc_calypte_hdr: + uint16_t frame_len + uint16_t frame_ptr + unsigned valid + unsigned reserved + unsigned metadata + cdef struct nc_ndp_ctrl_start_params: dma_addr_t desc_buffer dma_addr_t data_buffer; @@ -204,6 +211,8 @@ cdef extern from "": uint32_t *update_buffer uint32_t dir + unsigned int NDP_CTRL_REG_HDP + nc_ndp_desc nc_ndp_rx_desc0(dma_addr_t phys) nc_ndp_desc nc_ndp_rx_desc2(dma_addr_t phys, uint16_t len, int next) nc_ndp_desc nc_ndp_tx_desc0(dma_addr_t phys) diff --git a/pynfb/nfb/libnetcope.pyx b/pynfb/nfb/libnetcope.pyx index 7f144f65..3e48d1d2 100644 --- a/pynfb/nfb/libnetcope.pyx +++ b/pynfb/nfb/libnetcope.pyx @@ -11,7 +11,7 @@ from cpython.exc cimport PyErr_SetFromErrno import libnfb cimport libnfb -from libnfb cimport NfbDeviceHandle, nfb_comp_open, nfb_comp_close +from libnfb cimport NfbDeviceHandle, nfb_comp_open, nfb_comp_close, nfb_comp_read cdef class RxMac: @@ -427,6 +427,33 @@ cdef class DmaCtrlNdp: else: return self.__desc2uint(nc_ndp_tx_desc2(phys, length, ((meta & 0xF) << 8) | (hdr_length & 0xFF), 1 if next else 0)) + def calypte_hdr_decode(self, data: bytes): + """Decode a DMA Calypte RX/TX ring header (struct nc_calypte_hdr) from its raw bytes. + + Returns (valid, frame_len, frame_ptr, metadata). The caller is responsible for + tracking/toggling the expected valid-bit polarity across ring wraps. + """ + cdef bytes b + cdef nc_calypte_hdr *hdr + + b = bytes(data) + if len(b) != sizeof(nc_calypte_hdr): + raise ValueError(f"expected {sizeof(nc_calypte_hdr)} bytes, got {len(b)}") + hdr = b + return (hdr.valid != 0, hdr.frame_len, hdr.frame_ptr, hdr.metadata) + + def read_hdp(self) -> int: + """Read NDP_CTRL_REG_HDP directly via MI on this controller's own component. + + nc_ndp_ctrl_hdp_update() (exposed as update_hdp()) only ever reads the + RAM-pushed copy of this pointer. TX Calypte free-space tracking + needs a live read of this register instead. + """ + cdef uint32_t val = 0 + self._check_handle() + nfb_comp_read(self._ctrl.comp, &val, sizeof(val), NDP_CTRL_REG_HDP) + return val + def start(self, desc_buffer: dma_addr_t, hdr_buffer: dma_addr_t, update_buffer: dma_addr_t, update_buffer_p: memoryview, nb_desc: uint32_t, nb_hdr: uint32_t): @@ -435,14 +462,16 @@ cdef class DmaCtrlNdp: self.ub_view = update_buffer_p ub_ptr = &self.ub_view[0] - sp.data_buffer = 0 + # the data_buffer is used similarly (Medusa: desc_buffer, Calypte: data_buffer) + sp.data_buffer = desc_buffer sp.desc_buffer = desc_buffer sp.hdr_buffer = hdr_buffer sp.update_buffer = update_buffer sp.update_buffer_virt = ub_ptr sp.nb_desc = nb_desc sp.nb_hdr = nb_hdr - sp.nb_data = 0 + # the nb_data is used similarly (Medusa: nb_desc, Calypte: nb_data) + sp.nb_data = nb_desc sp.timeout = 0 self._ctrl.shp = 0 From dd7650eda5474dc9a5b84fcdcaa12b8276dafa9d Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 31 Jul 2026 08:30:16 +0200 Subject: [PATCH 496/518] chore(pynfb): bump version to 0.3.1 --- pynfb/pyproject.toml | 2 +- pynfb/setup.py | 2 +- pynfb/setup.py.in | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pynfb/pyproject.toml b/pynfb/pyproject.toml index 6a2e0913..99923726 100644 --- a/pynfb/pyproject.toml +++ b/pynfb/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "nfb" -version = "0.3.0" +version = "0.3.1" description = "Python API for control of the CESNET NDK based FPGA acceleration cards" readme = "README.md" license = "BSD-3-Clause" diff --git a/pynfb/setup.py b/pynfb/setup.py index f22712ba..292b79d1 100644 --- a/pynfb/setup.py +++ b/pynfb/setup.py @@ -22,7 +22,7 @@ setup( name="nfb", - version="0.2.2", + version="0.3.1", author="Martin Spinler", author_email="spinler@cesnet.cz", ext_package="nfb", diff --git a/pynfb/setup.py.in b/pynfb/setup.py.in index da04d428..3a7aced9 100644 --- a/pynfb/setup.py.in +++ b/pynfb/setup.py.in @@ -17,7 +17,7 @@ libnfb_ext_extra_args = libnetcope_ext_extra_args = ext_extra_args setup( name = "nfb", - version = "0.2.2", + version = "0.3.1", author = "Martin Spinler", author_email = "spinler@cesnet.cz", ext_package = "nfb", From be4be688f37f4419aacb87215b0aca4c1bdf43a0 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Tue, 11 Aug 2026 12:20:24 +0200 Subject: [PATCH 497/518] feat(libnetcope - mdio): adjustable adaptation effort level on e-tile --- libnfb/include/netcope/mdio.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 9d500d39..7bfa74ce 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -760,6 +760,9 @@ static inline int nc_mdio_fixup_ftile_set_loopback(struct nc_mdio *mdio, int prt #define ETILE_ADAPT_MODE_INITIAL 0x1 #define ETILE_ADAPT_MODE_ONESHOT 0x2 #define ETILE_ADAPT_MODE_CONTINUOUS 0x6 +#define ETILE_ADAPT_EFFORT_LOW 0x0000 +#define ETILE_ADAPT_EFFORT_MEDIUM 0x0010 +#define ETILE_ADAPT_EFFORT_FULL 0x0001 /* 32-bit read operation from the RS-FEC registers */ static inline uint32_t nc_mdio_etile_rsfec_read(struct nfb_comp *comp, int prtad, uint32_t addr) @@ -1151,11 +1154,11 @@ static inline void nc_mdio_fixup_etile_set_mode(struct nc_mdio *mdio, int prtad, /* Starts PMA adaptation on a lane. */ /* Adaptation mode: 0x1 - initial; 0x2 = One shot; 0x6 = continuous (mission) */ /* Beware, this is internal function and must be accessed with ATTR_IFC feature already locked! */ -static inline void nc_mdio_etile_adapt_start(struct nc_mdio *mdio, int prtad, int lane, uint16_t mode) +static inline void nc_mdio_etile_adapt_start(struct nc_mdio *mdio, int prtad, int lane, uint16_t mode, uint16_t effort) { /* Set Adaptation Effort Level to full effort */ nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x002c, 0x0118); /* */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, 0x0001); /* */ + nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x006c, effort); /* */ nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x000a, mode); /* Run the adaptation */ } @@ -1239,7 +1242,7 @@ static inline void nc_mdio_etile_loopback_enable(struct nc_mdio *mdio, int prtad /* Enable loopback and start the initial adaptation on all channels */ for (i = 0; i < mdio->pma_lanes; i++) { nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0301); /* Enable the loopback */ - nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL); + nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL, ETILE_ADAPT_EFFORT_FULL); } /* Check adaptation status on all channels */ for (i = 0; i < mdio->pma_lanes; i++) { @@ -1253,11 +1256,11 @@ static inline void nc_mdio_etile_mission_mode(struct nc_mdio *mdio, int prtad) int i; for (i = 0; i < mdio->pma_lanes; i++) { nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0008, 0x0300); /* Disable the loopback */ - nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL); /* Start the initial adaptation */ + nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL, ETILE_ADAPT_EFFORT_FULL); /* Start the initial adaptation */ } for (i = 0; i < mdio->pma_lanes; i++) { nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80); /* Check initial adaptation status */ - nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_CONTINUOUS); /* Start the continuous adaptation */ + nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_CONTINUOUS, ETILE_ADAPT_EFFORT_FULL); /* Start the continuous adaptation */ } for (i = 0; i < mdio->pma_lanes; i++) { nc_mdio_etile_adapt_wait(mdio, prtad, i, 0xE2); /* Check continuous adaptation status */ From d212c7bfa817e634ba876aa99f0140fc3ddec3aa Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Tue, 11 Aug 2026 12:22:50 +0200 Subject: [PATCH 498/518] feat(libnetcope - mdio): implement e-tile pma_attribute_write() timeout --- libnfb/include/netcope/mdio.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 7bfa74ce..4645c3d6 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -1004,8 +1004,9 @@ static inline int nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int pr int sent = 0; /* Clear PMA attribute code request sent flag */ - nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L, 0x80); - while (!sent) { + retries = 0; + while (!sent && retries++ < 1000000) { + nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L, 0x80); /* Set PMA attribute code address and data */ nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_VAL_L, code_val_l); nc_mdio_dmap_drp_write(comp, prtad, page, PMA_ATTR_CODE_VAL_H, code_val_h); @@ -1016,6 +1017,7 @@ static inline int nc_mdio_etile_pma_attribute_write(struct nc_mdio *mdio, int pr /* Verify that PMA attribute code request has been sent */ sent = ((nc_mdio_dmap_drp_read(comp, prtad, page, PMA_ATTR_CODE_REQ_STATUS_L) >> 7) & 0x01); } + /* TODO: error return code should return here if !sent */ /* Wait until PMA attribute code request is completed */ retries = 0; do { From a041275d8f136566120b41ec09c6cfbbfd11c5fa Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Tue, 11 Aug 2026 12:27:26 +0200 Subject: [PATCH 499/518] feat(libnetcope - mdio): adjustable adaptation timeout on e-tile --- libnfb/include/netcope/mdio.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 4645c3d6..6edbf385 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -1165,7 +1165,7 @@ static inline void nc_mdio_etile_adapt_start(struct nc_mdio *mdio, int prtad, in } /* Beware, this is internal function and must be accessed with ATTR_IFC feature already locked! */ -static inline void nc_mdio_etile_adapt_wait(struct nc_mdio *mdio, int prtad, int lane, uint8_t result) +static inline int nc_mdio_etile_adapt_wait(struct nc_mdio *mdio, int prtad, int lane, uint8_t result, int max_retries) { uint16_t ret; int retries = 0; @@ -1174,7 +1174,8 @@ static inline void nc_mdio_etile_adapt_wait(struct nc_mdio *mdio, int prtad, int do { nc_mdio_etile_pma_attribute_write(mdio, prtad, lane, 0x0126, 0x0b00); ret = nc_mdio_etile_pma_attribute_read(mdio, prtad, lane); - } while (((ret & 0xff) != result) && (++retries < 1000000)); + } while (((ret & 0xff) != result) && (++retries < max_retries)); + return ((ret & 0xff) == result); } /* Reload PMA settings (call PMA attribute sequencer) on all lanes */ @@ -1248,7 +1249,7 @@ static inline void nc_mdio_etile_loopback_enable(struct nc_mdio *mdio, int prtad } /* Check adaptation status on all channels */ for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80); + nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80, 10000); } } @@ -1261,11 +1262,11 @@ static inline void nc_mdio_etile_mission_mode(struct nc_mdio *mdio, int prtad) nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_INITIAL, ETILE_ADAPT_EFFORT_FULL); /* Start the initial adaptation */ } for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80); /* Check initial adaptation status */ + nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80, 400000); /* Check initial adaptation status */ nc_mdio_etile_adapt_start(mdio, prtad, i, ETILE_ADAPT_MODE_CONTINUOUS, ETILE_ADAPT_EFFORT_FULL); /* Start the continuous adaptation */ } for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_adapt_wait(mdio, prtad, i, 0xE2); /* Check continuous adaptation status */ + nc_mdio_etile_adapt_wait(mdio, prtad, i, 0xE2, 1000); /* Check continuous adaptation status */ } } From 4ab32c9257903eee1be3f31ff86465601dc67d00 Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Tue, 11 Aug 2026 12:30:46 +0200 Subject: [PATCH 500/518] feat(libnetcope - mdio): improve e-tile sysrst - reset PMA lanes and adaptation too --- libnfb/include/netcope/mdio.h | 71 +++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 6edbf385..96b8bcd9 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -1270,22 +1270,71 @@ static inline void nc_mdio_etile_mission_mode(struct nc_mdio *mdio, int prtad) } } -/* Performs Eth system reset */ +/* Performs Eth system reset and initialization */ static inline void nc_mdio_etile_eth_sysrst(struct nc_mdio *mdio, int prtad) { - int i; + int i, res; + uint16_t stat; + char pending[mdio->pma_lanes]; /* Lanes that still need adaptation */ + int pending_cnt = mdio->pma_lanes; + int retries = 0; struct nfb_comp *comp = nfb_user_to_comp(mdio); - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0011, 0x0003); /* Recalibrate the PMA on next enable */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0001, 0x0000); /* Disable the PMA */ - nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0001, 0x0007); /* Enable the PMA */ + /* Initially all lanes are pending */ + for (i = 0; i < mdio->pma_lanes; i++) + pending[i] = 1; + + /* Step 1: reset (disable + enable) all PMA lanes (this also forces the initial adaptation) */ + while (pending_cnt && retries++ < 3) { + /* Reset (disable + enable) lanes that still need adaptation */ + for (i = 0; i < mdio->pma_lanes; i++) { + if (!pending[i]) + continue; + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0001, 0x0000); /* Disable the PMA */ + stat = nc_mdio_etile_pma_attribute_read(mdio, prtad, i); /* Get operation status*/ + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0001, 0x0007); /* Enable the PMA */ + stat = nc_mdio_etile_pma_attribute_read(mdio, prtad, i); /* Get operation status*/ + } + /* Check adaptation of the pending lanes only */ + for (i = 0; i < mdio->pma_lanes; i++) { + if (!pending[i]) + continue; + res = nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80, 200000); /* Get adaptation status */ + if (res) { + pending[i] = 0; + pending_cnt--; + } + } + } + /* TODO: if (pending_cnt) -> adaptation failed. Not observed in hardware */ + + /* Step 2: Force Eth IP system reset (eio_sys_rst) */ + retries = 0; + res = 0; + while ((retries++ < 3) && !res) { + /* When the eio_sys_rst is asserted, the access to any other registers is forbidden */ + /* This reset leads to deassertion of the o_tx_lanes_stable and o_rx_pcs_ready output signals */ + nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x7); /* eio_sys_rst set */ + nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); /* eio_sys_rst clear */ + /* Wait a short time until the reset sequence starts */ + _drp_wait_until(comp, prtad, 0x32c, 0x01, 1, 10); /* Wait until bit[0] of 0x32c becomes 1 */ + /* Wait until the reset sequence finishes */ + res = _drp_wait_until(comp, prtad, 0x32c, 0x01, 0, 1000); /* Wait until bit[0] of 0x32c -> 0 */ + + /* Sometimes the reset remains active forever due to a stucked PMA lane. */ + /* This problematic PMA lanes require reset */ + if (!res) { + /* Find and reset stucked PMA lanes */ + for (i = 0; i < mdio->pma_lanes; i++) { + stat = nc_mdio_dmap_drp_read(comp, prtad, i+1, 0x40082); /* Check PMA transfer ready flags */ + /* Re-enable the PMA if not Transfer ready set */ + if ((stat & 0x3) != 0x3) { + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0001, 0x0000); /* Disable the PMA */ + nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0001, 0x0007); /* Enable the PMA */ + } + } + } } - nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x7); // eio_sys_rst set - /* Wait until the reset sequence starts */ - _drp_wait_until(comp, prtad, 0x32c, 0x01, 1, 10000); /* Wait until bit[0] of 0x32c becomes 1 */ - /* Wait until the reset sequence finishes */ - _drp_wait_until(comp, prtad, 0x32c, 0x01, 0, 100000); /* Wait until bit[0] of 0x32c -> 0 */ } /* Enable/disable E-Tile PMA loopback and initialize the link */ From c34a073d481fcc790384f25db0fbfe50d334cd4a Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Tue, 11 Aug 2026 12:33:53 +0200 Subject: [PATCH 501/518] feat(libnetcope - mdio): perform sysreset at the start of loopback switching on e-tile --- libnfb/include/netcope/mdio.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 96b8bcd9..2873c0d2 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -1357,12 +1357,7 @@ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prt /* Note: to avoid PMA reset which disturbs all channels in the quad, EQ reset is performed instead */ nc_mdio_etile_eq_reset(mdio, prtad); /* 4. Apply CSR reset */ - nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x7); // eio_sys_rst set - nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x6); // eio_sys_rst clear - /* Wait until the reset sequence starts */ - _drp_wait_until(comp, prtad, 0x32c, 0x01, 1, 10000); /* Wait until bit[0] of 0x32c becomes 1 */ - /* Wait until the reset sequence finishes */ - _drp_wait_until(comp, prtad, 0x32c, 0x01, 0, 100000); /* Wait until bit[0] of 0x32c becomes 0 */ + nc_mdio_etile_eth_sysrst(mdio, prtad); /* 5a. Deassert TX reset */ nc_mdio_dmap_drp_write(comp, prtad, 0, 0x310, 0x4); // soft rx rst only _drp_wait_until(comp, prtad, 0x32c, 0x12, 0, 1000000); /* Wait until bits[4,1] of 0x32c become 0 */ @@ -1386,7 +1381,6 @@ static inline int nc_mdio_fixup_etile_set_loopback(struct nc_mdio *mdio, int prt if (enable && (++retries < 3)) { if (!_drp_wait_until(comp, prtad, status_reg, 0x01, 1, 1000000)) { /* RX still not ready - perform hard reset and retry */ - nc_mdio_etile_eth_sysrst(mdio, prtad); goto retry; } } From a807fdfcfcb92868954f9ccc7f4dfdb6d20c2a73 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 20 Aug 2026 18:01:03 +0200 Subject: [PATCH 502/518] feat(libnfb-ext-python): add ExceptionBridgeBase contract Pluggable interface for intercepting BaseExceptions that must not remain set when libnfb C callbacks return. --- .../nfb/ext/python/exception_bridge.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ext/libnfb_ext_python/nfb/ext/python/exception_bridge.py diff --git a/ext/libnfb_ext_python/nfb/ext/python/exception_bridge.py b/ext/libnfb_ext_python/nfb/ext/python/exception_bridge.py new file mode 100644 index 00000000..69cd7b03 --- /dev/null +++ b/ext/libnfb_ext_python/nfb/ext/python/exception_bridge.py @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (C) 2026 CESNET z. s. p. o. + +"""Contract for optional exception bridges used by the libnfb Python shim. + +Shim callbacks return into C and must not leave a Python exception set. A +registered bridge may intercept selected BaseExceptions, clear them for the +C return path, and re-raise them later. Concrete policy is implemented +elsewhere. +""" + +from __future__ import annotations + +from abc import ABC, abstractmethod + + +class ExceptionBridgeBase(ABC): + """Base for bridges registered via ``set_exception_bridge``.""" + + @abstractmethod + def pending(self) -> bool: + """True if a prior intercept is still waiting to be re-raised.""" + + @abstractmethod + def intercept(self, exc: BaseException) -> bool: + """Handle *exc* for a C callback. + + Return True if the shim should treat the call as a C error (exception + cleared). Return False to leave handling to the shim (re-raise). + """ + + def raise_if_cancelled(self) -> None: + """Re-raise a stashed cancel/interrupt if any (default: no-op).""" + + def clear(self) -> None: + """Drop any stashed exception without raising (default: no-op).""" From ef33405a1de4022a102350b7ef17de5415609794 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 20 Aug 2026 18:01:07 +0200 Subject: [PATCH 503/518] feat(libnfb-ext-python): route shim callbacks through exception bridge Stash selected BaseExceptions via a registered bridge, fail fast while one is pending, and keep ordinary Exception handling as a plain C error return. --- .../nfb/ext/python/__init__.py | 14 +++ ext/libnfb_ext_python/nfb/ext/python/shim.pyx | 116 ++++++++++++++++-- ext/libnfb_ext_python/pyproject.toml | 2 +- 3 files changed, 122 insertions(+), 10 deletions(-) diff --git a/ext/libnfb_ext_python/nfb/ext/python/__init__.py b/ext/libnfb_ext_python/nfb/ext/python/__init__.py index 9e8167c1..39c9edc1 100644 --- a/ext/libnfb_ext_python/nfb/ext/python/__init__.py +++ b/ext/libnfb_ext_python/nfb/ext/python/__init__.py @@ -4,6 +4,20 @@ import fdt from . import shim +from .exception_bridge import ExceptionBridgeBase +from .shim import get_exception_bridge, get_libnfb_ext_path, set_exception_bridge + +__all__ = [ + "AbstractNdpQueue", + "AbstractNdpQueueRx", + "AbstractNdpQueueTx", + "AbstractNfb", + "ExceptionBridgeBase", + "get_exception_bridge", + "get_libnfb_ext_path", + "set_exception_bridge", + "shim", +] class AbstractNdpQueue(ABC): diff --git a/ext/libnfb_ext_python/nfb/ext/python/shim.pyx b/ext/libnfb_ext_python/nfb/ext/python/shim.pyx index 103710c0..bc856ee6 100644 --- a/ext/libnfb_ext_python/nfb/ext/python/shim.pyx +++ b/ext/libnfb_ext_python/nfb/ext/python/shim.pyx @@ -1,5 +1,35 @@ cdef api const char *libnfb_ext_compatible_pattern = "libnfb-ext-compat_pattern:" +import logging + +_log = logging.getLogger(__name__) + +# Optional hook implementing ExceptionBridgeBase (or pending/intercept duck type). +_exception_bridge = None + + +def set_exception_bridge(bridge): + """Register/clear a bridge for BaseException crossing C callbacks. + + *bridge* should implement :class:`nfb.ext.python.ExceptionBridgeBase` + (or the same ``pending`` / ``intercept`` interface). + """ + global _exception_bridge + _exception_bridge = bridge + + +def get_exception_bridge(): + return _exception_bridge + + +cdef bint _bridge_pending(): + return _exception_bridge is not None and bool(_exception_bridge.pending()) + + +cdef bint _bridge_intercept(object exc): + return _exception_bridge is not None and bool(_exception_bridge.intercept(exc)) + + def get_libnfb_ext_path(nfb): # early version of libnfb relies on a pattern "libnfb-ext-" somewhere in device string/path base = __file__ + ":" + libnfb_ext_compatible_pattern.decode() @@ -56,16 +86,28 @@ cdef void nfb_ext_python_close(void *priv) noexcept with gil: #free(wrap.fdt) Py_DECREF(wrap) +# Backend callbacks return to libnfb C, which does not check PyErr. +# Ordinary Python errors and unhandled BaseExceptions return a C error code. +# A registered exception bridge may intercept a BaseException to stash it +# for re-raise after the bridged call, and fail-fast while pending. + cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset) noexcept with gil: cdef PyObject* _bus = p cdef object bus = _bus cdef bytes data cdef ssize_t ret + if _bridge_pending(): + return -1 + try: nfb, comp_node, bus_node = bus data = nfb.read(bus_node, comp_node, offset, nbyte) - except BaseException: + except Exception: + _log.exception("MI bus read callback failed") + return -1 + except BaseException as e: + _bridge_intercept(e) return -1 ret = len(data) @@ -83,10 +125,17 @@ cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t o cdef const char* c_data = buf cdef bytes data = c_data[:nbyte] + if _bridge_pending(): + return -1 + try: nfb, comp_node, bus_node = bus nfb.write(bus_node, comp_node, offset, data) - except BaseException: + except Exception: + _log.exception("MI bus write callback failed") + return -1 + except BaseException as e: + _bridge_intercept(e) return -1 return nbyte @@ -134,10 +183,17 @@ cdef void nfb_pynfb_bus_close(void *priv) noexcept with gil: cdef int pyndp_start(void *priv) noexcept with gil: cdef object t = priv + if _bridge_pending(): + return -1 + try: queue, temp = t queue.start() - except BaseException: + except Exception: + _log.exception("NDP queue start callback failed") + return -1 + except BaseException as e: + _bridge_intercept(e) return -1 return 0 @@ -145,10 +201,17 @@ cdef int pyndp_start(void *priv) noexcept with gil: cdef int pyndp_stop(void *priv) noexcept with gil: cdef object t = priv + if _bridge_pending(): + return -1 + try: queue, temp = t queue.stop() - except BaseException: + except Exception: + _log.exception("NDP queue stop callback failed") + return -1 + except BaseException as e: + _bridge_intercept(e) return -1 return 0 @@ -164,10 +227,17 @@ cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count cdef unsigned cnt cdef unsigned i + if _bridge_pending(): + return 0 + try: queue, temp = t pkts = queue.burst_get(count) - except BaseException: + except Exception: + _log.exception("NDP RX burst_get callback failed") + return 0 + except BaseException as e: + _bridge_intercept(e) return 0 cnt = min(len(pkts), count) @@ -187,10 +257,17 @@ cdef unsigned pyndp_rx_burst_get(void *priv, ndp_packet *packets, unsigned count cdef int pyndp_rx_burst_put(void *priv) noexcept with gil: cdef object t = priv + if _bridge_pending(): + return -1 + try: queue, temp = t queue.burst_put() - except BaseException: + except Exception: + _log.exception("NDP RX burst_put callback failed") + return -1 + except BaseException as e: + _bridge_intercept(e) return -1 return 0 @@ -202,6 +279,9 @@ cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count cdef object prep cdef unsigned i + if _bridge_pending(): + return 0 + try: queue, temp = t pkts = [] @@ -212,7 +292,11 @@ cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count int(packets[i].flags), )) prep = queue.burst_get(pkts) - except BaseException: + except Exception: + _log.exception("NDP TX burst_get callback failed") + return 0 + except BaseException as e: + _bridge_intercept(e) return 0 for i in range(len(prep)): @@ -224,10 +308,17 @@ cdef unsigned pyndp_tx_burst_get(void *priv, ndp_packet *packets, unsigned count cdef int pyndp_tx_burst_put(void *priv) noexcept with gil: cdef object t = priv + if _bridge_pending(): + return -1 + try: queue, temp = t queue.burst_put() - except BaseException: + except Exception: + _log.exception("NDP TX burst_put callback failed") + return -1 + except BaseException as e: + _bridge_intercept(e) return -1 return 0 @@ -235,10 +326,17 @@ cdef int pyndp_tx_burst_put(void *priv) noexcept with gil: cdef int pyndp_tx_burst_flush(void *priv) noexcept with gil: cdef object t = priv + if _bridge_pending(): + return -1 + try: queue, temp = t queue.burst_flush() - except BaseException: + except Exception: + _log.exception("NDP TX burst_flush callback failed") + return -1 + except BaseException as e: + _bridge_intercept(e) return -1 return 0 diff --git a/ext/libnfb_ext_python/pyproject.toml b/ext/libnfb_ext_python/pyproject.toml index df3d266a..27dcb3c3 100644 --- a/ext/libnfb_ext_python/pyproject.toml +++ b/ext/libnfb_ext_python/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "libnfb-ext-python" -version = "0.1.2" +version = "0.2.0" description = "Python extension for libnfb — implement NFB device backends in Python" readme = "readme.rst" license = "BSD-3-Clause" From 0e4a84f7ecf4047b9a5dd434b1134da2d60dcede Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 21 Aug 2026 20:06:31 +0200 Subject: [PATCH 504/518] feat(tool - info): show PCI endpoint table and attachment state Add a PCI-centric endpoint table with per-endpoint state, overall PCIe state for single-device queries, and shared PCI endpoint mask helpers. The card list (-l) and the new PCI-centric table (-p) are independent and can be combined (-lp): -l lists NFB devices, -p lists PCI endpoints (including ones whose card isn't otherwise listed, e.g. still unbound from the driver). --- doc/tools/nfb-info.rst | 61 ++++- libnfb/include/netcope/pci_ep.h | 99 ++++++++ tools/CMakeLists.txt | 4 +- tools/info/info.c | 432 +++++++++++++++++++++++++++++--- tools/info/pci.c | 355 ++++++++++++++++++++++++++ tools/info/pci.h | 60 +++++ 6 files changed, 956 insertions(+), 55 deletions(-) create mode 100644 libnfb/include/netcope/pci_ep.h create mode 100644 tools/info/pci.c create mode 100644 tools/info/pci.h diff --git a/doc/tools/nfb-info.rst b/doc/tools/nfb-info.rst index 62a9cfb1..f64e17dd 100644 --- a/doc/tools/nfb-info.rst +++ b/doc/tools/nfb-info.rst @@ -9,6 +9,14 @@ It shows board name and its serial number, firmware project name and build details, number of RX/TX DMA queues and number of Ethernet channels. It also shows PCIe endpoint configuration (slot number, speed and link width) and their NUMA node. +With ``-l``, it lists all NFB devices in the system. Each row includes an overall design and PCIe info. + +With ``-p``, it prints a PCI-centric endpoint table instead: one row per PCIe endpoint, +including endpoints whose card isn't otherwise listed (e.g. still unbound from the +``nfb`` driver). + +``-l`` and ``-p`` can be combined (``-lp``) to print both. + .. tip:: Verbose mode shows also temperature of primary FPGA. @@ -90,9 +98,15 @@ JSON output ] }, "system": { + "pcie_overall_state": "ok", "pci": [ # list of PCI endpoints { "id": 0, + "state_degraded": false, + "state_mapped": true, + "state_bound": true, + "state_attached": true, + "state_orphan": false, "pci_bdf": "0000:03:00.0", "pci_link_speed_str": "8 GT/s", "pci_link_width": 8, @@ -112,16 +126,37 @@ JSON output } } - [ # only present in card list mode - { - "id": 2, - "path": "/dev/nfb2", - "pci_bdf": "0000:81:00.0", - "card_name": "FB2CGHH", - "serial_number": "144", - "project_name": "NDK_MINIMAL", - "project_variant": "100G2", - "project_version": "0.5.6" - }, - ... - ] + { # only present with -l and/or -p; each key is + # present only when the matching flag was given + "nfb": [ # -l: one entry per NFB device + { + "id": 2, + "path": "/dev/nfb2", + "pci_bdf": "0000:81:00.0", + "card_name": "FB2CGHH", + "serial_number": "144", + "project_name": "NDK_MINIMAL", + "project_variant": "100G2", + "project_version": "0.5.6", + "pcie_overall_state": "ok" + }, + ... + ], + "pci": [ # -p: one entry per PCIe endpoint + { + "pci_bdf": "0000:81:00.0", + "nfb_id": 2, + "ep_index": 0, + "pcie_link_speed": "16 GT/s", + "pcie_link_max_speed": "16 GT/s", + "pcie_link_width": 16, + "pcie_link_max_width": 16, + "state_degraded": false, + "state_mapped": true, + "state_bound": true, + "state_attached": true, + "state_orphan": false + }, + ... + ] + } diff --git a/libnfb/include/netcope/pci_ep.h b/libnfb/include/netcope/pci_ep.h new file mode 100644 index 00000000..6ecbe799 --- /dev/null +++ b/libnfb/include/netcope/pci_ep.h @@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Network component library - PCIe endpoint enumeration from firmware FDT + * + * Copyright (C) 2026 CESNET + * Author(s): + * Martin Spinler + */ + +#ifndef NETCOPE_PCI_EP_H +#define NETCOPE_PCI_EP_H + +#include +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Max endpoint index bit we track (PCI0 .. PCI31). */ +#define NFB_PCI_EP_MAX 32 + +/* Bitmask of endpoints implied by MI bus resources ("PCIx,BARy"). */ +static inline unsigned nfb_pci_ep_mask_by_mi_bus_nodes(const void *fdt) +{ + int node; + int pci_index, bar; + int proplen; + unsigned mask = 0; + const void *prop; + + if (fdt == NULL) + return 0; + + fdt_for_each_compatible_node(fdt, node, "netcope,bus,mi") { + prop = fdt_getprop(fdt, node, "resource", &proplen); + if (prop == NULL || proplen <= 0 || ((const char *)prop)[proplen - 1] != 0) + continue; + if (sscanf(prop, "PCI%d,BAR%d", &pci_index, &bar) != 2) + continue; + if (pci_index < 0 || pci_index >= NFB_PCI_EP_MAX) + continue; + mask |= 1u << pci_index; + } + + return mask; +} + +/* Bitmask of /system/device/endpointN nodes present in the FDT. */ +static inline unsigned nfb_pci_ep_mask_by_system_endpoints(const void *fdt) +{ + int node, subnode; + unsigned mask = 0; + const char *name; + char *end; + unsigned long idx; + + if (fdt == NULL) + return 0; + + node = fdt_path_offset(fdt, "/system/device/"); + if (node < 0) + return 0; + + fdt_for_each_subnode(subnode, fdt, node) { + name = fdt_get_name(fdt, subnode, NULL); + if (name == NULL || strncmp(name, "endpoint", 8) != 0) + continue; + idx = strtoul(name + 8, &end, 10); + if (end == name + 8 || *end != '\0' || idx >= NFB_PCI_EP_MAX) + continue; + mask |= 1u << idx; + } + + return mask; +} + +/* Number of endpoints implied by MI bus resources ("PCIx,BARy"). */ +static inline int nfb_pci_ep_count_by_mi_bus_nodes(const void *fdt) +{ + unsigned mask = nfb_pci_ep_mask_by_mi_bus_nodes(fdt); + int count = 0; + + while (mask) { + count += mask & 1u; + mask >>= 1; + } + return count; +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* NETCOPE_PCI_EP_H */ diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e2af4e78..0aaf82db 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -23,13 +23,15 @@ find_package(PkgConfig) pkg_check_modules(NCURSES REQUIRED ncurses) pkg_check_modules(ARCHIVE REQUIRED libarchive) +pkg_check_modules(PCI REQUIRED libpci) ndk_check_build_dependency(FDT_LIBRARIES fdt FDT_INCLUDE_DIRS libfdt.h libfdt) ndk_check_build_dependency(NUMA_LIBRARIES numa NUMA_INCLUDE_DIRS numa.h) link_libraries(nfb ${FDT_LIBRARIES}) include_directories(${CMAKE_CURRENT_LIST_DIR}/../drivers/kernel/include) -add_executable(nfb-info info/info.c) +add_executable(nfb-info info/info.c info/pci.c) +target_link_libraries(nfb-info PRIVATE ${PCI_LIBRARIES}) target_compile_definitions(nfb-info PRIVATE PACKAGE_VERSION="${PACKAGE_VERSION}-${GIT_VERSION_RELEASE}") add_executable(nfb-boot boot/boot.c) diff --git a/tools/info/info.c b/tools/info/info.c index fa7e39b8..d70530e2 100644 --- a/tools/info/info.c +++ b/tools/info/info.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -26,10 +27,14 @@ #include #include #include +#include #include +#include -#define ARGUMENTS "d:q:hjlvV" +#include "pci.h" + +#define ARGUMENTS "d:q:hjlpvV" #define BUFFER_SIZE 64 @@ -101,13 +106,39 @@ void usage(const char *progname, int verbose) printf(" example of usage: '-q project,build,card'\n"); } printf("-l Print list of available devices\n"); + printf("-p Print PCI endpoint table (can be combined with -l, e.g. -lp)\n"); printf("-j Print output in JSON\n"); printf("-v Increase verbosity\n"); printf("-V Show version\n"); printf("-h Show this text\n"); } -NI_DEFAULT_ITEMS(ni_common_item_callbacks, ) +/* JSON booleans for the state_* fields; unused in user mode (text-suppressed). */ +static int ni_print_bool_json(void *priv, int item, int val) +{ + struct ni_json_cbp *p = priv; + (void) item; + return fprintf(p->f, val ? "true" : "false"); +} + +struct ni_info_item_f_t { + struct ni_common_item_callbacks c; + int (*print_bool)(void *, int, int); +}; + +struct ni_info_item_f_t ni_info_item_f[] = { + [NI_DRC_USER] = { + .c = ni_common_item_callbacks[NI_DRC_USER], + .print_bool = ni_def_print_int_user, + }, + [NI_DRC_JSON] = { + .c = ni_common_item_callbacks[NI_DRC_JSON], + .print_bool = ni_print_bool_json, + }, +}; + +NI_DEFAULT_ITEMS(ni_info_item_f_t, c.) +NI_ITEM_CB(bool, int, ni_info_item_f_t, print_bool) enum NI_ITEMS { @@ -144,9 +175,16 @@ enum NI_ITEMS { NI_ETH_CHANNEL_ID, NI_ETH_CHANNEL_TYPE, NI_SEC0_SYSTEM, + NI_SYSTEM_PCI_STATE, /* overall PCIe state (text + JSON string) */ NI_SEC1_PCIEP, NI_LIST_PCIEP, NI_PCI_ID, + NI_PCI_STATE_T, /* combined state text */ + NI_PCI_STATE_DEGRADED, /* JSON only */ + NI_PCI_STATE_MAPPED, /* JSON only */ + NI_PCI_STATE_BOUND, /* JSON only */ + NI_PCI_STATE_ATTACHED, /* JSON only */ + NI_PCI_STATE_ORPHAN, /* JSON only */ NI_PCI_SLOT, NI_PCI_LINK_SPEED, NI_PCI_LINK_WIDTH, @@ -168,7 +206,28 @@ enum NI_ITEMS { NI_L_PROJECT_NAME, NI_L_PROJECT_VAR, NI_L_PROJECT_VER, + NI_L_PCI_STATE, NI_L_PROJECT_END, + + /* PCI device list (-p, PCI-centric) */ + NI_LIST_PCI, + NI_SEC_LIST_PCI, + NI_PL_PCI_BDF, + NI_PL_NFB_ID, + NI_PL_EP_INDEX, + NI_PL_LINK_SPEED, /* current link speed (JSON only) */ + NI_PL_LINK_SPEED_MAX, /* max link speed (JSON only) */ + NI_PL_LINK_SPEED_T, /* combined "cur/max" speed (text only) */ + NI_PL_LINK_WIDTH, /* current link width (JSON only) */ + NI_PL_LINK_WIDTH_MAX, /* max link width (JSON only) */ + NI_PL_LINK_WIDTH_T, /* combined "cur/max" width (text only) */ + NI_PL_STATE_T, /* combined state text */ + NI_PL_STATE_DEGRADED, /* JSON only */ + NI_PL_STATE_MAPPED, /* JSON only */ + NI_PL_STATE_BOUND, /* JSON only */ + NI_PL_STATE_ATTACHED, /* JSON only */ + NI_PL_STATE_ORPHAN, /* JSON only */ + NI_PL_END, /* text-only: row newline */ }; #define NUF_N (NI_USER_ITEM_F_NO_NEWLINE) @@ -219,9 +278,16 @@ struct ni_context_item_default ni_items[] = { [NI_ETH_CHANNEL_TYPE] = {ni_json_k("type"), ni_user_l("")}, [NI_SEC0_SYSTEM] = {ni_json_k("system"), ni_user_l("System info")}, + [NI_SYSTEM_PCI_STATE] = {ni_json_k("pcie_overall_state"), ni_user_l("Overall PCIe state")}, [NI_SEC1_PCIEP] = {ni_json_e, ni_user_l(NULL)}, [NI_LIST_PCIEP] = {ni_json_k("pci"), ni_user_l(NULL)}, [NI_PCI_ID] = {ni_json_k("id"), ni_user_v("PCIe Endpoint ", NUF_DA, NULL, ":")}, + [NI_PCI_STATE_T] = {ni_json_n, ni_user_l(" * state")}, + [NI_PCI_STATE_DEGRADED] = {ni_json_k("state_degraded"), ni_user_n}, + [NI_PCI_STATE_MAPPED] = {ni_json_k("state_mapped"), ni_user_n}, + [NI_PCI_STATE_BOUND] = {ni_json_k("state_bound"), ni_user_n}, + [NI_PCI_STATE_ATTACHED] = {ni_json_k("state_attached"), ni_user_n}, + [NI_PCI_STATE_ORPHAN] = {ni_json_k("state_orphan"), ni_user_n}, [NI_PCI_SLOT] = {ni_json_k("pci_bdf"), ni_user_l(" * PCI slot")}, [NI_PCI_LINK_SPEED] = {ni_json_k("pci_link_speed_str"), ni_user_l(" * PCI link speed")}, [NI_PCI_LINK_WIDTH] = {ni_json_k("pci_link_width"), ni_user_v(" * PCI link width", 0, "x", NULL)}, @@ -233,20 +299,43 @@ struct ni_context_item_default ni_items[] = { [NI_BAR_SIZE] = {ni_json_k("size"), ni_user_n}, /* Card list */ - [NI_LIST_NFB] = {ni_json_k("card_list"), - ni_user_v("ID Base path PCI address Card name Serial number Firmware info - project", 0, NULL, "\n")}, + [NI_LIST_NFB] = {ni_json_k("nfb"), + ni_user_v("ID Base path PCI address Card name Serial number PCIe Firmware info - project", 0, NULL, "\n")}, [NI_SEC_LIST_NFB] = {ni_json_e, ni_user_v(NULL, 0, NULL, " ")}, [NI_L_NFB_ID] = {ni_json_k("id"), ni_user_f("", NUF_NDA | NUFW(2))}, [NI_L_LPATH] = {ni_json_k("path"), ni_user_v("", NUF_NDA | NUFA(-10), " ", NULL)}, [NI_L_BFN] = {ni_json_k("pci_bdf"), ni_user_v("", NUF_NDA | NUFA(-12), " ", NULL)}, [NI_L_CARD_NAME] = {ni_json_k("card_name"), ni_user_v("", NUF_NDA | NUFA(-16), " ", NULL)}, [NI_L_SN] = {ni_json_k("serial_number"), ni_user_v("", NUF_NDA | NUFA(-14), " ", NULL)}, + [NI_L_PCI_STATE] = {ni_json_k("pcie_overall_state"), ni_user_v("", NUF_NDA | NUFA(-12), " ", NULL)}, [NI_L_PROJECT_NAME] = {ni_json_k("project_name"), ni_user_v("", NUF_NDA | NUFA(0), " ", NULL)}, [NI_L_PROJECT_VAR] = {ni_json_k("project_variant"), ni_user_v("", NUF_NDA | NUFA(0), " ", NULL)}, [NI_L_PROJECT_VER] = {ni_json_k("project_version"), ni_user_v("", NUF_NDA | NUFA(0), " ", NULL)}, [NI_L_PROJECT_END] = {ni_json_n, ni_user_f("", NUF_DAV)}, + + /* PCI device list */ + [NI_LIST_PCI] = {ni_json_k("pci"), + ni_user_v("PCI address NFB EP ID Speed cur/max Width cur/max State", 0, NULL, "\n")}, + [NI_SEC_LIST_PCI] = {ni_json_e, ni_user_v(NULL, 0, NULL, " ")}, + [NI_PL_PCI_BDF] = {ni_json_k("pci_bdf"), ni_user_v("", NUF_NDA | NUFA(-12), "", NULL)}, + [NI_PL_NFB_ID] = {ni_json_k("nfb_id"), ni_user_v("", NUF_NDA | NUFA(4), " ", NULL)}, + [NI_PL_EP_INDEX] = {ni_json_k("ep_index"), ni_user_v("", NUF_NDA | NUFA(5), " ", NULL)}, + [NI_PL_LINK_SPEED] = {ni_json_k("pcie_link_speed"), ni_user_n}, + [NI_PL_LINK_SPEED_MAX] = {ni_json_k("pcie_link_max_speed"), ni_user_n}, + [NI_PL_LINK_SPEED_T] = {ni_json_n, ni_user_v("", NUF_NDA | NUFA(13), " ", NULL)}, + [NI_PL_LINK_WIDTH] = {ni_json_k("pcie_link_width"), ni_user_n}, + [NI_PL_LINK_WIDTH_MAX] = {ni_json_k("pcie_link_max_width"), ni_user_n}, + [NI_PL_LINK_WIDTH_T] = {ni_json_n, ni_user_v("", NUF_NDA | NUFA(13), " ", NULL)}, + [NI_PL_STATE_T] = {ni_json_n, ni_user_v("", NUF_NDA | NUFA(-24), " ", NULL)}, + [NI_PL_STATE_DEGRADED] = {ni_json_k("state_degraded"), ni_user_n}, + [NI_PL_STATE_MAPPED] = {ni_json_k("state_mapped"), ni_user_n}, + [NI_PL_STATE_BOUND] = {ni_json_k("state_bound"), ni_user_n}, + [NI_PL_STATE_ATTACHED] = {ni_json_k("state_attached"), ni_user_n}, + [NI_PL_STATE_ORPHAN] = {ni_json_k("state_orphan"), ni_user_n}, + [NI_PL_END] = {ni_json_n, ni_user_f("", NUF_DAV)}, }; + void print_version() { #ifdef PACKAGE_VERSION @@ -266,26 +355,136 @@ int filter_nfbs(const struct dirent *dir) return 1; } -void print_device_list(struct ni_context *ctx) +struct paired_ep { + char bdf[16]; + int nfb_id; + int ep_index; + int state; + int listed; +}; + +static void ni_emit_state_flags(struct ni_context *ctx, int flags, + int item_text, int item_degraded, int item_mapped, + int item_bound, int item_attached, int item_orphan) +{ + char buf[64]; + int attached = !(flags & EP_ST_NOT_ATTACHED); + int bound = attached && !(flags & EP_ST_NOT_BOUND); + int mapped = bound && !(flags & EP_ST_UNMAPPED); + + ep_state_format(flags, buf, sizeof(buf)); + ni_item_str(ctx, item_text, buf); + ni_item_bool(ctx, item_degraded, !!(flags & EP_ST_DEGRADED)); + ni_item_bool(ctx, item_mapped, mapped); + ni_item_bool(ctx, item_bound, bound); + ni_item_bool(ctx, item_attached, attached); + ni_item_bool(ctx, item_orphan, !!(flags & EP_ST_ORPHAN)); +} + +static void print_pci_list_row(struct ni_context *ctx, struct pci_access *pacc, + const char *bdf, int nfb_id, int ep_index, int state) +{ + struct ep_state_link_info li; + char speed_text[24], width_text[16]; + char cur_num[8], max_num[8]; + char cur_tok[8], max_tok[8]; + char id_str[16]; + int ep_id; + + ni_section(ctx, NI_SEC_LIST_PCI); + + ni_item_str(ctx, NI_PL_PCI_BDF, bdf && bdf[0] ? bdf : "?"); + + if (nfb_id >= 0) { + snprintf(id_str, sizeof(id_str), "%d", nfb_id); + ni_item_str(ctx, NI_PL_NFB_ID, id_str); + } else { + ni_item_str(ctx, NI_PL_NFB_ID, "-"); + } + + ep_id = ep_index; + if (ep_id < 0 && pacc && bdf && bdf[0]) + ep_id = ep_state_read_endpoint_id(pacc, bdf); + if (ep_id >= 0) { + snprintf(id_str, sizeof(id_str), "%d", ep_id); + ni_item_str(ctx, NI_PL_EP_INDEX, id_str); + } else { + ni_item_str(ctx, NI_PL_EP_INDEX, "?"); + } + + memset(&li, 0, sizeof(li)); + if (bdf && bdf[0] && !(state & EP_ST_NOT_ATTACHED)) + ep_state_fill_link(pacc, bdf, &li); + + ni_item_str(ctx, NI_PL_LINK_SPEED, li.speed); + ni_item_str(ctx, NI_PL_LINK_SPEED_MAX, li.max_speed); + ni_item_int(ctx, NI_PL_LINK_WIDTH, li.width[0] ? atoi(li.width) : -1); + ni_item_int(ctx, NI_PL_LINK_WIDTH_MAX, li.max_width[0] ? atoi(li.max_width) : -1); + + if (li.speed[0] || li.max_speed[0] || li.width[0] || li.max_width[0]) { + snprintf(speed_text, sizeof(speed_text), "%2s/%2s GT/s", + ep_state_link_number(li.speed, cur_num, sizeof(cur_num)), + ep_state_link_number(li.max_speed, max_num, sizeof(max_num))); + ni_item_str(ctx, NI_PL_LINK_SPEED_T, speed_text); + + snprintf(cur_tok, sizeof(cur_tok), "x%.6s", ep_state_str_or_unknown(li.width)); + snprintf(max_tok, sizeof(max_tok), "x%.6s", ep_state_str_or_unknown(li.max_width)); + snprintf(width_text, sizeof(width_text), "%s/%3s", cur_tok, max_tok); + ni_item_str(ctx, NI_PL_LINK_WIDTH_T, width_text); + } else { + ni_item_str(ctx, NI_PL_LINK_SPEED_T, "-"); + ni_item_str(ctx, NI_PL_LINK_WIDTH_T, "-"); + } + + ni_emit_state_flags(ctx, state, + NI_PL_STATE_T, NI_PL_STATE_DEGRADED, NI_PL_STATE_MAPPED, + NI_PL_STATE_BOUND, NI_PL_STATE_ATTACHED, NI_PL_STATE_ORPHAN); + + ni_item_int(ctx, NI_PL_END, 0); + ni_endsection(ctx, NI_SEC_LIST_PCI); +} + +/* Returns 1 if any PCIe endpoint looks incomplete. Endpoint discovery always + * runs, even with show_nfb off, since show_pci needs the nfb-id pairing. */ +int print_device_list(struct ni_context *ctx, int js, int show_nfb, int show_pci) { int ret; int len; int fdt_offset, fdt_off_slot; - int cnt, i; + int cnt, i, j; + int incomplete_pci = 0; + int pci_scanned; struct dirent *dir; struct dirent **namelist; + struct dirent **pcinamelist; struct nc_composed_device_info info; struct nfb_device *dev; + struct pci_access *pacc = NULL; char path[NFB_PATH_MAXLEN]; char lpath[PATH_MAX]; + char state_buf[64]; const void *fdt; - const char *prop; + const char *cprop; const uint32_t *prop32; - ni_list(ctx, NI_LIST_NFB); + struct paired_ep *paired = NULL; + int paired_cnt = 0; + int paired_cap = 0; + + struct ep_state_desc eps[NFB_PCI_EP_MAX]; + int ep_cnt; + int card_overall; + + if (access("/sys/module/nfb", F_OK) != 0) + warnx("NFB kernel module is not loaded (/sys/module/nfb not found)"); + + ni_section(ctx, NI_SEC_ROOT); + + if (show_nfb) + ni_list(ctx, NI_LIST_NFB); cnt = scandir("/dev/nfb/", &namelist, filter_nfbs, alphasort); for (i = 0; i < cnt; i++) { dir = namelist[i]; @@ -293,47 +492,174 @@ void print_device_list(struct ni_context *ctx) snprintf(lpath, PATH_MAX, "/dev/nfb%s", dir->d_name); dev = nfb_open(lpath); if (dev) { - ni_section(ctx, NI_SEC_LIST_NFB); + if (show_nfb) + ni_section(ctx, NI_SEC_LIST_NFB); fdt = nfb_get_fdt(dev); fdt_offset = fdt_path_offset(fdt, "/firmware/"); fdt_off_slot = fdt_path_offset(fdt, "/system/device/endpoint0/"); + /* nfb_id is needed even without show_nfb, for paired[].nfb_id */ ret = nc_get_composed_device_info_by_pci(dev, NULL, &info); - ni_item_int(ctx, NI_L_NFB_ID, ret == 0 ? info.nfb_id : -1); - ni_item_str(ctx, NI_L_LPATH, lpath); - ni_fdt_prop_str(ctx, NI_L_BFN, fdt, fdt_off_slot, "pci-slot", &len); - ni_fdt_prop_str(ctx, NI_L_CARD_NAME, fdt, fdt_offset, "card-name", &len); + if (show_nfb) { + ni_item_int(ctx, NI_L_NFB_ID, ret == 0 ? info.nfb_id : -1); + ni_item_str(ctx, NI_L_LPATH, lpath); + ni_fdt_prop_str(ctx, NI_L_BFN, fdt, fdt_off_slot, "pci-slot", &len); + ni_fdt_prop_str(ctx, NI_L_CARD_NAME, fdt, fdt_offset, "card-name", &len); + } fdt_offset = fdt_path_offset(fdt, "/board/"); - prop = NULL; + cprop = NULL; prop32 = fdt_getprop(fdt, fdt_offset, "serial-number", &len); if (len == sizeof(*prop32)) { snprintf(path, NFB_PATH_MAXLEN, "%d", fdt32_to_cpu(*prop32)); - prop = path; + cprop = path; } else { - prop = fdt_getprop(fdt, fdt_offset, "serial-number-string", &len); + cprop = fdt_getprop(fdt, fdt_offset, "serial-number-string", &len); + } + if (show_nfb && cprop) + ni_item_str(ctx, NI_L_SN, cprop); + + card_overall = 0; + ep_cnt = 0; + if (ret == 0) { + ep_cnt = ep_state_collect(fdt, eps, NFB_PCI_EP_MAX, &card_overall); + if (ep_state_is_structural(card_overall)) + incomplete_pci = 1; + + for (j = 0; j < ep_cnt; j++) { + if (paired_cnt == paired_cap) { + struct paired_ep *tmp; + int new_cap = paired_cap ? paired_cap * 2 : 8; + + tmp = realloc(paired, new_cap * sizeof(*paired)); + if (tmp == NULL) { + warnx("out of memory while collecting PCI endpoints"); + } else { + paired = tmp; + paired_cap = new_cap; + } + } + if (paired_cnt < paired_cap) { + snprintf(paired[paired_cnt].bdf, sizeof(paired[0].bdf), + "%s", eps[j].bdf); + paired[paired_cnt].nfb_id = info.nfb_id; + paired[paired_cnt].ep_index = eps[j].index; + paired[paired_cnt].state = eps[j].state; + paired[paired_cnt].listed = 0; + paired_cnt++; + } + } + } + + if (show_nfb) { + ep_state_format(card_overall, state_buf, sizeof(state_buf)); + ni_item_str(ctx, NI_L_PCI_STATE, state_buf); + + fdt_offset = fdt_path_offset(fdt, "/firmware/"); + ni_fdt_prop_str(ctx, NI_L_PROJECT_NAME, fdt, fdt_offset, "project-name", &len); + ni_fdt_prop_str(ctx, NI_L_PROJECT_VAR, fdt, fdt_offset, "project-variant", &len); + ni_fdt_prop_str(ctx, NI_L_PROJECT_VER, fdt, fdt_offset, "project-version", &len); + ni_item_int(ctx, NI_L_PROJECT_END, 0); } - if (prop) - ni_item_str(ctx, NI_L_SN, prop); - fdt_offset = fdt_path_offset(fdt, "/firmware/"); - ni_fdt_prop_str(ctx, NI_L_PROJECT_NAME, fdt, fdt_offset, "project-name", &len); - ni_fdt_prop_str(ctx, NI_L_PROJECT_VAR, fdt, fdt_offset, "project-variant", &len); - ni_fdt_prop_str(ctx, NI_L_PROJECT_VER, fdt, fdt_offset, "project-version", &len); - ni_item_int(ctx, NI_L_PROJECT_END, 0); nfb_close(dev); - ni_endsection(ctx, NI_SEC_LIST_NFB); + if (show_nfb) + ni_endsection(ctx, NI_SEC_LIST_NFB); } free(dir); } if (cnt >= 0) free(namelist); - ni_endlist(ctx, NI_LIST_NFB); + if (show_nfb) + ni_endlist(ctx, NI_LIST_NFB); + + /* PCI devices: driver-bound + FDT-known but unbound */ + if (show_pci) { + pacc = pci_alloc(); + if (pacc) + pci_init(pacc); + } + + pci_scanned = scandir(NFB_PCI_DRIVER_DIR, &pcinamelist, ep_state_bdf_filter, alphasort); + cnt = pci_scanned < 0 ? 0 : pci_scanned; + + if (show_pci) { + /* Separate from the nfb list above; standalone -p needs no lead-in. */ + if (show_nfb && js == NI_DRC_USER) + printf("\n"); + ni_list(ctx, NI_LIST_PCI); + } + + for (i = 0; i < cnt; i++) { + int found = -1; + int state; + + dir = pcinamelist[i]; + + for (j = 0; j < paired_cnt; j++) { + if (paired[j].bdf[0] && strcmp(paired[j].bdf, dir->d_name) == 0) { + found = j; + break; + } + } + + if (found >= 0) { + state = paired[found].state; + paired[found].listed = 1; + } else { + state = ep_state_classify(NULL, -1, dir->d_name, 1); + if (ep_state_is_structural(state)) + incomplete_pci = 1; + } + + if (ep_state_is_structural(state)) + incomplete_pci = 1; + + if (show_pci) { + print_pci_list_row(ctx, pacc, dir->d_name, + found >= 0 ? paired[found].nfb_id : -1, + found >= 0 ? paired[found].ep_index : -1, + state); + } + free(dir); + } + if (pci_scanned >= 0) + free(pcinamelist); + + /* FDT endpoints not present in the driver directory */ + if (show_pci) { + for (j = 0; j < paired_cnt; j++) { + if (paired[j].listed) + continue; + if (ep_state_is_structural(paired[j].state)) + incomplete_pci = 1; + print_pci_list_row(ctx, pacc, + paired[j].bdf[0] ? paired[j].bdf : "?", + paired[j].nfb_id, paired[j].ep_index, + paired[j].state); + } + } else { + for (j = 0; j < paired_cnt; j++) { + if (ep_state_is_structural(paired[j].state)) + incomplete_pci = 1; + } + } + + if (show_pci) + ni_endlist(ctx, NI_LIST_PCI); + + if (pacc) + pci_cleanup(pacc); + + free(paired); + + ni_endsection(ctx, NI_SEC_ROOT); + return incomplete_pci; } int print_specific_info(struct nfb_device *dev, int query) @@ -463,28 +789,32 @@ void sprint_size(char *str, unsigned long size) sprintf(str, "%lu %s", size, units[i]); } -void print_endpoint_info(struct nfb_device *dev, int fdt_offset, struct ni_context *ctx) +void print_endpoint_info(struct nfb_device *dev, int fdt_offset, int ep_index, + int state_flags, struct ni_context *ctx) { int len; int bar; - int dev_id = -1; uint64_t bar_size; const uint32_t *prop32; const uint64_t *prop64; const void *fdt; - const char* node_name; char nodename[64]; + const char *bdf = NULL; fdt = nfb_get_fdt(dev); - node_name = fdt_get_name(fdt, fdt_offset, NULL); - if (node_name && strlen(node_name) > 8 && strncmp(node_name, "endpoint", 8) == 0) { - dev_id = strtoul(node_name+8, NULL, 10); - } + ni_item_int(ctx, NI_PCI_ID, ep_index); + ni_emit_state_flags(ctx, state_flags, + NI_PCI_STATE_T, NI_PCI_STATE_DEGRADED, NI_PCI_STATE_MAPPED, + NI_PCI_STATE_BOUND, NI_PCI_STATE_ATTACHED, NI_PCI_STATE_ORPHAN); - ni_item_int(ctx, NI_PCI_ID, dev_id); + if (fdt_offset < 0) + return; + + bdf = fdt_getprop(fdt, fdt_offset, "pci-slot", &len); + if (bdf) + ni_item_str(ctx, NI_PCI_SLOT, bdf); - ni_fdt_prop_str(ctx, NI_PCI_SLOT, fdt, fdt_offset, "pci-slot", &len); prop32 = fdt_getprop(fdt, fdt_offset, "pci-speed", &len); if (prop32) ni_item_str(ctx, NI_PCI_LINK_SPEED, pci_speed_string(fdt32_to_cpu(*prop32))); @@ -493,7 +823,7 @@ void print_endpoint_info(struct nfb_device *dev, int fdt_offset, struct ni_conte ni_list(ctx, NI_LIST_PCI_BAR); for (bar = 0; bar < 6; bar++) { - snprintf(nodename, sizeof(nodename), "/drivers/mi/PCI%d,BAR%d", dev_id, bar); + snprintf(nodename, sizeof(nodename), "/drivers/mi/PCI%d,BAR%d", ep_index, bar); fdt_offset = fdt_path_offset(fdt, nodename); if (fdt_offset >= 0) { ni_section(ctx, NI_SEC2_PCI_BAR); @@ -525,6 +855,10 @@ void print_common_info(struct nfb_device *dev, int verbose, struct ni_context *c const void *prop; const uint32_t *prop32; const void *fdt; + int overall; + int ep_cnt; + struct ep_state_desc eps[NFB_PCI_EP_MAX]; + char state_buf[64]; char buffer[BUFFER_SIZE]; time_t build_time; @@ -632,12 +966,15 @@ void print_common_info(struct nfb_device *dev, int verbose, struct ni_context *c ni_endsection(ctx, NI_SEC0_FIRMWARE); ni_section(ctx, NI_SEC0_SYSTEM); - fdt_offset = fdt_path_offset(fdt, "/system/device/"); + + ep_cnt = ep_state_collect(fdt, eps, NFB_PCI_EP_MAX, &overall); + ep_state_format(overall, state_buf, sizeof(state_buf)); + ni_item_str(ctx, NI_SYSTEM_PCI_STATE, state_buf); ni_list(ctx, NI_LIST_PCIEP); - fdt_for_each_subnode(node, fdt, fdt_offset) { + for (i = 0; i < ep_cnt; i++) { ni_section(ctx, NI_SEC1_PCIEP); - print_endpoint_info(dev, node, ctx); + print_endpoint_info(dev, eps[i].fdt_offset, eps[i].index, eps[i].state, ctx); ni_endsection(ctx, NI_SEC1_PCIEP); } ni_endlist(ctx, NI_LIST_PCIEP); @@ -659,6 +996,8 @@ int main(int argc, char *argv[]) enum commands command = CMD_PRINT_STATUS; int verbose = 0; + int show_nfb = 0; + int show_pci = 0; while ((c = getopt(argc, argv, ARGUMENTS)) != -1) { switch (c) { @@ -670,6 +1009,11 @@ int main(int argc, char *argv[]) break; case 'l': command = CMD_LIST; + show_nfb = 1; + break; + case 'p': + command = CMD_LIST; + show_pci = 1; break; case 'v': verbose++; @@ -696,9 +1040,15 @@ int main(int argc, char *argv[]) return 0; } else if (command == CMD_LIST) { struct ni_context *ctx; - ctx = ni_init_root_context_default(js, ni_items, &ni_common_item_callbacks[js]); - print_device_list(ctx); + int incomplete_pci; + + ctx = ni_init_root_context_default(js, ni_items, &ni_info_item_f[js]); + incomplete_pci = print_device_list(ctx, js, show_nfb, show_pci); ni_close_root_context(ctx); + if (incomplete_pci && !show_pci && js == NI_DRC_USER) { + warnx("some PCIe endpoints are not covered in the table; " + "pass -p to list PCI endpoints"); + } return 0; } @@ -730,7 +1080,7 @@ int main(int argc, char *argv[]) free(index); } else { struct ni_context *ctx; - ctx = ni_init_root_context_default(js, ni_items, &ni_common_item_callbacks[js]); + ctx = ni_init_root_context_default(js, ni_items, &ni_info_item_f[js]); ni_section(ctx, NI_SEC_ROOT); print_common_info(dev, verbose, ctx); diff --git a/tools/info/pci.c b/tools/info/pci.c new file mode 100644 index 00000000..c2a3da34 --- /dev/null +++ b/tools/info/pci.c @@ -0,0 +1,355 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * PCIe endpoint status: sysfs/libpci probing and attach/bind/map/link + * state classification for nfb-info's device and PCI listings. + * + * Copyright (C) 2026 CESNET + * Author(s): + * Martin Spinler + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "pci.h" + +#define PCI_SYSFS_PREFIX "/sys/bus/pci/devices/" + +/* VSEC header used by NFB cards for DTB/endpoint info. */ +#define NFB_PCI_VSEC_HEADER 0x02010D7B + +int ep_state_bdf_filter(const struct dirent *dir) +{ + return strchr(dir->d_name, ':') != NULL; +} + +static int read_sysfs_string(const char *path, char *buf, size_t buflen) +{ + int fd; + ssize_t n; + + fd = open(path, O_RDONLY); + if (fd < 0) + return -1; + n = read(fd, buf, buflen - 1); + close(fd); + if (n <= 0) + return -1; + buf[n] = '\0'; + while (n > 0 && (buf[n-1] == '\n' || buf[n-1] == '\r' || + buf[n-1] == ' ' || buf[n-1] == '\t')) + buf[--n] = '\0'; + return 0; +} + +void ep_state_format(int flags, char *buf, size_t buflen) +{ + size_t n = 0; + + if (buflen == 0) + return; + buf[0] = '\0'; + if (flags == 0) { + snprintf(buf, buflen, "ok"); + return; + } + +#define EP_ST_ADD(bit, name) do { \ + if (flags & (bit)) { \ + n += snprintf(buf + n, buflen > n ? buflen - n : 0, "%s%s", \ + n ? "," : "", (name)); \ + } \ +} while (0) + + EP_ST_ADD(EP_ST_NOT_ATTACHED, "unattached"); + EP_ST_ADD(EP_ST_NOT_BOUND, "unbound"); + EP_ST_ADD(EP_ST_UNMAPPED, "unmapped"); + EP_ST_ADD(EP_ST_DEGRADED, "degraded"); + EP_ST_ADD(EP_ST_ORPHAN, "orphan"); +#undef EP_ST_ADD +} + +static int pci_bdf_bound_to_nfb(const char *bdf) +{ + char path[PATH_MAX]; + + if (bdf == NULL || bdf[0] == '\0') + return 0; + snprintf(path, sizeof(path), NFB_PCI_DRIVER_DIR "%s", bdf); + return access(path, F_OK) == 0; +} + +static int endpoint_has_unmapped_bars(const void *fdt, int ep_index) +{ + int bar, off, len; + const uint64_t *prop64; + char path[64]; + + if (fdt == NULL || ep_index < 0) + return 0; + + for (bar = 0; bar < 6; bar++) { + snprintf(path, sizeof(path), "/drivers/mi/PCI%d,BAR%d", ep_index, bar); + off = fdt_path_offset(fdt, path); + if (off < 0) + continue; + prop64 = fdt_getprop(fdt, off, "mmap_size", &len); + if (len != sizeof(*prop64) || fdt64_to_cpu(*prop64) == 0) + return 1; + } + return 0; +} + +/* "16.0 GT/s PCIe" -> "16 GT/s", to match pci_speed_string() */ +static void normalize_speed(char *s) +{ + char *p; + + p = strstr(s, " PCIe"); + if (p) + *p = '\0'; + + p = strstr(s, ".0 "); + if (p) + memmove(p, p + 2, strlen(p + 2) + 1); +} + +static void read_pci_link(const char *bdf, struct ep_state_link_info *li) +{ + char spath[PATH_MAX]; + + li->speed[0] = '\0'; + li->width[0] = '\0'; + li->max_speed[0] = '\0'; + li->max_width[0] = '\0'; + + snprintf(spath, sizeof(spath), PCI_SYSFS_PREFIX "%s/current_link_speed", bdf); + if (read_sysfs_string(spath, li->speed, sizeof(li->speed)) == 0) + normalize_speed(li->speed); + + snprintf(spath, sizeof(spath), PCI_SYSFS_PREFIX "%s/current_link_width", bdf); + read_sysfs_string(spath, li->width, sizeof(li->width)); + + snprintf(spath, sizeof(spath), PCI_SYSFS_PREFIX "%s/max_link_speed", bdf); + if (read_sysfs_string(spath, li->max_speed, sizeof(li->max_speed)) == 0) + normalize_speed(li->max_speed); + + snprintf(spath, sizeof(spath), PCI_SYSFS_PREFIX "%s/max_link_width", bdf); + read_sysfs_string(spath, li->max_width, sizeof(li->max_width)); +} + +static int pci_link_degraded(const char *bdf) +{ + struct ep_state_link_info li; + int speed_known, width_known; + + if (bdf == NULL || bdf[0] == '\0') + return 0; + + read_pci_link(bdf, &li); + speed_known = li.speed[0] && li.max_speed[0]; + width_known = li.width[0] && li.max_width[0]; + return (speed_known && strcmp(li.speed, li.max_speed) != 0) || + (width_known && strcmp(li.width, li.max_width) != 0); +} + +int ep_state_classify(const void *fdt, int ep_index, const char *bdf, int orphan) +{ + int flags = 0; + + if (orphan) + flags |= EP_ST_ORPHAN; + + if (bdf == NULL || bdf[0] == '\0') { + flags |= EP_ST_NOT_ATTACHED; + return flags; + } + + if (!pci_bdf_bound_to_nfb(bdf)) + flags |= EP_ST_NOT_BOUND; + + if (!(flags & (EP_ST_NOT_BOUND | EP_ST_NOT_ATTACHED)) && + endpoint_has_unmapped_bars(fdt, ep_index)) + flags |= EP_ST_UNMAPPED; + + if (!(flags & EP_ST_NOT_BOUND) && pci_link_degraded(bdf)) + flags |= EP_ST_DEGRADED; + + return flags; +} + +/* eps[] = expected ∪ FDT endpoints; *overall = OR of all states */ +int ep_state_collect(const void *fdt, struct ep_state_desc *eps, int max, int *overall) +{ + unsigned mask; + int ep_index; + int count = 0; + int ovr = 0; + + mask = nfb_pci_ep_mask_by_mi_bus_nodes(fdt) | nfb_pci_ep_mask_by_system_endpoints(fdt); + for (ep_index = 0; ep_index < NFB_PCI_EP_MAX && count < max; ep_index++) { + char ep_path[64]; + const char *bdf = NULL; + int node = -1; + int state; + + if (!(mask & (1u << ep_index))) + continue; + + snprintf(ep_path, sizeof(ep_path), "/system/device/endpoint%d", ep_index); + node = fdt_path_offset(fdt, ep_path); + if (node >= 0) + bdf = fdt_getprop(fdt, node, "pci-slot", NULL); + + state = ep_state_classify(fdt, ep_index, bdf, 0); + eps[count].index = ep_index; + eps[count].fdt_offset = node; + snprintf(eps[count].bdf, sizeof(eps[0].bdf), "%s", bdf ? bdf : ""); + eps[count].state = state; + ovr |= state; + count++; + } + + if (overall) + *overall = ovr; + return count; +} + +static const char *pcie_speed_mts(unsigned code) +{ + switch (code) { + case 1: return "2.5 GT/s"; + case 2: return "5 GT/s"; + case 3: return "8 GT/s"; + case 4: return "16 GT/s"; + case 5: return "32 GT/s"; + case 6: return "64 GT/s"; + default: return NULL; + } +} + +/* config-space fallback, works even when unbound from nfb */ +static void read_pci_link_libpci(struct pci_access *pacc, const char *bdf, struct ep_state_link_info *li) +{ + struct pci_dev *dev; + struct pci_cap *cap; + unsigned int domain, bus, devno, func; + u32 lnkcap; + u16 lnksta; + const char *speed; + unsigned width; + + if (pacc == NULL || bdf == NULL || bdf[0] == '\0') + return; + if (sscanf(bdf, "%x:%x:%x.%x", &domain, &bus, &devno, &func) != 4) + return; + + dev = pci_get_dev(pacc, domain, bus, devno, func); + if (!dev) + return; + pci_fill_info(dev, PCI_FILL_CAPS); + + cap = pci_find_cap(dev, PCI_CAP_ID_EXP, PCI_CAP_NORMAL); + if (!cap) + goto out; + + lnkcap = pci_read_long(dev, cap->addr + PCI_EXP_LNKCAP); + lnksta = pci_read_word(dev, cap->addr + PCI_EXP_LNKSTA); + + if (li->speed[0] == '\0') { + speed = pcie_speed_mts(lnksta & PCI_EXP_LNKSTA_SPEED); + if (speed) + snprintf(li->speed, sizeof(li->speed), "%s", speed); + } + if (li->max_speed[0] == '\0') { + speed = pcie_speed_mts(lnkcap & PCI_EXP_LNKCAP_SPEED); + if (speed) + snprintf(li->max_speed, sizeof(li->max_speed), "%s", speed); + } + if (li->width[0] == '\0') { + width = (lnksta & PCI_EXP_LNKSTA_WIDTH) >> 4; + if (width) + snprintf(li->width, sizeof(li->width), "%u", width); + } + if (li->max_width[0] == '\0') { + width = (lnkcap & PCI_EXP_LNKCAP_WIDTH) >> 4; + if (width) + snprintf(li->max_width, sizeof(li->max_width), "%u", width); + } + +out: + pci_free_dev(dev); +} + +void ep_state_fill_link(struct pci_access *pacc, const char *bdf, struct ep_state_link_info *li) +{ + if (bdf == NULL || bdf[0] == '\0') { + memset(li, 0, sizeof(*li)); + return; + } + + read_pci_link(bdf, li); + if (li->speed[0] == '\0' || li->width[0] == '\0' || + li->max_speed[0] == '\0' || li->max_width[0] == '\0') + read_pci_link_libpci(pacc, bdf, li); +} + +const char *ep_state_link_number(const char *str, char *buf, size_t buflen) +{ + const char *sp; + size_t len; + + if (str[0] == '\0') + return "?"; + + sp = strchr(str, ' '); + len = sp ? (size_t)(sp - str) : strlen(str); + if (len >= buflen) + len = buflen - 1; + memcpy(buf, str, len); + buf[len] = '\0'; + return buf; +} + +const char *ep_state_str_or_unknown(const char *str) +{ + return str[0] ? str : "?"; +} + +int ep_state_read_endpoint_id(struct pci_access *pacc, const char *bdf) +{ + struct pci_dev *dev; + struct pci_cap *cap; + unsigned int domain, bus, devno, func; + int ret = -1; + + if (sscanf(bdf, "%x:%x:%x.%x", &domain, &bus, &devno, &func) != 4) + return -1; + + dev = pci_get_dev(pacc, domain, bus, devno, func); + if (!dev) + return -1; + + cap = pci_find_cap(dev, PCI_EXT_CAP_ID_VNDR, PCI_CAP_EXTENDED); + while (cap) { + u32 vsec = pci_read_long(dev, cap->addr + 4); + if (vsec == NFB_PCI_VSEC_HEADER) { + u32 reg = pci_read_long(dev, cap->addr + 8); + if (reg & 0x80000000) + ret = reg & 0xf; + break; + } + cap = cap->next; + } + + pci_free_dev(dev); + return ret; +} diff --git a/tools/info/pci.h b/tools/info/pci.h new file mode 100644 index 00000000..74c92b9e --- /dev/null +++ b/tools/info/pci.h @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * PCIe endpoint status for nfb-info's device and PCI listings. + * + * Copyright (C) 2026 CESNET + * Author(s): + * Martin Spinler + */ + +#ifndef NFB_TOOLS_INFO_PCI_H +#define NFB_TOOLS_INFO_PCI_H + +#include +#include + +#include + +#include + +#define NFB_PCI_DRIVER_DIR "/sys/module/nfb/drivers/pci:nfb/" + +enum { + EP_ST_DEGRADED = 1 << 0, + EP_ST_UNMAPPED = 1 << 1, + EP_ST_NOT_BOUND = 1 << 2, + EP_ST_NOT_ATTACHED = 1 << 3, + EP_ST_ORPHAN = 1 << 4, +}; + +#define EP_ST_STRUCTURAL (EP_ST_NOT_ATTACHED | EP_ST_NOT_BOUND | EP_ST_UNMAPPED | EP_ST_ORPHAN) + +static inline int ep_state_is_structural(int flags) +{ + return flags & EP_ST_STRUCTURAL; +} + +struct ep_state_desc { + int index; + int fdt_offset; + char bdf[16]; + int state; +}; + +struct ep_state_link_info { + char speed[32]; + char width[24]; + char max_speed[32]; + char max_width[24]; +}; + +int ep_state_bdf_filter(const struct dirent *dir); +void ep_state_format(int flags, char *buf, size_t buflen); +int ep_state_classify(const void *fdt, int ep_index, const char *bdf, int orphan); +int ep_state_collect(const void *fdt, struct ep_state_desc *eps, int max, int *overall); +void ep_state_fill_link(struct pci_access *pacc, const char *bdf, struct ep_state_link_info *li); +const char *ep_state_link_number(const char *str, char *buf, size_t buflen); +const char *ep_state_str_or_unknown(const char *str); +int ep_state_read_endpoint_id(struct pci_access *pacc, const char *bdf); + +#endif /* NFB_TOOLS_INFO_PCI_H */ From a2c0a88042da18316fcf9fd7ca0254e341c20a89 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 21 Aug 2026 20:06:37 +0200 Subject: [PATCH 505/518] feat(tool - boot): warn on PCIe endpoint count mismatch Warn when writing firmware whose FDT endpoint count differs from the running card, so users notice a likely PCIe bifurcation change before the device disappears. --- doc/tools/nfb-boot.rst | 7 +++++++ tools/boot/boot.c | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/tools/nfb-boot.rst b/doc/tools/nfb-boot.rst index ad7b3549..ab5ae633 100644 --- a/doc/tools/nfb-boot.rst +++ b/doc/tools/nfb-boot.rst @@ -40,6 +40,13 @@ As the system starts up, user can reload existing FPGA configuration from the `c - **-q** (quiet) Do not show progress +When writing a firmware image, ``nfb-boot`` warns if the new +firmware's number of PCIe endpoints differs from what's currently running - typically +a sign of a PCIe bifurcation change. After such a reload, some PCIe devices may +disappear from the system until it is rebooted or its PCIe bus is rescanned. The write +proceeds either way; check the warning before continuing if you weren't expecting the +endpoint layout to change. + .. tip:: The firmware.nfw is a TAR archive packed by GZIP, one can change the file suffix to `.tar.gz` and extract raw bitstream or the Device Tree. diff --git a/tools/boot/boot.c b/tools/boot/boot.c index 0d6a11ac..a1099477 100644 --- a/tools/boot/boot.c +++ b/tools/boot/boot.c @@ -26,6 +26,7 @@ #include #include +#include /* define input arguments of tool */ #define ARGUMENTS "d:D:P:w:f:b:F:i:I:lqvh" @@ -33,6 +34,7 @@ #define PRINT_WARNING_WHEN_USING_BITSTREAM 0 #define REQUIRE_FORCE_WHEN_USING_BITSTREAM 0 #define REQUIRE_FORCE_WHEN_CARD_MISMATCH 1 +#define REQUIRE_FORCE_WHEN_PCI_MISMATCH 0 #define FLAG_QUIET 1 #define FLAG_FORCE 2 @@ -567,10 +569,25 @@ int do_write_with_dev(struct nfb_device *dev, int slot, const char *filename, co goto err_no_force; } } else if (!(flags & FLAG_FORCE)) { + int cur_eps, new_eps; + if (firmware_diff(nfb_get_fdt(dev), fdt) == DIFF_CARD) { warnx("firmware file doesn't match card type"); if (REQUIRE_FORCE_WHEN_CARD_MISMATCH) { - warnx("if you want still use thie firmware file, use --force parameter"); + warnx("if you want still use this firmware file, use --force parameter"); + ret = EBADF; + goto err_no_force; + } + } + + cur_eps = nfb_pci_ep_count_by_mi_bus_nodes(nfb_get_fdt(dev)); + new_eps = nfb_pci_ep_count_by_mi_bus_nodes(fdt); + if (cur_eps > 0 && new_eps > 0 && cur_eps != new_eps) { + warnx("firmware PCIe endpoint count differs from the running design " + "(%d -> %d); endpoints or devices may disappear after boot", + cur_eps, new_eps); + if (REQUIRE_FORCE_WHEN_PCI_MISMATCH) { + warnx("if you still want to use this firmware file, use --force parameter"); ret = EBADF; goto err_no_force; } From 0486fd143161abe8f0a8686f0ab753b2fb65b8e3 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 21 Aug 2026 20:17:27 +0200 Subject: [PATCH 506/518] chore: bump version to 6.31.0 --- Changelog | 8 +++++++- VERSION | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index 0da80553..6873e6fb 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,9 @@ +* Fri Aug 21 2026 Martin Spinler - 6.31.0-1 +- [FEATURE] warn on PCIe endpoint mismatch when writing firmware with nfb-boot +- [FEATURE] add PCI-centric view in nfb-info +- [FEATURE] add ExceptionBridge to libnfb-ext-python +- [FIX] fix unstable loopback configuration on E-TILE + * Wed Jul 15 2026 Martin Spinler - 6.30.7-1 - [FIX] use cmake instead of cmake3 for COPR build @@ -215,7 +221,7 @@ * Tue Dec 19 2023 Martin Spinler - 6.20.1-1 - [BUGFIX] fixes pynfb circular reference in Nfb class -- [BUGFIX] fixes E-Tile RX EQ adaptation on return from loopback +- [BUGFIX] fixes E-Tile RX EQ adaptation on return from loopback - [BUGFIX] convert types explicitly for c++ build without -fpermissive * Tue Nov 14 2023 Martin Spinler - 6.20.0-1 diff --git a/VERSION b/VERSION index 016e5b55..d2715cd5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.30.7 +6.31.0 From dd7b418b5a74bde9bbf93625c5e511263cb8e4ac Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 21 Aug 2026 21:01:17 +0200 Subject: [PATCH 507/518] fix(ci): guard commitlint against unreachable BASE_COMMIT_SHA --- tests/ci/check.gitlab-ci.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ci/check.gitlab-ci.yaml b/tests/ci/check.gitlab-ci.yaml index 7f37fe6d..0cea8d9e 100644 --- a/tests/ci/check.gitlab-ci.yaml +++ b/tests/ci/check.gitlab-ci.yaml @@ -40,7 +40,8 @@ commitlint: - | if [ -z "${BASE_COMMIT_SHA}" ] || \ [ "${BASE_COMMIT_SHA}" = "0000000000000000000000000000000000000000" ] || \ - [ "${BASE_COMMIT_SHA}" = "${CI_COMMIT_SHA}" ]; then + [ "${BASE_COMMIT_SHA}" = "${CI_COMMIT_SHA}" ] || \ + ! git cat-file -e "${BASE_COMMIT_SHA}^{commit}" 2>/dev/null; then npx commitlint --extends '@commitlint/config-conventional' --from "${CI_COMMIT_SHA}^" --to "${CI_COMMIT_SHA}" else npx commitlint --extends '@commitlint/config-conventional' --from "${BASE_COMMIT_SHA}" --to "${CI_COMMIT_SHA}" From 705d184e6e7e55c9692e8891d3bc1444cc50fb85 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 21 Aug 2026 20:28:15 +0200 Subject: [PATCH 508/518] fix(ci): update build/CI scripts to install libpci-dev package --- .copr/Makefile | 2 +- .github/workflows/doc.yml | 2 +- .gitlab-ci.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.copr/Makefile b/.copr/Makefile index 66923ccc..f3b79b59 100644 --- a/.copr/Makefile +++ b/.copr/Makefile @@ -1,5 +1,5 @@ srpm: - dnf -y install cmake git curl gcc make rpm-build libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel + dnf -y install cmake git curl gcc make rpm-build libfdt-devel numactl-devel ncurses-devel libarchive-devel libconfig libconfig-devel pciutils-devel pciutils-libs ./build.sh --prepare; mkdir build; cd build; cmake ..; cpack -G RPM --config ./CPackSourceConfig.cmake; cp *.src.rpm $(outdir) srpm-dpdk: diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 35525f14..c0bca8bd 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -17,7 +17,7 @@ jobs: run: | sudo apt-get update sudo apt-get -y install python3-pip doxygen git cmake rsync graphviz - sudo apt-get -y install autoconf automake libfdt-dev libnuma-dev libncurses-dev libarchive-dev libconfig-dev python3-dev python3-setuptools cython3 + sudo apt-get -y install autoconf automake libfdt-dev libnuma-dev libncurses-dev libarchive-dev libconfig-dev libpci-dev python3-dev python3-setuptools cython3 pip3 install sphinx sphinx_rtd_theme breathe fdt bash build.sh --prepare (mkdir cmake-build; cd cmake-build; cmake --install-prefix=/usr/ ..; make; sudo make install) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 455bcab8..bc56052f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,7 +14,7 @@ pages: image: python:3.9-alpine script: - apk add -U make doxygen musl-dev py3-setuptools - - apk add -U gcc cmake dtc-dev numactl-dev ncurses-dev libarchive-dev libconfig libconfig-dev automake autoconf curl git cython python3-dev dtc-dev linux-headers zlib-dev + - apk add -U gcc cmake dtc-dev numactl-dev ncurses-dev libarchive-dev libconfig libconfig-dev automake autoconf curl git cython python3-dev dtc-dev linux-headers zlib-dev pciutils-dev - pip install -U sphinx - pip install -U sphinx-rtd-theme - pip install -U breathe From 19021650dd8a03486b43ce2c7b777a54ce1d81d0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Fri, 21 Aug 2026 21:17:22 +0200 Subject: [PATCH 509/518] chore: bump version to 6.31.1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index d2715cd5..efb48db9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.31.0 +6.31.1 From 26028454106dfe9f7b0fef0214b66b2c732e6492 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 24 Aug 2026 11:08:47 +0200 Subject: [PATCH 510/518] fix(mdio): use 64b bitmask for pending lanes --- libnfb/include/netcope/mdio.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index 2873c0d2..d7cbb0e3 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -1275,20 +1275,18 @@ static inline void nc_mdio_etile_eth_sysrst(struct nc_mdio *mdio, int prtad) { int i, res; uint16_t stat; - char pending[mdio->pma_lanes]; /* Lanes that still need adaptation */ - int pending_cnt = mdio->pma_lanes; + uint64_t pending; /* Bitmask of lanes that still need adaptation */ int retries = 0; struct nfb_comp *comp = nfb_user_to_comp(mdio); /* Initially all lanes are pending */ - for (i = 0; i < mdio->pma_lanes; i++) - pending[i] = 1; + pending = (mdio->pma_lanes == 64) ? ~(uint64_t) 0 : ((uint64_t) 1 << mdio->pma_lanes) - 1; /* Step 1: reset (disable + enable) all PMA lanes (this also forces the initial adaptation) */ - while (pending_cnt && retries++ < 3) { + while (pending && retries++ < 3) { /* Reset (disable + enable) lanes that still need adaptation */ for (i = 0; i < mdio->pma_lanes; i++) { - if (!pending[i]) + if (!(pending & ((uint64_t) 1 << i))) continue; nc_mdio_etile_pma_attribute_write(mdio, prtad, i, 0x0001, 0x0000); /* Disable the PMA */ stat = nc_mdio_etile_pma_attribute_read(mdio, prtad, i); /* Get operation status*/ @@ -1297,16 +1295,15 @@ static inline void nc_mdio_etile_eth_sysrst(struct nc_mdio *mdio, int prtad) } /* Check adaptation of the pending lanes only */ for (i = 0; i < mdio->pma_lanes; i++) { - if (!pending[i]) + if (!(pending & ((uint64_t) 1 << i))) continue; res = nc_mdio_etile_adapt_wait(mdio, prtad, i, 0x80, 200000); /* Get adaptation status */ if (res) { - pending[i] = 0; - pending_cnt--; + pending &= ~((uint64_t) 1 << i); } } } - /* TODO: if (pending_cnt) -> adaptation failed. Not observed in hardware */ + /* TODO: if (pending) -> adaptation failed. Not observed in hardware */ /* Step 2: Force Eth IP system reset (eio_sys_rst) */ retries = 0; From 31db813d0d96f28168b3a196cb99549ddc47d5d0 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Mon, 24 Aug 2026 11:16:41 +0200 Subject: [PATCH 511/518] chore: bump version to 6.31.2 --- Changelog | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 6873e6fb..2025a7aa 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +* Mon Aug 24 2026 Martin Spinler - 6.31.2-1 +- [FIX] fix mdio compilation issue in driver + * Fri Aug 21 2026 Martin Spinler - 6.31.0-1 - [FEATURE] warn on PCIe endpoint mismatch when writing firmware with nfb-boot - [FEATURE] add PCI-centric view in nfb-info diff --git a/VERSION b/VERSION index efb48db9..6c394679 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.31.1 +6.31.2 From b73369d2185e26183f90f6f66d688f055b7f8749 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Thu, 10 Sep 2026 14:44:20 +0200 Subject: [PATCH 512/518] feat(nfb-bootstrap): support FB2CDG1 card --- python/nfb-tools/nfbbootstrap/nfb_bootstrap.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py index 3739df58..dae1628b 100755 --- a/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py +++ b/python/nfb-tools/nfbbootstrap/nfb_bootstrap.py @@ -11,7 +11,7 @@ def main(): parser.add_argument('-d', '--device', help='Device specifier, e.g. 0000:03:00.0') parser.add_argument('-c', '--card', help='Card name, e.g. "N6010"') - parser.add_argument('--dtb', action='store', default='nfb-bootstrap.dtb', help='Output DTB filename') + parser.add_argument('--dtb', action='store', default=None, help='Output DTB filename') parser.add_argument('-v', '--verbose', action='store_true') args = parser.parse_args() @@ -39,6 +39,13 @@ def main(): n_mi.append(n_pmci) n_pmci.append(fdt.PropWords('reg', *pmci_reg)) n_pmci.append(fdt.PropStrings("compatible", "cesnet,pmci")) + + elif args.card in ['FB2CDG1-VAR1']: + n_pmci = fdt.Node('pmci') + n_mi.append(n_pmci) + n_pmci.append(fdt.PropWords('reg', 0x4000, 0x1000)) + n_pmci.append(fdt.PropStrings("compatible", "cesnet,pmci")) + elif args.card in ['IA-440I', 'IA-860M']: reg = [0x2000, 0x44] @@ -48,6 +55,9 @@ def main(): n_bmc.append(fdt.PropStrings("compatible", "bittware,bmc")) n_bmc.append(fdt.Property("throttle_write")) + if args.dtb is None: + args.dtb = f'nfb-bootstrap-{args.card}.dtb' + with open(args.dtb, "wb") as f: f.write(dt.to_dtb(version=17)) From e0e856e8e16dd15fa32ab3247a5d241ce7fe9eac Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 16 Sep 2026 15:18:54 +0200 Subject: [PATCH 513/518] chore: use 3rdparty version v6.31.2 --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 0305109d..c84a8e18 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ AUTOINSTALL=true # whether dependencies should be installed with '-y' RELTYPE=Release # Release type (Debug/Release) FILENAME_3RDPARTY="3rdparty.tar.gz" -SRC_3RDPARTY_VERSION="v6.30.4" +SRC_3RDPARTY_VERSION="v6.31.2" URL_3RDPARTY="https://github.com/CESNET/ndk-sw/releases/download/$SRC_3RDPARTY_VERSION/$FILENAME_3RDPARTY" EPEL8_DPDK_NFB_REPO_REMOTE="https://copr.fedorainfracloud.org/coprs/g/CESNET/dpdk-nfb/repo/epel-8/group_CESNET-dpdk-nfb-epel-8.repo" From fb7b41d3a69cdc16c08afd059bc226363917f03a Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 16 Sep 2026 14:28:50 +0200 Subject: [PATCH 514/518] feat(driver - boot): read BOM for fb2cdg1 from correct offset --- drivers/kernel/drivers/nfb/boot/nfb-pmci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c index 02bfb2e8..335eb09c 100644 --- a/drivers/kernel/drivers/nfb/boot/nfb-pmci.c +++ b/drivers/kernel/drivers/nfb/boot/nfb-pmci.c @@ -364,11 +364,14 @@ int nfb_pmci_attach(struct nfb_boot *boot) /* Read SN */ if (pmci->m10bmc.ops.flash_read) { + const u32 bom_info_addr = pmci->m10bmc.type == M10_FB2CDG1 ? + PMCI_BOM_INFO_ADDR_FB2CDG1 : PMCI_BOM_INFO_ADDR; + pmci_bom_info = kzalloc(PMCI_BOM_INFO_SIZE+1+1, GFP_KERNEL); if (pmci_bom_info) { pmci_bom_info[0] = '\n'; pmci_bom_info[PMCI_BOM_INFO_SIZE+1] = 0; - pmci->m10bmc.ops.flash_read(&pmci->m10bmc, pmci_bom_info+1, PMCI_BOM_INFO_ADDR, PMCI_BOM_INFO_SIZE); + pmci->m10bmc.ops.flash_read(&pmci->m10bmc, pmci_bom_info+1, bom_info_addr, PMCI_BOM_INFO_SIZE); if ((snc = strstr(pmci_bom_info, "\nSN,"))) { if (sscanf(snc, "\nSN,%d\n", &sn) == 1) { boot->nfb->serial = sn; From 66bd6e7c68ca263901d4e25ce3a125e80e8a7e91 Mon Sep 17 00:00:00 2001 From: Matyas Sedmidubsky Date: Fri, 31 Jul 2026 16:00:44 +0200 Subject: [PATCH 515/518] feat(libnfb): nfb_fdt_rxhdr_hash --- libnfb/include/nfb/fdt.h | 133 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/libnfb/include/nfb/fdt.h b/libnfb/include/nfb/fdt.h index 7ef35870..994b840b 100644 --- a/libnfb/include/nfb/fdt.h +++ b/libnfb/include/nfb/fdt.h @@ -14,6 +14,12 @@ extern "C" { #endif +#include +#include +#include +#include +#include +#include #include /* define for loop iterate throught compatible property of Device Tree */ @@ -113,6 +119,133 @@ static inline struct nfb_fdt_packed_item nfb_fdt_packed_item_by_name(const void return ret; } + +/*! + * \brief Generate a dynamic header name from devicetree format + * \param[in] fdt Firmware devicetree + * \param[in] offset Header node offset + * \return + * - Unique pointer (must be freed) to the generated string on success + * - NULL on error (errno is set) + */ +static inline char *nfb_fdt_rxhdr_hash(const void *fdt, int offset) +{ + int proplen = 0; + int names_offset = 0; + const int hash_size = 16 + 1; + + uint32_t header_id = fdt_getprop_u32(fdt, offset, "header_id", &proplen); + if (proplen != (int)sizeof(uint32_t)) { + errno = EBADFD; + return NULL; + } + + const char *names = fdt_getprop(fdt, offset, "item-name", &proplen); + if (!names || proplen <= 0) { + errno = EBADFD; + return NULL; + } + + size_t serial_cap = 128; + char *serialized = malloc(serial_cap); + if (!serialized) { + errno = ENOMEM; + return NULL; + } + char *serial_out = serialized; + + int n = snprintf(serialized, serial_cap, "%"PRIu32";", header_id); + if (n < 0 || (size_t)n >= serial_cap) { + errno = EOVERFLOW; + free(serialized); + return NULL; + } + + while (names_offset < proplen) { + const char *name = names + names_offset; + struct nfb_fdt_packed_item item = nfb_fdt_packed_item_by_name(fdt, offset, name); + if (item.name == NULL) { + errno = EBADFD; + free(serialized); + return NULL; + } + + size_t out_offset = (size_t)(serial_out - serialized); + size_t remaining_cap = (size_t)serial_cap - out_offset; + n = snprintf(serial_out, remaining_cap, "%s:%"PRIi16":%"PRIi16";", item.name, + item.width, item.offset); + if (n < 0) { + errno = EOVERFLOW; + free(serialized); + return NULL; + } + + if ((size_t)n >= remaining_cap) { + if (serial_cap > 1024) { + // something is very wrong + errno = EOVERFLOW; + free(serialized); + return NULL; + } + serial_cap *= 2; + char *new_serialized = realloc(serialized, serial_cap); + if (!new_serialized) { + errno = ENOMEM; + free(serialized); + return NULL; + } + serialized = new_serialized; + serial_out = serialized + out_offset; + continue; + } + + names_offset += strlen(name) + 1; + serial_out += n; + } + + // FNV-1a 64-bit + uint64_t hash_val = 0xcbf29ce484222325ULL; + for (size_t i = 0; i < (size_t)(serial_out - serialized); i++) { + hash_val ^= serialized[i]; + hash_val *= 0x100000001b3ULL; + } + + char *hash = malloc(hash_size); + if (!hash) { + errno = ENOMEM; + free(serialized); + return NULL; + } + + static const char hex[] = "0123456789abcdef"; + for (unsigned int i = 0; i < (unsigned int)sizeof(hash_val); i++) { + unsigned char byte = (unsigned char)(hash_val >> (i * 8)); + hash[i * 2] = hex[byte >> 4]; + hash[i * 2 + 1] = hex[byte & 0xf]; + } + hash[sizeof(hash_val) * 2] = '\0'; + + free(serialized); + + return hash; +} + +/*! + * \brief Generate a dynamic header name from devicetree format + * \param[in] fdt Firmware devicetree + * \param[in] id Header id in devicetree + * \return + * - Unique pointer (must be freed) to the generated string on success + * - NULL on error (errno is set) + */ +static inline char *nfb_fdt_rxhdr_hash_by_id(const void *fdt, int id) +{ + int node = ndp_header_fdt_node_offset(fdt, 0, id); + if (node <= 0) + return NULL; + + return nfb_fdt_rxhdr_hash(fdt, node); +} #ifdef __cplusplus } // extern "C" #endif From d1a06f7a9100aa522fed9dfea11bd68ad7223b8a Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Wed, 9 Sep 2026 17:10:59 +0200 Subject: [PATCH 516/518] fix(libnetcope - mdio): retry loopback enable operation when the link does not start on F-TILE --- libnfb/include/netcope/mdio.h | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/libnfb/include/netcope/mdio.h b/libnfb/include/netcope/mdio.h index d7cbb0e3..5fbe9fae 100644 --- a/libnfb/include/netcope/mdio.h +++ b/libnfb/include/netcope/mdio.h @@ -742,16 +742,35 @@ static inline uint16_t nc_mdio_fixup_ftile_pcs_read(struct nc_mdio *mdio, int pr static inline int nc_mdio_fixup_ftile_set_loopback(struct nc_mdio *mdio, int prtad, int enable) { - int i; + const int EHIP_STATUS_REG = (0x118 >> 2); + const int EHIP_RX_READY = (1 << 3); + struct nfb_comp *comp = nfb_user_to_comp(mdio); uint16_t data = enable ? 0x6 : 0x0; // enable or disable loopback? + int retries; + int polls; + int i; - nc_mdio_ftile_reset(mdio, prtad, 1, 1); // assert RX reset + /* The RX datapath may not come up after the loopback is turned on, + * repeat the whole setup until the RX ready flag is set. */ + for (retries = 0; retries < 10; retries++) { + nc_mdio_ftile_reset(mdio, prtad, 1, 1); // assert RX reset - for (i = 0; i < mdio->pma_lanes; i++) { - nc_mdio_ftile_fgt_attribute_write(mdio, prtad, data, i, 0x40); + for (i = 0; i < mdio->pma_lanes; i++) { + nc_mdio_ftile_fgt_attribute_write(mdio, prtad, data, i, 0x40); + } + nc_mdio_ftile_reset(mdio, prtad, 1, 0); // deassert RX reset + + if (!enable) + return 0; + + for (polls = 0; polls < 100000; polls++) { + if (nc_mdio_dmap_drp_read(comp, prtad, 0, EHIP_STATUS_REG) & EHIP_RX_READY) { + return 0; + } + } } - nc_mdio_ftile_reset(mdio, prtad, 1, 0); // deassert RX reset - return 0; + + return -ETIMEDOUT; } /* ~~~~[ Intel E-Tile ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ From f15ae2ba16ee5fd47ee96ddd464040e3a72c95bd Mon Sep 17 00:00:00 2001 From: Stepan Friedl Date: Mon, 5 Oct 2026 12:54:02 +0200 Subject: [PATCH 517/518] ci: enable artifact fingerprints --- jenkins/Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 26fba72d..ff77f6f6 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -47,7 +47,7 @@ node('docker') { } sh "mkdir -p ${osname}-${osreleasever}" sh "mv *.${pkg} ${osname}-${osreleasever}/" - archiveArtifacts artifacts: "${osname}-${osreleasever}/*.${pkg}" + archiveArtifacts artifacts: "${osname}-${osreleasever}/*.${pkg}", fingerprint: true sh 'find . -maxdepth 1 -type f -delete' } } @@ -69,12 +69,12 @@ node('docker') { } sh "mkdir -p ${osname}-${osreleasever}" sh "mv *.${pkg} ${osname}-${osreleasever}/" - archiveArtifacts artifacts: "${osname}-${osreleasever}/*.${pkg}" + archiveArtifacts artifacts: "${osname}-${osreleasever}/*.${pkg}", fingerprint: true sh 'find . -maxdepth 1 -type f -delete' } } } - + if (osreleasever == 'jammy') { // ubuntu 22.04 lts doesnt have libxdp in its repositories } else { @@ -94,7 +94,7 @@ node('docker') { } sh "mkdir -p ${osname}-${osreleasever}" sh "mv *.${pkg} ${osname}-${osreleasever}/" - archiveArtifacts artifacts: "${osname}-${osreleasever}/*.${pkg}" + archiveArtifacts artifacts: "${osname}-${osreleasever}/*.${pkg}", fingerprint: true sh 'find . -maxdepth 1 -type f -delete' } } From 40681c75ef1e6d2cb6b31894a4af6fc563da5998 Mon Sep 17 00:00:00 2001 From: Martin Spinler Date: Wed, 7 Oct 2026 07:47:55 +0200 Subject: [PATCH 518/518] chore: bump version to 6.32.0 --- Changelog | 6 ++++++ VERSION | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 2025a7aa..595a5748 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,9 @@ +* Wed Oct 7 2026 Martin Spinler - 6.32.0-1 +- [FEATURE] libnfb: add nfb_fdt_rxhdr_hash function +- [FEATURE] nfb-bootstrap: support FB2CDG1 card +- [FIX] read BOM (SN) for FB2CDG1 from correct offset +- [FIX] mdio: retry loopback enable operation when the link does not start on F-TILE + * Mon Aug 24 2026 Martin Spinler - 6.31.2-1 - [FIX] fix mdio compilation issue in driver diff --git a/VERSION b/VERSION index 6c394679..d6b71af5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.31.2 +6.32.0