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 31EC2A0563; Wed, 15 Apr 2020 22:05:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 768451DA1E; Wed, 15 Apr 2020 22:04:48 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 076391DA16 for ; Wed, 15 Apr 2020 22:04:45 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200415200444euoutp01997c4f430f894df760d1e9b71743a8a6~GFuNyfboa2184721847euoutp019 for ; Wed, 15 Apr 2020 20:04:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200415200444euoutp01997c4f430f894df760d1e9b71743a8a6~GFuNyfboa2184721847euoutp019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586981084; bh=/Sx5PLXWzYimOAlkENkZY4+K1nGA7XAmiXUi1RTi9wM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eyvS2v+BcReIxMm5MJQyouzCgcZPF3OHMaozJHpvdvV1B5f3EvUjtbnMIUWhxm6Qe uVONcpy8Eq5bQ2uA8/1H18DG7Ms8gl8zFzXlISr8v32gH8irubkjrYC3+tisgGYicE bVvbhQRZ0BFwBIGCT8DVefgG/5HDtP+u1nsQQoVQ= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200415200444eucas1p14e9e6bf3a32d4c4de724f19a113c54f1~GFuNLrQjT1271912719eucas1p1Q; Wed, 15 Apr 2020 20:04:44 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id D2.59.61286.CD8679E5; Wed, 15 Apr 2020 21:04:44 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200415200443eucas1p1d131bd52589c9f43d552c398fb3c10c3~GFuM9a_zR1298412984eucas1p1L; Wed, 15 Apr 2020 20:04:43 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200415200443eusmtrp215f98fdc87b36068a36e975c04301574~GFuM82R9S3009430094eusmtrp2B; Wed, 15 Apr 2020 20:04:43 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-43-5e9768dc1643 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id AD.27.07950.BD8679E5; Wed, 15 Apr 2020 21:04:43 +0100 (BST) Received: from idyukov.rnd.samsung.ru (unknown [106.109.129.29]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200415200443eusmtip10f9bde98aebba5f632e0c5224bd10265~GFuMZMhFh1865818658eusmtip1L; Wed, 15 Apr 2020 20:04:43 +0000 (GMT) From: Ivan Dyukov To: dev@dpdk.org, maxime.coquelin@redhat.com, i.dyukov@samsung.com, v.kuramshin@samsung.com, amorenoz@redhat.com, zhihong.wang@intel.com, xiaolong.ye@intel.com, mb@smartsharesystems.com Date: Wed, 15 Apr 2020 23:03:55 +0300 Message-Id: <20200415200423.6410-4-i.dyukov@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200415200423.6410-1-i.dyukov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSa0hTYRjHe885247LxWmKPpgkLISSmlpWp3uh0D51QUgIXM08XtJN3XFe 6kMSOZfBslFKI20oUiwqc0uXt2zlXctmZo0hmiCoqXhD0nVxnknffs/v+T/vAw8viYsXiSAy VZXNqFWKdAlfSNS1//q0x5VSJo+oXB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DFEjLPHnWhcbiC0k8JlRoqknG8RmE9CQON0xD6xXROA4o0TvrP9MIAlhASuJufuugdks AqoSt+58ZQWxeQUsJM62bWWEGCovsXrDAbAFnAKWEtsuHYJakC6xpLuHaQIj7wJGhlWMIqml xbnpucVGesWJucWleel6yfm5mxiBQbrt2M8tOxi73gUfYhTgYFTi4e14PS1OiDWxrLgy9xCj BAezkgjvDv/pcUK8KYmVValF+fFFpTmpxYcYTYGOmsgsJZqcD4ygvJJ4Q1NDcwtLQ3Njc2Mz CyVx3g6BgzFAZySWpGanphakFsH0MXFwSjUwLr5Vsn0P602h019WlN0VvbEp4OjSSQuWtV9q d/eVzNG4UbJVdtq+X7WzTFf8Oh/ekHbu8sQ7XO+lmF86xnWzPY/l4Tdcf+Eeo2fT527P2GVH Aw7GRH5355zu+7yP/5XABo5b1sIlnh+P35/M/EaGOS7n9fu7mTySTK8Obbi8qmCVieRy8evp f5VYijMSDbWYi4oTAXSCzMtoAgAA X-CMS-MailID: 20200415200443eucas1p1d131bd52589c9f43d552c398fb3c10c3 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200415200443eucas1p1d131bd52589c9f43d552c398fb3c10c3 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200415200443eucas1p1d131bd52589c9f43d552c398fb3c10c3 References: <20191212085012.9170-1-i.dyukov@samsung.com> <20200415200423.6410-1-i.dyukov@samsung.com> Subject: [dpdk-dev] [PATCH v10 3/6] 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" Default value of link speed is 0xffffffff (Unknown) 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 | 107 ++++++++++++++++++++++++----- drivers/net/virtio/virtio_pci.h | 1 + 3 files changed, 99 insertions(+), 16 deletions(-) diff --git a/doc/guides/nics/virtio.rst b/doc/guides/nics/virtio.rst index d1f5fb898..55bc6a267 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, in units of 1Mb. + Link speed is a part of link status structure. It could be requested + by application using rte_eth_link_get_nowait function. + (Default: 0xffffffff (Unknown)) + 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 60195ab3c..306241d37 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_UNKNOWN; 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. @@ -1967,33 +1976,100 @@ static int vdpa_check_handler(__rte_unused const char *key, return 0; } + +static uint32_t +virtio_dev_speed_capa_get(uint32_t speed) +{ + struct speed_caps { + uint32_t min_speed; + uint32_t speed_capa; + }; + struct speed_caps caps[] = { + {ETH_SPEED_NUM_10M, ETH_LINK_SPEED_10M}, + {ETH_SPEED_NUM_100M, ETH_LINK_SPEED_100M}, + {ETH_SPEED_NUM_1G, ETH_LINK_SPEED_1G}, + {ETH_SPEED_NUM_2_5G, ETH_LINK_SPEED_2_5G}, + {ETH_SPEED_NUM_5G, ETH_LINK_SPEED_5G}, + {ETH_SPEED_NUM_10G, ETH_LINK_SPEED_10G}, + {ETH_SPEED_NUM_20G, ETH_LINK_SPEED_20G}, + {ETH_SPEED_NUM_25G, ETH_LINK_SPEED_25G}, + {ETH_SPEED_NUM_40G, ETH_LINK_SPEED_40G}, + {ETH_SPEED_NUM_50G, ETH_LINK_SPEED_50G}, + {ETH_SPEED_NUM_56G, ETH_LINK_SPEED_56G}, + {ETH_SPEED_NUM_100G, ETH_LINK_SPEED_100G} + }; + const uint32_t caps_size = sizeof(caps) / sizeof(struct speed_caps); + uint32_t speed_capa = ETH_LINK_SPEED_AUTONEG; + if (speed != ETH_SPEED_NUM_UNKNOWN) { + /* find maximum suitable speed capability */ + for (uint32_t i = 0; i < caps_size; i++) { + if (speed >= caps[i].min_speed) + speed_capa = caps[i].speed_capa; + } + } + return speed_capa; +} + + +#define VIRTIO_ARG_SPEED "speed" +#define VIRTIO_ARG_VDPA "vdpa" + + static int -virtio_dev_devargs_parse(struct rte_devargs *devargs, int *vdpa) +link_speed_handler(const char *key __rte_unused, + const char *value, void *ret_val) +{ + uint32_t val; + if (!value || !ret_val) + return -EINVAL; + errno = 0; + val = strtoul(value, NULL, 0); + /* validate input */ + if (errno != 0) + return -EINVAL; + *(uint32_t *)ret_val = val; + + return 0; +} + + +static int +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 +2082,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 +2461,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_UNKNOWN; + link.link_speed = hw->speed; link.link_autoneg = ETH_LINK_FIXED; if (!hw->started) { @@ -2440,8 +2516,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_AUTONEG; /* 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