Merge branch 'feature/add_promiscuous_control_for_ethernet_v3.2' into 'release/v3.2'

add promiscuous mode control for Ethernet (v3.2)

See merge request idf/esp-idf!4976
This commit is contained in:
Angus Gratton 2019-05-23 14:23:48 +08:00
commit ee39083d1b
8 changed files with 36 additions and 2 deletions

View file

@ -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 {

View file

@ -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);
}

View file

@ -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)
{

View file

@ -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;

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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;
/**