Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2023 Napatech A/S 3 : : */ 4 : : 5 : : #ifndef NTOSS_SYSTEM_NT_UTIL_H 6 : : #define NTOSS_SYSTEM_NT_UTIL_H 7 : : 8 : : #include <stdint.h> 9 : : #include "nt4ga_link.h" 10 : : 11 : : /* Total max VDPA ports */ 12 : : #define MAX_VDPA_PORTS 128UL 13 : : 14 : : #ifndef ARRAY_SIZE 15 : : #define ARRAY_SIZE(arr) RTE_DIM(arr) 16 : : #endif 17 : : 18 : : /* 19 : : * Windows size in seconds for measuring FLM load 20 : : * and Port load. 21 : : * The windows size must max be 3 min in order to 22 : : * prevent overflow. 23 : : */ 24 : : #define PORT_LOAD_WINDOWS_SIZE 2ULL 25 : : #define FLM_LOAD_WINDOWS_SIZE 2ULL 26 : : 27 : : #define PCIIDENT_TO_DOMAIN(pci_ident) ((uint16_t)(((unsigned int)(pci_ident) >> 16) & 0xFFFFU)) 28 : : #define PCIIDENT_TO_BUSNR(pci_ident) ((uint8_t)(((unsigned int)(pci_ident) >> 8) & 0xFFU)) 29 : : #define PCIIDENT_TO_DEVNR(pci_ident) ((uint8_t)(((unsigned int)(pci_ident) >> 3) & 0x1FU)) 30 : : #define PCIIDENT_TO_FUNCNR(pci_ident) ((uint8_t)(((unsigned int)(pci_ident) >> 0) & 0x7U)) 31 : : #define PCIIDENT_PRINT_STR "%04x:%02x:%02x.%x" 32 : : #define BDF_TO_PCIIDENT(dom, bus, dev, fnc) (((dom) << 16) | ((bus) << 8) | ((dev) << 3) | (fnc)) 33 : : 34 : : uint64_t nthw_os_get_time_monotonic_counter(void); 35 : : void nthw_os_wait_usec(int val); 36 : : void nthw_os_wait_usec_poll(int val); 37 : : 38 : : static inline int min(int a, int b) 39 : : { 40 [ # # ]: 0 : return (a < b) ? a : b; 41 : : } 42 : : 43 : : uint64_t nthw_util_align_size(uint64_t size); 44 : : 45 : : struct nt_dma_s { 46 : : uint64_t iova; 47 : : uint64_t addr; 48 : : uint64_t size; 49 : : }; 50 : : 51 : : struct port_link_speed { 52 : : int port_id; 53 : : int link_speed; 54 : : }; 55 : : 56 : : struct nt_dma_s *nthw_dma_alloc(uint64_t size, uint64_t align, int numa); 57 : : struct nt_util_vfio_impl { 58 : : int (*vfio_dma_map)(int vf_num, void *virt_addr, uint64_t *iova_addr, uint64_t size); 59 : : int (*vfio_dma_unmap)(int vf_num, void *virt_addr, uint64_t iova_addr, uint64_t size); 60 : : }; 61 : : 62 : : void nthw_util_vfio_init(struct nt_util_vfio_impl *impl); 63 : : 64 : : int nthw_link_speed_to_eth_speed_num(enum nt_link_speed_e nt_link_speed); 65 : : uint32_t nthw_link_speed_capa_to_eth_speed_capa(int nt_link_speed_capa); 66 : : int nthw_link_duplex_to_eth_duplex(enum nt_link_duplex_e nt_link_duplex); 67 : : 68 : : int nthw_string_to_u32(const char *key_str __rte_unused, const char *value_str, void *extra_args); 69 : : 70 : : #endif /* NTOSS_SYSTEM_NT_UTIL_H */