diff options
Diffstat (limited to 'include/linux/etherdevice.h')
| -rw-r--r-- | include/linux/etherdevice.h | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 3d7a6687d247..ab68f785fd19 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h | |||
| @@ -48,8 +48,10 @@ extern int eth_validate_addr(struct net_device *dev); | |||
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | 50 | ||
| 51 | extern struct net_device *alloc_etherdev_mq(int sizeof_priv, unsigned int queue_count); | 51 | extern struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs, |
| 52 | unsigned int rxqs); | ||
| 52 | #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1) | 53 | #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1) |
| 54 | #define alloc_etherdev_mq(sizeof_priv, count) alloc_etherdev_mqs(sizeof_priv, count, count) | ||
| 53 | 55 | ||
| 54 | /** | 56 | /** |
| 55 | * is_zero_ether_addr - Determine if give Ethernet address is all zeros. | 57 | * is_zero_ether_addr - Determine if give Ethernet address is all zeros. |
| @@ -71,7 +73,7 @@ static inline int is_zero_ether_addr(const u8 *addr) | |||
| 71 | */ | 73 | */ |
| 72 | static inline int is_multicast_ether_addr(const u8 *addr) | 74 | static inline int is_multicast_ether_addr(const u8 *addr) |
| 73 | { | 75 | { |
| 74 | return (0x01 & addr[0]); | 76 | return 0x01 & addr[0]; |
| 75 | } | 77 | } |
| 76 | 78 | ||
| 77 | /** | 79 | /** |
| @@ -82,7 +84,7 @@ static inline int is_multicast_ether_addr(const u8 *addr) | |||
| 82 | */ | 84 | */ |
| 83 | static inline int is_local_ether_addr(const u8 *addr) | 85 | static inline int is_local_ether_addr(const u8 *addr) |
| 84 | { | 86 | { |
| 85 | return (0x02 & addr[0]); | 87 | return 0x02 & addr[0]; |
| 86 | } | 88 | } |
| 87 | 89 | ||
| 88 | /** | 90 | /** |
| @@ -97,6 +99,17 @@ static inline int is_broadcast_ether_addr(const u8 *addr) | |||
| 97 | } | 99 | } |
| 98 | 100 | ||
| 99 | /** | 101 | /** |
| 102 | * is_unicast_ether_addr - Determine if the Ethernet address is unicast | ||
| 103 | * @addr: Pointer to a six-byte array containing the Ethernet address | ||
| 104 | * | ||
| 105 | * Return true if the address is a unicast address. | ||
| 106 | */ | ||
| 107 | static inline int is_unicast_ether_addr(const u8 *addr) | ||
| 108 | { | ||
| 109 | return !is_multicast_ether_addr(addr); | ||
| 110 | } | ||
| 111 | |||
| 112 | /** | ||
| 100 | * is_valid_ether_addr - Determine if the given Ethernet address is valid | 113 | * is_valid_ether_addr - Determine if the given Ethernet address is valid |
| 101 | * @addr: Pointer to a six-byte array containing the Ethernet address | 114 | * @addr: Pointer to a six-byte array containing the Ethernet address |
| 102 | * | 115 | * |
| @@ -127,6 +140,20 @@ static inline void random_ether_addr(u8 *addr) | |||
| 127 | } | 140 | } |
| 128 | 141 | ||
| 129 | /** | 142 | /** |
| 143 | * dev_hw_addr_random - Create random MAC and set device flag | ||
| 144 | * @dev: pointer to net_device structure | ||
| 145 | * @hwaddr: Pointer to a six-byte array containing the Ethernet address | ||
| 146 | * | ||
| 147 | * Generate random MAC to be used by a device and set addr_assign_type | ||
| 148 | * so the state can be read by sysfs and be used by udev. | ||
| 149 | */ | ||
| 150 | static inline void dev_hw_addr_random(struct net_device *dev, u8 *hwaddr) | ||
| 151 | { | ||
| 152 | dev->addr_assign_type |= NET_ADDR_RANDOM; | ||
| 153 | random_ether_addr(hwaddr); | ||
| 154 | } | ||
| 155 | |||
| 156 | /** | ||
| 130 | * compare_ether_addr - Compare two Ethernet addresses | 157 | * compare_ether_addr - Compare two Ethernet addresses |
| 131 | * @addr1: Pointer to a six-byte array containing the Ethernet address | 158 | * @addr1: Pointer to a six-byte array containing the Ethernet address |
| 132 | * @addr2: Pointer other six-byte array containing the Ethernet address | 159 | * @addr2: Pointer other six-byte array containing the Ethernet address |
| @@ -223,13 +250,29 @@ static inline bool is_etherdev_addr(const struct net_device *dev, | |||
| 223 | * entry points. | 250 | * entry points. |
| 224 | */ | 251 | */ |
| 225 | 252 | ||
| 226 | static inline int compare_ether_header(const void *a, const void *b) | 253 | static inline unsigned long compare_ether_header(const void *a, const void *b) |
| 227 | { | 254 | { |
| 255 | #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 | ||
| 256 | unsigned long fold; | ||
| 257 | |||
| 258 | /* | ||
| 259 | * We want to compare 14 bytes: | ||
| 260 | * [a0 ... a13] ^ [b0 ... b13] | ||
| 261 | * Use two long XOR, ORed together, with an overlap of two bytes. | ||
| 262 | * [a0 a1 a2 a3 a4 a5 a6 a7 ] ^ [b0 b1 b2 b3 b4 b5 b6 b7 ] | | ||
| 263 | * [a6 a7 a8 a9 a10 a11 a12 a13] ^ [b6 b7 b8 b9 b10 b11 b12 b13] | ||
| 264 | * This means the [a6 a7] ^ [b6 b7] part is done two times. | ||
| 265 | */ | ||
| 266 | fold = *(unsigned long *)a ^ *(unsigned long *)b; | ||
| 267 | fold |= *(unsigned long *)(a + 6) ^ *(unsigned long *)(b + 6); | ||
| 268 | return fold; | ||
| 269 | #else | ||
| 228 | u32 *a32 = (u32 *)((u8 *)a + 2); | 270 | u32 *a32 = (u32 *)((u8 *)a + 2); |
| 229 | u32 *b32 = (u32 *)((u8 *)b + 2); | 271 | u32 *b32 = (u32 *)((u8 *)b + 2); |
| 230 | 272 | ||
| 231 | return (*(u16 *)a ^ *(u16 *)b) | (a32[0] ^ b32[0]) | | 273 | return (*(u16 *)a ^ *(u16 *)b) | (a32[0] ^ b32[0]) | |
| 232 | (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]); | 274 | (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]); |
| 275 | #endif | ||
| 233 | } | 276 | } |
| 234 | 277 | ||
| 235 | #endif /* _LINUX_ETHERDEVICE_H */ | 278 | #endif /* _LINUX_ETHERDEVICE_H */ |
