From 17c3f79e906f3a0ace3c9cd4b8b4b0263590d0b9 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Sun, 22 Sep 2024 23:41:10 +1000 Subject: [PATCH 1/3] Rename network size fields to capacity/length Signed-off-by: Courtney Darville --- drivers/network/imx/ethernet.c | 14 ++-- drivers/network/meson/ethernet.c | 12 ++-- drivers/network/virtio/ethernet.c | 4 +- .../include/ethernet_config/ethernet_config.h | 68 +++++++++---------- examples/echo_server/lwip.c | 10 +-- examples/echo_server/tcp_echo_socket.c | 14 ++-- include/sddf/network/queue.h | 30 ++++---- network/components/copy.c | 10 +-- network/components/virt_rx.c | 8 +-- network/components/virt_tx.c | 8 +-- 10 files changed, 89 insertions(+), 89 deletions(-) diff --git a/drivers/network/imx/ethernet.c b/drivers/network/imx/ethernet.c index ae86e6e10..90eea3857 100644 --- a/drivers/network/imx/ethernet.c +++ b/drivers/network/imx/ethernet.c @@ -58,14 +58,14 @@ net_queue_handle_t tx_queue; volatile struct enet_regs *eth; -static inline bool hw_ring_full(hw_ring_t *ring, size_t ring_size) +static inline bool hw_ring_full(hw_ring_t *ring, size_t ring_capacity) { - return !((ring->tail - ring->head + 1) % ring_size); + return !((ring->tail - ring->head + 1) % ring_capacity); } -static inline bool hw_ring_empty(hw_ring_t *ring, size_t ring_size) +static inline bool hw_ring_empty(hw_ring_t *ring, size_t ring_capacity) { - return !((ring->tail - ring->head) % ring_size); + return !((ring->tail - ring->head) % ring_capacity); } static void update_ring_slot(hw_ring_t *ring, unsigned int idx, uintptr_t phys, @@ -302,8 +302,8 @@ void init(void) { eth_setup(); - net_queue_init(&rx_queue, rx_free, rx_active, NET_RX_QUEUE_SIZE_DRIV); - net_queue_init(&tx_queue, tx_free, tx_active, NET_TX_QUEUE_SIZE_DRIV); + net_queue_init(&rx_queue, rx_free, rx_active, NET_RX_QUEUE_CAPACITY_DRIV); + net_queue_init(&tx_queue, tx_free, tx_active, NET_TX_QUEUE_CAPACITY_DRIV); rx_provide(); tx_provide(); @@ -330,4 +330,4 @@ void notified(microkit_channel ch) sddf_dprintf("ETH|LOG: received notification on unexpected channel: %u\n", ch); break; } -} \ No newline at end of file +} diff --git a/drivers/network/meson/ethernet.c b/drivers/network/meson/ethernet.c index 9d2f22af5..ea745b8fd 100644 --- a/drivers/network/meson/ethernet.c +++ b/drivers/network/meson/ethernet.c @@ -59,14 +59,14 @@ net_queue_handle_t tx_queue; volatile struct eth_mac_regs *eth_mac; volatile struct eth_dma_regs *eth_dma; -static inline bool hw_ring_full(hw_ring_t *ring, size_t ring_size) +static inline bool hw_ring_full(hw_ring_t *ring, size_t ring_capacity) { - return !((ring->tail + 2 - ring->head) % ring_size); + return !((ring->tail + 2 - ring->head) % ring_capacity); } -static inline bool hw_ring_empty(hw_ring_t *ring, size_t ring_size) +static inline bool hw_ring_empty(hw_ring_t *ring, size_t ring_capacity) { - return !((ring->tail - ring->head) % ring_size); + return !((ring->tail - ring->head) % ring_capacity); } static void update_ring_slot(hw_ring_t *ring, unsigned int idx, uint32_t status, @@ -271,8 +271,8 @@ void init(void) { eth_setup(); - net_queue_init(&rx_queue, (net_queue_t *)rx_free, (net_queue_t *)rx_active, NET_RX_QUEUE_SIZE_DRIV); - net_queue_init(&tx_queue, (net_queue_t *)tx_free, (net_queue_t *)tx_active, NET_TX_QUEUE_SIZE_DRIV); + net_queue_init(&rx_queue, (net_queue_t *)rx_free, (net_queue_t *)rx_active, NET_RX_QUEUE_CAPACITY_DRIV); + net_queue_init(&tx_queue, (net_queue_t *)tx_free, (net_queue_t *)tx_active, NET_TX_QUEUE_CAPACITY_DRIV); rx_provide(); tx_provide(); diff --git a/drivers/network/virtio/ethernet.c b/drivers/network/virtio/ethernet.c index 046eda9ca..0ad360f4f 100644 --- a/drivers/network/virtio/ethernet.c +++ b/drivers/network/virtio/ethernet.c @@ -443,8 +443,8 @@ void init(void) ialloc_init(&rx_ialloc_desc, rx_descriptors, RX_COUNT); ialloc_init(&tx_ialloc_desc, tx_descriptors, TX_COUNT); - net_queue_init(&rx_queue, rx_free, rx_active, NET_RX_QUEUE_SIZE_DRIV); - net_queue_init(&tx_queue, tx_free, tx_active, NET_TX_QUEUE_SIZE_DRIV); + net_queue_init(&rx_queue, rx_free, rx_active, NET_RX_QUEUE_CAPACITY_DRIV); + net_queue_init(&tx_queue, tx_free, tx_active, NET_TX_QUEUE_CAPACITY_DRIV); eth_setup(); diff --git a/examples/echo_server/include/ethernet_config/ethernet_config.h b/examples/echo_server/include/ethernet_config/ethernet_config.h index 2d810c381..bcb7ac5ab 100644 --- a/examples/echo_server/include/ethernet_config/ethernet_config.h +++ b/examples/echo_server/include/ethernet_config/ethernet_config.h @@ -43,44 +43,44 @@ #error "Must define MAC addresses for clients in ethernet config" #endif -#define NET_TX_QUEUE_SIZE_CLI0 512 -#define NET_TX_QUEUE_SIZE_CLI1 512 -#define NET_TX_QUEUE_SIZE_DRIV (NET_TX_QUEUE_SIZE_CLI0 + NET_TX_QUEUE_SIZE_CLI1) +#define NET_TX_QUEUE_CAPACITY_CLI0 512 +#define NET_TX_QUEUE_CAPACITY_CLI1 512 +#define NET_TX_QUEUE_CAPACITY_DRIV (NET_TX_QUEUE_CAPACITY_CLI0 + NET_TX_QUEUE_CAPACITY_CLI1) #define NET_TX_DATA_REGION_SIZE_CLI0 NET_DATA_REGION_SIZE #define NET_TX_DATA_REGION_SIZE_CLI1 NET_DATA_REGION_SIZE -_Static_assert(NET_TX_DATA_REGION_SIZE_CLI0 >= NET_TX_QUEUE_SIZE_CLI0 *NET_BUFFER_SIZE, +_Static_assert(NET_TX_DATA_REGION_SIZE_CLI0 >= NET_TX_QUEUE_CAPACITY_CLI0 *NET_BUFFER_SIZE, "Client0 TX data region size must fit Client0 TX buffers"); -_Static_assert(NET_TX_DATA_REGION_SIZE_CLI1 >= NET_TX_QUEUE_SIZE_CLI1 *NET_BUFFER_SIZE, +_Static_assert(NET_TX_DATA_REGION_SIZE_CLI1 >= NET_TX_QUEUE_CAPACITY_CLI1 *NET_BUFFER_SIZE, "Client1 TX data region size must fit Client1 TX buffers"); -#define NET_RX_QUEUE_SIZE_DRIV 512 -#define NET_RX_QUEUE_SIZE_CLI0 512 -#define NET_RX_QUEUE_SIZE_CLI1 512 -#define NET_MAX_CLIENT_QUEUE_SIZE MAX(NET_RX_QUEUE_SIZE_CLI0, NET_RX_QUEUE_SIZE_CLI1) -#define NET_RX_QUEUE_SIZE_COPY0 NET_RX_QUEUE_SIZE_DRIV -#define NET_RX_QUEUE_SIZE_COPY1 NET_RX_QUEUE_SIZE_DRIV +#define NET_RX_QUEUE_CAPACITY_DRIV 512 +#define NET_RX_QUEUE_CAPACITY_CLI0 512 +#define NET_RX_QUEUE_CAPACITY_CLI1 512 +#define NET_MAX_CLIENT_QUEUE_CAPACITY MAX(NET_RX_QUEUE_CAPACITY_CLI0, NET_RX_QUEUE_CAPACITY_CLI1) +#define NET_RX_QUEUE_CAPACITY_COPY0 NET_RX_QUEUE_CAPACITY_DRIV +#define NET_RX_QUEUE_CAPACITY_COPY1 NET_RX_QUEUE_CAPACITY_DRIV #define NET_RX_DATA_REGION_SIZE_DRIV NET_DATA_REGION_SIZE #define NET_RX_DATA_REGION_SIZE_CLI0 NET_DATA_REGION_SIZE #define NET_RX_DATA_REGION_SIZE_CLI1 NET_DATA_REGION_SIZE -_Static_assert(NET_RX_DATA_REGION_SIZE_DRIV >= NET_RX_QUEUE_SIZE_DRIV *NET_BUFFER_SIZE, +_Static_assert(NET_RX_DATA_REGION_SIZE_DRIV >= NET_RX_QUEUE_CAPACITY_DRIV *NET_BUFFER_SIZE, "Driver RX data region size must fit Driver RX buffers"); -_Static_assert(NET_RX_DATA_REGION_SIZE_CLI0 >= NET_RX_QUEUE_SIZE_CLI0 *NET_BUFFER_SIZE, +_Static_assert(NET_RX_DATA_REGION_SIZE_CLI0 >= NET_RX_QUEUE_CAPACITY_CLI0 *NET_BUFFER_SIZE, "Client0 RX data region size must fit Client0 RX buffers"); -_Static_assert(NET_RX_DATA_REGION_SIZE_CLI1 >= NET_RX_QUEUE_SIZE_CLI1 *NET_BUFFER_SIZE, +_Static_assert(NET_RX_DATA_REGION_SIZE_CLI1 >= NET_RX_QUEUE_CAPACITY_CLI1 *NET_BUFFER_SIZE, "Client1 RX data region size must fit Client1 RX buffers"); -#define NET_MAX_QUEUE_SIZE MAX(NET_TX_QUEUE_SIZE_DRIV, MAX(NET_RX_QUEUE_SIZE_DRIV, MAX(NET_RX_QUEUE_SIZE_CLI0, NET_RX_QUEUE_SIZE_CLI1))) -_Static_assert(NET_TX_QUEUE_SIZE_DRIV >= NET_TX_QUEUE_SIZE_CLI0 + NET_TX_QUEUE_SIZE_CLI1, +#define NET_MAX_QUEUE_CAPACITY MAX(NET_TX_QUEUE_CAPACITY_DRIV, MAX(NET_RX_QUEUE_CAPACITY_DRIV, MAX(NET_RX_QUEUE_CAPACITY_CLI0, NET_RX_QUEUE_CAPACITY_CLI1))) +_Static_assert(NET_TX_QUEUE_CAPACITY_DRIV >= NET_TX_QUEUE_CAPACITY_CLI0 + NET_TX_QUEUE_CAPACITY_CLI1, "Driver TX queue must have capacity to fit all of client's TX buffers."); -_Static_assert(NET_RX_QUEUE_SIZE_COPY0 >= NET_RX_QUEUE_SIZE_DRIV, +_Static_assert(NET_RX_QUEUE_CAPACITY_COPY0 >= NET_RX_QUEUE_CAPACITY_DRIV, "Copy0 queues must have capacity to fit all RX buffers."); -_Static_assert(NET_RX_QUEUE_SIZE_COPY1 >= NET_RX_QUEUE_SIZE_DRIV, +_Static_assert(NET_RX_QUEUE_CAPACITY_COPY1 >= NET_RX_QUEUE_CAPACITY_DRIV, "Copy1 queues must have capacity to fit all RX buffers."); -_Static_assert(sizeof(net_queue_t) + NET_MAX_QUEUE_SIZE *sizeof(net_buff_desc_t) <= NET_DATA_REGION_SIZE, +_Static_assert(sizeof(net_queue_t) + NET_MAX_QUEUE_CAPACITY *sizeof(net_buff_desc_t) <= NET_DATA_REGION_SIZE, "net_queue_t must fit into a single data region."); static inline uint64_t net_cli_mac_addr(char *pd_name) @@ -102,32 +102,32 @@ static inline void net_virt_mac_addrs(char *pd_name, uint64_t macs[NUM_NETWORK_C } } -static inline void net_cli_queue_size(char *pd_name, size_t *rx_queue_size, size_t *tx_queue_size) +static inline void net_cli_queue_capacity(char *pd_name, size_t *rx_queue_capacity, size_t *tx_queue_capacity) { if (!sddf_strcmp(pd_name, NET_CLI0_NAME)) { - *rx_queue_size = NET_RX_QUEUE_SIZE_CLI0; - *tx_queue_size = NET_TX_QUEUE_SIZE_CLI0; + *rx_queue_capacity = NET_RX_QUEUE_CAPACITY_CLI0; + *tx_queue_capacity = NET_TX_QUEUE_CAPACITY_CLI0; } else if (!sddf_strcmp(pd_name, NET_CLI1_NAME)) { - *rx_queue_size = NET_RX_QUEUE_SIZE_CLI1; - *tx_queue_size = NET_TX_QUEUE_SIZE_CLI1; + *rx_queue_capacity = NET_RX_QUEUE_CAPACITY_CLI1; + *tx_queue_capacity = NET_TX_QUEUE_CAPACITY_CLI1; } } -static inline void net_copy_queue_size(char *pd_name, size_t *cli_queue_size, size_t *virt_queue_size) +static inline void net_copy_queue_capacity(char *pd_name, size_t *cli_queue_capacity, size_t *virt_queue_capacity) { if (!sddf_strcmp(pd_name, NET_COPY0_NAME)) { - *cli_queue_size = NET_RX_QUEUE_SIZE_CLI0; - *virt_queue_size = NET_RX_QUEUE_SIZE_COPY0; + *cli_queue_capacity = NET_RX_QUEUE_CAPACITY_CLI0; + *virt_queue_capacity = NET_RX_QUEUE_CAPACITY_COPY0; } else if (!sddf_strcmp(pd_name, NET_COPY1_NAME)) { - *cli_queue_size = NET_RX_QUEUE_SIZE_CLI1; - *virt_queue_size = NET_RX_QUEUE_SIZE_COPY1; + *cli_queue_capacity = NET_RX_QUEUE_CAPACITY_CLI1; + *virt_queue_capacity = NET_RX_QUEUE_CAPACITY_COPY1; } } typedef struct net_queue_info { net_queue_t *free; net_queue_t *active; - size_t size; + size_t capacity; } net_queue_info_t; static inline void net_virt_queue_info(char *pd_name, net_queue_t *cli0_free, net_queue_t *cli0_active, @@ -135,21 +135,21 @@ static inline void net_virt_queue_info(char *pd_name, net_queue_t *cli0_free, ne { if (!sddf_strcmp(pd_name, NET_VIRT_RX_NAME)) { ret[0] = (net_queue_info_t) { - .free = cli0_free, .active = cli0_active, .size = NET_RX_QUEUE_SIZE_COPY0 + .free = cli0_free, .active = cli0_active, .capacity = NET_RX_QUEUE_CAPACITY_COPY0 }; ret[1] = (net_queue_info_t) { .free = (net_queue_t *)((uintptr_t)cli0_free + 2 * NET_DATA_REGION_SIZE), .active = (net_queue_t *)((uintptr_t)cli0_active + 2 * NET_DATA_REGION_SIZE), - .size = NET_RX_QUEUE_SIZE_COPY1 + .capacity = NET_RX_QUEUE_CAPACITY_COPY1 }; } else if (!sddf_strcmp(pd_name, NET_VIRT_TX_NAME)) { ret[0] = (net_queue_info_t) { - .free = cli0_free, .active = cli0_active, .size = NET_TX_QUEUE_SIZE_CLI0 + .free = cli0_free, .active = cli0_active, .capacity = NET_TX_QUEUE_CAPACITY_CLI0 }; ret[1] = (net_queue_info_t) { .free = (net_queue_t *)((uintptr_t)cli0_free + 2 * NET_DATA_REGION_SIZE), .active = (net_queue_t *)((uintptr_t)cli0_active + 2 * NET_DATA_REGION_SIZE), - .size = NET_TX_QUEUE_SIZE_CLI1 + .capacity = NET_TX_QUEUE_CAPACITY_CLI1 }; } } diff --git a/examples/echo_server/lwip.c b/examples/echo_server/lwip.c index 7f21022cd..54bfe0b29 100644 --- a/examples/echo_server/lwip.c +++ b/examples/echo_server/lwip.c @@ -38,7 +38,7 @@ 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 +#define NUM_PBUFFS NET_MAX_CLIENT_QUEUE_CAPACITY net_queue_t *rx_free; net_queue_t *rx_active; @@ -289,10 +289,10 @@ 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); + size_t rx_capacity, tx_capacity; + net_cli_queue_capacity(microkit_name, &rx_capacity, &tx_capacity); + net_queue_init(&state.rx_queue, rx_free, rx_active, rx_capacity); + net_queue_init(&state.tx_queue, tx_free, tx_active, tx_capacity); net_buffers_init(&state.tx_queue, 0); lwip_init(); diff --git a/examples/echo_server/tcp_echo_socket.c b/examples/echo_server/tcp_echo_socket.c index 69f5bd302..2e4e650b6 100644 --- a/examples/echo_server/tcp_echo_socket.c +++ b/examples/echo_server/tcp_echo_socket.c @@ -13,15 +13,15 @@ #include -// At most ECHO_QUEUE_SIZE - 1 bytes can be in the queue -#define ECHO_QUEUE_SIZE (TCP_WND + 1) +// At most ECHO_QUEUE_CAPACITY - 1 bytes can be in the queue +#define ECHO_QUEUE_CAPACITY (TCP_WND + 1) struct echo_state { bool in_use; // sending ring buffer size_t tail; // data gets added at tail size_t head; // moved forward for acknowledged data - char buf[ECHO_QUEUE_SIZE]; + char buf[ECHO_QUEUE_CAPACITY]; }; // This previously was a LWIP_MEMPOOL, but turns out that doesn't support sizes @@ -49,13 +49,13 @@ static void tcp_state_free(struct echo_state *state) static size_t queue_space(struct echo_state *state) { - return (state->head + ECHO_QUEUE_SIZE - state->tail - 1) % ECHO_QUEUE_SIZE; + return (state->head + ECHO_QUEUE_CAPACITY - state->tail - 1) % ECHO_QUEUE_CAPACITY; } static size_t queue_cont_space(struct echo_state *state) { if (state->tail >= state->head) { - return ECHO_QUEUE_SIZE - state->tail; + return ECHO_QUEUE_CAPACITY - state->tail; } return state->head - state->tail - 1; } @@ -65,7 +65,7 @@ static err_t tcp_echo_sent(void *arg, struct tcp_pcb *pcb, u16_t len) struct echo_state *state = arg; assert(state != NULL); - state->head = (state->head + len) % ECHO_QUEUE_SIZE; + state->head = (state->head + len) % ECHO_QUEUE_CAPACITY; // tcp_recved is only for increasing the TCP window, and isn't required to // ACK incoming packets (that is done automatically on receive). @@ -144,7 +144,7 @@ static err_t tcp_echo_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t } offset += copied_len; - state->tail = (state->tail + copied_len) % ECHO_QUEUE_SIZE; + state->tail = (state->tail + copied_len) % ECHO_QUEUE_CAPACITY; } tcp_output(pcb); diff --git a/include/sddf/network/queue.h b/include/sddf/network/queue.h index 5fce6d8f2..fd31ff7c5 100644 --- a/include/sddf/network/queue.h +++ b/include/sddf/network/queue.h @@ -36,18 +36,18 @@ typedef struct net_queue_handle { net_queue_t *free; /* filled buffers */ net_queue_t *active; - /* size of the queues */ - uint32_t size; + /* capacity of the queues */ + uint32_t capacity; } net_queue_handle_t; /** * Get the number of buffers enqueued into a queue. * - * @param queue queue handle for the queue to get the size of. + * @param queue queue handle for the queue to get the length of. * * @return number of buffers enqueued into a queue. */ -static inline uint16_t net_queue_size(net_queue_t *queue) +static inline uint16_t net_queue_length(net_queue_t *queue) { return queue->tail - queue->head; } @@ -79,13 +79,13 @@ static inline bool net_queue_empty_active(net_queue_handle_t *queue) /** * Check if the free queue is full. * - * @param queue queue handle t for the free queue to check. + * @param queue queue handle for the free queue to check. * * @return true indicates the queue is full, false otherwise. */ static inline bool net_queue_full_free(net_queue_handle_t *queue) { - return queue->free->tail + 1 - queue->free->head == queue->size; + return queue->free->tail + 1 - queue->free->head == queue->capacity; } /** @@ -97,7 +97,7 @@ static inline bool net_queue_full_free(net_queue_handle_t *queue) */ static inline bool net_queue_full_active(net_queue_handle_t *queue) { - return queue->active->tail + 1 - queue->active->head == queue->size; + return queue->active->tail + 1 - queue->active->head == queue->capacity; } /** @@ -114,7 +114,7 @@ static inline int net_enqueue_free(net_queue_handle_t *queue, net_buff_desc_t bu return -1; } - queue->free->buffers[queue->free->tail % queue->size] = buffer; + queue->free->buffers[queue->free->tail % queue->capacity] = buffer; #ifdef CONFIG_ENABLE_SMP_SUPPORT THREAD_MEMORY_RELEASE(); #endif @@ -137,7 +137,7 @@ static inline int net_enqueue_active(net_queue_handle_t *queue, net_buff_desc_t return -1; } - queue->active->buffers[queue->active->tail % queue->size] = buffer; + queue->active->buffers[queue->active->tail % queue->capacity] = buffer; #ifdef CONFIG_ENABLE_SMP_SUPPORT THREAD_MEMORY_RELEASE(); #endif @@ -160,7 +160,7 @@ static inline int net_dequeue_free(net_queue_handle_t *queue, net_buff_desc_t *b return -1; } - *buffer = queue->free->buffers[queue->free->head % queue->size]; + *buffer = queue->free->buffers[queue->free->head % queue->capacity]; #ifdef CONFIG_ENABLE_SMP_SUPPORT THREAD_MEMORY_RELEASE(); #endif @@ -183,7 +183,7 @@ static inline int net_dequeue_active(net_queue_handle_t *queue, net_buff_desc_t return -1; } - *buffer = queue->active->buffers[queue->active->head % queue->size]; + *buffer = queue->active->buffers[queue->active->head % queue->capacity]; #ifdef CONFIG_ENABLE_SMP_SUPPORT THREAD_MEMORY_RELEASE(); #endif @@ -198,13 +198,13 @@ static inline int net_dequeue_active(net_queue_handle_t *queue, net_buff_desc_t * @param queue queue handle to use. * @param free pointer to free queue in shared memory. * @param active pointer to active queue in shared memory. - * @param size size of the free and active queues. + * @param capacity capacity of the free and active queues. */ -static inline void net_queue_init(net_queue_handle_t *queue, net_queue_t *free, net_queue_t *active, uint32_t size) +static inline void net_queue_init(net_queue_handle_t *queue, net_queue_t *free, net_queue_t *active, uint32_t capacity) { queue->free = free; queue->active = active; - queue->size = size; + queue->capacity = capacity; } /** @@ -215,7 +215,7 @@ static inline void net_queue_init(net_queue_handle_t *queue, net_queue_t *free, */ static inline void net_buffers_init(net_queue_handle_t *queue, uintptr_t base_addr) { - for (uint32_t i = 0; i < queue->size - 1; i++) { + for (uint32_t i = 0; i < queue->capacity - 1; i++) { net_buff_desc_t buffer = {(NET_BUFFER_SIZE * i) + base_addr, 0}; int err = net_enqueue_free(queue, buffer); assert(!err); diff --git a/network/components/copy.c b/network/components/copy.c index cee16a3fb..9a9efe195 100644 --- a/network/components/copy.c +++ b/network/components/copy.c @@ -36,7 +36,7 @@ void rx_return(void) int err = net_dequeue_free(&rx_queue_cli, &cli_buffer); assert(!err); - if (cli_buffer.io_or_offset % NET_BUFFER_SIZE || cli_buffer.io_or_offset >= NET_BUFFER_SIZE * rx_queue_cli.size) { + if (cli_buffer.io_or_offset % NET_BUFFER_SIZE || cli_buffer.io_or_offset >= NET_BUFFER_SIZE * rx_queue_cli.capacity) { sddf_dprintf("COPY|LOG: Client provided offset %lx which is not buffer aligned or outside of buffer region\n", cli_buffer.io_or_offset); continue; @@ -97,12 +97,12 @@ void notified(microkit_channel ch) void init(void) { - size_t cli_queue_size, virt_queue_size = 0; - net_copy_queue_size(microkit_name, &cli_queue_size, &virt_queue_size); + size_t cli_queue_capacity, virt_queue_capacity = 0; + net_copy_queue_capacity(microkit_name, &cli_queue_capacity, &virt_queue_capacity); /* Set up the queues */ - net_queue_init(&rx_queue_cli, rx_free_cli, rx_active_cli, cli_queue_size); - net_queue_init(&rx_queue_virt, rx_free_virt, rx_active_virt, virt_queue_size); + net_queue_init(&rx_queue_cli, rx_free_cli, rx_active_cli, cli_queue_capacity); + net_queue_init(&rx_queue_virt, rx_free_virt, rx_active_virt, virt_queue_capacity); net_buffers_init(&rx_queue_cli, 0); } diff --git a/network/components/virt_rx.c b/network/components/virt_rx.c index cddfc0986..ef3b8e2cc 100644 --- a/network/components/virt_rx.c +++ b/network/components/virt_rx.c @@ -35,7 +35,7 @@ uintptr_t buffer_data_paddr; /* In order to handle broadcast packets where the same buffer is given to multiple clients * we keep track of a reference count of each buffer and only hand it back to the driver once * all clients have returned the buffer. */ -uint32_t buffer_refs[NET_RX_QUEUE_SIZE_DRIV] = {0}; +uint32_t buffer_refs[NET_RX_QUEUE_CAPACITY_DRIV] = {0}; typedef struct state { net_queue_handle_t rx_queue_drv; @@ -157,7 +157,7 @@ void rx_provide(void) int err = net_dequeue_free(&state.rx_queue_clients[client], &buffer); assert(!err); assert(!(buffer.io_or_offset % NET_BUFFER_SIZE) && - (buffer.io_or_offset < NET_BUFFER_SIZE * state.rx_queue_clients[client].size)); + (buffer.io_or_offset < NET_BUFFER_SIZE * state.rx_queue_clients[client].capacity)); int ref_index = buffer.io_or_offset / NET_BUFFER_SIZE; assert(buffer_refs[ref_index] != 0); @@ -213,11 +213,11 @@ void init(void) for (int i = 0; i < NUM_NETWORK_CLIENTS; i++) { net_set_mac_addr((uint8_t *) &state.mac_addrs[i], macs[i]); net_queue_init(&state.rx_queue_clients[i], queue_info[i].free, queue_info[i].active, - queue_info[i].size); + queue_info[i].capacity); } /* Set up driver queues */ - net_queue_init(&state.rx_queue_drv, rx_free_drv, rx_active_drv, NET_RX_QUEUE_SIZE_DRIV); + net_queue_init(&state.rx_queue_drv, rx_free_drv, rx_active_drv, NET_RX_QUEUE_CAPACITY_DRIV); net_buffers_init(&state.rx_queue_drv, buffer_data_paddr); if (net_require_signal_free(&state.rx_queue_drv)) { diff --git a/network/components/virt_tx.c b/network/components/virt_tx.c index dabc275fb..a8aec241f 100644 --- a/network/components/virt_tx.c +++ b/network/components/virt_tx.c @@ -35,7 +35,7 @@ int extract_offset(uintptr_t *phys) { for (int client = 0; client < NUM_NETWORK_CLIENTS; client++) { if (*phys >= state.buffer_region_paddrs[client] && - *phys < state.buffer_region_paddrs[client] + state.tx_queue_clients[client].size * NET_BUFFER_SIZE) { + *phys < state.buffer_region_paddrs[client] + state.tx_queue_clients[client].capacity * NET_BUFFER_SIZE) { *phys = *phys - state.buffer_region_paddrs[client]; return client; } @@ -55,7 +55,7 @@ void tx_provide(void) assert(!err); if (buffer.io_or_offset % NET_BUFFER_SIZE || - buffer.io_or_offset >= NET_BUFFER_SIZE * state.tx_queue_clients[client].size) { + buffer.io_or_offset >= NET_BUFFER_SIZE * state.tx_queue_clients[client].capacity) { sddf_dprintf("VIRT_TX|LOG: Client provided offset %lx which is not buffer aligned or outside of buffer region\n", buffer.io_or_offset); err = net_enqueue_free(&state.tx_queue_clients[client], buffer); @@ -132,7 +132,7 @@ void notified(microkit_channel ch) void init(void) { /* Set up driver queues */ - net_queue_init(&state.tx_queue_drv, tx_free_drv, tx_active_drv, NET_TX_QUEUE_SIZE_DRIV); + net_queue_init(&state.tx_queue_drv, tx_free_drv, tx_active_drv, NET_TX_QUEUE_CAPACITY_DRIV); /* Setup client queues and state */ net_queue_info_t queue_info[NUM_NETWORK_CLIENTS] = {0}; @@ -142,7 +142,7 @@ void init(void) for (int i = 0; i < NUM_NETWORK_CLIENTS; i++) { net_queue_init(&state.tx_queue_clients[i], queue_info[i].free, queue_info[i].active, - queue_info[i].size); + queue_info[i].capacity); state.buffer_region_vaddrs[i] = client_vaddrs[i]; } From a1ae302fe8972001c3cd5d6c8ea36bc6b8637c52 Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Sun, 22 Sep 2024 23:46:17 +1000 Subject: [PATCH 2/3] Rename serial size fields to capacity Signed-off-by: Courtney Darville --- drivers/serial/arm/uart.c | 6 +-- drivers/serial/imx/uart.c | 6 +-- drivers/serial/meson/uart.c | 6 +-- drivers/serial/snps/uart.c | 4 +- .../include/serial_config/serial_config.h | 36 +++++++-------- .../include/serial_config/serial_config.h | 46 +++++++++---------- include/sddf/serial/queue.h | 40 ++++++++-------- serial/components/virt_rx.c | 4 +- serial/components/virt_tx.c | 2 +- 9 files changed, 75 insertions(+), 75 deletions(-) diff --git a/drivers/serial/arm/uart.c b/drivers/serial/arm/uart.c index f974cd2d7..ccf305532 100644 --- a/drivers/serial/arm/uart.c +++ b/drivers/serial/arm/uart.c @@ -175,9 +175,9 @@ void init(void) uart_setup(); #if !SERIAL_TX_ONLY - serial_queue_init(&rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_SIZE_DRIV, rx_data); + serial_queue_init(&rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_CAPACITY_DRIV, rx_data); #endif - serial_queue_init(&tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_DRIV, tx_data); + serial_queue_init(&tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_CAPACITY_DRIV, tx_data); } void notified(microkit_channel ch) @@ -198,4 +198,4 @@ void notified(microkit_channel ch) sddf_dprintf("UART|LOG: received notification on unexpected channel: %u\n", ch); break; } -} \ No newline at end of file +} diff --git a/drivers/serial/imx/uart.c b/drivers/serial/imx/uart.c index 37cceeb5d..1466f9665 100644 --- a/drivers/serial/imx/uart.c +++ b/drivers/serial/imx/uart.c @@ -181,9 +181,9 @@ void init(void) uart_setup(); #if !SERIAL_TX_ONLY - serial_queue_init(&rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_SIZE_DRIV, rx_data); + serial_queue_init(&rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_CAPACITY_DRIV, rx_data); #endif - serial_queue_init(&tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_DRIV, tx_data); + serial_queue_init(&tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_CAPACITY_DRIV, tx_data); } void notified(microkit_channel ch) @@ -204,4 +204,4 @@ void notified(microkit_channel ch) sddf_dprintf("UART|LOG: received notification on unexpected channel: %u\n", ch); break; } -} \ No newline at end of file +} diff --git a/drivers/serial/meson/uart.c b/drivers/serial/meson/uart.c index 8775c21b6..8ccb78883 100644 --- a/drivers/serial/meson/uart.c +++ b/drivers/serial/meson/uart.c @@ -206,9 +206,9 @@ void init(void) uart_setup(); #if !SERIAL_TX_ONLY - serial_queue_init(&rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_SIZE_DRIV, rx_data); + serial_queue_init(&rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_CAPACITY_DRIV, rx_data); #endif - serial_queue_init(&tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_DRIV, tx_data); + serial_queue_init(&tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_CAPACITY_DRIV, tx_data); } void notified(microkit_channel ch) @@ -229,4 +229,4 @@ void notified(microkit_channel ch) sddf_dprintf("UART|LOG: received notification on unexpected channel: %u\n", ch); break; } -} \ No newline at end of file +} diff --git a/drivers/serial/snps/uart.c b/drivers/serial/snps/uart.c index 706215bba..7476afb01 100644 --- a/drivers/serial/snps/uart.c +++ b/drivers/serial/snps/uart.c @@ -170,9 +170,9 @@ void init(void) *REG_PTR(UART_IER) = (UART_IER_ERBFI | UART_IER_ETBEI); #if !SERIAL_TX_ONLY - serial_queue_init(&rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_SIZE_DRIV, rx_data); + serial_queue_init(&rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_CAPACITY_DRIV, rx_data); #endif - serial_queue_init(&tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_DRIV, tx_data); + serial_queue_init(&tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_CAPACITY_DRIV, tx_data); } void notified(microkit_channel ch) diff --git a/examples/echo_server/include/serial_config/serial_config.h b/examples/echo_server/include/serial_config/serial_config.h index 0aad9c143..be901af55 100644 --- a/examples/echo_server/include/serial_config/serial_config.h +++ b/examples/echo_server/include/serial_config/serial_config.h @@ -33,22 +33,22 @@ #define SERIAL_CLI2_NAME "bench" #define SERIAL_VIRT_TX_NAME "serial_virt_tx" -#define SERIAL_QUEUE_SIZE 0x1000 -#define SERIAL_DATA_REGION_SIZE 0x2000 +#define SERIAL_QUEUE_SIZE 0x1000 +#define SERIAL_DATA_REGION_CAPACITY 0x2000 -#define SERIAL_TX_DATA_REGION_SIZE_DRIV (2 * SERIAL_DATA_REGION_SIZE) -#define SERIAL_TX_DATA_REGION_SIZE_CLI0 SERIAL_DATA_REGION_SIZE -#define SERIAL_TX_DATA_REGION_SIZE_CLI1 SERIAL_DATA_REGION_SIZE -#define SERIAL_TX_DATA_REGION_SIZE_CLI2 SERIAL_DATA_REGION_SIZE +#define SERIAL_TX_DATA_REGION_CAPACITY_DRIV (2 * SERIAL_DATA_REGION_CAPACITY) +#define SERIAL_TX_DATA_REGION_CAPACITY_CLI0 SERIAL_DATA_REGION_CAPACITY +#define SERIAL_TX_DATA_REGION_CAPACITY_CLI1 SERIAL_DATA_REGION_CAPACITY +#define SERIAL_TX_DATA_REGION_CAPACITY_CLI2 SERIAL_DATA_REGION_CAPACITY -#define SERIAL_MAX_CLIENT_TX_DATA_SIZE MAX(SERIAL_TX_DATA_REGION_SIZE_CLI2, MAX(SERIAL_TX_DATA_REGION_SIZE_CLI0, SERIAL_TX_DATA_REGION_SIZE_CLI1)) +#define SERIAL_MAX_CLIENT_TX_DATA_CAPACITY MAX(SERIAL_TX_DATA_REGION_CAPACITY_CLI2, MAX(SERIAL_TX_DATA_REGION_CAPACITY_CLI0, SERIAL_TX_DATA_REGION_CAPACITY_CLI1)) #if SERIAL_WITH_COLOUR -_Static_assert(SERIAL_TX_DATA_REGION_SIZE_DRIV > SERIAL_MAX_CLIENT_TX_DATA_SIZE, +_Static_assert(SERIAL_TX_DATA_REGION_CAPACITY_DRIV > SERIAL_MAX_CLIENT_TX_DATA_CAPACITY, "Driver TX data region must be larger than all client data regions in SERIAL_WITH_COLOUR mode."); #endif -#define SERIAL_MAX_DATA_SIZE MAX(SERIAL_TX_DATA_REGION_SIZE_DRIV, SERIAL_MAX_CLIENT_TX_DATA_SIZE) -_Static_assert(SERIAL_MAX_DATA_SIZE < UINT32_MAX, +#define SERIAL_MAX_DATA_CAPACITY MAX(SERIAL_TX_DATA_REGION_CAPACITY_DRIV, SERIAL_MAX_CLIENT_TX_DATA_CAPACITY) +_Static_assert(SERIAL_MAX_DATA_CAPACITY < UINT32_MAX, "Data regions must be smaller than UINT32 max to correctly use queue data structure."); static inline void serial_cli_queue_init_sys(char *pd_name, serial_queue_handle_t *rx_queue_handle, @@ -56,11 +56,11 @@ static inline void serial_cli_queue_init_sys(char *pd_name, serial_queue_handle_ char *rx_data, serial_queue_handle_t *tx_queue_handle, serial_queue_t *tx_queue, char *tx_data) { if (!sddf_strcmp(pd_name, SERIAL_CLI0_NAME)) { - serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_CLI0, tx_data); + serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_CAPACITY_CLI0, tx_data); } else if (!sddf_strcmp(pd_name, SERIAL_CLI1_NAME)) { - serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_CLI1, tx_data); + serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_CAPACITY_CLI1, tx_data); } else if (!sddf_strcmp(pd_name, SERIAL_CLI2_NAME)) { - serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_CLI2, tx_data); + serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_CAPACITY_CLI2, tx_data); } } @@ -68,12 +68,12 @@ static inline void serial_virt_queue_init_sys(char *pd_name, serial_queue_handle serial_queue_t *cli_queue, char *cli_data) { if (!sddf_strcmp(pd_name, SERIAL_VIRT_TX_NAME)) { - serial_queue_init(cli_queue_handle, cli_queue, SERIAL_TX_DATA_REGION_SIZE_CLI0, cli_data); + serial_queue_init(cli_queue_handle, cli_queue, SERIAL_TX_DATA_REGION_CAPACITY_CLI0, cli_data); serial_queue_init(&cli_queue_handle[1], (serial_queue_t *)((uintptr_t)cli_queue + SERIAL_QUEUE_SIZE), - SERIAL_TX_DATA_REGION_SIZE_CLI1, cli_data + SERIAL_TX_DATA_REGION_SIZE_CLI0); + SERIAL_TX_DATA_REGION_CAPACITY_CLI1, cli_data + SERIAL_TX_DATA_REGION_CAPACITY_CLI0); serial_queue_init(&cli_queue_handle[2], (serial_queue_t *)((uintptr_t)cli_queue + 2 * SERIAL_QUEUE_SIZE), - SERIAL_TX_DATA_REGION_SIZE_CLI2, cli_data + SERIAL_TX_DATA_REGION_SIZE_CLI0 + - SERIAL_TX_DATA_REGION_SIZE_CLI1); + SERIAL_TX_DATA_REGION_CAPACITY_CLI2, cli_data + SERIAL_TX_DATA_REGION_CAPACITY_CLI0 + + SERIAL_TX_DATA_REGION_CAPACITY_CLI1); } } @@ -84,4 +84,4 @@ static inline void serial_channel_names_init(char **client_names) client_names[1] = SERIAL_CLI1_NAME; client_names[2] = SERIAL_CLI2_NAME; } -#endif \ No newline at end of file +#endif diff --git a/examples/serial/include/serial_config/serial_config.h b/examples/serial/include/serial_config/serial_config.h index b36f1afa0..eeb1f8a7b 100644 --- a/examples/serial/include/serial_config/serial_config.h +++ b/examples/serial/include/serial_config/serial_config.h @@ -36,27 +36,27 @@ #define SERIAL_VIRT_RX_NAME "serial_virt_rx" #define SERIAL_VIRT_TX_NAME "serial_virt_tx" -#define SERIAL_QUEUE_SIZE 0x1000 -#define SERIAL_DATA_REGION_SIZE 0x2000 +#define SERIAL_QUEUE_SIZE 0x1000 +#define SERIAL_DATA_REGION_CAPACITY 0x2000 -#define SERIAL_TX_DATA_REGION_SIZE_DRIV (2 * SERIAL_DATA_REGION_SIZE) -#define SERIAL_TX_DATA_REGION_SIZE_CLI0 SERIAL_DATA_REGION_SIZE -#define SERIAL_TX_DATA_REGION_SIZE_CLI1 SERIAL_DATA_REGION_SIZE +#define SERIAL_TX_DATA_REGION_CAPACITY_DRIV (2 * SERIAL_DATA_REGION_CAPACITY) +#define SERIAL_TX_DATA_REGION_CAPACITY_CLI0 SERIAL_DATA_REGION_CAPACITY +#define SERIAL_TX_DATA_REGION_CAPACITY_CLI1 SERIAL_DATA_REGION_CAPACITY -#define SERIAL_RX_DATA_REGION_SIZE_DRIV SERIAL_DATA_REGION_SIZE -#define SERIAL_RX_DATA_REGION_SIZE_CLI0 SERIAL_DATA_REGION_SIZE -#define SERIAL_RX_DATA_REGION_SIZE_CLI1 SERIAL_DATA_REGION_SIZE +#define SERIAL_RX_DATA_REGION_CAPACITY_DRIV SERIAL_DATA_REGION_CAPACITY +#define SERIAL_RX_DATA_REGION_CAPACITY_CLI0 SERIAL_DATA_REGION_CAPACITY +#define SERIAL_RX_DATA_REGION_CAPACITY_CLI1 SERIAL_DATA_REGION_CAPACITY -#define SERIAL_MAX_CLIENT_TX_DATA_SIZE MAX(SERIAL_TX_DATA_REGION_SIZE_CLI0, SERIAL_TX_DATA_REGION_SIZE_CLI1) +#define SERIAL_MAX_CLIENT_TX_DATA_CAPACITY MAX(SERIAL_TX_DATA_REGION_CAPACITY_CLI0, SERIAL_TX_DATA_REGION_CAPACITY_CLI1) #if SERIAL_WITH_COLOUR -_Static_assert(SERIAL_TX_DATA_REGION_SIZE_DRIV > SERIAL_MAX_CLIENT_TX_DATA_SIZE, +_Static_assert(SERIAL_TX_DATA_REGION_CAPACITY_DRIV > SERIAL_MAX_CLIENT_TX_DATA_CAPACITY, "Driver TX data region must be larger than all client data regions in SERIAL_WITH_COLOUR mode."); #endif -#define SERIAL_MAX_TX_DATA_SIZE MAX(SERIAL_TX_DATA_REGION_SIZE_DRIV, SERIAL_MAX_CLIENT_TX_DATA_SIZE) -#define SERIAL_MAX_RX_DATA_SIZE MAX(SERIAL_RX_DATA_REGION_SIZE_DRIV, MAX(SERIAL_RX_DATA_REGION_SIZE_CLI0, SERIAL_RX_DATA_REGION_SIZE_CLI1)) -#define SERIAL_MAX_DATA_SIZE MAX(SERIAL_MAX_TX_DATA_SIZE, SERIAL_MAX_RX_DATA_SIZE) -_Static_assert(SERIAL_MAX_DATA_SIZE < UINT32_MAX, +#define SERIAL_MAX_TX_DATA_CAPACITY MAX(SERIAL_TX_DATA_REGION_CAPACITY_DRIV, SERIAL_MAX_CLIENT_TX_DATA_CAPACITY) +#define SERIAL_MAX_RX_DATA_CAPACITY MAX(SERIAL_RX_DATA_REGION_CAPACITY_DRIV, MAX(SERIAL_RX_DATA_REGION_CAPACITY_CLI0, SERIAL_RX_DATA_REGION_CAPACITY_CLI1)) +#define SERIAL_MAX_DATA_CAPACITY MAX(SERIAL_MAX_TX_DATA_CAPACITY, SERIAL_MAX_RX_DATA_CAPACITY) +_Static_assert(SERIAL_MAX_DATA_CAPACITY < UINT32_MAX, "Data regions must be smaller than UINT32 max to correctly use queue data structure."); static inline void serial_cli_queue_init_sys(char *pd_name, serial_queue_handle_t *rx_queue_handle, @@ -64,11 +64,11 @@ static inline void serial_cli_queue_init_sys(char *pd_name, serial_queue_handle_ char *rx_data, serial_queue_handle_t *tx_queue_handle, serial_queue_t *tx_queue, char *tx_data) { if (!sddf_strcmp(pd_name, SERIAL_CLI0_NAME)) { - serial_queue_init(rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_SIZE_CLI0, rx_data); - serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_CLI0, tx_data); + serial_queue_init(rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_CAPACITY_CLI0, rx_data); + serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_CAPACITY_CLI0, tx_data); } else if (!sddf_strcmp(pd_name, SERIAL_CLI1_NAME)) { - serial_queue_init(rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_SIZE_CLI1, rx_data); - serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_CLI1, tx_data); + serial_queue_init(rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_CAPACITY_CLI1, rx_data); + serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_CAPACITY_CLI1, tx_data); } } @@ -76,13 +76,13 @@ static inline void serial_virt_queue_init_sys(char *pd_name, serial_queue_handle serial_queue_t *cli_queue, char *cli_data) { if (!sddf_strcmp(pd_name, SERIAL_VIRT_RX_NAME)) { - serial_queue_init(cli_queue_handle, cli_queue, SERIAL_RX_DATA_REGION_SIZE_CLI0, cli_data); + serial_queue_init(cli_queue_handle, cli_queue, SERIAL_RX_DATA_REGION_CAPACITY_CLI0, cli_data); serial_queue_init(&cli_queue_handle[1], (serial_queue_t *)((uintptr_t)cli_queue + SERIAL_QUEUE_SIZE), - SERIAL_RX_DATA_REGION_SIZE_CLI1, cli_data + SERIAL_RX_DATA_REGION_SIZE_CLI0); + SERIAL_RX_DATA_REGION_CAPACITY_CLI1, cli_data + SERIAL_RX_DATA_REGION_CAPACITY_CLI0); } else if (!sddf_strcmp(pd_name, SERIAL_VIRT_TX_NAME)) { - serial_queue_init(cli_queue_handle, cli_queue, SERIAL_TX_DATA_REGION_SIZE_CLI0, cli_data); + serial_queue_init(cli_queue_handle, cli_queue, SERIAL_TX_DATA_REGION_CAPACITY_CLI0, cli_data); serial_queue_init(&cli_queue_handle[1], (serial_queue_t *)((uintptr_t)cli_queue + SERIAL_QUEUE_SIZE), - SERIAL_TX_DATA_REGION_SIZE_CLI1, cli_data + SERIAL_TX_DATA_REGION_SIZE_CLI0); + SERIAL_TX_DATA_REGION_CAPACITY_CLI1, cli_data + SERIAL_TX_DATA_REGION_CAPACITY_CLI0); } } @@ -92,4 +92,4 @@ static inline void serial_channel_names_init(char **client_names) client_names[0] = SERIAL_CLI0_NAME; client_names[1] = SERIAL_CLI1_NAME; } -#endif \ No newline at end of file +#endif diff --git a/include/sddf/serial/queue.h b/include/sddf/serial/queue.h index 89916baeb..0baa299be 100644 --- a/include/sddf/serial/queue.h +++ b/include/sddf/serial/queue.h @@ -26,7 +26,7 @@ typedef struct serial_queue { typedef struct serial_queue_handle { serial_queue_t *queue; - uint32_t size; + uint32_t capacity; char *data_region; } serial_queue_handle_t; @@ -53,7 +53,7 @@ static inline int serial_queue_empty(serial_queue_handle_t *queue_handle, uint32 */ static inline int serial_queue_full(serial_queue_handle_t *queue_handle, uint32_t local_tail) { - return local_tail - queue_handle->queue->head == queue_handle->size; + return local_tail - queue_handle->queue->head == queue_handle->capacity; } /** @@ -73,7 +73,7 @@ static inline int serial_enqueue(serial_queue_handle_t *queue_handle, uint32_t * return -1; } - queue_handle->data_region[*local_tail % queue_handle->size] = character; + queue_handle->data_region[*local_tail % queue_handle->capacity] = character; (*local_tail)++; return 0; @@ -96,7 +96,7 @@ static inline int serial_dequeue(serial_queue_handle_t *queue_handle, uint32_t * return -1; } - *character = queue_handle->data_region[*local_head % queue_handle->size]; + *character = queue_handle->data_region[*local_head % queue_handle->capacity]; (*local_head)++; return 0; @@ -114,7 +114,7 @@ static inline void serial_update_visible_tail(serial_queue_handle_t *queue_handl { uint32_t head = queue_handle->queue->head; uint32_t tail = queue_handle->queue->tail; - uint32_t max_tail = head + queue_handle->size; + uint32_t max_tail = head + queue_handle->capacity; /* Ensure updates to tail don't overwrite existing data */ if (head <= tail) { @@ -124,7 +124,7 @@ static inline void serial_update_visible_tail(serial_queue_handle_t *queue_handl assert(local_tail >= tail && local_tail < head); } - /* Ensure updates to tail don't exceed size restraints */ + /* Ensure updates to tail don't exceed capacity restraints */ if (head <= max_tail) { assert(local_tail <= max_tail); } else { @@ -152,7 +152,7 @@ static inline void serial_update_visible_head(serial_queue_handle_t *queue_handl uint32_t head = queue_handle->queue->head; uint32_t tail = queue_handle->queue->tail; - /* Ensure updates to head don't corrupt queue size constraints */ + /* Ensure updates to head don't corrupt queue capacity constraints */ if (head <= tail) { assert(local_head >= head && local_head <= tail); } else { @@ -189,7 +189,7 @@ static inline uint32_t serial_queue_length(serial_queue_handle_t *queue_handle) */ static inline uint32_t serial_queue_contiguous_length(serial_queue_handle_t *queue_handle) { - return MIN(queue_handle->size - (queue_handle->queue->head % queue_handle->size), serial_queue_length(queue_handle)); + return MIN(queue_handle->capacity - (queue_handle->queue->head % queue_handle->capacity), serial_queue_length(queue_handle)); } /** @@ -202,7 +202,7 @@ static inline uint32_t serial_queue_contiguous_length(serial_queue_handle_t *que */ static inline uint32_t serial_queue_free(serial_queue_handle_t *queue_handle) { - return queue_handle->size - serial_queue_length(queue_handle); + return queue_handle->capacity - serial_queue_length(queue_handle); } /** @@ -215,7 +215,7 @@ static inline uint32_t serial_queue_free(serial_queue_handle_t *queue_handle) */ static inline uint32_t serial_queue_contiguous_free(serial_queue_handle_t *queue_handle) { - return MIN(queue_handle->size - (queue_handle->queue->tail % queue_handle->size), serial_queue_free(queue_handle)); + return MIN(queue_handle->capacity - (queue_handle->queue->tail % queue_handle->capacity), serial_queue_free(queue_handle)); } /** @@ -231,7 +231,7 @@ static inline uint32_t serial_enqueue_batch(serial_queue_handle_t *qh, uint32_t n, const char *src) { - char *p = qh->data_region + (qh->queue->tail % qh->size); + char *p = qh->data_region + (qh->queue->tail % qh->capacity); uint32_t avail = serial_queue_free(qh); uint32_t n_prewrap; uint32_t n_postwrap; @@ -270,9 +270,9 @@ static inline void serial_transfer_all(serial_queue_handle_t *active_queue_handl uint32_t free = serial_queue_contiguous_free(free_queue_handle); uint32_t to_transfer = (active < free) ? active : free; - sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->size), + sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->capacity), active_queue_handle->data_region + (active_queue_handle->queue->head % - active_queue_handle->size), to_transfer); + active_queue_handle->capacity), to_transfer); /* Make copy visible */ serial_update_visible_tail(free_queue_handle, free_queue_handle->queue->tail + to_transfer); @@ -308,7 +308,7 @@ static inline void serial_transfer_all_with_colour(serial_queue_handle_t *active uint32_t free = serial_queue_contiguous_free(free_queue_handle); uint32_t to_transfer = (remaining < free) ? remaining : free; - sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->size), + sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->capacity), colour_start + colour_transferred, to_transfer); serial_update_visible_tail(free_queue_handle, free_queue_handle->queue->tail + to_transfer); @@ -321,9 +321,9 @@ static inline void serial_transfer_all_with_colour(serial_queue_handle_t *active uint32_t free = serial_queue_contiguous_free(free_queue_handle); uint32_t to_transfer = (active < free) ? active : free; - sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->size), + sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->capacity), active_queue_handle->data_region + (active_queue_handle->queue->head % - active_queue_handle->size), to_transfer); + active_queue_handle->capacity), to_transfer); /* Make copy visible */ serial_update_visible_tail(free_queue_handle, free_queue_handle->queue->tail + to_transfer); @@ -336,7 +336,7 @@ static inline void serial_transfer_all_with_colour(serial_queue_handle_t *active uint32_t free = serial_queue_contiguous_free(free_queue_handle); uint32_t to_transfer = (remaining < free) ? remaining : free; - sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->size), + sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->capacity), colour_end + colour_transferred, to_transfer); serial_update_visible_tail(free_queue_handle, free_queue_handle->queue->tail + to_transfer); @@ -349,14 +349,14 @@ static inline void serial_transfer_all_with_colour(serial_queue_handle_t *active * * @param queue_handle queue handle to use. * @param queue pointer to queue in shared memory. - * @param size size of the queue. + * @param capacity capacity of the queue. * @param data_region address of the data region. */ static inline void serial_queue_init(serial_queue_handle_t *queue_handle, - serial_queue_t *queue, uint32_t size, char *data_region) + serial_queue_t *queue, uint32_t capacity, char *data_region) { queue_handle->queue = queue; - queue_handle->size = size; + queue_handle->capacity = capacity; queue_handle->data_region = data_region; } diff --git a/serial/components/virt_rx.c b/serial/components/virt_rx.c index 9be58f1f3..4d107d1b5 100644 --- a/serial/components/virt_rx.c +++ b/serial/components/virt_rx.c @@ -128,7 +128,7 @@ void rx_return(void) void init(void) { - serial_queue_init(&rx_queue_handle_drv, rx_queue_drv, SERIAL_RX_DATA_REGION_SIZE_DRIV, rx_data_drv); + serial_queue_init(&rx_queue_handle_drv, rx_queue_drv, SERIAL_RX_DATA_REGION_CAPACITY_DRIV, rx_data_drv); serial_virt_queue_init_sys(microkit_name, rx_queue_handle_cli, rx_queue_cli0, rx_data_cli0); } @@ -142,4 +142,4 @@ void notified(microkit_channel ch) sddf_dprintf("VIRT_RX|LOG: received notification on unexpected channel: %u\n", ch); break; } -} \ No newline at end of file +} diff --git a/serial/components/virt_tx.c b/serial/components/virt_tx.c index b745f564c..167b20ac3 100644 --- a/serial/components/virt_tx.c +++ b/serial/components/virt_tx.c @@ -203,7 +203,7 @@ void tx_provide(microkit_channel ch) void init(void) { - serial_queue_init(&tx_queue_handle_drv, tx_queue_drv, SERIAL_TX_DATA_REGION_SIZE_DRIV, tx_data_drv); + serial_queue_init(&tx_queue_handle_drv, tx_queue_drv, SERIAL_TX_DATA_REGION_CAPACITY_DRIV, tx_data_drv); serial_virt_queue_init_sys(microkit_name, tx_queue_handle_cli, tx_queue_cli0, tx_data_cli0); #if !SERIAL_TX_ONLY From 8679e92e19ff64d8bec4b9ae0cf2c93eb0c1508f Mon Sep 17 00:00:00 2001 From: Courtney Darville Date: Mon, 23 Sep 2024 18:27:26 +1000 Subject: [PATCH 3/3] fix style Signed-off-by: Courtney Darville --- .../include/ethernet_config/ethernet_config.h | 38 ++++++++----------- .../include/serial_config/serial_config.h | 4 +- include/sddf/serial/queue.h | 20 ++++++---- network/components/copy.c | 3 +- network/components/virt_rx.c | 9 ++--- network/components/virt_tx.c | 11 +++--- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/examples/echo_server/include/ethernet_config/ethernet_config.h b/examples/echo_server/include/ethernet_config/ethernet_config.h index bcb7ac5ab..e9ce98bb4 100644 --- a/examples/echo_server/include/ethernet_config/ethernet_config.h +++ b/examples/echo_server/include/ethernet_config/ethernet_config.h @@ -50,9 +50,9 @@ #define NET_TX_DATA_REGION_SIZE_CLI0 NET_DATA_REGION_SIZE #define NET_TX_DATA_REGION_SIZE_CLI1 NET_DATA_REGION_SIZE -_Static_assert(NET_TX_DATA_REGION_SIZE_CLI0 >= NET_TX_QUEUE_CAPACITY_CLI0 *NET_BUFFER_SIZE, +_Static_assert(NET_TX_DATA_REGION_SIZE_CLI0 >= NET_TX_QUEUE_CAPACITY_CLI0 * NET_BUFFER_SIZE, "Client0 TX data region size must fit Client0 TX buffers"); -_Static_assert(NET_TX_DATA_REGION_SIZE_CLI1 >= NET_TX_QUEUE_CAPACITY_CLI1 *NET_BUFFER_SIZE, +_Static_assert(NET_TX_DATA_REGION_SIZE_CLI1 >= NET_TX_QUEUE_CAPACITY_CLI1 * NET_BUFFER_SIZE, "Client1 TX data region size must fit Client1 TX buffers"); #define NET_RX_QUEUE_CAPACITY_DRIV 512 @@ -66,11 +66,11 @@ _Static_assert(NET_TX_DATA_REGION_SIZE_CLI1 >= NET_TX_QUEUE_CAPACITY_CLI1 *NET_B #define NET_RX_DATA_REGION_SIZE_CLI0 NET_DATA_REGION_SIZE #define NET_RX_DATA_REGION_SIZE_CLI1 NET_DATA_REGION_SIZE -_Static_assert(NET_RX_DATA_REGION_SIZE_DRIV >= NET_RX_QUEUE_CAPACITY_DRIV *NET_BUFFER_SIZE, +_Static_assert(NET_RX_DATA_REGION_SIZE_DRIV >= NET_RX_QUEUE_CAPACITY_DRIV * NET_BUFFER_SIZE, "Driver RX data region size must fit Driver RX buffers"); -_Static_assert(NET_RX_DATA_REGION_SIZE_CLI0 >= NET_RX_QUEUE_CAPACITY_CLI0 *NET_BUFFER_SIZE, +_Static_assert(NET_RX_DATA_REGION_SIZE_CLI0 >= NET_RX_QUEUE_CAPACITY_CLI0 * NET_BUFFER_SIZE, "Client0 RX data region size must fit Client0 RX buffers"); -_Static_assert(NET_RX_DATA_REGION_SIZE_CLI1 >= NET_RX_QUEUE_CAPACITY_CLI1 *NET_BUFFER_SIZE, +_Static_assert(NET_RX_DATA_REGION_SIZE_CLI1 >= NET_RX_QUEUE_CAPACITY_CLI1 * NET_BUFFER_SIZE, "Client1 RX data region size must fit Client1 RX buffers"); #define NET_MAX_QUEUE_CAPACITY MAX(NET_TX_QUEUE_CAPACITY_DRIV, MAX(NET_RX_QUEUE_CAPACITY_DRIV, MAX(NET_RX_QUEUE_CAPACITY_CLI0, NET_RX_QUEUE_CAPACITY_CLI1))) @@ -80,7 +80,7 @@ _Static_assert(NET_RX_QUEUE_CAPACITY_COPY0 >= NET_RX_QUEUE_CAPACITY_DRIV, "Copy0 queues must have capacity to fit all RX buffers."); _Static_assert(NET_RX_QUEUE_CAPACITY_COPY1 >= NET_RX_QUEUE_CAPACITY_DRIV, "Copy1 queues must have capacity to fit all RX buffers."); -_Static_assert(sizeof(net_queue_t) + NET_MAX_QUEUE_CAPACITY *sizeof(net_buff_desc_t) <= NET_DATA_REGION_SIZE, +_Static_assert(sizeof(net_queue_t) + NET_MAX_QUEUE_CAPACITY * sizeof(net_buff_desc_t) <= NET_DATA_REGION_SIZE, "net_queue_t must fit into a single data region."); static inline uint64_t net_cli_mac_addr(char *pd_name) @@ -134,23 +134,17 @@ static inline void net_virt_queue_info(char *pd_name, net_queue_t *cli0_free, ne net_queue_info_t ret[NUM_NETWORK_CLIENTS]) { if (!sddf_strcmp(pd_name, NET_VIRT_RX_NAME)) { - ret[0] = (net_queue_info_t) { - .free = cli0_free, .active = cli0_active, .capacity = NET_RX_QUEUE_CAPACITY_COPY0 - }; - ret[1] = (net_queue_info_t) { - .free = (net_queue_t *)((uintptr_t)cli0_free + 2 * NET_DATA_REGION_SIZE), - .active = (net_queue_t *)((uintptr_t)cli0_active + 2 * NET_DATA_REGION_SIZE), - .capacity = NET_RX_QUEUE_CAPACITY_COPY1 - }; + ret[0] = + (net_queue_info_t) { .free = cli0_free, .active = cli0_active, .capacity = NET_RX_QUEUE_CAPACITY_COPY0 }; + ret[1] = (net_queue_info_t) { .free = (net_queue_t *)((uintptr_t)cli0_free + 2 * NET_DATA_REGION_SIZE), + .active = (net_queue_t *)((uintptr_t)cli0_active + 2 * NET_DATA_REGION_SIZE), + .capacity = NET_RX_QUEUE_CAPACITY_COPY1 }; } else if (!sddf_strcmp(pd_name, NET_VIRT_TX_NAME)) { - ret[0] = (net_queue_info_t) { - .free = cli0_free, .active = cli0_active, .capacity = NET_TX_QUEUE_CAPACITY_CLI0 - }; - ret[1] = (net_queue_info_t) { - .free = (net_queue_t *)((uintptr_t)cli0_free + 2 * NET_DATA_REGION_SIZE), - .active = (net_queue_t *)((uintptr_t)cli0_active + 2 * NET_DATA_REGION_SIZE), - .capacity = NET_TX_QUEUE_CAPACITY_CLI1 - }; + ret[0] = + (net_queue_info_t) { .free = cli0_free, .active = cli0_active, .capacity = NET_TX_QUEUE_CAPACITY_CLI0 }; + ret[1] = (net_queue_info_t) { .free = (net_queue_t *)((uintptr_t)cli0_free + 2 * NET_DATA_REGION_SIZE), + .active = (net_queue_t *)((uintptr_t)cli0_active + 2 * NET_DATA_REGION_SIZE), + .capacity = NET_TX_QUEUE_CAPACITY_CLI1 }; } } diff --git a/examples/echo_server/include/serial_config/serial_config.h b/examples/echo_server/include/serial_config/serial_config.h index be901af55..cd0e744a0 100644 --- a/examples/echo_server/include/serial_config/serial_config.h +++ b/examples/echo_server/include/serial_config/serial_config.h @@ -72,8 +72,8 @@ static inline void serial_virt_queue_init_sys(char *pd_name, serial_queue_handle serial_queue_init(&cli_queue_handle[1], (serial_queue_t *)((uintptr_t)cli_queue + SERIAL_QUEUE_SIZE), SERIAL_TX_DATA_REGION_CAPACITY_CLI1, cli_data + SERIAL_TX_DATA_REGION_CAPACITY_CLI0); serial_queue_init(&cli_queue_handle[2], (serial_queue_t *)((uintptr_t)cli_queue + 2 * SERIAL_QUEUE_SIZE), - SERIAL_TX_DATA_REGION_CAPACITY_CLI2, cli_data + SERIAL_TX_DATA_REGION_CAPACITY_CLI0 + - SERIAL_TX_DATA_REGION_CAPACITY_CLI1); + SERIAL_TX_DATA_REGION_CAPACITY_CLI2, + cli_data + SERIAL_TX_DATA_REGION_CAPACITY_CLI0 + SERIAL_TX_DATA_REGION_CAPACITY_CLI1); } } diff --git a/include/sddf/serial/queue.h b/include/sddf/serial/queue.h index 0baa299be..cafd845fb 100644 --- a/include/sddf/serial/queue.h +++ b/include/sddf/serial/queue.h @@ -189,7 +189,8 @@ static inline uint32_t serial_queue_length(serial_queue_handle_t *queue_handle) */ static inline uint32_t serial_queue_contiguous_length(serial_queue_handle_t *queue_handle) { - return MIN(queue_handle->capacity - (queue_handle->queue->head % queue_handle->capacity), serial_queue_length(queue_handle)); + return MIN(queue_handle->capacity - (queue_handle->queue->head % queue_handle->capacity), + serial_queue_length(queue_handle)); } /** @@ -215,7 +216,8 @@ static inline uint32_t serial_queue_free(serial_queue_handle_t *queue_handle) */ static inline uint32_t serial_queue_contiguous_free(serial_queue_handle_t *queue_handle) { - return MIN(queue_handle->capacity - (queue_handle->queue->tail % queue_handle->capacity), serial_queue_free(queue_handle)); + return MIN(queue_handle->capacity - (queue_handle->queue->tail % queue_handle->capacity), + serial_queue_free(queue_handle)); } /** @@ -271,8 +273,9 @@ static inline void serial_transfer_all(serial_queue_handle_t *active_queue_handl uint32_t to_transfer = (active < free) ? active : free; sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->capacity), - active_queue_handle->data_region + (active_queue_handle->queue->head % - active_queue_handle->capacity), to_transfer); + active_queue_handle->data_region + + (active_queue_handle->queue->head % active_queue_handle->capacity), + to_transfer); /* Make copy visible */ serial_update_visible_tail(free_queue_handle, free_queue_handle->queue->tail + to_transfer); @@ -322,8 +325,9 @@ static inline void serial_transfer_all_with_colour(serial_queue_handle_t *active uint32_t to_transfer = (active < free) ? active : free; sddf_memcpy(free_queue_handle->data_region + (free_queue_handle->queue->tail % free_queue_handle->capacity), - active_queue_handle->data_region + (active_queue_handle->queue->head % - active_queue_handle->capacity), to_transfer); + active_queue_handle->data_region + + (active_queue_handle->queue->head % active_queue_handle->capacity), + to_transfer); /* Make copy visible */ serial_update_visible_tail(free_queue_handle, free_queue_handle->queue->tail + to_transfer); @@ -352,8 +356,8 @@ static inline void serial_transfer_all_with_colour(serial_queue_handle_t *active * @param capacity capacity of the queue. * @param data_region address of the data region. */ -static inline void serial_queue_init(serial_queue_handle_t *queue_handle, - serial_queue_t *queue, uint32_t capacity, char *data_region) +static inline void serial_queue_init(serial_queue_handle_t *queue_handle, serial_queue_t *queue, uint32_t capacity, + char *data_region) { queue_handle->queue = queue; queue_handle->capacity = capacity; diff --git a/network/components/copy.c b/network/components/copy.c index 9a9efe195..e48bcf573 100644 --- a/network/components/copy.c +++ b/network/components/copy.c @@ -36,7 +36,8 @@ void rx_return(void) int err = net_dequeue_free(&rx_queue_cli, &cli_buffer); assert(!err); - if (cli_buffer.io_or_offset % NET_BUFFER_SIZE || cli_buffer.io_or_offset >= NET_BUFFER_SIZE * rx_queue_cli.capacity) { + if (cli_buffer.io_or_offset % NET_BUFFER_SIZE + || cli_buffer.io_or_offset >= NET_BUFFER_SIZE * rx_queue_cli.capacity) { sddf_dprintf("COPY|LOG: Client provided offset %lx which is not buffer aligned or outside of buffer region\n", cli_buffer.io_or_offset); continue; diff --git a/network/components/virt_rx.c b/network/components/virt_rx.c index ef3b8e2cc..d6f4a7067 100644 --- a/network/components/virt_rx.c +++ b/network/components/virt_rx.c @@ -35,7 +35,7 @@ uintptr_t buffer_data_paddr; /* In order to handle broadcast packets where the same buffer is given to multiple clients * we keep track of a reference count of each buffer and only hand it back to the driver once * all clients have returned the buffer. */ -uint32_t buffer_refs[NET_RX_QUEUE_CAPACITY_DRIV] = {0}; +uint32_t buffer_refs[NET_RX_QUEUE_CAPACITY_DRIV] = { 0 }; typedef struct state { net_queue_handle_t rx_queue_drv; @@ -156,8 +156,8 @@ void rx_provide(void) net_buff_desc_t buffer; int err = net_dequeue_free(&state.rx_queue_clients[client], &buffer); assert(!err); - assert(!(buffer.io_or_offset % NET_BUFFER_SIZE) && - (buffer.io_or_offset < NET_BUFFER_SIZE * state.rx_queue_clients[client].capacity)); + assert(!(buffer.io_or_offset % NET_BUFFER_SIZE) + && (buffer.io_or_offset < NET_BUFFER_SIZE * state.rx_queue_clients[client].capacity)); int ref_index = buffer.io_or_offset / NET_BUFFER_SIZE; assert(buffer_refs[ref_index] != 0); @@ -212,8 +212,7 @@ void init(void) /* Set up client queues */ for (int i = 0; i < NUM_NETWORK_CLIENTS; i++) { net_set_mac_addr((uint8_t *) &state.mac_addrs[i], macs[i]); - net_queue_init(&state.rx_queue_clients[i], queue_info[i].free, queue_info[i].active, - queue_info[i].capacity); + net_queue_init(&state.rx_queue_clients[i], queue_info[i].free, queue_info[i].active, queue_info[i].capacity); } /* Set up driver queues */ diff --git a/network/components/virt_tx.c b/network/components/virt_tx.c index a8aec241f..61615b0dc 100644 --- a/network/components/virt_tx.c +++ b/network/components/virt_tx.c @@ -34,8 +34,8 @@ state_t state; int extract_offset(uintptr_t *phys) { for (int client = 0; client < NUM_NETWORK_CLIENTS; client++) { - if (*phys >= state.buffer_region_paddrs[client] && - *phys < state.buffer_region_paddrs[client] + state.tx_queue_clients[client].capacity * NET_BUFFER_SIZE) { + if (*phys >= state.buffer_region_paddrs[client] + && *phys < state.buffer_region_paddrs[client] + state.tx_queue_clients[client].capacity * NET_BUFFER_SIZE) { *phys = *phys - state.buffer_region_paddrs[client]; return client; } @@ -54,8 +54,8 @@ void tx_provide(void) int err = net_dequeue_active(&state.tx_queue_clients[client], &buffer); assert(!err); - if (buffer.io_or_offset % NET_BUFFER_SIZE || - buffer.io_or_offset >= NET_BUFFER_SIZE * state.tx_queue_clients[client].capacity) { + if (buffer.io_or_offset % NET_BUFFER_SIZE + || buffer.io_or_offset >= NET_BUFFER_SIZE * state.tx_queue_clients[client].capacity) { sddf_dprintf("VIRT_TX|LOG: Client provided offset %lx which is not buffer aligned or outside of buffer region\n", buffer.io_or_offset); err = net_enqueue_free(&state.tx_queue_clients[client], buffer); @@ -141,8 +141,7 @@ void init(void) net_mem_region_vaddr(microkit_name, client_vaddrs, buffer_data_region_cli0_vaddr); for (int i = 0; i < NUM_NETWORK_CLIENTS; i++) { - net_queue_init(&state.tx_queue_clients[i], queue_info[i].free, queue_info[i].active, - queue_info[i].capacity); + net_queue_init(&state.tx_queue_clients[i], queue_info[i].free, queue_info[i].active, queue_info[i].capacity); state.buffer_region_vaddrs[i] = client_vaddrs[i]; }