net: phy: mscc-miim: reduce waiting time between MDIO transactions
Subsystems (3)
cover net: phy: mscc-miim: reduce waiting time between MDIO transactions
Hello,
This series aims at reducing the waiting time between MDIO transactions when using the MSCC MIIM MDIO controller.
I'm not sure we need patch 4/4 and we could reasonably drop it from the series. I'm including the patch as it could help to ensure the system is functional with a non optimal configuration.
We needed to improve the driver's performances as when using a PHY requiring lots of registers accesses (such as the VSC85xx family), delays would add up and ended up to be quite large which would cause issues such as: a slow initialization of the PHY, and issues when using timestamping operations (this feature will be sent quite soon to the mailing lists).
Thanks,
Antoine
Antoine Tenart (4):
net: phy: mscc-miim: use more reasonable delays
net: phy: mscc-miim: remove redundant timeout check
net: phy: mscc-miim: improve waiting logic
net: phy: mscc-miim: read poll when high resolution timers are
disabled
drivers/net/phy/Kconfig | 3 ++- drivers/net/phy/mdio-mscc-miim.c | 33 +++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/4 net: phy: mscc-miim: use more reasonable delays
The MSCC MIIM MDIO driver uses delays to read poll a status register. I made multiple tests on a Ocelot PCS120 platform which led me to reduce those delays. The delay in between which the polling function is allowed to sleep is reduced from 100us to 50us which in almost all cases is a good value to succeed at the first retry. The overall delay is also lowered as the prior value was really way to high, 10000us is large enough.
--- drivers/net/phy/mdio-mscc-miim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/mdio-mscc-miim.c +1 -1
@@ -44,7 +44,7 @@ static int mscc_miim_wait_ready(struct mii_bus *bus)u32 val;readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, - !(val &MSCC_MIIM_STATUS_STAT_BUSY ),100 ,250000 ); + !(val &MSCC_MIIM_STATUS_STAT_BUSY ),50 ,10000 );if (val &MSCC_MIIM_STATUS_STAT_BUSY )return -ETIMEDOUT ;
Signature · 1 line
2.26.2
Re: [PATCH net-next 1/4] net: phy: mscc-miim: use more reasonable delays
Quoted 9 lines · Antoine Ténart
The MSCC MIIM MDIO driver uses delays to read poll a status register. I made multiple tests on a Ocelot PCS120 platform which led me to reduce those delays. The delay in between which the polling function is allowed to sleep is reduced from 100us to 50us which in almost all cases is a good value to succeed at the first retry. The overall delay is also lowered as the prior value was really way to high, 10000us is large enough.
Signed-off-by Antoine Tenart <[email protected]>
Quoted 20 lines
--- drivers/net/phy/mdio-mscc-miim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/phy/mdio-mscc-miim.c +1
-1@@ -44,7 +44,7 @@ static int mscc_miim_wait_ready(struct mii_bus *bus)u32 val;readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, - !(val &MSCC_MIIM_STATUS_STAT_BUSY ),100 ,250000 ); + !(val &MSCC_MIIM_STATUS_STAT_BUSY ),50 ,10000 );if (val &MSCC_MIIM_STATUS_STAT_BUSY )return -ETIMEDOUT ;Signature · 1 line
2.26.2
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH net-next 1/4] net: phy: mscc-miim: use more reasonable delays
In reply to Antoine TenartQuoted 9 lines · Antoine Tenart
The MSCC MIIM MDIO driver uses delays to read poll a status register. I made multiple tests on a Ocelot PCS120 platform which led me to reduce those delays. The delay in between which the polling function is allowed to sleep is reduced from 100us to 50us which in almost all cases is a good value to succeed at the first retry. The overall delay is also lowered as the prior value was really way to high, 10000us is large enough.
Signed-off-by Antoine Tenart <[email protected]>
Signature · 1 line
Florian
PATCH 2/4 net: phy: mscc-miim: remove redundant timeout check
In reply to Antoine Tenartreadl_poll_timeout already returns -ETIMEDOUT if the condition isn't satisfied, there's no need to check again the condition after calling it. Remove the redundant timeout check.
--- drivers/net/phy/mdio-mscc-miim.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/phy/mdio-mscc-miim.c +2 -6
@@ -43,12 +43,8 @@ static int mscc_miim_wait_ready(struct mii_bus *bus)struct mscc_miim_dev *miim = bus->priv;u32 val; -readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, - !(val &MSCC_MIIM_STATUS_STAT_BUSY ),50 ,10000 ); -if (val &MSCC_MIIM_STATUS_STAT_BUSY ) -return -ETIMEDOUT ; - -return 0 ; +return readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, + !(val &MSCC_MIIM_STATUS_STAT_BUSY ),50 ,10000 ); }static int mscc_miim_read (struct mii_bus *bus,int mii_id,int regnum)
Signature · 1 line
2.26.2
Re: [PATCH net-next 2/4] net: phy: mscc-miim: remove redundant timeout check
Quoted 5 lines · Antoine Ténart
readl_poll_timeoutalready returns-ETIMEDOUTif the condition isn't satisfied, there's no need to check again the condition after calling it. Remove the redundant timeout check.Signed-off-by Antoine Tenart <[email protected]>
Quoted 26 lines
--- drivers/net/phy/mdio-mscc-miim.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/net/phy/mdio-mscc-miim.c +2
-6@@ -43,12 +43,8 @@ static int mscc_miim_wait_ready(struct mii_bus *bus)struct mscc_miim_dev *miim = bus->priv;u32 val; -readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, - !(val &MSCC_MIIM_STATUS_STAT_BUSY ),50 ,10000 ); -if (val &MSCC_MIIM_STATUS_STAT_BUSY ) -return -ETIMEDOUT ; - -return 0 ; +return readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, + !(val &MSCC_MIIM_STATUS_STAT_BUSY ),50 ,10000 ); }static int mscc_miim_read (struct mii_bus *bus,int mii_id,int regnum)Signature · 1 line
2.26.2
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH net-next 2/4] net: phy: mscc-miim: remove redundant timeout check
In reply to Antoine TenartQuoted 5 lines · Antoine Tenart
readl_poll_timeoutalready returns-ETIMEDOUTif the condition isn't satisfied, there's no need to check again the condition after calling it. Remove the redundant timeout check.Signed-off-by Antoine Tenart <[email protected]>
Signature · 1 line
Florian
PATCH 3/4 net: phy: mscc-miim: improve waiting logic
In reply to Antoine TenartThe MSCC MIIM MDIO driver uses a waiting logic to wait for the MDIO bus to be ready to accept next commands. It does so by polling the BUSY status bit which indicates the MDIO bus has completed all pending operations. This can take time, and the controller supports writing the next command as soon as there are no pending commands (which happens while the MDIO bus is busy completing its current command).
This patch implements this improved logic by adding an helper to poll the PENDING status bit, and by adjusting where we should wait for the bus to not be busy or to not be pending.
--- drivers/net/phy/mdio-mscc-miim.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/phy/mdio-mscc-miim.c +13 -2
@@ -16,6 +16,7 @@#include <linux/of_mdio.h> #define MSCC_MIIM_REG_STATUS 0x0 +#define MSCC_MIIM_STATUS_STAT_PENDING BIT(2)#define MSCC_MIIM_STATUS_STAT_BUSY BIT(3)#define MSCC_MIIM_REG_CMD 0x8#define MSCC_MIIM_CMD_OPR_WRITE BIT(1)
@@ -47,13 +48,23 @@ static int mscc_miim_wait_ready(struct mii_bus *bus) !(val & MSCC_MIIM_STATUS_STAT_BUSY), 50, 10000); } +static int mscc_miim_wait_pending (struct mii_bus *bus) +{ +struct mscc_miim_dev *miim = bus->priv; +u32 val; + +return readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, + !(val &MSCC_MIIM_STATUS_STAT_PENDING ), +50 ,10000 ); +} +static int mscc_miim_read (struct mii_bus *bus,int mii_id,int regnum) {struct mscc_miim_dev *miim = bus->priv;u32 val;int ret; - ret =mscc_miim_wait_ready (bus); + ret =mscc_miim_wait_pending (bus);if (ret) goto out;
@@ -82,7 +93,7 @@ static int mscc_miim_write(struct mii_bus *bus, int mii_id,struct mscc_miim_dev *miim = bus->priv;int ret; - ret =mscc_miim_wait_ready (bus); + ret =mscc_miim_wait_pending (bus);if (ret <0 ) goto out;
Signature · 1 line
2.26.2
Re: [PATCH net-next 3/4] net: phy: mscc-miim: improve waiting logic
Quoted 7 lines · Antoine Ténart
The MSCC MIIM MDIO driver uses a waiting logic to wait for the MDIO bus to be ready to accept next commands. It does so by polling the BUSY status bit which indicates the MDIO bus has completed all pending operations. This can take time, and the controller supports writing the next command as soon as there are no pending commands (which happens while the MDIO bus is busy completing its current command).
Quoted 5 lines
This patch implements this improved logic by adding an helper to poll the PENDING status bit, and by adjusting where we should wait for the bus to not be busy or to not be pending.
Signed-off-by Antoine Tenart <[email protected]>
Quoted 53 lines
--- drivers/net/phy/mdio-mscc-miim.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/net/phy/mdio-mscc-miim.c +13
-2@@ -16,6 +16,7 @@#include <linux/of_mdio.h> #define MSCC_MIIM_REG_STATUS 0x0 +#define MSCC_MIIM_STATUS_STAT_PENDING BIT(2)#define MSCC_MIIM_STATUS_STAT_BUSY BIT(3)#define MSCC_MIIM_REG_CMD 0x8#define MSCC_MIIM_CMD_OPR_WRITE BIT(1)@@ -47,13 +48,23 @@ static int mscc_miim_wait_ready(struct mii_bus *bus) !(val & MSCC_MIIM_STATUS_STAT_BUSY), 50, 10000); } +static int mscc_miim_wait_pending (struct mii_bus *bus) +{ +struct mscc_miim_dev *miim = bus->priv; +u32 val; + +return readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, + !(val &MSCC_MIIM_STATUS_STAT_PENDING ), +50 ,10000 ); +} +static int mscc_miim_read (struct mii_bus *bus,int mii_id,int regnum) {struct mscc_miim_dev *miim = bus->priv;u32 val;int ret; - ret =mscc_miim_wait_ready (bus); + ret =mscc_miim_wait_pending (bus);if (ret) goto out;@@ -82,7 +93,7 @@ static int mscc_miim_write(struct mii_bus *bus, int mii_id,struct mscc_miim_dev *miim = bus->priv;int ret; - ret =mscc_miim_wait_ready (bus); + ret =mscc_miim_wait_pending (bus);if (ret <0 ) goto out;Signature · 1 line
2.26.2
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH net-next 3/4] net: phy: mscc-miim: improve waiting logic
In reply to Antoine TenartQuoted 7 lines · Antoine Tenart
The MSCC MIIM MDIO driver uses a waiting logic to wait for the MDIO bus to be ready to accept next commands. It does so by polling the BUSY status bit which indicates the MDIO bus has completed all pending operations. This can take time, and the controller supports writing the next command as soon as there are no pending commands (which happens while the MDIO bus is busy completing its current command).
Quoted 5 lines
This patch implements this improved logic by adding an helper to poll the PENDING status bit, and by adjusting where we should wait for the bus to not be busy or to not be pending.
Signed-off-by Antoine Tenart <[email protected]>
Signature · 1 line
Florian
PATCH 4/4 net: phy: mscc-miim: read poll when high resolution timers are disabled
In reply to Antoine TenartThe driver uses a read polling mechanism to check the status of the MDIO bus, to know if it is ready to accept next commands. This polling mechanism uses usleep_delay() under the hood between reads which is fine as long as high resolution timers are enabled. Otherwise the delays will end up to be much longer than expected.
This patch fixes this by using udelay() under the hood when CONFIG_HIGH_RES_TIMERS isn't enabled. This increases CPU usage.
--- drivers/net/phy/Kconfig | 3 ++- drivers/net/phy/mdio-mscc-miim.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-)
drivers/net/phy/Kconfig +2 -1
@@ -184,7 +184,8 @@ config MDIO_MSCC_MIIM depends on HAS_IOMEM help This driver supports the MIIM (MDIO) interface found in the network - switches of the Microsemi SoCs + switches of the Microsemi SoCs; it is recommended to switch on + CONFIG_HIGH_RES_TIMERS config MDIO_MVUSB tristate "Marvell USB to MDIO Adapter"
drivers/net/phy/mdio-mscc-miim.c +17 -5
@@ -39,13 +39,25 @@ struct mscc_miim_dev {void __iomem *phy_regs; }; +/* When high resolution timers aren't built-in: we can't use usleep_range() as +* we would sleep way too long. Use udelay() instead. +*/ +#define mscc_readl_poll_timeout (addr, val, cond, delay_us, timeout_us) \ +({ \ + if (!IS_ENABLED(CONFIG_HIGH_RES_TIMERS)) \ + readl_poll_timeout_atomic(addr, val, cond, delay_us, \ + timeout_us); \ + readl_poll_timeout(addr, val, cond, delay_us, timeout_us); \ +}) +static int mscc_miim_wait_ready (struct mii_bus *bus) {struct mscc_miim_dev *miim = bus->priv;u32 val; -return readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, - !(val &MSCC_MIIM_STATUS_STAT_BUSY ),50 ,10000 ); +return mscc_readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, + !(val &MSCC_MIIM_STATUS_STAT_BUSY ),50 , +10000 ); }static int mscc_miim_wait_pending (struct mii_bus *bus)
@@ -53,9 +65,9 @@ static int mscc_miim_wait_pending(struct mii_bus *bus)struct mscc_miim_dev *miim = bus->priv;u32 val; -return readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, - !(val &MSCC_MIIM_STATUS_STAT_PENDING ), -50 ,10000 ); +return mscc_readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, + !(val &MSCC_MIIM_STATUS_STAT_PENDING ), +50 ,10000 ); }static int mscc_miim_read (struct mii_bus *bus,int mii_id,int regnum)
Signature · 1 line
2.26.2
Re: [PATCH net-next 4/4] net: phy: mscc-miim: read poll when high resolution timers are disabled
Quoted 38 lines · Antoine Tenart
The driver uses a read polling mechanism to check the status of the MDIO bus, to know if it is ready to accept next commands. This polling mechanism uses
usleep_delay()under the hood between reads which is fine as long as high resolution timers are enabled. Otherwise the delays will end up to be much longer than expected.This patch fixes this by using
udelay()under the hood whenCONFIG_HIGH_RES_TIMERSisn't enabled. This increases CPU usage.Signed-off-by Antoine Tenart <[email protected]>--- drivers/net/phy/Kconfig | 3 ++- drivers/net/phy/mdio-mscc-miim.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-)drivers/net/phy/Kconfig +2
-1@@ -184,7 +184,8 @@ config MDIO_MSCC_MIIM depends on HAS_IOMEM help This driver supports the MIIM (MDIO) interface found in the network - switches of the Microsemi SoCs + switches of the Microsemi SoCs; it is recommended to switch on + CONFIG_HIGH_RES_TIMERS config MDIO_MVUSB tristate "Marvell USB to MDIO Adapter"drivers/net/phy/mdio-mscc-miim.c +1
-0@@ -39,13 +39,25 @@ struct mscc_miim_dev {void __iomem *phy_regs; }; +/* When high resolution timers aren't built-in: we can't use usleep_range() as
drivers/net/phy/mdio-mscc-miim.c struct mscc_miim_dev { · line 52
Quoted 10 lines
drivers/net/phy/mdio-mscc-miim.c +10
-0+* we would sleep way too long. Use udelay() instead. +*/ +#define mscc_readl_poll_timeout (addr, val, cond, delay_us, timeout_us) \ +({ \ + if (!IS_ENABLED(CONFIG_HIGH_RES_TIMERS)) \ + readl_poll_timeout_atomic(addr, val, cond, delay_us, \ + timeout_us); \ + readl_poll_timeout(addr, val, cond, delay_us, timeout_us); \ +}) +
I would make this a regular function which would not harm the compiler's ability to optimize it, but would give you type checking. With that fixed:
Signature · 1 line
Florian
Andrew Lunn
maintainerRe: [PATCH net-next 4/4] net: phy: mscc-miim: read poll when high resolution timers are disabled
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/mdio-mscc-miim.c +6
-0+/* When high resolution timers aren't built-in: we can't use usleep_range() as +* we would sleep way too long. Use udelay() instead. +*/ +#define mscc_readl_poll_timeout (addr, val, cond, delay_us, timeout_us) \ +({ \ + if (!IS_ENABLED(CONFIG_HIGH_RES_TIMERS)) \
Quoted 8 lines
drivers/net/phy/mdio-mscc-miim.c struct mscc_miim_dev { · line 52
Quoted 5 lines
drivers/net/phy/mdio-mscc-miim.c +5
-0+readl_poll_timeout_atomic (addr, val, cond, delay_us, \ + timeout_us); \ +readl_poll_timeout (addr, val, cond, delay_us, timeout_us); \ +}) +I would make this a regular function which would not harm the compiler's ability to optimize it, but would give you type checking. With that fixed:
Hi Florian
cond makes that difficult, since it is not a parameter in the usual sense, but an expression to evaluate if the polling should terminate.
readl_poll_timeout() and readl_poll_timeout_atomic() themselves are #define's, and there are more levels of macros under them.
Andrew
Re: [PATCH net-next 4/4] net: phy: mscc-miim: read poll when high resolution timers are disabled
Quoted 15 lines · Andrew Lunn
Quoted 6 lines
Quoted 6 lines
drivers/net/phy/mdio-mscc-miim.c +6
-0+/* When high resolution timers aren't built-in: we can't use usleep_range() as +* we would sleep way too long. Use udelay() instead. +*/ +#define mscc_readl_poll_timeout (addr, val, cond, delay_us, timeout_us) \ +({ \ + if (!IS_ENABLED(CONFIG_HIGH_RES_TIMERS)) \Quoted 8 lines
drivers/net/phy/mdio-mscc-miim.c struct mscc_miim_dev { · line 52
Quoted 5 lines
drivers/net/phy/mdio-mscc-miim.c +5
-0+readl_poll_timeout_atomic (addr, val, cond, delay_us, \ + timeout_us); \ +readl_poll_timeout (addr, val, cond, delay_us, timeout_us); \ +}) +I would make this a regular function which would not harm the compiler's ability to optimize it, but would give you type checking. With that fixed:
Quoted 7 lines
Hi Florian
cond makes that difficult, since it is not a parameter in the usual sense, but an expression to evaluate if the polling should terminate.
readl_poll_timeout()andreadl_poll_timeout_atomic()themselves are #define's, and there are more levels of macros under them.
Oh that's right, thanks for reminding me of this.
Signature · 1 line
Florian
Andrew Lunn
maintainerQuoted 4 lines · Antoine Tenart
Hello,
This series aims at reducing the waiting time between MDIO transactions when using the MSCC MIIM MDIO controller.
Hi Antoine
There are a couple of other things you can look at:
Can you disable the pre-amble on the MDIO transaction. It requires that both the bus master and all devices on the bus support it, but when it is usable, you half the number of bits sent over the wire.
Can you control the frequency of MDC? 802.3 says 2.5MHz, but many devices support higher speeds. Again, you need all devices on the bus to support the speed.
When accessing raw TDR data for cable tests i also have a lot of PHY accesses. I implemented both of these for the FEC MDIO bus, and made it a lot faster.
Andrew
Hi Andrew,
Quoting Andrew Lunn (2020-05-26 19:01:00)
Quoted 11 lines · Antoine Tenart
Quoted 3 lines
This series aims at reducing the waiting time between MDIO transactions when using the MSCC MIIM MDIO controller.
There are a couple of other things you can look at:
Can you disable the pre-amble on the MDIO transaction. It requires that both the bus master and all devices on the bus support it, but when it is usable, you half the number of bits sent over the wire.
Quoted 7 lines
Can you control the frequency of MDC? 802.3 says 2.5MHz, but many devices support higher speeds. Again, you need all devices on the bus to support the speed.
When accessing raw TDR data for cable tests i also have a lot of PHY accesses. I implemented both of these for the FEC MDIO bus, and made it a lot faster.
Thanks for the tips!
Antoine
Signature · 3 lines
Antoine Ténart, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
David Miller
maintainerFrom: Antoine Tenart <[email protected]>
Date: Tue, 26 May 2020 18:22:52 +0200
Quoted 7 lines
This series aims at reducing the waiting time between MDIO transactions when using the MSCC MIIM MDIO controller.
I'm not sure we need patch 4/4 and we could reasonably drop it from the series. I'm including the patch as it could help to ensure the system is functional with a non optimal configuration.
Quoted 6 lines
We needed to improve the driver's performances as when using a PHY requiring lots of registers accesses (such as the VSC85xx family), delays would add up and ended up to be quite large which would cause issues such as: a slow initialization of the PHY, and issues when using timestamping operations (this feature will be sent quite soon to the mailing lists).
Series applied, thank you.