WKern
Loading...
Searching...
No Matches
virtnet.h
Go to the documentation of this file.
1/*
2WKern - A Bare Metal OS / Kernel I am making (For Fun)
3Copyright (C) 2025 Wdboyes13
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20#include <types/nums.h>
21#include <global.h>
22
23#define VIRTIO_PCI_QUEUE_SEL 0x0E
24#define VIRTIO_PCI_QUEUE_NUM 0x0C
25#define VIRTIO_PCI_QUEUE_PFN 0x08
26#define VIRTIO_PCI_QUEUE_NOTIFY 0x10
27#define VIRTQ_DESC_F_NEXT 1
28#define VIRTQ_DESC_F_WRITE 2
29#define VIRTIO_MAX_SAFE_QSIZE 16
30#define MAX_RX_DESCS VIRTIO_MAX_SAFE_QSIZE
31#define VIRTIO_PCI_HOST_FEATURES 0x00
32#define VIRTIO_PCI_GUEST_FEATURES 0x04
33#define VIRTIO_PCI_STATUS 0x12
34
35#define VIRTIO_STATUS_ACKNOWLEDGE 1
36#define VIRTIO_STATUS_DRIVER 2
37#define VIRTIO_STATUS_DRIVER_OK 4
38
50typedef struct VirtqUsed {
53 struct {
56 } ring[];
58
59void NetStq(u32 iob);
60void VirtnetInit(u32 iob);
62void VirtnetSetup();
u32 iob
Definition main.c:36
#define PKG
Add attribute packed.
Definition global.h:35
unsigned int u32
32-Bit Unsigned Int
Definition nums.h:30
unsigned short u16
16-Bit Unsigned Int
Definition nums.h:36
unsigned long uptr
Long Unsigned Int.
Definition nums.h:34
u16 flags
Definition virtnet.h:46
u16 idx
Definition virtnet.h:47
u16 ring[]
Definition virtnet.h:48
uptr addr
Definition virtnet.h:40
u16 flags
Definition virtnet.h:42
u16 next
Definition virtnet.h:43
u32 len
Definition virtnet.h:41
u16 idx
Definition virtnet.h:51
u16 flags
Definition virtnet.h:52
struct VirtqUsed::@206011101211064315020313161146252055034302123264 ring[]
u32 id
Definition virtnet.h:54
u32 len
Definition virtnet.h:55
struct VirtqUsed virtq_used
void VirtnetSetup()
Performs full setup of the VirtIO network device.
Definition virtio.c:176
void NetStq(u32 iob)
Processes received packets from the VirtIO queue.
Definition virtio.c:138
struct VirtqAvail virtq_avail
struct VirtqDesc virtq_desc
void VirtnetNegotiate(u32 iob)
Performs device negotiation with the VirtIO network device.
Definition virtio.c:41
void VirtnetInit(u32 iob)
Initializes the VirtIO network queue and allocates RX buffers.
Definition virtio.c:78