From patchwork Sat May 27 08:22:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Dai X-Patchwork-Id: 24743 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 076C837A0; Sat, 27 May 2017 10:31:29 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 459403777 for ; Sat, 27 May 2017 10:31:22 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 May 2017 01:31:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.38,400,1491289200"; d="scan'208"; a="1135329748" Received: from dpdk6.bj.intel.com ([172.16.182.81]) by orsmga001.jf.intel.com with ESMTP; 27 May 2017 01:31:20 -0700 From: Wei Dai To: wenzhuo.lu@intel.com, konstantin.ananyev@intel.com, helin.zhang@intel.com, jingjing.wu@intel.com Cc: dev@dpdk.org, Wei Dai Date: Sat, 27 May 2017 16:22:05 +0800 Message-Id: <1495873329-43303-4-git-send-email-wei.dai@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495873329-43303-1-git-send-email-wei.dai@intel.com> References: <1495873329-43303-1-git-send-email-wei.dai@intel.com> Subject: [dpdk-dev] [PATCH 3/7] ethdev: add support of restoration of port status 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" As dev->data->dev_link.link_status may change when the port is initialized again, this patch adds dev->data->restore_link for restoration. In the restoration process, ethdev layer can restore link status as up or down by comparing dev->data->restore_link.link_status and dev->data->dev_link.link_status. Signed-off-by: Wei Dai --- lib/librte_ether/rte_ethdev.c | 37 +++++++++++++++++++++++++++++++++++-- lib/librte_ether/rte_ethdev.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 97c0044..af8ccf6 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -923,6 +923,28 @@ rte_eth_dev_tx_queue_restore(uint8_t port_id, uint16_t queue_id) } static void +rte_eth_dev_link_status_restore(uint8_t port_id) +{ + struct rte_eth_dev *dev; + + dev = &rte_eth_devices[port_id]; + + if (dev->data->in_restoration == 0) { + dev->data->restore_link.link_status = + dev->data->dev_link.link_status; + return; + } + + if (dev->data->restore_link.link_status + != dev->data->dev_link.link_status) { + if (dev->data->restore_link.link_status != 0) + rte_eth_dev_set_link_up(port_id); + else + rte_eth_dev_set_link_down(port_id); + } +} + +static void rte_eth_dev_config_restore(uint8_t port_id) { struct rte_eth_dev *dev; @@ -982,6 +1004,7 @@ rte_eth_dev_config_restore(uint8_t port_id) for (q = 0; q < dev->data->nb_tx_queues; q++) rte_eth_dev_tx_queue_restore(port_id, q); + rte_eth_dev_link_status_restore(port_id); } int @@ -1014,6 +1037,8 @@ rte_eth_dev_start(uint8_t port_id) if (dev->data->dev_conf.intr_conf.lsc == 0) { RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP); (*dev->dev_ops->link_update)(dev, 0); + dev->data->restore_link.link_status = + dev->data->dev_link.link_status; } return 0; } @@ -1043,26 +1068,34 @@ int rte_eth_dev_set_link_up(uint8_t port_id) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP); - return (*dev->dev_ops->dev_set_link_up)(dev); + ret = (*dev->dev_ops->dev_set_link_up)(dev); + if (!ret) + dev->data->restore_link.link_status = 1; + return ret; } int rte_eth_dev_set_link_down(uint8_t port_id) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP); - return (*dev->dev_ops->dev_set_link_down)(dev); + ret = (*dev->dev_ops->dev_set_link_down)(dev); + if (!ret) + dev->data->restore_link.link_status = 0; + return ret; } void diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 7a2ce07..9428f57 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1734,6 +1734,7 @@ struct rte_eth_dev_data { void *dev_private; /**< PMD-specific private data */ struct rte_eth_link dev_link; + struct rte_eth_link restore_link; /**< Link-level information & status */ struct rte_eth_conf dev_conf; /**< Configuration applied to device. */