ethernet: fix some bugs in ethernet driver

1. create a new pbuf to squash linked pbuf
2. optimize emac driver by adding ESP_IRAM_ATTR
3. remove duplicated function declare in esp_eth.h
4. remove duplicated code in emac_setup_tx_desc
5. disable Promiscuous mode
This commit is contained in:
morris
2018-09-10 21:00:08 +08:00
parent 61af7f3903
commit 3063a62e3e
4 changed files with 39 additions and 56 deletions

View File

@@ -111,5 +111,4 @@ void emac_mac_init(void)
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACDUPLEX); REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACDUPLEX);
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACMII); REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACMII);
REG_CLR_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACFESPEED); REG_CLR_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACFESPEED);
REG_SET_BIT(EMAC_GMACFF_REG, EMAC_PMODE);
} }

View File

@@ -104,9 +104,6 @@ esp_err_t esp_eth_set_mac(const uint8_t mac[6])
static void emac_setup_tx_desc(struct dma_extended_desc *tx_desc, uint32_t size) static void emac_setup_tx_desc(struct dma_extended_desc *tx_desc, uint32_t size)
{ {
tx_desc->basic.desc1 = size & 0xfff; tx_desc->basic.desc1 = size & 0xfff;
tx_desc->basic.desc0 = EMAC_DESC_INT_COMPL | EMAC_DESC_LAST_SEGMENT |
EMAC_DESC_FIRST_SEGMENT |
EMAC_DESC_SECOND_ADDR_CHAIN;
tx_desc->basic.desc0 = EMAC_DESC_TX_OWN | EMAC_DESC_INT_COMPL | tx_desc->basic.desc0 = EMAC_DESC_TX_OWN | EMAC_DESC_INT_COMPL |
EMAC_DESC_LAST_SEGMENT | EMAC_DESC_FIRST_SEGMENT | EMAC_DESC_LAST_SEGMENT | EMAC_DESC_FIRST_SEGMENT |
EMAC_DESC_SECOND_ADDR_CHAIN; EMAC_DESC_SECOND_ADDR_CHAIN;
@@ -630,10 +627,10 @@ static void IRAM_ATTR emac_process_intr(void *arg)
static void emac_set_macaddr_reg(void) static void emac_set_macaddr_reg(void)
{ {
REG_SET_FIELD(EMAC_ADDR0HIGH_REG, EMAC_ADDRESS0_HI, (emac_config.macaddr[0] << 8) | (emac_config.macaddr[1])); REG_SET_FIELD(EMAC_ADDR0HIGH_REG, EMAC_ADDRESS0_HI, (emac_config.macaddr[5] << 8) | (emac_config.macaddr[4]));
REG_WRITE(EMAC_ADDR0LOW_REG, (emac_config.macaddr[2] << 24) | REG_WRITE(EMAC_ADDR0LOW_REG, (emac_config.macaddr[3] << 24) |
(emac_config.macaddr[3] << 16) | (emac_config.macaddr[4] << 8) | (emac_config.macaddr[2] << 16) | (emac_config.macaddr[1] << 8) |
(emac_config.macaddr[5])); (emac_config.macaddr[0]));
} }
static void emac_check_phy_init(void) static void emac_check_phy_init(void)

View File

@@ -260,14 +260,6 @@ static inline esp_err_t esp_eth_smi_wait_set(uint32_t reg_num, uint16_t value_ma
*/ */
void esp_eth_free_rx_buf(void *buf); void esp_eth_free_rx_buf(void *buf);
/**
* @brief Get mac of ethernet interface.
*
* @param[out] mac: store mac of the interface.
*
*/
void esp_eth_get_mac(uint8_t mac[6]);
/** /**
* @brief Set mac of ethernet interface. * @brief Set mac of ethernet interface.
* *

View File

@@ -103,11 +103,12 @@ ethernet_low_level_init(struct netif *netif)
* to become availale since the stack doesn't retry to send a packet * to become availale since the stack doesn't retry to send a packet
* dropped because of memory failure (except for the TCP timers). * dropped because of memory failure (except for the TCP timers).
*/ */
static err_t static err_t ESP_IRAM_ATTR
ethernet_low_level_output(struct netif *netif, struct pbuf *p) ethernet_low_level_output(struct netif *netif, struct pbuf *p)
{ {
struct pbuf *q; struct pbuf *q = p;
esp_interface_t eth_if = tcpip_adapter_get_esp_if(netif); esp_interface_t eth_if = tcpip_adapter_get_esp_if(netif);
err_t ret;
if (eth_if != ESP_IF_ETH) { if (eth_if != ESP_IF_ETH) {
LWIP_DEBUGF(NETIF_DEBUG, ("eth_if=%d netif=%p pbuf=%p len=%d\n", eth_if, netif, p, p->len)); LWIP_DEBUGF(NETIF_DEBUG, ("eth_if=%d netif=%p pbuf=%p len=%d\n", eth_if, netif, p, p->len));
@@ -115,28 +116,22 @@ ethernet_low_level_output(struct netif *netif, struct pbuf *p)
return ERR_IF; return ERR_IF;
} }
#if ESP_LWIP if (q->next == NULL) {
q = p; ret = esp_eth_tx(q->payload, q->len);
u16_t pbuf_x_len = 0; } else {
pbuf_x_len = q->len; LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
if(q->next !=NULL) { q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
//char cnt = 0; if (q != NULL) {
struct pbuf *tmp = q->next; q->l2_owner = NULL;
while(tmp != NULL) { pbuf_copy(q, p);
memcpy( (u8_t *)( (u8_t *)(q->payload) + pbuf_x_len), (u8_t *)tmp->payload , tmp->len ); } else {
pbuf_x_len += tmp->len; return ERR_MEM;
//cnt++;
tmp = tmp->next;
} }
ret = esp_eth_tx(q->payload, q->len);
pbuf_free(q);
} }
return esp_eth_tx(q->payload, pbuf_x_len); return ret;
#else
for(q = p; q != NULL; q = q->next) {
return esp_emac_tx(q->payload, q->len);
}
return ERR_OK;
#endif
} }
/** /**
@@ -155,7 +150,7 @@ ethernet_low_level_output(struct netif *netif, struct pbuf *p)
* freeing the buffer. Otherwise, high layer and ethernet share the * freeing the buffer. Otherwise, high layer and ethernet share the
* same buffer and high layer is responsible for freeing the buffer. * same buffer and high layer is responsible for freeing the buffer.
*/ */
void void ESP_IRAM_ATTR
ethernetif_input(struct netif *netif, void *buffer, uint16_t len) ethernetif_input(struct netif *netif, void *buffer, uint16_t len)
{ {
struct pbuf *p; struct pbuf *p;