rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
To: miguel.ojeda.sandonis@gmail.com
Cc: fujita.tomonori@gmail.com, netdev@vger.kernel.org,
	rust-for-linux@vger.kernel.org, andrew@lunn.ch, greg@kroah.com,
	tmgross@umich.edu, wedsonaf@gmail.com
Subject: Re: [PATCH net-next v3 1/3] rust: core abstractions for network PHY drivers
Date: Thu, 12 Oct 2023 12:59:37 +0900 (JST)	[thread overview]
Message-ID: <20231012.125937.1346884503622296050.fujita.tomonori@gmail.com> (raw)
In-Reply-To: <CANiq72nBSyQw+vFayPco5b_-DDAKNqmhE7xiXSVbg920_ttAeQ@mail.gmail.com>

On Mon, 9 Oct 2023 14:59:19 +0200
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:

> Hi Tomonori,
> 
> A few nits I noticed. Please note that this is not really a full
> review, and that I recommend that other people like Wedson should take
> a look again and OK these abstractions before this is merged.
> 
> On Mon, Oct 9, 2023 at 3:41 AM FUJITA Tomonori
> <fujita.tomonori@gmail.com> wrote:
>>
>> +config RUST_PHYLIB_BINDINGS
> 
> This should be called ABSTRACTIONS. Please see:

Fixed.

>     https://docs.kernel.org/rust/general-information.html#abstractions-vs-bindings
> 
> Also, could this symbol go elsewhere?

This symbol is used by the third patch. Where do you want this? 


>> +        bool "PHYLIB bindings support"
> 
> Ditto.

Updated.


>> +          a wrapper around the C phlib core.
> 
> Typo.

Oops, sorry.


>> +#![feature(const_maybe_uninit_zeroed)]
> 
> The patch message should justify this addition and warn about it.

I added the following to the commit log.

This patch enables unstable const_maybe_uninit_zeroed feature for
kernel crate to enable unsafe code to handle a constant value with
uninitialized data. With the feature, the abstractions can initialize
a phy_driver structure with zero easily; instead of initializing all
the members by hand.


>> diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
>> new file mode 100644
>> index 000000000000..f31983bf0460
>> --- /dev/null
>> +++ b/rust/kernel/net/phy.rs
>> @@ -0,0 +1,733 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +// Copyright (C) 2023 FUJITA Tomonori <fujita.tomonori@gmail.com>
> 
> Newline missing.

Added.


>> +    /// Full-duplex mode
> 
> Please use the style of the rest of the Rust comments.

I'm not sure what the style should be but something like the
following?

