Add ntnic utilities. Signed-off-by: Serhii Iliushyk <sil-...@napatech.com> --- drivers/net/ntnic/meson.build | 2 ++ drivers/net/ntnic/ntnic_ethdev.c | 2 ++ drivers/net/ntnic/ntutil/include/nt_util.h | 28 ++++++++++++++++++ drivers/net/ntnic/ntutil/nt_util.c | 33 ++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 drivers/net/ntnic/ntutil/include/nt_util.h create mode 100644 drivers/net/ntnic/ntutil/nt_util.c
diff --git a/drivers/net/ntnic/meson.build b/drivers/net/ntnic/meson.build index b1ba8a860f..d364cf8621 100644 --- a/drivers/net/ntnic/meson.build +++ b/drivers/net/ntnic/meson.build @@ -16,11 +16,13 @@ cflags += [ includes = [ include_directories('.'), include_directories('ntlog/include'), + include_directories('ntutil/include'), ] # all sources sources = files( 'ntlog/ntlog.c', + 'ntutil/nt_util.c', 'ntnic_ethdev.c', ) # END diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c index e9a584877f..c9726343a1 100644 --- a/drivers/net/ntnic/ntnic_ethdev.c +++ b/drivers/net/ntnic/ntnic_ethdev.c @@ -14,6 +14,8 @@ #include "ntlog.h" +#include "nt_util.h" + /* Global static variables: */ static int diff --git a/drivers/net/ntnic/ntutil/include/nt_util.h b/drivers/net/ntnic/ntutil/include/nt_util.h new file mode 100644 index 0000000000..3c7b6cfce4 --- /dev/null +++ b/drivers/net/ntnic/ntutil/include/nt_util.h @@ -0,0 +1,28 @@ +/* + * 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); + + +#endif /* NTOSS_SYSTEM_NT_UTIL_H */ diff --git a/drivers/net/ntnic/ntutil/nt_util.c b/drivers/net/ntnic/ntutil/nt_util.c new file mode 100644 index 0000000000..5395bf6993 --- /dev/null +++ b/drivers/net/ntnic/ntutil/nt_util.c @@ -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); +} -- 2.45.0