X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fbus%2Fvmbus%2Flinux%2Fvmbus_uio.c;h=fb60ee126d9bf96f06912b910efad6e9161f9684;hb=2a28a502c6078ceb3e5b296b5f9cbb7e27ceedbd;hp=bc2c6235e6bc3f72f5b15eb7b58aac590f156ed8;hpb=5ef90536d748105fcf12fa887347365bdd18e01a;p=dpdk.git diff --git a/drivers/bus/vmbus/linux/vmbus_uio.c b/drivers/bus/vmbus/linux/vmbus_uio.c index bc2c6235e6..fb60ee126d 100644 --- a/drivers/bus/vmbus/linux/vmbus_uio.c +++ b/drivers/bus/vmbus/linux/vmbus_uio.c @@ -39,11 +39,17 @@ void vmbus_uio_irq_control(struct rte_vmbus_device *dev, int32_t onoff) int vmbus_uio_irq_read(struct rte_vmbus_device *dev) { int32_t count; - - if (read(dev->intr_handle.fd, &count, sizeof(count)) < 0) { - VMBUS_LOG(ERR, "cannot read to %d:%s", - dev->intr_handle.fd, strerror(errno)); - count = -errno; + int cc; + + cc = read(dev->intr_handle.fd, &count, sizeof(count)); + if (cc < (int)sizeof(count)) { + if (cc < 0) { + VMBUS_LOG(ERR, "IRQ read failed %s", + strerror(errno)); + return -errno; + } + VMBUS_LOG(ERR, "can't read IRQ count"); + return -EINVAL; } return count; @@ -196,6 +202,7 @@ static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev, char ring_path[PATH_MAX]; size_t file_size; struct stat sb; + void *mapaddr; int fd; snprintf(ring_path, sizeof(ring_path), @@ -226,18 +233,63 @@ static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev, return -EINVAL; } - *ring_size = file_size / 2; - *ring_buf = vmbus_map_resource(vmbus_map_addr, fd, - 0, sb.st_size, 0); + mapaddr = vmbus_map_resource(vmbus_map_addr, fd, + 0, file_size, 0); close(fd); - if (ring_buf == MAP_FAILED) + if (mapaddr == MAP_FAILED) return -EIO; + *ring_size = file_size / 2; + *ring_buf = mapaddr; + vmbus_map_addr = RTE_PTR_ADD(ring_buf, 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); + return -1; +} + int vmbus_uio_map_rings(struct vmbus_channel *chan) { const struct rte_vmbus_device *dev = chan->device; @@ -323,6 +375,7 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary, char chan_path[PATH_MAX], subchan_path[PATH_MAX]; struct dirent *ent; DIR *chan_dir; + int err; snprintf(chan_path, sizeof(chan_path), "%s/%s/channels", @@ -338,7 +391,6 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary, while ((ent = readdir(chan_dir))) { unsigned long relid, subid, monid; char *endp; - int err; if (ent->d_name[0] == '.') continue; @@ -351,42 +403,50 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary, continue; } + if (!vmbus_isnew_subchannel(primary, relid)) { + VMBUS_LOG(DEBUG, "skip already found channel: %lu", + relid); + continue; + } + + if (!vmbus_uio_ring_present(dev, relid)) { + VMBUS_LOG(DEBUG, "ring mmap not found (yet) for: %lu", + relid); + continue; + } + snprintf(subchan_path, sizeof(subchan_path), "%s/%lu", chan_path, relid); err = vmbus_uio_sysfs_read(subchan_path, "subchannel_id", &subid, UINT16_MAX); if (err) { - VMBUS_LOG(NOTICE, "invalid subchannel id %lu", - subid); - closedir(chan_dir); - return err; + VMBUS_LOG(NOTICE, "no subchannel_id in %s:%s", + subchan_path, strerror(-err)); + goto fail; } if (subid == 0) continue; /* skip primary channel */ - if (!vmbus_isnew_subchannel(primary, relid)) - continue; - - if (!vmbus_uio_ring_present(dev, relid)) - continue; /* Ring may not be ready yet */ - err = vmbus_uio_sysfs_read(subchan_path, "monitor_id", &monid, UINT8_MAX); if (err) { - VMBUS_LOG(NOTICE, "invalid monitor id %lu", - monid); - return err; + VMBUS_LOG(NOTICE, "no monitor_id in %s:%s", + subchan_path, strerror(-err)); + goto fail; } err = vmbus_chan_create(dev, relid, subid, monid, subchan); if (err) { - VMBUS_LOG(NOTICE, "subchannel setup failed"); - return err; + VMBUS_LOG(ERR, "subchannel setup failed"); + goto fail; } break; } closedir(chan_dir); return (ent == NULL) ? -ENOENT : 0; +fail: + closedir(chan_dir); + return err; }