Skip to content

Commit

Permalink
fix style issues
Browse files Browse the repository at this point in the history
Signed-off-by: Bill Nguyen <[email protected]>
  • Loading branch information
dreamliner787-9 committed Nov 6, 2024
1 parent 4472e4a commit 727a477
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 54 deletions.
76 changes: 41 additions & 35 deletions examples/net/src/vmm_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ bool uio_net_from_vmm_rx_signal(size_t vcpu_id, uintptr_t addr, size_t fsr, seL4
return true;
}

void init(void) {
void init(void)
{
LOG_VMM("starting %s at \"%s\"\n", "ethernet driver vm", microkit_name);
/* Initialise the VMM, the VCPU(s), and start the guest */

Expand All @@ -104,15 +105,15 @@ void init(void) {
size_t dtb_size = _guest_dtb_image_end - _guest_dtb_image;
size_t initrd_size = _guest_initrd_image_end - _guest_initrd_image;
uintptr_t kernel_pc = linux_setup_images(guest_ram_vaddr,
(uintptr_t) _guest_kernel_image,
kernel_size,
(uintptr_t) _guest_dtb_image,
GUEST_DTB_VADDR,
dtb_size,
(uintptr_t) _guest_initrd_image,
GUEST_INIT_RAM_DISK_VADDR,
initrd_size
);
(uintptr_t) _guest_kernel_image,
kernel_size,
(uintptr_t) _guest_dtb_image,
GUEST_DTB_VADDR,
dtb_size,
(uintptr_t) _guest_initrd_image,
GUEST_INIT_RAM_DISK_VADDR,
initrd_size
);
if (!kernel_pc) {
LOG_VMM_ERR("Failed to initialise guest images\n");
return;
Expand All @@ -138,15 +139,16 @@ void init(void) {

/* Initialise our sDDF ring buffers for the serial device */
serial_queue_handle_t serial_rxq, serial_txq;
serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, serial_tx_data);
serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue,
serial_tx_data);

/* Initialise virtIO console device */
success = virtio_mmio_console_init(&virtio_console,
VIRTIO_CONSOLE_BASE,
VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ,
&serial_rxq, &serial_txq,
SERIAL_VIRT_TX_CH);
VIRTIO_CONSOLE_BASE,
VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ,
&serial_rxq, &serial_txq,
SERIAL_VIRT_TX_CH);

/* Initialise UIO IRQ for TX and RX path */
if (!virq_register(GUEST_VCPU_ID, UIO_NET_TX_IRQ, uio_net_to_vmm_ack, NULL)) {
Expand All @@ -173,12 +175,14 @@ void init(void) {
LOG_VMM("tx cli1 data physadd is 0x%p\n", vmm_info_passing->tx_paddrs[1]);

/* Finally, register vmfault handlers for getting signals from the guest on tx and rx */
bool tx_vmfault_reg_ok = fault_register_vm_exception_handler(GUEST_TO_VMM_TX_FAULT_ADDR, PAGE_SIZE_4K, &uio_net_from_vmm_tx_signal, NULL);
bool tx_vmfault_reg_ok = fault_register_vm_exception_handler(GUEST_TO_VMM_TX_FAULT_ADDR, PAGE_SIZE_4K,
&uio_net_from_vmm_tx_signal, NULL);
if (!tx_vmfault_reg_ok) {
LOG_VMM_ERR("Failed to register the VM fault handler for tx\n");
return;
}
bool rx_vmfault_reg_ok = fault_register_vm_exception_handler(GUEST_TO_VMM_RX_FAULT_ADDR, PAGE_SIZE_4K, &uio_net_from_vmm_rx_signal, NULL);
bool rx_vmfault_reg_ok = fault_register_vm_exception_handler(GUEST_TO_VMM_RX_FAULT_ADDR, PAGE_SIZE_4K,
&uio_net_from_vmm_rx_signal, NULL);
if (!rx_vmfault_reg_ok) {
LOG_VMM_ERR("Failed to register the VM fault handler for rx\n");
return;
Expand All @@ -190,24 +194,25 @@ void init(void) {
LOG_VMM("ETH VMM is ready.\n");
}

void notified(microkit_channel ch) {
void notified(microkit_channel ch)
{
bool handled = virq_handle_passthrough(ch);
switch (ch) {
case VIRT_NET_TX_CH:
if (!virq_inject(GUEST_VCPU_ID, UIO_NET_TX_IRQ)) {
LOG_VMM_ERR("failed to inject TX UIO IRQ\n");
}
break;
case VIRT_NET_RX_CH:
if (!virq_inject(GUEST_VCPU_ID, UIO_NET_RX_IRQ)) {
LOG_VMM_ERR("failed to inject RX UIO IRQ\n");
}
break;
default:
if (handled) {
return;
}
printf("Unexpected channel, ch: 0x%lx\n", ch);
case VIRT_NET_TX_CH:
if (!virq_inject(GUEST_VCPU_ID, UIO_NET_TX_IRQ)) {
LOG_VMM_ERR("failed to inject TX UIO IRQ\n");
}
break;
case VIRT_NET_RX_CH:
if (!virq_inject(GUEST_VCPU_ID, UIO_NET_RX_IRQ)) {
LOG_VMM_ERR("failed to inject RX UIO IRQ\n");
}
break;
default:
if (handled) {
return;
}
printf("Unexpected channel, ch: 0x%lx\n", ch);
}
}

Expand All @@ -216,7 +221,8 @@ void notified(microkit_channel ch) {
* Whenever our guest causes an exception, it gets delivered to this entry point for
* the VMM to handle.
*/
seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) {
seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo)
{
bool success = fault_handle(child, msginfo);
if (success) {
/* Now that we have handled the fault successfully, we reply to it so
Expand Down
48 changes: 29 additions & 19 deletions tools/linux/uio_drivers/net/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int sock_fd;

/* UIO FD to access the sDDF control and data queues */
int uio_sddf_net_queues_fd;
char* sddf_net_queues_vaddr;
char *sddf_net_queues_vaddr;
net_queue_handle_t rx_queue;
net_queue_handle_t tx_queue;

Expand Down Expand Up @@ -79,7 +79,8 @@ vmm_net_info_t *vmm_info_passing;

struct ifreq ifr;

int create_promiscuous_socket(const char *net_inf) {
int create_promiscuous_socket(const char *net_inf)
{
// See https://man7.org/linux/man-pages/man7/packet.7.html for more details on these operations
int sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (sockfd == -1) {
Expand Down Expand Up @@ -120,7 +121,8 @@ int create_promiscuous_socket(const char *net_inf) {
return sockfd;
}

int create_epoll(void) {
int create_epoll(void)
{
epoll_fd = epoll_create1(0);
if (epoll_fd == -1) {
perror("create_epoll(): epoll_create1()");
Expand All @@ -130,7 +132,8 @@ int create_epoll(void) {
return epoll_fd;
}

void bind_fd_to_epoll(int fd, int epollfd) {
void bind_fd_to_epoll(int fd, int epollfd)
{
struct epoll_event sock_event;
sock_event.events = EPOLLIN;
sock_event.data.fd = fd;
Expand All @@ -141,7 +144,8 @@ void bind_fd_to_epoll(int fd, int epollfd) {
}
}

int open_uio(const char *abs_path) {
int open_uio(const char *abs_path)
{
int fd = open(abs_path, O_RDWR);
if (fd == -1) {
perror("open_uio(): open()");
Expand All @@ -151,7 +155,8 @@ int open_uio(const char *abs_path) {
return fd;
}

char *map_uio(uint64_t length, int uiofd) {
char *map_uio(uint64_t length, int uiofd)
{
void *base = (char *) mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, uiofd, 0);
if (base == MAP_FAILED) {
perror("map_uio(): mmap()");
Expand All @@ -161,7 +166,8 @@ char *map_uio(uint64_t length, int uiofd) {
return (char *) base;
}

void uio_interrupt_ack(int uiofd) {
void uio_interrupt_ack(int uiofd)
{
uint32_t enable = 1;
if (write(uiofd, &enable, sizeof(uint32_t)) != sizeof(uint32_t)) {
perror("uio_interrupt_ack(): write()");
Expand All @@ -170,7 +176,8 @@ void uio_interrupt_ack(int uiofd) {
}
}

void tx_process(void) {
void tx_process(void)
{
bool processed_tx = false;

net_request_signal_active(&tx_queue);
Expand All @@ -190,7 +197,7 @@ void tx_process(void) {
bool tx_data_paddr_found = false;
for (int i = 0; i < NUM_NETWORK_CLIENTS; i++) {
if (dma_tx_addr >= vmm_info_passing->tx_paddrs[i] &&
dma_tx_addr < (vmm_info_passing->tx_paddrs[i] + NET_DATA_REGION_BYTES)) {
dma_tx_addr < (vmm_info_passing->tx_paddrs[i] + NET_DATA_REGION_BYTES)) {

tx_data_offset = dma_tx_addr - vmm_info_passing->tx_paddrs[i];
tx_client = i;
Expand All @@ -204,7 +211,7 @@ void tx_process(void) {
}

char *tx_data_base = tx_datas_drv[tx_client];
char *tx_data = (char *) ((uintptr_t) tx_data_base + tx_data_offset);
char *tx_data = (char *)((uintptr_t) tx_data_base + tx_data_offset);

// Blocking send!
struct sockaddr_ll sa;
Expand Down Expand Up @@ -233,7 +240,8 @@ void tx_process(void) {
}
}

int bytes_available_in_socket(void) {
int bytes_available_in_socket(void)
{
int bytes_available;
if (ioctl(sock_fd, FIONREAD, &bytes_available) == -1) {
perror("bytes_available_in_socket(): ioctl()");
Expand All @@ -243,7 +251,8 @@ int bytes_available_in_socket(void) {
return bytes_available;
}

void rx_process(void) {
void rx_process(void)
{
bool processed_rx = false;

// Poll the socket and receive all frames until there is nothing to receive or the free queue is empty.
Expand All @@ -268,7 +277,7 @@ void rx_process(void) {

// Convert DMA addr from virtualiser to offset then mem copy
uintptr_t offset = buffer.io_or_offset - vmm_info_passing->rx_paddr;
char *buf_in_sddf_rx_data = (char *) ((uintptr_t) rx_data_drv + offset);
char *buf_in_sddf_rx_data = (char *)((uintptr_t) rx_data_drv + offset);
for (uint64_t i = 0; i < num_bytes; i++) {
buf_in_sddf_rx_data[i] = frame[i];
}
Expand Down Expand Up @@ -308,19 +317,20 @@ int main(int argc, char **argv)
LOG_NET("*** Mapping in sDDF control and data queues\n");
uio_sddf_net_queues_fd = open_uio(UIO_PATH_SDDF_NET_CONTROL_AND_DATA_QUEUES);
// tx active+free + rx active+free common rx data and per client tx data
uint64_t sddf_net_control_and_data_size = (NET_DATA_REGION_BYTES * 4) + (NET_DATA_REGION_BYTES * (1 + NUM_NETWORK_CLIENTS));
uint64_t sddf_net_control_and_data_size = (NET_DATA_REGION_BYTES * 4) + (NET_DATA_REGION_BYTES *
(1 + NUM_NETWORK_CLIENTS));
sddf_net_queues_vaddr = map_uio(sddf_net_control_and_data_size, uio_sddf_net_queues_fd);

LOG_NET("total control + data size is %p\n", sddf_net_control_and_data_size);

LOG_NET("*** Setting up sDDF control and data queues\n");
rx_free_drv = sddf_net_queues_vaddr;
rx_active_drv = (char *) ((uint64_t) rx_free_drv + NET_DATA_REGION_BYTES);
tx_free_drv = (char *) ((uint64_t) rx_active_drv + NET_DATA_REGION_BYTES);
tx_active_drv = (char *) ((uint64_t) tx_free_drv + NET_DATA_REGION_BYTES);
rx_data_drv = (char *) ((uint64_t) tx_active_drv + NET_DATA_REGION_BYTES);
rx_active_drv = (char *)((uint64_t) rx_free_drv + NET_DATA_REGION_BYTES);
tx_free_drv = (char *)((uint64_t) rx_active_drv + NET_DATA_REGION_BYTES);
tx_active_drv = (char *)((uint64_t) tx_free_drv + NET_DATA_REGION_BYTES);
rx_data_drv = (char *)((uint64_t) tx_active_drv + NET_DATA_REGION_BYTES);
for (int i = 0; i < NUM_NETWORK_CLIENTS; i++) {
tx_datas_drv[i] = (char *) ((uint64_t) rx_data_drv + (NET_DATA_REGION_BYTES * (i + 1)));
tx_datas_drv[i] = (char *)((uint64_t) rx_data_drv + (NET_DATA_REGION_BYTES * (i + 1)));
}

net_queue_init(&rx_queue, (net_queue_t *)rx_free_drv, (net_queue_t *)rx_active_drv, NET_RX_QUEUE_CAPACITY_DRIV);
Expand Down

0 comments on commit 727a477

Please sign in to comment.