Skip to content

Commit

Permalink
rust: core abstractions for network PHY drivers
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
fujita authored and NipaLocal committed Dec 13, 2023
1 parent 06ee118 commit 7a2c3da
Show file tree
Hide file tree
Showing 5 changed files with 774 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/net/phy/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ config FIXED_PHY

Currently tested with mpc866ads and mpc8349e-mitx.

config RUST_PHYLIB_ABSTRACTIONS
bool "Rust PHYLIB abstractions support"
depends on RUST
depends on PHYLIB=y
help
Adds support needed for PHY drivers written in Rust. It provides
a wrapper around the C phylib core.

config SFP
tristate "SFP cage support"
depends on I2C && PHYLINK
Expand Down
3 changes: 3 additions & 0 deletions rust/bindings/bindings_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#include <kunit/test.h>
#include <linux/errname.h>
#include <linux/ethtool.h>
#include <linux/mdio.h>
#include <linux/phy.h>
#include <linux/slab.h>
#include <linux/refcount.h>
#include <linux/wait.h>
Expand Down
3 changes: 3 additions & 0 deletions rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![no_std]
#![feature(allocator_api)]
#![feature(coerce_unsized)]
#![feature(const_maybe_uninit_zeroed)]
#![feature(dispatch_from_dyn)]
#![feature(new_uninit)]
#![feature(offset_of)]
Expand All @@ -38,6 +39,8 @@ pub mod init;
pub mod ioctl;
#[cfg(CONFIG_KUNIT)]
pub mod kunit;
#[cfg(CONFIG_NET)]
pub mod net;
pub mod prelude;
pub mod print;
mod static_assert;
Expand Down
6 changes: 6 additions & 0 deletions rust/kernel/net.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-2.0

//! Networking.

#[cfg(CONFIG_RUST_PHYLIB_ABSTRACTIONS)]
pub mod phy;
Loading

0 comments on commit 7a2c3da

Please sign in to comment.