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