net/virtio: fix packet corruption
[dpdk.git] / drivers / net / virtio / virtqueue.h
index 17c1ea1..c452d04 100644 (file)
@@ -66,6 +66,23 @@ struct rte_mbuf;
 
 #define VIRTQUEUE_MAX_NAME_SZ 32
 
+#ifdef RTE_VIRTIO_USER
+/**
+ * Return the physical address (or virtual address in case of
+ * virtio-user) of mbuf data buffer.
+ */
+#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))
+#else
+#define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_physaddr)
+#endif
+
+/**
+ * Return the physical address (or virtual address in case of
+ * virtio-user) of mbuf data buffer, taking care of mbuf data offset
+ */
+#define VIRTIO_MBUF_DATA_DMA_ADDR(mb, vq) \
+       (VIRTIO_MBUF_ADDR(mb, vq) + (mb)->data_off)
+
 #define VTNET_SQ_RQ_QUEUE_IDX 0
 #define VTNET_SQ_TQ_QUEUE_IDX 1
 #define VTNET_SQ_CQ_QUEUE_IDX 2
@@ -174,7 +191,8 @@ struct virtqueue {
        void *vq_ring_virt_mem;  /**< linear address of vring*/
        unsigned int vq_ring_size;
 
-       phys_addr_t vq_ring_mem; /**< physical address of vring */
+       phys_addr_t vq_ring_mem; /**< physical address of vring,
+                                 * or virtual address for virtio-user. */
 
        /**
         * Head of the free chain in the descriptor table. If
@@ -184,6 +202,7 @@ struct virtqueue {
        uint16_t  vq_desc_head_idx;
        uint16_t  vq_desc_tail_idx;
        uint16_t  vq_queue_index;   /**< PCI queue index */
+       uint16_t offset; /**< relative offset to obtain addr in mbuf */
        uint16_t  *notify_addr;
        int configured;
        struct rte_mbuf **sw_ring;  /**< RX software ring. */