Skip to content

Commit

Permalink
Conditionally expose LSO/CSO capabs based on underlay
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMcFelix committed Nov 21, 2024
1 parent 00765c6 commit 9e44656
Show file tree
Hide file tree
Showing 5 changed files with 347 additions and 101 deletions.
34 changes: 2 additions & 32 deletions crates/illumos-sys-hdrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub enum krw_type_t {
// } mac_ether_offload_info_t;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Default)]
pub struct mac_ether_offload_info_t {
pub meoi_flags: u8,
pub meoi_l2hlen: u8,
Expand All @@ -237,28 +237,10 @@ pub struct mac_ether_offload_info_t {
pub meoi_l4proto: u8,
pub meoi_l4hlen: u8,
pub meoi_len: u32,
// pub meoi_tunproto: u8,
// pub meoi_tunhlen: u16,
}

impl Default for mac_ether_offload_info_t {
fn default() -> Self {
Self {
meoi_flags: 0,
meoi_len: 0,
meoi_l2hlen: 0,
meoi_l3proto: 0,
meoi_l3hlen: 0,
meoi_l4proto: 0,
meoi_l4hlen: 0,
// meoi_tunproto: 0,
// meoi_tunhlen: 0,
}
}
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Default)]
pub struct mac_ether_tun_info_t {
pub mett_flags: u8,
pub mett_tuntype: u8,
Expand All @@ -267,18 +249,6 @@ pub struct mac_ether_tun_info_t {
pub mett_l3hlen: u16,
}

impl Default for mac_ether_tun_info_t {
fn default() -> Self {
Self {
mett_flags: 0,
mett_tuntype: 0,
mett_l2hlen: 0,
mett_l3proto: 0,
mett_l3hlen: 0,
}
}
}

// Many of these fields are not needed at the moment and thus defined
// imprecisely for expediency.
#[repr(C)]
Expand Down
1 change: 0 additions & 1 deletion lib/opte/src/ddi/mblk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use core::mem::ManuallyDrop;
use core::mem::MaybeUninit;
use core::ops::Deref;
use core::ops::DerefMut;
use core::ops::MulAssign;
use core::ptr;
use core::ptr::NonNull;
use core::slice;
Expand Down
69 changes: 69 additions & 0 deletions xde/src/mac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use alloc::sync::Arc;
use bitflags::bitflags;
use core::ffi::CStr;
use core::fmt;
use core::mem::MaybeUninit;
use core::ptr;
use illumos_sys_hdrs::*;
use opte::ddi::mblk::MsgBlk;
Expand Down Expand Up @@ -70,6 +71,41 @@ impl MacHandle {
}
mac
}

pub fn get_min_max_sdu(&self) -> (u32, u32) {
let (mut min, mut max) = (0, 0);

unsafe {
mac_sdu_get(self.0, &raw mut min, &raw mut max);
}

(min, max)
}

pub fn get_cso_capabs(&self) -> u32 {
let mut flags = 0u32;
unsafe {
mac_capab_get(
self.0,
mac_capab_t::MAC_CAPAB_HCKSUM,
(&raw mut flags) as *mut _,
);
}
flags
}

pub fn get_lso_capabs(&self) -> mac_capab_lso_t {
let mut lso = MaybeUninit::<mac_capab_lso_t>::zeroed();
unsafe {
mac_capab_get(
self.0,
mac_capab_t::MAC_CAPAB_LSO,
(&raw mut lso) as *mut _,
);

lso.assume_init()
}
}
}

impl Drop for MacHandle {
Expand Down Expand Up @@ -394,3 +430,36 @@ impl Drop for MacPerimeterHandle {
}
}
}

