xref: /openbsd/sys/dev/pci/if_em_osdep.h (revision 264ca280)
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.13 2016/02/18 14:24:39 bluhm 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 	size_t			em_flashoffset;
82 };
83 
84 #define E1000_WRITE_FLUSH(hw)	E1000_READ_REG(hw, STATUS)
85 
86 /* Read from an absolute offset in the adapter's memory space */
87 #define E1000_READ_OFFSET(hw, offset) \
88 	bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
89 			 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
90 			  offset)
91 
92 /* Write to an absolute offset in the adapter's memory space */
93 #define E1000_WRITE_OFFSET(hw, offset, value) \
94 	bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
95 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
96 			   offset, value)
97 
98 /* Convert a register name to its offset in the adapter's memory space */
99 #define E1000_REG_OFFSET(hw, reg) \
100 	((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg)
101 
102 /* Register READ/WRITE macros */
103 
104 #define E1000_READ_REG(hw, reg) \
105 	bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
106 			 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
107 			  ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg))
108 
109 #define E1000_WRITE_REG(hw, reg, value) \
110 	bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
111 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
112 			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg), \
113 			   value)
114 
115 #define EM_READ_REG(hw, reg) \
116 	bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
117 			 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
118 			  reg)
119 
120 #define EM_WRITE_REG(hw, reg, value) \
121 	bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
122 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
123 			   reg, value)
124 
125 
126 #define E1000_READ_REG_ARRAY(hw, reg, index) \
127 	bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
128 			 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
129 			  ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg) \
130 			  + ((index) << 2))
131 
132 #define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \
133 	bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
134 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
135 			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg) \
136 			   + ((index) << 2), value)
137 
138 #define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
139 #define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
140 
141 #define E1000_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \
142 	bus_space_write_1(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
143 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
144 			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg \
145 			   + index), value)
146 
147 #define E1000_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \
148 	bus_space_write_2(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
149 			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
150 			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg \
151 			   + (index << 1)), value)
152 
153 #define E1000_READ_ICH_FLASH_REG(hw, reg) \
154 	bus_space_read_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
155 			 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
156 			 ((struct em_osdep *)(hw)->back)->em_flashoffset + reg)
157 
158 #define E1000_READ_ICH_FLASH_REG16(hw, reg) \
159 	bus_space_read_2(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
160 			 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
161 			 ((struct em_osdep *)(hw)->back)->em_flashoffset + reg)
162 
163 #define E1000_READ_ICH_FLASH_REG32(hw, reg) \
164 	bus_space_read_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
165 			 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
166 			 ((struct em_osdep *)(hw)->back)->em_flashoffset + reg)
167 
168 
169 #define E1000_WRITE_ICH_FLASH_REG8(hw, reg, value) \
170 	bus_space_write_1(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
171 			  ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
172 			  ((struct em_osdep *)(hw)->back)->em_flashoffset + reg, \
173 			  value)
174 
175 #define E1000_WRITE_ICH_FLASH_REG16(hw, reg, value) \
176 	bus_space_write_2(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
177 			  ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
178 			  ((struct em_osdep *)(hw)->back)->em_flashoffset + reg, \
179 			  value)
180 
181 #define E1000_WRITE_ICH_FLASH_REG32(hw, reg, value) \
182 	bus_space_write_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
183 			  ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
184 			  ((struct em_osdep *)(hw)->back)->em_flashoffset + reg, \
185 			  value)
186 
187 #define em_io_read(hw, port) \
188 	bus_space_read_4(((struct em_osdep *)(hw)->back)->io_bus_space_tag, \
189 			 ((struct em_osdep *)(hw)->back)->io_bus_space_handle, (port))
190 
191 #define em_io_write(hw, port, value) \
192 	bus_space_write_4(((struct em_osdep *)(hw)->back)->io_bus_space_tag, \
193 			  ((struct em_osdep *)(hw)->back)->io_bus_space_handle, \
194 			   (port), (value))
195 
196 #ifdef DEBUG
197 #define EM_KASSERT(exp,msg)	do { if (!(exp)) panic msg; } while (0)
198 #else
199 #define EM_KASSERT(exp,msg)
200 #endif
201 
202 #endif  /* _EM_OPENBSD_OS_H_ */
203