diff options
Diffstat (limited to 'drivers/staging/hv')
-rw-r--r-- | drivers/staging/hv/Makefile | 10 | ||||
-rw-r--r-- | drivers/staging/hv/TODO | 2 | ||||
-rw-r--r-- | drivers/staging/hv/blkvsc.c | 2 | ||||
-rw-r--r-- | drivers/staging/hv/blkvsc_drv.c | 2 | ||||
-rw-r--r-- | drivers/staging/hv/channel.c | 841 | ||||
-rw-r--r-- | drivers/staging/hv/channel.h | 122 | ||||
-rw-r--r-- | drivers/staging/hv/channel_interface.c | 152 | ||||
-rw-r--r-- | drivers/staging/hv/channel_interface.h | 35 | ||||
-rw-r--r-- | drivers/staging/hv/channel_mgmt.c | 342 | ||||
-rw-r--r-- | drivers/staging/hv/channel_mgmt.h | 10 | ||||
-rw-r--r-- | drivers/staging/hv/connection.c | 4 | ||||
-rw-r--r-- | drivers/staging/hv/hv_utils.c | 15 | ||||
-rw-r--r-- | drivers/staging/hv/netvsc.c | 137 | ||||
-rw-r--r-- | drivers/staging/hv/netvsc_drv.c | 4 | ||||
-rw-r--r-- | drivers/staging/hv/storvsc.c | 93 | ||||
-rw-r--r-- | drivers/staging/hv/storvsc_drv.c | 9 | ||||
-rw-r--r-- | drivers/staging/hv/vmbus.c | 35 | ||||
-rw-r--r-- | drivers/staging/hv/vmbus.h | 2 | ||||
-rw-r--r-- | drivers/staging/hv/vmbus_api.h | 55 | ||||
-rw-r--r-- | drivers/staging/hv/vmbus_drv.c | 84 | ||||
-rw-r--r-- | drivers/staging/hv/vmbus_private.h | 3 |
21 files changed, 847 insertions, 1112 deletions
diff --git a/drivers/staging/hv/Makefile b/drivers/staging/hv/Makefile index b63515c20f5f..b46349bb43bf 100644 --- a/drivers/staging/hv/Makefile +++ b/drivers/staging/hv/Makefile @@ -4,9 +4,9 @@ obj-$(CONFIG_HYPERV_BLOCK) += hv_blkvsc.o obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o -hv_vmbus-objs := vmbus_drv.o osd.o \ +hv_vmbus-y := vmbus_drv.o osd.o \ vmbus.o hv.o connection.o channel.o \ - channel_mgmt.o channel_interface.o ring_buffer.o -hv_storvsc-objs := storvsc_drv.o storvsc.o -hv_blkvsc-objs := blkvsc_drv.o blkvsc.o -hv_netvsc-objs := netvsc_drv.o netvsc.o rndis_filter.o + channel_mgmt.o ring_buffer.o +hv_storvsc-y := storvsc_drv.o storvsc.o +hv_blkvsc-y := blkvsc_drv.o blkvsc.o +hv_netvsc-y := netvsc_drv.o netvsc.o rndis_filter.o diff --git a/drivers/staging/hv/TODO b/drivers/staging/hv/TODO index 66a89c809dd3..582fd4ab3f1e 100644 --- a/drivers/staging/hv/TODO +++ b/drivers/staging/hv/TODO @@ -2,8 +2,6 @@ TODO: - fix remaining checkpatch warnings and errors - audit the vmbus to verify it is working properly with the driver model - - convert vmbus driver interface function pointer tables - to constant, a.k.a vmbus_ops - see if the vmbus can be merged with the other virtual busses in the kernel - audit the network driver diff --git a/drivers/staging/hv/blkvsc.c b/drivers/staging/hv/blkvsc.c index 929238a6ce80..d5b0abd771ab 100644 --- a/drivers/staging/hv/blkvsc.c +++ b/drivers/staging/hv/blkvsc.c @@ -81,7 +81,7 @@ int BlkVscInitialize(struct hv_driver *Driver) * Divide the ring buffer data size (which is 1 page less than the ring * buffer size since that page is reserved for the ring buffer indices) * by the max request size (which is - * VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + struct vstor_packet + u64) + * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) */ storDriver->MaxOutstandingRequestsPerChannel = ((storDriver->RingBufferSize - PAGE_SIZE) / diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c index 8284297b30e9..3f81ca591064 100644 --- a/drivers/staging/hv/blkvsc_drv.c +++ b/drivers/staging/hv/blkvsc_drv.c @@ -177,8 +177,6 @@ static int blkvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx; int ret; - vmbus_get_interface(&storvsc_drv_obj->Base.VmbusChannelInterface); - storvsc_drv_obj->RingBufferSize = blkvsc_ringbuffer_size; /* Callback to client driver to complete the initialization */ diff --git a/drivers/staging/hv/channel.c b/drivers/staging/hv/channel.c index fece30c303a5..26ebc77f22b7 100644 --- a/drivers/staging/hv/channel.c +++ b/drivers/staging/hv/channel.c @@ -27,13 +27,13 @@ #include "vmbus_private.h" /* Internal routines */ -static int VmbusChannelCreateGpadlHeader( - void *Kbuffer, /* must be phys and virt contiguous */ - u32 Size, /* page-size multiple */ - struct vmbus_channel_msginfo **msgInfo, - u32 *MessageCount); -static void DumpVmbusChannel(struct vmbus_channel *channel); -static void VmbusChannelSetEvent(struct vmbus_channel *channel); +static int create_gpadl_header( + void *kbuffer, /* must be phys and virt contiguous */ + u32 size, /* page-size multiple */ + struct vmbus_channel_msginfo **msginfo, + u32 *messagecount); +static void dump_vmbus_channel(struct vmbus_channel *channel); +static void vmbus_setevent(struct vmbus_channel *channel); #if 0 @@ -67,28 +67,28 @@ static void DumpMonitorPage(struct hv_monitor_page *MonitorPage) #endif /* - * VmbusChannelSetEvent - Trigger an event notification on the specified + * vmbus_setevent- Trigger an event notification on the specified * channel. */ -static void VmbusChannelSetEvent(struct vmbus_channel *Channel) +static void vmbus_setevent(struct vmbus_channel *channel) { - struct hv_monitor_page *monitorPage; + struct hv_monitor_page *monitorpage; - if (Channel->OfferMsg.MonitorAllocated) { + if (channel->OfferMsg.MonitorAllocated) { /* Each u32 represents 32 channels */ - set_bit(Channel->OfferMsg.ChildRelId & 31, + set_bit(channel->OfferMsg.ChildRelId & 31, (unsigned long *) gVmbusConnection.SendInterruptPage + - (Channel->OfferMsg.ChildRelId >> 5)); + (channel->OfferMsg.ChildRelId >> 5)); - monitorPage = gVmbusConnection.MonitorPages; - monitorPage++; /* Get the child to parent monitor page */ + 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->MonitorBit, + (unsigned long *)&monitorpage->TriggerGroup + [channel->MonitorGroup].Pending); } else { - VmbusSetEvent(Channel->OfferMsg.ChildRelId); + VmbusSetEvent(channel->OfferMsg.ChildRelId); } } @@ -115,56 +115,56 @@ static void VmbusChannelClearEvent(struct vmbus_channel *channel) #endif /* - * VmbusChannelGetDebugInfo -Retrieve various channel debug info + * vmbus_get_debug_info -Retrieve various channel debug info */ -void VmbusChannelGetDebugInfo(struct vmbus_channel *Channel, - struct vmbus_channel_debug_info *DebugInfo) +void vmbus_get_debug_info(struct vmbus_channel *channel, + struct vmbus_channel_debug_info *debuginfo) { - struct hv_monitor_page *monitorPage; - u8 monitorGroup = (u8)Channel->OfferMsg.MonitorId / 32; - u8 monitorOffset = (u8)Channel->OfferMsg.MonitorId % 32; + struct hv_monitor_page *monitorpage; + 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.ChildRelId; + debuginfo->State = channel->State; + memcpy(&debuginfo->InterfaceType, + &channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid)); + memcpy(&debuginfo->InterfaceInstance, + &channel->OfferMsg.Offer.InterfaceInstance, sizeof(struct hv_guid)); - monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages; + monitorpage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages; - DebugInfo->MonitorId = Channel->OfferMsg.MonitorId; + debuginfo->MonitorId = channel->OfferMsg.MonitorId; - DebugInfo->ServerMonitorPending = - monitorPage->TriggerGroup[monitorGroup].Pending; - DebugInfo->ServerMonitorLatency = - monitorPage->Latency[monitorGroup][monitorOffset]; - DebugInfo->ServerMonitorConnectionId = - monitorPage->Parameter[monitorGroup] - [monitorOffset].ConnectionId.u.Id; + 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; - monitorPage++; + monitorpage++; - DebugInfo->ClientMonitorPending = - monitorPage->TriggerGroup[monitorGroup].Pending; - DebugInfo->ClientMonitorLatency = - monitorPage->Latency[monitorGroup][monitorOffset]; - DebugInfo->ClientMonitorConnectionId = - monitorPage->Parameter[monitorGroup] - [monitorOffset].ConnectionId.u.Id; + 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; - RingBufferGetDebugInfo(&Channel->Inbound, &DebugInfo->Inbound); - RingBufferGetDebugInfo(&Channel->Outbound, &DebugInfo->Outbound); + RingBufferGetDebugInfo(&channel->Inbound, &debuginfo->Inbound); + RingBufferGetDebugInfo(&channel->Outbound, &debuginfo->Outbound); } /* - * VmbusChannelOpen - Open the specified channel. + * vmbus_open - Open the specified channel. */ -int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, - u32 RecvRingBufferSize, void *UserData, u32 UserDataLen, - void (*OnChannelCallback)(void *context), void *Context) +int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, + u32 recv_ringbuffer_size, void *userdata, u32 userdatalen, + void (*onchannelcallback)(void *context), void *context) { struct vmbus_channel_open_channel *openMsg; struct vmbus_channel_msginfo *openInfo = NULL; @@ -176,30 +176,30 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, /* ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1))); */ /* ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1))); */ - NewChannel->OnChannelCallback = OnChannelCallback; - NewChannel->ChannelCallbackContext = Context; + newchannel->OnChannelCallback = onchannelcallback; + newchannel->ChannelCallbackContext = context; /* Allocate the ring buffer */ - out = osd_PageAlloc((SendRingBufferSize + RecvRingBufferSize) + out = osd_PageAlloc((send_ringbuffer_size + recv_ringbuffer_size) >> PAGE_SHIFT); if (!out) return -ENOMEM; /* ASSERT(((unsigned long)out & (PAGE_SIZE-1)) == 0); */ - in = (void *)((unsigned long)out + SendRingBufferSize); + in = (void *)((unsigned long)out + send_ringbuffer_size); - NewChannel->RingBufferPages = out; - NewChannel->RingBufferPageCount = (SendRingBufferSize + - RecvRingBufferSize) >> PAGE_SHIFT; + newchannel->RingBufferPages = out; + newchannel->RingBufferPageCount = (send_ringbuffer_size + + recv_ringbuffer_size) >> PAGE_SHIFT; - ret = RingBufferInit(&NewChannel->Outbound, out, SendRingBufferSize); + ret = RingBufferInit(&newchannel->Outbound, out, send_ringbuffer_size); if (ret != 0) { err = ret; goto errorout; } - ret = RingBufferInit(&NewChannel->Inbound, in, RecvRingBufferSize); + ret = RingBufferInit(&newchannel->Inbound, in, recv_ringbuffer_size); if (ret != 0) { err = ret; goto errorout; @@ -208,15 +208,15 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, /* Establish the gpadl for the ring buffer */ DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", - NewChannel); + newchannel); - NewChannel->RingBufferGpadlHandle = 0; + newchannel->RingBufferGpadlHandle = 0; - ret = VmbusChannelEstablishGpadl(NewChannel, - NewChannel->Outbound.RingBuffer, - SendRingBufferSize + - RecvRingBufferSize, - &NewChannel->RingBufferGpadlHandle); + ret = vmbus_establish_gpadl(newchannel, + newchannel->Outbound.RingBuffer, + send_ringbuffer_size + + recv_ringbuffer_size, + &newchannel->RingBufferGpadlHandle); if (ret != 0) { err = ret; @@ -225,13 +225,13 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, 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, - SendRingBufferSize); + newchannel, newchannel->OfferMsg.ChildRelId, + newchannel->RingBufferGpadlHandle, + newchannel->Outbound.RingBuffer, + newchannel->Outbound.RingSize, + newchannel->Inbound.RingBuffer, + newchannel->Inbound.RingSize, + send_ringbuffer_size); /* Create and init the channel open message */ openInfo = kmalloc(sizeof(*openInfo) + @@ -250,20 +250,20 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, 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 = SendRingBufferSize >> + openMsg->OpenId = newchannel->OfferMsg.ChildRelId; /* FIXME */ + openMsg->ChildRelId = newchannel->OfferMsg.ChildRelId; + openMsg->RingBufferGpadlHandle = newchannel->RingBufferGpadlHandle; + openMsg->DownstreamRingBufferPageOffset = send_ringbuffer_size >> PAGE_SHIFT; openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */ - if (UserDataLen > MAX_USER_DEFINED_BYTES) { + if (userdatalen > MAX_USER_DEFINED_BYTES) { err = -EINVAL; goto errorout; } - if (UserDataLen) - memcpy(openMsg->UserData, UserData, UserDataLen); + if (userdatalen) + memcpy(openMsg->UserData, userdata, userdatalen); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); list_add_tail(&openInfo->MsgListEntry, @@ -283,10 +283,10 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, osd_WaitEventWait(openInfo->WaitEvent); if (openInfo->Response.OpenResult.Status == 0) - DPRINT_INFO(VMBUS, "channel <%p> open success!!", NewChannel); + 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.OpenResult.Status); Cleanup: spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); @@ -298,301 +298,306 @@ Cleanup: return 0; errorout: - RingBufferCleanup(&NewChannel->Outbound); - RingBufferCleanup(&NewChannel->Inbound); - osd_PageFree(out, (SendRingBufferSize + RecvRingBufferSize) + RingBufferCleanup(&newchannel->Outbound); + RingBufferCleanup(&newchannel->Inbound); + osd_PageFree(out, (send_ringbuffer_size + recv_ringbuffer_size) >> PAGE_SHIFT); kfree(openInfo); return err; } +EXPORT_SYMBOL_GPL(vmbus_open); /* - * DumpGpadlBody - Dump the gpadl body message to the console for + * dump_gpadl_body - Dump the gpadl body message to the console for * debugging purposes. */ -static void DumpGpadlBody(struct vmbus_channel_gpadl_body *Gpadl, u32 Len) +static void dump_gpadl_body(struct vmbus_channel_gpadl_body *gpadl, u32 len) { int i; - int pfnCount; + int pfncount; - pfnCount = (Len - sizeof(struct vmbus_channel_gpadl_body)) / + pfncount = (len - sizeof(struct vmbus_channel_gpadl_body)) / sizeof(u64); - DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", Len, pfnCount); + DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", len, pfncount); - for (i = 0; i < pfnCount; i++) + for (i = 0; i < pfncount; i++) DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu", - i, Gpadl->Pfn[i]); + i, gpadl->Pfn[i]); } /* - * DumpGpadlHeader - Dump the gpadl header message to the console for + * dump_gpadl_header - Dump the gpadl header message to the console for * debugging purposes. */ -static void DumpGpadlHeader(struct vmbus_channel_gpadl_header *Gpadl) +static void dump_gpadl_header(struct vmbus_channel_gpadl_header *gpadl) { int i, j; - int pageCount; + int pagecount; 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; - pageCount = (pageCount > 26) ? 26 : pageCount; + gpadl->ChildRelId, gpadl->RangeCount, gpadl->RangeBufLen); + 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++) + for (j = 0; j < pagecount; j++) DPRINT_DBG(VMBUS, "%d) pfn %llu", j, - Gpadl->Range[i].PfnArray[j]); + gpadl->Range[i].PfnArray[j]); } } /* - * VmbusChannelCreateGpadlHeader - Creates a gpadl for the specified buffer + * create_gpadl_header - Creates a gpadl for the specified buffer */ -static int VmbusChannelCreateGpadlHeader(void *Kbuffer, u32 Size, - struct vmbus_channel_msginfo **MsgInfo, - u32 *MessageCount) +static int create_gpadl_header(void *kbuffer, u32 size, + struct vmbus_channel_msginfo **msginfo, + u32 *messagecount) { int i; - int pageCount; + int pagecount; unsigned long long pfn; - struct vmbus_channel_gpadl_header *gpaHeader; - struct vmbus_channel_gpadl_body *gpadlBody; - struct vmbus_channel_msginfo *msgHeader; - struct vmbus_channel_msginfo *msgBody = NULL; - u32 msgSize; + struct vmbus_channel_gpadl_header *gpadl_header; + struct vmbus_channel_gpadl_body *gpadl_body; + struct vmbus_channel_msginfo *msgheader; + struct vmbus_channel_msginfo *msgbody = NULL; + u32 msgsize; - int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize; + int pfnsum, pfncount, pfnleft, pfncurr, pfnsize; /* ASSERT((kbuffer & (PAGE_SIZE-1)) == 0); */ /* ASSERT((Size & (PAGE_SIZE-1)) == 0); */ - pageCount = Size >> PAGE_SHIFT; - pfn = virt_to_phys(Kbuffer) >> PAGE_SHIFT; + pagecount = size >> PAGE_SHIFT; + pfn = virt_to_phys(kbuffer) >> PAGE_SHIFT; /* do we need a gpadl body msg */ - pfnSize = MAX_SIZE_CHANNEL_MESSAGE - + pfnsize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(struct vmbus_channel_gpadl_header) - sizeof(struct gpa_range); - pfnCount = pfnSize / sizeof(u64); + pfncount = pfnsize / sizeof(u64); - if (pageCount > pfnCount) { + if (pagecount > pfncount) { /* we need a gpadl body */ /* fill in the header */ - msgSize = sizeof(struct vmbus_channel_msginfo) + + msgsize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_header) + - sizeof(struct gpa_range) + pfnCount * sizeof(u64); - msgHeader = kzalloc(msgSize, GFP_KERNEL); - if (!msgHeader) + sizeof(struct gpa_range) + pfncount * sizeof(u64); + msgheader = kzalloc(msgsize, GFP_KERNEL); + if (!msgheader) goto nomem; - INIT_LIST_HEAD(&msgHeader->SubMsgList); - msgHeader->MessageSize = msgSize; + INIT_LIST_HEAD(&msgheader->SubMsgList); + msgheader->MessageSize = msgsize; - gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg; - gpaHeader->RangeCount = 1; - gpaHeader->RangeBufLen = sizeof(struct gpa_range) + - pageCount * sizeof(u64); - gpaHeader->Range[0].ByteOffset = 0; - gpaHeader->Range[0].ByteCount = Size; - for (i = 0; i < pfnCount; i++) - gpaHeader->Range[0].PfnArray[i] = pfn+i; - *MsgInfo = msgHeader; - *MessageCount = 1; + gpadl_header = (struct vmbus_channel_gpadl_header *) + msgheader->Msg; + gpadl_header->RangeCount = 1; + gpadl_header->RangeBufLen = sizeof(struct gpa_range) + + pagecount * sizeof(u64); + 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; + *msginfo = msgheader; + *messagecount = 1; - pfnSum = pfnCount; - pfnLeft = pageCount - pfnCount; + pfnsum = pfncount; + pfnleft = pagecount - pfncount; /* how many pfns can we fit */ - pfnSize = MAX_SIZE_CHANNEL_MESSAGE - + pfnsize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(struct vmbus_channel_gpadl_body); - pfnCount = pfnSize / sizeof(u64); + pfncount = pfnsize / sizeof(u64); /* fill in the body */ - while (pfnLeft) { - if (pfnLeft > pfnCount) - pfnCurr = pfnCount; + while (pfnleft) { + if (pfnleft > pfncount) + pfncurr = pfncount; else - pfnCurr = pfnLeft; + pfncurr = pfnleft; - msgSize = sizeof(struct vmbus_channel_msginfo) + + msgsize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_body) + - pfnCurr * sizeof(u64); - msgBody = kzalloc(msgSize, GFP_KERNEL); + pfncurr * sizeof(u64); + msgbody = kzalloc(msgsize, GFP_KERNEL); /* FIXME: we probably need to more if this fails */ - if (!msgBody) + if (!msgbody) goto nomem; - msgBody->MessageSize = msgSize; - (*MessageCount)++; - gpadlBody = - (struct vmbus_channel_gpadl_body *)msgBody->Msg; + msgbody->MessageSize = msgsize; + (*messagecount)++; + gpadl_body = + (struct vmbus_channel_gpadl_body *)msgbody->Msg; /* * FIXME: * Gpadl is u32 and we are using a pointer which could * be 64-bit */ - /* gpadlBody->Gpadl = kbuffer; */ - for (i = 0; i < pfnCurr; i++) - gpadlBody->Pfn[i] = pfn + pfnSum + i; + /* gpadl_body->Gpadl = kbuffer; */ + for (i = 0; i < pfncurr; i++) + gpadl_body->Pfn[i] = pfn + pfnsum + i; /* add to msg header */ - list_add_tail(&msgBody->MsgListEntry, - &msgHeader->SubMsgList); - pfnSum += pfnCurr; - pfnLeft -= pfnCurr; + list_add_tail(&msgbody->MsgListEntry, + &msgheader->SubMsgList); + pfnsum += pfncurr; + pfnleft -= pfncurr; } } else { /* everything fits in a header */ - msgSize = sizeof(struct vmbus_channel_msginfo) + + msgsize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_header) + - sizeof(struct gpa_range) + pageCount * sizeof(u64); - msgHeader = kzalloc(msgSize, GFP_KERNEL); - if (msgHeader == NULL) + sizeof(struct gpa_range) + pagecount * sizeof(u64); + msgheader = kzalloc(msgsize, GFP_KERNEL); + if (msgheader == NULL) goto nomem; - msgHeader->MessageSize = msgSize; - - gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg; - gpaHeader->RangeCount = 1; - gpaHeader->RangeBufLen = sizeof(struct gpa_range) + - pageCount * sizeof(u64); - gpaHeader->Range[0].ByteOffset = 0; - gpaHeader->Range[0].ByteCount = Size; - for (i = 0; i < pageCount; i++) - gpaHeader->Range[0].PfnArray[i] = pfn+i; - - *MsgInfo = msgHeader; - *MessageCount = 1; + msgheader->MessageSize = msgsize; + + gpadl_header = (struct vmbus_channel_gpadl_header *) + msgheader->Msg; + gpadl_header->RangeCount = 1; + gpadl_header->RangeBufLen = sizeof(struct gpa_range) + + pagecount * sizeof(u64); + 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; + + *msginfo = msgheader; + *messagecount = 1; } return 0; nomem: - kfree(msgHeader); - kfree(msgBody); + kfree(msgheader); + kfree(msgbody); return -ENOMEM; } /* - * VmbusChannelEstablishGpadl - Estabish a GPADL for the specified buffer + * vmbus_establish_gpadl - Estabish a GPADL for the specified buffer * - * @Channel: a channel - * @Kbuffer: from kmalloc - * @Size: page-size multiple - * @GpadlHandle: some funky thing + * @channel: a channel + * @kbuffer: from kmalloc + * @size: page-size multiple + * @gpadl_handle: some funky thing */ -int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, void *Kbuffer, - u32 Size, u32 *GpadlHandle) +int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, + u32 size, u32 *gpadl_handle) { - struct vmbus_channel_gpadl_header *gpadlMsg; - struct vmbus_channel_gpadl_body *gpadlBody; + struct vmbus_channel_gpadl_header *gpadlmsg; + struct vmbus_channel_gpadl_body *gpadl_body; /* struct vmbus_channel_gpadl_created *gpadlCreated; */ - struct vmbus_channel_msginfo *msgInfo = NULL; - struct vmbus_channel_msginfo *subMsgInfo; - u32 msgCount; + struct vmbus_channel_msginfo *msginfo = NULL; + struct vmbus_channel_msginfo *submsginfo; + u32 msgcount; struct list_head *curr; - u32 nextGpadlHandle; + u32 next_gpadl_handle; unsigned long flags; int ret = 0; - nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle); + next_gpadl_handle = atomic_read(&gVmbusConnection.NextGpadlHandle); atomic_inc(&gVmbusConnection.NextGpadlHandle); - ret = VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount); + ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount); if (ret) return ret; - msgInfo->WaitEvent = osd_WaitEventCreate(); - if (!msgInfo->WaitEvent) { + msginfo->WaitEvent = osd_WaitEventCreate(); + 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 = nextGpadlHandle; + gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->Msg; + gpadlmsg->Header.MessageType = ChannelMessageGpadlHeader; + gpadlmsg->ChildRelId = channel->OfferMsg.ChildRelId; + gpadlmsg->Gpadl = next_gpadl_handle; - DumpGpadlHeader(gpadlMsg); + 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); DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", - Kbuffer, Size, msgCount); + kbuffer, size, msgcount); DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", - msgInfo->MessageSize - sizeof(*msgInfo)); + msginfo->MessageSize - sizeof(*msginfo)); - ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize - - sizeof(*msgInfo)); + ret = VmbusPostMessage(gpadlmsg, msginfo->MessageSize - + sizeof(*msginfo)); if (ret != 0) { DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret); goto Cleanup; } - if (msgCount > 1) { - list_for_each(curr, &msgInfo->SubMsgList) { + if (msgcount > 1) { + list_for_each(curr, &msginfo->SubMsgList) { /* FIXME: should this use list_entry() instead ? */ - subMsgInfo = (struct vmbus_channel_msginfo *)curr; - gpadlBody = - (struct vmbus_channel_gpadl_body *)subMsgInfo->Msg; + submsginfo = (struct vmbus_channel_msginfo *)curr; + gpadl_body = + (struct vmbus_channel_gpadl_body *)submsginfo->Msg; - gpadlBody->Header.MessageType = ChannelMessageGpadlBody; - gpadlBody->Gpadl = nextGpadlHandle; + gpadl_body->Header.MessageType = + ChannelMessageGpadlBody; + gpadl_body->Gpadl = next_gpadl_handle; DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", - subMsgInfo->MessageSize - - sizeof(*subMsgInfo)); - - DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize - - sizeof(*subMsgInfo)); - ret = VmbusPostMessage(gpadlBody, - subMsgInfo->MessageSize - - sizeof(*subMsgInfo)); + submsginfo->MessageSize - + sizeof(*submsginfo)); + + dump_gpadl_body(gpadl_body, submsginfo->MessageSize - + sizeof(*submsginfo)); + ret = VmbusPostMessage(gpadl_body, + submsginfo->MessageSize - + sizeof(*submsginfo)); if (ret != 0) goto Cleanup; } } - osd_WaitEventWait(msgInfo->WaitEvent); + osd_WaitEventWait(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.ChildRelId, + msginfo->Response.GpadlCreated.CreationStatus, + gpadlmsg->Gpadl); - *GpadlHandle = 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); + kfree(msginfo->WaitEvent); + kfree(msginfo); return ret; } +EXPORT_SYMBOL_GPL(vmbus_establish_gpadl); /* - * VmbusChannelTeardownGpadl -Teardown the specified GPADL handle + * vmbus_teardown_gpadl -Teardown the specified GPADL handle */ -int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle) +int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) { struct vmbus_channel_gpadl_teardown *msg; struct vmbus_channel_msginfo *info; unsigned long flags; int ret; - /* ASSERT(GpadlHandle != 0); */ + /* ASSERT(gpadl_handle != 0); */ info = kmalloc(sizeof(*info) + sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL); @@ -608,8 +613,8 @@ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle) msg = (struct vmbus_channel_gpadl_teardown *)info->Msg; msg->Header.MessageType = ChannelMessageGpadlTeardown; - msg->ChildRelId = Channel->OfferMsg.ChildRelId; - msg->Gpadl = GpadlHandle; + msg->ChildRelId = channel->OfferMsg.ChildRelId; + msg->Gpadl = gpadl_handle; spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); list_add_tail(&info->MsgListEntry, @@ -634,11 +639,12 @@ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle) kfree(info); return ret; } +EXPORT_SYMBOL_GPL(vmbus_teardown_gpadl); /* - * VmbusChannelClose - Close the specified channel + * vmbus_close - Close the specified channel */ -void VmbusChannelClose(struct vmbus_channel *Channel) +void vmbus_close(struct vmbus_channel *channel) { struct vmbus_channel_close_channel *msg; struct vmbus_channel_msginfo *info; @@ -646,8 +652,8 @@ void VmbusChannelClose(struct vmbus_channel *Channel) int ret; /* Stop callback and cancel the timer asap */ - Channel->OnChannelCallback = NULL; - del_timer_sync(&Channel->poll_timer); + channel->OnChannelCallback = NULL; + del_timer_sync(&channel->poll_timer); /* Send a closing message */ info = kmalloc(sizeof(*info) + @@ -661,7 +667,7 @@ void VmbusChannelClose(struct vmbus_channel *Channel) msg = (struct vmbus_channel_close_channel *)info->Msg; msg->Header.MessageType = ChannelMessageCloseChannel; - msg->ChildRelId = Channel->OfferMsg.ChildRelId; + msg->ChildRelId = channel->OfferMsg.ChildRelId; ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_close_channel)); if (ret != 0) { @@ -670,17 +676,17 @@ void VmbusChannelClose(struct vmbus_channel *Channel) } /* Tear down the gpadl for the channel's ring buffer */ - if (Channel->RingBufferGpadlHandle) - VmbusChannelTeardownGpadl(Channel, - Channel->RingBufferGpadlHandle); + if (channel->RingBufferGpadlHandle) + vmbus_teardown_gpadl(channel, + channel->RingBufferGpadlHandle); /* TODO: Send a msg to release the childRelId */ /* Cleanup the ring buffers for this channel */ - RingBufferCleanup(&Channel->Outbound); - RingBufferCleanup(&Channel->Inbound); + RingBufferCleanup(&channel->Outbound); + RingBufferCleanup(&channel->Inbound); - osd_PageFree(Channel->RingBufferPages, Channel->RingBufferPageCount); + osd_PageFree(channel->RingBufferPages, channel->RingBufferPageCount); kfree(info); @@ -690,231 +696,237 @@ void VmbusChannelClose(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); - FreeVmbusChannel(Channel); + free_channel(channel); } } +EXPORT_SYMBOL_GPL(vmbus_close); /** - * VmbusChannelSendPacket() - Send the specified buffer on the given channel - * @Channel: Pointer to vmbus_channel structure. - * @Buffer: Pointer to the buffer you want to receive the data into. - * @BufferLen: Maximum size of what the the buffer will hold - * @RequestId: Identifier of the request - * @vmbus_packet_type: Type of packet that is being send e.g. negotiate, time + * vmbus_sendpacket() - Send the specified buffer on the given channel + * @channel: Pointer to vmbus_channel structure. + * @buffer: Pointer to the buffer you want to receive the data into. + * @bufferlen: Maximum size of what the the buffer will hold + * @requestid: Identifier of the request + * @type: Type of packet that is being send e.g. negotiate, time * packet etc. * - * Sends data in @Buffer directly to hyper-v via the vmbus + * Sends data in @buffer directly to hyper-v via the vmbus * This will send the data unparsed to hyper-v. * * Mainly used by Hyper-V drivers. */ -int VmbusChannelSendPacket(struct vmbus_channel *Channel, const void *Buffer, - u32 BufferLen, u64 RequestId, - enum vmbus_packet_type Type, u32 Flags) +int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer, + u32 bufferlen, u64 requestid, + enum vmbus_packet_type type, u32 flags) { struct vmpacket_descriptor desc; - u32 packetLen = sizeof(struct vmpacket_descriptor) + BufferLen; - u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); - struct scatterlist bufferList[3]; - u64 alignedData = 0; + u32 packetlen = sizeof(struct vmpacket_descriptor) + bufferlen; + u32 packetlen_aligned = ALIGN_UP(packetlen, sizeof(u64)); + struct scatterlist bufferlist[3]; + u64 aligned_data = 0; int ret; DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", - Channel, Buffer, BufferLen); + channel, buffer, bufferlen); - DumpVmbusChannel(Channel); + dump_vmbus_channel(channel); /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ /* Setup the descriptor */ - desc.Type = Type; /* VmbusPacketTypeDataInBand; */ - desc.Flags = Flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ + desc.Type = type; /* VmbusPacketTypeDataInBand; */ + desc.Flags = flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ /* in 8-bytes granularity */ desc.DataOffset8 = sizeof(struct vmpacket_descriptor) >> 3; - desc.Length8 = (u16)(packetLenAligned >> 3); - desc.TransactionId = RequestId; + desc.Length8 = (u16)(packetlen_aligned >> 3); + desc.TransactionId = requestid; - sg_init_table(bufferList, 3); - sg_set_buf(&bufferList[0], &desc, sizeof(struct vmpacket_descriptor)); - sg_set_buf(&bufferList[1], Buffer, BufferLen); - sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen); + sg_init_table(bufferlist, 3); + sg_set_buf(&bufferlist[0], &desc, sizeof(struct vmpacket_descriptor)); + sg_set_buf(&bufferlist[1], buffer, bufferlen); + sg_set_buf(&bufferlist[2], &aligned_data, + packetlen_aligned - packetlen); - ret = RingBufferWrite(&Channel->Outbound, bufferList, 3); + ret = RingBufferWrite(&channel->Outbound, bufferlist, 3); /* TODO: We should determine if this is optional */ - if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) - VmbusChannelSetEvent(Channel); + if (ret == 0 && !GetRingBufferInterruptMask(&channel->Outbound)) + vmbus_setevent(channel); return ret; } -EXPORT_SYMBOL(VmbusChannelSendPacket); +EXPORT_SYMBOL(vmbus_sendpacket); /* - * VmbusChannelSendPacketPageBuffer - Send a range of single-page buffer + * vmbus_sendpacket_pagebuffer - Send a range of single-page buffer * packets using a GPADL Direct packet type. */ -int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel, - struct hv_page_buffer PageBuffers[], - u32 PageCount, void *Buffer, u32 BufferLen, - u64 RequestId) +int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, + struct hv_page_buffer pagebuffers[], + u32 pagecount, void *buffer, u32 bufferlen, + u64 requestid) { int ret; int i; - struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc; - u32 descSize; - u32 packetLen; - u32 packetLenAligned; - struct scatterlist bufferList[3]; - u64 alignedData = 0; - - if (PageCount > MAX_PAGE_BUFFER_COUNT) + struct vmbus_channel_packet_page_buffer desc; + u32 descsize; + u32 packetlen; + u32 packetlen_aligned; + struct scatterlist bufferlist[3]; + u64 aligned_data = 0; + + if (pagecount > MAX_PAGE_BUFFER_COUNT) return -EINVAL; - DumpVmbusChannel(Channel); + dump_vmbus_channel(channel); /* - * Adjust the size down since VMBUS_CHANNEL_PACKET_PAGE_BUFFER is the + * Adjust the size down since vmbus_channel_packet_page_buffer is the * largest size we support */ - descSize = sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER) - - ((MAX_PAGE_BUFFER_COUNT - PageCount) * + descsize = sizeof(struct vmbus_channel_packet_page_buffer) - + ((MAX_PAGE_BUFFER_COUNT - pagecount) * sizeof(struct hv_page_buffer)); - packetLen = descSize + BufferLen; - packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); + packetlen = descsize + bufferlen; + packetlen_aligned = ALIGN_UP(packetlen, sizeof(u64)); /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ /* Setup the descriptor */ - desc.Type = VmbusPacketTypeDataUsingGpaDirect; - desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; - desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */ - desc.Length8 = (u16)(packetLenAligned >> 3); - desc.TransactionId = RequestId; - desc.RangeCount = PageCount; - - for (i = 0; i < PageCount; i++) { - desc.Range[i].Length = PageBuffers[i].Length; - desc.Range[i].Offset = PageBuffers[i].Offset; - desc.Range[i].Pfn = PageBuffers[i].Pfn; + desc.type = VmbusPacketTypeDataUsingGpaDirect; + desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; + desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ + desc.length8 = (u16)(packetlen_aligned >> 3); + desc.transactionid = requestid; + desc.rangecount = pagecount; + + for (i = 0; i < pagecount; i++) { + desc.range[i].Length = pagebuffers[i].Length; + desc.range[i].Offset = pagebuffers[i].Offset; + desc.range[i].Pfn = pagebuffers[i].Pfn; } - sg_init_table(bufferList, 3); - sg_set_buf(&bufferList[0], &desc, descSize); - sg_set_buf(&bufferList[1], Buffer, BufferLen); - sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen); + sg_init_table(bufferlist, 3); + sg_set_buf(&bufferlist[0], &desc, descsize); + sg_set_buf(&bufferlist[1], buffer, bufferlen); + sg_set_buf(&bufferlist[2], &aligned_data, + packetlen_aligned - packetlen); - ret = RingBufferWrite(&Channel->Outbound, bufferList, 3); + ret = RingBufferWrite(&channel->Outbound, bufferlist, 3); /* TODO: We should determine if this is optional */ - if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) - VmbusChannelSetEvent(Channel); + if (ret == 0 && !GetRingBufferInterruptMask(&channel->Outbound)) + vmbus_setevent(channel); return ret; } +EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer); /* - * VmbusChannelSendPacketMultiPageBuffer - Send a multi-page buffer packet + * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet * using a GPADL Direct packet type. */ -int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *Channel, - struct hv_multipage_buffer *MultiPageBuffer, - void *Buffer, u32 BufferLen, u64 RequestId) +int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, + struct hv_multipage_buffer *multi_pagebuffer, + void *buffer, u32 bufferlen, u64 requestid) { int ret; - struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc; - u32 descSize; - u32 packetLen; - u32 packetLenAligned; - struct scatterlist bufferList[3]; - u64 alignedData = 0; - u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, - MultiPageBuffer->Length); + struct vmbus_channel_packet_multipage_buffer desc; + u32 descsize; + u32 packetlen; + u32 packetlen_aligned; + struct scatterlist bufferlist[3]; + u64 aligned_data = 0; + u32 pfncount = NUM_PAGES_SPANNED(multi_pagebuffer->Offset, + multi_pagebuffer->Length); - DumpVmbusChannel(Channel); + dump_vmbus_channel(channel); DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", - MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount); + multi_pagebuffer->Offset, + multi_pagebuffer->Length, pfncount); - if ((PfnCount < 0) || (PfnCount > MAX_MULTIPAGE_BUFFER_COUNT)) + if ((pfncount < 0) || (pfncount > MAX_MULTIPAGE_BUFFER_COUNT)) return -EINVAL; /* - * Adjust the size down since VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER is + * Adjust the size down since vmbus_channel_packet_multipage_buffer is * the largest size we support */ - descSize = sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - - ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount) * + descsize = sizeof(struct vmbus_channel_packet_multipage_buffer) - + ((MAX_MULTIPAGE_BUFFER_COUNT - pfncount) * sizeof(u64)); - packetLen = descSize + BufferLen; - packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); + packetlen = descsize + bufferlen; + packetlen_aligned = ALIGN_UP(packetlen, sizeof(u64)); /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ /* Setup the descriptor */ - desc.Type = VmbusPacketTypeDataUsingGpaDirect; - desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; - desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */ - desc.Length8 = (u16)(packetLenAligned >> 3); - desc.TransactionId = RequestId; - desc.RangeCount = 1; + desc.type = VmbusPacketTypeDataUsingGpaDirect; + desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; + desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ + desc.length8 = (u16)(packetlen_aligned >> 3); + desc.transactionid = requestid; + desc.rangecount = 1; - desc.Range.Length = MultiPageBuffer->Length; - desc.Range.Offset = MultiPageBuffer->Offset; + desc.range.Length = multi_pagebuffer->Length; + desc.range.Offset = multi_pagebuffer->Offset; - memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, - PfnCount * sizeof(u64)); + memcpy(desc.range.PfnArray, multi_pagebuffer->PfnArray, + pfncount * sizeof(u64)); - sg_init_table(bufferList, 3); - sg_set_buf(&bufferList[0], &desc, descSize); - sg_set_buf(&bufferList[1], Buffer, BufferLen); - sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen); + sg_init_table(bufferlist, 3); + sg_set_buf(&bufferlist[0], &desc, descsize); + sg_set_buf(&bufferlist[1], buffer, bufferlen); + sg_set_buf(&bufferlist[2], &aligned_data, + packetlen_aligned - packetlen); - ret = RingBufferWrite(&Channel->Outbound, bufferList, 3); + ret = RingBufferWrite(&channel->Outbound, bufferlist, 3); /* TODO: We should determine if this is optional */ - if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) - VmbusChannelSetEvent(Channel); + if (ret == 0 && !GetRingBufferInterruptMask(&channel->Outbound)) + vmbus_setevent(channel); return ret; } - +EXPORT_SYMBOL_GPL(vmbus_sendpacket_multipagebuffer); /** - * VmbusChannelRecvPacket() - Retrieve the user packet on the specified channel - * @Channel: Pointer to vmbus_channel structure. - * @Buffer: Pointer to the buffer you want to receive the data into. - * @BufferLen: Maximum size of what the the buffer will hold - * @BufferActualLen: The actual size of the data after it was received - * @RequestId: Identifier of the request + * vmbus_recvpacket() - Retrieve the user packet on the specified channel + * @channel: Pointer to vmbus_channel structure. + * @buffer: Pointer to the buffer you want to receive the data into. + * @bufferlen: Maximum size of what the the buffer will hold + * @buffer_actual_len: The actual size of the data after it was received + * @requestid: Identifier of the request * * Receives directly from the hyper-v vmbus and puts the data it received * into Buffer. This will receive the data unparsed from hyper-v. * * Mainly used by Hyper-V drivers. */ -int VmbusChannelRecvPacket(struct vmbus_channel *Channel, void *Buffer, - u32 BufferLen, u32 *BufferActualLen, u64 *RequestId) +int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, + u32 bufferlen, u32 *buffer_actual_len, u64 *requestid) { struct vmpacket_descriptor desc; - u32 packetLen; - u32 userLen; + u32 packetlen; + u32 userlen; int ret; unsigned long flags; - *BufferActualLen = 0; - *RequestId = 0; + *buffer_actual_len = 0; + *requestid = 0; - spin_lock_irqsave(&Channel->inbound_lock, flags); + spin_lock_irqsave(&channel->inbound_lock, flags); - ret = RingBufferPeek(&Channel->Inbound, &desc, + ret = RingBufferPeek(&channel->Inbound, &desc, sizeof(struct vmpacket_descriptor)); if (ret != 0) { - spin_unlock_irqrestore(&Channel->inbound_lock, flags); + spin_unlock_irqrestore(&channel->inbound_lock, flags); /* DPRINT_DBG(VMBUS, "nothing to read!!"); */ return 0; @@ -922,59 +934,59 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel, void *Buffer, /* VmbusChannelClearEvent(Channel); */ - packetLen = desc.Length8 << 3; - userLen = packetLen - (desc.DataOffset8 << 3); + packetlen = desc.Length8 << 3; + userlen = packetlen - (desc.DataOffset8 << 3); /* ASSERT(userLen > 0); */ DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d " "flag %d tid %llx pktlen %d datalen %d> ", - Channel, Channel->OfferMsg.ChildRelId, desc.Type, - desc.Flags, desc.TransactionId, packetLen, userLen); + channel, channel->OfferMsg.ChildRelId, desc.Type, + desc.Flags, desc.TransactionId, packetlen, userlen); - *BufferActualLen = userLen; + *buffer_actual_len = userlen; - if (userLen > BufferLen) { - spin_unlock_irqrestore(&Channel->inbound_lock, flags); + if (userlen > bufferlen) { + spin_unlock_irqrestore(&channel->inbound_lock, flags); DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", - BufferLen, userLen); + bufferlen, userlen); return -1; } - *RequestId = desc.TransactionId; + *requestid = desc.TransactionId; /* Copy over the packet to the user buffer */ - ret = RingBufferRead(&Channel->Inbound, Buffer, userLen, + ret = RingBufferRead(&channel->Inbound, buffer, userlen, (desc.DataOffset8 << 3)); - spin_unlock_irqrestore(&Channel->inbound_lock, flags); + spin_unlock_irqrestore(&channel->inbound_lock, flags); return 0; } -EXPORT_SYMBOL(VmbusChannelRecvPacket); +EXPORT_SYMBOL(vmbus_recvpacket); /* - * VmbusChannelRecvPacketRaw - Retrieve the raw packet on the specified channel + * vmbus_recvpacket_raw - Retrieve the raw packet on the specified channel */ -int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, void *Buffer, - u32 BufferLen, u32 *BufferActualLen, - u64 *RequestId) +int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, + u32 bufferlen, u32 *buffer_actual_len, + u64 *requestid) { struct vmpacket_descriptor desc; - u32 packetLen; - u32 userLen; + u32 packetlen; + u32 userlen; int ret; unsigned long flags; - *BufferActualLen = 0; - *RequestId = 0; + *buffer_actual_len = 0; + *requestid = 0; - spin_lock_irqsave(&Channel->inbound_lock, flags); + spin_lock_irqsave(&channel->inbound_lock, flags); - ret = RingBufferPeek(&Channel->Inbound, &desc, + ret = RingBufferPeek(&channel->Inbound, &desc, sizeof(struct vmpacket_descriptor)); if (ret != 0) { - spin_unlock_irqrestore(&Channel->inbound_lock, flags); + spin_unlock_irqrestore(&channel->inbound_lock, flags); /* DPRINT_DBG(VMBUS, "nothing to read!!"); */ return 0; @@ -982,50 +994,51 @@ int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, void *Buffer, /* VmbusChannelClearEvent(Channel); */ - packetLen = desc.Length8 << 3; - userLen = packetLen - (desc.DataOffset8 << 3); + packetlen = desc.Length8 << 3; + userlen = packetlen - (desc.DataOffset8 << 3); 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, - desc.Flags, desc.TransactionId, packetLen, userLen); + channel, channel->OfferMsg.ChildRelId, desc.Type, + desc.Flags, desc.TransactionId, packetlen, userlen); - *BufferActualLen = packetLen; + *buffer_actual_len = packetlen; - if (packetLen > BufferLen) { - spin_unlock_irqrestore(&Channel->inbound_lock, flags); + if (packetlen > bufferlen) { + spin_unlock_irqrestore(&channel->inbound_lock, flags); DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but " - "got space for only %d bytes", packetLen, BufferLen); + "got space for only %d bytes", packetlen, bufferlen); return -2; } - *RequestId = desc.TransactionId; + *requestid = desc.TransactionId; /* Copy over the entire packet to the user buffer */ - ret = RingBufferRead(&Channel->Inbound, Buffer, packetLen, 0); + ret = RingBufferRead(&channel->Inbound, buffer, packetlen, 0); - spin_unlock_irqrestore(&Channel->inbound_lock, flags); + spin_unlock_irqrestore(&channel->inbound_lock, flags); return 0; } +EXPORT_SYMBOL_GPL(vmbus_recvpacket_raw); /* - * VmbusChannelOnChannelEvent - Channel event callback + * vmbus_onchannel_event - Channel event callback */ -void VmbusChannelOnChannelEvent(struct vmbus_channel *Channel) +void vmbus_onchannel_event(struct vmbus_channel *channel) { - DumpVmbusChannel(Channel); + dump_vmbus_channel(channel); /* ASSERT(Channel->OnChannelCallback); */ - Channel->OnChannelCallback(Channel->ChannelCallbackContext); + channel->OnChannelCallback(channel->ChannelCallbackContext); - mod_timer(&Channel->poll_timer, jiffies + usecs_to_jiffies(100)); + mod_timer(&channel->poll_timer, jiffies + usecs_to_jiffies(100)); } /* - * VmbusChannelOnTimer - Timer event callback + * vmbus_ontimer - Timer event callback */ -void VmbusChannelOnTimer(unsigned long data) +void vmbus_ontimer(unsigned long data) { struct vmbus_channel *channel = (struct vmbus_channel *)data; @@ -1034,11 +1047,11 @@ void VmbusChannelOnTimer(unsigned long data) } /* - * DumpVmbusChannel - Dump vmbus channel info to the console + * dump_vmbus_channel- Dump vmbus channel info to the console */ -static void DumpVmbusChannel(struct vmbus_channel *Channel) +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.ChildRelId); + DumpRingInfo(&channel->Outbound, "Outbound "); + DumpRingInfo(&channel->Inbound, "Inbound "); } diff --git a/drivers/staging/hv/channel.h b/drivers/staging/hv/channel.h index acb2c556369b..7997056734d7 100644 --- a/drivers/staging/hv/channel.h +++ b/drivers/staging/hv/channel.h @@ -28,85 +28,85 @@ #include "channel_mgmt.h" /* The format must be the same as struct vmdata_gpa_direct */ -struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER { - u16 Type; - u16 DataOffset8; - u16 Length8; - u16 Flags; - u64 TransactionId; - u32 Reserved; - u32 RangeCount; - struct hv_page_buffer Range[MAX_PAGE_BUFFER_COUNT]; +struct vmbus_channel_packet_page_buffer { + u16 type; + u16 dataoffset8; + u16 length8; + u16 flags; + u64 transactionid; + u32 reserved; + u32 rangecount; + struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT]; } __attribute__((packed)); /* The format must be the same as struct vmdata_gpa_direct */ -struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER { - u16 Type; - u16 DataOffset8; - u16 Length8; - u16 Flags; - u64 TransactionId; - u32 Reserved; - u32 RangeCount; /* Always 1 in this case */ - struct hv_multipage_buffer Range; +struct vmbus_channel_packet_multipage_buffer { + u16 type; + u16 dataoffset8; + u16 length8; + u16 flags; + u64 transactionid; + u32 reserved; + u32 rangecount; /* Always 1 in this case */ + struct hv_multipage_buffer range; } __attribute__((packed)); -extern int VmbusChannelOpen(struct vmbus_channel *channel, - u32 SendRingBufferSize, - u32 RecvRingBufferSize, - void *UserData, - u32 UserDataLen, - void(*OnChannelCallback)(void *context), - void *Context); +extern int vmbus_open(struct vmbus_channel *channel, + u32 send_ringbuffersize, + u32 recv_ringbuffersize, + void *userdata, + u32 userdatalen, + void(*onchannel_callback)(void *context), + void *context); -extern void VmbusChannelClose(struct vmbus_channel *channel); +extern void vmbus_close(struct vmbus_channel *channel); -extern int VmbusChannelSendPacket(struct vmbus_channel *channel, - const void *Buffer, - u32 BufferLen, - u64 RequestId, - enum vmbus_packet_type Type, - u32 Flags); +extern int vmbus_sendpacket(struct vmbus_channel *channel, + const void *buffer, + u32 bufferLen, + u64 requestid, + enum vmbus_packet_type type, + u32 flags); -extern int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *channel, - struct hv_page_buffer PageBuffers[], - u32 PageCount, - void *Buffer, - u32 BufferLen, - u64 RequestId); +extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, + struct hv_page_buffer pagebuffers[], + u32 pagecount, + void *buffer, + u32 bufferlen, + u64 requestid); -extern int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *channel, +extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, struct hv_multipage_buffer *mpb, - void *Buffer, - u32 BufferLen, - u64 RequestId); + void *buffer, + u32 bufferlen, + u64 requestid); -extern int VmbusChannelEstablishGpadl(struct vmbus_channel *channel, - void *Kbuffer, - u32 Size, - u32 *GpadlHandle); +extern int vmbus_establish_gpadl(struct vmbus_channel *channel, + void *kbuffer, + u32 size, + u32 *gpadl_handle); -extern int VmbusChannelTeardownGpadl(struct vmbus_channel *channel, - u32 GpadlHandle); +extern int vmbus_teardown_gpadl(struct vmbus_channel *channel, + u32 gpadl_handle); -extern int VmbusChannelRecvPacket(struct vmbus_channel *channel, - void *Buffer, - u32 BufferLen, - u32 *BufferActualLen, - u64 *RequestId); +extern int vmbus_recvpacket(struct vmbus_channel *channel, + void *buffer, + u32 bufferlen, + u32 *buffer_actual_len, + u64 *requestid); -extern int VmbusChannelRecvPacketRaw(struct vmbus_channel *channel, - void *Buffer, - u32 BufferLen, - u32 *BufferActualLen, - u64 *RequestId); +extern int vmbus_recvpacket_raw(struct vmbus_channel *channel, + void *buffer, + u32 bufferlen, + u32 *buffer_actual_len, + u64 *requestid); -extern void VmbusChannelOnChannelEvent(struct vmbus_channel *channel); +extern void vmbus_onchannel_event(struct vmbus_channel *channel); -extern void VmbusChannelGetDebugInfo(struct vmbus_channel *channel, +extern void vmbus_get_debug_info(struct vmbus_channel *channel, struct vmbus_channel_debug_info *debug); -extern void VmbusChannelOnTimer(unsigned long data); +extern void vmbus_ontimer(unsigned long data); #endif /* _CHANNEL_H_ */ diff --git a/drivers/staging/hv/channel_interface.c b/drivers/staging/hv/channel_interface.c deleted file mode 100644 index d9f51ac75eaa..000000000000 --- a/drivers/staging/hv/channel_interface.c +++ /dev/null @@ -1,152 +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 "osd.h" -#include "vmbus_private.h" - -static int IVmbusChannelOpen(struct hv_device *device, u32 SendBufferSize, - u32 RecvRingBufferSize, void *UserData, - u32 UserDataLen, - void (*ChannelCallback)(void *context), - void *Context) -{ - return VmbusChannelOpen(device->context, SendBufferSize, - RecvRingBufferSize, UserData, UserDataLen, - ChannelCallback, Context); -} - -static void IVmbusChannelClose(struct hv_device *device) -{ - VmbusChannelClose(device->context); -} - -static int IVmbusChannelSendPacket(struct hv_device *device, const void *Buffer, - u32 BufferLen, u64 RequestId, u32 Type, - u32 Flags) -{ - return VmbusChannelSendPacket(device->context, Buffer, BufferLen, - RequestId, Type, Flags); -} - -static int IVmbusChannelSendPacketPageBuffer(struct hv_device *device, - struct hv_page_buffer PageBuffers[], - u32 PageCount, void *Buffer, - u32 BufferLen, u64 RequestId) -{ - return VmbusChannelSendPacketPageBuffer(device->context, PageBuffers, - PageCount, Buffer, BufferLen, - RequestId); -} - -static int IVmbusChannelSendPacketMultiPageBuffer(struct hv_device *device, - struct hv_multipage_buffer *MultiPageBuffer, - void *Buffer, u32 BufferLen, u64 RequestId) -{ - return VmbusChannelSendPacketMultiPageBuffer(device->context, - MultiPageBuffer, Buffer, - BufferLen, RequestId); -} - -static int IVmbusChannelRecvPacket(struct hv_device *device, void *Buffer, - u32 BufferLen, u32 *BufferActualLen, - u64 *RequestId) -{ - return VmbusChannelRecvPacket(device->context, Buffer, BufferLen, - BufferActualLen, RequestId); -} - -static int IVmbusChannelRecvPacketRaw(struct hv_device *device, void *Buffer, - u32 BufferLen, u32 *BufferActualLen, - u64 *RequestId) -{ - return VmbusChannelRecvPacketRaw(device->context, Buffer, BufferLen, - BufferActualLen, RequestId); -} - -static int IVmbusChannelEstablishGpadl(struct hv_device *device, void *Buffer, - u32 BufferLen, u32 *GpadlHandle) -{ - return VmbusChannelEstablishGpadl(device->context, Buffer, BufferLen, - GpadlHandle); -} - -static int IVmbusChannelTeardownGpadl(struct hv_device *device, u32 GpadlHandle) -{ - return VmbusChannelTeardownGpadl(device->context, GpadlHandle); - -} - -void GetChannelInterface(struct vmbus_channel_interface *iface) -{ - iface->Open = IVmbusChannelOpen; - iface->Close = IVmbusChannelClose; - iface->SendPacket = IVmbusChannelSendPacket; - iface->SendPacketPageBuffer = IVmbusChannelSendPacketPageBuffer; - iface->SendPacketMultiPageBuffer = - IVmbusChannelSendPacketMultiPageBuffer; - iface->RecvPacket = IVmbusChannelRecvPacket; - iface->RecvPacketRaw = IVmbusChannelRecvPacketRaw; - iface->EstablishGpadl = IVmbusChannelEstablishGpadl; - iface->TeardownGpadl = IVmbusChannelTeardownGpadl; - iface->GetInfo = GetChannelInfo; -} - -void GetChannelInfo(struct hv_device *device, struct hv_device_info *info) -{ - struct vmbus_channel_debug_info debugInfo; - - if (!device->context) - return; - - VmbusChannelGetDebugInfo(device->context, &debugInfo); - - info->ChannelId = debugInfo.RelId; - info->ChannelState = debugInfo.State; - memcpy(&info->ChannelType, &debugInfo.InterfaceType, - sizeof(struct hv_guid)); - memcpy(&info->ChannelInstance, &debugInfo.InterfaceInstance, - sizeof(struct hv_guid)); - - info->MonitorId = debugInfo.MonitorId; - - info->ServerMonitorPending = debugInfo.ServerMonitorPending; - info->ServerMonitorLatency = debugInfo.ServerMonitorLatency; - info->ServerMonitorConnectionId = debugInfo.ServerMonitorConnectionId; - - info->ClientMonitorPending = debugInfo.ClientMonitorPending; - info->ClientMonitorLatency = debugInfo.ClientMonitorLatency; - info->ClientMonitorConnectionId = debugInfo.ClientMonitorConnectionId; - - info->Inbound.InterruptMask = debugInfo.Inbound.CurrentInterruptMask; - info->Inbound.ReadIndex = debugInfo.Inbound.CurrentReadIndex; - info->Inbound.WriteIndex = debugInfo.Inbound.CurrentWriteIndex; - info->Inbound.BytesAvailToRead = debugInfo.Inbound.BytesAvailToRead; - info->Inbound.BytesAvailToWrite = debugInfo.Inbound.BytesAvailToWrite; - - info->Outbound.InterruptMask = debugInfo.Outbound.CurrentInterruptMask; - info->Outbound.ReadIndex = debugInfo.Outbound.CurrentReadIndex; - info->Outbound.WriteIndex = debugInfo.Outbound.CurrentWriteIndex; - info->Outbound.BytesAvailToRead = debugInfo.Outbound.BytesAvailToRead; - info->Outbound.BytesAvailToWrite = debugInfo.Outbound.BytesAvailToWrite; -} diff --git a/drivers/staging/hv/channel_interface.h b/drivers/staging/hv/channel_interface.h deleted file mode 100644 index 6acaf6ce2c48..000000000000 --- a/drivers/staging/hv/channel_interface.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Copyright (c) 2009, Microsoft Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307 USA. - * - * Authors: - * Haiyang Zhang <haiyangz@microsoft.com> - * Hank Janssen <hjanssen@microsoft.com> - * - */ - - -#ifndef _CHANNEL_INTERFACE_H_ -#define _CHANNEL_INTERFACE_H_ - -#include "vmbus_api.h" - -void GetChannelInterface(struct vmbus_channel_interface *ChannelInterface); - -void GetChannelInfo(struct hv_device *Device, - struct hv_device_info *DeviceInfo); - -#endif /* _CHANNEL_INTERFACE_H_ */ diff --git a/drivers/staging/hv/channel_mgmt.c b/drivers/staging/hv/channel_mgmt.c index 6ccf505e802d..45dbe305afed 100644 --- a/drivers/staging/hv/channel_mgmt.c +++ b/drivers/staging/hv/channel_mgmt.c @@ -172,7 +172,7 @@ void chn_cb_negotiate(void *context) buflen = PAGE_SIZE; buf = kmalloc(buflen, GFP_ATOMIC); - VmbusChannelRecvPacket(channel, buf, buflen, &recvlen, &requestid); + vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid); if (recvlen > 0) { icmsghdrp = (struct icmsg_hdr *)&buf[ @@ -183,7 +183,7 @@ void chn_cb_negotiate(void *context) icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; - VmbusChannelSendPacket(channel, buf, + vmbus_sendpacket(channel, buf, recvlen, requestid, VmbusPacketTypeDataInBand, 0); } @@ -235,9 +235,9 @@ struct hyperv_service_callback hv_cb_utils[MAX_MSG_TYPES] = { EXPORT_SYMBOL(hv_cb_utils); /* - * AllocVmbusChannel - Allocate and initialize a vmbus channel object + * alloc_channel - Allocate and initialize a vmbus channel object */ -struct vmbus_channel *AllocVmbusChannel(void) +static struct vmbus_channel *alloc_channel(void) { struct vmbus_channel *channel; @@ -249,7 +249,7 @@ struct vmbus_channel *AllocVmbusChannel(void) init_timer(&channel->poll_timer); channel->poll_timer.data = (unsigned long)channel; - channel->poll_timer.function = VmbusChannelOnTimer; + channel->poll_timer.function = vmbus_ontimer; channel->ControlWQ = create_workqueue("hv_vmbus_ctl"); if (!channel->ControlWQ) { @@ -261,9 +261,9 @@ struct vmbus_channel *AllocVmbusChannel(void) } /* - * ReleaseVmbusChannel - Release the vmbus channel object itself + * release_hannel - Release the vmbus channel object itself */ -static inline void ReleaseVmbusChannel(void *context) +static inline void release_channel(void *context) { struct vmbus_channel *channel = context; @@ -275,19 +275,19 @@ static inline void ReleaseVmbusChannel(void *context) } /* - * FreeVmbusChannel - Release the resources used by the vmbus channel object + * free_channel - Release the resources used by the vmbus channel object */ -void FreeVmbusChannel(struct vmbus_channel *Channel) +void free_channel(struct vmbus_channel *channel) { - del_timer_sync(&Channel->poll_timer); + del_timer_sync(&channel->poll_timer); /* * We have to release the channel's workqueue/thread in the vmbus's * workqueue/thread context * ie we can't destroy ourselves. */ - osd_schedule_callback(gVmbusConnection.WorkQueue, ReleaseVmbusChannel, - Channel); + osd_schedule_callback(gVmbusConnection.WorkQueue, release_channel, + channel); } @@ -310,14 +310,14 @@ static void count_hv_channel(void) /* - * VmbusChannelProcessOffer - Process the offer by creating a channel/device + * vmbus_process_offer - Process the offer by creating a channel/device * associated with this offer */ -static void VmbusChannelProcessOffer(void *context) +static void vmbus_process_offer(void *context) { - struct vmbus_channel *newChannel = context; + struct vmbus_channel *newchannel = context; struct vmbus_channel *channel; - bool fNew = true; + bool fnew = true; int ret; int cnt; unsigned long flags; @@ -327,26 +327,26 @@ static void VmbusChannelProcessOffer(void *context) list_for_each_entry(channel, &gVmbusConnection.ChannelList, ListEntry) { if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, - &newChannel->OfferMsg.Offer.InterfaceType, + &newchannel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid)) && !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, - &newChannel->OfferMsg.Offer.InterfaceInstance, + &newchannel->OfferMsg.Offer.InterfaceInstance, sizeof(struct hv_guid))) { - fNew = false; + fnew = false; break; } } - if (fNew) - list_add_tail(&newChannel->ListEntry, + if (fnew) + list_add_tail(&newchannel->ListEntry, &gVmbusConnection.ChannelList); spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); - if (!fNew) { + if (!fnew) { DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", - newChannel->OfferMsg.ChildRelId); - FreeVmbusChannel(newChannel); + newchannel->OfferMsg.ChildRelId); + free_channel(newchannel); return; } @@ -355,48 +355,48 @@ static void VmbusChannelProcessOffer(void *context) * We need to set the DeviceObject field before calling * VmbusChildDeviceAdd() */ - newChannel->DeviceObject = VmbusChildDeviceCreate( - &newChannel->OfferMsg.Offer.InterfaceType, - &newChannel->OfferMsg.Offer.InterfaceInstance, - newChannel); + newchannel->DeviceObject = VmbusChildDeviceCreate( + &newchannel->OfferMsg.Offer.InterfaceType, + &newchannel->OfferMsg.Offer.InterfaceInstance, + newchannel); DPRINT_DBG(VMBUS, "child device object allocated - %p", - newChannel->DeviceObject); + newchannel->DeviceObject); /* * 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->DeviceObject); if (ret != 0) { DPRINT_ERR(VMBUS, "unable to add child device object (relid %d)", - newChannel->OfferMsg.ChildRelId); + newchannel->OfferMsg.ChildRelId); spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); - list_del(&newChannel->ListEntry); + list_del(&newchannel->ListEntry); spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); - FreeVmbusChannel(newChannel); + free_channel(newchannel); } else { /* * This state is used to indicate a successful open * 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 && - VmbusChannelOpen(newChannel, 2 * PAGE_SIZE, + vmbus_open(newchannel, 2 * PAGE_SIZE, 2 * PAGE_SIZE, NULL, 0, hv_cb_utils[cnt].callback, - newChannel) == 0) { - hv_cb_utils[cnt].channel = newChannel; + newchannel) == 0) { + hv_cb_utils[cnt].channel = newchannel; DPRINT_INFO(VMBUS, "%s", hv_cb_utils[cnt].log_msg); count_hv_channel(); @@ -406,9 +406,10 @@ static void VmbusChannelProcessOffer(void *context) } /* - * VmbusChannelProcessRescindOffer - Rescind the offer by initiating a device removal + * vmbus_process_rescind_offer - + * Rescind the offer by initiating a device removal */ -static void VmbusChannelProcessRescindOffer(void *context) +static void vmbus_process_rescind_offer(void *context) { struct vmbus_channel *channel = context; @@ -416,38 +417,38 @@ static void VmbusChannelProcessRescindOffer(void *context) } /* - * VmbusChannelOnOffer - Handler for channel offers from vmbus in parent partition. + * vmbus_onoffer - Handler for channel offers from vmbus in parent partition. * * We ignore all offers except network and storage offers. For each network and * storage offers, we create a channel object and queue a work item to the * channel object to process the offer synchronously */ -static void VmbusChannelOnOffer(struct vmbus_channel_message_header *hdr) +static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) { struct vmbus_channel_offer_channel *offer; - struct vmbus_channel *newChannel; - struct hv_guid *guidType; - struct hv_guid *guidInstance; + struct vmbus_channel *newchannel; + struct hv_guid *guidtype; + struct hv_guid *guidinstance; int i; - int fSupported = 0; + int fsupported = 0; offer = (struct vmbus_channel_offer_channel *)hdr; for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) { if (memcmp(&offer->Offer.InterfaceType, &gSupportedDeviceClasses[i], sizeof(struct hv_guid)) == 0) { - fSupported = 1; + fsupported = 1; break; } } - if (!fSupported) { + if (!fsupported) { DPRINT_DBG(VMBUS, "Ignoring channel offer notification for " "child relid %d", offer->ChildRelId); 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, " @@ -457,48 +458,48 @@ static void VmbusChannelOnOffer(struct vmbus_channel_message_header *hdr) "%02x%02x%02x%02x%02x%02x%02x%02x}", offer->ChildRelId, offer->MonitorId, offer->MonitorAllocated, - guidType->data[3], guidType->data[2], - guidType->data[1], guidType->data[0], - guidType->data[5], guidType->data[4], - guidType->data[7], guidType->data[6], - guidType->data[8], guidType->data[9], - guidType->data[10], guidType->data[11], - guidType->data[12], guidType->data[13], - guidType->data[14], guidType->data[15], - guidInstance->data[3], guidInstance->data[2], - guidInstance->data[1], guidInstance->data[0], - guidInstance->data[5], guidInstance->data[4], - guidInstance->data[7], guidInstance->data[6], - guidInstance->data[8], guidInstance->data[9], - guidInstance->data[10], guidInstance->data[11], - guidInstance->data[12], guidInstance->data[13], - guidInstance->data[14], guidInstance->data[15]); + guidtype->data[3], guidtype->data[2], + guidtype->data[1], guidtype->data[0], + guidtype->data[5], guidtype->data[4], + guidtype->data[7], guidtype->data[6], + guidtype->data[8], guidtype->data[9], + guidtype->data[10], guidtype->data[11], + guidtype->data[12], guidtype->data[13], + guidtype->data[14], guidtype->data[15], + guidinstance->data[3], guidinstance->data[2], + guidinstance->data[1], guidinstance->data[0], + guidinstance->data[5], guidinstance->data[4], + guidinstance->data[7], guidinstance->data[6], + guidinstance->data[8], guidinstance->data[9], + guidinstance->data[10], guidinstance->data[11], + guidinstance->data[12], guidinstance->data[13], + guidinstance->data[14], guidinstance->data[15]); /* Allocate the channel object and save this offer. */ - newChannel = AllocVmbusChannel(); - if (!newChannel) { + newchannel = alloc_channel(); + if (!newchannel) { DPRINT_ERR(VMBUS, "unable to allocate channel object"); return; } - DPRINT_DBG(VMBUS, "channel object allocated - %p", newChannel); + 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->MonitorGroup = (u8)offer->MonitorId / 32; + newchannel->MonitorBit = (u8)offer->MonitorId % 32; /* TODO: Make sure the offer comes from our parent partition */ - osd_schedule_callback(newChannel->ControlWQ, VmbusChannelProcessOffer, - newChannel); + osd_schedule_callback(newchannel->ControlWQ, vmbus_process_offer, + newchannel); } /* - * VmbusChannelOnOfferRescind - Rescind offer handler. + * vmbus_onoffer_rescind - Rescind offer handler. * * We queue a work item to process this offer synchronously */ -static void VmbusChannelOnOfferRescind(struct vmbus_channel_message_header *hdr) +static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) { struct vmbus_channel_rescind_offer *rescind; struct vmbus_channel *channel; @@ -512,34 +513,35 @@ static void VmbusChannelOnOfferRescind(struct vmbus_channel_message_header *hdr) } osd_schedule_callback(channel->ControlWQ, - VmbusChannelProcessRescindOffer, + vmbus_process_rescind_offer, channel); } /* - * VmbusChannelOnOffersDelivered - This is invoked when all offers have been delivered. + * vmbus_onoffers_delivered - + * This is invoked when all offers have been delivered. * * Nothing to do here. */ -static void VmbusChannelOnOffersDelivered( +static void vmbus_onoffers_delivered( struct vmbus_channel_message_header *hdr) { } /* - * VmbusChannelOnOpenResult - Open result handler. + * vmbus_onopen_result - Open result handler. * * This is invoked when we received a response to our channel open request. * Find the matching request, copy the response and signal the requesting * thread. */ -static void VmbusChannelOnOpenResult(struct vmbus_channel_message_header *hdr) +static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) { struct vmbus_channel_open_result *result; struct list_head *curr; - struct vmbus_channel_msginfo *msgInfo; - struct vmbus_channel_message_header *requestHeader; - struct vmbus_channel_open_channel *openMsg; + struct vmbus_channel_msginfo *msginfo; + struct vmbus_channel_message_header *requestheader; + struct vmbus_channel_open_channel *openmsg; unsigned long flags; result = (struct vmbus_channel_open_result *)hdr; @@ -552,17 +554,19 @@ static void VmbusChannelOnOpenResult(struct vmbus_channel_message_header *hdr) list_for_each(curr, &gVmbusConnection.ChannelMsgList) { /* FIXME: this should probably use list_entry() instead */ - msgInfo = (struct vmbus_channel_msginfo *)curr; - requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg; - - if (requestHeader->MessageType == ChannelMessageOpenChannel) { - openMsg = (struct vmbus_channel_open_channel *)msgInfo->Msg; - if (openMsg->ChildRelId == result->ChildRelId && - openMsg->OpenId == result->OpenId) { - memcpy(&msgInfo->Response.OpenResult, + msginfo = (struct vmbus_channel_msginfo *)curr; + requestheader = + (struct vmbus_channel_message_header *)msginfo->Msg; + + if (requestheader->MessageType == ChannelMessageOpenChannel) { + openmsg = + (struct vmbus_channel_open_channel *)msginfo->Msg; + if (openmsg->ChildRelId == result->ChildRelId && + openmsg->OpenId == result->OpenId) { + memcpy(&msginfo->Response.OpenResult, result, sizeof(struct vmbus_channel_open_result)); - osd_WaitEventSet(msgInfo->WaitEvent); + osd_WaitEventSet(msginfo->WaitEvent); break; } } @@ -571,24 +575,24 @@ static void VmbusChannelOnOpenResult(struct vmbus_channel_message_header *hdr) } /* - * VmbusChannelOnGpadlCreated - GPADL created handler. + * vmbus_ongpadl_created - GPADL created handler. * * This is invoked when we received a response to our gpadl create request. * Find the matching request, copy the response and signal the requesting * thread. */ -static void VmbusChannelOnGpadlCreated(struct vmbus_channel_message_header *hdr) +static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) { - struct vmbus_channel_gpadl_created *gpadlCreated; + struct vmbus_channel_gpadl_created *gpadlcreated; struct list_head *curr; - struct vmbus_channel_msginfo *msgInfo; - struct vmbus_channel_message_header *requestHeader; - struct vmbus_channel_gpadl_header *gpadlHeader; + struct vmbus_channel_msginfo *msginfo; + struct vmbus_channel_message_header *requestheader; + struct vmbus_channel_gpadl_header *gpadlheader; unsigned long flags; - gpadlCreated = (struct vmbus_channel_gpadl_created *)hdr; + gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr; DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", - gpadlCreated->CreationStatus); + gpadlcreated->CreationStatus); /* * Find the establish msg, copy the result and signal/unblock the wait @@ -598,19 +602,21 @@ static void VmbusChannelOnGpadlCreated(struct vmbus_channel_message_header *hdr) list_for_each(curr, &gVmbusConnection.ChannelMsgList) { /* FIXME: this should probably use list_entry() instead */ - msgInfo = (struct vmbus_channel_msginfo *)curr; - requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg; - - if (requestHeader->MessageType == ChannelMessageGpadlHeader) { - gpadlHeader = (struct vmbus_channel_gpadl_header *)requestHeader; - - if ((gpadlCreated->ChildRelId == - gpadlHeader->ChildRelId) && - (gpadlCreated->Gpadl == gpadlHeader->Gpadl)) { - memcpy(&msgInfo->Response.GpadlCreated, - gpadlCreated, + msginfo = (struct vmbus_channel_msginfo *)curr; + requestheader = + (struct vmbus_channel_message_header *)msginfo->Msg; + + if (requestheader->MessageType == ChannelMessageGpadlHeader) { + gpadlheader = + (struct vmbus_channel_gpadl_header *)requestheader; + + if ((gpadlcreated->ChildRelId == + gpadlheader->ChildRelId) && + (gpadlcreated->Gpadl == gpadlheader->Gpadl)) { + memcpy(&msginfo->Response.GpadlCreated, + gpadlcreated, sizeof(struct vmbus_channel_gpadl_created)); - osd_WaitEventSet(msgInfo->WaitEvent); + osd_WaitEventSet(msginfo->WaitEvent); break; } } @@ -619,23 +625,23 @@ static void VmbusChannelOnGpadlCreated(struct vmbus_channel_message_header *hdr) } /* - * VmbusChannelOnGpadlTorndown - GPADL torndown handler. + * vmbus_ongpadl_torndown - GPADL torndown handler. * * This is invoked when we received a response to our gpadl teardown request. * Find the matching request, copy the response and signal the requesting * thread. */ -static void VmbusChannelOnGpadlTorndown( +static void vmbus_ongpadl_torndown( struct vmbus_channel_message_header *hdr) { - struct vmbus_channel_gpadl_torndown *gpadlTorndown; + struct vmbus_channel_gpadl_torndown *gpadl_torndown; struct list_head *curr; - struct vmbus_channel_msginfo *msgInfo; - struct vmbus_channel_message_header *requestHeader; - struct vmbus_channel_gpadl_teardown *gpadlTeardown; + struct vmbus_channel_msginfo *msginfo; + struct vmbus_channel_message_header *requestheader; + struct vmbus_channel_gpadl_teardown *gpadl_teardown; unsigned long flags; - gpadlTorndown = (struct vmbus_channel_gpadl_torndown *)hdr; + gpadl_torndown = (struct vmbus_channel_gpadl_torndown *)hdr; /* * Find the open msg, copy the result and signal/unblock the wait event @@ -644,17 +650,19 @@ static void VmbusChannelOnGpadlTorndown( list_for_each(curr, &gVmbusConnection.ChannelMsgList) { /* FIXME: this should probably use list_entry() instead */ - msgInfo = (struct vmbus_channel_msginfo *)curr; - requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg; + msginfo = (struct vmbus_channel_msginfo *)curr; + requestheader = + (struct vmbus_channel_message_header *)msginfo->Msg; - if (requestHeader->MessageType == ChannelMessageGpadlTeardown) { - gpadlTeardown = (struct vmbus_channel_gpadl_teardown *)requestHeader; + if (requestheader->MessageType == ChannelMessageGpadlTeardown) { + gpadl_teardown = + (struct vmbus_channel_gpadl_teardown *)requestheader; - if (gpadlTorndown->Gpadl == gpadlTeardown->Gpadl) { - memcpy(&msgInfo->Response.GpadlTorndown, - gpadlTorndown, + if (gpadl_torndown->Gpadl == gpadl_teardown->Gpadl) { + memcpy(&msginfo->Response.GpadlTorndown, + gpadl_torndown, sizeof(struct vmbus_channel_gpadl_torndown)); - osd_WaitEventSet(msgInfo->WaitEvent); + osd_WaitEventSet(msginfo->WaitEvent); break; } } @@ -663,37 +671,39 @@ static void VmbusChannelOnGpadlTorndown( } /* - * VmbusChannelOnVersionResponse - Version response handler + * vmbus_onversion_response - Version response handler * * This is invoked when we received a response to our initiate contact request. * Find the matching request, copy the response and signal the requesting * thread. */ -static void VmbusChannelOnVersionResponse( +static void vmbus_onversion_response( struct vmbus_channel_message_header *hdr) { struct list_head *curr; - struct vmbus_channel_msginfo *msgInfo; - struct vmbus_channel_message_header *requestHeader; + struct vmbus_channel_msginfo *msginfo; + struct vmbus_channel_message_header *requestheader; struct vmbus_channel_initiate_contact *initiate; - struct vmbus_channel_version_response *versionResponse; + struct vmbus_channel_version_response *version_response; unsigned long flags; - versionResponse = (struct vmbus_channel_version_response *)hdr; + version_response = (struct vmbus_channel_version_response *)hdr; spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); list_for_each(curr, &gVmbusConnection.ChannelMsgList) { /* FIXME: this should probably use list_entry() instead */ - msgInfo = (struct vmbus_channel_msginfo *)curr; - requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg; + msginfo = (struct vmbus_channel_msginfo *)curr; + requestheader = + (struct vmbus_channel_message_header *)msginfo->Msg; - if (requestHeader->MessageType == + if (requestheader->MessageType == ChannelMessageInitiateContact) { - initiate = (struct vmbus_channel_initiate_contact *)requestHeader; - memcpy(&msgInfo->Response.VersionResponse, - versionResponse, + initiate = + (struct vmbus_channel_initiate_contact *)requestheader; + memcpy(&msginfo->Response.VersionResponse, + version_response, sizeof(struct vmbus_channel_version_response)); - osd_WaitEventSet(msgInfo->WaitEvent); + osd_WaitEventSet(msginfo->WaitEvent); } } spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); @@ -703,32 +713,32 @@ static void VmbusChannelOnVersionResponse( static struct vmbus_channel_message_table_entry gChannelMessageTable[ChannelMessageCount] = { {ChannelMessageInvalid, NULL}, - {ChannelMessageOfferChannel, VmbusChannelOnOffer}, - {ChannelMessageRescindChannelOffer, VmbusChannelOnOfferRescind}, + {ChannelMessageOfferChannel, vmbus_onoffer}, + {ChannelMessageRescindChannelOffer, vmbus_onoffer_rescind}, {ChannelMessageRequestOffers, NULL}, - {ChannelMessageAllOffersDelivered, VmbusChannelOnOffersDelivered}, + {ChannelMessageAllOffersDelivered, vmbus_onoffers_delivered}, {ChannelMessageOpenChannel, NULL}, - {ChannelMessageOpenChannelResult, VmbusChannelOnOpenResult}, + {ChannelMessageOpenChannelResult, vmbus_onopen_result}, {ChannelMessageCloseChannel, NULL}, {ChannelMessageGpadlHeader, NULL}, {ChannelMessageGpadlBody, NULL}, - {ChannelMessageGpadlCreated, VmbusChannelOnGpadlCreated}, + {ChannelMessageGpadlCreated, vmbus_ongpadl_created}, {ChannelMessageGpadlTeardown, NULL}, - {ChannelMessageGpadlTorndown, VmbusChannelOnGpadlTorndown}, + {ChannelMessageGpadlTorndown, vmbus_ongpadl_torndown}, {ChannelMessageRelIdReleased, NULL}, {ChannelMessageInitiateContact, NULL}, - {ChannelMessageVersionResponse, VmbusChannelOnVersionResponse}, + {ChannelMessageVersionResponse, vmbus_onversion_response}, {ChannelMessageUnload, NULL}, }; /* - * VmbusOnChannelMessage - Handler for channel protocol messages. + * vmbus_onmessage - Handler for channel protocol messages. * * This is invoked in the vmbus worker thread context. */ -void VmbusOnChannelMessage(void *Context) +void vmbus_onmessage(void *context) { - struct hv_message *msg = Context; + struct hv_message *msg = context; struct vmbus_channel_message_header *hdr; int size; @@ -758,27 +768,27 @@ void VmbusOnChannelMessage(void *Context) } /* - * VmbusChannelRequestOffers - Send a request to get all our pending offers. + * vmbus_request_offers - Send a request to get all our pending offers. */ -int VmbusChannelRequestOffers(void) +int vmbus_request_offers(void) { struct vmbus_channel_message_header *msg; - struct vmbus_channel_msginfo *msgInfo; + struct vmbus_channel_msginfo *msginfo; int ret; - msgInfo = kmalloc(sizeof(*msgInfo) + + msginfo = kmalloc(sizeof(*msginfo) + sizeof(struct vmbus_channel_message_header), GFP_KERNEL); - if (!msgInfo) + if (!msginfo) return -ENOMEM; - msgInfo->WaitEvent = osd_WaitEventCreate(); - if (!msgInfo->WaitEvent) { - kfree(msgInfo); + msginfo->WaitEvent = osd_WaitEventCreate(); + 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; @@ -806,19 +816,19 @@ int VmbusChannelRequestOffers(void) Cleanup: - if (msgInfo) { - kfree(msgInfo->WaitEvent); - kfree(msgInfo); + if (msginfo) { + kfree(msginfo->WaitEvent); + kfree(msginfo); } return ret; } /* - * VmbusChannelReleaseUnattachedChannels - Release channels that are + * vmbus_release_unattached_channels - Release channels that are * unattached/unconnected ie (no drivers associated) */ -void VmbusChannelReleaseUnattachedChannels(void) +void vmbus_release_unattached_channels(void) { struct vmbus_channel *channel, *pos; struct vmbus_channel *start = NULL; @@ -838,7 +848,7 @@ void VmbusChannelReleaseUnattachedChannels(void) channel->DeviceObject); VmbusChildDeviceRemove(channel->DeviceObject); - FreeVmbusChannel(channel); + free_channel(channel); } else { if (!start) start = channel; diff --git a/drivers/staging/hv/channel_mgmt.h b/drivers/staging/hv/channel_mgmt.h index f969267895be..d16cc0811169 100644 --- a/drivers/staging/hv/channel_mgmt.h +++ b/drivers/staging/hv/channel_mgmt.h @@ -307,14 +307,12 @@ struct vmbus_channel_msginfo { }; -struct vmbus_channel *AllocVmbusChannel(void); +void free_channel(struct vmbus_channel *channel); -void FreeVmbusChannel(struct vmbus_channel *Channel); +void vmbus_onmessage(void *context); -void VmbusOnChannelMessage(void *Context); +int vmbus_request_offers(void); -int VmbusChannelRequestOffers(void); - -void VmbusChannelReleaseUnattachedChannels(void); +void vmbus_release_unattached_channels(void); #endif /* _CHANNEL_MGMT_H_ */ diff --git a/drivers/staging/hv/connection.c b/drivers/staging/hv/connection.c index 1f4d6683aaa7..f8477072ace4 100644 --- a/drivers/staging/hv/connection.c +++ b/drivers/staging/hv/connection.c @@ -254,10 +254,10 @@ static void VmbusProcessChannelEvent(void *context) channel = GetChannelFromRelId(relId); if (channel) { - VmbusChannelOnChannelEvent(channel); + vmbus_onchannel_event(channel); /* * WorkQueueQueueWorkItem(channel->dataWorkQueue, - * VmbusChannelOnChannelEvent, + * vmbus_onchannel_event, * (void*)channel); */ } else { diff --git a/drivers/staging/hv/hv_utils.c b/drivers/staging/hv/hv_utils.c index 6eb79febef9b..a99e900ec4c9 100644 --- a/drivers/staging/hv/hv_utils.c +++ b/drivers/staging/hv/hv_utils.c @@ -55,7 +55,7 @@ static void shutdown_onchannelcallback(void *context) buflen = PAGE_SIZE; buf = kmalloc(buflen, GFP_ATOMIC); - VmbusChannelRecvPacket(channel, buf, buflen, &recvlen, &requestid); + vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid); if (recvlen > 0) { DPRINT_DBG(VMBUS, "shutdown packet: len=%d, requestid=%lld", @@ -93,7 +93,7 @@ static void shutdown_onchannelcallback(void *context) icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; - VmbusChannelSendPacket(channel, buf, + vmbus_sendpacket(channel, buf, recvlen, requestid, VmbusPacketTypeDataInBand, 0); } @@ -159,7 +159,7 @@ static void timesync_onchannelcallback(void *context) buflen = PAGE_SIZE; buf = kmalloc(buflen, GFP_ATOMIC); - VmbusChannelRecvPacket(channel, buf, buflen, &recvlen, &requestid); + vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid); if (recvlen > 0) { DPRINT_DBG(VMBUS, "timesync packet: recvlen=%d, requestid=%lld", @@ -180,7 +180,7 @@ static void timesync_onchannelcallback(void *context) icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; - VmbusChannelSendPacket(channel, buf, + vmbus_sendpacket(channel, buf, recvlen, requestid, VmbusPacketTypeDataInBand, 0); } @@ -205,16 +205,13 @@ static void heartbeat_onchannelcallback(void *context) buflen = PAGE_SIZE; buf = kmalloc(buflen, GFP_ATOMIC); - VmbusChannelRecvPacket(channel, buf, buflen, &recvlen, &requestid); + vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid); if (recvlen > 0) { DPRINT_DBG(VMBUS, "heartbeat packet: len=%d, requestid=%lld", recvlen, requestid); icmsghdrp = (struct icmsg_hdr *)&buf[ - sizeof(struct vmbuspipe_hdr)]; - - icmsghdrp = (struct icmsg_hdr *)&buf[ sizeof(struct vmbuspipe_hdr)]; if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { @@ -233,7 +230,7 @@ static void heartbeat_onchannelcallback(void *context) icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; - VmbusChannelSendPacket(channel, buf, + vmbus_sendpacket(channel, buf, recvlen, requestid, VmbusPacketTypeDataInBand, 0); } diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index 1d2ebbe17e2c..4c2632cb19e9 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -27,6 +27,7 @@ #include "logging.h" #include "netvsc.h" #include "rndis_filter.h" +#include "channel.h" /* Globals */ @@ -239,10 +240,9 @@ 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 = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device, - netDevice->ReceiveBuffer, - netDevice->ReceiveBufferSize, - &netDevice->ReceiveBufferGpadlHandle); + ret = vmbus_establish_gpadl(Device->channel, netDevice->ReceiveBuffer, + netDevice->ReceiveBufferSize, + &netDevice->ReceiveBufferGpadlHandle); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to establish receive buffer's gpadl"); @@ -263,12 +263,11 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; /* Send the gpadl notification request */ - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - initPacket, - sizeof(struct nvsp_message), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, initPacket, + sizeof(struct nvsp_message), + (unsigned long)initPacket, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send receive buffer's gpadl to netvsp"); @@ -368,10 +367,9 @@ 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 = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device, - netDevice->SendBuffer, - netDevice->SendBufferSize, - &netDevice->SendBufferGpadlHandle); + ret = vmbus_establish_gpadl(Device->channel, netDevice->SendBuffer, + netDevice->SendBufferSize, + &netDevice->SendBufferGpadlHandle); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl"); goto Cleanup; @@ -391,11 +389,11 @@ static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device) initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_SEND_BUFFER_ID; /* Send the gpadl notification request */ - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - initPacket, sizeof(struct nvsp_message), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, initPacket, + sizeof(struct nvsp_message), + (unsigned long)initPacket, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send receive buffer's gpadl to netvsp"); @@ -447,12 +445,10 @@ static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice) revokePacket->Header.MessageType = NvspMessage1TypeRevokeReceiveBuffer; revokePacket->Messages.Version1Messages.RevokeReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; - ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket( - NetDevice->Device, - revokePacket, - sizeof(struct nvsp_message), - (unsigned long)revokePacket, - VmbusPacketTypeDataInBand, 0); + ret = vmbus_sendpacket(NetDevice->Device->channel, revokePacket, + sizeof(struct nvsp_message), + (unsigned long)revokePacket, + VmbusPacketTypeDataInBand, 0); /* * If we failed here, we might as well return and * have a leak rather than continue and a bugchk @@ -468,9 +464,8 @@ static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice) if (NetDevice->ReceiveBufferGpadlHandle) { DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL..."); - ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl( - NetDevice->Device, - NetDevice->ReceiveBufferGpadlHandle); + ret = vmbus_teardown_gpadl(NetDevice->Device->channel, + NetDevice->ReceiveBufferGpadlHandle); /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */ if (ret != 0) { @@ -521,11 +516,10 @@ static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice) revokePacket->Header.MessageType = NvspMessage1TypeRevokeSendBuffer; revokePacket->Messages.Version1Messages.RevokeSendBuffer.Id = NETVSC_SEND_BUFFER_ID; - ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device, - revokePacket, - sizeof(struct nvsp_message), - (unsigned long)revokePacket, - VmbusPacketTypeDataInBand, 0); + ret = vmbus_sendpacket(NetDevice->Device->channel, revokePacket, + sizeof(struct nvsp_message), + (unsigned long)revokePacket, + VmbusPacketTypeDataInBand, 0); /* * If we failed here, we might as well return and have a leak * rather than continue and a bugchk @@ -540,8 +534,8 @@ static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice) /* Teardown the gpadl on the vsp end */ if (NetDevice->SendBufferGpadlHandle) { DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL..."); - - ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(NetDevice->Device, NetDevice->SendBufferGpadlHandle); + ret = vmbus_teardown_gpadl(NetDevice->Device->channel, + NetDevice->SendBufferGpadlHandle); /* * If we failed here, we might as well return and have a leak @@ -592,12 +586,11 @@ static int NetVscConnectToVsp(struct hv_device *Device) DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit..."); /* Send the init request */ - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - initPacket, - sizeof(struct nvsp_message), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, initPacket, + sizeof(struct nvsp_message), + (unsigned long)initPacket, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send NvspMessageTypeInit"); @@ -642,11 +635,10 @@ static int NetVscConnectToVsp(struct hv_device *Device) ndisVersion & 0xFFFF; /* Send the init request */ - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - initPacket, - sizeof(struct nvsp_message), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, 0); + ret = vmbus_sendpacket(Device->channel, initPacket, + sizeof(struct nvsp_message), + (unsigned long)initPacket, + VmbusPacketTypeDataInBand, 0); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send NvspMessage1TypeSendNdisVersion"); @@ -725,12 +717,9 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) } /* Open the channel */ - ret = Device->Driver->VmbusChannelInterface.Open(Device, - netDriver->RingBufferSize, - netDriver->RingBufferSize, - NULL, 0, - NetVscOnChannelCallback, - Device); + ret = vmbus_open(Device->channel, netDriver->RingBufferSize, + netDriver->RingBufferSize, NULL, 0, + NetVscOnChannelCallback, Device); if (ret != 0) { DPRINT_ERR(NETVSC, "unable to open channel: %d", ret); @@ -746,7 +735,7 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) if (ret != 0) { DPRINT_ERR(NETVSC, "unable to connect to NetVSP - %d", ret); ret = -1; - goto Close; + goto close; } DPRINT_INFO(NETVSC, "*** NetVSC channel handshake result - %d ***", @@ -754,9 +743,9 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) return ret; -Close: +close: /* Now, we can close the channel safely */ - Device->Driver->VmbusChannelInterface.Close(Device); + vmbus_close(Device->channel); Cleanup: @@ -818,7 +807,7 @@ static int NetVscOnDeviceRemove(struct hv_device *Device) DPRINT_INFO(NETVSC, "net device (%p) safe to remove", netDevice); /* Now, we can close the channel safely */ - Device->Driver->VmbusChannelInterface.Close(Device); + vmbus_close(Device->channel); /* Release all resources */ list_for_each_entry_safe(netvscPacket, pos, @@ -914,19 +903,18 @@ static int NetVscOnSend(struct hv_device *Device, sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionSize = 0; if (Packet->PageBufferCount) { - ret = Device->Driver->VmbusChannelInterface.SendPacketPageBuffer( - Device, Packet->PageBuffers, - Packet->PageBufferCount, - &sendMessage, - sizeof(struct nvsp_message), - (unsigned long)Packet); + ret = vmbus_sendpacket_pagebuffer(Device->channel, + Packet->PageBuffers, + Packet->PageBufferCount, + &sendMessage, + sizeof(struct nvsp_message), + (unsigned long)Packet); } else { - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - &sendMessage, - sizeof(struct nvsp_message), - (unsigned long)Packet, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, &sendMessage, + sizeof(struct nvsp_message), + (unsigned long)Packet, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); } @@ -1154,11 +1142,9 @@ static void NetVscSendReceiveCompletion(struct hv_device *Device, retry_send_cmplt: /* Send the completion */ - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - &recvcompMessage, - sizeof(struct nvsp_message), - TransactionId, - VmbusPacketTypeCompletion, 0); + ret = vmbus_sendpacket(Device->channel, &recvcompMessage, + sizeof(struct nvsp_message), TransactionId, + VmbusPacketTypeCompletion, 0); if (ret == 0) { /* success */ /* no-op */ @@ -1263,9 +1249,8 @@ static void NetVscOnChannelCallback(void *Context) } do { - ret = device->Driver->VmbusChannelInterface.RecvPacketRaw( - device, buffer, bufferlen, - &bytesRecvd, &requestId); + ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen, + &bytesRecvd, &requestId); if (ret == 0) { if (bytesRecvd > 0) { DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx", diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c index 64a01147ecae..141535295a41 100644 --- a/drivers/staging/hv/netvsc_drv.c +++ b/drivers/staging/hv/netvsc_drv.c @@ -59,7 +59,7 @@ struct netvsc_driver_context { /* Need this many pages to handle worst case fragmented packet */ #define PACKET_PAGES_HIWATER (MAX_SKB_FRAGS + 2) -static int ring_size = roundup_pow_of_two(2*MAX_SKB_FRAGS+1); +static int ring_size = 128; module_param(ring_size, int, S_IRUGO); MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); @@ -495,8 +495,6 @@ static int netvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; int ret; - vmbus_get_interface(&net_drv_obj->Base.VmbusChannelInterface); - net_drv_obj->RingBufferSize = ring_size * PAGE_SIZE; net_drv_obj->OnReceiveCallback = netvsc_recv_callback; net_drv_obj->OnLinkStatusChanged = netvsc_linkstatus_callback; diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c index 6bd2ff138d24..19e87f689fa0 100644 --- a/drivers/staging/hv/storvsc.c +++ b/drivers/staging/hv/storvsc.c @@ -28,6 +28,7 @@ #include "storvsc_api.h" #include "vmbus_packet_format.h" #include "vstorage.h" +#include "channel.h" struct storvsc_request_extension { @@ -212,12 +213,11 @@ static int StorVscChannelInit(struct hv_device *Device) DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION..."); - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(struct vstor_packet), - (unsigned long)request, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, vstorPacket, + sizeof(struct vstor_packet), + (unsigned long)request, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION"); @@ -244,12 +244,11 @@ static int StorVscChannelInit(struct hv_device *Device) vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT; FILL_VMSTOR_REVISION(vstorPacket->Version.Revision); - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(struct vstor_packet), - (unsigned long)request, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, vstorPacket, + sizeof(struct vstor_packet), + (unsigned long)request, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION"); @@ -276,12 +275,11 @@ static int StorVscChannelInit(struct hv_device *Device) vstorPacket->StorageChannelProperties.PortNumber = storDevice->PortNumber; - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(struct vstor_packet), - (unsigned long)request, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, vstorPacket, + sizeof(struct vstor_packet), + (unsigned long)request, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, @@ -313,12 +311,11 @@ static int StorVscChannelInit(struct hv_device *Device) vstorPacket->Operation = VStorOperationEndInitialization; vstorPacket->Flags = REQUEST_COMPLETION_FLAG; - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(struct vstor_packet), - (unsigned long)request, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, vstorPacket, + sizeof(struct vstor_packet), + (unsigned long)request, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, @@ -451,10 +448,9 @@ static void StorVscOnChannelCallback(void *context) } do { - ret = device->Driver->VmbusChannelInterface.RecvPacket(device, - packet, - ALIGN_UP(sizeof(struct vstor_packet), 8), - &bytesRecvd, &requestId); + ret = vmbus_recvpacket(device->channel, packet, + ALIGN_UP(sizeof(struct vstor_packet), 8), + &bytesRecvd, &requestId); if (ret == 0 && bytesRecvd > 0) { DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", bytesRecvd, requestId); @@ -503,13 +499,11 @@ static int StorVscConnectToVsp(struct hv_device *Device) memset(&props, 0, sizeof(struct vmstorage_channel_properties)); /* Open the channel */ - ret = Device->Driver->VmbusChannelInterface.Open(Device, - storDriver->RingBufferSize, - storDriver->RingBufferSize, - (void *)&props, - sizeof(struct vmstorage_channel_properties), - StorVscOnChannelCallback, - Device); + ret = vmbus_open(Device->channel, + storDriver->RingBufferSize, storDriver->RingBufferSize, + (void *)&props, + sizeof(struct vmstorage_channel_properties), + StorVscOnChannelCallback, Device); DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", props.PathId, props.TargetId, props.MaxTransferBytes); @@ -603,7 +597,7 @@ static int StorVscOnDeviceRemove(struct hv_device *Device) DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice); /* Close the channel */ - Device->Driver->VmbusChannelInterface.Close(Device); + vmbus_close(Device->channel); FreeStorDevice(storDevice); return 0; @@ -638,12 +632,11 @@ int StorVscOnHostReset(struct hv_device *Device) vstorPacket->Flags = REQUEST_COMPLETION_FLAG; vstorPacket->VmSrb.PathId = storDevice->PathId; - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(struct vstor_packet), - (unsigned long)&storDevice->ResetRequest, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, vstorPacket, + sizeof(struct vstor_packet), + (unsigned long)&storDevice->ResetRequest, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", vstorPacket, ret); @@ -735,19 +728,17 @@ static int StorVscOnIORequest(struct hv_device *Device, vstorPacket->VmSrb.CdbLength); if (requestExtension->Request->DataBuffer.Length) { - ret = Device->Driver->VmbusChannelInterface. - SendPacketMultiPageBuffer(Device, + ret = vmbus_sendpacket_multipagebuffer(Device->channel, &requestExtension->Request->DataBuffer, vstorPacket, sizeof(struct vstor_packet), (unsigned long)requestExtension); } else { - ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(struct vstor_packet), - (unsigned long)requestExtension, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(Device->channel, vstorPacket, + sizeof(struct vstor_packet), + (unsigned long)requestExtension, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); } if (ret != 0) { @@ -799,7 +790,7 @@ int StorVscInitialize(struct hv_driver *Driver) * Divide the ring buffer data size (which is 1 page less * than the ring buffer size since that page is reserved for * the ring buffer indices) by the max request size (which is - * VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + struct vstor_packet + u64) + * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) */ storDriver->MaxOutstandingRequestsPerChannel = ((storDriver->RingBufferSize - PAGE_SIZE) / diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c index 62882a437aa4..6f8d67d0d64f 100644 --- a/drivers/staging/hv/storvsc_drv.c +++ b/drivers/staging/hv/storvsc_drv.c @@ -72,8 +72,7 @@ struct storvsc_driver_context { /* Static decl */ static int storvsc_probe(struct device *dev); -static int storvsc_queuecommand(struct scsi_cmnd *scmnd, - void (*done)(struct scsi_cmnd *)); +static int storvsc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd); static int storvsc_device_alloc(struct scsi_device *); static int storvsc_device_configure(struct scsi_device *); static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd); @@ -141,8 +140,6 @@ 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; - vmbus_get_interface(&storvsc_drv_obj->Base.VmbusChannelInterface); - storvsc_drv_obj->RingBufferSize = storvsc_ringbuffer_size; /* Callback to client driver to complete the initialization */ @@ -597,7 +594,7 @@ static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl, /* * storvsc_queuecommand - Initiate command processing */ -static int storvsc_queuecommand(struct scsi_cmnd *scmnd, +static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, void (*done)(struct scsi_cmnd *)) { int ret; @@ -785,6 +782,8 @@ retry_request: return ret; } +static DEF_SCSI_QCMD(storvsc_queuecommand) + static int storvsc_merge_bvec(struct request_queue *q, struct bvec_merge_data *bmd, struct bio_vec *bvec) { diff --git a/drivers/staging/hv/vmbus.c b/drivers/staging/hv/vmbus.c index ca1e18a62006..d449daf81976 100644 --- a/drivers/staging/hv/vmbus.c +++ b/drivers/staging/hv/vmbus.c @@ -57,24 +57,7 @@ static struct hv_device *gDevice; /* vmbus root device */ */ static void VmbusGetChannelOffers(void) { - VmbusChannelRequestOffers(); -} - -/* - * VmbusGetChannelInterface - Get the channel interface - */ -static void VmbusGetChannelInterface(struct vmbus_channel_interface *Interface) -{ - GetChannelInterface(Interface); -} - -/* - * VmbusGetChannelInfo - Get the device info for the specified device object - */ -static void VmbusGetChannelInfo(struct hv_device *DeviceObject, - struct hv_device_info *DeviceInfo) -{ - GetChannelInfo(DeviceObject, DeviceInfo); + vmbus_request_offers(); } /* @@ -82,12 +65,12 @@ static void VmbusGetChannelInfo(struct hv_device *DeviceObject, */ struct hv_device *VmbusChildDeviceCreate(struct hv_guid *DeviceType, struct hv_guid *DeviceInstance, - void *Context) + struct vmbus_channel *channel) { struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver; return vmbusDriver->OnChildDeviceCreate(DeviceType, DeviceInstance, - Context); + channel); } /* @@ -142,7 +125,7 @@ static int VmbusOnDeviceRemove(struct hv_device *dev) { int ret = 0; - VmbusChannelReleaseUnattachedChannels(); + vmbus_release_unattached_channels(); VmbusDisconnect(); on_each_cpu(HvSynicCleanup, NULL, 1); return ret; @@ -179,7 +162,7 @@ static void VmbusOnMsgDPC(struct hv_driver *drv) continue; osd_schedule_callback(gVmbusConnection.WorkQueue, - VmbusOnChannelMessage, + vmbus_onmessage, (void *)copied); } @@ -263,10 +246,10 @@ int VmbusInitialize(struct hv_driver *drv) VMBUS_REVISION_NUMBER); DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++", VMBUS_MESSAGE_SINT); - DPRINT_DBG(VMBUS, "sizeof(VMBUS_CHANNEL_PACKET_PAGE_BUFFER)=%zd, " + 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_MULITPAGE_BUFFER)); + 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)); @@ -279,8 +262,6 @@ int VmbusInitialize(struct hv_driver *drv) driver->OnMsgDpc = VmbusOnMsgDPC; driver->OnEventDpc = VmbusOnEventDPC; driver->GetChannelOffers = VmbusGetChannelOffers; - driver->GetChannelInterface = VmbusGetChannelInterface; - driver->GetChannelInfo = VmbusGetChannelInfo; /* Hypervisor initialization...setup hypercall page..etc */ ret = HvInit(); diff --git a/drivers/staging/hv/vmbus.h b/drivers/staging/hv/vmbus.h index 3c14b2926e00..42f2adb99547 100644 --- a/drivers/staging/hv/vmbus.h +++ b/drivers/staging/hv/vmbus.h @@ -69,10 +69,8 @@ static inline struct driver_context *driver_to_driver_context(struct device_driv /* Vmbus interface */ - int vmbus_child_driver_register(struct driver_context *driver_ctx); void vmbus_child_driver_unregister(struct driver_context *driver_ctx); -void vmbus_get_interface(struct vmbus_channel_interface *interface); extern struct completion hv_channel_ready; diff --git a/drivers/staging/hv/vmbus_api.h b/drivers/staging/hv/vmbus_api.h index 4275be3292ce..2af42e550076 100644 --- a/drivers/staging/hv/vmbus_api.h +++ b/drivers/staging/hv/vmbus_api.h @@ -84,51 +84,6 @@ struct hv_device_info { struct hv_dev_port_info Outbound; }; -/** - * struct vmbus_channel_interface - Contains member functions for vmbus channel - * @Open: Open the channel - * @Close: Close the channel - * @SendPacket: Send a packet over the channel - * @SendPacketPageBuffer: Send a single page buffer over the channel - * @SendPacketMultiPageBuffer: Send a multiple page buffers - * @RecvPacket: Receive packet - * @RecvPacketRaw: Receive Raw packet - * @EstablishGpadl: Set up GPADL for ringbuffer - * @TeardownGpadl: Teardown GPADL for ringbuffer - * @GetInfo: Get info about the channel - * - * This structure contains function pointer to control vmbus channel - * behavior. None of these functions is externally callable, but they - * are used for normal vmbus channel internal behavior. - * Only used by Hyper-V drivers. - */ -struct vmbus_channel_interface { - int (*Open)(struct hv_device *Device, u32 SendBufferSize, - u32 RecvRingBufferSize, void *UserData, u32 UserDataLen, - void (*ChannelCallback)(void *context), - void *Context); - void (*Close)(struct hv_device *device); - int (*SendPacket)(struct hv_device *Device, const void *Buffer, - u32 BufferLen, u64 RequestId, u32 Type, u32 Flags); - int (*SendPacketPageBuffer)(struct hv_device *dev, - struct hv_page_buffer PageBuffers[], - u32 PageCount, void *Buffer, u32 BufferLen, - u64 RequestId); - int (*SendPacketMultiPageBuffer)(struct hv_device *device, - struct hv_multipage_buffer *mpb, - void *Buffer, - u32 BufferLen, - u64 RequestId); - int (*RecvPacket)(struct hv_device *dev, void *buf, u32 buflen, - u32 *BufferActualLen, u64 *RequestId); - int (*RecvPacketRaw)(struct hv_device *dev, void *buf, u32 buflen, - u32 *BufferActualLen, u64 *RequestId); - int (*EstablishGpadl)(struct hv_device *dev, void *buf, u32 buflen, - u32 *GpadlHandle); - int (*TeardownGpadl)(struct hv_device *device, u32 GpadlHandle); - void (*GetInfo)(struct hv_device *dev, struct hv_device_info *devinfo); -}; - /* Base driver object */ struct hv_driver { const char *name; @@ -139,8 +94,6 @@ struct hv_driver { int (*OnDeviceAdd)(struct hv_device *device, void *data); int (*OnDeviceRemove)(struct hv_device *device); void (*OnCleanup)(struct hv_driver *driver); - - struct vmbus_channel_interface VmbusChannelInterface; }; /* Base device object */ @@ -156,7 +109,7 @@ struct hv_device { /* the device instance id of this device */ struct hv_guid deviceInstance; - void *context; + struct vmbus_channel *channel; /* Device extension; */ void *Extension; @@ -171,7 +124,7 @@ struct vmbus_driver { /* Set by the caller */ struct hv_device * (*OnChildDeviceCreate)(struct hv_guid *DeviceType, struct hv_guid *DeviceInstance, - void *Context); + struct vmbus_channel *channel); void (*OnChildDeviceDestroy)(struct hv_device *device); int (*OnChildDeviceAdd)(struct hv_device *RootDevice, struct hv_device *ChildDevice); @@ -182,10 +135,6 @@ struct vmbus_driver { void (*OnMsgDpc)(struct hv_driver *driver); void (*OnEventDpc)(struct hv_driver *driver); void (*GetChannelOffers)(void); - - void (*GetChannelInterface)(struct vmbus_channel_interface *i); - void (*GetChannelInfo)(struct hv_device *dev, - struct hv_device_info *devinfo); }; int VmbusInitialize(struct hv_driver *drv); diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c index 092f02ed6be1..0d9f3a411e72 100644 --- a/drivers/staging/hv/vmbus_drv.c +++ b/drivers/staging/hv/vmbus_drv.c @@ -32,6 +32,7 @@ #include "osd.h" #include "logging.h" #include "vmbus.h" +#include "channel.h" /* FIXME! We need to do this dynamically for PIC and APIC system */ @@ -70,13 +71,11 @@ static void vmbus_bus_release(struct device *device); static struct hv_device *vmbus_child_device_create(struct hv_guid *type, struct hv_guid *instance, - void *context); + 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 void vmbus_child_device_get_info(struct hv_device *device_obj, - struct hv_device_info *device_info); static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf); @@ -130,6 +129,47 @@ static struct vmbus_driver_context g_vmbus_drv = { .bus.dev_attrs = vmbus_device_attrs, }; +static void get_channel_info(struct hv_device *device, + struct hv_device_info *info) +{ + struct vmbus_channel_debug_info debug_info; + + if (!device->channel) + return; + + vmbus_get_debug_info(device->channel, &debug_info); + + 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, + 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->Outbound.BytesAvailToWrite = + debug_info.Outbound.BytesAvailToWrite; +} + /* * vmbus_show_device_attr - Show the device attribute in sysfs. * @@ -145,7 +185,7 @@ static ssize_t vmbus_show_device_attr(struct device *dev, memset(&device_info, 0, sizeof(struct hv_device_info)); - vmbus_child_device_get_info(&device_ctx->device_obj, &device_info); + get_channel_info(&device_ctx->device_obj, &device_info); if (!strcmp(dev_attr->attr.name, "class_id")) { return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" @@ -445,45 +485,13 @@ void vmbus_child_driver_unregister(struct driver_context *driver_ctx) } EXPORT_SYMBOL(vmbus_child_driver_unregister); -/** - * vmbus_get_interface() - Get the vmbus channel interface. - * @interface: Pointer to channel interface structure - * - * Get the Hyper-V channel used for the driver. - * - * @interface is of type &struct vmbus_channel_interface - * This is invoked by child/client driver that sits above vmbus. - * - * Mainly used by Hyper-V drivers. - */ -void vmbus_get_interface(struct vmbus_channel_interface *interface) -{ - struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; - - vmbus_drv_obj->GetChannelInterface(interface); -} -EXPORT_SYMBOL(vmbus_get_interface); - -/* - * vmbus_child_device_get_info - Get the vmbus child device info. - * - * This is invoked to display various device attributes in sysfs. - */ -static void vmbus_child_device_get_info(struct hv_device *device_obj, - struct hv_device_info *device_info) -{ - struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; - - vmbus_drv_obj->GetChannelInfo(device_obj, device_info); -} - /* * 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, - void *context) + struct vmbus_channel *channel) { struct vm_device *child_device_ctx; struct hv_device *child_device_obj; @@ -516,7 +524,7 @@ static struct hv_device *vmbus_child_device_create(struct hv_guid *type, instance->data[14], instance->data[15]); child_device_obj = &child_device_ctx->device_obj; - child_device_obj->context = context; + child_device_obj->channel = channel; memcpy(&child_device_obj->deviceType, type, sizeof(struct hv_guid)); memcpy(&child_device_obj->deviceInstance, instance, sizeof(struct hv_guid)); diff --git a/drivers/staging/hv/vmbus_private.h b/drivers/staging/hv/vmbus_private.h index 588c667a7f6b..09eaec964b30 100644 --- a/drivers/staging/hv/vmbus_private.h +++ b/drivers/staging/hv/vmbus_private.h @@ -29,7 +29,6 @@ #include "vmbus_api.h" #include "channel.h" #include "channel_mgmt.h" -#include "channel_interface.h" #include "ring_buffer.h" #include <linux/list.h> @@ -105,7 +104,7 @@ extern struct VMBUS_CONNECTION gVmbusConnection; struct hv_device *VmbusChildDeviceCreate(struct hv_guid *deviceType, struct hv_guid *deviceInstance, - void *context); + struct vmbus_channel *channel); int VmbusChildDeviceAdd(struct hv_device *Device); |