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 E209EA0562; Sun, 29 Mar 2020 16:44:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F27CC1BFDC; Sun, 29 Mar 2020 16:43:39 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id DA45A1BF9D for ; Sun, 29 Mar 2020 16:43:36 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200329144336euoutp020035b39d72915bb787d98b6fbb34c037~AzX_EM5Re1301113011euoutp02c for ; Sun, 29 Mar 2020 14:43:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200329144336euoutp020035b39d72915bb787d98b6fbb34c037~AzX_EM5Re1301113011euoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1585493016; bh=ZbN59GHW4ffE3sG8tYnOAPv/kl6HquKSHf4JmyUTkGE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=k4Sq9p29rb5PnFDfkiZNC3OvsTnCxFazMOuheiOOEeUfCWiQC0C1ik3sE2Yd7hD94 vfSmanR5kvLM7yxmzisiPErp2xoKrOx2fgw883xvn524rZKGyVbk9CRCUJhs+y8O1P CzP4VJJvybGp53V/jbxeUE93Fyl5RXomKVUCRVHg= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200329144336eucas1p29f5e5aad14617be3c703fb855d58cd56~AzX97Nlne0654106541eucas1p2l; Sun, 29 Mar 2020 14:43:36 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 41.A3.60679.814B08E5; Sun, 29 Mar 2020 15:43:36 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200329144335eucas1p1b3962cf40116e2da679b99c26f3f8ed7~AzX9cIhJ71502915029eucas1p1r; Sun, 29 Mar 2020 14:43:35 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200329144335eusmtrp1d1d102ce0a60bb5a29ee95e0cd079288~AzX9bJD5Z1668216682eusmtrp1b; Sun, 29 Mar 2020 14:43:35 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-6f-5e80b418093b Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 9D.D6.08375.714B08E5; Sun, 29 Mar 2020 15:43:35 +0100 (BST) Received: from idyukov.rnd.samsung.ru (unknown [106.109.129.29]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200329144335eusmtip10bada5fa0d36f53d6a51d1b983e62bcf~AzX820Ruk0278902789eusmtip1L; Sun, 29 Mar 2020 14:43:35 +0000 (GMT) From: Ivan Dyukov To: dev@dpdk.org, maxime.coquelin@redhat.com, i.dyukov@samsung.com, tiwei.bie@intel.com, amorenoz@redhat.com, zhihong.wang@intel.com, xiaolong.ye@intel.com Date: Sun, 29 Mar 2020 17:42:48 +0300 Message-Id: <20200329144308.5103-3-i.dyukov@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329144308.5103-1-i.dyukov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSa0hTURz37N7dXZeT2xT8u8JgEJTQZmZ0g3AVi/ZN+xQEWktvU9qmbNOa EY1M02FlRlRDUirfaFrztTaZSyY6ULLMEZlZ4PKV5ANtabZ5J337Pc//fw6HxISzuIjM1hoY nVapFhN8vMP9e/gAWE3pCZ/H+XRR11ec/rn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AQ0JE53zGMCSYgILGeU6L/cygaSEBawlPh0cDk7iM0ioCqxtKsNLM4r YCFx91YPE8RUeYnVGw6AbeAEqp/w/i4jiC0kkC5xcNcJpgmMvAsYGVYxiqSWFuem5xYb6hUn 5haX5qXrJefnbmIEhuS2Yz8372C8tDH4EKMAB6MSD69BZX2cEGtiWXFl7iFGCQ5mJRFeNv+G OCHelMTKqtSi/Pii0pzU4kOMpkBHTWSWEk3OB8ZLXkm8oamhuYWlobmxubGZhZI4b4fAwRig MxJLUrNTUwtSi2D6mDg4pRoYEyKrImvM4q4GcNULJCfFynR+kKmfJB4SvES+6vWhqPK8owcL lnwJUdkWNiGdY+dl1Z8++a6JDWz/mMNf/jZ+8TX6weGKk9bipx0mFVTbpk/PnCzTwLrpXJPs fOurL6pSbsU7ps5p/zpvSTqr84TPH4Me87A280y18Pl1bJUx+5aiOfcNJnxQYinOSDTUYi4q TgQAQBAU6V8CAAA= X-CMS-MailID: 20200329144335eucas1p1b3962cf40116e2da679b99c26f3f8ed7 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200329144335eucas1p1b3962cf40116e2da679b99c26f3f8ed7 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200329144335eucas1p1b3962cf40116e2da679b99c26f3f8ed7 References: <20191212085012.9170-1-i.dyukov@samsung.com> <20200329144308.5103-1-i.dyukov@samsung.com> Subject: [dpdk-dev] [PATCH v7 2/5] 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 transmission rate. It limits outcome traffic to hardcoded 10G. This patch adds 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 870ff7801..fe0e292ef 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. @@ -1956,6 +1965,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) { @@ -1967,33 +1977,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, "Failed 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, "Failed to parse %s", + VIRTIO_ARG_SPEED); + goto exit; + } } - exit: rte_kvargs_free(kvlist); @@ -2006,7 +2072,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_INIT_LOG(ERR, "devargs parsing is failed"); return ret; @@ -2385,7 +2451,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) { @@ -2440,8 +2506,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 7433d2f08..ed98e11c3 100644 --- a/drivers/net/virtio/virtio_pci.h +++ b/drivers/net/virtio/virtio_pci.h @@ -259,6 +259,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