• Home
  • Raw
  • Download

Lines Matching +full:eth +full:- +full:mac

1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Ethernet-type device handling.
9 * Version: @(#)eth.c 1.0.7 05/25/93
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
73 * @len: packet length (<= skb->len)
83 struct ethhdr *eth = skb_push(skb, ETH_HLEN); in eth_header() local
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
128 const struct ethhdr *eth = (const struct ethhdr *)data; in eth_get_headlen() local
132 if (unlikely(len < sizeof(*eth))) in eth_get_headlen()
137 eth->h_proto, sizeof(*eth), in eth_get_headlen()
139 return max_t(u32, keys.control.thoff, sizeof(*eth)); in eth_get_headlen()
147 * eth_type_trans - determine the packet's protocol ID.
159 const struct ethhdr *eth; in eth_type_trans() local
161 skb->dev = dev; in eth_type_trans()
164 eth = (struct ethhdr *)skb->data; in eth_type_trans()
173 * and if so, set skb->protocol without looking at the packet. in eth_type_trans()
178 if (likely(eth_proto_is_802_3(eth->h_proto))) in eth_type_trans()
179 return eth->h_proto; in eth_type_trans()
199 * eth_header_parse - extract hardware address from packet
205 const struct ethhdr *eth = eth_hdr(skb); in eth_header_parse() local
206 memcpy(haddr, eth->h_source, ETH_ALEN); in eth_header_parse()
212 * eth_header_cache - fill cache entry from neighbour
221 struct ethhdr *eth; in eth_header_cache() local
222 const struct net_device *dev = neigh->dev; in eth_header_cache()
224 eth = (struct ethhdr *) in eth_header_cache()
225 (((u8 *) hh->hh_data) + (HH_DATA_OFF(sizeof(*eth)))); in eth_header_cache()
228 return -1; in eth_header_cache()
230 eth->h_proto = type; in eth_header_cache()
231 memcpy(eth->h_source, dev->dev_addr, ETH_ALEN); in eth_header_cache()
232 memcpy(eth->h_dest, neigh->ha, ETH_ALEN); in eth_header_cache()
237 smp_store_release(&hh->hh_len, ETH_HLEN); in eth_header_cache()
244 * eth_header_cache_update - update cache entry
255 memcpy(((u8 *) hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)), in eth_header_cache_update()
261 * eth_header_parse_protocol - extract protocol from L2 header
266 const struct ethhdr *eth = eth_hdr(skb); in eth_header_parse_protocol() local
268 return eth->h_proto; in eth_header_parse_protocol()
273 * eth_prepare_mac_addr_change - prepare for mac change
281 if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev)) in eth_prepare_mac_addr_change()
282 return -EBUSY; in eth_prepare_mac_addr_change()
283 if (!is_valid_ether_addr(addr->sa_data)) in eth_prepare_mac_addr_change()
284 return -EADDRNOTAVAIL; in eth_prepare_mac_addr_change()
290 * eth_commit_mac_addr_change - commit mac change
298 eth_hw_addr_set(dev, addr->sa_data); in eth_commit_mac_addr_change()
303 * eth_mac_addr - set new Ethernet hardware address
326 if (!is_valid_ether_addr(dev->dev_addr)) in eth_validate_addr()
327 return -EADDRNOTAVAIL; in eth_validate_addr()
342 * ether_setup - setup Ethernet network device
345 * Fill in the fields of the device structure with Ethernet-generic values.
349 dev->header_ops = &eth_header_ops; in ether_setup()
350 dev->type = ARPHRD_ETHER; in ether_setup()
351 dev->hard_header_len = ETH_HLEN; in ether_setup()
352 dev->min_header_len = ETH_HLEN; in ether_setup()
353 dev->mtu = ETH_DATA_LEN; in ether_setup()
354 dev->min_mtu = ETH_MIN_MTU; in ether_setup()
355 dev->max_mtu = ETH_DATA_LEN; in ether_setup()
356 dev->addr_len = ETH_ALEN; in ether_setup()
357 dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN; in ether_setup()
358 dev->flags = IFF_BROADCAST|IFF_MULTICAST; in ether_setup()
359 dev->priv_flags |= IFF_TX_SKB_SHARING; in ether_setup()
361 eth_broadcast_addr(dev->broadcast); in ether_setup()
367 * alloc_etherdev_mqs - Allocates and sets up an Ethernet device
368 * @sizeof_priv: Size of additional driver-private structure to be allocated
373 * Fill in the fields of the device structure with Ethernet-generic
377 * size (sizeof_priv). A 32-byte (not bit) alignment is enforced for
384 return alloc_netdev_mqs(sizeof_priv, "eth%d", NET_NAME_ENUM, in alloc_etherdev_mqs()
414 if (!NAPI_GRO_CB(p)->same_flow) in eth_gro_receive()
417 eh2 = (struct ethhdr *)(p->data + off_eth); in eth_gro_receive()
419 NAPI_GRO_CB(p)->same_flow = 0; in eth_gro_receive()
424 type = eh->h_proto; in eth_gro_receive()
435 pp = indirect_call_gro_receive_inet(ptype->callbacks.gro_receive, in eth_gro_receive()
448 struct ethhdr *eh = (struct ethhdr *)(skb->data + nhoff); in eth_gro_complete()
449 __be16 type = eh->h_proto; in eth_gro_complete()
451 int err = -ENOSYS; in eth_gro_complete()
453 if (skb->encapsulation) in eth_gro_complete()
458 err = INDIRECT_CALL_INET(ptype->callbacks.gro_complete, in eth_gro_complete()
494 ret = of_get_mac_address(dev->of_node, mac_addr); in eth_platform_get_mac_address()
500 return -ENODEV; in eth_platform_get_mac_address()
509 * platform_get_ethdev_address - Set netdev's MAC address from a given device
514 * directly to netdev->dev_addr.
529 * nvmem_get_mac_address - Obtain the MAC address from an nvmem cell named
530 * 'mac-address' associated with given device.
532 * @dev: Device with which the mac-address cell is associated.
533 * @addrbuf: Buffer to which the MAC address will be copied on success.
540 const void *mac; in nvmem_get_mac_address() local
543 cell = nvmem_cell_get(dev, "mac-address"); in nvmem_get_mac_address()
547 mac = nvmem_cell_read(cell, &len); in nvmem_get_mac_address()
550 if (IS_ERR(mac)) in nvmem_get_mac_address()
551 return PTR_ERR(mac); in nvmem_get_mac_address()
553 if (len != ETH_ALEN || !is_valid_ether_addr(mac)) { in nvmem_get_mac_address()
554 kfree(mac); in nvmem_get_mac_address()
555 return -EINVAL; in nvmem_get_mac_address()
558 ether_addr_copy(addrbuf, mac); in nvmem_get_mac_address()
559 kfree(mac); in nvmem_get_mac_address()
574 return -EINVAL; in fwnode_get_mac_addr()
579 * fwnode_get_mac_address - Get the MAC from the firmware node
581 * @addr: Address of buffer to store the MAC in
583 * Search the firmware node for the best MAC address to use. 'mac-address' is
584 * checked first, because that is supposed to contain to "most recent" MAC
585 * address. If that isn't set, then 'local-mac-address' is checked next,
591 * MAC address.
593 * All-zero MAC addresses are rejected, because those could be properties that
595 * example, the DTS could define 'mac-address' and 'local-mac-address', with
596 * zero MAC addresses. Some older U-Boots only initialized 'local-mac-address'.
597 * In this case, the real MAC is in 'local-mac-address', and 'mac-address'
602 if (!fwnode_get_mac_addr(fwnode, "mac-address", addr) || in fwnode_get_mac_address()
603 !fwnode_get_mac_addr(fwnode, "local-mac-address", addr) || in fwnode_get_mac_address()
607 return -ENOENT; in fwnode_get_mac_address()
612 * device_get_mac_address - Get the MAC for a given device
614 * @addr: Address of buffer to store the MAC in
623 * device_get_ethdev_address - Set netdev's MAC address from a given device
628 * directly to netdev->dev_addr.