};
EAL_REGISTER_TAILQ(vmbus_tailq)
-static int
-vmbus_uio_map_secondary(struct rte_vmbus_device *dev)
+struct mapped_vmbus_resource *
+vmbus_uio_find_resource(const struct rte_vmbus_device *dev)
{
- int fd, i;
struct mapped_vmbus_resource *uio_res;
- struct mapped_vmbus_res_list *uio_res_list
- = RTE_TAILQ_CAST(vmbus_tailq.head, mapped_vmbus_res_list);
+ struct mapped_vmbus_res_list *uio_res_list =
+ RTE_TAILQ_CAST(vmbus_tailq.head, mapped_vmbus_res_list);
+
+ if (dev == NULL)
+ return NULL;
TAILQ_FOREACH(uio_res, uio_res_list, next) {
+ if (rte_uuid_compare(uio_res->id, dev->device_id) == 0)
+ return uio_res;
+ }
+ return NULL;
+}
- /* skip this element if it doesn't match our UUID */
- if (rte_uuid_compare(uio_res->id, dev->device_id) != 0)
- continue;
+static int
+vmbus_uio_map_secondary(struct rte_vmbus_device *dev)
+{
+ struct mapped_vmbus_resource *uio_res;
+ struct vmbus_channel *chan;
+ int fd, i;
- /* open /dev/uioX */
- fd = open(uio_res->path, O_RDWR);
- if (fd < 0) {
- VMBUS_LOG(ERR, "Cannot open %s: %s",
- uio_res->path, strerror(errno));
- return -1;
- }
+ uio_res = vmbus_uio_find_resource(dev);
+ if (!uio_res) {
+ VMBUS_LOG(ERR, "Cannot find resource for device");
+ return -1;
+ }
- for (i = 0; i != uio_res->nb_maps; i++) {
- void *mapaddr;
+ /* open /dev/uioX */
+ fd = open(uio_res->path, O_RDWR);
+ if (fd < 0) {
+ VMBUS_LOG(ERR, "Cannot open %s: %s",
+ uio_res->path, strerror(errno));
+ return -1;
+ }
- mapaddr = vmbus_map_resource(uio_res->maps[i].addr,
- fd, 0,
- uio_res->maps[i].size, 0);
+ for (i = 0; i != uio_res->nb_maps; i++) {
+ void *mapaddr;
+ off_t offset = i * rte_mem_page_size();
- if (mapaddr == uio_res->maps[i].addr)
- continue;
+ mapaddr = vmbus_map_resource(uio_res->maps[i].addr,
+ fd, offset,
+ uio_res->maps[i].size, 0);
+ if (mapaddr == uio_res->maps[i].addr) {
+ dev->resource[i].addr = mapaddr;
+ continue; /* successful map */
+ }
+
+ if (mapaddr == MAP_FAILED)
+ VMBUS_LOG(ERR,
+ "mmap resource %d in secondary failed", i);
+ else {
VMBUS_LOG(ERR,
- "Cannot mmap device resource file %s to address: %p",
- uio_res->path, uio_res->maps[i].addr);
+ "mmap resource %d address mismatch", i);
+ vmbus_unmap_resource(mapaddr, uio_res->maps[i].size);
+ }
+
+ close(fd);
+ return -1;
+ }
- if (mapaddr != MAP_FAILED)
- /* unmap addr wrongly mapped */
- vmbus_unmap_resource(mapaddr,
- (size_t)uio_res->maps[i].size);
+ /* fd is not needed in secondary process, close it */
+ close(fd);
- /* unmap addrs correctly mapped */
- while (--i >= 0)
- vmbus_unmap_resource(uio_res->maps[i].addr,
- (size_t)uio_res->maps[i].size);
+ /* Create and map primary channel */
+ if (vmbus_chan_create(dev, dev->relid, 0,
+ dev->monitor_id, &dev->primary)) {
+ VMBUS_LOG(ERR, "cannot create primary channel");
+ goto failed_primary;
+ }
- close(fd);
- return -1;
+ /* Create and map sub channels */
+ for (i = 0; i < uio_res->nb_subchannels; i++) {
+ if (rte_vmbus_subchan_open(dev->primary, &chan)) {
+ VMBUS_LOG(ERR,
+ "failed to create subchannel at index %d", i);
+ goto failed_secondary;
}
+ }
- /* fd is not needed in slave process, close it */
- close(fd);
- return 0;
+ return 0;
+
+failed_secondary:
+ while (!STAILQ_EMPTY(&dev->primary->subchannel_list)) {
+ chan = STAILQ_FIRST(&dev->primary->subchannel_list);
+ vmbus_unmap_resource(chan->txbr.vbr, chan->txbr.dsize * 2);
+ rte_vmbus_chan_close(chan);
}
+ rte_vmbus_chan_close(dev->primary);
- VMBUS_LOG(ERR, "Cannot find resource for device");
- return 1;
+failed_primary:
+ for (i = 0; i != uio_res->nb_maps; i++) {
+ vmbus_unmap_resource(
+ uio_res->maps[i].addr, uio_res->maps[i].size);
+ }
+
+ return -1;
}
static int
/* Map the resources */
for (i = 0; i < VMBUS_MAX_RESOURCE; i++) {
- /* skip empty BAR */
+ /* stop at empty BAR */
if (dev->resource[i].len == 0)
- continue;
+ break;
ret = vmbus_uio_map_resource_by_index(dev, i, uio_res, 0);
if (ret)
return -1;
}
-
-struct mapped_vmbus_resource *
-vmbus_uio_find_resource(const struct rte_vmbus_device *dev)
-{
- struct mapped_vmbus_resource *uio_res;
- struct mapped_vmbus_res_list *uio_res_list =
- RTE_TAILQ_CAST(vmbus_tailq.head, mapped_vmbus_res_list);
-
- if (dev == NULL)
- return NULL;
-
- TAILQ_FOREACH(uio_res, uio_res_list, next) {
- /* skip this element if it doesn't match our VMBUS address */
- if (rte_uuid_compare(uio_res->id, dev->device_id) == 0)
- return uio_res;
- }
- return NULL;
-}
-
/* map the VMBUS resource of a VMBUS device in virtual memory */
int
vmbus_uio_map_resource(struct rte_vmbus_device *dev)
int ret;
/* TODO: handle rescind */
- dev->intr_handle.fd = -1;
- dev->intr_handle.uio_cfg_fd = -1;
- dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+ if (rte_intr_fd_set(dev->intr_handle, -1))
+ return -1;
+
+ if (rte_intr_dev_fd_set(dev->intr_handle, -1))
+ return -1;
+
+ if (rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_UNKNOWN))
+ return -1;
/* secondary processes - use already recorded details */
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
}
dev->int_page = (uint32_t *)((char *)uio_res->maps[HV_INT_PAGE_MAP].addr
- + (PAGE_SIZE >> 1));
+ + (rte_mem_page_size() >> 1));
dev->monitor_page = uio_res->maps[HV_MON_PAGE_MAP].addr;
return 0;
}
if (uio_res == NULL)
return;
+ for (i = 0; i < uio_res->nb_subchannels; i++) {
+ vmbus_unmap_resource(uio_res->subchannel_maps[i].addr,
+ uio_res->subchannel_maps[i].size);
+ }
+
for (i = 0; i != uio_res->nb_maps; i++) {
vmbus_unmap_resource(uio_res->maps[i].addr,
(size_t)uio_res->maps[i].size);
return;
/* secondary processes - just free maps */
- if (rte_eal_process_type() != RTE_PROC_PRIMARY)
- return vmbus_uio_unmap(uio_res);
+ if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
+ vmbus_uio_unmap(uio_res);
+ rte_free(dev->primary);
+ return;
+ }
TAILQ_REMOVE(uio_res_list, uio_res, next);
rte_free(uio_res);
/* close fd if in primary process */
- close(dev->intr_handle.fd);
- if (dev->intr_handle.uio_cfg_fd >= 0) {
- close(dev->intr_handle.uio_cfg_fd);
- dev->intr_handle.uio_cfg_fd = -1;
+ if (rte_intr_fd_get(dev->intr_handle) >= 0)
+ close(rte_intr_fd_get(dev->intr_handle));
+
+ if (rte_intr_dev_fd_get(dev->intr_handle) >= 0) {
+ close(rte_intr_dev_fd_get(dev->intr_handle));
+ rte_intr_dev_fd_set(dev->intr_handle, -1);
}
- dev->intr_handle.fd = -1;
- dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+ rte_intr_fd_set(dev->intr_handle, -1);
+ rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_UNKNOWN);
}