1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Marvell International Ltd.
3 * Copyright(c) 2017 Semihalf.
11 #include <rte_common.h>
12 #include <rte_cfgfile.h>
14 #include <rte_lcore.h>
15 #include <rte_malloc.h>
16 #include <rte_string_fns.h>
20 /* Parsing tokens. Defined conveniently, so that any correction is easy. */
21 #define MRVL_TOK_DEFAULT "default"
22 #define MRVL_TOK_DSA_MODE "dsa_mode"
23 #define MRVL_TOK_START_HDR "start_hdr"
24 #define MRVL_TOK_START_HDR_NONE "none"
25 #define MRVL_TOK_START_HDR_DSA "dsa"
26 #define MRVL_TOK_START_HDR_CUSTOM "custom"
27 #define MRVL_TOK_START_HDR_EXT_DSA "ext_dsa"
28 #define MRVL_TOK_DEFAULT_TC "default_tc"
29 #define MRVL_TOK_DSCP "dscp"
30 #define MRVL_TOK_MAPPING_PRIORITY "mapping_priority"
31 #define MRVL_TOK_IP "ip"
32 #define MRVL_TOK_IP_VLAN "ip/vlan"
33 #define MRVL_TOK_PCP "pcp"
34 #define MRVL_TOK_PORT "port"
35 #define MRVL_TOK_RXQ "rxq"
36 #define MRVL_TOK_TC "tc"
37 #define MRVL_TOK_TXQ "txq"
38 #define MRVL_TOK_VLAN "vlan"
39 #define MRVL_TOK_VLAN_IP "vlan/ip"
40 #define MRVL_TOK_PARSER_UDF "parser udf"
42 /* egress specific configuration tokens */
43 #define MRVL_TOK_BURST_SIZE "burst_size"
44 #define MRVL_TOK_RATE_LIMIT "rate_limit"
45 #define MRVL_TOK_RATE_LIMIT_ENABLE "rate_limit_enable"
46 #define MRVL_TOK_SCHED_MODE "sched_mode"
47 #define MRVL_TOK_SCHED_MODE_SP "sp"
48 #define MRVL_TOK_SCHED_MODE_WRR "wrr"
49 #define MRVL_TOK_WRR_WEIGHT "wrr_weight"
51 /* policer specific configuration tokens */
52 #define MRVL_TOK_PLCR "policer"
53 #define MRVL_TOK_PLCR_DEFAULT "default_policer"
54 #define MRVL_TOK_PLCR_UNIT "token_unit"
55 #define MRVL_TOK_PLCR_UNIT_BYTES "bytes"
56 #define MRVL_TOK_PLCR_UNIT_PACKETS "packets"
57 #define MRVL_TOK_PLCR_COLOR "color_mode"
58 #define MRVL_TOK_PLCR_COLOR_BLIND "blind"
59 #define MRVL_TOK_PLCR_COLOR_AWARE "aware"
60 #define MRVL_TOK_PLCR_CIR "cir"
61 #define MRVL_TOK_PLCR_CBS "cbs"
62 #define MRVL_TOK_PLCR_EBS "ebs"
63 #define MRVL_TOK_PLCR_DEFAULT_COLOR "default_color"
64 #define MRVL_TOK_PLCR_DEFAULT_COLOR_GREEN "green"
65 #define MRVL_TOK_PLCR_DEFAULT_COLOR_YELLOW "yellow"
66 #define MRVL_TOK_PLCR_DEFAULT_COLOR_RED "red"
68 /* parser udf specific configuration tokens */
69 #define MRVL_TOK_PARSER_UDF_PROTO "proto"
70 #define MRVL_TOK_PARSER_UDF_FIELD "field"
71 #define MRVL_TOK_PARSER_UDF_KEY "key"
72 #define MRVL_TOK_PARSER_UDF_MASK "mask"
73 #define MRVL_TOK_PARSER_UDF_OFFSET "offset"
74 #define MRVL_TOK_PARSER_UDF_PROTO_ETH "eth"
75 #define MRVL_TOK_PARSER_UDF_FIELD_ETH_TYPE "type"
76 #define MRVL_TOK_PARSER_UDF_PROTO_UDP "udp"
77 #define MRVL_TOK_PARSER_UDF_FIELD_UDP_DPORT "dport"
79 /* parser forward bad frames tokens */
80 #define MRVL_TOK_FWD_BAD_FRAMES "forward_bad_frames"
82 /** Number of tokens in range a-b = 2. */
83 #define MAX_RNG_TOKENS 2
85 /** Maximum possible value of PCP. */
88 /** Maximum possible value of DSCP. */
91 /** Global configuration. */
92 struct mrvl_cfg *mrvl_cfg;
95 * Read out-queue configuration from file.
97 * @param file Path to the configuration file.
98 * @param port Port number.
99 * @param outq Out queue number.
100 * @param cfg Pointer to the Marvell configuration structure.
101 * @returns 0 in case of success, negative value otherwise.
104 get_outq_cfg(struct rte_cfgfile *file, int port, int outq,
105 struct mrvl_cfg *cfg)
111 snprintf(sec_name, sizeof(sec_name), "%s %d %s %d",
112 MRVL_TOK_PORT, port, MRVL_TOK_TXQ, outq);
114 /* Skip non-existing */
115 if (rte_cfgfile_num_sections(file, sec_name, strlen(sec_name)) <= 0)
118 /* Read scheduling mode */
119 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_SCHED_MODE);
121 if (!strncmp(entry, MRVL_TOK_SCHED_MODE_SP,
122 strlen(MRVL_TOK_SCHED_MODE_SP))) {
123 cfg->port[port].outq[outq].sched_mode =
125 } else if (!strncmp(entry, MRVL_TOK_SCHED_MODE_WRR,
126 strlen(MRVL_TOK_SCHED_MODE_WRR))) {
127 cfg->port[port].outq[outq].sched_mode =
128 PP2_PPIO_SCHED_M_WRR;
130 MRVL_LOG(ERR, "Unknown token: %s", entry);
135 /* Read wrr weight */
136 if (cfg->port[port].outq[outq].sched_mode == PP2_PPIO_SCHED_M_WRR) {
137 entry = rte_cfgfile_get_entry(file, sec_name,
138 MRVL_TOK_WRR_WEIGHT);
140 if (get_val_securely(entry, &val) < 0)
142 cfg->port[port].outq[outq].weight = val;
147 * There's no point in setting rate limiting for specific outq as
148 * global port rate limiting has priority.
150 if (cfg->port[port].rate_limit_enable) {
151 MRVL_LOG(WARNING, "Port %d rate limiting already enabled",
156 entry = rte_cfgfile_get_entry(file, sec_name,
157 MRVL_TOK_RATE_LIMIT_ENABLE);
159 if (get_val_securely(entry, &val) < 0)
161 cfg->port[port].outq[outq].rate_limit_enable = val;
164 if (!cfg->port[port].outq[outq].rate_limit_enable)
167 /* Read CBS (in kB) */
168 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_BURST_SIZE);
170 if (get_val_securely(entry, &val) < 0)
172 cfg->port[port].outq[outq].rate_limit_params.cbs = val;
175 /* Read CIR (in kbps) */
176 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_RATE_LIMIT);
178 if (get_val_securely(entry, &val) < 0)
180 cfg->port[port].outq[outq].rate_limit_params.cir = val;
187 * Gets multiple-entry values and places them in table.
189 * Entry can be anything, e.g. "1 2-3 5 6 7-9". This needs to be converted to
190 * table entries, respectively: {1, 2, 3, 5, 6, 7, 8, 9}.
191 * As all result table's elements are always 1-byte long, we
192 * won't overcomplicate the function, but we'll keep API generic,
193 * check if someone hasn't changed element size and make it simple
194 * to extend to other sizes.
196 * This function is purely utilitary, it does not print any error, only returns
197 * different error numbers.
199 * @param entry[in] Values string to parse.
200 * @param tab[out] Results table.
201 * @param elem_sz[in] Element size (in bytes).
202 * @param max_elems[in] Number of results table elements available.
203 * @param max val[in] Maximum value allowed.
204 * @returns Number of correctly parsed elements in case of success.
205 * @retval -1 Wrong element size.
206 * @retval -2 More tokens than result table allows.
207 * @retval -3 Wrong range syntax.
208 * @retval -4 Wrong range values.
209 * @retval -5 Maximum value exceeded.
212 get_entry_values(const char *entry, uint8_t *tab,
213 size_t elem_sz, uint8_t max_elems, uint8_t max_val)
215 /* There should not be more tokens than max elements.
216 * Add 1 for error trap.
218 char *tokens[max_elems + 1];
220 /* Begin, End + error trap = 3. */
221 char *rng_tokens[MAX_RNG_TOKENS + 1];
224 int nb_tokens, nb_rng_tokens;
228 char entry_cpy[CFG_VALUE_LEN];
233 /* Copy the entry to safely use rte_strsplit(). */
234 strlcpy(entry_cpy, entry, RTE_DIM(entry_cpy));
237 * If there are more tokens than array size, rte_strsplit will
238 * not return error, just array size.
240 nb_tokens = rte_strsplit(entry_cpy, strlen(entry_cpy),
241 tokens, max_elems + 1, ' ');
243 /* Quick check, will be refined later. */
244 if (nb_tokens > max_elems)
247 for (i = 0; i < nb_tokens; ++i) {
248 if (strchr(tokens[i], '-') != NULL) {
250 * Split to begin and end tokens.
251 * We want to catch error cases too, thus we leave
252 * option for number of tokens to be more than 2.
254 nb_rng_tokens = rte_strsplit(tokens[i],
255 strlen(tokens[i]), rng_tokens,
256 RTE_DIM(rng_tokens), '-');
257 if (nb_rng_tokens != 2)
260 /* Range and sanity checks. */
261 if (get_val_securely(rng_tokens[0], &token_val) < 0)
263 beg = (char)token_val;
264 if (get_val_securely(rng_tokens[1], &token_val) < 0)
266 end = (char)token_val;
267 if (beg < 0 || beg > UCHAR_MAX ||
268 end < 0 || end > UCHAR_MAX || end < beg)
271 for (val = beg; val <= end; ++val) {
276 tab = RTE_PTR_ADD(tab, elem_sz);
278 if (values >= max_elems)
283 if (get_val_securely(tokens[i], &token_val) < 0)
285 val = (char)token_val;
290 tab = RTE_PTR_ADD(tab, elem_sz);
292 if (values >= max_elems)
301 * Parse Traffic Class'es mapping configuration.
303 * @param file Config file handle.
304 * @param port Which port to look for.
305 * @param tc Which Traffic Class to look for.
306 * @param cfg[out] Parsing results.
307 * @returns 0 in case of success, negative value otherwise.
310 parse_tc_cfg(struct rte_cfgfile *file, int port, int tc,
311 struct mrvl_cfg *cfg)
317 snprintf(sec_name, sizeof(sec_name), "%s %d %s %d",
318 MRVL_TOK_PORT, port, MRVL_TOK_TC, tc);
320 /* Skip non-existing */
321 if (rte_cfgfile_num_sections(file, sec_name, strlen(sec_name)) <= 0)
324 cfg->port[port].use_qos_global_defaults = 0;
325 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_RXQ);
327 n = get_entry_values(entry,
328 cfg->port[port].tc[tc].inq,
329 sizeof(cfg->port[port].tc[tc].inq[0]),
330 RTE_DIM(cfg->port[port].tc[tc].inq),
333 MRVL_LOG(ERR, "Error %d while parsing: %s",
337 cfg->port[port].tc[tc].inqs = n;
340 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_PCP);
342 n = get_entry_values(entry,
343 cfg->port[port].tc[tc].pcp,
344 sizeof(cfg->port[port].tc[tc].pcp[0]),
345 RTE_DIM(cfg->port[port].tc[tc].pcp),
348 MRVL_LOG(ERR, "Error %d while parsing: %s",
352 cfg->port[port].tc[tc].pcps = n;
355 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_DSCP);
357 n = get_entry_values(entry,
358 cfg->port[port].tc[tc].dscp,
359 sizeof(cfg->port[port].tc[tc].dscp[0]),
360 RTE_DIM(cfg->port[port].tc[tc].dscp),
363 MRVL_LOG(ERR, "Error %d while parsing: %s",
367 cfg->port[port].tc[tc].dscps = n;
370 if (!cfg->port[port].setup_policer)
373 entry = rte_cfgfile_get_entry(file, sec_name,
374 MRVL_TOK_PLCR_DEFAULT_COLOR);
376 if (!strncmp(entry, MRVL_TOK_PLCR_DEFAULT_COLOR_GREEN,
377 sizeof(MRVL_TOK_PLCR_DEFAULT_COLOR_GREEN))) {
378 cfg->port[port].tc[tc].color = PP2_PPIO_COLOR_GREEN;
379 } else if (!strncmp(entry, MRVL_TOK_PLCR_DEFAULT_COLOR_YELLOW,
380 sizeof(MRVL_TOK_PLCR_DEFAULT_COLOR_YELLOW))) {
381 cfg->port[port].tc[tc].color = PP2_PPIO_COLOR_YELLOW;
382 } else if (!strncmp(entry, MRVL_TOK_PLCR_DEFAULT_COLOR_RED,
383 sizeof(MRVL_TOK_PLCR_DEFAULT_COLOR_RED))) {
384 cfg->port[port].tc[tc].color = PP2_PPIO_COLOR_RED;
386 MRVL_LOG(ERR, "Error while parsing: %s", entry);
395 * Parse default port policer.
397 * @param file Config file handle.
398 * @param sec_name Section name with policer configuration
399 * @param port Port number.
400 * @param cfg[out] Parsing results.
401 * @returns 0 in case of success, negative value otherwise.
404 parse_policer(struct rte_cfgfile *file, int port, const char *sec_name,
405 struct mrvl_cfg *cfg)
410 /* Read policer token unit */
411 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_PLCR_UNIT);
413 if (!strncmp(entry, MRVL_TOK_PLCR_UNIT_BYTES,
414 sizeof(MRVL_TOK_PLCR_UNIT_BYTES))) {
415 cfg->port[port].policer_params.token_unit =
416 PP2_CLS_PLCR_BYTES_TOKEN_UNIT;
417 } else if (!strncmp(entry, MRVL_TOK_PLCR_UNIT_PACKETS,
418 sizeof(MRVL_TOK_PLCR_UNIT_PACKETS))) {
419 cfg->port[port].policer_params.token_unit =
420 PP2_CLS_PLCR_PACKETS_TOKEN_UNIT;
422 MRVL_LOG(ERR, "Unknown token: %s", entry);
427 /* Read policer color mode */
428 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_PLCR_COLOR);
430 if (!strncmp(entry, MRVL_TOK_PLCR_COLOR_BLIND,
431 sizeof(MRVL_TOK_PLCR_COLOR_BLIND))) {
432 cfg->port[port].policer_params.color_mode =
433 PP2_CLS_PLCR_COLOR_BLIND_MODE;
434 } else if (!strncmp(entry, MRVL_TOK_PLCR_COLOR_AWARE,
435 sizeof(MRVL_TOK_PLCR_COLOR_AWARE))) {
436 cfg->port[port].policer_params.color_mode =
437 PP2_CLS_PLCR_COLOR_AWARE_MODE;
439 MRVL_LOG(ERR, "Error in parsing: %s", entry);
444 /* Read policer cir */
445 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_PLCR_CIR);
447 if (get_val_securely(entry, &val) < 0)
449 cfg->port[port].policer_params.cir = val;
452 /* Read policer cbs */
453 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_PLCR_CBS);
455 if (get_val_securely(entry, &val) < 0)
457 cfg->port[port].policer_params.cbs = val;
460 /* Read policer ebs */
461 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_PLCR_EBS);
463 if (get_val_securely(entry, &val) < 0)
465 cfg->port[port].policer_params.ebs = val;
468 cfg->port[port].setup_policer = 1;
476 * @param file Config file handle.
477 * @param sec_name section name
478 * @param udf udf index
479 * @param cfg[out] Parsing results.
480 * @returns 0 in case of success, negative value otherwise.
483 parse_udf(struct rte_cfgfile *file, const char *sec_name, int udf,
484 struct mrvl_cfg *cfg)
486 struct pp2_parse_udf_params *udf_params;
487 const char *entry, *entry_field;
490 char malloc_name[32], tmp_arr[3];
491 /* field len in chars equal to '0x' + rest of data */
492 #define FIELD_LEN_IN_CHARS(field_size) (uint32_t)(2 + (field_size) * 2)
494 udf_params = &cfg->pp2_cfg.prs_udfs.udfs[udf];
496 /* Read 'proto' field */
497 entry = rte_cfgfile_get_entry(file, sec_name,
498 MRVL_TOK_PARSER_UDF_PROTO);
500 MRVL_LOG(ERR, "UDF[%d]: '%s' field must be set\n", udf,
501 MRVL_TOK_PARSER_UDF_PROTO);
505 /* Read 'field' field */
506 entry_field = rte_cfgfile_get_entry(file, sec_name,
507 MRVL_TOK_PARSER_UDF_FIELD);
509 MRVL_LOG(ERR, "UDF[%d]: '%s' field must be set\n", udf,
510 MRVL_TOK_PARSER_UDF_FIELD);
514 if (!strncmp(entry, MRVL_TOK_PARSER_UDF_PROTO_ETH,
515 sizeof(MRVL_TOK_PARSER_UDF_PROTO_ETH))) {
516 udf_params->match_proto = MV_NET_PROTO_ETH;
517 if (!strncmp(entry_field, MRVL_TOK_PARSER_UDF_FIELD_ETH_TYPE,
518 sizeof(MRVL_TOK_PARSER_UDF_FIELD_ETH_TYPE))) {
519 udf_params->match_field.eth = MV_NET_ETH_F_TYPE;
522 MRVL_LOG(ERR, "UDF[%d]: mismatch between '%s' proto "
523 "and '%s' field\n", udf,
524 MRVL_TOK_PARSER_UDF_PROTO_ETH,
528 } else if (!strncmp(entry, MRVL_TOK_PARSER_UDF_PROTO_UDP,
529 sizeof(MRVL_TOK_PARSER_UDF_PROTO_UDP))) {
530 udf_params->match_proto = MV_NET_PROTO_UDP;
531 if (!strncmp(entry_field, MRVL_TOK_PARSER_UDF_FIELD_UDP_DPORT,
532 sizeof(MRVL_TOK_PARSER_UDF_FIELD_UDP_DPORT))) {
533 udf_params->match_field.udp = MV_NET_UDP_F_DP;
536 MRVL_LOG(ERR, "UDF[%d]: mismatch between '%s' proto "
537 "and '%s' field\n", udf,
538 MRVL_TOK_PARSER_UDF_PROTO_UDP,
543 MRVL_LOG(ERR, "UDF[%d]: Unsupported '%s' proto\n", udf, entry);
547 snprintf(malloc_name, sizeof(malloc_name), "mrvl_udf_%d_key", udf);
548 udf_params->match_key = rte_zmalloc(malloc_name, field_size, 0);
549 if (udf_params->match_key == NULL) {
550 MRVL_LOG(ERR, "Cannot allocate udf %d key\n", udf);
553 snprintf(malloc_name, sizeof(malloc_name), "mrvl_udf_%d_mask", udf);
554 udf_params->match_mask = rte_zmalloc(malloc_name, field_size, 0);
555 if (udf_params->match_mask == NULL) {
556 MRVL_LOG(ERR, "Cannot allocate udf %d mask\n", udf);
560 /* Read 'key' field */
561 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_PARSER_UDF_KEY);
563 MRVL_LOG(ERR, "UDF[%d]: '%s' field must be set\n", udf,
564 MRVL_TOK_PARSER_UDF_KEY);
568 if (strncmp(entry, "0x", 2) != 0) {
569 MRVL_LOG(ERR, "UDF[%d]: '%s' field must start with '0x'\n",
570 udf, MRVL_TOK_PARSER_UDF_KEY);
574 if (strlen(entry) != FIELD_LEN_IN_CHARS(field_size)) {
575 MRVL_LOG(ERR, "UDF[%d]: '%s' field's len must be %d\n", udf,
576 MRVL_TOK_PARSER_UDF_KEY,
577 FIELD_LEN_IN_CHARS(field_size));
581 entry += 2; /* skip the '0x' */
582 for (i = 0; i < field_size; i++) {
583 strncpy(tmp_arr, entry, 2);
585 if (get_val_securely8(tmp_arr, 16,
586 &udf_params->match_key[i]) < 0) {
587 MRVL_LOG(ERR, "UDF[%d]: '%s' field's value is not in "
588 "hex format\n", udf, MRVL_TOK_PARSER_UDF_KEY);
594 /* Read 'mask' field */
595 entry = rte_cfgfile_get_entry(file, sec_name, MRVL_TOK_PARSER_UDF_MASK);
597 MRVL_LOG(ERR, "UDF[%d]: '%s' field must be set\n", udf,
598 MRVL_TOK_PARSER_UDF_MASK);
601 if (strncmp(entry, "0x", 2) != 0) {
602 MRVL_LOG(ERR, "UDF[%d]: '%s' field must start with '0x'\n",
603 udf, MRVL_TOK_PARSER_UDF_MASK);
607 if (strlen(entry) != FIELD_LEN_IN_CHARS(field_size)) {
608 MRVL_LOG(ERR, "UDF[%d]: '%s' field's len must be %d\n", udf,
609 MRVL_TOK_PARSER_UDF_MASK,
610 FIELD_LEN_IN_CHARS(field_size));
614 entry += 2; /* skip the '0x' */
615 for (i = 0; i < field_size; i++) {
616 strncpy(tmp_arr, entry, 2);
618 if (get_val_securely8(tmp_arr, 16,
619 &udf_params->match_mask[i]) < 0) {
620 MRVL_LOG(ERR, "UDF[%d]: '%s' field's value is not in "
621 "hex format\n", udf, MRVL_TOK_PARSER_UDF_MASK);
628 entry = rte_cfgfile_get_entry(file, sec_name,
629 MRVL_TOK_PARSER_UDF_OFFSET);
631 MRVL_LOG(ERR, "UDF[%d]: '%s' field must be set\n", udf,
632 MRVL_TOK_PARSER_UDF_OFFSET);
635 if (get_val_securely(entry, &val) < 0)
637 udf_params->offset = val;
643 * Parse configuration - rte_kvargs_process handler.
645 * Opens configuration file and parses its content.
648 * @param path Path to config file.
649 * @param extra_args Pointer to configuration structure.
650 * @returns 0 in case of success, exits otherwise.
653 mrvl_get_cfg(const char *key __rte_unused, const char *path, void *extra_args)
655 struct mrvl_cfg **cfg = extra_args;
656 struct rte_cfgfile *file = rte_cfgfile_load(path, 0);
663 MRVL_LOG(ERR, "Cannot load configuration %s\n", path);
667 /* Create configuration. This is never accessed on the fast path,
668 * so we can ignore socket.
670 *cfg = rte_zmalloc("mrvl_cfg", sizeof(struct mrvl_cfg), 0);
672 MRVL_LOG(ERR, "Cannot allocate configuration %s\n", path);
676 /* PP2 configuration */
677 n = rte_cfgfile_num_sections(file, MRVL_TOK_PARSER_UDF,
678 sizeof(MRVL_TOK_PARSER_UDF) - 1);
680 if (n && n > PP2_MAX_UDFS_SUPPORTED) {
681 MRVL_LOG(ERR, "found %d udf sections, but only %d are supported\n",
682 n, PP2_MAX_UDFS_SUPPORTED);
685 (*cfg)->pp2_cfg.prs_udfs.num_udfs = n;
686 for (i = 0; i < n; i++) {
687 snprintf(sec_name, sizeof(sec_name), "%s %d",
688 MRVL_TOK_PARSER_UDF, i);
690 /* udf sections must be sequential. */
691 if (rte_cfgfile_num_sections(file, sec_name,
692 strlen(sec_name)) <= 0) {
693 MRVL_LOG(ERR, "udf sections must be sequential (0 - %d)\n",
694 PP2_MAX_UDFS_SUPPORTED - 1);
698 ret = parse_udf(file, sec_name, i, *cfg);
700 MRVL_LOG(ERR, "Error in parsing %s!\n", sec_name);
705 /* PP2 Ports configuration */
706 n = rte_cfgfile_num_sections(file, MRVL_TOK_PORT,
707 sizeof(MRVL_TOK_PORT) - 1);
710 /* This is weird, but not bad. */
711 MRVL_LOG(WARNING, "Empty configuration file?");
715 /* Use the number of ports given as vdev parameters. */
716 for (n = 0; n < (PP2_NUM_ETH_PPIO * PP2_NUM_PKT_PROC); ++n) {
717 snprintf(sec_name, sizeof(sec_name), "%s %d %s",
718 MRVL_TOK_PORT, n, MRVL_TOK_DEFAULT);
720 /* Use global defaults, unless an override occurs */
721 (*cfg)->port[n].use_qos_global_defaults = 1;
723 /* Skip ports non-existing in configuration. */
724 if (rte_cfgfile_num_sections(file, sec_name,
725 strlen(sec_name)) <= 0) {
729 /* MRVL_TOK_START_HDR replaces MRVL_TOK_DSA_MODE parameter.
730 * MRVL_TOK_DSA_MODE will be supported for backward
733 entry = rte_cfgfile_get_entry(file, sec_name,
735 /* if start_hsr is missing, check if dsa_mode exist instead */
737 entry = rte_cfgfile_get_entry(file, sec_name,
740 if (!strncmp(entry, MRVL_TOK_START_HDR_NONE,
741 sizeof(MRVL_TOK_START_HDR_NONE)))
742 (*cfg)->port[n].eth_start_hdr =
744 else if (!strncmp(entry, MRVL_TOK_START_HDR_DSA,
745 sizeof(MRVL_TOK_START_HDR_DSA)))
746 (*cfg)->port[n].eth_start_hdr =
747 PP2_PPIO_HDR_ETH_DSA;
748 else if (!strncmp(entry, MRVL_TOK_START_HDR_CUSTOM,
749 sizeof(MRVL_TOK_START_HDR_CUSTOM)))
750 (*cfg)->port[n].eth_start_hdr =
751 PP2_PPIO_HDR_ETH_CUSTOM;
752 else if (!strncmp(entry, MRVL_TOK_START_HDR_EXT_DSA,
753 sizeof(MRVL_TOK_START_HDR_EXT_DSA))) {
754 (*cfg)->port[n].eth_start_hdr =
755 PP2_PPIO_HDR_ETH_EXT_DSA;
758 "Error in parsing %s value (%s)!\n",
759 MRVL_TOK_START_HDR, entry);
763 (*cfg)->port[n].eth_start_hdr = PP2_PPIO_HDR_ETH;
767 * Read per-port rate limiting. Setting that will
768 * disable per-queue rate limiting.
770 entry = rte_cfgfile_get_entry(file, sec_name,
771 MRVL_TOK_RATE_LIMIT_ENABLE);
773 if (get_val_securely(entry, &val) < 0)
775 (*cfg)->port[n].rate_limit_enable = val;
778 if ((*cfg)->port[n].rate_limit_enable) {
779 entry = rte_cfgfile_get_entry(file, sec_name,
780 MRVL_TOK_BURST_SIZE);
782 if (get_val_securely(entry, &val) < 0)
784 (*cfg)->port[n].rate_limit_params.cbs = val;
787 entry = rte_cfgfile_get_entry(file, sec_name,
788 MRVL_TOK_RATE_LIMIT);
790 if (get_val_securely(entry, &val) < 0)
792 (*cfg)->port[n].rate_limit_params.cir = val;
796 entry = rte_cfgfile_get_entry(file, sec_name,
797 MRVL_TOK_MAPPING_PRIORITY);
799 (*cfg)->port[n].use_qos_global_defaults = 0;
800 if (!strncmp(entry, MRVL_TOK_VLAN_IP,
801 sizeof(MRVL_TOK_VLAN_IP)))
802 (*cfg)->port[n].mapping_priority =
803 PP2_CLS_QOS_TBL_VLAN_IP_PRI;
804 else if (!strncmp(entry, MRVL_TOK_IP_VLAN,
805 sizeof(MRVL_TOK_IP_VLAN)))
806 (*cfg)->port[n].mapping_priority =
807 PP2_CLS_QOS_TBL_IP_VLAN_PRI;
808 else if (!strncmp(entry, MRVL_TOK_IP,
809 sizeof(MRVL_TOK_IP)))
810 (*cfg)->port[n].mapping_priority =
811 PP2_CLS_QOS_TBL_IP_PRI;
812 else if (!strncmp(entry, MRVL_TOK_VLAN,
813 sizeof(MRVL_TOK_VLAN))) {
814 (*cfg)->port[n].mapping_priority =
815 PP2_CLS_QOS_TBL_VLAN_PRI;
818 "Error in parsing %s value (%s)!\n",
819 MRVL_TOK_MAPPING_PRIORITY, entry);
823 (*cfg)->port[n].mapping_priority =
824 PP2_CLS_QOS_TBL_NONE;
827 /* Parse policer configuration (if any) */
828 entry = rte_cfgfile_get_entry(file, sec_name,
829 MRVL_TOK_PLCR_DEFAULT);
831 (*cfg)->port[n].use_qos_global_defaults = 0;
832 if (get_val_securely(entry, &val) < 0)
835 snprintf(sec_name, sizeof(sec_name), "%s %d",
837 ret = parse_policer(file, n, sec_name, *cfg);
842 for (i = 0; i < MRVL_PP2_RXQ_MAX; ++i) {
843 ret = get_outq_cfg(file, n, i, *cfg);
846 "Error %d parsing port %d outq %d!\n",
852 for (i = 0; i < MRVL_PP2_TC_MAX; ++i) {
853 ret = parse_tc_cfg(file, n, i, *cfg);
856 "Error %d parsing port %d tc %d!\n",
862 entry = rte_cfgfile_get_entry(file, sec_name,
863 MRVL_TOK_DEFAULT_TC);
865 if (get_val_securely(entry, &val) < 0 ||
868 (*cfg)->port[n].default_tc = (uint8_t)val;
870 if ((*cfg)->port[n].use_qos_global_defaults == 0) {
872 "Default Traffic Class required in "
873 "custom configuration!");
878 /* Parse forward bad frames option */
879 entry = rte_cfgfile_get_entry(file, sec_name,
880 MRVL_TOK_FWD_BAD_FRAMES);
882 if (get_val_securely(entry, &val) < 0) {
884 "Error in parsing %s value (%s)!\n",
885 MRVL_TOK_FWD_BAD_FRAMES, entry);
888 (*cfg)->port[n].forward_bad_frames = (uint8_t)val;
890 (*cfg)->port[n].forward_bad_frames = 0;
898 * Setup Traffic Class.
900 * Fill in TC parameters in single MUSDK TC config entry.
901 * @param param TC parameters entry.
902 * @param inqs Number of MUSDK in-queues in this TC.
903 * @param bpool Bpool for this TC.
904 * @param color Default color for this TC.
905 * @returns 0 in case of success, exits otherwise.
908 setup_tc(struct pp2_ppio_tc_params *param, uint8_t inqs,
909 struct pp2_bpool *bpool, enum pp2_ppio_color color)
911 struct pp2_ppio_inq_params *inq_params;
913 param->pkt_offset = MRVL_PKT_OFFS;
914 param->pools[0][0] = bpool;
915 param->pools[0][1] = dummy_pool[bpool->pp2_id];
916 param->default_color = color;
918 inq_params = rte_zmalloc_socket("inq_params",
919 inqs * sizeof(*inq_params),
924 param->num_in_qs = inqs;
926 /* Release old config if necessary. */
927 if (param->inqs_params)
928 rte_free(param->inqs_params);
930 param->inqs_params = inq_params;
936 * Setup ingress policer.
938 * @param priv Port's private data.
939 * @param params Pointer to the policer's configuration.
940 * @param plcr_id Policer id.
941 * @returns 0 in case of success, negative values otherwise.
944 setup_policer(struct mrvl_priv *priv, struct pp2_cls_plcr_params *params)
950 * At this point no other policers are used which means
951 * any policer can be picked up and used as a default one.
955 sprintf(match, "policer-%d:%d\n", priv->pp_id, 0);
956 params->match = match;
958 ret = pp2_cls_plcr_init(params, &priv->default_policer);
960 MRVL_LOG(ERR, "Failed to setup %s", match);
964 priv->ppio_params.inqs_params.plcr = priv->default_policer;
965 priv->used_plcrs = BIT(0);
971 * Configure RX Queues in a given port.
973 * Sets up RX queues, their Traffic Classes and DPDK rxq->(TC,inq) mapping.
975 * @param priv Port's private data
976 * @param portid DPDK port ID
977 * @param max_queues Maximum number of queues to configure.
978 * @returns 0 in case of success, negative value otherwise.
981 mrvl_configure_rxqs(struct mrvl_priv *priv, uint16_t portid,
986 if (mrvl_cfg == NULL ||
987 mrvl_cfg->port[portid].use_qos_global_defaults) {
989 * No port configuration, use default: 1 TC, no QoS,
990 * TC color set to green.
992 priv->ppio_params.inqs_params.num_tcs = 1;
993 setup_tc(&priv->ppio_params.inqs_params.tcs_params[0],
994 max_queues, priv->bpool, PP2_PPIO_COLOR_GREEN);
996 /* Direct mapping of queues i.e. 0->0, 1->1 etc. */
997 for (i = 0; i < max_queues; ++i) {
998 priv->rxq_map[i].tc = 0;
999 priv->rxq_map[i].inq = i;
1004 /* We need only a subset of configuration. */
1005 struct port_cfg *port_cfg = &mrvl_cfg->port[portid];
1007 priv->qos_tbl_params.type = port_cfg->mapping_priority;
1010 * We need to reverse mapping, from tc->pcp (better from usability
1011 * point of view) to pcp->tc (configurable in MUSDK).
1012 * First, set all map elements to "default".
1014 for (i = 0; i < RTE_DIM(priv->qos_tbl_params.pcp_cos_map); ++i)
1015 priv->qos_tbl_params.pcp_cos_map[i].tc = port_cfg->default_tc;
1017 /* Then, fill in all known values. */
1018 for (tc = 0; tc < RTE_DIM(port_cfg->tc); ++tc) {
1019 if (port_cfg->tc[tc].pcps > RTE_DIM(port_cfg->tc[0].pcp)) {
1020 /* Better safe than sorry. */
1022 "Too many PCPs configured in TC %zu!", tc);
1025 for (i = 0; i < port_cfg->tc[tc].pcps; ++i) {
1026 priv->qos_tbl_params.pcp_cos_map[
1027 port_cfg->tc[tc].pcp[i]].tc = tc;
1032 * The same logic goes with DSCP.
1033 * First, set all map elements to "default".
1035 for (i = 0; i < RTE_DIM(priv->qos_tbl_params.dscp_cos_map); ++i)
1036 priv->qos_tbl_params.dscp_cos_map[i].tc =
1037 port_cfg->default_tc;
1039 /* Fill in all known values. */
1040 for (tc = 0; tc < RTE_DIM(port_cfg->tc); ++tc) {
1041 if (port_cfg->tc[tc].dscps > RTE_DIM(port_cfg->tc[0].dscp)) {
1042 /* Better safe than sorry. */
1044 "Too many DSCPs configured in TC %zu!", tc);
1047 for (i = 0; i < port_cfg->tc[tc].dscps; ++i) {
1048 priv->qos_tbl_params.dscp_cos_map[
1049 port_cfg->tc[tc].dscp[i]].tc = tc;
1054 * Surprisingly, similar logic goes with queue mapping.
1055 * We need only to store qid->tc mapping,
1056 * to know TC when queue is read.
1058 for (i = 0; i < RTE_DIM(priv->rxq_map); ++i)
1059 priv->rxq_map[i].tc = MRVL_UNKNOWN_TC;
1061 /* Set up DPDKq->(TC,inq) mapping. */
1062 for (tc = 0; tc < RTE_DIM(port_cfg->tc); ++tc) {
1063 if (port_cfg->tc[tc].inqs > RTE_DIM(port_cfg->tc[0].inq)) {
1066 "Too many RX queues configured per TC %zu!",
1070 for (i = 0; i < port_cfg->tc[tc].inqs; ++i) {
1071 uint8_t idx = port_cfg->tc[tc].inq[i];
1073 if (idx > RTE_DIM(priv->rxq_map)) {
1074 MRVL_LOG(ERR, "Bad queue index %d!", idx);
1078 priv->rxq_map[idx].tc = tc;
1079 priv->rxq_map[idx].inq = i;
1084 * Set up TC configuration. TCs need to be sequenced: 0, 1, 2
1085 * with no gaps. Empty TC means end of processing.
1087 for (i = 0; i < MRVL_PP2_TC_MAX; ++i) {
1088 if (port_cfg->tc[i].inqs == 0)
1090 setup_tc(&priv->ppio_params.inqs_params.tcs_params[i],
1091 port_cfg->tc[i].inqs,
1092 priv->bpool, port_cfg->tc[i].color);
1095 priv->ppio_params.inqs_params.num_tcs = i;
1097 if (port_cfg->setup_policer)
1098 return setup_policer(priv, &port_cfg->policer_params);
1104 * Configure TX Queues in a given port.
1106 * Sets up TX queues egress scheduler and limiter.
1108 * @param priv Port's private data
1109 * @param portid DPDK port ID
1110 * @param max_queues Maximum number of queues to configure.
1111 * @returns 0 in case of success, negative value otherwise.
1114 mrvl_configure_txqs(struct mrvl_priv *priv, uint16_t portid,
1115 uint16_t max_queues)
1117 /* We need only a subset of configuration. */
1118 struct port_cfg *port_cfg = &mrvl_cfg->port[portid];
1121 if (mrvl_cfg == NULL)
1124 priv->ppio_params.rate_limit_enable = port_cfg->rate_limit_enable;
1125 if (port_cfg->rate_limit_enable)
1126 priv->ppio_params.rate_limit_params =
1127 port_cfg->rate_limit_params;
1129 for (i = 0; i < max_queues; i++) {
1130 struct pp2_ppio_outq_params *params =
1131 &priv->ppio_params.outqs_params.outqs_params[i];
1133 params->sched_mode = port_cfg->outq[i].sched_mode;
1134 params->weight = port_cfg->outq[i].weight;
1135 params->rate_limit_enable = port_cfg->outq[i].rate_limit_enable;
1136 params->rate_limit_params = port_cfg->outq[i].rate_limit_params;
1143 * Start QoS mapping.
1145 * Finalize QoS table configuration and initialize it in SDK. It can be done
1146 * only after port is started, so we have a valid ppio reference.
1148 * @param priv Port's private (configuration) data.
1149 * @returns 0 in case of success, exits otherwise.
1152 mrvl_start_qos_mapping(struct mrvl_priv *priv)
1156 if (priv->qos_tbl_params.type == PP2_CLS_QOS_TBL_NONE)
1159 if (priv->ppio == NULL) {
1160 MRVL_LOG(ERR, "ppio must not be NULL here!");
1164 for (i = 0; i < RTE_DIM(priv->qos_tbl_params.pcp_cos_map); ++i)
1165 priv->qos_tbl_params.pcp_cos_map[i].ppio = priv->ppio;
1167 for (i = 0; i < RTE_DIM(priv->qos_tbl_params.dscp_cos_map); ++i)
1168 priv->qos_tbl_params.dscp_cos_map[i].ppio = priv->ppio;
1170 /* Initialize Classifier QoS table. */
1172 return pp2_cls_qos_tbl_init(&priv->qos_tbl_params, &priv->qos_tbl);