Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018-2021 HiSilicon Limited.
3 : : */
4 : :
5 : : #include <rte_alarm.h>
6 : : #include <bus_pci_driver.h>
7 : : #include <ethdev_pci.h>
8 : :
9 : : #include "hns3_common.h"
10 : : #include "hns3_dump.h"
11 : : #include "hns3_logs.h"
12 : : #include "hns3_rxtx.h"
13 : : #include "hns3_intr.h"
14 : : #include "hns3_regs.h"
15 : : #include "hns3_dcb.h"
16 : : #include "hns3_mp.h"
17 : : #include "hns3_flow.h"
18 : : #include "hns3_ptp.h"
19 : : #include "hns3_ethdev.h"
20 : :
21 : : #define HNS3_SERVICE_INTERVAL 1000000 /* us */
22 : : #define HNS3_SERVICE_QUICK_INTERVAL 10
23 : : #define HNS3_INVALID_PVID 0xFFFF
24 : :
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)
36 : :
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
42 : :
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
47 : : #define HNS3_VECTOR0_TRIGGER_IMP_RESET_B 7U
48 : :
49 : : #define HNS3_RESET_WAIT_MS 100
50 : : #define HNS3_RESET_WAIT_CNT 200
51 : :
52 : : enum hns3_evt_cause {
53 : : HNS3_VECTOR0_EVENT_RST,
54 : : HNS3_VECTOR0_EVENT_MBX,
55 : : HNS3_VECTOR0_EVENT_ERR,
56 : : HNS3_VECTOR0_EVENT_PTP,
57 : : HNS3_VECTOR0_EVENT_OTHER,
58 : : };
59 : :
60 : : struct hns3_intr_state {
61 : : uint32_t vector0_state;
62 : : uint32_t cmdq_state;
63 : : uint32_t hw_err_state;
64 : : };
65 : :
66 : : #define HNS3_SPEEDS_SUPP_FEC (RTE_ETH_LINK_SPEED_10G | \
67 : : RTE_ETH_LINK_SPEED_25G | \
68 : : RTE_ETH_LINK_SPEED_40G | \
69 : : RTE_ETH_LINK_SPEED_50G | \
70 : : RTE_ETH_LINK_SPEED_100G | \
71 : : RTE_ETH_LINK_SPEED_200G)
72 : :
73 : : static const struct rte_eth_fec_capa speed_fec_capa_tbl[] = {
74 : : { RTE_ETH_SPEED_NUM_10G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
75 : : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
76 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) },
77 : :
78 : : { RTE_ETH_SPEED_NUM_25G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
79 : : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
80 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
81 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS) },
82 : :
83 : : { RTE_ETH_SPEED_NUM_40G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
84 : : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
85 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) },
86 : :
87 : : { RTE_ETH_SPEED_NUM_50G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
88 : : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
89 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
90 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS) },
91 : :
92 : : { RTE_ETH_SPEED_NUM_100G, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
93 : : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
94 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS) },
95 : :
96 : : { RTE_ETH_SPEED_NUM_200G, RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
97 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS) |
98 : : RTE_ETH_FEC_MODE_CAPA_MASK(LLRS) }
99 : : };
100 : :
101 : : static enum hns3_reset_level hns3_get_reset_level(struct hns3_adapter *hns,
102 : : RTE_ATOMIC(uint64_t) *levels);
103 : : static int hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
104 : : static int hns3_vlan_pvid_configure(struct hns3_adapter *hns, uint16_t pvid,
105 : : int on);
106 : : static int hns3_update_link_info(struct rte_eth_dev *eth_dev);
107 : : static bool hns3_update_link_status(struct hns3_hw *hw);
108 : :
109 : : static int hns3_add_mc_mac_addr(struct hns3_hw *hw,
110 : : struct rte_ether_addr *mac_addr);
111 : : static int hns3_remove_mc_mac_addr(struct hns3_hw *hw,
112 : : struct rte_ether_addr *mac_addr);
113 : : static int hns3_restore_fec(struct hns3_hw *hw);
114 : : static int hns3_query_dev_fec_info(struct hns3_hw *hw);
115 : : static int hns3_do_stop(struct hns3_adapter *hns);
116 : : static int hns3_check_port_speed(struct hns3_hw *hw, uint32_t link_speeds);
117 : : static int hns3_cfg_mac_mode(struct hns3_hw *hw, bool enable);
118 : :
119 : :
120 : : static void
121 : : hns3_pf_disable_irq0(struct hns3_hw *hw)
122 : : {
123 : 0 : hns3_write_dev(hw, HNS3_MISC_VECTOR_REG_BASE, 0);
124 : : }
125 : :
126 : : static void
127 : : hns3_pf_enable_irq0(struct hns3_hw *hw)
128 : : {
129 : 0 : hns3_write_dev(hw, HNS3_MISC_VECTOR_REG_BASE, 1);
130 : 0 : }
131 : :
132 : : static enum hns3_evt_cause
133 : 0 : hns3_proc_imp_reset_event(struct hns3_adapter *hns, uint32_t *vec_val)
134 : : {
135 : : struct hns3_hw *hw = &hns->hw;
136 : :
137 : 0 : rte_atomic_store_explicit(&hw->reset.disable_cmd, 1, rte_memory_order_relaxed);
138 : 0 : hns3_atomic_set_bit(HNS3_IMP_RESET, &hw->reset.pending);
139 : 0 : *vec_val = BIT(HNS3_VECTOR0_IMPRESET_INT_B);
140 : 0 : hw->reset.stats.imp_cnt++;
141 : 0 : hns3_warn(hw, "IMP reset detected, clear reset status");
142 : :
143 : 0 : return HNS3_VECTOR0_EVENT_RST;
144 : : }
145 : :
146 : : static enum hns3_evt_cause
147 : 0 : hns3_proc_global_reset_event(struct hns3_adapter *hns, uint32_t *vec_val)
148 : : {
149 : : struct hns3_hw *hw = &hns->hw;
150 : :
151 : 0 : rte_atomic_store_explicit(&hw->reset.disable_cmd, 1, rte_memory_order_relaxed);
152 : 0 : hns3_atomic_set_bit(HNS3_GLOBAL_RESET, &hw->reset.pending);
153 : 0 : *vec_val = BIT(HNS3_VECTOR0_GLOBALRESET_INT_B);
154 : 0 : hw->reset.stats.global_cnt++;
155 : 0 : hns3_warn(hw, "Global reset detected, clear reset status");
156 : :
157 : 0 : return HNS3_VECTOR0_EVENT_RST;
158 : : }
159 : :
160 : : static void
161 : : hns3_query_intr_state(struct hns3_hw *hw, struct hns3_intr_state *state)
162 : : {
163 : 0 : state->vector0_state = hns3_read_dev(hw, HNS3_VECTOR0_OTHER_INT_STS_REG);
164 : 0 : state->cmdq_state = hns3_read_dev(hw, HNS3_VECTOR0_CMDQ_SRC_REG);
165 : 0 : state->hw_err_state = hns3_read_dev(hw, HNS3_RAS_PF_OTHER_INT_STS_REG);
166 : : }
167 : :
168 : : static enum hns3_evt_cause
169 : 0 : hns3_check_event_cause(struct hns3_adapter *hns, uint32_t *clearval)
170 : : {
171 : : struct hns3_hw *hw = &hns->hw;
172 : : struct hns3_intr_state state;
173 : : uint32_t val;
174 : : enum hns3_evt_cause ret;
175 : :
176 : : hns3_query_intr_state(hw, &state);
177 : :
178 : : /*
179 : : * Assumption: If by any chance reset and mailbox events are reported
180 : : * together then we will only process reset event and defer the
181 : : * processing of the mailbox events. Since, we would have not cleared
182 : : * RX CMDQ event this time we would receive again another interrupt
183 : : * from H/W just for the mailbox.
184 : : */
185 [ # # ]: 0 : if (BIT(HNS3_VECTOR0_IMPRESET_INT_B) & state.vector0_state) { /* IMP */
186 : 0 : ret = hns3_proc_imp_reset_event(hns, &val);
187 : 0 : goto out;
188 : : }
189 : :
190 : : /* Global reset */
191 [ # # ]: 0 : if (BIT(HNS3_VECTOR0_GLOBALRESET_INT_B) & state.vector0_state) {
192 : 0 : ret = hns3_proc_global_reset_event(hns, &val);
193 : 0 : goto out;
194 : : }
195 : :
196 : : /* Check for vector0 1588 event source */
197 [ # # ]: 0 : if (BIT(HNS3_VECTOR0_1588_INT_B) & state.vector0_state) {
198 : 0 : val = BIT(HNS3_VECTOR0_1588_INT_B);
199 : : ret = HNS3_VECTOR0_EVENT_PTP;
200 : 0 : goto out;
201 : : }
202 : :
203 : : /* check for vector0 msix event source */
204 [ # # ]: 0 : if (state.vector0_state & HNS3_VECTOR0_REG_MSIX_MASK ||
205 [ # # ]: 0 : state.hw_err_state & HNS3_RAS_REG_NFE_MASK) {
206 : 0 : val = state.vector0_state | state.hw_err_state;
207 : : ret = HNS3_VECTOR0_EVENT_ERR;
208 : 0 : goto out;
209 : : }
210 : :
211 : : /* check for vector0 mailbox(=CMDQ RX) event source */
212 [ # # ]: 0 : if (BIT(HNS3_VECTOR0_RX_CMDQ_INT_B) & state.cmdq_state) {
213 : 0 : state.cmdq_state &= ~BIT(HNS3_VECTOR0_RX_CMDQ_INT_B);
214 : 0 : val = state.cmdq_state;
215 : : ret = HNS3_VECTOR0_EVENT_MBX;
216 : 0 : goto out;
217 : : }
218 : :
219 : 0 : val = state.vector0_state;
220 : : ret = HNS3_VECTOR0_EVENT_OTHER;
221 : :
222 : 0 : out:
223 : 0 : *clearval = val;
224 : 0 : return ret;
225 : : }
226 : :
227 : : void
228 : 0 : hns3_clear_reset_event(struct hns3_hw *hw)
229 : : {
230 : : uint32_t clearval = 0;
231 : :
232 [ # # # ]: 0 : switch (hw->reset.level) {
233 : : case HNS3_IMP_RESET:
234 : : clearval = BIT(HNS3_VECTOR0_IMPRESET_INT_B);
235 : : break;
236 : : case HNS3_GLOBAL_RESET:
237 : : clearval = BIT(HNS3_VECTOR0_GLOBALRESET_INT_B);
238 : : break;
239 : : default:
240 : : break;
241 : : }
242 : :
243 : : if (clearval == 0)
244 : : return;
245 : :
246 : 0 : hns3_write_dev(hw, HNS3_MISC_RESET_STS_REG, clearval);
247 : :
248 : : hns3_pf_enable_irq0(hw);
249 : : }
250 : :
251 : : static void
252 : : hns3_clear_event_cause(struct hns3_hw *hw, uint32_t event_type, uint32_t regclr)
253 : : {
254 : 0 : if (event_type == HNS3_VECTOR0_EVENT_RST ||
255 [ # # ]: 0 : event_type == HNS3_VECTOR0_EVENT_PTP)
256 : 0 : hns3_write_dev(hw, HNS3_MISC_RESET_STS_REG, regclr);
257 [ # # ]: 0 : else if (event_type == HNS3_VECTOR0_EVENT_MBX)
258 : 0 : hns3_write_dev(hw, HNS3_VECTOR0_CMDQ_SRC_REG, regclr);
259 : : }
260 : :
261 : : static void
262 : 0 : hns3_clear_all_event_cause(struct hns3_hw *hw)
263 : : {
264 : : uint32_t vector0_int_stats;
265 : :
266 : 0 : vector0_int_stats = hns3_read_dev(hw, HNS3_VECTOR0_OTHER_INT_STS_REG);
267 [ # # ]: 0 : if (BIT(HNS3_VECTOR0_IMPRESET_INT_B) & vector0_int_stats)
268 : 0 : hns3_warn(hw, "Probe during IMP reset interrupt");
269 : :
270 [ # # ]: 0 : if (BIT(HNS3_VECTOR0_GLOBALRESET_INT_B) & vector0_int_stats)
271 : 0 : hns3_warn(hw, "Probe during Global reset interrupt");
272 : :
273 : : hns3_clear_event_cause(hw, HNS3_VECTOR0_EVENT_RST,
274 : : BIT(HNS3_VECTOR0_IMPRESET_INT_B) |
275 : : BIT(HNS3_VECTOR0_GLOBALRESET_INT_B) |
276 : : BIT(HNS3_VECTOR0_CORERESET_INT_B));
277 : : hns3_clear_event_cause(hw, HNS3_VECTOR0_EVENT_MBX, 0);
278 : : hns3_clear_event_cause(hw, HNS3_VECTOR0_EVENT_PTP,
279 : : BIT(HNS3_VECTOR0_1588_INT_B));
280 : 0 : }
281 : :
282 : : static void
283 : 0 : hns3_handle_mac_tnl(struct hns3_hw *hw)
284 : : {
285 : : struct hns3_cmd_desc desc;
286 : : uint32_t status;
287 : : int ret;
288 : :
289 : : /* query and clear mac tnl interrupt */
290 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_MAC_TNL_INT, true);
291 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
292 [ # # ]: 0 : if (ret) {
293 : 0 : hns3_err(hw, "failed to query mac tnl int, ret = %d.", ret);
294 : 0 : return;
295 : : }
296 : :
297 : 0 : status = rte_le_to_cpu_32(desc.data[0]);
298 [ # # ]: 0 : if (status) {
299 : 0 : hns3_warn(hw, "mac tnl int occurs, status = 0x%x.", status);
300 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CLEAR_MAC_TNL_INT,
301 : : false);
302 : 0 : desc.data[0] = rte_cpu_to_le_32(HNS3_MAC_TNL_INT_CLR);
303 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
304 [ # # ]: 0 : if (ret)
305 : 0 : hns3_err(hw, "failed to clear mac tnl int, ret = %d.",
306 : : ret);
307 : : }
308 : : }
309 : :
310 : : static void
311 : 0 : hns3_delay_before_clear_event_cause(struct hns3_hw *hw, uint32_t event_type, uint32_t regclr)
312 : : {
313 : : #define IMPRESET_WAIT_MS_TIME 5
314 : :
315 [ # # # # ]: 0 : if (event_type == HNS3_VECTOR0_EVENT_RST &&
316 : 0 : regclr & BIT(HNS3_VECTOR0_IMPRESET_INT_B) &&
317 [ # # ]: 0 : hw->revision >= PCI_REVISION_ID_HIP09_A) {
318 : : rte_delay_ms(IMPRESET_WAIT_MS_TIME);
319 : 0 : hns3_dbg(hw, "wait firmware watchdog initialization completed.");
320 : : }
321 : 0 : }
322 : :
323 : : static bool
324 : 0 : hns3_reset_event_valid(struct hns3_hw *hw)
325 : : {
326 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
327 : : enum hns3_reset_level new_req = HNS3_NONE_RESET;
328 : : enum hns3_reset_level last_req;
329 : : uint32_t vector0_int;
330 : :
331 : 0 : vector0_int = hns3_read_dev(hw, HNS3_VECTOR0_OTHER_INT_STS_REG);
332 [ # # ]: 0 : if (BIT(HNS3_VECTOR0_IMPRESET_INT_B) & vector0_int)
333 : : new_req = HNS3_IMP_RESET;
334 [ # # ]: 0 : else if (BIT(HNS3_VECTOR0_GLOBALRESET_INT_B) & vector0_int)
335 : : new_req = HNS3_GLOBAL_RESET;
336 : : if (new_req == HNS3_NONE_RESET)
337 : : return true;
338 : :
339 : 0 : last_req = hns3_get_reset_level(hns, &hw->reset.pending);
340 [ # # ]: 0 : if (last_req == HNS3_NONE_RESET)
341 : : return true;
342 : :
343 [ # # ]: 0 : if (new_req > last_req)
344 : : return true;
345 : :
346 : 0 : hns3_warn(hw, "last_req (%u) less than or equal to new_req (%u) ignore",
347 : : last_req, new_req);
348 : 0 : return false;
349 : : }
350 : :
351 : : static void
352 : 0 : hns3_interrupt_handler(void *param)
353 : : {
354 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
355 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
356 : 0 : struct hns3_hw *hw = &hns->hw;
357 : : enum hns3_evt_cause event_cause;
358 : : struct hns3_intr_state state;
359 : 0 : uint32_t clearval = 0;
360 : :
361 [ # # ]: 0 : if (!hns3_reset_event_valid(hw))
362 : 0 : return;
363 : :
364 : : /* Disable interrupt */
365 : : hns3_pf_disable_irq0(hw);
366 : :
367 : 0 : event_cause = hns3_check_event_cause(hns, &clearval);
368 : : hns3_query_intr_state(hw, &state);
369 : 0 : hns3_delay_before_clear_event_cause(hw, event_cause, clearval);
370 : : hns3_clear_event_cause(hw, event_cause, clearval);
371 : : /* vector 0 interrupt is shared with reset and mailbox source events. */
372 [ # # ]: 0 : if (event_cause == HNS3_VECTOR0_EVENT_ERR) {
373 : 0 : hns3_warn(hw, "received interrupt: vector0_int_stat:0x%x "
374 : : "ras_int_stat:0x%x cmdq_int_stat:0x%x",
375 : : state.vector0_state, state.hw_err_state,
376 : : state.cmdq_state);
377 : 0 : hns3_handle_mac_tnl(hw);
378 : 0 : hns3_handle_error(hns);
379 [ # # ]: 0 : } else if (event_cause == HNS3_VECTOR0_EVENT_RST) {
380 : 0 : hns3_warn(hw, "received reset interrupt");
381 : 0 : hns3_schedule_reset(hns);
382 [ # # ]: 0 : } else if (event_cause == HNS3_VECTOR0_EVENT_MBX) {
383 : 0 : hns3pf_handle_mbx_msg(hw);
384 [ # # ]: 0 : } else if (event_cause != HNS3_VECTOR0_EVENT_PTP) {
385 : 0 : hns3_warn(hw, "received unknown event: vector0_int_stat:0x%x "
386 : : "ras_int_stat:0x%x cmdq_int_stat:0x%x",
387 : : state.vector0_state, state.hw_err_state,
388 : : state.cmdq_state);
389 : : }
390 : :
391 : : /* Enable interrupt if it is not cause by reset */
392 : 0 : if (event_cause == HNS3_VECTOR0_EVENT_ERR ||
393 : : event_cause == HNS3_VECTOR0_EVENT_MBX ||
394 [ # # ]: 0 : event_cause == HNS3_VECTOR0_EVENT_PTP ||
395 : : event_cause == HNS3_VECTOR0_EVENT_OTHER)
396 : : hns3_pf_enable_irq0(hw);
397 : : }
398 : :
399 : : static int
400 : 0 : hns3_set_port_vlan_filter(struct hns3_adapter *hns, uint16_t vlan_id, int on)
401 : : {
402 : : #define HNS3_VLAN_ID_OFFSET_STEP 160
403 : : #define HNS3_VLAN_BYTE_SIZE 8
404 : : struct hns3_vlan_filter_pf_cfg_cmd *req;
405 : 0 : struct hns3_hw *hw = &hns->hw;
406 : : uint8_t vlan_offset_byte_val;
407 : : struct hns3_cmd_desc desc;
408 : : uint8_t vlan_offset_byte;
409 : : uint8_t vlan_offset_base;
410 : : int ret;
411 : :
412 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_FILTER_PF_CFG, false);
413 : :
414 : 0 : vlan_offset_base = vlan_id / HNS3_VLAN_ID_OFFSET_STEP;
415 : 0 : vlan_offset_byte = (vlan_id % HNS3_VLAN_ID_OFFSET_STEP) /
416 : : HNS3_VLAN_BYTE_SIZE;
417 : 0 : vlan_offset_byte_val = 1 << (vlan_id % HNS3_VLAN_BYTE_SIZE);
418 : :
419 : : req = (struct hns3_vlan_filter_pf_cfg_cmd *)desc.data;
420 : 0 : req->vlan_offset = vlan_offset_base;
421 : 0 : req->vlan_cfg = on ? 0 : 1;
422 : 0 : req->vlan_offset_bitmap[vlan_offset_byte] = vlan_offset_byte_val;
423 : :
424 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
425 [ # # ]: 0 : if (ret)
426 : 0 : hns3_err(hw, "set port vlan id failed, vlan_id =%u, ret =%d",
427 : : vlan_id, ret);
428 : :
429 : 0 : return ret;
430 : : }
431 : :
432 : : static void
433 : 0 : hns3_rm_dev_vlan_table(struct hns3_adapter *hns, uint16_t vlan_id)
434 : : {
435 : : struct hns3_user_vlan_table *vlan_entry;
436 : : struct hns3_pf *pf = &hns->pf;
437 : :
438 [ # # ]: 0 : LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
439 [ # # ]: 0 : if (vlan_entry->vlan_id == vlan_id) {
440 [ # # ]: 0 : if (vlan_entry->hd_tbl_status)
441 : 0 : hns3_set_port_vlan_filter(hns, vlan_id, 0);
442 [ # # ]: 0 : LIST_REMOVE(vlan_entry, next);
443 : 0 : rte_free(vlan_entry);
444 : 0 : break;
445 : : }
446 : : }
447 : 0 : }
448 : :
449 : : static void
450 : 0 : hns3_add_dev_vlan_table(struct hns3_adapter *hns, uint16_t vlan_id,
451 : : bool writen_to_tbl)
452 : : {
453 : : struct hns3_user_vlan_table *vlan_entry;
454 : : struct hns3_hw *hw = &hns->hw;
455 : : struct hns3_pf *pf = &hns->pf;
456 : :
457 [ # # ]: 0 : LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
458 [ # # ]: 0 : if (vlan_entry->vlan_id == vlan_id)
459 : : return;
460 : : }
461 : :
462 : 0 : vlan_entry = rte_zmalloc("hns3_vlan_tbl", sizeof(*vlan_entry), 0);
463 [ # # ]: 0 : if (vlan_entry == NULL) {
464 : 0 : hns3_err(hw, "Failed to malloc hns3 vlan table");
465 : 0 : return;
466 : : }
467 : :
468 : 0 : vlan_entry->hd_tbl_status = writen_to_tbl;
469 : 0 : vlan_entry->vlan_id = vlan_id;
470 : :
471 [ # # ]: 0 : LIST_INSERT_HEAD(&pf->vlan_list, vlan_entry, next);
472 : : }
473 : :
474 : : static int
475 : 0 : hns3_restore_vlan_table(struct hns3_adapter *hns)
476 : : {
477 : : struct hns3_user_vlan_table *vlan_entry;
478 : : struct hns3_hw *hw = &hns->hw;
479 : : struct hns3_pf *pf = &hns->pf;
480 : : uint16_t vlan_id;
481 : : int ret = 0;
482 : :
483 [ # # ]: 0 : if (hw->port_base_vlan_cfg.state == HNS3_PORT_BASE_VLAN_ENABLE)
484 : 0 : return hns3_vlan_pvid_configure(hns,
485 : 0 : hw->port_base_vlan_cfg.pvid, 1);
486 : :
487 [ # # ]: 0 : LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
488 [ # # ]: 0 : if (vlan_entry->hd_tbl_status) {
489 : 0 : vlan_id = vlan_entry->vlan_id;
490 : 0 : ret = hns3_set_port_vlan_filter(hns, vlan_id, 1);
491 [ # # ]: 0 : if (ret)
492 : : break;
493 : : }
494 : : }
495 : :
496 : : return ret;
497 : : }
498 : :
499 : : static int
500 : 0 : hns3_vlan_filter_configure(struct hns3_adapter *hns, uint16_t vlan_id, int on)
501 : : {
502 : : struct hns3_hw *hw = &hns->hw;
503 : : bool writen_to_tbl = false;
504 : : int ret = 0;
505 : :
506 : : /*
507 : : * When vlan filter is enabled, hardware regards packets without vlan
508 : : * as packets with vlan 0. So, to receive packets without vlan, vlan id
509 : : * 0 is not allowed to be removed by rte_eth_dev_vlan_filter.
510 : : */
511 [ # # ]: 0 : if (on == 0 && vlan_id == 0)
512 : : return 0;
513 : :
514 : : /*
515 : : * When port base vlan enabled, we use port base vlan as the vlan
516 : : * filter condition. In this case, we don't update vlan filter table
517 : : * when user add new vlan or remove exist vlan, just update the
518 : : * vlan list. The vlan id in vlan list will be written in vlan filter
519 : : * table until port base vlan disabled
520 : : */
521 [ # # ]: 0 : if (hw->port_base_vlan_cfg.state == HNS3_PORT_BASE_VLAN_DISABLE) {
522 : 0 : ret = hns3_set_port_vlan_filter(hns, vlan_id, on);
523 : : writen_to_tbl = true;
524 : : }
525 : :
526 [ # # ]: 0 : if (ret == 0) {
527 [ # # ]: 0 : if (on)
528 : 0 : hns3_add_dev_vlan_table(hns, vlan_id, writen_to_tbl);
529 : : else
530 : 0 : hns3_rm_dev_vlan_table(hns, vlan_id);
531 : : }
532 : : return ret;
533 : : }
534 : :
535 : : static int
536 : 0 : hns3_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
537 : : {
538 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
539 : : struct hns3_hw *hw = &hns->hw;
540 : : int ret;
541 : :
542 : 0 : rte_spinlock_lock(&hw->lock);
543 : 0 : ret = hns3_vlan_filter_configure(hns, vlan_id, on);
544 : : rte_spinlock_unlock(&hw->lock);
545 : 0 : return ret;
546 : : }
547 : :
548 : : static int
549 : 0 : hns3_vlan_tpid_configure(struct hns3_adapter *hns, enum rte_vlan_type vlan_type,
550 : : uint16_t tpid)
551 : : {
552 : : struct hns3_rx_vlan_type_cfg_cmd *rx_req;
553 : : struct hns3_tx_vlan_type_cfg_cmd *tx_req;
554 : 0 : struct hns3_hw *hw = &hns->hw;
555 : : struct hns3_cmd_desc desc;
556 : : int ret;
557 : :
558 [ # # ]: 0 : if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
559 : : vlan_type != RTE_ETH_VLAN_TYPE_OUTER)) {
560 : 0 : hns3_err(hw, "Unsupported vlan type, vlan_type =%d", vlan_type);
561 : 0 : return -EINVAL;
562 : : }
563 : :
564 [ # # ]: 0 : if (tpid != RTE_ETHER_TYPE_VLAN) {
565 : 0 : hns3_err(hw, "Unsupported vlan tpid, vlan_type =%d", vlan_type);
566 : 0 : return -EINVAL;
567 : : }
568 : :
569 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_VLAN_TYPE_ID, false);
570 : : rx_req = (struct hns3_rx_vlan_type_cfg_cmd *)desc.data;
571 : :
572 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER) {
573 : 0 : rx_req->ot_fst_vlan_type = rte_cpu_to_le_16(tpid);
574 : 0 : rx_req->ot_sec_vlan_type = rte_cpu_to_le_16(tpid);
575 : : } else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER) {
576 : 0 : rx_req->ot_fst_vlan_type = rte_cpu_to_le_16(tpid);
577 : 0 : rx_req->ot_sec_vlan_type = rte_cpu_to_le_16(tpid);
578 : 0 : rx_req->in_fst_vlan_type = rte_cpu_to_le_16(tpid);
579 : 0 : rx_req->in_sec_vlan_type = rte_cpu_to_le_16(tpid);
580 : : }
581 : :
582 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
583 [ # # ]: 0 : if (ret) {
584 : 0 : hns3_err(hw, "Send rxvlan protocol type command fail, ret =%d",
585 : : ret);
586 : 0 : return ret;
587 : : }
588 : :
589 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_VLAN_INSERT, false);
590 : :
591 : : tx_req = (struct hns3_tx_vlan_type_cfg_cmd *)desc.data;
592 : 0 : tx_req->ot_vlan_type = rte_cpu_to_le_16(tpid);
593 : 0 : tx_req->in_vlan_type = rte_cpu_to_le_16(tpid);
594 : :
595 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
596 [ # # ]: 0 : if (ret)
597 : 0 : hns3_err(hw, "Send txvlan protocol type command fail, ret =%d",
598 : : ret);
599 : : return ret;
600 : : }
601 : :
602 : : static int
603 : 0 : hns3_vlan_tpid_set(struct rte_eth_dev *dev, enum rte_vlan_type vlan_type,
604 : : uint16_t tpid)
605 : : {
606 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
607 : : struct hns3_hw *hw = &hns->hw;
608 : : int ret;
609 : :
610 : 0 : rte_spinlock_lock(&hw->lock);
611 : 0 : ret = hns3_vlan_tpid_configure(hns, vlan_type, tpid);
612 : : rte_spinlock_unlock(&hw->lock);
613 : 0 : return ret;
614 : : }
615 : :
616 : : static int
617 : 0 : hns3_set_vlan_rx_offload_cfg(struct hns3_adapter *hns,
618 : : struct hns3_rx_vtag_cfg *vcfg)
619 : : {
620 : : struct hns3_vport_vtag_rx_cfg_cmd *req;
621 : 0 : struct hns3_hw *hw = &hns->hw;
622 : : struct hns3_cmd_desc desc;
623 : : uint16_t vport_id;
624 : : uint8_t bitmap;
625 : : int ret;
626 : :
627 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_PORT_RX_CFG, false);
628 : :
629 : : req = (struct hns3_vport_vtag_rx_cfg_cmd *)desc.data;
630 : 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_REM_TAG1_EN_B,
631 : : vcfg->strip_tag1_en ? 1 : 0);
632 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_REM_TAG2_EN_B,
633 : : vcfg->strip_tag2_en ? 1 : 0);
634 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_SHOW_TAG1_EN_B,
635 : : vcfg->vlan1_vlan_prionly ? 1 : 0);
636 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_SHOW_TAG2_EN_B,
637 : : vcfg->vlan2_vlan_prionly ? 1 : 0);
638 : :
639 : : /* firmware will ignore this configuration for PCI_REVISION_ID_HIP08 */
640 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_DISCARD_TAG1_EN_B,
641 : : vcfg->strip_tag1_discard_en ? 1 : 0);
642 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_DISCARD_TAG2_EN_B,
643 : : vcfg->strip_tag2_discard_en ? 1 : 0);
644 : : /*
645 : : * In current version VF is not supported when PF is driven by DPDK
646 : : * driver, just need to configure parameters for PF vport.
647 : : */
648 : : vport_id = HNS3_PF_FUNC_ID;
649 : 0 : req->vf_offset = vport_id / HNS3_VF_NUM_PER_CMD;
650 : : bitmap = 1 << (vport_id % HNS3_VF_NUM_PER_BYTE);
651 : 0 : req->vf_bitmap[req->vf_offset] = bitmap;
652 : :
653 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
654 [ # # ]: 0 : if (ret)
655 : 0 : hns3_err(hw, "Send port rxvlan cfg command fail, ret =%d", ret);
656 : 0 : return ret;
657 : : }
658 : :
659 : : static int
660 : 0 : hns3_en_hw_strip_rxvtag(struct hns3_adapter *hns, bool enable)
661 : : {
662 : : struct hns3_rx_vtag_cfg rxvlan_cfg;
663 : : struct hns3_hw *hw = &hns->hw;
664 : : int ret;
665 : :
666 [ # # ]: 0 : if (hw->port_base_vlan_cfg.state == HNS3_PORT_BASE_VLAN_DISABLE) {
667 : 0 : rxvlan_cfg.strip_tag1_en = false;
668 : 0 : rxvlan_cfg.strip_tag2_en = enable;
669 : 0 : rxvlan_cfg.strip_tag2_discard_en = false;
670 : : } else {
671 : 0 : rxvlan_cfg.strip_tag1_en = enable;
672 : 0 : rxvlan_cfg.strip_tag2_en = true;
673 : 0 : rxvlan_cfg.strip_tag2_discard_en = true;
674 : : }
675 : :
676 : 0 : rxvlan_cfg.strip_tag1_discard_en = false;
677 : 0 : rxvlan_cfg.vlan1_vlan_prionly = false;
678 : 0 : rxvlan_cfg.vlan2_vlan_prionly = false;
679 : 0 : rxvlan_cfg.rx_vlan_offload_en = enable;
680 : :
681 : 0 : ret = hns3_set_vlan_rx_offload_cfg(hns, &rxvlan_cfg);
682 [ # # ]: 0 : if (ret) {
683 [ # # ]: 0 : hns3_err(hw, "%s strip rx vtag failed, ret = %d.",
684 : : enable ? "enable" : "disable", ret);
685 : 0 : return ret;
686 : : }
687 : :
688 : 0 : memcpy(&hns->pf.vtag_config.rx_vcfg, &rxvlan_cfg,
689 : : sizeof(struct hns3_rx_vtag_cfg));
690 : :
691 : 0 : return ret;
692 : : }
693 : :
694 : : static int
695 : 0 : hns3_set_vlan_filter_ctrl(struct hns3_hw *hw, uint8_t vlan_type,
696 : : uint8_t fe_type, bool filter_en, uint8_t vf_id)
697 : : {
698 : : struct hns3_vlan_filter_ctrl_cmd *req;
699 : : struct hns3_cmd_desc desc;
700 : : int ret;
701 : :
702 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_FILTER_CTRL, false);
703 : :
704 : : req = (struct hns3_vlan_filter_ctrl_cmd *)desc.data;
705 : 0 : req->vlan_type = vlan_type;
706 [ # # ]: 0 : req->vlan_fe = filter_en ? fe_type : 0;
707 : 0 : req->vf_id = vf_id;
708 : :
709 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
710 [ # # ]: 0 : if (ret)
711 : 0 : hns3_err(hw, "set vlan filter fail, ret =%d", ret);
712 : :
713 : 0 : return ret;
714 : : }
715 : :
716 : : static int
717 : 0 : hns3_vlan_filter_init(struct hns3_adapter *hns)
718 : : {
719 : 0 : struct hns3_hw *hw = &hns->hw;
720 : : int ret;
721 : :
722 : 0 : ret = hns3_set_vlan_filter_ctrl(hw, HNS3_FILTER_TYPE_VF,
723 : : HNS3_FILTER_FE_EGRESS, false,
724 : : HNS3_PF_FUNC_ID);
725 [ # # ]: 0 : if (ret) {
726 : 0 : hns3_err(hw, "failed to init vf vlan filter, ret = %d", ret);
727 : 0 : return ret;
728 : : }
729 : :
730 : 0 : ret = hns3_set_vlan_filter_ctrl(hw, HNS3_FILTER_TYPE_PORT,
731 : : HNS3_FILTER_FE_INGRESS, false,
732 : : HNS3_PF_FUNC_ID);
733 [ # # ]: 0 : if (ret)
734 : 0 : hns3_err(hw, "failed to init port vlan filter, ret = %d", ret);
735 : :
736 : : return ret;
737 : : }
738 : :
739 : : static int
740 : 0 : hns3_enable_vlan_filter(struct hns3_adapter *hns, bool enable)
741 : : {
742 : 0 : struct hns3_hw *hw = &hns->hw;
743 : : int ret;
744 : :
745 : 0 : ret = hns3_set_vlan_filter_ctrl(hw, HNS3_FILTER_TYPE_PORT,
746 : : HNS3_FILTER_FE_INGRESS, enable,
747 : : HNS3_PF_FUNC_ID);
748 [ # # ]: 0 : if (ret)
749 [ # # ]: 0 : hns3_err(hw, "failed to %s port vlan filter, ret = %d",
750 : : enable ? "enable" : "disable", ret);
751 : :
752 : 0 : return ret;
753 : : }
754 : :
755 : : static int
756 : 0 : hns3_vlan_offload_set(struct rte_eth_dev *dev, int mask)
757 : : {
758 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
759 : : struct hns3_hw *hw = &hns->hw;
760 : : struct rte_eth_rxmode *rxmode;
761 : : unsigned int tmp_mask;
762 : : bool enable;
763 : : int ret = 0;
764 : :
765 : 0 : rte_spinlock_lock(&hw->lock);
766 : 0 : rxmode = &dev->data->dev_conf.rxmode;
767 : 0 : tmp_mask = (unsigned int)mask;
768 [ # # ]: 0 : if (tmp_mask & RTE_ETH_VLAN_FILTER_MASK) {
769 : : /* ignore vlan filter configuration during promiscuous mode */
770 [ # # ]: 0 : if (!dev->data->promiscuous) {
771 : : /* Enable or disable VLAN filter */
772 : 0 : enable = rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER ?
773 : 0 : true : false;
774 : :
775 : 0 : ret = hns3_enable_vlan_filter(hns, enable);
776 [ # # ]: 0 : if (ret) {
777 : : rte_spinlock_unlock(&hw->lock);
778 [ # # ]: 0 : hns3_err(hw, "failed to %s rx filter, ret = %d",
779 : : enable ? "enable" : "disable", ret);
780 : 0 : return ret;
781 : : }
782 : : }
783 : : }
784 : :
785 [ # # ]: 0 : if (tmp_mask & RTE_ETH_VLAN_STRIP_MASK) {
786 : : /* Enable or disable VLAN stripping */
787 : 0 : enable = rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP ?
788 : 0 : true : false;
789 : :
790 : 0 : ret = hns3_en_hw_strip_rxvtag(hns, enable);
791 [ # # ]: 0 : if (ret) {
792 : : rte_spinlock_unlock(&hw->lock);
793 [ # # ]: 0 : hns3_err(hw, "failed to %s rx strip, ret = %d",
794 : : enable ? "enable" : "disable", ret);
795 : 0 : return ret;
796 : : }
797 : : }
798 : :
799 : : rte_spinlock_unlock(&hw->lock);
800 : :
801 : 0 : return ret;
802 : : }
803 : :
804 : : static int
805 : 0 : hns3_set_vlan_tx_offload_cfg(struct hns3_adapter *hns,
806 : : struct hns3_tx_vtag_cfg *vcfg)
807 : : {
808 : : struct hns3_vport_vtag_tx_cfg_cmd *req;
809 : : struct hns3_cmd_desc desc;
810 : 0 : struct hns3_hw *hw = &hns->hw;
811 : : uint16_t vport_id;
812 : : uint8_t bitmap;
813 : : int ret;
814 : :
815 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_VLAN_PORT_TX_CFG, false);
816 : :
817 : : req = (struct hns3_vport_vtag_tx_cfg_cmd *)desc.data;
818 : 0 : req->def_vlan_tag1 = vcfg->default_tag1;
819 : 0 : req->def_vlan_tag2 = vcfg->default_tag2;
820 : 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_ACCEPT_TAG1_B,
821 : : vcfg->accept_tag1 ? 1 : 0);
822 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_ACCEPT_UNTAG1_B,
823 : : vcfg->accept_untag1 ? 1 : 0);
824 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_ACCEPT_TAG2_B,
825 : : vcfg->accept_tag2 ? 1 : 0);
826 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_ACCEPT_UNTAG2_B,
827 : : vcfg->accept_untag2 ? 1 : 0);
828 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_PORT_INS_TAG1_EN_B,
829 : : vcfg->insert_tag1_en ? 1 : 0);
830 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_PORT_INS_TAG2_EN_B,
831 : : vcfg->insert_tag2_en ? 1 : 0);
832 : 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_CFG_NIC_ROCE_SEL_B, 0);
833 : :
834 : : /* firmware will ignore this configuration for PCI_REVISION_ID_HIP08 */
835 [ # # ]: 0 : hns3_set_bit(req->vport_vlan_cfg, HNS3_TAG_SHIFT_MODE_EN_B,
836 : : vcfg->tag_shift_mode_en ? 1 : 0);
837 : :
838 : : /*
839 : : * In current version VF is not supported when PF is driven by DPDK
840 : : * driver, just need to configure parameters for PF vport.
841 : : */
842 : : vport_id = HNS3_PF_FUNC_ID;
843 : 0 : req->vf_offset = vport_id / HNS3_VF_NUM_PER_CMD;
844 : : bitmap = 1 << (vport_id % HNS3_VF_NUM_PER_BYTE);
845 : 0 : req->vf_bitmap[req->vf_offset] = bitmap;
846 : :
847 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
848 [ # # ]: 0 : if (ret)
849 : 0 : hns3_err(hw, "Send port txvlan cfg command fail, ret =%d", ret);
850 : :
851 : 0 : return ret;
852 : : }
853 : :
854 : : static int
855 : 0 : hns3_vlan_txvlan_cfg(struct hns3_adapter *hns, uint16_t port_base_vlan_state,
856 : : uint16_t pvid)
857 : : {
858 : : struct hns3_hw *hw = &hns->hw;
859 : : struct hns3_tx_vtag_cfg txvlan_cfg;
860 : : int ret;
861 : :
862 [ # # ]: 0 : if (port_base_vlan_state == HNS3_PORT_BASE_VLAN_DISABLE) {
863 : 0 : txvlan_cfg.accept_tag1 = true;
864 : 0 : txvlan_cfg.insert_tag1_en = false;
865 : 0 : txvlan_cfg.default_tag1 = 0;
866 : : } else {
867 : 0 : txvlan_cfg.accept_tag1 =
868 : 0 : hw->vlan_mode == HNS3_HW_SHIFT_AND_DISCARD_MODE;
869 : 0 : txvlan_cfg.insert_tag1_en = true;
870 : 0 : txvlan_cfg.default_tag1 = pvid;
871 : : }
872 : :
873 : 0 : txvlan_cfg.accept_untag1 = true;
874 : 0 : txvlan_cfg.accept_tag2 = true;
875 : 0 : txvlan_cfg.accept_untag2 = true;
876 : 0 : txvlan_cfg.insert_tag2_en = false;
877 : 0 : txvlan_cfg.default_tag2 = 0;
878 : 0 : txvlan_cfg.tag_shift_mode_en = true;
879 : :
880 : 0 : ret = hns3_set_vlan_tx_offload_cfg(hns, &txvlan_cfg);
881 [ # # ]: 0 : if (ret) {
882 : 0 : hns3_err(hw, "pf vlan set pvid failed, pvid =%u ,ret =%d", pvid,
883 : : ret);
884 : 0 : return ret;
885 : : }
886 : :
887 : 0 : memcpy(&hns->pf.vtag_config.tx_vcfg, &txvlan_cfg,
888 : : sizeof(struct hns3_tx_vtag_cfg));
889 : :
890 : 0 : return ret;
891 : : }
892 : :
893 : :
894 : : static void
895 : 0 : hns3_rm_all_vlan_table(struct hns3_adapter *hns, bool is_del_list)
896 : : {
897 : : struct hns3_user_vlan_table *vlan_entry;
898 : : struct hns3_pf *pf = &hns->pf;
899 : :
900 [ # # ]: 0 : LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
901 [ # # ]: 0 : if (vlan_entry->hd_tbl_status) {
902 : 0 : hns3_set_port_vlan_filter(hns, vlan_entry->vlan_id, 0);
903 : 0 : vlan_entry->hd_tbl_status = false;
904 : : }
905 : : }
906 : :
907 [ # # ]: 0 : if (is_del_list) {
908 : 0 : vlan_entry = LIST_FIRST(&pf->vlan_list);
909 [ # # ]: 0 : while (vlan_entry) {
910 [ # # ]: 0 : LIST_REMOVE(vlan_entry, next);
911 : 0 : rte_free(vlan_entry);
912 : 0 : vlan_entry = LIST_FIRST(&pf->vlan_list);
913 : : }
914 : : }
915 : 0 : }
916 : :
917 : : static void
918 : 0 : hns3_add_all_vlan_table(struct hns3_adapter *hns)
919 : : {
920 : : struct hns3_user_vlan_table *vlan_entry;
921 : : struct hns3_pf *pf = &hns->pf;
922 : :
923 [ # # ]: 0 : LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
924 [ # # ]: 0 : if (!vlan_entry->hd_tbl_status) {
925 : 0 : hns3_set_port_vlan_filter(hns, vlan_entry->vlan_id, 1);
926 : 0 : vlan_entry->hd_tbl_status = true;
927 : : }
928 : : }
929 : 0 : }
930 : :
931 : : static void
932 : 0 : hns3_remove_all_vlan_table(struct hns3_adapter *hns)
933 : : {
934 : : struct hns3_hw *hw = &hns->hw;
935 : : int ret;
936 : :
937 : 0 : hns3_rm_all_vlan_table(hns, true);
938 [ # # ]: 0 : if (hw->port_base_vlan_cfg.pvid != HNS3_INVALID_PVID) {
939 : 0 : ret = hns3_set_port_vlan_filter(hns,
940 : : hw->port_base_vlan_cfg.pvid, 0);
941 [ # # ]: 0 : if (ret) {
942 : 0 : hns3_err(hw, "Failed to remove all vlan table, ret =%d",
943 : : ret);
944 : 0 : return;
945 : : }
946 : : }
947 : : }
948 : :
949 : : static int
950 : 0 : hns3_update_vlan_filter_entries(struct hns3_adapter *hns,
951 : : uint16_t port_base_vlan_state, uint16_t new_pvid)
952 : : {
953 : : struct hns3_hw *hw = &hns->hw;
954 : : uint16_t old_pvid;
955 : : int ret;
956 : :
957 [ # # ]: 0 : if (port_base_vlan_state == HNS3_PORT_BASE_VLAN_ENABLE) {
958 : 0 : old_pvid = hw->port_base_vlan_cfg.pvid;
959 [ # # ]: 0 : if (old_pvid != HNS3_INVALID_PVID) {
960 : 0 : ret = hns3_set_port_vlan_filter(hns, old_pvid, 0);
961 [ # # ]: 0 : if (ret) {
962 : 0 : hns3_err(hw, "failed to remove old pvid %u, "
963 : : "ret = %d", old_pvid, ret);
964 : 0 : return ret;
965 : : }
966 : : }
967 : :
968 : 0 : hns3_rm_all_vlan_table(hns, false);
969 : 0 : ret = hns3_set_port_vlan_filter(hns, new_pvid, 1);
970 [ # # ]: 0 : if (ret) {
971 : 0 : hns3_err(hw, "failed to add new pvid %u, ret = %d",
972 : : new_pvid, ret);
973 : 0 : return ret;
974 : : }
975 : : } else {
976 : 0 : ret = hns3_set_port_vlan_filter(hns, new_pvid, 0);
977 [ # # ]: 0 : if (ret) {
978 : 0 : hns3_err(hw, "failed to remove pvid %u, ret = %d",
979 : : new_pvid, ret);
980 : 0 : return ret;
981 : : }
982 : :
983 : 0 : hns3_add_all_vlan_table(hns);
984 : : }
985 : : return 0;
986 : : }
987 : :
988 : : static int
989 : 0 : hns3_en_pvid_strip(struct hns3_adapter *hns, int on)
990 : : {
991 : : struct hns3_rx_vtag_cfg *old_cfg = &hns->pf.vtag_config.rx_vcfg;
992 : : struct hns3_rx_vtag_cfg rx_vlan_cfg;
993 : : bool rx_strip_en;
994 : : int ret;
995 : :
996 : 0 : rx_strip_en = old_cfg->rx_vlan_offload_en;
997 [ # # ]: 0 : if (on) {
998 : 0 : rx_vlan_cfg.strip_tag1_en = rx_strip_en;
999 : 0 : rx_vlan_cfg.strip_tag2_en = true;
1000 : 0 : rx_vlan_cfg.strip_tag2_discard_en = true;
1001 : : } else {
1002 : 0 : rx_vlan_cfg.strip_tag1_en = false;
1003 : 0 : rx_vlan_cfg.strip_tag2_en = rx_strip_en;
1004 : 0 : rx_vlan_cfg.strip_tag2_discard_en = false;
1005 : : }
1006 : 0 : rx_vlan_cfg.strip_tag1_discard_en = false;
1007 : 0 : rx_vlan_cfg.vlan1_vlan_prionly = false;
1008 : 0 : rx_vlan_cfg.vlan2_vlan_prionly = false;
1009 : 0 : rx_vlan_cfg.rx_vlan_offload_en = old_cfg->rx_vlan_offload_en;
1010 : :
1011 : 0 : ret = hns3_set_vlan_rx_offload_cfg(hns, &rx_vlan_cfg);
1012 [ # # ]: 0 : if (ret)
1013 : : return ret;
1014 : :
1015 : 0 : memcpy(&hns->pf.vtag_config.rx_vcfg, &rx_vlan_cfg,
1016 : : sizeof(struct hns3_rx_vtag_cfg));
1017 : :
1018 : 0 : return ret;
1019 : : }
1020 : :
1021 : : static int
1022 : 0 : hns3_vlan_pvid_configure(struct hns3_adapter *hns, uint16_t pvid, int on)
1023 : : {
1024 : : struct hns3_hw *hw = &hns->hw;
1025 : : uint16_t port_base_vlan_state;
1026 : : int ret, err;
1027 : :
1028 [ # # # # ]: 0 : if (on == 0 && pvid != hw->port_base_vlan_cfg.pvid) {
1029 [ # # ]: 0 : if (hw->port_base_vlan_cfg.pvid != HNS3_INVALID_PVID)
1030 : 0 : hns3_warn(hw, "Invalid operation! As current pvid set "
1031 : : "is %u, disable pvid %u is invalid",
1032 : : hw->port_base_vlan_cfg.pvid, pvid);
1033 : 0 : return 0;
1034 : : }
1035 : :
1036 : 0 : port_base_vlan_state = on ? HNS3_PORT_BASE_VLAN_ENABLE :
1037 : : HNS3_PORT_BASE_VLAN_DISABLE;
1038 : 0 : ret = hns3_vlan_txvlan_cfg(hns, port_base_vlan_state, pvid);
1039 [ # # ]: 0 : if (ret) {
1040 : 0 : hns3_err(hw, "failed to config tx vlan for pvid, ret = %d",
1041 : : ret);
1042 : 0 : return ret;
1043 : : }
1044 : :
1045 : 0 : ret = hns3_en_pvid_strip(hns, on);
1046 [ # # ]: 0 : if (ret) {
1047 : 0 : hns3_err(hw, "failed to config rx vlan strip for pvid, "
1048 : : "ret = %d", ret);
1049 : 0 : goto pvid_vlan_strip_fail;
1050 : : }
1051 : :
1052 [ # # ]: 0 : if (pvid == HNS3_INVALID_PVID)
1053 : 0 : goto out;
1054 : 0 : ret = hns3_update_vlan_filter_entries(hns, port_base_vlan_state, pvid);
1055 [ # # ]: 0 : if (ret) {
1056 : 0 : hns3_err(hw, "failed to update vlan filter entries, ret = %d",
1057 : : ret);
1058 : 0 : goto vlan_filter_set_fail;
1059 : : }
1060 : :
1061 : 0 : out:
1062 : 0 : hw->port_base_vlan_cfg.state = port_base_vlan_state;
1063 [ # # ]: 0 : hw->port_base_vlan_cfg.pvid = on ? pvid : HNS3_INVALID_PVID;
1064 : 0 : return ret;
1065 : :
1066 : : vlan_filter_set_fail:
1067 : 0 : err = hns3_en_pvid_strip(hns, hw->port_base_vlan_cfg.state ==
1068 : : HNS3_PORT_BASE_VLAN_ENABLE);
1069 [ # # ]: 0 : if (err)
1070 : 0 : hns3_err(hw, "fail to rollback pvid strip, ret = %d", err);
1071 : :
1072 : 0 : pvid_vlan_strip_fail:
1073 : 0 : err = hns3_vlan_txvlan_cfg(hns, hw->port_base_vlan_cfg.state,
1074 : 0 : hw->port_base_vlan_cfg.pvid);
1075 [ # # ]: 0 : if (err)
1076 : 0 : hns3_err(hw, "fail to rollback txvlan status, ret = %d", err);
1077 : :
1078 : : return ret;
1079 : : }
1080 : :
1081 : : static int
1082 : 0 : hns3_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
1083 : : {
1084 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1085 : 0 : struct hns3_hw *hw = &hns->hw;
1086 : : bool pvid_en_state_change;
1087 : : uint16_t pvid_state;
1088 : : int ret;
1089 : :
1090 [ # # ]: 0 : if (pvid > RTE_ETHER_MAX_VLAN_ID) {
1091 : 0 : hns3_err(hw, "Invalid vlan_id = %u > %d", pvid,
1092 : : RTE_ETHER_MAX_VLAN_ID);
1093 : 0 : return -EINVAL;
1094 : : }
1095 : :
1096 : : /*
1097 : : * If PVID configuration state change, should refresh the PVID
1098 : : * configuration state in struct hns3_tx_queue/hns3_rx_queue.
1099 : : */
1100 : 0 : pvid_state = hw->port_base_vlan_cfg.state;
1101 [ # # ]: 0 : if ((on && pvid_state == HNS3_PORT_BASE_VLAN_ENABLE) ||
1102 [ # # ]: 0 : (!on && pvid_state == HNS3_PORT_BASE_VLAN_DISABLE))
1103 : : pvid_en_state_change = false;
1104 : : else
1105 : : pvid_en_state_change = true;
1106 : :
1107 : 0 : rte_spinlock_lock(&hw->lock);
1108 : 0 : ret = hns3_vlan_pvid_configure(hns, pvid, on);
1109 : : rte_spinlock_unlock(&hw->lock);
1110 [ # # ]: 0 : if (ret)
1111 : : return ret;
1112 : : /*
1113 : : * Only in HNS3_SW_SHIFT_AND_MODE the PVID related operation in Tx/Rx
1114 : : * need be processed by PMD.
1115 : : */
1116 [ # # ]: 0 : if (pvid_en_state_change &&
1117 [ # # ]: 0 : hw->vlan_mode == HNS3_SW_SHIFT_AND_DISCARD_MODE)
1118 : 0 : hns3_update_all_queues_pvid_proc_en(hw);
1119 : :
1120 : : return 0;
1121 : : }
1122 : :
1123 : : static int
1124 : 0 : hns3_default_vlan_config(struct hns3_adapter *hns)
1125 : : {
1126 : : struct hns3_hw *hw = &hns->hw;
1127 : : int ret;
1128 : :
1129 : : /*
1130 : : * When vlan filter is enabled, hardware regards packets without vlan
1131 : : * as packets with vlan 0. Therefore, if vlan 0 is not in the vlan
1132 : : * table, packets without vlan won't be received. So, add vlan 0 as
1133 : : * the default vlan.
1134 : : */
1135 : 0 : ret = hns3_vlan_filter_configure(hns, 0, 1);
1136 [ # # ]: 0 : if (ret)
1137 : 0 : hns3_err(hw, "default vlan 0 config failed, ret =%d", ret);
1138 : 0 : return ret;
1139 : : }
1140 : :
1141 : : static int
1142 : 0 : hns3_init_vlan_config(struct hns3_adapter *hns)
1143 : : {
1144 : : struct hns3_hw *hw = &hns->hw;
1145 : : int ret;
1146 : :
1147 : : /*
1148 : : * This function can be called in the initialization and reset process,
1149 : : * when in reset process, it means that hardware had been reseted
1150 : : * successfully and we need to restore the hardware configuration to
1151 : : * ensure that the hardware configuration remains unchanged before and
1152 : : * after reset.
1153 : : */
1154 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed) == 0) {
1155 : 0 : hw->port_base_vlan_cfg.state = HNS3_PORT_BASE_VLAN_DISABLE;
1156 : 0 : hw->port_base_vlan_cfg.pvid = HNS3_INVALID_PVID;
1157 : : }
1158 : :
1159 : 0 : ret = hns3_vlan_filter_init(hns);
1160 [ # # ]: 0 : if (ret) {
1161 : 0 : hns3_err(hw, "vlan init fail in pf, ret =%d", ret);
1162 : 0 : return ret;
1163 : : }
1164 : :
1165 : 0 : ret = hns3_vlan_tpid_configure(hns, RTE_ETH_VLAN_TYPE_INNER,
1166 : : RTE_ETHER_TYPE_VLAN);
1167 [ # # ]: 0 : if (ret) {
1168 : 0 : hns3_err(hw, "tpid set fail in pf, ret =%d", ret);
1169 : 0 : return ret;
1170 : : }
1171 : :
1172 : : /*
1173 : : * When in the reinit dev stage of the reset process, the following
1174 : : * vlan-related configurations may differ from those at initialization,
1175 : : * we will restore configurations to hardware in hns3_restore_vlan_table
1176 : : * and hns3_restore_vlan_conf later.
1177 : : */
1178 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed) == 0) {
1179 : 0 : ret = hns3_vlan_pvid_configure(hns, HNS3_INVALID_PVID, 0);
1180 [ # # ]: 0 : if (ret) {
1181 : 0 : hns3_err(hw, "pvid set fail in pf, ret =%d", ret);
1182 : 0 : return ret;
1183 : : }
1184 : :
1185 : 0 : ret = hns3_en_hw_strip_rxvtag(hns, false);
1186 [ # # ]: 0 : if (ret) {
1187 : 0 : hns3_err(hw, "rx strip configure fail in pf, ret =%d",
1188 : : ret);
1189 : 0 : return ret;
1190 : : }
1191 : : }
1192 : :
1193 : 0 : return hns3_default_vlan_config(hns);
1194 : : }
1195 : :
1196 : : static int
1197 : 0 : hns3_restore_vlan_conf(struct hns3_adapter *hns)
1198 : : {
1199 : : struct hns3_pf *pf = &hns->pf;
1200 : : struct hns3_hw *hw = &hns->hw;
1201 : : uint64_t offloads;
1202 : : bool enable;
1203 : : int ret;
1204 : :
1205 [ # # ]: 0 : if (!hw->data->promiscuous) {
1206 : : /* restore vlan filter states */
1207 : 0 : offloads = hw->data->dev_conf.rxmode.offloads;
1208 : 0 : enable = offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER ? true : false;
1209 : 0 : ret = hns3_enable_vlan_filter(hns, enable);
1210 [ # # ]: 0 : if (ret) {
1211 : 0 : hns3_err(hw, "failed to restore vlan rx filter conf, "
1212 : : "ret = %d", ret);
1213 : 0 : return ret;
1214 : : }
1215 : : }
1216 : :
1217 : 0 : ret = hns3_set_vlan_rx_offload_cfg(hns, &pf->vtag_config.rx_vcfg);
1218 [ # # ]: 0 : if (ret) {
1219 : 0 : hns3_err(hw, "failed to restore vlan rx conf, ret = %d", ret);
1220 : 0 : return ret;
1221 : : }
1222 : :
1223 : 0 : ret = hns3_set_vlan_tx_offload_cfg(hns, &pf->vtag_config.tx_vcfg);
1224 [ # # ]: 0 : if (ret)
1225 : 0 : hns3_err(hw, "failed to restore vlan tx conf, ret = %d", ret);
1226 : :
1227 : : return ret;
1228 : : }
1229 : :
1230 : : static int
1231 : 0 : hns3_dev_configure_vlan(struct rte_eth_dev *dev)
1232 : : {
1233 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1234 : : struct rte_eth_dev_data *data = dev->data;
1235 : : struct rte_eth_txmode *txmode;
1236 : : struct hns3_hw *hw = &hns->hw;
1237 : : int mask;
1238 : : int ret;
1239 : :
1240 : : txmode = &data->dev_conf.txmode;
1241 [ # # ]: 0 : if (txmode->hw_vlan_reject_tagged || txmode->hw_vlan_reject_untagged)
1242 : 0 : hns3_warn(hw,
1243 : : "hw_vlan_reject_tagged or hw_vlan_reject_untagged "
1244 : : "configuration is not supported! Ignore these two "
1245 : : "parameters: hw_vlan_reject_tagged(%u), "
1246 : : "hw_vlan_reject_untagged(%u)",
1247 : : txmode->hw_vlan_reject_tagged,
1248 : : txmode->hw_vlan_reject_untagged);
1249 : :
1250 : : /* Apply vlan offload setting */
1251 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK;
1252 : 0 : ret = hns3_vlan_offload_set(dev, mask);
1253 [ # # ]: 0 : if (ret) {
1254 : 0 : hns3_err(hw, "dev config rx vlan offload failed, ret = %d",
1255 : : ret);
1256 : 0 : return ret;
1257 : : }
1258 : :
1259 : : /*
1260 : : * If pvid config is not set in rte_eth_conf, driver needn't to set
1261 : : * VLAN pvid related configuration to hardware.
1262 : : */
1263 [ # # ]: 0 : if (txmode->pvid == 0 && txmode->hw_vlan_insert_pvid == 0)
1264 : : return 0;
1265 : :
1266 : : /* Apply pvid setting */
1267 : 0 : ret = hns3_vlan_pvid_set(dev, txmode->pvid,
1268 : 0 : txmode->hw_vlan_insert_pvid);
1269 [ # # ]: 0 : if (ret)
1270 : 0 : hns3_err(hw, "dev config vlan pvid(%u) failed, ret = %d",
1271 : : txmode->pvid, ret);
1272 : :
1273 : : return ret;
1274 : : }
1275 : :
1276 : : static int
1277 : 0 : hns3_config_tso(struct hns3_hw *hw, unsigned int tso_mss_min,
1278 : : unsigned int tso_mss_max)
1279 : : {
1280 : : struct hns3_cfg_tso_status_cmd *req;
1281 : : struct hns3_cmd_desc desc;
1282 : : uint16_t tso_mss;
1283 : :
1284 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TSO_GENERIC_CONFIG, false);
1285 : :
1286 : : req = (struct hns3_cfg_tso_status_cmd *)desc.data;
1287 : :
1288 : : tso_mss = 0;
1289 : 0 : hns3_set_field(tso_mss, HNS3_TSO_MSS_MIN_M, HNS3_TSO_MSS_MIN_S,
1290 : : tso_mss_min);
1291 : 0 : req->tso_mss_min = rte_cpu_to_le_16(tso_mss);
1292 : :
1293 : : tso_mss = 0;
1294 : 0 : hns3_set_field(tso_mss, HNS3_TSO_MSS_MIN_M, HNS3_TSO_MSS_MIN_S,
1295 : : tso_mss_max);
1296 : 0 : req->tso_mss_max = rte_cpu_to_le_16(tso_mss);
1297 : :
1298 : 0 : return hns3_cmd_send(hw, &desc, 1);
1299 : : }
1300 : :
1301 : : static int
1302 : 0 : hns3_set_umv_space(struct hns3_hw *hw, uint16_t space_size,
1303 : : uint16_t *allocated_size, bool is_alloc)
1304 : : {
1305 : : struct hns3_umv_spc_alc_cmd *req;
1306 : : struct hns3_cmd_desc desc;
1307 : : int ret;
1308 : :
1309 : : req = (struct hns3_umv_spc_alc_cmd *)desc.data;
1310 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_VLAN_ALLOCATE, false);
1311 : 0 : hns3_set_bit(req->allocate, HNS3_UMV_SPC_ALC_B, is_alloc ? 0 : 1);
1312 : 0 : req->space_size = rte_cpu_to_le_32(space_size);
1313 : :
1314 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
1315 [ # # ]: 0 : if (ret) {
1316 [ # # ]: 0 : PMD_INIT_LOG(ERR, "%s umv space failed for cmd_send, ret =%d",
1317 : : is_alloc ? "allocate" : "free", ret);
1318 : 0 : return ret;
1319 : : }
1320 : :
1321 [ # # ]: 0 : if (is_alloc && allocated_size)
1322 : 0 : *allocated_size = rte_le_to_cpu_32(desc.data[1]);
1323 : :
1324 : : return 0;
1325 : : }
1326 : :
1327 : : static int
1328 : 0 : hns3_init_umv_space(struct hns3_hw *hw)
1329 : : {
1330 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1331 : : struct hns3_pf *pf = &hns->pf;
1332 : 0 : uint16_t allocated_size = 0;
1333 : : int ret;
1334 : :
1335 : 0 : ret = hns3_set_umv_space(hw, pf->wanted_umv_size, &allocated_size,
1336 : : true);
1337 [ # # ]: 0 : if (ret)
1338 : : return ret;
1339 : :
1340 [ # # ]: 0 : if (allocated_size < pf->wanted_umv_size)
1341 : 0 : PMD_INIT_LOG(WARNING, "Alloc umv space failed, want %u, get %u",
1342 : : pf->wanted_umv_size, allocated_size);
1343 : :
1344 [ # # ]: 0 : pf->max_umv_size = (!!allocated_size) ? allocated_size :
1345 : : pf->wanted_umv_size;
1346 : 0 : pf->used_umv_size = 0;
1347 : 0 : return 0;
1348 : : }
1349 : :
1350 : : static int
1351 : 0 : hns3_uninit_umv_space(struct hns3_hw *hw)
1352 : : {
1353 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1354 : : struct hns3_pf *pf = &hns->pf;
1355 : : int ret;
1356 : :
1357 [ # # ]: 0 : if (pf->max_umv_size == 0)
1358 : : return 0;
1359 : :
1360 : 0 : ret = hns3_set_umv_space(hw, pf->max_umv_size, NULL, false);
1361 [ # # ]: 0 : if (ret)
1362 : : return ret;
1363 : :
1364 : 0 : pf->max_umv_size = 0;
1365 : :
1366 : 0 : return 0;
1367 : : }
1368 : :
1369 : : static bool
1370 : : hns3_is_umv_space_full(struct hns3_hw *hw)
1371 : : {
1372 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1373 : : struct hns3_pf *pf = &hns->pf;
1374 : : bool is_full;
1375 : :
1376 : 0 : is_full = (pf->used_umv_size >= pf->max_umv_size);
1377 : :
1378 : : return is_full;
1379 : : }
1380 : :
1381 : : static void
1382 : : hns3_update_umv_space(struct hns3_hw *hw, bool is_free)
1383 : : {
1384 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1385 : : struct hns3_pf *pf = &hns->pf;
1386 : :
1387 : : if (is_free) {
1388 [ # # ]: 0 : if (pf->used_umv_size > 0)
1389 : 0 : pf->used_umv_size--;
1390 : : } else
1391 : 0 : pf->used_umv_size++;
1392 : 0 : }
1393 : :
1394 : : static void
1395 : 0 : hns3_prepare_mac_addr(struct hns3_mac_vlan_tbl_entry_cmd *new_req,
1396 : : const uint8_t *addr, bool is_mc)
1397 : : {
1398 : : const unsigned char *mac_addr = addr;
1399 : 0 : uint32_t high_val = ((uint32_t)mac_addr[3] << 24) |
1400 : 0 : ((uint32_t)mac_addr[2] << 16) |
1401 : 0 : ((uint32_t)mac_addr[1] << 8) |
1402 : 0 : (uint32_t)mac_addr[0];
1403 : 0 : uint32_t low_val = ((uint32_t)mac_addr[5] << 8) | (uint32_t)mac_addr[4];
1404 : :
1405 : 0 : hns3_set_bit(new_req->flags, HNS3_MAC_VLAN_BIT0_EN_B, 1);
1406 [ # # ]: 0 : if (is_mc) {
1407 : 0 : hns3_set_bit(new_req->entry_type, HNS3_MAC_VLAN_BIT0_EN_B, 0);
1408 : 0 : hns3_set_bit(new_req->entry_type, HNS3_MAC_VLAN_BIT1_EN_B, 1);
1409 : 0 : hns3_set_bit(new_req->mc_mac_en, HNS3_MAC_VLAN_BIT0_EN_B, 1);
1410 : : }
1411 : :
1412 : 0 : new_req->mac_addr_hi32 = rte_cpu_to_le_32(high_val);
1413 : 0 : new_req->mac_addr_lo16 = rte_cpu_to_le_16(low_val & 0xffff);
1414 : 0 : }
1415 : :
1416 : : static int
1417 : 0 : hns3_get_mac_vlan_cmd_status(struct hns3_hw *hw, uint16_t cmdq_resp,
1418 : : uint8_t resp_code,
1419 : : enum hns3_mac_vlan_tbl_opcode op)
1420 : : {
1421 [ # # ]: 0 : if (cmdq_resp) {
1422 : 0 : hns3_err(hw, "cmdq execute failed for get_mac_vlan_cmd_status,status=%u",
1423 : : cmdq_resp);
1424 : 0 : return -EIO;
1425 : : }
1426 : :
1427 [ # # ]: 0 : if (op == HNS3_MAC_VLAN_ADD) {
1428 [ # # ]: 0 : if (resp_code == 0 || resp_code == 1) {
1429 : : return 0;
1430 [ # # ]: 0 : } else if (resp_code == HNS3_ADD_UC_OVERFLOW) {
1431 : 0 : hns3_err(hw, "add mac addr failed for uc_overflow");
1432 : 0 : return -ENOSPC;
1433 [ # # ]: 0 : } else if (resp_code == HNS3_ADD_MC_OVERFLOW) {
1434 : 0 : hns3_err(hw, "add mac addr failed for mc_overflow");
1435 : 0 : return -ENOSPC;
1436 : : }
1437 : :
1438 : 0 : hns3_err(hw, "add mac addr failed for undefined, code=%u",
1439 : : resp_code);
1440 : 0 : return -EIO;
1441 [ # # ]: 0 : } else if (op == HNS3_MAC_VLAN_REMOVE) {
1442 [ # # ]: 0 : if (resp_code == 0) {
1443 : : return 0;
1444 [ # # ]: 0 : } else if (resp_code == 1) {
1445 : 0 : hns3_dbg(hw, "remove mac addr failed for miss");
1446 : 0 : return -ENOENT;
1447 : : }
1448 : :
1449 : 0 : hns3_err(hw, "remove mac addr failed for undefined, code=%u",
1450 : : resp_code);
1451 : 0 : return -EIO;
1452 [ # # ]: 0 : } else if (op == HNS3_MAC_VLAN_LKUP) {
1453 [ # # ]: 0 : if (resp_code == 0) {
1454 : : return 0;
1455 [ # # ]: 0 : } else if (resp_code == 1) {
1456 : 0 : hns3_dbg(hw, "lookup mac addr failed for miss");
1457 : 0 : return -ENOENT;
1458 : : }
1459 : :
1460 : 0 : hns3_err(hw, "lookup mac addr failed for undefined, code=%u",
1461 : : resp_code);
1462 : 0 : return -EIO;
1463 : : }
1464 : :
1465 : 0 : hns3_err(hw, "unknown opcode for get_mac_vlan_cmd_status, opcode=%u",
1466 : : op);
1467 : :
1468 : 0 : return -EINVAL;
1469 : : }
1470 : :
1471 : : static int
1472 : 0 : hns3_lookup_mac_vlan_tbl(struct hns3_hw *hw,
1473 : : struct hns3_mac_vlan_tbl_entry_cmd *req,
1474 : : struct hns3_cmd_desc *desc, uint8_t desc_num)
1475 : : {
1476 : : uint8_t resp_code;
1477 : : uint16_t retval;
1478 : : int ret;
1479 : : int i;
1480 : :
1481 [ # # ]: 0 : if (desc_num == HNS3_MC_MAC_VLAN_OPS_DESC_NUM) {
1482 [ # # ]: 0 : for (i = 0; i < desc_num - 1; i++) {
1483 : 0 : hns3_cmd_setup_basic_desc(&desc[i],
1484 : : HNS3_OPC_MAC_VLAN_ADD, true);
1485 : 0 : desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
1486 [ # # ]: 0 : if (i == 0)
1487 : 0 : memcpy(desc[i].data, req,
1488 : : sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1489 : : }
1490 : 0 : hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_MAC_VLAN_ADD,
1491 : : true);
1492 : : } else {
1493 : 0 : hns3_cmd_setup_basic_desc(&desc[0], HNS3_OPC_MAC_VLAN_ADD,
1494 : : true);
1495 : 0 : memcpy(desc[0].data, req,
1496 : : sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1497 : : }
1498 : 0 : ret = hns3_cmd_send(hw, desc, desc_num);
1499 [ # # ]: 0 : if (ret) {
1500 : 0 : hns3_err(hw, "lookup mac addr failed for cmd_send, ret =%d.",
1501 : : ret);
1502 : 0 : return ret;
1503 : : }
1504 : 0 : resp_code = (rte_le_to_cpu_32(desc[0].data[0]) >> 8) & 0xff;
1505 : 0 : retval = rte_le_to_cpu_16(desc[0].retval);
1506 : :
1507 : 0 : return hns3_get_mac_vlan_cmd_status(hw, retval, resp_code,
1508 : : HNS3_MAC_VLAN_LKUP);
1509 : : }
1510 : :
1511 : : static int
1512 : 0 : hns3_add_mac_vlan_tbl(struct hns3_hw *hw,
1513 : : struct hns3_mac_vlan_tbl_entry_cmd *req,
1514 : : struct hns3_cmd_desc *desc, uint8_t desc_num)
1515 : : {
1516 : : uint8_t resp_code;
1517 : : uint16_t retval;
1518 : : int cfg_status;
1519 : : int ret;
1520 : : int i;
1521 : :
1522 [ # # ]: 0 : if (desc_num == HNS3_UC_MAC_VLAN_OPS_DESC_NUM) {
1523 : 0 : hns3_cmd_setup_basic_desc(desc, HNS3_OPC_MAC_VLAN_ADD, false);
1524 : 0 : memcpy(desc->data, req,
1525 : : sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1526 : 0 : ret = hns3_cmd_send(hw, desc, desc_num);
1527 : 0 : resp_code = (rte_le_to_cpu_32(desc->data[0]) >> 8) & 0xff;
1528 : 0 : retval = rte_le_to_cpu_16(desc->retval);
1529 : :
1530 : 0 : cfg_status = hns3_get_mac_vlan_cmd_status(hw, retval, resp_code,
1531 : : HNS3_MAC_VLAN_ADD);
1532 : : } else {
1533 [ # # ]: 0 : for (i = 0; i < desc_num; i++) {
1534 : 0 : hns3_cmd_reuse_desc(&desc[i], false);
1535 [ # # ]: 0 : if (i == desc_num - 1)
1536 : 0 : desc[i].flag &=
1537 : : rte_cpu_to_le_16(~HNS3_CMD_FLAG_NEXT);
1538 : : else
1539 : 0 : desc[i].flag |=
1540 : : rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
1541 : : }
1542 : 0 : memcpy(desc[0].data, req,
1543 : : sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1544 : 0 : desc[0].retval = 0;
1545 : 0 : ret = hns3_cmd_send(hw, desc, desc_num);
1546 : 0 : resp_code = (rte_le_to_cpu_32(desc[0].data[0]) >> 8) & 0xff;
1547 : 0 : retval = rte_le_to_cpu_16(desc[0].retval);
1548 : :
1549 : 0 : cfg_status = hns3_get_mac_vlan_cmd_status(hw, retval, resp_code,
1550 : : HNS3_MAC_VLAN_ADD);
1551 : : }
1552 : :
1553 [ # # ]: 0 : if (ret) {
1554 : 0 : hns3_err(hw, "add mac addr failed for cmd_send, ret =%d", ret);
1555 : 0 : return ret;
1556 : : }
1557 : :
1558 : : return cfg_status;
1559 : : }
1560 : :
1561 : : static int
1562 : 0 : hns3_remove_mac_vlan_tbl(struct hns3_hw *hw,
1563 : : struct hns3_mac_vlan_tbl_entry_cmd *req)
1564 : : {
1565 : : struct hns3_cmd_desc desc;
1566 : : uint8_t resp_code;
1567 : : uint16_t retval;
1568 : : int ret;
1569 : :
1570 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_VLAN_REMOVE, false);
1571 : :
1572 : : memcpy(desc.data, req, sizeof(struct hns3_mac_vlan_tbl_entry_cmd));
1573 : :
1574 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
1575 [ # # ]: 0 : if (ret) {
1576 : 0 : hns3_err(hw, "del mac addr failed for cmd_send, ret =%d", ret);
1577 : 0 : return ret;
1578 : : }
1579 : 0 : resp_code = (rte_le_to_cpu_32(desc.data[0]) >> 8) & 0xff;
1580 : 0 : retval = rte_le_to_cpu_16(desc.retval);
1581 : :
1582 : 0 : return hns3_get_mac_vlan_cmd_status(hw, retval, resp_code,
1583 : : HNS3_MAC_VLAN_REMOVE);
1584 : : }
1585 : :
1586 : : static int
1587 [ # # ]: 0 : hns3_add_uc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1588 : : {
1589 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1590 : : struct hns3_mac_vlan_tbl_entry_cmd req;
1591 : : struct hns3_pf *pf = &hns->pf;
1592 : : struct hns3_cmd_desc desc;
1593 : : char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1594 : : uint16_t egress_port = 0;
1595 : : uint8_t vf_id;
1596 : : int ret;
1597 : :
1598 : : /* check if mac addr is valid */
1599 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
1600 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1601 : : mac_addr);
1602 : 0 : hns3_err(hw, "Add unicast mac addr err! addr(%s) invalid",
1603 : : mac_str);
1604 : 0 : return -EINVAL;
1605 : : }
1606 : :
1607 : : memset(&req, 0, sizeof(req));
1608 : :
1609 : : /*
1610 : : * In current version VF is not supported when PF is driven by DPDK
1611 : : * driver, just need to configure parameters for PF vport.
1612 : : */
1613 : : vf_id = HNS3_PF_FUNC_ID;
1614 : : hns3_set_field(egress_port, HNS3_MAC_EPORT_VFID_M,
1615 : : HNS3_MAC_EPORT_VFID_S, vf_id);
1616 : :
1617 : : req.egress_port = rte_cpu_to_le_16(egress_port);
1618 : :
1619 : 0 : hns3_prepare_mac_addr(&req, mac_addr->addr_bytes, false);
1620 : :
1621 : : /*
1622 : : * Lookup the mac address in the mac_vlan table, and add
1623 : : * it if the entry is inexistent. Repeated unicast entry
1624 : : * is not allowed in the mac vlan table.
1625 : : */
1626 : 0 : ret = hns3_lookup_mac_vlan_tbl(hw, &req, &desc,
1627 : : HNS3_UC_MAC_VLAN_OPS_DESC_NUM);
1628 [ # # ]: 0 : if (ret == -ENOENT) {
1629 [ # # ]: 0 : if (!hns3_is_umv_space_full(hw)) {
1630 : 0 : ret = hns3_add_mac_vlan_tbl(hw, &req, &desc,
1631 : : HNS3_UC_MAC_VLAN_OPS_DESC_NUM);
1632 [ # # ]: 0 : if (!ret)
1633 : : hns3_update_umv_space(hw, false);
1634 : 0 : return ret;
1635 : : }
1636 : :
1637 : 0 : hns3_err(hw, "UC MAC table full(%u)", pf->used_umv_size);
1638 : :
1639 : 0 : return -ENOSPC;
1640 : : }
1641 : :
1642 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, mac_addr);
1643 : :
1644 : : /* check if we just hit the duplicate */
1645 [ # # ]: 0 : if (ret == 0) {
1646 : 0 : hns3_dbg(hw, "mac addr(%s) has been in the MAC table", mac_str);
1647 : 0 : return 0;
1648 : : }
1649 : :
1650 : 0 : hns3_err(hw, "PF failed to add unicast entry(%s) in the MAC table",
1651 : : mac_str);
1652 : :
1653 : 0 : return ret;
1654 : : }
1655 : :
1656 : : static int
1657 [ # # ]: 0 : hns3_remove_uc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1658 : : {
1659 : : struct hns3_mac_vlan_tbl_entry_cmd req;
1660 : : char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1661 : : int ret;
1662 : :
1663 : : /* check if mac addr is valid */
1664 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
1665 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1666 : : mac_addr);
1667 : 0 : hns3_err(hw, "remove unicast mac addr err! addr(%s) invalid",
1668 : : mac_str);
1669 : 0 : return -EINVAL;
1670 : : }
1671 : :
1672 : : memset(&req, 0, sizeof(req));
1673 : : hns3_set_bit(req.entry_type, HNS3_MAC_VLAN_BIT0_EN_B, 0);
1674 : 0 : hns3_prepare_mac_addr(&req, mac_addr->addr_bytes, false);
1675 : 0 : ret = hns3_remove_mac_vlan_tbl(hw, &req);
1676 [ # # ]: 0 : if (ret == -ENOENT) /* mac addr isn't existent in the mac vlan table. */
1677 : : return 0;
1678 [ # # ]: 0 : else if (ret == 0)
1679 : : hns3_update_umv_space(hw, true);
1680 : :
1681 : : return ret;
1682 : : }
1683 : :
1684 : : static int
1685 : 0 : hns3_set_default_mac_addr(struct rte_eth_dev *dev,
1686 : : struct rte_ether_addr *mac_addr)
1687 : : {
1688 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1689 : : struct rte_ether_addr *oaddr;
1690 : : char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1691 : : int ret, ret_val;
1692 : :
1693 : 0 : rte_spinlock_lock(&hw->lock);
1694 : 0 : oaddr = (struct rte_ether_addr *)hw->mac.mac_addr;
1695 : 0 : ret = hw->ops.del_uc_mac_addr(hw, oaddr);
1696 [ # # ]: 0 : if (ret) {
1697 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1698 : : oaddr);
1699 : 0 : hns3_warn(hw, "Remove old uc mac address(%s) fail: %d",
1700 : : mac_str, ret);
1701 : :
1702 : : rte_spinlock_unlock(&hw->lock);
1703 : 0 : return ret;
1704 : : }
1705 : :
1706 : 0 : ret = hw->ops.add_uc_mac_addr(hw, mac_addr);
1707 [ # # ]: 0 : if (ret) {
1708 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1709 : : mac_addr);
1710 : 0 : hns3_err(hw, "Failed to set mac addr(%s): %d", mac_str, ret);
1711 : 0 : goto err_add_uc_addr;
1712 : : }
1713 : :
1714 : 0 : ret = hns3_pause_addr_cfg(hw, mac_addr->addr_bytes);
1715 [ # # ]: 0 : if (ret) {
1716 : 0 : hns3_err(hw, "Failed to configure mac pause address: %d", ret);
1717 : 0 : goto err_pause_addr_cfg;
1718 : : }
1719 : :
1720 : : rte_ether_addr_copy(mac_addr,
1721 : : (struct rte_ether_addr *)hw->mac.mac_addr);
1722 : : rte_spinlock_unlock(&hw->lock);
1723 : :
1724 : 0 : return 0;
1725 : :
1726 : : err_pause_addr_cfg:
1727 : 0 : ret_val = hw->ops.del_uc_mac_addr(hw, mac_addr);
1728 [ # # ]: 0 : if (ret_val) {
1729 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1730 : : mac_addr);
1731 : 0 : hns3_warn(hw,
1732 : : "Failed to roll back to del set mac addr(%s): %d",
1733 : : mac_str, ret_val);
1734 : : }
1735 : :
1736 : 0 : err_add_uc_addr:
1737 : 0 : ret_val = hw->ops.add_uc_mac_addr(hw, oaddr);
1738 [ # # ]: 0 : if (ret_val) {
1739 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, oaddr);
1740 : 0 : hns3_warn(hw, "Failed to restore old uc mac addr(%s): %d",
1741 : : mac_str, ret_val);
1742 : : }
1743 : : rte_spinlock_unlock(&hw->lock);
1744 : :
1745 : 0 : return ret;
1746 : : }
1747 : :
1748 : : static void
1749 : 0 : hns3_update_desc_vfid(struct hns3_cmd_desc *desc, uint8_t vfid, bool clr)
1750 : : {
1751 : : #define HNS3_VF_NUM_IN_FIRST_DESC 192
1752 : : uint8_t word_num;
1753 : : uint8_t bit_num;
1754 : :
1755 [ # # ]: 0 : if (vfid < HNS3_VF_NUM_IN_FIRST_DESC) {
1756 : 0 : word_num = vfid / 32;
1757 : 0 : bit_num = vfid % 32;
1758 [ # # ]: 0 : if (clr)
1759 : 0 : desc[1].data[word_num] &=
1760 : 0 : rte_cpu_to_le_32(~(1UL << bit_num));
1761 : : else
1762 : 0 : desc[1].data[word_num] |=
1763 : 0 : rte_cpu_to_le_32(1UL << bit_num);
1764 : : } else {
1765 : 0 : word_num = (vfid - HNS3_VF_NUM_IN_FIRST_DESC) / 32;
1766 : 0 : bit_num = vfid % 32;
1767 [ # # ]: 0 : if (clr)
1768 : 0 : desc[2].data[word_num] &=
1769 : 0 : rte_cpu_to_le_32(~(1UL << bit_num));
1770 : : else
1771 : 0 : desc[2].data[word_num] |=
1772 : 0 : rte_cpu_to_le_32(1UL << bit_num);
1773 : : }
1774 : 0 : }
1775 : :
1776 : : static int
1777 [ # # ]: 0 : hns3_add_mc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1778 : : {
1779 : : struct hns3_cmd_desc desc[HNS3_MC_MAC_VLAN_OPS_DESC_NUM];
1780 : : struct hns3_mac_vlan_tbl_entry_cmd req;
1781 : : char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1782 : : uint8_t vf_id;
1783 : : int ret;
1784 : : int idx;
1785 : :
1786 : : /* Check if mac addr is valid */
1787 [ # # ]: 0 : if (!rte_is_multicast_ether_addr(mac_addr)) {
1788 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1789 : : mac_addr);
1790 : 0 : hns3_err(hw, "failed to add mc mac addr, addr(%s) invalid",
1791 : : mac_str);
1792 : 0 : return -EINVAL;
1793 : : }
1794 : :
1795 : : memset(&req, 0, sizeof(req));
1796 : : hns3_set_bit(req.entry_type, HNS3_MAC_VLAN_BIT0_EN_B, 0);
1797 : 0 : hns3_prepare_mac_addr(&req, mac_addr->addr_bytes, true);
1798 : 0 : ret = hns3_lookup_mac_vlan_tbl(hw, &req, desc,
1799 : : HNS3_MC_MAC_VLAN_OPS_DESC_NUM);
1800 [ # # ]: 0 : if (ret) {
1801 : : /* This mac addr do not exist, add new entry for it */
1802 [ # # ]: 0 : for (idx = 0; idx < HNS3_MC_MAC_VLAN_OPS_DESC_NUM; idx++)
1803 : 0 : memset(desc[idx].data, 0, sizeof(desc[idx].data));
1804 : : }
1805 : :
1806 : : /*
1807 : : * In current version VF is not supported when PF is driven by DPDK
1808 : : * driver, just need to configure parameters for PF vport.
1809 : : */
1810 : : vf_id = HNS3_PF_FUNC_ID;
1811 : 0 : hns3_update_desc_vfid(desc, vf_id, false);
1812 : 0 : ret = hns3_add_mac_vlan_tbl(hw, &req, desc,
1813 : : HNS3_MC_MAC_VLAN_OPS_DESC_NUM);
1814 [ # # ]: 0 : if (ret) {
1815 [ # # ]: 0 : if (ret == -ENOSPC)
1816 : 0 : hns3_err(hw, "mc mac vlan table is full");
1817 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1818 : : mac_addr);
1819 : 0 : hns3_err(hw, "failed to add mc mac addr(%s): %d", mac_str, ret);
1820 : : }
1821 : :
1822 : : return ret;
1823 : : }
1824 : :
1825 : : static int
1826 [ # # ]: 0 : hns3_remove_mc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
1827 : : {
1828 : : struct hns3_mac_vlan_tbl_entry_cmd req;
1829 : : struct hns3_cmd_desc desc[3];
1830 : : char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
1831 : : uint8_t vf_id;
1832 : : int ret;
1833 : :
1834 : : /* Check if mac addr is valid */
1835 [ # # ]: 0 : if (!rte_is_multicast_ether_addr(mac_addr)) {
1836 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1837 : : mac_addr);
1838 : 0 : hns3_err(hw, "Failed to rm mc mac addr, addr(%s) invalid",
1839 : : mac_str);
1840 : 0 : return -EINVAL;
1841 : : }
1842 : :
1843 : : memset(&req, 0, sizeof(req));
1844 : : hns3_set_bit(req.entry_type, HNS3_MAC_VLAN_BIT0_EN_B, 0);
1845 : 0 : hns3_prepare_mac_addr(&req, mac_addr->addr_bytes, true);
1846 : 0 : ret = hns3_lookup_mac_vlan_tbl(hw, &req, desc,
1847 : : HNS3_MC_MAC_VLAN_OPS_DESC_NUM);
1848 [ # # ]: 0 : if (ret == 0) {
1849 : : /*
1850 : : * This mac addr exist, remove this handle's VFID for it.
1851 : : * In current version VF is not supported when PF is driven by
1852 : : * DPDK driver, just need to configure parameters for PF vport.
1853 : : */
1854 : : vf_id = HNS3_PF_FUNC_ID;
1855 : 0 : hns3_update_desc_vfid(desc, vf_id, true);
1856 : :
1857 : : /* All the vfid is zero, so need to delete this entry */
1858 : 0 : ret = hns3_remove_mac_vlan_tbl(hw, &req);
1859 [ # # ]: 0 : } else if (ret == -ENOENT) {
1860 : : /* This mac addr doesn't exist. */
1861 : : return 0;
1862 : : }
1863 : :
1864 [ # # ]: 0 : if (ret) {
1865 : 0 : hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
1866 : : mac_addr);
1867 : 0 : hns3_err(hw, "Failed to rm mc mac addr(%s): %d", mac_str, ret);
1868 : : }
1869 : :
1870 : : return ret;
1871 : : }
1872 : :
1873 : : static int
1874 : 0 : hns3_bind_ring_with_vector(struct hns3_hw *hw, uint16_t vector_id, bool en,
1875 : : enum hns3_ring_type queue_type, uint16_t queue_id)
1876 : : {
1877 : : struct hns3_cmd_desc desc;
1878 : : struct hns3_ctrl_vector_chain_cmd *req =
1879 : : (struct hns3_ctrl_vector_chain_cmd *)desc.data;
1880 : : enum hns3_opcode_type op;
1881 : : uint16_t tqp_type_and_id = 0;
1882 : : uint16_t type;
1883 : : uint16_t gl;
1884 : : int ret;
1885 : :
1886 [ # # ]: 0 : op = en ? HNS3_OPC_ADD_RING_TO_VECTOR : HNS3_OPC_DEL_RING_TO_VECTOR;
1887 : 0 : hns3_cmd_setup_basic_desc(&desc, op, false);
1888 : 0 : req->int_vector_id = hns3_get_field(vector_id, HNS3_TQP_INT_ID_L_M,
1889 : : HNS3_TQP_INT_ID_L_S);
1890 : 0 : req->int_vector_id_h = hns3_get_field(vector_id, HNS3_TQP_INT_ID_H_M,
1891 : : HNS3_TQP_INT_ID_H_S);
1892 : :
1893 [ # # ]: 0 : if (queue_type == HNS3_RING_TYPE_RX)
1894 : : gl = HNS3_RING_GL_RX;
1895 : : else
1896 : : gl = HNS3_RING_GL_TX;
1897 : :
1898 : 0 : type = queue_type;
1899 : :
1900 : 0 : hns3_set_field(tqp_type_and_id, HNS3_INT_TYPE_M, HNS3_INT_TYPE_S,
1901 : : type);
1902 : 0 : hns3_set_field(tqp_type_and_id, HNS3_TQP_ID_M, HNS3_TQP_ID_S, queue_id);
1903 : 0 : hns3_set_field(tqp_type_and_id, HNS3_INT_GL_IDX_M, HNS3_INT_GL_IDX_S,
1904 : : gl);
1905 : 0 : req->tqp_type_and_id[0] = rte_cpu_to_le_16(tqp_type_and_id);
1906 : 0 : req->int_cause_num = 1;
1907 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
1908 [ # # ]: 0 : if (ret) {
1909 [ # # ]: 0 : hns3_err(hw, "%s TQP %u fail, vector_id = %u, ret = %d.",
1910 : : en ? "Map" : "Unmap", queue_id, vector_id, ret);
1911 : 0 : return ret;
1912 : : }
1913 : :
1914 : : return 0;
1915 : : }
1916 : :
1917 : : static int
1918 : 0 : hns3_setup_dcb(struct rte_eth_dev *dev)
1919 : : {
1920 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1921 : : struct hns3_hw *hw = &hns->hw;
1922 : : int ret;
1923 : :
1924 [ # # ]: 0 : if (!hns3_dev_get_support(hw, DCB)) {
1925 : 0 : hns3_err(hw, "this port does not support dcb configurations.");
1926 : 0 : return -EOPNOTSUPP;
1927 : : }
1928 : :
1929 [ # # ]: 0 : if (hw->current_fc_status == HNS3_FC_STATUS_MAC_PAUSE) {
1930 : 0 : hns3_err(hw, "MAC pause enabled, cannot config dcb info.");
1931 : 0 : return -EOPNOTSUPP;
1932 : : }
1933 : :
1934 : 0 : ret = hns3_dcb_configure(hns);
1935 [ # # ]: 0 : if (ret)
1936 : 0 : hns3_err(hw, "failed to config dcb: %d", ret);
1937 : :
1938 : : return ret;
1939 : : }
1940 : :
1941 : : static int
1942 : 0 : hns3_check_link_speed(struct hns3_hw *hw, uint32_t link_speeds)
1943 : : {
1944 : : int ret;
1945 : :
1946 : : /*
1947 : : * Some hardware doesn't support auto-negotiation, but users may not
1948 : : * configure link_speeds (default 0), which means auto-negotiation.
1949 : : * In this case, it should return success.
1950 : : */
1951 [ # # ]: 0 : if (link_speeds == RTE_ETH_LINK_SPEED_AUTONEG &&
1952 [ # # ]: 0 : hw->mac.support_autoneg == 0)
1953 : : return 0;
1954 : :
1955 [ # # ]: 0 : if (link_speeds != RTE_ETH_LINK_SPEED_AUTONEG) {
1956 : 0 : ret = hns3_check_port_speed(hw, link_speeds);
1957 [ # # ]: 0 : if (ret)
1958 : 0 : return ret;
1959 : : }
1960 : :
1961 : : return 0;
1962 : : }
1963 : :
1964 : : static int
1965 : 0 : hns3_check_dev_conf(struct rte_eth_dev *dev)
1966 : : {
1967 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1968 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
1969 : : int ret;
1970 : :
1971 : 0 : ret = hns3_check_dev_mq_mode(dev);
1972 [ # # ]: 0 : if (ret)
1973 : : return ret;
1974 : :
1975 : 0 : return hns3_check_link_speed(hw, conf->link_speeds);
1976 : : }
1977 : :
1978 : : static int
1979 : 0 : hns3_dev_configure(struct rte_eth_dev *dev)
1980 : : {
1981 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1982 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
1983 : 0 : enum rte_eth_rx_mq_mode mq_mode = conf->rxmode.mq_mode;
1984 : 0 : struct hns3_hw *hw = &hns->hw;
1985 : 0 : uint16_t nb_rx_q = dev->data->nb_rx_queues;
1986 : 0 : uint16_t nb_tx_q = dev->data->nb_tx_queues;
1987 : : struct rte_eth_rss_conf rss_conf;
1988 : : bool gro_en;
1989 : : int ret;
1990 : :
1991 : 0 : hw->cfg_max_queues = RTE_MAX(nb_rx_q, nb_tx_q);
1992 : :
1993 : : /*
1994 : : * Some versions of hardware network engine does not support
1995 : : * individually enable/disable/reset the Tx or Rx queue. These devices
1996 : : * must enable/disable/reset Tx and Rx queues at the same time. When the
1997 : : * numbers of Tx queues allocated by upper applications are not equal to
1998 : : * the numbers of Rx queues, driver needs to setup fake Tx or Rx queues
1999 : : * to adjust numbers of Tx/Rx queues. otherwise, network engine can not
2000 : : * work as usual. But these fake queues are imperceptible, and can not
2001 : : * be used by upper applications.
2002 : : */
2003 : 0 : ret = hns3_set_fake_rx_or_tx_queues(dev, nb_rx_q, nb_tx_q);
2004 [ # # ]: 0 : if (ret) {
2005 : 0 : hns3_err(hw, "fail to set Rx/Tx fake queues, ret = %d.", ret);
2006 : 0 : hw->cfg_max_queues = 0;
2007 : 0 : return ret;
2008 : : }
2009 : :
2010 : 0 : hw->adapter_state = HNS3_NIC_CONFIGURING;
2011 : 0 : ret = hns3_check_dev_conf(dev);
2012 [ # # ]: 0 : if (ret)
2013 : 0 : goto cfg_err;
2014 : :
2015 [ # # ]: 0 : if ((uint32_t)mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
2016 : 0 : ret = hns3_setup_dcb(dev);
2017 [ # # ]: 0 : if (ret)
2018 : 0 : goto cfg_err;
2019 : : }
2020 : :
2021 [ # # ]: 0 : if ((uint32_t)mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) {
2022 : 0 : conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
2023 : 0 : rss_conf = conf->rx_adv_conf.rss_conf;
2024 : 0 : ret = hns3_dev_rss_hash_update(dev, &rss_conf);
2025 [ # # ]: 0 : if (ret)
2026 : 0 : goto cfg_err;
2027 : : }
2028 : :
2029 : 0 : ret = hns3_dev_mtu_set(dev, conf->rxmode.mtu);
2030 [ # # ]: 0 : if (ret != 0)
2031 : 0 : goto cfg_err;
2032 : :
2033 : 0 : ret = hns3_mbuf_dyn_rx_timestamp_register(dev, conf);
2034 [ # # ]: 0 : if (ret)
2035 : 0 : goto cfg_err;
2036 : :
2037 : 0 : ret = hns3_dev_configure_vlan(dev);
2038 [ # # ]: 0 : if (ret)
2039 : 0 : goto cfg_err;
2040 : :
2041 : : /* config hardware GRO */
2042 : 0 : gro_en = conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO ? true : false;
2043 : 0 : ret = hns3_config_gro(hw, gro_en);
2044 [ # # ]: 0 : if (ret)
2045 : 0 : goto cfg_err;
2046 : :
2047 : 0 : hns3_init_rx_ptype_tble(dev);
2048 : 0 : hw->adapter_state = HNS3_NIC_CONFIGURED;
2049 : :
2050 : 0 : return 0;
2051 : :
2052 : 0 : cfg_err:
2053 : 0 : hw->cfg_max_queues = 0;
2054 : 0 : (void)hns3_set_fake_rx_or_tx_queues(dev, 0, 0);
2055 : 0 : hw->adapter_state = HNS3_NIC_INITIALIZED;
2056 : :
2057 : 0 : return ret;
2058 : : }
2059 : :
2060 : : static int
2061 : 0 : hns3_set_mac_mtu(struct hns3_hw *hw, uint16_t new_mps)
2062 : : {
2063 : : struct hns3_config_max_frm_size_cmd *req;
2064 : : struct hns3_cmd_desc desc;
2065 : :
2066 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_MAX_FRM_SIZE, false);
2067 : :
2068 : : req = (struct hns3_config_max_frm_size_cmd *)desc.data;
2069 : 0 : req->max_frm_size = rte_cpu_to_le_16(new_mps);
2070 : 0 : req->min_frm_size = RTE_ETHER_MIN_LEN;
2071 : :
2072 : 0 : return hns3_cmd_send(hw, &desc, 1);
2073 : : }
2074 : :
2075 : : static int
2076 : 0 : hns3_config_mtu(struct hns3_hw *hw, uint16_t mps)
2077 : : {
2078 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2079 : : int err;
2080 : : int ret;
2081 : :
2082 : 0 : ret = hns3_set_mac_mtu(hw, mps);
2083 [ # # ]: 0 : if (ret) {
2084 : 0 : hns3_err(hw, "failed to set mtu, ret = %d", ret);
2085 : 0 : return ret;
2086 : : }
2087 : :
2088 : 0 : ret = hns3_buffer_alloc(hw);
2089 [ # # ]: 0 : if (ret) {
2090 : 0 : hns3_err(hw, "failed to allocate buffer, ret = %d", ret);
2091 : 0 : goto rollback;
2092 : : }
2093 : :
2094 : 0 : hns->pf.mps = mps;
2095 : :
2096 : 0 : return 0;
2097 : :
2098 : : rollback:
2099 : 0 : err = hns3_set_mac_mtu(hw, hns->pf.mps);
2100 [ # # ]: 0 : if (err)
2101 : 0 : hns3_err(hw, "fail to rollback MTU, err = %d", err);
2102 : :
2103 : : return ret;
2104 : : }
2105 : :
2106 : : static int
2107 : 0 : hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
2108 : : {
2109 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
2110 : 0 : uint32_t frame_size = mtu + HNS3_ETH_OVERHEAD;
2111 : 0 : struct hns3_hw *hw = &hns->hw;
2112 : : int ret;
2113 : :
2114 [ # # ]: 0 : if (dev->data->dev_started) {
2115 : 0 : hns3_err(hw, "Failed to set mtu, port %u must be stopped "
2116 : : "before configuration", dev->data->port_id);
2117 : 0 : return -EBUSY;
2118 : : }
2119 : :
2120 : 0 : rte_spinlock_lock(&hw->lock);
2121 : 0 : frame_size = RTE_MAX(frame_size, HNS3_DEFAULT_FRAME_LEN);
2122 : :
2123 : : /*
2124 : : * Maximum value of frame_size is HNS3_MAX_FRAME_LEN, so it can safely
2125 : : * assign to "uint16_t" type variable.
2126 : : */
2127 : 0 : ret = hns3_config_mtu(hw, (uint16_t)frame_size);
2128 [ # # ]: 0 : if (ret) {
2129 : : rte_spinlock_unlock(&hw->lock);
2130 : 0 : hns3_err(hw, "Failed to set mtu, port %u mtu %u: %d",
2131 : : dev->data->port_id, mtu, ret);
2132 : 0 : return ret;
2133 : : }
2134 : :
2135 : : rte_spinlock_unlock(&hw->lock);
2136 : :
2137 : 0 : return 0;
2138 : : }
2139 : :
2140 : : static uint32_t
2141 : 0 : hns3_get_copper_port_speed_capa(uint32_t supported_speed)
2142 : : {
2143 : : uint32_t speed_capa = 0;
2144 : :
2145 [ # # ]: 0 : if (supported_speed & HNS3_PHY_LINK_SPEED_10M_HD_BIT)
2146 : : speed_capa |= RTE_ETH_LINK_SPEED_10M_HD;
2147 [ # # ]: 0 : if (supported_speed & HNS3_PHY_LINK_SPEED_10M_BIT)
2148 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_10M;
2149 [ # # ]: 0 : if (supported_speed & HNS3_PHY_LINK_SPEED_100M_HD_BIT)
2150 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_100M_HD;
2151 [ # # ]: 0 : if (supported_speed & HNS3_PHY_LINK_SPEED_100M_BIT)
2152 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_100M;
2153 [ # # ]: 0 : if (supported_speed & HNS3_PHY_LINK_SPEED_1000M_BIT)
2154 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_1G;
2155 : :
2156 : 0 : return speed_capa;
2157 : : }
2158 : :
2159 : : static uint32_t
2160 : 0 : hns3_get_firber_port_speed_capa(uint32_t supported_speed)
2161 : : {
2162 : : uint32_t speed_capa = 0;
2163 : :
2164 [ # # ]: 0 : if (supported_speed & HNS3_FIBER_LINK_SPEED_1G_BIT)
2165 : : speed_capa |= RTE_ETH_LINK_SPEED_1G;
2166 [ # # ]: 0 : if (supported_speed & HNS3_FIBER_LINK_SPEED_10G_BIT)
2167 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_10G;
2168 [ # # ]: 0 : if (supported_speed & HNS3_FIBER_LINK_SPEED_25G_BIT)
2169 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_25G;
2170 [ # # ]: 0 : if (supported_speed & HNS3_FIBER_LINK_SPEED_40G_BIT)
2171 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_40G;
2172 [ # # ]: 0 : if (supported_speed & HNS3_FIBER_LINK_SPEED_50G_BIT)
2173 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_50G;
2174 [ # # ]: 0 : if (supported_speed & HNS3_FIBER_LINK_SPEED_100G_BIT)
2175 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_100G;
2176 [ # # ]: 0 : if (supported_speed & HNS3_FIBER_LINK_SPEED_200G_BIT)
2177 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_200G;
2178 : :
2179 : 0 : return speed_capa;
2180 : : }
2181 : :
2182 : : uint32_t
2183 : 0 : hns3_get_speed_capa(struct hns3_hw *hw)
2184 : : {
2185 : : struct hns3_mac *mac = &hw->mac;
2186 : : uint32_t speed_capa;
2187 : :
2188 [ # # ]: 0 : if (mac->media_type == HNS3_MEDIA_TYPE_COPPER)
2189 : : speed_capa =
2190 : 0 : hns3_get_copper_port_speed_capa(mac->supported_speed);
2191 : : else
2192 : : speed_capa =
2193 : 0 : hns3_get_firber_port_speed_capa(mac->supported_speed);
2194 : :
2195 [ # # ]: 0 : if (mac->support_autoneg == 0)
2196 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_FIXED;
2197 : :
2198 : 0 : return speed_capa;
2199 : : }
2200 : :
2201 : : static int
2202 : 0 : hns3_update_port_link_info(struct rte_eth_dev *eth_dev)
2203 : : {
2204 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2205 : : int ret;
2206 : :
2207 : 0 : (void)hns3_update_link_status(hw);
2208 : :
2209 : 0 : ret = hns3_update_link_info(eth_dev);
2210 [ # # ]: 0 : if (ret)
2211 : 0 : hw->mac.link_status = RTE_ETH_LINK_DOWN;
2212 : :
2213 : 0 : return ret;
2214 : : }
2215 : :
2216 : : static void
2217 : 0 : hns3_setup_linkstatus(struct rte_eth_dev *eth_dev,
2218 : : struct rte_eth_link *new_link)
2219 : : {
2220 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2221 : : struct hns3_mac *mac = &hw->mac;
2222 : :
2223 [ # # ]: 0 : switch (mac->link_speed) {
2224 : 0 : case RTE_ETH_SPEED_NUM_10M:
2225 : : case RTE_ETH_SPEED_NUM_100M:
2226 : : case RTE_ETH_SPEED_NUM_1G:
2227 : : case RTE_ETH_SPEED_NUM_10G:
2228 : : case RTE_ETH_SPEED_NUM_25G:
2229 : : case RTE_ETH_SPEED_NUM_40G:
2230 : : case RTE_ETH_SPEED_NUM_50G:
2231 : : case RTE_ETH_SPEED_NUM_100G:
2232 : : case RTE_ETH_SPEED_NUM_200G:
2233 [ # # ]: 0 : if (mac->link_status)
2234 : 0 : new_link->link_speed = mac->link_speed;
2235 : : break;
2236 : 0 : default:
2237 [ # # ]: 0 : if (mac->link_status)
2238 : 0 : new_link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
2239 : : break;
2240 : : }
2241 : :
2242 [ # # ]: 0 : if (!mac->link_status)
2243 : 0 : new_link->link_speed = RTE_ETH_SPEED_NUM_NONE;
2244 : :
2245 : 0 : new_link->link_duplex = mac->link_duplex;
2246 : 0 : new_link->link_status = mac->link_status ? RTE_ETH_LINK_UP : RTE_ETH_LINK_DOWN;
2247 : 0 : new_link->link_autoneg = mac->link_autoneg;
2248 : 0 : }
2249 : :
2250 : : static int
2251 : 0 : hns3_dev_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete)
2252 : : {
2253 : : #define HNS3_LINK_CHECK_INTERVAL 100 /* 100ms */
2254 : : #define HNS3_MAX_LINK_CHECK_TIMES 20 /* 2s (100 * 20ms) in total */
2255 : :
2256 [ # # ]: 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2257 : : uint32_t retry_cnt = HNS3_MAX_LINK_CHECK_TIMES;
2258 : : struct hns3_mac *mac = &hw->mac;
2259 : : struct rte_eth_link new_link;
2260 : : int ret;
2261 : :
2262 : : memset(&new_link, 0, sizeof(new_link));
2263 : : /* When port is stopped, report link down. */
2264 [ # # ]: 0 : if (eth_dev->data->dev_started == 0) {
2265 : 0 : new_link.link_autoneg = mac->link_autoneg;
2266 : 0 : new_link.link_duplex = mac->link_duplex;
2267 : : new_link.link_speed = RTE_ETH_SPEED_NUM_NONE;
2268 : : new_link.link_status = RTE_ETH_LINK_DOWN;
2269 : 0 : goto out;
2270 : : }
2271 : :
2272 : : do {
2273 : 0 : ret = hns3_update_port_link_info(eth_dev);
2274 [ # # ]: 0 : if (ret) {
2275 : 0 : hns3_err(hw, "failed to get port link info, ret = %d.",
2276 : : ret);
2277 : 0 : break;
2278 : : }
2279 : :
2280 [ # # # # ]: 0 : if (!wait_to_complete || mac->link_status == RTE_ETH_LINK_UP)
2281 : : break;
2282 : :
2283 : : rte_delay_ms(HNS3_LINK_CHECK_INTERVAL);
2284 [ # # ]: 0 : } while (retry_cnt--);
2285 : :
2286 : 0 : hns3_setup_linkstatus(eth_dev, &new_link);
2287 : :
2288 [ # # ]: 0 : out:
2289 : 0 : return rte_eth_linkstatus_set(eth_dev, &new_link);
2290 : : }
2291 : :
2292 : : static int
2293 : 0 : hns3_dev_set_link_up(struct rte_eth_dev *dev)
2294 : : {
2295 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2296 : : int ret;
2297 : :
2298 : : /*
2299 : : * The "tx_pkt_burst" will be restored. But the secondary process does
2300 : : * not support the mechanism for notifying the primary process.
2301 : : */
2302 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2303 : 0 : hns3_err(hw, "secondary process does not support to set link up.");
2304 : 0 : return -ENOTSUP;
2305 : : }
2306 : :
2307 : : /*
2308 : : * If device isn't started Rx/Tx function is still disabled, setting
2309 : : * link up is not allowed. But it is probably better to return success
2310 : : * to reduce the impact on the upper layer.
2311 : : */
2312 [ # # ]: 0 : if (hw->adapter_state != HNS3_NIC_STARTED) {
2313 : 0 : hns3_info(hw, "device isn't started, can't set link up.");
2314 : 0 : return 0;
2315 : : }
2316 : :
2317 [ # # ]: 0 : if (!hw->set_link_down)
2318 : : return 0;
2319 : :
2320 : 0 : rte_spinlock_lock(&hw->lock);
2321 : 0 : ret = hns3_cfg_mac_mode(hw, true);
2322 [ # # ]: 0 : if (ret) {
2323 : : rte_spinlock_unlock(&hw->lock);
2324 : 0 : hns3_err(hw, "failed to set link up, ret = %d", ret);
2325 : 0 : return ret;
2326 : : }
2327 : :
2328 : 0 : hw->set_link_down = false;
2329 : 0 : hns3_start_tx_datapath(dev);
2330 : : rte_spinlock_unlock(&hw->lock);
2331 : :
2332 : 0 : return 0;
2333 : : }
2334 : :
2335 : : static int
2336 : 0 : hns3_dev_set_link_down(struct rte_eth_dev *dev)
2337 : : {
2338 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2339 : : int ret;
2340 : :
2341 : : /*
2342 : : * The "tx_pkt_burst" will be set to dummy function. But the secondary
2343 : : * process does not support the mechanism for notifying the primary
2344 : : * process.
2345 : : */
2346 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2347 : 0 : hns3_err(hw, "secondary process does not support to set link down.");
2348 : 0 : return -ENOTSUP;
2349 : : }
2350 : :
2351 : : /*
2352 : : * If device isn't started or the API has been called, link status is
2353 : : * down, return success.
2354 : : */
2355 [ # # # # ]: 0 : if (hw->adapter_state != HNS3_NIC_STARTED || hw->set_link_down)
2356 : : return 0;
2357 : :
2358 : 0 : rte_spinlock_lock(&hw->lock);
2359 : 0 : hns3_stop_tx_datapath(dev);
2360 : 0 : ret = hns3_cfg_mac_mode(hw, false);
2361 [ # # ]: 0 : if (ret) {
2362 : 0 : hns3_start_tx_datapath(dev);
2363 : : rte_spinlock_unlock(&hw->lock);
2364 : 0 : hns3_err(hw, "failed to set link down, ret = %d", ret);
2365 : 0 : return ret;
2366 : : }
2367 : :
2368 : 0 : hw->set_link_down = true;
2369 : : rte_spinlock_unlock(&hw->lock);
2370 : :
2371 : 0 : return 0;
2372 : : }
2373 : :
2374 : : static int
2375 : : hns3_parse_func_status(struct hns3_hw *hw, struct hns3_func_status_cmd *status)
2376 : : {
2377 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2378 : : struct hns3_pf *pf = &hns->pf;
2379 : :
2380 [ # # ]: 0 : if (!(status->pf_state & HNS3_PF_STATE_DONE))
2381 : : return -EINVAL;
2382 : :
2383 : 0 : pf->is_main_pf = (status->pf_state & HNS3_PF_STATE_MAIN) ? true : false;
2384 : :
2385 : 0 : return 0;
2386 : : }
2387 : :
2388 : : static int
2389 : 0 : hns3_query_function_status(struct hns3_hw *hw)
2390 : : {
2391 : : #define HNS3_QUERY_MAX_CNT 10
2392 : : #define HNS3_QUERY_SLEEP_MSCOEND 1
2393 : : struct hns3_func_status_cmd *req;
2394 : : struct hns3_cmd_desc desc;
2395 : : int timeout = 0;
2396 : : int ret;
2397 : :
2398 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_FUNC_STATUS, true);
2399 : : req = (struct hns3_func_status_cmd *)desc.data;
2400 : :
2401 : : do {
2402 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
2403 [ # # ]: 0 : if (ret) {
2404 : 0 : PMD_INIT_LOG(ERR, "query function status failed %d",
2405 : : ret);
2406 : 0 : return ret;
2407 : : }
2408 : :
2409 : : /* Check pf reset is done */
2410 [ # # ]: 0 : if (req->pf_state)
2411 : : break;
2412 : :
2413 : : rte_delay_ms(HNS3_QUERY_SLEEP_MSCOEND);
2414 [ # # ]: 0 : } while (timeout++ < HNS3_QUERY_MAX_CNT);
2415 : :
2416 : : return hns3_parse_func_status(hw, req);
2417 : : }
2418 : :
2419 : : static int
2420 : : hns3_get_pf_max_tqp_num(struct hns3_hw *hw)
2421 : : {
2422 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2423 : : struct hns3_pf *pf = &hns->pf;
2424 : :
2425 [ # # ]: 0 : if (pf->tqp_config_mode == HNS3_FLEX_MAX_TQP_NUM_MODE) {
2426 : : /*
2427 : : * The total_tqps_num obtained from firmware is maximum tqp
2428 : : * numbers of this port, which should be used for PF and VFs.
2429 : : * There is no need for pf to have so many tqp numbers in
2430 : : * most cases. RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF,
2431 : : * coming from config file, is assigned to maximum queue number
2432 : : * for the PF of this port by user. So users can modify the
2433 : : * maximum queue number of PF according to their own application
2434 : : * scenarios, which is more flexible to use. In addition, many
2435 : : * memories can be saved due to allocating queue statistics
2436 : : * room according to the actual number of queues required. The
2437 : : * maximum queue number of PF for network engine with
2438 : : * revision_id greater than 0x30 is assigned by config file.
2439 : : */
2440 : : if (RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF <= 0) {
2441 : : hns3_err(hw, "RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF(%d) "
2442 : : "must be greater than 0.",
2443 : : RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF);
2444 : : return -EINVAL;
2445 : : }
2446 : :
2447 : 0 : hw->tqps_num = RTE_MIN(RTE_LIBRTE_HNS3_MAX_TQP_NUM_PER_PF,
2448 : : hw->total_tqps_num);
2449 : : } else {
2450 : : /*
2451 : : * Due to the limitation on the number of PF interrupts
2452 : : * available, the maximum queue number assigned to PF on
2453 : : * the network engine with revision_id 0x21 is 64.
2454 : : */
2455 : 0 : hw->tqps_num = RTE_MIN(hw->total_tqps_num,
2456 : : HNS3_MAX_TQP_NUM_HIP08_PF);
2457 : : }
2458 : :
2459 : : return 0;
2460 : : }
2461 : :
2462 : : static int
2463 : 0 : hns3_query_pf_resource(struct hns3_hw *hw)
2464 : : {
2465 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2466 : : struct hns3_pf *pf = &hns->pf;
2467 : : struct hns3_pf_res_cmd *req;
2468 : : struct hns3_cmd_desc desc;
2469 : : int ret;
2470 : :
2471 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_PF_RSRC, true);
2472 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
2473 [ # # ]: 0 : if (ret) {
2474 : 0 : PMD_INIT_LOG(ERR, "query pf resource failed %d", ret);
2475 : 0 : return ret;
2476 : : }
2477 : :
2478 : : req = (struct hns3_pf_res_cmd *)desc.data;
2479 : 0 : hw->total_tqps_num = rte_le_to_cpu_16(req->tqp_num) +
2480 : 0 : rte_le_to_cpu_16(req->ext_tqp_num);
2481 [ # # ]: 0 : if (hw->total_tqps_num == 0) {
2482 : 0 : PMD_INIT_LOG(ERR, "the total tqp number of the port is 0.");
2483 : 0 : return -EINVAL;
2484 : : }
2485 : : ret = hns3_get_pf_max_tqp_num(hw);
2486 : : if (ret)
2487 : : return ret;
2488 : :
2489 : 0 : pf->pkt_buf_size = rte_le_to_cpu_16(req->buf_size) << HNS3_BUF_UNIT_S;
2490 : 0 : pf->func_num = rte_le_to_cpu_16(req->pf_own_fun_number);
2491 : :
2492 [ # # ]: 0 : if (req->tx_buf_size)
2493 : 0 : pf->tx_buf_size =
2494 : 0 : rte_le_to_cpu_16(req->tx_buf_size) << HNS3_BUF_UNIT_S;
2495 : : else
2496 : 0 : pf->tx_buf_size = HNS3_DEFAULT_TX_BUF;
2497 : :
2498 : 0 : pf->tx_buf_size = roundup(pf->tx_buf_size, HNS3_BUF_SIZE_UNIT);
2499 : :
2500 [ # # ]: 0 : if (req->dv_buf_size)
2501 : 0 : pf->dv_buf_size =
2502 : 0 : rte_le_to_cpu_16(req->dv_buf_size) << HNS3_BUF_UNIT_S;
2503 : : else
2504 : 0 : pf->dv_buf_size = HNS3_DEFAULT_DV;
2505 : :
2506 : 0 : pf->dv_buf_size = roundup(pf->dv_buf_size, HNS3_BUF_SIZE_UNIT);
2507 : :
2508 : 0 : hw->num_msi =
2509 : 0 : hns3_get_field(rte_le_to_cpu_16(req->nic_pf_intr_vector_number),
2510 : : HNS3_PF_VEC_NUM_M, HNS3_PF_VEC_NUM_S);
2511 : :
2512 : 0 : return 0;
2513 : : }
2514 : :
2515 : : static void
2516 : 0 : hns3_parse_cfg(struct hns3_cfg *cfg, struct hns3_cmd_desc *desc)
2517 : : {
2518 : : struct hns3_cfg_param_cmd *req;
2519 : : uint64_t mac_addr_tmp_high;
2520 : : uint8_t ext_rss_size_max;
2521 : : uint64_t mac_addr_tmp;
2522 : : uint32_t i;
2523 : :
2524 : : req = (struct hns3_cfg_param_cmd *)desc[0].data;
2525 : :
2526 : : /* get the configuration */
2527 : 0 : cfg->tc_num = hns3_get_field(rte_le_to_cpu_32(req->param[0]),
2528 : : HNS3_CFG_TC_NUM_M, HNS3_CFG_TC_NUM_S);
2529 : :
2530 : 0 : cfg->phy_addr = hns3_get_field(rte_le_to_cpu_32(req->param[1]),
2531 : : HNS3_CFG_PHY_ADDR_M,
2532 : : HNS3_CFG_PHY_ADDR_S);
2533 : 0 : cfg->media_type = hns3_get_field(rte_le_to_cpu_32(req->param[1]),
2534 : : HNS3_CFG_MEDIA_TP_M,
2535 : : HNS3_CFG_MEDIA_TP_S);
2536 : : /* get mac address */
2537 : 0 : mac_addr_tmp = rte_le_to_cpu_32(req->param[2]);
2538 : 0 : mac_addr_tmp_high = hns3_get_field(rte_le_to_cpu_32(req->param[3]),
2539 : : HNS3_CFG_MAC_ADDR_H_M,
2540 : : HNS3_CFG_MAC_ADDR_H_S);
2541 : :
2542 : 0 : mac_addr_tmp |= (mac_addr_tmp_high << 31) << 1;
2543 : :
2544 : 0 : cfg->default_speed = hns3_get_field(rte_le_to_cpu_32(req->param[3]),
2545 : : HNS3_CFG_DEFAULT_SPEED_M,
2546 : : HNS3_CFG_DEFAULT_SPEED_S);
2547 : 0 : cfg->rss_size_max = hns3_get_field(rte_le_to_cpu_32(req->param[3]),
2548 : : HNS3_CFG_RSS_SIZE_M,
2549 : : HNS3_CFG_RSS_SIZE_S);
2550 : :
2551 [ # # ]: 0 : for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
2552 : 0 : cfg->mac_addr[i] = (mac_addr_tmp >> (8 * i)) & 0xff;
2553 : :
2554 : : req = (struct hns3_cfg_param_cmd *)desc[1].data;
2555 : 0 : cfg->numa_node_map = rte_le_to_cpu_32(req->param[0]);
2556 : :
2557 : 0 : cfg->speed_ability = hns3_get_field(rte_le_to_cpu_32(req->param[1]),
2558 : : HNS3_CFG_SPEED_ABILITY_M,
2559 : : HNS3_CFG_SPEED_ABILITY_S);
2560 : 0 : cfg->umv_space = hns3_get_field(rte_le_to_cpu_32(req->param[1]),
2561 : : HNS3_CFG_UMV_TBL_SPACE_M,
2562 : : HNS3_CFG_UMV_TBL_SPACE_S);
2563 [ # # ]: 0 : if (!cfg->umv_space)
2564 : 0 : cfg->umv_space = HNS3_DEFAULT_UMV_SPACE_PER_PF;
2565 : :
2566 : 0 : ext_rss_size_max = hns3_get_field(rte_le_to_cpu_32(req->param[2]),
2567 : : HNS3_CFG_EXT_RSS_SIZE_M,
2568 : : HNS3_CFG_EXT_RSS_SIZE_S);
2569 : : /*
2570 : : * Field ext_rss_size_max obtained from firmware will be more flexible
2571 : : * for future changes and expansions, which is an exponent of 2, instead
2572 : : * of reading out directly. If this field is not zero, hns3 PF PMD
2573 : : * uses it as rss_size_max under one TC. Device, whose revision
2574 : : * id is greater than or equal to PCI_REVISION_ID_HIP09_A, obtains the
2575 : : * maximum number of queues supported under a TC through this field.
2576 : : */
2577 [ # # ]: 0 : if (ext_rss_size_max)
2578 : 0 : cfg->rss_size_max = 1U << ext_rss_size_max;
2579 : 0 : }
2580 : :
2581 : : /* hns3_get_board_cfg: query the static parameter from NCL_config file in flash
2582 : : * @hw: pointer to struct hns3_hw
2583 : : * @hcfg: the config structure to be getted
2584 : : */
2585 : : static int
2586 : 0 : hns3_get_board_cfg(struct hns3_hw *hw, struct hns3_cfg *hcfg)
2587 : : {
2588 : : struct hns3_cmd_desc desc[HNS3_PF_CFG_DESC_NUM];
2589 : : struct hns3_cfg_param_cmd *req;
2590 : : uint32_t offset;
2591 : : uint32_t i;
2592 : : int ret;
2593 : :
2594 [ # # ]: 0 : for (i = 0; i < HNS3_PF_CFG_DESC_NUM; i++) {
2595 : : offset = 0;
2596 : 0 : req = (struct hns3_cfg_param_cmd *)desc[i].data;
2597 : 0 : hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_GET_CFG_PARAM,
2598 : : true);
2599 : 0 : hns3_set_field(offset, HNS3_CFG_OFFSET_M, HNS3_CFG_OFFSET_S,
2600 : : i * HNS3_CFG_RD_LEN_BYTES);
2601 : : /* Len should be divided by 4 when send to hardware */
2602 : 0 : hns3_set_field(offset, HNS3_CFG_RD_LEN_M, HNS3_CFG_RD_LEN_S,
2603 : : HNS3_CFG_RD_LEN_BYTES / HNS3_CFG_RD_LEN_UNIT);
2604 : 0 : req->offset = rte_cpu_to_le_32(offset);
2605 : : }
2606 : :
2607 : 0 : ret = hns3_cmd_send(hw, desc, HNS3_PF_CFG_DESC_NUM);
2608 [ # # ]: 0 : if (ret) {
2609 : 0 : PMD_INIT_LOG(ERR, "get config failed %d.", ret);
2610 : 0 : return ret;
2611 : : }
2612 : :
2613 : 0 : hns3_parse_cfg(hcfg, desc);
2614 : :
2615 : 0 : return 0;
2616 : : }
2617 : :
2618 : : static int
2619 : 0 : hns3_parse_speed(int speed_cmd, uint32_t *speed)
2620 : : {
2621 [ # # # # : 0 : switch (speed_cmd) {
# # # # #
# ]
2622 : 0 : case HNS3_CFG_SPEED_10M:
2623 : 0 : *speed = RTE_ETH_SPEED_NUM_10M;
2624 : 0 : break;
2625 : 0 : case HNS3_CFG_SPEED_100M:
2626 : 0 : *speed = RTE_ETH_SPEED_NUM_100M;
2627 : 0 : break;
2628 : 0 : case HNS3_CFG_SPEED_1G:
2629 : 0 : *speed = RTE_ETH_SPEED_NUM_1G;
2630 : 0 : break;
2631 : 0 : case HNS3_CFG_SPEED_10G:
2632 : 0 : *speed = RTE_ETH_SPEED_NUM_10G;
2633 : 0 : break;
2634 : 0 : case HNS3_CFG_SPEED_25G:
2635 : 0 : *speed = RTE_ETH_SPEED_NUM_25G;
2636 : 0 : break;
2637 : 0 : case HNS3_CFG_SPEED_40G:
2638 : 0 : *speed = RTE_ETH_SPEED_NUM_40G;
2639 : 0 : break;
2640 : 0 : case HNS3_CFG_SPEED_50G:
2641 : 0 : *speed = RTE_ETH_SPEED_NUM_50G;
2642 : 0 : break;
2643 : 0 : case HNS3_CFG_SPEED_100G:
2644 : 0 : *speed = RTE_ETH_SPEED_NUM_100G;
2645 : 0 : break;
2646 : 0 : case HNS3_CFG_SPEED_200G:
2647 : 0 : *speed = RTE_ETH_SPEED_NUM_200G;
2648 : 0 : break;
2649 : : default:
2650 : : return -EINVAL;
2651 : : }
2652 : :
2653 : : return 0;
2654 : : }
2655 : :
2656 : : static int
2657 : 0 : hns3_get_capability(struct hns3_hw *hw)
2658 : : {
2659 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2660 : : struct hns3_pf *pf = &hns->pf;
2661 : : int ret;
2662 : :
2663 : 0 : ret = hns3_query_mac_stats_reg_num(hw);
2664 [ # # ]: 0 : if (ret)
2665 : : return ret;
2666 : :
2667 [ # # ]: 0 : if (hw->revision < PCI_REVISION_ID_HIP09_A) {
2668 : 0 : hns3_set_default_dev_specifications(hw);
2669 : 0 : hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
2670 : 0 : hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
2671 : 0 : hw->tso_mode = HNS3_TSO_SW_CAL_PSEUDO_H_CSUM;
2672 : 0 : hw->vlan_mode = HNS3_SW_SHIFT_AND_DISCARD_MODE;
2673 : 0 : hw->drop_stats_mode = HNS3_PKTS_DROP_STATS_MODE1;
2674 : 0 : hw->min_tx_pkt_len = HNS3_HIP08_MIN_TX_PKT_LEN;
2675 : 0 : pf->tqp_config_mode = HNS3_FIXED_MAX_TQP_NUM_MODE;
2676 : 0 : hw->rss_info.ipv6_sctp_offload_supported = false;
2677 : 0 : hw->udp_cksum_mode = HNS3_SPECIAL_PORT_SW_CKSUM_MODE;
2678 : 0 : pf->support_multi_tc_pause = false;
2679 : 0 : hw->rx_dma_addr_align = HNS3_RX_DMA_ADDR_ALIGN_64;
2680 : 0 : hw->strip_crc_ptype = HNS3_STRIP_CRC_PTYPE_TCP;
2681 : 0 : return 0;
2682 : : }
2683 : :
2684 : 0 : ret = hns3_query_dev_specifications(hw);
2685 [ # # ]: 0 : if (ret) {
2686 : 0 : PMD_INIT_LOG(ERR,
2687 : : "failed to query dev specifications, ret = %d",
2688 : : ret);
2689 : 0 : return ret;
2690 : : }
2691 : :
2692 : 0 : hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_ALL;
2693 : 0 : hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_1US;
2694 : 0 : hw->tso_mode = HNS3_TSO_HW_CAL_PSEUDO_H_CSUM;
2695 : 0 : hw->vlan_mode = HNS3_HW_SHIFT_AND_DISCARD_MODE;
2696 : 0 : hw->drop_stats_mode = HNS3_PKTS_DROP_STATS_MODE2;
2697 : 0 : pf->tqp_config_mode = HNS3_FLEX_MAX_TQP_NUM_MODE;
2698 : 0 : hw->rss_info.ipv6_sctp_offload_supported = true;
2699 : 0 : hw->udp_cksum_mode = HNS3_SPECIAL_PORT_HW_CKSUM_MODE;
2700 : 0 : pf->support_multi_tc_pause = true;
2701 : 0 : hw->rx_dma_addr_align = HNS3_RX_DMA_ADDR_ALIGN_128;
2702 : 0 : hw->strip_crc_ptype = HNS3_STRIP_CRC_PTYPE_IP;
2703 : :
2704 : 0 : return 0;
2705 : : }
2706 : :
2707 : : static int
2708 : 0 : hns3_check_media_type(struct hns3_hw *hw, uint8_t media_type)
2709 : : {
2710 : : int ret;
2711 : :
2712 [ # # # ]: 0 : switch (media_type) {
2713 : 0 : case HNS3_MEDIA_TYPE_COPPER:
2714 [ # # ]: 0 : if (!hns3_dev_get_support(hw, COPPER)) {
2715 : 0 : PMD_INIT_LOG(ERR,
2716 : : "Media type is copper, not supported.");
2717 : : ret = -EOPNOTSUPP;
2718 : : } else {
2719 : : ret = 0;
2720 : : }
2721 : : break;
2722 : : case HNS3_MEDIA_TYPE_FIBER:
2723 : : case HNS3_MEDIA_TYPE_BACKPLANE:
2724 : : ret = 0;
2725 : : break;
2726 : 0 : default:
2727 : 0 : PMD_INIT_LOG(ERR, "Unknown media type = %u!", media_type);
2728 : : ret = -EINVAL;
2729 : 0 : break;
2730 : : }
2731 : :
2732 : 0 : return ret;
2733 : : }
2734 : :
2735 : : static int
2736 : 0 : hns3_get_board_configuration(struct hns3_hw *hw)
2737 : : {
2738 : : #define HNS3_RSS_SIZE_MAX_DEFAULT 64
2739 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2740 : : struct hns3_pf *pf = &hns->pf;
2741 : : struct hns3_cfg cfg;
2742 : : int ret;
2743 : :
2744 : : memset(&cfg, 0, sizeof(cfg));
2745 : 0 : ret = hns3_get_board_cfg(hw, &cfg);
2746 [ # # ]: 0 : if (ret) {
2747 : 0 : PMD_INIT_LOG(ERR, "get board config failed %d", ret);
2748 : 0 : return ret;
2749 : : }
2750 : :
2751 : 0 : ret = hns3_check_media_type(hw, cfg.media_type);
2752 [ # # ]: 0 : if (ret)
2753 : : return ret;
2754 : :
2755 : 0 : hw->mac.media_type = cfg.media_type;
2756 : 0 : hw->rss_size_max = cfg.rss_size_max;
2757 [ # # ]: 0 : if (hw->rss_size_max == 0) {
2758 : 0 : PMD_INIT_LOG(WARNING, "rss_size_max is 0, already adjust to %u.",
2759 : : HNS3_RSS_SIZE_MAX_DEFAULT);
2760 : 0 : hw->rss_size_max = HNS3_RSS_SIZE_MAX_DEFAULT;
2761 : : }
2762 : 0 : memcpy(hw->mac.mac_addr, cfg.mac_addr, RTE_ETHER_ADDR_LEN);
2763 : 0 : hw->mac.phy_addr = cfg.phy_addr;
2764 : 0 : hw->dcb_info.num_pg = 1;
2765 : 0 : hw->dcb_info.hw_pfc_map = 0;
2766 : :
2767 : 0 : ret = hns3_parse_speed(cfg.default_speed, &hw->mac.link_speed);
2768 [ # # ]: 0 : if (ret) {
2769 : 0 : PMD_INIT_LOG(ERR, "Get wrong speed %u, ret = %d",
2770 : : cfg.default_speed, ret);
2771 : 0 : return ret;
2772 : : }
2773 : :
2774 : 0 : hw->dcb_info.tc_max = cfg.tc_num;
2775 [ # # ]: 0 : if (hw->dcb_info.tc_max > HNS3_MAX_TC_NUM || hw->dcb_info.tc_max < 1) {
2776 : 0 : PMD_INIT_LOG(WARNING,
2777 : : "Get TC num(%u) from flash, set TC num to 1",
2778 : : hw->dcb_info.tc_max);
2779 : 0 : hw->dcb_info.tc_max = 1;
2780 : : }
2781 : :
2782 : : /* Dev does not support DCB */
2783 [ # # ]: 0 : if (!hns3_dev_get_support(hw, DCB)) {
2784 : 0 : hw->dcb_info.tc_max = 1;
2785 : 0 : hw->dcb_info.pfc_max = 0;
2786 : : } else
2787 : 0 : hw->dcb_info.pfc_max = hw->dcb_info.tc_max;
2788 : :
2789 : 0 : hw->dcb_info.num_tc = 1;
2790 : 0 : hw->alloc_rss_size = RTE_MIN(hw->rss_size_max,
2791 : : hw->tqps_num / hw->dcb_info.num_tc);
2792 : 0 : hns3_set_bit(hw->dcb_info.hw_tc_map, 0, 1);
2793 : 0 : pf->tx_sch_mode = HNS3_FLAG_TC_BASE_SCH_MODE;
2794 : :
2795 : 0 : pf->wanted_umv_size = cfg.umv_space;
2796 : :
2797 : 0 : return ret;
2798 : : }
2799 : :
2800 : : static int
2801 : 0 : hns3_get_configuration(struct hns3_hw *hw)
2802 : : {
2803 : : int ret;
2804 : :
2805 : 0 : ret = hns3_query_function_status(hw);
2806 [ # # ]: 0 : if (ret) {
2807 : 0 : PMD_INIT_LOG(ERR, "Failed to query function status: %d.", ret);
2808 : 0 : return ret;
2809 : : }
2810 : :
2811 : : /* Get device capability */
2812 : 0 : ret = hns3_get_capability(hw);
2813 [ # # ]: 0 : if (ret) {
2814 : 0 : PMD_INIT_LOG(ERR, "failed to get device capability: %d.", ret);
2815 : 0 : return ret;
2816 : : }
2817 : :
2818 : : /* Get pf resource */
2819 : 0 : ret = hns3_query_pf_resource(hw);
2820 [ # # ]: 0 : if (ret) {
2821 : 0 : PMD_INIT_LOG(ERR, "Failed to query pf resource: %d", ret);
2822 : 0 : return ret;
2823 : : }
2824 : :
2825 : 0 : ret = hns3_get_board_configuration(hw);
2826 [ # # ]: 0 : if (ret) {
2827 : 0 : PMD_INIT_LOG(ERR, "failed to get board configuration: %d", ret);
2828 : 0 : return ret;
2829 : : }
2830 : :
2831 : 0 : ret = hns3_query_dev_fec_info(hw);
2832 [ # # ]: 0 : if (ret)
2833 : 0 : PMD_INIT_LOG(ERR,
2834 : : "failed to query FEC information, ret = %d", ret);
2835 : :
2836 : : return ret;
2837 : : }
2838 : :
2839 : : static int
2840 : 0 : hns3_map_tqps_to_func(struct hns3_hw *hw, uint16_t func_id, uint16_t tqp_pid,
2841 : : uint16_t tqp_vid, bool is_pf)
2842 : : {
2843 : : struct hns3_tqp_map_cmd *req;
2844 : : struct hns3_cmd_desc desc;
2845 : : int ret;
2846 : :
2847 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_SET_TQP_MAP, false);
2848 : :
2849 : : req = (struct hns3_tqp_map_cmd *)desc.data;
2850 : 0 : req->tqp_id = rte_cpu_to_le_16(tqp_pid);
2851 : 0 : req->tqp_vf = func_id;
2852 : 0 : req->tqp_flag = 1 << HNS3_TQP_MAP_EN_B;
2853 [ # # ]: 0 : if (!is_pf)
2854 : 0 : req->tqp_flag |= (1 << HNS3_TQP_MAP_TYPE_B);
2855 : 0 : req->tqp_vid = rte_cpu_to_le_16(tqp_vid);
2856 : :
2857 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
2858 [ # # ]: 0 : if (ret)
2859 : 0 : PMD_INIT_LOG(ERR, "TQP map failed %d", ret);
2860 : :
2861 : 0 : return ret;
2862 : : }
2863 : :
2864 : : static int
2865 : 0 : hns3_map_tqp(struct hns3_hw *hw)
2866 : : {
2867 : : uint16_t i;
2868 : : int ret;
2869 : :
2870 : : /*
2871 : : * In current version, VF is not supported when PF is driven by DPDK
2872 : : * driver, so we assign total tqps_num tqps allocated to this port
2873 : : * to PF.
2874 : : */
2875 [ # # ]: 0 : for (i = 0; i < hw->total_tqps_num; i++) {
2876 : 0 : ret = hns3_map_tqps_to_func(hw, HNS3_PF_FUNC_ID, i, i, true);
2877 [ # # ]: 0 : if (ret)
2878 : 0 : return ret;
2879 : : }
2880 : :
2881 : : return 0;
2882 : : }
2883 : :
2884 : : static int
2885 : 0 : hns3_cfg_mac_speed_dup_hw(struct hns3_hw *hw, uint32_t speed, uint8_t duplex)
2886 : : {
2887 : : struct hns3_config_mac_speed_dup_cmd *req;
2888 : : struct hns3_cmd_desc desc;
2889 : : int ret;
2890 : :
2891 : : req = (struct hns3_config_mac_speed_dup_cmd *)desc.data;
2892 : :
2893 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_SPEED_DUP, false);
2894 : :
2895 [ # # ]: 0 : hns3_set_bit(req->speed_dup, HNS3_CFG_DUPLEX_B, !!duplex ? 1 : 0);
2896 : :
2897 [ # # # # : 0 : switch (speed) {
# # # # #
# ]
2898 : 0 : case RTE_ETH_SPEED_NUM_10M:
2899 : 0 : hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
2900 : : HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_10M);
2901 : 0 : break;
2902 : 0 : case RTE_ETH_SPEED_NUM_100M:
2903 : 0 : hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
2904 : : HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_100M);
2905 : 0 : break;
2906 : 0 : case RTE_ETH_SPEED_NUM_1G:
2907 : 0 : hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
2908 : : HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_1G);
2909 : 0 : break;
2910 : 0 : case RTE_ETH_SPEED_NUM_10G:
2911 : 0 : hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
2912 : : HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_10G);
2913 : 0 : break;
2914 : 0 : case RTE_ETH_SPEED_NUM_25G:
2915 : 0 : hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
2916 : : HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_25G);
2917 : 0 : break;
2918 : 0 : case RTE_ETH_SPEED_NUM_40G:
2919 : 0 : hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
2920 : : HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_40G);
2921 : 0 : break;
2922 : 0 : case RTE_ETH_SPEED_NUM_50G:
2923 : 0 : hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
2924 : : HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_50G);
2925 : 0 : break;
2926 : 0 : case RTE_ETH_SPEED_NUM_100G:
2927 : 0 : hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
2928 : : HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_100G);
2929 : 0 : break;
2930 : 0 : case RTE_ETH_SPEED_NUM_200G:
2931 : 0 : hns3_set_field(req->speed_dup, HNS3_CFG_SPEED_M,
2932 : : HNS3_CFG_SPEED_S, HNS3_CFG_SPEED_200G);
2933 : 0 : break;
2934 : 0 : default:
2935 : 0 : PMD_INIT_LOG(ERR, "invalid speed (%u)", speed);
2936 : 0 : return -EINVAL;
2937 : : }
2938 : :
2939 : 0 : hns3_set_bit(req->mac_change_fec_en, HNS3_CFG_MAC_SPEED_CHANGE_EN_B, 1);
2940 : :
2941 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
2942 [ # # ]: 0 : if (ret)
2943 : 0 : PMD_INIT_LOG(ERR, "mac speed/duplex config cmd failed %d", ret);
2944 : :
2945 : : return ret;
2946 : : }
2947 : :
2948 : : static int
2949 : : hns3_tx_buffer_calc(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
2950 : : {
2951 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
2952 : : struct hns3_pf *pf = &hns->pf;
2953 : : struct hns3_priv_buf *priv;
2954 : : uint32_t i, total_size;
2955 : :
2956 : 0 : total_size = pf->pkt_buf_size;
2957 : :
2958 : : /* alloc tx buffer for all enabled tc */
2959 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
2960 : : priv = &buf_alloc->priv_buf[i];
2961 : :
2962 [ # # ]: 0 : if (hw->dcb_info.hw_tc_map & BIT(i)) {
2963 [ # # ]: 0 : if (total_size < pf->tx_buf_size)
2964 : : return -ENOMEM;
2965 : :
2966 : 0 : priv->tx_buf_size = pf->tx_buf_size;
2967 : : } else
2968 : 0 : priv->tx_buf_size = 0;
2969 : :
2970 : 0 : total_size -= priv->tx_buf_size;
2971 : : }
2972 : :
2973 : : return 0;
2974 : : }
2975 : :
2976 : : static int
2977 : 0 : hns3_tx_buffer_alloc(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
2978 : : {
2979 : : /* TX buffer size is unit by 128 byte */
2980 : : #define HNS3_BUF_SIZE_UNIT_SHIFT 7
2981 : : #define HNS3_BUF_SIZE_UPDATE_EN_MSK BIT(15)
2982 : : struct hns3_tx_buff_alloc_cmd *req;
2983 : : struct hns3_cmd_desc desc;
2984 : : uint32_t buf_size;
2985 : : uint32_t i;
2986 : : int ret;
2987 : :
2988 : : req = (struct hns3_tx_buff_alloc_cmd *)desc.data;
2989 : :
2990 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TX_BUFF_ALLOC, 0);
2991 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
2992 : 0 : buf_size = buf_alloc->priv_buf[i].tx_buf_size;
2993 : :
2994 : 0 : buf_size = buf_size >> HNS3_BUF_SIZE_UNIT_SHIFT;
2995 : 0 : req->tx_pkt_buff[i] = rte_cpu_to_le_16(buf_size |
2996 : : HNS3_BUF_SIZE_UPDATE_EN_MSK);
2997 : : }
2998 : :
2999 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
3000 [ # # ]: 0 : if (ret)
3001 : 0 : PMD_INIT_LOG(ERR, "tx buffer alloc cmd failed %d", ret);
3002 : :
3003 : 0 : return ret;
3004 : : }
3005 : :
3006 : : static int
3007 : : hns3_get_tc_num(struct hns3_hw *hw)
3008 : : {
3009 : : int cnt = 0;
3010 : : uint8_t i;
3011 : :
3012 [ # # # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++)
3013 [ # # # # ]: 0 : if (hw->dcb_info.hw_tc_map & BIT(i))
3014 : 0 : cnt++;
3015 : : return cnt;
3016 : : }
3017 : :
3018 : : static uint32_t
3019 : : hns3_get_rx_priv_buff_alloced(struct hns3_pkt_buf_alloc *buf_alloc)
3020 : : {
3021 : : struct hns3_priv_buf *priv;
3022 : : uint32_t rx_priv = 0;
3023 : : int i;
3024 : :
3025 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3026 : : priv = &buf_alloc->priv_buf[i];
3027 [ # # ]: 0 : if (priv->enable)
3028 : 0 : rx_priv += priv->buf_size;
3029 : : }
3030 : : return rx_priv;
3031 : : }
3032 : :
3033 : : static uint32_t
3034 : : hns3_get_tx_buff_alloced(struct hns3_pkt_buf_alloc *buf_alloc)
3035 : : {
3036 : : uint32_t total_tx_size = 0;
3037 : : uint32_t i;
3038 : :
3039 [ # # # # : 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++)
# # # # #
# ]
3040 : 0 : total_tx_size += buf_alloc->priv_buf[i].tx_buf_size;
3041 : :
3042 : : return total_tx_size;
3043 : : }
3044 : :
3045 : : /* Get the number of pfc enabled TCs, which have private buffer */
3046 : : static int
3047 : : hns3_get_pfc_priv_num(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3048 : : {
3049 : : struct hns3_priv_buf *priv;
3050 : : int cnt = 0;
3051 : : uint8_t i;
3052 : :
3053 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3054 : 0 : priv = &buf_alloc->priv_buf[i];
3055 [ # # # # ]: 0 : if ((hw->dcb_info.hw_pfc_map & BIT(i)) && priv->enable)
3056 : 0 : cnt++;
3057 : : }
3058 : :
3059 : : return cnt;
3060 : : }
3061 : :
3062 : : /* Get the number of pfc disabled TCs, which have private buffer */
3063 : : static int
3064 : : hns3_get_no_pfc_priv_num(struct hns3_hw *hw,
3065 : : struct hns3_pkt_buf_alloc *buf_alloc)
3066 : : {
3067 : : struct hns3_priv_buf *priv;
3068 : : int cnt = 0;
3069 : : uint8_t i;
3070 : :
3071 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3072 : 0 : priv = &buf_alloc->priv_buf[i];
3073 [ # # ]: 0 : if (hw->dcb_info.hw_tc_map & BIT(i) &&
3074 [ # # # # ]: 0 : !(hw->dcb_info.hw_pfc_map & BIT(i)) && priv->enable)
3075 : 0 : cnt++;
3076 : : }
3077 : :
3078 : : return cnt;
3079 : : }
3080 : :
3081 : : static bool
3082 : 0 : hns3_is_rx_buf_ok(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc,
3083 : : uint32_t rx_all)
3084 : : {
3085 : : uint32_t shared_buf_min, shared_buf_tc, shared_std, hi_thrd, lo_thrd;
3086 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3087 : : struct hns3_pf *pf = &hns->pf;
3088 : : uint32_t shared_buf, aligned_mps;
3089 : : uint32_t rx_priv;
3090 : : uint8_t tc_num;
3091 : : uint8_t i;
3092 : :
3093 : 0 : tc_num = hns3_get_tc_num(hw);
3094 : 0 : aligned_mps = roundup(pf->mps, HNS3_BUF_SIZE_UNIT);
3095 : :
3096 [ # # ]: 0 : if (hns3_dev_get_support(hw, DCB))
3097 : 0 : shared_buf_min = HNS3_BUF_MUL_BY * aligned_mps +
3098 : 0 : pf->dv_buf_size;
3099 : : else
3100 : 0 : shared_buf_min = aligned_mps + HNS3_NON_DCB_ADDITIONAL_BUF
3101 : 0 : + pf->dv_buf_size;
3102 : :
3103 : 0 : shared_buf_tc = tc_num * aligned_mps + aligned_mps;
3104 : 0 : shared_std = roundup(RTE_MAX(shared_buf_min, shared_buf_tc),
3105 : : HNS3_BUF_SIZE_UNIT);
3106 : :
3107 : : rx_priv = hns3_get_rx_priv_buff_alloced(buf_alloc);
3108 [ # # ]: 0 : if (rx_all < rx_priv + shared_std)
3109 : : return false;
3110 : :
3111 : 0 : shared_buf = rounddown(rx_all - rx_priv, HNS3_BUF_SIZE_UNIT);
3112 : 0 : buf_alloc->s_buf.buf_size = shared_buf;
3113 [ # # ]: 0 : if (hns3_dev_get_support(hw, DCB)) {
3114 : 0 : buf_alloc->s_buf.self.high = shared_buf - pf->dv_buf_size;
3115 : 0 : buf_alloc->s_buf.self.low = buf_alloc->s_buf.self.high
3116 : 0 : - roundup(aligned_mps / HNS3_BUF_DIV_BY,
3117 : : HNS3_BUF_SIZE_UNIT);
3118 : : } else {
3119 : 0 : buf_alloc->s_buf.self.high =
3120 : 0 : aligned_mps + HNS3_NON_DCB_ADDITIONAL_BUF;
3121 : 0 : buf_alloc->s_buf.self.low = aligned_mps;
3122 : : }
3123 : :
3124 [ # # ]: 0 : if (hns3_dev_get_support(hw, DCB)) {
3125 : 0 : hi_thrd = shared_buf - pf->dv_buf_size;
3126 : :
3127 [ # # ]: 0 : if (tc_num <= NEED_RESERVE_TC_NUM)
3128 : 0 : hi_thrd = hi_thrd * BUF_RESERVE_PERCENT /
3129 : : BUF_MAX_PERCENT;
3130 : :
3131 [ # # ]: 0 : if (tc_num)
3132 : 0 : hi_thrd = hi_thrd / tc_num;
3133 : :
3134 : 0 : hi_thrd = RTE_MAX(hi_thrd, HNS3_BUF_MUL_BY * aligned_mps);
3135 : 0 : hi_thrd = rounddown(hi_thrd, HNS3_BUF_SIZE_UNIT);
3136 : 0 : lo_thrd = hi_thrd - aligned_mps / HNS3_BUF_DIV_BY;
3137 : : } else {
3138 : 0 : hi_thrd = aligned_mps + HNS3_NON_DCB_ADDITIONAL_BUF;
3139 : : lo_thrd = aligned_mps;
3140 : : }
3141 : :
3142 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3143 : 0 : buf_alloc->s_buf.tc_thrd[i].low = lo_thrd;
3144 : 0 : buf_alloc->s_buf.tc_thrd[i].high = hi_thrd;
3145 : : }
3146 : :
3147 : : return true;
3148 : : }
3149 : :
3150 : : static bool
3151 : 0 : hns3_rx_buf_calc_all(struct hns3_hw *hw, bool max,
3152 : : struct hns3_pkt_buf_alloc *buf_alloc)
3153 : : {
3154 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3155 : : struct hns3_pf *pf = &hns->pf;
3156 : : struct hns3_priv_buf *priv;
3157 : : uint32_t aligned_mps;
3158 : : uint32_t rx_all;
3159 : : uint8_t i;
3160 : :
3161 : 0 : rx_all = pf->pkt_buf_size - hns3_get_tx_buff_alloced(buf_alloc);
3162 : 0 : aligned_mps = roundup(pf->mps, HNS3_BUF_SIZE_UNIT);
3163 : :
3164 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3165 : 0 : priv = &buf_alloc->priv_buf[i];
3166 : :
3167 : 0 : priv->enable = 0;
3168 : 0 : priv->wl.low = 0;
3169 : 0 : priv->wl.high = 0;
3170 : 0 : priv->buf_size = 0;
3171 : :
3172 [ # # ]: 0 : if (!(hw->dcb_info.hw_tc_map & BIT(i)))
3173 : 0 : continue;
3174 : :
3175 : 0 : priv->enable = 1;
3176 [ # # ]: 0 : if (hw->dcb_info.hw_pfc_map & BIT(i)) {
3177 [ # # ]: 0 : priv->wl.low = max ? aligned_mps : HNS3_BUF_SIZE_UNIT;
3178 : 0 : priv->wl.high = roundup(priv->wl.low + aligned_mps,
3179 : : HNS3_BUF_SIZE_UNIT);
3180 : : } else {
3181 : : priv->wl.low = 0;
3182 [ # # ]: 0 : priv->wl.high = max ? (aligned_mps * HNS3_BUF_MUL_BY) :
3183 : : aligned_mps;
3184 : : }
3185 : :
3186 : 0 : priv->buf_size = priv->wl.high + pf->dv_buf_size;
3187 : : }
3188 : :
3189 : 0 : return hns3_is_rx_buf_ok(hw, buf_alloc, rx_all);
3190 : : }
3191 : :
3192 : : static bool
3193 : 0 : hns3_drop_nopfc_buf_till_fit(struct hns3_hw *hw,
3194 : : struct hns3_pkt_buf_alloc *buf_alloc)
3195 : : {
3196 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3197 : : struct hns3_pf *pf = &hns->pf;
3198 : : struct hns3_priv_buf *priv;
3199 : : int no_pfc_priv_num;
3200 : : uint32_t rx_all;
3201 : : uint8_t mask;
3202 : : int i;
3203 : :
3204 : 0 : rx_all = pf->pkt_buf_size - hns3_get_tx_buff_alloced(buf_alloc);
3205 : : no_pfc_priv_num = hns3_get_no_pfc_priv_num(hw, buf_alloc);
3206 : :
3207 : : /* let the last to be cleared first */
3208 [ # # ]: 0 : for (i = HNS3_MAX_TC_NUM - 1; i >= 0; i--) {
3209 : : priv = &buf_alloc->priv_buf[i];
3210 : 0 : mask = BIT((uint8_t)i);
3211 [ # # ]: 0 : if (hw->dcb_info.hw_tc_map & mask &&
3212 [ # # ]: 0 : !(hw->dcb_info.hw_pfc_map & mask)) {
3213 : : /* Clear the no pfc TC private buffer */
3214 : 0 : priv->wl.low = 0;
3215 : 0 : priv->wl.high = 0;
3216 : 0 : priv->buf_size = 0;
3217 : 0 : priv->enable = 0;
3218 : 0 : no_pfc_priv_num--;
3219 : : }
3220 : :
3221 [ # # # # ]: 0 : if (hns3_is_rx_buf_ok(hw, buf_alloc, rx_all) ||
3222 : : no_pfc_priv_num == 0)
3223 : : break;
3224 : : }
3225 : :
3226 : 0 : return hns3_is_rx_buf_ok(hw, buf_alloc, rx_all);
3227 : : }
3228 : :
3229 : : static bool
3230 : 0 : hns3_drop_pfc_buf_till_fit(struct hns3_hw *hw,
3231 : : struct hns3_pkt_buf_alloc *buf_alloc)
3232 : : {
3233 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3234 : : struct hns3_pf *pf = &hns->pf;
3235 : : struct hns3_priv_buf *priv;
3236 : : uint32_t rx_all;
3237 : : int pfc_priv_num;
3238 : : uint8_t mask;
3239 : : int i;
3240 : :
3241 : 0 : rx_all = pf->pkt_buf_size - hns3_get_tx_buff_alloced(buf_alloc);
3242 : : pfc_priv_num = hns3_get_pfc_priv_num(hw, buf_alloc);
3243 : :
3244 : : /* let the last to be cleared first */
3245 [ # # ]: 0 : for (i = HNS3_MAX_TC_NUM - 1; i >= 0; i--) {
3246 : : priv = &buf_alloc->priv_buf[i];
3247 : 0 : mask = BIT((uint8_t)i);
3248 [ # # # # ]: 0 : if (hw->dcb_info.hw_tc_map & mask && hw->dcb_info.hw_pfc_map & mask) {
3249 : : /* Reduce the number of pfc TC with private buffer */
3250 : 0 : priv->wl.low = 0;
3251 : 0 : priv->enable = 0;
3252 : 0 : priv->wl.high = 0;
3253 : 0 : priv->buf_size = 0;
3254 : 0 : pfc_priv_num--;
3255 : : }
3256 [ # # # # ]: 0 : if (hns3_is_rx_buf_ok(hw, buf_alloc, rx_all) ||
3257 : : pfc_priv_num == 0)
3258 : : break;
3259 : : }
3260 : :
3261 : 0 : return hns3_is_rx_buf_ok(hw, buf_alloc, rx_all);
3262 : : }
3263 : :
3264 : : static bool
3265 : 0 : hns3_only_alloc_priv_buff(struct hns3_hw *hw,
3266 : : struct hns3_pkt_buf_alloc *buf_alloc)
3267 : : {
3268 : : #define COMPENSATE_BUFFER 0x3C00
3269 : : #define COMPENSATE_HALF_MPS_NUM 5
3270 : : #define PRIV_WL_GAP 0x1800
3271 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3272 : : struct hns3_pf *pf = &hns->pf;
3273 : 0 : uint32_t tc_num = hns3_get_tc_num(hw);
3274 : 0 : uint32_t half_mps = pf->mps >> 1;
3275 : : struct hns3_priv_buf *priv;
3276 : : uint32_t min_rx_priv;
3277 : : uint32_t rx_priv;
3278 : : uint8_t i;
3279 : :
3280 : 0 : rx_priv = pf->pkt_buf_size - hns3_get_tx_buff_alloced(buf_alloc);
3281 [ # # ]: 0 : if (tc_num)
3282 : 0 : rx_priv = rx_priv / tc_num;
3283 : :
3284 [ # # ]: 0 : if (tc_num <= NEED_RESERVE_TC_NUM)
3285 : 0 : rx_priv = rx_priv * BUF_RESERVE_PERCENT / BUF_MAX_PERCENT;
3286 : :
3287 : : /*
3288 : : * Minimum value of private buffer in rx direction (min_rx_priv) is
3289 : : * equal to "DV + 2.5 * MPS + 15KB". Driver only allocates rx private
3290 : : * buffer if rx_priv is greater than min_rx_priv.
3291 : : */
3292 : 0 : min_rx_priv = pf->dv_buf_size + COMPENSATE_BUFFER +
3293 : 0 : COMPENSATE_HALF_MPS_NUM * half_mps;
3294 : 0 : min_rx_priv = roundup(min_rx_priv, HNS3_BUF_SIZE_UNIT);
3295 : 0 : rx_priv = rounddown(rx_priv, HNS3_BUF_SIZE_UNIT);
3296 [ # # ]: 0 : if (rx_priv < min_rx_priv)
3297 : : return false;
3298 : :
3299 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3300 : 0 : priv = &buf_alloc->priv_buf[i];
3301 : 0 : priv->enable = 0;
3302 : 0 : priv->wl.low = 0;
3303 : 0 : priv->wl.high = 0;
3304 : 0 : priv->buf_size = 0;
3305 : :
3306 [ # # ]: 0 : if (!(hw->dcb_info.hw_tc_map & BIT(i)))
3307 : 0 : continue;
3308 : :
3309 : 0 : priv->enable = 1;
3310 : 0 : priv->buf_size = rx_priv;
3311 : 0 : priv->wl.high = rx_priv - pf->dv_buf_size;
3312 : 0 : priv->wl.low = priv->wl.high - PRIV_WL_GAP;
3313 : : }
3314 : :
3315 : 0 : buf_alloc->s_buf.buf_size = 0;
3316 : :
3317 : 0 : return true;
3318 : : }
3319 : :
3320 : : /*
3321 : : * hns3_rx_buffer_calc: calculate the rx private buffer size for all TCs
3322 : : * @hw: pointer to struct hns3_hw
3323 : : * @buf_alloc: pointer to buffer calculation data
3324 : : * @return: 0: calculate successful, negative: fail
3325 : : */
3326 : : static int
3327 : 0 : hns3_rx_buffer_calc(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3328 : : {
3329 : : /* When DCB is not supported, rx private buffer is not allocated. */
3330 [ # # ]: 0 : if (!hns3_dev_get_support(hw, DCB)) {
3331 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3332 : : struct hns3_pf *pf = &hns->pf;
3333 : 0 : uint32_t rx_all = pf->pkt_buf_size;
3334 : :
3335 : 0 : rx_all -= hns3_get_tx_buff_alloced(buf_alloc);
3336 [ # # ]: 0 : if (!hns3_is_rx_buf_ok(hw, buf_alloc, rx_all))
3337 : : return -ENOMEM;
3338 : :
3339 : 0 : return 0;
3340 : : }
3341 : :
3342 : : /*
3343 : : * Try to allocate privated packet buffer for all TCs without share
3344 : : * buffer.
3345 : : */
3346 [ # # ]: 0 : if (hns3_only_alloc_priv_buff(hw, buf_alloc))
3347 : : return 0;
3348 : :
3349 : : /*
3350 : : * Try to allocate privated packet buffer for all TCs with share
3351 : : * buffer.
3352 : : */
3353 [ # # ]: 0 : if (hns3_rx_buf_calc_all(hw, true, buf_alloc))
3354 : : return 0;
3355 : :
3356 : : /*
3357 : : * For different application scenes, the enabled port number, TC number
3358 : : * and no_drop TC number are different. In order to obtain the better
3359 : : * performance, software could allocate the buffer size and configure
3360 : : * the waterline by trying to decrease the private buffer size according
3361 : : * to the order, namely, waterline of valid tc, pfc disabled tc, pfc
3362 : : * enabled tc.
3363 : : */
3364 [ # # ]: 0 : if (hns3_rx_buf_calc_all(hw, false, buf_alloc))
3365 : : return 0;
3366 : :
3367 [ # # ]: 0 : if (hns3_drop_nopfc_buf_till_fit(hw, buf_alloc))
3368 : : return 0;
3369 : :
3370 [ # # ]: 0 : if (hns3_drop_pfc_buf_till_fit(hw, buf_alloc))
3371 : 0 : return 0;
3372 : :
3373 : : return -ENOMEM;
3374 : : }
3375 : :
3376 : : static int
3377 : 0 : hns3_rx_priv_buf_alloc(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3378 : : {
3379 : : struct hns3_rx_priv_buff_cmd *req;
3380 : : struct hns3_cmd_desc desc;
3381 : : uint32_t buf_size;
3382 : : int ret;
3383 : : int i;
3384 : :
3385 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RX_PRIV_BUFF_ALLOC, false);
3386 : : req = (struct hns3_rx_priv_buff_cmd *)desc.data;
3387 : :
3388 : : /* Alloc private buffer TCs */
3389 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
3390 : : struct hns3_priv_buf *priv = &buf_alloc->priv_buf[i];
3391 : :
3392 : 0 : req->buf_num[i] =
3393 : 0 : rte_cpu_to_le_16(priv->buf_size >> HNS3_BUF_UNIT_S);
3394 : 0 : req->buf_num[i] |= rte_cpu_to_le_16(1 << HNS3_TC0_PRI_BUF_EN_B);
3395 : : }
3396 : :
3397 : 0 : buf_size = buf_alloc->s_buf.buf_size;
3398 : 0 : req->shared_buf = rte_cpu_to_le_16((buf_size >> HNS3_BUF_UNIT_S) |
3399 : : (1 << HNS3_TC0_PRI_BUF_EN_B));
3400 : :
3401 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
3402 [ # # ]: 0 : if (ret)
3403 : 0 : PMD_INIT_LOG(ERR, "rx private buffer alloc cmd failed %d", ret);
3404 : :
3405 : 0 : return ret;
3406 : : }
3407 : :
3408 : : static int
3409 : 0 : hns3_rx_priv_wl_config(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3410 : : {
3411 : : #define HNS3_RX_PRIV_WL_ALLOC_DESC_NUM 2
3412 : : struct hns3_rx_priv_wl_buf *req;
3413 : : struct hns3_priv_buf *priv;
3414 : : struct hns3_cmd_desc desc[HNS3_RX_PRIV_WL_ALLOC_DESC_NUM];
3415 : : int i, j;
3416 : : int ret;
3417 : :
3418 [ # # ]: 0 : for (i = 0; i < HNS3_RX_PRIV_WL_ALLOC_DESC_NUM; i++) {
3419 : 0 : hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_RX_PRIV_WL_ALLOC,
3420 : : false);
3421 : 0 : req = (struct hns3_rx_priv_wl_buf *)desc[i].data;
3422 : :
3423 : : /* The first descriptor set the NEXT bit to 1 */
3424 [ # # ]: 0 : if (i == 0)
3425 : 0 : desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
3426 : : else
3427 : 0 : desc[i].flag &= ~rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
3428 : :
3429 [ # # ]: 0 : for (j = 0; j < HNS3_TC_NUM_ONE_DESC; j++) {
3430 : 0 : uint32_t idx = i * HNS3_TC_NUM_ONE_DESC + j;
3431 : :
3432 : : priv = &buf_alloc->priv_buf[idx];
3433 : 0 : req->tc_wl[j].high = rte_cpu_to_le_16(priv->wl.high >>
3434 : : HNS3_BUF_UNIT_S);
3435 : 0 : req->tc_wl[j].high |=
3436 : : rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3437 : 0 : req->tc_wl[j].low = rte_cpu_to_le_16(priv->wl.low >>
3438 : : HNS3_BUF_UNIT_S);
3439 : 0 : req->tc_wl[j].low |=
3440 : : rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3441 : : }
3442 : : }
3443 : :
3444 : : /* Send 2 descriptor at one time */
3445 : 0 : ret = hns3_cmd_send(hw, desc, HNS3_RX_PRIV_WL_ALLOC_DESC_NUM);
3446 [ # # ]: 0 : if (ret)
3447 : 0 : PMD_INIT_LOG(ERR, "rx private waterline config cmd failed %d",
3448 : : ret);
3449 : 0 : return ret;
3450 : : }
3451 : :
3452 : : static int
3453 : 0 : hns3_common_thrd_config(struct hns3_hw *hw,
3454 : : struct hns3_pkt_buf_alloc *buf_alloc)
3455 : : {
3456 : : #define HNS3_RX_COM_THRD_ALLOC_DESC_NUM 2
3457 : : struct hns3_shared_buf *s_buf = &buf_alloc->s_buf;
3458 : : struct hns3_rx_com_thrd *req;
3459 : : struct hns3_cmd_desc desc[HNS3_RX_COM_THRD_ALLOC_DESC_NUM];
3460 : : struct hns3_tc_thrd *tc;
3461 : : int tc_idx;
3462 : : int i, j;
3463 : : int ret;
3464 : :
3465 [ # # ]: 0 : for (i = 0; i < HNS3_RX_COM_THRD_ALLOC_DESC_NUM; i++) {
3466 : 0 : hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_RX_COM_THRD_ALLOC,
3467 : : false);
3468 : 0 : req = (struct hns3_rx_com_thrd *)&desc[i].data;
3469 : :
3470 : : /* The first descriptor set the NEXT bit to 1 */
3471 [ # # ]: 0 : if (i == 0)
3472 : 0 : desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
3473 : : else
3474 : 0 : desc[i].flag &= ~rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
3475 : :
3476 [ # # ]: 0 : for (j = 0; j < HNS3_TC_NUM_ONE_DESC; j++) {
3477 : 0 : tc_idx = i * HNS3_TC_NUM_ONE_DESC + j;
3478 : : tc = &s_buf->tc_thrd[tc_idx];
3479 : :
3480 : 0 : req->com_thrd[j].high =
3481 : 0 : rte_cpu_to_le_16(tc->high >> HNS3_BUF_UNIT_S);
3482 : 0 : req->com_thrd[j].high |=
3483 : : rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3484 : 0 : req->com_thrd[j].low =
3485 : 0 : rte_cpu_to_le_16(tc->low >> HNS3_BUF_UNIT_S);
3486 : 0 : req->com_thrd[j].low |=
3487 : : rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3488 : : }
3489 : : }
3490 : :
3491 : : /* Send 2 descriptors at one time */
3492 : 0 : ret = hns3_cmd_send(hw, desc, HNS3_RX_COM_THRD_ALLOC_DESC_NUM);
3493 [ # # ]: 0 : if (ret)
3494 : 0 : PMD_INIT_LOG(ERR, "common threshold config cmd failed %d", ret);
3495 : :
3496 : 0 : return ret;
3497 : : }
3498 : :
3499 : : static int
3500 : 0 : hns3_common_wl_config(struct hns3_hw *hw, struct hns3_pkt_buf_alloc *buf_alloc)
3501 : : {
3502 : : struct hns3_shared_buf *buf = &buf_alloc->s_buf;
3503 : : struct hns3_rx_com_wl *req;
3504 : : struct hns3_cmd_desc desc;
3505 : : int ret;
3506 : :
3507 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RX_COM_WL_ALLOC, false);
3508 : :
3509 : : req = (struct hns3_rx_com_wl *)desc.data;
3510 : 0 : req->com_wl.high = rte_cpu_to_le_16(buf->self.high >> HNS3_BUF_UNIT_S);
3511 : 0 : req->com_wl.high |= rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3512 : :
3513 : 0 : req->com_wl.low = rte_cpu_to_le_16(buf->self.low >> HNS3_BUF_UNIT_S);
3514 : 0 : req->com_wl.low |= rte_cpu_to_le_16(BIT(HNS3_RX_PRIV_EN_B));
3515 : :
3516 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
3517 [ # # ]: 0 : if (ret)
3518 : 0 : PMD_INIT_LOG(ERR, "common waterline config cmd failed %d", ret);
3519 : :
3520 : 0 : return ret;
3521 : : }
3522 : :
3523 : : int
3524 : 0 : hns3_buffer_alloc(struct hns3_hw *hw)
3525 : : {
3526 : : struct hns3_pkt_buf_alloc pkt_buf;
3527 : : int ret;
3528 : :
3529 : : memset(&pkt_buf, 0, sizeof(pkt_buf));
3530 : : ret = hns3_tx_buffer_calc(hw, &pkt_buf);
3531 [ # # ]: 0 : if (ret) {
3532 : 0 : PMD_INIT_LOG(ERR,
3533 : : "could not calc tx buffer size for all TCs %d",
3534 : : ret);
3535 : 0 : return ret;
3536 : : }
3537 : :
3538 : 0 : ret = hns3_tx_buffer_alloc(hw, &pkt_buf);
3539 [ # # ]: 0 : if (ret) {
3540 : 0 : PMD_INIT_LOG(ERR, "could not alloc tx buffers %d", ret);
3541 : 0 : return ret;
3542 : : }
3543 : :
3544 : 0 : ret = hns3_rx_buffer_calc(hw, &pkt_buf);
3545 [ # # ]: 0 : if (ret) {
3546 : 0 : PMD_INIT_LOG(ERR,
3547 : : "could not calc rx priv buffer size for all TCs %d",
3548 : : ret);
3549 : 0 : return ret;
3550 : : }
3551 : :
3552 : 0 : ret = hns3_rx_priv_buf_alloc(hw, &pkt_buf);
3553 [ # # ]: 0 : if (ret) {
3554 : 0 : PMD_INIT_LOG(ERR, "could not alloc rx priv buffer %d", ret);
3555 : 0 : return ret;
3556 : : }
3557 : :
3558 [ # # ]: 0 : if (hns3_dev_get_support(hw, DCB)) {
3559 : 0 : ret = hns3_rx_priv_wl_config(hw, &pkt_buf);
3560 [ # # ]: 0 : if (ret) {
3561 : 0 : PMD_INIT_LOG(ERR,
3562 : : "could not configure rx private waterline %d",
3563 : : ret);
3564 : 0 : return ret;
3565 : : }
3566 : :
3567 : 0 : ret = hns3_common_thrd_config(hw, &pkt_buf);
3568 [ # # ]: 0 : if (ret) {
3569 : 0 : PMD_INIT_LOG(ERR,
3570 : : "could not configure common threshold %d",
3571 : : ret);
3572 : 0 : return ret;
3573 : : }
3574 : : }
3575 : :
3576 : 0 : ret = hns3_common_wl_config(hw, &pkt_buf);
3577 [ # # ]: 0 : if (ret)
3578 : 0 : PMD_INIT_LOG(ERR, "could not configure common waterline %d",
3579 : : ret);
3580 : :
3581 : : return ret;
3582 : : }
3583 : :
3584 : : static int
3585 : 0 : hns3_mac_init(struct hns3_hw *hw)
3586 : : {
3587 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3588 : : struct hns3_mac *mac = &hw->mac;
3589 : : struct hns3_pf *pf = &hns->pf;
3590 : : int ret;
3591 : :
3592 : 0 : pf->support_sfp_query = true;
3593 : 0 : mac->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3594 : 0 : ret = hns3_cfg_mac_speed_dup_hw(hw, mac->link_speed, mac->link_duplex);
3595 [ # # ]: 0 : if (ret) {
3596 : 0 : PMD_INIT_LOG(ERR, "Config mac speed dup fail ret = %d", ret);
3597 : 0 : return ret;
3598 : : }
3599 : :
3600 : 0 : mac->link_status = RTE_ETH_LINK_DOWN;
3601 : :
3602 : 0 : return hns3_config_mtu(hw, pf->mps);
3603 : : }
3604 : :
3605 : : static int
3606 : 0 : hns3_get_mac_ethertype_cmd_status(uint16_t cmdq_resp, uint8_t resp_code)
3607 : : {
3608 : : #define HNS3_ETHERTYPE_SUCCESS_ADD 0
3609 : : #define HNS3_ETHERTYPE_ALREADY_ADD 1
3610 : : #define HNS3_ETHERTYPE_MGR_TBL_OVERFLOW 2
3611 : : #define HNS3_ETHERTYPE_KEY_CONFLICT 3
3612 : : int return_status;
3613 : :
3614 [ # # ]: 0 : if (cmdq_resp) {
3615 : 0 : PMD_INIT_LOG(ERR,
3616 : : "cmdq execute failed for get_mac_ethertype_cmd_status, status=%u.",
3617 : : cmdq_resp);
3618 : 0 : return -EIO;
3619 : : }
3620 : :
3621 [ # # # # ]: 0 : switch (resp_code) {
3622 : : case HNS3_ETHERTYPE_SUCCESS_ADD:
3623 : : case HNS3_ETHERTYPE_ALREADY_ADD:
3624 : : return_status = 0;
3625 : : break;
3626 : 0 : case HNS3_ETHERTYPE_MGR_TBL_OVERFLOW:
3627 : 0 : PMD_INIT_LOG(ERR,
3628 : : "add mac ethertype failed for manager table overflow.");
3629 : : return_status = -EIO;
3630 : 0 : break;
3631 : 0 : case HNS3_ETHERTYPE_KEY_CONFLICT:
3632 : 0 : PMD_INIT_LOG(ERR, "add mac ethertype failed for key conflict.");
3633 : : return_status = -EIO;
3634 : 0 : break;
3635 : 0 : default:
3636 : 0 : PMD_INIT_LOG(ERR,
3637 : : "add mac ethertype failed for undefined, code=%u.",
3638 : : resp_code);
3639 : : return_status = -EIO;
3640 : 0 : break;
3641 : : }
3642 : :
3643 : : return return_status;
3644 : : }
3645 : :
3646 : : static int
3647 : 0 : hns3_add_mgr_tbl(struct hns3_hw *hw,
3648 : : const struct hns3_mac_mgr_tbl_entry_cmd *req)
3649 : : {
3650 : : struct hns3_cmd_desc desc;
3651 : : uint8_t resp_code;
3652 : : uint16_t retval;
3653 : : int ret;
3654 : :
3655 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MAC_ETHTYPE_ADD, false);
3656 : : memcpy(desc.data, req, sizeof(struct hns3_mac_mgr_tbl_entry_cmd));
3657 : :
3658 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
3659 [ # # ]: 0 : if (ret) {
3660 : 0 : PMD_INIT_LOG(ERR,
3661 : : "add mac ethertype failed for cmd_send, ret =%d.",
3662 : : ret);
3663 : 0 : return ret;
3664 : : }
3665 : :
3666 : 0 : resp_code = (rte_le_to_cpu_32(desc.data[0]) >> 8) & 0xff;
3667 : 0 : retval = rte_le_to_cpu_16(desc.retval);
3668 : :
3669 : 0 : return hns3_get_mac_ethertype_cmd_status(retval, resp_code);
3670 : : }
3671 : :
3672 : : static void
3673 : : hns3_prepare_mgr_tbl(struct hns3_mac_mgr_tbl_entry_cmd *mgr_table,
3674 : : int *table_item_num)
3675 : : {
3676 : : struct hns3_mac_mgr_tbl_entry_cmd *tbl;
3677 : :
3678 : : /*
3679 : : * In current version, we add one item in management table as below:
3680 : : * 0x0180C200000E -- LLDP MC address
3681 : : */
3682 : : tbl = mgr_table;
3683 : 0 : tbl->flags = HNS3_MAC_MGR_MASK_VLAN_B;
3684 : 0 : tbl->ethter_type = rte_cpu_to_le_16(HNS3_MAC_ETHERTYPE_LLDP);
3685 : 0 : tbl->mac_addr_hi32 = rte_cpu_to_le_32(htonl(0x0180C200));
3686 : 0 : tbl->mac_addr_lo16 = rte_cpu_to_le_16(htons(0x000E));
3687 : 0 : tbl->i_port_bitmap = 0x1;
3688 : : *table_item_num = 1;
3689 : : }
3690 : :
3691 : : static int
3692 : 0 : hns3_init_mgr_tbl(struct hns3_hw *hw)
3693 : : {
3694 : : #define HNS_MAC_MGR_TBL_MAX_SIZE 16
3695 : : struct hns3_mac_mgr_tbl_entry_cmd mgr_table[HNS_MAC_MGR_TBL_MAX_SIZE];
3696 : : int table_item_num;
3697 : : int ret;
3698 : : int i;
3699 : :
3700 : : memset(mgr_table, 0, sizeof(mgr_table));
3701 : : hns3_prepare_mgr_tbl(mgr_table, &table_item_num);
3702 [ # # ]: 0 : for (i = 0; i < table_item_num; i++) {
3703 : 0 : ret = hns3_add_mgr_tbl(hw, &mgr_table[i]);
3704 [ # # ]: 0 : if (ret) {
3705 : 0 : PMD_INIT_LOG(ERR, "add mac ethertype failed, ret =%d",
3706 : : ret);
3707 : 0 : return ret;
3708 : : }
3709 : : }
3710 : :
3711 : : return 0;
3712 : : }
3713 : :
3714 : : static void
3715 : 0 : hns3_promisc_param_init(struct hns3_promisc_param *param, bool en_uc,
3716 : : bool en_mc, bool en_bc, int vport_id)
3717 : : {
3718 [ # # ]: 0 : if (!param)
3719 : : return;
3720 : :
3721 : : memset(param, 0, sizeof(struct hns3_promisc_param));
3722 [ # # ]: 0 : if (en_uc)
3723 : 0 : param->enable = HNS3_PROMISC_EN_UC;
3724 [ # # ]: 0 : if (en_mc)
3725 : 0 : param->enable |= HNS3_PROMISC_EN_MC;
3726 [ # # ]: 0 : if (en_bc)
3727 : 0 : param->enable |= HNS3_PROMISC_EN_BC;
3728 : 0 : param->vf_id = vport_id;
3729 : : }
3730 : :
3731 : : static int
3732 : 0 : hns3_cmd_set_promisc_mode(struct hns3_hw *hw, struct hns3_promisc_param *param)
3733 : : {
3734 : : struct hns3_promisc_cfg_cmd *req;
3735 : : struct hns3_cmd_desc desc;
3736 : : int ret;
3737 : :
3738 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_PROMISC_MODE, false);
3739 : :
3740 : : req = (struct hns3_promisc_cfg_cmd *)desc.data;
3741 : 0 : req->vf_id = param->vf_id;
3742 : 0 : req->flag = (param->enable << HNS3_PROMISC_EN_B) |
3743 : : HNS3_PROMISC_TX_EN_B | HNS3_PROMISC_RX_EN_B;
3744 : :
3745 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
3746 [ # # ]: 0 : if (ret)
3747 : 0 : PMD_INIT_LOG(ERR, "Set promisc mode fail, ret = %d", ret);
3748 : :
3749 : 0 : return ret;
3750 : : }
3751 : :
3752 : : static int
3753 : 0 : hns3_set_promisc_mode(struct hns3_hw *hw, bool en_uc_pmc, bool en_mc_pmc)
3754 : : {
3755 : : struct hns3_promisc_param param;
3756 : : bool en_bc_pmc = true;
3757 : : uint8_t vf_id;
3758 : :
3759 : : /*
3760 : : * In current version VF is not supported when PF is driven by DPDK
3761 : : * driver, just need to configure parameters for PF vport.
3762 : : */
3763 : : vf_id = HNS3_PF_FUNC_ID;
3764 : :
3765 : 0 : hns3_promisc_param_init(¶m, en_uc_pmc, en_mc_pmc, en_bc_pmc, vf_id);
3766 : 0 : return hns3_cmd_set_promisc_mode(hw, ¶m);
3767 : : }
3768 : :
3769 : : static int
3770 : 0 : hns3_promisc_init(struct hns3_hw *hw)
3771 : : {
3772 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
3773 : : struct hns3_pf *pf = &hns->pf;
3774 : : struct hns3_promisc_param param;
3775 : : uint16_t func_id;
3776 : : int ret;
3777 : :
3778 : 0 : ret = hns3_set_promisc_mode(hw, false, false);
3779 [ # # ]: 0 : if (ret) {
3780 : 0 : PMD_INIT_LOG(ERR, "failed to set promisc mode, ret = %d", ret);
3781 : 0 : return ret;
3782 : : }
3783 : :
3784 : : /*
3785 : : * In current version VFs are not supported when PF is driven by DPDK
3786 : : * driver. After PF has been taken over by DPDK, the original VF will
3787 : : * be invalid. So, there is a possibility of entry residues. It should
3788 : : * clear VFs's promisc mode to avoid unnecessary bandwidth usage
3789 : : * during init.
3790 : : */
3791 [ # # ]: 0 : for (func_id = HNS3_1ST_VF_FUNC_ID; func_id < pf->func_num; func_id++) {
3792 : 0 : hns3_promisc_param_init(¶m, false, false, false, func_id);
3793 : 0 : ret = hns3_cmd_set_promisc_mode(hw, ¶m);
3794 [ # # ]: 0 : if (ret) {
3795 : 0 : PMD_INIT_LOG(ERR, "failed to clear vf:%u promisc mode,"
3796 : : " ret = %d", func_id, ret);
3797 : 0 : return ret;
3798 : : }
3799 : : }
3800 : :
3801 : : return 0;
3802 : : }
3803 : :
3804 : : static void
3805 : 0 : hns3_promisc_uninit(struct hns3_hw *hw)
3806 : : {
3807 : : struct hns3_promisc_param param;
3808 : : uint16_t func_id;
3809 : : int ret;
3810 : :
3811 : : func_id = HNS3_PF_FUNC_ID;
3812 : :
3813 : : /*
3814 : : * In current version VFs are not supported when PF is driven by
3815 : : * DPDK driver, and VFs' promisc mode status has been cleared during
3816 : : * init and their status will not change. So just clear PF's promisc
3817 : : * mode status during uninit.
3818 : : */
3819 : : hns3_promisc_param_init(¶m, false, false, false, func_id);
3820 : 0 : ret = hns3_cmd_set_promisc_mode(hw, ¶m);
3821 [ # # ]: 0 : if (ret)
3822 : 0 : PMD_INIT_LOG(ERR, "failed to clear promisc status during"
3823 : : " uninit, ret = %d", ret);
3824 : 0 : }
3825 : :
3826 : : static int
3827 : 0 : hns3_dev_promiscuous_enable(struct rte_eth_dev *dev)
3828 : : {
3829 : 0 : bool allmulti = dev->data->all_multicast ? true : false;
3830 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
3831 : 0 : struct hns3_hw *hw = &hns->hw;
3832 : : uint64_t offloads;
3833 : : int err;
3834 : : int ret;
3835 : :
3836 : 0 : rte_spinlock_lock(&hw->lock);
3837 : 0 : ret = hns3_set_promisc_mode(hw, true, true);
3838 [ # # ]: 0 : if (ret) {
3839 : : rte_spinlock_unlock(&hw->lock);
3840 : 0 : hns3_err(hw, "failed to enable promiscuous mode, ret = %d",
3841 : : ret);
3842 : 0 : return ret;
3843 : : }
3844 : :
3845 : : /*
3846 : : * When promiscuous mode was enabled, disable the vlan filter to let
3847 : : * all packets coming in the receiving direction.
3848 : : */
3849 : 0 : offloads = dev->data->dev_conf.rxmode.offloads;
3850 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
3851 : 0 : ret = hns3_enable_vlan_filter(hns, false);
3852 [ # # ]: 0 : if (ret) {
3853 : 0 : hns3_err(hw, "failed to enable promiscuous mode due to "
3854 : : "failure to disable vlan filter, ret = %d",
3855 : : ret);
3856 : 0 : err = hns3_set_promisc_mode(hw, false, allmulti);
3857 [ # # ]: 0 : if (err)
3858 : 0 : hns3_err(hw, "failed to restore promiscuous "
3859 : : "status after disable vlan filter "
3860 : : "failed during enabling promiscuous "
3861 : : "mode, ret = %d", ret);
3862 : : }
3863 : : }
3864 : :
3865 : : rte_spinlock_unlock(&hw->lock);
3866 : :
3867 : 0 : return ret;
3868 : : }
3869 : :
3870 : : static int
3871 : 0 : hns3_dev_promiscuous_disable(struct rte_eth_dev *dev)
3872 : : {
3873 : 0 : bool allmulti = dev->data->all_multicast ? true : false;
3874 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
3875 : 0 : struct hns3_hw *hw = &hns->hw;
3876 : : uint64_t offloads;
3877 : : int err;
3878 : : int ret;
3879 : :
3880 : : /* If now in all_multicast mode, must remain in all_multicast mode. */
3881 : 0 : rte_spinlock_lock(&hw->lock);
3882 : 0 : ret = hns3_set_promisc_mode(hw, false, allmulti);
3883 [ # # ]: 0 : if (ret) {
3884 : : rte_spinlock_unlock(&hw->lock);
3885 : 0 : hns3_err(hw, "failed to disable promiscuous mode, ret = %d",
3886 : : ret);
3887 : 0 : return ret;
3888 : : }
3889 : : /* when promiscuous mode was disabled, restore the vlan filter status */
3890 : 0 : offloads = dev->data->dev_conf.rxmode.offloads;
3891 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
3892 : 0 : ret = hns3_enable_vlan_filter(hns, true);
3893 [ # # ]: 0 : if (ret) {
3894 : 0 : hns3_err(hw, "failed to disable promiscuous mode due to"
3895 : : " failure to restore vlan filter, ret = %d",
3896 : : ret);
3897 : 0 : err = hns3_set_promisc_mode(hw, true, true);
3898 [ # # ]: 0 : if (err)
3899 : 0 : hns3_err(hw, "failed to restore promiscuous "
3900 : : "status after enabling vlan filter "
3901 : : "failed during disabling promiscuous "
3902 : : "mode, ret = %d", ret);
3903 : : }
3904 : : }
3905 : : rte_spinlock_unlock(&hw->lock);
3906 : :
3907 : 0 : return ret;
3908 : : }
3909 : :
3910 : : static int
3911 : 0 : hns3_dev_allmulticast_enable(struct rte_eth_dev *dev)
3912 : : {
3913 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
3914 : 0 : struct hns3_hw *hw = &hns->hw;
3915 : : int ret;
3916 : :
3917 [ # # ]: 0 : if (dev->data->promiscuous)
3918 : : return 0;
3919 : :
3920 : 0 : rte_spinlock_lock(&hw->lock);
3921 : 0 : ret = hns3_set_promisc_mode(hw, false, true);
3922 : : rte_spinlock_unlock(&hw->lock);
3923 [ # # ]: 0 : if (ret)
3924 : 0 : hns3_err(hw, "failed to enable allmulticast mode, ret = %d",
3925 : : ret);
3926 : :
3927 : : return ret;
3928 : : }
3929 : :
3930 : : static int
3931 : 0 : hns3_dev_allmulticast_disable(struct rte_eth_dev *dev)
3932 : : {
3933 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
3934 : 0 : struct hns3_hw *hw = &hns->hw;
3935 : : int ret;
3936 : :
3937 : : /* If now in promiscuous mode, must remain in all_multicast mode. */
3938 [ # # ]: 0 : if (dev->data->promiscuous)
3939 : : return 0;
3940 : :
3941 : 0 : rte_spinlock_lock(&hw->lock);
3942 : 0 : ret = hns3_set_promisc_mode(hw, false, false);
3943 : : rte_spinlock_unlock(&hw->lock);
3944 [ # # ]: 0 : if (ret)
3945 : 0 : hns3_err(hw, "failed to disable allmulticast mode, ret = %d",
3946 : : ret);
3947 : :
3948 : : return ret;
3949 : : }
3950 : :
3951 : : static int
3952 : 0 : hns3_dev_promisc_restore(struct hns3_adapter *hns)
3953 : : {
3954 : 0 : struct hns3_hw *hw = &hns->hw;
3955 : 0 : bool allmulti = hw->data->all_multicast ? true : false;
3956 : : int ret;
3957 : :
3958 [ # # ]: 0 : if (hw->data->promiscuous) {
3959 : 0 : ret = hns3_set_promisc_mode(hw, true, true);
3960 [ # # ]: 0 : if (ret)
3961 : 0 : hns3_err(hw, "failed to restore promiscuous mode, "
3962 : : "ret = %d", ret);
3963 : 0 : return ret;
3964 : : }
3965 : :
3966 : 0 : ret = hns3_set_promisc_mode(hw, false, allmulti);
3967 [ # # ]: 0 : if (ret)
3968 : 0 : hns3_err(hw, "failed to restore allmulticast mode, ret = %d",
3969 : : ret);
3970 : : return ret;
3971 : : }
3972 : :
3973 : : static int
3974 : 0 : hns3_get_sfp_info(struct hns3_hw *hw, struct hns3_mac *mac_info)
3975 : : {
3976 : : struct hns3_sfp_info_cmd *resp;
3977 : : uint32_t local_pause, lp_pause;
3978 : : struct hns3_cmd_desc desc;
3979 : : int ret;
3980 : :
3981 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_GET_SFP_INFO, true);
3982 : : resp = (struct hns3_sfp_info_cmd *)desc.data;
3983 : 0 : resp->query_type = HNS3_ACTIVE_QUERY;
3984 : :
3985 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
3986 [ # # ]: 0 : if (ret == -EOPNOTSUPP) {
3987 : 0 : hns3_warn(hw, "firmware does not support get SFP info,"
3988 : : " ret = %d.", ret);
3989 : 0 : return ret;
3990 [ # # ]: 0 : } else if (ret) {
3991 : 0 : hns3_err(hw, "get sfp info failed, ret = %d.", ret);
3992 : 0 : return ret;
3993 : : }
3994 : :
3995 : : /*
3996 : : * In some case, the speed of MAC obtained from firmware may be 0, it
3997 : : * shouldn't be set to mac->speed.
3998 : : */
3999 [ # # ]: 0 : if (!rte_le_to_cpu_32(resp->sfp_speed))
4000 : : return 0;
4001 : :
4002 : 0 : mac_info->link_speed = rte_le_to_cpu_32(resp->sfp_speed);
4003 : : /*
4004 : : * if resp->supported_speed is 0, it means it's an old version
4005 : : * firmware, do not update these params.
4006 : : */
4007 [ # # ]: 0 : if (resp->supported_speed) {
4008 : 0 : mac_info->query_type = HNS3_ACTIVE_QUERY;
4009 : 0 : mac_info->supported_speed =
4010 : : rte_le_to_cpu_32(resp->supported_speed);
4011 : 0 : mac_info->support_autoneg = resp->autoneg_ability;
4012 : 0 : mac_info->link_autoneg = (resp->autoneg == 0) ? RTE_ETH_LINK_FIXED
4013 : 0 : : RTE_ETH_LINK_AUTONEG;
4014 : 0 : mac_info->fec_capa = resp->fec_ability;
4015 : 0 : local_pause = resp->pause_status & HNS3_FIBER_LOCAL_PAUSE_MASK;
4016 : 0 : lp_pause = (resp->pause_status & HNS3_FIBER_LP_PAUSE_MASK) >>
4017 : : HNS3_FIBER_LP_PAUSE_S;
4018 : 0 : mac_info->advertising =
4019 : 0 : local_pause << HNS3_PHY_LINK_MODE_PAUSE_S;
4020 : 0 : mac_info->lp_advertising =
4021 : 0 : lp_pause << HNS3_PHY_LINK_MODE_PAUSE_S;
4022 : : } else {
4023 : 0 : mac_info->query_type = HNS3_DEFAULT_QUERY;
4024 : : }
4025 : :
4026 : : return 0;
4027 : : }
4028 : :
4029 : : static uint8_t
4030 : : hns3_check_speed_dup(uint8_t duplex, uint32_t speed)
4031 : : {
4032 : 0 : if (!(speed == RTE_ETH_SPEED_NUM_10M || speed == RTE_ETH_SPEED_NUM_100M))
4033 : : duplex = RTE_ETH_LINK_FULL_DUPLEX;
4034 : :
4035 : : return duplex;
4036 : : }
4037 : :
4038 : : static int
4039 [ # # ]: 0 : hns3_cfg_mac_speed_dup(struct hns3_hw *hw, uint32_t speed, uint8_t duplex)
4040 : : {
4041 : : struct hns3_mac *mac = &hw->mac;
4042 : : int ret;
4043 : :
4044 : : duplex = hns3_check_speed_dup(duplex, speed);
4045 [ # # # # ]: 0 : if (mac->link_speed == speed && mac->link_duplex == duplex)
4046 : : return 0;
4047 : :
4048 : 0 : ret = hns3_cfg_mac_speed_dup_hw(hw, speed, duplex);
4049 [ # # ]: 0 : if (ret)
4050 : : return ret;
4051 : :
4052 : 0 : ret = hns3_port_shaper_update(hw, speed);
4053 [ # # ]: 0 : if (ret)
4054 : : return ret;
4055 : :
4056 : 0 : mac->link_speed = speed;
4057 : 0 : mac->link_duplex = duplex;
4058 : :
4059 : 0 : return 0;
4060 : : }
4061 : :
4062 : : static int
4063 : 0 : hns3_update_fiber_link_info(struct hns3_hw *hw)
4064 : : {
4065 : : struct hns3_pf *pf = HNS3_DEV_HW_TO_PF(hw);
4066 : : struct hns3_mac *mac = &hw->mac;
4067 : : struct hns3_mac mac_info;
4068 : : int ret;
4069 : :
4070 : : /* If firmware do not support get SFP/qSFP speed, return directly */
4071 [ # # ]: 0 : if (!pf->support_sfp_query)
4072 : : return 0;
4073 : :
4074 : : memset(&mac_info, 0, sizeof(struct hns3_mac));
4075 : 0 : ret = hns3_get_sfp_info(hw, &mac_info);
4076 [ # # ]: 0 : if (ret == -EOPNOTSUPP) {
4077 : 0 : pf->support_sfp_query = false;
4078 : 0 : return ret;
4079 [ # # ]: 0 : } else if (ret)
4080 : : return ret;
4081 : :
4082 : : /* Do nothing if no SFP */
4083 [ # # ]: 0 : if (mac_info.link_speed == RTE_ETH_SPEED_NUM_NONE)
4084 : : return 0;
4085 : :
4086 : : /*
4087 : : * If query_type is HNS3_ACTIVE_QUERY, it is no need
4088 : : * to reconfigure the speed of MAC. Otherwise, it indicates
4089 : : * that the current firmware only supports to obtain the
4090 : : * speed of the SFP, and the speed of MAC needs to reconfigure.
4091 : : */
4092 : 0 : mac->query_type = mac_info.query_type;
4093 [ # # ]: 0 : if (mac->query_type == HNS3_ACTIVE_QUERY) {
4094 [ # # ]: 0 : if (mac_info.link_speed != mac->link_speed) {
4095 : 0 : ret = hns3_port_shaper_update(hw, mac_info.link_speed);
4096 [ # # ]: 0 : if (ret)
4097 : : return ret;
4098 : : }
4099 : :
4100 : 0 : mac->link_speed = mac_info.link_speed;
4101 : 0 : mac->supported_speed = mac_info.supported_speed;
4102 : 0 : mac->support_autoneg = mac_info.support_autoneg;
4103 : 0 : mac->link_autoneg = mac_info.link_autoneg;
4104 : 0 : mac->fec_capa = mac_info.fec_capa;
4105 : 0 : mac->advertising = mac_info.advertising;
4106 : 0 : mac->lp_advertising = mac_info.lp_advertising;
4107 : :
4108 : 0 : return 0;
4109 : : }
4110 : :
4111 : : /* Config full duplex for SFP */
4112 : 0 : return hns3_cfg_mac_speed_dup(hw, mac_info.link_speed,
4113 : : RTE_ETH_LINK_FULL_DUPLEX);
4114 : : }
4115 : :
4116 : : static void
4117 : : hns3_parse_copper_phy_params(struct hns3_cmd_desc *desc, struct hns3_mac *mac)
4118 : : {
4119 : : #define HNS3_PHY_SUPPORTED_SPEED_MASK 0x2f
4120 : :
4121 : : struct hns3_phy_params_bd0_cmd *req;
4122 : : uint32_t supported;
4123 : :
4124 : : req = (struct hns3_phy_params_bd0_cmd *)desc[0].data;
4125 : 0 : mac->link_speed = rte_le_to_cpu_32(req->speed);
4126 : 0 : mac->link_duplex = hns3_get_bit(req->duplex,
4127 : : HNS3_PHY_DUPLEX_CFG_B);
4128 : 0 : mac->link_autoneg = hns3_get_bit(req->autoneg,
4129 : : HNS3_PHY_AUTONEG_CFG_B);
4130 : 0 : mac->advertising = rte_le_to_cpu_32(req->advertising);
4131 : 0 : mac->lp_advertising = rte_le_to_cpu_32(req->lp_advertising);
4132 : 0 : supported = rte_le_to_cpu_32(req->supported);
4133 : 0 : mac->supported_speed = supported & HNS3_PHY_SUPPORTED_SPEED_MASK;
4134 : 0 : mac->support_autoneg = !!(supported & HNS3_PHY_LINK_MODE_AUTONEG_BIT);
4135 : : }
4136 : :
4137 : : static int
4138 : 0 : hns3_get_copper_phy_params(struct hns3_hw *hw, struct hns3_mac *mac)
4139 : : {
4140 : : struct hns3_cmd_desc desc[HNS3_PHY_PARAM_CFG_BD_NUM];
4141 : : uint16_t i;
4142 : : int ret;
4143 : :
4144 [ # # ]: 0 : for (i = 0; i < HNS3_PHY_PARAM_CFG_BD_NUM - 1; i++) {
4145 : 0 : hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_PHY_PARAM_CFG,
4146 : : true);
4147 : 0 : desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
4148 : : }
4149 : 0 : hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_PHY_PARAM_CFG, true);
4150 : :
4151 : 0 : ret = hns3_cmd_send(hw, desc, HNS3_PHY_PARAM_CFG_BD_NUM);
4152 [ # # ]: 0 : if (ret) {
4153 : 0 : hns3_err(hw, "get phy parameters failed, ret = %d.", ret);
4154 : 0 : return ret;
4155 : : }
4156 : :
4157 : : hns3_parse_copper_phy_params(desc, mac);
4158 : :
4159 : 0 : return 0;
4160 : : }
4161 : :
4162 : : static int
4163 : 0 : hns3_update_copper_link_info(struct hns3_hw *hw)
4164 : : {
4165 : : struct hns3_mac *mac = &hw->mac;
4166 : : struct hns3_mac mac_info;
4167 : : int ret;
4168 : :
4169 : : memset(&mac_info, 0, sizeof(struct hns3_mac));
4170 : 0 : ret = hns3_get_copper_phy_params(hw, &mac_info);
4171 [ # # ]: 0 : if (ret)
4172 : : return ret;
4173 : :
4174 [ # # ]: 0 : if (mac_info.link_speed != mac->link_speed) {
4175 : 0 : ret = hns3_port_shaper_update(hw, mac_info.link_speed);
4176 [ # # ]: 0 : if (ret)
4177 : : return ret;
4178 : : }
4179 : :
4180 : 0 : mac->link_speed = mac_info.link_speed;
4181 : 0 : mac->link_duplex = mac_info.link_duplex;
4182 : 0 : mac->link_autoneg = mac_info.link_autoneg;
4183 : 0 : mac->supported_speed = mac_info.supported_speed;
4184 : 0 : mac->advertising = mac_info.advertising;
4185 : 0 : mac->lp_advertising = mac_info.lp_advertising;
4186 : 0 : mac->support_autoneg = mac_info.support_autoneg;
4187 : :
4188 : 0 : return 0;
4189 : : }
4190 : :
4191 : : static int
4192 : 0 : hns3_update_link_info(struct rte_eth_dev *eth_dev)
4193 : : {
4194 : 0 : struct hns3_adapter *hns = eth_dev->data->dev_private;
4195 : 0 : struct hns3_hw *hw = &hns->hw;
4196 : :
4197 [ # # ]: 0 : if (hw->mac.media_type == HNS3_MEDIA_TYPE_COPPER)
4198 : 0 : return hns3_update_copper_link_info(hw);
4199 : :
4200 : 0 : return hns3_update_fiber_link_info(hw);
4201 : : }
4202 : :
4203 : : static int
4204 : 0 : hns3_cfg_mac_mode(struct hns3_hw *hw, bool enable)
4205 : : {
4206 : : struct hns3_config_mac_mode_cmd *req;
4207 : : struct hns3_cmd_desc desc;
4208 : : uint32_t loop_en = 0;
4209 : : uint8_t val = 0;
4210 : : int ret;
4211 : :
4212 : : req = (struct hns3_config_mac_mode_cmd *)desc.data;
4213 : :
4214 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_MAC_MODE, false);
4215 [ # # ]: 0 : if (enable)
4216 : : val = 1;
4217 : 0 : hns3_set_bit(loop_en, HNS3_MAC_TX_EN_B, val);
4218 : 0 : hns3_set_bit(loop_en, HNS3_MAC_RX_EN_B, val);
4219 : 0 : hns3_set_bit(loop_en, HNS3_MAC_PAD_TX_B, val);
4220 : 0 : hns3_set_bit(loop_en, HNS3_MAC_PAD_RX_B, val);
4221 : : hns3_set_bit(loop_en, HNS3_MAC_1588_TX_B, 0);
4222 : : hns3_set_bit(loop_en, HNS3_MAC_1588_RX_B, 0);
4223 : : hns3_set_bit(loop_en, HNS3_MAC_APP_LP_B, 0);
4224 : : hns3_set_bit(loop_en, HNS3_MAC_LINE_LP_B, 0);
4225 : 0 : hns3_set_bit(loop_en, HNS3_MAC_FCS_TX_B, val);
4226 : 0 : hns3_set_bit(loop_en, HNS3_MAC_RX_FCS_B, val);
4227 : :
4228 : : /*
4229 : : * If RTE_ETH_RX_OFFLOAD_KEEP_CRC offload is set, MAC will not strip CRC
4230 : : * when receiving frames. Otherwise, CRC will be stripped.
4231 : : */
4232 [ # # ]: 0 : if (hw->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
4233 : : hns3_set_bit(loop_en, HNS3_MAC_RX_FCS_STRIP_B, 0);
4234 : : else
4235 : 0 : hns3_set_bit(loop_en, HNS3_MAC_RX_FCS_STRIP_B, val);
4236 : 0 : hns3_set_bit(loop_en, HNS3_MAC_TX_OVERSIZE_TRUNCATE_B, val);
4237 : 0 : hns3_set_bit(loop_en, HNS3_MAC_RX_OVERSIZE_TRUNCATE_B, val);
4238 : 0 : hns3_set_bit(loop_en, HNS3_MAC_TX_UNDER_MIN_ERR_B, val);
4239 : 0 : req->txrx_pad_fcs_loop_en = rte_cpu_to_le_32(loop_en);
4240 : :
4241 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
4242 [ # # ]: 0 : if (ret)
4243 : 0 : PMD_INIT_LOG(ERR, "mac enable fail, ret =%d.", ret);
4244 : :
4245 : 0 : return ret;
4246 : : }
4247 : :
4248 : : static int
4249 : 0 : hns3_get_mac_link_status(struct hns3_hw *hw)
4250 : : {
4251 : : struct hns3_link_status_cmd *req;
4252 : : struct hns3_cmd_desc desc;
4253 : : int link_status;
4254 : : int ret;
4255 : :
4256 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_LINK_STATUS, true);
4257 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
4258 [ # # ]: 0 : if (ret) {
4259 : 0 : hns3_err(hw, "get link status cmd failed %d", ret);
4260 : 0 : return RTE_ETH_LINK_DOWN;
4261 : : }
4262 : :
4263 : : req = (struct hns3_link_status_cmd *)desc.data;
4264 : 0 : link_status = req->status & HNS3_LINK_STATUS_UP_M;
4265 : :
4266 : 0 : return !!link_status;
4267 : : }
4268 : :
4269 : : static bool
4270 : 0 : hns3_update_link_status(struct hns3_hw *hw)
4271 : : {
4272 : : int state;
4273 : :
4274 : 0 : state = hns3_get_mac_link_status(hw);
4275 [ # # ]: 0 : if (state != hw->mac.link_status) {
4276 : 0 : hw->mac.link_status = state;
4277 [ # # ]: 0 : hns3_warn(hw, "Link status change to %s!", state ? "up" : "down");
4278 : 0 : return true;
4279 : : }
4280 : :
4281 : : return false;
4282 : : }
4283 : :
4284 : : void
4285 : 0 : hns3_update_linkstatus_and_event(struct hns3_hw *hw, bool query)
4286 : : {
4287 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id];
4288 : : struct rte_eth_link new_link;
4289 : : int ret;
4290 : :
4291 [ # # ]: 0 : if (query)
4292 : 0 : hns3_update_port_link_info(dev);
4293 : :
4294 : : memset(&new_link, 0, sizeof(new_link));
4295 : 0 : hns3_setup_linkstatus(dev, &new_link);
4296 : :
4297 : : ret = rte_eth_linkstatus_set(dev, &new_link);
4298 [ # # ]: 0 : if (ret == 0 && dev->data->dev_conf.intr_conf.lsc != 0)
4299 : 0 : hns3_start_report_lse(dev);
4300 : 0 : }
4301 : :
4302 : : static void
4303 : 0 : hns3_service_handler(void *param)
4304 : : {
4305 : : struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
4306 : 0 : struct hns3_adapter *hns = eth_dev->data->dev_private;
4307 : 0 : struct hns3_hw *hw = &hns->hw;
4308 : :
4309 [ # # ]: 0 : if (!hns3_is_reset_pending(hns)) {
4310 : 0 : hns3_update_linkstatus_and_event(hw, true);
4311 : 0 : hns3_update_hw_stats(hw);
4312 : : } else {
4313 : 0 : hns3_warn(hw, "Cancel the query when reset is pending");
4314 : : }
4315 : :
4316 : 0 : rte_eal_alarm_set(HNS3_SERVICE_INTERVAL, hns3_service_handler, eth_dev);
4317 : 0 : }
4318 : :
4319 : : static int
4320 : 0 : hns3_init_hardware(struct hns3_adapter *hns)
4321 : : {
4322 : 0 : struct hns3_hw *hw = &hns->hw;
4323 : : int ret;
4324 : :
4325 : : /*
4326 : : * All queue-related HW operations must be performed after the TCAM
4327 : : * table is configured.
4328 : : */
4329 : 0 : ret = hns3_map_tqp(hw);
4330 [ # # ]: 0 : if (ret) {
4331 : 0 : PMD_INIT_LOG(ERR, "Failed to map tqp: %d", ret);
4332 : 0 : return ret;
4333 : : }
4334 : :
4335 : 0 : ret = hns3_init_umv_space(hw);
4336 [ # # ]: 0 : if (ret) {
4337 : 0 : PMD_INIT_LOG(ERR, "Failed to init umv space: %d", ret);
4338 : 0 : return ret;
4339 : : }
4340 : :
4341 : 0 : ret = hns3_mac_init(hw);
4342 [ # # ]: 0 : if (ret) {
4343 : 0 : PMD_INIT_LOG(ERR, "Failed to init MAC: %d", ret);
4344 : 0 : goto err_mac_init;
4345 : : }
4346 : :
4347 : 0 : ret = hns3_init_mgr_tbl(hw);
4348 [ # # ]: 0 : if (ret) {
4349 : 0 : PMD_INIT_LOG(ERR, "Failed to init manager table: %d", ret);
4350 : 0 : goto err_mac_init;
4351 : : }
4352 : :
4353 : 0 : ret = hns3_promisc_init(hw);
4354 [ # # ]: 0 : if (ret) {
4355 : 0 : PMD_INIT_LOG(ERR, "Failed to init promisc: %d",
4356 : : ret);
4357 : 0 : goto err_mac_init;
4358 : : }
4359 : :
4360 : 0 : ret = hns3_init_vlan_config(hns);
4361 [ # # ]: 0 : if (ret) {
4362 : 0 : PMD_INIT_LOG(ERR, "Failed to init vlan: %d", ret);
4363 : 0 : goto err_mac_init;
4364 : : }
4365 : :
4366 : 0 : ret = hns3_dcb_init(hw);
4367 [ # # ]: 0 : if (ret) {
4368 : 0 : PMD_INIT_LOG(ERR, "Failed to init dcb: %d", ret);
4369 : 0 : goto err_mac_init;
4370 : : }
4371 : :
4372 : 0 : ret = hns3_init_fd_config(hns);
4373 [ # # ]: 0 : if (ret) {
4374 : 0 : PMD_INIT_LOG(ERR, "Failed to init flow director: %d", ret);
4375 : 0 : goto err_mac_init;
4376 : : }
4377 : :
4378 : 0 : ret = hns3_config_tso(hw, HNS3_TSO_MSS_MIN, HNS3_TSO_MSS_MAX);
4379 [ # # ]: 0 : if (ret) {
4380 : 0 : PMD_INIT_LOG(ERR, "Failed to config tso: %d", ret);
4381 : 0 : goto err_mac_init;
4382 : : }
4383 : :
4384 : 0 : ret = hns3_config_gro(hw, false);
4385 [ # # ]: 0 : if (ret) {
4386 : 0 : PMD_INIT_LOG(ERR, "Failed to config gro: %d", ret);
4387 : 0 : goto err_mac_init;
4388 : : }
4389 : :
4390 : : /*
4391 : : * In the initialization clearing the all hardware mapping relationship
4392 : : * configurations between queues and interrupt vectors is needed, so
4393 : : * some error caused by the residual configurations, such as the
4394 : : * unexpected interrupt, can be avoid.
4395 : : */
4396 : 0 : ret = hns3_init_ring_with_vector(hw);
4397 [ # # ]: 0 : if (ret) {
4398 : 0 : PMD_INIT_LOG(ERR, "Failed to init ring intr vector: %d", ret);
4399 : 0 : goto err_mac_init;
4400 : : }
4401 : :
4402 : 0 : ret = hns3_ptp_init(hw);
4403 [ # # ]: 0 : if (ret) {
4404 : 0 : PMD_INIT_LOG(ERR, "Failed to init PTP, ret = %d", ret);
4405 : 0 : goto err_mac_init;
4406 : : }
4407 : :
4408 : : return 0;
4409 : :
4410 : 0 : err_mac_init:
4411 : 0 : hns3_uninit_umv_space(hw);
4412 : 0 : return ret;
4413 : : }
4414 : :
4415 : : static int
4416 : 0 : hns3_clear_hw(struct hns3_hw *hw)
4417 : : {
4418 : : struct hns3_cmd_desc desc;
4419 : : int ret;
4420 : :
4421 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CLEAR_HW_STATE, false);
4422 : :
4423 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
4424 [ # # ]: 0 : if (ret && ret != -EOPNOTSUPP)
4425 : 0 : return ret;
4426 : :
4427 : : return 0;
4428 : : }
4429 : :
4430 : : static void
4431 : : hns3_config_all_msix_error(struct hns3_hw *hw, bool enable)
4432 : : {
4433 : : uint32_t val;
4434 : :
4435 : : /*
4436 : : * The new firmware support report more hardware error types by
4437 : : * msix mode. These errors are defined as RAS errors in hardware
4438 : : * and belong to a different type from the MSI-x errors processed
4439 : : * by the network driver.
4440 : : *
4441 : : * Network driver should open the new error report on initialization.
4442 : : */
4443 : 0 : val = hns3_read_dev(hw, HNS3_VECTOR0_OTER_EN_REG);
4444 : 0 : hns3_set_bit(val, HNS3_VECTOR0_ALL_MSIX_ERR_B, enable ? 1 : 0);
4445 : 0 : hns3_write_dev(hw, HNS3_VECTOR0_OTER_EN_REG, val);
4446 : : }
4447 : :
4448 : : static uint32_t
4449 : 0 : hns3_set_firber_default_support_speed(struct hns3_hw *hw)
4450 : : {
4451 : : struct hns3_mac *mac = &hw->mac;
4452 : :
4453 [ # # # # : 0 : switch (mac->link_speed) {
# # # # ]
4454 : : case RTE_ETH_SPEED_NUM_1G:
4455 : : return HNS3_FIBER_LINK_SPEED_1G_BIT;
4456 : 0 : case RTE_ETH_SPEED_NUM_10G:
4457 : 0 : return HNS3_FIBER_LINK_SPEED_10G_BIT;
4458 : 0 : case RTE_ETH_SPEED_NUM_25G:
4459 : 0 : return HNS3_FIBER_LINK_SPEED_25G_BIT;
4460 : 0 : case RTE_ETH_SPEED_NUM_40G:
4461 : 0 : return HNS3_FIBER_LINK_SPEED_40G_BIT;
4462 : 0 : case RTE_ETH_SPEED_NUM_50G:
4463 : 0 : return HNS3_FIBER_LINK_SPEED_50G_BIT;
4464 : 0 : case RTE_ETH_SPEED_NUM_100G:
4465 : 0 : return HNS3_FIBER_LINK_SPEED_100G_BIT;
4466 : 0 : case RTE_ETH_SPEED_NUM_200G:
4467 : 0 : return HNS3_FIBER_LINK_SPEED_200G_BIT;
4468 : 0 : default:
4469 : 0 : hns3_warn(hw, "invalid speed %u Mbps.", mac->link_speed);
4470 : 0 : return 0;
4471 : : }
4472 : : }
4473 : :
4474 : : /*
4475 : : * Validity of supported_speed for fiber and copper media type can be
4476 : : * guaranteed by the following policy:
4477 : : * Copper:
4478 : : * Although the initialization of the phy in the firmware may not be
4479 : : * completed, the firmware can guarantees that the supported_speed is
4480 : : * an valid value.
4481 : : * Firber:
4482 : : * If the version of firmware supports the active query way of the
4483 : : * HNS3_OPC_GET_SFP_INFO opcode, the supported_speed can be obtained
4484 : : * through it. If unsupported, use the SFP's speed as the value of the
4485 : : * supported_speed.
4486 : : */
4487 : : static int
4488 : 0 : hns3_get_port_supported_speed(struct rte_eth_dev *eth_dev)
4489 : : {
4490 : 0 : struct hns3_adapter *hns = eth_dev->data->dev_private;
4491 : 0 : struct hns3_hw *hw = &hns->hw;
4492 : : struct hns3_mac *mac = &hw->mac;
4493 : : int ret;
4494 : :
4495 : 0 : ret = hns3_update_link_info(eth_dev);
4496 [ # # ]: 0 : if (ret)
4497 : : return ret;
4498 : :
4499 [ # # ]: 0 : if (mac->media_type == HNS3_MEDIA_TYPE_FIBER ||
4500 : : mac->media_type == HNS3_MEDIA_TYPE_BACKPLANE) {
4501 : : /*
4502 : : * Some firmware does not support the report of supported_speed,
4503 : : * and only report the effective speed of SFP/backplane. In this
4504 : : * case, it is necessary to use the SFP/backplane's speed as the
4505 : : * supported_speed.
4506 : : */
4507 [ # # ]: 0 : if (mac->supported_speed == 0)
4508 : 0 : mac->supported_speed =
4509 : 0 : hns3_set_firber_default_support_speed(hw);
4510 : : }
4511 : :
4512 : : return 0;
4513 : : }
4514 : :
4515 : : static int
4516 : 0 : hns3_init_pf(struct rte_eth_dev *eth_dev)
4517 : : {
4518 : 0 : struct rte_device *dev = eth_dev->device;
4519 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
4520 : 0 : struct hns3_adapter *hns = eth_dev->data->dev_private;
4521 : 0 : struct hns3_hw *hw = &hns->hw;
4522 : : int ret;
4523 : :
4524 : 0 : PMD_INIT_FUNC_TRACE();
4525 : :
4526 : : /* Get hardware io base address from pcie BAR2 IO space */
4527 : 0 : hw->io_base = pci_dev->mem_resource[2].addr;
4528 : :
4529 : 0 : ret = hns3_get_pci_revision_id(hw, &hw->revision);
4530 [ # # ]: 0 : if (ret)
4531 : : return ret;
4532 : :
4533 : : /* Firmware command queue initialize */
4534 : 0 : ret = hns3_cmd_init_queue(hw);
4535 [ # # ]: 0 : if (ret) {
4536 : 0 : PMD_INIT_LOG(ERR, "Failed to init cmd queue: %d", ret);
4537 : 0 : goto err_cmd_init_queue;
4538 : : }
4539 : :
4540 : 0 : hns3_clear_all_event_cause(hw);
4541 : :
4542 : : /* Firmware command initialize */
4543 : 0 : ret = hns3_cmd_init(hw);
4544 [ # # ]: 0 : if (ret) {
4545 : 0 : PMD_INIT_LOG(ERR, "Failed to init cmd: %d", ret);
4546 : 0 : goto err_cmd_init;
4547 : : }
4548 : :
4549 : 0 : hns3_tx_push_init(eth_dev);
4550 : :
4551 : : /*
4552 : : * To ensure that the hardware environment is clean during
4553 : : * initialization, the driver actively clear the hardware environment
4554 : : * during initialization, including PF and corresponding VFs' vlan, mac,
4555 : : * flow table configurations, etc.
4556 : : */
4557 : 0 : ret = hns3_clear_hw(hw);
4558 [ # # ]: 0 : if (ret) {
4559 : 0 : PMD_INIT_LOG(ERR, "failed to clear hardware: %d", ret);
4560 : 0 : goto err_cmd_init;
4561 : : }
4562 : :
4563 : : hns3_config_all_msix_error(hw, true);
4564 : :
4565 : 0 : ret = rte_intr_callback_register(pci_dev->intr_handle,
4566 : : hns3_interrupt_handler,
4567 : : eth_dev);
4568 [ # # ]: 0 : if (ret) {
4569 : 0 : PMD_INIT_LOG(ERR, "Failed to register intr: %d", ret);
4570 : 0 : goto err_intr_callback_register;
4571 : : }
4572 : :
4573 : : /* Enable interrupt */
4574 : 0 : rte_intr_enable(pci_dev->intr_handle);
4575 : : hns3_pf_enable_irq0(hw);
4576 : :
4577 : : /* Get configuration */
4578 : 0 : ret = hns3_get_configuration(hw);
4579 [ # # ]: 0 : if (ret) {
4580 : 0 : PMD_INIT_LOG(ERR, "Failed to fetch configuration: %d", ret);
4581 : 0 : goto err_get_config;
4582 : : }
4583 : :
4584 : 0 : ret = hns3_stats_init(hw);
4585 [ # # ]: 0 : if (ret)
4586 : 0 : goto err_get_config;
4587 : :
4588 : 0 : ret = hns3_init_hardware(hns);
4589 [ # # ]: 0 : if (ret) {
4590 : 0 : PMD_INIT_LOG(ERR, "Failed to init hardware: %d", ret);
4591 : 0 : goto err_init_hw;
4592 : : }
4593 : :
4594 : : /* Initialize flow director filter list & hash */
4595 : 0 : ret = hns3_fdir_filter_init(hns);
4596 [ # # ]: 0 : if (ret) {
4597 : 0 : PMD_INIT_LOG(ERR, "Failed to alloc hashmap for fdir: %d", ret);
4598 : 0 : goto err_fdir;
4599 : : }
4600 : :
4601 : 0 : hns3_rss_set_default_args(hw);
4602 : :
4603 : 0 : ret = hns3_enable_hw_error_intr(hns, true);
4604 [ # # ]: 0 : if (ret) {
4605 : 0 : PMD_INIT_LOG(ERR, "fail to enable hw error interrupts: %d",
4606 : : ret);
4607 : 0 : goto err_enable_intr;
4608 : : }
4609 : :
4610 : 0 : ret = hns3_get_port_supported_speed(eth_dev);
4611 [ # # ]: 0 : if (ret) {
4612 : 0 : PMD_INIT_LOG(ERR, "failed to get speed capabilities supported "
4613 : : "by device, ret = %d.", ret);
4614 : 0 : goto err_supported_speed;
4615 : : }
4616 : :
4617 : 0 : hns3_tm_conf_init(eth_dev);
4618 : :
4619 : 0 : return 0;
4620 : :
4621 : : err_supported_speed:
4622 : 0 : (void)hns3_enable_hw_error_intr(hns, false);
4623 : 0 : err_enable_intr:
4624 : 0 : hns3_fdir_filter_uninit(hns);
4625 : 0 : err_fdir:
4626 : 0 : hns3_uninit_umv_space(hw);
4627 : 0 : hns3_ptp_uninit(hw);
4628 : 0 : err_init_hw:
4629 : 0 : hns3_stats_uninit(hw);
4630 : 0 : err_get_config:
4631 : : hns3_pf_disable_irq0(hw);
4632 : 0 : rte_intr_disable(pci_dev->intr_handle);
4633 : 0 : hns3_intr_unregister(pci_dev->intr_handle, hns3_interrupt_handler,
4634 : : eth_dev);
4635 : 0 : err_intr_callback_register:
4636 : 0 : err_cmd_init:
4637 : 0 : hns3_cmd_uninit(hw);
4638 : 0 : hns3_cmd_destroy_queue(hw);
4639 : 0 : err_cmd_init_queue:
4640 : 0 : hw->io_base = NULL;
4641 : :
4642 : 0 : return ret;
4643 : : }
4644 : :
4645 : : static void
4646 : 0 : hns3_uninit_pf(struct rte_eth_dev *eth_dev)
4647 : : {
4648 : 0 : struct hns3_adapter *hns = eth_dev->data->dev_private;
4649 : 0 : struct rte_device *dev = eth_dev->device;
4650 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
4651 : 0 : struct hns3_hw *hw = &hns->hw;
4652 : :
4653 : 0 : PMD_INIT_FUNC_TRACE();
4654 : :
4655 : 0 : hns3_tm_conf_uninit(eth_dev);
4656 : 0 : hns3_enable_hw_error_intr(hns, false);
4657 : 0 : hns3_rss_uninit(hns);
4658 : 0 : (void)hns3_config_gro(hw, false);
4659 : 0 : hns3_promisc_uninit(hw);
4660 : 0 : hns3_flow_uninit(eth_dev);
4661 : 0 : hns3_fdir_filter_uninit(hns);
4662 : 0 : hns3_uninit_umv_space(hw);
4663 : 0 : hns3_ptp_uninit(hw);
4664 : 0 : hns3_stats_uninit(hw);
4665 : 0 : hns3_config_mac_tnl_int(hw, false);
4666 : : hns3_pf_disable_irq0(hw);
4667 : 0 : rte_intr_disable(pci_dev->intr_handle);
4668 : 0 : hns3_intr_unregister(pci_dev->intr_handle, hns3_interrupt_handler,
4669 : : eth_dev);
4670 : : hns3_config_all_msix_error(hw, false);
4671 : 0 : hns3_cmd_uninit(hw);
4672 : 0 : hns3_cmd_destroy_queue(hw);
4673 : 0 : hw->io_base = NULL;
4674 : 0 : }
4675 : :
4676 : : static uint32_t
4677 : : hns3_convert_link_speeds2bitmap_copper(uint32_t link_speeds)
4678 : : {
4679 : : uint32_t speed_bit;
4680 : :
4681 [ # # ]: 0 : switch (link_speeds & ~RTE_ETH_LINK_SPEED_FIXED) {
4682 : : case RTE_ETH_LINK_SPEED_10M:
4683 : : speed_bit = HNS3_PHY_LINK_SPEED_10M_BIT;
4684 : : break;
4685 : : case RTE_ETH_LINK_SPEED_10M_HD:
4686 : : speed_bit = HNS3_PHY_LINK_SPEED_10M_HD_BIT;
4687 : : break;
4688 : : case RTE_ETH_LINK_SPEED_100M:
4689 : : speed_bit = HNS3_PHY_LINK_SPEED_100M_BIT;
4690 : : break;
4691 : : case RTE_ETH_LINK_SPEED_100M_HD:
4692 : : speed_bit = HNS3_PHY_LINK_SPEED_100M_HD_BIT;
4693 : : break;
4694 : : case RTE_ETH_LINK_SPEED_1G:
4695 : : speed_bit = HNS3_PHY_LINK_SPEED_1000M_BIT;
4696 : : break;
4697 : : default:
4698 : : speed_bit = 0;
4699 : : break;
4700 : : }
4701 : :
4702 : : return speed_bit;
4703 : : }
4704 : :
4705 : : static uint32_t
4706 : : hns3_convert_link_speeds2bitmap_fiber(uint32_t link_speeds)
4707 : : {
4708 : : uint32_t speed_bit;
4709 : :
4710 [ # # # # : 0 : switch (link_speeds & ~RTE_ETH_LINK_SPEED_FIXED) {
# # # # ]
4711 : : case RTE_ETH_LINK_SPEED_1G:
4712 : : speed_bit = HNS3_FIBER_LINK_SPEED_1G_BIT;
4713 : : break;
4714 : 0 : case RTE_ETH_LINK_SPEED_10G:
4715 : : speed_bit = HNS3_FIBER_LINK_SPEED_10G_BIT;
4716 : 0 : break;
4717 : 0 : case RTE_ETH_LINK_SPEED_25G:
4718 : : speed_bit = HNS3_FIBER_LINK_SPEED_25G_BIT;
4719 : 0 : break;
4720 : 0 : case RTE_ETH_LINK_SPEED_40G:
4721 : : speed_bit = HNS3_FIBER_LINK_SPEED_40G_BIT;
4722 : 0 : break;
4723 : 0 : case RTE_ETH_LINK_SPEED_50G:
4724 : : speed_bit = HNS3_FIBER_LINK_SPEED_50G_BIT;
4725 : 0 : break;
4726 : 0 : case RTE_ETH_LINK_SPEED_100G:
4727 : : speed_bit = HNS3_FIBER_LINK_SPEED_100G_BIT;
4728 : 0 : break;
4729 : 0 : case RTE_ETH_LINK_SPEED_200G:
4730 : : speed_bit = HNS3_FIBER_LINK_SPEED_200G_BIT;
4731 : 0 : break;
4732 : 0 : default:
4733 : : speed_bit = 0;
4734 : 0 : break;
4735 : : }
4736 : :
4737 : : return speed_bit;
4738 : : }
4739 : :
4740 : : static int
4741 : 0 : hns3_check_port_speed(struct hns3_hw *hw, uint32_t link_speeds)
4742 : : {
4743 : : struct hns3_mac *mac = &hw->mac;
4744 : 0 : uint32_t supported_speed = mac->supported_speed;
4745 : : uint32_t speed_bit = 0;
4746 : :
4747 [ # # ]: 0 : if (mac->media_type == HNS3_MEDIA_TYPE_COPPER)
4748 : : speed_bit = hns3_convert_link_speeds2bitmap_copper(link_speeds);
4749 : : else
4750 : : speed_bit = hns3_convert_link_speeds2bitmap_fiber(link_speeds);
4751 : :
4752 [ # # ]: 0 : if (!(speed_bit & supported_speed)) {
4753 : 0 : hns3_err(hw, "link_speeds(0x%x) exceeds the supported speed capability or is incorrect.",
4754 : : link_speeds);
4755 : 0 : return -EINVAL;
4756 : : }
4757 : :
4758 : : return 0;
4759 : : }
4760 : :
4761 : : static uint32_t
4762 : 0 : hns3_get_link_speed(uint32_t link_speeds)
4763 : : {
4764 : : uint32_t speed = RTE_ETH_SPEED_NUM_NONE;
4765 : :
4766 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10M ||
4767 : : link_speeds & RTE_ETH_LINK_SPEED_10M_HD)
4768 : : speed = RTE_ETH_SPEED_NUM_10M;
4769 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100M ||
4770 : : link_speeds & RTE_ETH_LINK_SPEED_100M_HD)
4771 : : speed = RTE_ETH_SPEED_NUM_100M;
4772 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
4773 : : speed = RTE_ETH_SPEED_NUM_1G;
4774 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G)
4775 : : speed = RTE_ETH_SPEED_NUM_10G;
4776 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_25G)
4777 : : speed = RTE_ETH_SPEED_NUM_25G;
4778 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
4779 : : speed = RTE_ETH_SPEED_NUM_40G;
4780 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_50G)
4781 : : speed = RTE_ETH_SPEED_NUM_50G;
4782 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100G)
4783 : : speed = RTE_ETH_SPEED_NUM_100G;
4784 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_200G)
4785 : : speed = RTE_ETH_SPEED_NUM_200G;
4786 : :
4787 : 0 : return speed;
4788 : : }
4789 : :
4790 : : static uint8_t
4791 : : hns3_get_link_duplex(uint32_t link_speeds)
4792 : : {
4793 : 0 : if ((link_speeds & RTE_ETH_LINK_SPEED_10M_HD) ||
4794 : : (link_speeds & RTE_ETH_LINK_SPEED_100M_HD))
4795 : : return RTE_ETH_LINK_HALF_DUPLEX;
4796 : : else
4797 : 0 : return RTE_ETH_LINK_FULL_DUPLEX;
4798 : : }
4799 : :
4800 : : static int
4801 : 0 : hns3_copper_port_link_speed_cfg(struct hns3_hw *hw,
4802 : : struct hns3_set_link_speed_cfg *cfg)
4803 : : {
4804 : : struct hns3_cmd_desc desc[HNS3_PHY_PARAM_CFG_BD_NUM];
4805 : : struct hns3_phy_params_bd0_cmd *req;
4806 : : uint16_t i;
4807 : :
4808 [ # # ]: 0 : for (i = 0; i < HNS3_PHY_PARAM_CFG_BD_NUM - 1; i++) {
4809 : 0 : hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_PHY_PARAM_CFG,
4810 : : false);
4811 : 0 : desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
4812 : : }
4813 : 0 : hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_PHY_PARAM_CFG, false);
4814 : : req = (struct hns3_phy_params_bd0_cmd *)desc[0].data;
4815 : 0 : req->autoneg = cfg->autoneg;
4816 : :
4817 : : /*
4818 : : * The full speed capability is used to negotiate when
4819 : : * auto-negotiation is enabled.
4820 : : */
4821 [ # # ]: 0 : if (cfg->autoneg) {
4822 : 0 : req->advertising = HNS3_PHY_LINK_SPEED_10M_BIT |
4823 : : HNS3_PHY_LINK_SPEED_10M_HD_BIT |
4824 : : HNS3_PHY_LINK_SPEED_100M_BIT |
4825 : : HNS3_PHY_LINK_SPEED_100M_HD_BIT |
4826 : : HNS3_PHY_LINK_SPEED_1000M_BIT;
4827 : : } else {
4828 : 0 : req->speed = cfg->speed;
4829 : 0 : req->duplex = cfg->duplex;
4830 : : }
4831 : :
4832 : 0 : return hns3_cmd_send(hw, desc, HNS3_PHY_PARAM_CFG_BD_NUM);
4833 : : }
4834 : :
4835 : : static int
4836 : 0 : hns3_set_copper_port_link_speed(struct hns3_hw *hw,
4837 : : struct hns3_set_link_speed_cfg *cfg)
4838 : : {
4839 : : #define HNS3_PHY_PARAM_CFG_RETRY_TIMES 10
4840 : : #define HNS3_PHY_PARAM_CFG_RETRY_DELAY_MS 100
4841 : : uint32_t retry_cnt = 0;
4842 : : int ret;
4843 : :
4844 : : /*
4845 : : * The initialization of copper port contains the following two steps.
4846 : : * 1. Configure firmware takeover the PHY. The firmware will start an
4847 : : * asynchronous task to initialize the PHY chip.
4848 : : * 2. Configure work speed and duplex.
4849 : : * In earlier versions of the firmware, when the asynchronous task is not
4850 : : * finished, the firmware will return -ENOTBLK in the second step. And this
4851 : : * will lead to driver failed to initialize. Here add retry for this case.
4852 : : */
4853 : 0 : ret = hns3_copper_port_link_speed_cfg(hw, cfg);
4854 [ # # # # ]: 0 : while (ret == -ENOTBLK && retry_cnt++ < HNS3_PHY_PARAM_CFG_RETRY_TIMES) {
4855 : : rte_delay_ms(HNS3_PHY_PARAM_CFG_RETRY_DELAY_MS);
4856 : 0 : ret = hns3_copper_port_link_speed_cfg(hw, cfg);
4857 : : }
4858 : :
4859 : 0 : return ret;
4860 : : }
4861 : :
4862 : : static int
4863 : 0 : hns3_set_autoneg(struct hns3_hw *hw, bool enable)
4864 : : {
4865 : : struct hns3_config_auto_neg_cmd *req;
4866 : : struct hns3_cmd_desc desc;
4867 : : uint32_t flag = 0;
4868 : : int ret;
4869 : :
4870 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_AN_MODE, false);
4871 : :
4872 : : req = (struct hns3_config_auto_neg_cmd *)desc.data;
4873 [ # # ]: 0 : if (enable)
4874 : : hns3_set_bit(flag, HNS3_MAC_CFG_AN_EN_B, 1);
4875 : 0 : req->cfg_an_cmd_flag = rte_cpu_to_le_32(flag);
4876 : :
4877 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
4878 [ # # ]: 0 : if (ret)
4879 : 0 : hns3_err(hw, "autoneg set cmd failed, ret = %d.", ret);
4880 : :
4881 : 0 : return ret;
4882 : : }
4883 : :
4884 : : static int
4885 : 0 : hns3_set_fiber_port_link_speed(struct hns3_hw *hw,
4886 : : struct hns3_set_link_speed_cfg *cfg)
4887 : : {
4888 : : int ret;
4889 : :
4890 [ # # ]: 0 : if (hw->mac.support_autoneg) {
4891 : 0 : ret = hns3_set_autoneg(hw, cfg->autoneg);
4892 [ # # ]: 0 : if (ret) {
4893 : 0 : hns3_err(hw, "failed to configure auto-negotiation.");
4894 : 0 : return ret;
4895 : : }
4896 : :
4897 : : /*
4898 : : * To enable auto-negotiation, we only need to open the switch
4899 : : * of auto-negotiation, then firmware sets all speed
4900 : : * capabilities.
4901 : : */
4902 [ # # ]: 0 : if (cfg->autoneg)
4903 : : return 0;
4904 : : }
4905 : :
4906 : : /*
4907 : : * Some hardware doesn't support auto-negotiation, but users may not
4908 : : * configure link_speeds (default 0), which means auto-negotiation.
4909 : : * In this case, a warning message need to be printed, instead of
4910 : : * an error.
4911 : : */
4912 [ # # ]: 0 : if (cfg->autoneg) {
4913 : 0 : hns3_warn(hw, "auto-negotiation is not supported, use default fixed speed!");
4914 : 0 : return 0;
4915 : : }
4916 : :
4917 : 0 : return hns3_cfg_mac_speed_dup(hw, cfg->speed, cfg->duplex);
4918 : : }
4919 : :
4920 : : const char *
4921 : 0 : hns3_get_media_type_name(uint8_t media_type)
4922 : : {
4923 [ # # ]: 0 : if (media_type == HNS3_MEDIA_TYPE_FIBER)
4924 : : return "fiber";
4925 [ # # ]: 0 : else if (media_type == HNS3_MEDIA_TYPE_COPPER)
4926 : : return "copper";
4927 [ # # ]: 0 : else if (media_type == HNS3_MEDIA_TYPE_BACKPLANE)
4928 : : return "backplane";
4929 : : else
4930 : 0 : return "unknown";
4931 : : }
4932 : :
4933 : : static int
4934 : 0 : hns3_set_port_link_speed(struct hns3_hw *hw,
4935 : : struct hns3_set_link_speed_cfg *cfg)
4936 : : {
4937 : : int ret;
4938 : :
4939 [ # # ]: 0 : if (hw->mac.media_type == HNS3_MEDIA_TYPE_COPPER)
4940 : 0 : ret = hns3_set_copper_port_link_speed(hw, cfg);
4941 : : else
4942 : 0 : ret = hns3_set_fiber_port_link_speed(hw, cfg);
4943 : :
4944 [ # # ]: 0 : if (ret) {
4945 : 0 : hns3_err(hw, "failed to set %s port link speed, ret = %d.",
4946 : : hns3_get_media_type_name(hw->mac.media_type),
4947 : : ret);
4948 : 0 : return ret;
4949 : : }
4950 : :
4951 : : return 0;
4952 : : }
4953 : :
4954 : : static int
4955 : 0 : hns3_apply_link_speed(struct hns3_hw *hw)
4956 : : {
4957 [ # # ]: 0 : struct rte_eth_conf *conf = &hw->data->dev_conf;
4958 : : struct hns3_set_link_speed_cfg cfg;
4959 : :
4960 : : memset(&cfg, 0, sizeof(struct hns3_set_link_speed_cfg));
4961 : 0 : cfg.autoneg = (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) ?
4962 : 0 : RTE_ETH_LINK_AUTONEG : RTE_ETH_LINK_FIXED;
4963 [ # # ]: 0 : if (cfg.autoneg != RTE_ETH_LINK_AUTONEG) {
4964 [ # # ]: 0 : cfg.speed = hns3_get_link_speed(conf->link_speeds);
4965 : 0 : cfg.duplex = hns3_get_link_duplex(conf->link_speeds);
4966 : : }
4967 : :
4968 : 0 : return hns3_set_port_link_speed(hw, &cfg);
4969 : : }
4970 : :
4971 : : static int
4972 : 0 : hns3_do_start(struct hns3_adapter *hns, bool reset_queue)
4973 : : {
4974 : 0 : struct hns3_hw *hw = &hns->hw;
4975 : : bool link_en;
4976 : : int ret;
4977 : :
4978 : 0 : ret = hns3_update_queue_map_configure(hns);
4979 [ # # ]: 0 : if (ret) {
4980 : 0 : hns3_err(hw, "failed to update queue mapping configuration, ret = %d",
4981 : : ret);
4982 : 0 : return ret;
4983 : : }
4984 : :
4985 : : /* Note: hns3_tm_conf_update must be called after configuring DCB. */
4986 : 0 : ret = hns3_tm_conf_update(hw);
4987 [ # # ]: 0 : if (ret) {
4988 : 0 : PMD_INIT_LOG(ERR, "failed to update tm conf, ret = %d.", ret);
4989 : 0 : return ret;
4990 : : }
4991 : :
4992 : 0 : hns3_enable_rxd_adv_layout(hw);
4993 : :
4994 : 0 : ret = hns3_init_queues(hns, reset_queue);
4995 [ # # ]: 0 : if (ret) {
4996 : 0 : PMD_INIT_LOG(ERR, "failed to init queues, ret = %d.", ret);
4997 : 0 : return ret;
4998 : : }
4999 : :
5000 : 0 : link_en = hw->set_link_down ? false : true;
5001 : 0 : ret = hns3_cfg_mac_mode(hw, link_en);
5002 [ # # ]: 0 : if (ret) {
5003 : 0 : PMD_INIT_LOG(ERR, "failed to enable MAC, ret = %d", ret);
5004 : 0 : goto err_config_mac_mode;
5005 : : }
5006 : :
5007 : 0 : ret = hns3_apply_link_speed(hw);
5008 [ # # ]: 0 : if (ret)
5009 : 0 : goto err_set_link_speed;
5010 : :
5011 : 0 : return hns3_restore_filter(hns);
5012 : :
5013 : : err_set_link_speed:
5014 : 0 : (void)hns3_cfg_mac_mode(hw, false);
5015 : :
5016 : 0 : err_config_mac_mode:
5017 : 0 : hns3_dev_release_mbufs(hns);
5018 : : /*
5019 : : * Here is exception handling, hns3_reset_all_tqps will have the
5020 : : * corresponding error message if it is handled incorrectly, so it is
5021 : : * not necessary to check hns3_reset_all_tqps return value, here keep
5022 : : * ret as the error code causing the exception.
5023 : : */
5024 : 0 : (void)hns3_reset_all_tqps(hns);
5025 : 0 : return ret;
5026 : : }
5027 : :
5028 : : static int
5029 : 0 : hns3_dev_start(struct rte_eth_dev *dev)
5030 : : {
5031 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
5032 : 0 : struct hns3_hw *hw = &hns->hw;
5033 : 0 : bool old_state = hw->set_link_down;
5034 : : int ret;
5035 : :
5036 : 0 : PMD_INIT_FUNC_TRACE();
5037 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed))
5038 : : return -EBUSY;
5039 : :
5040 : 0 : rte_spinlock_lock(&hw->lock);
5041 : 0 : hw->adapter_state = HNS3_NIC_STARTING;
5042 : :
5043 : : /*
5044 : : * If the dev_set_link_down() API has been called, the "set_link_down"
5045 : : * flag can be cleared by dev_start() API. In addition, the flag should
5046 : : * also be cleared before calling hns3_do_start() so that MAC can be
5047 : : * enabled in dev_start stage.
5048 : : */
5049 : 0 : hw->set_link_down = false;
5050 : 0 : ret = hns3_do_start(hns, true);
5051 [ # # ]: 0 : if (ret)
5052 : 0 : goto do_start_fail;
5053 : :
5054 : 0 : ret = hns3_map_rx_interrupt(dev);
5055 [ # # ]: 0 : if (ret)
5056 : 0 : goto map_rx_inter_err;
5057 : :
5058 : : /*
5059 : : * There are three register used to control the status of a TQP
5060 : : * (contains a pair of Tx queue and Rx queue) in the new version network
5061 : : * engine. One is used to control the enabling of Tx queue, the other is
5062 : : * used to control the enabling of Rx queue, and the last is the master
5063 : : * switch used to control the enabling of the tqp. The Tx register and
5064 : : * TQP register must be enabled at the same time to enable a Tx queue.
5065 : : * The same applies to the Rx queue. For the older network engine, this
5066 : : * function only refresh the enabled flag, and it is used to update the
5067 : : * status of queue in the dpdk framework.
5068 : : */
5069 : 0 : ret = hns3_start_all_txqs(dev);
5070 [ # # ]: 0 : if (ret)
5071 : 0 : goto start_all_txqs_fail;
5072 : :
5073 : 0 : ret = hns3_start_all_rxqs(dev);
5074 [ # # ]: 0 : if (ret)
5075 : 0 : goto start_all_rxqs_fail;
5076 : :
5077 : 0 : hw->adapter_state = HNS3_NIC_STARTED;
5078 : : rte_spinlock_unlock(&hw->lock);
5079 : :
5080 : 0 : hns3_rx_scattered_calc(dev);
5081 : 0 : hns3_start_rxtx_datapath(dev);
5082 : :
5083 : : /* Enable interrupt of all rx queues before enabling queues */
5084 : 0 : hns3_dev_all_rx_queue_intr_enable(hw, true);
5085 : :
5086 : : /*
5087 : : * After finished the initialization, enable tqps to receive/transmit
5088 : : * packets and refresh all queue status.
5089 : : */
5090 : 0 : hns3_start_tqps(hw);
5091 : :
5092 : 0 : hns3_tm_dev_start_proc(hw);
5093 : :
5094 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
5095 : 0 : hns3_dev_link_update(dev, 0);
5096 : 0 : rte_eal_alarm_set(HNS3_SERVICE_INTERVAL, hns3_service_handler, dev);
5097 : :
5098 : 0 : hns3_info(hw, "hns3 dev start successful!");
5099 : :
5100 : 0 : return 0;
5101 : :
5102 : : start_all_rxqs_fail:
5103 : 0 : hns3_stop_all_txqs(dev);
5104 : 0 : start_all_txqs_fail:
5105 : 0 : hns3_unmap_rx_interrupt(dev);
5106 : 0 : map_rx_inter_err:
5107 : 0 : (void)hns3_do_stop(hns);
5108 : 0 : do_start_fail:
5109 : 0 : hw->set_link_down = old_state;
5110 : 0 : hw->adapter_state = HNS3_NIC_CONFIGURED;
5111 : : rte_spinlock_unlock(&hw->lock);
5112 : :
5113 : 0 : return ret;
5114 : : }
5115 : :
5116 : : static int
5117 : 0 : hns3_do_stop(struct hns3_adapter *hns)
5118 : : {
5119 : 0 : struct hns3_hw *hw = &hns->hw;
5120 : : int ret;
5121 : :
5122 : : /*
5123 : : * The "hns3_do_stop" function will also be called by .stop_service to
5124 : : * prepare reset. At the time of global or IMP reset, the command cannot
5125 : : * be sent to stop the tx/rx queues. The mbuf in Tx/Rx queues may be
5126 : : * accessed during the reset process. So the mbuf can not be released
5127 : : * during reset and is required to be released after the reset is
5128 : : * completed.
5129 : : */
5130 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed) == 0)
5131 : 0 : hns3_dev_release_mbufs(hns);
5132 : :
5133 : 0 : ret = hns3_cfg_mac_mode(hw, false);
5134 [ # # ]: 0 : if (ret)
5135 : : return ret;
5136 : 0 : hw->mac.link_status = RTE_ETH_LINK_DOWN;
5137 : :
5138 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.disable_cmd, rte_memory_order_relaxed) == 0) {
5139 : 0 : hns3_configure_all_mac_addr(hns, true);
5140 : 0 : ret = hns3_reset_all_tqps(hns);
5141 [ # # ]: 0 : if (ret) {
5142 : 0 : hns3_err(hw, "failed to reset all queues ret = %d.",
5143 : : ret);
5144 : 0 : return ret;
5145 : : }
5146 : : }
5147 : :
5148 : : return 0;
5149 : : }
5150 : :
5151 : : static int
5152 : 0 : hns3_dev_stop(struct rte_eth_dev *dev)
5153 : : {
5154 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
5155 : 0 : struct hns3_hw *hw = &hns->hw;
5156 : :
5157 : 0 : PMD_INIT_FUNC_TRACE();
5158 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed) != 0) {
5159 : 0 : hns3_warn(hw, "device is resetting, stop operation is not allowed.");
5160 : 0 : return -EBUSY;
5161 : : }
5162 : :
5163 : 0 : dev->data->dev_started = 0;
5164 : :
5165 : 0 : hw->adapter_state = HNS3_NIC_STOPPING;
5166 : 0 : hns3_stop_rxtx_datapath(dev);
5167 : :
5168 : 0 : rte_spinlock_lock(&hw->lock);
5169 : 0 : hns3_tm_dev_stop_proc(hw);
5170 : 0 : hns3_config_mac_tnl_int(hw, false);
5171 : 0 : hns3_stop_tqps(hw);
5172 : 0 : hns3_do_stop(hns);
5173 : 0 : hns3_unmap_rx_interrupt(dev);
5174 : 0 : hw->adapter_state = HNS3_NIC_CONFIGURED;
5175 : 0 : hns3_rx_scattered_reset(dev);
5176 : 0 : rte_eal_alarm_cancel(hns3_service_handler, dev);
5177 : 0 : hns3_stop_report_lse(dev);
5178 : : rte_spinlock_unlock(&hw->lock);
5179 : :
5180 : 0 : return 0;
5181 : : }
5182 : :
5183 : : static int
5184 : 0 : hns3_dev_close(struct rte_eth_dev *eth_dev)
5185 : : {
5186 : 0 : struct hns3_adapter *hns = eth_dev->data->dev_private;
5187 : : struct hns3_hw *hw = &hns->hw;
5188 : : int ret = 0;
5189 : :
5190 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
5191 : 0 : hns3_mp_uninit(eth_dev);
5192 : 0 : return 0;
5193 : : }
5194 : :
5195 [ # # ]: 0 : if (hw->adapter_state == HNS3_NIC_STARTED)
5196 : 0 : ret = hns3_dev_stop(eth_dev);
5197 : :
5198 : 0 : hw->adapter_state = HNS3_NIC_CLOSING;
5199 : 0 : hns3_reset_abort(hns);
5200 : 0 : hw->adapter_state = HNS3_NIC_CLOSED;
5201 : :
5202 : 0 : hns3_configure_all_mc_mac_addr(hns, true);
5203 : 0 : hns3_remove_all_vlan_table(hns);
5204 : 0 : hns3_vlan_txvlan_cfg(hns, HNS3_PORT_BASE_VLAN_DISABLE, 0);
5205 : 0 : hns3_uninit_pf(eth_dev);
5206 : 0 : hns3_free_all_queues(eth_dev);
5207 : 0 : rte_free(hw->reset.wait_data);
5208 : 0 : hns3_mp_uninit(eth_dev);
5209 : 0 : hns3_warn(hw, "Close port %u finished", hw->data->port_id);
5210 : :
5211 : 0 : return ret;
5212 : : }
5213 : :
5214 : : static void
5215 : : hns3_get_autoneg_rxtx_pause(struct hns3_hw *hw, bool *rx_pause, bool *tx_pause)
5216 : : {
5217 : : struct hns3_mac *mac = &hw->mac;
5218 : 0 : uint32_t advertising = mac->advertising;
5219 : 0 : uint32_t lp_advertising = mac->lp_advertising;
5220 : : *rx_pause = false;
5221 : : *tx_pause = false;
5222 : :
5223 : 0 : if (advertising & lp_advertising & HNS3_PHY_LINK_MODE_PAUSE_BIT) {
5224 : : *rx_pause = true;
5225 : : *tx_pause = true;
5226 [ # # ]: 0 : } else if (advertising & lp_advertising & HNS3_PHY_LINK_MODE_ASYM_PAUSE_BIT) {
5227 [ # # ]: 0 : if (advertising & HNS3_PHY_LINK_MODE_PAUSE_BIT)
5228 : : *rx_pause = true;
5229 [ # # ]: 0 : else if (lp_advertising & HNS3_PHY_LINK_MODE_PAUSE_BIT)
5230 : : *tx_pause = true;
5231 : : }
5232 : : }
5233 : :
5234 : : static enum hns3_fc_mode
5235 [ # # ]: 0 : hns3_get_autoneg_fc_mode(struct hns3_hw *hw)
5236 : : {
5237 : : enum hns3_fc_mode current_mode;
5238 : : bool rx_pause = false;
5239 : : bool tx_pause = false;
5240 : :
5241 : : hns3_get_autoneg_rxtx_pause(hw, &rx_pause, &tx_pause);
5242 : :
5243 [ # # ]: 0 : if (rx_pause && tx_pause)
5244 : : current_mode = HNS3_FC_FULL;
5245 [ # # ]: 0 : else if (rx_pause)
5246 : : current_mode = HNS3_FC_RX_PAUSE;
5247 [ # # ]: 0 : else if (tx_pause)
5248 : : current_mode = HNS3_FC_TX_PAUSE;
5249 : : else
5250 : : current_mode = HNS3_FC_NONE;
5251 : :
5252 : 0 : return current_mode;
5253 : : }
5254 : :
5255 : : static enum hns3_fc_mode
5256 : 0 : hns3_get_current_fc_mode(struct rte_eth_dev *dev)
5257 : : {
5258 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5259 : : struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5260 : : struct hns3_mac *mac = &hw->mac;
5261 : :
5262 : : /*
5263 : : * If the link auto-negotiation of the nic is disabled, or the flow
5264 : : * control auto-negotiation is not supported, the forced flow control
5265 : : * mode is used.
5266 : : */
5267 [ # # # # ]: 0 : if (mac->link_autoneg == 0 || !pf->support_fc_autoneg)
5268 : 0 : return hw->requested_fc_mode;
5269 : :
5270 : : /*
5271 : : * When the flow control mode is obtained, the device may not complete
5272 : : * auto-negotiation. It is necessary to wait for link establishment.
5273 : : */
5274 : 0 : (void)hns3_dev_link_update(dev, 1);
5275 : :
5276 : 0 : return hns3_get_autoneg_fc_mode(hw);
5277 : : }
5278 : :
5279 : : int
5280 : 0 : hns3_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
5281 : : {
5282 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5283 : : struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5284 : : enum hns3_fc_mode current_mode;
5285 : :
5286 : 0 : current_mode = hns3_get_current_fc_mode(dev);
5287 [ # # # # ]: 0 : switch (current_mode) {
5288 : 0 : case HNS3_FC_FULL:
5289 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
5290 : 0 : break;
5291 : 0 : case HNS3_FC_TX_PAUSE:
5292 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
5293 : 0 : break;
5294 : 0 : case HNS3_FC_RX_PAUSE:
5295 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
5296 : 0 : break;
5297 : 0 : case HNS3_FC_NONE:
5298 : : default:
5299 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
5300 : 0 : break;
5301 : : }
5302 : :
5303 : 0 : fc_conf->pause_time = pf->pause_time;
5304 [ # # ]: 0 : fc_conf->autoneg = pf->support_fc_autoneg ? hw->mac.link_autoneg : 0;
5305 : :
5306 : 0 : return 0;
5307 : : }
5308 : :
5309 : : static int
5310 : 0 : hns3_check_fc_autoneg_valid(struct hns3_hw *hw, uint8_t autoneg)
5311 : : {
5312 : : struct hns3_pf *pf = HNS3_DEV_HW_TO_PF(hw);
5313 : :
5314 [ # # ]: 0 : if (!pf->support_fc_autoneg) {
5315 [ # # ]: 0 : if (autoneg != 0) {
5316 : 0 : hns3_err(hw, "unsupported fc auto-negotiation.");
5317 : 0 : return -EOPNOTSUPP;
5318 : : }
5319 : :
5320 : : return 0;
5321 : : }
5322 : :
5323 : : /*
5324 : : * If flow control auto-negotiation of the NIC is supported, all
5325 : : * auto-negotiation features are supported.
5326 : : */
5327 [ # # ]: 0 : if (autoneg != hw->mac.link_autoneg) {
5328 : 0 : hns3_err(hw, "please use 'link_speeds' in struct rte_eth_conf to change autoneg!");
5329 : 0 : return -EOPNOTSUPP;
5330 : : }
5331 : :
5332 : : return 0;
5333 : : }
5334 : :
5335 : : static int
5336 : 0 : hns3_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
5337 : : {
5338 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5339 : : struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5340 : : int ret;
5341 : :
5342 [ # # # # ]: 0 : if (fc_conf->high_water || fc_conf->low_water ||
5343 [ # # # # ]: 0 : fc_conf->send_xon || fc_conf->mac_ctrl_frame_fwd) {
5344 : 0 : hns3_err(hw, "Unsupported flow control settings specified, "
5345 : : "high_water(%u), low_water(%u), send_xon(%u) and "
5346 : : "mac_ctrl_frame_fwd(%u) must be set to '0'",
5347 : : fc_conf->high_water, fc_conf->low_water,
5348 : : fc_conf->send_xon, fc_conf->mac_ctrl_frame_fwd);
5349 : 0 : return -EINVAL;
5350 : : }
5351 : :
5352 : 0 : ret = hns3_check_fc_autoneg_valid(hw, fc_conf->autoneg);
5353 [ # # ]: 0 : if (ret)
5354 : : return ret;
5355 : :
5356 [ # # ]: 0 : if (!fc_conf->pause_time) {
5357 : 0 : hns3_err(hw, "Invalid pause time %u setting.",
5358 : : fc_conf->pause_time);
5359 : 0 : return -EINVAL;
5360 : : }
5361 : :
5362 [ # # ]: 0 : if (!(hw->current_fc_status == HNS3_FC_STATUS_NONE ||
5363 : : hw->current_fc_status == HNS3_FC_STATUS_MAC_PAUSE)) {
5364 : 0 : hns3_err(hw, "PFC is enabled. Cannot set MAC pause. "
5365 : : "current_fc_status = %d", hw->current_fc_status);
5366 : 0 : return -EOPNOTSUPP;
5367 : : }
5368 : :
5369 [ # # # # ]: 0 : if (hw->dcb_info.num_tc > 1 && !pf->support_multi_tc_pause) {
5370 : 0 : hns3_err(hw, "in multi-TC scenarios, MAC pause is not supported.");
5371 : 0 : return -EOPNOTSUPP;
5372 : : }
5373 : :
5374 : 0 : rte_spinlock_lock(&hw->lock);
5375 : 0 : ret = hns3_fc_enable(dev, fc_conf);
5376 : : rte_spinlock_unlock(&hw->lock);
5377 : :
5378 : 0 : return ret;
5379 : : }
5380 : :
5381 : : static int
5382 : 0 : hns3_priority_flow_ctrl_set(struct rte_eth_dev *dev,
5383 : : struct rte_eth_pfc_conf *pfc_conf)
5384 : : {
5385 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5386 : : int ret;
5387 : :
5388 [ # # ]: 0 : if (!hns3_dev_get_support(hw, DCB)) {
5389 : 0 : hns3_err(hw, "This port does not support dcb configurations.");
5390 : 0 : return -EOPNOTSUPP;
5391 : : }
5392 : :
5393 [ # # # # ]: 0 : if (pfc_conf->fc.high_water || pfc_conf->fc.low_water ||
5394 [ # # # # ]: 0 : pfc_conf->fc.send_xon || pfc_conf->fc.mac_ctrl_frame_fwd) {
5395 : 0 : hns3_err(hw, "Unsupported flow control settings specified, "
5396 : : "high_water(%u), low_water(%u), send_xon(%u) and "
5397 : : "mac_ctrl_frame_fwd(%u) must be set to '0'",
5398 : : pfc_conf->fc.high_water, pfc_conf->fc.low_water,
5399 : : pfc_conf->fc.send_xon,
5400 : : pfc_conf->fc.mac_ctrl_frame_fwd);
5401 : 0 : return -EINVAL;
5402 : : }
5403 [ # # ]: 0 : if (pfc_conf->fc.autoneg) {
5404 : 0 : hns3_err(hw, "Unsupported fc auto-negotiation setting.");
5405 : 0 : return -EINVAL;
5406 : : }
5407 [ # # ]: 0 : if (pfc_conf->fc.pause_time == 0) {
5408 : 0 : hns3_err(hw, "Invalid pause time %u setting.",
5409 : : pfc_conf->fc.pause_time);
5410 : 0 : return -EINVAL;
5411 : : }
5412 : :
5413 [ # # ]: 0 : if (!(hw->current_fc_status == HNS3_FC_STATUS_NONE ||
5414 : : hw->current_fc_status == HNS3_FC_STATUS_PFC)) {
5415 : 0 : hns3_err(hw, "MAC pause is enabled. Cannot set PFC."
5416 : : "current_fc_status = %d", hw->current_fc_status);
5417 : 0 : return -EOPNOTSUPP;
5418 : : }
5419 : :
5420 : 0 : rte_spinlock_lock(&hw->lock);
5421 : 0 : ret = hns3_dcb_pfc_enable(dev, pfc_conf);
5422 : : rte_spinlock_unlock(&hw->lock);
5423 : :
5424 : 0 : return ret;
5425 : : }
5426 : :
5427 : : static int
5428 : 0 : hns3_reinit_dev(struct hns3_adapter *hns)
5429 : : {
5430 : 0 : struct hns3_hw *hw = &hns->hw;
5431 : : int ret;
5432 : :
5433 : 0 : ret = hns3_cmd_init(hw);
5434 [ # # ]: 0 : if (ret) {
5435 : 0 : hns3_err(hw, "Failed to init cmd: %d", ret);
5436 : 0 : return ret;
5437 : : }
5438 : :
5439 : 0 : ret = hns3_init_hardware(hns);
5440 [ # # ]: 0 : if (ret) {
5441 : 0 : hns3_err(hw, "Failed to init hardware: %d", ret);
5442 : 0 : return ret;
5443 : : }
5444 : :
5445 : 0 : ret = hns3_reset_all_tqps(hns);
5446 [ # # ]: 0 : if (ret) {
5447 : 0 : hns3_err(hw, "Failed to reset all queues: %d", ret);
5448 : 0 : return ret;
5449 : : }
5450 : :
5451 : 0 : ret = hns3_enable_hw_error_intr(hns, true);
5452 [ # # ]: 0 : if (ret) {
5453 : 0 : hns3_err(hw, "fail to enable hw error interrupts: %d",
5454 : : ret);
5455 : 0 : return ret;
5456 : : }
5457 : 0 : hns3_info(hw, "Reset done, driver initialization finished.");
5458 : :
5459 : 0 : return 0;
5460 : : }
5461 : :
5462 : : static bool
5463 : 0 : is_pf_reset_done(struct hns3_hw *hw)
5464 : : {
5465 : : uint32_t val, reg, reg_bit;
5466 : :
5467 [ # # ]: 0 : switch (hw->reset.level) {
5468 : : case HNS3_IMP_RESET:
5469 : : reg = HNS3_GLOBAL_RESET_REG;
5470 : : reg_bit = HNS3_IMP_RESET_BIT;
5471 : : break;
5472 : : case HNS3_GLOBAL_RESET:
5473 : : reg = HNS3_GLOBAL_RESET_REG;
5474 : : reg_bit = HNS3_GLOBAL_RESET_BIT;
5475 : : break;
5476 : : case HNS3_FUNC_RESET:
5477 : : reg = HNS3_FUN_RST_ING;
5478 : : reg_bit = HNS3_FUN_RST_ING_B;
5479 : : break;
5480 : 0 : case HNS3_FLR_RESET:
5481 : : default:
5482 : 0 : hns3_err(hw, "Wait for unsupported reset level: %d",
5483 : : hw->reset.level);
5484 : 0 : return true;
5485 : : }
5486 : 0 : val = hns3_read_dev(hw, reg);
5487 [ # # ]: 0 : if (hns3_get_bit(val, reg_bit))
5488 : : return false;
5489 : : else
5490 : 0 : return true;
5491 : : }
5492 : :
5493 : : static enum hns3_reset_level
5494 : : hns3_detect_reset_event(struct hns3_hw *hw)
5495 : : {
5496 : : enum hns3_reset_level new_req = HNS3_NONE_RESET;
5497 : : uint32_t vector0_intr_state;
5498 : :
5499 : 0 : vector0_intr_state = hns3_read_dev(hw, HNS3_VECTOR0_OTHER_INT_STS_REG);
5500 [ # # ]: 0 : if (BIT(HNS3_VECTOR0_IMPRESET_INT_B) & vector0_intr_state)
5501 : : new_req = HNS3_IMP_RESET;
5502 [ # # ]: 0 : else if (BIT(HNS3_VECTOR0_GLOBALRESET_INT_B) & vector0_intr_state)
5503 : : new_req = HNS3_GLOBAL_RESET;
5504 : :
5505 : : return new_req;
5506 : : }
5507 : :
5508 : : bool
5509 : 0 : hns3_is_reset_pending(struct hns3_adapter *hns)
5510 : : {
5511 : : enum hns3_reset_level new_req;
5512 : : struct hns3_hw *hw = &hns->hw;
5513 : : enum hns3_reset_level last_req;
5514 : :
5515 : : /*
5516 : : * Only primary can process can process the reset event,
5517 : : * so don't check reset event in secondary.
5518 : : */
5519 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5520 : : return false;
5521 : :
5522 : : new_req = hns3_detect_reset_event(hw);
5523 : : if (new_req == HNS3_NONE_RESET)
5524 : : return false;
5525 : :
5526 : 0 : last_req = hns3_get_reset_level(hns, &hw->reset.pending);
5527 [ # # ]: 0 : if (last_req == HNS3_NONE_RESET || last_req < new_req) {
5528 : 0 : rte_atomic_store_explicit(&hw->reset.disable_cmd, 1, rte_memory_order_relaxed);
5529 : 0 : hns3_schedule_delayed_reset(hns);
5530 : 0 : hns3_warn(hw, "High level reset detected, delay do reset");
5531 : 0 : return true;
5532 : : }
5533 : 0 : last_req = hns3_get_reset_level(hns, &hw->reset.request);
5534 [ # # # # : 0 : if (last_req != HNS3_NONE_RESET && hw->reset.level != HNS3_NONE_RESET &&
# # ]
5535 : : hw->reset.level < last_req) {
5536 : 0 : hns3_warn(hw, "High level reset %d is request", last_req);
5537 : 0 : return true;
5538 : : }
5539 : : return false;
5540 : : }
5541 : :
5542 : : static int
5543 : 0 : hns3_wait_hardware_ready(struct hns3_adapter *hns)
5544 : : {
5545 : : struct hns3_hw *hw = &hns->hw;
5546 : 0 : struct hns3_wait_data *wait_data = hw->reset.wait_data;
5547 : : struct timeval tv;
5548 : :
5549 [ # # ]: 0 : if (wait_data->result == HNS3_WAIT_SUCCESS)
5550 : : return 0;
5551 [ # # ]: 0 : else if (wait_data->result == HNS3_WAIT_TIMEOUT) {
5552 : 0 : hns3_clock_gettime(&tv);
5553 : 0 : hns3_warn(hw, "Reset step4 hardware not ready after reset time=%ld.%.6ld",
5554 : : tv.tv_sec, tv.tv_usec);
5555 : 0 : return -ETIME;
5556 [ # # ]: 0 : } else if (wait_data->result == HNS3_WAIT_REQUEST)
5557 : : return -EAGAIN;
5558 : :
5559 : 0 : wait_data->hns = hns;
5560 : 0 : wait_data->check_completion = is_pf_reset_done;
5561 : 0 : wait_data->end_ms = (uint64_t)HNS3_RESET_WAIT_CNT *
5562 : 0 : HNS3_RESET_WAIT_MS + hns3_clock_gettime_ms();
5563 : 0 : wait_data->interval = HNS3_RESET_WAIT_MS * USEC_PER_MSEC;
5564 : 0 : wait_data->count = HNS3_RESET_WAIT_CNT;
5565 : 0 : wait_data->result = HNS3_WAIT_REQUEST;
5566 : 0 : rte_eal_alarm_set(wait_data->interval, hns3_wait_callback, wait_data);
5567 : 0 : return -EAGAIN;
5568 : : }
5569 : :
5570 : : static int
5571 : 0 : hns3_func_reset_cmd(struct hns3_hw *hw, int func_id)
5572 : : {
5573 : : struct hns3_cmd_desc desc;
5574 : : struct hns3_reset_cmd *req = (struct hns3_reset_cmd *)desc.data;
5575 : :
5576 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_RST_TRIGGER, false);
5577 : 0 : hns3_set_bit(req->mac_func_reset, HNS3_CFG_RESET_FUNC_B, 1);
5578 : 0 : req->fun_reset_vfid = func_id;
5579 : :
5580 : 0 : return hns3_cmd_send(hw, &desc, 1);
5581 : : }
5582 : :
5583 : : static void
5584 : 0 : hns3_msix_process(struct hns3_adapter *hns, enum hns3_reset_level reset_level)
5585 : : {
5586 : : struct hns3_hw *hw = &hns->hw;
5587 : : struct timeval tv;
5588 : : uint32_t val;
5589 : :
5590 : 0 : hns3_clock_gettime(&tv);
5591 [ # # # # ]: 0 : if (hns3_read_dev(hw, HNS3_GLOBAL_RESET_REG) ||
5592 : 0 : hns3_read_dev(hw, HNS3_FUN_RST_ING)) {
5593 : 0 : hns3_warn(hw, "Don't process msix during resetting time=%ld.%.6ld",
5594 : : tv.tv_sec, tv.tv_usec);
5595 : 0 : return;
5596 : : }
5597 : :
5598 [ # # # # ]: 0 : switch (reset_level) {
5599 : 0 : case HNS3_IMP_RESET:
5600 : 0 : val = hns3_read_dev(hw, HNS3_VECTOR0_OTER_EN_REG);
5601 : 0 : hns3_set_bit(val, HNS3_VECTOR0_TRIGGER_IMP_RESET_B, 1);
5602 : 0 : hns3_write_dev(hw, HNS3_VECTOR0_OTER_EN_REG, val);
5603 : 0 : hns3_warn(hw, "IMP Reset requested time=%ld.%.6ld",
5604 : : tv.tv_sec, tv.tv_usec);
5605 : 0 : break;
5606 : 0 : case HNS3_GLOBAL_RESET:
5607 : 0 : val = hns3_read_dev(hw, HNS3_GLOBAL_RESET_REG);
5608 : 0 : hns3_set_bit(val, HNS3_GLOBAL_RESET_BIT, 1);
5609 : 0 : hns3_write_dev(hw, HNS3_GLOBAL_RESET_REG, val);
5610 : 0 : hns3_warn(hw, "Global Reset requested time=%ld.%.6ld",
5611 : : tv.tv_sec, tv.tv_usec);
5612 : 0 : break;
5613 : 0 : case HNS3_FUNC_RESET:
5614 : 0 : hns3_warn(hw, "PF Reset requested time=%ld.%.6ld",
5615 : : tv.tv_sec, tv.tv_usec);
5616 : : /* schedule again to check later */
5617 : 0 : hns3_atomic_set_bit(HNS3_FUNC_RESET, &hw->reset.pending);
5618 : 0 : hns3_schedule_reset(hns);
5619 : 0 : break;
5620 : 0 : default:
5621 : 0 : hns3_warn(hw, "Unsupported reset level: %d", reset_level);
5622 : 0 : return;
5623 : : }
5624 : 0 : hns3_atomic_clear_bit(reset_level, &hw->reset.request);
5625 : : }
5626 : :
5627 : : static enum hns3_reset_level
5628 [ # # ]: 0 : hns3_get_reset_level(struct hns3_adapter *hns, RTE_ATOMIC(uint64_t) *levels)
5629 : : {
5630 : : struct hns3_hw *hw = &hns->hw;
5631 : : enum hns3_reset_level reset_level = HNS3_NONE_RESET;
5632 : :
5633 : : /* Return the highest priority reset level amongst all */
5634 [ # # ]: 0 : if (hns3_atomic_test_bit(HNS3_IMP_RESET, levels))
5635 : : reset_level = HNS3_IMP_RESET;
5636 [ # # ]: 0 : else if (hns3_atomic_test_bit(HNS3_GLOBAL_RESET, levels))
5637 : : reset_level = HNS3_GLOBAL_RESET;
5638 [ # # ]: 0 : else if (hns3_atomic_test_bit(HNS3_FUNC_RESET, levels))
5639 : : reset_level = HNS3_FUNC_RESET;
5640 [ # # ]: 0 : else if (hns3_atomic_test_bit(HNS3_FLR_RESET, levels))
5641 : : reset_level = HNS3_FLR_RESET;
5642 : :
5643 [ # # # # ]: 0 : if (hw->reset.level != HNS3_NONE_RESET && reset_level < hw->reset.level)
5644 : 0 : return HNS3_NONE_RESET;
5645 : :
5646 : : return reset_level;
5647 : : }
5648 : :
5649 : : static void
5650 : 0 : hns3_record_imp_error(struct hns3_adapter *hns)
5651 : : {
5652 : : struct hns3_hw *hw = &hns->hw;
5653 : : uint32_t reg_val;
5654 : :
5655 : 0 : reg_val = hns3_read_dev(hw, HNS3_VECTOR0_OTER_EN_REG);
5656 [ # # ]: 0 : if (hns3_get_bit(reg_val, HNS3_VECTOR0_IMP_RD_POISON_B)) {
5657 : 0 : hns3_warn(hw, "Detected IMP RD poison!");
5658 : 0 : hns3_set_bit(reg_val, HNS3_VECTOR0_IMP_RD_POISON_B, 0);
5659 : 0 : hns3_write_dev(hw, HNS3_VECTOR0_OTER_EN_REG, reg_val);
5660 : : }
5661 : :
5662 [ # # ]: 0 : if (hns3_get_bit(reg_val, HNS3_VECTOR0_IMP_CMDQ_ERR_B)) {
5663 : 0 : hns3_warn(hw, "Detected IMP CMDQ error!");
5664 : 0 : hns3_set_bit(reg_val, HNS3_VECTOR0_IMP_CMDQ_ERR_B, 0);
5665 : 0 : hns3_write_dev(hw, HNS3_VECTOR0_OTER_EN_REG, reg_val);
5666 : : }
5667 : 0 : }
5668 : :
5669 : : static int
5670 : 0 : hns3_prepare_reset(struct hns3_adapter *hns)
5671 : : {
5672 : 0 : struct hns3_hw *hw = &hns->hw;
5673 : : uint32_t reg_val;
5674 : : int ret;
5675 : :
5676 [ # # # ]: 0 : switch (hw->reset.level) {
5677 : 0 : case HNS3_FUNC_RESET:
5678 : 0 : ret = hns3_func_reset_cmd(hw, HNS3_PF_FUNC_ID);
5679 [ # # ]: 0 : if (ret)
5680 : : return ret;
5681 : :
5682 : : /*
5683 : : * After performaning pf reset, it is not necessary to do the
5684 : : * mailbox handling or send any command to firmware, because
5685 : : * any mailbox handling or command to firmware is only valid
5686 : : * after hns3_cmd_init is called.
5687 : : */
5688 : 0 : rte_atomic_store_explicit(&hw->reset.disable_cmd, 1, rte_memory_order_relaxed);
5689 : 0 : hw->reset.stats.request_cnt++;
5690 : 0 : break;
5691 : 0 : case HNS3_IMP_RESET:
5692 : 0 : hns3_record_imp_error(hns);
5693 : 0 : reg_val = hns3_read_dev(hw, HNS3_VECTOR0_OTER_EN_REG);
5694 : 0 : hns3_write_dev(hw, HNS3_VECTOR0_OTER_EN_REG, reg_val |
5695 : : BIT(HNS3_VECTOR0_IMP_RESET_INT_B));
5696 : : break;
5697 : : default:
5698 : : break;
5699 : : }
5700 : : return 0;
5701 : : }
5702 : :
5703 : : static int
5704 : 0 : hns3_set_rst_done(struct hns3_hw *hw)
5705 : : {
5706 : : struct hns3_pf_rst_done_cmd *req;
5707 : : struct hns3_cmd_desc desc;
5708 : :
5709 : : req = (struct hns3_pf_rst_done_cmd *)desc.data;
5710 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_PF_RST_DONE, false);
5711 : 0 : req->pf_rst_done |= HNS3_PF_RESET_DONE_BIT;
5712 : 0 : return hns3_cmd_send(hw, &desc, 1);
5713 : : }
5714 : :
5715 : : static int
5716 : 0 : hns3_stop_service(struct hns3_adapter *hns)
5717 : : {
5718 : 0 : struct hns3_hw *hw = &hns->hw;
5719 : : struct rte_eth_dev *eth_dev;
5720 : :
5721 : 0 : eth_dev = &rte_eth_devices[hw->data->port_id];
5722 : 0 : hw->mac.link_status = RTE_ETH_LINK_DOWN;
5723 [ # # ]: 0 : if (hw->adapter_state == HNS3_NIC_STARTED) {
5724 : 0 : rte_eal_alarm_cancel(hns3_service_handler, eth_dev);
5725 : 0 : hns3_update_linkstatus_and_event(hw, false);
5726 : : }
5727 : 0 : hns3_stop_rxtx_datapath(eth_dev);
5728 : :
5729 : 0 : rte_spinlock_lock(&hw->lock);
5730 [ # # # # ]: 0 : if (hns->hw.adapter_state == HNS3_NIC_STARTED ||
5731 : : hw->adapter_state == HNS3_NIC_STOPPING) {
5732 : 0 : hns3_enable_all_queues(hw, false);
5733 : 0 : hns3_do_stop(hns);
5734 : 0 : hw->reset.mbuf_deferred_free = true;
5735 : : } else
5736 : 0 : hw->reset.mbuf_deferred_free = false;
5737 : :
5738 : : /*
5739 : : * It is cumbersome for hardware to pick-and-choose entries for deletion
5740 : : * from table space. Hence, for function reset software intervention is
5741 : : * required to delete the entries
5742 : : */
5743 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.disable_cmd, rte_memory_order_relaxed) == 0)
5744 : 0 : hns3_configure_all_mc_mac_addr(hns, true);
5745 : : rte_spinlock_unlock(&hw->lock);
5746 : :
5747 : 0 : return 0;
5748 : : }
5749 : :
5750 : : static int
5751 : 0 : hns3_start_service(struct hns3_adapter *hns)
5752 : : {
5753 : 0 : struct hns3_hw *hw = &hns->hw;
5754 : : struct rte_eth_dev *eth_dev;
5755 : :
5756 [ # # ]: 0 : if (hw->reset.level == HNS3_IMP_RESET ||
5757 : : hw->reset.level == HNS3_GLOBAL_RESET)
5758 : 0 : hns3_set_rst_done(hw);
5759 : 0 : eth_dev = &rte_eth_devices[hw->data->port_id];
5760 : 0 : hns3_start_rxtx_datapath(eth_dev);
5761 [ # # ]: 0 : if (hw->adapter_state == HNS3_NIC_STARTED) {
5762 : : /*
5763 : : * This API parent function already hold the hns3_hw.lock, the
5764 : : * hns3_service_handler may report lse, in bonding application
5765 : : * it will call driver's ops which may acquire the hns3_hw.lock
5766 : : * again, thus lead to deadlock.
5767 : : * We defer calls hns3_service_handler to avoid the deadlock.
5768 : : */
5769 : 0 : rte_eal_alarm_set(HNS3_SERVICE_QUICK_INTERVAL,
5770 : : hns3_service_handler, eth_dev);
5771 : :
5772 : : /* Enable interrupt of all rx queues before enabling queues */
5773 : 0 : hns3_dev_all_rx_queue_intr_enable(hw, true);
5774 : : /*
5775 : : * Enable state of each rxq and txq will be recovered after
5776 : : * reset, so we need to restore them before enable all tqps;
5777 : : */
5778 : 0 : hns3_restore_tqp_enable_state(hw);
5779 : : /*
5780 : : * When finished the initialization, enable queues to receive
5781 : : * and transmit packets.
5782 : : */
5783 : 0 : hns3_enable_all_queues(hw, true);
5784 : : }
5785 : :
5786 : 0 : return 0;
5787 : : }
5788 : :
5789 : : static int
5790 : 0 : hns3_restore_conf(struct hns3_adapter *hns)
5791 : : {
5792 : 0 : struct hns3_hw *hw = &hns->hw;
5793 : : int ret;
5794 : :
5795 : 0 : ret = hns3_configure_all_mac_addr(hns, false);
5796 [ # # ]: 0 : if (ret)
5797 : : return ret;
5798 : :
5799 : 0 : ret = hns3_configure_all_mc_mac_addr(hns, false);
5800 [ # # ]: 0 : if (ret)
5801 : 0 : goto err_mc_mac;
5802 : :
5803 : 0 : ret = hns3_dev_promisc_restore(hns);
5804 [ # # ]: 0 : if (ret)
5805 : 0 : goto err_promisc;
5806 : :
5807 : 0 : ret = hns3_restore_vlan_table(hns);
5808 [ # # ]: 0 : if (ret)
5809 : 0 : goto err_promisc;
5810 : :
5811 : 0 : ret = hns3_restore_vlan_conf(hns);
5812 [ # # ]: 0 : if (ret)
5813 : 0 : goto err_promisc;
5814 : :
5815 : 0 : ret = hns3_restore_ptp(hns);
5816 [ # # ]: 0 : if (ret)
5817 : 0 : goto err_promisc;
5818 : :
5819 : 0 : ret = hns3_restore_rx_interrupt(hw);
5820 [ # # ]: 0 : if (ret)
5821 : 0 : goto err_promisc;
5822 : :
5823 : 0 : ret = hns3_restore_gro_conf(hw);
5824 [ # # ]: 0 : if (ret)
5825 : 0 : goto err_promisc;
5826 : :
5827 : 0 : ret = hns3_restore_fec(hw);
5828 [ # # ]: 0 : if (ret)
5829 : 0 : goto err_promisc;
5830 : :
5831 [ # # ]: 0 : if (hns->hw.adapter_state == HNS3_NIC_STARTED) {
5832 : 0 : ret = hns3_do_start(hns, false);
5833 [ # # ]: 0 : if (ret)
5834 : 0 : goto err_promisc;
5835 : 0 : hns3_info(hw, "hns3 dev restart successful!");
5836 [ # # ]: 0 : } else if (hw->adapter_state == HNS3_NIC_STOPPING)
5837 : 0 : hw->adapter_state = HNS3_NIC_CONFIGURED;
5838 : : return 0;
5839 : :
5840 : 0 : err_promisc:
5841 : 0 : hns3_configure_all_mc_mac_addr(hns, true);
5842 : 0 : err_mc_mac:
5843 : 0 : hns3_configure_all_mac_addr(hns, true);
5844 : 0 : return ret;
5845 : : }
5846 : :
5847 : : static void
5848 : 0 : hns3_reset_service(void *param)
5849 : : {
5850 : : struct hns3_adapter *hns = (struct hns3_adapter *)param;
5851 : : struct hns3_hw *hw = &hns->hw;
5852 : : enum hns3_reset_level reset_level;
5853 : : struct timeval tv_delta;
5854 : : struct timeval tv_start;
5855 : : struct timeval tv;
5856 : : uint64_t msec;
5857 : : int ret;
5858 : :
5859 : : /*
5860 : : * The interrupt is not triggered within the delay time.
5861 : : * The interrupt may have been lost. It is necessary to handle
5862 : : * the interrupt to recover from the error.
5863 : : */
5864 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.schedule, rte_memory_order_relaxed) ==
5865 : : SCHEDULE_DEFERRED) {
5866 : 0 : rte_atomic_store_explicit(&hw->reset.schedule, SCHEDULE_REQUESTED,
5867 : : rte_memory_order_relaxed);
5868 : 0 : hns3_err(hw, "Handling interrupts in delayed tasks");
5869 : 0 : hns3_interrupt_handler(&rte_eth_devices[hw->data->port_id]);
5870 : 0 : reset_level = hns3_get_reset_level(hns, &hw->reset.pending);
5871 [ # # ]: 0 : if (reset_level == HNS3_NONE_RESET) {
5872 : 0 : hns3_err(hw, "No reset level is set, try IMP reset");
5873 : : hns3_atomic_set_bit(HNS3_IMP_RESET, &hw->reset.pending);
5874 : : }
5875 : : }
5876 : 0 : rte_atomic_store_explicit(&hw->reset.schedule, SCHEDULE_NONE, rte_memory_order_relaxed);
5877 : :
5878 : : /*
5879 : : * Check if there is any ongoing reset in the hardware. This status can
5880 : : * be checked from reset_pending. If there is then, we need to wait for
5881 : : * hardware to complete reset.
5882 : : * a. If we are able to figure out in reasonable time that hardware
5883 : : * has fully resetted then, we can proceed with driver, client
5884 : : * reset.
5885 : : * b. else, we can come back later to check this status so re-sched
5886 : : * now.
5887 : : */
5888 : 0 : reset_level = hns3_get_reset_level(hns, &hw->reset.pending);
5889 [ # # ]: 0 : if (reset_level != HNS3_NONE_RESET) {
5890 : 0 : hns3_clock_gettime(&tv_start);
5891 : 0 : ret = hns3_reset_process(hns, reset_level);
5892 : 0 : hns3_clock_gettime(&tv);
5893 [ # # ]: 0 : timersub(&tv, &tv_start, &tv_delta);
5894 : 0 : msec = hns3_clock_calctime_ms(&tv_delta);
5895 [ # # ]: 0 : if (msec > HNS3_RESET_PROCESS_MS)
5896 : 0 : hns3_err(hw, "%d handle long time delta %" PRIu64 " ms time=%ld.%.6ld",
5897 : : hw->reset.level, msec,
5898 : : tv.tv_sec, tv.tv_usec);
5899 [ # # ]: 0 : if (ret == -EAGAIN)
5900 : 0 : return;
5901 : : }
5902 : :
5903 : : /* Check if we got any *new* reset requests to be honored */
5904 : 0 : reset_level = hns3_get_reset_level(hns, &hw->reset.request);
5905 [ # # ]: 0 : if (reset_level != HNS3_NONE_RESET)
5906 : 0 : hns3_msix_process(hns, reset_level);
5907 : : }
5908 : :
5909 : : static uint32_t
5910 : 0 : hns3_get_speed_fec_capa(struct rte_eth_fec_capa *speed_fec_capa,
5911 : : uint32_t speed_capa)
5912 : : {
5913 : : uint32_t speed_bit;
5914 : : uint32_t num = 0;
5915 : : uint32_t i;
5916 : :
5917 [ # # ]: 0 : for (i = 0; i < RTE_DIM(speed_fec_capa_tbl); i++) {
5918 : : speed_bit =
5919 : 0 : rte_eth_speed_bitflag(speed_fec_capa_tbl[i].speed,
5920 : : RTE_ETH_LINK_FULL_DUPLEX);
5921 [ # # ]: 0 : if ((speed_capa & speed_bit) == 0)
5922 : 0 : continue;
5923 : :
5924 : 0 : speed_fec_capa[num].speed = speed_fec_capa_tbl[i].speed;
5925 : 0 : speed_fec_capa[num].capa = speed_fec_capa_tbl[i].capa;
5926 : 0 : num++;
5927 : : }
5928 : :
5929 : 0 : return num;
5930 : : }
5931 : :
5932 : : static int
5933 : 0 : hns3_fec_get_capability(struct rte_eth_dev *dev,
5934 : : struct rte_eth_fec_capa *speed_fec_capa,
5935 : : unsigned int num)
5936 : : {
5937 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5938 : : unsigned int speed_num;
5939 : : uint32_t speed_capa;
5940 : :
5941 : 0 : speed_capa = hns3_get_speed_capa(hw);
5942 : : /* speed_num counts number of speed capabilities */
5943 [ # # ]: 0 : speed_num = rte_popcount32(speed_capa & HNS3_SPEEDS_SUPP_FEC);
5944 [ # # ]: 0 : if (speed_num == 0)
5945 : : return -ENOTSUP;
5946 : :
5947 [ # # ]: 0 : if (speed_fec_capa == NULL)
5948 : : return speed_num;
5949 : :
5950 [ # # ]: 0 : if (num < speed_num) {
5951 : 0 : hns3_err(hw, "not enough array size(%u) to store FEC capabilities, should not be less than %u",
5952 : : num, speed_num);
5953 : 0 : return -EINVAL;
5954 : : }
5955 : :
5956 : 0 : return hns3_get_speed_fec_capa(speed_fec_capa, speed_capa);
5957 : : }
5958 : :
5959 : :
5960 : : static int
5961 : 0 : get_current_fec_auto_state(struct hns3_hw *hw, uint8_t *state)
5962 : : {
5963 : : struct hns3_config_fec_cmd *req;
5964 : : struct hns3_cmd_desc desc;
5965 : : int ret;
5966 : :
5967 : : /*
5968 : : * CMD(HNS3_OPC_CONFIG_FEC_MODE) read is not supported
5969 : : * in device of link speed
5970 : : * below 10 Gbps.
5971 : : */
5972 [ # # ]: 0 : if (hw->mac.link_speed < RTE_ETH_SPEED_NUM_10G) {
5973 : 0 : *state = 0;
5974 : 0 : return 0;
5975 : : }
5976 : :
5977 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_FEC_MODE, true);
5978 : : req = (struct hns3_config_fec_cmd *)desc.data;
5979 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
5980 [ # # ]: 0 : if (ret) {
5981 : 0 : hns3_err(hw, "get current fec auto state failed, ret = %d",
5982 : : ret);
5983 : 0 : return ret;
5984 : : }
5985 : :
5986 : 0 : *state = req->fec_mode & (1U << HNS3_MAC_CFG_FEC_AUTO_EN_B);
5987 : 0 : return 0;
5988 : : }
5989 : :
5990 : : static int
5991 : 0 : hns3_fec_get_internal(struct hns3_hw *hw, uint32_t *fec_capa)
5992 : : {
5993 : : struct hns3_sfp_info_cmd *resp;
5994 : : uint32_t tmp_fec_capa;
5995 : 0 : uint8_t auto_state = 0;
5996 : : struct hns3_cmd_desc desc;
5997 : : int ret;
5998 : :
5999 : : /*
6000 : : * If link is down and AUTO is enabled, AUTO is returned, otherwise,
6001 : : * configured FEC mode is returned.
6002 : : * If link is up, current FEC mode is returned.
6003 : : */
6004 [ # # ]: 0 : if (hw->mac.link_status == RTE_ETH_LINK_DOWN) {
6005 : 0 : ret = get_current_fec_auto_state(hw, &auto_state);
6006 [ # # ]: 0 : if (ret)
6007 : : return ret;
6008 : :
6009 [ # # ]: 0 : if (auto_state == 0x1) {
6010 : 0 : *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(AUTO);
6011 : 0 : return 0;
6012 : : }
6013 : : }
6014 : :
6015 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_GET_SFP_INFO, true);
6016 : : resp = (struct hns3_sfp_info_cmd *)desc.data;
6017 : 0 : resp->query_type = HNS3_ACTIVE_QUERY;
6018 : :
6019 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
6020 [ # # ]: 0 : if (ret == -EOPNOTSUPP) {
6021 : 0 : hns3_err(hw, "IMP do not support get FEC, ret = %d", ret);
6022 : 0 : return ret;
6023 [ # # ]: 0 : } else if (ret) {
6024 : 0 : hns3_err(hw, "get FEC failed, ret = %d", ret);
6025 : 0 : return ret;
6026 : : }
6027 : :
6028 : : /*
6029 : : * FEC mode order defined in hns3 hardware is inconsistent with
6030 : : * that defined in the ethdev library. So the sequence needs
6031 : : * to be converted.
6032 : : */
6033 [ # # ]: 0 : switch (resp->active_fec) {
6034 : : case HNS3_MAC_FEC_OFF:
6035 : : tmp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
6036 : : break;
6037 : : case HNS3_MAC_FEC_BASER:
6038 : : tmp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
6039 : : break;
6040 : : case HNS3_MAC_FEC_RS:
6041 : : tmp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(RS);
6042 : : break;
6043 : : case HNS3_MAC_FEC_LLRS:
6044 : : tmp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(LLRS);
6045 : : break;
6046 : : default:
6047 : : tmp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
6048 : : break;
6049 : : }
6050 : :
6051 : 0 : *fec_capa = tmp_fec_capa;
6052 : 0 : return 0;
6053 : : }
6054 : :
6055 : : static int
6056 : 0 : hns3_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
6057 : : {
6058 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6059 : :
6060 : 0 : return hns3_fec_get_internal(hw, fec_capa);
6061 : : }
6062 : :
6063 : : static int
6064 : 0 : hns3_set_fec_hw(struct hns3_hw *hw, uint32_t mode)
6065 : : {
6066 : : struct hns3_config_fec_cmd *req;
6067 : : struct hns3_cmd_desc desc;
6068 : : int ret;
6069 : :
6070 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CONFIG_FEC_MODE, false);
6071 : :
6072 : : req = (struct hns3_config_fec_cmd *)desc.data;
6073 [ # # # # : 0 : switch (mode) {
# # ]
6074 : 0 : case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
6075 : 0 : hns3_set_field(req->fec_mode, HNS3_MAC_CFG_FEC_MODE_M,
6076 : : HNS3_MAC_CFG_FEC_MODE_S, HNS3_MAC_FEC_OFF);
6077 : 0 : break;
6078 : 0 : case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
6079 : 0 : hns3_set_field(req->fec_mode, HNS3_MAC_CFG_FEC_MODE_M,
6080 : : HNS3_MAC_CFG_FEC_MODE_S, HNS3_MAC_FEC_BASER);
6081 : 0 : break;
6082 : 0 : case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
6083 : 0 : hns3_set_field(req->fec_mode, HNS3_MAC_CFG_FEC_MODE_M,
6084 : : HNS3_MAC_CFG_FEC_MODE_S, HNS3_MAC_FEC_RS);
6085 : 0 : break;
6086 : 0 : case RTE_ETH_FEC_MODE_CAPA_MASK(LLRS):
6087 : 0 : hns3_set_field(req->fec_mode, HNS3_MAC_CFG_FEC_MODE_M,
6088 : : HNS3_MAC_CFG_FEC_MODE_S, HNS3_MAC_FEC_LLRS);
6089 : 0 : break;
6090 : 0 : case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
6091 : 0 : hns3_set_bit(req->fec_mode, HNS3_MAC_CFG_FEC_AUTO_EN_B, 1);
6092 : 0 : break;
6093 : : default:
6094 : : return 0;
6095 : : }
6096 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
6097 [ # # ]: 0 : if (ret)
6098 : 0 : hns3_err(hw, "set fec mode failed, ret = %d", ret);
6099 : :
6100 : : return ret;
6101 : : }
6102 : :
6103 : : static uint32_t
6104 : 0 : hns3_parse_hw_fec_capa(uint8_t hw_fec_capa)
6105 : : {
6106 : : const struct {
6107 : : uint32_t hw_fec_capa;
6108 : : uint32_t fec_capa;
6109 : 0 : } fec_capa_map[] = {
6110 : : { HNS3_FIBER_FEC_AUTO_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) },
6111 : : { HNS3_FIBER_FEC_BASER_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(BASER) },
6112 : : { HNS3_FIBER_FEC_RS_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(RS) },
6113 : : { HNS3_FIBER_FEC_LLRS_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(LLRS) },
6114 : : { HNS3_FIBER_FEC_NOFEC_BIT, RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) },
6115 : : };
6116 : : uint32_t capa = 0;
6117 : : uint32_t i;
6118 : :
6119 [ # # ]: 0 : for (i = 0; i < RTE_DIM(fec_capa_map); i++) {
6120 [ # # ]: 0 : if ((hw_fec_capa & fec_capa_map[i].hw_fec_capa) != 0)
6121 : 0 : capa |= fec_capa_map[i].fec_capa;
6122 : : }
6123 : :
6124 : 0 : return capa;
6125 : : }
6126 : :
6127 : : static uint32_t
6128 : 0 : hns3_get_current_speed_fec_cap(struct hns3_mac *mac)
6129 : : {
6130 : : uint32_t i;
6131 : :
6132 [ # # ]: 0 : if (mac->fec_capa != 0)
6133 : 0 : return hns3_parse_hw_fec_capa(mac->fec_capa);
6134 : :
6135 [ # # ]: 0 : for (i = 0; i < RTE_DIM(speed_fec_capa_tbl); i++) {
6136 [ # # ]: 0 : if (mac->link_speed == speed_fec_capa_tbl[i].speed)
6137 : 0 : return speed_fec_capa_tbl[i].capa;
6138 : : }
6139 : :
6140 : : return 0;
6141 : : }
6142 : :
6143 : : static int
6144 : 0 : hns3_fec_mode_valid(struct rte_eth_dev *dev, uint32_t mode)
6145 : : {
6146 [ # # ]: 0 : struct hns3_adapter *hns = dev->data->dev_private;
6147 : : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns);
6148 : : uint32_t cur_capa;
6149 : :
6150 [ # # ]: 0 : if (rte_popcount32(mode) != 1) {
6151 : 0 : hns3_err(hw, "FEC mode(0x%x) should be only one bit set", mode);
6152 : 0 : return -EINVAL;
6153 : : }
6154 : :
6155 : : /*
6156 : : * Check whether the configured mode is within the FEC capability.
6157 : : * If not, the configured mode will not be supported.
6158 : : */
6159 : 0 : cur_capa = hns3_get_current_speed_fec_cap(&hw->mac);
6160 [ # # ]: 0 : if ((cur_capa & mode) == 0) {
6161 : 0 : hns3_err(hw, "unsupported FEC mode(0x%x)", mode);
6162 : 0 : return -EINVAL;
6163 : : }
6164 : :
6165 : : return 0;
6166 : : }
6167 : :
6168 : : static int
6169 : 0 : hns3_fec_set(struct rte_eth_dev *dev, uint32_t mode)
6170 : : {
6171 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
6172 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns);
6173 : : struct hns3_pf *pf = &hns->pf;
6174 : : int ret;
6175 : :
6176 : 0 : ret = hns3_fec_mode_valid(dev, mode);
6177 [ # # ]: 0 : if (ret != 0)
6178 : : return ret;
6179 : :
6180 : 0 : rte_spinlock_lock(&hw->lock);
6181 : 0 : ret = hns3_set_fec_hw(hw, mode);
6182 [ # # ]: 0 : if (ret) {
6183 : : rte_spinlock_unlock(&hw->lock);
6184 : 0 : return ret;
6185 : : }
6186 : :
6187 : 0 : pf->fec_mode = mode;
6188 : : rte_spinlock_unlock(&hw->lock);
6189 : :
6190 : 0 : return 0;
6191 : : }
6192 : :
6193 : : static int
6194 : 0 : hns3_restore_fec(struct hns3_hw *hw)
6195 : : {
6196 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
6197 : : struct hns3_pf *pf = &hns->pf;
6198 : 0 : uint32_t mode = pf->fec_mode;
6199 : : int ret;
6200 : :
6201 : 0 : ret = hns3_set_fec_hw(hw, mode);
6202 [ # # ]: 0 : if (ret)
6203 : 0 : hns3_err(hw, "restore fec mode(0x%x) failed, ret = %d",
6204 : : mode, ret);
6205 : :
6206 : 0 : return ret;
6207 : : }
6208 : :
6209 : : static int
6210 : 0 : hns3_query_dev_fec_info(struct hns3_hw *hw)
6211 : : {
6212 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
6213 : : struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(hns);
6214 : : int ret;
6215 : :
6216 : 0 : ret = hns3_fec_get_internal(hw, &pf->fec_mode);
6217 [ # # ]: 0 : if (ret)
6218 : 0 : hns3_err(hw, "query device FEC info failed, ret = %d", ret);
6219 : :
6220 : 0 : return ret;
6221 : : }
6222 : :
6223 : : static bool
6224 : 0 : hns3_optical_module_existed(struct hns3_hw *hw)
6225 : : {
6226 : : struct hns3_cmd_desc desc;
6227 : : bool existed;
6228 : : int ret;
6229 : :
6230 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_GET_SFP_EXIST, true);
6231 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
6232 [ # # ]: 0 : if (ret) {
6233 : 0 : hns3_err(hw,
6234 : : "fail to get optical module exist state, ret = %d.",
6235 : : ret);
6236 : 0 : return false;
6237 : : }
6238 : 0 : existed = !!desc.data[0];
6239 : :
6240 : 0 : return existed;
6241 : : }
6242 : :
6243 : : static int
6244 : 0 : hns3_get_module_eeprom_data(struct hns3_hw *hw, uint32_t offset,
6245 : : uint32_t len, uint8_t *data)
6246 : : {
6247 : : #define HNS3_SFP_INFO_CMD_NUM 6
6248 : : #define HNS3_SFP_INFO_MAX_LEN \
6249 : : (HNS3_SFP_INFO_BD0_LEN + \
6250 : : (HNS3_SFP_INFO_CMD_NUM - 1) * HNS3_SFP_INFO_BDX_LEN)
6251 : : struct hns3_cmd_desc desc[HNS3_SFP_INFO_CMD_NUM];
6252 : : struct hns3_sfp_info_bd0_cmd *sfp_info_bd0;
6253 : : uint16_t read_len;
6254 : : uint16_t copy_len;
6255 : : int ret;
6256 : : int i;
6257 : :
6258 [ # # ]: 0 : for (i = 0; i < HNS3_SFP_INFO_CMD_NUM; i++) {
6259 : 0 : hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_GET_SFP_EEPROM,
6260 : : true);
6261 [ # # ]: 0 : if (i < HNS3_SFP_INFO_CMD_NUM - 1)
6262 : 0 : desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
6263 : : }
6264 : :
6265 : : sfp_info_bd0 = (struct hns3_sfp_info_bd0_cmd *)desc[0].data;
6266 : 0 : sfp_info_bd0->offset = rte_cpu_to_le_16((uint16_t)offset);
6267 : 0 : read_len = RTE_MIN(len, HNS3_SFP_INFO_MAX_LEN);
6268 : 0 : sfp_info_bd0->read_len = rte_cpu_to_le_16((uint16_t)read_len);
6269 : :
6270 : 0 : ret = hns3_cmd_send(hw, desc, HNS3_SFP_INFO_CMD_NUM);
6271 [ # # ]: 0 : if (ret) {
6272 : 0 : hns3_err(hw, "fail to get module EEPROM info, ret = %d.",
6273 : : ret);
6274 : 0 : return ret;
6275 : : }
6276 : :
6277 : : /* The data format in BD0 is different with the others. */
6278 : 0 : copy_len = RTE_MIN(len, HNS3_SFP_INFO_BD0_LEN);
6279 : : memcpy(data, sfp_info_bd0->data, copy_len);
6280 : : read_len = copy_len;
6281 : :
6282 [ # # ]: 0 : for (i = 1; i < HNS3_SFP_INFO_CMD_NUM; i++) {
6283 [ # # ]: 0 : if (read_len >= len)
6284 : : break;
6285 : :
6286 : 0 : copy_len = RTE_MIN(len - read_len, HNS3_SFP_INFO_BDX_LEN);
6287 : 0 : memcpy(data + read_len, desc[i].data, copy_len);
6288 : 0 : read_len += copy_len;
6289 : : }
6290 : :
6291 : 0 : return (int)read_len;
6292 : : }
6293 : :
6294 : : static int
6295 : 0 : hns3_get_module_eeprom(struct rte_eth_dev *dev,
6296 : : struct rte_dev_eeprom_info *info)
6297 : : {
6298 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
6299 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns);
6300 : 0 : uint32_t offset = info->offset;
6301 : 0 : uint32_t len = info->length;
6302 : 0 : uint8_t *data = info->data;
6303 : : uint32_t read_len = 0;
6304 : :
6305 [ # # ]: 0 : if (hw->mac.media_type != HNS3_MEDIA_TYPE_FIBER)
6306 : : return -ENOTSUP;
6307 : :
6308 [ # # ]: 0 : if (!hns3_optical_module_existed(hw)) {
6309 : 0 : hns3_err(hw, "fail to read module EEPROM: no module is connected.");
6310 : 0 : return -EIO;
6311 : : }
6312 : :
6313 [ # # ]: 0 : while (read_len < len) {
6314 : : int ret;
6315 : 0 : ret = hns3_get_module_eeprom_data(hw, offset + read_len,
6316 : : len - read_len,
6317 : : data + read_len);
6318 [ # # ]: 0 : if (ret < 0)
6319 : : return -EIO;
6320 : 0 : read_len += ret;
6321 : : }
6322 : :
6323 : : return 0;
6324 : : }
6325 : :
6326 : : static int
6327 : 0 : hns3_get_module_info(struct rte_eth_dev *dev,
6328 : : struct rte_eth_dev_module_info *modinfo)
6329 : : {
6330 : : #define HNS3_SFF8024_ID_SFP 0x03
6331 : : #define HNS3_SFF8024_ID_QSFP_8438 0x0c
6332 : : #define HNS3_SFF8024_ID_QSFP_8436_8636 0x0d
6333 : : #define HNS3_SFF8024_ID_QSFP28_8636 0x11
6334 : : #define HNS3_SFF_8636_V1_3 0x03
6335 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
6336 : : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns);
6337 : : struct rte_dev_eeprom_info info;
6338 : : struct hns3_sfp_type sfp_type;
6339 : : int ret;
6340 : :
6341 : : memset(&sfp_type, 0, sizeof(sfp_type));
6342 : : memset(&info, 0, sizeof(info));
6343 : 0 : info.data = (uint8_t *)&sfp_type;
6344 : 0 : info.length = sizeof(sfp_type);
6345 : 0 : ret = hns3_get_module_eeprom(dev, &info);
6346 [ # # ]: 0 : if (ret)
6347 : : return ret;
6348 : :
6349 [ # # # # : 0 : switch (sfp_type.type) {
# ]
6350 : 0 : case HNS3_SFF8024_ID_SFP:
6351 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
6352 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
6353 : 0 : break;
6354 : 0 : case HNS3_SFF8024_ID_QSFP_8438:
6355 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8436;
6356 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8436_MAX_LEN;
6357 : 0 : break;
6358 : 0 : case HNS3_SFF8024_ID_QSFP_8436_8636:
6359 [ # # ]: 0 : if (sfp_type.ext_type < HNS3_SFF_8636_V1_3) {
6360 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8436;
6361 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8436_MAX_LEN;
6362 : : } else {
6363 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
6364 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8636_MAX_LEN;
6365 : : }
6366 : : break;
6367 : 0 : case HNS3_SFF8024_ID_QSFP28_8636:
6368 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
6369 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8636_MAX_LEN;
6370 : 0 : break;
6371 : 0 : default:
6372 : 0 : hns3_err(hw, "unknown module, type = %u, extra_type = %u.",
6373 : : sfp_type.type, sfp_type.ext_type);
6374 : 0 : return -EINVAL;
6375 : : }
6376 : :
6377 : : return 0;
6378 : : }
6379 : :
6380 : : static const struct eth_dev_ops hns3_eth_dev_ops = {
6381 : : .dev_configure = hns3_dev_configure,
6382 : : .dev_start = hns3_dev_start,
6383 : : .dev_stop = hns3_dev_stop,
6384 : : .dev_close = hns3_dev_close,
6385 : : .promiscuous_enable = hns3_dev_promiscuous_enable,
6386 : : .promiscuous_disable = hns3_dev_promiscuous_disable,
6387 : : .allmulticast_enable = hns3_dev_allmulticast_enable,
6388 : : .allmulticast_disable = hns3_dev_allmulticast_disable,
6389 : : .mtu_set = hns3_dev_mtu_set,
6390 : : .stats_get = hns3_stats_get,
6391 : : .stats_reset = hns3_stats_reset,
6392 : : .xstats_get = hns3_dev_xstats_get,
6393 : : .xstats_get_names = hns3_dev_xstats_get_names,
6394 : : .xstats_reset = hns3_dev_xstats_reset,
6395 : : .xstats_get_by_id = hns3_dev_xstats_get_by_id,
6396 : : .xstats_get_names_by_id = hns3_dev_xstats_get_names_by_id,
6397 : : .dev_infos_get = hns3_dev_infos_get,
6398 : : .fw_version_get = hns3_fw_version_get,
6399 : : .rx_queue_setup = hns3_rx_queue_setup,
6400 : : .tx_queue_setup = hns3_tx_queue_setup,
6401 : : .rx_queue_release = hns3_dev_rx_queue_release,
6402 : : .tx_queue_release = hns3_dev_tx_queue_release,
6403 : : .rx_queue_start = hns3_dev_rx_queue_start,
6404 : : .rx_queue_stop = hns3_dev_rx_queue_stop,
6405 : : .tx_queue_start = hns3_dev_tx_queue_start,
6406 : : .tx_queue_stop = hns3_dev_tx_queue_stop,
6407 : : .rx_queue_intr_enable = hns3_dev_rx_queue_intr_enable,
6408 : : .rx_queue_intr_disable = hns3_dev_rx_queue_intr_disable,
6409 : : .rxq_info_get = hns3_rxq_info_get,
6410 : : .txq_info_get = hns3_txq_info_get,
6411 : : .rx_burst_mode_get = hns3_rx_burst_mode_get,
6412 : : .tx_burst_mode_get = hns3_tx_burst_mode_get,
6413 : : .flow_ctrl_get = hns3_flow_ctrl_get,
6414 : : .flow_ctrl_set = hns3_flow_ctrl_set,
6415 : : .priority_flow_ctrl_set = hns3_priority_flow_ctrl_set,
6416 : : .mac_addr_add = hns3_add_mac_addr,
6417 : : .mac_addr_remove = hns3_remove_mac_addr,
6418 : : .mac_addr_set = hns3_set_default_mac_addr,
6419 : : .set_mc_addr_list = hns3_set_mc_mac_addr_list,
6420 : : .link_update = hns3_dev_link_update,
6421 : : .dev_set_link_up = hns3_dev_set_link_up,
6422 : : .dev_set_link_down = hns3_dev_set_link_down,
6423 : : .rss_hash_update = hns3_dev_rss_hash_update,
6424 : : .rss_hash_conf_get = hns3_dev_rss_hash_conf_get,
6425 : : .reta_update = hns3_dev_rss_reta_update,
6426 : : .reta_query = hns3_dev_rss_reta_query,
6427 : : .flow_ops_get = hns3_dev_flow_ops_get,
6428 : : .vlan_filter_set = hns3_vlan_filter_set,
6429 : : .vlan_tpid_set = hns3_vlan_tpid_set,
6430 : : .vlan_offload_set = hns3_vlan_offload_set,
6431 : : .vlan_pvid_set = hns3_vlan_pvid_set,
6432 : : .get_reg = hns3_get_regs,
6433 : : .get_module_info = hns3_get_module_info,
6434 : : .get_module_eeprom = hns3_get_module_eeprom,
6435 : : .get_dcb_info = hns3_get_dcb_info,
6436 : : .dev_supported_ptypes_get = hns3_dev_supported_ptypes_get,
6437 : : .fec_get_capability = hns3_fec_get_capability,
6438 : : .fec_get = hns3_fec_get,
6439 : : .fec_set = hns3_fec_set,
6440 : : .tm_ops_get = hns3_tm_ops_get,
6441 : : .tx_done_cleanup = hns3_tx_done_cleanup,
6442 : : .timesync_enable = hns3_timesync_enable,
6443 : : .timesync_disable = hns3_timesync_disable,
6444 : : .timesync_read_rx_timestamp = hns3_timesync_read_rx_timestamp,
6445 : : .timesync_read_tx_timestamp = hns3_timesync_read_tx_timestamp,
6446 : : .timesync_adjust_time = hns3_timesync_adjust_time,
6447 : : .timesync_read_time = hns3_timesync_read_time,
6448 : : .timesync_write_time = hns3_timesync_write_time,
6449 : : .eth_dev_priv_dump = hns3_eth_dev_priv_dump,
6450 : : .eth_rx_descriptor_dump = hns3_rx_descriptor_dump,
6451 : : .eth_tx_descriptor_dump = hns3_tx_descriptor_dump,
6452 : : .get_monitor_addr = hns3_get_monitor_addr,
6453 : : };
6454 : :
6455 : : static const struct hns3_reset_ops hns3_reset_ops = {
6456 : : .reset_service = hns3_reset_service,
6457 : : .stop_service = hns3_stop_service,
6458 : : .prepare_reset = hns3_prepare_reset,
6459 : : .wait_hardware_ready = hns3_wait_hardware_ready,
6460 : : .reinit_dev = hns3_reinit_dev,
6461 : : .restore_conf = hns3_restore_conf,
6462 : : .start_service = hns3_start_service,
6463 : : };
6464 : :
6465 : : static void
6466 : : hns3_init_hw_ops(struct hns3_hw *hw)
6467 : : {
6468 : 0 : hw->ops.add_mc_mac_addr = hns3_add_mc_mac_addr;
6469 : 0 : hw->ops.del_mc_mac_addr = hns3_remove_mc_mac_addr;
6470 : 0 : hw->ops.add_uc_mac_addr = hns3_add_uc_mac_addr;
6471 : 0 : hw->ops.del_uc_mac_addr = hns3_remove_uc_mac_addr;
6472 : 0 : hw->ops.bind_ring_with_vector = hns3_bind_ring_with_vector;
6473 : : }
6474 : :
6475 : : static int
6476 : 0 : hns3_dev_init(struct rte_eth_dev *eth_dev)
6477 : : {
6478 : 0 : struct hns3_adapter *hns = eth_dev->data->dev_private;
6479 : 0 : struct hns3_hw *hw = &hns->hw;
6480 : : int ret;
6481 : :
6482 : 0 : PMD_INIT_FUNC_TRACE();
6483 : :
6484 : 0 : hns3_flow_init(eth_dev);
6485 : :
6486 : 0 : hns3_set_rxtx_function(eth_dev);
6487 : 0 : eth_dev->dev_ops = &hns3_eth_dev_ops;
6488 : 0 : eth_dev->rx_queue_count = hns3_rx_queue_count;
6489 : 0 : ret = hns3_mp_init(eth_dev);
6490 [ # # ]: 0 : if (ret)
6491 : 0 : goto err_mp_init;
6492 : :
6493 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
6494 : 0 : hns3_tx_push_init(eth_dev);
6495 : 0 : return 0;
6496 : : }
6497 : :
6498 : 0 : hw->adapter_state = HNS3_NIC_UNINITIALIZED;
6499 : 0 : hns->is_vf = false;
6500 : 0 : hw->data = eth_dev->data;
6501 : 0 : hns3_parse_devargs(eth_dev);
6502 : :
6503 : : /*
6504 : : * Set default max packet size according to the mtu
6505 : : * default vale in DPDK frame.
6506 : : */
6507 : 0 : hns->pf.mps = hw->data->mtu + HNS3_ETH_OVERHEAD;
6508 : :
6509 : 0 : ret = hns3_reset_init(hw);
6510 [ # # ]: 0 : if (ret)
6511 : 0 : goto err_init_reset;
6512 : 0 : hw->reset.ops = &hns3_reset_ops;
6513 : :
6514 : : hns3_init_hw_ops(hw);
6515 : 0 : ret = hns3_init_pf(eth_dev);
6516 [ # # ]: 0 : if (ret) {
6517 : 0 : PMD_INIT_LOG(ERR, "Failed to init pf: %d", ret);
6518 : 0 : goto err_init_pf;
6519 : : }
6520 : :
6521 : 0 : ret = hns3_init_mac_addrs(eth_dev);
6522 [ # # ]: 0 : if (ret != 0)
6523 : 0 : goto err_init_mac_addrs;
6524 : :
6525 : 0 : hw->adapter_state = HNS3_NIC_INITIALIZED;
6526 : :
6527 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.schedule, rte_memory_order_relaxed) ==
6528 : : SCHEDULE_PENDING) {
6529 : 0 : hns3_err(hw, "Reschedule reset service after dev_init");
6530 : 0 : hns3_schedule_reset(hns);
6531 : : } else {
6532 : : /* IMP will wait ready flag before reset */
6533 : 0 : hns3_notify_reset_ready(hw, false);
6534 : : }
6535 : :
6536 : 0 : hns3_info(hw, "hns3 dev initialization successful!");
6537 : 0 : return 0;
6538 : :
6539 : : err_init_mac_addrs:
6540 : 0 : hns3_uninit_pf(eth_dev);
6541 : :
6542 : 0 : err_init_pf:
6543 : 0 : rte_free(hw->reset.wait_data);
6544 : :
6545 : 0 : err_init_reset:
6546 : 0 : hns3_mp_uninit(eth_dev);
6547 : :
6548 : 0 : err_mp_init:
6549 : 0 : eth_dev->dev_ops = NULL;
6550 : 0 : eth_dev->rx_pkt_burst = NULL;
6551 : 0 : eth_dev->rx_descriptor_status = NULL;
6552 : 0 : eth_dev->tx_pkt_burst = NULL;
6553 : 0 : eth_dev->tx_pkt_prepare = NULL;
6554 : 0 : eth_dev->tx_descriptor_status = NULL;
6555 : 0 : return ret;
6556 : : }
6557 : :
6558 : : static int
6559 : 0 : hns3_dev_uninit(struct rte_eth_dev *eth_dev)
6560 : : {
6561 : 0 : struct hns3_adapter *hns = eth_dev->data->dev_private;
6562 : : struct hns3_hw *hw = &hns->hw;
6563 : :
6564 : 0 : PMD_INIT_FUNC_TRACE();
6565 : :
6566 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
6567 : 0 : hns3_mp_uninit(eth_dev);
6568 : 0 : return 0;
6569 : : }
6570 : :
6571 [ # # ]: 0 : if (hw->adapter_state < HNS3_NIC_CLOSING)
6572 : 0 : hns3_dev_close(eth_dev);
6573 : :
6574 : 0 : hw->adapter_state = HNS3_NIC_REMOVED;
6575 : 0 : return 0;
6576 : : }
6577 : :
6578 : : static int
6579 : 0 : eth_hns3_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
6580 : : struct rte_pci_device *pci_dev)
6581 : : {
6582 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
6583 : : sizeof(struct hns3_adapter),
6584 : : hns3_dev_init);
6585 : : }
6586 : :
6587 : : static int
6588 : 0 : eth_hns3_pci_remove(struct rte_pci_device *pci_dev)
6589 : : {
6590 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, hns3_dev_uninit);
6591 : : }
6592 : :
6593 : : static const struct rte_pci_id pci_id_hns3_map[] = {
6594 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_GE) },
6595 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_25GE) },
6596 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_25GE_RDMA) },
6597 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_50GE_RDMA) },
6598 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_100G_RDMA_MACSEC) },
6599 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_200G_RDMA) },
6600 : : { .vendor_id = 0, }, /* sentinel */
6601 : : };
6602 : :
6603 : : static struct rte_pci_driver rte_hns3_pmd = {
6604 : : .id_table = pci_id_hns3_map,
6605 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
6606 : : .probe = eth_hns3_pci_probe,
6607 : : .remove = eth_hns3_pci_remove,
6608 : : };
6609 : :
6610 : 253 : RTE_PMD_REGISTER_PCI(net_hns3, rte_hns3_pmd);
6611 : : RTE_PMD_REGISTER_PCI_TABLE(net_hns3, pci_id_hns3_map);
6612 : : RTE_PMD_REGISTER_KMOD_DEP(net_hns3, "* igb_uio | vfio-pci");
6613 : : RTE_PMD_REGISTER_PARAM_STRING(net_hns3,
6614 : : HNS3_DEVARG_RX_FUNC_HINT "=vec|sve|simple|common "
6615 : : HNS3_DEVARG_TX_FUNC_HINT "=vec|sve|simple|common "
6616 : : HNS3_DEVARG_DEV_CAPS_MASK "=<1-65535> "
6617 : : HNS3_DEVARG_MBX_TIME_LIMIT_MS "=<uint16> "
6618 : : HNS3_DEVARG_FDIR_VLAN_MATCH_MODE "=strict|nostrict "
6619 : : HNS3_DEVARG_FDIR_TUPLE_CONFIG "=+outvlan-insmac|+outvlan-indmac|"
6620 : : "+outvlan-insip|+outvlan-indip"
6621 : : "+outvlan-sctptag|+outvlan-tunvni "
6622 : : HNS3_DEVARG_FDIR_INDEX_CONFIG "=hash|priority ");
6623 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(hns3_logtype_init, init, NOTICE);
6624 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(hns3_logtype_driver, driver, NOTICE);
6625 : : #ifdef RTE_ETHDEV_DEBUG_RX
6626 : : RTE_LOG_REGISTER_SUFFIX(hns3_logtype_rx, rx, DEBUG);
6627 : : #endif
6628 : : #ifdef RTE_ETHDEV_DEBUG_TX
6629 : : RTE_LOG_REGISTER_SUFFIX(hns3_logtype_tx, tx, DEBUG);
6630 : : #endif
|