WKern
Loading...
Searching...
No Matches
virtnet.h File Reference
#include <types/nums.h>
#include <global.h>

Go to the source code of this file.

Data Structures

struct  VirtqDesc
struct  VirtqAvail
struct  VirtqUsed

Macros

#define VIRTIO_PCI_QUEUE_SEL   0x0E
#define VIRTIO_PCI_QUEUE_NUM   0x0C
#define VIRTIO_PCI_QUEUE_PFN   0x08
#define VIRTIO_PCI_QUEUE_NOTIFY   0x10
#define VIRTQ_DESC_F_NEXT   1
#define VIRTQ_DESC_F_WRITE   2
#define VIRTIO_MAX_SAFE_QSIZE   16
#define MAX_RX_DESCS   VIRTIO_MAX_SAFE_QSIZE
#define VIRTIO_PCI_HOST_FEATURES   0x00
#define VIRTIO_PCI_GUEST_FEATURES   0x04
#define VIRTIO_PCI_STATUS   0x12
#define VIRTIO_STATUS_ACKNOWLEDGE   1
#define VIRTIO_STATUS_DRIVER   2
#define VIRTIO_STATUS_DRIVER_OK   4

Typedefs

typedef struct VirtqDesc virtq_desc
typedef struct VirtqAvail virtq_avail
typedef struct VirtqUsed virtq_used

Functions

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

Macro Definition Documentation

◆ MAX_RX_DESCS

#define MAX_RX_DESCS   VIRTIO_MAX_SAFE_QSIZE

Definition at line 30 of file virtnet.h.

◆ VIRTIO_MAX_SAFE_QSIZE

#define VIRTIO_MAX_SAFE_QSIZE   16

Definition at line 29 of file virtnet.h.

◆ VIRTIO_PCI_GUEST_FEATURES

#define VIRTIO_PCI_GUEST_FEATURES   0x04

Definition at line 32 of file virtnet.h.

◆ VIRTIO_PCI_HOST_FEATURES

#define VIRTIO_PCI_HOST_FEATURES   0x00

Definition at line 31 of file virtnet.h.

◆ VIRTIO_PCI_QUEUE_NOTIFY

#define VIRTIO_PCI_QUEUE_NOTIFY   0x10

Definition at line 26 of file virtnet.h.

◆ VIRTIO_PCI_QUEUE_NUM

#define VIRTIO_PCI_QUEUE_NUM   0x0C

Definition at line 24 of file virtnet.h.

◆ VIRTIO_PCI_QUEUE_PFN

#define VIRTIO_PCI_QUEUE_PFN   0x08

Definition at line 25 of file virtnet.h.

◆ VIRTIO_PCI_QUEUE_SEL

#define VIRTIO_PCI_QUEUE_SEL   0x0E

Definition at line 23 of file virtnet.h.

◆ VIRTIO_PCI_STATUS

#define VIRTIO_PCI_STATUS   0x12

Definition at line 33 of file virtnet.h.

◆ VIRTIO_STATUS_ACKNOWLEDGE

#define VIRTIO_STATUS_ACKNOWLEDGE   1

Definition at line 35 of file virtnet.h.

◆ VIRTIO_STATUS_DRIVER

#define VIRTIO_STATUS_DRIVER   2

Definition at line 36 of file virtnet.h.

◆ VIRTIO_STATUS_DRIVER_OK

#define VIRTIO_STATUS_DRIVER_OK   4

Definition at line 37 of file virtnet.h.

◆ VIRTQ_DESC_F_NEXT

#define VIRTQ_DESC_F_NEXT   1

Definition at line 27 of file virtnet.h.

◆ VIRTQ_DESC_F_WRITE

#define VIRTQ_DESC_F_WRITE   2

Definition at line 28 of file virtnet.h.

Typedef Documentation

◆ virtq_avail

typedef struct VirtqAvail virtq_avail

◆ virtq_desc

typedef struct VirtqDesc virtq_desc

◆ virtq_used

typedef struct VirtqUsed virtq_used

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.