net/enic: replace some PMD macros with standard API
[dpdk.git] / drivers / net / enic / enic_compat.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  */
5
6 #ifndef _ENIC_COMPAT_H_
7 #define _ENIC_COMPAT_H_
8
9 #include <stdio.h>
10 #include <unistd.h>
11
12 #include <rte_atomic.h>
13 #include <rte_malloc.h>
14 #include <rte_log.h>
15 #include <rte_io.h>
16
17 #define ENIC_PAGE_ALIGN 4096UL
18 #define ENIC_ALIGN      ENIC_PAGE_ALIGN
19 #define ETH_ALEN        6
20
21 #define __iomem
22
23 #define rmb()     rte_rmb() /* dpdk rte provided rmb */
24 #define wmb()     rte_wmb() /* dpdk rte provided wmb */
25
26 #ifndef offsetof
27 #define offsetof(t, m) ((size_t) &((t *)0)->m)
28 #endif
29
30 #define pr_err(y, args...) dev_err(0, y, ##args)
31 #define pr_warn(y, args...) dev_warning(0, y, ##args)
32 #define BUG() pr_err("BUG at %s:%d", __func__, __LINE__)
33
34 #define VNIC_ALIGN(x, a)         __ALIGN_MASK(x, (typeof(x))(a)-1)
35 #define __ALIGN_MASK(x, mask)    (((x)+(mask))&~(mask))
36 #define udelay usleep
37 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
38
39 #define kzalloc(size, flags) calloc(1, size)
40 #define kfree(x) free(x)
41
42 extern int enic_pmd_logtype;
43
44 #define dev_printk(level, fmt, args...) \
45         rte_log(RTE_LOG_ ## level, enic_pmd_logtype, \
46                 "PMD: rte_enic_pmd: " fmt, ##args)
47
48 #define dev_err(x, args...) dev_printk(ERR, args)
49 #define dev_info(x, args...) dev_printk(INFO,  args)
50 #define dev_warning(x, args...) dev_printk(WARNING, args)
51 #define dev_debug(x, args...) dev_printk(DEBUG, args)
52
53 #define ENICPMD_LOG(level, fmt, args...) \
54         rte_log(RTE_LOG_ ## level, enic_pmd_logtype, \
55                 "%s " fmt "\n", __func__, ##args)
56 #define ENICPMD_FUNC_TRACE() ENICPMD_LOG(DEBUG, ">>")
57
58 #define __le16 u16
59 #define __le32 u32
60 #define __le64 u64
61
62 typedef         unsigned char       u8;
63 typedef         unsigned short      u16;
64 typedef         unsigned int        u32;
65 typedef         unsigned long long  u64;
66 typedef         unsigned long long  dma_addr_t;
67
68 static inline uint32_t ioread32(volatile void *addr)
69 {
70         return rte_read32(addr);
71 }
72
73 static inline uint8_t ioread8(volatile void *addr)
74 {
75         return rte_read8(addr);
76 }
77
78 static inline void iowrite32(uint32_t val, volatile void *addr)
79 {
80         rte_write32(val, addr);
81 }
82
83 static inline void iowrite32_relaxed(uint32_t val, volatile void *addr)
84 {
85         rte_write32_relaxed(val, addr);
86 }
87
88 static inline unsigned int readl(volatile void __iomem *addr)
89 {
90         return rte_read32(addr);
91 }
92
93 static inline void writel(unsigned int val, volatile void __iomem *addr)
94 {
95         rte_write32(val, addr);
96 }
97
98 #define min_t(type, x, y) ({                    \
99         type __min1 = (x);                      \
100         type __min2 = (y);                      \
101         __min1 < __min2 ? __min1 : __min2; })
102
103 #define max_t(type, x, y) ({                    \
104         type __max1 = (x);                      \
105         type __max2 = (y);                      \
106         __max1 > __max2 ? __max1 : __max2; })
107
108 #endif /* _ENIC_COMPAT_H_ */