From patchwork Wed Jun 3 14:03:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Iremonger, Bernard" X-Patchwork-Id: 5103 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 54F8C5A56; Wed, 3 Jun 2015 16:03:09 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 4AE093237 for ; Wed, 3 Jun 2015 16:03:07 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 03 Jun 2015 07:03:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,547,1427785200"; d="scan'208";a="704640803" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 03 Jun 2015 07:03:05 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t53E34RF005681; Wed, 3 Jun 2015 15:03:04 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t53E34gk020422; Wed, 3 Jun 2015 15:03:04 +0100 Received: (from bairemon@localhost) by sivswdev01.ir.intel.com with id t53E34lQ020418; Wed, 3 Jun 2015 15:03:04 +0100 From: Bernard Iremonger To: dev@dpdk.org Date: Wed, 3 Jun 2015 15:03:02 +0100 Message-Id: <1433340182-20382-1-git-send-email-bernard.iremonger@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: References: Subject: [dpdk-dev] [RFC PATCH V3] e1000: igb and em1000 PCI Port Hotplug changes 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch depends on the Port Hotplug Framework. It implements the eth_dev_uninit functions for rte_em_pmd, rte_igb_pmd and rte_igbvf_pmd. Changes in V3: Add igb_adapter_stopped and em_adapter_stopped booleans. Release rx and tx queues Changes in V2: Call dev_close() from dev_uninit() functions. Remove input parameter checking from dev_uninit() functions. Signed-off-by: Bernard Iremonger --- drivers/net/e1000/e1000_ethdev.h | 4 +- drivers/net/e1000/em_ethdev.c | 50 ++++++++++++++++++++++- drivers/net/e1000/igb_ethdev.c | 85 +++++++++++++++++++++++++++++++++++++- drivers/net/e1000/igb_pf.c | 22 ++++++++++ 4 files changed, 157 insertions(+), 4 deletions(-) diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h index c451faa..3ce1a22 100644 --- a/drivers/net/e1000/e1000_ethdev.h +++ b/drivers/net/e1000/e1000_ethdev.h @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -337,4 +337,6 @@ uint16_t eth_em_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts); +void igb_pf_host_uninit(struct rte_eth_dev *dev); + #endif /* _E1000_ETHDEV_H_ */ diff --git a/drivers/net/e1000/em_ethdev.c b/drivers/net/e1000/em_ethdev.c index d28030e..db9b465 100644 --- a/drivers/net/e1000/em_ethdev.c +++ b/drivers/net/e1000/em_ethdev.c @@ -121,6 +121,7 @@ static void eth_em_rar_clear(struct rte_eth_dev *dev, uint32_t index); #define EM_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */ static enum e1000_fc_mode em_fc_setting = e1000_fc_full; +static bool em_adapter_stopped; /* * The set of PCI devices this driver supports @@ -241,6 +242,7 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev) hw->hw_addr = (void *)pci_dev->mem_resource[0].addr; hw->device_id = pci_dev->id.device_id; + em_adapter_stopped = 0; /* For ICH8 support we'll need to map the flash memory BAR */ @@ -280,13 +282,56 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev) return (0); } +static int +eth_em_dev_uninit(struct rte_eth_dev *eth_dev) +{ + struct rte_pci_device *pci_dev; + unsigned i; + + PMD_INIT_FUNC_TRACE(); + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -EPERM; + + pci_dev = eth_dev->pci_dev; + + if (em_adapter_stopped == 0) + eth_em_close(eth_dev); + + eth_dev->dev_ops = NULL; + eth_dev->rx_pkt_burst = NULL; + eth_dev->tx_pkt_burst = NULL; + + rte_free(eth_dev->data->mac_addrs); + eth_dev->data->mac_addrs = NULL; + + for (i = 0; i < eth_dev->data->nb_rx_queues; i++) { + eth_em_rx_queue_release(eth_dev->data->rx_queues[i]); + eth_dev->data->rx_queues[i] = NULL; + } + + for (i = 0; i < eth_dev->data->nb_tx_queues; i++) { + eth_em_tx_queue_release(eth_dev->data->tx_queues[i]); + eth_dev->data->tx_queues[i] = NULL; + } + + /* disable uio intr before callback unregister */ + rte_intr_disable(&(pci_dev->intr_handle)); + rte_intr_callback_unregister(&(pci_dev->intr_handle), + eth_em_interrupt_handler, (void *)eth_dev); + + return 0; +} + static struct eth_driver rte_em_pmd = { { .name = "rte_em_pmd", .id_table = pci_id_em_map, - .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC, + .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC | + RTE_PCI_DRV_DETACHABLE, }, .eth_dev_init = eth_em_dev_init, + .eth_dev_uninit = eth_em_dev_uninit, .dev_private_size = sizeof(struct e1000_adapter), }; @@ -565,6 +610,8 @@ eth_em_start(struct rte_eth_dev *dev) } } + em_adapter_stopped = 0; + PMD_INIT_LOG(DEBUG, "<<"); return (0); @@ -610,6 +657,7 @@ eth_em_close(struct rte_eth_dev *dev) struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private); eth_em_stop(dev); + em_adapter_stopped = 1; e1000_phy_hw_reset(hw); em_release_manageability(hw); em_hw_control_release(hw); diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c index e4b370d..fb130c7 100644 --- a/drivers/net/e1000/igb_ethdev.c +++ b/drivers/net/e1000/igb_ethdev.c @@ -212,6 +212,7 @@ static int eth_igb_filter_ctrl(struct rte_eth_dev *dev, #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */ static enum e1000_fc_mode igb_fc_setting = e1000_fc_full; +static bool igb_adapter_stopped; /* * The set of PCI devices this driver supports @@ -564,6 +565,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev) goto err_late; } hw->mac.get_link_status = 1; + igb_adapter_stopped = 0; /* Indicate SOL/IDER usage */ if (e1000_check_reset_block(hw) < 0) { @@ -608,6 +610,55 @@ err_late: return (error); } +static int +eth_igb_dev_uninit(struct rte_eth_dev *eth_dev) +{ + struct rte_pci_device *pci_dev; + struct e1000_hw *hw; + unsigned i; + + PMD_INIT_FUNC_TRACE(); + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -EPERM; + + hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); + pci_dev = eth_dev->pci_dev; + + if (igb_adapter_stopped == 0) + eth_igb_close(eth_dev); + + eth_dev->dev_ops = NULL; + eth_dev->rx_pkt_burst = NULL; + eth_dev->tx_pkt_burst = NULL; + + for (i = 0; i < eth_dev->data->nb_rx_queues; i++) { + eth_igb_rx_queue_release(eth_dev->data->rx_queues[i]); + eth_dev->data->rx_queues[i] = NULL; + } + + for (i = 0; i < eth_dev->data->nb_tx_queues; i++) { + eth_igb_tx_queue_release(eth_dev->data->tx_queues[i]); + eth_dev->data->tx_queues[i] = NULL; + } + + /* Reset any pending lock */ + igb_reset_swfw_lock(hw); + + rte_free(eth_dev->data->mac_addrs); + eth_dev->data->mac_addrs = NULL; + + /* uninitialize PF if max_vfs not zero */ + igb_pf_host_uninit(eth_dev); + + /* disable uio intr before callback unregister */ + rte_intr_disable(&(pci_dev->intr_handle)); + rte_intr_callback_unregister(&(pci_dev->intr_handle), + eth_igb_interrupt_handler, (void *)eth_dev); + + return 0; +} + /* * Virtual Function device init */ @@ -639,6 +690,7 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev) hw->device_id = pci_dev->id.device_id; hw->vendor_id = pci_dev->id.vendor_id; hw->hw_addr = (void *)pci_dev->mem_resource[0].addr; + igb_adapter_stopped = 0; /* Initialize the shared code (base driver) */ diag = e1000_setup_init_funcs(hw, TRUE); @@ -679,13 +731,36 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev) return 0; } +static int +eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev) +{ + PMD_INIT_FUNC_TRACE(); + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -EPERM; + + if (igb_adapter_stopped == 0) + igbvf_dev_close(eth_dev); + + eth_dev->dev_ops = NULL; + eth_dev->rx_pkt_burst = NULL; + eth_dev->tx_pkt_burst = NULL; + + rte_free(eth_dev->data->mac_addrs); + eth_dev->data->mac_addrs = NULL; + + return 0; +} + static struct eth_driver rte_igb_pmd = { { .name = "rte_igb_pmd", .id_table = pci_id_igb_map, - .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC, + .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC | + RTE_PCI_DRV_DETACHABLE, }, .eth_dev_init = eth_igb_dev_init, + .eth_dev_uninit = eth_igb_dev_uninit, .dev_private_size = sizeof(struct e1000_adapter), }; @@ -696,9 +771,10 @@ static struct eth_driver rte_igbvf_pmd = { { .name = "rte_igbvf_pmd", .id_table = pci_id_igbvf_map, - .drv_flags = RTE_PCI_DRV_NEED_MAPPING, + .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE, }, .eth_dev_init = eth_igbvf_dev_init, + .eth_dev_uninit = eth_igbvf_dev_uninit, .dev_private_size = sizeof(struct e1000_adapter), }; @@ -780,6 +856,7 @@ eth_igb_start(struct rte_eth_dev *dev) PMD_INIT_LOG(ERR, "Unable to initialize the hardware"); return (-EIO); } + igb_adapter_stopped = 0; E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN); @@ -989,6 +1066,8 @@ eth_igb_close(struct rte_eth_dev *dev) struct rte_eth_link link; eth_igb_stop(dev); + igb_adapter_stopped = 1; + e1000_phy_hw_reset(hw); igb_release_manageability(hw); igb_hw_control_release(hw); @@ -2227,6 +2306,7 @@ igbvf_dev_start(struct rte_eth_dev *dev) PMD_INIT_FUNC_TRACE(); hw->mac.ops.reset_hw(hw); + igb_adapter_stopped = 0; /* Set all vfta */ igbvf_set_vfta_all(dev,1); @@ -2270,6 +2350,7 @@ igbvf_dev_close(struct rte_eth_dev *dev) e1000_reset_hw(hw); igbvf_dev_stop(dev); + igb_adapter_stopped = 1; } static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on) diff --git a/drivers/net/e1000/igb_pf.c b/drivers/net/e1000/igb_pf.c index 6a4d210..26c2960 100644 --- a/drivers/net/e1000/igb_pf.c +++ b/drivers/net/e1000/igb_pf.c @@ -127,6 +127,28 @@ void igb_pf_host_init(struct rte_eth_dev *eth_dev) return; } +void igb_pf_host_uninit(struct rte_eth_dev *dev) +{ + struct e1000_vf_info **vfinfo; + uint16_t vf_num; + + PMD_INIT_FUNC_TRACE(); + + vfinfo = E1000_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private); + + RTE_ETH_DEV_SRIOV(dev).active = 0; + RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 0; + RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx = 0; + RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx = 0; + + vf_num = dev_num_vf(dev); + if (vf_num == 0) + return; + + rte_free(*vfinfo); + *vfinfo = NULL; +} + #define E1000_RAH_POOLSEL_SHIFT (18) int igb_pf_host_configure(struct rte_eth_dev *eth_dev) {