Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ propolis_types = { path = "crates/propolis-types" }
rfb = { path = "crates/rfb" }
rgb_frame = { path = "crates/rgb-frame" }
viona_api = { path = "crates/viona-api" }
viona_api_sys = { path = "crates/viona-api/sys" }

# PHD testing framework
phd-framework = { path = "phd-tests/framework" }
Expand Down
2 changes: 0 additions & 2 deletions bin/propolis-server/src/lib/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,6 @@ impl MachineInitializer<'_> {

let viona = virtio::PciVirtioViona::new(
&nic.backend_spec.vnic_name,
0x0800.try_into().unwrap(),
0x0100.try_into().unwrap(),
&self.machine.hdl,
params,
)
Expand Down
2 changes: 0 additions & 2 deletions bin/propolis-standalone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,6 @@ fn setup_instance(

let viona = hw::virtio::PciVirtioViona::new(
vnic_name,
0x0800.try_into().unwrap(),
0x0100.try_into().unwrap(),
&hdl,
viona_params,
)?;
Expand Down
3 changes: 1 addition & 2 deletions crates/viona-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ doctest = false

[dependencies]
libc.workspace = true
viona_api_sys.workspace = true

# nvpair dependency only enabled when building on illumos to avoid any attempts
# to link to an absent libnvpair
[target.'cfg(target_os = "illumos")'.dependencies]
nvpair.workspace = true

[features]
falcon = ["viona_api_sys/falcon"]
falcon = []
3 changes: 2 additions & 1 deletion crates/viona-api/header-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ version = "0.0.0"
license = "MPL-2.0"
build = "build.rs"
publish = false
edition = "2021"

[dependencies]
viona_api_sys = { path = "../sys" }
viona_api = { path = ".." }
libc = "0.2"

[build-dependencies]
Expand Down
7 changes: 2 additions & 5 deletions crates/viona-api/header-check/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ fn main() {
}
};

let include_paths = [
"usr/src/uts/intel",
"usr/src/uts/common",
];
let include_paths = ["usr/src/uts/intel", "usr/src/uts/common"];
cfg.include("/usr/include");
for p in include_paths {
cfg.include(gate_dir.join(p));
Expand Down Expand Up @@ -53,5 +50,5 @@ fn main() {
_ => false,
});

cfg.generate("../sys/src/lib.rs", "main.rs");
cfg.generate("../src/ffi.rs", "main.rs");
}
5 changes: 1 addition & 4 deletions crates/viona-api/header-check/test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

extern crate viona_api_sys;
extern crate libc;

use viona_api_sys::*;
use viona_api::*;

include!(concat!(env!("OUT_DIR"), "/main.rs"));
153 changes: 153 additions & 0 deletions crates/viona-api/src/ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![allow(non_camel_case_types)]

use libc::size_t;
use std::ffi::c_void;

const fn vna_ioc(ioc: i32) -> i32 {
const V: i32 = b'V' as i32;
const C: i32 = b'C' as i32;
V << 16 | C << 8 | ioc
}

pub const VNA_IOC_CREATE: i32 = vna_ioc(0x01);
pub const VNA_IOC_DELETE: i32 = vna_ioc(0x02);
pub const VNA_IOC_VERSION: i32 = vna_ioc(0x03);
pub const VNA_IOC_DEFAULT_PARAMS: i32 = vna_ioc(0x04);

pub const VNA_IOC_RING_INIT: i32 = vna_ioc(0x10);
pub const VNA_IOC_RING_RESET: i32 = vna_ioc(0x11);
pub const VNA_IOC_RING_KICK: i32 = vna_ioc(0x12);
pub const VNA_IOC_RING_SET_MSI: i32 = vna_ioc(0x13);
pub const VNA_IOC_RING_INTR_CLR: i32 = vna_ioc(0x14);
pub const VNA_IOC_RING_SET_STATE: i32 = vna_ioc(0x15);
pub const VNA_IOC_RING_GET_STATE: i32 = vna_ioc(0x16);
pub const VNA_IOC_RING_PAUSE: i32 = vna_ioc(0x17);

