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 40CB3A0562; Sun, 29 Mar 2020 16:45:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8BE6A1C0C3; Sun, 29 Mar 2020 16:43:49 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id E79831C02C for ; Sun, 29 Mar 2020 16:43:40 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200329144340euoutp0286e78e90c3331fae7fe4b3f11342b2de~AzYCHhWoO1301113011euoutp02f for ; Sun, 29 Mar 2020 14:43:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200329144340euoutp0286e78e90c3331fae7fe4b3f11342b2de~AzYCHhWoO1301113011euoutp02f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1585493020; bh=M7fJPba7ImOU1eJfmvdx8D1pboFpBOi4ntuP+Fmij4o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MLGXiYHD07Jd1lDRzsMQmDeF2AipQS+a66DAD8HUfwHLpxSyCpKTq6NFupYpphPoE yhYrTfpbIuWWRW54iydMC+z4r8iX6uJXhpTBeoJyAtlej9qAm41miAMeu5pbi1Jm3z OkwCzYd1WAwpkTHQ7nNbtZZYyLmepJ5F7JJmIy3Y= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200329144340eucas1p14e391c8792c57d5e41efe58a35281db2~AzYBjr3AJ1546415464eucas1p16; Sun, 29 Mar 2020 14:43:40 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id E2.A3.60679.C14B08E5; Sun, 29 Mar 2020 15:43:40 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200329144339eucas1p19f866f53b24156a01ef54ec5e6bb8926~AzYBKRdQN1536015360eucas1p19; Sun, 29 Mar 2020 14:43:39 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200329144339eusmtrp1001d5a454a7544b5351e5ef79ce758ba~AzYBJmM151668216682eusmtrp1d; Sun, 29 Mar 2020 14:43:39 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-77-5e80b41ca93b Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 9E.D6.08375.B14B08E5; Sun, 29 Mar 2020 15:43:39 +0100 (BST) Received: from idyukov.rnd.samsung.ru (unknown [106.109.129.29]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200329144339eusmtip1f09c101709e67e23f6b7ca6eda695d99~AzYAq4awO0185501855eusmtip1R; Sun, 29 Mar 2020 14:43:39 +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:51 +0300 Message-Id: <20200329144308.5103-6-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: H4sIAAAAAAAAA+NgFnrJIsWRmVeSWpSXmKPExsWy7djPc7oyWxriDD4tZLNo3fGAxeLdp+1M FrMuNbFbHOvcw2KxteE/k8WfN6YWmy9OYnJg9/i1YCmrx+I9L5k83u+7yubRt2UVYwBLFJdN SmpOZllqkb5dAlfGpWWb2QumqlRcaJn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yx4TSK+IwHJGif7LrWBFwgIeEsva+8FsFgFVif4b98FsXgEL iWOL/rJADJWXWL3hANgCTgFLiQnv7zJCLEiXOLjrBNMERt4FjAyrGEVSS4tz03OLDfWKE3OL S/PS9ZLzczcxAgNy27Gfm3cwXtoYfIhRgINRiYfXoLI+Tog1say4MvcQowQHs5IIL5t/Q5wQ b0piZVVqUX58UWlOavEhRlOgoyYyS4km5wOjJa8k3tDU0NzC0tDc2NzYzEJJnLdD4GAM0BmJ JanZqakFqUUwfUwcnFINjM3/d026cuTiAv6Hzw//FFut/G/P+/I//mFOCyd9dPebEibPK3p0 4p77E/901840ORlca2nezF/w7RjTli8S6caPzj2793iai3iB+ZRL5Y6Ohw9dZo6V3Mpx9t7u Rz5Pf65cl1MaGv91sXXopgAmvtr+vOnqBTuexHxkubxoIs+iS6Ftf2sdmCSVWIozEg21mIuK EwE2nWFWXgIAAA== X-CMS-MailID: 20200329144339eucas1p19f866f53b24156a01ef54ec5e6bb8926 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200329144339eucas1p19f866f53b24156a01ef54ec5e6bb8926 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200329144339eucas1p19f866f53b24156a01ef54ec5e6bb8926 References: <20191212085012.9170-1-i.dyukov@samsung.com> <20200329144308.5103-1-i.dyukov@samsung.com> Subject: [dpdk-dev] [PATCH v7 5/5] net/virtio: Support of VIRTIO_NET_F_SPEED_DUPLEX 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" This patch adds a support of VIRTIO_NET_F_SPEED_DUPLEX feature for virtio driver. There are few ways to specify speed of the link: 'speed' devarg negotiate speed from qemu via VIRTIO_NET_F_SPEED_DUPLEX The highest priority is devarg. If devarg is not specified, drivers tries to negotiate it from qemu. Signed-off-by: Ivan Dyukov --- drivers/net/virtio/virtio_ethdev.c | 26 +++++++++++++++++++++++--- drivers/net/virtio/virtio_ethdev.h | 3 ++- drivers/net/virtio/virtio_pci.h | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index fe0e292ef..8a6e1933a 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -1662,7 +1662,8 @@ virtio_configure_intr(struct rte_eth_dev *dev) return 0; } - +#define SPEED_UNKNOWN 0xffffffff +#define DUPLEX_UNKNOWN 0xff /* reset device and renegotiate features if needed */ static int virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) @@ -1718,6 +1719,25 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2], hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]); + if (hw->speed == SPEED_UNKNOWN) { + if (vtpci_with_feature(hw, VIRTIO_NET_F_SPEED_DUPLEX)) { + config = &local_config; + vtpci_read_dev_config(hw, + offsetof(struct virtio_net_config, speed), + &config->speed, sizeof(config->speed)); + vtpci_read_dev_config(hw, + offsetof(struct virtio_net_config, duplex), + &config->duplex, sizeof(config->duplex)); + hw->speed = config->speed; + hw->duplex = config->duplex; + } + } + if (hw->speed == SPEED_UNKNOWN) + hw->speed = ETH_SPEED_NUM_10G; + if (hw->duplex == DUPLEX_UNKNOWN) + hw->duplex = ETH_LINK_FULL_DUPLEX; + PMD_INIT_LOG(DEBUG, "link speed = %d, duplex = %d", + hw->speed, hw->duplex); if (vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_VQ)) { config = &local_config; @@ -1865,7 +1885,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; + uint32_t speed = SPEED_UNKNOWN; int ret; if (sizeof(struct virtio_net_hdr_mrg_rxbuf) > RTE_PKTMBUF_HEADROOM) { @@ -2450,7 +2470,7 @@ virtio_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complet struct virtio_hw *hw = dev->data->dev_private; memset(&link, 0, sizeof(link)); - link.link_duplex = ETH_LINK_FULL_DUPLEX; + link.link_duplex = hw->duplex; link.link_speed = hw->speed; link.link_autoneg = ETH_LINK_FIXED; diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h index cd8947656..febaf17a8 100644 --- a/drivers/net/virtio/virtio_ethdev.h +++ b/drivers/net/virtio/virtio_ethdev.h @@ -37,7 +37,8 @@ 1ULL << VIRTIO_F_RING_PACKED | \ 1ULL << VIRTIO_F_IOMMU_PLATFORM | \ 1ULL << VIRTIO_F_ORDER_PLATFORM | \ - 1ULL << VIRTIO_F_NOTIFICATION_DATA) + 1ULL << VIRTIO_F_NOTIFICATION_DATA | \ + 1ULL << VIRTIO_NET_F_SPEED_DUPLEX) #define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \ (VIRTIO_PMD_DEFAULT_GUEST_FEATURES | \ diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h index ed98e11c3..1da3df940 100644 --- a/drivers/net/virtio/virtio_pci.h +++ b/drivers/net/virtio/virtio_pci.h @@ -141,6 +141,9 @@ struct virtnet_ctl; */ #define VIRTIO_F_NOTIFICATION_DATA 38 +/* Device set linkspeed and duplex */ +#define VIRTIO_NET_F_SPEED_DUPLEX 63 + /* The Guest publishes the used index for which it expects an interrupt * at the end of the avail ring. Host should ignore the avail->flags field. */ /* The Host publishes the avail index for which it expects a kick @@ -260,6 +263,7 @@ struct virtio_hw { uint8_t mac_addr[RTE_ETHER_ADDR_LEN]; uint32_t notify_off_multiplier; uint32_t speed; /* link speed in MB */ + uint8_t duplex; uint8_t *isr; uint16_t *notify_base; struct virtio_pci_common_cfg *common_cfg; @@ -306,6 +310,18 @@ struct virtio_net_config { uint16_t status; uint16_t max_virtqueue_pairs; uint16_t mtu; + /* + * speed, in units of 1Mb. All values 0 to INT_MAX are legal. + * Any other value stands for unknown. + */ + uint32_t speed; + /* + * 0x00 - half duplex + * 0x01 - full duplex + * Any other value stands for unknown. + */ + uint8_t duplex; + } __attribute__((packed)); /* -- 2.17.1