1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Gaƫtan Rivet
5 #include "rte_ethdev.h"
6 #include "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)
41 /* Put new value into list. */
43 rte_eth_devargs_enlist(uint16_t *list, uint16_t *len_list,
44 const uint16_t max_list, uint16_t val)
48 for (i = 0; i < *len_list; i++) {
52 if (*len_list >= max_list)
54 list[(*len_list)++] = val;
58 /* Parse and enlist a range expression of "min-max" or a single value. */
60 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
61 const uint16_t max_list)
67 result = sscanf(str, "%hu%n-%hu%n", &lo, &n, &hi, &n);
69 if (rte_eth_devargs_enlist(list, len_list, max_list, lo) != 0)
71 } else if (result == 2) {
74 for (val = lo; val <= hi; val++) {
75 if (rte_eth_devargs_enlist(list, len_list, max_list,
85 * Parse list of values separated by ",".
86 * Each value could be a range [min-max] or single number.
89 * [1,2,3] - single list
90 * [1,3-5,7,9-11] - list with singles and ranges
93 rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
94 const uint16_t max_list)
101 pos = rte_eth_devargs_process_range(pos, list, len_list,
105 if (*pos != ',') /* end of list */
109 if (*str == '[' && *pos != ']')
117 * Parse representor ports from a single value or lists.
119 * Representor format:
120 * #: range or single number of VF representor - legacy
121 * [[c#]pf#]vf#: VF port representor/s
122 * [[c#]pf#]sf#: SF port representor/s
123 * [c#]pf#: PF port representor/s
127 * [1,2,3] - single list
128 * [1,3-5,7,9-11] - list with singles and ranges
131 rte_eth_devargs_parse_representor_ports(char *str, void *data)
133 struct rte_eth_devargs *eth_da = data;
137 str = rte_eth_devargs_process_list(str, eth_da->mh_controllers,
138 ð_da->nb_mh_controllers,
139 RTE_DIM(eth_da->mh_controllers));
143 if (str[0] == 'p' && str[1] == 'f') {
144 eth_da->type = RTE_ETH_REPRESENTOR_PF;
146 str = rte_eth_devargs_process_list(str, eth_da->ports,
147 ð_da->nb_ports, RTE_DIM(eth_da->ports));
148 if (str == NULL || str[0] == '\0')
150 } else if (eth_da->nb_mh_controllers > 0) {
151 /* 'c' must followed by 'pf'. */
155 if (str[0] == 'v' && str[1] == 'f') {
156 eth_da->type = RTE_ETH_REPRESENTOR_VF;
158 } else if (str[0] == 's' && str[1] == 'f') {
159 eth_da->type = RTE_ETH_REPRESENTOR_SF;
162 /* 'pf' must followed by 'vf' or 'sf'. */
163 if (eth_da->type == RTE_ETH_REPRESENTOR_PF) {
167 eth_da->type = RTE_ETH_REPRESENTOR_VF;
169 str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
170 ð_da->nb_representor_ports,
171 RTE_DIM(eth_da->representor_ports));
174 RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
175 return str == NULL ? -1 : 0;