xref: /dpdk/drivers/net/thunderx/base/nicvf_plat.h (revision 93998f3c5f22747e4f2c5e8714fa5cbe6c9d1574)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016 Cavium, Inc
3  */
4 
5 #ifndef _THUNDERX_NICVF_H
6 #define _THUNDERX_NICVF_H
7 
8 /* Platform/OS/arch specific abstractions */
9 
10 /* log */
11 #include <rte_log.h>
12 #include "../nicvf_logs.h"
13 
14 #define nicvf_log_error(s, ...) PMD_DRV_LOG(ERR, s, ##__VA_ARGS__)
15 
16 #define nicvf_log_debug(s, ...) PMD_DRV_LOG(DEBUG, s, ##__VA_ARGS__)
17 
18 #define nicvf_mbox_log(s, ...) PMD_MBOX_LOG(DEBUG, s, ##__VA_ARGS__)
19 
20 #define nicvf_log(s, ...) fprintf(stderr, s, ##__VA_ARGS__)
21 
22 /* delay */
23 #include <rte_cycles.h>
24 #define nicvf_delay_us(x) rte_delay_us(x)
25 
26 /* barrier */
27 #include <rte_atomic.h>
28 #define nicvf_smp_wmb() rte_smp_wmb()
29 #define nicvf_smp_rmb() rte_smp_rmb()
30 
31 /* utils */
32 #include <rte_common.h>
33 #define nicvf_min(x, y) RTE_MIN(x, y)
34 #define nicvf_log2_u32(x) rte_log2_u32(x)
35 
36 /* byte order */
37 #include <rte_byteorder.h>
38 #define nicvf_cpu_to_be_64(x) rte_cpu_to_be_64(x)
39 #define nicvf_be_to_cpu_64(x) rte_be_to_cpu_64(x)
40 
41 #define NICVF_BYTE_ORDER RTE_BYTE_ORDER
42 #define NICVF_BIG_ENDIAN RTE_BIG_ENDIAN
43 #define NICVF_LITTLE_ENDIAN RTE_LITTLE_ENDIAN
44 
45 /* Constants */
46 #include <rte_ether.h>
47 #define NICVF_MAC_ADDR_SIZE RTE_ETHER_ADDR_LEN
48 
49 /* Ethernet */
50 #define ether_addr_copy(x, y) memcpy(y, x, RTE_ETHER_ADDR_LEN)
51 
52 #include <rte_io.h>
53 #define nicvf_addr_write(addr, val) rte_write64_relaxed((val), (void *)(addr))
54 #define nicvf_addr_read(addr) rte_read64_relaxed((void *)(addr))
55 
56 /* ARM64 specific functions */
57 #if defined(RTE_ARCH_ARM64)
58 #define nicvf_prefetch_store_keep(_ptr) __extension__ ({\
59 	asm volatile("prfm pstl1keep, [%x0]\n" : : "r" (_ptr)); })
60 
61 
62 #define NICVF_LOAD_PAIR(reg1, reg2, addr) __extension__ ({		\
63 			asm volatile(			\
64 			"ldp %x[x1], %x[x0], [%x[p1]]"	\
65 			: [x1]"=r"(reg1), [x0]"=r"(reg2)\
66 			: [p1]"r"(addr)			\
67 			); })
68 
69 #else /* non optimized functions for building on non arm64 arch */
70 
71 #define nicvf_prefetch_store_keep(_ptr) do {} while (0)
72 
73 #define NICVF_LOAD_PAIR(reg1, reg2, addr)		\
74 do {							\
75 	reg1 = nicvf_addr_read((uintptr_t)addr);	\
76 	reg2 = nicvf_addr_read((uintptr_t)addr + 8);	\
77 } while (0)
78 
79 #endif
80 
81 #include "nicvf_hw.h"
82 #include "nicvf_mbox.h"
83 
84 #endif /* _THUNDERX_NICVF_H */
85