examples/vhost: fix vlan offload
[dpdk.git] / examples / vhost / main.c
index 0c76ece..04f0118 100644 (file)
@@ -53,7 +53,7 @@
 
 #include "main.h"
 
-#define MAX_QUEUES 256
+#define MAX_QUEUES 512
 
 /* the maximum number of external ports supported */
 #define MAX_SUP_PORTS 1
@@ -380,10 +380,19 @@ port_init(uint8_t port)
        /* The max pool number from dev_info will be used to validate the pool number specified in cmd line */
        rte_eth_dev_info_get (port, &dev_info);
 
+       if (dev_info.max_rx_queues > MAX_QUEUES) {
+               rte_exit(EXIT_FAILURE,
+                       "please define MAX_QUEUES no less than %u in %s\n",
+                       dev_info.max_rx_queues, __FILE__);
+       }
+
        rxconf = &dev_info.default_rxconf;
        txconf = &dev_info.default_txconf;
        rxconf->rx_drop_en = 1;
 
+       /* Enable vlan offload */
+       txconf->txq_flags &= ~ETH_TXQ_FLAGS_NOVLANOFFL;
+
        /*
         * Zero copy defers queue RX/TX start to the time when guest
         * finishes its startup and packet buffers from that guest are
@@ -1113,9 +1122,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
                return;
        }
 
-       if (vm2vm_mode == VM2VM_HARDWARE) {
-               if (find_local_dest(dev, m, &offset, &vlan_tag) != 0 ||
-                       offset > rte_pktmbuf_tailroom(m)) {
+       if (unlikely(vm2vm_mode == VM2VM_HARDWARE)) {
+               if (unlikely(find_local_dest(dev, m, &offset, &vlan_tag) != 0)) {
                        rte_pktmbuf_free(m);
                        return;
                }
@@ -1129,8 +1137,24 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 
        m->ol_flags = PKT_TX_VLAN_PKT;
 
-       m->data_len += offset;
-       m->pkt_len += offset;
+       /*
+        * Find the right seg to adjust the data len when offset is
+        * bigger than tail room size.
+        */
+       if (unlikely(vm2vm_mode == VM2VM_HARDWARE)) {
+               if (likely(offset <= rte_pktmbuf_tailroom(m)))
+                       m->data_len += offset;
+               else {
+                       struct rte_mbuf *seg = m;
+
+                       while ((seg->next != NULL) &&
+                               (offset > rte_pktmbuf_tailroom(seg)))
+                               seg = seg->next;
+
+                       seg->data_len += offset;
+               }
+               m->pkt_len += offset;
+       }
 
        m->vlan_tci = vlan_tag;