ethdev: move representor parsing functions

The functions for representor devargs parsing were static
in the file rte_ethdev.c.
In order to reuse them in the file rte_class_eth.c,
they are moved to the files ethdev_private.c/.h.

A log is fixed by adding a missing line feed.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
This commit is contained in:
Thomas Monjalon 2018-10-22 15:15:28 +02:00 committed by Ferruh Yigit
parent cc0579f233
commit 7f07e7d794
3 changed files with 88 additions and 85 deletions

View File

@ -3,6 +3,7 @@
*/
#include "rte_ethdev.h"
#include "rte_ethdev_driver.h"
#include "ethdev_private.h"
uint16_t
@ -37,3 +38,84 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
return NULL;
}
int
rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
void *data)
{
char *str_start;
int state;
int result;
if (*str != '[')
/* Single element, not a list */
return callback(str, data);
/* Sanity check, then strip the brackets */
str_start = &str[strlen(str) - 1];
if (*str_start != ']') {
RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
return -EINVAL;
}
str++;
*str_start = '\0';
/* Process list elements */
state = 0;
while (1) {
if (state == 0) {
if (*str == '\0')
break;
if (*str != ',') {
str_start = str;
state = 1;
}
} else if (state == 1) {
if (*str == ',' || *str == '\0') {
if (str > str_start) {
/* Non-empty string fragment */
*str = '\0';
result = callback(str_start, data);
if (result < 0)
return result;
}
state = 0;
}
}
str++;
}
return 0;
}
static int
rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
const uint16_t max_list)
{
uint16_t lo, hi, val;
int result;
result = sscanf(str, "%hu-%hu", &lo, &hi);
if (result == 1) {
if (*len_list >= max_list)
return -ENOMEM;
list[(*len_list)++] = lo;
} else if (result == 2) {
if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
return -EINVAL;
for (val = lo; val <= hi; val++) {
if (*len_list >= max_list)
return -ENOMEM;
list[(*len_list)++] = val;
}
} else
return -EINVAL;
return 0;
}
int
rte_eth_devargs_parse_representor_ports(char *str, void *data)
{
struct rte_eth_devargs *eth_da = data;
return rte_eth_devargs_process_range(str, eth_da->representor_ports,
&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
}

View File

@ -25,6 +25,12 @@ struct rte_eth_dev *
eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
const void *data);
/* Parse devargs value for representor parameter. */
typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
void *data);
int rte_eth_devargs_parse_representor_ports(char *str, void *data);
#ifdef __cplusplus
}
#endif

View File

@ -4350,8 +4350,6 @@ rte_eth_switch_domain_free(uint16_t domain_id)
return 0;
}
typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
static int
rte_eth_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
{
@ -4416,89 +4414,6 @@ rte_eth_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
}
}
static int
rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
void *data)
{
char *str_start;
int state;
int result;
if (*str != '[')
/* Single element, not a list */
return callback(str, data);
/* Sanity check, then strip the brackets */
str_start = &str[strlen(str) - 1];
if (*str_start != ']') {
RTE_LOG(ERR, EAL, "(%s): List does not end with ']'", str);
return -EINVAL;
}
str++;
*str_start = '\0';
/* Process list elements */
state = 0;
while (1) {
if (state == 0) {
if (*str == '\0')
break;
if (*str != ',') {
str_start = str;
state = 1;
}
} else if (state == 1) {
if (*str == ',' || *str == '\0') {
if (str > str_start) {
/* Non-empty string fragment */
*str = '\0';
result = callback(str_start, data);
if (result < 0)
return result;
}
state = 0;
}
}
str++;
}
return 0;
}
static int
rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
const uint16_t max_list)
{
uint16_t lo, hi, val;
int result;
result = sscanf(str, "%hu-%hu", &lo, &hi);
if (result == 1) {
if (*len_list >= max_list)
return -ENOMEM;
list[(*len_list)++] = lo;
} else if (result == 2) {
if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
return -EINVAL;
for (val = lo; val <= hi; val++) {
if (*len_list >= max_list)
return -ENOMEM;
list[(*len_list)++] = val;
}
} else
return -EINVAL;
return 0;
}
static int
rte_eth_devargs_parse_representor_ports(char *str, void *data)
{
struct rte_eth_devargs *eth_da = data;
return rte_eth_devargs_process_range(str, eth_da->representor_ports,
&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
}
int __rte_experimental
rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
{