[dpdk-dev] [PATCH v2 2/2] igb: VF supports mailbox interruption for PF link up/down

2016-06-13 Thread Wu, Jingjing


> -Original Message-
> From: Lu, Wenzhuo
> Sent: Wednesday, June 01, 2016 9:53 AM
> To: dev at dpdk.org
> Cc: Wu, Jingjing; Lu, Wenzhuo
> Subject: [PATCH v2 2/2] igb: VF supports mailbox interruption for PF link
> up/down
> 
> In this scenario, kernel PF + DPDK VF, when PF finds the link state changes,
> up -> down or down -> up, it will send a message to VF by mailbox. This link
> state change may be triggered by PHY disconnection/reconnection,
> configuration like *ifconfig down/up* or interface parameter, like MTU,
> change.
> This patch enables the support of the mailbox interruption, so VF can receive
> the message of link up/down.
> After VF receives this message, VF port need to be reset to recover. So the
> handler of this message registers a reset callback to let APP reset the VF 
> port.
> 
> Signed-off-by: Wenzhuo Lu 
Acked-by: Jingjing Wu 



[dpdk-dev] [PATCH v2 2/2] igb: VF supports mailbox interruption for PF link up/down

2016-06-01 Thread Wenzhuo Lu
In this scenario, kernel PF + DPDK VF, when PF finds the link
state changes, up -> down or down -> up, it will send a
message to VF by mailbox. This link state change may be
triggered by PHY disconnection/reconnection, configuration
like *ifconfig down/up* or interface parameter, like MTU,
change.
This patch enables the support of the mailbox interruption,
so VF can receive the message of link up/down.
After VF receives this message, VF port need to be reset to
recover. So the handler of this message registers a reset
callback to let APP reset the VF port.

Signed-off-by: Wenzhuo Lu 
---
 doc/guides/rel_notes/release_16_07.rst |   2 +-
 drivers/net/e1000/igb_ethdev.c | 159 +
 2 files changed, 160 insertions(+), 1 deletion(-)

diff --git a/doc/guides/rel_notes/release_16_07.rst 
b/doc/guides/rel_notes/release_16_07.rst
index 990bd46..a761e3c 100644
--- a/doc/guides/rel_notes/release_16_07.rst
+++ b/doc/guides/rel_notes/release_16_07.rst
@@ -47,7 +47,7 @@ New Features
   * Dropped specific Xen Dom0 code.
   * Dropped specific anonymous mempool code in testpmd.

-* **Added mailbox interruption support for ixgbe VF.**
+* **Added mailbox interruption support for ixgbe/igb VF.**

   When the link becomes down or up, PF will use mailbox message to notice
   VF. To handle this link up/down event, add the mailbox interruption
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index f0921ee..b0e5e6a 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -86,6 +86,12 @@
 #define E1000_INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
 #define E1000_TSAUXC_DISABLE_SYSTIME 0x8000

+#define E1000_VTIVAR_MISC0x01740
+#define E1000_VTIVAR_MISC_MASK   0xFF
+#define E1000_VTIVAR_VALID   0x80
+#define E1000_VTIVAR_MISC_MAILBOX0
+#define E1000_VTIVAR_MISC_INTR_MASK  0x3
+
 static int  eth_igb_configure(struct rte_eth_dev *dev);
 static int  eth_igb_start(struct rte_eth_dev *dev);
 static void eth_igb_stop(struct rte_eth_dev *dev);
@@ -259,6 +265,9 @@ static void eth_igb_assign_msix_vector(struct e1000_hw *hw, 
int8_t direction,
 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
   uint8_t index, uint8_t offset);
 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
+static void eth_igbvf_interrupt_handler(struct rte_intr_handle *handle,
+   void *param);
+static void igbvf_mbx_process(struct rte_eth_dev *dev);

 /*
  * Define VF Stats MACRO for Non "cleared on read" register
@@ -554,6 +563,41 @@ igb_intr_disable(struct e1000_hw *hw)
E1000_WRITE_FLUSH(hw);
 }

+static inline void
+igbvf_intr_enable(struct rte_eth_dev *dev)
+{
+   struct e1000_hw *hw =
+   E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+   /* only for mailbox */
+   E1000_WRITE_REG(hw, E1000_EIAM, 1 << E1000_VTIVAR_MISC_MAILBOX);
+   E1000_WRITE_REG(hw, E1000_EIAC, 1 << E1000_VTIVAR_MISC_MAILBOX);
+   E1000_WRITE_REG(hw, E1000_EIMS, 1 << E1000_VTIVAR_MISC_MAILBOX);
+   E1000_WRITE_FLUSH(hw);
+}
+
+/* only for mailbox now. If RX/TX needed, should extend this function.  */
+static void
+igbvf_set_ivar_map(struct e1000_hw *hw, uint8_t msix_vector)
+{
+   uint32_t tmp = 0;
+
+   /* mailbox */
+   tmp |= (msix_vector & E1000_VTIVAR_MISC_INTR_MASK);
+   tmp |= E1000_VTIVAR_VALID;
+   E1000_WRITE_REG(hw, E1000_VTIVAR_MISC, tmp);
+}
+
+static void
+eth_igbvf_configure_msix_intr(struct rte_eth_dev *dev)
+{
+   struct e1000_hw *hw =
+   E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+   /* Configure VF other cause ivar */
+   igbvf_set_ivar_map(hw, E1000_VTIVAR_MISC_MAILBOX);
+}
+
 static inline int32_t
 igb_pf_reset_hw(struct e1000_hw *hw)
 {
@@ -942,6 +986,10 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 eth_dev->data->port_id, pci_dev->id.vendor_id,
 pci_dev->id.device_id, "igb_mac_82576_vf");

+   rte_intr_callback_register(_dev->intr_handle,
+  eth_igbvf_interrupt_handler,
+  (void *)eth_dev);
+
return 0;
 }

@@ -950,6 +998,7 @@ eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
struct e1000_adapter *adapter =
E1000_DEV_PRIVATE(eth_dev->data->dev_private);
+   struct rte_pci_device *pci_dev = eth_dev->pci_dev;

PMD_INIT_FUNC_TRACE();

@@ -966,6 +1015,12 @@ eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
rte_free(eth_dev->data->mac_addrs);
eth_dev->data->mac_addrs = NULL;

+   /* disable uio intr before callback unregister */
+   rte_intr_disable(_dev->intr_handle);
+   rte_intr_callback_unregister(_dev->intr_handle,
+eth_igbvf_interrupt_handler,
+(void *)eth_dev);
+