Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire up viona for illumos#17032 #870

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion crates/viona-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ impl VionaFd {
| ioctls::VNA_IOC_RING_INTR_CLR
| ioctls::VNA_IOC_VERSION
| ioctls::VNA_IOC_SET_PROMISC
| ioctls::VNA_IOC_GET_MTU
| ioctls::VNA_IOC_SET_MTU
)
}
}
Expand Down Expand Up @@ -178,6 +180,9 @@ unsafe fn ioctl(
#[repr(u32)]
#[derive(Copy, Clone)]
pub enum ApiVersion {
/// Add support for getting/setting MTU
V4 = 4,

/// Adds support for interface parameters
V3 = 3,

Expand All @@ -189,7 +194,7 @@ pub enum ApiVersion {
}
impl ApiVersion {
pub const fn current() -> Self {
Self::V3
Self::V4
}
}
impl PartialEq<ApiVersion> for u32 {
Expand Down
6 changes: 5 additions & 1 deletion crates/viona-api/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub mod ioctls {
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 VIONA_VQ_MAX: u16 = 2;
Expand Down Expand Up @@ -84,11 +86,13 @@ mod structs {
use libc::size_t;
use std::ffi::c_void;

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

#[repr(C)]
pub struct vioc_set_params {
pub vsp_param: *mut c_void,
pub vsp_param_sz: size_t,
Expand All @@ -100,7 +104,7 @@ mod structs {
/// 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 = 3;
pub const VIONA_CURRENT_INTERFACE_VERSION: u32 = 4;

/// Maximum size of packed nvlists used in viona parameter ioctls
pub const VIONA_MAX_PARAM_NVLIST_SZ: usize = 4096;
Expand Down
23 changes: 23 additions & 0 deletions lib/propolis/src/hw/virtio/viona.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ impl PciVirtioViona {
let msix_count = Some(3);
let dev_features = hdl.get_avail_features()?;

// Do in-kernel configuration of device MTU
if let Some(mtu) = info.mtu {
if hdl.api_version().unwrap() >= viona_api::ApiVersion::V4 {
hdl.set_mtu(mtu)?;
} else if mtu != 1500 {
// Squawk about MTUs not matching the default of 1500
return Err(io::Error::new(
ErrorKind::Unsupported,
"viona device version is inadequate to set MTU",
));
}
}

let queues =
VirtQueues::new(NonZeroU16::new(queue_size).unwrap(), queue_count);
let (virtio_state, pci_state) = PciVirtioState::create(
Expand Down Expand Up @@ -719,6 +732,16 @@ impl VionaHdl {
self.0.instance_id()
}

/// Set MTU for viona device
fn set_mtu(&self, mtu: u16) -> io::Result<()> {
self.0.ioctl_usize(viona_api::VNA_IOC_SET_MTU, mtu.into())?;
Ok(())
}

fn api_version(&self) -> io::Result<u32> {
self.0.api_version()
}

/// Set the desired promiscuity level on this interface.
#[cfg(feature = "falcon")]
fn set_promisc(&self, p: viona_api::viona_promisc_t) -> io::Result<()> {
Expand Down
Loading