LCOV - code coverage report
Current view: top level - drivers/net/hns3 - hns3_dump.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 370 0.0 %
Date: 2025-08-01 17:49:26 Functions: 0 31 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 266 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2022 HiSilicon Limited
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_malloc.h>
       6                 :            : 
       7                 :            : #include "hns3_common.h"
       8                 :            : #include "hns3_logs.h"
       9                 :            : #include "hns3_regs.h"
      10                 :            : #include "hns3_rxtx.h"
      11                 :            : #include "hns3_dump.h"
      12                 :            : 
      13                 :            : #define HNS3_BD_DW_NUM 8
      14                 :            : #define HNS3_BD_ADDRESS_LAST_DW 2
      15                 :            : 
      16                 :            : static const char *
      17                 :          0 : hns3_get_adapter_state_name(enum hns3_adapter_state state)
      18                 :            : {
      19                 :            :         const struct {
      20                 :            :                 enum hns3_adapter_state state;
      21                 :            :                 const char *name;
      22                 :          0 :         } adapter_state_name[] = {
      23                 :            :                 {HNS3_NIC_UNINITIALIZED, "UNINITIALIZED"},
      24                 :            :                 {HNS3_NIC_INITIALIZED, "INITIALIZED"},
      25                 :            :                 {HNS3_NIC_CONFIGURING, "CONFIGURING"},
      26                 :            :                 {HNS3_NIC_CONFIGURED, "CONFIGURED"},
      27                 :            :                 {HNS3_NIC_STARTING, "STARTING"},
      28                 :            :                 {HNS3_NIC_STARTED, "STARTED"},
      29                 :            :                 {HNS3_NIC_STOPPING, "STOPPING"},
      30                 :            :                 {HNS3_NIC_CLOSING, "CLOSING"},
      31                 :            :                 {HNS3_NIC_CLOSED, "CLOSED"},
      32                 :            :                 {HNS3_NIC_REMOVED, "REMOVED"},
      33                 :            :                 {HNS3_NIC_NSTATES, "NSTATES"},
      34                 :            :         };
      35                 :            :         uint32_t i;
      36                 :            : 
      37         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(adapter_state_name); i++)
      38         [ #  # ]:          0 :                 if (state == adapter_state_name[i].state)
      39                 :          0 :                         return adapter_state_name[i].name;
      40                 :            : 
      41                 :            :         return "Unknown";
      42                 :            : }
      43                 :            : 
      44                 :            : static const char *
      45                 :            : hns3_get_io_func_hint_name(uint32_t hint)
      46                 :            : {
      47                 :          0 :         switch (hint) {
      48                 :            :         case HNS3_IO_FUNC_HINT_NONE:
      49                 :            :                 return "none";
      50                 :          0 :         case HNS3_IO_FUNC_HINT_VEC:
      51                 :          0 :                 return "vec";
      52                 :          0 :         case HNS3_IO_FUNC_HINT_SVE:
      53                 :          0 :                 return "sve";
      54                 :          0 :         case HNS3_IO_FUNC_HINT_SIMPLE:
      55                 :          0 :                 return "simple";
      56                 :          0 :         case HNS3_IO_FUNC_HINT_COMMON:
      57                 :          0 :                 return "common";
      58                 :          0 :         default:
      59                 :          0 :                 return "unknown";
      60                 :            :         }
      61                 :            : }
      62                 :            : 
      63                 :            : static void
      64                 :          0 : hns3_get_dev_mac_info(FILE *file, struct hns3_adapter *hns)
      65                 :            : {
      66                 :            :         struct hns3_hw *hw = &hns->hw;
      67                 :            :         struct hns3_pf *pf = &hns->pf;
      68                 :            : 
      69                 :            :         fprintf(file, "  - MAC Info:\n");
      70                 :          0 :         fprintf(file,
      71                 :            :                 "\t  -- media_type=%s\n"
      72                 :            :                 "\t  -- query_type=%u\n"
      73                 :            :                 "\t  -- supported_speed=0x%x\n"
      74                 :            :                 "\t  -- advertising=0x%x\n"
      75                 :            :                 "\t  -- lp_advertising=0x%x\n"
      76                 :            :                 "\t  -- support_autoneg=%s\n"
      77                 :            :                 "\t  -- support_fc_autoneg=%s\n",
      78                 :          0 :                 hns3_get_media_type_name(hw->mac.media_type),
      79                 :          0 :                 hw->mac.query_type,
      80                 :            :                 hw->mac.supported_speed,
      81                 :            :                 hw->mac.advertising,
      82                 :            :                 hw->mac.lp_advertising,
      83         [ #  # ]:          0 :                 hw->mac.support_autoneg != 0 ? "Yes" : "No",
      84         [ #  # ]:          0 :                 pf->support_fc_autoneg ? "Yes" : "No");
      85                 :          0 : }
      86                 :            : 
      87                 :            : static void
      88                 :          0 : hns3_get_dev_feature_capability(FILE *file, struct hns3_hw *hw)
      89                 :            : {
      90                 :            :         const struct {
      91                 :            :                 enum hns3_dev_cap cap;
      92                 :            :                 const char *name;
      93                 :          0 :         } caps_name[] = {
      94                 :            :                 {HNS3_DEV_SUPPORT_DCB_B, "DCB"},
      95                 :            :                 {HNS3_DEV_SUPPORT_COPPER_B, "COPPER"},
      96                 :            :                 {HNS3_DEV_SUPPORT_FD_QUEUE_REGION_B, "FD QUEUE REGION"},
      97                 :            :                 {HNS3_DEV_SUPPORT_PTP_B, "PTP"},
      98                 :            :                 {HNS3_DEV_SUPPORT_TX_PUSH_B, "TX PUSH"},
      99                 :            :                 {HNS3_DEV_SUPPORT_INDEP_TXRX_B, "INDEP TXRX"},
     100                 :            :                 {HNS3_DEV_SUPPORT_STASH_B, "STASH"},
     101                 :            :                 {HNS3_DEV_SUPPORT_SIMPLE_BD_B, "SIMPLE BD"},
     102                 :            :                 {HNS3_DEV_SUPPORT_RXD_ADV_LAYOUT_B, "RXD Advanced Layout"},
     103                 :            :                 {HNS3_DEV_SUPPORT_OUTER_UDP_CKSUM_B, "OUTER UDP CKSUM"},
     104                 :            :                 {HNS3_DEV_SUPPORT_RAS_IMP_B, "RAS IMP"},
     105                 :            :                 {HNS3_DEV_SUPPORT_TM_B, "TM"},
     106                 :            :                 {HNS3_DEV_SUPPORT_VF_VLAN_FLT_MOD_B, "VF VLAN FILTER MOD"},
     107                 :            :                 {HNS3_DEV_SUPPORT_FC_AUTO_B, "FC AUTO"},
     108                 :            :                 {HNS3_DEV_SUPPORT_GRO_B, "GRO"},
     109                 :            :                 {HNS3_DEV_SUPPORT_VF_MULTI_TCS_B, "VF MULTI TCS"},
     110                 :            :         };
     111                 :            :         uint32_t i;
     112                 :            : 
     113                 :            :         fprintf(file, "  - Dev Capability:\n");
     114         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(caps_name); i++)
     115                 :          0 :                 fprintf(file, "\t  -- support %s: %s\n", caps_name[i].name,
     116         [ #  # ]:          0 :                         hns3_get_bit(hw->capability, caps_name[i].cap) ? "Yes" :
     117                 :            :                                                                          "No");
     118                 :          0 : }
     119                 :            : 
     120                 :            : static const char *
     121                 :          0 : hns3_get_fdir_tuple_name(uint32_t index)
     122                 :            : {
     123                 :          0 :         const char * const tuple_name[] = {
     124                 :            :                 "outer_dst_mac",
     125                 :            :                 "outer_src_mac",
     126                 :            :                 "outer_vlan_1st_tag",
     127                 :            :                 "outer_vlan_2nd_tag",
     128                 :            :                 "outer_eth_type",
     129                 :            :                 "outer_l2_rsv",
     130                 :            :                 "outer_ip_tos",
     131                 :            :                 "outer_ip_proto",
     132                 :            :                 "outer_src_ip",
     133                 :            :                 "outer_dst_ip",
     134                 :            :                 "outer_l3_rsv",
     135                 :            :                 "outer_src_port",
     136                 :            :                 "outer_dst_port",
     137                 :            :                 "outer_l4_rsv",
     138                 :            :                 "outer_tun_vni",
     139                 :            :                 "outer_tun_flow_id",
     140                 :            :                 "inner_dst_mac",
     141                 :            :                 "inner_src_mac",
     142                 :            :                 "inner_vlan_tag1",
     143                 :            :                 "inner_vlan_tag2",
     144                 :            :                 "inner_eth_type",
     145                 :            :                 "inner_l2_rsv",
     146                 :            :                 "inner_ip_tos",
     147                 :            :                 "inner_ip_proto",
     148                 :            :                 "inner_src_ip",
     149                 :            :                 "inner_dst_ip",
     150                 :            :                 "inner_l3_rsv",
     151                 :            :                 "inner_src_port",
     152                 :            :                 "inner_dst_port",
     153                 :            :                 "inner_sctp_tag",
     154                 :            :         };
     155         [ #  # ]:          0 :         if (index < RTE_DIM(tuple_name))
     156                 :          0 :                 return tuple_name[index];
     157                 :            :         else
     158                 :            :                 return "unknown";
     159                 :            : }
     160                 :            : 
     161                 :            : static void
     162                 :          0 : hns3_get_fdir_basic_info(FILE *file, struct hns3_pf *pf)
     163                 :            : {
     164                 :            : #define HNS3_PERLINE_TUPLE_NAME_LEN     4
     165                 :            :         struct hns3_fd_cfg *fdcfg = &pf->fdir.fd_cfg;
     166                 :            :         uint32_t i, count = 0;
     167                 :            : 
     168                 :            :         fprintf(file, "  - Fdir Info:\n");
     169                 :          0 :         fprintf(file,
     170                 :            :                 "\t  -- mode=%u max_key_len=%u rule_num:%u cnt_num:%u\n"
     171                 :            :                 "\t  -- key_sel=%u tuple_active=0x%x meta_data_active=0x%x\n"
     172                 :            :                 "\t  -- ipv6_word_en: in_s=%u in_d=%u out_s=%u out_d=%u\n"
     173                 :            :                 "\t  -- index_cfg: %s\n"
     174                 :            :                 "\t  -- tuple_config: %s\n"
     175                 :            :                 "\t  -- active_tuples:\n",
     176                 :          0 :                 fdcfg->fd_mode, fdcfg->max_key_length,
     177                 :            :                 fdcfg->rule_num[HNS3_FD_STAGE_1],
     178                 :          0 :                 fdcfg->cnt_num[HNS3_FD_STAGE_1],
     179                 :          0 :                 fdcfg->key_cfg[HNS3_FD_STAGE_1].key_sel,
     180                 :            :                 fdcfg->key_cfg[HNS3_FD_STAGE_1].tuple_active,
     181                 :            :                 fdcfg->key_cfg[HNS3_FD_STAGE_1].meta_data_active,
     182                 :          0 :                 fdcfg->key_cfg[HNS3_FD_STAGE_1].inner_sipv6_word_en,
     183                 :          0 :                 fdcfg->key_cfg[HNS3_FD_STAGE_1].inner_dipv6_word_en,
     184                 :          0 :                 fdcfg->key_cfg[HNS3_FD_STAGE_1].outer_sipv6_word_en,
     185                 :          0 :                 fdcfg->key_cfg[HNS3_FD_STAGE_1].outer_dipv6_word_en,
     186                 :            :                 hns3_fdir_index_config_name(pf->fdir.index_cfg),
     187                 :            :                 hns3_tuple_config_name(pf->fdir.tuple_cfg));
     188                 :            : 
     189         [ #  # ]:          0 :         for (i = 0; i < MAX_TUPLE; i++) {
     190         [ #  # ]:          0 :                 if (!(fdcfg->key_cfg[HNS3_FD_STAGE_1].tuple_active & BIT(i)))
     191                 :          0 :                         continue;
     192         [ #  # ]:          0 :                 if (count % HNS3_PERLINE_TUPLE_NAME_LEN == 0)
     193                 :            :                         fprintf(file, "\t      ");
     194                 :          0 :                 fprintf(file, " %s", hns3_get_fdir_tuple_name(i));
     195                 :          0 :                 count++;
     196         [ #  # ]:          0 :                 if (count % HNS3_PERLINE_TUPLE_NAME_LEN == 0)
     197                 :            :                         fprintf(file, "\n");
     198                 :            :         }
     199         [ #  # ]:          0 :         if (count % HNS3_PERLINE_TUPLE_NAME_LEN)
     200                 :            :                 fprintf(file, "\n");
     201                 :          0 : }
     202                 :            : 
     203                 :            : static void
     204                 :          0 : hns3_get_device_basic_info(FILE *file, struct rte_eth_dev *dev)
     205                 :            : {
     206                 :          0 :         struct hns3_adapter *hns = dev->data->dev_private;
     207                 :            :         struct hns3_hw *hw = &hns->hw;
     208                 :            : 
     209   [ #  #  #  #  :          0 :         fprintf(file,
                   #  # ]
     210                 :            :                 "  - Device Base Info:\n"
     211                 :            :                 "\t  -- name: %s\n"
     212                 :            :                 "\t  -- adapter_state=%s\n"
     213                 :            :                 "\t  -- tc_max=%u tc_num=%u dwrr[%u %u %u %u]\n"
     214                 :            :                 "\t  -- nb_rx_queues=%u nb_tx_queues=%u\n"
     215                 :            :                 "\t  -- total_tqps_num=%u tqps_num=%u intr_tqps_num=%u\n"
     216                 :            :                 "\t  -- rss_size_max=%u alloc_rss_size=%u tx_qnum_per_tc=%u\n"
     217                 :            :                 "\t  -- min_tx_pkt_len=%u intr_mapping_mode=%u vlan_mode=%u\n"
     218                 :            :                 "\t  -- tso_mode=%u max_non_tso_bd_num=%u\n"
     219                 :            :                 "\t  -- max_tm_rate=%u Mbps\n"
     220                 :            :                 "\t  -- set link down: %s\n"
     221                 :            :                 "\t  -- rx_func_hint=%s tx_func_hint=%s\n"
     222                 :            :                 "\t  -- dev_flags: lsc=%d\n"
     223                 :            :                 "\t  -- intr_conf: lsc=%u rxq=%u\n",
     224                 :          0 :                 dev->data->name,
     225                 :            :                 hns3_get_adapter_state_name(hw->adapter_state),
     226                 :          0 :                 hw->dcb_info.tc_max, hw->dcb_info.num_tc,
     227                 :          0 :                 hw->dcb_info.pg_info[0].tc_dwrr[0],
     228                 :          0 :                 hw->dcb_info.pg_info[0].tc_dwrr[1],
     229                 :          0 :                 hw->dcb_info.pg_info[0].tc_dwrr[2],
     230                 :          0 :                 hw->dcb_info.pg_info[0].tc_dwrr[3],
     231                 :          0 :                 dev->data->nb_rx_queues, dev->data->nb_tx_queues,
     232                 :          0 :                 hw->total_tqps_num, hw->tqps_num, hw->intr_tqps_num,
     233                 :          0 :                 hw->rss_size_max, hw->alloc_rss_size, hw->tx_qnum_per_tc,
     234                 :          0 :                 hw->min_tx_pkt_len, hw->intr.mapping_mode, hw->vlan_mode,
     235                 :          0 :                 hw->tso_mode, hw->max_non_tso_bd_num,
     236                 :            :                 hw->max_tm_rate,
     237         [ #  # ]:          0 :                 hw->set_link_down ? "Yes" : "No",
     238                 :            :                 hns3_get_io_func_hint_name(hns->rx_func_hint),
     239                 :            :                 hns3_get_io_func_hint_name(hns->tx_func_hint),
     240                 :          0 :                 !!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC),
     241                 :          0 :                 dev->data->dev_conf.intr_conf.lsc,
     242   [ #  #  #  #  :          0 :                 dev->data->dev_conf.intr_conf.rxq);
                   #  # ]
     243                 :          0 : }
     244                 :            : 
     245                 :            : static struct hns3_rx_queue *
     246                 :          0 : hns3_get_rx_queue(struct rte_eth_dev *dev)
     247                 :            : {
     248                 :          0 :         struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     249                 :            :         struct hns3_rx_queue *rxq;
     250                 :            :         uint32_t queue_id;
     251                 :            :         void **rx_queues;
     252                 :            : 
     253         [ #  # ]:          0 :         for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
     254                 :          0 :                 rx_queues = dev->data->rx_queues;
     255   [ #  #  #  # ]:          0 :                 if (rx_queues == NULL || rx_queues[queue_id] == NULL) {
     256                 :          0 :                         hns3_err(hw, "detect rx_queues is NULL!");
     257                 :          0 :                         return NULL;
     258                 :            :                 }
     259                 :            : 
     260                 :            :                 rxq = (struct hns3_rx_queue *)rx_queues[queue_id];
     261         [ #  # ]:          0 :                 if (rxq->rx_deferred_start)
     262                 :            :                         continue;
     263                 :            : 
     264                 :            :                 return rx_queues[queue_id];
     265                 :            :         }
     266                 :            : 
     267                 :            :         return NULL;
     268                 :            : }
     269                 :            : 
     270                 :            : static struct hns3_tx_queue *
     271                 :          0 : hns3_get_tx_queue(struct rte_eth_dev *dev)
     272                 :            : {
     273                 :          0 :         struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     274                 :            :         struct hns3_tx_queue *txq;
     275                 :            :         uint32_t queue_id;
     276                 :            :         void **tx_queues;
     277                 :            : 
     278         [ #  # ]:          0 :         for (queue_id = 0; queue_id < dev->data->nb_tx_queues; queue_id++) {
     279                 :          0 :                 tx_queues = dev->data->tx_queues;
     280   [ #  #  #  # ]:          0 :                 if (tx_queues == NULL || tx_queues[queue_id] == NULL) {
     281                 :          0 :                         hns3_err(hw, "detect tx_queues is NULL!");
     282                 :          0 :                         return NULL;
     283                 :            :                 }
     284                 :            : 
     285                 :            :                 txq = (struct hns3_tx_queue *)tx_queues[queue_id];
     286         [ #  # ]:          0 :                 if (txq->tx_deferred_start)
     287                 :            :                         continue;
     288                 :            : 
     289                 :            :                 return tx_queues[queue_id];
     290                 :            :         }
     291                 :            : 
     292                 :            :         return NULL;
     293                 :            : }
     294                 :            : 
     295                 :            : static void
     296                 :          0 : hns3_get_rxtx_fake_queue_info(FILE *file, struct rte_eth_dev *dev)
     297                 :            : {
     298                 :          0 :         struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     299                 :            :         struct hns3_rx_queue *rxq;
     300                 :            :         struct hns3_tx_queue *txq;
     301                 :            :         uint32_t queue_id = 0;
     302                 :            :         void **rx_queues;
     303                 :            :         void **tx_queues;
     304                 :            : 
     305         [ #  # ]:          0 :         if (hns3_dev_get_support(hw, INDEP_TXRX))
     306                 :            :                 return;
     307                 :            : 
     308         [ #  # ]:          0 :         if (dev->data->nb_rx_queues < dev->data->nb_tx_queues) {
     309                 :          0 :                 rx_queues = hw->fkq_data.rx_queues;
     310   [ #  #  #  # ]:          0 :                 if (rx_queues == NULL || rx_queues[queue_id] == NULL) {
     311                 :          0 :                         hns3_err(hw, "detect rx_queues is NULL!");
     312                 :          0 :                         return;
     313                 :            :                 }
     314                 :            :                 rxq = (struct hns3_rx_queue *)rx_queues[queue_id];
     315                 :            : 
     316                 :          0 :                 fprintf(file,
     317                 :            :                         "\t  -- first fake_queue info:\n"
     318                 :            :                         "\t       Rx: port=%u nb_desc=%u free_thresh=%u\n",
     319                 :          0 :                         rxq->port_id, rxq->nb_rx_desc, rxq->rx_free_thresh);
     320         [ #  # ]:          0 :         } else if (dev->data->nb_rx_queues > dev->data->nb_tx_queues) {
     321                 :          0 :                 tx_queues = hw->fkq_data.tx_queues;
     322                 :            :                 queue_id = 0;
     323                 :            : 
     324   [ #  #  #  # ]:          0 :                 if (tx_queues == NULL || tx_queues[queue_id] == NULL) {
     325                 :          0 :                         hns3_err(hw, "detect tx_queues is NULL!");
     326                 :          0 :                         return;
     327                 :            :                 }
     328                 :            :                 txq = (struct hns3_tx_queue *)tx_queues[queue_id];
     329                 :            : 
     330                 :          0 :                 fprintf(file,
     331                 :            :                         "\t  -- first fake_queue info:\n"
     332                 :            :                         "\t          Tx: port=%u nb_desc=%u\n",
     333                 :          0 :                         txq->port_id, txq->nb_tx_desc);
     334                 :            :         }
     335                 :            : }
     336                 :            : 
     337                 :            : static void
     338                 :          0 : hns3_get_queue_enable_state(struct hns3_hw *hw, uint32_t *queue_state,
     339                 :            :                             uint32_t nb_queues, bool is_rxq)
     340                 :            : {
     341                 :            : #define HNS3_QUEUE_NUM_PER_STATS (sizeof(*queue_state) * HNS3_UINT8_BIT)
     342                 :            :         uint32_t queue_en_reg;
     343                 :            :         uint32_t reg_offset;
     344                 :            :         uint32_t state;
     345                 :            :         uint32_t i;
     346                 :            : 
     347         [ #  # ]:          0 :         queue_en_reg = is_rxq ? HNS3_RING_RX_EN_REG : HNS3_RING_TX_EN_REG;
     348         [ #  # ]:          0 :         for (i = 0; i < nb_queues; i++) {
     349                 :          0 :                 reg_offset = hns3_get_tqp_reg_offset(i);
     350                 :          0 :                 state = hns3_read_dev(hw, reg_offset + HNS3_RING_EN_REG);
     351         [ #  # ]:          0 :                 if (hns3_dev_get_support(hw, INDEP_TXRX))
     352   [ #  #  #  # ]:          0 :                         state = state && hns3_read_dev(hw, reg_offset +
     353                 :            :                                                        queue_en_reg);
     354                 :          0 :                 hns3_set_bit(queue_state[i / HNS3_QUEUE_NUM_PER_STATS],
     355                 :            :                                 i % HNS3_QUEUE_NUM_PER_STATS, state);
     356                 :            :         }
     357                 :          0 : }
     358                 :            : 
     359                 :            : static void
     360                 :          0 : hns3_print_queue_state_perline(FILE *file, const uint32_t *queue_state,
     361                 :            :                                uint32_t nb_queues, uint32_t line_num)
     362                 :            : {
     363                 :            : #define HNS3_NUM_QUEUE_PER_LINE (sizeof(uint32_t) * HNS3_UINT8_BIT)
     364                 :          0 :         uint32_t id = line_num * HNS3_NUM_QUEUE_PER_LINE;
     365                 :            :         uint32_t i;
     366                 :            : 
     367         [ #  # ]:          0 :         for (i = 0; i < HNS3_NUM_QUEUE_PER_LINE; i++) {
     368                 :          0 :                 fprintf(file, "%1lx", hns3_get_bit(queue_state[line_num], i));
     369                 :            : 
     370         [ #  # ]:          0 :                 if (id % HNS3_UINT8_BIT == HNS3_UINT8_BIT - 1) {
     371         [ #  # ]:          0 :                         fprintf(file, "%s",
     372                 :            :                                 i == HNS3_NUM_QUEUE_PER_LINE - 1 ? "\n" : ":");
     373                 :            :                 }
     374                 :          0 :                 id++;
     375         [ #  # ]:          0 :                 if (id >= nb_queues) {
     376                 :            :                         fprintf(file, "\n");
     377                 :            :                         break;
     378                 :            :                 }
     379                 :            :         }
     380                 :          0 : }
     381                 :            : 
     382                 :            : static void
     383                 :          0 : hns3_display_queue_enable_state(FILE *file, const uint32_t *queue_state,
     384                 :            :                                 uint32_t nb_queues, bool is_rxq)
     385                 :            : {
     386                 :            : #define HNS3_NUM_QUEUE_PER_LINE (sizeof(uint32_t) * HNS3_UINT8_BIT)
     387                 :            :         uint32_t i;
     388                 :            : 
     389         [ #  # ]:          0 :         fprintf(file, "\t       %s queue id | enable state bitMap\n",
     390                 :            :                         is_rxq ? "Rx" : "Tx");
     391                 :            : 
     392         [ #  # ]:          0 :         for (i = 0; i < (nb_queues - 1) / HNS3_NUM_QUEUE_PER_LINE + 1; i++) {
     393                 :          0 :                 uint32_t line_end = (i + 1) * HNS3_NUM_QUEUE_PER_LINE - 1;
     394                 :          0 :                 uint32_t line_start = i * HNS3_NUM_QUEUE_PER_LINE;
     395                 :          0 :                 fprintf(file, "\t       %04u - %04u | ", line_start,
     396                 :            :                         nb_queues - 1 > line_end ? line_end : nb_queues - 1);
     397                 :            : 
     398                 :          0 :                 hns3_print_queue_state_perline(file, queue_state, nb_queues, i);
     399                 :            :         }
     400                 :          0 : }
     401                 :            : 
     402                 :            : static void
     403                 :          0 : hns3_get_rxtx_queue_enable_state(FILE *file, struct rte_eth_dev *dev)
     404                 :            : {
     405                 :          0 :         struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     406                 :            :         uint32_t *rx_queue_state;
     407                 :            :         uint32_t *tx_queue_state;
     408                 :            :         uint32_t nb_rx_queues;
     409                 :            :         uint32_t nb_tx_queues;
     410                 :            :         uint32_t bitmap_size;
     411                 :            : 
     412                 :          0 :         nb_rx_queues = dev->data->nb_rx_queues;
     413                 :          0 :         nb_tx_queues = dev->data->nb_tx_queues;
     414         [ #  # ]:          0 :         if (nb_rx_queues == 0) {
     415                 :            :                 fprintf(file, "\t  -- Rx queue number is 0\n");
     416                 :          0 :                 return;
     417                 :            :         }
     418         [ #  # ]:          0 :         if (nb_tx_queues == 0) {
     419                 :            :                 fprintf(file, "\t  -- Tx queue number is 0\n");
     420                 :          0 :                 return;
     421                 :            :         }
     422                 :            : 
     423                 :          0 :         bitmap_size = (hw->tqps_num * sizeof(uint32_t) + HNS3_UINT32_BIT) /
     424                 :            :                         HNS3_UINT32_BIT;
     425                 :          0 :         rx_queue_state = (uint32_t *)rte_zmalloc(NULL, bitmap_size, 0);
     426         [ #  # ]:          0 :         if (rx_queue_state == NULL) {
     427                 :          0 :                 hns3_err(hw, "Failed to allocate memory for rx queue state!");
     428                 :          0 :                 return;
     429                 :            :         }
     430                 :            : 
     431                 :          0 :         tx_queue_state = (uint32_t *)rte_zmalloc(NULL, bitmap_size, 0);
     432         [ #  # ]:          0 :         if (tx_queue_state == NULL) {
     433                 :          0 :                 hns3_err(hw, "Failed to allocate memory for tx queue state!");
     434                 :          0 :                 rte_free(rx_queue_state);
     435                 :          0 :                 return;
     436                 :            :         }
     437                 :            : 
     438                 :            :         fprintf(file, "\t  -- enable state:\n");
     439                 :          0 :         hns3_get_queue_enable_state(hw, rx_queue_state, nb_rx_queues, true);
     440                 :          0 :         hns3_display_queue_enable_state(file, rx_queue_state, nb_rx_queues,
     441                 :            :                                          true);
     442                 :            : 
     443                 :          0 :         hns3_get_queue_enable_state(hw, tx_queue_state, nb_tx_queues, false);
     444                 :          0 :         hns3_display_queue_enable_state(file, tx_queue_state, nb_tx_queues,
     445                 :            :                                          false);
     446                 :          0 :         rte_free(rx_queue_state);
     447                 :          0 :         rte_free(tx_queue_state);
     448                 :            : }
     449                 :            : 
     450                 :            : static void
     451                 :          0 : hns3_get_rxtx_queue_head_tail_pointer(FILE *file, struct rte_eth_dev *dev)
     452                 :            : {
     453                 :          0 :         struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     454                 :            :         uint32_t reg_offset, queue_id;
     455                 :            :         void **rx_queues, **tx_queues;
     456                 :            :         struct hns3_rx_queue *rxq;
     457                 :            :         struct hns3_tx_queue *txq;
     458                 :            :         uint16_t sw_hold;
     459                 :            : 
     460                 :          0 :         rx_queues = dev->data->rx_queues;
     461         [ #  # ]:          0 :         if (rx_queues == NULL)
     462                 :            :                 return;
     463                 :          0 :         tx_queues = dev->data->tx_queues;
     464         [ #  # ]:          0 :         if (tx_queues == NULL)
     465                 :            :                 return;
     466                 :            : 
     467                 :            :         fprintf(file, "\t  -- Rx queue head and tail info:\n");
     468                 :            :         fprintf(file, "\t       qid  sw_head  sw_hold  hw_head  hw_tail\n");
     469         [ #  # ]:          0 :         for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
     470         [ #  # ]:          0 :                 if (rx_queues[queue_id] == NULL)
     471                 :          0 :                         continue;
     472                 :            :                 rxq = (struct hns3_rx_queue *)rx_queues[queue_id];
     473         [ #  # ]:          0 :                 if (rxq->rx_deferred_start)
     474                 :          0 :                         continue;
     475                 :            : 
     476   [ #  #  #  # ]:          0 :                 if (dev->rx_pkt_burst == hns3_recv_pkts_vec ||
     477                 :            :                     dev->rx_pkt_burst == hns3_recv_pkts_vec_sve)
     478                 :          0 :                         sw_hold = rxq->rx_rearm_nb;
     479                 :            :                 else
     480                 :          0 :                         sw_hold = rxq->rx_free_hold;
     481                 :            : 
     482                 :          0 :                 reg_offset = hns3_get_tqp_reg_offset(queue_id);
     483                 :          0 :                 fprintf(file, "\t        %-5u%-9u%-9u%-9u%u\n", queue_id,
     484                 :          0 :                         rxq->next_to_use, sw_hold,
     485                 :            :                         hns3_read_dev(hw, HNS3_RING_RX_HEAD_REG + reg_offset),
     486                 :            :                         hns3_read_dev(hw, HNS3_RING_RX_TAIL_REG + reg_offset));
     487                 :            :         }
     488                 :            : 
     489                 :            :         fprintf(file, "\t  -- Tx queue head and tail info:\n");
     490                 :            :         fprintf(file, "\t       qid  sw_head  sw_tail  hw_head  hw_tail\n");
     491         [ #  # ]:          0 :         for (queue_id = 0; queue_id < dev->data->nb_tx_queues; queue_id++) {
     492         [ #  # ]:          0 :                 if (tx_queues[queue_id] == NULL)
     493                 :          0 :                         continue;
     494                 :            :                 txq = (struct hns3_tx_queue *)tx_queues[queue_id];
     495         [ #  # ]:          0 :                 if (txq->tx_deferred_start)
     496                 :          0 :                         continue;
     497                 :            : 
     498                 :          0 :                 reg_offset = hns3_get_tqp_reg_offset(queue_id);
     499                 :          0 :                 fprintf(file, "\t        %-5u%-9u%-9u%-9u%u\n", queue_id,
     500                 :          0 :                         txq->next_to_clean, txq->next_to_use,
     501                 :            :                         hns3_read_dev(hw, HNS3_RING_TX_HEAD_REG + reg_offset),
     502                 :            :                         hns3_read_dev(hw, HNS3_RING_TX_TAIL_REG + reg_offset));
     503                 :            :         }
     504                 :            : }
     505                 :            : 
     506                 :            : static void
     507                 :          0 : hns3_get_rxtx_queue_info(FILE *file, struct rte_eth_dev *dev)
     508                 :            : {
     509                 :            :         struct hns3_rx_queue *rxq;
     510                 :            :         struct hns3_tx_queue *txq;
     511                 :            : 
     512                 :          0 :         rxq = hns3_get_rx_queue(dev);
     513         [ #  # ]:          0 :         if (rxq == NULL)
     514                 :            :                 return;
     515                 :          0 :         txq = hns3_get_tx_queue(dev);
     516         [ #  # ]:          0 :         if (txq == NULL)
     517                 :            :                 return;
     518                 :            :         fprintf(file, "  - Rx/Tx Queue Info:\n");
     519                 :          0 :         fprintf(file,
     520                 :            :                 "\t  -- first queue rxtx info:\n"
     521                 :            :                 "\t       Rx: port=%u nb_desc=%u free_thresh=%u\n"
     522                 :            :                 "\t       Tx: port=%u nb_desc=%u\n"
     523                 :            :                 "\t  -- tx push: %s\n",
     524                 :          0 :                 rxq->port_id, rxq->nb_rx_desc, rxq->rx_free_thresh,
     525                 :          0 :                 txq->port_id, txq->nb_tx_desc,
     526         [ #  # ]:          0 :                 txq->tx_push_enable ? "enabled" : "disabled");
     527                 :            : 
     528                 :          0 :         hns3_get_rxtx_fake_queue_info(file, dev);
     529                 :          0 :         hns3_get_rxtx_queue_enable_state(file, dev);
     530                 :          0 :         hns3_get_rxtx_queue_head_tail_pointer(file, dev);
     531                 :            : }
     532                 :            : 
     533                 :            : static int
     534                 :          0 : hns3_get_vlan_filter_cfg(FILE *file, struct hns3_hw *hw)
     535                 :            : {
     536                 :            : #define HNS3_FILTER_TYPE_VF             0
     537                 :            : #define HNS3_FILTER_TYPE_PORT           1
     538                 :            : #define HNS3_FILTER_FE_NIC_INGRESS_B    BIT(0)
     539                 :            : #define HNS3_FILTER_FE_NIC_EGRESS_B     BIT(1)
     540                 :            :         struct hns3_vlan_filter_ctrl_cmd *req;
     541                 :            :         struct hns3_cmd_desc desc;
     542                 :            :         uint8_t i;
     543                 :            :         int ret;
     544                 :            : 
     545                 :            :         static const uint32_t vlan_filter_type[] = {
     546                 :            :                 HNS3_FILTER_TYPE_PORT,
     547                 :            :                 HNS3_FILTER_TYPE_VF
     548                 :            :         };
     549                 :            : 
     550         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(vlan_filter_type); i++) {
     551                 :          0 :                 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_FILTER_CTRL,
     552                 :            :                                                 true);
     553                 :            :                 req = (struct hns3_vlan_filter_ctrl_cmd *)desc.data;
     554                 :          0 :                 req->vlan_type = vlan_filter_type[i];
     555                 :          0 :                 req->vf_id = HNS3_PF_FUNC_ID;
     556                 :          0 :                 ret = hns3_cmd_send(hw, &desc, 1);
     557         [ #  # ]:          0 :                 if (ret != 0) {
     558                 :          0 :                         hns3_err(hw,
     559                 :            :                                 "NIC IMP exec ret=%d desc_num=%d optcode=0x%x!",
     560                 :            :                                 ret, 1, rte_le_to_cpu_16(desc.opcode));
     561                 :          0 :                         return ret;
     562                 :            :                 }
     563         [ #  # ]:          0 :                 fprintf(file,
     564                 :            :                         "\t  -- %s VLAN filter configuration\n"
     565                 :            :                         "\t       nic_ingress           :%s\n"
     566                 :            :                         "\t       nic_egress            :%s\n",
     567         [ #  # ]:          0 :                         req->vlan_type == HNS3_FILTER_TYPE_PORT ?
     568                 :            :                         "Port" : "VF",
     569                 :            :                         req->vlan_fe & HNS3_FILTER_FE_NIC_INGRESS_B ?
     570                 :            :                         "Enable" : "Disable",
     571         [ #  # ]:          0 :                         req->vlan_fe & HNS3_FILTER_FE_NIC_EGRESS_B ?
     572                 :            :                         "Enable" : "Disable");
     573                 :            :         }
     574                 :            : 
     575                 :            :         return 0;
     576                 :            : }
     577                 :            : 
     578                 :            : static int
     579                 :          0 : hns3_get_vlan_rx_offload_cfg(FILE *file, struct hns3_hw *hw)
     580                 :            : {
     581                 :            :         struct hns3_vport_vtag_rx_cfg_cmd *req;
     582                 :            :         struct hns3_cmd_desc desc;
     583                 :            :         uint16_t vport_id;
     584                 :            :         uint8_t bitmap;
     585                 :            :         int ret;
     586                 :            : 
     587                 :          0 :         hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_PORT_RX_CFG, true);
     588                 :            :         req = (struct hns3_vport_vtag_rx_cfg_cmd *)desc.data;
     589                 :            :         vport_id = HNS3_PF_FUNC_ID;
     590                 :          0 :         req->vf_offset = vport_id / HNS3_VF_NUM_PER_CMD;
     591                 :            :         bitmap = 1 << (vport_id % HNS3_VF_NUM_PER_BYTE);
     592                 :          0 :         req->vf_bitmap[req->vf_offset] = bitmap;
     593                 :            : 
     594                 :            :         /*
     595                 :            :          * current version VF is not supported when PF is driven by DPDK driver,
     596                 :            :          * just need to configure rx parameters for PF vport.
     597                 :            :          */
     598                 :          0 :         ret = hns3_cmd_send(hw, &desc, 1);
     599         [ #  # ]:          0 :         if (ret != 0) {
     600                 :          0 :                 hns3_err(hw,
     601                 :            :                          "NIC firmware exec ret=%d optcode=0x%x!", ret,
     602                 :            :                          rte_le_to_cpu_16(desc.opcode));
     603                 :          0 :                 return ret;
     604                 :            :         }
     605                 :            : 
     606   [ #  #  #  #  :          0 :         fprintf(file,
          #  #  #  #  #  
                      # ]
     607                 :            :                 "\t  -- RX VLAN configuration\n"
     608                 :            :                 "\t       vlan1_strip_en        :%s\n"
     609                 :            :                 "\t       vlan2_strip_en        :%s\n"
     610                 :            :                 "\t       vlan1_vlan_prionly    :%s\n"
     611                 :            :                 "\t       vlan2_vlan_prionly    :%s\n"
     612                 :            :                 "\t       vlan1_strip_discard   :%s\n"
     613                 :            :                 "\t       vlan2_strip_discard   :%s\n",
     614                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     615                 :            :                         HNS3_REM_TAG1_EN_B) ? "Enable" : "Disable",
     616                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     617                 :            :                         HNS3_REM_TAG2_EN_B) ? "Enable" : "Disable",
     618                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     619                 :            :                         HNS3_SHOW_TAG1_EN_B) ? "Enable" : "Disable",
     620                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     621                 :            :                         HNS3_SHOW_TAG2_EN_B) ? "Enable" : "Disable",
     622                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     623                 :            :                         HNS3_DISCARD_TAG1_EN_B) ? "Enable" : "Disable",
     624         [ #  # ]:          0 :                 hns3_get_bit(req->vport_vlan_cfg,
     625                 :            :                         HNS3_DISCARD_TAG2_EN_B) ? "Enable" : "Disable");
     626                 :            : 
     627                 :          0 :         return 0;
     628                 :            : }
     629                 :            : 
     630                 :            : static void
     631                 :          0 : hns3_parse_tx_vlan_cfg(FILE *file, struct hns3_vport_vtag_tx_cfg_cmd *req)
     632                 :            : {
     633                 :            : #define VLAN_VID_MASK 0x0fff
     634                 :            : #define VLAN_PRIO_SHIFT 13
     635                 :            : 
     636   [ #  #  #  #  :          0 :         fprintf(file,
             #  #  #  # ]
     637                 :            :                 "\t  -- TX VLAN configuration\n"
     638                 :            :                 "\t       accept_tag1           :%s\n"
     639                 :            :                 "\t       accept_untag1         :%s\n"
     640                 :            :                 "\t       insert_tag1_en        :%s\n"
     641                 :            :                 "\t       default_vlan_tag1 = %d, qos = %d\n"
     642                 :            :                 "\t       accept_tag2           :%s\n"
     643                 :            :                 "\t       accept_untag2         :%s\n"
     644                 :            :                 "\t       insert_tag2_en        :%s\n"
     645                 :            :                 "\t       default_vlan_tag2 = %d, qos = %d\n"
     646                 :            :                 "\t       vlan_shift_mode       :%s\n",
     647                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     648                 :            :                         HNS3_ACCEPT_TAG1_B) ? "Enable" : "Disable",
     649                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     650                 :            :                         HNS3_ACCEPT_UNTAG1_B) ? "Enable" : "Disable",
     651                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     652                 :            :                         HNS3_PORT_INS_TAG1_EN_B) ? "Enable" : "Disable",
     653                 :            :                 req->def_vlan_tag1 & VLAN_VID_MASK,
     654         [ #  # ]:          0 :                 req->def_vlan_tag1 >> VLAN_PRIO_SHIFT,
     655                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     656                 :            :                         HNS3_ACCEPT_TAG2_B) ? "Enable" : "Disable",
     657                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     658                 :            :                         HNS3_ACCEPT_UNTAG2_B) ? "Enable" : "Disable",
     659                 :            :                 hns3_get_bit(req->vport_vlan_cfg,
     660                 :            :                         HNS3_PORT_INS_TAG2_EN_B) ? "Enable" : "Disable",
     661                 :            :                 req->def_vlan_tag2 & VLAN_VID_MASK,
     662         [ #  # ]:          0 :                 req->def_vlan_tag2 >> VLAN_PRIO_SHIFT,
     663                 :          0 :                 hns3_get_bit(req->vport_vlan_cfg,
     664         [ #  # ]:          0 :                         HNS3_TAG_SHIFT_MODE_EN_B) ? "Enable" :
     665                 :            :                         "Disable");
     666                 :          0 : }
     667                 :            : 
     668                 :            : static int
     669                 :          0 : hns3_get_vlan_tx_offload_cfg(FILE *file, struct hns3_hw *hw)
     670                 :            : {
     671                 :            :         struct hns3_vport_vtag_tx_cfg_cmd *req;
     672                 :            :         struct hns3_cmd_desc desc;
     673                 :            :         uint16_t vport_id;
     674                 :            :         uint8_t bitmap;
     675                 :            :         int ret;
     676                 :            : 
     677                 :          0 :         hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_PORT_TX_CFG, true);
     678                 :            :         req = (struct hns3_vport_vtag_tx_cfg_cmd *)desc.data;
     679                 :            :         vport_id = HNS3_PF_FUNC_ID;
     680                 :          0 :         req->vf_offset = vport_id / HNS3_VF_NUM_PER_CMD;
     681                 :            :         bitmap = 1 << (vport_id % HNS3_VF_NUM_PER_BYTE);
     682                 :          0 :         req->vf_bitmap[req->vf_offset] = bitmap;
     683                 :            :         /*
     684                 :            :          * current version VF is not supported when PF is driven by DPDK driver,
     685                 :            :          * just need to configure tx parameters for PF vport.
     686                 :            :          */
     687                 :          0 :         ret = hns3_cmd_send(hw, &desc, 1);
     688         [ #  # ]:          0 :         if (ret != 0) {
     689                 :          0 :                 hns3_err(hw,
     690                 :            :                         "NIC firmware exec ret=%d desc_num=%d optcode=0x%x!",
     691                 :            :                         ret, 1, rte_le_to_cpu_16(desc.opcode));
     692                 :          0 :                 return ret;
     693                 :            :         }
     694                 :            : 
     695                 :          0 :         hns3_parse_tx_vlan_cfg(file, req);
     696                 :            : 
     697                 :          0 :         return 0;
     698                 :            : }
     699                 :            : 
     700                 :            : static void
     701                 :            : hns3_get_port_pvid_info(FILE *file, struct hns3_hw *hw)
     702                 :            : {
     703                 :            :         struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
     704         [ #  # ]:          0 :         if (hns->is_vf)
     705                 :            :                 return;
     706                 :            : 
     707                 :          0 :         fprintf(file, "  - pvid status: %s\n",
     708         [ #  # ]:          0 :                 hw->port_base_vlan_cfg.state ? "On" : "Off");
     709                 :            : }
     710                 :            : 
     711                 :            : static void
     712                 :          0 : hns3_get_vlan_config_info(FILE *file, struct hns3_hw *hw)
     713                 :            : {
     714                 :            :         int ret;
     715                 :            : 
     716                 :            :         fprintf(file, "  - VLAN Config Info:\n");
     717                 :          0 :         ret = hns3_get_vlan_filter_cfg(file, hw);
     718         [ #  # ]:          0 :         if (ret < 0)
     719                 :            :                 return;
     720                 :            : 
     721                 :          0 :         ret = hns3_get_vlan_rx_offload_cfg(file, hw);
     722         [ #  # ]:          0 :         if (ret < 0)
     723                 :            :                 return;
     724                 :            : 
     725                 :          0 :         ret = hns3_get_vlan_tx_offload_cfg(file, hw);
     726                 :            :         if (ret < 0)
     727                 :            :                 return;
     728                 :            : }
     729                 :            : 
     730                 :            : static void
     731                 :          0 : hns3_get_tm_conf_shaper_info(FILE *file, struct hns3_tm_conf *conf)
     732                 :            : {
     733                 :            :         struct hns3_shaper_profile_list *shaper_profile_list =
     734                 :            :                 &conf->shaper_profile_list;
     735                 :            :         struct hns3_tm_shaper_profile *shaper_profile;
     736                 :            : 
     737         [ #  # ]:          0 :         if (conf->nb_shaper_profile == 0)
     738                 :            :                 return;
     739                 :            : 
     740                 :            :         fprintf(file, "\t  -- shaper_profile:\n");
     741         [ #  # ]:          0 :         TAILQ_FOREACH(shaper_profile, shaper_profile_list, node) {
     742                 :          0 :                 fprintf(file,
     743                 :            :                         "\t       id=%u reference_count=%u peak_rate=%" PRIu64 "Bps\n",
     744                 :            :                         shaper_profile->shaper_profile_id,
     745                 :            :                         shaper_profile->reference_count,
     746                 :            :                         shaper_profile->profile.peak.rate);
     747                 :            :         }
     748                 :            : }
     749                 :            : 
     750                 :            : static void
     751                 :          0 : hns3_get_tm_conf_port_node_info(FILE *file, struct hns3_tm_conf *conf)
     752                 :            : {
     753         [ #  # ]:          0 :         if (conf->root == NULL)
     754                 :            :                 return;
     755                 :            : 
     756                 :          0 :         fprintf(file,
     757                 :            :                 "\t  -- port_node:\n"
     758                 :            :                 "\t       node_id=%u reference_count=%u shaper_profile_id=%d\n",
     759                 :            :                 conf->root->id, conf->root->reference_count,
     760         [ #  # ]:          0 :                 conf->root->shaper_profile ?
     761                 :          0 :                 (int)conf->root->shaper_profile->shaper_profile_id : -1);
     762                 :            : }
     763                 :            : 
     764                 :            : static void
     765                 :          0 : hns3_get_tm_conf_tc_node_info(FILE *file, struct hns3_tm_conf *conf)
     766                 :            : {
     767                 :            :         struct hns3_tm_node_list *tc_list = &conf->tc_list;
     768                 :            :         struct hns3_tm_node *tc_node[HNS3_MAX_TC_NUM];
     769                 :            :         struct hns3_tm_node *tm_node;
     770                 :            :         uint32_t tidx;
     771                 :            : 
     772         [ #  # ]:          0 :         if (conf->nb_tc_node == 0)
     773                 :          0 :                 return;
     774                 :            : 
     775                 :            :         fprintf(file, "\t  -- tc_node:\n");
     776                 :            :         memset(tc_node, 0, sizeof(tc_node));
     777         [ #  # ]:          0 :         TAILQ_FOREACH(tm_node, tc_list, node) {
     778         [ #  # ]:          0 :                 tidx = hns3_tm_calc_node_tc_no(conf, tm_node->id);
     779         [ #  # ]:          0 :                 if (tidx < HNS3_MAX_TC_NUM)
     780                 :          0 :                         tc_node[tidx] = tm_node;
     781                 :            :         }
     782                 :            : 
     783         [ #  # ]:          0 :         for (tidx = 0; tidx < HNS3_MAX_TC_NUM; tidx++) {
     784                 :          0 :                 tm_node = tc_node[tidx];
     785         [ #  # ]:          0 :                 if (tm_node == NULL)
     786                 :          0 :                         continue;
     787                 :          0 :                 fprintf(file,
     788                 :            :                         "\t       id=%u TC%u reference_count=%u parent_id=%d "
     789                 :            :                         "shaper_profile_id=%d\n",
     790         [ #  # ]:          0 :                         tm_node->id, hns3_tm_calc_node_tc_no(conf, tm_node->id),
     791                 :            :                         tm_node->reference_count,
     792         [ #  # ]:          0 :                         tm_node->parent ? (int)tm_node->parent->id : -1,
     793         [ #  # ]:          0 :                         tm_node->shaper_profile ?
     794                 :          0 :                         (int)tm_node->shaper_profile->shaper_profile_id : -1);
     795                 :            :         }
     796                 :            : }
     797                 :            : 
     798                 :            : static void
     799                 :          0 : hns3_get_tm_conf_queue_format_info(FILE *file, struct hns3_tm_node **queue_node,
     800                 :            :                                    uint32_t *queue_node_tc,
     801                 :            :                                    uint32_t nb_tx_queues)
     802                 :            : {
     803                 :            : #define HNS3_PERLINE_QUEUES     32
     804                 :            : #define HNS3_PERLINE_STRIDE     8
     805                 :            :         uint32_t i, j, line_num, start_queue_id, end_queue_id;
     806                 :            : 
     807                 :          0 :         line_num = (nb_tx_queues + HNS3_PERLINE_QUEUES - 1) /
     808                 :            :                 HNS3_PERLINE_QUEUES;
     809         [ #  # ]:          0 :         for (i = 0; i < line_num; i++) {
     810                 :          0 :                 start_queue_id = i * HNS3_PERLINE_QUEUES;
     811                 :          0 :                 end_queue_id = (i + 1) * HNS3_PERLINE_QUEUES - 1;
     812                 :          0 :                 if (end_queue_id > nb_tx_queues - 1)
     813                 :            :                         end_queue_id = nb_tx_queues - 1;
     814                 :            :                 fprintf(file, "\t       %04u - %04u | ", start_queue_id,
     815                 :            :                         end_queue_id);
     816         [ #  # ]:          0 :                 for (j = start_queue_id; j < nb_tx_queues; j++) {
     817         [ #  # ]:          0 :                         if (j >= end_queue_id + 1)
     818                 :            :                                 break;
     819   [ #  #  #  # ]:          0 :                         if (j > start_queue_id && j % HNS3_PERLINE_STRIDE == 0)
     820                 :            :                                 fprintf(file, ":");
     821                 :          0 :                         fprintf(file, "%u",
     822         [ #  # ]:          0 :                                 queue_node[j] ? queue_node_tc[j] :
     823                 :            :                                 HNS3_MAX_TC_NUM);
     824                 :            :                 }
     825                 :            :                 fprintf(file, "\n");
     826                 :            :         }
     827                 :          0 : }
     828                 :            : 
     829                 :            : static void
     830                 :          0 : hns3_get_tm_conf_queue_node_info(FILE *file, struct hns3_tm_conf *conf,
     831                 :            :                                  uint32_t nb_tx_queues)
     832                 :          0 : {
     833                 :            :         struct hns3_tm_node_list *queue_list = &conf->queue_list;
     834                 :          0 :         uint32_t nb_queue_node = conf->nb_leaf_nodes_max + 1;
     835                 :          0 :         struct hns3_tm_node *queue_node[nb_queue_node];
     836                 :          0 :         uint32_t queue_node_tc[nb_queue_node];
     837                 :            :         struct hns3_tm_node *tm_node;
     838                 :            : 
     839         [ #  # ]:          0 :         if (conf->nb_queue_node == 0)
     840                 :          0 :                 return;
     841                 :            : 
     842                 :            :         fprintf(file,
     843                 :            :                 "\t  -- queue_node:\n"
     844                 :            :                 "\t       tx queue id | mapped tc (8 mean node not exist)\n");
     845                 :            : 
     846                 :            :         memset(queue_node, 0, sizeof(queue_node));
     847                 :            :         memset(queue_node_tc, 0, sizeof(queue_node_tc));
     848                 :          0 :         nb_tx_queues = RTE_MIN(nb_tx_queues, nb_queue_node);
     849         [ #  # ]:          0 :         TAILQ_FOREACH(tm_node, queue_list, node) {
     850         [ #  # ]:          0 :                 if (tm_node->id >= nb_queue_node)
     851                 :          0 :                         continue;
     852                 :          0 :                 queue_node[tm_node->id] = tm_node;
     853                 :          0 :                 queue_node_tc[tm_node->id] = tm_node->parent ?
     854   [ #  #  #  # ]:          0 :                         hns3_tm_calc_node_tc_no(conf, tm_node->parent->id) : 0;
     855                 :          0 :                 nb_tx_queues = RTE_MAX(nb_tx_queues, tm_node->id + 1);
     856                 :            :         }
     857                 :            : 
     858                 :          0 :         hns3_get_tm_conf_queue_format_info(file, queue_node, queue_node_tc,
     859                 :            :                                       nb_tx_queues);
     860                 :            : }
     861                 :            : 
     862                 :            : static void
     863                 :          0 : hns3_get_tm_conf_info(FILE *file, struct rte_eth_dev *dev)
     864                 :            : {
     865                 :          0 :         struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     866                 :            :         struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
     867                 :          0 :         struct hns3_tm_conf *conf = &pf->tm_conf;
     868                 :            : 
     869         [ #  # ]:          0 :         if (!hns3_dev_get_support(hw, TM))
     870                 :            :                 return;
     871                 :            : 
     872                 :            :         fprintf(file, "  - TM config info:\n");
     873                 :          0 :         fprintf(file,
     874                 :            :                 "\t  -- nb_leaf_nodes_max=%u nb_nodes_max=%u\n"
     875                 :            :                 "\t  -- nb_shaper_profile=%u nb_tc_node=%u nb_queue_node=%u\n"
     876                 :            :                 "\t  -- committed=%u\n",
     877                 :            :                 conf->nb_leaf_nodes_max, conf->nb_nodes_max,
     878                 :            :                 conf->nb_shaper_profile, conf->nb_tc_node, conf->nb_queue_node,
     879                 :          0 :                 conf->committed);
     880                 :            : 
     881                 :          0 :         hns3_get_tm_conf_shaper_info(file, conf);
     882                 :          0 :         hns3_get_tm_conf_port_node_info(file, conf);
     883                 :          0 :         hns3_get_tm_conf_tc_node_info(file, conf);
     884                 :          0 :         hns3_get_tm_conf_queue_node_info(file, conf, dev->data->nb_tx_queues);
     885                 :            : }
     886                 :            : 
     887                 :            : static void
     888                 :            : hns3_fc_mode_to_rxtx_pause(enum hns3_fc_mode fc_mode, bool *rx_pause,
     889                 :            :                            bool *tx_pause)
     890                 :            : {
     891                 :            :         switch (fc_mode) {
     892                 :            :         case HNS3_FC_NONE:
     893                 :            :                 *tx_pause = false;
     894                 :            :                 *rx_pause = false;
     895                 :            :                 break;
     896                 :            :         case HNS3_FC_RX_PAUSE:
     897                 :            :                 *rx_pause = true;
     898                 :            :                 *tx_pause = false;
     899                 :            :                 break;
     900                 :            :         case HNS3_FC_TX_PAUSE:
     901                 :            :                 *rx_pause = false;
     902                 :            :                 *tx_pause = true;
     903                 :            :                 break;
     904                 :            :         case HNS3_FC_FULL:
     905                 :            :                 *rx_pause = true;
     906                 :            :                 *tx_pause = true;
     907                 :            :                 break;
     908                 :            :         default:
     909                 :            :                 *rx_pause = false;
     910                 :            :                 *tx_pause = false;
     911                 :            :                 break;
     912                 :            :         }
     913                 :            : }
     914                 :            : 
     915                 :            : static bool
     916                 :            : hns3_is_link_fc_mode(struct hns3_adapter *hns)
     917                 :            : {
     918                 :            :         struct hns3_hw *hw = &hns->hw;
     919                 :            :         struct hns3_pf *pf = &hns->pf;
     920                 :            : 
     921                 :          0 :         if (hw->current_fc_status == HNS3_FC_STATUS_PFC)
     922                 :            :                 return false;
     923                 :            : 
     924   [ #  #  #  # ]:          0 :         if (hw->dcb_info.num_tc > 1 && !pf->support_multi_tc_pause)
     925                 :            :                 return false;
     926                 :            : 
     927                 :            :         return true;
     928                 :            : }
     929                 :            : 
     930                 :            : static void
     931                 :          0 : hns3_get_link_fc_info(FILE *file, struct rte_eth_dev *dev)
     932                 :            : {
     933         [ #  # ]:          0 :         struct hns3_adapter *hns = dev->data->dev_private;
     934                 :            :         struct hns3_hw *hw = &hns->hw;
     935                 :            :         struct rte_eth_fc_conf cur_fc_conf;
     936                 :            :         bool rx_pause1;
     937                 :            :         bool tx_pause1;
     938                 :            :         bool rx_pause2;
     939                 :            :         bool tx_pause2;
     940                 :            :         int ret;
     941                 :            : 
     942                 :            :         if (!hns3_is_link_fc_mode(hns))
     943                 :          0 :                 return;
     944                 :            : 
     945                 :          0 :         ret = hns3_flow_ctrl_get(dev, &cur_fc_conf);
     946         [ #  # ]:          0 :         if (ret)  {
     947                 :            :                 fprintf(file, "get device flow control info fail!\n");
     948                 :          0 :                 return;
     949                 :            :         }
     950                 :            : 
     951         [ #  # ]:          0 :         hns3_fc_mode_to_rxtx_pause(hw->requested_fc_mode,
     952                 :            :                                    &rx_pause1, &tx_pause1);
     953         [ #  # ]:          0 :         hns3_fc_mode_to_rxtx_pause((enum hns3_fc_mode)cur_fc_conf.mode,
     954                 :            :                                    &rx_pause2, &tx_pause2);
     955                 :            : 
     956   [ #  #  #  #  :          0 :         fprintf(file,
             #  #  #  # ]
     957                 :            :                 "\t  -- link_fc_info:\n"
     958                 :            :                 "\t       Requested fc:\n"
     959                 :            :                 "\t         Rx:    %s\n"
     960                 :            :                 "\t         Tx:    %s\n"
     961                 :            :                 "\t       Current fc:\n"
     962                 :            :                 "\t         Rx:    %s\n"
     963                 :            :                 "\t         Tx:    %s\n"
     964                 :            :                 "\t       Autonegotiate: %s\n"
     965                 :            :                 "\t       Pause time:      0x%x\n",
     966                 :            :                 rx_pause1 ? "On" : "Off", tx_pause1 ? "On" : "Off",
     967                 :            :                 rx_pause2 ? "On" : "Off", tx_pause2 ? "On" : "Off",
     968                 :          0 :                 cur_fc_conf.autoneg == RTE_ETH_LINK_AUTONEG ? "On" : "Off",
     969         [ #  # ]:          0 :                 cur_fc_conf.pause_time);
     970                 :            : }
     971                 :            : 
     972                 :            : static void
     973                 :          0 : hns3_get_flow_ctrl_info(FILE *file, struct rte_eth_dev *dev)
     974                 :            : {
     975                 :          0 :         struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     976                 :            : 
     977                 :            :         fprintf(file, "  - Flow Ctrl Info:\n");
     978                 :            :         fprintf(file,
     979                 :            :                 "\t  -- fc_common_info:\n"
     980                 :            :                 "\t       current_fc_status=%u\n"
     981                 :            :                 "\t       requested_fc_mode=%u\n",
     982                 :          0 :                 hw->current_fc_status,
     983                 :          0 :                 hw->requested_fc_mode);
     984                 :            : 
     985                 :          0 :         hns3_get_link_fc_info(file, dev);
     986                 :          0 : }
     987                 :            : 
     988                 :            : int
     989                 :          0 : hns3_eth_dev_priv_dump(struct rte_eth_dev *dev, FILE *file)
     990                 :            : {
     991                 :          0 :         struct hns3_adapter *hns = dev->data->dev_private;
     992                 :          0 :         struct hns3_hw *hw = &hns->hw;
     993                 :            : 
     994                 :          0 :         rte_spinlock_lock(&hw->lock);
     995                 :            : 
     996                 :          0 :         hns3_get_device_basic_info(file, dev);
     997                 :          0 :         hns3_get_dev_feature_capability(file, hw);
     998                 :          0 :         hns3_get_rxtx_queue_info(file, dev);
     999                 :            :         hns3_get_port_pvid_info(file, hw);
    1000                 :            : 
    1001                 :            :         /*
    1002                 :            :          * VF only supports dumping basic info, feature capability and queue
    1003                 :            :          * info.
    1004                 :            :          */
    1005         [ #  # ]:          0 :         if (hns->is_vf) {
    1006                 :            :                 rte_spinlock_unlock(&hw->lock);
    1007                 :          0 :                 return 0;
    1008                 :            :         }
    1009                 :            : 
    1010                 :          0 :         hns3_get_dev_mac_info(file, hns);
    1011                 :          0 :         hns3_get_vlan_config_info(file, hw);
    1012                 :          0 :         hns3_get_fdir_basic_info(file, &hns->pf);
    1013                 :          0 :         hns3_get_tm_conf_info(file, dev);
    1014                 :          0 :         hns3_get_flow_ctrl_info(file, dev);
    1015                 :            : 
    1016                 :            :         rte_spinlock_unlock(&hw->lock);
    1017                 :            : 
    1018                 :          0 :         return 0;
    1019                 :            : }
    1020                 :            : 
    1021                 :            : int
    1022                 :          0 : hns3_rx_descriptor_dump(const struct rte_eth_dev *dev, uint16_t queue_id,
    1023                 :            :                         uint16_t offset, uint16_t num, FILE *file)
    1024                 :            : {
    1025                 :          0 :         struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1026                 :          0 :         struct hns3_rx_queue *rxq = dev->data->rx_queues[queue_id];
    1027                 :            :         uint32_t *bd_data;
    1028                 :            :         uint16_t count = 0;
    1029                 :            :         uint16_t desc_id;
    1030                 :            :         int i;
    1031                 :            : 
    1032         [ #  # ]:          0 :         if (offset >= rxq->nb_rx_desc)
    1033                 :            :                 return -EINVAL;
    1034                 :            : 
    1035         [ #  # ]:          0 :         if (num > rxq->nb_rx_desc) {
    1036                 :          0 :                 hns3_err(hw, "Invalid BD num=%u", num);
    1037                 :          0 :                 return -EINVAL;
    1038                 :            :         }
    1039                 :            : 
    1040         [ #  # ]:          0 :         while (count < num) {
    1041                 :          0 :                 desc_id = (rxq->next_to_use + offset + count) % rxq->nb_rx_desc;
    1042                 :          0 :                 bd_data = (uint32_t *)(&rxq->rx_ring[desc_id]);
    1043                 :          0 :                 fprintf(file, "Rx queue id:%u BD id:%u\n", queue_id, desc_id);
    1044         [ #  # ]:          0 :                 for (i = 0; i < HNS3_BD_DW_NUM; i++) {
    1045                 :            :                         /*
    1046                 :            :                          * For the sake of security, first 8 bytes of BD which
    1047                 :            :                          * stands for physical address of packet should not be
    1048                 :            :                          * shown.
    1049                 :            :                          */
    1050         [ #  # ]:          0 :                         if (i < HNS3_BD_ADDRESS_LAST_DW) {
    1051                 :            :                                 fprintf(file, "RX BD WORD[%d]:0x%08x\n", i, 0);
    1052                 :          0 :                                 continue;
    1053                 :            :                         }
    1054                 :          0 :                         fprintf(file, "RX BD WORD[%d]:0x%08x\n", i,
    1055                 :          0 :                                 *(bd_data + i));
    1056                 :            :                 }
    1057                 :          0 :                 count++;
    1058                 :            :         }
    1059                 :            : 
    1060                 :            :         return 0;
    1061                 :            : }
    1062                 :            : 
    1063                 :            : int
    1064                 :          0 : hns3_tx_descriptor_dump(const struct rte_eth_dev *dev, uint16_t queue_id,
    1065                 :            :                         uint16_t offset, uint16_t num, FILE *file)
    1066                 :            : {
    1067                 :          0 :         struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1068                 :          0 :         struct hns3_tx_queue *txq = dev->data->tx_queues[queue_id];
    1069                 :            :         uint32_t *bd_data;
    1070                 :            :         uint16_t count = 0;
    1071                 :            :         uint16_t desc_id;
    1072                 :            :         int i;
    1073                 :            : 
    1074         [ #  # ]:          0 :         if (offset >= txq->nb_tx_desc)
    1075                 :            :                 return -EINVAL;
    1076                 :            : 
    1077         [ #  # ]:          0 :         if (num > txq->nb_tx_desc) {
    1078                 :          0 :                 hns3_err(hw, "Invalid BD num=%u", num);
    1079                 :          0 :                 return -EINVAL;
    1080                 :            :         }
    1081                 :            : 
    1082         [ #  # ]:          0 :         while (count < num) {
    1083                 :          0 :                 desc_id = (txq->next_to_use + offset + count) % txq->nb_tx_desc;
    1084                 :          0 :                 bd_data = (uint32_t *)(&txq->tx_ring[desc_id]);
    1085                 :          0 :                 fprintf(file, "Tx queue id:%u BD id:%u\n", queue_id, desc_id);
    1086         [ #  # ]:          0 :                 for (i = 0; i < HNS3_BD_DW_NUM; i++) {
    1087                 :            :                         /*
    1088                 :            :                          * For the sake of security, first 8 bytes of BD which
    1089                 :            :                          * stands for physical address of packet should not be
    1090                 :            :                          * shown.
    1091                 :            :                          */
    1092         [ #  # ]:          0 :                         if (i < HNS3_BD_ADDRESS_LAST_DW) {
    1093                 :            :                                 fprintf(file, "TX BD WORD[%d]:0x%08x\n", i, 0);
    1094                 :          0 :                                 continue;
    1095                 :            :                         }
    1096                 :            : 
    1097                 :          0 :                         fprintf(file, "Tx BD WORD[%d]:0x%08x\n", i,
    1098                 :          0 :                                 *(bd_data + i));
    1099                 :            :                 }
    1100                 :          0 :                 count++;
    1101                 :            :         }
    1102                 :            : 
    1103                 :            :         return 0;
    1104                 :            : }

Generated by: LCOV version 1.14