diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index 189c10ced6d4f7..55828d089e7de9 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -163,4 +163,11 @@ config SAMPLE_RUST_SELFTESTS If unsure, say N. +config SAMPLE_RUST_MLX4 + tristate "infiniband mlx4" + help + This option builds the infiniband mlx4 driver cases for Rust. + + If unsure, say N. + endif # SAMPLES_RUST diff --git a/samples/rust/Makefile b/samples/rust/Makefile index 420bcefeb08255..d7cee929accf34 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -15,5 +15,6 @@ obj-$(CONFIG_SAMPLE_RUST_NETFILTER) += rust_netfilter.o obj-$(CONFIG_SAMPLE_RUST_ECHO_SERVER) += rust_echo_server.o obj-$(CONFIG_SAMPLE_RUST_FS) += rust_fs.o obj-$(CONFIG_SAMPLE_RUST_SELFTESTS) += rust_selftests.o +obj-$(CONFIG_SAMPLE_RUST_MLX4) += rust_mlx4.o subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs diff --git a/samples/rust/rust_mlx4.rs b/samples/rust/rust_mlx4.rs new file mode 100644 index 00000000000000..280838071eeee6 --- /dev/null +++ b/samples/rust/rust_mlx4.rs @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust infiniband mls4 device sample. + +use kernel::mlx4; +use kernel::prelude::*; + +module! { + type: RustMlx4, + name: "rust_mlx4", + author: "Rust for Linux Contributors", + description: "Rust infiniband mlx4 device sample", + license: "GPL", +} + +struct RustMlx4Ops; + +#[vtable] +impl mlx4::Mlx4Operation for RustMlx4Ops { + fn add() -> Result { + Ok(()) + } + fn remove() -> Result { + Ok(()) + } + fn event() -> Result { + Ok(()) + } +} + +struct RustMlx4 { + _dev: Pin>>, +} + +impl kernel::Module for RustMlx4 { + fn init(name: &'static CStr, _module: &'static ThisModule) -> Result { + pr_info!("Rust infiniband mlx4 driver sample (init)\n"); + + Ok(RustMlx4 { + _dev: mlx4::Registration::new_pinned(name)?, + }) + } +} + +impl Drop for RustMlx4 { + fn drop(&mut self) { + pr_info!("Rust infiniband mlx4 driver sample (exit)\n"); + } +}