[dpdk-dev,RFC] librte_pmd_fm10k: Add hotplug support for fm10k

Message ID 8CEF83825BEC744B83065625E567D7C204A2C707@IRSMSX108.ger.corp.intel.com (mailing list archive)
State Not Applicable, archived
Headers

Commit Message

Iremonger, Bernard June 2, 2015, 8:26 a.m. UTC
  -----Original Message-----
From: Qiu, Michael 
Sent: Sunday, May 31, 2015 3:37 PM
To: dev@dpdk.org
Cc: Chen, Jing D; Iremonger, Bernard; He, Shaopeng; Qiu, Michael
Subject: [RFC PATCH] librte_pmd_fm10k: Add hotplug support for fm10k

Add hotplug support for fm10k

Signed-off-by: Michael Qiu <michael.qiu@intel.com>
---
 lib/librte_pmd_fm10k/fm10k_ethdev.c | 134 ++++++++++++++++++++++++++++++++++--
 1 file changed, 129 insertions(+), 5 deletions(-)

Hi Michael,

The location of the fm10k  pmd has changed to  drivers/net/fm10k.
lib/librte_pmd_fm10k  no longer exists.
You will need to rebase to use the new directory structure.

Regards,

Bernard.
 

 	PMD_INIT_FUNC_TRACE();
 
-	for (i = 0; i < dev->data->nb_tx_queues; i++)
-		fm10k_dev_tx_queue_stop(dev, i);
+	if (dev->data->tx_queues)
+		for (i = 0; i < dev->data->nb_tx_queues; i++)
+			fm10k_dev_tx_queue_stop(dev, i);
 
-	for (i = 0; i < dev->data->nb_rx_queues; i++)
-		fm10k_dev_rx_queue_stop(dev, i);
+	if (dev->data->rx_queues)
+		for (i = 0; i < dev->data->nb_rx_queues; i++)
+			fm10k_dev_rx_queue_stop(dev, i);
+}
+
+static void
+fm10k_dev_queue_release(__rte_unused struct rte_eth_dev *dev) {
+	int i;
+
+	PMD_INIT_FUNC_TRACE();
+
+	if (dev->data->tx_queues) {
+		for (i = 0; i < dev->data->nb_tx_queues; i++)
+			fm10k_tx_queue_release(dev->data->tx_queues[i]);
+		rte_free(dev->data->tx_queues);
+		dev->data->tx_queues = NULL;
+	}
+
+	if (dev->data->rx_queues) {
+		for (i = 0; i < dev->data->nb_rx_queues; i++)
+			fm10k_rx_queue_release(dev->data->rx_queues[i]);
+		rte_free(dev->data->rx_queues);
+		dev->data->rx_queues = NULL;
+	}
 }
 
 static void
@@ -705,6 +733,7 @@ fm10k_dev_close(struct rte_eth_dev *dev)
 	/* Stop mailbox service first */
 	fm10k_close_mbx_service(hw);
 	fm10k_dev_stop(dev);
+	fm10k_dev_queue_release(dev);
 	fm10k_stop_hw(hw);
 }
 
@@ -1406,6 +1435,36 @@ fm10k_dev_enable_intr_pf(struct rte_eth_dev *dev)  }
 
 static void
+fm10k_dev_disable_intr_pf(struct rte_eth_dev *dev) {
+	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	uint32_t int_map = FM10K_INT_MAP_DISABLE;
+
+	int_map |= 0;
+
+	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_Mailbox), int_map);
+	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_PCIeFault), int_map);
+	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_SwitchUpDown), int_map);
+	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_SwitchEvent), int_map);
+	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_SRAM), int_map);
+	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_VFLR), int_map);
+
+	/* Disable misc causes */
+	FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(PCA_FAULT) |
+				FM10K_EIMR_DISABLE(THI_FAULT) |
+				FM10K_EIMR_DISABLE(FUM_FAULT) |
+				FM10K_EIMR_DISABLE(MAILBOX) |
+				FM10K_EIMR_DISABLE(SWITCHREADY) |
+				FM10K_EIMR_DISABLE(SWITCHNOTREADY) |
+				FM10K_EIMR_DISABLE(SRAMERROR) |
+				FM10K_EIMR_DISABLE(VFLR));
+
+	/* Disable ITR 0 */
+	FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_MASK_SET);
+	FM10K_WRITE_FLUSH(hw);
+}
+
+static void
 fm10k_dev_enable_intr_vf(struct rte_eth_dev *dev)  {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -1423,6 +1482,22 @@ fm10k_dev_enable_intr_vf(struct rte_eth_dev *dev)
 	FM10K_WRITE_FLUSH(hw);
 }
 
