New upstream version 16.11.7
[deb_dpdk.git] / lib / librte_vhost / vhost.h
index 22564f1..abc5a90 100644 (file)
@@ -52,6 +52,8 @@
 
 #define BUF_VECTOR_MAX 256
 
+#define VHOST_LOG_CACHE_NR 32
+
 /**
  * Structure contains buffer address, length and descriptor index
  * from vring to do scatter RX.
@@ -75,6 +77,14 @@ struct zcopy_mbuf {
 };
 TAILQ_HEAD(zcopy_mbuf_list, zcopy_mbuf);
 
+/*
+ * Structure that contains the info for batched dirty logging.
+ */
+struct log_cache_entry {
+       uint32_t offset;
+       unsigned long val;
+};
+
 /**
  * Structure contains variables relevant to RX/TX virtqueues.
  */
@@ -91,6 +101,8 @@ struct vhost_virtqueue {
 
        /* Backend value to determine if device should started/stopped */
        int                     backend;
+       rte_spinlock_t          access_lock;
+
        /* Used to notify the guest (trigger interrupt) */
        int                     callfd;
        /* Currently unused as polling mode is enabled */
@@ -108,27 +120,20 @@ struct vhost_virtqueue {
 
        struct vring_used_elem  *shadow_used_ring;
        uint16_t                shadow_used_idx;
+
+       struct log_cache_entry log_cache[VHOST_LOG_CACHE_NR];
+       uint16_t log_cache_nb_elem;
 } __rte_cache_aligned;
 
-/* Old kernels have no such macro defined */
+/* Old kernels have no such macros defined */
 #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
  #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
 #endif
 
-
-/*
- * Make an extra wrapper for VIRTIO_NET_F_MQ and
- * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are
- * introduced since kernel v3.8. This makes our
- * code buildable for older kernel.
- */
-#ifdef VIRTIO_NET_F_MQ
- #define VHOST_MAX_QUEUE_PAIRS VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX
- #define VHOST_SUPPORTS_MQ     (1ULL << VIRTIO_NET_F_MQ)
-#else
- #define VHOST_MAX_QUEUE_PAIRS 1
- #define VHOST_SUPPORTS_MQ     0
+#ifndef VIRTIO_NET_F_MQ
+ #define VIRTIO_NET_F_MQ               22
 #endif
+#define VHOST_MAX_QUEUE_PAIRS          0x80
 
 /*
  * Define virtio 1.0 for older kernels
@@ -203,7 +208,8 @@ struct virtio_memory {
 #ifdef RTE_LIBRTE_VHOST_DEBUG
 #define VHOST_MAX_PRINT_BUFF 6072
 #define LOG_LEVEL RTE_LOG_DEBUG
-#define LOG_DEBUG(log_type, fmt, args...) RTE_LOG(DEBUG, log_type, fmt, ##args)
+#define VHOST_LOG_DEBUG(log_type, fmt, args...) \
+       RTE_LOG(DEBUG, log_type, fmt, ##args)
 #define PRINT_PACKET(device, addr, size, header) do { \
        char *pkt_addr = (char *)(addr); \
        unsigned int index; \
@@ -219,11 +225,11 @@ struct virtio_memory {
        } \
        snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
        \
-       LOG_DEBUG(VHOST_DATA, "%s", packet); \
+       VHOST_LOG_DEBUG(VHOST_DATA, "%s", packet); \
 } while (0)
 #else
 #define LOG_LEVEL RTE_LOG_INFO
-#define LOG_DEBUG(log_type, fmt, args...) do {} while (0)
+#define VHOST_LOG_DEBUG(log_type, fmt, args...) do {} while (0)
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
 #endif
 
@@ -233,19 +239,24 @@ extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
 
 /* Convert guest physical Address to host virtual address */
 static inline uint64_t __attribute__((always_inline))
-gpa_to_vva(struct virtio_net *dev, uint64_t gpa)
+gpa_to_vva(struct virtio_net *dev, uint64_t gpa, uint64_t *len)
 {
-       struct virtio_memory_region *reg;
+       struct virtio_memory_region *r;
        uint32_t i;
 
        for (i = 0; i < dev->mem->nregions; i++) {
-               reg = &dev->mem->regions[i];
-               if (gpa >= reg->guest_phys_addr &&
-                   gpa <  reg->guest_phys_addr + reg->size) {
-                       return gpa - reg->guest_phys_addr +
-                              reg->host_user_addr;
+               r = &dev->mem->regions[i];
+               if (gpa >= r->guest_phys_addr &&
+                   gpa <  r->guest_phys_addr + r->size) {
+
+                       if (unlikely(*len > r->guest_phys_addr + r->size - gpa))
+                               *len = r->guest_phys_addr + r->size - gpa;
+
+                       return gpa - r->guest_phys_addr +
+                              r->host_user_addr;
                }
        }
+       *len = 0;
 
        return 0;
 }