Commit 9e9f6e72 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-bcmgenet-add-support-for-Wake-on-Filter'

Doug Berger says:

====================
net: bcmgenet: add support for Wake on Filter

Changes in v2:
	Corrected Signed-off-by for commit 3/7.

This commit set adds support for waking from 'standby' using a
Rx Network Flow Classification filter specified with ethtool.

The first two commits are bug fixes that should be applied to the
stable branches, but are included in this patch set to reduce merge
conflicts that might occur if not applied before the other commits
in this set.

The next commit consolidates WoL clock managment as a part of the
overall WoL configuration.

The next commit restores a set of functions that were removed from
the driver just prior to the 4.9 kernel release.

The following commit relocates the functions in the file to prevent
the need for additional forward declarations.

Next, support for the Rx Network Flow Classification interface of
ethtool is added.

Finally, support for the WAKE_FILTER wol method is added.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 323e395f f50932cc
/* SPDX-License-Identifier: GPL-2.0-only */ /* SPDX-License-Identifier: GPL-2.0-only */
/* /*
* Copyright (c) 2014-2017 Broadcom * Copyright (c) 2014-2020 Broadcom
*/ */
#ifndef __BCMGENET_H__ #ifndef __BCMGENET_H__
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/if_vlan.h> #include <linux/if_vlan.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/dim.h> #include <linux/dim.h>
#include <linux/ethtool.h>
/* total number of Buffer Descriptors, same for Rx/Tx */ /* total number of Buffer Descriptors, same for Rx/Tx */
#define TOTAL_DESC 256 #define TOTAL_DESC 256
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
#define DMA_MAX_BURST_LENGTH 0x10 #define DMA_MAX_BURST_LENGTH 0x10
/* misc. configuration */ /* misc. configuration */
#define MAX_NUM_OF_FS_RULES 16
#define CLEAR_ALL_HFB 0xFF #define CLEAR_ALL_HFB 0xFF
#define DMA_FC_THRESH_HI (TOTAL_DESC >> 4) #define DMA_FC_THRESH_HI (TOTAL_DESC >> 4)
#define DMA_FC_THRESH_LO 5 #define DMA_FC_THRESH_LO 5
...@@ -608,6 +610,18 @@ struct bcmgenet_rx_ring { ...@@ -608,6 +610,18 @@ struct bcmgenet_rx_ring {
struct bcmgenet_priv *priv; struct bcmgenet_priv *priv;
}; };
enum bcmgenet_rxnfc_state {
BCMGENET_RXNFC_STATE_UNUSED = 0,
BCMGENET_RXNFC_STATE_DISABLED,
BCMGENET_RXNFC_STATE_ENABLED
};
struct bcmgenet_rxnfc_rule {
struct list_head list;
struct ethtool_rx_flow_spec fs;
enum bcmgenet_rxnfc_state state;
};
/* device context */ /* device context */
struct bcmgenet_priv { struct bcmgenet_priv {
void __iomem *base; void __iomem *base;
...@@ -626,6 +640,8 @@ struct bcmgenet_priv { ...@@ -626,6 +640,8 @@ struct bcmgenet_priv {
struct enet_cb *rx_cbs; struct enet_cb *rx_cbs;
unsigned int num_rx_bds; unsigned int num_rx_bds;
unsigned int rx_buf_len; unsigned int rx_buf_len;
struct bcmgenet_rxnfc_rule rxnfc_rules[MAX_NUM_OF_FS_RULES];
struct list_head rxnfc_list;
struct bcmgenet_rx_ring rx_rings[DESC_INDEX + 1]; struct bcmgenet_rx_ring rx_rings[DESC_INDEX + 1];
...@@ -676,6 +692,9 @@ struct bcmgenet_priv { ...@@ -676,6 +692,9 @@ struct bcmgenet_priv {
/* WOL */ /* WOL */
struct clk *clk_wol; struct clk *clk_wol;
u32 wolopts; u32 wolopts;
u8 sopass[SOPASS_MAX];
bool wol_active;
u32 hfb_en[3];
struct bcmgenet_mib_counters mib; struct bcmgenet_mib_counters mib;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* /*
* Broadcom GENET (Gigabit Ethernet) Wake-on-LAN support * Broadcom GENET (Gigabit Ethernet) Wake-on-LAN support
* *
* Copyright (c) 2014-2017 Broadcom * Copyright (c) 2014-2020 Broadcom
*/ */
#define pr_fmt(fmt) "bcmgenet_wol: " fmt #define pr_fmt(fmt) "bcmgenet_wol: " fmt
...@@ -41,18 +41,13 @@ ...@@ -41,18 +41,13 @@
void bcmgenet_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) void bcmgenet_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{ {
struct bcmgenet_priv *priv = netdev_priv(dev); struct bcmgenet_priv *priv = netdev_priv(dev);
u32 reg;
wol->supported = WAKE_MAGIC | WAKE_MAGICSECURE; wol->supported = WAKE_MAGIC | WAKE_MAGICSECURE | WAKE_FILTER;
wol->wolopts = priv->wolopts; wol->wolopts = priv->wolopts;
memset(wol->sopass, 0, sizeof(wol->sopass)); memset(wol->sopass, 0, sizeof(wol->sopass));
if (wol->wolopts & WAKE_MAGICSECURE) { if (wol->wolopts & WAKE_MAGICSECURE)
reg = bcmgenet_umac_readl(priv, UMAC_MPD_PW_MS); memcpy(wol->sopass, priv->sopass, sizeof(priv->sopass));
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. /* ethtool function - set WOL (Wake on LAN) settings.
...@@ -62,25 +57,15 @@ int bcmgenet_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) ...@@ -62,25 +57,15 @@ int bcmgenet_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{ {
struct bcmgenet_priv *priv = netdev_priv(dev); struct bcmgenet_priv *priv = netdev_priv(dev);
struct device *kdev = &priv->pdev->dev; struct device *kdev = &priv->pdev->dev;
u32 reg;
if (!device_can_wakeup(kdev)) if (!device_can_wakeup(kdev))
return -ENOTSUPP; return -ENOTSUPP;
if (wol->wolopts & ~(WAKE_MAGIC | WAKE_MAGICSECURE)) if (wol->wolopts & ~(WAKE_MAGIC | WAKE_MAGICSECURE | WAKE_FILTER))
return -EINVAL; return -EINVAL;
reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL); if (wol->wolopts & WAKE_MAGICSECURE)
if (wol->wolopts & WAKE_MAGICSECURE) { memcpy(priv->sopass, wol->sopass, sizeof(priv->sopass));
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 */ /* Flag the device and relevant IRQ as wakeup capable */
if (wol->wolopts) { if (wol->wolopts) {
...@@ -120,12 +105,21 @@ static int bcmgenet_poll_wol_status(struct bcmgenet_priv *priv) ...@@ -120,12 +105,21 @@ static int bcmgenet_poll_wol_status(struct bcmgenet_priv *priv)
return retries; return retries;
} }
static void bcmgenet_set_mpd_password(struct bcmgenet_priv *priv)
{
bcmgenet_umac_writel(priv, get_unaligned_be16(&priv->sopass[0]),
UMAC_MPD_PW_MS);
bcmgenet_umac_writel(priv, get_unaligned_be32(&priv->sopass[2]),
UMAC_MPD_PW_LS);
}
int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,
enum bcmgenet_power_mode mode) enum bcmgenet_power_mode mode)
{ {
struct net_device *dev = priv->dev; struct net_device *dev = priv->dev;
struct bcmgenet_rxnfc_rule *rule;
u32 reg, hfb_ctrl_reg, hfb_enable = 0;
int retries = 0; int retries = 0;
u32 reg;
if (mode != GENET_POWER_WOL_MAGIC) { if (mode != GENET_POWER_WOL_MAGIC) {
netif_err(priv, wol, dev, "unsupported mode: %d\n", mode); netif_err(priv, wol, dev, "unsupported mode: %d\n", mode);
...@@ -142,22 +136,48 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, ...@@ -142,22 +136,48 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,
bcmgenet_umac_writel(priv, reg, UMAC_CMD); bcmgenet_umac_writel(priv, reg, UMAC_CMD);
mdelay(10); mdelay(10);
reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL); if (priv->wolopts & (WAKE_MAGIC | WAKE_MAGICSECURE)) {
reg |= MPD_EN; reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL);
bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL); reg |= MPD_EN;
if (priv->wolopts & WAKE_MAGICSECURE) {
bcmgenet_set_mpd_password(priv);
reg |= MPD_PW_EN;
}
bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL);
}
hfb_ctrl_reg = bcmgenet_hfb_reg_readl(priv, HFB_CTRL);
if (priv->wolopts & WAKE_FILTER) {
list_for_each_entry(rule, &priv->rxnfc_list, list)
if (rule->fs.ring_cookie == RX_CLS_FLOW_WAKE)
hfb_enable |= (1 << rule->fs.location);
reg = (hfb_ctrl_reg & ~RBUF_HFB_EN) | RBUF_ACPI_EN;
bcmgenet_hfb_reg_writel(priv, reg, HFB_CTRL);
}
/* Do not leave UniMAC in MPD mode only */ /* Do not leave UniMAC in MPD mode only */
retries = bcmgenet_poll_wol_status(priv); retries = bcmgenet_poll_wol_status(priv);
if (retries < 0) { if (retries < 0) {
reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL); reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL);
reg &= ~MPD_EN; reg &= ~(MPD_EN | MPD_PW_EN);
bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL); bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL);
bcmgenet_hfb_reg_writel(priv, hfb_ctrl_reg, HFB_CTRL);
return retries; return retries;
} }
netif_dbg(priv, wol, dev, "MPD WOL-ready status set after %d msec\n", netif_dbg(priv, wol, dev, "MPD WOL-ready status set after %d msec\n",
retries); retries);
clk_prepare_enable(priv->clk_wol);
priv->wol_active = 1;
if (hfb_enable) {
bcmgenet_hfb_reg_writel(priv, hfb_enable,
HFB_FLT_ENABLE_V3PLUS + 4);
hfb_ctrl_reg = RBUF_HFB_EN | RBUF_ACPI_EN;
bcmgenet_hfb_reg_writel(priv, hfb_ctrl_reg, HFB_CTRL);
}
/* Enable CRC forward */ /* Enable CRC forward */
reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg = bcmgenet_umac_readl(priv, UMAC_CMD);
priv->crc_fwd_en = 1; priv->crc_fwd_en = 1;
...@@ -186,12 +206,22 @@ void bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv, ...@@ -186,12 +206,22 @@ void bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv,
return; return;
} }
if (!priv->wol_active)
return; /* failed to suspend so skip the rest */
priv->wol_active = 0;
clk_disable_unprepare(priv->clk_wol);
/* Disable Magic Packet Detection */
reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL); reg = bcmgenet_umac_readl(priv, UMAC_MPD_CTRL);
if (!(reg & MPD_EN)) reg &= ~(MPD_EN | MPD_PW_EN);
return; /* already powered up so skip the rest */
reg &= ~MPD_EN;
bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL); bcmgenet_umac_writel(priv, reg, UMAC_MPD_CTRL);
/* Disable WAKE_FILTER Detection */
reg = bcmgenet_hfb_reg_readl(priv, HFB_CTRL);
reg &= ~(RBUF_HFB_EN | RBUF_ACPI_EN);
bcmgenet_hfb_reg_writel(priv, reg, HFB_CTRL);
/* Disable CRC Forward */ /* Disable CRC Forward */
reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg = bcmgenet_umac_readl(priv, UMAC_CMD);
reg &= ~CMD_CRC_FWD; reg &= ~CMD_CRC_FWD;
......
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