summaryrefslogtreecommitdiffstats
path: root/src/spdk/dpdk/drivers/net/hns3/hns3_rss.c
blob: a6cab29c93d7d597ec56f9d05e53b8ff0f1c2db8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2018-2019 Hisilicon Limited.
 */

#include <stdbool.h>
#include <rte_ethdev.h>
#include <rte_io.h>
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_spinlock.h>

#include "hns3_ethdev.h"
#include "hns3_logs.h"

/*
 * The hash key used for rss initialization.
 */
static const uint8_t hns3_hash_key[] = {
	0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
	0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
	0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
	0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
	0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA
};

/*
 * rss_generic_config command function, opcode:0x0D01.
 * Used to set algorithm, key_offset and hash key of rss.
 */
int
hns3_set_rss_algo_key(struct hns3_hw *hw, uint8_t hash_algo, const uint8_t *key)
{
#define HNS3_KEY_OFFSET_MAX	3
#define HNS3_SET_HASH_KEY_BYTE_FOUR	2

	struct hns3_rss_generic_config_cmd *req;
	struct hns3_cmd_desc desc;
	uint32_t key_offset, key_size;
	const uint8_t *key_cur;
	uint8_t cur_offset;
	int ret;

	req = (struct hns3_rss_generic_config_cmd *)desc.data;

	/*
	 * key_offset=0, hash key byte0~15 is set to hardware.
	 * key_offset=1, hash key byte16~31 is set to hardware.
	 * key_offset=2, hash key byte32~39 is set to hardware.
	 */
	for (key_offset = 0; key_offset < HNS3_KEY_OFFSET_MAX; key_offset++) {
		hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_GENERIC_CONFIG,
					  false);

		req->hash_config |= (hash_algo & HNS3_RSS_HASH_ALGO_MASK);
		req->hash_config |= (key_offset << HNS3_RSS_HASH_KEY_OFFSET_B);

		if (key_offset == HNS3_SET_HASH_KEY_BYTE_FOUR)
			key_size = HNS3_RSS_KEY_SIZE - HNS3_RSS_HASH_KEY_NUM *
			HNS3_SET_HASH_KEY_BYTE_FOUR;
		else
			key_size = HNS3_RSS_HASH_KEY_NUM;

		cur_offset = key_offset * HNS3_RSS_HASH_KEY_NUM;
		key_cur = key + cur_offset;
		memcpy(req->hash_key, key_cur, key_size);

		ret = hns3_cmd_send(hw, &desc, 1);
		if (ret) {
			hns3_err(hw, "Configure RSS algo key failed %d", ret);
			return ret;
		}
	}
	/* Update the shadow RSS key with user specified */
	memcpy(hw->rss_info.key, key, HNS3_RSS_KEY_SIZE);
	return 0;
}

/*
 * Used to configure the tuple selection for RSS hash input.
 */
static int
hns3_set_rss_input_tuple(struct hns3_hw *hw)
{
	struct hns3_rss_conf *rss_config = &hw->rss_info;
	struct hns3_rss_input_tuple_cmd *req;
	struct hns3_cmd_desc desc_tuple;
	int ret;

	hns3_cmd_setup_basic_desc(&desc_tuple, HNS3_OPC_RSS_INPUT_TUPLE, false);

	req = (struct hns3_rss_input_tuple_cmd *)desc_tuple.data;

	req->ipv4_tcp_en = rss_config->rss_tuple_sets.ipv4_tcp_en;
	req->ipv4_udp_en = rss_config->rss_tuple_sets.ipv4_udp_en;
	req->ipv4_sctp_en = rss_config->rss_tuple_sets.ipv4_sctp_en;
	req->ipv4_fragment_en = rss_config->rss_tuple_sets.ipv4_fragment_en;
	req->ipv6_tcp_en = rss_config->rss_tuple_sets.ipv6_tcp_en;
	req->ipv6_udp_en = rss_config->rss_tuple_sets.ipv6_udp_en;
	req->ipv6_sctp_en = rss_config->rss_tuple_sets.ipv6_sctp_en;
	req->ipv6_fragment_en = rss_config->rss_tuple_sets.ipv6_fragment_en;

	ret = hns3_cmd_send(hw, &desc_tuple, 1);
	if (ret)
		hns3_err(hw, "Configure RSS input tuple mode failed %d", ret);

	return ret;
}

/*
 * rss_indirection_table command function, opcode:0x0D07.
 * Used to configure the indirection table of rss.
 */
