Skip to content

Commit c8584b3

Browse files
committed
Merge branch 'sh_eth-wol'
Niklas Söderlund says: ==================== sh_eth: add wake-on-lan support via magic packet This series adds support for Wake-on-Lan using Magic Packet for a few models of the sh_eth driver. Patch 1/6 fix a naming error, patch 2/6 adds generic support to control and support WoL while patches 3/6 - 6/6 enable different models. Based ontop of net-next master. Changes since v2. - Fix bookkeeping for "active_count" and "event_count" reported in /sys/kernel/debug/wakeup_sources. Thanks Geert for noticing this. - Add new patch 1/6 which corrects the name of ECMR_MPDE bit, suggested by Sergei. - s/sh7743/sh7734/ in patch 5/6. Thanks Geert for spotting this. - Spelling improvements suggested by Sergei and Geert. - Add Tested-by to 3/6 and 4/6. Changes since v1. - Split generic WoL functionality and device enablement to different patches. - Enable more devices then Gen2 after feedback from Geert and datasheets. - Do not set mdp->irq_enabled = false and remove specific MagicPacket interrupt clearing, instead let sh_eth_error() clear the interrupt as for other EMAC interrupts, thanks Sergei for the suggestion. - Use the original return logic in sh_eth_resume(). - Moved sh_eth_private variable *clk to top of data structure to avoid possible gaps due to alignment restrictions. - Make wol_enabled in sh_eth_private part of the already existing bitfield instead of a bool. - Do not initiate mdp->wol_enabled to 0, the struct is kzalloc'ed so it's already set to 0. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 9f2f27a + 267e1d5 commit c8584b3

File tree

2 files changed

+117
-11
lines changed

2 files changed

+117
-11
lines changed

drivers/net/ethernet/renesas/sh_eth.c

Lines changed: 113 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ static struct sh_eth_cpu_data r8a7740_data = {
576576
.hw_checksum = 1,
577577
.tsu = 1,
578578
.select_mii = 1,
579+
.magic = 1,
579580
};
580581

581582
/* There is CPU dependent code */
@@ -622,8 +623,9 @@ static struct sh_eth_cpu_data r8a779x_data = {
622623

623624
.register_type = SH_ETH_REG_FAST_RCAR,
624625

625-
.ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD,
626-
.ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP,
626+
.ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD | ECSR_MPD,
627+
.ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP |
628+
ECSIPR_MPDIP,
627629
.eesipr_value = 0x01ff009f,
628630

629631
.tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
@@ -638,6 +640,7 @@ static struct sh_eth_cpu_data r8a779x_data = {
638640
.tpauser = 1,
639641
.hw_swap = 1,
640642
.rmiimode = 1,
643+
.magic = 1,
641644
};
642645
#endif /* CONFIG_OF */
643646

@@ -814,6 +817,7 @@ static struct sh_eth_cpu_data sh7734_data = {
814817
.tsu = 1,
815818
.hw_checksum = 1,
816819
.select_mii = 1,
820+
.magic = 1,
817821
};
818822

819823
/* SH7763 */
@@ -841,6 +845,7 @@ static struct sh_eth_cpu_data sh7763_data = {
841845
.no_ade = 1,
842846
.tsu = 1,
843847
.irq_flags = IRQF_SHARED,
848+
.magic = 1,
844849
};
845850

846851
static struct sh_eth_cpu_data sh7619_data = {
@@ -1550,6 +1555,8 @@ static void sh_eth_emac_interrupt(struct net_device *ndev)
15501555
sh_eth_rcv_snd_enable(ndev);
15511556
}
15521557
}
1558+
if (felic_stat & ECSR_MPD)
1559+
pm_wakeup_event(&mdp->pdev->dev, 0);
15531560
}
15541561

15551562
/* error control function */
@@ -2199,6 +2206,33 @@ static int sh_eth_set_ringparam(struct net_device *ndev,
21992206
return 0;
22002207
}
22012208

