xref: /f-stack/dpdk/drivers/net/hns3/hns3_rss.h (revision 2d9fd380)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2019 Hisilicon Limited.
3  */
4 
5 #ifndef _HNS3_RSS_H_
6 #define _HNS3_RSS_H_
7 #include <rte_ethdev.h>
8 #include <rte_flow.h>
9 
10 #define HNS3_ETH_RSS_SUPPORT ( \
11 	ETH_RSS_FRAG_IPV4 | \
12 	ETH_RSS_NONFRAG_IPV4_TCP | \
13 	ETH_RSS_NONFRAG_IPV4_UDP | \
14 	ETH_RSS_NONFRAG_IPV4_SCTP | \
15 	ETH_RSS_NONFRAG_IPV4_OTHER | \
16 	ETH_RSS_FRAG_IPV6 | \
17 	ETH_RSS_NONFRAG_IPV6_TCP | \
18 	ETH_RSS_NONFRAG_IPV6_UDP | \
19 	ETH_RSS_NONFRAG_IPV6_SCTP | \
20 	ETH_RSS_NONFRAG_IPV6_OTHER | \
21 	ETH_RSS_L3_SRC_ONLY | \
22 	ETH_RSS_L3_DST_ONLY | \
23 	ETH_RSS_L4_SRC_ONLY | \
24 	ETH_RSS_L4_DST_ONLY)
25 
26 #define HNS3_RSS_IND_TBL_SIZE	512 /* The size of hash lookup table */
27 #define HNS3_RSS_KEY_SIZE	40
28 #define HNS3_RSS_CFG_TBL_NUM \
29 	(HNS3_RSS_IND_TBL_SIZE / HNS3_RSS_CFG_TBL_SIZE)
30 #define HNS3_RSS_SET_BITMAP_MSK	0xffff
31 
32 #define HNS3_RSS_HASH_ALGO_TOEPLITZ	0
33 #define HNS3_RSS_HASH_ALGO_SIMPLE	1
34 #define HNS3_RSS_HASH_ALGO_SYMMETRIC_TOEP 2
35 #define HNS3_RSS_HASH_ALGO_MASK		0xf
36 
37 struct hns3_rss_tuple_cfg {
38 	uint64_t rss_tuple_fields;
39 };
40 
41 #define HNS3_RSS_QUEUES_BUFFER_NUM	64 /* Same as the Max rx/tx queue num */
42 struct hns3_rss_conf {
43 	/* RSS parameters :algorithm, flow_types,  key, queue */
44 	struct rte_flow_action_rss conf;
45 	uint8_t hash_algo; /* hash function type definited by hardware */
46 	uint8_t key[HNS3_RSS_KEY_SIZE];  /* Hash key */
47 	struct hns3_rss_tuple_cfg rss_tuple_sets;
48 	uint16_t rss_indirection_tbl[HNS3_RSS_IND_TBL_SIZE]; /* Shadow table */
49 	uint16_t queue[HNS3_RSS_QUEUES_BUFFER_NUM]; /* Queues indices to use */
50 	bool valid; /* check if RSS rule is valid */
51 	/*
52 	 * For IPv6 SCTP packets type, check whether the NIC hardware support
53 	 * RSS hash using the src/dst port as the input tuple. For Kunpeng920
54 	 * NIC hardware, it is not supported
55 	 */
56 	bool ipv6_sctp_offload_supported;
57 };
58 
59 #ifndef ilog2
rss_ilog2(uint32_t x)60 static inline int rss_ilog2(uint32_t x)
61 {
62 	int log = 0;
63 	x >>= 1;
64 
65 	while (x) {
66 		log++;
67 		x >>= 1;
68 	}
69 	return log;
70 }
71 #define ilog2(x) rss_ilog2(x)
72 #endif
73 
fls(uint32_t x)74 static inline uint32_t fls(uint32_t x)
75 {
76 	uint32_t position;
77 	uint32_t i;
78 
79 	if (x == 0)
80 		return 0;
81 
82 	for (i = (x >> 1), position = 0; i != 0; ++position)
83 		i >>= 1;
84 
85 	return position + 1;
86 }
87 
roundup_pow_of_two(uint32_t x)88 static inline uint32_t roundup_pow_of_two(uint32_t x)
89 {
90 	return 1UL << fls(x - 1);
91 }
92 
93 struct hns3_adapter;
94 
95 int hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
96 			     struct rte_eth_rss_conf *rss_conf);
97 int hns3_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
98 			       struct rte_eth_rss_conf *rss_conf);
99 int hns3_dev_rss_reta_update(struct rte_eth_dev *dev,
100 			     struct rte_eth_rss_reta_entry64 *reta_conf,
101 			     uint16_t reta_size);
102 int hns3_dev_rss_reta_query(struct rte_eth_dev *dev,
103 			    struct rte_eth_rss_reta_entry64 *reta_conf,
104 			    uint16_t reta_size);
105 void hns3_set_default_rss_args(struct hns3_hw *hw);
106 int hns3_set_rss_indir_table(struct hns3_hw *hw, uint16_t *indir,
107 			     uint16_t size);
108 int hns3_rss_reset_indir_table(struct hns3_hw *hw);
109 int hns3_config_rss(struct hns3_adapter *hns);
110 void hns3_rss_uninit(struct hns3_adapter *hns);
111 int hns3_set_rss_tuple_by_rss_hf(struct hns3_hw *hw,
112 				 struct hns3_rss_tuple_cfg *tuple,
113 				 uint64_t rss_hf);
114 int hns3_set_rss_algo_key(struct hns3_hw *hw, const uint8_t *key);
115 int hns3_restore_rss_filter(struct rte_eth_dev *dev);
116 
117 #endif /* _HNS3_RSS_H_ */
118