diff options
Diffstat (limited to 'drivers/staging/hv')
35 files changed, 3276 insertions, 1599 deletions
diff --git a/drivers/staging/hv/Kconfig b/drivers/staging/hv/Kconfig index 7455c804962a..d41f380d188f 100644 --- a/drivers/staging/hv/Kconfig +++ b/drivers/staging/hv/Kconfig @@ -31,8 +31,16 @@ config HYPERV_NET config HYPERV_UTILS tristate "Microsoft Hyper-V Utilities driver" + depends on CONNECTOR default HYPERV help Select this option to enable the Hyper-V Utilities. +config HYPERV_MOUSE + tristate "Microsoft Hyper-V mouse driver" + depends on HID + default HYPERV + help + Select this option to enable the Hyper-V mouse driver. + endif diff --git a/drivers/staging/hv/Makefile b/drivers/staging/hv/Makefile index acd39bd75b1c..abeb2f7ef4e2 100644 --- a/drivers/staging/hv/Makefile +++ b/drivers/staging/hv/Makefile @@ -3,10 +3,12 @@ obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o obj-$(CONFIG_HYPERV_BLOCK) += hv_blkvsc.o obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o +obj-$(CONFIG_HYPERV_MOUSE) += hv_mouse.o -hv_vmbus-y := vmbus_drv.o osd.o \ +hv_vmbus-y := vmbus_drv.o \ hv.o connection.o channel.o \ channel_mgmt.o ring_buffer.o hv_storvsc-y := storvsc_drv.o storvsc.o hv_blkvsc-y := blkvsc_drv.o blkvsc.o hv_netvsc-y := netvsc_drv.o netvsc.o rndis_filter.o +hv_utils-y := hv_util.o hv_kvp.o diff --git a/drivers/staging/hv/blkvsc.c b/drivers/staging/hv/blkvsc.c index bc16d9172eb2..7c8729bc8329 100644 --- a/drivers/staging/hv/blkvsc.c +++ b/drivers/staging/hv/blkvsc.c @@ -22,7 +22,7 @@ */ #include <linux/kernel.h> #include <linux/mm.h> -#include "osd.h" +#include "hv_api.h" #include "storvsc.c" static const char *g_blk_driver_name = "blkvsc"; @@ -51,13 +51,13 @@ static int blk_vsc_on_device_add(struct hv_device *device, void *additional_info * id. For IDE devices, the device instance id is formatted as * <bus id> * - <device id> - 8899 - 000000000000. */ - device_info->path_id = device->deviceInstance.data[3] << 24 | - device->deviceInstance.data[2] << 16 | - device->deviceInstance.data[1] << 8 | - device->deviceInstance.data[0]; + device_info->path_id = device->dev_instance.data[3] << 24 | + device->dev_instance.data[2] << 16 | + device->dev_instance.data[1] << 8 | + device->dev_instance.data[0]; - device_info->target_id = device->deviceInstance.data[5] << 8 | - device->deviceInstance.data[4]; + device_info->target_id = device->dev_instance.data[5] << 8 | + device->dev_instance.data[4]; return ret; } @@ -73,7 +73,7 @@ int blk_vsc_initialize(struct hv_driver *driver) /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */ driver->name = g_blk_driver_name; - memcpy(&driver->deviceType, &g_blk_device_type, sizeof(struct hv_guid)); + memcpy(&driver->dev_type, &g_blk_device_type, sizeof(struct hv_guid)); stor_driver->request_ext_size = sizeof(struct storvsc_request_extension); @@ -85,7 +85,7 @@ int blk_vsc_initialize(struct hv_driver *driver) */ stor_driver->max_outstanding_req_per_channel = ((stor_driver->ring_buffer_size - PAGE_SIZE) / - ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + + ALIGN(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(struct vstor_packet) + sizeof(u64), sizeof(u64))); @@ -93,9 +93,9 @@ int blk_vsc_initialize(struct hv_driver *driver) stor_driver->max_outstanding_req_per_channel); /* Setup the dispatch table */ - stor_driver->base.OnDeviceAdd = blk_vsc_on_device_add; - stor_driver->base.OnDeviceRemove = stor_vsc_on_device_remove; - stor_driver->base.OnCleanup = stor_vsc_on_cleanup; + stor_driver->base.dev_add = blk_vsc_on_device_add; + stor_driver->base.dev_rm = stor_vsc_on_device_remove; + stor_driver->base.cleanup = stor_vsc_on_cleanup; stor_driver->on_io_request = stor_vsc_on_io_request; return ret; diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c index 4fb809485d9e..6e02f1b0c46f 100644 --- a/drivers/staging/hv/blkvsc_drv.c +++ b/drivers/staging/hv/blkvsc_drv.c @@ -31,7 +31,7 @@ #include <scsi/scsi_cmnd.h> #include <scsi/scsi_eh.h> #include <scsi/scsi_dbg.h> -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "version_info.h" #include "vmbus.h" @@ -95,7 +95,7 @@ struct blkvsc_request { /* Per device structure */ struct block_device_context { /* point back to our device context */ - struct vm_device *device_ctx; + struct hv_device *device_ctx; struct kmem_cache *request_pool; spinlock_t lock; struct gendisk *gd; @@ -115,13 +115,6 @@ struct block_device_context { int users; }; -/* Per driver */ -struct blkvsc_driver_context { - /* !! These must be the first 2 fields !! */ - /* FIXME this is a bug! */ - struct driver_context drv_ctx; - struct storvsc_driver_object drv_obj; -}; /* Static decl */ static DEFINE_MUTEX(blkvsc_mutex); @@ -156,7 +149,7 @@ module_param(blkvsc_ringbuffer_size, int, S_IRUGO); MODULE_PARM_DESC(ring_size, "Ring buffer size (in bytes)"); /* The one and only one */ -static struct blkvsc_driver_context g_blkvsc_drv; +static struct storvsc_driver_object g_blkvsc_drv; static const struct block_device_operations block_ops = { .owner = THIS_MODULE, @@ -173,25 +166,25 @@ static const struct block_device_operations block_ops = { */ static int blkvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) { - struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv.drv_obj; - struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx; + struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv; + struct hv_driver *drv = &g_blkvsc_drv.base; int ret; storvsc_drv_obj->ring_buffer_size = blkvsc_ringbuffer_size; + drv->priv = storvsc_drv_obj; + /* Callback to client driver to complete the initialization */ drv_init(&storvsc_drv_obj->base); - drv_ctx->driver.name = storvsc_drv_obj->base.name; - memcpy(&drv_ctx->class_id, &storvsc_drv_obj->base.deviceType, - sizeof(struct hv_guid)); + drv->driver.name = storvsc_drv_obj->base.name; - drv_ctx->probe = blkvsc_probe; - drv_ctx->remove = blkvsc_remove; - drv_ctx->shutdown = blkvsc_shutdown; + drv->driver.probe = blkvsc_probe; + drv->driver.remove = blkvsc_remove; + drv->driver.shutdown = blkvsc_shutdown; /* The driver belongs to vmbus */ - ret = vmbus_child_driver_register(drv_ctx); + ret = vmbus_child_driver_register(&drv->driver); return ret; } @@ -205,8 +198,8 @@ static int blkvsc_drv_exit_cb(struct device *dev, void *data) static void blkvsc_drv_exit(void) { - struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv.drv_obj; - struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx; + struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv; + struct hv_driver *drv = &g_blkvsc_drv.base; struct device *current_dev; int ret; @@ -214,7 +207,7 @@ static void blkvsc_drv_exit(void) current_dev = NULL; /* Get the device */ - ret = driver_for_each_device(&drv_ctx->driver, NULL, + ret = driver_for_each_device(&drv->driver, NULL, (void *) ¤t_dev, blkvsc_drv_exit_cb); @@ -230,10 +223,10 @@ static void blkvsc_drv_exit(void) device_unregister(current_dev); } - if (storvsc_drv_obj->base.OnCleanup) - storvsc_drv_obj->base.OnCleanup(&storvsc_drv_obj->base); + if (storvsc_drv_obj->base.cleanup) + storvsc_drv_obj->base.cleanup(&storvsc_drv_obj->base); - vmbus_child_driver_unregister(drv_ctx); + vmbus_child_driver_unregister(&drv->driver); return; } @@ -243,14 +236,11 @@ static void blkvsc_drv_exit(void) */ static int blkvsc_probe(struct device *device) { - struct driver_context *driver_ctx = - driver_to_driver_context(device->driver); - struct blkvsc_driver_context *blkvsc_drv_ctx = - (struct blkvsc_driver_context *)driver_ctx; + struct hv_driver *drv = + drv_to_hv_drv(device->driver); struct storvsc_driver_object *storvsc_drv_obj = - &blkvsc_drv_ctx->drv_obj; - struct vm_device *device_ctx = device_to_vm_device(device); - struct hv_device *device_obj = &device_ctx->device_obj; + drv->priv; + struct hv_device *device_obj = device_to_hv_device(device); struct block_device_context *blkdev = NULL; struct storvsc_device_info device_info; @@ -262,7 +252,7 @@ static int blkvsc_probe(struct device *device) DPRINT_DBG(BLKVSC_DRV, "blkvsc_probe - enter"); - if (!storvsc_drv_obj->base.OnDeviceAdd) { + if (!storvsc_drv_obj->base.dev_add) { DPRINT_ERR(BLKVSC_DRV, "OnDeviceAdd() not set"); ret = -1; goto Cleanup; @@ -282,7 +272,7 @@ static int blkvsc_probe(struct device *device) /* ASSERT(sizeof(struct blkvsc_request_group) <= */ /* sizeof(struct blkvsc_request)); */ - blkdev->request_pool = kmem_cache_create(dev_name(&device_ctx->device), + blkdev->request_pool = kmem_cache_create(dev_name(&device_obj->device), sizeof(struct blkvsc_request) + storvsc_drv_obj->request_ext_size, 0, SLAB_HWCACHE_ALIGN, NULL); @@ -293,13 +283,13 @@ static int blkvsc_probe(struct device *device) /* Call to the vsc driver to add the device */ - ret = storvsc_drv_obj->base.OnDeviceAdd(device_obj, &device_info); + ret = storvsc_drv_obj->base.dev_add(device_obj, &device_info); if (ret != 0) { DPRINT_ERR(BLKVSC_DRV, "unable to add blkvsc device"); goto Cleanup; } - blkdev->device_ctx = device_ctx; + blkdev->device_ctx = device_obj; /* this identified the device 0 or 1 */ blkdev->target = device_info.target_id; /* this identified the ide ctrl 0 or 1 */ @@ -392,7 +382,7 @@ static int blkvsc_probe(struct device *device) return ret; Remove: - storvsc_drv_obj->base.OnDeviceRemove(device_obj); + storvsc_drv_obj->base.dev_rm(device_obj); Cleanup: if (blkdev) { @@ -460,9 +450,9 @@ static int blkvsc_do_flush(struct block_device_context *blkdev) blkvsc_req->req = NULL; blkvsc_req->write = 0; - blkvsc_req->request.data_buffer.PfnArray[0] = 0; - blkvsc_req->request.data_buffer.Offset = 0; - blkvsc_req->request.data_buffer.Length = 0; + blkvsc_req->request.data_buffer.pfn_array[0] = 0; + blkvsc_req->request.data_buffer.offset = 0; + blkvsc_req->request.data_buffer.len = 0; blkvsc_req->cmnd[0] = SYNCHRONIZE_CACHE; blkvsc_req->cmd_len = 10; @@ -507,9 +497,9 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev) blkvsc_req->req = NULL; blkvsc_req->write = 0; - blkvsc_req->request.data_buffer.PfnArray[0] = page_to_pfn(page_buf); - blkvsc_req->request.data_buffer.Offset = 0; - blkvsc_req->request.data_buffer.Length = 64; + blkvsc_req->request.data_buffer.pfn_array[0] = page_to_pfn(page_buf); + blkvsc_req->request.data_buffer.offset = 0; + blkvsc_req->request.data_buffer.len = 64; blkvsc_req->cmnd[0] = INQUIRY; blkvsc_req->cmnd[1] = 0x1; /* Get product data */ @@ -594,9 +584,9 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev) blkvsc_req->req = NULL; blkvsc_req->write = 0; - blkvsc_req->request.data_buffer.PfnArray[0] = page_to_pfn(page_buf); - blkvsc_req->request.data_buffer.Offset = 0; - blkvsc_req->request.data_buffer.Length = 8; + blkvsc_req->request.data_buffer.pfn_array[0] = page_to_pfn(page_buf); + blkvsc_req->request.data_buffer.offset = 0; + blkvsc_req->request.data_buffer.len = 8; blkvsc_req->cmnd[0] = READ_CAPACITY; blkvsc_req->cmd_len = 16; @@ -671,9 +661,9 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev) blkvsc_req->req = NULL; blkvsc_req->write = 0; - blkvsc_req->request.data_buffer.PfnArray[0] = page_to_pfn(page_buf); - blkvsc_req->request.data_buffer.Offset = 0; - blkvsc_req->request.data_buffer.Length = 12; + blkvsc_req->request.data_buffer.pfn_array[0] = page_to_pfn(page_buf); + blkvsc_req->request.data_buffer.offset = 0; + blkvsc_req->request.data_buffer.len = 12; blkvsc_req->cmnd[0] = 0x9E; /* READ_CAPACITY16; */ blkvsc_req->cmd_len = 16; @@ -728,28 +718,25 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev) */ static int blkvsc_remove(struct device *device) { - struct driver_context *driver_ctx = - driver_to_driver_context(device->driver); - struct blkvsc_driver_context *blkvsc_drv_ctx = - (struct blkvsc_driver_context *)driver_ctx; + struct hv_driver *drv = + drv_to_hv_drv(device->driver); struct storvsc_driver_object *storvsc_drv_obj = - &blkvsc_drv_ctx->drv_obj; - struct vm_device *device_ctx = device_to_vm_device(device); - struct hv_device *device_obj = &device_ctx->device_obj; + drv->priv; + struct hv_device *device_obj = device_to_hv_device(device); struct block_device_context *blkdev = dev_get_drvdata(device); unsigned long flags; int ret; DPRINT_DBG(BLKVSC_DRV, "blkvsc_remove()\n"); - if (!storvsc_drv_obj->base.OnDeviceRemove) + if (!storvsc_drv_obj->base.dev_rm) return -1; /* * Call to the vsc driver to let it know that the device is being * removed */ - ret = storvsc_drv_obj->base.OnDeviceRemove(device_obj); + ret = storvsc_drv_obj->base.dev_rm(device_obj); if (ret != 0) { /* TODO: */ DPRINT_ERR(BLKVSC_DRV, @@ -850,13 +837,11 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*request_completion)(struct hv_storvsc_request *)) { struct block_device_context *blkdev = blkvsc_req->dev; - struct vm_device *device_ctx = blkdev->device_ctx; - struct driver_context *driver_ctx = - driver_to_driver_context(device_ctx->device.driver); - struct blkvsc_driver_context *blkvsc_drv_ctx = - (struct blkvsc_driver_context *)driver_ctx; + struct hv_device *device_ctx = blkdev->device_ctx; + struct hv_driver *drv = + drv_to_hv_drv(device_ctx->device.driver); struct storvsc_driver_object *storvsc_drv_obj = - &blkvsc_drv_ctx->drv_obj; + drv->priv; struct hv_storvsc_request *storvsc_req; int ret; @@ -866,14 +851,14 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, (blkvsc_req->write) ? "WRITE" : "READ", (unsigned long) blkvsc_req->sector_start, blkvsc_req->sector_count, - blkvsc_req->request.data_buffer.Offset, - blkvsc_req->request.data_buffer.Length); + blkvsc_req->request.data_buffer.offset, + blkvsc_req->request.data_buffer.len); #if 0 - for (i = 0; i < (blkvsc_req->request.data_buffer.Length >> 12); i++) { + for (i = 0; i < (blkvsc_req->request.data_buffer.len >> 12); i++) { DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - " "req %p pfn[%d] %llx\n", blkvsc_req, i, - blkvsc_req->request.data_buffer.PfnArray[i]); + blkvsc_req->request.data_buffer.pfn_array[i]); } #endif @@ -897,7 +882,7 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, storvsc_req->sense_buffer = blkvsc_req->sense_buffer; storvsc_req->sense_buffer_size = SCSI_SENSE_BUFFERSIZE; - ret = storvsc_drv_obj->on_io_request(&blkdev->device_ctx->device_obj, + ret = storvsc_drv_obj->on_io_request(blkdev->device_ctx, &blkvsc_req->request); if (ret == 0) blkdev->num_outstanding_reqs++; @@ -993,9 +978,9 @@ static int blkvsc_do_request(struct block_device_context *blkdev, blkvsc_req->dev = blkdev; blkvsc_req->req = req; - blkvsc_req->request.data_buffer.Offset + blkvsc_req->request.data_buffer.offset = bvec->bv_offset; - blkvsc_req->request.data_buffer.Length + blkvsc_req->request.data_buffer.len = 0; /* Add to the group */ @@ -1011,9 +996,9 @@ static int blkvsc_do_request(struct block_device_context *blkdev, /* Add the curr bvec/segment to the curr blkvsc_req */ blkvsc_req->request.data_buffer. - PfnArray[databuf_idx] + pfn_array[databuf_idx] = page_to_pfn(bvec->bv_page); - blkvsc_req->request.data_buffer.Length + blkvsc_req->request.data_buffer.len += bvec->bv_len; prev_bvec = bvec; @@ -1116,7 +1101,7 @@ static void blkvsc_request_completion(struct hv_storvsc_request *request) (blkvsc_req->write) ? "WRITE" : "READ", (unsigned long)blkvsc_req->sector_start, blkvsc_req->sector_count, - blkvsc_req->request.data_buffer.Length, + blkvsc_req->request.data_buffer.len, blkvsc_req->group->outstanding, blkdev->num_outstanding_reqs); diff --git a/drivers/staging/hv/channel.c b/drivers/staging/hv/channel.c index 45a627d77b41..775a52a91222 100644 --- a/drivers/staging/hv/channel.c +++ b/drivers/staging/hv/channel.c @@ -19,13 +19,18 @@ * Hank Janssen <hjanssen@microsoft.com> */ #include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/wait.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/module.h> -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "vmbus_private.h" +#define NUM_PAGES_SPANNED(addr, len) \ +((PAGE_ALIGN(addr + len) >> PAGE_SHIFT) - (addr >> PAGE_SHIFT)) + /* Internal routines */ static int create_gpadl_header( void *kbuffer, /* must be phys and virt contiguous */ @@ -77,10 +82,10 @@ static void vmbus_setevent(struct vmbus_channel *channel) if (channel->offermsg.monitor_allocated) { /* Each u32 represents 32 channels */ set_bit(channel->offermsg.child_relid & 31, - (unsigned long *) gVmbusConnection.SendInterruptPage + + (unsigned long *) vmbus_connection.send_int_page + (channel->offermsg.child_relid >> 5)); - monitorpage = gVmbusConnection.MonitorPages; + monitorpage = vmbus_connection.monitor_pages; monitorpage++; /* Get the child to parent monitor page */ set_bit(channel->monitor_bit, @@ -88,7 +93,7 @@ static void vmbus_setevent(struct vmbus_channel *channel) [channel->monitor_grp].pending); } else { - VmbusSetEvent(channel->offermsg.child_relid); + vmbus_set_event(channel->offermsg.child_relid); } } @@ -100,11 +105,11 @@ static void VmbusChannelClearEvent(struct vmbus_channel *channel) if (Channel->offermsg.monitor_allocated) { /* Each u32 represents 32 channels */ clear_bit(Channel->offermsg.child_relid & 31, - (unsigned long *)gVmbusConnection.SendInterruptPage + + (unsigned long *)vmbus_connection.send_int_page + (Channel->offermsg.child_relid >> 5)); - monitorPage = - (struct hv_monitor_page *)gVmbusConnection.MonitorPages; + monitorPage = (struct hv_monitor_page *) + vmbus_connection.monitor_pages; monitorPage++; /* Get the child to parent monitor page */ clear_bit(Channel->monitor_bit, @@ -128,12 +133,12 @@ void vmbus_get_debug_info(struct vmbus_channel *channel, debuginfo->relid = channel->offermsg.child_relid; debuginfo->state = channel->state; memcpy(&debuginfo->interfacetype, - &channel->offermsg.offer.InterfaceType, sizeof(struct hv_guid)); + &channel->offermsg.offer.if_type, sizeof(struct hv_guid)); memcpy(&debuginfo->interface_instance, - &channel->offermsg.offer.InterfaceInstance, + &channel->offermsg.offer.if_instance, sizeof(struct hv_guid)); - monitorpage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages; + monitorpage = (struct hv_monitor_page *)vmbus_connection.monitor_pages; debuginfo->monitorid = channel->offermsg.monitorid; @@ -180,8 +185,9 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, newchannel->channel_callback_context = context; /* Allocate the ring buffer */ - out = osd_page_alloc((send_ringbuffer_size + recv_ringbuffer_size) - >> PAGE_SHIFT); + out = (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, + get_order(send_ringbuffer_size + recv_ringbuffer_size)); + if (!out) return -ENOMEM; @@ -242,11 +248,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, goto errorout; } - openInfo->waitevent = osd_waitevent_create(); - if (!openInfo->waitevent) { - err = -ENOMEM; - goto errorout; - } + init_waitqueue_head(&openInfo->waitevent); openMsg = (struct vmbus_channel_open_channel *)openInfo->msg; openMsg->header.msgtype = CHANNELMSG_OPENCHANNEL; @@ -265,22 +267,29 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, if (userdatalen) memcpy(openMsg->userdata, userdata, userdatalen); - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_add_tail(&openInfo->msglistentry, - &gVmbusConnection.ChannelMsgList); - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + &vmbus_connection.chn_msg_list); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); DPRINT_DBG(VMBUS, "Sending channel open msg..."); - ret = VmbusPostMessage(openMsg, + ret = vmbus_post_msg(openMsg, sizeof(struct vmbus_channel_open_channel)); if (ret != 0) { DPRINT_ERR(VMBUS, "unable to open channel - %d", ret); goto Cleanup; } - /* FIXME: Need to time-out here */ - osd_waitevent_wait(openInfo->waitevent); + openInfo->wait_condition = 0; + wait_event_timeout(openInfo->waitevent, + openInfo->wait_condition, + msecs_to_jiffies(1000)); + if (openInfo->wait_condition == 0) { + err = -ETIMEDOUT; + goto errorout; + } + if (openInfo->response.open_result.status == 0) DPRINT_INFO(VMBUS, "channel <%p> open success!!", newchannel); @@ -289,19 +298,18 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, newchannel, openInfo->response.open_result.status); Cleanup: - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_del(&openInfo->msglistentry); - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); - kfree(openInfo->waitevent); kfree(openInfo); return 0; errorout: ringbuffer_cleanup(&newchannel->outbound); ringbuffer_cleanup(&newchannel->inbound); - osd_page_free(out, (send_ringbuffer_size + recv_ringbuffer_size) - >> PAGE_SHIFT); + free_pages((unsigned long)out, + get_order(send_ringbuffer_size + recv_ringbuffer_size)); kfree(openInfo); return err; } @@ -338,16 +346,16 @@ static void dump_gpadl_header(struct vmbus_channel_gpadl_header *gpadl) "gpadl header - relid %d, range count %d, range buflen %d", gpadl->child_relid, gpadl->rangecount, gpadl->range_buflen); for (i = 0; i < gpadl->rangecount; i++) { - pagecount = gpadl->range[i].ByteCount >> PAGE_SHIFT; + pagecount = gpadl->range[i].byte_count >> PAGE_SHIFT; pagecount = (pagecount > 26) ? 26 : pagecount; DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d " - "page count %d", i, gpadl->range[i].ByteCount, - gpadl->range[i].ByteOffset, pagecount); + "page count %d", i, gpadl->range[i].byte_count, + gpadl->range[i].byte_offset, pagecount); for (j = 0; j < pagecount; j++) DPRINT_DBG(VMBUS, "%d) pfn %llu", j, - gpadl->range[i].PfnArray[j]); + gpadl->range[i].pfn_array[j]); } } @@ -399,10 +407,10 @@ static int create_gpadl_header(void *kbuffer, u32 size, gpadl_header->rangecount = 1; gpadl_header->range_buflen = sizeof(struct gpa_range) + pagecount * sizeof(u64); - gpadl_header->range[0].ByteOffset = 0; - gpadl_header->range[0].ByteCount = size; + gpadl_header->range[0].byte_offset = 0; + gpadl_header->range[0].byte_count = size; for (i = 0; i < pfncount; i++) - gpadl_header->range[0].PfnArray[i] = pfn+i; + gpadl_header->range[0].pfn_array[i] = pfn+i; *msginfo = msgheader; *messagecount = 1; @@ -463,10 +471,10 @@ static int create_gpadl_header(void *kbuffer, u32 size, gpadl_header->rangecount = 1; gpadl_header->range_buflen = sizeof(struct gpa_range) + pagecount * sizeof(u64); - gpadl_header->range[0].ByteOffset = 0; - gpadl_header->range[0].ByteCount = size; + gpadl_header->range[0].byte_offset = 0; + gpadl_header->range[0].byte_count = size; for (i = 0; i < pagecount; i++) - gpadl_header->range[0].PfnArray[i] = pfn+i; + gpadl_header->range[0].pfn_array[i] = pfn+i; *msginfo = msgheader; *messagecount = 1; @@ -501,18 +509,14 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, unsigned long flags; int ret = 0; - next_gpadl_handle = atomic_read(&gVmbusConnection.NextGpadlHandle); - atomic_inc(&gVmbusConnection.NextGpadlHandle); + next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle); + atomic_inc(&vmbus_connection.next_gpadl_handle); ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount); if (ret) return ret; - msginfo->waitevent = osd_waitevent_create(); - if (!msginfo->waitevent) { - ret = -ENOMEM; - goto Cleanup; - } + init_waitqueue_head(&msginfo->waitevent); gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->msg; gpadlmsg->header.msgtype = CHANNELMSG_GPADL_HEADER; @@ -521,18 +525,19 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, dump_gpadl_header(gpadlmsg); - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_add_tail(&msginfo->msglistentry, - &gVmbusConnection.ChannelMsgList); + &vmbus_connection.chn_msg_list); - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", kbuffer, size, msgcount); DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", msginfo->msgsize - sizeof(*msginfo)); - ret = VmbusPostMessage(gpadlmsg, msginfo->msgsize - + msginfo->wait_condition = 0; + ret = vmbus_post_msg(gpadlmsg, msginfo->msgsize - sizeof(*msginfo)); if (ret != 0) { DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret); @@ -557,7 +562,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, dump_gpadl_body(gpadl_body, submsginfo->msgsize - sizeof(*submsginfo)); - ret = VmbusPostMessage(gpadl_body, + ret = vmbus_post_msg(gpadl_body, submsginfo->msgsize - sizeof(*submsginfo)); if (ret != 0) @@ -565,7 +570,11 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, } } - osd_waitevent_wait(msginfo->waitevent); + wait_event_timeout(msginfo->waitevent, + msginfo->wait_condition, + msecs_to_jiffies(1000)); + BUG_ON(msginfo->wait_condition == 0); + /* At this point, we received the gpadl created msg */ DPRINT_DBG(VMBUS, "Received GPADL created " @@ -577,11 +586,10 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, *gpadl_handle = gpadlmsg->gpadl; Cleanup: - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_del(&msginfo->msglistentry); - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); - kfree(msginfo->waitevent); kfree(msginfo); return ret; } @@ -604,11 +612,7 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) if (!info) return -ENOMEM; - info->waitevent = osd_waitevent_create(); - if (!info->waitevent) { - kfree(info); - return -ENOMEM; - } + init_waitqueue_head(&info->waitevent); msg = (struct vmbus_channel_gpadl_teardown *)info->msg; @@ -616,26 +620,24 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) msg->child_relid = channel->offermsg.child_relid; msg->gpadl = gpadl_handle; - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_add_tail(&info->msglistentry, - &gVmbusConnection.ChannelMsgList); - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); - - ret = VmbusPostMessage(msg, + &vmbus_connection.chn_msg_list); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); + info->wait_condition = 0; + ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_gpadl_teardown)); - if (ret != 0) { - /* TODO: */ - /* something... */ - } - osd_waitevent_wait(info->waitevent); + BUG_ON(ret != 0); + wait_event_timeout(info->waitevent, + info->wait_condition, msecs_to_jiffies(1000)); + BUG_ON(info->wait_condition == 0); /* Received a torndown response */ - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_del(&info->msglistentry); - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); - kfree(info->waitevent); kfree(info); return ret; } @@ -663,18 +665,14 @@ void vmbus_close(struct vmbus_channel *channel) if (!info) return; - /* info->waitEvent = osd_waitevent_create(); */ msg = (struct vmbus_channel_close_channel *)info->msg; msg->header.msgtype = CHANNELMSG_CLOSECHANNEL; msg->child_relid = channel->offermsg.child_relid; - ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_close_channel)); - if (ret != 0) { - /* TODO: */ - /* something... */ - } + ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_close_channel)); + BUG_ON(ret != 0); /* Tear down the gpadl for the channel's ring buffer */ if (channel->ringbuffer_gpadlhandle) vmbus_teardown_gpadl(channel, @@ -686,7 +684,8 @@ void vmbus_close(struct vmbus_channel *channel) ringbuffer_cleanup(&channel->outbound); ringbuffer_cleanup(&channel->inbound); - osd_page_free(channel->ringbuffer_pages, channel->ringbuffer_pagecount); + free_pages((unsigned long)channel->ringbuffer_pages, + get_order(channel->ringbuffer_pagecount * PAGE_SIZE)); kfree(info); @@ -697,9 +696,9 @@ void vmbus_close(struct vmbus_channel *channel) */ if (channel->state == CHANNEL_OPEN_STATE) { - spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); + spin_lock_irqsave(&vmbus_connection.channel_lock, flags); list_del(&channel->listentry); - spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); free_channel(channel); } @@ -726,7 +725,7 @@ int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer, { struct vmpacket_descriptor desc; u32 packetlen = sizeof(struct vmpacket_descriptor) + bufferlen; - u32 packetlen_aligned = ALIGN_UP(packetlen, sizeof(u64)); + u32 packetlen_aligned = ALIGN(packetlen, sizeof(u64)); struct scatterlist bufferlist[3]; u64 aligned_data = 0; int ret; @@ -739,12 +738,12 @@ int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer, /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ /* Setup the descriptor */ - desc.Type = type; /* VmbusPacketTypeDataInBand; */ - desc.Flags = flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ + desc.type = type; /* VmbusPacketTypeDataInBand; */ + desc.flags = flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ /* in 8-bytes granularity */ - desc.DataOffset8 = sizeof(struct vmpacket_descriptor) >> 3; - desc.Length8 = (u16)(packetlen_aligned >> 3); - desc.TransactionId = requestid; + desc.offset8 = sizeof(struct vmpacket_descriptor) >> 3; + desc.len8 = (u16)(packetlen_aligned >> 3); + desc.trans_id = requestid; sg_init_table(bufferlist, 3); sg_set_buf(&bufferlist[0], &desc, sizeof(struct vmpacket_descriptor)); @@ -793,12 +792,12 @@ int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, ((MAX_PAGE_BUFFER_COUNT - pagecount) * sizeof(struct hv_page_buffer)); packetlen = descsize + bufferlen; - packetlen_aligned = ALIGN_UP(packetlen, sizeof(u64)); + packetlen_aligned = ALIGN(packetlen, sizeof(u64)); /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ /* Setup the descriptor */ - desc.type = VmbusPacketTypeDataUsingGpaDirect; + desc.type = VM_PKT_DATA_USING_GPA_DIRECT; desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ desc.length8 = (u16)(packetlen_aligned >> 3); @@ -806,9 +805,9 @@ int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, desc.rangecount = pagecount; for (i = 0; i < pagecount; i++) { - desc.range[i].Length = pagebuffers[i].Length; - desc.range[i].Offset = pagebuffers[i].Offset; - desc.range[i].Pfn = pagebuffers[i].Pfn; + desc.range[i].len = pagebuffers[i].len; + desc.range[i].offset = pagebuffers[i].offset; + desc.range[i].pfn = pagebuffers[i].pfn; } sg_init_table(bufferlist, 3); @@ -842,14 +841,14 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, u32 packetlen_aligned; struct scatterlist bufferlist[3]; u64 aligned_data = 0; - u32 pfncount = NUM_PAGES_SPANNED(multi_pagebuffer->Offset, - multi_pagebuffer->Length); + u32 pfncount = NUM_PAGES_SPANNED(multi_pagebuffer->offset, + multi_pagebuffer->len); dump_vmbus_channel(channel); DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", - multi_pagebuffer->Offset, - multi_pagebuffer->Length, pfncount); + multi_pagebuffer->offset, + multi_pagebuffer->len, pfncount); if ((pfncount < 0) || (pfncount > MAX_MULTIPAGE_BUFFER_COUNT)) return -EINVAL; @@ -862,22 +861,22 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, ((MAX_MULTIPAGE_BUFFER_COUNT - pfncount) * sizeof(u64)); packetlen = descsize + bufferlen; - packetlen_aligned = ALIGN_UP(packetlen, sizeof(u64)); + packetlen_aligned = ALIGN(packetlen, sizeof(u64)); /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ /* Setup the descriptor */ - desc.type = VmbusPacketTypeDataUsingGpaDirect; + desc.type = VM_PKT_DATA_USING_GPA_DIRECT; desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ desc.length8 = (u16)(packetlen_aligned >> 3); desc.transactionid = requestid; desc.rangecount = 1; - desc.range.Length = multi_pagebuffer->Length; - desc.range.Offset = multi_pagebuffer->Offset; + desc.range.len = multi_pagebuffer->len; + desc.range.offset = multi_pagebuffer->offset; - memcpy(desc.range.PfnArray, multi_pagebuffer->PfnArray, + memcpy(desc.range.pfn_array, multi_pagebuffer->pfn_array, pfncount * sizeof(u64)); sg_init_table(bufferlist, 3); @@ -934,14 +933,14 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, /* VmbusChannelClearEvent(Channel); */ - packetlen = desc.Length8 << 3; - userlen = packetlen - (desc.DataOffset8 << 3); + packetlen = desc.len8 << 3; + userlen = packetlen - (desc.offset8 << 3); /* ASSERT(userLen > 0); */ DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d " "flag %d tid %llx pktlen %d datalen %d> ", - channel, channel->offermsg.child_relid, desc.Type, - desc.Flags, desc.TransactionId, packetlen, userlen); + channel, channel->offermsg.child_relid, desc.type, + desc.flags, desc.trans_id, packetlen, userlen); *buffer_actual_len = userlen; @@ -953,11 +952,11 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, return -1; } - *requestid = desc.TransactionId; + *requestid = desc.trans_id; /* Copy over the packet to the user buffer */ ret = ringbuffer_read(&channel->inbound, buffer, userlen, - (desc.DataOffset8 << 3)); + (desc.offset8 << 3)); spin_unlock_irqrestore(&channel->inbound_lock, flags); @@ -994,13 +993,13 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, /* VmbusChannelClearEvent(Channel); */ - packetlen = desc.Length8 << 3; - userlen = packetlen - (desc.DataOffset8 << 3); + packetlen = desc.len8 << 3; + userlen = packetlen - (desc.offset8 << 3); DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d " "flag %d tid %llx pktlen %d datalen %d> ", - channel, channel->offermsg.child_relid, desc.Type, - desc.Flags, desc.TransactionId, packetlen, userlen); + channel, channel->offermsg.child_relid, desc.type, + desc.flags, desc.trans_id, packetlen, userlen); *buffer_actual_len = packetlen; @@ -1012,7 +1011,7 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, return -2; } - *requestid = desc.TransactionId; + *requestid = desc.trans_id; /* Copy over the entire packet to the user buffer */ ret = ringbuffer_read(&channel->inbound, buffer, packetlen, 0); diff --git a/drivers/staging/hv/channel.h b/drivers/staging/hv/channel.h index 7997056734d7..de4f867de171 100644 --- a/drivers/staging/hv/channel.h +++ b/drivers/staging/hv/channel.h @@ -37,7 +37,7 @@ struct vmbus_channel_packet_page_buffer { u32 reserved; u32 rangecount; struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT]; -} __attribute__((packed)); +} __packed; /* The format must be the same as struct vmdata_gpa_direct */ struct vmbus_channel_packet_multipage_buffer { @@ -49,7 +49,7 @@ struct vmbus_channel_packet_multipage_buffer { u32 reserved; u32 rangecount; /* Always 1 in this case */ struct hv_multipage_buffer range; -} __attribute__((packed)); +} __packed; extern int vmbus_open(struct vmbus_channel *channel, diff --git a/drivers/staging/hv/channel_mgmt.c b/drivers/staging/hv/channel_mgmt.c index d44d5c39f68b..bc0393a41d29 100644 --- a/drivers/staging/hv/channel_mgmt.c +++ b/drivers/staging/hv/channel_mgmt.c @@ -19,12 +19,14 @@ * Hank Janssen <hjanssen@microsoft.com> */ #include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/wait.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/list.h> #include <linux/module.h> #include <linux/completion.h> -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "vmbus_private.h" #include "utils.h" @@ -34,8 +36,8 @@ struct vmbus_channel_message_table_entry { void (*messageHandler)(struct vmbus_channel_message_header *msg); }; -#define MAX_MSG_TYPES 3 -#define MAX_NUM_DEVICE_CLASSES_SUPPORTED 7 +#define MAX_MSG_TYPES 4 +#define MAX_NUM_DEVICE_CLASSES_SUPPORTED 8 static const struct hv_guid gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED] = { @@ -98,6 +100,15 @@ static const struct hv_guid 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d } }, + /* {A9A0F4E7-5A45-4d96-B827-8A841E8C03E6} */ + /* KVP */ + { + .data = { + 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, + 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 + } + }, + }; @@ -185,7 +196,7 @@ void chn_cb_negotiate(void *context) vmbus_sendpacket(channel, buf, recvlen, requestid, - VmbusPacketTypeDataInBand, 0); + VM_PKT_DATA_INBAND, 0); } kfree(buf); @@ -231,6 +242,16 @@ struct hyperv_service_callback hv_cb_utils[MAX_MSG_TYPES] = { .callback = chn_cb_negotiate, .log_msg = "Heartbeat channel functionality initialized" }, + /* {A9A0F4E7-5A45-4d96-B827-8A841E8C03E6} */ + /* KVP */ + { + .data = { + 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, + 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 + }, + .callback = chn_cb_negotiate, + .log_msg = "KVP channel functionality initialized" + }, }; EXPORT_SYMBOL(hv_cb_utils); @@ -289,7 +310,7 @@ void free_channel(struct vmbus_channel *channel) * ie we can't destroy ourselves. */ INIT_WORK(&channel->work, release_channel); - queue_work(gVmbusConnection.WorkQueue, &channel->work); + queue_work(vmbus_connection.work_queue, &channel->work); } @@ -304,10 +325,10 @@ static void count_hv_channel(void) static int counter; unsigned long flags; - spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); + spin_lock_irqsave(&vmbus_connection.channel_lock, flags); if (++counter == MAX_MSG_TYPES) complete(&hv_channel_ready); - spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); } /* @@ -342,14 +363,14 @@ static void vmbus_process_offer(struct work_struct *work) INIT_WORK(&newchannel->work, vmbus_process_rescind_offer); /* Make sure this is a new offer */ - spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); + spin_lock_irqsave(&vmbus_connection.channel_lock, flags); - list_for_each_entry(channel, &gVmbusConnection.ChannelList, listentry) { - if (!memcmp(&channel->offermsg.offer.InterfaceType, - &newchannel->offermsg.offer.InterfaceType, + list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { + if (!memcmp(&channel->offermsg.offer.if_type, + &newchannel->offermsg.offer.if_type, sizeof(struct hv_guid)) && - !memcmp(&channel->offermsg.offer.InterfaceInstance, - &newchannel->offermsg.offer.InterfaceInstance, + !memcmp(&channel->offermsg.offer.if_instance, + &newchannel->offermsg.offer.if_instance, sizeof(struct hv_guid))) { fnew = false; break; @@ -358,9 +379,9 @@ static void vmbus_process_offer(struct work_struct *work) if (fnew) list_add_tail(&newchannel->listentry, - &gVmbusConnection.ChannelList); + &vmbus_connection.chn_list); - spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); if (!fnew) { DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", @@ -372,11 +393,11 @@ static void vmbus_process_offer(struct work_struct *work) /* * Start the process of binding this offer to the driver * We need to set the DeviceObject field before calling - * VmbusChildDeviceAdd() + * vmbus_child_dev_add() */ newchannel->device_obj = vmbus_child_device_create( - &newchannel->offermsg.offer.InterfaceType, - &newchannel->offermsg.offer.InterfaceInstance, + &newchannel->offermsg.offer.if_type, + &newchannel->offermsg.offer.if_instance, newchannel); DPRINT_DBG(VMBUS, "child device object allocated - %p", @@ -387,15 +408,15 @@ static void vmbus_process_offer(struct work_struct *work) * binding which eventually invokes the device driver's AddDevice() * method. */ - ret = VmbusChildDeviceAdd(newchannel->device_obj); + ret = vmbus_child_device_register(newchannel->device_obj); if (ret != 0) { DPRINT_ERR(VMBUS, "unable to add child device object (relid %d)", newchannel->offermsg.child_relid); - spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); + spin_lock_irqsave(&vmbus_connection.channel_lock, flags); list_del(&newchannel->listentry); - spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); free_channel(newchannel); } else { @@ -408,7 +429,7 @@ static void vmbus_process_offer(struct work_struct *work) /* Open IC channels */ for (cnt = 0; cnt < MAX_MSG_TYPES; cnt++) { - if (memcmp(&newchannel->offermsg.offer.InterfaceType, + if (memcmp(&newchannel->offermsg.offer.if_type, &hv_cb_utils[cnt].data, sizeof(struct hv_guid)) == 0 && vmbus_open(newchannel, 2 * PAGE_SIZE, @@ -442,7 +463,7 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) offer = (struct vmbus_channel_offer_channel *)hdr; for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) { - if (memcmp(&offer->offer.InterfaceType, + if (memcmp(&offer->offer.if_type, &gSupportedDeviceClasses[i], sizeof(struct hv_guid)) == 0) { fsupported = 1; break; @@ -455,8 +476,8 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) return; } - guidtype = &offer->offer.InterfaceType; - guidinstance = &offer->offer.InterfaceInstance; + guidtype = &offer->offer.if_type; + guidinstance = &offer->offer.if_instance; DPRINT_INFO(VMBUS, "Channel offer notification - " "child relid %d monitor id %d allocated %d, " @@ -513,7 +534,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) struct vmbus_channel *channel; rescind = (struct vmbus_channel_rescind_offer *)hdr; - channel = GetChannelFromRelId(rescind->child_relid); + channel = relid2channel(rescind->child_relid); if (channel == NULL) { DPRINT_DBG(VMBUS, "channel not found for relId %d", rescind->child_relid); @@ -546,7 +567,6 @@ static void vmbus_onoffers_delivered( static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) { struct vmbus_channel_open_result *result; - struct list_head *curr; struct vmbus_channel_msginfo *msginfo; struct vmbus_channel_message_header *requestheader; struct vmbus_channel_open_channel *openmsg; @@ -558,11 +578,10 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) /* * Find the open msg, copy the result and signal/unblock the wait event */ - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); - list_for_each(curr, &gVmbusConnection.ChannelMsgList) { -/* FIXME: this should probably use list_entry() instead */ - msginfo = (struct vmbus_channel_msginfo *)curr; + list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, + msglistentry) { requestheader = (struct vmbus_channel_message_header *)msginfo->msg; @@ -574,12 +593,13 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) memcpy(&msginfo->response.open_result, result, sizeof(struct vmbus_channel_open_result)); - osd_waitevent_set(msginfo->waitevent); + msginfo->wait_condition = 1; + wake_up(&msginfo->waitevent); break; } } } - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); } /* @@ -592,7 +612,6 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) { struct vmbus_channel_gpadl_created *gpadlcreated; - struct list_head *curr; struct vmbus_channel_msginfo *msginfo; struct vmbus_channel_message_header *requestheader; struct vmbus_channel_gpadl_header *gpadlheader; @@ -606,11 +625,10 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) * Find the establish msg, copy the result and signal/unblock the wait * event */ - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); - list_for_each(curr, &gVmbusConnection.ChannelMsgList) { -/* FIXME: this should probably use list_entry() instead */ - msginfo = (struct vmbus_channel_msginfo *)curr; + list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, + msglistentry) { requestheader = (struct vmbus_channel_message_header *)msginfo->msg; @@ -624,12 +642,13 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) memcpy(&msginfo->response.gpadl_created, gpadlcreated, sizeof(struct vmbus_channel_gpadl_created)); - osd_waitevent_set(msginfo->waitevent); + msginfo->wait_condition = 1; + wake_up(&msginfo->waitevent); break; } } } - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); } /* @@ -643,7 +662,6 @@ static void vmbus_ongpadl_torndown( struct vmbus_channel_message_header *hdr) { struct vmbus_channel_gpadl_torndown *gpadl_torndown; - struct list_head *curr; struct vmbus_channel_msginfo *msginfo; struct vmbus_channel_message_header *requestheader; struct vmbus_channel_gpadl_teardown *gpadl_teardown; @@ -654,11 +672,10 @@ static void vmbus_ongpadl_torndown( /* * Find the open msg, copy the result and signal/unblock the wait event */ - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); - list_for_each(curr, &gVmbusConnection.ChannelMsgList) { -/* FIXME: this should probably use list_entry() instead */ - msginfo = (struct vmbus_channel_msginfo *)curr; + list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, + msglistentry) { requestheader = (struct vmbus_channel_message_header *)msginfo->msg; @@ -670,12 +687,13 @@ static void vmbus_ongpadl_torndown( memcpy(&msginfo->response.gpadl_torndown, gpadl_torndown, sizeof(struct vmbus_channel_gpadl_torndown)); - osd_waitevent_set(msginfo->waitevent); + msginfo->wait_condition = 1; + wake_up(&msginfo->waitevent); break; } } } - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); } /* @@ -688,7 +706,6 @@ static void vmbus_ongpadl_torndown( static void vmbus_onversion_response( struct vmbus_channel_message_header *hdr) { - struct list_head *curr; struct vmbus_channel_msginfo *msginfo; struct vmbus_channel_message_header *requestheader; struct vmbus_channel_initiate_contact *initiate; @@ -696,11 +713,10 @@ static void vmbus_onversion_response( unsigned long flags; version_response = (struct vmbus_channel_version_response *)hdr; - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); - list_for_each(curr, &gVmbusConnection.ChannelMsgList) { -/* FIXME: this should probably use list_entry() instead */ - msginfo = (struct vmbus_channel_msginfo *)curr; + list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, + msglistentry) { requestheader = (struct vmbus_channel_message_header *)msginfo->msg; @@ -711,10 +727,11 @@ static void vmbus_onversion_response( memcpy(&msginfo->response.version_response, version_response, sizeof(struct vmbus_channel_version_response)); - osd_waitevent_set(msginfo->waitevent); + msginfo->wait_condition = 1; + wake_up(&msginfo->waitevent); } } - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); } /* Channel message dispatch table */ @@ -786,44 +803,33 @@ int vmbus_request_offers(void) if (!msginfo) return -ENOMEM; - msginfo->waitevent = osd_waitevent_create(); - if (!msginfo->waitevent) { - kfree(msginfo); - return -ENOMEM; - } + init_waitqueue_head(&msginfo->waitevent); msg = (struct vmbus_channel_message_header *)msginfo->msg; msg->msgtype = CHANNELMSG_REQUESTOFFERS; - /*SpinlockAcquire(gVmbusConnection.channelMsgLock); - INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, - &msgInfo->msgListEntry); - SpinlockRelease(gVmbusConnection.channelMsgLock);*/ - ret = VmbusPostMessage(msg, + ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_message_header)); if (ret != 0) { DPRINT_ERR(VMBUS, "Unable to request offers - %d", ret); - /*SpinlockAcquire(gVmbusConnection.channelMsgLock); - REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); - SpinlockRelease(gVmbusConnection.channelMsgLock);*/ + goto cleanup; + } - goto Cleanup; + msginfo->wait_condition = 0; + wait_event_timeout(msginfo->waitevent, msginfo->wait_condition, + msecs_to_jiffies(1000)); + if (msginfo->wait_condition == 0) { + ret = -ETIMEDOUT; + goto cleanup; } - /* osd_waitevent_wait(msgInfo->waitEvent); */ - /*SpinlockAcquire(gVmbusConnection.channelMsgLock); - REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); - SpinlockRelease(gVmbusConnection.channelMsgLock);*/ -Cleanup: - if (msginfo) { - kfree(msginfo->waitevent); - kfree(msginfo); - } +cleanup: + kfree(msginfo); return ret; } @@ -838,14 +844,14 @@ void vmbus_release_unattached_channels(void) struct vmbus_channel *start = NULL; unsigned long flags; - spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); + spin_lock_irqsave(&vmbus_connection.channel_lock, flags); - list_for_each_entry_safe(channel, pos, &gVmbusConnection.ChannelList, + list_for_each_entry_safe(channel, pos, &vmbus_connection.chn_list, listentry) { if (channel == start) break; - if (!channel->device_obj->Driver) { + if (!channel->device_obj->drv) { list_del(&channel->listentry); DPRINT_INFO(VMBUS, "Releasing unattached device object %p", @@ -859,7 +865,7 @@ void vmbus_release_unattached_channels(void) } } - spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); } /* eof */ diff --git a/drivers/staging/hv/channel_mgmt.h b/drivers/staging/hv/channel_mgmt.h index de6b2a0ebf70..96f74e2a3c7f 100644 --- a/drivers/staging/hv/channel_mgmt.h +++ b/drivers/staging/hv/channel_mgmt.h @@ -27,6 +27,7 @@ #include <linux/list.h> #include <linux/timer.h> +#include <linux/workqueue.h> #include "ring_buffer.h" #include "vmbus_channel_interface.h" #include "vmbus_packet_format.h" @@ -60,19 +61,19 @@ enum vmbus_channel_message_type { struct vmbus_channel_message_header { enum vmbus_channel_message_type msgtype; u32 padding; -} __attribute__((packed)); +} __packed; /* Query VMBus Version parameters */ struct vmbus_channel_query_vmbus_version { struct vmbus_channel_message_header header; u32 version; -} __attribute__((packed)); +} __packed; /* VMBus Version Supported parameters */ struct vmbus_channel_version_supported { struct vmbus_channel_message_header header; bool version_supported; -} __attribute__((packed)); +} __packed; /* Offer Channel parameters */ struct vmbus_channel_offer_channel { @@ -81,13 +82,13 @@ struct vmbus_channel_offer_channel { u32 child_relid; u8 monitorid; bool monitor_allocated; -} __attribute__((packed)); +} __packed; /* Rescind Offer parameters */ struct vmbus_channel_rescind_offer { struct vmbus_channel_message_header header; u32 child_relid; -} __attribute__((packed)); +} __packed; /* * Request Offer -- no parameters, SynIC message contains the partition ID @@ -123,7 +124,7 @@ struct vmbus_channel_open_channel { /* User-specific data to be passed along to the server endpoint. */ unsigned char userdata[MAX_USER_DEFINED_BYTES]; -} __attribute__((packed)); +} __packed; /* Open Channel Result parameters */ struct vmbus_channel_open_result { @@ -131,13 +132,13 @@ struct vmbus_channel_open_result { u32 child_relid; u32 openid; u32 status; -} __attribute__((packed)); +} __packed; /* Close channel parameters; */ struct vmbus_channel_close_channel { struct vmbus_channel_message_header header; u32 child_relid; -} __attribute__((packed)); +} __packed; /* Channel Message GPADL */ #define GPADL_TYPE_RING_BUFFER 1 @@ -157,7 +158,7 @@ struct vmbus_channel_gpadl_header { u16 range_buflen; u16 rangecount; struct gpa_range range[0]; -} __attribute__((packed)); +} __packed; /* This is the followup packet that contains more PFNs. */ struct vmbus_channel_gpadl_body { @@ -165,25 +166,25 @@ struct vmbus_channel_gpadl_body { u32 msgnumber; u32 gpadl; u64 pfn[0]; -} __attribute__((packed)); +} __packed; struct vmbus_channel_gpadl_created { struct vmbus_channel_message_header header; u32 child_relid; u32 gpadl; u32 creation_status; -} __attribute__((packed)); +} __packed; struct vmbus_channel_gpadl_teardown { struct vmbus_channel_message_header header; u32 child_relid; u32 gpadl; -} __attribute__((packed)); +} __packed; struct vmbus_channel_gpadl_torndown { struct vmbus_channel_message_header header; u32 gpadl; -} __attribute__((packed)); +} __packed; #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD struct vmbus_channel_view_range_add { @@ -191,19 +192,19 @@ struct vmbus_channel_view_range_add { PHYSICAL_ADDRESS viewrange_base; u64 viewrange_length; u32 child_relid; -} __attribute__((packed)); +} __packed; struct vmbus_channel_view_range_remove { struct vmbus_channel_message_header header; PHYSICAL_ADDRESS viewrange_base; u32 child_relid; -} __attribute__((packed)); +} __packed; #endif struct vmbus_channel_relid_released { struct vmbus_channel_message_header header; u32 child_relid; -} __attribute__((packed)); +} __packed; struct vmbus_channel_initiate_contact { struct vmbus_channel_message_header header; @@ -212,12 +213,12 @@ struct vmbus_channel_initiate_contact { u64 interrupt_page; u64 monitor_page1; u64 monitor_page2; -} __attribute__((packed)); +} __packed; struct vmbus_channel_version_response { struct vmbus_channel_message_header header; bool version_supported; -} __attribute__((packed)); +} __packed; enum vmbus_channel_state { CHANNEL_OFFER_STATE, @@ -289,8 +290,8 @@ struct vmbus_channel_msginfo { struct list_head submsglist; /* Synchronize the request/response if needed */ - struct osd_waitevent *waitevent; - + int wait_condition; + wait_queue_head_t waitevent; union { struct vmbus_channel_version_supported version_supported; struct vmbus_channel_open_result open_result; diff --git a/drivers/staging/hv/connection.c b/drivers/staging/hv/connection.c index c2e298ff4834..44b203b95a22 100644 --- a/drivers/staging/hv/connection.c +++ b/drivers/staging/hv/connection.c @@ -21,127 +21,143 @@ * */ #include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/wait.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/vmalloc.h> -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "vmbus_private.h" -struct VMBUS_CONNECTION gVmbusConnection = { - .ConnectState = Disconnected, - .NextGpadlHandle = ATOMIC_INIT(0xE1E10), +struct vmbus_connection vmbus_connection = { + .conn_state = DISCONNECTED, + .next_gpadl_handle = ATOMIC_INIT(0xE1E10), }; /* - * VmbusConnect - Sends a connect request on the partition service connection + * vmbus_connect - Sends a connect request on the partition service connection */ -int VmbusConnect(void) +int vmbus_connect(void) { int ret = 0; - struct vmbus_channel_msginfo *msgInfo = NULL; + struct vmbus_channel_msginfo *msginfo = NULL; struct vmbus_channel_initiate_contact *msg; unsigned long flags; /* Make sure we are not connecting or connected */ - if (gVmbusConnection.ConnectState != Disconnected) + if (vmbus_connection.conn_state != DISCONNECTED) return -1; /* Initialize the vmbus connection */ - gVmbusConnection.ConnectState = Connecting; - gVmbusConnection.WorkQueue = create_workqueue("hv_vmbus_con"); - if (!gVmbusConnection.WorkQueue) { + vmbus_connection.conn_state = CONNECTING; + vmbus_connection.work_queue = create_workqueue("hv_vmbus_con"); + if (!vmbus_connection.work_queue) { ret = -1; goto Cleanup; } - INIT_LIST_HEAD(&gVmbusConnection.ChannelMsgList); - spin_lock_init(&gVmbusConnection.channelmsg_lock); + INIT_LIST_HEAD(&vmbus_connection.chn_msg_list); + spin_lock_init(&vmbus_connection.channelmsg_lock); - INIT_LIST_HEAD(&gVmbusConnection.ChannelList); - spin_lock_init(&gVmbusConnection.channel_lock); + INIT_LIST_HEAD(&vmbus_connection.chn_list); + spin_lock_init(&vmbus_connection.channel_lock); /* * Setup the vmbus event connection for channel interrupt * abstraction stuff */ - gVmbusConnection.InterruptPage = osd_page_alloc(1); - if (gVmbusConnection.InterruptPage == NULL) { + vmbus_connection.int_page = + (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, 0); + if (vmbus_connection.int_page == NULL) { ret = -1; goto Cleanup; } - gVmbusConnection.RecvInterruptPage = gVmbusConnection.InterruptPage; - gVmbusConnection.SendInterruptPage = - (void *)((unsigned long)gVmbusConnection.InterruptPage + + vmbus_connection.recv_int_page = vmbus_connection.int_page; + vmbus_connection.send_int_page = + (void *)((unsigned long)vmbus_connection.int_page + (PAGE_SIZE >> 1)); /* * Setup the monitor notification facility. The 1st page for * parent->child and the 2nd page for child->parent */ - gVmbusConnection.MonitorPages = osd_page_alloc(2); - if (gVmbusConnection.MonitorPages == NULL) { + vmbus_connection.monitor_pages = + (void *)__get_free_pages((GFP_KERNEL|__GFP_ZERO), 1); + if (vmbus_connection.monitor_pages == NULL) { ret = -1; goto Cleanup; } - msgInfo = kzalloc(sizeof(*msgInfo) + + msginfo = kzalloc(sizeof(*msginfo) + sizeof(struct vmbus_channel_initiate_contact), GFP_KERNEL); - if (msgInfo == NULL) { + if (msginfo == NULL) { ret = -ENOMEM; goto Cleanup; } - msgInfo->waitevent = osd_waitevent_create(); - if (!msgInfo->waitevent) { - ret = -ENOMEM; - goto Cleanup; - } + init_waitqueue_head(&msginfo->waitevent); - msg = (struct vmbus_channel_initiate_contact *)msgInfo->msg; + msg = (struct vmbus_channel_initiate_contact *)msginfo->msg; msg->header.msgtype = CHANNELMSG_INITIATE_CONTACT; msg->vmbus_version_requested = VMBUS_REVISION_NUMBER; - msg->interrupt_page = virt_to_phys(gVmbusConnection.InterruptPage); - msg->monitor_page1 = virt_to_phys(gVmbusConnection.MonitorPages); + msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); + msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages); msg->monitor_page2 = virt_to_phys( - (void *)((unsigned long)gVmbusConnection.MonitorPages + + (void *)((unsigned long)vmbus_connection.monitor_pages + PAGE_SIZE)); /* * Add to list before we send the request since we may * receive the response before returning from this routine */ - spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - list_add_tail(&msgInfo->msglistentry, - &gVmbusConnection.ChannelMsgList); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); + list_add_tail(&msginfo->msglistentry, + &vmbus_connection.chn_msg_list); - spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, " "monitor1 pfn %llx,, monitor2 pfn %llx", msg->interrupt_page, msg->monitor_page1, msg->monitor_page2); DPRINT_DBG(VMBUS, "Sending channel initiate msg..."); - ret = VmbusPostMessage(msg, + ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_initiate_contact)); if (ret != 0) { - list_del(&msgInfo->msglistentry); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); + list_del(&msginfo->msglistentry); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, + flags); goto Cleanup; } /* Wait for the connection response */ - osd_waitevent_wait(msgInfo->waitevent); + msginfo->wait_condition = 0; + wait_event_timeout(msginfo->waitevent, msginfo->wait_condition, + msecs_to_jiffies(1000)); + if (msginfo->wait_condition == 0) { + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, + flags); + list_del(&msginfo->msglistentry); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, + flags); + ret = -ETIMEDOUT; + goto Cleanup; + } - list_del(&msgInfo->msglistentry); + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); + list_del(&msginfo->msglistentry); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); /* Check if successful */ - if (msgInfo->response.version_response.version_supported) { + if (msginfo->response.version_response.version_supported) { DPRINT_INFO(VMBUS, "Vmbus connected!!"); - gVmbusConnection.ConnectState = Connected; + vmbus_connection.conn_state = CONNECTED; } else { DPRINT_ERR(VMBUS, "Vmbus connection failed!!..." @@ -151,44 +167,41 @@ int VmbusConnect(void) goto Cleanup; } - kfree(msgInfo->waitevent); - kfree(msgInfo); + kfree(msginfo); return 0; Cleanup: - gVmbusConnection.ConnectState = Disconnected; + vmbus_connection.conn_state = DISCONNECTED; - if (gVmbusConnection.WorkQueue) - destroy_workqueue(gVmbusConnection.WorkQueue); + if (vmbus_connection.work_queue) + destroy_workqueue(vmbus_connection.work_queue); - if (gVmbusConnection.InterruptPage) { - osd_page_free(gVmbusConnection.InterruptPage, 1); - gVmbusConnection.InterruptPage = NULL; + if (vmbus_connection.int_page) { + free_pages((unsigned long)vmbus_connection.int_page, 0); + vmbus_connection.int_page = NULL; } - if (gVmbusConnection.MonitorPages) { - osd_page_free(gVmbusConnection.MonitorPages, 2); - gVmbusConnection.MonitorPages = NULL; + if (vmbus_connection.monitor_pages) { + free_pages((unsigned long)vmbus_connection.monitor_pages, 1); + vmbus_connection.monitor_pages = NULL; } - if (msgInfo) { - kfree(msgInfo->waitevent); - kfree(msgInfo); - } + kfree(msginfo); return ret; } /* - * VmbusDisconnect - Sends a disconnect request on the partition service connection + * vmbus_disconnect - + * Sends a disconnect request on the partition service connection */ -int VmbusDisconnect(void) +int vmbus_disconnect(void) { int ret = 0; struct vmbus_channel_message_header *msg; /* Make sure we are connected */ - if (gVmbusConnection.ConnectState != Connected) + if (vmbus_connection.conn_state != CONNECTED) return -1; msg = kzalloc(sizeof(struct vmbus_channel_message_header), GFP_KERNEL); @@ -197,17 +210,18 @@ int VmbusDisconnect(void) msg->msgtype = CHANNELMSG_UNLOAD; - ret = VmbusPostMessage(msg, + ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_message_header)); if (ret != 0) goto Cleanup; - osd_page_free(gVmbusConnection.InterruptPage, 1); + free_pages((unsigned long)vmbus_connection.int_page, 0); + free_pages((unsigned long)vmbus_connection.monitor_pages, 1); /* TODO: iterate thru the msg list and free up */ - destroy_workqueue(gVmbusConnection.WorkQueue); + destroy_workqueue(vmbus_connection.work_queue); - gVmbusConnection.ConnectState = Disconnected; + vmbus_connection.conn_state = DISCONNECTED; DPRINT_INFO(VMBUS, "Vmbus disconnected!!"); @@ -217,33 +231,34 @@ Cleanup: } /* - * GetChannelFromRelId - Get the channel object given its child relative id (ie channel id) + * relid2channel - Get the channel object given its + * child relative id (ie channel id) */ -struct vmbus_channel *GetChannelFromRelId(u32 relId) +struct vmbus_channel *relid2channel(u32 relid) { struct vmbus_channel *channel; - struct vmbus_channel *foundChannel = NULL; + struct vmbus_channel *found_channel = NULL; unsigned long flags; - spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); - list_for_each_entry(channel, &gVmbusConnection.ChannelList, listentry) { - if (channel->offermsg.child_relid == relId) { - foundChannel = channel; + spin_lock_irqsave(&vmbus_connection.channel_lock, flags); + list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { + if (channel->offermsg.child_relid == relid) { + found_channel = channel; break; } } - spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); + spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); - return foundChannel; + return found_channel; } /* - * VmbusProcessChannelEvent - Process a channel event notification + * process_chn_event - Process a channel event notification */ -static void VmbusProcessChannelEvent(void *context) +static void process_chn_event(void *context) { struct vmbus_channel *channel; - u32 relId = (u32)(unsigned long)context; + u32 relid = (u32)(unsigned long)context; /* ASSERT(relId > 0); */ @@ -251,7 +266,7 @@ static void VmbusProcessChannelEvent(void *context) * Find the channel based on this relid and invokes the * channel callback to process the event */ - channel = GetChannelFromRelId(relId); + channel = relid2channel(relid); if (channel) { vmbus_onchannel_event(channel); @@ -261,27 +276,29 @@ static void VmbusProcessChannelEvent(void *context) * (void*)channel); */ } else { - DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId); + DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relid); } } /* - * VmbusOnEvents - Handler for events + * vmbus_on_event - Handler for events */ -void VmbusOnEvents(void) +void vmbus_on_event(unsigned long data) { int dword; int maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; int bit; int relid; - u32 *recvInterruptPage = gVmbusConnection.RecvInterruptPage; + u32 *recv_int_page = vmbus_connection.recv_int_page; /* Check events */ - if (recvInterruptPage) { + if (recv_int_page) { for (dword = 0; dword < maxdword; dword++) { - if (recvInterruptPage[dword]) { + if (recv_int_page[dword]) { for (bit = 0; bit < 32; bit++) { - if (test_and_clear_bit(bit, (unsigned long *)&recvInterruptPage[dword])) { + if (test_and_clear_bit(bit, + (unsigned long *) + &recv_int_page[dword])) { relid = (dword << 5) + bit; DPRINT_DBG(VMBUS, "event detected for relid - %d", relid); @@ -292,7 +309,8 @@ void VmbusOnEvents(void) } else { /* QueueWorkItem(VmbusProcessEvent, (void*)relid); */ /* ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid); */ - VmbusProcessChannelEvent((void *)(unsigned long)relid); + process_chn_event((void *) + (unsigned long)relid); } } } @@ -303,26 +321,26 @@ void VmbusOnEvents(void) } /* - * VmbusPostMessage - Send a msg on the vmbus's message connection + * vmbus_post_msg - Send a msg on the vmbus's message connection */ -int VmbusPostMessage(void *buffer, size_t bufferLen) +int vmbus_post_msg(void *buffer, size_t buflen) { - union hv_connection_id connId; + union hv_connection_id conn_id; - connId.asu32 = 0; - connId.u.id = VMBUS_MESSAGE_CONNECTION_ID; - return hv_post_message(connId, 1, buffer, bufferLen); + conn_id.asu32 = 0; + conn_id.u.id = VMBUS_MESSAGE_CONNECTION_ID; + return hv_post_message(conn_id, 1, buffer, buflen); } /* - * VmbusSetEvent - Send an event notification to the parent + * vmbus_set_event - Send an event notification to the parent */ -int VmbusSetEvent(u32 childRelId) +int vmbus_set_event(u32 child_relid) { /* Each u32 represents 32 channels */ - set_bit(childRelId & 31, - (unsigned long *)gVmbusConnection.SendInterruptPage + - (childRelId >> 5)); + set_bit(child_relid & 31, + (unsigned long *)vmbus_connection.send_int_page + + (child_relid >> 5)); return hv_signal_event(); } diff --git a/drivers/staging/hv/hv.c b/drivers/staging/hv/hv.c index a34d713d9c57..2d492adb95bb 100644 --- a/drivers/staging/hv/hv.c +++ b/drivers/staging/hv/hv.c @@ -23,7 +23,7 @@ #include <linux/mm.h> #include <linux/slab.h> #include <linux/vmalloc.h> -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "vmbus_private.h" @@ -230,7 +230,7 @@ int hv_init(void) * Allocate the hypercall page memory * virtaddr = osd_page_alloc(1); */ - virtaddr = osd_virtual_alloc_exec(PAGE_SIZE); + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC); if (!virtaddr) { DPRINT_ERR(VMBUS, @@ -267,7 +267,7 @@ int hv_init(void) hv_context.signal_event_param = (struct hv_input_signal_event *) - (ALIGN_UP((unsigned long) + (ALIGN((unsigned long) hv_context.signal_event_buffer, HV_HYPERCALL_PARAM_ALIGN)); hv_context.signal_event_param->connectionid.asu32 = 0; @@ -338,7 +338,7 @@ u16 hv_post_message(union hv_connection_id connection_id, return -1; aligned_msg = (struct hv_input_post_message *) - (ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN)); + (ALIGN(addr, HV_HYPERCALL_PARAM_ALIGN)); aligned_msg->connectionid = connection_id; aligned_msg->message_type = message_type; @@ -462,10 +462,10 @@ void hv_synic_init(void *irqarg) Cleanup: if (hv_context.synic_event_page[cpu]) - osd_page_free(hv_context.synic_event_page[cpu], 1); + free_page((unsigned long)hv_context.synic_event_page[cpu]); if (hv_context.synic_message_page[cpu]) - osd_page_free(hv_context.synic_message_page[cpu], 1); + free_page((unsigned long)hv_context.synic_message_page[cpu]); return; } @@ -502,6 +502,6 @@ void hv_synic_cleanup(void *arg) wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); - osd_page_free(hv_context.synic_message_page[cpu], 1); - osd_page_free(hv_context.synic_event_page[cpu], 1); + free_page((unsigned long)hv_context.synic_message_page[cpu]); + free_page((unsigned long)hv_context.synic_event_page[cpu]); } diff --git a/drivers/staging/hv/hv_api.h b/drivers/staging/hv/hv_api.h index 70e863ad0464..7114fceab21e 100644 --- a/drivers/staging/hv/hv_api.h +++ b/drivers/staging/hv/hv_api.h @@ -23,6 +23,11 @@ #ifndef __HV_API_H #define __HV_API_H +struct hv_guid { + unsigned char data[16]; +}; + + /* Status codes for hypervisor operations. */ diff --git a/drivers/staging/hv/hv_kvp.c b/drivers/staging/hv/hv_kvp.c new file mode 100644 index 000000000000..faf692e4126e --- /dev/null +++ b/drivers/staging/hv/hv_kvp.c @@ -0,0 +1,346 @@ +/* + * An implementation of key value pair (KVP) functionality for Linux. + * + * + * Copyright (C) 2010, Novell, Inc. + * Author : K. Y. Srinivasan <ksrinivasan@novell.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or + * NON INFRINGEMENT. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + + +#include <linux/net.h> +#include <linux/nls.h> +#include <linux/connector.h> +#include <linux/workqueue.h> + +#include "logging.h" +#include "hv_api.h" +#include "vmbus.h" +#include "vmbus_packet_format.h" +#include "vmbus_channel_interface.h" +#include "version_info.h" +#include "channel.h" +#include "vmbus_private.h" +#include "vmbus_api.h" +#include "utils.h" +#include "hv_kvp.h" + + + +/* + * Global state maintained for transaction that is being processed. + * Note that only one transaction can be active at any point in time. + * + * This state is set when we receive a request from the host; we + * cleanup this state when the transaction is completed - when we respond + * to the host with the key value. + */ + +static struct { + bool active; /* transaction status - active or not */ + int recv_len; /* number of bytes received. */ + struct vmbus_channel *recv_channel; /* chn we got the request */ + u64 recv_req_id; /* request ID. */ +} kvp_transaction; + +static int kvp_send_key(int index); + +static void kvp_respond_to_host(char *key, char *value, int error); +static void kvp_work_func(struct work_struct *dummy); +static void kvp_register(void); + +static DECLARE_DELAYED_WORK(kvp_work, kvp_work_func); + +static struct cb_id kvp_id = { CN_KVP_IDX, CN_KVP_VAL }; +static const char kvp_name[] = "kvp_kernel_module"; +static int timeout_fired; +static u8 *recv_buffer; +/* + * Register the kernel component with the user-level daemon. + * As part of this registration, pass the LIC version number. + */ + +static void +kvp_register(void) +{ + + struct cn_msg *msg; + + msg = kzalloc(sizeof(*msg) + strlen(HV_DRV_VERSION) + 1 , GFP_ATOMIC); + + if (msg) { + msg->id.idx = CN_KVP_IDX; + msg->id.val = CN_KVP_VAL; + msg->seq = KVP_REGISTER; + strcpy(msg->data, HV_DRV_VERSION); + msg->len = strlen(HV_DRV_VERSION) + 1; + cn_netlink_send(msg, 0, GFP_ATOMIC); + kfree(msg); + } +} +static void +kvp_work_func(struct work_struct *dummy) +{ + /* + * If the timer fires, the user-mode component has not responded; + * process the pending transaction. + */ + kvp_respond_to_host("Unknown key", "Guest timed out", timeout_fired); + timeout_fired = 1; +} + +/* + * Callback when data is received from user mode. + */ + +static void +kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) +{ + struct hv_ku_msg *message; + + message = (struct hv_ku_msg *)msg->data; + if (msg->seq == KVP_REGISTER) { + printk(KERN_INFO "KVP: user-mode registering done.\n"); + kvp_register(); + } + + if (msg->seq == KVP_USER_SET) { + /* + * Complete the transaction by forwarding the key value + * to the host. But first, cancel the timeout. + */ + if (cancel_delayed_work_sync(&kvp_work)) + kvp_respond_to_host(message->kvp_key, + message->kvp_value, + !strlen(message->kvp_key)); + } +} + +static int +kvp_send_key(int index) +{ + struct cn_msg *msg; + + msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg) , GFP_ATOMIC); + + if (msg) { + msg->id.idx = CN_KVP_IDX; + msg->id.val = CN_KVP_VAL; + msg->seq = KVP_KERNEL_GET; + ((struct hv_ku_msg *)msg->data)->kvp_index = index; + msg->len = sizeof(struct hv_ku_msg); + cn_netlink_send(msg, 0, GFP_ATOMIC); + kfree(msg); + return 0; + } + return 1; +} + +/* + * Send a response back to the host. + */ + +static void +kvp_respond_to_host(char *key, char *value, int error) +{ + struct hv_kvp_msg *kvp_msg; + struct hv_kvp_msg_enumerate *kvp_data; + char *key_name; + struct icmsg_hdr *icmsghdrp; + int keylen, valuelen; + u32 buf_len; + struct vmbus_channel *channel; + u64 req_id; + + /* + * If a transaction is not active; log and return. + */ + + if (!kvp_transaction.active) { + /* + * This is a spurious call! + */ + printk(KERN_WARNING "KVP: Transaction not active\n"); + return; + } + /* + * Copy the global state for completing the transaction. Note that + * only one transaction can be active at a time. + */ + + buf_len = kvp_transaction.recv_len; + channel = kvp_transaction.recv_channel; + req_id = kvp_transaction.recv_req_id; + + icmsghdrp = (struct icmsg_hdr *) + &recv_buffer[sizeof(struct vmbuspipe_hdr)]; + kvp_msg = (struct hv_kvp_msg *) + &recv_buffer[sizeof(struct vmbuspipe_hdr) + + sizeof(struct icmsg_hdr)]; + kvp_data = &kvp_msg->kvp_data; + key_name = key; + + /* + * If the error parameter is set, terminate the host's enumeration. + */ + if (error) { + /* + * We don't support this index or the we have timedout; + * terminate the host-side iteration by returning an error. + */ + icmsghdrp->status = HV_E_FAIL; + goto response_done; + } + + /* + * The windows host expects the key/value pair to be encoded + * in utf16. + */ + keylen = utf8s_to_utf16s(key_name, strlen(key_name), + (wchar_t *)kvp_data->data.key); + kvp_data->data.key_size = 2*(keylen + 1); /* utf16 encoding */ + valuelen = utf8s_to_utf16s(value, strlen(value), + (wchar_t *)kvp_data->data.value); + kvp_data->data.value_size = 2*(valuelen + 1); /* utf16 encoding */ + + kvp_data->data.value_type = REG_SZ; /* all our values are strings */ + icmsghdrp->status = HV_S_OK; + +response_done: + icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; + + vmbus_sendpacket(channel, recv_buffer, buf_len, req_id, + VM_PKT_DATA_INBAND, 0); + + kvp_transaction.active = false; +} + +/* + * This callback is invoked when we get a KVP message from the host. + * The host ensures that only one KVP transaction can be active at a time. + * KVP implementation in Linux needs to forward the key to a user-mde + * component to retrive the corresponding value. Consequently, we cannot + * respond to the host in the conext of this callback. Since the host + * guarantees that at most only one transaction can be active at a time, + * we stash away the transaction state in a set of global variables. + */ + +void hv_kvp_onchannelcallback(void *context) +{ + struct vmbus_channel *channel = context; + u32 recvlen; + u64 requestid; + + struct hv_kvp_msg *kvp_msg; + struct hv_kvp_msg_enumerate *kvp_data; + + struct icmsg_hdr *icmsghdrp; + struct icmsg_negotiate *negop = NULL; + + + if (kvp_transaction.active) + return; + + + vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE, &recvlen, &requestid); + + if (recvlen > 0) { + DPRINT_DBG(VMBUS, "KVP packet: len=%d, requestid=%lld", + recvlen, requestid); + + icmsghdrp = (struct icmsg_hdr *)&recv_buffer[ + sizeof(struct vmbuspipe_hdr)]; + + if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { + prep_negotiate_resp(icmsghdrp, negop, recv_buffer); + } else { + kvp_msg = (struct hv_kvp_msg *)&recv_buffer[ + sizeof(struct vmbuspipe_hdr) + + sizeof(struct icmsg_hdr)]; + + kvp_data = &kvp_msg->kvp_data; + + /* + * We only support the "get" operation on + * "KVP_POOL_AUTO" pool. + */ + + if ((kvp_msg->kvp_hdr.pool != KVP_POOL_AUTO) || + (kvp_msg->kvp_hdr.operation != + KVP_OP_ENUMERATE)) { + icmsghdrp->status = HV_E_FAIL; + goto callback_done; + } + + /* + * Stash away this global state for completing the + * transaction; note transactions are serialized. + */ + kvp_transaction.recv_len = recvlen; + kvp_transaction.recv_channel = channel; + kvp_transaction.recv_req_id = requestid; + kvp_transaction.active = true; + + /* + * Get the information from the + * user-mode component. + * component. This transaction will be + * completed when we get the value from + * the user-mode component. + * Set a timeout to deal with + * user-mode not responding. + */ + kvp_send_key(kvp_data->index); + schedule_delayed_work(&kvp_work, 100); + + return; + + } + +callback_done: + + icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION + | ICMSGHDRFLAG_RESPONSE; + + vmbus_sendpacket(channel, recv_buffer, + recvlen, requestid, + VM_PKT_DATA_INBAND, 0); + } + +} + +int +hv_kvp_init(void) +{ + int err; + + err = cn_add_callback(&kvp_id, kvp_name, kvp_cn_callback); + if (err) + return err; + recv_buffer = kmalloc(PAGE_SIZE, GFP_KERNEL); + if (!recv_buffer) + return -ENOMEM; + + return 0; +} + +void hv_kvp_deinit(void) +{ + cn_del_callback(&kvp_id); + cancel_delayed_work_sync(&kvp_work); + kfree(recv_buffer); +} diff --git a/drivers/staging/hv/hv_kvp.h b/drivers/staging/hv/hv_kvp.h new file mode 100644 index 000000000000..e069f59b5135 --- /dev/null +++ b/drivers/staging/hv/hv_kvp.h @@ -0,0 +1,184 @@ +/* + * An implementation of HyperV key value pair (KVP) functionality for Linux. + * + * + * Copyright (C) 2010, Novell, Inc. + * Author : K. Y. Srinivasan <ksrinivasan@novell.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or + * NON INFRINGEMENT. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ +#ifndef _KVP_H +#define _KVP_H_ + +/* + * Maximum value size - used for both key names and value data, and includes + * any applicable NULL terminators. + * + * Note: This limit is somewhat arbitrary, but falls easily within what is + * supported for all native guests (back to Win 2000) and what is reasonable + * for the IC KVP exchange functionality. Note that Windows Me/98/95 are + * limited to 255 character key names. + * + * MSDN recommends not storing data values larger than 2048 bytes in the + * registry. + * + * Note: This value is used in defining the KVP exchange message - this value + * cannot be modified without affecting the message size and compatability. + */ + +/* + * bytes, including any null terminators + */ +#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048) + + +/* + * Maximum key size - the registry limit for the length of an entry name + * is 256 characters, including the null terminator + */ + +#define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512) + +/* + * In Linux, we implement the KVP functionality in two components: + * 1) The kernel component which is packaged as part of the hv_utils driver + * is responsible for communicating with the host and responsible for + * implementing the host/guest protocol. 2) A user level daemon that is + * responsible for data gathering. + * + * Host/Guest Protocol: The host iterates over an index and expects the guest + * to assign a key name to the index and also return the value corresponding to + * the key. The host will have atmost one KVP transaction outstanding at any + * given point in time. The host side iteration stops when the guest returns + * an error. Microsoft has specified the following mapping of key names to + * host specified index: + * + * Index Key Name + * 0 FullyQualifiedDomainName + * 1 IntegrationServicesVersion + * 2 NetworkAddressIPv4 + * 3 NetworkAddressIPv6 + * 4 OSBuildNumber + * 5 OSName + * 6 OSMajorVersion + * 7 OSMinorVersion + * 8 OSVersion + * 9 ProcessorArchitecture + * + * The Windows host expects the Key Name and Key Value to be encoded in utf16. + * + * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the + * data gathering functionality in a user mode daemon. The user level daemon + * is also responsible for binding the key name to the index as well. The + * kernel and user-level daemon communicate using a connector channel. + * + * The user mode component first registers with the + * the kernel component. Subsequently, the kernel component requests, data + * for the specified keys. In response to this message the user mode component + * fills in the value corresponding to the specified key. We overload the + * sequence field in the cn_msg header to define our KVP message types. + * + * + * The kernel component simply acts as a conduit for communication between the + * Windows host and the user-level daemon. The kernel component passes up the + * index received from the Host to the user-level daemon. If the index is + * valid (supported), the corresponding key as well as its + * value (both are strings) is returned. If the index is invalid + * (not supported), a NULL key string is returned. + */ + +/* + * + * The following definitions are shared with the user-mode component; do not + * change any of this without making the corresponding changes in + * the KVP user-mode component. + */ + +#define CN_KVP_VAL 0x1 /* This supports queries from the kernel */ +#define CN_KVP_USER_VAL 0x2 /* This supports queries from the user */ + +enum hv_ku_op { + KVP_REGISTER = 0, /* Register the user mode component */ + KVP_KERNEL_GET, /* Kernel is requesting the value */ + KVP_KERNEL_SET, /* Kernel is providing the value */ + KVP_USER_GET, /* User is requesting the value */ + KVP_USER_SET /* User is providing the value */ +}; + +struct hv_ku_msg { + __u32 kvp_index; /* Key index */ + __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */ + __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */ +}; + + + + +#ifdef __KERNEL__ + +/* + * Registry value types. + */ + +#define REG_SZ 1 + +enum hv_kvp_exchg_op { + KVP_OP_GET = 0, + KVP_OP_SET, + KVP_OP_DELETE, + KVP_OP_ENUMERATE, + KVP_OP_COUNT /* Number of operations, must be last. */ +}; + +enum hv_kvp_exchg_pool { + KVP_POOL_EXTERNAL = 0, + KVP_POOL_GUEST, + KVP_POOL_AUTO, + KVP_POOL_AUTO_EXTERNAL, + KVP_POOL_AUTO_INTERNAL, + KVP_POOL_COUNT /* Number of pools, must be last. */ +}; + +struct hv_kvp_hdr { + u8 operation; + u8 pool; +}; + +struct hv_kvp_exchg_msg_value { + u32 value_type; + u32 key_size; + u32 value_size; + u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; + u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; +}; + +struct hv_kvp_msg_enumerate { + u32 index; + struct hv_kvp_exchg_msg_value data; +}; + +struct hv_kvp_msg { + struct hv_kvp_hdr kvp_hdr; + struct hv_kvp_msg_enumerate kvp_data; +}; + +int hv_kvp_init(void); +void hv_kvp_deinit(void); +void hv_kvp_onchannelcallback(void *); + +#endif /* __KERNEL__ */ +#endif /* _KVP_H */ + diff --git a/drivers/staging/hv/hv_mouse.c b/drivers/staging/hv/hv_mouse.c new file mode 100644 index 000000000000..50147f84741c --- /dev/null +++ b/drivers/staging/hv/hv_mouse.c @@ -0,0 +1,1046 @@ +/* + * Copyright (c) 2009, Citrix Systems, Inc. + * Copyright (c) 2010, Microsoft Corporation. + * Copyright (c) 2011, Novell Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ +#include <linux/init.h> +#include <linux/module.h> +#include <linux/device.h> +#include <linux/workqueue.h> +#include <linux/sched.h> +#include <linux/wait.h> +#include <linux/input.h> +#include <linux/hid.h> +#include <linux/hiddev.h> +#include <linux/pci.h> +#include <linux/dmi.h> + +#include "hv_api.h" +#include "logging.h" +#include "version_info.h" +#include "vmbus.h" +#include "vmbus_api.h" +#include "channel.h" +#include "vmbus_packet_format.h" + + +/* + * Data types + */ +struct hv_input_dev_info { + unsigned short vendor; + unsigned short product; + unsigned short version; + char name[128]; +}; + +/* Represents the input vsc driver */ +/* FIXME - can be removed entirely */ +struct mousevsc_drv_obj { + struct hv_driver Base; +}; + + +/* The maximum size of a synthetic input message. */ +#define SYNTHHID_MAX_INPUT_REPORT_SIZE 16 + +/* + * Current version + * + * History: + * Beta, RC < 2008/1/22 1,0 + * RC > 2008/1/22 2,0 + */ +#define SYNTHHID_INPUT_VERSION_MAJOR 2 +#define SYNTHHID_INPUT_VERSION_MINOR 0 +#define SYNTHHID_INPUT_VERSION (SYNTHHID_INPUT_VERSION_MINOR | \ + (SYNTHHID_INPUT_VERSION_MAJOR << 16)) + + +#pragma pack(push,1) +/* + * Message types in the synthetic input protocol + */ +enum synthhid_msg_type { + SynthHidProtocolRequest, + SynthHidProtocolResponse, + SynthHidInitialDeviceInfo, + SynthHidInitialDeviceInfoAck, + SynthHidInputReport, + SynthHidMax +}; + +/* + * Basic message structures. + */ +struct synthhid_msg_hdr { + enum synthhid_msg_type type; + u32 size; +}; + +struct synthhid_msg { + struct synthhid_msg_hdr header; + char data[1]; /* Enclosed message */ +}; + +union synthhid_version { + struct { + u16 minor_version; + u16 major_version; + }; + u32 version; +}; + +/* + * Protocol messages + */ +struct synthhid_protocol_request { + struct synthhid_msg_hdr header; + union synthhid_version version_requested; +}; + +struct synthhid_protocol_response { + struct synthhid_msg_hdr header; + union synthhid_version version_requested; + unsigned char approved; +}; + +struct synthhid_device_info { + struct synthhid_msg_hdr header; + struct hv_input_dev_info hid_dev_info; + struct hid_descriptor hid_descriptor; +}; + +struct synthhid_device_info_ack { + struct synthhid_msg_hdr header; + unsigned char reserved; +}; + +struct synthhid_input_report { + struct synthhid_msg_hdr header; + char buffer[1]; +}; + +#pragma pack(pop) + +#define INPUTVSC_SEND_RING_BUFFER_SIZE 10*PAGE_SIZE +#define INPUTVSC_RECV_RING_BUFFER_SIZE 10*PAGE_SIZE + +#define NBITS(x) (((x)/BITS_PER_LONG)+1) + +enum pipe_prot_msg_type { + PipeMessageInvalid = 0, + PipeMessageData, + PipeMessageMaximum +}; + + +struct pipe_prt_msg { + enum pipe_prot_msg_type type; + u32 size; + char data[1]; +}; + +/* + * Data types + */ +struct mousevsc_prt_msg { + enum pipe_prot_msg_type type; + u32 size; + union { + struct synthhid_protocol_request request; + struct synthhid_protocol_response response; + struct synthhid_device_info_ack ack; + }; +}; + +/* + * Represents an mousevsc device + */ +struct mousevsc_dev { + struct hv_device *Device; + /* 0 indicates the device is being destroyed */ + atomic_t RefCount; + int NumOutstandingRequests; + unsigned char bInitializeComplete; + struct mousevsc_prt_msg ProtocolReq; + struct mousevsc_prt_msg ProtocolResp; + /* Synchronize the request/response if needed */ + wait_queue_head_t ProtocolWaitEvent; + wait_queue_head_t DeviceInfoWaitEvent; + int protocol_wait_condition; + int device_wait_condition; + int DeviceInfoStatus; + + struct hid_descriptor *HidDesc; + unsigned char *ReportDesc; + u32 ReportDescSize; + struct hv_input_dev_info hid_dev_info; +}; + + +static const char *driver_name = "mousevsc"; + +/* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */ +static const struct hv_guid mouse_guid = { + .data = {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c, + 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A} +}; + +static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info); +static void inputreport_callback(struct hv_device *dev, void *packet, u32 len); +static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len); + +static struct mousevsc_dev *AllocInputDevice(struct hv_device *Device) +{ + struct mousevsc_dev *inputDevice; + + inputDevice = kzalloc(sizeof(struct mousevsc_dev), GFP_KERNEL); + + if (!inputDevice) + return NULL; + + /* + * Set to 2 to allow both inbound and outbound traffics + * (ie GetInputDevice() and MustGetInputDevice()) to proceed. + */ + atomic_cmpxchg(&inputDevice->RefCount, 0, 2); + + inputDevice->Device = Device; + Device->ext = inputDevice; + + return inputDevice; +} + +static void FreeInputDevice(struct mousevsc_dev *Device) +{ + WARN_ON(atomic_read(&Device->RefCount) == 0); + kfree(Device); +} + +/* + * Get the inputdevice object if exists and its refcount > 1 + */ +static struct mousevsc_dev *GetInputDevice(struct hv_device *Device) +{ + struct mousevsc_dev *inputDevice; + + inputDevice = (struct mousevsc_dev *)Device->ext; + +/* + * FIXME + * This sure isn't a valid thing to print for debugging, no matter + * what the intention is... + * + * printk(KERN_ERR "-------------------------> REFCOUNT = %d", + * inputDevice->RefCount); + */ + + if (inputDevice && atomic_read(&inputDevice->RefCount) > 1) + atomic_inc(&inputDevice->RefCount); + else + inputDevice = NULL; + + return inputDevice; +} + +/* + * Get the inputdevice object iff exists and its refcount > 0 + */ +static struct mousevsc_dev *MustGetInputDevice(struct hv_device *Device) +{ + struct mousevsc_dev *inputDevice; + + inputDevice = (struct mousevsc_dev *)Device->ext; + + if (inputDevice && atomic_read(&inputDevice->RefCount)) + atomic_inc(&inputDevice->RefCount); + else + inputDevice = NULL; + + return inputDevice; +} + +static void PutInputDevice(struct hv_device *Device) +{ + struct mousevsc_dev *inputDevice; + + inputDevice = (struct mousevsc_dev *)Device->ext; + + atomic_dec(&inputDevice->RefCount); +} + +/* + * Drop ref count to 1 to effectively disable GetInputDevice() + */ +static struct mousevsc_dev *ReleaseInputDevice(struct hv_device *Device) +{ + struct mousevsc_dev *inputDevice; + + inputDevice = (struct mousevsc_dev *)Device->ext; + + /* Busy wait until the ref drop to 2, then set it to 1 */ + while (atomic_cmpxchg(&inputDevice->RefCount, 2, 1) != 2) + udelay(100); + + return inputDevice; +} + +/* + * Drop ref count to 0. No one can use InputDevice object. + */ +static struct mousevsc_dev *FinalReleaseInputDevice(struct hv_device *Device) +{ + struct mousevsc_dev *inputDevice; + + inputDevice = (struct mousevsc_dev *)Device->ext; + + /* Busy wait until the ref drop to 1, then set it to 0 */ + while (atomic_cmpxchg(&inputDevice->RefCount, 1, 0) != 1) + udelay(100); + + Device->ext = NULL; + return inputDevice; +} + +static void MousevscOnSendCompletion(struct hv_device *Device, struct vmpacket_descriptor *Packet) +{ + struct mousevsc_dev *inputDevice; + void *request; + + inputDevice = MustGetInputDevice(Device); + if (!inputDevice) { + pr_err("unable to get input device...device being destroyed?"); + return; + } + + request = (void *)(unsigned long)Packet->trans_id; + + if (request == &inputDevice->ProtocolReq) { + /* FIXME */ + /* Shouldn't we be doing something here? */ + } + + PutInputDevice(Device); +} + +static void MousevscOnReceiveDeviceInfo(struct mousevsc_dev *InputDevice, struct synthhid_device_info *DeviceInfo) +{ + int ret = 0; + struct hid_descriptor *desc; + struct mousevsc_prt_msg ack; + + /* Assume success for now */ + InputDevice->DeviceInfoStatus = 0; + + /* Save the device attr */ + memcpy(&InputDevice->hid_dev_info, &DeviceInfo->hid_dev_info, sizeof(struct hv_input_dev_info)); + + /* Save the hid desc */ + desc = &DeviceInfo->hid_descriptor; + WARN_ON(desc->bLength > 0); + + InputDevice->HidDesc = kzalloc(desc->bLength, GFP_KERNEL); + + if (!InputDevice->HidDesc) { + pr_err("unable to allocate hid descriptor - size %d", desc->bLength); + goto Cleanup; + } + + memcpy(InputDevice->HidDesc, desc, desc->bLength); + + /* Save the report desc */ + InputDevice->ReportDescSize = desc->desc[0].wDescriptorLength; + InputDevice->ReportDesc = kzalloc(InputDevice->ReportDescSize, + GFP_KERNEL); + + if (!InputDevice->ReportDesc) { + pr_err("unable to allocate report descriptor - size %d", + InputDevice->ReportDescSize); + goto Cleanup; + } + + memcpy(InputDevice->ReportDesc, + ((unsigned char *)desc) + desc->bLength, + desc->desc[0].wDescriptorLength); + + /* Send the ack */ + memset(&ack, sizeof(struct mousevsc_prt_msg), 0); + + ack.type = PipeMessageData; + ack.size = sizeof(struct synthhid_device_info_ack); + + ack.ack.header.type = SynthHidInitialDeviceInfoAck; + ack.ack.header.size = 1; + ack.ack.reserved = 0; + + ret = vmbus_sendpacket(InputDevice->Device->channel, + &ack, + sizeof(struct pipe_prt_msg) - sizeof(unsigned char) + + sizeof(struct synthhid_device_info_ack), + (unsigned long)&ack, + VM_PKT_DATA_INBAND, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (ret != 0) { + pr_err("unable to send synthhid device info ack - ret %d", + ret); + goto Cleanup; + } + + InputDevice->device_wait_condition = 1; + wake_up(&InputDevice->DeviceInfoWaitEvent); + + return; + +Cleanup: + kfree(InputDevice->HidDesc); + InputDevice->HidDesc = NULL; + + kfree(InputDevice->ReportDesc); + InputDevice->ReportDesc = NULL; + + InputDevice->DeviceInfoStatus = -1; + InputDevice->device_wait_condition = 1; + wake_up(&InputDevice->DeviceInfoWaitEvent); +} + +static void MousevscOnReceiveInputReport(struct mousevsc_dev *InputDevice, struct synthhid_input_report *InputReport) +{ + struct mousevsc_drv_obj *inputDriver; + + if (!InputDevice->bInitializeComplete) { + pr_info("Initialization incomplete...ignoring InputReport msg"); + return; + } + + inputDriver = (struct mousevsc_drv_obj *)InputDevice->Device->drv; + + inputreport_callback(InputDevice->Device, + InputReport->buffer, + InputReport->header.size); +} + +static void MousevscOnReceive(struct hv_device *Device, struct vmpacket_descriptor *Packet) +{ + struct pipe_prt_msg *pipeMsg; + struct synthhid_msg *hidMsg; + struct mousevsc_dev *inputDevice; + + inputDevice = MustGetInputDevice(Device); + if (!inputDevice) { + pr_err("unable to get input device...device being destroyed?"); + return; + } + + pipeMsg = (struct pipe_prt_msg *)((unsigned long)Packet + (Packet->offset8 << 3)); + + if (pipeMsg->type != PipeMessageData) { + pr_err("unknown pipe msg type - type %d len %d", + pipeMsg->type, pipeMsg->size); + PutInputDevice(Device); + return ; + } + + hidMsg = (struct synthhid_msg *)&pipeMsg->data[0]; + + switch (hidMsg->header.type) { + case SynthHidProtocolResponse: + memcpy(&inputDevice->ProtocolResp, pipeMsg, + pipeMsg->size + sizeof(struct pipe_prt_msg) - + sizeof(unsigned char)); + inputDevice->protocol_wait_condition = 1; + wake_up(&inputDevice->ProtocolWaitEvent); + break; + + case SynthHidInitialDeviceInfo: + WARN_ON(pipeMsg->size >= sizeof(struct hv_input_dev_info)); + + /* + * Parse out the device info into device attr, + * hid desc and report desc + */ + MousevscOnReceiveDeviceInfo(inputDevice, + (struct synthhid_device_info *)&pipeMsg->data[0]); + break; + case SynthHidInputReport: + MousevscOnReceiveInputReport(inputDevice, + (struct synthhid_input_report *)&pipeMsg->data[0]); + + break; + default: + pr_err("unsupported hid msg type - type %d len %d", + hidMsg->header.type, hidMsg->header.size); + break; + } + + PutInputDevice(Device); +} + +static void MousevscOnChannelCallback(void *Context) +{ + const int packetSize = 0x100; + int ret = 0; + struct hv_device *device = (struct hv_device *)Context; + struct mousevsc_dev *inputDevice; + + u32 bytesRecvd; + u64 requestId; + unsigned char packet[packetSize]; + struct vmpacket_descriptor *desc; + unsigned char *buffer = packet; + int bufferlen = packetSize; + + inputDevice = MustGetInputDevice(device); + + if (!inputDevice) { + pr_err("unable to get input device...device being destroyed?"); + return; + } + + do { + ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen, &bytesRecvd, &requestId); + + if (ret == 0) { + if (bytesRecvd > 0) { + desc = (struct vmpacket_descriptor *)buffer; + + switch (desc->type) { + case VM_PKT_COMP: + MousevscOnSendCompletion(device, + desc); + break; + + case VM_PKT_DATA_INBAND: + MousevscOnReceive(device, desc); + break; + + default: + pr_err("unhandled packet type %d, tid %llx len %d\n", + desc->type, + requestId, + bytesRecvd); + break; + } + + /* reset */ + if (bufferlen > packetSize) { + kfree(buffer); + + buffer = packet; + bufferlen = packetSize; + } + } else { + /* + * pr_debug("nothing else to read..."); + * reset + */ + if (bufferlen > packetSize) { + kfree(buffer); + + buffer = packet; + bufferlen = packetSize; + } + break; + } + } else if (ret == -2) { + /* Handle large packet */ + bufferlen = bytesRecvd; + buffer = kzalloc(bytesRecvd, GFP_KERNEL); + + if (buffer == NULL) { + buffer = packet; + bufferlen = packetSize; + + /* Try again next time around */ + pr_err("unable to allocate buffer of size %d!", + bytesRecvd); + break; + } + } + } while (1); + + PutInputDevice(device); + + return; +} + +static int MousevscConnectToVsp(struct hv_device *Device) +{ + int ret = 0; + struct mousevsc_dev *inputDevice; + struct mousevsc_prt_msg *request; + struct mousevsc_prt_msg *response; + + inputDevice = GetInputDevice(Device); + + if (!inputDevice) { + pr_err("unable to get input device...device being destroyed?"); + return -1; + } + + init_waitqueue_head(&inputDevice->ProtocolWaitEvent); + init_waitqueue_head(&inputDevice->DeviceInfoWaitEvent); + + request = &inputDevice->ProtocolReq; + + /* + * Now, initiate the vsc/vsp initialization protocol on the open channel + */ + memset(request, sizeof(struct mousevsc_prt_msg), 0); + + request->type = PipeMessageData; + request->size = sizeof(struct synthhid_protocol_request); + + request->request.header.type = SynthHidProtocolRequest; + request->request.header.size = sizeof(unsigned long); + request->request.version_requested.version = SYNTHHID_INPUT_VERSION; + + pr_info("synthhid protocol request..."); + + ret = vmbus_sendpacket(Device->channel, request, + sizeof(struct pipe_prt_msg) - + sizeof(unsigned char) + + sizeof(struct synthhid_protocol_request), + (unsigned long)request, + VM_PKT_DATA_INBAND, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (ret != 0) { + pr_err("unable to send synthhid protocol request."); + goto Cleanup; + } + + inputDevice->protocol_wait_condition = 0; + wait_event_timeout(inputDevice->ProtocolWaitEvent, inputDevice->protocol_wait_condition, msecs_to_jiffies(1000)); + if (inputDevice->protocol_wait_condition == 0) { + ret = -ETIMEDOUT; + goto Cleanup; + } + + response = &inputDevice->ProtocolResp; + + if (!response->response.approved) { + pr_err("synthhid protocol request failed (version %d)", + SYNTHHID_INPUT_VERSION); + ret = -1; + goto Cleanup; + } + + inputDevice->device_wait_condition = 0; + wait_event_timeout(inputDevice->DeviceInfoWaitEvent, inputDevice->device_wait_condition, msecs_to_jiffies(1000)); + if (inputDevice->device_wait_condition == 0) { + ret = -ETIMEDOUT; + goto Cleanup; + } + + /* + * We should have gotten the device attr, hid desc and report + * desc at this point + */ + if (!inputDevice->DeviceInfoStatus) + pr_info("**** input channel up and running!! ****"); + else + ret = -1; + +Cleanup: + PutInputDevice(Device); + + return ret; +} + +static int MousevscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) +{ + int ret = 0; + struct mousevsc_dev *inputDevice; + struct mousevsc_drv_obj *inputDriver; + struct hv_input_dev_info dev_info; + + inputDevice = AllocInputDevice(Device); + + if (!inputDevice) { + ret = -1; + goto Cleanup; + } + + inputDevice->bInitializeComplete = false; + + /* Open the channel */ + ret = vmbus_open(Device->channel, + INPUTVSC_SEND_RING_BUFFER_SIZE, + INPUTVSC_RECV_RING_BUFFER_SIZE, + NULL, + 0, + MousevscOnChannelCallback, + Device + ); + + if (ret != 0) { + pr_err("unable to open channel: %d", ret); + FreeInputDevice(inputDevice); + return -1; + } + + pr_info("InputVsc channel open: %d", ret); + + ret = MousevscConnectToVsp(Device); + + if (ret != 0) { + pr_err("unable to connect channel: %d", ret); + + vmbus_close(Device->channel); + FreeInputDevice(inputDevice); + return ret; + } + + inputDriver = (struct mousevsc_drv_obj *)inputDevice->Device->drv; + + dev_info.vendor = inputDevice->hid_dev_info.vendor; + dev_info.product = inputDevice->hid_dev_info.product; + dev_info.version = inputDevice->hid_dev_info.version; + strcpy(dev_info.name, "Microsoft Vmbus HID-compliant Mouse"); + + /* Send the device info back up */ + deviceinfo_callback(Device, &dev_info); + + /* Send the report desc back up */ + /* workaround SA-167 */ + if (inputDevice->ReportDesc[14] == 0x25) + inputDevice->ReportDesc[14] = 0x29; + + reportdesc_callback(Device, inputDevice->ReportDesc, + inputDevice->ReportDescSize); + + inputDevice->bInitializeComplete = true; + +Cleanup: + return ret; +} + +static int MousevscOnDeviceRemove(struct hv_device *Device) +{ + struct mousevsc_dev *inputDevice; + int ret = 0; + + pr_info("disabling input device (%p)...", + Device->ext); + + inputDevice = ReleaseInputDevice(Device); + + + /* + * At this point, all outbound traffic should be disable. We only + * allow inbound traffic (responses) to proceed + * + * so that outstanding requests can be completed. + */ + while (inputDevice->NumOutstandingRequests) { + pr_info("waiting for %d requests to complete...", inputDevice->NumOutstandingRequests); + + udelay(100); + } + + pr_info("removing input device (%p)...", Device->ext); + + inputDevice = FinalReleaseInputDevice(Device); + + pr_info("input device (%p) safe to remove", inputDevice); + + /* Close the channel */ + vmbus_close(Device->channel); + + FreeInputDevice(inputDevice); + + return ret; +} + +static void MousevscOnCleanup(struct hv_driver *drv) +{ +} + +/* + * Data types + */ +struct input_device_context { + struct hv_device *device_ctx; + struct hid_device *hid_device; + struct hv_input_dev_info device_info; + int connected; +}; + + +static struct mousevsc_drv_obj g_mousevsc_drv; + +static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info) +{ + struct input_device_context *input_device_ctx = + dev_get_drvdata(&dev->device); + + memcpy(&input_device_ctx->device_info, info, + sizeof(struct hv_input_dev_info)); + + DPRINT_INFO(INPUTVSC_DRV, "%s", __func__); +} + +static void inputreport_callback(struct hv_device *dev, void *packet, u32 len) +{ + int ret = 0; + + struct input_device_context *input_dev_ctx = + dev_get_drvdata(&dev->device); + + ret = hid_input_report(input_dev_ctx->hid_device, + HID_INPUT_REPORT, packet, len, 1); + + DPRINT_DBG(INPUTVSC_DRV, "hid_input_report (ret %d)", ret); +} + +static int mousevsc_hid_open(struct hid_device *hid) +{ + return 0; +} + +static void mousevsc_hid_close(struct hid_device *hid) +{ +} + +static int mousevsc_probe(struct device *device) +{ + int ret = 0; + + struct hv_driver *drv = + drv_to_hv_drv(device->driver); + struct mousevsc_drv_obj *mousevsc_drv_obj = drv->priv; + + struct hv_device *device_obj = device_to_hv_device(device); + struct input_device_context *input_dev_ctx; + + input_dev_ctx = kmalloc(sizeof(struct input_device_context), + GFP_KERNEL); + + dev_set_drvdata(device, input_dev_ctx); + + /* Call to the vsc driver to add the device */ + ret = mousevsc_drv_obj->Base.dev_add(device_obj, NULL); + + if (ret != 0) { + DPRINT_ERR(INPUTVSC_DRV, "unable to add input vsc device"); + + return -1; + } + + return 0; +} + +static int mousevsc_remove(struct device *device) +{ + int ret = 0; + + struct hv_driver *drv = + drv_to_hv_drv(device->driver); + struct mousevsc_drv_obj *mousevsc_drv_obj = drv->priv; + + struct hv_device *device_obj = device_to_hv_device(device); + struct input_device_context *input_dev_ctx; + + input_dev_ctx = kmalloc(sizeof(struct input_device_context), + GFP_KERNEL); + + dev_set_drvdata(device, input_dev_ctx); + + if (input_dev_ctx->connected) { + hidinput_disconnect(input_dev_ctx->hid_device); + input_dev_ctx->connected = 0; + } + + if (!mousevsc_drv_obj->Base.dev_rm) + return -1; + + /* + * Call to the vsc driver to let it know that the device + * is being removed + */ + ret = mousevsc_drv_obj->Base.dev_rm(device_obj); + + if (ret != 0) { + DPRINT_ERR(INPUTVSC_DRV, + "unable to remove vsc device (ret %d)", ret); + } + + kfree(input_dev_ctx); + + return ret; +} + +static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len) +{ + struct input_device_context *input_device_ctx = + dev_get_drvdata(&dev->device); + struct hid_device *hid_dev; + + /* hid_debug = -1; */ + hid_dev = kmalloc(sizeof(struct hid_device), GFP_KERNEL); + + if (hid_parse_report(hid_dev, packet, len)) { + DPRINT_INFO(INPUTVSC_DRV, "Unable to call hd_parse_report"); + return; + } + + if (hid_dev) { + DPRINT_INFO(INPUTVSC_DRV, "hid_device created"); + + hid_dev->ll_driver->open = mousevsc_hid_open; + hid_dev->ll_driver->close = mousevsc_hid_close; + + hid_dev->bus = BUS_VIRTUAL; + hid_dev->vendor = input_device_ctx->device_info.vendor; + hid_dev->product = input_device_ctx->device_info.product; + hid_dev->version = input_device_ctx->device_info.version; + hid_dev->dev = dev->device; + + sprintf(hid_dev->name, "%s", + input_device_ctx->device_info.name); + + /* + * HJ Do we want to call it with a 0 + */ + if (!hidinput_connect(hid_dev, 0)) { + hid_dev->claimed |= HID_CLAIMED_INPUT; + + input_device_ctx->connected = 1; + + DPRINT_INFO(INPUTVSC_DRV, + "HID device claimed by input\n"); + } + + if (!hid_dev->claimed) { + DPRINT_ERR(INPUTVSC_DRV, + "HID device not claimed by " + "input or hiddev\n"); + } + + input_device_ctx->hid_device = hid_dev; + } + + kfree(hid_dev); +} + +static int mousevsc_drv_exit_cb(struct device *dev, void *data) +{ + struct device **curr = (struct device **)data; + *curr = dev; + + return 1; +} + +static void mousevsc_drv_exit(void) +{ + struct mousevsc_drv_obj *mousevsc_drv_obj = &g_mousevsc_drv; + struct hv_driver *drv = &g_mousevsc_drv.Base; + int ret; + + struct device *current_dev = NULL; + + while (1) { + current_dev = NULL; + + /* Get the device */ + ret = driver_for_each_device(&drv->driver, NULL, + (void *)¤t_dev, + mousevsc_drv_exit_cb); + if (ret) + printk(KERN_ERR "Can't find mouse device!\n"); + + if (current_dev == NULL) + break; + + /* Initiate removal from the top-down */ + device_unregister(current_dev); + } + + if (mousevsc_drv_obj->Base.cleanup) + mousevsc_drv_obj->Base.cleanup(&mousevsc_drv_obj->Base); + + vmbus_child_driver_unregister(&drv->driver); + + return; +} + +static int mouse_vsc_initialize(struct hv_driver *Driver) +{ + struct mousevsc_drv_obj *inputDriver = + (struct mousevsc_drv_obj *)Driver; + int ret = 0; + + Driver->name = driver_name; + memcpy(&Driver->dev_type, &mouse_guid, + sizeof(struct hv_guid)); + + /* Setup the dispatch table */ + inputDriver->Base.dev_add = MousevscOnDeviceAdd; + inputDriver->Base.dev_rm = MousevscOnDeviceRemove; + inputDriver->Base.cleanup = MousevscOnCleanup; + + return ret; +} + + +static int __init mousevsc_init(void) +{ + struct mousevsc_drv_obj *input_drv_obj = &g_mousevsc_drv; + struct hv_driver *drv = &g_mousevsc_drv.Base; + + DPRINT_INFO(INPUTVSC_DRV, "Hyper-V Mouse driver initializing."); + + /* Callback to client driver to complete the initialization */ + mouse_vsc_initialize(&input_drv_obj->Base); + + drv->driver.name = input_drv_obj->Base.name; + drv->priv = input_drv_obj; + + drv->driver.probe = mousevsc_probe; + drv->driver.remove = mousevsc_remove; + + /* The driver belongs to vmbus */ + vmbus_child_driver_register(&drv->driver); + + return 0; +} + +static void __exit mousevsc_exit(void) +{ + mousevsc_drv_exit(); +} + +/* + * We don't want to automatically load this driver just yet, it's quite + * broken. It's safe if you want to load it yourself manually, but + * don't inflict it on unsuspecting users, that's just mean. + */ +#if 0 + +/* + * We use a PCI table to determine if we should autoload this driver This is + * needed by distro tools to determine if the hyperv drivers should be + * installed and/or configured. We don't do anything else with the table, but + * it needs to be present. + */ +const static struct pci_device_id microsoft_hv_pci_table[] = { + { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */ + { 0 } +}; +MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table); +#endif + +MODULE_LICENSE("GPL"); +MODULE_VERSION(HV_DRV_VERSION); +module_init(mousevsc_init); +module_exit(mousevsc_exit); + diff --git a/drivers/staging/hv/hv_utils.c b/drivers/staging/hv/hv_util.c index 0074581f20e8..4792f2c402b2 100644 --- a/drivers/staging/hv/hv_utils.c +++ b/drivers/staging/hv/hv_util.c @@ -28,7 +28,7 @@ #include <linux/pci.h> #include "logging.h" -#include "osd.h" +#include "hv_api.h" #include "vmbus.h" #include "vmbus_packet_format.h" #include "vmbus_channel_interface.h" @@ -37,6 +37,7 @@ #include "vmbus_private.h" #include "vmbus_api.h" #include "utils.h" +#include "hv_kvp.h" static u8 *shut_txf_buf; static u8 *time_txf_buf; @@ -96,7 +97,7 @@ static void shutdown_onchannelcallback(void *context) vmbus_sendpacket(channel, shut_txf_buf, recvlen, requestid, - VmbusPacketTypeDataInBand, 0); + VM_PKT_DATA_INBAND, 0); } if (execute_shutdown == true) @@ -178,7 +179,7 @@ static void timesync_onchannelcallback(void *context) vmbus_sendpacket(channel, time_txf_buf, recvlen, requestid, - VmbusPacketTypeDataInBand, 0); + VM_PKT_DATA_INBAND, 0); } } @@ -224,7 +225,7 @@ static void heartbeat_onchannelcallback(void *context) vmbus_sendpacket(channel, hbeat_txf_buf, recvlen, requestid, - VmbusPacketTypeDataInBand, 0); + VM_PKT_DATA_INBAND, 0); } } @@ -255,6 +256,10 @@ static int __init init_hyperv_utils(void) { printk(KERN_INFO "Registering HyperV Utility Driver\n"); + if (hv_kvp_init()) + return -ENODEV; + + if (!dmi_check_system(hv_utils_dmi_table)) return -ENODEV; @@ -283,6 +288,11 @@ static int __init init_hyperv_utils(void) &heartbeat_onchannelcallback; hv_cb_utils[HV_HEARTBEAT_MSG].callback = &heartbeat_onchannelcallback; + hv_cb_utils[HV_KVP_MSG].channel->onchannel_callback = + &hv_kvp_onchannelcallback; + + + return 0; } @@ -302,6 +312,10 @@ static void exit_hyperv_utils(void) &chn_cb_negotiate; hv_cb_utils[HV_HEARTBEAT_MSG].callback = &chn_cb_negotiate; + hv_cb_utils[HV_KVP_MSG].channel->onchannel_callback = + &chn_cb_negotiate; + hv_kvp_deinit(); + kfree(shut_txf_buf); kfree(time_txf_buf); kfree(hbeat_txf_buf); diff --git a/drivers/staging/hv/logging.h b/drivers/staging/hv/logging.h index 20d4d12023de..17999515ce08 100644 --- a/drivers/staging/hv/logging.h +++ b/drivers/staging/hv/logging.h @@ -25,6 +25,9 @@ #ifndef _LOGGING_H_ #define _LOGGING_H_ +#define LOWORD(dw) ((unsigned short)(dw)) +#define HIWORD(dw) ((unsigned short)(((unsigned int) (dw) >> 16) & 0xFFFF)) + /* #include <linux/init.h> */ /* #include <linux/module.h> */ diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index 0edbe7483a4c..20b159775e88 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -19,11 +19,13 @@ * Hank Janssen <hjanssen@microsoft.com> */ #include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/wait.h> #include <linux/mm.h> #include <linux/delay.h> #include <linux/io.h> #include <linux/slab.h> -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "netvsc.h" #include "rndis_filter.h" @@ -86,15 +88,15 @@ static struct netvsc_device *alloc_net_device(struct hv_device *device) atomic_cmpxchg(&net_device->refcnt, 0, 2); net_device->dev = device; - device->Extension = net_device; + device->ext = net_device; return net_device; } static void free_net_device(struct netvsc_device *device) { - WARN_ON(atomic_read(&device->refcnt) == 0); - device->dev->Extension = NULL; + WARN_ON(atomic_read(&device->refcnt) != 0); + device->dev->ext = NULL; kfree(device); } @@ -104,7 +106,7 @@ static struct netvsc_device *get_outbound_net_device(struct hv_device *device) { struct netvsc_device *net_device; - net_device = device->Extension; + net_device = device->ext; if (net_device && atomic_read(&net_device->refcnt) > 1) atomic_inc(&net_device->refcnt); else @@ -118,7 +120,7 @@ static struct netvsc_device *get_inbound_net_device(struct hv_device *device) { struct netvsc_device *net_device; - net_device = device->Extension; + net_device = device->ext; if (net_device && atomic_read(&net_device->refcnt)) atomic_inc(&net_device->refcnt); else @@ -131,8 +133,7 @@ static void put_net_device(struct hv_device *device) { struct netvsc_device *net_device; - net_device = device->Extension; - /* ASSERT(netDevice); */ + net_device = device->ext; atomic_dec(&net_device->refcnt); } @@ -142,7 +143,7 @@ static struct netvsc_device *release_outbound_net_device( { struct netvsc_device *net_device; - net_device = device->Extension; + net_device = device->ext; if (net_device == NULL) return NULL; @@ -158,7 +159,7 @@ static struct netvsc_device *release_inbound_net_device( { struct netvsc_device *net_device; - net_device = device->Extension; + net_device = device->ext; if (net_device == NULL) return NULL; @@ -166,7 +167,7 @@ static struct netvsc_device *release_inbound_net_device( while (atomic_cmpxchg(&net_device->refcnt, 1, 0) != 1) udelay(100); - device->Extension = NULL; + device->ext = NULL; return net_device; } @@ -184,21 +185,13 @@ int netvsc_initialize(struct hv_driver *drv) sizeof(struct nvsp_message), sizeof(struct vmtransfer_page_packet_header)); - /* Make sure we are at least 2 pages since 1 page is used for control */ - /* ASSERT(driver->RingBufferSize >= (PAGE_SIZE << 1)); */ - drv->name = driver_name; - memcpy(&drv->deviceType, &netvsc_device_type, sizeof(struct hv_guid)); - - /* Make sure it is set by the caller */ - /* FIXME: These probably should still be tested in some way */ - /* ASSERT(driver->OnReceiveCallback); */ - /* ASSERT(driver->OnLinkStatusChanged); */ + memcpy(&drv->dev_type, &netvsc_device_type, sizeof(struct hv_guid)); /* Setup the dispatch table */ - driver->base.OnDeviceAdd = netvsc_device_add; - driver->base.OnDeviceRemove = netvsc_device_remove; - driver->base.OnCleanup = netvsc_cleanup; + driver->base.dev_add = netvsc_device_add; + driver->base.dev_rm = netvsc_device_remove; + driver->base.cleanup = netvsc_cleanup; driver->send = netvsc_send; @@ -218,22 +211,17 @@ static int netvsc_init_recv_buf(struct hv_device *device) "device being destroyed?"); return -1; } - /* ASSERT(netDevice->ReceiveBufferSize > 0); */ - /* page-size grandularity */ - /* ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE - 1)) == 0); */ net_device->recv_buf = - osd_page_alloc(net_device->recv_buf_size >> PAGE_SHIFT); + (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, + get_order(net_device->recv_buf_size)); if (!net_device->recv_buf) { DPRINT_ERR(NETVSC, "unable to allocate receive buffer of size %d", net_device->recv_buf_size); ret = -1; - goto Cleanup; + goto cleanup; } - /* page-aligned buffer */ - /* ASSERT(((unsigned long)netDevice->ReceiveBuffer & (PAGE_SIZE - 1)) == */ - /* 0); */ DPRINT_INFO(NETVSC, "Establishing receive buffer's GPADL..."); @@ -248,10 +236,9 @@ static int netvsc_init_recv_buf(struct hv_device *device) if (ret != 0) { DPRINT_ERR(NETVSC, "unable to establish receive buffer's gpadl"); - goto Cleanup; + goto cleanup; } - /* osd_waitevent_wait(ext->ChannelInitEvent); */ /* Notify the NetVsp of the gpadl handle */ DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendReceiveBuffer..."); @@ -267,18 +254,23 @@ static int netvsc_init_recv_buf(struct hv_device *device) send_recv_buf.id = NETVSC_RECEIVE_BUFFER_ID; /* Send the gpadl notification request */ + net_device->wait_condition = 0; ret = vmbus_sendpacket(device->channel, init_packet, sizeof(struct nvsp_message), (unsigned long)init_packet, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send receive buffer's gpadl to netvsp"); - goto Cleanup; + goto cleanup; } - osd_waitevent_wait(net_device->channel_init_event); + wait_event_timeout(net_device->channel_init_wait, + net_device->wait_condition, + msecs_to_jiffies(1000)); + BUG_ON(net_device->wait_condition == 0); + /* Check the response */ if (init_packet->msg.v1_msg. @@ -288,12 +280,10 @@ static int netvsc_init_recv_buf(struct hv_device *device) init_packet->msg.v1_msg. send_recv_buf_complete.status); ret = -1; - goto Cleanup; + goto cleanup; } /* Parse the response */ - /* ASSERT(netDevice->ReceiveSectionCount == 0); */ - /* ASSERT(netDevice->ReceiveSections == NULL); */ net_device->recv_section_cnt = init_packet->msg. v1_msg.send_recv_buf_complete.num_sections; @@ -302,7 +292,7 @@ static int netvsc_init_recv_buf(struct hv_device *device) * sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL); if (net_device->recv_section == NULL) { ret = -1; - goto Cleanup; + goto cleanup; } memcpy(net_device->recv_section, @@ -326,15 +316,15 @@ static int netvsc_init_recv_buf(struct hv_device *device) if (net_device->recv_section_cnt != 1 || net_device->recv_section->offset != 0) { ret = -1; - goto Cleanup; + goto cleanup; } - goto Exit; + goto exit; -Cleanup: +cleanup: netvsc_destroy_recv_buf(net_device); -Exit: +exit: put_net_device(device); return ret; } @@ -353,22 +343,18 @@ static int netvsc_init_send_buf(struct hv_device *device) } if (net_device->send_buf_size <= 0) { ret = -EINVAL; - goto Cleanup; + goto cleanup; } - /* page-size grandularity */ - /* ASSERT((netDevice->SendBufferSize & (PAGE_SIZE - 1)) == 0); */ - net_device->send_buf = - osd_page_alloc(net_device->send_buf_size >> PAGE_SHIFT); + (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, + get_order(net_device->send_buf_size)); if (!net_device->send_buf) { DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d", net_device->send_buf_size); ret = -1; - goto Cleanup; + goto cleanup; } - /* page-aligned buffer */ - /* ASSERT(((unsigned long)netDevice->SendBuffer & (PAGE_SIZE - 1)) == 0); */ DPRINT_INFO(NETVSC, "Establishing send buffer's GPADL..."); @@ -382,11 +368,9 @@ static int netvsc_init_send_buf(struct hv_device *device) &net_device->send_buf_gpadl_handle); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl"); - goto Cleanup; + goto cleanup; } - /* osd_waitevent_wait(ext->ChannelInitEvent); */ - /* Notify the NetVsp of the gpadl handle */ DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendSendBuffer..."); @@ -401,18 +385,22 @@ static int netvsc_init_send_buf(struct hv_device *device) NETVSC_SEND_BUFFER_ID; /* Send the gpadl notification request */ + net_device->wait_condition = 0; ret = vmbus_sendpacket(device->channel, init_packet, sizeof(struct nvsp_message), (unsigned long)init_packet, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send receive buffer's gpadl to netvsp"); - goto Cleanup; + goto cleanup; } - osd_waitevent_wait(net_device->channel_init_event); + wait_event_timeout(net_device->channel_init_wait, + net_device->wait_condition, + msecs_to_jiffies(1000)); + BUG_ON(net_device->wait_condition == 0); /* Check the response */ if (init_packet->msg.v1_msg. @@ -422,18 +410,18 @@ static int netvsc_init_send_buf(struct hv_device *device) init_packet->msg.v1_msg. send_send_buf_complete.status); ret = -1; - goto Cleanup; + goto cleanup; } net_device->send_section_size = init_packet-> msg.v1_msg.send_send_buf_complete.section_size; - goto Exit; + goto exit; -Cleanup: +cleanup: netvsc_destroy_send_buf(net_device); -Exit: +exit: put_net_device(device); return ret; } @@ -466,7 +454,7 @@ static int netvsc_destroy_recv_buf(struct netvsc_device *net_device) revoke_packet, sizeof(struct nvsp_message), (unsigned long)revoke_packet, - VmbusPacketTypeDataInBand, 0); + VM_PKT_DATA_INBAND, 0); /* * If we failed here, we might as well return and * have a leak rather than continue and a bugchk @@ -498,8 +486,8 @@ static int netvsc_destroy_recv_buf(struct netvsc_device *net_device) DPRINT_INFO(NETVSC, "Freeing up receive buffer..."); /* Free up the receive buffer */ - osd_page_free(net_device->recv_buf, - net_device->recv_buf_size >> PAGE_SHIFT); + free_pages((unsigned long)net_device->recv_buf, + get_order(net_device->recv_buf_size)); net_device->recv_buf = NULL; } @@ -540,7 +528,7 @@ static int netvsc_destroy_send_buf(struct netvsc_device *net_device) revoke_packet, sizeof(struct nvsp_message), (unsigned long)revoke_packet, - VmbusPacketTypeDataInBand, 0); + VM_PKT_DATA_INBAND, 0); /* * If we failed here, we might as well return and have a leak * rather than continue and a bugchk @@ -574,8 +562,8 @@ static int netvsc_destroy_send_buf(struct netvsc_device *net_device) DPRINT_INFO(NETVSC, "Freeing up send buffer..."); /* Free up the receive buffer */ - osd_page_free(net_device->send_buf, - net_device->send_buf_size >> PAGE_SHIFT); + free_pages((unsigned long)net_device->send_buf, + get_order(net_device->send_buf_size)); net_device->send_buf = NULL; } @@ -609,21 +597,26 @@ static int netvsc_connect_vsp(struct hv_device *device) DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit..."); /* Send the init request */ + net_device->wait_condition = 0; ret = vmbus_sendpacket(device->channel, init_packet, sizeof(struct nvsp_message), (unsigned long)init_packet, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send NvspMessageTypeInit"); - goto Cleanup; + goto cleanup; } - osd_waitevent_wait(net_device->channel_init_event); + wait_event_timeout(net_device->channel_init_wait, + net_device->wait_condition, + msecs_to_jiffies(1000)); + if (net_device->wait_condition == 0) { + ret = -ETIMEDOUT; + goto cleanup; + } - /* Now, check the response */ - /* ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT); */ DPRINT_INFO(NETVSC, "NvspMessageTypeInit status(%d) max mdl chain (%d)", init_packet->msg.init_msg.init_complete.status, init_packet->msg.init_msg. @@ -635,7 +628,7 @@ static int netvsc_connect_vsp(struct hv_device *device) "unable to initialize with netvsp (status 0x%x)", init_packet->msg.init_msg.init_complete.status); ret = -1; - goto Cleanup; + goto cleanup; } if (init_packet->msg.init_msg.init_complete. @@ -645,7 +638,7 @@ static int netvsc_connect_vsp(struct hv_device *device) init_packet->msg.init_msg. init_complete.negotiated_protocol_ver); ret = -1; - goto Cleanup; + goto cleanup; } DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion..."); @@ -664,29 +657,22 @@ static int netvsc_connect_vsp(struct hv_device *device) /* Send the init request */ ret = vmbus_sendpacket(device->channel, init_packet, - sizeof(struct nvsp_message), - (unsigned long)init_packet, - VmbusPacketTypeDataInBand, 0); + sizeof(struct nvsp_message), + (unsigned long)init_packet, + VM_PKT_DATA_INBAND, 0); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send NvspMessage1TypeSendNdisVersion"); ret = -1; - goto Cleanup; + goto cleanup; } - /* - * BUGBUG - We have to wait for the above msg since the - * netvsp uses KMCL which acknowledges packet (completion - * packet) since our Vmbus always set the - * VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag - */ - /* osd_waitevent_wait(NetVscChannel->ChannelInitEvent); */ /* Post the big receive buffer to NetVSP */ ret = netvsc_init_recv_buf(device); if (ret == 0) ret = netvsc_init_send_buf(device); -Cleanup: +cleanup: put_net_device(device); return ret; } @@ -708,12 +694,12 @@ static int netvsc_device_add(struct hv_device *device, void *additional_info) struct netvsc_device *net_device; struct hv_netvsc_packet *packet, *pos; struct netvsc_driver *net_driver = - (struct netvsc_driver *)device->Driver; + (struct netvsc_driver *)device->drv; net_device = alloc_net_device(device); if (!net_device) { ret = -1; - goto Cleanup; + goto cleanup; } DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", net_device); @@ -739,11 +725,7 @@ static int netvsc_device_add(struct hv_device *device, void *additional_info) list_add_tail(&packet->list_ent, &net_device->recv_pkt_list); } - net_device->channel_init_event = osd_waitevent_create(); - if (!net_device->channel_init_event) { - ret = -ENOMEM; - goto Cleanup; - } + init_waitqueue_head(&net_device->channel_init_wait); /* Open the channel */ ret = vmbus_open(device->channel, net_driver->ring_buf_size, @@ -753,7 +735,7 @@ static int netvsc_device_add(struct hv_device *device, void *additional_info) if (ret != 0) { DPRINT_ERR(NETVSC, "unable to open channel: %d", ret); ret = -1; - goto Cleanup; + goto cleanup; } /* Channel is opened */ @@ -776,11 +758,9 @@ close: /* Now, we can close the channel safely */ vmbus_close(device->channel); -Cleanup: +cleanup: if (net_device) { - kfree(net_device->channel_init_event); - list_for_each_entry_safe(packet, pos, &net_device->recv_pkt_list, list_ent) { @@ -806,7 +786,7 @@ static int netvsc_device_remove(struct hv_device *device) struct hv_netvsc_packet *netvsc_packet, *pos; DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...", - device->Extension); + device->ext); /* Stop outbound traffic ie sends and receives completions */ net_device = release_outbound_net_device(device); @@ -827,7 +807,7 @@ static int netvsc_device_remove(struct hv_device *device) NetVscDisconnectFromVsp(net_device); DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...", - device->Extension); + device->ext); /* Stop inbound traffic ie receives and sends completions */ net_device = release_inbound_net_device(device); @@ -845,7 +825,6 @@ static int netvsc_device_remove(struct hv_device *device) kfree(netvsc_packet); } - kfree(net_device->channel_init_event); free_net_device(net_device); return 0; } @@ -872,7 +851,7 @@ static void netvsc_send_completion(struct hv_device *device, } nvsp_packet = (struct nvsp_message *)((unsigned long)packet + - (packet->DataOffset8 << 3)); + (packet->offset8 << 3)); DPRINT_DBG(NETVSC, "send completion packet - type %d", nvsp_packet->hdr.msg_type); @@ -885,13 +864,13 @@ static void netvsc_send_completion(struct hv_device *device, /* Copy the response back */ memcpy(&net_device->channel_init_pkt, nvsp_packet, sizeof(struct nvsp_message)); - osd_waitevent_set(net_device->channel_init_event); + net_device->wait_condition = 1; + wake_up(&net_device->channel_init_wait); } else if (nvsp_packet->hdr.msg_type == NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE) { /* Get the send context */ nvsc_packet = (struct hv_netvsc_packet *)(unsigned long) - packet->TransactionId; - /* ASSERT(nvscPacket); */ + packet->trans_id; /* Notify the layer above us */ nvsc_packet->completion.send.send_completion( @@ -946,7 +925,7 @@ static int netvsc_send(struct hv_device *device, ret = vmbus_sendpacket(device->channel, &sendMessage, sizeof(struct nvsp_message), (unsigned long)packet, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); } @@ -987,15 +966,15 @@ static void netvsc_receive(struct hv_device *device, * All inbound packets other than send completion should be xfer page * packet */ - if (packet->Type != VmbusPacketTypeDataUsingTransferPages) { + if (packet->type != VM_PKT_DATA_USING_XFER_PAGES) { DPRINT_ERR(NETVSC, "Unknown packet type received - %d", - packet->Type); + packet->type); put_net_device(device); return; } nvsp_packet = (struct nvsp_message *)((unsigned long)packet + - (packet->DataOffset8 << 3)); + (packet->offset8 << 3)); /* Make sure this is a valid nvsp packet */ if (nvsp_packet->hdr.msg_type != @@ -1011,16 +990,16 @@ static void netvsc_receive(struct hv_device *device, vmxferpage_packet = (struct vmtransfer_page_packet_header *)packet; - if (vmxferpage_packet->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID) { + if (vmxferpage_packet->xfer_pageset_id != NETVSC_RECEIVE_BUFFER_ID) { DPRINT_ERR(NETVSC, "Invalid xfer page set id - " "expecting %x got %x", NETVSC_RECEIVE_BUFFER_ID, - vmxferpage_packet->TransferPageSetId); + vmxferpage_packet->xfer_pageset_id); put_net_device(device); return; } DPRINT_DBG(NETVSC, "xfer page - range count %d", - vmxferpage_packet->RangeCount); + vmxferpage_packet->range_cnt); /* * Grab free packets (range count + 1) to represent this xfer @@ -1031,7 +1010,7 @@ static void netvsc_receive(struct hv_device *device, spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); while (!list_empty(&net_device->recv_pkt_list)) { list_move_tail(net_device->recv_pkt_list.next, &listHead); - if (++count == vmxferpage_packet->RangeCount + 1) + if (++count == vmxferpage_packet->range_cnt + 1) break; } spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags); @@ -1044,7 +1023,7 @@ static void netvsc_receive(struct hv_device *device, if (count < 2) { DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. " "Dropping this xfer page packet completely!", - count, vmxferpage_packet->RangeCount + 1); + count, vmxferpage_packet->range_cnt + 1); /* Return it to the freelist */ spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); @@ -1056,7 +1035,7 @@ static void netvsc_receive(struct hv_device *device, flags); netvsc_send_recv_completion(device, - vmxferpage_packet->d.TransactionId); + vmxferpage_packet->d.trans_id); put_net_device(device); return; @@ -1068,12 +1047,10 @@ static void netvsc_receive(struct hv_device *device, /* This is how much we can satisfy */ xferpage_packet->count = count - 1; - /* ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <= */ - /* vmxferpagePacket->RangeCount); */ - if (xferpage_packet->count != vmxferpage_packet->RangeCount) { + if (xferpage_packet->count != vmxferpage_packet->range_cnt) { DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer " - "page...got %d", vmxferpage_packet->RangeCount, + "page...got %d", vmxferpage_packet->range_cnt, xferpage_packet->count); } @@ -1091,78 +1068,71 @@ static void netvsc_receive(struct hv_device *device, netvsc_packet->device = device; /* Save this so that we can send it back */ netvsc_packet->completion.recv.recv_completion_tid = - vmxferpage_packet->d.TransactionId; + vmxferpage_packet->d.trans_id; netvsc_packet->total_data_buflen = - vmxferpage_packet->Ranges[i].ByteCount; + vmxferpage_packet->ranges[i].byte_count; netvsc_packet->page_buf_cnt = 1; - /* ASSERT(vmxferpagePacket->Ranges[i].ByteOffset + */ - /* vmxferpagePacket->Ranges[i].ByteCount < */ - /* netDevice->ReceiveBufferSize); */ - - netvsc_packet->page_buf[0].Length = - vmxferpage_packet->Ranges[i].ByteCount; + netvsc_packet->page_buf[0].len = + vmxferpage_packet->ranges[i].byte_count; start = virt_to_phys((void *)((unsigned long)net_device-> - recv_buf + vmxferpage_packet->Ranges[i].ByteOffset)); + recv_buf + vmxferpage_packet->ranges[i].byte_offset)); - netvsc_packet->page_buf[0].Pfn = start >> PAGE_SHIFT; + netvsc_packet->page_buf[0].pfn = start >> PAGE_SHIFT; end_virtual = (unsigned long)net_device->recv_buf - + vmxferpage_packet->Ranges[i].ByteOffset - + vmxferpage_packet->Ranges[i].ByteCount - 1; + + vmxferpage_packet->ranges[i].byte_offset + + vmxferpage_packet->ranges[i].byte_count - 1; end = virt_to_phys((void *)end_virtual); /* Calculate the page relative offset */ - netvsc_packet->page_buf[0].Offset = - vmxferpage_packet->Ranges[i].ByteOffset & + netvsc_packet->page_buf[0].offset = + vmxferpage_packet->ranges[i].byte_offset & (PAGE_SIZE - 1); if ((end >> PAGE_SHIFT) != (start >> PAGE_SHIFT)) { /* Handle frame across multiple pages: */ - netvsc_packet->page_buf[0].Length = - (netvsc_packet->page_buf[0].Pfn << + netvsc_packet->page_buf[0].len = + (netvsc_packet->page_buf[0].pfn << PAGE_SHIFT) + PAGE_SIZE - start; bytes_remain = netvsc_packet->total_data_buflen - - netvsc_packet->page_buf[0].Length; + netvsc_packet->page_buf[0].len; for (j = 1; j < NETVSC_PACKET_MAXPAGE; j++) { - netvsc_packet->page_buf[j].Offset = 0; + netvsc_packet->page_buf[j].offset = 0; if (bytes_remain <= PAGE_SIZE) { - netvsc_packet->page_buf[j].Length = + netvsc_packet->page_buf[j].len = bytes_remain; bytes_remain = 0; } else { - netvsc_packet->page_buf[j].Length = + netvsc_packet->page_buf[j].len = PAGE_SIZE; bytes_remain -= PAGE_SIZE; } - netvsc_packet->page_buf[j].Pfn = + netvsc_packet->page_buf[j].pfn = virt_to_phys((void *)(end_virtual - bytes_remain)) >> PAGE_SHIFT; netvsc_packet->page_buf_cnt++; if (bytes_remain == 0) break; } - /* ASSERT(bytesRemain == 0); */ } DPRINT_DBG(NETVSC, "[%d] - (abs offset %u len %u) => " "(pfn %llx, offset %u, len %u)", i, - vmxferpage_packet->Ranges[i].ByteOffset, - vmxferpage_packet->Ranges[i].ByteCount, - netvsc_packet->page_buf[0].Pfn, - netvsc_packet->page_buf[0].Offset, - netvsc_packet->page_buf[0].Length); + vmxferpage_packet->ranges[i].byte_offset, + vmxferpage_packet->ranges[i].byte_count, + netvsc_packet->page_buf[0].pfn, + netvsc_packet->page_buf[0].offset, + netvsc_packet->page_buf[0].len); /* Pass it to the upper layer */ - ((struct netvsc_driver *)device->Driver)-> + ((struct netvsc_driver *)device->drv)-> recv_cb(device, netvsc_packet); netvsc_receive_completion(netvsc_packet-> completion.recv.recv_completion_ctx); } - /* ASSERT(list_empty(&listHead)); */ - put_net_device(device); } @@ -1187,7 +1157,7 @@ retry_send_cmplt: /* Send the completion */ ret = vmbus_sendpacket(device->channel, &recvcompMessage, sizeof(struct nvsp_message), transaction_id, - VmbusPacketTypeCompletion, 0); + VM_PKT_COMP, 0); if (ret == 0) { /* success */ /* no-op */ @@ -1221,8 +1191,6 @@ static void netvsc_receive_completion(void *context) bool fsend_receive_comp = false; unsigned long flags; - /* ASSERT(packet->XferPagePacket); */ - /* * Even though it seems logical to do a GetOutboundNetDevice() here to * send out receive completion, we are using GetInboundNetDevice() @@ -1238,7 +1206,6 @@ static void netvsc_receive_completion(void *context) /* Overloading use of the lock. */ spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); - /* ASSERT(packet->XferPagePacket->Count > 0); */ packet->xfer_page_pkt->count--; /* @@ -1276,8 +1243,6 @@ static void netvsc_channel_cb(void *context) unsigned char *buffer; int bufferlen = NETVSC_PACKET_SIZE; - /* ASSERT(device); */ - packet = kzalloc(NETVSC_PACKET_SIZE * sizeof(unsigned char), GFP_ATOMIC); if (!packet) @@ -1300,12 +1265,12 @@ static void netvsc_channel_cb(void *context) bytes_recvd, request_id); desc = (struct vmpacket_descriptor *)buffer; - switch (desc->Type) { - case VmbusPacketTypeCompletion: + switch (desc->type) { + case VM_PKT_COMP: netvsc_send_completion(device, desc); break; - case VmbusPacketTypeDataUsingTransferPages: + case VM_PKT_DATA_USING_XFER_PAGES: netvsc_receive(device, desc); break; @@ -1313,7 +1278,7 @@ static void netvsc_channel_cb(void *context) DPRINT_ERR(NETVSC, "unhandled packet type %d, " "tid %llx len %d\n", - desc->Type, request_id, + desc->type, request_id, bytes_recvd); break; } diff --git a/drivers/staging/hv/netvsc.h b/drivers/staging/hv/netvsc.h index 932a77ccdc04..45d24b9d91a1 100644 --- a/drivers/staging/hv/netvsc.h +++ b/drivers/staging/hv/netvsc.h @@ -92,7 +92,7 @@ struct nvsp_message_header { struct nvsp_message_init { u32 min_protocol_ver; u32 max_protocol_ver; -} __attribute__((packed)); +} __packed; /* * This message is used by the VSP to complete the initialization of the @@ -103,12 +103,12 @@ struct nvsp_message_init_complete { u32 negotiated_protocol_ver; u32 max_mdl_chain_len; u32 status; -} __attribute__((packed)); +} __packed; union nvsp_message_init_uber { struct nvsp_message_init init; struct nvsp_message_init_complete init_complete; -} __attribute__((packed)); +} __packed; /* Version 1 Messages */ @@ -119,7 +119,7 @@ union nvsp_message_init_uber { struct nvsp_1_message_send_ndis_version { u32 ndis_major_ver; u32 ndis_minor_ver; -} __attribute__((packed)); +} __packed; /* * This message is used by the VSC to send a receive buffer to the VSP. The VSP @@ -128,14 +128,14 @@ struct nvsp_1_message_send_ndis_version { struct nvsp_1_message_send_receive_buffer { u32 gpadl_handle; u16 id; -} __attribute__((packed)); +} __packed; struct nvsp_1_receive_buffer_section { u32 offset; u32 sub_alloc_size; u32 num_sub_allocs; u32 end_offset; -} __attribute__((packed)); +} __packed; /* * This message is used by the VSP to acknowledge a receive buffer send by the @@ -166,7 +166,7 @@ struct nvsp_1_message_send_receive_buffer_complete { */ struct nvsp_1_receive_buffer_section sections[1]; -} __attribute__((packed)); +} __packed; /* * This message is sent by the VSC to revoke the receive buffer. After the VSP @@ -184,7 +184,7 @@ struct nvsp_1_message_revoke_receive_buffer { struct nvsp_1_message_send_send_buffer { u32 gpadl_handle; u16 id; -} __attribute__((packed)); +} __packed; /* * This message is used by the VSP to acknowledge a send buffer sent by the @@ -201,7 +201,7 @@ struct nvsp_1_message_send_send_buffer_complete { * decreases. */ u32 section_size; -} __attribute__((packed)); +} __packed; /* * This message is sent by the VSC to revoke the send buffer. After the VSP @@ -231,7 +231,7 @@ struct nvsp_1_message_send_rndis_packet { */ u32 send_buf_section_index; u32 send_buf_section_size; -} __attribute__((packed)); +} __packed; /* * This message is used by both the VSP and the VSC to complete a RNDIS message @@ -257,18 +257,18 @@ union nvsp_1_message_uber { struct nvsp_1_message_send_rndis_packet send_rndis_pkt; struct nvsp_1_message_send_rndis_packet_complete send_rndis_pkt_complete; -} __attribute__((packed)); +} __packed; union nvsp_all_messages { union nvsp_message_init_uber init_msg; union nvsp_1_message_uber v1_msg; -} __attribute__((packed)); +} __packed; /* ALL Messages */ struct nvsp_message { struct nvsp_message_header hdr; union nvsp_all_messages msg; -} __attribute__((packed)); +} __packed; @@ -318,7 +318,8 @@ struct netvsc_device { struct nvsp_1_receive_buffer_section *recv_section; /* Used for NetVSP initialization protocol */ - struct osd_waitevent *channel_init_event; + int wait_condition; + wait_queue_head_t channel_init_wait; struct nvsp_message channel_init_pkt; struct nvsp_message revoke_packet; diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c index b41c9640b72d..2d40f5f86b24 100644 --- a/drivers/staging/hv/netvsc_drv.c +++ b/drivers/staging/hv/netvsc_drv.c @@ -36,7 +36,7 @@ #include <net/route.h> #include <net/sock.h> #include <net/pkt_sched.h> -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "version_info.h" #include "vmbus.h" @@ -44,16 +44,10 @@ struct net_device_context { /* point back to our device context */ - struct vm_device *device_ctx; + struct hv_device *device_ctx; unsigned long avail; }; -struct netvsc_driver_context { - /* !! These must be the first 2 fields !! */ - /* Which is a bug FIXME! */ - struct driver_context drv_ctx; - struct netvsc_driver drv_obj; -}; #define PACKET_PAGES_LOWATER 8 /* Need this many pages to handle worst case fragmented packet */ @@ -64,7 +58,7 @@ module_param(ring_size, int, S_IRUGO); MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); /* The one and only one */ -static struct netvsc_driver_context g_netvsc_drv; +static struct netvsc_driver g_netvsc_drv; /* no-op so the netdev core doesn't return -EINVAL when modifying the the * multicast address list in SIOCADDMULTI. hv is setup to get all multicast @@ -76,7 +70,7 @@ static void netvsc_set_multicast_list(struct net_device *net) static int netvsc_open(struct net_device *net) { struct net_device_context *net_device_ctx = netdev_priv(net); - struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj; + struct hv_device *device_obj = net_device_ctx->device_ctx; int ret = 0; if (netif_carrier_ok(net)) { @@ -99,7 +93,7 @@ static int netvsc_open(struct net_device *net) static int netvsc_close(struct net_device *net) { struct net_device_context *net_device_ctx = netdev_priv(net); - struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj; + struct hv_device *device_obj = net_device_ctx->device_ctx; int ret; netif_stop_queue(net); @@ -126,7 +120,8 @@ static void netvsc_xmit_completion(void *context) dev_kfree_skb_any(skb); - if ((net_device_ctx->avail += num_pages) >= PACKET_PAGES_HIWATER) + net_device_ctx->avail += num_pages; + if (net_device_ctx->avail >= PACKET_PAGES_HIWATER) netif_wake_queue(net); } } @@ -134,11 +129,9 @@ static void netvsc_xmit_completion(void *context) static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) { struct net_device_context *net_device_ctx = netdev_priv(net); - struct driver_context *driver_ctx = - driver_to_driver_context(net_device_ctx->device_ctx->device.driver); - struct netvsc_driver_context *net_drv_ctx = - (struct netvsc_driver_context *)driver_ctx; - struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; + struct hv_driver *drv = + drv_to_hv_drv(net_device_ctx->device_ctx->device.driver); + struct netvsc_driver *net_drv_obj = drv->priv; struct hv_netvsc_packet *packet; int ret; unsigned int i, num_pages; @@ -178,18 +171,18 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) packet->total_data_buflen = skb->len; /* Start filling in the page buffers starting after RNDIS buffer. */ - packet->page_buf[1].Pfn = virt_to_phys(skb->data) >> PAGE_SHIFT; - packet->page_buf[1].Offset + packet->page_buf[1].pfn = virt_to_phys(skb->data) >> PAGE_SHIFT; + packet->page_buf[1].offset = (unsigned long)skb->data & (PAGE_SIZE - 1); - packet->page_buf[1].Length = skb_headlen(skb); + packet->page_buf[1].len = skb_headlen(skb); /* Additional fragments are after SKB data */ for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { skb_frag_t *f = &skb_shinfo(skb)->frags[i]; - packet->page_buf[i+2].Pfn = page_to_pfn(f->page); - packet->page_buf[i+2].Offset = f->page_offset; - packet->page_buf[i+2].Length = f->size; + packet->page_buf[i+2].pfn = page_to_pfn(f->page); + packet->page_buf[i+2].offset = f->page_offset; + packet->page_buf[i+2].len = f->size; } /* Set the completion routine */ @@ -197,7 +190,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) packet->completion.send.send_completion_ctx = packet; packet->completion.send.send_completion_tid = (unsigned long)skb; - ret = net_drv_obj->send(&net_device_ctx->device_ctx->device_obj, + ret = net_drv_obj->send(net_device_ctx->device_ctx, packet); if (ret == 0) { net->stats.tx_bytes += skb->len; @@ -207,7 +200,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) net->stats.tx_packets, net->stats.tx_bytes); - if ((net_device_ctx->avail -= num_pages) < PACKET_PAGES_LOWATER) + net_device_ctx->avail -= num_pages; + if (net_device_ctx->avail < PACKET_PAGES_LOWATER) netif_stop_queue(net); } else { /* we are shutting down or bus overloaded, just drop packet */ @@ -224,8 +218,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) static void netvsc_linkstatus_callback(struct hv_device *device_obj, unsigned int status) { - struct vm_device *device_ctx = to_vm_device(device_obj); - struct net_device *net = dev_get_drvdata(&device_ctx->device); + struct net_device *net = dev_get_drvdata(&device_obj->device); if (!net) { DPRINT_ERR(NETVSC_DRV, "got link status but net device " @@ -250,8 +243,7 @@ static void netvsc_linkstatus_callback(struct hv_device *device_obj, static int netvsc_recv_callback(struct hv_device *device_obj, struct hv_netvsc_packet *packet) { - struct vm_device *device_ctx = to_vm_device(device_obj); - struct net_device *net = dev_get_drvdata(&device_ctx->device); + struct net_device *net = dev_get_drvdata(&device_obj->device); struct sk_buff *skb; void *data; int i; @@ -278,16 +270,16 @@ static int netvsc_recv_callback(struct hv_device *device_obj, * hv_netvsc_packet cannot be deallocated */ for (i = 0; i < packet->page_buf_cnt; i++) { - data = kmap_atomic(pfn_to_page(packet->page_buf[i].Pfn), + data = kmap_atomic(pfn_to_page(packet->page_buf[i].pfn), KM_IRQ1); data = (void *)(unsigned long)data + - packet->page_buf[i].Offset; + packet->page_buf[i].offset; - memcpy(skb_put(skb, packet->page_buf[i].Length), data, - packet->page_buf[i].Length); + memcpy(skb_put(skb, packet->page_buf[i].len), data, + packet->page_buf[i].len); kunmap_atomic((void *)((unsigned long)data - - packet->page_buf[i].Offset), KM_IRQ1); + packet->page_buf[i].offset), KM_IRQ1); } local_irq_restore(flags); @@ -338,19 +330,16 @@ static const struct net_device_ops device_ops = { static int netvsc_probe(struct device *device) { - struct driver_context *driver_ctx = - driver_to_driver_context(device->driver); - struct netvsc_driver_context *net_drv_ctx = - (struct netvsc_driver_context *)driver_ctx; - struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; - struct vm_device *device_ctx = device_to_vm_device(device); - struct hv_device *device_obj = &device_ctx->device_obj; + struct hv_driver *drv = + drv_to_hv_drv(device->driver); + struct netvsc_driver *net_drv_obj = drv->priv; + struct hv_device *device_obj = device_to_hv_device(device); struct net_device *net = NULL; struct net_device_context *net_device_ctx; struct netvsc_device_info device_info; int ret; - if (!net_drv_obj->base.OnDeviceAdd) + if (!net_drv_obj->base.dev_add) return -1; net = alloc_etherdev(sizeof(struct net_device_context)); @@ -361,12 +350,12 @@ static int netvsc_probe(struct device *device) netif_carrier_off(net); net_device_ctx = netdev_priv(net); - net_device_ctx->device_ctx = device_ctx; + net_device_ctx->device_ctx = device_obj; net_device_ctx->avail = ring_size; dev_set_drvdata(device, net); /* Notify the netvsc driver of the new device */ - ret = net_drv_obj->base.OnDeviceAdd(device_obj, &device_info); + ret = net_drv_obj->base.dev_add(device_obj, &device_info); if (ret != 0) { free_netdev(net); dev_set_drvdata(device, NULL); @@ -401,7 +390,7 @@ static int netvsc_probe(struct device *device) ret = register_netdev(net); if (ret != 0) { /* Remove the device and release the resource */ - net_drv_obj->base.OnDeviceRemove(device_obj); + net_drv_obj->base.dev_rm(device_obj); free_netdev(net); } @@ -410,14 +399,11 @@ static int netvsc_probe(struct device *device) static int netvsc_remove(struct device *device) { - struct driver_context *driver_ctx = - driver_to_driver_context(device->driver); - struct netvsc_driver_context *net_drv_ctx = - (struct netvsc_driver_context *)driver_ctx; - struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; - struct vm_device *device_ctx = device_to_vm_device(device); - struct net_device *net = dev_get_drvdata(&device_ctx->device); - struct hv_device *device_obj = &device_ctx->device_obj; + struct hv_driver *drv = + drv_to_hv_drv(device->driver); + struct netvsc_driver *net_drv_obj = drv->priv; + struct hv_device *device_obj = device_to_hv_device(device); + struct net_device *net = dev_get_drvdata(&device_obj->device); int ret; if (net == NULL) { @@ -425,7 +411,7 @@ static int netvsc_remove(struct device *device) return 0; } - if (!net_drv_obj->base.OnDeviceRemove) + if (!net_drv_obj->base.dev_rm) return -1; /* Stop outbound asap */ @@ -438,7 +424,7 @@ static int netvsc_remove(struct device *device) * Call to the vsc driver to let it know that the device is being * removed */ - ret = net_drv_obj->base.OnDeviceRemove(device_obj); + ret = net_drv_obj->base.dev_rm(device_obj); if (ret != 0) { /* TODO: */ DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret); @@ -459,8 +445,8 @@ static int netvsc_drv_exit_cb(struct device *dev, void *data) static void netvsc_drv_exit(void) { - struct netvsc_driver *netvsc_drv_obj = &g_netvsc_drv.drv_obj; - struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; + struct netvsc_driver *netvsc_drv_obj = &g_netvsc_drv; + struct hv_driver *drv = &g_netvsc_drv.base; struct device *current_dev; int ret; @@ -468,7 +454,7 @@ static void netvsc_drv_exit(void) current_dev = NULL; /* Get the device */ - ret = driver_for_each_device(&drv_ctx->driver, NULL, + ret = driver_for_each_device(&drv->driver, NULL, ¤t_dev, netvsc_drv_exit_cb); if (ret) DPRINT_WARN(NETVSC_DRV, @@ -484,36 +470,35 @@ static void netvsc_drv_exit(void) device_unregister(current_dev); } - if (netvsc_drv_obj->base.OnCleanup) - netvsc_drv_obj->base.OnCleanup(&netvsc_drv_obj->base); + if (netvsc_drv_obj->base.cleanup) + netvsc_drv_obj->base.cleanup(&netvsc_drv_obj->base); - vmbus_child_driver_unregister(drv_ctx); + vmbus_child_driver_unregister(&drv->driver); return; } static int netvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) { - struct netvsc_driver *net_drv_obj = &g_netvsc_drv.drv_obj; - struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; + struct netvsc_driver *net_drv_obj = &g_netvsc_drv; + struct hv_driver *drv = &g_netvsc_drv.base; int ret; net_drv_obj->ring_buf_size = ring_size * PAGE_SIZE; net_drv_obj->recv_cb = netvsc_recv_callback; net_drv_obj->link_status_change = netvsc_linkstatus_callback; + drv->priv = net_drv_obj; /* Callback to client driver to complete the initialization */ drv_init(&net_drv_obj->base); - drv_ctx->driver.name = net_drv_obj->base.name; - memcpy(&drv_ctx->class_id, &net_drv_obj->base.deviceType, - sizeof(struct hv_guid)); + drv->driver.name = net_drv_obj->base.name; - drv_ctx->probe = netvsc_probe; - drv_ctx->remove = netvsc_remove; + drv->driver.probe = netvsc_probe; + drv->driver.remove = netvsc_remove; /* The driver belongs to vmbus */ - ret = vmbus_child_driver_register(drv_ctx); + ret = vmbus_child_driver_register(&drv->driver); return ret; } diff --git a/drivers/staging/hv/osd.c b/drivers/staging/hv/osd.c deleted file mode 100644 index b5a3940331b3..000000000000 --- a/drivers/staging/hv/osd.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * - * Copyright (c) 2009, Microsoft Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307 USA. - * - * Authors: - * Haiyang Zhang <haiyangz@microsoft.com> - * Hank Janssen <hjanssen@microsoft.com> - * - */ - -#include <linux/module.h> -#include <linux/init.h> -#include <linux/types.h> -#include <linux/mm.h> -#include <linux/highmem.h> -#include <linux/vmalloc.h> -#include <linux/ioport.h> -#include <linux/irq.h> -#include <linux/interrupt.h> -#include <linux/sched.h> -#include <linux/wait.h> -#include <linux/spinlock.h> -#include <linux/workqueue.h> -#include <linux/kernel.h> -#include <linux/jiffies.h> -#include <linux/delay.h> -#include <linux/time.h> -#include <linux/io.h> -#include <linux/bitops.h> -#include <linux/slab.h> -#include "osd.h" - -void *osd_virtual_alloc_exec(unsigned int size) -{ -#ifdef __x86_64__ - return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL_EXEC); -#else - return __vmalloc(size, GFP_KERNEL, - __pgprot(__PAGE_KERNEL & (~_PAGE_NX))); -#endif -} - -/** - * osd_page_alloc() - Allocate pages - * @count: Total number of Kernel pages you want to allocate - * - * Tries to allocate @count number of consecutive free kernel pages. - * And if successful, it will set the pages to 0 before returning. - * If successfull it will return pointer to the @count pages. - * Mainly used by Hyper-V drivers. - */ -void *osd_page_alloc(unsigned int count) -{ - void *p; - - p = (void *)__get_free_pages(GFP_KERNEL, get_order(count * PAGE_SIZE)); - if (p) - memset(p, 0, count * PAGE_SIZE); - return p; - - /* struct page* page = alloc_page(GFP_KERNEL|__GFP_ZERO); */ - /* void *p; */ - - /* BUGBUG: We need to use kmap in case we are in HIMEM region */ - /* p = page_address(page); */ - /* if (p) memset(p, 0, PAGE_SIZE); */ - /* return p; */ -} -EXPORT_SYMBOL_GPL(osd_page_alloc); - -/** - * osd_page_free() - Free pages - * @page: Pointer to the first page to be freed - * @count: Total number of Kernel pages you free - * - * Frees the pages allocated by osd_page_alloc() - * Mainly used by Hyper-V drivers. - */ -void osd_page_free(void *page, unsigned int count) -{ - free_pages((unsigned long)page, get_order(count * PAGE_SIZE)); - /*struct page* p = virt_to_page(page); - __free_page(p);*/ -} -EXPORT_SYMBOL_GPL(osd_page_free); - -/** - * osd_waitevent_create() - Create the event queue - * - * Allocates memory for a &struct osd_waitevent. And then calls - * init_waitqueue_head to set up the wait queue for the event. - * This structure is usually part of a another structure that contains - * the actual Hyper-V device driver structure. - * - * Returns pointer to &struct osd_waitevent - * Mainly used by Hyper-V drivers. - */ -struct osd_waitevent *osd_waitevent_create(void) -{ - struct osd_waitevent *wait = kmalloc(sizeof(struct osd_waitevent), - GFP_KERNEL); - if (!wait) - return NULL; - - wait->condition = 0; - init_waitqueue_head(&wait->event); - return wait; -} -EXPORT_SYMBOL_GPL(osd_waitevent_create); - - -/** - * osd_waitevent_set() - Wake up the process - * @wait_event: Structure to event to be woken up - * - * @wait_event is of type &struct osd_waitevent - * - * Wake up the sleeping process so it can do some work. - * And set condition indicator in &struct osd_waitevent to indicate - * the process is in a woken state. - * - * Only used by Network and Storage Hyper-V drivers. - */ -void osd_waitevent_set(struct osd_waitevent *wait_event) -{ - wait_event->condition = 1; - wake_up_interruptible(&wait_event->event); -} -EXPORT_SYMBOL_GPL(osd_waitevent_set); - -/** - * osd_waitevent_wait() - Wait for event till condition is true - * @wait_event: Structure to event to be put to sleep - * - * @wait_event is of type &struct osd_waitevent - * - * Set up the process to sleep until waitEvent->condition get true. - * And set condition indicator in &struct osd_waitevent to indicate - * the process is in a sleeping state. - * - * Returns the status of 'wait_event_interruptible()' system call - * - * Mainly used by Hyper-V drivers. - */ -int osd_waitevent_wait(struct osd_waitevent *wait_event) -{ - int ret = 0; - - ret = wait_event_interruptible(wait_event->event, - wait_event->condition); - wait_event->condition = 0; - return ret; -} -EXPORT_SYMBOL_GPL(osd_waitevent_wait); - -/** - * osd_waitevent_waitex() - Wait for event or timeout for process wakeup - * @wait_event: Structure to event to be put to sleep - * @timeout_in_ms: Total number of Milliseconds to wait before waking up - * - * @wait_event is of type &struct osd_waitevent - * Set up the process to sleep until @waitEvent->condition get true or - * @timeout_in_ms (Time out in Milliseconds) has been reached. - * And set condition indicator in &struct osd_waitevent to indicate - * the process is in a sleeping state. - * - * Returns the status of 'wait_event_interruptible_timeout()' system call - * - * Mainly used by Hyper-V drivers. - */ -int osd_waitevent_waitex(struct osd_waitevent *wait_event, u32 timeout_in_ms) -{ - int ret = 0; - - ret = wait_event_interruptible_timeout(wait_event->event, - wait_event->condition, - msecs_to_jiffies(timeout_in_ms)); - wait_event->condition = 0; - return ret; -} -EXPORT_SYMBOL_GPL(osd_waitevent_waitex); diff --git a/drivers/staging/hv/osd.h b/drivers/staging/hv/osd.h deleted file mode 100644 index 870ef0768833..000000000000 --- a/drivers/staging/hv/osd.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * Copyright (c) 2009, Microsoft Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307 USA. - * - * Authors: - * Haiyang Zhang <haiyangz@microsoft.com> - * Hank Janssen <hjanssen@microsoft.com> - * - */ - - -#ifndef _OSD_H_ -#define _OSD_H_ - -#include <linux/workqueue.h> - -/* Defines */ -#define ALIGN_UP(value, align) (((value) & (align-1)) ? \ - (((value) + (align-1)) & ~(align-1)) : \ - (value)) -#define ALIGN_DOWN(value, align) ((value) & ~(align-1)) -#define NUM_PAGES_SPANNED(addr, len) ((ALIGN_UP(addr+len, PAGE_SIZE) - \ - ALIGN_DOWN(addr, PAGE_SIZE)) >> \ - PAGE_SHIFT) - -#define LOWORD(dw) ((unsigned short)(dw)) -#define HIWORD(dw) ((unsigned short)(((unsigned int) (dw) >> 16) & 0xFFFF)) - -struct hv_guid { - unsigned char data[16]; -}; - -struct osd_waitevent { - int condition; - wait_queue_head_t event; -}; - -/* Osd routines */ - -extern void *osd_virtual_alloc_exec(unsigned int size); - -extern void *osd_page_alloc(unsigned int count); -extern void osd_page_free(void *page, unsigned int count); - -extern struct osd_waitevent *osd_waitevent_create(void); -extern void osd_waitevent_set(struct osd_waitevent *wait_event); -extern int osd_waitevent_wait(struct osd_waitevent *wait_event); - -/* If >0, wait_event got signaled. If ==0, timeout. If < 0, error */ -extern int osd_waitevent_waitex(struct osd_waitevent *wait_event, - u32 timeout_in_ms); - -#endif /* _OSD_H_ */ diff --git a/drivers/staging/hv/ring_buffer.c b/drivers/staging/hv/ring_buffer.c index 4d53392f1e60..66688fb69741 100644 --- a/drivers/staging/hv/ring_buffer.c +++ b/drivers/staging/hv/ring_buffer.c @@ -23,7 +23,6 @@ #include <linux/kernel.h> #include <linux/mm.h> -#include "osd.h" #include "logging.h" #include "ring_buffer.h" diff --git a/drivers/staging/hv/ring_buffer.h b/drivers/staging/hv/ring_buffer.h index 7bd6ecf2f015..7bf20d67187b 100644 --- a/drivers/staging/hv/ring_buffer.h +++ b/drivers/staging/hv/ring_buffer.h @@ -51,7 +51,7 @@ struct hv_ring_buffer { * !!! DO NOT place any fields below this !!! */ u8 buffer[0]; -} __attribute__((packed)); +} __packed; struct hv_ring_buffer_info { struct hv_ring_buffer *ring_buffer; diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c index 53676dcbf381..e7189cd324ca 100644 --- a/drivers/staging/hv/rndis_filter.c +++ b/drivers/staging/hv/rndis_filter.c @@ -19,13 +19,15 @@ * Hank Janssen <hjanssen@microsoft.com> */ #include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/wait.h> #include <linux/highmem.h> #include <linux/slab.h> #include <linux/io.h> #include <linux/if_ether.h> -#include "osd.h" #include "logging.h" +#include "hv_api.h" #include "netvsc_api.h" #include "rndis_filter.h" @@ -57,7 +59,8 @@ struct rndis_device { struct rndis_request { struct list_head list_ent; - struct osd_waitevent *waitevent; + int wait_condition; + wait_queue_head_t wait_event; /* * FIXME: We assumed a fixed size response here. If we do ever need to @@ -129,11 +132,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev, if (!request) return NULL; - request->waitevent = osd_waitevent_create(); - if (!request->waitevent) { - kfree(request); - return NULL; - } + init_waitqueue_head(&request->wait_event); rndis_msg = &request->request_msg; rndis_msg->ndis_msg_type = msg_type; @@ -164,7 +163,6 @@ static void put_rndis_request(struct rndis_device *dev, list_del(&req->list_ent); spin_unlock_irqrestore(&dev->request_lock, flags); - kfree(req->waitevent); kfree(req); } @@ -255,10 +253,10 @@ static int rndis_filter_send_request(struct rndis_device *dev, packet->total_data_buflen = req->request_msg.msg_len; packet->page_buf_cnt = 1; - packet->page_buf[0].Pfn = virt_to_phys(&req->request_msg) >> + packet->page_buf[0].pfn = virt_to_phys(&req->request_msg) >> PAGE_SHIFT; - packet->page_buf[0].Length = req->request_msg.msg_len; - packet->page_buf[0].Offset = + packet->page_buf[0].len = req->request_msg.msg_len; + packet->page_buf[0].offset = (unsigned long)&req->request_msg & (PAGE_SIZE - 1); packet->completion.send.send_completion_ctx = req;/* packet; */ @@ -321,7 +319,8 @@ static void rndis_filter_receive_response(struct rndis_device *dev, } } - osd_waitevent_set(request->waitevent); + request->wait_condition = 1; + wake_up(&request->wait_event); } else { DPRINT_ERR(NETVSC, "no rndis request found for this response " "(id 0x%x res type 0x%x)", @@ -356,10 +355,6 @@ static void rndis_filter_receive_data(struct rndis_device *dev, struct rndis_packet *rndis_pkt; u32 data_offset; - /* empty ethernet frame ?? */ - /* ASSERT(Packet->PageBuffers[0].Length > */ - /* RNDIS_MESSAGE_SIZE(struct rndis_packet)); */ - rndis_pkt = &msg->msg.pkt; /* @@ -371,8 +366,8 @@ static void rndis_filter_receive_data(struct rndis_device *dev, data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset; pkt->total_data_buflen -= data_offset; - pkt->page_buf[0].Offset += data_offset; - pkt->page_buf[0].Length -= data_offset; + pkt->page_buf[0].offset += data_offset; + pkt->page_buf[0].len -= data_offset; pkt->is_data_pkt = true; @@ -383,7 +378,7 @@ static void rndis_filter_receive_data(struct rndis_device *dev, static int rndis_filter_receive(struct hv_device *dev, struct hv_netvsc_packet *pkt) { - struct netvsc_device *net_dev = dev->Extension; + struct netvsc_device *net_dev = dev->ext; struct rndis_device *rndis_dev; struct rndis_message rndis_msg; struct rndis_message *rndis_hdr; @@ -406,10 +401,10 @@ static int rndis_filter_receive(struct hv_device *dev, } rndis_hdr = (struct rndis_message *)kmap_atomic( - pfn_to_page(pkt->page_buf[0].Pfn), KM_IRQ0); + pfn_to_page(pkt->page_buf[0].pfn), KM_IRQ0); rndis_hdr = (void *)((unsigned long)rndis_hdr + - pkt->page_buf[0].Offset); + pkt->page_buf[0].offset); /* Make sure we got a valid rndis message */ /* @@ -419,7 +414,7 @@ static int rndis_filter_receive(struct hv_device *dev, * */ #if 0 if (pkt->total_data_buflen != rndis_hdr->msg_len) { - kunmap_atomic(rndis_hdr - pkt->page_buf[0].Offset, + kunmap_atomic(rndis_hdr - pkt->page_buf[0].offset, KM_IRQ0); DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u " @@ -443,7 +438,7 @@ static int rndis_filter_receive(struct hv_device *dev, sizeof(struct rndis_message) : rndis_hdr->msg_len); - kunmap_atomic(rndis_hdr - pkt->page_buf[0].Offset, KM_IRQ0); + kunmap_atomic(rndis_hdr - pkt->page_buf[0].offset, KM_IRQ0); dump_rndis_message(&rndis_msg); @@ -456,8 +451,6 @@ static int rndis_filter_receive(struct hv_device *dev, case REMOTE_NDIS_INITIALIZE_CMPLT: case REMOTE_NDIS_QUERY_CMPLT: case REMOTE_NDIS_SET_CMPLT: - /* case REMOTE_NDIS_RESET_CMPLT: */ - /* case REMOTE_NDIS_KEEPALIVE_CMPLT: */ /* completion msgs */ rndis_filter_receive_response(rndis_dev, &rndis_msg); break; @@ -503,11 +496,17 @@ static int rndis_filter_query_device(struct rndis_device *dev, u32 oid, query->info_buflen = 0; query->dev_vc_handle = 0; + request->wait_condition = 0; ret = rndis_filter_send_request(dev, request); if (ret != 0) goto Cleanup; - osd_waitevent_wait(request->waitevent); + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { + ret = -ETIMEDOUT; + goto Cleanup; + } /* Copy the response back */ query_complete = &request->response_msg.msg.query_complete; @@ -558,9 +557,6 @@ static int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 status; int ret; - /* ASSERT(RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32) <= */ - /* sizeof(struct rndis_message)); */ - request = get_rndis_request(dev, REMOTE_NDIS_SET_MSG, RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32)); @@ -578,12 +574,14 @@ static int rndis_filter_set_packet_filter(struct rndis_device *dev, memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request), &new_filter, sizeof(u32)); + request->wait_condition = 0; ret = rndis_filter_send_request(dev, request); if (ret != 0) goto Cleanup; - ret = osd_waitevent_waitex(request->waitevent, 2000/*2sec*/); - if (!ret) { + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(2000)); + if (request->wait_condition == 0) { ret = -1; DPRINT_ERR(NETVSC, "timeout before we got a set response..."); /* @@ -622,24 +620,21 @@ int rndis_filter_init(struct netvsc_driver *drv) rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/ /* Save the original dispatch handlers before we override it */ - rndis_filter.inner_drv.base.OnDeviceAdd = drv->base.OnDeviceAdd; - rndis_filter.inner_drv.base.OnDeviceRemove = - drv->base.OnDeviceRemove; - rndis_filter.inner_drv.base.OnCleanup = drv->base.OnCleanup; + rndis_filter.inner_drv.base.dev_add = drv->base.dev_add; + rndis_filter.inner_drv.base.dev_rm = + drv->base.dev_rm; + rndis_filter.inner_drv.base.cleanup = drv->base.cleanup; - /* ASSERT(Driver->OnSend); */ - /* ASSERT(Driver->OnReceiveCallback); */ rndis_filter.inner_drv.send = drv->send; rndis_filter.inner_drv.recv_cb = drv->recv_cb; rndis_filter.inner_drv.link_status_change = drv->link_status_change; /* Override */ - drv->base.OnDeviceAdd = rndis_filte_device_add; - drv->base.OnDeviceRemove = rndis_filter_device_remove; - drv->base.OnCleanup = rndis_filter_cleanup; + drv->base.dev_add = rndis_filte_device_add; + drv->base.dev_rm = rndis_filter_device_remove; + drv->base.cleanup = rndis_filter_cleanup; drv->send = rndis_filter_send; - /* Driver->QueryLinkStatus = RndisFilterQueryDeviceLinkStatus; */ drv->recv_cb = rndis_filter_receive; return 0; @@ -669,13 +664,20 @@ static int rndis_filter_init_device(struct rndis_device *dev) dev->state = RNDIS_DEV_INITIALIZING; + request->wait_condition = 0; ret = rndis_filter_send_request(dev, request); if (ret != 0) { dev->state = RNDIS_DEV_UNINITIALIZED; goto Cleanup; } - osd_waitevent_wait(request->waitevent); + + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { + ret = -ETIMEDOUT; + goto Cleanup; + } init_complete = &request->response_msg.msg.init_complete; status = init_complete->status; @@ -770,7 +772,7 @@ static int rndis_filte_device_add(struct hv_device *dev, * NOTE! Once the channel is created, we may get a receive callback * (RndisFilterOnReceive()) before this call is completed */ - ret = rndis_filter.inner_drv.base.OnDeviceAdd(dev, additional_info); + ret = rndis_filter.inner_drv.base.dev_add(dev, additional_info); if (ret != 0) { kfree(rndisDevice); return ret; @@ -778,9 +780,7 @@ static int rndis_filte_device_add(struct hv_device *dev, /* Initialize the rndis device */ - netDevice = dev->Extension; - /* ASSERT(netDevice); */ - /* ASSERT(netDevice->Device); */ + netDevice = dev->ext; netDevice->extension = rndisDevice; rndisDevice->net_dev = netDevice; @@ -818,7 +818,7 @@ static int rndis_filte_device_add(struct hv_device *dev, static int rndis_filter_device_remove(struct hv_device *dev) { - struct netvsc_device *net_dev = dev->Extension; + struct netvsc_device *net_dev = dev->ext; struct rndis_device *rndis_dev = net_dev->extension; /* Halt and release the rndis device */ @@ -828,7 +828,7 @@ static int rndis_filter_device_remove(struct hv_device *dev) net_dev->extension = NULL; /* Pass control to inner driver to remove the device */ - rndis_filter.inner_drv.base.OnDeviceRemove(dev); + rndis_filter.inner_drv.base.dev_rm(dev); return 0; } @@ -839,7 +839,7 @@ static void rndis_filter_cleanup(struct hv_driver *drv) int rndis_filter_open(struct hv_device *dev) { - struct netvsc_device *netDevice = dev->Extension; + struct netvsc_device *netDevice = dev->ext; if (!netDevice) return -EINVAL; @@ -849,7 +849,7 @@ int rndis_filter_open(struct hv_device *dev) int rndis_filter_close(struct hv_device *dev) { - struct netvsc_device *netDevice = dev->Extension; + struct netvsc_device *netDevice = dev->ext; if (!netDevice) return -EINVAL; @@ -868,7 +868,6 @@ static int rndis_filter_send(struct hv_device *dev, /* Add the rndis header */ filterPacket = (struct rndis_filter_packet *)pkt->extension; - /* ASSERT(filterPacket); */ memset(filterPacket, 0, sizeof(struct rndis_filter_packet)); @@ -884,10 +883,10 @@ static int rndis_filter_send(struct hv_device *dev, rndisPacket->data_len = pkt->total_data_buflen; pkt->is_data_pkt = true; - pkt->page_buf[0].Pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT; - pkt->page_buf[0].Offset = + pkt->page_buf[0].pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT; + pkt->page_buf[0].offset = (unsigned long)rndisMessage & (PAGE_SIZE-1); - pkt->page_buf[0].Length = rndisMessageSize; + pkt->page_buf[0].len = rndisMessageSize; /* Save the packet send completion and context */ filterPacket->completion = pkt->completion.send.send_completion; diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c index 9295113e09b9..e2ad72924184 100644 --- a/drivers/staging/hv/storvsc.c +++ b/drivers/staging/hv/storvsc.c @@ -19,11 +19,13 @@ * Hank Janssen <hjanssen@microsoft.com> */ #include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/wait.h> #include <linux/string.h> #include <linux/slab.h> #include <linux/mm.h> #include <linux/delay.h> -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "storvsc_api.h" #include "vmbus_packet_format.h" @@ -38,7 +40,8 @@ struct storvsc_request_extension { struct hv_device *device; /* Synchronize the request/response if needed */ - struct osd_waitevent *wait_event; + int wait_condition; + wait_queue_head_t wait_event; struct vstor_packet vstor_packet; }; @@ -94,7 +97,7 @@ static inline struct storvsc_device *alloc_stor_device(struct hv_device *device) atomic_cmpxchg(&stor_device->ref_count, 0, 2); stor_device->device = device; - device->Extension = stor_device; + device->ext = stor_device; return stor_device; } @@ -110,7 +113,7 @@ static inline struct storvsc_device *get_stor_device(struct hv_device *device) { struct storvsc_device *stor_device; - stor_device = (struct storvsc_device *)device->Extension; + stor_device = (struct storvsc_device *)device->ext; if (stor_device && atomic_read(&stor_device->ref_count) > 1) atomic_inc(&stor_device->ref_count); else @@ -125,7 +128,7 @@ static inline struct storvsc_device *must_get_stor_device( { struct storvsc_device *stor_device; - stor_device = (struct storvsc_device *)device->Extension; + stor_device = (struct storvsc_device *)device->ext; if (stor_device && atomic_read(&stor_device->ref_count)) atomic_inc(&stor_device->ref_count); else @@ -138,7 +141,7 @@ static inline void put_stor_device(struct hv_device *device) { struct storvsc_device *stor_device; - stor_device = (struct storvsc_device *)device->Extension; + stor_device = (struct storvsc_device *)device->ext; /* ASSERT(stor_device); */ atomic_dec(&stor_device->ref_count); @@ -151,7 +154,7 @@ static inline struct storvsc_device *release_stor_device( { struct storvsc_device *stor_device; - stor_device = (struct storvsc_device *)device->Extension; + stor_device = (struct storvsc_device *)device->ext; /* ASSERT(stor_device); */ /* Busy wait until the ref drop to 2, then set it to 1 */ @@ -167,14 +170,14 @@ static inline struct storvsc_device *final_release_stor_device( { struct storvsc_device *stor_device; - stor_device = (struct storvsc_device *)device->Extension; + stor_device = (struct storvsc_device *)device->ext; /* ASSERT(stor_device); */ /* Busy wait until the ref drop to 1, then set it to 0 */ while (atomic_cmpxchg(&stor_device->ref_count, 1, 0) != 1) udelay(100); - device->Extension = NULL; + device->ext = NULL; return stor_device; } @@ -200,40 +203,38 @@ static int stor_vsc_channel_init(struct hv_device *device) * channel */ memset(request, 0, sizeof(struct storvsc_request_extension)); - request->wait_event = osd_waitevent_create(); - if (!request->wait_event) { - ret = -ENOMEM; - goto nomem; - } - + init_waitqueue_head(&request->wait_event); vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION; vstor_packet->flags = REQUEST_COMPLETION_FLAG; - /*SpinlockAcquire(gDriverExt.packetListLock); - INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry); - SpinlockRelease(gDriverExt.packetListLock);*/ - DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION..."); + request->wait_condition = 0; ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION"); - goto Cleanup; + goto cleanup; + } + + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { + ret = -ETIMEDOUT; + goto cleanup; } - osd_waitevent_wait(request->wait_event); if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || vstor_packet->status != 0) { DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed " "(op %d status 0x%x)", vstor_packet->operation, vstor_packet->status); - goto Cleanup; + goto cleanup; } DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION..."); @@ -246,18 +247,24 @@ static int stor_vsc_channel_init(struct hv_device *device) vstor_packet->version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT; FILL_VMSTOR_REVISION(vstor_packet->version.revision); + request->wait_condition = 0; ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION"); - goto Cleanup; + goto cleanup; } - osd_waitevent_wait(request->wait_event); + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { + ret = -ETIMEDOUT; + goto cleanup; + } /* TODO: Check returned version */ if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || @@ -265,7 +272,7 @@ static int stor_vsc_channel_init(struct hv_device *device) DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed " "(op %d status 0x%x)", vstor_packet->operation, vstor_packet->status); - goto Cleanup; + goto cleanup; } /* Query channel properties */ @@ -277,19 +284,25 @@ static int stor_vsc_channel_init(struct hv_device *device) vstor_packet->storage_channel_properties.port_number = stor_device->port_number; + request->wait_condition = 0; ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send QUERY_PROPERTIES_OPERATION"); - goto Cleanup; + goto cleanup; } - osd_waitevent_wait(request->wait_event); + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { + ret = -ETIMEDOUT; + goto cleanup; + } /* TODO: Check returned version */ if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || @@ -297,7 +310,7 @@ static int stor_vsc_channel_init(struct hv_device *device) DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed " "(op %d status 0x%x)", vstor_packet->operation, vstor_packet->status); - goto Cleanup; + goto cleanup; } stor_device->path_id = vstor_packet->storage_channel_properties.path_id; @@ -314,34 +327,37 @@ static int stor_vsc_channel_init(struct hv_device *device) vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION; vstor_packet->flags = REQUEST_COMPLETION_FLAG; + request->wait_condition = 0; ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send END_INITIALIZATION_OPERATION"); - goto Cleanup; + goto cleanup; } - osd_waitevent_wait(request->wait_event); + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { + ret = -ETIMEDOUT; + goto cleanup; + } if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || vstor_packet->status != 0) { DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed " "(op %d status 0x%x)", vstor_packet->operation, vstor_packet->status); - goto Cleanup; + goto cleanup; } DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****"); -Cleanup: - kfree(request->wait_event); - request->wait_event = NULL; -nomem: +cleanup: put_stor_device(device); return ret; } @@ -437,7 +453,7 @@ static void stor_vsc_on_channel_callback(void *context) struct storvsc_device *stor_device; u32 bytes_recvd; u64 request_id; - unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet), 8)]; + unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)]; struct storvsc_request_extension *request; int ret; @@ -452,7 +468,7 @@ static void stor_vsc_on_channel_callback(void *context) do { ret = vmbus_recvpacket(device->channel, packet, - ALIGN_UP(sizeof(struct vstor_packet), 8), + ALIGN(sizeof(struct vstor_packet), 8), &bytes_recvd, &request_id); if (ret == 0 && bytes_recvd > 0) { DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", @@ -476,8 +492,8 @@ static void stor_vsc_on_channel_callback(void *context) memcpy(&request->vstor_packet, packet, sizeof(struct vstor_packet)); - - osd_waitevent_set(request->wait_event); + request->wait_condition = 1; + wake_up(&request->wait_event); } else { stor_vsc_on_receive(device, (struct vstor_packet *)packet, @@ -499,7 +515,7 @@ static int stor_vsc_connect_to_vsp(struct hv_device *device) struct storvsc_driver_object *stor_driver; int ret; - stor_driver = (struct storvsc_driver_object *)device->Driver; + stor_driver = (struct storvsc_driver_object *)device->drv; memset(&props, 0, sizeof(struct vmstorage_channel_properties)); /* Open the channel */ @@ -539,7 +555,7 @@ static int stor_vsc_on_device_add(struct hv_device *device, stor_device = alloc_stor_device(device); if (!stor_device) { ret = -1; - goto Cleanup; + goto cleanup; } /* Save the channel properties to our storvsc channel */ @@ -569,7 +585,7 @@ static int stor_vsc_on_device_add(struct hv_device *device, stor_device->port_number, stor_device->path_id, stor_device->target_id); -Cleanup: +cleanup: return ret; } @@ -581,7 +597,7 @@ static int stor_vsc_on_device_remove(struct hv_device *device) struct storvsc_device *stor_device; DPRINT_INFO(STORVSC, "disabling storage device (%p)...", - device->Extension); + device->ext); stor_device = release_stor_device(device); @@ -597,7 +613,7 @@ static int stor_vsc_on_device_remove(struct hv_device *device) } DPRINT_INFO(STORVSC, "removing storage device (%p)...", - device->Extension); + device->ext); stor_device = final_release_stor_device(device); @@ -629,31 +645,31 @@ int stor_vsc_on_host_reset(struct hv_device *device) request = &stor_device->reset_request; vstor_packet = &request->vstor_packet; - request->wait_event = osd_waitevent_create(); - if (!request->wait_event) { - ret = -ENOMEM; - goto Cleanup; - } + init_waitqueue_head(&request->wait_event); vstor_packet->operation = VSTOR_OPERATION_RESET_BUS; vstor_packet->flags = REQUEST_COMPLETION_FLAG; vstor_packet->vm_srb.path_id = stor_device->path_id; + request->wait_condition = 0; ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)&stor_device->reset_request, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", vstor_packet, ret); - goto Cleanup; + goto cleanup; } - /* FIXME: Add a timeout */ - osd_waitevent_wait(request->wait_event); + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { + ret = -ETIMEDOUT; + goto cleanup; + } - kfree(request->wait_event); DPRINT_INFO(STORVSC, "host adapter reset completed"); /* @@ -661,7 +677,7 @@ int stor_vsc_on_host_reset(struct hv_device *device) * should have been flushed out and return to us */ -Cleanup: +cleanup: put_stor_device(device); return ret; } @@ -687,7 +703,7 @@ static int stor_vsc_on_io_request(struct hv_device *device, request_extension); DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d", - request, request->data_buffer.Length, request->bus, + request, request->data_buffer.len, request->bus, request->target_id, request->lun_id, request->cdb_len); if (!stor_device) { @@ -720,7 +736,7 @@ static int stor_vsc_on_io_request(struct hv_device *device, memcpy(&vstor_packet->vm_srb.cdb, request->cdb, request->cdb_len); vstor_packet->vm_srb.data_in = request->type; - vstor_packet->vm_srb.data_transfer_length = request->data_buffer.Length; + vstor_packet->vm_srb.data_transfer_length = request->data_buffer.len; vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB; @@ -734,7 +750,7 @@ static int stor_vsc_on_io_request(struct hv_device *device, vstor_packet->vm_srb.sense_info_length, vstor_packet->vm_srb.cdb_length); - if (request_extension->request->data_buffer.Length) { + if (request_extension->request->data_buffer.len) { ret = vmbus_sendpacket_multipagebuffer(device->channel, &request_extension->request->data_buffer, vstor_packet, @@ -744,7 +760,7 @@ static int stor_vsc_on_io_request(struct hv_device *device, ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request_extension, - VmbusPacketTypeDataInBand, + VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); } @@ -788,7 +804,7 @@ int stor_vsc_initialize(struct hv_driver *driver) /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */ driver->name = g_driver_name; - memcpy(&driver->deviceType, &gStorVscDeviceType, + memcpy(&driver->dev_type, &gStorVscDeviceType, sizeof(struct hv_guid)); stor_driver->request_ext_size = @@ -802,7 +818,7 @@ int stor_vsc_initialize(struct hv_driver *driver) */ stor_driver->max_outstanding_req_per_channel = ((stor_driver->ring_buffer_size - PAGE_SIZE) / - ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + + ALIGN(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(struct vstor_packet) + sizeof(u64), sizeof(u64))); @@ -811,9 +827,9 @@ int stor_vsc_initialize(struct hv_driver *driver) STORVSC_MAX_IO_REQUESTS); /* Setup the dispatch table */ - stor_driver->base.OnDeviceAdd = stor_vsc_on_device_add; - stor_driver->base.OnDeviceRemove = stor_vsc_on_device_remove; - stor_driver->base.OnCleanup = stor_vsc_on_cleanup; + stor_driver->base.dev_add = stor_vsc_on_device_add; + stor_driver->base.dev_rm = stor_vsc_on_device_remove; + stor_driver->base.cleanup = stor_vsc_on_cleanup; stor_driver->on_io_request = stor_vsc_on_io_request; diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c index 17f1b344fbc5..e6462a2fe9ab 100644 --- a/drivers/staging/hv/storvsc_drv.c +++ b/drivers/staging/hv/storvsc_drv.c @@ -31,7 +31,7 @@ #include <scsi/scsi_eh.h> #include <scsi/scsi_devinfo.h> #include <scsi/scsi_dbg.h> -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "version_info.h" #include "vmbus.h" @@ -42,7 +42,7 @@ struct host_device_context { /* must be 1st field * FIXME this is a bug */ /* point back to our device context */ - struct vm_device *device_ctx; + struct hv_device *device_ctx; struct kmem_cache *request_pool; unsigned int port; unsigned char path; @@ -63,12 +63,6 @@ struct storvsc_cmd_request { * Which sounds like a very bad design... */ }; -struct storvsc_driver_context { - /* !! These must be the first 2 fields !! */ - /* FIXME this is a bug... */ - struct driver_context drv_ctx; - struct storvsc_driver_object drv_obj; -}; /* Static decl */ static int storvsc_probe(struct device *dev); @@ -100,7 +94,7 @@ module_param(storvsc_ringbuffer_size, int, S_IRUGO); MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)"); /* The one and only one */ -static struct storvsc_driver_context g_storvsc_drv; +static struct storvsc_driver_object g_storvsc_drv; /* Scsi driver */ static struct scsi_host_template scsi_driver = { @@ -137,14 +131,16 @@ static struct scsi_host_template scsi_driver = { static int storvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) { int ret; - struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv.drv_obj; - struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx; + struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv; + struct hv_driver *drv = &g_storvsc_drv.base; storvsc_drv_obj->ring_buffer_size = storvsc_ringbuffer_size; /* Callback to client driver to complete the initialization */ drv_init(&storvsc_drv_obj->base); + drv->priv = storvsc_drv_obj; + DPRINT_INFO(STORVSC_DRV, "request extension size %u, max outstanding reqs %u", storvsc_drv_obj->request_ext_size, @@ -160,15 +156,13 @@ static int storvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) return -1; } - drv_ctx->driver.name = storvsc_drv_obj->base.name; - memcpy(&drv_ctx->class_id, &storvsc_drv_obj->base.deviceType, - sizeof(struct hv_guid)); + drv->driver.name = storvsc_drv_obj->base.name; - drv_ctx->probe = storvsc_probe; - drv_ctx->remove = storvsc_remove; + drv->driver.probe = storvsc_probe; + drv->driver.remove = storvsc_remove; /* The driver belongs to vmbus */ - ret = vmbus_child_driver_register(drv_ctx); + ret = vmbus_child_driver_register(&drv->driver); return ret; } @@ -182,8 +176,8 @@ static int storvsc_drv_exit_cb(struct device *dev, void *data) static void storvsc_drv_exit(void) { - struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv.drv_obj; - struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx; + struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv; + struct hv_driver *drv = &g_storvsc_drv.base; struct device *current_dev = NULL; int ret; @@ -191,7 +185,7 @@ static void storvsc_drv_exit(void) current_dev = NULL; /* Get the device */ - ret = driver_for_each_device(&drv_ctx->driver, NULL, + ret = driver_for_each_device(&drv->driver, NULL, (void *) ¤t_dev, storvsc_drv_exit_cb); @@ -206,10 +200,10 @@ static void storvsc_drv_exit(void) device_unregister(current_dev); } - if (storvsc_drv_obj->base.OnCleanup) - storvsc_drv_obj->base.OnCleanup(&storvsc_drv_obj->base); + if (storvsc_drv_obj->base.cleanup) + storvsc_drv_obj->base.cleanup(&storvsc_drv_obj->base); - vmbus_child_driver_unregister(drv_ctx); + vmbus_child_driver_unregister(&drv->driver); return; } @@ -219,19 +213,15 @@ static void storvsc_drv_exit(void) static int storvsc_probe(struct device *device) { int ret; - struct driver_context *driver_ctx = - driver_to_driver_context(device->driver); - struct storvsc_driver_context *storvsc_drv_ctx = - (struct storvsc_driver_context *)driver_ctx; - struct storvsc_driver_object *storvsc_drv_obj = - &storvsc_drv_ctx->drv_obj; - struct vm_device *device_ctx = device_to_vm_device(device); - struct hv_device *device_obj = &device_ctx->device_obj; + struct hv_driver *drv = + drv_to_hv_drv(device->driver); + struct storvsc_driver_object *storvsc_drv_obj = drv->priv; + struct hv_device *device_obj = device_to_hv_device(device); struct Scsi_Host *host; struct host_device_context *host_device_ctx; struct storvsc_device_info device_info; - if (!storvsc_drv_obj->base.OnDeviceAdd) + if (!storvsc_drv_obj->base.dev_add) return -1; host = scsi_host_alloc(&scsi_driver, @@ -247,10 +237,10 @@ static int storvsc_probe(struct device *device) memset(host_device_ctx, 0, sizeof(struct host_device_context)); host_device_ctx->port = host->host_no; - host_device_ctx->device_ctx = device_ctx; + host_device_ctx->device_ctx = device_obj; host_device_ctx->request_pool = - kmem_cache_create(dev_name(&device_ctx->device), + kmem_cache_create(dev_name(&device_obj->device), sizeof(struct storvsc_cmd_request) + storvsc_drv_obj->request_ext_size, 0, SLAB_HWCACHE_ALIGN, NULL); @@ -262,7 +252,7 @@ static int storvsc_probe(struct device *device) device_info.port_number = host->host_no; /* Call to the vsc driver to add the device */ - ret = storvsc_drv_obj->base.OnDeviceAdd(device_obj, + ret = storvsc_drv_obj->base.dev_add(device_obj, (void *)&device_info); if (ret != 0) { DPRINT_ERR(STORVSC_DRV, "unable to add scsi vsc device"); @@ -287,7 +277,7 @@ static int storvsc_probe(struct device *device) if (ret != 0) { DPRINT_ERR(STORVSC_DRV, "unable to add scsi host device"); - storvsc_drv_obj->base.OnDeviceRemove(device_obj); + storvsc_drv_obj->base.dev_rm(device_obj); kmem_cache_destroy(host_device_ctx->request_pool); scsi_host_put(host); @@ -304,27 +294,23 @@ static int storvsc_probe(struct device *device) static int storvsc_remove(struct device *device) { int ret; - struct driver_context *driver_ctx = - driver_to_driver_context(device->driver); - struct storvsc_driver_context *storvsc_drv_ctx = - (struct storvsc_driver_context *)driver_ctx; - struct storvsc_driver_object *storvsc_drv_obj = - &storvsc_drv_ctx->drv_obj; - struct vm_device *device_ctx = device_to_vm_device(device); - struct hv_device *device_obj = &device_ctx->device_obj; + struct hv_driver *drv = + drv_to_hv_drv(device->driver); + struct storvsc_driver_object *storvsc_drv_obj = drv->priv; + struct hv_device *device_obj = device_to_hv_device(device); struct Scsi_Host *host = dev_get_drvdata(device); struct host_device_context *host_device_ctx = (struct host_device_context *)host->hostdata; - if (!storvsc_drv_obj->base.OnDeviceRemove) + if (!storvsc_drv_obj->base.dev_rm) return -1; /* * Call to the vsc driver to let it know that the device is being * removed */ - ret = storvsc_drv_obj->base.OnDeviceRemove(device_obj); + ret = storvsc_drv_obj->base.dev_rm(device_obj); if (ret != 0) { /* TODO: */ DPRINT_ERR(STORVSC, "unable to remove vsc device (ret %d)", @@ -385,7 +371,7 @@ static void storvsc_commmand_completion(struct hv_storvsc_request *request) /* ASSERT(request->BytesXfer <= request->data_buffer.Length); */ scsi_set_resid(scmnd, - request->data_buffer.Length - request->bytes_xfer); + request->data_buffer.len - request->bytes_xfer); scsi_done_fn = scmnd->scsi_done; @@ -434,7 +420,7 @@ static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, struct scatterlist *bounce_sgl; struct page *page_buf; - num_pages = ALIGN_UP(len, PAGE_SIZE) >> PAGE_SHIFT; + num_pages = ALIGN(len, PAGE_SIZE) >> PAGE_SHIFT; bounce_sgl = kcalloc(num_pages, sizeof(struct scatterlist), GFP_ATOMIC); if (!bounce_sgl) @@ -601,13 +587,10 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, int ret; struct host_device_context *host_device_ctx = (struct host_device_context *)scmnd->device->host->hostdata; - struct vm_device *device_ctx = host_device_ctx->device_ctx; - struct driver_context *driver_ctx = - driver_to_driver_context(device_ctx->device.driver); - struct storvsc_driver_context *storvsc_drv_ctx = - (struct storvsc_driver_context *)driver_ctx; - struct storvsc_driver_object *storvsc_drv_obj = - &storvsc_drv_ctx->drv_obj; + struct hv_device *device_ctx = host_device_ctx->device_ctx; + struct hv_driver *drv = + drv_to_hv_drv(device_ctx->device.driver); + struct storvsc_driver_object *storvsc_drv_obj = drv->priv; struct hv_storvsc_request *request; struct storvsc_cmd_request *cmd_request; unsigned int request_size = 0; @@ -693,7 +676,7 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, request->sense_buffer_size = SCSI_SENSE_BUFFERSIZE; - request->data_buffer.Length = scsi_bufflen(scmnd); + request->data_buffer.len = scsi_bufflen(scmnd); if (scsi_sg_count(scmnd)) { sgl = (struct scatterlist *)scsi_sglist(scmnd); sg_count = scsi_sg_count(scmnd); @@ -720,7 +703,7 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, } cmd_request->bounce_sgl_count = - ALIGN_UP(scsi_bufflen(scmnd), PAGE_SIZE) >> + ALIGN(scsi_bufflen(scmnd), PAGE_SIZE) >> PAGE_SHIFT; /* @@ -734,25 +717,25 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, sg_count = cmd_request->bounce_sgl_count; } - request->data_buffer.Offset = sgl[0].offset; + request->data_buffer.offset = sgl[0].offset; for (i = 0; i < sg_count; i++) { DPRINT_DBG(STORVSC_DRV, "sgl[%d] len %d offset %d\n", i, sgl[i].length, sgl[i].offset); - request->data_buffer.PfnArray[i] = + request->data_buffer.pfn_array[i] = page_to_pfn(sg_page((&sgl[i]))); } } else if (scsi_sglist(scmnd)) { /* ASSERT(scsi_bufflen(scmnd) <= PAGE_SIZE); */ - request->data_buffer.Offset = + request->data_buffer.offset = virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1); - request->data_buffer.PfnArray[0] = + request->data_buffer.pfn_array[0] = virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT; } retry_request: /* Invokes the vsc to start an IO */ - ret = storvsc_drv_obj->on_io_request(&device_ctx->device_obj, + ret = storvsc_drv_obj->on_io_request(device_ctx, &cmd_request->request); if (ret == -1) { /* no more space */ @@ -839,18 +822,18 @@ static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd) int ret; struct host_device_context *host_device_ctx = (struct host_device_context *)scmnd->device->host->hostdata; - struct vm_device *device_ctx = host_device_ctx->device_ctx; + struct hv_device *device_ctx = host_device_ctx->device_ctx; DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host resetting...", - scmnd->device, &device_ctx->device_obj); + scmnd->device, device_ctx); /* Invokes the vsc to reset the host/bus */ - ret = stor_vsc_on_host_reset(&device_ctx->device_obj); + ret = stor_vsc_on_host_reset(device_ctx); if (ret != 0) return ret; DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host reseted", - scmnd->device, &device_ctx->device_obj); + scmnd->device, device_ctx); return ret; } diff --git a/drivers/staging/hv/tools/hv_kvp_daemon.c b/drivers/staging/hv/tools/hv_kvp_daemon.c new file mode 100644 index 000000000000..f5a2dd694611 --- /dev/null +++ b/drivers/staging/hv/tools/hv_kvp_daemon.c @@ -0,0 +1,470 @@ +/* + * An implementation of key value pair (KVP) functionality for Linux. + * + * + * Copyright (C) 2010, Novell, Inc. + * Author : K. Y. Srinivasan <ksrinivasan@novell.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or + * NON INFRINGEMENT. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/poll.h> +#include <sys/utsname.h> +#include <linux/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <arpa/inet.h> +#include <linux/connector.h> +#include <linux/netlink.h> +#include <sys/socket.h> +#include <ifaddrs.h> +#include <netdb.h> +#include <syslog.h> + +/* + * KYS: TODO. Need to register these in the kernel. + * + * The following definitions are shared with the in-kernel component; do not + * change any of this without making the corresponding changes in + * the KVP kernel component. + */ +#define CN_KVP_IDX 0x9 /* MSFT KVP functionality */ +#define CN_KVP_VAL 0x1 /* This supports queries from the kernel */ +#define CN_KVP_USER_VAL 0x2 /* This supports queries from the user */ + +/* + * KVP protocol: The user mode component first registers with the + * the kernel component. Subsequently, the kernel component requests, data + * for the specified keys. In response to this message the user mode component + * fills in the value corresponding to the specified key. We overload the + * sequence field in the cn_msg header to define our KVP message types. + * + * We use this infrastructure for also supporting queries from user mode + * application for state that may be maintained in the KVP kernel component. + * + * XXXKYS: Have a shared header file between the user and kernel (TODO) + */ + +enum kvp_op { + KVP_REGISTER = 0, /* Register the user mode component*/ + KVP_KERNEL_GET, /*Kernel is requesting the value for the specified key*/ + KVP_KERNEL_SET, /*Kernel is providing the value for the specified key*/ + KVP_USER_GET, /*User is requesting the value for the specified key*/ + KVP_USER_SET /*User is providing the value for the specified key*/ +}; + +#define HV_KVP_EXCHANGE_MAX_KEY_SIZE 512 +#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE 2048 + +struct hv_ku_msg { + __u32 kvp_index; + __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */ + __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */ +}; + +enum key_index { + FullyQualifiedDomainName = 0, + IntegrationServicesVersion, /*This key is serviced in the kernel*/ + NetworkAddressIPv4, + NetworkAddressIPv6, + OSBuildNumber, + OSName, + OSMajorVersion, + OSMinorVersion, + OSVersion, + ProcessorArchitecture +}; + +/* + * End of shared definitions. + */ + +static char kvp_send_buffer[4096]; +static char kvp_recv_buffer[4096]; +static struct sockaddr_nl addr; + +static char os_name[100]; +static char os_major[50]; +static char os_minor[50]; +static char processor_arch[50]; +static char os_build[100]; +static char *lic_version; + +void kvp_get_os_info(void) +{ + FILE *file; + char *eol; + struct utsname buf; + + uname(&buf); + strcpy(os_build, buf.release); + strcpy(processor_arch, buf.machine); + + file = fopen("/etc/SuSE-release", "r"); + if (file != NULL) + goto kvp_osinfo_found; + file = fopen("/etc/redhat-release", "r"); + if (file != NULL) + goto kvp_osinfo_found; + /* + * Add code for other supported platforms. + */ + + /* + * We don't have information about the os. + */ + strcpy(os_name, "Linux"); + strcpy(os_major, "0"); + strcpy(os_minor, "0"); + return; + +kvp_osinfo_found: + fgets(os_name, 99, file); + eol = index(os_name, '\n'); + *eol = '\0'; + fgets(os_major, 49, file); + eol = index(os_major, '\n'); + *eol = '\0'; + fgets(os_minor, 49, file); + eol = index(os_minor, '\n'); + *eol = '\0'; + fclose(file); + return; +} + +static int +kvp_get_ip_address(int family, char *buffer, int length) +{ + struct ifaddrs *ifap; + struct ifaddrs *curp; + int ipv4_len = strlen("255.255.255.255") + 1; + int ipv6_len = strlen("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")+1; + int offset = 0; + const char *str; + char tmp[50]; + int error = 0; + + /* + * On entry into this function, the buffer is capable of holding the + * maximum key value (2048 bytes). + */ + + if (getifaddrs(&ifap)) { + strcpy(buffer, "getifaddrs failed\n"); + return 1; + } + + curp = ifap; + while (curp != NULL) { + if ((curp->ifa_addr != NULL) && + (curp->ifa_addr->sa_family == family)) { + if (family == AF_INET) { + struct sockaddr_in *addr = + (struct sockaddr_in *) curp->ifa_addr; + + str = inet_ntop(family, &addr->sin_addr, + tmp, 50); + if (str == NULL) { + strcpy(buffer, "inet_ntop failed\n"); + error = 1; + goto getaddr_done; + } + if (offset == 0) + strcpy(buffer, tmp); + else + strcat(buffer, tmp); + strcat(buffer, ";"); + + offset += strlen(str) + 1; + if ((length - offset) < (ipv4_len + 1)) + goto getaddr_done; + + } else { + + /* + * We only support AF_INET and AF_INET6 + * and the list of addresses is seperated by a ";". + */ + struct sockaddr_in6 *addr = + (struct sockaddr_in6 *) curp->ifa_addr; + + str = inet_ntop(family, + &addr->sin6_addr.s6_addr, + tmp, 50); + if (str == NULL) { + strcpy(buffer, "inet_ntop failed\n"); + error = 1; + goto getaddr_done; + } + if (offset == 0) + strcpy(buffer, tmp); + else + strcat(buffer, tmp); + strcat(buffer, ";"); + offset += strlen(str) + 1; + if ((length - offset) < (ipv6_len + 1)) + goto getaddr_done; + + } + + } + curp = curp->ifa_next; + } + +getaddr_done: + freeifaddrs(ifap); + return error; +} + + +static int +kvp_get_domain_name(char *buffer, int length) +{ + struct addrinfo hints, *info ; + gethostname(buffer, length); + int error = 0; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; /*Get only ipv4 addrinfo. */ + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_CANONNAME; + + error = getaddrinfo(buffer, "http", &hints, &info); + if (error != 0) { + strcpy(buffer, "getaddrinfo failed\n"); + error = 1; + goto get_domain_done; + } + strcpy(buffer, info->ai_canonname); +get_domain_done: + freeaddrinfo(info); + return error; +} + +static int +netlink_send(int fd, struct cn_msg *msg) +{ + struct nlmsghdr *nlh; + unsigned int size; + struct msghdr message; + char buffer[64]; + struct iovec iov[2]; + + size = NLMSG_SPACE(sizeof(struct cn_msg) + msg->len); + + nlh = (struct nlmsghdr *)buffer; + nlh->nlmsg_seq = 0; + nlh->nlmsg_pid = getpid(); + nlh->nlmsg_type = NLMSG_DONE; + nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh)); + nlh->nlmsg_flags = 0; + + iov[0].iov_base = nlh; + iov[0].iov_len = sizeof(*nlh); + + iov[1].iov_base = msg; + iov[1].iov_len = size; + + memset(&message, 0, sizeof(message)); + message.msg_name = &addr; + message.msg_namelen = sizeof(addr); + message.msg_iov = iov; + message.msg_iovlen = 2; + + return sendmsg(fd, &message, 0); +} + +main(void) +{ + int fd, len, sock_opt; + int error; + struct cn_msg *message; + struct pollfd pfd; + struct nlmsghdr *incoming_msg; + struct cn_msg *incoming_cn_msg; + char *key_value; + char *key_name; + int key_index; + + daemon(1, 0); + openlog("KVP", 0, LOG_USER); + syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); + /* + * Retrieve OS release information. + */ + kvp_get_os_info(); + + fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); + if (fd < 0) { + syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd); + exit(-1); + } + addr.nl_family = AF_NETLINK; + addr.nl_pad = 0; + addr.nl_pid = 0; + addr.nl_groups = CN_KVP_IDX; + + + error = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); + if (error < 0) { + syslog(LOG_ERR, "bind failed; error:%d", error); + close(fd); + exit(-1); + } + sock_opt = addr.nl_groups; + setsockopt(fd, 270, 1, &sock_opt, sizeof(sock_opt)); + /* + * Register ourselves with the kernel. + */ + message = (struct cn_msg *)kvp_send_buffer; + message->id.idx = CN_KVP_IDX; + message->id.val = CN_KVP_VAL; + message->seq = KVP_REGISTER; + message->ack = 0; + message->len = 0; + + len = netlink_send(fd, message); + if (len < 0) { + syslog(LOG_ERR, "netlink_send failed; error:%d", len); + close(fd); + exit(-1); + } + + pfd.fd = fd; + + while (1) { + pfd.events = POLLIN; + pfd.revents = 0; + poll(&pfd, 1, -1); + + len = recv(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0); + + if (len < 0) { + syslog(LOG_ERR, "recv failed; error:%d", len); + close(fd); + return -1; + } + + incoming_msg = (struct nlmsghdr *)kvp_recv_buffer; + incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg); + + switch (incoming_cn_msg->seq) { + case KVP_REGISTER: + /* + * Driver is registering with us; stash away the version + * information. + */ + lic_version = malloc(strlen(incoming_cn_msg->data) + 1); + if (lic_version) { + strcpy(lic_version, incoming_cn_msg->data); + syslog(LOG_INFO, "KVP LIC Version: %s", + lic_version); + } else { + syslog(LOG_ERR, "malloc failed"); + } + continue; + + case KVP_KERNEL_GET: + break; + default: + continue; + } + + key_index = + ((struct hv_ku_msg *)incoming_cn_msg->data)->kvp_index; + key_name = + ((struct hv_ku_msg *)incoming_cn_msg->data)->kvp_key; + key_value = + ((struct hv_ku_msg *)incoming_cn_msg->data)->kvp_value; + + switch (key_index) { + case FullyQualifiedDomainName: + kvp_get_domain_name(key_value, + HV_KVP_EXCHANGE_MAX_VALUE_SIZE); + strcpy(key_name, "FullyQualifiedDomainName"); + break; + case IntegrationServicesVersion: + strcpy(key_name, "IntegrationServicesVersion"); + strcpy(key_value, lic_version); + break; + case NetworkAddressIPv4: + kvp_get_ip_address(AF_INET, key_value, + HV_KVP_EXCHANGE_MAX_VALUE_SIZE); + strcpy(key_name, "NetworkAddressIPv4"); + break; + case NetworkAddressIPv6: + kvp_get_ip_address(AF_INET6, key_value, + HV_KVP_EXCHANGE_MAX_VALUE_SIZE); + strcpy(key_name, "NetworkAddressIPv6"); + break; + case OSBuildNumber: + strcpy(key_value, os_build); + strcpy(key_name, "OSBuildNumber"); + break; + case OSName: + strcpy(key_value, os_name); + strcpy(key_name, "OSName"); + break; + case OSMajorVersion: + strcpy(key_value, os_major); + strcpy(key_name, "OSMajorVersion"); + break; + case OSMinorVersion: + strcpy(key_value, os_minor); + strcpy(key_name, "OSMinorVersion"); + break; + case OSVersion: + strcpy(key_value, os_build); + strcpy(key_name, "OSVersion"); + break; + case ProcessorArchitecture: + strcpy(key_value, processor_arch); + strcpy(key_name, "ProcessorArchitecture"); + break; + default: + strcpy(key_value, "Unknown Key"); + /* + * We use a null key name to terminate enumeration. + */ + strcpy(key_name, ""); + break; + } + /* + * Send the value back to the kernel. The response is + * already in the receive buffer. Update the cn_msg header to + * reflect the key value that has been added to the message + */ + + incoming_cn_msg->id.idx = CN_KVP_IDX; + incoming_cn_msg->id.val = CN_KVP_VAL; + incoming_cn_msg->seq = KVP_USER_SET; + incoming_cn_msg->ack = 0; + incoming_cn_msg->len = sizeof(struct hv_ku_msg); + + len = netlink_send(fd, incoming_cn_msg); + if (len < 0) { + syslog(LOG_ERR, "net_link send failed; error:%d", len); + exit(-1); + } + } + +} diff --git a/drivers/staging/hv/utils.h b/drivers/staging/hv/utils.h index 7c0749999a6f..acebbbf888b0 100644 --- a/drivers/staging/hv/utils.h +++ b/drivers/staging/hv/utils.h @@ -43,12 +43,12 @@ struct vmbuspipe_hdr { u32 flags; u32 msgsize; -} __attribute__((packed)); +} __packed; struct ic_version { u16 major; u16 minor; -} __attribute__((packed)); +} __packed; struct icmsg_hdr { struct ic_version icverframe; @@ -59,26 +59,26 @@ struct icmsg_hdr { u8 ictransaction_id; u8 icflags; u8 reserved[2]; -} __attribute__((packed)); +} __packed; struct icmsg_negotiate { u16 icframe_vercnt; u16 icmsg_vercnt; u32 reserved; struct ic_version icversion_data[1]; /* any size array */ -} __attribute__((packed)); +} __packed; struct shutdown_msg_data { u32 reason_code; u32 timeout_seconds; u32 flags; u8 display_message[2048]; -} __attribute__((packed)); +} __packed; struct heartbeat_msg_data { u64 seq_num; u32 reserved[8]; -} __attribute__((packed)); +} __packed; /* Time Sync IC defs */ #define ICTIMESYNCFLAG_PROBE 0 @@ -96,12 +96,13 @@ struct ictimesync_data{ u64 childtime; u64 roundtriptime; u8 flags; -} __attribute__((packed)); +} __packed; /* Index for each IC struct in array hv_cb_utils[] */ #define HV_SHUTDOWN_MSG 0 #define HV_TIMESYNC_MSG 1 #define HV_HEARTBEAT_MSG 2 +#define HV_KVP_MSG 3 struct hyperv_service_callback { u8 msg_type; diff --git a/drivers/staging/hv/vmbus.h b/drivers/staging/hv/vmbus.h index 42f2adb99547..73087f26bec2 100644 --- a/drivers/staging/hv/vmbus.h +++ b/drivers/staging/hv/vmbus.h @@ -28,49 +28,23 @@ #include <linux/device.h> #include "vmbus_api.h" -struct driver_context { - struct hv_guid class_id; - struct device_driver driver; - /* - * Use these methods instead of the struct device_driver so 2.6 kernel - * stops complaining - * TODO - fix this! - */ - int (*probe)(struct device *); - int (*remove)(struct device *); - void (*shutdown)(struct device *); -}; -struct vm_device { - struct work_struct probe_failed_work_item; - struct hv_guid class_id; - struct hv_guid device_id; - int probe_error; - struct hv_device device_obj; - struct device device; -}; - -static inline struct vm_device *to_vm_device(struct hv_device *d) -{ - return container_of(d, struct vm_device, device_obj); -} - -static inline struct vm_device *device_to_vm_device(struct device *d) +static inline struct hv_device *device_to_hv_device(struct device *d) { - return container_of(d, struct vm_device, device); + return container_of(d, struct hv_device, device); } -static inline struct driver_context *driver_to_driver_context(struct device_driver *d) +static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d) { - return container_of(d, struct driver_context, driver); + return container_of(d, struct hv_driver, driver); } /* Vmbus interface */ -int vmbus_child_driver_register(struct driver_context *driver_ctx); -void vmbus_child_driver_unregister(struct driver_context *driver_ctx); +int vmbus_child_driver_register(struct device_driver *drv); +void vmbus_child_driver_unregister(struct device_driver *drv); extern struct completion hv_channel_ready; diff --git a/drivers/staging/hv/vmbus_api.h b/drivers/staging/hv/vmbus_api.h index 2da3f52610b3..f0d96eba7013 100644 --- a/drivers/staging/hv/vmbus_api.h +++ b/drivers/staging/hv/vmbus_api.h @@ -25,6 +25,9 @@ #ifndef _VMBUS_API_H_ #define _VMBUS_API_H_ +#include <linux/device.h> +#include <linux/workqueue.h> + #define MAX_PAGE_BUFFER_COUNT 16 #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */ @@ -32,17 +35,17 @@ /* Single-page buffer */ struct hv_page_buffer { - u32 Length; - u32 Offset; - u64 Pfn; + u32 len; + u32 offset; + u64 pfn; }; /* Multiple-page buffer */ struct hv_multipage_buffer { /* Length and Offset determines the # of pfns in the array */ - u32 Length; - u32 Offset; - u64 PfnArray[MAX_MULTIPAGE_BUFFER_COUNT]; + u32 len; + u32 offset; + u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT]; }; /* 0x18 includes the proprietary packet header */ @@ -59,29 +62,29 @@ struct hv_driver; struct hv_device; struct hv_dev_port_info { - u32 InterruptMask; - u32 ReadIndex; - u32 WriteIndex; - u32 BytesAvailToRead; - u32 BytesAvailToWrite; + u32 int_mask; + u32 read_idx; + u32 write_idx; + u32 bytes_avail_toread; + u32 bytes_avail_towrite; }; struct hv_device_info { - u32 ChannelId; - u32 ChannelState; - struct hv_guid ChannelType; - struct hv_guid ChannelInstance; - - u32 MonitorId; - u32 ServerMonitorPending; - u32 ServerMonitorLatency; - u32 ServerMonitorConnectionId; - u32 ClientMonitorPending; - u32 ClientMonitorLatency; - u32 ClientMonitorConnectionId; - - struct hv_dev_port_info Inbound; - struct hv_dev_port_info Outbound; + u32 chn_id; + u32 chn_state; + struct hv_guid chn_type; + struct hv_guid chn_instance; + + u32 monitor_id; + u32 server_monitor_pending; + u32 server_monitor_latency; + u32 server_monitor_conn_id; + u32 client_monitor_pending; + u32 client_monitor_latency; + u32 client_monitor_conn_id; + + struct hv_dev_port_info inbound; + struct hv_dev_port_info outbound; }; /* Base driver object */ @@ -89,30 +92,48 @@ struct hv_driver { const char *name; /* the device type supported by this driver */ - struct hv_guid deviceType; - - int (*OnDeviceAdd)(struct hv_device *device, void *data); - int (*OnDeviceRemove)(struct hv_device *device); - void (*OnCleanup)(struct hv_driver *driver); + struct hv_guid dev_type; + + /* + * Device type specific drivers (net, blk etc.) + * need a mechanism to get a pointer to + * device type specific driver structure given + * a pointer to the base hyperv driver structure. + * The current code solves this problem using + * a hack. Support this need explicitly + */ + void *priv; + + struct device_driver driver; + + int (*dev_add)(struct hv_device *device, void *data); + int (*dev_rm)(struct hv_device *device); + void (*cleanup)(struct hv_driver *driver); }; /* Base device object */ struct hv_device { /* the driver for this device */ - struct hv_driver *Driver; + struct hv_driver *drv; char name[64]; + struct work_struct probe_failed_work_item; + + int probe_error; + /* the device type id of this device */ - struct hv_guid deviceType; + struct hv_guid dev_type; /* the device instance id of this device */ - struct hv_guid deviceInstance; + struct hv_guid dev_instance; + + struct device device; struct vmbus_channel *channel; /* Device extension; */ - void *Extension; + void *ext; }; #endif /* _VMBUS_API_H_ */ diff --git a/drivers/staging/hv/vmbus_channel_interface.h b/drivers/staging/hv/vmbus_channel_interface.h index 26742823748d..20ae258e5f9c 100644 --- a/drivers/staging/hv/vmbus_channel_interface.h +++ b/drivers/staging/hv/vmbus_channel_interface.h @@ -48,19 +48,19 @@ * struct contains the fundamental information about an offer. */ struct vmbus_channel_offer { - struct hv_guid InterfaceType; - struct hv_guid InterfaceInstance; - u64 InterruptLatencyIn100nsUnits; - u32 InterfaceRevision; - u32 ServerContextAreaSize; /* in bytes */ - u16 ChannelFlags; - u16 MmioMegabytes; /* in bytes * 1024 * 1024 */ + struct hv_guid if_type; + struct hv_guid if_instance; + u64 int_latency; /* in 100ns units */ + u32 if_revision; + u32 server_ctx_size; /* in bytes */ + u16 chn_flags; + u16 mmio_megabytes; /* in bytes * 1024 * 1024 */ union { /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */ struct { - unsigned char UserDefined[MAX_USER_DEFINED_BYTES]; - } Standard; + unsigned char user_def[MAX_USER_DEFINED_BYTES]; + } std; /* * Pipes: @@ -70,12 +70,12 @@ struct vmbus_channel_offer { * use. */ struct { - u32 PipeMode; - unsigned char UserDefined[MAX_PIPE_USER_DEFINED_BYTES]; - } Pipe; + u32 pipe_mode; + unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES]; + } pipe; } u; - u32 Padding; -} __attribute__((packed)); + u32 padding; +} __packed; /* Server Flags */ #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1 diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c index 84fdb64d3ceb..b473f468dd83 100644 --- a/drivers/staging/hv/vmbus_drv.c +++ b/drivers/staging/hv/vmbus_drv.c @@ -29,7 +29,7 @@ #include <linux/slab.h> #include <linux/completion.h> #include "version_info.h" -#include "osd.h" +#include "hv_api.h" #include "logging.h" #include "vmbus.h" #include "channel.h" @@ -42,19 +42,13 @@ /* Main vmbus driver data structure */ struct vmbus_driver_context { - /* !! These must be the first 2 fields !! */ - /* FIXME, this is a bug */ - /* The driver field is not used in here. Instead, the bus field is */ - /* used to represent the driver */ - struct driver_context drv_ctx; - struct hv_driver drv_obj; struct bus_type bus; struct tasklet_struct msg_dpc; struct tasklet_struct event_dpc; /* The bus root device */ - struct vm_device device_ctx; + struct hv_device device_ctx; }; static int vmbus_match(struct device *device, struct device_driver *driver); @@ -62,8 +56,6 @@ static int vmbus_probe(struct device *device); static int vmbus_remove(struct device *device); static void vmbus_shutdown(struct device *device); static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env); -static void vmbus_msg_dpc(unsigned long data); -static void vmbus_event_dpc(unsigned long data); static irqreturn_t vmbus_isr(int irq, void *dev_id); @@ -113,7 +105,7 @@ static struct device_attribute vmbus_device_attrs[] = { }; /* The one and only one */ -static struct vmbus_driver_context g_vmbus_drv = { +static struct vmbus_driver_context vmbus_drv = { .bus.name = "vmbus", .bus.match = vmbus_match, .bus.shutdown = vmbus_shutdown, @@ -123,14 +115,14 @@ static struct vmbus_driver_context g_vmbus_drv = { .bus.dev_attrs = vmbus_device_attrs, }; -static const char *gDriverName = "hyperv"; +static const char *driver_name = "hyperv"; /* * Windows vmbus does not defined this. * We defined this to be consistent with other devices */ /* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */ -static const struct hv_guid gVmbusDeviceType = { +static const struct hv_guid device_type = { .data = { 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d, 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85 @@ -138,35 +130,28 @@ static const struct hv_guid gVmbusDeviceType = { }; /* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */ -static const struct hv_guid gVmbusDeviceId = { +static const struct hv_guid device_id = { .data = { 0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40, 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5 } }; -static struct hv_device *gDevice; /* vmbus root device */ +static struct hv_device *vmbus_device; /* vmbus root device */ -/* - * VmbusChildDeviceAdd - Registers the child device with the vmbus - */ -int VmbusChildDeviceAdd(struct hv_device *ChildDevice) -{ - return vmbus_child_device_register(gDevice, ChildDevice); -} /* - * VmbusOnDeviceAdd - Callback when the root bus device is added + * vmbus_dev_add - Callback when the root bus device is added */ -static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo) +static int vmbus_dev_add(struct hv_device *dev, void *info) { - u32 *irqvector = AdditionalInfo; + u32 *irqvector = info; int ret; - gDevice = dev; + vmbus_device = dev; - memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid)); - memcpy(&gDevice->deviceInstance, &gVmbusDeviceId, + memcpy(&vmbus_device->dev_type, &device_type, sizeof(struct hv_guid)); + memcpy(&vmbus_device->dev_instance, &device_id, sizeof(struct hv_guid)); /* strcpy(dev->name, "vmbus"); */ @@ -174,34 +159,12 @@ static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo) on_each_cpu(hv_synic_init, (void *)irqvector, 1); /* Connect to VMBus in the root partition */ - ret = VmbusConnect(); + ret = vmbus_connect(); /* VmbusSendEvent(device->localPortId+1); */ return ret; } -/* - * VmbusOnDeviceRemove - Callback when the root bus device is removed - */ -static int VmbusOnDeviceRemove(struct hv_device *dev) -{ - int ret = 0; - - vmbus_release_unattached_channels(); - VmbusDisconnect(); - on_each_cpu(hv_synic_cleanup, NULL, 1); - return ret; -} - -/* - * VmbusOnCleanup - Perform any cleanup when the driver is removed - */ -static void VmbusOnCleanup(struct hv_driver *drv) -{ - /* struct vmbus_driver *driver = (struct vmbus_driver *)drv; */ - - hv_cleanup(); -} struct onmessage_work_context { struct work_struct work; @@ -221,7 +184,7 @@ static void vmbus_onmessage_work(struct work_struct *work) /* * vmbus_on_msg_dpc - DPC routine to handle messages from the hypervisior */ -static void vmbus_on_msg_dpc(struct hv_driver *drv) +static void vmbus_on_msg_dpc(unsigned long data) { int cpu = smp_processor_id(); void *page_addr = hv_context.synic_message_page[cpu]; @@ -239,7 +202,7 @@ static void vmbus_on_msg_dpc(struct hv_driver *drv) continue; INIT_WORK(&ctx->work, vmbus_onmessage_work); memcpy(&ctx->msg, msg, sizeof(*msg)); - queue_work(gVmbusConnection.WorkQueue, &ctx->work); + queue_work(vmbus_connection.work_queue, &ctx->work); } msg->header.message_type = HVMSG_NONE; @@ -267,7 +230,7 @@ static void vmbus_on_msg_dpc(struct hv_driver *drv) /* * vmbus_on_isr - ISR routine */ -static int vmbus_on_isr(struct hv_driver *drv) +static int vmbus_on_isr(void) { int ret = 0; int cpu = smp_processor_id(); @@ -309,37 +272,38 @@ static void get_channel_info(struct hv_device *device, vmbus_get_debug_info(device->channel, &debug_info); - info->ChannelId = debug_info.relid; - info->ChannelState = debug_info.state; - memcpy(&info->ChannelType, &debug_info.interfacetype, + info->chn_id = debug_info.relid; + info->chn_state = debug_info.state; + memcpy(&info->chn_type, &debug_info.interfacetype, sizeof(struct hv_guid)); - memcpy(&info->ChannelInstance, &debug_info.interface_instance, + memcpy(&info->chn_instance, &debug_info.interface_instance, sizeof(struct hv_guid)); - info->MonitorId = debug_info.monitorid; + info->monitor_id = debug_info.monitorid; - info->ServerMonitorPending = debug_info.servermonitor_pending; - info->ServerMonitorLatency = debug_info.servermonitor_latency; - info->ServerMonitorConnectionId = debug_info.servermonitor_connectionid; + info->server_monitor_pending = debug_info.servermonitor_pending; + info->server_monitor_latency = debug_info.servermonitor_latency; + info->server_monitor_conn_id = debug_info.servermonitor_connectionid; - info->ClientMonitorPending = debug_info.clientmonitor_pending; - info->ClientMonitorLatency = debug_info.clientmonitor_latency; - info->ClientMonitorConnectionId = debug_info.clientmonitor_connectionid; + info->client_monitor_pending = debug_info.clientmonitor_pending; + info->client_monitor_latency = debug_info.clientmonitor_latency; + info->client_monitor_conn_id = debug_info.clientmonitor_connectionid; - info->Inbound.InterruptMask = debug_info.inbound.current_interrupt_mask; - info->Inbound.ReadIndex = debug_info.inbound.current_read_index; - info->Inbound.WriteIndex = debug_info.inbound.current_write_index; - info->Inbound.BytesAvailToRead = debug_info.inbound.bytes_avail_toread; - info->Inbound.BytesAvailToWrite = + info->inbound.int_mask = debug_info.inbound.current_interrupt_mask; + info->inbound.read_idx = debug_info.inbound.current_read_index; + info->inbound.write_idx = debug_info.inbound.current_write_index; + info->inbound.bytes_avail_toread = + debug_info.inbound.bytes_avail_toread; + info->inbound.bytes_avail_towrite = debug_info.inbound.bytes_avail_towrite; - info->Outbound.InterruptMask = + info->outbound.int_mask = debug_info.outbound.current_interrupt_mask; - info->Outbound.ReadIndex = debug_info.outbound.current_read_index; - info->Outbound.WriteIndex = debug_info.outbound.current_write_index; - info->Outbound.BytesAvailToRead = + info->outbound.read_idx = debug_info.outbound.current_read_index; + info->outbound.write_idx = debug_info.outbound.current_write_index; + info->outbound.bytes_avail_toread = debug_info.outbound.bytes_avail_toread; - info->Outbound.BytesAvailToWrite = + info->outbound.bytes_avail_towrite = debug_info.outbound.bytes_avail_towrite; } @@ -353,95 +317,95 @@ static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf) { - struct vm_device *device_ctx = device_to_vm_device(dev); + struct hv_device *device_ctx = device_to_hv_device(dev); struct hv_device_info device_info; memset(&device_info, 0, sizeof(struct hv_device_info)); - get_channel_info(&device_ctx->device_obj, &device_info); + get_channel_info(device_ctx, &device_info); if (!strcmp(dev_attr->attr.name, "class_id")) { return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x%02x%02x}\n", - device_info.ChannelType.data[3], - device_info.ChannelType.data[2], - device_info.ChannelType.data[1], - device_info.ChannelType.data[0], - device_info.ChannelType.data[5], - device_info.ChannelType.data[4], - device_info.ChannelType.data[7], - device_info.ChannelType.data[6], - device_info.ChannelType.data[8], - device_info.ChannelType.data[9], - device_info.ChannelType.data[10], - device_info.ChannelType.data[11], - device_info.ChannelType.data[12], - device_info.ChannelType.data[13], - device_info.ChannelType.data[14], - device_info.ChannelType.data[15]); + device_info.chn_type.data[3], + device_info.chn_type.data[2], + device_info.chn_type.data[1], + device_info.chn_type.data[0], + device_info.chn_type.data[5], + device_info.chn_type.data[4], + device_info.chn_type.data[7], + device_info.chn_type.data[6], + device_info.chn_type.data[8], + device_info.chn_type.data[9], + device_info.chn_type.data[10], + device_info.chn_type.data[11], + device_info.chn_type.data[12], + device_info.chn_type.data[13], + device_info.chn_type.data[14], + device_info.chn_type.data[15]); } else if (!strcmp(dev_attr->attr.name, "device_id")) { return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x%02x%02x}\n", - device_info.ChannelInstance.data[3], - device_info.ChannelInstance.data[2], - device_info.ChannelInstance.data[1], - device_info.ChannelInstance.data[0], - device_info.ChannelInstance.data[5], - device_info.ChannelInstance.data[4], - device_info.ChannelInstance.data[7], - device_info.ChannelInstance.data[6], - device_info.ChannelInstance.data[8], - device_info.ChannelInstance.data[9], - device_info.ChannelInstance.data[10], - device_info.ChannelInstance.data[11], - device_info.ChannelInstance.data[12], - device_info.ChannelInstance.data[13], - device_info.ChannelInstance.data[14], - device_info.ChannelInstance.data[15]); + device_info.chn_instance.data[3], + device_info.chn_instance.data[2], + device_info.chn_instance.data[1], + device_info.chn_instance.data[0], + device_info.chn_instance.data[5], + device_info.chn_instance.data[4], + device_info.chn_instance.data[7], + device_info.chn_instance.data[6], + device_info.chn_instance.data[8], + device_info.chn_instance.data[9], + device_info.chn_instance.data[10], + device_info.chn_instance.data[11], + device_info.chn_instance.data[12], + device_info.chn_instance.data[13], + device_info.chn_instance.data[14], + device_info.chn_instance.data[15]); } else if (!strcmp(dev_attr->attr.name, "state")) { - return sprintf(buf, "%d\n", device_info.ChannelState); + return sprintf(buf, "%d\n", device_info.chn_state); } else if (!strcmp(dev_attr->attr.name, "id")) { - return sprintf(buf, "%d\n", device_info.ChannelId); + return sprintf(buf, "%d\n", device_info.chn_id); } else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) { - return sprintf(buf, "%d\n", device_info.Outbound.InterruptMask); + return sprintf(buf, "%d\n", device_info.outbound.int_mask); } else if (!strcmp(dev_attr->attr.name, "out_read_index")) { - return sprintf(buf, "%d\n", device_info.Outbound.ReadIndex); + return sprintf(buf, "%d\n", device_info.outbound.read_idx); } else if (!strcmp(dev_attr->attr.name, "out_write_index")) { - return sprintf(buf, "%d\n", device_info.Outbound.WriteIndex); + return sprintf(buf, "%d\n", device_info.outbound.write_idx); } else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) { return sprintf(buf, "%d\n", - device_info.Outbound.BytesAvailToRead); + device_info.outbound.bytes_avail_toread); } else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) { return sprintf(buf, "%d\n", - device_info.Outbound.BytesAvailToWrite); + device_info.outbound.bytes_avail_towrite); } else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) { - return sprintf(buf, "%d\n", device_info.Inbound.InterruptMask); + return sprintf(buf, "%d\n", device_info.inbound.int_mask); } else if (!strcmp(dev_attr->attr.name, "in_read_index")) { - return sprintf(buf, "%d\n", device_info.Inbound.ReadIndex); + return sprintf(buf, "%d\n", device_info.inbound.read_idx); } else if (!strcmp(dev_attr->attr.name, "in_write_index")) { - return sprintf(buf, "%d\n", device_info.Inbound.WriteIndex); + return sprintf(buf, "%d\n", device_info.inbound.write_idx); } else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) { return sprintf(buf, "%d\n", - device_info.Inbound.BytesAvailToRead); + device_info.inbound.bytes_avail_toread); } else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) { return sprintf(buf, "%d\n", - device_info.Inbound.BytesAvailToWrite); + device_info.inbound.bytes_avail_towrite); } else if (!strcmp(dev_attr->attr.name, "monitor_id")) { - return sprintf(buf, "%d\n", device_info.MonitorId); + return sprintf(buf, "%d\n", device_info.monitor_id); } else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) { - return sprintf(buf, "%d\n", device_info.ServerMonitorPending); + return sprintf(buf, "%d\n", device_info.server_monitor_pending); } else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) { - return sprintf(buf, "%d\n", device_info.ServerMonitorLatency); + return sprintf(buf, "%d\n", device_info.server_monitor_latency); } else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) { return sprintf(buf, "%d\n", - device_info.ServerMonitorConnectionId); + device_info.server_monitor_conn_id); } else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) { - return sprintf(buf, "%d\n", device_info.ClientMonitorPending); + return sprintf(buf, "%d\n", device_info.client_monitor_pending); } else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) { - return sprintf(buf, "%d\n", device_info.ClientMonitorLatency); + return sprintf(buf, "%d\n", device_info.client_monitor_latency); } else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) { return sprintf(buf, "%d\n", - device_info.ClientMonitorConnectionId); + device_info.client_monitor_conn_id); } else { return 0; } @@ -461,9 +425,8 @@ static ssize_t vmbus_show_device_attr(struct device *dev, */ static int vmbus_bus_init(void) { - struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; - struct hv_driver *driver = &g_vmbus_drv.drv_obj; - struct vm_device *dev_ctx = &g_vmbus_drv.device_ctx; + struct vmbus_driver_context *vmbus_drv_ctx = &vmbus_drv; + struct hv_device *dev_ctx = &vmbus_drv.device_ctx; int ret; unsigned int vector; @@ -478,13 +441,6 @@ static int vmbus_bus_init(void) sizeof(struct vmbus_channel_packet_page_buffer), sizeof(struct vmbus_channel_packet_multipage_buffer)); - driver->name = gDriverName; - memcpy(&driver->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid)); - - /* Setup dispatch table */ - driver->OnDeviceAdd = VmbusOnDeviceAdd; - driver->OnDeviceRemove = VmbusOnDeviceRemove; - driver->OnCleanup = VmbusOnCleanup; /* Hypervisor initialization...setup hypercall page..etc */ ret = hv_init(); @@ -494,22 +450,16 @@ static int vmbus_bus_init(void) goto cleanup; } - /* Sanity checks */ - if (!driver->OnDeviceAdd) { - DPRINT_ERR(VMBUS_DRV, "OnDeviceAdd() routine not set"); - ret = -1; - goto cleanup; - } - vmbus_drv_ctx->bus.name = driver->name; + vmbus_drv_ctx->bus.name = driver_name; /* Initialize the bus context */ - tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc, - (unsigned long)driver); - tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc, - (unsigned long)driver); + tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_on_msg_dpc, + (unsigned long)NULL); + tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_on_event, + (unsigned long)NULL); - /* Now, register the bus driver with LDM */ + /* Now, register the bus with LDM */ ret = bus_register(&vmbus_drv_ctx->bus); if (ret) { ret = -1; @@ -518,7 +468,7 @@ static int vmbus_bus_init(void) /* Get the interrupt resource */ ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM, - driver->name, NULL); + driver_name, NULL); if (ret != 0) { DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", @@ -533,10 +483,10 @@ static int vmbus_bus_init(void) DPRINT_INFO(VMBUS_DRV, "irq 0x%x vector 0x%x", vmbus_irq, vector); - /* Call to bus driver to add the root device */ - memset(dev_ctx, 0, sizeof(struct vm_device)); + /* Add the root device */ + memset(dev_ctx, 0, sizeof(struct hv_device)); - ret = driver->OnDeviceAdd(&dev_ctx->device_obj, &vector); + ret = vmbus_dev_add(dev_ctx, &vector); if (ret != 0) { DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to add vmbus root device"); @@ -550,10 +500,6 @@ static int vmbus_bus_init(void) } /* strcpy(dev_ctx->device.bus_id, dev_ctx->device_obj.name); */ dev_set_name(&dev_ctx->device, "vmbus_0_0"); - memcpy(&dev_ctx->class_id, &dev_ctx->device_obj.deviceType, - sizeof(struct hv_guid)); - memcpy(&dev_ctx->device_id, &dev_ctx->device_obj.deviceInstance, - sizeof(struct hv_guid)); /* No need to bind a driver to the root device. */ dev_ctx->device.parent = NULL; @@ -563,7 +509,7 @@ static int vmbus_bus_init(void) /* Setup the device dispatch table */ dev_ctx->device.release = vmbus_bus_release; - /* Setup the bus as root device */ + /* register the root device */ ret = device_register(&dev_ctx->device); if (ret) { DPRINT_ERR(VMBUS_DRV, @@ -590,17 +536,15 @@ cleanup: */ static void vmbus_bus_exit(void) { - struct hv_driver *driver = &g_vmbus_drv.drv_obj; - struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; + struct vmbus_driver_context *vmbus_drv_ctx = &vmbus_drv; - struct vm_device *dev_ctx = &g_vmbus_drv.device_ctx; + struct hv_device *dev_ctx = &vmbus_drv.device_ctx; - /* Remove the root device */ - if (driver->OnDeviceRemove) - driver->OnDeviceRemove(&dev_ctx->device_obj); + vmbus_release_unattached_channels(); + vmbus_disconnect(); + on_each_cpu(hv_synic_cleanup, NULL, 1); - if (driver->OnCleanup) - driver->OnCleanup(driver); + hv_cleanup(); /* Unregister the root bus device */ device_unregister(&dev_ctx->device); @@ -616,9 +560,8 @@ static void vmbus_bus_exit(void) /** * vmbus_child_driver_register() - Register a vmbus's child driver - * @driver_ctx: Pointer to driver structure you want to register + * @drv: Pointer to driver structure you want to register * - * @driver_ctx is of type &struct driver_context * * Registers the given driver with Linux through the 'driver_register()' call * And sets up the hyper-v vmbus handling for this driver. @@ -626,17 +569,17 @@ static void vmbus_bus_exit(void) * * Mainly used by Hyper-V drivers. */ -int vmbus_child_driver_register(struct driver_context *driver_ctx) +int vmbus_child_driver_register(struct device_driver *drv) { int ret; DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", - driver_ctx, driver_ctx->driver.name); + drv, drv->name); /* The child driver on this vmbus */ - driver_ctx->driver.bus = &g_vmbus_drv.bus; + drv->bus = &vmbus_drv.bus; - ret = driver_register(&driver_ctx->driver); + ret = driver_register(drv); vmbus_request_offers(); @@ -646,23 +589,22 @@ EXPORT_SYMBOL(vmbus_child_driver_register); /** * vmbus_child_driver_unregister() - Unregister a vmbus's child driver - * @driver_ctx: Pointer to driver structure you want to un-register + * @drv: Pointer to driver structure you want to un-register * - * @driver_ctx is of type &struct driver_context * * Un-register the given driver with Linux through the 'driver_unregister()' * call. And ungegisters the driver from the Hyper-V vmbus handler. * * Mainly used by Hyper-V drivers. */ -void vmbus_child_driver_unregister(struct driver_context *driver_ctx) +void vmbus_child_driver_unregister(struct device_driver *drv) { DPRINT_INFO(VMBUS_DRV, "child driver (%p) unregistering - name %s", - driver_ctx, driver_ctx->driver.name); + drv, drv->name); - driver_unregister(&driver_ctx->driver); + driver_unregister(drv); - driver_ctx->driver.bus = NULL; + drv->bus = NULL; } EXPORT_SYMBOL(vmbus_child_driver_unregister); @@ -674,12 +616,11 @@ struct hv_device *vmbus_child_device_create(struct hv_guid *type, struct hv_guid *instance, struct vmbus_channel *channel) { - struct vm_device *child_device_ctx; struct hv_device *child_device_obj; /* Allocate the new child device */ - child_device_ctx = kzalloc(sizeof(struct vm_device), GFP_KERNEL); - if (!child_device_ctx) { + child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL); + if (!child_device_obj) { DPRINT_ERR(VMBUS_DRV, "unable to allocate device_context for child device"); return NULL; @@ -690,7 +631,7 @@ struct hv_device *vmbus_child_device_create(struct hv_guid *type, "%02x%02x%02x%02x%02x%02x%02x%02x}," "id {%02x%02x%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x%02x%02x}", - &child_device_ctx->device, + &child_device_obj->device, type->data[3], type->data[2], type->data[1], type->data[0], type->data[5], type->data[4], type->data[7], type->data[6], type->data[8], type->data[9], type->data[10], type->data[11], @@ -704,58 +645,51 @@ struct hv_device *vmbus_child_device_create(struct hv_guid *type, instance->data[12], instance->data[13], instance->data[14], instance->data[15]); - child_device_obj = &child_device_ctx->device_obj; child_device_obj->channel = channel; - memcpy(&child_device_obj->deviceType, type, sizeof(struct hv_guid)); - memcpy(&child_device_obj->deviceInstance, instance, + memcpy(&child_device_obj->dev_type, type, sizeof(struct hv_guid)); + memcpy(&child_device_obj->dev_instance, instance, sizeof(struct hv_guid)); - memcpy(&child_device_ctx->class_id, type, sizeof(struct hv_guid)); - memcpy(&child_device_ctx->device_id, instance, sizeof(struct hv_guid)); return child_device_obj; } /* - * vmbus_child_device_register - Register the child device on the specified bus + * vmbus_child_device_register - Register the child device */ -int vmbus_child_device_register(struct hv_device *root_device_obj, - struct hv_device *child_device_obj) +int vmbus_child_device_register(struct hv_device *child_device_obj) { int ret = 0; - struct vm_device *root_device_ctx = - to_vm_device(root_device_obj); - struct vm_device *child_device_ctx = - to_vm_device(child_device_obj); + static atomic_t device_num = ATOMIC_INIT(0); DPRINT_DBG(VMBUS_DRV, "child device (%p) registering", - child_device_ctx); + child_device_obj); /* Set the device name. Otherwise, device_register() will fail. */ - dev_set_name(&child_device_ctx->device, "vmbus_0_%d", + dev_set_name(&child_device_obj->device, "vmbus_0_%d", atomic_inc_return(&device_num)); /* The new device belongs to this bus */ - child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */ - child_device_ctx->device.parent = &root_device_ctx->device; - child_device_ctx->device.release = vmbus_device_release; + child_device_obj->device.bus = &vmbus_drv.bus; /* device->dev.bus; */ + child_device_obj->device.parent = &vmbus_device->device; + child_device_obj->device.release = vmbus_device_release; /* * Register with the LDM. This will kick off the driver/device * binding...which will eventually call vmbus_match() and vmbus_probe() */ - ret = device_register(&child_device_ctx->device); + ret = device_register(&child_device_obj->device); /* vmbus_probe() error does not get propergate to device_register(). */ - ret = child_device_ctx->probe_error; + ret = child_device_obj->probe_error; if (ret) DPRINT_ERR(VMBUS_DRV, "unable to register child device (%p)", - &child_device_ctx->device); + &child_device_obj->device); else DPRINT_INFO(VMBUS_DRV, "child device (%p) registered", - &child_device_ctx->device); + &child_device_obj->device); return ret; } @@ -766,19 +700,18 @@ int vmbus_child_device_register(struct hv_device *root_device_obj, */ void vmbus_child_device_unregister(struct hv_device *device_obj) { - struct vm_device *device_ctx = to_vm_device(device_obj); DPRINT_INFO(VMBUS_DRV, "unregistering child device (%p)", - &device_ctx->device); + &device_obj->device); /* * Kick off the process of unregistering the device. * This will call vmbus_remove() and eventually vmbus_device_release() */ - device_unregister(&device_ctx->device); + device_unregister(&device_obj->device); DPRINT_INFO(VMBUS_DRV, "child device (%p) unregistered", - &device_ctx->device); + &device_obj->device); } /* @@ -790,43 +723,43 @@ void vmbus_child_device_unregister(struct hv_device *device_obj) */ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) { - struct vm_device *device_ctx = device_to_vm_device(device); + struct hv_device *dev = device_to_hv_device(device); int ret; DPRINT_INFO(VMBUS_DRV, "generating uevent - VMBUS_DEVICE_CLASS_GUID={" "%02x%02x%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x%02x%02x}", - device_ctx->class_id.data[3], device_ctx->class_id.data[2], - device_ctx->class_id.data[1], device_ctx->class_id.data[0], - device_ctx->class_id.data[5], device_ctx->class_id.data[4], - device_ctx->class_id.data[7], device_ctx->class_id.data[6], - device_ctx->class_id.data[8], device_ctx->class_id.data[9], - device_ctx->class_id.data[10], - device_ctx->class_id.data[11], - device_ctx->class_id.data[12], - device_ctx->class_id.data[13], - device_ctx->class_id.data[14], - device_ctx->class_id.data[15]); + dev->dev_type.data[3], dev->dev_type.data[2], + dev->dev_type.data[1], dev->dev_type.data[0], + dev->dev_type.data[5], dev->dev_type.data[4], + dev->dev_type.data[7], dev->dev_type.data[6], + dev->dev_type.data[8], dev->dev_type.data[9], + dev->dev_type.data[10], + dev->dev_type.data[11], + dev->dev_type.data[12], + dev->dev_type.data[13], + dev->dev_type.data[14], + dev->dev_type.data[15]); ret = add_uevent_var(env, "VMBUS_DEVICE_CLASS_GUID={" "%02x%02x%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x%02x%02x}", - device_ctx->class_id.data[3], - device_ctx->class_id.data[2], - device_ctx->class_id.data[1], - device_ctx->class_id.data[0], - device_ctx->class_id.data[5], - device_ctx->class_id.data[4], - device_ctx->class_id.data[7], - device_ctx->class_id.data[6], - device_ctx->class_id.data[8], - device_ctx->class_id.data[9], - device_ctx->class_id.data[10], - device_ctx->class_id.data[11], - device_ctx->class_id.data[12], - device_ctx->class_id.data[13], - device_ctx->class_id.data[14], - device_ctx->class_id.data[15]); + dev->dev_type.data[3], + dev->dev_type.data[2], + dev->dev_type.data[1], + dev->dev_type.data[0], + dev->dev_type.data[5], + dev->dev_type.data[4], + dev->dev_type.data[7], + dev->dev_type.data[6], + dev->dev_type.data[8], + dev->dev_type.data[9], + dev->dev_type.data[10], + dev->dev_type.data[11], + dev->dev_type.data[12], + dev->dev_type.data[13], + dev->dev_type.data[14], + dev->dev_type.data[15]); if (ret) return ret; @@ -834,22 +767,22 @@ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) ret = add_uevent_var(env, "VMBUS_DEVICE_DEVICE_GUID={" "%02x%02x%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x%02x%02x}", - device_ctx->device_id.data[3], - device_ctx->device_id.data[2], - device_ctx->device_id.data[1], - device_ctx->device_id.data[0], - device_ctx->device_id.data[5], - device_ctx->device_id.data[4], - device_ctx->device_id.data[7], - device_ctx->device_id.data[6], - device_ctx->device_id.data[8], - device_ctx->device_id.data[9], - device_ctx->device_id.data[10], - device_ctx->device_id.data[11], - device_ctx->device_id.data[12], - device_ctx->device_id.data[13], - device_ctx->device_id.data[14], - device_ctx->device_id.data[15]); + dev->dev_instance.data[3], + dev->dev_instance.data[2], + dev->dev_instance.data[1], + dev->dev_instance.data[0], + dev->dev_instance.data[5], + dev->dev_instance.data[4], + dev->dev_instance.data[7], + dev->dev_instance.data[6], + dev->dev_instance.data[8], + dev->dev_instance.data[9], + dev->dev_instance.data[10], + dev->dev_instance.data[11], + dev->dev_instance.data[12], + dev->dev_instance.data[13], + dev->dev_instance.data[14], + dev->dev_instance.data[15]); if (ret) return ret; @@ -862,24 +795,18 @@ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) static int vmbus_match(struct device *device, struct device_driver *driver) { int match = 0; - struct driver_context *driver_ctx = driver_to_driver_context(driver); - struct vm_device *device_ctx = device_to_vm_device(device); + struct hv_driver *drv = drv_to_hv_drv(driver); + struct hv_device *device_ctx = device_to_hv_device(device); /* We found our driver ? */ - if (memcmp(&device_ctx->class_id, &driver_ctx->class_id, + if (memcmp(&device_ctx->dev_type, &drv->dev_type, sizeof(struct hv_guid)) == 0) { - /* - * !! NOTE: The driver_ctx is not a vmbus_drv_ctx. We typecast - * it here to access the struct hv_driver field - */ - struct vmbus_driver_context *vmbus_drv_ctx = - (struct vmbus_driver_context *)driver_ctx; - device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj; + device_ctx->drv = drv->priv; DPRINT_INFO(VMBUS_DRV, "device object (%p) set to driver object (%p)", - &device_ctx->device_obj, - device_ctx->device_obj.Driver); + &device_ctx, + device_ctx->drv); match = 1; } @@ -895,7 +822,7 @@ static int vmbus_match(struct device *device, struct device_driver *driver) */ static void vmbus_probe_failed_cb(struct work_struct *context) { - struct vm_device *device_ctx = (struct vm_device *)context; + struct hv_device *device_ctx = (struct hv_device *)context; /* * Kick off the process of unregistering the device. @@ -912,23 +839,23 @@ static void vmbus_probe_failed_cb(struct work_struct *context) static int vmbus_probe(struct device *child_device) { int ret = 0; - struct driver_context *driver_ctx = - driver_to_driver_context(child_device->driver); - struct vm_device *device_ctx = - device_to_vm_device(child_device); + struct hv_driver *drv = + drv_to_hv_drv(child_device->driver); + struct hv_device *dev = device_to_hv_device(child_device); /* Let the specific open-source driver handles the probe if it can */ - if (driver_ctx->probe) { - ret = device_ctx->probe_error = driver_ctx->probe(child_device); + if (drv->driver.probe) { + ret = dev->probe_error = + drv->driver.probe(child_device); if (ret != 0) { DPRINT_ERR(VMBUS_DRV, "probe() failed for device %s " "(%p) on driver %s (%d)...", dev_name(child_device), child_device, child_device->driver->name, ret); - INIT_WORK(&device_ctx->probe_failed_work_item, + INIT_WORK(&dev->probe_failed_work_item, vmbus_probe_failed_cb); - schedule_work(&device_ctx->probe_failed_work_item); + schedule_work(&dev->probe_failed_work_item); } } else { DPRINT_ERR(VMBUS_DRV, "probe() method not set for driver - %s", @@ -944,7 +871,7 @@ static int vmbus_probe(struct device *child_device) static int vmbus_remove(struct device *child_device) { int ret; - struct driver_context *driver_ctx; + struct hv_driver *drv; /* Special case root bus device */ if (child_device->parent == NULL) { @@ -956,14 +883,14 @@ static int vmbus_remove(struct device *child_device) } if (child_device->driver) { - driver_ctx = driver_to_driver_context(child_device->driver); + drv = drv_to_hv_drv(child_device->driver); /* * Let the specific open-source driver handles the removal if * it can */ - if (driver_ctx->remove) { - ret = driver_ctx->remove(child_device); + if (drv->driver.remove) { + ret = drv->driver.remove(child_device); } else { DPRINT_ERR(VMBUS_DRV, "remove() method not set for driver - %s", @@ -980,7 +907,7 @@ static int vmbus_remove(struct device *child_device) */ static void vmbus_shutdown(struct device *child_device) { - struct driver_context *driver_ctx; + struct hv_driver *drv; /* Special case root bus device */ if (child_device->parent == NULL) { @@ -995,11 +922,11 @@ static void vmbus_shutdown(struct device *child_device) if (!child_device->driver) return; - driver_ctx = driver_to_driver_context(child_device->driver); + drv = drv_to_hv_drv(child_device->driver); /* Let the specific open-source driver handles the removal if it can */ - if (driver_ctx->shutdown) - driver_ctx->shutdown(child_device); + if (drv->driver.shutdown) + drv->driver.shutdown(child_device); return; } @@ -1021,48 +948,28 @@ static void vmbus_bus_release(struct device *device) */ static void vmbus_device_release(struct device *device) { - struct vm_device *device_ctx = device_to_vm_device(device); + struct hv_device *device_ctx = device_to_hv_device(device); kfree(device_ctx); /* !!DO NOT REFERENCE device_ctx anymore at this point!! */ } -/* - * vmbus_msg_dpc - Tasklet routine to handle hypervisor messages - */ -static void vmbus_msg_dpc(unsigned long data) -{ - struct hv_driver *driver = (struct hv_driver *)data; - - /* Call to bus driver to handle interrupt */ - vmbus_on_msg_dpc(driver); -} -/* - * vmbus_event_dpc - Tasklet routine to handle hypervisor events - */ -static void vmbus_event_dpc(unsigned long data) -{ - /* Call to bus driver to handle interrupt */ - VmbusOnEvents(); -} static irqreturn_t vmbus_isr(int irq, void *dev_id) { - struct hv_driver *driver = &g_vmbus_drv.drv_obj; int ret; - /* Call to bus driver to handle interrupt */ - ret = vmbus_on_isr(driver); + ret = vmbus_on_isr(); /* Schedules a dpc if necessary */ if (ret > 0) { if (test_bit(0, (unsigned long *)&ret)) - tasklet_schedule(&g_vmbus_drv.msg_dpc); + tasklet_schedule(&vmbus_drv.msg_dpc); if (test_bit(1, (unsigned long *)&ret)) - tasklet_schedule(&g_vmbus_drv.event_dpc); + tasklet_schedule(&vmbus_drv.event_dpc); return IRQ_HANDLED; } else { diff --git a/drivers/staging/hv/vmbus_packet_format.h b/drivers/staging/hv/vmbus_packet_format.h index f9f6b4bf6fb1..c0b2c2b11646 100644 --- a/drivers/staging/hv/vmbus_packet_format.h +++ b/drivers/staging/hv/vmbus_packet_format.h @@ -25,53 +25,53 @@ #define _VMBUSPACKETFORMAT_H_ struct vmpacket_descriptor { - u16 Type; - u16 DataOffset8; - u16 Length8; - u16 Flags; - u64 TransactionId; -} __attribute__((packed)); + u16 type; + u16 offset8; + u16 len8; + u16 flags; + u64 trans_id; +} __packed; struct vmpacket_header { - u32 PreviousPacketStartOffset; - struct vmpacket_descriptor Descriptor; -} __attribute__((packed)); + u32 prev_pkt_start_offset; + struct vmpacket_descriptor descriptor; +} __packed; struct vmtransfer_page_range { - u32 ByteCount; - u32 ByteOffset; -} __attribute__((packed)); + u32 byte_count; + u32 byte_offset; +} __packed; struct vmtransfer_page_packet_header { struct vmpacket_descriptor d; - u16 TransferPageSetId; - bool SenderOwnsSet; - u8 Reserved; - u32 RangeCount; - struct vmtransfer_page_range Ranges[1]; -} __attribute__((packed)); + u16 xfer_pageset_id; + bool sender_owns_set; + u8 reserved; + u32 range_cnt; + struct vmtransfer_page_range ranges[1]; +} __packed; struct vmgpadl_packet_header { struct vmpacket_descriptor d; - u32 Gpadl; - u32 Reserved; -} __attribute__((packed)); + u32 gpadl; + u32 reserved; +} __packed; struct vmadd_remove_transfer_page_set { struct vmpacket_descriptor d; - u32 Gpadl; - u16 TransferPageSetId; - u16 Reserved; -} __attribute__((packed)); + u32 gpadl; + u16 xfer_pageset_id; + u16 reserved; +} __packed; /* * This structure defines a range in guest physical space that can be made to * look virtually contiguous. */ struct gpa_range { - u32 ByteCount; - u32 ByteOffset; - u64 PfnArray[0]; + u32 byte_count; + u32 byte_offset; + u64 pfn_array[0]; }; /* @@ -83,10 +83,10 @@ struct gpa_range { */ struct vmestablish_gpadl { struct vmpacket_descriptor d; - u32 Gpadl; - u32 RangeCount; - struct gpa_range Range[1]; -} __attribute__((packed)); + u32 gpadl; + u32 range_cnt; + struct gpa_range range[1]; +} __packed; /* * This is the format for a Teardown Gpadl packet, which indicates that the @@ -94,9 +94,9 @@ struct vmestablish_gpadl { */ struct vmteardown_gpadl { struct vmpacket_descriptor d; - u32 Gpadl; - u32 Reserved; /* for alignment to a 8-byte boundary */ -} __attribute__((packed)); + u32 gpadl; + u32 reserved; /* for alignment to a 8-byte boundary */ +} __packed; /* * This is the format for a GPA-Direct packet, which contains a set of GPA @@ -104,56 +104,56 @@ struct vmteardown_gpadl { */ struct vmdata_gpa_direct { struct vmpacket_descriptor d; - u32 Reserved; - u32 RangeCount; - struct gpa_range Range[1]; -} __attribute__((packed)); + u32 reserved; + u32 range_cnt; + struct gpa_range range[1]; +} __packed; /* This is the format for a Additional Data Packet. */ struct vmadditional_data { struct vmpacket_descriptor d; - u64 TotalBytes; - u32 ByteOffset; - u32 ByteCount; - unsigned char Data[1]; -} __attribute__((packed)); + u64 total_bytes; + u32 offset; + u32 byte_cnt; + unsigned char data[1]; +} __packed; union vmpacket_largest_possible_header { - struct vmpacket_descriptor SimpleHeader; - struct vmtransfer_page_packet_header TransferPageHeader; - struct vmgpadl_packet_header GpadlHeader; - struct vmadd_remove_transfer_page_set AddRemoveTransferPageHeader; - struct vmestablish_gpadl EstablishGpadlHeader; - struct vmteardown_gpadl TeardownGpadlHeader; - struct vmdata_gpa_direct DataGpaDirectHeader; + struct vmpacket_descriptor simple_hdr; + struct vmtransfer_page_packet_header xfer_page_hdr; + struct vmgpadl_packet_header gpadl_hdr; + struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr; + struct vmestablish_gpadl establish_gpadl_hdr; + struct vmteardown_gpadl teardown_gpadl_hdr; + struct vmdata_gpa_direct data_gpa_direct_hdr; }; #define VMPACKET_DATA_START_ADDRESS(__packet) \ (void *)(((unsigned char *)__packet) + \ - ((struct vmpacket_descriptor)__packet)->DataOffset8 * 8) + ((struct vmpacket_descriptor)__packet)->offset8 * 8) #define VMPACKET_DATA_LENGTH(__packet) \ - ((((struct vmpacket_descriptor)__packet)->Length8 - \ - ((struct vmpacket_descriptor)__packet)->DataOffset8) * 8) + ((((struct vmpacket_descriptor)__packet)->len8 - \ + ((struct vmpacket_descriptor)__packet)->offset8) * 8) #define VMPACKET_TRANSFER_MODE(__packet) \ - (((struct IMPACT)__packet)->Type) + (((struct IMPACT)__packet)->type) enum vmbus_packet_type { - VmbusPacketTypeInvalid = 0x0, - VmbusPacketTypeSynch = 0x1, - VmbusPacketTypeAddTransferPageSet = 0x2, - VmbusPacketTypeRemoveTransferPageSet = 0x3, - VmbusPacketTypeEstablishGpadl = 0x4, - VmbusPacketTypeTearDownGpadl = 0x5, - VmbusPacketTypeDataInBand = 0x6, - VmbusPacketTypeDataUsingTransferPages = 0x7, - VmbusPacketTypeDataUsingGpadl = 0x8, - VmbusPacketTypeDataUsingGpaDirect = 0x9, - VmbusPacketTypeCancelRequest = 0xa, - VmbusPacketTypeCompletion = 0xb, - VmbusPacketTypeDataUsingAdditionalPackets = 0xc, - VmbusPacketTypeAdditionalData = 0xd + VM_PKT_INVALID = 0x0, + VM_PKT_SYNCH = 0x1, + VM_PKT_ADD_XFER_PAGESET = 0x2, + VM_PKT_RM_XFER_PAGESET = 0x3, + VM_PKT_ESTABLISH_GPADL = 0x4, + VM_PKT_TEARDOWN_GPADL = 0x5, + VM_PKT_DATA_INBAND = 0x6, + VM_PKT_DATA_USING_XFER_PAGES = 0x7, + VM_PKT_DATA_USING_GPADL = 0x8, + VM_PKT_DATA_USING_GPA_DIRECT = 0x9, + VM_PKT_CANCEL_REQUEST = 0xa, + VM_PKT_COMP = 0xb, + VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc, + VM_PKT_ADDITIONAL_DATA = 0xd }; #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1 diff --git a/drivers/staging/hv/vmbus_private.h b/drivers/staging/hv/vmbus_private.h index 07f6d22eeabb..ca050a499b99 100644 --- a/drivers/staging/hv/vmbus_private.h +++ b/drivers/staging/hv/vmbus_private.h @@ -45,19 +45,19 @@ #define MAX_NUM_CHANNELS_SUPPORTED 256 -enum VMBUS_CONNECT_STATE { - Disconnected, - Connecting, - Connected, - Disconnecting +enum vmbus_connect_state { + DISCONNECTED, + CONNECTING, + CONNECTED, + DISCONNECTING }; #define MAX_SIZE_CHANNEL_MESSAGE HV_MESSAGE_PAYLOAD_BYTE_COUNT -struct VMBUS_CONNECTION { - enum VMBUS_CONNECT_STATE ConnectState; +struct vmbus_connection { + enum vmbus_connect_state conn_state; - atomic_t NextGpadlHandle; + atomic_t next_gpadl_handle; /* * Represents channel interrupts. Each bit position represents a @@ -66,69 +66,68 @@ struct VMBUS_CONNECTION { * event. The other end receives the port event and parse the * recvInterruptPage to see which bit is set */ - void *InterruptPage; - void *SendInterruptPage; - void *RecvInterruptPage; + void *int_page; + void *send_int_page; + void *recv_int_page; /* * 2 pages - 1st page for parent->child notification and 2nd * is child->parent notification */ - void *MonitorPages; - struct list_head ChannelMsgList; + void *monitor_pages; + struct list_head chn_msg_list; spinlock_t channelmsg_lock; /* List of channels */ - struct list_head ChannelList; + struct list_head chn_list; spinlock_t channel_lock; - struct workqueue_struct *WorkQueue; + struct workqueue_struct *work_queue; }; -struct VMBUS_MSGINFO { +struct vmbus_msginfo { /* Bookkeeping stuff */ - struct list_head MsgListEntry; + struct list_head msglist_entry; /* Synchronize the request/response if needed */ - struct osd_waitevent *WaitEvent; + int wait_condition; + wait_queue_head_t wait_event; /* The message itself */ - unsigned char Msg[0]; + unsigned char msg[0]; }; -extern struct VMBUS_CONNECTION gVmbusConnection; +extern struct vmbus_connection vmbus_connection; /* General vmbus interface */ -struct hv_device *vmbus_child_device_create(struct hv_guid *deviceType, - struct hv_guid *deviceInstance, +struct hv_device *vmbus_child_device_create(struct hv_guid *type, + struct hv_guid *instance, struct vmbus_channel *channel); -int VmbusChildDeviceAdd(struct hv_device *Device); -int vmbus_child_device_register(struct hv_device *root_device_obj, - struct hv_device *child_device_obj); +int vmbus_child_device_register(struct hv_device *child_device_obj); void vmbus_child_device_unregister(struct hv_device *device_obj); /* static void */ /* VmbusChildDeviceDestroy( */ /* struct hv_device *); */ -struct vmbus_channel *GetChannelFromRelId(u32 relId); +struct vmbus_channel *relid2channel(u32 relid); /* Connection interface */ -int VmbusConnect(void); +int vmbus_connect(void); -int VmbusDisconnect(void); +int vmbus_disconnect(void); -int VmbusPostMessage(void *buffer, size_t bufSize); +int vmbus_post_msg(void *buffer, size_t buflen); -int VmbusSetEvent(u32 childRelId); +int vmbus_set_event(u32 child_relid); -void VmbusOnEvents(void); +void vmbus_on_event(unsigned long data); #endif /* _VMBUS_PRIVATE_H_ */ diff --git a/drivers/staging/hv/vstorage.h b/drivers/staging/hv/vstorage.h index ae8be84394d5..ebb4d671c424 100644 --- a/drivers/staging/hv/vstorage.h +++ b/drivers/staging/hv/vstorage.h @@ -135,7 +135,7 @@ struct vmstorage_channel_properties { /* This id is unique for each channel and will correspond with */ /* vendor specific data in the inquirydata */ unsigned long long unique_id; -} __attribute__((packed)); +} __packed; /* This structure is sent during the storage protocol negotiations. */ struct vmstorage_protocol_version { @@ -149,7 +149,7 @@ struct vmstorage_protocol_version { * builds. */ unsigned short revision; -} __attribute__((packed)); +} __packed; /* Channel Property Flags */ #define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1 @@ -179,7 +179,7 @@ struct vstor_packet { /* Used during version negotiations. */ struct vmstorage_protocol_version version; }; -} __attribute__((packed)); +} __packed; /* Packet flags */ /* |