pub const VNA_IOC_INTR_POLL: i32 = vna_ioc(0x20);
pub const VNA_IOC_SET_FEATURES: i32 = vna_ioc(0x21);
pub const VNA_IOC_GET_FEATURES: i32 = vna_ioc(0x22);
pub const VNA_IOC_SET_NOTIFY_IOP: i32 = vna_ioc(0x23);
pub const VNA_IOC_SET_PROMISC: i32 = vna_ioc(0x24);
pub const VNA_IOC_GET_PARAMS: i32 = vna_ioc(0x25);
pub const VNA_IOC_SET_PARAMS: i32 = vna_ioc(0x26);
pub const VNA_IOC_GET_MTU: i32 = vna_ioc(0x27);
pub const VNA_IOC_SET_MTU: i32 = vna_ioc(0x28);
pub const VNA_IOC_SET_NOTIFY_MMIO: i32 = vna_ioc(0x29);

/// VirtIO 1.2 queue pair support.
pub const VNA_IOC_GET_PAIRS: i32 = vna_ioc(0x30);
pub const VNA_IOC_SET_PAIRS: i32 = vna_ioc(0x31);
pub const VNA_IOC_GET_USEPAIRS: i32 = vna_ioc(0x32);
pub const VNA_IOC_SET_USEPAIRS: i32 = vna_ioc(0x33);

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_vna_ioc() {
assert_eq!(vna_ioc(0x22), 0x00_56_43_22);
}
}

/// The minimum number of queue pairs supported by a device.
pub const VIONA_MIN_QPAIRS: usize = 1;

/// The maximum number of queue pairs supported by a device.
///
/// Note that the VirtIO limit is much higher (0x8000); Viona artificially
/// limits the number to 256 pairs, which makes it possible to implmeent
/// interrupt notification with a reasonably sized bitmap.
pub const VIONA_MAX_QPAIRS: usize = 0x100;

const fn howmany(x: usize, y: usize) -> usize {
assert!(y > 0);
x.div_ceil(y)
}

#[repr(C)]
pub struct vioc_create {
pub c_linkid: u32,
pub c_vmfd: i32,
}

#[repr(C)]
#[derive(Default)]
pub struct vioc_ring_init {
pub ri_index: u16,
pub ri_qsize: u16,
pub _pad: [u16; 2],
pub ri_qaddr_desc: u64,
pub ri_qaddr_avail: u64,
pub ri_qaddr_used: u64,
}

#[repr(C)]
#[derive(Default)]
pub struct vioc_ring_msi {
pub rm_index: u16,
pub _pad: [u16; 3],
pub rm_addr: u64,
pub rm_msg: u64,
}

#[repr(C)]
#[derive(Default)]
pub struct vioc_intr_poll {
pub vip_nrings: u16,
pub _vip_pad0: u16,
pub vip_status: [u32; howmany(VIONA_MAX_QPAIRS, 32)],
}

#[repr(C)]
#[derive(Default)]
pub struct vioc_notify_mmio {
pub vim_address: u64,
pub vim_size: u32,
}

#[repr(C)]
#[derive(Default)]
pub struct vioc_ring_state {
pub vrs_index: u16,
pub vrs_avail_idx: u16,
pub vrs_used_idx: u16,
pub vrs_qsize: u16,
pub vrs_qaddr_desc: u64,
pub vrs_qaddr_avail: u64,
pub vrs_qaddr_used: u64,
}

pub const VIONA_PROMISC_NONE: i32 = 0;
pub const VIONA_PROMISC_MULTI: i32 = 1;
pub const VIONA_PROMISC_ALL: i32 = 2;
#[cfg(feature = "falcon")]
pub const VIONA_PROMISC_ALL_VLAN: i32 = 3;

#[repr(C)]
#[derive(Default)]
pub struct vioc_get_params {
pub vgp_param: *mut c_void,
pub vgp_param_sz: size_t,
}

#[repr(C)]
#[derive(Default)]
pub struct vioc_set_params {
pub vsp_param: *mut c_void,
pub vsp_param_sz: size_t,
pub vsp_error: *mut c_void,
pub vsp_error_sz: size_t,
}

