Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1 | /* |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2 | * Copyright (c) 2009, Microsoft Corporation. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 15 | * Place - Suite 330, Boston, MA 02111-1307 USA. |
| 16 | * |
| 17 | * Authors: |
| 18 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 19 | * Hank Janssen <hjanssen@microsoft.com> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 20 | */ |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 22 | |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 24 | #include <linux/sched.h> |
| 25 | #include <linux/wait.h> |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 26 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 28 | #include <linux/list.h> |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 30 | #include <linux/completion.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 31 | #include <linux/hyperv.h> |
K. Y. Srinivasan | 3f335ea | 2011-05-12 19:34:15 -0700 | [diff] [blame] | 32 | |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 33 | #include "hyperv_vmbus.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 34 | |
Greg Kroah-Hartman | 1d7e907 | 2009-08-28 16:26:11 -0700 | [diff] [blame] | 35 | struct vmbus_channel_message_table_entry { |
K. Y. Srinivasan | cf9dcba | 2011-05-10 07:55:37 -0700 | [diff] [blame] | 36 | enum vmbus_channel_message_type message_type; |
K. Y. Srinivasan | fa90f1d | 2011-05-10 07:55:36 -0700 | [diff] [blame] | 37 | void (*message_handler)(struct vmbus_channel_message_header *msg); |
Greg Kroah-Hartman | 1d7e907 | 2009-08-28 16:26:11 -0700 | [diff] [blame] | 38 | }; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 39 | |
Ky Srinivasan | 245ba56 | 2010-12-16 18:54:16 -0700 | [diff] [blame] | 40 | #define MAX_MSG_TYPES 4 |
| 41 | #define MAX_NUM_DEVICE_CLASSES_SUPPORTED 8 |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 42 | |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 43 | static const uuid_le |
K. Y. Srinivasan | 50b0326 | 2011-05-10 07:55:35 -0700 | [diff] [blame] | 44 | supported_device_classes[MAX_NUM_DEVICE_CLASSES_SUPPORTED] = { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 45 | /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 46 | /* Storage - SCSI */ |
| 47 | { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 48 | .b = { |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 49 | 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, |
| 50 | 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f |
| 51 | } |
| 52 | }, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 53 | |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 54 | /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */ |
| 55 | /* Network */ |
| 56 | { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 57 | .b = { |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 58 | 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, |
| 59 | 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E |
| 60 | } |
| 61 | }, |
| 62 | |
| 63 | /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */ |
| 64 | /* Input */ |
| 65 | { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 66 | .b = { |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 67 | 0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c, |
| 68 | 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A |
| 69 | } |
| 70 | }, |
| 71 | |
| 72 | /* {32412632-86cb-44a2-9b5c-50d1417354f5} */ |
| 73 | /* IDE */ |
| 74 | { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 75 | .b = { |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 76 | 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, |
| 77 | 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 |
| 78 | } |
| 79 | }, |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 80 | /* 0E0B6031-5213-4934-818B-38D90CED39DB */ |
| 81 | /* Shutdown */ |
| 82 | { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 83 | .b = { |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 84 | 0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49, |
| 85 | 0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB |
| 86 | } |
| 87 | }, |
Haiyang Zhang | 39c4e9c | 2010-05-05 19:23:46 +0000 | [diff] [blame] | 88 | /* {9527E630-D0AE-497b-ADCE-E80AB0175CAF} */ |
| 89 | /* TimeSync */ |
| 90 | { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 91 | .b = { |
Haiyang Zhang | 39c4e9c | 2010-05-05 19:23:46 +0000 | [diff] [blame] | 92 | 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, |
| 93 | 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf |
| 94 | } |
| 95 | }, |
Hank Janssen | 9153f7b | 2010-05-15 14:39:58 -0700 | [diff] [blame] | 96 | /* {57164f39-9115-4e78-ab55-382f3bd5422d} */ |
| 97 | /* Heartbeat */ |
| 98 | { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 99 | .b = { |
Hank Janssen | 9153f7b | 2010-05-15 14:39:58 -0700 | [diff] [blame] | 100 | 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, |
| 101 | 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d |
| 102 | } |
| 103 | }, |
Ky Srinivasan | 245ba56 | 2010-12-16 18:54:16 -0700 | [diff] [blame] | 104 | /* {A9A0F4E7-5A45-4d96-B827-8A841E8C03E6} */ |
| 105 | /* KVP */ |
| 106 | { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 107 | .b = { |
Ky Srinivasan | 245ba56 | 2010-12-16 18:54:16 -0700 | [diff] [blame] | 108 | 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, |
| 109 | 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 |
| 110 | } |
| 111 | }, |
| 112 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
Greg Kroah-Hartman | da0e963 | 2011-10-11 08:42:28 -0600 | [diff] [blame] | 117 | * vmbus_prep_negotiate_resp() - Create default response for Hyper-V Negotiate message |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 118 | * @icmsghdrp: Pointer to msg header structure |
| 119 | * @icmsg_negotiate: Pointer to negotiate message structure |
| 120 | * @buf: Raw buffer channel data |
| 121 | * |
| 122 | * @icmsghdrp is of type &struct icmsg_hdr. |
| 123 | * @negop is of type &struct icmsg_negotiate. |
| 124 | * Set up and fill in default negotiate response message. This response can |
| 125 | * come from both the vmbus driver and the hv_utils driver. The current api |
| 126 | * will respond properly to both Windows 2008 and Windows 2008-R2 operating |
| 127 | * systems. |
| 128 | * |
| 129 | * Mainly used by Hyper-V drivers. |
| 130 | */ |
Greg Kroah-Hartman | da0e963 | 2011-10-11 08:42:28 -0600 | [diff] [blame] | 131 | void vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, |
| 132 | struct icmsg_negotiate *negop, u8 *buf) |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 133 | { |
| 134 | if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { |
| 135 | icmsghdrp->icmsgsize = 0x10; |
| 136 | |
| 137 | negop = (struct icmsg_negotiate *)&buf[ |
| 138 | sizeof(struct vmbuspipe_hdr) + |
| 139 | sizeof(struct icmsg_hdr)]; |
| 140 | |
| 141 | if (negop->icframe_vercnt == 2 && |
| 142 | negop->icversion_data[1].major == 3) { |
| 143 | negop->icversion_data[0].major = 3; |
| 144 | negop->icversion_data[0].minor = 0; |
| 145 | negop->icversion_data[1].major = 3; |
| 146 | negop->icversion_data[1].minor = 0; |
| 147 | } else { |
| 148 | negop->icversion_data[0].major = 1; |
| 149 | negop->icversion_data[0].minor = 0; |
| 150 | negop->icversion_data[1].major = 1; |
| 151 | negop->icversion_data[1].minor = 0; |
| 152 | } |
| 153 | |
| 154 | negop->icframe_vercnt = 1; |
| 155 | negop->icmsg_vercnt = 1; |
| 156 | } |
| 157 | } |
Greg Kroah-Hartman | da0e963 | 2011-10-11 08:42:28 -0600 | [diff] [blame] | 158 | EXPORT_SYMBOL_GPL(vmbus_prep_negotiate_resp); |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 159 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 160 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 161 | * alloc_channel - Allocate and initialize a vmbus channel object |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 162 | */ |
Greg Kroah-Hartman | 50fe56d | 2010-10-20 15:51:57 -0700 | [diff] [blame] | 163 | static struct vmbus_channel *alloc_channel(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 164 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 165 | struct vmbus_channel *channel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 166 | |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 167 | channel = kzalloc(sizeof(*channel), GFP_ATOMIC); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 168 | if (!channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 169 | return NULL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 170 | |
Greg Kroah-Hartman | 54411c4 | 2009-07-15 14:48:32 -0700 | [diff] [blame] | 171 | spin_lock_init(&channel->inbound_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 172 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 173 | channel->controlwq = create_workqueue("hv_vmbus_ctl"); |
| 174 | if (!channel->controlwq) { |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 175 | kfree(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 176 | return NULL; |
| 177 | } |
| 178 | |
| 179 | return channel; |
| 180 | } |
| 181 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 182 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 183 | * release_hannel - Release the vmbus channel object itself |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 184 | */ |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 185 | static void release_channel(struct work_struct *work) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 186 | { |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 187 | struct vmbus_channel *channel = container_of(work, |
| 188 | struct vmbus_channel, |
| 189 | work); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 190 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 191 | destroy_workqueue(channel->controlwq); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 192 | |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 193 | kfree(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 196 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 197 | * free_channel - Release the resources used by the vmbus channel object |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 198 | */ |
Greg Kroah-Hartman | 9f3e28e | 2011-10-11 09:40:01 -0600 | [diff] [blame] | 199 | static void free_channel(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 200 | { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 201 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 202 | /* |
| 203 | * We have to release the channel's workqueue/thread in the vmbus's |
| 204 | * workqueue/thread context |
| 205 | * ie we can't destroy ourselves. |
| 206 | */ |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 207 | INIT_WORK(&channel->work, release_channel); |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 208 | queue_work(vmbus_connection.work_queue, &channel->work); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 211 | |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 212 | |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 213 | /* |
| 214 | * vmbus_process_rescind_offer - |
| 215 | * Rescind the offer by initiating a device removal |
| 216 | */ |
| 217 | static void vmbus_process_rescind_offer(struct work_struct *work) |
| 218 | { |
| 219 | struct vmbus_channel *channel = container_of(work, |
| 220 | struct vmbus_channel, |
| 221 | work); |
| 222 | |
K. Y. Srinivasan | 696453b | 2011-09-08 07:24:14 -0700 | [diff] [blame] | 223 | vmbus_device_unregister(channel->device_obj); |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 224 | } |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 225 | |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 226 | void vmbus_free_channels(void) |
| 227 | { |
| 228 | struct vmbus_channel *channel; |
| 229 | |
| 230 | list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { |
| 231 | vmbus_device_unregister(channel->device_obj); |
| 232 | kfree(channel->device_obj); |
| 233 | free_channel(channel); |
| 234 | } |
| 235 | } |
| 236 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 237 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 238 | * vmbus_process_offer - Process the offer by creating a channel/device |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 239 | * associated with this offer |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 240 | */ |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 241 | static void vmbus_process_offer(struct work_struct *work) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 242 | { |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 243 | struct vmbus_channel *newchannel = container_of(work, |
| 244 | struct vmbus_channel, |
| 245 | work); |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 246 | struct vmbus_channel *channel; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 247 | bool fnew = true; |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 248 | int ret; |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 249 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 250 | |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 251 | /* The next possible work is rescind handling */ |
| 252 | INIT_WORK(&newchannel->work, vmbus_process_rescind_offer); |
| 253 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 254 | /* Make sure this is a new offer */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 255 | spin_lock_irqsave(&vmbus_connection.channel_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 256 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 257 | list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 258 | if (!uuid_le_cmp(channel->offermsg.offer.if_type, |
| 259 | newchannel->offermsg.offer.if_type) && |
| 260 | !uuid_le_cmp(channel->offermsg.offer.if_instance, |
| 261 | newchannel->offermsg.offer.if_instance)) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 262 | fnew = false; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 263 | break; |
| 264 | } |
| 265 | } |
| 266 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 267 | if (fnew) |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 268 | list_add_tail(&newchannel->listentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 269 | &vmbus_connection.chn_list); |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 270 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 271 | spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 272 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 273 | if (!fnew) { |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 274 | free_channel(newchannel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 275 | return; |
| 276 | } |
| 277 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 278 | /* |
| 279 | * Start the process of binding this offer to the driver |
| 280 | * We need to set the DeviceObject field before calling |
Haiyang Zhang | 646f1ea | 2011-01-26 12:12:10 -0800 | [diff] [blame] | 281 | * vmbus_child_dev_add() |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 282 | */ |
K. Y. Srinivasan | f2c7301 | 2011-09-08 07:24:12 -0700 | [diff] [blame] | 283 | newchannel->device_obj = vmbus_device_create( |
Haiyang Zhang | 767dff6 | 2011-01-26 12:12:12 -0800 | [diff] [blame] | 284 | &newchannel->offermsg.offer.if_type, |
| 285 | &newchannel->offermsg.offer.if_instance, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 286 | newchannel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 287 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 288 | /* |
| 289 | * Add the new device to the bus. This will kick off device-driver |
| 290 | * binding which eventually invokes the device driver's AddDevice() |
| 291 | * method. |
| 292 | */ |
K. Y. Srinivasan | 22794281 | 2011-09-08 07:24:13 -0700 | [diff] [blame] | 293 | ret = vmbus_device_register(newchannel->device_obj); |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 294 | if (ret != 0) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 295 | pr_err("unable to add child device object (relid %d)\n", |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 296 | newchannel->offermsg.child_relid); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 297 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 298 | spin_lock_irqsave(&vmbus_connection.channel_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 299 | list_del(&newchannel->listentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 300 | spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); |
K. Y. Srinivasan | 8b8ee67 | 2011-12-12 09:29:16 -0800 | [diff] [blame] | 301 | kfree(newchannel->device_obj); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 302 | |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 303 | free_channel(newchannel); |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 304 | } else { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 305 | /* |
| 306 | * This state is used to indicate a successful open |
| 307 | * so that when we do close the channel normally, we |
| 308 | * can cleanup properly |
| 309 | */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 310 | newchannel->state = CHANNEL_OPEN_STATE; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 311 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 314 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 315 | * vmbus_onoffer - Handler for channel offers from vmbus in parent partition. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 316 | * |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 317 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 318 | static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 319 | { |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 320 | struct vmbus_channel_offer_channel *offer; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 321 | struct vmbus_channel *newchannel; |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 322 | uuid_le *guidtype; |
| 323 | uuid_le *guidinstance; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 324 | int i; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 325 | int fsupported = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 326 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 327 | offer = (struct vmbus_channel_offer_channel *)hdr; |
| 328 | for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 329 | if (!uuid_le_cmp(offer->offer.if_type, |
| 330 | supported_device_classes[i])) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 331 | fsupported = 1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 332 | break; |
| 333 | } |
| 334 | } |
| 335 | |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 336 | if (!fsupported) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 337 | return; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 338 | |
Haiyang Zhang | 767dff6 | 2011-01-26 12:12:12 -0800 | [diff] [blame] | 339 | guidtype = &offer->offer.if_type; |
| 340 | guidinstance = &offer->offer.if_instance; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 341 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 342 | /* Allocate the channel object and save this offer. */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 343 | newchannel = alloc_channel(); |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 344 | if (!newchannel) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 345 | pr_err("Unable to allocate channel object\n"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 346 | return; |
| 347 | } |
| 348 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 349 | memcpy(&newchannel->offermsg, offer, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 350 | sizeof(struct vmbus_channel_offer_channel)); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 351 | newchannel->monitor_grp = (u8)offer->monitorid / 32; |
| 352 | newchannel->monitor_bit = (u8)offer->monitorid % 32; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 353 | |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 354 | INIT_WORK(&newchannel->work, vmbus_process_offer); |
| 355 | queue_work(newchannel->controlwq, &newchannel->work); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 358 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 359 | * vmbus_onoffer_rescind - Rescind offer handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 360 | * |
| 361 | * We queue a work item to process this offer synchronously |
| 362 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 363 | static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 364 | { |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 365 | struct vmbus_channel_rescind_offer *rescind; |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 366 | struct vmbus_channel *channel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 367 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 368 | rescind = (struct vmbus_channel_rescind_offer *)hdr; |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 369 | channel = relid2channel(rescind->child_relid); |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 370 | |
| 371 | if (channel == NULL) |
| 372 | /* Just return here, no channel found */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 373 | return; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 374 | |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 375 | /* work is initialized for vmbus_process_rescind_offer() from |
| 376 | * vmbus_process_offer() where the channel got created */ |
| 377 | queue_work(channel->controlwq, &channel->work); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 380 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 381 | * vmbus_onoffers_delivered - |
| 382 | * This is invoked when all offers have been delivered. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 383 | * |
| 384 | * Nothing to do here. |
| 385 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 386 | static void vmbus_onoffers_delivered( |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 387 | struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 388 | { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 391 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 392 | * vmbus_onopen_result - Open result handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 393 | * |
| 394 | * This is invoked when we received a response to our channel open request. |
| 395 | * Find the matching request, copy the response and signal the requesting |
| 396 | * thread. |
| 397 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 398 | static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 399 | { |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 400 | struct vmbus_channel_open_result *result; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 401 | struct vmbus_channel_msginfo *msginfo; |
| 402 | struct vmbus_channel_message_header *requestheader; |
| 403 | struct vmbus_channel_open_channel *openmsg; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 404 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 405 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 406 | result = (struct vmbus_channel_open_result *)hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 407 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 408 | /* |
| 409 | * Find the open msg, copy the result and signal/unblock the wait event |
| 410 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 411 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 412 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 413 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 414 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 415 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 416 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 417 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 418 | if (requestheader->msgtype == CHANNELMSG_OPENCHANNEL) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 419 | openmsg = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 420 | (struct vmbus_channel_open_channel *)msginfo->msg; |
| 421 | if (openmsg->child_relid == result->child_relid && |
| 422 | openmsg->openid == result->openid) { |
| 423 | memcpy(&msginfo->response.open_result, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 424 | result, |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 425 | sizeof( |
| 426 | struct vmbus_channel_open_result)); |
| 427 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 428 | break; |
| 429 | } |
| 430 | } |
| 431 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 432 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 435 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 436 | * vmbus_ongpadl_created - GPADL created handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 437 | * |
| 438 | * This is invoked when we received a response to our gpadl create request. |
| 439 | * Find the matching request, copy the response and signal the requesting |
| 440 | * thread. |
| 441 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 442 | static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 443 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 444 | struct vmbus_channel_gpadl_created *gpadlcreated; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 445 | struct vmbus_channel_msginfo *msginfo; |
| 446 | struct vmbus_channel_message_header *requestheader; |
| 447 | struct vmbus_channel_gpadl_header *gpadlheader; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 448 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 449 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 450 | gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 451 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 452 | /* |
| 453 | * Find the establish msg, copy the result and signal/unblock the wait |
| 454 | * event |
| 455 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 456 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 457 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 458 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 459 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 460 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 461 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 462 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 463 | if (requestheader->msgtype == CHANNELMSG_GPADL_HEADER) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 464 | gpadlheader = |
| 465 | (struct vmbus_channel_gpadl_header *)requestheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 466 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 467 | if ((gpadlcreated->child_relid == |
| 468 | gpadlheader->child_relid) && |
| 469 | (gpadlcreated->gpadl == gpadlheader->gpadl)) { |
| 470 | memcpy(&msginfo->response.gpadl_created, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 471 | gpadlcreated, |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 472 | sizeof( |
| 473 | struct vmbus_channel_gpadl_created)); |
| 474 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 475 | break; |
| 476 | } |
| 477 | } |
| 478 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 479 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 482 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 483 | * vmbus_ongpadl_torndown - GPADL torndown handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 484 | * |
| 485 | * This is invoked when we received a response to our gpadl teardown request. |
| 486 | * Find the matching request, copy the response and signal the requesting |
| 487 | * thread. |
| 488 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 489 | static void vmbus_ongpadl_torndown( |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 490 | struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 491 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 492 | struct vmbus_channel_gpadl_torndown *gpadl_torndown; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 493 | struct vmbus_channel_msginfo *msginfo; |
| 494 | struct vmbus_channel_message_header *requestheader; |
| 495 | struct vmbus_channel_gpadl_teardown *gpadl_teardown; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 496 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 497 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 498 | gpadl_torndown = (struct vmbus_channel_gpadl_torndown *)hdr; |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 499 | |
| 500 | /* |
| 501 | * Find the open msg, copy the result and signal/unblock the wait event |
| 502 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 503 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 504 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 505 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 506 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 507 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 508 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 509 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 510 | if (requestheader->msgtype == CHANNELMSG_GPADL_TEARDOWN) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 511 | gpadl_teardown = |
| 512 | (struct vmbus_channel_gpadl_teardown *)requestheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 513 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 514 | if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) { |
| 515 | memcpy(&msginfo->response.gpadl_torndown, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 516 | gpadl_torndown, |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 517 | sizeof( |
| 518 | struct vmbus_channel_gpadl_torndown)); |
| 519 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 520 | break; |
| 521 | } |
| 522 | } |
| 523 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 524 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 527 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 528 | * vmbus_onversion_response - Version response handler |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 529 | * |
| 530 | * This is invoked when we received a response to our initiate contact request. |
| 531 | * Find the matching request, copy the response and signal the requesting |
| 532 | * thread. |
| 533 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 534 | static void vmbus_onversion_response( |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 535 | struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 536 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 537 | struct vmbus_channel_msginfo *msginfo; |
| 538 | struct vmbus_channel_message_header *requestheader; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 539 | struct vmbus_channel_initiate_contact *initiate; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 540 | struct vmbus_channel_version_response *version_response; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 541 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 542 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 543 | version_response = (struct vmbus_channel_version_response *)hdr; |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 544 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 545 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 546 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 547 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 548 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 549 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 550 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 551 | if (requestheader->msgtype == |
| 552 | CHANNELMSG_INITIATE_CONTACT) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 553 | initiate = |
| 554 | (struct vmbus_channel_initiate_contact *)requestheader; |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 555 | memcpy(&msginfo->response.version_response, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 556 | version_response, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 557 | sizeof(struct vmbus_channel_version_response)); |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 558 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 559 | } |
| 560 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 561 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Greg Kroah-Hartman | c8212f0 | 2009-08-31 21:51:50 -0700 | [diff] [blame] | 564 | /* Channel message dispatch table */ |
| 565 | static struct vmbus_channel_message_table_entry |
K. Y. Srinivasan | b7c6b02 | 2011-05-10 07:55:38 -0700 | [diff] [blame] | 566 | channel_message_table[CHANNELMSG_COUNT] = { |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 567 | {CHANNELMSG_INVALID, NULL}, |
| 568 | {CHANNELMSG_OFFERCHANNEL, vmbus_onoffer}, |
| 569 | {CHANNELMSG_RESCIND_CHANNELOFFER, vmbus_onoffer_rescind}, |
| 570 | {CHANNELMSG_REQUESTOFFERS, NULL}, |
| 571 | {CHANNELMSG_ALLOFFERS_DELIVERED, vmbus_onoffers_delivered}, |
| 572 | {CHANNELMSG_OPENCHANNEL, NULL}, |
| 573 | {CHANNELMSG_OPENCHANNEL_RESULT, vmbus_onopen_result}, |
| 574 | {CHANNELMSG_CLOSECHANNEL, NULL}, |
| 575 | {CHANNELMSG_GPADL_HEADER, NULL}, |
| 576 | {CHANNELMSG_GPADL_BODY, NULL}, |
| 577 | {CHANNELMSG_GPADL_CREATED, vmbus_ongpadl_created}, |
| 578 | {CHANNELMSG_GPADL_TEARDOWN, NULL}, |
| 579 | {CHANNELMSG_GPADL_TORNDOWN, vmbus_ongpadl_torndown}, |
| 580 | {CHANNELMSG_RELID_RELEASED, NULL}, |
| 581 | {CHANNELMSG_INITIATE_CONTACT, NULL}, |
| 582 | {CHANNELMSG_VERSION_RESPONSE, vmbus_onversion_response}, |
| 583 | {CHANNELMSG_UNLOAD, NULL}, |
Greg Kroah-Hartman | c8212f0 | 2009-08-31 21:51:50 -0700 | [diff] [blame] | 584 | }; |
| 585 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 586 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 587 | * vmbus_onmessage - Handler for channel protocol messages. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 588 | * |
| 589 | * This is invoked in the vmbus worker thread context. |
| 590 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 591 | void vmbus_onmessage(void *context) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 592 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 593 | struct hv_message *msg = context; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 594 | struct vmbus_channel_message_header *hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 595 | int size; |
| 596 | |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 597 | hdr = (struct vmbus_channel_message_header *)msg->u.payload; |
| 598 | size = msg->header.payload_size; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 599 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 600 | if (hdr->msgtype >= CHANNELMSG_COUNT) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 601 | pr_err("Received invalid channel message type %d size %d\n", |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 602 | hdr->msgtype, size); |
Greg Kroah-Hartman | 04f50c4 | 2009-07-16 12:35:37 -0700 | [diff] [blame] | 603 | print_hex_dump_bytes("", DUMP_PREFIX_NONE, |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 604 | (unsigned char *)msg->u.payload, size); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 605 | return; |
| 606 | } |
| 607 | |
K. Y. Srinivasan | b7c6b02 | 2011-05-10 07:55:38 -0700 | [diff] [blame] | 608 | if (channel_message_table[hdr->msgtype].message_handler) |
| 609 | channel_message_table[hdr->msgtype].message_handler(hdr); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 610 | else |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 611 | pr_err("Unhandled channel message type %d\n", hdr->msgtype); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 614 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 615 | * vmbus_request_offers - Send a request to get all our pending offers. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 616 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 617 | int vmbus_request_offers(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 618 | { |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 619 | struct vmbus_channel_message_header *msg; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 620 | struct vmbus_channel_msginfo *msginfo; |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 621 | int ret, t; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 622 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 623 | msginfo = kmalloc(sizeof(*msginfo) + |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 624 | sizeof(struct vmbus_channel_message_header), |
| 625 | GFP_KERNEL); |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 626 | if (!msginfo) |
Bill Pemberton | 75910f2 | 2010-05-05 15:27:31 -0400 | [diff] [blame] | 627 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 628 | |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 629 | init_completion(&msginfo->waitevent); |
Bill Pemberton | 75910f2 | 2010-05-05 15:27:31 -0400 | [diff] [blame] | 630 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 631 | msg = (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 632 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 633 | msg->msgtype = CHANNELMSG_REQUESTOFFERS; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 634 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 635 | |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 636 | ret = vmbus_post_msg(msg, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 637 | sizeof(struct vmbus_channel_message_header)); |
| 638 | if (ret != 0) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 639 | pr_err("Unable to request offers - %d\n", ret); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 640 | |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 641 | goto cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 642 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 643 | |
K. Y. Srinivasan | 2dfde96 | 2011-06-16 13:16:34 -0700 | [diff] [blame] | 644 | t = wait_for_completion_timeout(&msginfo->waitevent, 5*HZ); |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 645 | if (t == 0) { |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 646 | ret = -ETIMEDOUT; |
| 647 | goto cleanup; |
| 648 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 649 | |
| 650 | |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 651 | |
| 652 | cleanup: |
Ilia Mirkin | dd9b15d | 2011-03-13 00:29:00 -0500 | [diff] [blame] | 653 | kfree(msginfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 654 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 655 | return ret; |
| 656 | } |
| 657 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 658 | /* eof */ |