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> |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 25 | #include <linux/sched.h> |
| 26 | #include <linux/wait.h> |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 27 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 29 | #include <linux/list.h> |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 31 | #include <linux/completion.h> |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 32 | #include <linux/delay.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 33 | #include <linux/hyperv.h> |
K. Y. Srinivasan | 3f335ea | 2011-05-12 19:34:15 -0700 | [diff] [blame] | 34 | |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 35 | #include "hyperv_vmbus.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 36 | |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 37 | static void init_vp_index(struct vmbus_channel *channel, u16 dev_type); |
| 38 | |
| 39 | static const struct vmbus_device vmbus_devs[] = { |
| 40 | /* IDE */ |
| 41 | { .dev_type = HV_IDE, |
| 42 | HV_IDE_GUID, |
| 43 | .perf_device = true, |
| 44 | }, |
| 45 | |
| 46 | /* SCSI */ |
| 47 | { .dev_type = HV_SCSI, |
| 48 | HV_SCSI_GUID, |
| 49 | .perf_device = true, |
| 50 | }, |
| 51 | |
| 52 | /* Fibre Channel */ |
| 53 | { .dev_type = HV_FC, |
| 54 | HV_SYNTHFC_GUID, |
| 55 | .perf_device = true, |
| 56 | }, |
| 57 | |
| 58 | /* Synthetic NIC */ |
| 59 | { .dev_type = HV_NIC, |
| 60 | HV_NIC_GUID, |
| 61 | .perf_device = true, |
| 62 | }, |
| 63 | |
| 64 | /* Network Direct */ |
| 65 | { .dev_type = HV_ND, |
| 66 | HV_ND_GUID, |
| 67 | .perf_device = true, |
| 68 | }, |
| 69 | |
| 70 | /* PCIE */ |
| 71 | { .dev_type = HV_PCIE, |
| 72 | HV_PCIE_GUID, |
| 73 | .perf_device = true, |
| 74 | }, |
| 75 | |
| 76 | /* Synthetic Frame Buffer */ |
| 77 | { .dev_type = HV_FB, |
| 78 | HV_SYNTHVID_GUID, |
| 79 | .perf_device = false, |
| 80 | }, |
| 81 | |
| 82 | /* Synthetic Keyboard */ |
| 83 | { .dev_type = HV_KBD, |
| 84 | HV_KBD_GUID, |
| 85 | .perf_device = false, |
| 86 | }, |
| 87 | |
| 88 | /* Synthetic MOUSE */ |
| 89 | { .dev_type = HV_MOUSE, |
| 90 | HV_MOUSE_GUID, |
| 91 | .perf_device = false, |
| 92 | }, |
| 93 | |
| 94 | /* KVP */ |
| 95 | { .dev_type = HV_KVP, |
| 96 | HV_KVP_GUID, |
| 97 | .perf_device = false, |
| 98 | }, |
| 99 | |
| 100 | /* Time Synch */ |
| 101 | { .dev_type = HV_TS, |
| 102 | HV_TS_GUID, |
| 103 | .perf_device = false, |
| 104 | }, |
| 105 | |
| 106 | /* Heartbeat */ |
| 107 | { .dev_type = HV_HB, |
| 108 | HV_HEART_BEAT_GUID, |
| 109 | .perf_device = false, |
| 110 | }, |
| 111 | |
| 112 | /* Shutdown */ |
| 113 | { .dev_type = HV_SHUTDOWN, |
| 114 | HV_SHUTDOWN_GUID, |
| 115 | .perf_device = false, |
| 116 | }, |
| 117 | |
| 118 | /* File copy */ |
| 119 | { .dev_type = HV_FCOPY, |
| 120 | HV_FCOPY_GUID, |
| 121 | .perf_device = false, |
| 122 | }, |
| 123 | |
| 124 | /* Backup */ |
| 125 | { .dev_type = HV_BACKUP, |
| 126 | HV_VSS_GUID, |
| 127 | .perf_device = false, |
| 128 | }, |
| 129 | |
| 130 | /* Dynamic Memory */ |
| 131 | { .dev_type = HV_DM, |
| 132 | HV_DM_GUID, |
| 133 | .perf_device = false, |
| 134 | }, |
| 135 | |
| 136 | /* Unknown GUID */ |
| 137 | { .dev_type = HV_UNKOWN, |
| 138 | .perf_device = false, |
| 139 | }, |
| 140 | }; |
| 141 | |
Dexuan Cui | 0f98829 | 2016-09-07 05:39:34 -0700 | [diff] [blame] | 142 | static const struct { |
| 143 | uuid_le guid; |
| 144 | } vmbus_unsupported_devs[] = { |
| 145 | { HV_AVMA1_GUID }, |
| 146 | { HV_AVMA2_GUID }, |
| 147 | { HV_RDV_GUID }, |
| 148 | }; |
| 149 | |
| 150 | static bool is_unsupported_vmbus_devs(const uuid_le *guid) |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 151 | { |
Dexuan Cui | 0f98829 | 2016-09-07 05:39:34 -0700 | [diff] [blame] | 152 | int i; |
| 153 | |
| 154 | for (i = 0; i < ARRAY_SIZE(vmbus_unsupported_devs); i++) |
| 155 | if (!uuid_le_cmp(*guid, vmbus_unsupported_devs[i].guid)) |
| 156 | return true; |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | static u16 hv_get_dev_type(const struct vmbus_channel *channel) |
| 161 | { |
| 162 | const uuid_le *guid = &channel->offermsg.offer.if_type; |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 163 | u16 i; |
| 164 | |
Dexuan Cui | 0f98829 | 2016-09-07 05:39:34 -0700 | [diff] [blame] | 165 | if (is_hvsock_channel(channel) || is_unsupported_vmbus_devs(guid)) |
| 166 | return HV_UNKOWN; |
| 167 | |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 168 | for (i = HV_IDE; i < HV_UNKOWN; i++) { |
| 169 | if (!uuid_le_cmp(*guid, vmbus_devs[i].guid)) |
| 170 | return i; |
| 171 | } |
| 172 | pr_info("Unknown GUID: %pUl\n", guid); |
| 173 | return i; |
| 174 | } |
Vitaly Kuznetsov | f38e7dd | 2015-05-06 17:47:45 -0700 | [diff] [blame] | 175 | |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 176 | /** |
Greg Kroah-Hartman | da0e963 | 2011-10-11 08:42:28 -0600 | [diff] [blame] | 177 | * vmbus_prep_negotiate_resp() - Create default response for Hyper-V Negotiate message |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 178 | * @icmsghdrp: Pointer to msg header structure |
| 179 | * @icmsg_negotiate: Pointer to negotiate message structure |
| 180 | * @buf: Raw buffer channel data |
| 181 | * |
| 182 | * @icmsghdrp is of type &struct icmsg_hdr. |
| 183 | * @negop is of type &struct icmsg_negotiate. |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 184 | * Set up and fill in default negotiate response message. |
| 185 | * |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 186 | * The fw_version specifies the framework version that |
| 187 | * we can support and srv_version specifies the service |
| 188 | * version we can support. |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 189 | * |
| 190 | * Mainly used by Hyper-V drivers. |
| 191 | */ |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 192 | bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 193 | struct icmsg_negotiate *negop, u8 *buf, |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 194 | int fw_version, int srv_version) |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 195 | { |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 196 | int icframe_major, icframe_minor; |
| 197 | int icmsg_major, icmsg_minor; |
| 198 | int fw_major, fw_minor; |
| 199 | int srv_major, srv_minor; |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 200 | int i; |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 201 | bool found_match = false; |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 202 | |
K. Y. Srinivasan | a360530 | 2012-05-12 13:44:57 -0700 | [diff] [blame] | 203 | icmsghdrp->icmsgsize = 0x10; |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 204 | fw_major = (fw_version >> 16); |
| 205 | fw_minor = (fw_version & 0xFFFF); |
| 206 | |
| 207 | srv_major = (srv_version >> 16); |
| 208 | srv_minor = (srv_version & 0xFFFF); |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 209 | |
K. Y. Srinivasan | a360530 | 2012-05-12 13:44:57 -0700 | [diff] [blame] | 210 | negop = (struct icmsg_negotiate *)&buf[ |
| 211 | sizeof(struct vmbuspipe_hdr) + |
| 212 | sizeof(struct icmsg_hdr)]; |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 213 | |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 214 | icframe_major = negop->icframe_vercnt; |
| 215 | icframe_minor = 0; |
| 216 | |
| 217 | icmsg_major = negop->icmsg_vercnt; |
| 218 | icmsg_minor = 0; |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * Select the framework version number we will |
| 222 | * support. |
| 223 | */ |
| 224 | |
| 225 | for (i = 0; i < negop->icframe_vercnt; i++) { |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 226 | if ((negop->icversion_data[i].major == fw_major) && |
| 227 | (negop->icversion_data[i].minor == fw_minor)) { |
| 228 | icframe_major = negop->icversion_data[i].major; |
| 229 | icframe_minor = negop->icversion_data[i].minor; |
| 230 | found_match = true; |
| 231 | } |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 232 | } |
K. Y. Srinivasan | a360530 | 2012-05-12 13:44:57 -0700 | [diff] [blame] | 233 | |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 234 | if (!found_match) |
| 235 | goto fw_error; |
| 236 | |
| 237 | found_match = false; |
| 238 | |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 239 | for (i = negop->icframe_vercnt; |
| 240 | (i < negop->icframe_vercnt + negop->icmsg_vercnt); i++) { |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 241 | if ((negop->icversion_data[i].major == srv_major) && |
| 242 | (negop->icversion_data[i].minor == srv_minor)) { |
| 243 | icmsg_major = negop->icversion_data[i].major; |
| 244 | icmsg_minor = negop->icversion_data[i].minor; |
| 245 | found_match = true; |
| 246 | } |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /* |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 250 | * Respond with the framework and service |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 251 | * version numbers we can support. |
| 252 | */ |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 253 | |
| 254 | fw_error: |
| 255 | if (!found_match) { |
| 256 | negop->icframe_vercnt = 0; |
| 257 | negop->icmsg_vercnt = 0; |
| 258 | } else { |
| 259 | negop->icframe_vercnt = 1; |
| 260 | negop->icmsg_vercnt = 1; |
| 261 | } |
| 262 | |
| 263 | negop->icversion_data[0].major = icframe_major; |
| 264 | negop->icversion_data[0].minor = icframe_minor; |
| 265 | negop->icversion_data[1].major = icmsg_major; |
| 266 | negop->icversion_data[1].minor = icmsg_minor; |
| 267 | return found_match; |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 268 | } |
K. Y. Srinivasan | a360530 | 2012-05-12 13:44:57 -0700 | [diff] [blame] | 269 | |
Greg Kroah-Hartman | da0e963 | 2011-10-11 08:42:28 -0600 | [diff] [blame] | 270 | EXPORT_SYMBOL_GPL(vmbus_prep_negotiate_resp); |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 271 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 272 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 273 | * alloc_channel - Allocate and initialize a vmbus channel object |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 274 | */ |
Greg Kroah-Hartman | 50fe56d | 2010-10-20 15:51:57 -0700 | [diff] [blame] | 275 | static struct vmbus_channel *alloc_channel(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 276 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 277 | struct vmbus_channel *channel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 278 | |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 279 | channel = kzalloc(sizeof(*channel), GFP_ATOMIC); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 280 | if (!channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 281 | return NULL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 282 | |
K. Y. Srinivasan | fe760e4 | 2016-01-27 22:29:45 -0800 | [diff] [blame] | 283 | channel->acquire_ring_lock = true; |
Greg Kroah-Hartman | 54411c4 | 2009-07-15 14:48:32 -0700 | [diff] [blame] | 284 | spin_lock_init(&channel->inbound_lock); |
Vitaly Kuznetsov | 67fae05 | 2015-01-20 16:45:05 +0100 | [diff] [blame] | 285 | spin_lock_init(&channel->lock); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 286 | |
| 287 | INIT_LIST_HEAD(&channel->sc_list); |
K. Y. Srinivasan | 3a28fa3 | 2014-04-08 18:45:54 -0700 | [diff] [blame] | 288 | INIT_LIST_HEAD(&channel->percpu_list); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 289 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 290 | return channel; |
| 291 | } |
| 292 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 293 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 294 | * free_channel - Release the resources used by the vmbus channel object |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 295 | */ |
Greg Kroah-Hartman | 9f3e28e | 2011-10-11 09:40:01 -0600 | [diff] [blame] | 296 | static void free_channel(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 297 | { |
Dexuan Cui | aadc378 | 2015-03-27 09:10:10 -0700 | [diff] [blame] | 298 | kfree(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 299 | } |
| 300 | |
K. Y. Srinivasan | 3a28fa3 | 2014-04-08 18:45:54 -0700 | [diff] [blame] | 301 | static void percpu_channel_enq(void *arg) |
| 302 | { |
| 303 | struct vmbus_channel *channel = arg; |
| 304 | int cpu = smp_processor_id(); |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 305 | |
K. Y. Srinivasan | 3a28fa3 | 2014-04-08 18:45:54 -0700 | [diff] [blame] | 306 | list_add_tail(&channel->percpu_list, &hv_context.percpu_list[cpu]); |
| 307 | } |
| 308 | |
| 309 | static void percpu_channel_deq(void *arg) |
| 310 | { |
| 311 | struct vmbus_channel *channel = arg; |
| 312 | |
| 313 | list_del(&channel->percpu_list); |
| 314 | } |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 315 | |
K. Y. Srinivasan | ed6cfcc | 2015-02-28 11:18:17 -0800 | [diff] [blame] | 316 | |
Dexuan Cui | f52078c | 2015-12-14 16:01:50 -0800 | [diff] [blame] | 317 | static void vmbus_release_relid(u32 relid) |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 318 | { |
K. Y. Srinivasan | ed6cfcc | 2015-02-28 11:18:17 -0800 | [diff] [blame] | 319 | struct vmbus_channel_relid_released msg; |
Vitaly Kuznetsov | 04a258c | 2014-11-04 13:40:11 +0100 | [diff] [blame] | 320 | |
K. Y. Srinivasan | c870597 | 2013-03-15 12:25:44 -0700 | [diff] [blame] | 321 | memset(&msg, 0, sizeof(struct vmbus_channel_relid_released)); |
K. Y. Srinivasan | ed6cfcc | 2015-02-28 11:18:17 -0800 | [diff] [blame] | 322 | msg.child_relid = relid; |
K. Y. Srinivasan | c870597 | 2013-03-15 12:25:44 -0700 | [diff] [blame] | 323 | msg.header.msgtype = CHANNELMSG_RELID_RELEASED; |
| 324 | vmbus_post_msg(&msg, sizeof(struct vmbus_channel_relid_released)); |
Dexuan Cui | f52078c | 2015-12-14 16:01:50 -0800 | [diff] [blame] | 325 | } |
K. Y. Srinivasan | c870597 | 2013-03-15 12:25:44 -0700 | [diff] [blame] | 326 | |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 327 | void hv_event_tasklet_disable(struct vmbus_channel *channel) |
| 328 | { |
| 329 | struct tasklet_struct *tasklet; |
| 330 | tasklet = hv_context.event_dpc[channel->target_cpu]; |
| 331 | tasklet_disable(tasklet); |
| 332 | } |
| 333 | |
| 334 | void hv_event_tasklet_enable(struct vmbus_channel *channel) |
| 335 | { |
| 336 | struct tasklet_struct *tasklet; |
| 337 | tasklet = hv_context.event_dpc[channel->target_cpu]; |
| 338 | tasklet_enable(tasklet); |
| 339 | |
| 340 | /* In case there is any pending event */ |
| 341 | tasklet_schedule(tasklet); |
| 342 | } |
| 343 | |
Dexuan Cui | f52078c | 2015-12-14 16:01:50 -0800 | [diff] [blame] | 344 | void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid) |
| 345 | { |
| 346 | unsigned long flags; |
| 347 | struct vmbus_channel *primary_channel; |
| 348 | |
Dexuan Cui | 34c6801 | 2015-12-14 16:01:49 -0800 | [diff] [blame] | 349 | BUG_ON(!channel->rescind); |
Dexuan Cui | 85d9aa7 | 2016-01-27 22:29:43 -0800 | [diff] [blame] | 350 | BUG_ON(!mutex_is_locked(&vmbus_connection.channel_mutex)); |
Dexuan Cui | 34c6801 | 2015-12-14 16:01:49 -0800 | [diff] [blame] | 351 | |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 352 | hv_event_tasklet_disable(channel); |
K. Y. Srinivasan | 2115b56 | 2014-08-28 18:29:53 -0700 | [diff] [blame] | 353 | if (channel->target_cpu != get_cpu()) { |
| 354 | put_cpu(); |
K. Y. Srinivasan | 3a28fa3 | 2014-04-08 18:45:54 -0700 | [diff] [blame] | 355 | smp_call_function_single(channel->target_cpu, |
| 356 | percpu_channel_deq, channel, true); |
K. Y. Srinivasan | 2115b56 | 2014-08-28 18:29:53 -0700 | [diff] [blame] | 357 | } else { |
K. Y. Srinivasan | 3a28fa3 | 2014-04-08 18:45:54 -0700 | [diff] [blame] | 358 | percpu_channel_deq(channel); |
K. Y. Srinivasan | 2115b56 | 2014-08-28 18:29:53 -0700 | [diff] [blame] | 359 | put_cpu(); |
| 360 | } |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 361 | hv_event_tasklet_enable(channel); |
K. Y. Srinivasan | 3a28fa3 | 2014-04-08 18:45:54 -0700 | [diff] [blame] | 362 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 363 | if (channel->primary_channel == NULL) { |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 364 | list_del(&channel->listentry); |
Dexuan Cui | ca1c4b7 | 2015-08-13 17:07:03 -0700 | [diff] [blame] | 365 | |
| 366 | primary_channel = channel; |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 367 | } else { |
| 368 | primary_channel = channel->primary_channel; |
Vitaly Kuznetsov | 67fae05 | 2015-01-20 16:45:05 +0100 | [diff] [blame] | 369 | spin_lock_irqsave(&primary_channel->lock, flags); |
K. Y. Srinivasan | 565ce64 | 2013-10-16 19:27:19 -0700 | [diff] [blame] | 370 | list_del(&channel->sc_list); |
Vitaly Kuznetsov | 357e836 | 2015-05-06 17:47:44 -0700 | [diff] [blame] | 371 | primary_channel->num_sc--; |
Vitaly Kuznetsov | 67fae05 | 2015-01-20 16:45:05 +0100 | [diff] [blame] | 372 | spin_unlock_irqrestore(&primary_channel->lock, flags); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 373 | } |
Dexuan Cui | ca1c4b7 | 2015-08-13 17:07:03 -0700 | [diff] [blame] | 374 | |
| 375 | /* |
| 376 | * We need to free the bit for init_vp_index() to work in the case |
| 377 | * of sub-channel, when we reload drivers like hv_netvsc. |
| 378 | */ |
K. Y. Srinivasan | 509879b | 2016-09-02 05:58:23 -0700 | [diff] [blame] | 379 | if (channel->affinity_policy == HV_LOCALIZED) |
| 380 | cpumask_clear_cpu(channel->target_cpu, |
| 381 | &primary_channel->alloced_cpus_in_node); |
Dexuan Cui | ca1c4b7 | 2015-08-13 17:07:03 -0700 | [diff] [blame] | 382 | |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 383 | vmbus_release_relid(relid); |
| 384 | |
K. Y. Srinivasan | c870597 | 2013-03-15 12:25:44 -0700 | [diff] [blame] | 385 | free_channel(channel); |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 386 | } |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 387 | |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 388 | void vmbus_free_channels(void) |
| 389 | { |
Dexuan Cui | 813c5b7 | 2015-04-22 21:31:30 -0700 | [diff] [blame] | 390 | struct vmbus_channel *channel, *tmp; |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 391 | |
Vitaly Kuznetsov | bf6a9b3 | 2016-12-03 12:34:32 -0800 | [diff] [blame^] | 392 | mutex_lock(&vmbus_connection.channel_mutex); |
Dexuan Cui | 813c5b7 | 2015-04-22 21:31:30 -0700 | [diff] [blame] | 393 | list_for_each_entry_safe(channel, tmp, &vmbus_connection.chn_list, |
| 394 | listentry) { |
Dexuan Cui | 34c6801 | 2015-12-14 16:01:49 -0800 | [diff] [blame] | 395 | /* hv_process_channel_removal() needs this */ |
Dexuan Cui | 813c5b7 | 2015-04-22 21:31:30 -0700 | [diff] [blame] | 396 | channel->rescind = true; |
| 397 | |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 398 | vmbus_device_unregister(channel->device_obj); |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 399 | } |
Vitaly Kuznetsov | bf6a9b3 | 2016-12-03 12:34:32 -0800 | [diff] [blame^] | 400 | mutex_unlock(&vmbus_connection.channel_mutex); |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 403 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 404 | * vmbus_process_offer - Process the offer by creating a channel/device |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 405 | * associated with this offer |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 406 | */ |
K. Y. Srinivasan | 2dd37cb | 2015-02-28 11:18:18 -0800 | [diff] [blame] | 407 | static void vmbus_process_offer(struct vmbus_channel *newchannel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 408 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 409 | struct vmbus_channel *channel; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 410 | bool fnew = true; |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 411 | unsigned long flags; |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 412 | u16 dev_type; |
Dexuan Cui | 85d9aa7 | 2016-01-27 22:29:43 -0800 | [diff] [blame] | 413 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 414 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 415 | /* Make sure this is a new offer */ |
Dexuan Cui | d6f591e | 2015-12-14 16:01:51 -0800 | [diff] [blame] | 416 | mutex_lock(&vmbus_connection.channel_mutex); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 417 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 418 | list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 419 | if (!uuid_le_cmp(channel->offermsg.offer.if_type, |
| 420 | newchannel->offermsg.offer.if_type) && |
| 421 | !uuid_le_cmp(channel->offermsg.offer.if_instance, |
| 422 | newchannel->offermsg.offer.if_instance)) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 423 | fnew = false; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 424 | break; |
| 425 | } |
| 426 | } |
| 427 | |
Vitaly Kuznetsov | 8dfd332 | 2015-05-06 17:47:42 -0700 | [diff] [blame] | 428 | if (fnew) |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 429 | list_add_tail(&newchannel->listentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 430 | &vmbus_connection.chn_list); |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 431 | |
Dexuan Cui | d6f591e | 2015-12-14 16:01:51 -0800 | [diff] [blame] | 432 | mutex_unlock(&vmbus_connection.channel_mutex); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 433 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 434 | if (!fnew) { |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 435 | /* |
| 436 | * Check to see if this is a sub-channel. |
| 437 | */ |
| 438 | if (newchannel->offermsg.offer.sub_channel_index != 0) { |
| 439 | /* |
| 440 | * Process the sub-channel. |
| 441 | */ |
| 442 | newchannel->primary_channel = channel; |
Vitaly Kuznetsov | 67fae05 | 2015-01-20 16:45:05 +0100 | [diff] [blame] | 443 | spin_lock_irqsave(&channel->lock, flags); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 444 | list_add_tail(&newchannel->sc_list, &channel->sc_list); |
K. Y. Srinivasan | a13e8bb | 2015-02-28 11:39:02 -0800 | [diff] [blame] | 445 | channel->num_sc++; |
Vitaly Kuznetsov | 357e836 | 2015-05-06 17:47:44 -0700 | [diff] [blame] | 446 | spin_unlock_irqrestore(&channel->lock, flags); |
Vitaly Kuznetsov | 8dfd332 | 2015-05-06 17:47:42 -0700 | [diff] [blame] | 447 | } else |
| 448 | goto err_free_chan; |
| 449 | } |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 450 | |
Dexuan Cui | 0f98829 | 2016-09-07 05:39:34 -0700 | [diff] [blame] | 451 | dev_type = hv_get_dev_type(newchannel); |
K. Y. Srinivasan | ccef9bc | 2016-07-01 16:26:35 -0700 | [diff] [blame] | 452 | if (dev_type == HV_NIC) |
| 453 | set_channel_signal_state(newchannel, HV_SIGNAL_POLICY_EXPLICIT); |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 454 | |
| 455 | init_vp_index(newchannel, dev_type); |
Vitaly Kuznetsov | f38e7dd | 2015-05-06 17:47:45 -0700 | [diff] [blame] | 456 | |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 457 | hv_event_tasklet_disable(newchannel); |
Vitaly Kuznetsov | 8dfd332 | 2015-05-06 17:47:42 -0700 | [diff] [blame] | 458 | if (newchannel->target_cpu != get_cpu()) { |
| 459 | put_cpu(); |
| 460 | smp_call_function_single(newchannel->target_cpu, |
| 461 | percpu_channel_enq, |
| 462 | newchannel, true); |
| 463 | } else { |
| 464 | percpu_channel_enq(newchannel); |
| 465 | put_cpu(); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 466 | } |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 467 | hv_event_tasklet_enable(newchannel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 468 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 469 | /* |
K. Y. Srinivasan | 42dceeb | 2013-08-26 14:08:58 -0700 | [diff] [blame] | 470 | * This state is used to indicate a successful open |
| 471 | * so that when we do close the channel normally, we |
| 472 | * can cleanup properly |
| 473 | */ |
| 474 | newchannel->state = CHANNEL_OPEN_STATE; |
| 475 | |
Vitaly Kuznetsov | 8dfd332 | 2015-05-06 17:47:42 -0700 | [diff] [blame] | 476 | if (!fnew) { |
| 477 | if (channel->sc_creation_callback != NULL) |
| 478 | channel->sc_creation_callback(newchannel); |
| 479 | return; |
| 480 | } |
| 481 | |
K. Y. Srinivasan | 42dceeb | 2013-08-26 14:08:58 -0700 | [diff] [blame] | 482 | /* |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 483 | * Start the process of binding this offer to the driver |
| 484 | * We need to set the DeviceObject field before calling |
Haiyang Zhang | 646f1ea | 2011-01-26 12:12:10 -0800 | [diff] [blame] | 485 | * vmbus_child_dev_add() |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 486 | */ |
K. Y. Srinivasan | f2c7301 | 2011-09-08 07:24:12 -0700 | [diff] [blame] | 487 | newchannel->device_obj = vmbus_device_create( |
Haiyang Zhang | 767dff6 | 2011-01-26 12:12:12 -0800 | [diff] [blame] | 488 | &newchannel->offermsg.offer.if_type, |
| 489 | &newchannel->offermsg.offer.if_instance, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 490 | newchannel); |
Vitaly Kuznetsov | 9c3a6f7 | 2015-01-20 16:45:04 +0100 | [diff] [blame] | 491 | if (!newchannel->device_obj) |
K. Y. Srinivasan | 5b1e5b5 | 2015-02-28 11:18:19 -0800 | [diff] [blame] | 492 | goto err_deq_chan; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 493 | |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 494 | newchannel->device_obj->device_id = dev_type; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 495 | /* |
| 496 | * Add the new device to the bus. This will kick off device-driver |
| 497 | * binding which eventually invokes the device driver's AddDevice() |
| 498 | * method. |
| 499 | */ |
Dexuan Cui | 85d9aa7 | 2016-01-27 22:29:43 -0800 | [diff] [blame] | 500 | mutex_lock(&vmbus_connection.channel_mutex); |
| 501 | ret = vmbus_device_register(newchannel->device_obj); |
| 502 | mutex_unlock(&vmbus_connection.channel_mutex); |
| 503 | |
| 504 | if (ret != 0) { |
Dexuan Cui | d43e2fe | 2015-03-27 09:10:09 -0700 | [diff] [blame] | 505 | pr_err("unable to add child device object (relid %d)\n", |
| 506 | newchannel->offermsg.child_relid); |
| 507 | kfree(newchannel->device_obj); |
| 508 | goto err_deq_chan; |
| 509 | } |
Vitaly Kuznetsov | 9c3a6f7 | 2015-01-20 16:45:04 +0100 | [diff] [blame] | 510 | return; |
K. Y. Srinivasan | 2dd37cb | 2015-02-28 11:18:18 -0800 | [diff] [blame] | 511 | |
K. Y. Srinivasan | 5b1e5b5 | 2015-02-28 11:18:19 -0800 | [diff] [blame] | 512 | err_deq_chan: |
Dexuan Cui | d6f591e | 2015-12-14 16:01:51 -0800 | [diff] [blame] | 513 | mutex_lock(&vmbus_connection.channel_mutex); |
K. Y. Srinivasan | 5b1e5b5 | 2015-02-28 11:18:19 -0800 | [diff] [blame] | 514 | list_del(&newchannel->listentry); |
Dexuan Cui | d6f591e | 2015-12-14 16:01:51 -0800 | [diff] [blame] | 515 | mutex_unlock(&vmbus_connection.channel_mutex); |
K. Y. Srinivasan | 5b1e5b5 | 2015-02-28 11:18:19 -0800 | [diff] [blame] | 516 | |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 517 | hv_event_tasklet_disable(newchannel); |
K. Y. Srinivasan | 5b1e5b5 | 2015-02-28 11:18:19 -0800 | [diff] [blame] | 518 | if (newchannel->target_cpu != get_cpu()) { |
| 519 | put_cpu(); |
| 520 | smp_call_function_single(newchannel->target_cpu, |
| 521 | percpu_channel_deq, newchannel, true); |
| 522 | } else { |
| 523 | percpu_channel_deq(newchannel); |
| 524 | put_cpu(); |
| 525 | } |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 526 | hv_event_tasklet_enable(newchannel); |
| 527 | |
| 528 | vmbus_release_relid(newchannel->offermsg.child_relid); |
K. Y. Srinivasan | 5b1e5b5 | 2015-02-28 11:18:19 -0800 | [diff] [blame] | 529 | |
Vitaly Kuznetsov | 9c3a6f7 | 2015-01-20 16:45:04 +0100 | [diff] [blame] | 530 | err_free_chan: |
| 531 | free_channel(newchannel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 532 | } |
| 533 | |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 534 | /* |
| 535 | * We use this state to statically distribute the channel interrupt load. |
| 536 | */ |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 537 | static int next_numa_node_id; |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 538 | |
| 539 | /* |
| 540 | * Starting with Win8, we can statically distribute the incoming |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 541 | * channel interrupt load by binding a channel to VCPU. |
| 542 | * We do this in a hierarchical fashion: |
| 543 | * First distribute the primary channels across available NUMA nodes |
| 544 | * and then distribute the subchannels amongst the CPUs in the NUMA |
| 545 | * node assigned to the primary channel. |
| 546 | * |
| 547 | * For pre-win8 hosts or non-performance critical channels we assign the |
| 548 | * first CPU in the first NUMA node. |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 549 | */ |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 550 | static void init_vp_index(struct vmbus_channel *channel, u16 dev_type) |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 551 | { |
| 552 | u32 cur_cpu; |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 553 | bool perf_chn = vmbus_devs[dev_type].perf_device; |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 554 | struct vmbus_channel *primary = channel->primary_channel; |
| 555 | int next_node; |
| 556 | struct cpumask available_mask; |
K. Y. Srinivasan | 9f01ec53 | 2015-08-05 00:52:38 -0700 | [diff] [blame] | 557 | struct cpumask *alloced_mask; |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 558 | |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 559 | if ((vmbus_proto_version == VERSION_WS2008) || |
| 560 | (vmbus_proto_version == VERSION_WIN7) || (!perf_chn)) { |
| 561 | /* |
| 562 | * Prior to win8, all channel interrupts are |
| 563 | * delivered on cpu 0. |
| 564 | * Also if the channel is not a performance critical |
| 565 | * channel, bind it to cpu 0. |
| 566 | */ |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 567 | channel->numa_node = 0; |
K. Y. Srinivasan | d3ba720 | 2014-04-08 18:45:53 -0700 | [diff] [blame] | 568 | channel->target_cpu = 0; |
K. Y. Srinivasan | 9c6e64a | 2015-05-30 23:37:47 -0700 | [diff] [blame] | 569 | channel->target_vp = hv_context.vp_index[0]; |
K. Y. Srinivasan | d3ba720 | 2014-04-08 18:45:53 -0700 | [diff] [blame] | 570 | return; |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 571 | } |
Vitaly Kuznetsov | ce59fec | 2015-05-06 17:47:46 -0700 | [diff] [blame] | 572 | |
| 573 | /* |
K. Y. Srinivasan | 509879b | 2016-09-02 05:58:23 -0700 | [diff] [blame] | 574 | * Based on the channel affinity policy, we will assign the NUMA |
| 575 | * nodes. |
Vitaly Kuznetsov | ce59fec | 2015-05-06 17:47:46 -0700 | [diff] [blame] | 576 | */ |
K. Y. Srinivasan | 509879b | 2016-09-02 05:58:23 -0700 | [diff] [blame] | 577 | |
| 578 | if ((channel->affinity_policy == HV_BALANCED) || (!primary)) { |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 579 | while (true) { |
| 580 | next_node = next_numa_node_id++; |
K. Y. Srinivasan | 509879b | 2016-09-02 05:58:23 -0700 | [diff] [blame] | 581 | if (next_node == nr_node_ids) { |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 582 | next_node = next_numa_node_id = 0; |
K. Y. Srinivasan | 509879b | 2016-09-02 05:58:23 -0700 | [diff] [blame] | 583 | continue; |
| 584 | } |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 585 | if (cpumask_empty(cpumask_of_node(next_node))) |
| 586 | continue; |
| 587 | break; |
Vitaly Kuznetsov | ce59fec | 2015-05-06 17:47:46 -0700 | [diff] [blame] | 588 | } |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 589 | channel->numa_node = next_node; |
| 590 | primary = channel; |
Vitaly Kuznetsov | ce59fec | 2015-05-06 17:47:46 -0700 | [diff] [blame] | 591 | } |
K. Y. Srinivasan | 9f01ec53 | 2015-08-05 00:52:38 -0700 | [diff] [blame] | 592 | alloced_mask = &hv_context.hv_numa_map[primary->numa_node]; |
Vitaly Kuznetsov | ce59fec | 2015-05-06 17:47:46 -0700 | [diff] [blame] | 593 | |
K. Y. Srinivasan | 9f01ec53 | 2015-08-05 00:52:38 -0700 | [diff] [blame] | 594 | if (cpumask_weight(alloced_mask) == |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 595 | cpumask_weight(cpumask_of_node(primary->numa_node))) { |
| 596 | /* |
| 597 | * We have cycled through all the CPUs in the node; |
| 598 | * reset the alloced map. |
| 599 | */ |
K. Y. Srinivasan | 9f01ec53 | 2015-08-05 00:52:38 -0700 | [diff] [blame] | 600 | cpumask_clear(alloced_mask); |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 601 | } |
| 602 | |
K. Y. Srinivasan | 9f01ec53 | 2015-08-05 00:52:38 -0700 | [diff] [blame] | 603 | cpumask_xor(&available_mask, alloced_mask, |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 604 | cpumask_of_node(primary->numa_node)); |
| 605 | |
Dexuan Cui | 3b71107 | 2015-08-05 00:52:39 -0700 | [diff] [blame] | 606 | cur_cpu = -1; |
Vitaly Kuznetsov | 79fd8e7 | 2016-01-27 22:29:34 -0800 | [diff] [blame] | 607 | |
K. Y. Srinivasan | 509879b | 2016-09-02 05:58:23 -0700 | [diff] [blame] | 608 | if (primary->affinity_policy == HV_LOCALIZED) { |
| 609 | /* |
| 610 | * Normally Hyper-V host doesn't create more subchannels |
| 611 | * than there are VCPUs on the node but it is possible when not |
| 612 | * all present VCPUs on the node are initialized by guest. |
| 613 | * Clear the alloced_cpus_in_node to start over. |
| 614 | */ |
| 615 | if (cpumask_equal(&primary->alloced_cpus_in_node, |
| 616 | cpumask_of_node(primary->numa_node))) |
| 617 | cpumask_clear(&primary->alloced_cpus_in_node); |
| 618 | } |
Vitaly Kuznetsov | 79fd8e7 | 2016-01-27 22:29:34 -0800 | [diff] [blame] | 619 | |
Dexuan Cui | 3b71107 | 2015-08-05 00:52:39 -0700 | [diff] [blame] | 620 | while (true) { |
| 621 | cur_cpu = cpumask_next(cur_cpu, &available_mask); |
| 622 | if (cur_cpu >= nr_cpu_ids) { |
| 623 | cur_cpu = -1; |
| 624 | cpumask_copy(&available_mask, |
| 625 | cpumask_of_node(primary->numa_node)); |
| 626 | continue; |
| 627 | } |
| 628 | |
K. Y. Srinivasan | 509879b | 2016-09-02 05:58:23 -0700 | [diff] [blame] | 629 | if (primary->affinity_policy == HV_LOCALIZED) { |
| 630 | /* |
| 631 | * NOTE: in the case of sub-channel, we clear the |
| 632 | * sub-channel related bit(s) in |
| 633 | * primary->alloced_cpus_in_node in |
| 634 | * hv_process_channel_removal(), so when we |
| 635 | * reload drivers like hv_netvsc in SMP guest, here |
| 636 | * we're able to re-allocate |
| 637 | * bit from primary->alloced_cpus_in_node. |
| 638 | */ |
| 639 | if (!cpumask_test_cpu(cur_cpu, |
| 640 | &primary->alloced_cpus_in_node)) { |
| 641 | cpumask_set_cpu(cur_cpu, |
| 642 | &primary->alloced_cpus_in_node); |
| 643 | cpumask_set_cpu(cur_cpu, alloced_mask); |
| 644 | break; |
| 645 | } |
| 646 | } else { |
Dexuan Cui | 3b71107 | 2015-08-05 00:52:39 -0700 | [diff] [blame] | 647 | cpumask_set_cpu(cur_cpu, alloced_mask); |
| 648 | break; |
| 649 | } |
| 650 | } |
K. Y. Srinivasan | 1f656ff | 2015-05-30 23:37:48 -0700 | [diff] [blame] | 651 | |
K. Y. Srinivasan | d3ba720 | 2014-04-08 18:45:53 -0700 | [diff] [blame] | 652 | channel->target_cpu = cur_cpu; |
| 653 | channel->target_vp = hv_context.vp_index[cur_cpu]; |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 656 | static void vmbus_wait_for_unload(void) |
| 657 | { |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 658 | int cpu; |
| 659 | void *page_addr; |
| 660 | struct hv_message *msg; |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 661 | struct vmbus_channel_message_header *hdr; |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 662 | u32 message_type; |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 663 | |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 664 | /* |
| 665 | * CHANNELMSG_UNLOAD_RESPONSE is always delivered to the CPU which was |
| 666 | * used for initial contact or to CPU0 depending on host version. When |
| 667 | * we're crashing on a different CPU let's hope that IRQ handler on |
| 668 | * the cpu which receives CHANNELMSG_UNLOAD_RESPONSE is still |
| 669 | * functional and vmbus_unload_response() will complete |
| 670 | * vmbus_connection.unload_event. If not, the last thing we can do is |
| 671 | * read message pages for all CPUs directly. |
| 672 | */ |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 673 | while (1) { |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 674 | if (completion_done(&vmbus_connection.unload_event)) |
| 675 | break; |
| 676 | |
| 677 | for_each_online_cpu(cpu) { |
| 678 | page_addr = hv_context.synic_message_page[cpu]; |
| 679 | msg = (struct hv_message *)page_addr + |
| 680 | VMBUS_MESSAGE_SINT; |
| 681 | |
| 682 | message_type = READ_ONCE(msg->header.message_type); |
| 683 | if (message_type == HVMSG_NONE) |
| 684 | continue; |
| 685 | |
| 686 | hdr = (struct vmbus_channel_message_header *) |
| 687 | msg->u.payload; |
| 688 | |
| 689 | if (hdr->msgtype == CHANNELMSG_UNLOAD_RESPONSE) |
| 690 | complete(&vmbus_connection.unload_event); |
| 691 | |
| 692 | vmbus_signal_eom(msg, message_type); |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 693 | } |
| 694 | |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 695 | mdelay(10); |
| 696 | } |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 697 | |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 698 | /* |
| 699 | * We're crashing and already got the UNLOAD_RESPONSE, cleanup all |
| 700 | * maybe-pending messages on all CPUs to be able to receive new |
| 701 | * messages after we reconnect. |
| 702 | */ |
| 703 | for_each_online_cpu(cpu) { |
| 704 | page_addr = hv_context.synic_message_page[cpu]; |
| 705 | msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; |
| 706 | msg->header.message_type = HVMSG_NONE; |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 710 | /* |
K. Y. Srinivasan | 2db84ef | 2015-04-22 21:31:32 -0700 | [diff] [blame] | 711 | * vmbus_unload_response - Handler for the unload response. |
| 712 | */ |
| 713 | static void vmbus_unload_response(struct vmbus_channel_message_header *hdr) |
| 714 | { |
| 715 | /* |
| 716 | * This is a global event; just wakeup the waiting thread. |
| 717 | * Once we successfully unload, we can cleanup the monitor state. |
| 718 | */ |
| 719 | complete(&vmbus_connection.unload_event); |
| 720 | } |
| 721 | |
Vitaly Kuznetsov | 75ff3a8 | 2016-02-26 15:13:16 -0800 | [diff] [blame] | 722 | void vmbus_initiate_unload(bool crash) |
K. Y. Srinivasan | 2db84ef | 2015-04-22 21:31:32 -0700 | [diff] [blame] | 723 | { |
| 724 | struct vmbus_channel_message_header hdr; |
| 725 | |
Vitaly Kuznetsov | 4a54243 | 2015-08-01 16:08:19 -0700 | [diff] [blame] | 726 | /* Pre-Win2012R2 hosts don't support reconnect */ |
| 727 | if (vmbus_proto_version < VERSION_WIN8_1) |
| 728 | return; |
| 729 | |
K. Y. Srinivasan | 2db84ef | 2015-04-22 21:31:32 -0700 | [diff] [blame] | 730 | init_completion(&vmbus_connection.unload_event); |
| 731 | memset(&hdr, 0, sizeof(struct vmbus_channel_message_header)); |
| 732 | hdr.msgtype = CHANNELMSG_UNLOAD; |
| 733 | vmbus_post_msg(&hdr, sizeof(struct vmbus_channel_message_header)); |
| 734 | |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 735 | /* |
| 736 | * vmbus_initiate_unload() is also called on crash and the crash can be |
| 737 | * happening in an interrupt context, where scheduling is impossible. |
| 738 | */ |
Vitaly Kuznetsov | 75ff3a8 | 2016-02-26 15:13:16 -0800 | [diff] [blame] | 739 | if (!crash) |
Vitaly Kuznetsov | 4157191 | 2016-01-27 22:29:35 -0800 | [diff] [blame] | 740 | wait_for_completion(&vmbus_connection.unload_event); |
| 741 | else |
| 742 | vmbus_wait_for_unload(); |
K. Y. Srinivasan | 2db84ef | 2015-04-22 21:31:32 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 746 | * vmbus_onoffer - Handler for channel offers from vmbus in parent partition. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 747 | * |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 748 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 749 | static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 750 | { |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 751 | struct vmbus_channel_offer_channel *offer; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 752 | struct vmbus_channel *newchannel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 753 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 754 | offer = (struct vmbus_channel_offer_channel *)hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 755 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 756 | /* Allocate the channel object and save this offer. */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 757 | newchannel = alloc_channel(); |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 758 | if (!newchannel) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 759 | pr_err("Unable to allocate channel object\n"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 760 | return; |
| 761 | } |
| 762 | |
K. Y. Srinivasan | 132368b | 2012-12-01 06:46:33 -0800 | [diff] [blame] | 763 | /* |
| 764 | * By default we setup state to enable batched |
| 765 | * reading. A specific service can choose to |
| 766 | * disable this prior to opening the channel. |
| 767 | */ |
| 768 | newchannel->batched_reading = true; |
| 769 | |
K. Y. Srinivasan | b3bf60c | 2012-12-01 06:46:45 -0800 | [diff] [blame] | 770 | /* |
| 771 | * Setup state for signalling the host. |
| 772 | */ |
| 773 | newchannel->sig_event = (struct hv_input_signal_event *) |
| 774 | (ALIGN((unsigned long) |
| 775 | &newchannel->sig_buf, |
| 776 | HV_HYPERCALL_PARAM_ALIGN)); |
| 777 | |
| 778 | newchannel->sig_event->connectionid.asu32 = 0; |
| 779 | newchannel->sig_event->connectionid.u.id = VMBUS_EVENT_CONNECTION_ID; |
| 780 | newchannel->sig_event->flag_number = 0; |
| 781 | newchannel->sig_event->rsvdz = 0; |
| 782 | |
| 783 | if (vmbus_proto_version != VERSION_WS2008) { |
| 784 | newchannel->is_dedicated_interrupt = |
| 785 | (offer->is_dedicated_interrupt != 0); |
| 786 | newchannel->sig_event->connectionid.u.id = |
| 787 | offer->connection_id; |
| 788 | } |
| 789 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 790 | memcpy(&newchannel->offermsg, offer, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 791 | sizeof(struct vmbus_channel_offer_channel)); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 792 | newchannel->monitor_grp = (u8)offer->monitorid / 32; |
| 793 | newchannel->monitor_bit = (u8)offer->monitorid % 32; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 794 | |
K. Y. Srinivasan | 2dd37cb | 2015-02-28 11:18:18 -0800 | [diff] [blame] | 795 | vmbus_process_offer(newchannel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 798 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 799 | * vmbus_onoffer_rescind - Rescind offer handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 800 | * |
| 801 | * We queue a work item to process this offer synchronously |
| 802 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 803 | static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 804 | { |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 805 | struct vmbus_channel_rescind_offer *rescind; |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 806 | struct vmbus_channel *channel; |
Dexuan Cui | d43e2fe | 2015-03-27 09:10:09 -0700 | [diff] [blame] | 807 | unsigned long flags; |
| 808 | struct device *dev; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 809 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 810 | rescind = (struct vmbus_channel_rescind_offer *)hdr; |
Dexuan Cui | 85d9aa7 | 2016-01-27 22:29:43 -0800 | [diff] [blame] | 811 | |
| 812 | mutex_lock(&vmbus_connection.channel_mutex); |
Dexuan Cui | d43e2fe | 2015-03-27 09:10:09 -0700 | [diff] [blame] | 813 | channel = relid2channel(rescind->child_relid); |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 814 | |
K. Y. Srinivasan | 2dd37cb | 2015-02-28 11:18:18 -0800 | [diff] [blame] | 815 | if (channel == NULL) { |
Dexuan Cui | f52078c | 2015-12-14 16:01:50 -0800 | [diff] [blame] | 816 | /* |
| 817 | * This is very impossible, because in |
| 818 | * vmbus_process_offer(), we have already invoked |
| 819 | * vmbus_release_relid() on error. |
| 820 | */ |
Dexuan Cui | 85d9aa7 | 2016-01-27 22:29:43 -0800 | [diff] [blame] | 821 | goto out; |
K. Y. Srinivasan | 2dd37cb | 2015-02-28 11:18:18 -0800 | [diff] [blame] | 822 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 823 | |
Dexuan Cui | d43e2fe | 2015-03-27 09:10:09 -0700 | [diff] [blame] | 824 | spin_lock_irqsave(&channel->lock, flags); |
| 825 | channel->rescind = true; |
| 826 | spin_unlock_irqrestore(&channel->lock, flags); |
| 827 | |
| 828 | if (channel->device_obj) { |
Dexuan Cui | 499e840 | 2016-01-27 22:29:42 -0800 | [diff] [blame] | 829 | if (channel->chn_rescind_callback) { |
| 830 | channel->chn_rescind_callback(channel); |
Dexuan Cui | 85d9aa7 | 2016-01-27 22:29:43 -0800 | [diff] [blame] | 831 | goto out; |
Dexuan Cui | 499e840 | 2016-01-27 22:29:42 -0800 | [diff] [blame] | 832 | } |
Dexuan Cui | d43e2fe | 2015-03-27 09:10:09 -0700 | [diff] [blame] | 833 | /* |
| 834 | * We will have to unregister this device from the |
| 835 | * driver core. |
| 836 | */ |
| 837 | dev = get_device(&channel->device_obj->device); |
| 838 | if (dev) { |
| 839 | vmbus_device_unregister(channel->device_obj); |
| 840 | put_device(dev); |
| 841 | } |
| 842 | } else { |
| 843 | hv_process_channel_removal(channel, |
| 844 | channel->offermsg.child_relid); |
K. Y. Srinivasan | 2dd37cb | 2015-02-28 11:18:18 -0800 | [diff] [blame] | 845 | } |
Dexuan Cui | 85d9aa7 | 2016-01-27 22:29:43 -0800 | [diff] [blame] | 846 | |
| 847 | out: |
| 848 | mutex_unlock(&vmbus_connection.channel_mutex); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Dexuan Cui | 85d9aa7 | 2016-01-27 22:29:43 -0800 | [diff] [blame] | 851 | void vmbus_hvsock_device_unregister(struct vmbus_channel *channel) |
| 852 | { |
| 853 | mutex_lock(&vmbus_connection.channel_mutex); |
| 854 | |
| 855 | BUG_ON(!is_hvsock_channel(channel)); |
| 856 | |
| 857 | channel->rescind = true; |
| 858 | vmbus_device_unregister(channel->device_obj); |
| 859 | |
| 860 | mutex_unlock(&vmbus_connection.channel_mutex); |
| 861 | } |
| 862 | EXPORT_SYMBOL_GPL(vmbus_hvsock_device_unregister); |
| 863 | |
| 864 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 865 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 866 | * vmbus_onoffers_delivered - |
| 867 | * This is invoked when all offers have been delivered. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 868 | * |
| 869 | * Nothing to do here. |
| 870 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 871 | static void vmbus_onoffers_delivered( |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 872 | struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 873 | { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 876 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 877 | * vmbus_onopen_result - Open result handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 878 | * |
| 879 | * This is invoked when we received a response to our channel open request. |
| 880 | * Find the matching request, copy the response and signal the requesting |
| 881 | * thread. |
| 882 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 883 | static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 884 | { |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 885 | struct vmbus_channel_open_result *result; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 886 | struct vmbus_channel_msginfo *msginfo; |
| 887 | struct vmbus_channel_message_header *requestheader; |
| 888 | struct vmbus_channel_open_channel *openmsg; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 889 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 890 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 891 | result = (struct vmbus_channel_open_result *)hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 892 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 893 | /* |
| 894 | * Find the open msg, copy the result and signal/unblock the wait event |
| 895 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 896 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 897 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 898 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 899 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 900 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 901 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 902 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 903 | if (requestheader->msgtype == CHANNELMSG_OPENCHANNEL) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 904 | openmsg = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 905 | (struct vmbus_channel_open_channel *)msginfo->msg; |
| 906 | if (openmsg->child_relid == result->child_relid && |
| 907 | openmsg->openid == result->openid) { |
| 908 | memcpy(&msginfo->response.open_result, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 909 | result, |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 910 | sizeof( |
| 911 | struct vmbus_channel_open_result)); |
| 912 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 913 | break; |
| 914 | } |
| 915 | } |
| 916 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 917 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 920 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 921 | * vmbus_ongpadl_created - GPADL created handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 922 | * |
| 923 | * This is invoked when we received a response to our gpadl create request. |
| 924 | * Find the matching request, copy the response and signal the requesting |
| 925 | * thread. |
| 926 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 927 | static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 928 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 929 | struct vmbus_channel_gpadl_created *gpadlcreated; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 930 | struct vmbus_channel_msginfo *msginfo; |
| 931 | struct vmbus_channel_message_header *requestheader; |
| 932 | struct vmbus_channel_gpadl_header *gpadlheader; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 933 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 934 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 935 | gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 936 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 937 | /* |
| 938 | * Find the establish msg, copy the result and signal/unblock the wait |
| 939 | * event |
| 940 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 941 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 942 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 943 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 944 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 945 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 946 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 947 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 948 | if (requestheader->msgtype == CHANNELMSG_GPADL_HEADER) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 949 | gpadlheader = |
| 950 | (struct vmbus_channel_gpadl_header *)requestheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 951 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 952 | if ((gpadlcreated->child_relid == |
| 953 | gpadlheader->child_relid) && |
| 954 | (gpadlcreated->gpadl == gpadlheader->gpadl)) { |
| 955 | memcpy(&msginfo->response.gpadl_created, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 956 | gpadlcreated, |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 957 | sizeof( |
| 958 | struct vmbus_channel_gpadl_created)); |
| 959 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 960 | break; |
| 961 | } |
| 962 | } |
| 963 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 964 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 967 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 968 | * vmbus_ongpadl_torndown - GPADL torndown handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 969 | * |
| 970 | * This is invoked when we received a response to our gpadl teardown request. |
| 971 | * Find the matching request, copy the response and signal the requesting |
| 972 | * thread. |
| 973 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 974 | static void vmbus_ongpadl_torndown( |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 975 | struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 976 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 977 | struct vmbus_channel_gpadl_torndown *gpadl_torndown; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 978 | struct vmbus_channel_msginfo *msginfo; |
| 979 | struct vmbus_channel_message_header *requestheader; |
| 980 | struct vmbus_channel_gpadl_teardown *gpadl_teardown; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 981 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 982 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 983 | gpadl_torndown = (struct vmbus_channel_gpadl_torndown *)hdr; |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 984 | |
| 985 | /* |
| 986 | * Find the open msg, copy the result and signal/unblock the wait event |
| 987 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 988 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 989 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 990 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 991 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 992 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 993 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 994 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 995 | if (requestheader->msgtype == CHANNELMSG_GPADL_TEARDOWN) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 996 | gpadl_teardown = |
| 997 | (struct vmbus_channel_gpadl_teardown *)requestheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 998 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 999 | if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) { |
| 1000 | memcpy(&msginfo->response.gpadl_torndown, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1001 | gpadl_torndown, |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 1002 | sizeof( |
| 1003 | struct vmbus_channel_gpadl_torndown)); |
| 1004 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1005 | break; |
| 1006 | } |
| 1007 | } |
| 1008 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 1009 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1012 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 1013 | * vmbus_onversion_response - Version response handler |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 1014 | * |
| 1015 | * This is invoked when we received a response to our initiate contact request. |
| 1016 | * Find the matching request, copy the response and signal the requesting |
| 1017 | * thread. |
| 1018 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 1019 | static void vmbus_onversion_response( |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 1020 | struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1021 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1022 | struct vmbus_channel_msginfo *msginfo; |
| 1023 | struct vmbus_channel_message_header *requestheader; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1024 | struct vmbus_channel_version_response *version_response; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 1025 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1026 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1027 | version_response = (struct vmbus_channel_version_response *)hdr; |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 1028 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1029 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 1030 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 1031 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1032 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 1033 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1034 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 1035 | if (requestheader->msgtype == |
| 1036 | CHANNELMSG_INITIATE_CONTACT) { |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 1037 | memcpy(&msginfo->response.version_response, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1038 | version_response, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 1039 | sizeof(struct vmbus_channel_version_response)); |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 1040 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1041 | } |
| 1042 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 1043 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
Greg Kroah-Hartman | c8212f0 | 2009-08-31 21:51:50 -0700 | [diff] [blame] | 1046 | /* Channel message dispatch table */ |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1047 | struct vmbus_channel_message_table_entry |
K. Y. Srinivasan | b7c6b02 | 2011-05-10 07:55:38 -0700 | [diff] [blame] | 1048 | channel_message_table[CHANNELMSG_COUNT] = { |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1049 | {CHANNELMSG_INVALID, 0, NULL}, |
| 1050 | {CHANNELMSG_OFFERCHANNEL, 0, vmbus_onoffer}, |
| 1051 | {CHANNELMSG_RESCIND_CHANNELOFFER, 0, vmbus_onoffer_rescind}, |
| 1052 | {CHANNELMSG_REQUESTOFFERS, 0, NULL}, |
| 1053 | {CHANNELMSG_ALLOFFERS_DELIVERED, 1, vmbus_onoffers_delivered}, |
| 1054 | {CHANNELMSG_OPENCHANNEL, 0, NULL}, |
| 1055 | {CHANNELMSG_OPENCHANNEL_RESULT, 1, vmbus_onopen_result}, |
| 1056 | {CHANNELMSG_CLOSECHANNEL, 0, NULL}, |
| 1057 | {CHANNELMSG_GPADL_HEADER, 0, NULL}, |
| 1058 | {CHANNELMSG_GPADL_BODY, 0, NULL}, |
| 1059 | {CHANNELMSG_GPADL_CREATED, 1, vmbus_ongpadl_created}, |
| 1060 | {CHANNELMSG_GPADL_TEARDOWN, 0, NULL}, |
| 1061 | {CHANNELMSG_GPADL_TORNDOWN, 1, vmbus_ongpadl_torndown}, |
| 1062 | {CHANNELMSG_RELID_RELEASED, 0, NULL}, |
| 1063 | {CHANNELMSG_INITIATE_CONTACT, 0, NULL}, |
| 1064 | {CHANNELMSG_VERSION_RESPONSE, 1, vmbus_onversion_response}, |
| 1065 | {CHANNELMSG_UNLOAD, 0, NULL}, |
K. Y. Srinivasan | 2db84ef | 2015-04-22 21:31:32 -0700 | [diff] [blame] | 1066 | {CHANNELMSG_UNLOAD_RESPONSE, 1, vmbus_unload_response}, |
Dexuan Cui | 5c23a1a | 2016-01-27 22:29:40 -0800 | [diff] [blame] | 1067 | {CHANNELMSG_18, 0, NULL}, |
| 1068 | {CHANNELMSG_19, 0, NULL}, |
| 1069 | {CHANNELMSG_20, 0, NULL}, |
| 1070 | {CHANNELMSG_TL_CONNECT_REQUEST, 0, NULL}, |
Greg Kroah-Hartman | c8212f0 | 2009-08-31 21:51:50 -0700 | [diff] [blame] | 1071 | }; |
| 1072 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1073 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 1074 | * vmbus_onmessage - Handler for channel protocol messages. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 1075 | * |
| 1076 | * This is invoked in the vmbus worker thread context. |
| 1077 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 1078 | void vmbus_onmessage(void *context) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1079 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1080 | struct hv_message *msg = context; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 1081 | struct vmbus_channel_message_header *hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1082 | int size; |
| 1083 | |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 1084 | hdr = (struct vmbus_channel_message_header *)msg->u.payload; |
| 1085 | size = msg->header.payload_size; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1086 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 1087 | if (hdr->msgtype >= CHANNELMSG_COUNT) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1088 | pr_err("Received invalid channel message type %d size %d\n", |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 1089 | hdr->msgtype, size); |
Greg Kroah-Hartman | 04f50c4 | 2009-07-16 12:35:37 -0700 | [diff] [blame] | 1090 | print_hex_dump_bytes("", DUMP_PREFIX_NONE, |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 1091 | (unsigned char *)msg->u.payload, size); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1092 | return; |
| 1093 | } |
| 1094 | |
K. Y. Srinivasan | b7c6b02 | 2011-05-10 07:55:38 -0700 | [diff] [blame] | 1095 | if (channel_message_table[hdr->msgtype].message_handler) |
| 1096 | channel_message_table[hdr->msgtype].message_handler(hdr); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1097 | else |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1098 | pr_err("Unhandled channel message type %d\n", hdr->msgtype); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1101 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 1102 | * 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] | 1103 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 1104 | int vmbus_request_offers(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1105 | { |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 1106 | struct vmbus_channel_message_header *msg; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1107 | struct vmbus_channel_msginfo *msginfo; |
Nicholas Mc Guire | 51e5181 | 2015-02-27 11:26:02 -0800 | [diff] [blame] | 1108 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1109 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1110 | msginfo = kmalloc(sizeof(*msginfo) + |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 1111 | sizeof(struct vmbus_channel_message_header), |
| 1112 | GFP_KERNEL); |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 1113 | if (!msginfo) |
Bill Pemberton | 75910f2 | 2010-05-05 15:27:31 -0400 | [diff] [blame] | 1114 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1115 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 1116 | msg = (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1117 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 1118 | msg->msgtype = CHANNELMSG_REQUESTOFFERS; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1119 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1120 | |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 1121 | ret = vmbus_post_msg(msg, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 1122 | sizeof(struct vmbus_channel_message_header)); |
| 1123 | if (ret != 0) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1124 | pr_err("Unable to request offers - %d\n", ret); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1125 | |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 1126 | goto cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1127 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1128 | |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 1129 | cleanup: |
Ilia Mirkin | dd9b15d | 2011-03-13 00:29:00 -0500 | [diff] [blame] | 1130 | kfree(msginfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1131 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1132 | return ret; |
| 1133 | } |
| 1134 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 1135 | /* |
| 1136 | * Retrieve the (sub) channel on which to send an outgoing request. |
K. Y. Srinivasan | a13e8bb | 2015-02-28 11:39:02 -0800 | [diff] [blame] | 1137 | * When a primary channel has multiple sub-channels, we try to |
| 1138 | * distribute the load equally amongst all available channels. |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 1139 | */ |
| 1140 | struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary) |
| 1141 | { |
| 1142 | struct list_head *cur, *tmp; |
K. Y. Srinivasan | 87712bf8 | 2014-12-14 23:34:51 -0800 | [diff] [blame] | 1143 | int cur_cpu; |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 1144 | struct vmbus_channel *cur_channel; |
| 1145 | struct vmbus_channel *outgoing_channel = primary; |
K. Y. Srinivasan | a13e8bb | 2015-02-28 11:39:02 -0800 | [diff] [blame] | 1146 | int next_channel; |
| 1147 | int i = 1; |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 1148 | |
| 1149 | if (list_empty(&primary->sc_list)) |
| 1150 | return outgoing_channel; |
| 1151 | |
K. Y. Srinivasan | a13e8bb | 2015-02-28 11:39:02 -0800 | [diff] [blame] | 1152 | next_channel = primary->next_oc++; |
| 1153 | |
| 1154 | if (next_channel > (primary->num_sc)) { |
| 1155 | primary->next_oc = 0; |
| 1156 | return outgoing_channel; |
| 1157 | } |
| 1158 | |
K. Y. Srinivasan | 87712bf8 | 2014-12-14 23:34:51 -0800 | [diff] [blame] | 1159 | cur_cpu = hv_context.vp_index[get_cpu()]; |
| 1160 | put_cpu(); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 1161 | list_for_each_safe(cur, tmp, &primary->sc_list) { |
| 1162 | cur_channel = list_entry(cur, struct vmbus_channel, sc_list); |
| 1163 | if (cur_channel->state != CHANNEL_OPENED_STATE) |
| 1164 | continue; |
| 1165 | |
| 1166 | if (cur_channel->target_vp == cur_cpu) |
| 1167 | return cur_channel; |
| 1168 | |
K. Y. Srinivasan | a13e8bb | 2015-02-28 11:39:02 -0800 | [diff] [blame] | 1169 | if (i == next_channel) |
| 1170 | return cur_channel; |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 1171 | |
K. Y. Srinivasan | a13e8bb | 2015-02-28 11:39:02 -0800 | [diff] [blame] | 1172 | i++; |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | return outgoing_channel; |
| 1176 | } |
| 1177 | EXPORT_SYMBOL_GPL(vmbus_get_outgoing_channel); |
| 1178 | |
| 1179 | static void invoke_sc_cb(struct vmbus_channel *primary_channel) |
| 1180 | { |
| 1181 | struct list_head *cur, *tmp; |
| 1182 | struct vmbus_channel *cur_channel; |
| 1183 | |
| 1184 | if (primary_channel->sc_creation_callback == NULL) |
| 1185 | return; |
| 1186 | |
| 1187 | list_for_each_safe(cur, tmp, &primary_channel->sc_list) { |
| 1188 | cur_channel = list_entry(cur, struct vmbus_channel, sc_list); |
| 1189 | |
| 1190 | primary_channel->sc_creation_callback(cur_channel); |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel, |
| 1195 | void (*sc_cr_cb)(struct vmbus_channel *new_sc)) |
| 1196 | { |
| 1197 | primary_channel->sc_creation_callback = sc_cr_cb; |
| 1198 | } |
| 1199 | EXPORT_SYMBOL_GPL(vmbus_set_sc_create_callback); |
| 1200 | |
| 1201 | bool vmbus_are_subchannels_present(struct vmbus_channel *primary) |
| 1202 | { |
| 1203 | bool ret; |
| 1204 | |
| 1205 | ret = !list_empty(&primary->sc_list); |
| 1206 | |
| 1207 | if (ret) { |
| 1208 | /* |
| 1209 | * Invoke the callback on sub-channel creation. |
| 1210 | * This will present a uniform interface to the |
| 1211 | * clients. |
| 1212 | */ |
| 1213 | invoke_sc_cb(primary); |
| 1214 | } |
| 1215 | |
| 1216 | return ret; |
| 1217 | } |
| 1218 | EXPORT_SYMBOL_GPL(vmbus_are_subchannels_present); |
Dexuan Cui | 499e840 | 2016-01-27 22:29:42 -0800 | [diff] [blame] | 1219 | |
| 1220 | void vmbus_set_chn_rescind_callback(struct vmbus_channel *channel, |
| 1221 | void (*chn_rescind_cb)(struct vmbus_channel *)) |
| 1222 | { |
| 1223 | channel->chn_rescind_callback = chn_rescind_cb; |
| 1224 | } |
| 1225 | EXPORT_SYMBOL_GPL(vmbus_set_chn_rescind_callback); |