d22578e3347b858dfe9451b63ac5560257850d8c
[dpdk.git] / lib / librte_pmd_enic / enic_compat.h
1 /*
2  * Copyright 2008-2014 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * Copyright (c) 2014, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 #ident "$Id$"
35
36 #ifndef _ENIC_COMPAT_H_
37 #define _ENIC_COMPAT_H_
38
39 #include <stdio.h>
40
41 #include <rte_atomic.h>
42 #include <rte_malloc.h>
43
44 #define ENIC_PAGE_ALIGN 4096ULL
45 #define ENIC_ALIGN      ENIC_PAGE_ALIGN
46 #define NAME_MAX        255
47 #define ETH_ALEN        6
48
49 #define __iomem
50
51 #define rmb()     rte_rmb() /* dpdk rte provided rmb */
52 #define wmb()     rte_wmb() /* dpdk rte provided wmb */
53
54 #define le16_to_cpu
55 #define le32_to_cpu
56 #define le64_to_cpu
57 #define cpu_to_le16
58 #define cpu_to_le32
59 #define cpu_to_le64
60
61 #ifndef offsetof
62 #define offsetof(t, m) ((size_t) &((t *)0)->m)
63 #endif
64
65 #define pr_err(y, args...) dev_err(0, y, ##args)
66 #define pr_warn(y, args...) dev_warning(0, y, ##args)
67 #define BUG() pr_err("BUG at %s:%d", __func__, __LINE__)
68
69 #define ALIGN(x, a)              __ALIGN_MASK(x, (typeof(x))(a)-1)
70 #define __ALIGN_MASK(x, mask)    (((x)+(mask))&~(mask))
71 #define udelay usleep
72 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
73
74 #define kzalloc(size, flags) calloc(1, size)
75 #define kfree(x) free(x)
76
77 #define dev_err(x, args...) printf("rte_enic_pmd : Error - " args)
78 #define dev_info(x, args...) printf("rte_enic_pmd: Info - " args)
79 #define dev_warning(x, args...) printf("rte_enic_pmd: Warning - " args)
80 #define dev_trace(x, args...) printf("rte_enic_pmd: Trace - " args)
81
82 #define __le16 u16
83 #define __le32 u32
84 #define __le64 u64
85
86 typedef         unsigned char       u8;
87 typedef         unsigned short      u16;
88 typedef         unsigned int        u32;
89 typedef         unsigned long long  u64;
90 typedef         unsigned long long  dma_addr_t;
91
92 static inline u_int32_t ioread32(volatile void *addr)
93 {
94         return *(volatile u_int32_t *)addr;
95 }
96
97 static inline u16 ioread16(volatile void *addr)
98 {
99         return *(volatile u16 *)addr;
100 }
101
102 static inline u_int8_t ioread8(volatile void *addr)
103 {
104         return *(volatile u_int8_t *)addr;
105 }
106
107 static inline void iowrite32(u_int32_t val, volatile void *addr)
108 {
109         *(volatile u_int32_t *)addr = val;
110 }
111
112 static inline void iowrite16(u16 val, volatile void *addr)
113 {
114         *(volatile u16 *)addr = val;
115 }
116
117 static inline void iowrite8(u_int8_t val, volatile void *addr)
118 {
119         *(volatile u_int8_t *)addr = val;
120 }
121
122 static inline unsigned int readl(volatile void __iomem *addr)
123 {
124         return *(volatile unsigned int *)addr;
125 }
126
127 static inline void writel(unsigned int val, volatile void __iomem *addr)
128 {
129         *(volatile unsigned int *)addr = val;
130 }
131
132 #define min_t(type, x, y) ({                    \
133         type __min1 = (x);                      \
134         type __min2 = (y);                      \
135         __min1 < __min2 ? __min1 : __min2; })
136
137 #define max_t(type, x, y) ({                    \
138         type __max1 = (x);                      \
139         type __max2 = (y);                      \
140         __max1 > __max2 ? __max1 : __max2; })
141
142 #endif /* _ENIC_COMPAT_H_ */