From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5FA0FA0524; Tue, 25 Feb 2020 08:31:19 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 75BD31BFDB; Tue, 25 Feb 2020 08:31:09 +0100 (CET) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 842071BFD3 for ; Tue, 25 Feb 2020 08:31:08 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200225073108euoutp0101e5e1f39a5143f26c86722cb2349543~2lL9ICLcv2036720367euoutp013 for ; Tue, 25 Feb 2020 07:31:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200225073108euoutp0101e5e1f39a5143f26c86722cb2349543~2lL9ICLcv2036720367euoutp013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1582615868; bh=wTOgce56Xo1vSap25g5XnEIAprhbLgtuOwkEoBo7BGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RrwegqKSXIodlBgRRLrqITkm6f8pinKV7v5X3sp2vNhwvJVuIiA4+leBO9lEnqDci Dh7/AYbckbrnYr7pU61zaoT3PG+y0rUzmrSE4UUGHE+B3JbMg4DJgOSRd0R75zaBTS Pojaxr29cp2FCuJPS7pweOhRAhYWih0SwanNUOrg= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200225073108eucas1p10ce3642c90526753fcf98186f6b2a491~2lL80vEDG1971419714eucas1p1f; Tue, 25 Feb 2020 07:31:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id C4.7F.60698.B3DC45E5; Tue, 25 Feb 2020 07:31:07 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200225073107eucas1p2255c2df9fb15b1e17b8447b7d88dbf2d~2lL8XHqEA1004210042eucas1p2z; Tue, 25 Feb 2020 07:31:07 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200225073107eusmtrp242a8d23b6f7daf4a4c00cad13545e012~2lL8V7RW40405804058eusmtrp2H; Tue, 25 Feb 2020 07:31:07 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-5b-5e54cd3bf21d Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id AC.99.07950.B3DC45E5; Tue, 25 Feb 2020 07:31:07 +0000 (GMT) Received: from idyukov.rnd.samsung.ru (unknown [106.109.129.29]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200225073106eusmtip226956a9874035240bbbc6bb1757ef732~2lL728huH1348813488eusmtip2A; Tue, 25 Feb 2020 07:31:06 +0000 (GMT) From: Ivan Dyukov To: dev@dpdk.org, maxime.coquelin@redhat.com, tiwei.bie@intel.com, amorenoz@redhat.com, zhihong.wang@intel.com Cc: Ivan Dyukov Date: Tue, 25 Feb 2020 10:28:11 +0300 Message-Id: <20200225072813.9385-3-i.dyukov@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200225072813.9385-1-i.dyukov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHIsWRmVeSWpSXmKPExsWy7djP87rWZ0PiDM5vNbdo3fGAxeLdp+1M FrMuNbFbHOvcw2KxteE/k8Xmi5OYHNg8fi1YyuqxeM9LJo/3+66yefRtWcUYwBLFZZOSmpNZ llqkb5fAlbH1+maWgq0mFS+vLmFqYDyp1cXIySEhYCLxdOt89i5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82RljAUuJRkypImEVAVWLumRaw MbwCFhIN5xezQIyXl1i94QDYKk6g8s3PJjNDrMqRePFgK9sERr4FjAyrGEVSS4tz03OLjfSK E3OLS/PS9ZLzczcxAkNz27GfW3Ywdr0LPsQowMGoxMMrsTc4Tog1say4MvcQowQHs5IIrzdj UJwQb0piZVVqUX58UWlOavEhRlOgoyYyS4km5wPjJq8k3tDU0NzC0tDc2NzYzEJJnLdD4GCM kEB6YklqdmpqQWoRTB8TB6dUA6O7kvbZczqXOOetfGDbdvSh7tzqCSeLX5RP6lb2nfStXTnX P4bti9rFm8qv98tE/CiQlin8uVte7eK8nUtTJ9Wp35/wZadoBFe7+YU2rodRyzfoa81T8yyu 1lm7maF3/TXz4/wO3xoE/7DcNtgWm9YV9yHj3cukVW/PL1jz7h97QL38Eom1BZxKLMUZiYZa zEXFiQDKe0saYwIAAA== X-CMS-MailID: 20200225073107eucas1p2255c2df9fb15b1e17b8447b7d88dbf2d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200225073107eucas1p2255c2df9fb15b1e17b8447b7d88dbf2d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200225073107eucas1p2255c2df9fb15b1e17b8447b7d88dbf2d References: <20200225072813.9385-1-i.dyukov@samsung.com> Subject: [dpdk-dev] [PATCH v4 2/4] net/virtio: add link speed devarg X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Some applications like pktgen use link_speed to calculate transmit rate. It limits outcome traffic to hardcoded 10G. This patch adds link_speed devarg which allows to configure link_speed of virtio device. Signed-off-by: Ivan Dyukov --- doc/guides/nics/virtio.rst | 7 +++ drivers/net/virtio/virtio_ethdev.c | 97 +++++++++++++++++++++++++----- drivers/net/virtio/virtio_pci.h | 1 + 3 files changed, 89 insertions(+), 16 deletions(-) diff --git a/doc/guides/nics/virtio.rst b/doc/guides/nics/virtio.rst index d1f5fb898..0341907ef 100644 --- a/doc/guides/nics/virtio.rst +++ b/doc/guides/nics/virtio.rst @@ -356,6 +356,13 @@ Below devargs are supported by the PCI virtio driver: a virtio device needs to work in vDPA mode. (Default: 0 (disabled)) +#. ``speed``: + + It is used to specify link speed of virtio device. Link speed is a part of + link status structure. It could be requested by application using + rte_eth_link_get_nowait function. + (Default: 10000 (10G)) + Below devargs are supported by the virtio-user vdev: #. ``path``: diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 22323d9a5..9707c8cbc 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -45,6 +45,10 @@ static int virtio_dev_promiscuous_enable(struct rte_eth_dev *dev); static int virtio_dev_promiscuous_disable(struct rte_eth_dev *dev); static int virtio_dev_allmulticast_enable(struct rte_eth_dev *dev); static int virtio_dev_allmulticast_disable(struct rte_eth_dev *dev); +static uint32_t virtio_dev_speed_capa_get(uint32_t speed); +static int virtio_dev_devargs_parse(struct rte_devargs *devargs, + int *vdpa, + uint32_t *speed); static int virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info); static int virtio_dev_link_update(struct rte_eth_dev *dev, @@ -1861,6 +1865,7 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev) { struct virtio_hw *hw = eth_dev->data->dev_private; + uint32_t speed = ETH_SPEED_NUM_10G; int ret; if (sizeof(struct virtio_net_hdr_mrg_rxbuf) > RTE_PKTMBUF_HEADROOM) { @@ -1886,7 +1891,11 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) return 0; } - + ret = virtio_dev_devargs_parse(eth_dev->device->devargs, + NULL, &speed); + if (ret < 0) + return ret; + hw->speed = speed; /* * Pass the information to the rte_eth_dev_close() that it should also * release the private port resources. @@ -1954,6 +1963,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) return 0; } + static int vdpa_check_handler(__rte_unused const char *key, const char *value, void *ret_val) { @@ -1965,33 +1975,89 @@ static int vdpa_check_handler(__rte_unused const char *key, return 0; } + +static uint32_t +virtio_dev_speed_capa_get(uint32_t speed) +{ + switch (speed) { + case ETH_SPEED_NUM_10G: + return ETH_LINK_SPEED_10G; + case ETH_SPEED_NUM_20G: + return ETH_LINK_SPEED_20G; + case ETH_SPEED_NUM_25G: + return ETH_LINK_SPEED_25G; + case ETH_SPEED_NUM_40G: + return ETH_LINK_SPEED_40G; + case ETH_SPEED_NUM_50G: + return ETH_LINK_SPEED_50G; + case ETH_SPEED_NUM_56G: + return ETH_LINK_SPEED_56G; + case ETH_SPEED_NUM_100G: + return ETH_LINK_SPEED_100G; + default: + return 0; + } +} + + +#define VIRTIO_ARG_SPEED "speed" +#define VIRTIO_ARG_VDPA "vdpa" + + +static int link_speed_handler(const char *key __rte_unused, + const char *value, void *ret_val) +{ + uint32_t val; + if (!value || !ret_val) + return -EINVAL; + val = strtoul(value, NULL, 0); + /* validate input */ + if (virtio_dev_speed_capa_get(val) == 0) + return -EINVAL; + *(uint32_t *)ret_val = val; + + return 0; +} + + static int -virtio_dev_devargs_parse(struct rte_devargs *devargs, int *vdpa) +virtio_dev_devargs_parse(struct rte_devargs *devargs, int *vdpa, + uint32_t *speed) { struct rte_kvargs *kvlist; - const char *key = "vdpa"; int ret = 0; if (devargs == NULL) return 0; kvlist = rte_kvargs_parse(devargs->args, NULL); - if (kvlist == NULL) + if (kvlist == NULL) { + PMD_INIT_LOG(ERR, "error when parsing param"); return 0; - - if (!rte_kvargs_count(kvlist, key)) - goto exit; - - if (vdpa) { + } + if (vdpa && rte_kvargs_count(kvlist, VIRTIO_ARG_VDPA) == 1) { /* vdpa mode selected when there's a key-value pair: * vdpa=1 */ - ret = rte_kvargs_process(kvlist, key, + ret = rte_kvargs_process(kvlist, VIRTIO_ARG_VDPA, vdpa_check_handler, vdpa); - if (ret < 0) + if (ret < 0) { + PMD_INIT_LOG(ERR, "error to parse %s", + VIRTIO_ARG_VDPA); goto exit; + } + } + if (speed && + rte_kvargs_count(kvlist, VIRTIO_ARG_SPEED) == 1) { + ret = rte_kvargs_process(kvlist, + VIRTIO_ARG_SPEED, + link_speed_handler, speed); + if (ret < 0) { + PMD_INIT_LOG(ERR, "error to parse %s", + VIRTIO_ARG_SPEED); + goto exit; + } } - exit: rte_kvargs_free(kvlist); @@ -2004,7 +2070,7 @@ static int eth_virtio_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, int vdpa = 0; int ret = 0; - ret = virtio_dev_devargs_parse(pci_dev->device.devargs, &vdpa); + ret = virtio_dev_devargs_parse(pci_dev->device.devargs, &vdpa, NULL); if (ret < 0) { PMD_DRV_LOG(ERR, "devargs parsing is failed"); @@ -2386,7 +2452,7 @@ virtio_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complet memset(&link, 0, sizeof(link)); link.link_duplex = ETH_LINK_FULL_DUPLEX; - link.link_speed = ETH_SPEED_NUM_10G; + link.link_speed = hw->speed; link.link_autoneg = ETH_LINK_FIXED; if (!hw->started) { @@ -2441,8 +2507,7 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { uint64_t tso_mask, host_features; struct virtio_hw *hw = dev->data->dev_private; - - dev_info->speed_capa = ETH_LINK_SPEED_10G; /* fake value */ + dev_info->speed_capa = virtio_dev_speed_capa_get(hw->speed); dev_info->max_rx_queues = RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES); diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h index a38cb45ad..59012d55a 100644 --- a/drivers/net/virtio/virtio_pci.h +++ b/drivers/net/virtio/virtio_pci.h @@ -253,6 +253,7 @@ struct virtio_hw { uint16_t port_id; uint8_t mac_addr[RTE_ETHER_ADDR_LEN]; uint32_t notify_off_multiplier; + uint32_t speed; /* link speed in MB */ uint8_t *isr; uint16_t *notify_base; struct virtio_pci_common_cfg *common_cfg; -- 2.17.1