Skip to content

Commit 06b9634

Browse files
fujitaNipaLocal
authored and
NipaLocal
committed
rust: core abstractions for network PHY drivers
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions. This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y. This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future. Link: rust-lang/rust#116218 Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: NipaLocal <nipa@local>
1 parent 2b67a98 commit 06b9634

File tree

5 files changed

+775
-0
lines changed

5 files changed

+775
-0
lines changed

drivers/net/phy/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ config FIXED_PHY
6060

6161
Currently tested with mpc866ads and mpc8349e-mitx.
6262

63+
config RUST_PHYLIB_ABSTRACTIONS
64+
bool "Rust PHYLIB abstractions support"
65+
depends on RUST
66+
depends on PHYLIB=y
67+
help
68+
Adds support needed for PHY drivers written in Rust. It provides
69+
a wrapper around the C phylib core.
70+
6371
config SFP
6472
tristate "SFP cage support"
6573
depends on I2C && PHYLINK

rust/bindings/bindings_helper.h

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
#include <kunit/test.h>
1010
#include <linux/errname.h>
11+
#include <linux/ethtool.h>
12+
#include <linux/mdio.h>
13+
#include <linux/phy.h>
1114
#include <linux/slab.h>
1215
#include <linux/refcount.h>
1316
#include <linux/wait.h>

rust/kernel/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![no_std]
1515
#![feature(allocator_api)]
1616
#![feature(coerce_unsized)]
17+
#![feature(const_maybe_uninit_zeroed)]
1718
#![feature(dispatch_from_dyn)]
1819
#![feature(new_uninit)]
1920
#![feature(offset_of)]
@@ -38,6 +39,8 @@ pub mod init;
3839
pub mod ioctl;
3940
#[cfg(CONFIG_KUNIT)]
4041
pub mod kunit;
42+
#[cfg(CONFIG_NET)]
43+
pub mod net;
4144
pub mod prelude;
4245
pub mod print;
4346
mod static_assert;

rust/kernel/net.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
//! Networking.
4+
5+
#[cfg(CONFIG_RUST_PHYLIB_ABSTRACTIONS)]
6+
pub mod phy;

0 commit comments

Comments
 (0)