Skip to content

Commit

Permalink
sfc: Clean up MDIO flag setting
Browse files Browse the repository at this point in the history
We often want to set or clear a flag in an MDIO register, but avoid
writing if no change is required since this can have side-effects.
Encapsulate this in a function, mdio_clause45_set_flag().

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ben Hutchings authored and David S. Miller committed Dec 13, 2008
1 parent 04300d2 commit 356eebb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 59 deletions.
87 changes: 28 additions & 59 deletions drivers/net/sfc/mdio_10g.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,83 +205,38 @@ bool mdio_clause45_links_ok(struct efx_nic *efx, unsigned int mmd_mask)

void mdio_clause45_transmit_disable(struct efx_nic *efx)
{
int phy_id = efx->mii.phy_id;
int ctrl1, ctrl2;

ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
MDIO_MMDREG_TXDIS);
if (efx->phy_mode & PHY_MODE_TX_DISABLED)
ctrl2 |= (1 << MDIO_MMDREG_TXDIS_GLOBAL_LBN);
else
ctrl1 &= ~(1 << MDIO_MMDREG_TXDIS_GLOBAL_LBN);
if (ctrl1 != ctrl2)
mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
MDIO_MMDREG_TXDIS, ctrl2);
mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
MDIO_MMDREG_TXDIS, MDIO_MMDREG_TXDIS_GLOBAL_LBN,
efx->phy_mode & PHY_MODE_TX_DISABLED);
}

void mdio_clause45_phy_reconfigure(struct efx_nic *efx)
{
int phy_id = efx->mii.phy_id;
int ctrl1, ctrl2;

/* Handle (with debouncing) PMA/PMD loopback */
ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
MDIO_MMDREG_CTRL1);

if (efx->loopback_mode == LOOPBACK_PMAPMD)
ctrl2 |= (1 << MDIO_PMAPMD_CTRL1_LBACK_LBN);
else
ctrl2 &= ~(1 << MDIO_PMAPMD_CTRL1_LBACK_LBN);

if (ctrl1 != ctrl2)
mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
MDIO_MMDREG_CTRL1, ctrl2);

/* Handle (with debouncing) PCS loopback */
ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PCS,
MDIO_MMDREG_CTRL1);
if (efx->loopback_mode == LOOPBACK_PCS)
ctrl2 |= (1 << MDIO_MMDREG_CTRL1_LBACK_LBN);
else
ctrl2 &= ~(1 << MDIO_MMDREG_CTRL1_LBACK_LBN);

if (ctrl1 != ctrl2)
mdio_clause45_write(efx, phy_id, MDIO_MMD_PCS,
MDIO_MMDREG_CTRL1, ctrl2);

/* Handle (with debouncing) PHYXS network loopback */
ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PHYXS,
MDIO_MMDREG_CTRL1);
if (efx->loopback_mode == LOOPBACK_NETWORK)
ctrl2 |= (1 << MDIO_MMDREG_CTRL1_LBACK_LBN);
else
ctrl2 &= ~(1 << MDIO_MMDREG_CTRL1_LBACK_LBN);

if (ctrl1 != ctrl2)
mdio_clause45_write(efx, phy_id, MDIO_MMD_PHYXS,
MDIO_MMDREG_CTRL1, ctrl2);
mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PMAPMD,
MDIO_MMDREG_CTRL1, MDIO_PMAPMD_CTRL1_LBACK_LBN,
efx->loopback_mode == LOOPBACK_PMAPMD);
mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PCS,
MDIO_MMDREG_CTRL1, MDIO_MMDREG_CTRL1_LBACK_LBN,
efx->loopback_mode == LOOPBACK_PCS);
mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS,
MDIO_MMDREG_CTRL1, MDIO_MMDREG_CTRL1_LBACK_LBN,
efx->loopback_mode == LOOPBACK_NETWORK);
}

static void mdio_clause45_set_mmd_lpower(struct efx_nic *efx,
int lpower, int mmd)
{
int phy = efx->mii.phy_id;
int stat = mdio_clause45_read(efx, phy, mmd, MDIO_MMDREG_STAT1);
int ctrl1, ctrl2;

EFX_TRACE(efx, "Setting low power mode for MMD %d to %d\n",
mmd, lpower);

if (stat & (1 << MDIO_MMDREG_STAT1_LPABLE_LBN)) {
ctrl1 = ctrl2 = mdio_clause45_read(efx, phy,
mmd, MDIO_MMDREG_CTRL1);
if (lpower)
ctrl2 |= (1 << MDIO_MMDREG_CTRL1_LPOWER_LBN);
else
ctrl2 &= ~(1 << MDIO_MMDREG_CTRL1_LPOWER_LBN);
if (ctrl1 != ctrl2)
mdio_clause45_write(efx, phy, mmd,
MDIO_MMDREG_CTRL1, ctrl2);
mdio_clause45_set_flag(efx, phy, mmd, MDIO_MMDREG_CTRL1,
MDIO_MMDREG_CTRL1_LPOWER_LBN, lpower);
}
}

Expand Down Expand Up @@ -395,3 +350,17 @@ int mdio_clause45_set_settings(struct efx_nic *efx,
return 0;
return -EOPNOTSUPP;
}

void mdio_clause45_set_flag(struct efx_nic *efx, u8 prt, u8 dev,
u16 addr, int bit, bool sense)
{
int old_val = mdio_clause45_read(efx, prt, dev, addr);
int new_val;

if (sense)
new_val = old_val | (1 << bit);
else
new_val = old_val & ~(1 << bit);
if (old_val != new_val)
mdio_clause45_write(efx, prt, dev, addr, new_val);
}
4 changes: 4 additions & 0 deletions drivers/net/sfc/mdio_10g.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,8 @@ extern int mdio_clause45_set_settings(struct efx_nic *efx,
extern int mdio_clause45_wait_reset_mmds(struct efx_nic *efx,
unsigned int mmd_mask);

/* Set or clear flag, debouncing */
extern void mdio_clause45_set_flag(struct efx_nic *efx, u8 prt, u8 dev,
u16 addr, int bit, bool sense);

#endif /* EFX_MDIO_10G_H */

0 comments on commit 356eebb

Please sign in to comment.