1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2022 HiSilicon Limited
5 #include <rte_kvargs.h>
6 #include <rte_bus_pci.h>
7 #include <ethdev_pci.h>
10 #include "hns3_common.h"
11 #include "hns3_logs.h"
12 #include "hns3_regs.h"
13 #include "hns3_rxtx.h"
16 get_adapter_state_name(uint32_t state)
18 static const char * const state_name[] = {
32 if (state < RTE_DIM(state_name))
33 return state_name[state];
39 get_io_func_hint_name(uint32_t hint)
42 case HNS3_IO_FUNC_HINT_NONE:
44 case HNS3_IO_FUNC_HINT_VEC:
46 case HNS3_IO_FUNC_HINT_SVE:
48 case HNS3_IO_FUNC_HINT_SIMPLE:
50 case HNS3_IO_FUNC_HINT_COMMON:
58 get_dev_mac_info(FILE *file, struct hns3_adapter *hns)
60 struct hns3_hw *hw = &hns->hw;
61 struct hns3_pf *pf = &hns->pf;
63 fprintf(file, " - MAC Info:\n");
65 "\t -- query_type=%u\n"
66 "\t -- supported_speed=0x%x\n"
67 "\t -- advertising=0x%x\n"
68 "\t -- lp_advertising=0x%x\n"
69 "\t -- support_autoneg=%s\n"
70 "\t -- support_fc_autoneg=%s\n",
72 hw->mac.supported_speed,
74 hw->mac.lp_advertising,
75 hw->mac.support_autoneg != 0 ? "Yes" : "No",
76 pf->support_fc_autoneg ? "Yes" : "No");
80 get_dev_feature_capability(FILE *file, struct hns3_hw *hw)
82 const char * const caps_name[] = {
91 "RXD Advanced Layout",
99 fprintf(file, " - Dev Capability:\n");
100 for (i = 0; i < RTE_DIM(caps_name); i++)
101 fprintf(file, "\t -- support %s: %s\n", caps_name[i],
102 hw->capability & BIT(i) ? "yes" : "no");
106 get_device_basic_info(FILE *file, struct rte_eth_dev *dev)
108 struct hns3_adapter *hns = dev->data->dev_private;
109 struct hns3_hw *hw = &hns->hw;
112 " - Device Base Info:\n"
114 "\t -- adapter_state=%s\n"
115 "\t -- nb_rx_queues=%u nb_tx_queues=%u\n"
116 "\t -- total_tqps_num=%u tqps_num=%u intr_tqps_num=%u\n"
117 "\t -- rss_size_max=%u alloc_rss_size=%u tx_qnum_per_tc=%u\n"
118 "\t -- min_tx_pkt_len=%u intr_mapping_mode=%u vlan_mode=%u\n"
119 "\t -- tso_mode=%u max_non_tso_bd_num=%u\n"
120 "\t -- max_tm_rate=%u Mbps\n"
121 "\t -- set link down: %s\n"
122 "\t -- rx_func_hint=%s tx_func_hint=%s\n"
123 "\t -- dev_flags: lsc=%d\n"
124 "\t -- intr_conf: lsc=%u rxq=%u\n",
126 get_adapter_state_name(hw->adapter_state),
127 dev->data->nb_rx_queues, dev->data->nb_tx_queues,
128 hw->total_tqps_num, hw->tqps_num, hw->intr_tqps_num,
129 hw->rss_size_max, hw->alloc_rss_size, hw->tx_qnum_per_tc,
130 hw->min_tx_pkt_len, hw->intr.mapping_mode, hw->vlan_mode,
131 hw->tso_mode, hw->max_non_tso_bd_num,
133 hw->set_link_down ? "Yes" : "No",
134 get_io_func_hint_name(hns->rx_func_hint),
135 get_io_func_hint_name(hns->tx_func_hint),
136 !!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC),
137 dev->data->dev_conf.intr_conf.lsc,
138 dev->data->dev_conf.intr_conf.rxq);
142 * Note: caller must make sure queue_id < nb_queues
143 * nb_queues = RTE_MAX(eth_dev->data->nb_rx_queues,
144 * eth_dev->data->nb_tx_queues)
146 static struct hns3_rx_queue *
147 get_rx_queue(struct rte_eth_dev *dev, unsigned int queue_id)
149 struct hns3_adapter *hns = dev->data->dev_private;
150 struct hns3_hw *hw = &hns->hw;
154 if (queue_id < dev->data->nb_rx_queues) {
155 rx_queues = dev->data->rx_queues;
159 * For kunpeng930, fake queue is not exist. But since the queues
160 * are usually accessd in pairs, this branch may still exist.
162 if (hns3_dev_get_support(hw, INDEP_TXRX))
165 rx_queues = hw->fkq_data.rx_queues;
166 offset = queue_id - dev->data->nb_rx_queues;
169 if (rx_queues != NULL && rx_queues[offset] != NULL)
170 return rx_queues[offset];
172 hns3_err(hw, "Detect rx_queues is NULL!\n");
177 * Note: caller must make sure queue_id < nb_queues
178 * nb_queues = RTE_MAX(eth_dev->data->nb_rx_queues,
179 * eth_dev->data->nb_tx_queues)
181 static struct hns3_tx_queue *
182 get_tx_queue(struct rte_eth_dev *dev, unsigned int queue_id)
184 struct hns3_adapter *hns = dev->data->dev_private;
185 struct hns3_hw *hw = &hns->hw;
189 if (queue_id < dev->data->nb_tx_queues) {
190 tx_queues = dev->data->tx_queues;
194 * For kunpeng930, fake queue is not exist. But since the queues
195 * are usually accessd in pairs, this branch may still exist.
197 if (hns3_dev_get_support(hw, INDEP_TXRX))
199 tx_queues = hw->fkq_data.tx_queues;
200 offset = queue_id - dev->data->nb_tx_queues;
203 if (tx_queues != NULL && tx_queues[offset] != NULL)
204 return tx_queues[offset];
206 hns3_err(hw, "Detect tx_queues is NULL!\n");
211 get_rxtx_fake_queue_info(FILE *file, struct rte_eth_dev *dev)
213 struct hns3_adapter *hns = dev->data->dev_private;
214 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns);
215 struct hns3_rx_queue *rxq;
216 struct hns3_tx_queue *txq;
217 unsigned int queue_id;
219 if (dev->data->nb_rx_queues != dev->data->nb_tx_queues &&
220 !hns3_dev_get_support(hw, INDEP_TXRX)) {
221 queue_id = RTE_MIN(dev->data->nb_rx_queues,
222 dev->data->nb_tx_queues);
223 rxq = get_rx_queue(dev, queue_id);
226 txq = get_tx_queue(dev, queue_id);
230 "\t -- first fake_queue rxtx info:\n"
231 "\t rx: port=%u nb_desc=%u free_thresh=%u\n"
232 "\t tx: port=%u nb_desc=%u\n",
233 rxq->port_id, rxq->nb_rx_desc, rxq->rx_free_thresh,
234 txq->port_id, txq->nb_tx_desc);
239 get_queue_enable_state(struct hns3_hw *hw, uint32_t *queue_state,
240 uint32_t nb_queues, bool is_rxq)
242 #define STATE_SIZE (sizeof(*queue_state) * CHAR_BIT)
243 uint32_t queue_en_reg;
248 queue_en_reg = is_rxq ? HNS3_RING_RX_EN_REG : HNS3_RING_TX_EN_REG;
249 for (i = 0; i < nb_queues; i++) {
250 reg_offset = hns3_get_tqp_reg_offset(i);
251 state = hns3_read_dev(hw, reg_offset + HNS3_RING_EN_REG);
252 if (hns3_dev_get_support(hw, INDEP_TXRX))
253 state = state && hns3_read_dev(hw, reg_offset +
255 hns3_set_bit(queue_state[i / STATE_SIZE],
256 i % STATE_SIZE, state);
261 print_queue_state_perline(FILE *file, const uint32_t *queue_state,
262 uint32_t nb_queues, uint32_t line_num)
264 #define NUM_QUEUE_PER_LINE (sizeof(*queue_state) * CHAR_BIT)
265 uint32_t qid = line_num * NUM_QUEUE_PER_LINE;
268 for (j = 0; j < NUM_QUEUE_PER_LINE; j++) {
269 fprintf(file, "%1lx", hns3_get_bit(queue_state[line_num], j));
271 if (qid % CHAR_BIT == CHAR_BIT - 1) {
273 j == NUM_QUEUE_PER_LINE - 1 ? "\n" : ":");
276 if (qid >= nb_queues) {
284 display_queue_enable_state(FILE *file, const uint32_t *queue_state,
285 uint32_t nb_queues, bool is_rxq)
287 #define NUM_QUEUE_PER_LINE (sizeof(*queue_state) * CHAR_BIT)
290 if (nb_queues == 0) {
291 fprintf(file, "\t %s queue number is 0\n",
292 is_rxq ? "Rx" : "Tx");
296 fprintf(file, "\t %s queue id | enable state bitMap\n",
297 is_rxq ? "rx" : "tx");
299 for (i = 0; i < (nb_queues - 1) / NUM_QUEUE_PER_LINE + 1; i++) {
300 uint32_t line_end = (i + 1) * NUM_QUEUE_PER_LINE - 1;
301 uint32_t line_start = i * NUM_QUEUE_PER_LINE;
302 fprintf(file, "\t %04u - %04u | ", line_start,
303 nb_queues - 1 > line_end ? line_end : nb_queues - 1);
306 print_queue_state_perline(file, queue_state, nb_queues, i);
311 get_rxtx_queue_enable_state(FILE *file, struct rte_eth_dev *dev)
313 #define MAX_TQP_NUM 1280
314 #define QUEUE_BITMAP_SIZE (MAX_TQP_NUM / 32)
315 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
316 uint32_t rx_queue_state[QUEUE_BITMAP_SIZE] = {0};
317 uint32_t tx_queue_state[QUEUE_BITMAP_SIZE] = {0};
318 uint32_t nb_rx_queues;
319 uint32_t nb_tx_queues;
321 nb_rx_queues = dev->data->nb_rx_queues;
322 nb_tx_queues = dev->data->nb_tx_queues;
324 fprintf(file, "\t -- enable state:\n");
325 get_queue_enable_state(hw, rx_queue_state, nb_rx_queues, true);
326 display_queue_enable_state(file, rx_queue_state, nb_rx_queues,
329 get_queue_enable_state(hw, tx_queue_state, nb_tx_queues, false);
330 display_queue_enable_state(file, tx_queue_state, nb_tx_queues,
335 get_rxtx_queue_info(FILE *file, struct rte_eth_dev *dev)
337 struct hns3_rx_queue *rxq;
338 struct hns3_tx_queue *txq;
339 unsigned int queue_id = 0;
341 rxq = get_rx_queue(dev, queue_id);
344 txq = get_tx_queue(dev, queue_id);
347 fprintf(file, " - Rx/Tx Queue Info:\n");
349 "\t -- nb_rx_queues=%u nb_tx_queues=%u, "
350 "first queue rxtx info:\n"
351 "\t rx: port=%u nb_desc=%u free_thresh=%u\n"
352 "\t tx: port=%u nb_desc=%u\n"
353 "\t -- tx push: %s\n",
354 dev->data->nb_rx_queues,
355 dev->data->nb_tx_queues,
356 rxq->port_id, rxq->nb_rx_desc, rxq->rx_free_thresh,
357 txq->port_id, txq->nb_tx_desc,
358 txq->tx_push_enable ? "enabled" : "disabled");
360 get_rxtx_fake_queue_info(file, dev);
361 get_rxtx_queue_enable_state(file, dev);
365 get_vlan_filter_cfg(FILE *file, struct hns3_hw *hw)
367 #define HNS3_FILTER_TYPE_VF 0
368 #define HNS3_FILTER_TYPE_PORT 1
369 #define HNS3_FILTER_FE_NIC_INGRESS_B BIT(0)
370 #define HNS3_FILTER_FE_NIC_EGRESS_B BIT(1)
371 struct hns3_vlan_filter_ctrl_cmd *req;
372 struct hns3_cmd_desc desc;
376 static const uint32_t vlan_filter_type[] = {
377 HNS3_FILTER_TYPE_PORT,
381 for (i = 0; i < RTE_DIM(vlan_filter_type); i++) {
382 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_FILTER_CTRL,
384 req = (struct hns3_vlan_filter_ctrl_cmd *)desc.data;
385 req->vlan_type = vlan_filter_type[i];
386 req->vf_id = HNS3_PF_FUNC_ID;
387 ret = hns3_cmd_send(hw, &desc, 1);
390 "NIC IMP exec ret=%d desc_num=%d optcode=0x%x!",
391 ret, 1, rte_le_to_cpu_16(desc.opcode));
395 "\t -- %s VLAN filter configuration\n"
396 "\t nic_ingress :%s\n"
397 "\t nic_egress :%s\n",
398 req->vlan_type == HNS3_FILTER_TYPE_PORT ?
400 req->vlan_fe & HNS3_FILTER_FE_NIC_INGRESS_B ?
401 "Enable" : "Disable",
402 req->vlan_fe & HNS3_FILTER_FE_NIC_EGRESS_B ?
403 "Enable" : "Disable");
410 get_vlan_rx_offload_cfg(FILE *file, struct hns3_hw *hw)
412 struct hns3_vport_vtag_rx_cfg_cmd *req;
413 struct hns3_cmd_desc desc;
418 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_PORT_RX_CFG, true);
419 req = (struct hns3_vport_vtag_rx_cfg_cmd *)desc.data;
420 vport_id = HNS3_PF_FUNC_ID;
421 req->vf_offset = vport_id / HNS3_VF_NUM_PER_CMD;
422 bitmap = 1 << (vport_id % HNS3_VF_NUM_PER_BYTE);
423 req->vf_bitmap[req->vf_offset] = bitmap;
426 * current version VF is not supported when PF is driven by DPDK driver,
427 * just need to configure rx parameters for PF vport.
429 ret = hns3_cmd_send(hw, &desc, 1);
432 "NIC IMP exec ret=%d desc_num=%d optcode=0x%x!",
433 ret, 1, rte_le_to_cpu_16(desc.opcode));
438 "\t -- RX VLAN configuration\n"
439 "\t vlan1_strip_en :%s\n"
440 "\t vlan2_strip_en :%s\n"
441 "\t vlan1_vlan_prionly :%s\n"
442 "\t vlan2_vlan_prionly :%s\n"
443 "\t vlan1_strip_discard :%s\n"
444 "\t vlan2_strip_discard :%s\n",
445 hns3_get_bit(req->vport_vlan_cfg,
446 HNS3_REM_TAG1_EN_B) ? "Enable" : "Disable",
447 hns3_get_bit(req->vport_vlan_cfg,
448 HNS3_REM_TAG2_EN_B) ? "Enable" : "Disable",
449 hns3_get_bit(req->vport_vlan_cfg,
450 HNS3_SHOW_TAG1_EN_B) ? "Enable" : "Disable",
451 hns3_get_bit(req->vport_vlan_cfg,
452 HNS3_SHOW_TAG2_EN_B) ? "Enable" : "Disable",
453 hns3_get_bit(req->vport_vlan_cfg,
454 HNS3_DISCARD_TAG1_EN_B) ? "Enable" : "Disable",
455 hns3_get_bit(req->vport_vlan_cfg,
456 HNS3_DISCARD_TAG2_EN_B) ? "Enable" : "Disable");
462 parse_tx_vlan_cfg(FILE *file, struct hns3_vport_vtag_tx_cfg_cmd *req)
464 #define VLAN_VID_MASK 0x0fff
465 #define VLAN_PRIO_SHIFT 13
468 "\t -- TX VLAN configuration\n"
469 "\t accept_tag1 :%s\n"
470 "\t accept_untag1 :%s\n"
471 "\t insert_tag1_en :%s\n"
472 "\t default_vlan_tag1 = %d, qos = %d\n"
473 "\t accept_tag2 :%s\n"
474 "\t accept_untag2 :%s\n"
475 "\t insert_tag2_en :%s\n"
476 "\t default_vlan_tag2 = %d, qos = %d\n"
477 "\t vlan_shift_mode :%s\n",
478 hns3_get_bit(req->vport_vlan_cfg,
479 HNS3_ACCEPT_TAG1_B) ? "Enable" : "Disable",
480 hns3_get_bit(req->vport_vlan_cfg,
481 HNS3_ACCEPT_UNTAG1_B) ? "Enable" : "Disable",
482 hns3_get_bit(req->vport_vlan_cfg,
483 HNS3_PORT_INS_TAG1_EN_B) ? "Enable" : "Disable",
484 req->def_vlan_tag1 & VLAN_VID_MASK,
485 req->def_vlan_tag1 >> VLAN_PRIO_SHIFT,
486 hns3_get_bit(req->vport_vlan_cfg,
487 HNS3_ACCEPT_TAG2_B) ? "Enable" : "Disable",
488 hns3_get_bit(req->vport_vlan_cfg,
489 HNS3_ACCEPT_UNTAG2_B) ? "Enable" : "Disable",
490 hns3_get_bit(req->vport_vlan_cfg,
491 HNS3_PORT_INS_TAG2_EN_B) ? "Enable" : "Disable",
492 req->def_vlan_tag2 & VLAN_VID_MASK,
493 req->def_vlan_tag2 >> VLAN_PRIO_SHIFT,
494 hns3_get_bit(req->vport_vlan_cfg,
495 HNS3_TAG_SHIFT_MODE_EN_B) ? "Enable" :
500 get_vlan_tx_offload_cfg(FILE *file, struct hns3_hw *hw)
502 struct hns3_vport_vtag_tx_cfg_cmd *req;
503 struct hns3_cmd_desc desc;
508 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_PORT_TX_CFG, true);
509 req = (struct hns3_vport_vtag_tx_cfg_cmd *)desc.data;
510 vport_id = HNS3_PF_FUNC_ID;
511 req->vf_offset = vport_id / HNS3_VF_NUM_PER_CMD;
512 bitmap = 1 << (vport_id % HNS3_VF_NUM_PER_BYTE);
513 req->vf_bitmap[req->vf_offset] = bitmap;
515 * current version VF is not supported when PF is driven by DPDK driver,
516 * just need to configure tx parameters for PF vport.
518 ret = hns3_cmd_send(hw, &desc, 1);
521 "NIC IMP exec ret=%d desc_num=%d optcode=0x%x!",
522 ret, 1, rte_le_to_cpu_16(desc.opcode));
526 parse_tx_vlan_cfg(file, req);
532 get_port_pvid_info(FILE *file, struct hns3_hw *hw)
534 fprintf(file, "\t -- pvid status: %s\n",
535 hw->port_base_vlan_cfg.state ? "on" : "off");
539 get_vlan_config_info(FILE *file, struct hns3_hw *hw)
543 fprintf(file, " - VLAN Config Info:\n");
544 ret = get_vlan_filter_cfg(file, hw);
548 ret = get_vlan_rx_offload_cfg(file, hw);
552 ret = get_vlan_tx_offload_cfg(file, hw);
556 get_port_pvid_info(file, hw);
560 hns3_eth_dev_priv_dump(struct rte_eth_dev *dev, FILE *file)
562 struct hns3_adapter *hns = dev->data->dev_private;
563 struct hns3_hw *hw = &hns->hw;
565 get_device_basic_info(file, dev);
566 get_dev_feature_capability(file, hw);
568 /* VF only supports dumping basic info and feaure capability */
572 get_dev_mac_info(file, hns);
573 get_rxtx_queue_info(file, dev);
574 get_vlan_config_info(file, hw);