[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALNs47v+35RX4+ibHrcZgrJEJ52RqWRQUBa=_Aky_6gk1ika4w@mail.gmail.com>
Date: Tue, 16 Apr 2024 00:34:30 -0400
From: Trevor Gross <tmgross@...ch.edu>
To: FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: netdev@...r.kernel.org, andrew@...n.ch, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH net-next v1 4/4] net: phy: add Applied Micro QT2025 PHY driver
On Mon, Apr 15, 2024 at 6:47 AM FUJITA Tomonori
<fujita.tomonori@...il.com> wrote:
>
> This driver supports Applied Micro Circuits Corporation QT2025 PHY,
> based on a driver for Tehuti Networks TN40xx chips.
>
> The original driver for TN40xx chips supports multiple PHY hardware
> (AMCC QT2025, TI TLK10232, Aqrate AQR105, and Marvell 88X3120,
> 88X3310, and MV88E2010). This driver is extracted from the original
> driver and modified to a PHY driver in Rust.
>
> This has been tested with Edimax EN-9320SFP+ 10G network adapter.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
> [...]
> diff --git a/drivers/net/phy/qt2025.rs b/drivers/net/phy/qt2025.rs
> new file mode 100644
> index 000000000000..e42b77753717
> --- /dev/null
> +++ b/drivers/net/phy/qt2025.rs
> @@ -0,0 +1,75 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (C) Tehuti Networks Ltd.
> +// Copyright (C) 2024 FUJITA Tomonori <fujita.tomonori@...il.com>
> +
> +//! Applied Micro Circuits Corporation QT2025 PHY driver
> +use kernel::c_str;
> +use kernel::net::phy::{self, DeviceId, Driver, Firmware};
> +use kernel::prelude::*;
> +use kernel::uapi;
> +
> +kernel::module_phy_driver! {
> + drivers: [PhyQT2025],
> + device_table: [
> + DeviceId::new_with_driver::<PhyQT2025>(),
> + ],
> + name: "qt2025_phy",
> + author: "FUJITA Tomonori <fujita.tomonori@...il.com>",
> + description: "AMCC QT2025 PHY driver",
> + license: "GPL",
> +}
> +
> +const MDIO_MMD_PMAPMD: u8 = uapi::MDIO_MMD_PMAPMD as u8;
> +const MDIO_MMD_PCS: u8 = uapi::MDIO_MMD_PCS as u8;
> +const MDIO_MMD_PHYXS: u8 = uapi::MDIO_MMD_PHYXS as u8;
> +
> +struct PhyQT2025;
> +
> +#[vtable]
> +impl Driver for PhyQT2025 {
> + const NAME: &'static CStr = c_str!("QT2025 10Gpbs SFP+");
Since 1.77 we have C string literals, `c"QT2025 10Gpbs SFP+"` (woohoo)
> + const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x0043A400);
> +
> + fn config_init(dev: &mut phy::Device) -> Result<()> {
> + let fw = Firmware::new(c_str!("qt2025-2.0.3.3.fw"), dev)?;
Same as above
> + let phy_id = dev.c45_read(MDIO_MMD_PMAPMD, 0xd001)?;
> + if (phy_id >> 8) & 0xff != 0xb3 {
> + return Ok(());
> + }
Could you add a note about why you are returning early? Also some magic numbers
> +
> + dev.c45_write(MDIO_MMD_PMAPMD, 0xC300, 0x0000)?;
> + dev.c45_write(MDIO_MMD_PMAPMD, 0xC302, 0x4)?;
> + dev.c45_write(MDIO_MMD_PMAPMD, 0xC319, 0x0038)?;
> +
> + dev.c45_write(MDIO_MMD_PMAPMD, 0xC31A, 0x0098)?;
> + dev.c45_write(MDIO_MMD_PCS, 0x0026, 0x0E00)?;
> +
> + dev.c45_write(MDIO_MMD_PCS, 0x0027, 0x0893)?;
> +
> + dev.c45_write(MDIO_MMD_PCS, 0x0028, 0xA528)?;
> + dev.c45_write(MDIO_MMD_PCS, 0x0029, 0x03)?;
> + dev.c45_write(MDIO_MMD_PMAPMD, 0xC30A, 0x06E1)?;
> + dev.c45_write(MDIO_MMD_PMAPMD, 0xC300, 0x0002)?;
> + dev.c45_write(MDIO_MMD_PCS, 0xE854, 0x00C0)?;
It might be nicer to put this in a table, like
const QT2025_INIT_ROUTINE: &[(u8, u16, u16)] = &[
// Add some notes about what the registers do, or put them in
separate consts
(MDIO_MMD_PMAPMD, 0xC300, 0x0000),
(MDIO_MMD_PMAPMD, 0xC302, 0x4),
// ...
];
for (add reg, val) in QT2025_INIT_ROUTINE {
dev.c45_write(add, reg, val)?;
}
> + let mut j = 0x8000;
Could you give this one a name?
> + let mut a = MDIO_MMD_PCS;
> + for (i, val) in fw.data().iter().enumerate() {
> + if i == 0x4000 {
> + a = MDIO_MMD_PHYXS;
> + j = 0x8000;
> + }
Looks like firmware is split between PCS and PHYXS at 0x4000, but like
Greg said you should probably explain where this comes from.
> + dev.c45_write(a, j, (*val).into())?;
I think this is writing one byte at a time, to answer Andrew's
question. Can you write a `u16::from_le_bytes(...)` to alternating
addresses instead? This would be pretty easy by doing
`fw.data().chunks(2)`.
> +
> + j += 1;
> + }
> + dev.c45_write(MDIO_MMD_PCS, 0xe854, 0x0040)?;
> +
> + Ok(())
> + }
> +
> + fn read_status(dev: &mut phy::Device) -> Result<u16> {
> + dev.genphy_c45_read_status()
> + }
> +}
Powered by blists - more mailing lists