[v10,04/21] net/ntnic: add utilities implementation
Checks
Commit Message
Add ntnic utilities.
Signed-off-by: Serhii Iliushyk <sil-plv@napatech.com>
---
v6
* NT utils header file was moved
v10
* Remove "NT" from the commit message title
* Use 8 spaces as indentation in meson
---
drivers/net/ntnic/meson.build | 2 ++
drivers/net/ntnic/ntnic_ethdev.c | 2 ++
drivers/net/ntnic/ntutil/nt_util.c | 33 +++++++++++++++++++++++
drivers/net/ntnic/ntutil/nt_util.h | 43 ++++++++++++++++++++++++++++++
4 files changed, 80 insertions(+)
create mode 100644 drivers/net/ntnic/ntutil/nt_util.c
create mode 100644 drivers/net/ntnic/ntutil/nt_util.h
@@ -11,10 +11,12 @@ endif
includes = [
include_directories('.'),
include_directories('ntlog'),
+ include_directories('ntutil'),
]
# all sources
sources = files(
'ntlog/ntlog.c',
+ 'ntutil/nt_util.c',
'ntnic_ethdev.c',
)
@@ -10,6 +10,8 @@
#include "ntlog.h"
+#include "nt_util.h"
+
static const struct rte_pci_id nthw_pci_id_map[] = {
{
.vendor_id = 0,
new file mode 100644
@@ -0,0 +1,33 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Napatech A/S
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include <rte_ethdev.h>
+#include <rte_malloc.h>
+
+#include "ntlog.h"
+#include "nt_util.h"
+
+/* uses usleep which schedules out the calling thread */
+void nt_os_wait_usec(int val)
+{
+ rte_delay_us_sleep(val);
+}
+
+uint64_t nt_os_get_time_monotonic_counter(void)
+{
+ return rte_get_timer_cycles();
+}
+
+/* Allocation size matching minimum alignment of specified size */
+uint64_t nt_util_align_size(uint64_t size)
+{
+ return 1 << rte_log2_u64(size);
+}
new file mode 100644
@@ -0,0 +1,43 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Napatech A/S
+ */
+
+#ifndef NTOSS_SYSTEM_NT_UTIL_H
+#define NTOSS_SYSTEM_NT_UTIL_H
+
+#include <stdint.h>
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) RTE_DIM(arr)
+#endif
+
+#define PCIIDENT_TO_DOMAIN(pci_ident) ((uint16_t)(((unsigned int)(pci_ident) >> 16) & 0xFFFFU))
+#define PCIIDENT_TO_BUSNR(pci_ident) ((uint8_t)(((unsigned int)(pci_ident) >> 8) & 0xFFU))
+#define PCIIDENT_TO_DEVNR(pci_ident) ((uint8_t)(((unsigned int)(pci_ident) >> 3) & 0x1FU))
+#define PCIIDENT_TO_FUNCNR(pci_ident) ((uint8_t)(((unsigned int)(pci_ident) >> 0) & 0x7U))
+#define PCIIDENT_PRINT_STR "%04x:%02x:%02x.%x"
+#define BDF_TO_PCIIDENT(dom, bus, dev, fnc) (((dom) << 16) | ((bus) << 8) | ((dev) << 3) | (fnc))
+
+uint64_t nt_os_get_time_monotonic_counter(void);
+void nt_os_wait_usec(int val);
+
+uint64_t nt_util_align_size(uint64_t size);
+
+struct nt_dma_s {
+ uint64_t iova;
+ uint64_t addr;
+ uint64_t size;
+};
+
+struct nt_dma_s *nt_dma_alloc(uint64_t size, uint64_t align, int numa);
+void nt_dma_free(struct nt_dma_s *vfio_addr);
+
+struct nt_util_vfio_impl {
+ int (*vfio_dma_map)(int vf_num, void *virt_addr, uint64_t *iova_addr, uint64_t size);
+ int (*vfio_dma_unmap)(int vf_num, void *virt_addr, uint64_t iova_addr, uint64_t size);
+};
+
+void nt_util_vfio_init(struct nt_util_vfio_impl *impl);
+
+#endif /* NTOSS_SYSTEM_NT_UTIL_H */