Commit 629cb919 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'introduce-read_poll_timeout'



Dejin Zheng says:

====================
introduce read_poll_timeout

This patch sets is introduce read_poll_timeout macro, it is an extension
of readx_poll_timeout macro. the accessor function op just supports only
one parameter in the readx_poll_timeout macro, but this macro can
supports multiple variable parameters for it. so functions like
phy_read(struct phy_device *phydev, u32 regnum) and
phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum) can
use this poll timeout framework.

the first patch introduce read_poll_timeout macro, and the second patch
redefined readx_poll_timeout macro by read_poll_timeout(), and the other
patches are examples using read_poll_timeout macro.

v6 -> v7:
	- add a parameter to supports that it can sleep some time
	  before read operation in read_poll_timeout macro.
	- add prefix with double underscores for some variable to avoid
	  any variable re-declaration or shadowing in patch 3 and patch
	  7.
v5 -> v6:
	- add some check to keep the code more similar in patch 8
v4 -> v5:
	- add some msleep() before call phy_read_mmd_poll_timeout() to
	  keep the code more similar in patch 6 and patch 9.
	- add a patch of drop by v4, it can add msleep before call
	  phy_read_poll_timeout() to keep the code more similar.
v3 -> v4:
	- add 3 examples of using new functions.
	- deal with precedence issues for parameter cond.
	- drop a patch about phy_poll_reset() function.
v2 -> v3:
	- modify the parameter order of newly added functions.
	  phy_read_mmd_poll_timeout(val, cond, sleep_us, timeout_us, \
				     phydev, devaddr, regnum)
				||
				\/
	  phy_read_mmd_poll_timeout(phydev, devaddr regnum, val, cond, \
				    sleep_us, timeout_us)

	  phy_read_poll_timeout(val, cond, sleep_us, timeout_us, \
				phydev, regnum)
				||
				\/
	  phy_read_poll_timeout(phydev, regnum, val, cond, sleep_us, \
				timeout_us)
v1 -> v2:
	- passed a phydev, device address and a reg to replace args...
	  parameter in phy_read_mmd_poll_timeout() by Andrew Lunn 's
	  suggestion in patch 3. Andrew Lunn <andrew@lunn.ch>, Thanks
	  very much for your help!
	- also in patch 3, handle phy_read_mmd return an error(the return
	  value < 0) in phy_read_mmd_poll_timeout(). Thanks Andrew
	  again.
	- in patch 6, pass a phydev and a reg to replace args...
	  parameter in phy_read_poll_timeout(), and also handle the
	  phy_read() function's return error.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents af13b3c3 704f691a
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -434,16 +434,11 @@ static int aqr107_set_tunable(struct phy_device *phydev,
 */
static int aqr107_wait_reset_complete(struct phy_device *phydev)
{
	int val, retries = 100;

	do {
		val = phy_read_mmd(phydev, MDIO_MMD_VEND1, VEND1_GLOBAL_FW_ID);
		if (val < 0)
			return val;
		msleep(20);
	} while (!val && --retries);
	int val;

	return val ? 0 : -ETIMEDOUT;
	return phy_read_mmd_poll_timeout(phydev, MDIO_MMD_VEND1,
					 VEND1_GLOBAL_FW_ID, val, val != 0,
					 20000, 2000000, false);
}

static void aqr107_chip_info(struct phy_device *phydev)
+4 −23
Original line number Diff line number Diff line
@@ -22,30 +22,11 @@ enum {

static int bcm84881_wait_init(struct phy_device *phydev)
{
	unsigned int tries = 20;
	int ret, val;
	int val;

	do {
		val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_CTRL1);
		if (val < 0) {
			ret = val;
			break;
		}
		if (!(val & MDIO_CTRL1_RESET)) {
			ret = 0;
			break;
		}
		if (!--tries) {
			ret = -ETIMEDOUT;
			break;
		}
		msleep(100);
	} while (1);

	if (ret)
		phydev_err(phydev, "%s failed: %d\n", __func__, ret);

	return ret;
	return phy_read_mmd_poll_timeout(phydev, MDIO_MMD_PMAPMD, MDIO_CTRL1,
					 val, !(val & MDIO_CTRL1_RESET),
					 100000, 2000000, false);
}

static int bcm84881_config_init(struct phy_device *phydev)
+5 −10
Original line number Diff line number Diff line
@@ -241,22 +241,17 @@ static int mv3310_power_up(struct phy_device *phydev)

static int mv3310_reset(struct phy_device *phydev, u32 unit)
{
	int retries, val, err;
	int val, err;

	err = phy_modify_mmd(phydev, MDIO_MMD_PCS, unit + MDIO_CTRL1,
			     MDIO_CTRL1_RESET, MDIO_CTRL1_RESET);
	if (err < 0)
		return err;

	retries = 20;
	do {
		msleep(5);
		val = phy_read_mmd(phydev, MDIO_MMD_PCS, unit + MDIO_CTRL1);
		if (val < 0)
			return val;
	} while (val & MDIO_CTRL1_RESET && --retries);

	return val & MDIO_CTRL1_RESET ? -ETIMEDOUT : 0;
	return phy_read_mmd_poll_timeout(phydev, MDIO_MMD_PCS,
					 unit + MDIO_CTRL1, val,
					 !(val & MDIO_CTRL1_RESET),
					 5000, 100000, true);
}

static int mv3310_get_edpd(struct phy_device *phydev, u16 *edpd)
+3 −13
Original line number Diff line number Diff line
@@ -72,20 +72,10 @@ static struct tja11xx_phy_stats tja11xx_hw_stats[] = {

static int tja11xx_check(struct phy_device *phydev, u8 reg, u16 mask, u16 set)
{
	int i, ret;

	for (i = 0; i < 200; i++) {
		ret = phy_read(phydev, reg);
		if (ret < 0)
			return ret;

		if ((ret & mask) == set)
			return 0;

		usleep_range(100, 150);
	}
	int val;

	return -ETIMEDOUT;
	return phy_read_poll_timeout(phydev, reg, val, (val & mask) == set,
				     150, 30000, false);
}

static int phy_modify_check(struct phy_device *phydev, u8 reg,
+5 −11
Original line number Diff line number Diff line
@@ -1059,18 +1059,12 @@ EXPORT_SYMBOL(phy_disconnect);
static int phy_poll_reset(struct phy_device *phydev)
{
	/* Poll until the reset bit clears (50ms per retry == 0.6 sec) */
	unsigned int retries = 12;
	int ret;
	int ret, val;

	do {
		msleep(50);
		ret = phy_read(phydev, MII_BMCR);
		if (ret < 0)
	ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET),
				    50000, 600000, true);
	if (ret)
		return ret;
	} while (ret & BMCR_RESET && --retries);
	if (ret & BMCR_RESET)
		return -ETIMEDOUT;

	/* Some chips (smsc911x) may still need up to another 1ms after the
	 * BMCR_RESET bit is cleared before they are usable.
	 */
Loading