Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace some uses of struct rte_kvargs with api functions #96

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 61 additions & 67 deletions drivers/net/af_packet/rte_eth_af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
const char *name = rte_vdev_device_name(dev);
const unsigned int numa_node = dev->device.numa_node;
struct rte_eth_dev_data *data = NULL;
struct rte_kvargs_pair *pair = NULL;
const char *ifname = NULL;
struct ifreq ifr;
size_t ifnamelen;
unsigned k_idx;
Expand All @@ -731,12 +731,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
int fanout_arg;
#endif

for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
pair = &kvlist->pairs[k_idx];
if (strstr(pair->key, ETH_AF_PACKET_IFACE_ARG) != NULL)
break;
}
if (pair == NULL) {
ifname = rte_kvargs_get(kvlist, ETH_AF_PACKET_IFACE_ARG);
if (ifname == NULL) {
PMD_LOG(ERR,
"%s: no interface specified for AF_PACKET ethdev",
name);
Expand Down Expand Up @@ -779,21 +775,21 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
req->tp_frame_size = framesize;
req->tp_frame_nr = framecnt;

ifnamelen = strlen(pair->value);
ifnamelen = strlen(ifname);
if (ifnamelen < sizeof(ifr.ifr_name)) {
memcpy(ifr.ifr_name, pair->value, ifnamelen);
memcpy(ifr.ifr_name, ifname, ifnamelen);
ifr.ifr_name[ifnamelen] = '\0';
} else {
PMD_LOG(ERR,
"%s: I/F name too long (%s)",
name, pair->value);
name, ifname);
goto free_internals;
}
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFINDEX)", name);
goto free_internals;
}
(*internals)->if_name = strdup(pair->value);
(*internals)->if_name = strdup(ifname);
if ((*internals)->if_name == NULL)
goto free_internals;
(*internals)->if_index = ifr.ifr_ifindex;
Expand Down Expand Up @@ -833,7 +829,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
if (rc == -1) {
PMD_LOG_ERRNO(ERR,
"%s: could not set PACKET_VERSION on AF_PACKET socket for %s",
name, pair->value);
name, ifname);
goto error;
}

Expand All @@ -843,7 +839,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
if (rc == -1) {
PMD_LOG_ERRNO(ERR,
"%s: could not set PACKET_LOSS on AF_PACKET socket for %s",
name, pair->value);
name, ifname);
goto error;
}

Expand All @@ -854,7 +850,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
if (rc == -1) {
PMD_LOG_ERRNO(ERR,
"%s: could not set PACKET_QDISC_BYPASS on AF_PACKET socket for %s",
name, pair->value);
name, ifname);
goto error;
}
#endif
Expand All @@ -864,15 +860,15 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
if (rc == -1) {
PMD_LOG_ERRNO(ERR,
"%s: could not set PACKET_RX_RING on AF_PACKET socket for %s",
name, pair->value);
name, ifname);
goto error;
}

rc = setsockopt(qsockfd, SOL_PACKET, PACKET_TX_RING, req, sizeof(*req));
if (rc == -1) {
PMD_LOG_ERRNO(ERR,
"%s: could not set PACKET_TX_RING on AF_PACKET "
"socket for %s", name, pair->value);
"socket for %s", name, ifname);
goto error;
}

Expand All @@ -885,7 +881,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
if (rx_queue->map == MAP_FAILED) {
PMD_LOG_ERRNO(ERR,
"%s: call to mmap failed on AF_PACKET socket for %s",
name, pair->value);
name, ifname);
goto error;
}

Expand Down Expand Up @@ -922,7 +918,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
if (rc == -1) {
PMD_LOG_ERRNO(ERR,
"%s: could not bind AF_PACKET socket to %s",
name, pair->value);
name, ifname);
goto error;
}

