| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * INET An implementation of the TCP/IP protocol suite for the LINUX |
|---|
| 3 | 4 | * operating system. NET is implemented using the BSD Socket |
|---|
| .. | .. |
|---|
| 12 | 13 | * |
|---|
| 13 | 14 | * Relocated to include/linux where it belongs by Alan Cox |
|---|
| 14 | 15 | * <gw4pts@gw4pts.ampr.org> |
|---|
| 15 | | - * |
|---|
| 16 | | - * This program is free software; you can redistribute it and/or |
|---|
| 17 | | - * modify it under the terms of the GNU General Public License |
|---|
| 18 | | - * as published by the Free Software Foundation; either version |
|---|
| 19 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 20 | | - * |
|---|
| 21 | 16 | */ |
|---|
| 22 | 17 | #ifndef _LINUX_ETHERDEVICE_H |
|---|
| 23 | 18 | #define _LINUX_ETHERDEVICE_H |
|---|
| .. | .. |
|---|
| 25 | 20 | #include <linux/if_ether.h> |
|---|
| 26 | 21 | #include <linux/netdevice.h> |
|---|
| 27 | 22 | #include <linux/random.h> |
|---|
| 23 | +#include <linux/crc32.h> |
|---|
| 28 | 24 | #include <asm/unaligned.h> |
|---|
| 29 | 25 | #include <asm/bitsperlong.h> |
|---|
| 30 | 26 | |
|---|
| .. | .. |
|---|
| 32 | 28 | struct device; |
|---|
| 33 | 29 | int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr); |
|---|
| 34 | 30 | unsigned char *arch_get_platform_mac_address(void); |
|---|
| 35 | | -u32 eth_get_headlen(void *data, unsigned int max_len); |
|---|
| 31 | +int nvmem_get_mac_address(struct device *dev, void *addrbuf); |
|---|
| 32 | +u32 eth_get_headlen(const struct net_device *dev, void *data, unsigned int len); |
|---|
| 36 | 33 | __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev); |
|---|
| 37 | 34 | extern const struct header_ops eth_header_ops; |
|---|
| 38 | 35 | |
|---|
| .. | .. |
|---|
| 43 | 40 | __be16 type); |
|---|
| 44 | 41 | void eth_header_cache_update(struct hh_cache *hh, const struct net_device *dev, |
|---|
| 45 | 42 | const unsigned char *haddr); |
|---|
| 43 | +__be16 eth_header_parse_protocol(const struct sk_buff *skb); |
|---|
| 46 | 44 | int eth_prepare_mac_addr_change(struct net_device *dev, void *p); |
|---|
| 47 | 45 | void eth_commit_mac_addr_change(struct net_device *dev, void *p); |
|---|
| 48 | 46 | int eth_mac_addr(struct net_device *dev, void *p); |
|---|
| 49 | | -int eth_change_mtu(struct net_device *dev, int new_mtu); |
|---|
| 50 | 47 | int eth_validate_addr(struct net_device *dev); |
|---|
| 51 | 48 | |
|---|
| 52 | 49 | struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs, |
|---|
| .. | .. |
|---|
| 130 | 127 | #endif |
|---|
| 131 | 128 | } |
|---|
| 132 | 129 | |
|---|
| 133 | | -static inline bool is_multicast_ether_addr_64bits(const u8 addr[6+2]) |
|---|
| 130 | +static inline bool is_multicast_ether_addr_64bits(const u8 *addr) |
|---|
| 134 | 131 | { |
|---|
| 135 | 132 | #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 |
|---|
| 136 | 133 | #ifdef __BIG_ENDIAN |
|---|
| .. | .. |
|---|
| 270 | 267 | } |
|---|
| 271 | 268 | |
|---|
| 272 | 269 | /** |
|---|
| 270 | + * eth_hw_addr_crc - Calculate CRC from netdev_hw_addr |
|---|
| 271 | + * @ha: pointer to hardware address |
|---|
| 272 | + * |
|---|
| 273 | + * Calculate CRC from a hardware address as basis for filter hashes. |
|---|
| 274 | + */ |
|---|
| 275 | +static inline u32 eth_hw_addr_crc(struct netdev_hw_addr *ha) |
|---|
| 276 | +{ |
|---|
| 277 | + return ether_crc(ETH_ALEN, ha->addr); |
|---|
| 278 | +} |
|---|
| 279 | + |
|---|
| 280 | +/** |
|---|
| 273 | 281 | * ether_addr_copy - Copy an Ethernet address |
|---|
| 274 | 282 | * @dst: Pointer to a six-byte array Ethernet address destination |
|---|
| 275 | 283 | * @src: Pointer to a six-byte array Ethernet address source |
|---|
| .. | .. |
|---|
| 289 | 297 | a[1] = b[1]; |
|---|
| 290 | 298 | a[2] = b[2]; |
|---|
| 291 | 299 | #endif |
|---|
| 300 | +} |
|---|
| 301 | + |
|---|
| 302 | +/** |
|---|
| 303 | + * eth_hw_addr_set - Assign Ethernet address to a net_device |
|---|
| 304 | + * @dev: pointer to net_device structure |
|---|
| 305 | + * @addr: address to assign |
|---|
| 306 | + * |
|---|
| 307 | + * Assign given address to the net_device, addr_assign_type is not changed. |
|---|
| 308 | + */ |
|---|
| 309 | +static inline void eth_hw_addr_set(struct net_device *dev, const u8 *addr) |
|---|
| 310 | +{ |
|---|
| 311 | + ether_addr_copy(dev->dev_addr, addr); |
|---|
| 292 | 312 | } |
|---|
| 293 | 313 | |
|---|
| 294 | 314 | /** |
|---|
| .. | .. |
|---|
| 344 | 364 | * Please note that alignment of addr1 & addr2 are only guaranteed to be 16 bits. |
|---|
| 345 | 365 | */ |
|---|
| 346 | 366 | |
|---|
| 347 | | -static inline bool ether_addr_equal_64bits(const u8 addr1[6+2], |
|---|
| 348 | | - const u8 addr2[6+2]) |
|---|
| 367 | +static inline bool ether_addr_equal_64bits(const u8 *addr1, const u8 *addr2) |
|---|
| 349 | 368 | { |
|---|
| 350 | 369 | #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 |
|---|
| 351 | 370 | u64 fold = (*(const u64 *)addr1) ^ (*(const u64 *)addr2); |
|---|
| .. | .. |
|---|
| 447 | 466 | } |
|---|
| 448 | 467 | |
|---|
| 449 | 468 | /** |
|---|
| 469 | + * eth_addr_inc() - Increment the given MAC address. |
|---|
| 470 | + * @addr: Pointer to a six-byte array containing Ethernet address to increment. |
|---|
| 471 | + */ |
|---|
| 472 | +static inline void eth_addr_inc(u8 *addr) |
|---|
| 473 | +{ |
|---|
| 474 | + u64 u = ether_addr_to_u64(addr); |
|---|
| 475 | + |
|---|
| 476 | + u++; |
|---|
| 477 | + u64_to_ether_addr(u, addr); |
|---|
| 478 | +} |
|---|
| 479 | + |
|---|
| 480 | +/** |
|---|
| 450 | 481 | * is_etherdev_addr - Tell if given Ethernet address belongs to the device. |
|---|
| 451 | 482 | * @dev: Pointer to a device structure |
|---|
| 452 | 483 | * @addr: Pointer to a six-byte array containing the Ethernet address |
|---|