diff --git a/components/esp_eth/include/esp_eth_mac.h b/components/esp_eth/include/esp_eth_mac.h index db462728a1..c054cafcf9 100644 --- a/components/esp_eth/include/esp_eth_mac.h +++ b/components/esp_eth/include/esp_eth_mac.h @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include @@ -374,11 +366,7 @@ typedef struct { uint32_t sw_reset_timeout_ms; /*!< Software reset timeout value (Unit: ms) */ uint32_t rx_task_stack_size; /*!< Stack size of the receive task */ uint32_t rx_task_prio; /*!< Priority of the receive task */ - int smi_mdc_gpio_num; /*!< SMI MDC GPIO number, set to -1 could bypass the SMI GPIO configuration */ - int smi_mdio_gpio_num; /*!< SMI MDIO GPIO number, set to -1 could bypass the SMI GPIO configuration */ uint32_t flags; /*!< Flags that specify extra capability for mac driver */ - eth_data_interface_t interface; /*!< EMAC Data interface to PHY (MII/RMII) */ - eth_mac_clock_config_t clock_config; /*!< EMAC Interface clock configuration */ } eth_mac_config_t; #define ETH_MAC_FLAG_WORK_WITH_CACHE_DISABLE (1 << 0) /*!< MAC driver can work when cache is disabled */ @@ -393,21 +381,42 @@ typedef struct { .sw_reset_timeout_ms = 100, \ .rx_task_stack_size = 2048, \ .rx_task_prio = 15, \ - .smi_mdc_gpio_num = 23, \ - .smi_mdio_gpio_num = 18, \ .flags = 0, \ - .interface = EMAC_DATA_INTERFACE_RMII, \ - .clock_config = \ - { \ - .rmii = \ - { \ - .clock_mode = EMAC_CLK_DEFAULT, \ - .clock_gpio = EMAC_CLK_IN_GPIO \ - } \ - } \ } #if CONFIG_ETH_USE_ESP32_EMAC +/** +* @brief EMAC specific configuration +* +*/ +typedef struct { + int smi_mdc_gpio_num; /*!< SMI MDC GPIO number, set to -1 could bypass the SMI GPIO configuration */ + int smi_mdio_gpio_num; /*!< SMI MDIO GPIO number, set to -1 could bypass the SMI GPIO configuration */ + eth_data_interface_t interface; /*!< EMAC Data interface to PHY (MII/RMII) */ + eth_mac_clock_config_t clock_config; /*!< EMAC Interface clock configuration */ + eth_mac_dma_burst_len_t dma_burst_len; /*!< EMAC DMA burst length for both Tx and Rx */ +} eth_esp32_emac_config_t; + +/** + * @brief Default ESP32's EMAC specific configuration + * + */ +#define ETH_ESP32_EMAC_DEFAULT_CONFIG() \ + { \ + .smi_mdc_gpio_num = 23, \ + .smi_mdio_gpio_num = 18, \ + .interface = EMAC_DATA_INTERFACE_RMII, \ + .clock_config = \ + { \ + .rmii = \ + { \ + .clock_mode = EMAC_CLK_DEFAULT, \ + .clock_gpio = EMAC_CLK_IN_GPIO \ + } \ + }, \ + .dma_burst_len = ETH_DMA_BURST_LEN_32 \ + } + /** * @brief Create ESP32 Ethernet MAC instance * @@ -417,7 +426,7 @@ typedef struct { * - instance: create MAC instance successfully * - NULL: create MAC instance failed because some error occurred */ -esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config); +esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_esp32_emac_config_t *esp32_config, const eth_mac_config_t *config); #endif // CONFIG_ETH_USE_ESP32_EMAC #if CONFIG_ETH_SPI_ETHERNET_DM9051 diff --git a/components/esp_eth/src/esp_eth_mac_esp.c b/components/esp_eth/src/esp_eth_mac_esp.c index 02df23aed4..12b0a34f78 100644 --- a/components/esp_eth/src/esp_eth_mac_esp.c +++ b/components/esp_eth/src/esp_eth_mac_esp.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -61,6 +61,7 @@ typedef struct { #ifdef CONFIG_PM_ENABLE esp_pm_lock_handle_t pm_lock; #endif + eth_mac_dma_burst_len_t dma_burst_len; } emac_esp32_t; static esp_err_t esp_emac_alloc_driver_obj(const eth_mac_config_t *config, emac_esp32_t **emac_out_hdl, void **out_descriptors); @@ -342,8 +343,9 @@ static esp_err_t emac_esp32_init(esp_eth_mac_t *mac) emac_hal_reset_desc_chain(&emac->hal); /* init mac registers by default */ emac_hal_init_mac_default(&emac->hal); - /* init dma registers by default */ - emac_hal_init_dma_default(&emac->hal); + /* init dma registers with selected EMAC-DMA configuration */ + emac_hal_dma_config_t dma_config = { .dma_burst_len = emac->dma_burst_len }; + emac_hal_init_dma_default(&emac->hal, &dma_config); /* get emac address from efuse */ ESP_GOTO_ON_ERROR(esp_read_mac(emac->addr, ESP_MAC_ETH), err, TAG, "fetch ethernet mac address failed"); /* set MAC address to emac register */ @@ -497,12 +499,12 @@ err: return ret; } -static esp_err_t esp_emac_config_data_interface(const eth_mac_config_t *config, emac_esp32_t *emac) +static esp_err_t esp_emac_config_data_interface(const eth_esp32_emac_config_t *esp32_emac_config, emac_esp32_t *emac) { esp_err_t ret = ESP_OK; - switch (config->interface) { + switch (esp32_emac_config->interface) { case EMAC_DATA_INTERFACE_MII: - emac->clock_config = config->clock_config; + emac->clock_config = esp32_emac_config->clock_config; /* MII interface GPIO initialization */ emac_hal_iomux_init_mii(); /* Enable MII clock */ @@ -510,7 +512,7 @@ static esp_err_t esp_emac_config_data_interface(const eth_mac_config_t *config, break; case EMAC_DATA_INTERFACE_RMII: // by default, the clock mode is selected at compile time (by Kconfig) - if (config->clock_config.rmii.clock_mode == EMAC_CLK_DEFAULT) { + if (esp32_emac_config->clock_config.rmii.clock_mode == EMAC_CLK_DEFAULT) { #if CONFIG_ETH_RMII_CLK_INPUT #if CONFIG_ETH_RMII_CLK_IN_GPIO == 0 emac->clock_config.rmii.clock_mode = EMAC_CLK_EXT_IN; @@ -529,7 +531,7 @@ static esp_err_t esp_emac_config_data_interface(const eth_mac_config_t *config, #error "Unsupported RMII clock mode" #endif } else { - emac->clock_config = config->clock_config; + emac->clock_config = esp32_emac_config->clock_config; } /* RMII interface GPIO initialization */ emac_hal_iomux_init_rmii(); @@ -559,13 +561,13 @@ static esp_err_t esp_emac_config_data_interface(const eth_mac_config_t *config, } break; default: - ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "invalid EMAC Data Interface:%d", config->interface); + ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "invalid EMAC Data Interface:%d", esp32_emac_config->interface); } err: return ret; } -esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config) +esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_esp32_emac_config_t *esp32_config, const eth_mac_config_t *config) { esp_err_t ret_code = ESP_OK; esp_eth_mac_t *ret = NULL; @@ -588,12 +590,13 @@ esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config) emac_isr_default_handler, &emac->hal, &(emac->intr_hdl)); } ESP_GOTO_ON_FALSE(ret_code == ESP_OK, NULL, err, TAG, "alloc emac interrupt failed"); - ret_code = esp_emac_config_data_interface(config, emac); + ret_code = esp_emac_config_data_interface(esp32_config, emac); ESP_GOTO_ON_FALSE(ret_code == ESP_OK, NULL, err_interf, TAG, "config emac interface failed"); + emac->dma_burst_len = esp32_config->dma_burst_len; emac->sw_reset_timeout_ms = config->sw_reset_timeout_ms; - emac->smi_mdc_gpio_num = config->smi_mdc_gpio_num; - emac->smi_mdio_gpio_num = config->smi_mdio_gpio_num; + emac->smi_mdc_gpio_num = esp32_config->smi_mdc_gpio_num; + emac->smi_mdio_gpio_num = esp32_config->smi_mdio_gpio_num; emac->flow_control_high_water_mark = FLOW_CONTROL_HIGH_WATER_MARK; emac->flow_control_low_water_mark = FLOW_CONTROL_LOW_WATER_MARK; emac->use_apll = false; diff --git a/components/esp_eth/test/test_emac.c b/components/esp_eth/test/test_emac.c index 7c2bef237e..5fc632f67e 100644 --- a/components/esp_eth/test/test_emac.c +++ b/components/esp_eth/test/test_emac.c @@ -97,7 +97,8 @@ TEST_CASE("esp32 ethernet io test", "[ethernet][test_env=UT_T2_Ethernet]") { eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); mac_config.flags = ETH_MAC_FLAG_PIN_TO_CORE; // pin to core - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // auto detect PHY address phy_config.phy_addr = ESP_ETH_PHY_ADDR_AUTO; @@ -131,7 +132,8 @@ TEST_CASE("esp32 ethernet speed/duplex/autonegotiation", "[ethernet][test_env=UT TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, eth_event_group)); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); mac_config.flags = ETH_MAC_FLAG_PIN_TO_CORE; // pin to core - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // auto detect PHY address phy_config.phy_addr = ESP_ETH_PHY_ADDR_AUTO; @@ -310,7 +312,8 @@ TEST_CASE("esp32 ethernet event test", "[ethernet][test_env=UT_T2_Ethernet]") TEST_ESP_OK(esp_event_loop_create_default()); TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, eth_event_group)); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); @@ -350,7 +353,8 @@ TEST_CASE("esp32 ethernet dhcp test", "[ethernet][test_env=UT_T2_Ethernet]") esp_netif_t *eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); @@ -397,7 +401,8 @@ TEST_CASE("esp32 ethernet start/stop stress test", "[ethernet][test_env=UT_T2_Et esp_netif_t *eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); @@ -495,7 +500,8 @@ TEST_CASE("esp32 ethernet download test", "[ethernet][test_env=UT_T2_Ethernet][t esp_netif_t *eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); diff --git a/components/esp_eth/test_apps/main/esp_eth_test.c b/components/esp_eth/test_apps/main/esp_eth_test.c index b934b51b59..e785aad0b4 100644 --- a/components/esp_eth/test_apps/main/esp_eth_test.c +++ b/components/esp_eth/test_apps/main/esp_eth_test.c @@ -48,7 +48,8 @@ TEST_CASE("start_and_stop", "[esp_eth]") TEST_ASSERT(eth_event_group != NULL); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC configuration - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); // create MAC instance + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance TEST_ASSERT_NOT_NULL(mac); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration #if defined(CONFIG_TARGET_ETH_PHY_DEVICE_IP101) @@ -99,7 +100,8 @@ TEST_CASE("get_set_mac", "[esp_eth]") TEST_ASSERT_NOT_NULL(mutex); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC configuration - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); // create MAC instance + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance TEST_ASSERT_NOT_NULL(mac); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration #if defined(CONFIG_TARGET_ETH_PHY_DEVICE_IP101) @@ -152,7 +154,8 @@ TEST_CASE("ethernet_broadcast_transmit", "[esp_eth]") TEST_ASSERT_NOT_NULL(mutex); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC configuration - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); // create MAC instance + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance TEST_ASSERT_NOT_NULL(mac); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration #if defined(CONFIG_TARGET_ETH_PHY_DEVICE_IP101) @@ -222,7 +225,8 @@ TEST_CASE("recv_pkt", "[esp_eth]") TEST_ASSERT(eth_event_group != NULL); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC configuration - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); // create MAC instance + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance TEST_ASSERT_NOT_NULL(mac); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration #if defined(CONFIG_TARGET_ETH_PHY_DEVICE_IP101) diff --git a/components/esp_netif/test/test_vfs_l2tap.c b/components/esp_netif/test/test_vfs_l2tap.c index 85e0b06d4d..61b75e398c 100644 --- a/components/esp_netif/test/test_vfs_l2tap.c +++ b/components/esp_netif/test/test_vfs_l2tap.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -144,7 +144,8 @@ static void ethernet_init(test_vfs_eth_network_t *network_hndls) network_hndls->eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - network_hndls->mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + network_hndls->mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); network_hndls->phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(network_hndls->mac, network_hndls->phy); diff --git a/components/hal/emac_hal.c b/components/hal/emac_hal.c index df9d0901b6..c4619b3b01 100644 --- a/components/hal/emac_hal.c +++ b/components/hal/emac_hal.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -265,7 +265,7 @@ void emac_hal_enable_flow_ctrl(emac_hal_context_t *hal, bool enable) } } -void emac_hal_init_dma_default(emac_hal_context_t *hal) +void emac_hal_init_dma_default(emac_hal_context_t *hal, emac_hal_dma_config_t *hal_config) { /* DMAOMR Configuration */ /* Enable Dropping of TCP/IP Checksum Error Frames */ @@ -294,11 +294,10 @@ void emac_hal_init_dma_default(emac_hal_context_t *hal) emac_ll_mixed_burst_enable(hal->dma_regs, true); /* Enable Address Aligned Beates */ emac_ll_addr_align_enable(hal->dma_regs, true); - /* Use Separate PBL */ - emac_ll_use_separate_pbl_enable(hal->dma_regs, true); + /* Don't use Separate PBL */ + emac_ll_use_separate_pbl_enable(hal->dma_regs, false); /* Set Rx/Tx DMA Burst Length */ - emac_ll_set_rx_dma_pbl(hal->dma_regs, EMAC_LL_DMA_BURST_LENGTH_32BEAT); - emac_ll_set_prog_burst_len(hal->dma_regs, EMAC_LL_DMA_BURST_LENGTH_32BEAT); + emac_ll_set_prog_burst_len(hal->dma_regs, hal_config->dma_burst_len); /* Enable Enhanced Descriptor,8 Words(32 Bytes) */ emac_ll_enhance_desc_enable(hal->dma_regs, true); /* Specifies the number of word to skip between two unchained descriptors (Ring mode) */ diff --git a/components/hal/esp32/include/hal/emac_ll.h b/components/hal/esp32/include/hal/emac_ll.h index bea18961bc..4fdc0e62f5 100644 --- a/components/hal/esp32/include/hal/emac_ll.h +++ b/components/hal/esp32/include/hal/emac_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -468,9 +468,14 @@ static inline void emac_ll_set_rx_dma_pbl(emac_dma_dev_t *dma_regs, uint32_t pbl dma_regs->dmabusmode.rx_dma_pbl = pbl; } -static inline void emac_ll_set_prog_burst_len(emac_dma_dev_t *dma_regs, uint32_t len) +static inline void emac_ll_set_prog_burst_len(emac_dma_dev_t *dma_regs, eth_mac_dma_burst_len_t dma_burst_len) { - dma_regs->dmabusmode.prog_burst_len = len; + dma_regs->dmabusmode.prog_burst_len = dma_burst_len == ETH_DMA_BURST_LEN_1 ? EMAC_LL_DMA_BURST_LENGTH_1BEAT : + dma_burst_len == ETH_DMA_BURST_LEN_2 ? EMAC_LL_DMA_BURST_LENGTH_2BEAT : + dma_burst_len == ETH_DMA_BURST_LEN_4 ? EMAC_LL_DMA_BURST_LENGTH_4BEAT : + dma_burst_len == ETH_DMA_BURST_LEN_8 ? EMAC_LL_DMA_BURST_LENGTH_8BEAT : + dma_burst_len == ETH_DMA_BURST_LEN_16 ? EMAC_LL_DMA_BURST_LENGTH_16BEAT : + EMAC_LL_DMA_BURST_LENGTH_32BEAT; } static inline void emac_ll_enhance_desc_enable(emac_dma_dev_t *dma_regs, bool enable) diff --git a/components/hal/include/hal/emac_hal.h b/components/hal/include/hal/emac_hal.h index 4f332811ab..961f2c4ce3 100644 --- a/components/hal/include/hal/emac_hal.h +++ b/components/hal/include/hal/emac_hal.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -164,6 +164,13 @@ typedef struct { } emac_hal_context_t; +/** + * @brief EMAC related configuration + */ +typedef struct { + eth_mac_dma_burst_len_t dma_burst_len; /*!< eth-type enum of chosen dma burst-len */ +} emac_hal_dma_config_t; + void emac_hal_init(emac_hal_context_t *hal, void *descriptors, uint8_t **rx_buf, uint8_t **tx_buf); @@ -189,7 +196,7 @@ void emac_hal_set_csr_clock_range(emac_hal_context_t *hal, int freq); void emac_hal_init_mac_default(emac_hal_context_t *hal); -void emac_hal_init_dma_default(emac_hal_context_t *hal); +void emac_hal_init_dma_default(emac_hal_context_t *hal, emac_hal_dma_config_t *hal_config); void emac_hal_set_speed(emac_hal_context_t *hal, uint32_t speed); diff --git a/components/hal/include/hal/eth_types.h b/components/hal/include/hal/eth_types.h index d9ce868169..d7d1f2ec4a 100644 --- a/components/hal/include/hal/eth_types.h +++ b/components/hal/include/hal/eth_types.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -49,3 +49,15 @@ typedef enum { ETH_CHECKSUM_SW, /*!< Ethernet checksum calculate by software */ ETH_CHECKSUM_HW /*!< Ethernet checksum calculate by hardware */ } eth_checksum_t; + +/** +* @brief Internal ethernet EMAC's DMA available burst sizes +*/ +typedef enum { + ETH_DMA_BURST_LEN_32, + ETH_DMA_BURST_LEN_16, + ETH_DMA_BURST_LEN_8, + ETH_DMA_BURST_LEN_4, + ETH_DMA_BURST_LEN_2, + ETH_DMA_BURST_LEN_1, +} eth_mac_dma_burst_len_t; diff --git a/components/mqtt/test/test_mqtt_connection.c b/components/mqtt/test/test_mqtt_connection.c index bf3f09ab4a..6598b985c9 100644 --- a/components/mqtt/test/test_mqtt_connection.c +++ b/components/mqtt/test/test_mqtt_connection.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -100,7 +100,8 @@ void connect_test_fixture_setup(void) s_eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - s_mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + s_mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); s_phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(s_mac, s_phy); diff --git a/examples/common_components/protocol_examples_common/connect.c b/examples/common_components/protocol_examples_common/connect.c index 50925b76a8..c54deae670 100644 --- a/examples/common_components/protocol_examples_common/connect.c +++ b/examples/common_components/protocol_examples_common/connect.c @@ -379,9 +379,10 @@ static esp_netif_t *eth_start(void) phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; #if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET - mac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; - mac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; - s_mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; + s_mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_EXAMPLE_ETH_PHY_IP101 s_phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_RTL8201 diff --git a/examples/ethernet/basic/main/ethernet_example_main.c b/examples/ethernet/basic/main/ethernet_example_main.c index e539af9f65..3698fe7f0a 100644 --- a/examples/ethernet/basic/main/ethernet_example_main.c +++ b/examples/ethernet/basic/main/ethernet_example_main.c @@ -101,9 +101,10 @@ void app_main(void) phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; - mac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; - mac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_EXAMPLE_ETH_PHY_IP101 esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_RTL8201 diff --git a/examples/ethernet/enc28j60/main/enc28j60_example_main.c b/examples/ethernet/enc28j60/main/enc28j60_example_main.c index ba021a92f7..fa28770d18 100644 --- a/examples/ethernet/enc28j60/main/enc28j60_example_main.c +++ b/examples/ethernet/enc28j60/main/enc28j60_example_main.c @@ -101,8 +101,6 @@ void app_main(void) enc28j60_config.int_gpio_num = CONFIG_EXAMPLE_ENC28J60_INT_GPIO; eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - mac_config.smi_mdc_gpio_num = -1; // ENC28J60 doesn't have SMI interface - mac_config.smi_mdio_gpio_num = -1; esp_eth_mac_t *mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); diff --git a/examples/ethernet/eth2ap/main/ethernet_example_main.c b/examples/ethernet/eth2ap/main/ethernet_example_main.c index 47ce52eabd..4f11e4591b 100644 --- a/examples/ethernet/eth2ap/main/ethernet_example_main.c +++ b/examples/ethernet/eth2ap/main/ethernet_example_main.c @@ -158,9 +158,10 @@ static void initialize_ethernet(void) phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; #if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET - mac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; - mac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_EXAMPLE_ETH_PHY_IP101 esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_RTL8201 diff --git a/examples/ethernet/iperf/main/cmd_ethernet.c b/examples/ethernet/iperf/main/cmd_ethernet.c index 07c47dbfeb..e9999eda69 100644 --- a/examples/ethernet/iperf/main/cmd_ethernet.c +++ b/examples/ethernet/iperf/main/cmd_ethernet.c @@ -208,9 +208,10 @@ void register_ethernet(void) phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; #if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET - mac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; - mac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_EXAMPLE_ETH_PHY_IP101 esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_RTL8201 @@ -293,8 +294,6 @@ void register_ethernet(void) eth_enc28j60_config_t enc28j60_config = ETH_ENC28J60_DEFAULT_CONFIG(spi_handle); enc28j60_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO; - mac_config.smi_mdc_gpio_num = -1; // ENC28J60 doesn't have SMI interface - mac_config.smi_mdio_gpio_num = -1; esp_eth_mac_t *mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config); phy_config.autonego_timeout_ms = 0; // ENC28J60 doesn't support auto-negotiation diff --git a/examples/network/simple_sniffer/main/simple_sniffer_example_main.c b/examples/network/simple_sniffer/main/simple_sniffer_example_main.c index 5282200e39..107cd60d0b 100644 --- a/examples/network/simple_sniffer/main/simple_sniffer_example_main.c +++ b/examples/network/simple_sniffer/main/simple_sniffer_example_main.c @@ -135,9 +135,10 @@ static void initialize_eth(void) phy_config.phy_addr = CONFIG_SNIFFER_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_SNIFFER_ETH_PHY_RST_GPIO; #if CONFIG_SNIFFER_USE_INTERNAL_ETHERNET - mac_config.smi_mdc_gpio_num = CONFIG_SNIFFER_ETH_MDC_GPIO; - mac_config.smi_mdio_gpio_num = CONFIG_SNIFFER_ETH_MDIO_GPIO; - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_SNIFFER_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_SNIFFER_ETH_MDIO_GPIO; + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_SNIFFER_ETH_PHY_IP101 esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_SNIFFER_ETH_PHY_RTL8201 diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index a794be05c3..9589e413c7 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -439,7 +439,6 @@ components/esp_common/include/esp_compiler.h components/esp_common/include/esp_types.h components/esp_common/src/esp_err_to_name.c components/esp_common/test/test_attr.c -components/esp_eth/include/esp_eth_mac.h components/esp_eth/include/eth_phy_regs_struct.h components/esp_eth/src/dm9051.h components/esp_eth/src/esp_eth_mac_openeth.c