From: Alexander Duyck The code for handling link down event tracking wasn't working in the existing code. Specifically we should be tracking unexpected link down events, not expected ones. To do this tracking we can use the pmd_state variable and track cases where we transition from send_data to initialize in the interrupt. These should be the cases where we would be seeing unexpected link down events. In addition we have cases where the PCS will reset following the training due to errors generated while the PMD was training. This will result in a PCS reset which will flap the link. To avoid counting this link flap as the NIC has yet to report link up we will only record the link event if the netif_carrier was already reporeted as present. In order for the stat to have any value we have to display it so this change adds logic to display it as a part of the ethtool stats. Signed-off-by: Alexander Duyck --- drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 9 +++++++++ drivers/net/ethernet/meta/fbnic/fbnic_irq.c | 13 ++++++++++++- drivers/net/ethernet/meta/fbnic/fbnic_phylink.c | 2 -- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c index 95fac020eb93..693ebdf38705 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c @@ -1863,6 +1863,14 @@ fbnic_get_rmon_stats(struct net_device *netdev, *ranges = fbnic_rmon_ranges; } +static void fbnic_get_link_ext_stats(struct net_device *netdev, + struct ethtool_link_ext_stats *stats) +{ + struct fbnic_net *fbn = netdev_priv(netdev); + + stats->link_down_events = fbn->link_down_events; +} + static const struct ethtool_ops fbnic_ethtool_ops = { .cap_link_lanes_supported = true, .supported_coalesce_params = ETHTOOL_COALESCE_USECS | @@ -1874,6 +1882,7 @@ static const struct ethtool_ops fbnic_ethtool_ops = { .get_regs_len = fbnic_get_regs_len, .get_regs = fbnic_get_regs, .get_link = ethtool_op_get_link, + .get_link_ext_stats = fbnic_get_link_ext_stats, .get_coalesce = fbnic_get_coalesce, .set_coalesce = fbnic_set_coalesce, .get_ringparam = fbnic_get_ringparam, diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_irq.c b/drivers/net/ethernet/meta/fbnic/fbnic_irq.c index 9b068b82f30a..73dd10b7a1a8 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_irq.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_irq.c @@ -122,6 +122,7 @@ static irqreturn_t fbnic_mac_msix_intr(int __always_unused irq, void *data) { struct fbnic_dev *fbd = data; struct fbnic_net *fbn; + u64 link_down_event; if (fbd->mac->get_link_event(fbd) == FBNIC_LINK_EVENT_NONE) { fbnic_wr32(fbd, FBNIC_INTR_MASK_CLEAR(0), @@ -129,11 +130,21 @@ static irqreturn_t fbnic_mac_msix_intr(int __always_unused irq, void *data) return IRQ_HANDLED; } + /* If the link is up this would be a loss event */ + link_down_event = (fbd->pmd_state == FBNIC_PMD_SEND_DATA) ? 1 : 0; + fbn = netdev_priv(fbd->netdev); /* Record link down events */ - if (!fbd->mac->get_link(fbd, fbn->aui, fbn->fec)) + if (!fbd->mac->get_link(fbd, fbn->aui, fbn->fec)) { + /* Do not count link down events if the PCS has yet to + * acknowledge the link. This allows for the flushing out + * PCS errors generated during link training. + */ + if (netif_carrier_ok(fbd->netdev)) + fbn->link_down_events += link_down_event; phylink_pcs_change(&fbn->phylink_pcs, false); + } return IRQ_HANDLED; } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_phylink.c b/drivers/net/ethernet/meta/fbnic/fbnic_phylink.c index 27e4073d9898..592e9642a418 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_phylink.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_phylink.c @@ -203,8 +203,6 @@ fbnic_phylink_mac_link_down(struct phylink_config *config, unsigned int mode, struct fbnic_dev *fbd = fbn->fbd; fbd->mac->link_down(fbd); - - fbn->link_down_events++; } static void