rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benno Lossin <benno.lossin@proton.me>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>,
	rust-for-linux@vger.kernel.org
Cc: andrew@lunn.ch, tmgross@umich.edu
Subject: Re: [RFC PATCH v2 2/2] rust: net::phy support for C45 genphy helpers
Date: Sat, 01 Jun 2024 12:23:16 +0000	[thread overview]
Message-ID: <c67b9654-cc6c-41b0-9693-b8830ec42e78@proton.me> (raw)
In-Reply-To: <20240601043535.53545-3-fujita.tomonori@gmail.com>

On 01.06.24 06:35, FUJITA Tomonori wrote:
> Add support for genphy_c45_* helper functions. Instead of adding
> genphy_c45_ methods, this unifies the API for genphy functions with
> trait.
> 
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
>  rust/kernel/net/phy.rs | 49 +++++++++++++++++++++++++++++++++---------
>  1 file changed, 39 insertions(+), 10 deletions(-)
> 
> diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
> index 286fd5a7ec91..aabd714ae3f6 100644
> --- a/rust/kernel/net/phy.rs
> +++ b/rust/kernel/net/phy.rs
> @@ -248,16 +248,8 @@ pub fn genphy_suspend(&mut self) -> Result {
>      }
> 
>      /// Checks the link status and updates current link state.
> -    pub fn genphy_read_status(&mut self) -> Result<u16> {
> -        let phydev = self.0.get();
> -        // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`.
> -        // So it's just an FFI call.
> -        let ret = unsafe { bindings::genphy_read_status(phydev) };
> -        if ret < 0 {
> -            Err(Error::from_errno(ret))
> -        } else {
> -            Ok(ret as u16)
> -        }
> +    pub fn genphy_read_status<G: reg::GenPhyOps>(&mut self) -> Result<u16> {

With this change, don't you also need a change in the ax88796b Rust
driver?

> +        G::read_status(self)
>      }
> 
>      /// Updates the link status.
> @@ -446,6 +438,43 @@ fn write(&self, dev: &mut Device, val: u16) -> Result {
>              })
>          }
>      }
> +
> +    /// PHY helper functions.
> +    ///
> +    /// This trait is used to implement some helper functions executed either
> +    /// via C22 or C45 registers.
> +    pub trait GenPhyOps {

Why does this need another trait? Can't it be part of the `Register`
(currently named `Access`) trait?

---
Cheers,
Benno

> +        /// Checks the link status and updates current link state.
> +        fn read_status(dev: &mut Device) -> Result<u16>;
> +    }
> +
> +    impl GenPhyOps for C22 {
> +        fn read_status(dev: &mut Device) -> Result<u16> {
> +            let phydev = dev.0.get();
> +            // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`.
> +            // So it's just an FFI call.
> +            let ret = unsafe { bindings::genphy_read_status(phydev) };
> +            if ret < 0 {
> +                Err(Error::from_errno(ret))
> +            } else {
> +                Ok(ret as u16)
> +            }
> +        }
> +    }
> +
> +    impl GenPhyOps for C45 {
> +        fn read_status(dev: &mut Device) -> Result<u16> {
> +            let phydev = dev.0.get();
> +            // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`.
> +            // So it's just an FFI call.
> +            let ret = unsafe { bindings::genphy_c45_read_status(phydev) };
> +            if ret < 0 {
> +                Err(Error::from_errno(ret))
> +            } else {
> +                Ok(ret as u16)
> +            }
> +        }
> +    }
>  }
> 
>  /// Defines certain other features this PHY supports (like interrupts).
> --
> 2.34.1
> 


  reply	other threads:[~2024-06-01 12:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-01  4:35 [RFC PATCH v2 0/2] net::phy support for C45 FUJITA Tomonori
2024-06-01  4:35 ` [RFC PATCH v2 1/2] rust: net::phy support for C45 register access FUJITA Tomonori
2024-06-01 12:21   ` Benno Lossin
2024-06-02  7:24     ` FUJITA Tomonori
2024-06-02  9:59       ` Benno Lossin
2024-06-01  4:35 ` [RFC PATCH v2 2/2] rust: net::phy support for C45 genphy helpers FUJITA Tomonori
2024-06-01 12:23   ` Benno Lossin [this message]
2024-06-02  7:36     ` 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=c67b9654-cc6c-41b0-9693-b8830ec42e78@proton.me \
    --to=benno.lossin@proton.me \
    --cc=andrew@lunn.ch \
    --cc=fujita.tomonori@gmail.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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).