phy dp83867: Fix compilation with CONFIG_OF_MDIO=m
Subsystems (3)
PATCH v2 1/2 phy dp83867: Fix compilation with CONFIG_OF_MDIO=m
When CONFIG_OF_MDIO is configured as module, the #define for it really is CONFIG_OF_MDIO_MODULE, not CONFIG_OF_MDIO. So if we are compiling it as module, the dp83867 doesn't see that OF_MDIO was selected and doesn't read the dt rgmii parameters.
The fix is simple: Use IS_ENABLED(). It checks for both - module as well as compiled in code.
--- drivers/net/phy/dp83867.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/dp83867.c +1 -1
@@ -99,7 +99,7 @@ static int dp83867_config_intr(struct phy_device *phydev)return phy_write (phydev,MII_DP83867_MICR , micr_status); } -#ifdef CONFIG_OF_MDIO +#if IS_ENABLED (CONFIG_OF_MDIO )static int dp83867_of_init (struct phy_device *phydev) {struct dp83867_private *dp83867 = phydev->priv;
Signature · 1 line
1.8.5.6
PATCH v2 2/2 phy dp83867: Make rgmii parameters optional
If you compile without OF_MDIO support in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.
On the other hand if you do compile with OF_MDIO and the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.
To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
--- drivers/net/phy/dp83867.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
drivers/net/phy/dp83867.c +28 -3
@@ -65,6 +65,7 @@ struct dp83867_private {int rx_id_delay;int tx_id_delay;int fifo_depth; +int values_are_sane; };static int dp83867_ack_interrupt (struct phy_device *phydev)
@@ -113,15 +114,30 @@ static int dp83867_of_init(struct phy_device *phydev) ret =of_property_read_u32 (of_node,"ti,rx-internal-delay" , &dp83867->rx_id_delay);if (ret) -return ret; + goto invalid_dt; ret =of_property_read_u32 (of_node,"ti,tx-internal-delay" , &dp83867->tx_id_delay);if (ret) -return ret; + goto invalid_dt; -return of_property_read_u32 (of_node,"ti,fifo-depth" , + ret =of_property_read_u32 (of_node,"ti,fifo-depth" , &dp83867->fifo_depth); +if (ret) + goto invalid_dt; + + dp83867->values_are_sane =1 ; + +return 0 ; + +invalid_dt: +phydev_err (phydev,"missing properties in device tree" ); + +/* +* We can still run with a broken dt by not using any of the optional +* parameters, so just don't set dp83867->values_are_sane. +*/ + return 0; }#else static int dp83867_of_init (struct phy_device *phydev)
@@ -150,6 +166,15 @@ static int dp83867_config_init(struct phy_device *phydev) dp83867 = (struct dp83867_private *)phydev->priv; } +/* +* With no or broken device tree, we don't have the values that we would +* want to configure the phy with. In that case, cross our fingers and +* assume that firmware did everything correctly for us or that we don't +* need them. +*/ +if (!dp83867->values_are_sane) +return 0 ; +if (phy_interface_is_rgmii (phydev)) { ret =phy_write (phydev,MII_DP83867_PHYCTRL , (dp83867->fifo_depth <<DP83867_PHYCR_FIFO_DEPTH_SHIFT ));
Signature · 1 line
1.8.5.6
Re: [PATCH v2 2/2] phy dp83867: Make rgmii parameters optional
Quoted 22 lines · Alexander Graf
If you compile without
OF_MDIOsupport in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.On the other hand if you do compile with
OF_MDIOand the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
Signed-off-by Alexander Graf <[email protected]>--- drivers/net/phy/dp83867.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)drivers/net/phy/dp83867.c +0
-0
drivers/net/phy/dp83867.c struct dp83867_private { · line 68
Quoted 4 lines
drivers/net/phy/dp83867.c +1
-0@@ -65,6 +65,7 @@ struct dp83867_private {int rx_id_delay;int tx_id_delay;int fifo_depth; +int values_are_sane;
This could be a boolean type.
Quoted 18 lines
drivers/net/phy/dp83867.c +3
-3};static int dp83867_ack_interrupt (struct phy_device *phydev)@@ -113,15 +114,30 @@ static int dp83867_of_init(struct phy_device *phydev) ret =of_property_read_u32 (of_node,"ti,rx-internal-delay" , &dp83867->rx_id_delay);if (ret) -return ret; + goto invalid_dt; ret =of_property_read_u32 (of_node,"ti,tx-internal-delay" , &dp83867->tx_id_delay);if (ret) -return ret; + goto invalid_dt; - return of_property_read_u32(of_node, "ti,fifo-depth", + ret = of_property_read_u32(of_node, "ti,fifo-depth",
drivers/net/phy/dp83867.c static int dp83867_of_init(struct phy_device *phydev) · line 134
Quoted 10 lines
drivers/net/phy/dp83867.c +9
-0&dp83867->fifo_depth); +if (ret) + goto invalid_dt; + + dp83867->values_are_sane =1 ; + +return 0 ; + +invalid_dt: +phydev_err (phydev,"missing properties in device tree" );
phydev_warn() maybe?
Other than that, this looks okay to me.
Signature · 1 line
Florian
Andrew Lunn
maintainerRe: [PATCH v2 2/2] phy dp83867: Make rgmii parameters optional
In reply to Alexander GrafQuoted 11 lines · Alexander Graf
If you compile without
OF_MDIOsupport in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.On the other hand if you do compile with
OF_MDIOand the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
The binding document actually says they are required. It would be good to make the binding documentation and the code consistent.
Andrew
Re: [PATCH v2 2/2] phy dp83867: Make rgmii parameters optional
In reply to Alexander GrafQuoted 31 lines · Alexander Graf
If you compile without
OF_MDIOsupport in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.On the other hand if you do compile with
OF_MDIOand the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
Signed-off-by Alexander Graf <[email protected]>--- drivers/net/phy/dp83867.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)drivers/net/phy/dp83867.c +1
-0@@ -65,6 +65,7 @@ struct dp83867_private {int rx_id_delay;int tx_id_delay;int fifo_depth; +int values_are_sane; };static int dp83867_ack_interrupt (struct phy_device *phydev)@@ -113,15 +114,30 @@ static int dp83867_of_init(struct phy_device *phydev) ret = of_property_read_u32(of_node, "ti,rx-internal-delay",
drivers/net/phy/dp83867.c static int dp83867_of_init(struct phy_device *phydev) · line 122
Quoted 10 lines
drivers/net/phy/dp83867.c +2
-2&dp83867->rx_id_delay);if (ret) -return ret; + goto invalid_dt; ret =of_property_read_u32 (of_node,"ti,tx-internal-delay" , &dp83867->tx_id_delay);if (ret) -return ret; + goto invalid_dt;
Optional means you may or may not have the entries
I would prefer to wrap the DT reading with the interface type check.
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID || phydev->interface == PHY_INTERFACE_MODE_RGMII_ID )
ret = of_property_read_u32(of_node, "ti,tx-internal-delay",
&dp83867->tx_id_delay);
if (ret)
goto invalid_dt;
Otherwise this continues to mandate that you need to declare all the DT entries when in fact you may only have to declare 1.
And if the other interfaces are declared then DT entries are ignored. And configuring internal delay is not required per section 8.9 footnote 3 of the data sheet.
Dan
Quoted 38 lines
drivers/net/phy/dp83867.c +25
-1-return of_property_read_u32 (of_node,"ti,fifo-depth" , + ret =of_property_read_u32 (of_node,"ti,fifo-depth" , &dp83867->fifo_depth); +if (ret) + goto invalid_dt; + + dp83867->values_are_sane =1 ; + +return 0 ; + +invalid_dt: +phydev_err (phydev,"missing properties in device tree" ); + +/* +* We can still run with a broken dt by not using any of the optional +* parameters, so just don't set dp83867->values_are_sane. +*/ + return 0; }#else static int dp83867_of_init (struct phy_device *phydev)@@ -150,6 +166,15 @@ static int dp83867_config_init(struct phy_device *phydev) dp83867 = (struct dp83867_private *)phydev->priv; } +/* +* With no or broken device tree, we don't have the values that we would +* want to configure the phy with. In that case, cross our fingers and +* assume that firmware did everything correctly for us or that we don't +* need them. +*/ +if (!dp83867->values_are_sane) +return 0 ; +if (phy_interface_is_rgmii (phydev)) { ret =phy_write (phydev,MII_DP83867_PHYCTRL , (dp83867->fifo_depth <<DP83867_PHYCR_FIFO_DEPTH_SHIFT ));
Signature · 2 lines
------------------ Dan Murphy
From: Alexander Graf <[email protected]>
Date: Mon, 16 May 2016 20:52:42 +0200
Quoted 9 lines
When
CONFIG_OF_MDIOis configured as module, the #define for it really isCONFIG_OF_MDIO_MODULE, notCONFIG_OF_MDIO. So if we are compiling it as module, the dp83867 doesn't see thatOF_MDIOwas selected and doesn't read the dt rgmii parameters.The fix is simple: Use
IS_ENABLED(). It checks for both - module as well as compiled in code.Signed-off-by Alexander Graf <[email protected]>
Applied.
Re: [PATCH v2 2/2] phy dp83867: Make rgmii parameters optional
In reply to Alexander GrafFrom: Alexander Graf <[email protected]>
Date: Mon, 16 May 2016 20:52:43 +0200
Quoted 9 lines
If you compile without
OF_MDIOsupport in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.On the other hand if you do compile with
OF_MDIOand the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.
Quoted 4 lines
To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
Signed-off-by Alexander Graf <[email protected]>
Applied.
Re: [PATCH v2 2/2] phy dp83867: Make rgmii parameters optional
David
Quoted 12 lines · David Miller
From: Alexander Graf <[email protected]>
Date: Mon, 16 May 2016 20:52:43 +0200Quoted 9 lines
If you compile without
OF_MDIOsupport in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.On the other hand if you do compile with
OF_MDIOand the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.
Quoted 5 lines
Quoted 4 lines
To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
Signed-off-by Alexander Graf <[email protected]>Applied.
This patch should not have been applied.
I did not believe the implementation was proper for that driver.
It seems my objection to the code was not seen. Nor was Andrew's point about the DT bindings document
https://patchwork.kernel.org/patch/9105371/
Dan
Signature · 2 lines
------------------ Dan Murphy
David Miller
maintainerRe: [PATCH v2 2/2] phy dp83867: Make rgmii parameters optional
From: Dan Murphy <[email protected]>
Date: Tue, 17 May 2016 13:34:34 -0500
Quoted 21 lines
David
Quoted 12 lines · David Miller
From: Alexander Graf <[email protected]>
Date: Mon, 16 May 2016 20:52:43 +0200Quoted 9 lines
If you compile without
OF_MDIOsupport in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.On the other hand if you do compile with
OF_MDIOand the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.Quoted 5 lines
Quoted 4 lines
To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
Signed-off-by Alexander Graf <[email protected]>Applied.
Quoted 7 lines
This patch should not have been applied.
I did not believe the implementation was proper for that driver.
It seems my objection to the code was not seen. Nor was Andrew's point about the DT bindings document
The discussions around the recent phy patches have been a labrynth that I've found hard to follow, sorry.
I'll revert these two, sigh....
Re: [PATCH v2 2/2] phy dp83867: Make rgmii parameters optional
Hi David,
Quoted 30 lines
Am 17.05.2016 um 20:48 schrieb David Miller <[email protected]>:
From: Dan Murphy <[email protected]>
Date: Tue, 17 May 2016 13:34:34 -0500Quoted 25 lines
David
Quoted 13 lines · David Miller
From: Alexander Graf <[email protected]>
Date: Mon, 16 May 2016 20:52:43 +0200Quoted 9 lines
If you compile without
OF_MDIOsupport in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.On the other hand if you do compile with
OF_MDIOand the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.Quoted 5 lines
Quoted 4 lines
To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
Signed-off-by Alexander Graf <[email protected]>Applied.
This patch should not have been applied.
I did not believe the implementation was proper for that driver.
Quoted 8 lines
Quoted 3 lines
It seems my objection to the code was not seen. Nor was Andrew's point about the DT bindings document
The discussions around the recent phy patches have been a labrynth that I've found hard to follow, sorry.
I'll revert these two, sigh....
The first patch is an obvious and correct fix. Discussions were only about the second one (which I'm happy to drop given the rat hole this turned out to be).
Alex
Re: [PATCH v2 2/2] phy dp83867: Make rgmii parameters optional
Quoted 31 lines · Alexander Graf
Hi David,
Quoted 29 lines
Am 17.05.2016 um 20:48 schrieb David Miller <[email protected]>:
From: Dan Murphy <[email protected]>
Date: Tue, 17 May 2016 13:34:34 -0500Quoted 24 lines
David
Quoted 13 lines · David Miller
From: Alexander Graf <[email protected]>
Date: Mon, 16 May 2016 20:52:43 +0200Quoted 9 lines
If you compile without
OF_MDIOsupport in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.On the other hand if you do compile with
OF_MDIOand the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.Quoted 5 lines
Quoted 4 lines
To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
Signed-off-by Alexander Graf <[email protected]>Applied.
This patch should not have been applied.
I did not believe the implementation was proper for that driver.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
It seems my objection to the code was not seen. Nor was Andrew's point about the DT bindings document
The discussions around the recent phy patches have been a labrynth that I've found hard to follow, sorry.
I'll revert these two, sigh....
The first patch is an obvious and correct fix. Discussions were only about the second one (which I'm happy to drop given the rat hole this turned out to be).
So are you going to abandon the second patch all together? If you do, let me know I can submit a patch.
Dan
Quoted 4 lines
Alex
Signature · 2 lines
------------------ Dan Murphy
Re: [PATCH v2 2/2] phy dp83867: Make rgmii parameters optional
Quoted 39 lines
Am 17.05.2016 um 22:40 schrieb Dan Murphy <[email protected]>:
Quoted 35 lines · Alexander Graf
Hi David,
Quoted 32 lines
Am 17.05.2016 um 20:48 schrieb David Miller <[email protected]>:
From: Dan Murphy <[email protected]>
Date: Tue, 17 May 2016 13:34:34 -0500Quoted 27 lines
David
Quoted 13 lines · David Miller
From: Alexander Graf <[email protected]>
Date: Mon, 16 May 2016 20:52:43 +0200Quoted 9 lines
If you compile without
OF_MDIOsupport in an RGMII configuration, we fail to configure the dp83867 phy today by writing garbage into its configuration registers.On the other hand if you do compile with
OF_MDIOand the phy gets loaded via device tree, you have to have the properties set in the device tree, otherwise we fail to load the driver and don't even attach the generic phy driver to the interface anymore.Quoted 5 lines
Quoted 4 lines
To make things slightly more consistent, make the rgmii configuration properties optional and allow a user to omit them in their device tree.
Signed-off-by Alexander Graf <[email protected]>Applied.
This patch should not have been applied.
I did not believe the implementation was proper for that driver.
It seems my objection to the code was not seen. Nor was Andrew's point about the DT bindings document
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
The discussions around the recent phy patches have been a labrynth that I've found hard to follow, sorry.
I'll revert these two, sigh....
The first patch is an obvious and correct fix. Discussions were only about the second one (which I'm happy to drop given the rat hole this turned out to be).
So are you going to abandon the second patch all together? If you do, let me know I can submit a patch.
I'm fairly sure you'll be done with it much quicker than me and the real bug I wanted to fix is that the driver broke with OF_MDIO=m ;)
So yes, please take over from here.
Alex