lwip: Refactor support for L2 pbuf free notification into each driver

Makes it easier to handle different drivers enabled at compile/link time.
This commit is contained in:
Angus Gratton 2017-02-24 14:45:17 +11:00
parent 36b3963efb
commit eb1fbaabce
5 changed files with 32 additions and 32 deletions

View File

@ -78,11 +78,6 @@
#include <string.h> #include <string.h>
#if ESP_LWIP
#include "esp_wifi_internal.h"
#include "esp_eth.h"
#endif
#define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf)) #define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
/* Since the pool is created in memp, PBUF_POOL_BUFSIZE will be automatically /* Since the pool is created in memp, PBUF_POOL_BUFSIZE will be automatically
aligned there. Therefore, PBUF_POOL_BUFSIZE_ALIGNED can be used here. */ aligned there. Therefore, PBUF_POOL_BUFSIZE_ALIGNED can be used here. */
@ -352,8 +347,8 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
p->flags = 0; p->flags = 0;
#if ESP_LWIP #if ESP_LWIP
p->user_buf = NULL; p->l2_owner = NULL;
p->user_flag = PBUF_USER_FLAG_OWNER_NULL; p->l2_buf = NULL;
#endif #endif
LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p)); LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p));
@ -722,12 +717,11 @@ pbuf_free(struct pbuf *p)
} else if (type == PBUF_ROM || type == PBUF_REF) { } else if (type == PBUF_ROM || type == PBUF_REF) {
#if ESP_LWIP #if ESP_LWIP
if (type == PBUF_REF && p->user_flag == PBUF_USER_FLAG_OWNER_WIFI ) { if (p->l2_owner != NULL
esp_wifi_internal_free_rx_buffer(p->user_buf); && p->l2_buf != NULL
} && p->l2_owner->l2_buffer_free_notify != NULL) {
if (type == PBUF_REF && p->user_flag == PBUF_USER_FLAG_OWNER_ETH ) { p->l2_owner->l2_buffer_free_notify(p->l2_buf);
esp_eth_free_rx_buf(p->user_buf); }
}
#endif #endif
memp_free(MEMP_PBUF, p); memp_free(MEMP_PBUF, p);
/* type == PBUF_RAM */ /* type == PBUF_RAM */

View File

@ -330,6 +330,10 @@ struct netif {
u16_t loop_cnt_current; u16_t loop_cnt_current;
#endif /* LWIP_LOOPBACK_MAX_PBUFS */ #endif /* LWIP_LOOPBACK_MAX_PBUFS */
#endif /* ENABLE_LOOPBACK */ #endif /* ENABLE_LOOPBACK */
#if ESP_LWIP
void (*l2_buffer_free_notify)(void *user_buf); /* Allows LWIP to notify driver when a L2-supplied pbuf can be freed */
#endif
}; };
#if LWIP_CHECKSUM_CTRL_PER_NETIF #if LWIP_CHECKSUM_CTRL_PER_NETIF

View File

@ -105,12 +105,6 @@ typedef enum {
/** indicates this pbuf includes a TCP FIN flag */ /** indicates this pbuf includes a TCP FIN flag */
#define PBUF_FLAG_TCP_FIN 0x20U #define PBUF_FLAG_TCP_FIN 0x20U
#if ESP_LWIP
#define PBUF_USER_FLAG_OWNER_NULL 0
#define PBUF_USER_FLAG_OWNER_WIFI 1
#define PBUF_USER_FLAG_OWNER_ETH 2
#endif
struct pbuf { struct pbuf {
/** next pbuf in singly linked pbuf chain */ /** next pbuf in singly linked pbuf chain */
struct pbuf *next; struct pbuf *next;
@ -144,8 +138,8 @@ struct pbuf {
u16_t ref; u16_t ref;
#if ESP_LWIP #if ESP_LWIP
void *user_buf; struct netif *l2_owner;
u8_t user_flag; void *l2_buf;
#endif #endif
}; };

View File

@ -82,7 +82,10 @@ ethernet_low_level_init(struct netif *netif)
netif->flags |= NETIF_FLAG_IGMP; netif->flags |= NETIF_FLAG_IGMP;
#endif #endif
#endif #endif
/* Do whatever else is needed to initialize interface. */
#ifndef CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE
netif->l2_buffer_free_notify = esp_eth_free_rx_buf;
#endif
} }
/** /**
@ -152,11 +155,12 @@ ethernetif_input(struct netif *netif, void *buffer, uint16_t len)
if(buffer== NULL || netif == NULL) if(buffer== NULL || netif == NULL)
goto _exit; goto _exit;
#if CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE #ifdef CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM); p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
if (p == NULL) { if (p == NULL) {
return; return;
} }
p->l2_owner = NULL;
memcpy(p->payload, buffer, len); memcpy(p->payload, buffer, len);
/* full packet send to tcpip_thread to process */ /* full packet send to tcpip_thread to process */
@ -171,13 +175,13 @@ if (netif->input(p, netif) != ERR_OK) {
return; return;
} }
p->payload = buffer; p->payload = buffer;
p->user_flag = PBUF_USER_FLAG_OWNER_ETH; p->l2_owner = netif;
p->user_buf = buffer; p->l2_buf = buffer;
/* full packet send to tcpip_thread to process */ /* full packet send to tcpip_thread to process */
if (netif->input(p, netif) != ERR_OK) { if (netif->input(p, netif) != ERR_OK) {
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
p->user_flag = PBUF_USER_FLAG_OWNER_NULL; p->l2_owner = NULL;
pbuf_free(p); pbuf_free(p);
} }
#endif #endif

View File

@ -84,7 +84,9 @@ low_level_init(struct netif *netif)
#endif #endif
#endif #endif
/* Do whatever else is needed to initialize interface. */ #if !ESP_L2_TO_L3_COPY
netif->l2_buffer_free_notify = esp_wifi_internal_free_rx_buffer;
#endif
} }
/** /**
@ -119,6 +121,7 @@ low_level_output(struct netif *netif, struct pbuf *p)
LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug")); LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM); q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
if (q != NULL) { if (q != NULL) {
q->l2_owner = NULL;
pbuf_copy(q, p); pbuf_copy(q, p);
} else { } else {
return ERR_MEM; return ERR_MEM;
@ -154,6 +157,7 @@ wlanif_input(struct netif *netif, void *buffer, u16_t len, void* eb)
esp_wifi_internal_free_rx_buffer(eb); esp_wifi_internal_free_rx_buffer(eb);
return; return;
} }
p->l2_owner = NULL;
memcpy(p->payload, buffer, len); memcpy(p->payload, buffer, len);
esp_wifi_internal_free_rx_buffer(eb); esp_wifi_internal_free_rx_buffer(eb);
#else #else
@ -163,8 +167,8 @@ wlanif_input(struct netif *netif, void *buffer, u16_t len, void* eb)
return; return;
} }
p->payload = buffer; p->payload = buffer;
p->user_buf = eb; p->l2_owner = netif;
p->user_flag = PBUF_USER_FLAG_OWNER_WIFI; p->l2_buf = eb;
#endif #endif
/* full packet send to tcpip_thread to process */ /* full packet send to tcpip_thread to process */