diff options
Diffstat (limited to 'drivers/staging/hv')
30 files changed, 3036 insertions, 3105 deletions
diff --git a/drivers/staging/hv/Makefile b/drivers/staging/hv/Makefile index b46349bb43bf..acd39bd75b1c 100644 --- a/drivers/staging/hv/Makefile +++ b/drivers/staging/hv/Makefile @@ -5,7 +5,7 @@ obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o hv_vmbus-y := vmbus_drv.o osd.o \ - vmbus.o hv.o connection.o channel.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 diff --git a/drivers/staging/hv/blkvsc.c b/drivers/staging/hv/blkvsc.c index d5b0abd771ab..bc16d9172eb2 100644 --- a/drivers/staging/hv/blkvsc.c +++ b/drivers/staging/hv/blkvsc.c @@ -25,24 +25,24 @@ #include "osd.h" #include "storvsc.c" -static const char *gBlkDriverName = "blkvsc"; +static const char *g_blk_driver_name = "blkvsc"; /* {32412632-86cb-44a2-9b5c-50d1417354f5} */ -static const struct hv_guid gBlkVscDeviceType = { +static const struct hv_guid g_blk_device_type = { .data = { 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 } }; -static int BlkVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) +static int blk_vsc_on_device_add(struct hv_device *device, void *additional_info) { - struct storvsc_device_info *deviceInfo; + struct storvsc_device_info *device_info; int ret = 0; - deviceInfo = (struct storvsc_device_info *)AdditionalInfo; + device_info = (struct storvsc_device_info *)additional_info; - ret = StorVscOnDeviceAdd(Device, AdditionalInfo); + ret = stor_vsc_on_device_add(device, additional_info); if (ret != 0) return ret; @@ -51,31 +51,31 @@ static int BlkVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) * id. For IDE devices, the device instance id is formatted as * <bus id> * - <device id> - 8899 - 000000000000. */ - deviceInfo->PathId = Device->deviceInstance.data[3] << 24 | - Device->deviceInstance.data[2] << 16 | - Device->deviceInstance.data[1] << 8 | - Device->deviceInstance.data[0]; + device_info->path_id = device->deviceInstance.data[3] << 24 | + device->deviceInstance.data[2] << 16 | + device->deviceInstance.data[1] << 8 | + device->deviceInstance.data[0]; - deviceInfo->TargetId = Device->deviceInstance.data[5] << 8 | - Device->deviceInstance.data[4]; + device_info->target_id = device->deviceInstance.data[5] << 8 | + device->deviceInstance.data[4]; return ret; } -int BlkVscInitialize(struct hv_driver *Driver) +int blk_vsc_initialize(struct hv_driver *driver) { - struct storvsc_driver_object *storDriver; + struct storvsc_driver_object *stor_driver; int ret = 0; - storDriver = (struct storvsc_driver_object *)Driver; + stor_driver = (struct storvsc_driver_object *)driver; /* Make sure we are at least 2 pages since 1 page is used for control */ - /* ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1)); */ + /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */ - Driver->name = gBlkDriverName; - memcpy(&Driver->deviceType, &gBlkVscDeviceType, sizeof(struct hv_guid)); + driver->name = g_blk_driver_name; + memcpy(&driver->deviceType, &g_blk_device_type, sizeof(struct hv_guid)); - storDriver->RequestExtSize = sizeof(struct storvsc_request_extension); + stor_driver->request_ext_size = sizeof(struct storvsc_request_extension); /* * Divide the ring buffer data size (which is 1 page less than the ring @@ -83,20 +83,20 @@ int BlkVscInitialize(struct hv_driver *Driver) * by the max request size (which is * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) */ - storDriver->MaxOutstandingRequestsPerChannel = - ((storDriver->RingBufferSize - PAGE_SIZE) / + stor_driver->max_outstanding_req_per_channel = + ((stor_driver->ring_buffer_size - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(struct vstor_packet) + sizeof(u64), sizeof(u64))); DPRINT_INFO(BLKVSC, "max io outstd %u", - storDriver->MaxOutstandingRequestsPerChannel); + stor_driver->max_outstanding_req_per_channel); /* Setup the dispatch table */ - storDriver->Base.OnDeviceAdd = BlkVscOnDeviceAdd; - storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove; - storDriver->Base.OnCleanup = StorVscOnCleanup; - storDriver->OnIORequest = StorVscOnIORequest; + 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->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 3f81ca591064..b3d05fcfe6d2 100644 --- a/drivers/staging/hv/blkvsc_drv.c +++ b/drivers/staging/hv/blkvsc_drv.c @@ -177,13 +177,13 @@ static int blkvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx; int ret; - storvsc_drv_obj->RingBufferSize = blkvsc_ringbuffer_size; + storvsc_drv_obj->ring_buffer_size = blkvsc_ringbuffer_size; /* Callback to client driver to complete the initialization */ - drv_init(&storvsc_drv_obj->Base); + 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, + drv_ctx->driver.name = storvsc_drv_obj->base.name; + memcpy(&drv_ctx->class_id, &storvsc_drv_obj->base.deviceType, sizeof(struct hv_guid)); drv_ctx->probe = blkvsc_probe; @@ -230,8 +230,8 @@ 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.OnCleanup) + storvsc_drv_obj->base.OnCleanup(&storvsc_drv_obj->base); vmbus_child_driver_unregister(drv_ctx); @@ -262,7 +262,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.OnDeviceAdd) { DPRINT_ERR(BLKVSC_DRV, "OnDeviceAdd() not set"); ret = -1; goto Cleanup; @@ -284,7 +284,7 @@ static int blkvsc_probe(struct device *device) blkdev->request_pool = kmem_cache_create(dev_name(&device_ctx->device), sizeof(struct blkvsc_request) + - storvsc_drv_obj->RequestExtSize, 0, + storvsc_drv_obj->request_ext_size, 0, SLAB_HWCACHE_ALIGN, NULL); if (!blkdev->request_pool) { ret = -ENOMEM; @@ -293,7 +293,7 @@ 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.OnDeviceAdd(device_obj, &device_info); if (ret != 0) { DPRINT_ERR(BLKVSC_DRV, "unable to add blkvsc device"); goto Cleanup; @@ -301,9 +301,9 @@ static int blkvsc_probe(struct device *device) blkdev->device_ctx = device_ctx; /* this identified the device 0 or 1 */ - blkdev->target = device_info.TargetId; + blkdev->target = device_info.target_id; /* this identified the ide ctrl 0 or 1 */ - blkdev->path = device_info.PathId; + blkdev->path = device_info.path_id; dev_set_drvdata(device, blkdev); @@ -391,7 +391,7 @@ static int blkvsc_probe(struct device *device) return ret; Remove: - storvsc_drv_obj->Base.OnDeviceRemove(device_obj); + storvsc_drv_obj->base.OnDeviceRemove(device_obj); Cleanup: if (blkdev) { @@ -459,9 +459,9 @@ static int blkvsc_do_flush(struct block_device_context *blkdev) blkvsc_req->req = NULL; blkvsc_req->write = 0; - blkvsc_req->request.DataBuffer.PfnArray[0] = 0; - blkvsc_req->request.DataBuffer.Offset = 0; - blkvsc_req->request.DataBuffer.Length = 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->cmnd[0] = SYNCHRONIZE_CACHE; blkvsc_req->cmd_len = 10; @@ -506,9 +506,9 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev) blkvsc_req->req = NULL; blkvsc_req->write = 0; - blkvsc_req->request.DataBuffer.PfnArray[0] = page_to_pfn(page_buf); - blkvsc_req->request.DataBuffer.Offset = 0; - blkvsc_req->request.DataBuffer.Length = 64; + 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->cmnd[0] = INQUIRY; blkvsc_req->cmnd[1] = 0x1; /* Get product data */ @@ -593,9 +593,9 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev) blkvsc_req->req = NULL; blkvsc_req->write = 0; - blkvsc_req->request.DataBuffer.PfnArray[0] = page_to_pfn(page_buf); - blkvsc_req->request.DataBuffer.Offset = 0; - blkvsc_req->request.DataBuffer.Length = 8; + 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->cmnd[0] = READ_CAPACITY; blkvsc_req->cmd_len = 16; @@ -614,7 +614,7 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev) wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); /* check error */ - if (blkvsc_req->request.Status) { + if (blkvsc_req->request.status) { scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr); @@ -670,9 +670,9 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev) blkvsc_req->req = NULL; blkvsc_req->write = 0; - blkvsc_req->request.DataBuffer.PfnArray[0] = page_to_pfn(page_buf); - blkvsc_req->request.DataBuffer.Offset = 0; - blkvsc_req->request.DataBuffer.Length = 12; + 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->cmnd[0] = 0x9E; /* READ_CAPACITY16; */ blkvsc_req->cmd_len = 16; @@ -691,7 +691,7 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev) wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); /* check error */ - if (blkvsc_req->request.Status) { + if (blkvsc_req->request.status) { scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr); if (sense_hdr.asc == 0x3A) { @@ -741,14 +741,14 @@ static int blkvsc_remove(struct device *device) DPRINT_DBG(BLKVSC_DRV, "blkvsc_remove()\n"); - if (!storvsc_drv_obj->Base.OnDeviceRemove) + if (!storvsc_drv_obj->base.OnDeviceRemove) 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.OnDeviceRemove(device_obj); if (ret != 0) { /* TODO: */ DPRINT_ERR(BLKVSC_DRV, @@ -865,38 +865,38 @@ 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.DataBuffer.Offset, - blkvsc_req->request.DataBuffer.Length); + blkvsc_req->request.data_buffer.Offset, + blkvsc_req->request.data_buffer.Length); #if 0 - for (i = 0; i < (blkvsc_req->request.DataBuffer.Length >> 12); i++) { + for (i = 0; i < (blkvsc_req->request.data_buffer.Length >> 12); i++) { DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - " "req %p pfn[%d] %llx\n", blkvsc_req, i, - blkvsc_req->request.DataBuffer.PfnArray[i]); + blkvsc_req->request.data_buffer.PfnArray[i]); } #endif storvsc_req = &blkvsc_req->request; - storvsc_req->Extension = (void *)((unsigned long)blkvsc_req + + storvsc_req->extension = (void *)((unsigned long)blkvsc_req + sizeof(struct blkvsc_request)); - storvsc_req->Type = blkvsc_req->write ? WRITE_TYPE : READ_TYPE; + storvsc_req->type = blkvsc_req->write ? WRITE_TYPE : READ_TYPE; - storvsc_req->OnIOCompletion = request_completion; - storvsc_req->Context = blkvsc_req; + storvsc_req->on_io_completion = request_completion; + storvsc_req->context = blkvsc_req; - storvsc_req->Host = blkdev->port; - storvsc_req->Bus = blkdev->path; - storvsc_req->TargetId = blkdev->target; - storvsc_req->LunId = 0; /* this is not really used at all */ + storvsc_req->host = blkdev->port; + storvsc_req->bus = blkdev->path; + storvsc_req->target_id = blkdev->target; + storvsc_req->lun_id = 0; /* this is not really used at all */ - storvsc_req->CdbLen = blkvsc_req->cmd_len; - storvsc_req->Cdb = blkvsc_req->cmnd; + storvsc_req->cdb_len = blkvsc_req->cmd_len; + storvsc_req->cdb = blkvsc_req->cmnd; - storvsc_req->SenseBuffer = blkvsc_req->sense_buffer; - storvsc_req->SenseBufferSize = SCSI_SENSE_BUFFERSIZE; + storvsc_req->sense_buffer = blkvsc_req->sense_buffer; + storvsc_req->sense_buffer_size = SCSI_SENSE_BUFFERSIZE; - ret = storvsc_drv_obj->OnIORequest(&blkdev->device_ctx->device_obj, + ret = storvsc_drv_obj->on_io_request(&blkdev->device_ctx->device_obj, &blkvsc_req->request); if (ret == 0) blkdev->num_outstanding_reqs++; @@ -992,8 +992,10 @@ static int blkvsc_do_request(struct block_device_context *blkdev, blkvsc_req->dev = blkdev; blkvsc_req->req = req; - blkvsc_req->request.DataBuffer.Offset = bvec->bv_offset; - blkvsc_req->request.DataBuffer.Length = 0; + blkvsc_req->request.data_buffer.Offset + = bvec->bv_offset; + blkvsc_req->request.data_buffer.Length + = 0; /* Add to the group */ blkvsc_req->group = group; @@ -1007,8 +1009,11 @@ static int blkvsc_do_request(struct block_device_context *blkdev, } /* Add the curr bvec/segment to the curr blkvsc_req */ - blkvsc_req->request.DataBuffer.PfnArray[databuf_idx] = page_to_pfn(bvec->bv_page); - blkvsc_req->request.DataBuffer.Length += bvec->bv_len; + blkvsc_req->request.data_buffer. + PfnArray[databuf_idx] + = page_to_pfn(bvec->bv_page); + blkvsc_req->request.data_buffer.Length + += bvec->bv_len; prev_bvec = bvec; @@ -1073,7 +1078,7 @@ static int blkvsc_do_request(struct block_device_context *blkdev, static void blkvsc_cmd_completion(struct hv_storvsc_request *request) { struct blkvsc_request *blkvsc_req = - (struct blkvsc_request *)request->Context; + (struct blkvsc_request *)request->context; struct block_device_context *blkdev = (struct block_device_context *)blkvsc_req->dev; struct scsi_sense_hdr sense_hdr; @@ -1083,7 +1088,7 @@ static void blkvsc_cmd_completion(struct hv_storvsc_request *request) blkdev->num_outstanding_reqs--; - if (blkvsc_req->request.Status) + if (blkvsc_req->request.status) if (scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr)) scsi_print_sense_hdr("blkvsc", &sense_hdr); @@ -1095,7 +1100,7 @@ static void blkvsc_cmd_completion(struct hv_storvsc_request *request) static void blkvsc_request_completion(struct hv_storvsc_request *request) { struct blkvsc_request *blkvsc_req = - (struct blkvsc_request *)request->Context; + (struct blkvsc_request *)request->context; struct block_device_context *blkdev = (struct block_device_context *)blkvsc_req->dev; unsigned long flags; @@ -1110,7 +1115,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.DataBuffer.Length, + blkvsc_req->request.data_buffer.Length, blkvsc_req->group->outstanding, blkdev->num_outstanding_reqs); @@ -1137,7 +1142,7 @@ static void blkvsc_request_completion(struct hv_storvsc_request *request) list_del(&comp_req->req_entry); if (!__blk_end_request(comp_req->req, - (!comp_req->request.Status ? 0 : -EIO), + (!comp_req->request.status ? 0 : -EIO), comp_req->sector_count * blkdev->sector_size)) { /* * All the sectors have been xferred ie the @@ -1195,7 +1200,7 @@ static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev) if (comp_req->req) { ret = __blk_end_request(comp_req->req, - (!comp_req->request.Status ? 0 : -EIO), + (!comp_req->request.status ? 0 : -EIO), comp_req->sector_count * blkdev->sector_size); @@ -1482,7 +1487,7 @@ static int __init blkvsc_init(void) DPRINT_INFO(BLKVSC_DRV, "Blkvsc initializing...."); - ret = blkvsc_drv_init(BlkVscInitialize); + ret = blkvsc_drv_init(blk_vsc_initialize); return ret; } diff --git a/drivers/staging/hv/channel.c b/drivers/staging/hv/channel.c index 26ebc77f22b7..45a627d77b41 100644 --- a/drivers/staging/hv/channel.c +++ b/drivers/staging/hv/channel.c @@ -43,24 +43,24 @@ static void DumpMonitorPage(struct hv_monitor_page *MonitorPage) int j = 0; DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d", - MonitorPage, MonitorPage->TriggerState); + MonitorPage, MonitorPage->trigger_state); for (i = 0; i < 4; i++) DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i, - MonitorPage->TriggerGroup[i].AsUINT64); + MonitorPage->trigger_group[i].as_uint64); for (i = 0; i < 4; i++) { for (j = 0; j < 32; j++) { DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j, - MonitorPage->Latency[i][j]); + MonitorPage->latency[i][j]); } } for (i = 0; i < 4; i++) { for (j = 0; j < 32; j++) { DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, - MonitorPage->Parameter[i][j].ConnectionId.Asu32); + MonitorPage->parameter[i][j].connectionid.asu32); DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, - MonitorPage->Parameter[i][j].FlagNumber); + MonitorPage->parameter[i][j].flag_number); } } } @@ -74,21 +74,21 @@ static void vmbus_setevent(struct vmbus_channel *channel) { struct hv_monitor_page *monitorpage; - if (channel->OfferMsg.MonitorAllocated) { + if (channel->offermsg.monitor_allocated) { /* Each u32 represents 32 channels */ - set_bit(channel->OfferMsg.ChildRelId & 31, + set_bit(channel->offermsg.child_relid & 31, (unsigned long *) gVmbusConnection.SendInterruptPage + - (channel->OfferMsg.ChildRelId >> 5)); + (channel->offermsg.child_relid >> 5)); monitorpage = gVmbusConnection.MonitorPages; monitorpage++; /* Get the child to parent monitor page */ - set_bit(channel->MonitorBit, - (unsigned long *)&monitorpage->TriggerGroup - [channel->MonitorGroup].Pending); + set_bit(channel->monitor_bit, + (unsigned long *)&monitorpage->trigger_group + [channel->monitor_grp].pending); } else { - VmbusSetEvent(channel->OfferMsg.ChildRelId); + VmbusSetEvent(channel->offermsg.child_relid); } } @@ -97,19 +97,19 @@ static void VmbusChannelClearEvent(struct vmbus_channel *channel) { struct hv_monitor_page *monitorPage; - if (Channel->OfferMsg.MonitorAllocated) { + if (Channel->offermsg.monitor_allocated) { /* Each u32 represents 32 channels */ - clear_bit(Channel->OfferMsg.ChildRelId & 31, + clear_bit(Channel->offermsg.child_relid & 31, (unsigned long *)gVmbusConnection.SendInterruptPage + - (Channel->OfferMsg.ChildRelId >> 5)); + (Channel->offermsg.child_relid >> 5)); monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages; monitorPage++; /* Get the child to parent monitor page */ - clear_bit(Channel->MonitorBit, - (unsigned long *)&monitorPage->TriggerGroup - [Channel->MonitorGroup].Pending); + clear_bit(Channel->monitor_bit, + (unsigned long *)&monitorPage->trigger_group + [Channel->monitor_grp].Pending); } } @@ -121,42 +121,42 @@ void vmbus_get_debug_info(struct vmbus_channel *channel, struct vmbus_channel_debug_info *debuginfo) { struct hv_monitor_page *monitorpage; - u8 monitor_group = (u8)channel->OfferMsg.MonitorId / 32; - u8 monitor_offset = (u8)channel->OfferMsg.MonitorId % 32; + u8 monitor_group = (u8)channel->offermsg.monitorid / 32; + u8 monitor_offset = (u8)channel->offermsg.monitorid % 32; /* u32 monitorBit = 1 << monitorOffset; */ - debuginfo->RelId = channel->OfferMsg.ChildRelId; - debuginfo->State = channel->State; - memcpy(&debuginfo->InterfaceType, - &channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid)); - memcpy(&debuginfo->InterfaceInstance, - &channel->OfferMsg.Offer.InterfaceInstance, + debuginfo->relid = channel->offermsg.child_relid; + debuginfo->state = channel->state; + memcpy(&debuginfo->interfacetype, + &channel->offermsg.offer.InterfaceType, sizeof(struct hv_guid)); + memcpy(&debuginfo->interface_instance, + &channel->offermsg.offer.InterfaceInstance, sizeof(struct hv_guid)); monitorpage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages; - debuginfo->MonitorId = channel->OfferMsg.MonitorId; + debuginfo->monitorid = channel->offermsg.monitorid; - debuginfo->ServerMonitorPending = - monitorpage->TriggerGroup[monitor_group].Pending; - debuginfo->ServerMonitorLatency = - monitorpage->Latency[monitor_group][monitor_offset]; - debuginfo->ServerMonitorConnectionId = - monitorpage->Parameter[monitor_group] - [monitor_offset].ConnectionId.u.Id; + debuginfo->servermonitor_pending = + monitorpage->trigger_group[monitor_group].pending; + debuginfo->servermonitor_latency = + monitorpage->latency[monitor_group][monitor_offset]; + debuginfo->servermonitor_connectionid = + monitorpage->parameter[monitor_group] + [monitor_offset].connectionid.u.id; monitorpage++; - debuginfo->ClientMonitorPending = - monitorpage->TriggerGroup[monitor_group].Pending; - debuginfo->ClientMonitorLatency = - monitorpage->Latency[monitor_group][monitor_offset]; - debuginfo->ClientMonitorConnectionId = - monitorpage->Parameter[monitor_group] - [monitor_offset].ConnectionId.u.Id; + debuginfo->clientmonitor_pending = + monitorpage->trigger_group[monitor_group].pending; + debuginfo->clientmonitor_latency = + monitorpage->latency[monitor_group][monitor_offset]; + debuginfo->clientmonitor_connectionid = + monitorpage->parameter[monitor_group] + [monitor_offset].connectionid.u.id; - RingBufferGetDebugInfo(&channel->Inbound, &debuginfo->Inbound); - RingBufferGetDebugInfo(&channel->Outbound, &debuginfo->Outbound); + ringbuffer_get_debuginfo(&channel->inbound, &debuginfo->inbound); + ringbuffer_get_debuginfo(&channel->outbound, &debuginfo->outbound); } /* @@ -176,11 +176,11 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, /* ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1))); */ /* ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1))); */ - newchannel->OnChannelCallback = onchannelcallback; - newchannel->ChannelCallbackContext = context; + newchannel->onchannel_callback = onchannelcallback; + newchannel->channel_callback_context = context; /* Allocate the ring buffer */ - out = osd_PageAlloc((send_ringbuffer_size + recv_ringbuffer_size) + out = osd_page_alloc((send_ringbuffer_size + recv_ringbuffer_size) >> PAGE_SHIFT); if (!out) return -ENOMEM; @@ -189,17 +189,17 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, in = (void *)((unsigned long)out + send_ringbuffer_size); - newchannel->RingBufferPages = out; - newchannel->RingBufferPageCount = (send_ringbuffer_size + + newchannel->ringbuffer_pages = out; + newchannel->ringbuffer_pagecount = (send_ringbuffer_size + recv_ringbuffer_size) >> PAGE_SHIFT; - ret = RingBufferInit(&newchannel->Outbound, out, send_ringbuffer_size); + ret = ringbuffer_init(&newchannel->outbound, out, send_ringbuffer_size); if (ret != 0) { err = ret; goto errorout; } - ret = RingBufferInit(&newchannel->Inbound, in, recv_ringbuffer_size); + ret = ringbuffer_init(&newchannel->inbound, in, recv_ringbuffer_size); if (ret != 0) { err = ret; goto errorout; @@ -210,13 +210,13 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", newchannel); - newchannel->RingBufferGpadlHandle = 0; + newchannel->ringbuffer_gpadlhandle = 0; ret = vmbus_establish_gpadl(newchannel, - newchannel->Outbound.RingBuffer, + newchannel->outbound.ring_buffer, send_ringbuffer_size + recv_ringbuffer_size, - &newchannel->RingBufferGpadlHandle); + &newchannel->ringbuffer_gpadlhandle); if (ret != 0) { err = ret; @@ -225,12 +225,12 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p " "size %d recv ring %p size %d, downstreamoffset %d>", - newchannel, newchannel->OfferMsg.ChildRelId, - newchannel->RingBufferGpadlHandle, - newchannel->Outbound.RingBuffer, - newchannel->Outbound.RingSize, - newchannel->Inbound.RingBuffer, - newchannel->Inbound.RingSize, + newchannel, newchannel->offermsg.child_relid, + newchannel->ringbuffer_gpadlhandle, + newchannel->outbound.ring_buffer, + newchannel->outbound.ring_size, + newchannel->inbound.ring_buffer, + newchannel->inbound.ring_size, send_ringbuffer_size); /* Create and init the channel open message */ @@ -242,20 +242,20 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, goto errorout; } - openInfo->WaitEvent = osd_WaitEventCreate(); - if (!openInfo->WaitEvent) { + openInfo->waitevent = osd_waitevent_create(); + if (!openInfo->waitevent) { err = -ENOMEM; goto errorout; } - openMsg = (struct vmbus_channel_open_channel *)openInfo->Msg; - openMsg->Header.MessageType = ChannelMessageOpenChannel; - openMsg->OpenId = newchannel->OfferMsg.ChildRelId; /* FIXME */ - openMsg->ChildRelId = newchannel->OfferMsg.ChildRelId; - openMsg->RingBufferGpadlHandle = newchannel->RingBufferGpadlHandle; - openMsg->DownstreamRingBufferPageOffset = send_ringbuffer_size >> + openMsg = (struct vmbus_channel_open_channel *)openInfo->msg; + openMsg->header.msgtype = CHANNELMSG_OPENCHANNEL; + openMsg->openid = newchannel->offermsg.child_relid; /* FIXME */ + openMsg->child_relid = newchannel->offermsg.child_relid; + openMsg->ringbuffer_gpadlhandle = newchannel->ringbuffer_gpadlhandle; + openMsg->downstream_ringbuffer_pageoffset = send_ringbuffer_size >> PAGE_SHIFT; - openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */ + openMsg->server_contextarea_gpadlhandle = 0; /* TODO */ if (userdatalen > MAX_USER_DEFINED_BYTES) { err = -EINVAL; @@ -263,10 +263,10 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, } if (userdatalen) - memcpy(openMsg->UserData, userdata, userdatalen); + memcpy(openMsg->userdata, userdata, userdatalen); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - list_add_tail(&openInfo->MsgListEntry, + list_add_tail(&openInfo->msglistentry, &gVmbusConnection.ChannelMsgList); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); @@ -280,27 +280,27 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, } /* FIXME: Need to time-out here */ - osd_WaitEventWait(openInfo->WaitEvent); + osd_waitevent_wait(openInfo->waitevent); - if (openInfo->Response.OpenResult.Status == 0) + if (openInfo->response.open_result.status == 0) DPRINT_INFO(VMBUS, "channel <%p> open success!!", newchannel); else DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", - newchannel, openInfo->Response.OpenResult.Status); + newchannel, openInfo->response.open_result.status); Cleanup: spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - list_del(&openInfo->MsgListEntry); + list_del(&openInfo->msglistentry); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); - kfree(openInfo->WaitEvent); + kfree(openInfo->waitevent); kfree(openInfo); return 0; errorout: - RingBufferCleanup(&newchannel->Outbound); - RingBufferCleanup(&newchannel->Inbound); - osd_PageFree(out, (send_ringbuffer_size + recv_ringbuffer_size) + ringbuffer_cleanup(&newchannel->outbound); + ringbuffer_cleanup(&newchannel->inbound); + osd_page_free(out, (send_ringbuffer_size + recv_ringbuffer_size) >> PAGE_SHIFT); kfree(openInfo); return err; @@ -322,7 +322,7 @@ static void dump_gpadl_body(struct vmbus_channel_gpadl_body *gpadl, u32 len) for (i = 0; i < pfncount; i++) DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu", - i, gpadl->Pfn[i]); + i, gpadl->pfn[i]); } /* @@ -336,18 +336,18 @@ static void dump_gpadl_header(struct vmbus_channel_gpadl_header *gpadl) DPRINT_DBG(VMBUS, "gpadl header - relid %d, range count %d, range buflen %d", - gpadl->ChildRelId, gpadl->RangeCount, gpadl->RangeBufLen); - for (i = 0; i < gpadl->RangeCount; i++) { - pagecount = gpadl->Range[i].ByteCount >> PAGE_SHIFT; + gpadl->child_relid, gpadl->rangecount, gpadl->range_buflen); + for (i = 0; i < gpadl->rangecount; i++) { + pagecount = gpadl->range[i].ByteCount >> 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].ByteCount, + gpadl->range[i].ByteOffset, pagecount); for (j = 0; j < pagecount; j++) DPRINT_DBG(VMBUS, "%d) pfn %llu", j, - gpadl->Range[i].PfnArray[j]); + gpadl->range[i].PfnArray[j]); } } @@ -391,18 +391,18 @@ static int create_gpadl_header(void *kbuffer, u32 size, if (!msgheader) goto nomem; - INIT_LIST_HEAD(&msgheader->SubMsgList); - msgheader->MessageSize = msgsize; + INIT_LIST_HEAD(&msgheader->submsglist); + msgheader->msgsize = msgsize; gpadl_header = (struct vmbus_channel_gpadl_header *) - msgheader->Msg; - gpadl_header->RangeCount = 1; - gpadl_header->RangeBufLen = sizeof(struct gpa_range) + + msgheader->msg; + 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].ByteOffset = 0; + gpadl_header->range[0].ByteCount = size; for (i = 0; i < pfncount; i++) - gpadl_header->Range[0].PfnArray[i] = pfn+i; + gpadl_header->range[0].PfnArray[i] = pfn+i; *msginfo = msgheader; *messagecount = 1; @@ -428,10 +428,10 @@ static int create_gpadl_header(void *kbuffer, u32 size, /* FIXME: we probably need to more if this fails */ if (!msgbody) goto nomem; - msgbody->MessageSize = msgsize; + msgbody->msgsize = msgsize; (*messagecount)++; gpadl_body = - (struct vmbus_channel_gpadl_body *)msgbody->Msg; + (struct vmbus_channel_gpadl_body *)msgbody->msg; /* * FIXME: @@ -440,11 +440,11 @@ static int create_gpadl_header(void *kbuffer, u32 size, */ /* gpadl_body->Gpadl = kbuffer; */ for (i = 0; i < pfncurr; i++) - gpadl_body->Pfn[i] = pfn + pfnsum + i; + gpadl_body->pfn[i] = pfn + pfnsum + i; /* add to msg header */ - list_add_tail(&msgbody->MsgListEntry, - &msgheader->SubMsgList); + list_add_tail(&msgbody->msglistentry, + &msgheader->submsglist); pfnsum += pfncurr; pfnleft -= pfncurr; } @@ -456,17 +456,17 @@ static int create_gpadl_header(void *kbuffer, u32 size, msgheader = kzalloc(msgsize, GFP_KERNEL); if (msgheader == NULL) goto nomem; - msgheader->MessageSize = msgsize; + msgheader->msgsize = msgsize; gpadl_header = (struct vmbus_channel_gpadl_header *) - msgheader->Msg; - gpadl_header->RangeCount = 1; - gpadl_header->RangeBufLen = sizeof(struct gpa_range) + + msgheader->msg; + 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].ByteOffset = 0; + gpadl_header->range[0].ByteCount = size; for (i = 0; i < pagecount; i++) - gpadl_header->Range[0].PfnArray[i] = pfn+i; + gpadl_header->range[0].PfnArray[i] = pfn+i; *msginfo = msgheader; *messagecount = 1; @@ -508,21 +508,21 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, if (ret) return ret; - msginfo->WaitEvent = osd_WaitEventCreate(); - if (!msginfo->WaitEvent) { + msginfo->waitevent = osd_waitevent_create(); + if (!msginfo->waitevent) { ret = -ENOMEM; goto Cleanup; } - gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->Msg; - gpadlmsg->Header.MessageType = ChannelMessageGpadlHeader; - gpadlmsg->ChildRelId = channel->OfferMsg.ChildRelId; - gpadlmsg->Gpadl = next_gpadl_handle; + gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->msg; + gpadlmsg->header.msgtype = CHANNELMSG_GPADL_HEADER; + gpadlmsg->child_relid = channel->offermsg.child_relid; + gpadlmsg->gpadl = next_gpadl_handle; dump_gpadl_header(gpadlmsg); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - list_add_tail(&msginfo->MsgListEntry, + list_add_tail(&msginfo->msglistentry, &gVmbusConnection.ChannelMsgList); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); @@ -530,9 +530,9 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, kbuffer, size, msgcount); DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", - msginfo->MessageSize - sizeof(*msginfo)); + msginfo->msgsize - sizeof(*msginfo)); - ret = VmbusPostMessage(gpadlmsg, msginfo->MessageSize - + ret = VmbusPostMessage(gpadlmsg, msginfo->msgsize - sizeof(*msginfo)); if (ret != 0) { DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret); @@ -540,48 +540,48 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, } if (msgcount > 1) { - list_for_each(curr, &msginfo->SubMsgList) { + list_for_each(curr, &msginfo->submsglist) { /* FIXME: should this use list_entry() instead ? */ submsginfo = (struct vmbus_channel_msginfo *)curr; gpadl_body = - (struct vmbus_channel_gpadl_body *)submsginfo->Msg; + (struct vmbus_channel_gpadl_body *)submsginfo->msg; - gpadl_body->Header.MessageType = - ChannelMessageGpadlBody; - gpadl_body->Gpadl = next_gpadl_handle; + gpadl_body->header.msgtype = + CHANNELMSG_GPADL_BODY; + gpadl_body->gpadl = next_gpadl_handle; DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", - submsginfo->MessageSize - + submsginfo->msgsize - sizeof(*submsginfo)); - dump_gpadl_body(gpadl_body, submsginfo->MessageSize - + dump_gpadl_body(gpadl_body, submsginfo->msgsize - sizeof(*submsginfo)); ret = VmbusPostMessage(gpadl_body, - submsginfo->MessageSize - + submsginfo->msgsize - sizeof(*submsginfo)); if (ret != 0) goto Cleanup; } } - osd_WaitEventWait(msginfo->WaitEvent); + osd_waitevent_wait(msginfo->waitevent); /* At this point, we received the gpadl created msg */ DPRINT_DBG(VMBUS, "Received GPADL created " "(relid %d, status %d handle %x)", - channel->OfferMsg.ChildRelId, - msginfo->Response.GpadlCreated.CreationStatus, - gpadlmsg->Gpadl); + channel->offermsg.child_relid, + msginfo->response.gpadl_created.creation_status, + gpadlmsg->gpadl); - *gpadl_handle = gpadlmsg->Gpadl; + *gpadl_handle = gpadlmsg->gpadl; Cleanup: spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - list_del(&msginfo->MsgListEntry); + list_del(&msginfo->msglistentry); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); - kfree(msginfo->WaitEvent); + kfree(msginfo->waitevent); kfree(msginfo); return ret; } @@ -604,20 +604,20 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) if (!info) return -ENOMEM; - info->WaitEvent = osd_WaitEventCreate(); - if (!info->WaitEvent) { + info->waitevent = osd_waitevent_create(); + if (!info->waitevent) { kfree(info); return -ENOMEM; } - msg = (struct vmbus_channel_gpadl_teardown *)info->Msg; + msg = (struct vmbus_channel_gpadl_teardown *)info->msg; - msg->Header.MessageType = ChannelMessageGpadlTeardown; - msg->ChildRelId = channel->OfferMsg.ChildRelId; - msg->Gpadl = gpadl_handle; + msg->header.msgtype = CHANNELMSG_GPADL_TEARDOWN; + msg->child_relid = channel->offermsg.child_relid; + msg->gpadl = gpadl_handle; spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - list_add_tail(&info->MsgListEntry, + list_add_tail(&info->msglistentry, &gVmbusConnection.ChannelMsgList); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); @@ -628,14 +628,14 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) /* something... */ } - osd_WaitEventWait(info->WaitEvent); + osd_waitevent_wait(info->waitevent); /* Received a torndown response */ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - list_del(&info->MsgListEntry); + list_del(&info->msglistentry); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); - kfree(info->WaitEvent); + kfree(info->waitevent); kfree(info); return ret; } @@ -652,7 +652,7 @@ void vmbus_close(struct vmbus_channel *channel) int ret; /* Stop callback and cancel the timer asap */ - channel->OnChannelCallback = NULL; + channel->onchannel_callback = NULL; del_timer_sync(&channel->poll_timer); /* Send a closing message */ @@ -663,11 +663,11 @@ void vmbus_close(struct vmbus_channel *channel) if (!info) return; - /* info->waitEvent = osd_WaitEventCreate(); */ + /* info->waitEvent = osd_waitevent_create(); */ - msg = (struct vmbus_channel_close_channel *)info->Msg; - msg->Header.MessageType = ChannelMessageCloseChannel; - msg->ChildRelId = channel->OfferMsg.ChildRelId; + 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) { @@ -676,17 +676,17 @@ void vmbus_close(struct vmbus_channel *channel) } /* Tear down the gpadl for the channel's ring buffer */ - if (channel->RingBufferGpadlHandle) + if (channel->ringbuffer_gpadlhandle) vmbus_teardown_gpadl(channel, - channel->RingBufferGpadlHandle); + channel->ringbuffer_gpadlhandle); /* TODO: Send a msg to release the childRelId */ /* Cleanup the ring buffers for this channel */ - RingBufferCleanup(&channel->Outbound); - RingBufferCleanup(&channel->Inbound); + ringbuffer_cleanup(&channel->outbound); + ringbuffer_cleanup(&channel->inbound); - osd_PageFree(channel->RingBufferPages, channel->RingBufferPageCount); + osd_page_free(channel->ringbuffer_pages, channel->ringbuffer_pagecount); kfree(info); @@ -696,9 +696,9 @@ void vmbus_close(struct vmbus_channel *channel) * caller will free the channel */ - if (channel->State == CHANNEL_OPEN_STATE) { + if (channel->state == CHANNEL_OPEN_STATE) { spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); - list_del(&channel->ListEntry); + list_del(&channel->listentry); spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); free_channel(channel); @@ -752,10 +752,10 @@ int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer, sg_set_buf(&bufferlist[2], &aligned_data, packetlen_aligned - packetlen); - ret = RingBufferWrite(&channel->Outbound, bufferlist, 3); + ret = ringbuffer_write(&channel->outbound, bufferlist, 3); /* TODO: We should determine if this is optional */ - if (ret == 0 && !GetRingBufferInterruptMask(&channel->Outbound)) + if (ret == 0 && !get_ringbuffer_interrupt_mask(&channel->outbound)) vmbus_setevent(channel); return ret; @@ -817,10 +817,10 @@ int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, sg_set_buf(&bufferlist[2], &aligned_data, packetlen_aligned - packetlen); - ret = RingBufferWrite(&channel->Outbound, bufferlist, 3); + ret = ringbuffer_write(&channel->outbound, bufferlist, 3); /* TODO: We should determine if this is optional */ - if (ret == 0 && !GetRingBufferInterruptMask(&channel->Outbound)) + if (ret == 0 && !get_ringbuffer_interrupt_mask(&channel->outbound)) vmbus_setevent(channel); return ret; @@ -886,10 +886,10 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, sg_set_buf(&bufferlist[2], &aligned_data, packetlen_aligned - packetlen); - ret = RingBufferWrite(&channel->Outbound, bufferlist, 3); + ret = ringbuffer_write(&channel->outbound, bufferlist, 3); /* TODO: We should determine if this is optional */ - if (ret == 0 && !GetRingBufferInterruptMask(&channel->Outbound)) + if (ret == 0 && !get_ringbuffer_interrupt_mask(&channel->outbound)) vmbus_setevent(channel); return ret; @@ -923,7 +923,7 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, spin_lock_irqsave(&channel->inbound_lock, flags); - ret = RingBufferPeek(&channel->Inbound, &desc, + ret = ringbuffer_peek(&channel->inbound, &desc, sizeof(struct vmpacket_descriptor)); if (ret != 0) { spin_unlock_irqrestore(&channel->inbound_lock, flags); @@ -940,7 +940,7 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d " "flag %d tid %llx pktlen %d datalen %d> ", - channel, channel->OfferMsg.ChildRelId, desc.Type, + channel, channel->offermsg.child_relid, desc.Type, desc.Flags, desc.TransactionId, packetlen, userlen); *buffer_actual_len = userlen; @@ -956,7 +956,7 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, *requestid = desc.TransactionId; /* Copy over the packet to the user buffer */ - ret = RingBufferRead(&channel->Inbound, buffer, userlen, + ret = ringbuffer_read(&channel->inbound, buffer, userlen, (desc.DataOffset8 << 3)); spin_unlock_irqrestore(&channel->inbound_lock, flags); @@ -983,7 +983,7 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, spin_lock_irqsave(&channel->inbound_lock, flags); - ret = RingBufferPeek(&channel->Inbound, &desc, + ret = ringbuffer_peek(&channel->inbound, &desc, sizeof(struct vmpacket_descriptor)); if (ret != 0) { spin_unlock_irqrestore(&channel->inbound_lock, flags); @@ -999,7 +999,7 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d " "flag %d tid %llx pktlen %d datalen %d> ", - channel, channel->OfferMsg.ChildRelId, desc.Type, + channel, channel->offermsg.child_relid, desc.Type, desc.Flags, desc.TransactionId, packetlen, userlen); *buffer_actual_len = packetlen; @@ -1015,7 +1015,7 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, *requestid = desc.TransactionId; /* Copy over the entire packet to the user buffer */ - ret = RingBufferRead(&channel->Inbound, buffer, packetlen, 0); + ret = ringbuffer_read(&channel->inbound, buffer, packetlen, 0); spin_unlock_irqrestore(&channel->inbound_lock, flags); return 0; @@ -1030,7 +1030,7 @@ void vmbus_onchannel_event(struct vmbus_channel *channel) dump_vmbus_channel(channel); /* ASSERT(Channel->OnChannelCallback); */ - channel->OnChannelCallback(channel->ChannelCallbackContext); + channel->onchannel_callback(channel->channel_callback_context); mod_timer(&channel->poll_timer, jiffies + usecs_to_jiffies(100)); } @@ -1042,8 +1042,8 @@ void vmbus_ontimer(unsigned long data) { struct vmbus_channel *channel = (struct vmbus_channel *)data; - if (channel->OnChannelCallback) - channel->OnChannelCallback(channel->ChannelCallbackContext); + if (channel->onchannel_callback) + channel->onchannel_callback(channel->channel_callback_context); } /* @@ -1051,7 +1051,7 @@ void vmbus_ontimer(unsigned long data) */ static void dump_vmbus_channel(struct vmbus_channel *channel) { - DPRINT_DBG(VMBUS, "Channel (%d)", channel->OfferMsg.ChildRelId); - DumpRingInfo(&channel->Outbound, "Outbound "); - DumpRingInfo(&channel->Inbound, "Inbound "); + DPRINT_DBG(VMBUS, "Channel (%d)", channel->offermsg.child_relid); + dump_ring_info(&channel->outbound, "Outbound "); + dump_ring_info(&channel->inbound, "Inbound "); } diff --git a/drivers/staging/hv/channel_mgmt.c b/drivers/staging/hv/channel_mgmt.c index 45dbe305afed..d44d5c39f68b 100644 --- a/drivers/staging/hv/channel_mgmt.c +++ b/drivers/staging/hv/channel_mgmt.c @@ -251,8 +251,8 @@ static struct vmbus_channel *alloc_channel(void) channel->poll_timer.data = (unsigned long)channel; channel->poll_timer.function = vmbus_ontimer; - channel->ControlWQ = create_workqueue("hv_vmbus_ctl"); - if (!channel->ControlWQ) { + channel->controlwq = create_workqueue("hv_vmbus_ctl"); + if (!channel->controlwq) { kfree(channel); return NULL; } @@ -263,12 +263,14 @@ static struct vmbus_channel *alloc_channel(void) /* * release_hannel - Release the vmbus channel object itself */ -static inline void release_channel(void *context) +static void release_channel(struct work_struct *work) { - struct vmbus_channel *channel = context; + struct vmbus_channel *channel = container_of(work, + struct vmbus_channel, + work); DPRINT_DBG(VMBUS, "releasing channel (%p)", channel); - destroy_workqueue(channel->ControlWQ); + destroy_workqueue(channel->controlwq); DPRINT_DBG(VMBUS, "channel released (%p)", channel); kfree(channel); @@ -286,8 +288,8 @@ void free_channel(struct vmbus_channel *channel) * workqueue/thread context * ie we can't destroy ourselves. */ - osd_schedule_callback(gVmbusConnection.WorkQueue, release_channel, - channel); + INIT_WORK(&channel->work, release_channel); + queue_work(gVmbusConnection.WorkQueue, &channel->work); } @@ -308,29 +310,46 @@ static void count_hv_channel(void) spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); } +/* + * vmbus_process_rescind_offer - + * Rescind the offer by initiating a device removal + */ +static void vmbus_process_rescind_offer(struct work_struct *work) +{ + struct vmbus_channel *channel = container_of(work, + struct vmbus_channel, + work); + + vmbus_child_device_unregister(channel->device_obj); +} /* * vmbus_process_offer - Process the offer by creating a channel/device * associated with this offer */ -static void vmbus_process_offer(void *context) +static void vmbus_process_offer(struct work_struct *work) { - struct vmbus_channel *newchannel = context; + struct vmbus_channel *newchannel = container_of(work, + struct vmbus_channel, + work); struct vmbus_channel *channel; bool fnew = true; int ret; int cnt; unsigned long flags; + /* The next possible work is rescind handling */ + INIT_WORK(&newchannel->work, vmbus_process_rescind_offer); + /* Make sure this is a new offer */ spin_lock_irqsave(&gVmbusConnection.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, &gVmbusConnection.ChannelList, listentry) { + if (!memcmp(&channel->offermsg.offer.InterfaceType, + &newchannel->offermsg.offer.InterfaceType, sizeof(struct hv_guid)) && - !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, - &newchannel->OfferMsg.Offer.InterfaceInstance, + !memcmp(&channel->offermsg.offer.InterfaceInstance, + &newchannel->offermsg.offer.InterfaceInstance, sizeof(struct hv_guid))) { fnew = false; break; @@ -338,14 +357,14 @@ static void vmbus_process_offer(void *context) } if (fnew) - list_add_tail(&newchannel->ListEntry, + list_add_tail(&newchannel->listentry, &gVmbusConnection.ChannelList); spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); if (!fnew) { DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", - newchannel->OfferMsg.ChildRelId); + newchannel->offermsg.child_relid); free_channel(newchannel); return; } @@ -355,27 +374,27 @@ static void vmbus_process_offer(void *context) * We need to set the DeviceObject field before calling * VmbusChildDeviceAdd() */ - newchannel->DeviceObject = VmbusChildDeviceCreate( - &newchannel->OfferMsg.Offer.InterfaceType, - &newchannel->OfferMsg.Offer.InterfaceInstance, + newchannel->device_obj = vmbus_child_device_create( + &newchannel->offermsg.offer.InterfaceType, + &newchannel->offermsg.offer.InterfaceInstance, newchannel); DPRINT_DBG(VMBUS, "child device object allocated - %p", - newchannel->DeviceObject); + newchannel->device_obj); /* * Add the new device to the bus. This will kick off device-driver * binding which eventually invokes the device driver's AddDevice() * method. */ - ret = VmbusChildDeviceAdd(newchannel->DeviceObject); + ret = VmbusChildDeviceAdd(newchannel->device_obj); if (ret != 0) { DPRINT_ERR(VMBUS, "unable to add child device object (relid %d)", - newchannel->OfferMsg.ChildRelId); + newchannel->offermsg.child_relid); spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); - list_del(&newchannel->ListEntry); + list_del(&newchannel->listentry); spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); free_channel(newchannel); @@ -385,11 +404,11 @@ static void vmbus_process_offer(void *context) * so that when we do close the channel normally, we * can cleanup properly */ - newchannel->State = CHANNEL_OPEN_STATE; + newchannel->state = CHANNEL_OPEN_STATE; /* Open IC channels */ for (cnt = 0; cnt < MAX_MSG_TYPES; cnt++) { - if (memcmp(&newchannel->OfferMsg.Offer.InterfaceType, + if (memcmp(&newchannel->offermsg.offer.InterfaceType, &hv_cb_utils[cnt].data, sizeof(struct hv_guid)) == 0 && vmbus_open(newchannel, 2 * PAGE_SIZE, @@ -406,17 +425,6 @@ static void vmbus_process_offer(void *context) } /* - * vmbus_process_rescind_offer - - * Rescind the offer by initiating a device removal - */ -static void vmbus_process_rescind_offer(void *context) -{ - struct vmbus_channel *channel = context; - - VmbusChildDeviceRemove(channel->DeviceObject); -} - -/* * vmbus_onoffer - Handler for channel offers from vmbus in parent partition. * * We ignore all offers except network and storage offers. For each network and @@ -434,7 +442,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.InterfaceType, &gSupportedDeviceClasses[i], sizeof(struct hv_guid)) == 0) { fsupported = 1; break; @@ -443,12 +451,12 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) if (!fsupported) { DPRINT_DBG(VMBUS, "Ignoring channel offer notification for " - "child relid %d", offer->ChildRelId); + "child relid %d", offer->child_relid); return; } - guidtype = &offer->Offer.InterfaceType; - guidinstance = &offer->Offer.InterfaceInstance; + guidtype = &offer->offer.InterfaceType; + guidinstance = &offer->offer.InterfaceInstance; DPRINT_INFO(VMBUS, "Channel offer notification - " "child relid %d monitor id %d allocated %d, " @@ -456,8 +464,8 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) "%02x%02x%02x%02x%02x%02x%02x%02x} " "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x%02x%02x}", - offer->ChildRelId, offer->MonitorId, - offer->MonitorAllocated, + offer->child_relid, offer->monitorid, + offer->monitor_allocated, guidtype->data[3], guidtype->data[2], guidtype->data[1], guidtype->data[0], guidtype->data[5], guidtype->data[4], @@ -484,14 +492,14 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) DPRINT_DBG(VMBUS, "channel object allocated - %p", newchannel); - memcpy(&newchannel->OfferMsg, offer, + memcpy(&newchannel->offermsg, offer, sizeof(struct vmbus_channel_offer_channel)); - newchannel->MonitorGroup = (u8)offer->MonitorId / 32; - newchannel->MonitorBit = (u8)offer->MonitorId % 32; + newchannel->monitor_grp = (u8)offer->monitorid / 32; + newchannel->monitor_bit = (u8)offer->monitorid % 32; /* TODO: Make sure the offer comes from our parent partition */ - osd_schedule_callback(newchannel->ControlWQ, vmbus_process_offer, - newchannel); + INIT_WORK(&newchannel->work, vmbus_process_offer); + queue_work(newchannel->controlwq, &newchannel->work); } /* @@ -505,16 +513,16 @@ 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->ChildRelId); + channel = GetChannelFromRelId(rescind->child_relid); if (channel == NULL) { DPRINT_DBG(VMBUS, "channel not found for relId %d", - rescind->ChildRelId); + rescind->child_relid); return; } - osd_schedule_callback(channel->ControlWQ, - vmbus_process_rescind_offer, - channel); + /* work is initialized for vmbus_process_rescind_offer() from + * vmbus_process_offer() where the channel got created */ + queue_work(channel->controlwq, &channel->work); } /* @@ -545,7 +553,7 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) unsigned long flags; result = (struct vmbus_channel_open_result *)hdr; - DPRINT_DBG(VMBUS, "vmbus open result - %d", result->Status); + DPRINT_DBG(VMBUS, "vmbus open result - %d", result->status); /* * Find the open msg, copy the result and signal/unblock the wait event @@ -556,17 +564,17 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) /* FIXME: this should probably use list_entry() instead */ msginfo = (struct vmbus_channel_msginfo *)curr; requestheader = - (struct vmbus_channel_message_header *)msginfo->Msg; + (struct vmbus_channel_message_header *)msginfo->msg; - if (requestheader->MessageType == ChannelMessageOpenChannel) { + if (requestheader->msgtype == CHANNELMSG_OPENCHANNEL) { openmsg = - (struct vmbus_channel_open_channel *)msginfo->Msg; - if (openmsg->ChildRelId == result->ChildRelId && - openmsg->OpenId == result->OpenId) { - memcpy(&msginfo->Response.OpenResult, + (struct vmbus_channel_open_channel *)msginfo->msg; + if (openmsg->child_relid == result->child_relid && + openmsg->openid == result->openid) { + memcpy(&msginfo->response.open_result, result, sizeof(struct vmbus_channel_open_result)); - osd_WaitEventSet(msginfo->WaitEvent); + osd_waitevent_set(msginfo->waitevent); break; } } @@ -592,7 +600,7 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr; DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", - gpadlcreated->CreationStatus); + gpadlcreated->creation_status); /* * Find the establish msg, copy the result and signal/unblock the wait @@ -604,19 +612,19 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) /* FIXME: this should probably use list_entry() instead */ msginfo = (struct vmbus_channel_msginfo *)curr; requestheader = - (struct vmbus_channel_message_header *)msginfo->Msg; + (struct vmbus_channel_message_header *)msginfo->msg; - if (requestheader->MessageType == ChannelMessageGpadlHeader) { + if (requestheader->msgtype == CHANNELMSG_GPADL_HEADER) { gpadlheader = (struct vmbus_channel_gpadl_header *)requestheader; - if ((gpadlcreated->ChildRelId == - gpadlheader->ChildRelId) && - (gpadlcreated->Gpadl == gpadlheader->Gpadl)) { - memcpy(&msginfo->Response.GpadlCreated, + if ((gpadlcreated->child_relid == + gpadlheader->child_relid) && + (gpadlcreated->gpadl == gpadlheader->gpadl)) { + memcpy(&msginfo->response.gpadl_created, gpadlcreated, sizeof(struct vmbus_channel_gpadl_created)); - osd_WaitEventSet(msginfo->WaitEvent); + osd_waitevent_set(msginfo->waitevent); break; } } @@ -652,17 +660,17 @@ static void vmbus_ongpadl_torndown( /* FIXME: this should probably use list_entry() instead */ msginfo = (struct vmbus_channel_msginfo *)curr; requestheader = - (struct vmbus_channel_message_header *)msginfo->Msg; + (struct vmbus_channel_message_header *)msginfo->msg; - if (requestheader->MessageType == ChannelMessageGpadlTeardown) { + if (requestheader->msgtype == CHANNELMSG_GPADL_TEARDOWN) { gpadl_teardown = (struct vmbus_channel_gpadl_teardown *)requestheader; - if (gpadl_torndown->Gpadl == gpadl_teardown->Gpadl) { - memcpy(&msginfo->Response.GpadlTorndown, + if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) { + memcpy(&msginfo->response.gpadl_torndown, gpadl_torndown, sizeof(struct vmbus_channel_gpadl_torndown)); - osd_WaitEventSet(msginfo->WaitEvent); + osd_waitevent_set(msginfo->waitevent); break; } } @@ -694,16 +702,16 @@ static void vmbus_onversion_response( /* FIXME: this should probably use list_entry() instead */ msginfo = (struct vmbus_channel_msginfo *)curr; requestheader = - (struct vmbus_channel_message_header *)msginfo->Msg; + (struct vmbus_channel_message_header *)msginfo->msg; - if (requestheader->MessageType == - ChannelMessageInitiateContact) { + if (requestheader->msgtype == + CHANNELMSG_INITIATE_CONTACT) { initiate = (struct vmbus_channel_initiate_contact *)requestheader; - memcpy(&msginfo->Response.VersionResponse, + memcpy(&msginfo->response.version_response, version_response, sizeof(struct vmbus_channel_version_response)); - osd_WaitEventSet(msginfo->WaitEvent); + osd_waitevent_set(msginfo->waitevent); } } spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); @@ -711,24 +719,24 @@ static void vmbus_onversion_response( /* Channel message dispatch table */ static struct vmbus_channel_message_table_entry - gChannelMessageTable[ChannelMessageCount] = { - {ChannelMessageInvalid, NULL}, - {ChannelMessageOfferChannel, vmbus_onoffer}, - {ChannelMessageRescindChannelOffer, vmbus_onoffer_rescind}, - {ChannelMessageRequestOffers, NULL}, - {ChannelMessageAllOffersDelivered, vmbus_onoffers_delivered}, - {ChannelMessageOpenChannel, NULL}, - {ChannelMessageOpenChannelResult, vmbus_onopen_result}, - {ChannelMessageCloseChannel, NULL}, - {ChannelMessageGpadlHeader, NULL}, - {ChannelMessageGpadlBody, NULL}, - {ChannelMessageGpadlCreated, vmbus_ongpadl_created}, - {ChannelMessageGpadlTeardown, NULL}, - {ChannelMessageGpadlTorndown, vmbus_ongpadl_torndown}, - {ChannelMessageRelIdReleased, NULL}, - {ChannelMessageInitiateContact, NULL}, - {ChannelMessageVersionResponse, vmbus_onversion_response}, - {ChannelMessageUnload, NULL}, + gChannelMessageTable[CHANNELMSG_COUNT] = { + {CHANNELMSG_INVALID, NULL}, + {CHANNELMSG_OFFERCHANNEL, vmbus_onoffer}, + {CHANNELMSG_RESCIND_CHANNELOFFER, vmbus_onoffer_rescind}, + {CHANNELMSG_REQUESTOFFERS, NULL}, + {CHANNELMSG_ALLOFFERS_DELIVERED, vmbus_onoffers_delivered}, + {CHANNELMSG_OPENCHANNEL, NULL}, + {CHANNELMSG_OPENCHANNEL_RESULT, vmbus_onopen_result}, + {CHANNELMSG_CLOSECHANNEL, NULL}, + {CHANNELMSG_GPADL_HEADER, NULL}, + {CHANNELMSG_GPADL_BODY, NULL}, + {CHANNELMSG_GPADL_CREATED, vmbus_ongpadl_created}, + {CHANNELMSG_GPADL_TEARDOWN, NULL}, + {CHANNELMSG_GPADL_TORNDOWN, vmbus_ongpadl_torndown}, + {CHANNELMSG_RELID_RELEASED, NULL}, + {CHANNELMSG_INITIATE_CONTACT, NULL}, + {CHANNELMSG_VERSION_RESPONSE, vmbus_onversion_response}, + {CHANNELMSG_UNLOAD, NULL}, }; /* @@ -742,29 +750,25 @@ void vmbus_onmessage(void *context) struct vmbus_channel_message_header *hdr; int size; - hdr = (struct vmbus_channel_message_header *)msg->u.Payload; - size = msg->Header.PayloadSize; + hdr = (struct vmbus_channel_message_header *)msg->u.payload; + size = msg->header.payload_size; - DPRINT_DBG(VMBUS, "message type %d size %d", hdr->MessageType, size); + DPRINT_DBG(VMBUS, "message type %d size %d", hdr->msgtype, size); - if (hdr->MessageType >= ChannelMessageCount) { + if (hdr->msgtype >= CHANNELMSG_COUNT) { DPRINT_ERR(VMBUS, "Received invalid channel message type %d size %d", - hdr->MessageType, size); + hdr->msgtype, size); print_hex_dump_bytes("", DUMP_PREFIX_NONE, - (unsigned char *)msg->u.Payload, size); - kfree(msg); + (unsigned char *)msg->u.payload, size); return; } - if (gChannelMessageTable[hdr->MessageType].messageHandler) - gChannelMessageTable[hdr->MessageType].messageHandler(hdr); + if (gChannelMessageTable[hdr->msgtype].messageHandler) + gChannelMessageTable[hdr->msgtype].messageHandler(hdr); else DPRINT_ERR(VMBUS, "Unhandled channel message type %d", - hdr->MessageType); - - /* Free the msg that was allocated in VmbusOnMsgDPC() */ - kfree(msg); + hdr->msgtype); } /* @@ -782,15 +786,15 @@ int vmbus_request_offers(void) if (!msginfo) return -ENOMEM; - msginfo->WaitEvent = osd_WaitEventCreate(); - if (!msginfo->WaitEvent) { + msginfo->waitevent = osd_waitevent_create(); + if (!msginfo->waitevent) { kfree(msginfo); return -ENOMEM; } - msg = (struct vmbus_channel_message_header *)msginfo->Msg; + msg = (struct vmbus_channel_message_header *)msginfo->msg; - msg->MessageType = ChannelMessageRequestOffers; + msg->msgtype = CHANNELMSG_REQUESTOFFERS; /*SpinlockAcquire(gVmbusConnection.channelMsgLock); INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, @@ -808,7 +812,7 @@ int vmbus_request_offers(void) goto Cleanup; } - /* osd_WaitEventWait(msgInfo->waitEvent); */ + /* osd_waitevent_wait(msgInfo->waitEvent); */ /*SpinlockAcquire(gVmbusConnection.channelMsgLock); REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); @@ -817,7 +821,7 @@ int vmbus_request_offers(void) Cleanup: if (msginfo) { - kfree(msginfo->WaitEvent); + kfree(msginfo->waitevent); kfree(msginfo); } @@ -837,17 +841,17 @@ void vmbus_release_unattached_channels(void) spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); list_for_each_entry_safe(channel, pos, &gVmbusConnection.ChannelList, - ListEntry) { + listentry) { if (channel == start) break; - if (!channel->DeviceObject->Driver) { - list_del(&channel->ListEntry); + if (!channel->device_obj->Driver) { + list_del(&channel->listentry); DPRINT_INFO(VMBUS, "Releasing unattached device object %p", - channel->DeviceObject); + channel->device_obj); - VmbusChildDeviceRemove(channel->DeviceObject); + vmbus_child_device_unregister(channel->device_obj); free_channel(channel); } else { if (!start) diff --git a/drivers/staging/hv/channel_mgmt.h b/drivers/staging/hv/channel_mgmt.h index d16cc0811169..de6b2a0ebf70 100644 --- a/drivers/staging/hv/channel_mgmt.h +++ b/drivers/staging/hv/channel_mgmt.h @@ -33,60 +33,60 @@ /* Version 1 messages */ enum vmbus_channel_message_type { - ChannelMessageInvalid = 0, - ChannelMessageOfferChannel = 1, - ChannelMessageRescindChannelOffer = 2, - ChannelMessageRequestOffers = 3, - ChannelMessageAllOffersDelivered = 4, - ChannelMessageOpenChannel = 5, - ChannelMessageOpenChannelResult = 6, - ChannelMessageCloseChannel = 7, - ChannelMessageGpadlHeader = 8, - ChannelMessageGpadlBody = 9, - ChannelMessageGpadlCreated = 10, - ChannelMessageGpadlTeardown = 11, - ChannelMessageGpadlTorndown = 12, - ChannelMessageRelIdReleased = 13, - ChannelMessageInitiateContact = 14, - ChannelMessageVersionResponse = 15, - ChannelMessageUnload = 16, + CHANNELMSG_INVALID = 0, + CHANNELMSG_OFFERCHANNEL = 1, + CHANNELMSG_RESCIND_CHANNELOFFER = 2, + CHANNELMSG_REQUESTOFFERS = 3, + CHANNELMSG_ALLOFFERS_DELIVERED = 4, + CHANNELMSG_OPENCHANNEL = 5, + CHANNELMSG_OPENCHANNEL_RESULT = 6, + CHANNELMSG_CLOSECHANNEL = 7, + CHANNELMSG_GPADL_HEADER = 8, + CHANNELMSG_GPADL_BODY = 9, + CHANNELMSG_GPADL_CREATED = 10, + CHANNELMSG_GPADL_TEARDOWN = 11, + CHANNELMSG_GPADL_TORNDOWN = 12, + CHANNELMSG_RELID_RELEASED = 13, + CHANNELMSG_INITIATE_CONTACT = 14, + CHANNELMSG_VERSION_RESPONSE = 15, + CHANNELMSG_UNLOAD = 16, #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD - ChannelMessageViewRangeAdd = 17, - ChannelMessageViewRangeRemove = 18, + CHANNELMSG_VIEWRANGE_ADD = 17, + CHANNELMSG_VIEWRANGE_REMOVE = 18, #endif - ChannelMessageCount + CHANNELMSG_COUNT }; struct vmbus_channel_message_header { - enum vmbus_channel_message_type MessageType; - u32 Padding; + enum vmbus_channel_message_type msgtype; + u32 padding; } __attribute__((packed)); /* Query VMBus Version parameters */ struct vmbus_channel_query_vmbus_version { - struct vmbus_channel_message_header Header; - u32 Version; + struct vmbus_channel_message_header header; + u32 version; } __attribute__((packed)); /* VMBus Version Supported parameters */ struct vmbus_channel_version_supported { - struct vmbus_channel_message_header Header; - bool VersionSupported; + struct vmbus_channel_message_header header; + bool version_supported; } __attribute__((packed)); /* Offer Channel parameters */ struct vmbus_channel_offer_channel { - struct vmbus_channel_message_header Header; - struct vmbus_channel_offer Offer; - u32 ChildRelId; - u8 MonitorId; - bool MonitorAllocated; + struct vmbus_channel_message_header header; + struct vmbus_channel_offer offer; + u32 child_relid; + u8 monitorid; + bool monitor_allocated; } __attribute__((packed)); /* Rescind Offer parameters */ struct vmbus_channel_rescind_offer { - struct vmbus_channel_message_header Header; - u32 ChildRelId; + struct vmbus_channel_message_header header; + u32 child_relid; } __attribute__((packed)); /* @@ -100,43 +100,43 @@ struct vmbus_channel_rescind_offer { /* Open Channel parameters */ struct vmbus_channel_open_channel { - struct vmbus_channel_message_header Header; + struct vmbus_channel_message_header header; /* Identifies the specific VMBus channel that is being opened. */ - u32 ChildRelId; + u32 child_relid; /* ID making a particular open request at a channel offer unique. */ - u32 OpenId; + u32 openid; /* GPADL for the channel's ring buffer. */ - u32 RingBufferGpadlHandle; + u32 ringbuffer_gpadlhandle; /* GPADL for the channel's server context save area. */ - u32 ServerContextAreaGpadlHandle; + u32 server_contextarea_gpadlhandle; /* * The upstream ring buffer begins at offset zero in the memory * described by RingBufferGpadlHandle. The downstream ring buffer * follows it at this offset (in pages). */ - u32 DownstreamRingBufferPageOffset; + u32 downstream_ringbuffer_pageoffset; /* User-specific data to be passed along to the server endpoint. */ - unsigned char UserData[MAX_USER_DEFINED_BYTES]; + unsigned char userdata[MAX_USER_DEFINED_BYTES]; } __attribute__((packed)); /* Open Channel Result parameters */ struct vmbus_channel_open_result { - struct vmbus_channel_message_header Header; - u32 ChildRelId; - u32 OpenId; - u32 Status; + struct vmbus_channel_message_header header; + u32 child_relid; + u32 openid; + u32 status; } __attribute__((packed)); /* Close channel parameters; */ struct vmbus_channel_close_channel { - struct vmbus_channel_message_header Header; - u32 ChildRelId; + struct vmbus_channel_message_header header; + u32 child_relid; } __attribute__((packed)); /* Channel Message GPADL */ @@ -151,72 +151,72 @@ struct vmbus_channel_close_channel { * follow-up packet that contains more. */ struct vmbus_channel_gpadl_header { - struct vmbus_channel_message_header Header; - u32 ChildRelId; - u32 Gpadl; - u16 RangeBufLen; - u16 RangeCount; - struct gpa_range Range[0]; + struct vmbus_channel_message_header header; + u32 child_relid; + u32 gpadl; + u16 range_buflen; + u16 rangecount; + struct gpa_range range[0]; } __attribute__((packed)); /* This is the followup packet that contains more PFNs. */ struct vmbus_channel_gpadl_body { - struct vmbus_channel_message_header Header; - u32 MessageNumber; - u32 Gpadl; - u64 Pfn[0]; + struct vmbus_channel_message_header header; + u32 msgnumber; + u32 gpadl; + u64 pfn[0]; } __attribute__((packed)); struct vmbus_channel_gpadl_created { - struct vmbus_channel_message_header Header; - u32 ChildRelId; - u32 Gpadl; - u32 CreationStatus; + struct vmbus_channel_message_header header; + u32 child_relid; + u32 gpadl; + u32 creation_status; } __attribute__((packed)); struct vmbus_channel_gpadl_teardown { - struct vmbus_channel_message_header Header; - u32 ChildRelId; - u32 Gpadl; + struct vmbus_channel_message_header header; + u32 child_relid; + u32 gpadl; } __attribute__((packed)); struct vmbus_channel_gpadl_torndown { - struct vmbus_channel_message_header Header; - u32 Gpadl; + struct vmbus_channel_message_header header; + u32 gpadl; } __attribute__((packed)); #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD struct vmbus_channel_view_range_add { - struct vmbus_channel_message_header Header; - PHYSICAL_ADDRESS ViewRangeBase; - u64 ViewRangeLength; - u32 ChildRelId; + struct vmbus_channel_message_header header; + PHYSICAL_ADDRESS viewrange_base; + u64 viewrange_length; + u32 child_relid; } __attribute__((packed)); struct vmbus_channel_view_range_remove { - struct vmbus_channel_message_header Header; - PHYSICAL_ADDRESS ViewRangeBase; - u32 ChildRelId; + struct vmbus_channel_message_header header; + PHYSICAL_ADDRESS viewrange_base; + u32 child_relid; } __attribute__((packed)); #endif struct vmbus_channel_relid_released { - struct vmbus_channel_message_header Header; - u32 ChildRelId; + struct vmbus_channel_message_header header; + u32 child_relid; } __attribute__((packed)); struct vmbus_channel_initiate_contact { - struct vmbus_channel_message_header Header; - u32 VMBusVersionRequested; - u32 Padding2; - u64 InterruptPage; - u64 MonitorPage1; - u64 MonitorPage2; + struct vmbus_channel_message_header header; + u32 vmbus_version_requested; + u32 padding2; + u64 interrupt_page; + u64 monitor_page1; + u64 monitor_page2; } __attribute__((packed)); struct vmbus_channel_version_response { - struct vmbus_channel_message_header Header; - bool VersionSupported; + struct vmbus_channel_message_header header; + bool version_supported; } __attribute__((packed)); enum vmbus_channel_state { @@ -226,54 +226,55 @@ enum vmbus_channel_state { }; struct vmbus_channel { - struct list_head ListEntry; + struct list_head listentry; - struct hv_device *DeviceObject; + struct hv_device *device_obj; struct timer_list poll_timer; /* SA-111 workaround */ + struct work_struct work; - enum vmbus_channel_state State; + enum vmbus_channel_state state; - struct vmbus_channel_offer_channel OfferMsg; + struct vmbus_channel_offer_channel offermsg; /* * These are based on the OfferMsg.MonitorId. * Save it here for easy access. */ - u8 MonitorGroup; - u8 MonitorBit; + u8 monitor_grp; + u8 monitor_bit; - u32 RingBufferGpadlHandle; + u32 ringbuffer_gpadlhandle; /* Allocated memory for ring buffer */ - void *RingBufferPages; - u32 RingBufferPageCount; - struct hv_ring_buffer_info Outbound; /* send to parent */ - struct hv_ring_buffer_info Inbound; /* receive from parent */ + void *ringbuffer_pages; + u32 ringbuffer_pagecount; + struct hv_ring_buffer_info outbound; /* send to parent */ + struct hv_ring_buffer_info inbound; /* receive from parent */ spinlock_t inbound_lock; - struct workqueue_struct *ControlWQ; + struct workqueue_struct *controlwq; /* Channel callback are invoked in this workqueue context */ /* HANDLE dataWorkQueue; */ - void (*OnChannelCallback)(void *context); - void *ChannelCallbackContext; + void (*onchannel_callback)(void *context); + void *channel_callback_context; }; struct vmbus_channel_debug_info { - u32 RelId; - enum vmbus_channel_state State; - struct hv_guid InterfaceType; - struct hv_guid InterfaceInstance; - u32 MonitorId; - u32 ServerMonitorPending; - u32 ServerMonitorLatency; - u32 ServerMonitorConnectionId; - u32 ClientMonitorPending; - u32 ClientMonitorLatency; - u32 ClientMonitorConnectionId; - - struct hv_ring_buffer_debug_info Inbound; - struct hv_ring_buffer_debug_info Outbound; + u32 relid; + enum vmbus_channel_state state; + struct hv_guid interfacetype; + struct hv_guid interface_instance; + u32 monitorid; + u32 servermonitor_pending; + u32 servermonitor_latency; + u32 servermonitor_connectionid; + u32 clientmonitor_pending; + u32 clientmonitor_latency; + u32 clientmonitor_connectionid; + + struct hv_ring_buffer_debug_info inbound; + struct hv_ring_buffer_debug_info outbound; }; /* @@ -282,28 +283,28 @@ struct vmbus_channel_debug_info { */ struct vmbus_channel_msginfo { /* Bookkeeping stuff */ - struct list_head MsgListEntry; + struct list_head msglistentry; /* So far, this is only used to handle gpadl body message */ - struct list_head SubMsgList; + struct list_head submsglist; /* Synchronize the request/response if needed */ - struct osd_waitevent *WaitEvent; + struct osd_waitevent *waitevent; union { - struct vmbus_channel_version_supported VersionSupported; - struct vmbus_channel_open_result OpenResult; - struct vmbus_channel_gpadl_torndown GpadlTorndown; - struct vmbus_channel_gpadl_created GpadlCreated; - struct vmbus_channel_version_response VersionResponse; - } Response; - - u32 MessageSize; + struct vmbus_channel_version_supported version_supported; + struct vmbus_channel_open_result open_result; + struct vmbus_channel_gpadl_torndown gpadl_torndown; + struct vmbus_channel_gpadl_created gpadl_created; + struct vmbus_channel_version_response version_response; + } response; + + u32 msgsize; /* * The channel message that goes out on the "wire". * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header */ - unsigned char Msg[0]; + unsigned char msg[0]; }; diff --git a/drivers/staging/hv/connection.c b/drivers/staging/hv/connection.c index f8477072ace4..c2e298ff4834 100644 --- a/drivers/staging/hv/connection.c +++ b/drivers/staging/hv/connection.c @@ -66,7 +66,7 @@ int VmbusConnect(void) * Setup the vmbus event connection for channel interrupt * abstraction stuff */ - gVmbusConnection.InterruptPage = osd_PageAlloc(1); + gVmbusConnection.InterruptPage = osd_page_alloc(1); if (gVmbusConnection.InterruptPage == NULL) { ret = -1; goto Cleanup; @@ -81,7 +81,7 @@ int VmbusConnect(void) * Setup the monitor notification facility. The 1st page for * parent->child and the 2nd page for child->parent */ - gVmbusConnection.MonitorPages = osd_PageAlloc(2); + gVmbusConnection.MonitorPages = osd_page_alloc(2); if (gVmbusConnection.MonitorPages == NULL) { ret = -1; goto Cleanup; @@ -95,19 +95,19 @@ int VmbusConnect(void) goto Cleanup; } - msgInfo->WaitEvent = osd_WaitEventCreate(); - if (!msgInfo->WaitEvent) { + msgInfo->waitevent = osd_waitevent_create(); + if (!msgInfo->waitevent) { ret = -ENOMEM; goto Cleanup; } - msg = (struct vmbus_channel_initiate_contact *)msgInfo->Msg; + msg = (struct vmbus_channel_initiate_contact *)msgInfo->msg; - msg->Header.MessageType = ChannelMessageInitiateContact; - msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER; - msg->InterruptPage = virt_to_phys(gVmbusConnection.InterruptPage); - msg->MonitorPage1 = virt_to_phys(gVmbusConnection.MonitorPages); - msg->MonitorPage2 = virt_to_phys( + 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->monitor_page2 = virt_to_phys( (void *)((unsigned long)gVmbusConnection.MonitorPages + PAGE_SIZE)); @@ -116,30 +116,30 @@ int VmbusConnect(void) * receive the response before returning from this routine */ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - list_add_tail(&msgInfo->MsgListEntry, + list_add_tail(&msgInfo->msglistentry, &gVmbusConnection.ChannelMsgList); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, " "monitor1 pfn %llx,, monitor2 pfn %llx", - msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2); + msg->interrupt_page, msg->monitor_page1, msg->monitor_page2); DPRINT_DBG(VMBUS, "Sending channel initiate msg..."); ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_initiate_contact)); if (ret != 0) { - list_del(&msgInfo->MsgListEntry); + list_del(&msgInfo->msglistentry); goto Cleanup; } /* Wait for the connection response */ - osd_WaitEventWait(msgInfo->WaitEvent); + osd_waitevent_wait(msgInfo->waitevent); - list_del(&msgInfo->MsgListEntry); + list_del(&msgInfo->msglistentry); /* Check if successful */ - if (msgInfo->Response.VersionResponse.VersionSupported) { + if (msgInfo->response.version_response.version_supported) { DPRINT_INFO(VMBUS, "Vmbus connected!!"); gVmbusConnection.ConnectState = Connected; @@ -151,7 +151,7 @@ int VmbusConnect(void) goto Cleanup; } - kfree(msgInfo->WaitEvent); + kfree(msgInfo->waitevent); kfree(msgInfo); return 0; @@ -162,17 +162,17 @@ Cleanup: destroy_workqueue(gVmbusConnection.WorkQueue); if (gVmbusConnection.InterruptPage) { - osd_PageFree(gVmbusConnection.InterruptPage, 1); + osd_page_free(gVmbusConnection.InterruptPage, 1); gVmbusConnection.InterruptPage = NULL; } if (gVmbusConnection.MonitorPages) { - osd_PageFree(gVmbusConnection.MonitorPages, 2); + osd_page_free(gVmbusConnection.MonitorPages, 2); gVmbusConnection.MonitorPages = NULL; } if (msgInfo) { - kfree(msgInfo->WaitEvent); + kfree(msgInfo->waitevent); kfree(msgInfo); } @@ -195,14 +195,14 @@ int VmbusDisconnect(void) if (!msg) return -ENOMEM; - msg->MessageType = ChannelMessageUnload; + msg->msgtype = CHANNELMSG_UNLOAD; ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_message_header)); if (ret != 0) goto Cleanup; - osd_PageFree(gVmbusConnection.InterruptPage, 1); + osd_page_free(gVmbusConnection.InterruptPage, 1); /* TODO: iterate thru the msg list and free up */ destroy_workqueue(gVmbusConnection.WorkQueue); @@ -226,8 +226,8 @@ struct vmbus_channel *GetChannelFromRelId(u32 relId) unsigned long flags; spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); - list_for_each_entry(channel, &gVmbusConnection.ChannelList, ListEntry) { - if (channel->OfferMsg.ChildRelId == relId) { + list_for_each_entry(channel, &gVmbusConnection.ChannelList, listentry) { + if (channel->offermsg.child_relid == relId) { foundChannel = channel; break; } @@ -309,9 +309,9 @@ int VmbusPostMessage(void *buffer, size_t bufferLen) { union hv_connection_id connId; - connId.Asu32 = 0; - connId.u.Id = VMBUS_MESSAGE_CONNECTION_ID; - return HvPostMessage(connId, 1, buffer, bufferLen); + connId.asu32 = 0; + connId.u.id = VMBUS_MESSAGE_CONNECTION_ID; + return hv_post_message(connId, 1, buffer, bufferLen); } /* @@ -324,5 +324,5 @@ int VmbusSetEvent(u32 childRelId) (unsigned long *)gVmbusConnection.SendInterruptPage + (childRelId >> 5)); - return HvSignalEvent(); + return hv_signal_event(); } diff --git a/drivers/staging/hv/hv.c b/drivers/staging/hv/hv.c index 86b1ddd90404..a34d713d9c57 100644 --- a/drivers/staging/hv/hv.c +++ b/drivers/staging/hv/hv.c @@ -28,17 +28,18 @@ #include "vmbus_private.h" /* The one and only */ -struct hv_context gHvContext = { - .SynICInitialized = false, - .HypercallPage = NULL, - .SignalEventParam = NULL, - .SignalEventBuffer = NULL, +struct hv_context hv_context = { + .synic_initialized = false, + .hypercall_page = NULL, + .signal_event_param = NULL, + .signal_event_buffer = NULL, }; /* - * HvQueryHypervisorPresence - Query the cpuid for presense of windows hypervisor + * query_hypervisor_presence + * - Query the cpuid for presense of windows hypervisor */ -static int HvQueryHypervisorPresence(void) +static int query_hypervisor_presence(void) { unsigned int eax; unsigned int ebx; @@ -50,22 +51,22 @@ static int HvQueryHypervisorPresence(void) ebx = 0; ecx = 0; edx = 0; - op = HvCpuIdFunctionVersionAndFeatures; + op = HVCPUID_VERSION_FEATURES; cpuid(op, &eax, &ebx, &ecx, &edx); return ecx & HV_PRESENT_BIT; } /* - * HvQueryHypervisorInfo - Get version info of the windows hypervisor + * query_hypervisor_info - Get version info of the windows hypervisor */ -static int HvQueryHypervisorInfo(void) +static int query_hypervisor_info(void) { unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx; - unsigned int maxLeaf; + unsigned int max_leaf; unsigned int op; /* @@ -76,7 +77,7 @@ static int HvQueryHypervisorInfo(void) ebx = 0; ecx = 0; edx = 0; - op = HvCpuIdFunctionHvVendorAndMaxFunction; + op = HVCPUID_VENDOR_MAXFUNCTION; cpuid(op, &eax, &ebx, &ecx, &edx); DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c", @@ -93,12 +94,12 @@ static int HvQueryHypervisorInfo(void) ((edx >> 16) & 0xFF), ((edx >> 24) & 0xFF)); - maxLeaf = eax; + max_leaf = eax; eax = 0; ebx = 0; ecx = 0; edx = 0; - op = HvCpuIdFunctionHvInterface; + op = HVCPUID_INTERFACE; cpuid(op, &eax, &ebx, &ecx, &edx); DPRINT_INFO(VMBUS, "Interface ID: %c%c%c%c", @@ -107,12 +108,12 @@ static int HvQueryHypervisorInfo(void) ((eax >> 16) & 0xFF), ((eax >> 24) & 0xFF)); - if (maxLeaf >= HvCpuIdFunctionMsHvVersion) { + if (max_leaf >= HVCPUID_VERSION) { eax = 0; ebx = 0; ecx = 0; edx = 0; - op = HvCpuIdFunctionMsHvVersion; + op = HVCPUID_VERSION; cpuid(op, &eax, &ebx, &ecx, &edx); DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d",\ eax, @@ -122,80 +123,81 @@ static int HvQueryHypervisorInfo(void) edx >> 24, edx & 0xFFFFFF); } - return maxLeaf; + return max_leaf; } /* - * HvDoHypercall - Invoke the specified hypercall + * do_hypercall- Invoke the specified hypercall */ -static u64 HvDoHypercall(u64 Control, void *Input, void *Output) +static u64 do_hypercall(u64 control, void *input, void *output) { #ifdef CONFIG_X86_64 - u64 hvStatus = 0; - u64 inputAddress = (Input) ? virt_to_phys(Input) : 0; - u64 outputAddress = (Output) ? virt_to_phys(Output) : 0; - volatile void *hypercallPage = gHvContext.HypercallPage; + u64 hv_status = 0; + u64 input_address = (input) ? virt_to_phys(input) : 0; + u64 output_address = (output) ? virt_to_phys(output) : 0; + volatile void *hypercall_page = hv_context.hypercall_page; DPRINT_DBG(VMBUS, "Hypercall <control %llx input phys %llx virt %p " "output phys %llx virt %p hypercall %p>", - Control, inputAddress, Input, - outputAddress, Output, hypercallPage); + control, input_address, input, + output_address, output, hypercall_page); - __asm__ __volatile__("mov %0, %%r8" : : "r" (outputAddress) : "r8"); - __asm__ __volatile__("call *%3" : "=a" (hvStatus) : - "c" (Control), "d" (inputAddress), - "m" (hypercallPage)); + __asm__ __volatile__("mov %0, %%r8" : : "r" (output_address) : "r8"); + __asm__ __volatile__("call *%3" : "=a" (hv_status) : + "c" (control), "d" (input_address), + "m" (hypercall_page)); - DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hvStatus); + DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hv_status); - return hvStatus; + return hv_status; #else - u32 controlHi = Control >> 32; - u32 controlLo = Control & 0xFFFFFFFF; - u32 hvStatusHi = 1; - u32 hvStatusLo = 1; - u64 inputAddress = (Input) ? virt_to_phys(Input) : 0; - u32 inputAddressHi = inputAddress >> 32; - u32 inputAddressLo = inputAddress & 0xFFFFFFFF; - u64 outputAddress = (Output) ? virt_to_phys(Output) : 0; - u32 outputAddressHi = outputAddress >> 32; - u32 outputAddressLo = outputAddress & 0xFFFFFFFF; - volatile void *hypercallPage = gHvContext.HypercallPage; + u32 control_hi = control >> 32; + u32 control_lo = control & 0xFFFFFFFF; + u32 hv_status_hi = 1; + u32 hv_status_lo = 1; + u64 input_address = (input) ? virt_to_phys(input) : 0; + u32 input_address_hi = input_address >> 32; + u32 input_address_lo = input_address & 0xFFFFFFFF; + u64 output_address = (output) ? virt_to_phys(output) : 0; + u32 output_address_hi = output_address >> 32; + u32 output_address_lo = output_address & 0xFFFFFFFF; + volatile void *hypercall_page = hv_context.hypercall_page; DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>", - Control, Input, Output); + control, input, output); - __asm__ __volatile__ ("call *%8" : "=d"(hvStatusHi), - "=a"(hvStatusLo) : "d" (controlHi), - "a" (controlLo), "b" (inputAddressHi), - "c" (inputAddressLo), "D"(outputAddressHi), - "S"(outputAddressLo), "m" (hypercallPage)); + __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi), + "=a"(hv_status_lo) : "d" (control_hi), + "a" (control_lo), "b" (input_address_hi), + "c" (input_address_lo), "D"(output_address_hi), + "S"(output_address_lo), "m" (hypercall_page)); DPRINT_DBG(VMBUS, "Hypercall <return %llx>", - hvStatusLo | ((u64)hvStatusHi << 32)); + hv_status_lo | ((u64)hv_status_hi << 32)); - return hvStatusLo | ((u64)hvStatusHi << 32); + return hv_status_lo | ((u64)hv_status_hi << 32); #endif /* !x86_64 */ } /* - * HvInit - Main initialization routine. + * hv_init - Main initialization routine. * * This routine must be called before any other routines in here are called */ -int HvInit(void) +int hv_init(void) { int ret = 0; - int maxLeaf; - union hv_x64_msr_hypercall_contents hypercallMsr; - void *virtAddr = NULL; + int max_leaf; + union hv_x64_msr_hypercall_contents hypercall_msr; + void *virtaddr = NULL; - memset(gHvContext.synICEventPage, 0, sizeof(void *) * MAX_NUM_CPUS); - memset(gHvContext.synICMessagePage, 0, sizeof(void *) * MAX_NUM_CPUS); + memset(hv_context.synic_event_page, 0, sizeof(void *) * MAX_NUM_CPUS); + memset(hv_context.synic_message_page, 0, + sizeof(void *) * MAX_NUM_CPUS); - if (!HvQueryHypervisorPresence()) { + if (!query_hypervisor_presence()) { DPRINT_ERR(VMBUS, "No Windows hypervisor detected!!"); goto Cleanup; } @@ -203,146 +205,148 @@ int HvInit(void) DPRINT_INFO(VMBUS, "Windows hypervisor detected! Retrieving more info..."); - maxLeaf = HvQueryHypervisorInfo(); + max_leaf = query_hypervisor_info(); /* HvQueryHypervisorFeatures(maxLeaf); */ /* * We only support running on top of Hyper-V */ - rdmsrl(HV_X64_MSR_GUEST_OS_ID, gHvContext.GuestId); + rdmsrl(HV_X64_MSR_GUEST_OS_ID, hv_context.guestid); - if (gHvContext.GuestId != 0) { + if (hv_context.guestid != 0) { DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!", - gHvContext.GuestId); + hv_context.guestid); goto Cleanup; } /* Write our OS info */ wrmsrl(HV_X64_MSR_GUEST_OS_ID, HV_LINUX_GUEST_ID); - gHvContext.GuestId = HV_LINUX_GUEST_ID; + hv_context.guestid = HV_LINUX_GUEST_ID; /* See if the hypercall page is already set */ - rdmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); /* * Allocate the hypercall page memory - * virtAddr = osd_PageAlloc(1); + * virtaddr = osd_page_alloc(1); */ - virtAddr = osd_VirtualAllocExec(PAGE_SIZE); + virtaddr = osd_virtual_alloc_exec(PAGE_SIZE); - if (!virtAddr) { + if (!virtaddr) { DPRINT_ERR(VMBUS, "unable to allocate hypercall page!!"); goto Cleanup; } - hypercallMsr.Enable = 1; + hypercall_msr.enable = 1; - hypercallMsr.GuestPhysicalAddress = vmalloc_to_pfn(virtAddr); - wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); + hypercall_msr.guest_physical_address = vmalloc_to_pfn(virtaddr); + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); /* Confirm that hypercall page did get setup. */ - hypercallMsr.AsUINT64 = 0; - rdmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); + hypercall_msr.as_uint64 = 0; + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); - if (!hypercallMsr.Enable) { + if (!hypercall_msr.enable) { DPRINT_ERR(VMBUS, "unable to set hypercall page!!"); goto Cleanup; } - gHvContext.HypercallPage = virtAddr; + hv_context.hypercall_page = virtaddr; DPRINT_INFO(VMBUS, "Hypercall page VA=%p, PA=0x%0llx", - gHvContext.HypercallPage, - (u64)hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT); + hv_context.hypercall_page, + (u64)hypercall_msr.guest_physical_address << PAGE_SHIFT); /* Setup the global signal event param for the signal event hypercall */ - gHvContext.SignalEventBuffer = + hv_context.signal_event_buffer = kmalloc(sizeof(struct hv_input_signal_event_buffer), GFP_KERNEL); - if (!gHvContext.SignalEventBuffer) + if (!hv_context.signal_event_buffer) goto Cleanup; - gHvContext.SignalEventParam = + hv_context.signal_event_param = (struct hv_input_signal_event *) - (ALIGN_UP((unsigned long)gHvContext.SignalEventBuffer, + (ALIGN_UP((unsigned long) + hv_context.signal_event_buffer, HV_HYPERCALL_PARAM_ALIGN)); - gHvContext.SignalEventParam->ConnectionId.Asu32 = 0; - gHvContext.SignalEventParam->ConnectionId.u.Id = + hv_context.signal_event_param->connectionid.asu32 = 0; + hv_context.signal_event_param->connectionid.u.id = VMBUS_EVENT_CONNECTION_ID; - gHvContext.SignalEventParam->FlagNumber = 0; - gHvContext.SignalEventParam->RsvdZ = 0; + hv_context.signal_event_param->flag_number = 0; + hv_context.signal_event_param->rsvdz = 0; return ret; Cleanup: - if (virtAddr) { - if (hypercallMsr.Enable) { - hypercallMsr.AsUINT64 = 0; - wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); + if (virtaddr) { + if (hypercall_msr.enable) { + hypercall_msr.as_uint64 = 0; + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); } - vfree(virtAddr); + vfree(virtaddr); } ret = -1; return ret; } /* - * HvCleanup - Cleanup routine. + * hv_cleanup - Cleanup routine. * * This routine is called normally during driver unloading or exiting. */ -void HvCleanup(void) +void hv_cleanup(void) { - union hv_x64_msr_hypercall_contents hypercallMsr; + union hv_x64_msr_hypercall_contents hypercall_msr; - kfree(gHvContext.SignalEventBuffer); - gHvContext.SignalEventBuffer = NULL; - gHvContext.SignalEventParam = NULL; + kfree(hv_context.signal_event_buffer); + hv_context.signal_event_buffer = NULL; + hv_context.signal_event_param = NULL; - if (gHvContext.HypercallPage) { - hypercallMsr.AsUINT64 = 0; - wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); - vfree(gHvContext.HypercallPage); - gHvContext.HypercallPage = NULL; + if (hv_context.hypercall_page) { + hypercall_msr.as_uint64 = 0; + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + vfree(hv_context.hypercall_page); + hv_context.hypercall_page = NULL; } } /* - * HvPostMessage - Post a message using the hypervisor message IPC. + * hv_post_message - Post a message using the hypervisor message IPC. * * This involves a hypercall. */ -u16 HvPostMessage(union hv_connection_id connectionId, - enum hv_message_type messageType, - void *payload, size_t payloadSize) +u16 hv_post_message(union hv_connection_id connection_id, + enum hv_message_type message_type, + void *payload, size_t payload_size) { - struct alignedInput { + struct aligned_input { u64 alignment8; struct hv_input_post_message msg; }; - struct hv_input_post_message *alignedMsg; + struct hv_input_post_message *aligned_msg; u16 status; unsigned long addr; - if (payloadSize > HV_MESSAGE_PAYLOAD_BYTE_COUNT) + if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT) return -1; - addr = (unsigned long)kmalloc(sizeof(struct alignedInput), GFP_ATOMIC); + addr = (unsigned long)kmalloc(sizeof(struct aligned_input), GFP_ATOMIC); if (!addr) return -1; - alignedMsg = (struct hv_input_post_message *) + aligned_msg = (struct hv_input_post_message *) (ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN)); - alignedMsg->ConnectionId = connectionId; - alignedMsg->MessageType = messageType; - alignedMsg->PayloadSize = payloadSize; - memcpy((void *)alignedMsg->Payload, payload, payloadSize); + aligned_msg->connectionid = connection_id; + aligned_msg->message_type = message_type; + aligned_msg->payload_size = payload_size; + memcpy((void *)aligned_msg->payload, payload, payload_size); - status = HvDoHypercall(HvCallPostMessage, alignedMsg, NULL) & 0xFFFF; + status = do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL) + & 0xFFFF; kfree((void *)addr); @@ -351,38 +355,40 @@ u16 HvPostMessage(union hv_connection_id connectionId, /* - * HvSignalEvent - Signal an event on the specified connection using the hypervisor event IPC. + * hv_signal_event - + * Signal an event on the specified connection using the hypervisor event IPC. * * This involves a hypercall. */ -u16 HvSignalEvent(void) +u16 hv_signal_event(void) { u16 status; - status = HvDoHypercall(HvCallSignalEvent, gHvContext.SignalEventParam, + status = do_hypercall(HVCALL_SIGNAL_EVENT, + hv_context.signal_event_param, NULL) & 0xFFFF; return status; } /* - * HvSynicInit - Initialize the Synthethic Interrupt Controller. + * hv_synic_init - Initialize the Synthethic Interrupt Controller. * * If it is already initialized by another entity (ie x2v shim), we need to * retrieve the initialized message and event pages. Otherwise, we create and * initialize the message and event pages. */ -void HvSynicInit(void *irqarg) +void hv_synic_init(void *irqarg) { u64 version; union hv_synic_simp simp; union hv_synic_siefp siefp; - union hv_synic_sint sharedSint; + union hv_synic_sint shared_sint; union hv_synic_scontrol sctrl; - u32 irqVector = *((u32 *)(irqarg)); + u32 irq_vector = *((u32 *)(irqarg)); int cpu = smp_processor_id(); - if (!gHvContext.HypercallPage) + if (!hv_context.hypercall_page) return; /* Check the version */ @@ -390,110 +396,112 @@ void HvSynicInit(void *irqarg) DPRINT_INFO(VMBUS, "SynIC version: %llx", version); - gHvContext.synICMessagePage[cpu] = (void *)get_zeroed_page(GFP_ATOMIC); + hv_context.synic_message_page[cpu] = + (void *)get_zeroed_page(GFP_ATOMIC); - if (gHvContext.synICMessagePage[cpu] == NULL) { + if (hv_context.synic_message_page[cpu] == NULL) { DPRINT_ERR(VMBUS, "unable to allocate SYNIC message page!!"); goto Cleanup; } - gHvContext.synICEventPage[cpu] = (void *)get_zeroed_page(GFP_ATOMIC); + hv_context.synic_event_page[cpu] = + (void *)get_zeroed_page(GFP_ATOMIC); - if (gHvContext.synICEventPage[cpu] == NULL) { + if (hv_context.synic_event_page[cpu] == NULL) { DPRINT_ERR(VMBUS, "unable to allocate SYNIC event page!!"); goto Cleanup; } /* Setup the Synic's message page */ - rdmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); - simp.SimpEnabled = 1; - simp.BaseSimpGpa = virt_to_phys(gHvContext.synICMessagePage[cpu]) + rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64); + simp.simp_enabled = 1; + simp.base_simp_gpa = virt_to_phys(hv_context.synic_message_page[cpu]) >> PAGE_SHIFT; - DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", simp.AsUINT64); + DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", simp.as_uint64); - wrmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); + wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64); /* Setup the Synic's event page */ - rdmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); - siefp.SiefpEnabled = 1; - siefp.BaseSiefpGpa = virt_to_phys(gHvContext.synICEventPage[cpu]) + rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); + siefp.siefp_enabled = 1; + siefp.base_siefp_gpa = virt_to_phys(hv_context.synic_event_page[cpu]) >> PAGE_SHIFT; - DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", siefp.AsUINT64); + DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", siefp.as_uint64); - wrmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); + wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); /* Setup the interception SINT. */ /* wrmsrl((HV_X64_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX), */ - /* interceptionSint.AsUINT64); */ + /* interceptionSint.as_uint64); */ /* Setup the shared SINT. */ - rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); + rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); - sharedSint.AsUINT64 = 0; - sharedSint.Vector = irqVector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */ - sharedSint.Masked = false; - sharedSint.AutoEoi = true; + shared_sint.as_uint64 = 0; + shared_sint.vector = irq_vector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */ + shared_sint.masked = false; + shared_sint.auto_eoi = true; DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", - sharedSint.AsUINT64); + shared_sint.as_uint64); - wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); + wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); /* Enable the global synic bit */ - rdmsrl(HV_X64_MSR_SCONTROL, sctrl.AsUINT64); - sctrl.Enable = 1; + rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); + sctrl.enable = 1; - wrmsrl(HV_X64_MSR_SCONTROL, sctrl.AsUINT64); + wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); - gHvContext.SynICInitialized = true; + hv_context.synic_initialized = true; return; Cleanup: - if (gHvContext.synICEventPage[cpu]) - osd_PageFree(gHvContext.synICEventPage[cpu], 1); + if (hv_context.synic_event_page[cpu]) + osd_page_free(hv_context.synic_event_page[cpu], 1); - if (gHvContext.synICMessagePage[cpu]) - osd_PageFree(gHvContext.synICMessagePage[cpu], 1); + if (hv_context.synic_message_page[cpu]) + osd_page_free(hv_context.synic_message_page[cpu], 1); return; } /* - * HvSynicCleanup - Cleanup routine for HvSynicInit(). + * hv_synic_cleanup - Cleanup routine for hv_synic_init(). */ -void HvSynicCleanup(void *arg) +void hv_synic_cleanup(void *arg) { - union hv_synic_sint sharedSint; + union hv_synic_sint shared_sint; union hv_synic_simp simp; union hv_synic_siefp siefp; int cpu = smp_processor_id(); - if (!gHvContext.SynICInitialized) + if (!hv_context.synic_initialized) return; - rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); + rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); - sharedSint.Masked = 1; + shared_sint.masked = 1; /* Need to correctly cleanup in the case of SMP!!! */ /* Disable the interrupt */ - wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); + wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); - rdmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); - simp.SimpEnabled = 0; - simp.BaseSimpGpa = 0; + rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64); + simp.simp_enabled = 0; + simp.base_simp_gpa = 0; - wrmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); + wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64); - rdmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); - siefp.SiefpEnabled = 0; - siefp.BaseSiefpGpa = 0; + rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); + siefp.siefp_enabled = 0; + siefp.base_siefp_gpa = 0; - wrmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); + wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); - osd_PageFree(gHvContext.synICMessagePage[cpu], 1); - osd_PageFree(gHvContext.synICEventPage[cpu], 1); + osd_page_free(hv_context.synic_message_page[cpu], 1); + osd_page_free(hv_context.synic_event_page[cpu], 1); } diff --git a/drivers/staging/hv/hv.h b/drivers/staging/hv/hv.h index 41f5ebb86e17..829aff81bb30 100644 --- a/drivers/staging/hv/hv.h +++ b/drivers/staging/hv/hv.h @@ -92,49 +92,49 @@ static const struct hv_guid VMBUS_SERVICE_ID = { struct hv_input_signal_event_buffer { - u64 Align8; - struct hv_input_signal_event Event; + u64 align8; + struct hv_input_signal_event event; }; struct hv_context { /* We only support running on top of Hyper-V * So at this point this really can only contain the Hyper-V ID */ - u64 GuestId; + u64 guestid; - void *HypercallPage; + void *hypercall_page; - bool SynICInitialized; + bool synic_initialized; /* * This is used as an input param to HvCallSignalEvent hypercall. The * input param is immutable in our usage and must be dynamic mem (vs * stack or global). */ - struct hv_input_signal_event_buffer *SignalEventBuffer; + struct hv_input_signal_event_buffer *signal_event_buffer; /* 8-bytes aligned of the buffer above */ - struct hv_input_signal_event *SignalEventParam; + struct hv_input_signal_event *signal_event_param; - void *synICMessagePage[MAX_NUM_CPUS]; - void *synICEventPage[MAX_NUM_CPUS]; + void *synic_message_page[MAX_NUM_CPUS]; + void *synic_event_page[MAX_NUM_CPUS]; }; -extern struct hv_context gHvContext; +extern struct hv_context hv_context; /* Hv Interface */ -extern int HvInit(void); +extern int hv_init(void); -extern void HvCleanup(void); +extern void hv_cleanup(void); -extern u16 HvPostMessage(union hv_connection_id connectionId, - enum hv_message_type messageType, - void *payload, size_t payloadSize); +extern u16 hv_post_message(union hv_connection_id connection_id, + enum hv_message_type message_type, + void *payload, size_t payload_size); -extern u16 HvSignalEvent(void); +extern u16 hv_signal_event(void); -extern void HvSynicInit(void *irqarg); +extern void hv_synic_init(void *irqarg); -extern void HvSynicCleanup(void *arg); +extern void hv_synic_cleanup(void *arg); #endif /* __HV_H__ */ diff --git a/drivers/staging/hv/hv_api.h b/drivers/staging/hv/hv_api.h index 9eb818ee07ba..70e863ad0464 100644 --- a/drivers/staging/hv/hv_api.h +++ b/drivers/staging/hv/hv_api.h @@ -510,21 +510,21 @@ /* * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent - * is set by CPUID(HvCpuIdFunctionVersionAndFeatures). + * is set by CPUID(HVCPUID_VERSION_FEATURES). */ enum hv_cpuid_function { - HvCpuIdFunctionVersionAndFeatures = 0x00000001, - HvCpuIdFunctionHvVendorAndMaxFunction = 0x40000000, - HvCpuIdFunctionHvInterface = 0x40000001, + HVCPUID_VERSION_FEATURES = 0x00000001, + HVCPUID_VENDOR_MAXFUNCTION = 0x40000000, + HVCPUID_INTERFACE = 0x40000001, /* * The remaining functions depend on the value of - * HvCpuIdFunctionInterface + * HVCPUID_INTERFACE */ - HvCpuIdFunctionMsHvVersion = 0x40000002, - HvCpuIdFunctionMsHvFeatures = 0x40000003, - HvCpuIdFunctionMsHvEnlightenmentInformation = 0x40000004, - HvCpuIdFunctionMsHvImplementationLimits = 0x40000005, + HVCPUID_VERSION = 0x40000002, + HVCPUID_FEATURES = 0x40000003, + HVCPUID_ENLIGHTENMENT_INFO = 0x40000004, + HVCPUID_IMPLEMENTATION_LIMITS = 0x40000005, }; /* Define the virtual APIC registers */ @@ -575,30 +575,30 @@ enum hv_cpuid_function { /* Define hypervisor message types. */ enum hv_message_type { - HvMessageTypeNone = 0x00000000, + HVMSG_NONE = 0x00000000, /* Memory access messages. */ - HvMessageTypeUnmappedGpa = 0x80000000, - HvMessageTypeGpaIntercept = 0x80000001, + HVMSG_UNMAPPED_GPA = 0x80000000, + HVMSG_GPA_INTERCEPT = 0x80000001, /* Timer notification messages. */ - HvMessageTimerExpired = 0x80000010, + HVMSG_TIMER_EXPIRED = 0x80000010, /* Error messages. */ - HvMessageTypeInvalidVpRegisterValue = 0x80000020, - HvMessageTypeUnrecoverableException = 0x80000021, - HvMessageTypeUnsupportedFeature = 0x80000022, + HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020, + HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021, + HVMSG_UNSUPPORTED_FEATURE = 0x80000022, /* Trace buffer complete messages. */ - HvMessageTypeEventLogBufferComplete = 0x80000040, + HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040, /* Platform-specific processor intercept messages. */ - HvMessageTypeX64IoPortIntercept = 0x80010000, - HvMessageTypeX64MsrIntercept = 0x80010001, - HvMessageTypeX64CpuidIntercept = 0x80010002, - HvMessageTypeX64ExceptionIntercept = 0x80010003, - HvMessageTypeX64ApicEoi = 0x80010004, - HvMessageTypeX64LegacyFpError = 0x80010005 + HVMSG_X64_IOPORT_INTERCEPT = 0x80010000, + HVMSG_X64_MSR_INTERCEPT = 0x80010001, + HVMSG_X64_CPUID_INTERCEPT = 0x80010002, + HVMSG_X64_EXCEPTION_INTERCEPT = 0x80010003, + HVMSG_X64_APIC_EOI = 0x80010004, + HVMSG_X64_LEGACY_FP_ERROR = 0x80010005 }; /* Define the number of synthetic interrupt sources. */ @@ -610,103 +610,103 @@ enum hv_message_type { /* Define connection identifier type. */ union hv_connection_id { - u32 Asu32; + u32 asu32; struct { - u32 Id:24; - u32 Reserved:8; + u32 id:24; + u32 reserved:8; } u; }; /* Define port identifier type. */ union hv_port_id { - u32 Asu32; + u32 asu32; struct { - u32 Id:24; - u32 Reserved:8; + u32 id:24; + u32 reserved:8; } u ; }; /* Define port type. */ enum hv_port_type { - HvPortTypeMessage = 1, - HvPortTypeEvent = 2, - HvPortTypeMonitor = 3 + HVPORT_MSG = 1, + HVPORT_EVENT = 2, + HVPORT_MONITOR = 3 }; /* Define port information structure. */ struct hv_port_info { - enum hv_port_type PortType; - u32 Padding; + enum hv_port_type port_type; + u32 padding; union { struct { - u32 TargetSint; - u32 TargetVp; - u64 RsvdZ; - } MessagePortInfo; + u32 target_sint; + u32 target_vp; + u64 rsvdz; + } message_port_info; struct { - u32 TargetSint; - u32 TargetVp; - u16 BaseFlagNumber; - u16 FlagCount; - u32 RsvdZ; - } EventPortInfo; + u32 target_sint; + u32 target_vp; + u16 base_flag_bumber; + u16 flag_count; + u32 rsvdz; + } event_port_info; struct { - u64 MonitorAddress; - u64 RsvdZ; - } MonitorPortInfo; + u64 monitor_address; + u64 rsvdz; + } monitor_port_info; }; }; struct hv_connection_info { - enum hv_port_type PortType; - u32 Padding; + enum hv_port_type port_type; + u32 padding; union { struct { - u64 RsvdZ; - } MessageConnectionInfo; + u64 rsvdz; + } message_connection_info; struct { - u64 RsvdZ; - } EventConnectionInfo; + u64 rsvdz; + } event_connection_info; struct { - u64 MonitorAddress; - } MonitorConnectionInfo; + u64 monitor_address; + } monitor_connection_info; }; }; /* Define synthetic interrupt controller message flags. */ union hv_message_flags { - u8 Asu8; + u8 asu8; struct { - u8 MessagePending:1; - u8 Reserved:7; + u8 msg_pending:1; + u8 reserved:7; }; }; /* Define synthetic interrupt controller message header. */ struct hv_message_header { - enum hv_message_type MessageType; - u8 PayloadSize; - union hv_message_flags MessageFlags; - u8 Reserved[2]; + enum hv_message_type message_type; + u8 payload_size; + union hv_message_flags message_flags; + u8 reserved[2]; union { - u64 Sender; - union hv_port_id Port; + u64 sender; + union hv_port_id port; }; }; /* Define timer message payload structure. */ struct hv_timer_message_payload { - u32 TimerIndex; - u32 Reserved; - u64 ExpirationTime; /* When the timer expired */ - u64 DeliveryTime; /* When the message was delivered */ + u32 timer_index; + u32 reserved; + u64 expiration_time; /* When the timer expired */ + u64 delivery_time; /* When the message was delivered */ }; /* Define synthetic interrupt controller message format. */ struct hv_message { - struct hv_message_header Header; + struct hv_message_header header; union { - u64 Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; + u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; } u ; }; @@ -715,82 +715,82 @@ struct hv_message { /* Define the synthetic interrupt message page layout. */ struct hv_message_page { - struct hv_message SintMessage[HV_SYNIC_SINT_COUNT]; + struct hv_message sint_message[HV_SYNIC_SINT_COUNT]; }; /* Define the synthetic interrupt controller event flags format. */ union hv_synic_event_flags { - u8 Flags8[HV_EVENT_FLAGS_BYTE_COUNT]; - u32 Flags32[HV_EVENT_FLAGS_DWORD_COUNT]; + u8 flags8[HV_EVENT_FLAGS_BYTE_COUNT]; + u32 flags32[HV_EVENT_FLAGS_DWORD_COUNT]; }; /* Define the synthetic interrupt flags page layout. */ struct hv_synic_event_flags_page { - union hv_synic_event_flags SintEventFlags[HV_SYNIC_SINT_COUNT]; + union hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT]; }; /* Define SynIC control register. */ union hv_synic_scontrol { - u64 AsUINT64; + u64 as_uint64; struct { - u64 Enable:1; - u64 Reserved:63; + u64 enable:1; + u64 reserved:63; }; }; /* Define synthetic interrupt source. */ union hv_synic_sint { - u64 AsUINT64; + u64 as_uint64; struct { - u64 Vector:8; - u64 Reserved1:8; - u64 Masked:1; - u64 AutoEoi:1; - u64 Reserved2:46; + u64 vector:8; + u64 reserved1:8; + u64 masked:1; + u64 auto_eoi:1; + u64 reserved2:46; }; }; /* Define the format of the SIMP register */ union hv_synic_simp { - u64 AsUINT64; + u64 as_uint64; struct { - u64 SimpEnabled:1; - u64 Preserved:11; - u64 BaseSimpGpa:52; + u64 simp_enabled:1; + u64 preserved:11; + u64 base_simp_gpa:52; }; }; /* Define the format of the SIEFP register */ union hv_synic_siefp { - u64 AsUINT64; + u64 as_uint64; struct { - u64 SiefpEnabled:1; - u64 Preserved:11; - u64 BaseSiefpGpa:52; + u64 siefp_enabled:1; + u64 preserved:11; + u64 base_siefp_gpa:52; }; }; /* Definitions for the monitored notification facility */ union hv_monitor_trigger_group { - u64 AsUINT64; + u64 as_uint64; struct { - u32 Pending; - u32 Armed; + u32 pending; + u32 armed; }; }; struct hv_monitor_parameter { - union hv_connection_id ConnectionId; - u16 FlagNumber; - u16 RsvdZ; + union hv_connection_id connectionid; + u16 flagnumber; + u16 rsvdz; }; union hv_monitor_trigger_state { - u32 Asu32; + u32 asu32; struct { - u32 GroupEnable:4; - u32 RsvdZ:28; + u32 group_enable:4; + u32 rsvdz:28; }; }; @@ -814,42 +814,42 @@ union hv_monitor_trigger_state { /* | 840 | Rsvd4[0] | */ /* ------------------------------------------------------ */ struct hv_monitor_page { - union hv_monitor_trigger_state TriggerState; - u32 RsvdZ1; + union hv_monitor_trigger_state trigger_state; + u32 rsvdz1; - union hv_monitor_trigger_group TriggerGroup[4]; - u64 RsvdZ2[3]; + union hv_monitor_trigger_group trigger_group[4]; + u64 rsvdz2[3]; - s32 NextCheckTime[4][32]; + s32 next_checktime[4][32]; - u16 Latency[4][32]; - u64 RsvdZ3[32]; + u16 latency[4][32]; + u64 rsvdz3[32]; - struct hv_monitor_parameter Parameter[4][32]; + struct hv_monitor_parameter parameter[4][32]; - u8 RsvdZ4[1984]; + u8 rsvdz4[1984]; }; /* Declare the various hypercall operations. */ enum hv_call_code { - HvCallPostMessage = 0x005c, - HvCallSignalEvent = 0x005d, + HVCALL_POST_MESSAGE = 0x005c, + HVCALL_SIGNAL_EVENT = 0x005d, }; -/* Definition of the HvPostMessage hypercall input structure. */ +/* Definition of the hv_post_message hypercall input structure. */ struct hv_input_post_message { - union hv_connection_id ConnectionId; - u32 Reserved; - enum hv_message_type MessageType; - u32 PayloadSize; - u64 Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; + union hv_connection_id connectionid; + u32 reserved; + enum hv_message_type message_type; + u32 payload_size; + u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; }; -/* Definition of the HvSignalEvent hypercall input structure. */ +/* Definition of the hv_signal_event hypercall input structure. */ struct hv_input_signal_event { - union hv_connection_id ConnectionId; - u16 FlagNumber; - u16 RsvdZ; + union hv_connection_id connectionid; + u16 flag_number; + u16 rsvdz; }; /* @@ -859,16 +859,16 @@ struct hv_input_signal_event { /* Version info reported by guest OS's */ enum hv_guest_os_vendor { - HvGuestOsVendorMicrosoft = 0x0001 + HVGUESTOS_VENDOR_MICROSOFT = 0x0001 }; enum hv_guest_os_microsoft_ids { - HvGuestOsMicrosoftUndefined = 0x00, - HvGuestOsMicrosoftMSDOS = 0x01, - HvGuestOsMicrosoftWindows3x = 0x02, - HvGuestOsMicrosoftWindows9x = 0x03, - HvGuestOsMicrosoftWindowsNT = 0x04, - HvGuestOsMicrosoftWindowsCE = 0x05 + HVGUESTOS_MICROSOFT_UNDEFINED = 0x00, + HVGUESTOS_MICROSOFT_MSDOS = 0x01, + HVGUESTOS_MICROSOFT_WINDOWS3X = 0x02, + HVGUESTOS_MICROSOFT_WINDOWS9X = 0x03, + HVGUESTOS_MICROSOFT_WINDOWSNT = 0x04, + HVGUESTOS_MICROSOFT_WINDOWSCE = 0x05 }; /* @@ -877,14 +877,14 @@ enum hv_guest_os_microsoft_ids { #define HV_X64_MSR_GUEST_OS_ID 0x40000000 union hv_x64_msr_guest_os_id_contents { - u64 AsUINT64; + u64 as_uint64; struct { - u64 BuildNumber:16; - u64 ServiceVersion:8; /* Service Pack, etc. */ - u64 MinorVersion:8; - u64 MajorVersion:8; - u64 OsId:8; /* enum hv_guest_os_microsoft_ids (if Vendor=MS) */ - u64 VendorId:16; /* enum hv_guest_os_vendor */ + u64 build_number:16; + u64 service_version:8; /* Service Pack, etc. */ + u64 minor_version:8; + u64 major_version:8; + u64 os_id:8; /* enum hv_guest_os_microsoft_ids (if Vendor=MS) */ + u64 vendor_id:16; /* enum hv_guest_os_vendor */ }; }; @@ -894,11 +894,11 @@ union hv_x64_msr_guest_os_id_contents { #define HV_X64_MSR_HYPERCALL 0x40000001 union hv_x64_msr_hypercall_contents { - u64 AsUINT64; + u64 as_uint64; struct { - u64 Enable:1; - u64 Reserved:11; - u64 GuestPhysicalAddress:52; + u64 enable:1; + u64 reserved:11; + u64 guest_physical_address:52; }; }; diff --git a/drivers/staging/hv/hv_utils.c b/drivers/staging/hv/hv_utils.c index a99e900ec4c9..0074581f20e8 100644 --- a/drivers/staging/hv/hv_utils.c +++ b/drivers/staging/hv/hv_utils.c @@ -38,12 +38,14 @@ #include "vmbus_api.h" #include "utils.h" +static u8 *shut_txf_buf; +static u8 *time_txf_buf; +static u8 *hbeat_txf_buf; static void shutdown_onchannelcallback(void *context) { struct vmbus_channel *channel = context; - u8 *buf; - u32 buflen, recvlen; + u32 recvlen; u64 requestid; u8 execute_shutdown = false; @@ -52,24 +54,23 @@ static void shutdown_onchannelcallback(void *context) struct icmsg_hdr *icmsghdrp; struct icmsg_negotiate *negop = NULL; - buflen = PAGE_SIZE; - buf = kmalloc(buflen, GFP_ATOMIC); - - vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid); + vmbus_recvpacket(channel, shut_txf_buf, + PAGE_SIZE, &recvlen, &requestid); if (recvlen > 0) { DPRINT_DBG(VMBUS, "shutdown packet: len=%d, requestid=%lld", recvlen, requestid); - icmsghdrp = (struct icmsg_hdr *)&buf[ + icmsghdrp = (struct icmsg_hdr *)&shut_txf_buf[ sizeof(struct vmbuspipe_hdr)]; if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { - prep_negotiate_resp(icmsghdrp, negop, buf); + prep_negotiate_resp(icmsghdrp, negop, shut_txf_buf); } else { - shutdown_msg = (struct shutdown_msg_data *)&buf[ - sizeof(struct vmbuspipe_hdr) + - sizeof(struct icmsg_hdr)]; + shutdown_msg = + (struct shutdown_msg_data *)&shut_txf_buf[ + sizeof(struct vmbuspipe_hdr) + + sizeof(struct icmsg_hdr)]; switch (shutdown_msg->flags) { case 0: @@ -93,13 +94,11 @@ static void shutdown_onchannelcallback(void *context) icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; - vmbus_sendpacket(channel, buf, + vmbus_sendpacket(channel, shut_txf_buf, recvlen, requestid, VmbusPacketTypeDataInBand, 0); } - kfree(buf); - if (execute_shutdown == true) orderly_poweroff(false); } @@ -150,28 +149,25 @@ static inline void adj_guesttime(u64 hosttime, u8 flags) static void timesync_onchannelcallback(void *context) { struct vmbus_channel *channel = context; - u8 *buf; - u32 buflen, recvlen; + u32 recvlen; u64 requestid; struct icmsg_hdr *icmsghdrp; struct ictimesync_data *timedatap; - buflen = PAGE_SIZE; - buf = kmalloc(buflen, GFP_ATOMIC); - - vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid); + vmbus_recvpacket(channel, time_txf_buf, + PAGE_SIZE, &recvlen, &requestid); if (recvlen > 0) { DPRINT_DBG(VMBUS, "timesync packet: recvlen=%d, requestid=%lld", recvlen, requestid); - icmsghdrp = (struct icmsg_hdr *)&buf[ + icmsghdrp = (struct icmsg_hdr *)&time_txf_buf[ sizeof(struct vmbuspipe_hdr)]; if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { - prep_negotiate_resp(icmsghdrp, NULL, buf); + prep_negotiate_resp(icmsghdrp, NULL, time_txf_buf); } else { - timedatap = (struct ictimesync_data *)&buf[ + timedatap = (struct ictimesync_data *)&time_txf_buf[ sizeof(struct vmbuspipe_hdr) + sizeof(struct icmsg_hdr)]; adj_guesttime(timedatap->parenttime, timedatap->flags); @@ -180,12 +176,10 @@ static void timesync_onchannelcallback(void *context) icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; - vmbus_sendpacket(channel, buf, + vmbus_sendpacket(channel, time_txf_buf, recvlen, requestid, VmbusPacketTypeDataInBand, 0); } - - kfree(buf); } /* @@ -196,30 +190,28 @@ static void timesync_onchannelcallback(void *context) static void heartbeat_onchannelcallback(void *context) { struct vmbus_channel *channel = context; - u8 *buf; - u32 buflen, recvlen; + u32 recvlen; u64 requestid; struct icmsg_hdr *icmsghdrp; struct heartbeat_msg_data *heartbeat_msg; - buflen = PAGE_SIZE; - buf = kmalloc(buflen, GFP_ATOMIC); - - vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid); + vmbus_recvpacket(channel, hbeat_txf_buf, + PAGE_SIZE, &recvlen, &requestid); if (recvlen > 0) { DPRINT_DBG(VMBUS, "heartbeat packet: len=%d, requestid=%lld", recvlen, requestid); - icmsghdrp = (struct icmsg_hdr *)&buf[ + icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[ sizeof(struct vmbuspipe_hdr)]; if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { - prep_negotiate_resp(icmsghdrp, NULL, buf); + prep_negotiate_resp(icmsghdrp, NULL, hbeat_txf_buf); } else { - heartbeat_msg = (struct heartbeat_msg_data *)&buf[ - sizeof(struct vmbuspipe_hdr) + - sizeof(struct icmsg_hdr)]; + heartbeat_msg = + (struct heartbeat_msg_data *)&hbeat_txf_buf[ + sizeof(struct vmbuspipe_hdr) + + sizeof(struct icmsg_hdr)]; DPRINT_DBG(VMBUS, "heartbeat seq = %lld", heartbeat_msg->seq_num); @@ -230,12 +222,10 @@ static void heartbeat_onchannelcallback(void *context) icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; - vmbus_sendpacket(channel, buf, + vmbus_sendpacket(channel, hbeat_txf_buf, recvlen, requestid, VmbusPacketTypeDataInBand, 0); } - - kfree(buf); } static const struct pci_device_id __initconst @@ -268,15 +258,28 @@ static int __init init_hyperv_utils(void) if (!dmi_check_system(hv_utils_dmi_table)) return -ENODEV; - hv_cb_utils[HV_SHUTDOWN_MSG].channel->OnChannelCallback = + shut_txf_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); + time_txf_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); + hbeat_txf_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); + + if (!shut_txf_buf || !time_txf_buf || !hbeat_txf_buf) { + printk(KERN_INFO + "Unable to allocate memory for receive buffer\n"); + kfree(shut_txf_buf); + kfree(time_txf_buf); + kfree(hbeat_txf_buf); + return -ENOMEM; + } + + hv_cb_utils[HV_SHUTDOWN_MSG].channel->onchannel_callback = &shutdown_onchannelcallback; hv_cb_utils[HV_SHUTDOWN_MSG].callback = &shutdown_onchannelcallback; - hv_cb_utils[HV_TIMESYNC_MSG].channel->OnChannelCallback = + hv_cb_utils[HV_TIMESYNC_MSG].channel->onchannel_callback = ×ync_onchannelcallback; hv_cb_utils[HV_TIMESYNC_MSG].callback = ×ync_onchannelcallback; - hv_cb_utils[HV_HEARTBEAT_MSG].channel->OnChannelCallback = + hv_cb_utils[HV_HEARTBEAT_MSG].channel->onchannel_callback = &heartbeat_onchannelcallback; hv_cb_utils[HV_HEARTBEAT_MSG].callback = &heartbeat_onchannelcallback; @@ -287,17 +290,21 @@ static void exit_hyperv_utils(void) { printk(KERN_INFO "De-Registered HyperV Utility Driver\n"); - hv_cb_utils[HV_SHUTDOWN_MSG].channel->OnChannelCallback = + hv_cb_utils[HV_SHUTDOWN_MSG].channel->onchannel_callback = &chn_cb_negotiate; hv_cb_utils[HV_SHUTDOWN_MSG].callback = &chn_cb_negotiate; - hv_cb_utils[HV_TIMESYNC_MSG].channel->OnChannelCallback = + hv_cb_utils[HV_TIMESYNC_MSG].channel->onchannel_callback = &chn_cb_negotiate; hv_cb_utils[HV_TIMESYNC_MSG].callback = &chn_cb_negotiate; - hv_cb_utils[HV_HEARTBEAT_MSG].channel->OnChannelCallback = + hv_cb_utils[HV_HEARTBEAT_MSG].channel->onchannel_callback = &chn_cb_negotiate; hv_cb_utils[HV_HEARTBEAT_MSG].callback = &chn_cb_negotiate; + + kfree(shut_txf_buf); + kfree(time_txf_buf); + kfree(hbeat_txf_buf); } module_init(init_hyperv_utils); diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index 4c2632cb19e9..df9cd131e953 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -31,147 +31,149 @@ /* Globals */ -static const char *gDriverName = "netvsc"; +static const char *driver_name = "netvsc"; /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */ -static const struct hv_guid gNetVscDeviceType = { +static const struct hv_guid netvsc_device_type = { .data = { 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E } }; -static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo); +static int netvsc_device_add(struct hv_device *device, void *additional_info); -static int NetVscOnDeviceRemove(struct hv_device *Device); +static int netvsc_device_remove(struct hv_device *device); -static void NetVscOnCleanup(struct hv_driver *Driver); +static void netvsc_cleanup(struct hv_driver *driver); -static void NetVscOnChannelCallback(void *context); +static void netvsc_channel_cb(void *context); -static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device); +static int netvsc_init_send_buf(struct hv_device *device); -static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device); +static int netvsc_init_recv_buf(struct hv_device *device); -static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice); +static int netvsc_destroy_send_buf(struct netvsc_device *net_device); -static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice); +static int netvsc_destroy_recv_buf(struct netvsc_device *net_device); -static int NetVscConnectToVsp(struct hv_device *Device); +static int netvsc_connect_vsp(struct hv_device *device); -static void NetVscOnSendCompletion(struct hv_device *Device, - struct vmpacket_descriptor *Packet); +static void netvsc_send_completion(struct hv_device *device, + struct vmpacket_descriptor *packet); -static int NetVscOnSend(struct hv_device *Device, - struct hv_netvsc_packet *Packet); +static int netvsc_send(struct hv_device *device, + struct hv_netvsc_packet *packet); -static void NetVscOnReceive(struct hv_device *Device, - struct vmpacket_descriptor *Packet); +static void netvsc_receive(struct hv_device *device, + struct vmpacket_descriptor *packet); -static void NetVscOnReceiveCompletion(void *Context); +static void netvsc_receive_completion(void *context); -static void NetVscSendReceiveCompletion(struct hv_device *Device, - u64 TransactionId); +static void netvsc_send_recv_completion(struct hv_device *device, + u64 transaction_id); -static struct netvsc_device *AllocNetDevice(struct hv_device *Device) +static struct netvsc_device *alloc_net_device(struct hv_device *device) { - struct netvsc_device *netDevice; + struct netvsc_device *net_device; - netDevice = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL); - if (!netDevice) + net_device = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL); + if (!net_device) return NULL; /* Set to 2 to allow both inbound and outbound traffic */ - atomic_cmpxchg(&netDevice->RefCount, 0, 2); + atomic_cmpxchg(&net_device->refcnt, 0, 2); - netDevice->Device = Device; - Device->Extension = netDevice; + net_device->dev = device; + device->Extension = net_device; - return netDevice; + return net_device; } -static void FreeNetDevice(struct netvsc_device *Device) +static void free_net_device(struct netvsc_device *device) { - WARN_ON(atomic_read(&Device->RefCount) == 0); - Device->Device->Extension = NULL; - kfree(Device); + WARN_ON(atomic_read(&device->refcnt) == 0); + device->dev->Extension = NULL; + kfree(device); } /* Get the net device object iff exists and its refcount > 1 */ -static struct netvsc_device *GetOutboundNetDevice(struct hv_device *Device) +static struct netvsc_device *get_outbound_net_device(struct hv_device *device) { - struct netvsc_device *netDevice; + struct netvsc_device *net_device; - netDevice = Device->Extension; - if (netDevice && atomic_read(&netDevice->RefCount) > 1) - atomic_inc(&netDevice->RefCount); + net_device = device->Extension; + if (net_device && atomic_read(&net_device->refcnt) > 1) + atomic_inc(&net_device->refcnt); else - netDevice = NULL; + net_device = NULL; - return netDevice; + return net_device; } /* Get the net device object iff exists and its refcount > 0 */ -static struct netvsc_device *GetInboundNetDevice(struct hv_device *Device) +static struct netvsc_device *get_inbound_net_device(struct hv_device *device) { - struct netvsc_device *netDevice; + struct netvsc_device *net_device; - netDevice = Device->Extension; - if (netDevice && atomic_read(&netDevice->RefCount)) - atomic_inc(&netDevice->RefCount); + net_device = device->Extension; + if (net_device && atomic_read(&net_device->refcnt)) + atomic_inc(&net_device->refcnt); else - netDevice = NULL; + net_device = NULL; - return netDevice; + return net_device; } -static void PutNetDevice(struct hv_device *Device) +static void put_net_device(struct hv_device *device) { - struct netvsc_device *netDevice; + struct netvsc_device *net_device; - netDevice = Device->Extension; + net_device = device->Extension; /* ASSERT(netDevice); */ - atomic_dec(&netDevice->RefCount); + atomic_dec(&net_device->refcnt); } -static struct netvsc_device *ReleaseOutboundNetDevice(struct hv_device *Device) +static struct netvsc_device *release_outbound_net_device( + struct hv_device *device) { - struct netvsc_device *netDevice; + struct netvsc_device *net_device; - netDevice = Device->Extension; - if (netDevice == NULL) + net_device = device->Extension; + if (net_device == NULL) return NULL; /* Busy wait until the ref drop to 2, then set it to 1 */ - while (atomic_cmpxchg(&netDevice->RefCount, 2, 1) != 2) + while (atomic_cmpxchg(&net_device->refcnt, 2, 1) != 2) udelay(100); - return netDevice; + return net_device; } -static struct netvsc_device *ReleaseInboundNetDevice(struct hv_device *Device) +static struct netvsc_device *release_inbound_net_device( + struct hv_device *device) { - struct netvsc_device *netDevice; + struct netvsc_device *net_device; - netDevice = Device->Extension; - if (netDevice == NULL) + net_device = device->Extension; + if (net_device == NULL) return NULL; /* Busy wait until the ref drop to 1, then set it to 0 */ - while (atomic_cmpxchg(&netDevice->RefCount, 1, 0) != 1) + while (atomic_cmpxchg(&net_device->refcnt, 1, 0) != 1) udelay(100); - Device->Extension = NULL; - return netDevice; + device->Extension = NULL; + return net_device; } /* - * NetVscInitialize - Main entry point + * netvsc_initialize - Main entry point */ -int NetVscInitialize(struct hv_driver *drv) +int netvsc_initialize(struct hv_driver *drv) { struct netvsc_driver *driver = (struct netvsc_driver *)drv; @@ -185,8 +187,8 @@ int NetVscInitialize(struct hv_driver *drv) /* Make sure we are at least 2 pages since 1 page is used for control */ /* ASSERT(driver->RingBufferSize >= (PAGE_SIZE << 1)); */ - drv->name = gDriverName; - memcpy(&drv->deviceType, &gNetVscDeviceType, sizeof(struct hv_guid)); + 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 */ @@ -194,24 +196,24 @@ int NetVscInitialize(struct hv_driver *drv) /* ASSERT(driver->OnLinkStatusChanged); */ /* Setup the dispatch table */ - driver->Base.OnDeviceAdd = NetVscOnDeviceAdd; - driver->Base.OnDeviceRemove = NetVscOnDeviceRemove; - driver->Base.OnCleanup = NetVscOnCleanup; + driver->base.OnDeviceAdd = netvsc_device_add; + driver->base.OnDeviceRemove = netvsc_device_remove; + driver->base.OnCleanup = netvsc_cleanup; - driver->OnSend = NetVscOnSend; + driver->send = netvsc_send; - RndisFilterInit(driver); + rndis_filter_init(driver); return 0; } -static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) +static int netvsc_init_recv_buf(struct hv_device *device) { int ret = 0; - struct netvsc_device *netDevice; - struct nvsp_message *initPacket; + struct netvsc_device *net_device; + struct nvsp_message *init_packet; - netDevice = GetOutboundNetDevice(Device); - if (!netDevice) { + net_device = get_outbound_net_device(device); + if (!net_device) { DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return -1; @@ -220,12 +222,12 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) /* page-size grandularity */ /* ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE - 1)) == 0); */ - netDevice->ReceiveBuffer = - osd_PageAlloc(netDevice->ReceiveBufferSize >> PAGE_SHIFT); - if (!netDevice->ReceiveBuffer) { + net_device->recv_buf = + osd_page_alloc(net_device->recv_buf_size >> PAGE_SHIFT); + if (!net_device->recv_buf) { DPRINT_ERR(NETVSC, "unable to allocate receive buffer of size %d", - netDevice->ReceiveBufferSize); + net_device->recv_buf_size); ret = -1; goto Cleanup; } @@ -240,32 +242,34 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) * channel. Note: This call uses the vmbus connection rather * than the channel to establish the gpadl handle. */ - ret = vmbus_establish_gpadl(Device->channel, netDevice->ReceiveBuffer, - netDevice->ReceiveBufferSize, - &netDevice->ReceiveBufferGpadlHandle); + ret = vmbus_establish_gpadl(device->channel, net_device->recv_buf, + net_device->recv_buf_size, + &net_device->recv_buf_gpadl_handle); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to establish receive buffer's gpadl"); goto Cleanup; } - /* osd_WaitEventWait(ext->ChannelInitEvent); */ + /* osd_waitevent_wait(ext->ChannelInitEvent); */ /* Notify the NetVsp of the gpadl handle */ DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendReceiveBuffer..."); - initPacket = &netDevice->ChannelInitPacket; + init_packet = &net_device->channel_init_pkt; - memset(initPacket, 0, sizeof(struct nvsp_message)); + memset(init_packet, 0, sizeof(struct nvsp_message)); - initPacket->Header.MessageType = NvspMessage1TypeSendReceiveBuffer; - initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->ReceiveBufferGpadlHandle; - initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; + init_packet->hdr.msg_type = NVSP_MSG1_TYPE_SEND_RECV_BUF; + init_packet->msg.v1_msg.send_recv_buf. + gpadl_handle = net_device->recv_buf_gpadl_handle; + init_packet->msg.v1_msg. + send_recv_buf.id = NETVSC_RECEIVE_BUFFER_ID; /* Send the gpadl notification request */ - ret = vmbus_sendpacket(Device->channel, initPacket, + ret = vmbus_sendpacket(device->channel, init_packet, sizeof(struct nvsp_message), - (unsigned long)initPacket, + (unsigned long)init_packet, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { @@ -274,13 +278,15 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) goto Cleanup; } - osd_WaitEventWait(netDevice->ChannelInitEvent); + osd_waitevent_wait(net_device->channel_init_event); /* Check the response */ - if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess) { + if (init_packet->msg.v1_msg. + send_recv_buf_complete.status != NVSP_STAT_SUCCESS) { DPRINT_ERR(NETVSC, "Unable to complete receive buffer " "initialzation with NetVsp - status %d", - initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status); + init_packet->msg.v1_msg. + send_recv_buf_complete.status); ret = -1; goto Cleanup; } @@ -289,32 +295,36 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) /* ASSERT(netDevice->ReceiveSectionCount == 0); */ /* ASSERT(netDevice->ReceiveSections == NULL); */ - netDevice->ReceiveSectionCount = initPacket->Messages.Version1Messages.SendReceiveBufferComplete.NumSections; + net_device->recv_section_cnt = init_packet->msg. + v1_msg.send_recv_buf_complete.num_sections; - netDevice->ReceiveSections = kmalloc(netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL); - if (netDevice->ReceiveSections == NULL) { + net_device->recv_section = kmalloc(net_device->recv_section_cnt + * sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL); + if (net_device->recv_section == NULL) { ret = -1; goto Cleanup; } - memcpy(netDevice->ReceiveSections, - initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Sections, - netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section)); + memcpy(net_device->recv_section, + init_packet->msg.v1_msg. + send_recv_buf_complete.sections, + net_device->recv_section_cnt * + sizeof(struct nvsp_1_receive_buffer_section)); DPRINT_INFO(NETVSC, "Receive sections info (count %d, offset %d, " "endoffset %d, suballoc size %d, num suballocs %d)", - netDevice->ReceiveSectionCount, - netDevice->ReceiveSections[0].Offset, - netDevice->ReceiveSections[0].EndOffset, - netDevice->ReceiveSections[0].SubAllocationSize, - netDevice->ReceiveSections[0].NumSubAllocations); + net_device->recv_section_cnt, + net_device->recv_section[0].offset, + net_device->recv_section[0].end_offset, + net_device->recv_section[0].sub_alloc_size, + net_device->recv_section[0].num_sub_allocs); /* * For 1st release, there should only be 1 section that represents the * entire receive buffer */ - if (netDevice->ReceiveSectionCount != 1 || - netDevice->ReceiveSections->Offset != 0) { + if (net_device->recv_section_cnt != 1 || + net_device->recv_section->offset != 0) { ret = -1; goto Cleanup; } @@ -322,26 +332,26 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) goto Exit; Cleanup: - NetVscDestroyReceiveBuffer(netDevice); + netvsc_destroy_recv_buf(net_device); Exit: - PutNetDevice(Device); + put_net_device(device); return ret; } -static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device) +static int netvsc_init_send_buf(struct hv_device *device) { int ret = 0; - struct netvsc_device *netDevice; - struct nvsp_message *initPacket; + struct netvsc_device *net_device; + struct nvsp_message *init_packet; - netDevice = GetOutboundNetDevice(Device); - if (!netDevice) { + net_device = get_outbound_net_device(device); + if (!net_device) { DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return -1; } - if (netDevice->SendBufferSize <= 0) { + if (net_device->send_buf_size <= 0) { ret = -EINVAL; goto Cleanup; } @@ -349,11 +359,11 @@ static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device) /* page-size grandularity */ /* ASSERT((netDevice->SendBufferSize & (PAGE_SIZE - 1)) == 0); */ - netDevice->SendBuffer = - osd_PageAlloc(netDevice->SendBufferSize >> PAGE_SHIFT); - if (!netDevice->SendBuffer) { + net_device->send_buf = + osd_page_alloc(net_device->send_buf_size >> PAGE_SHIFT); + if (!net_device->send_buf) { DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d", - netDevice->SendBufferSize); + net_device->send_buf_size); ret = -1; goto Cleanup; } @@ -367,31 +377,33 @@ static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device) * channel. Note: This call uses the vmbus connection rather * than the channel to establish the gpadl handle. */ - ret = vmbus_establish_gpadl(Device->channel, netDevice->SendBuffer, - netDevice->SendBufferSize, - &netDevice->SendBufferGpadlHandle); + ret = vmbus_establish_gpadl(device->channel, net_device->send_buf, + net_device->send_buf_size, + &net_device->send_buf_gpadl_handle); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl"); goto Cleanup; } - /* osd_WaitEventWait(ext->ChannelInitEvent); */ + /* osd_waitevent_wait(ext->ChannelInitEvent); */ /* Notify the NetVsp of the gpadl handle */ DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendSendBuffer..."); - initPacket = &netDevice->ChannelInitPacket; + init_packet = &net_device->channel_init_pkt; - memset(initPacket, 0, sizeof(struct nvsp_message)); + memset(init_packet, 0, sizeof(struct nvsp_message)); - initPacket->Header.MessageType = NvspMessage1TypeSendSendBuffer; - initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->SendBufferGpadlHandle; - initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_SEND_BUFFER_ID; + init_packet->hdr.msg_type = NVSP_MSG1_TYPE_SEND_SEND_BUF; + init_packet->msg.v1_msg.send_recv_buf. + gpadl_handle = net_device->send_buf_gpadl_handle; + init_packet->msg.v1_msg.send_recv_buf.id = + NETVSC_SEND_BUFFER_ID; /* Send the gpadl notification request */ - ret = vmbus_sendpacket(Device->channel, initPacket, + ret = vmbus_sendpacket(device->channel, init_packet, sizeof(struct nvsp_message), - (unsigned long)initPacket, + (unsigned long)init_packet, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { @@ -400,32 +412,35 @@ static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device) goto Cleanup; } - osd_WaitEventWait(netDevice->ChannelInitEvent); + osd_waitevent_wait(net_device->channel_init_event); /* Check the response */ - if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess) { + if (init_packet->msg.v1_msg. + send_send_buf_complete.status != NVSP_STAT_SUCCESS) { DPRINT_ERR(NETVSC, "Unable to complete send buffer " "initialzation with NetVsp - status %d", - initPacket->Messages.Version1Messages.SendSendBufferComplete.Status); + init_packet->msg.v1_msg. + send_send_buf_complete.status); ret = -1; goto Cleanup; } - netDevice->SendSectionSize = initPacket->Messages.Version1Messages.SendSendBufferComplete.SectionSize; + net_device->send_section_size = init_packet-> + msg.v1_msg.send_send_buf_complete.section_size; goto Exit; Cleanup: - NetVscDestroySendBuffer(netDevice); + netvsc_destroy_send_buf(net_device); Exit: - PutNetDevice(Device); + put_net_device(device); return ret; } -static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice) +static int netvsc_destroy_recv_buf(struct netvsc_device *net_device) { - struct nvsp_message *revokePacket; + struct nvsp_message *revoke_packet; int ret = 0; /* @@ -434,20 +449,23 @@ static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice) * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need * to send a revoke msg here */ - if (NetDevice->ReceiveSectionCount) { + if (net_device->recv_section_cnt) { DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeRevokeReceiveBuffer..."); /* Send the revoke receive buffer */ - revokePacket = &NetDevice->RevokePacket; - memset(revokePacket, 0, sizeof(struct nvsp_message)); + revoke_packet = &net_device->revoke_packet; + memset(revoke_packet, 0, sizeof(struct nvsp_message)); - revokePacket->Header.MessageType = NvspMessage1TypeRevokeReceiveBuffer; - revokePacket->Messages.Version1Messages.RevokeReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; + revoke_packet->hdr.msg_type = + NVSP_MSG1_TYPE_REVOKE_RECV_BUF; + revoke_packet->msg.v1_msg. + revoke_recv_buf.id = NETVSC_RECEIVE_BUFFER_ID; - ret = vmbus_sendpacket(NetDevice->Device->channel, revokePacket, + ret = vmbus_sendpacket(net_device->dev->channel, + revoke_packet, sizeof(struct nvsp_message), - (unsigned long)revokePacket, + (unsigned long)revoke_packet, VmbusPacketTypeDataInBand, 0); /* * If we failed here, we might as well return and @@ -461,11 +479,11 @@ static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice) } /* Teardown the gpadl on the vsp end */ - if (NetDevice->ReceiveBufferGpadlHandle) { + if (net_device->recv_buf_gpadl_handle) { DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL..."); - ret = vmbus_teardown_gpadl(NetDevice->Device->channel, - NetDevice->ReceiveBufferGpadlHandle); + ret = vmbus_teardown_gpadl(net_device->dev->channel, + net_device->recv_buf_gpadl_handle); /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */ if (ret != 0) { @@ -473,30 +491,30 @@ static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice) "unable to teardown receive buffer's gpadl"); return -1; } - NetDevice->ReceiveBufferGpadlHandle = 0; + net_device->recv_buf_gpadl_handle = 0; } - if (NetDevice->ReceiveBuffer) { + if (net_device->recv_buf) { DPRINT_INFO(NETVSC, "Freeing up receive buffer..."); /* Free up the receive buffer */ - osd_PageFree(NetDevice->ReceiveBuffer, - NetDevice->ReceiveBufferSize >> PAGE_SHIFT); - NetDevice->ReceiveBuffer = NULL; + osd_page_free(net_device->recv_buf, + net_device->recv_buf_size >> PAGE_SHIFT); + net_device->recv_buf = NULL; } - if (NetDevice->ReceiveSections) { - NetDevice->ReceiveSectionCount = 0; - kfree(NetDevice->ReceiveSections); - NetDevice->ReceiveSections = NULL; + if (net_device->recv_section) { + net_device->recv_section_cnt = 0; + kfree(net_device->recv_section); + net_device->recv_section = NULL; } return ret; } -static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice) +static int netvsc_destroy_send_buf(struct netvsc_device *net_device) { - struct nvsp_message *revokePacket; + struct nvsp_message *revoke_packet; int ret = 0; /* @@ -505,20 +523,23 @@ static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice) * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need * to send a revoke msg here */ - if (NetDevice->SendSectionSize) { + if (net_device->send_section_size) { DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeRevokeSendBuffer..."); /* Send the revoke send buffer */ - revokePacket = &NetDevice->RevokePacket; - memset(revokePacket, 0, sizeof(struct nvsp_message)); + revoke_packet = &net_device->revoke_packet; + memset(revoke_packet, 0, sizeof(struct nvsp_message)); - revokePacket->Header.MessageType = NvspMessage1TypeRevokeSendBuffer; - revokePacket->Messages.Version1Messages.RevokeSendBuffer.Id = NETVSC_SEND_BUFFER_ID; + revoke_packet->hdr.msg_type = + NVSP_MSG1_TYPE_REVOKE_SEND_BUF; + revoke_packet->msg.v1_msg. + revoke_send_buf.id = NETVSC_SEND_BUFFER_ID; - ret = vmbus_sendpacket(NetDevice->Device->channel, revokePacket, + ret = vmbus_sendpacket(net_device->dev->channel, + revoke_packet, sizeof(struct nvsp_message), - (unsigned long)revokePacket, + (unsigned long)revoke_packet, VmbusPacketTypeDataInBand, 0); /* * If we failed here, we might as well return and have a leak @@ -532,10 +553,10 @@ static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice) } /* Teardown the gpadl on the vsp end */ - if (NetDevice->SendBufferGpadlHandle) { + if (net_device->send_buf_gpadl_handle) { DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL..."); - ret = vmbus_teardown_gpadl(NetDevice->Device->channel, - NetDevice->SendBufferGpadlHandle); + ret = vmbus_teardown_gpadl(net_device->dev->channel, + net_device->send_buf_gpadl_handle); /* * If we failed here, we might as well return and have a leak @@ -546,49 +567,51 @@ static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice) "gpadl"); return -1; } - NetDevice->SendBufferGpadlHandle = 0; + net_device->send_buf_gpadl_handle = 0; } - if (NetDevice->SendBuffer) { + if (net_device->send_buf) { DPRINT_INFO(NETVSC, "Freeing up send buffer..."); /* Free up the receive buffer */ - osd_PageFree(NetDevice->SendBuffer, - NetDevice->SendBufferSize >> PAGE_SHIFT); - NetDevice->SendBuffer = NULL; + osd_page_free(net_device->send_buf, + net_device->send_buf_size >> PAGE_SHIFT); + net_device->send_buf = NULL; } return ret; } -static int NetVscConnectToVsp(struct hv_device *Device) +static int netvsc_connect_vsp(struct hv_device *device) { int ret; - struct netvsc_device *netDevice; - struct nvsp_message *initPacket; - int ndisVersion; + struct netvsc_device *net_device; + struct nvsp_message *init_packet; + int ndis_version; - netDevice = GetOutboundNetDevice(Device); - if (!netDevice) { + net_device = get_outbound_net_device(device); + if (!net_device) { DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return -1; } - initPacket = &netDevice->ChannelInitPacket; + init_packet = &net_device->channel_init_pkt; - memset(initPacket, 0, sizeof(struct nvsp_message)); - initPacket->Header.MessageType = NvspMessageTypeInit; - initPacket->Messages.InitMessages.Init.MinProtocolVersion = NVSP_MIN_PROTOCOL_VERSION; - initPacket->Messages.InitMessages.Init.MaxProtocolVersion = NVSP_MAX_PROTOCOL_VERSION; + memset(init_packet, 0, sizeof(struct nvsp_message)); + init_packet->hdr.msg_type = NVSP_MSG_TYPE_INIT; + init_packet->msg.init_msg.init.min_protocol_ver = + NVSP_MIN_PROTOCOL_VERSION; + init_packet->msg.init_msg.init.max_protocol_ver = + NVSP_MAX_PROTOCOL_VERSION; DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit..."); /* Send the init request */ - ret = vmbus_sendpacket(Device->channel, initPacket, + ret = vmbus_sendpacket(device->channel, init_packet, sizeof(struct nvsp_message), - (unsigned long)initPacket, + (unsigned long)init_packet, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); @@ -597,47 +620,52 @@ static int NetVscConnectToVsp(struct hv_device *Device) goto Cleanup; } - osd_WaitEventWait(netDevice->ChannelInitEvent); + osd_waitevent_wait(net_device->channel_init_event); /* Now, check the response */ /* ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT); */ DPRINT_INFO(NETVSC, "NvspMessageTypeInit status(%d) max mdl chain (%d)", - initPacket->Messages.InitMessages.InitComplete.Status, - initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength); + init_packet->msg.init_msg.init_complete.status, + init_packet->msg.init_msg. + init_complete.max_mdl_chain_len); - if (initPacket->Messages.InitMessages.InitComplete.Status != - NvspStatusSuccess) { + if (init_packet->msg.init_msg.init_complete.status != + NVSP_STAT_SUCCESS) { DPRINT_ERR(NETVSC, "unable to initialize with netvsp (status 0x%x)", - initPacket->Messages.InitMessages.InitComplete.Status); + init_packet->msg.init_msg.init_complete.status); ret = -1; goto Cleanup; } - if (initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion != NVSP_PROTOCOL_VERSION_1) { + if (init_packet->msg.init_msg.init_complete. + negotiated_protocol_ver != NVSP_PROTOCOL_VERSION_1) { DPRINT_ERR(NETVSC, "unable to initialize with netvsp " "(version expected 1 got %d)", - initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion); + init_packet->msg.init_msg. + init_complete.negotiated_protocol_ver); ret = -1; goto Cleanup; } DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion..."); /* Send the ndis version */ - memset(initPacket, 0, sizeof(struct nvsp_message)); + memset(init_packet, 0, sizeof(struct nvsp_message)); - ndisVersion = 0x00050000; + ndis_version = 0x00050000; - initPacket->Header.MessageType = NvspMessage1TypeSendNdisVersion; - initPacket->Messages.Version1Messages.SendNdisVersion.NdisMajorVersion = - (ndisVersion & 0xFFFF0000) >> 16; - initPacket->Messages.Version1Messages.SendNdisVersion.NdisMinorVersion = - ndisVersion & 0xFFFF; + init_packet->hdr.msg_type = NVSP_MSG1_TYPE_SEND_NDIS_VER; + init_packet->msg.v1_msg. + send_ndis_ver.ndis_major_ver = + (ndis_version & 0xFFFF0000) >> 16; + init_packet->msg.v1_msg. + send_ndis_ver.ndis_minor_ver = + ndis_version & 0xFFFF; /* Send the init request */ - ret = vmbus_sendpacket(Device->channel, initPacket, + ret = vmbus_sendpacket(device->channel, init_packet, sizeof(struct nvsp_message), - (unsigned long)initPacket, + (unsigned long)init_packet, VmbusPacketTypeDataInBand, 0); if (ret != 0) { DPRINT_ERR(NETVSC, @@ -651,51 +679,52 @@ static int NetVscConnectToVsp(struct hv_device *Device) * packet) since our Vmbus always set the * VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag */ - /* osd_WaitEventWait(NetVscChannel->ChannelInitEvent); */ + /* osd_waitevent_wait(NetVscChannel->ChannelInitEvent); */ /* Post the big receive buffer to NetVSP */ - ret = NetVscInitializeReceiveBufferWithNetVsp(Device); + ret = netvsc_init_recv_buf(device); if (ret == 0) - ret = NetVscInitializeSendBufferWithNetVsp(Device); + ret = netvsc_init_send_buf(device); Cleanup: - PutNetDevice(Device); + put_net_device(device); return ret; } -static void NetVscDisconnectFromVsp(struct netvsc_device *NetDevice) +static void NetVscDisconnectFromVsp(struct netvsc_device *net_device) { - NetVscDestroyReceiveBuffer(NetDevice); - NetVscDestroySendBuffer(NetDevice); + netvsc_destroy_recv_buf(net_device); + netvsc_destroy_send_buf(net_device); } /* - * NetVscOnDeviceAdd - Callback when the device belonging to this driver is added + * netvsc_device_add - Callback when the device belonging to this + * driver is added */ -static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) +static int netvsc_device_add(struct hv_device *device, void *additional_info) { int ret = 0; int i; - struct netvsc_device *netDevice; + struct netvsc_device *net_device; struct hv_netvsc_packet *packet, *pos; - struct netvsc_driver *netDriver = - (struct netvsc_driver *)Device->Driver; + struct netvsc_driver *net_driver = + (struct netvsc_driver *)device->Driver; - netDevice = AllocNetDevice(Device); - if (!netDevice) { + net_device = alloc_net_device(device); + if (!net_device) { ret = -1; goto Cleanup; } - DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", netDevice); + DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", net_device); /* Initialize the NetVSC channel extension */ - netDevice->ReceiveBufferSize = NETVSC_RECEIVE_BUFFER_SIZE; - spin_lock_init(&netDevice->receive_packet_list_lock); + net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE; + spin_lock_init(&net_device->recv_pkt_list_lock); - netDevice->SendBufferSize = NETVSC_SEND_BUFFER_SIZE; + net_device->send_buf_size = NETVSC_SEND_BUFFER_SIZE; - INIT_LIST_HEAD(&netDevice->ReceivePacketList); + INIT_LIST_HEAD(&net_device->recv_pkt_list); for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) { packet = kzalloc(sizeof(struct hv_netvsc_packet) + @@ -707,19 +736,19 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) NETVSC_RECEIVE_PACKETLIST_COUNT, i); break; } - list_add_tail(&packet->ListEntry, - &netDevice->ReceivePacketList); + list_add_tail(&packet->list_ent, + &net_device->recv_pkt_list); } - netDevice->ChannelInitEvent = osd_WaitEventCreate(); - if (!netDevice->ChannelInitEvent) { + net_device->channel_init_event = osd_waitevent_create(); + if (!net_device->channel_init_event) { ret = -ENOMEM; goto Cleanup; } /* Open the channel */ - ret = vmbus_open(Device->channel, netDriver->RingBufferSize, - netDriver->RingBufferSize, NULL, 0, - NetVscOnChannelCallback, Device); + ret = vmbus_open(device->channel, net_driver->ring_buf_size, + net_driver->ring_buf_size, NULL, 0, + netvsc_channel_cb, device); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to open channel: %d", ret); @@ -731,7 +760,7 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) DPRINT_INFO(NETVSC, "*** NetVSC channel opened successfully! ***"); /* Connect with the NetVsp */ - ret = NetVscConnectToVsp(Device); + ret = netvsc_connect_vsp(device); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to connect to NetVSP - %d", ret); ret = -1; @@ -745,174 +774,178 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) close: /* Now, we can close the channel safely */ - vmbus_close(Device->channel); + vmbus_close(device->channel); Cleanup: - if (netDevice) { - kfree(netDevice->ChannelInitEvent); + if (net_device) { + kfree(net_device->channel_init_event); list_for_each_entry_safe(packet, pos, - &netDevice->ReceivePacketList, - ListEntry) { - list_del(&packet->ListEntry); + &net_device->recv_pkt_list, + list_ent) { + list_del(&packet->list_ent); kfree(packet); } - ReleaseOutboundNetDevice(Device); - ReleaseInboundNetDevice(Device); + release_outbound_net_device(device); + release_inbound_net_device(device); - FreeNetDevice(netDevice); + free_net_device(net_device); } return ret; } /* - * NetVscOnDeviceRemove - Callback when the root bus device is removed + * netvsc_device_remove - Callback when the root bus device is removed */ -static int NetVscOnDeviceRemove(struct hv_device *Device) +static int netvsc_device_remove(struct hv_device *device) { - struct netvsc_device *netDevice; - struct hv_netvsc_packet *netvscPacket, *pos; + struct netvsc_device *net_device; + struct hv_netvsc_packet *netvsc_packet, *pos; DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...", - Device->Extension); + device->Extension); /* Stop outbound traffic ie sends and receives completions */ - netDevice = ReleaseOutboundNetDevice(Device); - if (!netDevice) { + net_device = release_outbound_net_device(device); + if (!net_device) { DPRINT_ERR(NETVSC, "No net device present!!"); return -1; } /* Wait for all send completions */ - while (atomic_read(&netDevice->NumOutstandingSends)) { + while (atomic_read(&net_device->num_outstanding_sends)) { DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", - atomic_read(&netDevice->NumOutstandingSends)); + atomic_read(&net_device->num_outstanding_sends)); udelay(100); } DPRINT_INFO(NETVSC, "Disconnecting from netvsp..."); - NetVscDisconnectFromVsp(netDevice); + NetVscDisconnectFromVsp(net_device); DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...", - Device->Extension); + device->Extension); /* Stop inbound traffic ie receives and sends completions */ - netDevice = ReleaseInboundNetDevice(Device); + net_device = release_inbound_net_device(device); /* At this point, no one should be accessing netDevice except in here */ - DPRINT_INFO(NETVSC, "net device (%p) safe to remove", netDevice); + DPRINT_INFO(NETVSC, "net device (%p) safe to remove", net_device); /* Now, we can close the channel safely */ - vmbus_close(Device->channel); + vmbus_close(device->channel); /* Release all resources */ - list_for_each_entry_safe(netvscPacket, pos, - &netDevice->ReceivePacketList, ListEntry) { - list_del(&netvscPacket->ListEntry); - kfree(netvscPacket); + list_for_each_entry_safe(netvsc_packet, pos, + &net_device->recv_pkt_list, list_ent) { + list_del(&netvsc_packet->list_ent); + kfree(netvsc_packet); } - kfree(netDevice->ChannelInitEvent); - FreeNetDevice(netDevice); + kfree(net_device->channel_init_event); + free_net_device(net_device); return 0; } /* - * NetVscOnCleanup - Perform any cleanup when the driver is removed + * netvsc_cleanup - Perform any cleanup when the driver is removed */ -static void NetVscOnCleanup(struct hv_driver *drv) +static void netvsc_cleanup(struct hv_driver *drv) { } -static void NetVscOnSendCompletion(struct hv_device *Device, - struct vmpacket_descriptor *Packet) +static void netvsc_send_completion(struct hv_device *device, + struct vmpacket_descriptor *packet) { - struct netvsc_device *netDevice; - struct nvsp_message *nvspPacket; - struct hv_netvsc_packet *nvscPacket; + struct netvsc_device *net_device; + struct nvsp_message *nvsp_packet; + struct hv_netvsc_packet *nvsc_packet; - netDevice = GetInboundNetDevice(Device); - if (!netDevice) { + net_device = get_inbound_net_device(device); + if (!net_device) { DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return; } - nvspPacket = (struct nvsp_message *)((unsigned long)Packet + (Packet->DataOffset8 << 3)); + nvsp_packet = (struct nvsp_message *)((unsigned long)packet + + (packet->DataOffset8 << 3)); DPRINT_DBG(NETVSC, "send completion packet - type %d", - nvspPacket->Header.MessageType); + nvsp_packet->hdr.msg_type); - if ((nvspPacket->Header.MessageType == NvspMessageTypeInitComplete) || - (nvspPacket->Header.MessageType == - NvspMessage1TypeSendReceiveBufferComplete) || - (nvspPacket->Header.MessageType == - NvspMessage1TypeSendSendBufferComplete)) { + if ((nvsp_packet->hdr.msg_type == NVSP_MSG_TYPE_INIT_COMPLETE) || + (nvsp_packet->hdr.msg_type == + NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE) || + (nvsp_packet->hdr.msg_type == + NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE)) { /* Copy the response back */ - memcpy(&netDevice->ChannelInitPacket, nvspPacket, + memcpy(&net_device->channel_init_pkt, nvsp_packet, sizeof(struct nvsp_message)); - osd_WaitEventSet(netDevice->ChannelInitEvent); - } else if (nvspPacket->Header.MessageType == - NvspMessage1TypeSendRNDISPacketComplete) { + osd_waitevent_set(net_device->channel_init_event); + } else if (nvsp_packet->hdr.msg_type == + NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE) { /* Get the send context */ - nvscPacket = (struct hv_netvsc_packet *)(unsigned long)Packet->TransactionId; + nvsc_packet = (struct hv_netvsc_packet *)(unsigned long) + packet->TransactionId; /* ASSERT(nvscPacket); */ /* Notify the layer above us */ - nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext); + nvsc_packet->completion.send.send_completion( + nvsc_packet->completion.send.send_completion_ctx); - atomic_dec(&netDevice->NumOutstandingSends); + atomic_dec(&net_device->num_outstanding_sends); } else { DPRINT_ERR(NETVSC, "Unknown send completion packet type - " - "%d received!!", nvspPacket->Header.MessageType); + "%d received!!", nvsp_packet->hdr.msg_type); } - PutNetDevice(Device); + put_net_device(device); } -static int NetVscOnSend(struct hv_device *Device, - struct hv_netvsc_packet *Packet) +static int netvsc_send(struct hv_device *device, + struct hv_netvsc_packet *packet) { - struct netvsc_device *netDevice; + struct netvsc_device *net_device; int ret = 0; struct nvsp_message sendMessage; - netDevice = GetOutboundNetDevice(Device); - if (!netDevice) { + net_device = get_outbound_net_device(device); + if (!net_device) { DPRINT_ERR(NETVSC, "net device (%p) shutting down..." - "ignoring outbound packets", netDevice); + "ignoring outbound packets", net_device); return -2; } - sendMessage.Header.MessageType = NvspMessage1TypeSendRNDISPacket; - if (Packet->IsDataPacket) { + sendMessage.hdr.msg_type = NVSP_MSG1_TYPE_SEND_RNDIS_PKT; + if (packet->is_data_pkt) { /* 0 is RMC_DATA; */ - sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 0; + sendMessage.msg.v1_msg.send_rndis_pkt.channel_type = 0; } else { /* 1 is RMC_CONTROL; */ - sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 1; + sendMessage.msg.v1_msg.send_rndis_pkt.channel_type = 1; } /* Not using send buffer section */ - sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionIndex = 0xFFFFFFFF; - sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionSize = 0; - - if (Packet->PageBufferCount) { - ret = vmbus_sendpacket_pagebuffer(Device->channel, - Packet->PageBuffers, - Packet->PageBufferCount, + sendMessage.msg.v1_msg.send_rndis_pkt.send_buf_section_index = + 0xFFFFFFFF; + sendMessage.msg.v1_msg.send_rndis_pkt.send_buf_section_size = 0; + + if (packet->page_buf_cnt) { + ret = vmbus_sendpacket_pagebuffer(device->channel, + packet->page_buf, + packet->page_buf_cnt, &sendMessage, sizeof(struct nvsp_message), - (unsigned long)Packet); + (unsigned long)packet); } else { - ret = vmbus_sendpacket(Device->channel, &sendMessage, + ret = vmbus_sendpacket(device->channel, &sendMessage, sizeof(struct nvsp_message), - (unsigned long)Packet, + (unsigned long)packet, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); @@ -920,31 +953,31 @@ static int NetVscOnSend(struct hv_device *Device, if (ret != 0) DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", - Packet, ret); + packet, ret); - atomic_inc(&netDevice->NumOutstandingSends); - PutNetDevice(Device); + atomic_inc(&net_device->num_outstanding_sends); + put_net_device(device); return ret; } -static void NetVscOnReceive(struct hv_device *Device, - struct vmpacket_descriptor *Packet) +static void netvsc_receive(struct hv_device *device, + struct vmpacket_descriptor *packet) { - struct netvsc_device *netDevice; - struct vmtransfer_page_packet_header *vmxferpagePacket; - struct nvsp_message *nvspPacket; - struct hv_netvsc_packet *netvscPacket = NULL; + struct netvsc_device *net_device; + struct vmtransfer_page_packet_header *vmxferpage_packet; + struct nvsp_message *nvsp_packet; + struct hv_netvsc_packet *netvsc_packet = NULL; unsigned long start; - unsigned long end, endVirtual; + unsigned long end, end_virtual; /* struct netvsc_driver *netvscDriver; */ - struct xferpage_packet *xferpagePacket = NULL; + struct xferpage_packet *xferpage_packet = NULL; int i, j; - int count = 0, bytesRemain = 0; + int count = 0, bytes_remain = 0; unsigned long flags; LIST_HEAD(listHead); - netDevice = GetInboundNetDevice(Device); - if (!netDevice) { + net_device = get_inbound_net_device(device); + if (!net_device) { DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return; @@ -954,39 +987,40 @@ static void NetVscOnReceive(struct hv_device *Device, * All inbound packets other than send completion should be xfer page * packet */ - if (Packet->Type != VmbusPacketTypeDataUsingTransferPages) { + if (packet->Type != VmbusPacketTypeDataUsingTransferPages) { DPRINT_ERR(NETVSC, "Unknown packet type received - %d", - Packet->Type); - PutNetDevice(Device); + packet->Type); + put_net_device(device); return; } - nvspPacket = (struct nvsp_message *)((unsigned long)Packet + - (Packet->DataOffset8 << 3)); + nvsp_packet = (struct nvsp_message *)((unsigned long)packet + + (packet->DataOffset8 << 3)); /* Make sure this is a valid nvsp packet */ - if (nvspPacket->Header.MessageType != NvspMessage1TypeSendRNDISPacket) { + if (nvsp_packet->hdr.msg_type != + NVSP_MSG1_TYPE_SEND_RNDIS_PKT) { DPRINT_ERR(NETVSC, "Unknown nvsp packet type received - %d", - nvspPacket->Header.MessageType); - PutNetDevice(Device); + nvsp_packet->hdr.msg_type); + put_net_device(device); return; } DPRINT_DBG(NETVSC, "NVSP packet received - type %d", - nvspPacket->Header.MessageType); + nvsp_packet->hdr.msg_type); - vmxferpagePacket = (struct vmtransfer_page_packet_header *)Packet; + vmxferpage_packet = (struct vmtransfer_page_packet_header *)packet; - if (vmxferpagePacket->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID) { + if (vmxferpage_packet->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID) { DPRINT_ERR(NETVSC, "Invalid xfer page set id - " "expecting %x got %x", NETVSC_RECEIVE_BUFFER_ID, - vmxferpagePacket->TransferPageSetId); - PutNetDevice(Device); + vmxferpage_packet->TransferPageSetId); + put_net_device(device); return; } DPRINT_DBG(NETVSC, "xfer page - range count %d", - vmxferpagePacket->RangeCount); + vmxferpage_packet->RangeCount); /* * Grab free packets (range count + 1) to represent this xfer @@ -994,13 +1028,13 @@ static void NetVscOnReceive(struct hv_device *Device, * We grab it here so that we know exactly how many we can * fulfil */ - spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); - while (!list_empty(&netDevice->ReceivePacketList)) { - list_move_tail(netDevice->ReceivePacketList.next, &listHead); - if (++count == vmxferpagePacket->RangeCount + 1) + 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) break; } - spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); + spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags); /* * We need at least 2 netvsc pkts (1 to represent the xfer @@ -1010,140 +1044,149 @@ static void NetVscOnReceive(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, vmxferpagePacket->RangeCount + 1); + count, vmxferpage_packet->RangeCount + 1); /* Return it to the freelist */ - spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); + spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); for (i = count; i != 0; i--) { list_move_tail(listHead.next, - &netDevice->ReceivePacketList); + &net_device->recv_pkt_list); } - spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, + spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags); - NetVscSendReceiveCompletion(Device, - vmxferpagePacket->d.TransactionId); + netvsc_send_recv_completion(device, + vmxferpage_packet->d.TransactionId); - PutNetDevice(Device); + put_net_device(device); return; } /* Remove the 1st packet to represent the xfer page packet itself */ - xferpagePacket = (struct xferpage_packet *)listHead.next; - list_del(&xferpagePacket->ListEntry); + xferpage_packet = (struct xferpage_packet *)listHead.next; + list_del(&xferpage_packet->list_ent); /* This is how much we can satisfy */ - xferpagePacket->Count = count - 1; + xferpage_packet->count = count - 1; /* ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <= */ /* vmxferpagePacket->RangeCount); */ - if (xferpagePacket->Count != vmxferpagePacket->RangeCount) { + if (xferpage_packet->count != vmxferpage_packet->RangeCount) { DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer " - "page...got %d", vmxferpagePacket->RangeCount, - xferpagePacket->Count); + "page...got %d", vmxferpage_packet->RangeCount, + xferpage_packet->count); } /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */ for (i = 0; i < (count - 1); i++) { - netvscPacket = (struct hv_netvsc_packet *)listHead.next; - list_del(&netvscPacket->ListEntry); + netvsc_packet = (struct hv_netvsc_packet *)listHead.next; + list_del(&netvsc_packet->list_ent); /* Initialize the netvsc packet */ - netvscPacket->XferPagePacket = xferpagePacket; - netvscPacket->Completion.Recv.OnReceiveCompletion = - NetVscOnReceiveCompletion; - netvscPacket->Completion.Recv.ReceiveCompletionContext = - netvscPacket; - netvscPacket->Device = Device; + netvsc_packet->xfer_page_pkt = xferpage_packet; + netvsc_packet->completion.recv.recv_completion = + netvsc_receive_completion; + netvsc_packet->completion.recv.recv_completion_ctx = + netvsc_packet; + netvsc_packet->device = device; /* Save this so that we can send it back */ - netvscPacket->Completion.Recv.ReceiveCompletionTid = - vmxferpagePacket->d.TransactionId; + netvsc_packet->completion.recv.recv_completion_tid = + vmxferpage_packet->d.TransactionId; - netvscPacket->TotalDataBufferLength = - vmxferpagePacket->Ranges[i].ByteCount; - netvscPacket->PageBufferCount = 1; + netvsc_packet->total_data_buflen = + vmxferpage_packet->Ranges[i].ByteCount; + netvsc_packet->page_buf_cnt = 1; /* ASSERT(vmxferpagePacket->Ranges[i].ByteOffset + */ /* vmxferpagePacket->Ranges[i].ByteCount < */ /* netDevice->ReceiveBufferSize); */ - netvscPacket->PageBuffers[0].Length = - vmxferpagePacket->Ranges[i].ByteCount; + netvsc_packet->page_buf[0].Length = + vmxferpage_packet->Ranges[i].ByteCount; - start = virt_to_phys((void *)((unsigned long)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset)); + start = virt_to_phys((void *)((unsigned long)net_device-> + recv_buf + vmxferpage_packet->Ranges[i].ByteOffset)); - netvscPacket->PageBuffers[0].Pfn = start >> PAGE_SHIFT; - endVirtual = (unsigned long)netDevice->ReceiveBuffer - + vmxferpagePacket->Ranges[i].ByteOffset - + vmxferpagePacket->Ranges[i].ByteCount - 1; - end = virt_to_phys((void *)endVirtual); + 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; + end = virt_to_phys((void *)end_virtual); /* Calculate the page relative offset */ - netvscPacket->PageBuffers[0].Offset = - vmxferpagePacket->Ranges[i].ByteOffset & (PAGE_SIZE - 1); + netvsc_packet->page_buf[0].Offset = + vmxferpage_packet->Ranges[i].ByteOffset & + (PAGE_SIZE - 1); if ((end >> PAGE_SHIFT) != (start >> PAGE_SHIFT)) { /* Handle frame across multiple pages: */ - netvscPacket->PageBuffers[0].Length = - (netvscPacket->PageBuffers[0].Pfn << PAGE_SHIFT) + netvsc_packet->page_buf[0].Length = + (netvsc_packet->page_buf[0].Pfn << + PAGE_SHIFT) + PAGE_SIZE - start; - bytesRemain = netvscPacket->TotalDataBufferLength - - netvscPacket->PageBuffers[0].Length; + bytes_remain = netvsc_packet->total_data_buflen - + netvsc_packet->page_buf[0].Length; for (j = 1; j < NETVSC_PACKET_MAXPAGE; j++) { - netvscPacket->PageBuffers[j].Offset = 0; - if (bytesRemain <= PAGE_SIZE) { - netvscPacket->PageBuffers[j].Length = bytesRemain; - bytesRemain = 0; + netvsc_packet->page_buf[j].Offset = 0; + if (bytes_remain <= PAGE_SIZE) { + netvsc_packet->page_buf[j].Length = + bytes_remain; + bytes_remain = 0; } else { - netvscPacket->PageBuffers[j].Length = PAGE_SIZE; - bytesRemain -= PAGE_SIZE; + netvsc_packet->page_buf[j].Length = + PAGE_SIZE; + bytes_remain -= PAGE_SIZE; } - netvscPacket->PageBuffers[j].Pfn = - virt_to_phys((void *)(endVirtual - bytesRemain)) >> PAGE_SHIFT; - netvscPacket->PageBufferCount++; - if (bytesRemain == 0) + 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, - vmxferpagePacket->Ranges[i].ByteOffset, - vmxferpagePacket->Ranges[i].ByteCount, - netvscPacket->PageBuffers[0].Pfn, - netvscPacket->PageBuffers[0].Offset, - netvscPacket->PageBuffers[0].Length); + 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); /* Pass it to the upper layer */ - ((struct netvsc_driver *)Device->Driver)->OnReceiveCallback(Device, netvscPacket); + ((struct netvsc_driver *)device->Driver)-> + recv_cb(device, netvsc_packet); - NetVscOnReceiveCompletion(netvscPacket->Completion.Recv.ReceiveCompletionContext); + netvsc_receive_completion(netvsc_packet-> + completion.recv.recv_completion_ctx); } /* ASSERT(list_empty(&listHead)); */ - PutNetDevice(Device); + put_net_device(device); } -static void NetVscSendReceiveCompletion(struct hv_device *Device, - u64 TransactionId) +static void netvsc_send_recv_completion(struct hv_device *device, + u64 transaction_id) { struct nvsp_message recvcompMessage; int retries = 0; int ret; DPRINT_DBG(NETVSC, "Sending receive completion pkt - %llx", - TransactionId); + transaction_id); - recvcompMessage.Header.MessageType = - NvspMessage1TypeSendRNDISPacketComplete; + recvcompMessage.hdr.msg_type = + NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE; /* FIXME: Pass in the status */ - recvcompMessage.Messages.Version1Messages.SendRNDISPacketComplete.Status = NvspStatusSuccess; + recvcompMessage.msg.v1_msg.send_rndis_pkt_complete.status = + NVSP_STAT_SUCCESS; retry_send_cmplt: /* Send the completion */ - ret = vmbus_sendpacket(Device->channel, &recvcompMessage, - sizeof(struct nvsp_message), TransactionId, + ret = vmbus_sendpacket(device->channel, &recvcompMessage, + sizeof(struct nvsp_message), transaction_id, VmbusPacketTypeCompletion, 0); if (ret == 0) { /* success */ @@ -1152,7 +1195,7 @@ retry_send_cmplt: /* no more room...wait a bit and attempt to retry 3 times */ retries++; DPRINT_ERR(NETVSC, "unable to send receive completion pkt " - "(tid %llx)...retrying %d", TransactionId, retries); + "(tid %llx)...retrying %d", transaction_id, retries); if (retries < 4) { udelay(100); @@ -1160,22 +1203,22 @@ retry_send_cmplt: } else { DPRINT_ERR(NETVSC, "unable to send receive completion " "pkt (tid %llx)...give up retrying", - TransactionId); + transaction_id); } } else { DPRINT_ERR(NETVSC, "unable to send receive completion pkt - " - "%llx", TransactionId); + "%llx", transaction_id); } } /* Send a receive completion packet to RNDIS device (ie NetVsp) */ -static void NetVscOnReceiveCompletion(void *Context) +static void netvsc_receive_completion(void *context) { - struct hv_netvsc_packet *packet = Context; - struct hv_device *device = (struct hv_device *)packet->Device; - struct netvsc_device *netDevice; - u64 transactionId = 0; - bool fSendReceiveComp = false; + struct hv_netvsc_packet *packet = context; + struct hv_device *device = (struct hv_device *)packet->device; + struct netvsc_device *net_device; + u64 transaction_id = 0; + bool fsend_receive_comp = false; unsigned long flags; /* ASSERT(packet->XferPagePacket); */ @@ -1185,49 +1228,49 @@ static void NetVscOnReceiveCompletion(void *Context) * send out receive completion, we are using GetInboundNetDevice() * since we may have disable outbound traffic already. */ - netDevice = GetInboundNetDevice(device); - if (!netDevice) { + net_device = get_inbound_net_device(device); + if (!net_device) { DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return; } /* Overloading use of the lock. */ - spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); + spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); /* ASSERT(packet->XferPagePacket->Count > 0); */ - packet->XferPagePacket->Count--; + packet->xfer_page_pkt->count--; /* * Last one in the line that represent 1 xfer page packet. * Return the xfer page packet itself to the freelist */ - if (packet->XferPagePacket->Count == 0) { - fSendReceiveComp = true; - transactionId = packet->Completion.Recv.ReceiveCompletionTid; - list_add_tail(&packet->XferPagePacket->ListEntry, - &netDevice->ReceivePacketList); + if (packet->xfer_page_pkt->count == 0) { + fsend_receive_comp = true; + transaction_id = packet->completion.recv.recv_completion_tid; + list_add_tail(&packet->xfer_page_pkt->list_ent, + &net_device->recv_pkt_list); } /* Put the packet back */ - list_add_tail(&packet->ListEntry, &netDevice->ReceivePacketList); - spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); + list_add_tail(&packet->list_ent, &net_device->recv_pkt_list); + spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags); /* Send a receive completion for the xfer page packet */ - if (fSendReceiveComp) - NetVscSendReceiveCompletion(device, transactionId); + if (fsend_receive_comp) + netvsc_send_recv_completion(device, transaction_id); - PutNetDevice(device); + put_net_device(device); } -static void NetVscOnChannelCallback(void *Context) +static void netvsc_channel_cb(void *context) { int ret; - struct hv_device *device = Context; - struct netvsc_device *netDevice; - u32 bytesRecvd; - u64 requestId; + struct hv_device *device = context; + struct netvsc_device *net_device; + u32 bytes_recvd; + u64 request_id; unsigned char *packet; struct vmpacket_descriptor *desc; unsigned char *buffer; @@ -1241,37 +1284,37 @@ static void NetVscOnChannelCallback(void *Context) return; buffer = packet; - netDevice = GetInboundNetDevice(device); - if (!netDevice) { + net_device = get_inbound_net_device(device); + if (!net_device) { DPRINT_ERR(NETVSC, "net device (%p) shutting down..." - "ignoring inbound packets", netDevice); + "ignoring inbound packets", net_device); goto out; } do { ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen, - &bytesRecvd, &requestId); + &bytes_recvd, &request_id); if (ret == 0) { - if (bytesRecvd > 0) { + if (bytes_recvd > 0) { DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx", - bytesRecvd, requestId); + bytes_recvd, request_id); desc = (struct vmpacket_descriptor *)buffer; switch (desc->Type) { case VmbusPacketTypeCompletion: - NetVscOnSendCompletion(device, desc); + netvsc_send_completion(device, desc); break; case VmbusPacketTypeDataUsingTransferPages: - NetVscOnReceive(device, desc); + netvsc_receive(device, desc); break; default: DPRINT_ERR(NETVSC, "unhandled packet type %d, " "tid %llx len %d\n", - desc->Type, requestId, - bytesRecvd); + desc->Type, request_id, + bytes_recvd); break; } @@ -1293,20 +1336,20 @@ static void NetVscOnChannelCallback(void *Context) } } else if (ret == -2) { /* Handle large packet */ - buffer = kmalloc(bytesRecvd, GFP_ATOMIC); + buffer = kmalloc(bytes_recvd, GFP_ATOMIC); if (buffer == NULL) { /* Try again next time around */ DPRINT_ERR(NETVSC, "unable to allocate buffer of size " - "(%d)!!", bytesRecvd); + "(%d)!!", bytes_recvd); break; } - bufferlen = bytesRecvd; + bufferlen = bytes_recvd; } } while (1); - PutNetDevice(device); + put_net_device(device); out: kfree(buffer); return; diff --git a/drivers/staging/hv/netvsc.h b/drivers/staging/hv/netvsc.h index c71dce5b3f7c..932a77ccdc04 100644 --- a/drivers/staging/hv/netvsc.h +++ b/drivers/staging/hv/netvsc.h @@ -38,48 +38,48 @@ #define NVSP_MAX_PROTOCOL_VERSION NVSP_PROTOCOL_VERSION_1 enum { - NvspMessageTypeNone = 0, + NVSP_MSG_TYPE_NONE = 0, /* Init Messages */ - NvspMessageTypeInit = 1, - NvspMessageTypeInitComplete = 2, + NVSP_MSG_TYPE_INIT = 1, + NVSP_MSG_TYPE_INIT_COMPLETE = 2, - NvspVersionMessageStart = 100, + NVSP_VERSION_MSG_START = 100, /* Version 1 Messages */ - NvspMessage1TypeSendNdisVersion = NvspVersionMessageStart, + NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START, - NvspMessage1TypeSendReceiveBuffer, - NvspMessage1TypeSendReceiveBufferComplete, - NvspMessage1TypeRevokeReceiveBuffer, + NVSP_MSG1_TYPE_SEND_RECV_BUF, + NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE, + NVSP_MSG1_TYPE_REVOKE_RECV_BUF, - NvspMessage1TypeSendSendBuffer, - NvspMessage1TypeSendSendBufferComplete, - NvspMessage1TypeRevokeSendBuffer, + NVSP_MSG1_TYPE_SEND_SEND_BUF, + NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE, + NVSP_MSG1_TYPE_REVOKE_SEND_BUF, - NvspMessage1TypeSendRNDISPacket, - NvspMessage1TypeSendRNDISPacketComplete, + NVSP_MSG1_TYPE_SEND_RNDIS_PKT, + NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE, /* * This should be set to the number of messages for the version with * the maximum number of messages. */ - NvspNumMessagePerVersion = 9, + NVSP_NUM_MSG_PER_VERSION = 9, }; enum { - NvspStatusNone = 0, - NvspStatusSuccess, - NvspStatusFailure, - NvspStatusProtocolVersionRangeTooNew, - NvspStatusProtocolVersionRangeTooOld, - NvspStatusInvalidRndisPacket, - NvspStatusBusy, - NvspStatusMax, + NVSP_STAT_NONE = 0, + NVSP_STAT_SUCCESS, + NVSP_STAT_FAIL, + NVSP_STAT_PROTOCOL_TOO_NEW, + NVSP_STAT_PROTOCOL_TOO_OLD, + NVSP_STAT_INVALID_RNDIS_PKT, + NVSP_STAT_BUSY, + NVSP_STAT_MAX, }; struct nvsp_message_header { - u32 MessageType; + u32 msg_type; }; /* Init Messages */ @@ -90,8 +90,8 @@ struct nvsp_message_header { * versioning (i.e. this message will be the same for ever). */ struct nvsp_message_init { - u32 MinProtocolVersion; - u32 MaxProtocolVersion; + u32 min_protocol_ver; + u32 max_protocol_ver; } __attribute__((packed)); /* @@ -100,14 +100,14 @@ struct nvsp_message_init { * (i.e. this message will be the same for ever). */ struct nvsp_message_init_complete { - u32 NegotiatedProtocolVersion; - u32 MaximumMdlChainLength; - u32 Status; + u32 negotiated_protocol_ver; + u32 max_mdl_chain_len; + u32 status; } __attribute__((packed)); union nvsp_message_init_uber { - struct nvsp_message_init Init; - struct nvsp_message_init_complete InitComplete; + struct nvsp_message_init init; + struct nvsp_message_init_complete init_complete; } __attribute__((packed)); /* Version 1 Messages */ @@ -117,8 +117,8 @@ union nvsp_message_init_uber { * can use this information when handling OIDs sent by the VSC. */ struct nvsp_1_message_send_ndis_version { - u32 NdisMajorVersion; - u32 NdisMinorVersion; + u32 ndis_major_ver; + u32 ndis_minor_ver; } __attribute__((packed)); /* @@ -126,15 +126,15 @@ struct nvsp_1_message_send_ndis_version { * can then use the receive buffer to send data to the VSC. */ struct nvsp_1_message_send_receive_buffer { - u32 GpadlHandle; - u16 Id; + u32 gpadl_handle; + u16 id; } __attribute__((packed)); struct nvsp_1_receive_buffer_section { - u32 Offset; - u32 SubAllocationSize; - u32 NumSubAllocations; - u32 EndOffset; + u32 offset; + u32 sub_alloc_size; + u32 num_sub_allocs; + u32 end_offset; } __attribute__((packed)); /* @@ -143,8 +143,8 @@ struct nvsp_1_receive_buffer_section { * buffer. */ struct nvsp_1_message_send_receive_buffer_complete { - u32 Status; - u32 NumSections; + u32 status; + u32 num_sections; /* * The receive buffer is split into two parts, a large suballocation @@ -165,7 +165,7 @@ struct nvsp_1_message_send_receive_buffer_complete { * LargeOffset SmallOffset */ - struct nvsp_1_receive_buffer_section Sections[1]; + struct nvsp_1_receive_buffer_section sections[1]; } __attribute__((packed)); /* @@ -174,7 +174,7 @@ struct nvsp_1_message_send_receive_buffer_complete { * again. */ struct nvsp_1_message_revoke_receive_buffer { - u16 Id; + u16 id; }; /* @@ -182,8 +182,8 @@ struct nvsp_1_message_revoke_receive_buffer { * can then use the send buffer to send data to the VSP. */ struct nvsp_1_message_send_send_buffer { - u32 GpadlHandle; - u16 Id; + u32 gpadl_handle; + u16 id; } __attribute__((packed)); /* @@ -192,7 +192,7 @@ struct nvsp_1_message_send_send_buffer { * buffer. */ struct nvsp_1_message_send_send_buffer_complete { - u32 Status; + u32 status; /* * The VSC gets to choose the size of the send buffer and the VSP gets @@ -200,7 +200,7 @@ struct nvsp_1_message_send_send_buffer_complete { * dynamic reconfigurations when the cost of GPA-direct buffers * decreases. */ - u32 SectionSize; + u32 section_size; } __attribute__((packed)); /* @@ -208,7 +208,7 @@ struct nvsp_1_message_send_send_buffer_complete { * completes this transaction, the vsp should never use the send buffer again. */ struct nvsp_1_message_revoke_send_buffer { - u16 Id; + u16 id; }; /* @@ -221,7 +221,7 @@ struct nvsp_1_message_send_rndis_packet { * channels of communication. However, the Network VSP only has one. * Therefore, the channel travels with the RNDIS packet. */ - u32 ChannelType; + u32 channel_type; /* * This field is used to send part or all of the data through a send @@ -229,8 +229,8 @@ struct nvsp_1_message_send_rndis_packet { * index is 0xFFFFFFFF, then the send buffer is not being used and all * of the data was sent through other VMBus mechanisms. */ - u32 SendBufferSectionIndex; - u32 SendBufferSectionSize; + u32 send_buf_section_index; + u32 send_buf_section_size; } __attribute__((packed)); /* @@ -239,35 +239,35 @@ struct nvsp_1_message_send_rndis_packet { * message cannot use any resources associated with the original RNDIS packet. */ struct nvsp_1_message_send_rndis_packet_complete { - u32 Status; + u32 status; }; union nvsp_1_message_uber { - struct nvsp_1_message_send_ndis_version SendNdisVersion; + struct nvsp_1_message_send_ndis_version send_ndis_ver; - struct nvsp_1_message_send_receive_buffer SendReceiveBuffer; + struct nvsp_1_message_send_receive_buffer send_recv_buf; struct nvsp_1_message_send_receive_buffer_complete - SendReceiveBufferComplete; - struct nvsp_1_message_revoke_receive_buffer RevokeReceiveBuffer; + send_recv_buf_complete; + struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf; - struct nvsp_1_message_send_send_buffer SendSendBuffer; - struct nvsp_1_message_send_send_buffer_complete SendSendBufferComplete; - struct nvsp_1_message_revoke_send_buffer RevokeSendBuffer; + struct nvsp_1_message_send_send_buffer send_send_buf; + struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete; + struct nvsp_1_message_revoke_send_buffer revoke_send_buf; - struct nvsp_1_message_send_rndis_packet SendRNDISPacket; + struct nvsp_1_message_send_rndis_packet send_rndis_pkt; struct nvsp_1_message_send_rndis_packet_complete - SendRNDISPacketComplete; + send_rndis_pkt_complete; } __attribute__((packed)); union nvsp_all_messages { - union nvsp_message_init_uber InitMessages; - union nvsp_1_message_uber Version1Messages; + union nvsp_message_init_uber init_msg; + union nvsp_1_message_uber v1_msg; } __attribute__((packed)); /* ALL Messages */ struct nvsp_message { - struct nvsp_message_header Header; - union nvsp_all_messages Messages; + struct nvsp_message_header hdr; + union nvsp_all_messages msg; } __attribute__((packed)); @@ -293,39 +293,39 @@ struct nvsp_message { /* Per netvsc channel-specific */ struct netvsc_device { - struct hv_device *Device; + struct hv_device *dev; - atomic_t RefCount; - atomic_t NumOutstandingSends; + atomic_t refcnt; + atomic_t num_outstanding_sends; /* * List of free preallocated hv_netvsc_packet to represent receive * packet */ - struct list_head ReceivePacketList; - spinlock_t receive_packet_list_lock; + struct list_head recv_pkt_list; + spinlock_t recv_pkt_list_lock; /* Send buffer allocated by us but manages by NetVSP */ - void *SendBuffer; - u32 SendBufferSize; - u32 SendBufferGpadlHandle; - u32 SendSectionSize; + void *send_buf; + u32 send_buf_size; + u32 send_buf_gpadl_handle; + u32 send_section_size; /* Receive buffer allocated by us but manages by NetVSP */ - void *ReceiveBuffer; - u32 ReceiveBufferSize; - u32 ReceiveBufferGpadlHandle; - u32 ReceiveSectionCount; - struct nvsp_1_receive_buffer_section *ReceiveSections; + void *recv_buf; + u32 recv_buf_size; + u32 recv_buf_gpadl_handle; + u32 recv_section_cnt; + struct nvsp_1_receive_buffer_section *recv_section; /* Used for NetVSP initialization protocol */ - struct osd_waitevent *ChannelInitEvent; - struct nvsp_message ChannelInitPacket; + struct osd_waitevent *channel_init_event; + struct nvsp_message channel_init_pkt; - struct nvsp_message RevokePacket; + struct nvsp_message revoke_packet; /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */ /* Holds rndis device info */ - void *Extension; + void *extension; }; #endif /* _NETVSC_H_ */ diff --git a/drivers/staging/hv/netvsc_api.h b/drivers/staging/hv/netvsc_api.h index 4b5b3ac458c8..b4bed3636594 100644 --- a/drivers/staging/hv/netvsc_api.h +++ b/drivers/staging/hv/netvsc_api.h @@ -32,10 +32,10 @@ struct hv_netvsc_packet; /* Represent the xfer page packet which contains 1 or more netvsc packet */ struct xferpage_packet { - struct list_head ListEntry; + struct list_head list_ent; /* # of netvsc packets this xfer packet contains */ - u32 Count; + u32 count; }; /* The number of pages which are enough to cover jumbo frame buffer. */ @@ -47,70 +47,70 @@ struct xferpage_packet { */ struct hv_netvsc_packet { /* Bookkeeping stuff */ - struct list_head ListEntry; + struct list_head list_ent; - struct hv_device *Device; - bool IsDataPacket; + struct hv_device *device; + bool is_data_pkt; /* * Valid only for receives when we break a xfer page packet * into multiple netvsc packets */ - struct xferpage_packet *XferPagePacket; + struct xferpage_packet *xfer_page_pkt; union { struct{ - u64 ReceiveCompletionTid; - void *ReceiveCompletionContext; - void (*OnReceiveCompletion)(void *context); - } Recv; + u64 recv_completion_tid; + void *recv_completion_ctx; + void (*recv_completion)(void *context); + } recv; struct{ - u64 SendCompletionTid; - void *SendCompletionContext; - void (*OnSendCompletion)(void *context); - } Send; - } Completion; + u64 send_completion_tid; + void *send_completion_ctx; + void (*send_completion)(void *context); + } send; + } completion; - /* This points to the memory after PageBuffers */ - void *Extension; + /* This points to the memory after page_buf */ + void *extension; - u32 TotalDataBufferLength; + u32 total_data_buflen; /* Points to the send/receive buffer where the ethernet frame is */ - u32 PageBufferCount; - struct hv_page_buffer PageBuffers[NETVSC_PACKET_MAXPAGE]; + u32 page_buf_cnt; + struct hv_page_buffer page_buf[NETVSC_PACKET_MAXPAGE]; }; /* Represents the net vsc driver */ struct netvsc_driver { /* Must be the first field */ /* Which is a bug FIXME! */ - struct hv_driver Base; + struct hv_driver base; - u32 RingBufferSize; - u32 RequestExtSize; + u32 ring_buf_size; + u32 req_ext_size; /* * This is set by the caller to allow us to callback when we * receive a packet from the "wire" */ - int (*OnReceiveCallback)(struct hv_device *dev, + int (*recv_cb)(struct hv_device *dev, struct hv_netvsc_packet *packet); - void (*OnLinkStatusChanged)(struct hv_device *dev, u32 Status); + void (*link_status_change)(struct hv_device *dev, u32 status); /* Specific to this driver */ - int (*OnSend)(struct hv_device *dev, struct hv_netvsc_packet *packet); + int (*send)(struct hv_device *dev, struct hv_netvsc_packet *packet); - void *Context; + void *ctx; }; struct netvsc_device_info { - unsigned char MacAddr[6]; - bool LinkState; /* 0 - link up, 1 - link down */ + unsigned char mac_adr[6]; + bool link_state; /* 0 - link up, 1 - link down */ }; /* Interface */ -int NetVscInitialize(struct hv_driver *drv); -int RndisFilterOnOpen(struct hv_device *Device); -int RndisFilterOnClose(struct hv_device *Device); +int netvsc_initialize(struct hv_driver *drv); +int rndis_filter_open(struct hv_device *dev); +int rndis_filter_close(struct hv_device *dev); #endif /* _NETVSC_API_H_ */ diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c index 141535295a41..0147b407512c 100644 --- a/drivers/staging/hv/netvsc_drv.c +++ b/drivers/staging/hv/netvsc_drv.c @@ -66,6 +66,9 @@ MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); /* The one and only one */ static struct netvsc_driver_context 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 + * when it calls RndisFilterOnOpen() */ static void netvsc_set_multicast_list(struct net_device *net) { } @@ -78,7 +81,7 @@ static int netvsc_open(struct net_device *net) if (netif_carrier_ok(net)) { /* Open up the device */ - ret = RndisFilterOnOpen(device_obj); + ret = rndis_filter_open(device_obj); if (ret != 0) { DPRINT_ERR(NETVSC_DRV, "unable to open device (ret %d).", ret); @@ -101,7 +104,7 @@ static int netvsc_close(struct net_device *net) netif_stop_queue(net); - ret = RndisFilterOnClose(device_obj); + ret = rndis_filter_close(device_obj); if (ret != 0) DPRINT_ERR(NETVSC_DRV, "unable to close device (ret %d).", ret); @@ -112,7 +115,7 @@ static void netvsc_xmit_completion(void *context) { struct hv_netvsc_packet *packet = (struct hv_netvsc_packet *)context; struct sk_buff *skb = (struct sk_buff *) - (unsigned long)packet->Completion.Send.SendCompletionTid; + (unsigned long)packet->completion.send.send_completion_tid; kfree(packet); @@ -151,7 +154,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) /* Allocate a netvsc packet based on # of frags. */ packet = kzalloc(sizeof(struct hv_netvsc_packet) + (num_pages * sizeof(struct hv_page_buffer)) + - net_drv_obj->RequestExtSize, GFP_ATOMIC); + net_drv_obj->req_ext_size, GFP_ATOMIC); if (!packet) { /* out of memory, silently drop packet */ DPRINT_ERR(NETVSC_DRV, "unable to allocate hv_netvsc_packet"); @@ -161,40 +164,40 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) return NETDEV_TX_OK; } - packet->Extension = (void *)(unsigned long)packet + + packet->extension = (void *)(unsigned long)packet + sizeof(struct hv_netvsc_packet) + (num_pages * sizeof(struct hv_page_buffer)); /* Setup the rndis header */ - packet->PageBufferCount = num_pages; + packet->page_buf_cnt = num_pages; /* TODO: Flush all write buffers/ memory fence ??? */ /* wmb(); */ /* Initialize it from the skb */ - packet->TotalDataBufferLength = skb->len; + packet->total_data_buflen = skb->len; /* Start filling in the page buffers starting after RNDIS buffer. */ - packet->PageBuffers[1].Pfn = virt_to_phys(skb->data) >> PAGE_SHIFT; - packet->PageBuffers[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->PageBuffers[1].Length = skb_headlen(skb); + packet->page_buf[1].Length = 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->PageBuffers[i+2].Pfn = page_to_pfn(f->page); - packet->PageBuffers[i+2].Offset = f->page_offset; - packet->PageBuffers[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].Length = f->size; } /* Set the completion routine */ - packet->Completion.Send.OnSendCompletion = netvsc_xmit_completion; - packet->Completion.Send.SendCompletionContext = packet; - packet->Completion.Send.SendCompletionTid = (unsigned long)skb; + packet->completion.send.send_completion = netvsc_xmit_completion; + packet->completion.send.send_completion_ctx = packet; + packet->completion.send.send_completion_tid = (unsigned long)skb; - ret = net_drv_obj->OnSend(&net_device_ctx->device_ctx->device_obj, + ret = net_drv_obj->send(&net_device_ctx->device_ctx->device_obj, packet); if (ret == 0) { net->stats.tx_bytes += skb->len; @@ -260,7 +263,7 @@ static int netvsc_recv_callback(struct hv_device *device_obj, } /* Allocate a skb - TODO direct I/O to pages? */ - skb = netdev_alloc_skb_ip_align(net, packet->TotalDataBufferLength); + skb = netdev_alloc_skb_ip_align(net, packet->total_data_buflen); if (unlikely(!skb)) { ++net->stats.rx_dropped; return 0; @@ -273,17 +276,17 @@ static int netvsc_recv_callback(struct hv_device *device_obj, * Copy to skb. This copy is needed here since the memory pointed by * hv_netvsc_packet cannot be deallocated */ - for (i = 0; i < packet->PageBufferCount; i++) { - data = kmap_atomic(pfn_to_page(packet->PageBuffers[i].Pfn), + for (i = 0; i < packet->page_buf_cnt; i++) { + data = kmap_atomic(pfn_to_page(packet->page_buf[i].Pfn), KM_IRQ1); data = (void *)(unsigned long)data + - packet->PageBuffers[i].Offset; + packet->page_buf[i].Offset; - memcpy(skb_put(skb, packet->PageBuffers[i].Length), data, - packet->PageBuffers[i].Length); + memcpy(skb_put(skb, packet->page_buf[i].Length), data, + packet->page_buf[i].Length); kunmap_atomic((void *)((unsigned long)data - - packet->PageBuffers[i].Offset), KM_IRQ1); + packet->page_buf[i].Offset), KM_IRQ1); } local_irq_restore(flags); @@ -346,7 +349,7 @@ static int netvsc_probe(struct device *device) struct netvsc_device_info device_info; int ret; - if (!net_drv_obj->Base.OnDeviceAdd) + if (!net_drv_obj->base.OnDeviceAdd) return -1; net = alloc_etherdev(sizeof(struct net_device_context)); @@ -363,7 +366,7 @@ static int netvsc_probe(struct device *device) 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.OnDeviceAdd(device_obj, &device_info); if (ret != 0) { free_netdev(net); dev_set_drvdata(device, NULL); @@ -382,10 +385,10 @@ static int netvsc_probe(struct device *device) * out of sync with the device's link status */ if (!netif_carrier_ok(net)) - if (!device_info.LinkState) + if (!device_info.link_state) netif_carrier_on(net); - memcpy(net->dev_addr, device_info.MacAddr, ETH_ALEN); + memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN); net->netdev_ops = &device_ops; @@ -398,7 +401,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.OnDeviceRemove(device_obj); free_netdev(net); } @@ -422,7 +425,7 @@ static int netvsc_remove(struct device *device) return 0; } - if (!net_drv_obj->Base.OnDeviceRemove) + if (!net_drv_obj->base.OnDeviceRemove) return -1; /* Stop outbound asap */ @@ -435,7 +438,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.OnDeviceRemove(device_obj); if (ret != 0) { /* TODO: */ DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret); @@ -481,8 +484,8 @@ 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.OnCleanup) + netvsc_drv_obj->base.OnCleanup(&netvsc_drv_obj->base); vmbus_child_driver_unregister(drv_ctx); @@ -495,15 +498,15 @@ static int netvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; int ret; - net_drv_obj->RingBufferSize = ring_size * PAGE_SIZE; - net_drv_obj->OnReceiveCallback = netvsc_recv_callback; - net_drv_obj->OnLinkStatusChanged = netvsc_linkstatus_callback; + 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; /* Callback to client driver to complete the initialization */ - drv_init(&net_drv_obj->Base); + 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, + drv_ctx->driver.name = net_drv_obj->base.name; + memcpy(&drv_ctx->class_id, &net_drv_obj->base.deviceType, sizeof(struct hv_guid)); drv_ctx->probe = netvsc_probe; @@ -536,7 +539,7 @@ static int __init netvsc_init(void) if (!dmi_check_system(hv_netvsc_dmi_table)) return -ENODEV; - return netvsc_drv_init(NetVscInitialize); + return netvsc_drv_init(netvsc_initialize); } static void __exit netvsc_exit(void) diff --git a/drivers/staging/hv/osd.c b/drivers/staging/hv/osd.c index 8c3eb278a81f..b5a3940331b3 100644 --- a/drivers/staging/hv/osd.c +++ b/drivers/staging/hv/osd.c @@ -43,13 +43,7 @@ #include <linux/slab.h> #include "osd.h" -struct osd_callback_struct { - struct work_struct work; - void (*callback)(void *); - void *data; -}; - -void *osd_VirtualAllocExec(unsigned int size) +void *osd_virtual_alloc_exec(unsigned int size) { #ifdef __x86_64__ return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL_EXEC); @@ -60,7 +54,7 @@ void *osd_VirtualAllocExec(unsigned int size) } /** - * osd_PageAlloc() - Allocate pages + * 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. @@ -68,7 +62,7 @@ void *osd_VirtualAllocExec(unsigned int size) * If successfull it will return pointer to the @count pages. * Mainly used by Hyper-V drivers. */ -void *osd_PageAlloc(unsigned int count) +void *osd_page_alloc(unsigned int count) { void *p; @@ -85,26 +79,26 @@ void *osd_PageAlloc(unsigned int count) /* if (p) memset(p, 0, PAGE_SIZE); */ /* return p; */ } -EXPORT_SYMBOL_GPL(osd_PageAlloc); +EXPORT_SYMBOL_GPL(osd_page_alloc); /** - * osd_PageFree() - Free pages + * 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_PageAlloc() + * Frees the pages allocated by osd_page_alloc() * Mainly used by Hyper-V drivers. */ -void osd_PageFree(void *page, unsigned int count) +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_PageFree); +EXPORT_SYMBOL_GPL(osd_page_free); /** - * osd_WaitEventCreate() - Create the event queue + * 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. @@ -114,7 +108,7 @@ EXPORT_SYMBOL_GPL(osd_PageFree); * Returns pointer to &struct osd_waitevent * Mainly used by Hyper-V drivers. */ -struct osd_waitevent *osd_WaitEventCreate(void) +struct osd_waitevent *osd_waitevent_create(void) { struct osd_waitevent *wait = kmalloc(sizeof(struct osd_waitevent), GFP_KERNEL); @@ -125,14 +119,14 @@ struct osd_waitevent *osd_WaitEventCreate(void) init_waitqueue_head(&wait->event); return wait; } -EXPORT_SYMBOL_GPL(osd_WaitEventCreate); +EXPORT_SYMBOL_GPL(osd_waitevent_create); /** - * osd_WaitEventSet() - Wake up the process - * @waitEvent: Structure to event to be woken up + * osd_waitevent_set() - Wake up the process + * @wait_event: Structure to event to be woken up * - * @waitevent is of type &struct osd_waitevent + * @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 @@ -140,18 +134,18 @@ EXPORT_SYMBOL_GPL(osd_WaitEventCreate); * * Only used by Network and Storage Hyper-V drivers. */ -void osd_WaitEventSet(struct osd_waitevent *waitEvent) +void osd_waitevent_set(struct osd_waitevent *wait_event) { - waitEvent->condition = 1; - wake_up_interruptible(&waitEvent->event); + wait_event->condition = 1; + wake_up_interruptible(&wait_event->event); } -EXPORT_SYMBOL_GPL(osd_WaitEventSet); +EXPORT_SYMBOL_GPL(osd_waitevent_set); /** - * osd_WaitEventWait() - Wait for event till condition is true - * @waitEvent: Structure to event to be put to sleep + * osd_waitevent_wait() - Wait for event till condition is true + * @wait_event: Structure to event to be put to sleep * - * @waitevent is of type &struct osd_waitevent + * @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 @@ -161,25 +155,25 @@ EXPORT_SYMBOL_GPL(osd_WaitEventSet); * * Mainly used by Hyper-V drivers. */ -int osd_WaitEventWait(struct osd_waitevent *waitEvent) +int osd_waitevent_wait(struct osd_waitevent *wait_event) { int ret = 0; - ret = wait_event_interruptible(waitEvent->event, - waitEvent->condition); - waitEvent->condition = 0; + ret = wait_event_interruptible(wait_event->event, + wait_event->condition); + wait_event->condition = 0; return ret; } -EXPORT_SYMBOL_GPL(osd_WaitEventWait); +EXPORT_SYMBOL_GPL(osd_waitevent_wait); /** - * osd_WaitEventWaitEx() - Wait for event or timeout for process wakeup - * @waitEvent: Structure to event to be put to sleep - * @TimeoutInMs: Total number of Milliseconds to wait before waking up + * 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 * - * @waitevent is of type &struct osd_waitevent + * @wait_event is of type &struct osd_waitevent * Set up the process to sleep until @waitEvent->condition get true or - * @TimeoutInMs (Time out in Milliseconds) has been reached. + * @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. * @@ -187,42 +181,14 @@ EXPORT_SYMBOL_GPL(osd_WaitEventWait); * * Mainly used by Hyper-V drivers. */ -int osd_WaitEventWaitEx(struct osd_waitevent *waitEvent, u32 TimeoutInMs) +int osd_waitevent_waitex(struct osd_waitevent *wait_event, u32 timeout_in_ms) { int ret = 0; - ret = wait_event_interruptible_timeout(waitEvent->event, - waitEvent->condition, - msecs_to_jiffies(TimeoutInMs)); - waitEvent->condition = 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_WaitEventWaitEx); - -static void osd_callback_work(struct work_struct *work) -{ - struct osd_callback_struct *cb = container_of(work, - struct osd_callback_struct, - work); - (cb->callback)(cb->data); - kfree(cb); -} - -int osd_schedule_callback(struct workqueue_struct *wq, - void (*func)(void *), - void *data) -{ - struct osd_callback_struct *cb; - - cb = kmalloc(sizeof(*cb), GFP_KERNEL); - if (!cb) { - printk(KERN_ERR "unable to allocate memory in osd_schedule_callback\n"); - return -1; - } - - cb->callback = func; - cb->data = data; - INIT_WORK(&cb->work, osd_callback_work); - return queue_work(wq, &cb->work); -} - +EXPORT_SYMBOL_GPL(osd_waitevent_waitex); diff --git a/drivers/staging/hv/osd.h b/drivers/staging/hv/osd.h index ce064e8ea644..870ef0768833 100644 --- a/drivers/staging/hv/osd.h +++ b/drivers/staging/hv/osd.h @@ -50,21 +50,17 @@ struct osd_waitevent { /* Osd routines */ -extern void *osd_VirtualAllocExec(unsigned int size); +extern void *osd_virtual_alloc_exec(unsigned int size); -extern void *osd_PageAlloc(unsigned int count); -extern void osd_PageFree(void *page, unsigned int count); +extern void *osd_page_alloc(unsigned int count); +extern void osd_page_free(void *page, unsigned int count); -extern struct osd_waitevent *osd_WaitEventCreate(void); -extern void osd_WaitEventSet(struct osd_waitevent *waitEvent); -extern int osd_WaitEventWait(struct osd_waitevent *waitEvent); +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, waitEvent got signaled. If ==0, timeout. If < 0, error */ -extern int osd_WaitEventWaitEx(struct osd_waitevent *waitEvent, - u32 TimeoutInMs); - -int osd_schedule_callback(struct workqueue_struct *wq, - void (*func)(void *), - void *data); +/* 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 d78c569ac94a..4d53392f1e60 100644 --- a/drivers/staging/hv/ring_buffer.c +++ b/drivers/staging/hv/ring_buffer.c @@ -38,7 +38,7 @@ /*++ Name: - GetRingBufferAvailBytes() + get_ringbuffer_availbytes() Description: Get number of bytes available to read and to write to @@ -46,33 +46,34 @@ Description: --*/ static inline void -GetRingBufferAvailBytes(struct hv_ring_buffer_info *rbi, u32 *read, u32 *write) +get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi, + u32 *read, u32 *write) { u32 read_loc, write_loc; /* Capture the read/write indices before they changed */ - read_loc = rbi->RingBuffer->ReadIndex; - write_loc = rbi->RingBuffer->WriteIndex; + read_loc = rbi->ring_buffer->read_index; + write_loc = rbi->ring_buffer->write_index; - *write = BYTES_AVAIL_TO_WRITE(read_loc, write_loc, rbi->RingDataSize); - *read = rbi->RingDataSize - *write; + *write = BYTES_AVAIL_TO_WRITE(read_loc, write_loc, rbi->ring_datasize); + *read = rbi->ring_datasize - *write; } /*++ Name: - GetNextWriteLocation() + get_next_write_location() Description: Get the next write location for the specified ring buffer --*/ static inline u32 -GetNextWriteLocation(struct hv_ring_buffer_info *RingInfo) +get_next_write_location(struct hv_ring_buffer_info *ring_info) { - u32 next = RingInfo->RingBuffer->WriteIndex; + u32 next = ring_info->ring_buffer->write_index; - /* ASSERT(next < RingInfo->RingDataSize); */ + /* ASSERT(next < ring_info->RingDataSize); */ return next; } @@ -80,34 +81,34 @@ GetNextWriteLocation(struct hv_ring_buffer_info *RingInfo) /*++ Name: - SetNextWriteLocation() + set_next_write_location() Description: Set the next write location for the specified ring buffer --*/ static inline void -SetNextWriteLocation(struct hv_ring_buffer_info *RingInfo, - u32 NextWriteLocation) +set_next_write_location(struct hv_ring_buffer_info *ring_info, + u32 next_write_location) { - RingInfo->RingBuffer->WriteIndex = NextWriteLocation; + ring_info->ring_buffer->write_index = next_write_location; } /*++ Name: - GetNextReadLocation() + get_next_read_location() Description: Get the next read location for the specified ring buffer --*/ static inline u32 -GetNextReadLocation(struct hv_ring_buffer_info *RingInfo) +get_next_read_location(struct hv_ring_buffer_info *ring_info) { - u32 next = RingInfo->RingBuffer->ReadIndex; + u32 next = ring_info->ring_buffer->read_index; - /* ASSERT(next < RingInfo->RingDataSize); */ + /* ASSERT(next < ring_info->RingDataSize); */ return next; } @@ -115,7 +116,7 @@ GetNextReadLocation(struct hv_ring_buffer_info *RingInfo) /*++ Name: - GetNextReadLocationWithOffset() + get_next_readlocation_withoffset() Description: Get the next read location + offset for the specified ring buffer. @@ -123,13 +124,14 @@ Description: --*/ static inline u32 -GetNextReadLocationWithOffset(struct hv_ring_buffer_info *RingInfo, u32 Offset) +get_next_readlocation_withoffset(struct hv_ring_buffer_info *ring_info, + u32 offset) { - u32 next = RingInfo->RingBuffer->ReadIndex; + u32 next = ring_info->ring_buffer->read_index; - /* ASSERT(next < RingInfo->RingDataSize); */ - next += Offset; - next %= RingInfo->RingDataSize; + /* ASSERT(next < ring_info->RingDataSize); */ + next += offset; + next %= ring_info->ring_datasize; return next; } @@ -137,141 +139,145 @@ GetNextReadLocationWithOffset(struct hv_ring_buffer_info *RingInfo, u32 Offset) /*++ Name: - SetNextReadLocation() + set_next_read_location() Description: Set the next read location for the specified ring buffer --*/ static inline void -SetNextReadLocation(struct hv_ring_buffer_info *RingInfo, u32 NextReadLocation) +set_next_read_location(struct hv_ring_buffer_info *ring_info, + u32 next_read_location) { - RingInfo->RingBuffer->ReadIndex = NextReadLocation; + ring_info->ring_buffer->read_index = next_read_location; } /*++ Name: - GetRingBuffer() + get_ring_buffer() Description: Get the start of the ring buffer --*/ static inline void * -GetRingBuffer(struct hv_ring_buffer_info *RingInfo) +get_ring_buffer(struct hv_ring_buffer_info *ring_info) { - return (void *)RingInfo->RingBuffer->Buffer; + return (void *)ring_info->ring_buffer->buffer; } /*++ Name: - GetRingBufferSize() + get_ring_buffersize() Description: Get the size of the ring buffer --*/ static inline u32 -GetRingBufferSize(struct hv_ring_buffer_info *RingInfo) +get_ring_buffersize(struct hv_ring_buffer_info *ring_info) { - return RingInfo->RingDataSize; + return ring_info->ring_datasize; } /*++ Name: - GetRingBufferIndices() + get_ring_bufferindices() Description: Get the read and write indices as u64 of the specified ring buffer --*/ static inline u64 -GetRingBufferIndices(struct hv_ring_buffer_info *RingInfo) +get_ring_bufferindices(struct hv_ring_buffer_info *ring_info) { - return (u64)RingInfo->RingBuffer->WriteIndex << 32; + return (u64)ring_info->ring_buffer->write_index << 32; } /*++ Name: - DumpRingInfo() + dump_ring_info() Description: Dump out to console the ring buffer info --*/ -void DumpRingInfo(struct hv_ring_buffer_info *RingInfo, char *Prefix) +void dump_ring_info(struct hv_ring_buffer_info *ring_info, char *prefix) { - u32 bytesAvailToWrite; - u32 bytesAvailToRead; + u32 bytes_avail_towrite; + u32 bytes_avail_toread; - GetRingBufferAvailBytes(RingInfo, - &bytesAvailToRead, - &bytesAvailToWrite); + get_ringbuffer_availbytes(ring_info, + &bytes_avail_toread, + &bytes_avail_towrite); DPRINT(VMBUS, DEBUG_RING_LVL, "%s <<ringinfo %p buffer %p avail write %u " "avail read %u read idx %u write idx %u>>", - Prefix, - RingInfo, - RingInfo->RingBuffer->Buffer, - bytesAvailToWrite, - bytesAvailToRead, - RingInfo->RingBuffer->ReadIndex, - RingInfo->RingBuffer->WriteIndex); + prefix, + ring_info, + ring_info->ring_buffer->buffer, + bytes_avail_towrite, + bytes_avail_toread, + ring_info->ring_buffer->read_index, + ring_info->ring_buffer->write_index); } /* Internal routines */ static u32 -CopyToRingBuffer( - struct hv_ring_buffer_info *RingInfo, - u32 StartWriteOffset, - void *Src, - u32 SrcLen); +copyto_ringbuffer( + struct hv_ring_buffer_info *ring_info, + u32 start_write_offset, + void *src, + u32 srclen); static u32 -CopyFromRingBuffer( - struct hv_ring_buffer_info *RingInfo, - void *Dest, - u32 DestLen, - u32 StartReadOffset); +copyfrom_ringbuffer( + struct hv_ring_buffer_info *ring_info, + void *dest, + u32 destlen, + u32 start_read_offset); /*++ Name: - RingBufferGetDebugInfo() + ringbuffer_get_debuginfo() Description: Get various debug metrics for the specified ring buffer --*/ -void RingBufferGetDebugInfo(struct hv_ring_buffer_info *RingInfo, +void ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info, struct hv_ring_buffer_debug_info *debug_info) { - u32 bytesAvailToWrite; - u32 bytesAvailToRead; - - if (RingInfo->RingBuffer) { - GetRingBufferAvailBytes(RingInfo, - &bytesAvailToRead, - &bytesAvailToWrite); - - debug_info->BytesAvailToRead = bytesAvailToRead; - debug_info->BytesAvailToWrite = bytesAvailToWrite; - debug_info->CurrentReadIndex = RingInfo->RingBuffer->ReadIndex; - debug_info->CurrentWriteIndex = RingInfo->RingBuffer->WriteIndex; - debug_info->CurrentInterruptMask = RingInfo->RingBuffer->InterruptMask; + u32 bytes_avail_towrite; + u32 bytes_avail_toread; + + if (ring_info->ring_buffer) { + get_ringbuffer_availbytes(ring_info, + &bytes_avail_toread, + &bytes_avail_towrite); + + debug_info->bytes_avail_toread = bytes_avail_toread; + debug_info->bytes_avail_towrite = bytes_avail_towrite; + debug_info->current_read_index = + ring_info->ring_buffer->read_index; + debug_info->current_write_index = + ring_info->ring_buffer->write_index; + debug_info->current_interrupt_mask = + ring_info->ring_buffer->interrupt_mask; } } @@ -279,40 +285,42 @@ void RingBufferGetDebugInfo(struct hv_ring_buffer_info *RingInfo, /*++ Name: - GetRingBufferInterruptMask() + get_ringbuffer_interrupt_mask() Description: Get the interrupt mask for the specified ring buffer --*/ -u32 GetRingBufferInterruptMask(struct hv_ring_buffer_info *rbi) +u32 get_ringbuffer_interrupt_mask(struct hv_ring_buffer_info *rbi) { - return rbi->RingBuffer->InterruptMask; + return rbi->ring_buffer->interrupt_mask; } /*++ Name: - RingBufferInit() + ringbuffer_init() Description: Initialize the ring buffer --*/ -int RingBufferInit(struct hv_ring_buffer_info *RingInfo, void *Buffer, u32 BufferLen) +int ringbuffer_init(struct hv_ring_buffer_info *ring_info, + void *buffer, u32 buflen) { if (sizeof(struct hv_ring_buffer) != PAGE_SIZE) return -EINVAL; - memset(RingInfo, 0, sizeof(struct hv_ring_buffer_info)); + memset(ring_info, 0, sizeof(struct hv_ring_buffer_info)); - RingInfo->RingBuffer = (struct hv_ring_buffer *)Buffer; - RingInfo->RingBuffer->ReadIndex = RingInfo->RingBuffer->WriteIndex = 0; + ring_info->ring_buffer = (struct hv_ring_buffer *)buffer; + ring_info->ring_buffer->read_index = + ring_info->ring_buffer->write_index = 0; - RingInfo->RingSize = BufferLen; - RingInfo->RingDataSize = BufferLen - sizeof(struct hv_ring_buffer); + ring_info->ring_size = buflen; + ring_info->ring_datasize = buflen - sizeof(struct hv_ring_buffer); - spin_lock_init(&RingInfo->ring_lock); + spin_lock_init(&ring_info->ring_lock); return 0; } @@ -320,97 +328,97 @@ int RingBufferInit(struct hv_ring_buffer_info *RingInfo, void *Buffer, u32 Buffe /*++ Name: - RingBufferCleanup() + ringbuffer_cleanup() Description: Cleanup the ring buffer --*/ -void RingBufferCleanup(struct hv_ring_buffer_info *RingInfo) +void ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info) { } /*++ Name: - RingBufferWrite() + ringbuffer_write() Description: Write to the ring buffer --*/ -int RingBufferWrite(struct hv_ring_buffer_info *OutRingInfo, +int ringbuffer_write(struct hv_ring_buffer_info *outring_info, struct scatterlist *sglist, u32 sgcount) { int i = 0; - u32 byteAvailToWrite; - u32 byteAvailToRead; - u32 totalBytesToWrite = 0; + u32 bytes_avail_towrite; + u32 bytes_avail_toread; + u32 totalbytes_towrite = 0; struct scatterlist *sg; - volatile u32 nextWriteLocation; - u64 prevIndices = 0; + volatile u32 next_write_location; + u64 prev_indices = 0; unsigned long flags; for_each_sg(sglist, sg, sgcount, i) { - totalBytesToWrite += sg->length; + totalbytes_towrite += sg->length; } - totalBytesToWrite += sizeof(u64); + totalbytes_towrite += sizeof(u64); - spin_lock_irqsave(&OutRingInfo->ring_lock, flags); + spin_lock_irqsave(&outring_info->ring_lock, flags); - GetRingBufferAvailBytes(OutRingInfo, - &byteAvailToRead, - &byteAvailToWrite); + get_ringbuffer_availbytes(outring_info, + &bytes_avail_toread, + &bytes_avail_towrite); - DPRINT_DBG(VMBUS, "Writing %u bytes...", totalBytesToWrite); + DPRINT_DBG(VMBUS, "Writing %u bytes...", totalbytes_towrite); - /* DumpRingInfo(OutRingInfo, "BEFORE "); */ + /* Dumpring_info(Outring_info, "BEFORE "); */ /* If there is only room for the packet, assume it is full. */ /* Otherwise, the next time around, we think the ring buffer */ /* is empty since the read index == write index */ - if (byteAvailToWrite <= totalBytesToWrite) { + if (bytes_avail_towrite <= totalbytes_towrite) { DPRINT_DBG(VMBUS, "No more space left on outbound ring buffer " "(needed %u, avail %u)", - totalBytesToWrite, - byteAvailToWrite); + totalbytes_towrite, + bytes_avail_towrite); - spin_unlock_irqrestore(&OutRingInfo->ring_lock, flags); + spin_unlock_irqrestore(&outring_info->ring_lock, flags); return -1; } /* Write to the ring buffer */ - nextWriteLocation = GetNextWriteLocation(OutRingInfo); + next_write_location = get_next_write_location(outring_info); for_each_sg(sglist, sg, sgcount, i) { - nextWriteLocation = CopyToRingBuffer(OutRingInfo, - nextWriteLocation, + next_write_location = copyto_ringbuffer(outring_info, + next_write_location, sg_virt(sg), sg->length); } /* Set previous packet start */ - prevIndices = GetRingBufferIndices(OutRingInfo); + prev_indices = get_ring_bufferindices(outring_info); - nextWriteLocation = CopyToRingBuffer(OutRingInfo, - nextWriteLocation, - &prevIndices, + next_write_location = copyto_ringbuffer(outring_info, + next_write_location, + &prev_indices, sizeof(u64)); /* Make sure we flush all writes before updating the writeIndex */ mb(); /* Now, update the write location */ - SetNextWriteLocation(OutRingInfo, nextWriteLocation); + set_next_write_location(outring_info, next_write_location); - /* DumpRingInfo(OutRingInfo, "AFTER "); */ + /* Dumpring_info(Outring_info, "AFTER "); */ - spin_unlock_irqrestore(&OutRingInfo->ring_lock, flags); + spin_unlock_irqrestore(&outring_info->ring_lock, flags); return 0; } @@ -418,47 +426,48 @@ int RingBufferWrite(struct hv_ring_buffer_info *OutRingInfo, /*++ Name: - RingBufferPeek() + ringbuffer_peek() Description: Read without advancing the read index --*/ -int RingBufferPeek(struct hv_ring_buffer_info *InRingInfo, void *Buffer, u32 BufferLen) +int ringbuffer_peek(struct hv_ring_buffer_info *Inring_info, + void *Buffer, u32 buflen) { - u32 bytesAvailToWrite; - u32 bytesAvailToRead; - u32 nextReadLocation = 0; + u32 bytes_avail_towrite; + u32 bytes_avail_toread; + u32 next_read_location = 0; unsigned long flags; - spin_lock_irqsave(&InRingInfo->ring_lock, flags); + spin_lock_irqsave(&Inring_info->ring_lock, flags); - GetRingBufferAvailBytes(InRingInfo, - &bytesAvailToRead, - &bytesAvailToWrite); + get_ringbuffer_availbytes(Inring_info, + &bytes_avail_toread, + &bytes_avail_towrite); /* Make sure there is something to read */ - if (bytesAvailToRead < BufferLen) { + if (bytes_avail_toread < buflen) { /* DPRINT_DBG(VMBUS, "got callback but not enough to read " "<avail to read %d read size %d>!!", - bytesAvailToRead, + bytes_avail_toread, BufferLen); */ - spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); + spin_unlock_irqrestore(&Inring_info->ring_lock, flags); return -1; } /* Convert to byte offset */ - nextReadLocation = GetNextReadLocation(InRingInfo); + next_read_location = get_next_read_location(Inring_info); - nextReadLocation = CopyFromRingBuffer(InRingInfo, + next_read_location = copyfrom_ringbuffer(Inring_info, Buffer, - BufferLen, - nextReadLocation); + buflen, + next_read_location); - spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); + spin_unlock_irqrestore(&Inring_info->ring_lock, flags); return 0; } @@ -467,58 +476,59 @@ int RingBufferPeek(struct hv_ring_buffer_info *InRingInfo, void *Buffer, u32 Buf /*++ Name: - RingBufferRead() + ringbuffer_read() Description: Read and advance the read index --*/ -int RingBufferRead(struct hv_ring_buffer_info *InRingInfo, void *Buffer, - u32 BufferLen, u32 Offset) +int ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer, + u32 buflen, u32 offset) { - u32 bytesAvailToWrite; - u32 bytesAvailToRead; - u32 nextReadLocation = 0; - u64 prevIndices = 0; + u32 bytes_avail_towrite; + u32 bytes_avail_toread; + u32 next_read_location = 0; + u64 prev_indices = 0; unsigned long flags; - if (BufferLen <= 0) + if (buflen <= 0) return -EINVAL; - spin_lock_irqsave(&InRingInfo->ring_lock, flags); + spin_lock_irqsave(&inring_info->ring_lock, flags); - GetRingBufferAvailBytes(InRingInfo, - &bytesAvailToRead, - &bytesAvailToWrite); + get_ringbuffer_availbytes(inring_info, + &bytes_avail_toread, + &bytes_avail_towrite); - DPRINT_DBG(VMBUS, "Reading %u bytes...", BufferLen); + DPRINT_DBG(VMBUS, "Reading %u bytes...", buflen); - /* DumpRingInfo(InRingInfo, "BEFORE "); */ + /* Dumpring_info(Inring_info, "BEFORE "); */ /* Make sure there is something to read */ - if (bytesAvailToRead < BufferLen) { + if (bytes_avail_toread < buflen) { DPRINT_DBG(VMBUS, "got callback but not enough to read " "<avail to read %d read size %d>!!", - bytesAvailToRead, - BufferLen); + bytes_avail_toread, + buflen); - spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); + spin_unlock_irqrestore(&inring_info->ring_lock, flags); return -1; } - nextReadLocation = GetNextReadLocationWithOffset(InRingInfo, Offset); + next_read_location = + get_next_readlocation_withoffset(inring_info, offset); - nextReadLocation = CopyFromRingBuffer(InRingInfo, - Buffer, - BufferLen, - nextReadLocation); + next_read_location = copyfrom_ringbuffer(inring_info, + buffer, + buflen, + next_read_location); - nextReadLocation = CopyFromRingBuffer(InRingInfo, - &prevIndices, + next_read_location = copyfrom_ringbuffer(inring_info, + &prev_indices, sizeof(u64), - nextReadLocation); + next_read_location); /* Make sure all reads are done before we update the read index since */ /* the writer may start writing to the read area once the read index */ @@ -526,11 +536,11 @@ int RingBufferRead(struct hv_ring_buffer_info *InRingInfo, void *Buffer, mb(); /* Update the read index */ - SetNextReadLocation(InRingInfo, nextReadLocation); + set_next_read_location(inring_info, next_read_location); - /* DumpRingInfo(InRingInfo, "AFTER "); */ + /* Dumpring_info(Inring_info, "AFTER "); */ - spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); + spin_unlock_irqrestore(&inring_info->ring_lock, flags); return 0; } @@ -539,7 +549,7 @@ int RingBufferRead(struct hv_ring_buffer_info *InRingInfo, void *Buffer, /*++ Name: - CopyToRingBuffer() + copyto_ringbuffer() Description: Helper routine to copy from source to ring buffer. @@ -547,37 +557,37 @@ Description: --*/ static u32 -CopyToRingBuffer( - struct hv_ring_buffer_info *RingInfo, - u32 StartWriteOffset, - void *Src, - u32 SrcLen) +copyto_ringbuffer( + struct hv_ring_buffer_info *ring_info, + u32 start_write_offset, + void *src, + u32 srclen) { - void *ringBuffer = GetRingBuffer(RingInfo); - u32 ringBufferSize = GetRingBufferSize(RingInfo); - u32 fragLen; + void *ring_buffer = get_ring_buffer(ring_info); + u32 ring_buffer_size = get_ring_buffersize(ring_info); + u32 frag_len; /* wrap-around detected! */ - if (SrcLen > ringBufferSize - StartWriteOffset) { + if (srclen > ring_buffer_size - start_write_offset) { DPRINT_DBG(VMBUS, "wrap-around detected!"); - fragLen = ringBufferSize - StartWriteOffset; - memcpy(ringBuffer + StartWriteOffset, Src, fragLen); - memcpy(ringBuffer, Src + fragLen, SrcLen - fragLen); + frag_len = ring_buffer_size - start_write_offset; + memcpy(ring_buffer + start_write_offset, src, frag_len); + memcpy(ring_buffer, src + frag_len, srclen - frag_len); } else - memcpy(ringBuffer + StartWriteOffset, Src, SrcLen); + memcpy(ring_buffer + start_write_offset, src, srclen); - StartWriteOffset += SrcLen; - StartWriteOffset %= ringBufferSize; + start_write_offset += srclen; + start_write_offset %= ring_buffer_size; - return StartWriteOffset; + return start_write_offset; } /*++ Name: - CopyFromRingBuffer() + copyfrom_ringbuffer() Description: Helper routine to copy to source from ring buffer. @@ -585,34 +595,34 @@ Description: --*/ static u32 -CopyFromRingBuffer( - struct hv_ring_buffer_info *RingInfo, - void *Dest, - u32 DestLen, - u32 StartReadOffset) +copyfrom_ringbuffer( + struct hv_ring_buffer_info *ring_info, + void *dest, + u32 destlen, + u32 start_read_offset) { - void *ringBuffer = GetRingBuffer(RingInfo); - u32 ringBufferSize = GetRingBufferSize(RingInfo); + void *ring_buffer = get_ring_buffer(ring_info); + u32 ring_buffer_size = get_ring_buffersize(ring_info); - u32 fragLen; + u32 frag_len; /* wrap-around detected at the src */ - if (DestLen > ringBufferSize - StartReadOffset) { + if (destlen > ring_buffer_size - start_read_offset) { DPRINT_DBG(VMBUS, "src wrap-around detected!"); - fragLen = ringBufferSize - StartReadOffset; + frag_len = ring_buffer_size - start_read_offset; - memcpy(Dest, ringBuffer + StartReadOffset, fragLen); - memcpy(Dest + fragLen, ringBuffer, DestLen - fragLen); + memcpy(dest, ring_buffer + start_read_offset, frag_len); + memcpy(dest + frag_len, ring_buffer, destlen - frag_len); } else - memcpy(Dest, ringBuffer + StartReadOffset, DestLen); + memcpy(dest, ring_buffer + start_read_offset, destlen); - StartReadOffset += DestLen; - StartReadOffset %= ringBufferSize; + start_read_offset += destlen; + start_read_offset %= ring_buffer_size; - return StartReadOffset; + return start_read_offset; } diff --git a/drivers/staging/hv/ring_buffer.h b/drivers/staging/hv/ring_buffer.h index a7f1717c6a56..7bd6ecf2f015 100644 --- a/drivers/staging/hv/ring_buffer.h +++ b/drivers/staging/hv/ring_buffer.h @@ -29,18 +29,18 @@ struct hv_ring_buffer { /* Offset in bytes from the start of ring data below */ - volatile u32 WriteIndex; + volatile u32 write_index; /* Offset in bytes from the start of ring data below */ - volatile u32 ReadIndex; + volatile u32 read_index; - volatile u32 InterruptMask; + volatile u32 interrupt_mask; /* Pad it to PAGE_SIZE so that data starts on page boundary */ - u8 Reserved[4084]; + u8 reserved[4084]; /* NOTE: - * The InterruptMask field is used only for channels but since our + * The interrupt_mask field is used only for channels but since our * vmbus connection also uses this data structure and its data starts * here, we commented out this field. */ @@ -50,24 +50,24 @@ struct hv_ring_buffer { * Ring data starts here + RingDataStartOffset * !!! DO NOT place any fields below this !!! */ - u8 Buffer[0]; + u8 buffer[0]; } __attribute__((packed)); struct hv_ring_buffer_info { - struct hv_ring_buffer *RingBuffer; - u32 RingSize; /* Include the shared header */ + struct hv_ring_buffer *ring_buffer; + u32 ring_size; /* Include the shared header */ spinlock_t ring_lock; - u32 RingDataSize; /* < ringSize */ - u32 RingDataStartOffset; + u32 ring_datasize; /* < ring_size */ + u32 ring_data_startoffset; }; struct hv_ring_buffer_debug_info { - u32 CurrentInterruptMask; - u32 CurrentReadIndex; - u32 CurrentWriteIndex; - u32 BytesAvailToRead; - u32 BytesAvailToWrite; + u32 current_interrupt_mask; + u32 current_read_index; + u32 current_write_index; + u32 bytes_avail_toread; + u32 bytes_avail_towrite; }; @@ -75,28 +75,28 @@ struct hv_ring_buffer_debug_info { /* Interface */ -int RingBufferInit(struct hv_ring_buffer_info *RingInfo, void *Buffer, - u32 BufferLen); +int ringbuffer_init(struct hv_ring_buffer_info *ring_info, void *buffer, + u32 buflen); -void RingBufferCleanup(struct hv_ring_buffer_info *RingInfo); +void ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info); -int RingBufferWrite(struct hv_ring_buffer_info *RingInfo, +int ringbuffer_write(struct hv_ring_buffer_info *ring_info, struct scatterlist *sglist, u32 sgcount); -int RingBufferPeek(struct hv_ring_buffer_info *RingInfo, void *Buffer, - u32 BufferLen); +int ringbuffer_peek(struct hv_ring_buffer_info *ring_info, void *buffer, + u32 buflen); -int RingBufferRead(struct hv_ring_buffer_info *RingInfo, - void *Buffer, - u32 BufferLen, - u32 Offset); +int ringbuffer_read(struct hv_ring_buffer_info *ring_info, + void *buffer, + u32 buflen, + u32 offset); -u32 GetRingBufferInterruptMask(struct hv_ring_buffer_info *RingInfo); +u32 get_ringbuffer_interrupt_mask(struct hv_ring_buffer_info *ring_info); -void DumpRingInfo(struct hv_ring_buffer_info *RingInfo, char *Prefix); +void dump_ring_info(struct hv_ring_buffer_info *ring_info, char *prefix); -void RingBufferGetDebugInfo(struct hv_ring_buffer_info *RingInfo, +void ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info, struct hv_ring_buffer_debug_info *debug_info); #endif /* _RING_BUFFER_H_ */ diff --git a/drivers/staging/hv/rndis.h b/drivers/staging/hv/rndis.h index 723e1f15b90d..014de047b86d 100644 --- a/drivers/staging/hv/rndis.h +++ b/drivers/staging/hv/rndis.h @@ -288,24 +288,24 @@ #define RNDIS_DF_RAW_DATA 0x00000004 /* Remote NDIS medium types. */ -#define RNdisMedium802_3 0x00000000 -#define RNdisMedium802_5 0x00000001 -#define RNdisMediumFddi 0x00000002 -#define RNdisMediumWan 0x00000003 -#define RNdisMediumLocalTalk 0x00000004 -#define RNdisMediumArcnetRaw 0x00000006 -#define RNdisMediumArcnet878_2 0x00000007 -#define RNdisMediumAtm 0x00000008 -#define RNdisMediumWirelessWan 0x00000009 -#define RNdisMediumIrda 0x0000000a -#define RNdisMediumCoWan 0x0000000b +#define RNDIS_MEDIUM_802_3 0x00000000 +#define RNDIS_MEDIUM_802_5 0x00000001 +#define RNDIS_MEDIUM_FDDI 0x00000002 +#define RNDIS_MEDIUM_WAN 0x00000003 +#define RNDIS_MEDIUM_LOCAL_TALK 0x00000004 +#define RNDIS_MEDIUM_ARCNET_RAW 0x00000006 +#define RNDIS_MEDIUM_ARCNET_878_2 0x00000007 +#define RNDIS_MEDIUM_ATM 0x00000008 +#define RNDIS_MEDIUM_WIRELESS_WAN 0x00000009 +#define RNDIS_MEDIUM_IRDA 0x0000000a +#define RNDIS_MEDIUM_CO_WAN 0x0000000b /* Not a real medium, defined as an upper-bound */ -#define RNdisMediumMax 0x0000000d +#define RNDIS_MEDIUM_MAX 0x0000000d /* Remote NDIS medium connection states. */ -#define RNdisMediaStateConnected 0x00000000 -#define RNdisMediaStateDisconnected 0x00000001 +#define RNDIS_MEDIA_STATE_CONNECTED 0x00000000 +#define RNDIS_MEDIA_STATE_DISCONNECTED 0x00000001 /* Remote NDIS version numbers */ #define RNDIS_MAJOR_VERSION 0x00000001 @@ -314,106 +314,106 @@ /* NdisInitialize message */ struct rndis_initialize_request { - u32 RequestId; - u32 MajorVersion; - u32 MinorVersion; - u32 MaxTransferSize; + u32 req_id; + u32 major_ver; + u32 minor_ver; + u32 max_xfer_size; }; /* Response to NdisInitialize */ struct rndis_initialize_complete { - u32 RequestId; - u32 Status; - u32 MajorVersion; - u32 MinorVersion; - u32 DeviceFlags; - u32 Medium; - u32 MaxPacketsPerMessage; - u32 MaxTransferSize; - u32 PacketAlignmentFactor; - u32 AFListOffset; - u32 AFListSize; + u32 req_id; + u32 status; + u32 major_ver; + u32 minor_ver; + u32 dev_flags; + u32 medium; + u32 max_pkt_per_msg; + u32 max_xfer_size; + u32 pkt_alignment_factor; + u32 af_list_offset; + u32 af_list_size; }; /* Call manager devices only: Information about an address family */ /* supported by the device is appended to the response to NdisInitialize. */ struct rndis_co_address_family { - u32 AddressFamily; - u32 MajorVersion; - u32 MinorVersion; + u32 address_family; + u32 major_ver; + u32 minor_ver; }; /* NdisHalt message */ struct rndis_halt_request { - u32 RequestId; + u32 req_id; }; /* NdisQueryRequest message */ struct rndis_query_request { - u32 RequestId; - u32 Oid; - u32 InformationBufferLength; - u32 InformationBufferOffset; - u32 DeviceVcHandle; + u32 req_id; + u32 oid; + u32 info_buflen; + u32 info_buf_offset; + u32 dev_vc_handle; }; /* Response to NdisQueryRequest */ struct rndis_query_complete { - u32 RequestId; - u32 Status; - u32 InformationBufferLength; - u32 InformationBufferOffset; + u32 req_id; + u32 status; + u32 info_buflen; + u32 info_buf_offset; }; /* NdisSetRequest message */ struct rndis_set_request { - u32 RequestId; - u32 Oid; - u32 InformationBufferLength; - u32 InformationBufferOffset; - u32 DeviceVcHandle; + u32 req_id; + u32 oid; + u32 info_buflen; + u32 info_buf_offset; + u32 dev_vc_handle; }; /* Response to NdisSetRequest */ struct rndis_set_complete { - u32 RequestId; - u32 Status; + u32 req_id; + u32 status; }; /* NdisReset message */ struct rndis_reset_request { - u32 Reserved; + u32 reserved; }; /* Response to NdisReset */ struct rndis_reset_complete { - u32 Status; - u32 AddressingReset; + u32 status; + u32 addressing_reset; }; /* NdisMIndicateStatus message */ struct rndis_indicate_status { - u32 Status; - u32 StatusBufferLength; - u32 StatusBufferOffset; + u32 status; + u32 status_buflen; + u32 status_buf_offset; }; /* Diagnostic information passed as the status buffer in */ /* struct rndis_indicate_status messages signifying error conditions. */ struct rndis_diagnostic_info { - u32 DiagStatus; - u32 ErrorOffset; + u32 diag_status; + u32 error_offset; }; /* NdisKeepAlive message */ struct rndis_keepalive_request { - u32 RequestId; + u32 req_id; }; /* Response to NdisKeepAlive */ struct rndis_keepalive_complete { - u32 RequestId; - u32 Status; + u32 req_id; + u32 status; }; /* @@ -422,39 +422,39 @@ struct rndis_keepalive_complete { * to 0 for connectionless data, otherwise it contains the VC handle. */ struct rndis_packet { - u32 DataOffset; - u32 DataLength; - u32 OOBDataOffset; - u32 OOBDataLength; - u32 NumOOBDataElements; - u32 PerPacketInfoOffset; - u32 PerPacketInfoLength; - u32 VcHandle; - u32 Reserved; + u32 data_offset; + u32 data_len; + u32 oob_data_offset; + u32 oob_data_len; + u32 num_oob_data_elements; + u32 per_pkt_info_offset; + u32 per_pkt_info_len; + u32 vc_handle; + u32 reserved; }; /* Optional Out of Band data associated with a Data message. */ struct rndis_oobd { - u32 Size; - u32 Type; - u32 ClassInformationOffset; + u32 size; + u32 type; + u32 class_info_offset; }; /* Packet extension field contents associated with a Data message. */ struct rndis_per_packet_info { - u32 Size; - u32 Type; - u32 PerPacketInformationOffset; + u32 size; + u32 type; + u32 per_pkt_info_offset; }; /* Format of Information buffer passed in a SetRequest for the OID */ /* OID_GEN_RNDIS_CONFIG_PARAMETER. */ struct rndis_config_parameter_info { - u32 ParameterNameOffset; - u32 ParameterNameLength; - u32 ParameterType; - u32 ParameterValueOffset; - u32 ParameterValueLength; + u32 parameter_name_offset; + u32 parameter_name_length; + u32 parameter_type; + u32 parameter_value_offset; + u32 parameter_value_length; }; /* Values for ParameterType in struct rndis_config_parameter_info */ @@ -466,187 +466,188 @@ struct rndis_config_parameter_info { /* CoNdisMiniportCreateVc message */ struct rcondis_mp_create_vc { - u32 RequestId; - u32 NdisVcHandle; + u32 req_id; + u32 ndis_vc_handle; }; /* Response to CoNdisMiniportCreateVc */ struct rcondis_mp_create_vc_complete { - u32 RequestId; - u32 DeviceVcHandle; - u32 Status; + u32 req_id; + u32 dev_vc_handle; + u32 status; }; /* CoNdisMiniportDeleteVc message */ struct rcondis_mp_delete_vc { - u32 RequestId; - u32 DeviceVcHandle; + u32 req_id; + u32 dev_vc_handle; }; /* Response to CoNdisMiniportDeleteVc */ struct rcondis_mp_delete_vc_complete { - u32 RequestId; - u32 Status; + u32 req_id; + u32 status; }; /* CoNdisMiniportQueryRequest message */ struct rcondis_mp_query_request { - u32 RequestId; - u32 RequestType; - u32 Oid; - u32 DeviceVcHandle; - u32 InformationBufferLength; - u32 InformationBufferOffset; + u32 req_id; + u32 request_type; + u32 oid; + u32 dev_vc_handle; + u32 info_buflen; + u32 info_buf_offset; }; /* CoNdisMiniportSetRequest message */ struct rcondis_mp_set_request { - u32 RequestId; - u32 RequestType; - u32 Oid; - u32 DeviceVcHandle; - u32 InformationBufferLength; - u32 InformationBufferOffset; + u32 req_id; + u32 request_type; + u32 oid; + u32 dev_vc_handle; + u32 info_buflen; + u32 info_buf_offset; }; /* CoNdisIndicateStatus message */ struct rcondis_indicate_status { - u32 NdisVcHandle; - u32 Status; - u32 StatusBufferLength; - u32 StatusBufferOffset; + u32 ndis_vc_handle; + u32 status; + u32 status_buflen; + u32 status_buf_offset; }; /* CONDIS Call/VC parameters */ struct rcondis_specific_parameters { - u32 ParameterType; - u32 ParameterLength; - u32 ParameterOffset; + u32 parameter_type; + u32 parameter_length; + u32 parameter_lffset; }; struct rcondis_media_parameters { - u32 Flags; - u32 Reserved1; - u32 Reserved2; - struct rcondis_specific_parameters MediaSpecific; + u32 flags; + u32 reserved1; + u32 reserved2; + struct rcondis_specific_parameters media_specific; }; struct rndis_flowspec { - u32 TokenRate; - u32 TokenBucketSize; - u32 PeakBandwidth; - u32 Latency; - u32 DelayVariation; - u32 ServiceType; - u32 MaxSduSize; - u32 MinimumPolicedSize; + u32 token_rate; + u32 token_bucket_size; + u32 peak_bandwidth; + u32 latency; + u32 delay_variation; + u32 service_type; + u32 max_sdu_size; + u32 minimum_policed_size; }; struct rcondis_call_manager_parameters { - struct rndis_flowspec Transmit; - struct rndis_flowspec Receive; - struct rcondis_specific_parameters CallMgrSpecific; + struct rndis_flowspec transmit; + struct rndis_flowspec receive; + struct rcondis_specific_parameters call_mgr_specific; }; /* CoNdisMiniportActivateVc message */ struct rcondis_mp_activate_vc_request { - u32 RequestId; - u32 Flags; - u32 DeviceVcHandle; - u32 MediaParamsOffset; - u32 MediaParamsLength; - u32 CallMgrParamsOffset; - u32 CallMgrParamsLength; + u32 req_id; + u32 flags; + u32 dev_vc_handle; + u32 media_params_offset; + u32 media_params_length; + u32 call_mgr_params_offset; + u32 call_mgr_params_length; }; /* Response to CoNdisMiniportActivateVc */ struct rcondis_mp_activate_vc_complete { - u32 RequestId; - u32 Status; + u32 req_id; + u32 status; }; /* CoNdisMiniportDeactivateVc message */ struct rcondis_mp_deactivate_vc_request { - u32 RequestId; - u32 Flags; - u32 DeviceVcHandle; + u32 req_id; + u32 flags; + u32 dev_vc_handle; }; /* Response to CoNdisMiniportDeactivateVc */ struct rcondis_mp_deactivate_vc_complete { - u32 RequestId; - u32 Status; + u32 req_id; + u32 status; }; /* union with all of the RNDIS messages */ union rndis_message_container { - struct rndis_packet Packet; - struct rndis_initialize_request InitializeRequest; - struct rndis_halt_request HaltRequest; - struct rndis_query_request QueryRequest; - struct rndis_set_request SetRequest; - struct rndis_reset_request ResetRequest; - struct rndis_keepalive_request KeepaliveRequest; - struct rndis_indicate_status IndicateStatus; - struct rndis_initialize_complete InitializeComplete; - struct rndis_query_complete QueryComplete; - struct rndis_set_complete SetComplete; - struct rndis_reset_complete ResetComplete; - struct rndis_keepalive_complete KeepaliveComplete; - struct rcondis_mp_create_vc CoMiniportCreateVc; - struct rcondis_mp_delete_vc CoMiniportDeleteVc; - struct rcondis_indicate_status CoIndicateStatus; - struct rcondis_mp_activate_vc_request CoMiniportActivateVc; - struct rcondis_mp_deactivate_vc_request CoMiniportDeactivateVc; - struct rcondis_mp_create_vc_complete CoMiniportCreateVcComplete; - struct rcondis_mp_delete_vc_complete CoMiniportDeleteVcComplete; - struct rcondis_mp_activate_vc_complete CoMiniportActivateVcComplete; - struct rcondis_mp_deactivate_vc_complete CoMiniportDeactivateVcComplete; + struct rndis_packet pkt; + struct rndis_initialize_request init_req; + struct rndis_halt_request halt_req; + struct rndis_query_request query_req; + struct rndis_set_request set_req; + struct rndis_reset_request reset_req; + struct rndis_keepalive_request keep_alive_req; + struct rndis_indicate_status indicate_status; + struct rndis_initialize_complete init_complete; + struct rndis_query_complete query_complete; + struct rndis_set_complete set_complete; + struct rndis_reset_complete reset_complete; + struct rndis_keepalive_complete keep_alive_complete; + struct rcondis_mp_create_vc co_miniport_create_vc; + struct rcondis_mp_delete_vc co_miniport_delete_vc; + struct rcondis_indicate_status co_indicate_status; + struct rcondis_mp_activate_vc_request co_miniport_activate_vc; + struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc; + struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete; + struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete; + struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete; + struct rcondis_mp_deactivate_vc_complete + co_miniport_deactivate_vc_complete; }; /* Remote NDIS message format */ struct rndis_message { - u32 NdisMessageType; + u32 ndis_msg_type; /* Total length of this message, from the beginning */ /* of the sruct rndis_message, in bytes. */ - u32 MessageLength; + u32 msg_len; /* Actual message */ - union rndis_message_container Message; + union rndis_message_container msg; }; /* Handy macros */ /* get the size of an RNDIS message. Pass in the message type, */ /* struct rndis_set_request, struct rndis_packet for example */ -#define RNDIS_MESSAGE_SIZE(Message) \ - (sizeof(Message) + (sizeof(struct rndis_message) - \ +#define RNDIS_MESSAGE_SIZE(msg) \ + (sizeof(msg) + (sizeof(struct rndis_message) - \ sizeof(union rndis_message_container))) /* get pointer to info buffer with message pointer */ -#define MESSAGE_TO_INFO_BUFFER(Message) \ - (((unsigned char *)(Message)) + Message->InformationBufferOffset) +#define MESSAGE_TO_INFO_BUFFER(msg) \ + (((unsigned char *)(msg)) + msg->info_buf_offset) /* get pointer to status buffer with message pointer */ -#define MESSAGE_TO_STATUS_BUFFER(Message) \ - (((unsigned char *)(Message)) + Message->StatusBufferOffset) +#define MESSAGE_TO_STATUS_BUFFER(msg) \ + (((unsigned char *)(msg)) + msg->status_buf_offset) /* get pointer to OOBD buffer with message pointer */ -#define MESSAGE_TO_OOBD_BUFFER(Message) \ - (((unsigned char *)(Message)) + Message->OOBDataOffset) +#define MESSAGE_TO_OOBD_BUFFER(msg) \ + (((unsigned char *)(msg)) + msg->oob_data_offset) /* get pointer to data buffer with message pointer */ -#define MESSAGE_TO_DATA_BUFFER(Message) \ - (((unsigned char *)(Message)) + Message->PerPacketInfoOffset) +#define MESSAGE_TO_DATA_BUFFER(msg) \ + (((unsigned char *)(msg)) + msg->per_pkt_info_offset) /* get pointer to contained message from NDIS_MESSAGE pointer */ -#define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(RndisMessage) \ - ((void *) &RndisMessage->Message) +#define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg) \ + ((void *) &rndis_msg->msg) /* get pointer to contained message from NDIS_MESSAGE pointer */ -#define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(RndisMessage) \ - ((void *) RndisMessage) +#define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \ + ((void *) rndis_msg) #endif /* _RNDIS_H_ */ diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c index fa2141f454f0..53676dcbf381 100644 --- a/drivers/staging/hv/rndis_filter.c +++ b/drivers/staging/hv/rndis_filter.c @@ -32,7 +32,7 @@ /* Data types */ struct rndis_filter_driver_object { /* The original driver */ - struct netvsc_driver InnerDriver; + struct netvsc_driver inner_drv; }; enum rndis_device_state { @@ -43,63 +43,63 @@ enum rndis_device_state { }; struct rndis_device { - struct netvsc_device *NetDevice; + struct netvsc_device *net_dev; - enum rndis_device_state State; - u32 LinkStatus; - atomic_t NewRequestId; + enum rndis_device_state state; + u32 link_stat; + atomic_t new_req_id; spinlock_t request_lock; - struct list_head RequestList; + struct list_head req_list; - unsigned char HwMacAddr[ETH_ALEN]; + unsigned char hw_mac_adr[ETH_ALEN]; }; struct rndis_request { - struct list_head ListEntry; - struct osd_waitevent *WaitEvent; + struct list_head list_ent; + struct osd_waitevent *waitevent; /* * FIXME: We assumed a fixed size response here. If we do ever need to * handle a bigger response, we can either define a max response * message or add a response buffer variable above this field */ - struct rndis_message ResponseMessage; + struct rndis_message response_msg; /* Simplify allocation by having a netvsc packet inline */ - struct hv_netvsc_packet Packet; - struct hv_page_buffer Buffer; + struct hv_netvsc_packet pkt; + struct hv_page_buffer buf; /* FIXME: We assumed a fixed size request here. */ - struct rndis_message RequestMessage; + struct rndis_message request_msg; }; struct rndis_filter_packet { - void *CompletionContext; - void (*OnCompletion)(void *context); - struct rndis_message Message; + void *completion_ctx; + void (*completion)(void *context); + struct rndis_message msg; }; -static int RndisFilterOnDeviceAdd(struct hv_device *Device, - void *AdditionalInfo); +static int rndis_filte_device_add(struct hv_device *dev, + void *additional_info); -static int RndisFilterOnDeviceRemove(struct hv_device *Device); +static int rndis_filter_device_remove(struct hv_device *dev); -static void RndisFilterOnCleanup(struct hv_driver *Driver); +static void rndis_filter_cleanup(struct hv_driver *drv); -static int RndisFilterOnSend(struct hv_device *Device, - struct hv_netvsc_packet *Packet); +static int rndis_filter_send(struct hv_device *dev, + struct hv_netvsc_packet *pkt); -static void RndisFilterOnSendCompletion(void *Context); +static void rndis_filter_send_completion(void *ctx); -static void RndisFilterOnSendRequestCompletion(void *Context); +static void rndis_filter_send_request_completion(void *ctx); /* The one and only */ -static struct rndis_filter_driver_object gRndisFilter; +static struct rndis_filter_driver_object rndis_filter; -static struct rndis_device *GetRndisDevice(void) +static struct rndis_device *get_rndis_device(void) { struct rndis_device *device; @@ -109,19 +109,19 @@ static struct rndis_device *GetRndisDevice(void) spin_lock_init(&device->request_lock); - INIT_LIST_HEAD(&device->RequestList); + INIT_LIST_HEAD(&device->req_list); - device->State = RNDIS_DEV_UNINITIALIZED; + device->state = RNDIS_DEV_UNINITIALIZED; return device; } -static struct rndis_request *GetRndisRequest(struct rndis_device *Device, - u32 MessageType, - u32 MessageLength) +static struct rndis_request *get_rndis_request(struct rndis_device *dev, + u32 msg_type, + u32 msg_len) { struct rndis_request *request; - struct rndis_message *rndisMessage; + struct rndis_message *rndis_msg; struct rndis_set_request *set; unsigned long flags; @@ -129,61 +129,61 @@ static struct rndis_request *GetRndisRequest(struct rndis_device *Device, if (!request) return NULL; - request->WaitEvent = osd_WaitEventCreate(); - if (!request->WaitEvent) { + request->waitevent = osd_waitevent_create(); + if (!request->waitevent) { kfree(request); return NULL; } - rndisMessage = &request->RequestMessage; - rndisMessage->NdisMessageType = MessageType; - rndisMessage->MessageLength = MessageLength; + rndis_msg = &request->request_msg; + rndis_msg->ndis_msg_type = msg_type; + rndis_msg->msg_len = msg_len; /* * Set the request id. This field is always after the rndis header for * request/response packet types so we just used the SetRequest as a * template */ - set = &rndisMessage->Message.SetRequest; - set->RequestId = atomic_inc_return(&Device->NewRequestId); + set = &rndis_msg->msg.set_req; + set->req_id = atomic_inc_return(&dev->new_req_id); /* Add to the request list */ - spin_lock_irqsave(&Device->request_lock, flags); - list_add_tail(&request->ListEntry, &Device->RequestList); - spin_unlock_irqrestore(&Device->request_lock, flags); + spin_lock_irqsave(&dev->request_lock, flags); + list_add_tail(&request->list_ent, &dev->req_list); + spin_unlock_irqrestore(&dev->request_lock, flags); return request; } -static void PutRndisRequest(struct rndis_device *Device, - struct rndis_request *Request) +static void put_rndis_request(struct rndis_device *dev, + struct rndis_request *req) { unsigned long flags; - spin_lock_irqsave(&Device->request_lock, flags); - list_del(&Request->ListEntry); - spin_unlock_irqrestore(&Device->request_lock, flags); + spin_lock_irqsave(&dev->request_lock, flags); + list_del(&req->list_ent); + spin_unlock_irqrestore(&dev->request_lock, flags); - kfree(Request->WaitEvent); - kfree(Request); + kfree(req->waitevent); + kfree(req); } -static void DumpRndisMessage(struct rndis_message *RndisMessage) +static void dump_rndis_message(struct rndis_message *rndis_msg) { - switch (RndisMessage->NdisMessageType) { + switch (rndis_msg->ndis_msg_type) { case REMOTE_NDIS_PACKET_MSG: DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, " "data offset %u data len %u, # oob %u, " "oob offset %u, oob len %u, pkt offset %u, " "pkt len %u", - RndisMessage->MessageLength, - RndisMessage->Message.Packet.DataOffset, - RndisMessage->Message.Packet.DataLength, - RndisMessage->Message.Packet.NumOOBDataElements, - RndisMessage->Message.Packet.OOBDataOffset, - RndisMessage->Message.Packet.OOBDataLength, - RndisMessage->Message.Packet.PerPacketInfoOffset, - RndisMessage->Message.Packet.PerPacketInfoLength); + rndis_msg->msg_len, + rndis_msg->msg.pkt.data_offset, + rndis_msg->msg.pkt.data_len, + rndis_msg->msg.pkt.num_oob_data_elements, + rndis_msg->msg.pkt.oob_data_offset, + rndis_msg->msg.pkt.oob_data_len, + rndis_msg->msg.pkt.per_pkt_info_offset, + rndis_msg->msg.pkt.per_pkt_info_len); break; case REMOTE_NDIS_INITIALIZE_CMPLT: @@ -191,147 +191,157 @@ static void DumpRndisMessage(struct rndis_message *RndisMessage) "(len %u, id 0x%x, status 0x%x, major %d, minor %d, " "device flags %d, max xfer size 0x%x, max pkts %u, " "pkt aligned %u)", - RndisMessage->MessageLength, - RndisMessage->Message.InitializeComplete.RequestId, - RndisMessage->Message.InitializeComplete.Status, - RndisMessage->Message.InitializeComplete.MajorVersion, - RndisMessage->Message.InitializeComplete.MinorVersion, - RndisMessage->Message.InitializeComplete.DeviceFlags, - RndisMessage->Message.InitializeComplete.MaxTransferSize, - RndisMessage->Message.InitializeComplete.MaxPacketsPerMessage, - RndisMessage->Message.InitializeComplete.PacketAlignmentFactor); + rndis_msg->msg_len, + rndis_msg->msg.init_complete.req_id, + rndis_msg->msg.init_complete.status, + rndis_msg->msg.init_complete.major_ver, + rndis_msg->msg.init_complete.minor_ver, + rndis_msg->msg.init_complete.dev_flags, + rndis_msg->msg.init_complete.max_xfer_size, + rndis_msg->msg.init_complete. + max_pkt_per_msg, + rndis_msg->msg.init_complete. + pkt_alignment_factor); break; case REMOTE_NDIS_QUERY_CMPLT: DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT " "(len %u, id 0x%x, status 0x%x, buf len %u, " "buf offset %u)", - RndisMessage->MessageLength, - RndisMessage->Message.QueryComplete.RequestId, - RndisMessage->Message.QueryComplete.Status, - RndisMessage->Message.QueryComplete.InformationBufferLength, - RndisMessage->Message.QueryComplete.InformationBufferOffset); + rndis_msg->msg_len, + rndis_msg->msg.query_complete.req_id, + rndis_msg->msg.query_complete.status, + rndis_msg->msg.query_complete. + info_buflen, + rndis_msg->msg.query_complete. + info_buf_offset); break; case REMOTE_NDIS_SET_CMPLT: DPRINT_DBG(NETVSC, "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)", - RndisMessage->MessageLength, - RndisMessage->Message.SetComplete.RequestId, - RndisMessage->Message.SetComplete.Status); + rndis_msg->msg_len, + rndis_msg->msg.set_complete.req_id, + rndis_msg->msg.set_complete.status); break; case REMOTE_NDIS_INDICATE_STATUS_MSG: DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG " "(len %u, status 0x%x, buf len %u, buf offset %u)", - RndisMessage->MessageLength, - RndisMessage->Message.IndicateStatus.Status, - RndisMessage->Message.IndicateStatus.StatusBufferLength, - RndisMessage->Message.IndicateStatus.StatusBufferOffset); + rndis_msg->msg_len, + rndis_msg->msg.indicate_status.status, + rndis_msg->msg.indicate_status.status_buflen, + rndis_msg->msg.indicate_status.status_buf_offset); break; default: DPRINT_DBG(NETVSC, "0x%x (len %u)", - RndisMessage->NdisMessageType, - RndisMessage->MessageLength); + rndis_msg->ndis_msg_type, + rndis_msg->msg_len); break; } } -static int RndisFilterSendRequest(struct rndis_device *Device, - struct rndis_request *Request) +static int rndis_filter_send_request(struct rndis_device *dev, + struct rndis_request *req) { int ret; struct hv_netvsc_packet *packet; /* Setup the packet to send it */ - packet = &Request->Packet; + packet = &req->pkt; - packet->IsDataPacket = false; - packet->TotalDataBufferLength = Request->RequestMessage.MessageLength; - packet->PageBufferCount = 1; + packet->is_data_pkt = false; + packet->total_data_buflen = req->request_msg.msg_len; + packet->page_buf_cnt = 1; - packet->PageBuffers[0].Pfn = virt_to_phys(&Request->RequestMessage) >> + packet->page_buf[0].Pfn = virt_to_phys(&req->request_msg) >> PAGE_SHIFT; - packet->PageBuffers[0].Length = Request->RequestMessage.MessageLength; - packet->PageBuffers[0].Offset = - (unsigned long)&Request->RequestMessage & (PAGE_SIZE - 1); + packet->page_buf[0].Length = req->request_msg.msg_len; + packet->page_buf[0].Offset = + (unsigned long)&req->request_msg & (PAGE_SIZE - 1); - packet->Completion.Send.SendCompletionContext = Request;/* packet; */ - packet->Completion.Send.OnSendCompletion = - RndisFilterOnSendRequestCompletion; - packet->Completion.Send.SendCompletionTid = (unsigned long)Device; + packet->completion.send.send_completion_ctx = req;/* packet; */ + packet->completion.send.send_completion = + rndis_filter_send_request_completion; + packet->completion.send.send_completion_tid = (unsigned long)dev; - ret = gRndisFilter.InnerDriver.OnSend(Device->NetDevice->Device, packet); + ret = rndis_filter.inner_drv.send(dev->net_dev->dev, packet); return ret; } -static void RndisFilterReceiveResponse(struct rndis_device *Device, - struct rndis_message *Response) +static void rndis_filter_receive_response(struct rndis_device *dev, + struct rndis_message *resp) { struct rndis_request *request = NULL; bool found = false; unsigned long flags; - spin_lock_irqsave(&Device->request_lock, flags); - list_for_each_entry(request, &Device->RequestList, ListEntry) { + spin_lock_irqsave(&dev->request_lock, flags); + list_for_each_entry(request, &dev->req_list, list_ent) { /* * All request/response message contains RequestId as the 1st * field */ - if (request->RequestMessage.Message.InitializeRequest.RequestId - == Response->Message.InitializeComplete.RequestId) { + if (request->request_msg.msg.init_req.req_id + == resp->msg.init_complete.req_id) { DPRINT_DBG(NETVSC, "found rndis request for " "this response (id 0x%x req type 0x%x res " "type 0x%x)", - request->RequestMessage.Message.InitializeRequest.RequestId, - request->RequestMessage.NdisMessageType, - Response->NdisMessageType); + request->request_msg.msg. + init_req.req_id, + request->request_msg.ndis_msg_type, + resp->ndis_msg_type); found = true; break; } } - spin_unlock_irqrestore(&Device->request_lock, flags); + spin_unlock_irqrestore(&dev->request_lock, flags); if (found) { - if (Response->MessageLength <= sizeof(struct rndis_message)) { - memcpy(&request->ResponseMessage, Response, - Response->MessageLength); + if (resp->msg_len <= sizeof(struct rndis_message)) { + memcpy(&request->response_msg, resp, + resp->msg_len); } else { DPRINT_ERR(NETVSC, "rndis response buffer overflow " "detected (size %u max %zu)", - Response->MessageLength, + resp->msg_len, sizeof(struct rndis_filter_packet)); - if (Response->NdisMessageType == + if (resp->ndis_msg_type == REMOTE_NDIS_RESET_CMPLT) { /* does not have a request id field */ - request->ResponseMessage.Message.ResetComplete.Status = STATUS_BUFFER_OVERFLOW; + request->response_msg.msg.reset_complete. + status = STATUS_BUFFER_OVERFLOW; } else { - request->ResponseMessage.Message.InitializeComplete.Status = STATUS_BUFFER_OVERFLOW; + request->response_msg.msg. + init_complete.status = + STATUS_BUFFER_OVERFLOW; } } - osd_WaitEventSet(request->WaitEvent); + osd_waitevent_set(request->waitevent); } else { DPRINT_ERR(NETVSC, "no rndis request found for this response " "(id 0x%x res type 0x%x)", - Response->Message.InitializeComplete.RequestId, - Response->NdisMessageType); + resp->msg.init_complete.req_id, + resp->ndis_msg_type); } } -static void RndisFilterReceiveIndicateStatus(struct rndis_device *Device, - struct rndis_message *Response) +static void rndis_filter_receive_indicate_status(struct rndis_device *dev, + struct rndis_message *resp) { struct rndis_indicate_status *indicate = - &Response->Message.IndicateStatus; - - if (indicate->Status == RNDIS_STATUS_MEDIA_CONNECT) { - gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 1); - } else if (indicate->Status == RNDIS_STATUS_MEDIA_DISCONNECT) { - gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 0); + &resp->msg.indicate_status; + + if (indicate->status == RNDIS_STATUS_MEDIA_CONNECT) { + rndis_filter.inner_drv.link_status_change( + dev->net_dev->dev, 1); + } else if (indicate->status == RNDIS_STATUS_MEDIA_DISCONNECT) { + rndis_filter.inner_drv.link_status_change( + dev->net_dev->dev, 0); } else { /* * TODO: @@ -339,18 +349,18 @@ static void RndisFilterReceiveIndicateStatus(struct rndis_device *Device, } } -static void RndisFilterReceiveData(struct rndis_device *Device, - struct rndis_message *Message, - struct hv_netvsc_packet *Packet) +static void rndis_filter_receive_data(struct rndis_device *dev, + struct rndis_message *msg, + struct hv_netvsc_packet *pkt) { - struct rndis_packet *rndisPacket; - u32 dataOffset; + struct rndis_packet *rndis_pkt; + u32 data_offset; /* empty ethernet frame ?? */ /* ASSERT(Packet->PageBuffers[0].Length > */ /* RNDIS_MESSAGE_SIZE(struct rndis_packet)); */ - rndisPacket = &Message->Message.Packet; + rndis_pkt = &msg->msg.pkt; /* * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this @@ -358,48 +368,48 @@ static void RndisFilterReceiveData(struct rndis_device *Device, */ /* Remove the rndis header and pass it back up the stack */ - dataOffset = RNDIS_HEADER_SIZE + rndisPacket->DataOffset; + data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset; - Packet->TotalDataBufferLength -= dataOffset; - Packet->PageBuffers[0].Offset += dataOffset; - Packet->PageBuffers[0].Length -= dataOffset; + pkt->total_data_buflen -= data_offset; + pkt->page_buf[0].Offset += data_offset; + pkt->page_buf[0].Length -= data_offset; - Packet->IsDataPacket = true; + pkt->is_data_pkt = true; - gRndisFilter.InnerDriver.OnReceiveCallback(Device->NetDevice->Device, - Packet); + rndis_filter.inner_drv.recv_cb(dev->net_dev->dev, + pkt); } -static int RndisFilterOnReceive(struct hv_device *Device, - struct hv_netvsc_packet *Packet) +static int rndis_filter_receive(struct hv_device *dev, + struct hv_netvsc_packet *pkt) { - struct netvsc_device *netDevice = Device->Extension; - struct rndis_device *rndisDevice; - struct rndis_message rndisMessage; - struct rndis_message *rndisHeader; + struct netvsc_device *net_dev = dev->Extension; + struct rndis_device *rndis_dev; + struct rndis_message rndis_msg; + struct rndis_message *rndis_hdr; - if (!netDevice) + if (!net_dev) return -EINVAL; /* Make sure the rndis device state is initialized */ - if (!netDevice->Extension) { + if (!net_dev->extension) { DPRINT_ERR(NETVSC, "got rndis message but no rndis device..." "dropping this message!"); return -1; } - rndisDevice = (struct rndis_device *)netDevice->Extension; - if (rndisDevice->State == RNDIS_DEV_UNINITIALIZED) { + rndis_dev = (struct rndis_device *)net_dev->extension; + if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) { DPRINT_ERR(NETVSC, "got rndis message but rndis device " "uninitialized...dropping this message!"); return -1; } - rndisHeader = (struct rndis_message *)kmap_atomic( - pfn_to_page(Packet->PageBuffers[0].Pfn), KM_IRQ0); + rndis_hdr = (struct rndis_message *)kmap_atomic( + pfn_to_page(pkt->page_buf[0].Pfn), KM_IRQ0); - rndisHeader = (void *)((unsigned long)rndisHeader + - Packet->PageBuffers[0].Offset); + rndis_hdr = (void *)((unsigned long)rndis_hdr + + pkt->page_buf[0].Offset); /* Make sure we got a valid rndis message */ /* @@ -408,39 +418,39 @@ static int RndisFilterOnReceive(struct hv_device *Device, * range shows 52 bytes * */ #if 0 - if (Packet->TotalDataBufferLength != rndisHeader->MessageLength) { - kunmap_atomic(rndisHeader - Packet->PageBuffers[0].Offset, + if (pkt->total_data_buflen != rndis_hdr->msg_len) { + kunmap_atomic(rndis_hdr - pkt->page_buf[0].Offset, KM_IRQ0); DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u " "bytes got %u)...dropping this message!", - rndisHeader->MessageLength, - Packet->TotalDataBufferLength); + rndis_hdr->msg_len, + pkt->total_data_buflen); return -1; } #endif - if ((rndisHeader->NdisMessageType != REMOTE_NDIS_PACKET_MSG) && - (rndisHeader->MessageLength > sizeof(struct rndis_message))) { + if ((rndis_hdr->ndis_msg_type != REMOTE_NDIS_PACKET_MSG) && + (rndis_hdr->msg_len > sizeof(struct rndis_message))) { DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow " "detected (got %u, max %zu)...marking it an error!", - rndisHeader->MessageLength, + rndis_hdr->msg_len, sizeof(struct rndis_message)); } - memcpy(&rndisMessage, rndisHeader, - (rndisHeader->MessageLength > sizeof(struct rndis_message)) ? + memcpy(&rndis_msg, rndis_hdr, + (rndis_hdr->msg_len > sizeof(struct rndis_message)) ? sizeof(struct rndis_message) : - rndisHeader->MessageLength); + rndis_hdr->msg_len); - kunmap_atomic(rndisHeader - Packet->PageBuffers[0].Offset, KM_IRQ0); + kunmap_atomic(rndis_hdr - pkt->page_buf[0].Offset, KM_IRQ0); - DumpRndisMessage(&rndisMessage); + dump_rndis_message(&rndis_msg); - switch (rndisMessage.NdisMessageType) { + switch (rndis_msg.ndis_msg_type) { case REMOTE_NDIS_PACKET_MSG: /* data msg */ - RndisFilterReceiveData(rndisDevice, &rndisMessage, Packet); + rndis_filter_receive_data(rndis_dev, &rndis_msg, pkt); break; case REMOTE_NDIS_INITIALIZE_CMPLT: @@ -449,37 +459,37 @@ static int RndisFilterOnReceive(struct hv_device *Device, /* case REMOTE_NDIS_RESET_CMPLT: */ /* case REMOTE_NDIS_KEEPALIVE_CMPLT: */ /* completion msgs */ - RndisFilterReceiveResponse(rndisDevice, &rndisMessage); + rndis_filter_receive_response(rndis_dev, &rndis_msg); break; case REMOTE_NDIS_INDICATE_STATUS_MSG: /* notification msgs */ - RndisFilterReceiveIndicateStatus(rndisDevice, &rndisMessage); + rndis_filter_receive_indicate_status(rndis_dev, &rndis_msg); break; default: DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)", - rndisMessage.NdisMessageType, - rndisMessage.MessageLength); + rndis_msg.ndis_msg_type, + rndis_msg.msg_len); break; } return 0; } -static int RndisFilterQueryDevice(struct rndis_device *Device, u32 Oid, - void *Result, u32 *ResultSize) +static int rndis_filter_query_device(struct rndis_device *dev, u32 oid, + void *result, u32 *result_size) { struct rndis_request *request; - u32 inresultSize = *ResultSize; + u32 inresult_size = *result_size; struct rndis_query_request *query; - struct rndis_query_complete *queryComplete; + struct rndis_query_complete *query_complete; int ret = 0; - if (!Result) + if (!result) return -EINVAL; - *ResultSize = 0; - request = GetRndisRequest(Device, REMOTE_NDIS_QUERY_MSG, + *result_size = 0; + request = get_rndis_request(dev, REMOTE_NDIS_QUERY_MSG, RNDIS_MESSAGE_SIZE(struct rndis_query_request)); if (!request) { ret = -1; @@ -487,71 +497,71 @@ static int RndisFilterQueryDevice(struct rndis_device *Device, u32 Oid, } /* Setup the rndis query */ - query = &request->RequestMessage.Message.QueryRequest; - query->Oid = Oid; - query->InformationBufferOffset = sizeof(struct rndis_query_request); - query->InformationBufferLength = 0; - query->DeviceVcHandle = 0; + query = &request->request_msg.msg.query_req; + query->oid = oid; + query->info_buf_offset = sizeof(struct rndis_query_request); + query->info_buflen = 0; + query->dev_vc_handle = 0; - ret = RndisFilterSendRequest(Device, request); + ret = rndis_filter_send_request(dev, request); if (ret != 0) goto Cleanup; - osd_WaitEventWait(request->WaitEvent); + osd_waitevent_wait(request->waitevent); /* Copy the response back */ - queryComplete = &request->ResponseMessage.Message.QueryComplete; + query_complete = &request->response_msg.msg.query_complete; - if (queryComplete->InformationBufferLength > inresultSize) { + if (query_complete->info_buflen > inresult_size) { ret = -1; goto Cleanup; } - memcpy(Result, - (void *)((unsigned long)queryComplete + - queryComplete->InformationBufferOffset), - queryComplete->InformationBufferLength); + memcpy(result, + (void *)((unsigned long)query_complete + + query_complete->info_buf_offset), + query_complete->info_buflen); - *ResultSize = queryComplete->InformationBufferLength; + *result_size = query_complete->info_buflen; Cleanup: if (request) - PutRndisRequest(Device, request); + put_rndis_request(dev, request); return ret; } -static int RndisFilterQueryDeviceMac(struct rndis_device *Device) +static int rndis_filter_query_device_mac(struct rndis_device *dev) { u32 size = ETH_ALEN; - return RndisFilterQueryDevice(Device, + return rndis_filter_query_device(dev, RNDIS_OID_802_3_PERMANENT_ADDRESS, - Device->HwMacAddr, &size); + dev->hw_mac_adr, &size); } -static int RndisFilterQueryDeviceLinkStatus(struct rndis_device *Device) +static int rndis_filter_query_device_link_status(struct rndis_device *dev) { u32 size = sizeof(u32); - return RndisFilterQueryDevice(Device, + return rndis_filter_query_device(dev, RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, - &Device->LinkStatus, &size); + &dev->link_stat, &size); } -static int RndisFilterSetPacketFilter(struct rndis_device *Device, - u32 NewFilter) +static int rndis_filter_set_packet_filter(struct rndis_device *dev, + u32 new_filter) { struct rndis_request *request; struct rndis_set_request *set; - struct rndis_set_complete *setComplete; + struct rndis_set_complete *set_complete; u32 status; int ret; /* ASSERT(RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32) <= */ /* sizeof(struct rndis_message)); */ - request = GetRndisRequest(Device, REMOTE_NDIS_SET_MSG, + request = get_rndis_request(dev, REMOTE_NDIS_SET_MSG, RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32)); if (!request) { @@ -560,19 +570,19 @@ static int RndisFilterSetPacketFilter(struct rndis_device *Device, } /* Setup the rndis set */ - set = &request->RequestMessage.Message.SetRequest; - set->Oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER; - set->InformationBufferLength = sizeof(u32); - set->InformationBufferOffset = sizeof(struct rndis_set_request); + set = &request->request_msg.msg.set_req; + set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER; + set->info_buflen = sizeof(u32); + set->info_buf_offset = sizeof(struct rndis_set_request); memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request), - &NewFilter, sizeof(u32)); + &new_filter, sizeof(u32)); - ret = RndisFilterSendRequest(Device, request); + ret = rndis_filter_send_request(dev, request); if (ret != 0) goto Cleanup; - ret = osd_WaitEventWaitEx(request->WaitEvent, 2000/*2sec*/); + ret = osd_waitevent_waitex(request->waitevent, 2000/*2sec*/); if (!ret) { ret = -1; DPRINT_ERR(NETVSC, "timeout before we got a set response..."); @@ -584,27 +594,27 @@ static int RndisFilterSetPacketFilter(struct rndis_device *Device, } else { if (ret > 0) ret = 0; - setComplete = &request->ResponseMessage.Message.SetComplete; - status = setComplete->Status; + set_complete = &request->response_msg.msg.set_complete; + status = set_complete->status; } Cleanup: if (request) - PutRndisRequest(Device, request); + put_rndis_request(dev, request); Exit: return ret; } -int RndisFilterInit(struct netvsc_driver *Driver) +int rndis_filter_init(struct netvsc_driver *drv) { DPRINT_DBG(NETVSC, "sizeof(struct rndis_filter_packet) == %zd", sizeof(struct rndis_filter_packet)); - Driver->RequestExtSize = sizeof(struct rndis_filter_packet); + drv->req_ext_size = sizeof(struct rndis_filter_packet); /* Driver->Context = rndisDriver; */ - memset(&gRndisFilter, 0, sizeof(struct rndis_filter_driver_object)); + memset(&rndis_filter, 0, sizeof(struct rndis_filter_driver_object)); /*rndisDriver->Driver = Driver; @@ -612,38 +622,38 @@ int RndisFilterInit(struct netvsc_driver *Driver) rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/ /* Save the original dispatch handlers before we override it */ - gRndisFilter.InnerDriver.Base.OnDeviceAdd = Driver->Base.OnDeviceAdd; - gRndisFilter.InnerDriver.Base.OnDeviceRemove = - Driver->Base.OnDeviceRemove; - gRndisFilter.InnerDriver.Base.OnCleanup = Driver->Base.OnCleanup; + 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; /* ASSERT(Driver->OnSend); */ /* ASSERT(Driver->OnReceiveCallback); */ - gRndisFilter.InnerDriver.OnSend = Driver->OnSend; - gRndisFilter.InnerDriver.OnReceiveCallback = Driver->OnReceiveCallback; - gRndisFilter.InnerDriver.OnLinkStatusChanged = - Driver->OnLinkStatusChanged; + 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 */ - Driver->Base.OnDeviceAdd = RndisFilterOnDeviceAdd; - Driver->Base.OnDeviceRemove = RndisFilterOnDeviceRemove; - Driver->Base.OnCleanup = RndisFilterOnCleanup; - Driver->OnSend = RndisFilterOnSend; + drv->base.OnDeviceAdd = rndis_filte_device_add; + drv->base.OnDeviceRemove = rndis_filter_device_remove; + drv->base.OnCleanup = rndis_filter_cleanup; + drv->send = rndis_filter_send; /* Driver->QueryLinkStatus = RndisFilterQueryDeviceLinkStatus; */ - Driver->OnReceiveCallback = RndisFilterOnReceive; + drv->recv_cb = rndis_filter_receive; return 0; } -static int RndisFilterInitDevice(struct rndis_device *Device) +static int rndis_filter_init_device(struct rndis_device *dev) { struct rndis_request *request; struct rndis_initialize_request *init; - struct rndis_initialize_complete *initComplete; + struct rndis_initialize_complete *init_complete; u32 status; int ret; - request = GetRndisRequest(Device, REMOTE_NDIS_INITIALIZE_MSG, + request = get_rndis_request(dev, REMOTE_NDIS_INITIALIZE_MSG, RNDIS_MESSAGE_SIZE(struct rndis_initialize_request)); if (!request) { ret = -1; @@ -651,105 +661,105 @@ static int RndisFilterInitDevice(struct rndis_device *Device) } /* Setup the rndis set */ - init = &request->RequestMessage.Message.InitializeRequest; - init->MajorVersion = RNDIS_MAJOR_VERSION; - init->MinorVersion = RNDIS_MINOR_VERSION; + init = &request->request_msg.msg.init_req; + init->major_ver = RNDIS_MAJOR_VERSION; + init->minor_ver = RNDIS_MINOR_VERSION; /* FIXME: Use 1536 - rounded ethernet frame size */ - init->MaxTransferSize = 2048; + init->max_xfer_size = 2048; - Device->State = RNDIS_DEV_INITIALIZING; + dev->state = RNDIS_DEV_INITIALIZING; - ret = RndisFilterSendRequest(Device, request); + ret = rndis_filter_send_request(dev, request); if (ret != 0) { - Device->State = RNDIS_DEV_UNINITIALIZED; + dev->state = RNDIS_DEV_UNINITIALIZED; goto Cleanup; } - osd_WaitEventWait(request->WaitEvent); + osd_waitevent_wait(request->waitevent); - initComplete = &request->ResponseMessage.Message.InitializeComplete; - status = initComplete->Status; + init_complete = &request->response_msg.msg.init_complete; + status = init_complete->status; if (status == RNDIS_STATUS_SUCCESS) { - Device->State = RNDIS_DEV_INITIALIZED; + dev->state = RNDIS_DEV_INITIALIZED; ret = 0; } else { - Device->State = RNDIS_DEV_UNINITIALIZED; + dev->state = RNDIS_DEV_UNINITIALIZED; ret = -1; } Cleanup: if (request) - PutRndisRequest(Device, request); + put_rndis_request(dev, request); return ret; } -static void RndisFilterHaltDevice(struct rndis_device *Device) +static void rndis_filter_halt_device(struct rndis_device *dev) { struct rndis_request *request; struct rndis_halt_request *halt; /* Attempt to do a rndis device halt */ - request = GetRndisRequest(Device, REMOTE_NDIS_HALT_MSG, + request = get_rndis_request(dev, REMOTE_NDIS_HALT_MSG, RNDIS_MESSAGE_SIZE(struct rndis_halt_request)); if (!request) goto Cleanup; /* Setup the rndis set */ - halt = &request->RequestMessage.Message.HaltRequest; - halt->RequestId = atomic_inc_return(&Device->NewRequestId); + halt = &request->request_msg.msg.halt_req; + halt->req_id = atomic_inc_return(&dev->new_req_id); /* Ignore return since this msg is optional. */ - RndisFilterSendRequest(Device, request); + rndis_filter_send_request(dev, request); - Device->State = RNDIS_DEV_UNINITIALIZED; + dev->state = RNDIS_DEV_UNINITIALIZED; Cleanup: if (request) - PutRndisRequest(Device, request); + put_rndis_request(dev, request); return; } -static int RndisFilterOpenDevice(struct rndis_device *Device) +static int rndis_filter_open_device(struct rndis_device *dev) { int ret; - if (Device->State != RNDIS_DEV_INITIALIZED) + if (dev->state != RNDIS_DEV_INITIALIZED) return 0; - ret = RndisFilterSetPacketFilter(Device, + ret = rndis_filter_set_packet_filter(dev, NDIS_PACKET_TYPE_BROADCAST | NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_DIRECTED); if (ret == 0) - Device->State = RNDIS_DEV_DATAINITIALIZED; + dev->state = RNDIS_DEV_DATAINITIALIZED; return ret; } -static int RndisFilterCloseDevice(struct rndis_device *Device) +static int rndis_filter_close_device(struct rndis_device *dev) { int ret; - if (Device->State != RNDIS_DEV_DATAINITIALIZED) + if (dev->state != RNDIS_DEV_DATAINITIALIZED) return 0; - ret = RndisFilterSetPacketFilter(Device, 0); + ret = rndis_filter_set_packet_filter(dev, 0); if (ret == 0) - Device->State = RNDIS_DEV_INITIALIZED; + dev->state = RNDIS_DEV_INITIALIZED; return ret; } -static int RndisFilterOnDeviceAdd(struct hv_device *Device, - void *AdditionalInfo) +static int rndis_filte_device_add(struct hv_device *dev, + void *additional_info) { int ret; struct netvsc_device *netDevice; struct rndis_device *rndisDevice; - struct netvsc_device_info *deviceInfo = AdditionalInfo; + struct netvsc_device_info *deviceInfo = additional_info; - rndisDevice = GetRndisDevice(); + rndisDevice = get_rndis_device(); if (!rndisDevice) return -1; @@ -760,7 +770,7 @@ static int RndisFilterOnDeviceAdd(struct hv_device *Device, * NOTE! Once the channel is created, we may get a receive callback * (RndisFilterOnReceive()) before this call is completed */ - ret = gRndisFilter.InnerDriver.Base.OnDeviceAdd(Device, AdditionalInfo); + ret = rndis_filter.inner_drv.base.OnDeviceAdd(dev, additional_info); if (ret != 0) { kfree(rndisDevice); return ret; @@ -768,15 +778,15 @@ static int RndisFilterOnDeviceAdd(struct hv_device *Device, /* Initialize the rndis device */ - netDevice = Device->Extension; + netDevice = dev->Extension; /* ASSERT(netDevice); */ /* ASSERT(netDevice->Device); */ - netDevice->Extension = rndisDevice; - rndisDevice->NetDevice = netDevice; + netDevice->extension = rndisDevice; + rndisDevice->net_dev = netDevice; /* Send the rndis initialization message */ - ret = RndisFilterInitDevice(rndisDevice); + ret = rndis_filter_init_device(rndisDevice); if (ret != 0) { /* * TODO: If rndis init failed, we will need to shut down the @@ -785,7 +795,7 @@ static int RndisFilterOnDeviceAdd(struct hv_device *Device, } /* Get the mac address */ - ret = RndisFilterQueryDeviceMac(rndisDevice); + ret = rndis_filter_query_device_mac(rndisDevice); if (ret != 0) { /* * TODO: shutdown rndis device and the channel @@ -793,62 +803,62 @@ static int RndisFilterOnDeviceAdd(struct hv_device *Device, } DPRINT_INFO(NETVSC, "Device 0x%p mac addr %pM", - rndisDevice, rndisDevice->HwMacAddr); + rndisDevice, rndisDevice->hw_mac_adr); - memcpy(deviceInfo->MacAddr, rndisDevice->HwMacAddr, ETH_ALEN); + memcpy(deviceInfo->mac_adr, rndisDevice->hw_mac_adr, ETH_ALEN); - RndisFilterQueryDeviceLinkStatus(rndisDevice); + rndis_filter_query_device_link_status(rndisDevice); - deviceInfo->LinkState = rndisDevice->LinkStatus; + deviceInfo->link_state = rndisDevice->link_stat; DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice, - ((deviceInfo->LinkState) ? ("down") : ("up"))); + ((deviceInfo->link_state) ? ("down") : ("up"))); return ret; } -static int RndisFilterOnDeviceRemove(struct hv_device *Device) +static int rndis_filter_device_remove(struct hv_device *dev) { - struct netvsc_device *netDevice = Device->Extension; - struct rndis_device *rndisDevice = netDevice->Extension; + struct netvsc_device *net_dev = dev->Extension; + struct rndis_device *rndis_dev = net_dev->extension; /* Halt and release the rndis device */ - RndisFilterHaltDevice(rndisDevice); + rndis_filter_halt_device(rndis_dev); - kfree(rndisDevice); - netDevice->Extension = NULL; + kfree(rndis_dev); + net_dev->extension = NULL; /* Pass control to inner driver to remove the device */ - gRndisFilter.InnerDriver.Base.OnDeviceRemove(Device); + rndis_filter.inner_drv.base.OnDeviceRemove(dev); return 0; } -static void RndisFilterOnCleanup(struct hv_driver *Driver) +static void rndis_filter_cleanup(struct hv_driver *drv) { } -int RndisFilterOnOpen(struct hv_device *Device) +int rndis_filter_open(struct hv_device *dev) { - struct netvsc_device *netDevice = Device->Extension; + struct netvsc_device *netDevice = dev->Extension; if (!netDevice) return -EINVAL; - return RndisFilterOpenDevice(netDevice->Extension); + return rndis_filter_open_device(netDevice->extension); } -int RndisFilterOnClose(struct hv_device *Device) +int rndis_filter_close(struct hv_device *dev) { - struct netvsc_device *netDevice = Device->Extension; + struct netvsc_device *netDevice = dev->Extension; if (!netDevice) return -EINVAL; - return RndisFilterCloseDevice(netDevice->Extension); + return rndis_filter_close_device(netDevice->extension); } -static int RndisFilterOnSend(struct hv_device *Device, - struct hv_netvsc_packet *Packet) +static int rndis_filter_send(struct hv_device *dev, + struct hv_netvsc_packet *pkt) { int ret; struct rndis_filter_packet *filterPacket; @@ -857,62 +867,62 @@ static int RndisFilterOnSend(struct hv_device *Device, u32 rndisMessageSize; /* Add the rndis header */ - filterPacket = (struct rndis_filter_packet *)Packet->Extension; + filterPacket = (struct rndis_filter_packet *)pkt->extension; /* ASSERT(filterPacket); */ memset(filterPacket, 0, sizeof(struct rndis_filter_packet)); - rndisMessage = &filterPacket->Message; + rndisMessage = &filterPacket->msg; rndisMessageSize = RNDIS_MESSAGE_SIZE(struct rndis_packet); - rndisMessage->NdisMessageType = REMOTE_NDIS_PACKET_MSG; - rndisMessage->MessageLength = Packet->TotalDataBufferLength + + rndisMessage->ndis_msg_type = REMOTE_NDIS_PACKET_MSG; + rndisMessage->msg_len = pkt->total_data_buflen + rndisMessageSize; - rndisPacket = &rndisMessage->Message.Packet; - rndisPacket->DataOffset = sizeof(struct rndis_packet); - rndisPacket->DataLength = Packet->TotalDataBufferLength; + rndisPacket = &rndisMessage->msg.pkt; + rndisPacket->data_offset = sizeof(struct rndis_packet); + rndisPacket->data_len = pkt->total_data_buflen; - Packet->IsDataPacket = true; - Packet->PageBuffers[0].Pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT; - Packet->PageBuffers[0].Offset = + pkt->is_data_pkt = true; + pkt->page_buf[0].Pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT; + pkt->page_buf[0].Offset = (unsigned long)rndisMessage & (PAGE_SIZE-1); - Packet->PageBuffers[0].Length = rndisMessageSize; + pkt->page_buf[0].Length = rndisMessageSize; /* Save the packet send completion and context */ - filterPacket->OnCompletion = Packet->Completion.Send.OnSendCompletion; - filterPacket->CompletionContext = - Packet->Completion.Send.SendCompletionContext; + filterPacket->completion = pkt->completion.send.send_completion; + filterPacket->completion_ctx = + pkt->completion.send.send_completion_ctx; /* Use ours */ - Packet->Completion.Send.OnSendCompletion = RndisFilterOnSendCompletion; - Packet->Completion.Send.SendCompletionContext = filterPacket; + pkt->completion.send.send_completion = rndis_filter_send_completion; + pkt->completion.send.send_completion_ctx = filterPacket; - ret = gRndisFilter.InnerDriver.OnSend(Device, Packet); + ret = rndis_filter.inner_drv.send(dev, pkt); if (ret != 0) { /* * Reset the completion to originals to allow retries from * above */ - Packet->Completion.Send.OnSendCompletion = - filterPacket->OnCompletion; - Packet->Completion.Send.SendCompletionContext = - filterPacket->CompletionContext; + pkt->completion.send.send_completion = + filterPacket->completion; + pkt->completion.send.send_completion_ctx = + filterPacket->completion_ctx; } return ret; } -static void RndisFilterOnSendCompletion(void *Context) +static void rndis_filter_send_completion(void *ctx) { - struct rndis_filter_packet *filterPacket = Context; + struct rndis_filter_packet *filterPacket = ctx; /* Pass it back to the original handler */ - filterPacket->OnCompletion(filterPacket->CompletionContext); + filterPacket->completion(filterPacket->completion_ctx); } -static void RndisFilterOnSendRequestCompletion(void *Context) +static void rndis_filter_send_request_completion(void *ctx) { /* Noop */ } diff --git a/drivers/staging/hv/rndis_filter.h b/drivers/staging/hv/rndis_filter.h index 764b9bf3e5dc..4da18f3cbade 100644 --- a/drivers/staging/hv/rndis_filter.h +++ b/drivers/staging/hv/rndis_filter.h @@ -50,6 +50,6 @@ /* Interface */ -extern int RndisFilterInit(struct netvsc_driver *driver); +extern int rndis_filter_init(struct netvsc_driver *driver); #endif /* _RNDISFILTER_H_ */ diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c index 19e87f689fa0..9295113e09b9 100644 --- a/drivers/staging/hv/storvsc.c +++ b/drivers/staging/hv/storvsc.c @@ -34,43 +34,43 @@ struct storvsc_request_extension { /* LIST_ENTRY ListEntry; */ - struct hv_storvsc_request *Request; - struct hv_device *Device; + struct hv_storvsc_request *request; + struct hv_device *device; /* Synchronize the request/response if needed */ - struct osd_waitevent *WaitEvent; + struct osd_waitevent *wait_event; - struct vstor_packet VStorPacket; + struct vstor_packet vstor_packet; }; /* A storvsc device is a device object that contains a vmbus channel */ struct storvsc_device { - struct hv_device *Device; + struct hv_device *device; /* 0 indicates the device is being destroyed */ - atomic_t RefCount; + atomic_t ref_count; - atomic_t NumOutstandingRequests; + atomic_t num_outstanding_req; /* * Each unique Port/Path/Target represents 1 channel ie scsi * controller. In reality, the pathid, targetid is always 0 * and the port is set by us */ - unsigned int PortNumber; - unsigned char PathId; - unsigned char TargetId; + unsigned int port_number; + unsigned char path_id; + unsigned char target_id; /* LIST_ENTRY OutstandingRequestList; */ /* HANDLE OutstandingRequestLock; */ /* Used for vsc/vsp channel reset process */ - struct storvsc_request_extension InitRequest; - struct storvsc_request_extension ResetRequest; + struct storvsc_request_extension init_request; + struct storvsc_request_extension reset_request; }; -static const char *gDriverName = "storvsc"; +static const char *g_driver_name = "storvsc"; /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ static const struct hv_guid gStorVscDeviceType = { @@ -81,131 +81,133 @@ static const struct hv_guid gStorVscDeviceType = { }; -static inline struct storvsc_device *AllocStorDevice(struct hv_device *Device) +static inline struct storvsc_device *alloc_stor_device(struct hv_device *device) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; - storDevice = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL); - if (!storDevice) + stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL); + if (!stor_device) return NULL; /* Set to 2 to allow both inbound and outbound traffics */ - /* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */ - atomic_cmpxchg(&storDevice->RefCount, 0, 2); + /* (ie get_stor_device() and must_get_stor_device()) to proceed. */ + atomic_cmpxchg(&stor_device->ref_count, 0, 2); - storDevice->Device = Device; - Device->Extension = storDevice; + stor_device->device = device; + device->Extension = stor_device; - return storDevice; + return stor_device; } -static inline void FreeStorDevice(struct storvsc_device *Device) +static inline void free_stor_device(struct storvsc_device *device) { - /* ASSERT(atomic_read(&Device->RefCount) == 0); */ - kfree(Device); + /* ASSERT(atomic_read(&device->ref_count) == 0); */ + kfree(device); } /* Get the stordevice object iff exists and its refcount > 1 */ -static inline struct storvsc_device *GetStorDevice(struct hv_device *Device) +static inline struct storvsc_device *get_stor_device(struct hv_device *device) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; - storDevice = (struct storvsc_device *)Device->Extension; - if (storDevice && atomic_read(&storDevice->RefCount) > 1) - atomic_inc(&storDevice->RefCount); + stor_device = (struct storvsc_device *)device->Extension; + if (stor_device && atomic_read(&stor_device->ref_count) > 1) + atomic_inc(&stor_device->ref_count); else - storDevice = NULL; + stor_device = NULL; - return storDevice; + return stor_device; } /* Get the stordevice object iff exists and its refcount > 0 */ -static inline struct storvsc_device *MustGetStorDevice(struct hv_device *Device) +static inline struct storvsc_device *must_get_stor_device( + struct hv_device *device) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; - storDevice = (struct storvsc_device *)Device->Extension; - if (storDevice && atomic_read(&storDevice->RefCount)) - atomic_inc(&storDevice->RefCount); + stor_device = (struct storvsc_device *)device->Extension; + if (stor_device && atomic_read(&stor_device->ref_count)) + atomic_inc(&stor_device->ref_count); else - storDevice = NULL; + stor_device = NULL; - return storDevice; + return stor_device; } -static inline void PutStorDevice(struct hv_device *Device) +static inline void put_stor_device(struct hv_device *device) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; - storDevice = (struct storvsc_device *)Device->Extension; - /* ASSERT(storDevice); */ + stor_device = (struct storvsc_device *)device->Extension; + /* ASSERT(stor_device); */ - atomic_dec(&storDevice->RefCount); - /* ASSERT(atomic_read(&storDevice->RefCount)); */ + atomic_dec(&stor_device->ref_count); + /* ASSERT(atomic_read(&stor_device->ref_count)); */ } -/* Drop ref count to 1 to effectively disable GetStorDevice() */ -static inline struct storvsc_device *ReleaseStorDevice(struct hv_device *Device) +/* Drop ref count to 1 to effectively disable get_stor_device() */ +static inline struct storvsc_device *release_stor_device( + struct hv_device *device) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; - storDevice = (struct storvsc_device *)Device->Extension; - /* ASSERT(storDevice); */ + stor_device = (struct storvsc_device *)device->Extension; + /* ASSERT(stor_device); */ /* Busy wait until the ref drop to 2, then set it to 1 */ - while (atomic_cmpxchg(&storDevice->RefCount, 2, 1) != 2) + while (atomic_cmpxchg(&stor_device->ref_count, 2, 1) != 2) udelay(100); - return storDevice; + return stor_device; } -/* Drop ref count to 0. No one can use StorDevice object. */ -static inline struct storvsc_device *FinalReleaseStorDevice( - struct hv_device *Device) +/* Drop ref count to 0. No one can use stor_device object. */ +static inline struct storvsc_device *final_release_stor_device( + struct hv_device *device) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; - storDevice = (struct storvsc_device *)Device->Extension; - /* ASSERT(storDevice); */ + stor_device = (struct storvsc_device *)device->Extension; + /* ASSERT(stor_device); */ /* Busy wait until the ref drop to 1, then set it to 0 */ - while (atomic_cmpxchg(&storDevice->RefCount, 1, 0) != 1) + while (atomic_cmpxchg(&stor_device->ref_count, 1, 0) != 1) udelay(100); - Device->Extension = NULL; - return storDevice; + device->Extension = NULL; + return stor_device; } -static int StorVscChannelInit(struct hv_device *Device) +static int stor_vsc_channel_init(struct hv_device *device) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; struct storvsc_request_extension *request; - struct vstor_packet *vstorPacket; + struct vstor_packet *vstor_packet; int ret; - storDevice = GetStorDevice(Device); - if (!storDevice) { + stor_device = get_stor_device(device); + if (!stor_device) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); return -1; } - request = &storDevice->InitRequest; - vstorPacket = &request->VStorPacket; + request = &stor_device->init_request; + vstor_packet = &request->vstor_packet; /* * Now, initiate the vsc/vsp initialization protocol on the open * channel */ memset(request, 0, sizeof(struct storvsc_request_extension)); - request->WaitEvent = osd_WaitEventCreate(); - if (!request->WaitEvent) { + request->wait_event = osd_waitevent_create(); + if (!request->wait_event) { ret = -ENOMEM; goto nomem; } - vstorPacket->Operation = VStorOperationBeginInitialization; - vstorPacket->Flags = REQUEST_COMPLETION_FLAG; + vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION; + vstor_packet->flags = REQUEST_COMPLETION_FLAG; /*SpinlockAcquire(gDriverExt.packetListLock); INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry); @@ -213,7 +215,7 @@ static int StorVscChannelInit(struct hv_device *Device) DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION..."); - ret = vmbus_sendpacket(Device->channel, vstorPacket, + ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, VmbusPacketTypeDataInBand, @@ -224,27 +226,27 @@ static int StorVscChannelInit(struct hv_device *Device) goto Cleanup; } - osd_WaitEventWait(request->WaitEvent); + osd_waitevent_wait(request->wait_event); - if (vstorPacket->Operation != VStorOperationCompleteIo || - vstorPacket->Status != 0) { + if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || + vstor_packet->status != 0) { DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed " "(op %d status 0x%x)", - vstorPacket->Operation, vstorPacket->Status); + vstor_packet->operation, vstor_packet->status); goto Cleanup; } DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION..."); /* reuse the packet for version range supported */ - memset(vstorPacket, 0, sizeof(struct vstor_packet)); - vstorPacket->Operation = VStorOperationQueryProtocolVersion; - vstorPacket->Flags = REQUEST_COMPLETION_FLAG; + memset(vstor_packet, 0, sizeof(struct vstor_packet)); + vstor_packet->operation = VSTOR_OPERATION_QUERY_PROTOCOL_VERSION; + vstor_packet->flags = REQUEST_COMPLETION_FLAG; - vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT; - FILL_VMSTOR_REVISION(vstorPacket->Version.Revision); + vstor_packet->version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT; + FILL_VMSTOR_REVISION(vstor_packet->version.revision); - ret = vmbus_sendpacket(Device->channel, vstorPacket, + ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, VmbusPacketTypeDataInBand, @@ -255,27 +257,27 @@ static int StorVscChannelInit(struct hv_device *Device) goto Cleanup; } - osd_WaitEventWait(request->WaitEvent); + osd_waitevent_wait(request->wait_event); /* TODO: Check returned version */ - if (vstorPacket->Operation != VStorOperationCompleteIo || - vstorPacket->Status != 0) { + if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || + vstor_packet->status != 0) { DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed " "(op %d status 0x%x)", - vstorPacket->Operation, vstorPacket->Status); + vstor_packet->operation, vstor_packet->status); goto Cleanup; } /* Query channel properties */ DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION..."); - memset(vstorPacket, 0, sizeof(struct vstor_packet)); - vstorPacket->Operation = VStorOperationQueryProperties; - vstorPacket->Flags = REQUEST_COMPLETION_FLAG; - vstorPacket->StorageChannelProperties.PortNumber = - storDevice->PortNumber; + memset(vstor_packet, 0, sizeof(struct vstor_packet)); + vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES; + vstor_packet->flags = REQUEST_COMPLETION_FLAG; + vstor_packet->storage_channel_properties.port_number = + stor_device->port_number; - ret = vmbus_sendpacket(Device->channel, vstorPacket, + ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, VmbusPacketTypeDataInBand, @@ -287,31 +289,32 @@ static int StorVscChannelInit(struct hv_device *Device) goto Cleanup; } - osd_WaitEventWait(request->WaitEvent); + osd_waitevent_wait(request->wait_event); /* TODO: Check returned version */ - if (vstorPacket->Operation != VStorOperationCompleteIo || - vstorPacket->Status != 0) { + if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || + vstor_packet->status != 0) { DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed " "(op %d status 0x%x)", - vstorPacket->Operation, vstorPacket->Status); + vstor_packet->operation, vstor_packet->status); goto Cleanup; } - storDevice->PathId = vstorPacket->StorageChannelProperties.PathId; - storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId; + stor_device->path_id = vstor_packet->storage_channel_properties.path_id; + stor_device->target_id + = vstor_packet->storage_channel_properties.target_id; DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", - vstorPacket->StorageChannelProperties.Flags, - vstorPacket->StorageChannelProperties.MaxTransferBytes); + vstor_packet->storage_channel_properties.flags, + vstor_packet->storage_channel_properties.max_transfer_bytes); DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION..."); - memset(vstorPacket, 0, sizeof(struct vstor_packet)); - vstorPacket->Operation = VStorOperationEndInitialization; - vstorPacket->Flags = REQUEST_COMPLETION_FLAG; + memset(vstor_packet, 0, sizeof(struct vstor_packet)); + vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION; + vstor_packet->flags = REQUEST_COMPLETION_FLAG; - ret = vmbus_sendpacket(Device->channel, vstorPacket, + ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, VmbusPacketTypeDataInBand, @@ -323,125 +326,125 @@ static int StorVscChannelInit(struct hv_device *Device) goto Cleanup; } - osd_WaitEventWait(request->WaitEvent); + osd_waitevent_wait(request->wait_event); - if (vstorPacket->Operation != VStorOperationCompleteIo || - vstorPacket->Status != 0) { + if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || + vstor_packet->status != 0) { DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed " "(op %d status 0x%x)", - vstorPacket->Operation, vstorPacket->Status); + vstor_packet->operation, vstor_packet->status); goto Cleanup; } DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****"); Cleanup: - kfree(request->WaitEvent); - request->WaitEvent = NULL; + kfree(request->wait_event); + request->wait_event = NULL; nomem: - PutStorDevice(Device); + put_stor_device(device); return ret; } -static void StorVscOnIOCompletion(struct hv_device *Device, - struct vstor_packet *VStorPacket, - struct storvsc_request_extension *RequestExt) +static void stor_vsc_on_io_completion(struct hv_device *device, + struct vstor_packet *vstor_packet, + struct storvsc_request_extension *request_ext) { struct hv_storvsc_request *request; - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; - storDevice = MustGetStorDevice(Device); - if (!storDevice) { + stor_device = must_get_stor_device(device); + if (!stor_device) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); return; } DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p " - "completed bytes xfer %u", RequestExt, - VStorPacket->VmSrb.DataTransferLength); + "completed bytes xfer %u", request_ext, + vstor_packet->vm_srb.data_transfer_length); - /* ASSERT(RequestExt != NULL); */ - /* ASSERT(RequestExt->Request != NULL); */ + /* ASSERT(request_ext != NULL); */ + /* ASSERT(request_ext->request != NULL); */ - request = RequestExt->Request; + request = request_ext->request; /* ASSERT(request->OnIOCompletion != NULL); */ /* Copy over the status...etc */ - request->Status = VStorPacket->VmSrb.ScsiStatus; + request->status = vstor_packet->vm_srb.scsi_status; - if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1) { + if (request->status != 0 || vstor_packet->vm_srb.srb_status != 1) { DPRINT_WARN(STORVSC, "cmd 0x%x scsi status 0x%x srb status 0x%x\n", - request->Cdb[0], VStorPacket->VmSrb.ScsiStatus, - VStorPacket->VmSrb.SrbStatus); + request->cdb[0], vstor_packet->vm_srb.scsi_status, + vstor_packet->vm_srb.srb_status); } - if ((request->Status & 0xFF) == 0x02) { + if ((request->status & 0xFF) == 0x02) { /* CHECK_CONDITION */ - if (VStorPacket->VmSrb.SrbStatus & 0x80) { + if (vstor_packet->vm_srb.srb_status & 0x80) { /* autosense data available */ DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data " - "valid - len %d\n", RequestExt, - VStorPacket->VmSrb.SenseInfoLength); + "valid - len %d\n", request_ext, + vstor_packet->vm_srb.sense_info_length); - /* ASSERT(VStorPacket->VmSrb.SenseInfoLength <= */ + /* ASSERT(vstor_packet->vm_srb.sense_info_length <= */ /* request->SenseBufferSize); */ - memcpy(request->SenseBuffer, - VStorPacket->VmSrb.SenseData, - VStorPacket->VmSrb.SenseInfoLength); + memcpy(request->sense_buffer, + vstor_packet->vm_srb.sense_data, + vstor_packet->vm_srb.sense_info_length); - request->SenseBufferSize = - VStorPacket->VmSrb.SenseInfoLength; + request->sense_buffer_size = + vstor_packet->vm_srb.sense_info_length; } } /* TODO: */ - request->BytesXfer = VStorPacket->VmSrb.DataTransferLength; + request->bytes_xfer = vstor_packet->vm_srb.data_transfer_length; - request->OnIOCompletion(request); + request->on_io_completion(request); - atomic_dec(&storDevice->NumOutstandingRequests); + atomic_dec(&stor_device->num_outstanding_req); - PutStorDevice(Device); + put_stor_device(device); } -static void StorVscOnReceive(struct hv_device *Device, - struct vstor_packet *VStorPacket, - struct storvsc_request_extension *RequestExt) +static void stor_vsc_on_receive(struct hv_device *device, + struct vstor_packet *vstor_packet, + struct storvsc_request_extension *request_ext) { - switch (VStorPacket->Operation) { - case VStorOperationCompleteIo: + switch (vstor_packet->operation) { + case VSTOR_OPERATION_COMPLETE_IO: DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION"); - StorVscOnIOCompletion(Device, VStorPacket, RequestExt); + stor_vsc_on_io_completion(device, vstor_packet, request_ext); break; - case VStorOperationRemoveDevice: + case VSTOR_OPERATION_REMOVE_DEVICE: DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION"); /* TODO: */ break; default: DPRINT_INFO(STORVSC, "Unknown operation received - %d", - VStorPacket->Operation); + vstor_packet->operation); break; } } -static void StorVscOnChannelCallback(void *context) +static void stor_vsc_on_channel_callback(void *context) { struct hv_device *device = (struct hv_device *)context; - struct storvsc_device *storDevice; - u32 bytesRecvd; - u64 requestId; + struct storvsc_device *stor_device; + u32 bytes_recvd; + u64 request_id; unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet), 8)]; struct storvsc_request_extension *request; int ret; /* ASSERT(device); */ - storDevice = MustGetStorDevice(device); - if (!storDevice) { + stor_device = must_get_stor_device(device); + if (!stor_device) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); return; @@ -450,32 +453,33 @@ static void StorVscOnChannelCallback(void *context) do { ret = vmbus_recvpacket(device->channel, packet, ALIGN_UP(sizeof(struct vstor_packet), 8), - &bytesRecvd, &requestId); - if (ret == 0 && bytesRecvd > 0) { + &bytes_recvd, &request_id); + if (ret == 0 && bytes_recvd > 0) { DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", - bytesRecvd, requestId); + bytes_recvd, request_id); - /* ASSERT(bytesRecvd == sizeof(struct vstor_packet)); */ + /* ASSERT(bytes_recvd == + sizeof(struct vstor_packet)); */ request = (struct storvsc_request_extension *) - (unsigned long)requestId; + (unsigned long)request_id; /* ASSERT(request);c */ - /* if (vstorPacket.Flags & SYNTHETIC_FLAG) */ - if ((request == &storDevice->InitRequest) || - (request == &storDevice->ResetRequest)) { + /* if (vstor_packet.Flags & SYNTHETIC_FLAG) */ + if ((request == &stor_device->init_request) || + (request == &stor_device->reset_request)) { /* DPRINT_INFO(STORVSC, * "reset completion - operation " * "%u status %u", - * vstorPacket.Operation, - * vstorPacket.Status); */ + * vstor_packet.Operation, + * vstor_packet.Status); */ - memcpy(&request->VStorPacket, packet, + memcpy(&request->vstor_packet, packet, sizeof(struct vstor_packet)); - osd_WaitEventSet(request->WaitEvent); + osd_waitevent_set(request->wait_event); } else { - StorVscOnReceive(device, + stor_vsc_on_receive(device, (struct vstor_packet *)packet, request); } @@ -485,52 +489,55 @@ static void StorVscOnChannelCallback(void *context) } } while (1); - PutStorDevice(device); + put_stor_device(device); return; } -static int StorVscConnectToVsp(struct hv_device *Device) +static int stor_vsc_connect_to_vsp(struct hv_device *device) { struct vmstorage_channel_properties props; - struct storvsc_driver_object *storDriver; + struct storvsc_driver_object *stor_driver; int ret; - storDriver = (struct storvsc_driver_object *)Device->Driver; + stor_driver = (struct storvsc_driver_object *)device->Driver; memset(&props, 0, sizeof(struct vmstorage_channel_properties)); /* Open the channel */ - ret = vmbus_open(Device->channel, - storDriver->RingBufferSize, storDriver->RingBufferSize, + ret = vmbus_open(device->channel, + stor_driver->ring_buffer_size, + stor_driver->ring_buffer_size, (void *)&props, sizeof(struct vmstorage_channel_properties), - StorVscOnChannelCallback, Device); + stor_vsc_on_channel_callback, device); DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", - props.PathId, props.TargetId, props.MaxTransferBytes); + props.path_id, props.target_id, props.max_transfer_bytes); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to open channel: %d", ret); return -1; } - ret = StorVscChannelInit(Device); + ret = stor_vsc_channel_init(device); return ret; } /* - * StorVscOnDeviceAdd - Callback when the device belonging to this driver is added + * stor_vsc_on_device_add - Callback when the device belonging to this driver + * is added */ -static int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) +static int stor_vsc_on_device_add(struct hv_device *device, + void *additional_info) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; /* struct vmstorage_channel_properties *props; */ - struct storvsc_device_info *deviceInfo; + struct storvsc_device_info *device_info; int ret = 0; - deviceInfo = (struct storvsc_device_info *)AdditionalInfo; - storDevice = AllocStorDevice(Device); - if (!storDevice) { + device_info = (struct storvsc_device_info *)additional_info; + stor_device = alloc_stor_device(device); + if (!stor_device) { ret = -1; goto Cleanup; } @@ -550,103 +557,103 @@ static int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) storChannel->PathId = props->PathId; storChannel->TargetId = props->TargetId; */ - storDevice->PortNumber = deviceInfo->PortNumber; + stor_device->port_number = device_info->port_number; /* Send it back up */ - ret = StorVscConnectToVsp(Device); + ret = stor_vsc_connect_to_vsp(device); - /* deviceInfo->PortNumber = storDevice->PortNumber; */ - deviceInfo->PathId = storDevice->PathId; - deviceInfo->TargetId = storDevice->TargetId; + /* device_info->PortNumber = stor_device->PortNumber; */ + device_info->path_id = stor_device->path_id; + device_info->target_id = stor_device->target_id; DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", - storDevice->PortNumber, storDevice->PathId, - storDevice->TargetId); + stor_device->port_number, stor_device->path_id, + stor_device->target_id); Cleanup: return ret; } /* - * StorVscOnDeviceRemove - Callback when the our device is being removed + * stor_vsc_on_device_remove - Callback when the our device is being removed */ -static int StorVscOnDeviceRemove(struct hv_device *Device) +static int stor_vsc_on_device_remove(struct hv_device *device) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; DPRINT_INFO(STORVSC, "disabling storage device (%p)...", - Device->Extension); + device->Extension); - storDevice = ReleaseStorDevice(Device); + stor_device = release_stor_device(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 (atomic_read(&storDevice->NumOutstandingRequests)) { + while (atomic_read(&stor_device->num_outstanding_req)) { DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", - atomic_read(&storDevice->NumOutstandingRequests)); + atomic_read(&stor_device->num_outstanding_req)); udelay(100); } DPRINT_INFO(STORVSC, "removing storage device (%p)...", - Device->Extension); + device->Extension); - storDevice = FinalReleaseStorDevice(Device); + stor_device = final_release_stor_device(device); - DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice); + DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", stor_device); /* Close the channel */ - vmbus_close(Device->channel); + vmbus_close(device->channel); - FreeStorDevice(storDevice); + free_stor_device(stor_device); return 0; } -int StorVscOnHostReset(struct hv_device *Device) +int stor_vsc_on_host_reset(struct hv_device *device) { - struct storvsc_device *storDevice; + struct storvsc_device *stor_device; struct storvsc_request_extension *request; - struct vstor_packet *vstorPacket; + struct vstor_packet *vstor_packet; int ret; DPRINT_INFO(STORVSC, "resetting host adapter..."); - storDevice = GetStorDevice(Device); - if (!storDevice) { + stor_device = get_stor_device(device); + if (!stor_device) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); return -1; } - request = &storDevice->ResetRequest; - vstorPacket = &request->VStorPacket; + request = &stor_device->reset_request; + vstor_packet = &request->vstor_packet; - request->WaitEvent = osd_WaitEventCreate(); - if (!request->WaitEvent) { + request->wait_event = osd_waitevent_create(); + if (!request->wait_event) { ret = -ENOMEM; goto Cleanup; } - vstorPacket->Operation = VStorOperationResetBus; - vstorPacket->Flags = REQUEST_COMPLETION_FLAG; - vstorPacket->VmSrb.PathId = storDevice->PathId; + vstor_packet->operation = VSTOR_OPERATION_RESET_BUS; + vstor_packet->flags = REQUEST_COMPLETION_FLAG; + vstor_packet->vm_srb.path_id = stor_device->path_id; - ret = vmbus_sendpacket(Device->channel, vstorPacket, + ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), - (unsigned long)&storDevice->ResetRequest, + (unsigned long)&stor_device->reset_request, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", - vstorPacket, ret); + vstor_packet, ret); goto Cleanup; } /* FIXME: Add a timeout */ - osd_WaitEventWait(request->WaitEvent); + osd_waitevent_wait(request->wait_event); - kfree(request->WaitEvent); + kfree(request->wait_event); DPRINT_INFO(STORVSC, "host adapter reset completed"); /* @@ -655,118 +662,118 @@ int StorVscOnHostReset(struct hv_device *Device) */ Cleanup: - PutStorDevice(Device); + put_stor_device(device); return ret; } /* - * StorVscOnIORequest - Callback to initiate an I/O request + * stor_vsc_on_io_request - Callback to initiate an I/O request */ -static int StorVscOnIORequest(struct hv_device *Device, - struct hv_storvsc_request *Request) +static int stor_vsc_on_io_request(struct hv_device *device, + struct hv_storvsc_request *request) { - struct storvsc_device *storDevice; - struct storvsc_request_extension *requestExtension; - struct vstor_packet *vstorPacket; + struct storvsc_device *stor_device; + struct storvsc_request_extension *request_extension; + struct vstor_packet *vstor_packet; int ret = 0; - requestExtension = - (struct storvsc_request_extension *)Request->Extension; - vstorPacket = &requestExtension->VStorPacket; - storDevice = GetStorDevice(Device); + request_extension = + (struct storvsc_request_extension *)request->extension; + vstor_packet = &request_extension->vstor_packet; + stor_device = get_stor_device(device); DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, " - "Extension %p", Device, storDevice, Request, - requestExtension); + "Extension %p", device, stor_device, request, + request_extension); DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d", - Request, Request->DataBuffer.Length, Request->Bus, - Request->TargetId, Request->LunId, Request->CdbLen); + request, request->data_buffer.Length, request->bus, + request->target_id, request->lun_id, request->cdb_len); - if (!storDevice) { + if (!stor_device) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); return -2; } - /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, Request->Cdb, - * Request->CdbLen); */ + /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, request->Cdb, + * request->CdbLen); */ - requestExtension->Request = Request; - requestExtension->Device = Device; + request_extension->request = request; + request_extension->device = device; - memset(vstorPacket, 0 , sizeof(struct vstor_packet)); + memset(vstor_packet, 0 , sizeof(struct vstor_packet)); - vstorPacket->Flags |= REQUEST_COMPLETION_FLAG; + vstor_packet->flags |= REQUEST_COMPLETION_FLAG; - vstorPacket->VmSrb.Length = sizeof(struct vmscsi_request); + vstor_packet->vm_srb.length = sizeof(struct vmscsi_request); - vstorPacket->VmSrb.PortNumber = Request->Host; - vstorPacket->VmSrb.PathId = Request->Bus; - vstorPacket->VmSrb.TargetId = Request->TargetId; - vstorPacket->VmSrb.Lun = Request->LunId; + vstor_packet->vm_srb.port_number = request->host; + vstor_packet->vm_srb.path_id = request->bus; + vstor_packet->vm_srb.target_id = request->target_id; + vstor_packet->vm_srb.lun = request->lun_id; - vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE; + vstor_packet->vm_srb.sense_info_length = SENSE_BUFFER_SIZE; /* Copy over the scsi command descriptor block */ - vstorPacket->VmSrb.CdbLength = Request->CdbLen; - memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen); + vstor_packet->vm_srb.cdb_length = request->cdb_len; + memcpy(&vstor_packet->vm_srb.cdb, request->cdb, request->cdb_len); - vstorPacket->VmSrb.DataIn = Request->Type; - vstorPacket->VmSrb.DataTransferLength = Request->DataBuffer.Length; + vstor_packet->vm_srb.data_in = request->type; + vstor_packet->vm_srb.data_transfer_length = request->data_buffer.Length; - vstorPacket->Operation = VStorOperationExecuteSRB; + vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB; DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, " "lun %d senselen %d cdblen %d", - vstorPacket->VmSrb.Length, - vstorPacket->VmSrb.PortNumber, - vstorPacket->VmSrb.PathId, - vstorPacket->VmSrb.TargetId, - vstorPacket->VmSrb.Lun, - vstorPacket->VmSrb.SenseInfoLength, - vstorPacket->VmSrb.CdbLength); - - if (requestExtension->Request->DataBuffer.Length) { - ret = vmbus_sendpacket_multipagebuffer(Device->channel, - &requestExtension->Request->DataBuffer, - vstorPacket, + vstor_packet->vm_srb.length, + vstor_packet->vm_srb.port_number, + vstor_packet->vm_srb.path_id, + vstor_packet->vm_srb.target_id, + vstor_packet->vm_srb.lun, + vstor_packet->vm_srb.sense_info_length, + vstor_packet->vm_srb.cdb_length); + + if (request_extension->request->data_buffer.Length) { + ret = vmbus_sendpacket_multipagebuffer(device->channel, + &request_extension->request->data_buffer, + vstor_packet, sizeof(struct vstor_packet), - (unsigned long)requestExtension); + (unsigned long)request_extension); } else { - ret = vmbus_sendpacket(Device->channel, vstorPacket, + ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), - (unsigned long)requestExtension, + (unsigned long)request_extension, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); } if (ret != 0) { DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", - vstorPacket, ret); + vstor_packet, ret); } - atomic_inc(&storDevice->NumOutstandingRequests); + atomic_inc(&stor_device->num_outstanding_req); - PutStorDevice(Device); + put_stor_device(device); return ret; } /* - * StorVscOnCleanup - Perform any cleanup when the driver is removed + * stor_vsc_on_cleanup - Perform any cleanup when the driver is removed */ -static void StorVscOnCleanup(struct hv_driver *Driver) +static void stor_vsc_on_cleanup(struct hv_driver *driver) { } /* - * StorVscInitialize - Main entry point + * stor_vsc_initialize - Main entry point */ -int StorVscInitialize(struct hv_driver *Driver) +int stor_vsc_initialize(struct hv_driver *driver) { - struct storvsc_driver_object *storDriver; + struct storvsc_driver_object *stor_driver; - storDriver = (struct storvsc_driver_object *)Driver; + stor_driver = (struct storvsc_driver_object *)driver; DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd " "sizeof(struct storvsc_request_extension)=%zd " @@ -778,13 +785,14 @@ int StorVscInitialize(struct hv_driver *Driver) sizeof(struct vmscsi_request)); /* Make sure we are at least 2 pages since 1 page is used for control */ - /* ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1)); */ + /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */ - Driver->name = gDriverName; - memcpy(&Driver->deviceType, &gStorVscDeviceType, + driver->name = g_driver_name; + memcpy(&driver->deviceType, &gStorVscDeviceType, sizeof(struct hv_guid)); - storDriver->RequestExtSize = sizeof(struct storvsc_request_extension); + stor_driver->request_ext_size = + sizeof(struct storvsc_request_extension); /* * Divide the ring buffer data size (which is 1 page less @@ -792,22 +800,22 @@ int StorVscInitialize(struct hv_driver *Driver) * the ring buffer indices) by the max request size (which is * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) */ - storDriver->MaxOutstandingRequestsPerChannel = - ((storDriver->RingBufferSize - PAGE_SIZE) / + stor_driver->max_outstanding_req_per_channel = + ((stor_driver->ring_buffer_size - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(struct vstor_packet) + sizeof(u64), sizeof(u64))); DPRINT_INFO(STORVSC, "max io %u, currently %u\n", - storDriver->MaxOutstandingRequestsPerChannel, + stor_driver->max_outstanding_req_per_channel, STORVSC_MAX_IO_REQUESTS); /* Setup the dispatch table */ - storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd; - storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove; - storDriver->Base.OnCleanup = StorVscOnCleanup; + 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; - storDriver->OnIORequest = StorVscOnIORequest; + stor_driver->on_io_request = stor_vsc_on_io_request; return 0; } diff --git a/drivers/staging/hv/storvsc_api.h b/drivers/staging/hv/storvsc_api.h index 8505a1c5f9ee..fbf57556d890 100644 --- a/drivers/staging/hv/storvsc_api.h +++ b/drivers/staging/hv/storvsc_api.h @@ -53,58 +53,58 @@ enum storvsc_request_type{ }; struct hv_storvsc_request { - enum storvsc_request_type Type; - u32 Host; - u32 Bus; - u32 TargetId; - u32 LunId; - u8 *Cdb; - u32 CdbLen; - u32 Status; - u32 BytesXfer; + enum storvsc_request_type type; + u32 host; + u32 bus; + u32 target_id; + u32 lun_id; + u8 *cdb; + u32 cdb_len; + u32 status; + u32 bytes_xfer; - unsigned char *SenseBuffer; - u32 SenseBufferSize; + unsigned char *sense_buffer; + u32 sense_buffer_size; - void *Context; + void *context; - void (*OnIOCompletion)(struct hv_storvsc_request *Request); + void (*on_io_completion)(struct hv_storvsc_request *request); /* This points to the memory after DataBuffer */ - void *Extension; + void *extension; - struct hv_multipage_buffer DataBuffer; + struct hv_multipage_buffer data_buffer; }; /* Represents the block vsc driver */ struct storvsc_driver_object { /* Must be the first field */ /* Which is a bug FIXME! */ - struct hv_driver Base; + struct hv_driver base; /* Set by caller (in bytes) */ - u32 RingBufferSize; + u32 ring_buffer_size; /* Allocate this much private extension for each I/O request */ - u32 RequestExtSize; + u32 request_ext_size; /* Maximum # of requests in flight per channel/device */ - u32 MaxOutstandingRequestsPerChannel; + u32 max_outstanding_req_per_channel; /* Specific to this driver */ - int (*OnIORequest)(struct hv_device *Device, - struct hv_storvsc_request *Request); + int (*on_io_request)(struct hv_device *device, + struct hv_storvsc_request *request); }; struct storvsc_device_info { - unsigned int PortNumber; - unsigned char PathId; - unsigned char TargetId; + unsigned int port_number; + unsigned char path_id; + unsigned char target_id; }; /* Interface */ -int StorVscInitialize(struct hv_driver *driver); -int StorVscOnHostReset(struct hv_device *Device); -int BlkVscInitialize(struct hv_driver *driver); +int stor_vsc_initialize(struct hv_driver *driver); +int stor_vsc_on_host_reset(struct hv_device *device); +int blk_vsc_initialize(struct hv_driver *driver); #endif /* _STORVSC_API_H_ */ diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c index 6f8d67d0d64f..17f1b344fbc5 100644 --- a/drivers/staging/hv/storvsc_drv.c +++ b/drivers/staging/hv/storvsc_drv.c @@ -140,28 +140,28 @@ static int storvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv.drv_obj; struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx; - storvsc_drv_obj->RingBufferSize = storvsc_ringbuffer_size; + storvsc_drv_obj->ring_buffer_size = storvsc_ringbuffer_size; /* Callback to client driver to complete the initialization */ - drv_init(&storvsc_drv_obj->Base); + drv_init(&storvsc_drv_obj->base); DPRINT_INFO(STORVSC_DRV, "request extension size %u, max outstanding reqs %u", - storvsc_drv_obj->RequestExtSize, - storvsc_drv_obj->MaxOutstandingRequestsPerChannel); + storvsc_drv_obj->request_ext_size, + storvsc_drv_obj->max_outstanding_req_per_channel); - if (storvsc_drv_obj->MaxOutstandingRequestsPerChannel < + if (storvsc_drv_obj->max_outstanding_req_per_channel < STORVSC_MAX_IO_REQUESTS) { DPRINT_ERR(STORVSC_DRV, "The number of outstanding io requests (%d) " "is larger than that supported (%d) internally.", STORVSC_MAX_IO_REQUESTS, - storvsc_drv_obj->MaxOutstandingRequestsPerChannel); + storvsc_drv_obj->max_outstanding_req_per_channel); return -1; } - drv_ctx->driver.name = storvsc_drv_obj->Base.name; - memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, + drv_ctx->driver.name = storvsc_drv_obj->base.name; + memcpy(&drv_ctx->class_id, &storvsc_drv_obj->base.deviceType, sizeof(struct hv_guid)); drv_ctx->probe = storvsc_probe; @@ -206,8 +206,8 @@ 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.OnCleanup) + storvsc_drv_obj->base.OnCleanup(&storvsc_drv_obj->base); vmbus_child_driver_unregister(drv_ctx); return; @@ -231,7 +231,7 @@ static int storvsc_probe(struct device *device) struct host_device_context *host_device_ctx; struct storvsc_device_info device_info; - if (!storvsc_drv_obj->Base.OnDeviceAdd) + if (!storvsc_drv_obj->base.OnDeviceAdd) return -1; host = scsi_host_alloc(&scsi_driver, @@ -252,7 +252,7 @@ static int storvsc_probe(struct device *device) host_device_ctx->request_pool = kmem_cache_create(dev_name(&device_ctx->device), sizeof(struct storvsc_cmd_request) + - storvsc_drv_obj->RequestExtSize, 0, + storvsc_drv_obj->request_ext_size, 0, SLAB_HWCACHE_ALIGN, NULL); if (!host_device_ctx->request_pool) { @@ -260,9 +260,9 @@ static int storvsc_probe(struct device *device) return -ENOMEM; } - device_info.PortNumber = host->host_no; + 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.OnDeviceAdd(device_obj, (void *)&device_info); if (ret != 0) { DPRINT_ERR(STORVSC_DRV, "unable to add scsi vsc device"); @@ -272,8 +272,8 @@ static int storvsc_probe(struct device *device) } /* host_device_ctx->port = device_info.PortNumber; */ - host_device_ctx->path = device_info.PathId; - host_device_ctx->target = device_info.TargetId; + host_device_ctx->path = device_info.path_id; + host_device_ctx->target = device_info.target_id; /* max # of devices per target */ host->max_lun = STORVSC_MAX_LUNS_PER_TARGET; @@ -287,7 +287,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.OnDeviceRemove(device_obj); kmem_cache_destroy(host_device_ctx->request_pool); scsi_host_put(host); @@ -317,14 +317,14 @@ static int storvsc_remove(struct device *device) (struct host_device_context *)host->hostdata; - if (!storvsc_drv_obj->Base.OnDeviceRemove) + if (!storvsc_drv_obj->base.OnDeviceRemove) 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.OnDeviceRemove(device_obj); if (ret != 0) { /* TODO: */ DPRINT_ERR(STORVSC, "unable to remove vsc device (ret %d)", @@ -350,7 +350,7 @@ static int storvsc_remove(struct device *device) static void storvsc_commmand_completion(struct hv_storvsc_request *request) { struct storvsc_cmd_request *cmd_request = - (struct storvsc_cmd_request *)request->Context; + (struct storvsc_cmd_request *)request->context; struct scsi_cmnd *scmnd = cmd_request->cmd; struct host_device_context *host_device_ctx = (struct host_device_context *)scmnd->device->host->hostdata; @@ -375,16 +375,17 @@ static void storvsc_commmand_completion(struct hv_storvsc_request *request) cmd_request->bounce_sgl_count); } - scmnd->result = request->Status; + scmnd->result = request->status; if (scmnd->result) { if (scsi_normalize_sense(scmnd->sense_buffer, - request->SenseBufferSize, &sense_hdr)) + request->sense_buffer_size, &sense_hdr)) scsi_print_sense_hdr("storvsc", &sense_hdr); } - /* ASSERT(request->BytesXfer <= request->DataBuffer.Length); */ - scsi_set_resid(scmnd, request->DataBuffer.Length - request->BytesXfer); + /* ASSERT(request->BytesXfer <= request->data_buffer.Length); */ + scsi_set_resid(scmnd, + request->data_buffer.Length - request->bytes_xfer); scsi_done_fn = scmnd->scsi_done; @@ -657,42 +658,42 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, request = &cmd_request->request; - request->Extension = + request->extension = (void *)((unsigned long)cmd_request + request_size); DPRINT_DBG(STORVSC_DRV, "req %p size %d ext %d", request, request_size, - storvsc_drv_obj->RequestExtSize); + storvsc_drv_obj->request_ext_size); /* Build the SRB */ switch (scmnd->sc_data_direction) { case DMA_TO_DEVICE: - request->Type = WRITE_TYPE; + request->type = WRITE_TYPE; break; case DMA_FROM_DEVICE: - request->Type = READ_TYPE; + request->type = READ_TYPE; break; default: - request->Type = UNKNOWN_TYPE; + request->type = UNKNOWN_TYPE; break; } - request->OnIOCompletion = storvsc_commmand_completion; - request->Context = cmd_request;/* scmnd; */ + request->on_io_completion = storvsc_commmand_completion; + request->context = cmd_request;/* scmnd; */ /* request->PortId = scmnd->device->channel; */ - request->Host = host_device_ctx->port; - request->Bus = scmnd->device->channel; - request->TargetId = scmnd->device->id; - request->LunId = scmnd->device->lun; + request->host = host_device_ctx->port; + request->bus = scmnd->device->channel; + request->target_id = scmnd->device->id; + request->lun_id = scmnd->device->lun; /* ASSERT(scmnd->cmd_len <= 16); */ - request->CdbLen = scmnd->cmd_len; - request->Cdb = scmnd->cmnd; + request->cdb_len = scmnd->cmd_len; + request->cdb = scmnd->cmnd; - request->SenseBuffer = scmnd->sense_buffer; - request->SenseBufferSize = SCSI_SENSE_BUFFERSIZE; + request->sense_buffer = scmnd->sense_buffer; + request->sense_buffer_size = SCSI_SENSE_BUFFERSIZE; - request->DataBuffer.Length = scsi_bufflen(scmnd); + request->data_buffer.Length = scsi_bufflen(scmnd); if (scsi_sg_count(scmnd)) { sgl = (struct scatterlist *)scsi_sglist(scmnd); sg_count = scsi_sg_count(scmnd); @@ -733,25 +734,25 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, sg_count = cmd_request->bounce_sgl_count; } - request->DataBuffer.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->DataBuffer.PfnArray[i] = + request->data_buffer.PfnArray[i] = page_to_pfn(sg_page((&sgl[i]))); } } else if (scsi_sglist(scmnd)) { /* ASSERT(scsi_bufflen(scmnd) <= PAGE_SIZE); */ - request->DataBuffer.Offset = + request->data_buffer.Offset = virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1); - request->DataBuffer.PfnArray[0] = + request->data_buffer.PfnArray[0] = virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT; } retry_request: /* Invokes the vsc to start an IO */ - ret = storvsc_drv_obj->OnIORequest(&device_ctx->device_obj, + ret = storvsc_drv_obj->on_io_request(&device_ctx->device_obj, &cmd_request->request); if (ret == -1) { /* no more space */ @@ -844,7 +845,7 @@ static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd) scmnd->device, &device_ctx->device_obj); /* Invokes the vsc to reset the host/bus */ - ret = StorVscOnHostReset(&device_ctx->device_obj); + ret = stor_vsc_on_host_reset(&device_ctx->device_obj); if (ret != 0) return ret; @@ -939,7 +940,7 @@ static int __init storvsc_init(void) int ret; DPRINT_INFO(STORVSC_DRV, "Storvsc initializing...."); - ret = storvsc_drv_init(StorVscInitialize); + ret = storvsc_drv_init(stor_vsc_initialize); return ret; } diff --git a/drivers/staging/hv/vmbus.c b/drivers/staging/hv/vmbus.c deleted file mode 100644 index d449daf81976..000000000000 --- a/drivers/staging/hv/vmbus.c +++ /dev/null @@ -1,274 +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/kernel.h> -#include <linux/mm.h> -#include <linux/slab.h> -#include "osd.h" -#include "logging.h" -#include "version_info.h" -#include "vmbus_private.h" - -static const char *gDriverName = "vmbus"; - -/* - * 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 = { - .data = { - 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d, - 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85 - } -}; - -/* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */ -static const struct hv_guid gVmbusDeviceId = { - .data = { - 0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40, - 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5 - } -}; - -static struct hv_driver *gDriver; /* vmbus driver object */ -static struct hv_device *gDevice; /* vmbus root device */ - -/* - * VmbusGetChannelOffers - Retrieve the channel offers from the parent partition - */ -static void VmbusGetChannelOffers(void) -{ - vmbus_request_offers(); -} - -/* - * VmbusCreateChildDevice - Creates the child device on the bus that represents the channel offer - */ -struct hv_device *VmbusChildDeviceCreate(struct hv_guid *DeviceType, - struct hv_guid *DeviceInstance, - struct vmbus_channel *channel) -{ - struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver; - - return vmbusDriver->OnChildDeviceCreate(DeviceType, DeviceInstance, - channel); -} - -/* - * VmbusChildDeviceAdd - Registers the child device with the vmbus - */ -int VmbusChildDeviceAdd(struct hv_device *ChildDevice) -{ - struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver; - - return vmbusDriver->OnChildDeviceAdd(gDevice, ChildDevice); -} - -/* - * VmbusChildDeviceRemove Unregisters the child device from the vmbus - */ -void VmbusChildDeviceRemove(struct hv_device *ChildDevice) -{ - struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver; - - vmbusDriver->OnChildDeviceRemove(ChildDevice); -} - -/* - * VmbusOnDeviceAdd - Callback when the root bus device is added - */ -static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo) -{ - u32 *irqvector = AdditionalInfo; - int ret; - - gDevice = dev; - - memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid)); - memcpy(&gDevice->deviceInstance, &gVmbusDeviceId, - sizeof(struct hv_guid)); - - /* strcpy(dev->name, "vmbus"); */ - /* SynIC setup... */ - on_each_cpu(HvSynicInit, (void *)irqvector, 1); - - /* Connect to VMBus in the root partition */ - ret = VmbusConnect(); - - /* 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(HvSynicCleanup, 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; */ - - HvCleanup(); -} - -/* - * VmbusOnMsgDPC - DPC routine to handle messages from the hypervisior - */ -static void VmbusOnMsgDPC(struct hv_driver *drv) -{ - int cpu = smp_processor_id(); - void *page_addr = gHvContext.synICMessagePage[cpu]; - struct hv_message *msg = (struct hv_message *)page_addr + - VMBUS_MESSAGE_SINT; - struct hv_message *copied; - - while (1) { - if (msg->Header.MessageType == HvMessageTypeNone) { - /* no msg */ - break; - } else { - copied = kmemdup(msg, sizeof(*copied), GFP_ATOMIC); - if (copied == NULL) - continue; - - osd_schedule_callback(gVmbusConnection.WorkQueue, - vmbus_onmessage, - (void *)copied); - } - - msg->Header.MessageType = HvMessageTypeNone; - - /* - * Make sure the write to MessageType (ie set to - * HvMessageTypeNone) happens before we read the - * MessagePending and EOMing. Otherwise, the EOMing - * will not deliver any more messages since there is - * no empty slot - */ - mb(); - - if (msg->Header.MessageFlags.MessagePending) { - /* - * This will cause message queue rescan to - * possibly deliver another msg from the - * hypervisor - */ - wrmsrl(HV_X64_MSR_EOM, 0); - } - } -} - -/* - * VmbusOnEventDPC - DPC routine to handle events from the hypervisior - */ -static void VmbusOnEventDPC(struct hv_driver *drv) -{ - /* TODO: Process any events */ - VmbusOnEvents(); -} - -/* - * VmbusOnISR - ISR routine - */ -static int VmbusOnISR(struct hv_driver *drv) -{ - int ret = 0; - int cpu = smp_processor_id(); - void *page_addr; - struct hv_message *msg; - union hv_synic_event_flags *event; - - page_addr = gHvContext.synICMessagePage[cpu]; - msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; - - /* Check if there are actual msgs to be process */ - if (msg->Header.MessageType != HvMessageTypeNone) { - DPRINT_DBG(VMBUS, "received msg type %d size %d", - msg->Header.MessageType, - msg->Header.PayloadSize); - ret |= 0x1; - } - - /* TODO: Check if there are events to be process */ - page_addr = gHvContext.synICEventPage[cpu]; - event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT; - - /* Since we are a child, we only need to check bit 0 */ - if (test_and_clear_bit(0, (unsigned long *) &event->Flags32[0])) { - DPRINT_DBG(VMBUS, "received event %d", event->Flags32[0]); - ret |= 0x2; - } - - return ret; -} - -/* - * VmbusInitialize - Main entry point - */ -int VmbusInitialize(struct hv_driver *drv) -{ - struct vmbus_driver *driver = (struct vmbus_driver *)drv; - int ret; - - DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++", - HV_DRV_VERSION); - DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++", - VMBUS_REVISION_NUMBER); - DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++", - VMBUS_MESSAGE_SINT); - DPRINT_DBG(VMBUS, "sizeof(vmbus_channel_packet_page_buffer)=%zd, " - "sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd", - sizeof(struct vmbus_channel_packet_page_buffer), - sizeof(struct vmbus_channel_packet_multipage_buffer)); - - drv->name = gDriverName; - memcpy(&drv->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid)); - - /* Setup dispatch table */ - driver->Base.OnDeviceAdd = VmbusOnDeviceAdd; - driver->Base.OnDeviceRemove = VmbusOnDeviceRemove; - driver->Base.OnCleanup = VmbusOnCleanup; - driver->OnIsr = VmbusOnISR; - driver->OnMsgDpc = VmbusOnMsgDPC; - driver->OnEventDpc = VmbusOnEventDPC; - driver->GetChannelOffers = VmbusGetChannelOffers; - - /* Hypervisor initialization...setup hypercall page..etc */ - ret = HvInit(); - if (ret != 0) - DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x", - ret); - gDriver = drv; - - return ret; -} diff --git a/drivers/staging/hv/vmbus_api.h b/drivers/staging/hv/vmbus_api.h index 2af42e550076..2da3f52610b3 100644 --- a/drivers/staging/hv/vmbus_api.h +++ b/drivers/staging/hv/vmbus_api.h @@ -115,28 +115,4 @@ struct hv_device { void *Extension; }; -/* Vmbus driver object */ -struct vmbus_driver { - /* !! Must be the 1st field !! */ - /* FIXME if ^, then someone is doing somthing stupid */ - struct hv_driver Base; - - /* Set by the caller */ - struct hv_device * (*OnChildDeviceCreate)(struct hv_guid *DeviceType, - struct hv_guid *DeviceInstance, - struct vmbus_channel *channel); - void (*OnChildDeviceDestroy)(struct hv_device *device); - int (*OnChildDeviceAdd)(struct hv_device *RootDevice, - struct hv_device *ChildDevice); - void (*OnChildDeviceRemove)(struct hv_device *device); - - /* Set by the callee */ - int (*OnIsr)(struct hv_driver *driver); - void (*OnMsgDpc)(struct hv_driver *driver); - void (*OnEventDpc)(struct hv_driver *driver); - void (*GetChannelOffers)(void); -}; - -int VmbusInitialize(struct hv_driver *drv); - #endif /* _VMBUS_API_H_ */ diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c index 0d9f3a411e72..84fdb64d3ceb 100644 --- a/drivers/staging/hv/vmbus_drv.c +++ b/drivers/staging/hv/vmbus_drv.c @@ -33,6 +33,7 @@ #include "logging.h" #include "vmbus.h" #include "channel.h" +#include "vmbus_private.h" /* FIXME! We need to do this dynamically for PIC and APIC system */ @@ -46,7 +47,7 @@ struct vmbus_driver_context { /* The driver field is not used in here. Instead, the bus field is */ /* used to represent the driver */ struct driver_context drv_ctx; - struct vmbus_driver drv_obj; + struct hv_driver drv_obj; struct bus_type bus; struct tasklet_struct msg_dpc; @@ -69,13 +70,6 @@ static irqreturn_t vmbus_isr(int irq, void *dev_id); static void vmbus_device_release(struct device *device); static void vmbus_bus_release(struct device *device); -static struct hv_device *vmbus_child_device_create(struct hv_guid *type, - struct hv_guid *instance, - struct vmbus_channel *channel); -static void vmbus_child_device_destroy(struct hv_device *device_obj); -static int vmbus_child_device_register(struct hv_device *root_device_obj, - struct hv_device *child_device_obj); -static void vmbus_child_device_unregister(struct hv_device *child_device_obj); static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf); @@ -129,6 +123,182 @@ static struct vmbus_driver_context g_vmbus_drv = { .bus.dev_attrs = vmbus_device_attrs, }; +static const char *gDriverName = "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 = { + .data = { + 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d, + 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85 + } +}; + +/* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */ +static const struct hv_guid gVmbusDeviceId = { + .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 */ + +/* + * 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 + */ +static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo) +{ + u32 *irqvector = AdditionalInfo; + int ret; + + gDevice = dev; + + memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid)); + memcpy(&gDevice->deviceInstance, &gVmbusDeviceId, + sizeof(struct hv_guid)); + + /* strcpy(dev->name, "vmbus"); */ + /* SynIC setup... */ + on_each_cpu(hv_synic_init, (void *)irqvector, 1); + + /* Connect to VMBus in the root partition */ + ret = VmbusConnect(); + + /* 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; + struct hv_message msg; +}; + +static void vmbus_onmessage_work(struct work_struct *work) +{ + struct onmessage_work_context *ctx; + + ctx = container_of(work, struct onmessage_work_context, + work); + vmbus_onmessage(&ctx->msg); + kfree(ctx); +} + +/* + * vmbus_on_msg_dpc - DPC routine to handle messages from the hypervisior + */ +static void vmbus_on_msg_dpc(struct hv_driver *drv) +{ + int cpu = smp_processor_id(); + void *page_addr = hv_context.synic_message_page[cpu]; + struct hv_message *msg = (struct hv_message *)page_addr + + VMBUS_MESSAGE_SINT; + struct onmessage_work_context *ctx; + + while (1) { + if (msg->header.message_type == HVMSG_NONE) { + /* no msg */ + break; + } else { + ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC); + if (ctx == NULL) + continue; + INIT_WORK(&ctx->work, vmbus_onmessage_work); + memcpy(&ctx->msg, msg, sizeof(*msg)); + queue_work(gVmbusConnection.WorkQueue, &ctx->work); + } + + msg->header.message_type = HVMSG_NONE; + + /* + * Make sure the write to MessageType (ie set to + * HVMSG_NONE) happens before we read the + * MessagePending and EOMing. Otherwise, the EOMing + * will not deliver any more messages since there is + * no empty slot + */ + mb(); + + if (msg->header.message_flags.msg_pending) { + /* + * This will cause message queue rescan to + * possibly deliver another msg from the + * hypervisor + */ + wrmsrl(HV_X64_MSR_EOM, 0); + } + } +} + +/* + * vmbus_on_isr - ISR routine + */ +static int vmbus_on_isr(struct hv_driver *drv) +{ + int ret = 0; + int cpu = smp_processor_id(); + void *page_addr; + struct hv_message *msg; + union hv_synic_event_flags *event; + + page_addr = hv_context.synic_message_page[cpu]; + msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; + + /* Check if there are actual msgs to be process */ + if (msg->header.message_type != HVMSG_NONE) { + DPRINT_DBG(VMBUS, "received msg type %d size %d", + msg->header.message_type, + msg->header.payload_size); + ret |= 0x1; + } + + /* TODO: Check if there are events to be process */ + page_addr = hv_context.synic_event_page[cpu]; + event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT; + + /* Since we are a child, we only need to check bit 0 */ + if (test_and_clear_bit(0, (unsigned long *) &event->flags32[0])) { + DPRINT_DBG(VMBUS, "received event %d", event->flags32[0]); + ret |= 0x2; + } + + return ret; +} + static void get_channel_info(struct hv_device *device, struct hv_device_info *info) { @@ -139,35 +309,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->ChannelId = debug_info.relid; + info->ChannelState = debug_info.state; + memcpy(&info->ChannelType, &debug_info.interfacetype, sizeof(struct hv_guid)); - memcpy(&info->ChannelInstance, &debug_info.InterfaceInstance, + memcpy(&info->ChannelInstance, &debug_info.interface_instance, sizeof(struct hv_guid)); - info->MonitorId = debug_info.MonitorId; - - info->ServerMonitorPending = debug_info.ServerMonitorPending; - info->ServerMonitorLatency = debug_info.ServerMonitorLatency; - info->ServerMonitorConnectionId = debug_info.ServerMonitorConnectionId; - - info->ClientMonitorPending = debug_info.ClientMonitorPending; - info->ClientMonitorLatency = debug_info.ClientMonitorLatency; - info->ClientMonitorConnectionId = debug_info.ClientMonitorConnectionId; - - info->Inbound.InterruptMask = debug_info.Inbound.CurrentInterruptMask; - info->Inbound.ReadIndex = debug_info.Inbound.CurrentReadIndex; - info->Inbound.WriteIndex = debug_info.Inbound.CurrentWriteIndex; - info->Inbound.BytesAvailToRead = debug_info.Inbound.BytesAvailToRead; - info->Inbound.BytesAvailToWrite = debug_info.Inbound.BytesAvailToWrite; - - info->Outbound.InterruptMask = debug_info.Outbound.CurrentInterruptMask; - info->Outbound.ReadIndex = debug_info.Outbound.CurrentReadIndex; - info->Outbound.WriteIndex = debug_info.Outbound.CurrentWriteIndex; - info->Outbound.BytesAvailToRead = debug_info.Outbound.BytesAvailToRead; + info->MonitorId = debug_info.monitorid; + + info->ServerMonitorPending = debug_info.servermonitor_pending; + info->ServerMonitorLatency = debug_info.servermonitor_latency; + info->ServerMonitorConnectionId = debug_info.servermonitor_connectionid; + + info->ClientMonitorPending = debug_info.clientmonitor_pending; + info->ClientMonitorLatency = debug_info.clientmonitor_latency; + info->ClientMonitorConnectionId = 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 = + debug_info.inbound.bytes_avail_towrite; + + info->Outbound.InterruptMask = + 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 = + debug_info.outbound.bytes_avail_toread; info->Outbound.BytesAvailToWrite = - debug_info.Outbound.BytesAvailToWrite; + debug_info.outbound.bytes_avail_towrite; } /* @@ -286,44 +459,55 @@ static ssize_t vmbus_show_device_attr(struct device *dev, * - setup the vmbus root device * - retrieve the channel offers */ -static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv)) +static int vmbus_bus_init(void) { struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; - struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; + struct hv_driver *driver = &g_vmbus_drv.drv_obj; struct vm_device *dev_ctx = &g_vmbus_drv.device_ctx; int ret; unsigned int vector; - /* - * Set this up to allow lower layer to callback to add/remove child - * devices on the bus - */ - vmbus_drv_obj->OnChildDeviceCreate = vmbus_child_device_create; - vmbus_drv_obj->OnChildDeviceDestroy = vmbus_child_device_destroy; - vmbus_drv_obj->OnChildDeviceAdd = vmbus_child_device_register; - vmbus_drv_obj->OnChildDeviceRemove = vmbus_child_device_unregister; - - /* Call to bus driver to initialize */ - ret = drv_init(&vmbus_drv_obj->Base); + DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++", + HV_DRV_VERSION); + DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++", + VMBUS_REVISION_NUMBER); + DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++", + VMBUS_MESSAGE_SINT); + DPRINT_DBG(VMBUS, "sizeof(vmbus_channel_packet_page_buffer)=%zd, " + "sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd", + 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(); if (ret != 0) { - DPRINT_ERR(VMBUS_DRV, "Unable to initialize vmbus (%d)", ret); + DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x", + ret); goto cleanup; } /* Sanity checks */ - if (!vmbus_drv_obj->Base.OnDeviceAdd) { + if (!driver->OnDeviceAdd) { DPRINT_ERR(VMBUS_DRV, "OnDeviceAdd() routine not set"); ret = -1; goto cleanup; } - vmbus_drv_ctx->bus.name = vmbus_drv_obj->Base.name; + vmbus_drv_ctx->bus.name = driver->name; /* Initialize the bus context */ tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc, - (unsigned long)vmbus_drv_obj); + (unsigned long)driver); tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc, - (unsigned long)vmbus_drv_obj); + (unsigned long)driver); /* Now, register the bus driver with LDM */ ret = bus_register(&vmbus_drv_ctx->bus); @@ -334,7 +518,7 @@ static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv)) /* Get the interrupt resource */ ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM, - vmbus_drv_obj->Base.name, NULL); + driver->name, NULL); if (ret != 0) { DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", @@ -352,7 +536,7 @@ static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv)) /* Call to bus driver to add the root device */ memset(dev_ctx, 0, sizeof(struct vm_device)); - ret = vmbus_drv_obj->Base.OnDeviceAdd(&dev_ctx->device_obj, &vector); + ret = driver->OnDeviceAdd(&dev_ctx->device_obj, &vector); if (ret != 0) { DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to add vmbus root device"); @@ -392,9 +576,7 @@ static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv)) goto cleanup; } - - vmbus_drv_obj->GetChannelOffers(); - + vmbus_request_offers(); wait_for_completion(&hv_channel_ready); cleanup: @@ -408,17 +590,17 @@ cleanup: */ static void vmbus_bus_exit(void) { - struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; + struct hv_driver *driver = &g_vmbus_drv.drv_obj; struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; struct vm_device *dev_ctx = &g_vmbus_drv.device_ctx; /* Remove the root device */ - if (vmbus_drv_obj->Base.OnDeviceRemove) - vmbus_drv_obj->Base.OnDeviceRemove(&dev_ctx->device_obj); + if (driver->OnDeviceRemove) + driver->OnDeviceRemove(&dev_ctx->device_obj); - if (vmbus_drv_obj->Base.OnCleanup) - vmbus_drv_obj->Base.OnCleanup(&vmbus_drv_obj->Base); + if (driver->OnCleanup) + driver->OnCleanup(driver); /* Unregister the root bus device */ device_unregister(&dev_ctx->device); @@ -446,7 +628,6 @@ static void vmbus_bus_exit(void) */ int vmbus_child_driver_register(struct driver_context *driver_ctx) { - struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; int ret; DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", @@ -457,7 +638,7 @@ int vmbus_child_driver_register(struct driver_context *driver_ctx) ret = driver_register(&driver_ctx->driver); - vmbus_drv_obj->GetChannelOffers(); + vmbus_request_offers(); return ret; } @@ -489,9 +670,9 @@ EXPORT_SYMBOL(vmbus_child_driver_unregister); * vmbus_child_device_create - Creates and registers a new child device * on the vmbus. */ -static struct hv_device *vmbus_child_device_create(struct hv_guid *type, - struct hv_guid *instance, - struct vmbus_channel *channel) +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; @@ -538,8 +719,8 @@ static struct hv_device *vmbus_child_device_create(struct hv_guid *type, /* * vmbus_child_device_register - Register the child device on the specified bus */ -static 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 *root_device_obj, + struct hv_device *child_device_obj) { int ret = 0; struct vm_device *root_device_ctx = @@ -583,7 +764,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj, * vmbus_child_device_unregister - Remove the specified child device * from the vmbus. */ -static void vmbus_child_device_unregister(struct hv_device *device_obj) +void vmbus_child_device_unregister(struct hv_device *device_obj) { struct vm_device *device_ctx = to_vm_device(device_obj); @@ -601,13 +782,6 @@ static void vmbus_child_device_unregister(struct hv_device *device_obj) } /* - * vmbus_child_device_destroy - Destroy the specified child device on the vmbus. - */ -static void vmbus_child_device_destroy(struct hv_device *device_obj) -{ -} - -/* * vmbus_uevent - add uevent for our device * * This routine is invoked when a device is added or removed on the vmbus to @@ -701,7 +875,7 @@ static int vmbus_match(struct device *device, struct device_driver *driver) struct vmbus_driver_context *vmbus_drv_ctx = (struct vmbus_driver_context *)driver_ctx; - device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj.Base; + device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj; DPRINT_INFO(VMBUS_DRV, "device object (%p) set to driver object (%p)", &device_ctx->device_obj, @@ -849,7 +1023,6 @@ static void vmbus_device_release(struct device *device) { struct vm_device *device_ctx = device_to_vm_device(device); - /* vmbus_child_device_destroy(&device_ctx->device_obj); */ kfree(device_ctx); /* !!DO NOT REFERENCE device_ctx anymore at this point!! */ @@ -860,36 +1033,28 @@ static void vmbus_device_release(struct device *device) */ static void vmbus_msg_dpc(unsigned long data) { - struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data; - - /* ASSERT(vmbus_drv_obj->OnMsgDpc != NULL); */ + struct hv_driver *driver = (struct hv_driver *)data; /* Call to bus driver to handle interrupt */ - vmbus_drv_obj->OnMsgDpc(&vmbus_drv_obj->Base); + vmbus_on_msg_dpc(driver); } /* - * vmbus_msg_dpc - Tasklet routine to handle hypervisor events + * vmbus_event_dpc - Tasklet routine to handle hypervisor events */ static void vmbus_event_dpc(unsigned long data) { - struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data; - - /* ASSERT(vmbus_drv_obj->OnEventDpc != NULL); */ - /* Call to bus driver to handle interrupt */ - vmbus_drv_obj->OnEventDpc(&vmbus_drv_obj->Base); + VmbusOnEvents(); } static irqreturn_t vmbus_isr(int irq, void *dev_id) { - struct vmbus_driver *vmbus_driver_obj = &g_vmbus_drv.drv_obj; + struct hv_driver *driver = &g_vmbus_drv.drv_obj; int ret; - /* ASSERT(vmbus_driver_obj->OnIsr != NULL); */ - /* Call to bus driver to handle interrupt */ - ret = vmbus_driver_obj->OnIsr(&vmbus_driver_obj->Base); + ret = vmbus_on_isr(driver); /* Schedules a dpc if necessary */ if (ret > 0) { @@ -928,7 +1093,7 @@ static int __init vmbus_init(void) if (!dmi_check_system(microsoft_hv_dmi_table)) return -ENODEV; - return vmbus_bus_init(VmbusInitialize); + return vmbus_bus_init(); } static void __exit vmbus_exit(void) diff --git a/drivers/staging/hv/vmbus_private.h b/drivers/staging/hv/vmbus_private.h index 09eaec964b30..07f6d22eeabb 100644 --- a/drivers/staging/hv/vmbus_private.h +++ b/drivers/staging/hv/vmbus_private.h @@ -102,13 +102,14 @@ extern struct VMBUS_CONNECTION gVmbusConnection; /* General vmbus interface */ -struct hv_device *VmbusChildDeviceCreate(struct hv_guid *deviceType, +struct hv_device *vmbus_child_device_create(struct hv_guid *deviceType, struct hv_guid *deviceInstance, struct vmbus_channel *channel); int VmbusChildDeviceAdd(struct hv_device *Device); - -void VmbusChildDeviceRemove(struct hv_device *Device); +int vmbus_child_device_register(struct hv_device *root_device_obj, + struct hv_device *child_device_obj); +void vmbus_child_device_unregister(struct hv_device *device_obj); /* static void */ /* VmbusChildDeviceDestroy( */ diff --git a/drivers/staging/hv/vstorage.h b/drivers/staging/hv/vstorage.h index 4ea597d7a7d7..ae8be84394d5 100644 --- a/drivers/staging/hv/vstorage.h +++ b/drivers/staging/hv/vstorage.h @@ -27,15 +27,17 @@ #define REVISION_STRING(REVISION_) #REVISION_ #define FILL_VMSTOR_REVISION(RESULT_LVALUE_) \ -{ \ - char *revisionString = REVISION_STRING($Revision : 6 $) + 11; \ - RESULT_LVALUE_ = 0; \ - while (*revisionString >= '0' && *revisionString <= '9') { \ - RESULT_LVALUE_ *= 10; \ - RESULT_LVALUE_ += *revisionString - '0'; \ - revisionString++; \ - } \ -} + do { \ + char *revision_string \ + = REVISION_STRING($Rev : 6 $) + 6; \ + RESULT_LVALUE_ = 0; \ + while (*revision_string >= '0' \ + && *revision_string <= '9') { \ + RESULT_LVALUE_ *= 10; \ + RESULT_LVALUE_ += *revision_string - '0'; \ + revision_string++; \ + } \ + } while (0) /* Major/minor macros. Minor version is in LSB, meaning that earlier flat */ /* version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1). */ @@ -65,17 +67,17 @@ /* Packet structure describing virtual storage requests. */ enum vstor_packet_operation { - VStorOperationCompleteIo = 1, - VStorOperationRemoveDevice = 2, - VStorOperationExecuteSRB = 3, - VStorOperationResetLun = 4, - VStorOperationResetAdapter = 5, - VStorOperationResetBus = 6, - VStorOperationBeginInitialization = 7, - VStorOperationEndInitialization = 8, - VStorOperationQueryProtocolVersion = 9, - VStorOperationQueryProperties = 10, - VStorOperationMaximum = 10 + VSTOR_OPERATION_COMPLETE_IO = 1, + VSTOR_OPERATION_REMOVE_DEVICE = 2, + VSTOR_OPERATION_EXECUTE_SRB = 3, + VSTOR_OPERATION_RESET_LUN = 4, + VSTOR_OPERATION_RESET_ADAPTER = 5, + VSTOR_OPERATION_RESET_BUS = 6, + VSTOR_OPERATION_BEGIN_INITIALIZATION = 7, + VSTOR_OPERATION_END_INITIALIZATION = 8, + VSTOR_OPERATION_QUERY_PROTOCOL_VERSION = 9, + VSTOR_OPERATION_QUERY_PROPERTIES = 10, + VSTOR_OPERATION_MAXIMUM = 10 }; /* @@ -89,31 +91,29 @@ enum vstor_packet_operation { #define SENSE_BUFFER_SIZE 0x12 #endif -#define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14 +#define MAX_DATA_BUF_LEN_WITH_PADDING 0x14 struct vmscsi_request { - unsigned short Length; - unsigned char SrbStatus; - unsigned char ScsiStatus; + unsigned short length; + unsigned char srb_status; + unsigned char scsi_status; - unsigned char PortNumber; - unsigned char PathId; - unsigned char TargetId; - unsigned char Lun; + unsigned char port_number; + unsigned char path_id; + unsigned char target_id; + unsigned char lun; - unsigned char CdbLength; - unsigned char SenseInfoLength; - unsigned char DataIn; - unsigned char Reserved; + unsigned char cdb_length; + unsigned char sense_info_length; + unsigned char data_in; + unsigned char reserved; - unsigned int DataTransferLength; + unsigned int data_transfer_length; union { - unsigned char Cdb[CDB16GENERIC_LENGTH]; - - unsigned char SenseData[SENSE_BUFFER_SIZE]; - - unsigned char ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING]; + unsigned char cdb[CDB16GENERIC_LENGTH]; + unsigned char sense_data[SENSE_BUFFER_SIZE]; + unsigned char reserved_array[MAX_DATA_BUF_LEN_WITH_PADDING]; }; } __attribute((packed)); @@ -123,24 +123,24 @@ struct vmscsi_request { * properties of the channel. */ struct vmstorage_channel_properties { - unsigned short ProtocolVersion; - unsigned char PathId; - unsigned char TargetId; + unsigned short protocol_version; + unsigned char path_id; + unsigned char target_id; /* Note: port number is only really known on the client side */ - unsigned int PortNumber; - unsigned int Flags; - unsigned int MaxTransferBytes; + unsigned int port_number; + unsigned int flags; + unsigned int max_transfer_bytes; /* This id is unique for each channel and will correspond with */ /* vendor specific data in the inquirydata */ - unsigned long long UniqueId; + unsigned long long unique_id; } __attribute__((packed)); /* This structure is sent during the storage protocol negotiations. */ struct vmstorage_protocol_version { /* Major (MSW) and minor (LSW) version numbers. */ - unsigned short MajorMinor; + unsigned short major_minor; /* * Revision number is auto-incremented whenever this file is changed @@ -148,7 +148,7 @@ struct vmstorage_protocol_version { * definitely indicate incompatibility--but it does indicate mismatched * builds. */ - unsigned short Revision; + unsigned short revision; } __attribute__((packed)); /* Channel Property Flags */ @@ -157,13 +157,13 @@ struct vmstorage_protocol_version { struct vstor_packet { /* Requested operation type */ - enum vstor_packet_operation Operation; + enum vstor_packet_operation operation; /* Flags - see below for values */ - unsigned int Flags; + unsigned int flags; /* Status of the request returned from the server side. */ - unsigned int Status; + unsigned int status; /* Data payload area */ union { @@ -171,13 +171,13 @@ struct vstor_packet { * Structure used to forward SCSI commands from the * client to the server. */ - struct vmscsi_request VmSrb; + struct vmscsi_request vm_srb; /* Structure used to query channel properties. */ - struct vmstorage_channel_properties StorageChannelProperties; + struct vmstorage_channel_properties storage_channel_properties; /* Used during version negotiations. */ - struct vmstorage_protocol_version Version; + struct vmstorage_protocol_version version; }; } __attribute__((packed)); |