zephyr/include/net/ethernet.h
Jukka Rissanen 85a2459edb net: Support network packet checksum calc offloading
Create infrastructure that allows ethernet device driver to tell
if it supports network packet checksum offloading. This applies only
to IPv4, UDP or TCP checksums. The driver can enable/disable checksum
offloading separately for Tx and Rx network packets.

If the device (ethernet in this case) can calculate the network
packet checksum for IPv4, UDP or TCP, then do not calculate the
corresponding checksum by the stack itself.

Fixes #2987

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-23 08:37:01 +02:00

145 lines
2.7 KiB
C

/** @file
@brief Ethernet
This is not to be included by the application.
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __ETHERNET_H
#define __ETHERNET_H
#include <zephyr/types.h>
#include <stdbool.h>
#include <net/net_ip.h>
#include <net/net_pkt.h>
#include <misc/util.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Ethernet support functions
* @defgroup ethernet Ethernet Support Functions
* @ingroup networking
* @{
*/
#define NET_ETH_HDR(pkt) ((struct net_eth_hdr *)net_pkt_ll(pkt))
#define NET_ETH_PTYPE_ARP 0x0806
#define NET_ETH_PTYPE_IP 0x0800
#define NET_ETH_PTYPE_IPV6 0x86dd
#define NET_ETH_MINIMAL_FRAME_SIZE 60
enum eth_hw_caps {
/** TX Checksum offloading supported */
ETH_HW_TX_CHKSUM_OFFLOAD = BIT(0),
/** RX Checksum offloading supported */
ETH_HW_RX_CHKSUM_OFFLOAD = BIT(1),
};
struct ethernet_api {
/**
* The net_if_api must be placed in first position in this
* struct so that we are compatible with network interface API.
*/
struct net_if_api iface_api;
/** Get the device capabilities */
enum eth_hw_caps (*get_capabilities)(struct device *dev);
} __packed;
struct net_eth_addr {
u8_t addr[6];
};
struct net_eth_hdr {
struct net_eth_addr dst;
struct net_eth_addr src;
u16_t type;
} __packed;
static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
{
if (addr->addr[0] == 0xff &&
addr->addr[1] == 0xff &&
addr->addr[2] == 0xff &&
addr->addr[3] == 0xff &&
addr->addr[4] == 0xff &&
addr->addr[5] == 0xff) {
return true;
}
return false;
}
static inline bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
{
#if defined(CONFIG_NET_IPV6)
if (addr->addr[0] == 0x33 &&
addr->addr[1] == 0x33) {
return true;
}
#endif
#if defined(CONFIG_NET_IPV4)
if (addr->addr[0] == 0x01 &&
addr->addr[1] == 0x00 &&
addr->addr[2] == 0x5e) {
return true;
}
#endif
return false;
}
const struct net_eth_addr *net_eth_broadcast_addr(void);
/**
* @brief Convert IPv6 multicast address to Ethernet address.
*
* @param ipv6_addr IPv6 multicast address
* @param mac_addr Output buffer for Ethernet address
*/
void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr,
struct net_eth_addr *mac_addr);
/**
* @brief Return ethernet device hardware capability information.
*
* @param iface Network interface
*
* @return Hardware capabilities
*/
static inline
enum eth_hw_caps net_eth_get_hw_capabilities(struct net_if *iface)
{
const struct ethernet_api *eth =
net_if_get_device(iface)->driver_api;
if (!eth->get_capabilities) {
return 0;
}
return eth->get_capabilities(net_if_get_device(iface));
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* __ETHERNET_H */