xref: /openbsd/sys/dev/pci/if_em_osdep.h (revision cecf84d4)
1 /**************************************************************************
2 
3 Copyright (c) 2001-2006, 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 /* $OpenBSD: if_em_osdep.h,v 1.12 2011/10/05 02:52:10 jsg Exp $ */
35 /* $FreeBSD: if_em_osdep.h,v 1.11 2003/05/02 21:17:08 pdeuskar Exp $ */
36 
37 #ifndef _EM_OPENBSD_OS_H_
38 #define _EM_OPENBSD_OS_H_
39 
40 #define usec_delay(x)		DELAY(x)
41 #define msec_delay(x)		DELAY(1000*(x))
42 /* TODO: Should we be paranoid about delaying in interrupt context? */
43 #define msec_delay_irq(x)	DELAY(1000*(x))
44 
45 #define MSGOUT(S, A, B)		printf(S "\n", A, B)
46 #define DEBUGFUNC(F)		DEBUGOUT(F);
47 #ifdef DBG
48 	#define DEBUGOUT(S)			printf(S "\n")
49 	#define DEBUGOUT1(S,A)			printf(S "\n",A)
50 	#define DEBUGOUT2(S,A,B)		printf(S "\n",A,B)
51 	#define DEBUGOUT3(S,A,B,C)		printf(S "\n",A,B,C)
52 	#define DEBUGOUT7(S,A,B,C,D,E,F,G)	printf(S "\n",A,B,C,D,E,F,G)
53 #else
54 	#define DEBUGOUT(S)
55 	#define DEBUGOUT1(S,A)
56 	#define DEBUGOUT2(S,A,B)
57 	#define DEBUGOUT3(S,A,B,C)
58 	#define DEBUGOUT7(S,A,B,C,D,E,F,G)
59 #endif
60 
61 #define CMD_MEM_WRT_INVALIDATE		0x0010  /* BIT_4 */
62 
63 struct em_osdep
64 {
65 	bus_space_tag_t		mem_bus_space_tag;
66 	bus_space_handle_t	mem_bus_space_handle;
67 	bus_space_tag_t		io_bus_space_tag;
68 	bus_space_handle_t	io_bus_space_handle;
69 	bus_space_tag_t		flash_bus_space_tag;
70 	bus_space_handle_t	flash_bus_space_handle;
71 	struct device		*dev;
72 
73 	struct pci_attach_args	em_pa;
74 
75 	bus_size_t		em_memsize;
76 	bus_addr_t		em_membase;
77 	bus_size_t		em_iosize;
78 	bus_addr_t		em_iobase;
79 	bus_size_t		em_flashsize;
80 	bus_addr_t		em_flashbase;
81 };
82 
83 #define E1000_WRITE_FLUSH(hw)	E1000_READ_REG(hw, STATUS)
84 
85 /* Read from an absolute offset in the adapter's memory space */
86 #define E1000_READ_OFFSET(hw, offset) \
87 	bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
88 			 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
89 			  offset)
90 
91 /* Write to an absolute offset in the adapter's memory space */
92 #define E1000_WRITE_OFFSET(hw, offset, value) \
93 	bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
94 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
95 			   offset, value)
96 
97 /* Convert a register name to its offset in the adapter's memory space */
98 #define E1000_REG_OFFSET(hw, reg) \
99 	((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg)
100 
101 /* Register READ/WRITE macros */
102 
103 #define E1000_READ_REG(hw, reg) \
104 	bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
105 			 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
106 			  ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg))
107 
108 #define E1000_WRITE_REG(hw, reg, value) \
109 	bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
110 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
111 			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg), \
112 			   value)
113 
114 #define EM_READ_REG(hw, reg) \
115 	bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
116 			 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
117 			  reg)
118 
119 #define EM_WRITE_REG(hw, reg, value) \
120 	bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
121 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
122 			   reg, value)
123 
124 
125 #define E1000_READ_REG_ARRAY(hw, reg, index) \
126 	bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
127 			 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
128 			  ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg) \
129 			  + ((index) << 2))
130 
131 #define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \
132 	bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
133 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
134 			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg) \
135 			   + ((index) << 2), value)
136 
137 #define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
138 #define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
139 
140 #define E1000_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \
141 	bus_space_write_1(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
142 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
143 			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg \
144 			   + index), value)
145 
146 #define E1000_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \
147 	bus_space_write_2(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
148 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
149 			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg \
150 			   + (index << 1)), value)
151 
152 #define E1000_READ_ICH_FLASH_REG(hw, reg) \
153 	bus_space_read_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
154 			 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, reg)
155 
156 #define E1000_READ_ICH_FLASH_REG16(hw, reg) \
157 	bus_space_read_2(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
158 			 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, reg)
159 
160 #define E1000_WRITE_ICH_FLASH_REG(hw, reg, value) \
161 	bus_space_write_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
162 			  ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
163 			   reg, value)
164 
165 #define E1000_WRITE_ICH_FLASH_REG16(hw, reg, value) \
166 	bus_space_write_2(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
167 			  ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
168 			   reg, value)
169 
170 #define em_io_read(hw, port) \
171 	bus_space_read_4(((struct em_osdep *)(hw)->back)->io_bus_space_tag, \
172 			 ((struct em_osdep *)(hw)->back)->io_bus_space_handle, (port))
173 
174 #define em_io_write(hw, port, value) \
175 	bus_space_write_4(((struct em_osdep *)(hw)->back)->io_bus_space_tag, \
176 			  ((struct em_osdep *)(hw)->back)->io_bus_space_handle, \
177 			   (port), (value))
178 
179 #ifdef DEBUG
180 #define EM_KASSERT(exp,msg)	do { if (!(exp)) panic msg; } while (0)
181 #else
182 #define EM_KASSERT(exp,msg)
183 #endif
184 
185 #endif  /* _EM_OPENBSD_OS_H_ */
186