From: Michael Walle <hidden> Date: 2021-02-09 16:42:04
Cleanup the PHY drivers for IPplus devices and add PHY counters and MDIX
support for the IP101A/G.
Patch 5 adds a model detection based on the behavior of the PHY.
Unfortunately, the IP101A shares the PHY ID with the IP101G. But the latter
provides more features. Try to detect the newer model by accessing the page
selection register. If it is writeable, it is assumed, that it is a IP101G.
With this detection in place, we can now access registers >= 16 in a
correct way on the IP101G; that is by first selecting the correct page.
This might previouly worked, because no one ever set another active page
before booting linux.
The last two patches add the new features.
Michael Walle (9):
net: phy: icplus: use PHY_ID_MATCH_MODEL() macro
net: phy: icplus: use PHY_ID_MATCH_EXACT() for IP101A/G
net: phy: icplus: drop address operator for functions
net: phy: icplus: use the .soft_reset() of the phy-core
net: phy: icplus: add IP101A/IP101G model detection
net: phy: icplus: don't set APS_EN bit on IP101G
net: phy: icplus: select page before writing control register
net: phy: icplus: add PHY counter for IP101G
net: phy: icplus: add MDI/MDIX support for IP101A/G
drivers/net/phy/icplus.c | 328 ++++++++++++++++++++++++++++++++-------
1 file changed, 272 insertions(+), 56 deletions(-)
--
2.20.1
From: Michael Walle <hidden> Date: 2021-02-09 16:42:36
Simpify the initializations of the structures. There is no functional
change.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
From: Michael Walle <hidden> Date: 2021-02-09 16:42:36
According to the datasheet of the IP101A/G there is no revision field
and MII_PHYSID2 always reads as 0x0c54. Use PHY_ID_MATCH_EXACT() then.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Michael Walle <hidden> Date: 2021-02-09 16:43:21
The PHY core already resets the PHY before .config_init() if a
.soft_reset() op is registered. Drop the open-coded ip1xx_reset().
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 32 ++------------------------------
1 file changed, 2 insertions(+), 30 deletions(-)
@@ -120,36 +120,10 @@ static int ip175c_config_init(struct phy_device *phydev)return0;}-staticintip1xx_reset(structphy_device*phydev)-{-intbmcr;--/* Software Reset PHY */-bmcr=phy_read(phydev,MII_BMCR);-if(bmcr<0)-returnbmcr;-bmcr|=BMCR_RESET;-bmcr=phy_write(phydev,MII_BMCR,bmcr);-if(bmcr<0)-returnbmcr;--do{-bmcr=phy_read(phydev,MII_BMCR);-if(bmcr<0)-returnbmcr;-}while(bmcr&BMCR_RESET);--return0;-}-staticintip1001_config_init(structphy_device*phydev){intc;-c=ip1xx_reset(phydev);-if(c<0)-returnc;-/* Enable Auto Power Saving mode */c=phy_read(phydev,IP1001_SPEC_CTRL_STATUS_2);if(c<0)
@@ -237,10 +211,6 @@ static int ip101a_g_config_init(struct phy_device *phydev)structip101a_g_phy_priv*priv=phydev->priv;interr,c;-c=ip1xx_reset(phydev);-if(c<0)-returnc;-/* configure the RXER/INTR_32 pin of the 32-pin IP101GR if needed: */switch(priv->sel_intr32){caseIP101GR_SEL_INTR32_RXER:
From: Michael Walle <hidden> Date: 2021-02-09 16:43:27
Don't sometimes use the address operator and sometimes not. Drop it and
make the code look uniform.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
From: Michael Walle <hidden> Date: 2021-02-09 16:44:12
Unfortunately, the IP101A and IP101G share the same PHY identifier.
While most of the functions are somewhat backwards compatible, there is
for example the APS_EN bit on the IP101A but on the IP101G this bit
reserved. Also, the IP101G has many more functionalities.
Deduce the model by accessing the page select register which - according
to the datasheet - is not available on the IP101A. If this register is
writable, assume we have an IP101G.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 43 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
@@ -175,6 +183,39 @@ static int ip175c_config_aneg(struct phy_device *phydev)return0;}+/* The IP101A and the IP101G share the same PHY identifier.The IP101G seems to+*beasuccessoroftheIP101Aandimplementsmorefunctions.Amongstother+*thingsapageselectregister,whichisnotavailableontheIP101.Usethis+*todistinguishthesetwo.+*/+staticintip101a_g_detect_model(structphy_device*phydev)+{+structip101a_g_phy_priv*priv=phydev->priv;+intoldval,ret;++oldval=phy_read(phydev,IP101G_PAGE_CONTROL);+if(oldval<0)+returnoldval;++ret=phy_write(phydev,IP101G_PAGE_CONTROL,0xffff);+if(ret)+returnret;++ret=phy_read(phydev,IP101G_PAGE_CONTROL);+if(ret<0)+returnret;++if(ret==IP101G_PAGE_CONTROL_MASK)+priv->model=IP101G;+else+priv->model=IP101A;++phydev_dbg(phydev,"Detected %s\n",+priv->model==IP101G?"IP101G":"IP101A");++returnphy_write(phydev,IP101G_PAGE_CONTROL,oldval);+}+staticintip101a_g_probe(structphy_device*phydev){structdevice*dev=&phydev->mdio.dev;
@@ -203,7 +244,7 @@ static int ip101a_g_probe(struct phy_device *phydev)phydev->priv=priv;-return0;+returnip101a_g_detect_model(phydev);}staticintip101a_g_config_init(structphy_device*phydev)
From: Michael Walle <hidden> Date: 2021-02-09 16:44:43
This bit is reserved as 'always-write-1'. While this is not a particular
error, because we are only setting it, guard it by checking the model to
prevent errors in the future.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
@@ -250,7 +250,7 @@ static int ip101a_g_probe(struct phy_device *phydev)staticintip101a_g_config_init(structphy_device*phydev){structip101a_g_phy_priv*priv=phydev->priv;-interr,c;+interr;/* configure the RXER/INTR_32 pin of the 32-pin IP101GR if needed: */switch(priv->sel_intr32){
@@ -280,11 +280,16 @@ static int ip101a_g_config_init(struct phy_device *phydev)break;}-/* Enable Auto Power Saving mode */-c=phy_read(phydev,IP10XX_SPEC_CTRL_STATUS);-c|=IP101A_G_APS_ON;+/* Enable Auto Power Saving mode on IP101A, on IP101G this bit is+*reservedas'write-one'.+*/+if(priv->model==IP101A){+err=phy_set_bits(phydev,IP10XX_SPEC_CTRL_STATUS,IP101A_G_APS_ON);+if(err)+returnerr;+}-returnphy_write(phydev,IP10XX_SPEC_CTRL_STATUS,c);+return0;}staticintip101a_g_ack_interrupt(structphy_device*phydev)
From: Michael Walle <hidden> Date: 2021-02-09 16:45:04
The IP101G provides three counters: RX packets, CRC errors and symbol
errors. The error counters can be configured to clear automatically on
read. Unfortunately, this isn't true for the RX packet counter. Because
of this and because the RX packet counter is more likely to overflow,
than the error counters implement only support for the error counters.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 78 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
@@ -254,6 +271,18 @@ static int ip101a_g_config_init(struct phy_device *phydev)structip101a_g_phy_priv*priv=phydev->priv;intoldpage,err;+/* Enable the PHY counters */+err=phy_modify_paged(phydev,1,IP101G_P1_CNT_CTRL,+CNT_CTRL_RX_EN,CNT_CTRL_RX_EN);+if(err)+returnerr;++/* Clear error counters on read */+err=phy_modify_paged(phydev,8,IP101G_P8_CNT_CTRL,+CNT_CTRL_RDCLR_EN,CNT_CTRL_RDCLR_EN);+if(err)+returnerr;+oldpage=phy_select_page(phydev,IP101G_DEFAULT_PAGE);/* configure the RXER/INTR_32 pin of the 32-pin IP101GR if needed: */
@@ -373,6 +402,52 @@ static int ip101a_g_write_page(struct phy_device *phydev, int page)return__phy_write(phydev,IP101G_PAGE_CONTROL,page);}+staticintip101a_g_get_sset_count(structphy_device*phydev)+{+structip101a_g_phy_priv*priv=phydev->priv;++if(priv->model==IP101A)+return-EOPNOTSUPP;++returnARRAY_SIZE(ip101g_hw_stats);+}++staticvoidip101a_g_get_strings(structphy_device*phydev,u8*data)+{+inti;++for(i=0;i<ARRAY_SIZE(ip101g_hw_stats);i++)+strscpy(data+i*ETH_GSTRING_LEN,+ip101g_hw_stats[i].name,ETH_GSTRING_LEN);+}++staticu64ip101a_g_get_stat(structphy_device*phydev,inti)+{+structip101g_hw_statstat=ip101g_hw_stats[i];+structip101a_g_phy_priv*priv=phydev->priv;+intval;+u64ret;++val=phy_read_paged(phydev,stat.page,IP101G_CNT_REG);+if(val<0){+ret=U64_MAX;+}else{+priv->stats[i]+=val;+ret=priv->stats[i];+}++returnret;+}++staticvoidip101a_g_get_stats(structphy_device*phydev,+structethtool_stats*stats,u64*data)+{+inti;++for(i=0;i<ARRAY_SIZE(ip101g_hw_stats);i++)+data[i]=ip101a_g_get_stat(phydev,i);+}+staticstructphy_drivericplus_driver[]={{PHY_ID_MATCH_MODEL(IP175C_PHY_ID),
From: Michael Walle <hidden> Date: 2021-02-09 16:45:37
Registers >= 16 are paged. Be sure to set the page. It seems this was
working for now, because the default is correct for the registers used
in the driver at the moment. But this will also assume, nobody will
change the page select register before linux is started. The page select
register is _not_ reset with a soft reset of the PHY.
Add read_page()/write_page() support for the IP101G and use it
accordingly.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 50 +++++++++++++++++++++++++++++++---------
1 file changed, 39 insertions(+), 11 deletions(-)
@@ -250,23 +252,25 @@ static int ip101a_g_probe(struct phy_device *phydev)staticintip101a_g_config_init(structphy_device*phydev){structip101a_g_phy_priv*priv=phydev->priv;-interr;+intoldpage,err;++oldpage=phy_select_page(phydev,IP101G_DEFAULT_PAGE);/* configure the RXER/INTR_32 pin of the 32-pin IP101GR if needed: */switch(priv->sel_intr32){caseIP101GR_SEL_INTR32_RXER:-err=phy_modify(phydev,IP101G_DIGITAL_IO_SPEC_CTRL,-IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32,0);+err=__phy_modify(phydev,IP101G_DIGITAL_IO_SPEC_CTRL,+IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32,0);if(err<0)-returnerr;+gotoout;break;caseIP101GR_SEL_INTR32_INTR:-err=phy_modify(phydev,IP101G_DIGITAL_IO_SPEC_CTRL,-IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32,-IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32);+err=__phy_modify(phydev,IP101G_DIGITAL_IO_SPEC_CTRL,+IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32,+IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32);if(err<0)-returnerr;+gotoout;break;default:
@@ -284,12 +288,14 @@ static int ip101a_g_config_init(struct phy_device *phydev)*reservedas'write-one'.*/if(priv->model==IP101A){-err=phy_set_bits(phydev,IP10XX_SPEC_CTRL_STATUS,IP101A_G_APS_ON);+err=__phy_set_bits(phydev,IP10XX_SPEC_CTRL_STATUS,+IP101A_G_APS_ON);if(err)-returnerr;+gotoout;}-return0;+out:+returnphy_restore_page(phydev,oldpage,err);}staticintip101a_g_ack_interrupt(structphy_device*phydev)
From: Michael Walle <hidden> Date: 2021-02-09 16:45:47
Implement the operations to set desired mode and retrieve the current
mode.
This feature was tested with an IP101G.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 91 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
Unfortunately, the IP101A and IP101G share the same PHY identifier.
While most of the functions are somewhat backwards compatible, there is
for example the APS_EN bit on the IP101A but on the IP101G this bit
reserved. Also, the IP101G has many more functionalities.
Deduce the model by accessing the page select register which - according
to the datasheet - is not available on the IP101A. If this register is
writable, assume we have an IP101G.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 43 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
@@ -175,6 +183,39 @@ static int ip175c_config_aneg(struct phy_device *phydev)return0;}+/* The IP101A and the IP101G share the same PHY identifier.The IP101G seems to+*beasuccessoroftheIP101Aandimplementsmorefunctions.Amongstother+*thingsapageselectregister,whichisnotavailableontheIP101.Usethis+*todistinguishthesetwo.+*/+staticintip101a_g_detect_model(structphy_device*phydev)+{+structip101a_g_phy_priv*priv=phydev->priv;+intoldval,ret;++oldval=phy_read(phydev,IP101G_PAGE_CONTROL);+if(oldval<0)+returnoldval;++ret=phy_write(phydev,IP101G_PAGE_CONTROL,0xffff);+if(ret)+returnret;++ret=phy_read(phydev,IP101G_PAGE_CONTROL);+if(ret<0)+returnret;++if(ret==IP101G_PAGE_CONTROL_MASK)+priv->model=IP101G;+else+priv->model=IP101A;++phydev_dbg(phydev,"Detected %s\n",+priv->model==IP101G?"IP101G":"IP101A");++returnphy_write(phydev,IP101G_PAGE_CONTROL,oldval);+}+staticintip101a_g_probe(structphy_device*phydev){structdevice*dev=&phydev->mdio.dev;
@@ -203,7 +244,7 @@ static int ip101a_g_probe(struct phy_device *phydev)phydev->priv=priv;-return0;+returnip101a_g_detect_model(phydev);}staticintip101a_g_config_init(structphy_device*phydev)
You could also implement the match_phy_device callback. Then you can
have separate PHY drivers for IP101A/IP101G. Would be cleaner I think.
See the Realtek PHY driver for an example.
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-02-10 02:27:17
On Tue, Feb 09, 2021 at 05:40:44PM +0100, Michael Walle wrote:
According to the datasheet of the IP101A/G there is no revision field
and MII_PHYSID2 always reads as 0x0c54. Use PHY_ID_MATCH_EXACT() then.
Signed-off-by: Michael Walle <redacted>
Lets hope the datasheet is correct and up to date, because this could
cause a regression if wrong.
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-02-10 02:31:14
On Tue, Feb 09, 2021 at 05:40:46PM +0100, Michael Walle wrote:
The PHY core already resets the PHY before .config_init() if a
.soft_reset() op is registered. Drop the open-coded ip1xx_reset().
Signed-off-by: Michael Walle <redacted>
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-02-10 02:31:45
On Tue, Feb 09, 2021 at 05:40:48PM +0100, Michael Walle wrote:
This bit is reserved as 'always-write-1'. While this is not a particular
error, because we are only setting it, guard it by checking the model to
prevent errors in the future.
Signed-off-by: Michael Walle <redacted>
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-02-10 02:32:33
On Tue, Feb 09, 2021 at 05:40:49PM +0100, Michael Walle wrote:
Registers >= 16 are paged. Be sure to set the page. It seems this was
working for now, because the default is correct for the registers used
in the driver at the moment. But this will also assume, nobody will
change the page select register before linux is started. The page select
register is _not_ reset with a soft reset of the PHY.
Add read_page()/write_page() support for the IP101G and use it
accordingly.
Signed-off-by: Michael Walle <redacted>
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-02-10 02:33:32
On Tue, Feb 09, 2021 at 05:40:50PM +0100, Michael Walle wrote:
The IP101G provides three counters: RX packets, CRC errors and symbol
errors. The error counters can be configured to clear automatically on
read. Unfortunately, this isn't true for the RX packet counter. Because
of this and because the RX packet counter is more likely to overflow,
than the error counters implement only support for the error counters.
Signed-off-by: Michael Walle <redacted>
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-02-10 02:33:51
On Tue, Feb 09, 2021 at 05:40:51PM +0100, Michael Walle wrote:
Implement the operations to set desired mode and retrieve the current
mode.
This feature was tested with an IP101G.
Signed-off-by: Michael Walle <redacted>
Registers >= 16 are paged. Be sure to set the page. It seems this was
working for now, because the default is correct for the registers used
in the driver at the moment. But this will also assume, nobody will
change the page select register before linux is started. The page select
register is _not_ reset with a soft reset of the PHY.
Add read_page()/write_page() support for the IP101G and use it
accordingly.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 50 +++++++++++++++++++++++++++++++---------
1 file changed, 39 insertions(+), 11 deletions(-)
@@ -250,23 +252,25 @@ static int ip101a_g_probe(struct phy_device *phydev)staticintip101a_g_config_init(structphy_device*phydev){structip101a_g_phy_priv*priv=phydev->priv;-interr;+intoldpage,err;++oldpage=phy_select_page(phydev,IP101G_DEFAULT_PAGE);/* configure the RXER/INTR_32 pin of the 32-pin IP101GR if needed: */switch(priv->sel_intr32){caseIP101GR_SEL_INTR32_RXER:-err=phy_modify(phydev,IP101G_DIGITAL_IO_SPEC_CTRL,-IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32,0);+err=__phy_modify(phydev,IP101G_DIGITAL_IO_SPEC_CTRL,+IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32,0);if(err<0)-returnerr;+gotoout;break;caseIP101GR_SEL_INTR32_INTR:-err=phy_modify(phydev,IP101G_DIGITAL_IO_SPEC_CTRL,-IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32,-IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32);+err=__phy_modify(phydev,IP101G_DIGITAL_IO_SPEC_CTRL,+IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32,+IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32);if(err<0)-returnerr;+gotoout;break;default:
@@ -284,12 +288,14 @@ static int ip101a_g_config_init(struct phy_device *phydev)*reservedas'write-one'.*/if(priv->model==IP101A){-err=phy_set_bits(phydev,IP10XX_SPEC_CTRL_STATUS,IP101A_G_APS_ON);+err=__phy_set_bits(phydev,IP10XX_SPEC_CTRL_STATUS,+IP101A_G_APS_ON);if(err)-returnerr;+gotoout;}-return0;+out:+returnphy_restore_page(phydev,oldpage,err);
If a random page was set before entering config_init, do we actually want
to restore it? Or wouldn't it be better to set the default page as part
of initialization?
quoted hunk
}
static int ip101a_g_ack_interrupt(struct phy_device *phydev)
From: Michael Walle <hidden> Date: 2021-02-10 08:26:53
Hi,
Am 2021-02-10 08:03, schrieb Heiner Kallweit:
On 09.02.2021 17:40, Michael Walle wrote:
quoted
Registers >= 16 are paged. Be sure to set the page. It seems this was
working for now, because the default is correct for the registers used
in the driver at the moment. But this will also assume, nobody will
change the page select register before linux is started. The page
select
register is _not_ reset with a soft reset of the PHY.
Add read_page()/write_page() support for the IP101G and use it
accordingly.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 50
+++++++++++++++++++++++++++++++---------
1 file changed, 39 insertions(+), 11 deletions(-)
If a random page was set before entering config_init, do we actually
want
to restore it? Or wouldn't it be better to set the default page as part
of initialization?
First, I want to convert this to the match_phy_device() and while at it,
I noticed that there is this one "problem". Short summary: the IP101A
isn't
paged, the IP101G has serveral and if page 16 is selected it is more or
less compatible with the IP101A. My problem here is now how to share the
functions for both PHYs without duplicating all the code. Eg. the IP101A
will phy_read/phy_write/phy_modify(), that is, all the locked versions.
For the IP101G I'd either need the _paged() versions or the __phy ones
which don't take the mdio_bus lock.
Here is what I came up with:
(1) provide a common function which uses the __phy ones, then the
callback for the A version will take the mdio_bus lock and calls
the common one. The G version will use phy_{select,restore}_page().
(2) the phy_driver ops for A will also provde a .read/write_page()
callback which is just a no-op. So A can just use the G versions.
(3) What Heiner mentioned here, just set the default page in
config_init().
(1) will still bloat the code; (3) has the disadvantage, that the
userspace might fiddle around with the page register and then the
whole PHY driver goes awry. I don't know if we have to respect that
use case in general. I know there is an API to read/write the PHY
registers and it could happen.
That being said, I'm either fine with (2) and (3) but I'm preferring
(2).
BTW, this patch is still missing read/writes to the interrupt status
and control registers which is also paged.
-michael
Registers >= 16 are paged. Be sure to set the page. It seems this was
working for now, because the default is correct for the registers used
in the driver at the moment. But this will also assume, nobody will
change the page select register before linux is started. The page select
register is _not_ reset with a soft reset of the PHY.
Add read_page()/write_page() support for the IP101G and use it
accordingly.
Signed-off-by: Michael Walle <redacted>
---
drivers/net/phy/icplus.c | 50 +++++++++++++++++++++++++++++++---------
1 file changed, 39 insertions(+), 11 deletions(-)
If a random page was set before entering config_init, do we actually want
to restore it? Or wouldn't it be better to set the default page as part
of initialization?
First, I want to convert this to the match_phy_device() and while at it,
I noticed that there is this one "problem". Short summary: the IP101A isn't
paged, the IP101G has serveral and if page 16 is selected it is more or
less compatible with the IP101A. My problem here is now how to share the
functions for both PHYs without duplicating all the code. Eg. the IP101A
will phy_read/phy_write/phy_modify(), that is, all the locked versions.
For the IP101G I'd either need the _paged() versions or the __phy ones
which don't take the mdio_bus lock.
Here is what I came up with:
(1) provide a common function which uses the __phy ones, then the
callback for the A version will take the mdio_bus lock and calls
the common one. The G version will use phy_{select,restore}_page().
(2) the phy_driver ops for A will also provde a .read/write_page()
callback which is just a no-op. So A can just use the G versions.
(3) What Heiner mentioned here, just set the default page in
config_init().
(1) will still bloat the code; (3) has the disadvantage, that the
userspace might fiddle around with the page register and then the
whole PHY driver goes awry. I don't know if we have to respect that
use case in general. I know there is an API to read/write the PHY
registers and it could happen.
The potential issue you mention here we have with all PHY's using
pages. As one example, the genphy functions rely on the PHY being
set to the default page. In general userspace can write PHY register
values that break processing, independent of paging.
I'm not aware of any complaints regarding this behavior, therefore
wouldn't be too concerned here.
Regarding (2) I'd like to come back to my proposal from yesterday,
implement match_phy_device to completely decouple the A and G versions.
Did you consider this option?
That being said, I'm either fine with (2) and (3) but I'm preferring
(2).
BTW, this patch is still missing read/writes to the interrupt status
and control registers which is also paged.
-michael
From: Michael Walle <hidden> Date: 2021-02-10 09:32:10
Hi,
Am 2021-02-10 10:03, schrieb Heiner Kallweit:
[..]
quoted
quoted
quoted
+ return phy_restore_page(phydev, oldpage, err);
If a random page was set before entering config_init, do we actually
want
to restore it? Or wouldn't it be better to set the default page as
part
of initialization?
First, I want to convert this to the match_phy_device() and while at
it,
I noticed that there is this one "problem". Short summary: the IP101A
isn't
paged, the IP101G has serveral and if page 16 is selected it is more
or
less compatible with the IP101A. My problem here is now how to share
the
functions for both PHYs without duplicating all the code. Eg. the
IP101A
will phy_read/phy_write/phy_modify(), that is, all the locked
versions.
For the IP101G I'd either need the _paged() versions or the __phy ones
which don't take the mdio_bus lock.
Here is what I came up with:
(1) provide a common function which uses the __phy ones, then the
callback for the A version will take the mdio_bus lock and calls
the common one. The G version will use
phy_{select,restore}_page().
(2) the phy_driver ops for A will also provde a .read/write_page()
callback which is just a no-op. So A can just use the G versions.
(3) What Heiner mentioned here, just set the default page in
config_init().
(1) will still bloat the code; (3) has the disadvantage, that the
userspace might fiddle around with the page register and then the
whole PHY driver goes awry. I don't know if we have to respect that
use case in general. I know there is an API to read/write the PHY
registers and it could happen.
The potential issue you mention here we have with all PHY's using
pages. As one example, the genphy functions rely on the PHY being
set to the default page. In general userspace can write PHY register
values that break processing, independent of paging.
I'm not aware of any complaints regarding this behavior, therefore
wouldn't be too concerned here.
I'm fine with that, that will make the driver easier.
Regarding (2) I'd like to come back to my proposal from yesterday,
implement match_phy_device to completely decouple the A and G versions.
Did you consider this option?
Yes, that is what I was talking about above: "First, I want to convert
this to the match_phy_device()" ;) And then I stumbled across that
problem
I was describing above.
It will likely go away if I just set the page to the default page.
quoted
That being said, I'm either fine with (2) and (3) but I'm preferring
(2).
BTW, this patch is still missing read/writes to the interrupt status
and control registers which is also paged.
If a random page was set before entering config_init, do we actually want
to restore it? Or wouldn't it be better to set the default page as part
of initialization?
I think you've missed asking one key question: does the paging on this
PHY affect the standardised registers at 0..15 inclusive, or does it
only affect registers 16..31?
If it doesn't affect the standardised registers, then the genphy_*
functions don't care which page is selected.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
If a random page was set before entering config_init, do we actually
want
to restore it? Or wouldn't it be better to set the default page as
part
of initialization?
I think you've missed asking one key question: does the paging on this
PHY affect the standardised registers at 0..15 inclusive, or does it
only affect registers 16..31?
For this PHY it affects only registers >=16. But that doesn't invaldiate
the point that for other PHYs this might affect all regsisters. Eg. ones
where you could select between fiber and copper pages, right?
If it doesn't affect the standardised registers, then the genphy_*
functions don't care which page is selected.
If a random page was set before entering config_init, do we actually
want
to restore it? Or wouldn't it be better to set the default page as
part
of initialization?
I think you've missed asking one key question: does the paging on this
PHY affect the standardised registers at 0..15 inclusive, or does it
only affect registers 16..31?
For this PHY it affects only registers >=16. But that doesn't invaldiate
the point that for other PHYs this might affect all regsisters. Eg. ones
where you could select between fiber and copper pages, right?
You are modifying the code using ip101a_g_* functions, which is only
used for the IP101A and IP101G PHYs. Do these devices support fiber
in a way that change the first 16 registers?
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
If a random page was set before entering config_init, do we actually
want
to restore it? Or wouldn't it be better to set the default page as
part
of initialization?
I think you've missed asking one key question: does the paging on this
PHY affect the standardised registers at 0..15 inclusive, or does it
only affect registers 16..31?
For this PHY it affects only registers >=16. But that doesn't
invaldiate
the point that for other PHYs this might affect all regsisters. Eg.
ones
where you could select between fiber and copper pages, right?
You are modifying the code using ip101a_g_* functions, which is only
used for the IP101A and IP101G PHYs. Do these devices support fiber
in a way that change the first 16 registers?
The PHY doesn't support fiber and register 0..15 are always available
regardless of the selected page for the IP101G.
genphy_() stuff will work, but the IP101G PHY driver specific functions,
like interrupt and mdix will break if someone is messing with the page
register from userspace.
So Heiner's point was, that there are other PHY drivers which
also break when a user changes registers from userspace and no one
seemed to cared about that for now.
I guess it boils down to: how hard should we try to get the driver
behave correctly if the user is changing registers. Or can we
just make the assumption that if the PHY driver sets the page
selection to its default, all the other callbacks will work
on this page.
-michael
From: Russell King - ARM Linux admin <linux@armlinux.org.uk> Date: 2021-02-10 11:54:37
On Wed, Feb 10, 2021 at 12:14:35PM +0100, Michael Walle wrote:
Am 2021-02-10 11:49, schrieb Russell King - ARM Linux admin:
The PHY doesn't support fiber and register 0..15 are always available
regardless of the selected page for the IP101G.
genphy_() stuff will work, but the IP101G PHY driver specific functions,
like interrupt and mdix will break if someone is messing with the page
register from userspace.
So Heiner's point was, that there are other PHY drivers which
also break when a user changes registers from userspace and no one
seemed to cared about that for now.
I guess it boils down to: how hard should we try to get the driver
behave correctly if the user is changing registers. Or can we
just make the assumption that if the PHY driver sets the page
selection to its default, all the other callbacks will work
on this page.
Provided the PHY driver uses the paged accessors for all paged
registers, userspace can't break the PHY driver because we have proper
locking in the paged accessors (I wrote them.) Userspace can access the
paged registers too, but there will be no locking other than on each
individual access. This can't be fixed without augmenting the kernel/
user API, and in any case is not a matter for the PHY driver.
So, let's stop worrying about the userspace paged access problem for
driver reviews; that's a core phylib and userspace API issue.
The paged accessor API is designed to allow the driver author to access
registers in the most efficient manner. There are two parts to it.
1) the phy_*_paged() accessors switch the page before accessing the
register, and restore it afterwards. If you need to access a lot
of paged registers, this can be inefficient.
2) phy_save_page()..phy_restore_page() allows wrapping of __phy_*
accessors to access paged registers.
3) phy_select_page()..phy_restore_page() also allows wrapping of
__phy_* accessors to access paged registers.
phy_save_page() and phy_select_page() must /always/ be paired with
a call to phy_restore_page(), since the former pair takes the bus lock
and the latter releases it.
(2) and (3) allow multiple accesses to either a single page without
constantly saving and restoring the page, and can also be used to
select other pages without the save/restore and locking steps. We
could export __phy_read_page() and __phy_write_page() if required.
While the bus lock is taken, userspace can't access any PHY on the bus.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
From: Michael Walle <hidden> Date: 2021-02-10 12:21:06
Am 2021-02-10 12:48, schrieb Russell King - ARM Linux admin:
On Wed, Feb 10, 2021 at 12:14:35PM +0100, Michael Walle wrote:
quoted
Am 2021-02-10 11:49, schrieb Russell King - ARM Linux admin:
The PHY doesn't support fiber and register 0..15 are always available
regardless of the selected page for the IP101G.
genphy_() stuff will work, but the IP101G PHY driver specific
functions,
like interrupt and mdix will break if someone is messing with the page
register from userspace.
So Heiner's point was, that there are other PHY drivers which
also break when a user changes registers from userspace and no one
seemed to cared about that for now.
I guess it boils down to: how hard should we try to get the driver
behave correctly if the user is changing registers. Or can we
just make the assumption that if the PHY driver sets the page
selection to its default, all the other callbacks will work
on this page.
Provided the PHY driver uses the paged accessors for all paged
registers, userspace can't break the PHY driver because we have proper
locking in the paged accessors (I wrote them.) Userspace can access the
paged registers too, but there will be no locking other than on each
individual access. This can't be fixed without augmenting the kernel/
user API, and in any case is not a matter for the PHY driver.
So, let's stop worrying about the userspace paged access problem for
driver reviews; that's a core phylib and userspace API issue.
The paged accessor API is designed to allow the driver author to access
registers in the most efficient manner. There are two parts to it.
1) the phy_*_paged() accessors switch the page before accessing the
register, and restore it afterwards. If you need to access a lot
of paged registers, this can be inefficient.
2) phy_save_page()..phy_restore_page() allows wrapping of __phy_*
accessors to access paged registers.
3) phy_select_page()..phy_restore_page() also allows wrapping of
__phy_* accessors to access paged registers.
phy_save_page() and phy_select_page() must /always/ be paired with
a call to phy_restore_page(), since the former pair takes the bus lock
and the latter releases it.
(2) and (3) allow multiple accesses to either a single page without
constantly saving and restoring the page, and can also be used to
select other pages without the save/restore and locking steps. We
could export __phy_read_page() and __phy_write_page() if required.
While the bus lock is taken, userspace can't access any PHY on the bus.
That was how the v1 of this series was written. But Heiner's review
comment was, what if we just set the default page and don't
use phy_save_page()..phy_restore_page() for the registers which are
behind the default page. And in this case, userspace _can_ break
access to the paged registers.
-michael
Am 2021-02-10 12:48, schrieb Russell King - ARM Linux admin:
quoted
On Wed, Feb 10, 2021 at 12:14:35PM +0100, Michael Walle wrote:
quoted
Am 2021-02-10 11:49, schrieb Russell King - ARM Linux admin:
The PHY doesn't support fiber and register 0..15 are always available
regardless of the selected page for the IP101G.
genphy_() stuff will work, but the IP101G PHY driver specific functions,
like interrupt and mdix will break if someone is messing with the page
register from userspace.
So Heiner's point was, that there are other PHY drivers which
also break when a user changes registers from userspace and no one
seemed to cared about that for now.
I guess it boils down to: how hard should we try to get the driver
behave correctly if the user is changing registers. Or can we
just make the assumption that if the PHY driver sets the page
selection to its default, all the other callbacks will work
on this page.
Provided the PHY driver uses the paged accessors for all paged
registers, userspace can't break the PHY driver because we have proper
locking in the paged accessors (I wrote them.) Userspace can access the
paged registers too, but there will be no locking other than on each
individual access. This can't be fixed without augmenting the kernel/
user API, and in any case is not a matter for the PHY driver.
So, let's stop worrying about the userspace paged access problem for
driver reviews; that's a core phylib and userspace API issue.
The paged accessor API is designed to allow the driver author to access
registers in the most efficient manner. There are two parts to it.
1) the phy_*_paged() accessors switch the page before accessing the
register, and restore it afterwards. If you need to access a lot
of paged registers, this can be inefficient.
2) phy_save_page()..phy_restore_page() allows wrapping of __phy_*
accessors to access paged registers.
3) phy_select_page()..phy_restore_page() also allows wrapping of
__phy_* accessors to access paged registers.
phy_save_page() and phy_select_page() must /always/ be paired with
a call to phy_restore_page(), since the former pair takes the bus lock
and the latter releases it.
(2) and (3) allow multiple accesses to either a single page without
constantly saving and restoring the page, and can also be used to
select other pages without the save/restore and locking steps. We
could export __phy_read_page() and __phy_write_page() if required.
While the bus lock is taken, userspace can't access any PHY on the bus.
That was how the v1 of this series was written. But Heiner's review
comment was, what if we just set the default page and don't
use phy_save_page()..phy_restore_page() for the registers which are
behind the default page. And in this case, userspace _can_ break
access to the paged registers.
The comment was assuming that paging also applies to register 0..15,
like it is the case for Realtek PHY's. That's not the case for your
PHY, therefore the situation is slightly different.
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-02-10 20:28:38
I guess it boils down to: how hard should we try to get the driver
behave correctly if the user is changing registers.
All bets are off if root starts messing with the PHY state from
userspace. Its a foot gun, don't be surprised with what happens when
you use it.
Andrew