net/bnxt: fix logical AND in if condition
[dpdk.git] / drivers / net / hns3 / hns3_rss.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2019 Hisilicon Limited.
3  */
4
5 #include <stdbool.h>
6 #include <rte_ethdev.h>
7 #include <rte_io.h>
8 #include <rte_malloc.h>
9 #include <rte_memcpy.h>
10 #include <rte_spinlock.h>
11
12 #include "hns3_ethdev.h"
13 #include "hns3_logs.h"
14
15 /*
16  * The hash key used for rss initialization.
17  */
18 static const uint8_t hns3_hash_key[] = {
19         0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
20         0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
21         0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
22         0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
23         0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA
24 };
25
26 /*
27  * rss_generic_config command function, opcode:0x0D01.
28  * Used to set algorithm, key_offset and hash key of rss.
29  */
30 int
31 hns3_set_rss_algo_key(struct hns3_hw *hw, const uint8_t *key)
32 {
33 #define HNS3_KEY_OFFSET_MAX     3
34 #define HNS3_SET_HASH_KEY_BYTE_FOUR     2
35
36         struct hns3_rss_generic_config_cmd *req;
37         struct hns3_cmd_desc desc;
38         uint32_t key_offset, key_size;
39         const uint8_t *key_cur;
40         uint8_t cur_offset;
41         int ret;
42
43         req = (struct hns3_rss_generic_config_cmd *)desc.data;
44
45         /*
46          * key_offset=0, hash key byte0~15 is set to hardware.
47          * key_offset=1, hash key byte16~31 is set to hardware.
48          * key_offset=2, hash key byte32~39 is set to hardware.
49          */
50         for (key_offset = 0; key_offset < HNS3_KEY_OFFSET_MAX; key_offset++) {
51                 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_GENERIC_CONFIG,
52                                           false);
53
54                 req->hash_config |=
55                         (hw->rss_info.hash_algo & HNS3_RSS_HASH_ALGO_MASK);
56                 req->hash_config |= (key_offset << HNS3_RSS_HASH_KEY_OFFSET_B);
57
58                 if (key_offset == HNS3_SET_HASH_KEY_BYTE_FOUR)
59                         key_size = HNS3_RSS_KEY_SIZE - HNS3_RSS_HASH_KEY_NUM *
60                         HNS3_SET_HASH_KEY_BYTE_FOUR;
61                 else
62                         key_size = HNS3_RSS_HASH_KEY_NUM;
63
64                 cur_offset = key_offset * HNS3_RSS_HASH_KEY_NUM;
65                 key_cur = key + cur_offset;
66                 memcpy(req->hash_key, key_cur, key_size);
67
68                 ret = hns3_cmd_send(hw, &desc, 1);
69                 if (ret) {
70                         hns3_err(hw, "Configure RSS algo key failed %d", ret);
71                         return ret;
72                 }
73         }
74         /* Update the shadow RSS key with user specified */
75         memcpy(hw->rss_info.key, key, HNS3_RSS_KEY_SIZE);
76         return 0;
77 }
78
79 /*
80  * Used to configure the tuple selection for RSS hash input.
81  */
82 static int
83 hns3_set_rss_input_tuple(struct hns3_hw *hw)
84 {
85         struct hns3_rss_conf *rss_config = &hw->rss_info;
86         struct hns3_rss_input_tuple_cmd *req;
87         struct hns3_cmd_desc desc_tuple;
88         int ret;
89
90         hns3_cmd_setup_basic_desc(&desc_tuple, HNS3_OPC_RSS_INPUT_TUPLE, false);
91
92         req = (struct hns3_rss_input_tuple_cmd *)desc_tuple.data;
93
94         req->ipv4_tcp_en = rss_config->rss_tuple_sets.ipv4_tcp_en;
95         req->ipv4_udp_en = rss_config->rss_tuple_sets.ipv4_udp_en;
96         req->ipv4_sctp_en = rss_config->rss_tuple_sets.ipv4_sctp_en;
97         req->ipv4_fragment_en = rss_config->rss_tuple_sets.ipv4_fragment_en;
98         req->ipv6_tcp_en = rss_config->rss_tuple_sets.ipv6_tcp_en;
99         req->ipv6_udp_en = rss_config->rss_tuple_sets.ipv6_udp_en;
100         req->ipv6_sctp_en = rss_config->rss_tuple_sets.ipv6_sctp_en;
101         req->ipv6_fragment_en = rss_config->rss_tuple_sets.ipv6_fragment_en;
102
103         ret = hns3_cmd_send(hw, &desc_tuple, 1);
104         if (ret)
105                 hns3_err(hw, "Configure RSS input tuple mode failed %d", ret);
106
107         return ret;
108 }
109
110 /*
111  * rss_indirection_table command function, opcode:0x0D07.
112  * Used to configure the indirection table of rss.
113  */
114 int
115 hns3_set_rss_indir_table(struct hns3_hw *hw, uint8_t *indir, uint16_t size)
116 {
117         struct hns3_rss_indirection_table_cmd *req;
118         struct hns3_cmd_desc desc;
119         int ret, i, j, num;
120
121         req = (struct hns3_rss_indirection_table_cmd *)desc.data;
122
123         for (i = 0; i < size / HNS3_RSS_CFG_TBL_SIZE; i++) {
124                 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INDIR_TABLE,
125                                           false);
126                 req->start_table_index =
127                                 rte_cpu_to_le_16(i * HNS3_RSS_CFG_TBL_SIZE);
128                 req->rss_set_bitmap = rte_cpu_to_le_16(HNS3_RSS_SET_BITMAP_MSK);
129                 for (j = 0; j < HNS3_RSS_CFG_TBL_SIZE; j++) {
130                         num = i * HNS3_RSS_CFG_TBL_SIZE + j;
131                         req->rss_result[j] = indir[num];
132                 }
133                 ret = hns3_cmd_send(hw, &desc, 1);
134                 if (ret) {
135                         hns3_err(hw,
136                                  "Sets RSS indirection table failed %d size %u",
137                                  ret, size);
138                         return ret;
139                 }
140         }
141
142         /* Update redirection table of hw */
143         memcpy(hw->rss_info.rss_indirection_tbl, indir, HNS3_RSS_IND_TBL_SIZE);
144
145         return 0;
146 }
147
148 int
149 hns3_rss_reset_indir_table(struct hns3_hw *hw)
150 {
151         uint8_t *lut;
152         int ret;
153
154         lut = rte_zmalloc("hns3_rss_lut", HNS3_RSS_IND_TBL_SIZE, 0);
155         if (lut == NULL) {
156                 hns3_err(hw, "No hns3_rss_lut memory can be allocated");
157                 return -ENOMEM;
158         }
159
160         ret = hns3_set_rss_indir_table(hw, lut, HNS3_RSS_IND_TBL_SIZE);
161         if (ret)
162                 hns3_err(hw, "RSS uninit indir table failed: %d", ret);
163         rte_free(lut);
164
165         return ret;
166 }
167
168 int
169 hns3_set_rss_tuple_by_rss_hf(struct hns3_hw *hw,
170                              struct hns3_rss_tuple_cfg *tuple, uint64_t rss_hf)
171 {
172         struct hns3_rss_input_tuple_cmd *req;
173         struct hns3_cmd_desc desc;
174         uint32_t i;
175         int ret;
176
177         hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INPUT_TUPLE, false);
178
179         req = (struct hns3_rss_input_tuple_cmd *)desc.data;
180
181         /* Enable ipv4 or ipv6 tuple by flow type */
182         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
183                 switch (rss_hf & (1ULL << i)) {
184                 case ETH_RSS_NONFRAG_IPV4_TCP:
185                         req->ipv4_tcp_en = HNS3_RSS_INPUT_TUPLE_OTHER;
186                         break;
187                 case ETH_RSS_NONFRAG_IPV4_UDP:
188                         req->ipv4_udp_en = HNS3_RSS_INPUT_TUPLE_OTHER;
189                         break;
190                 case ETH_RSS_NONFRAG_IPV4_SCTP:
191                         req->ipv4_sctp_en = HNS3_RSS_INPUT_TUPLE_SCTP;
192                         break;
193                 case ETH_RSS_FRAG_IPV4:
194                         req->ipv4_fragment_en |= HNS3_IP_FRAG_BIT_MASK;
195                         break;
196                 case ETH_RSS_NONFRAG_IPV4_OTHER:
197                         req->ipv4_fragment_en |= HNS3_IP_OTHER_BIT_MASK;
198                         break;
199                 case ETH_RSS_NONFRAG_IPV6_TCP:
200                         req->ipv6_tcp_en = HNS3_RSS_INPUT_TUPLE_OTHER;
201                         break;
202                 case ETH_RSS_NONFRAG_IPV6_UDP:
203                         req->ipv6_udp_en = HNS3_RSS_INPUT_TUPLE_OTHER;
204                         break;
205                 case ETH_RSS_NONFRAG_IPV6_SCTP:
206                         req->ipv6_sctp_en = HNS3_RSS_INPUT_TUPLE_SCTP;
207                         break;
208                 case ETH_RSS_FRAG_IPV6:
209                         req->ipv6_fragment_en |= HNS3_IP_FRAG_BIT_MASK;
210                         break;
211                 case ETH_RSS_NONFRAG_IPV6_OTHER:
212                         req->ipv6_fragment_en |= HNS3_IP_OTHER_BIT_MASK;
213                         break;
214                 default:
215                         /*
216                          * rss_hf doesn't include unsupported flow types
217                          * because the API framework has checked it, and
218                          * this branch will never go unless rss_hf is zero.
219                          */
220                         break;
221                 }
222         }
223
224         ret = hns3_cmd_send(hw, &desc, 1);
225         if (ret) {
226                 hns3_err(hw, "Update RSS flow types tuples failed %d", ret);
227                 return ret;
228         }
229
230         tuple->ipv4_tcp_en = req->ipv4_tcp_en;
231         tuple->ipv4_udp_en = req->ipv4_udp_en;
232         tuple->ipv4_sctp_en = req->ipv4_sctp_en;
233         tuple->ipv4_fragment_en = req->ipv4_fragment_en;
234         tuple->ipv6_tcp_en = req->ipv6_tcp_en;
235         tuple->ipv6_udp_en = req->ipv6_udp_en;
236         tuple->ipv6_sctp_en = req->ipv6_sctp_en;
237         tuple->ipv6_fragment_en = req->ipv6_fragment_en;
238
239         return 0;
240 }
241
242 /*
243  * Configure RSS hash protocols and hash key.
244  * @param dev
245  *   Pointer to Ethernet device.
246  * @praram rss_conf
247  *   The configuration select of  rss key size and tuple flow_types.
248  * @return
249  *   0 on success, a negative errno value otherwise is set.
250  */
251 int
252 hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
253                          struct rte_eth_rss_conf *rss_conf)
254 {
255         struct hns3_adapter *hns = dev->data->dev_private;
256         struct hns3_hw *hw = &hns->hw;
257         struct hns3_rss_tuple_cfg *tuple = &hw->rss_info.rss_tuple_sets;
258         struct hns3_rss_conf *rss_cfg = &hw->rss_info;
259         uint8_t key_len = rss_conf->rss_key_len;
260         uint64_t rss_hf = rss_conf->rss_hf;
261         uint8_t *key = rss_conf->rss_key;
262         int ret;
263
264         if (hw->rss_dis_flag)
265                 return -EINVAL;
266
267         rte_spinlock_lock(&hw->lock);
268         ret = hns3_set_rss_tuple_by_rss_hf(hw, tuple, rss_hf);
269         if (ret)
270                 goto conf_err;
271
272         if (rss_cfg->conf.types && rss_hf == 0) {
273                 /* Disable RSS, reset indirection table by local variable */
274                 ret = hns3_rss_reset_indir_table(hw);
275                 if (ret)
276                         goto conf_err;
277         } else if (rss_hf && rss_cfg->conf.types == 0) {
278                 /* Enable RSS, restore indirection table by hw's config */
279                 ret = hns3_set_rss_indir_table(hw, rss_cfg->rss_indirection_tbl,
280                                                HNS3_RSS_IND_TBL_SIZE);
281                 if (ret)
282                         goto conf_err;
283         }
284
285         /* Update supported flow types when set tuple success */
286         rss_cfg->conf.types = rss_hf;
287
288         if (key) {
289                 if (key_len != HNS3_RSS_KEY_SIZE) {
290                         hns3_err(hw, "The hash key len(%u) is invalid",
291                                  key_len);
292                         ret = -EINVAL;
293                         goto conf_err;
294                 }
295                 ret = hns3_set_rss_algo_key(hw, key);
296                 if (ret)
297                         goto conf_err;
298         }
299         rte_spinlock_unlock(&hw->lock);
300
301         return 0;
302
303 conf_err:
304         rte_spinlock_unlock(&hw->lock);
305         return ret;
306 }
307
308 /*
309  * Get rss key and rss_hf types set of RSS hash configuration.
310  * @param dev
311  *   Pointer to Ethernet device.
312  * @praram rss_conf
313  *   The buffer to get rss key size and tuple types.
314  * @return
315  *   0 on success.
316  */
317 int
318 hns3_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
319                            struct rte_eth_rss_conf *rss_conf)
320 {
321         struct hns3_adapter *hns = dev->data->dev_private;
322         struct hns3_hw *hw = &hns->hw;
323         struct hns3_rss_conf *rss_cfg = &hw->rss_info;
324
325         rte_spinlock_lock(&hw->lock);
326         rss_conf->rss_hf = rss_cfg->conf.types;
327
328         /* Get the RSS Key required by the user */
329         if (rss_conf->rss_key && rss_conf->rss_key_len >= HNS3_RSS_KEY_SIZE) {
330                 memcpy(rss_conf->rss_key, rss_cfg->key, HNS3_RSS_KEY_SIZE);
331                 rss_conf->rss_key_len = HNS3_RSS_KEY_SIZE;
332         }
333         rte_spinlock_unlock(&hw->lock);
334
335         return 0;
336 }
337
338 /*
339  * Update rss redirection table of RSS.
340  * @param dev
341  *   Pointer to Ethernet device.
342  * @praram reta_conf
343  *   Pointer to the configuration select of mask and redirection tables.
344  * @param reta_size
345  *   Redirection table size.
346  * @return
347  *   0 on success, a negative errno value otherwise is set.
348  */
349 int
350 hns3_dev_rss_reta_update(struct rte_eth_dev *dev,
351                          struct rte_eth_rss_reta_entry64 *reta_conf,
352                          uint16_t reta_size)
353 {
354         struct hns3_adapter *hns = dev->data->dev_private;
355         struct hns3_hw *hw = &hns->hw;
356         struct hns3_rss_conf *rss_cfg = &hw->rss_info;
357         uint16_t i, indir_size = HNS3_RSS_IND_TBL_SIZE; /* Table size is 512 */
358         uint8_t indirection_tbl[HNS3_RSS_IND_TBL_SIZE];
359         uint16_t idx, shift, allow_rss_queues;
360         int ret;
361
362         if (reta_size != indir_size || reta_size > ETH_RSS_RETA_SIZE_512) {
363                 hns3_err(hw, "The size of hash lookup table configured (%u)"
364                          "doesn't match the number hardware can supported"
365                          "(%u)", reta_size, indir_size);
366                 return -EINVAL;
367         }
368         rte_spinlock_lock(&hw->lock);
369         memcpy(indirection_tbl, rss_cfg->rss_indirection_tbl,
370                 HNS3_RSS_IND_TBL_SIZE);
371         allow_rss_queues = RTE_MIN(dev->data->nb_rx_queues, hw->rss_size_max);
372         for (i = 0; i < reta_size; i++) {
373                 idx = i / RTE_RETA_GROUP_SIZE;
374                 shift = i % RTE_RETA_GROUP_SIZE;
375                 if (reta_conf[idx].reta[shift] >= allow_rss_queues) {
376                         rte_spinlock_unlock(&hw->lock);
377                         hns3_err(hw, "Invalid queue id(%u) to be set in "
378                                  "redirection table, max number of rss "
379                                  "queues: %u", reta_conf[idx].reta[shift],
380                                  allow_rss_queues);
381                         return -EINVAL;
382                 }
383
384                 if (reta_conf[idx].mask & (1ULL << shift))
385                         indirection_tbl[i] = reta_conf[idx].reta[shift];
386         }
387
388         ret = hns3_set_rss_indir_table(hw, indirection_tbl,
389                                        HNS3_RSS_IND_TBL_SIZE);
390
391         rte_spinlock_unlock(&hw->lock);
392         return ret;
393 }
394
395 /*
396  * Get rss redirection table of RSS hash configuration.
397  * @param dev
398  *   Pointer to Ethernet device.
399  * @praram reta_conf
400  *   Pointer to the configuration select of mask and redirection tables.
401  * @param reta_size
402  *   Redirection table size.
403  * @return
404  *   0 on success, a negative errno value otherwise is set.
405  */
406 int
407 hns3_dev_rss_reta_query(struct rte_eth_dev *dev,
408                         struct rte_eth_rss_reta_entry64 *reta_conf,
409                         uint16_t reta_size)
410 {
411         struct hns3_adapter *hns = dev->data->dev_private;
412         struct hns3_hw *hw = &hns->hw;
413         struct hns3_rss_conf *rss_cfg = &hw->rss_info;
414         uint16_t i, indir_size = HNS3_RSS_IND_TBL_SIZE; /* Table size is 512 */
415         uint16_t idx, shift;
416
417         if (reta_size != indir_size || reta_size > ETH_RSS_RETA_SIZE_512) {
418                 hns3_err(hw, "The size of hash lookup table configured (%u)"
419                          " doesn't match the number hardware can supported"
420                          "(%u)", reta_size, indir_size);
421                 return -EINVAL;
422         }
423         rte_spinlock_lock(&hw->lock);
424         for (i = 0; i < reta_size; i++) {
425                 idx = i / RTE_RETA_GROUP_SIZE;
426                 shift = i % RTE_RETA_GROUP_SIZE;
427                 if (reta_conf[idx].mask & (1ULL << shift))
428                         reta_conf[idx].reta[shift] =
429                                                 rss_cfg->rss_indirection_tbl[i];
430         }
431         rte_spinlock_unlock(&hw->lock);
432         return 0;
433 }
434
435 /*
436  * Used to configure the tc_size and tc_offset.
437  */
438 static int
439 hns3_set_rss_tc_mode(struct hns3_hw *hw)
440 {
441         uint16_t rss_size = hw->alloc_rss_size;
442         struct hns3_rss_tc_mode_cmd *req;
443         uint16_t tc_offset[HNS3_MAX_TC_NUM];
444         uint8_t tc_valid[HNS3_MAX_TC_NUM];
445         uint16_t tc_size[HNS3_MAX_TC_NUM];
446         struct hns3_cmd_desc desc;
447         uint16_t roundup_size;
448         uint16_t i;
449         int ret;
450
451         req = (struct hns3_rss_tc_mode_cmd *)desc.data;
452
453         roundup_size = roundup_pow_of_two(rss_size);
454         roundup_size = ilog2(roundup_size);
455
456         for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
457                 tc_valid[i] = !!(hw->hw_tc_map & BIT(i));
458                 tc_size[i] = roundup_size;
459                 tc_offset[i] = rss_size * i;
460         }
461
462         hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_TC_MODE, false);
463         for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
464                 uint16_t mode = 0;
465
466                 hns3_set_bit(mode, HNS3_RSS_TC_VALID_B, (tc_valid[i] & 0x1));
467                 hns3_set_field(mode, HNS3_RSS_TC_SIZE_M, HNS3_RSS_TC_SIZE_S,
468                                tc_size[i]);
469                 hns3_set_field(mode, HNS3_RSS_TC_OFFSET_M, HNS3_RSS_TC_OFFSET_S,
470                                tc_offset[i]);
471
472                 req->rss_tc_mode[i] = rte_cpu_to_le_16(mode);
473         }
474         ret = hns3_cmd_send(hw, &desc, 1);
475         if (ret)
476                 hns3_err(hw, "Sets rss tc mode failed %d", ret);
477
478         return ret;
479 }
480
481 static void
482 hns3_rss_tuple_uninit(struct hns3_hw *hw)
483 {
484         struct hns3_rss_input_tuple_cmd *req;
485         struct hns3_cmd_desc desc;
486         int ret;
487
488         hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INPUT_TUPLE, false);
489
490         req = (struct hns3_rss_input_tuple_cmd *)desc.data;
491
492         memset(req, 0, sizeof(struct hns3_rss_tuple_cfg));
493
494         ret = hns3_cmd_send(hw, &desc, 1);
495         if (ret) {
496                 hns3_err(hw, "RSS uninit tuple failed %d", ret);
497                 return;
498         }
499 }
500
501 /*
502  * Set the default rss configuration in the init of driver.
503  */
504 void
505 hns3_set_default_rss_args(struct hns3_hw *hw)
506 {
507         struct hns3_rss_conf *rss_cfg = &hw->rss_info;
508         uint16_t queue_num = hw->alloc_rss_size;
509         int i;
510
511         /* Default hash algorithm */
512         rss_cfg->conf.func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
513
514         /* Default RSS key */
515         memcpy(rss_cfg->key, hns3_hash_key, HNS3_RSS_KEY_SIZE);
516
517         /* Initialize RSS indirection table */
518         for (i = 0; i < HNS3_RSS_IND_TBL_SIZE; i++)
519                 rss_cfg->rss_indirection_tbl[i] = i % queue_num;
520 }
521
522 /*
523  * RSS initialization for hns3 pmd driver.
524  */
525 int
526 hns3_config_rss(struct hns3_adapter *hns)
527 {
528         struct hns3_hw *hw = &hns->hw;
529         struct hns3_rss_conf *rss_cfg = &hw->rss_info;
530         uint8_t *hash_key = rss_cfg->key;
531         int ret, ret1;
532
533         enum rte_eth_rx_mq_mode mq_mode = hw->data->dev_conf.rxmode.mq_mode;
534
535         switch (hw->rss_info.conf.func) {
536         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
537                 hw->rss_info.hash_algo = HNS3_RSS_HASH_ALGO_SIMPLE;
538                 break;
539         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
540                 hw->rss_info.hash_algo = HNS3_RSS_HASH_ALGO_SYMMETRIC_TOEP;
541                 break;
542         default:
543                 hw->rss_info.hash_algo = HNS3_RSS_HASH_ALGO_TOEPLITZ;
544                 break;
545         }
546
547         /* When RSS is off, redirect the packet queue 0 */
548         if (((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG) == 0)
549                 hns3_rss_uninit(hns);
550
551         /* Configure RSS hash algorithm and hash key offset */
552         ret = hns3_set_rss_algo_key(hw, hash_key);
553         if (ret)
554                 return ret;
555
556         /* Configure the tuple selection for RSS hash input */
557         ret = hns3_set_rss_input_tuple(hw);
558         if (ret)
559                 return ret;
560
561         /*
562          * When RSS is off, it doesn't need to configure rss redirection table
563          * to hardware.
564          */
565         if (((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG)) {
566                 ret = hns3_set_rss_indir_table(hw, rss_cfg->rss_indirection_tbl,
567                                                HNS3_RSS_IND_TBL_SIZE);
568                 if (ret)
569                         goto rss_tuple_uninit;
570         }
571
572         ret = hns3_set_rss_tc_mode(hw);
573         if (ret)
574                 goto rss_indir_table_uninit;
575
576         return ret;
577
578 rss_indir_table_uninit:
579         if (((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG)) {
580                 ret1 = hns3_rss_reset_indir_table(hw);
581                 if (ret1 != 0)
582                         return ret;
583         }
584
585 rss_tuple_uninit:
586         hns3_rss_tuple_uninit(hw);
587
588         /* Disable RSS */
589         hw->rss_info.conf.types = 0;
590
591         return ret;
592 }
593
594 /*
595  * RSS uninitialization for hns3 pmd driver.
596  */
597 void
598 hns3_rss_uninit(struct hns3_adapter *hns)
599 {
600         struct hns3_hw *hw = &hns->hw;
601         int ret;
602
603         hns3_rss_tuple_uninit(hw);
604         ret = hns3_rss_reset_indir_table(hw);
605         if (ret != 0)
606                 return;
607
608         /* Disable RSS */
609         hw->rss_info.conf.types = 0;
610 }