event/cnxk: support vectorized Rx adapter
[dpdk.git] / drivers / bus / vmbus / linux / vmbus_uio.c
index 8c6bc52..b52ca5b 100644 (file)
@@ -14,7 +14,6 @@
 #include <rte_log.h>
 #include <rte_bus.h>
 #include <rte_memory.h>
-#include <rte_eal_memconfig.h>
 #include <rte_common.h>
 #include <rte_malloc.h>
 #include <rte_bus_vmbus.h>
@@ -155,7 +154,7 @@ vmbus_uio_map_resource_by_index(struct rte_vmbus_device *dev, int idx,
                vmbus_map_addr = vmbus_find_max_end_va();
 
        /* offset is special in uio it indicates which resource */
-       offset = idx * PAGE_SIZE;
+       offset = idx * rte_mem_page_size();
 
        mapaddr = vmbus_map_resource(vmbus_map_addr, fd, offset, size, flags);
        close(fd);
@@ -166,7 +165,7 @@ vmbus_uio_map_resource_by_index(struct rte_vmbus_device *dev, int idx,
        dev->resource[idx].addr = mapaddr;
        vmbus_map_addr = RTE_PTR_ADD(mapaddr, size);
 
-       /* Record result of sucessful mapping for use by secondary */
+       /* Record result of successful mapping for use by secondary */
        maps[idx].addr = mapaddr;
        maps[idx].size = size;
 
@@ -225,7 +224,7 @@ static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev,
        }
        file_size = sb.st_size;
 
-       if (file_size == 0 || (file_size & (PAGE_SIZE - 1))) {
+       if (file_size == 0 || (file_size & (rte_mem_page_size() - 1))) {
                VMBUS_LOG(ERR, "incorrect size %s: %zu",
                          ring_path, file_size);
 
@@ -243,10 +242,55 @@ static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev,
        *ring_size = file_size / 2;
        *ring_buf = mapaddr;
 
-       vmbus_map_addr = RTE_PTR_ADD(ring_buf, file_size);
+       vmbus_map_addr = RTE_PTR_ADD(mapaddr, file_size);
        return 0;
 }
 
+int
+vmbus_uio_map_secondary_subchan(const struct rte_vmbus_device *dev,
+                               const struct vmbus_channel *chan)
+{
+       const struct vmbus_br *br = &chan->txbr;
+       char ring_path[PATH_MAX];
+       void *mapaddr, *ring_buf;
+       uint32_t ring_size;
+       int fd;
+
+       snprintf(ring_path, sizeof(ring_path),
+                "%s/%s/channels/%u/ring",
+                SYSFS_VMBUS_DEVICES, dev->device.name,
+                chan->relid);
+
+       ring_buf = br->vbr;
+       ring_size = br->dsize + sizeof(struct vmbus_bufring);
+       VMBUS_LOG(INFO, "secondary ring_buf %p size %u",
+                 ring_buf, ring_size);
+
+       fd = open(ring_path, O_RDWR);
+       if (fd < 0) {
+               VMBUS_LOG(ERR, "Cannot open %s: %s",
+                         ring_path, strerror(errno));
+               return -errno;
+       }
+
+       mapaddr = vmbus_map_resource(ring_buf, fd, 0, 2 * ring_size, 0);
+       close(fd);
+
+       if (mapaddr == ring_buf)
+               return 0;
+
+       if (mapaddr == MAP_FAILED)
+               VMBUS_LOG(ERR,
+                         "mmap subchan %u in secondary failed", chan->relid);
+       else {
+               VMBUS_LOG(ERR,
+                         "mmap subchan %u in secondary address mismatch",
+                         chan->relid);
+               vmbus_unmap_resource(mapaddr, 2 * ring_size);
+       }
+       return -1;
+}
+
 int vmbus_uio_map_rings(struct vmbus_channel *chan)
 {
        const struct rte_vmbus_device *dev = chan->device;