2209+
static void sh_eth_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
2210+
{
2211+
struct sh_eth_private *mdp = netdev_priv(ndev);
2212+
2213+
wol->supported = 0;
2214+
wol->wolopts = 0;
2215+
2216+
if (mdp->cd->magic && mdp->clk) {
2217+
wol->supported = WAKE_MAGIC;
2218+
wol->wolopts = mdp->wol_enabled ? WAKE_MAGIC : 0;
2219+
}
2220+
}
2221+
2222+
static int sh_eth_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
2223+
{
2224+
struct sh_eth_private *mdp = netdev_priv(ndev);
2225+
2226+
if (!mdp->cd->magic || !mdp->clk || wol->wolopts & ~WAKE_MAGIC)
2227+
return -EOPNOTSUPP;
2228+
2229+
mdp->wol_enabled = !!(wol->wolopts & WAKE_MAGIC);
2230+
2231+
device_set_wakeup_enable(&mdp->pdev->dev, mdp->wol_enabled);
2232+
2233+
return 0;
2234+
}
2235+
22022236
static const struct ethtool_ops sh_eth_ethtool_ops = {
22032237
.get_regs_len = sh_eth_get_regs_len,
22042238
.get_regs = sh_eth_get_regs,
@@ -2213,6 +2247,8 @@ static const struct ethtool_ops sh_eth_ethtool_ops = {
22132247
.set_ringparam = sh_eth_set_ringparam,
22142248
.get_link_ksettings = sh_eth_get_link_ksettings,
22152249
.set_link_ksettings = sh_eth_set_link_ksettings,
2250+
.get_wol = sh_eth_get_wol,
2251+
.set_wol = sh_eth_set_wol,
22162252
};
22172253

22182254
/* network device open function */
@@ -3015,6 +3051,11 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
30153051
goto out_release;
30163052
}
30173053

3054+
/* Get clock, if not found that's OK but Wake-On-Lan is unavailable */
3055+
mdp->clk = devm_clk_get(&pdev->dev, NULL);
3056+
if (IS_ERR(mdp->clk))
3057+
mdp->clk = NULL;
3058+
30183059
ndev->base_addr = res->start;
30193060

30203061
spin_lock_init(&mdp->lock);
@@ -3109,6 +3150,9 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
31093150
if (ret)
31103151
goto out_napi_del;
31113152

