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
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(C) 2019 Marvell International Ltd.
*/
#include "otx2_ethdev.h"
int
otx2_nix_rss_tbl_init(struct otx2_eth_dev *dev,
uint8_t group, uint16_t *ind_tbl)
{
struct otx2_rss_info *rss = &dev->rss_info;
struct otx2_mbox *mbox = dev->mbox;
struct nix_aq_enq_req *req;
int rc, idx;
for (idx = 0; idx < rss->rss_size; idx++) {
req = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
if (!req) {
/* The shared memory buffer can be full.
* Flush it and retry
*/
otx2_mbox_msg_send(mbox, 0);
rc = otx2_mbox_wait_for_rsp(mbox, 0);
if (rc < 0)
return rc;
req = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
if (!req)
return -ENOMEM;
}
req->rss.rq = ind_tbl[idx];
/* Fill AQ info */
req->qidx = (group * rss->rss_size) + idx;
req->ctype = NIX_AQ_CTYPE_RSS;
req->op = NIX_AQ_INSTOP_INIT;
}
otx2_mbox_msg_send(mbox, 0);
rc = otx2_mbox_wait_for_rsp(mbox, 0);
if (rc < 0)
return rc;
return 0;
}
int
otx2_nix_dev_reta_update(struct rte_eth_dev *eth_dev,
struct rte_eth_rss_reta_entry64 *reta_conf,
uint16_t reta_size)
{
struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
struct otx2_rss_info *rss = &dev->rss_info;
int rc, i, j;
int idx = 0;
rc = -EINVAL;
if (reta_size != dev->rss_info.rss_size) {
otx2_err("Size of hash lookup table configured "
"(%d) doesn't match the number hardware can supported "
"(%d)", reta_size, dev->rss_info.rss_size);
goto fail;
}
/* Copy RETA table */
for (i = 0; i < (dev->rss_info.rss_size / RTE_RETA_GROUP_SIZE); i++) {
for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
if ((reta_conf[i].mask >> j) & 0x01)
rss->ind_tbl[idx] = reta_conf[i].reta[j];
idx++;
}
}
return otx2_nix_rss_tbl_init(dev, 0, dev->rss_info.ind_tbl);
fail:
return rc;
}
int
otx2_nix_dev_reta_query(struct rte_eth_dev *eth_dev,
struct rte_eth_rss_reta_entry64 *reta_conf,
uint16_t reta_size)
{
struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
struct otx2_rss_info *rss = &dev->rss_info;
int rc, i, j;
rc = -EINVAL;
if (reta_size != dev->rss_info.rss_size) {
otx2_err("Size of hash lookup table configured "
"(%d) doesn't match the number hardware can supported "
"(%d)", reta_size, dev->rss_info.rss_size);
goto fail;
}
/* Copy RETA table */
for (i = 0; i < (dev->rss_info.rss_size / RTE_RETA_GROUP_SIZE); i++) {
for (j = 0; j < RTE_RETA_GROUP_SIZE; j++)
if ((reta_conf[i].mask >> j) & 0x01)
reta_conf[i].reta[j] = rss->ind_tbl[j];
}
return 0;
fail:
return rc;
}
void
otx2_nix_rss_set_key(struct otx2_eth_dev *dev, uint8_t *key,
uint32_t key_len)
{
const uint8_t default_key[NIX_HASH_KEY_SIZE] = {
0xFE, 0xED, 0x0B, 0xAD, 0xFE, 0xED, 0x0B, 0xAD,
0xFE, 0xED, 0x0B, 0xAD, 0xFE, 0xED, 0x0B, 0xAD,
0xFE, 0xED, 0x0B, 0xAD, 0xFE, 0xED, 0x0B, 0xAD,
0xFE, 0xED, 0x0B, 0xAD, 0xFE, 0xED, 0x0B, 0xAD,
0xFE, 0xED, 0x0B, 0xAD, 0xFE, 0xED, 0x0B, 0xAD,
0xFE, 0xED, 0x0B, 0xAD, 0xFE, 0xED, 0x0B, 0xAD
};
struct otx2_rss_info *rss = &dev->rss_info;
uint64_t *keyptr;
uint64_t val;
uint32_t idx;
if (key == NULL || key == 0) {
keyptr = (uint64_t *)(uintptr_t)default_key;
key_len = NIX_HASH_KEY_SIZE;
memset(rss->key, 0, key_len);
} else {
memcpy(rss->key, key, key_len);
keyptr = (uint64_t *)rss->key;
}
for (idx = 0; idx < (key_len >> 3); idx++) {
val = rte_cpu_to_be_64(*keyptr);
otx2_write64(val, dev->base + NIX_LF_RX_SECRETX(idx));
keyptr++;
}
}
static void
rss_get_key(struct otx2_eth_dev *dev, uint8_t *key)
{
uint64_t *keyptr = (uint64_t *)key;
uint64_t val;
int idx;
for (idx = 0; idx < (NIX_HASH_KEY_SIZE >> 3); idx++) {
val = otx2_read64(dev->base + NIX_LF_RX_SECRETX(idx));
*keyptr = rte_be_to_cpu_64(val);
keyptr++;
}
}
#define RSS_IPV4_ENABLE ( \
ETH_RSS_IPV4 | \
ETH_RSS_FRAG_IPV4 | \
ETH_RSS_NONFRAG_IPV4_UDP | \
ETH_RSS_NONFRAG_IPV4_TCP | \
ETH_RSS_NONFRAG_IPV4_SCTP)
#define RSS_IPV6_ENABLE ( \
ETH_RSS_IPV6 | \
ETH_RSS_FRAG_IPV6 | \
ETH_RSS_NONFRAG_IPV6_UDP | \
ETH_RSS_NONFRAG_IPV6_TCP | \
ETH_RSS_NONFRAG_IPV6_SCTP)
#define RSS_IPV6_EX_ENABLE ( \
ETH_RSS_IPV6_EX | \
ETH_RSS_IPV6_TCP_EX | \
ETH_RSS_IPV6_UDP_EX)
#define RSS_MAX_LEVELS 3
#define RSS_IPV4_INDEX 0
#define RSS_IPV6_INDEX 1
#define RSS_TCP_INDEX 2
#define RSS_UDP_INDEX 3
#define RSS_SCTP_INDEX 4
#define RSS_DMAC_INDEX 5
uint32_t
otx2_rss_ethdev_to_nix(struct otx2_eth_dev *dev, uint64_t ethdev_rss,
uint8_t rss_level)
{
uint32_t flow_key_type[RSS_MAX_LEVELS][6] = {
{
FLOW_KEY_TYPE_IPV4, FLOW_KEY_TYPE_IPV6,
FLOW_KEY_TYPE_TCP, FLOW_KEY_TYPE_UDP,
FLOW_KEY_TYPE_SCTP, FLOW_KEY_TYPE_ETH_DMAC
},
{
FLOW_KEY_TYPE_INNR_IPV4, FLOW_KEY_TYPE_INNR_IPV6,
FLOW_KEY_TYPE_INNR_TCP, FLOW_KEY_TYPE_INNR_UDP,
FLOW_KEY_TYPE_INNR_SCTP, FLOW_KEY_TYPE_INNR_ETH_DMAC
},
{
FLOW_KEY_TYPE_IPV4 | FLOW_KEY_TYPE_INNR_IPV4,
FLOW_KEY_TYPE_IPV6 | FLOW_KEY_TYPE_INNR_IPV6,
FLOW_KEY_TYPE_TCP | FLOW_KEY_TYPE_INNR_TCP,
FLOW_KEY_TYPE_UDP | FLOW_KEY_TYPE_INNR_UDP,
FLOW_KEY_TYPE_SCTP | FLOW_KEY_TYPE_INNR_SCTP,
FLOW_KEY_TYPE_ETH_DMAC | FLOW_KEY_TYPE_INNR_ETH_DMAC
}
};
uint32_t flowkey_cfg = 0;
dev->rss_info.nix_rss = ethdev_rss;
if (ethdev_rss & ETH_RSS_L2_PAYLOAD &&
dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_LEN_90B) {
flowkey_cfg |= FLOW_KEY_TYPE_CH_LEN_90B;
}
if (ethdev_rss & ETH_RSS_L3_SRC_ONLY)
flowkey_cfg |= FLOW_KEY_TYPE_L3_SRC;
if (ethdev_rss & ETH_RSS_L3_DST_ONLY)
flowkey_cfg |= FLOW_KEY_TYPE_L3_DST;
if (ethdev_rss & ETH_RSS_L4_SRC_ONLY)
flowkey_cfg |= FLOW_KEY_TYPE_L4_SRC;
if (ethdev_rss & ETH_RSS_L4_DST_ONLY)
flowkey_cfg |= FLOW_KEY_TYPE_L4_DST;
if (ethdev_rss & RSS_IPV4_ENABLE)
flowkey_cfg |= flow_key_type[rss_level][RSS_IPV4_INDEX];
if (ethdev_rss & RSS_IPV6_ENABLE)
flowkey_cfg |= flow_key_type[rss_level][RSS_IPV6_INDEX];
if (ethdev_rss & ETH_RSS_TCP)
flowkey_cfg |= flow_key_type[rss_level][RSS_TCP_INDEX];
if (ethdev_rss & ETH_RSS_UDP)
flowkey_cfg |= flow_key_type[rss_level][RSS_UDP_INDEX];
if (ethdev_rss & ETH_RSS_SCTP)
flowkey_cfg |= flow_key_type[rss_level][RSS_SCTP_INDEX];
if (ethdev_rss & ETH_RSS_L2_PAYLOAD)
flowkey_cfg |= flow_key_type[rss_level][RSS_DMAC_INDEX];
if (ethdev_rss & RSS_IPV6_EX_ENABLE)
flowkey_cfg |= FLOW_KEY_TYPE_IPV6_EXT;
if (ethdev_rss & ETH_RSS_PORT)
flowkey_cfg |= FLOW_KEY_TYPE_PORT;
if (ethdev_rss & ETH_RSS_NVGRE)
flowkey_cfg |= FLOW_KEY_TYPE_NVGRE;
if (ethdev_rss & ETH_RSS_VXLAN)
flowkey_cfg |= FLOW_KEY_TYPE_VXLAN;
if (ethdev_rss & ETH_RSS_GENEVE)
flowkey_cfg |= FLOW_KEY_TYPE_GENEVE;
if (ethdev_rss & ETH_RSS_GTPU)
flowkey_cfg |= FLOW_KEY_TYPE_GTPU;
return flowkey_cfg;
}
int
otx2_rss_set_hf(struct otx2_eth_dev *dev, uint32_t flowkey_cfg,
uint8_t *alg_idx, uint8_t group, int mcam_index)
{
struct nix_rss_flowkey_cfg_rsp *rss_rsp;
struct otx2_mbox *mbox = dev->mbox;
struct nix_rss_flowkey_cfg *cfg;
int rc;
rc = -EINVAL;
dev->rss_info.flowkey_cfg = flowkey_cfg;
cfg = otx2_mbox_alloc_msg_nix_rss_flowkey_cfg(mbox);
cfg->flowkey_cfg = flowkey_cfg;
cfg->mcam_index = mcam_index; /* -1 indicates default group */
cfg->group = group; /* 0 is default group */
rc = otx2_mbox_process_msg(mbox, (void *)&rss_rsp);
if (rc)
return rc;
if (alg_idx)
*alg_idx = rss_rsp->alg_idx;
return rc;
}
int
otx2_nix_rss_hash_update(struct rte_eth_dev *eth_dev,
struct rte_eth_rss_conf *rss_conf)
{
struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
uint32_t flowkey_cfg;
uint8_t alg_idx;
int rc;
rc = -EINVAL;
if (rss_conf->rss_key && rss_conf->rss_key_len != NIX_HASH_KEY_SIZE) {
otx2_err("Hash key size mismatch %d vs %d",
rss_conf->rss_key_len, NIX_HASH_KEY_SIZE);
goto fail;
}
if (rss_conf->rss_key)
otx2_nix_rss_set_key(dev, rss_conf->rss_key,
(uint32_t)rss_conf->rss_key_len);
flowkey_cfg = otx2_rss_ethdev_to_nix(dev, rss_conf->rss_hf, 0);
rc = otx2_rss_set_hf(dev, flowkey_cfg, &alg_idx,
NIX_DEFAULT_RSS_CTX_GROUP,
NIX_DEFAULT_RSS_MCAM_IDX);
if (rc) {
otx2_err("Failed to set RSS hash function rc=%d", rc);
return rc;
}
dev->rss_info.alg_idx = alg_idx;
fail:
return rc;
}
int
otx2_nix_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
struct rte_eth_rss_conf *rss_conf)
{
struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
if (rss_conf->rss_key)
rss_get_key(dev, rss_conf->rss_key);
rss_conf->rss_key_len = NIX_HASH_KEY_SIZE;
rss_conf->rss_hf = dev->rss_info.nix_rss;
return 0;
}
int
otx2_nix_rss_config(struct rte_eth_dev *eth_dev)
{
struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
uint32_t idx, qcnt = eth_dev->data->nb_rx_queues;
uint32_t flowkey_cfg;
uint64_t rss_hf;
uint8_t alg_idx;
int rc;
/* Skip further configuration if selected mode is not RSS */
if (eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS || !qcnt)
return 0;
/* Update default RSS key and cfg */
otx2_nix_rss_set_key(dev, NULL, 0);
/* Update default RSS RETA */
for (idx = 0; idx < dev->rss_info.rss_size; idx++)
dev->rss_info.ind_tbl[idx] = idx % qcnt;
/* Init RSS table context */
rc = otx2_nix_rss_tbl_init(dev, 0, dev->rss_info.ind_tbl);
if (rc) {
otx2_err("Failed to init RSS table rc=%d", rc);
return rc;
}
rss_hf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
flowkey_cfg = otx2_rss_ethdev_to_nix(dev, rss_hf, 0);
rc = otx2_rss_set_hf(dev, flowkey_cfg, &alg_idx,
NIX_DEFAULT_RSS_CTX_GROUP,
NIX_DEFAULT_RSS_MCAM_IDX);
if (rc) {
otx2_err("Failed to set RSS hash function rc=%d", rc);
return rc;
}
dev->rss_info.alg_idx = alg_idx;
return 0;
}
|