Imported Upstream version 16.04
[deb_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 #ifndef BOULDER_RAPIDS_HW
48 #define BOULDER_RAPIDS_HW
49 #endif
50
51 #define STATIC                  static
52 #define DEBUGFUNC(F)            DEBUGOUT(F "\n");
53 #define DEBUGOUT(S, args...)    PMD_DRV_LOG_RAW(DEBUG, S, ##args)
54 #define DEBUGOUT1(S, args...)   DEBUGOUT(S, ##args)
55 #define DEBUGOUT2(S, args...)   DEBUGOUT(S, ##args)
56 #define DEBUGOUT3(S, args...)   DEBUGOUT(S, ##args)
57 #define DEBUGOUT6(S, args...)   DEBUGOUT(S, ##args)
58 #define DEBUGOUT7(S, args...)   DEBUGOUT(S, ##args)
59
60 #define FALSE      0
61 #define TRUE       1
62 #ifndef false
63 #define false      FALSE
64 #endif
65 #ifndef true
66 #define true       TRUE
67 #endif
68
69 typedef uint8_t    u8;
70 typedef int8_t     s8;
71 typedef uint16_t   u16;
72 typedef int16_t    s16;
73 typedef uint32_t   u32;
74 typedef int32_t    s32;
75 typedef int64_t    s64;
76 typedef uint64_t   u64;
77 typedef int        bool;
78
79 #ifndef __le16
80 #define __le16     u16
81 #define __le32     u32
82 #define __le64     u64
83 #endif
84 #ifndef __be16
85 #define __be16     u16
86 #define __be32     u32
87 #define __be64     u64
88 #endif
89
90 /* offsets are WORD offsets, not BYTE offsets */
91 #define FM10K_WRITE_REG(hw, reg, val)    \
92         ((((volatile uint32_t *)(hw)->hw_addr)[(reg)]) = ((uint32_t)(val)))
93 #define FM10K_READ_REG(hw, reg)          \
94         (((volatile uint32_t *)(hw)->hw_addr)[(reg)])
95 #define FM10K_WRITE_FLUSH(a) FM10K_READ_REG(a, FM10K_CTRL)
96
97 #define FM10K_PCI_REG(reg) (*((volatile uint32_t *)(reg)))
98
99 #define FM10K_PCI_REG_WRITE(reg, value) do { \
100         FM10K_PCI_REG((reg)) = (value); \
101 } while (0)
102
103 /* not implemented */
104 #define FM10K_READ_PCI_WORD(hw, reg)     0
105
106 #define FM10K_WRITE_MBX(hw, reg, value) FM10K_WRITE_REG(hw, reg, value)
107 #define FM10K_READ_MBX(hw, reg) FM10K_READ_REG(hw, reg)
108
109 #define FM10K_LE16_TO_CPU    rte_le_to_cpu_16
110 #define FM10K_LE32_TO_CPU    rte_le_to_cpu_32
111 #define FM10K_CPU_TO_LE32    rte_cpu_to_le_32
112 #define FM10K_CPU_TO_LE16    rte_cpu_to_le_16
113 #define le16_to_cpu          rte_le_to_cpu_16
114
115 #define FM10K_RMB            rte_rmb
116 #define FM10K_WMB            rte_wmb
117
118 #define usec_delay           rte_delay_us
119
120 #define FM10K_REMOVED(hw_addr) (!(hw_addr))
121
122 #ifndef FM10K_IS_ZERO_ETHER_ADDR
123 /* make certain address is not 0 */
124 #define FM10K_IS_ZERO_ETHER_ADDR(addr) \
125 (!((addr)[0] | (addr)[1] | (addr)[2] | (addr)[3] | (addr)[4] | (addr)[5]))
126 #endif
127
128 #ifndef FM10K_IS_MULTICAST_ETHER_ADDR
129 #define FM10K_IS_MULTICAST_ETHER_ADDR(addr) ((addr)[0] & 0x1)
130 #endif
131
132 #ifndef FM10K_IS_VALID_ETHER_ADDR
133 /* make certain address is not multicast or 0 */
134 #define FM10K_IS_VALID_ETHER_ADDR(addr) \
135 (!FM10K_IS_MULTICAST_ETHER_ADDR(addr) && !FM10K_IS_ZERO_ETHER_ADDR(addr))
136 #endif
137
138 #ifndef do_div
139 #define do_div(n, base) ({\
140         (n) = (n) / (base);\
141 })
142 #endif /* do_div */
143
144 /* DPDK can't access IOMEM directly */
145 #ifndef FM10K_WRITE_SW_REG
146 #define FM10K_WRITE_SW_REG(v1, v2, v3)   do { } while (0)
147 #endif
148
149 #ifndef fm10k_read_reg
150 #define fm10k_read_reg FM10K_READ_REG
151 #endif
152
153 #define FM10K_INTEL_VENDOR_ID       0x8086
154 #define FM10K_DMA_CTRL_MINMSS_SHIFT             9
155 #define FM10K_EICR_PCA_FAULT                    0x00000001
156 #define FM10K_EICR_THI_FAULT                    0x00000004
157 #define FM10K_EICR_FUM_FAULT                    0x00000020
158 #define FM10K_EICR_SRAMERROR                    0x00000400
159 #define FM10K_SRAM_IP           0x13003
160 #define FM10K_RXINT_TIMER_SHIFT                 8
161 #define FM10K_TXINT_TIMER_SHIFT                 8
162 #define FM10K_RXD_PKTTYPE_MASK          0x03F0
163 #define FM10K_RXD_PKTTYPE_SHIFT         4
164
165 enum fm10k_rdesc_pkt_type {
166         /* L3 type */
167         FM10K_PKTTYPE_OTHER     = 0x00,
168         FM10K_PKTTYPE_IPV4      = 0x01,
169         FM10K_PKTTYPE_IPV4_EX   = 0x02,
170         FM10K_PKTTYPE_IPV6      = 0x03,
171         FM10K_PKTTYPE_IPV6_EX   = 0x04,
172
173         /* L4 type */
174         FM10K_PKTTYPE_TCP       = 0x08,
175         FM10K_PKTTYPE_UDP       = 0x10,
176         FM10K_PKTTYPE_GRE       = 0x18,
177         FM10K_PKTTYPE_VXLAN     = 0x20,
178         FM10K_PKTTYPE_NVGRE     = 0x28,
179         FM10K_PKTTYPE_GENEVE    = 0x30
180 };
181
182 #define FM10K_RXD_STATUS_IPCS           0x0008 /* Indicates IPv4 csum */
183 #define FM10K_RXD_STATUS_HBO            0x0400 /* header buffer overrun */
184
185 #define FM10K_TSO_MINMSS \
186         (FM10K_DMA_CTRL_MINMSS_64 >> FM10K_DMA_CTRL_MINMSS_SHIFT)
187 #define FM10K_TSO_MIN_HEADERLEN                 54
188 #define FM10K_TSO_MAX_HEADERLEN                 192
189
190 #endif /* _FM10K_OSDEP_H_ */