LCOV - code coverage report
Current view: top level - drivers/net/sxe2 - sxe2_stats.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 318 0.0 %
Date: 2026-08-01 17:54:00 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 100 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (C), 2025, Wuxi Stars Micro System Technologies Co., Ltd.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_eal.h>
       6                 :            : 
       7                 :            : #include "sxe2_ethdev.h"
       8                 :            : #include "sxe2_vsi.h"
       9                 :            : #include "sxe2_common_log.h"
      10                 :            : #include "sxe2_stats.h"
      11                 :            : #include "sxe2_queue.h"
      12                 :            : #include "sxe2_cmd_chnl.h"
      13                 :            : #include "sxe2_mp.h"
      14                 :            : 
      15                 :            : #define SXE2_XSTAT_CNT_PF RTE_DIM(sxe2_xstats_field_pf)
      16                 :            : #define SXE2_XSTAT_CNT_VF RTE_DIM(sxe2_xstats_field_vf)
      17                 :            : 
      18                 :            : static struct sxe2_stats_field sxe2_xstats_field_pf[] = {
      19                 :            :         {"rx_qblock_drop", offsetof(struct sxe2_stats, rx_qblock_drop)},
      20                 :            :         {"rx_out_of_buffer", offsetof(struct sxe2_stats, rx_out_of_buffer)},
      21                 :            :         {"tx_packets_phy", offsetof(struct sxe2_stats, tx_frame_good)},
      22                 :            :         {"rx_packets_phy", offsetof(struct sxe2_stats, rx_frame_good)},
      23                 :            :         {"rx_crc_errors_phy", offsetof(struct sxe2_stats, rx_crc_errors)},
      24                 :            :         {"tx_bytes_phy", offsetof(struct sxe2_stats, tx_bytes_good)},
      25                 :            :         {"rx_bytes_phy", offsetof(struct sxe2_stats, rx_bytes_good)},
      26                 :            :         {"tx_multicast_phy", offsetof(struct sxe2_stats, tx_multicast_good)},
      27                 :            :         {"tx_broadcast_phy", offsetof(struct sxe2_stats, tx_broadcast_good)},
      28                 :            :         {"rx_multicast_phy", offsetof(struct sxe2_stats, rx_multicast_good)},
      29                 :            :         {"rx_broadcast_phy", offsetof(struct sxe2_stats, rx_broadcast_good)},
      30                 :            :         {"rx_in_range_len_errs_phy", offsetof(struct sxe2_stats, rx_len_errors)},
      31                 :            :         {"rx_out_of_range_len_phy", offsetof(struct sxe2_stats, rx_out_of_range_errors)},
      32                 :            :         {"rx_oversize_pkts_phy", offsetof(struct sxe2_stats, rx_oversize_pkts_phy)},
      33                 :            :         {"rx_symbol_err_phy", offsetof(struct sxe2_stats, rx_symbol_err)},
      34                 :            :         {"rx_pause_ctrl_phy", offsetof(struct sxe2_stats, rx_pause_frame)},
      35                 :            :         {"tx_pause_ctrl_phy", offsetof(struct sxe2_stats, tx_pause_frame)},
      36                 :            :         {"rx_discards_phy", offsetof(struct sxe2_stats, rx_discards_phy)},
      37                 :            :         {"rx_discards_ips_phy", offsetof(struct sxe2_stats, rx_discards_ips_phy)},
      38                 :            :         {"tx_dropped_link_down_phy", offsetof(struct sxe2_stats, tx_dropped_link_down)},
      39                 :            :         {"rx_undersize_pkts_phy", offsetof(struct sxe2_stats, rx_undersize_good)},
      40                 :            :         {"rx_fragments_phy", offsetof(struct sxe2_stats, rx_runt_error)},
      41                 :            :         {"tx_bytes_all_phy", offsetof(struct sxe2_stats, tx_bytes_good_bad)},
      42                 :            :         {"tx_packets_all_phy", offsetof(struct sxe2_stats, tx_frame_good_bad)},
      43                 :            :         {"rx_jabbers_phy", offsetof(struct sxe2_stats, rx_jabbers)},
      44                 :            :         {"rx_64_bytes_phy", offsetof(struct sxe2_stats, rx_size_64)},
      45                 :            :         {"rx_65_to_127_bytes_phy", offsetof(struct sxe2_stats, rx_size_65_127)},
      46                 :            :         {"rx_128_to_255_bytes_phy", offsetof(struct sxe2_stats, rx_size_128_255)},
      47                 :            :         {"rx_256_to_511_bytes_phy", offsetof(struct sxe2_stats, rx_size_256_511)},
      48                 :            :         {"rx_512_to_1023_bytes_phy", offsetof(struct sxe2_stats, rx_size_512_1023)},
      49                 :            :         {"rx_1024_to_1522_bytes_phy", offsetof(struct sxe2_stats, rx_size_1024_1522)},
      50                 :            :         {"rx_1523_to_max_bytes_phy", offsetof(struct sxe2_stats, rx_size_1523_max)},
      51                 :            :         {"rx_pcs_symbol_err_phy", offsetof(struct sxe2_stats, rx_pcs_symbol_err_phy)},
      52                 :            :         {"rx_corrected_bits_phy", offsetof(struct sxe2_stats, rx_corrected_bits_phy)},
      53                 :            :         {"rx_err_lane_0_phy", offsetof(struct sxe2_stats, rx_err_lane_0_phy)},
      54                 :            :         {"rx_err_lane_1_phy", offsetof(struct sxe2_stats, rx_err_lane_1_phy)},
      55                 :            :         {"rx_err_lane_2_phy", offsetof(struct sxe2_stats, rx_err_lane_2_phy)},
      56                 :            :         {"rx_err_lane_3_phy", offsetof(struct sxe2_stats, rx_err_lane_3_phy)},
      57                 :            :         {"rx_illegal_bytes_phy", offsetof(struct sxe2_stats, rx_illegal_bytes)},
      58                 :            :         {"rx_oversize_good_phy", offsetof(struct sxe2_stats, rx_oversize_good)},
      59                 :            :         {"tx_unicast_all_phy", offsetof(struct sxe2_stats, tx_unicast)},
      60                 :            :         {"tx_broadcast_all_phy", offsetof(struct sxe2_stats, tx_broadcast)},
      61                 :            :         {"tx_multicast_all_phy", offsetof(struct sxe2_stats, tx_multicast)},
      62                 :            :         {"tx_vlan_packets_good_phy", offsetof(struct sxe2_stats, tx_vlan_packet_good)},
      63                 :            :         {"tx_64_bytes_phy", offsetof(struct sxe2_stats, tx_size_64)},
      64                 :            :         {"tx_65_to_127_bytes_phy", offsetof(struct sxe2_stats, tx_size_65_127)},
      65                 :            :         {"tx_128_to_255_bytes_phy", offsetof(struct sxe2_stats, tx_size_128_255)},
      66                 :            :         {"tx_256_to_511_bytes_phy", offsetof(struct sxe2_stats, tx_size_256_511)},
      67                 :            :         {"tx_512_to_1023_bytes_phy", offsetof(struct sxe2_stats, tx_size_512_1023)},
      68                 :            :         {"tx_1024_to_1522_bytes_phy", offsetof(struct sxe2_stats, tx_size_1024_1522)},
      69                 :            :         {"tx_1523_to_max_bytes_phy", offsetof(struct sxe2_stats, tx_size_1523_max)},
      70                 :            :         {"tx_underflow_error_phy", offsetof(struct sxe2_stats, tx_underflow_error)},
      71                 :            :         {"rx_bytes_all_phy", offsetof(struct sxe2_stats, rx_byte_good_bad)},
      72                 :            :         {"rx_packets_all_phy", offsetof(struct sxe2_stats, rx_frame_good_bad)},
      73                 :            :         {"rx_unicast_phy", offsetof(struct sxe2_stats, rx_unicast_good)},
      74                 :            :         {"rx_vlan_packets_phy", offsetof(struct sxe2_stats, rx_vlan_packets)},
      75                 :            : 
      76                 :            :         {"rx_vport_bytes",             offsetof(struct sxe2_stats, rx_vsi_bytes)},
      77                 :            :         {"rx_vport_unicast_packets",   offsetof(struct sxe2_stats, rx_vsi_unicast_packets)},
      78                 :            :         {"rx_vport_broadcast_packets", offsetof(struct sxe2_stats, rx_vsi_broadcast_packets)},
      79                 :            :         {"rx_vport_multicast_packets", offsetof(struct sxe2_stats, rx_vsi_multicast_packets)},
      80                 :            :         {"rx_sw_unicast_packets",      offsetof(struct sxe2_stats, rx_sw_unicast_packets)},
      81                 :            :         {"rx_sw_broadcast_packets",    offsetof(struct sxe2_stats, rx_sw_broadcast_packets)},
      82                 :            :         {"rx_sw_multicast_packets",    offsetof(struct sxe2_stats, rx_sw_multicast_packets)},
      83                 :            :         {"rx_sw_drop_packets",         offsetof(struct sxe2_stats, rx_sw_drop_packets)},
      84                 :            :         {"rx_sw_drop_bytes",           offsetof(struct sxe2_stats, rx_sw_drop_bytes)},
      85                 :            : 
      86                 :            :         {"tx_vport_bytes",             offsetof(struct sxe2_stats, tx_vsi_bytes)},
      87                 :            :         {"tx_vport_unicast_packets",   offsetof(struct sxe2_stats, tx_vsi_unicast_packets)},
      88                 :            :         {"tx_vport_broadcast_packets", offsetof(struct sxe2_stats, tx_vsi_broadcast_packets)},
      89                 :            :         {"tx_vport_multicast_packets", offsetof(struct sxe2_stats, tx_vsi_multicast_packets)},
      90                 :            : };
      91                 :            : 
      92                 :            : static struct sxe2_stats_field sxe2_xstats_field_vf[] = {
      93                 :            :         {"rx_vport_bytes",             offsetof(struct sxe2_stats, rx_vsi_bytes)},
      94                 :            :         {"rx_vport_unicast_packets",   offsetof(struct sxe2_stats, rx_vsi_unicast_packets)},
      95                 :            :         {"rx_vport_broadcast_packets", offsetof(struct sxe2_stats, rx_vsi_broadcast_packets)},
      96                 :            :         {"rx_vport_multicast_packets", offsetof(struct sxe2_stats, rx_vsi_multicast_packets)},
      97                 :            :         {"rx_sw_unicast_packets",      offsetof(struct sxe2_stats, rx_sw_unicast_packets)},
      98                 :            :         {"rx_sw_broadcast_packets",    offsetof(struct sxe2_stats, rx_sw_broadcast_packets)},
      99                 :            :         {"rx_sw_multicast_packets",    offsetof(struct sxe2_stats, rx_sw_multicast_packets)},
     100                 :            :         {"rx_sw_drop_packets",         offsetof(struct sxe2_stats, rx_sw_drop_packets)},
     101                 :            :         {"rx_sw_drop_bytes",           offsetof(struct sxe2_stats, rx_sw_drop_bytes)},
     102                 :            : 
     103                 :            :         {"tx_vport_bytes",             offsetof(struct sxe2_stats, tx_vsi_bytes)},
     104                 :            :         {"tx_vport_unicast_packets",   offsetof(struct sxe2_stats, tx_vsi_unicast_packets)},
     105                 :            :         {"tx_vport_broadcast_packets", offsetof(struct sxe2_stats, tx_vsi_broadcast_packets)},
     106                 :            :         {"tx_vport_multicast_packets", offsetof(struct sxe2_stats, tx_vsi_multicast_packets)},
     107                 :            : };
     108                 :            : 
     109                 :          0 : static int32_t sxe2_xstat_pf_offset_get(uint32_t id, uint32_t *offset)
     110                 :            : {
     111                 :          0 :         int32_t ret  = 0;
     112                 :          0 :         uint32_t size = SXE2_XSTAT_CNT_PF;
     113                 :            : 
     114         [ #  # ]:          0 :         if (id < size) {
     115                 :          0 :                 *offset = sxe2_xstats_field_pf[id].offset;
     116                 :            :         } else {
     117                 :          0 :                 ret = -EINVAL;
     118                 :          0 :                 PMD_LOG_ERR(DRV, "invalid id:%u exceed stats size cnt:%u", id, size);
     119                 :            :         }
     120                 :          0 :         return ret;
     121                 :            : }
     122                 :            : 
     123                 :          0 : static int32_t sxe2_xstat_vf_offset_get(uint32_t id, uint32_t *offset)
     124                 :            : {
     125                 :          0 :         int32_t ret  = 0;
     126                 :          0 :         uint32_t size = SXE2_XSTAT_CNT_VF;
     127                 :            : 
     128         [ #  # ]:          0 :         if (id < size) {
     129                 :          0 :                 *offset = sxe2_xstats_field_vf[id].offset;
     130                 :            :         } else {
     131                 :          0 :                 ret = -EINVAL;
     132                 :          0 :                 PMD_LOG_ERR(DRV, "invalid id:%u exceed stats size cnt:%u", id, size);
     133                 :            :         }
     134                 :          0 :         return ret;
     135                 :            : }
     136                 :            : 
     137                 :          0 : static int32_t sxe2_mac_hw_stats_get_update(struct sxe2_adapter *adapter)
     138                 :            : {
     139                 :          0 :         int32_t ret = 0;
     140                 :            : 
     141                 :          0 :         ret = sxe2_drv_get_mac_stats(adapter);
     142         [ #  # ]:          0 :         if (ret) {
     143                 :          0 :                 PMD_LOG_ERR(DRV, "get mac stats failed, ret:%d.", ret);
     144                 :          0 :                 goto l_end;
     145                 :            :         }
     146                 :            : 
     147                 :          0 : l_end:
     148                 :          0 :         return ret;
     149                 :            : }
     150                 :            : 
     151                 :          0 : static int32_t sxe2_vsi_hw_stats_get_update(struct sxe2_adapter *adapter)
     152                 :            : {
     153                 :          0 :         int32_t ret = 0;
     154                 :            : 
     155                 :          0 :         ret = sxe2_drv_get_vsi_stats(adapter);
     156         [ #  # ]:          0 :         if (ret) {
     157         [ #  # ]:          0 :                 if (adapter->is_dev_repr) {
     158                 :          0 :                         PMD_LOG_WARN(DRV, "get repr vsi stats failed, ret:%d.", ret);
     159                 :          0 :                         ret = 0;
     160                 :            :                 } else {
     161                 :          0 :                         PMD_LOG_ERR(DRV, "get vsi stats failed, ret:%d.", ret);
     162                 :            :                 }
     163                 :          0 :                 goto l_end;
     164                 :            :         }
     165                 :            : 
     166                 :          0 : l_end:
     167                 :          0 :         return ret;
     168                 :            : }
     169                 :            : 
     170                 :          0 : static int32_t sxe2_vsi_sw_stats_get_update(struct sxe2_adapter *adapter)
     171                 :            : {
     172                 :          0 :         int32_t ret  = 0;
     173                 :          0 :         struct sxe2_vsi          *vsi      = adapter->vsi_ctxt.main_vsi;
     174                 :          0 :         struct sxe2_stats        *sw_stats = &vsi->vsi_stats.vsi_sw_stats;
     175                 :          0 :         struct sxe2_rx_queue     *rxq;
     176                 :          0 :         uint32_t rx_queue_id;
     177                 :          0 :         memset(sw_stats, 0, sizeof(struct sxe2_stats));
     178                 :            : 
     179         [ #  # ]:          0 :         for (rx_queue_id = 0; rx_queue_id < adapter->dev_info.dev_data->nb_rx_queues;
     180                 :          0 :                      rx_queue_id++) {
     181                 :          0 :                 rxq = adapter->dev_info.dev_data->rx_queues[rx_queue_id];
     182         [ #  # ]:          0 :                 if (rxq) {
     183                 :          0 :                         sw_stats->ipackets += rxq->sw_stats.pkts;
     184                 :          0 :                         sw_stats->ierrors += rxq->sw_stats.drop_pkts;
     185                 :          0 :                         sw_stats->ibytes += rxq->sw_stats.bytes;
     186                 :            : 
     187                 :          0 :                         sw_stats->rx_sw_unicast_packets += rxq->sw_stats.unicast_pkts;
     188                 :          0 :                         sw_stats->rx_sw_broadcast_packets += rxq->sw_stats.broadcast_pkts;
     189                 :          0 :                         sw_stats->rx_sw_multicast_packets += rxq->sw_stats.multicast_pkts;
     190                 :          0 :                         sw_stats->rx_sw_drop_packets += rxq->sw_stats.drop_pkts;
     191                 :          0 :                         sw_stats->rx_sw_drop_bytes += rxq->sw_stats.drop_bytes;
     192                 :            :                 }
     193                 :            :         }
     194                 :            : 
     195                 :          0 :         return ret;
     196                 :            : }
     197                 :            : 
     198                 :          0 : static void sxe2_stats_update(struct sxe2_adapter *adapter)
     199                 :            : {
     200                 :          0 :         struct sxe2_vsi          *vsi      = adapter->vsi_ctxt.main_vsi;
     201                 :          0 :         struct sxe2_stats        *stats = &vsi->vsi_stats.stats;
     202                 :          0 :         struct sxe2_stats        *hw_stats = &vsi->vsi_stats.vsi_hw_stats;
     203                 :          0 :         struct sxe2_stats        *sw_stats = &vsi->vsi_stats.vsi_sw_stats;
     204                 :          0 :         struct sxe2_stats        *sw_stats_prev = &vsi->vsi_stats.vsi_sw_stats_prev;
     205                 :          0 :         uint8_t i = 0;
     206                 :            : 
     207         [ #  # ]:          0 :         memset(stats, 0, sizeof(struct sxe2_stats));
     208                 :            : 
     209                 :          0 :         stats->opackets = hw_stats->opackets;
     210                 :          0 :         stats->obytes   = hw_stats->tx_vsi_bytes;
     211                 :          0 :         stats->tx_vsi_bytes             = hw_stats->tx_vsi_bytes;
     212                 :          0 :         stats->tx_vsi_unicast_packets   = hw_stats->tx_vsi_unicast_packets;
     213                 :          0 :         stats->tx_vsi_broadcast_packets = hw_stats->tx_vsi_broadcast_packets;
     214                 :          0 :         stats->tx_vsi_multicast_packets = hw_stats->tx_vsi_multicast_packets;
     215                 :            : 
     216                 :          0 :         stats->ierrors = sw_stats->ierrors + sw_stats_prev->ierrors;
     217                 :          0 :         stats->ipackets = sw_stats->ipackets + sw_stats_prev->ipackets;
     218                 :          0 :         stats->ibytes = sw_stats->ibytes + sw_stats_prev->ibytes;
     219                 :          0 :         stats->rx_vsi_bytes             = hw_stats->rx_vsi_bytes;
     220                 :          0 :         stats->rx_vsi_unicast_packets   = hw_stats->rx_vsi_unicast_packets;
     221                 :          0 :         stats->rx_vsi_broadcast_packets = hw_stats->rx_vsi_broadcast_packets;
     222                 :          0 :         stats->rx_vsi_multicast_packets = hw_stats->rx_vsi_multicast_packets;
     223                 :          0 :         stats->rx_sw_unicast_packets = sw_stats->rx_sw_unicast_packets +
     224                 :          0 :                         sw_stats_prev->rx_sw_unicast_packets;
     225                 :          0 :         stats->rx_sw_broadcast_packets = sw_stats->rx_sw_broadcast_packets +
     226                 :          0 :                         sw_stats_prev->rx_sw_broadcast_packets;
     227                 :          0 :         stats->rx_sw_multicast_packets = sw_stats->rx_sw_multicast_packets +
     228                 :          0 :                         sw_stats_prev->rx_sw_multicast_packets;
     229                 :          0 :         stats->rx_sw_drop_packets = sw_stats->rx_sw_drop_packets +
     230                 :          0 :                         sw_stats_prev->rx_sw_drop_packets;
     231                 :          0 :         stats->rx_sw_drop_bytes = sw_stats->rx_sw_drop_bytes +
     232                 :          0 :                         sw_stats_prev->rx_sw_drop_bytes;
     233                 :            : 
     234   [ #  #  #  # ]:          0 :         if (adapter->dev_type != SXE2_DEV_T_VF  && !adapter->is_dev_repr) {
     235                 :          0 :                 stats->rx_out_of_buffer = hw_stats->rx_out_of_buffer;
     236                 :          0 :                 stats->rx_qblock_drop = hw_stats->rx_qblock_drop;
     237                 :          0 :                 stats->tx_frame_good = hw_stats->tx_frame_good;
     238                 :          0 :                 stats->rx_frame_good = hw_stats->rx_frame_good;
     239                 :          0 :                 stats->rx_crc_errors = hw_stats->rx_crc_errors;
     240                 :          0 :                 stats->tx_bytes_good = hw_stats->tx_bytes_good;
     241                 :          0 :                 stats->rx_bytes_good = hw_stats->rx_bytes_good;
     242                 :          0 :                 stats->tx_multicast_good = hw_stats->tx_multicast_good;
     243                 :          0 :                 stats->tx_broadcast_good = hw_stats->tx_broadcast_good;
     244                 :          0 :                 stats->rx_multicast_good = hw_stats->rx_multicast_good;
     245                 :          0 :                 stats->rx_broadcast_good = hw_stats->rx_broadcast_good;
     246                 :          0 :                 stats->rx_len_errors = hw_stats->rx_len_errors;
     247                 :          0 :                 stats->rx_out_of_range_errors = hw_stats->rx_out_of_range_errors;
     248                 :          0 :                 stats->rx_oversize_pkts_phy = hw_stats->rx_oversize_pkts_phy;
     249                 :          0 :                 stats->rx_symbol_err = hw_stats->rx_symbol_err;
     250                 :          0 :                 stats->rx_pause_frame = hw_stats->rx_pause_frame;
     251                 :          0 :                 stats->tx_pause_frame = hw_stats->tx_pause_frame;
     252                 :          0 :                 stats->rx_discards_phy = hw_stats->rx_discards_phy;
     253                 :          0 :                 stats->rx_discards_ips_phy = hw_stats->rx_discards_ips_phy;
     254                 :          0 :                 stats->tx_dropped_link_down = hw_stats->tx_dropped_link_down;
     255                 :          0 :                 stats->rx_undersize_good = hw_stats->rx_undersize_good;
     256                 :          0 :                 stats->rx_runt_error = hw_stats->rx_runt_error;
     257                 :          0 :                 stats->tx_bytes_good_bad = hw_stats->tx_bytes_good_bad;
     258                 :          0 :                 stats->tx_frame_good_bad = hw_stats->tx_frame_good_bad;
     259                 :          0 :                 stats->rx_jabbers = hw_stats->rx_jabbers;
     260                 :          0 :                 stats->rx_size_64 = hw_stats->rx_size_64;
     261                 :          0 :                 stats->rx_size_65_127 = hw_stats->rx_size_65_127;
     262                 :          0 :                 stats->rx_size_128_255 = hw_stats->rx_size_128_255;
     263                 :          0 :                 stats->rx_size_256_511 = hw_stats->rx_size_256_511;
     264                 :          0 :                 stats->rx_size_512_1023 = hw_stats->rx_size_512_1023;
     265                 :          0 :                 stats->rx_size_1024_1522 = hw_stats->rx_size_1024_1522;
     266                 :          0 :                 stats->rx_size_1523_max = hw_stats->rx_size_1523_max;
     267                 :          0 :                 stats->rx_pcs_symbol_err_phy = hw_stats->rx_pcs_symbol_err_phy;
     268                 :          0 :                 stats->rx_corrected_bits_phy = hw_stats->rx_corrected_bits_phy;
     269                 :          0 :                 stats->rx_err_lane_0_phy = hw_stats->rx_err_lane_0_phy;
     270                 :          0 :                 stats->rx_err_lane_1_phy = hw_stats->rx_err_lane_1_phy;
     271                 :          0 :                 stats->rx_err_lane_2_phy = hw_stats->rx_err_lane_2_phy;
     272                 :          0 :                 stats->rx_err_lane_3_phy = hw_stats->rx_err_lane_3_phy;
     273                 :          0 :                 stats->rx_illegal_bytes = hw_stats->rx_illegal_bytes;
     274                 :          0 :                 stats->rx_oversize_good = hw_stats->rx_oversize_good;
     275                 :          0 :                 stats->tx_unicast = hw_stats->tx_unicast;
     276                 :          0 :                 stats->tx_broadcast = hw_stats->tx_broadcast;
     277                 :          0 :                 stats->tx_multicast = hw_stats->tx_multicast;
     278                 :          0 :                 stats->tx_vlan_packet_good = hw_stats->tx_vlan_packet_good;
     279                 :          0 :                 stats->tx_size_64 = hw_stats->tx_size_64;
     280                 :          0 :                 stats->tx_size_65_127 = hw_stats->tx_size_65_127;
     281                 :          0 :                 stats->tx_size_128_255 = hw_stats->tx_size_128_255;
     282                 :          0 :                 stats->tx_size_256_511 = hw_stats->tx_size_256_511;
     283                 :          0 :                 stats->tx_size_512_1023 = hw_stats->tx_size_512_1023;
     284                 :          0 :                 stats->tx_size_1024_1522 = hw_stats->tx_size_1024_1522;
     285                 :          0 :                 stats->tx_size_1523_max = hw_stats->tx_size_1523_max;
     286                 :          0 :                 stats->tx_underflow_error = hw_stats->tx_underflow_error;
     287                 :          0 :                 stats->rx_byte_good_bad = hw_stats->rx_byte_good_bad;
     288                 :          0 :                 stats->rx_frame_good_bad = hw_stats->rx_frame_good_bad;
     289                 :          0 :                 stats->rx_unicast_good = hw_stats->rx_unicast_good;
     290                 :          0 :                 stats->rx_vlan_packets = hw_stats->rx_vlan_packets;
     291                 :          0 :                 rte_memcpy(stats->rx_prio_buf_discard, hw_stats->rx_prio_buf_discard,
     292                 :            :                                 sizeof(hw_stats->rx_prio_buf_discard));
     293                 :          0 :                 rte_memcpy(stats->prio_xoff_rx, hw_stats->prio_xoff_rx,
     294                 :            :                                 sizeof(hw_stats->prio_xoff_rx));
     295                 :          0 :                 rte_memcpy(stats->prio_xon_rx, hw_stats->prio_xon_rx,
     296                 :            :                                 sizeof(hw_stats->prio_xon_rx));
     297                 :          0 :                 rte_memcpy(stats->prio_xon_tx, hw_stats->prio_xon_tx,
     298                 :            :                                 sizeof(hw_stats->prio_xon_tx));
     299                 :          0 :                 rte_memcpy(stats->prio_xoff_tx, hw_stats->prio_xoff_tx,
     300                 :            :                                 sizeof(hw_stats->prio_xoff_tx));
     301                 :          0 :                 rte_memcpy(stats->prio_xon_2_xoff, hw_stats->prio_xon_2_xoff,
     302                 :            :                                 sizeof(hw_stats->prio_xon_2_xoff));
     303                 :            : 
     304                 :          0 :                 stats->imissed = hw_stats->rx_out_of_buffer +
     305                 :            :                                 hw_stats->rx_qblock_drop;
     306         [ #  # ]:          0 :                 for (i = 0; i < SXE2_MAX_USER_PRIORITY; i++)
     307                 :          0 :                         stats->imissed += hw_stats->rx_prio_buf_discard[i];
     308                 :            :         }
     309                 :          0 : }
     310                 :            : 
     311                 :          0 : int32_t sxe2_stats_info_get(struct rte_eth_dev *dev,
     312                 :            :                         struct rte_eth_stats *stats,
     313                 :            :                         struct eth_queue_stats *qstats)
     314                 :            : {
     315                 :          0 :         int32_t ret = 0;
     316                 :          0 :         struct sxe2_adapter *adapter  = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     317                 :          0 :         struct sxe2_vsi     *vsi      = adapter->vsi_ctxt.main_vsi;
     318                 :          0 :         struct sxe2_stats   *stats_out = &vsi->vsi_stats.stats;
     319                 :            : 
     320         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_SECONDARY)
     321                 :          0 :                 return sxe2_mp_req_get_stats(dev, stats, qstats);
     322                 :            : 
     323                 :          0 :         ret = sxe2_vsi_hw_stats_get_update(adapter);
     324         [ #  # ]:          0 :         if (ret)
     325                 :          0 :                 goto end;
     326                 :            : 
     327                 :          0 :         ret = sxe2_vsi_sw_stats_get_update(adapter);
     328         [ #  # ]:          0 :         if (ret)
     329                 :          0 :                 goto end;
     330                 :            : 
     331                 :          0 :         ret = sxe2_drv_queue_info_get_update(adapter, qstats);
     332         [ #  # ]:          0 :         if (ret)
     333                 :          0 :                 goto end;
     334                 :            : 
     335                 :          0 :         sxe2_stats_update(adapter);
     336                 :            : 
     337                 :          0 :         stats->ipackets = stats_out->ipackets;
     338                 :          0 :         stats->ibytes   = stats_out->ibytes;
     339                 :          0 :         stats->ierrors  = stats_out->ierrors;
     340                 :          0 :         stats->imissed  = stats_out->imissed;
     341                 :          0 :         stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
     342                 :            : 
     343                 :          0 :         stats->opackets = stats_out->opackets;
     344                 :          0 :         stats->obytes   = stats_out->obytes;
     345                 :            : 
     346                 :          0 :         ret = 0;
     347                 :            : 
     348                 :            : end:
     349                 :            :         return ret;
     350                 :            : }
     351                 :            : 
     352                 :          0 : int32_t sxe2_xstats_info_get(struct rte_eth_dev *dev,
     353                 :            :                 struct rte_eth_xstat *xstats, uint32_t usr_cnt)
     354                 :            : {
     355                 :          0 :         uint32_t i      = 0;
     356                 :          0 :         uint32_t cnt    = 0;
     357                 :          0 :         int32_t ret    = 0;
     358                 :          0 :         uint32_t offset = 0;
     359                 :          0 :         uint32_t xstats_cnt = 0;
     360                 :          0 :         struct sxe2_adapter    *adapter   = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     361                 :          0 :         struct sxe2_vsi        *vsi       = adapter->vsi_ctxt.main_vsi;
     362                 :          0 :         struct sxe2_vsi_stats  *xstats_out = &vsi->vsi_stats;
     363                 :            : 
     364         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_SECONDARY)
     365                 :          0 :                 return sxe2_mp_req_get_xstats(dev, xstats, usr_cnt);
     366                 :            : 
     367   [ #  #  #  # ]:          0 :         if (adapter->dev_type == SXE2_DEV_T_VF || adapter->is_dev_repr)
     368                 :            :                 xstats_cnt = SXE2_XSTAT_CNT_VF;
     369                 :            :         else
     370                 :          0 :                 xstats_cnt = SXE2_XSTAT_CNT_PF;
     371                 :            : 
     372         [ #  # ]:          0 :         if (usr_cnt < xstats_cnt) {
     373                 :          0 :                 ret = xstats_cnt;
     374                 :          0 :                 PMD_LOG_ERR(DRV, "user usr_cnt:%u less than stats cnt:%u", usr_cnt, ret);
     375                 :          0 :                 goto end;
     376                 :            :         }
     377                 :            : 
     378                 :          0 :         ret = sxe2_vsi_hw_stats_get_update(adapter);
     379         [ #  # ]:          0 :         if (ret) {
     380                 :          0 :                 ret = xstats_cnt;
     381                 :          0 :                 goto end;
     382                 :            :         }
     383                 :            : 
     384                 :          0 :         ret = sxe2_vsi_sw_stats_get_update(adapter);
     385         [ #  # ]:          0 :         if (ret) {
     386                 :          0 :                 ret = xstats_cnt;
     387                 :          0 :                 goto end;
     388                 :            :         }
     389                 :            : 
     390   [ #  #  #  # ]:          0 :         if (adapter->dev_type == SXE2_DEV_T_VF || adapter->is_dev_repr) {
     391                 :          0 :                 sxe2_stats_update(adapter);
     392         [ #  # ]:          0 :                 for (i = 0; i < xstats_cnt; i++) {
     393                 :          0 :                         (void)sxe2_xstat_vf_offset_get(i, &offset);
     394                 :          0 :                         xstats[cnt].value = *(uint64_t *)(((int8_t *)(&xstats_out->stats)) +
     395                 :            :                                                           offset);
     396                 :          0 :                         xstats[cnt].id    = cnt;
     397                 :          0 :                         cnt++;
     398                 :            :                 }
     399                 :            :         } else {
     400                 :          0 :                 ret = sxe2_mac_hw_stats_get_update(adapter);
     401         [ #  # ]:          0 :                 if (ret) {
     402                 :          0 :                         ret = xstats_cnt;
     403                 :          0 :                         goto end;
     404                 :            :                 }
     405                 :            : 
     406                 :          0 :                 sxe2_stats_update(adapter);
     407                 :            : 
     408         [ #  # ]:          0 :                 for (i = 0; i < xstats_cnt; i++) {
     409                 :          0 :                         (void)sxe2_xstat_pf_offset_get(i, &offset);
     410                 :          0 :                         xstats[cnt].value = *(uint64_t *)(((int8_t *)(&xstats_out->stats)) +
     411                 :            :                                                           offset);
     412                 :          0 :                         xstats[cnt].id = cnt;
     413                 :          0 :                         cnt++;
     414                 :            :                 }
     415                 :            :         }
     416                 :          0 :         ret = cnt;
     417                 :          0 :         PMD_LOG_DEBUG(DRV, "usr_cnt:%u stats cnt:%u stats done", usr_cnt, cnt);
     418                 :            : 
     419                 :            : end:
     420                 :            :         return ret;
     421                 :            : }
     422                 :            : 
     423                 :          0 : int32_t sxe2_xstats_names_get(__rte_unused struct rte_eth_dev *dev,
     424                 :            :         struct rte_eth_xstat_name *xstats_names,
     425                 :            :         __rte_unused unsigned int usr_cnt)
     426                 :            : {
     427                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     428                 :          0 :         struct sxe2_stats_field *field = NULL;
     429                 :          0 :         uint32_t i   = 0;
     430                 :          0 :         uint32_t cnt = 0;
     431                 :          0 :         int32_t ret = -1;
     432                 :          0 :         uint32_t xstats_cnt = 0;
     433                 :            : 
     434   [ #  #  #  # ]:          0 :         if (adapter->dev_type == SXE2_DEV_T_VF || adapter->is_dev_repr) {
     435                 :            :                 field = sxe2_xstats_field_vf;
     436                 :            :                 xstats_cnt = SXE2_XSTAT_CNT_VF;
     437                 :            :         } else {
     438                 :          0 :                 field = sxe2_xstats_field_pf;
     439                 :          0 :                 xstats_cnt = SXE2_XSTAT_CNT_PF;
     440                 :            :         }
     441                 :            : 
     442         [ #  # ]:          0 :         if (!xstats_names) {
     443                 :          0 :                 ret = xstats_cnt;
     444                 :          0 :                 PMD_LOG_DEBUG(DRV, "xstats field size:%u", ret);
     445                 :          0 :                 goto l_out;
     446                 :            :         }
     447                 :            : 
     448         [ #  # ]:          0 :         if (usr_cnt < xstats_cnt) {
     449                 :          0 :                 ret = -EINVAL;
     450                 :          0 :                 PMD_LOG_ERR(DRV, "max:%d usr_cnt:%u invalid (err:%d)", xstats_cnt, usr_cnt, ret);
     451                 :          0 :                 goto l_out;
     452                 :            :         }
     453                 :            : 
     454         [ #  # ]:          0 :         for (i = 0; i < xstats_cnt; i++) {
     455                 :          0 :                 (void)strlcpy(xstats_names[cnt].name, field[i].name,
     456                 :            :                               sizeof(xstats_names[cnt].name));
     457                 :          0 :                 cnt++;
     458                 :            :         }
     459                 :            : 
     460                 :          0 :         ret = cnt;
     461                 :            : 
     462                 :          0 : l_out:
     463                 :          0 :         return ret;
     464                 :            : }
     465                 :            : 
     466                 :          0 : int32_t sxe2_stats_hw_reset(struct rte_eth_dev *dev)
     467                 :            : {
     468                 :          0 :         int32_t ret = 0;
     469                 :          0 :         struct sxe2_adapter    *adapter   = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     470                 :          0 :         struct sxe2_vsi        *vsi       = adapter->vsi_ctxt.main_vsi;
     471                 :          0 :         struct sxe2_rx_queue   *rxq;
     472                 :          0 :         uint32_t rx_queue_id;
     473                 :            : 
     474                 :          0 :         ret = sxe2_drv_vsi_stats_reset(adapter);
     475         [ #  # ]:          0 :         if (ret) {
     476                 :          0 :                 PMD_LOG_ERR(DRV, "reset vsi stats failed, ret:%d.", ret);
     477                 :          0 :                 goto l_end;
     478                 :            :         }
     479   [ #  #  #  # ]:          0 :         if (adapter->dev_type != SXE2_DEV_T_VF && !adapter->is_dev_repr) {
     480                 :          0 :                 ret = sxe2_drv_mac_stats_reset(adapter);
     481         [ #  # ]:          0 :                 if (ret) {
     482                 :          0 :                         PMD_LOG_ERR(DRV, "reset mac stats failed, ret:%d.", ret);
     483                 :          0 :                         goto l_end;
     484                 :            :                 }
     485                 :            :         }
     486                 :            : 
     487                 :          0 :         memset(&vsi->vsi_stats, 0, sizeof(vsi->vsi_stats));
     488         [ #  # ]:          0 :         for (rx_queue_id = 0; rx_queue_id < dev->data->nb_rx_queues; rx_queue_id++) {
     489                 :          0 :                 rxq = dev->data->rx_queues[rx_queue_id];
     490         [ #  # ]:          0 :                 if (rxq)
     491                 :          0 :                         memset(&rxq->sw_stats, 0, sizeof(rxq->sw_stats));
     492                 :            :         }
     493                 :            : 
     494                 :          0 : l_end:
     495                 :          0 :         return ret;
     496                 :            : }
     497                 :            : 
     498                 :          0 : int32_t sxe2_stats_info_reset(struct rte_eth_dev *dev)
     499                 :            : {
     500                 :          0 :         int32_t ret;
     501                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     502                 :            : 
     503         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_SECONDARY)
     504                 :          0 :                 return sxe2_mp_req_reset_stats(dev);
     505                 :            : 
     506         [ #  # ]:          0 :         if (adapter->cap_flags & SXE2_DEV_CAPS_OFFLOAD_Q_MAP) {
     507                 :          0 :                 ret = sxe2_drv_mapping_stats_info_clear(dev);
     508         [ #  # ]:          0 :                 if (ret)
     509                 :          0 :                         goto l_end;
     510                 :            :         }
     511                 :            : 
     512                 :          0 :         ret = sxe2_stats_hw_reset(dev);
     513         [ #  # ]:          0 :         if (ret)
     514                 :          0 :                 goto l_end;
     515                 :            : 
     516                 :          0 : l_end:
     517                 :            :         return ret;
     518                 :            : }
     519                 :            : 
     520                 :          0 : int32_t sxe2_stats_init(struct rte_eth_dev *dev)
     521                 :            : {
     522                 :          0 :         PMD_INIT_FUNC_TRACE();
     523                 :          0 :         int32_t ret;
     524                 :            : 
     525         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     526                 :            :                 return 0;
     527                 :            : 
     528                 :          0 :         ret = sxe2_queue_stats_map_init(dev);
     529         [ #  # ]:          0 :         if (ret)
     530                 :          0 :                 goto l_end;
     531                 :            : 
     532                 :          0 :         ret = sxe2_stats_hw_reset(dev);
     533         [ #  # ]:          0 :         if (ret)
     534                 :          0 :                 goto l_end;
     535                 :            : 
     536                 :          0 : l_end:
     537                 :            :         return ret;
     538                 :            : }
     539                 :            : 
     540                 :          0 : int32_t sxe2_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
     541                 :            :                                   uint16_t queue_id, uint8_t pool_idx, uint8_t is_rx)
     542                 :            : {
     543                 :          0 :         int32_t ret = -1;
     544                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(eth_dev);
     545                 :            : 
     546         [ #  # ]:          0 :         if (!(adapter->cap_flags & SXE2_DEV_CAPS_OFFLOAD_Q_MAP)) {
     547                 :          0 :                 PMD_LOG_ERR(DRV, "VF does not support queue mapping! ");
     548                 :          0 :                 goto l_end;
     549                 :            :         }
     550                 :            : 
     551         [ #  # ]:          0 :         if (is_rx)
     552                 :          0 :                 ret = sxe2_drv_rxq_mapping_set(eth_dev, queue_id, pool_idx);
     553                 :            :         else
     554                 :          0 :                 ret = sxe2_drv_txq_mapping_set(eth_dev, queue_id, pool_idx);
     555                 :            : 
     556         [ #  # ]:          0 :         if (ret) {
     557                 :          0 :                 PMD_LOG_ERR(DRV, "Queue stats mapping failed ! "
     558                 :            :                         "queue_id:%u pool_idx:%u", queue_id, pool_idx);
     559                 :          0 :                 goto l_end;
     560                 :            :         }
     561                 :            : 
     562         [ #  # ]:          0 :         PMD_LOG_DEBUG(DRV, "port %u %s queue_id %d stat map to pool[%u] ",
     563                 :            :                      (uint16_t)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
     564                 :            :                      queue_id, pool_idx);
     565                 :          0 : l_end:
     566                 :          0 :         return ret;
     567                 :            : }
     568                 :            : 
     569                 :          0 : int32_t sxe2_queue_stats_map_init(struct rte_eth_dev *dev)
     570                 :            : {
     571                 :          0 :         int32_t ret = 0;
     572                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     573                 :            : 
     574         [ #  # ]:          0 :         if (adapter->cap_flags & SXE2_DEV_CAPS_OFFLOAD_Q_MAP) {
     575                 :          0 :                 dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
     576                 :            : 
     577                 :          0 :                 ret = sxe2_drv_mapping_reset(dev);
     578         [ #  # ]:          0 :                 if (ret) {
     579                 :          0 :                         PMD_LOG_ERR(DRV, "Queue stats mapping init failed !");
     580                 :          0 :                         goto l_end;
     581                 :            :                 }
     582                 :            :         }
     583                 :            : 
     584                 :          0 : l_end:
     585                 :          0 :         return ret;
     586                 :            : }

Generated by: LCOV version 1.14