Skip to content

Commit

Permalink
rust: add infiniband mlx4 sample
Browse files Browse the repository at this point in the history
  • Loading branch information
xubo3006 committed Sep 3, 2023
1 parent 6c0f564 commit 77aad03
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions samples/rust/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions samples/rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 49 additions & 0 deletions samples/rust/rust_mlx4.rs
Original file line number Diff line number Diff line change
@@ -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<Box<mlx4::Registration<RustMlx4Ops>>>,
}

impl kernel::Module for RustMlx4 {
fn init(name: &'static CStr, _module: &'static ThisModule) -> Result<Self> {
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");
}
}

0 comments on commit 77aad03

Please sign in to comment.