Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create sDDF LWIP Library #238

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/echo_server/board/imx8mm_evk/echo_server.system
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
</protection_domain>

<protection_domain name="client0" priority="97" budget="20000" id="6">
<program_image path="lwip.elf" />
<program_image path="echo.elf" />

<map mr="net_rx_free_cli0" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="net_rx_active_cli0" vaddr="0x2_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand All @@ -181,7 +181,7 @@
</protection_domain>

<protection_domain name="client1" priority="95" budget="20000" id="7">
<program_image path="lwip.elf" />
<program_image path="echo.elf" />

<map mr="net_rx_free_cli1" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="net_rx_active_cli1" vaddr="0x2_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand Down
4 changes: 2 additions & 2 deletions examples/echo_server/board/maaxboard/echo_server.system
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
</protection_domain>

<protection_domain name="client0" priority="97" budget="20000" id="6">
<program_image path="lwip.elf" />
<program_image path="echo.elf" />

<map mr="net_rx_free_cli0" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="net_rx_active_cli0" vaddr="0x2_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand All @@ -181,7 +181,7 @@
</protection_domain>

<protection_domain name="client1" priority="95" budget="20000" id="7">
<program_image path="lwip.elf" />
<program_image path="echo.elf" />

<map mr="net_rx_free_cli1" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="net_rx_active_cli1" vaddr="0x2_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand Down
4 changes: 2 additions & 2 deletions examples/echo_server/board/odroidc4/echo_server.system
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
</protection_domain>

<protection_domain name="client0" priority="97" budget="20000" id="6">
<program_image path="lwip.elf" />
<program_image path="echo.elf" />

<map mr="net_rx_free_cli0" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="net_rx_active_cli0" vaddr="0x2_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand All @@ -181,7 +181,7 @@
</protection_domain>

<protection_domain name="client1" priority="95" budget="20000" id="7">
<program_image path="lwip.elf" />
<program_image path="echo.elf" />

<map mr="net_rx_free_cli1" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="net_rx_active_cli1" vaddr="0x2_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
</protection_domain>

<protection_domain name="client0" priority="97" budget="20000" id="6">
<program_image path="lwip.elf" />
<program_image path="echo.elf" />

<map mr="net_rx_free_cli0" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="net_rx_active_cli0" vaddr="0x2_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand All @@ -180,7 +180,7 @@
</protection_domain>

<protection_domain name="client1" priority="95" budget="20000" id="7">
<program_image path="lwip.elf" />
<program_image path="echo.elf" />

<map mr="net_rx_free_cli1" vaddr="0x2_000_000" perms="rw" cached="true" setvar_vaddr="rx_free" />
<map mr="net_rx_active_cli1" vaddr="0x2_200_000" perms="rw" cached="true" setvar_vaddr="rx_active" />
Expand Down
167 changes: 167 additions & 0 deletions examples/echo_server/echo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* Copyright 2022, UNSW
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <stdbool.h>
#include <stdint.h>
#include <microkit.h>
#include <sddf/util/util.h>
#include <sddf/util/string.h>
#include <sddf/util/printf.h>
#include <sddf/network/lib_sddf_lwip.h>
#include <sddf/network/queue.h>
#include <sddf/serial/queue.h>
#include <sddf/timer/client.h>
#include <sddf/benchmark/sel4bench.h>
#include <serial_config.h>
#include <ethernet_config.h>
#include "lwip/pbuf.h"

#include "echo.h"

#define SERIAL_TX_CH 0
#define TIMER 1
Courtney3141 marked this conversation as resolved.
Show resolved Hide resolved
#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();
}
3 changes: 0 additions & 3 deletions examples/echo_server/echo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
37 changes: 19 additions & 18 deletions examples/echo_server/echo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) \
Expand All @@ -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-*
Expand All @@ -64,21 +63,20 @@ 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 := $(COREFILES) $(CORE4FILES) $(NETIFFILES)
ECHO_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 := $(ECHO_OBJS:.o=.d)

all: loader.img

${LWIP_OBJS}: ${CHECK_FLAGS_BOARD_MD5}
lwip.elf: $(LWIP_OBJS) libsddf_util.a
${ECHO_OBJS}: ${CHECK_FLAGS_BOARD_MD5}
echo.elf: $(ECHO_OBJS) lib_sddf_lwip.a libsddf_util.a
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@
Courtney3141 marked this conversation as resolved.
Show resolved Hide resolved

LWIPDIRS := $(addprefix ${LWIPDIR}/, core/ipv4 netif api)
${LWIP_OBJS}: |${BUILD_DIR}/${LWIPDIRS}
${ECHO_OBJS}: |${BUILD_DIR}/${LWIPDIRS}
${BUILD_DIR}/${LWIPDIRS}:
mkdir -p $@

Expand All @@ -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
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
include ${TIMER_DRIVER}/timer_driver.mk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <microkit.h>
#include <sddf/util/string.h>
#include <sddf/network/queue.h>
#include <sddf/network/util.h>
#include <sddf/util/util.h>

#define NUM_NETWORK_CLIENTS 2
Expand Down
Loading