Rust abstractions for network PHY drivers
From: | FUJITA Tomonori <fujita.tomonori-AT-gmail.com> | |
To: | rust-for-linux-AT-vger.kernel.org | |
Subject: | [RFC PATCH v2 0/3] Rust abstractions for network PHY drivers | |
Date: | Sun, 24 Sep 2023 15:48:59 +0900 | |
Message-ID: | <20230924064902.1339662-1-fujita.tomonori@gmail.com> | |
Cc: | andrew-AT-lunn.ch, tmgross-AT-umich.edu, miguel.ojeda.sandonis-AT-gmail.com | |
Archive-link: | Article |
This patchset adds Rust abstractions for network PHY drivers. It doesn't fully cover the C APIs for PHY drivers but I think that it's already useful. I implement two PHY drivers (Asix AX88772A PHYs and Realtek Generic FE-GE). Seems they work well with real hardware. Thanks for lots of feedback on v1! I've tried to address them but sorry if I missed some. Here are major changes from v1: - uses rustified enum for C's phy_state enum This guarantees that C and Rust never diverge. If the C code is changed without updating the Rust code, compiling the Rust code fails. Note that C allows using a value that isn't defined in phy_state enum for phy_state. It leads to undefined behaviour in Rust side. But this enum is used as state machine in the C side. Such should not happen. If it happens, it's a bug on the C side. - adds the Asix driver to drivers/net/phy/ instead of samples/rust/ I've implemented all the features of drivers/net/phy/ax88796b.c. The features of C and Rust versions are equivalent. You can choose either on kernel configuration. I suppose that how to handle drivers in Rust will be discussed in KS or somewhere. Until then, you can use this to make reviewing the abstractions easier. - uses static allocation for phy_driver v1 dynamically allocates memory for phy_driver. v2 uses static allocation; the registration of drivers is much simpler. I added a macro that handles registering drivers, building the device id table, etc. - cleaning up the interface for PHYLIB Uses u16 for register and value, keeps genphy_ function names, dropping lockless_ functions without MDIO bus locked, etc. u8 could be used for C22 registers but I like to use the same type for C22 and C45. v1: https://lwn.net/ml/rust-for-linux/20230913133609.1668758-... FUJITA Tomonori (3): rust: core abstractions for network PHY drivers MAINTAINERS: add Rust PHY abstractions file to the ETHERNET PHY LIBRARY net: phy: add Rust Asix PHY driver MAINTAINERS | 2 + drivers/net/phy/Kconfig | 16 + drivers/net/phy/Makefile | 8 +- drivers/net/phy/ax88796b_rust.rs | 147 ++++++ rust/Makefile | 1 + rust/bindings/bindings_helper.h | 3 + rust/kernel/lib.rs | 3 + rust/kernel/net.rs | 6 + rust/kernel/net/phy.rs | 760 +++++++++++++++++++++++++++++++ rust/uapi/uapi_helper.h | 1 + 10 files changed, 946 insertions(+), 1 deletion(-) create mode 100644 drivers/net/phy/ax88796b_rust.rs create mode 100644 rust/kernel/net.rs create mode 100644 rust/kernel/net/phy.rs base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d -- 2.34.1