3b6298010da5400565d98855d30e2afcedf76ff5
[dpdk.git] / drivers / net / fm10k / base / fm10k_osdep.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2013 - 2015 Intel Corporation
3  */
4
5 #ifndef _FM10K_OSDEP_H_
6 #define _FM10K_OSDEP_H_
7
8 #include <stdint.h>
9 #include <string.h>
10 #include <rte_atomic.h>
11 #include <rte_byteorder.h>
12 #include <rte_cycles.h>
13 #include <rte_io.h>
14
15 #include "../fm10k_logs.h"
16
17 /* TODO: this does not look like it should be used... */
18 #define ERROR_REPORT2(v1, v2, v3)   do { } while (0)
19
20 #ifndef BOULDER_RAPIDS_HW
21 #define BOULDER_RAPIDS_HW
22 #endif
23
24 #define STATIC                  static
25 #define DEBUGFUNC(F)            DEBUGOUT(F "\n");
26 #define DEBUGOUT(S, args...)    PMD_DRV_LOG_RAW(DEBUG, S, ##args)
27 #define DEBUGOUT1(S, args...)   DEBUGOUT(S, ##args)
28 #define DEBUGOUT2(S, args...)   DEBUGOUT(S, ##args)
29 #define DEBUGOUT3(S, args...)   DEBUGOUT(S, ##args)
30 #define DEBUGOUT6(S, args...)   DEBUGOUT(S, ##args)
31 #define DEBUGOUT7(S, args...)   DEBUGOUT(S, ##args)
32
33 #define FALSE      0
34 #define TRUE       1
35 #ifndef false
36 #define false      FALSE
37 #endif
38 #ifndef true
39 #define true       TRUE
40 #endif
41
42 typedef uint8_t    u8;
43 typedef int8_t     s8;
44 typedef uint16_t   u16;
45 typedef int16_t    s16;
46 typedef uint32_t   u32;
47 typedef int32_t    s32;
48 typedef int64_t    s64;
49 typedef uint64_t   u64;
50 typedef int        bool;
51
52 #ifndef __le16
53 #define __le16     u16
54 #define __le32     u32
55 #define __le64     u64
56 #endif
57 #ifndef __be16
58 #define __be16     u16
59 #define __be32     u32
60 #define __be64     u64
61 #endif
62
63 /* offsets are WORD offsets, not BYTE offsets */
64 #define FM10K_WRITE_REG(hw, reg, val)           \
65         rte_write32((val), ((hw)->hw_addr + (reg)))
66
67 #define FM10K_READ_REG(hw, reg) rte_read32(((hw)->hw_addr + (reg)))
68
69 #define FM10K_WRITE_FLUSH(a) FM10K_READ_REG(a, FM10K_CTRL)
70
71 #define FM10K_PCI_REG(reg) rte_read32(reg)
72
73 #define FM10K_PCI_REG_WRITE(reg, value) rte_write32((value), (reg))
74
75 /* not implemented */
76 #define FM10K_READ_PCI_WORD(hw, reg)     0
77
78 #define FM10K_WRITE_MBX(hw, reg, value) FM10K_WRITE_REG(hw, reg, value)
79 #define FM10K_READ_MBX(hw, reg) FM10K_READ_REG(hw, reg)
80
81 #define FM10K_LE16_TO_CPU    rte_le_to_cpu_16
82 #define FM10K_LE32_TO_CPU    rte_le_to_cpu_32
83 #define FM10K_CPU_TO_LE32    rte_cpu_to_le_32
84 #define FM10K_CPU_TO_LE16    rte_cpu_to_le_16
85 #define le16_to_cpu          rte_le_to_cpu_16
86
87 #define FM10K_RMB            rte_rmb
88 #define FM10K_WMB            rte_wmb
89
90 #define usec_delay           rte_delay_us
91
92 #define FM10K_REMOVED(hw_addr) (!(hw_addr))
93
94 #ifndef FM10K_IS_ZERO_ETHER_ADDR
95 /* make certain address is not 0 */
96 #define FM10K_IS_ZERO_ETHER_ADDR(addr) \
97 (!((addr)[0] | (addr)[1] | (addr)[2] | (addr)[3] | (addr)[4] | (addr)[5]))
98 #endif
99
100 #ifndef FM10K_IS_MULTICAST_ETHER_ADDR
101 #define FM10K_IS_MULTICAST_ETHER_ADDR(addr) ((addr)[0] & 0x1)
102 #endif
103
104 #ifndef FM10K_IS_VALID_ETHER_ADDR
105 /* make certain address is not multicast or 0 */
106 #define FM10K_IS_VALID_ETHER_ADDR(addr) \
107 (!FM10K_IS_MULTICAST_ETHER_ADDR(addr) && !FM10K_IS_ZERO_ETHER_ADDR(addr))
108 #endif
109
110 #ifndef do_div
111 #define do_div(n, base) ({\
112         (n) = (n) / (base);\
113 })
114 #endif /* do_div */
115
116 /* DPDK can't access IOMEM directly */
117 #ifndef FM10K_WRITE_SW_REG
118 #define FM10K_WRITE_SW_REG(v1, v2, v3)   do { } while (0)
119 #endif
120
121 #ifndef fm10k_read_reg
122 #define fm10k_read_reg FM10K_READ_REG
123 #endif
124
125 #define FM10K_INTEL_VENDOR_ID       0x8086
126 #define FM10K_DMA_CTRL_MINMSS_SHIFT             9
127 #define FM10K_EICR_PCA_FAULT                    0x00000001
128 #define FM10K_EICR_THI_FAULT                    0x00000004
129 #define FM10K_EICR_FUM_FAULT                    0x00000020
130 #define FM10K_EICR_SRAMERROR                    0x00000400
131 #define FM10K_SRAM_IP           0x13003
132 #define FM10K_RXINT_TIMER_SHIFT                 8
133 #define FM10K_TXINT_TIMER_SHIFT                 8
134 #define FM10K_RXD_PKTTYPE_MASK          0x03F0
135 #define FM10K_RXD_PKTTYPE_SHIFT         4
136
137 #define FM10K_RXD_STATUS_IPCS           0x0008 /* Indicates IPv4 csum */
138 #define FM10K_RXD_STATUS_HBO            0x0400 /* header buffer overrun */
139
140 #define FM10K_TSO_MINMSS \
141         (FM10K_DMA_CTRL_MINMSS_64 >> FM10K_DMA_CTRL_MINMSS_SHIFT)
142 #define FM10K_TSO_MIN_HEADERLEN                 54
143 #define FM10K_TSO_MAX_HEADERLEN                 192
144
145 #endif /* _FM10K_OSDEP_H_ */