2 * Copyright 2008-2014 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * Copyright (c) 2014, Cisco Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
36 #ifndef _ENIC_COMPAT_H_
37 #define _ENIC_COMPAT_H_
42 #include <rte_atomic.h>
43 #include <rte_malloc.h>
45 #define ENIC_PAGE_ALIGN 4096ULL
46 #define ENIC_ALIGN ENIC_PAGE_ALIGN
52 #define rmb() rte_rmb() /* dpdk rte provided rmb */
53 #define wmb() rte_wmb() /* dpdk rte provided wmb */
63 #define offsetof(t, m) ((size_t) &((t *)0)->m)
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__)
70 #define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
71 #define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
73 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
75 #define kzalloc(size, flags) calloc(1, size)
76 #define kfree(x) free(x)
78 #define dev_err(x, args...) printf("rte_enic_pmd : Error - " args)
79 #define dev_info(x, args...) printf("rte_enic_pmd: Info - " args)
80 #define dev_warning(x, args...) printf("rte_enic_pmd: Warning - " args)
81 #define dev_trace(x, args...) printf("rte_enic_pmd: Trace - " args)
87 typedef unsigned char u8;
88 typedef unsigned short u16;
89 typedef unsigned int u32;
90 typedef unsigned long long u64;
91 typedef unsigned long long dma_addr_t;
93 static inline uint32_t ioread32(volatile void *addr)
95 return *(volatile uint32_t *)addr;
98 static inline uint16_t ioread16(volatile void *addr)
100 return *(volatile uint16_t *)addr;
103 static inline uint8_t ioread8(volatile void *addr)
105 return *(volatile uint8_t *)addr;
108 static inline void iowrite32(uint32_t val, volatile void *addr)
110 *(volatile uint32_t *)addr = val;
113 static inline void iowrite16(uint16_t val, volatile void *addr)
115 *(volatile uint16_t *)addr = val;
118 static inline void iowrite8(uint8_t val, volatile void *addr)
120 *(volatile uint8_t *)addr = val;
123 static inline unsigned int readl(volatile void __iomem *addr)
125 return *(volatile unsigned int *)addr;
128 static inline void writel(unsigned int val, volatile void __iomem *addr)
130 *(volatile unsigned int *)addr = val;
133 #define min_t(type, x, y) ({ \
136 __min1 < __min2 ? __min1 : __min2; })
138 #define max_t(type, x, y) ({ \
141 __max1 > __max2 ? __max1 : __max2; })
143 #endif /* _ENIC_COMPAT_H_ */