Fix coverity issues in DPDK code, fixes VPP-189
[vpp.git] / vnet / vnet / devices / dpdk / dpdk_priv.h
index 54d3803..d4d1422 100644 (file)
 #define DPDK_NB_TX_DESC_DEFAULT   512
 #define DPDK_NB_RX_DESC_VIRTIO    256
 #define DPDK_NB_TX_DESC_VIRTIO    256
-#define DPDK_NB_RX_DESC_10GE    2048
-#define DPDK_NB_TX_DESC_10GE    2048
-#define DPDK_NB_RX_DESC_40GE    (4096-128)
-#define DPDK_NB_TX_DESC_40GE    2048
+#define DPDK_NB_RX_DESC_10GE    1024
+#define DPDK_NB_TX_DESC_10GE    1024
+#define DPDK_NB_RX_DESC_40GE    1024
+#define DPDK_NB_TX_DESC_40GE    1024
+#define DPDK_NB_RX_DESC_ENIC    1024
+
+#if RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 0)
+#define I40E_DEV_ID_SFP_XL710           0x1572
+#define I40E_DEV_ID_QSFP_A              0x1583
+#define I40E_DEV_ID_QSFP_B              0x1584
+#define I40E_DEV_ID_QSFP_C              0x1585
+#define I40E_DEV_ID_10G_BASE_T          0x1586
+#define I40E_DEV_ID_VF                  0x154C
+#endif
 
 /* These args appear by themselves */
 #define foreach_eal_double_hyphen_predicate_arg \
 _(no-shconf)                                    \
 _(no-hpet)                                      \
-_(no-pci)                                       \
 _(no-huge)                                      \
 _(vmware-tsc-map)                               \
 _(virtio-vhost)
@@ -71,6 +80,7 @@ dpdk_rx_burst ( dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
             break;
       }
     }
+#if DPDK_VHOST_USER
   else if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
     {
       vlib_main_t * vm = vlib_get_main();
@@ -78,7 +88,6 @@ dpdk_rx_burst ( dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
       unsigned socket_id = rte_socket_id();
       u32 offset = 0;
 
-#if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
       offset = queue_id * VIRTIO_QNUM;
 
       struct vhost_virtqueue *vq =
@@ -86,17 +95,21 @@ dpdk_rx_burst ( dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
 
       if (PREDICT_FALSE(!vq->enabled))
         return 0;
-#else
-      if (PREDICT_FALSE(!xd->vu_is_running))
-        return 0;
-#endif
 
-      n_buffers = rte_vhost_dequeue_burst(&xd->vu_vhost_dev, offset + VIRTIO_TXQ,
-                                          bm->pktmbuf_pools[socket_id],
-                                          xd->rx_vectors[queue_id], VLIB_FRAME_SIZE);
+      struct rte_mbuf **pkts = xd->rx_vectors[queue_id];
+      while (n_left) {
+          n_this_chunk = rte_vhost_dequeue_burst(&xd->vu_vhost_dev,
+                                                 offset + VIRTIO_TXQ,
+                                                 bm->pktmbuf_pools[socket_id],
+                                                 pkts + n_buffers,
+                                                 n_left);
+          n_buffers += n_this_chunk;
+          n_left -= n_this_chunk;
+          if (n_this_chunk == 0)
+              break;
+      }
 
       int i; u32 bytes = 0;
-      struct rte_mbuf **pkts = xd->rx_vectors[queue_id];
       for (i = 0; i < n_buffers; i++) {
           struct rte_mbuf *buff = pkts[i];
           bytes += rte_pktmbuf_data_len(buff);
@@ -111,7 +124,7 @@ dpdk_rx_burst ( dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
           vring->n_since_last_int += n_buffers;
 
           if ((vring->n_since_last_int && (vring->int_deadline < now))
-              || (vring->n_since_last_int > dm->vhost_coalesce_frames))
+              || (vring->n_since_last_int > dm->conf->vhost_coalesce_frames))
             dpdk_vhost_user_send_interrupt(vm, xd, offset + VIRTIO_TXQ);
       }
 
@@ -125,6 +138,7 @@ dpdk_rx_burst ( dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
       }
 
     }
+#endif
 #ifdef RTE_LIBRTE_KNI
   else if (xd->dev_type == VNET_DPDK_DEV_KNI)
     {
@@ -183,7 +197,7 @@ dpdk_update_counters (dpdk_device_t * xd, f64 now)
   if (xd->admin_up != 0xff)
     {
       xd->time_last_stats_update = now ? now : xd->time_last_stats_update;
-      memcpy (&xd->last_stats, &xd->stats, sizeof (xd->last_stats));
+      clib_memcpy (&xd->last_stats, &xd->stats, sizeof (xd->last_stats));
       rte_eth_stats_get (xd->device_index, &xd->stats);
 
       /* maybe bump interface rx no buffer counter */
@@ -207,15 +221,8 @@ dpdk_update_counters (dpdk_device_t * xd, f64 now)
                                          xd->stats.imissed -
                                          xd->last_stats.imissed);
         }
-#if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
       rxerrors = xd->stats.ierrors;
       last_rxerrors = xd->last_stats.ierrors;
-#else
-      rxerrors = xd->stats.ibadcrc
-        + xd->stats.ibadlen + xd->stats.ierrors;
-      last_rxerrors = xd->last_stats.ibadcrc
-        + xd->last_stats.ibadlen + xd->last_stats.ierrors;
-#endif
 
       if (PREDICT_FALSE (rxerrors != last_rxerrors))
         {