/// Represents duplex mode.
pub enum DuplexMode {
    /// PHY is in full-duplex mode.
    Full,

>> +/// An instance of a PHY device.
>> +/// Wraps the kernel's `struct phy_device`.
> 
> That should be separated.

Added.


>> +    /// For the duration of the lifetime 'a, the pointer must be valid for writing and nobody else
> 
> Missing Markdown around the lifetime.

Fixed.


>> +        // FIXME: enum-cast
> 
> Please explain what needs to be fixed.

Added.


>> +    /// Executes software reset the PHY via BMCR_RESET bit.
> 
> Markdown missing (multiple instances).

Can you elaborate?


>> +    /// Reads Link partner ability.
> 
> Why is "link" capitalized here?

Fixed.


>> +/// Creates the kernel's `phy_driver` instance.
>> +///
>> +/// This is used by [`module_phy_driver`] macro to create a static array of phy_driver`.
> 
> Broken formatting? Does `rustdoc` complain about it?

Yes, sorry about that.


>> +/// The `drivers` points to an array of `struct phy_driver`, which is
>> +/// registered to the kernel via `phy_drivers_register`.
> 
> Perhaps "The `drivers` field"?

I replaced this with the following comment suggested by Benno.

/// All elements of the `drivers` slice are valid and currently registered
/// to the kernel via `phy_drivers_register`.


>> +            // SAFETY: The type invariants guarantee that self.drivers is valid.
> 
> Markdown.

Fixed.


>> +/// Represents the kernel's `struct mdio_device_id`.
>> +pub struct DeviceId {
>> +    /// Corresponds to `phy_id` in `struct mdio_device_id`.
>> +    pub id: u32,
>> +    mask: DeviceMask,
>> +}
> 
> It would be nice to explain why the field is `pub`.

Added.


>> +    /// Get a mask as u32.
> 
> Markdown.

Fixed.


> This patch could be split a bit too, but that is up to the maintainers.

Yeah.


>> +/// Declares a kernel module for PHYs drivers.
>> +///
>> +/// This creates a static array of `struct phy_driver` and registers it.
> 
> "kernel's" or similar

Added.


>> +/// This also corresponds to the kernel's MODULE_DEVICE_TABLE macro, which embeds the information
> 
> Markdown.

Fixed.

>> +/// for module loading into the module binary file. Every driver needs an entry in device_table.
> 
> Markdown.

Fixed.


>> +/// # Examples
>> +///
>> +/// ```ignore
>> +///
>> +/// use kernel::net::phy::{self, DeviceId, Driver};
>> +/// use kernel::prelude::*;
>> +///
>> +/// kernel::module_phy_driver! {
>> +///     drivers: [PhyAX88772A, PhyAX88772C, PhyAX88796B],
>> +///     device_table: [
>> +///         DeviceId::new_with_driver::<PhyAX88772A>(),
>> +///         DeviceId::new_with_driver::<PhyAX88772C>(),
>> +///         DeviceId::new_with_driver::<PhyAX88796B>()
>> +///     ],
>> +///     name: "rust_asix_phy",
>> +///     author: "Rust for Linux Contributors",
>> +///     description: "Rust Asix PHYs driver",
>> +///     license: "GPL",
>> +/// }
>> +/// ```
> 
> Please add an example above with the expansion of the macro so that it
> is easy to understand at a glance, see e.g. what Benno did in
> `pin-init` (`rust/init*`).

Added.

Thanks a lot!

