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 CA085A0562; Mon, 30 Mar 2020 09:59:13 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E141D1C0B9; Mon, 30 Mar 2020 09:58:38 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 244601C02A for ; Mon, 30 Mar 2020 09:58:35 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200330075834euoutp01230143fb231de44916bbe99b33ee099c~BBfnzdyq_2510925109euoutp01e for ; Mon, 30 Mar 2020 07:58:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200330075834euoutp01230143fb231de44916bbe99b33ee099c~BBfnzdyq_2510925109euoutp01e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1585555114; bh=azBop3x8eIJeC0jTqFtVBghYmdWsKLcfxPp4qmB8fvM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hplgxlNVjBKtkfVS5S+V3+g9q0A4do15nNgEOVIxb0WikdNEyZp4bxeMRpEtnzNGE tHJSuSD6LISY/MarX2wXf9dCDC2T0Oej/BipSNqK5OQ3FrxXN/EPzUNUgwXEUIn059 qH2d5/cFXCfLb3+Q6NGAjTQc+M97W0f5R9KQNBQI= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200330075834eucas1p2a626069748c4f6f62f7ad2fb85bbc9e8~BBfnjrDui0523005230eucas1p2O; Mon, 30 Mar 2020 07:58:34 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 5B.3B.60698.AA6A18E5; Mon, 30 Mar 2020 08:58:34 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200330075834eucas1p2892713fbbd1b13d9f65e5efc9d25d9a8~BBfnS9PFC0523005230eucas1p2N; Mon, 30 Mar 2020 07:58:34 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200330075834eusmtrp2cb98010418fd21775d64f2f4b52aca5a~BBfnSDvge1664516645eusmtrp2K; Mon, 30 Mar 2020 07:58:34 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-d1-5e81a6aa1cf2 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 26.AE.08375.AA6A18E5; Mon, 30 Mar 2020 08:58:34 +0100 (BST) Received: from idyukov.rnd.samsung.ru (unknown [106.109.129.29]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200330075833eusmtip2531ced43063a2549c0b5f96711771fbc~BBfmxGwZh3044630446eusmtip2O; Mon, 30 Mar 2020 07:58:33 +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: Mon, 30 Mar 2020 10:58:02 +0300 Message-Id: <20200330075814.6857-6-i.dyukov@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330075814.6857-1-i.dyukov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBIsWRmVeSWpSXmKPExsWy7djPc7qrljXGGbzfqmrRuuMBi8W7T9uZ LGZdamK3ONa5h8Via8N/Jos/b0wtNl+cxOTA7vFrwVJWj8V7XjJ5vN93lc2jb8sqxgCWKC6b lNSczLLUIn27BK6Mnt0X2AqmqFSsb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/citYkbCAh8TpDX8YQWwWAVWJH3P7mEBsXgEL iX8zdrNBDJWXWL3hANgCTgFLiTMTtzJBLEiXaLzdwTSBkXcBI8MqRpHU0uLc9NxiQ73ixNzi 0rx0veT83E2MwHDcduzn5h2MlzYGH2IU4GBU4uGdsbUhTog1say4MvcQowQHs5IIL5s/UIg3 JbGyKrUoP76oNCe1+BCjKdBRE5mlRJPzgbGSVxJvaGpobmFpaG5sbmxmoSTO2yFwMAbojMSS 1OzU1ILUIpg+Jg5OqQZGHpH5OfOPsbLHPlX+8ZFpfm/JJ98vgYHm6otU+PVFtZ7MX/E41coq /3Ke1XTRmTEpdbGf/DniVomJlD89zvFQsS8h79XV7VH3dhsISsXP+vpg4u49h9JV8t787uT0 VZVctDfOwSvl3YZlxr9trP7aSJyaGmRd3yx0W4DttehDV7Yklo8HWv2VWIozEg21mIuKEwFl adwCXQIAAA== X-CMS-MailID: 20200330075834eucas1p2892713fbbd1b13d9f65e5efc9d25d9a8 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200330075834eucas1p2892713fbbd1b13d9f65e5efc9d25d9a8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200330075834eucas1p2892713fbbd1b13d9f65e5efc9d25d9a8 References: <20191212085012.9170-1-i.dyukov@samsung.com> <20200330075814.6857-1-i.dyukov@samsung.com> Subject: [dpdk-dev] [PATCH v8 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..bd89357e4 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