Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2009, Microsoft Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 16 | * Place - Suite 330, Boston, MA 02111-1307 USA. |
| 17 | * |
| 18 | * Authors: |
| 19 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 20 | * Hank Janssen <hjanssen@microsoft.com> |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/mm.h> |
| 27 | #include <linux/vmalloc.h> |
Greg Kroah-Hartman | 4983b39 | 2009-08-19 16:14:47 -0700 | [diff] [blame] | 28 | #include "osd.h" |
Greg Kroah-Hartman | 645954c | 2009-08-28 16:22:59 -0700 | [diff] [blame] | 29 | #include "logging.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 30 | #include "VmbusPrivate.h" |
| 31 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 32 | /* Globals */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 33 | |
| 34 | |
Bill Pemberton | 662e66b | 2009-07-27 16:47:42 -0400 | [diff] [blame] | 35 | struct VMBUS_CONNECTION gVmbusConnection = { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 36 | .ConnectState = Disconnected, |
Bill Pemberton | f488841 | 2009-07-29 17:00:12 -0400 | [diff] [blame] | 37 | .NextGpadlHandle = ATOMIC_INIT(0xE1E10), |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | |
| 41 | /*++ |
| 42 | |
| 43 | Name: |
| 44 | VmbusConnect() |
| 45 | |
| 46 | Description: |
| 47 | Sends a connect request on the partition service connection |
| 48 | |
| 49 | --*/ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 50 | int VmbusConnect(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 51 | { |
| 52 | int ret=0; |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 53 | struct vmbus_channel_msginfo *msgInfo = NULL; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 54 | struct vmbus_channel_initiate_contact *msg; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 55 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 56 | |
| 57 | DPRINT_ENTER(VMBUS); |
| 58 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 59 | /* Make sure we are not connecting or connected */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 60 | if (gVmbusConnection.ConnectState != Disconnected) |
| 61 | return -1; |
| 62 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 63 | /* Initialize the vmbus connection */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 64 | gVmbusConnection.ConnectState = Connecting; |
Bill Pemberton | de65a38 | 2009-07-29 17:00:09 -0400 | [diff] [blame] | 65 | gVmbusConnection.WorkQueue = create_workqueue("hv_vmbus_con"); |
| 66 | if (!gVmbusConnection.WorkQueue) |
| 67 | { |
| 68 | ret = -1; |
| 69 | goto Cleanup; |
| 70 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 71 | |
| 72 | INITIALIZE_LIST_HEAD(&gVmbusConnection.ChannelMsgList); |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 73 | spin_lock_init(&gVmbusConnection.channelmsg_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 74 | |
| 75 | INITIALIZE_LIST_HEAD(&gVmbusConnection.ChannelList); |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 76 | spin_lock_init(&gVmbusConnection.channel_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 77 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 78 | /* |
| 79 | * Setup the vmbus event connection for channel interrupt |
| 80 | * abstraction stuff |
| 81 | */ |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 82 | gVmbusConnection.InterruptPage = osd_PageAlloc(1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 83 | if (gVmbusConnection.InterruptPage == NULL) |
| 84 | { |
| 85 | ret = -1; |
| 86 | goto Cleanup; |
| 87 | } |
| 88 | |
| 89 | gVmbusConnection.RecvInterruptPage = gVmbusConnection.InterruptPage; |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 90 | gVmbusConnection.SendInterruptPage = (void*)((unsigned long)gVmbusConnection.InterruptPage + (PAGE_SIZE >> 1)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 91 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 92 | /* Setup the monitor |
| 93 | * notification facility. The 1st page for parent->child and |
| 94 | * the 2nd page for child->parent |
| 95 | */ |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 96 | gVmbusConnection.MonitorPages = osd_PageAlloc(2); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 97 | if (gVmbusConnection.MonitorPages == NULL) |
| 98 | { |
| 99 | ret = -1; |
| 100 | goto Cleanup; |
| 101 | } |
| 102 | |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 103 | msgInfo = kzalloc(sizeof(*msgInfo) + sizeof(struct vmbus_channel_initiate_contact), GFP_KERNEL); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 104 | if (msgInfo == NULL) |
| 105 | { |
| 106 | ret = -1; |
| 107 | goto Cleanup; |
| 108 | } |
| 109 | |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 110 | msgInfo->WaitEvent = osd_WaitEventCreate(); |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 111 | msg = (struct vmbus_channel_initiate_contact *)msgInfo->Msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 112 | |
| 113 | msg->Header.MessageType = ChannelMessageInitiateContact; |
| 114 | msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER; |
Greg Kroah-Hartman | fa56d36 | 2009-07-29 15:39:27 -0700 | [diff] [blame] | 115 | msg->InterruptPage = virt_to_phys(gVmbusConnection.InterruptPage); |
| 116 | msg->MonitorPage1 = virt_to_phys(gVmbusConnection.MonitorPages); |
| 117 | msg->MonitorPage2 = virt_to_phys((void *)((unsigned long)gVmbusConnection.MonitorPages + PAGE_SIZE)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 118 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 119 | /* |
| 120 | * Add to list before we send the request since we may |
| 121 | * receive the response before returning from this routine |
| 122 | */ |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 123 | spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 124 | INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry); |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 125 | spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 126 | |
| 127 | DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, monitor1 pfn %llx,, monitor2 pfn %llx", |
| 128 | msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2); |
| 129 | |
| 130 | DPRINT_DBG(VMBUS, "Sending channel initiate msg..."); |
| 131 | |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 132 | ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_initiate_contact)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 133 | if (ret != 0) |
| 134 | { |
| 135 | REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry); |
| 136 | goto Cleanup; |
| 137 | } |
| 138 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 139 | /* Wait for the connection response */ |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 140 | osd_WaitEventWait(msgInfo->WaitEvent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 141 | |
| 142 | REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry); |
| 143 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 144 | /* Check if successful */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 145 | if (msgInfo->Response.VersionResponse.VersionSupported) |
| 146 | { |
| 147 | DPRINT_INFO(VMBUS, "Vmbus connected!!"); |
| 148 | gVmbusConnection.ConnectState = Connected; |
| 149 | |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | DPRINT_ERR(VMBUS, "Vmbus connection failed!!...current version (%d) not supported", VMBUS_REVISION_NUMBER); |
| 154 | ret = -1; |
| 155 | |
| 156 | goto Cleanup; |
| 157 | } |
| 158 | |
| 159 | |
Bill Pemberton | 420beac | 2009-07-29 17:00:10 -0400 | [diff] [blame] | 160 | kfree(msgInfo->WaitEvent); |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 161 | kfree(msgInfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 162 | DPRINT_EXIT(VMBUS); |
| 163 | |
| 164 | return 0; |
| 165 | |
| 166 | Cleanup: |
| 167 | |
| 168 | gVmbusConnection.ConnectState = Disconnected; |
| 169 | |
Bill Pemberton | de65a38 | 2009-07-29 17:00:09 -0400 | [diff] [blame] | 170 | if (gVmbusConnection.WorkQueue) |
| 171 | destroy_workqueue(gVmbusConnection.WorkQueue); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 172 | |
| 173 | if (gVmbusConnection.InterruptPage) |
| 174 | { |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 175 | osd_PageFree(gVmbusConnection.InterruptPage, 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 176 | gVmbusConnection.InterruptPage = NULL; |
| 177 | } |
| 178 | |
| 179 | if (gVmbusConnection.MonitorPages) |
| 180 | { |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 181 | osd_PageFree(gVmbusConnection.MonitorPages, 2); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 182 | gVmbusConnection.MonitorPages = NULL; |
| 183 | } |
| 184 | |
| 185 | if (msgInfo) |
| 186 | { |
| 187 | if (msgInfo->WaitEvent) |
Bill Pemberton | 420beac | 2009-07-29 17:00:10 -0400 | [diff] [blame] | 188 | kfree(msgInfo->WaitEvent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 189 | |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 190 | kfree(msgInfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | DPRINT_EXIT(VMBUS); |
| 194 | |
| 195 | return ret; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | /*++ |
| 200 | |
| 201 | Name: |
| 202 | VmbusDisconnect() |
| 203 | |
| 204 | Description: |
| 205 | Sends a disconnect request on the partition service connection |
| 206 | |
| 207 | --*/ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 208 | int VmbusDisconnect(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 209 | { |
| 210 | int ret=0; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 211 | struct vmbus_channel_message_header *msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 212 | |
| 213 | DPRINT_ENTER(VMBUS); |
| 214 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 215 | /* Make sure we are connected */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 216 | if (gVmbusConnection.ConnectState != Connected) |
| 217 | return -1; |
| 218 | |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 219 | msg = kzalloc(sizeof(struct vmbus_channel_message_header), GFP_KERNEL); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 220 | |
| 221 | msg->MessageType = ChannelMessageUnload; |
| 222 | |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 223 | ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_message_header)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 224 | |
| 225 | if (ret != 0) |
| 226 | { |
| 227 | goto Cleanup; |
| 228 | } |
| 229 | |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 230 | osd_PageFree(gVmbusConnection.InterruptPage, 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 231 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 232 | /* TODO: iterate thru the msg list and free up */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 233 | |
Bill Pemberton | de65a38 | 2009-07-29 17:00:09 -0400 | [diff] [blame] | 234 | destroy_workqueue(gVmbusConnection.WorkQueue); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 235 | |
| 236 | gVmbusConnection.ConnectState = Disconnected; |
| 237 | |
| 238 | DPRINT_INFO(VMBUS, "Vmbus disconnected!!"); |
| 239 | |
| 240 | Cleanup: |
| 241 | if (msg) |
| 242 | { |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 243 | kfree(msg); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | DPRINT_EXIT(VMBUS); |
| 247 | |
| 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | |
| 252 | /*++ |
| 253 | |
| 254 | Name: |
| 255 | GetChannelFromRelId() |
| 256 | |
| 257 | Description: |
| 258 | Get the channel object given its child relative id (ie channel id) |
| 259 | |
| 260 | --*/ |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 261 | struct vmbus_channel *GetChannelFromRelId(u32 relId) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 262 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 263 | struct vmbus_channel *channel; |
| 264 | struct vmbus_channel *foundChannel = NULL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 265 | LIST_ENTRY* anchor; |
| 266 | LIST_ENTRY* curr; |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 267 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 268 | |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 269 | spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 270 | ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList) |
| 271 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 272 | channel = CONTAINING_RECORD(curr, struct vmbus_channel, ListEntry); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 273 | |
| 274 | if (channel->OfferMsg.ChildRelId == relId) |
| 275 | { |
| 276 | foundChannel = channel; |
| 277 | break; |
| 278 | } |
| 279 | } |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 280 | spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 281 | |
| 282 | return foundChannel; |
| 283 | } |
| 284 | |
| 285 | |
| 286 | |
| 287 | /*++ |
| 288 | |
| 289 | Name: |
| 290 | VmbusProcessChannelEvent() |
| 291 | |
| 292 | Description: |
| 293 | Process a channel event notification |
| 294 | |
| 295 | --*/ |
| 296 | static void |
| 297 | VmbusProcessChannelEvent( |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 298 | void * context |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 299 | ) |
| 300 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 301 | struct vmbus_channel *channel; |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 302 | u32 relId = (u32)(unsigned long)context; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 303 | |
| 304 | ASSERT(relId > 0); |
| 305 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 306 | /* |
| 307 | * Find the channel based on this relid and invokes the |
| 308 | * channel callback to process the event |
| 309 | */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 310 | channel = GetChannelFromRelId(relId); |
| 311 | |
| 312 | if (channel) |
| 313 | { |
| 314 | VmbusChannelOnChannelEvent(channel); |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 315 | /* WorkQueueQueueWorkItem(channel->dataWorkQueue, VmbusChannelOnChannelEvent, (void*)channel); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 316 | } |
| 317 | else |
| 318 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 319 | DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
| 323 | |
| 324 | /*++ |
| 325 | |
| 326 | Name: |
| 327 | VmbusOnEvents() |
| 328 | |
| 329 | Description: |
| 330 | Handler for events |
| 331 | |
| 332 | --*/ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 333 | void VmbusOnEvents(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 334 | { |
| 335 | int dword; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 336 | /* int maxdword = PAGE_SIZE >> 3; // receive size is 1/2 page and divide that by 4 bytes */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 337 | int maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; |
| 338 | int bit; |
| 339 | int relid; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 340 | u32* recvInterruptPage = gVmbusConnection.RecvInterruptPage; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 341 | /* VMBUS_CHANNEL_MESSAGE* receiveMsg; */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 342 | |
| 343 | DPRINT_ENTER(VMBUS); |
| 344 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 345 | /* Check events */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 346 | if (recvInterruptPage) |
| 347 | { |
| 348 | for (dword = 0; dword < maxdword; dword++) |
| 349 | { |
| 350 | if (recvInterruptPage[dword]) |
| 351 | { |
| 352 | for (bit = 0; bit < 32; bit++) |
| 353 | { |
Bill Pemberton | 7c369f4 | 2009-07-29 17:00:11 -0400 | [diff] [blame] | 354 | if (test_and_clear_bit(bit, (unsigned long *) &recvInterruptPage[dword])) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 355 | { |
| 356 | relid = (dword << 5) + bit; |
| 357 | |
| 358 | DPRINT_DBG(VMBUS, "event detected for relid - %d", relid); |
| 359 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 360 | if (relid == 0) /* special case - vmbus channel protocol msg */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 361 | { |
| 362 | DPRINT_DBG(VMBUS, "invalid relid - %d", relid); |
| 363 | |
| 364 | continue; } |
| 365 | else |
| 366 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 367 | /* QueueWorkItem(VmbusProcessEvent, (void*)relid); */ |
| 368 | /* ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid); */ |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 369 | VmbusProcessChannelEvent((void*)(unsigned long)relid); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | DPRINT_EXIT(VMBUS); |
| 377 | |
| 378 | return; |
| 379 | } |
| 380 | |
| 381 | /*++ |
| 382 | |
| 383 | Name: |
| 384 | VmbusPostMessage() |
| 385 | |
| 386 | Description: |
| 387 | Send a msg on the vmbus's message connection |
| 388 | |
| 389 | --*/ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 390 | int VmbusPostMessage(void *buffer, size_t bufferLen) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 391 | { |
| 392 | int ret=0; |
Greg Kroah-Hartman | eacb1b4 | 2009-08-20 12:11:26 -0700 | [diff] [blame] | 393 | union hv_connection_id connId; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 394 | |
| 395 | |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 396 | connId.Asu32 =0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 397 | connId.u.Id = VMBUS_MESSAGE_CONNECTION_ID; |
| 398 | ret = HvPostMessage( |
| 399 | connId, |
| 400 | 1, |
| 401 | buffer, |
| 402 | bufferLen); |
| 403 | |
| 404 | return ret; |
| 405 | } |
| 406 | |
| 407 | /*++ |
| 408 | |
| 409 | Name: |
| 410 | VmbusSetEvent() |
| 411 | |
| 412 | Description: |
| 413 | Send an event notification to the parent |
| 414 | |
| 415 | --*/ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 416 | int VmbusSetEvent(u32 childRelId) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 417 | { |
| 418 | int ret=0; |
| 419 | |
| 420 | DPRINT_ENTER(VMBUS); |
| 421 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 422 | /* Each u32 represents 32 channels */ |
Bill Pemberton | 7c369f4 | 2009-07-29 17:00:11 -0400 | [diff] [blame] | 423 | set_bit(childRelId & 31, |
| 424 | (unsigned long *) gVmbusConnection.SendInterruptPage + (childRelId >> 5)); |
| 425 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 426 | ret = HvSignalEvent(); |
| 427 | |
| 428 | DPRINT_EXIT(VMBUS); |
| 429 | |
| 430 | return ret; |
| 431 | } |
| 432 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 433 | /* EOF */ |