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 26551A0542; Fri, 7 Feb 2020 12:25:47 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BF3851C0CF; Fri, 7 Feb 2020 12:25:43 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 659F91C0CB for ; Fri, 7 Feb 2020 12:25:43 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200207112542euoutp027683f0bc0959dee793f470a0665b0ce0~xGxoKmthF0460204602euoutp02t for ; Fri, 7 Feb 2020 11:25:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200207112542euoutp027683f0bc0959dee793f470a0665b0ce0~xGxoKmthF0460204602euoutp02t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1581074742; bh=XxgJ6IBeniClOtF3VmqICXEiGlNlR0uVNjmgmtnaI80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RPIBjKPmI6J6TtoZN8i2tmJy/Cr+pxk/XnnErHD/V4gkhnTI57fDU0dxDKG1myF5r C5kXrm6YT0XdBg5axHNkVH7VkTUemD7HrHXmZSwh+OgYZve9dmW7ljS13b42Jx4ghw xf61KjUeRETmstUHh17bVBDbQWKFVt/rnyFQhslg= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200207112542eucas1p29a4a9bef8ff26fc7a8c6ff61edbe44f3~xGxn2h1340654306543eucas1p2s; Fri, 7 Feb 2020 11:25:42 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id B9.00.60698.6394D3E5; Fri, 7 Feb 2020 11:25:42 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200207112542eucas1p149c88c52b887aab888351eab73fe7639~xGxnixHCR0739307393eucas1p1J; Fri, 7 Feb 2020 11:25:42 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200207112542eusmtrp259ce20042295466d41e6abe3d898050e~xGxniPMcz0922909229eusmtrp2R; Fri, 7 Feb 2020 11:25:42 +0000 (GMT) X-AuditID: cbfec7f5-a0fff7000001ed1a-2c-5e3d493689f3 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 76.E0.08375.6394D3E5; Fri, 7 Feb 2020 11:25:42 +0000 (GMT) Received: from idyukov.rnd.samsung.ru (unknown [106.109.129.29]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200207112541eusmtip193d02ebc02f044265356bcfc31b18f56~xGxnEr_Ri2768527685eusmtip1x; Fri, 7 Feb 2020 11:25:41 +0000 (GMT) From: Ivan Dyukov To: dev@dpdk.org, maxime.coquelin@redhat.com, tiwei.bie@intel.com, amorenoz@redhat.com Cc: Ivan Dyukov Date: Fri, 7 Feb 2020 14:25:26 +0300 Message-Id: <20200207112526.11455-2-i.dyukov@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200207112526.11455-1-i.dyukov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNIsWRmVeSWpSXmKPExsWy7djP87pmnrZxBrPOyVq07njAYvHu03Ym i1mXmtgtjnXuYbHY2vCfyYHV49eCpawei/e8ZPJ4v+8qm0ffllWMASxRXDYpqTmZZalF+nYJ XBnHFj1jLVhrVrHk0x62BsaNOl2MnBwSAiYSFy/OZOti5OIQEljBKPF1yXxWCOcLo8STT2+Y IJzP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QC+QlVm84ABbnFLCSmN/+BKxXCKjm2ZXLLBMY+RYwMqxiFEktLc5Nzy021CtOzC0uzUvX S87P3cQIDMptx35u3sF4aWPwIUYBDkYlHt4ER5s4IdbEsuLK3EOMEhzMSiK8faq2cUK8KYmV ValF+fFFpTmpxYcYTYGOmsgsJZqcD4yYvJJ4Q1NDcwtLQ3Njc2MzCyVx3g6BgzFCAumJJanZ qakFqUUwfUwcnFINjLy2O1nfm61/aGhroHXRJHHzsrvqOb+3cIVsztxY8z/H3UFmS7zlr8uP 02ISLZg03BwNoyYsfxMfwawi+taSO9powQ7lFX33NzRlzGBfl7ZlWdSu9wZ53gVi2wtPSvPs UJT79Tn6X82tW8mbNXyl0hpzuMu02QqFK1S3n3gwidH046zMEH1lJZbijERDLeai4kQAlZsc 2GACAAA= X-CMS-MailID: 20200207112542eucas1p149c88c52b887aab888351eab73fe7639 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200207112542eucas1p149c88c52b887aab888351eab73fe7639 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200207112542eucas1p149c88c52b887aab888351eab73fe7639 References: <20200207112526.11455-1-i.dyukov@samsung.com> Subject: [dpdk-dev] [PATCH v3 2/2] 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 | 101 ++++++++++++++++++++++++----- drivers/net/virtio/virtio_pci.h | 1 + 3 files changed, 92 insertions(+), 17 deletions(-) diff --git a/doc/guides/nics/virtio.rst b/doc/guides/nics/virtio.rst index d1f5fb898..f190f2e4f 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)) +#. ``link_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..5ef3c11a7 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 link_speed); +static int virtio_dev_devargs_parse(struct rte_devargs *devargs, + int *vdpa, + uint32_t *link_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 link_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, &link_speed); + if (ret < 0) + return ret; + hw->link_speed = link_speed; /* * Pass the information to the rte_eth_dev_close() that it should also * release the private port resources. @@ -1953,6 +1962,14 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) return 0; } +#define VIRTIO_ARG_LINK_SPEED "link_speed" +#define VIRTIO_ARG_VDPA "vdpa" + +static const char * const valid_args[] = { + VIRTIO_ARG_LINK_SPEED, + VIRTIO_ARG_VDPA, + NULL +}; static int vdpa_check_handler(__rte_unused const char *key, const char *value, void *ret_val) @@ -1965,33 +1982,84 @@ static int vdpa_check_handler(__rte_unused const char *key, return 0; } + +static uint32_t +virtio_dev_speed_capa_get(uint32_t link_speed) +{ + switch (link_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; + } +} + +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 *link_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) + kvlist = rte_kvargs_parse(devargs->args, valid_args); + 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 (link_speed && + rte_kvargs_count(kvlist, VIRTIO_ARG_LINK_SPEED) == 1) { + ret = rte_kvargs_process(kvlist, + VIRTIO_ARG_LINK_SPEED, + link_speed_handler, link_speed); + if (ret < 0) { + PMD_INIT_LOG(ERR, "error to parse %s", + VIRTIO_ARG_LINK_SPEED); + goto exit; + } } - exit: rte_kvargs_free(kvlist); @@ -2004,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_DRV_LOG(ERR, "devargs parsing is failed"); @@ -2386,7 +2454,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->link_speed; link.link_autoneg = ETH_LINK_FIXED; if (!hw->started) { @@ -2441,8 +2509,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->link_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..688eda914 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 link_speed; /* link speed in MB */ uint8_t *isr; uint16_t *notify_base; struct virtio_pci_common_cfg *common_cfg; -- 2.17.1