Skip to content

Commit

Permalink
Back to work
Browse files Browse the repository at this point in the history
Support dev capabilities query

Bump dpdk-sys
  • Loading branch information
daniel-noland committed Dec 1, 2024
1 parent 19e39ce commit f12d742
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 493 deletions.
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ target = "x86_64-unknown-linux-gnu"
[alias]
just = ["just", "cargo"]
sterile = ["just", "sterile", "cargo"]

[target.x86_64-unknown-linux-gnu]
runner = "sudo -E"

[target.x86_64-unknown-linux-musl]
runner = "sudo -E"
27 changes: 14 additions & 13 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ rand = { version = "0.8.5", default-features = false, features = [] }
rstest = { version = "0.23.0", default-features = false, features = [] }
serde = { version = "1.0.213", default-features = false, features = ["derive", "alloc", "rc"] }
syscalls = { version = "0.6.18" }
thiserror = { version = "2.0.0", package = "thiserror-no-std" } # replace with regular thiserror when https://github.com/dtolnay/thiserror/pull/304 lands
thiserror = { version = "2.0.2", default-features = false }
tracing = { version = "0.1.40", default-features = false, features = ["attributes"] }
tracing-subscriber = { version = "0.3.18" }
tracing-test = { version = "0.2.5" }
bitflags = { version = "2.6.0", default-features = false }

