Lines Matching +full:device +full:- +full:addr
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Ethernet-type device handling.
14 * Florian La Roche, <rzsfl@rz.uni-sb.de>
34 * Andrew Morton : 26Feb01: kill ether_setup() - use netdev_boot_setup().
46 #include <linux/nvmem-consumer.h>
67 * eth_header - create the Ethernet header
69 * @dev: source device
72 * @saddr: source address (NULL use device source address)
73 * @len: packet length (<= skb->len)
86 eth->h_proto = htons(type); in eth_header()
88 eth->h_proto = htons(len); in eth_header()
95 saddr = dev->dev_addr; in eth_header()
96 memcpy(eth->h_source, saddr, ETH_ALEN); in eth_header()
99 memcpy(eth->h_dest, daddr, ETH_ALEN); in eth_header()
104 * Anyway, the loopback-device should never use this function... in eth_header()
107 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) { in eth_header()
108 eth_zero_addr(eth->h_dest); in eth_header()
112 return -ETH_HLEN; in eth_header()
117 * eth_get_headlen - determine the length of header for an ethernet frame
118 * @dev: pointer to network device
137 eth->h_proto, sizeof(*eth), in eth_get_headlen()
147 * eth_type_trans - determine the packet's protocol ID.
149 * @dev: receiving network device
161 skb->dev = dev; in eth_type_trans()
171 * and if so, set skb->protocol without looking at the packet. in eth_type_trans()
176 if (likely(eth_proto_is_802_3(eth->h_proto))) in eth_type_trans()
177 return eth->h_proto; in eth_type_trans()
197 * eth_header_parse - extract hardware address from packet
204 memcpy(haddr, eth->h_source, ETH_ALEN); in eth_header_parse()
210 * eth_header_cache - fill cache entry from neighbour
220 const struct net_device *dev = neigh->dev; in eth_header_cache()
223 (((u8 *) hh->hh_data) + (HH_DATA_OFF(sizeof(*eth)))); in eth_header_cache()
226 return -1; in eth_header_cache()
228 eth->h_proto = type; in eth_header_cache()
229 memcpy(eth->h_source, dev->dev_addr, ETH_ALEN); in eth_header_cache()
230 memcpy(eth->h_dest, neigh->ha, ETH_ALEN); in eth_header_cache()
235 smp_store_release(&hh->hh_len, ETH_HLEN); in eth_header_cache()
242 * eth_header_cache_update - update cache entry
244 * @dev: network device
253 memcpy(((u8 *) hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)), in eth_header_cache_update()
259 * eth_header_parse_protocol - extract protocol from L2 header
266 return eth->h_proto; in eth_header_parse_protocol()
271 * eth_prepare_mac_addr_change - prepare for mac change
272 * @dev: network device
277 struct sockaddr *addr = p; in eth_prepare_mac_addr_change() local
279 if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev)) in eth_prepare_mac_addr_change()
280 return -EBUSY; in eth_prepare_mac_addr_change()
281 if (!is_valid_ether_addr(addr->sa_data)) in eth_prepare_mac_addr_change()
282 return -EADDRNOTAVAIL; in eth_prepare_mac_addr_change()
288 * eth_commit_mac_addr_change - commit mac change
289 * @dev: network device
294 struct sockaddr *addr = p; in eth_commit_mac_addr_change() local
296 eth_hw_addr_set(dev, addr->sa_data); in eth_commit_mac_addr_change()
301 * eth_mac_addr - set new Ethernet hardware address
302 * @dev: network device
305 * Change hardware address of device.
324 if (!is_valid_ether_addr(dev->dev_addr)) in eth_validate_addr()
325 return -EADDRNOTAVAIL; in eth_validate_addr()
340 * ether_setup - setup Ethernet network device
341 * @dev: network device
343 * Fill in the fields of the device structure with Ethernet-generic values.
347 dev->header_ops = ð_header_ops; in ether_setup()
348 dev->type = ARPHRD_ETHER; in ether_setup()
349 dev->hard_header_len = ETH_HLEN; in ether_setup()
350 dev->min_header_len = ETH_HLEN; in ether_setup()
351 dev->mtu = ETH_DATA_LEN; in ether_setup()
352 dev->min_mtu = ETH_MIN_MTU; in ether_setup()
353 dev->max_mtu = ETH_DATA_LEN; in ether_setup()
354 dev->addr_len = ETH_ALEN; in ether_setup()
355 dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN; in ether_setup()
356 dev->flags = IFF_BROADCAST|IFF_MULTICAST; in ether_setup()
357 dev->priv_flags |= IFF_TX_SKB_SHARING; in ether_setup()
359 eth_broadcast_addr(dev->broadcast); in ether_setup()
365 * alloc_etherdev_mqs - Allocates and sets up an Ethernet device
366 * @sizeof_priv: Size of additional driver-private structure to be allocated
367 * for this Ethernet device
368 * @txqs: The number of TX queues this device has.
369 * @rxqs: The number of RX queues this device has.
371 * Fill in the fields of the device structure with Ethernet-generic
372 * values. Basically does everything except registering the device.
374 * Constructs a new net device, complete with a private data area of
375 * size (sizeof_priv). A 32-byte (not bit) alignment is enforced for
387 ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len) in sysfs_format_mac() argument
389 return sysfs_emit(buf, "%*phC\n", len, addr); in sysfs_format_mac()
412 if (!NAPI_GRO_CB(p)->same_flow) in eth_gro_receive()
415 eh2 = (struct ethhdr *)(p->data + off_eth); in eth_gro_receive()
417 NAPI_GRO_CB(p)->same_flow = 0; in eth_gro_receive()
422 type = eh->h_proto; in eth_gro_receive()
433 pp = indirect_call_gro_receive_inet(ptype->callbacks.gro_receive, in eth_gro_receive()
446 struct ethhdr *eh = (struct ethhdr *)(skb->data + nhoff); in eth_gro_complete()
447 __be16 type = eh->h_proto; in eth_gro_complete()
449 int err = -ENOSYS; in eth_gro_complete()
451 if (skb->encapsulation) in eth_gro_complete()
456 err = INDIRECT_CALL_INET(ptype->callbacks.gro_complete, in eth_gro_complete()
487 int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) in eth_platform_get_mac_address()
489 unsigned char *addr; in eth_platform_get_mac_address() local
492 ret = of_get_mac_address(dev->of_node, mac_addr); in eth_platform_get_mac_address()
496 addr = arch_get_platform_mac_address(); in eth_platform_get_mac_address()
497 if (!addr) in eth_platform_get_mac_address()
498 return -ENODEV; in eth_platform_get_mac_address()
500 ether_addr_copy(mac_addr, addr); in eth_platform_get_mac_address()
507 * platform_get_ethdev_address - Set netdev's MAC address from a given device
508 * @dev: Pointer to the device
512 * directly to netdev->dev_addr.
514 int platform_get_ethdev_address(struct device *dev, struct net_device *netdev) in platform_get_ethdev_address()
516 u8 addr[ETH_ALEN] __aligned(2); in platform_get_ethdev_address() local
519 ret = eth_platform_get_mac_address(dev, addr); in platform_get_ethdev_address()
521 eth_hw_addr_set(netdev, addr); in platform_get_ethdev_address()
527 * nvmem_get_mac_address - Obtain the MAC address from an nvmem cell named
528 * 'mac-address' associated with given device.
530 * @dev: Device with which the mac-address cell is associated.
535 int nvmem_get_mac_address(struct device *dev, void *addrbuf) in nvmem_get_mac_address()
541 cell = nvmem_cell_get(dev, "mac-address"); in nvmem_get_mac_address()
553 return -EINVAL; in nvmem_get_mac_address()
563 const char *name, char *addr) in fwnode_get_mac_addr() argument
567 ret = fwnode_property_read_u8_array(fwnode, name, addr, ETH_ALEN); in fwnode_get_mac_addr()
571 if (!is_valid_ether_addr(addr)) in fwnode_get_mac_addr()
572 return -EINVAL; in fwnode_get_mac_addr()
577 * fwnode_get_mac_address - Get the MAC from the firmware node
579 * @addr: Address of buffer to store the MAC in
581 * Search the firmware node for the best MAC address to use. 'mac-address' is
583 * address. If that isn't set, then 'local-mac-address' is checked next,
585 * 'address' is checked, just in case we're using an old device tree.
591 * All-zero MAC addresses are rejected, because those could be properties that
593 * example, the DTS could define 'mac-address' and 'local-mac-address', with
594 * zero MAC addresses. Some older U-Boots only initialized 'local-mac-address'.
595 * In this case, the real MAC is in 'local-mac-address', and 'mac-address'
598 int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr) in fwnode_get_mac_address() argument
600 if (!fwnode_get_mac_addr(fwnode, "mac-address", addr) || in fwnode_get_mac_address()
601 !fwnode_get_mac_addr(fwnode, "local-mac-address", addr) || in fwnode_get_mac_address()
602 !fwnode_get_mac_addr(fwnode, "address", addr)) in fwnode_get_mac_address()
605 return -ENOENT; in fwnode_get_mac_address()
610 * device_get_mac_address - Get the MAC for a given device
611 * @dev: Pointer to the device
612 * @addr: Address of buffer to store the MAC in
614 int device_get_mac_address(struct device *dev, char *addr) in device_get_mac_address() argument
616 return fwnode_get_mac_address(dev_fwnode(dev), addr); in device_get_mac_address()
621 * device_get_ethdev_address - Set netdev's MAC address from a given device
622 * @dev: Pointer to the device
626 * directly to netdev->dev_addr.
628 int device_get_ethdev_address(struct device *dev, struct net_device *netdev) in device_get_ethdev_address()
630 u8 addr[ETH_ALEN]; in device_get_ethdev_address() local
633 ret = device_get_mac_address(dev, addr); in device_get_ethdev_address()
635 eth_hw_addr_set(netdev, addr); in device_get_ethdev_address()