int
hns3_set_rss_indir_table(struct hns3_hw *hw, uint8_t *indir, uint16_t size)
{
	struct hns3_rss_indirection_table_cmd *req;
	struct hns3_cmd_desc desc;
	int ret, i, j, num;

	req = (struct hns3_rss_indirection_table_cmd *)desc.data;

	for (i = 0; i < size / HNS3_RSS_CFG_TBL_SIZE; i++) {
		hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INDIR_TABLE,
					  false);
		req->start_table_index =
				rte_cpu_to_le_16(i * HNS3_RSS_CFG_TBL_SIZE);
		req->rss_set_bitmap = rte_cpu_to_le_16(HNS3_RSS_SET_BITMAP_MSK);
		for (j = 0; j < HNS3_RSS_CFG_TBL_SIZE; j++) {
			num = i * HNS3_RSS_CFG_TBL_SIZE + j;
			req->rss_result[j] = indir[num];
		}
		ret = hns3_cmd_send(hw, &desc, 1);
		if (ret) {
			hns3_err(hw,
				 "Sets RSS indirection table failed %d size %u",
				 ret, size);
			return ret;
		}
	}

	/* Update redirection table of hw */
	memcpy(hw->rss_info.rss_indirection_tbl, indir,	HNS3_RSS_IND_TBL_SIZE);

	return 0;
}

int
hns3_rss_reset_indir_table(struct hns3_hw *hw)
{
	uint8_t *lut;
	int ret;

	lut = rte_zmalloc("hns3_rss_lut", HNS3_RSS_IND_TBL_SIZE, 0);
	if (lut == NULL) {
		hns3_err(hw, "No hns3_rss_lut memory can be allocated");
		return -ENOMEM;
	}

	ret = hns3_set_rss_indir_table(hw, lut, HNS3_RSS_IND_TBL_SIZE);
	if (ret)
		hns3_err(hw, "RSS uninit indir table failed: %d", ret);
	rte_free(lut);

	return ret;
}

int
hns3_set_rss_tuple_by_rss_hf(struct hns3_hw *hw,
			     struct hns3_rss_tuple_cfg *tuple, uint64_t rss_hf)
{
	struct hns3_rss_input_tuple_cmd *req;
	struct hns3_cmd_desc desc;
	uint32_t i;
	int ret;

	hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INPUT_TUPLE, false);

	req = (struct hns3_rss_input_tuple_cmd *)desc.data;

	/* Enable ipv4 or ipv6 tuple by flow type */
	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
		switch (rss_hf & (1ULL << i)) {
		case ETH_RSS_NONFRAG_IPV4_TCP:
			req->ipv4_tcp_en = HNS3_RSS_INPUT_TUPLE_OTHER;
			break;
		case ETH_RSS_NONFRAG_IPV4_UDP:
			req->ipv4_udp_en = HNS3_RSS_INPUT_TUPLE_OTHER;
			break;
		case ETH_RSS_NONFRAG_IPV4_SCTP:
			req->ipv4_sctp_en = HNS3_RSS_INPUT_TUPLE_SCTP;
			break;
		case ETH_RSS_FRAG_IPV4:
			req->ipv4_fragment_en |= HNS3_IP_FRAG_BIT_MASK;
			break;
		case ETH_RSS_NONFRAG_IPV4_OTHER:
			req->ipv4_fragment_en |= HNS3_IP_OTHER_BIT_MASK;
			break;
		case ETH_RSS_NONFRAG_IPV6_TCP:
			req->ipv6_tcp_en = HNS3_RSS_INPUT_TUPLE_OTHER;
			break;
		case ETH_RSS_NONFRAG_IPV6_UDP:
			req->ipv6_udp_en = HNS3_RSS_INPUT_TUPLE_OTHER;
			break;
		case ETH_RSS_NONFRAG_IPV6_SCTP:
			req->ipv6_sctp_en = HNS3_RSS_INPUT_TUPLE_SCTP;
			break;
		case ETH_RSS_FRAG_IPV6:
			req->ipv6_fragment_en |= HNS3_IP_FRAG_BIT_MASK;
			break;
		case ETH_RSS_NONFRAG_IPV6_OTHER:
			req->ipv6_fragment_en |= HNS3_IP_OTHER_BIT_MASK;
			break;
		default:
			/*
			 * rss_hf doesn't include unsupported flow types
			 * because the API framework has checked it, and
			 * this branch will never go unless rss_hf is zero.
			 */
			break;
		}
	}

	ret = hns3_cmd_send(hw, &desc, 1);
	if (ret) {
		hns3_err(hw, "Update RSS flow types tuples failed %d", ret);
		return ret;
	}

	tuple->ipv4_tcp_en = req->ipv4_tcp_en;
	tuple->ipv4_udp_en = req->ipv4_udp_en;
	tuple->ipv4_sctp_en = req->ipv4_sctp_en;
	tuple->ipv4_fragment_en = req->ipv4_fragment_en;
	tuple->ipv6_tcp_en = req->ipv6_tcp_en;
	tuple->ipv6_udp_en = req->ipv6_udp_en;
	tuple->ipv6_sctp_en = req->ipv6_sctp_en;
	tuple->ipv6_fragment_en = req->ipv6_fragment_en;

	return 0;
}

