fm10k: move to drivers/net/
[dpdk.git] / drivers / net / fm10k / base / fm10k_osdep.h
1 /*******************************************************************************
2
3 Copyright (c) 2013-2015, Intel Corporation
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9  1. Redistributions of source code must retain the above copyright notice,
10     this list of conditions and the following disclaimer.
11
12  2. Redistributions in binary form must reproduce the above copyright
13     notice, this list of conditions and the following disclaimer in the
14     documentation and/or other materials provided with the distribution.
15
16  3. Neither the name of the Intel Corporation nor the names of its
17     contributors may be used to endorse or promote products derived from
18     this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32 ***************************************************************************/
33
34 #ifndef _FM10K_OSDEP_H_
35 #define _FM10K_OSDEP_H_
36
37 #include <stdint.h>
38 #include <string.h>
39 #include <rte_atomic.h>
40 #include <rte_byteorder.h>
41 #include <rte_cycles.h>
42 #include "../fm10k_logs.h"
43
44 /* TODO: this does not look like it should be used... */
45 #define ERROR_REPORT2(v1, v2, v3)   do { } while (0)
46
47 #define STATIC                  static
48 #define DEBUGFUNC(F)            DEBUGOUT(F);
49 #define DEBUGOUT(S, args...)    PMD_DRV_LOG_RAW(DEBUG, S, ##args)
50 #define DEBUGOUT1(S, args...)   DEBUGOUT(S, ##args)
51 #define DEBUGOUT2(S, args...)   DEBUGOUT(S, ##args)
52 #define DEBUGOUT3(S, args...)   DEBUGOUT(S, ##args)
53 #define DEBUGOUT6(S, args...)   DEBUGOUT(S, ##args)
54 #define DEBUGOUT7(S, args...)   DEBUGOUT(S, ##args)
55
56 #define FALSE      0
57 #define TRUE       1
58 #ifndef false
59 #define false      FALSE
60 #endif
61 #ifndef true
62 #define true       TRUE
63 #endif
64
65 typedef uint8_t    u8;
66 typedef int8_t     s8;
67 typedef uint16_t   u16;
68 typedef int16_t    s16;
69 typedef uint32_t   u32;
70 typedef int32_t    s32;
71 typedef int64_t    s64;
72 typedef uint64_t   u64;
73 typedef int        bool;
74
75 #ifndef __le16
76 #define __le16     u16
77 #define __le32     u32
78 #define __le64     u64
79 #endif
80 #ifndef __be16
81 #define __be16     u16
82 #define __be32     u32
83 #define __be64     u64
84 #endif
85
86 /* offsets are WORD offsets, not BYTE offsets */
87 #define FM10K_WRITE_REG(hw, reg, val)    \
88         ((((volatile uint32_t *)(hw)->hw_addr)[(reg)]) = ((uint32_t)(val)))
89 #define FM10K_READ_REG(hw, reg)          \
90         (((volatile uint32_t *)(hw)->hw_addr)[(reg)])
91 #define FM10K_WRITE_FLUSH(a) FM10K_READ_REG(a, FM10K_CTRL)
92
93 #define FM10K_PCI_REG(reg) (*((volatile uint32_t *)(reg)))
94
95 #define FM10K_PCI_REG_WRITE(reg, value) do { \
96         FM10K_PCI_REG((reg)) = (value); \
97 } while (0)
98
99 /* not implemented */
100 #define FM10K_READ_PCI_WORD(hw, reg)     0
101
102 #define FM10K_WRITE_MBX(hw, reg, value) FM10K_WRITE_REG(hw, reg, value)
103 #define FM10K_READ_MBX(hw, reg) FM10K_READ_REG(hw, reg)
104
105 #define FM10K_LE16_TO_CPU    rte_le_to_cpu_16
106 #define FM10K_LE32_TO_CPU    rte_le_to_cpu_32
107 #define FM10K_CPU_TO_LE32    rte_cpu_to_le_32
108 #define FM10K_CPU_TO_LE16    rte_cpu_to_le_16
109
110 #define FM10K_RMB            rte_rmb
111 #define FM10K_WMB            rte_wmb
112
113 #define usec_delay           rte_delay_us
114
115 #define FM10K_REMOVED(hw_addr) (!(hw_addr))
116
117 #ifndef FM10K_IS_ZERO_ETHER_ADDR
118 /* make certain address is not 0 */
119 #define FM10K_IS_ZERO_ETHER_ADDR(addr) \
120 (!((addr)[0] | (addr)[1] | (addr)[2] | (addr)[3] | (addr)[4] | (addr)[5]))
121 #endif
122
123 #ifndef FM10K_IS_MULTICAST_ETHER_ADDR
124 #define FM10K_IS_MULTICAST_ETHER_ADDR(addr) ((addr)[0] & 0x1)
125 #endif
126
127 #ifndef FM10K_IS_VALID_ETHER_ADDR
128 /* make certain address is not multicast or 0 */
129 #define FM10K_IS_VALID_ETHER_ADDR(addr) \
130 (!FM10K_IS_MULTICAST_ETHER_ADDR(addr) && !FM10K_IS_ZERO_ETHER_ADDR(addr))
131 #endif
132
133 #ifndef do_div
134 #define do_div(n, base) ({\
135         (n) = (n) / (base);\
136 })
137 #endif /* do_div */
138
139 /* DPDK can't access IOMEM directly */
140 #ifndef FM10K_WRITE_SW_REG
141 #define FM10K_WRITE_SW_REG(v1, v2, v3)   do { } while (0)
142 #endif
143
144 #ifndef fm10k_read_reg
145 #define fm10k_read_reg FM10K_READ_REG
146 #endif
147
148 #endif /* _FM10K_OSDEP_H_ */