From: Trevor Gross <tmgross@umich.edu>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: aliceryhl@google.com, miguel.ojeda.sandonis@gmail.com,
wedsonaf@gmail.com, rust-for-linux@vger.kernel.org,
andrew@lunn.ch, benno.lossin@proton.me
Subject: Re: [RFC PATCH v3 1/3] rust: core abstractions for network PHY drivers
Date: Thu, 12 Oct 2023 00:20:24 -0400 [thread overview]
Message-ID: <CALNs47sT2mhP+q7ESEMwuJpQaOS8++xortWLv-Q95Xxr4YXg0Q@mail.gmail.com> (raw)
In-Reply-To: <20231012.121656.1502998233251919494.fujita.tomonori@gmail.com>
On Wed, Oct 11, 2023 at 11:17 PM FUJITA Tomonori
<fujita.tomonori@gmail.com> wrote:
> >> 3. multiple phy drivers has one id in device_table.
> >>
> >> How these approach can handle the case?
> >>
> >> Also note that there is a driver doesn't define PHY_ID, uses
> >> match_phy_device() instead.
> >
> > In this case you would just need to put the same `DeviceId` in the
> > array for both drivers, perhaps as a const. I think this proposal
>
> I'm not sure modpost can handle it.
>
> I guess that you would have two exact same lines in modules.alias,
> which might works but I don't think that it's not designed to handle
> such.
>
> Or the macro needs to find the same id and keep only one.
Good point, scratch that. What about this logic:
1. Leave `Driver` as you have it, one `DeviceId` with a null default
2. Use the macro to create a `const fn` to build the mdio_device_table
so you can add logic (like in the playground I linked)
3. Make this function skip anything that doesn't specify a `DeviceId`,
i.e. if the `DeviceID` is null don't add it to the table
4. Any devices that don't specify a `DeviceId` must specify
`match_phy_device` (I think, since it will never get matched
otherwise?). This could be verified in `create_phy_driver`
4. In the macro, allow specifying extra `DeviceId`s that aren't
specific to any phy.
Something complex like the icplus driver [1] is probably a good test
to see how any of these work out. I think that would look something
like:
const IP175C_PHY_ID: u32 = 0x02430d80;
const IP1001_PHY_ID: u32 = 0x02430d90;
const IP101A_PHY_ID: u32 = 0x02430c54;
impl Driver for Ip175c {
const PHY_DEVICE_ID: phy::DeviceId =
phy::DeviceId::match_model(IP175C_PHY_ID);
// ...
}
impl Driver for Ip1001 {
const PHY_DEVICE_ID: phy::DeviceId =
phy::DeviceId::match_model(IP1001_PHY_ID);
// ...
}
impl Driver for Ip101a {
// no override of PHY_DEVICE_ID
fn match_phy_device(_dev: &mut Device) -> bool { /* ... */ }
// ...
}
impl Driver for Ip101g {
// no override of PHY_DEVICE_ID
fn match_phy_device(_dev: &mut Device) -> bool { /* ... */ }
// ...
}
kernel::module_phy_driver! {
// the first two drivers provide match_model for IP175C_PHY_ID
and IP1001_PHY_ID
drivers: [Ip175, Ip1001, Ip101a, Ip101g],
// this provides the extra match_exact
// this field is optional, most drivers won't need it
additional_matches: [phy::DeviceId::match_exact(IP101A_PHY_ID)],
name: "...",
author: "...",
description: "ICPlus IP175C/IP101A/IP101G/IC1001 PHY drivers",
license: "...",
}
Nice because the easy default behavior is to add PHY_DEVICE_ID to the
table if it is specified. But you get the flexibility to not provide
it, or add extra entries that aren't specific to a device. Any
thoughts?
If this works, maybe PHY_DEVICE_ID should be Option<DeviceId> to make
it more clear that you don't have to specify anything?
---
I know you have the `DeviceId` functions called `new_with_exact_mask`
and similar. Maybe rename them to `match_exact`, `match_vendor`,
`match_model` so they are easier to discover based on the C macros?
Also more terse.
[1]: https://elixir.bootlin.com/linux/v6.6-rc5/source/drivers/net/phy/icplus.c
next prev parent reply other threads:[~2023-10-12 4:20 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 22:55 [RFC PATCH v3 0/3] Rust abstractions for network PHY drivers FUJITA Tomonori
2023-09-28 22:55 ` [RFC PATCH v3 1/3] rust: core " FUJITA Tomonori
2023-09-29 6:03 ` Greg KH
2023-09-29 8:38 ` FUJITA Tomonori
2023-09-29 9:11 ` Trevor Gross
2023-10-02 14:08 ` Andrew Lunn
2023-10-02 16:24 ` Miguel Ojeda
2023-10-02 19:08 ` Andrew Lunn
2023-10-09 12:25 ` Miguel Ojeda
2023-10-09 15:50 ` Andrew Lunn
2023-10-09 16:16 ` Miguel Ojeda
2023-10-09 16:29 ` Andrew Lunn
2023-10-10 17:31 ` Miguel Ojeda
2023-10-02 16:37 ` Trevor Gross
2023-09-29 11:39 ` Miguel Ojeda
2023-09-29 12:23 ` Andrew Lunn
2023-10-01 13:08 ` FUJITA Tomonori
2023-09-29 8:50 ` Trevor Gross
2023-09-29 18:42 ` Miguel Ojeda
2023-10-10 19:19 ` Wedson Almeida Filho
2023-10-10 20:28 ` Andrew Lunn
2023-10-10 21:00 ` Wedson Almeida Filho
2023-10-10 23:34 ` Andrew Lunn
2023-10-11 1:56 ` Wedson Almeida Filho
2023-10-11 5:17 ` FUJITA Tomonori
2023-10-10 22:50 ` Trevor Gross
2023-10-10 22:53 ` Miguel Ojeda
2023-10-10 23:06 ` FUJITA Tomonori
2023-10-10 23:12 ` Trevor Gross
2023-10-11 23:57 ` FUJITA Tomonori
2023-10-12 3:09 ` Trevor Gross
2023-10-12 3:16 ` FUJITA Tomonori
2023-10-12 4:20 ` Trevor Gross [this message]
2023-10-12 15:05 ` Andrew Lunn
2023-10-11 6:56 ` FUJITA Tomonori
2023-10-11 14:28 ` Wedson Almeida Filho
2023-10-11 14:59 ` FUJITA Tomonori
2023-10-11 23:28 ` FUJITA Tomonori
2023-10-11 17:35 ` Trevor Gross
2023-09-28 22:55 ` [RFC PATCH v3 2/3] MAINTAINERS: add Rust PHY abstractions to the ETHERNET PHY LIBRARY FUJITA Tomonori
2023-09-28 22:55 ` [RFC PATCH v3 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=CALNs47sT2mhP+q7ESEMwuJpQaOS8++xortWLv-Q95Xxr4YXg0Q@mail.gmail.com \
--to=tmgross@umich.edu \
--cc=aliceryhl@google.com \
--cc=andrew@lunn.ch \
--cc=benno.lossin@proton.me \
--cc=fujita.tomonori@gmail.com \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
/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).