Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / ethernet.h
1 #ifndef _IPXE_ETHERNET_H
2 #define _IPXE_ETHERNET_H
3
4 /** @file
5  *
6  * Ethernet protocol
7  *
8  */
9
10 FILE_LICENCE ( GPL2_OR_LATER );
11
12 #include <stdint.h>
13 #include <ipxe/netdevice.h>
14 #include <ipxe/iobuf.h>
15
16 /**
17  * Check if Ethernet address is all zeroes
18  *
19  * @v addr              Ethernet address
20  * @ret is_zero         Address is all zeroes
21  */
22 static inline int is_zero_ether_addr ( const void *addr ) {
23         const uint8_t *addr_bytes = addr;
24
25         return ( ! ( addr_bytes[0] | addr_bytes[1] | addr_bytes[2] |
26                      addr_bytes[3] | addr_bytes[4] | addr_bytes[5] ) );
27 }
28
29 /**
30  * Check if Ethernet address is a multicast address
31  *
32  * @v addr              Ethernet address
33  * @ret is_mcast        Address is a multicast address
34  *
35  * Note that the broadcast address is also a multicast address.
36  */
37 static inline int is_multicast_ether_addr ( const void *addr ) {
38         const uint8_t *addr_bytes = addr;
39
40         return ( addr_bytes[0] & 0x01 );
41 }
42
43 /**
44  * Check if Ethernet address is locally assigned
45  *
46  * @v addr              Ethernet address
47  * @ret is_local        Address is locally assigned
48  */
49 static inline int is_local_ether_addr ( const void *addr ) {
50         const uint8_t *addr_bytes = addr;
51
52         return ( addr_bytes[0] & 0x02 );
53 }
54
55 /**
56  * Check if Ethernet address is the broadcast address
57  *
58  * @v addr              Ethernet address
59  * @ret is_bcast        Address is the broadcast address
60  */
61 static inline int is_broadcast_ether_addr ( const void *addr ) {
62         const uint8_t *addr_bytes = addr;
63
64         return ( ( addr_bytes[0] & addr_bytes[1] & addr_bytes[2] &
65                    addr_bytes[3] & addr_bytes[4] & addr_bytes[5] ) == 0xff );
66 }
67
68 /**
69  * Check if Ethernet address is valid
70  *
71  * @v addr              Ethernet address
72  * @ret is_valid        Address is valid
73  *
74  * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is
75  * not a multicast address, and is not ff:ff:ff:ff:ff:ff.
76  */
77 static inline int is_valid_ether_addr ( const void *addr ) {
78         return ( ( ! is_multicast_ether_addr ( addr ) ) &&
79                  ( ! is_zero_ether_addr ( addr ) ) );
80 }
81
82 extern uint8_t eth_broadcast[];
83 extern struct ll_protocol ethernet_protocol __ll_protocol;
84
85 extern int eth_push ( struct net_device *netdev, struct io_buffer *iobuf,
86                       const void *ll_dest, const void *ll_source,
87                       uint16_t net_proto );
88 extern int eth_pull ( struct net_device *netdev, struct io_buffer *iobuf,
89                       const void **ll_dest, const void **ll_source,
90                       uint16_t *net_proto, unsigned int *flags );
91 extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
92 extern void eth_random_addr ( void *hw_addr );
93 extern const char * eth_ntoa ( const void *ll_addr );
94 extern int eth_mc_hash ( unsigned int af, const void *net_addr,
95                          void *ll_addr );
96 extern int eth_eth_addr ( const void *ll_addr, void *eth_addr );
97 extern int eth_eui64 ( const void *ll_addr, void *eui64 );
98 extern struct net_device * alloc_etherdev ( size_t priv_size );
99
100 #endif /* _IPXE_ETHERNET_H */