From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [143.182.124.21]) by dpdk.org (Postfix) with ESMTP id 6B20DAFCD for ; Wed, 28 May 2014 09:15:26 +0200 (CEST) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 28 May 2014 00:15:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.98,926,1392192000"; d="scan'208";a="437905980" Received: from shilc102.sh.intel.com ([10.239.39.44]) by azsmga001.ch.intel.com with ESMTP; 28 May 2014 00:15:16 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shilc102.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s4S7FCu8024960; Wed, 28 May 2014 15:15:14 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s4S7FAIB030282; Wed, 28 May 2014 15:15:12 +0800 Received: (from couyang@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s4S7FA41030278; Wed, 28 May 2014 15:15:10 +0800 From: Ouyang Changchun To: dev@dpdk.org Date: Wed, 28 May 2014 15:15:00 +0800 Message-Id: <1401261302-30140-2-git-send-email-changchun.ouyang@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1401261302-30140-1-git-send-email-changchun.ouyang@intel.com> References: <1401261302-30140-1-git-send-email-changchun.ouyang@intel.com> Subject: [dpdk-dev] [PATCH v2 1/3] ether: Add API to support set link up and link down X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 May 2014 07:15:27 -0000 Please ignore previous v1 patch, just use this v2 patch. This patch adds API to support the functionality of setting link up and down. It can be used to repeatedly stop and restart RX/TX of a port without re-allocating resources for the port and re-configuring the port. Signed-off-by: Ouyang Changchun --- lib/librte_ether/rte_ethdev.c | 38 ++++++++++++++++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index a5727dd..97e3f9d 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -691,6 +691,44 @@ rte_eth_dev_stop(uint8_t port_id) (*dev->dev_ops->dev_stop)(dev); } +int +rte_eth_dev_set_link_up(uint8_t port_id) +{ + struct rte_eth_dev *dev; + + /* This function is only safe when called from the primary process + * in a multi-process setup*/ + PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return -EINVAL; + } + dev = &rte_eth_devices[port_id]; + + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP); + return (*dev->dev_ops->dev_set_link_up)(dev); +} + +int +rte_eth_dev_set_link_down(uint8_t port_id) +{ + struct rte_eth_dev *dev; + + /* This function is only safe when called from the primary process + * in a multi-process setup*/ + PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return -EINVAL; + } + dev = &rte_eth_devices[port_id]; + + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP); + return (*dev->dev_ops->dev_set_link_down)(dev); +} + void rte_eth_dev_close(uint8_t port_id) { diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index d5ea46b..84f2e9f 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -823,6 +823,12 @@ typedef int (*eth_dev_start_t)(struct rte_eth_dev *dev); typedef void (*eth_dev_stop_t)(struct rte_eth_dev *dev); /**< @internal Function used to stop a configured Ethernet device. */ +typedef int (*eth_dev_set_link_up_t)(struct rte_eth_dev *dev); +/**< @internal Function used to link up a configured Ethernet device. */ + +typedef int (*eth_dev_set_link_down_t)(struct rte_eth_dev *dev); +/**< @internal Function used to link down a configured Ethernet device. */ + typedef void (*eth_dev_close_t)(struct rte_eth_dev *dev); /**< @internal Function used to close a configured Ethernet device. */ @@ -1084,6 +1090,8 @@ struct eth_dev_ops { eth_dev_configure_t dev_configure; /**< Configure device. */ eth_dev_start_t dev_start; /**< Start device. */ eth_dev_stop_t dev_stop; /**< Stop device. */ + eth_dev_set_link_up_t dev_set_link_up; /**< Device link up. */ + eth_dev_set_link_down_t dev_set_link_down; /**< Device link down. */ eth_dev_close_t dev_close; /**< Close device. */ eth_promiscuous_enable_t promiscuous_enable; /**< Promiscuous ON. */ eth_promiscuous_disable_t promiscuous_disable;/**< Promiscuous OFF. */ @@ -1475,6 +1483,32 @@ extern int rte_eth_dev_start(uint8_t port_id); */ extern void rte_eth_dev_stop(uint8_t port_id); + +/** + * Link up an Ethernet device. + * + * Set device link up will re-enable the device rx/tx + * functionality after it is previously set device linked down. + * + * @param port_id + * The port identifier of the Ethernet device. + * @return + * - 0: Success, Ethernet device linked up. + * - <0: Error code of the driver device link up function. + */ +extern int rte_eth_dev_set_link_up(uint8_t port_id); + +/** + * Link down an Ethernet device. + * The device rx/tx functionality will be disabled if success, + * and it can be re-enabled with a call to + * rte_eth_dev_set_link_up() + * + * @param port_id + * The port identifier of the Ethernet device. + */ +extern int rte_eth_dev_set_link_down(uint8_t port_id); + /** * Close an Ethernet device. The device cannot be restarted! * -- 1.9.0