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);
88 eth->h_proto = htons(len);
91 * Set the source hardware address.
95 saddr = dev->dev_addr;
96 memcpy(eth->h_source, saddr, ETH_ALEN);
99 memcpy(eth->h_dest, daddr, ETH_ALEN);
104 * Anyway, the loopback-device should never use this function...
107 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
108 eth_zero_addr(eth->h_dest);
112 return -ETH_HLEN;
117 * eth_get_headlen - determine the length of header for an ethernet frame
137 eth->h_proto, sizeof(*eth),
147 * eth_type_trans - determine the packet's protocol ID.
161 skb->dev = dev;
171 * and if so, set skb->protocol without looking at the packet.
176 if (likely(eth_proto_is_802_3(eth->h_proto)))
177 return eth->h_proto;
197 * eth_header_parse - extract hardware address from packet
204 memcpy(haddr, eth->h_source, ETH_ALEN);
210 * eth_header_cache - fill cache entry from neighbour
220 const struct net_device *dev = neigh->dev;
223 (((u8 *) hh->hh_data) + (HH_DATA_OFF(sizeof(*eth))));
226 return -1;
228 eth->h_proto = type;
229 memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
230 memcpy(eth->h_dest, neigh->ha, ETH_ALEN);
235 smp_store_release(&hh->hh_len, ETH_HLEN);
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)),
259 * eth_header_parse_protocol - extract protocol from L2 header
266 return eth->h_proto;
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))
280 return -EBUSY;
281 if (!is_valid_ether_addr(addr->sa_data))
282 return -EADDRNOTAVAIL;
288 * eth_commit_mac_addr_change - commit mac change
290 * @p: socket address
296 eth_hw_addr_set(dev, addr->sa_data);
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))
325 return -EADDRNOTAVAIL;
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;
348 dev->type = ARPHRD_ETHER;
349 dev->hard_header_len = ETH_HLEN;
350 dev->min_header_len = ETH_HLEN;
351 dev->mtu = ETH_DATA_LEN;
352 dev->min_mtu = ETH_MIN_MTU;
353 dev->max_mtu = ETH_DATA_LEN;
354 dev->addr_len = ETH_ALEN;
355 dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
356 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
357 dev->priv_flags |= IFF_TX_SKB_SHARING;
359 eth_broadcast_addr(dev->broadcast);
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)
415 eh2 = (struct ethhdr *)(p->data + off_eth);
417 NAPI_GRO_CB(p)->same_flow = 0;
422 type = eh->h_proto;
433 pp = indirect_call_gro_receive_inet(ptype->callbacks.gro_receive,
446 struct ethhdr *eh = (struct ethhdr *)(skb->data + nhoff);
447 __be16 type = eh->h_proto;
449 int err = -ENOSYS;
451 if (skb->encapsulation)
456 err = INDIRECT_CALL_INET(ptype->callbacks.gro_complete,
492 ret = of_get_mac_address(dev->of_node, mac_addr);
498 return -ENODEV;
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;
541 cell = nvmem_cell_get(dev, "mac-address");
545 mac = nvmem_cell_read(cell, &len);
548 if (IS_ERR(mac))
549 return PTR_ERR(mac);
551 if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
552 kfree(mac);
553 return -EINVAL;
556 ether_addr_copy(addrbuf, mac);
557 kfree(mac);
572 return -EINVAL;
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) ||
601 !fwnode_get_mac_addr(fwnode, "local-mac-address", addr) ||
602 !fwnode_get_mac_addr(fwnode, "address", addr))
605 return -ENOENT;
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.