4 changes: 3 additions & 1 deletion dpdk-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn bind(path: &Path, sysroot: &str) {
// (not the items themselves, just the documentation associated with them)
// I suspect this is a bug in bindgen, but I'm not sure.
// I don't have any reason to think we need any of these functions and I'd
// rather have the doc comments on for the rest of the project
// rather have the doc comments on for the rest of the project, so turn these off.
.blocklist_type("rte_bus_cmp_t")
.blocklist_type("rte_class_cmp_t")
.blocklist_function("rte_bus_find")
Expand All @@ -57,6 +57,7 @@ fn bind(path: &Path, sysroot: &str) {
.blocklist_function("rte_pci_addr_cmp")
.blocklist_function("rte_pci_addr_parse")
// rustc doesn't like repr(packed) types which contain other repr(packed) types
// I am very confident that we don't need these structs anyway.
.opaque_type("rte_arp_hdr")
.opaque_type("rte_arp_ipv4")
.opaque_type("rte_gtp_psc_generic_hdr")
Expand Down Expand Up @@ -103,6 +104,7 @@ fn main() {
"mlx5",
"nl-route-3",
"nl-3",

"numa",
];

Expand Down
1 change: 1 addition & 0 deletions dpdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ etherparse = { workspace = true, default-features = false, features = [] }
serde = { workspace = true, optional = true }
thiserror = { workspace = true }
tracing = { workspace = true, features = ["attributes"] }
bitflags = { workspace = true }

[build-dependencies]
dpdk-sysroot-helper = { path = "../dpdk-sysroot-helper" }
100 changes: 79 additions & 21 deletions dpdk/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl DevIndex {
self.0
}

#[tracing::instrument(level = "trace", ret)]
/// Get information about an ethernet device.
///
/// # Arguments
Expand All @@ -74,33 +73,34 @@ impl DevIndex {
/// # Safety
///
/// This function should never panic assuming DPDK is correctly implemented.
#[tracing::instrument(level = "trace", ret)]
pub fn info(&self) -> Result<DevInfo, DevInfoError> {
let mut dev_info = rte_eth_dev_info::default();

let ret = unsafe { rte_eth_dev_info_get(self.0, &mut dev_info) };

if ret != 0 {
match ret {
return match ret {
errno::NEG_ENOTSUP => {
error!(
"Device information not supported for port {index}",
index = self.0
);
return Err(DevInfoError::NotSupported);
Err(DevInfoError::NotSupported)
}
errno::NEG_ENODEV => {
error!(
"Device information not available for port {index}",
index = self.0
);
return Err(DevInfoError::NotAvailable);
Err(DevInfoError::NotAvailable)
}
errno::NEG_EINVAL => {
error!(
"Invalid argument when getting device info for port {index}",
index = self.0
);
return Err(DevInfoError::InvalidArgument);
Err(DevInfoError::InvalidArgument)
}
val => {
let _unknown = match StandardErrno::parse_i32(val) {
Expand All @@ -120,9 +120,9 @@ impl DevIndex {
index = self.0,
val = val
);
return Err(DevInfoError::Unknown(errno::Errno(val)));
Err(DevInfoError::Unknown(Errno(val)))
}
}
};
// error!(
// "Failed to get device info for port {index}: {err}",
// index = self.0
Expand Down Expand Up @@ -150,7 +150,8 @@ impl DevIndex {
/// (statically ensured).
/// * This function may panic if DPDK returns an unexpected (undocumented) error code after
/// failing to determine the socket id.
pub fn socket_id(&self) -> Result<SocketId, errno::ErrorCode> {
#[tracing::instrument(level = "trace", ret)]
pub fn socket_id(&self) -> Result<SocketId, ErrorCode> {
let socket_id = unsafe { rte_eth_dev_socket_id(self.as_u16()) };
if socket_id == -1 {
match unsafe { wrte_errno() } {
Expand All @@ -160,7 +161,7 @@ impl DevIndex {
}
errno::EINVAL => {
// We are asking DPDK for the socket id of a port that doesn't exist.
return Err(errno::ErrorCode::parse_i32(errno::EINVAL));
return Err(ErrorCode::parse_i32(errno::EINVAL));
}
errno => {
// Getting here means we have an unknown error.
Expand Down Expand Up @@ -313,13 +314,13 @@ impl From<u64> for RxOffload {
}
}

#[non_exhaustive]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
/// Verbose configuration for transmit offloads.
///
/// This struct is mostly for coherent reporting on network cards.
///
/// TODO: fill in remaining offload types from `rte_ethdev.h`
#[non_exhaustive]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TxOffloadConfig {
/// GENEVE tunnel segmentation offload.
pub geneve_tnl_tso: bool,
Expand Down Expand Up @@ -382,6 +383,36 @@ impl Display for TxOffloadConfig {
}
}

bitflags! {
#[repr(transparent)]
#[derive(Debug, PartialEq, Eq)]
pub struct TxOffloads: u64 {
const VLAN_INSERT = wrte_eth_tx_offload::TX_OFFLOAD_VLAN_INSERT;
const IPV4_CKSUM = wrte_eth_tx_offload::TX_OFFLOAD_IPV4_CKSUM;
const UDP_CKSUM = wrte_eth_tx_offload::TX_OFFLOAD_UDP_CKSUM;
const TCP_CKSUM = wrte_eth_tx_offload::TX_OFFLOAD_TCP_CKSUM;
const SCTP_CKSUM = wrte_eth_tx_offload::TX_OFFLOAD_SCTP_CKSUM;
const TCP_TSO = wrte_eth_tx_offload::TX_OFFLOAD_TCP_TSO;
const UDP_TSO = wrte_eth_tx_offload::TX_OFFLOAD_UDP_TSO;
const OUTER_IPV4_CKSUM = wrte_eth_tx_offload::TX_OFFLOAD_OUTER_IPV4_CKSUM;
const QINQ_INSERT = wrte_eth_tx_offload::TX_OFFLOAD_QINQ_INSERT;
const VXLAN_TNL_TSO = wrte_eth_tx_offload::TX_OFFLOAD_VXLAN_TNL_TSO;
const GRE_TNL_TSO = wrte_eth_tx_offload::TX_OFFLOAD_GRE_TNL_TSO;
const IPIP_TNL_TSO = wrte_eth_tx_offload::TX_OFFLOAD_IPIP_TNL_TSO;
const GENEVE_TNL_TSO = wrte_eth_tx_offload::TX_OFFLOAD_GENEVE_TNL_TSO;
const MACSEC_INSERT = wrte_eth_tx_offload::TX_OFFLOAD_MACSEC_INSERT;
const MT_LOCKFREE = wrte_eth_tx_offload::TX_OFFLOAD_MT_LOCKFREE;
const MULTI_SEGS = wrte_eth_tx_offload::TX_OFFLOAD_MULTI_SEGS;
const MBUF_FAST_FREE = wrte_eth_tx_offload::TX_OFFLOAD_MBUF_FAST_FREE;
const SECURITY = wrte_eth_tx_offload::TX_OFFLOAD_SECURITY;
const UDP_TNL_TSO = wrte_eth_tx_offload::TX_OFFLOAD_UDP_TNL_TSO;
const IP_TNL_TSO = wrte_eth_tx_offload::TX_OFFLOAD_IP_TNL_TSO;
const OUTER_UDP_CKSUM = wrte_eth_tx_offload::TX_OFFLOAD_OUTER_UDP_CKSUM;
const SEND_ON_TIMESTAMP = wrte_eth_tx_offload::TX_OFFLOAD_SEND_ON_TIMESTAMP;
const _ = !0;
}
}

impl From<TxOffloadConfig> for TxOffload {
fn from(value: TxOffloadConfig) -> Self {
use wrte_eth_tx_offload::*;
Expand Down Expand Up @@ -428,6 +459,13 @@ impl From<TxOffloadConfig> for TxOffload {
} else {
0
}
| if value.qinq_insert { TX_OFFLOAD_QINQ_INSERT } else { 0 }
| if value.sctp_cksum { TX_OFFLOAD_SCTP_CKSUM } else { 0 }
| if value.tcp_cksum { TX_OFFLOAD_TCP_CKSUM } else { 0 }
| if value.tcp_tso { TX_OFFLOAD_TCP_TSO } else { 0 }
| if value.udp_cksum { TX_OFFLOAD_UDP_CKSUM } else { 0 }
| if value.udp_tso { TX_OFFLOAD_UDP_TSO } else { 0 }
| if value.vlan_insert { TX_OFFLOAD_VLAN_INSERT } else { 0 }
| if value.udp_tso { TX_OFFLOAD_UDP_TSO } else { 0 }
| if value.vlan_insert {
TX_OFFLOAD_VLAN_INSERT
Expand Down Expand Up @@ -479,8 +517,7 @@ impl TxOffload {
/// MACsec insertion.
pub const MACSEC_INSERT: TxOffload = TxOffload(wrte_eth_tx_offload::TX_OFFLOAD_MACSEC_INSERT);
/// Outer IPv4 checksum calculation.
pub const OUTER_IPV4_CKSUM: TxOffload =
TxOffload(wrte_eth_tx_offload::TX_OFFLOAD_OUTER_IPV4_CKSUM);
pub const OUTER_IPV4_CKSUM: TxOffload = TxOffload(wrte_eth_tx_offload::TX_OFFLOAD_OUTER_IPV4_CKSUM);
/// QinQ (double VLAN) insertion.
pub const QINQ_INSERT: TxOffload = TxOffload(wrte_eth_tx_offload::TX_OFFLOAD_QINQ_INSERT);
/// SCTP checksum calculation.
Expand Down Expand Up @@ -562,15 +599,28 @@ impl BitXorAssign for TxOffload {
}
}

#[derive(Debug, PartialEq)]
/// Information about a DPDK ethernet device.
///
/// This struct is a wrapper around the `rte_eth_dev_info` struct from DPDK.
#[derive(Debug, PartialEq)]
pub struct DevInfo {
pub(crate) index: DevIndex,
pub(crate) inner: rte_eth_dev_info,
}

bitflags! {
#[repr(transparent)]
#[derive(Debug, PartialEq, Eq)]
pub struct DevCapabilities: u64 {
const RUNTIME_RX_QUEUE_SETUP = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP as u64;
const RUNTIME_TX_QUEUE_SETUP = RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP as u64;
const RXQ_SHARE = RTE_ETH_DEV_CAPA_RXQ_SHARE as u64;
const FLOW_RULE_KEEP = RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP as u64;
const FLOW_SHARED_OBJECT_KEEP = RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP as u64;
const _ = !0;
}
}

#[repr(transparent)]
#[derive(Debug)]
struct DevIterator {
Expand Down Expand Up @@ -693,30 +743,38 @@ impl DevInfo {
self.inner.if_index
}

#[allow(clippy::expect_used)]
#[tracing::instrument(level = "debug")]
/// Get the driver name of the device.
///
/// # Panics
///
/// This function will panic if the driver name is not valid utf-8.
#[allow(clippy::expect_used)]
#[tracing::instrument(level = "debug")]
pub fn driver_name(&self) -> &str {
unsafe { CStr::from_ptr(self.inner.driver_name) }
.to_str()
.expect("driver name is not valid utf-8")
}

#[tracing::instrument(level = "trace")]
/// Get the maximum set of available tx offloads supported by the device.
#[tracing::instrument(level = "trace")]
pub fn tx_offload_caps(&self) -> TxOffload {
self.inner.tx_offload_capa.into()
}

#[tracing::instrument(level = "trace")]
/// Get the maximum set of available rx offloads supported by the device.
#[tracing::instrument(level = "trace")]
pub fn rx_offload_caps(&self) -> RxOffload {
self.inner.rx_offload_capa.into()
}

/// Get the capabilities of the device.
///
/// See [`DevCapabilities`]
#[tracing::instrument(level = "trace")]
pub fn capabilities(&self) -> DevCapabilities {
DevCapabilities::from_bits_retain(self.inner.dev_capa)
}
}

#[derive(Debug)]
Expand All @@ -728,7 +786,7 @@ pub struct Dev {
pub config: DevConfig,
pub(crate) rx_queues: Vec<RxQueue>,
pub(crate) tx_queues: Vec<TxQueue>,
pub(crate) hairpin_queues: Vec<queue::hairpin::HairpinQueue>,
pub(crate) hairpin_queues: Vec<HairpinQueue>,
}

impl Dev {
Expand Down Expand Up @@ -854,7 +912,7 @@ impl Drop for Dev {
port = self.info.index()
);
match self.stop() {
Ok(()) => {
Ok(_) => {
info!("Device {port} stopped", port = self.info.index());
}
Err(err) => {
Expand All @@ -873,5 +931,5 @@ pub enum SocketIdLookupError {
#[error("Invalid port ID")]
DevDoesNotExist(DevIndex),
#[error("Unknown error code set")]
UnknownErrno(errno::ErrorCode),
UnknownErrno(ErrorCode),
}
2 changes: 1 addition & 1 deletion dpdk/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl Mbuf {
pub(crate) fn new_from_raw(raw: *mut rte_mbuf) -> Option<Mbuf> {
let raw = match NonNull::new(raw) {
None => {
warn!("Attempted to create Mbuf from null pointer");
error!("Attempted to create Mbuf from null pointer");
return None;
}
Some(raw) => raw,
Expand Down
Loading

0 comments on commit f12d742

Please sign in to comment.