2 * Broadcom GENET (Gigabit Ethernet) Wake-on-LAN support
4 * Copyright (c) 2014 Broadcom Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #define pr_fmt(fmt) "bcmgenet_wol: " fmt
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/sched.h>
16 #include <linux/types.h>
17 #include <linux/interrupt.h>
18 #include <linux/string.h>
19 #include <linux/init.h>
20 #include <linux/errno.h>
21 #include <linux/delay.h>
23 #include <linux/clk.h>
24 #include <linux/version.h>
25 #include <linux/platform_device.h>
28 #include <linux/mii.h>
29 #include <linux/ethtool.h>
30 #include <linux/netdevice.h>
31 #include <linux/inetdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/skbuff.h>
36 #include <linux/ipv6.h>
37 #include <linux/phy.h>
41 /* ethtool function - get WOL (Wake on LAN) settings, Only Magic Packet
42 * Detection is supported through ethtool
44 void bcmgenet_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
46 struct bcmgenet_priv
*priv
= netdev_priv(dev
);
49 wol
->supported
= WAKE_MAGIC
| WAKE_MAGICSECURE
;
50 wol
->wolopts
= priv
->wolopts
;
51 memset(wol
->sopass
, 0, sizeof(wol
->sopass
));
53 if (wol
->wolopts
& WAKE_MAGICSECURE
) {
54 reg
= bcmgenet_umac_readl(priv
, UMAC_MPD_PW_MS
);
55 put_unaligned_be16(reg
, &wol
->sopass
[0]);
56 reg
= bcmgenet_umac_readl(priv
, UMAC_MPD_PW_LS
);
57 put_unaligned_be32(reg
, &wol
->sopass
[2]);
61 /* ethtool function - set WOL (Wake on LAN) settings.
62 * Only for magic packet detection mode.
64 int bcmgenet_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
66 struct bcmgenet_priv
*priv
= netdev_priv(dev
);
67 struct device
*kdev
= &priv
->pdev
->dev
;
70 if (!device_can_wakeup(kdev
))
73 if (wol
->wolopts
& ~(WAKE_MAGIC
| WAKE_MAGICSECURE
))
76 if (wol
->wolopts
& WAKE_MAGICSECURE
) {
77 bcmgenet_umac_writel(priv
, get_unaligned_be16(&wol
->sopass
[0]),
79 bcmgenet_umac_writel(priv
, get_unaligned_be32(&wol
->sopass
[2]),
81 reg
= bcmgenet_umac_readl(priv
, UMAC_MPD_CTRL
);
83 bcmgenet_umac_writel(priv
, reg
, UMAC_MPD_CTRL
);
86 /* Flag the device and relevant IRQ as wakeup capable */
88 device_set_wakeup_enable(kdev
, 1);
89 /* Avoid unbalanced enable_irq_wake calls */
90 if (priv
->wol_irq_disabled
)
91 enable_irq_wake(priv
->wol_irq
);
92 priv
->wol_irq_disabled
= false;
94 device_set_wakeup_enable(kdev
, 0);
95 /* Avoid unbalanced disable_irq_wake calls */
96 if (!priv
->wol_irq_disabled
)
97 disable_irq_wake(priv
->wol_irq
);
98 priv
->wol_irq_disabled
= true;
101 priv
->wolopts
= wol
->wolopts
;
106 static int bcmgenet_poll_wol_status(struct bcmgenet_priv
*priv
)
108 struct net_device
*dev
= priv
->dev
;
111 while (!(bcmgenet_rbuf_readl(priv
, RBUF_STATUS
)
112 & RBUF_STATUS_WOL
)) {
115 netdev_crit(dev
, "polling wol mode timeout\n");
124 int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv
*priv
,
125 enum bcmgenet_power_mode mode
)
127 struct net_device
*dev
= priv
->dev
;
132 if (mode
!= GENET_POWER_WOL_MAGIC
) {
133 netif_err(priv
, wol
, dev
, "unsupported mode: %d\n", mode
);
138 reg
= bcmgenet_umac_readl(priv
, UMAC_CMD
);
140 bcmgenet_umac_writel(priv
, reg
, UMAC_CMD
);
143 reg
= bcmgenet_umac_readl(priv
, UMAC_MPD_CTRL
);
145 bcmgenet_umac_writel(priv
, reg
, UMAC_MPD_CTRL
);
147 /* Do not leave UniMAC in MPD mode only */
148 retries
= bcmgenet_poll_wol_status(priv
);
150 reg
= bcmgenet_umac_readl(priv
, UMAC_MPD_CTRL
);
152 bcmgenet_umac_writel(priv
, reg
, UMAC_MPD_CTRL
);
156 netif_dbg(priv
, wol
, dev
, "MPD WOL-ready status set after %d msec\n",
159 /* Enable CRC forward */
160 reg
= bcmgenet_umac_readl(priv
, UMAC_CMD
);
161 priv
->crc_fwd_en
= 1;
164 /* Receiver must be enabled for WOL MP detection */
166 bcmgenet_umac_writel(priv
, reg
, UMAC_CMD
);
168 if (priv
->hw_params
->flags
& GENET_HAS_EXT
) {
169 reg
= bcmgenet_ext_readl(priv
, EXT_EXT_PWR_MGMT
);
170 reg
&= ~EXT_ENERGY_DET_MASK
;
171 bcmgenet_ext_writel(priv
, reg
, EXT_EXT_PWR_MGMT
);
174 /* Enable the MPD interrupt */
175 cpu_mask_clear
= UMAC_IRQ_MPD_R
;
177 bcmgenet_intrl2_0_writel(priv
, cpu_mask_clear
, INTRL2_CPU_MASK_CLEAR
);
182 void bcmgenet_wol_power_up_cfg(struct bcmgenet_priv
*priv
,
183 enum bcmgenet_power_mode mode
)
188 if (mode
!= GENET_POWER_WOL_MAGIC
) {
189 netif_err(priv
, wol
, priv
->dev
, "invalid mode: %d\n", mode
);
193 reg
= bcmgenet_umac_readl(priv
, UMAC_MPD_CTRL
);
195 bcmgenet_umac_writel(priv
, reg
, UMAC_MPD_CTRL
);
197 /* Disable CRC Forward */
198 reg
= bcmgenet_umac_readl(priv
, UMAC_CMD
);
200 bcmgenet_umac_writel(priv
, reg
, UMAC_CMD
);
201 priv
->crc_fwd_en
= 0;
203 /* Stop monitoring magic packet IRQ */
204 cpu_mask_set
= UMAC_IRQ_MPD_R
;
206 /* Stop monitoring magic packet IRQ */
207 bcmgenet_intrl2_0_writel(priv
, cpu_mask_set
, INTRL2_CPU_MASK_SET
);
This page took 0.035775 seconds and 6 git commands to generate.