blob: b6c1211b4df72959ad0cf4c3a6a5950ca7a560b8 [file] [log] [blame]
Hank Janssen3e7ee492009-07-13 16:02:34 -07001/*
Hank Janssen3e7ee492009-07-13 16:02:34 -07002 * 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 Janssen3e7ee492009-07-13 16:02:34 -070020 */
Hank Janssen0a466182011-03-29 13:58:47 -070021#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
Greg Kroah-Hartmana0086dc2009-08-17 17:22:08 -070023#include <linux/kernel.h>
K. Y. Srinivasan0c3b7b22011-02-11 09:59:43 -080024#include <linux/sched.h>
25#include <linux/wait.h>
Greg Kroah-Hartmana0086dc2009-08-17 17:22:08 -070026#include <linux/mm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Bill Pemberton53af5452009-09-11 21:46:44 -040028#include <linux/list.h>
Hank Janssenc88c4e42010-05-04 15:55:05 -070029#include <linux/module.h>
Haiyang Zhang8b5d6d32010-05-28 23:22:44 +000030#include <linux/completion.h>
Vitaly Kuznetsov41571912016-01-27 22:29:35 -080031#include <linux/delay.h>
Greg Kroah-Hartman46a97192011-10-04 12:29:52 -070032#include <linux/hyperv.h>
K. Y. Srinivasan3f335ea2011-05-12 19:34:15 -070033
K. Y. Srinivasan0f2a6612011-05-12 19:34:28 -070034#include "hyperv_vmbus.h"
Hank Janssen3e7ee492009-07-13 16:02:34 -070035
K. Y. Srinivasan7047f172015-12-25 20:00:30 -080036static void init_vp_index(struct vmbus_channel *channel, u16 dev_type);
37
38static const struct vmbus_device vmbus_devs[] = {
39 /* IDE */
40 { .dev_type = HV_IDE,
41 HV_IDE_GUID,
42 .perf_device = true,
43 },
44
45 /* SCSI */
46 { .dev_type = HV_SCSI,
47 HV_SCSI_GUID,
48 .perf_device = true,
49 },
50
51 /* Fibre Channel */
52 { .dev_type = HV_FC,
53 HV_SYNTHFC_GUID,
54 .perf_device = true,
55 },
56
57 /* Synthetic NIC */
58 { .dev_type = HV_NIC,
59 HV_NIC_GUID,
60 .perf_device = true,
61 },
62
63 /* Network Direct */
64 { .dev_type = HV_ND,
65 HV_ND_GUID,
66 .perf_device = true,
67 },
68
69 /* PCIE */
70 { .dev_type = HV_PCIE,
71 HV_PCIE_GUID,
72 .perf_device = true,
73 },
74
75 /* Synthetic Frame Buffer */
76 { .dev_type = HV_FB,
77 HV_SYNTHVID_GUID,
78 .perf_device = false,
79 },
80
81 /* Synthetic Keyboard */
82 { .dev_type = HV_KBD,
83 HV_KBD_GUID,
84 .perf_device = false,
85 },
86
87 /* Synthetic MOUSE */
88 { .dev_type = HV_MOUSE,
89 HV_MOUSE_GUID,
90 .perf_device = false,
91 },
92
93 /* KVP */
94 { .dev_type = HV_KVP,
95 HV_KVP_GUID,
96 .perf_device = false,
97 },
98
99 /* Time Synch */
100 { .dev_type = HV_TS,
101 HV_TS_GUID,
102 .perf_device = false,
103 },
104
105 /* Heartbeat */
106 { .dev_type = HV_HB,
107 HV_HEART_BEAT_GUID,
108 .perf_device = false,
109 },
110
111 /* Shutdown */
112 { .dev_type = HV_SHUTDOWN,
113 HV_SHUTDOWN_GUID,
114 .perf_device = false,
115 },
116
117 /* File copy */
118 { .dev_type = HV_FCOPY,
119 HV_FCOPY_GUID,
120 .perf_device = false,
121 },
122
123 /* Backup */
124 { .dev_type = HV_BACKUP,
125 HV_VSS_GUID,
126 .perf_device = false,
127 },
128
129 /* Dynamic Memory */
130 { .dev_type = HV_DM,
131 HV_DM_GUID,
132 .perf_device = false,
133 },
134
135 /* Unknown GUID */
136 { .dev_type = HV_UNKOWN,
137 .perf_device = false,
138 },
139};
140
141static u16 hv_get_dev_type(const uuid_le *guid)
142{
143 u16 i;
144
145 for (i = HV_IDE; i < HV_UNKOWN; i++) {
146 if (!uuid_le_cmp(*guid, vmbus_devs[i].guid))
147 return i;
148 }
149 pr_info("Unknown GUID: %pUl\n", guid);
150 return i;
151}
Vitaly Kuznetsovf38e7dd2015-05-06 17:47:45 -0700152
Hank Janssenc88c4e42010-05-04 15:55:05 -0700153/**
Greg Kroah-Hartmanda0e9632011-10-11 08:42:28 -0600154 * vmbus_prep_negotiate_resp() - Create default response for Hyper-V Negotiate message
Hank Janssenc88c4e42010-05-04 15:55:05 -0700155 * @icmsghdrp: Pointer to msg header structure
156 * @icmsg_negotiate: Pointer to negotiate message structure
157 * @buf: Raw buffer channel data
158 *
159 * @icmsghdrp is of type &struct icmsg_hdr.
160 * @negop is of type &struct icmsg_negotiate.
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -0700161 * Set up and fill in default negotiate response message.
162 *
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700163 * The fw_version specifies the framework version that
164 * we can support and srv_version specifies the service
165 * version we can support.
Hank Janssenc88c4e42010-05-04 15:55:05 -0700166 *
167 * Mainly used by Hyper-V drivers.
168 */
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700169bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp,
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -0700170 struct icmsg_negotiate *negop, u8 *buf,
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700171 int fw_version, int srv_version)
Hank Janssenc88c4e42010-05-04 15:55:05 -0700172{
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700173 int icframe_major, icframe_minor;
174 int icmsg_major, icmsg_minor;
175 int fw_major, fw_minor;
176 int srv_major, srv_minor;
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -0700177 int i;
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700178 bool found_match = false;
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -0700179
K. Y. Srinivasana3605302012-05-12 13:44:57 -0700180 icmsghdrp->icmsgsize = 0x10;
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700181 fw_major = (fw_version >> 16);
182 fw_minor = (fw_version & 0xFFFF);
183
184 srv_major = (srv_version >> 16);
185 srv_minor = (srv_version & 0xFFFF);
Hank Janssenc88c4e42010-05-04 15:55:05 -0700186
K. Y. Srinivasana3605302012-05-12 13:44:57 -0700187 negop = (struct icmsg_negotiate *)&buf[
188 sizeof(struct vmbuspipe_hdr) +
189 sizeof(struct icmsg_hdr)];
Hank Janssenc88c4e42010-05-04 15:55:05 -0700190
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700191 icframe_major = negop->icframe_vercnt;
192 icframe_minor = 0;
193
194 icmsg_major = negop->icmsg_vercnt;
195 icmsg_minor = 0;
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -0700196
197 /*
198 * Select the framework version number we will
199 * support.
200 */
201
202 for (i = 0; i < negop->icframe_vercnt; i++) {
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700203 if ((negop->icversion_data[i].major == fw_major) &&
204 (negop->icversion_data[i].minor == fw_minor)) {
205 icframe_major = negop->icversion_data[i].major;
206 icframe_minor = negop->icversion_data[i].minor;
207 found_match = true;
208 }
Hank Janssenc88c4e42010-05-04 15:55:05 -0700209 }
K. Y. Srinivasana3605302012-05-12 13:44:57 -0700210
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700211 if (!found_match)
212 goto fw_error;
213
214 found_match = false;
215
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -0700216 for (i = negop->icframe_vercnt;
217 (i < negop->icframe_vercnt + negop->icmsg_vercnt); i++) {
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700218 if ((negop->icversion_data[i].major == srv_major) &&
219 (negop->icversion_data[i].minor == srv_minor)) {
220 icmsg_major = negop->icversion_data[i].major;
221 icmsg_minor = negop->icversion_data[i].minor;
222 found_match = true;
223 }
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -0700224 }
225
226 /*
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700227 * Respond with the framework and service
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -0700228 * version numbers we can support.
229 */
K. Y. Srinivasan67413352013-07-02 10:31:30 -0700230
231fw_error:
232 if (!found_match) {
233 negop->icframe_vercnt = 0;
234 negop->icmsg_vercnt = 0;
235 } else {
236 negop->icframe_vercnt = 1;
237 negop->icmsg_vercnt = 1;
238 }
239
240 negop->icversion_data[0].major = icframe_major;
241 negop->icversion_data[0].minor = icframe_minor;
242 negop->icversion_data[1].major = icmsg_major;
243 negop->icversion_data[1].minor = icmsg_minor;
244 return found_match;
Hank Janssenc88c4e42010-05-04 15:55:05 -0700245}
K. Y. Srinivasana3605302012-05-12 13:44:57 -0700246
Greg Kroah-Hartmanda0e9632011-10-11 08:42:28 -0600247EXPORT_SYMBOL_GPL(vmbus_prep_negotiate_resp);
Hank Janssenc88c4e42010-05-04 15:55:05 -0700248
Hank Janssen3e189512010-03-04 22:11:00 +0000249/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700250 * alloc_channel - Allocate and initialize a vmbus channel object
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700251 */
Greg Kroah-Hartman50fe56d2010-10-20 15:51:57 -0700252static struct vmbus_channel *alloc_channel(void)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700253{
Vitaly Kuznetsovbc63b6f2015-02-27 11:25:52 -0800254 static atomic_t chan_num = ATOMIC_INIT(0);
Greg Kroah-Hartmanaded71652009-08-18 15:21:19 -0700255 struct vmbus_channel *channel;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700256
Greg Kroah-Hartmanaded71652009-08-18 15:21:19 -0700257 channel = kzalloc(sizeof(*channel), GFP_ATOMIC);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700258 if (!channel)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700259 return NULL;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700260
Vitaly Kuznetsovbc63b6f2015-02-27 11:25:52 -0800261 channel->id = atomic_inc_return(&chan_num);
K. Y. Srinivasanfe760e42016-01-27 22:29:45 -0800262 channel->acquire_ring_lock = true;
Greg Kroah-Hartman54411c42009-07-15 14:48:32 -0700263 spin_lock_init(&channel->inbound_lock);
Vitaly Kuznetsov67fae052015-01-20 16:45:05 +0100264 spin_lock_init(&channel->lock);
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700265
266 INIT_LIST_HEAD(&channel->sc_list);
K. Y. Srinivasan3a28fa32014-04-08 18:45:54 -0700267 INIT_LIST_HEAD(&channel->percpu_list);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700268
Hank Janssen3e7ee492009-07-13 16:02:34 -0700269 return channel;
270}
271
Hank Janssen3e189512010-03-04 22:11:00 +0000272/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700273 * free_channel - Release the resources used by the vmbus channel object
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700274 */
Greg Kroah-Hartman9f3e28e2011-10-11 09:40:01 -0600275static void free_channel(struct vmbus_channel *channel)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700276{
Dexuan Cuiaadc3782015-03-27 09:10:10 -0700277 kfree(channel);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700278}
279
K. Y. Srinivasan3a28fa32014-04-08 18:45:54 -0700280static void percpu_channel_enq(void *arg)
281{
282 struct vmbus_channel *channel = arg;
283 int cpu = smp_processor_id();
Haiyang Zhang8b5d6d32010-05-28 23:22:44 +0000284
K. Y. Srinivasan3a28fa32014-04-08 18:45:54 -0700285 list_add_tail(&channel->percpu_list, &hv_context.percpu_list[cpu]);
286}
287
288static void percpu_channel_deq(void *arg)
289{
290 struct vmbus_channel *channel = arg;
291
292 list_del(&channel->percpu_list);
293}
Haiyang Zhang8b5d6d32010-05-28 23:22:44 +0000294
K. Y. Srinivasaned6cfcc2015-02-28 11:18:17 -0800295
Dexuan Cuif52078c2015-12-14 16:01:50 -0800296static void vmbus_release_relid(u32 relid)
Timo Teräs4b2f9ab2010-12-15 20:48:09 +0200297{
K. Y. Srinivasaned6cfcc2015-02-28 11:18:17 -0800298 struct vmbus_channel_relid_released msg;
Vitaly Kuznetsov04a258c2014-11-04 13:40:11 +0100299
K. Y. Srinivasanc8705972013-03-15 12:25:44 -0700300 memset(&msg, 0, sizeof(struct vmbus_channel_relid_released));
K. Y. Srinivasaned6cfcc2015-02-28 11:18:17 -0800301 msg.child_relid = relid;
K. Y. Srinivasanc8705972013-03-15 12:25:44 -0700302 msg.header.msgtype = CHANNELMSG_RELID_RELEASED;
303 vmbus_post_msg(&msg, sizeof(struct vmbus_channel_relid_released));
Dexuan Cuif52078c2015-12-14 16:01:50 -0800304}
K. Y. Srinivasanc8705972013-03-15 12:25:44 -0700305
Dexuan Cuif52078c2015-12-14 16:01:50 -0800306void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid)
307{
308 unsigned long flags;
309 struct vmbus_channel *primary_channel;
310
311 vmbus_release_relid(relid);
K. Y. Srinivasaned6cfcc2015-02-28 11:18:17 -0800312
Dexuan Cui34c68012015-12-14 16:01:49 -0800313 BUG_ON(!channel->rescind);
Dexuan Cui85d9aa72016-01-27 22:29:43 -0800314 BUG_ON(!mutex_is_locked(&vmbus_connection.channel_mutex));
Dexuan Cui34c68012015-12-14 16:01:49 -0800315
K. Y. Srinivasan2115b562014-08-28 18:29:53 -0700316 if (channel->target_cpu != get_cpu()) {
317 put_cpu();
K. Y. Srinivasan3a28fa32014-04-08 18:45:54 -0700318 smp_call_function_single(channel->target_cpu,
319 percpu_channel_deq, channel, true);
K. Y. Srinivasan2115b562014-08-28 18:29:53 -0700320 } else {
K. Y. Srinivasan3a28fa32014-04-08 18:45:54 -0700321 percpu_channel_deq(channel);
K. Y. Srinivasan2115b562014-08-28 18:29:53 -0700322 put_cpu();
323 }
K. Y. Srinivasan3a28fa32014-04-08 18:45:54 -0700324
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700325 if (channel->primary_channel == NULL) {
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700326 list_del(&channel->listentry);
Dexuan Cuica1c4b72015-08-13 17:07:03 -0700327
328 primary_channel = channel;
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700329 } else {
330 primary_channel = channel->primary_channel;
Vitaly Kuznetsov67fae052015-01-20 16:45:05 +0100331 spin_lock_irqsave(&primary_channel->lock, flags);
K. Y. Srinivasan565ce642013-10-16 19:27:19 -0700332 list_del(&channel->sc_list);
Vitaly Kuznetsov357e8362015-05-06 17:47:44 -0700333 primary_channel->num_sc--;
Vitaly Kuznetsov67fae052015-01-20 16:45:05 +0100334 spin_unlock_irqrestore(&primary_channel->lock, flags);
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700335 }
Dexuan Cuica1c4b72015-08-13 17:07:03 -0700336
337 /*
338 * We need to free the bit for init_vp_index() to work in the case
339 * of sub-channel, when we reload drivers like hv_netvsc.
340 */
341 cpumask_clear_cpu(channel->target_cpu,
342 &primary_channel->alloced_cpus_in_node);
343
K. Y. Srinivasanc8705972013-03-15 12:25:44 -0700344 free_channel(channel);
Timo Teräs4b2f9ab2010-12-15 20:48:09 +0200345}
Haiyang Zhang8b5d6d32010-05-28 23:22:44 +0000346
K. Y. Srinivasan93e5bd02011-12-12 09:29:17 -0800347void vmbus_free_channels(void)
348{
Dexuan Cui813c5b72015-04-22 21:31:30 -0700349 struct vmbus_channel *channel, *tmp;
K. Y. Srinivasan93e5bd02011-12-12 09:29:17 -0800350
Dexuan Cui813c5b72015-04-22 21:31:30 -0700351 list_for_each_entry_safe(channel, tmp, &vmbus_connection.chn_list,
352 listentry) {
Dexuan Cui34c68012015-12-14 16:01:49 -0800353 /* hv_process_channel_removal() needs this */
Dexuan Cui813c5b72015-04-22 21:31:30 -0700354 channel->rescind = true;
355
K. Y. Srinivasan93e5bd02011-12-12 09:29:17 -0800356 vmbus_device_unregister(channel->device_obj);
K. Y. Srinivasan93e5bd02011-12-12 09:29:17 -0800357 }
358}
359
Hank Janssen3e189512010-03-04 22:11:00 +0000360/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700361 * vmbus_process_offer - Process the offer by creating a channel/device
Hank Janssenc88c4e42010-05-04 15:55:05 -0700362 * associated with this offer
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700363 */
K. Y. Srinivasan2dd37cb2015-02-28 11:18:18 -0800364static void vmbus_process_offer(struct vmbus_channel *newchannel)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700365{
Greg Kroah-Hartmanaded71652009-08-18 15:21:19 -0700366 struct vmbus_channel *channel;
Haiyang Zhang188963e2010-10-15 10:14:06 -0700367 bool fnew = true;
Greg Kroah-Hartman0f5e44c2009-07-15 14:57:16 -0700368 unsigned long flags;
K. Y. Srinivasan7047f172015-12-25 20:00:30 -0800369 u16 dev_type;
Dexuan Cui85d9aa72016-01-27 22:29:43 -0800370 int ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700371
Bill Pemberton454f18a2009-07-27 16:47:24 -0400372 /* Make sure this is a new offer */
Dexuan Cuid6f591e2015-12-14 16:01:51 -0800373 mutex_lock(&vmbus_connection.channel_mutex);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700374
Haiyang Zhangda9fcb72011-01-26 12:12:14 -0800375 list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) {
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700376 if (!uuid_le_cmp(channel->offermsg.offer.if_type,
377 newchannel->offermsg.offer.if_type) &&
378 !uuid_le_cmp(channel->offermsg.offer.if_instance,
379 newchannel->offermsg.offer.if_instance)) {
Haiyang Zhang188963e2010-10-15 10:14:06 -0700380 fnew = false;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700381 break;
382 }
383 }
384
Vitaly Kuznetsov8dfd3322015-05-06 17:47:42 -0700385 if (fnew)
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800386 list_add_tail(&newchannel->listentry,
Haiyang Zhangda9fcb72011-01-26 12:12:14 -0800387 &vmbus_connection.chn_list);
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700388
Dexuan Cuid6f591e2015-12-14 16:01:51 -0800389 mutex_unlock(&vmbus_connection.channel_mutex);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700390
Haiyang Zhang188963e2010-10-15 10:14:06 -0700391 if (!fnew) {
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700392 /*
393 * Check to see if this is a sub-channel.
394 */
395 if (newchannel->offermsg.offer.sub_channel_index != 0) {
396 /*
397 * Process the sub-channel.
398 */
399 newchannel->primary_channel = channel;
Vitaly Kuznetsov67fae052015-01-20 16:45:05 +0100400 spin_lock_irqsave(&channel->lock, flags);
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700401 list_add_tail(&newchannel->sc_list, &channel->sc_list);
K. Y. Srinivasana13e8bb2015-02-28 11:39:02 -0800402 channel->num_sc++;
Vitaly Kuznetsov357e8362015-05-06 17:47:44 -0700403 spin_unlock_irqrestore(&channel->lock, flags);
Vitaly Kuznetsov8dfd3322015-05-06 17:47:42 -0700404 } else
405 goto err_free_chan;
406 }
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700407
K. Y. Srinivasan7047f172015-12-25 20:00:30 -0800408 dev_type = hv_get_dev_type(&newchannel->offermsg.offer.if_type);
409
410 init_vp_index(newchannel, dev_type);
Vitaly Kuznetsovf38e7dd2015-05-06 17:47:45 -0700411
Vitaly Kuznetsov8dfd3322015-05-06 17:47:42 -0700412 if (newchannel->target_cpu != get_cpu()) {
413 put_cpu();
414 smp_call_function_single(newchannel->target_cpu,
415 percpu_channel_enq,
416 newchannel, true);
417 } else {
418 percpu_channel_enq(newchannel);
419 put_cpu();
Hank Janssen3e7ee492009-07-13 16:02:34 -0700420 }
421
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700422 /*
K. Y. Srinivasan42dceeb2013-08-26 14:08:58 -0700423 * This state is used to indicate a successful open
424 * so that when we do close the channel normally, we
425 * can cleanup properly
426 */
427 newchannel->state = CHANNEL_OPEN_STATE;
428
Vitaly Kuznetsov8dfd3322015-05-06 17:47:42 -0700429 if (!fnew) {
430 if (channel->sc_creation_callback != NULL)
431 channel->sc_creation_callback(newchannel);
432 return;
433 }
434
K. Y. Srinivasan42dceeb2013-08-26 14:08:58 -0700435 /*
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700436 * Start the process of binding this offer to the driver
437 * We need to set the DeviceObject field before calling
Haiyang Zhang646f1ea2011-01-26 12:12:10 -0800438 * vmbus_child_dev_add()
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700439 */
K. Y. Srinivasanf2c73012011-09-08 07:24:12 -0700440 newchannel->device_obj = vmbus_device_create(
Haiyang Zhang767dff62011-01-26 12:12:12 -0800441 &newchannel->offermsg.offer.if_type,
442 &newchannel->offermsg.offer.if_instance,
Haiyang Zhang188963e2010-10-15 10:14:06 -0700443 newchannel);
Vitaly Kuznetsov9c3a6f72015-01-20 16:45:04 +0100444 if (!newchannel->device_obj)
K. Y. Srinivasan5b1e5b52015-02-28 11:18:19 -0800445 goto err_deq_chan;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700446
K. Y. Srinivasan7047f172015-12-25 20:00:30 -0800447 newchannel->device_obj->device_id = dev_type;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400448 /*
449 * Add the new device to the bus. This will kick off device-driver
450 * binding which eventually invokes the device driver's AddDevice()
451 * method.
452 */
Dexuan Cui85d9aa72016-01-27 22:29:43 -0800453 mutex_lock(&vmbus_connection.channel_mutex);
454 ret = vmbus_device_register(newchannel->device_obj);
455 mutex_unlock(&vmbus_connection.channel_mutex);
456
457 if (ret != 0) {
Dexuan Cuid43e2fe2015-03-27 09:10:09 -0700458 pr_err("unable to add child device object (relid %d)\n",
459 newchannel->offermsg.child_relid);
460 kfree(newchannel->device_obj);
461 goto err_deq_chan;
462 }
Vitaly Kuznetsov9c3a6f72015-01-20 16:45:04 +0100463 return;
K. Y. Srinivasan2dd37cb2015-02-28 11:18:18 -0800464
K. Y. Srinivasan5b1e5b52015-02-28 11:18:19 -0800465err_deq_chan:
Dexuan Cuif52078c2015-12-14 16:01:50 -0800466 vmbus_release_relid(newchannel->offermsg.child_relid);
467
Dexuan Cuid6f591e2015-12-14 16:01:51 -0800468 mutex_lock(&vmbus_connection.channel_mutex);
K. Y. Srinivasan5b1e5b52015-02-28 11:18:19 -0800469 list_del(&newchannel->listentry);
Dexuan Cuid6f591e2015-12-14 16:01:51 -0800470 mutex_unlock(&vmbus_connection.channel_mutex);
K. Y. Srinivasan5b1e5b52015-02-28 11:18:19 -0800471
472 if (newchannel->target_cpu != get_cpu()) {
473 put_cpu();
474 smp_call_function_single(newchannel->target_cpu,
475 percpu_channel_deq, newchannel, true);
476 } else {
477 percpu_channel_deq(newchannel);
478 put_cpu();
479 }
480
Vitaly Kuznetsov9c3a6f72015-01-20 16:45:04 +0100481err_free_chan:
482 free_channel(newchannel);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700483}
484
K. Y. Srinivasana1198452012-12-01 06:46:50 -0800485/*
486 * We use this state to statically distribute the channel interrupt load.
487 */
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700488static int next_numa_node_id;
K. Y. Srinivasana1198452012-12-01 06:46:50 -0800489
490/*
491 * Starting with Win8, we can statically distribute the incoming
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700492 * channel interrupt load by binding a channel to VCPU.
493 * We do this in a hierarchical fashion:
494 * First distribute the primary channels across available NUMA nodes
495 * and then distribute the subchannels amongst the CPUs in the NUMA
496 * node assigned to the primary channel.
497 *
498 * For pre-win8 hosts or non-performance critical channels we assign the
499 * first CPU in the first NUMA node.
K. Y. Srinivasana1198452012-12-01 06:46:50 -0800500 */
K. Y. Srinivasan7047f172015-12-25 20:00:30 -0800501static void init_vp_index(struct vmbus_channel *channel, u16 dev_type)
K. Y. Srinivasana1198452012-12-01 06:46:50 -0800502{
503 u32 cur_cpu;
K. Y. Srinivasan7047f172015-12-25 20:00:30 -0800504 bool perf_chn = vmbus_devs[dev_type].perf_device;
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700505 struct vmbus_channel *primary = channel->primary_channel;
506 int next_node;
507 struct cpumask available_mask;
K. Y. Srinivasan9f01ec532015-08-05 00:52:38 -0700508 struct cpumask *alloced_mask;
K. Y. Srinivasana1198452012-12-01 06:46:50 -0800509
K. Y. Srinivasana1198452012-12-01 06:46:50 -0800510 if ((vmbus_proto_version == VERSION_WS2008) ||
511 (vmbus_proto_version == VERSION_WIN7) || (!perf_chn)) {
512 /*
513 * Prior to win8, all channel interrupts are
514 * delivered on cpu 0.
515 * Also if the channel is not a performance critical
516 * channel, bind it to cpu 0.
517 */
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700518 channel->numa_node = 0;
K. Y. Srinivasand3ba7202014-04-08 18:45:53 -0700519 channel->target_cpu = 0;
K. Y. Srinivasan9c6e64a2015-05-30 23:37:47 -0700520 channel->target_vp = hv_context.vp_index[0];
K. Y. Srinivasand3ba7202014-04-08 18:45:53 -0700521 return;
K. Y. Srinivasana1198452012-12-01 06:46:50 -0800522 }
Vitaly Kuznetsovce59fec2015-05-06 17:47:46 -0700523
524 /*
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700525 * We distribute primary channels evenly across all the available
526 * NUMA nodes and within the assigned NUMA node we will assign the
527 * first available CPU to the primary channel.
528 * The sub-channels will be assigned to the CPUs available in the
529 * NUMA node evenly.
Vitaly Kuznetsovce59fec2015-05-06 17:47:46 -0700530 */
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700531 if (!primary) {
532 while (true) {
533 next_node = next_numa_node_id++;
534 if (next_node == nr_node_ids)
535 next_node = next_numa_node_id = 0;
536 if (cpumask_empty(cpumask_of_node(next_node)))
537 continue;
538 break;
Vitaly Kuznetsovce59fec2015-05-06 17:47:46 -0700539 }
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700540 channel->numa_node = next_node;
541 primary = channel;
Vitaly Kuznetsovce59fec2015-05-06 17:47:46 -0700542 }
K. Y. Srinivasan9f01ec532015-08-05 00:52:38 -0700543 alloced_mask = &hv_context.hv_numa_map[primary->numa_node];
Vitaly Kuznetsovce59fec2015-05-06 17:47:46 -0700544
K. Y. Srinivasan9f01ec532015-08-05 00:52:38 -0700545 if (cpumask_weight(alloced_mask) ==
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700546 cpumask_weight(cpumask_of_node(primary->numa_node))) {
547 /*
548 * We have cycled through all the CPUs in the node;
549 * reset the alloced map.
550 */
K. Y. Srinivasan9f01ec532015-08-05 00:52:38 -0700551 cpumask_clear(alloced_mask);
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700552 }
553
K. Y. Srinivasan9f01ec532015-08-05 00:52:38 -0700554 cpumask_xor(&available_mask, alloced_mask,
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700555 cpumask_of_node(primary->numa_node));
556
Dexuan Cui3b711072015-08-05 00:52:39 -0700557 cur_cpu = -1;
Vitaly Kuznetsov79fd8e72016-01-27 22:29:34 -0800558
559 /*
560 * Normally Hyper-V host doesn't create more subchannels than there
561 * are VCPUs on the node but it is possible when not all present VCPUs
562 * on the node are initialized by guest. Clear the alloced_cpus_in_node
563 * to start over.
564 */
565 if (cpumask_equal(&primary->alloced_cpus_in_node,
566 cpumask_of_node(primary->numa_node)))
567 cpumask_clear(&primary->alloced_cpus_in_node);
568
Dexuan Cui3b711072015-08-05 00:52:39 -0700569 while (true) {
570 cur_cpu = cpumask_next(cur_cpu, &available_mask);
571 if (cur_cpu >= nr_cpu_ids) {
572 cur_cpu = -1;
573 cpumask_copy(&available_mask,
574 cpumask_of_node(primary->numa_node));
575 continue;
576 }
577
Dexuan Cuica1c4b72015-08-13 17:07:03 -0700578 /*
579 * NOTE: in the case of sub-channel, we clear the sub-channel
580 * related bit(s) in primary->alloced_cpus_in_node in
581 * hv_process_channel_removal(), so when we reload drivers
582 * like hv_netvsc in SMP guest, here we're able to re-allocate
583 * bit from primary->alloced_cpus_in_node.
584 */
Dexuan Cui3b711072015-08-05 00:52:39 -0700585 if (!cpumask_test_cpu(cur_cpu,
586 &primary->alloced_cpus_in_node)) {
587 cpumask_set_cpu(cur_cpu,
588 &primary->alloced_cpus_in_node);
589 cpumask_set_cpu(cur_cpu, alloced_mask);
590 break;
591 }
592 }
K. Y. Srinivasan1f656ff2015-05-30 23:37:48 -0700593
K. Y. Srinivasand3ba7202014-04-08 18:45:53 -0700594 channel->target_cpu = cur_cpu;
595 channel->target_vp = hv_context.vp_index[cur_cpu];
K. Y. Srinivasana1198452012-12-01 06:46:50 -0800596}
597
Vitaly Kuznetsov41571912016-01-27 22:29:35 -0800598static void vmbus_wait_for_unload(void)
599{
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -0700600 int cpu;
601 void *page_addr;
602 struct hv_message *msg;
Vitaly Kuznetsov41571912016-01-27 22:29:35 -0800603 struct vmbus_channel_message_header *hdr;
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -0700604 u32 message_type;
Vitaly Kuznetsov41571912016-01-27 22:29:35 -0800605
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -0700606 /*
607 * CHANNELMSG_UNLOAD_RESPONSE is always delivered to the CPU which was
608 * used for initial contact or to CPU0 depending on host version. When
609 * we're crashing on a different CPU let's hope that IRQ handler on
610 * the cpu which receives CHANNELMSG_UNLOAD_RESPONSE is still
611 * functional and vmbus_unload_response() will complete
612 * vmbus_connection.unload_event. If not, the last thing we can do is
613 * read message pages for all CPUs directly.
614 */
Vitaly Kuznetsov41571912016-01-27 22:29:35 -0800615 while (1) {
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -0700616 if (completion_done(&vmbus_connection.unload_event))
617 break;
618
619 for_each_online_cpu(cpu) {
620 page_addr = hv_context.synic_message_page[cpu];
621 msg = (struct hv_message *)page_addr +
622 VMBUS_MESSAGE_SINT;
623
624 message_type = READ_ONCE(msg->header.message_type);
625 if (message_type == HVMSG_NONE)
626 continue;
627
628 hdr = (struct vmbus_channel_message_header *)
629 msg->u.payload;
630
631 if (hdr->msgtype == CHANNELMSG_UNLOAD_RESPONSE)
632 complete(&vmbus_connection.unload_event);
633
634 vmbus_signal_eom(msg, message_type);
Vitaly Kuznetsov41571912016-01-27 22:29:35 -0800635 }
636
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -0700637 mdelay(10);
638 }
Vitaly Kuznetsov41571912016-01-27 22:29:35 -0800639
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -0700640 /*
641 * We're crashing and already got the UNLOAD_RESPONSE, cleanup all
642 * maybe-pending messages on all CPUs to be able to receive new
643 * messages after we reconnect.
644 */
645 for_each_online_cpu(cpu) {
646 page_addr = hv_context.synic_message_page[cpu];
647 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
648 msg->header.message_type = HVMSG_NONE;
Vitaly Kuznetsov41571912016-01-27 22:29:35 -0800649 }
650}
651
Hank Janssen3e189512010-03-04 22:11:00 +0000652/*
K. Y. Srinivasan2db84ef2015-04-22 21:31:32 -0700653 * vmbus_unload_response - Handler for the unload response.
654 */
655static void vmbus_unload_response(struct vmbus_channel_message_header *hdr)
656{
657 /*
658 * This is a global event; just wakeup the waiting thread.
659 * Once we successfully unload, we can cleanup the monitor state.
660 */
661 complete(&vmbus_connection.unload_event);
662}
663
Vitaly Kuznetsov75ff3a82016-02-26 15:13:16 -0800664void vmbus_initiate_unload(bool crash)
K. Y. Srinivasan2db84ef2015-04-22 21:31:32 -0700665{
666 struct vmbus_channel_message_header hdr;
667
Vitaly Kuznetsov4a542432015-08-01 16:08:19 -0700668 /* Pre-Win2012R2 hosts don't support reconnect */
669 if (vmbus_proto_version < VERSION_WIN8_1)
670 return;
671
K. Y. Srinivasan2db84ef2015-04-22 21:31:32 -0700672 init_completion(&vmbus_connection.unload_event);
673 memset(&hdr, 0, sizeof(struct vmbus_channel_message_header));
674 hdr.msgtype = CHANNELMSG_UNLOAD;
675 vmbus_post_msg(&hdr, sizeof(struct vmbus_channel_message_header));
676
Vitaly Kuznetsov41571912016-01-27 22:29:35 -0800677 /*
678 * vmbus_initiate_unload() is also called on crash and the crash can be
679 * happening in an interrupt context, where scheduling is impossible.
680 */
Vitaly Kuznetsov75ff3a82016-02-26 15:13:16 -0800681 if (!crash)
Vitaly Kuznetsov41571912016-01-27 22:29:35 -0800682 wait_for_completion(&vmbus_connection.unload_event);
683 else
684 vmbus_wait_for_unload();
K. Y. Srinivasan2db84ef2015-04-22 21:31:32 -0700685}
686
687/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700688 * vmbus_onoffer - Handler for channel offers from vmbus in parent partition.
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700689 *
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700690 */
Haiyang Zhange98cb272010-10-15 10:14:07 -0700691static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700692{
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700693 struct vmbus_channel_offer_channel *offer;
Haiyang Zhang188963e2010-10-15 10:14:06 -0700694 struct vmbus_channel *newchannel;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700695
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700696 offer = (struct vmbus_channel_offer_channel *)hdr;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700697
Bill Pemberton454f18a2009-07-27 16:47:24 -0400698 /* Allocate the channel object and save this offer. */
Haiyang Zhange98cb272010-10-15 10:14:07 -0700699 newchannel = alloc_channel();
Haiyang Zhang188963e2010-10-15 10:14:06 -0700700 if (!newchannel) {
Hank Janssen0a466182011-03-29 13:58:47 -0700701 pr_err("Unable to allocate channel object\n");
Hank Janssen3e7ee492009-07-13 16:02:34 -0700702 return;
703 }
704
K. Y. Srinivasan132368b2012-12-01 06:46:33 -0800705 /*
706 * By default we setup state to enable batched
707 * reading. A specific service can choose to
708 * disable this prior to opening the channel.
709 */
710 newchannel->batched_reading = true;
711
K. Y. Srinivasanb3bf60c2012-12-01 06:46:45 -0800712 /*
713 * Setup state for signalling the host.
714 */
715 newchannel->sig_event = (struct hv_input_signal_event *)
716 (ALIGN((unsigned long)
717 &newchannel->sig_buf,
718 HV_HYPERCALL_PARAM_ALIGN));
719
720 newchannel->sig_event->connectionid.asu32 = 0;
721 newchannel->sig_event->connectionid.u.id = VMBUS_EVENT_CONNECTION_ID;
722 newchannel->sig_event->flag_number = 0;
723 newchannel->sig_event->rsvdz = 0;
724
725 if (vmbus_proto_version != VERSION_WS2008) {
726 newchannel->is_dedicated_interrupt =
727 (offer->is_dedicated_interrupt != 0);
728 newchannel->sig_event->connectionid.u.id =
729 offer->connection_id;
730 }
731
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800732 memcpy(&newchannel->offermsg, offer,
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700733 sizeof(struct vmbus_channel_offer_channel));
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800734 newchannel->monitor_grp = (u8)offer->monitorid / 32;
735 newchannel->monitor_bit = (u8)offer->monitorid % 32;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700736
K. Y. Srinivasan2dd37cb2015-02-28 11:18:18 -0800737 vmbus_process_offer(newchannel);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700738}
739
Hank Janssen3e189512010-03-04 22:11:00 +0000740/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700741 * vmbus_onoffer_rescind - Rescind offer handler.
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700742 *
743 * We queue a work item to process this offer synchronously
744 */
Haiyang Zhange98cb272010-10-15 10:14:07 -0700745static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700746{
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700747 struct vmbus_channel_rescind_offer *rescind;
Greg Kroah-Hartmanaded71652009-08-18 15:21:19 -0700748 struct vmbus_channel *channel;
Dexuan Cuid43e2fe2015-03-27 09:10:09 -0700749 unsigned long flags;
750 struct device *dev;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700751
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700752 rescind = (struct vmbus_channel_rescind_offer *)hdr;
Dexuan Cui85d9aa72016-01-27 22:29:43 -0800753
754 mutex_lock(&vmbus_connection.channel_mutex);
Dexuan Cuid43e2fe2015-03-27 09:10:09 -0700755 channel = relid2channel(rescind->child_relid);
Hank Janssen98e08702011-03-29 13:58:44 -0700756
K. Y. Srinivasan2dd37cb2015-02-28 11:18:18 -0800757 if (channel == NULL) {
Dexuan Cuif52078c2015-12-14 16:01:50 -0800758 /*
759 * This is very impossible, because in
760 * vmbus_process_offer(), we have already invoked
761 * vmbus_release_relid() on error.
762 */
Dexuan Cui85d9aa72016-01-27 22:29:43 -0800763 goto out;
K. Y. Srinivasan2dd37cb2015-02-28 11:18:18 -0800764 }
Hank Janssen3e7ee492009-07-13 16:02:34 -0700765
Dexuan Cuid43e2fe2015-03-27 09:10:09 -0700766 spin_lock_irqsave(&channel->lock, flags);
767 channel->rescind = true;
768 spin_unlock_irqrestore(&channel->lock, flags);
769
770 if (channel->device_obj) {
Dexuan Cui499e8402016-01-27 22:29:42 -0800771 if (channel->chn_rescind_callback) {
772 channel->chn_rescind_callback(channel);
Dexuan Cui85d9aa72016-01-27 22:29:43 -0800773 goto out;
Dexuan Cui499e8402016-01-27 22:29:42 -0800774 }
Dexuan Cuid43e2fe2015-03-27 09:10:09 -0700775 /*
776 * We will have to unregister this device from the
777 * driver core.
778 */
779 dev = get_device(&channel->device_obj->device);
780 if (dev) {
781 vmbus_device_unregister(channel->device_obj);
782 put_device(dev);
783 }
784 } else {
785 hv_process_channel_removal(channel,
786 channel->offermsg.child_relid);
K. Y. Srinivasan2dd37cb2015-02-28 11:18:18 -0800787 }
Dexuan Cui85d9aa72016-01-27 22:29:43 -0800788
789out:
790 mutex_unlock(&vmbus_connection.channel_mutex);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700791}
792
Dexuan Cui85d9aa72016-01-27 22:29:43 -0800793void vmbus_hvsock_device_unregister(struct vmbus_channel *channel)
794{
795 mutex_lock(&vmbus_connection.channel_mutex);
796
797 BUG_ON(!is_hvsock_channel(channel));
798
799 channel->rescind = true;
800 vmbus_device_unregister(channel->device_obj);
801
802 mutex_unlock(&vmbus_connection.channel_mutex);
803}
804EXPORT_SYMBOL_GPL(vmbus_hvsock_device_unregister);
805
806
Hank Janssen3e189512010-03-04 22:11:00 +0000807/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700808 * vmbus_onoffers_delivered -
809 * This is invoked when all offers have been delivered.
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700810 *
811 * Nothing to do here.
812 */
Haiyang Zhange98cb272010-10-15 10:14:07 -0700813static void vmbus_onoffers_delivered(
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700814 struct vmbus_channel_message_header *hdr)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700815{
Hank Janssen3e7ee492009-07-13 16:02:34 -0700816}
817
Hank Janssen3e189512010-03-04 22:11:00 +0000818/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700819 * vmbus_onopen_result - Open result handler.
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700820 *
821 * This is invoked when we received a response to our channel open request.
822 * Find the matching request, copy the response and signal the requesting
823 * thread.
824 */
Haiyang Zhange98cb272010-10-15 10:14:07 -0700825static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700826{
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700827 struct vmbus_channel_open_result *result;
Haiyang Zhang188963e2010-10-15 10:14:06 -0700828 struct vmbus_channel_msginfo *msginfo;
829 struct vmbus_channel_message_header *requestheader;
830 struct vmbus_channel_open_channel *openmsg;
Greg Kroah-Hartmandd0813b2009-07-15 14:56:45 -0700831 unsigned long flags;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700832
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700833 result = (struct vmbus_channel_open_result *)hdr;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700834
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700835 /*
836 * Find the open msg, copy the result and signal/unblock the wait event
837 */
Haiyang Zhang15b2f642011-01-26 12:12:07 -0800838 spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700839
Hank Janssenebb61e52011-02-18 12:39:57 -0800840 list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
841 msglistentry) {
Haiyang Zhang188963e2010-10-15 10:14:06 -0700842 requestheader =
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800843 (struct vmbus_channel_message_header *)msginfo->msg;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700844
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800845 if (requestheader->msgtype == CHANNELMSG_OPENCHANNEL) {
Haiyang Zhang188963e2010-10-15 10:14:06 -0700846 openmsg =
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800847 (struct vmbus_channel_open_channel *)msginfo->msg;
848 if (openmsg->child_relid == result->child_relid &&
849 openmsg->openid == result->openid) {
850 memcpy(&msginfo->response.open_result,
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700851 result,
K. Y. Srinivasan9568a192011-05-10 07:55:39 -0700852 sizeof(
853 struct vmbus_channel_open_result));
854 complete(&msginfo->waitevent);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700855 break;
856 }
857 }
858 }
Haiyang Zhang15b2f642011-01-26 12:12:07 -0800859 spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700860}
861
Hank Janssen3e189512010-03-04 22:11:00 +0000862/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700863 * vmbus_ongpadl_created - GPADL created handler.
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700864 *
865 * This is invoked when we received a response to our gpadl create request.
866 * Find the matching request, copy the response and signal the requesting
867 * thread.
868 */
Haiyang Zhange98cb272010-10-15 10:14:07 -0700869static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700870{
Haiyang Zhang188963e2010-10-15 10:14:06 -0700871 struct vmbus_channel_gpadl_created *gpadlcreated;
Haiyang Zhang188963e2010-10-15 10:14:06 -0700872 struct vmbus_channel_msginfo *msginfo;
873 struct vmbus_channel_message_header *requestheader;
874 struct vmbus_channel_gpadl_header *gpadlheader;
Greg Kroah-Hartmandd0813b2009-07-15 14:56:45 -0700875 unsigned long flags;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700876
Haiyang Zhang188963e2010-10-15 10:14:06 -0700877 gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700878
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700879 /*
880 * Find the establish msg, copy the result and signal/unblock the wait
881 * event
882 */
Haiyang Zhang15b2f642011-01-26 12:12:07 -0800883 spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700884
Hank Janssenebb61e52011-02-18 12:39:57 -0800885 list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
886 msglistentry) {
Haiyang Zhang188963e2010-10-15 10:14:06 -0700887 requestheader =
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800888 (struct vmbus_channel_message_header *)msginfo->msg;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700889
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800890 if (requestheader->msgtype == CHANNELMSG_GPADL_HEADER) {
Haiyang Zhang188963e2010-10-15 10:14:06 -0700891 gpadlheader =
892 (struct vmbus_channel_gpadl_header *)requestheader;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700893
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800894 if ((gpadlcreated->child_relid ==
895 gpadlheader->child_relid) &&
896 (gpadlcreated->gpadl == gpadlheader->gpadl)) {
897 memcpy(&msginfo->response.gpadl_created,
Haiyang Zhang188963e2010-10-15 10:14:06 -0700898 gpadlcreated,
K. Y. Srinivasan9568a192011-05-10 07:55:39 -0700899 sizeof(
900 struct vmbus_channel_gpadl_created));
901 complete(&msginfo->waitevent);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700902 break;
903 }
904 }
905 }
Haiyang Zhang15b2f642011-01-26 12:12:07 -0800906 spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700907}
908
Hank Janssen3e189512010-03-04 22:11:00 +0000909/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700910 * vmbus_ongpadl_torndown - GPADL torndown handler.
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700911 *
912 * This is invoked when we received a response to our gpadl teardown request.
913 * Find the matching request, copy the response and signal the requesting
914 * thread.
915 */
Haiyang Zhange98cb272010-10-15 10:14:07 -0700916static void vmbus_ongpadl_torndown(
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700917 struct vmbus_channel_message_header *hdr)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700918{
Haiyang Zhang188963e2010-10-15 10:14:06 -0700919 struct vmbus_channel_gpadl_torndown *gpadl_torndown;
Haiyang Zhang188963e2010-10-15 10:14:06 -0700920 struct vmbus_channel_msginfo *msginfo;
921 struct vmbus_channel_message_header *requestheader;
922 struct vmbus_channel_gpadl_teardown *gpadl_teardown;
Greg Kroah-Hartmandd0813b2009-07-15 14:56:45 -0700923 unsigned long flags;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700924
Haiyang Zhang188963e2010-10-15 10:14:06 -0700925 gpadl_torndown = (struct vmbus_channel_gpadl_torndown *)hdr;
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700926
927 /*
928 * Find the open msg, copy the result and signal/unblock the wait event
929 */
Haiyang Zhang15b2f642011-01-26 12:12:07 -0800930 spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700931
Hank Janssenebb61e52011-02-18 12:39:57 -0800932 list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
933 msglistentry) {
Haiyang Zhang188963e2010-10-15 10:14:06 -0700934 requestheader =
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800935 (struct vmbus_channel_message_header *)msginfo->msg;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700936
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800937 if (requestheader->msgtype == CHANNELMSG_GPADL_TEARDOWN) {
Haiyang Zhang188963e2010-10-15 10:14:06 -0700938 gpadl_teardown =
939 (struct vmbus_channel_gpadl_teardown *)requestheader;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700940
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800941 if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) {
942 memcpy(&msginfo->response.gpadl_torndown,
Haiyang Zhang188963e2010-10-15 10:14:06 -0700943 gpadl_torndown,
K. Y. Srinivasan9568a192011-05-10 07:55:39 -0700944 sizeof(
945 struct vmbus_channel_gpadl_torndown));
946 complete(&msginfo->waitevent);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700947 break;
948 }
949 }
950 }
Haiyang Zhang15b2f642011-01-26 12:12:07 -0800951 spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700952}
953
Hank Janssen3e189512010-03-04 22:11:00 +0000954/*
Haiyang Zhange98cb272010-10-15 10:14:07 -0700955 * vmbus_onversion_response - Version response handler
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700956 *
957 * This is invoked when we received a response to our initiate contact request.
958 * Find the matching request, copy the response and signal the requesting
959 * thread.
960 */
Haiyang Zhange98cb272010-10-15 10:14:07 -0700961static void vmbus_onversion_response(
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700962 struct vmbus_channel_message_header *hdr)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700963{
Haiyang Zhang188963e2010-10-15 10:14:06 -0700964 struct vmbus_channel_msginfo *msginfo;
965 struct vmbus_channel_message_header *requestheader;
Haiyang Zhang188963e2010-10-15 10:14:06 -0700966 struct vmbus_channel_version_response *version_response;
Greg Kroah-Hartmandd0813b2009-07-15 14:56:45 -0700967 unsigned long flags;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700968
Haiyang Zhang188963e2010-10-15 10:14:06 -0700969 version_response = (struct vmbus_channel_version_response *)hdr;
Haiyang Zhang15b2f642011-01-26 12:12:07 -0800970 spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700971
Hank Janssenebb61e52011-02-18 12:39:57 -0800972 list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
973 msglistentry) {
Haiyang Zhang188963e2010-10-15 10:14:06 -0700974 requestheader =
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800975 (struct vmbus_channel_message_header *)msginfo->msg;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700976
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800977 if (requestheader->msgtype ==
978 CHANNELMSG_INITIATE_CONTACT) {
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -0800979 memcpy(&msginfo->response.version_response,
Haiyang Zhang188963e2010-10-15 10:14:06 -0700980 version_response,
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -0700981 sizeof(struct vmbus_channel_version_response));
K. Y. Srinivasan9568a192011-05-10 07:55:39 -0700982 complete(&msginfo->waitevent);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700983 }
984 }
Haiyang Zhang15b2f642011-01-26 12:12:07 -0800985 spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700986}
987
Greg Kroah-Hartmanc8212f02009-08-31 21:51:50 -0700988/* Channel message dispatch table */
Dexuan Cui652594c2015-03-27 09:10:08 -0700989struct vmbus_channel_message_table_entry
K. Y. Srinivasanb7c6b022011-05-10 07:55:38 -0700990 channel_message_table[CHANNELMSG_COUNT] = {
Dexuan Cui652594c2015-03-27 09:10:08 -0700991 {CHANNELMSG_INVALID, 0, NULL},
992 {CHANNELMSG_OFFERCHANNEL, 0, vmbus_onoffer},
993 {CHANNELMSG_RESCIND_CHANNELOFFER, 0, vmbus_onoffer_rescind},
994 {CHANNELMSG_REQUESTOFFERS, 0, NULL},
995 {CHANNELMSG_ALLOFFERS_DELIVERED, 1, vmbus_onoffers_delivered},
996 {CHANNELMSG_OPENCHANNEL, 0, NULL},
997 {CHANNELMSG_OPENCHANNEL_RESULT, 1, vmbus_onopen_result},
998 {CHANNELMSG_CLOSECHANNEL, 0, NULL},
999 {CHANNELMSG_GPADL_HEADER, 0, NULL},
1000 {CHANNELMSG_GPADL_BODY, 0, NULL},
1001 {CHANNELMSG_GPADL_CREATED, 1, vmbus_ongpadl_created},
1002 {CHANNELMSG_GPADL_TEARDOWN, 0, NULL},
1003 {CHANNELMSG_GPADL_TORNDOWN, 1, vmbus_ongpadl_torndown},
1004 {CHANNELMSG_RELID_RELEASED, 0, NULL},
1005 {CHANNELMSG_INITIATE_CONTACT, 0, NULL},
1006 {CHANNELMSG_VERSION_RESPONSE, 1, vmbus_onversion_response},
1007 {CHANNELMSG_UNLOAD, 0, NULL},
K. Y. Srinivasan2db84ef2015-04-22 21:31:32 -07001008 {CHANNELMSG_UNLOAD_RESPONSE, 1, vmbus_unload_response},
Dexuan Cui5c23a1a2016-01-27 22:29:40 -08001009 {CHANNELMSG_18, 0, NULL},
1010 {CHANNELMSG_19, 0, NULL},
1011 {CHANNELMSG_20, 0, NULL},
1012 {CHANNELMSG_TL_CONNECT_REQUEST, 0, NULL},
Greg Kroah-Hartmanc8212f02009-08-31 21:51:50 -07001013};
1014
Hank Janssen3e189512010-03-04 22:11:00 +00001015/*
Haiyang Zhange98cb272010-10-15 10:14:07 -07001016 * vmbus_onmessage - Handler for channel protocol messages.
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -07001017 *
1018 * This is invoked in the vmbus worker thread context.
1019 */
Haiyang Zhange98cb272010-10-15 10:14:07 -07001020void vmbus_onmessage(void *context)
Hank Janssen3e7ee492009-07-13 16:02:34 -07001021{
Haiyang Zhang188963e2010-10-15 10:14:06 -07001022 struct hv_message *msg = context;
Greg Kroah-Hartman82250212009-08-26 15:16:04 -07001023 struct vmbus_channel_message_header *hdr;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001024 int size;
1025
Haiyang Zhangf6feebe2010-11-08 14:04:39 -08001026 hdr = (struct vmbus_channel_message_header *)msg->u.payload;
1027 size = msg->header.payload_size;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001028
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -08001029 if (hdr->msgtype >= CHANNELMSG_COUNT) {
Hank Janssen0a466182011-03-29 13:58:47 -07001030 pr_err("Received invalid channel message type %d size %d\n",
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -08001031 hdr->msgtype, size);
Greg Kroah-Hartman04f50c42009-07-16 12:35:37 -07001032 print_hex_dump_bytes("", DUMP_PREFIX_NONE,
Haiyang Zhangf6feebe2010-11-08 14:04:39 -08001033 (unsigned char *)msg->u.payload, size);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001034 return;
1035 }
1036
K. Y. Srinivasanb7c6b022011-05-10 07:55:38 -07001037 if (channel_message_table[hdr->msgtype].message_handler)
1038 channel_message_table[hdr->msgtype].message_handler(hdr);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001039 else
Hank Janssen0a466182011-03-29 13:58:47 -07001040 pr_err("Unhandled channel message type %d\n", hdr->msgtype);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001041}
1042
Hank Janssen3e189512010-03-04 22:11:00 +00001043/*
Haiyang Zhange98cb272010-10-15 10:14:07 -07001044 * vmbus_request_offers - Send a request to get all our pending offers.
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -07001045 */
Haiyang Zhange98cb272010-10-15 10:14:07 -07001046int vmbus_request_offers(void)
Hank Janssen3e7ee492009-07-13 16:02:34 -07001047{
Greg Kroah-Hartman82250212009-08-26 15:16:04 -07001048 struct vmbus_channel_message_header *msg;
Haiyang Zhang188963e2010-10-15 10:14:06 -07001049 struct vmbus_channel_msginfo *msginfo;
Nicholas Mc Guire51e51812015-02-27 11:26:02 -08001050 int ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001051
Haiyang Zhang188963e2010-10-15 10:14:06 -07001052 msginfo = kmalloc(sizeof(*msginfo) +
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -07001053 sizeof(struct vmbus_channel_message_header),
1054 GFP_KERNEL);
Haiyang Zhang188963e2010-10-15 10:14:06 -07001055 if (!msginfo)
Bill Pemberton75910f22010-05-05 15:27:31 -04001056 return -ENOMEM;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001057
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -08001058 msg = (struct vmbus_channel_message_header *)msginfo->msg;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001059
Haiyang Zhangc50f7fb2010-11-08 14:04:38 -08001060 msg->msgtype = CHANNELMSG_REQUESTOFFERS;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001061
Hank Janssen3e7ee492009-07-13 16:02:34 -07001062
Haiyang Zhangc6977672011-01-26 12:12:08 -08001063 ret = vmbus_post_msg(msg,
Greg Kroah-Hartmanbd60c332009-08-31 21:47:21 -07001064 sizeof(struct vmbus_channel_message_header));
1065 if (ret != 0) {
Hank Janssen0a466182011-03-29 13:58:47 -07001066 pr_err("Unable to request offers - %d\n", ret);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001067
K. Y. Srinivasan0c3b7b22011-02-11 09:59:43 -08001068 goto cleanup;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001069 }
Hank Janssen3e7ee492009-07-13 16:02:34 -07001070
K. Y. Srinivasan0c3b7b22011-02-11 09:59:43 -08001071cleanup:
Ilia Mirkindd9b15d2011-03-13 00:29:00 -05001072 kfree(msginfo);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001073
Hank Janssen3e7ee492009-07-13 16:02:34 -07001074 return ret;
1075}
1076
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001077/*
1078 * Retrieve the (sub) channel on which to send an outgoing request.
K. Y. Srinivasana13e8bb2015-02-28 11:39:02 -08001079 * When a primary channel has multiple sub-channels, we try to
1080 * distribute the load equally amongst all available channels.
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001081 */
1082struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary)
1083{
1084 struct list_head *cur, *tmp;
K. Y. Srinivasan87712bf82014-12-14 23:34:51 -08001085 int cur_cpu;
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001086 struct vmbus_channel *cur_channel;
1087 struct vmbus_channel *outgoing_channel = primary;
K. Y. Srinivasana13e8bb2015-02-28 11:39:02 -08001088 int next_channel;
1089 int i = 1;
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001090
1091 if (list_empty(&primary->sc_list))
1092 return outgoing_channel;
1093
K. Y. Srinivasana13e8bb2015-02-28 11:39:02 -08001094 next_channel = primary->next_oc++;
1095
1096 if (next_channel > (primary->num_sc)) {
1097 primary->next_oc = 0;
1098 return outgoing_channel;
1099 }
1100
K. Y. Srinivasan87712bf82014-12-14 23:34:51 -08001101 cur_cpu = hv_context.vp_index[get_cpu()];
1102 put_cpu();
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001103 list_for_each_safe(cur, tmp, &primary->sc_list) {
1104 cur_channel = list_entry(cur, struct vmbus_channel, sc_list);
1105 if (cur_channel->state != CHANNEL_OPENED_STATE)
1106 continue;
1107
1108 if (cur_channel->target_vp == cur_cpu)
1109 return cur_channel;
1110
K. Y. Srinivasana13e8bb2015-02-28 11:39:02 -08001111 if (i == next_channel)
1112 return cur_channel;
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001113
K. Y. Srinivasana13e8bb2015-02-28 11:39:02 -08001114 i++;
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001115 }
1116
1117 return outgoing_channel;
1118}
1119EXPORT_SYMBOL_GPL(vmbus_get_outgoing_channel);
1120
1121static void invoke_sc_cb(struct vmbus_channel *primary_channel)
1122{
1123 struct list_head *cur, *tmp;
1124 struct vmbus_channel *cur_channel;
1125
1126 if (primary_channel->sc_creation_callback == NULL)
1127 return;
1128
1129 list_for_each_safe(cur, tmp, &primary_channel->sc_list) {
1130 cur_channel = list_entry(cur, struct vmbus_channel, sc_list);
1131
1132 primary_channel->sc_creation_callback(cur_channel);
1133 }
1134}
1135
1136void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
1137 void (*sc_cr_cb)(struct vmbus_channel *new_sc))
1138{
1139 primary_channel->sc_creation_callback = sc_cr_cb;
1140}
1141EXPORT_SYMBOL_GPL(vmbus_set_sc_create_callback);
1142
1143bool vmbus_are_subchannels_present(struct vmbus_channel *primary)
1144{
1145 bool ret;
1146
1147 ret = !list_empty(&primary->sc_list);
1148
1149 if (ret) {
1150 /*
1151 * Invoke the callback on sub-channel creation.
1152 * This will present a uniform interface to the
1153 * clients.
1154 */
1155 invoke_sc_cb(primary);
1156 }
1157
1158 return ret;
1159}
1160EXPORT_SYMBOL_GPL(vmbus_are_subchannels_present);
Dexuan Cui499e8402016-01-27 22:29:42 -08001161
1162void vmbus_set_chn_rescind_callback(struct vmbus_channel *channel,
1163 void (*chn_rescind_cb)(struct vmbus_channel *))
1164{
1165 channel->chn_rescind_callback = chn_rescind_cb;
1166}
1167EXPORT_SYMBOL_GPL(vmbus_set_chn_rescind_callback);