From: Boqun Feng <boqun.feng@gmail.com>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: netdev@vger.kernel.org, rust-for-linux@vger.kernel.org,
andrew@lunn.ch, tmgross@umich.edu,
miguel.ojeda.sandonis@gmail.com, benno.lossin@proton.me,
wedsonaf@gmail.com, aliceryhl@google.com
Subject: Re: [PATCH net-next v9 1/4] rust: core abstractions for network PHY drivers
Date: Mon, 4 Dec 2023 18:00:15 -0800 [thread overview]
Message-ID: <ZW6EL-4XaoY3n4J9@Boquns-Mac-mini.home> (raw)
In-Reply-To: <20231205011420.1246000-2-fujita.tomonori@gmail.com>
On Tue, Dec 05, 2023 at 10:14:17AM +0900, FUJITA Tomonori wrote:
[...]
> + /// Gets the current link state.
> + ///
> + /// It returns true if the link is up.
> + pub fn is_link_up(&self) -> bool {
> + const LINK_IS_UP: u64 = 1;
> + // TODO: the code to access to the bit field will be replaced with automatically
> + // generated code by bindgen when it becomes possible.
> + // SAFETY: The struct invariant ensures that we may access
> + // this field without additional synchronization.
> + let bit_field = unsafe { &(*self.0.get())._bitfield_1 };
> + bit_field.get(14, 1) == LINK_IS_UP
I made a mistake here [1], this should be:
let bit_field = unsafe { &*(core::ptr::addr_of!((*self.0.get())._bitfield_1)) };
bit_field.get(14, 1) == LINK_IS_UP
without `core::ptr::add_of!`, `*(self.0.get())` would still create a
temporary `&` to the underlying object I believe. `addr_of!` is the way
to avoid create the temporary reference. Same for the other functions.
[1]: https://lore.kernel.org/rust-for-linux/ZT6fzfV9GUQOZnlx@boqun-archlinux/
Regards,
Boqun
> + }
> +
> + /// Gets the current auto-negotiation configuration.
> + ///
> + /// It returns true if auto-negotiation is enabled.
> + pub fn is_autoneg_enabled(&self) -> bool {
> + // TODO: the code to access to the bit field will be replaced with automatically
> + // generated code by bindgen when it becomes possible.
> + // SAFETY: The struct invariant ensures that we may access
> + // this field without additional synchronization.
> + let bit_field = unsafe { &(*self.0.get())._bitfield_1 };
> + bit_field.get(13, 1) == bindings::AUTONEG_ENABLE as u64
> + }
> +
> + /// Gets the current auto-negotiation state.
> + ///
> + /// It returns true if auto-negotiation is completed.
> + pub fn is_autoneg_completed(&self) -> bool {
> + const AUTONEG_COMPLETED: u64 = 1;
> + // TODO: the code to access to the bit field will be replaced with automatically
> + // generated code by bindgen when it becomes possible.
> + // SAFETY: The struct invariant ensures that we may access
> + // this field without additional synchronization.
> + let bit_field = unsafe { &(*self.0.get())._bitfield_1 };
> + bit_field.get(15, 1) == AUTONEG_COMPLETED
> + }
> +
[...]
next prev parent reply other threads:[~2023-12-05 2:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-05 1:14 [PATCH net-next v9 0/4] Rust abstractions for network PHY drivers FUJITA Tomonori
2023-12-05 1:14 ` [PATCH net-next v9 1/4] rust: core " FUJITA Tomonori
2023-12-05 1:43 ` Jarkko Sakkinen
2023-12-05 2:06 ` FUJITA Tomonori
2023-12-05 2:00 ` Boqun Feng [this message]
2023-12-05 3:23 ` FUJITA Tomonori
2023-12-05 3:40 ` Boqun Feng
2023-12-07 17:25 ` Benno Lossin
2023-12-08 1:28 ` FUJITA Tomonori
2023-12-05 1:14 ` [PATCH net-next v9 2/4] rust: net::phy add module_phy_driver macro FUJITA Tomonori
2023-12-05 1:48 ` Jarkko Sakkinen
2023-12-05 3:44 ` FUJITA Tomonori
2023-12-08 14:42 ` Miguel Ojeda
2023-12-08 18:11 ` Benno Lossin
2023-12-05 1:14 ` [PATCH net-next v9 3/4] MAINTAINERS: add Rust PHY abstractions for ETHERNET PHY LIBRARY FUJITA Tomonori
2023-12-05 1:49 ` Jarkko Sakkinen
2023-12-05 1:53 ` Trevor Gross
2023-12-05 1:57 ` Jarkko Sakkinen
2023-12-05 1:53 ` Trevor Gross
2023-12-05 3:45 ` FUJITA Tomonori
2023-12-05 1:14 ` [PATCH net-next v9 4/4] net: phy: add Rust Asix PHY driver FUJITA Tomonori
2023-12-05 1:54 ` Jarkko Sakkinen
2023-12-05 2:24 ` Andrew Lunn
2023-12-05 1:35 ` [PATCH net-next v9 0/4] Rust abstractions for network PHY drivers Jarkko Sakkinen
2023-12-05 1:42 ` 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=ZW6EL-4XaoY3n4J9@Boquns-Mac-mini.home \
--to=boqun.feng@gmail.com \
--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=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).