/// This is the viona interface version which viona_api expects to operate
/// against. All constants and structs defined by the crate are done so in
/// terms of that specific version.
pub const VIONA_CURRENT_INTERFACE_VERSION: u32 = 6;

/// Maximum size of packed nvlists used in viona parameter ioctls
pub const VIONA_MAX_PARAM_NVLIST_SZ: usize = 4096;
43 changes: 28 additions & 15 deletions crates/viona-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::io::{Error, ErrorKind, Result};
use std::os::fd::*;
use std::os::unix::fs::MetadataExt;

pub use viona_api_sys::*;
mod ffi;

pub use ffi::*;

// Hide libnvpair usage when not building on illumos to avoid linking errors
#[cfg(target_os = "illumos")]
Expand All @@ -23,7 +25,7 @@ impl VionaFd {
let this = Self::open()?;

let mut vna_create = vioc_create { c_linkid: link_id, c_vmfd: vm_fd };
let _ = unsafe { this.ioctl(ioctls::VNA_IOC_CREATE, &mut vna_create) }?;
let _ = unsafe { this.ioctl(VNA_IOC_CREATE, &mut vna_create) }?;
Ok(this)
}

Expand Down Expand Up @@ -109,7 +111,7 @@ impl VionaFd {

/// Query the API version exposed by the kernel VMM.
pub fn api_version(&self) -> Result<u32> {
let vers = self.ioctl_usize(ioctls::VNA_IOC_VERSION, 0)?;
let vers = self.ioctl_usize(VNA_IOC_VERSION, 0)?;

// We expect and demand a positive version number from the
// VNA_IOC_VERSION interface.
Expand All @@ -129,16 +131,20 @@ impl VionaFd {
const fn ioctl_usize_safe(cmd: i32) -> bool {
matches!(
cmd,
ioctls::VNA_IOC_DELETE
| ioctls::VNA_IOC_RING_RESET
| ioctls::VNA_IOC_RING_KICK
| ioctls::VNA_IOC_RING_PAUSE
| ioctls::VNA_IOC_RING_INTR_CLR
| ioctls::VNA_IOC_VERSION
| ioctls::VNA_IOC_SET_NOTIFY_IOP
| ioctls::VNA_IOC_SET_PROMISC
| ioctls::VNA_IOC_GET_MTU
| ioctls::VNA_IOC_SET_MTU,
VNA_IOC_DELETE
| VNA_IOC_RING_RESET
| VNA_IOC_RING_KICK
| VNA_IOC_RING_PAUSE
| VNA_IOC_RING_INTR_CLR
| VNA_IOC_VERSION
| VNA_IOC_SET_NOTIFY_IOP
| VNA_IOC_SET_PROMISC
| VNA_IOC_GET_MTU
| VNA_IOC_SET_MTU
| VNA_IOC_GET_PAIRS
| VNA_IOC_SET_PAIRS
| VNA_IOC_GET_USEPAIRS
| VNA_IOC_SET_USEPAIRS,
)
}
}
Expand Down Expand Up @@ -191,7 +197,14 @@ fn minor(meta: &std::fs::Metadata) -> u32 {
#[repr(u32)]
#[derive(Copy, Clone)]
pub enum ApiVersion {
/// Add support for getting/setting MTU
/// Adds multi-queue support and change the data structure for per-queue
/// interrupt polling to a compact bitmap.
V6 = 6,

/// Adds support for VirtIO 1.0 (modern) virtqueues.
V5 = 5,

/// Adds support for getting/setting MTU
V4 = 4,

/// Adds support for interface parameters
Expand All @@ -205,7 +218,7 @@ pub enum ApiVersion {
}
impl ApiVersion {
pub const fn current() -> Self {
Self::V4
Self::V6
}
}
impl PartialEq<ApiVersion> for u32 {
Expand Down
15 changes: 0 additions & 15 deletions crates/viona-api/sys/Cargo.toml

This file was deleted.

Loading
Loading