Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: phy: smsc: add support for edpd tunable

This adds support for the EDPD PHY tunable.
Per default EDPD is disabled in interrupt mode, the tunable can be used
to override this, e.g. if the link partner doesn't use EDPD.
The interval to check for energy can be chosen between 1000ms and
2000ms. Note that this value consists of the 1000ms phylib interval
for state machine runs plus the time to wait for energy being detected.

v2:
- consider that phylib core holds phydev->lock when calling the
phy tunable hooks

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Heiner Kallweit and committed by
David S. Miller
657de1cf 1ce65869

+79
+75
drivers/net/phy/smsc.c
··· 34 34 #define SPECIAL_CTRL_STS_AMDIX_STATE_ 0x2000 35 35 36 36 #define EDPD_MAX_WAIT_DFLT_MS 640 37 + /* interval between phylib state machine runs in ms */ 38 + #define PHY_STATE_MACH_MS 1000 37 39 38 40 struct smsc_hw_stat { 39 41 const char *string; ··· 296 294 for (i = 0; i < ARRAY_SIZE(smsc_hw_stats); i++) 297 295 data[i] = smsc_get_stat(phydev, i); 298 296 } 297 + 298 + static int smsc_phy_get_edpd(struct phy_device *phydev, u16 *edpd) 299 + { 300 + struct smsc_phy_priv *priv = phydev->priv; 301 + 302 + if (!priv) 303 + return -EOPNOTSUPP; 304 + 305 + if (!priv->edpd_enable) 306 + *edpd = ETHTOOL_PHY_EDPD_DISABLE; 307 + else if (!priv->edpd_max_wait_ms) 308 + *edpd = ETHTOOL_PHY_EDPD_NO_TX; 309 + else 310 + *edpd = PHY_STATE_MACH_MS + priv->edpd_max_wait_ms; 311 + 312 + return 0; 313 + } 314 + 315 + static int smsc_phy_set_edpd(struct phy_device *phydev, u16 edpd) 316 + { 317 + struct smsc_phy_priv *priv = phydev->priv; 318 + 319 + if (!priv) 320 + return -EOPNOTSUPP; 321 + 322 + switch (edpd) { 323 + case ETHTOOL_PHY_EDPD_DISABLE: 324 + priv->edpd_enable = false; 325 + break; 326 + case ETHTOOL_PHY_EDPD_NO_TX: 327 + priv->edpd_enable = true; 328 + priv->edpd_max_wait_ms = 0; 329 + break; 330 + case ETHTOOL_PHY_EDPD_DFLT_TX_MSECS: 331 + edpd = PHY_STATE_MACH_MS + EDPD_MAX_WAIT_DFLT_MS; 332 + fallthrough; 333 + default: 334 + if (phydev->irq != PHY_POLL) 335 + return -EOPNOTSUPP; 336 + if (edpd < PHY_STATE_MACH_MS || edpd > PHY_STATE_MACH_MS + 1000) 337 + return -EINVAL; 338 + priv->edpd_enable = true; 339 + priv->edpd_max_wait_ms = edpd - PHY_STATE_MACH_MS; 340 + } 341 + 342 + priv->edpd_mode_set_by_user = true; 343 + 344 + return smsc_phy_config_edpd(phydev); 345 + } 346 + 347 + int smsc_phy_get_tunable(struct phy_device *phydev, 348 + struct ethtool_tunable *tuna, void *data) 349 + { 350 + switch (tuna->id) { 351 + case ETHTOOL_PHY_EDPD: 352 + return smsc_phy_get_edpd(phydev, data); 353 + default: 354 + return -EOPNOTSUPP; 355 + } 356 + } 357 + EXPORT_SYMBOL_GPL(smsc_phy_get_tunable); 358 + 359 + int smsc_phy_set_tunable(struct phy_device *phydev, 360 + struct ethtool_tunable *tuna, const void *data) 361 + { 362 + switch (tuna->id) { 363 + case ETHTOOL_PHY_EDPD: 364 + return smsc_phy_set_edpd(phydev, *(u16 *)data); 365 + default: 366 + return -EOPNOTSUPP; 367 + } 368 + } 369 + EXPORT_SYMBOL_GPL(smsc_phy_set_tunable); 299 370 300 371 int smsc_phy_probe(struct phy_device *phydev) 301 372 {
+4
include/linux/smscphy.h
··· 32 32 irqreturn_t smsc_phy_handle_interrupt(struct phy_device *phydev); 33 33 int smsc_phy_config_init(struct phy_device *phydev); 34 34 int lan87xx_read_status(struct phy_device *phydev); 35 + int smsc_phy_get_tunable(struct phy_device *phydev, 36 + struct ethtool_tunable *tuna, void *data); 37 + int smsc_phy_set_tunable(struct phy_device *phydev, 38 + struct ethtool_tunable *tuna, const void *data); 35 39 int smsc_phy_probe(struct phy_device *phydev); 36 40 37 41 #endif /* __LINUX_SMSCPHY_H__ */