From: Greg KH <greg@kroah.com>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: netdev@vger.kernel.org, rust-for-linux@vger.kernel.org,
andrew@lunn.ch, miguel.ojeda.sandonis@gmail.com
Subject: Re: [PATCH v1 1/3] rust: core abstractions for network PHY drivers
Date: Mon, 2 Oct 2023 11:14:36 +0200 [thread overview]
Message-ID: <2023100237-satirical-prance-bd57@gregkh> (raw)
In-Reply-To: <20231002085302.2274260-2-fujita.tomonori@gmail.com>
On Mon, Oct 02, 2023 at 05:53:00PM +0900, FUJITA Tomonori wrote:
> +/// Corresponds to the kernel's `enum phy_state`.
> +#[derive(PartialEq)]
> +pub enum DeviceState {
> + /// PHY device and driver are not ready for anything.
> + Down,
> + /// PHY is ready to send and receive packets.
> + Ready,
> + /// PHY is up, but no polling or interrupts are done.
> + Halted,
> + /// PHY is up, but is in an error state.
> + Error,
> + /// PHY and attached device are ready to do work.
> + Up,
> + /// PHY is currently running.
> + Running,
> + /// PHY is up, but not currently plugged in.
> + NoLink,
> + /// PHY is performing a cable test.
> + CableTest,
> +}
I still think these should come straight from the C code, and that
moving them to an enum makes sense to make this possible, but hey, it's
not my subsystem to maintain! :)
> +/// Wraps the kernel's `struct phy_device`.
> +///
> +/// # Invariants
> +///
> +/// `self.0` is always in a valid state.
> +#[repr(transparent)]
> +pub struct Device(Opaque<bindings::phy_device>);
> +
> +impl Device {
> + /// Creates a new [`Device`] instance from a raw pointer.
> + ///
> + /// # Safety
> + ///
> + /// For the duration of the lifetime 'a, the pointer must be valid for writing and nobody else
> + /// may read or write to the `phy_device` object.
> + pub unsafe fn from_raw<'a>(ptr: *mut bindings::phy_device) -> &'a mut Self {
> + unsafe { &mut *ptr.cast() }
> + }
> +
> + /// Gets the id of the PHY.
> + pub fn id(&mut self) -> u32 {
> + let phydev = self.0.get();
> + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`.
> + unsafe { (*phydev).phy_id }
> + }
Naming question, why are you making this "id" instead of "phy_id"
like the C code has? Same for many of these bindings.
> + /// Returns true if the link is up.
> + pub fn get_link(&mut self) -> bool {
> + const LINK_IS_UP: u32 = 1;
> + let phydev = self.0.get();
> + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`.
> + unsafe { (*phydev).link() == LINK_IS_UP }
> + }
"get_" normally means to grab a reference, if this isn't matching a C
call, why not just call it link_is_up or to match your other state
checks "is_link_up"?
but hey, I'm just bikeshedding at this point in time, if they maintainer
likes these as-is, keep them :)
thanks,
greg k-h
next prev parent reply other threads:[~2023-10-02 9:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-02 8:52 [PATCH v1 0/3] Rust abstractions for network PHY drivers FUJITA Tomonori
2023-10-02 8:53 ` [PATCH v1 1/3] rust: core " FUJITA Tomonori
2023-10-02 9:14 ` Greg KH [this message]
2023-10-02 14:52 ` Andrew Lunn
2023-10-03 0:33 ` FUJITA Tomonori
2023-10-03 1:40 ` Andrew Lunn
2023-10-03 3:43 ` FUJITA Tomonori
2023-10-03 6:31 ` Greg KH
2023-10-03 6:40 ` FUJITA Tomonori
2023-10-03 12:45 ` Andrew Lunn
2023-10-02 15:24 ` Andrew Lunn
2023-10-03 23:46 ` FUJITA Tomonori
2023-10-02 8:53 ` [PATCH v1 2/3] MAINTAINERS: add Rust PHY abstractions to the ETHERNET PHY LIBRARY FUJITA Tomonori
2023-10-02 8:53 ` [PATCH v1 3/3] net: phy: add Rust Asix PHY driver FUJITA Tomonori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2023100237-satirical-prance-bd57@gregkh \
--to=greg@kroah.com \
--cc=andrew@lunn.ch \
--cc=fujita.tomonori@gmail.com \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).