Lines Matching +full:local +full:- +full:mac +full:- +full:address
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Ethernet-type device handling.
14 * Florian La Roche, <rzsfl@rz.uni-sb.de>
29 * Alan Cox : MAC layer pointers/new format.
34 * Andrew Morton : 26Feb01: kill ether_setup() - use netdev_boot_setup().
46 #include <linux/nvmem-consumer.h>
67 * eth_header - create the Ethernet header
71 * @daddr: destination address (NULL leave destination address)
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()
91 * Set the source hardware address. 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
137 eth->h_proto, sizeof(*eth), in eth_get_headlen()
147 * eth_type_trans - determine the packet's protocol ID.
161 skb->dev = dev; in eth_type_trans()
164 eth = (struct ethhdr *)skb->data; in eth_type_trans()
167 if (unlikely(!ether_addr_equal_64bits(eth->h_dest, in eth_type_trans()
168 dev->dev_addr))) { in eth_type_trans()
169 if (unlikely(is_multicast_ether_addr_64bits(eth->h_dest))) { in eth_type_trans()
170 if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast)) in eth_type_trans()
171 skb->pkt_type = PACKET_BROADCAST; in eth_type_trans()
173 skb->pkt_type = PACKET_MULTICAST; in eth_type_trans()
175 skb->pkt_type = PACKET_OTHERHOST; in eth_type_trans()
183 * and if so, set skb->protocol without looking at the packet. in eth_type_trans()
188 if (likely(eth_proto_is_802_3(eth->h_proto))) in eth_type_trans()
189 return eth->h_proto; in eth_type_trans()
209 * eth_header_parse - extract hardware address from packet
216 memcpy(haddr, eth->h_source, ETH_ALEN); in eth_header_parse()
222 * eth_header_cache - fill cache entry from neighbour
232 const struct net_device *dev = neigh->dev; in eth_header_cache()
235 (((u8 *) hh->hh_data) + (HH_DATA_OFF(sizeof(*eth)))); in eth_header_cache()
238 return -1; in eth_header_cache()
240 eth->h_proto = type; in eth_header_cache()
241 memcpy(eth->h_source, dev->dev_addr, ETH_ALEN); in eth_header_cache()
242 memcpy(eth->h_dest, neigh->ha, ETH_ALEN); in eth_header_cache()
247 smp_store_release(&hh->hh_len, ETH_HLEN); in eth_header_cache()
254 * eth_header_cache_update - update cache entry
257 * @haddr: new hardware address
259 * Called by Address Resolution module to notify changes in address.
265 memcpy(((u8 *) hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)), in eth_header_cache_update()
271 * eth_header_parse_protocol - extract protocol from L2 header
278 return eth->h_proto; in eth_header_parse_protocol()
283 * eth_prepare_mac_addr_change - prepare for mac change
285 * @p: socket address
291 if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev)) in eth_prepare_mac_addr_change()
292 return -EBUSY; in eth_prepare_mac_addr_change()
293 if (!is_valid_ether_addr(addr->sa_data)) in eth_prepare_mac_addr_change()
294 return -EADDRNOTAVAIL; in eth_prepare_mac_addr_change()
300 * eth_commit_mac_addr_change - commit mac change
302 * @p: socket address
308 eth_hw_addr_set(dev, addr->sa_data); in eth_commit_mac_addr_change()
313 * eth_mac_addr - set new Ethernet hardware address
315 * @p: socket address
317 * Change hardware address of device.
336 if (!is_valid_ether_addr(dev->dev_addr)) in eth_validate_addr()
337 return -EADDRNOTAVAIL; in eth_validate_addr()
352 * ether_setup - setup Ethernet network device
355 * Fill in the fields of the device structure with Ethernet-generic values.
359 dev->header_ops = ð_header_ops; in ether_setup()
360 dev->type = ARPHRD_ETHER; in ether_setup()
361 dev->hard_header_len = ETH_HLEN; in ether_setup()
362 dev->min_header_len = ETH_HLEN; in ether_setup()
363 dev->mtu = ETH_DATA_LEN; in ether_setup()
364 dev->min_mtu = ETH_MIN_MTU; in ether_setup()
365 dev->max_mtu = ETH_DATA_LEN; in ether_setup()
366 dev->addr_len = ETH_ALEN; in ether_setup()
367 dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN; in ether_setup()
368 dev->flags = IFF_BROADCAST|IFF_MULTICAST; in ether_setup()
369 dev->priv_flags |= IFF_TX_SKB_SHARING; in ether_setup()
371 eth_broadcast_addr(dev->broadcast); in ether_setup()
377 * alloc_etherdev_mqs - Allocates and sets up an Ethernet device
378 * @sizeof_priv: Size of additional driver-private structure to be allocated
383 * Fill in the fields of the device structure with Ethernet-generic
387 * size (sizeof_priv). A 32-byte (not bit) alignment is enforced for
424 if (!NAPI_GRO_CB(p)->same_flow) in eth_gro_receive()
427 eh2 = (struct ethhdr *)(p->data + off_eth); in eth_gro_receive()
429 NAPI_GRO_CB(p)->same_flow = 0; in eth_gro_receive()
434 type = eh->h_proto; in eth_gro_receive()
445 pp = indirect_call_gro_receive_inet(ptype->callbacks.gro_receive, in eth_gro_receive()
458 struct ethhdr *eh = (struct ethhdr *)(skb->data + nhoff); in eth_gro_complete()
459 __be16 type = eh->h_proto; in eth_gro_complete()
461 int err = -ENOSYS; in eth_gro_complete()
463 if (skb->encapsulation) in eth_gro_complete()
468 err = INDIRECT_CALL_INET(ptype->callbacks.gro_complete, in eth_gro_complete()
504 ret = of_get_mac_address(dev->of_node, mac_addr); in eth_platform_get_mac_address()
510 return -ENODEV; in eth_platform_get_mac_address()
519 * platform_get_ethdev_address - Set netdev's MAC address from a given device
521 * @netdev: Pointer to netdev to write the address to
523 * Wrapper around eth_platform_get_mac_address() which writes the address
524 * directly to netdev->dev_addr.
539 * nvmem_get_mac_address - Obtain the MAC address from an nvmem cell named
540 * 'mac-address' associated with given device.
542 * @dev: Device with which the mac-address cell is associated.
543 * @addrbuf: Buffer to which the MAC address will be copied on success.
550 const void *mac; in nvmem_get_mac_address() local
553 cell = nvmem_cell_get(dev, "mac-address"); in nvmem_get_mac_address()
557 mac = nvmem_cell_read(cell, &len); in nvmem_get_mac_address()
560 if (IS_ERR(mac)) in nvmem_get_mac_address()
561 return PTR_ERR(mac); in nvmem_get_mac_address()
563 if (len != ETH_ALEN || !is_valid_ether_addr(mac)) { in nvmem_get_mac_address()
564 kfree(mac); in nvmem_get_mac_address()
565 return -EINVAL; in nvmem_get_mac_address()
568 ether_addr_copy(addrbuf, mac); in nvmem_get_mac_address()
569 kfree(mac); in nvmem_get_mac_address()
584 return -EINVAL; in fwnode_get_mac_addr()
589 * fwnode_get_mac_address - Get the MAC from the firmware node
591 * @addr: Address of buffer to store the MAC in
593 * Search the firmware node for the best MAC address to use. 'mac-address' is
594 * checked first, because that is supposed to contain to "most recent" MAC
595 * address. If that isn't set, then 'local-mac-address' is checked next,
596 * because that is the default address. If that isn't set, then the obsolete
597 * 'address' is checked, just in case we're using an old device tree.
599 * Note that the 'address' property is supposed to contain a virtual address of
601 * MAC address.
603 * All-zero MAC addresses are rejected, because those could be properties that
605 * example, the DTS could define 'mac-address' and 'local-mac-address', with
606 * zero MAC addresses. Some older U-Boots only initialized 'local-mac-address'.
607 * In this case, the real MAC is in 'local-mac-address', and 'mac-address'
612 if (!fwnode_get_mac_addr(fwnode, "mac-address", addr) || in fwnode_get_mac_address()
613 !fwnode_get_mac_addr(fwnode, "local-mac-address", addr) || in fwnode_get_mac_address()
614 !fwnode_get_mac_addr(fwnode, "address", addr)) in fwnode_get_mac_address()
617 return -ENOENT; in fwnode_get_mac_address()
622 * device_get_mac_address - Get the MAC for a given device
624 * @addr: Address of buffer to store the MAC in
633 * device_get_ethdev_address - Set netdev's MAC address from a given device
635 * @netdev: Pointer to netdev to write the address to
637 * Wrapper around device_get_mac_address() which writes the address
638 * directly to netdev->dev_addr.