1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Gaƫtan Rivet
5 #include "rte_ethdev.h"
6 #include "rte_ethdev_driver.h"
7 #include "ethdev_private.h"
10 eth_dev_to_id(const struct rte_eth_dev *dev)
13 return RTE_MAX_ETHPORTS;
14 return dev - rte_eth_devices;
18 eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
21 struct rte_eth_dev *edev;
24 /* Avoid Undefined Behaviour */
26 (start < &rte_eth_devices[0] ||
27 start > &rte_eth_devices[RTE_MAX_ETHPORTS]))
30 idx = eth_dev_to_id(start) + 1;
33 for (; idx < RTE_MAX_ETHPORTS; idx++) {
34 edev = &rte_eth_devices[idx];
35 if (cmp(edev, data) == 0)
42 rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
50 /* Single element, not a list */
51 return callback(str, data);
53 /* Sanity check, then strip the brackets */
54 str_start = &str[strlen(str) - 1];
55 if (*str_start != ']') {
56 RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
62 /* Process list elements */
72 } else if (state == 1) {
73 if (*str == ',' || *str == '\0') {
74 if (str > str_start) {
75 /* Non-empty string fragment */
77 result = callback(str_start, data);
90 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
91 const uint16_t max_list)
96 result = sscanf(str, "%hu-%hu", &lo, &hi);
98 if (*len_list >= max_list)
100 list[(*len_list)++] = lo;
101 } else if (result == 2) {
102 if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
104 for (val = lo; val <= hi; val++) {
105 if (*len_list >= max_list)
107 list[(*len_list)++] = val;
115 rte_eth_devargs_parse_representor_ports(char *str, void *data)
117 struct rte_eth_devargs *eth_da = data;
119 return rte_eth_devargs_process_range(str, eth_da->representor_ports,
120 ð_da->nb_representor_ports, RTE_MAX_ETHPORTS);