diff mbox series

[net-next,3/5] net: phy: aquantia: search for firmware-name in fwnode

Message ID trinity-da86cb70-f227-403a-be94-6e6a3fd0a0ca-1726082854312@3c-app-gmx-bs04 (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: tn40xx: add support for AQR105 based cards (was: net: phy: aquantia: emable firmware loading for aqr105) | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: robimarko@gmail.com ansuelsmth@gmail.com
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 38 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-12--00-00 (tests: 764)

Commit Message

Hans-Frieder Vogt Sept. 11, 2024, 7:27 p.m. UTC
For loading of a firmware file over the filesystem, and
if the system is non-device-tree, try finding firmware-name from the software
node (or: fwnode) of the mdio device. This software node may have been
provided by the MAC or MDIO driver.

Signed-off-by: Hans-Frieder Vogt <hfdevel@gmx.net>
---
 drivers/net/phy/aquantia/aquantia_firmware.c | 25 +++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

--
2.45.2

Comments

Andrew Lunn Sept. 11, 2024, 8:58 p.m. UTC | #1
On Wed, Sep 11, 2024 at 09:27:34PM +0200, Hans-Frieder Vogt wrote:
> For loading of a firmware file over the filesystem, and
> if the system is non-device-tree, try finding firmware-name from the software
> node (or: fwnode) of the mdio device. This software node may have been
> provided by the MAC or MDIO driver.
> 
> Signed-off-by: Hans-Frieder Vogt <hfdevel@gmx.net>
> ---
>  drivers/net/phy/aquantia/aquantia_firmware.c | 25 +++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/phy/aquantia/aquantia_firmware.c b/drivers/net/phy/aquantia/aquantia_firmware.c
> index 090fcc9a3413..f6154f815d72 100644
> --- a/drivers/net/phy/aquantia/aquantia_firmware.c
> +++ b/drivers/net/phy/aquantia/aquantia_firmware.c
> @@ -324,14 +324,37 @@ static int aqr_firmware_load_nvmem(struct phy_device *phydev)
>  static int aqr_firmware_load_fs(struct phy_device *phydev)
>  {
>  	struct device *dev = &phydev->mdio.dev;
> +	struct fwnode_handle *fw_node;
>  	const struct firmware *fw;
>  	const char *fw_name;
> +	u32 phy_id;
>  	int ret;
> 
>  	ret = of_property_read_string(dev->of_node, "firmware-name",
>  				      &fw_name);

Did you try just replacing this with:

    	ret = device_property_read_string(dev, "firmware-name", &fw_name);

As far as i understand, the device_property_ functions will look
around in OF, ACPI and swnode to find the given property. As long as
the MAC driver puts the property in the right place, i _think_ this
will just work.

	Andrew
Hans-Frieder Vogt Sept. 12, 2024, 6:48 p.m. UTC | #2
On 11.09.2024 22.58, Andrew Lunn wrote:
> On Wed, Sep 11, 2024 at 09:27:34PM +0200, Hans-Frieder Vogt wrote:
>> For loading of a firmware file over the filesystem, and
>> if the system is non-device-tree, try finding firmware-name from the software
>> node (or: fwnode) of the mdio device. This software node may have been
>> provided by the MAC or MDIO driver.
>>
>> Signed-off-by: Hans-Frieder Vogt <hfdevel@gmx.net>
>> ---
>>   drivers/net/phy/aquantia/aquantia_firmware.c | 25 +++++++++++++++++++-
>>   1 file changed, 24 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/phy/aquantia/aquantia_firmware.c b/drivers/net/phy/aquantia/aquantia_firmware.c
>> index 090fcc9a3413..f6154f815d72 100644
>> --- a/drivers/net/phy/aquantia/aquantia_firmware.c
>> +++ b/drivers/net/phy/aquantia/aquantia_firmware.c
>> @@ -324,14 +324,37 @@ static int aqr_firmware_load_nvmem(struct phy_device *phydev)
>>   static int aqr_firmware_load_fs(struct phy_device *phydev)
>>   {
>>   	struct device *dev = &phydev->mdio.dev;
>> +	struct fwnode_handle *fw_node;
>>   	const struct firmware *fw;
>>   	const char *fw_name;
>> +	u32 phy_id;
>>   	int ret;
>>
>>   	ret = of_property_read_string(dev->of_node, "firmware-name",
>>   				      &fw_name);
> Did you try just replacing this with:
>
>      	ret = device_property_read_string(dev, "firmware-name", &fw_name);
>
> As far as i understand, the device_property_ functions will look
> around in OF, ACPI and swnode to find the given property. As long as
> the MAC driver puts the property in the right place, i _think_ this
> will just work.
>
> 	Andrew
device_property_read_string() would would be very elegant, but it only
looks for properties in the swnode of this device.
However, I did not find a way to add a swnode directly to the phy, but
only to the mdiobus.
I could have added the firmware-name directly to the swnode of the
mdiobus of course, then
         ret = device_property_read_string(dev->parent, "firmware-name",
&fw_name);
would have succeeded.
But adding a "firmware-name" property to an mdiobus seemed not sensible
to me.

Did I maybe overlook a clever way to directly add a swnode to the
phy_device?
I'll certainly investigate this another time.
Thanks!

         Hans
Andrew Lunn Sept. 12, 2024, 7:15 p.m. UTC | #3
> device_property_read_string() would would be very elegant, but it only
> looks for properties in the swnode of this device.
> However, I did not find a way to add a swnode directly to the phy, but
> only to the mdiobus.

Think about the DT representation, taken from marvell,aquantia.yaml.

    mdio {
        #address-cells = <1>;
        #size-cells = <0>;

        ethernet-phy@0 {
            compatible = "ethernet-phy-id31c3.1c12",
                         "ethernet-phy-ieee802.3-c45";

            reg = <0>;
            firmware-name = "AQR-G4_v5.4.C-AQR_CIG_WF-1945_0x8_ID44776_VER1630.cld";
        };

        ethernet-phy@1 {
            compatible = "ethernet-phy-id31c3.1c12",
                         "ethernet-phy-ieee802.3-c45";

            reg = <1>;
            nvmem-cells = <&aqr_fw>;
            nvmem-cell-names = "firmware";
        };
    };

You want to construct the same. Do you know the address on the bus the
PHY uses? Can you create a ethernet-phy@X node? And then put the
property there?

Then there is the question of if the current code associates the
swnode to the PHY device. I've no idea if it does! If not, it might
mean we need to add a device_set_node(&mdiodev->dev, fwnode) somewhere
in the core code.

       Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/aquantia/aquantia_firmware.c b/drivers/net/phy/aquantia/aquantia_firmware.c
index 090fcc9a3413..f6154f815d72 100644
--- a/drivers/net/phy/aquantia/aquantia_firmware.c
+++ b/drivers/net/phy/aquantia/aquantia_firmware.c
@@ -324,14 +324,37 @@  static int aqr_firmware_load_nvmem(struct phy_device *phydev)
 static int aqr_firmware_load_fs(struct phy_device *phydev)
 {
 	struct device *dev = &phydev->mdio.dev;
+	struct fwnode_handle *fw_node;
 	const struct firmware *fw;
 	const char *fw_name;
+	u32 phy_id;
 	int ret;

 	ret = of_property_read_string(dev->of_node, "firmware-name",
 				      &fw_name);
-	if (ret)
+	/* check if there is an fwnode connected to mdio */
+	if (ret && dev->parent->fwnode) {
+		fw_node = fwnode_get_phy_node(dev->parent->fwnode);
+		if (fw_node) {
+			ret = fwnode_get_phy_id(fw_node, &phy_id);
+			if (ret)
+				goto cleanup_fwnode;
+			phy_id &= phydev->drv->phy_id_mask;
+			if (phy_id != (phydev->drv->phy_id &
+				       phydev->drv->phy_id_mask))
+				goto cleanup_fwnode;
+
+			ret = fwnode_property_read_string(fw_node,
+							  "firmware-name",
+							  &fw_name);
+		}
+cleanup_fwnode:
+		fwnode_handle_put(fw_node);
+	}
+	if (ret) {
+		phydev_err(phydev, "failed to read firmware name: %d\n", ret);
 		return ret;
+	}

 	ret = request_firmware(&fw, fw_name, dev);
 	if (ret) {