Imported Upstream version 16.04
[deb_dpdk.git] / drivers / net / 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
35 #ifndef _ENIC_COMPAT_H_
36 #define _ENIC_COMPAT_H_
37
38 #include <stdio.h>
39 #include <unistd.h>
40
41 #include <rte_atomic.h>
42 #include <rte_malloc.h>
43 #include <rte_log.h>
44
45 #define ENIC_PAGE_ALIGN 4096UL
46 #define ENIC_ALIGN      ENIC_PAGE_ALIGN
47 #define NAME_MAX        255
48 #define ETH_ALEN        6
49
50 #define __iomem
51
52 #define rmb()     rte_rmb() /* dpdk rte provided rmb */
53 #define wmb()     rte_wmb() /* dpdk rte provided wmb */
54
55 #define le16_to_cpu
56 #define le32_to_cpu
57 #define le64_to_cpu
58 #define cpu_to_le16
59 #define cpu_to_le32
60 #define cpu_to_le64
61
62 #ifndef offsetof
63 #define offsetof(t, m) ((size_t) &((t *)0)->m)
64 #endif
65
66 #define pr_err(y, args...) dev_err(0, y, ##args)
67 #define pr_warn(y, args...) dev_warning(0, y, ##args)
68 #define BUG() pr_err("BUG at %s:%d", __func__, __LINE__)
69
70 #define VNIC_ALIGN(x, a)         __ALIGN_MASK(x, (typeof(x))(a)-1)
71 #define __ALIGN_MASK(x, mask)    (((x)+(mask))&~(mask))
72 #define udelay usleep
73 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
74
75 #define kzalloc(size, flags) calloc(1, size)
76 #define kfree(x) free(x)
77
78 #define dev_printk(level, fmt, args...) \
79         RTE_LOG(level, PMD, "rte_enic_pmd: " fmt, ## args)
80
81 #define dev_err(x, args...) dev_printk(ERR, args)
82 #define dev_info(x, args...) dev_printk(INFO,  args)
83 #define dev_warning(x, args...) dev_printk(WARNING, args)
84 #define dev_debug(x, args...) dev_printk(DEBUG, args)
85
86 #define __le16 u16
87 #define __le32 u32
88 #define __le64 u64
89
90 typedef         unsigned char       u8;
91 typedef         unsigned short      u16;
92 typedef         unsigned int        u32;
93 typedef         unsigned long long  u64;
94 typedef         unsigned long long  dma_addr_t;
95
96 static inline uint32_t ioread32(volatile void *addr)
97 {
98         return *(volatile uint32_t *)addr;
99 }
100
101 static inline uint16_t ioread16(volatile void *addr)
102 {
103         return *(volatile uint16_t *)addr;
104 }
105
106 static inline uint8_t ioread8(volatile void *addr)
107 {
108         return *(volatile uint8_t *)addr;
109 }
110
111 static inline void iowrite32(uint32_t val, volatile void *addr)
112 {
113         *(volatile uint32_t *)addr = val;
114 }
115
116 static inline void iowrite16(uint16_t val, volatile void *addr)
117 {
118         *(volatile uint16_t *)addr = val;
119 }
120
121 static inline void iowrite8(uint8_t val, volatile void *addr)
122 {
123         *(volatile uint8_t *)addr = val;
124 }
125
126 static inline unsigned int readl(volatile void __iomem *addr)
127 {
128         return *(volatile unsigned int *)addr;
129 }
130
131 static inline void writel(unsigned int val, volatile void __iomem *addr)
132 {
133         *(volatile unsigned int *)addr = val;
134 }
135
136 #define min_t(type, x, y) ({                    \
137         type __min1 = (x);                      \
138         type __min2 = (y);                      \
139         __min1 < __min2 ? __min1 : __min2; })
140
141 #define max_t(type, x, y) ({                    \
142         type __max1 = (x);                      \
143         type __max2 = (y);                      \
144         __max1 > __max2 ? __max1 : __max2; })
145
146 #endif /* _ENIC_COMPAT_H_ */