/*
 * Configure RSS hash protocols and hash key.
 * @param dev
 *   Pointer to Ethernet device.
 * @praram rss_conf
 *   The configuration select of  rss key size and tuple flow_types.
 * @return
 *   0 on success, a negative errno value otherwise is set.
 */
int
hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
			 struct rte_eth_rss_conf *rss_conf)
{
	struct hns3_adapter *hns = dev->data->dev_private;
	struct hns3_hw *hw = &hns->hw;
	struct hns3_rss_tuple_cfg *tuple = &hw->rss_info.rss_tuple_sets;
	struct hns3_rss_conf *rss_cfg = &hw->rss_info;
	uint8_t key_len = rss_conf->rss_key_len;
	uint8_t algo;
	uint64_t rss_hf = rss_conf->rss_hf;
	uint8_t *key = rss_conf->rss_key;
	int ret;

	if (hw->rss_dis_flag)
		return -EINVAL;

	rte_spinlock_lock(&hw->lock);
	ret = hns3_set_rss_tuple_by_rss_hf(hw, tuple, rss_hf);
	if (ret)
		goto conf_err;

	if (rss_cfg->conf.types && rss_hf == 0) {
		/* Disable RSS, reset indirection table by local variable */
		ret = hns3_rss_reset_indir_table(hw);
		if (ret)
			goto conf_err;
	} else if (rss_hf && rss_cfg->conf.types == 0) {
		/* Enable RSS, restore indirection table by hw's config */
		ret = hns3_set_rss_indir_table(hw, rss_cfg->rss_indirection_tbl,
					       HNS3_RSS_IND_TBL_SIZE);
		if (ret)
			goto conf_err;
	}

	/* Update supported flow types when set tuple success */
	rss_cfg->conf.types = rss_hf;

	if (key) {
		if (key_len != HNS3_RSS_KEY_SIZE) {
			hns3_err(hw, "The hash key len(%u) is invalid",
				 key_len);
			ret = -EINVAL;
			goto conf_err;
		}
		algo = rss_cfg->conf.func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR ?
			HNS3_RSS_HASH_ALGO_SIMPLE : HNS3_RSS_HASH_ALGO_TOEPLITZ;
		ret = hns3_set_rss_algo_key(hw, algo, key);
		if (ret)
			goto conf_err;
	}
	rte_spinlock_unlock(&hw->lock);

	return 0;

conf_err:
	rte_spinlock_unlock(&hw->lock);
	return ret;
}

/*
 * Get rss key and rss_hf types set of RSS hash configuration.
 * @param dev
 *   Pointer to Ethernet device.
 * @praram rss_conf
 *   The buffer to get rss key size and tuple types.
 * @return
 *   0 on success.
 */
int
hns3_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
			   struct rte_eth_rss_conf *rss_conf)
{
	struct hns3_adapter *hns = dev->data->dev_private;
	struct hns3_hw *hw = &hns->hw;
	struct hns3_rss_conf *rss_cfg = &hw->rss_info;

	rte_spinlock_lock(&hw->lock);
	rss_conf->rss_hf = rss_cfg->conf.types;

	/* Get the RSS Key required by the user */
	if (rss_conf->rss_key && rss_conf->rss_key_len >= HNS3_RSS_KEY_SIZE) {
		memcpy(rss_conf->rss_key, rss_cfg->key, HNS3_RSS_KEY_SIZE);
		rss_conf->rss_key_len = HNS3_RSS_KEY_SIZE;
	}
	rte_spinlock_unlock(&hw->lock);

	return 0;
}

/*
 * Update rss redirection table of RSS.
 * @param dev
 *   Pointer to Ethernet device.
 * @praram reta_conf
 *   Pointer to the configuration select of mask and redirection tables.
 * @param reta_size
 *   Redirection table size.
 * @return
 *   0 on success, a negative errno value otherwise is set.
 */
