Skip to content

Commit 77aad03

Browse files
committed
rust: add infiniband mlx4 sample
1 parent 6c0f564 commit 77aad03

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

samples/rust/Kconfig

+7
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,11 @@ config SAMPLE_RUST_SELFTESTS
163163

164164
If unsure, say N.
165165

166+
config SAMPLE_RUST_MLX4
167+
tristate "infiniband mlx4"
168+
help
169+
This option builds the infiniband mlx4 driver cases for Rust.
170+
171+
If unsure, say N.
172+
166173
endif # SAMPLES_RUST

samples/rust/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ obj-$(CONFIG_SAMPLE_RUST_NETFILTER) += rust_netfilter.o
1515
obj-$(CONFIG_SAMPLE_RUST_ECHO_SERVER) += rust_echo_server.o
1616
obj-$(CONFIG_SAMPLE_RUST_FS) += rust_fs.o
1717
obj-$(CONFIG_SAMPLE_RUST_SELFTESTS) += rust_selftests.o
18+
obj-$(CONFIG_SAMPLE_RUST_MLX4) += rust_mlx4.o
1819

1920
subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs

samples/rust/rust_mlx4.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
//! Rust infiniband mls4 device sample.
4+
5+
use kernel::mlx4;
6+
use kernel::prelude::*;
7+
8+
module! {
9+
type: RustMlx4,
10+
name: "rust_mlx4",
11+
author: "Rust for Linux Contributors",
12+
description: "Rust infiniband mlx4 device sample",
13+
license: "GPL",
14+
}
15+
16+
struct RustMlx4Ops;
17+
18+
#[vtable]
19+
impl mlx4::Mlx4Operation for RustMlx4Ops {
20+
fn add() -> Result {
21+
Ok(())
22+
}
23+
fn remove() -> Result {
24+
Ok(())
25+
}
26+
fn event() -> Result {
27+
Ok(())
28+
}
29+
}
30+
31+
struct RustMlx4 {
32+
_dev: Pin<Box<mlx4::Registration<RustMlx4Ops>>>,
33+
}
34+
35+
impl kernel::Module for RustMlx4 {
36+
fn init(name: &'static CStr, _module: &'static ThisModule) -> Result<Self> {
37+
pr_info!("Rust infiniband mlx4 driver sample (init)\n");
38+
39+
Ok(RustMlx4 {
40+
_dev: mlx4::Registration::new_pinned(name)?,
41+
})
42+
}
43+
}
44+
45+
impl Drop for RustMlx4 {
46+
fn drop(&mut self) {
47+
pr_info!("Rust infiniband mlx4 driver sample (exit)\n");
48+
}
49+
}

0 commit comments

Comments
 (0)