if_em_osdep.h revision 1.11
1/**************************************************************************
2
3Copyright (c) 2001-2006, Intel Corporation
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, 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
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30POSSIBILITY OF SUCH DAMAGE.
31
32***************************************************************************/
33
34/* $OpenBSD: if_em_osdep.h,v 1.11 2011/07/26 14:57:57 deraadt 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
63struct 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 E1000_READ_REG_ARRAY(hw, reg, index) \
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			  ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg) \
118			  + ((index) << 2))
119
120#define E1000_WRITE_REG_ARRAY(hw, reg, index, 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			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg) \
124			   + ((index) << 2), value)
125
126#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
127#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
128
129#define E1000_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \
130	bus_space_write_1(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
131			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
132			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg \
133			   + index), value)
134
135#define E1000_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \
136	bus_space_write_2(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \
137			  ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \
138			   ((hw)->mac_type >= em_82543 ? E1000_##reg : E1000_82542_##reg \
139			   + (index << 1)), value)
140
141#define E1000_READ_ICH_FLASH_REG(hw, reg) \
142	bus_space_read_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
143			 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, reg)
144
145#define E1000_READ_ICH_FLASH_REG16(hw, reg) \
146	bus_space_read_2(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
147			 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, reg)
148
149#define E1000_WRITE_ICH_FLASH_REG(hw, reg, value) \
150	bus_space_write_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
151			  ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
152			   reg, value)
153
154#define E1000_WRITE_ICH_FLASH_REG16(hw, reg, value) \
155	bus_space_write_2(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \
156			  ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \
157			   reg, value)
158
159#define em_io_read(hw, port) \
160	bus_space_read_4(((struct em_osdep *)(hw)->back)->io_bus_space_tag, \
161			 ((struct em_osdep *)(hw)->back)->io_bus_space_handle, (port))
162
163#define em_io_write(hw, port, value) \
164	bus_space_write_4(((struct em_osdep *)(hw)->back)->io_bus_space_tag, \
165			  ((struct em_osdep *)(hw)->back)->io_bus_space_handle, \
166			   (port), (value))
167
168#ifdef DEBUG
169#define EM_KASSERT(exp,msg)	do { if (!(exp)) panic msg; } while (0)
170#else
171#define EM_KASSERT(exp,msg)
172#endif
173
174#endif  /* _EM_OPENBSD_OS_H_ */
175