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

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: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ben Hutchings and committed by
David S. Miller
356eebb2 04300d24

+32 -59
+28 -59
drivers/net/sfc/mdio_10g.c
··· 205 205 206 206 void mdio_clause45_transmit_disable(struct efx_nic *efx) 207 207 { 208 - int phy_id = efx->mii.phy_id; 209 - int ctrl1, ctrl2; 210 - 211 - ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD, 212 - MDIO_MMDREG_TXDIS); 213 - if (efx->phy_mode & PHY_MODE_TX_DISABLED) 214 - ctrl2 |= (1 << MDIO_MMDREG_TXDIS_GLOBAL_LBN); 215 - else 216 - ctrl1 &= ~(1 << MDIO_MMDREG_TXDIS_GLOBAL_LBN); 217 - if (ctrl1 != ctrl2) 218 - mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD, 219 - MDIO_MMDREG_TXDIS, ctrl2); 208 + mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, 209 + MDIO_MMDREG_TXDIS, MDIO_MMDREG_TXDIS_GLOBAL_LBN, 210 + efx->phy_mode & PHY_MODE_TX_DISABLED); 220 211 } 221 212 222 213 void mdio_clause45_phy_reconfigure(struct efx_nic *efx) 223 214 { 224 215 int phy_id = efx->mii.phy_id; 225 - int ctrl1, ctrl2; 226 216 227 - /* Handle (with debouncing) PMA/PMD loopback */ 228 - ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD, 229 - MDIO_MMDREG_CTRL1); 230 - 231 - if (efx->loopback_mode == LOOPBACK_PMAPMD) 232 - ctrl2 |= (1 << MDIO_PMAPMD_CTRL1_LBACK_LBN); 233 - else 234 - ctrl2 &= ~(1 << MDIO_PMAPMD_CTRL1_LBACK_LBN); 235 - 236 - if (ctrl1 != ctrl2) 237 - mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD, 238 - MDIO_MMDREG_CTRL1, ctrl2); 239 - 240 - /* Handle (with debouncing) PCS loopback */ 241 - ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PCS, 242 - MDIO_MMDREG_CTRL1); 243 - if (efx->loopback_mode == LOOPBACK_PCS) 244 - ctrl2 |= (1 << MDIO_MMDREG_CTRL1_LBACK_LBN); 245 - else 246 - ctrl2 &= ~(1 << MDIO_MMDREG_CTRL1_LBACK_LBN); 247 - 248 - if (ctrl1 != ctrl2) 249 - mdio_clause45_write(efx, phy_id, MDIO_MMD_PCS, 250 - MDIO_MMDREG_CTRL1, ctrl2); 251 - 252 - /* Handle (with debouncing) PHYXS network loopback */ 253 - ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PHYXS, 254 - MDIO_MMDREG_CTRL1); 255 - if (efx->loopback_mode == LOOPBACK_NETWORK) 256 - ctrl2 |= (1 << MDIO_MMDREG_CTRL1_LBACK_LBN); 257 - else 258 - ctrl2 &= ~(1 << MDIO_MMDREG_CTRL1_LBACK_LBN); 259 - 260 - if (ctrl1 != ctrl2) 261 - mdio_clause45_write(efx, phy_id, MDIO_MMD_PHYXS, 262 - MDIO_MMDREG_CTRL1, ctrl2); 217 + mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PMAPMD, 218 + MDIO_MMDREG_CTRL1, MDIO_PMAPMD_CTRL1_LBACK_LBN, 219 + efx->loopback_mode == LOOPBACK_PMAPMD); 220 + mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PCS, 221 + MDIO_MMDREG_CTRL1, MDIO_MMDREG_CTRL1_LBACK_LBN, 222 + efx->loopback_mode == LOOPBACK_PCS); 223 + mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS, 224 + MDIO_MMDREG_CTRL1, MDIO_MMDREG_CTRL1_LBACK_LBN, 225 + efx->loopback_mode == LOOPBACK_NETWORK); 263 226 } 264 227 265 228 static void mdio_clause45_set_mmd_lpower(struct efx_nic *efx, ··· 230 267 { 231 268 int phy = efx->mii.phy_id; 232 269 int stat = mdio_clause45_read(efx, phy, mmd, MDIO_MMDREG_STAT1); 233 - int ctrl1, ctrl2; 234 270 235 271 EFX_TRACE(efx, "Setting low power mode for MMD %d to %d\n", 236 272 mmd, lpower); 237 273 238 274 if (stat & (1 << MDIO_MMDREG_STAT1_LPABLE_LBN)) { 239 - ctrl1 = ctrl2 = mdio_clause45_read(efx, phy, 240 - mmd, MDIO_MMDREG_CTRL1); 241 - if (lpower) 242 - ctrl2 |= (1 << MDIO_MMDREG_CTRL1_LPOWER_LBN); 243 - else 244 - ctrl2 &= ~(1 << MDIO_MMDREG_CTRL1_LPOWER_LBN); 245 - if (ctrl1 != ctrl2) 246 - mdio_clause45_write(efx, phy, mmd, 247 - MDIO_MMDREG_CTRL1, ctrl2); 275 + mdio_clause45_set_flag(efx, phy, mmd, MDIO_MMDREG_CTRL1, 276 + MDIO_MMDREG_CTRL1_LPOWER_LBN, lpower); 248 277 } 249 278 } 250 279 ··· 349 394 (ecmd->advertising == tmpcmd.advertising)) 350 395 return 0; 351 396 return -EOPNOTSUPP; 397 + } 398 + 399 + void mdio_clause45_set_flag(struct efx_nic *efx, u8 prt, u8 dev, 400 + u16 addr, int bit, bool sense) 401 + { 402 + int old_val = mdio_clause45_read(efx, prt, dev, addr); 403 + int new_val; 404 + 405 + if (sense) 406 + new_val = old_val | (1 << bit); 407 + else 408 + new_val = old_val & ~(1 << bit); 409 + if (old_val != new_val) 410 + mdio_clause45_write(efx, prt, dev, addr, new_val); 352 411 }
+4
drivers/net/sfc/mdio_10g.h
··· 259 259 extern int mdio_clause45_wait_reset_mmds(struct efx_nic *efx, 260 260 unsigned int mmd_mask); 261 261 262 + /* Set or clear flag, debouncing */ 263 + extern void mdio_clause45_set_flag(struct efx_nic *efx, u8 prt, u8 dev, 264 + u16 addr, int bit, bool sense); 265 + 262 266 #endif /* EFX_MDIO_10G_H */