@@ -652,42 +652,10 @@ static const struct phylink_pcs_ops macb_phylink_pcs_ops = {
static void macb_mac_config(struct phylink_config *config, unsigned int mode,
const struct phylink_link_state *state)
{
- struct net_device *ndev = to_net_dev(config->dev);
- struct macb *bp = netdev_priv(ndev);
unsigned long flags;
- u32 old_ctrl, ctrl;
- u32 old_ncr, ncr;
spin_lock_irqsave(&bp->lock, flags);
- old_ctrl = ctrl = macb_or_gem_readl(bp, NCFGR);
- old_ncr = ncr = macb_or_gem_readl(bp, NCR);
-
- if (bp->caps & MACB_CAPS_MACB_IS_EMAC) {
- if (state->interface == PHY_INTERFACE_MODE_RMII)
- ctrl |= MACB_BIT(RM9200_RMII);
- } else if (macb_is_gem(bp)) {
- ctrl &= ~(GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL));
- ncr &= ~GEM_BIT(ENABLE_HS_MAC);
-
- if (state->interface == PHY_INTERFACE_MODE_SGMII) {
- ctrl |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL);
- } else if (state->interface == PHY_INTERFACE_MODE_10GBASER) {
- ctrl |= GEM_BIT(PCSSEL);
- ncr |= GEM_BIT(ENABLE_HS_MAC);
- } else if (bp->caps & MACB_CAPS_MIIONRGMII &&
- bp->phy_interface == PHY_INTERFACE_MODE_MII) {
- ncr |= MACB_BIT(MIIONRGMII);
- }
- }
-
- /* Apply the new configuration, if any */
- if (old_ctrl ^ ctrl)
- macb_or_gem_writel(bp, NCFGR, ctrl);
-
- if (old_ncr ^ ncr)
- macb_or_gem_writel(bp, NCR, ncr);
-
/* Disable AN for SGMII fixed link configuration, enable otherwise.
* Must be written after PCSSEL is set in NCFGR,
* otherwise writes will not take effect.
@@ -797,6 +765,9 @@ static int macb_mac_prepare(struct phylink_config *config, unsigned int mode,
{
struct net_device *ndev = to_net_dev(config->dev);
struct macb *bp = netdev_priv(ndev);
+ unsigned long flags;
+ u32 old_ctrl, ctrl;
+ u32 old_ncr, ncr;
if (interface == PHY_INTERFACE_MODE_10GBASER)
bp->phylink_pcs.ops = &macb_phylink_usx_pcs_ops;
@@ -808,6 +779,38 @@ static int macb_mac_prepare(struct phylink_config *config, unsigned int mode,
if (bp->phylink_pcs.ops)
phylink_set_pcs(bp->phylink, &bp->phylink_pcs);
+ spin_lock_irqsave(&bp->lock, flags);
+
+ old_ctrl = ctrl = macb_or_gem_readl(bp, NCFGR);
+ old_ncr = ncr = macb_or_gem_readl(bp, NCR);
+
+ if (bp->caps & MACB_CAPS_MACB_IS_EMAC) {
+ if (interface == PHY_INTERFACE_MODE_RMII)
+ ctrl |= MACB_BIT(RM9200_RMII);
+ } else if (macb_is_gem(bp)) {
+ ctrl &= ~(GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL));
+ ncr &= ~GEM_BIT(ENABLE_HS_MAC);
+
+ if (state->interface == PHY_INTERFACE_MODE_SGMII) {
+ ctrl |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL);
+ } else if (state->interface == PHY_INTERFACE_MODE_10GBASER) {
+ ctrl |= GEM_BIT(PCSSEL);
+ ncr |= GEM_BIT(ENABLE_HS_MAC);
+ } else if (bp->caps & MACB_CAPS_MIIONRGMII &&
+ bp->phy_interface == PHY_INTERFACE_MODE_MII) {
+ ncr |= MACB_BIT(MIIONRGMII);
+ }
+ }
+
+ /* Apply the new configuration, if any */
+ if (old_ctrl ^ ctrl)
+ macb_or_gem_writel(bp, NCFGR, ctrl);
+
+ if (old_ncr ^ ncr)
+ macb_or_gem_writel(bp, NCR, ncr);
+
+ spin_unlock_irqrestore(&bp->lock, flags);
+
return 0;
}
mac_prepare is called every time the interface is changed, so we can do all of our configuration there, instead of in mac_config. This will be useful for the next patch where we will set the PCS bit based on whether we are using our internal PCS. No functional change intended. Signed-off-by: Sean Anderson <sean.anderson@seco.com> --- drivers/net/ethernet/cadence/macb_main.c | 67 +++++++++++++----------- 1 file changed, 35 insertions(+), 32 deletions(-)