[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240418.221532.1329700378176129871.fujita.tomonori@gmail.com>
Date: Thu, 18 Apr 2024 22:15:32 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: benno.lossin@...ton.me
Cc: andrew@...n.ch, fujita.tomonori@...il.com, netdev@...r.kernel.org,
rust-for-linux@...r.kernel.org, tmgross@...ch.edu
Subject: Re: [PATCH net-next v1 2/4] rust: net::phy support C45 helpers
On Wed, 17 Apr 2024 08:20:25 +0000
Benno Lossin <benno.lossin@...ton.me> wrote:
> On 17.04.24 00:30, Andrew Lunn wrote:
>>> I think we could also do a more rusty solution. For example we could
>>> have these generic functions for `phy::Device`:
>>>
>>> fn read_register<R: Register>(&mut self, which: R::Index) -> Result<R::Value>;
>>> fn write_register<R: Register>(&mut self, which: R::Index, value: R::Value) -> Result;
>>>
>>> That way we can support many different registers without polluting the
>>> namespace. We can then have a `C45` register and a `C22` register and a
>>> `C45OrC22` (maybe we should use `C45_OrC22` instead, since I can read
>>> that better, but let's bikeshed when we have the actual patch).
>>>
>>> Calling those functions would look like this:
>>>
>>> let value = dev.read_register::<C45>(reg1)?;
>>> dev.write_register::<C45>(reg2, value)?;
>>
>> I don't know how well that will work out in practice. The addressing
>> schemes for C22 and C45 are different.
>>
>> C22 simply has 32 registers, numbered 0-31.
>>
>> C45 has 32 MDIO manageable devices (MMD) each with 65536 registers.
>>
>> All of the 32 C22 registers have well defined names, which are listed
>> in mii.h. Ideally we want to keep the same names. The most of the MMD
>> also have defined names, listed in mdio.h. Many of the registers are
>> also named in mdio.h, although vendors do tend to add more vendor
>> proprietary registers.
>>
>> Your R::Index would need to be a single value for C22 and a tuple of
>> two values for C45.
>
> Yes that was my idea:
>
> enum C22Index {
> // The unique 32 names of the C22 registers...
> }
>
> impl Register for C22 {
> type Index = C22Index;
> type Value = u16;
> }
>
> impl Register for C45 {
> type Index = (u8, u16); // We could also create a newtype that wraps this and give it a better name.
> type Value = u16;
> }
C45 looks a bit odd to me because C45 has a member which isn't a
register. It's a value to specify which MMD you access to.
Powered by blists - more mailing lists