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 44E3FA0521; Mon, 20 Jan 2020 15:18:12 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B05271BE85; Mon, 20 Jan 2020 15:18:05 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 6F3F91BC25 for ; Mon, 20 Jan 2020 15:18:04 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200120141803euoutp02ab2abca0b657cbe265488c73715505b4~rng_Kcdv42959829598euoutp02l for ; Mon, 20 Jan 2020 14:18:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200120141803euoutp02ab2abca0b657cbe265488c73715505b4~rng_Kcdv42959829598euoutp02l DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1579529883; bh=M+ABnjGTiZKGNUlpwyi5eBH2UVcJIbo+P46Ox/Jqy58=; h=From:To:Cc:Subject:Date:In-Reply-To:Reply-To:References:From; b=N8lW1Y5sG/1w9QaUepFt6O85w+kx3H1JkFxd+XDru1lCduM7qa58q0F9PMU1nfgP2 wKyWjAlrD9jvdjjzohHMr2mjz0lO7NzM26xDhNx8tSBrxK2gK8iIXhKpU0uevPJwui 6lDxDzWqSWfmESxePk+dwck1Rjy9pVIX/Mm39Nrw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200120141803eucas1p19392db8116cd5f58ad5cac9a8851c67f~rng_BuSD42954729547eucas1p1C; Mon, 20 Jan 2020 14:18:03 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 5E.CD.60679.B96B52E5; Mon, 20 Jan 2020 14:18:03 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200120141803eucas1p237734f0e71549561006618f4c8ee637e~rng9qqT6l1193311933eucas1p2m; Mon, 20 Jan 2020 14:18:03 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200120141803eusmtrp2688f3f72ffac5169f9c08b7aa82bcbb2~rng9qF4zq2867528675eusmtrp2i; Mon, 20 Jan 2020 14:18:03 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-f5-5e25b69be11f Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 60.C1.07950.B96B52E5; Mon, 20 Jan 2020 14:18:03 +0000 (GMT) Received: from idyukov.rnd.samsung.ru (unknown [106.109.129.29]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200120141803eusmtip274c23522b44613bdc001e024cac94496~rng9U9_9M1447214472eusmtip2e; Mon, 20 Jan 2020 14:18:02 +0000 (GMT) From: Ivan Dyukov To: dev@dpdk.org, maxime.coquelin@redhat.com, tiwei.bie@intel.com Cc: Ivan Dyukov Date: Mon, 20 Jan 2020 17:16:03 +0300 Message-Id: <20200120141603.18719-3-i.dyukov@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120141603.18719-1-i.dyukov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEIsWRmVeSWpSXmKPExsWy7djP87qzt6nGGTTv1LV492k7k8WsS03s Fsc697BYbG34z+TA4vFrwVJWj8V7XjJ5vN93lc2jb8sqxgCWKC6blNSczLLUIn27BK6MVbtX MRXcMKg4fecocwPjG/UuRk4OCQETic62dqYuRi4OIYEVjBKPzt1ngXC+MEps3LuHFcL5zCjx Y/8SNpiWGRev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qOAWsJLbMvwpmCwHV3F+9hgXClpO4Pv8L0wRG/gWMDKsYRVJLi3PTc4uN9IoT c4tL89L1kvNzNzECQ3TbsZ9bdjB2vQs+xCjAwajEw+swTTVOiDWxrLgy9xCjBAezkgjvgiag EG9KYmVValF+fFFpTmrxIUZToAMnMkuJJucD4yevJN7Q1NDcwtLQ3Njc2MxCSZy3Q+BgjJBA emJJanZqakFqEUwfEwenVAMjS6DwDQNn59MH5n/Uu2DwSjZA5uTHf49aqr54PnKLu92Y1f3C SdvZLOCxsHjFnoig0qVTF+1S5RARMbHy6Atv3uk0vyqO0Vr/mJ4D3+Tqw6Fvz627LaOtZxPu pqfJ8d5iqahPxrPd1y+VLLje3tBxY+H7I7s5591Knb1LV+3bjH2Vm+WehgkosRRnJBpqMRcV JwIAV7dYo2cCAAA= X-CMS-MailID: 20200120141803eucas1p237734f0e71549561006618f4c8ee637e X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200120141803eucas1p237734f0e71549561006618f4c8ee637e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200120141803eucas1p237734f0e71549561006618f4c8ee637e References: <20200120141603.18719-1-i.dyukov@samsung.com> Subject: [dpdk-dev] [PATCH 2/2] net/virtio: add link speed devarg X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: i.dyukov@samsung.com 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 --- drivers/net/virtio/virtio_ethdev.c | 99 +++++++++++++++++++++++++----- drivers/net/virtio/virtio_pci.h | 1 + 2 files changed, 85 insertions(+), 15 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index d6ccbd7b2..29cf53911 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -45,6 +45,11 @@ 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 +1866,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 +1892,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 +1963,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 *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,30 +1983,82 @@ 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) { - goto exit; + 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; + } } @@ -2003,7 +2073,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"); @@ -2385,7 +2455,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) { @@ -2440,8 +2510,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