int
hns3_dev_rss_reta_update(struct rte_eth_dev *dev,
			 struct rte_eth_rss_reta_entry64 *reta_conf,
			 uint16_t reta_size)
{
	struct hns3_adapter *hns = dev->data->dev_private;
	struct hns3_hw *hw = &hns->hw;
	struct hns3_rss_conf *rss_cfg = &hw->rss_info;
	uint16_t i, indir_size = HNS3_RSS_IND_TBL_SIZE; /* Table size is 512 */
	uint8_t indirection_tbl[HNS3_RSS_IND_TBL_SIZE];
	uint16_t idx, shift, allow_rss_queues;
	int ret;

	if (reta_size != indir_size || reta_size > ETH_RSS_RETA_SIZE_512) {
		hns3_err(hw, "The size of hash lookup table configured (%u)"
			 "doesn't match the number hardware can supported"
			 "(%u)", reta_size, indir_size);
		return -EINVAL;
	}
	rte_spinlock_lock(&hw->lock);
	memcpy(indirection_tbl, rss_cfg->rss_indirection_tbl,
		HNS3_RSS_IND_TBL_SIZE);
	allow_rss_queues = RTE_MIN(dev->data->nb_rx_queues, hw->rss_size_max);
	for (i = 0; i < reta_size; i++) {
		idx = i / RTE_RETA_GROUP_SIZE;
		shift = i % RTE_RETA_GROUP_SIZE;
		if (reta_conf[idx].reta[shift] >= allow_rss_queues) {
			rte_spinlock_unlock(&hw->lock);
			hns3_err(hw, "Invalid queue id(%u) to be set in "
				 "redirection table, max number of rss "
				 "queues: %u", reta_conf[idx].reta[shift],
				 allow_rss_queues);
			return -EINVAL;
		}

		if (reta_conf[idx].mask & (1ULL << shift))
			indirection_tbl[i] = reta_conf[idx].reta[shift];
	}

	ret = hns3_set_rss_indir_table(hw, indirection_tbl,
				       HNS3_RSS_IND_TBL_SIZE);

	rte_spinlock_unlock(&hw->lock);
	return ret;
}

/*
 * Get rss redirection table of RSS hash configuration.
 * @param dev
 *   Pointer to Ethernet device.
 * @praram reta_conf
 *   Pointer to the configuration select of mask and redirection tables.
 * @param reta_size
 *   Redirection table size.
 * @return
 *   0 on success, a negative errno value otherwise is set.
 */
int
hns3_dev_rss_reta_query(struct rte_eth_dev *dev,
			struct rte_eth_rss_reta_entry64 *reta_conf,
			uint16_t reta_size)
{
	struct hns3_adapter *hns = dev->data->dev_private;
	struct hns3_hw *hw = &hns->hw;
	struct hns3_rss_conf *rss_cfg = &hw->rss_info;
	uint16_t i, indir_size = HNS3_RSS_IND_TBL_SIZE; /* Table size is 512 */
	uint16_t idx, shift;

	if (reta_size != indir_size || reta_size > ETH_RSS_RETA_SIZE_512) {
		hns3_err(hw, "The size of hash lookup table configured (%u)"
			 " doesn't match the number hardware can supported"
			 "(%u)", reta_size, indir_size);
		return -EINVAL;
	}
	rte_spinlock_lock(&hw->lock);
	for (i = 0; i < reta_size; i++) {
		idx = i / RTE_RETA_GROUP_SIZE;
		shift = i % RTE_RETA_GROUP_SIZE;
		if (reta_conf[idx].mask & (1ULL << shift))
			reta_conf[idx].reta[shift] =
						rss_cfg->rss_indirection_tbl[i];
	}
	rte_spinlock_unlock(&hw->lock);
	return 0;
}

/*
 * Used to configure the tc_size and tc_offset.
 */
static int
hns3_set_rss_tc_mode(struct hns3_hw *hw)
{
	uint16_t rss_size = hw->alloc_rss_size;
	struct hns3_rss_tc_mode_cmd *req;
	uint16_t tc_offset[HNS3_MAX_TC_NUM];
	uint8_t tc_valid[HNS3_MAX_TC_NUM];
	uint16_t tc_size[HNS3_MAX_TC_NUM];
	struct hns3_cmd_desc desc;
	uint16_t roundup_size;
	uint16_t i;
	int ret;

	req = (struct hns3_rss_tc_mode_cmd *)desc.data;

	roundup_size = roundup_pow_of_two(rss_size);
	roundup_size = ilog2(roundup_size);

	for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
		tc_valid[i] = !!(hw->hw_tc_map & BIT(i));
		tc_size[i] = roundup_size;
		tc_offset[i] = rss_size * i;
	}

	hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_TC_MODE, false);
	for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
		uint16_t mode = 0;

		hns3_set_bit(mode, HNS3_RSS_TC_VALID_B, (tc_valid[i] & 0x1));
		hns3_set_field(mode, HNS3_RSS_TC_SIZE_M, HNS3_RSS_TC_SIZE_S,
			       tc_size[i]);
		hns3_set_field(mode, HNS3_RSS_TC_OFFSET_M, HNS3_RSS_TC_OFFSET_S,
			       tc_offset[i]);

		req->rss_tc_mode[i] = rte_cpu_to_le_16(mode);
	}
	ret = hns3_cmd_send(hw, &desc, 1);
	if (ret)
		hns3_err(hw, "Sets rss tc mode failed %d", ret);

	return ret;
}

