Commit f285604a authored by David S. Miller's avatar David S. Miller

Merge branch 'net-macb-convert-to-phylink'

Antoine Tenart says:

====================
net: macb: convert to phylink

This series converts the MACB Ethernet driver to the Phylink framework.
The MAC configuration is moved to the Phylink ops and Phylink helpers
are now used in the ethtools functions. This helps to access the flow
control and pauseparam logic and this will be helpful in the future for
boards using this controller with SFP cages.

Since v2:
  - Moved the Tx and Rx buffer initialization rework to its own patch.

Since v1:
  - Stopped using state->link in mac_config and moved macb_set_tx_clk to
    the link_up helper..
  - Fixed the node given to phylink_of_phy_connect.
  - Removed netif_carrier_off from macb_open.
  - Fixed the macb_get_wol logic.
  - Rewored macb_ioctl as suggested.
  - Added a call to phylink_destroy in macb_remove.
  - Fixed the suspend/resume case by calling phylink_start/stop in the
    resume/suspend helpers. I had to take the rtnl lock to do this,
    which might be something to discuss.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents d7eaf962 7897b071
...@@ -22,7 +22,7 @@ if NET_VENDOR_CADENCE ...@@ -22,7 +22,7 @@ if NET_VENDOR_CADENCE
config MACB config MACB
tristate "Cadence MACB/GEM support" tristate "Cadence MACB/GEM support"
depends on HAS_DMA && COMMON_CLK depends on HAS_DMA && COMMON_CLK
select PHYLIB select PHYLINK
---help--- ---help---
The Cadence MACB ethernet interface is found on many Atmel AT32 and The Cadence MACB ethernet interface is found on many Atmel AT32 and
AT91 parts. This driver also supports the Cadence GEM (Gigabit AT91 parts. This driver also supports the Cadence GEM (Gigabit
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef _MACB_H #ifndef _MACB_H
#define _MACB_H #define _MACB_H
#include <linux/phy.h> #include <linux/phylink.h>
#include <linux/ptp_clock_kernel.h> #include <linux/ptp_clock_kernel.h>
#include <linux/net_tstamp.h> #include <linux/net_tstamp.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -1185,15 +1185,14 @@ struct macb { ...@@ -1185,15 +1185,14 @@ struct macb {
struct macb_or_gem_ops macbgem_ops; struct macb_or_gem_ops macbgem_ops;
struct mii_bus *mii_bus; struct mii_bus *mii_bus;
struct device_node *phy_node; struct phylink *phylink;
int link; struct phylink_config phylink_config;
int speed;
int duplex;
u32 caps; u32 caps;
unsigned int dma_burst_length; unsigned int dma_burst_length;
phy_interface_t phy_interface; phy_interface_t phy_interface;
int speed;
/* AT91RM9200 transmit */ /* AT91RM9200 transmit */
struct sk_buff *skb; /* holds skb until xmit interrupt completes */ struct sk_buff *skb; /* holds skb until xmit interrupt completes */
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/platform_data/macb.h> #include <linux/platform_data/macb.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/phy.h> #include <linux/phylink.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
...@@ -388,6 +388,27 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum, ...@@ -388,6 +388,27 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
return status; return status;
} }
static void macb_init_buffers(struct macb *bp)
{
struct macb_queue *queue;
unsigned int q;
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma));
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
if (bp->hw_dma_cap & HW_DMA_CAP_64B)
queue_writel(queue, RBQPH,
upper_32_bits(queue->rx_ring_dma));
#endif
queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma));
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
if (bp->hw_dma_cap & HW_DMA_CAP_64B)
queue_writel(queue, TBQPH,
upper_32_bits(queue->tx_ring_dma));
#endif
}
}
/** /**
* macb_set_tx_clk() - Set a clock to a new frequency * macb_set_tx_clk() - Set a clock to a new frequency
* @clk Pointer to the clock to change * @clk Pointer to the clock to change
...@@ -432,114 +453,178 @@ static void macb_set_tx_clk(struct clk *clk, int speed, struct net_device *dev) ...@@ -432,114 +453,178 @@ static void macb_set_tx_clk(struct clk *clk, int speed, struct net_device *dev)
netdev_err(dev, "adjusting tx_clk failed.\n"); netdev_err(dev, "adjusting tx_clk failed.\n");
} }
static void macb_handle_link_change(struct net_device *dev) static void macb_validate(struct phylink_config *config,
unsigned long *supported,
struct phylink_link_state *state)
{ {
struct macb *bp = netdev_priv(dev); struct net_device *ndev = to_net_dev(config->dev);
struct phy_device *phydev = dev->phydev; __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
struct macb *bp = netdev_priv(ndev);
/* We only support MII, RMII, GMII, RGMII & SGMII. */
if (state->interface != PHY_INTERFACE_MODE_NA &&
state->interface != PHY_INTERFACE_MODE_MII &&
state->interface != PHY_INTERFACE_MODE_RMII &&
state->interface != PHY_INTERFACE_MODE_GMII &&
state->interface != PHY_INTERFACE_MODE_SGMII &&
!phy_interface_mode_is_rgmii(state->interface)) {
bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
return;
}
if (!macb_is_gem(bp) &&
(state->interface == PHY_INTERFACE_MODE_GMII ||
phy_interface_mode_is_rgmii(state->interface))) {
bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
return;
}
phylink_set_port_modes(mask);
phylink_set(mask, Autoneg);
phylink_set(mask, Asym_Pause);
phylink_set(mask, 10baseT_Half);
phylink_set(mask, 10baseT_Full);
phylink_set(mask, 100baseT_Half);
phylink_set(mask, 100baseT_Full);
if (bp->caps & MACB_CAPS_GIGABIT_MODE_AVAILABLE &&
(state->interface == PHY_INTERFACE_MODE_NA ||
state->interface == PHY_INTERFACE_MODE_GMII ||
state->interface == PHY_INTERFACE_MODE_SGMII ||
phy_interface_mode_is_rgmii(state->interface))) {
phylink_set(mask, 1000baseT_Full);
phylink_set(mask, 1000baseX_Full);
if (!(bp->caps & MACB_CAPS_NO_GIGABIT_HALF))
phylink_set(mask, 1000baseT_Half);
}
bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
bitmap_and(state->advertising, state->advertising, mask,
__ETHTOOL_LINK_MODE_MASK_NBITS);
}
static int macb_mac_link_state(struct phylink_config *config,
struct phylink_link_state *state)
{
return -EOPNOTSUPP;
}
static void macb_mac_an_restart(struct phylink_config *config)
{
/* Not supported */
}
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; unsigned long flags;
int status_change = 0; u32 old_ctrl, ctrl;
spin_lock_irqsave(&bp->lock, flags); spin_lock_irqsave(&bp->lock, flags);
if (phydev->link) { old_ctrl = ctrl = macb_or_gem_readl(bp, NCFGR);
if ((bp->speed != phydev->speed) ||
(bp->duplex != phydev->duplex)) {
u32 reg;
reg = macb_readl(bp, NCFGR); /* Clear all the bits we might set later */
reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD)); ctrl &= ~(GEM_BIT(GBE) | MACB_BIT(SPD) | MACB_BIT(FD) | MACB_BIT(PAE) |
if (macb_is_gem(bp)) GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL));
reg &= ~GEM_BIT(GBE);
if (phydev->duplex) if (state->speed == SPEED_1000)
reg |= MACB_BIT(FD); ctrl |= GEM_BIT(GBE);
if (phydev->speed == SPEED_100) else if (state->speed == SPEED_100)
reg |= MACB_BIT(SPD); ctrl |= MACB_BIT(SPD);
if (phydev->speed == SPEED_1000 &&
bp->caps & MACB_CAPS_GIGABIT_MODE_AVAILABLE)
reg |= GEM_BIT(GBE);
macb_or_gem_writel(bp, NCFGR, reg); if (state->duplex)
ctrl |= MACB_BIT(FD);
bp->speed = phydev->speed; /* We do not support MLO_PAUSE_RX yet */
bp->duplex = phydev->duplex; if (state->pause & MLO_PAUSE_TX)
status_change = 1; ctrl |= MACB_BIT(PAE);
}
}
if (phydev->link != bp->link) { if (state->interface == PHY_INTERFACE_MODE_SGMII)
if (!phydev->link) { ctrl |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL);
bp->speed = 0;
bp->duplex = -1;
}
bp->link = phydev->link;
status_change = 1; /* Apply the new configuration, if any */
} if (old_ctrl ^ ctrl)
macb_or_gem_writel(bp, NCFGR, ctrl);
bp->speed = state->speed;
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock_irqrestore(&bp->lock, flags);
}
if (status_change) { static void macb_mac_link_down(struct phylink_config *config, unsigned int mode,
if (phydev->link) { phy_interface_t interface)
/* Update the TX clock rate if and only if the link is {
* up and there has been a link change. struct net_device *ndev = to_net_dev(config->dev);
*/ struct macb *bp = netdev_priv(ndev);
macb_set_tx_clk(bp->tx_clk, phydev->speed, dev); struct macb_queue *queue;
unsigned int q;
u32 ctrl;
netif_carrier_on(dev); for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue)
netdev_info(dev, "link up (%d/%s)\n", queue_writel(queue, IDR,
phydev->speed, bp->rx_intr_mask | MACB_TX_INT_FLAGS | MACB_BIT(HRESP));
phydev->duplex == DUPLEX_FULL ?
"Full" : "Half"); /* Disable Rx and Tx */
} else { ctrl = macb_readl(bp, NCR) & ~(MACB_BIT(RE) | MACB_BIT(TE));
netif_carrier_off(dev); macb_writel(bp, NCR, ctrl);
netdev_info(dev, "link down\n");
} netif_tx_stop_all_queues(ndev);
}
} }
/* based on au1000_eth. c*/ static void macb_mac_link_up(struct phylink_config *config, unsigned int mode,
static int macb_mii_probe(struct net_device *dev) phy_interface_t interface, struct phy_device *phy)
{ {
struct macb *bp = netdev_priv(dev); struct net_device *ndev = to_net_dev(config->dev);
struct phy_device *phydev; struct macb *bp = netdev_priv(ndev);
struct device_node *np; struct macb_queue *queue;
int ret, i; unsigned int q;
np = bp->pdev->dev.of_node; macb_set_tx_clk(bp->tx_clk, bp->speed, ndev);
ret = 0;
if (np) { /* Initialize rings & buffers as clearing MACB_BIT(TE) in link down
if (of_phy_is_fixed_link(np)) { * cleared the pipeline and control registers.
bp->phy_node = of_node_get(np); */
} else { bp->macbgem_ops.mog_init_rings(bp);
bp->phy_node = of_parse_phandle(np, "phy-handle", 0); macb_init_buffers(bp);
/* fallback to standard phy registration if no
* phy-handle was found nor any phy found during
* dt phy registration
*/
if (!bp->phy_node && !phy_find_first(bp->mii_bus)) {
for (i = 0; i < PHY_MAX_ADDR; i++) {
phydev = mdiobus_scan(bp->mii_bus, i);
if (IS_ERR(phydev) &&
PTR_ERR(phydev) != -ENODEV) {
ret = PTR_ERR(phydev);
break;
}
}
if (ret) for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue)
return -ENODEV; queue_writel(queue, IER,
} bp->rx_intr_mask | MACB_TX_INT_FLAGS | MACB_BIT(HRESP));
}
} /* Enable Rx and Tx */
macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(RE) | MACB_BIT(TE));
if (bp->phy_node) { netif_tx_wake_all_queues(ndev);
phydev = of_phy_connect(dev, bp->phy_node, }
&macb_handle_link_change, 0,
bp->phy_interface); static const struct phylink_mac_ops macb_phylink_ops = {
if (!phydev) .validate = macb_validate,
return -ENODEV; .mac_link_state = macb_mac_link_state,
.mac_an_restart = macb_mac_an_restart,
.mac_config = macb_mac_config,
.mac_link_down = macb_mac_link_down,
.mac_link_up = macb_mac_link_up,
};
static int macb_phylink_connect(struct macb *bp)
{
struct net_device *dev = bp->dev;
struct phy_device *phydev;
int ret;
if (bp->pdev->dev.of_node &&
of_parse_phandle(bp->pdev->dev.of_node, "phy-handle", 0)) {
ret = phylink_of_phy_connect(bp->phylink, bp->pdev->dev.of_node,
0);
if (ret) {
netdev_err(dev, "Could not attach PHY (%d)\n", ret);
return ret;
}
} else { } else {
phydev = phy_find_first(bp->mii_bus); phydev = phy_find_first(bp->mii_bus);
if (!phydev) { if (!phydev) {
...@@ -548,27 +633,33 @@ static int macb_mii_probe(struct net_device *dev) ...@@ -548,27 +633,33 @@ static int macb_mii_probe(struct net_device *dev)
} }
/* attach the mac to the phy */ /* attach the mac to the phy */
ret = phy_connect_direct(dev, phydev, &macb_handle_link_change, ret = phylink_connect_phy(bp->phylink, phydev);
bp->phy_interface);
if (ret) { if (ret) {
netdev_err(dev, "Could not attach to PHY\n"); netdev_err(dev, "Could not attach to PHY (%d)\n", ret);
return ret; return ret;
} }
} }
/* mask with MAC supported features */ phylink_start(bp->phylink);
if (macb_is_gem(bp) && bp->caps & MACB_CAPS_GIGABIT_MODE_AVAILABLE)
phy_set_max_speed(phydev, SPEED_1000);
else
phy_set_max_speed(phydev, SPEED_100);
if (bp->caps & MACB_CAPS_NO_GIGABIT_HALF) return 0;
phy_remove_link_mode(phydev, }
ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
/* based on au1000_eth. c*/
static int macb_mii_probe(struct net_device *dev)
{
struct macb *bp = netdev_priv(dev);
bp->link = 0; bp->phylink_config.dev = &dev->dev;
bp->speed = 0; bp->phylink_config.type = PHYLINK_NETDEV;
bp->duplex = -1;
bp->phylink = phylink_create(&bp->phylink_config, bp->pdev->dev.fwnode,
bp->phy_interface, &macb_phylink_ops);
if (IS_ERR(bp->phylink)) {
netdev_err(dev, "Could not create a phylink instance (%ld)\n",
PTR_ERR(bp->phylink));
return PTR_ERR(bp->phylink);
}
return 0; return 0;
} }
...@@ -598,20 +689,10 @@ static int macb_mii_init(struct macb *bp) ...@@ -598,20 +689,10 @@ static int macb_mii_init(struct macb *bp)
dev_set_drvdata(&bp->dev->dev, bp->mii_bus); dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
np = bp->pdev->dev.of_node; np = bp->pdev->dev.of_node;
if (np && of_phy_is_fixed_link(np)) {
if (of_phy_register_fixed_link(np) < 0) {
dev_err(&bp->pdev->dev,
"broken fixed-link specification %pOF\n", np);
goto err_out_free_mdiobus;
}
err = mdiobus_register(bp->mii_bus);
} else {
err = of_mdiobus_register(bp->mii_bus, np);
}
err = of_mdiobus_register(bp->mii_bus, np);
if (err) if (err)
goto err_out_free_fixed_link; goto err_out_free_mdiobus;
err = macb_mii_probe(bp->dev); err = macb_mii_probe(bp->dev);
if (err) if (err)
...@@ -621,11 +702,7 @@ static int macb_mii_init(struct macb *bp) ...@@ -621,11 +702,7 @@ static int macb_mii_init(struct macb *bp)
err_out_unregister_bus: err_out_unregister_bus:
mdiobus_unregister(bp->mii_bus); mdiobus_unregister(bp->mii_bus);
err_out_free_fixed_link:
if (np && of_phy_is_fixed_link(np))
of_phy_deregister_fixed_link(np);
err_out_free_mdiobus: err_out_free_mdiobus:
of_node_put(bp->phy_node);
mdiobus_free(bp->mii_bus); mdiobus_free(bp->mii_bus);
err_out: err_out:
return err; return err;
...@@ -1314,26 +1391,14 @@ static void macb_hresp_error_task(unsigned long data) ...@@ -1314,26 +1391,14 @@ static void macb_hresp_error_task(unsigned long data)
bp->macbgem_ops.mog_init_rings(bp); bp->macbgem_ops.mog_init_rings(bp);
/* Initialize TX and RX buffers */ /* Initialize TX and RX buffers */
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { macb_init_buffers(bp);
queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma));
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
if (bp->hw_dma_cap & HW_DMA_CAP_64B)
queue_writel(queue, RBQPH,
upper_32_bits(queue->rx_ring_dma));
#endif
queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma));
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
if (bp->hw_dma_cap & HW_DMA_CAP_64B)
queue_writel(queue, TBQPH,
upper_32_bits(queue->tx_ring_dma));
#endif
/* Enable interrupts */ /* Enable interrupts */
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue)
queue_writel(queue, IER, queue_writel(queue, IER,
bp->rx_intr_mask | bp->rx_intr_mask |
MACB_TX_INT_FLAGS | MACB_TX_INT_FLAGS |
MACB_BIT(HRESP)); MACB_BIT(HRESP));
}
ctrl |= MACB_BIT(RE) | MACB_BIT(TE); ctrl |= MACB_BIT(RE) | MACB_BIT(TE);
macb_writel(bp, NCR, ctrl); macb_writel(bp, NCR, ctrl);
...@@ -2221,19 +2286,13 @@ static void macb_configure_dma(struct macb *bp) ...@@ -2221,19 +2286,13 @@ static void macb_configure_dma(struct macb *bp)
static void macb_init_hw(struct macb *bp) static void macb_init_hw(struct macb *bp)
{ {
struct macb_queue *queue;
unsigned int q;
u32 config; u32 config;
macb_reset_hw(bp); macb_reset_hw(bp);
macb_set_hwaddr(bp); macb_set_hwaddr(bp);
config = macb_mdc_clk_div(bp); config = macb_mdc_clk_div(bp);
if (bp->phy_interface == PHY_INTERFACE_MODE_SGMII)
config |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL);
config |= MACB_BF(RBOF, NET_IP_ALIGN); /* Make eth data aligned */ config |= MACB_BF(RBOF, NET_IP_ALIGN); /* Make eth data aligned */
config |= MACB_BIT(PAE); /* PAuse Enable */
config |= MACB_BIT(DRFCS); /* Discard Rx FCS */ config |= MACB_BIT(DRFCS); /* Discard Rx FCS */
if (bp->caps & MACB_CAPS_JUMBO) if (bp->caps & MACB_CAPS_JUMBO)
config |= MACB_BIT(JFRAME); /* Enable jumbo frames */ config |= MACB_BIT(JFRAME); /* Enable jumbo frames */
...@@ -2249,36 +2308,11 @@ static void macb_init_hw(struct macb *bp) ...@@ -2249,36 +2308,11 @@ static void macb_init_hw(struct macb *bp)
macb_writel(bp, NCFGR, config); macb_writel(bp, NCFGR, config);
if ((bp->caps & MACB_CAPS_JUMBO) && bp->jumbo_max_len) if ((bp->caps & MACB_CAPS_JUMBO) && bp->jumbo_max_len)
gem_writel(bp, JML, bp->jumbo_max_len); gem_writel(bp, JML, bp->jumbo_max_len);
bp->speed = SPEED_10;
bp->duplex = DUPLEX_HALF;
bp->rx_frm_len_mask = MACB_RX_FRMLEN_MASK; bp->rx_frm_len_mask = MACB_RX_FRMLEN_MASK;
if (bp->caps & MACB_CAPS_JUMBO) if (bp->caps & MACB_CAPS_JUMBO)
bp->rx_frm_len_mask = MACB_RX_JFRMLEN_MASK; bp->rx_frm_len_mask = MACB_RX_JFRMLEN_MASK;
macb_configure_dma(bp); macb_configure_dma(bp);
/* Initialize TX and RX buffers */
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma));
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
if (bp->hw_dma_cap & HW_DMA_CAP_64B)
queue_writel(queue, RBQPH, upper_32_bits(queue->rx_ring_dma));
#endif
queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma));
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
if (bp->hw_dma_cap & HW_DMA_CAP_64B)
queue_writel(queue, TBQPH, upper_32_bits(queue->tx_ring_dma));
#endif
/* Enable interrupts */
queue_writel(queue, IER,
bp->rx_intr_mask |
MACB_TX_INT_FLAGS |
MACB_BIT(HRESP));
}
/* Enable TX and RX */
macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(RE) | MACB_BIT(TE));
} }
/* The hash address register is 64 bits long and takes up two /* The hash address register is 64 bits long and takes up two
...@@ -2402,8 +2436,8 @@ static void macb_set_rx_mode(struct net_device *dev) ...@@ -2402,8 +2436,8 @@ static void macb_set_rx_mode(struct net_device *dev)
static int macb_open(struct net_device *dev) static int macb_open(struct net_device *dev)
{ {
struct macb *bp = netdev_priv(dev);
size_t bufsz = dev->mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN; size_t bufsz = dev->mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN;
struct macb *bp = netdev_priv(dev);
struct macb_queue *queue; struct macb_queue *queue;
unsigned int q; unsigned int q;
int err; int err;
...@@ -2414,15 +2448,6 @@ static int macb_open(struct net_device *dev) ...@@ -2414,15 +2448,6 @@ static int macb_open(struct net_device *dev)
if (err < 0) if (err < 0)
goto pm_exit; goto pm_exit;
/* carrier starts down */
netif_carrier_off(dev);
/* if the phy is not yet register, retry later*/
if (!dev->phydev) {
err = -EAGAIN;
goto pm_exit;
}
/* RX buffers initialization */ /* RX buffers initialization */
macb_init_rx_buffer_size(bp, bufsz); macb_init_rx_buffer_size(bp, bufsz);
...@@ -2436,11 +2461,11 @@ static int macb_open(struct net_device *dev) ...@@ -2436,11 +2461,11 @@ static int macb_open(struct net_device *dev)
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue)
napi_enable(&queue->napi); napi_enable(&queue->napi);
bp->macbgem_ops.mog_init_rings(bp);
macb_init_hw(bp); macb_init_hw(bp);
/* schedule a link state check */ err = macb_phylink_connect(bp);
phy_start(dev->phydev); if (err)
goto pm_exit;
netif_tx_start_all_queues(dev); netif_tx_start_all_queues(dev);
...@@ -2467,8 +2492,8 @@ static int macb_close(struct net_device *dev) ...@@ -2467,8 +2492,8 @@ static int macb_close(struct net_device *dev)
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue)
napi_disable(&queue->napi); napi_disable(&queue->napi);
if (dev->phydev) phylink_stop(bp->phylink);
phy_stop(dev->phydev); phylink_disconnect_phy(bp->phylink);
spin_lock_irqsave(&bp->lock, flags); spin_lock_irqsave(&bp->lock, flags);
macb_reset_hw(bp); macb_reset_hw(bp);
...@@ -2702,17 +2727,18 @@ static void macb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) ...@@ -2702,17 +2727,18 @@ static void macb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
wol->supported = 0; wol->supported = 0;
wol->wolopts = 0; wol->wolopts = 0;
if (bp->wol & MACB_WOL_HAS_MAGIC_PACKET) { if (bp->wol & MACB_WOL_HAS_MAGIC_PACKET)
wol->supported = WAKE_MAGIC; phylink_ethtool_get_wol(bp->phylink, wol);
if (bp->wol & MACB_WOL_ENABLED)
wol->wolopts |= WAKE_MAGIC;
}
} }
static int macb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) static int macb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
{ {
struct macb *bp = netdev_priv(netdev); struct macb *bp = netdev_priv(netdev);
int ret;
ret = phylink_ethtool_set_wol(bp->phylink, wol);
if (!ret)
return 0;
if (!(bp->wol & MACB_WOL_HAS_MAGIC_PACKET) || if (!(bp->wol & MACB_WOL_HAS_MAGIC_PACKET) ||
(wol->wolopts & ~WAKE_MAGIC)) (wol->wolopts & ~WAKE_MAGIC))
...@@ -2728,6 +2754,22 @@ static int macb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) ...@@ -2728,6 +2754,22 @@ static int macb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
return 0; return 0;
} }
static int macb_get_link_ksettings(struct net_device *netdev,
struct ethtool_link_ksettings *kset)
{
struct macb *bp = netdev_priv(netdev);
return phylink_ethtool_ksettings_get(bp->phylink, kset);
}
static int macb_set_link_ksettings(struct net_device *netdev,
const struct ethtool_link_ksettings *kset)
{
struct macb *bp = netdev_priv(netdev);
return phylink_ethtool_ksettings_set(bp->phylink, kset);
}
static void macb_get_ringparam(struct net_device *netdev, static void macb_get_ringparam(struct net_device *netdev,
struct ethtool_ringparam *ring) struct ethtool_ringparam *ring)
{ {
...@@ -3164,8 +3206,8 @@ static const struct ethtool_ops macb_ethtool_ops = { ...@@ -3164,8 +3206,8 @@ static const struct ethtool_ops macb_ethtool_ops = {
.get_ts_info = ethtool_op_get_ts_info, .get_ts_info = ethtool_op_get_ts_info,
.get_wol = macb_get_wol, .get_wol = macb_get_wol,
.set_wol = macb_set_wol, .set_wol = macb_set_wol,
.get_link_ksettings = phy_ethtool_get_link_ksettings, .get_link_ksettings = macb_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings, .set_link_ksettings = macb_set_link_ksettings,
.get_ringparam = macb_get_ringparam, .get_ringparam = macb_get_ringparam,
.set_ringparam = macb_set_ringparam, .set_ringparam = macb_set_ringparam,
}; };
...@@ -3178,8 +3220,8 @@ static const struct ethtool_ops gem_ethtool_ops = { ...@@ -3178,8 +3220,8 @@ static const struct ethtool_ops gem_ethtool_ops = {
.get_ethtool_stats = gem_get_ethtool_stats, .get_ethtool_stats = gem_get_ethtool_stats,
.get_strings = gem_get_ethtool_strings, .get_strings = gem_get_ethtool_strings,
.get_sset_count = gem_get_sset_count, .get_sset_count = gem_get_sset_count,
.get_link_ksettings = phy_ethtool_get_link_ksettings, .get_link_ksettings = macb_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings, .set_link_ksettings = macb_set_link_ksettings,
.get_ringparam = macb_get_ringparam, .get_ringparam = macb_get_ringparam,
.set_ringparam = macb_set_ringparam, .set_ringparam = macb_set_ringparam,
.get_rxnfc = gem_get_rxnfc, .get_rxnfc = gem_get_rxnfc,
...@@ -3188,26 +3230,21 @@ static const struct ethtool_ops gem_ethtool_ops = { ...@@ -3188,26 +3230,21 @@ static const struct ethtool_ops gem_ethtool_ops = {
static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{ {
struct phy_device *phydev = dev->phydev;
struct macb *bp = netdev_priv(dev); struct macb *bp = netdev_priv(dev);
if (!netif_running(dev)) if (!netif_running(dev))
return -EINVAL; return -EINVAL;
if (!phydev) if (bp->ptp_info) {
return -ENODEV; switch (cmd) {
case SIOCSHWTSTAMP:
if (!bp->ptp_info) return bp->ptp_info->set_hwtst(dev, rq, cmd);
return phy_mii_ioctl(phydev, rq, cmd); case SIOCGHWTSTAMP:
return bp->ptp_info->get_hwtst(dev, rq);
switch (cmd) { }
case SIOCSHWTSTAMP:
return bp->ptp_info->set_hwtst(dev, rq, cmd);
case SIOCGHWTSTAMP:
return bp->ptp_info->get_hwtst(dev, rq);
default:
return phy_mii_ioctl(phydev, rq, cmd);
} }
return phylink_mii_ioctl(bp->phylink, rq, cmd);
} }
static inline void macb_set_txcsum_feature(struct macb *bp, static inline void macb_set_txcsum_feature(struct macb *bp,
...@@ -3330,7 +3367,8 @@ static void macb_configure_caps(struct macb *bp, ...@@ -3330,7 +3367,8 @@ static void macb_configure_caps(struct macb *bp,
#ifdef CONFIG_MACB_USE_HWSTAMP #ifdef CONFIG_MACB_USE_HWSTAMP
if (gem_has_ptp(bp)) { if (gem_has_ptp(bp)) {
if (!GEM_BFEXT(TSU, gem_readl(bp, DCFG5))) if (!GEM_BFEXT(TSU, gem_readl(bp, DCFG5)))
pr_err("GEM doesn't support hardware ptp.\n"); dev_err(&bp->pdev->dev,
"GEM doesn't support hardware ptp.\n");
else { else {
bp->hw_dma_cap |= HW_DMA_CAP_PTP; bp->hw_dma_cap |= HW_DMA_CAP_PTP;
bp->ptp_info = &gem_ptp_info; bp->ptp_info = &gem_ptp_info;
...@@ -3707,8 +3745,9 @@ static int at91ether_open(struct net_device *dev) ...@@ -3707,8 +3745,9 @@ static int at91ether_open(struct net_device *dev)
MACB_BIT(ISR_ROVR) | MACB_BIT(ISR_ROVR) |
MACB_BIT(HRESP)); MACB_BIT(HRESP));
/* schedule a link state check */ ret = macb_phylink_connect(lp);
phy_start(dev->phydev); if (ret)
return ret;
netif_start_queue(dev); netif_start_queue(dev);
...@@ -3737,6 +3776,9 @@ static int at91ether_close(struct net_device *dev) ...@@ -3737,6 +3776,9 @@ static int at91ether_close(struct net_device *dev)
netif_stop_queue(dev); netif_stop_queue(dev);
phylink_stop(lp->phylink);
phylink_disconnect_phy(lp->phylink);
dma_free_coherent(&lp->pdev->dev, dma_free_coherent(&lp->pdev->dev,
AT91ETHER_MAX_RX_DESCR * AT91ETHER_MAX_RX_DESCR *
macb_dma_desc_get_size(lp), macb_dma_desc_get_size(lp),
...@@ -4181,7 +4223,6 @@ static int macb_probe(struct platform_device *pdev) ...@@ -4181,7 +4223,6 @@ static int macb_probe(struct platform_device *pdev)
struct clk *tsu_clk = NULL; struct clk *tsu_clk = NULL;
unsigned int queue_mask, num_queues; unsigned int queue_mask, num_queues;
bool native_io; bool native_io;
struct phy_device *phydev;
phy_interface_t interface; phy_interface_t interface;
struct net_device *dev; struct net_device *dev;
struct resource *regs; struct resource *regs;
...@@ -4316,6 +4357,8 @@ static int macb_probe(struct platform_device *pdev) ...@@ -4316,6 +4357,8 @@ static int macb_probe(struct platform_device *pdev)
else else
bp->phy_interface = interface; bp->phy_interface = interface;
bp->speed = SPEED_UNKNOWN;
/* IP specific init */ /* IP specific init */
err = init(pdev); err = init(pdev);
if (err) if (err)
...@@ -4325,8 +4368,6 @@ static int macb_probe(struct platform_device *pdev) ...@@ -4325,8 +4368,6 @@ static int macb_probe(struct platform_device *pdev)
if (err) if (err)
goto err_out_free_netdev; goto err_out_free_netdev;
phydev = dev->phydev;
netif_carrier_off(dev); netif_carrier_off(dev);
err = register_netdev(dev); err = register_netdev(dev);
...@@ -4338,8 +4379,6 @@ static int macb_probe(struct platform_device *pdev) ...@@ -4338,8 +4379,6 @@ static int macb_probe(struct platform_device *pdev)
tasklet_init(&bp->hresp_err_tasklet, macb_hresp_error_task, tasklet_init(&bp->hresp_err_tasklet, macb_hresp_error_task,
(unsigned long)bp); (unsigned long)bp);
phy_attached_info(phydev);
netdev_info(dev, "Cadence %s rev 0x%08x at 0x%08lx irq %d (%pM)\n", netdev_info(dev, "Cadence %s rev 0x%08x at 0x%08lx irq %d (%pM)\n",
macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp, MID), macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp, MID),
dev->base_addr, dev->irq, dev->dev_addr); dev->base_addr, dev->irq, dev->dev_addr);
...@@ -4350,11 +4389,7 @@ static int macb_probe(struct platform_device *pdev) ...@@ -4350,11 +4389,7 @@ static int macb_probe(struct platform_device *pdev)
return 0; return 0;
err_out_unregister_mdio: err_out_unregister_mdio:
phy_disconnect(dev->phydev);
mdiobus_unregister(bp->mii_bus); mdiobus_unregister(bp->mii_bus);
of_node_put(bp->phy_node);
if (np && of_phy_is_fixed_link(np))
of_phy_deregister_fixed_link(np);
mdiobus_free(bp->mii_bus); mdiobus_free(bp->mii_bus);
err_out_free_netdev: err_out_free_netdev:
...@@ -4378,18 +4413,12 @@ static int macb_remove(struct platform_device *pdev) ...@@ -4378,18 +4413,12 @@ static int macb_remove(struct platform_device *pdev)
{ {
struct net_device *dev; struct net_device *dev;
struct macb *bp; struct macb *bp;
struct device_node *np = pdev->dev.of_node;
dev = platform_get_drvdata(pdev); dev = platform_get_drvdata(pdev);
if (dev) { if (dev) {
bp = netdev_priv(dev); bp = netdev_priv(dev);
if (dev->phydev)
phy_disconnect(dev->phydev);
mdiobus_unregister(bp->mii_bus); mdiobus_unregister(bp->mii_bus);
if (np && of_phy_is_fixed_link(np))
of_phy_deregister_fixed_link(np);
dev->phydev = NULL;
mdiobus_free(bp->mii_bus); mdiobus_free(bp->mii_bus);
unregister_netdev(dev); unregister_netdev(dev);
...@@ -4404,7 +4433,7 @@ static int macb_remove(struct platform_device *pdev) ...@@ -4404,7 +4433,7 @@ static int macb_remove(struct platform_device *pdev)
clk_disable_unprepare(bp->tsu_clk); clk_disable_unprepare(bp->tsu_clk);
pm_runtime_set_suspended(&pdev->dev); pm_runtime_set_suspended(&pdev->dev);
} }
of_node_put(bp->phy_node); phylink_destroy(bp->phylink);
free_netdev(dev); free_netdev(dev);
} }
...@@ -4422,7 +4451,6 @@ static int __maybe_unused macb_suspend(struct device *dev) ...@@ -4422,7 +4451,6 @@ static int __maybe_unused macb_suspend(struct device *dev)
if (!netif_running(netdev)) if (!netif_running(netdev))
return 0; return 0;
if (bp->wol & MACB_WOL_ENABLED) { if (bp->wol & MACB_WOL_ENABLED) {
macb_writel(bp, IER, MACB_BIT(WOL)); macb_writel(bp, IER, MACB_BIT(WOL));
macb_writel(bp, WOL, MACB_BIT(MAG)); macb_writel(bp, WOL, MACB_BIT(MAG));
...@@ -4433,8 +4461,9 @@ static int __maybe_unused macb_suspend(struct device *dev) ...@@ -4433,8 +4461,9 @@ static int __maybe_unused macb_suspend(struct device *dev)
for (q = 0, queue = bp->queues; q < bp->num_queues; for (q = 0, queue = bp->queues; q < bp->num_queues;
++q, ++queue) ++q, ++queue)
napi_disable(&queue->napi); napi_disable(&queue->napi);
phy_stop(netdev->phydev); rtnl_lock();
phy_suspend(netdev->phydev); phylink_stop(bp->phylink);
rtnl_unlock();
spin_lock_irqsave(&bp->lock, flags); spin_lock_irqsave(&bp->lock, flags);
macb_reset_hw(bp); macb_reset_hw(bp);
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock_irqrestore(&bp->lock, flags);
...@@ -4482,12 +4511,11 @@ static int __maybe_unused macb_resume(struct device *dev) ...@@ -4482,12 +4511,11 @@ static int __maybe_unused macb_resume(struct device *dev)
for (q = 0, queue = bp->queues; q < bp->num_queues; for (q = 0, queue = bp->queues; q < bp->num_queues;
++q, ++queue) ++q, ++queue)
napi_enable(&queue->napi); napi_enable(&queue->napi);
phy_resume(netdev->phydev); rtnl_lock();
phy_init_hw(netdev->phydev); phylink_start(bp->phylink);
phy_start(netdev->phydev); rtnl_unlock();
} }
bp->macbgem_ops.mog_init_rings(bp);
macb_init_hw(bp); macb_init_hw(bp);
macb_set_rx_mode(netdev); macb_set_rx_mode(netdev);
macb_restore_features(bp); macb_restore_features(bp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment