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_ethdev.h>
6 : : #include <rte_io.h>
7 : : #include <rte_malloc.h>
8 : : #include <rte_common.h>
9 : :
10 : : #include "hns3_ethdev.h"
11 : : #include "hns3_logs.h"
12 : :
13 : : /* Default hash keys */
14 : : const uint8_t hns3_hash_key[HNS3_RSS_KEY_SIZE] = {
15 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
16 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
17 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
18 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
19 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA
20 : : };
21 : :
22 : : const uint8_t hns3_hash_func_map[] = {
23 : : [RTE_ETH_HASH_FUNCTION_DEFAULT] = HNS3_RSS_HASH_ALGO_TOEPLITZ,
24 : : [RTE_ETH_HASH_FUNCTION_TOEPLITZ] = HNS3_RSS_HASH_ALGO_TOEPLITZ,
25 : : [RTE_ETH_HASH_FUNCTION_SIMPLE_XOR] = HNS3_RSS_HASH_ALGO_SIMPLE,
26 : : [RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ] = HNS3_RSS_HASH_ALGO_SYMMETRIC_TOEP,
27 : : };
28 : :
29 : : enum hns3_rss_tuple_type {
30 : : HNS3_RSS_IP_TUPLE,
31 : : HNS3_RSS_IP_L4_TUPLE,
32 : : };
33 : :
34 : : static const struct {
35 : : uint64_t rss_types;
36 : : uint16_t tuple_type;
37 : : uint64_t rss_field;
38 : : uint64_t tuple_mask;
39 : : } hns3_set_tuple_table[] = {
40 : : /* IPV4-FRAG */
41 : : { RTE_ETH_RSS_FRAG_IPV4 | RTE_ETH_RSS_L3_SRC_ONLY,
42 : : HNS3_RSS_IP_TUPLE,
43 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_FRAG_IP_S),
44 : : HNS3_RSS_TUPLE_IPV4_FLAG_M },
45 : : { RTE_ETH_RSS_FRAG_IPV4 | RTE_ETH_RSS_L3_DST_ONLY,
46 : : HNS3_RSS_IP_TUPLE,
47 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_FRAG_IP_D),
48 : : HNS3_RSS_TUPLE_IPV4_FLAG_M },
49 : : { RTE_ETH_RSS_FRAG_IPV4,
50 : : HNS3_RSS_IP_TUPLE,
51 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_FRAG_IP_S) |
52 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_FRAG_IP_D),
53 : : HNS3_RSS_TUPLE_IPV4_FLAG_M },
54 : :
55 : : /* IPV4 */
56 : : { RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_L3_SRC_ONLY,
57 : : HNS3_RSS_IP_TUPLE,
58 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_NONFRAG_IP_S),
59 : : HNS3_RSS_TUPLE_IPV4_NONF_M },
60 : : { RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_L3_DST_ONLY,
61 : : HNS3_RSS_IP_TUPLE,
62 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_NONFRAG_IP_D),
63 : : HNS3_RSS_TUPLE_IPV4_NONF_M },
64 : : { RTE_ETH_RSS_IPV4,
65 : : HNS3_RSS_IP_TUPLE,
66 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_NONFRAG_IP_S) |
67 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_NONFRAG_IP_D),
68 : : HNS3_RSS_TUPLE_IPV4_NONF_M },
69 : :
70 : : /* IPV4-OTHER */
71 : : { RTE_ETH_RSS_NONFRAG_IPV4_OTHER | RTE_ETH_RSS_L3_SRC_ONLY,
72 : : HNS3_RSS_IP_TUPLE,
73 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_NONFRAG_IP_S),
74 : : HNS3_RSS_TUPLE_IPV4_NONF_M },
75 : : { RTE_ETH_RSS_NONFRAG_IPV4_OTHER | RTE_ETH_RSS_L3_DST_ONLY,
76 : : HNS3_RSS_IP_TUPLE,
77 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_NONFRAG_IP_D),
78 : : HNS3_RSS_TUPLE_IPV4_NONF_M },
79 : : { RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
80 : : HNS3_RSS_IP_TUPLE,
81 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_NONFRAG_IP_S) |
82 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_EN_NONFRAG_IP_D),
83 : : HNS3_RSS_TUPLE_IPV4_NONF_M },
84 : :
85 : : /* IPV4-TCP */
86 : : { RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_L3_SRC_ONLY,
87 : : HNS3_RSS_IP_L4_TUPLE,
88 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_IP_S),
89 : : HNS3_RSS_TUPLE_IPV4_TCP_M },
90 : : { RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_L3_DST_ONLY,
91 : : HNS3_RSS_IP_L4_TUPLE,
92 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_IP_D),
93 : : HNS3_RSS_TUPLE_IPV4_TCP_M },
94 : : { RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_L4_SRC_ONLY,
95 : : HNS3_RSS_IP_L4_TUPLE,
96 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_TCP_S),
97 : : HNS3_RSS_TUPLE_IPV4_TCP_M },
98 : : { RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_L4_DST_ONLY,
99 : : HNS3_RSS_IP_L4_TUPLE,
100 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_TCP_D),
101 : : HNS3_RSS_TUPLE_IPV4_TCP_M },
102 : : { RTE_ETH_RSS_NONFRAG_IPV4_TCP,
103 : : HNS3_RSS_IP_L4_TUPLE,
104 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_IP_S) |
105 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_IP_D) |
106 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_TCP_S) |
107 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_TCP_D),
108 : : HNS3_RSS_TUPLE_IPV4_TCP_M },
109 : :
110 : : /* IPV4-UDP */
111 : : { RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_L3_SRC_ONLY,
112 : : HNS3_RSS_IP_L4_TUPLE,
113 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_IP_S),
114 : : HNS3_RSS_TUPLE_IPV4_UDP_M },
115 : : { RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_L3_DST_ONLY,
116 : : HNS3_RSS_IP_L4_TUPLE,
117 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_IP_D),
118 : : HNS3_RSS_TUPLE_IPV4_UDP_M },
119 : : { RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_L4_SRC_ONLY,
120 : : HNS3_RSS_IP_L4_TUPLE,
121 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_UDP_S),
122 : : HNS3_RSS_TUPLE_IPV4_UDP_M },
123 : : { RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_L4_DST_ONLY,
124 : : HNS3_RSS_IP_L4_TUPLE,
125 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_UDP_D),
126 : : HNS3_RSS_TUPLE_IPV4_UDP_M },
127 : : { RTE_ETH_RSS_NONFRAG_IPV4_UDP,
128 : : HNS3_RSS_IP_L4_TUPLE,
129 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_IP_S) |
130 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_IP_D) |
131 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_UDP_S) |
132 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_UDP_D),
133 : : HNS3_RSS_TUPLE_IPV4_UDP_M },
134 : :
135 : : /* IPV4-SCTP */
136 : : { RTE_ETH_RSS_NONFRAG_IPV4_SCTP | RTE_ETH_RSS_L3_SRC_ONLY,
137 : : HNS3_RSS_IP_L4_TUPLE,
138 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_SCTP_EN_IP_S),
139 : : HNS3_RSS_TUPLE_IPV4_SCTP_M },
140 : : { RTE_ETH_RSS_NONFRAG_IPV4_SCTP | RTE_ETH_RSS_L3_DST_ONLY,
141 : : HNS3_RSS_IP_L4_TUPLE,
142 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_SCTP_EN_IP_D),
143 : : HNS3_RSS_TUPLE_IPV4_SCTP_M },
144 : : { RTE_ETH_RSS_NONFRAG_IPV4_SCTP | RTE_ETH_RSS_L4_SRC_ONLY,
145 : : HNS3_RSS_IP_L4_TUPLE,
146 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_SCTP_EN_SCTP_S),
147 : : HNS3_RSS_TUPLE_IPV4_SCTP_M },
148 : : { RTE_ETH_RSS_NONFRAG_IPV4_SCTP | RTE_ETH_RSS_L4_DST_ONLY,
149 : : HNS3_RSS_IP_L4_TUPLE,
150 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_SCTP_EN_SCTP_D),
151 : : HNS3_RSS_TUPLE_IPV4_SCTP_M },
152 : : { RTE_ETH_RSS_NONFRAG_IPV4_SCTP,
153 : : HNS3_RSS_IP_L4_TUPLE,
154 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_SCTP_EN_IP_S) |
155 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_SCTP_EN_IP_D) |
156 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_SCTP_EN_SCTP_S) |
157 : : BIT_ULL(HNS3_RSS_FIELD_IPV4_SCTP_EN_SCTP_D),
158 : : HNS3_RSS_TUPLE_IPV4_SCTP_M },
159 : :
160 : : /* IPV6-FRAG */
161 : : { RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_L3_SRC_ONLY,
162 : : HNS3_RSS_IP_TUPLE,
163 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_FRAG_IP_S),
164 : : HNS3_RSS_TUPLE_IPV6_FLAG_M },
165 : : { RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_L3_DST_ONLY,
166 : : HNS3_RSS_IP_TUPLE,
167 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_FRAG_IP_D),
168 : : HNS3_RSS_TUPLE_IPV6_FLAG_M },
169 : : { RTE_ETH_RSS_FRAG_IPV6,
170 : : HNS3_RSS_IP_TUPLE,
171 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_FRAG_IP_S) |
172 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_FRAG_IP_D),
173 : : HNS3_RSS_TUPLE_IPV6_FLAG_M },
174 : :
175 : : /* IPV6 */
176 : : { RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_L3_SRC_ONLY,
177 : : HNS3_RSS_IP_TUPLE,
178 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_NONFRAG_IP_S),
179 : : HNS3_RSS_TUPLE_IPV6_NONF_M },
180 : : { RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_L3_DST_ONLY,
181 : : HNS3_RSS_IP_TUPLE,
182 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_NONFRAG_IP_D),
183 : : HNS3_RSS_TUPLE_IPV6_NONF_M },
184 : : { RTE_ETH_RSS_IPV6,
185 : : HNS3_RSS_IP_TUPLE,
186 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_NONFRAG_IP_S) |
187 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_NONFRAG_IP_D),
188 : : HNS3_RSS_TUPLE_IPV6_NONF_M },
189 : :
190 : : /* IPV6-OTHER */
191 : : { RTE_ETH_RSS_NONFRAG_IPV6_OTHER | RTE_ETH_RSS_L3_SRC_ONLY,
192 : : HNS3_RSS_IP_TUPLE,
193 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_NONFRAG_IP_S),
194 : : HNS3_RSS_TUPLE_IPV6_NONF_M },
195 : : { RTE_ETH_RSS_NONFRAG_IPV6_OTHER | RTE_ETH_RSS_L3_DST_ONLY,
196 : : HNS3_RSS_IP_TUPLE,
197 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_NONFRAG_IP_D),
198 : : HNS3_RSS_TUPLE_IPV6_NONF_M },
199 : : { RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
200 : : HNS3_RSS_IP_TUPLE,
201 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_NONFRAG_IP_S) |
202 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_NONFRAG_IP_D),
203 : : HNS3_RSS_TUPLE_IPV6_NONF_M },
204 : :
205 : : /* IPV6-TCP */
206 : : { RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_L3_SRC_ONLY,
207 : : HNS3_RSS_IP_L4_TUPLE,
208 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_TCP_EN_IP_S),
209 : : HNS3_RSS_TUPLE_IPV6_TCP_M },
210 : : { RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_L3_DST_ONLY,
211 : : HNS3_RSS_IP_L4_TUPLE,
212 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_TCP_EN_IP_D),
213 : : HNS3_RSS_TUPLE_IPV6_TCP_M },
214 : : { RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_L4_SRC_ONLY,
215 : : HNS3_RSS_IP_L4_TUPLE,
216 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_TCP_EN_TCP_S),
217 : : HNS3_RSS_TUPLE_IPV6_TCP_M },
218 : : { RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_L4_DST_ONLY,
219 : : HNS3_RSS_IP_L4_TUPLE,
220 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_TCP_EN_TCP_D),
221 : : HNS3_RSS_TUPLE_IPV6_TCP_M },
222 : : { RTE_ETH_RSS_NONFRAG_IPV6_TCP,
223 : : HNS3_RSS_IP_L4_TUPLE,
224 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_TCP_EN_IP_S) |
225 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_TCP_EN_IP_D) |
226 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_TCP_EN_TCP_S) |
227 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_TCP_EN_TCP_D),
228 : : HNS3_RSS_TUPLE_IPV6_TCP_M },
229 : :
230 : : /* IPV6-UDP */
231 : : { RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_L3_SRC_ONLY,
232 : : HNS3_RSS_IP_L4_TUPLE,
233 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_UDP_EN_IP_S),
234 : : HNS3_RSS_TUPLE_IPV6_UDP_M },
235 : : { RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_L3_DST_ONLY,
236 : : HNS3_RSS_IP_L4_TUPLE,
237 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_UDP_EN_IP_D),
238 : : HNS3_RSS_TUPLE_IPV6_UDP_M },
239 : : { RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_L4_SRC_ONLY,
240 : : HNS3_RSS_IP_L4_TUPLE,
241 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_UDP_EN_UDP_S),
242 : : HNS3_RSS_TUPLE_IPV6_UDP_M },
243 : : { RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_L4_DST_ONLY,
244 : : HNS3_RSS_IP_L4_TUPLE,
245 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_UDP_EN_UDP_D),
246 : : HNS3_RSS_TUPLE_IPV6_UDP_M },
247 : : { RTE_ETH_RSS_NONFRAG_IPV6_UDP,
248 : : HNS3_RSS_IP_L4_TUPLE,
249 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_UDP_EN_IP_S) |
250 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_UDP_EN_IP_D) |
251 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_UDP_EN_UDP_S) |
252 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_UDP_EN_UDP_D),
253 : : HNS3_RSS_TUPLE_IPV6_UDP_M },
254 : :
255 : : /* IPV6-SCTP */
256 : : { RTE_ETH_RSS_NONFRAG_IPV6_SCTP | RTE_ETH_RSS_L3_SRC_ONLY,
257 : : HNS3_RSS_IP_L4_TUPLE,
258 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_IP_S),
259 : : HNS3_RSS_TUPLE_IPV6_SCTP_M },
260 : : { RTE_ETH_RSS_NONFRAG_IPV6_SCTP | RTE_ETH_RSS_L3_DST_ONLY,
261 : : HNS3_RSS_IP_L4_TUPLE,
262 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_IP_D),
263 : : HNS3_RSS_TUPLE_IPV6_SCTP_M },
264 : : { RTE_ETH_RSS_NONFRAG_IPV6_SCTP | RTE_ETH_RSS_L4_SRC_ONLY,
265 : : HNS3_RSS_IP_L4_TUPLE,
266 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_SCTP_S),
267 : : HNS3_RSS_TUPLE_IPV6_SCTP_M },
268 : : { RTE_ETH_RSS_NONFRAG_IPV6_SCTP | RTE_ETH_RSS_L4_DST_ONLY,
269 : : HNS3_RSS_IP_L4_TUPLE,
270 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_SCTP_D),
271 : : HNS3_RSS_TUPLE_IPV6_SCTP_M },
272 : : { RTE_ETH_RSS_NONFRAG_IPV6_SCTP,
273 : : HNS3_RSS_IP_L4_TUPLE,
274 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_IP_S) |
275 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_IP_D) |
276 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_SCTP_D) |
277 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_SCTP_S),
278 : : HNS3_RSS_TUPLE_IPV6_SCTP_M },
279 : : };
280 : :
281 : : /*
282 : : * rss_generic_config command function, opcode:0x0D01.
283 : : * Used to set algorithm and hash key of RSS.
284 : : */
285 : : static int
286 : 0 : hns3_rss_set_algo_key(struct hns3_hw *hw, uint8_t hash_algo,
287 : : const uint8_t *key, uint8_t key_len)
288 : : {
289 : : struct hns3_rss_generic_config_cmd *req;
290 : : struct hns3_cmd_desc desc;
291 : : const uint8_t *cur_key;
292 : : uint16_t cur_key_size;
293 : : uint16_t max_bd_num;
294 : : uint16_t idx;
295 : : int ret;
296 : :
297 : : req = (struct hns3_rss_generic_config_cmd *)desc.data;
298 : :
299 : 0 : max_bd_num = RTE_DIV_ROUND_UP(key_len, HNS3_RSS_HASH_KEY_NUM);
300 [ # # ]: 0 : for (idx = 0; idx < max_bd_num; idx++) {
301 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_GENERIC_CONFIG,
302 : : false);
303 : :
304 : 0 : req->hash_config |= (hash_algo & HNS3_RSS_HASH_ALGO_MASK);
305 : 0 : req->hash_config |= (idx << HNS3_RSS_HASH_KEY_OFFSET_B);
306 : :
307 [ # # ]: 0 : if (idx == max_bd_num - 1 &&
308 [ # # ]: 0 : (key_len % HNS3_RSS_HASH_KEY_NUM) != 0)
309 : 0 : cur_key_size = key_len % HNS3_RSS_HASH_KEY_NUM;
310 : : else
311 : : cur_key_size = HNS3_RSS_HASH_KEY_NUM;
312 : :
313 : 0 : cur_key = key + idx * HNS3_RSS_HASH_KEY_NUM;
314 : 0 : memcpy(req->hash_key, cur_key, cur_key_size);
315 : :
316 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
317 [ # # ]: 0 : if (ret) {
318 : 0 : hns3_err(hw, "Configure RSS algo key failed %d", ret);
319 : 0 : return ret;
320 : : }
321 : : }
322 : :
323 : : return 0;
324 : : }
325 : :
326 : : static int
327 : 0 : hns3_rss_get_algo_key(struct hns3_hw *hw, uint8_t *hash_algo,
328 : : uint8_t *key, uint8_t key_len)
329 : : {
330 : : struct hns3_rss_generic_config_cmd *req;
331 : : struct hns3_cmd_desc desc;
332 : : uint16_t cur_key_size;
333 : : uint16_t max_bd_num;
334 : : uint8_t *cur_key;
335 : : uint16_t idx;
336 : : int ret;
337 : :
338 : : req = (struct hns3_rss_generic_config_cmd *)desc.data;
339 : 0 : max_bd_num = RTE_DIV_ROUND_UP(key_len, HNS3_RSS_HASH_KEY_NUM);
340 [ # # ]: 0 : for (idx = 0; idx < max_bd_num; idx++) {
341 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_GENERIC_CONFIG,
342 : : true);
343 : :
344 : 0 : req->hash_config |= (idx << HNS3_RSS_HASH_KEY_OFFSET_B);
345 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
346 [ # # ]: 0 : if (ret) {
347 : 0 : hns3_err(hw, "fail to obtain RSS algo and key from firmware, ret = %d",
348 : : ret);
349 : 0 : return ret;
350 : : }
351 : :
352 [ # # ]: 0 : if (idx == 0)
353 : 0 : *hash_algo = req->hash_config & HNS3_RSS_HASH_ALGO_MASK;
354 : :
355 [ # # ]: 0 : if (idx == max_bd_num - 1 &&
356 [ # # ]: 0 : (key_len % HNS3_RSS_HASH_KEY_NUM) != 0)
357 : 0 : cur_key_size = key_len % HNS3_RSS_HASH_KEY_NUM;
358 : : else
359 : : cur_key_size = HNS3_RSS_HASH_KEY_NUM;
360 : :
361 : 0 : cur_key = key + idx * HNS3_RSS_HASH_KEY_NUM;
362 : 0 : memcpy(cur_key, req->hash_key, cur_key_size);
363 : : }
364 : :
365 : : return 0;
366 : : }
367 : :
368 : : /*
369 : : * rss_indirection_table command function, opcode:0x0D07.
370 : : * Used to configure the indirection table of rss.
371 : : */
372 : : int
373 : 0 : hns3_set_rss_indir_table(struct hns3_hw *hw, uint16_t *indir, uint16_t size)
374 : : {
375 : : struct hns3_rss_indirection_table_cmd *req;
376 : : uint16_t max_bd_num, cfg_tbl_size;
377 : : struct hns3_cmd_desc desc;
378 : : uint8_t qid_msb_off;
379 : : uint8_t qid_msb_val;
380 : : uint16_t q_id;
381 : : uint16_t i, j;
382 : : int ret;
383 : :
384 : : req = (struct hns3_rss_indirection_table_cmd *)desc.data;
385 : 0 : max_bd_num = RTE_DIV_ROUND_UP(size, HNS3_RSS_CFG_TBL_SIZE);
386 [ # # ]: 0 : for (i = 0; i < max_bd_num; i++) {
387 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INDIR_TABLE,
388 : : false);
389 : 0 : req->start_table_index =
390 : : rte_cpu_to_le_16(i * HNS3_RSS_CFG_TBL_SIZE);
391 : 0 : req->rss_set_bitmap = rte_cpu_to_le_16(HNS3_RSS_SET_BITMAP_MSK);
392 : :
393 [ # # # # ]: 0 : if (i == max_bd_num - 1 && (size % HNS3_RSS_CFG_TBL_SIZE) != 0)
394 : 0 : cfg_tbl_size = size % HNS3_RSS_CFG_TBL_SIZE;
395 : : else
396 : : cfg_tbl_size = HNS3_RSS_CFG_TBL_SIZE;
397 : :
398 [ # # ]: 0 : for (j = 0; j < cfg_tbl_size; j++) {
399 : 0 : q_id = indir[i * HNS3_RSS_CFG_TBL_SIZE + j];
400 : 0 : req->rss_result_l[j] = q_id & 0xff;
401 : :
402 : : qid_msb_off =
403 : 0 : j * HNS3_RSS_CFG_TBL_BW_H / HNS3_BITS_PER_BYTE;
404 : 0 : qid_msb_val = (q_id >> HNS3_RSS_CFG_TBL_BW_L & 0x1)
405 : 0 : << (j * HNS3_RSS_CFG_TBL_BW_H %
406 : : HNS3_BITS_PER_BYTE);
407 : 0 : req->rss_result_h[qid_msb_off] |= qid_msb_val;
408 : : }
409 : :
410 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
411 [ # # ]: 0 : if (ret) {
412 : 0 : hns3_err(hw,
413 : : "Sets RSS indirection table failed %d size %u",
414 : : ret, size);
415 : 0 : return ret;
416 : : }
417 : : }
418 : :
419 : : return 0;
420 : : }
421 : :
422 : : static int
423 : 0 : hns3_get_rss_indir_table(struct hns3_hw *hw, uint16_t *indir, uint16_t size)
424 : : {
425 : : struct hns3_rss_indirection_table_cmd *req;
426 : : uint16_t max_bd_num, cfg_tbl_size;
427 : : uint8_t qid_msb_off, qid_msb_idx;
428 : : struct hns3_cmd_desc desc;
429 : : uint16_t q_id, q_hi, q_lo;
430 : : uint8_t rss_result_h;
431 : : uint16_t i, j;
432 : : int ret;
433 : :
434 : : req = (struct hns3_rss_indirection_table_cmd *)desc.data;
435 : 0 : max_bd_num = RTE_DIV_ROUND_UP(size, HNS3_RSS_CFG_TBL_SIZE);
436 [ # # ]: 0 : for (i = 0; i < max_bd_num; i++) {
437 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INDIR_TABLE,
438 : : true);
439 : 0 : req->start_table_index =
440 : : rte_cpu_to_le_16(i * HNS3_RSS_CFG_TBL_SIZE);
441 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
442 [ # # ]: 0 : if (ret) {
443 : 0 : hns3_err(hw, "fail to get RSS indirection table from firmware, ret = %d",
444 : : ret);
445 : 0 : return ret;
446 : : }
447 : :
448 [ # # # # ]: 0 : if (i == max_bd_num - 1 && (size % HNS3_RSS_CFG_TBL_SIZE) != 0)
449 : 0 : cfg_tbl_size = size % HNS3_RSS_CFG_TBL_SIZE;
450 : : else
451 : : cfg_tbl_size = HNS3_RSS_CFG_TBL_SIZE;
452 : :
453 [ # # ]: 0 : for (j = 0; j < cfg_tbl_size; j++) {
454 : : qid_msb_idx =
455 : 0 : j * HNS3_RSS_CFG_TBL_BW_H / HNS3_BITS_PER_BYTE;
456 : 0 : rss_result_h = req->rss_result_h[qid_msb_idx];
457 : 0 : qid_msb_off =
458 : 0 : j * HNS3_RSS_CFG_TBL_BW_H % HNS3_BITS_PER_BYTE;
459 : 0 : q_hi = (rss_result_h >> qid_msb_off) &
460 : : HNS3_RSS_CFG_TBL_BW_H_M;
461 : 0 : q_lo = req->rss_result_l[j];
462 : 0 : q_id = (q_hi << HNS3_RSS_CFG_TBL_BW_L) | q_lo;
463 : 0 : indir[i * HNS3_RSS_CFG_TBL_SIZE + j] = q_id;
464 : : }
465 : : }
466 : :
467 : : return 0;
468 : : }
469 : :
470 : : int
471 : 0 : hns3_rss_reset_indir_table(struct hns3_hw *hw)
472 : : {
473 : : uint16_t *lut;
474 : : int ret;
475 : :
476 : 0 : lut = rte_zmalloc("hns3_rss_lut",
477 : 0 : hw->rss_ind_tbl_size * sizeof(uint16_t), 0);
478 [ # # ]: 0 : if (lut == NULL) {
479 : 0 : hns3_err(hw, "No hns3_rss_lut memory can be allocated");
480 : 0 : return -ENOMEM;
481 : : }
482 : :
483 : 0 : ret = hns3_set_rss_indir_table(hw, lut, hw->rss_ind_tbl_size);
484 [ # # ]: 0 : if (ret != 0)
485 : 0 : hns3_err(hw, "RSS uninit indir table failed, ret = %d.", ret);
486 : : else
487 : 0 : memcpy(hw->rss_info.rss_indirection_tbl, lut,
488 : 0 : sizeof(uint16_t) * hw->rss_ind_tbl_size);
489 : 0 : rte_free(lut);
490 : :
491 : 0 : return ret;
492 : : }
493 : :
494 : : bool
495 : 0 : hns3_check_rss_types_valid(struct hns3_hw *hw, uint64_t types)
496 : : {
497 : : uint64_t ip_mask = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
498 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER |
499 : : RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
500 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER;
501 : : uint64_t ip_l4_mask = RTE_ETH_RSS_NONFRAG_IPV4_TCP |
502 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP |
503 : : RTE_ETH_RSS_NONFRAG_IPV4_SCTP |
504 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP |
505 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP |
506 : : RTE_ETH_RSS_NONFRAG_IPV6_SCTP;
507 : 0 : bool has_l4_src_dst = !!(types & HNS3_RSS_SUPPORT_L4_SRC_DST);
508 : 0 : bool has_ip_pkt = !!(types & ip_mask);
509 : : uint64_t final_types;
510 : :
511 [ # # ]: 0 : if (types == 0)
512 : : return true;
513 : :
514 [ # # ]: 0 : if ((types & HNS3_ETH_RSS_SUPPORT) == 0) {
515 : 0 : hns3_err(hw, "specified types(0x%" PRIx64 ") are unsupported.",
516 : : types);
517 : 0 : return false;
518 : : }
519 : :
520 [ # # ]: 0 : if ((types & HNS3_RSS_SUPPORT_L3_SRC_DST) != 0 &&
521 [ # # ]: 0 : (types & HNS3_RSS_SUPPORT_FLOW_TYPE) == 0) {
522 : 0 : hns3_err(hw, "IP or IP-TCP/UDP/SCTP packet type isn't specified, L3_SRC/DST_ONLY cannot be set.");
523 : 0 : return false;
524 : : }
525 : :
526 [ # # # # ]: 0 : if (has_l4_src_dst && (types & ip_l4_mask) == 0) {
527 [ # # ]: 0 : if (!has_ip_pkt) {
528 : 0 : hns3_err(hw, "IP-TCP/UDP/SCTP packet type isn't specified, L4_SRC/DST_ONLY cannot be set.");
529 : 0 : return false;
530 : : }
531 : : /*
532 : : * For the case that the types has L4_SRC/DST_ONLY but hasn't
533 : : * IP-TCP/UDP/SCTP packet type, this types is considered valid
534 : : * if it also has IP packet type.
535 : : */
536 : 0 : hns3_warn(hw, "L4_SRC/DST_ONLY is ignored because of no including L4 packet.");
537 : : }
538 : :
539 [ # # ]: 0 : if ((types & ~HNS3_ETH_RSS_SUPPORT) != 0) {
540 : : final_types = types & HNS3_ETH_RSS_SUPPORT;
541 : 0 : hns3_warn(hw, "set RSS types based on hardware support, requested:0x%" PRIx64 " configured:0x%" PRIx64 "",
542 : : types, final_types);
543 : : }
544 : :
545 : : return true;
546 : : }
547 : :
548 : : uint64_t
549 : 0 : hns3_rss_calc_tuple_filed(uint64_t rss_hf)
550 : : {
551 : : uint64_t l3_only_mask = RTE_ETH_RSS_L3_SRC_ONLY |
552 : : RTE_ETH_RSS_L3_DST_ONLY;
553 : : uint64_t l4_only_mask = RTE_ETH_RSS_L4_SRC_ONLY |
554 : : RTE_ETH_RSS_L4_DST_ONLY;
555 : : uint64_t l3_l4_only_mask = l3_only_mask | l4_only_mask;
556 : 0 : bool has_l3_l4_only = !!(rss_hf & l3_l4_only_mask);
557 : 0 : bool has_l3_only = !!(rss_hf & l3_only_mask);
558 : : uint64_t tuple = 0;
559 : : uint32_t i;
560 : :
561 [ # # ]: 0 : for (i = 0; i < RTE_DIM(hns3_set_tuple_table); i++) {
562 [ # # ]: 0 : if ((rss_hf & hns3_set_tuple_table[i].rss_types) !=
563 : : hns3_set_tuple_table[i].rss_types)
564 : 0 : continue;
565 : :
566 [ # # ]: 0 : if (hns3_set_tuple_table[i].tuple_type == HNS3_RSS_IP_TUPLE) {
567 [ # # # # ]: 0 : if (hns3_set_tuple_table[i].rss_types & l3_only_mask ||
568 : : !has_l3_only)
569 : 0 : tuple |= hns3_set_tuple_table[i].rss_field;
570 : 0 : continue;
571 : : }
572 : :
573 : : /* For IP types with L4, we need check both L3 and L4 */
574 [ # # # # ]: 0 : if (hns3_set_tuple_table[i].rss_types & l3_l4_only_mask ||
575 : : !has_l3_l4_only)
576 : 0 : tuple |= hns3_set_tuple_table[i].rss_field;
577 : : }
578 : :
579 : 0 : return tuple;
580 : : }
581 : :
582 : : int
583 : 0 : hns3_set_rss_tuple_field(struct hns3_hw *hw, uint64_t tuple_fields)
584 : : {
585 : : struct hns3_rss_input_tuple_cmd *req;
586 : : struct hns3_cmd_desc desc;
587 : : int ret;
588 : :
589 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INPUT_TUPLE, false);
590 : : req = (struct hns3_rss_input_tuple_cmd *)desc.data;
591 : 0 : req->tuple_field = rte_cpu_to_le_64(tuple_fields);
592 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
593 [ # # ]: 0 : if (ret != 0)
594 : 0 : hns3_err(hw, "set RSS hash tuple fields failed ret = %d", ret);
595 : :
596 : 0 : return ret;
597 : : }
598 : :
599 : : int
600 : 0 : hns3_set_rss_tuple_by_rss_hf(struct hns3_hw *hw, uint64_t rss_hf)
601 : : {
602 : : uint64_t tuple_fields;
603 : : int ret;
604 : :
605 : 0 : tuple_fields = hns3_rss_calc_tuple_filed(rss_hf);
606 : 0 : ret = hns3_set_rss_tuple_field(hw, tuple_fields);
607 [ # # ]: 0 : if (ret != 0)
608 : 0 : hns3_err(hw, "Update RSS flow types tuples failed, ret = %d",
609 : : ret);
610 : :
611 : 0 : return ret;
612 : : }
613 : :
614 : : /*
615 : : * Configure RSS hash protocols and hash key.
616 : : * @param dev
617 : : * Pointer to Ethernet device.
618 : : * @praram rss_conf
619 : : * The configuration select of rss key size and tuple flow_types.
620 : : * @return
621 : : * 0 on success, a negative errno value otherwise is set.
622 : : */
623 : : int
624 : 0 : hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
625 : : struct rte_eth_rss_conf *rss_conf)
626 : : {
627 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
628 : 0 : uint64_t rss_hf_bk = hw->rss_info.rss_hf;
629 : 0 : uint8_t key_len = rss_conf->rss_key_len;
630 : 0 : uint64_t rss_hf = rss_conf->rss_hf;
631 : 0 : uint8_t *key = rss_conf->rss_key;
632 : : int ret;
633 : :
634 [ # # # # ]: 0 : if (key && key_len != hw->rss_key_size) {
635 : 0 : hns3_err(hw, "the hash key len(%u) is invalid, must be %u",
636 : : key_len, hw->rss_key_size);
637 : 0 : return -EINVAL;
638 : : }
639 : :
640 [ # # ]: 0 : if (!hns3_check_rss_types_valid(hw, rss_hf))
641 : : return -EINVAL;
642 : :
643 : 0 : rte_spinlock_lock(&hw->lock);
644 : 0 : ret = hns3_set_rss_tuple_by_rss_hf(hw, rss_hf);
645 [ # # ]: 0 : if (ret)
646 : 0 : goto set_tuple_fail;
647 : :
648 : 0 : ret = hns3_update_rss_algo_key(hw, rss_conf->algorithm, key, key_len);
649 [ # # ]: 0 : if (ret != 0)
650 : 0 : goto set_algo_key_fail;
651 : :
652 [ # # ]: 0 : if (rss_conf->algorithm != RTE_ETH_HASH_FUNCTION_DEFAULT)
653 : 0 : hw->rss_info.hash_algo = hns3_hash_func_map[rss_conf->algorithm];
654 [ # # ]: 0 : if (key != NULL)
655 : 0 : memcpy(hw->rss_info.key, key, hw->rss_key_size);
656 : 0 : hw->rss_info.rss_hf = rss_hf;
657 : : rte_spinlock_unlock(&hw->lock);
658 : :
659 : 0 : return 0;
660 : :
661 : : set_algo_key_fail:
662 : 0 : (void)hns3_set_rss_tuple_by_rss_hf(hw, rss_hf_bk);
663 : 0 : set_tuple_fail:
664 : : rte_spinlock_unlock(&hw->lock);
665 : 0 : return ret;
666 : : }
667 : :
668 : : int
669 : 0 : hns3_get_rss_tuple_field(struct hns3_hw *hw, uint64_t *tuple_fields)
670 : : {
671 : : struct hns3_rss_input_tuple_cmd *req;
672 : : struct hns3_cmd_desc desc;
673 : : int ret;
674 : :
675 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INPUT_TUPLE, true);
676 : : req = (struct hns3_rss_input_tuple_cmd *)desc.data;
677 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
678 [ # # ]: 0 : if (ret != 0) {
679 : 0 : hns3_err(hw, "fail to get RSS hash tuple fields from firmware, ret = %d",
680 : : ret);
681 : 0 : return ret;
682 : : }
683 : :
684 : 0 : *tuple_fields = rte_le_to_cpu_64(req->tuple_field);
685 : :
686 : 0 : return 0;
687 : : }
688 : :
689 : : static uint64_t
690 : 0 : hns3_rss_tuple_fields_to_rss_hf(struct hns3_hw *hw, uint64_t tuple_fields)
691 : : {
692 : : uint64_t ipv6_sctp_l4_mask =
693 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_SCTP_D) |
694 : : BIT_ULL(HNS3_RSS_FIELD_IPV6_SCTP_EN_SCTP_S);
695 : : uint64_t rss_hf = 0;
696 : : uint64_t tuple_mask;
697 : : uint32_t i;
698 : :
699 [ # # ]: 0 : for (i = 0; i < RTE_DIM(hns3_set_tuple_table); i++) {
700 : 0 : tuple_mask = hns3_set_tuple_table[i].tuple_mask;
701 : : /*
702 : : * The RSS hash of the packet type is disabled if its tuples is
703 : : * zero.
704 : : */
705 [ # # ]: 0 : if ((tuple_fields & tuple_mask) == 0)
706 : 0 : continue;
707 : :
708 : : /*
709 : : * Some hardware don't support to use src/dst port fields to
710 : : * hash for IPV6-SCTP packet.
711 : : */
712 [ # # ]: 0 : if ((hns3_set_tuple_table[i].rss_types &
713 : 0 : RTE_ETH_RSS_NONFRAG_IPV6_SCTP) &&
714 [ # # ]: 0 : !hw->rss_info.ipv6_sctp_offload_supported)
715 : 0 : tuple_mask &= ~ipv6_sctp_l4_mask;
716 : :
717 : : /*
718 : : * The framework (ethdev ops) or driver (rte flow API) ensure
719 : : * that both L3_SRC/DST_ONLY and L4_SRC/DST_ONLY cannot be set
720 : : * to driver at the same time. But if user doesn't specify
721 : : * anything L3/L4_SRC/DST_ONLY, driver enables all tuple fields.
722 : : * In this case, driver should not report L3/L4_SRC/DST_ONLY.
723 : : */
724 [ # # ]: 0 : if ((tuple_fields & tuple_mask) == tuple_mask) {
725 : : /* Skip the item enabled part tuples. */
726 [ # # ]: 0 : if ((tuple_fields & hns3_set_tuple_table[i].rss_field) !=
727 : : tuple_mask)
728 : 0 : continue;
729 : :
730 : 0 : rss_hf |= hns3_set_tuple_table[i].rss_types;
731 : 0 : continue;
732 : : }
733 : :
734 : : /* Match the item enabled part tuples.*/
735 [ # # ]: 0 : if ((tuple_fields & hns3_set_tuple_table[i].rss_field) ==
736 : : hns3_set_tuple_table[i].rss_field)
737 : 0 : rss_hf |= hns3_set_tuple_table[i].rss_types;
738 : : }
739 : :
740 : 0 : return rss_hf;
741 : : }
742 : :
743 : : static int
744 : 0 : hns3_rss_hash_get_rss_hf(struct hns3_hw *hw, uint64_t *rss_hf)
745 : : {
746 : : uint64_t tuple_fields;
747 : : int ret;
748 : :
749 : 0 : ret = hns3_get_rss_tuple_field(hw, &tuple_fields);
750 [ # # ]: 0 : if (ret != 0)
751 : : return ret;
752 : :
753 : 0 : *rss_hf = hns3_rss_tuple_fields_to_rss_hf(hw, tuple_fields);
754 : :
755 : 0 : return 0;
756 : : }
757 : :
758 : : /*
759 : : * Get rss key and rss_hf types set of RSS hash configuration.
760 : : * @param dev
761 : : * Pointer to Ethernet device.
762 : : * @praram rss_conf
763 : : * The buffer to get rss key size and tuple types.
764 : : * @return
765 : : * 0 on success.
766 : : */
767 : : int
768 : 0 : hns3_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
769 : : struct rte_eth_rss_conf *rss_conf)
770 : : {
771 : 0 : const uint8_t hash_func_map[] = {
772 : : [HNS3_RSS_HASH_ALGO_TOEPLITZ] = RTE_ETH_HASH_FUNCTION_TOEPLITZ,
773 : : [HNS3_RSS_HASH_ALGO_SIMPLE] = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR,
774 : : [HNS3_RSS_HASH_ALGO_SYMMETRIC_TOEP] = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ,
775 : : };
776 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
777 : 0 : uint8_t rss_key[HNS3_RSS_KEY_SIZE_MAX] = {0};
778 : 0 : struct hns3_hw *hw = &hns->hw;
779 : 0 : uint8_t hash_algo = 0;
780 : : int ret;
781 : :
782 : 0 : rte_spinlock_lock(&hw->lock);
783 : 0 : ret = hns3_rss_hash_get_rss_hf(hw, &rss_conf->rss_hf);
784 [ # # ]: 0 : if (ret != 0) {
785 : : rte_spinlock_unlock(&hw->lock);
786 : 0 : hns3_err(hw, "obtain hash tuples failed, ret = %d", ret);
787 : 0 : return ret;
788 : : }
789 : :
790 : 0 : ret = hns3_rss_get_algo_key(hw, &hash_algo, rss_key, hw->rss_key_size);
791 [ # # ]: 0 : if (ret != 0) {
792 : : rte_spinlock_unlock(&hw->lock);
793 : 0 : hns3_err(hw, "obtain hash algo and key failed, ret = %d", ret);
794 : 0 : return ret;
795 : : }
796 : : rte_spinlock_unlock(&hw->lock);
797 : :
798 : : /* Get the RSS Key if user required. */
799 [ # # # # ]: 0 : if (rss_conf->rss_key && rss_conf->rss_key_len >= hw->rss_key_size) {
800 : 0 : memcpy(rss_conf->rss_key, rss_key, hw->rss_key_size);
801 : 0 : rss_conf->rss_key_len = hw->rss_key_size;
802 : : }
803 : 0 : rss_conf->algorithm = hash_func_map[hash_algo];
804 : :
805 : 0 : return 0;
806 : : }
807 : :
808 : : /*
809 : : * Update rss redirection table of RSS.
810 : : * @param dev
811 : : * Pointer to Ethernet device.
812 : : * @praram reta_conf
813 : : * Pointer to the configuration select of mask and redirection tables.
814 : : * @param reta_size
815 : : * Redirection table size.
816 : : * @return
817 : : * 0 on success, a negative errno value otherwise is set.
818 : : */
819 : : int
820 : 0 : hns3_dev_rss_reta_update(struct rte_eth_dev *dev,
821 : : struct rte_eth_rss_reta_entry64 *reta_conf,
822 : : uint16_t reta_size)
823 : : {
824 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
825 : 0 : struct hns3_hw *hw = &hns->hw;
826 : : struct hns3_rss_conf *rss_cfg = &hw->rss_info;
827 : : uint16_t indirection_tbl[HNS3_RSS_IND_TBL_SIZE_MAX];
828 : : uint16_t idx, shift;
829 : : uint16_t i;
830 : : int ret;
831 : :
832 [ # # ]: 0 : if (reta_size != hw->rss_ind_tbl_size) {
833 : 0 : hns3_err(hw, "The size of hash lookup table configured (%u)"
834 : : "doesn't match the number hardware can supported"
835 : : "(%u)", reta_size, hw->rss_ind_tbl_size);
836 : 0 : return -EINVAL;
837 : : }
838 : 0 : rte_spinlock_lock(&hw->lock);
839 : 0 : memcpy(indirection_tbl, rss_cfg->rss_indirection_tbl,
840 : : sizeof(rss_cfg->rss_indirection_tbl));
841 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
842 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
843 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
844 [ # # ]: 0 : if (reta_conf[idx].reta[shift] >= hw->alloc_rss_size) {
845 : 0 : hns3_err(hw, "queue id(%u) set to redirection table "
846 : : "exceeds queue number(%u) allocated to a TC",
847 : : reta_conf[idx].reta[shift],
848 : : hw->alloc_rss_size);
849 : : ret = -EINVAL;
850 : 0 : goto out;
851 : : }
852 : :
853 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
854 : 0 : indirection_tbl[i] = reta_conf[idx].reta[shift];
855 : : }
856 : :
857 : 0 : ret = hns3_set_rss_indir_table(hw, indirection_tbl,
858 : 0 : hw->rss_ind_tbl_size);
859 [ # # ]: 0 : if (ret != 0)
860 : 0 : goto out;
861 : :
862 : 0 : memcpy(rss_cfg->rss_indirection_tbl, indirection_tbl,
863 : 0 : sizeof(uint16_t) * hw->rss_ind_tbl_size);
864 : :
865 : 0 : out:
866 : : rte_spinlock_unlock(&hw->lock);
867 : 0 : return ret;
868 : : }
869 : :
870 : : /*
871 : : * Get rss redirection table of RSS hash configuration.
872 : : * @param dev
873 : : * Pointer to Ethernet device.
874 : : * @praram reta_conf
875 : : * Pointer to the configuration select of mask and redirection tables.
876 : : * @param reta_size
877 : : * Redirection table size.
878 : : * @return
879 : : * 0 on success, a negative errno value otherwise is set.
880 : : */
881 : : int
882 : 0 : hns3_dev_rss_reta_query(struct rte_eth_dev *dev,
883 : : struct rte_eth_rss_reta_entry64 *reta_conf,
884 : : uint16_t reta_size)
885 : : {
886 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
887 : : uint16_t reta_table[HNS3_RSS_IND_TBL_SIZE_MAX];
888 : 0 : struct hns3_hw *hw = &hns->hw;
889 : : uint16_t idx, shift;
890 : : uint16_t i;
891 : : int ret;
892 : :
893 [ # # ]: 0 : if (reta_size != hw->rss_ind_tbl_size) {
894 : 0 : hns3_err(hw, "The size of hash lookup table configured (%u)"
895 : : " doesn't match the number hardware can supported"
896 : : "(%u)", reta_size, hw->rss_ind_tbl_size);
897 : 0 : return -EINVAL;
898 : : }
899 : 0 : rte_spinlock_lock(&hw->lock);
900 : 0 : ret = hns3_get_rss_indir_table(hw, reta_table, reta_size);
901 [ # # ]: 0 : if (ret != 0) {
902 : : rte_spinlock_unlock(&hw->lock);
903 : 0 : hns3_err(hw, "query RSS redirection table failed, ret = %d.",
904 : : ret);
905 : 0 : return ret;
906 : : }
907 : : rte_spinlock_unlock(&hw->lock);
908 : :
909 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
910 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
911 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
912 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
913 : 0 : reta_conf[idx].reta[shift] = reta_table[i];
914 : : }
915 : :
916 : : return 0;
917 : : }
918 : :
919 : : static void
920 : 0 : hns3_set_rss_tc_mode_entry(struct hns3_hw *hw, uint8_t *tc_valid,
921 : : uint16_t *tc_size, uint16_t *tc_offset,
922 : : uint8_t tc_num)
923 : : {
924 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
925 : 0 : uint16_t rss_size = hw->alloc_rss_size;
926 : : uint16_t roundup_size;
927 : : uint16_t i;
928 : :
929 [ # # ]: 0 : roundup_size = roundup_pow_of_two(rss_size);
930 : 0 : roundup_size = ilog2(roundup_size);
931 : :
932 [ # # ]: 0 : for (i = 0; i < tc_num; i++) {
933 [ # # ]: 0 : if (hns->is_vf) {
934 : : /*
935 : : * For packets with VLAN priorities destined for the VF,
936 : : * hardware still assign Rx queue based on the Up-to-TC
937 : : * mapping PF configured. But VF has only one TC. If
938 : : * other TC don't enable, it causes that the priority
939 : : * packets that aren't destined for TC0 aren't received
940 : : * by RSS hash but is destined for queue 0. So driver
941 : : * has to enable the unused TC by using TC0 queue
942 : : * mapping configuration.
943 : : */
944 : 0 : tc_valid[i] = (hw->dcb_info.hw_tc_map & BIT(i)) ?
945 : : !!(hw->dcb_info.hw_tc_map & BIT(i)) : 1;
946 : 0 : tc_size[i] = roundup_size;
947 [ # # ]: 0 : tc_offset[i] = (hw->dcb_info.hw_tc_map & BIT(i)) ?
948 : : rss_size * i : 0;
949 : : } else {
950 : 0 : tc_valid[i] = !!(hw->dcb_info.hw_tc_map & BIT(i));
951 [ # # ]: 0 : tc_size[i] = tc_valid[i] ? roundup_size : 0;
952 [ # # ]: 0 : tc_offset[i] = tc_valid[i] ? rss_size * i : 0;
953 : : }
954 : : }
955 : 0 : }
956 : :
957 : : static int
958 : 0 : hns3_set_rss_tc_mode(struct hns3_hw *hw)
959 : : {
960 : : struct hns3_rss_tc_mode_cmd *req;
961 : : uint16_t tc_offset[HNS3_MAX_TC_NUM];
962 : : uint8_t tc_valid[HNS3_MAX_TC_NUM];
963 : : uint16_t tc_size[HNS3_MAX_TC_NUM];
964 : : struct hns3_cmd_desc desc;
965 : : uint16_t i;
966 : : int ret;
967 : :
968 : 0 : hns3_set_rss_tc_mode_entry(hw, tc_valid, tc_size,
969 : : tc_offset, HNS3_MAX_TC_NUM);
970 : :
971 : : req = (struct hns3_rss_tc_mode_cmd *)desc.data;
972 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_TC_MODE, false);
973 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
974 : : uint16_t mode = 0;
975 : :
976 : 0 : hns3_set_bit(mode, HNS3_RSS_TC_VALID_B, (tc_valid[i] & 0x1));
977 : 0 : hns3_set_field(mode, HNS3_RSS_TC_SIZE_M, HNS3_RSS_TC_SIZE_S,
978 : : tc_size[i]);
979 [ # # ]: 0 : if (tc_size[i] >> HNS3_RSS_TC_SIZE_MSB_OFFSET > 0)
980 : 0 : hns3_set_bit(mode, HNS3_RSS_TC_SIZE_MSB_S, 1);
981 : 0 : hns3_set_field(mode, HNS3_RSS_TC_OFFSET_M, HNS3_RSS_TC_OFFSET_S,
982 : : tc_offset[i]);
983 : :
984 : 0 : req->rss_tc_mode[i] = rte_cpu_to_le_16(mode);
985 : : }
986 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
987 [ # # ]: 0 : if (ret)
988 : 0 : hns3_err(hw, "Sets rss tc mode failed %d", ret);
989 : :
990 : 0 : return ret;
991 : : }
992 : :
993 : : /*
994 : : * Note: the 'hash_algo' is defined by enum rte_eth_hash_function.
995 : : */
996 : : int
997 : 0 : hns3_update_rss_algo_key(struct hns3_hw *hw, uint8_t hash_func,
998 : : uint8_t *key, uint8_t key_len)
999 : : {
1000 : 0 : uint8_t rss_key[HNS3_RSS_KEY_SIZE_MAX] = {0};
1001 : : bool modify_key, modify_algo;
1002 : 0 : uint8_t hash_algo = 0;
1003 : : int ret;
1004 : :
1005 : 0 : modify_key = (key != NULL && key_len > 0);
1006 : : modify_algo = hash_func != RTE_ETH_HASH_FUNCTION_DEFAULT;
1007 [ # # ]: 0 : if (!modify_key && !modify_algo)
1008 : : return 0;
1009 : :
1010 [ # # ]: 0 : if (modify_algo && hash_func >= RTE_DIM(hns3_hash_func_map)) {
1011 : 0 : hns3_err(hw, "hash func (%u) is unsupported.", hash_func);
1012 : 0 : return -ENOTSUP;
1013 : : }
1014 [ # # # # ]: 0 : if (modify_key && key_len != hw->rss_key_size) {
1015 : 0 : hns3_err(hw, "hash key length (%u) is invalid.", key_len);
1016 : 0 : return -EINVAL;
1017 : : }
1018 : :
1019 : 0 : ret = hns3_rss_get_algo_key(hw, &hash_algo, rss_key, hw->rss_key_size);
1020 [ # # ]: 0 : if (ret != 0) {
1021 : 0 : hns3_err(hw, "fail to get RSS hash algorithm and key, ret = %d",
1022 : : ret);
1023 : 0 : return ret;
1024 : : }
1025 : :
1026 [ # # ]: 0 : if (modify_algo)
1027 : 0 : hash_algo = hns3_hash_func_map[hash_func];
1028 [ # # ]: 0 : if (modify_key)
1029 : 0 : memcpy(rss_key, key, key_len);
1030 : :
1031 : 0 : ret = hns3_rss_set_algo_key(hw, hash_algo, rss_key, hw->rss_key_size);
1032 [ # # ]: 0 : if (ret != 0)
1033 : 0 : hns3_err(hw, "fail to set RSS hash algorithm and key, ret = %d",
1034 : : ret);
1035 : :
1036 : : return ret;
1037 : : }
1038 : :
1039 : : static void
1040 : 0 : hns3_rss_tuple_uninit(struct hns3_hw *hw)
1041 : : {
1042 : : struct hns3_cmd_desc desc;
1043 : : int ret;
1044 : :
1045 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_INPUT_TUPLE, false);
1046 : :
1047 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
1048 [ # # ]: 0 : if (ret) {
1049 : 0 : hns3_err(hw, "RSS uninit tuple failed %d", ret);
1050 : 0 : return;
1051 : : }
1052 : : }
1053 : :
1054 : : /*
1055 : : * Set the default rss configuration in the init of driver.
1056 : : */
1057 : : void
1058 : 0 : hns3_rss_set_default_args(struct hns3_hw *hw)
1059 : : {
1060 : : struct hns3_rss_conf *rss_cfg = &hw->rss_info;
1061 : 0 : uint16_t queue_num = hw->alloc_rss_size;
1062 : : uint16_t i;
1063 : :
1064 : : /* Default hash algorithm */
1065 : 0 : rss_cfg->hash_algo = HNS3_RSS_HASH_ALGO_TOEPLITZ;
1066 : :
1067 : 0 : hw->rss_info.rss_hf = 0;
1068 : 0 : memcpy(rss_cfg->key, hns3_hash_key,
1069 : 0 : RTE_MIN(sizeof(hns3_hash_key), hw->rss_key_size));
1070 : :
1071 : : /* Initialize RSS indirection table */
1072 [ # # ]: 0 : for (i = 0; i < hw->rss_ind_tbl_size; i++)
1073 : 0 : rss_cfg->rss_indirection_tbl[i] = i % queue_num;
1074 : 0 : }
1075 : :
1076 : : /*
1077 : : * RSS initialization for hns3 PMD.
1078 : : */
1079 : : int
1080 : 0 : hns3_config_rss(struct hns3_adapter *hns)
1081 : : {
1082 : 0 : struct hns3_hw *hw = &hns->hw;
1083 : : struct hns3_rss_conf *rss_cfg = &hw->rss_info;
1084 : 0 : uint8_t *hash_key = rss_cfg->key;
1085 : : uint64_t rss_hf;
1086 : : int ret;
1087 : :
1088 : 0 : enum rte_eth_rx_mq_mode mq_mode = hw->data->dev_conf.rxmode.mq_mode;
1089 : :
1090 : 0 : ret = hns3_rss_set_algo_key(hw, rss_cfg->hash_algo,
1091 : 0 : hash_key, hw->rss_key_size);
1092 [ # # ]: 0 : if (ret)
1093 : : return ret;
1094 : :
1095 : 0 : ret = hns3_set_rss_indir_table(hw, rss_cfg->rss_indirection_tbl,
1096 : 0 : hw->rss_ind_tbl_size);
1097 [ # # ]: 0 : if (ret)
1098 : : return ret;
1099 : :
1100 : 0 : ret = hns3_set_rss_tc_mode(hw);
1101 [ # # ]: 0 : if (ret)
1102 : : return ret;
1103 : :
1104 : : /*
1105 : : * When multi-queue RSS mode flag is not set or unsupported tuples are
1106 : : * set, disable all tuples.
1107 : : */
1108 : 0 : rss_hf = hw->rss_info.rss_hf;
1109 [ # # ]: 0 : if (!((uint32_t)mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) ||
1110 [ # # ]: 0 : !(rss_hf & HNS3_ETH_RSS_SUPPORT))
1111 : : rss_hf = 0;
1112 : :
1113 : 0 : ret = hns3_set_rss_tuple_by_rss_hf(hw, rss_hf);
1114 [ # # ]: 0 : if (ret != 0) {
1115 : 0 : hns3_err(hw, "set RSS tuples failed, ret = %d.", ret);
1116 : 0 : return ret;
1117 : : }
1118 : 0 : hw->rss_info.rss_hf = rss_hf;
1119 : :
1120 : 0 : return 0;
1121 : : }
1122 : :
1123 : : /*
1124 : : * RSS uninitialization for hns3 PMD.
1125 : : */
1126 : : void
1127 : 0 : hns3_rss_uninit(struct hns3_adapter *hns)
1128 : : {
1129 : 0 : struct hns3_hw *hw = &hns->hw;
1130 : : int ret;
1131 : :
1132 : 0 : hns3_rss_tuple_uninit(hw);
1133 : 0 : ret = hns3_rss_reset_indir_table(hw);
1134 [ # # ]: 0 : if (ret != 0)
1135 : : return;
1136 : :
1137 : : /* Disable RSS */
1138 : 0 : hw->rss_info.rss_hf = 0;
1139 : : }
|