Skip to content

Commit

Permalink
net: qcom/emac: add software control for pause frame mode
Browse files Browse the repository at this point in the history
The EMAC has the option of sending only a single pause frame when
flow control is enabled and the RX queue is full.  Although sending
only one pause frame has little value, this would allow admins to
enable automatic flow control without having to worry about the EMAC
flooding nearby switches with pause frames if the kernel hangs.

The option is enabled by using the single-pause-mode private flag.

Signed-off-by: Timur Tabi <timur@codeaurora.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Timur Tabi authored and David S. Miller committed Sep 21, 2017
1 parent 0ab09be commit 4a7a386
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
30 changes: 30 additions & 0 deletions drivers/net/ethernet/qualcomm/emac/emac-ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static void emac_set_msglevel(struct net_device *netdev, u32 data)
static int emac_get_sset_count(struct net_device *netdev, int sset)
{
switch (sset) {
case ETH_SS_PRIV_FLAGS:
return 1;
case ETH_SS_STATS:
return EMAC_STATS_LEN;
default:
Expand All @@ -100,6 +102,10 @@ static void emac_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
unsigned int i;

switch (stringset) {
case ETH_SS_PRIV_FLAGS:
strcpy(data, "single-pause-mode");
break;

case ETH_SS_STATS:
for (i = 0; i < EMAC_STATS_LEN; i++) {
strlcpy(data, emac_ethtool_stat_strings[i],
Expand Down Expand Up @@ -230,6 +236,27 @@ static int emac_get_regs_len(struct net_device *netdev)
return EMAC_MAX_REG_SIZE * sizeof(u32);
}

#define EMAC_PRIV_ENABLE_SINGLE_PAUSE BIT(0)

static int emac_set_priv_flags(struct net_device *netdev, u32 flags)
{
struct emac_adapter *adpt = netdev_priv(netdev);

adpt->single_pause_mode = !!(flags & EMAC_PRIV_ENABLE_SINGLE_PAUSE);

if (netif_running(netdev))
return emac_reinit_locked(adpt);

return 0;
}

static u32 emac_get_priv_flags(struct net_device *netdev)
{
struct emac_adapter *adpt = netdev_priv(netdev);

return adpt->single_pause_mode ? EMAC_PRIV_ENABLE_SINGLE_PAUSE : 0;
}

static const struct ethtool_ops emac_ethtool_ops = {
.get_link_ksettings = phy_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings,
Expand All @@ -253,6 +280,9 @@ static const struct ethtool_ops emac_ethtool_ops = {

.get_regs_len = emac_get_regs_len,
.get_regs = emac_get_regs,

.set_priv_flags = emac_set_priv_flags,
.get_priv_flags = emac_get_priv_flags,
};

void emac_set_ethtool_ops(struct net_device *netdev)
Expand Down
22 changes: 22 additions & 0 deletions drivers/net/ethernet/qualcomm/emac/emac-mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,28 @@ static void emac_mac_start(struct emac_adapter *adpt)
mac &= ~(HUGEN | VLAN_STRIP | TPAUSE | SIMR | HUGE | MULTI_ALL |
DEBUG_MODE | SINGLE_PAUSE_MODE);

/* Enable single-pause-frame mode if requested.
*
* If enabled, the EMAC will send a single pause frame when the RX
* queue is full. This normally leads to packet loss because
* the pause frame disables the remote MAC only for 33ms (the quanta),
* and then the remote MAC continues sending packets even though
* the RX queue is still full.
*
* If disabled, the EMAC sends a pause frame every 31ms until the RX
* queue is no longer full. Normally, this is the preferred
* method of operation. However, when the system is hung (e.g.
* cores are halted), the EMAC interrupt handler is never called
* and so the RX queue fills up quickly and stays full. The resuling
* non-stop "flood" of pause frames sometimes has the effect of
* disabling nearby switches. In some cases, other nearby switches
* are also affected, shutting down the entire network.
*
* The user can enable or disable single-pause-frame mode
* via ethtool.
*/
mac |= adpt->single_pause_mode ? SINGLE_PAUSE_MODE : 0;

writel_relaxed(csr1, adpt->csr + EMAC_EMAC_WRAPPER_CSR1);

writel_relaxed(mac, adpt->base + EMAC_MAC_CTRL);
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/ethernet/qualcomm/emac/emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ static void emac_init_adapter(struct emac_adapter *adpt)

/* default to automatic flow control */
adpt->automatic = true;

/* Disable single-pause-frame mode by default */
adpt->single_pause_mode = false;
}

/* Get the clock */
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/ethernet/qualcomm/emac/emac.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ struct emac_adapter {
bool tx_flow_control;
bool rx_flow_control;

/* True == use single-pause-frame mode. */
bool single_pause_mode;

/* Ring parameter */
u8 tpd_burst;
u8 rfd_burst;
Expand Down

0 comments on commit 4a7a386

Please sign in to comment.