Lines Matching +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()
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
245 * @haddr: new hardware address
247 * Called by Address Resolution module to notify changes in address.
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
273 * @p: socket address
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
290 * @p: socket address
296 eth_hw_addr_set(dev, addr->sa_data); in eth_commit_mac_addr_change()
301 * eth_mac_addr - set new Ethernet hardware address
303 * @p: socket address
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
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
371 * Fill in the fields of the device structure with Ethernet-generic
375 * size (sizeof_priv). A 32-byte (not bit) alignment is enforced for
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()
492 ret = of_get_mac_address(dev->of_node, mac_addr); in eth_platform_get_mac_address()
498 return -ENODEV; in eth_platform_get_mac_address()
507 * platform_get_ethdev_address - Set netdev's MAC address from a given device
509 * @netdev: Pointer to netdev to write the address to
511 * Wrapper around eth_platform_get_mac_address() which writes the address
512 * directly to netdev->dev_addr.
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.
531 * @addrbuf: Buffer to which the MAC address will be copied on success.
538 const void *mac; in nvmem_get_mac_address() local
541 cell = nvmem_cell_get(dev, "mac-address"); in nvmem_get_mac_address()
545 mac = nvmem_cell_read(cell, &len); in nvmem_get_mac_address()
548 if (IS_ERR(mac)) in nvmem_get_mac_address()
549 return PTR_ERR(mac); in nvmem_get_mac_address()
551 if (len != ETH_ALEN || !is_valid_ether_addr(mac)) { in nvmem_get_mac_address()
552 kfree(mac); in nvmem_get_mac_address()
553 return -EINVAL; in nvmem_get_mac_address()
556 ether_addr_copy(addrbuf, mac); in nvmem_get_mac_address()
557 kfree(mac); in nvmem_get_mac_address()
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
582 * checked first, because that is supposed to contain to "most recent" MAC
583 * address. If that isn't set, then 'local-mac-address' is checked next,
584 * because that is the default address. If that isn't set, then the obsolete
585 * 'address' is checked, just in case we're using an old device tree.
587 * Note that the 'address' property is supposed to contain a virtual address of
589 * MAC address.
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'
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
612 * @addr: Address of buffer to store the MAC in
621 * device_get_ethdev_address - Set netdev's MAC address from a given device
623 * @netdev: Pointer to netdev to write the address to
625 * Wrapper around device_get_mac_address() which writes the address
626 * directly to netdev->dev_addr.