Skip to content

Commit d07521f

Browse files
stlankesmkroening
authored andcommitted
feat(ixgbe): add network driver for the Intel X550
The initialization sequence follows the ixy.rs user space driver and the X550 datasheet. The driver operates a single receive and transmit queue. It prefers MSI-X over the legacy interrupt, because a hypervisor is not obliged to offer one for a passed-through device and QEMU in fact does not, which leaves MSI-X as the only way to receive interrupts at all. Should neither be available, the device still makes progress when the kernel is built with the idle-poll feature. This makes the msix module available outside of virtio.
1 parent cd53141 commit d07521f

12 files changed

Lines changed: 953 additions & 28 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,34 @@ jobs:
5454
- run: cargo clippy --package xtask
5555
- name: cargo hack clippy (x86_64)
5656
run: |
57-
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net
58-
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net --features pci
59-
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,rtl8139 --features tcp,virtio-net
60-
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,rtl8139 --features pci,tcp,virtio-net
61-
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,virtio-net --features tcp,rtl8139
62-
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,virtio-net --features pci,tcp,rtl8139
57+
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net,ixgbe
58+
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net,ixgbe --features pci
59+
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,rtl8139,ixgbe --features tcp,virtio-net
60+
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,rtl8139,ixgbe --features pci,tcp,virtio-net
61+
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,virtio-net,ixgbe --features tcp,rtl8139
62+
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,virtio-net,ixgbe --features pci,tcp,rtl8139
63+
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,rtl8139,virtio-net --features tcp,ixgbe
64+
cargo hack clippy --each-feature --no-dev-deps --target x86_64-unknown-none --exclude-features gem-net,rtl8139,virtio-net --features pci,tcp,ixgbe
6365
- name: cargo hack clippy (aarch64)
6466
run: |
65-
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net
66-
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net --features pci
67-
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,rtl8139 --features tcp,virtio-net
68-
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,rtl8139 --features pci,tcp,virtio-net
69-
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,virtio-net --features tcp,rtl8139
70-
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,virtio-net --features pci,tcp,rtl8139
67+
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net,ixgbe
68+
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net,ixgbe --features pci
69+
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,rtl8139,ixgbe --features tcp,virtio-net
70+
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,rtl8139,ixgbe --features pci,tcp,virtio-net
71+
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,virtio-net,ixgbe --features tcp,rtl8139
72+
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,virtio-net,ixgbe --features pci,tcp,rtl8139
73+
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,rtl8139,virtio-net --features tcp,ixgbe
74+
cargo hack clippy --each-feature --no-dev-deps --target aarch64-unknown-none-softfloat --exclude-features gem-net,rtl8139,virtio-net --features pci,tcp,ixgbe
7175
- name: cargo hack clippy (riscv64)
7276
run: |
73-
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net
74-
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net --features pci
75-
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features gem-net,rtl8139 --features tcp,virtio-net
76-
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features gem-net,rtl8139 --features pci,tcp,virtio-net
77-
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features rtl8139,virtio-net --features tcp,gem-net
78-
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features rtl8139,virtio-net --features pci,tcp,gem-net
77+
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net,ixgbe
78+
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features dhcpv4,dns,gem-net,net,rtl8139,virtio-net,ixgbe --features pci
79+
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features gem-net,rtl8139,ixgbe --features tcp,virtio-net
80+
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features gem-net,rtl8139,ixgbe --features pci,tcp,virtio-net
81+
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features rtl8139,virtio-net,ixgbe --features tcp,gem-net
82+
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features rtl8139,virtio-net,ixgbe --features pci,tcp,gem-net
83+
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features gem-net,rtl8139,virtio-net --features tcp,ixgbe
84+
cargo hack clippy --each-feature --no-dev-deps --target riscv64gc-unknown-none-elf --exclude-features gem-net,rtl8139,virtio-net --features pci,tcp,ixgbe
7985
8086
format:
8187
name: Format

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ virtio-net = ["net", "virtio"]
208208
## Enables the RTL8139 network driver.
209209
rtl8139 = ["net", "pci", "volatile/derive", "endian-num"]
210210

211+
## Enables the ixgbe network driver for the Intel X550.
212+
ixgbe = ["net", "pci", "volatile/derive"]
213+
211214
## Enables the Cadence Gigabit Ethernet MAC (GEM) network driver.
212215
gem-net = ["net", "dep:tock-registers"]
213216

src/arch/aarch64/kernel/processor.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ pub fn get_timestamp() -> u64 {
256256
CNTVCT_EL0.get() - BOOT_COUNTER.get().unwrap()
257257
}
258258

259+
#[cfg(feature = "ixgbe")]
260+
#[inline]
261+
pub fn udelay(usecs: u64) {
262+
let khz: u64 = CPU_FREQUENCY.get().into();
263+
let ticks = (khz * usecs).div_ceil(1_000).max(1);
264+
let end = get_timestamp() + ticks;
265+
while get_timestamp() < end {
266+
core::hint::spin_loop();
267+
}
268+
}
269+
259270
#[inline]
260271
#[allow(dead_code)]
261272
pub fn supports_1gib_pages() -> bool {

src/arch/riscv64/kernel/processor.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,17 @@ pub fn get_timestamp() -> u64 {
262262
time::read64()
263263
}
264264

265+
#[cfg(feature = "ixgbe")]
266+
#[inline]
267+
pub fn udelay(usecs: u64) {
268+
// Round up so that even sub-tick delays wait at least one tick.
269+
let ticks = (get_timebase_freq() * usecs).div_ceil(1_000_000).max(1);
270+
let end = get_timestamp() + ticks;
271+
while get_timestamp() < end {
272+
core::hint::spin_loop();
273+
}
274+
}
275+
265276
pub fn supports_1gib_pages() -> bool {
266277
true
267278
}

src/drivers/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ pub mod error {
3535
#[cfg(any(
3636
feature = "virtio",
3737
all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")),
38+
feature = "ixgbe",
3839
feature = "rtl8139",
3940
))]
4041
use thiserror::Error;
4142

4243
#[cfg(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")))]
4344
use crate::drivers::net::gem::GEMError;
45+
#[cfg(feature = "ixgbe")]
46+
use crate::drivers::net::ixgbe::IxgbeError;
4447
#[cfg(feature = "rtl8139")]
4548
use crate::drivers::net::rtl8139::RTL8139Error;
4649
#[cfg(feature = "virtio")]
@@ -49,6 +52,7 @@ pub mod error {
4952
#[cfg(any(
5053
feature = "virtio",
5154
all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")),
55+
feature = "ixgbe",
5256
feature = "rtl8139",
5357
))]
5458
#[derive(Error, Debug)]
@@ -57,6 +61,10 @@ pub mod error {
5761
#[error("Virtio driver failed: {0:?}")]
5862
InitVirtioDevFail(#[from] VirtioError),
5963

64+
#[cfg(feature = "ixgbe")]
65+
#[error("ixgbe driver failed: {0:?}")]
66+
InitIxgbeDevFail(#[from] IxgbeError),
67+
6068
#[cfg(feature = "rtl8139")]
6169
#[error("RTL8139 driver failed: {0:?}")]
6270
InitRTL8139DevFail(#[from] RTL8139Error),

0 commit comments

Comments
 (0)