static void
hns3_rss_tuple_uninit(struct hns3_hw *hw)
{
	struct hns3_rss_input_tuple_cmd *req;
	struct hns3_cmd_desc desc;
	int ret;

	hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INPUT_TUPLE, false);

	req = (struct hns3_rss_input_tuple_cmd *)desc.data;

	memset(req, 0, sizeof(struct hns3_rss_tuple_cfg));

	ret = hns3_cmd_send(hw, &desc, 1);
	if (ret) {
		hns3_err(hw, "RSS uninit tuple failed %d", ret);
		return;
	}
}

/*
 * Set the default rss configuration in the init of driver.
 */
void
hns3_set_default_rss_args(struct hns3_hw *hw)
{
	struct hns3_rss_conf *rss_cfg = &hw->rss_info;
	uint16_t queue_num = hw->alloc_rss_size;
	int i;

	/* Default hash algorithm */
	rss_cfg->conf.func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;

	/* Default RSS key */
	memcpy(rss_cfg->key, hns3_hash_key, HNS3_RSS_KEY_SIZE);

	/* Initialize RSS indirection table */
	for (i = 0; i < HNS3_RSS_IND_TBL_SIZE; i++)
		rss_cfg->rss_indirection_tbl[i] = i % queue_num;
}

/*
 * RSS initialization for hns3 pmd driver.
 */
int
hns3_config_rss(struct hns3_adapter *hns)
{
	struct hns3_hw *hw = &hns->hw;
	struct hns3_rss_conf *rss_cfg = &hw->rss_info;
	uint8_t hash_algo =
		(hw->rss_info.conf.func == RTE_ETH_HASH_FUNCTION_TOEPLITZ ?
		 HNS3_RSS_HASH_ALGO_TOEPLITZ : HNS3_RSS_HASH_ALGO_SIMPLE);
	uint8_t *hash_key = rss_cfg->key;
	int ret, ret1;

	enum rte_eth_rx_mq_mode mq_mode = hw->data->dev_conf.rxmode.mq_mode;

	/* When RSS is off, redirect the packet queue 0 */
	if (((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG) == 0)
		hns3_rss_uninit(hns);

	/* Configure RSS hash algorithm and hash key offset */
	ret = hns3_set_rss_algo_key(hw, hash_algo, hash_key);
	if (ret)
		return ret;

	/* Configure the tuple selection for RSS hash input */
	ret = hns3_set_rss_input_tuple(hw);
	if (ret)
		return ret;

	/*
	 * When RSS is off, it doesn't need to configure rss redirection table
	 * to hardware.
	 */
	if (((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG)) {
		ret = hns3_set_rss_indir_table(hw, rss_cfg->rss_indirection_tbl,
					       HNS3_RSS_IND_TBL_SIZE);
		if (ret)
			goto rss_tuple_uninit;
	}

	ret = hns3_set_rss_tc_mode(hw);
	if (ret)
		goto rss_indir_table_uninit;

	return ret;

rss_indir_table_uninit:
	if (((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG)) {
		ret1 = hns3_rss_reset_indir_table(hw);
		if (ret1 != 0)
			return ret;
	}

rss_tuple_uninit:
	hns3_rss_tuple_uninit(hw);

	/* Disable RSS */
	hw->rss_info.conf.types = 0;

	return ret;
}

/*
 * RSS uninitialization for hns3 pmd driver.
 */
void
hns3_rss_uninit(struct hns3_adapter *hns)
{
	struct hns3_hw *hw = &hns->hw;
	int ret;

	hns3_rss_tuple_uninit(hw);
	ret = hns3_rss_reset_indir_table(hw);
	if (ret != 0)
		return;

	/* Disable RSS */
	hw->rss_info.conf.types = 0;
}