From 62a534ab629a8e685f63c7f40f66855440a1103c Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Wed, 4 Sep 2024 15:38:48 +1000 Subject: [PATCH 01/18] Fix inconsistensies with network components mk snippet Signed-off-by: Courtney Darville --- network/components/network_components.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/network/components/network_components.mk b/network/components/network_components.mk index 9ed9b3fd4..d681a79c7 100644 --- a/network/components/network_components.mk +++ b/network/components/network_components.mk @@ -11,7 +11,6 @@ # Generates network_virt_rx.elf network_virt_tx.elf arp.elf copy.elf # Requires ${SDDF}/util/util.mk to build the utility library for debug output -NETWORK_COMPONENTS_DIR := $(abspath $(dir $(lastword ${MAKEFILE_LIST}))) NETWORK_IMAGES:= network_virt_rx.elf network_virt_tx.elf arp.elf copy.elf network/components/%.o: ${SDDF}/network/components/%.c ${CC} ${CFLAGS} -c -o $@ $< @@ -40,10 +39,11 @@ network/components/network_virt_%.o: ${SDDF}/network/components/virt_%.c ${LD} ${LDFLAGS} -o $@ $< ${LIBS} clean:: - rm -f network_virt_[rt]x.[od] copy.[od] arp.[od] + ${RM} -f network_virt_[rt]x.[od] copy.[od] arp.[od] clobber:: - rm -f ${IMAGES} + ${RM} -f ${NETWORK_IMAGES} + rmdir network/components network/components: mkdir -p $@ From f66940af221829c771edf50fe7fbb5253b7e9b69 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Wed, 4 Sep 2024 16:39:07 +1000 Subject: [PATCH 02/18] Create sDDF LWIP interface library Signed-off-by: Courtney Darville --- .../include/ethernet_config/ethernet_config.h | 1 + include/sddf/network/lib_sddf_lwip.h | 111 ++++++ include/sddf/network/util.h | 2 +- network/lib_sddf_lwip/lib_sddf_lwip.c | 369 ++++++++++++++++++ network/lib_sddf_lwip/lib_sddf_lwip.mk | 32 ++ 5 files changed, 514 insertions(+), 1 deletion(-) create mode 100644 include/sddf/network/lib_sddf_lwip.h create mode 100644 network/lib_sddf_lwip/lib_sddf_lwip.c create mode 100644 network/lib_sddf_lwip/lib_sddf_lwip.mk diff --git a/examples/echo_server/include/ethernet_config/ethernet_config.h b/examples/echo_server/include/ethernet_config/ethernet_config.h index 2d810c381..7a5913a80 100644 --- a/examples/echo_server/include/ethernet_config/ethernet_config.h +++ b/examples/echo_server/include/ethernet_config/ethernet_config.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #define NUM_NETWORK_CLIENTS 2 diff --git a/include/sddf/network/lib_sddf_lwip.h b/include/sddf/network/lib_sddf_lwip.h new file mode 100644 index 000000000..ac8c668a0 --- /dev/null +++ b/include/sddf/network/lib_sddf_lwip.h @@ -0,0 +1,111 @@ +/* + * Copyright 2022, UNSW + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include "lwip/pbuf.h" + +#define LINK_SPEED 1000000000 // Gigabit +#define ETHER_MTU 1500 + +/* Definitions for sDDF error constants. */ +typedef enum { + /* No error, everything OK. */ + SDDF_ERR_OK = 0, + /* Pbuf too large for sDDF buffer. */ + SDDF_ERR_PBUF = -1, + /* No buffers available. */ + SDDF_ERR_NO_BUF = -2, + /* Pbuf successfully enqueued to be sent later. */ + SDDF_ERR_ENQUEUED = -3, + /* Could not resolve error. */ + SDDF_ERR_UNHANDLED = -4 +} net_sddf_err_t; + +/** + * Function type for output of sDDF LWIP errors. + */ +typedef int (*sddf_lwip_err_output_fn)(const char *format, ...); + +/** + * Function type for netif status callback. Invoked by LWIP upon + * successfully obtaining an IP address for the network interface. + */ +typedef void (*sddf_lwip_netif_status_callback_fn)(char *ip_addr); + +/** + * Function type for handling function which is optionally invoked + * when a pbuf is unable to be sent due to no available sDDF tx buffers. + * Can be used to store pbuf until more buffers are available. + */ +typedef net_sddf_err_t (*sddf_lwip_handle_empty_tx_free_fn)(struct pbuf *p); + +/** + * Checks LWIP system timeouts. Should be invoked after every LWIP tick. + */ +void sddf_lwip_process_timeout(void); + +/** + * Transmits the provided pbuf through the sddf network system. + * + * @param p pbuf to be transmitted. + * + * @return If the pbuf is sent successfully, SDDF_ERR_OK is returned and the + * pbuf can safely be freed. If the pbuf is too large, SDDF_ERR_PBUF is + * returned. If there are no free sDDF buffers available, + * handle_empty_tx_free will be called with the pbuf, and the return value + * will be returned. + */ +net_sddf_err_t sddf_lwip_transmit_pbuf(struct pbuf *p); + +/** + * Handles the passing of incoming packets in sDDF buffers to LWIP. Must be + * called to process the sDDF RX queue each time a notification is received + * from the network virtualiser. + */ +void sddf_lwip_process_rx(void); + +/** + * Handles the sending of notifications to the network RX and TX virtualisers. + * Must be invoked at the end of each event handling loop to ensure outgoing + * buffers are processed by the virtualisers. + */ +void sddf_lwip_maybe_notify(void); + +/** + * Initialisation function for the sDDF LWIP library. Must be called prior + * to using any other library functions. + * + * @param rx_queue RX net queue handle data structure. Must be initialised + * prior to being passed to this function. + * @param tx_queue TX net queue handle data structure. Must be initialised + * prior to being passed to this function. + * @param rx_ch RX notification channel to the net RX virtualiser. + * @param tx_ch TX notification channel to the net TX virtualiser. + * @param rx_buffer_data_region virtual address of the start of the RX + * buffer region. + * @param tx_buffer_data_region virtual address of the start of the TX + * buffer region. + * @param timer_ch timer notification channel to the timer driver. + * @param mac mac address of the client. + * @param err_output function pointer to optional user provided error + * output function. Provide NULL to use default sddf_printf_. + * @param netif_callback function pointer to optional user provided netif + * status callback function. Provide NULL to use err_output to print client + * MAC address and obtained IP address. + * @param handle_empty_tx_free function pointer to optional user provided + * handling function for no available sDDF TX buffers during sending of LWIP + * pbuf. Provide NULL to leave unhandled. + */ +void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, + microkit_channel rx_ch, microkit_channel tx_ch, + uintptr_t rx_buffer_data_region, + uintptr_t tx_buffer_data_region, + microkit_channel timer_ch, + uint64_t mac, sddf_lwip_err_output_fn err_output, + sddf_lwip_netif_status_callback_fn netif_callback, + sddf_lwip_handle_empty_tx_free_fn handle_empty_tx_free); \ No newline at end of file diff --git a/include/sddf/network/util.h b/include/sddf/network/util.h index 916a56322..1c45f8d33 100644 --- a/include/sddf/network/util.h +++ b/include/sddf/network/util.h @@ -21,4 +21,4 @@ static void net_set_mac_addr(uint8_t *mac, uint64_t val) mac[3] = val >> 16 & 0xff; mac[4] = val >> 8 & 0xff; mac[5] = val & 0xff; -} \ No newline at end of file +} diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.c b/network/lib_sddf_lwip/lib_sddf_lwip.c new file mode 100644 index 000000000..94ff95542 --- /dev/null +++ b/network/lib_sddf_lwip/lib_sddf_lwip.c @@ -0,0 +1,369 @@ +/* + * Copyright 2022, UNSW + * SPDX-License-Identifier: BSD-2-Clause + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lwip/err.h" +#include "lwip/init.h" +#include "lwip/ip4_addr.h" +#include "netif/etharp.h" +#include "lwip/pbuf.h" +#include "lwip/netif.h" +#include "lwip/snmp.h" +#include "lwip/sys.h" +#include "lwip/timeouts.h" +#include "lwip/dhcp.h" + +typedef struct lwip_state { + /* LWIP network interface struct. */ + struct netif netif; + /* MAC address of client. */ + uint64_t mac; + /* Output function used to print error messages. */ + sddf_lwip_err_output_fn err_output; + /* Callback function to be invoked when ip address is obtained. */ + sddf_lwip_netif_status_callback_fn netif_callback; + /* Function that optionally handles when no free tx buffers available. */ + sddf_lwip_handle_empty_tx_free_fn handle_empty_tx_free; +} lwip_state_t; + +typedef struct sddf_state { + /* sddf net rx queue handle. */ + net_queue_handle_t rx_queue; + /* sddf net tx queue handle. */ + net_queue_handle_t tx_queue; + /* sddf channel for net rx virt. */ + microkit_channel rx_ch; + /* sddf channel for net tx virt. */ + microkit_channel tx_ch; + /* Base address of data region containing rx buffers. */ + uintptr_t rx_buffer_data_region; + /* Base address of data region containing tx buffers. */ + uintptr_t tx_buffer_data_region; + /* Boolean indicating whether buffers have been given to rx virt. */ + bool notify_rx; + /* Boolean indicating whether buffers have been given to tx virt. */ + bool notify_tx; + /* sddf channel for timer. */ + microkit_channel timer_ch; +} sddf_state_t; + +/* Wrapper over custom_pbuf structure to keep track of buffer's offset into data region. */ +typedef struct pbuf_custom_offset { + struct pbuf_custom custom; + uint64_t offset; +} pbuf_custom_offset_t; + +LWIP_MEMPOOL_DECLARE( + RX_POOL, + MAX_NUM_BUFFS * 2, + sizeof(struct pbuf_custom_offset), + "Zero-copy RX pool" +); + +lwip_state_t lwip_state; +sddf_state_t sddf_state; + +/** + * Helper function to convert sddf errors to lwip errors. + * + * @param sddf_err sddf error. + * + * @return Equivalent lwip error. + */ +static err_t sddf_err_to_lwip_err(net_sddf_err_t sddf_err) { + switch (sddf_err) { + case SDDF_ERR_OK: + return ERR_OK; + case SDDF_ERR_PBUF: + return ERR_BUF; + case SDDF_ERR_NO_BUF: + return ERR_MEM; + case SDDF_ERR_ENQUEUED: + return ERR_OK; + case SDDF_ERR_UNHANDLED: + return ERR_MEM; + } + return ERR_ARG; +} + +/** + * Default netif status callback function. Prints client MAC address and + * obtained ip address. + * + * @param ip_addr Obtained ip address as a string. + */ +static void netif_status_callback_default(char *ip_addr) { + uint8_t *mac = lwip_state.netif.hwaddr; + lwip_state.err_output("LWIP|NOTICE: DHCP request for mac " + "%02lx:%02lx:%02lx:%02lx:%02lx:%02lx " + "returned ip address: %s\n", mac[0], + mac[1], mac[2], mac[3], mac[4], mac[5], + ip_addr); +} + +/** + * Default handling function to be called during transmission if tx free + * queue is empty. + * + * @param p pbuf that could not be sent due to queue being empty. + * + * @return Simply returns the sddf error indicating nothing was done. + */ +static net_sddf_err_t handle_empty_tx_free_default(struct pbuf *p) { + return SDDF_ERR_UNHANDLED; +} + +/** + * Returns current time from the timer. + */ +uint32_t sys_now(void) { + return sddf_timer_time_now(sddf_state.timer_ch) / NS_IN_MS; +} + +void sddf_lwip_process_timeout() { + sys_check_timeouts(); +} + +/** + * Free a pbuf. This also returns the underlying sddf buffer to the receive free ring. + * + * @param p pbuf to free. + */ +static void interface_free_buffer(struct pbuf *p) { + SYS_ARCH_DECL_PROTECT(old_level); + pbuf_custom_offset_t *custom_pbuf_offset = (pbuf_custom_offset_t *)p; + SYS_ARCH_PROTECT(old_level); + net_buff_desc_t buffer = {custom_pbuf_offset->offset, 0}; + int err = net_enqueue_free(&(sddf_state.rx_queue), buffer); + assert(!err); + sddf_state.notify_rx = true; + LWIP_MEMPOOL_FREE(RX_POOL, custom_pbuf_offset); + SYS_ARCH_UNPROTECT(old_level); +} + +/** + * Create a pbuf structure to pass to the network interface. + * + * @param offset offset into the data region of the buffer to be passed. + * @param length length of data. + * + * @return the newly created pbuf. Can be cast to pbuf_custom. + */ +static struct pbuf *create_interface_buffer(uint64_t offset, size_t length) { + pbuf_custom_offset_t *custom_pbuf_offset = (pbuf_custom_offset_t *) LWIP_MEMPOOL_ALLOC(RX_POOL); + custom_pbuf_offset->offset = offset; + custom_pbuf_offset->custom.custom_free_function = interface_free_buffer; + + return pbuf_alloced_custom( + PBUF_RAW, + length, + PBUF_REF, + &custom_pbuf_offset->custom, + (void *)(offset + sddf_state.rx_buffer_data_region), + NET_BUFFER_SIZE + ); +} + +/** + * Copy a pbuf into an sddf buffer and insert it into the transmit active queue. + * + * @param netif lwip network interface state. + * @param p pbuf to be transmitted. + * + * @return If the pbuf is sent, ERR_OK is returned and the pbuf can safely be + * freed. If the pbuf is too large ERR_MEM is returned. If there are no free + * sddf buffers available, handle_empty_tx_free will be called with the pbuf, + * and the equivalent lwip error will be returned. + */ +static err_t lwip_eth_send(struct netif *netif, struct pbuf *p) { + if (p->tot_len > NET_BUFFER_SIZE) { + lwip_state.err_output("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", + p->tot_len, NET_BUFFER_SIZE); + return ERR_MEM; + } + + if (net_queue_empty_free(&sddf_state.tx_queue)) { + return sddf_err_to_lwip_err(lwip_state.handle_empty_tx_free(p)); + } + + net_buff_desc_t buffer; + int err = net_dequeue_free(&sddf_state.tx_queue, &buffer); + assert(!err); + + uintptr_t frame = buffer.io_or_offset + sddf_state.tx_buffer_data_region; + uint16_t copied = 0; + for (struct pbuf *curr = p; curr != NULL; curr = curr->next) { + memcpy((void *)(frame + copied), curr->payload, curr->len); + copied += curr->len; + } + + buffer.len = copied; + err = net_enqueue_active(&sddf_state.tx_queue, buffer); + assert(!err); + + sddf_state.notify_tx = true; + + return ERR_OK; +} + +net_sddf_err_t sddf_lwip_transmit_pbuf(struct pbuf *p) { + if (p->tot_len > NET_BUFFER_SIZE) { + lwip_state.err_output("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", + p->tot_len, NET_BUFFER_SIZE); + return SDDF_ERR_PBUF; + } + + if (net_queue_empty_free(&sddf_state.tx_queue)) { + return lwip_state.handle_empty_tx_free(p); + } + + err_t err = lwip_eth_send(&lwip_state.netif, p); + assert(!err); + + return SDDF_ERR_OK; +} + +void sddf_lwip_process_rx(void) { + bool reprocess = true; + while (reprocess) { + while (!net_queue_empty_active(&sddf_state.rx_queue)) { + net_buff_desc_t buffer; + int err = net_dequeue_active(&sddf_state.rx_queue, &buffer); + assert(!err); + + struct pbuf *p = create_interface_buffer(buffer.io_or_offset, buffer.len); + assert(p != NULL); + if (lwip_state.netif.input(p, &lwip_state.netif) != ERR_OK) { + lwip_state.err_output("LWIP|ERROR: unkown error inputting pbuf into network stack\n"); + pbuf_free(p); + } + } + + net_request_signal_active(&sddf_state.rx_queue); + reprocess = false; + + if (!net_queue_empty_active(&sddf_state.rx_queue)) { + net_cancel_signal_active(&sddf_state.rx_queue); + reprocess = true; + } + } +} + +/** + * Initialise the network interface data structure. + * + * @param netif network interface data structure. + */ +static err_t ethernet_init(struct netif *netif) { + if (netif->state == NULL) { + return ERR_ARG; + } + + net_set_mac_addr(netif->hwaddr, lwip_state.mac); + netif->mtu = ETHER_MTU; + netif->hwaddr_len = ETHARP_HWADDR_LEN; + netif->output = etharp_output; + netif->linkoutput = lwip_eth_send; + NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED); + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP; + + return ERR_OK; +} + +/** + * Network interface callback function invoked when DHCP packets are received. + * If an ip address is successfully obtained, the provided netif_callback + * function will be invoked with the ip address as a string. + * + * @param netif network interface data structure. + */ +static void netif_status_callback(struct netif *netif) { + if (dhcp_supplied_address(netif)) { + char ip4_str[IP4ADDR_STRLEN_MAX]; + lwip_state.netif_callback(ip4addr_ntoa_r(netif_ip4_addr(netif), ip4_str, IP4ADDR_STRLEN_MAX)); + } +} + +void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, + microkit_channel rx_ch, microkit_channel tx_ch, + uintptr_t rx_buffer_data_region, + uintptr_t tx_buffer_data_region, + microkit_channel timer_ch, + uint64_t mac, sddf_lwip_err_output_fn err_output, + sddf_lwip_netif_status_callback_fn netif_callback, + sddf_lwip_handle_empty_tx_free_fn handle_empty_tx_free) { + /* Initialise sddf state */ + sddf_state.rx_queue = rx_queue; + sddf_state.tx_queue = tx_queue; + sddf_state.rx_ch = rx_ch; + sddf_state.tx_ch = tx_ch; + sddf_state.rx_buffer_data_region = rx_buffer_data_region; + sddf_state.tx_buffer_data_region = tx_buffer_data_region; + sddf_state.timer_ch = timer_ch; + + /* Initialise lwip state */ + lwip_state.mac = mac; + lwip_state.err_output = (err_output == NULL)? sddf_printf_: err_output; + lwip_state.netif_callback = (netif_callback == NULL)? netif_status_callback_default: netif_callback; + lwip_state.handle_empty_tx_free = (handle_empty_tx_free == NULL)? handle_empty_tx_free_default: handle_empty_tx_free; + + lwip_init(); + + LWIP_MEMPOOL_INIT(RX_POOL); + + /* Set dummy IP configuration values to get lwIP bootstrapped */ + struct ip4_addr netmask, ipaddr, gw, multicast; + ipaddr_aton("0.0.0.0", &gw); + ipaddr_aton("0.0.0.0", &ipaddr); + ipaddr_aton("0.0.0.0", &multicast); + ipaddr_aton("255.255.255.0", &netmask); + + lwip_state.netif.name[0] = 'e'; + lwip_state.netif.name[1] = '0'; + + if (!netif_add(&(lwip_state.netif), &ipaddr, &netmask, &gw, (void *)&lwip_state, + ethernet_init, ethernet_input)) { + lwip_state.err_output("LWIP|ERROR: Netif add returned NULL\n"); + } + + netif_set_default(&(lwip_state.netif)); + netif_set_status_callback(&(lwip_state.netif), netif_status_callback); + netif_set_up(&(lwip_state.netif)); + + if (dhcp_start(&(lwip_state.netif))) { + lwip_state.err_output("LWIP|ERROR: failed to start DHCP negotiation\n"); + } +} + +void sddf_lwip_maybe_notify() { + if (sddf_state.notify_rx && net_require_signal_free(&sddf_state.rx_queue)) { + net_cancel_signal_free(&sddf_state.rx_queue); + sddf_state.notify_rx = false; + if (!microkit_have_signal) { + microkit_deferred_notify(sddf_state.rx_ch); + } else if (microkit_signal_cap != BASE_OUTPUT_NOTIFICATION_CAP + sddf_state.rx_ch) { + microkit_notify(sddf_state.rx_ch); + } + } + + if (sddf_state.notify_tx && net_require_signal_active(&sddf_state.tx_queue)) { + net_cancel_signal_active(&sddf_state.tx_queue); + sddf_state.notify_tx = false; + if (!microkit_have_signal) { + microkit_deferred_notify(sddf_state.tx_ch); + } else if (microkit_signal_cap != BASE_OUTPUT_NOTIFICATION_CAP + sddf_state.tx_ch) { + microkit_notify(sddf_state.tx_ch); + } + } +} diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.mk b/network/lib_sddf_lwip/lib_sddf_lwip.mk new file mode 100644 index 000000000..7f80c39bc --- /dev/null +++ b/network/lib_sddf_lwip/lib_sddf_lwip.mk @@ -0,0 +1,32 @@ +# +# Copyright 2022, UNSW +# +# SPDX-License-Identifier: BSD-2-Clause +# + +ifeq ($(strip $(MAX_NUM_BUFFS)),) +$(error MAX_NUM_BUFFS must be specified) +endif + +CFLAGS += -DMAX_NUM_BUFFS=$(MAX_NUM_BUFFS) + +LIB_SDDF_LWIP_DIR := network/lib_sddf_lwip +LIB_SDDF_LWIP_FILES := $(addprefix ${LIB_SDDF_LWIP_DIR}/, lib_sddf_lwip.c) +LIB_SDDF_LWIP_OBJS := $(LIB_SDDF_LWIP_FILES:.c=.o) + +${LIB_SDDF_LWIP_OBJS}: | ${LIB_SDDF_LWIP_DIR} ${CHECK_FLAGS_BOARD_MD5} +${LIB_SDDF_LWIP_DIR}: + mkdir -p $@ + +lib_sddf_lwip.a: ${LIB_SDDF_LWIP_OBJS} + ${AR} rv $@ $^ + ${RANLIB} $@ + +clean:: + ${RM} -f ${LIB_SDDF_LWIP_OBJS} ${LIB_SDDF_LWIP_OBJS:.o=.d} + +clobber:: clean + ${RM} -f lib_sddf_lwip.a + rmdir ${LIB_SDDF_LWIP_DIR} + +-include ${LIB_SDDF_LWIP_OBJS:.o=.d} From c4646bf741897bced5950b1a3b17d7de5eecbcec Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Wed, 4 Sep 2024 17:29:58 +1000 Subject: [PATCH 03/18] Convert echo servers to use lib sddf_lwip Signed-off-by: Courtney Darville --- .../board/imx8mm_evk/echo_server.system | 4 +- .../board/maaxboard/echo_server.system | 4 +- .../board/odroidc4/echo_server.system | 4 +- .../qemu_virt_aarch64/echo_server.system | 4 +- examples/echo_server/echo.c | 165 ++++++++ examples/echo_server/echo.h | 3 - examples/echo_server/echo.mk | 33 +- examples/echo_server/lwip.c | 395 ------------------ 8 files changed, 190 insertions(+), 422 deletions(-) create mode 100644 examples/echo_server/echo.c delete mode 100644 examples/echo_server/lwip.c diff --git a/examples/echo_server/board/imx8mm_evk/echo_server.system b/examples/echo_server/board/imx8mm_evk/echo_server.system index 264e4e867..f4c9dd681 100644 --- a/examples/echo_server/board/imx8mm_evk/echo_server.system +++ b/examples/echo_server/board/imx8mm_evk/echo_server.system @@ -164,7 +164,7 @@ - + @@ -181,7 +181,7 @@ - + diff --git a/examples/echo_server/board/maaxboard/echo_server.system b/examples/echo_server/board/maaxboard/echo_server.system index 05e1d7684..a26891f98 100644 --- a/examples/echo_server/board/maaxboard/echo_server.system +++ b/examples/echo_server/board/maaxboard/echo_server.system @@ -164,7 +164,7 @@ - + @@ -181,7 +181,7 @@ - + diff --git a/examples/echo_server/board/odroidc4/echo_server.system b/examples/echo_server/board/odroidc4/echo_server.system index 74998d981..001b4f9c8 100644 --- a/examples/echo_server/board/odroidc4/echo_server.system +++ b/examples/echo_server/board/odroidc4/echo_server.system @@ -164,7 +164,7 @@ - + @@ -181,7 +181,7 @@ - + diff --git a/examples/echo_server/board/qemu_virt_aarch64/echo_server.system b/examples/echo_server/board/qemu_virt_aarch64/echo_server.system index 1cacbb3c9..8a859f46a 100644 --- a/examples/echo_server/board/qemu_virt_aarch64/echo_server.system +++ b/examples/echo_server/board/qemu_virt_aarch64/echo_server.system @@ -163,7 +163,7 @@ - + @@ -180,7 +180,7 @@ - + diff --git a/examples/echo_server/echo.c b/examples/echo_server/echo.c new file mode 100644 index 000000000..f53d3d265 --- /dev/null +++ b/examples/echo_server/echo.c @@ -0,0 +1,165 @@ +/* + * Copyright 2022, UNSW + * SPDX-License-Identifier: BSD-2-Clause + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lwip/pbuf.h" + +#include "echo.h" + +#define SERIAL_TX_CH 0 +#define TIMER 1 +#define RX_CH 2 +#define TX_CH 3 + +char *serial_tx_data; +serial_queue_t *serial_tx_queue; +serial_queue_handle_t serial_tx_queue_handle; + +net_queue_t *rx_free; +net_queue_t *rx_active; +net_queue_t *tx_free; +net_queue_t *tx_active; +uintptr_t rx_buffer_data_region; +uintptr_t tx_buffer_data_region; + +net_queue_handle_t net_rx_handle; +net_queue_handle_t net_tx_handle; + +#define LWIP_TICK_MS 100 + +struct pbuf *head; +struct pbuf *tail; + +/** + * Netif status callback function that output's client's Microkit name and + * obtained IP address. + * + * @param ip_addr ip address of the client. + */ +void netif_status_callback(char *ip_addr) { + sddf_printf("DHCP request finished, IP address for netif %s is: %s\n", microkit_name, ip_addr); +} + +/** + * Sets a timeout for the next lwip tick. + */ +void set_timeout(void) { + sddf_timer_set_timeout(TIMER, LWIP_TICK_MS * NS_IN_MS); +} + +/** + * Stores a pbuf to be transmitted upon available transmit buffers. + * + * @param p pbuf to be stored. + */ +net_sddf_err_t enqueue_pbufs(struct pbuf *p) +{ + /* Indicate to the tx virt that we wish to be notified about free tx buffers */ + net_request_signal_free(&net_tx_handle); + + if (head == NULL) { + head = p; + } else { + tail->next_chain = p; + } + tail = p; + + /* Increment reference count to ensure this pbuf is not freed by lwip */ + pbuf_ref(p); + + return SDDF_ERR_OK; +} + +void transmit(void) +{ + bool reprocess = true; + while (reprocess) { + while (head != NULL && !net_queue_empty_free(&net_tx_handle)) { + net_sddf_err_t err = sddf_lwip_transmit_pbuf(head); + if (err == SDDF_ERR_PBUF) { + sddf_dprintf("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", + head->tot_len, NET_BUFFER_SIZE); + } else if (err != SDDF_ERR_OK) { + sddf_dprintf("LWIP|ERROR: unkown error when trying to send pbuf %p\n", head); + } + + struct pbuf *temp = head; + head = temp->next_chain; + if (head == NULL) { + tail = NULL; + } + pbuf_free(temp); + } + + /* Only request a signal if there are more pending pbufs to send */ + if (head == NULL || !net_queue_empty_free(&net_tx_handle)) { + net_cancel_signal_free(&net_tx_handle); + } else { + net_request_signal_free(&net_tx_handle); + } + reprocess = false; + + if (head != NULL && !net_queue_empty_free(&net_tx_handle)) { + net_cancel_signal_free(&net_tx_handle); + reprocess = true; + } + } +} + +void init(void) +{ + serial_cli_queue_init_sys(microkit_name, NULL, NULL, NULL, &serial_tx_queue_handle, serial_tx_queue, serial_tx_data); + serial_putchar_init(SERIAL_TX_CH, &serial_tx_queue_handle); + + size_t rx_size, tx_size; + net_cli_queue_size(microkit_name, &rx_size, &tx_size); + net_queue_init(&net_rx_handle, rx_free, rx_active, rx_size); + net_queue_init(&net_tx_handle, tx_free, tx_active, tx_size); + net_buffers_init(&net_tx_handle, 0); + + sddf_lwip_init(net_rx_handle, net_tx_handle, RX_CH, TX_CH, rx_buffer_data_region, tx_buffer_data_region, TIMER, + net_cli_mac_addr(microkit_name), NULL, netif_status_callback, enqueue_pbufs); + set_timeout(); + + setup_udp_socket(); + setup_utilization_socket(); + setup_tcp_socket(); + + sddf_lwip_maybe_notify(); +} + +void notified(microkit_channel ch) +{ + switch (ch) { + case RX_CH: + sddf_lwip_process_rx(); + break; + case TIMER: + sddf_lwip_process_timeout(); + set_timeout(); + break; + case TX_CH: + transmit(); + break; + case SERIAL_TX_CH: + break; + default: + sddf_dprintf("LWIP|LOG: received notification on unexpected channel: %u\n", ch); + break; + } + + sddf_lwip_maybe_notify(); +} diff --git a/examples/echo_server/echo.h b/examples/echo_server/echo.h index f514c979c..066e22365 100644 --- a/examples/echo_server/echo.h +++ b/examples/echo_server/echo.h @@ -9,9 +9,6 @@ #define UTILIZATION_PORT 1236 #define TCP_ECHO_PORT 1237 -#define LINK_SPEED 1000000000 // Gigabit -#define ETHER_MTU 1500 - int setup_udp_socket(void); int setup_utilization_socket(void); int setup_tcp_socket(void); diff --git a/examples/echo_server/echo.mk b/examples/echo_server/echo.mk index bf5e3a67c..0434cf57a 100644 --- a/examples/echo_server/echo.mk +++ b/examples/echo_server/echo.mk @@ -7,17 +7,17 @@ QEMU := qemu-system-aarch64 MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit -ECHO_SERVER:=${SDDF}/examples/echo_server -LWIPDIR:=network/ipstacks/lwip/src -BENCHMARK:=$(SDDF)/benchmark -UTIL:=$(SDDF)/util -ETHERNET_DRIVER:=$(SDDF)/drivers/network/$(DRIV_DIR) -ETHERNET_CONFIG_INCLUDE:=${ECHO_SERVER}/include/ethernet_config +ECHO_SERVER := ${SDDF}/examples/echo_server +LWIPDIR := network/ipstacks/lwip/src +BENCHMARK := $(SDDF)/benchmark +UTIL := $(SDDF)/util +ETHERNET_DRIVER := $(SDDF)/drivers/network/$(DRIV_DIR) +ETHERNET_CONFIG_INCLUDE := ${ECHO_SERVER}/include/ethernet_config SERIAL_COMPONENTS := $(SDDF)/serial/components UART_DRIVER := $(SDDF)/drivers/serial/$(UART_DRIV_DIR) -SERIAL_CONFIG_INCLUDE:=${ECHO_SERVER}/include/serial_config +SERIAL_CONFIG_INCLUDE := ${ECHO_SERVER}/include/serial_config TIMER_DRIVER:=$(SDDF)/drivers/timer/$(TIMER_DRV_DIR) -NETWORK_COMPONENTS:=$(SDDF)/network/components +NETWORK_COMPONENTS := $(SDDF)/network/components BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) SYSTEM_FILE := ${ECHO_SERVER}/board/$(MICROKIT_BOARD)/echo_server.system @@ -26,7 +26,7 @@ REPORT_FILE := report.txt vpath %.c ${SDDF} ${ECHO_SERVER} -IMAGES := eth_driver.elf lwip.elf benchmark.elf idle.elf network_virt_rx.elf\ +IMAGES := eth_driver.elf echo.elf benchmark.elf idle.elf network_virt_rx.elf\ network_virt_tx.elf copy.elf timer_driver.elf uart_driver.elf serial_virt_tx.elf CFLAGS := -mcpu=$(CPU) \ @@ -41,14 +41,13 @@ CFLAGS := -mcpu=$(CPU) \ -I${ETHERNET_CONFIG_INCLUDE} \ -I$(SERIAL_CONFIG_INCLUDE) \ -I${SDDF}/$(LWIPDIR)/include \ - -I${SDDF}/$(LWIPDIR)/include/ipv4 \ -MD \ -MP LDFLAGS := -L$(BOARD_DIR)/lib -L${LIBC} LIBS := --start-group -lmicrokit -Tmicrokit.ld -lc libsddf_util_debug.a --end-group -CHECK_FLAGS_BOARD_MD5:=.board_cflags-$(shell echo -- ${CFLAGS} ${BOARD} ${MICROKIT_CONFIG} | shasum | sed 's/ *-//') +CHECK_FLAGS_BOARD_MD5 := .board_cflags-$(shell echo -- ${CFLAGS} ${BOARD} ${MICROKIT_CONFIG} | shasum | sed 's/ *-//') ${CHECK_FLAGS_BOARD_MD5}: -rm -f .board_cflags-* @@ -64,17 +63,16 @@ include ${SDDF}/${LWIPDIR}/Filelists.mk NETIFFILES:=$(LWIPDIR)/netif/ethernet.c # LWIPFILES: All the above. -LWIPFILES=lwip.c $(COREFILES) $(CORE4FILES) $(NETIFFILES) -LWIP_OBJS := $(LWIPFILES:.c=.o) lwip.o utilization_socket.o \ +LWIPFILES = echo.c $(COREFILES) $(CORE4FILES) $(NETIFFILES) +LWIP_OBJS := $(LWIPFILES:.c=.o) echo.o utilization_socket.o \ udp_echo_socket.o tcp_echo_socket.o -OBJS := $(LWIP_OBJS) -DEPS := $(filter %.d,$(OBJS:.o=.d)) +DEPS := $(filter %.d,$(LWIP_OBJS:.o=.d)) all: loader.img ${LWIP_OBJS}: ${CHECK_FLAGS_BOARD_MD5} -lwip.elf: $(LWIP_OBJS) libsddf_util.a +echo.elf: $(LWIP_OBJS) libsddf_util.a lib_sddf_lwip.a $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ LWIPDIRS := $(addprefix ${LWIPDIR}/, core/ipv4 netif api) @@ -92,6 +90,9 @@ ${IMAGE_FILE} $(REPORT_FILE): $(IMAGES) $(SYSTEM_FILE) include ${SDDF}/util/util.mk include ${SDDF}/network/components/network_components.mk +# Specify how many pbufs sDDF LWIP library requires for all clients +MAX_NUM_BUFFS=512 +include ${SDDF}/network/lib_sddf_lwip/lib_sddf_lwip.mk include ${ETHERNET_DRIVER}/eth_driver.mk include ${BENCHMARK}/benchmark.mk include ${TIMER_DRIVER}/timer_driver.mk diff --git a/examples/echo_server/lwip.c b/examples/echo_server/lwip.c deleted file mode 100644 index 7f21022cd..000000000 --- a/examples/echo_server/lwip.c +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright 2022, UNSW - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "lwip/init.h" -#include "netif/etharp.h" -#include "lwip/pbuf.h" -#include "lwip/netif.h" -#include "lwip/stats.h" -#include "lwip/snmp.h" -#include "lwip/sys.h" -#include "lwip/timeouts.h" -#include "lwip/dhcp.h" - -#include "echo.h" - -#define SERIAL_TX_CH 0 -#define TIMER 1 -#define RX_CH 2 -#define TX_CH 3 - -char *serial_tx_data; -serial_queue_t *serial_tx_queue; -serial_queue_handle_t serial_tx_queue_handle; - -#define LWIP_TICK_MS 100 -#define NUM_PBUFFS NET_MAX_CLIENT_QUEUE_SIZE - -net_queue_t *rx_free; -net_queue_t *rx_active; -net_queue_t *tx_free; -net_queue_t *tx_active; -uintptr_t rx_buffer_data_region; -uintptr_t tx_buffer_data_region; - -/* Booleans to indicate whether packets have been enqueued during notification handling */ -static bool notify_tx; -static bool notify_rx; - -/* Wrapper over custom_pbuf structure to keep track of buffer offset */ -typedef struct pbuf_custom_offset { - struct pbuf_custom custom; - uint64_t offset; -} pbuf_custom_offset_t; - -LWIP_MEMPOOL_DECLARE( - RX_POOL, - NUM_PBUFFS * 2, - sizeof(struct pbuf_custom_offset), - "Zero-copy RX pool" -); - -typedef struct state { - struct netif netif; - uint8_t mac[ETH_HWADDR_LEN]; - net_queue_handle_t rx_queue; - net_queue_handle_t tx_queue; - struct pbuf *head; - struct pbuf *tail; -} state_t; - -state_t state; - -void set_timeout(void) -{ - sddf_timer_set_timeout(TIMER, LWIP_TICK_MS * NS_IN_MS); -} - -uint32_t sys_now(void) -{ - return sddf_timer_time_now(TIMER) / NS_IN_MS; -} - -/** - * Free a pbuf. This also returns the underlying buffer to the receive free ring. - * - * @param p pbuf to free. - */ -static void interface_free_buffer(struct pbuf *p) -{ - SYS_ARCH_DECL_PROTECT(old_level); - pbuf_custom_offset_t *custom_pbuf_offset = (pbuf_custom_offset_t *)p; - SYS_ARCH_PROTECT(old_level); - net_buff_desc_t buffer = {custom_pbuf_offset->offset, 0}; - int err = net_enqueue_free(&(state.rx_queue), buffer); - assert(!err); - notify_rx = true; - LWIP_MEMPOOL_FREE(RX_POOL, custom_pbuf_offset); - SYS_ARCH_UNPROTECT(old_level); -} - -/** - * Create a pbuf structure to pass to the network interface. - * - * @param state client state data. - * @param buffer shared buffer containing the data. - * @param length length of data. - * - * @return the newly created pbuf. Can be cast to pbuf_custom. - */ -static struct pbuf *create_interface_buffer(uint64_t offset, size_t length) -{ - pbuf_custom_offset_t *custom_pbuf_offset = (pbuf_custom_offset_t *) LWIP_MEMPOOL_ALLOC(RX_POOL); - custom_pbuf_offset->offset = offset; - custom_pbuf_offset->custom.custom_free_function = interface_free_buffer; - - return pbuf_alloced_custom( - PBUF_RAW, - length, - PBUF_REF, - &custom_pbuf_offset->custom, - (void *)(offset + rx_buffer_data_region), - NET_BUFFER_SIZE - ); -} - -/** - * Stores a pbuf to be transmitted upon available transmit buffers. - * - * @param p pbuf to be stored. - */ -void enqueue_pbufs(struct pbuf *p) -{ - /* Indicate to the multiplexer that we require transmit free buffers */ - net_request_signal_free(&state.tx_queue); - - if (state.head == NULL) { - state.head = p; - } else { - state.tail->next_chain = p; - } - state.tail = p; - - /* Increment refernce count to ensure this pbuf is not freed by lwip */ - pbuf_ref(p); -} - -/** - * Insert pbuf into transmit active queue. If no free buffers available or transmit active queue is full, - * stores pbuf to be sent upon buffers becoming available. - * */ -static err_t lwip_eth_send(struct netif *netif, struct pbuf *p) -{ - if (p->tot_len > NET_BUFFER_SIZE) { - sddf_dprintf("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", p->tot_len, NET_BUFFER_SIZE); - return ERR_MEM; - } - - if (net_queue_empty_free(&state.tx_queue)) { - enqueue_pbufs(p); - return ERR_OK; - } - - net_buff_desc_t buffer; - int err = net_dequeue_free(&state.tx_queue, &buffer); - assert(!err); - - uintptr_t frame = buffer.io_or_offset + tx_buffer_data_region; - uint16_t copied = 0; - for (struct pbuf *curr = p; curr != NULL; curr = curr->next) { - memcpy((void *)(frame + copied), curr->payload, curr->len); - copied += curr->len; - } - - buffer.len = copied; - err = net_enqueue_active(&state.tx_queue, buffer); - assert(!err); - - notify_tx = true; - - return ERR_OK; -} - -void transmit(void) -{ - bool reprocess = true; - while (reprocess) { - while (state.head != NULL && !net_queue_empty_free(&state.tx_queue)) { - err_t err = lwip_eth_send(&state.netif, state.head); - if (err == ERR_MEM) { - sddf_dprintf("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", state.head->tot_len, - NET_BUFFER_SIZE); - } else if (err != ERR_OK) { - sddf_dprintf("LWIP|ERROR: unkown error when trying to send pbuf %p\n", state.head); - } - - struct pbuf *temp = state.head; - state.head = temp->next_chain; - if (state.head == NULL) { - state.tail = NULL; - } - pbuf_free(temp); - } - - /* Only request a signal if no more pbufs enqueud to send */ - if (state.head == NULL || !net_queue_empty_free(&state.tx_queue)) { - net_cancel_signal_free(&state.tx_queue); - } else { - net_request_signal_free(&state.tx_queue); - } - reprocess = false; - - if (state.head != NULL && !net_queue_empty_free(&state.tx_queue)) { - net_cancel_signal_free(&state.tx_queue); - reprocess = true; - } - } -} - -void receive(void) -{ - bool reprocess = true; - while (reprocess) { - while (!net_queue_empty_active(&state.rx_queue)) { - net_buff_desc_t buffer; - int err = net_dequeue_active(&state.rx_queue, &buffer); - assert(!err); - - struct pbuf *p = create_interface_buffer(buffer.io_or_offset, buffer.len); - assert(p != NULL); - if (state.netif.input(p, &state.netif) != ERR_OK) { - sddf_dprintf("LWIP|ERROR: unkown error inputting pbuf into network stack\n"); - pbuf_free(p); - } - } - - net_request_signal_active(&state.rx_queue); - reprocess = false; - - if (!net_queue_empty_active(&state.rx_queue)) { - net_cancel_signal_active(&state.rx_queue); - reprocess = true; - } - } -} - -/** - * Initialise the network interface data structure. - * - * @param netif network interface data structuer. - */ -static err_t ethernet_init(struct netif *netif) -{ - if (netif->state == NULL) { - return ERR_ARG; - } - state_t *data = netif->state; - - netif->hwaddr[0] = data->mac[0]; - netif->hwaddr[1] = data->mac[1]; - netif->hwaddr[2] = data->mac[2]; - netif->hwaddr[3] = data->mac[3]; - netif->hwaddr[4] = data->mac[4]; - netif->hwaddr[5] = data->mac[5]; - netif->mtu = ETHER_MTU; - netif->hwaddr_len = ETHARP_HWADDR_LEN; - netif->output = etharp_output; - netif->linkoutput = lwip_eth_send; - NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED); - netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP; - return ERR_OK; -} - -/* Callback function that prints DHCP supplied IP address. */ -static void netif_status_callback(struct netif *netif) -{ - if (dhcp_supplied_address(netif)) { - sddf_printf("LWIP|NOTICE: DHCP request for %s returned IP address: %s\n", microkit_name, - ip4addr_ntoa(netif_ip4_addr(netif))); - } -} - -void init(void) -{ - serial_cli_queue_init_sys(microkit_name, NULL, NULL, NULL, &serial_tx_queue_handle, serial_tx_queue, serial_tx_data); - serial_putchar_init(SERIAL_TX_CH, &serial_tx_queue_handle); - - size_t rx_size, tx_size; - net_cli_queue_size(microkit_name, &rx_size, &tx_size); - net_queue_init(&state.rx_queue, rx_free, rx_active, rx_size); - net_queue_init(&state.tx_queue, tx_free, tx_active, tx_size); - net_buffers_init(&state.tx_queue, 0); - - lwip_init(); - set_timeout(); - - LWIP_MEMPOOL_INIT(RX_POOL); - - uint64_t mac_addr = net_cli_mac_addr(microkit_name); - net_set_mac_addr(state.mac, mac_addr); - - /* Set dummy IP configuration values to get lwIP bootstrapped */ - struct ip4_addr netmask, ipaddr, gw, multicast; - ipaddr_aton("0.0.0.0", &gw); - ipaddr_aton("0.0.0.0", &ipaddr); - ipaddr_aton("0.0.0.0", &multicast); - ipaddr_aton("255.255.255.0", &netmask); - - state.netif.name[0] = 'e'; - state.netif.name[1] = '0'; - - if (!netif_add(&(state.netif), &ipaddr, &netmask, &gw, (void *)&state, - ethernet_init, ethernet_input)) { - sddf_dprintf("LWIP|ERROR: Netif add returned NULL\n"); - } - - netif_set_default(&(state.netif)); - netif_set_status_callback(&(state.netif), netif_status_callback); - netif_set_up(&(state.netif)); - - if (dhcp_start(&(state.netif))) { - sddf_dprintf("LWIP|ERROR: failed to start DHCP negotiation\n"); - } - - setup_udp_socket(); - setup_utilization_socket(); - setup_tcp_socket(); - - if (notify_rx && net_require_signal_free(&state.rx_queue)) { - net_cancel_signal_free(&state.rx_queue); - notify_rx = false; - if (!microkit_have_signal) { - microkit_deferred_notify(RX_CH); - } else if (microkit_signal_cap != BASE_OUTPUT_NOTIFICATION_CAP + RX_CH) { - microkit_notify(RX_CH); - } - } - - if (notify_tx && net_require_signal_active(&state.tx_queue)) { - net_cancel_signal_active(&state.tx_queue); - notify_tx = false; - if (!microkit_have_signal) { - microkit_deferred_notify(TX_CH); - } else if (microkit_signal_cap != BASE_OUTPUT_NOTIFICATION_CAP + TX_CH) { - microkit_notify(TX_CH); - } - } -} - -void notified(microkit_channel ch) -{ - switch (ch) { - case RX_CH: - receive(); - break; - case TIMER: - sys_check_timeouts(); - set_timeout(); - break; - case TX_CH: - transmit(); - receive(); - break; - case SERIAL_TX_CH: - // Nothing to do - break; - default: - sddf_dprintf("LWIP|LOG: received notification on unexpected channel: %u\n", ch); - break; - } - - if (notify_rx && net_require_signal_free(&state.rx_queue)) { - net_cancel_signal_free(&state.rx_queue); - notify_rx = false; - if (!microkit_have_signal) { - microkit_deferred_notify(RX_CH); - } else if (microkit_signal_cap != BASE_OUTPUT_NOTIFICATION_CAP + RX_CH) { - microkit_notify(RX_CH); - } - } - - if (notify_tx && net_require_signal_active(&state.tx_queue)) { - net_cancel_signal_active(&state.tx_queue); - notify_tx = false; - if (!microkit_have_signal) { - microkit_deferred_notify(TX_CH); - } else if (microkit_signal_cap != BASE_OUTPUT_NOTIFICATION_CAP + TX_CH) { - microkit_notify(TX_CH); - } - } -} From dc8b994c15c30b9f2c817878e658a8fa50ab3f36 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Fri, 6 Sep 2024 15:43:21 +1000 Subject: [PATCH 04/18] Add absolute path to lib_sddf_lwip dir Signed-off-by: Courtney Darville --- network/lib_sddf_lwip/lib_sddf_lwip.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.mk b/network/lib_sddf_lwip/lib_sddf_lwip.mk index 7f80c39bc..c0158ae75 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.mk +++ b/network/lib_sddf_lwip/lib_sddf_lwip.mk @@ -10,7 +10,7 @@ endif CFLAGS += -DMAX_NUM_BUFFS=$(MAX_NUM_BUFFS) -LIB_SDDF_LWIP_DIR := network/lib_sddf_lwip +LIB_SDDF_LWIP_DIR := ${SDDF}/network/lib_sddf_lwip LIB_SDDF_LWIP_FILES := $(addprefix ${LIB_SDDF_LWIP_DIR}/, lib_sddf_lwip.c) LIB_SDDF_LWIP_OBJS := $(LIB_SDDF_LWIP_FILES:.c=.o) From c08780084fe5c40017bb493d15b2d24e57ed4ed0 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Fri, 6 Sep 2024 17:15:14 +1000 Subject: [PATCH 05/18] Update description for lib sddf lwip notify function Signed-off-by: Courtney Darville --- include/sddf/network/lib_sddf_lwip.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/sddf/network/lib_sddf_lwip.h b/include/sddf/network/lib_sddf_lwip.h index ac8c668a0..494437213 100644 --- a/include/sddf/network/lib_sddf_lwip.h +++ b/include/sddf/network/lib_sddf_lwip.h @@ -9,8 +9,7 @@ #include #include "lwip/pbuf.h" -#define LINK_SPEED 1000000000 // Gigabit -#define ETHER_MTU 1500 + /* Definitions for sDDF error constants. */ typedef enum { @@ -71,8 +70,8 @@ void sddf_lwip_process_rx(void); /** * Handles the sending of notifications to the network RX and TX virtualisers. - * Must be invoked at the end of each event handling loop to ensure outgoing - * buffers are processed by the virtualisers. + * Must be invoked at the end of each event handling loop and initialisation + * to ensure outgoing buffers are processed by the virtualisers. */ void sddf_lwip_maybe_notify(void); From df3847091a7f6b2e7cbd5f47d200f8c429bb0213 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Fri, 6 Sep 2024 17:20:49 +1000 Subject: [PATCH 06/18] Add prefixes to lib sddf constants Signed-off-by: Courtney Darville --- include/sddf/network/lib_sddf_lwip.h | 4 ++++ network/lib_sddf_lwip/lib_sddf_lwip.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/sddf/network/lib_sddf_lwip.h b/include/sddf/network/lib_sddf_lwip.h index 494437213..4c92583a4 100644 --- a/include/sddf/network/lib_sddf_lwip.h +++ b/include/sddf/network/lib_sddf_lwip.h @@ -9,7 +9,11 @@ #include #include "lwip/pbuf.h" +/* Default gigabit link speed. */ +#define SDDF_LWIP_LINK_SPEED 1000000000 +/* Default ethernet MTU. */ +#define SDDF_LWIP_ETHER_MTU 1500 /* Definitions for sDDF error constants. */ typedef enum { diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.c b/network/lib_sddf_lwip/lib_sddf_lwip.c index 94ff95542..2d3571578 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.c +++ b/network/lib_sddf_lwip/lib_sddf_lwip.c @@ -271,11 +271,11 @@ static err_t ethernet_init(struct netif *netif) { } net_set_mac_addr(netif->hwaddr, lwip_state.mac); - netif->mtu = ETHER_MTU; + netif->mtu = SDDF_LWIP_ETHER_MTU; netif->hwaddr_len = ETHARP_HWADDR_LEN; netif->output = etharp_output; netif->linkoutput = lwip_eth_send; - NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED); + NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, SDDF_LWIP_LINK_SPEED); netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP; return ERR_OK; From 69a27d75b0015c26273fbc24d714201eb787bfcb Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Fri, 6 Sep 2024 17:30:44 +1000 Subject: [PATCH 07/18] Add prefix to NUM_BUFFS constant for lib sddf lwip Signed-off-by: Courtney Darville --- examples/echo_server/echo.mk | 2 +- network/lib_sddf_lwip/lib_sddf_lwip.c | 2 +- network/lib_sddf_lwip/lib_sddf_lwip.mk | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/echo_server/echo.mk b/examples/echo_server/echo.mk index 0434cf57a..c32d41ce2 100644 --- a/examples/echo_server/echo.mk +++ b/examples/echo_server/echo.mk @@ -91,7 +91,7 @@ ${IMAGE_FILE} $(REPORT_FILE): $(IMAGES) $(SYSTEM_FILE) include ${SDDF}/util/util.mk include ${SDDF}/network/components/network_components.mk # Specify how many pbufs sDDF LWIP library requires for all clients -MAX_NUM_BUFFS=512 +SDDF_LWIP_NUM_BUFFS=512 include ${SDDF}/network/lib_sddf_lwip/lib_sddf_lwip.mk include ${ETHERNET_DRIVER}/eth_driver.mk include ${BENCHMARK}/benchmark.mk diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.c b/network/lib_sddf_lwip/lib_sddf_lwip.c index 2d3571578..8e5858103 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.c +++ b/network/lib_sddf_lwip/lib_sddf_lwip.c @@ -66,7 +66,7 @@ typedef struct pbuf_custom_offset { LWIP_MEMPOOL_DECLARE( RX_POOL, - MAX_NUM_BUFFS * 2, + SDDF_LWIP_NUM_BUFFS * 2, sizeof(struct pbuf_custom_offset), "Zero-copy RX pool" ); diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.mk b/network/lib_sddf_lwip/lib_sddf_lwip.mk index c0158ae75..4ce8d3908 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.mk +++ b/network/lib_sddf_lwip/lib_sddf_lwip.mk @@ -4,11 +4,11 @@ # SPDX-License-Identifier: BSD-2-Clause # -ifeq ($(strip $(MAX_NUM_BUFFS)),) +ifeq ($(strip $(SDDF_LWIP_NUM_BUFFS)),) $(error MAX_NUM_BUFFS must be specified) endif -CFLAGS += -DMAX_NUM_BUFFS=$(MAX_NUM_BUFFS) +CFLAGS += -DSDDF_LWIP_NUM_BUFFS=$(SDDF_LWIP_NUM_BUFFS) LIB_SDDF_LWIP_DIR := ${SDDF}/network/lib_sddf_lwip LIB_SDDF_LWIP_FILES := $(addprefix ${LIB_SDDF_LWIP_DIR}/, lib_sddf_lwip.c) From d122ece74d48434b503aff9e0b8ca1dbdf3221db Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Fri, 6 Sep 2024 18:56:58 +1000 Subject: [PATCH 08/18] Fix style Signed-off-by: Courtney Darville --- examples/echo_server/echo.c | 8 ++- include/sddf/network/lib_sddf_lwip.h | 4 +- network/lib_sddf_lwip/lib_sddf_lwip.c | 88 ++++++++++++++++----------- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/examples/echo_server/echo.c b/examples/echo_server/echo.c index f53d3d265..81706d831 100644 --- a/examples/echo_server/echo.c +++ b/examples/echo_server/echo.c @@ -46,17 +46,19 @@ struct pbuf *tail; /** * Netif status callback function that output's client's Microkit name and * obtained IP address. - * + * * @param ip_addr ip address of the client. */ -void netif_status_callback(char *ip_addr) { +void netif_status_callback(char *ip_addr) +{ sddf_printf("DHCP request finished, IP address for netif %s is: %s\n", microkit_name, ip_addr); } /** * Sets a timeout for the next lwip tick. */ -void set_timeout(void) { +void set_timeout(void) +{ sddf_timer_set_timeout(TIMER, LWIP_TICK_MS * NS_IN_MS); } diff --git a/include/sddf/network/lib_sddf_lwip.h b/include/sddf/network/lib_sddf_lwip.h index 4c92583a4..1f389d20c 100644 --- a/include/sddf/network/lib_sddf_lwip.h +++ b/include/sddf/network/lib_sddf_lwip.h @@ -47,7 +47,7 @@ typedef void (*sddf_lwip_netif_status_callback_fn)(char *ip_addr); */ typedef net_sddf_err_t (*sddf_lwip_handle_empty_tx_free_fn)(struct pbuf *p); -/** +/** * Checks LWIP system timeouts. Should be invoked after every LWIP tick. */ void sddf_lwip_process_timeout(void); @@ -65,7 +65,7 @@ void sddf_lwip_process_timeout(void); */ net_sddf_err_t sddf_lwip_transmit_pbuf(struct pbuf *p); -/** +/** * Handles the passing of incoming packets in sDDF buffers to LWIP. Must be * called to process the sDDF RX queue each time a notification is received * from the network virtualiser. diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.c b/network/lib_sddf_lwip/lib_sddf_lwip.c index 8e5858103..135abfb92 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.c +++ b/network/lib_sddf_lwip/lib_sddf_lwip.c @@ -76,23 +76,24 @@ sddf_state_t sddf_state; /** * Helper function to convert sddf errors to lwip errors. - * + * * @param sddf_err sddf error. * - * @return Equivalent lwip error. + * @return Equivalent lwip error. */ -static err_t sddf_err_to_lwip_err(net_sddf_err_t sddf_err) { +static err_t sddf_err_to_lwip_err(net_sddf_err_t sddf_err) +{ switch (sddf_err) { - case SDDF_ERR_OK: - return ERR_OK; - case SDDF_ERR_PBUF: - return ERR_BUF; - case SDDF_ERR_NO_BUF: - return ERR_MEM; - case SDDF_ERR_ENQUEUED: - return ERR_OK; - case SDDF_ERR_UNHANDLED: - return ERR_MEM; + case SDDF_ERR_OK: + return ERR_OK; + case SDDF_ERR_PBUF: + return ERR_BUF; + case SDDF_ERR_NO_BUF: + return ERR_MEM; + case SDDF_ERR_ENQUEUED: + return ERR_OK; + case SDDF_ERR_UNHANDLED: + return ERR_MEM; } return ERR_ARG; } @@ -100,38 +101,42 @@ static err_t sddf_err_to_lwip_err(net_sddf_err_t sddf_err) { /** * Default netif status callback function. Prints client MAC address and * obtained ip address. - * - * @param ip_addr Obtained ip address as a string. + * + * @param ip_addr Obtained ip address as a string. */ -static void netif_status_callback_default(char *ip_addr) { +static void netif_status_callback_default(char *ip_addr) +{ uint8_t *mac = lwip_state.netif.hwaddr; lwip_state.err_output("LWIP|NOTICE: DHCP request for mac " - "%02lx:%02lx:%02lx:%02lx:%02lx:%02lx " - "returned ip address: %s\n", mac[0], - mac[1], mac[2], mac[3], mac[4], mac[5], - ip_addr); + "%02lx:%02lx:%02lx:%02lx:%02lx:%02lx " + "returned ip address: %s\n", mac[0], + mac[1], mac[2], mac[3], mac[4], mac[5], + ip_addr); } /** * Default handling function to be called during transmission if tx free * queue is empty. - * + * * @param p pbuf that could not be sent due to queue being empty. * * @return Simply returns the sddf error indicating nothing was done. */ -static net_sddf_err_t handle_empty_tx_free_default(struct pbuf *p) { +static net_sddf_err_t handle_empty_tx_free_default(struct pbuf *p) +{ return SDDF_ERR_UNHANDLED; } /** * Returns current time from the timer. */ -uint32_t sys_now(void) { +uint32_t sys_now(void) +{ return sddf_timer_time_now(sddf_state.timer_ch) / NS_IN_MS; } -void sddf_lwip_process_timeout() { +void sddf_lwip_process_timeout() +{ sys_check_timeouts(); } @@ -140,7 +145,8 @@ void sddf_lwip_process_timeout() { * * @param p pbuf to free. */ -static void interface_free_buffer(struct pbuf *p) { +static void interface_free_buffer(struct pbuf *p) +{ SYS_ARCH_DECL_PROTECT(old_level); pbuf_custom_offset_t *custom_pbuf_offset = (pbuf_custom_offset_t *)p; SYS_ARCH_PROTECT(old_level); @@ -160,7 +166,8 @@ static void interface_free_buffer(struct pbuf *p) { * * @return the newly created pbuf. Can be cast to pbuf_custom. */ -static struct pbuf *create_interface_buffer(uint64_t offset, size_t length) { +static struct pbuf *create_interface_buffer(uint64_t offset, size_t length) +{ pbuf_custom_offset_t *custom_pbuf_offset = (pbuf_custom_offset_t *) LWIP_MEMPOOL_ALLOC(RX_POOL); custom_pbuf_offset->offset = offset; custom_pbuf_offset->custom.custom_free_function = interface_free_buffer; @@ -186,7 +193,8 @@ static struct pbuf *create_interface_buffer(uint64_t offset, size_t length) { * sddf buffers available, handle_empty_tx_free will be called with the pbuf, * and the equivalent lwip error will be returned. */ -static err_t lwip_eth_send(struct netif *netif, struct pbuf *p) { +static err_t lwip_eth_send(struct netif *netif, struct pbuf *p) +{ if (p->tot_len > NET_BUFFER_SIZE) { lwip_state.err_output("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", p->tot_len, NET_BUFFER_SIZE); @@ -217,7 +225,8 @@ static err_t lwip_eth_send(struct netif *netif, struct pbuf *p) { return ERR_OK; } -net_sddf_err_t sddf_lwip_transmit_pbuf(struct pbuf *p) { +net_sddf_err_t sddf_lwip_transmit_pbuf(struct pbuf *p) +{ if (p->tot_len > NET_BUFFER_SIZE) { lwip_state.err_output("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", p->tot_len, NET_BUFFER_SIZE); @@ -234,7 +243,8 @@ net_sddf_err_t sddf_lwip_transmit_pbuf(struct pbuf *p) { return SDDF_ERR_OK; } -void sddf_lwip_process_rx(void) { +void sddf_lwip_process_rx(void) +{ bool reprocess = true; while (reprocess) { while (!net_queue_empty_active(&sddf_state.rx_queue)) { @@ -265,11 +275,12 @@ void sddf_lwip_process_rx(void) { * * @param netif network interface data structure. */ -static err_t ethernet_init(struct netif *netif) { +static err_t ethernet_init(struct netif *netif) +{ if (netif->state == NULL) { return ERR_ARG; } - + net_set_mac_addr(netif->hwaddr, lwip_state.mac); netif->mtu = SDDF_LWIP_ETHER_MTU; netif->hwaddr_len = ETHARP_HWADDR_LEN; @@ -288,7 +299,8 @@ static err_t ethernet_init(struct netif *netif) { * * @param netif network interface data structure. */ -static void netif_status_callback(struct netif *netif) { +static void netif_status_callback(struct netif *netif) +{ if (dhcp_supplied_address(netif)) { char ip4_str[IP4ADDR_STRLEN_MAX]; lwip_state.netif_callback(ip4addr_ntoa_r(netif_ip4_addr(netif), ip4_str, IP4ADDR_STRLEN_MAX)); @@ -302,7 +314,8 @@ void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, microkit_channel timer_ch, uint64_t mac, sddf_lwip_err_output_fn err_output, sddf_lwip_netif_status_callback_fn netif_callback, - sddf_lwip_handle_empty_tx_free_fn handle_empty_tx_free) { + sddf_lwip_handle_empty_tx_free_fn handle_empty_tx_free) +{ /* Initialise sddf state */ sddf_state.rx_queue = rx_queue; sddf_state.tx_queue = tx_queue; @@ -314,9 +327,9 @@ void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, /* Initialise lwip state */ lwip_state.mac = mac; - lwip_state.err_output = (err_output == NULL)? sddf_printf_: err_output; - lwip_state.netif_callback = (netif_callback == NULL)? netif_status_callback_default: netif_callback; - lwip_state.handle_empty_tx_free = (handle_empty_tx_free == NULL)? handle_empty_tx_free_default: handle_empty_tx_free; + lwip_state.err_output = (err_output == NULL) ? sddf_printf_ : err_output; + lwip_state.netif_callback = (netif_callback == NULL) ? netif_status_callback_default : netif_callback; + lwip_state.handle_empty_tx_free = (handle_empty_tx_free == NULL) ? handle_empty_tx_free_default : handle_empty_tx_free; lwip_init(); @@ -346,7 +359,8 @@ void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, } } -void sddf_lwip_maybe_notify() { +void sddf_lwip_maybe_notify() +{ if (sddf_state.notify_rx && net_require_signal_free(&sddf_state.rx_queue)) { net_cancel_signal_free(&sddf_state.rx_queue); sddf_state.notify_rx = false; From 917941c6f9c4110e4819b08f35c844ba18e57e1f Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Mon, 9 Sep 2024 16:40:37 +1000 Subject: [PATCH 09/18] Rename LWIP_OBJS to ECHO_OBJS Signed-off-by: Courtney Darville --- examples/echo_server/echo.mk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/echo_server/echo.mk b/examples/echo_server/echo.mk index c32d41ce2..3a613f85d 100644 --- a/examples/echo_server/echo.mk +++ b/examples/echo_server/echo.mk @@ -63,20 +63,20 @@ include ${SDDF}/${LWIPDIR}/Filelists.mk NETIFFILES:=$(LWIPDIR)/netif/ethernet.c # LWIPFILES: All the above. -LWIPFILES = echo.c $(COREFILES) $(CORE4FILES) $(NETIFFILES) -LWIP_OBJS := $(LWIPFILES:.c=.o) echo.o utilization_socket.o \ +LWIPFILES := $(COREFILES) $(CORE4FILES) $(NETIFFILES) +ECHO_OBJS := $(LWIPFILES:.c=.o) echo.o utilization_socket.o \ udp_echo_socket.o tcp_echo_socket.o -DEPS := $(filter %.d,$(LWIP_OBJS:.o=.d)) +DEPS := $(filter %.d,$(ECHO_OBJS:.o=.d)) all: loader.img -${LWIP_OBJS}: ${CHECK_FLAGS_BOARD_MD5} -echo.elf: $(LWIP_OBJS) libsddf_util.a lib_sddf_lwip.a +${ECHO_OBJS}: ${CHECK_FLAGS_BOARD_MD5} +echo.elf: $(ECHO_OBJS) lib_sddf_lwip.a libsddf_util.a $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ LWIPDIRS := $(addprefix ${LWIPDIR}/, core/ipv4 netif api) -${LWIP_OBJS}: |${BUILD_DIR}/${LWIPDIRS} +${ECHO_OBJS}: |${BUILD_DIR}/${LWIPDIRS} ${BUILD_DIR}/${LWIPDIRS}: mkdir -p $@ From 73f6f7c97b1886b0d77c7e3191c3ceca0c0a1387 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Mon, 9 Sep 2024 16:43:18 +1000 Subject: [PATCH 10/18] Remove unnecessary filter Signed-off-by: Courtney Darville --- examples/echo_server/echo.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/echo_server/echo.mk b/examples/echo_server/echo.mk index 3a613f85d..fe90d625f 100644 --- a/examples/echo_server/echo.mk +++ b/examples/echo_server/echo.mk @@ -67,7 +67,7 @@ LWIPFILES := $(COREFILES) $(CORE4FILES) $(NETIFFILES) ECHO_OBJS := $(LWIPFILES:.c=.o) echo.o utilization_socket.o \ udp_echo_socket.o tcp_echo_socket.o -DEPS := $(filter %.d,$(ECHO_OBJS:.o=.d)) +DEPS := $(ECHO_OBJS:.o=.d) all: loader.img From 49e62e4a8578d0adad5ac39685e71200cb528314 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Mon, 9 Sep 2024 17:44:14 +1000 Subject: [PATCH 11/18] Only use SDDF_LWIP_NUM_BUFFS for building lib sddf lwip Signed-off-by: Courtney Darville --- network/lib_sddf_lwip/lib_sddf_lwip.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.mk b/network/lib_sddf_lwip/lib_sddf_lwip.mk index 4ce8d3908..8f71c02f8 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.mk +++ b/network/lib_sddf_lwip/lib_sddf_lwip.mk @@ -8,12 +8,12 @@ ifeq ($(strip $(SDDF_LWIP_NUM_BUFFS)),) $(error MAX_NUM_BUFFS must be specified) endif -CFLAGS += -DSDDF_LWIP_NUM_BUFFS=$(SDDF_LWIP_NUM_BUFFS) - LIB_SDDF_LWIP_DIR := ${SDDF}/network/lib_sddf_lwip LIB_SDDF_LWIP_FILES := $(addprefix ${LIB_SDDF_LWIP_DIR}/, lib_sddf_lwip.c) LIB_SDDF_LWIP_OBJS := $(LIB_SDDF_LWIP_FILES:.c=.o) +${LIB_SDDF_LWIP_OBJS}: CFLAGS += -DSDDF_LWIP_NUM_BUFFS=$(SDDF_LWIP_NUM_BUFFS) + ${LIB_SDDF_LWIP_OBJS}: | ${LIB_SDDF_LWIP_DIR} ${CHECK_FLAGS_BOARD_MD5} ${LIB_SDDF_LWIP_DIR}: mkdir -p $@ From 4db3f63000d4fd2081ae73cb9709ce6bf424e417 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Mon, 9 Sep 2024 17:47:22 +1000 Subject: [PATCH 12/18] SDDF_LWIP_NUM_BUFS rename Signed-off-by: Courtney Darville --- examples/echo_server/echo.mk | 2 +- network/lib_sddf_lwip/lib_sddf_lwip.c | 2 +- network/lib_sddf_lwip/lib_sddf_lwip.mk | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/echo_server/echo.mk b/examples/echo_server/echo.mk index fe90d625f..7240089b8 100644 --- a/examples/echo_server/echo.mk +++ b/examples/echo_server/echo.mk @@ -91,7 +91,7 @@ ${IMAGE_FILE} $(REPORT_FILE): $(IMAGES) $(SYSTEM_FILE) include ${SDDF}/util/util.mk include ${SDDF}/network/components/network_components.mk # Specify how many pbufs sDDF LWIP library requires for all clients -SDDF_LWIP_NUM_BUFFS=512 +SDDF_LWIP_NUM_BUFS=512 include ${SDDF}/network/lib_sddf_lwip/lib_sddf_lwip.mk include ${ETHERNET_DRIVER}/eth_driver.mk include ${BENCHMARK}/benchmark.mk diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.c b/network/lib_sddf_lwip/lib_sddf_lwip.c index 135abfb92..b4fe83755 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.c +++ b/network/lib_sddf_lwip/lib_sddf_lwip.c @@ -66,7 +66,7 @@ typedef struct pbuf_custom_offset { LWIP_MEMPOOL_DECLARE( RX_POOL, - SDDF_LWIP_NUM_BUFFS * 2, + SDDF_LWIP_NUM_BUFS * 2, sizeof(struct pbuf_custom_offset), "Zero-copy RX pool" ); diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.mk b/network/lib_sddf_lwip/lib_sddf_lwip.mk index 8f71c02f8..9c8966efd 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.mk +++ b/network/lib_sddf_lwip/lib_sddf_lwip.mk @@ -4,17 +4,17 @@ # SPDX-License-Identifier: BSD-2-Clause # -ifeq ($(strip $(SDDF_LWIP_NUM_BUFFS)),) -$(error MAX_NUM_BUFFS must be specified) +ifeq ($(strip $(SDDF_LWIP_NUM_BUFS)),) +$(error SDDF_LWIP_NUM_BUFS must be specified) endif LIB_SDDF_LWIP_DIR := ${SDDF}/network/lib_sddf_lwip LIB_SDDF_LWIP_FILES := $(addprefix ${LIB_SDDF_LWIP_DIR}/, lib_sddf_lwip.c) LIB_SDDF_LWIP_OBJS := $(LIB_SDDF_LWIP_FILES:.c=.o) -${LIB_SDDF_LWIP_OBJS}: CFLAGS += -DSDDF_LWIP_NUM_BUFFS=$(SDDF_LWIP_NUM_BUFFS) +${LIB_SDDF_LWIP_OBJS}: CFLAGS += -DSDDF_LWIP_NUM_BUFS=$(SDDF_LWIP_NUM_BUFS) -${LIB_SDDF_LWIP_OBJS}: | ${LIB_SDDF_LWIP_DIR} ${CHECK_FLAGS_BOARD_MD5} +${LIB_SDDF_LWIP_OBJS}: ${CHECK_FLAGS_BOARD_MD5} | ${LIB_SDDF_LWIP_DIR} ${LIB_SDDF_LWIP_DIR}: mkdir -p $@ From 6e15f97a54645dbd47d90afc7791de0a1edc7d80 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Mon, 9 Sep 2024 17:51:29 +1000 Subject: [PATCH 13/18] Use makefile snippet location rather than hardcoded location Signed-off-by: Courtney Darville --- network/lib_sddf_lwip/lib_sddf_lwip.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.mk b/network/lib_sddf_lwip/lib_sddf_lwip.mk index 9c8966efd..17506e141 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.mk +++ b/network/lib_sddf_lwip/lib_sddf_lwip.mk @@ -8,7 +8,7 @@ ifeq ($(strip $(SDDF_LWIP_NUM_BUFS)),) $(error SDDF_LWIP_NUM_BUFS must be specified) endif -LIB_SDDF_LWIP_DIR := ${SDDF}/network/lib_sddf_lwip +LIB_SDDF_LWIP_DIR := $(dir $(lastword $(MAKEFILE_LIST))) LIB_SDDF_LWIP_FILES := $(addprefix ${LIB_SDDF_LWIP_DIR}/, lib_sddf_lwip.c) LIB_SDDF_LWIP_OBJS := $(LIB_SDDF_LWIP_FILES:.c=.o) From fabf5c6ccf5e97bec40a2e4cf43aa37f19b1038b Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Mon, 9 Sep 2024 17:59:38 +1000 Subject: [PATCH 14/18] Add attribute to print function Signed-off-by: Courtney Darville --- include/sddf/network/lib_sddf_lwip.h | 4 ++-- network/lib_sddf_lwip/lib_sddf_lwip.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/sddf/network/lib_sddf_lwip.h b/include/sddf/network/lib_sddf_lwip.h index 1f389d20c..79adb3e37 100644 --- a/include/sddf/network/lib_sddf_lwip.h +++ b/include/sddf/network/lib_sddf_lwip.h @@ -32,7 +32,7 @@ typedef enum { /** * Function type for output of sDDF LWIP errors. */ -typedef int (*sddf_lwip_err_output_fn)(const char *format, ...); +typedef int (*sddf_lwip_err_output_fn)(const char *format, ...) __attribute__((format(__printf__, 1, 2))); /** * Function type for netif status callback. Invoked by LWIP upon @@ -111,4 +111,4 @@ void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, microkit_channel timer_ch, uint64_t mac, sddf_lwip_err_output_fn err_output, sddf_lwip_netif_status_callback_fn netif_callback, - sddf_lwip_handle_empty_tx_free_fn handle_empty_tx_free); \ No newline at end of file + sddf_lwip_handle_empty_tx_free_fn handle_empty_tx_free); diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.c b/network/lib_sddf_lwip/lib_sddf_lwip.c index b4fe83755..234a66e44 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.c +++ b/network/lib_sddf_lwip/lib_sddf_lwip.c @@ -108,7 +108,7 @@ static void netif_status_callback_default(char *ip_addr) { uint8_t *mac = lwip_state.netif.hwaddr; lwip_state.err_output("LWIP|NOTICE: DHCP request for mac " - "%02lx:%02lx:%02lx:%02lx:%02lx:%02lx " + "%02x:%02x:%02x:%02x:%02x:%02x " "returned ip address: %s\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], ip_addr); From d06e9677648e62ec8c8d8488ea3aef25dea47c92 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Thu, 19 Sep 2024 19:22:16 +1000 Subject: [PATCH 15/18] Update err prefix Signed-off-by: Courtney Darville --- examples/echo_server/echo.c | 6 +++--- include/sddf/network/lib_sddf_lwip.h | 14 +++++++------- network/lib_sddf_lwip/lib_sddf_lwip.c | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/echo_server/echo.c b/examples/echo_server/echo.c index 81706d831..49da1147e 100644 --- a/examples/echo_server/echo.c +++ b/examples/echo_server/echo.c @@ -82,7 +82,7 @@ net_sddf_err_t enqueue_pbufs(struct pbuf *p) /* Increment reference count to ensure this pbuf is not freed by lwip */ pbuf_ref(p); - return SDDF_ERR_OK; + return SDDF_LWIP_ERR_OK; } void transmit(void) @@ -91,10 +91,10 @@ void transmit(void) while (reprocess) { while (head != NULL && !net_queue_empty_free(&net_tx_handle)) { net_sddf_err_t err = sddf_lwip_transmit_pbuf(head); - if (err == SDDF_ERR_PBUF) { + if (err == SDDF_LWIP_ERR_PBUF) { sddf_dprintf("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", head->tot_len, NET_BUFFER_SIZE); - } else if (err != SDDF_ERR_OK) { + } else if (err != SDDF_LWIP_ERR_OK) { sddf_dprintf("LWIP|ERROR: unkown error when trying to send pbuf %p\n", head); } diff --git a/include/sddf/network/lib_sddf_lwip.h b/include/sddf/network/lib_sddf_lwip.h index 79adb3e37..5b8dfea95 100644 --- a/include/sddf/network/lib_sddf_lwip.h +++ b/include/sddf/network/lib_sddf_lwip.h @@ -18,15 +18,15 @@ /* Definitions for sDDF error constants. */ typedef enum { /* No error, everything OK. */ - SDDF_ERR_OK = 0, + SDDF_LWIP_ERR_OK = 0, /* Pbuf too large for sDDF buffer. */ - SDDF_ERR_PBUF = -1, + SDDF_LWIP_ERR_PBUF = -1, /* No buffers available. */ - SDDF_ERR_NO_BUF = -2, + SDDF_LWIP_ERR_NO_BUF = -2, /* Pbuf successfully enqueued to be sent later. */ - SDDF_ERR_ENQUEUED = -3, + SDDF_LWIP_ERR_ENQUEUED = -3, /* Could not resolve error. */ - SDDF_ERR_UNHANDLED = -4 + SDDF_LWIP_ERR_UNHANDLED = -4 } net_sddf_err_t; /** @@ -57,8 +57,8 @@ void sddf_lwip_process_timeout(void); * * @param p pbuf to be transmitted. * - * @return If the pbuf is sent successfully, SDDF_ERR_OK is returned and the - * pbuf can safely be freed. If the pbuf is too large, SDDF_ERR_PBUF is + * @return If the pbuf is sent successfully, SDDF_LWIP_ERR_OK is returned and the + * pbuf can safely be freed. If the pbuf is too large, SDDF_LWIP_ERR_PBUF is * returned. If there are no free sDDF buffers available, * handle_empty_tx_free will be called with the pbuf, and the return value * will be returned. diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.c b/network/lib_sddf_lwip/lib_sddf_lwip.c index 234a66e44..f56304301 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.c +++ b/network/lib_sddf_lwip/lib_sddf_lwip.c @@ -84,15 +84,15 @@ sddf_state_t sddf_state; static err_t sddf_err_to_lwip_err(net_sddf_err_t sddf_err) { switch (sddf_err) { - case SDDF_ERR_OK: + case SDDF_LWIP_ERR_OK: return ERR_OK; - case SDDF_ERR_PBUF: + case SDDF_LWIP_ERR_PBUF: return ERR_BUF; case SDDF_ERR_NO_BUF: return ERR_MEM; - case SDDF_ERR_ENQUEUED: + case SDDF_LWIP_ERR_ENQUEUED: return ERR_OK; - case SDDF_ERR_UNHANDLED: + case SDDF_LWIP_ERR_UNHANDLED: return ERR_MEM; } return ERR_ARG; @@ -124,7 +124,7 @@ static void netif_status_callback_default(char *ip_addr) */ static net_sddf_err_t handle_empty_tx_free_default(struct pbuf *p) { - return SDDF_ERR_UNHANDLED; + return SDDF_LWIP_ERR_UNHANDLED; } /** @@ -230,7 +230,7 @@ net_sddf_err_t sddf_lwip_transmit_pbuf(struct pbuf *p) if (p->tot_len > NET_BUFFER_SIZE) { lwip_state.err_output("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", p->tot_len, NET_BUFFER_SIZE); - return SDDF_ERR_PBUF; + return SDDF_LWIP_ERR_PBUF; } if (net_queue_empty_free(&sddf_state.tx_queue)) { @@ -240,7 +240,7 @@ net_sddf_err_t sddf_lwip_transmit_pbuf(struct pbuf *p) err_t err = lwip_eth_send(&lwip_state.netif, p); assert(!err); - return SDDF_ERR_OK; + return SDDF_LWIP_ERR_OK; } void sddf_lwip_process_rx(void) From f98391f60f9640f48fe32825c9a8299f7ad949a1 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Thu, 19 Sep 2024 19:24:12 +1000 Subject: [PATCH 16/18] Unify channel naming Signed-off-by: Courtney Darville --- examples/echo_server/echo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/echo_server/echo.c b/examples/echo_server/echo.c index 49da1147e..45c81299c 100644 --- a/examples/echo_server/echo.c +++ b/examples/echo_server/echo.c @@ -20,7 +20,7 @@ #include "echo.h" #define SERIAL_TX_CH 0 -#define TIMER 1 +#define TIMER_CH 1 #define RX_CH 2 #define TX_CH 3 @@ -59,7 +59,7 @@ void netif_status_callback(char *ip_addr) */ void set_timeout(void) { - sddf_timer_set_timeout(TIMER, LWIP_TICK_MS * NS_IN_MS); + sddf_timer_set_timeout(TIMER_CH, LWIP_TICK_MS * NS_IN_MS); } /** @@ -132,7 +132,7 @@ void init(void) net_queue_init(&net_tx_handle, tx_free, tx_active, tx_size); net_buffers_init(&net_tx_handle, 0); - sddf_lwip_init(net_rx_handle, net_tx_handle, RX_CH, TX_CH, rx_buffer_data_region, tx_buffer_data_region, TIMER, + sddf_lwip_init(net_rx_handle, net_tx_handle, RX_CH, TX_CH, rx_buffer_data_region, tx_buffer_data_region, TIMER_CH, net_cli_mac_addr(microkit_name), NULL, netif_status_callback, enqueue_pbufs); set_timeout(); @@ -149,7 +149,7 @@ void notified(microkit_channel ch) case RX_CH: sddf_lwip_process_rx(); break; - case TIMER: + case TIMER_CH: sddf_lwip_process_timeout(); set_timeout(); break; From 7928c2987dbc37029dae602544b10c5bf0de4cf8 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Thu, 19 Sep 2024 19:31:57 +1000 Subject: [PATCH 17/18] fix style Signed-off-by: Courtney Darville --- examples/echo_server/echo.c | 7 ++-- include/sddf/network/lib_sddf_lwip.h | 13 +++---- network/lib_sddf_lwip/lib_sddf_lwip.c | 49 ++++++++++----------------- 3 files changed, 26 insertions(+), 43 deletions(-) diff --git a/examples/echo_server/echo.c b/examples/echo_server/echo.c index 45c81299c..6f9b3ffa0 100644 --- a/examples/echo_server/echo.c +++ b/examples/echo_server/echo.c @@ -92,8 +92,8 @@ void transmit(void) while (head != NULL && !net_queue_empty_free(&net_tx_handle)) { net_sddf_err_t err = sddf_lwip_transmit_pbuf(head); if (err == SDDF_LWIP_ERR_PBUF) { - sddf_dprintf("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", - head->tot_len, NET_BUFFER_SIZE); + sddf_dprintf("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", head->tot_len, + NET_BUFFER_SIZE); } else if (err != SDDF_LWIP_ERR_OK) { sddf_dprintf("LWIP|ERROR: unkown error when trying to send pbuf %p\n", head); } @@ -123,7 +123,8 @@ void transmit(void) void init(void) { - serial_cli_queue_init_sys(microkit_name, NULL, NULL, NULL, &serial_tx_queue_handle, serial_tx_queue, serial_tx_data); + serial_cli_queue_init_sys(microkit_name, NULL, NULL, NULL, &serial_tx_queue_handle, serial_tx_queue, + serial_tx_data); serial_putchar_init(SERIAL_TX_CH, &serial_tx_queue_handle); size_t rx_size, tx_size; diff --git a/include/sddf/network/lib_sddf_lwip.h b/include/sddf/network/lib_sddf_lwip.h index 5b8dfea95..68e7a1b6c 100644 --- a/include/sddf/network/lib_sddf_lwip.h +++ b/include/sddf/network/lib_sddf_lwip.h @@ -24,9 +24,9 @@ typedef enum { /* No buffers available. */ SDDF_LWIP_ERR_NO_BUF = -2, /* Pbuf successfully enqueued to be sent later. */ - SDDF_LWIP_ERR_ENQUEUED = -3, + SDDF_LWIP_ERR_ENQUEUED = -3, /* Could not resolve error. */ - SDDF_LWIP_ERR_UNHANDLED = -4 + SDDF_LWIP_ERR_UNHANDLED = -4 } net_sddf_err_t; /** @@ -104,11 +104,8 @@ void sddf_lwip_maybe_notify(void); * handling function for no available sDDF TX buffers during sending of LWIP * pbuf. Provide NULL to leave unhandled. */ -void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, - microkit_channel rx_ch, microkit_channel tx_ch, - uintptr_t rx_buffer_data_region, - uintptr_t tx_buffer_data_region, - microkit_channel timer_ch, - uint64_t mac, sddf_lwip_err_output_fn err_output, +void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, microkit_channel rx_ch, + microkit_channel tx_ch, uintptr_t rx_buffer_data_region, uintptr_t tx_buffer_data_region, + microkit_channel timer_ch, uint64_t mac, sddf_lwip_err_output_fn err_output, sddf_lwip_netif_status_callback_fn netif_callback, sddf_lwip_handle_empty_tx_free_fn handle_empty_tx_free); diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.c b/network/lib_sddf_lwip/lib_sddf_lwip.c index f56304301..e8b2342bf 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.c +++ b/network/lib_sddf_lwip/lib_sddf_lwip.c @@ -64,12 +64,7 @@ typedef struct pbuf_custom_offset { uint64_t offset; } pbuf_custom_offset_t; -LWIP_MEMPOOL_DECLARE( - RX_POOL, - SDDF_LWIP_NUM_BUFS * 2, - sizeof(struct pbuf_custom_offset), - "Zero-copy RX pool" -); +LWIP_MEMPOOL_DECLARE(RX_POOL, SDDF_LWIP_NUM_BUFS * 2, sizeof(struct pbuf_custom_offset), "Zero-copy RX pool"); lwip_state_t lwip_state; sddf_state_t sddf_state; @@ -109,9 +104,8 @@ static void netif_status_callback_default(char *ip_addr) uint8_t *mac = lwip_state.netif.hwaddr; lwip_state.err_output("LWIP|NOTICE: DHCP request for mac " "%02x:%02x:%02x:%02x:%02x:%02x " - "returned ip address: %s\n", mac[0], - mac[1], mac[2], mac[3], mac[4], mac[5], - ip_addr); + "returned ip address: %s\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], ip_addr); } /** @@ -150,7 +144,7 @@ static void interface_free_buffer(struct pbuf *p) SYS_ARCH_DECL_PROTECT(old_level); pbuf_custom_offset_t *custom_pbuf_offset = (pbuf_custom_offset_t *)p; SYS_ARCH_PROTECT(old_level); - net_buff_desc_t buffer = {custom_pbuf_offset->offset, 0}; + net_buff_desc_t buffer = { custom_pbuf_offset->offset, 0 }; int err = net_enqueue_free(&(sddf_state.rx_queue), buffer); assert(!err); sddf_state.notify_rx = true; @@ -168,18 +162,12 @@ static void interface_free_buffer(struct pbuf *p) */ static struct pbuf *create_interface_buffer(uint64_t offset, size_t length) { - pbuf_custom_offset_t *custom_pbuf_offset = (pbuf_custom_offset_t *) LWIP_MEMPOOL_ALLOC(RX_POOL); + pbuf_custom_offset_t *custom_pbuf_offset = (pbuf_custom_offset_t *)LWIP_MEMPOOL_ALLOC(RX_POOL); custom_pbuf_offset->offset = offset; custom_pbuf_offset->custom.custom_free_function = interface_free_buffer; - return pbuf_alloced_custom( - PBUF_RAW, - length, - PBUF_REF, - &custom_pbuf_offset->custom, - (void *)(offset + sddf_state.rx_buffer_data_region), - NET_BUFFER_SIZE - ); + return pbuf_alloced_custom(PBUF_RAW, length, PBUF_REF, &custom_pbuf_offset->custom, + (void *)(offset + sddf_state.rx_buffer_data_region), NET_BUFFER_SIZE); } /** @@ -196,8 +184,8 @@ static struct pbuf *create_interface_buffer(uint64_t offset, size_t length) static err_t lwip_eth_send(struct netif *netif, struct pbuf *p) { if (p->tot_len > NET_BUFFER_SIZE) { - lwip_state.err_output("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", - p->tot_len, NET_BUFFER_SIZE); + lwip_state.err_output("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", p->tot_len, + NET_BUFFER_SIZE); return ERR_MEM; } @@ -228,8 +216,8 @@ static err_t lwip_eth_send(struct netif *netif, struct pbuf *p) net_sddf_err_t sddf_lwip_transmit_pbuf(struct pbuf *p) { if (p->tot_len > NET_BUFFER_SIZE) { - lwip_state.err_output("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", - p->tot_len, NET_BUFFER_SIZE); + lwip_state.err_output("LWIP|ERROR: attempted to send a packet of size %u > BUFFER SIZE %u\n", p->tot_len, + NET_BUFFER_SIZE); return SDDF_LWIP_ERR_PBUF; } @@ -307,12 +295,9 @@ static void netif_status_callback(struct netif *netif) } } -void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, - microkit_channel rx_ch, microkit_channel tx_ch, - uintptr_t rx_buffer_data_region, - uintptr_t tx_buffer_data_region, - microkit_channel timer_ch, - uint64_t mac, sddf_lwip_err_output_fn err_output, +void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, microkit_channel rx_ch, + microkit_channel tx_ch, uintptr_t rx_buffer_data_region, uintptr_t tx_buffer_data_region, + microkit_channel timer_ch, uint64_t mac, sddf_lwip_err_output_fn err_output, sddf_lwip_netif_status_callback_fn netif_callback, sddf_lwip_handle_empty_tx_free_fn handle_empty_tx_free) { @@ -329,7 +314,8 @@ void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, lwip_state.mac = mac; lwip_state.err_output = (err_output == NULL) ? sddf_printf_ : err_output; lwip_state.netif_callback = (netif_callback == NULL) ? netif_status_callback_default : netif_callback; - lwip_state.handle_empty_tx_free = (handle_empty_tx_free == NULL) ? handle_empty_tx_free_default : handle_empty_tx_free; + lwip_state.handle_empty_tx_free = (handle_empty_tx_free == NULL) ? handle_empty_tx_free_default + : handle_empty_tx_free; lwip_init(); @@ -345,8 +331,7 @@ void sddf_lwip_init(net_queue_handle_t rx_queue, net_queue_handle_t tx_queue, lwip_state.netif.name[0] = 'e'; lwip_state.netif.name[1] = '0'; - if (!netif_add(&(lwip_state.netif), &ipaddr, &netmask, &gw, (void *)&lwip_state, - ethernet_init, ethernet_input)) { + if (!netif_add(&(lwip_state.netif), &ipaddr, &netmask, &gw, (void *)&lwip_state, ethernet_init, ethernet_input)) { lwip_state.err_output("LWIP|ERROR: Netif add returned NULL\n"); } From b5983a0388f2394851f1e24a201ce7edff2bf3cd Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Thu, 19 Sep 2024 19:40:42 +1000 Subject: [PATCH 18/18] Fix forgotten name update Signed-off-by: Courtney Darville --- network/lib_sddf_lwip/lib_sddf_lwip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/lib_sddf_lwip/lib_sddf_lwip.c b/network/lib_sddf_lwip/lib_sddf_lwip.c index e8b2342bf..349e3eea4 100644 --- a/network/lib_sddf_lwip/lib_sddf_lwip.c +++ b/network/lib_sddf_lwip/lib_sddf_lwip.c @@ -83,7 +83,7 @@ static err_t sddf_err_to_lwip_err(net_sddf_err_t sddf_err) return ERR_OK; case SDDF_LWIP_ERR_PBUF: return ERR_BUF; - case SDDF_ERR_NO_BUF: + case SDDF_LWIP_ERR_NO_BUF: return ERR_MEM; case SDDF_LWIP_ERR_ENQUEUED: return ERR_OK;