Jakub Kicinski says: ==================== eth: fbnic: Extend hw stats support Mohsin says: Extend hardware stats support for fbnic by adding the ability to reset hardware stats when the device experience a reset due to a PCI error and include MAC stats in the hardware stats reset. Additionally, expand hardware stats coverage to include FEC, PHY, and Pause stats. v1: https://lore.kernel.org/20250822164731.1461754-1-kuba@kernel.org ====================
Unified · Split
| @@ -84,9 +84,6 @@ struct fbnic_dev { · 83 unmodified lines | ||
| 84 | 84 | /* Local copy of hardware statistics */ |
| 85 | 85 | struct fbnic_hw_stats hw_stats; |
| 86 | 86 | |
| 87 | − /* Lock protecting access to hw_stats */ | |
| 88 | − spinlock_t hw_stats_lock; | |
| 89 | − | |
| 90 | 87 | struct fbnic_fw_log fw_log; |
| 91 | 88 | }; |
| 92 | 89 | |
| @@ -790,6 +790,21 @@ enum { · 789 unmodified lines | ||
| 790 | 790 | #define FBNIC_CSR_END_PCS 0x10668 /* CSR section delimiter */ |
| 791 | 791 | |
| 792 | 792 | #define FBNIC_CSR_START_RSFEC 0x10800 /* CSR section delimiter */ |
| 793 | + | |
| 794 | +/* We have 4 RSFEC engines present in our part, however we are only using 1. | |
| 795 | + * As such only CCW(0) and NCCW(0) will never be non-zero and the other | |
| 796 | + * registers can be ignored. | |
| 797 | + */ | |
| 798 | +#define FBNIC_RSFEC_CCW_LO(n) (0x10802 + 8 * (n)) /* 0x42008 + 32*n */ | |
| 799 | +#define FBNIC_RSFEC_CCW_HI(n) (0x10803 + 8 * (n)) /* 0x4200c + 32*n */ | |
| 800 | +#define FBNIC_RSFEC_NCCW_LO(n) (0x10804 + 8 * (n)) /* 0x42010 + 32*n */ | |
| 801 | +#define FBNIC_RSFEC_NCCW_HI(n) (0x10805 + 8 * (n)) /* 0x42014 + 32*n */ | |
| 802 | + | |
| 803 | +#define FBNIC_PCS_MAX_LANES 4 | |
| 804 | +#define FBNIC_PCS_SYMBLERR_LO(n) \ | |
| 805 | + (0x10880 + 2 * (n)) /* 0x42200 + 8*n */ | |
| 806 | +#define FBNIC_PCS_SYMBLERR_HI(n) \ | |
| 807 | + (0x10881 + 2 * (n)) /* 0x42204 + 8*n */ | |
| 793 | 808 | #define FBNIC_CSR_END_RSFEC 0x108c8 /* CSR section delimiter */ |
| 794 | 809 | |
| 795 | 810 | /* MAC MAC registers (ASIC only) */ |
| @@ -829,6 +844,10 @@ enum { · 33 unmodified lines | ||
| 829 | 844 | #define FBNIC_CSR_END_SIG 0x1184e /* CSR section delimiter */ |
| 830 | 845 | |
| 831 | 846 | #define FBNIC_CSR_START_MAC_STAT 0x11a00 |
| 847 | +#define FBNIC_MAC_STAT_RX_XOFF_STB_L 0x11a00 /* 0x46800 */ | |
| 848 | +#define FBNIC_MAC_STAT_RX_XOFF_STB_H 0x11a01 /* 0x46804 */ | |
| 849 | +#define FBNIC_MAC_STAT_TX_XOFF_STB_L 0x11a04 /* 0x46810 */ | |
| 850 | +#define FBNIC_MAC_STAT_TX_XOFF_STB_H 0x11a05 /* 0x46814 */ | |
| 832 | 851 | #define FBNIC_MAC_STAT_RX_BYTE_COUNT_L 0x11a08 /* 0x46820 */ |
| 833 | 852 | #define FBNIC_MAC_STAT_RX_BYTE_COUNT_H 0x11a09 /* 0x46824 */ |
| 834 | 853 | #define FBNIC_MAC_STAT_RX_ALIGN_ERROR_L 0x11a0a /* 0x46828 */ |
| @@ -518,7 +518,7 @@ static void fbnic_get_ethtool_stats(struct net_device *dev, · 517 unmodified lines | ||
| 518 | 518 | |
| 519 | 519 | fbnic_get_hw_stats(fbn->fbd); |
| 520 | 520 | |
| 521 | − spin_lock(&fbd->hw_stats_lock); | |
| 521 | + spin_lock(&fbd->hw_stats.lock); | |
| 522 | 522 | fbnic_report_hw_stats(fbnic_gstrings_hw_stats, &fbd->hw_stats, |
| 523 | 523 | FBNIC_HW_FIXED_STATS_LEN, &data); |
| 524 | 524 | |
| @@ -555,7 +555,7 @@ static void fbnic_get_ethtool_stats(struct net_device *dev, · 30 unmodified lines | ||
| 555 | 555 | fbnic_report_hw_stats(fbnic_gstrings_hw_q_stats, hw_q, |
| 556 | 556 | FBNIC_HW_Q_STATS_LEN, &data); |
| 557 | 557 | } |
| 558 | − spin_unlock(&fbd->hw_stats_lock); | |
| 558 | + spin_unlock(&fbd->hw_stats.lock); | |
| 559 | 559 | |
| 560 | 560 | for (i = 0; i < FBNIC_MAX_XDPQS; i++) |
| 561 | 561 | fbnic_get_xdp_queue_stats(fbn->tx[i + FBNIC_MAX_TXQS], &data); |
| @@ -1641,6 +1641,62 @@ static void fbnic_set_counter(u64 *stat, struct fbnic_stat_counter *counter) · 1079 unmodified lines | ||
| 1641 | 1641 | *stat = counter->value; |
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | +static void | |
| 1645 | +fbnic_get_pause_stats(struct net_device *netdev, | |
| 1646 | + struct ethtool_pause_stats *pause_stats) | |
| 1647 | +{ | |
| 1648 | + struct fbnic_net *fbn = netdev_priv(netdev); | |
| 1649 | + struct fbnic_mac_stats *mac_stats; | |
| 1650 | + struct fbnic_dev *fbd = fbn->fbd; | |
| 1651 | + | |
| 1652 | + mac_stats = &fbd->hw_stats.mac; | |
| 1653 | + | |
| 1654 | + fbd->mac->get_pause_stats(fbd, false, &mac_stats->pause); | |
| 1655 | + | |
| 1656 | + pause_stats->tx_pause_frames = mac_stats->pause.tx_pause_frames.value; | |
| 1657 | + pause_stats->rx_pause_frames = mac_stats->pause.rx_pause_frames.value; | |
| 1658 | +} | |
| 1659 | + | |
| 1660 | +static void | |
| 1661 | +fbnic_get_fec_stats(struct net_device *netdev, | |
| 1662 | + struct ethtool_fec_stats *fec_stats) | |
| 1663 | +{ | |
| 1664 | + struct fbnic_net *fbn = netdev_priv(netdev); | |
| 1665 | + struct fbnic_phy_stats *phy_stats; | |
| 1666 | + struct fbnic_dev *fbd = fbn->fbd; | |
| 1667 | + | |
| 1668 | + fbnic_get_hw_stats32(fbd); | |
| 1669 | + phy_stats = &fbd->hw_stats.phy; | |
| 1670 | + | |
| 1671 | + spin_lock(&fbd->hw_stats.lock); | |
| 1672 | + fec_stats->corrected_blocks.total = | |
| 1673 | + phy_stats->fec.corrected_blocks.value; | |
| 1674 | + fec_stats->uncorrectable_blocks.total = | |
| 1675 | + phy_stats->fec.uncorrectable_blocks.value; | |
| 1676 | + spin_unlock(&fbd->hw_stats.lock); | |
| 1677 | +} | |
| 1678 | + | |
| 1679 | +static void | |
| 1680 | +fbnic_get_eth_phy_stats(struct net_device *netdev, | |
| 1681 | + struct ethtool_eth_phy_stats *eth_phy_stats) | |
| 1682 | +{ | |
| 1683 | + struct fbnic_net *fbn = netdev_priv(netdev); | |
| 1684 | + struct fbnic_phy_stats *phy_stats; | |
| 1685 | + struct fbnic_dev *fbd = fbn->fbd; | |
| 1686 | + u64 total = 0; | |
| 1687 | + int i; | |
| 1688 | + | |
| 1689 | + fbnic_get_hw_stats32(fbd); | |
| 1690 | + phy_stats = &fbd->hw_stats.phy; | |
| 1691 | + | |
| 1692 | + spin_lock(&fbd->hw_stats.lock); | |
| 1693 | + for (i = 0; i < FBNIC_PCS_MAX_LANES; i++) | |
| 1694 | + total += phy_stats->pcs.SymbolErrorDuringCarrier.lanes[i].value; | |
| 1695 | + | |
| 1696 | + eth_phy_stats->SymbolErrorDuringCarrier = total; | |
| 1697 | + spin_unlock(&fbd->hw_stats.lock); | |
| 1698 | +} | |
| 1699 | + | |
| 1644 | 1700 | static void |
| 1645 | 1701 | fbnic_get_eth_mac_stats(struct net_device *netdev, |
| 1646 | 1702 | struct ethtool_eth_mac_stats *eth_mac_stats) |
| @@ -1761,6 +1817,7 @@ static const struct ethtool_ops fbnic_ethtool_ops = { · 114 unmodified lines | ||
| 1761 | 1817 | .set_coalesce = fbnic_set_coalesce, |
| 1762 | 1818 | .get_ringparam = fbnic_get_ringparam, |
| 1763 | 1819 | .set_ringparam = fbnic_set_ringparam, |
| 1820 | + .get_pause_stats = fbnic_get_pause_stats, | |
| 1764 | 1821 | .get_pauseparam = fbnic_phylink_get_pauseparam, |
| 1765 | 1822 | .set_pauseparam = fbnic_phylink_set_pauseparam, |
| 1766 | 1823 | .get_strings = fbnic_get_strings, |
| @@ -1782,7 +1839,9 @@ static const struct ethtool_ops fbnic_ethtool_ops = { · 15 unmodified lines | ||
| 1782 | 1839 | .get_ts_info = fbnic_get_ts_info, |
| 1783 | 1840 | .get_ts_stats = fbnic_get_ts_stats, |
| 1784 | 1841 | .get_link_ksettings = fbnic_phylink_ethtool_ksettings_get, |
| 1842 | + .get_fec_stats = fbnic_get_fec_stats, | |
| 1785 | 1843 | .get_fecparam = fbnic_phylink_get_fecparam, |
| 1844 | + .get_eth_phy_stats = fbnic_get_eth_phy_stats, | |
| 1786 | 1845 | .get_eth_mac_stats = fbnic_get_eth_mac_stats, |
| 1787 | 1846 | .get_eth_ctrl_stats = fbnic_get_eth_ctrl_stats, |
| 1788 | 1847 | .get_rmon_stats = fbnic_get_rmon_stats, |
| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | 2 | /* Copyright (c) Meta Platforms, Inc. and affiliates. */ |
| 3 | 3 | |
| 4 | +#include <linux/rtnetlink.h> | |
| 5 | + | |
| 4 | 6 | #include "fbnic.h" |
| 5 | 7 | |
| 6 | 8 | static void fbnic_hw_stat_rst32(struct fbnic_dev *fbd, u32 reg, |
| @@ -421,9 +423,9 @@ static void fbnic_get_hw_rxq_stats32(struct fbnic_dev *fbd, · 414 unmodified lines | ||
| 421 | 423 | void fbnic_get_hw_q_stats(struct fbnic_dev *fbd, |
| 422 | 424 | struct fbnic_hw_q_stats *hw_q) |
| 423 | 425 | { |
| 424 | − spin_lock(&fbd->hw_stats_lock); | |
| 426 | + spin_lock(&fbd->hw_stats.lock); | |
| 425 | 427 | fbnic_get_hw_rxq_stats32(fbd, hw_q); |
| 426 | − spin_unlock(&fbd->hw_stats_lock); | |
| 428 | + spin_unlock(&fbd->hw_stats.lock); | |
| 427 | 429 | } |
| 428 | 430 | |
| 429 | 431 | static void fbnic_reset_pcie_stats_asic(struct fbnic_dev *fbd, |
| @@ -510,20 +512,68 @@ static void fbnic_get_pcie_stats_asic64(struct fbnic_dev *fbd, · 80 unmodified lines | ||
| 510 | 512 | &pcie->ob_rd_no_np_cred); |
| 511 | 513 | } |
| 512 | 514 | |
| 515 | +static void fbnic_reset_phy_stats(struct fbnic_dev *fbd, | |
| 516 | + struct fbnic_phy_stats *phy_stats) | |
| 517 | +{ | |
| 518 | + const struct fbnic_mac *mac = fbd->mac; | |
| 519 | + | |
| 520 | + mac->get_fec_stats(fbd, true, &phy_stats->fec); | |
| 521 | + mac->get_pcs_stats(fbd, true, &phy_stats->pcs); | |
| 522 | +} | |
| 523 | + | |
| 524 | +static void fbnic_get_phy_stats32(struct fbnic_dev *fbd, | |
| 525 | + struct fbnic_phy_stats *phy_stats) | |
| 526 | +{ | |
| 527 | + const struct fbnic_mac *mac = fbd->mac; | |
| 528 | + | |
| 529 | + mac->get_fec_stats(fbd, false, &phy_stats->fec); | |
| 530 | + mac->get_pcs_stats(fbd, false, &phy_stats->pcs); | |
| 531 | +} | |
| 532 | + | |
| 533 | +static void fbnic_reset_hw_mac_stats(struct fbnic_dev *fbd, | |
| 534 | + struct fbnic_mac_stats *mac_stats) | |
| 535 | +{ | |
| 536 | + const struct fbnic_mac *mac = fbd->mac; | |
| 537 | + | |
| 538 | + mac->get_eth_mac_stats(fbd, true, &mac_stats->eth_mac); | |
| 539 | + mac->get_pause_stats(fbd, true, &mac_stats->pause); | |
| 540 | + mac->get_eth_ctrl_stats(fbd, true, &mac_stats->eth_ctrl); | |
| 541 | + mac->get_rmon_stats(fbd, true, &mac_stats->rmon); | |
| 542 | +} | |
| 543 | + | |
| 513 | 544 | void fbnic_reset_hw_stats(struct fbnic_dev *fbd) |
| 514 | 545 | { |
| 515 | − spin_lock(&fbd->hw_stats_lock); | |
| 546 | + spin_lock(&fbd->hw_stats.lock); | |
| 547 | + fbnic_reset_phy_stats(fbd, &fbd->hw_stats.phy); | |
| 516 | 548 | fbnic_reset_tmi_stats(fbd, &fbd->hw_stats.tmi); |
| 517 | 549 | fbnic_reset_tti_stats(fbd, &fbd->hw_stats.tti); |
| 518 | 550 | fbnic_reset_rpc_stats(fbd, &fbd->hw_stats.rpc); |
| 519 | 551 | fbnic_reset_rxb_stats(fbd, &fbd->hw_stats.rxb); |
| 520 | 552 | fbnic_reset_hw_rxq_stats(fbd, fbd->hw_stats.hw_q); |
| 521 | 553 | fbnic_reset_pcie_stats_asic(fbd, &fbd->hw_stats.pcie); |
| 522 | − spin_unlock(&fbd->hw_stats_lock); | |
| 554 | + spin_unlock(&fbd->hw_stats.lock); | |
| 555 | + | |
| 556 | + /* Once registered, the only other access to MAC stats is via the | |
| 557 | + * ethtool API which is protected by the rtnl_lock. The call to | |
| 558 | + * fbnic_reset_hw_stats() during PCI recovery is also protected | |
| 559 | + * by the rtnl_lock hence, we don't need the spinlock to access | |
| 560 | + * the MAC stats. | |
| 561 | + */ | |
| 562 | + if (fbd->netdev) | |
| 563 | + ASSERT_RTNL(); | |
| 564 | + fbnic_reset_hw_mac_stats(fbd, &fbd->hw_stats.mac); | |
| 565 | +} | |
| 566 | + | |
| 567 | +void fbnic_init_hw_stats(struct fbnic_dev *fbd) | |
| 568 | +{ | |
| 569 | + spin_lock_init(&fbd->hw_stats.lock); | |
| 570 | + | |
| 571 | + fbnic_reset_hw_stats(fbd); | |
| 523 | 572 | } |
| 524 | 573 | |
| 525 | 574 | static void __fbnic_get_hw_stats32(struct fbnic_dev *fbd) |
| 526 | 575 | { |
| 576 | + fbnic_get_phy_stats32(fbd, &fbd->hw_stats.phy); | |
| 527 | 577 | fbnic_get_tmi_stats32(fbd, &fbd->hw_stats.tmi); |
| 528 | 578 | fbnic_get_tti_stats32(fbd, &fbd->hw_stats.tti); |
| 529 | 579 | fbnic_get_rpc_stats32(fbd, &fbd->hw_stats.rpc); |
| @@ -533,19 +583,19 @@ static void __fbnic_get_hw_stats32(struct fbnic_dev *fbd) · 3 unmodified lines | ||
| 533 | 583 | |
| 534 | 584 | void fbnic_get_hw_stats32(struct fbnic_dev *fbd) |
| 535 | 585 | { |
| 536 | − spin_lock(&fbd->hw_stats_lock); | |
| 586 | + spin_lock(&fbd->hw_stats.lock); | |
| 537 | 587 | __fbnic_get_hw_stats32(fbd); |
| 538 | − spin_unlock(&fbd->hw_stats_lock); | |
| 588 | + spin_unlock(&fbd->hw_stats.lock); | |
| 539 | 589 | } |
| 540 | 590 | |
| 541 | 591 | void fbnic_get_hw_stats(struct fbnic_dev *fbd) |
| 542 | 592 | { |
| 543 | − spin_lock(&fbd->hw_stats_lock); | |
| 593 | + spin_lock(&fbd->hw_stats.lock); | |
| 544 | 594 | __fbnic_get_hw_stats32(fbd); |
| 545 | 595 | |
| 546 | 596 | fbnic_get_tmi_stats(fbd, &fbd->hw_stats.tmi); |
| 547 | 597 | fbnic_get_tti_stats(fbd, &fbd->hw_stats.tti); |
| 548 | 598 | fbnic_get_rxb_stats(fbd, &fbd->hw_stats.rxb); |
| 549 | 599 | fbnic_get_pcie_stats_asic64(fbd, &fbd->hw_stats.pcie); |
| 550 | − spin_unlock(&fbd->hw_stats_lock); | |
| 600 | + spin_unlock(&fbd->hw_stats.lock); | |
| 551 | 601 | } |
| @@ -5,6 +5,7 @@ · 4 unmodified lines | ||
| 5 | 5 | #define _FBNIC_HW_STATS_H_ |
| 6 | 6 | |
| 7 | 7 | #include <linux/ethtool.h> |
| 8 | +#include <linux/spinlock.h> | |
| 8 | 9 | |
| 9 | 10 | #include "fbnic_csr.h" |
| 10 | 11 | |
| @@ -22,6 +23,16 @@ struct fbnic_hw_stat { · 11 unmodified lines | ||
| 22 | 23 | struct fbnic_stat_counter bytes; |
| 23 | 24 | }; |
| 24 | 25 | |
| 26 | +struct fbnic_fec_stats { | |
| 27 | + struct fbnic_stat_counter corrected_blocks, uncorrectable_blocks; | |
| 28 | +}; | |
| 29 | + | |
| 30 | +struct fbnic_pcs_stats { | |
| 31 | + struct { | |
| 32 | + struct fbnic_stat_counter lanes[FBNIC_PCS_MAX_LANES]; | |
| 33 | + } SymbolErrorDuringCarrier; | |
| 34 | +}; | |
| 35 | + | |
| 25 | 36 | /* Note: not updated by fbnic_get_hw_stats() */ |
| 26 | 37 | struct fbnic_eth_ctrl_stats { |
| 27 | 38 | struct fbnic_stat_counter MACControlFramesTransmitted; |
| @@ -39,6 +50,12 @@ struct fbnic_rmon_stats { · 11 unmodified lines | ||
| 39 | 50 | struct fbnic_stat_counter hist_tx[ETHTOOL_RMON_HIST_MAX]; |
| 40 | 51 | }; |
| 41 | 52 | |
| 53 | +/* Note: not updated by fbnic_get_hw_stats() */ | |
| 54 | +struct fbnic_pause_stats { | |
| 55 | + struct fbnic_stat_counter tx_pause_frames; | |
| 56 | + struct fbnic_stat_counter rx_pause_frames; | |
| 57 | +}; | |
| 58 | + | |
| 42 | 59 | struct fbnic_eth_mac_stats { |
| 43 | 60 | struct fbnic_stat_counter FramesTransmittedOK; |
| 44 | 61 | struct fbnic_stat_counter FramesReceivedOK; |
| @@ -55,8 +72,14 @@ struct fbnic_eth_mac_stats { · 10 unmodified lines | ||
| 55 | 72 | struct fbnic_stat_counter FrameTooLongErrors; |
| 56 | 73 | }; |
| 57 | 74 | |
| 75 | +struct fbnic_phy_stats { | |
| 76 | + struct fbnic_fec_stats fec; | |
| 77 | + struct fbnic_pcs_stats pcs; | |
| 78 | +}; | |
| 79 | + | |
| 58 | 80 | struct fbnic_mac_stats { |
| 59 | 81 | struct fbnic_eth_mac_stats eth_mac; |
| 82 | + struct fbnic_pause_stats pause; | |
| 60 | 83 | struct fbnic_eth_ctrl_stats eth_ctrl; |
| 61 | 84 | struct fbnic_rmon_stats rmon; |
| 62 | 85 | }; |
| @@ -115,6 +138,7 @@ struct fbnic_pcie_stats { · 52 unmodified lines | ||
| 115 | 138 | }; |
| 116 | 139 | |
| 117 | 140 | struct fbnic_hw_stats { |
| 141 | + struct fbnic_phy_stats phy; | |
| 118 | 142 | struct fbnic_mac_stats mac; |
| 119 | 143 | struct fbnic_tmi_stats tmi; |
| 120 | 144 | struct fbnic_tti_stats tti; |
| @@ -122,11 +146,15 @@ struct fbnic_hw_stats { · 1 unmodified line | ||
| 122 | 146 | struct fbnic_rxb_stats rxb; |
| 123 | 147 | struct fbnic_hw_q_stats hw_q[FBNIC_MAX_QUEUES]; |
| 124 | 148 | struct fbnic_pcie_stats pcie; |
| 149 | + | |
| 150 | + /* Lock protecting the access to hw stats */ | |
| 151 | + spinlock_t lock; | |
| 125 | 152 | }; |
| 126 | 153 | |
| 127 | 154 | u64 fbnic_stat_rd64(struct fbnic_dev *fbd, u32 reg, u32 offset); |
| 128 | 155 | |
| 129 | 156 | void fbnic_reset_hw_stats(struct fbnic_dev *fbd); |
| 157 | +void fbnic_init_hw_stats(struct fbnic_dev *fbd); | |
| 130 | 158 | void fbnic_get_hw_q_stats(struct fbnic_dev *fbd, |
| 131 | 159 | struct fbnic_hw_q_stats *hw_q); |
| 132 | 160 | void fbnic_get_hw_stats32(struct fbnic_dev *fbd); |
| @@ -631,6 +631,50 @@ static void fbnic_mac_link_up_asic(struct fbnic_dev *fbd, · 630 unmodified lines | ||
| 631 | 631 | wr32(fbd, FBNIC_MAC_COMMAND_CONFIG, cmd_cfg); |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | +static void | |
| 635 | +fbnic_pcs_rsfec_stat_rd32(struct fbnic_dev *fbd, u32 reg, bool reset, | |
| 636 | + struct fbnic_stat_counter *stat) | |
| 637 | +{ | |
| 638 | + u32 pcs_rsfec_stat; | |
| 639 | + | |
| 640 | + /* The PCS/RFSEC registers are only 16b wide each. So what we will | |
| 641 | + * have after the 64b read is 0x0000xxxx0000xxxx. To make it usable | |
| 642 | + * as a full stat we will shift the upper bits into the lower set of | |
| 643 | + * 0s and then mask off the math at 32b. | |
| 644 | + * | |
| 645 | + * Read ordering must be lower reg followed by upper reg. | |
| 646 | + */ | |
| 647 | + pcs_rsfec_stat = rd32(fbd, reg) & 0xffff; | |
| 648 | + pcs_rsfec_stat |= rd32(fbd, reg + 1) << 16; | |
| 649 | + | |
| 650 | + /* RFSEC registers clear themselves upon being read so there is no | |
| 651 | + * need to store the old_reg_value. | |
| 652 | + */ | |
| 653 | + if (!reset) | |
| 654 | + stat->value += pcs_rsfec_stat; | |
| 655 | +} | |
| 656 | + | |
| 657 | +static void | |
| 658 | +fbnic_mac_get_fec_stats(struct fbnic_dev *fbd, bool reset, | |
| 659 | + struct fbnic_fec_stats *s) | |
| 660 | +{ | |
| 661 | + fbnic_pcs_rsfec_stat_rd32(fbd, FBNIC_RSFEC_CCW_LO(0), reset, | |
| 662 | + &s->corrected_blocks); | |
| 663 | + fbnic_pcs_rsfec_stat_rd32(fbd, FBNIC_RSFEC_NCCW_LO(0), reset, | |
| 664 | + &s->uncorrectable_blocks); | |
| 665 | +} | |
| 666 | + | |
| 667 | +static void | |
| 668 | +fbnic_mac_get_pcs_stats(struct fbnic_dev *fbd, bool reset, | |
| 669 | + struct fbnic_pcs_stats *s) | |
| 670 | +{ | |
| 671 | + int i; | |
| 672 | + | |
| 673 | + for (i = 0; i < FBNIC_PCS_MAX_LANES; i++) | |
| 674 | + fbnic_pcs_rsfec_stat_rd32(fbd, FBNIC_PCS_SYMBLERR_LO(i), reset, | |
| 675 | + &s->SymbolErrorDuringCarrier.lanes[i]); | |
| 676 | +} | |
| 677 | + | |
| 634 | 678 | static void |
| 635 | 679 | fbnic_mac_get_eth_mac_stats(struct fbnic_dev *fbd, bool reset, |
| 636 | 680 | struct fbnic_eth_mac_stats *mac_stats) |
| @@ -665,6 +709,16 @@ fbnic_mac_get_eth_mac_stats(struct fbnic_dev *fbd, bool reset, · 28 unmodified lines | ||
| 665 | 709 | MAC_STAT_TX_BROADCAST); |
| 666 | 710 | } |
| 667 | 711 | |
| 712 | +static void | |
| 713 | +fbnic_mac_get_pause_stats(struct fbnic_dev *fbd, bool reset, | |
| 714 | + struct fbnic_pause_stats *pause_stats) | |
| 715 | +{ | |
| 716 | + fbnic_mac_stat_rd64(fbd, reset, pause_stats->tx_pause_frames, | |
| 717 | + MAC_STAT_TX_XOFF_STB); | |
| 718 | + fbnic_mac_stat_rd64(fbd, reset, pause_stats->rx_pause_frames, | |
| 719 | + MAC_STAT_RX_XOFF_STB); | |
| 720 | +} | |
| 721 | + | |
| 668 | 722 | static void |
| 669 | 723 | fbnic_mac_get_eth_ctrl_stats(struct fbnic_dev *fbd, bool reset, |
| 670 | 724 | struct fbnic_eth_ctrl_stats *ctrl_stats) |
| @@ -809,7 +863,10 @@ static const struct fbnic_mac fbnic_mac_asic = { · 138 unmodified lines | ||
| 809 | 863 | .pcs_disable = fbnic_pcs_disable_asic, |
| 810 | 864 | .pcs_get_link = fbnic_pcs_get_link_asic, |
| 811 | 865 | .pcs_get_link_event = fbnic_pcs_get_link_event_asic, |
| 866 | + .get_fec_stats = fbnic_mac_get_fec_stats, | |
| 867 | + .get_pcs_stats = fbnic_mac_get_pcs_stats, | |
| 812 | 868 | .get_eth_mac_stats = fbnic_mac_get_eth_mac_stats, |
| 869 | + .get_pause_stats = fbnic_mac_get_pause_stats, | |
| 813 | 870 | .get_eth_ctrl_stats = fbnic_mac_get_eth_ctrl_stats, |
| 814 | 871 | .get_rmon_stats = fbnic_mac_get_rmon_stats, |
| 815 | 872 | .link_down = fbnic_mac_link_down_asic, |
| @@ -79,8 +79,14 @@ struct fbnic_mac { · 78 unmodified lines | ||
| 79 | 79 | bool (*pcs_get_link)(struct fbnic_dev *fbd); |
| 80 | 80 | int (*pcs_get_link_event)(struct fbnic_dev *fbd); |
| 81 | 81 | |
| 82 | + void (*get_fec_stats)(struct fbnic_dev *fbd, bool reset, | |
| 83 | + struct fbnic_fec_stats *fec_stats); | |
| 84 | + void (*get_pcs_stats)(struct fbnic_dev *fbd, bool reset, | |
| 85 | + struct fbnic_pcs_stats *pcs_stats); | |
| 82 | 86 | void (*get_eth_mac_stats)(struct fbnic_dev *fbd, bool reset, |
| 83 | 87 | struct fbnic_eth_mac_stats *mac_stats); |
| 88 | + void (*get_pause_stats)(struct fbnic_dev *fbd, bool reset, | |
| 89 | + struct fbnic_pause_stats *pause_stats); | |
| 84 | 90 | void (*get_eth_ctrl_stats)(struct fbnic_dev *fbd, bool reset, |
| 85 | 91 | struct fbnic_eth_ctrl_stats *ctrl_stats); |
| 86 | 92 | void (*get_rmon_stats)(struct fbnic_dev *fbd, bool reset, |
| @@ -424,12 +424,12 @@ static void fbnic_get_stats64(struct net_device *dev, · 423 unmodified lines | ||
| 424 | 424 | tx_dropped = stats->dropped; |
| 425 | 425 | |
| 426 | 426 | /* Record drops from Tx HW Datapath */ |
| 427 | − spin_lock(&fbd->hw_stats_lock); | |
| 427 | + spin_lock(&fbd->hw_stats.lock); | |
| 428 | 428 | tx_dropped += fbd->hw_stats.tmi.drop.frames.value + |
| 429 | 429 | fbd->hw_stats.tti.cm_drop.frames.value + |
| 430 | 430 | fbd->hw_stats.tti.frame_drop.frames.value + |
| 431 | 431 | fbd->hw_stats.tti.tbi_drop.frames.value; |
| 432 | − spin_unlock(&fbd->hw_stats_lock); | |
| 432 | + spin_unlock(&fbd->hw_stats.lock); | |
| 433 | 433 | |
| 434 | 434 | stats64->tx_bytes = tx_bytes; |
| 435 | 435 | stats64->tx_packets = tx_packets; |
| @@ -460,7 +460,7 @@ static void fbnic_get_stats64(struct net_device *dev, · 24 unmodified lines | ||
| 460 | 460 | rx_packets = stats->packets; |
| 461 | 461 | rx_dropped = stats->dropped; |
| 462 | 462 | |
| 463 | − spin_lock(&fbd->hw_stats_lock); | |
| 463 | + spin_lock(&fbd->hw_stats.lock); | |
| 464 | 464 | /* Record drops for the host FIFOs. |
| 465 | 465 | * 4: network to Host, 6: BMC to Host |
| 466 | 466 | * Exclude the BMC and MC FIFOs as those stats may contain drops |
| @@ -480,7 +480,7 @@ static void fbnic_get_stats64(struct net_device *dev, · 13 unmodified lines | ||
| 480 | 480 | /* Report packets with errors */ |
| 481 | 481 | rx_errors += fbd->hw_stats.hw_q[i].rde_pkt_err.value; |
| 482 | 482 | } |
| 483 | − spin_unlock(&fbd->hw_stats_lock); | |
| 483 | + spin_unlock(&fbd->hw_stats.lock); | |
| 484 | 484 | |
| 485 | 485 | stats64->rx_bytes = rx_bytes; |
| 486 | 486 | stats64->rx_packets = rx_packets; |
| @@ -608,12 +608,12 @@ static void fbnic_get_queue_stats_rx(struct net_device *dev, int idx, · 121 unmodified lines | ||
| 608 | 608 | |
| 609 | 609 | fbnic_get_hw_q_stats(fbd, fbd->hw_stats.hw_q); |
| 610 | 610 | |
| 611 | − spin_lock(&fbd->hw_stats_lock); | |
| 611 | + spin_lock(&fbd->hw_stats.lock); | |
| 612 | 612 | rx->hw_drop_overruns = fbd->hw_stats.hw_q[idx].rde_pkt_cq_drop.value + |
| 613 | 613 | fbd->hw_stats.hw_q[idx].rde_pkt_bdq_drop.value; |
| 614 | 614 | rx->hw_drops = fbd->hw_stats.hw_q[idx].rde_pkt_err.value + |
| 615 | 615 | rx->hw_drop_overruns; |
| 616 | − spin_unlock(&fbd->hw_stats_lock); | |
| 616 | + spin_unlock(&fbd->hw_stats.lock); | |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | static void fbnic_get_queue_stats_tx(struct net_device *dev, int idx, |
| @@ -304,10 +304,9 @@ static int fbnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · 303 unmodified lines | ||
| 304 | 304 | |
| 305 | 305 | fbnic_devlink_register(fbd); |
| 306 | 306 | fbnic_dbg_fbd_init(fbd); |
| 307 | − spin_lock_init(&fbd->hw_stats_lock); | |
| 308 | 307 | |
| 309 | 308 | /* Capture snapshot of hardware stats so netdev can calculate delta */ |
| 310 | − fbnic_reset_hw_stats(fbd); | |
| 309 | + fbnic_init_hw_stats(fbd); | |
| 311 | 310 | |
| 312 | 311 | fbnic_hwmon_register(fbd); |
| 313 | 312 | |
| @@ -492,6 +491,10 @@ static void __fbnic_pm_attach(struct device *dev) · 178 unmodified lines | ||
| 492 | 491 | struct net_device *netdev = fbd->netdev; |
| 493 | 492 | struct fbnic_net *fbn; |
| 494 | 493 | |
| 494 | + rtnl_lock(); | |
| 495 | + fbnic_reset_hw_stats(fbd); | |
| 496 | + rtnl_unlock(); | |
| 497 | + | |
| 495 | 498 | if (fbnic_init_failure(fbd)) |
| 496 | 499 | return; |
| 497 | 500 | |