WKern
Loading...
Searching...
No Matches
virtio.c File Reference
#include <idt/idtirq.h>
#include <io/kio.h>
#include <mem/kmem.h>
#include <net/virtnet.h>
#include <pci/pci.h>
#include <types/nums.h>

Go to the source code of this file.

Functions

void VirtnetNegotiate (u32 iob)
 Performs device negotiation with the VirtIO network device.
void VirtnetInit (u32 iob)
 Initializes the VirtIO network queue and allocates RX buffers.
void NetStq (u32 iob)
 Processes received packets from the VirtIO queue.
void VirtnetSetup ()
 Performs full setup of the VirtIO network device.

Function Documentation

◆ NetStq()

void NetStq ( u32 iob)

Processes received packets from the VirtIO queue.

Iterates over the used ring to find received packets, prints their contents in hex, and recycles the RX buffers by re-adding the descriptors to the avail ring.

Parameters
iobThe I/O base address for the VirtIO device.

Definition at line 138 of file virtio.c.

◆ VirtnetInit()

void VirtnetInit ( u32 iob)

Initializes the VirtIO network queue and allocates RX buffers.

  • Selects RX queue 0 via PCI register.
  • Allocates a 4 KiB block for the VirtIO queue and zeroes it.
  • Determines the queue size from the device, clamping if needed.
  • Initializes descriptor structures:
    • desc: descriptors for received packets
    • avail: list of available descriptors
    • used: list of used descriptors from the device
  • Allocates individual 2 KiB RX buffers for each descriptor.
  • Notifies the device that the queue is ready and available.
Parameters
iobThe I/O base address for the VirtIO device.

Definition at line 78 of file virtio.c.

◆ VirtnetNegotiate()

void VirtnetNegotiate ( u32 iob)

Performs device negotiation with the VirtIO network device.

Resets the VirtIO network device and negotiates feature support by writing appropriate status flags to the I/O port.

Parameters
iobThe I/O base address for the VirtIO device.

Definition at line 41 of file virtio.c.

◆ VirtnetSetup()

void VirtnetSetup ( )

Performs full setup of the VirtIO network device.

Finds the VirtIO network device on the PCI bus, reads its IRQ, sets the interrupt handler, unmasks the IRQ, and performs negotiation and initialization.

Definition at line 176 of file virtio.c.