18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright(c) 2017 - 2019 Pensando Systems, Inc */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include <linux/kernel.h> 58c2ecf20Sopenharmony_ci#include <linux/mutex.h> 68c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include "ionic.h" 98c2ecf20Sopenharmony_ci#include "ionic_lif.h" 108c2ecf20Sopenharmony_ci#include "ionic_stats.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistatic const struct ionic_stat_desc ionic_lif_stats_desc[] = { 138c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(tx_packets), 148c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(tx_bytes), 158c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(rx_packets), 168c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(rx_bytes), 178c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(tx_tso), 188c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(tx_tso_bytes), 198c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(tx_csum_none), 208c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(tx_csum), 218c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(rx_csum_none), 228c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(rx_csum_complete), 238c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(rx_csum_error), 248c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(hw_tx_dropped), 258c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(hw_rx_dropped), 268c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(hw_rx_over_errors), 278c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(hw_rx_missed_errors), 288c2ecf20Sopenharmony_ci IONIC_LIF_STAT_DESC(hw_tx_aborted_errors), 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic const struct ionic_stat_desc ionic_port_stats_desc[] = { 328c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_ok), 338c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_all), 348c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_bad_fcs), 358c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_bad_all), 368c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(octets_rx_ok), 378c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(octets_rx_all), 388c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_unicast), 398c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_multicast), 408c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_broadcast), 418c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pause), 428c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_bad_length), 438c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_undersized), 448c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_oversized), 458c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_fragments), 468c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_jabber), 478c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pripause), 488c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_stomped_crc), 498c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_too_long), 508c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_vlan_good), 518c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_dropped), 528c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_less_than_64b), 538c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_64b), 548c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_65b_127b), 558c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_128b_255b), 568c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_256b_511b), 578c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_512b_1023b), 588c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_1024b_1518b), 598c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_1519b_2047b), 608c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_2048b_4095b), 618c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_4096b_8191b), 628c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_8192b_9215b), 638c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_other), 648c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_ok), 658c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_all), 668c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_bad), 678c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(octets_tx_ok), 688c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(octets_tx_total), 698c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_unicast), 708c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_multicast), 718c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_broadcast), 728c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pause), 738c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pripause), 748c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_vlan), 758c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_less_than_64b), 768c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_64b), 778c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_65b_127b), 788c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_128b_255b), 798c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_256b_511b), 808c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_512b_1023b), 818c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_1024b_1518b), 828c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_1519b_2047b), 838c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_2048b_4095b), 848c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_4096b_8191b), 858c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_8192b_9215b), 868c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_other), 878c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pri_0), 888c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pri_1), 898c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pri_2), 908c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pri_3), 918c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pri_4), 928c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pri_5), 938c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pri_6), 948c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_pri_7), 958c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pri_0), 968c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pri_1), 978c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pri_2), 988c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pri_3), 998c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pri_4), 1008c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pri_5), 1018c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pri_6), 1028c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_rx_pri_7), 1038c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(tx_pripause_0_1us_count), 1048c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(tx_pripause_1_1us_count), 1058c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(tx_pripause_2_1us_count), 1068c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(tx_pripause_3_1us_count), 1078c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(tx_pripause_4_1us_count), 1088c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(tx_pripause_5_1us_count), 1098c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(tx_pripause_6_1us_count), 1108c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(tx_pripause_7_1us_count), 1118c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(rx_pripause_0_1us_count), 1128c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(rx_pripause_1_1us_count), 1138c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(rx_pripause_2_1us_count), 1148c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(rx_pripause_3_1us_count), 1158c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(rx_pripause_4_1us_count), 1168c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(rx_pripause_5_1us_count), 1178c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(rx_pripause_6_1us_count), 1188c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(rx_pripause_7_1us_count), 1198c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(rx_pause_1us_count), 1208c2ecf20Sopenharmony_ci IONIC_PORT_STAT_DESC(frames_tx_truncated), 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistatic const struct ionic_stat_desc ionic_tx_stats_desc[] = { 1248c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(pkts), 1258c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(bytes), 1268c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(clean), 1278c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(dma_map_err), 1288c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(linearize), 1298c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(frags), 1308c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(tso), 1318c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(tso_bytes), 1328c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(csum_none), 1338c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(csum), 1348c2ecf20Sopenharmony_ci IONIC_TX_STAT_DESC(vlan_inserted), 1358c2ecf20Sopenharmony_ci}; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistatic const struct ionic_stat_desc ionic_rx_stats_desc[] = { 1388c2ecf20Sopenharmony_ci IONIC_RX_STAT_DESC(pkts), 1398c2ecf20Sopenharmony_ci IONIC_RX_STAT_DESC(bytes), 1408c2ecf20Sopenharmony_ci IONIC_RX_STAT_DESC(dma_map_err), 1418c2ecf20Sopenharmony_ci IONIC_RX_STAT_DESC(alloc_err), 1428c2ecf20Sopenharmony_ci IONIC_RX_STAT_DESC(csum_none), 1438c2ecf20Sopenharmony_ci IONIC_RX_STAT_DESC(csum_complete), 1448c2ecf20Sopenharmony_ci IONIC_RX_STAT_DESC(csum_error), 1458c2ecf20Sopenharmony_ci IONIC_RX_STAT_DESC(dropped), 1468c2ecf20Sopenharmony_ci IONIC_RX_STAT_DESC(vlan_stripped), 1478c2ecf20Sopenharmony_ci}; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic const struct ionic_stat_desc ionic_txq_stats_desc[] = { 1508c2ecf20Sopenharmony_ci IONIC_TX_Q_STAT_DESC(stop), 1518c2ecf20Sopenharmony_ci IONIC_TX_Q_STAT_DESC(wake), 1528c2ecf20Sopenharmony_ci IONIC_TX_Q_STAT_DESC(drop), 1538c2ecf20Sopenharmony_ci IONIC_TX_Q_STAT_DESC(dbell_count), 1548c2ecf20Sopenharmony_ci}; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistatic const struct ionic_stat_desc ionic_dbg_cq_stats_desc[] = { 1578c2ecf20Sopenharmony_ci IONIC_CQ_STAT_DESC(compl_count), 1588c2ecf20Sopenharmony_ci}; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_cistatic const struct ionic_stat_desc ionic_dbg_intr_stats_desc[] = { 1618c2ecf20Sopenharmony_ci IONIC_INTR_STAT_DESC(rearm_count), 1628c2ecf20Sopenharmony_ci}; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistatic const struct ionic_stat_desc ionic_dbg_napi_stats_desc[] = { 1658c2ecf20Sopenharmony_ci IONIC_NAPI_STAT_DESC(poll_count), 1668c2ecf20Sopenharmony_ci}; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci#define IONIC_NUM_LIF_STATS ARRAY_SIZE(ionic_lif_stats_desc) 1698c2ecf20Sopenharmony_ci#define IONIC_NUM_PORT_STATS ARRAY_SIZE(ionic_port_stats_desc) 1708c2ecf20Sopenharmony_ci#define IONIC_NUM_TX_STATS ARRAY_SIZE(ionic_tx_stats_desc) 1718c2ecf20Sopenharmony_ci#define IONIC_NUM_RX_STATS ARRAY_SIZE(ionic_rx_stats_desc) 1728c2ecf20Sopenharmony_ci#define IONIC_NUM_TX_Q_STATS ARRAY_SIZE(ionic_txq_stats_desc) 1738c2ecf20Sopenharmony_ci#define IONIC_NUM_DBG_CQ_STATS ARRAY_SIZE(ionic_dbg_cq_stats_desc) 1748c2ecf20Sopenharmony_ci#define IONIC_NUM_DBG_INTR_STATS ARRAY_SIZE(ionic_dbg_intr_stats_desc) 1758c2ecf20Sopenharmony_ci#define IONIC_NUM_DBG_NAPI_STATS ARRAY_SIZE(ionic_dbg_napi_stats_desc) 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci#define MAX_Q(lif) ((lif)->netdev->real_num_tx_queues) 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistatic void ionic_get_lif_stats(struct ionic_lif *lif, 1808c2ecf20Sopenharmony_ci struct ionic_lif_sw_stats *stats) 1818c2ecf20Sopenharmony_ci{ 1828c2ecf20Sopenharmony_ci struct ionic_tx_stats *txstats; 1838c2ecf20Sopenharmony_ci struct ionic_rx_stats *rxstats; 1848c2ecf20Sopenharmony_ci struct rtnl_link_stats64 ns; 1858c2ecf20Sopenharmony_ci int q_num; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci memset(stats, 0, sizeof(*stats)); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci for (q_num = 0; q_num < MAX_Q(lif); q_num++) { 1908c2ecf20Sopenharmony_ci txstats = &lif->txqstats[q_num]; 1918c2ecf20Sopenharmony_ci stats->tx_packets += txstats->pkts; 1928c2ecf20Sopenharmony_ci stats->tx_bytes += txstats->bytes; 1938c2ecf20Sopenharmony_ci stats->tx_tso += txstats->tso; 1948c2ecf20Sopenharmony_ci stats->tx_tso_bytes += txstats->tso_bytes; 1958c2ecf20Sopenharmony_ci stats->tx_csum_none += txstats->csum_none; 1968c2ecf20Sopenharmony_ci stats->tx_csum += txstats->csum; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci rxstats = &lif->rxqstats[q_num]; 1998c2ecf20Sopenharmony_ci stats->rx_packets += rxstats->pkts; 2008c2ecf20Sopenharmony_ci stats->rx_bytes += rxstats->bytes; 2018c2ecf20Sopenharmony_ci stats->rx_csum_none += rxstats->csum_none; 2028c2ecf20Sopenharmony_ci stats->rx_csum_complete += rxstats->csum_complete; 2038c2ecf20Sopenharmony_ci stats->rx_csum_error += rxstats->csum_error; 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci ionic_get_stats64(lif->netdev, &ns); 2078c2ecf20Sopenharmony_ci stats->hw_tx_dropped = ns.tx_dropped; 2088c2ecf20Sopenharmony_ci stats->hw_rx_dropped = ns.rx_dropped; 2098c2ecf20Sopenharmony_ci stats->hw_rx_over_errors = ns.rx_over_errors; 2108c2ecf20Sopenharmony_ci stats->hw_rx_missed_errors = ns.rx_missed_errors; 2118c2ecf20Sopenharmony_ci stats->hw_tx_aborted_errors = ns.tx_aborted_errors; 2128c2ecf20Sopenharmony_ci} 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistatic u64 ionic_sw_stats_get_count(struct ionic_lif *lif) 2158c2ecf20Sopenharmony_ci{ 2168c2ecf20Sopenharmony_ci u64 total = 0; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci /* lif stats */ 2198c2ecf20Sopenharmony_ci total += IONIC_NUM_LIF_STATS; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci /* tx stats */ 2228c2ecf20Sopenharmony_ci total += MAX_Q(lif) * IONIC_NUM_TX_STATS; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci /* rx stats */ 2258c2ecf20Sopenharmony_ci total += MAX_Q(lif) * IONIC_NUM_RX_STATS; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci /* port stats */ 2288c2ecf20Sopenharmony_ci total += IONIC_NUM_PORT_STATS; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci if (test_bit(IONIC_LIF_F_UP, lif->state) && 2318c2ecf20Sopenharmony_ci test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state)) { 2328c2ecf20Sopenharmony_ci /* tx debug stats */ 2338c2ecf20Sopenharmony_ci total += MAX_Q(lif) * (IONIC_NUM_DBG_CQ_STATS + 2348c2ecf20Sopenharmony_ci IONIC_NUM_TX_Q_STATS + 2358c2ecf20Sopenharmony_ci IONIC_NUM_DBG_INTR_STATS + 2368c2ecf20Sopenharmony_ci IONIC_MAX_NUM_SG_CNTR); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci /* rx debug stats */ 2398c2ecf20Sopenharmony_ci total += MAX_Q(lif) * (IONIC_NUM_DBG_CQ_STATS + 2408c2ecf20Sopenharmony_ci IONIC_NUM_DBG_INTR_STATS + 2418c2ecf20Sopenharmony_ci IONIC_NUM_DBG_NAPI_STATS + 2428c2ecf20Sopenharmony_ci IONIC_MAX_NUM_NAPI_CNTR); 2438c2ecf20Sopenharmony_ci } 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci return total; 2468c2ecf20Sopenharmony_ci} 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_cistatic void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf) 2498c2ecf20Sopenharmony_ci{ 2508c2ecf20Sopenharmony_ci int i, q_num; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_LIF_STATS; i++) { 2538c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, ionic_lif_stats_desc[i].name); 2548c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_PORT_STATS; i++) { 2588c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 2598c2ecf20Sopenharmony_ci ionic_port_stats_desc[i].name); 2608c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 2618c2ecf20Sopenharmony_ci } 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci for (q_num = 0; q_num < MAX_Q(lif); q_num++) { 2648c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_TX_STATS; i++) { 2658c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, "tx_%d_%s", 2668c2ecf20Sopenharmony_ci q_num, ionic_tx_stats_desc[i].name); 2678c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 2688c2ecf20Sopenharmony_ci } 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci if (test_bit(IONIC_LIF_F_UP, lif->state) && 2718c2ecf20Sopenharmony_ci test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state)) { 2728c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++) { 2738c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 2748c2ecf20Sopenharmony_ci "txq_%d_%s", 2758c2ecf20Sopenharmony_ci q_num, 2768c2ecf20Sopenharmony_ci ionic_txq_stats_desc[i].name); 2778c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 2788c2ecf20Sopenharmony_ci } 2798c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) { 2808c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 2818c2ecf20Sopenharmony_ci "txq_%d_cq_%s", 2828c2ecf20Sopenharmony_ci q_num, 2838c2ecf20Sopenharmony_ci ionic_dbg_cq_stats_desc[i].name); 2848c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 2858c2ecf20Sopenharmony_ci } 2868c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_INTR_STATS; i++) { 2878c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 2888c2ecf20Sopenharmony_ci "txq_%d_intr_%s", 2898c2ecf20Sopenharmony_ci q_num, 2908c2ecf20Sopenharmony_ci ionic_dbg_intr_stats_desc[i].name); 2918c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 2928c2ecf20Sopenharmony_ci } 2938c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_MAX_NUM_SG_CNTR; i++) { 2948c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 2958c2ecf20Sopenharmony_ci "txq_%d_sg_cntr_%d", 2968c2ecf20Sopenharmony_ci q_num, i); 2978c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 2988c2ecf20Sopenharmony_ci } 2998c2ecf20Sopenharmony_ci } 3008c2ecf20Sopenharmony_ci } 3018c2ecf20Sopenharmony_ci for (q_num = 0; q_num < MAX_Q(lif); q_num++) { 3028c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_RX_STATS; i++) { 3038c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 3048c2ecf20Sopenharmony_ci "rx_%d_%s", 3058c2ecf20Sopenharmony_ci q_num, ionic_rx_stats_desc[i].name); 3068c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci if (test_bit(IONIC_LIF_F_UP, lif->state) && 3108c2ecf20Sopenharmony_ci test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state)) { 3118c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) { 3128c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 3138c2ecf20Sopenharmony_ci "rxq_%d_cq_%s", 3148c2ecf20Sopenharmony_ci q_num, 3158c2ecf20Sopenharmony_ci ionic_dbg_cq_stats_desc[i].name); 3168c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 3178c2ecf20Sopenharmony_ci } 3188c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_INTR_STATS; i++) { 3198c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 3208c2ecf20Sopenharmony_ci "rxq_%d_intr_%s", 3218c2ecf20Sopenharmony_ci q_num, 3228c2ecf20Sopenharmony_ci ionic_dbg_intr_stats_desc[i].name); 3238c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 3248c2ecf20Sopenharmony_ci } 3258c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_NAPI_STATS; i++) { 3268c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 3278c2ecf20Sopenharmony_ci "rxq_%d_napi_%s", 3288c2ecf20Sopenharmony_ci q_num, 3298c2ecf20Sopenharmony_ci ionic_dbg_napi_stats_desc[i].name); 3308c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 3318c2ecf20Sopenharmony_ci } 3328c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_MAX_NUM_NAPI_CNTR; i++) { 3338c2ecf20Sopenharmony_ci snprintf(*buf, ETH_GSTRING_LEN, 3348c2ecf20Sopenharmony_ci "rxq_%d_napi_work_done_%d", 3358c2ecf20Sopenharmony_ci q_num, i); 3368c2ecf20Sopenharmony_ci *buf += ETH_GSTRING_LEN; 3378c2ecf20Sopenharmony_ci } 3388c2ecf20Sopenharmony_ci } 3398c2ecf20Sopenharmony_ci } 3408c2ecf20Sopenharmony_ci} 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_cistatic void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf) 3438c2ecf20Sopenharmony_ci{ 3448c2ecf20Sopenharmony_ci struct ionic_port_stats *port_stats; 3458c2ecf20Sopenharmony_ci struct ionic_lif_sw_stats lif_stats; 3468c2ecf20Sopenharmony_ci struct ionic_qcq *txqcq, *rxqcq; 3478c2ecf20Sopenharmony_ci struct ionic_tx_stats *txstats; 3488c2ecf20Sopenharmony_ci struct ionic_rx_stats *rxstats; 3498c2ecf20Sopenharmony_ci int i, q_num; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci ionic_get_lif_stats(lif, &lif_stats); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_LIF_STATS; i++) { 3548c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT64(&lif_stats, &ionic_lif_stats_desc[i]); 3558c2ecf20Sopenharmony_ci (*buf)++; 3568c2ecf20Sopenharmony_ci } 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci port_stats = &lif->ionic->idev.port_info->stats; 3598c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_PORT_STATS; i++) { 3608c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT_LE64(port_stats, 3618c2ecf20Sopenharmony_ci &ionic_port_stats_desc[i]); 3628c2ecf20Sopenharmony_ci (*buf)++; 3638c2ecf20Sopenharmony_ci } 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci for (q_num = 0; q_num < MAX_Q(lif); q_num++) { 3668c2ecf20Sopenharmony_ci txstats = &lif->txqstats[q_num]; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_TX_STATS; i++) { 3698c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT64(txstats, 3708c2ecf20Sopenharmony_ci &ionic_tx_stats_desc[i]); 3718c2ecf20Sopenharmony_ci (*buf)++; 3728c2ecf20Sopenharmony_ci } 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci if (test_bit(IONIC_LIF_F_UP, lif->state) && 3758c2ecf20Sopenharmony_ci test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state)) { 3768c2ecf20Sopenharmony_ci txqcq = lif->txqcqs[q_num]; 3778c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++) { 3788c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT64(&txqcq->q, 3798c2ecf20Sopenharmony_ci &ionic_txq_stats_desc[i]); 3808c2ecf20Sopenharmony_ci (*buf)++; 3818c2ecf20Sopenharmony_ci } 3828c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) { 3838c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT64(&txqcq->cq, 3848c2ecf20Sopenharmony_ci &ionic_dbg_cq_stats_desc[i]); 3858c2ecf20Sopenharmony_ci (*buf)++; 3868c2ecf20Sopenharmony_ci } 3878c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_INTR_STATS; i++) { 3888c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT64(&txqcq->intr, 3898c2ecf20Sopenharmony_ci &ionic_dbg_intr_stats_desc[i]); 3908c2ecf20Sopenharmony_ci (*buf)++; 3918c2ecf20Sopenharmony_ci } 3928c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_MAX_NUM_SG_CNTR; i++) { 3938c2ecf20Sopenharmony_ci **buf = txstats->sg_cntr[i]; 3948c2ecf20Sopenharmony_ci (*buf)++; 3958c2ecf20Sopenharmony_ci } 3968c2ecf20Sopenharmony_ci } 3978c2ecf20Sopenharmony_ci } 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci for (q_num = 0; q_num < MAX_Q(lif); q_num++) { 4008c2ecf20Sopenharmony_ci rxstats = &lif->rxqstats[q_num]; 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_RX_STATS; i++) { 4038c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT64(rxstats, 4048c2ecf20Sopenharmony_ci &ionic_rx_stats_desc[i]); 4058c2ecf20Sopenharmony_ci (*buf)++; 4068c2ecf20Sopenharmony_ci } 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci if (test_bit(IONIC_LIF_F_UP, lif->state) && 4098c2ecf20Sopenharmony_ci test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state)) { 4108c2ecf20Sopenharmony_ci rxqcq = lif->rxqcqs[q_num]; 4118c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) { 4128c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT64(&rxqcq->cq, 4138c2ecf20Sopenharmony_ci &ionic_dbg_cq_stats_desc[i]); 4148c2ecf20Sopenharmony_ci (*buf)++; 4158c2ecf20Sopenharmony_ci } 4168c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_INTR_STATS; i++) { 4178c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT64(&rxqcq->intr, 4188c2ecf20Sopenharmony_ci &ionic_dbg_intr_stats_desc[i]); 4198c2ecf20Sopenharmony_ci (*buf)++; 4208c2ecf20Sopenharmony_ci } 4218c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_NUM_DBG_NAPI_STATS; i++) { 4228c2ecf20Sopenharmony_ci **buf = IONIC_READ_STAT64(&rxqcq->napi_stats, 4238c2ecf20Sopenharmony_ci &ionic_dbg_napi_stats_desc[i]); 4248c2ecf20Sopenharmony_ci (*buf)++; 4258c2ecf20Sopenharmony_ci } 4268c2ecf20Sopenharmony_ci for (i = 0; i < IONIC_MAX_NUM_NAPI_CNTR; i++) { 4278c2ecf20Sopenharmony_ci **buf = rxqcq->napi_stats.work_done_cntr[i]; 4288c2ecf20Sopenharmony_ci (*buf)++; 4298c2ecf20Sopenharmony_ci } 4308c2ecf20Sopenharmony_ci } 4318c2ecf20Sopenharmony_ci } 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ciconst struct ionic_stats_group_intf ionic_stats_groups[] = { 4358c2ecf20Sopenharmony_ci /* SW Stats group */ 4368c2ecf20Sopenharmony_ci { 4378c2ecf20Sopenharmony_ci .get_strings = ionic_sw_stats_get_strings, 4388c2ecf20Sopenharmony_ci .get_values = ionic_sw_stats_get_values, 4398c2ecf20Sopenharmony_ci .get_count = ionic_sw_stats_get_count, 4408c2ecf20Sopenharmony_ci }, 4418c2ecf20Sopenharmony_ci /* Add more stat groups here */ 4428c2ecf20Sopenharmony_ci}; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ciconst int ionic_num_stats_grps = ARRAY_SIZE(ionic_stats_groups); 445