1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2019 Hisilicon Limited.
6 #include <rte_bus_pci.h>
7 #include <rte_ethdev_pci.h>
11 #include "hns3_ethdev.h"
12 #include "hns3_logs.h"
13 #include "hns3_rxtx.h"
14 #include "hns3_intr.h"
15 #include "hns3_regs.h"
19 #define HNS3_DEFAULT_PORT_CONF_BURST_SIZE 32
20 #define HNS3_DEFAULT_PORT_CONF_QUEUES_NUM 1
22 #define HNS3_SERVICE_INTERVAL 1000000 /* us */
23 #define HNS3_INVALID_PVID 0xFFFF
25 #define HNS3_FILTER_TYPE_VF 0
26 #define HNS3_FILTER_TYPE_PORT 1
27 #define HNS3_FILTER_FE_EGRESS_V1_B BIT(0)
28 #define HNS3_FILTER_FE_NIC_INGRESS_B BIT(0)
29 #define HNS3_FILTER_FE_NIC_EGRESS_B BIT(1)
30 #define HNS3_FILTER_FE_ROCE_INGRESS_B BIT(2)
31 #define HNS3_FILTER_FE_ROCE_EGRESS_B BIT(3)
32 #define HNS3_FILTER_FE_EGRESS (HNS3_FILTER_FE_NIC_EGRESS_B \
33 | HNS3_FILTER_FE_ROCE_EGRESS_B)
34 #define HNS3_FILTER_FE_INGRESS (HNS3_FILTER_FE_NIC_INGRESS_B \
35 | HNS3_FILTER_FE_ROCE_INGRESS_B)
37 /* Reset related Registers */
38 #define HNS3_GLOBAL_RESET_BIT 0
39 #define HNS3_CORE_RESET_BIT 1
40 #define HNS3_IMP_RESET_BIT 2
41 #define HNS3_FUN_RST_ING_B 0
43 #define HNS3_VECTOR0_IMP_RESET_INT_B 1
44 #define HNS3_VECTOR0_IMP_CMDQ_ERR_B 4U
45 #define HNS3_VECTOR0_IMP_RD_POISON_B 5U
46 #define HNS3_VECTOR0_ALL_MSIX_ERR_B 6U
48 #define HNS3_RESET_WAIT_MS 100
49 #define HNS3_RESET_WAIT_CNT 200
51 /* FEC mode order defined in HNS3 hardware */
52 #define HNS3_HW_FEC_MODE_NOFEC 0
53 #define HNS3_HW_FEC_MODE_BASER 1
54 #define HNS3_HW_FEC_MODE_RS 2
57 HNS3_VECTOR0_EVENT_RST,
58 HNS3_VECTOR0_EVENT_MBX,
59 HNS3_VECTOR0_EVENT_ERR,
60 HNS3_VECTOR0_EVENT_OTHER,
63 static const struct rte_eth_fec_capa speed_fec_capa_tbl[] = {
64 { ETH_SPEED_NUM_10G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
65 RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
66 RTE_ETH_FEC_MODE_CAPA_MASK(BASER) },
68 { ETH_SPEED_NUM_25G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
69 RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
70 RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
71 RTE_ETH_FEC_MODE_CAPA_MASK(RS) },
73 { ETH_SPEED_NUM_40G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
74 RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
75 RTE_ETH_FEC_MODE_CAPA_MASK(BASER) },
77 { ETH_SPEED_NUM_50G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
78 RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
79 RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
80 RTE_ETH_FEC_MODE_CAPA_MASK(RS) },
82 { ETH_SPEED_NUM_100G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
83 RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
84 RTE_ETH_FEC_MODE_CAPA_MASK(RS) },
86 { ETH_SPEED_NUM_200G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
87 RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
88 RTE_ETH_FEC_MODE_CAPA_MASK(RS) }
91 static enum hns3_reset_level hns3_get_reset_level(struct hns3_adapter *hns,
93 static int hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
94 static int hns3_vlan_pvid_configure(struct hns3_adapter *hns, uint16_t pvid,
96 static int hns3_update_speed_duplex(struct rte_eth_dev *eth_dev);
98 static int hns3_add_mc_addr(struct hns3_hw *hw,
99 struct rte_ether_addr *mac_addr);
100 static int hns3_remove_mc_addr(struct hns3_hw *hw,
101 struct rte_ether_addr *mac_addr);
102 static int hns3_restore_fec(struct hns3_hw *hw);
103 static int hns3_query_dev_fec_info(struct rte_eth_dev *dev);
106 hns3_pf_disable_irq0(struct hns3_hw *hw)
108 hns3_write_dev(hw, HNS3_MISC_VECTOR_REG_BASE, 0);
112 hns3_pf_enable_irq0(struct hns3_hw *hw)
114 hns3_write_dev(hw, HNS3_MISC_VECTOR_REG_BASE, 1);
117 static enum hns3_evt_cause
118 hns3_check_event_cause(struct hns3_adapter *hns, uint32_t *clearval)
120 struct hns3_hw *hw = &hns->hw;
121 uint32_t vector0_int_stats;
122 uint32_t cmdq_src_val;
123 uint32_t hw_err_src_reg;
125 enum hns3_evt_cause ret;
127 /* fetch the events from their corresponding regs */
128 vector0_int_stats = hns3_read_dev(hw, HNS3_VECTOR0_OTHER_INT_STS_REG);
129 cmdq_src_val = hns3_read_dev(hw, HNS3_VECTOR0_CMDQ_SRC_REG);
130 hw_err_src_reg = hns3_read_dev(hw, HNS3_RAS_PF_OTHER_INT_STS_REG);
133 * Assumption: If by any chance reset and mailbox events are reported
134 * together then we will only process reset event and defer the
135 * processing of the mailbox events. Since, we would have not cleared
136 * RX CMDQ event this time we would receive again another interrupt
137 * from H/W just for the mailbox.
139 if (BIT(HNS3_VECTOR0_IMPRESET_INT_B) & vector0_int_stats) { /* IMP */
140 rte_atomic16_set(&hw->reset.disable_cmd, 1);
141 hns3_atomic_set_bit(HNS3_IMP_RESET, &hw->reset.pending);
142 val = BIT(HNS3_VECTOR0_IMPRESET_INT_B);
144 hw->reset.stats.imp_cnt++;
145 hns3_warn(hw, "IMP reset detected, clear reset status");
147 hns3_schedule_delayed_reset(hns);
148 hns3_warn(hw, "IMP reset detected, don't clear reset status");
151 ret = HNS3_VECTOR0_EVENT_RST;
156 if (BIT(HNS3_VECTOR0_GLOBALRESET_INT_B) & vector0_int_stats) {
157 rte_atomic16_set(&hw->reset.disable_cmd, 1);
158 hns3_atomic_set_bit(HNS3_GLOBAL_RESET, &hw->reset.pending);
159 val = BIT(HNS3_VECTOR0_GLOBALRESET_INT_B);
161 hw->reset.stats.global_cnt++;
162 hns3_warn(hw, "Global reset detected, clear reset status");
164 hns3_schedule_delayed_reset(hns);
165 hns3_warn(hw, "Global reset detected, don't clear reset status");
168 ret = HNS3_VECTOR0_EVENT_RST;
172 /* check for vector0 msix event source */
173 if (vector0_int_stats & HNS3_VECTOR0_REG_MSIX_MASK ||
174 hw_err_src_reg & HNS3_RAS_REG_NFE_MASK) {
175 val = vector0_int_stats | hw_err_src_reg;
176 ret = HNS3_VECTOR0_EVENT_ERR;
180 /* check for vector0 mailbox(=CMDQ RX) event source */
181 if (BIT(HNS3_VECTOR0_RX_CMDQ_INT_B) & cmdq_src_val) {
182 cmdq_src_val &= ~BIT(HNS3_VECTOR0_RX_CMDQ_INT_B);
184 ret = HNS3_VECTOR0_EVENT_MBX;
188 if (clearval && (vector0_int_stats || cmdq_src_val || hw_err_src_reg))
189 hns3_warn(hw, "vector0_int_stats:0x%x cmdq_src_val:0x%x hw_err_src_reg:0x%x",
190 vector0_int_stats, cmdq_src_val, hw_err_src_reg);
191 val = vector0_int_stats;
192 ret = HNS3_VECTOR0_EVENT_OTHER;
201 hns3_clear_event_cause(struct hns3_hw *hw, uint32_t event_type, uint32_t regclr)
203 if (event_type == HNS3_VECTOR0_EVENT_RST)
204 hns3_write_dev(hw, HNS3_MISC_RESET_STS_REG, regclr);
205 else if (event_type == HNS3_VECTOR0_EVENT_MBX)
206 hns3_write_dev(hw, HNS3_VECTOR0_CMDQ_SRC_REG, regclr);
210 hns3_clear_all_event_cause(struct hns3_hw *hw)
212 uint32_t vector0_int_stats;
213 vector0_int_stats = hns3_read_dev(hw, HNS3_VECTOR0_OTHER_INT_STS_REG);
215 if (BIT(HNS3_VECTOR0_IMPRESET_INT_B) & vector0_int_stats)
216 hns3_warn(hw, "Probe during IMP reset interrupt");
218 if (BIT(HNS3_VECTOR0_GLOBALRESET_INT_B) & vector0_int_stats)
219 hns3_warn(hw, "Probe during Global reset interrupt");
221 hns3_clear_event_cause(hw, HNS3_VECTOR0_EVENT_RST,
222 BIT(HNS3_VECTOR0_IMPRESET_INT_B) |
223 BIT(HNS3_VECTOR0_GLOBALRESET_INT_B) |
224 BIT(HNS3_VECTOR0_CORERESET_INT_B));
225 hns3_clear_event_cause(hw, HNS3_VECTOR0_EVENT_MBX, 0);
229 hns3_interrupt_handler(void *param)
231 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
232 struct hns3_adapter *hns = dev->data->dev_private;
233 struct hns3_hw *hw = &hns->hw;
234 enum hns3_evt_cause event_cause;
235 uint32_t clearval = 0;
237 /* Disable interrupt */
238 hns3_pf_disable_irq0(hw);
240 event_cause = hns3_check_event_cause(hns, &clearval);
242 /* vector 0 interrupt is shared with reset and mailbox source events. */
243 if (event_cause == HNS3_VECTOR0_EVENT_ERR) {
244 hns3_warn(hw, "Received err interrupt");
245 hns3_handle_msix_error(hns, &hw->reset.request);
246 hns3_handle_ras_error(hns, &hw->reset.request);
247 hns3_schedule_reset(hns);
248 } else if (event_cause == HNS3_VECTOR0_EVENT_RST) {
249 hns3_warn(hw, "Received reset interrupt");
250 hns3_schedule_reset(hns);
251 } else if (event_cause == HNS3_VECTOR0_EVENT_MBX)
252 hns3_dev_handle_mbx_msg(hw);
254 hns3_err(hw, "Received unknown event");
256 hns3_clear_event_cause(hw, event_cause, clearval);
257 /* Enable interrupt if it is not cause by reset */
258 hns3_pf_enable_irq0(hw);
262 hns3_set_port_vlan_filter(struct hns3_adapter *hns, uint16_t vlan_id, int on)
264 #define HNS3_VLAN_ID_OFFSET_STEP 160
265 #define HNS3_VLAN_BYTE_SIZE 8
266 struct hns3_vlan_filter_pf_cfg_cmd *req;
267 struct hns3_hw *hw = &hns->hw;
268 uint8_t vlan_offset_byte_val;
269 struct hns3_cmd_desc desc;
270 uint8_t vlan_offset_byte;
271 uint8_t vlan_offset_base;
274 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_FILTER_PF_CFG, false);
276 vlan_offset_base = vlan_id / HNS3_VLAN_ID_OFFSET_STEP;
277 vlan_offset_byte = (vlan_id % HNS3_VLAN_ID_OFFSET_STEP) /
279 vlan_offset_byte_val = 1 << (vlan_id % HNS3_VLAN_BYTE_SIZE);
281 req = (struct hns3_vlan_filter_pf_cfg_cmd *)desc.data;
282 req->vlan_offset = vlan_offset_base;
283 req->vlan_cfg = on ? 0 : 1;
284 req->vlan_offset_bitmap[vlan_offset_byte] = vlan_offset_byte_val;
286 ret = hns3_cmd_send(hw, &desc, 1);
288 hns3_err(hw, "set port vlan id failed, vlan_id =%u, ret =%d",
295 hns3_rm_dev_vlan_table(struct hns3_adapter *hns, uint16_t vlan_id)
297 struct hns3_user_vlan_table *vlan_entry;
298 struct hns3_pf *pf = &hns->pf;
300 LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
301 if (vlan_entry->vlan_id == vlan_id) {
302 if (vlan_entry->hd_tbl_status)
303 hns3_set_port_vlan_filter(hns, vlan_id, 0);
304 LIST_REMOVE(vlan_entry, next);
305 rte_free(vlan_entry);
312 hns3_add_dev_vlan_table(struct hns3_adapter *hns, uint16_t vlan_id,
315 struct hns3_user_vlan_table *vlan_entry;
316 struct hns3_hw *hw = &hns->hw;
317 struct hns3_pf *pf = &hns->pf;
319 LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
320 if (vlan_entry->vlan_id == vlan_id)
324 vlan_entry = rte_zmalloc("hns3_vlan_tbl", sizeof(*vlan_entry), 0);
325 if (vlan_entry == NULL) {
326 hns3_err(hw, "Failed to malloc hns3 vlan table");
330 vlan_entry->hd_tbl_status = writen_to_tbl;
331 vlan_entry->vlan_id = vlan_id;
333 LIST_INSERT_HEAD(&pf->vlan_list, vlan_entry, next);
337 hns3_restore_vlan_table(struct hns3_adapter *hns)
339 struct hns3_user_vlan_table *vlan_entry;
340 struct hns3_hw *hw = &hns->hw;
341 struct hns3_pf *pf = &hns->pf;
345 if (hw->port_base_vlan_cfg.state == HNS3_PORT_BASE_VLAN_ENABLE)
346 return hns3_vlan_pvid_configure(hns,
347 hw->port_base_vlan_cfg.pvid, 1);
349 LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
350 if (vlan_entry->hd_tbl_status) {
351 vlan_id = vlan_entry->vlan_id;
352 ret = hns3_set_port_vlan_filter(hns, vlan_id, 1);
362 hns3_vlan_filter_configure(struct hns3_adapter *hns, uint16_t vlan_id, int on)
364 struct hns3_hw *hw = &hns->hw;
365 bool writen_to_tbl = false;
369 * When vlan filter is enabled, hardware regards packets without vlan
370 * as packets with vlan 0. So, to receive packets without vlan, vlan id
371 * 0 is not allowed to be removed by rte_eth_dev_vlan_filter.
373 if (on == 0 && vlan_id == 0)
377 * When port base vlan enabled, we use port base vlan as the vlan
378 * filter condition. In this case, we don't update vlan filter table
379 * when user add new vlan or remove exist vlan, just update the
380 * vlan list. The vlan id in vlan list will be writen in vlan filter
381 * table until port base vlan disabled
383 if (hw->port_base_vlan_cfg.state == HNS3_PORT_BASE_VLAN_DISABLE) {
384 ret = hns3_set_port_vlan_filter(hns, vlan_id, on);
385 writen_to_tbl = true;
390 hns3_add_dev_vlan_table(hns, vlan_id, writen_to_tbl);
392 hns3_rm_dev_vlan_table(hns, vlan_id);
398 hns3_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
400 struct hns3_adapter *hns = dev->data->dev_private;
401 struct hns3_hw *hw = &hns->hw;
404 rte_spinlock_lock(&hw->lock);
405 ret = hns3_vlan_filter_configure(hns, vlan_id, on);
406 rte_spinlock_unlock(&hw->lock);
411 hns3_vlan_tpid_configure(struct hns3_adapter *hns, enum rte_vlan_type vlan_type,
414 struct hns3_rx_vlan_type_cfg_cmd *rx_req;
415 struct hns3_tx_vlan_type_cfg_cmd *tx_req;
416 struct hns3_hw *hw = &hns->hw;
417 struct hns3_cmd_desc desc;
420 if ((vlan_type != ETH_VLAN_TYPE_INNER &&
421 vlan_type != ETH_VLAN_TYPE_OUTER)) {
422 hns3_err(hw, "Unsupported vlan type, vlan_type =%d", vlan_type);
426 if (tpid != RTE_ETHER_TYPE_VLAN) {
427 hns3_err(hw, "Unsupported vlan tpid, vlan_type =%d", vlan_type);
431 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_VLAN_TYPE_ID, false);
432 rx_req = (struct hns3_rx_vlan_type_cfg_cmd *)desc.data;
434 if (vlan_type == ETH_VLAN_TYPE_OUTER) {
435 rx_req->ot_fst_vlan_type = rte_cpu_to_le_16(tpid);
436 rx_req->ot_sec_vlan_type = rte_cpu_to_le_16(tpid);
437 } else if (vlan_type == ETH_VLAN_TYPE_INNER) {
438 rx_req->ot_fst_vlan_type = rte_cpu_to_le_16(tpid);
439 rx_req->ot_sec_vlan_type = rte_cpu_to_le_16(tpid);
440 rx_req->in_fst_vlan_type = rte_cpu_to_le_16(tpid);
441 rx_req->in_sec_vlan_type = rte_cpu_to_le_16(tpid);
444 ret = hns3_cmd_send(hw, &desc, 1);
446 hns3_err(hw, "Send rxvlan protocol type command fail, ret =%d",
451 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_VLAN_INSERT, false);
453 tx_req = (struct hns3_tx_vlan_type_cfg_cmd *)desc.data;
454 tx_req->ot_vlan_type = rte_cpu_to_le_16(tpid);
455 tx_req->in_vlan_type = rte_cpu_to_le_16(tpid);
457 ret = hns3_cmd_send(hw, &desc, 1);
459 hns3_err(hw, "Send txvlan protocol type command fail, ret =%d",
465 hns3_vlan_tpid_set(struct rte_eth_dev *dev, enum rte_vlan_type vlan_type,
468 struct hns3_adapter *hns = dev->data->dev_private;
469 struct hns3_hw *hw = &hns->hw;
472 rte_spinlock_lock(&hw->lock);
473 ret = hns3_vlan_tpid_configure(hns, vlan_type, tpid);
474 rte_spinlock_unlock(&hw->lock);
479 hns3_set_vlan_rx_offload_cfg(struct hns3_adapter *hns,
480 struct hns3_rx_vtag_cfg *vcfg)
482 struct hns3_vport_vtag_rx_cfg_cmd *req;
483 struct hns3_hw *hw = &hns->hw;
484 struct hns3_cmd_desc desc;
489 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_PORT_RX_CFG, false);
491 req = (struct hns3_vport_vtag_rx_cfg_cmd *)desc.data;
492 hns3_set_bit(req->vport_vlan_cfg, HNS3_REM_TAG1_EN_B,
493 vcfg->strip_tag1_en ? 1 : 0);
494 hns3_set_bit(req->vport_vlan_cfg, HNS3_REM_TAG2_EN_B,
495 vcfg->strip_tag2_en ? 1 : 0);
496 hns3_set_bit(req->vport_vlan_cfg, HNS3_SHOW_TAG1_EN_B,
497 vcfg->vlan1_vlan_prionly ? 1 : 0);
498 hns3_set_bit(req->vport_vlan_cfg, HNS3_SHOW_TAG2_EN_B,
499 vcfg->vlan2_vlan_prionly ? 1 : 0);
501 /* firmwall will ignore this configuration for PCI_REVISION_ID_HIP08 */
502 hns3_set_bit(req->vport_vlan_cfg, HNS3_DISCARD_TAG1_EN_B,
503 vcfg->strip_tag1_discard_en ? 1 : 0);
504 hns3_set_bit(req->vport_vlan_cfg, HNS3_DISCARD_TAG2_EN_B,
505 vcfg->strip_tag2_discard_en ? 1 : 0);
507 * In current version VF is not supported when PF is driven by DPDK
508 * driver, just need to configure parameters for PF vport.
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 ret = hns3_cmd_send(hw, &desc, 1);
517 hns3_err(hw, "Send port rxvlan cfg command fail, ret =%d", ret);
522 hns3_update_rx_offload_cfg(struct hns3_adapter *hns,
523 struct hns3_rx_vtag_cfg *vcfg)
525 struct hns3_pf *pf = &hns->pf;
526 memcpy(&pf->vtag_config.rx_vcfg, vcfg, sizeof(pf->vtag_config.rx_vcfg));
530 hns3_update_tx_offload_cfg(struct hns3_adapter *hns,
531 struct hns3_tx_vtag_cfg *vcfg)
533 struct hns3_pf *pf = &hns->pf;
534 memcpy(&pf->vtag_config.tx_vcfg, vcfg, sizeof(pf->vtag_config.tx_vcfg));
538 hns3_en_hw_strip_rxvtag(struct hns3_adapter *hns, bool enable)
540 struct hns3_rx_vtag_cfg rxvlan_cfg;
541 struct hns3_hw *hw = &hns->hw;
544 if (hw->port_base_vlan_cfg.state == HNS3_PORT_BASE_VLAN_DISABLE) {
545 rxvlan_cfg.strip_tag1_en = false;
546 rxvlan_cfg.strip_tag2_en = enable;
547 rxvlan_cfg.strip_tag2_discard_en = false;
549 rxvlan_cfg.strip_tag1_en = enable;
550 rxvlan_cfg.strip_tag2_en = true;
551 rxvlan_cfg.strip_tag2_discard_en = true;
554 rxvlan_cfg.strip_tag1_discard_en = false;
555 rxvlan_cfg.vlan1_vlan_prionly = false;
556 rxvlan_cfg.vlan2_vlan_prionly = false;
557 rxvlan_cfg.rx_vlan_offload_en = enable;
559 ret = hns3_set_vlan_rx_offload_cfg(hns, &rxvlan_cfg);
561 hns3_err(hw, "enable strip rx vtag failed, ret =%d", ret);
565 hns3_update_rx_offload_cfg(hns, &rxvlan_cfg);
571 hns3_set_vlan_filter_ctrl(struct hns3_hw *hw, uint8_t vlan_type,
572 uint8_t fe_type, bool filter_en, uint8_t vf_id)
574 struct hns3_vlan_filter_ctrl_cmd *req;
575 struct hns3_cmd_desc desc;
578 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_FILTER_CTRL, false);
580 req = (struct hns3_vlan_filter_ctrl_cmd *)desc.data;
581 req->vlan_type = vlan_type;
582 req->vlan_fe = filter_en ? fe_type : 0;
585 ret = hns3_cmd_send(hw, &desc, 1);
587 hns3_err(hw, "set vlan filter fail, ret =%d", ret);
593 hns3_vlan_filter_init(struct hns3_adapter *hns)
595 struct hns3_hw *hw = &hns->hw;
598 ret = hns3_set_vlan_filter_ctrl(hw, HNS3_FILTER_TYPE_VF,
599 HNS3_FILTER_FE_EGRESS, false,
602 hns3_err(hw, "failed to init vf vlan filter, ret = %d", ret);
606 ret = hns3_set_vlan_filter_ctrl(hw, HNS3_FILTER_TYPE_PORT,
607 HNS3_FILTER_FE_INGRESS, false,
610 hns3_err(hw, "failed to init port vlan filter, ret = %d", ret);
616 hns3_enable_vlan_filter(struct hns3_adapter *hns, bool enable)
618 struct hns3_hw *hw = &hns->hw;
621 ret = hns3_set_vlan_filter_ctrl(hw, HNS3_FILTER_TYPE_PORT,
622 HNS3_FILTER_FE_INGRESS, enable,
625 hns3_err(hw, "failed to %s port vlan filter, ret = %d",
626 enable ? "enable" : "disable", ret);
632 hns3_vlan_offload_set(struct rte_eth_dev *dev, int mask)
634 struct hns3_adapter *hns = dev->data->dev_private;
635 struct hns3_hw *hw = &hns->hw;
636 struct rte_eth_rxmode *rxmode;
637 unsigned int tmp_mask;
641 rte_spinlock_lock(&hw->lock);
642 rxmode = &dev->data->dev_conf.rxmode;
643 tmp_mask = (unsigned int)mask;
644 if (tmp_mask & ETH_VLAN_FILTER_MASK) {
645 /* ignore vlan filter configuration during promiscuous mode */
646 if (!dev->data->promiscuous) {
647 /* Enable or disable VLAN filter */
648 enable = rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER ?
651 ret = hns3_enable_vlan_filter(hns, enable);
653 rte_spinlock_unlock(&hw->lock);
654 hns3_err(hw, "failed to %s rx filter, ret = %d",
655 enable ? "enable" : "disable", ret);
661 if (tmp_mask & ETH_VLAN_STRIP_MASK) {
662 /* Enable or disable VLAN stripping */
663 enable = rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP ?
666 ret = hns3_en_hw_strip_rxvtag(hns, enable);
668 rte_spinlock_unlock(&hw->lock);
669 hns3_err(hw, "failed to %s rx strip, ret = %d",
670 enable ? "enable" : "disable", ret);
675 rte_spinlock_unlock(&hw->lock);
681 hns3_set_vlan_tx_offload_cfg(struct hns3_adapter *hns,
682 struct hns3_tx_vtag_cfg *vcfg)
684 struct hns3_vport_vtag_tx_cfg_cmd *req;
685 struct hns3_cmd_desc desc;
686 struct hns3_hw *hw = &hns->hw;
691 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_PORT_TX_CFG, false);
693 req = (struct hns3_vport_vtag_tx_cfg_cmd *)desc.data;
694 req->def_vlan_tag1 = vcfg->default_tag1;
695 req->def_vlan_tag2 = vcfg->default_tag2;
696 hns3_set_bit(req->vport_vlan_cfg, HNS3_ACCEPT_TAG1_B,
697 vcfg->accept_tag1 ? 1 : 0);
698 hns3_set_bit(req->vport_vlan_cfg, HNS3_ACCEPT_UNTAG1_B,
699 vcfg->accept_untag1 ? 1 : 0);
700 hns3_set_bit(req->vport_vlan_cfg, HNS3_ACCEPT_TAG2_B,
701 vcfg->accept_tag2 ? 1 : 0);
702 hns3_set_bit(req->vport_vlan_cfg, HNS3_ACCEPT_UNTAG2_B,
703 vcfg->accept_untag2 ? 1 : 0);
704 hns3_set_bit(req->vport_vlan_cfg, HNS3_PORT_INS_TAG1_EN_B,
705 vcfg->insert_tag1_en ? 1 : 0);
706 hns3_set_bit(req->vport_vlan_cfg, HNS3_PORT_INS_TAG2_EN_B,
707 vcfg->insert_tag2_en ? 1 : 0);
708 hns3_set_bit(req->vport_vlan_cfg, HNS3_CFG_NIC_ROCE_SEL_B, 0);
710 /* firmwall will ignore this configuration for PCI_REVISION_ID_HIP08 */
711 hns3_set_bit(req->vport_vlan_cfg, HNS3_TAG_SHIFT_MODE_EN_B,
712 vcfg->tag_shift_mode_en ? 1 : 0);
715 * In current version VF is not supported when PF is driven by DPDK
716 * driver, just need to configure parameters for PF vport.
718 vport_id = HNS3_PF_FUNC_ID;
719 req->vf_offset = vport_id / HNS3_VF_NUM_PER_CMD;
720 bitmap = 1 << (vport_id % HNS3_VF_NUM_PER_BYTE);
721 req->vf_bitmap[req->vf_offset] = bitmap;
723 ret = hns3_cmd_send(hw, &desc, 1);
725 hns3_err(hw, "Send port txvlan cfg command fail, ret =%d", ret);
731 hns3_vlan_txvlan_cfg(struct hns3_adapter *hns, uint16_t port_base_vlan_state,
734 struct hns3_hw *hw = &hns->hw;
735 struct hns3_tx_vtag_cfg txvlan_cfg;
738 if (port_base_vlan_state == HNS3_PORT_BASE_VLAN_DISABLE) {
739 txvlan_cfg.accept_tag1 = true;
740 txvlan_cfg.insert_tag1_en = false;
741 txvlan_cfg.default_tag1 = 0;
743 txvlan_cfg.accept_tag1 =
744 hw->vlan_mode == HNS3_HW_SHIFT_AND_DISCARD_MODE;
745 txvlan_cfg.insert_tag1_en = true;
746 txvlan_cfg.default_tag1 = pvid;
749 txvlan_cfg.accept_untag1 = true;
750 txvlan_cfg.accept_tag2 = true;
751 txvlan_cfg.accept_untag2 = true;
752 txvlan_cfg.insert_tag2_en = false;
753 txvlan_cfg.default_tag2 = 0;
754 txvlan_cfg.tag_shift_mode_en = true;
756 ret = hns3_set_vlan_tx_offload_cfg(hns, &txvlan_cfg);
758 hns3_err(hw, "pf vlan set pvid failed, pvid =%u ,ret =%d", pvid,
763 hns3_update_tx_offload_cfg(hns, &txvlan_cfg);
769 hns3_rm_all_vlan_table(struct hns3_adapter *hns, bool is_del_list)
771 struct hns3_user_vlan_table *vlan_entry;
772 struct hns3_pf *pf = &hns->pf;
774 LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
775 if (vlan_entry->hd_tbl_status) {
776 hns3_set_port_vlan_filter(hns, vlan_entry->vlan_id, 0);
777 vlan_entry->hd_tbl_status = false;
782 vlan_entry = LIST_FIRST(&pf->vlan_list);
784 LIST_REMOVE(vlan_entry, next);
785 rte_free(vlan_entry);
786 vlan_entry = LIST_FIRST(&pf->vlan_list);
792 hns3_add_all_vlan_table(struct hns3_adapter *hns)
794 struct hns3_user_vlan_table *vlan_entry;
795 struct hns3_pf *pf = &hns->pf;
797 LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
798 if (!vlan_entry->hd_tbl_status) {
799 hns3_set_port_vlan_filter(hns, vlan_entry->vlan_id, 1);
800 vlan_entry->hd_tbl_status = true;
806 hns3_remove_all_vlan_table(struct hns3_adapter *hns)
808 struct hns3_hw *hw = &hns->hw;
811 hns3_rm_all_vlan_table(hns, true);
812 if (hw->port_base_vlan_cfg.pvid != HNS3_INVALID_PVID) {
813 ret = hns3_set_port_vlan_filter(hns,
814 hw->port_base_vlan_cfg.pvid, 0);
816 hns3_err(hw, "Failed to remove all vlan table, ret =%d",
824 hns3_update_vlan_filter_entries(struct hns3_adapter *hns,
825 uint16_t port_base_vlan_state, uint16_t new_pvid)
827 struct hns3_hw *hw = &hns->hw;
831 if (port_base_vlan_state == HNS3_PORT_BASE_VLAN_ENABLE) {
832 old_pvid = hw->port_base_vlan_cfg.pvid;
833 if (old_pvid != HNS3_INVALID_PVID) {
834 ret = hns3_set_port_vlan_filter(hns, old_pvid, 0);
836 hns3_err(hw, "failed to remove old pvid %u, "
837 "ret = %d", old_pvid, ret);
842 hns3_rm_all_vlan_table(hns, false);
843 ret = hns3_set_port_vlan_filter(hns, new_pvid, 1);
845 hns3_err(hw, "failed to add new pvid %u, ret = %d",
850 ret = hns3_set_port_vlan_filter(hns, new_pvid, 0);
852 hns3_err(hw, "failed to remove pvid %u, ret = %d",
857 hns3_add_all_vlan_table(hns);
863 hns3_en_pvid_strip(struct hns3_adapter *hns, int on)
865 struct hns3_rx_vtag_cfg *old_cfg = &hns->pf.vtag_config.rx_vcfg;
866 struct hns3_rx_vtag_cfg rx_vlan_cfg;
870 rx_strip_en = old_cfg->rx_vlan_offload_en;
872 rx_vlan_cfg.strip_tag1_en = rx_strip_en;
873 rx_vlan_cfg.strip_tag2_en = true;
874 rx_vlan_cfg.strip_tag2_discard_en = true;
876 rx_vlan_cfg.strip_tag1_en = false;
877 rx_vlan_cfg.strip_tag2_en = rx_strip_en;
878 rx_vlan_cfg.strip_tag2_discard_en = false;
880 rx_vlan_cfg.strip_tag1_discard_en = false;
881 rx_vlan_cfg.vlan1_vlan_prionly = false;
882 rx_vlan_cfg.vlan2_vlan_prionly = false;
883 rx_vlan_cfg.rx_vlan_offload_en = old_cfg->rx_vlan_offload_en;
885 ret = hns3_set_vlan_rx_offload_cfg(hns, &rx_vlan_cfg);
889 hns3_update_rx_offload_cfg(hns, &rx_vlan_cfg);
894 hns3_vlan_pvid_configure(struct hns3_adapter *hns, uint16_t pvid, int on)
896 struct hns3_hw *hw = &hns->hw;
897 uint16_t port_base_vlan_state;
900 if (on == 0 && pvid != hw->port_base_vlan_cfg.pvid) {
901 if (hw->port_base_vlan_cfg.pvid != HNS3_INVALID_PVID)
902 hns3_warn(hw, "Invalid operation! As current pvid set "
903 "is %u, disable pvid %u is invalid",
904 hw->port_base_vlan_cfg.pvid, pvid);
908 port_base_vlan_state = on ? HNS3_PORT_BASE_VLAN_ENABLE :
909 HNS3_PORT_BASE_VLAN_DISABLE;
910 ret = hns3_vlan_txvlan_cfg(hns, port_base_vlan_state, pvid);
912 hns3_err(hw, "failed to config tx vlan for pvid, ret = %d",
917 ret = hns3_en_pvid_strip(hns, on);
919 hns3_err(hw, "failed to config rx vlan strip for pvid, "
924 if (pvid == HNS3_INVALID_PVID)
926 ret = hns3_update_vlan_filter_entries(hns, port_base_vlan_state, pvid);
928 hns3_err(hw, "failed to update vlan filter entries, ret = %d",
934 hw->port_base_vlan_cfg.state = port_base_vlan_state;
935 hw->port_base_vlan_cfg.pvid = on ? pvid : HNS3_INVALID_PVID;
940 hns3_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
942 struct hns3_adapter *hns = dev->data->dev_private;
943 struct hns3_hw *hw = &hns->hw;
944 bool pvid_en_state_change;
948 if (pvid > RTE_ETHER_MAX_VLAN_ID) {
949 hns3_err(hw, "Invalid vlan_id = %u > %d", pvid,
950 RTE_ETHER_MAX_VLAN_ID);
955 * If PVID configuration state change, should refresh the PVID
956 * configuration state in struct hns3_tx_queue/hns3_rx_queue.
958 pvid_state = hw->port_base_vlan_cfg.state;
959 if ((on && pvid_state == HNS3_PORT_BASE_VLAN_ENABLE) ||
960 (!on && pvid_state == HNS3_PORT_BASE_VLAN_DISABLE))
961 pvid_en_state_change = false;
963 pvid_en_state_change = true;
965 rte_spinlock_lock(&hw->lock);
966 ret = hns3_vlan_pvid_configure(hns, pvid, on);
967 rte_spinlock_unlock(&hw->lock);
971 * Only in HNS3_SW_SHIFT_AND_MODE the PVID related operation in Tx/Rx
972 * need be processed by PMD driver.
974 if (pvid_en_state_change &&
975 hw->vlan_mode == HNS3_SW_SHIFT_AND_DISCARD_MODE)
976 hns3_update_all_queues_pvid_proc_en(hw);
982 hns3_default_vlan_config(struct hns3_adapter *hns)
984 struct hns3_hw *hw = &hns->hw;
988 * When vlan filter is enabled, hardware regards packets without vlan
989 * as packets with vlan 0. Therefore, if vlan 0 is not in the vlan
990 * table, packets without vlan won't be received. So, add vlan 0 as
993 ret = hns3_vlan_filter_configure(hns, 0, 1);
995 hns3_err(hw, "default vlan 0 config failed, ret =%d", ret);
1000 hns3_init_vlan_config(struct hns3_adapter *hns)
1002 struct hns3_hw *hw = &hns->hw;
1006 * This function can be called in the initialization and reset process,
1007 * when in reset process, it means that hardware had been reseted
1008 * successfully and we need to restore the hardware configuration to
1009 * ensure that the hardware configuration remains unchanged before and
1012 if (rte_atomic16_read(&hw->reset.resetting) == 0) {
1013 hw->port_base_vlan_cfg.state = HNS3_PORT_BASE_VLAN_DISABLE;
1014 hw->port_base_vlan_cfg.pvid = HNS3_INVALID_PVID;
1017 ret = hns3_vlan_filter_init(hns);
1019 hns3_err(hw, "vlan init fail in pf, ret =%d", ret);
1023 ret = hns3_vlan_tpid_configure(hns, ETH_VLAN_TYPE_INNER,
1024 RTE_ETHER_TYPE_VLAN);
1026 hns3_err(hw, "tpid set fail in pf, ret =%d", ret);
1031 * When in the reinit dev stage of the reset process, the following
1032 * vlan-related configurations may differ from those at initialization,
1033 * we will restore configurations to hardware in hns3_restore_vlan_table
1034 * and hns3_restore_vlan_conf later.
1036 if (rte_atomic16_read(&hw->reset.resetting) == 0) {
1037 ret = hns3_vlan_pvid_configure(hns, HNS3_INVALID_PVID, 0);
1039 hns3_err(hw, "pvid set fail in pf, ret =%d", ret);
1043 ret = hns3_en_hw_strip_rxvtag(hns, false);
1045 hns3_err(hw, "rx strip configure fail in pf, ret =%d",
1051 return hns3_default_vlan_config(hns);
1055 hns3_restore_vlan_conf(struct hns3_adapter *hns)
1057 struct hns3_pf *pf = &hns->pf;
1058 struct hns3_hw *hw = &hns->hw;
1063 if (!hw->data->promiscuous) {
1064 /* restore vlan filter states */
1065 offloads = hw->data->dev_conf.rxmode.offloads;
1066 enable = offloads & DEV_RX_OFFLOAD_VLAN_FILTER ? true : false;
1067 ret = hns3_enable_vlan_filter(hns, enable);
1069 hns3_err(hw, "failed to restore vlan rx filter conf, "
1075 ret = hns3_set_vlan_rx_offload_cfg(hns, &pf->vtag_config.rx_vcfg);
1077 hns3_err(hw, "failed to restore vlan rx conf, ret = %d", ret);
1081 ret = hns3_set_vlan_tx_offload_cfg(hns, &pf->vtag_config.tx_vcfg);
1083 hns3_err(hw, "failed to restore vlan tx conf, ret = %d", ret);
1089 hns3_dev_configure_vlan(struct rte_eth_dev *dev)
1091 struct hns3_adapter *hns = dev->data->dev_private;
1092 struct rte_eth_dev_data *data = dev->data;
1093 struct rte_eth_txmode *txmode;
1094 struct hns3_hw *hw = &hns->hw;
1098 txmode = &data->dev_conf.txmode;
1099 if (txmode->hw_vlan_reject_tagged || txmode->hw_vlan_reject_untagged)
1101 "hw_vlan_reject_tagged or hw_vlan_reject_untagged "
1102 "configuration is not supported! Ignore these two "
1103 "parameters: hw_vlan_reject_tagged(%u), "
1104 "hw_vlan_reject_untagged(%u)",
1105 txmode->hw_vlan_reject_tagged,
1106 txmode->hw_vlan_reject_untagged);
1108 /* Apply vlan offload setting */
1109 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK;
1110 ret = hns3_vlan_offload_set(dev, mask);
1112 hns3_err(hw, "dev config rx vlan offload failed, ret = %d",
1118 * If pvid config is not set in rte_eth_conf, driver needn't to set
1119 * VLAN pvid related configuration to hardware.
1121 if (txmode->pvid == 0 && txmode->hw_vlan_insert_pvid == 0)
1124 /* Apply pvid setting */
1125 ret = hns3_vlan_pvid_set(dev, txmode->pvid,
1126 txmode->hw_vlan_insert_pvid);
1128 hns3_err(hw, "dev config vlan pvid(%u) failed, ret = %d",
1135 hns3_config_tso(struct hns3_hw *hw, unsigned int tso_mss_min,
1136 unsigned int tso_mss_max)
1138 struct hns3_cfg_tso_status_cmd *req;
1139 struct hns3_cmd_desc desc;
1142 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TSO_GENERIC_CONFIG, false);
1144 req = (struct hns3_cfg_tso_status_cmd *)desc.data;
1147 hns3_set_field(tso_mss, HNS3_TSO_MSS_MIN_M, HNS3_TSO_MSS_MIN_S,
1149 req->tso_mss_min = rte_cpu_to_le_16(tso_mss);
1152 hns3_set_field(tso_mss, HNS3_TSO_MSS_MIN_M, HNS3_TSO_MSS_MIN_S,
1154 req->tso_mss_max = rte_cpu_to_le_16(tso_mss);
1156 return hns3_cmd_send(hw, &desc, 1);
1160 hns3_set_umv_space(struct hns3_hw *hw, uint16_t space_size,
1161 uint16_t *allocated_size, bool is_alloc)
1163 struct hns3_umv_spc_alc_cmd *req;
1164 struct hns3_cmd_desc desc;
1167 req = (struct hns3_umv_spc_alc_cmd *)desc.data;
1168 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_VLAN_ALLOCATE, false);
1169 hns3_set_bit(req->allocate, HNS3_UMV_SPC_ALC_B, is_alloc ? 0 : 1);
1170 req->space_size = rte_cpu_to_le_32(space_size);
1172 ret = hns3_cmd_send(hw, &desc, 1);
1174 PMD_INIT_LOG(ERR, "%s umv space failed for cmd_send, ret =%d",
1175 is_alloc ? "allocate" : "free", ret);
1179 if (is_alloc && allocated_size)
1180 *allocated_size = rte_le_to_cpu_32(desc.data[1]);
1186 hns3_init_umv_space(struct hns3_hw *hw)
1188 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1189 struct hns3_pf *pf = &hns->pf;
1190 uint16_t allocated_size = 0;
1193 ret = hns3_set_umv_space(hw, pf->wanted_umv_size, &allocated_size,
1198 if (allocated_size < pf->wanted_umv_size)
1199 PMD_INIT_LOG(WARNING, "Alloc umv space failed, want %u, get %u",
1200 pf->wanted_umv_size, allocated_size);
1202 pf->max_umv_size = (!!allocated_size) ? allocated_size :
1203 pf->wanted_umv_size;
1204 pf->used_umv_size = 0;
1209 hns3_uninit_umv_space(struct hns3_hw *hw)
1211 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1212 struct hns3_pf *pf = &hns->pf;
1215 if (pf->max_umv_size == 0)
1218 ret = hns3_set_umv_space(hw, pf->max_umv_size, NULL, false);
1222 pf->max_umv_size = 0;
1228 hns3_is_umv_space_full(struct hns3_hw *hw)
1230 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1231 struct hns3_pf *pf = &hns->pf;
1234 is_full = (pf->used_umv_size >= pf->max_umv_size);
1240 hns3_update_umv_space(struct hns3_hw *hw, bool is_free)
1242 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1243 struct hns3_pf *pf = &hns->pf;
1246 if (pf->used_umv_size > 0)
1247 pf->used_umv_size--;
1249 pf->used_umv_size++;
1253 hns3_prepare_mac_addr(struct hns3_mac_vlan_tbl_entry_cmd *new_req,
1254 const uint8_t *addr, bool is_mc)
1256 const unsigned char *mac_addr = addr;
1257 uint32_t high_val = ((uint32_t)mac_addr[3] << 24) |
1258 ((uint32_t)mac_addr[2] << 16) |
1259 ((uint32_t)mac_addr[1] << 8) |
1260 (uint32_t)mac_addr[0];
1261 uint32_t low_val = ((uint32_t)mac_addr[5] << 8) | (uint32_t)mac_addr[4];
1263 hns3_set_bit(new_req->flags, HNS3_MAC_VLAN_BIT0_EN_B, 1);
1265 hns3_set_bit(new_req->entry_type, HNS3_MAC_VLAN_BIT0_EN_B, 0);
1266 hns3_set_bit(new_req->entry_type, HNS3_MAC_VLAN_BIT1_EN_B, 1);
1267 hns3_set_bit(new_req->mc_mac_en, HNS3_MAC_VLAN_BIT0_EN_B, 1);
1270 new_req->mac_addr_hi32 = rte_cpu_to_le_32(high_val);
1271 new_req->mac_addr_lo16 = rte_cpu_to_le_16(low_val & 0xffff);
1275 hns3_get_mac_vlan_cmd_status(struct hns3_hw *hw, uint16_t cmdq_resp,
1277 enum hns3_mac_vlan_tbl_opcode op)
1280 hns3_err(hw, "cmdq execute failed for get_mac_vlan_cmd_status,status=%u",
1285 if (op == HNS3_MAC_VLAN_ADD) {
1286 if (resp_code == 0 || resp_code == 1) {
1288 } else if (resp_code == HNS3_ADD_UC_OVERFLOW) {
1289 hns3_err(hw, "add mac addr failed for uc_overflow");
1291 } else if (resp_code == HNS3_ADD_MC_OVERFLOW) {
1292 hns3_err(hw, "add mac addr failed for mc_overflow");
1296 hns3_err(hw, "add mac addr failed for undefined, code=%u",
1299 } else if (op == HNS3_MAC_VLAN_REMOVE) {
1300 if (resp_code == 0) {
1302 } else if (resp_code == 1) {
1303 hns3_dbg(hw, "remove mac addr failed for miss");
1307 hns3_err(hw, "remove mac addr failed for undefined, code=%u",
1310 } else if (op == HNS3_MAC_VLAN_LKUP) {
1311 if (resp_code == 0) {
1313 } else if (resp_code == 1) {
1314 hns3_dbg(hw, "lookup mac addr failed for miss");
1318 hns3_err(hw, "lookup mac addr failed for undefined, code=%u",
1323 hns3_err(hw, "unknown opcode for get_mac_vlan_cmd_status, opcode=%u",
1330 hns3_lookup_mac_vlan_tbl(struct hns3_hw *hw,
1331 struct hns3_mac_vlan_tbl_entry_cmd *req,
1332 struct hns3_cmd_desc *desc, bool is_mc)
1338 hns3_cmd_setup_basic_desc(&desc[0], HNS3_OPC_MAC_VLAN_ADD, true);
1340 desc[0].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
1341 memcpy(desc[0].data, req,
1342 sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1343 hns3_cmd_setup_basic_desc(&desc[1], HNS3_OPC_MAC_VLAN_ADD,
1345 desc[1].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
1346 hns3_cmd_setup_basic_desc(&desc[2], HNS3_OPC_MAC_VLAN_ADD,
1348 ret = hns3_cmd_send(hw, desc, HNS3_MC_MAC_VLAN_ADD_DESC_NUM);
1350 memcpy(desc[0].data, req,
1351 sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1352 ret = hns3_cmd_send(hw, desc, 1);
1355 hns3_err(hw, "lookup mac addr failed for cmd_send, ret =%d.",
1359 resp_code = (rte_le_to_cpu_32(desc[0].data[0]) >> 8) & 0xff;
1360 retval = rte_le_to_cpu_16(desc[0].retval);
1362 return hns3_get_mac_vlan_cmd_status(hw, retval, resp_code,
1363 HNS3_MAC_VLAN_LKUP);
1367 hns3_add_mac_vlan_tbl(struct hns3_hw *hw,
1368 struct hns3_mac_vlan_tbl_entry_cmd *req,
1369 struct hns3_cmd_desc *mc_desc)
1376 if (mc_desc == NULL) {
1377 struct hns3_cmd_desc desc;
1379 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_VLAN_ADD, false);
1380 memcpy(desc.data, req,
1381 sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1382 ret = hns3_cmd_send(hw, &desc, 1);
1383 resp_code = (rte_le_to_cpu_32(desc.data[0]) >> 8) & 0xff;
1384 retval = rte_le_to_cpu_16(desc.retval);
1386 cfg_status = hns3_get_mac_vlan_cmd_status(hw, retval, resp_code,
1389 hns3_cmd_reuse_desc(&mc_desc[0], false);
1390 mc_desc[0].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
1391 hns3_cmd_reuse_desc(&mc_desc[1], false);
1392 mc_desc[1].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
1393 hns3_cmd_reuse_desc(&mc_desc[2], false);
1394 mc_desc[2].flag &= rte_cpu_to_le_16(~HNS3_CMD_FLAG_NEXT);
1395 memcpy(mc_desc[0].data, req,
1396 sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1397 mc_desc[0].retval = 0;
1398 ret = hns3_cmd_send(hw, mc_desc, HNS3_MC_MAC_VLAN_ADD_DESC_NUM);
1399 resp_code = (rte_le_to_cpu_32(mc_desc[0].data[0]) >> 8) & 0xff;
1400 retval = rte_le_to_cpu_16(mc_desc[0].retval);
1402 cfg_status = hns3_get_mac_vlan_cmd_status(hw, retval, resp_code,
1407 hns3_err(hw, "add mac addr failed for cmd_send, ret =%d", ret);
1415 hns3_remove_mac_vlan_tbl(struct hns3_hw *hw,
1416 struct hns3_mac_vlan_tbl_entry_cmd *req)
1418 struct hns3_cmd_desc desc;
1423 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_VLAN_REMOVE, false);
1425 memcpy(desc.data, req, sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1427 ret = hns3_cmd_send(hw, &desc, 1);
1429 hns3_err(hw, "del mac addr failed for cmd_send, ret =%d", ret);
1432 resp_code = (rte_le_to_cpu_32(desc.data[0]) >> 8) & 0xff;
1433 retval = rte_le_to_cpu_16(desc.retval);
1435 return hns3_get_mac_vlan_cmd_status(hw, retval, resp_code,
1436 HNS3_MAC_VLAN_REMOVE);
1440 hns3_add_uc_addr_common(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1442 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1443 struct hns3_mac_vlan_tbl_entry_cmd req;
1444 struct hns3_pf *pf = &hns->pf;
1445 struct hns3_cmd_desc desc[3];
1446 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1447 uint16_t egress_port = 0;
1451 /* check if mac addr is valid */
1452 if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
1453 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1455 hns3_err(hw, "Add unicast mac addr err! addr(%s) invalid",
1460 memset(&req, 0, sizeof(req));
1463 * In current version VF is not supported when PF is driven by DPDK
1464 * driver, just need to configure parameters for PF vport.
1466 vf_id = HNS3_PF_FUNC_ID;
1467 hns3_set_field(egress_port, HNS3_MAC_EPORT_VFID_M,
1468 HNS3_MAC_EPORT_VFID_S, vf_id);
1470 req.egress_port = rte_cpu_to_le_16(egress_port);
1472 hns3_prepare_mac_addr(&req, mac_addr->addr_bytes, false);
1475 * Lookup the mac address in the mac_vlan table, and add
1476 * it if the entry is inexistent. Repeated unicast entry
1477 * is not allowed in the mac vlan table.
1479 ret = hns3_lookup_mac_vlan_tbl(hw, &req, desc, false);
1480 if (ret == -ENOENT) {
1481 if (!hns3_is_umv_space_full(hw)) {
1482 ret = hns3_add_mac_vlan_tbl(hw, &req, NULL);
1484 hns3_update_umv_space(hw, false);
1488 hns3_err(hw, "UC MAC table full(%u)", pf->used_umv_size);
1493 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, mac_addr);
1495 /* check if we just hit the duplicate */
1497 hns3_dbg(hw, "mac addr(%s) has been in the MAC table", mac_str);
1501 hns3_err(hw, "PF failed to add unicast entry(%s) in the MAC table",
1508 hns3_add_mc_addr_common(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1510 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1511 struct rte_ether_addr *addr;
1515 for (i = 0; i < hw->mc_addrs_num; i++) {
1516 addr = &hw->mc_addrs[i];
1517 /* Check if there are duplicate addresses */
1518 if (rte_is_same_ether_addr(addr, mac_addr)) {
1519 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1521 hns3_err(hw, "failed to add mc mac addr, same addrs"
1522 "(%s) is added by the set_mc_mac_addr_list "
1528 ret = hns3_add_mc_addr(hw, mac_addr);
1530 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1532 hns3_err(hw, "failed to add mc mac addr(%s), ret = %d",
1539 hns3_remove_mc_addr_common(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1541 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1544 ret = hns3_remove_mc_addr(hw, mac_addr);
1546 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1548 hns3_err(hw, "failed to remove mc mac addr(%s), ret = %d",
1555 hns3_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1556 uint32_t idx, __rte_unused uint32_t pool)
1558 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1559 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1562 rte_spinlock_lock(&hw->lock);
1565 * In hns3 network engine adding UC and MC mac address with different
1566 * commands with firmware. We need to determine whether the input
1567 * address is a UC or a MC address to call different commands.
1568 * By the way, it is recommended calling the API function named
1569 * rte_eth_dev_set_mc_addr_list to set the MC mac address, because
1570 * using the rte_eth_dev_mac_addr_add API function to set MC mac address
1571 * may affect the specifications of UC mac addresses.
1573 if (rte_is_multicast_ether_addr(mac_addr))
1574 ret = hns3_add_mc_addr_common(hw, mac_addr);
1576 ret = hns3_add_uc_addr_common(hw, mac_addr);
1579 rte_spinlock_unlock(&hw->lock);
1580 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1582 hns3_err(hw, "failed to add mac addr(%s), ret = %d", mac_str,
1588 hw->mac.default_addr_setted = true;
1589 rte_spinlock_unlock(&hw->lock);
1595 hns3_remove_uc_addr_common(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1597 struct hns3_mac_vlan_tbl_entry_cmd req;
1598 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1601 /* check if mac addr is valid */
1602 if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
1603 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1605 hns3_err(hw, "remove unicast mac addr err! addr(%s) invalid",
1610 memset(&req, 0, sizeof(req));
1611 hns3_set_bit(req.entry_type, HNS3_MAC_VLAN_BIT0_EN_B, 0);
1612 hns3_prepare_mac_addr(&req, mac_addr->addr_bytes, false);
1613 ret = hns3_remove_mac_vlan_tbl(hw, &req);
1614 if (ret == -ENOENT) /* mac addr isn't existent in the mac vlan table. */
1617 hns3_update_umv_space(hw, true);
1623 hns3_remove_mac_addr(struct rte_eth_dev *dev, uint32_t idx)
1625 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1626 /* index will be checked by upper level rte interface */
1627 struct rte_ether_addr *mac_addr = &dev->data->mac_addrs[idx];
1628 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1631 rte_spinlock_lock(&hw->lock);
1633 if (rte_is_multicast_ether_addr(mac_addr))
1634 ret = hns3_remove_mc_addr_common(hw, mac_addr);
1636 ret = hns3_remove_uc_addr_common(hw, mac_addr);
1637 rte_spinlock_unlock(&hw->lock);
1639 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1641 hns3_err(hw, "failed to remove mac addr(%s), ret = %d", mac_str,
1647 hns3_set_default_mac_addr(struct rte_eth_dev *dev,
1648 struct rte_ether_addr *mac_addr)
1650 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1651 struct rte_ether_addr *oaddr;
1652 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1653 bool default_addr_setted;
1654 bool rm_succes = false;
1658 * It has been guaranteed that input parameter named mac_addr is valid
1659 * address in the rte layer of DPDK framework.
1661 oaddr = (struct rte_ether_addr *)hw->mac.mac_addr;
1662 default_addr_setted = hw->mac.default_addr_setted;
1663 if (default_addr_setted && !!rte_is_same_ether_addr(mac_addr, oaddr))
1666 rte_spinlock_lock(&hw->lock);
1667 if (default_addr_setted) {
1668 ret = hns3_remove_uc_addr_common(hw, oaddr);
1670 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1672 hns3_warn(hw, "Remove old uc mac address(%s) fail: %d",
1679 ret = hns3_add_uc_addr_common(hw, mac_addr);
1681 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1683 hns3_err(hw, "Failed to set mac addr(%s): %d", mac_str, ret);
1684 goto err_add_uc_addr;
1687 ret = hns3_pause_addr_cfg(hw, mac_addr->addr_bytes);
1689 hns3_err(hw, "Failed to configure mac pause address: %d", ret);
1690 goto err_pause_addr_cfg;
1693 rte_ether_addr_copy(mac_addr,
1694 (struct rte_ether_addr *)hw->mac.mac_addr);
1695 hw->mac.default_addr_setted = true;
1696 rte_spinlock_unlock(&hw->lock);
1701 ret_val = hns3_remove_uc_addr_common(hw, mac_addr);
1703 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1706 "Failed to roll back to del setted mac addr(%s): %d",
1712 ret_val = hns3_add_uc_addr_common(hw, oaddr);
1714 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1717 "Failed to restore old uc mac addr(%s): %d",
1719 hw->mac.default_addr_setted = false;
1722 rte_spinlock_unlock(&hw->lock);
1728 hns3_configure_all_mac_addr(struct hns3_adapter *hns, bool del)
1730 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1731 struct hns3_hw *hw = &hns->hw;
1732 struct rte_ether_addr *addr;
1737 for (i = 0; i < HNS3_UC_MACADDR_NUM; i++) {
1738 addr = &hw->data->mac_addrs[i];
1739 if (rte_is_zero_ether_addr(addr))
1741 if (rte_is_multicast_ether_addr(addr))
1742 ret = del ? hns3_remove_mc_addr(hw, addr) :
1743 hns3_add_mc_addr(hw, addr);
1745 ret = del ? hns3_remove_uc_addr_common(hw, addr) :
1746 hns3_add_uc_addr_common(hw, addr);
1750 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1752 hns3_err(hw, "failed to %s mac addr(%s) index:%d "
1753 "ret = %d.", del ? "remove" : "restore",
1761 hns3_update_desc_vfid(struct hns3_cmd_desc *desc, uint8_t vfid, bool clr)
1763 #define HNS3_VF_NUM_IN_FIRST_DESC 192
1767 if (vfid < HNS3_VF_NUM_IN_FIRST_DESC) {
1768 word_num = vfid / 32;
1769 bit_num = vfid % 32;
1771 desc[1].data[word_num] &=
1772 rte_cpu_to_le_32(~(1UL << bit_num));
1774 desc[1].data[word_num] |=
1775 rte_cpu_to_le_32(1UL << bit_num);
1777 word_num = (vfid - HNS3_VF_NUM_IN_FIRST_DESC) / 32;
1778 bit_num = vfid % 32;
1780 desc[2].data[word_num] &=
1781 rte_cpu_to_le_32(~(1UL << bit_num));
1783 desc[2].data[word_num] |=
1784 rte_cpu_to_le_32(1UL << bit_num);
1789 hns3_add_mc_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1791 struct hns3_mac_vlan_tbl_entry_cmd req;
1792 struct hns3_cmd_desc desc[3];
1793 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1797 /* Check if mac addr is valid */
1798 if (!rte_is_multicast_ether_addr(mac_addr)) {
1799 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1801 hns3_err(hw, "failed to add mc mac addr, addr(%s) invalid",
1806 memset(&req, 0, sizeof(req));
1807 hns3_set_bit(req.entry_type, HNS3_MAC_VLAN_BIT0_EN_B, 0);
1808 hns3_prepare_mac_addr(&req, mac_addr->addr_bytes, true);
1809 ret = hns3_lookup_mac_vlan_tbl(hw, &req, desc, true);
1811 /* This mac addr do not exist, add new entry for it */
1812 memset(desc[0].data, 0, sizeof(desc[0].data));
1813 memset(desc[1].data, 0, sizeof(desc[0].data));
1814 memset(desc[2].data, 0, sizeof(desc[0].data));
1818 * In current version VF is not supported when PF is driven by DPDK
1819 * driver, just need to configure parameters for PF vport.
1821 vf_id = HNS3_PF_FUNC_ID;
1822 hns3_update_desc_vfid(desc, vf_id, false);
1823 ret = hns3_add_mac_vlan_tbl(hw, &req, desc);
1826 hns3_err(hw, "mc mac vlan table is full");
1827 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1829 hns3_err(hw, "failed to add mc mac addr(%s): %d", mac_str, ret);
1836 hns3_remove_mc_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1838 struct hns3_mac_vlan_tbl_entry_cmd req;
1839 struct hns3_cmd_desc desc[3];
1840 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1844 /* Check if mac addr is valid */
1845 if (!rte_is_multicast_ether_addr(mac_addr)) {
1846 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1848 hns3_err(hw, "Failed to rm mc mac addr, addr(%s) invalid",
1853 memset(&req, 0, sizeof(req));
1854 hns3_set_bit(req.entry_type, HNS3_MAC_VLAN_BIT0_EN_B, 0);
1855 hns3_prepare_mac_addr(&req, mac_addr->addr_bytes, true);
1856 ret = hns3_lookup_mac_vlan_tbl(hw, &req, desc, true);
1859 * This mac addr exist, remove this handle's VFID for it.
1860 * In current version VF is not supported when PF is driven by
1861 * DPDK driver, just need to configure parameters for PF vport.
1863 vf_id = HNS3_PF_FUNC_ID;
1864 hns3_update_desc_vfid(desc, vf_id, true);
1866 /* All the vfid is zero, so need to delete this entry */
1867 ret = hns3_remove_mac_vlan_tbl(hw, &req);
1868 } else if (ret == -ENOENT) {
1869 /* This mac addr doesn't exist. */
1874 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1876 hns3_err(hw, "Failed to rm mc mac addr(%s): %d", mac_str, ret);
1883 hns3_set_mc_addr_chk_param(struct hns3_hw *hw,
1884 struct rte_ether_addr *mc_addr_set,
1885 uint32_t nb_mc_addr)
1887 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1888 struct rte_ether_addr *addr;
1892 if (nb_mc_addr > HNS3_MC_MACADDR_NUM) {
1893 hns3_err(hw, "failed to set mc mac addr, nb_mc_addr(%u) "
1894 "invalid. valid range: 0~%d",
1895 nb_mc_addr, HNS3_MC_MACADDR_NUM);
1899 /* Check if input mac addresses are valid */
1900 for (i = 0; i < nb_mc_addr; i++) {
1901 addr = &mc_addr_set[i];
1902 if (!rte_is_multicast_ether_addr(addr)) {
1903 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1906 "failed to set mc mac addr, addr(%s) invalid.",
1911 /* Check if there are duplicate addresses */
1912 for (j = i + 1; j < nb_mc_addr; j++) {
1913 if (rte_is_same_ether_addr(addr, &mc_addr_set[j])) {
1914 rte_ether_format_addr(mac_str,
1915 RTE_ETHER_ADDR_FMT_SIZE,
1917 hns3_err(hw, "failed to set mc mac addr, "
1918 "addrs invalid. two same addrs(%s).",
1925 * Check if there are duplicate addresses between mac_addrs
1928 for (j = 0; j < HNS3_UC_MACADDR_NUM; j++) {
1929 if (rte_is_same_ether_addr(addr,
1930 &hw->data->mac_addrs[j])) {
1931 rte_ether_format_addr(mac_str,
1932 RTE_ETHER_ADDR_FMT_SIZE,
1934 hns3_err(hw, "failed to set mc mac addr, "
1935 "addrs invalid. addrs(%s) has already "
1936 "configured in mac_addr add API",
1947 hns3_set_mc_addr_calc_addr(struct hns3_hw *hw,
1948 struct rte_ether_addr *mc_addr_set,
1950 struct rte_ether_addr *reserved_addr_list,
1951 int *reserved_addr_num,
1952 struct rte_ether_addr *add_addr_list,
1954 struct rte_ether_addr *rm_addr_list,
1957 struct rte_ether_addr *addr;
1958 int current_addr_num;
1959 int reserved_num = 0;
1967 /* Calculate the mc mac address list that should be removed */
1968 current_addr_num = hw->mc_addrs_num;
1969 for (i = 0; i < current_addr_num; i++) {
1970 addr = &hw->mc_addrs[i];
1972 for (j = 0; j < mc_addr_num; j++) {
1973 if (rte_is_same_ether_addr(addr, &mc_addr_set[j])) {
1980 rte_ether_addr_copy(addr, &rm_addr_list[rm_num]);
1983 rte_ether_addr_copy(addr,
1984 &reserved_addr_list[reserved_num]);
1989 /* Calculate the mc mac address list that should be added */
1990 for (i = 0; i < mc_addr_num; i++) {
1991 addr = &mc_addr_set[i];
1993 for (j = 0; j < current_addr_num; j++) {
1994 if (rte_is_same_ether_addr(addr, &hw->mc_addrs[j])) {
2001 rte_ether_addr_copy(addr, &add_addr_list[add_num]);
2006 /* Reorder the mc mac address list maintained by driver */
2007 for (i = 0; i < reserved_num; i++)
2008 rte_ether_addr_copy(&reserved_addr_list[i], &hw->mc_addrs[i]);
2010 for (i = 0; i < rm_num; i++) {
2011 num = reserved_num + i;
2012 rte_ether_addr_copy(&rm_addr_list[i], &hw->mc_addrs[num]);
2015 *reserved_addr_num = reserved_num;
2016 *add_addr_num = add_num;
2017 *rm_addr_num = rm_num;
2021 hns3_set_mc_mac_addr_list(struct rte_eth_dev *dev,
2022 struct rte_ether_addr *mc_addr_set,
2023 uint32_t nb_mc_addr)
2025 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2026 struct rte_ether_addr reserved_addr_list[HNS3_MC_MACADDR_NUM];
2027 struct rte_ether_addr add_addr_list[HNS3_MC_MACADDR_NUM];
2028 struct rte_ether_addr rm_addr_list[HNS3_MC_MACADDR_NUM];
2029 struct rte_ether_addr *addr;
2030 int reserved_addr_num;
2038 /* Check if input parameters are valid */
2039 ret = hns3_set_mc_addr_chk_param(hw, mc_addr_set, nb_mc_addr);
2043 rte_spinlock_lock(&hw->lock);
2046 * Calculate the mc mac address lists those should be removed and be
2047 * added, Reorder the mc mac address list maintained by driver.
2049 mc_addr_num = (int)nb_mc_addr;
2050 hns3_set_mc_addr_calc_addr(hw, mc_addr_set, mc_addr_num,
2051 reserved_addr_list, &reserved_addr_num,
2052 add_addr_list, &add_addr_num,
2053 rm_addr_list, &rm_addr_num);
2055 /* Remove mc mac addresses */
2056 for (i = 0; i < rm_addr_num; i++) {
2057 num = rm_addr_num - i - 1;
2058 addr = &rm_addr_list[num];
2059 ret = hns3_remove_mc_addr(hw, addr);
2061 rte_spinlock_unlock(&hw->lock);
2067 /* Add mc mac addresses */
2068 for (i = 0; i < add_addr_num; i++) {
2069 addr = &add_addr_list[i];
2070 ret = hns3_add_mc_addr(hw, addr);
2072 rte_spinlock_unlock(&hw->lock);
2076 num = reserved_addr_num + i;
2077 rte_ether_addr_copy(addr, &hw->mc_addrs[num]);
2080 rte_spinlock_unlock(&hw->lock);
2086 hns3_configure_all_mc_mac_addr(struct hns3_adapter *hns, bool del)
2088 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
2089 struct hns3_hw *hw = &hns->hw;
2090 struct rte_ether_addr *addr;
2095 for (i = 0; i < hw->mc_addrs_num; i++) {
2096 addr = &hw->mc_addrs[i];
2097 if (!rte_is_multicast_ether_addr(addr))
2100 ret = hns3_remove_mc_addr(hw, addr);
2102 ret = hns3_add_mc_addr(hw, addr);
2105 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
2107 hns3_dbg(hw, "%s mc mac addr: %s failed for pf: ret = %d",
2108 del ? "Remove" : "Restore", mac_str, ret);
2115 hns3_check_mq_mode(struct rte_eth_dev *dev)
2117 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
2118 enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
2119 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2120 struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2121 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
2122 struct rte_eth_dcb_tx_conf *dcb_tx_conf;
2127 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
2128 dcb_tx_conf = &dev->data->dev_conf.tx_adv_conf.dcb_tx_conf;
2130 if (rx_mq_mode == ETH_MQ_RX_VMDQ_DCB_RSS) {
2131 hns3_err(hw, "ETH_MQ_RX_VMDQ_DCB_RSS is not supported. "
2132 "rx_mq_mode = %d", rx_mq_mode);
2136 if (rx_mq_mode == ETH_MQ_RX_VMDQ_DCB ||
2137 tx_mq_mode == ETH_MQ_TX_VMDQ_DCB) {
2138 hns3_err(hw, "ETH_MQ_RX_VMDQ_DCB and ETH_MQ_TX_VMDQ_DCB "
2139 "is not supported. rx_mq_mode = %d, tx_mq_mode = %d",
2140 rx_mq_mode, tx_mq_mode);
2144 if (rx_mq_mode == ETH_MQ_RX_DCB_RSS) {
2145 if (dcb_rx_conf->nb_tcs > pf->tc_max) {
2146 hns3_err(hw, "nb_tcs(%u) > max_tc(%u) driver supported.",
2147 dcb_rx_conf->nb_tcs, pf->tc_max);
2151 if (!(dcb_rx_conf->nb_tcs == HNS3_4_TCS ||
2152 dcb_rx_conf->nb_tcs == HNS3_8_TCS)) {
2153 hns3_err(hw, "on ETH_MQ_RX_DCB_RSS mode, "
2154 "nb_tcs(%d) != %d or %d in rx direction.",
2155 dcb_rx_conf->nb_tcs, HNS3_4_TCS, HNS3_8_TCS);
2159 if (dcb_rx_conf->nb_tcs != dcb_tx_conf->nb_tcs) {
2160 hns3_err(hw, "num_tcs(%d) of tx is not equal to rx(%d)",
2161 dcb_tx_conf->nb_tcs, dcb_rx_conf->nb_tcs);
2165 for (i = 0; i < HNS3_MAX_USER_PRIO; i++) {
2166 if (dcb_rx_conf->dcb_tc[i] != dcb_tx_conf->dcb_tc[i]) {
2167 hns3_err(hw, "dcb_tc[%d] = %u in rx direction, "
2168 "is not equal to one in tx direction.",
2169 i, dcb_rx_conf->dcb_tc[i]);
2172 if (dcb_rx_conf->dcb_tc[i] > max_tc)
2173 max_tc = dcb_rx_conf->dcb_tc[i];
2176 num_tc = max_tc + 1;
2177 if (num_tc > dcb_rx_conf->nb_tcs) {
2178 hns3_err(hw, "max num_tc(%u) mapped > nb_tcs(%u)",
2179 num_tc, dcb_rx_conf->nb_tcs);
2188 hns3_check_dcb_cfg(struct rte_eth_dev *dev)
2190 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2192 if (!hns3_dev_dcb_supported(hw)) {
2193 hns3_err(hw, "this port does not support dcb configurations.");
2197 if (hw->current_fc_status == HNS3_FC_STATUS_MAC_PAUSE) {
2198 hns3_err(hw, "MAC pause enabled, cannot config dcb info.");
2202 /* Check multiple queue mode */
2203 return hns3_check_mq_mode(dev);
2207 hns3_bind_ring_with_vector(struct hns3_hw *hw, uint8_t vector_id, bool mmap,
2208 enum hns3_ring_type queue_type, uint16_t queue_id)
2210 struct hns3_cmd_desc desc;
2211 struct hns3_ctrl_vector_chain_cmd *req =
2212 (struct hns3_ctrl_vector_chain_cmd *)desc.data;
2213 enum hns3_cmd_status status;
2214 enum hns3_opcode_type op;
2215 uint16_t tqp_type_and_id = 0;
2220 op = mmap ? HNS3_OPC_ADD_RING_TO_VECTOR : HNS3_OPC_DEL_RING_TO_VECTOR;
2221 hns3_cmd_setup_basic_desc(&desc, op, false);
2222 req->int_vector_id = vector_id;
2224 if (queue_type == HNS3_RING_TYPE_RX)
2225 gl = HNS3_RING_GL_RX;
2227 gl = HNS3_RING_GL_TX;
2231 hns3_set_field(tqp_type_and_id, HNS3_INT_TYPE_M, HNS3_INT_TYPE_S,
2233 hns3_set_field(tqp_type_and_id, HNS3_TQP_ID_M, HNS3_TQP_ID_S, queue_id);
2234 hns3_set_field(tqp_type_and_id, HNS3_INT_GL_IDX_M, HNS3_INT_GL_IDX_S,
2236 req->tqp_type_and_id[0] = rte_cpu_to_le_16(tqp_type_and_id);
2237 req->int_cause_num = 1;
2238 op_str = mmap ? "Map" : "Unmap";
2239 status = hns3_cmd_send(hw, &desc, 1);
2241 hns3_err(hw, "%s TQP %u fail, vector_id is %u, status is %d.",
2242 op_str, queue_id, req->int_vector_id, status);
2250 hns3_init_ring_with_vector(struct hns3_hw *hw)
2257 * In hns3 network engine, vector 0 is always the misc interrupt of this
2258 * function, vector 1~N can be used respectively for the queues of the
2259 * function. Tx and Rx queues with the same number share the interrupt
2260 * vector. In the initialization clearing the all hardware mapping
2261 * relationship configurations between queues and interrupt vectors is
2262 * needed, so some error caused by the residual configurations, such as
2263 * the unexpected Tx interrupt, can be avoid.
2265 vec = hw->num_msi - 1; /* vector 0 for misc interrupt, not for queue */
2266 if (hw->intr.mapping_mode == HNS3_INTR_MAPPING_VEC_RSV_ONE)
2267 vec = vec - 1; /* the last interrupt is reserved */
2268 hw->intr_tqps_num = RTE_MIN(vec, hw->tqps_num);
2269 for (i = 0; i < hw->intr_tqps_num; i++) {
2271 * Set gap limiter/rate limiter/quanity limiter algorithm
2272 * configuration for interrupt coalesce of queue's interrupt.
2274 hns3_set_queue_intr_gl(hw, i, HNS3_RING_GL_RX,
2275 HNS3_TQP_INTR_GL_DEFAULT);
2276 hns3_set_queue_intr_gl(hw, i, HNS3_RING_GL_TX,
2277 HNS3_TQP_INTR_GL_DEFAULT);
2278 hns3_set_queue_intr_rl(hw, i, HNS3_TQP_INTR_RL_DEFAULT);
2280 * QL(quantity limiter) is not used currently, just set 0 to
2283 hns3_set_queue_intr_ql(hw, i, HNS3_TQP_INTR_QL_DEFAULT);
2285 ret = hns3_bind_ring_with_vector(hw, vec, false,
2286 HNS3_RING_TYPE_TX, i);
2288 PMD_INIT_LOG(ERR, "PF fail to unbind TX ring(%d) with "
2289 "vector: %u, ret=%d", i, vec, ret);
2293 ret = hns3_bind_ring_with_vector(hw, vec, false,
2294 HNS3_RING_TYPE_RX, i);
2296 PMD_INIT_LOG(ERR, "PF fail to unbind RX ring(%d) with "
2297 "vector: %u, ret=%d", i, vec, ret);
2306 hns3_dev_configure(struct rte_eth_dev *dev)
2308 struct hns3_adapter *hns = dev->data->dev_private;
2309 struct rte_eth_conf *conf = &dev->data->dev_conf;
2310 enum rte_eth_rx_mq_mode mq_mode = conf->rxmode.mq_mode;
2311 struct hns3_hw *hw = &hns->hw;
2312 struct hns3_rss_conf *rss_cfg = &hw->rss_info;
2313 uint16_t nb_rx_q = dev->data->nb_rx_queues;
2314 uint16_t nb_tx_q = dev->data->nb_tx_queues;
2315 struct rte_eth_rss_conf rss_conf;
2320 hw->cfg_max_queues = RTE_MAX(nb_rx_q, nb_tx_q);
2323 * Some versions of hardware network engine does not support
2324 * individually enable/disable/reset the Tx or Rx queue. These devices
2325 * must enable/disable/reset Tx and Rx queues at the same time. When the
2326 * numbers of Tx queues allocated by upper applications are not equal to
2327 * the numbers of Rx queues, driver needs to setup fake Tx or Rx queues
2328 * to adjust numbers of Tx/Rx queues. otherwise, network engine can not
2329 * work as usual. But these fake queues are imperceptible, and can not
2330 * be used by upper applications.
2332 if (!hns3_dev_indep_txrx_supported(hw)) {
2333 ret = hns3_set_fake_rx_or_tx_queues(dev, nb_rx_q, nb_tx_q);
2335 hns3_err(hw, "fail to set Rx/Tx fake queues, ret = %d.",
2341 hw->adapter_state = HNS3_NIC_CONFIGURING;
2342 if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
2343 hns3_err(hw, "setting link speed/duplex not supported");
2348 if ((uint32_t)mq_mode & ETH_MQ_RX_DCB_FLAG) {
2349 ret = hns3_check_dcb_cfg(dev);
2354 /* When RSS is not configured, redirect the packet queue 0 */
2355 if ((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG) {
2356 conf->rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
2357 rss_conf = conf->rx_adv_conf.rss_conf;
2358 hw->rss_dis_flag = false;
2359 if (rss_conf.rss_key == NULL) {
2360 rss_conf.rss_key = rss_cfg->key;
2361 rss_conf.rss_key_len = HNS3_RSS_KEY_SIZE;
2364 ret = hns3_dev_rss_hash_update(dev, &rss_conf);
2370 * If jumbo frames are enabled, MTU needs to be refreshed
2371 * according to the maximum RX packet length.
2373 if (conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
2375 * Security of max_rx_pkt_len is guaranteed in dpdk frame.
2376 * Maximum value of max_rx_pkt_len is HNS3_MAX_FRAME_LEN, so it
2377 * can safely assign to "uint16_t" type variable.
2379 mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(conf->rxmode.max_rx_pkt_len);
2380 ret = hns3_dev_mtu_set(dev, mtu);
2383 dev->data->mtu = mtu;
2386 ret = hns3_dev_configure_vlan(dev);
2390 /* config hardware GRO */
2391 gro_en = conf->rxmode.offloads & DEV_RX_OFFLOAD_TCP_LRO ? true : false;
2392 ret = hns3_config_gro(hw, gro_en);
2396 hns->rx_simple_allowed = true;
2397 hns->rx_vec_allowed = true;
2398 hns->tx_simple_allowed = true;
2399 hns->tx_vec_allowed = true;
2401 hns3_init_rx_ptype_tble(dev);
2402 hw->adapter_state = HNS3_NIC_CONFIGURED;
2407 (void)hns3_set_fake_rx_or_tx_queues(dev, 0, 0);
2408 hw->adapter_state = HNS3_NIC_INITIALIZED;
2414 hns3_set_mac_mtu(struct hns3_hw *hw, uint16_t new_mps)
2416 struct hns3_config_max_frm_size_cmd *req;
2417 struct hns3_cmd_desc desc;
2419 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_MAX_FRM_SIZE, false);
2421 req = (struct hns3_config_max_frm_size_cmd *)desc.data;
2422 req->max_frm_size = rte_cpu_to_le_16(new_mps);
2423 req->min_frm_size = RTE_ETHER_MIN_LEN;
2425 return hns3_cmd_send(hw, &desc, 1);
2429 hns3_config_mtu(struct hns3_hw *hw, uint16_t mps)
2433 ret = hns3_set_mac_mtu(hw, mps);
2435 hns3_err(hw, "Failed to set mtu, ret = %d", ret);
2439 ret = hns3_buffer_alloc(hw);
2441 hns3_err(hw, "Failed to allocate buffer, ret = %d", ret);
2447 hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
2449 struct hns3_adapter *hns = dev->data->dev_private;
2450 uint32_t frame_size = mtu + HNS3_ETH_OVERHEAD;
2451 struct hns3_hw *hw = &hns->hw;
2452 bool is_jumbo_frame;
2455 if (dev->data->dev_started) {
2456 hns3_err(hw, "Failed to set mtu, port %u must be stopped "
2457 "before configuration", dev->data->port_id);
2461 rte_spinlock_lock(&hw->lock);
2462 is_jumbo_frame = frame_size > RTE_ETHER_MAX_LEN ? true : false;
2463 frame_size = RTE_MAX(frame_size, HNS3_DEFAULT_FRAME_LEN);
2466 * Maximum value of frame_size is HNS3_MAX_FRAME_LEN, so it can safely
2467 * assign to "uint16_t" type variable.
2469 ret = hns3_config_mtu(hw, (uint16_t)frame_size);
2471 rte_spinlock_unlock(&hw->lock);
2472 hns3_err(hw, "Failed to set mtu, port %u mtu %u: %d",
2473 dev->data->port_id, mtu, ret);
2476 hns->pf.mps = (uint16_t)frame_size;
2478 dev->data->dev_conf.rxmode.offloads |=
2479 DEV_RX_OFFLOAD_JUMBO_FRAME;
2481 dev->data->dev_conf.rxmode.offloads &=
2482 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2483 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
2484 rte_spinlock_unlock(&hw->lock);
2490 hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
2492 struct hns3_adapter *hns = eth_dev->data->dev_private;
2493 struct hns3_hw *hw = &hns->hw;
2494 uint16_t queue_num = hw->tqps_num;
2497 * In interrupt mode, 'max_rx_queues' is set based on the number of
2498 * MSI-X interrupt resources of the hardware.
2500 if (hw->data->dev_conf.intr_conf.rxq == 1)
2501 queue_num = hw->intr_tqps_num;
2503 info->max_rx_queues = queue_num;
2504 info->max_tx_queues = hw->tqps_num;
2505 info->max_rx_pktlen = HNS3_MAX_FRAME_LEN; /* CRC included */
2506 info->min_rx_bufsize = HNS3_MIN_BD_BUF_SIZE;
2507 info->max_mac_addrs = HNS3_UC_MACADDR_NUM;
2508 info->max_mtu = info->max_rx_pktlen - HNS3_ETH_OVERHEAD;
2509 info->max_lro_pkt_size = HNS3_MAX_LRO_SIZE;
2510 info->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
2511 DEV_RX_OFFLOAD_TCP_CKSUM |
2512 DEV_RX_OFFLOAD_UDP_CKSUM |
2513 DEV_RX_OFFLOAD_SCTP_CKSUM |
2514 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
2515 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM |
2516 DEV_RX_OFFLOAD_KEEP_CRC |
2517 DEV_RX_OFFLOAD_SCATTER |
2518 DEV_RX_OFFLOAD_VLAN_STRIP |
2519 DEV_RX_OFFLOAD_VLAN_FILTER |
2520 DEV_RX_OFFLOAD_JUMBO_FRAME |
2521 DEV_RX_OFFLOAD_RSS_HASH |
2522 DEV_RX_OFFLOAD_TCP_LRO);
2523 info->tx_offload_capa = (DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
2524 DEV_TX_OFFLOAD_IPV4_CKSUM |
2525 DEV_TX_OFFLOAD_TCP_CKSUM |
2526 DEV_TX_OFFLOAD_UDP_CKSUM |
2527 DEV_TX_OFFLOAD_SCTP_CKSUM |
2528 DEV_TX_OFFLOAD_MULTI_SEGS |
2529 DEV_TX_OFFLOAD_TCP_TSO |
2530 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
2531 DEV_TX_OFFLOAD_GRE_TNL_TSO |
2532 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
2533 DEV_TX_OFFLOAD_MBUF_FAST_FREE |
2534 hns3_txvlan_cap_get(hw));
2536 if (hns3_dev_indep_txrx_supported(hw))
2537 info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
2538 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
2540 info->rx_desc_lim = (struct rte_eth_desc_lim) {
2541 .nb_max = HNS3_MAX_RING_DESC,
2542 .nb_min = HNS3_MIN_RING_DESC,
2543 .nb_align = HNS3_ALIGN_RING_DESC,
2546 info->tx_desc_lim = (struct rte_eth_desc_lim) {
2547 .nb_max = HNS3_MAX_RING_DESC,
2548 .nb_min = HNS3_MIN_RING_DESC,
2549 .nb_align = HNS3_ALIGN_RING_DESC,
2550 .nb_seg_max = HNS3_MAX_TSO_BD_PER_PKT,
2551 .nb_mtu_seg_max = hw->max_non_tso_bd_num,
2554 info->default_rxconf = (struct rte_eth_rxconf) {
2555 .rx_free_thresh = HNS3_DEFAULT_RX_FREE_THRESH,
2557 * If there are no available Rx buffer descriptors, incoming
2558 * packets are always dropped by hardware based on hns3 network
2564 info->default_txconf = (struct rte_eth_txconf) {
2565 .tx_rs_thresh = HNS3_DEFAULT_TX_RS_THRESH,
2569 info->vmdq_queue_num = 0;
2571 info->reta_size = HNS3_RSS_IND_TBL_SIZE;
2572 info->hash_key_size = HNS3_RSS_KEY_SIZE;
2573 info->flow_type_rss_offloads = HNS3_ETH_RSS_SUPPORT;
2575 info->default_rxportconf.burst_size = HNS3_DEFAULT_PORT_CONF_BURST_SIZE;
2576 info->default_txportconf.burst_size = HNS3_DEFAULT_PORT_CONF_BURST_SIZE;
2577 info->default_rxportconf.nb_queues = HNS3_DEFAULT_PORT_CONF_QUEUES_NUM;
2578 info->default_txportconf.nb_queues = HNS3_DEFAULT_PORT_CONF_QUEUES_NUM;
2579 info->default_rxportconf.ring_size = HNS3_DEFAULT_RING_DESC;
2580 info->default_txportconf.ring_size = HNS3_DEFAULT_RING_DESC;
2586 hns3_fw_version_get(struct rte_eth_dev *eth_dev, char *fw_version,
2589 struct hns3_adapter *hns = eth_dev->data->dev_private;
2590 struct hns3_hw *hw = &hns->hw;
2591 uint32_t version = hw->fw_version;
2594 ret = snprintf(fw_version, fw_size, "%lu.%lu.%lu.%lu",
2595 hns3_get_field(version, HNS3_FW_VERSION_BYTE3_M,
2596 HNS3_FW_VERSION_BYTE3_S),
2597 hns3_get_field(version, HNS3_FW_VERSION_BYTE2_M,
2598 HNS3_FW_VERSION_BYTE2_S),
2599 hns3_get_field(version, HNS3_FW_VERSION_BYTE1_M,
2600 HNS3_FW_VERSION_BYTE1_S),
2601 hns3_get_field(version, HNS3_FW_VERSION_BYTE0_M,
2602 HNS3_FW_VERSION_BYTE0_S));
2603 ret += 1; /* add the size of '\0' */
2604 if (fw_size < (uint32_t)ret)
2611 hns3_dev_link_update(struct rte_eth_dev *eth_dev,
2612 __rte_unused int wait_to_complete)
2614 struct hns3_adapter *hns = eth_dev->data->dev_private;
2615 struct hns3_hw *hw = &hns->hw;
2616 struct hns3_mac *mac = &hw->mac;
2617 struct rte_eth_link new_link;
2619 if (!hns3_is_reset_pending(hns)) {
2620 hns3_update_speed_duplex(eth_dev);
2621 hns3_update_link_status(hw);
2624 memset(&new_link, 0, sizeof(new_link));
2625 switch (mac->link_speed) {
2626 case ETH_SPEED_NUM_10M:
2627 case ETH_SPEED_NUM_100M:
2628 case ETH_SPEED_NUM_1G:
2629 case ETH_SPEED_NUM_10G:
2630 case ETH_SPEED_NUM_25G:
2631 case ETH_SPEED_NUM_40G:
2632 case ETH_SPEED_NUM_50G:
2633 case ETH_SPEED_NUM_100G:
2634 case ETH_SPEED_NUM_200G:
2635 new_link.link_speed = mac->link_speed;
2638 new_link.link_speed = ETH_SPEED_NUM_100M;
2642 new_link.link_duplex = mac->link_duplex;
2643 new_link.link_status = mac->link_status ? ETH_LINK_UP : ETH_LINK_DOWN;
2644 new_link.link_autoneg =
2645 !(eth_dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED);
2647 return rte_eth_linkstatus_set(eth_dev, &new_link);
2651 hns3_parse_func_status(struct hns3_hw *hw, struct hns3_func_status_cmd *status)
2653 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2654 struct hns3_pf *pf = &hns->pf;
2656 if (!(status->pf_state & HNS3_PF_STATE_DONE))
2659 pf->is_main_pf = (status->pf_state & HNS3_PF_STATE_MAIN) ? true : false;
2665 hns3_query_function_status(struct hns3_hw *hw)
2667 #define HNS3_QUERY_MAX_CNT 10
2668 #define HNS3_QUERY_SLEEP_MSCOEND 1
2669 struct hns3_func_status_cmd *req;
2670 struct hns3_cmd_desc desc;
2674 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_FUNC_STATUS, true);
2675 req = (struct hns3_func_status_cmd *)desc.data;
2678 ret = hns3_cmd_send(hw, &desc, 1);
2680 PMD_INIT_LOG(ERR, "query function status failed %d",
2685 /* Check pf reset is done */
2689 rte_delay_ms(HNS3_QUERY_SLEEP_MSCOEND);
2690 } while (timeout++ < HNS3_QUERY_MAX_CNT);
2692 return hns3_parse_func_status(hw, req);
2696 hns3_get_pf_max_tqp_num(struct hns3_hw *hw)
2698 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2699 struct hns3_pf *pf = &hns->pf;
2701 if (pf->tqp_config_mode == HNS3_FLEX_MAX_TQP_NUM_MODE) {
2703 * The total_tqps_num obtained from firmware is maximum tqp
2704 * numbers of this port, which should be used for PF and VFs.
2705 * There is no need for pf to have so many tqp numbers in
2706 * most cases. RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF,
2707 * coming from config file, is assigned to maximum queue number
2708 * for the PF of this port by user. So users can modify the
2709 * maximum queue number of PF according to their own application
2710 * scenarios, which is more flexible to use. In addition, many
2711 * memories can be saved due to allocating queue statistics
2712 * room according to the actual number of queues required. The
2713 * maximum queue number of PF for network engine with
2714 * revision_id greater than 0x30 is assigned by config file.
2716 if (RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF <= 0) {
2717 hns3_err(hw, "RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF(%d) "
2718 "must be greater than 0.",
2719 RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF);
2723 hw->tqps_num = RTE_MIN(RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF,
2724 hw->total_tqps_num);
2727 * Due to the limitation on the number of PF interrupts
2728 * available, the maximum queue number assigned to PF on
2729 * the network engine with revision_id 0x21 is 64.
2731 hw->tqps_num = RTE_MIN(hw->total_tqps_num,
2732 HNS3_MAX_TQP_NUM_HIP08_PF);
2739 hns3_query_pf_resource(struct hns3_hw *hw)
2741 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2742 struct hns3_pf *pf = &hns->pf;
2743 struct hns3_pf_res_cmd *req;
2744 struct hns3_cmd_desc desc;
2747 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_PF_RSRC, true);
2748 ret = hns3_cmd_send(hw, &desc, 1);
2750 PMD_INIT_LOG(ERR, "query pf resource failed %d", ret);
2754 req = (struct hns3_pf_res_cmd *)desc.data;
2755 hw->total_tqps_num = rte_le_to_cpu_16(req->tqp_num) +
2756 rte_le_to_cpu_16(req->ext_tqp_num);
2757 ret = hns3_get_pf_max_tqp_num(hw);
2761 pf->pkt_buf_size = rte_le_to_cpu_16(req->buf_size) << HNS3_BUF_UNIT_S;
2762 pf->func_num = rte_le_to_cpu_16(req->pf_own_fun_number);
2764 if (req->tx_buf_size)
2766 rte_le_to_cpu_16(req->tx_buf_size) << HNS3_BUF_UNIT_S;
2768 pf->tx_buf_size = HNS3_DEFAULT_TX_BUF;
2770 pf->tx_buf_size = roundup(pf->tx_buf_size, HNS3_BUF_SIZE_UNIT);
2772 if (req->dv_buf_size)
2774 rte_le_to_cpu_16(req->dv_buf_size) << HNS3_BUF_UNIT_S;
2776 pf->dv_buf_size = HNS3_DEFAULT_DV;
2778 pf->dv_buf_size = roundup(pf->dv_buf_size, HNS3_BUF_SIZE_UNIT);
2781 hns3_get_field(rte_le_to_cpu_16(req->nic_pf_intr_vector_number),
2782 HNS3_PF_VEC_NUM_M, HNS3_PF_VEC_NUM_S);
2788 hns3_parse_cfg(struct hns3_cfg *cfg, struct hns3_cmd_desc *desc)
2790 struct hns3_cfg_param_cmd *req;
2791 uint64_t mac_addr_tmp_high;
2792 uint8_t ext_rss_size_max;
2793 uint64_t mac_addr_tmp;
2796 req = (struct hns3_cfg_param_cmd *)desc[0].data;
2798 /* get the configuration */
2799 cfg->vmdq_vport_num = hns3_get_field(rte_le_to_cpu_32(req->param[0]),
2800 HNS3_CFG_VMDQ_M, HNS3_CFG_VMDQ_S);
2801 cfg->tc_num = hns3_get_field(rte_le_to_cpu_32(req->param[0]),
2802 HNS3_CFG_TC_NUM_M, HNS3_CFG_TC_NUM_S);
2803 cfg->tqp_desc_num = hns3_get_field(rte_le_to_cpu_32(req->param[0]),
2804 HNS3_CFG_TQP_DESC_N_M,
2805 HNS3_CFG_TQP_DESC_N_S);
2807 cfg->phy_addr = hns3_get_field(rte_le_to_cpu_32(req->param[1]),
2808 HNS3_CFG_PHY_ADDR_M,
2809 HNS3_CFG_PHY_ADDR_S);
2810 cfg->media_type = hns3_get_field(rte_le_to_cpu_32(req->param[1]),
2811 HNS3_CFG_MEDIA_TP_M,
2812 HNS3_CFG_MEDIA_TP_S);
2813 cfg->rx_buf_len = hns3_get_field(rte_le_to_cpu_32(req->param[1]),
2814 HNS3_CFG_RX_BUF_LEN_M,
2815 HNS3_CFG_RX_BUF_LEN_S);
2816 /* get mac address */
2817 mac_addr_tmp = rte_le_to_cpu_32(req->param[2]);
2818 mac_addr_tmp_high = hns3_get_field(rte_le_to_cpu_32(req->param[3]),
2819 HNS3_CFG_MAC_ADDR_H_M,
2820 HNS3_CFG_MAC_ADDR_H_S);
2822 mac_addr_tmp |= (mac_addr_tmp_high << 31) << 1;
2824 cfg->default_speed = hns3_get_field(rte_le_to_cpu_32(req->param[3]),
2825 HNS3_CFG_DEFAULT_SPEED_M,
2826 HNS3_CFG_DEFAULT_SPEED_S);
2827 cfg->rss_size_max = hns3_get_field(rte_le_to_cpu_32(req->param[3]),
2828 HNS3_CFG_RSS_SIZE_M,
2829 HNS3_CFG_RSS_SIZE_S);
2831 for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
2832 cfg->mac_addr[i] = (mac_addr_tmp >> (8 * i)) & 0xff;
2834 req = (struct hns3_cfg_param_cmd *)desc[1].data;
2835 cfg->numa_node_map = rte_le_to_cpu_32(req->param[0]);
2837 cfg->speed_ability = hns3_get_field(rte_le_to_cpu_32(req->param[1]),
2838 HNS3_CFG_SPEED_ABILITY_M,
2839 HNS3_CFG_SPEED_ABILITY_S);
2840 cfg->umv_space = hns3_get_field(rte_le_to_cpu_32(req->param[1]),
2841 HNS3_CFG_UMV_TBL_SPACE_M,
2842 HNS3_CFG_UMV_TBL_SPACE_S);
2843 if (!cfg->umv_space)
2844 cfg->umv_space = HNS3_DEFAULT_UMV_SPACE_PER_PF;
2846 ext_rss_size_max = hns3_get_field(rte_le_to_cpu_32(req->param[2]),
2847 HNS3_CFG_EXT_RSS_SIZE_M,
2848 HNS3_CFG_EXT_RSS_SIZE_S);
2851 * Field ext_rss_size_max obtained from firmware will be more flexible
2852 * for future changes and expansions, which is an exponent of 2, instead
2853 * of reading out directly. If this field is not zero, hns3 PF PMD
2854 * driver uses it as rss_size_max under one TC. Device, whose revision
2855 * id is greater than or equal to PCI_REVISION_ID_HIP09_A, obtains the
2856 * maximum number of queues supported under a TC through this field.
2858 if (ext_rss_size_max)
2859 cfg->rss_size_max = 1U << ext_rss_size_max;
2862 /* hns3_get_board_cfg: query the static parameter from NCL_config file in flash
2863 * @hw: pointer to struct hns3_hw
2864 * @hcfg: the config structure to be getted
2867 hns3_get_board_cfg(struct hns3_hw *hw, struct hns3_cfg *hcfg)
2869 struct hns3_cmd_desc desc[HNS3_PF_CFG_DESC_NUM];
2870 struct hns3_cfg_param_cmd *req;
2875 for (i = 0; i < HNS3_PF_CFG_DESC_NUM; i++) {
2877 req = (struct hns3_cfg_param_cmd *)desc[i].data;
2878 hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_GET_CFG_PARAM,
2880 hns3_set_field(offset, HNS3_CFG_OFFSET_M, HNS3_CFG_OFFSET_S,
2881 i * HNS3_CFG_RD_LEN_BYTES);
2882 /* Len should be divided by 4 when send to hardware */
2883 hns3_set_field(offset, HNS3_CFG_RD_LEN_M, HNS3_CFG_RD_LEN_S,
2884 HNS3_CFG_RD_LEN_BYTES / HNS3_CFG_RD_LEN_UNIT);
2885 req->offset = rte_cpu_to_le_32(offset);
2888 ret = hns3_cmd_send(hw, desc, HNS3_PF_CFG_DESC_NUM);
2890 PMD_INIT_LOG(ERR, "get config failed %d.", ret);
2894 hns3_parse_cfg(hcfg, desc);
2900 hns3_parse_speed(int speed_cmd, uint32_t *speed)
2902 switch (speed_cmd) {
2903 case HNS3_CFG_SPEED_10M:
2904 *speed = ETH_SPEED_NUM_10M;
2906 case HNS3_CFG_SPEED_100M:
2907 *speed = ETH_SPEED_NUM_100M;
2909 case HNS3_CFG_SPEED_1G:
2910 *speed = ETH_SPEED_NUM_1G;
2912 case HNS3_CFG_SPEED_10G:
2913 *speed = ETH_SPEED_NUM_10G;
2915 case HNS3_CFG_SPEED_25G:
2916 *speed = ETH_SPEED_NUM_25G;
2918 case HNS3_CFG_SPEED_40G:
2919 *speed = ETH_SPEED_NUM_40G;
2921 case HNS3_CFG_SPEED_50G:
2922 *speed = ETH_SPEED_NUM_50G;
2924 case HNS3_CFG_SPEED_100G:
2925 *speed = ETH_SPEED_NUM_100G;
2927 case HNS3_CFG_SPEED_200G:
2928 *speed = ETH_SPEED_NUM_200G;
2938 hns3_set_default_dev_specifications(struct hns3_hw *hw)
2940 hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
2941 hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
2942 hw->rss_key_size = HNS3_RSS_KEY_SIZE;
2943 hw->max_tm_rate = HNS3_ETHER_MAX_RATE;
2944 hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
2948 hns3_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
2950 struct hns3_dev_specs_0_cmd *req0;
2952 req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
2954 hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
2955 hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
2956 hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
2957 hw->max_tm_rate = rte_le_to_cpu_32(req0->max_tm_rate);
2958 hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
2962 hns3_query_dev_specifications(struct hns3_hw *hw)
2964 struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
2968 for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
2969 hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
2971 desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
2973 hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
2975 ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
2979 hns3_parse_dev_specifications(hw, desc);
2985 hns3_get_capability(struct hns3_hw *hw)
2987 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2988 struct rte_pci_device *pci_dev;
2989 struct hns3_pf *pf = &hns->pf;
2990 struct rte_eth_dev *eth_dev;
2995 eth_dev = &rte_eth_devices[hw->data->port_id];
2996 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2997 device_id = pci_dev->id.device_id;
2999 if (device_id == HNS3_DEV_ID_25GE_RDMA ||
3000 device_id == HNS3_DEV_ID_50GE_RDMA ||
3001 device_id == HNS3_DEV_ID_100G_RDMA_MACSEC ||
3002 device_id == HNS3_DEV_ID_200G_RDMA)
3003 hns3_set_bit(hw->capability, HNS3_DEV_SUPPORT_DCB_B, 1);
3005 ret = hns3_query_dev_fec_info(eth_dev);
3008 "failed to query FEC information, ret = %d", ret);
3012 /* Get PCI revision id */
3013 ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN,
3014 HNS3_PCI_REVISION_ID);
3015 if (ret != HNS3_PCI_REVISION_ID_LEN) {
3016 PMD_INIT_LOG(ERR, "failed to read pci revision id, ret = %d",
3020 hw->revision = revision;
3022 if (revision < PCI_REVISION_ID_HIP09_A) {
3023 hns3_set_default_dev_specifications(hw);
3024 hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
3025 hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
3026 hw->tso_mode = HNS3_TSO_SW_CAL_PSEUDO_H_CSUM;
3027 hw->vlan_mode = HNS3_SW_SHIFT_AND_DISCARD_MODE;
3028 hw->min_tx_pkt_len = HNS3_HIP08_MIN_TX_PKT_LEN;
3029 pf->tqp_config_mode = HNS3_FIXED_MAX_TQP_NUM_MODE;
3030 hw->rss_info.ipv6_sctp_offload_supported = false;
3034 ret = hns3_query_dev_specifications(hw);
3037 "failed to query dev specifications, ret = %d",
3042 hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_ALL;
3043 hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_1US;
3044 hw->tso_mode = HNS3_TSO_HW_CAL_PSEUDO_H_CSUM;
3045 hw->vlan_mode = HNS3_HW_SHIFT_AND_DISCARD_MODE;
3046 hw->min_tx_pkt_len = HNS3_HIP09_MIN_TX_PKT_LEN;
3047 pf->tqp_config_mode = HNS3_FLEX_MAX_TQP_NUM_MODE;
3048 hw->rss_info.ipv6_sctp_offload_supported = true;
3054 hns3_get_board_configuration(struct hns3_hw *hw)
3056 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3057 struct hns3_pf *pf = &hns->pf;
3058 struct hns3_cfg cfg;
3061 ret = hns3_get_board_cfg(hw, &cfg);
3063 PMD_INIT_LOG(ERR, "get board config failed %d", ret);
3067 if (cfg.media_type == HNS3_MEDIA_TYPE_COPPER &&
3068 !hns3_dev_copper_supported(hw)) {
3069 PMD_INIT_LOG(ERR, "media type is copper, not supported.");
3073 hw->mac.media_type = cfg.media_type;
3074 hw->rss_size_max = cfg.rss_size_max;
3075 hw->rss_dis_flag = false;
3076 memcpy(hw->mac.mac_addr, cfg.mac_addr, RTE_ETHER_ADDR_LEN);
3077 hw->mac.phy_addr = cfg.phy_addr;
3078 hw->mac.default_addr_setted = false;
3079 hw->num_tx_desc = cfg.tqp_desc_num;
3080 hw->num_rx_desc = cfg.tqp_desc_num;
3081 hw->dcb_info.num_pg = 1;
3082 hw->dcb_info.hw_pfc_map = 0;
3084 ret = hns3_parse_speed(cfg.default_speed, &hw->mac.link_speed);
3086 PMD_INIT_LOG(ERR, "Get wrong speed %u, ret = %d",
3087 cfg.default_speed, ret);
3091 pf->tc_max = cfg.tc_num;
3092 if (pf->tc_max > HNS3_MAX_TC_NUM || pf->tc_max < 1) {
3093 PMD_INIT_LOG(WARNING,
3094 "Get TC num(%u) from flash, set TC num to 1",
3099 /* Dev does not support DCB */
3100 if (!hns3_dev_dcb_supported(hw)) {
3104 pf->pfc_max = pf->tc_max;
3106 hw->dcb_info.num_tc = 1;
3107 hw->alloc_rss_size = RTE_MIN(hw->rss_size_max,
3108 hw->tqps_num / hw->dcb_info.num_tc);
3109 hns3_set_bit(hw->hw_tc_map, 0, 1);
3110 pf->tx_sch_mode = HNS3_FLAG_TC_BASE_SCH_MODE;
3112 pf->wanted_umv_size = cfg.umv_space;
3118 hns3_get_configuration(struct hns3_hw *hw)
3122 ret = hns3_query_function_status(hw);
3124 PMD_INIT_LOG(ERR, "Failed to query function status: %d.", ret);
3128 /* Get device capability */
3129 ret = hns3_get_capability(hw);
3131 PMD_INIT_LOG(ERR, "failed to get device capability: %d.", ret);
3135 /* Get pf resource */
3136 ret = hns3_query_pf_resource(hw);
3138 PMD_INIT_LOG(ERR, "Failed to query pf resource: %d", ret);
3142 ret = hns3_get_board_configuration(hw);
3144 PMD_INIT_LOG(ERR, "failed to get board configuration: %d", ret);
3150 hns3_map_tqps_to_func(struct hns3_hw *hw, uint16_t func_id, uint16_t tqp_pid,
3151 uint16_t tqp_vid, bool is_pf)
3153 struct hns3_tqp_map_cmd *req;
3154 struct hns3_cmd_desc desc;
3157 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_SET_TQP_MAP, false);
3159 req = (struct hns3_tqp_map_cmd *)desc.data;
3160 req->tqp_id = rte_cpu_to_le_16(tqp_pid);
3161 req->tqp_vf = func_id;
3162 req->tqp_flag = 1 << HNS3_TQP_MAP_EN_B;
3164 req->tqp_flag |= (1 << HNS3_TQP_MAP_TYPE_B);
3165 req->tqp_vid = rte_cpu_to_le_16(tqp_vid);
3167 ret = hns3_cmd_send(hw, &desc, 1);
3169 PMD_INIT_LOG(ERR, "TQP map failed %d", ret);
3175 hns3_map_tqp(struct hns3_hw *hw)
3181 * In current version, VF is not supported when PF is driven by DPDK
3182 * driver, so we assign total tqps_num tqps allocated to this port
3185 for (i = 0; i < hw->total_tqps_num; i++) {
3186 ret = hns3_map_tqps_to_func(hw, HNS3_PF_FUNC_ID, i, i, true);
3195 hns3_cfg_mac_speed_dup_hw(struct hns3_hw *hw, uint32_t speed, uint8_t duplex)
3197 struct hns3_config_mac_speed_dup_cmd *req;
3198 struct hns3_cmd_desc desc;
3201 req = (struct hns3_config_mac_speed_dup_cmd *)desc.data;
3203 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_SPEED_DUP, false);
3205 hns3_set_bit(req->speed_dup, HNS3_CFG_DUPLEX_B, !!duplex ? 1 : 0);
3208 case ETH_SPEED_NUM_10M:
3209 hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
3210 HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_10M);
3212 case ETH_SPEED_NUM_100M:
3213 hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
3214 HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_100M);
3216 case ETH_SPEED_NUM_1G:
3217 hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
3218 HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_1G);
3220 case ETH_SPEED_NUM_10G:
3221 hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
3222 HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_10G);
3224 case ETH_SPEED_NUM_25G:
3225 hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
3226 HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_25G);
3228 case ETH_SPEED_NUM_40G:
3229 hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
3230 HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_40G);
3232 case ETH_SPEED_NUM_50G:
3233 hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
3234 HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_50G);
3236 case ETH_SPEED_NUM_100G:
3237 hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
3238 HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_100G);
3240 case ETH_SPEED_NUM_200G:
3241 hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
3242 HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_200G);
3245 PMD_INIT_LOG(ERR, "invalid speed (%u)", speed);
3249 hns3_set_bit(req->mac_change_fec_en, HNS3_CFG_MAC_SPEED_CHANGE_EN_B, 1);
3251 ret = hns3_cmd_send(hw, &desc, 1);
3253 PMD_INIT_LOG(ERR, "mac speed/duplex config cmd failed %d", ret);
3259 hns3_tx_buffer_calc(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3261 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3262 struct hns3_pf *pf = &hns->pf;
3263 struct hns3_priv_buf *priv;
3264 uint32_t i, total_size;
3266 total_size = pf->pkt_buf_size;
3268 /* alloc tx buffer for all enabled tc */
3269 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3270 priv = &buf_alloc->priv_buf[i];
3272 if (hw->hw_tc_map & BIT(i)) {
3273 if (total_size < pf->tx_buf_size)
3276 priv->tx_buf_size = pf->tx_buf_size;
3278 priv->tx_buf_size = 0;
3280 total_size -= priv->tx_buf_size;
3287 hns3_tx_buffer_alloc(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3289 /* TX buffer size is unit by 128 byte */
3290 #define HNS3_BUF_SIZE_UNIT_SHIFT 7
3291 #define HNS3_BUF_SIZE_UPDATE_EN_MSK BIT(15)
3292 struct hns3_tx_buff_alloc_cmd *req;
3293 struct hns3_cmd_desc desc;
3298 req = (struct hns3_tx_buff_alloc_cmd *)desc.data;
3300 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TX_BUFF_ALLOC, 0);
3301 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3302 buf_size = buf_alloc->priv_buf[i].tx_buf_size;
3304 buf_size = buf_size >> HNS3_BUF_SIZE_UNIT_SHIFT;
3305 req->tx_pkt_buff[i] = rte_cpu_to_le_16(buf_size |
3306 HNS3_BUF_SIZE_UPDATE_EN_MSK);
3309 ret = hns3_cmd_send(hw, &desc, 1);
3311 PMD_INIT_LOG(ERR, "tx buffer alloc cmd failed %d", ret);
3317 hns3_get_tc_num(struct hns3_hw *hw)
3322 for (i = 0; i < HNS3_MAX_TC_NUM; i++)
3323 if (hw->hw_tc_map & BIT(i))
3329 hns3_get_rx_priv_buff_alloced(struct hns3_pkt_buf_alloc *buf_alloc)
3331 struct hns3_priv_buf *priv;
3332 uint32_t rx_priv = 0;
3335 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3336 priv = &buf_alloc->priv_buf[i];
3338 rx_priv += priv->buf_size;
3344 hns3_get_tx_buff_alloced(struct hns3_pkt_buf_alloc *buf_alloc)
3346 uint32_t total_tx_size = 0;
3349 for (i = 0; i < HNS3_MAX_TC_NUM; i++)
3350 total_tx_size += buf_alloc->priv_buf[i].tx_buf_size;
3352 return total_tx_size;
3355 /* Get the number of pfc enabled TCs, which have private buffer */
3357 hns3_get_pfc_priv_num(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3359 struct hns3_priv_buf *priv;
3363 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3364 priv = &buf_alloc->priv_buf[i];
3365 if ((hw->dcb_info.hw_pfc_map & BIT(i)) && priv->enable)
3372 /* Get the number of pfc disabled TCs, which have private buffer */
3374 hns3_get_no_pfc_priv_num(struct hns3_hw *hw,
3375 struct hns3_pkt_buf_alloc *buf_alloc)
3377 struct hns3_priv_buf *priv;
3381 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3382 priv = &buf_alloc->priv_buf[i];
3383 if (hw->hw_tc_map & BIT(i) &&
3384 !(hw->dcb_info.hw_pfc_map & BIT(i)) && priv->enable)
3392 hns3_is_rx_buf_ok(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc,
3395 uint32_t shared_buf_min, shared_buf_tc, shared_std, hi_thrd, lo_thrd;
3396 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3397 struct hns3_pf *pf = &hns->pf;
3398 uint32_t shared_buf, aligned_mps;
3403 tc_num = hns3_get_tc_num(hw);
3404 aligned_mps = roundup(pf->mps, HNS3_BUF_SIZE_UNIT);
3406 if (hns3_dev_dcb_supported(hw))
3407 shared_buf_min = HNS3_BUF_MUL_BY * aligned_mps +
3410 shared_buf_min = aligned_mps + HNS3_NON_DCB_ADDITIONAL_BUF
3413 shared_buf_tc = tc_num * aligned_mps + aligned_mps;
3414 shared_std = roundup(RTE_MAX(shared_buf_min, shared_buf_tc),
3415 HNS3_BUF_SIZE_UNIT);
3417 rx_priv = hns3_get_rx_priv_buff_alloced(buf_alloc);
3418 if (rx_all < rx_priv + shared_std)
3421 shared_buf = rounddown(rx_all - rx_priv, HNS3_BUF_SIZE_UNIT);
3422 buf_alloc->s_buf.buf_size = shared_buf;
3423 if (hns3_dev_dcb_supported(hw)) {
3424 buf_alloc->s_buf.self.high = shared_buf - pf->dv_buf_size;
3425 buf_alloc->s_buf.self.low = buf_alloc->s_buf.self.high
3426 - roundup(aligned_mps / HNS3_BUF_DIV_BY,
3427 HNS3_BUF_SIZE_UNIT);
3429 buf_alloc->s_buf.self.high =
3430 aligned_mps + HNS3_NON_DCB_ADDITIONAL_BUF;
3431 buf_alloc->s_buf.self.low = aligned_mps;
3434 if (hns3_dev_dcb_supported(hw)) {
3435 hi_thrd = shared_buf - pf->dv_buf_size;
3437 if (tc_num <= NEED_RESERVE_TC_NUM)
3438 hi_thrd = hi_thrd * BUF_RESERVE_PERCENT /
3442 hi_thrd = hi_thrd / tc_num;
3444 hi_thrd = RTE_MAX(hi_thrd, HNS3_BUF_MUL_BY * aligned_mps);
3445 hi_thrd = rounddown(hi_thrd, HNS3_BUF_SIZE_UNIT);
3446 lo_thrd = hi_thrd - aligned_mps / HNS3_BUF_DIV_BY;
3448 hi_thrd = aligned_mps + HNS3_NON_DCB_ADDITIONAL_BUF;
3449 lo_thrd = aligned_mps;
3452 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3453 buf_alloc->s_buf.tc_thrd[i].low = lo_thrd;
3454 buf_alloc->s_buf.tc_thrd[i].high = hi_thrd;
3461 hns3_rx_buf_calc_all(struct hns3_hw *hw, bool max,
3462 struct hns3_pkt_buf_alloc *buf_alloc)
3464 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3465 struct hns3_pf *pf = &hns->pf;
3466 struct hns3_priv_buf *priv;
3467 uint32_t aligned_mps;
3471 rx_all = pf->pkt_buf_size - hns3_get_tx_buff_alloced(buf_alloc);
3472 aligned_mps = roundup(pf->mps, HNS3_BUF_SIZE_UNIT);
3474 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3475 priv = &buf_alloc->priv_buf[i];
3482 if (!(hw->hw_tc_map & BIT(i)))
3486 if (hw->dcb_info.hw_pfc_map & BIT(i)) {
3487 priv->wl.low = max ? aligned_mps : HNS3_BUF_SIZE_UNIT;
3488 priv->wl.high = roundup(priv->wl.low + aligned_mps,
3489 HNS3_BUF_SIZE_UNIT);
3492 priv->wl.high = max ? (aligned_mps * HNS3_BUF_MUL_BY) :
3496 priv->buf_size = priv->wl.high + pf->dv_buf_size;
3499 return hns3_is_rx_buf_ok(hw, buf_alloc, rx_all);
3503 hns3_drop_nopfc_buf_till_fit(struct hns3_hw *hw,
3504 struct hns3_pkt_buf_alloc *buf_alloc)
3506 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3507 struct hns3_pf *pf = &hns->pf;
3508 struct hns3_priv_buf *priv;
3509 int no_pfc_priv_num;
3514 rx_all = pf->pkt_buf_size - hns3_get_tx_buff_alloced(buf_alloc);
3515 no_pfc_priv_num = hns3_get_no_pfc_priv_num(hw, buf_alloc);
3517 /* let the last to be cleared first */
3518 for (i = HNS3_MAX_TC_NUM - 1; i >= 0; i--) {
3519 priv = &buf_alloc->priv_buf[i];
3520 mask = BIT((uint8_t)i);
3522 if (hw->hw_tc_map & mask &&
3523 !(hw->dcb_info.hw_pfc_map & mask)) {
3524 /* Clear the no pfc TC private buffer */
3532 if (hns3_is_rx_buf_ok(hw, buf_alloc, rx_all) ||
3533 no_pfc_priv_num == 0)
3537 return hns3_is_rx_buf_ok(hw, buf_alloc, rx_all);
3541 hns3_drop_pfc_buf_till_fit(struct hns3_hw *hw,
3542 struct hns3_pkt_buf_alloc *buf_alloc)
3544 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3545 struct hns3_pf *pf = &hns->pf;
3546 struct hns3_priv_buf *priv;
3552 rx_all = pf->pkt_buf_size - hns3_get_tx_buff_alloced(buf_alloc);
3553 pfc_priv_num = hns3_get_pfc_priv_num(hw, buf_alloc);
3555 /* let the last to be cleared first */
3556 for (i = HNS3_MAX_TC_NUM - 1; i >= 0; i--) {
3557 priv = &buf_alloc->priv_buf[i];
3558 mask = BIT((uint8_t)i);
3560 if (hw->hw_tc_map & mask &&
3561 hw->dcb_info.hw_pfc_map & mask) {
3562 /* Reduce the number of pfc TC with private buffer */
3569 if (hns3_is_rx_buf_ok(hw, buf_alloc, rx_all) ||
3574 return hns3_is_rx_buf_ok(hw, buf_alloc, rx_all);
3578 hns3_only_alloc_priv_buff(struct hns3_hw *hw,
3579 struct hns3_pkt_buf_alloc *buf_alloc)
3581 #define COMPENSATE_BUFFER 0x3C00
3582 #define COMPENSATE_HALF_MPS_NUM 5
3583 #define PRIV_WL_GAP 0x1800
3584 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3585 struct hns3_pf *pf = &hns->pf;
3586 uint32_t tc_num = hns3_get_tc_num(hw);
3587 uint32_t half_mps = pf->mps >> 1;
3588 struct hns3_priv_buf *priv;
3589 uint32_t min_rx_priv;
3593 rx_priv = pf->pkt_buf_size - hns3_get_tx_buff_alloced(buf_alloc);
3595 rx_priv = rx_priv / tc_num;
3597 if (tc_num <= NEED_RESERVE_TC_NUM)
3598 rx_priv = rx_priv * BUF_RESERVE_PERCENT / BUF_MAX_PERCENT;
3601 * Minimum value of private buffer in rx direction (min_rx_priv) is
3602 * equal to "DV + 2.5 * MPS + 15KB". Driver only allocates rx private
3603 * buffer if rx_priv is greater than min_rx_priv.
3605 min_rx_priv = pf->dv_buf_size + COMPENSATE_BUFFER +
3606 COMPENSATE_HALF_MPS_NUM * half_mps;
3607 min_rx_priv = roundup(min_rx_priv, HNS3_BUF_SIZE_UNIT);
3608 rx_priv = rounddown(rx_priv, HNS3_BUF_SIZE_UNIT);
3610 if (rx_priv < min_rx_priv)
3613 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3614 priv = &buf_alloc->priv_buf[i];
3621 if (!(hw->hw_tc_map & BIT(i)))
3625 priv->buf_size = rx_priv;
3626 priv->wl.high = rx_priv - pf->dv_buf_size;
3627 priv->wl.low = priv->wl.high - PRIV_WL_GAP;
3630 buf_alloc->s_buf.buf_size = 0;
3636 * hns3_rx_buffer_calc: calculate the rx private buffer size for all TCs
3637 * @hw: pointer to struct hns3_hw
3638 * @buf_alloc: pointer to buffer calculation data
3639 * @return: 0: calculate sucessful, negative: fail
3642 hns3_rx_buffer_calc(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3644 /* When DCB is not supported, rx private buffer is not allocated. */
3645 if (!hns3_dev_dcb_supported(hw)) {
3646 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3647 struct hns3_pf *pf = &hns->pf;
3648 uint32_t rx_all = pf->pkt_buf_size;
3650 rx_all -= hns3_get_tx_buff_alloced(buf_alloc);
3651 if (!hns3_is_rx_buf_ok(hw, buf_alloc, rx_all))
3658 * Try to allocate privated packet buffer for all TCs without share
3661 if (hns3_only_alloc_priv_buff(hw, buf_alloc))
3665 * Try to allocate privated packet buffer for all TCs with share
3668 if (hns3_rx_buf_calc_all(hw, true, buf_alloc))
3672 * For different application scenes, the enabled port number, TC number
3673 * and no_drop TC number are different. In order to obtain the better
3674 * performance, software could allocate the buffer size and configure
3675 * the waterline by tring to decrease the private buffer size according
3676 * to the order, namely, waterline of valided tc, pfc disabled tc, pfc
3679 if (hns3_rx_buf_calc_all(hw, false, buf_alloc))
3682 if (hns3_drop_nopfc_buf_till_fit(hw, buf_alloc))
3685 if (hns3_drop_pfc_buf_till_fit(hw, buf_alloc))
3692 hns3_rx_priv_buf_alloc(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3694 struct hns3_rx_priv_buff_cmd *req;
3695 struct hns3_cmd_desc desc;
3700 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RX_PRIV_BUFF_ALLOC, false);
3701 req = (struct hns3_rx_priv_buff_cmd *)desc.data;
3703 /* Alloc private buffer TCs */
3704 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3705 struct hns3_priv_buf *priv = &buf_alloc->priv_buf[i];
3708 rte_cpu_to_le_16(priv->buf_size >> HNS3_BUF_UNIT_S);
3709 req->buf_num[i] |= rte_cpu_to_le_16(1 << HNS3_TC0_PRI_BUF_EN_B);
3712 buf_size = buf_alloc->s_buf.buf_size;
3713 req->shared_buf = rte_cpu_to_le_16((buf_size >> HNS3_BUF_UNIT_S) |
3714 (1 << HNS3_TC0_PRI_BUF_EN_B));
3716 ret = hns3_cmd_send(hw, &desc, 1);
3718 PMD_INIT_LOG(ERR, "rx private buffer alloc cmd failed %d", ret);
3724 hns3_rx_priv_wl_config(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3726 #define HNS3_RX_PRIV_WL_ALLOC_DESC_NUM 2
3727 struct hns3_rx_priv_wl_buf *req;
3728 struct hns3_priv_buf *priv;
3729 struct hns3_cmd_desc desc[HNS3_RX_PRIV_WL_ALLOC_DESC_NUM];
3733 for (i = 0; i < HNS3_RX_PRIV_WL_ALLOC_DESC_NUM; i++) {
3734 hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_RX_PRIV_WL_ALLOC,
3736 req = (struct hns3_rx_priv_wl_buf *)desc[i].data;
3738 /* The first descriptor set the NEXT bit to 1 */
3740 desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
3742 desc[i].flag &= ~rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
3744 for (j = 0; j < HNS3_TC_NUM_ONE_DESC; j++) {
3745 uint32_t idx = i * HNS3_TC_NUM_ONE_DESC + j;
3747 priv = &buf_alloc->priv_buf[idx];
3748 req->tc_wl[j].high = rte_cpu_to_le_16(priv->wl.high >>
3750 req->tc_wl[j].high |=
3751 rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3752 req->tc_wl[j].low = rte_cpu_to_le_16(priv->wl.low >>
3754 req->tc_wl[j].low |=
3755 rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3759 /* Send 2 descriptor at one time */
3760 ret = hns3_cmd_send(hw, desc, HNS3_RX_PRIV_WL_ALLOC_DESC_NUM);
3762 PMD_INIT_LOG(ERR, "rx private waterline config cmd failed %d",
3768 hns3_common_thrd_config(struct hns3_hw *hw,
3769 struct hns3_pkt_buf_alloc *buf_alloc)
3771 #define HNS3_RX_COM_THRD_ALLOC_DESC_NUM 2
3772 struct hns3_shared_buf *s_buf = &buf_alloc->s_buf;
3773 struct hns3_rx_com_thrd *req;
3774 struct hns3_cmd_desc desc[HNS3_RX_COM_THRD_ALLOC_DESC_NUM];
3775 struct hns3_tc_thrd *tc;
3780 for (i = 0; i < HNS3_RX_COM_THRD_ALLOC_DESC_NUM; i++) {
3781 hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_RX_COM_THRD_ALLOC,
3783 req = (struct hns3_rx_com_thrd *)&desc[i].data;
3785 /* The first descriptor set the NEXT bit to 1 */
3787 desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
3789 desc[i].flag &= ~rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
3791 for (j = 0; j < HNS3_TC_NUM_ONE_DESC; j++) {
3792 tc_idx = i * HNS3_TC_NUM_ONE_DESC + j;
3793 tc = &s_buf->tc_thrd[tc_idx];
3795 req->com_thrd[j].high =
3796 rte_cpu_to_le_16(tc->high >> HNS3_BUF_UNIT_S);
3797 req->com_thrd[j].high |=
3798 rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3799 req->com_thrd[j].low =
3800 rte_cpu_to_le_16(tc->low >> HNS3_BUF_UNIT_S);
3801 req->com_thrd[j].low |=
3802 rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3806 /* Send 2 descriptors at one time */
3807 ret = hns3_cmd_send(hw, desc, HNS3_RX_COM_THRD_ALLOC_DESC_NUM);
3809 PMD_INIT_LOG(ERR, "common threshold config cmd failed %d", ret);
3815 hns3_common_wl_config(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3817 struct hns3_shared_buf *buf = &buf_alloc->s_buf;
3818 struct hns3_rx_com_wl *req;
3819 struct hns3_cmd_desc desc;
3822 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RX_COM_WL_ALLOC, false);
3824 req = (struct hns3_rx_com_wl *)desc.data;
3825 req->com_wl.high = rte_cpu_to_le_16(buf->self.high >> HNS3_BUF_UNIT_S);
3826 req->com_wl.high |= rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3828 req->com_wl.low = rte_cpu_to_le_16(buf->self.low >> HNS3_BUF_UNIT_S);
3829 req->com_wl.low |= rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3831 ret = hns3_cmd_send(hw, &desc, 1);
3833 PMD_INIT_LOG(ERR, "common waterline config cmd failed %d", ret);
3839 hns3_buffer_alloc(struct hns3_hw *hw)
3841 struct hns3_pkt_buf_alloc pkt_buf;
3844 memset(&pkt_buf, 0, sizeof(pkt_buf));
3845 ret = hns3_tx_buffer_calc(hw, &pkt_buf);
3848 "could not calc tx buffer size for all TCs %d",
3853 ret = hns3_tx_buffer_alloc(hw, &pkt_buf);
3855 PMD_INIT_LOG(ERR, "could not alloc tx buffers %d", ret);
3859 ret = hns3_rx_buffer_calc(hw, &pkt_buf);
3862 "could not calc rx priv buffer size for all TCs %d",
3867 ret = hns3_rx_priv_buf_alloc(hw, &pkt_buf);
3869 PMD_INIT_LOG(ERR, "could not alloc rx priv buffer %d", ret);
3873 if (hns3_dev_dcb_supported(hw)) {
3874 ret = hns3_rx_priv_wl_config(hw, &pkt_buf);
3877 "could not configure rx private waterline %d",
3882 ret = hns3_common_thrd_config(hw, &pkt_buf);
3885 "could not configure common threshold %d",
3891 ret = hns3_common_wl_config(hw, &pkt_buf);
3893 PMD_INIT_LOG(ERR, "could not configure common waterline %d",
3900 hns3_mac_init(struct hns3_hw *hw)
3902 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3903 struct hns3_mac *mac = &hw->mac;
3904 struct hns3_pf *pf = &hns->pf;
3907 pf->support_sfp_query = true;
3908 mac->link_duplex = ETH_LINK_FULL_DUPLEX;
3909 ret = hns3_cfg_mac_speed_dup_hw(hw, mac->link_speed, mac->link_duplex);
3911 PMD_INIT_LOG(ERR, "Config mac speed dup fail ret = %d", ret);
3915 mac->link_status = ETH_LINK_DOWN;
3917 return hns3_config_mtu(hw, pf->mps);
3921 hns3_get_mac_ethertype_cmd_status(uint16_t cmdq_resp, uint8_t resp_code)
3923 #define HNS3_ETHERTYPE_SUCCESS_ADD 0
3924 #define HNS3_ETHERTYPE_ALREADY_ADD 1
3925 #define HNS3_ETHERTYPE_MGR_TBL_OVERFLOW 2
3926 #define HNS3_ETHERTYPE_KEY_CONFLICT 3
3931 "cmdq execute failed for get_mac_ethertype_cmd_status, status=%u.\n",
3936 switch (resp_code) {
3937 case HNS3_ETHERTYPE_SUCCESS_ADD:
3938 case HNS3_ETHERTYPE_ALREADY_ADD:
3941 case HNS3_ETHERTYPE_MGR_TBL_OVERFLOW:
3943 "add mac ethertype failed for manager table overflow.");
3944 return_status = -EIO;
3946 case HNS3_ETHERTYPE_KEY_CONFLICT:
3947 PMD_INIT_LOG(ERR, "add mac ethertype failed for key conflict.");
3948 return_status = -EIO;
3952 "add mac ethertype failed for undefined, code=%u.",
3954 return_status = -EIO;
3958 return return_status;
3962 hns3_add_mgr_tbl(struct hns3_hw *hw,
3963 const struct hns3_mac_mgr_tbl_entry_cmd *req)
3965 struct hns3_cmd_desc desc;
3970 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_ETHTYPE_ADD, false);
3971 memcpy(desc.data, req, sizeof(struct hns3_mac_mgr_tbl_entry_cmd));
3973 ret = hns3_cmd_send(hw, &desc, 1);
3976 "add mac ethertype failed for cmd_send, ret =%d.",
3981 resp_code = (rte_le_to_cpu_32(desc.data[0]) >> 8) & 0xff;
3982 retval = rte_le_to_cpu_16(desc.retval);
3984 return hns3_get_mac_ethertype_cmd_status(retval, resp_code);
3988 hns3_prepare_mgr_tbl(struct hns3_mac_mgr_tbl_entry_cmd *mgr_table,
3989 int *table_item_num)
3991 struct hns3_mac_mgr_tbl_entry_cmd *tbl;
3994 * In current version, we add one item in management table as below:
3995 * 0x0180C200000E -- LLDP MC address
3998 tbl->flags = HNS3_MAC_MGR_MASK_VLAN_B;
3999 tbl->ethter_type = rte_cpu_to_le_16(HNS3_MAC_ETHERTYPE_LLDP);
4000 tbl->mac_addr_hi32 = rte_cpu_to_le_32(htonl(0x0180C200));
4001 tbl->mac_addr_lo16 = rte_cpu_to_le_16(htons(0x000E));
4002 tbl->i_port_bitmap = 0x1;
4003 *table_item_num = 1;
4007 hns3_init_mgr_tbl(struct hns3_hw *hw)
4009 #define HNS_MAC_MGR_TBL_MAX_SIZE 16
4010 struct hns3_mac_mgr_tbl_entry_cmd mgr_table[HNS_MAC_MGR_TBL_MAX_SIZE];
4015 memset(mgr_table, 0, sizeof(mgr_table));
4016 hns3_prepare_mgr_tbl(mgr_table, &table_item_num);
4017 for (i = 0; i < table_item_num; i++) {
4018 ret = hns3_add_mgr_tbl(hw, &mgr_table[i]);
4020 PMD_INIT_LOG(ERR, "add mac ethertype failed, ret =%d",
4030 hns3_promisc_param_init(struct hns3_promisc_param *param, bool en_uc,
4031 bool en_mc, bool en_bc, int vport_id)
4036 memset(param, 0, sizeof(struct hns3_promisc_param));
4038 param->enable = HNS3_PROMISC_EN_UC;
4040 param->enable |= HNS3_PROMISC_EN_MC;
4042 param->enable |= HNS3_PROMISC_EN_BC;
4043 param->vf_id = vport_id;
4047 hns3_cmd_set_promisc_mode(struct hns3_hw *hw, struct hns3_promisc_param *param)
4049 struct hns3_promisc_cfg_cmd *req;
4050 struct hns3_cmd_desc desc;
4053 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_PROMISC_MODE, false);
4055 req = (struct hns3_promisc_cfg_cmd *)desc.data;
4056 req->vf_id = param->vf_id;
4057 req->flag = (param->enable << HNS3_PROMISC_EN_B) |
4058 HNS3_PROMISC_TX_EN_B | HNS3_PROMISC_RX_EN_B;
4060 ret = hns3_cmd_send(hw, &desc, 1);
4062 PMD_INIT_LOG(ERR, "Set promisc mode fail, ret = %d", ret);
4068 hns3_set_promisc_mode(struct hns3_hw *hw, bool en_uc_pmc, bool en_mc_pmc)
4070 struct hns3_promisc_param param;
4071 bool en_bc_pmc = true;
4075 * In current version VF is not supported when PF is driven by DPDK
4076 * driver, just need to configure parameters for PF vport.
4078 vf_id = HNS3_PF_FUNC_ID;
4080 hns3_promisc_param_init(¶m, en_uc_pmc, en_mc_pmc, en_bc_pmc, vf_id);
4081 return hns3_cmd_set_promisc_mode(hw, ¶m);
4085 hns3_promisc_init(struct hns3_hw *hw)
4087 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
4088 struct hns3_pf *pf = &hns->pf;
4089 struct hns3_promisc_param param;
4093 ret = hns3_set_promisc_mode(hw, false, false);
4095 PMD_INIT_LOG(ERR, "failed to set promisc mode, ret = %d", ret);
4100 * In current version VFs are not supported when PF is driven by DPDK
4101 * driver. After PF has been taken over by DPDK, the original VF will
4102 * be invalid. So, there is a possibility of entry residues. It should
4103 * clear VFs's promisc mode to avoid unnecessary bandwidth usage
4106 for (func_id = HNS3_1ST_VF_FUNC_ID; func_id < pf->func_num; func_id++) {
4107 hns3_promisc_param_init(¶m, false, false, false, func_id);
4108 ret = hns3_cmd_set_promisc_mode(hw, ¶m);
4110 PMD_INIT_LOG(ERR, "failed to clear vf:%u promisc mode,"
4111 " ret = %d", func_id, ret);
4120 hns3_promisc_uninit(struct hns3_hw *hw)
4122 struct hns3_promisc_param param;
4126 func_id = HNS3_PF_FUNC_ID;
4129 * In current version VFs are not supported when PF is driven by
4130 * DPDK driver, and VFs' promisc mode status has been cleared during
4131 * init and their status will not change. So just clear PF's promisc
4132 * mode status during uninit.
4134 hns3_promisc_param_init(¶m, false, false, false, func_id);
4135 ret = hns3_cmd_set_promisc_mode(hw, ¶m);
4137 PMD_INIT_LOG(ERR, "failed to clear promisc status during"
4138 " uninit, ret = %d", ret);
4142 hns3_dev_promiscuous_enable(struct rte_eth_dev *dev)
4144 bool allmulti = dev->data->all_multicast ? true : false;
4145 struct hns3_adapter *hns = dev->data->dev_private;
4146 struct hns3_hw *hw = &hns->hw;
4151 rte_spinlock_lock(&hw->lock);
4152 ret = hns3_set_promisc_mode(hw, true, true);
4154 rte_spinlock_unlock(&hw->lock);
4155 hns3_err(hw, "failed to enable promiscuous mode, ret = %d",
4161 * When promiscuous mode was enabled, disable the vlan filter to let
4162 * all packets coming in in the receiving direction.
4164 offloads = dev->data->dev_conf.rxmode.offloads;
4165 if (offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
4166 ret = hns3_enable_vlan_filter(hns, false);
4168 hns3_err(hw, "failed to enable promiscuous mode due to "
4169 "failure to disable vlan filter, ret = %d",
4171 err = hns3_set_promisc_mode(hw, false, allmulti);
4173 hns3_err(hw, "failed to restore promiscuous "
4174 "status after disable vlan filter "
4175 "failed during enabling promiscuous "
4176 "mode, ret = %d", ret);
4180 rte_spinlock_unlock(&hw->lock);
4186 hns3_dev_promiscuous_disable(struct rte_eth_dev *dev)
4188 bool allmulti = dev->data->all_multicast ? true : false;
4189 struct hns3_adapter *hns = dev->data->dev_private;
4190 struct hns3_hw *hw = &hns->hw;
4195 /* If now in all_multicast mode, must remain in all_multicast mode. */
4196 rte_spinlock_lock(&hw->lock);
4197 ret = hns3_set_promisc_mode(hw, false, allmulti);
4199 rte_spinlock_unlock(&hw->lock);
4200 hns3_err(hw, "failed to disable promiscuous mode, ret = %d",
4204 /* when promiscuous mode was disabled, restore the vlan filter status */
4205 offloads = dev->data->dev_conf.rxmode.offloads;
4206 if (offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
4207 ret = hns3_enable_vlan_filter(hns, true);
4209 hns3_err(hw, "failed to disable promiscuous mode due to"
4210 " failure to restore vlan filter, ret = %d",
4212 err = hns3_set_promisc_mode(hw, true, true);
4214 hns3_err(hw, "failed to restore promiscuous "
4215 "status after enabling vlan filter "
4216 "failed during disabling promiscuous "
4217 "mode, ret = %d", ret);
4220 rte_spinlock_unlock(&hw->lock);
4226 hns3_dev_allmulticast_enable(struct rte_eth_dev *dev)
4228 struct hns3_adapter *hns = dev->data->dev_private;
4229 struct hns3_hw *hw = &hns->hw;
4232 if (dev->data->promiscuous)
4235 rte_spinlock_lock(&hw->lock);
4236 ret = hns3_set_promisc_mode(hw, false, true);
4237 rte_spinlock_unlock(&hw->lock);
4239 hns3_err(hw, "failed to enable allmulticast mode, ret = %d",
4246 hns3_dev_allmulticast_disable(struct rte_eth_dev *dev)
4248 struct hns3_adapter *hns = dev->data->dev_private;
4249 struct hns3_hw *hw = &hns->hw;
4252 /* If now in promiscuous mode, must remain in all_multicast mode. */
4253 if (dev->data->promiscuous)
4256 rte_spinlock_lock(&hw->lock);
4257 ret = hns3_set_promisc_mode(hw, false, false);
4258 rte_spinlock_unlock(&hw->lock);
4260 hns3_err(hw, "failed to disable allmulticast mode, ret = %d",
4267 hns3_dev_promisc_restore(struct hns3_adapter *hns)
4269 struct hns3_hw *hw = &hns->hw;
4270 bool allmulti = hw->data->all_multicast ? true : false;
4273 if (hw->data->promiscuous) {
4274 ret = hns3_set_promisc_mode(hw, true, true);
4276 hns3_err(hw, "failed to restore promiscuous mode, "
4281 ret = hns3_set_promisc_mode(hw, false, allmulti);
4283 hns3_err(hw, "failed to restore allmulticast mode, ret = %d",
4289 hns3_get_sfp_speed(struct hns3_hw *hw, uint32_t *speed)
4291 struct hns3_sfp_speed_cmd *resp;
4292 struct hns3_cmd_desc desc;
4295 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_SFP_GET_SPEED, true);
4296 resp = (struct hns3_sfp_speed_cmd *)desc.data;
4297 ret = hns3_cmd_send(hw, &desc, 1);
4298 if (ret == -EOPNOTSUPP) {
4299 hns3_err(hw, "IMP do not support get SFP speed %d", ret);
4302 hns3_err(hw, "get sfp speed failed %d", ret);
4306 *speed = resp->sfp_speed;
4312 hns3_check_speed_dup(uint8_t duplex, uint32_t speed)
4314 if (!(speed == ETH_SPEED_NUM_10M || speed == ETH_SPEED_NUM_100M))
4315 duplex = ETH_LINK_FULL_DUPLEX;
4321 hns3_cfg_mac_speed_dup(struct hns3_hw *hw, uint32_t speed, uint8_t duplex)
4323 struct hns3_mac *mac = &hw->mac;
4324 uint32_t cur_speed = mac->link_speed;
4327 duplex = hns3_check_speed_dup(duplex, speed);
4328 if (mac->link_speed == speed && mac->link_duplex == duplex)
4331 ret = hns3_cfg_mac_speed_dup_hw(hw, speed, duplex);
4335 mac->link_speed = speed;
4336 ret = hns3_dcb_port_shaper_cfg(hw);
4338 hns3_err(hw, "failed to configure port shaper, ret = %d.", ret);
4339 mac->link_speed = cur_speed;
4343 mac->link_duplex = duplex;
4349 hns3_update_speed_duplex(struct rte_eth_dev *eth_dev)
4351 struct hns3_adapter *hns = eth_dev->data->dev_private;
4352 struct hns3_hw *hw = &hns->hw;
4353 struct hns3_pf *pf = &hns->pf;
4357 /* If IMP do not support get SFP/qSFP speed, return directly */
4358 if (!pf->support_sfp_query)
4361 ret = hns3_get_sfp_speed(hw, &speed);
4362 if (ret == -EOPNOTSUPP) {
4363 pf->support_sfp_query = false;
4368 if (speed == ETH_SPEED_NUM_NONE)
4369 return 0; /* do nothing if no SFP */
4371 /* Config full duplex for SFP */
4372 return hns3_cfg_mac_speed_dup(hw, speed, ETH_LINK_FULL_DUPLEX);
4376 hns3_cfg_mac_mode(struct hns3_hw *hw, bool enable)
4378 struct hns3_config_mac_mode_cmd *req;
4379 struct hns3_cmd_desc desc;
4380 uint32_t loop_en = 0;
4384 req = (struct hns3_config_mac_mode_cmd *)desc.data;
4386 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_MAC_MODE, false);
4389 hns3_set_bit(loop_en, HNS3_MAC_TX_EN_B, val);
4390 hns3_set_bit(loop_en, HNS3_MAC_RX_EN_B, val);
4391 hns3_set_bit(loop_en, HNS3_MAC_PAD_TX_B, val);
4392 hns3_set_bit(loop_en, HNS3_MAC_PAD_RX_B, val);
4393 hns3_set_bit(loop_en, HNS3_MAC_1588_TX_B, 0);
4394 hns3_set_bit(loop_en, HNS3_MAC_1588_RX_B, 0);
4395 hns3_set_bit(loop_en, HNS3_MAC_APP_LP_B, 0);
4396 hns3_set_bit(loop_en, HNS3_MAC_LINE_LP_B, 0);
4397 hns3_set_bit(loop_en, HNS3_MAC_FCS_TX_B, val);
4398 hns3_set_bit(loop_en, HNS3_MAC_RX_FCS_B, val);
4401 * If DEV_RX_OFFLOAD_KEEP_CRC offload is set, MAC will not strip CRC
4402 * when receiving frames. Otherwise, CRC will be stripped.
4404 if (hw->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)
4405 hns3_set_bit(loop_en, HNS3_MAC_RX_FCS_STRIP_B, 0);
4407 hns3_set_bit(loop_en, HNS3_MAC_RX_FCS_STRIP_B, val);
4408 hns3_set_bit(loop_en, HNS3_MAC_TX_OVERSIZE_TRUNCATE_B, val);
4409 hns3_set_bit(loop_en, HNS3_MAC_RX_OVERSIZE_TRUNCATE_B, val);
4410 hns3_set_bit(loop_en, HNS3_MAC_TX_UNDER_MIN_ERR_B, val);
4411 req->txrx_pad_fcs_loop_en = rte_cpu_to_le_32(loop_en);
4413 ret = hns3_cmd_send(hw, &desc, 1);
4415 PMD_INIT_LOG(ERR, "mac enable fail, ret =%d.", ret);
4421 hns3_get_mac_link_status(struct hns3_hw *hw)
4423 struct hns3_link_status_cmd *req;
4424 struct hns3_cmd_desc desc;
4428 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_LINK_STATUS, true);
4429 ret = hns3_cmd_send(hw, &desc, 1);
4431 hns3_err(hw, "get link status cmd failed %d", ret);
4432 return ETH_LINK_DOWN;
4435 req = (struct hns3_link_status_cmd *)desc.data;
4436 link_status = req->status & HNS3_LINK_STATUS_UP_M;
4438 return !!link_status;
4442 hns3_update_link_status(struct hns3_hw *hw)
4446 state = hns3_get_mac_link_status(hw);
4447 if (state != hw->mac.link_status) {
4448 hw->mac.link_status = state;
4449 hns3_warn(hw, "Link status change to %s!", state ? "up" : "down");
4454 hns3_service_handler(void *param)
4456 struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
4457 struct hns3_adapter *hns = eth_dev->data->dev_private;
4458 struct hns3_hw *hw = &hns->hw;
4460 if (!hns3_is_reset_pending(hns)) {
4461 hns3_update_speed_duplex(eth_dev);
4462 hns3_update_link_status(hw);
4464 hns3_warn(hw, "Cancel the query when reset is pending");
4466 rte_eal_alarm_set(HNS3_SERVICE_INTERVAL, hns3_service_handler, eth_dev);
4470 hns3_init_hardware(struct hns3_adapter *hns)
4472 struct hns3_hw *hw = &hns->hw;
4475 ret = hns3_map_tqp(hw);
4477 PMD_INIT_LOG(ERR, "Failed to map tqp: %d", ret);
4481 ret = hns3_init_umv_space(hw);
4483 PMD_INIT_LOG(ERR, "Failed to init umv space: %d", ret);
4487 ret = hns3_mac_init(hw);
4489 PMD_INIT_LOG(ERR, "Failed to init MAC: %d", ret);
4493 ret = hns3_init_mgr_tbl(hw);
4495 PMD_INIT_LOG(ERR, "Failed to init manager table: %d", ret);
4499 ret = hns3_promisc_init(hw);
4501 PMD_INIT_LOG(ERR, "Failed to init promisc: %d",
4506 ret = hns3_init_vlan_config(hns);
4508 PMD_INIT_LOG(ERR, "Failed to init vlan: %d", ret);
4512 ret = hns3_dcb_init(hw);
4514 PMD_INIT_LOG(ERR, "Failed to init dcb: %d", ret);
4518 ret = hns3_init_fd_config(hns);
4520 PMD_INIT_LOG(ERR, "Failed to init flow director: %d", ret);
4524 ret = hns3_config_tso(hw, HNS3_TSO_MSS_MIN, HNS3_TSO_MSS_MAX);
4526 PMD_INIT_LOG(ERR, "Failed to config tso: %d", ret);
4530 ret = hns3_config_gro(hw, false);
4532 PMD_INIT_LOG(ERR, "Failed to config gro: %d", ret);
4537 * In the initialization clearing the all hardware mapping relationship
4538 * configurations between queues and interrupt vectors is needed, so
4539 * some error caused by the residual configurations, such as the
4540 * unexpected interrupt, can be avoid.
4542 ret = hns3_init_ring_with_vector(hw);
4544 PMD_INIT_LOG(ERR, "Failed to init ring intr vector: %d", ret);
4551 hns3_uninit_umv_space(hw);
4556 hns3_clear_hw(struct hns3_hw *hw)
4558 struct hns3_cmd_desc desc;
4561 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CLEAR_HW_STATE, false);
4563 ret = hns3_cmd_send(hw, &desc, 1);
4564 if (ret && ret != -EOPNOTSUPP)
4571 hns3_config_all_msix_error(struct hns3_hw *hw, bool enable)
4576 * The new firmware support report more hardware error types by
4577 * msix mode. These errors are defined as RAS errors in hardware
4578 * and belong to a different type from the MSI-x errors processed
4579 * by the network driver.
4581 * Network driver should open the new error report on initialition
4583 val = hns3_read_dev(hw, HNS3_VECTOR0_OTER_EN_REG);
4584 hns3_set_bit(val, HNS3_VECTOR0_ALL_MSIX_ERR_B, enable ? 1 : 0);
4585 hns3_write_dev(hw, HNS3_VECTOR0_OTER_EN_REG, val);
4589 hns3_init_pf(struct rte_eth_dev *eth_dev)
4591 struct rte_device *dev = eth_dev->device;
4592 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
4593 struct hns3_adapter *hns = eth_dev->data->dev_private;
4594 struct hns3_hw *hw = &hns->hw;
4597 PMD_INIT_FUNC_TRACE();
4599 /* Get hardware io base address from pcie BAR2 IO space */
4600 hw->io_base = pci_dev->mem_resource[2].addr;
4602 /* Firmware command queue initialize */
4603 ret = hns3_cmd_init_queue(hw);
4605 PMD_INIT_LOG(ERR, "Failed to init cmd queue: %d", ret);
4606 goto err_cmd_init_queue;
4609 hns3_clear_all_event_cause(hw);
4611 /* Firmware command initialize */
4612 ret = hns3_cmd_init(hw);
4614 PMD_INIT_LOG(ERR, "Failed to init cmd: %d", ret);
4619 * To ensure that the hardware environment is clean during
4620 * initialization, the driver actively clear the hardware environment
4621 * during initialization, including PF and corresponding VFs' vlan, mac,
4622 * flow table configurations, etc.
4624 ret = hns3_clear_hw(hw);
4626 PMD_INIT_LOG(ERR, "failed to clear hardware: %d", ret);
4630 hns3_config_all_msix_error(hw, true);
4632 ret = rte_intr_callback_register(&pci_dev->intr_handle,
4633 hns3_interrupt_handler,
4636 PMD_INIT_LOG(ERR, "Failed to register intr: %d", ret);
4637 goto err_intr_callback_register;
4640 /* Enable interrupt */
4641 rte_intr_enable(&pci_dev->intr_handle);
4642 hns3_pf_enable_irq0(hw);
4644 /* Get configuration */
4645 ret = hns3_get_configuration(hw);
4647 PMD_INIT_LOG(ERR, "Failed to fetch configuration: %d", ret);
4648 goto err_get_config;
4651 ret = hns3_tqp_stats_init(hw);
4653 goto err_get_config;
4655 ret = hns3_init_hardware(hns);
4657 PMD_INIT_LOG(ERR, "Failed to init hardware: %d", ret);
4661 /* Initialize flow director filter list & hash */
4662 ret = hns3_fdir_filter_init(hns);
4664 PMD_INIT_LOG(ERR, "Failed to alloc hashmap for fdir: %d", ret);
4668 hns3_set_default_rss_args(hw);
4670 ret = hns3_enable_hw_error_intr(hns, true);
4672 PMD_INIT_LOG(ERR, "fail to enable hw error interrupts: %d",
4674 goto err_enable_intr;
4680 hns3_fdir_filter_uninit(hns);
4682 hns3_uninit_umv_space(hw);
4684 hns3_tqp_stats_uninit(hw);
4686 hns3_pf_disable_irq0(hw);
4687 rte_intr_disable(&pci_dev->intr_handle);
4688 hns3_intr_unregister(&pci_dev->intr_handle, hns3_interrupt_handler,
4690 err_intr_callback_register:
4692 hns3_cmd_uninit(hw);
4693 hns3_cmd_destroy_queue(hw);
4701 hns3_uninit_pf(struct rte_eth_dev *eth_dev)
4703 struct hns3_adapter *hns = eth_dev->data->dev_private;
4704 struct rte_device *dev = eth_dev->device;
4705 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
4706 struct hns3_hw *hw = &hns->hw;
4708 PMD_INIT_FUNC_TRACE();
4710 hns3_enable_hw_error_intr(hns, false);
4711 hns3_rss_uninit(hns);
4712 (void)hns3_config_gro(hw, false);
4713 hns3_promisc_uninit(hw);
4714 hns3_fdir_filter_uninit(hns);
4715 hns3_uninit_umv_space(hw);
4716 hns3_tqp_stats_uninit(hw);
4717 hns3_pf_disable_irq0(hw);
4718 rte_intr_disable(&pci_dev->intr_handle);
4719 hns3_intr_unregister(&pci_dev->intr_handle, hns3_interrupt_handler,
4721 hns3_config_all_msix_error(hw, false);
4722 hns3_cmd_uninit(hw);
4723 hns3_cmd_destroy_queue(hw);
4728 hns3_do_start(struct hns3_adapter *hns, bool reset_queue)
4730 struct hns3_hw *hw = &hns->hw;
4733 ret = hns3_dcb_cfg_update(hns);
4737 ret = hns3_init_queues(hns, reset_queue);
4739 PMD_INIT_LOG(ERR, "failed to init queues, ret = %d.", ret);
4743 ret = hns3_cfg_mac_mode(hw, true);
4745 PMD_INIT_LOG(ERR, "failed to enable MAC, ret = %d", ret);
4746 goto err_config_mac_mode;
4750 err_config_mac_mode:
4751 hns3_dev_release_mbufs(hns);
4753 * Here is exception handling, hns3_reset_all_tqps will have the
4754 * corresponding error message if it is handled incorrectly, so it is
4755 * not necessary to check hns3_reset_all_tqps return value, here keep
4756 * ret as the error code causing the exception.
4758 (void)hns3_reset_all_tqps(hns);
4763 hns3_map_rx_interrupt(struct rte_eth_dev *dev)
4765 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4766 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4767 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4768 uint8_t base = RTE_INTR_VEC_ZERO_OFFSET;
4769 uint8_t vec = RTE_INTR_VEC_ZERO_OFFSET;
4770 uint32_t intr_vector;
4774 if (dev->data->dev_conf.intr_conf.rxq == 0)
4777 /* disable uio/vfio intr/eventfd mapping */
4778 rte_intr_disable(intr_handle);
4780 /* check and configure queue intr-vector mapping */
4781 if (rte_intr_cap_multiple(intr_handle) ||
4782 !RTE_ETH_DEV_SRIOV(dev).active) {
4783 intr_vector = hw->used_rx_queues;
4784 /* creates event fd for each intr vector when MSIX is used */
4785 if (rte_intr_efd_enable(intr_handle, intr_vector))
4788 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
4789 intr_handle->intr_vec =
4790 rte_zmalloc("intr_vec",
4791 hw->used_rx_queues * sizeof(int), 0);
4792 if (intr_handle->intr_vec == NULL) {
4793 hns3_err(hw, "Failed to allocate %u rx_queues"
4794 " intr_vec", hw->used_rx_queues);
4796 goto alloc_intr_vec_error;
4800 if (rte_intr_allow_others(intr_handle)) {
4801 vec = RTE_INTR_VEC_RXTX_OFFSET;
4802 base = RTE_INTR_VEC_RXTX_OFFSET;
4804 if (rte_intr_dp_is_en(intr_handle)) {
4805 for (q_id = 0; q_id < hw->used_rx_queues; q_id++) {
4806 ret = hns3_bind_ring_with_vector(hw, vec, true,
4810 goto bind_vector_error;
4811 intr_handle->intr_vec[q_id] = vec;
4812 if (vec < base + intr_handle->nb_efd - 1)
4816 rte_intr_enable(intr_handle);
4820 rte_intr_efd_disable(intr_handle);
4821 if (intr_handle->intr_vec) {
4822 free(intr_handle->intr_vec);
4823 intr_handle->intr_vec = NULL;
4826 alloc_intr_vec_error:
4827 rte_intr_efd_disable(intr_handle);
4832 hns3_restore_rx_interrupt(struct hns3_hw *hw)
4834 struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id];
4835 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4836 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4840 if (dev->data->dev_conf.intr_conf.rxq == 0)
4843 if (rte_intr_dp_is_en(intr_handle)) {
4844 for (q_id = 0; q_id < hw->used_rx_queues; q_id++) {
4845 ret = hns3_bind_ring_with_vector(hw,
4846 intr_handle->intr_vec[q_id], true,
4847 HNS3_RING_TYPE_RX, q_id);
4857 hns3_restore_filter(struct rte_eth_dev *dev)
4859 hns3_restore_rss_filter(dev);
4863 hns3_dev_start(struct rte_eth_dev *dev)
4865 struct hns3_adapter *hns = dev->data->dev_private;
4866 struct hns3_hw *hw = &hns->hw;
4869 PMD_INIT_FUNC_TRACE();
4870 if (rte_atomic16_read(&hw->reset.resetting))
4873 rte_spinlock_lock(&hw->lock);
4874 hw->adapter_state = HNS3_NIC_STARTING;
4876 ret = hns3_do_start(hns, true);
4878 hw->adapter_state = HNS3_NIC_CONFIGURED;
4879 rte_spinlock_unlock(&hw->lock);
4882 ret = hns3_map_rx_interrupt(dev);
4884 hw->adapter_state = HNS3_NIC_CONFIGURED;
4885 rte_spinlock_unlock(&hw->lock);
4890 * There are three register used to control the status of a TQP
4891 * (contains a pair of Tx queue and Rx queue) in the new version network
4892 * engine. One is used to control the enabling of Tx queue, the other is
4893 * used to control the enabling of Rx queue, and the last is the master
4894 * switch used to control the enabling of the tqp. The Tx register and
4895 * TQP register must be enabled at the same time to enable a Tx queue.
4896 * The same applies to the Rx queue. For the older network engine, this
4897 * function only refresh the enabled flag, and it is used to update the
4898 * status of queue in the dpdk framework.
4900 ret = hns3_start_all_txqs(dev);
4902 hw->adapter_state = HNS3_NIC_CONFIGURED;
4903 rte_spinlock_unlock(&hw->lock);
4907 ret = hns3_start_all_rxqs(dev);
4909 hns3_stop_all_txqs(dev);
4910 hw->adapter_state = HNS3_NIC_CONFIGURED;
4911 rte_spinlock_unlock(&hw->lock);
4915 hw->adapter_state = HNS3_NIC_STARTED;
4916 rte_spinlock_unlock(&hw->lock);
4918 hns3_rx_scattered_calc(dev);
4919 hns3_set_rxtx_function(dev);
4920 hns3_mp_req_start_rxtx(dev);
4921 rte_eal_alarm_set(HNS3_SERVICE_INTERVAL, hns3_service_handler, dev);
4923 hns3_restore_filter(dev);
4925 /* Enable interrupt of all rx queues before enabling queues */
4926 hns3_dev_all_rx_queue_intr_enable(hw, true);
4929 * After finished the initialization, enable tqps to receive/transmit
4930 * packets and refresh all queue status.
4932 hns3_start_tqps(hw);
4934 hns3_info(hw, "hns3 dev start successful!");
4939 hns3_do_stop(struct hns3_adapter *hns)
4941 struct hns3_hw *hw = &hns->hw;
4944 ret = hns3_cfg_mac_mode(hw, false);
4947 hw->mac.link_status = ETH_LINK_DOWN;
4949 if (rte_atomic16_read(&hw->reset.disable_cmd) == 0) {
4950 hns3_configure_all_mac_addr(hns, true);
4951 ret = hns3_reset_all_tqps(hns);
4953 hns3_err(hw, "failed to reset all queues ret = %d.",
4958 hw->mac.default_addr_setted = false;
4963 hns3_unmap_rx_interrupt(struct rte_eth_dev *dev)
4965 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4966 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4967 struct hns3_adapter *hns = dev->data->dev_private;
4968 struct hns3_hw *hw = &hns->hw;
4969 uint8_t base = RTE_INTR_VEC_ZERO_OFFSET;
4970 uint8_t vec = RTE_INTR_VEC_ZERO_OFFSET;
4973 if (dev->data->dev_conf.intr_conf.rxq == 0)
4976 /* unmap the ring with vector */
4977 if (rte_intr_allow_others(intr_handle)) {
4978 vec = RTE_INTR_VEC_RXTX_OFFSET;
4979 base = RTE_INTR_VEC_RXTX_OFFSET;
4981 if (rte_intr_dp_is_en(intr_handle)) {
4982 for (q_id = 0; q_id < hw->used_rx_queues; q_id++) {
4983 (void)hns3_bind_ring_with_vector(hw, vec, false,
4986 if (vec < base + intr_handle->nb_efd - 1)
4990 /* Clean datapath event and queue/vec mapping */
4991 rte_intr_efd_disable(intr_handle);
4992 if (intr_handle->intr_vec) {
4993 rte_free(intr_handle->intr_vec);
4994 intr_handle->intr_vec = NULL;
4999 hns3_dev_stop(struct rte_eth_dev *dev)
5001 struct hns3_adapter *hns = dev->data->dev_private;
5002 struct hns3_hw *hw = &hns->hw;
5004 PMD_INIT_FUNC_TRACE();
5005 dev->data->dev_started = 0;
5007 hw->adapter_state = HNS3_NIC_STOPPING;
5008 hns3_set_rxtx_function(dev);
5010 /* Disable datapath on secondary process. */
5011 hns3_mp_req_stop_rxtx(dev);
5012 /* Prevent crashes when queues are still in use. */
5013 rte_delay_ms(hw->tqps_num);
5015 rte_spinlock_lock(&hw->lock);
5016 if (rte_atomic16_read(&hw->reset.resetting) == 0) {
5019 hns3_unmap_rx_interrupt(dev);
5020 hns3_dev_release_mbufs(hns);
5021 hw->adapter_state = HNS3_NIC_CONFIGURED;
5023 hns3_rx_scattered_reset(dev);
5024 rte_eal_alarm_cancel(hns3_service_handler, dev);
5025 rte_spinlock_unlock(&hw->lock);
5031 hns3_dev_close(struct rte_eth_dev *eth_dev)
5033 struct hns3_adapter *hns = eth_dev->data->dev_private;
5034 struct hns3_hw *hw = &hns->hw;
5037 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
5038 rte_free(eth_dev->process_private);
5039 eth_dev->process_private = NULL;
5043 if (hw->adapter_state == HNS3_NIC_STARTED)
5044 ret = hns3_dev_stop(eth_dev);
5046 hw->adapter_state = HNS3_NIC_CLOSING;
5047 hns3_reset_abort(hns);
5048 hw->adapter_state = HNS3_NIC_CLOSED;
5050 hns3_configure_all_mc_mac_addr(hns, true);
5051 hns3_remove_all_vlan_table(hns);
5052 hns3_vlan_txvlan_cfg(hns, HNS3_PORT_BASE_VLAN_DISABLE, 0);
5053 hns3_uninit_pf(eth_dev);
5054 hns3_free_all_queues(eth_dev);
5055 rte_free(hw->reset.wait_data);
5056 rte_free(eth_dev->process_private);
5057 eth_dev->process_private = NULL;
5058 hns3_mp_uninit_primary();
5059 hns3_warn(hw, "Close port %u finished", hw->data->port_id);
5065 hns3_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
5067 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5068 struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5070 fc_conf->pause_time = pf->pause_time;
5072 /* return fc current mode */
5073 switch (hw->current_mode) {
5075 fc_conf->mode = RTE_FC_FULL;
5077 case HNS3_FC_TX_PAUSE:
5078 fc_conf->mode = RTE_FC_TX_PAUSE;
5080 case HNS3_FC_RX_PAUSE:
5081 fc_conf->mode = RTE_FC_RX_PAUSE;
5085 fc_conf->mode = RTE_FC_NONE;
5093 hns3_get_fc_mode(struct hns3_hw *hw, enum rte_eth_fc_mode mode)
5097 hw->requested_mode = HNS3_FC_NONE;
5099 case RTE_FC_RX_PAUSE:
5100 hw->requested_mode = HNS3_FC_RX_PAUSE;
5102 case RTE_FC_TX_PAUSE:
5103 hw->requested_mode = HNS3_FC_TX_PAUSE;
5106 hw->requested_mode = HNS3_FC_FULL;
5109 hw->requested_mode = HNS3_FC_NONE;
5110 hns3_warn(hw, "fc_mode(%u) exceeds member scope and is "
5111 "configured to RTE_FC_NONE", mode);
5117 hns3_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
5119 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5120 struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5123 if (fc_conf->high_water || fc_conf->low_water ||
5124 fc_conf->send_xon || fc_conf->mac_ctrl_frame_fwd) {
5125 hns3_err(hw, "Unsupported flow control settings specified, "
5126 "high_water(%u), low_water(%u), send_xon(%u) and "
5127 "mac_ctrl_frame_fwd(%u) must be set to '0'",
5128 fc_conf->high_water, fc_conf->low_water,
5129 fc_conf->send_xon, fc_conf->mac_ctrl_frame_fwd);
5132 if (fc_conf->autoneg) {
5133 hns3_err(hw, "Unsupported fc auto-negotiation setting.");
5136 if (!fc_conf->pause_time) {
5137 hns3_err(hw, "Invalid pause time %u setting.",
5138 fc_conf->pause_time);
5142 if (!(hw->current_fc_status == HNS3_FC_STATUS_NONE ||
5143 hw->current_fc_status == HNS3_FC_STATUS_MAC_PAUSE)) {
5144 hns3_err(hw, "PFC is enabled. Cannot set MAC pause. "
5145 "current_fc_status = %d", hw->current_fc_status);
5149 hns3_get_fc_mode(hw, fc_conf->mode);
5150 if (hw->requested_mode == hw->current_mode &&
5151 pf->pause_time == fc_conf->pause_time)
5154 rte_spinlock_lock(&hw->lock);
5155 ret = hns3_fc_enable(dev, fc_conf);
5156 rte_spinlock_unlock(&hw->lock);
5162 hns3_priority_flow_ctrl_set(struct rte_eth_dev *dev,
5163 struct rte_eth_pfc_conf *pfc_conf)
5165 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5166 struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5170 if (!hns3_dev_dcb_supported(hw)) {
5171 hns3_err(hw, "This port does not support dcb configurations.");
5175 if (pfc_conf->fc.high_water || pfc_conf->fc.low_water ||
5176 pfc_conf->fc.send_xon || pfc_conf->fc.mac_ctrl_frame_fwd) {
5177 hns3_err(hw, "Unsupported flow control settings specified, "
5178 "high_water(%u), low_water(%u), send_xon(%u) and "
5179 "mac_ctrl_frame_fwd(%u) must be set to '0'",
5180 pfc_conf->fc.high_water, pfc_conf->fc.low_water,
5181 pfc_conf->fc.send_xon,
5182 pfc_conf->fc.mac_ctrl_frame_fwd);
5185 if (pfc_conf->fc.autoneg) {
5186 hns3_err(hw, "Unsupported fc auto-negotiation setting.");
5189 if (pfc_conf->fc.pause_time == 0) {
5190 hns3_err(hw, "Invalid pause time %u setting.",
5191 pfc_conf->fc.pause_time);
5195 if (!(hw->current_fc_status == HNS3_FC_STATUS_NONE ||
5196 hw->current_fc_status == HNS3_FC_STATUS_PFC)) {
5197 hns3_err(hw, "MAC pause is enabled. Cannot set PFC."
5198 "current_fc_status = %d", hw->current_fc_status);
5202 priority = pfc_conf->priority;
5203 hns3_get_fc_mode(hw, pfc_conf->fc.mode);
5204 if (hw->dcb_info.pfc_en & BIT(priority) &&
5205 hw->requested_mode == hw->current_mode &&
5206 pfc_conf->fc.pause_time == pf->pause_time)
5209 rte_spinlock_lock(&hw->lock);
5210 ret = hns3_dcb_pfc_enable(dev, pfc_conf);
5211 rte_spinlock_unlock(&hw->lock);
5217 hns3_get_dcb_info(struct rte_eth_dev *dev, struct rte_eth_dcb_info *dcb_info)
5219 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5220 struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5221 enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
5224 rte_spinlock_lock(&hw->lock);
5225 if ((uint32_t)mq_mode & ETH_MQ_RX_DCB_FLAG)
5226 dcb_info->nb_tcs = pf->local_max_tc;
5228 dcb_info->nb_tcs = 1;
5230 for (i = 0; i < HNS3_MAX_USER_PRIO; i++)
5231 dcb_info->prio_tc[i] = hw->dcb_info.prio_tc[i];
5232 for (i = 0; i < dcb_info->nb_tcs; i++)
5233 dcb_info->tc_bws[i] = hw->dcb_info.pg_info[0].tc_dwrr[i];
5235 for (i = 0; i < hw->num_tc; i++) {
5236 dcb_info->tc_queue.tc_rxq[0][i].base = hw->alloc_rss_size * i;
5237 dcb_info->tc_queue.tc_txq[0][i].base =
5238 hw->tc_queue[i].tqp_offset;
5239 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = hw->alloc_rss_size;
5240 dcb_info->tc_queue.tc_txq[0][i].nb_queue =
5241 hw->tc_queue[i].tqp_count;
5243 rte_spinlock_unlock(&hw->lock);
5249 hns3_reinit_dev(struct hns3_adapter *hns)
5251 struct hns3_hw *hw = &hns->hw;
5254 ret = hns3_cmd_init(hw);
5256 hns3_err(hw, "Failed to init cmd: %d", ret);
5260 ret = hns3_reset_all_tqps(hns);
5262 hns3_err(hw, "Failed to reset all queues: %d", ret);
5266 ret = hns3_init_hardware(hns);
5268 hns3_err(hw, "Failed to init hardware: %d", ret);
5272 ret = hns3_enable_hw_error_intr(hns, true);
5274 hns3_err(hw, "fail to enable hw error interrupts: %d",
5278 hns3_info(hw, "Reset done, driver initialization finished.");
5284 is_pf_reset_done(struct hns3_hw *hw)
5286 uint32_t val, reg, reg_bit;
5288 switch (hw->reset.level) {
5289 case HNS3_IMP_RESET:
5290 reg = HNS3_GLOBAL_RESET_REG;
5291 reg_bit = HNS3_IMP_RESET_BIT;
5293 case HNS3_GLOBAL_RESET:
5294 reg = HNS3_GLOBAL_RESET_REG;
5295 reg_bit = HNS3_GLOBAL_RESET_BIT;
5297 case HNS3_FUNC_RESET:
5298 reg = HNS3_FUN_RST_ING;
5299 reg_bit = HNS3_FUN_RST_ING_B;
5301 case HNS3_FLR_RESET:
5303 hns3_err(hw, "Wait for unsupported reset level: %d",
5307 val = hns3_read_dev(hw, reg);
5308 if (hns3_get_bit(val, reg_bit))
5315 hns3_is_reset_pending(struct hns3_adapter *hns)
5317 struct hns3_hw *hw = &hns->hw;
5318 enum hns3_reset_level reset;
5320 hns3_check_event_cause(hns, NULL);
5321 reset = hns3_get_reset_level(hns, &hw->reset.pending);
5322 if (hw->reset.level != HNS3_NONE_RESET && hw->reset.level < reset) {
5323 hns3_warn(hw, "High level reset %d is pending", reset);
5326 reset = hns3_get_reset_level(hns, &hw->reset.request);
5327 if (hw->reset.level != HNS3_NONE_RESET && hw->reset.level < reset) {
5328 hns3_warn(hw, "High level reset %d is request", reset);
5335 hns3_wait_hardware_ready(struct hns3_adapter *hns)
5337 struct hns3_hw *hw = &hns->hw;
5338 struct hns3_wait_data *wait_data = hw->reset.wait_data;
5341 if (wait_data->result == HNS3_WAIT_SUCCESS)
5343 else if (wait_data->result == HNS3_WAIT_TIMEOUT) {
5344 gettimeofday(&tv, NULL);
5345 hns3_warn(hw, "Reset step4 hardware not ready after reset time=%ld.%.6ld",
5346 tv.tv_sec, tv.tv_usec);
5348 } else if (wait_data->result == HNS3_WAIT_REQUEST)
5351 wait_data->hns = hns;
5352 wait_data->check_completion = is_pf_reset_done;
5353 wait_data->end_ms = (uint64_t)HNS3_RESET_WAIT_CNT *
5354 HNS3_RESET_WAIT_MS + get_timeofday_ms();
5355 wait_data->interval = HNS3_RESET_WAIT_MS * USEC_PER_MSEC;
5356 wait_data->count = HNS3_RESET_WAIT_CNT;
5357 wait_data->result = HNS3_WAIT_REQUEST;
5358 rte_eal_alarm_set(wait_data->interval, hns3_wait_callback, wait_data);
5363 hns3_func_reset_cmd(struct hns3_hw *hw, int func_id)
5365 struct hns3_cmd_desc desc;
5366 struct hns3_reset_cmd *req = (struct hns3_reset_cmd *)desc.data;
5368 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_RST_TRIGGER, false);
5369 hns3_set_bit(req->mac_func_reset, HNS3_CFG_RESET_FUNC_B, 1);
5370 req->fun_reset_vfid = func_id;
5372 return hns3_cmd_send(hw, &desc, 1);
5376 hns3_imp_reset_cmd(struct hns3_hw *hw)
5378 struct hns3_cmd_desc desc;
5380 hns3_cmd_setup_basic_desc(&desc, 0xFFFE, false);
5381 desc.data[0] = 0xeedd;
5383 return hns3_cmd_send(hw, &desc, 1);
5387 hns3_msix_process(struct hns3_adapter *hns, enum hns3_reset_level reset_level)
5389 struct hns3_hw *hw = &hns->hw;
5393 gettimeofday(&tv, NULL);
5394 if (hns3_read_dev(hw, HNS3_GLOBAL_RESET_REG) ||
5395 hns3_read_dev(hw, HNS3_FUN_RST_ING)) {
5396 hns3_warn(hw, "Don't process msix during resetting time=%ld.%.6ld",
5397 tv.tv_sec, tv.tv_usec);
5401 switch (reset_level) {
5402 case HNS3_IMP_RESET:
5403 hns3_imp_reset_cmd(hw);
5404 hns3_warn(hw, "IMP Reset requested time=%ld.%.6ld",
5405 tv.tv_sec, tv.tv_usec);
5407 case HNS3_GLOBAL_RESET:
5408 val = hns3_read_dev(hw, HNS3_GLOBAL_RESET_REG);
5409 hns3_set_bit(val, HNS3_GLOBAL_RESET_BIT, 1);
5410 hns3_write_dev(hw, HNS3_GLOBAL_RESET_REG, val);
5411 hns3_warn(hw, "Global Reset requested time=%ld.%.6ld",
5412 tv.tv_sec, tv.tv_usec);
5414 case HNS3_FUNC_RESET:
5415 hns3_warn(hw, "PF Reset requested time=%ld.%.6ld",
5416 tv.tv_sec, tv.tv_usec);
5417 /* schedule again to check later */
5418 hns3_atomic_set_bit(HNS3_FUNC_RESET, &hw->reset.pending);
5419 hns3_schedule_reset(hns);
5422 hns3_warn(hw, "Unsupported reset level: %d", reset_level);
5425 hns3_atomic_clear_bit(reset_level, &hw->reset.request);
5428 static enum hns3_reset_level
5429 hns3_get_reset_level(struct hns3_adapter *hns, uint64_t *levels)
5431 struct hns3_hw *hw = &hns->hw;
5432 enum hns3_reset_level reset_level = HNS3_NONE_RESET;
5434 /* Return the highest priority reset level amongst all */
5435 if (hns3_atomic_test_bit(HNS3_IMP_RESET, levels))
5436 reset_level = HNS3_IMP_RESET;
5437 else if (hns3_atomic_test_bit(HNS3_GLOBAL_RESET, levels))
5438 reset_level = HNS3_GLOBAL_RESET;
5439 else if (hns3_atomic_test_bit(HNS3_FUNC_RESET, levels))
5440 reset_level = HNS3_FUNC_RESET;
5441 else if (hns3_atomic_test_bit(HNS3_FLR_RESET, levels))
5442 reset_level = HNS3_FLR_RESET;
5444 if (hw->reset.level != HNS3_NONE_RESET && reset_level < hw->reset.level)
5445 return HNS3_NONE_RESET;
5451 hns3_record_imp_error(struct hns3_adapter *hns)
5453 struct hns3_hw *hw = &hns->hw;
5456 reg_val = hns3_read_dev(hw, HNS3_VECTOR0_OTER_EN_REG);
5457 if (hns3_get_bit(reg_val, HNS3_VECTOR0_IMP_RD_POISON_B)) {
5458 hns3_warn(hw, "Detected IMP RD poison!");
5459 hns3_error_int_stats_add(hns, "IMP_RD_POISON_INT_STS");
5460 hns3_set_bit(reg_val, HNS3_VECTOR0_IMP_RD_POISON_B, 0);
5461 hns3_write_dev(hw, HNS3_VECTOR0_OTER_EN_REG, reg_val);
5464 if (hns3_get_bit(reg_val, HNS3_VECTOR0_IMP_CMDQ_ERR_B)) {
5465 hns3_warn(hw, "Detected IMP CMDQ error!");
5466 hns3_error_int_stats_add(hns, "CMDQ_MEM_ECC_INT_STS");
5467 hns3_set_bit(reg_val, HNS3_VECTOR0_IMP_CMDQ_ERR_B, 0);
5468 hns3_write_dev(hw, HNS3_VECTOR0_OTER_EN_REG, reg_val);
5473 hns3_prepare_reset(struct hns3_adapter *hns)
5475 struct hns3_hw *hw = &hns->hw;
5479 switch (hw->reset.level) {
5480 case HNS3_FUNC_RESET:
5481 ret = hns3_func_reset_cmd(hw, HNS3_PF_FUNC_ID);
5486 * After performaning pf reset, it is not necessary to do the
5487 * mailbox handling or send any command to firmware, because
5488 * any mailbox handling or command to firmware is only valid
5489 * after hns3_cmd_init is called.
5491 rte_atomic16_set(&hw->reset.disable_cmd, 1);
5492 hw->reset.stats.request_cnt++;
5494 case HNS3_IMP_RESET:
5495 hns3_record_imp_error(hns);
5496 reg_val = hns3_read_dev(hw, HNS3_VECTOR0_OTER_EN_REG);
5497 hns3_write_dev(hw, HNS3_VECTOR0_OTER_EN_REG, reg_val |
5498 BIT(HNS3_VECTOR0_IMP_RESET_INT_B));
5507 hns3_set_rst_done(struct hns3_hw *hw)
5509 struct hns3_pf_rst_done_cmd *req;
5510 struct hns3_cmd_desc desc;
5512 req = (struct hns3_pf_rst_done_cmd *)desc.data;
5513 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_PF_RST_DONE, false);
5514 req->pf_rst_done |= HNS3_PF_RESET_DONE_BIT;
5515 return hns3_cmd_send(hw, &desc, 1);
5519 hns3_stop_service(struct hns3_adapter *hns)
5521 struct hns3_hw *hw = &hns->hw;
5522 struct rte_eth_dev *eth_dev;
5524 eth_dev = &rte_eth_devices[hw->data->port_id];
5525 if (hw->adapter_state == HNS3_NIC_STARTED)
5526 rte_eal_alarm_cancel(hns3_service_handler, eth_dev);
5527 hw->mac.link_status = ETH_LINK_DOWN;
5529 hns3_set_rxtx_function(eth_dev);
5531 /* Disable datapath on secondary process. */
5532 hns3_mp_req_stop_rxtx(eth_dev);
5533 rte_delay_ms(hw->tqps_num);
5535 rte_spinlock_lock(&hw->lock);
5536 if (hns->hw.adapter_state == HNS3_NIC_STARTED ||
5537 hw->adapter_state == HNS3_NIC_STOPPING) {
5538 hns3_enable_all_queues(hw, false);
5540 hw->reset.mbuf_deferred_free = true;
5542 hw->reset.mbuf_deferred_free = false;
5545 * It is cumbersome for hardware to pick-and-choose entries for deletion
5546 * from table space. Hence, for function reset software intervention is
5547 * required to delete the entries
5549 if (rte_atomic16_read(&hw->reset.disable_cmd) == 0)
5550 hns3_configure_all_mc_mac_addr(hns, true);
5551 rte_spinlock_unlock(&hw->lock);
5557 hns3_start_service(struct hns3_adapter *hns)
5559 struct hns3_hw *hw = &hns->hw;
5560 struct rte_eth_dev *eth_dev;
5562 if (hw->reset.level == HNS3_IMP_RESET ||
5563 hw->reset.level == HNS3_GLOBAL_RESET)
5564 hns3_set_rst_done(hw);
5565 eth_dev = &rte_eth_devices[hw->data->port_id];
5566 hns3_set_rxtx_function(eth_dev);
5567 hns3_mp_req_start_rxtx(eth_dev);
5568 if (hw->adapter_state == HNS3_NIC_STARTED) {
5569 hns3_service_handler(eth_dev);
5571 /* Enable interrupt of all rx queues before enabling queues */
5572 hns3_dev_all_rx_queue_intr_enable(hw, true);
5574 * When finished the initialization, enable queues to receive
5575 * and transmit packets.
5577 hns3_enable_all_queues(hw, true);
5584 hns3_restore_conf(struct hns3_adapter *hns)
5586 struct hns3_hw *hw = &hns->hw;
5589 ret = hns3_configure_all_mac_addr(hns, false);
5593 ret = hns3_configure_all_mc_mac_addr(hns, false);
5597 ret = hns3_dev_promisc_restore(hns);
5601 ret = hns3_restore_vlan_table(hns);
5605 ret = hns3_restore_vlan_conf(hns);
5609 ret = hns3_restore_all_fdir_filter(hns);
5613 ret = hns3_restore_rx_interrupt(hw);
5617 ret = hns3_restore_gro_conf(hw);
5621 ret = hns3_restore_fec(hw);
5625 if (hns->hw.adapter_state == HNS3_NIC_STARTED) {
5626 ret = hns3_do_start(hns, false);
5629 hns3_info(hw, "hns3 dev restart successful!");
5630 } else if (hw->adapter_state == HNS3_NIC_STOPPING)
5631 hw->adapter_state = HNS3_NIC_CONFIGURED;
5635 hns3_configure_all_mc_mac_addr(hns, true);
5637 hns3_configure_all_mac_addr(hns, true);
5642 hns3_reset_service(void *param)
5644 struct hns3_adapter *hns = (struct hns3_adapter *)param;
5645 struct hns3_hw *hw = &hns->hw;
5646 enum hns3_reset_level reset_level;
5647 struct timeval tv_delta;
5648 struct timeval tv_start;
5654 * The interrupt is not triggered within the delay time.
5655 * The interrupt may have been lost. It is necessary to handle
5656 * the interrupt to recover from the error.
5658 if (rte_atomic16_read(&hns->hw.reset.schedule) == SCHEDULE_DEFERRED) {
5659 rte_atomic16_set(&hns->hw.reset.schedule, SCHEDULE_REQUESTED);
5660 hns3_err(hw, "Handling interrupts in delayed tasks");
5661 hns3_interrupt_handler(&rte_eth_devices[hw->data->port_id]);
5662 reset_level = hns3_get_reset_level(hns, &hw->reset.pending);
5663 if (reset_level == HNS3_NONE_RESET) {
5664 hns3_err(hw, "No reset level is set, try IMP reset");
5665 hns3_atomic_set_bit(HNS3_IMP_RESET, &hw->reset.pending);
5668 rte_atomic16_set(&hns->hw.reset.schedule, SCHEDULE_NONE);
5671 * Check if there is any ongoing reset in the hardware. This status can
5672 * be checked from reset_pending. If there is then, we need to wait for
5673 * hardware to complete reset.
5674 * a. If we are able to figure out in reasonable time that hardware
5675 * has fully resetted then, we can proceed with driver, client
5677 * b. else, we can come back later to check this status so re-sched
5680 reset_level = hns3_get_reset_level(hns, &hw->reset.pending);
5681 if (reset_level != HNS3_NONE_RESET) {
5682 gettimeofday(&tv_start, NULL);
5683 ret = hns3_reset_process(hns, reset_level);
5684 gettimeofday(&tv, NULL);
5685 timersub(&tv, &tv_start, &tv_delta);
5686 msec = tv_delta.tv_sec * MSEC_PER_SEC +
5687 tv_delta.tv_usec / USEC_PER_MSEC;
5688 if (msec > HNS3_RESET_PROCESS_MS)
5689 hns3_err(hw, "%d handle long time delta %" PRIx64
5690 " ms time=%ld.%.6ld",
5691 hw->reset.level, msec,
5692 tv.tv_sec, tv.tv_usec);
5697 /* Check if we got any *new* reset requests to be honored */
5698 reset_level = hns3_get_reset_level(hns, &hw->reset.request);
5699 if (reset_level != HNS3_NONE_RESET)
5700 hns3_msix_process(hns, reset_level);
5704 hns3_get_speed_capa_num(uint16_t device_id)
5708 switch (device_id) {
5709 case HNS3_DEV_ID_25GE:
5710 case HNS3_DEV_ID_25GE_RDMA:
5713 case HNS3_DEV_ID_100G_RDMA_MACSEC:
5714 case HNS3_DEV_ID_200G_RDMA:
5726 hns3_get_speed_fec_capa(struct rte_eth_fec_capa *speed_fec_capa,
5729 switch (device_id) {
5730 case HNS3_DEV_ID_25GE:
5732 case HNS3_DEV_ID_25GE_RDMA:
5733 speed_fec_capa[0].speed = speed_fec_capa_tbl[1].speed;
5734 speed_fec_capa[0].capa = speed_fec_capa_tbl[1].capa;
5736 /* In HNS3 device, the 25G NIC is compatible with 10G rate */
5737 speed_fec_capa[1].speed = speed_fec_capa_tbl[0].speed;
5738 speed_fec_capa[1].capa = speed_fec_capa_tbl[0].capa;
5740 case HNS3_DEV_ID_100G_RDMA_MACSEC:
5741 speed_fec_capa[0].speed = speed_fec_capa_tbl[4].speed;
5742 speed_fec_capa[0].capa = speed_fec_capa_tbl[4].capa;
5744 case HNS3_DEV_ID_200G_RDMA:
5745 speed_fec_capa[0].speed = speed_fec_capa_tbl[5].speed;
5746 speed_fec_capa[0].capa = speed_fec_capa_tbl[5].capa;
5756 hns3_fec_get_capability(struct rte_eth_dev *dev,
5757 struct rte_eth_fec_capa *speed_fec_capa,
5760 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5761 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5762 uint16_t device_id = pci_dev->id.device_id;
5763 unsigned int capa_num;
5766 capa_num = hns3_get_speed_capa_num(device_id);
5767 if (capa_num == 0) {
5768 hns3_err(hw, "device(0x%x) is not supported by hns3 PMD",
5773 if (speed_fec_capa == NULL || num < capa_num)
5776 ret = hns3_get_speed_fec_capa(speed_fec_capa, device_id);
5784 get_current_fec_auto_state(struct hns3_hw *hw, uint8_t *state)
5786 struct hns3_config_fec_cmd *req;
5787 struct hns3_cmd_desc desc;
5790 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_FEC_MODE, true);
5791 req = (struct hns3_config_fec_cmd *)desc.data;
5792 ret = hns3_cmd_send(hw, &desc, 1);
5794 hns3_err(hw, "get current fec auto state failed, ret = %d",
5799 *state = req->fec_mode & (1U << HNS3_MAC_CFG_FEC_AUTO_EN_B);
5804 hns3_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
5806 #define QUERY_ACTIVE_SPEED 1
5807 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5808 struct hns3_sfp_speed_cmd *resp;
5809 uint32_t tmp_fec_capa;
5811 struct hns3_cmd_desc desc;
5815 * If link is down and AUTO is enabled, AUTO is returned, otherwise,
5816 * configured FEC mode is returned.
5817 * If link is up, current FEC mode is returned.
5819 if (hw->mac.link_status == ETH_LINK_DOWN) {
5820 ret = get_current_fec_auto_state(hw, &auto_state);
5824 if (auto_state == 0x1) {
5825 *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(AUTO);
5830 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_SFP_GET_SPEED, true);
5831 resp = (struct hns3_sfp_speed_cmd *)desc.data;
5832 resp->query_type = QUERY_ACTIVE_SPEED;
5834 ret = hns3_cmd_send(hw, &desc, 1);
5835 if (ret == -EOPNOTSUPP) {
5836 hns3_err(hw, "IMP do not support get FEC, ret = %d", ret);
5839 hns3_err(hw, "get FEC failed, ret = %d", ret);
5844 * FEC mode order defined in hns3 hardware is inconsistend with
5845 * that defined in the ethdev library. So the sequence needs
5848 switch (resp->active_fec) {
5849 case HNS3_HW_FEC_MODE_NOFEC:
5850 tmp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
5852 case HNS3_HW_FEC_MODE_BASER:
5853 tmp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
5855 case HNS3_HW_FEC_MODE_RS:
5856 tmp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(RS);
5859 tmp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
5863 *fec_capa = tmp_fec_capa;
5868 hns3_set_fec_hw(struct hns3_hw *hw, uint32_t mode)
5870 struct hns3_config_fec_cmd *req;
5871 struct hns3_cmd_desc desc;
5874 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_FEC_MODE, false);
5876 req = (struct hns3_config_fec_cmd *)desc.data;
5878 case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
5879 hns3_set_field(req->fec_mode, HNS3_MAC_CFG_FEC_MODE_M,
5880 HNS3_MAC_CFG_FEC_MODE_S, HNS3_MAC_FEC_OFF);
5882 case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
5883 hns3_set_field(req->fec_mode, HNS3_MAC_CFG_FEC_MODE_M,
5884 HNS3_MAC_CFG_FEC_MODE_S, HNS3_MAC_FEC_BASER);
5886 case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
5887 hns3_set_field(req->fec_mode, HNS3_MAC_CFG_FEC_MODE_M,
5888 HNS3_MAC_CFG_FEC_MODE_S, HNS3_MAC_FEC_RS);
5890 case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
5891 hns3_set_bit(req->fec_mode, HNS3_MAC_CFG_FEC_AUTO_EN_B, 1);
5896 ret = hns3_cmd_send(hw, &desc, 1);
5898 hns3_err(hw, "set fec mode failed, ret = %d", ret);
5904 get_current_speed_fec_cap(struct hns3_hw *hw, struct rte_eth_fec_capa *fec_capa)
5906 struct hns3_mac *mac = &hw->mac;
5909 switch (mac->link_speed) {
5910 case ETH_SPEED_NUM_10G:
5911 cur_capa = fec_capa[1].capa;
5913 case ETH_SPEED_NUM_25G:
5914 case ETH_SPEED_NUM_100G:
5915 case ETH_SPEED_NUM_200G:
5916 cur_capa = fec_capa[0].capa;
5927 is_fec_mode_one_bit_set(uint32_t mode)
5932 for (i = 0; i < sizeof(mode); i++)
5933 if (mode >> i & 0x1)
5936 return cnt == 1 ? true : false;
5940 hns3_fec_set(struct rte_eth_dev *dev, uint32_t mode)
5942 #define FEC_CAPA_NUM 2
5943 struct hns3_adapter *hns = dev->data->dev_private;
5944 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns);
5945 struct hns3_pf *pf = &hns->pf;
5947 struct rte_eth_fec_capa fec_capa[FEC_CAPA_NUM];
5949 uint32_t num = FEC_CAPA_NUM;
5952 ret = hns3_fec_get_capability(dev, fec_capa, num);
5956 /* HNS3 PMD driver only support one bit set mode, e.g. 0x1, 0x4 */
5957 if (!is_fec_mode_one_bit_set(mode))
5958 hns3_err(hw, "FEC mode(0x%x) not supported in HNS3 PMD,"
5959 "FEC mode should be only one bit set", mode);
5962 * Check whether the configured mode is within the FEC capability.
5963 * If not, the configured mode will not be supported.
5965 cur_capa = get_current_speed_fec_cap(hw, fec_capa);
5966 if (!(cur_capa & mode)) {
5967 hns3_err(hw, "unsupported FEC mode = 0x%x", mode);
5971 ret = hns3_set_fec_hw(hw, mode);
5975 pf->fec_mode = mode;
5980 hns3_restore_fec(struct hns3_hw *hw)
5982 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
5983 struct hns3_pf *pf = &hns->pf;
5984 uint32_t mode = pf->fec_mode;
5987 ret = hns3_set_fec_hw(hw, mode);
5989 hns3_err(hw, "restore fec mode(0x%x) failed, ret = %d",
5996 hns3_query_dev_fec_info(struct rte_eth_dev *dev)
5998 struct hns3_adapter *hns = dev->data->dev_private;
5999 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns);
6000 struct hns3_pf *pf = &hns->pf;
6003 ret = hns3_fec_get(dev, &pf->fec_mode);
6005 hns3_err(hw, "query device FEC info failed, ret = %d", ret);
6010 static const struct eth_dev_ops hns3_eth_dev_ops = {
6011 .dev_configure = hns3_dev_configure,
6012 .dev_start = hns3_dev_start,
6013 .dev_stop = hns3_dev_stop,
6014 .dev_close = hns3_dev_close,
6015 .promiscuous_enable = hns3_dev_promiscuous_enable,
6016 .promiscuous_disable = hns3_dev_promiscuous_disable,
6017 .allmulticast_enable = hns3_dev_allmulticast_enable,
6018 .allmulticast_disable = hns3_dev_allmulticast_disable,
6019 .mtu_set = hns3_dev_mtu_set,
6020 .stats_get = hns3_stats_get,
6021 .stats_reset = hns3_stats_reset,
6022 .xstats_get = hns3_dev_xstats_get,
6023 .xstats_get_names = hns3_dev_xstats_get_names,
6024 .xstats_reset = hns3_dev_xstats_reset,
6025 .xstats_get_by_id = hns3_dev_xstats_get_by_id,
6026 .xstats_get_names_by_id = hns3_dev_xstats_get_names_by_id,
6027 .dev_infos_get = hns3_dev_infos_get,
6028 .fw_version_get = hns3_fw_version_get,
6029 .rx_queue_setup = hns3_rx_queue_setup,
6030 .tx_queue_setup = hns3_tx_queue_setup,
6031 .rx_queue_release = hns3_dev_rx_queue_release,
6032 .tx_queue_release = hns3_dev_tx_queue_release,
6033 .rx_queue_start = hns3_dev_rx_queue_start,
6034 .rx_queue_stop = hns3_dev_rx_queue_stop,
6035 .tx_queue_start = hns3_dev_tx_queue_start,
6036 .tx_queue_stop = hns3_dev_tx_queue_stop,
6037 .rx_queue_intr_enable = hns3_dev_rx_queue_intr_enable,
6038 .rx_queue_intr_disable = hns3_dev_rx_queue_intr_disable,
6039 .rxq_info_get = hns3_rxq_info_get,
6040 .txq_info_get = hns3_txq_info_get,
6041 .rx_burst_mode_get = hns3_rx_burst_mode_get,
6042 .tx_burst_mode_get = hns3_tx_burst_mode_get,
6043 .flow_ctrl_get = hns3_flow_ctrl_get,
6044 .flow_ctrl_set = hns3_flow_ctrl_set,
6045 .priority_flow_ctrl_set = hns3_priority_flow_ctrl_set,
6046 .mac_addr_add = hns3_add_mac_addr,
6047 .mac_addr_remove = hns3_remove_mac_addr,
6048 .mac_addr_set = hns3_set_default_mac_addr,
6049 .set_mc_addr_list = hns3_set_mc_mac_addr_list,
6050 .link_update = hns3_dev_link_update,
6051 .rss_hash_update = hns3_dev_rss_hash_update,
6052 .rss_hash_conf_get = hns3_dev_rss_hash_conf_get,
6053 .reta_update = hns3_dev_rss_reta_update,
6054 .reta_query = hns3_dev_rss_reta_query,
6055 .filter_ctrl = hns3_dev_filter_ctrl,
6056 .vlan_filter_set = hns3_vlan_filter_set,
6057 .vlan_tpid_set = hns3_vlan_tpid_set,
6058 .vlan_offload_set = hns3_vlan_offload_set,
6059 .vlan_pvid_set = hns3_vlan_pvid_set,
6060 .get_reg = hns3_get_regs,
6061 .get_dcb_info = hns3_get_dcb_info,
6062 .dev_supported_ptypes_get = hns3_dev_supported_ptypes_get,
6063 .fec_get_capability = hns3_fec_get_capability,
6064 .fec_get = hns3_fec_get,
6065 .fec_set = hns3_fec_set,
6068 static const struct hns3_reset_ops hns3_reset_ops = {
6069 .reset_service = hns3_reset_service,
6070 .stop_service = hns3_stop_service,
6071 .prepare_reset = hns3_prepare_reset,
6072 .wait_hardware_ready = hns3_wait_hardware_ready,
6073 .reinit_dev = hns3_reinit_dev,
6074 .restore_conf = hns3_restore_conf,
6075 .start_service = hns3_start_service,
6079 hns3_dev_init(struct rte_eth_dev *eth_dev)
6081 struct hns3_adapter *hns = eth_dev->data->dev_private;
6082 char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
6083 struct rte_ether_addr *eth_addr;
6084 struct hns3_hw *hw = &hns->hw;
6087 PMD_INIT_FUNC_TRACE();
6089 eth_dev->process_private = (struct hns3_process_private *)
6090 rte_zmalloc_socket("hns3_filter_list",
6091 sizeof(struct hns3_process_private),
6092 RTE_CACHE_LINE_SIZE, eth_dev->device->numa_node);
6093 if (eth_dev->process_private == NULL) {
6094 PMD_INIT_LOG(ERR, "Failed to alloc memory for process private");
6097 /* initialize flow filter lists */
6098 hns3_filterlist_init(eth_dev);
6100 hns3_set_rxtx_function(eth_dev);
6101 eth_dev->dev_ops = &hns3_eth_dev_ops;
6102 eth_dev->rx_queue_count = hns3_rx_queue_count;
6103 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
6104 ret = hns3_mp_init_secondary();
6106 PMD_INIT_LOG(ERR, "Failed to init for secondary "
6107 "process, ret = %d", ret);
6108 goto err_mp_init_secondary;
6111 hw->secondary_cnt++;
6115 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
6117 ret = hns3_mp_init_primary();
6120 "Failed to init for primary process, ret = %d",
6122 goto err_mp_init_primary;
6125 hw->adapter_state = HNS3_NIC_UNINITIALIZED;
6127 hw->data = eth_dev->data;
6130 * Set default max packet size according to the mtu
6131 * default vale in DPDK frame.
6133 hns->pf.mps = hw->data->mtu + HNS3_ETH_OVERHEAD;
6135 ret = hns3_reset_init(hw);
6137 goto err_init_reset;
6138 hw->reset.ops = &hns3_reset_ops;
6140 ret = hns3_init_pf(eth_dev);
6142 PMD_INIT_LOG(ERR, "Failed to init pf: %d", ret);
6146 /* Allocate memory for storing MAC addresses */
6147 eth_dev->data->mac_addrs = rte_zmalloc("hns3-mac",
6148 sizeof(struct rte_ether_addr) *
6149 HNS3_UC_MACADDR_NUM, 0);
6150 if (eth_dev->data->mac_addrs == NULL) {
6151 PMD_INIT_LOG(ERR, "Failed to allocate %zx bytes needed "
6152 "to store MAC addresses",
6153 sizeof(struct rte_ether_addr) *
6154 HNS3_UC_MACADDR_NUM);
6156 goto err_rte_zmalloc;
6159 eth_addr = (struct rte_ether_addr *)hw->mac.mac_addr;
6160 if (!rte_is_valid_assigned_ether_addr(eth_addr)) {
6161 rte_eth_random_addr(hw->mac.mac_addr);
6162 rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
6163 (struct rte_ether_addr *)hw->mac.mac_addr);
6164 hns3_warn(hw, "default mac_addr from firmware is an invalid "
6165 "unicast address, using random MAC address %s",
6168 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.mac_addr,
6169 ð_dev->data->mac_addrs[0]);
6171 hw->adapter_state = HNS3_NIC_INITIALIZED;
6173 if (rte_atomic16_read(&hns->hw.reset.schedule) == SCHEDULE_PENDING) {
6174 hns3_err(hw, "Reschedule reset service after dev_init");
6175 hns3_schedule_reset(hns);
6177 /* IMP will wait ready flag before reset */
6178 hns3_notify_reset_ready(hw, false);
6181 hns3_info(hw, "hns3 dev initialization successful!");
6185 hns3_uninit_pf(eth_dev);
6188 rte_free(hw->reset.wait_data);
6191 hns3_mp_uninit_primary();
6193 err_mp_init_primary:
6194 err_mp_init_secondary:
6195 eth_dev->dev_ops = NULL;
6196 eth_dev->rx_pkt_burst = NULL;
6197 eth_dev->tx_pkt_burst = NULL;
6198 eth_dev->tx_pkt_prepare = NULL;
6199 rte_free(eth_dev->process_private);
6200 eth_dev->process_private = NULL;
6205 hns3_dev_uninit(struct rte_eth_dev *eth_dev)
6207 struct hns3_adapter *hns = eth_dev->data->dev_private;
6208 struct hns3_hw *hw = &hns->hw;
6210 PMD_INIT_FUNC_TRACE();
6212 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6215 if (hw->adapter_state < HNS3_NIC_CLOSING)
6216 hns3_dev_close(eth_dev);
6218 hw->adapter_state = HNS3_NIC_REMOVED;
6223 eth_hns3_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
6224 struct rte_pci_device *pci_dev)
6226 return rte_eth_dev_pci_generic_probe(pci_dev,
6227 sizeof(struct hns3_adapter),
6232 eth_hns3_pci_remove(struct rte_pci_device *pci_dev)
6234 return rte_eth_dev_pci_generic_remove(pci_dev, hns3_dev_uninit);
6237 static const struct rte_pci_id pci_id_hns3_map[] = {
6238 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_GE) },
6239 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_25GE) },
6240 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_25GE_RDMA) },
6241 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_50GE_RDMA) },
6242 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_100G_RDMA_MACSEC) },
6243 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_200G_RDMA) },
6244 { .vendor_id = 0, }, /* sentinel */
6247 static struct rte_pci_driver rte_hns3_pmd = {
6248 .id_table = pci_id_hns3_map,
6249 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
6250 .probe = eth_hns3_pci_probe,
6251 .remove = eth_hns3_pci_remove,
6254 RTE_PMD_REGISTER_PCI(net_hns3, rte_hns3_pmd);
6255 RTE_PMD_REGISTER_PCI_TABLE(net_hns3, pci_id_hns3_map);
6256 RTE_PMD_REGISTER_KMOD_DEP(net_hns3, "* igb_uio | vfio-pci");
6257 RTE_LOG_REGISTER(hns3_logtype_init, pmd.net.hns3.init, NOTICE);
6258 RTE_LOG_REGISTER(hns3_logtype_driver, pmd.net.hns3.driver, NOTICE);