Expand All @@ -932,7 +928,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
if (rc == -1) {
PMD_LOG_ERRNO(ERR,
"%s: could not set PACKET_FANOUT on AF_PACKET socket for %s",
name, pair->value);
name, ifname);
goto error;
}
#endif
Expand Down Expand Up @@ -995,7 +991,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev,
const char *name = rte_vdev_device_name(dev);
struct pmd_internals *internals = NULL;
struct rte_eth_dev *eth_dev = NULL;
struct rte_kvargs_pair *pair = NULL;
const char *arg = NULL;
unsigned k_idx;
unsigned int blockcount;
unsigned int blocksize;
Expand All @@ -1013,57 +1009,55 @@ rte_eth_from_packet(struct rte_vdev_device *dev,
/*
* Walk arguments for configurable settings
*/
for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
pair = &kvlist->pairs[k_idx];
if (strstr(pair->key, ETH_AF_PACKET_NUM_Q_ARG) != NULL) {
qpairs = atoi(pair->value);
if (qpairs < 1) {
PMD_LOG(ERR,
"%s: invalid qpairs value",
name);
return -1;
}
continue;
}
if (strstr(pair->key, ETH_AF_PACKET_BLOCKSIZE_ARG) != NULL) {
blocksize = atoi(pair->value);
if (!blocksize) {
PMD_LOG(ERR,
"%s: invalid blocksize value",
name);
return -1;
}
continue;
arg = rte_kvargs_get(kvlist, ETH_AF_PACKET_NUM_Q_ARG);
if (arg != NULL) {
qpairs = atoi(arg);
if (qpairs < 1)
{
PMD_LOG(ERR,
"%s: invalid qpairs value",
name);
return -1;
}
if (strstr(pair->key, ETH_AF_PACKET_FRAMESIZE_ARG) != NULL) {
framesize = atoi(pair->value);
if (!framesize) {
PMD_LOG(ERR,
"%s: invalid framesize value",
name);
return -1;
}
continue;
}
arg = rte_kvargs_get(kvlist, ETH_AF_PACKET_BLOCKSIZE_ARG);
if (arg != NULL) {
blocksize = atoi(arg);
if (!blocksize) {
PMD_LOG(ERR,
"%s: invalid blocksize value",
name);
return -1;
}
if (strstr(pair->key, ETH_AF_PACKET_FRAMECOUNT_ARG) != NULL) {
framecount = atoi(pair->value);
if (!framecount) {
PMD_LOG(ERR,
"%s: invalid framecount value",
name);
return -1;
}
continue;
}
arg = rte_kvargs_get(kvlist, ETH_AF_PACKET_FRAMESIZE_ARG);
if (arg != NULL) {
framesize = atoi(arg);
if (!framesize) {
PMD_LOG(ERR,
"%s: invalid framesize value",
name);
return -1;
}
if (strstr(pair->key, ETH_AF_PACKET_QDISC_BYPASS_ARG) != NULL) {
qdisc_bypass = atoi(pair->value);
if (qdisc_bypass > 1) {
PMD_LOG(ERR,
"%s: invalid bypass value",
}
arg = rte_kvargs_get(kvlist, ETH_AF_PACKET_FRAMECOUNT_ARG);
if (arg != NULL) {
framecount = atoi(arg);
if (!framecount) {
PMD_LOG(ERR,
"%s: invalid framecount value",
name);
return -1;
}
continue;
return -1;
}
}
arg = rte_kvargs_get(kvlist, ETH_AF_PACKET_QDISC_BYPASS_ARG);
if (arg != NULL) {
qdisc_bypass = atoi(arg);
if (qdisc_bypass > 1) {
PMD_LOG(ERR,
"%s: invalid bypass value",
name);
return -1;
}
}

Expand Down
17 changes: 11 additions & 6 deletions drivers/net/ark/ark_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,16 @@ eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t size)
return -ENOTSUP;
}

static inline int
log_args(const char *key, const char *value,
void *extra_args)
{
ARK_PMD_LOG(DEBUG, "**** Arg passed to PMD = %s:%s\n",
key,
value);
return 0;
}

static inline int
process_pktdir_arg(const char *key, const char *value,
void *extra_args)
Expand Down Expand Up @@ -942,12 +952,7 @@ eth_ark_check_args(struct ark_adapter *ark, const char *params)
ark->pkt_gen_args[0] = 0;
ark->pkt_chkr_args[0] = 0;

for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
pair = &kvlist->pairs[k_idx];
ARK_PMD_LOG(DEBUG, "**** Arg passed to PMD = %s:%s\n",
pair->key,
pair->value);
}
rte_kvargs_process(kvlist, NULL, log_args, NULL);

if (rte_kvargs_process(kvlist,
ARK_PKTDIR_ARG,
Expand Down
10 changes: 4 additions & 6 deletions drivers/net/thunderx/nicvf_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2147,14 +2147,12 @@ nicvf_set_first_skip(struct rte_eth_dev *dev)
if (!kvlist)
return -EINVAL;

if (kvlist->count == 0)
if (rte_kvargs_count(kvlist, NULL) == 0)
goto exit;

for (i = 0; i != kvlist->count; ++i) {
const struct rte_kvargs_pair *pair = &kvlist->pairs[i];

if (!strcmp(pair->key, SKIP_DATA_BYTES))
bytes_to_skip = atoi(pair->value);
const char *arg = rte_kvargs_get(kvlist, SKIP_DATA_BYTES);
if (arg != NULL) {
bytes_to_skip = atoi(arg);
}

/*128 bytes amounts to one cache line*/
Expand Down
38 changes: 21 additions & 17 deletions lib/eal/common/eal_common_devargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
struct {
const char *key;
const char *str;
struct rte_kvargs *kvlist;
struct rte_kvargs *kvargs;
} layers[] = {
{ RTE_DEVARGS_KEY_BUS "=", NULL, NULL, },
{ RTE_DEVARGS_KEY_CLASS "=", NULL, NULL, },
Expand All @@ -67,6 +67,9 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
struct rte_kvargs_pair *kv = NULL;
struct rte_kvargs *bus_kvlist = NULL;
char *s;
const char *bus = NULL;
const char *cls = NULL;
const char *drv = NULL;
size_t nblayer = 0;
size_t i;
int ret = 0;
Expand Down Expand Up @@ -111,9 +114,9 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
break;
}

layers[nblayer].kvlist = rte_kvargs_parse
layers[nblayer].kvargs = rte_kvargs_parse
(layers[nblayer].str, NULL);
if (layers[nblayer].kvlist == NULL) {
if (layers[nblayer].kvargs == NULL) {
ret = -EINVAL;
goto get_out;
}
Expand All @@ -123,33 +126,34 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,

/* Parse each sub-list. */
for (i = 0; i < RTE_DIM(layers); i++) {
if (layers[i].kvlist == NULL)
if (layers[i].kvargs == NULL)
continue;
kv = &layers[i].kvlist->pairs[0];
if (kv->key == NULL)
continue;
if (strcmp(kv->key, RTE_DEVARGS_KEY_BUS) == 0) {
bus_kvlist = layers[i].kvlist;
bus = rte_kvargs_get(layers[i].kvargs, RTE_DEVARGS_KEY_BUS);
if (bus != NULL) {
bus_kvlist = layers[i].kvargs;
devargs->bus_str = layers[i].str;
devargs->bus = rte_bus_find_by_name(kv->value);
devargs->bus = rte_bus_find_by_name(bus);
if (devargs->bus == NULL) {
EAL_LOG(ERR, "Could not find bus \"%s\"",
kv->value);
bus);
ret = -EFAULT;
goto get_out;
}
} else if (strcmp(kv->key, RTE_DEVARGS_KEY_CLASS) == 0) {
}
cls = rte_kvargs_get(layers[i].kvargs, RTE_DEVARGS_KEY_CLASS);
if (cls != NULL) {
devargs->cls_str = layers[i].str;
devargs->cls = rte_class_find_by_name(kv->value);
devargs->cls = rte_class_find_by_name(cls);
if (devargs->cls == NULL) {
EAL_LOG(ERR, "Could not find class \"%s\"",
kv->value);
cls);
ret = -EFAULT;
goto get_out;
}
} else if (strcmp(kv->key, RTE_DEVARGS_KEY_DRIVER) == 0) {
}
drv = rte_kvargs_get(layers[i].kvargs, RTE_DEVARGS_KEY_DRIVER);
if (drv != NULL) {
devargs->drv_str = layers[i].str;
continue;
}
}

Expand All @@ -161,7 +165,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,

get_out:
for (i = 0; i < RTE_DIM(layers); i++) {
rte_kvargs_free(layers[i].kvlist);
rte_kvargs_free(layers[i].kvargs);
}
if (ret != 0) {
if (allocated_data) {
Expand Down
7 changes: 2 additions & 5 deletions lib/ethdev/rte_class_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ eth_dev_match(const struct rte_eth_dev *edev,
if (ret != 0)
return -1;
/* search for representor key */
for (pair = 0; pair < kvlist->count; pair++) {
ret = strcmp(kvlist->pairs[pair].key,
eth_params_keys[RTE_ETH_PARAM_REPRESENTOR]);
if (ret == 0)
break; /* there is a representor key */
if (rte_kvargs_get(kvlist, eth_params_keys[RTE_ETH_PARAM_REPRESENTOR]) == NULL) {
ret = 0; /* there is a representor key */
}
/* if no representor key, default is to not match representor ports */
if (ret != 0)
Expand Down