net: ethernet: Define and use Ethernet frame and datagram size
Remove magic numbers from Ethernet drivers and tests by defining NET_ETH_MAX_DATAGRAM_SIZE and NET_ETH_MAX_FRAME_SIZE. Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
parent
652efa530f
commit
99403c5b13
22 changed files with 49 additions and 42 deletions
|
@ -388,5 +388,5 @@ NET_DEVICE_INIT(eth_dw_0, CONFIG_ETH_DW_0_NAME,
|
|||
eth_setup, ð_0_runtime,
|
||||
ð_config_0, CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2),
|
||||
ETH_DW_MTU);
|
||||
NET_ETH_MTU);
|
||||
#endif /* CONFIG_ETH_DW_0 */
|
||||
|
|
|
@ -142,8 +142,6 @@ struct eth_rx_desc {
|
|||
u8_t *buf2_ptr;
|
||||
};
|
||||
|
||||
#define ETH_DW_MTU 1500
|
||||
|
||||
/* Driver metadata associated with each Ethernet device */
|
||||
struct eth_runtime {
|
||||
u32_t base_addr;
|
||||
|
@ -156,7 +154,7 @@ struct eth_runtime {
|
|||
/* Receive descriptor */
|
||||
volatile struct eth_rx_desc rx_desc;
|
||||
/* Receive DMA packet buffer */
|
||||
volatile u8_t rx_buf[ETH_DW_MTU];
|
||||
volatile u8_t rx_buf[NET_ETH_MTU];
|
||||
|
||||
union {
|
||||
struct {
|
||||
|
|
|
@ -233,4 +233,4 @@ NET_DEVICE_INIT(eth_e1000,
|
|||
&e1000_api,
|
||||
ETHERNET_L2,
|
||||
NET_L2_GET_CTX_TYPE(ETHERNET_L2),
|
||||
E1000_MTU);
|
||||
NET_ETH_MTU);
|
||||
|
|
|
@ -30,8 +30,6 @@ extern "C" {
|
|||
#define RDESC_STA_DD (1) /* Descriptor Done */
|
||||
#define TDESC_STA_DD (1) /* Descriptor Done */
|
||||
|
||||
#define E1000_MTU 1500
|
||||
|
||||
#define ETH_ALEN 6 /* TODO: Add a global reusable definition in OS */
|
||||
|
||||
enum e1000_reg_t {
|
||||
|
@ -82,8 +80,8 @@ struct e1000_dev {
|
|||
struct pci_dev_info pci;
|
||||
struct net_if *iface;
|
||||
u8_t mac[ETH_ALEN];
|
||||
u8_t txb[E1000_MTU];
|
||||
u8_t rxb[E1000_MTU];
|
||||
u8_t txb[NET_ETH_MTU];
|
||||
u8_t rxb[NET_ETH_MTU];
|
||||
};
|
||||
|
||||
static const char *e1000_reg_to_string(enum e1000_reg_t r)
|
||||
|
|
|
@ -774,6 +774,7 @@ static const struct eth_enc28j60_config eth_enc28j60_0_config = {
|
|||
NET_DEVICE_INIT(enc28j60_0, DT_MICROCHIP_ENC28J60_0_LABEL,
|
||||
eth_enc28j60_init, ð_enc28j60_0_runtime,
|
||||
ð_enc28j60_0_config, CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2), 1500);
|
||||
ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2),
|
||||
NET_ETH_MTU);
|
||||
|
||||
#endif /* CONFIG_ETH_ENC28J60_0 */
|
||||
|
|
|
@ -102,7 +102,7 @@ struct eth_context {
|
|||
* Note that we do not copy FCS into this buffer thus the
|
||||
* size is 1514 bytes.
|
||||
*/
|
||||
u8_t frame_buf[1500 + 14]; /* Max MTU + ethernet header size */
|
||||
u8_t frame_buf[NET_ETH_MAX_FRAME_SIZE]; /* Max MTU + ethernet header */
|
||||
};
|
||||
|
||||
static void eth_0_config_func(void);
|
||||
|
@ -1012,7 +1012,7 @@ static struct eth_context eth_0_context = {
|
|||
|
||||
ETH_NET_DEVICE_INIT(eth_mcux_0, DT_ETH_MCUX_0_NAME, eth_0_init,
|
||||
ð_0_context, NULL, CONFIG_ETH_INIT_PRIORITY,
|
||||
&api_funcs, 1500);
|
||||
&api_funcs, NET_ETH_MTU);
|
||||
|
||||
static void eth_0_config_func(void)
|
||||
{
|
||||
|
|
|
@ -36,10 +36,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
|||
|
||||
#include "eth_native_posix_priv.h"
|
||||
|
||||
#if defined(CONFIG_NET_L2_ETHERNET)
|
||||
#define _ETH_MTU 1500
|
||||
#endif
|
||||
|
||||
#define NET_BUF_TIMEOUT K_MSEC(100)
|
||||
|
||||
#if defined(CONFIG_NET_VLAN)
|
||||
|
@ -49,8 +45,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
|||
#endif
|
||||
|
||||
struct eth_context {
|
||||
u8_t recv[_ETH_MTU + ETH_HDR_LEN];
|
||||
u8_t send[_ETH_MTU + ETH_HDR_LEN];
|
||||
u8_t recv[NET_ETH_MTU + ETH_HDR_LEN];
|
||||
u8_t send[NET_ETH_MTU + ETH_HDR_LEN];
|
||||
u8_t mac_addr[6];
|
||||
struct net_linkaddr ll_addr;
|
||||
struct net_if *iface;
|
||||
|
@ -509,7 +505,7 @@ static const struct ethernet_api eth_if_api = {
|
|||
ETH_NET_DEVICE_INIT(eth_native_posix, ETH_NATIVE_POSIX_DRV_NAME,
|
||||
eth_init, ð_context_data, NULL,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, ð_if_api,
|
||||
_ETH_MTU);
|
||||
NET_ETH_MTU);
|
||||
|
||||
#if defined(CONFIG_ETH_NATIVE_POSIX_PTP_CLOCK)
|
||||
struct ptp_context {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
#define GMAC_MULTIPLE_TX_PACKETS 0
|
||||
|
||||
#define GMAC_MTU 1500
|
||||
#define GMAC_MTU NET_ETH_MTU
|
||||
#define GMAC_FRAME_SIZE_MAX (GMAC_MTU + 18)
|
||||
|
||||
/** Cache alignment */
|
||||
|
|
|
@ -472,7 +472,7 @@ static int smsc_write_tx_fifo(const u8_t *buf, u32_t len, bool is_last)
|
|||
static int eth_tx(struct device *dev, struct net_pkt *pkt)
|
||||
{
|
||||
u16_t total_len = net_pkt_get_len(pkt);
|
||||
static u8_t tx_buf[1514] __aligned(4);
|
||||
static u8_t tx_buf[NET_ETH_MAX_FRAME_SIZE] __aligned(4);
|
||||
u32_t txcmd_a, txcmd_b;
|
||||
u32_t tx_stat;
|
||||
int res;
|
||||
|
@ -679,5 +679,5 @@ static struct eth_context eth_0_context;
|
|||
|
||||
ETH_NET_DEVICE_INIT(eth_smsc911x_0, "smsc911x_0",
|
||||
eth_init, ð_0_context,
|
||||
NULL/*ð_config_0*/, CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
1500/*MTU*/);
|
||||
NULL /*ð_config_0*/, CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
NET_ETH_MTU /*MTU*/);
|
||||
|
|
|
@ -358,4 +358,4 @@ NET_DEVICE_INIT(eth_stellaris, DT_ETH_DRV_NAME,
|
|||
eth_stellaris_dev_init, ð_data, ð_cfg,
|
||||
CONFIG_ETH_INIT_PRIORITY,
|
||||
ð_stellaris_apis, ETHERNET_L2,
|
||||
NET_L2_GET_CTX_TYPE(ETHERNET_L2), ETH_MTU);
|
||||
NET_L2_GET_CTX_TYPE(ETHERNET_L2), NET_ETH_MTU);
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
#ifndef ETH_STELLARIS_PRIV_H_
|
||||
#define ETH_STELLARIS_PRIV_H_
|
||||
|
||||
#define ETH_MTU 1500
|
||||
|
||||
#define DEV_DATA(dev) \
|
||||
((struct eth_stellaris_runtime *)(dev)->driver_data)
|
||||
#define DEV_CFG(dev) \
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <kernel.h>
|
||||
#include <zephyr/types.h>
|
||||
|
||||
#define ETH_STM32_HAL_MTU 1500
|
||||
#define ETH_STM32_HAL_MTU NET_ETH_MTU
|
||||
#define ETH_STM32_HAL_FRAME_SIZE_MAX (ETH_STM32_HAL_MTU + 18)
|
||||
|
||||
/* Definition of the Ethernet driver buffers size and count */
|
||||
|
|
|
@ -72,6 +72,8 @@ struct net_eth_addr {
|
|||
#endif
|
||||
|
||||
#define NET_ETH_MINIMAL_FRAME_SIZE 60
|
||||
#define NET_ETH_MTU 1500
|
||||
#define NET_ETH_MAX_FRAME_SIZE (NET_ETH_MTU + sizeof(struct net_eth_hdr))
|
||||
|
||||
/** @endcond */
|
||||
|
||||
|
|
|
@ -291,13 +291,15 @@ ETH_NET_DEVICE_INIT(eth_offloading_disabled_test,
|
|||
"eth_offloading_disabled_test",
|
||||
eth_init, ð_context_offloading_disabled,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY,
|
||||
&api_funcs_offloading_disabled, 1500);
|
||||
&api_funcs_offloading_disabled,
|
||||
NET_ETH_MTU);
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_offloading_enabled_test,
|
||||
"eth_offloading_enabled_test",
|
||||
eth_init, ð_context_offloading_enabled,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY,
|
||||
&api_funcs_offloading_enabled, 1500);
|
||||
&api_funcs_offloading_enabled,
|
||||
NET_ETH_MTU);
|
||||
|
||||
struct user_data {
|
||||
int eth_if_count;
|
||||
|
|
|
@ -302,7 +302,8 @@ static int eth_fake_init(struct device *dev)
|
|||
}
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_fake, "eth_fake", eth_fake_init, ð_fake_data,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, ð_fake_api_funcs, 1500);
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, ð_fake_api_funcs,
|
||||
NET_ETH_MTU);
|
||||
|
||||
static void test_change_mac_when_up(void)
|
||||
{
|
||||
|
|
|
@ -258,7 +258,8 @@ static int eth_fake_init(struct device *dev)
|
|||
}
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_fake, "eth_fake", eth_fake_init, ð_fake_data,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, ð_fake_api_funcs, 1500);
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, ð_fake_api_funcs,
|
||||
NET_ETH_MTU);
|
||||
|
||||
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG
|
||||
static const char *iface2str(struct net_if *iface)
|
||||
|
|
|
@ -75,7 +75,8 @@ static const struct dummy_api fake_dev_api = {
|
|||
NET_DEVICE_INIT(fake_dev, "fake_dev",
|
||||
fake_dev_init, NULL, NULL,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
||||
&fake_dev_api, _ETH_L2_LAYER, _ETH_L2_CTX_TYPE, 1500);
|
||||
&fake_dev_api, _ETH_L2_LAYER, _ETH_L2_CTX_TYPE,
|
||||
NET_ETH_MTU);
|
||||
|
||||
/*********************\
|
||||
* UTILITY FUNCTIONS *
|
||||
|
|
|
@ -143,10 +143,12 @@ static int eth_fake_init(struct device *dev)
|
|||
}
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_fake1, "eth_fake1", eth_fake_init, ð_fake_data1,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, ð_fake_api_funcs, 1500);
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, ð_fake_api_funcs,
|
||||
NET_ETH_MTU);
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_fake2, "eth_fake2", eth_fake_init, ð_fake_data2,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, ð_fake_api_funcs, 1500);
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, ð_fake_api_funcs,
|
||||
NET_ETH_MTU);
|
||||
|
||||
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG
|
||||
static const char *iface2str(struct net_if *iface)
|
||||
|
|
|
@ -155,13 +155,16 @@ static int eth_init(struct device *dev)
|
|||
}
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_test_1, "eth_test_1", eth_init, ð_context_1, NULL,
|
||||
CONFIG_ETH_INIT_PRIORITY, &api_funcs, 1500);
|
||||
CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
NET_ETH_MTU);
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_test_2, "eth_test_2", eth_init, ð_context_2, NULL,
|
||||
CONFIG_ETH_INIT_PRIORITY, &api_funcs, 1500);
|
||||
CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
NET_ETH_MTU);
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_test_3, "eth_test_3", eth_init, ð_context_3, NULL,
|
||||
CONFIG_ETH_INIT_PRIORITY, &api_funcs, 1500);
|
||||
CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
NET_ETH_MTU);
|
||||
|
||||
static u64_t timestamp_to_nsec(struct net_ptp_time *ts)
|
||||
{
|
||||
|
|
|
@ -267,7 +267,8 @@ static int eth_init(struct device *dev)
|
|||
*/
|
||||
NET_DEVICE_INIT(eth_test, "eth_test", eth_init, ð_context,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
DUMMY_L2, NET_L2_GET_CTX_TYPE(DUMMY_L2), 1500);
|
||||
DUMMY_L2, NET_L2_GET_CTX_TYPE(DUMMY_L2),
|
||||
NET_ETH_MTU);
|
||||
|
||||
static void address_setup(void)
|
||||
{
|
||||
|
|
|
@ -153,10 +153,12 @@ static int eth_init(struct device *dev)
|
|||
}
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_test, "eth_test", eth_init, ð_context,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, &api_funcs, 1500);
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
NET_ETH_MTU);
|
||||
|
||||
ETH_NET_DEVICE_INIT(eth_test2, "eth_test2", eth_init, ð_context2,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, &api_funcs, 1500);
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
NET_ETH_MTU);
|
||||
|
||||
static void timestamp_callback(struct net_pkt *pkt)
|
||||
{
|
||||
|
|
|
@ -172,7 +172,7 @@ static int eth_vlan_init(struct device *dev)
|
|||
|
||||
ETH_NET_DEVICE_INIT(eth_vlan_test, "eth_vlan_test", eth_vlan_init,
|
||||
ð_vlan_context, NULL, CONFIG_ETH_INIT_PRIORITY,
|
||||
&api_funcs, 1500);
|
||||
&api_funcs, NET_ETH_MTU);
|
||||
|
||||
static int eth_init(struct device *dev)
|
||||
{
|
||||
|
@ -189,7 +189,8 @@ static int eth_init(struct device *dev)
|
|||
*/
|
||||
NET_DEVICE_INIT(eth_test, "eth_test", eth_init, ð_vlan_context,
|
||||
NULL, CONFIG_ETH_INIT_PRIORITY, &api_funcs,
|
||||
ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2), 1500);
|
||||
ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2),
|
||||
NET_ETH_MTU);
|
||||
|
||||
struct net_if_test {
|
||||
u8_t idx; /* not used for anything, just a dummy value */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue