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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 26 | #include <linux/vmalloc.h> |
Greg Kroah-Hartman | 4983b39 | 2009-08-19 16:14:47 -0700 | [diff] [blame] | 27 | #include "osd.h" |
Greg Kroah-Hartman | 645954c | 2009-08-28 16:22:59 -0700 | [diff] [blame] | 28 | #include "logging.h" |
Greg Kroah-Hartman | 72daf32 | 2010-05-05 22:45:25 -0700 | [diff] [blame] | 29 | #include "vmbus_private.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 30 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 31 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 32 | struct vmbus_connection vmbus_connection = { |
| 33 | .conn_state = DISCONNECTED, |
| 34 | .next_gpadl_handle = ATOMIC_INIT(0xE1E10), |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 37 | /* |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 38 | * vmbus_connect - Sends a connect request on the partition service connection |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 39 | */ |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 40 | int vmbus_connect(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 41 | { |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 42 | int ret = 0; |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 43 | struct vmbus_channel_msginfo *msginfo = NULL; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 44 | struct vmbus_channel_initiate_contact *msg; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 45 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 46 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 47 | /* Make sure we are not connecting or connected */ |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 48 | if (vmbus_connection.conn_state != DISCONNECTED) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 49 | return -1; |
| 50 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 51 | /* Initialize the vmbus connection */ |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 52 | vmbus_connection.conn_state = CONNECTING; |
| 53 | vmbus_connection.work_queue = create_workqueue("hv_vmbus_con"); |
| 54 | if (!vmbus_connection.work_queue) { |
Bill Pemberton | de65a38 | 2009-07-29 17:00:09 -0400 | [diff] [blame] | 55 | ret = -1; |
| 56 | goto Cleanup; |
| 57 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 58 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 59 | INIT_LIST_HEAD(&vmbus_connection.chn_msg_list); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 60 | spin_lock_init(&vmbus_connection.channelmsg_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 61 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 62 | INIT_LIST_HEAD(&vmbus_connection.chn_list); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 63 | spin_lock_init(&vmbus_connection.channel_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 64 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 65 | /* |
| 66 | * Setup the vmbus event connection for channel interrupt |
| 67 | * abstraction stuff |
| 68 | */ |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame^] | 69 | vmbus_connection.int_page = |
| 70 | (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, 0); |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 71 | if (vmbus_connection.int_page == NULL) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 72 | ret = -1; |
| 73 | goto Cleanup; |
| 74 | } |
| 75 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 76 | vmbus_connection.recv_int_page = vmbus_connection.int_page; |
| 77 | vmbus_connection.send_int_page = |
| 78 | (void *)((unsigned long)vmbus_connection.int_page + |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 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 | */ |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame^] | 85 | vmbus_connection.monitor_pages = |
| 86 | (void *)__get_free_pages((GFP_KERNEL|__GFP_ZERO), 1); |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 87 | if (vmbus_connection.monitor_pages == NULL) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 88 | ret = -1; |
| 89 | goto Cleanup; |
| 90 | } |
| 91 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 92 | msginfo = kzalloc(sizeof(*msginfo) + |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 93 | sizeof(struct vmbus_channel_initiate_contact), |
| 94 | GFP_KERNEL); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 95 | if (msginfo == NULL) { |
Bill Pemberton | 8cad0af | 2010-05-05 15:27:32 -0400 | [diff] [blame] | 96 | ret = -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 97 | goto Cleanup; |
| 98 | } |
| 99 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 100 | msginfo->waitevent = osd_waitevent_create(); |
| 101 | if (!msginfo->waitevent) { |
Bill Pemberton | 80d11b2 | 2010-05-05 15:27:33 -0400 | [diff] [blame] | 102 | ret = -ENOMEM; |
| 103 | goto Cleanup; |
| 104 | } |
| 105 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 106 | msg = (struct vmbus_channel_initiate_contact *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 107 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 108 | msg->header.msgtype = CHANNELMSG_INITIATE_CONTACT; |
| 109 | msg->vmbus_version_requested = VMBUS_REVISION_NUMBER; |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 110 | msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); |
| 111 | msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 112 | msg->monitor_page2 = virt_to_phys( |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 113 | (void *)((unsigned long)vmbus_connection.monitor_pages + |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 114 | PAGE_SIZE)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 115 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 116 | /* |
| 117 | * Add to list before we send the request since we may |
| 118 | * receive the response before returning from this routine |
| 119 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 120 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
| 121 | list_add_tail(&msginfo->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 122 | &vmbus_connection.chn_msg_list); |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 123 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 124 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 125 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 126 | DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, " |
| 127 | "monitor1 pfn %llx,, monitor2 pfn %llx", |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 128 | msg->interrupt_page, msg->monitor_page1, msg->monitor_page2); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 129 | |
| 130 | DPRINT_DBG(VMBUS, "Sending channel initiate msg..."); |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 131 | ret = vmbus_post_msg(msg, |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 132 | sizeof(struct vmbus_channel_initiate_contact)); |
| 133 | if (ret != 0) { |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 134 | list_del(&msginfo->msglistentry); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 135 | goto Cleanup; |
| 136 | } |
| 137 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 138 | /* Wait for the connection response */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 139 | osd_waitevent_wait(msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 140 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 141 | list_del(&msginfo->msglistentry); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 142 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 143 | /* Check if successful */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 144 | if (msginfo->response.version_response.version_supported) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 145 | DPRINT_INFO(VMBUS, "Vmbus connected!!"); |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 146 | vmbus_connection.conn_state = CONNECTED; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 147 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 148 | } else { |
| 149 | DPRINT_ERR(VMBUS, "Vmbus connection failed!!..." |
| 150 | "current version (%d) not supported", |
| 151 | VMBUS_REVISION_NUMBER); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 152 | ret = -1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 153 | goto Cleanup; |
| 154 | } |
| 155 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 156 | kfree(msginfo->waitevent); |
| 157 | kfree(msginfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 158 | return 0; |
| 159 | |
| 160 | Cleanup: |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 161 | vmbus_connection.conn_state = DISCONNECTED; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 162 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 163 | if (vmbus_connection.work_queue) |
| 164 | destroy_workqueue(vmbus_connection.work_queue); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 165 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 166 | if (vmbus_connection.int_page) { |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame^] | 167 | free_pages((unsigned long)vmbus_connection.int_page, 0); |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 168 | vmbus_connection.int_page = NULL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 171 | if (vmbus_connection.monitor_pages) { |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame^] | 172 | free_pages((unsigned long)vmbus_connection.monitor_pages, 1); |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 173 | vmbus_connection.monitor_pages = NULL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 176 | if (msginfo) { |
| 177 | kfree(msginfo->waitevent); |
| 178 | kfree(msginfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 181 | return ret; |
| 182 | } |
| 183 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 184 | /* |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 185 | * vmbus_disconnect - |
| 186 | * Sends a disconnect request on the partition service connection |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 187 | */ |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 188 | int vmbus_disconnect(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 189 | { |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 190 | int ret = 0; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 191 | struct vmbus_channel_message_header *msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 192 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 193 | /* Make sure we are connected */ |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 194 | if (vmbus_connection.conn_state != CONNECTED) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 195 | return -1; |
| 196 | |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 197 | msg = kzalloc(sizeof(struct vmbus_channel_message_header), GFP_KERNEL); |
Bill Pemberton | 8cad0af | 2010-05-05 15:27:32 -0400 | [diff] [blame] | 198 | if (!msg) |
| 199 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 200 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 201 | msg->msgtype = CHANNELMSG_UNLOAD; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 202 | |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 203 | ret = vmbus_post_msg(msg, |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 204 | sizeof(struct vmbus_channel_message_header)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 205 | if (ret != 0) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 206 | goto Cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 207 | |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame^] | 208 | free_pages((unsigned long)vmbus_connection.int_page, 0); |
| 209 | free_pages((unsigned long)vmbus_connection.monitor_pages, 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 210 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 211 | /* TODO: iterate thru the msg list and free up */ |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 212 | destroy_workqueue(vmbus_connection.work_queue); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 213 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 214 | vmbus_connection.conn_state = DISCONNECTED; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 215 | |
| 216 | DPRINT_INFO(VMBUS, "Vmbus disconnected!!"); |
| 217 | |
| 218 | Cleanup: |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 219 | kfree(msg); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 220 | return ret; |
| 221 | } |
| 222 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 223 | /* |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 224 | * relid2channel - Get the channel object given its |
| 225 | * child relative id (ie channel id) |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 226 | */ |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 227 | struct vmbus_channel *relid2channel(u32 relid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 228 | { |
Greg Kroah-Hartman | aded716 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 229 | struct vmbus_channel *channel; |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 230 | struct vmbus_channel *found_channel = NULL; |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 231 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 232 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 233 | spin_lock_irqsave(&vmbus_connection.channel_lock, flags); |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 234 | list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 235 | if (channel->offermsg.child_relid == relid) { |
| 236 | found_channel = channel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 237 | break; |
| 238 | } |
| 239 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 240 | spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 241 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 242 | return found_channel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 245 | /* |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 246 | * process_chn_event - Process a channel event notification |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 247 | */ |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 248 | static void process_chn_event(void *context) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 249 | { |
Greg Kroah-Hartman | aded716 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 250 | struct vmbus_channel *channel; |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 251 | u32 relid = (u32)(unsigned long)context; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 252 | |
Bill Pemberton | 972b952 | 2010-05-05 15:27:54 -0400 | [diff] [blame] | 253 | /* ASSERT(relId > 0); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 254 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 255 | /* |
| 256 | * Find the channel based on this relid and invokes the |
| 257 | * channel callback to process the event |
| 258 | */ |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 259 | channel = relid2channel(relid); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 260 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 261 | if (channel) { |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 262 | vmbus_onchannel_event(channel); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 263 | /* |
| 264 | * WorkQueueQueueWorkItem(channel->dataWorkQueue, |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 265 | * vmbus_onchannel_event, |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 266 | * (void*)channel); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 267 | */ |
| 268 | } else { |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 269 | DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relid); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 273 | /* |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 274 | * vmbus_on_event - Handler for events |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 275 | */ |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 276 | void vmbus_on_event(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 277 | { |
| 278 | int dword; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 279 | int maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; |
| 280 | int bit; |
| 281 | int relid; |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 282 | u32 *recv_int_page = vmbus_connection.recv_int_page; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 283 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 284 | /* Check events */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 285 | if (recv_int_page) { |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 286 | for (dword = 0; dword < maxdword; dword++) { |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 287 | if (recv_int_page[dword]) { |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 288 | for (bit = 0; bit < 32; bit++) { |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 289 | if (test_and_clear_bit(bit, |
| 290 | (unsigned long *) |
| 291 | &recv_int_page[dword])) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 292 | relid = (dword << 5) + bit; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 293 | DPRINT_DBG(VMBUS, "event detected for relid - %d", relid); |
| 294 | |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 295 | if (relid == 0) { |
| 296 | /* special case - vmbus channel protocol msg */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 297 | DPRINT_DBG(VMBUS, "invalid relid - %d", relid); |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 298 | continue; |
| 299 | } else { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 300 | /* QueueWorkItem(VmbusProcessEvent, (void*)relid); */ |
| 301 | /* ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid); */ |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 302 | process_chn_event((void *) |
| 303 | (unsigned long)relid); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 310 | return; |
| 311 | } |
| 312 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 313 | /* |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 314 | * vmbus_post_msg - Send a msg on the vmbus's message connection |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 315 | */ |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 316 | int vmbus_post_msg(void *buffer, size_t buflen) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 317 | { |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 318 | union hv_connection_id conn_id; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 319 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 320 | conn_id.asu32 = 0; |
| 321 | conn_id.u.id = VMBUS_MESSAGE_CONNECTION_ID; |
| 322 | return hv_post_message(conn_id, 1, buffer, buflen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 325 | /* |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 326 | * vmbus_set_event - Send an event notification to the parent |
Greg Kroah-Hartman | fd8b85e | 2009-08-31 11:40:14 -0700 | [diff] [blame] | 327 | */ |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 328 | int vmbus_set_event(u32 child_relid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 329 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 330 | /* Each u32 represents 32 channels */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 331 | set_bit(child_relid & 31, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 332 | (unsigned long *)vmbus_connection.send_int_page + |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 333 | (child_relid >> 5)); |
Bill Pemberton | 7c369f4 | 2009-07-29 17:00:11 -0400 | [diff] [blame] | 334 | |
Haiyang Zhang | d44890c | 2010-11-08 14:04:42 -0800 | [diff] [blame] | 335 | return hv_signal_event(); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 336 | } |