bitflags! {
pub struct TcpLsoFlags: u32 {
const BASIC_IPV4 = LSO_TX_BASIC_TCP_IPV4;
const BASIC_IPV6 = LSO_TX_BASIC_TCP_IPV6;
const TUN_IPV4 = LSO_TX_TUNNEL_TCP_IPV4;
const TUN_IPV6 = LSO_TX_TUNNEL_TCP_IPV6;
}

pub struct TunnelTcpLsoFlags: u32 {
const FILL_OUTER_CSUM = LSO_TX_TUNNEL_OUTER_CSUM;
const INNER_IPV4 = LSO_TX_TUNNEL_INNER_IP4;
const INNER_IPV6 = LSO_TX_TUNNEL_INNER_IP6;
const GENEVE = LSO_TX_TUNNEL_GENEVE;
const VXLAN = LSO_TX_TUNNEL_VXLAN;
}

pub struct ChecksumOffloadCapabs: u32 {
/// XXX: set on packets, not on device.
const ENABLE = 1 << 0;

const INET_PARTIAL = 1 << 1;
const INET_FULL_V4 = 1 << 2;
const INET_FULL_V6 = 1 << 3;
const INET_HDRCKSUM = 1 << 4;

const NON_TUN_CAPABS =
Self::INET_PARTIAL.bits() | Self::INET_FULL_V4.bits() | Self::INET_FULL_V6.bits() | Self::INET_HDRCKSUM.bits();

const TUN_OUTER_CSUM = 1 << 5;
const TUN_GENEVE = 1 << 6;
}
}
73 changes: 73 additions & 0 deletions xde/src/mac/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ pub enum link_state_t {
#[allow(unused_imports)]
use mac_client_promisc_type_t::*;

use crate::ip::t_uscalar_t;

pub type mac_tx_cookie_t = uintptr_t;
pub type mac_rx_fn = unsafe extern "C" fn(
*mut c_void,
Expand Down Expand Up @@ -159,6 +161,12 @@ extern "C" {
mp_chain: *mut mblk_t,
);
pub fn mac_private_minor() -> minor_t;

pub fn mac_sdu_get(
mh: *mut mac_handle,
min_sdu: *mut c_uint,
max_sdu: *mut c_uint,
);
}

// Private MAC functions needed to get us a Tx path.
Expand All @@ -177,8 +185,73 @@ extern "C" {
) -> c_int;
pub fn mac_perim_exit(mph: mac_perim_handle);
pub fn mac_perim_held(mh: mac_handle) -> boolean_t;

// VERY private to MAC.
pub fn mac_capab_get(
mh: *mut mac_handle,
capab: mac_capab_t,
data: *mut c_void,
) -> boolean_t;
}

#[repr(C)]
#[derive(Clone, Copy, Default)]
pub struct lso_basic_tcp_ipv4_t {
pub lso_max: t_uscalar_t,
}

#[repr(C)]
#[derive(Clone, Copy, Default)]
pub struct lso_basic_tcp_ipv6_t {
pub lso_max: t_uscalar_t,
}

#[repr(C)]
#[derive(Clone, Copy, Default)]
pub struct lso_tunnel_tcp_ipv4_t {
pub lso_max: t_uscalar_t,
pub encap_max: t_uscalar_t,
pub flags: t_uscalar_t,
}

#[repr(C)]
#[derive(Clone, Copy, Default)]
pub struct lso_tunnel_tcp_ipv6_t {
pub lso_max: t_uscalar_t,
pub encap_max: t_uscalar_t,
pub flags: t_uscalar_t,
}

#[repr(C)]
#[derive(Clone, Copy, Default)]
pub struct mac_capab_lso_t {
pub lso_flags: t_uscalar_t,
pub lso_basic_tcp_ipv4: lso_basic_tcp_ipv4_t,
pub lso_basic_tcp_ipv6: lso_basic_tcp_ipv6_t,

pub lso_tunnel_tcp_ipv4: lso_tunnel_tcp_ipv4_t,
pub lso_tunnel_tcp_ipv6: lso_tunnel_tcp_ipv6_t,
}

/*
* Currently supported flags for LSO.
*/
pub const LSO_TX_BASIC_TCP_IPV4: u32 = 0x01; /* TCPv4 LSO capability */
pub const LSO_TX_BASIC_TCP_IPV6: u32 = 0x02; /* TCPv6 LSO capability */
pub const LSO_TX_TUNNEL_TCP_IPV4: u32 = 0x04; /* Tun/v4 LSO capability */
pub const LSO_TX_TUNNEL_TCP_IPV6: u32 = 0x08; /* Tun/v6 LSO capability */

/*
* Currently supported tunnel classes for tunnelled LSO offload.
* Design: This allows different L3 support from unencapped. Overkill?
*/
/* hardware can fill outer UDP or GRE checksum information */
pub const LSO_TX_TUNNEL_OUTER_CSUM: u32 = 0x01;
pub const LSO_TX_TUNNEL_INNER_IP4: u32 = 0x02;
pub const LSO_TX_TUNNEL_INNER_IP6: u32 = 0x04;
pub const LSO_TX_TUNNEL_GENEVE: u32 = 0x08; /* support Geneve (UDP) */
pub const LSO_TX_TUNNEL_VXLAN: u32 = 0x10; /* support VXLAN (UDP) */

#[repr(C)]
#[derive(Debug)]
pub enum mac_diag {
Expand Down
Loading

0 comments on commit 9e44656

Please sign in to comment.