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 45C5BA0526; Mon, 20 Jan 2020 18:11:21 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9C3621C123; Mon, 20 Jan 2020 18:05:34 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 893151BFCC for ; Mon, 20 Jan 2020 18:05:32 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200120170532euoutp0294e477d3acf04368834f2c3f451ad8c9~rpzMfdba00349003490euoutp02i for ; Mon, 20 Jan 2020 17:05:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200120170532euoutp0294e477d3acf04368834f2c3f451ad8c9~rpzMfdba00349003490euoutp02i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1579539932; bh=Hpe1tp3R4qrR/4uhutp6qiPz/J7xZp7HhIRkEMbWdX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZEoLEgx3mni6b5BfhJogdVbdIwmO/iMQPS+nH1B8i+JNAKlawpnZrRpUCmApWoDKs DFo1xG33zdvthte+SvDc5ZilfSs8nzoRlhO9r/qw78CeagmkMWmsBWOoxGV/eiWK56 0ZF9NRmsRtzXkjrb6sOGPlHT36LvrI34RT0tK2M8= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200120170531eucas1p27d90e3f2b9fe8406d2fb31f3b9e23840~rpzL8ttwI2114021140eucas1p2G; Mon, 20 Jan 2020 17:05:31 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 96.B3.60679.BDDD52E5; Mon, 20 Jan 2020 17:05:31 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200120170531eucas1p218252a80fbf9252baf21921f8c72fe82~rpzLoylE60873108731eucas1p2h; Mon, 20 Jan 2020 17:05:31 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200120170531eusmtrp1a9fafe7ec302bbac48d8403965d870d7~rpzLoQWt-3265232652eusmtrp1E; Mon, 20 Jan 2020 17:05:31 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-d4-5e25dddbaa88 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id BB.66.08375.BDDD52E5; Mon, 20 Jan 2020 17:05:31 +0000 (GMT) Received: from idyukov.rnd.samsung.ru (unknown [106.109.129.29]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200120170531eusmtip2a21dc7afa453ac2c6e2cff2b64f3bca7~rpzLRXaX72042920429eusmtip2i; Mon, 20 Jan 2020 17:05:30 +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 20:05:20 +0300 Message-Id: <20200120170520.24192-2-i.dyukov@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200120170520.24192-1-i.dyukov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKIsWRmVeSWpSXmKPExsWy7djPc7q376rGGXz5pW3x7tN2JotZl5rY LY517mGx2Nrwn8mBxePXgqWsHov3vGTyeL/vKptH35ZVjAEsUVw2Kak5mWWpRfp2CVwZC/Y9 Yi94b1Dx5/FzpgbGDo0uRk4OCQETicMXljF3MXJxCAmsYJT4s/sIO0hCSOALo8StEzkQ9m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f XmL1hgNgcU4BK4mOKc/A4kJANc3nNrBPYORbwMiwilEktbQ4Nz232FCvODG3uDQvXS85P3cT IzAUtx37uXkH46WNwYcYBTgYlXh4HaapxgmxJpYVV+YeYpTgYFYS4V3QBBTiTUmsrEotyo8v Ks1JLT7EaAp01ERmKdHkfGCc5JXEG5oamltYGpobmxubWSiJ83YIHIwREkhPLEnNTk0tSC2C 6WPi4JRqYPT+G6WUbnKjXcFrE5O63fYZm/rKwt/MLtbN7Vt5QTFvw9VF0vmXljYmN/OcTU5T urXgaPIF66yzs3YvuuLFva9Y08jm7togK+3JDz/OaMu5dF5oykvFWSX3c5amPry+mZPtx7Vq y+0/WX7fFGqLmT/vnecy857gRKm261+FU0TOXnxlf2fbwVlKLMUZiYZazEXFiQA2RUWVWwIA AA== X-CMS-MailID: 20200120170531eucas1p218252a80fbf9252baf21921f8c72fe82 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200120170531eucas1p218252a80fbf9252baf21921f8c72fe82 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200120170531eucas1p218252a80fbf9252baf21921f8c72fe82 References: <20200120170520.24192-1-i.dyukov@samsung.com> Subject: [dpdk-dev] [PATCH v2 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 --- drivers/net/virtio/virtio_ethdev.c | 101 ++++++++++++++++++++++++----- drivers/net/virtio/virtio_pci.h | 1 + 2 files changed, 85 insertions(+), 17 deletions(-) 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