From patchwork Fri Apr 14 06:36:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuanhan Liu X-Patchwork-Id: 23639 X-Patchwork-Delegate: yuanhan.liu@linux.intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id AC5FF37B2; Fri, 14 Apr 2017 08:39:43 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 0ADF8378B; Fri, 14 Apr 2017 08:39:41 +0200 (CEST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Apr 2017 23:39:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,197,1488873600"; d="scan'208";a="87380779" Received: from yliu-dev.sh.intel.com ([10.239.67.162]) by orsmga005.jf.intel.com with ESMTP; 13 Apr 2017 23:39:39 -0700 From: Yuanhan Liu To: dev@dpdk.org Cc: Maxime Coquelin , Yuanhan Liu , stable@dpdk.org Date: Fri, 14 Apr 2017 14:36:45 +0800 Message-Id: <1492151805-14086-1-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 Subject: [dpdk-dev] [PATCH] net/virtio: fix link status always being up 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" The virtio port link status will always be UP, even the port is stopped: testpmd> port stop 0 Stopping ports... Checking link statuses... Port 0 Link Up - speed 10000 Mbps - full-duplex Done The link status is queried by link_update callback when LSC is disabled. Which in turn queries the "status" field. However, the "status" is read-only. I couldn't think of some proper ways to change the status without doing device reset. Instead of doing (the heavy) reset at stop, this patch introduced a flag, which is set to 1 and 0 on start and stop, respectively. When it's set to 0, the link status is set to DOWN unconditionally. Fixes: a85786dc816f ("virtio: fix states handling during initialization") Cc: stable@dpdk.org Signed-off-by: Yuanhan Liu --- drivers/net/virtio/virtio_ethdev.c | 7 ++++++- drivers/net/virtio/virtio_pci.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 78cb3e8..b2f9570 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -1768,6 +1768,7 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev, txvq = dev->data->tx_queues[i]; VIRTQUEUE_DUMP(txvq->vq); } + hw->started = 1; return 0; } @@ -1823,6 +1824,7 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev) static void virtio_dev_stop(struct rte_eth_dev *dev) { + struct virtio_hw *hw = dev->data->dev_private; struct rte_eth_link link; struct rte_intr_conf *intr_conf = &dev->data->dev_conf.intr_conf; @@ -1831,6 +1833,7 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev) if (intr_conf->lsc || intr_conf->rxq) rte_intr_disable(dev->intr_handle); + hw->started = 0; memset(&link, 0, sizeof(link)); virtio_dev_atomic_write_link_status(dev, &link); } @@ -1847,7 +1850,9 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev) link.link_duplex = ETH_LINK_FULL_DUPLEX; link.link_speed = SPEED_10G; - if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS)) { + if (hw->started == 0) { + link.link_status = ETH_LINK_DOWN; + } else if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS)) { PMD_INIT_LOG(DEBUG, "Get link status from hw"); vtpci_read_dev_config(hw, offsetof(struct virtio_net_config, status), diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h index 0362acd..e7290d7 100644 --- a/drivers/net/virtio/virtio_pci.h +++ b/drivers/net/virtio/virtio_pci.h @@ -253,6 +253,7 @@ struct virtio_hw { uint64_t req_guest_features; uint64_t guest_features; uint32_t max_queue_pairs; + uint16_t started; uint16_t max_mtu; uint16_t vtnet_hdr_size; uint8_t vlan_strip;