1 #ifndef RTEMS_COMPAT_BSD_NET_H 2 #define RTEMS_COMPAT_BSD_NET_H 13 #include <sys/errno.h> 14 #include <sys/types.h> 19 #define ISMINVERSION(ma,mi,re) \ 20 ( __RTEMS_MAJOR__ > (ma) \ 21 || (__RTEMS_MAJOR__ == (ma) && __RTEMS_MINOR__ > (mi)) \ 22 || (__RTEMS_MAJOR__ == (ma) && __RTEMS_MINOR__ == (mi) && __RTEMS_REVISION__ >= (re)) \ 26 #define _DO_ALIGN(addr, align) (((uint32_t)(addr) + (align) - 1) & ~((align)-1)) 30 static inline void *the_real_malloc(
size_t n)
35 static inline void the_real_free(
void *
p)
40 #include <machine/rtems-bsd-kernel-space.h> 41 #include <rtems/rtems_bsdnet.h> 42 #include <rtems/rtems_bsdnet_internal.h> 44 #include <libcpu/cpu.h> 45 #elif defined(__PPC__) 46 #include <libcpu/io.h> 48 #error "dunno what IO ops to use on this architecture" 52 #define NET_EMB(x,y,z) x ## y ## z 53 #define NET_EMBEMB(x,y,z) NET_EMB(x,y,z) 55 #define NET_STR(arg) #arg 56 #define NET_STRSTR(arg) NET_STR(arg) 58 #define NET_SOFTC NET_EMBEMB(,NETDRIVER_PREFIX,_softc) 60 #define METHODS NET_EMBEMB(rtems_,NETDRIVER_PREFIX,_methods) 64 #define METHODSPTR NET_EMBEMB(rtems_,NETDRIVER_PREFIX,_methods_p) 67 #define METHODSPTR (&METHODS) 70 #if defined(__LITTLE_ENDIAN__) || (__i386__) 71 static inline uint16_t htole16(uint16_t
v) {
return v; }
72 static inline uint32_t htole32(uint32_t
v) {
return v; }
73 static inline uint64_t htole64(uint64_t
v) {
return v; }
74 static inline uint16_t le16toh(uint16_t
v) {
return v; }
75 static inline uint32_t le32toh(uint32_t
v) {
return v; }
76 static inline uint64_t le64toh(uint64_t
v) {
return v; }
77 #elif defined(__BIG_ENDIAN__) 79 #include <libcpu/byteorder.h> 87 #if ISMINVERSION(4,8,0) 88 typedef uint32_t rtemscompat_32_t;
90 typedef unsigned rtemscompat_32_t;
93 static inline uint16_t
101 static inline uint16_t
104 return ld_le16((
unsigned short*)&
v);
107 static inline uint32_t
110 rtemscompat_32_t rval;
115 static inline uint32_t
118 rtemscompat_32_t vv =
v;
126 static inline uint64_t
130 rtemscompat_32_t tmp[2];
134 st_le32( &u.tmp[0], (
unsigned)(
v&0xffffffff) );
135 st_le32( &u.tmp[1], (
unsigned)((
v>>32)&0xffffffff) );
141 #error "need htoleXX() implementation for this CPU arch" 145 #error "Unknown CPU endianness" 151 #define _out_byte(a,v) out_8((volatile uint8_t*)(a),(v)) 152 #define _inp_byte(a) in_8((volatile uint8_t*)(a)) 154 #define _out_word(a,v) out_le16((volatile uint16_t*)(a),(v)) 155 #define _out_long(a,v) out_le32((volatile uint32_t *)(a),(v)) 156 #define _inp_word(a) in_le16((volatile uint16_t*)(a)) 157 #define _inp_long(a) in_le32((volatile uint32_t *)(a)) 158 #elif defined(NET_CHIP_BE) 159 #define _out_word(a,v) out_be16((volatile uint16_t*)(a),(v)) 160 #define _out_long(a,v) out_be32((volatile uint32_t *)(a),(v)) 161 #define _inp_word(a) in_be16((volatile uint16_t*)(a)) 162 #define _inp_long(a) in_be32((volatile uint32_t *)(a)) 164 #error rtemscompat_defs.h must define either NET_CHIP_LE or NET_CHIP_BE 166 static inline void wrle32(
unsigned *a,
unsigned v)
168 asm volatile(
"stwbrx %1,0,%2":
"=m"(*a):
"r"(
v),
"r"(a));
170 static inline unsigned rdle32(
unsigned *a)
172 asm volatile(
"lwbrx %0,0,%0":
"=r"(a):
"0"(a),
"m"(*a));
175 static inline void orle32(
unsigned *a,
unsigned v) { wrle32(a, rdle32(a) |
v); }
176 static inline void anle32(
unsigned *a,
unsigned v) { wrle32(a, rdle32(a) &
v); }
178 static inline void wrle16(
unsigned short *a,
unsigned short v)
180 asm volatile(
"sthbrx %1,0,%2":
"=m"(*a):
"r"(
v),
"r"(a));
182 static inline unsigned short rdle16(
unsigned short *a)
184 asm volatile(
"lhbrx %0,0,%0":
"=r"(a):
"0"(a),
"m"(*a));
185 return (
unsigned short)(unsigned)a;
187 static inline void orle16(
unsigned short *a,
unsigned short v) { wrle16(a, rdle16(a) |
v); }
188 static inline void anle16(
unsigned short *a,
unsigned short v) { wrle16(a, rdle16(a) &
v); }
193 #error dunno how to output BE data 196 static inline void wrle32(
volatile unsigned *
p,
unsigned v) { *
p =
v; }
197 static inline void orle32(
volatile unsigned *
p,
unsigned v) { *
p |=
v; }
198 static inline void anle32(
volatile unsigned *
p,
unsigned v) { *
p &=
v; }
199 static inline unsigned rdle32(
volatile unsigned *
p) {
return *
p; }
201 static inline void wrle16(
volatile unsigned short *
p,
unsigned short v) { *
p =
v; }
202 static inline void orle16(
volatile unsigned short *
p,
unsigned short v) { *
p |=
v; }
203 static inline void anle16(
volatile unsigned short *
p,
unsigned short v) { *
p &=
v; }
204 static inline unsigned short rdle16(
volatile unsigned short *
p) {
return *
p; }
206 #ifdef NET_CHIP_MEM_IO 209 static inline void _out_byte(
unsigned a,
unsigned char v) { *(
volatile unsigned char*)a =
v; }
210 static inline unsigned char _inp_byte(
unsigned a) {
return *(
volatile unsigned char*)a; }
212 static inline void _out_word(
unsigned a,
unsigned short v) { *(
volatile unsigned short*)a =
v; }
213 static inline unsigned short _inp_word(
unsigned a) {
return *(
volatile unsigned short*)a; }
214 static inline void _out_long(
unsigned a,
unsigned v) { *(
volatile unsigned *)a =
v; }
215 static inline unsigned _inp_long(
unsigned a) {
return *(
volatile unsigned *)a; }
216 #elif defined(NET_CHIP_BE) 217 #error "BE memory IO not implemented for i386 yet" 219 #error rtemscompat_defs.h must define either NET_CHIP_LE or NET_CHIP_BE 223 #error "Memory IO not implemented for this CPU architecture yet" 226 #elif defined(NET_CHIP_PORT_IO) 227 #define _out_byte(addr,val) outport_byte((addr),(val)) 228 #define _out_word(addr,val) outport_word((addr),(val)) 229 #define _out_long(addr,val) outport_long((addr),(val)) 231 static inline u_int8_t _inp_byte(
volatile unsigned char *a)
233 register u_int8_t rval;
234 inport_byte((
unsigned short)(
unsigned)a,rval);
237 static inline u_int16_t _inp_word(
volatile unsigned short *a)
239 register u_int16_t rval;
240 inport_word((
unsigned short)(
unsigned)a,rval);
243 static inline u_int32_t _inp_long(
volatile unsigned *a)
245 register u_int32_t rval;
246 inport_long((
unsigned short)(
unsigned)a,rval);
250 #error either NET_CHIP_MEM_IO or NET_CHIP_PORT_IO must be defined 255 #define __FBSDID(arg) 258 #define device_printf(device,format,args...) printk(format,## args) 260 static inline u_int8_t bus_space_do_read_1(u_long handle,
unsigned reg)
262 return _inp_byte((
volatile unsigned char*)((handle)+(reg)));
265 static inline u_int16_t bus_space_do_read_2(u_long handle,
unsigned reg)
267 return _inp_word((
volatile unsigned short*)((handle)+(reg)));
270 static inline u_int32_t bus_space_do_read_4(u_long handle,
unsigned reg)
272 return _inp_long((
volatile unsigned *)((handle)+(reg)));
275 #define bus_space_read_1(tag,handle,reg) bus_space_do_read_1((handle),(reg)) 276 #define bus_space_read_2(tag,handle,reg) bus_space_do_read_2((handle),(reg)) 277 #define bus_space_read_4(tag,handle,reg) bus_space_do_read_4((handle),(reg)) 279 static inline void bus_space_do_write_multi_1(u_long handle,
unsigned reg,
unsigned char *addr,
int cnt)
281 int i;
for (i=0; i<cnt; i++) _out_byte( (handle) + (reg), (addr)[i]);
284 static inline void bus_space_do_write_multi_2(u_long handle,
unsigned reg,
unsigned short *addr,
int cnt)
286 int i;
for (i=0; i<cnt; i++) _out_word( (handle) + (reg), (addr)[i]);
289 static inline void bus_space_do_write_multi_4(u_long handle,
unsigned reg,
unsigned long *addr,
int cnt)
291 int i;
for (i=0; i<cnt; i++) _out_long( (handle) + (reg), (addr)[i]);
295 #define bus_space_write_multi_1(tag, handle, reg, addr, cnt) \ 296 bus_space_do_write_multi_1(handle, reg, addr, cnt) 297 #define bus_space_write_multi_2(tag, handle, reg, addr, cnt) \ 298 bus_space_do_write_multi_2(handle, reg, addr, cnt) 299 #define bus_space_write_multi_4(tag, handle, reg, addr, cnt) \ 300 bus_space_do_write_multi_4(handle, reg, addr, cnt) 302 static inline void bus_space_do_read_multi_1(u_long handle,
unsigned reg,
unsigned char *addr,
int cnt)
304 int i;
for (i=0; i<cnt; i++)
305 (addr)[i] = _inp_byte((
volatile unsigned char*)((handle)+(reg)));
308 static inline void bus_space_do_read_multi_2(u_long handle,
unsigned reg,
unsigned short *addr,
int cnt)
310 int i;
for (i=0; i<cnt; i++)
311 (addr)[i] = _inp_word((
volatile unsigned short*)((handle)+(reg)));
314 static inline void bus_space_do_read_multi_4(u_long handle,
unsigned reg,
unsigned long *addr,
int cnt)
316 int i;
for (i=0; i<cnt; i++)
317 (addr)[i] = _inp_long((
volatile unsigned *)((handle)+(reg)));
320 #define bus_space_read_multi_1(tag, handle, reg, addr, cnt) \ 321 bus_space_do_read_multi_1(handle, reg, addr, cnt) 322 #define bus_space_read_multi_2(tag, handle, reg, addr, cnt) \ 323 bus_space_do_read_multi_2(handle, reg, addr, cnt) 324 #define bus_space_read_multi_4(tag, handle, reg, addr, cnt) \ 325 bus_space_do_read_multi_4(handle, reg, addr, cnt) 329 #define bus_space_write_1(tag, handle, reg, val) \ 330 do { _out_byte( (handle) + (reg), (val)); } while (0) 332 #define bus_space_write_2(tag, handle, reg, val) \ 333 do { _out_word( (handle) + (reg), (val)); } while (0) 335 #define bus_space_write_4(tag, handle, reg, val) \ 336 do { _out_long( (handle) + (reg), (val)); } while (0) 338 #define BPF_MTAP(a,b) do { } while (0) 340 extern unsigned net_driver_ticks_per_sec;
344 #define DELAY(n) do { \ 346 rtems_task_wake_after((((n)*net_driver_ticks_per_sec)/1000000) + 1); \ 348 rtems_bsp_delay(n); \ 351 #warning "Have no good usec delay implementation" 352 #define DELAY(n) do { \ 353 rtems_task_wake_after((((n)*net_driver_ticks_per_sec)/1000000) + 1); \ 358 #define IRQ_LOCKED(code) \ 359 do { unsigned long _xtre_irq_flags; \ 360 rtems_interrupt_disable(_xtre_irq_flags); \ 361 do { code } while(0); \ 362 rtems_interrupt_enable(_xtre_irq_flags); \ 365 typedef void (driver_intr_t)(
void *);
367 #define if_xname if_name 372 #ifndef PCI_DRAM_OFFSET 373 #define PCI_DRAM_OFFSET 0 377 #define PCI_MEM_BASE 0 380 #define kvtop(a) ((unsigned long)(a) + PCI_DRAM_OFFSET) 381 #define vtophys(a) ((unsigned long)(a) + PCI_DRAM_OFFSET) 383 #define PCI2LOCAL(a,bus) ((unsigned long)(a) + PCI_MEM_BASE) 386 #define PCI_IO_2LOCAL(a,bus) ((unsigned long)(a) + PCI0_IO_BASE) 387 #elif defined(PCI_IO_BASE) 388 #define PCI_IO_2LOCAL(a,bus) ((unsigned long)(a) + PCI_IO_BASE) 389 #elif defined(_IO_BASE) 390 #define PCI_IO_2LOCAL(a,bus) ((unsigned long)(a) + _IO_BASE) 392 #warning "Unable to determine base address of PCI IO space; using ZERO" 393 #define PCI_IO_2LOCAL(a,bus) ((unsigned long)(a)) 396 #define if_printf(if,fmt,args...) printf("%s:"fmt,(if)->if_name,args) 398 #ifndef BUS_PROBE_DEFAULT 399 #define BUS_PROBE_DEFAULT 0 412 void *ptr = rtems_bsdnet_malloc(
size +
sizeof(ptr) + align-1, type, flags);
415 unsigned tmp = (unsigned)ptr + align - 1;
419 *(
void**)(rval+
size) = ptr;
425 contigfree(
void *ptr,
size_t size,
int type)
427 rtems_bsdnet_free( *(
void**)((
unsigned)ptr +
size), type);
431 #define callout_init(args...) do {} while (0); 432 #define callout_reset(args...) do {} while (0); 433 #define callout_stop(args...) do {} while (0); 435 #define IFQ_DRV_IS_EMPTY(q) (0 == (q)->ifq_head) 436 #define IFQ_DRV_DEQUEUE(q,m) IF_DEQUEUE((q),(m)) 437 #define IFQ_DRV_PREPEND(q,m) IF_PREPEND((q),(m)) 439 #define DO_ETHER_INPUT_SKIPPING_ETHER_HEADER(ifp,m) \ 440 { struct ether_header *eh; \ 441 eh = mtod(m, struct ether_header*); \ 442 m->m_data += sizeof(struct ether_header); \ 443 m->m_len -= sizeof(struct ether_header); \ 444 m->m_pkthdr.len -= sizeof(struct ether_header); \ 445 m->m_pkthdr.rcvif = ifp; \ 446 ether_input(ifp, eh, m); \ 450 #ifndef __KERNEL_RCSID 451 #define __KERNEL_RCSID(arg...) unsigned p
Definition: tte.h:90
Interface to Kernel Print Methods.
unsigned size
Definition: tte.h:74
unsigned v
Definition: tte.h:73
Definition: rtemscompat1.h:32