3153+
if (mdp->cd->magic && mdp->clk)
3154+
device_set_wakeup_capable(&pdev->dev, 1);
3155+
31123156
/* print device information */
31133157
netdev_info(ndev, "Base address at 0x%x, %pM, IRQ %d.\n",
31143158
(u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
@@ -3148,30 +3192,89 @@ static int sh_eth_drv_remove(struct platform_device *pdev)
31483192

31493193
#ifdef CONFIG_PM
31503194
#ifdef CONFIG_PM_SLEEP
3195+
static int sh_eth_wol_setup(struct net_device *ndev)
3196+
{
3197+
struct sh_eth_private *mdp = netdev_priv(ndev);
3198+
3199+
/* Only allow ECI interrupts */
3200+
synchronize_irq(ndev->irq);
3201+
napi_disable(&mdp->napi);
3202+
sh_eth_write(ndev, DMAC_M_ECI, EESIPR);
3203+
3204+
/* Enable MagicPacket */
3205+
sh_eth_modify(ndev, ECMR, 0, ECMR_MPDE);
3206+
3207+
/* Increased clock usage so device won't be suspended */
3208+
clk_enable(mdp->clk);
3209+
3210+
return enable_irq_wake(ndev->irq);
3211+
}
3212+
3213+
static int sh_eth_wol_restore(struct net_device *ndev)
3214+
{
3215+
struct sh_eth_private *mdp = netdev_priv(ndev);
3216+
int ret;
3217+
3218+
napi_enable(&mdp->napi);
3219+
3220+
/* Disable MagicPacket */
3221+
sh_eth_modify(ndev, ECMR, ECMR_MPDE, 0);
3222+
3223+
/* The device needs to be reset to restore MagicPacket logic
3224+
* for next wakeup. If we close and open the device it will
3225+
* both be reset and all registers restored. This is what
3226+
* happens during suspend and resume without WoL enabled.
3227+
*/
3228+
ret = sh_eth_close(ndev);
3229+
if (ret < 0)
3230+
return ret;
3231+
ret = sh_eth_open(ndev);
3232+
if (ret < 0)
3233+
return ret;
3234+
3235+
/* Restore clock usage count */
3236+
clk_disable(mdp->clk);
3237+
3238+
return disable_irq_wake(ndev->irq);
3239+
}
3240+
31513241
static int sh_eth_suspend(struct device *dev)
31523242
{
31533243
struct net_device *ndev = dev_get_drvdata(dev);
3244+
struct sh_eth_private *mdp = netdev_priv(ndev);
31543245
int ret = 0;
31553246

3156-
if (netif_running(ndev)) {
3157-
netif_device_detach(ndev);
3247+
if (!netif_running(ndev))
3248+
return 0;
3249+
3250+
netif_device_detach(ndev);
3251+
3252+
if (mdp->wol_enabled)
3253+
ret = sh_eth_wol_setup(ndev);
3254+
else
31583255
ret = sh_eth_close(ndev);
3159-
}
31603256

31613257
return ret;
31623258
}
31633259

31643260
static int sh_eth_resume(struct device *dev)
31653261
{
31663262
struct net_device *ndev = dev_get_drvdata(dev);
3263+
struct sh_eth_private *mdp = netdev_priv(ndev);
31673264
int ret = 0;
31683265

3169-
if (netif_running(ndev)) {
3266+
if (!netif_running(ndev))
3267+
return 0;
3268+
3269+
if (mdp->wol_enabled)
3270+
ret = sh_eth_wol_restore(ndev);
3271+
else
31703272
ret = sh_eth_open(ndev);
3171-
if (ret < 0)
3172-
return ret;
3173-
netif_device_attach(ndev);
3174-
}
3273+
3274+
if (ret < 0)
3275+
return ret;
3276+
3277+
netif_device_attach(ndev);
31753278

31763279
return ret;
31773280
}

drivers/net/ethernet/renesas/sh_eth.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ enum FELIC_MODE_BIT {
339339
ECMR_DPAD = 0x00200000, ECMR_RZPF = 0x00100000,
340340
ECMR_ZPF = 0x00080000, ECMR_PFR = 0x00040000, ECMR_RXF = 0x00020000,
341341
ECMR_TXF = 0x00010000, ECMR_MCT = 0x00002000, ECMR_PRCEF = 0x00001000,
342-
ECMR_PMDE = 0x00000200, ECMR_RE = 0x00000040, ECMR_TE = 0x00000020,
342+
ECMR_MPDE = 0x00000200, ECMR_RE = 0x00000040, ECMR_TE = 0x00000020,
343343
ECMR_RTM = 0x00000010, ECMR_ILB = 0x00000008, ECMR_ELB = 0x00000004,
344344
ECMR_DM = 0x00000002, ECMR_PRM = 0x00000001,
345345
};
@@ -492,6 +492,7 @@ struct sh_eth_cpu_data {
492492
unsigned select_mii:1; /* EtherC have RMII_MII (MII select register) */
493493
unsigned rmiimode:1; /* EtherC has RMIIMODE register */
494494
unsigned rtrate:1; /* EtherC has RTRATE register */
495+
unsigned magic:1; /* EtherC has ECMR.MPDE and ECSR.MPD */
495496
};
496497

497498
struct sh_eth_private {
@@ -500,6 +501,7 @@ struct sh_eth_private {
500501
const u16 *reg_offset;
501502
void __iomem *addr;
502503
void __iomem *tsu_addr;
504+
struct clk *clk;
503505
u32 num_rx_ring;
504506
u32 num_tx_ring;
505507
dma_addr_t rx_desc_dma;
@@ -528,6 +530,7 @@ struct sh_eth_private {
528530
unsigned no_ether_link:1;
529531
unsigned ether_link_active_low:1;
530532
unsigned is_opened:1;
533+
unsigned wol_enabled:1;
531534
};
532535

533536
static inline void sh_eth_soft_swap(char *src, int len)

0 commit comments

Comments
 (0)