X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fvdev_netvsc%2Fvdev_netvsc.c;h=c1b7099717f51041f756cf7ba5666cfa0c8f493f;hb=d566bfcff0c7bfe167f6c520d4fd5b0104130af6;hp=48717f2f0d755ded7c632d7fcce5183d4666be45;hpb=83d63f0903b3951c76a4508693e8bade582b28b0;p=dpdk.git diff --git a/drivers/net/vdev_netvsc/vdev_netvsc.c b/drivers/net/vdev_netvsc/vdev_netvsc.c index 48717f2f0d..c1b7099717 100644 --- a/drivers/net/vdev_netvsc/vdev_netvsc.c +++ b/drivers/net/vdev_netvsc/vdev_netvsc.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -49,6 +48,8 @@ #define NETVSC_CLASS_ID "{f8615163-df3e-46c5-913f-f2d2f965ed0e}" #define NETVSC_MAX_ROUTE_LINE_SIZE 300 +RTE_LOG_REGISTER(vdev_netvsc_logtype, pmd.net.vdev_netvsc, NOTICE); + #define DRV_LOG(level, ...) \ rte_log(RTE_LOG_ ## level, \ vdev_netvsc_logtype, \ @@ -56,9 +57,6 @@ RTE_FMT_HEAD(__VA_ARGS__,) "\n", \ RTE_FMT_TAIL(__VA_ARGS__,))) -/** Driver-specific log messages type. */ -static int vdev_netvsc_logtype; - /** Context structure for a vdev_netvsc instance. */ struct vdev_netvsc_ctx { LIST_ENTRY(vdev_netvsc_ctx) entry; /**< Next entry in list. */ @@ -68,7 +66,7 @@ struct vdev_netvsc_ctx { char devargs[256]; /**< Fail-safe device arguments. */ char if_name[IF_NAMESIZE]; /**< NetVSC netdevice name. */ unsigned int if_index; /**< NetVSC netdevice index. */ - struct ether_addr if_addr; /**< NetVSC MAC address. */ + struct rte_ether_addr if_addr; /**< NetVSC MAC address. */ int pipe[2]; /**< Fail-safe communication pipe. */ char yield[256]; /**< PCI sub-device arguments. */ }; @@ -157,7 +155,7 @@ vdev_netvsc_iface_is_netvsc(const struct if_nameindex *iface) */ static int vdev_netvsc_foreach_iface(int (*func)(const struct if_nameindex *iface, - const struct ether_addr *eth_addr, + const struct rte_ether_addr *eth_addr, va_list ap), int is_netvsc, ...) { struct if_nameindex *iface = if_nameindex(); @@ -178,7 +176,7 @@ vdev_netvsc_foreach_iface(int (*func)(const struct if_nameindex *iface, for (i = 0; iface[i].if_name; ++i) { int is_netvsc_ret; struct ifreq req; - struct ether_addr eth_addr; + struct rte_ether_addr eth_addr; va_list ap; is_netvsc_ret = vdev_netvsc_iface_is_netvsc(&iface[i]) ? 1 : 0; @@ -191,11 +189,8 @@ vdev_netvsc_foreach_iface(int (*func)(const struct if_nameindex *iface, req.ifr_name, rte_strerror(errno)); continue; } - if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER) { - DRV_LOG(DEBUG, "interface %s is non-ethernet device", - req.ifr_name); + if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER) continue; - } memcpy(eth_addr.addr_bytes, req.ifr_hwaddr.sa_data, RTE_DIM(eth_addr.addr_bytes)); va_start(ap, is_netvsc); @@ -333,7 +328,7 @@ vdev_netvsc_sysfs_readlink(char *buf, size_t size, const char *if_name, char in[RTE_MAX(sizeof(ctx->yield), 256u)]; int ret; - ret = snprintf(in, sizeof(in) - 1, "/sys/class/net/%s/%s", + ret = snprintf(in, sizeof(in), "/sys/class/net/%s/%s", if_name, relpath); if (ret == -1 || (size_t)ret >= sizeof(in)) return -ENOBUFS; @@ -371,7 +366,7 @@ vdev_netvsc_sysfs_readlink(char *buf, size_t size, const char *if_name, */ static int vdev_netvsc_device_probe(const struct if_nameindex *iface, - const struct ether_addr *eth_addr, + const struct rte_ether_addr *eth_addr, va_list ap) { struct vdev_netvsc_ctx *ctx = va_arg(ap, struct vdev_netvsc_ctx *); @@ -390,7 +385,7 @@ vdev_netvsc_device_probe(const struct if_nameindex *iface, strlcpy(ctx->if_name, iface->if_name, sizeof(ctx->if_name)); return 0; } - if (!is_same_ether_addr(eth_addr, &ctx->if_addr)) + if (!rte_is_same_ether_addr(eth_addr, &ctx->if_addr)) return 0; /* Look for associated PCI device. */ ret = vdev_netvsc_sysfs_readlink(buf, sizeof(buf), iface->if_name, @@ -510,7 +505,7 @@ vdev_netvsc_alarm(__rte_unused void *arg) */ static int vdev_netvsc_netvsc_probe(const struct if_nameindex *iface, - const struct ether_addr *eth_addr, + const struct rte_ether_addr *eth_addr, va_list ap) { const char *name = va_arg(ap, const char *); @@ -530,24 +525,16 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface, if (!strcmp(pair->value, iface->if_name)) break; } else if (!strcmp(pair->key, VDEV_NETVSC_ARG_MAC)) { - struct ether_addr tmp; - - if (sscanf(pair->value, - "%" SCNx8 ":%" SCNx8 ":%" SCNx8 ":" - "%" SCNx8 ":%" SCNx8 ":%" SCNx8, - &tmp.addr_bytes[0], - &tmp.addr_bytes[1], - &tmp.addr_bytes[2], - &tmp.addr_bytes[3], - &tmp.addr_bytes[4], - &tmp.addr_bytes[5]) != 6) { + struct rte_ether_addr tmp; + + if (rte_ether_unformat_addr(pair->value, &tmp) != 0) { DRV_LOG(ERR, "invalid MAC address format" " \"%s\"", pair->value); return -EINVAL; } - if (is_same_ether_addr(eth_addr, &tmp)) + if (rte_is_same_ether_addr(eth_addr, &tmp)) break; } } @@ -636,7 +623,7 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface, ctx->devname, ctx->devargs); vdev_netvsc_foreach_iface(vdev_netvsc_device_probe, 0, ctx); ret = rte_eal_hotplug_add("vdev", ctx->devname, ctx->devargs); - if (ret) + if (ret < 0) goto error; LIST_INSERT_HEAD(&vdev_netvsc_ctx_list, ctx, entry); ++vdev_netvsc_ctx_count; @@ -684,6 +671,7 @@ vdev_netvsc_vdev_probe(struct rte_vdev_device *dev) int ret; DRV_LOG(DEBUG, "invoked as \"%s\", using arguments \"%s\"", name, args); + rte_eal_alarm_cancel(vdev_netvsc_alarm, NULL); if (!kvargs) { DRV_LOG(ERR, "cannot parse arguments list"); goto error; @@ -699,17 +687,13 @@ vdev_netvsc_vdev_probe(struct rte_vdev_device *dev) !strcmp(pair->key, VDEV_NETVSC_ARG_MAC)) ++specified; } - if (ignore) { - if (kvargs) - rte_kvargs_free(kvargs); - return 0; - } + if (ignore) + goto ignore; if (specified > 1) { DRV_LOG(ERR, "More than one way used to specify the netvsc" " device."); goto error; } - rte_eal_alarm_cancel(vdev_netvsc_alarm, NULL); /* Gather interfaces. */ ret = vdev_netvsc_foreach_iface(vdev_netvsc_netvsc_probe, 1, name, kvargs, specified, &matched); @@ -730,17 +714,19 @@ vdev_netvsc_vdev_probe(struct rte_vdev_device *dev) } DRV_LOG(WARNING, "non-netvsc device was probed as netvsc"); } - ret = rte_eal_alarm_set(VDEV_NETVSC_PROBE_MS * 1000, - vdev_netvsc_alarm, NULL); - if (ret < 0) { - DRV_LOG(ERR, "unable to schedule alarm callback: %s", - rte_strerror(-ret)); - goto error; - } error: + ++vdev_netvsc_ctx_inst; +ignore: if (kvargs) rte_kvargs_free(kvargs); - ++vdev_netvsc_ctx_inst; + /* Reset alarm if there are device context created */ + if (vdev_netvsc_ctx_count) { + ret = rte_eal_alarm_set(VDEV_NETVSC_PROBE_MS * 1000, + vdev_netvsc_alarm, NULL); + if (ret < 0) + DRV_LOG(ERR, "unable to schedule alarm callback: %s", + rte_strerror(-ret)); + } return 0; } @@ -786,14 +772,6 @@ RTE_PMD_REGISTER_PARAM_STRING(net_vdev_netvsc, VDEV_NETVSC_ARG_FORCE "= " VDEV_NETVSC_ARG_IGNORE "="); -/** Initialize driver log type. */ -RTE_INIT(vdev_netvsc_init_log) -{ - vdev_netvsc_logtype = rte_log_register("pmd.vdev_netvsc"); - if (vdev_netvsc_logtype >= 0) - rte_log_set_level(vdev_netvsc_logtype, RTE_LOG_NOTICE); -} - /** Compare function for vdev find device operation. */ static int vdev_netvsc_cmp_rte_device(const struct rte_device *dev1, @@ -811,7 +789,7 @@ vdev_netvsc_cmp_rte_device(const struct rte_device *dev1, static void vdev_netvsc_scan_callback(__rte_unused void *arg) { - struct rte_vdev_device *dev; + struct rte_device *dev; struct rte_devargs *devargs; struct rte_bus *vbus = rte_bus_find_by_name("vdev"); @@ -819,8 +797,9 @@ vdev_netvsc_scan_callback(__rte_unused void *arg) if (!strncmp(devargs->name, VDEV_NETVSC_DRIVER_NAME, VDEV_NETVSC_DRIVER_NAME_LEN)) return; - dev = (struct rte_vdev_device *)vbus->find_device(NULL, - vdev_netvsc_cmp_rte_device, VDEV_NETVSC_DRIVER_NAME); + + dev = vbus->find_device(NULL, vdev_netvsc_cmp_rte_device, + VDEV_NETVSC_DRIVER_NAME); if (dev) return; if (rte_devargs_add(RTE_DEVTYPE_VIRTUAL, VDEV_NETVSC_DRIVER_NAME))