diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index ceb8d9356a..c369214f85 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -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; @@ -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); @@ -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; @@ -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; } @@ -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; } @@ -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 @@ -864,7 +860,7 @@ 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; } @@ -872,7 +868,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, 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; } @@ -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; } @@ -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; } @@ -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 @@ -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; @@ -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; } } diff --git a/drivers/net/ark/ark_ethdev.c b/drivers/net/ark/ark_ethdev.c index c029dc46b3..a4b34fbffd 100644 --- a/drivers/net/ark/ark_ethdev.c +++ b/drivers/net/ark/ark_ethdev.c @@ -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) @@ -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, diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c index 4441a90bdf..31dcae25c1 100644 --- a/drivers/net/thunderx/nicvf_ethdev.c +++ b/drivers/net/thunderx/nicvf_ethdev.c @@ -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*/ diff --git a/lib/eal/common/eal_common_devargs.c b/lib/eal/common/eal_common_devargs.c index a64805b268..4e85d5e913 100644 --- a/lib/eal/common/eal_common_devargs.c +++ b/lib/eal/common/eal_common_devargs.c @@ -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, }, @@ -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; @@ -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; } @@ -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; } } @@ -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) { diff --git a/lib/ethdev/rte_class_eth.c b/lib/ethdev/rte_class_eth.c index a8d01e2595..a4500c242c 100644 --- a/lib/ethdev/rte_class_eth.c +++ b/lib/ethdev/rte_class_eth.c @@ -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)