|
@@ -576,6 +576,7 @@ static struct sh_eth_cpu_data r8a7740_data = {
|
|
|
.hw_checksum = 1,
|
|
|
.tsu = 1,
|
|
|
.select_mii = 1,
|
|
|
+ .magic = 1,
|
|
|
};
|
|
|
|
|
|
/* There is CPU dependent code */
|
|
@@ -622,8 +623,9 @@ static struct sh_eth_cpu_data r8a779x_data = {
|
|
|
|
|
|
.register_type = SH_ETH_REG_FAST_RCAR,
|
|
|
|
|
|
- .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD,
|
|
|
- .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP,
|
|
|
+ .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD | ECSR_MPD,
|
|
|
+ .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP |
|
|
|
+ ECSIPR_MPDIP,
|
|
|
.eesipr_value = 0x01ff009f,
|
|
|
|
|
|
.tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
|
|
@@ -638,6 +640,7 @@ static struct sh_eth_cpu_data r8a779x_data = {
|
|
|
.tpauser = 1,
|
|
|
.hw_swap = 1,
|
|
|
.rmiimode = 1,
|
|
|
+ .magic = 1,
|
|
|
};
|
|
|
#endif /* CONFIG_OF */
|
|
|
|
|
@@ -814,6 +817,7 @@ static struct sh_eth_cpu_data sh7734_data = {
|
|
|
.tsu = 1,
|
|
|
.hw_checksum = 1,
|
|
|
.select_mii = 1,
|
|
|
+ .magic = 1,
|
|
|
};
|
|
|
|
|
|
/* SH7763 */
|
|
@@ -841,6 +845,7 @@ static struct sh_eth_cpu_data sh7763_data = {
|
|
|
.no_ade = 1,
|
|
|
.tsu = 1,
|
|
|
.irq_flags = IRQF_SHARED,
|
|
|
+ .magic = 1,
|
|
|
};
|
|
|
|
|
|
static struct sh_eth_cpu_data sh7619_data = {
|
|
@@ -1550,6 +1555,8 @@ static void sh_eth_emac_interrupt(struct net_device *ndev)
|
|
|
sh_eth_rcv_snd_enable(ndev);
|
|
|
}
|
|
|
}
|
|
|
+ if (felic_stat & ECSR_MPD)
|
|
|
+ pm_wakeup_event(&mdp->pdev->dev, 0);
|
|
|
}
|
|
|
|
|
|
/* error control function */
|
|
@@ -2199,6 +2206,33 @@ static int sh_eth_set_ringparam(struct net_device *ndev,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+static void sh_eth_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
|
|
|
+{
|
|
|
+ struct sh_eth_private *mdp = netdev_priv(ndev);
|
|
|
+
|
|
|
+ wol->supported = 0;
|
|
|
+ wol->wolopts = 0;
|
|
|
+
|
|
|
+ if (mdp->cd->magic && mdp->clk) {
|
|
|
+ wol->supported = WAKE_MAGIC;
|
|
|
+ wol->wolopts = mdp->wol_enabled ? WAKE_MAGIC : 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static int sh_eth_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
|
|
|
+{
|
|
|
+ struct sh_eth_private *mdp = netdev_priv(ndev);
|
|
|
+
|
|
|
+ if (!mdp->cd->magic || !mdp->clk || wol->wolopts & ~WAKE_MAGIC)
|
|
|
+ return -EOPNOTSUPP;
|
|
|
+
|
|
|
+ mdp->wol_enabled = !!(wol->wolopts & WAKE_MAGIC);
|
|
|
+
|
|
|
+ device_set_wakeup_enable(&mdp->pdev->dev, mdp->wol_enabled);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
static const struct ethtool_ops sh_eth_ethtool_ops = {
|
|
|
.get_regs_len = sh_eth_get_regs_len,
|
|
|
.get_regs = sh_eth_get_regs,
|
|
@@ -2213,6 +2247,8 @@ static const struct ethtool_ops sh_eth_ethtool_ops = {
|
|
|
.set_ringparam = sh_eth_set_ringparam,
|
|
|
.get_link_ksettings = sh_eth_get_link_ksettings,
|
|
|
.set_link_ksettings = sh_eth_set_link_ksettings,
|
|
|
+ .get_wol = sh_eth_get_wol,
|
|
|
+ .set_wol = sh_eth_set_wol,
|
|
|
};
|
|
|
|
|
|
/* network device open function */
|
|
@@ -3015,6 +3051,11 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
|
|
|
goto out_release;
|
|
|
}
|
|
|
|
|
|
+ /* Get clock, if not found that's OK but Wake-On-Lan is unavailable */
|
|
|
+ mdp->clk = devm_clk_get(&pdev->dev, NULL);
|
|
|
+ if (IS_ERR(mdp->clk))
|
|
|
+ mdp->clk = NULL;
|
|
|
+
|
|
|
ndev->base_addr = res->start;
|
|
|
|
|
|
spin_lock_init(&mdp->lock);
|
|
@@ -3109,6 +3150,9 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
|
|
|
if (ret)
|
|
|
goto out_napi_del;
|
|
|
|
|
|
+ if (mdp->cd->magic && mdp->clk)
|
|
|
+ device_set_wakeup_capable(&pdev->dev, 1);
|
|
|
+
|
|
|
/* print device information */
|
|
|
netdev_info(ndev, "Base address at 0x%x, %pM, IRQ %d.\n",
|
|
|
(u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
|
|
@@ -3148,15 +3192,67 @@ static int sh_eth_drv_remove(struct platform_device *pdev)
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
+static int sh_eth_wol_setup(struct net_device *ndev)
|
|
|
+{
|
|
|
+ struct sh_eth_private *mdp = netdev_priv(ndev);
|
|
|
+
|
|
|
+ /* Only allow ECI interrupts */
|
|
|
+ synchronize_irq(ndev->irq);
|
|
|
+ napi_disable(&mdp->napi);
|
|
|
+ sh_eth_write(ndev, DMAC_M_ECI, EESIPR);
|
|
|
+
|
|
|
+ /* Enable MagicPacket */
|
|
|
+ sh_eth_modify(ndev, ECMR, 0, ECMR_MPDE);
|
|
|
+
|
|
|
+ /* Increased clock usage so device won't be suspended */
|
|
|
+ clk_enable(mdp->clk);
|
|
|
+
|
|
|
+ return enable_irq_wake(ndev->irq);
|
|
|
+}
|
|
|
+
|
|
|
+static int sh_eth_wol_restore(struct net_device *ndev)
|
|
|
+{
|
|
|
+ struct sh_eth_private *mdp = netdev_priv(ndev);
|
|
|
+ int ret;
|
|
|
+
|
|
|
+ napi_enable(&mdp->napi);
|
|
|
+
|
|
|
+ /* Disable MagicPacket */
|
|
|
+ sh_eth_modify(ndev, ECMR, ECMR_MPDE, 0);
|
|
|
+
|
|
|
+ /* The device needs to be reset to restore MagicPacket logic
|
|
|
+ * for next wakeup. If we close and open the device it will
|
|
|
+ * both be reset and all registers restored. This is what
|
|
|
+ * happens during suspend and resume without WoL enabled.
|
|
|
+ */
|
|
|
+ ret = sh_eth_close(ndev);
|
|
|
+ if (ret < 0)
|
|
|
+ return ret;
|
|
|
+ ret = sh_eth_open(ndev);
|
|
|
+ if (ret < 0)
|
|
|
+ return ret;
|
|
|
+
|
|
|
+ /* Restore clock usage count */
|
|
|
+ clk_disable(mdp->clk);
|
|
|
+
|
|
|
+ return disable_irq_wake(ndev->irq);
|
|
|
+}
|
|
|
+
|
|
|
static int sh_eth_suspend(struct device *dev)
|
|
|
{
|
|
|
struct net_device *ndev = dev_get_drvdata(dev);
|
|
|
+ struct sh_eth_private *mdp = netdev_priv(ndev);
|
|
|
int ret = 0;
|
|
|
|
|
|
- if (netif_running(ndev)) {
|
|
|
- netif_device_detach(ndev);
|
|
|
+ if (!netif_running(ndev))
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ netif_device_detach(ndev);
|
|
|
+
|
|
|
+ if (mdp->wol_enabled)
|
|
|
+ ret = sh_eth_wol_setup(ndev);
|
|
|
+ else
|
|
|
ret = sh_eth_close(ndev);
|
|
|
- }
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -3164,14 +3260,21 @@ static int sh_eth_suspend(struct device *dev)
|
|
|
static int sh_eth_resume(struct device *dev)
|
|
|
{
|
|
|
struct net_device *ndev = dev_get_drvdata(dev);
|
|
|
+ struct sh_eth_private *mdp = netdev_priv(ndev);
|
|
|
int ret = 0;
|
|
|
|
|
|
- if (netif_running(ndev)) {
|
|
|
+ if (!netif_running(ndev))
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ if (mdp->wol_enabled)
|
|
|
+ ret = sh_eth_wol_restore(ndev);
|
|
|
+ else
|
|
|
ret = sh_eth_open(ndev);
|
|
|
- if (ret < 0)
|
|
|
- return ret;
|
|
|
- netif_device_attach(ndev);
|
|
|
- }
|
|
|
+
|
|
|
+ if (ret < 0)
|
|
|
+ return ret;
|
|
|
+
|
|
|
+ netif_device_attach(ndev);
|
|
|
|
|
|
return ret;
|
|
|
}
|