dpdk: use flags for identifying interface types

This will allow us to handle some more complex situations
like in case when hqos needs to be enabled only for some PMDs.

Change-Id: I5421a8d4cf29b8394b9e956cc4e39737dd07dbbb
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/vnet/vnet/devices/dpdk/cli.c b/vnet/vnet/devices/dpdk/cli.c
index f257a8b..2ffb958 100644
--- a/vnet/vnet/devices/dpdk/cli.c
+++ b/vnet/vnet/devices/dpdk/cli.c
@@ -713,7 +713,7 @@
   hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
   xd = vec_elt_at_index (dm->devices, hw->dev_instance);
 
-  if (xd->dev_type != VNET_DPDK_DEV_ETH)
+  if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
     return clib_error_return (0, "number of descriptors can be set only for "
 			      "physical devices");
 
diff --git a/vnet/vnet/devices/dpdk/device.c b/vnet/vnet/devices/dpdk/device.c
index 2ccfcda..be54bd2 100644
--- a/vnet/vnet/devices/dpdk/device.c
+++ b/vnet/vnet/devices/dpdk/device.c
@@ -323,7 +323,7 @@
        * This device only supports one TX queue,
        * and we're running multi-threaded...
        */
-      if (PREDICT_FALSE (xd->dev_type != VNET_DPDK_DEV_VHOST_USER &&
+      if (PREDICT_FALSE ((xd->flags & DPDK_DEVICE_FLAG_VHOST_USER) == 0 &&
 			 xd->lockp != 0))
 	{
 	  queue_id = queue_id % xd->tx_q_used;
@@ -332,7 +332,7 @@
 	    queue_id = (queue_id + 1) % xd->tx_q_used;
 	}
 
-      if (PREDICT_TRUE (xd->dev_type == VNET_DPDK_DEV_ETH))
+      if (PREDICT_TRUE (xd->flags & DPDK_DEVICE_FLAG_PMD))
 	{
 	  if (PREDICT_TRUE (tx_head > tx_tail))
 	    {
@@ -366,7 +366,7 @@
 	    }
 	}
 #if DPDK_VHOST_USER
-      else if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
+      else if (xd->flags & DPDK_DEVICE_FLAG_VHOST_USER)
 	{
 	  u32 offset = 0;
 	  if (xd->need_txlock)
@@ -484,7 +484,7 @@
 	}
 #endif
 #if RTE_LIBRTE_KNI
-      else if (xd->dev_type == VNET_DPDK_DEV_KNI)
+      else if (xd->flags & DPDK_DEVICE_FLAG_KNI)
 	{
 	  if (PREDICT_TRUE (tx_head > tx_tail))
 	    {
@@ -522,7 +522,7 @@
 	  rv = 0;
 	}
 
-      if (PREDICT_FALSE (xd->dev_type != VNET_DPDK_DEV_VHOST_USER &&
+      if (PREDICT_FALSE ((xd->flags & DPDK_DEVICE_FLAG_VHOST_USER) == 0 &&
 			 xd->lockp != 0))
 	*xd->lockp[queue_id] = 0;
 
@@ -919,7 +919,7 @@
   dpdk_main_t *dm = &dpdk_main;
   dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
 
-  if (!xd || xd->dev_type != VNET_DPDK_DEV_VHOST_USER)
+  if (!xd || (xd->flags & DPDK_DEVICE_FLAG_VHOST_USER) == 0)
     {
       clib_warning
 	("cannot renumber non-vhost-user interface (sw_if_index: %d)",
@@ -950,7 +950,7 @@
 	       sizeof (xd->last_cleared_xstats[0]));
 
 #if DPDK_VHOST_USER
-  if (PREDICT_FALSE (xd->dev_type == VNET_DPDK_DEV_VHOST_USER))
+  if (PREDICT_FALSE (xd->flags & DPDK_DEVICE_FLAG_VHOST_USER))
     {
       int i;
       for (i = 0; i < xd->rx_q_used * VIRTIO_QNUM; i++)
@@ -1025,7 +1025,7 @@
   int rv = 0;
 
 #ifdef RTE_LIBRTE_KNI
-  if (xd->dev_type == VNET_DPDK_DEV_KNI)
+  if (xd->flags & DPDK_DEVICE_FLAG_KNI)
     {
       if (is_up)
 	{
@@ -1066,7 +1066,7 @@
     }
 #endif
 #if DPDK_VHOST_USER
-  if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
+  if (xd->flags & DPDK_DEVICE_FLAG_VHOST_USER)
     {
       if (is_up)
 	{
@@ -1172,7 +1172,7 @@
   else if (xd->vlan_subifs)
     xd->vlan_subifs--;
 
-  if (xd->dev_type != VNET_DPDK_DEV_ETH)
+  if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
     return 0;
 
   /* currently we program VLANS only for IXGBE VF and I40E VF */
diff --git a/vnet/vnet/devices/dpdk/dpdk.h b/vnet/vnet/devices/dpdk/dpdk.h
index e7c177b..025ebf4 100644
--- a/vnet/vnet/devices/dpdk/dpdk.h
+++ b/vnet/vnet/devices/dpdk/dpdk.h
@@ -75,14 +75,6 @@
 extern vlib_node_registration_t dpdk_input_node;
 extern vlib_node_registration_t handoff_dispatch_node;
 
-typedef enum
-{
-  VNET_DPDK_DEV_ETH = 1,	/* Standard DPDK PMD driver */
-  VNET_DPDK_DEV_KNI,		/* Kernel NIC Interface */
-  VNET_DPDK_DEV_VHOST_USER,
-  VNET_DPDK_DEV_UNKNOWN,	/* must be last */
-} dpdk_device_type_t;
-
 #define foreach_dpdk_pmd          \
   _ ("rte_nicvf_pmd", THUNDERX)	  \
   _ ("rte_em_pmd", E1000EM)       \
@@ -214,13 +206,15 @@
   /* number of sub-interfaces */
   u16 vlan_subifs;
 
-  dpdk_device_type_t dev_type:8;
   dpdk_pmd_t pmd:8;
   i8 cpu_socket;
 
   u16 flags;
-#define DPDK_DEVICE_FLAG_ADMIN_UP (1 << 0)
-#define DPDK_DEVICE_FLAG_PROMISC  (1 << 1)
+#define DPDK_DEVICE_FLAG_ADMIN_UP       (1 << 0)
+#define DPDK_DEVICE_FLAG_PROMISC        (1 << 1)
+#define DPDK_DEVICE_FLAG_PMD            (1 << 2)
+#define DPDK_DEVICE_FLAG_KNI            (1 << 3)
+#define DPDK_DEVICE_FLAG_VHOST_USER     (1 << 4)
 
     CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
 
diff --git a/vnet/vnet/devices/dpdk/dpdk_priv.h b/vnet/vnet/devices/dpdk/dpdk_priv.h
index 0abe630..fd4f2d7 100644
--- a/vnet/vnet/devices/dpdk/dpdk_priv.h
+++ b/vnet/vnet/devices/dpdk/dpdk_priv.h
@@ -88,7 +88,7 @@
   u64 rxerrors, last_rxerrors;
 
   /* only update counters for PMD interfaces */
-  if (xd->dev_type != VNET_DPDK_DEV_ETH)
+  if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
     return;
 
   xd->time_last_stats_update = now ? now : xd->time_last_stats_update;
diff --git a/vnet/vnet/devices/dpdk/format.c b/vnet/vnet/devices/dpdk/format.c
index 1f401a9..ef7ee0e 100644
--- a/vnet/vnet/devices/dpdk/format.c
+++ b/vnet/vnet/devices/dpdk/format.c
@@ -166,14 +166,14 @@
     devname_format = "%s%x/%x/%x";
 
 #ifdef RTE_LIBRTE_KNI
-  if (dm->devices[i].dev_type == VNET_DPDK_DEV_KNI)
+  if (dm->devices[i].flags & DPDK_DEVICE_FLAG_KNI)
     {
       return format (s, "kni%d", dm->devices[i].kni_port_id);
     }
   else
 #endif
 #if DPDK_VHOST_USER
-  if (dm->devices[i].dev_type == VNET_DPDK_DEV_VHOST_USER)
+  if (dm->devices[i].flags & DPDK_DEVICE_FLAG_VHOST_USER)
     {
       return format (s, "VirtualEthernet0/0/%d", dm->devices[i].vu_if_id);
     }
@@ -226,11 +226,11 @@
   char *dev_type;
   u32 i = va_arg (*args, u32);
 
-  if (dm->devices[i].dev_type == VNET_DPDK_DEV_KNI)
+  if (dm->devices[i].flags & DPDK_DEVICE_FLAG_KNI)
     {
       return format (s, "Kernel NIC Interface");
     }
-  else if (dm->devices[i].dev_type == VNET_DPDK_DEV_VHOST_USER)
+  else if (dm->devices[i].flags & DPDK_DEVICE_FLAG_VHOST_USER)
     {
       return format (s, "vhost-user interface");
     }
@@ -401,7 +401,7 @@
 
   rte_eth_dev_info_get (xd->device_index, &di);
 
-  if (verbose > 1 && xd->dev_type == VNET_DPDK_DEV_ETH)
+  if (verbose > 1 && xd->flags & DPDK_DEVICE_FLAG_PMD)
     {
       struct rte_pci_device *pci;
       struct rte_eth_rss_conf rss_conf;
@@ -455,7 +455,7 @@
 		  format_dpdk_rss_hf_name, di.flow_type_rss_offloads);
     }
 
-  if (verbose && xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
+  if (verbose && xd->flags & DPDK_DEVICE_FLAG_VHOST_USER)
     {
       s = format (s, "%Uqueue size (max):  rx %d (%d) tx %d (%d)\n",
 		  format_white_space, indent + 2,
@@ -527,7 +527,7 @@
 #endif
 
 #if DPDK_VHOST_USER
-  if (verbose && xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
+  if (verbose && xd->flags & DPDK_DEVICE_FLAG_VHOST_USER)
     {
       int i;
       for (i = 0; i < xd->rx_q_used * VIRTIO_QNUM; i++)
diff --git a/vnet/vnet/devices/dpdk/init.c b/vnet/vnet/devices/dpdk/init.c
index 7b65720..a2cc884 100644
--- a/vnet/vnet/devices/dpdk/init.c
+++ b/vnet/vnet/devices/dpdk/init.c
@@ -405,7 +405,7 @@
       else
 	xd->rx_q_used = 1;
 
-      xd->dev_type = VNET_DPDK_DEV_ETH;
+      xd->flags |= DPDK_DEVICE_FLAG_PMD;
 
       /* workaround for drivers not setting driver_name */
       if ((!dev_info.driver_name) && (dev_info.pci_dev))
@@ -755,7 +755,7 @@
 
 	  /* Create vnet interface */
 	  vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
-	  xd->dev_type = VNET_DPDK_DEV_KNI;
+	  xd->flags |= DPDK_DEVICE_FLAG_KNI;
 
 	  xd->device_index = xd - dm->devices;
 	  ASSERT (nports + i == xd->device_index);
@@ -1458,7 +1458,7 @@
   u8 hw_flags_chg = 0;
 
   /* only update link state for PMD interfaces */
-  if (xd->dev_type != VNET_DPDK_DEV_ETH)
+  if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
     return;
 
   xd->time_last_link_update = now ? now : xd->time_last_link_update;
@@ -1757,7 +1757,7 @@
 	  dpdk_update_link_state (xd, now);
 
 #if DPDK_VHOST_USER
-	if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
+	if (xd->flags & DPDK_DEVICE_FLAG_VHOST_USER)
 	  if (dpdk_vhost_user_process_if (vm, xd, vu_state) != 0)
 	    continue;
 #endif
diff --git a/vnet/vnet/devices/dpdk/node.c b/vnet/vnet/devices/dpdk/node.c
index 54a6a50..5852b3d 100644
--- a/vnet/vnet/devices/dpdk/node.c
+++ b/vnet/vnet/devices/dpdk/node.c
@@ -287,7 +287,7 @@
   n_left = VLIB_FRAME_SIZE;
   n_buffers = 0;
 
-  if (PREDICT_TRUE (xd->dev_type == VNET_DPDK_DEV_ETH))
+  if (PREDICT_TRUE (xd->flags & DPDK_DEVICE_FLAG_PMD))
     {
       while (n_left)
 	{
@@ -303,7 +303,7 @@
 	}
     }
 #if DPDK_VHOST_USER
-  else if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
+  else if (xd->flags & DPDK_DEVICE_FLAG_VHOST_USER)
     {
       vlib_main_t *vm = vlib_get_main ();
       vlib_buffer_main_t *bm = vm->buffer_main;
@@ -367,7 +367,7 @@
     }
 #endif
 #ifdef RTE_LIBRTE_KNI
-  else if (xd->dev_type == VNET_DPDK_DEV_KNI)
+  else if (xd->flags & DPDK_DEVICE_FLAG_KNI)
     {
       n_buffers =
 	rte_kni_rx_burst (xd->kni, xd->rx_vectors[queue_id], VLIB_FRAME_SIZE);
diff --git a/vnet/vnet/devices/dpdk/vhost_user.c b/vnet/vnet/devices/dpdk/vhost_user.c
index 58cff7b..f8910ad 100644
--- a/vnet/vnet/devices/dpdk/vhost_user.c
+++ b/vnet/vnet/devices/dpdk/vhost_user.c
@@ -137,7 +137,7 @@
   vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
   dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
 
-  if (xd->dev_type != VNET_DPDK_DEV_VHOST_USER)
+  if ((xd->flags DPDK_DEVICE_FLAG_VHOST_USER) == 0)
     return 0;
 
   return xd;
@@ -221,7 +221,7 @@
       if (vec_len (dm->devices) > vui_idx)
 	{
 	  xd = vec_elt_at_index (dm->devices, vui_idx);
-	  if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
+	  if (xd->flags & DPDK_DEVICE_FLAG_VHOST_USER)
 	    {
 	      DBG_SOCK
 		("reusing inactive vhost-user interface sw_if_index %d",
@@ -283,7 +283,7 @@
     {
       // vui was not retrieved from inactive ifaces - create new
       vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
-      xd->dev_type = VNET_DPDK_DEV_VHOST_USER;
+      xd->flags |= DPDK_DEVICE_FLAG_VHOST_USER;
       xd->rx_q_used = num_qpairs;
       xd->tx_q_used = num_qpairs;
       xd->vu_vhost_dev.virt_qp_nb = num_qpairs;
@@ -1661,7 +1661,7 @@
 
   vec_foreach (xd, dm->devices)
   {
-    if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER && xd->vu_intf->active)
+    if ((xd->flags & DPDK_DEVICE_FLAG_VHOST_USER) && xd->vu_intf->active)
       vec_add1 (hw_if_indices, xd->vlib_hw_if_index);
   }
 
@@ -1988,7 +1988,7 @@
     {
       vec_foreach (xd, dm->devices)
       {
-	if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER && xd->vu_intf->active)
+	if ((xd->flags DPDK_DEVICE_FLAG_VHOST_USER) && xd->vu_intf->active)
 	  vec_add1 (hw_if_indices, xd->vlib_hw_if_index);
       }
     }