Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 356eebb2 authored by Ben Hutchings's avatar Ben Hutchings Committed by David S. Miller
Browse files

sfc: Clean up MDIO flag setting



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: default avatarBen Hutchings <bhutchings@solarflare.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 04300d24
Loading
Loading
Loading
Loading
+28 −59
Original line number Original line Diff line number Diff line
@@ -205,61 +205,24 @@ bool mdio_clause45_links_ok(struct efx_nic *efx, unsigned int mmd_mask)


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

			       efx->phy_mode & PHY_MODE_TX_DISABLED);
	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);
}
}


void mdio_clause45_phy_reconfigure(struct efx_nic *efx)
void mdio_clause45_phy_reconfigure(struct efx_nic *efx)
{
{
	int phy_id = efx->mii.phy_id;
	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_set_flag(efx, phy_id, MDIO_MMD_PMAPMD,
		mdio_clause45_write(efx, phy_id, MDIO_MMD_PCS,
			       MDIO_MMDREG_CTRL1, MDIO_PMAPMD_CTRL1_LBACK_LBN,
				    MDIO_MMDREG_CTRL1, ctrl2);
			       efx->loopback_mode == LOOPBACK_PMAPMD);

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

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


static void mdio_clause45_set_mmd_lpower(struct efx_nic *efx,
static void mdio_clause45_set_mmd_lpower(struct efx_nic *efx,
@@ -267,21 +230,13 @@ static void mdio_clause45_set_mmd_lpower(struct efx_nic *efx,
{
{
	int phy = efx->mii.phy_id;
	int phy = efx->mii.phy_id;
	int stat = mdio_clause45_read(efx, phy, mmd, MDIO_MMDREG_STAT1);
	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",
	EFX_TRACE(efx, "Setting low power mode for MMD %d to %d\n",
		  mmd, lpower);
		  mmd, lpower);


	if (stat & (1 << MDIO_MMDREG_STAT1_LPABLE_LBN)) {
	if (stat & (1 << MDIO_MMDREG_STAT1_LPABLE_LBN)) {
		ctrl1 = ctrl2 = mdio_clause45_read(efx, phy,
		mdio_clause45_set_flag(efx, phy, mmd, MDIO_MMDREG_CTRL1,
						   mmd, MDIO_MMDREG_CTRL1);
				       MDIO_MMDREG_CTRL1_LPOWER_LBN, lpower);
		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);
	}
	}
}
}


@@ -395,3 +350,17 @@ int mdio_clause45_set_settings(struct efx_nic *efx,
		return 0;
		return 0;
	return -EOPNOTSUPP;
	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 −0
Original line number Original line Diff line number Diff line
@@ -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,
extern int mdio_clause45_wait_reset_mmds(struct efx_nic *efx,
					 unsigned int mmd_mask);
					 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 */
#endif /* EFX_MDIO_10G_H */