]> granicus.if.org Git - esp-idf/commitdiff
add promiscuous mode control in emac driver
authorsuda-morris <362953310@qq.com>
Tue, 7 May 2019 10:30:10 +0000 (18:30 +0800)
committersuda-morris <362953310@qq.com>
Fri, 10 May 2019 04:56:35 +0000 (12:56 +0800)
1. add promiscuous mode control in emac driver
2. fix minor bugs in IP101 driver

components/ethernet/emac_common.h
components/ethernet/emac_dev.c
components/ethernet/emac_dev.h
components/ethernet/emac_main.c
components/ethernet/eth_phy/phy_ip101.c
components/ethernet/eth_phy/phy_lan8720.c
components/ethernet/eth_phy/phy_tlk110.c
components/ethernet/include/esp_eth.h

index d0bcff8093aabc87385d0466d3074ccd1ae47b46..64a0bf9f2f27b3b1f3c2710d341dcc4bae2c6bd8 100644 (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 {
index e0269a48957da48ed0afe9010e58cf86c85e13c9..0899868a7cf2f12d9caf3475615d8bb22109ecc1 100644 (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);
+}
index 01a1e23914a80d90cde5562240f19cf2bf70a8e4..3d686cf883f46219829c70fa9efb9decc1c2619d 100644 (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)
 {
index a5624c4dd59a05a356366d2c5fdcc25f940dbc0a..7ca1298fb6d3c040d91f691260d1571ef44b5f39 100644 (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;
index 2969ff2449e60890fd4b6967649009b76858f640..69b5c2daf830cfd151f3b5e8a9de75d161916628 100644 (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()
index b74ecad8b64203ed90a1b3a8906b42dc4c1adb8f..666b82868e8f717a5ac2f1d8a2dfe12c3a8e16d5 100644 (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()
index 500eb5539bab6bd14bafb935ee5659d4176edee6..8e8fd2bfd8b6baf3a0fa79ec06653f7eb641f163 100644 (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()
index ccbc59d04086340fa76516df648b791f437c9c6c..f22cf4f7013300e9ca6c0fdcabff99521af3e7e9 100644 (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;
 
 /**