Changes in 4.9.277 ARM: dts: rockchip: fix pinctrl sleep nodename for rk3036-kylin and rk3288 ARM: dts: rockchip: Fix power-controller node names for rk3288 reset: ti-syscon: fix to_ti_syscon_reset_data macro ARM: brcmstb: dts: fix NAND nodes names ARM: dts: BCM63xx: Fix NAND nodes names ARM: dts: imx6: phyFLEX: Fix UART hardware flow control ARM: imx: pm-imx5: Fix references to imx5_cpu_suspend_info ARM: dts: stm32: fix RCC node name on stm32f429 MCU arm64: dts: juno: Update SCPI nodes as per the YAML schema thermal/core: Correct function name thermal_zone_device_unregister() kbuild: mkcompile_h: consider timestamp if KBUILD_BUILD_TIMESTAMP is set rtc: max77686: Do not enforce (incorrect) interrupt trigger type scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8 sched/fair: Fix CFS bandwidth hrtimer expiry type net: ipv6: fix return value of ip6_skb_dst_mtu net: bridge: sync fdb to new unicast-filtering ports net: bcmgenet: Ensure all TX/RX queues DMAs are disabled net: moxa: fix UAF in moxart_mac_probe net: qcom/emac: fix UAF in emac_remove net: ti: fix UAF in tlan_remove_one net: validate lwtstate->data before returning from skb_tunnel_info() tcp: annotate data races around tp->mtu_info ipv6: tcp: drop silly ICMPv6 packet too big messages ixgbe: Fix an error handling path in 'ixgbe_probe()' igb: Fix an error handling path in 'igb_probe()' fm10k: Fix an error handling path in 'fm10k_probe()' e1000e: Fix an error handling path in 'e1000_probe()' iavf: Fix an error handling path in 'iavf_probe()' igb: Check if num of q_vectors is smaller than max before array access perf lzma: Close lzma stream on exit perf test bpf: Free obj_buf perf probe-file: Delete namelist in del_events() on the error path spi: mediatek: fix fifo rx mode s390/bpf: Perform r1 range checking before accessing jit->seen_reg[r1] net: fix uninit-value in caif_seqpkt_sendmsg net: decnet: Fix sleeping inside in af_decnet netrom: Decrease sock refcount when sock timers expire scsi: iscsi: Fix iface sysfs attr detection scsi: target: Fix protect handling in WRITE SAME(32) Revert "USB: quirks: ignore remote wake-up on Fibocom L850-GL LTE modem" proc: Avoid mixing integer types in mem_rw() Revert "MIPS: add PMD table accounting into MIPS'pmd_alloc_one" s390/ftrace: fix ftrace_update_ftrace_func implementation ALSA: sb: Fix potential ABBA deadlock in CSP driver xhci: Fix lost USB 2 remote wake KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow usb: hub: Disable USB 3 device initiated lpm if exit latency is too high USB: usb-storage: Add LaCie Rugged USB3-FW to IGNORE_UAS usb: max-3421: Prevent corruption of freed memory usb: renesas_usbhs: Fix superfluous irqs happen after usb_pkt_pop() USB: serial: option: add support for u-blox LARA-R6 family USB: serial: cp210x: fix comments for GE CS1000 USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop. media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf() net: bcmgenet: ensure EXT_ENERGY_DET_MASK is clear iio: accel: bma180: Use explicit member assignment iio: accel: bma180: Fix BMA25x bandwidth register values btrfs: compression: don't try to compress if we don't have enough pages Linux 4.9.277 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ibb9aa2b6a757b06f50f0e77ef193df58dc813646
205 lines
5.1 KiB
C
205 lines
5.1 KiB
C
/*
|
|
* Broadcom GENET (Gigabit Ethernet) Wake-on-LAN support
|
|
*
|
|
* Copyright (c) 2014 Broadcom Corporation
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "bcmgenet_wol: " fmt
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/types.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/string.h>
|
|
#include <linux/init.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/pm.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/version.h>
|
|
#include <linux/platform_device.h>
|
|
#include <net/arp.h>
|
|
|
|
#include <linux/mii.h>
|
|
#include <linux/ethtool.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/inetdevice.h>
|
|
#include <linux/etherdevice.h>
|
|
#include <linux/skbuff.h>
|
|
#include <linux/in.h>
|
|
#include <linux/ip.h>
|
|
#include <linux/ipv6.h>
|
|
#include <linux/phy.h>
|
|
|
|
#include "bcmgenet.h"
|
|
|
|
/* ethtool function - get WOL (Wake on LAN) settings, Only Magic Packet
|
|
* Detection is supported through ethtool
|
|
*/
|
|
void bcmgenet_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
|
|
{
|
|
struct bcmgenet_priv *priv = netdev_priv(dev);
|
|
u32 reg;
|
|
|
|
wol->supported = WAKE_MAGIC | WAKE_MAGICSECURE;
|
|
wol->wolopts = priv->wolopts;
|
|
memset(wol->sopass, 0, sizeof(wol->sopass));
|
|
|
|
if (wol->wolopts & WAKE_MAGICSECURE) {
|
|
reg = bcmgenet_umac_readl(priv, UMAC_MPD_PW_MS);
|
|
put_unaligned_be16(reg, &wol->sopass[0]);
|
|
reg = bcmgenet_umac_readl(priv, UMAC_MPD_PW_LS);
|
|
put_unaligned_be32(reg, &wol->sopass[2]);
|
|
}
|
|
}
|
|
|
|
/* ethtool function - set WOL (Wake on LAN) settings.
|
|
* Only for magic packet detection mode.
|
|
*/
|
|
int bcmgenet_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
|
|
{
|
|
struct bcmgenet_priv *priv = netdev_priv(dev);
|
|
struct device *kdev = &priv->pdev->dev;
|
|
u32 reg;
|
|
|
|
if (!device_can_wakeup(kdev))
|
|
return -ENOTSUPP;
|
|
|
|
if (wol->wolopts & ~(WAKE_MAGIC | WAKE_MAGICSECURE))
|
|
return -EINVAL;
|
|
|
|
reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL);
|
|
if (wol->wolopts & WAKE_MAGICSECURE) {
|
|
bcmgenet_umac_writel(priv, get_unaligned_be16(&wol->sopass[0]),
|
|
UMAC_MPD_PW_MS);
|
|
bcmgenet_umac_writel(priv, get_unaligned_be32(&wol->sopass[2]),
|
|
UMAC_MPD_PW_LS);
|
|
reg |= MPD_PW_EN;
|
|
} else {
|
|
reg &= ~MPD_PW_EN;
|
|
}
|
|
bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL);
|
|
|
|
/* Flag the device and relevant IRQ as wakeup capable */
|
|
if (wol->wolopts) {
|
|
device_set_wakeup_enable(kdev, 1);
|
|
/* Avoid unbalanced enable_irq_wake calls */
|
|
if (priv->wol_irq_disabled)
|
|
enable_irq_wake(priv->wol_irq);
|
|
priv->wol_irq_disabled = false;
|
|
} else {
|
|
device_set_wakeup_enable(kdev, 0);
|
|
/* Avoid unbalanced disable_irq_wake calls */
|
|
if (!priv->wol_irq_disabled)
|
|
disable_irq_wake(priv->wol_irq);
|
|
priv->wol_irq_disabled = true;
|
|
}
|
|
|
|
priv->wolopts = wol->wolopts;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int bcmgenet_poll_wol_status(struct bcmgenet_priv *priv)
|
|
{
|
|
struct net_device *dev = priv->dev;
|
|
int retries = 0;
|
|
|
|
while (!(bcmgenet_rbuf_readl(priv, RBUF_STATUS)
|
|
& RBUF_STATUS_WOL)) {
|
|
retries++;
|
|
if (retries > 5) {
|
|
netdev_crit(dev, "polling wol mode timeout\n");
|
|
return -ETIMEDOUT;
|
|
}
|
|
mdelay(1);
|
|
}
|
|
|
|
return retries;
|
|
}
|
|
|
|
int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,
|
|
enum bcmgenet_power_mode mode)
|
|
{
|
|
struct net_device *dev = priv->dev;
|
|
u32 cpu_mask_clear;
|
|
int retries = 0;
|
|
u32 reg;
|
|
|
|
if (mode != GENET_POWER_WOL_MAGIC) {
|
|
netif_err(priv, wol, dev, "unsupported mode: %d\n", mode);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* disable RX */
|
|
reg = bcmgenet_umac_readl(priv, UMAC_CMD);
|
|
reg &= ~CMD_RX_EN;
|
|
bcmgenet_umac_writel(priv, reg, UMAC_CMD);
|
|
mdelay(10);
|
|
|
|
reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL);
|
|
reg |= MPD_EN;
|
|
bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL);
|
|
|
|
/* Do not leave UniMAC in MPD mode only */
|
|
retries = bcmgenet_poll_wol_status(priv);
|
|
if (retries < 0) {
|
|
reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL);
|
|
reg &= ~MPD_EN;
|
|
bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL);
|
|
return retries;
|
|
}
|
|
|
|
netif_dbg(priv, wol, dev, "MPD WOL-ready status set after %d msec\n",
|
|
retries);
|
|
|
|
/* Enable CRC forward */
|
|
reg = bcmgenet_umac_readl(priv, UMAC_CMD);
|
|
priv->crc_fwd_en = 1;
|
|
reg |= CMD_CRC_FWD;
|
|
|
|
/* Receiver must be enabled for WOL MP detection */
|
|
reg |= CMD_RX_EN;
|
|
bcmgenet_umac_writel(priv, reg, UMAC_CMD);
|
|
|
|
/* Enable the MPD interrupt */
|
|
cpu_mask_clear = UMAC_IRQ_MPD_R;
|
|
|
|
bcmgenet_intrl2_0_writel(priv, cpu_mask_clear, INTRL2_CPU_MASK_CLEAR);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv,
|
|
enum bcmgenet_power_mode mode)
|
|
{
|
|
u32 cpu_mask_set;
|
|
u32 reg;
|
|
|
|
if (mode != GENET_POWER_WOL_MAGIC) {
|
|
netif_err(priv, wol, priv->dev, "invalid mode: %d\n", mode);
|
|
return;
|
|
}
|
|
|
|
reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL);
|
|
reg &= ~MPD_EN;
|
|
bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL);
|
|
|
|
/* Disable CRC Forward */
|
|
reg = bcmgenet_umac_readl(priv, UMAC_CMD);
|
|
reg &= ~CMD_CRC_FWD;
|
|
bcmgenet_umac_writel(priv, reg, UMAC_CMD);
|
|
priv->crc_fwd_en = 0;
|
|
|
|
/* Stop monitoring magic packet IRQ */
|
|
cpu_mask_set = UMAC_IRQ_MPD_R;
|
|
|
|
/* Stop monitoring magic packet IRQ */
|
|
bcmgenet_intrl2_0_writel(priv, cpu_mask_set, INTRL2_CPU_MASK_SET);
|
|
}
|