New upstream version 18.02
[deb_dpdk.git] / lib / librte_eal / linuxapp / kni / ethtool / igb / e1000_osdep.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*******************************************************************************
3
4   Intel(R) Gigabit Ethernet Linux driver
5   Copyright(c) 2007-2013 Intel Corporation.
6
7   Contact Information:
8   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
9   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
10
11 *******************************************************************************/
12
13
14 /* glue for the OS independent part of e1000
15  * includes register access macros
16  */
17
18 #ifndef _E1000_OSDEP_H_
19 #define _E1000_OSDEP_H_
20
21 #include <linux/pci.h>
22 #include <linux/delay.h>
23 #include <linux/interrupt.h>
24 #include <linux/if_ether.h>
25 #include <linux/sched.h>
26 #include "kcompat.h"
27
28 #ifndef __INTEL_COMPILER
29 #pragma GCC diagnostic ignored "-Wunused-function"
30 #endif
31
32 #define usec_delay(x) udelay(x)
33 #define usec_delay_irq(x) udelay(x)
34 #ifndef msec_delay
35 #define msec_delay(x) do { \
36         /* Don't mdelay in interrupt context! */ \
37         if (in_interrupt()) \
38                 BUG(); \
39         else \
40                 msleep(x); \
41 } while (0)
42
43 /* Some workarounds require millisecond delays and are run during interrupt
44  * context.  Most notably, when establishing link, the phy may need tweaking
45  * but cannot process phy register reads/writes faster than millisecond
46  * intervals...and we establish link due to a "link status change" interrupt.
47  */
48 #define msec_delay_irq(x) mdelay(x)
49 #endif
50
51 #define PCI_COMMAND_REGISTER   PCI_COMMAND
52 #define CMD_MEM_WRT_INVALIDATE PCI_COMMAND_INVALIDATE
53 #define ETH_ADDR_LEN           ETH_ALEN
54
55 #ifdef __BIG_ENDIAN
56 #define E1000_BIG_ENDIAN __BIG_ENDIAN
57 #endif
58
59
60 #ifdef DEBUG
61 #define DEBUGOUT(S) printk(KERN_DEBUG S)
62 #define DEBUGOUT1(S, A...) printk(KERN_DEBUG S, ## A)
63 #else
64 #define DEBUGOUT(S)
65 #define DEBUGOUT1(S, A...)
66 #endif
67
68 #ifdef DEBUG_FUNC
69 #define DEBUGFUNC(F) DEBUGOUT(F "\n")
70 #else
71 #define DEBUGFUNC(F)
72 #endif
73 #define DEBUGOUT2 DEBUGOUT1
74 #define DEBUGOUT3 DEBUGOUT2
75 #define DEBUGOUT7 DEBUGOUT3
76
77 #define E1000_REGISTER(a, reg) reg
78
79 #define E1000_WRITE_REG(a, reg, value) ( \
80     writel((value), ((a)->hw_addr + E1000_REGISTER(a, reg))))
81
82 #define E1000_READ_REG(a, reg) (readl((a)->hw_addr + E1000_REGISTER(a, reg)))
83
84 #define E1000_WRITE_REG_ARRAY(a, reg, offset, value) ( \
85     writel((value), ((a)->hw_addr + E1000_REGISTER(a, reg) + ((offset) << 2))))
86
87 #define E1000_READ_REG_ARRAY(a, reg, offset) ( \
88     readl((a)->hw_addr + E1000_REGISTER(a, reg) + ((offset) << 2)))
89
90 #define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
91 #define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
92
93 #define E1000_WRITE_REG_ARRAY_WORD(a, reg, offset, value) ( \
94     writew((value), ((a)->hw_addr + E1000_REGISTER(a, reg) + ((offset) << 1))))
95
96 #define E1000_READ_REG_ARRAY_WORD(a, reg, offset) ( \
97     readw((a)->hw_addr + E1000_REGISTER(a, reg) + ((offset) << 1)))
98
99 #define E1000_WRITE_REG_ARRAY_BYTE(a, reg, offset, value) ( \
100     writeb((value), ((a)->hw_addr + E1000_REGISTER(a, reg) + (offset))))
101
102 #define E1000_READ_REG_ARRAY_BYTE(a, reg, offset) ( \
103     readb((a)->hw_addr + E1000_REGISTER(a, reg) + (offset)))
104
105 #define E1000_WRITE_REG_IO(a, reg, offset) do { \
106     outl(reg, ((a)->io_base));                  \
107     outl(offset, ((a)->io_base + 4));      } while (0)
108
109 #define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, E1000_STATUS)
110
111 #define E1000_WRITE_FLASH_REG(a, reg, value) ( \
112     writel((value), ((a)->flash_address + reg)))
113
114 #define E1000_WRITE_FLASH_REG16(a, reg, value) ( \
115     writew((value), ((a)->flash_address + reg)))
116
117 #define E1000_READ_FLASH_REG(a, reg) (readl((a)->flash_address + reg))
118
119 #define E1000_READ_FLASH_REG16(a, reg) (readw((a)->flash_address + reg))
120
121 #endif /* _E1000_OSDEP_H_ */