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 | */ |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/mm.h> |
| 25 | #include <linux/vmalloc.h> |
Greg Kroah-Hartman | 4983b39 | 2009-08-19 16:14:47 -0700 | [diff] [blame] | 26 | #include "osd.h" |
Greg Kroah-Hartman | 645954c | 2009-08-28 16:22:59 -0700 | [diff] [blame] | 27 | #include "logging.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 28 | #include "VmbusPrivate.h" |
| 29 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 30 | |
Bill Pemberton | 662e66b | 2009-07-27 16:47:42 -0400 | [diff] [blame] | 31 | struct VMBUS_CONNECTION gVmbusConnection = { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 32 | .ConnectState = Disconnected, |
Bill Pemberton | f488841 | 2009-07-29 17:00:12 -0400 | [diff] [blame] | 33 | .NextGpadlHandle = ATOMIC_INIT(0xE1E10), |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 36 | /** |
| 37 | * VmbusConnect - Sends a connect request on the partition service connection |
| 38 | */ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 39 | int VmbusConnect(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 40 | { |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 41 | int ret = 0; |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 42 | struct vmbus_channel_msginfo *msgInfo = NULL; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 43 | struct vmbus_channel_initiate_contact *msg; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 44 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 45 | |
| 46 | DPRINT_ENTER(VMBUS); |
| 47 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 48 | /* Make sure we are not connecting or connected */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 49 | if (gVmbusConnection.ConnectState != Disconnected) |
| 50 | return -1; |
| 51 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 52 | /* Initialize the vmbus connection */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 53 | gVmbusConnection.ConnectState = Connecting; |
Bill Pemberton | de65a38 | 2009-07-29 17:00:09 -0400 | [diff] [blame] | 54 | gVmbusConnection.WorkQueue = create_workqueue("hv_vmbus_con"); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 55 | if (!gVmbusConnection.WorkQueue) { |
Bill Pemberton | de65a38 | 2009-07-29 17:00:09 -0400 | [diff] [blame] | 56 | ret = -1; |
| 57 | goto Cleanup; |
| 58 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 59 | |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 60 | INIT_LIST_HEAD(&gVmbusConnection.ChannelMsgList); |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 61 | spin_lock_init(&gVmbusConnection.channelmsg_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 62 | |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 63 | INIT_LIST_HEAD(&gVmbusConnection.ChannelList); |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 64 | spin_lock_init(&gVmbusConnection.channel_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 65 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 66 | /* |
| 67 | * Setup the vmbus event connection for channel interrupt |
| 68 | * abstraction stuff |
| 69 | */ |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 70 | gVmbusConnection.InterruptPage = osd_PageAlloc(1); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 71 | if (gVmbusConnection.InterruptPage == NULL) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 72 | ret = -1; |
| 73 | goto Cleanup; |
| 74 | } |
| 75 | |
| 76 | gVmbusConnection.RecvInterruptPage = gVmbusConnection.InterruptPage; |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 77 | gVmbusConnection.SendInterruptPage = |
| 78 | (void *)((unsigned long)gVmbusConnection.InterruptPage + |
| 79 | (PAGE_SIZE >> 1)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 80 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 81 | /* |
| 82 | * Setup the monitor notification facility. The 1st page for |
| 83 | * parent->child and the 2nd page for child->parent |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 84 | */ |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 85 | gVmbusConnection.MonitorPages = osd_PageAlloc(2); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 86 | if (gVmbusConnection.MonitorPages == NULL) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 87 | ret = -1; |
| 88 | goto Cleanup; |
| 89 | } |
| 90 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 91 | msgInfo = kzalloc(sizeof(*msgInfo) + |
| 92 | sizeof(struct vmbus_channel_initiate_contact), |
| 93 | GFP_KERNEL); |
| 94 | if (msgInfo == NULL) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 95 | ret = -1; |
| 96 | goto Cleanup; |
| 97 | } |
| 98 | |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 99 | msgInfo->WaitEvent = osd_WaitEventCreate(); |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 100 | msg = (struct vmbus_channel_initiate_contact *)msgInfo->Msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 101 | |
| 102 | msg->Header.MessageType = ChannelMessageInitiateContact; |
| 103 | msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER; |
Greg Kroah-Hartman | fa56d36 | 2009-07-29 15:39:27 -0700 | [diff] [blame] | 104 | msg->InterruptPage = virt_to_phys(gVmbusConnection.InterruptPage); |
| 105 | msg->MonitorPage1 = virt_to_phys(gVmbusConnection.MonitorPages); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 106 | msg->MonitorPage2 = virt_to_phys( |
| 107 | (void *)((unsigned long)gVmbusConnection.MonitorPages + |
| 108 | PAGE_SIZE)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 109 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 110 | /* |
| 111 | * Add to list before we send the request since we may |
| 112 | * receive the response before returning from this routine |
| 113 | */ |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 114 | spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 115 | list_add_tail(&msgInfo->MsgListEntry, |
| 116 | &gVmbusConnection.ChannelMsgList); |
| 117 | |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 118 | spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 119 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 120 | DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, " |
| 121 | "monitor1 pfn %llx,, monitor2 pfn %llx", |
| 122 | msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 123 | |
| 124 | DPRINT_DBG(VMBUS, "Sending channel initiate msg..."); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 125 | ret = VmbusPostMessage(msg, |
| 126 | sizeof(struct vmbus_channel_initiate_contact)); |
| 127 | if (ret != 0) { |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 128 | list_del(&msgInfo->MsgListEntry); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 129 | goto Cleanup; |
| 130 | } |
| 131 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 132 | /* Wait for the connection response */ |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 133 | osd_WaitEventWait(msgInfo->WaitEvent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 134 | |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 135 | list_del(&msgInfo->MsgListEntry); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 136 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 137 | /* Check if successful */ |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 138 | if (msgInfo->Response.VersionResponse.VersionSupported) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 139 | DPRINT_INFO(VMBUS, "Vmbus connected!!"); |
| 140 | gVmbusConnection.ConnectState = Connected; |
| 141 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 142 | } else { |
| 143 | DPRINT_ERR(VMBUS, "Vmbus connection failed!!..." |
| 144 | "current version (%d) not supported", |
| 145 | VMBUS_REVISION_NUMBER); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 146 | ret = -1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 147 | goto Cleanup; |
| 148 | } |
| 149 | |
Bill Pemberton | 420beac | 2009-07-29 17:00:10 -0400 | [diff] [blame] | 150 | kfree(msgInfo->WaitEvent); |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 151 | kfree(msgInfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 152 | DPRINT_EXIT(VMBUS); |
| 153 | |
| 154 | return 0; |
| 155 | |
| 156 | Cleanup: |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 157 | gVmbusConnection.ConnectState = Disconnected; |
| 158 | |
Bill Pemberton | de65a38 | 2009-07-29 17:00:09 -0400 | [diff] [blame] | 159 | if (gVmbusConnection.WorkQueue) |
| 160 | destroy_workqueue(gVmbusConnection.WorkQueue); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 161 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 162 | if (gVmbusConnection.InterruptPage) { |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 163 | osd_PageFree(gVmbusConnection.InterruptPage, 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 164 | gVmbusConnection.InterruptPage = NULL; |
| 165 | } |
| 166 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 167 | if (gVmbusConnection.MonitorPages) { |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 168 | osd_PageFree(gVmbusConnection.MonitorPages, 2); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 169 | gVmbusConnection.MonitorPages = NULL; |
| 170 | } |
| 171 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 172 | if (msgInfo) { |
| 173 | kfree(msgInfo->WaitEvent); |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 174 | kfree(msgInfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | DPRINT_EXIT(VMBUS); |
| 178 | |
| 179 | return ret; |
| 180 | } |
| 181 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 182 | /** |
| 183 | * VmbusDisconnect - Sends a disconnect request on the partition service connection |
| 184 | */ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 185 | int VmbusDisconnect(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 186 | { |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 187 | int ret = 0; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 188 | struct vmbus_channel_message_header *msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 189 | |
| 190 | DPRINT_ENTER(VMBUS); |
| 191 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 192 | /* Make sure we are connected */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 193 | if (gVmbusConnection.ConnectState != Connected) |
| 194 | return -1; |
| 195 | |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 196 | msg = kzalloc(sizeof(struct vmbus_channel_message_header), GFP_KERNEL); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 197 | |
| 198 | msg->MessageType = ChannelMessageUnload; |
| 199 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 200 | ret = VmbusPostMessage(msg, |
| 201 | sizeof(struct vmbus_channel_message_header)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 202 | if (ret != 0) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 203 | goto Cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 204 | |
Greg Kroah-Hartman | bfc30aa | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 205 | osd_PageFree(gVmbusConnection.InterruptPage, 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 206 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 207 | /* TODO: iterate thru the msg list and free up */ |
Bill Pemberton | de65a38 | 2009-07-29 17:00:09 -0400 | [diff] [blame] | 208 | destroy_workqueue(gVmbusConnection.WorkQueue); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 209 | |
| 210 | gVmbusConnection.ConnectState = Disconnected; |
| 211 | |
| 212 | DPRINT_INFO(VMBUS, "Vmbus disconnected!!"); |
| 213 | |
| 214 | Cleanup: |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 215 | kfree(msg); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 216 | DPRINT_EXIT(VMBUS); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 217 | return ret; |
| 218 | } |
| 219 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 220 | /** |
| 221 | * GetChannelFromRelId - Get the channel object given its child relative id (ie channel id) |
| 222 | */ |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 223 | struct vmbus_channel *GetChannelFromRelId(u32 relId) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 224 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 225 | struct vmbus_channel *channel; |
| 226 | struct vmbus_channel *foundChannel = NULL; |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 227 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 228 | |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 229 | spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 230 | list_for_each_entry(channel, &gVmbusConnection.ChannelList, ListEntry) { |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 231 | if (channel->OfferMsg.ChildRelId == relId) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 232 | foundChannel = channel; |
| 233 | break; |
| 234 | } |
| 235 | } |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 236 | spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 237 | |
| 238 | return foundChannel; |
| 239 | } |
| 240 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 241 | /** |
| 242 | * VmbusProcessChannelEvent - Process a channel event notification |
| 243 | */ |
| 244 | static void VmbusProcessChannelEvent(void *context) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 245 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 246 | struct vmbus_channel *channel; |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 247 | u32 relId = (u32)(unsigned long)context; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 248 | |
| 249 | ASSERT(relId > 0); |
| 250 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 251 | /* |
| 252 | * Find the channel based on this relid and invokes the |
| 253 | * channel callback to process the event |
| 254 | */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 255 | channel = GetChannelFromRelId(relId); |
| 256 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 257 | if (channel) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 258 | VmbusChannelOnChannelEvent(channel); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 259 | /* |
| 260 | * WorkQueueQueueWorkItem(channel->dataWorkQueue, |
| 261 | * VmbusChannelOnChannelEvent, |
| 262 | * (void*)channel); |
| 263 | */ |
| 264 | } else { |
| 265 | DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 269 | /** |
| 270 | * VmbusOnEvents - Handler for events |
| 271 | */ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 272 | void VmbusOnEvents(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 273 | { |
| 274 | int dword; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 275 | int maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; |
| 276 | int bit; |
| 277 | int relid; |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 278 | u32 *recvInterruptPage = gVmbusConnection.RecvInterruptPage; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 279 | |
| 280 | DPRINT_ENTER(VMBUS); |
| 281 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 282 | /* Check events */ |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 283 | if (recvInterruptPage) { |
| 284 | for (dword = 0; dword < maxdword; dword++) { |
| 285 | if (recvInterruptPage[dword]) { |
| 286 | for (bit = 0; bit < 32; bit++) { |
| 287 | if (test_and_clear_bit(bit, (unsigned long *)&recvInterruptPage[dword])) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 288 | relid = (dword << 5) + bit; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 289 | DPRINT_DBG(VMBUS, "event detected for relid - %d", relid); |
| 290 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 291 | if (relid == 0) { |
| 292 | /* special case - vmbus channel protocol msg */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 293 | DPRINT_DBG(VMBUS, "invalid relid - %d", relid); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 294 | continue; |
| 295 | } else { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 296 | /* QueueWorkItem(VmbusProcessEvent, (void*)relid); */ |
| 297 | /* ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid); */ |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 298 | VmbusProcessChannelEvent((void *)(unsigned long)relid); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | DPRINT_EXIT(VMBUS); |
| 306 | |
| 307 | return; |
| 308 | } |
| 309 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 310 | /** |
| 311 | * VmbusPostMessage - Send a msg on the vmbus's message connection |
| 312 | */ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 313 | int VmbusPostMessage(void *buffer, size_t bufferLen) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 314 | { |
Greg Kroah-Hartman | eacb1b4 | 2009-08-20 12:11:26 -0700 | [diff] [blame] | 315 | union hv_connection_id connId; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 316 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 317 | connId.Asu32 = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 318 | connId.u.Id = VMBUS_MESSAGE_CONNECTION_ID; |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 319 | return HvPostMessage(connId, 1, buffer, bufferLen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 322 | /** |
| 323 | * VmbusSetEvent - Send an event notification to the parent |
| 324 | */ |
Greg Kroah-Hartman | f346fdc | 2009-08-17 17:23:00 -0700 | [diff] [blame] | 325 | int VmbusSetEvent(u32 childRelId) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 326 | { |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 327 | int ret = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 328 | |
| 329 | DPRINT_ENTER(VMBUS); |
| 330 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 331 | /* Each u32 represents 32 channels */ |
Bill Pemberton | 7c369f4 | 2009-07-29 17:00:11 -0400 | [diff] [blame] | 332 | set_bit(childRelId & 31, |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 333 | (unsigned long *)gVmbusConnection.SendInterruptPage + |
| 334 | (childRelId >> 5)); |
Bill Pemberton | 7c369f4 | 2009-07-29 17:00:11 -0400 | [diff] [blame] | 335 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 336 | ret = HvSignalEvent(); |
| 337 | |
| 338 | DPRINT_EXIT(VMBUS); |
| 339 | |
| 340 | return ret; |
| 341 | } |