  parent reply	other threads:[~2023-10-12  3:59 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09  1:39 [PATCH net-next v3 0/3] Rust abstractions for network PHY drivers FUJITA Tomonori
2023-10-09  1:39 ` [PATCH net-next v3 1/3] rust: core " FUJITA Tomonori
2023-10-09  3:17   ` Trevor Gross
2023-10-09 12:19   ` Benno Lossin
2023-10-09 13:02     ` Andrew Lunn
2023-10-09 13:56       ` Benno Lossin
2023-10-09 14:13         ` Andrew Lunn
2023-10-11 14:16     ` FUJITA Tomonori
2023-10-09 12:59   ` Miguel Ojeda
2023-10-09 13:49     ` FUJITA Tomonori
2023-10-09 14:32       ` Miguel Ojeda
2023-10-09 15:15         ` FUJITA Tomonori
2023-10-09 15:19           ` Miguel Ojeda
2023-10-09 15:11       ` Greg KH
2023-10-09 15:24         ` FUJITA Tomonori
2023-10-09 15:39           ` Miguel Ojeda
2023-10-09 15:50             ` FUJITA Tomonori
2023-10-11  9:59               ` Miguel Ojeda
2023-10-11 23:18                 ` FUJITA Tomonori
2023-10-13 11:59                   ` Miguel Ojeda
2023-10-13 15:15                     ` FUJITA Tomonori
2023-10-13 18:33                       ` Miguel Ojeda
2023-10-14 12:31                         ` FUJITA Tomonori
2023-10-14 16:19                           ` Miguel Ojeda
2023-10-12  0:29                 ` FUJITA Tomonori
2023-10-09 21:07           ` Trevor Gross
2023-10-09 21:21             ` Andrew Lunn
2023-10-11  7:04             ` FUJITA Tomonori
2023-10-09 13:54     ` Andrew Lunn
2023-10-09 14:48       ` Miguel Ojeda
2023-10-09 17:04         ` Andrew Lunn
2023-10-12  3:59     ` FUJITA Tomonori [this message]
2023-10-12  4:43       ` Trevor Gross
2023-10-12  7:09         ` FUJITA Tomonori
2023-10-11 18:29   ` Boqun Feng
2023-10-12  5:58     ` FUJITA Tomonori
2023-10-12  6:34       ` Boqun Feng
2023-10-12  6:44         ` FUJITA Tomonori
2023-10-12  7:02           ` FUJITA Tomonori
2023-10-12  7:13             ` Boqun Feng
2023-10-12  7:32               ` Trevor Gross
2023-10-12  7:58                 ` FUJITA Tomonori
2023-10-12  9:10                   ` Benno Lossin
2023-10-13  4:17                     ` Boqun Feng
2023-10-13  5:45                       ` FUJITA Tomonori
2023-10-13  7:56                         ` Benno Lossin
2023-10-13  9:53                           ` FUJITA Tomonori
2023-10-13 10:03                             ` Benno Lossin
2023-10-13 10:53                               ` FUJITA Tomonori
2023-10-14  7:47                                 ` Benno Lossin
2023-10-14 21:55                                   ` Andrew Lunn
2023-10-14 22:18                                     ` Benno Lossin
2023-10-14 22:33                                       ` Andrew Lunn
2023-10-14  4:11                             ` Boqun Feng
2023-10-14 11:59                             ` Miguel Ojeda
2023-10-12  7:07           ` Boqun Feng
2023-10-09  1:39 ` [PATCH net-next v3 2/3] MAINTAINERS: add Rust PHY abstractions to the ETHERNET PHY LIBRARY FUJITA Tomonori
2023-10-09  1:39 ` [PATCH net-next v3 3/3] net: phy: add Rust Asix PHY driver FUJITA Tomonori
2023-10-09  3:22   ` Trevor Gross
2023-10-09  7:23   ` Jiri Pirko
2023-10-09 10:58     ` Miguel Ojeda
2023-10-09 11:41     ` FUJITA Tomonori
2023-10-09 12:32     ` Andrew Lunn
2023-10-09 14:01       ` Miguel Ojeda
2023-10-09 14:31         ` Andrew Lunn
2023-10-09 15:27           ` Miguel Ojeda
2023-10-09 15:35             ` Miguel Ojeda
2023-10-09 16:09               ` Andrew Lunn
2023-10-09 10:10   ` Greg KH
2023-10-12 11:57     ` FUJITA Tomonori
2023-10-09 12:42   ` Benno Lossin
2023-10-09 13:15     ` Andrew Lunn
2023-10-09 13:45       ` Benno Lossin
2023-10-09 12:48 ` [PATCH net-next v3 0/3] Rust abstractions for network PHY drivers Andrew Lunn
2023-10-09 12:53   ` Miguel Ojeda
2023-10-09 13:06     ` Greg KH
2023-10-09 14:13       ` Miguel Ojeda
2023-10-09 14:52         ` Greg KH
2023-10-09 15:06           ` Miguel Ojeda
2023-10-09 15:14             ` Greg KH
2023-10-09 15:15               ` Miguel Ojeda
2023-10-09 13:24     ` Andrew Lunn
2023-10-09 13:36       ` Miguel Ojeda
2023-10-09 14:21     ` Andrea Righi
2023-10-09 14:22       ` Miguel Ojeda
2023-10-09 14:56       ` Andrew Lunn
2023-10-09 15:04         ` Greg KH
2023-10-09 15:10           ` Miguel Ojeda
2023-10-09 15:15             ` Miguel Ojeda
2023-10-09 14:56       ` Greg KH
2023-10-09 15:09         ` Andrea Righi

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=20231012.125937.1346884503622296050.fujita.tomonori@gmail.com \
    --to=fujita.tomonori@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=greg@kroah.com \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --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).