source: libbsdport/bsd_eth_drivers/if_em/e1000_osdep.h @ 4610a13

Last change on this file since 4610a13 was 4610a13, checked in by Till Straumann <strauman@…>, on Oct 20, 2009 at 11:46:58 PM

2009-10-20 Till Straumann <Till.Straumann@…>

  • libbsdport/libbsdport.h, if_em/e1000_osdep.h: We need BSD_VISIBLE defined. Some things in the rtems headers changed with 4.10 (can't pinpoint the details). We now #define INSIDE_RTEMS_BSD_TCPIP_STACK before explicitly including <rtems/rtems_bsdnet.h> and this seemed to fix things for 4.10.
  • Property mode set to 100644
File size: 14.3 KB
Line 
1/**************************************************************************
2
3Copyright (c) 2001-2007, 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/*$FreeBSD: src/sys/dev/em/e1000_osdep.h,v 1.3 2007/05/16 00:14:23 jfv Exp $*/
34
35
36#ifndef _FREEBSD_OS_H_
37#define _FREEBSD_OS_H_
38
39#include <rtems.h>
40#include <bsp.h>
41#include <rtems/pci.h>
42#include <vm/vm.h> /* for non-_KERNEL boolean_t :-( */
43
44#ifdef   _KERNEL
45#ifndef __INSIDE_RTEMS_BSD_TCPIP_STACK__
46#define __INSIDE_RTEMS_BSD_TCPIP_STACK__
47#endif
48#include <rtems/rtems_bsdnet.h>
49#include <rtems/rtems_bsdnet_internal.h>
50
51#include <sys/types.h>
52#include <sys/param.h>
53#include <sys/systm.h>
54#include <sys/mbuf.h>
55#include <sys/protosw.h>
56#include <sys/socket.h>
57#include <sys/malloc.h>
58#include <sys/kernel.h>
59#include <sys/bus.h>
60
61#define ASSERT(x) if(!(x)) panic("EM: x")
62
63/* The happy-fun DELAY macro is defined in /usr/src/sys/i386/include/clock.h */
64#define usec_delay(x) DELAY(x)
65#define msec_delay(x) DELAY(1000*(x))
66/* TODO: Should we be paranoid about delaying in interrupt context? */
67#define msec_delay_irq(x) DELAY(1000*(x))
68#include <rtems_udelay.h>
69
70#define MSGOUT(S, A, B)     printf(S "\n", A, B)
71#define DEBUGFUNC(F)        DEBUGOUT(F);
72        #define DEBUGOUT(S)
73        #define DEBUGOUT1(S,A)
74        #define DEBUGOUT2(S,A,B)
75        #define DEBUGOUT3(S,A,B,C)
76        #define DEBUGOUT7(S,A,B,C,D,E,F,G)
77
78#include <devicet.h>
79
80struct e1000_osdep
81{
82        uint32_t mem_bus_space_handle;
83        uint32_t io_bus_space_handle;
84        uint32_t flash_bus_space_handle;
85        /* these are currently unused; present for freebsd compatibility only */
86        uint32_t mem_bus_space_tag;
87        uint32_t io_bus_space_tag;
88        uint32_t flash_bus_space_tag;
89        device_t dev;   
90};
91
92#define STATIC                          static
93#endif
94
95#ifndef FALSE
96#define FALSE               0
97#endif
98#ifndef TRUE
99#define TRUE                1
100#endif
101
102#define CMD_MEM_WRT_INVALIDATE          0x0010  /* BIT_4 */
103#define PCI_COMMAND_REGISTER            PCIR_COMMAND
104
105/*
106** These typedefs are necessary due to the new
107** shared code, they are native to Linux.
108*/
109typedef uint64_t        u64;
110typedef uint32_t        u32;
111typedef uint16_t        u16;
112typedef uint8_t         u8 ;
113typedef int64_t         s64;
114typedef int32_t         s32;
115typedef int16_t         s16;
116typedef int8_t          s8 ;
117
118typedef volatile uint32_t __uint32_va_t __attribute__((may_alias));
119typedef volatile uint16_t __uint16_va_t __attribute__((may_alias));
120
121#ifdef NO_82542_SUPPORT
122#define E1000_REGISTER(hw, reg) reg
123#else
124#define E1000_REGISTER(hw, reg) (((hw)->mac.type >= e1000_82543) \
125    ? reg : e1000_translate_register_82542(reg))
126#endif
127
128#define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, E1000_STATUS)
129
130/* Provide our own I/O so that the low-level driver API can
131 * be used independently from the BSD stuff.
132 * This is useful for people who want to use an e1000 adapter
133 * for special ethernet links that do not use BSD TCP/IP.
134 */
135#ifdef __PPC__
136
137#include <libcpu/io.h>
138
139static inline uint16_t __in_le16(uint8_t *base, uint32_t offset)
140{
141uint16_t     rval;
142    __asm__ __volatile__(
143        "lhbrx %0,%2,%1; eieio\n"
144            : "=r" (rval)
145            : "r"(base), "b"(offset), "m"(*(__uint16_va_t*)(base + offset))
146    );
147    return rval;
148}
149
150static inline void __out_le16(uint8_t *base, uint32_t offset, uint16_t val)
151{
152    __asm__ __volatile__(
153        "sthbrx %1,%3,%2; eieio"
154            : "=o"(*(__uint16_va_t*)(base+offset))
155            : "r"(val), "r"(base), "b"(offset)
156    );
157}
158
159static inline uint32_t __in_le32(uint8_t *base, uint32_t offset)
160{
161uint32_t     rval;
162    __asm__ __volatile__(
163        "lwbrx %0,%2,%1; eieio\n"
164            : "=r" (rval)
165            : "r"(base), "b"(offset), "m"(*(__uint32_va_t*)(base + offset))
166    );
167    return rval;
168}
169
170static inline void __out_le32(uint8_t *base, uint32_t offset, uint32_t val)
171{
172    __asm__ __volatile__(
173        "stwbrx %1,%3,%2; eieio"
174            : "=o"(*(__uint32_va_t*)(base+offset))
175            : "r"(val), "r"(base), "b"(offset)
176    );
177}
178
179#ifdef _IO_BASE
180static inline void __outport_dword(unsigned long base, uint32_t off, uint32_t val)
181{
182        __out_le32((uint8_t*)(_IO_BASE+base), off, val);
183}
184#else
185#error "_IO_BASE needs to be defined by BSP (bsp.h)"
186#endif
187
188#elif defined(__i386__)
189#include <libcpu/cpu.h>
190
191static inline uint16_t __in_le16(uint8_t *base, uint32_t offset)
192{
193        return *(__uint16_va_t*)(base + offset);
194}
195
196static inline void __out_le16(uint8_t *base, uint32_t offset, uint16_t val)
197{
198        *(__uint16_va_t*)(base + offset) = val;
199}
200
201static inline uint32_t __in_le32(uint8_t *base, uint32_t offset)
202{
203        return *(__uint32_va_t*)(base + offset);
204}
205
206static inline void __out_le32(uint8_t *base, uint32_t offset, uint32_t val)
207{
208        *(__uint32_va_t*)(base + offset) = val;
209}
210
211static inline void __outport_dword(unsigned long base, uint32_t off, uint32_t val)
212{
213        i386_outport_long( (base + off), val );
214}
215
216#else
217#warning "not ported to this CPU architecture yet -- using libbsdport I/O"
218#define  USE_LIBBSDPORT_IO
219#endif
220
221#ifdef USE_LIBBSDPORT_IO
222
223#define USE_EXPLICIT_BUSTAGS
224
225#ifdef USE_EXPLICIT_BUSTAGS /* Help compiler by specifying explicit bus tags */
226
227/* Read from an absolute offset in the adapter's memory space */
228#define E1000_READ_OFFSET(hw, offset) \
229    bus_space_read_4(bus_space_mem, \
230    ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset)
231
232/* Write to an absolute offset in the adapter's memory space */
233#define E1000_WRITE_OFFSET(hw, offset, value) \
234    bus_space_write_4(bus_space_mem, \
235    ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset, value)
236
237/* Register READ/WRITE macros */
238
239#define E1000_READ_REG(hw, reg) \
240    bus_space_read_4(bus_space_mem, \
241        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
242        E1000_REGISTER(hw, reg))
243
244#define E1000_WRITE_REG(hw, reg, value) \
245    bus_space_write_4(bus_space_mem, \
246        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
247        E1000_REGISTER(hw, reg), value)
248
249#define E1000_READ_REG_ARRAY(hw, reg, index) \
250    bus_space_read_4(bus_space_mem, \
251        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
252        E1000_REGISTER(hw, reg) + ((index)<< 2))
253
254#define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \
255    bus_space_write_4(bus_space_mem, \
256        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
257        E1000_REGISTER(hw, reg) + ((index)<< 2), value)
258
259#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
260#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
261
262#define E1000_READ_REG_ARRAY_BYTE(hw, reg, index) \
263    bus_space_read_1(bus_space_mem, \
264        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
265        E1000_REGISTER(hw, reg) + index)
266
267#define E1000_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \
268    bus_space_write_1(bus_space_mem, \
269        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
270        E1000_REGISTER(hw, reg) + index, value)
271
272#define E1000_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \
273    bus_space_write_2(bus_space_mem, \
274        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
275        E1000_REGISTER(hw, reg) + (index << 1), value)
276
277#define E1000_WRITE_REG_IO(hw, reg, value) do {\
278    bus_space_write_4(bus_space_io, \
279        ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
280        (hw)->io_base, reg); \
281    bus_space_write_4(bus_space_io, \
282        ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
283        (hw)->io_base + 4, value); } while (0)
284
285#define E1000_READ_FLASH_REG(hw, reg) \
286    bus_space_read_4(bus_space_mem, \
287        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
288
289#define E1000_READ_FLASH_REG16(hw, reg) \
290    bus_space_read_2(bus_space_mem, \
291        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
292
293#define E1000_WRITE_FLASH_REG(hw, reg, value) \
294    bus_space_write_4(bus_space_mem, \
295        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
296
297#define E1000_WRITE_FLASH_REG16(hw, reg, value) \
298    bus_space_write_2(bus_space_mem, \
299        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
300
301#else /* USE_EXPLICIT_BUSTAGS */
302
303/* Read from an absolute offset in the adapter's memory space */
304#define E1000_READ_OFFSET(hw, offset) \
305    bus_space_read_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
306    ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset)
307
308/* Write to an absolute offset in the adapter's memory space */
309#define E1000_WRITE_OFFSET(hw, offset, value) \
310    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
311    ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset, value)
312
313/* Register READ/WRITE macros */
314
315#define E1000_READ_REG(hw, reg) \
316    bus_space_read_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
317        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
318        E1000_REGISTER(hw, reg))
319
320#define E1000_WRITE_REG(hw, reg, value) \
321    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
322        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
323        E1000_REGISTER(hw, reg), value)
324
325#define E1000_READ_REG_ARRAY(hw, reg, index) \
326    bus_space_read_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
327        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
328        E1000_REGISTER(hw, reg) + ((index)<< 2))
329
330#define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \
331    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
332        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
333        E1000_REGISTER(hw, reg) + ((index)<< 2), value)
334
335#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
336#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
337
338#define E1000_READ_REG_ARRAY_BYTE(hw, reg, index) \
339    bus_space_read_1(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
340        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
341        E1000_REGISTER(hw, reg) + index)
342
343#define E1000_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \
344    bus_space_write_1(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
345        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
346        E1000_REGISTER(hw, reg) + index, value)
347
348#define E1000_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \
349    bus_space_write_2(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
350        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
351        E1000_REGISTER(hw, reg) + (index << 1), value)
352
353#define E1000_WRITE_REG_IO(hw, reg, value) do {\
354    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->io_bus_space_tag, \
355        ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
356        (hw)->io_base, reg); \
357    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->io_bus_space_tag, \
358        ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
359        (hw)->io_base + 4, value); } while (0)
360
361#define E1000_READ_FLASH_REG(hw, reg) \
362    bus_space_read_4(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
363        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
364
365#define E1000_READ_FLASH_REG16(hw, reg) \
366    bus_space_read_2(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
367        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
368
369#define E1000_WRITE_FLASH_REG(hw, reg, value) \
370    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
371        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
372
373#define E1000_WRITE_FLASH_REG16(hw, reg, value) \
374    bus_space_write_2(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
375        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
376#endif /* USE_EXPLICIT_BUSTAGS */
377
378#else /* USE_LIBBSDPORT_IO */
379
380/* Read from an absolute offset in the adapter's memory space */
381#define E1000_READ_OFFSET(hw, offset) \
382        __in_le32((hw)->hw_addr, offset)
383
384/* Write to an absolute offset in the adapter's memory space */
385#define E1000_WRITE_OFFSET(hw, offset, value) \
386        __out_le32((hw)->hw_addr, offset, value)
387
388/* Register READ/WRITE macros */
389
390#define E1000_READ_REG(hw, reg) \
391        __in_le32((hw)->hw_addr, E1000_REGISTER(hw, reg))
392
393#define E1000_WRITE_REG(hw, reg, value) \
394        __out_le32((hw)->hw_addr, E1000_REGISTER(hw, reg), value)
395
396#define E1000_READ_REG_ARRAY(hw, reg, index) \
397        __in_le32((hw)->hw_addr, E1000_REGISTER(hw, reg) + ((index)<< 2))
398
399#define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \
400        __out_le32((hw)->hw_addr, E1000_REGISTER(hw, reg) + ((index)<< 2), value)
401
402#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
403#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
404
405#define E1000_WRITE_REG_IO(hw, reg, value) do { \
406        __outport_dword((hw)->io_base, 0, reg);     \
407        __outport_dword((hw)->io_base, 4, value);   \
408        } while (0)
409
410#define E1000_READ_FLASH_REG(hw, reg) \
411        __in_le32( (hw)->flash_address, reg )
412
413#define E1000_READ_FLASH_REG16(hw, reg) \
414        __in_le16( (hw)->flash_address, reg )
415
416#define E1000_WRITE_FLASH_REG(hw, reg, value) \
417        __out_le32( (hw)->flash_address, reg, value )
418
419#define E1000_WRITE_FLASH_REG16(hw, reg, value) \
420        __out_le16( (hw)->flash_address, reg, value )
421
422#endif /* USE_LIBBSDPORT_IO */
423
424
425#endif  /* _FREEBSD_OS_H_ */
426
Note: See TracBrowser for help on using the repository browser.