29static void *virtq_rx =
NULL;
31static u16 last_used_idx = 0;
42 Kprintf(
"Reset device status\n");
49 Kprintf(
"Reading host features\n");
54 Kprintf(
"Writing guest features\n");
83 Kprintf(
"Malloc Failed at virtnet_init");
88 Kprintf(
"Raw qsize: 0x%x\n", raw_qsize);
99 Kprintf(
"Setting descriptors, avail, and used\n");
102 used = (
virtq_used *)((
u8 *)virtq_rx + 4096 - (6 + 8 * qsize));
104 for (
int i = 0; i < qsize; i++) {
105 rx_bufs[i] =
Kmalloc(2048, 4096);
107 Kprintf(
"Failed to alloc rx_buf %d\n", i);
111 desc[i].addr = (
uptr)rx_bufs[i];
117 Kprintf(
"Finishing net setup\n");
118 Kprintf(
"Failed RX_BUF: %d, Final qsize = %d\n", failed, qsize);
142 static const char hexchars[] =
"0123456789ABCDEF";
143 while (last_used_idx != used->idx) {
144 u16 idx = last_used_idx % qsize;
145 u32 desc_id = used->ring[idx].id;
146 u32 len = used->ring[idx].len;
148 char *pacKet = (
char *)desc[desc_id].addr;
149 Kprintf(
"Received pacKet (%d bytes):\n", len);
150 for (
u32 b = 0; b < len; b++) {
152 Kputchar(hexchars[(
byte >> 4) & 0xF]);
159 avail->ring[avail->idx % qsize] = desc_id;
181 extern void Virtirq(
void);
void * Kmalloc(size_t size, size_t align)
Allocate memory.
void Outb(u16 port, u8 val)
Write a byte to the specified I/O port.
void Outw(u16 port, u16 val)
Write a 16-bit word to the specified I/O port.
u32 Inl(u16 port)
Read a 32-bit value from the specified I/O port.
u16 Inw(u16 port)
Read a 16-bit word from the specified I/O port.
void Outl(u16 port, u32 val)
Write a 32-bit value to the specified I/O port.
void IdtSetGate(u8 num, u32 base, u16 sel, u8 flags)
Set an IDT gate (entry) at given index.
#define KERNEL_CODE_SEGMENT
void UnmaskIrq(u8 irq)
Unmask an IRQ.
void Kprintf(const char *fmt,...)
Formatted output to the screen.
void KprintHex(u32 num)
Prints a 32-bit unsigned integer in hexadecimal format prefixed with "0x".
void Kputchar(char c)
Outputs a single character to the screen at the current cursor position.
void Kmemset(void *ptr, unsigned char value, unsigned int num)
Set memory to a value.
unsigned int u32
32-Bit Unsigned Int
unsigned short u16
16-Bit Unsigned Int
unsigned long uptr
Long Unsigned Int.
unsigned char u8
8-Bit Unsigned Int
#define PCI_INTERRUPT_LINE
u32 FindVirtionetDev()
Search for VirtNet Device.
u32 PciConfigRead(u8 bus, u8 slot, u8 func, u8 offset)
Reads a 32-bit value from PCI configuration space.
void VirtnetSetup()
Performs full setup of the VirtIO network device.
void NetStq(u32 iob)
Processes received packets from the VirtIO queue.
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.
#define VIRTIO_STATUS_DRIVER_OK
struct VirtqUsed virtq_used
#define VIRTIO_PCI_QUEUE_NUM
#define VIRTQ_DESC_F_WRITE
#define VIRTIO_STATUS_DRIVER
#define VIRTIO_STATUS_ACKNOWLEDGE
#define VIRTIO_PCI_HOST_FEATURES
#define VIRTIO_PCI_QUEUE_SEL
#define VIRTIO_PCI_STATUS
#define VIRTIO_PCI_QUEUE_NOTIFY
#define VIRTIO_PCI_GUEST_FEATURES
struct VirtqAvail virtq_avail
struct VirtqDesc virtq_desc
#define VIRTIO_MAX_SAFE_QSIZE
#define VIRTIO_PCI_QUEUE_PFN