+static void
+fm10k_dev_disable_intr_vf(struct rte_eth_dev *dev) {
+	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	uint32_t int_map = FM10K_INT_MAP_DISABLE;
+
+	int_map |= 0;
+
+	/* Only INT 0 available, other 15 are reserved. */
+	FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
+
+	/* Disable ITR 0 */
+	FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_MASK_SET);
+	FM10K_WRITE_FLUSH(hw);
+}
+
 static int
 fm10k_dev_handle_fault(struct fm10k_hw *hw, uint32_t eicr)  { @@ -1868,6 +1943,54 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static int
+eth_fm10k_dev_uninit(struct rte_eth_dev *dev) {
+	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	PMD_INIT_FUNC_TRACE();
+
+	/* only uninitialize in the primary process */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return 0;
+
+	/* safe to close dev here */
+	fm10k_dev_close(dev);
+
+	dev->dev_ops = NULL;
+	dev->rx_pkt_burst = NULL;
+	dev->tx_pkt_burst = NULL;
+
+	/* disable uio/vfio intr */
+	rte_intr_disable(&(dev->pci_dev->intr_handle));
+
+	/*PF/VF has different interrupt handling mechanism */
+	if (hw->mac.type == fm10k_mac_pf) {
+		/* disable interrupt */
+		fm10k_dev_disable_intr_pf(dev);
+
+		/* unregister callback func to eal lib */
+		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+			fm10k_dev_interrupt_handler_pf, (void *)dev);
+	} else {
+		/* disable interrupt */
+		fm10k_dev_disable_intr_vf(dev);
+
+		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+			fm10k_dev_interrupt_handler_vf, (void *)dev);
+	}
+
+	/* free mac memory */
+	if (dev->data->mac_addrs) {
+		rte_free(dev->data->mac_addrs);
+		dev->data->mac_addrs = NULL;
+	}
+
+	memset(hw, 0, sizeof(*hw));
+
+	return 0;
+}
+
 /*
  * The set of PCI devices this driver supports. This driver will enable both PF
  * and SRIOV-VF devices.
@@ -1883,9 +2006,10 @@ static struct eth_driver rte_pmd_fm10k = {
 	{
 		.name = "rte_pmd_fm10k",
 		.id_table = pci_id_fm10k_map,
-		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
 	},
 	.eth_dev_init = eth_fm10k_dev_init,
+	.eth_dev_uninit = eth_fm10k_dev_uninit,
 	.dev_private_size = sizeof(struct fm10k_adapter),  };
 
--
1.9.3
  

Comments

Michael Qiu June 2, 2015, 9:36 a.m. UTC | #1
On 6/2/2015 4:26 PM, Iremonger, Bernard wrote:
>
> -----Original Message-----
> From: Qiu, Michael 
> Sent: Sunday, May 31, 2015 3:37 PM
> To: dev@dpdk.org
> Cc: Chen, Jing D; Iremonger, Bernard; He, Shaopeng; Qiu, Michael
> Subject: [RFC PATCH] librte_pmd_fm10k: Add hotplug support for fm10k
>
> Add hotplug support for fm10k
>
> Signed-off-by: Michael Qiu <michael.qiu@intel.com>
> ---
>  lib/librte_pmd_fm10k/fm10k_ethdev.c | 134 ++++++++++++++++++++++++++++++++++--
>  1 file changed, 129 insertions(+), 5 deletions(-)
>
> Hi Michael,
>
> The location of the fm10k  pmd has changed to  drivers/net/fm10k.
> lib/librte_pmd_fm10k  no longer exists.
> You will need to rebase to use the new directory structure.

OK, got it, I will rebase it,

Thanks,
Michael
> Regards,
>
> Bernard.
>  
>
> diff --git a/lib/librte_pmd_fm10k/fm10k_ethdev.c b/lib/librte_pmd_fm10k/fm10k_ethdev.c
> index 7f5f513..3d72607 100644
> --- a/lib/librte_pmd_fm10k/fm10k_ethdev.c
> +++ b/lib/librte_pmd_fm10k/fm10k_ethdev.c
> @@ -55,6 +55,10 @@
>  
>  static void fm10k_close_mbx_service(struct fm10k_hw *hw);
>  
> +static void fm10k_tx_queue_release(void *queue);
> +
> +static void fm10k_rx_queue_release(void *queue);
> +
>  static void
>  fm10k_mbx_initlock(struct fm10k_hw *hw)  { @@ -688,11 +692,35 @@ fm10k_dev_stop(struct rte_eth_dev *dev)
>  
>  	PMD_INIT_FUNC_TRACE();
>  
> -	for (i = 0; i < dev->data->nb_tx_queues; i++)
> -		fm10k_dev_tx_queue_stop(dev, i);
> +	if (dev->data->tx_queues)
> +		for (i = 0; i < dev->data->nb_tx_queues; i++)
> +			fm10k_dev_tx_queue_stop(dev, i);
>  
> -	for (i = 0; i < dev->data->nb_rx_queues; i++)
> -		fm10k_dev_rx_queue_stop(dev, i);
> +	if (dev->data->rx_queues)
> +		for (i = 0; i < dev->data->nb_rx_queues; i++)
> +			fm10k_dev_rx_queue_stop(dev, i);
> +}
> +
> +static void
> +fm10k_dev_queue_release(__rte_unused struct rte_eth_dev *dev) {
> +	int i;
> +
> +	PMD_INIT_FUNC_TRACE();
> +
> +	if (dev->data->tx_queues) {
> +		for (i = 0; i < dev->data->nb_tx_queues; i++)
> +			fm10k_tx_queue_release(dev->data->tx_queues[i]);
> +		rte_free(dev->data->tx_queues);
> +		dev->data->tx_queues = NULL;
> +	}
> +
> +	if (dev->data->rx_queues) {
> +		for (i = 0; i < dev->data->nb_rx_queues; i++)
> +			fm10k_rx_queue_release(dev->data->rx_queues[i]);
> +		rte_free(dev->data->rx_queues);
> +		dev->data->rx_queues = NULL;
> +	}
>  }
>  
>  static void
> @@ -705,6 +733,7 @@ fm10k_dev_close(struct rte_eth_dev *dev)
>  	/* Stop mailbox service first */
>  	fm10k_close_mbx_service(hw);
>  	fm10k_dev_stop(dev);
> +	fm10k_dev_queue_release(dev);
>  	fm10k_stop_hw(hw);
>  }
>  
> @@ -1406,6 +1435,36 @@ fm10k_dev_enable_intr_pf(struct rte_eth_dev *dev)  }
>  
>  static void
> +fm10k_dev_disable_intr_pf(struct rte_eth_dev *dev) {
> +	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> +	uint32_t int_map = FM10K_INT_MAP_DISABLE;
> +
> +	int_map |= 0;
> +
> +	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_Mailbox), int_map);
> +	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_PCIeFault), int_map);
> +	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_SwitchUpDown), int_map);
> +	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_SwitchEvent), int_map);
> +	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_SRAM), int_map);
> +	FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_VFLR), int_map);
> +
> +	/* Disable misc causes */
> +	FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(PCA_FAULT) |
> +				FM10K_EIMR_DISABLE(THI_FAULT) |
> +				FM10K_EIMR_DISABLE(FUM_FAULT) |
> +				FM10K_EIMR_DISABLE(MAILBOX) |
> +				FM10K_EIMR_DISABLE(SWITCHREADY) |
> +				FM10K_EIMR_DISABLE(SWITCHNOTREADY) |
> +				FM10K_EIMR_DISABLE(SRAMERROR) |
> +				FM10K_EIMR_DISABLE(VFLR));
> +
> +	/* Disable ITR 0 */
> +	FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_MASK_SET);
> +	FM10K_WRITE_FLUSH(hw);
> +}
> +
> +static void
>  fm10k_dev_enable_intr_vf(struct rte_eth_dev *dev)  {
>  	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> @@ -1423,6 +1482,22 @@ fm10k_dev_enable_intr_vf(struct rte_eth_dev *dev)
>  	FM10K_WRITE_FLUSH(hw);
>  }
>  
> +static void
> +fm10k_dev_disable_intr_vf(struct rte_eth_dev *dev) {
> +	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> +	uint32_t int_map = FM10K_INT_MAP_DISABLE;
> +
> +	int_map |= 0;
> +
> +	/* Only INT 0 available, other 15 are reserved. */
> +	FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
> +
> +	/* Disable ITR 0 */
> +	FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_MASK_SET);
> +	FM10K_WRITE_FLUSH(hw);
> +}
> +
>  static int
>  fm10k_dev_handle_fault(struct fm10k_hw *hw, uint32_t eicr)  { @@ -1868,6 +1943,54 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)
>  	return 0;
>  }
>  
> +static int
> +eth_fm10k_dev_uninit(struct rte_eth_dev *dev) {
> +	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> +
> +	PMD_INIT_FUNC_TRACE();
> +
> +	/* only uninitialize in the primary process */
> +	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> +		return 0;
> +
> +	/* safe to close dev here */
> +	fm10k_dev_close(dev);
> +
> +	dev->dev_ops = NULL;
> +	dev->rx_pkt_burst = NULL;
> +	dev->tx_pkt_burst = NULL;
> +
> +	/* disable uio/vfio intr */
> +	rte_intr_disable(&(dev->pci_dev->intr_handle));
> +
> +	/*PF/VF has different interrupt handling mechanism */
> +	if (hw->mac.type == fm10k_mac_pf) {
> +		/* disable interrupt */
> +		fm10k_dev_disable_intr_pf(dev);
> +
> +		/* unregister callback func to eal lib */
> +		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
> +			fm10k_dev_interrupt_handler_pf, (void *)dev);
> +	} else {
> +		/* disable interrupt */
> +		fm10k_dev_disable_intr_vf(dev);
> +
> +		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
> +			fm10k_dev_interrupt_handler_vf, (void *)dev);
> +	}
> +
> +	/* free mac memory */
> +	if (dev->data->mac_addrs) {
> +		rte_free(dev->data->mac_addrs);
> +		dev->data->mac_addrs = NULL;
> +	}
> +
> +	memset(hw, 0, sizeof(*hw));
> +
> +	return 0;
> +}
> +
>  /*
>   * The set of PCI devices this driver supports. This driver will enable both PF
>   * and SRIOV-VF devices.
> @@ -1883,9 +2006,10 @@ static struct eth_driver rte_pmd_fm10k = {
>  	{
>  		.name = "rte_pmd_fm10k",
>  		.id_table = pci_id_fm10k_map,
> -		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
> +		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
>  	},
>  	.eth_dev_init = eth_fm10k_dev_init,
> +	.eth_dev_uninit = eth_fm10k_dev_uninit,
>  	.dev_private_size = sizeof(struct fm10k_adapter),  };
>  
> --
> 1.9.3
>
>
  

Patch

diff --git a/lib/librte_pmd_fm10k/fm10k_ethdev.c b/lib/librte_pmd_fm10k/fm10k_ethdev.c
index 7f5f513..3d72607 100644
--- a/lib/librte_pmd_fm10k/fm10k_ethdev.c
+++ b/lib/librte_pmd_fm10k/fm10k_ethdev.c
@@ -55,6 +55,10 @@ 
 
 static void fm10k_close_mbx_service(struct fm10k_hw *hw);
 
+static void fm10k_tx_queue_release(void *queue);
+
+static void fm10k_rx_queue_release(void *queue);
+
 static void
 fm10k_mbx_initlock(struct fm10k_hw *hw)  { @@ -688,11 +692,35 @@ fm10k_dev_stop(struct rte_eth_dev *dev)