trivial: Style changed files
diff --git a/libethdrivers/src/lwip.c b/libethdrivers/src/lwip.c index 2a38484..221ce62 100644 --- a/libethdrivers/src/lwip.c +++ b/libethdrivers/src/lwip.c
@@ -25,19 +25,21 @@ #include <lwip/snmp.h> #include "debug.h" -static void initialize_free_bufs(lwip_iface_t *iface) { +static void initialize_free_bufs(lwip_iface_t *iface) +{ dma_addr_t *dma_bufs = NULL; dma_bufs = malloc(sizeof(dma_addr_t) * CONFIG_LIB_ETHDRIVER_NUM_PREALLOCATED_BUFFERS); if (!dma_bufs) { goto error; } memset(dma_bufs, 0, sizeof(dma_addr_t) * CONFIG_LIB_ETHDRIVER_NUM_PREALLOCATED_BUFFERS); - iface->bufs = malloc(sizeof(dma_addr_t*) * CONFIG_LIB_ETHDRIVER_NUM_PREALLOCATED_BUFFERS); + iface->bufs = malloc(sizeof(dma_addr_t *) * CONFIG_LIB_ETHDRIVER_NUM_PREALLOCATED_BUFFERS); if (!iface->bufs) { goto error; } for (int i = 0; i < CONFIG_LIB_ETHDRIVER_NUM_PREALLOCATED_BUFFERS; i++) { - dma_bufs[i] = dma_alloc_pin(&iface->dma_man, CONFIG_LIB_ETHDRIVER_PREALLOCATED_BUF_SIZE, 1, iface->driver.dma_alignment); + dma_bufs[i] = dma_alloc_pin(&iface->dma_man, CONFIG_LIB_ETHDRIVER_PREALLOCATED_BUF_SIZE, 1, + iface->driver.dma_alignment); if (!dma_bufs[i].phys) { goto error; } @@ -61,10 +63,12 @@ iface->bufs = NULL; } -static uintptr_t lwip_allocate_rx_buf(void *iface, size_t buf_size, void **cookie) { - lwip_iface_t *lwip_iface = (lwip_iface_t*)iface; +static uintptr_t lwip_allocate_rx_buf(void *iface, size_t buf_size, void **cookie) +{ + lwip_iface_t *lwip_iface = (lwip_iface_t *)iface; if (buf_size > CONFIG_LIB_ETHDRIVER_PREALLOCATED_BUF_SIZE) { - LOG_ERROR("Requested RX buffer of size %zu which can never be fullfilled by preallocated buffers of size %d", buf_size, CONFIG_LIB_ETHDRIVER_PREALLOCATED_BUF_SIZE); + LOG_ERROR("Requested RX buffer of size %zu which can never be fullfilled by preallocated buffers of size %d", buf_size, + CONFIG_LIB_ETHDRIVER_PREALLOCATED_BUF_SIZE); return 0; } if (lwip_iface->num_free_bufs == 0) { @@ -81,24 +85,26 @@ lwip_iface->num_free_bufs--; dma_addr_t *buf = lwip_iface->bufs[lwip_iface->num_free_bufs]; ps_dma_cache_invalidate(&lwip_iface->dma_man, buf->virt, buf_size); - *cookie = (void*)buf; + *cookie = (void *)buf; return buf->phys; } -static void lwip_tx_complete(void *iface, void *cookie) { - lwip_iface_t *lwip_iface = (lwip_iface_t*)iface; +static void lwip_tx_complete(void *iface, void *cookie) +{ + lwip_iface_t *lwip_iface = (lwip_iface_t *)iface; lwip_iface->bufs[lwip_iface->num_free_bufs] = cookie; lwip_iface->num_free_bufs++; } -static void lwip_rx_complete(void *iface, unsigned int num_bufs, void **cookies, unsigned int *lens) { +static void lwip_rx_complete(void *iface, unsigned int num_bufs, void **cookies, unsigned int *lens) +{ struct pbuf *p; int len; - lwip_iface_t *lwip_iface = (lwip_iface_t*)iface; + lwip_iface_t *lwip_iface = (lwip_iface_t *)iface; int i; len = 0; for (i = 0; i < num_bufs; i++) { - ps_dma_cache_invalidate(&lwip_iface->dma_man, ((dma_addr_t*)cookies[i])->virt, lens[i]); + ps_dma_cache_invalidate(&lwip_iface->dma_man, ((dma_addr_t *)cookies[i])->virt, lens[i]); len += lens[i]; } #if ETH_PAD_SIZE @@ -126,7 +132,7 @@ unsigned int pbuf_done = 0; while (copied < len) { unsigned int next = MIN(q->len - pbuf_done, lens[buf] - buf_done); - memcpy(q->payload + pbuf_done, ((dma_addr_t*)cookies[buf])->virt + buf_done, next); + memcpy(q->payload + pbuf_done, ((dma_addr_t *)cookies[buf])->virt + buf_done, next); buf_done += next; pbuf_done += next; copied += next; @@ -164,24 +170,23 @@ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ - /* full packet send to tcpip_thread to process */ + /* full packet send to tcpip_thread to process */ if (lwip_iface->netif->input(p, lwip_iface->netif) != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } - break; + break; default: pbuf_free(p); - break; + break; } } -static err_t -ethif_link_output(struct netif *netif, struct pbuf *p) +static err_t ethif_link_output(struct netif *netif, struct pbuf *p) { - lwip_iface_t *iface = (lwip_iface_t*)netif->state; + lwip_iface_t *iface = (lwip_iface_t *)netif->state; dma_addr_t buf; struct pbuf *q; int status; @@ -200,8 +205,8 @@ dma_addr_t *orig_buf = iface->bufs[iface->num_free_bufs]; buf = *orig_buf; - char *pkt_pos = (char*)buf.virt; - for(q = p; q != NULL; q = q->next) { + char *pkt_pos = (char *)buf.virt; + for (q = p; q != NULL; q = q->next) { memcpy(pkt_pos, q->payload, q->len); pkt_pos += q->len; } @@ -215,7 +220,7 @@ unsigned int length = p->tot_len; status = iface->driver.i_fn.raw_tx(&iface->driver, 1, &buf.phys, &length, orig_buf); - switch(status) { + switch (status) { case ETHIF_TX_FAILED: lwip_tx_complete(iface, orig_buf); return ERR_WOULDBLOCK; @@ -230,8 +235,9 @@ return ERR_OK; } -static uintptr_t lwip_pbuf_allocate_rx_buf(void *iface, size_t buf_size, void **cookie) { - lwip_iface_t *lwip_iface = (lwip_iface_t*)iface; +static uintptr_t lwip_pbuf_allocate_rx_buf(void *iface, size_t buf_size, void **cookie) +{ + lwip_iface_t *lwip_iface = (lwip_iface_t *)iface; #if ETH_PAD_SIZE buf_size += ETH_PAD_SIZE; /* allow room for Ethernet padding */ #endif @@ -263,9 +269,10 @@ return phys; } -static void lwip_pbuf_tx_complete(void *iface, void *cookie) { - lwip_iface_t *lwip_iface = (lwip_iface_t*)iface; - struct pbuf *p = (struct pbuf*)cookie; +static void lwip_pbuf_tx_complete(void *iface, void *cookie) +{ + lwip_iface_t *lwip_iface = (lwip_iface_t *)iface; + struct pbuf *p = (struct pbuf *)cookie; for (; p; p = p->next) { uintptr_t loc = (uintptr_t)p->payload; uintptr_t end = (uintptr_t)p->payload + p->len; @@ -274,23 +281,24 @@ if (next > end) { next = end; } - ps_dma_unpin(&lwip_iface->dma_man, (void*)loc, next - loc); + ps_dma_unpin(&lwip_iface->dma_man, (void *)loc, next - loc); loc = next; } } pbuf_free(cookie); } -static void lwip_pbuf_rx_complete(void *iface, unsigned int num_bufs, void **cookies, unsigned int *lens) { +static void lwip_pbuf_rx_complete(void *iface, unsigned int num_bufs, void **cookies, unsigned int *lens) +{ struct pbuf *p = NULL; int i; - lwip_iface_t *lwip_iface = (lwip_iface_t*)iface; + lwip_iface_t *lwip_iface = (lwip_iface_t *)iface; assert(num_bufs > 0); /* staple all the bufs together, do it in reverse order for efficiency * of traversing pbuf chains */ for (i = num_bufs - 1; i >= 0; i--) { - struct pbuf *q = (struct pbuf*)cookies[i]; + struct pbuf *q = (struct pbuf *)cookies[i]; ps_dma_cache_invalidate(&lwip_iface->dma_man, q->payload, lens[i]); pbuf_realloc(q, lens[i]); if (p) { @@ -317,24 +325,23 @@ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ - /* full packet send to tcpip_thread to process */ + /* full packet send to tcpip_thread to process */ if (lwip_iface->netif->input(p, lwip_iface->netif) != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); LOG_INFO("failed to input\n"); pbuf_free(p); } - break; + break; default: pbuf_free(p); - break; + break; } } -static err_t -ethif_pbuf_link_output(struct netif *netif, struct pbuf *p) +static err_t ethif_pbuf_link_output(struct netif *netif, struct pbuf *p) { - lwip_iface_t *iface = (lwip_iface_t*)netif->state; + lwip_iface_t *iface = (lwip_iface_t *)netif->state; struct pbuf *q; int status; @@ -364,8 +371,8 @@ next = end; } lengths[num_frames] = next - loc; - phys[num_frames] = ps_dma_pin(&iface->dma_man, (void*)loc, lengths[num_frames]); - ps_dma_cache_clean(&iface->dma_man, (void*)loc, lengths[num_frames]); + phys[num_frames] = ps_dma_pin(&iface->dma_man, (void *)loc, lengths[num_frames]); + ps_dma_cache_clean(&iface->dma_man, (void *)loc, lengths[num_frames]); assert(phys[num_frames]); num_frames++; loc = next; @@ -377,7 +384,7 @@ #endif status = iface->driver.i_fn.raw_tx(&iface->driver, num_frames, phys, lengths, p); - switch(status) { + switch (status) { case ETHIF_TX_FAILED: lwip_pbuf_tx_complete(iface, p); return ERR_WOULDBLOCK; @@ -404,14 +411,13 @@ .allocate_rx_buf = lwip_pbuf_allocate_rx_buf }; -static err_t -ethif_init(struct netif *netif) +static err_t ethif_init(struct netif *netif) { if (netif -> state == NULL) { return ERR_ARG; } - lwip_iface_t *iface = (lwip_iface_t*)netif->state; + lwip_iface_t *iface = (lwip_iface_t *)netif->state; int mtu; iface->driver.i_fn.low_level_init(&iface->driver, netif->hwaddr, &mtu); netif->mtu = mtu; @@ -425,16 +431,18 @@ } NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, - LINK_SPEED_OF_YOUR_NETIF_IN_BPS); + LINK_SPEED_OF_YOUR_NETIF_IN_BPS); netif -> flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | - NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP; + NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP; iface->netif = netif; return ERR_OK; } -lwip_iface_t *ethif_new_lwip_driver_no_malloc(ps_io_ops_t io_ops, ps_dma_man_t *pbuf_dma, ethif_driver_init driver, void *driver_config, lwip_iface_t *iface) { +lwip_iface_t *ethif_new_lwip_driver_no_malloc(ps_io_ops_t io_ops, ps_dma_man_t *pbuf_dma, ethif_driver_init driver, + void *driver_config, lwip_iface_t *iface) +{ memset(iface, 0, sizeof(*iface)); iface->driver.cb_cookie = iface; if (pbuf_dma) { @@ -463,7 +471,9 @@ return NULL; } -lwip_iface_t *ethif_new_lwip_driver(ps_io_ops_t io_ops, ps_dma_man_t *pbuf_dma, ethif_driver_init driver, void *driver_config) { +lwip_iface_t *ethif_new_lwip_driver(ps_io_ops_t io_ops, ps_dma_man_t *pbuf_dma, ethif_driver_init driver, + void *driver_config) +{ lwip_iface_t *ret; lwip_iface_t *iface = malloc(sizeof(*iface)); if (!iface) {