* [PATCH v3 0/2] ethtool: implement Energy Detect Powerdown support via phy-tunable @ 2019-09-09 13:12 Alexandru Ardelean 2019-09-09 13:12 ` [PATCH v3 1/2] " Alexandru Ardelean 2019-09-09 13:12 ` [PATCH v3 2/2] net: phy: adin: implement Energy Detect Powerdown mode " Alexandru Ardelean 0 siblings, 2 replies; 5+ messages in thread From: Alexandru Ardelean @ 2019-09-09 13:12 UTC (permalink / raw) To: netdev, devicetree, linux-kernel Cc: davem, robh+dt, mark.rutland, f.fainelli, hkallweit1, andrew, Alexandru Ardelean This changeset proposes a new control for PHY tunable to control Energy Detect Power Down. The `phy_tunable_id` has been named `ETHTOOL_PHY_EDPD` since it looks like this feature is common across other PHYs (like EEE), and defining `ETHTOOL_PHY_ENERGY_DETECT_POWER_DOWN` seems too long. The way EDPD works, is that the RX block is put to a lower power mode, except for link-pulse detection circuits. The TX block is also put to low power mode, but the PHY wakes-up periodically to send link pulses, to avoid lock-ups in case the other side is also in EDPD mode. Currently, there are 2 PHY drivers that look like they could use this new PHY tunable feature: the `adin` && `micrel` PHYs. This series updates only the `adin` PHY driver to support this new feature, as this chip has been tested. A change for `micrel` can be proposed after a discussion of the PHY-tunable API is resolved. Alexandru Ardelean (2): ethtool: implement Energy Detect Powerdown support via phy-tunable net: phy: adin: implement Energy Detect Powerdown mode via phy-tunable drivers/net/phy/adin.c | 61 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/ethtool.h | 19 +++++++++++ net/core/ethtool.c | 6 ++++ 3 files changed, 86 insertions(+) -- Changelog v2 -> v3: * implement Andrew's review comments: 1. for patch `ethtool: implement Energy Detect Powerdown support via phy-tunable` - ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL == 0xffff - ETHTOOL_PHY_EDPD_NO_TX == 0xfffe - added comment in include/uapi/linux/ethtool.h 2. for patch `net: phy: adin: implement Energy Detect Powerdown mode via phy-tunable` - added comments about interval & units for the ADIN PHY - in `adin_set_edpd()`: add a switch statement of all the valid values - in `adin_get_edpd()`: return `ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL` since the PHY only supports a single TX-interval value (1 second) Changelog v1 -> v2: * initial series was made up of 2 sub-series: 1 for kernel & 1 for ethtool in userspace; v2 contains only the kernel series 2.20.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] ethtool: implement Energy Detect Powerdown support via phy-tunable 2019-09-09 13:12 [PATCH v3 0/2] ethtool: implement Energy Detect Powerdown support via phy-tunable Alexandru Ardelean @ 2019-09-09 13:12 ` Alexandru Ardelean 2019-09-10 8:00 ` Michal Kubecek 2019-09-09 13:12 ` [PATCH v3 2/2] net: phy: adin: implement Energy Detect Powerdown mode " Alexandru Ardelean 1 sibling, 1 reply; 5+ messages in thread From: Alexandru Ardelean @ 2019-09-09 13:12 UTC (permalink / raw) To: netdev, devicetree, linux-kernel Cc: davem, robh+dt, mark.rutland, f.fainelli, hkallweit1, andrew, Alexandru Ardelean The `phy_tunable_id` has been named `ETHTOOL_PHY_EDPD` since it looks like this feature is common across other PHYs (like EEE), and defining `ETHTOOL_PHY_ENERGY_DETECT_POWER_DOWN` seems too long. The way EDPD works, is that the RX block is put to a lower power mode, except for link-pulse detection circuits. The TX block is also put to low power mode, but the PHY wakes-up periodically to send link pulses, to avoid lock-ups in case the other side is also in EDPD mode. Currently, there are 2 PHY drivers that look like they could use this new PHY tunable feature: the `adin` && `micrel` PHYs. The ADIN's datasheet mentions that TX pulses are at intervals of 1 second default each, and they can be disabled. For the Micrel KSZ9031 PHY, the datasheet does not mention whether they can be disabled, but mentions that they can modified. The way this change is structured, is similar to the PHY tunable downshift control: * a `ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL` value is exposed to cover a default TX interval; some PHYs could specify a certain value that makes sense * `ETHTOOL_PHY_EDPD_NO_TX` would disable TX when EDPD is enabled * `ETHTOOL_PHY_EDPD_DISABLE` will disable EDPD This should allow PHYs to: * enable EDPD and not enable TX pulses (interval would be 0) * enable EDPD and configure TX pulse interval; note that TX interval units would be PHY specific; we could consider `seconds` as units, but it could happen that some PHYs would be prefer milliseconds as a unit; a maximum of 65533 units should be sufficient * disable EDPD Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> --- include/uapi/linux/ethtool.h | 19 +++++++++++++++++++ net/core/ethtool.c | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index dd06302aa93e..5961b4984cb6 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -259,10 +259,29 @@ struct ethtool_tunable { #define ETHTOOL_PHY_FAST_LINK_DOWN_ON 0 #define ETHTOOL_PHY_FAST_LINK_DOWN_OFF 0xff +/* Energy Detect Power Down (EDPD) is a feature supported by some PHYs, where + * the PHY's RX & TX blocks are put into a low-power mode when there is no + * link detected (typically cable is un-plugged). For RX, only a minimal + * link-detection is available, and for TX the PHY wakes up to send link pulses + * to avoid any lock-ups in case the peer PHY may also be running in EDPD mode. + * + * Some PHYs may support configuration of the wake-up interval for TX pulses, + * and some PHYs may support only disabling TX pulses entirely. For the latter + * a special value is required (ETHTOOL_PHY_EDPD_NO_TX) so that this can be + * configured from userspace (should the user want it). + * + * The interval units for TX wake-up are PHY specific, as some PHYs may require + * seconds as intervals, and some would require milliseconds. + */ +#define ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL 0xffff +#define ETHTOOL_PHY_EDPD_NO_TX 0xfffe +#define ETHTOOL_PHY_EDPD_DISABLE 0 + enum phy_tunable_id { ETHTOOL_PHY_ID_UNSPEC, ETHTOOL_PHY_DOWNSHIFT, ETHTOOL_PHY_FAST_LINK_DOWN, + ETHTOOL_PHY_EDPD, /* * Add your fresh new phy tunable attribute above and remember to update * phy_tunable_strings[] in net/core/ethtool.c diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 6288e69e94fc..c763106c73fc 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -133,6 +133,7 @@ phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = { [ETHTOOL_ID_UNSPEC] = "Unspec", [ETHTOOL_PHY_DOWNSHIFT] = "phy-downshift", [ETHTOOL_PHY_FAST_LINK_DOWN] = "phy-fast-link-down", + [ETHTOOL_PHY_EDPD] = "phy-energy-detect-power-down", }; static int ethtool_get_features(struct net_device *dev, void __user *useraddr) @@ -2451,6 +2452,11 @@ static int ethtool_phy_tunable_valid(const struct ethtool_tunable *tuna) tuna->type_id != ETHTOOL_TUNABLE_U8) return -EINVAL; break; + case ETHTOOL_PHY_EDPD: + if (tuna->len != sizeof(u16) || + tuna->type_id != ETHTOOL_TUNABLE_U16) + return -EINVAL; + break; default: return -EINVAL; } -- 2.20.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] ethtool: implement Energy Detect Powerdown support via phy-tunable 2019-09-09 13:12 ` [PATCH v3 1/2] " Alexandru Ardelean @ 2019-09-10 8:00 ` Michal Kubecek 2019-09-10 12:07 ` Ardelean, Alexandru 0 siblings, 1 reply; 5+ messages in thread From: Michal Kubecek @ 2019-09-10 8:00 UTC (permalink / raw) To: netdev Cc: Alexandru Ardelean, devicetree, linux-kernel, davem, robh+dt, mark.rutland, f.fainelli, hkallweit1, andrew On Mon, Sep 09, 2019 at 04:12:50PM +0300, Alexandru Ardelean wrote: > The `phy_tunable_id` has been named `ETHTOOL_PHY_EDPD` since it looks like > this feature is common across other PHYs (like EEE), and defining > `ETHTOOL_PHY_ENERGY_DETECT_POWER_DOWN` seems too long. > > The way EDPD works, is that the RX block is put to a lower power mode, > except for link-pulse detection circuits. The TX block is also put to low > power mode, but the PHY wakes-up periodically to send link pulses, to avoid > lock-ups in case the other side is also in EDPD mode. > > Currently, there are 2 PHY drivers that look like they could use this new > PHY tunable feature: the `adin` && `micrel` PHYs. > > The ADIN's datasheet mentions that TX pulses are at intervals of 1 second > default each, and they can be disabled. For the Micrel KSZ9031 PHY, the > datasheet does not mention whether they can be disabled, but mentions that > they can modified. > > The way this change is structured, is similar to the PHY tunable downshift > control: > * a `ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL` value is exposed to cover a default > TX interval; some PHYs could specify a certain value that makes sense > * `ETHTOOL_PHY_EDPD_NO_TX` would disable TX when EDPD is enabled > * `ETHTOOL_PHY_EDPD_DISABLE` will disable EDPD > > This should allow PHYs to: > * enable EDPD and not enable TX pulses (interval would be 0) > * enable EDPD and configure TX pulse interval; note that TX interval units > would be PHY specific; we could consider `seconds` as units, but it could > happen that some PHYs would be prefer milliseconds as a unit; > a maximum of 65533 units should be sufficient Sorry for missing the discussion on previous version but I don't really like the idea of leaving the choice of units to PHY. Both for manual setting and system configuration, it would be IMHO much more convenient to have the interpretation universal for all NICs. Seconds as units seem too coarse and maximum of ~18 hours way too big. Milliseconds would be more practical from granularity point of view, would maximum of ~65 seconds be sufficient? Michal Kubecek > * disable EDPD > > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] ethtool: implement Energy Detect Powerdown support via phy-tunable 2019-09-10 8:00 ` Michal Kubecek @ 2019-09-10 12:07 ` Ardelean, Alexandru 0 siblings, 0 replies; 5+ messages in thread From: Ardelean, Alexandru @ 2019-09-10 12:07 UTC (permalink / raw) To: mkubecek, netdev Cc: andrew, davem, hkallweit1, devicetree, mark.rutland, linux-kernel, f.fainelli, robh+dt On Tue, 2019-09-10 at 10:00 +0200, Michal Kubecek wrote: > [External] > > On Mon, Sep 09, 2019 at 04:12:50PM +0300, Alexandru Ardelean wrote: > > The `phy_tunable_id` has been named `ETHTOOL_PHY_EDPD` since it looks like > > this feature is common across other PHYs (like EEE), and defining > > `ETHTOOL_PHY_ENERGY_DETECT_POWER_DOWN` seems too long. > > > > The way EDPD works, is that the RX block is put to a lower power mode, > > except for link-pulse detection circuits. The TX block is also put to low > > power mode, but the PHY wakes-up periodically to send link pulses, to avoid > > lock-ups in case the other side is also in EDPD mode. > > > > Currently, there are 2 PHY drivers that look like they could use this new > > PHY tunable feature: the `adin` && `micrel` PHYs. > > > > The ADIN's datasheet mentions that TX pulses are at intervals of 1 second > > default each, and they can be disabled. For the Micrel KSZ9031 PHY, the > > datasheet does not mention whether they can be disabled, but mentions that > > they can modified. > > > > The way this change is structured, is similar to the PHY tunable downshift > > control: > > * a `ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL` value is exposed to cover a default > > TX interval; some PHYs could specify a certain value that makes sense > > * `ETHTOOL_PHY_EDPD_NO_TX` would disable TX when EDPD is enabled > > * `ETHTOOL_PHY_EDPD_DISABLE` will disable EDPD > > > > This should allow PHYs to: > > * enable EDPD and not enable TX pulses (interval would be 0) > > * enable EDPD and configure TX pulse interval; note that TX interval units > > would be PHY specific; we could consider `seconds` as units, but it could > > happen that some PHYs would be prefer milliseconds as a unit; > > a maximum of 65533 units should be sufficient > > Sorry for missing the discussion on previous version but I don't really > like the idea of leaving the choice of units to PHY. Both for manual > setting and system configuration, it would be IMHO much more convenient > to have the interpretation universal for all NICs. > I was also a bit uncertain/undecided here about letting PHYs decide units. And I also wasn't sure what to propose. Not proposing a unit now, would have allowed us to decide later based on what PHYs implement (generally) in the future. I know that may make me look a bit lazy [for not proposing units in ethtool], but tbh it's more of lack-of-experience with ethtool (or these APIs) evolve over time. > Seconds as units seem too coarse and maximum of ~18 hours way too big. > Milliseconds would be more practical from granularity point of view, > would maximum of ~65 seconds be sufficient? I think 65 seconds is more than enough. I feel that, if you plug-in an eth cable and don't have a link in a minute, then it's not great (no matter how much of a power-saver you are). Actually, voicing out these units makes it simpler for a decision to go in favor for milliseconds. So: thank you :) Alex > > Michal Kubecek > > > * disable EDPD > > > > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] net: phy: adin: implement Energy Detect Powerdown mode via phy-tunable 2019-09-09 13:12 [PATCH v3 0/2] ethtool: implement Energy Detect Powerdown support via phy-tunable Alexandru Ardelean 2019-09-09 13:12 ` [PATCH v3 1/2] " Alexandru Ardelean @ 2019-09-09 13:12 ` Alexandru Ardelean 1 sibling, 0 replies; 5+ messages in thread From: Alexandru Ardelean @ 2019-09-09 13:12 UTC (permalink / raw) To: netdev, devicetree, linux-kernel Cc: davem, robh+dt, mark.rutland, f.fainelli, hkallweit1, andrew, Alexandru Ardelean This driver becomes the first user of the kernel's `ETHTOOL_PHY_EDPD` phy-tunable feature. EDPD is also enabled by default on PHY config_init, but can be disabled via the phy-tunable control. When enabling EDPD, it's also a good idea (for the ADIN PHYs) to enable TX periodic pulses, so that in case the other PHY is also on EDPD mode, there is no lock-up situation where both sides are waiting for the other to transmit. Via the phy-tunable control, TX pulses can be disabled if specifying 0 `tx-interval` via ethtool. The ADIN PHY supports only fixed 1 second intervals; they cannot be configured. That is why the acceptable values are 1, ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL and ETHTOOL_PHY_EDPD_NO_TX (which disables TX pulses). Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> --- drivers/net/phy/adin.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c index 4dec83df048d..5f5f73a58122 100644 --- a/drivers/net/phy/adin.c +++ b/drivers/net/phy/adin.c @@ -26,6 +26,11 @@ #define ADIN1300_RX_ERR_CNT 0x0014 +#define ADIN1300_PHY_CTRL_STATUS2 0x0015 +#define ADIN1300_NRG_PD_EN BIT(3) +#define ADIN1300_NRG_PD_TX_EN BIT(2) +#define ADIN1300_NRG_PD_STATUS BIT(1) + #define ADIN1300_PHY_CTRL2 0x0016 #define ADIN1300_DOWNSPEED_AN_100_EN BIT(11) #define ADIN1300_DOWNSPEED_AN_10_EN BIT(10) @@ -328,12 +333,62 @@ static int adin_set_downshift(struct phy_device *phydev, u8 cnt) ADIN1300_DOWNSPEEDS_EN); } +static int adin_get_edpd(struct phy_device *phydev, u16 *tx_interval) +{ + int val; + + val = phy_read(phydev, ADIN1300_PHY_CTRL_STATUS2); + if (val < 0) + return val; + + if (ADIN1300_NRG_PD_EN & val) { + if (val & ADIN1300_NRG_PD_TX_EN) + /* default is 1 second */ + *tx_interval = ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL; + else + *tx_interval = ETHTOOL_PHY_EDPD_NO_TX; + } else { + *tx_interval = ETHTOOL_PHY_EDPD_DISABLE; + } + + return 0; +} + +static int adin_set_edpd(struct phy_device *phydev, u16 tx_interval) +{ + u16 val; + + if (tx_interval == ETHTOOL_PHY_EDPD_DISABLE) + return phy_clear_bits(phydev, ADIN1300_PHY_CTRL_STATUS2, + (ADIN1300_NRG_PD_EN | ADIN1300_NRG_PD_TX_EN)); + + val = ADIN1300_NRG_PD_EN; + + switch (tx_interval) { + case 1: /* second */ + /* fallthrough */ + case ETHTOOL_PHY_EDPD_DFLT_TX_INTERVAL: + val |= ADIN1300_NRG_PD_TX_EN; + /* fallthrough */ + case ETHTOOL_PHY_EDPD_NO_TX: + break; + default: + return -EINVAL; + } + + return phy_modify(phydev, ADIN1300_PHY_CTRL_STATUS2, + (ADIN1300_NRG_PD_EN | ADIN1300_NRG_PD_TX_EN), + val); +} + static int adin_get_tunable(struct phy_device *phydev, struct ethtool_tunable *tuna, void *data) { switch (tuna->id) { case ETHTOOL_PHY_DOWNSHIFT: return adin_get_downshift(phydev, data); + case ETHTOOL_PHY_EDPD: + return adin_get_edpd(phydev, data); default: return -EOPNOTSUPP; } @@ -345,6 +400,8 @@ static int adin_set_tunable(struct phy_device *phydev, switch (tuna->id) { case ETHTOOL_PHY_DOWNSHIFT: return adin_set_downshift(phydev, *(const u8 *)data); + case ETHTOOL_PHY_EDPD: + return adin_set_edpd(phydev, *(const u16 *)data); default: return -EOPNOTSUPP; } @@ -368,6 +425,10 @@ static int adin_config_init(struct phy_device *phydev) if (rc < 0) return rc; + rc = adin_set_edpd(phydev, 1); + if (rc < 0) + return rc; + phydev_dbg(phydev, "PHY is using mode '%s'\n", phy_modes(phydev->interface)); -- 2.20.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-09-10 12:08 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-09-09 13:12 [PATCH v3 0/2] ethtool: implement Energy Detect Powerdown support via phy-tunable Alexandru Ardelean 2019-09-09 13:12 ` [PATCH v3 1/2] " Alexandru Ardelean 2019-09-10 8:00 ` Michal Kubecek 2019-09-10 12:07 ` Ardelean, Alexandru 2019-09-09 13:12 ` [PATCH v3 2/2] net: phy: adin: implement Energy Detect Powerdown mode " Alexandru Ardelean
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).