From fd281c11cc86635dcdaafb5736e75f22fad6243a Mon Sep 17 00:00:00 2001 From: suda-morris <362953310@qq.com> Date: Tue, 7 May 2019 18:30:10 +0800 Subject: [PATCH] add promiscuous mode control in emac driver 1. add promiscuous mode control in emac driver 2. fix minor bugs in IP101 driver --- components/ethernet/emac_common.h | 1 + components/ethernet/emac_dev.c | 10 ++++++++++ components/ethernet/emac_dev.h | 2 ++ components/ethernet/emac_main.c | 8 ++++++++ components/ethernet/eth_phy/phy_ip101.c | 10 ++++++++++ components/ethernet/eth_phy/phy_lan8720.c | 3 ++- components/ethernet/eth_phy/phy_tlk110.c | 3 ++- components/ethernet/include/esp_eth.h | 1 + 8 files changed, 36 insertions(+), 2 deletions(-) diff --git a/components/ethernet/emac_common.h b/components/ethernet/emac_common.h index d0bcff809..64a0bf9f2 100644 --- a/components/ethernet/emac_common.h +++ b/components/ethernet/emac_common.h @@ -75,6 +75,7 @@ struct emac_config_data { eth_phy_get_partner_pause_enable_func emac_phy_get_partner_pause_enable; eth_phy_power_enable_func emac_phy_power_enable; uint32_t reset_timeout_ms; + bool promiscuous_enable; }; enum emac_post_type { diff --git a/components/ethernet/emac_dev.c b/components/ethernet/emac_dev.c index e0269a489..0899868a7 100644 --- a/components/ethernet/emac_dev.c +++ b/components/ethernet/emac_dev.c @@ -99,3 +99,13 @@ void emac_mac_init(void) REG_CLR_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACFESPEED); REG_SET_BIT(EMAC_GMACFF_REG, EMAC_PAM); } + +void emac_enable_promiscuous(void) +{ + REG_SET_BIT(EMAC_GMACFF_REG, EMAC_PMODE); +} + +void emac_disable_promiscuous(void) +{ + REG_CLR_BIT(EMAC_GMACFF_REG, EMAC_PMODE); +} diff --git a/components/ethernet/emac_dev.h b/components/ethernet/emac_dev.h index 01a1e2391..3d686cf88 100644 --- a/components/ethernet/emac_dev.h +++ b/components/ethernet/emac_dev.h @@ -53,6 +53,8 @@ void emac_disable_dma_rx(void); void emac_enable_flowctrl(void); void emac_disable_flowctrl(void); void emac_mac_enable_txrx(void); +void emac_enable_promiscuous(void); +void emac_disable_promiscuous(void); static inline uint32_t emac_read_tx_cur_reg(void) { diff --git a/components/ethernet/emac_main.c b/components/ethernet/emac_main.c index a5624c4dd..7ca1298fb 100644 --- a/components/ethernet/emac_main.c +++ b/components/ethernet/emac_main.c @@ -325,6 +325,7 @@ static void emac_set_user_config_data(eth_config_t *config) #endif emac_config.emac_phy_get_partner_pause_enable = config->phy_get_partner_pause_enable; emac_config.emac_phy_power_enable = config->phy_power_enable; + emac_config.promiscuous_enable = config->promiscuous_enable; } static void emac_enable_intr() @@ -823,6 +824,13 @@ static void emac_start(void *param) emac_mac_init(); + /* check if enable promiscuous mode */ + if(emac_config.promiscuous_enable){ + emac_enable_promiscuous(); + }else{ + emac_disable_promiscuous(); + } + emac_enable_intr(); emac_config.emac_status = EMAC_RUNTIME_START; diff --git a/components/ethernet/eth_phy/phy_ip101.c b/components/ethernet/eth_phy/phy_ip101.c index 2969ff244..69b5c2daf 100644 --- a/components/ethernet/eth_phy/phy_ip101.c +++ b/components/ethernet/eth_phy/phy_ip101.c @@ -70,11 +70,19 @@ esp_err_t phy_ip101_init(void) esp_err_t res1, res2; ESP_LOGD(TAG, "phy_ip101_init()"); phy_ip101_dump_registers(); + + esp_eth_smi_write(MII_BASIC_MODE_CONTROL_REG, MII_SOFTWARE_RESET); + do { // Call esp_eth_smi_wait_value() with a timeout so it prints an error periodically res1 = esp_eth_smi_wait_value(MII_PHY_IDENTIFIER_1_REG, IP101_PHY_ID1, UINT16_MAX, 1000); res2 = esp_eth_smi_wait_value(MII_PHY_IDENTIFIER_2_REG, IP101_PHY_ID2, IP101_PHY_ID2_MASK, 1000); } while (res1 != ESP_OK || res2 != ESP_OK); + + uint32_t data = esp_eth_smi_read(MII_BASIC_MODE_CONTROL_REG); + data |= MII_AUTO_NEGOTIATION_ENABLE | MII_RESTART_AUTO_NEGOTIATION; + esp_eth_smi_write(MII_BASIC_MODE_CONTROL_REG, data); + ets_delay_us(300); // TODO: only do this if config.flow_ctrl_enable == true phy_mii_enable_flow_ctrl(); @@ -97,6 +105,8 @@ const eth_config_t phy_ip101_default_ethernet_config = { .phy_get_duplex_mode = phy_ip101_get_duplex_mode, .phy_get_partner_pause_enable = phy_mii_get_partner_pause_enable, .phy_power_enable = phy_ip101_power_enable, + .reset_timeout_ms = 1000, + .promiscuous_enable = false, }; void phy_ip101_dump_registers() diff --git a/components/ethernet/eth_phy/phy_lan8720.c b/components/ethernet/eth_phy/phy_lan8720.c index b74ecad8b..666b82868 100644 --- a/components/ethernet/eth_phy/phy_lan8720.c +++ b/components/ethernet/eth_phy/phy_lan8720.c @@ -114,7 +114,8 @@ const eth_config_t phy_lan8720_default_ethernet_config = { .phy_get_speed_mode = phy_lan8720_get_speed_mode, .phy_get_duplex_mode = phy_lan8720_get_duplex_mode, .phy_get_partner_pause_enable = phy_mii_get_partner_pause_enable, - .reset_timeout_ms = 1000 + .reset_timeout_ms = 1000, + .promiscuous_enable = false, }; void phy_lan8720_dump_registers() diff --git a/components/ethernet/eth_phy/phy_tlk110.c b/components/ethernet/eth_phy/phy_tlk110.c index 500eb5539..8e8fd2bfd 100644 --- a/components/ethernet/eth_phy/phy_tlk110.c +++ b/components/ethernet/eth_phy/phy_tlk110.c @@ -125,7 +125,8 @@ const eth_config_t phy_tlk110_default_ethernet_config = { .phy_get_duplex_mode = phy_tlk110_get_duplex_mode, .phy_get_partner_pause_enable = phy_mii_get_partner_pause_enable, .phy_power_enable = phy_tlk110_power_enable, - .reset_timeout_ms = 1000 + .reset_timeout_ms = 1000, + .promiscuous_enable = false, }; void phy_tlk110_dump_registers() diff --git a/components/ethernet/include/esp_eth.h b/components/ethernet/include/esp_eth.h index ccbc59d04..f22cf4f70 100644 --- a/components/ethernet/include/esp_eth.h +++ b/components/ethernet/include/esp_eth.h @@ -128,6 +128,7 @@ typedef struct { eth_phy_get_partner_pause_enable_func phy_get_partner_pause_enable; /*!< get partner pause enable */ eth_phy_power_enable_func phy_power_enable; /*!< enable or disable phy power */ uint32_t reset_timeout_ms; /*!< timeout value for reset emac */ + bool promiscuous_enable; /*!< set true to enable promiscuous mode */ } eth_config_t; /**