blob: eb4d0730f44d74eba2a298616ea1573fed9eb268 [file] [log] [blame]
Ky Srinivasan245ba562010-12-16 18:54:16 -07001/*
2 * An implementation of key value pair (KVP) functionality for Linux.
3 *
4 *
5 * Copyright (C) 2010, Novell, Inc.
6 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
15 * NON INFRINGEMENT. See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
Hank Janssenaf7a5b62011-03-29 13:58:49 -070023#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Ky Srinivasan245ba562010-12-16 18:54:16 -070024
25#include <linux/net.h>
26#include <linux/nls.h>
27#include <linux/connector.h>
28#include <linux/workqueue.h>
Greg Kroah-Hartman46a97192011-10-04 12:29:52 -070029#include <linux/hyperv.h>
Ky Srinivasan245ba562010-12-16 18:54:16 -070030
Ky Srinivasan245ba562010-12-16 18:54:16 -070031
32
33/*
34 * Global state maintained for transaction that is being processed.
35 * Note that only one transaction can be active at any point in time.
36 *
37 * This state is set when we receive a request from the host; we
38 * cleanup this state when the transaction is completed - when we respond
39 * to the host with the key value.
40 */
41
42static struct {
43 bool active; /* transaction status - active or not */
44 int recv_len; /* number of bytes received. */
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -070045 struct hv_kvp_msg *kvp_msg; /* current message */
Ky Srinivasan245ba562010-12-16 18:54:16 -070046 struct vmbus_channel *recv_channel; /* chn we got the request */
47 u64 recv_req_id; /* request ID. */
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -070048 void *kvp_context; /* for the channel callback */
Ky Srinivasan245ba562010-12-16 18:54:16 -070049} kvp_transaction;
50
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -070051/*
52 * Before we can accept KVP messages from the host, we need
53 * to handshake with the user level daemon. This state tracks
54 * if we are in the handshake phase.
55 */
56static bool in_hand_shake = true;
57
58/*
59 * This state maintains the version number registered by the daemon.
60 */
61static int dm_reg_value;
62
K. Y. Srinivasane2bb6532011-10-09 19:42:28 -070063static void kvp_send_key(struct work_struct *dummy);
Ky Srinivasan245ba562010-12-16 18:54:16 -070064
K. Y. Srinivasan76e5f812011-10-04 14:00:02 -070065
Ky Srinivasan245ba562010-12-16 18:54:16 -070066static void kvp_respond_to_host(char *key, char *value, int error);
67static void kvp_work_func(struct work_struct *dummy);
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -070068static void kvp_register(int);
Ky Srinivasan245ba562010-12-16 18:54:16 -070069
70static DECLARE_DELAYED_WORK(kvp_work, kvp_work_func);
K. Y. Srinivasane2bb6532011-10-09 19:42:28 -070071static DECLARE_WORK(kvp_sendkey_work, kvp_send_key);
Ky Srinivasan245ba562010-12-16 18:54:16 -070072
73static struct cb_id kvp_id = { CN_KVP_IDX, CN_KVP_VAL };
74static const char kvp_name[] = "kvp_kernel_module";
Ky Srinivasan245ba562010-12-16 18:54:16 -070075static u8 *recv_buffer;
76/*
77 * Register the kernel component with the user-level daemon.
78 * As part of this registration, pass the LIC version number.
79 */
80
81static void
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -070082kvp_register(int reg_value)
Ky Srinivasan245ba562010-12-16 18:54:16 -070083{
84
85 struct cn_msg *msg;
K. Y. Srinivasan2640335432012-02-02 16:56:50 -080086 struct hv_kvp_msg *kvp_msg;
87 char *version;
Ky Srinivasan245ba562010-12-16 18:54:16 -070088
K. Y. Srinivasan2640335432012-02-02 16:56:50 -080089 msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg), GFP_ATOMIC);
Ky Srinivasan245ba562010-12-16 18:54:16 -070090
91 if (msg) {
K. Y. Srinivasan2640335432012-02-02 16:56:50 -080092 kvp_msg = (struct hv_kvp_msg *)msg->data;
K. Y. Srinivasane485ceac2012-03-10 15:32:08 -080093 version = kvp_msg->body.kvp_register.version;
Ky Srinivasan245ba562010-12-16 18:54:16 -070094 msg->id.idx = CN_KVP_IDX;
95 msg->id.val = CN_KVP_VAL;
K. Y. Srinivasan2640335432012-02-02 16:56:50 -080096
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -070097 kvp_msg->kvp_hdr.operation = reg_value;
K. Y. Srinivasan2640335432012-02-02 16:56:50 -080098 strcpy(version, HV_DRV_VERSION);
99 msg->len = sizeof(struct hv_kvp_msg);
Ky Srinivasan245ba562010-12-16 18:54:16 -0700100 cn_netlink_send(msg, 0, GFP_ATOMIC);
101 kfree(msg);
102 }
103}
104static void
105kvp_work_func(struct work_struct *dummy)
106{
107 /*
108 * If the timer fires, the user-mode component has not responded;
109 * process the pending transaction.
110 */
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700111 kvp_respond_to_host("Unknown key", "Guest timed out", HV_E_FAIL);
Ky Srinivasan245ba562010-12-16 18:54:16 -0700112}
113
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700114static int kvp_handle_handshake(struct hv_kvp_msg *msg)
115{
116 int ret = 1;
117
118 switch (msg->kvp_hdr.operation) {
119 case KVP_OP_REGISTER:
120 dm_reg_value = KVP_OP_REGISTER;
121 pr_info("KVP: IP injection functionality not available\n");
122 pr_info("KVP: Upgrade the KVP daemon\n");
123 break;
124 case KVP_OP_REGISTER1:
125 dm_reg_value = KVP_OP_REGISTER1;
126 break;
127 default:
128 pr_info("KVP: incompatible daemon\n");
129 pr_info("KVP: KVP version: %d, Daemon version: %d\n",
130 KVP_OP_REGISTER1, msg->kvp_hdr.operation);
131 ret = 0;
132 }
133
134 if (ret) {
135 /*
136 * We have a compatible daemon; complete the handshake.
137 */
138 pr_info("KVP: user-mode registering done.\n");
139 kvp_register(dm_reg_value);
140 kvp_transaction.active = false;
141 if (kvp_transaction.kvp_context)
142 hv_kvp_onchannelcallback(kvp_transaction.kvp_context);
143 }
144 return ret;
145}
146
147
Ky Srinivasan245ba562010-12-16 18:54:16 -0700148/*
149 * Callback when data is received from user mode.
150 */
151
152static void
153kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
154{
K. Y. Srinivasan2640335432012-02-02 16:56:50 -0800155 struct hv_kvp_msg *message;
156 struct hv_kvp_msg_enumerate *data;
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700157 int error = 0;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700158
K. Y. Srinivasan2640335432012-02-02 16:56:50 -0800159 message = (struct hv_kvp_msg *)msg->data;
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700160
161 /*
162 * If we are negotiating the version information
163 * with the daemon; handle that first.
164 */
165
166 if (in_hand_shake) {
167 if (kvp_handle_handshake(message))
168 in_hand_shake = false;
169 return;
170 }
171
172 /*
173 * Based on the version of the daemon, we propagate errors from the
174 * daemon differently.
175 */
176
177 data = &message->body.kvp_enum_data;
178
179 switch (dm_reg_value) {
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700180 case KVP_OP_REGISTER:
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700181 /*
182 * Null string is used to pass back error condition.
183 */
184 if (data->data.key[0] == 0)
185 error = HV_S_CONT;
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700186 break;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700187
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700188 case KVP_OP_REGISTER1:
Ky Srinivasan245ba562010-12-16 18:54:16 -0700189 /*
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700190 * We use the message header information from
191 * the user level daemon to transmit errors.
Ky Srinivasan245ba562010-12-16 18:54:16 -0700192 */
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700193 error = message->error;
194 break;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700195 }
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700196
197 /*
198 * Complete the transaction by forwarding the key value
199 * to the host. But first, cancel the timeout.
200 */
201 if (cancel_delayed_work_sync(&kvp_work))
202 kvp_respond_to_host(data->data.key, data->data.value, error);
Ky Srinivasan245ba562010-12-16 18:54:16 -0700203}
204
K. Y. Srinivasane2bb6532011-10-09 19:42:28 -0700205static void
206kvp_send_key(struct work_struct *dummy)
Ky Srinivasan245ba562010-12-16 18:54:16 -0700207{
208 struct cn_msg *msg;
K. Y. Srinivasan2640335432012-02-02 16:56:50 -0800209 struct hv_kvp_msg *message;
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700210 struct hv_kvp_msg *in_msg;
211 __u8 operation = kvp_transaction.kvp_msg->kvp_hdr.operation;
212 __u8 pool = kvp_transaction.kvp_msg->kvp_hdr.pool;
213 __u32 val32;
214 __u64 val64;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700215
216 msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg) , GFP_ATOMIC);
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700217 if (!msg)
218 return;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700219
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700220 msg->id.idx = CN_KVP_IDX;
221 msg->id.val = CN_KVP_VAL;
K. Y. Srinivasan2640335432012-02-02 16:56:50 -0800222
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700223 message = (struct hv_kvp_msg *)msg->data;
224 message->kvp_hdr.operation = operation;
225 message->kvp_hdr.pool = pool;
226 in_msg = kvp_transaction.kvp_msg;
227
228 /*
229 * The key/value strings sent from the host are encoded in
230 * in utf16; convert it to utf8 strings.
231 * The host assures us that the utf16 strings will not exceed
232 * the max lengths specified. We will however, reserve room
233 * for the string terminating character - in the utf16s_utf8s()
234 * function we limit the size of the buffer where the converted
235 * string is placed to HV_KVP_EXCHANGE_MAX_*_SIZE -1 to gaurantee
236 * that the strings can be properly terminated!
237 */
238
239 switch (message->kvp_hdr.operation) {
240 case KVP_OP_SET:
241 switch (in_msg->body.kvp_set.data.value_type) {
242 case REG_SZ:
243 /*
244 * The value is a string - utf16 encoding.
245 */
246 message->body.kvp_set.data.value_size =
247 utf16s_to_utf8s(
248 (wchar_t *)in_msg->body.kvp_set.data.value,
249 in_msg->body.kvp_set.data.value_size,
250 UTF16_LITTLE_ENDIAN,
251 message->body.kvp_set.data.value,
252 HV_KVP_EXCHANGE_MAX_VALUE_SIZE - 1) + 1;
253 break;
254
255 case REG_U32:
256 /*
257 * The value is a 32 bit scalar.
258 * We save this as a utf8 string.
259 */
260 val32 = in_msg->body.kvp_set.data.value_u32;
261 message->body.kvp_set.data.value_size =
262 sprintf(message->body.kvp_set.data.value,
263 "%d", val32) + 1;
264 break;
265
266 case REG_U64:
267 /*
268 * The value is a 64 bit scalar.
269 * We save this as a utf8 string.
270 */
271 val64 = in_msg->body.kvp_set.data.value_u64;
272 message->body.kvp_set.data.value_size =
273 sprintf(message->body.kvp_set.data.value,
274 "%llu", val64) + 1;
275 break;
276
277 }
278 case KVP_OP_GET:
279 message->body.kvp_set.data.key_size =
280 utf16s_to_utf8s(
281 (wchar_t *)in_msg->body.kvp_set.data.key,
282 in_msg->body.kvp_set.data.key_size,
283 UTF16_LITTLE_ENDIAN,
284 message->body.kvp_set.data.key,
285 HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
286 break;
287
288 case KVP_OP_DELETE:
289 message->body.kvp_delete.key_size =
290 utf16s_to_utf8s(
291 (wchar_t *)in_msg->body.kvp_delete.key,
292 in_msg->body.kvp_delete.key_size,
293 UTF16_LITTLE_ENDIAN,
294 message->body.kvp_delete.key,
295 HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
296 break;
297
298 case KVP_OP_ENUMERATE:
299 message->body.kvp_enum_data.index =
300 in_msg->body.kvp_enum_data.index;
301 break;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700302 }
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700303
304 msg->len = sizeof(struct hv_kvp_msg);
305 cn_netlink_send(msg, 0, GFP_ATOMIC);
306 kfree(msg);
307
K. Y. Srinivasane2bb6532011-10-09 19:42:28 -0700308 return;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700309}
310
311/*
312 * Send a response back to the host.
313 */
314
315static void
316kvp_respond_to_host(char *key, char *value, int error)
317{
318 struct hv_kvp_msg *kvp_msg;
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700319 struct hv_kvp_exchg_msg_value *kvp_data;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700320 char *key_name;
321 struct icmsg_hdr *icmsghdrp;
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700322 int keylen = 0;
323 int valuelen = 0;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700324 u32 buf_len;
325 struct vmbus_channel *channel;
326 u64 req_id;
327
328 /*
329 * If a transaction is not active; log and return.
330 */
331
332 if (!kvp_transaction.active) {
333 /*
334 * This is a spurious call!
335 */
Hank Janssenaf7a5b62011-03-29 13:58:49 -0700336 pr_warn("KVP: Transaction not active\n");
Ky Srinivasan245ba562010-12-16 18:54:16 -0700337 return;
338 }
339 /*
340 * Copy the global state for completing the transaction. Note that
341 * only one transaction can be active at a time.
342 */
343
344 buf_len = kvp_transaction.recv_len;
345 channel = kvp_transaction.recv_channel;
346 req_id = kvp_transaction.recv_req_id;
347
K. Y. Srinivasan76e5f812011-10-04 14:00:02 -0700348 kvp_transaction.active = false;
349
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700350 icmsghdrp = (struct icmsg_hdr *)
351 &recv_buffer[sizeof(struct vmbuspipe_hdr)];
352
K. Y. Srinivasan4e65f6e2011-09-18 10:31:34 -0700353 if (channel->onchannel_callback == NULL)
354 /*
355 * We have raced with util driver being unloaded;
356 * silently return.
357 */
358 return;
359
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700360 icmsghdrp->status = error;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700361
362 /*
K. Y. Srinivasanadc80ae2012-03-16 08:02:27 -0700363 * If the error parameter is set, terminate the host's enumeration
364 * on this pool.
Ky Srinivasan245ba562010-12-16 18:54:16 -0700365 */
366 if (error) {
367 /*
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700368 * Something failed or we have timedout;
369 * terminate the current host-side iteration.
Ky Srinivasan245ba562010-12-16 18:54:16 -0700370 */
Ky Srinivasan245ba562010-12-16 18:54:16 -0700371 goto response_done;
372 }
373
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700374 kvp_msg = (struct hv_kvp_msg *)
375 &recv_buffer[sizeof(struct vmbuspipe_hdr) +
376 sizeof(struct icmsg_hdr)];
377
378 switch (kvp_transaction.kvp_msg->kvp_hdr.operation) {
379 case KVP_OP_GET:
380 kvp_data = &kvp_msg->body.kvp_get.data;
381 goto copy_value;
382
383 case KVP_OP_SET:
384 case KVP_OP_DELETE:
385 goto response_done;
386
387 default:
388 break;
389 }
390
391 kvp_data = &kvp_msg->body.kvp_enum_data.data;
392 key_name = key;
393
Ky Srinivasan245ba562010-12-16 18:54:16 -0700394 /*
395 * The windows host expects the key/value pair to be encoded
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700396 * in utf16. Ensure that the key/value size reported to the host
397 * will be less than or equal to the MAX size (including the
398 * terminating character).
Ky Srinivasan245ba562010-12-16 18:54:16 -0700399 */
Alan Stern0720a062011-11-17 16:42:19 -0500400 keylen = utf8s_to_utf16s(key_name, strlen(key_name), UTF16_HOST_ENDIAN,
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700401 (wchar_t *) kvp_data->key,
402 (HV_KVP_EXCHANGE_MAX_KEY_SIZE / 2) - 2);
403 kvp_data->key_size = 2*(keylen + 1); /* utf16 encoding */
Ky Srinivasan245ba562010-12-16 18:54:16 -0700404
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700405copy_value:
406 valuelen = utf8s_to_utf16s(value, strlen(value), UTF16_HOST_ENDIAN,
407 (wchar_t *) kvp_data->value,
408 (HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2) - 2);
409 kvp_data->value_size = 2*(valuelen + 1); /* utf16 encoding */
410
411 /*
412 * If the utf8s to utf16s conversion failed; notify host
413 * of the error.
414 */
415 if ((keylen < 0) || (valuelen < 0))
416 icmsghdrp->status = HV_E_FAIL;
417
418 kvp_data->value_type = REG_SZ; /* all our values are strings */
Ky Srinivasan245ba562010-12-16 18:54:16 -0700419
420response_done:
421 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE;
422
423 vmbus_sendpacket(channel, recv_buffer, buf_len, req_id,
Haiyang Zhang415f2282011-01-26 12:12:13 -0800424 VM_PKT_DATA_INBAND, 0);
Ky Srinivasan245ba562010-12-16 18:54:16 -0700425
Ky Srinivasan245ba562010-12-16 18:54:16 -0700426}
427
428/*
429 * This callback is invoked when we get a KVP message from the host.
430 * The host ensures that only one KVP transaction can be active at a time.
431 * KVP implementation in Linux needs to forward the key to a user-mde
432 * component to retrive the corresponding value. Consequently, we cannot
433 * respond to the host in the conext of this callback. Since the host
434 * guarantees that at most only one transaction can be active at a time,
435 * we stash away the transaction state in a set of global variables.
436 */
437
438void hv_kvp_onchannelcallback(void *context)
439{
440 struct vmbus_channel *channel = context;
441 u32 recvlen;
442 u64 requestid;
443
444 struct hv_kvp_msg *kvp_msg;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700445
446 struct icmsg_hdr *icmsghdrp;
447 struct icmsg_negotiate *negop = NULL;
448
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700449 if (kvp_transaction.active) {
450 /*
451 * We will defer processing this callback once
452 * the current transaction is complete.
453 */
454 kvp_transaction.kvp_context = context;
455 return;
456 }
Ky Srinivasan245ba562010-12-16 18:54:16 -0700457
Ky Srinivasan245ba562010-12-16 18:54:16 -0700458 vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE, &recvlen, &requestid);
459
460 if (recvlen > 0) {
Ky Srinivasan245ba562010-12-16 18:54:16 -0700461 icmsghdrp = (struct icmsg_hdr *)&recv_buffer[
462 sizeof(struct vmbuspipe_hdr)];
463
464 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -0700465 vmbus_prep_negotiate_resp(icmsghdrp, negop,
466 recv_buffer, MAX_SRV_VER, MAX_SRV_VER);
Ky Srinivasan245ba562010-12-16 18:54:16 -0700467 } else {
468 kvp_msg = (struct hv_kvp_msg *)&recv_buffer[
469 sizeof(struct vmbuspipe_hdr) +
470 sizeof(struct icmsg_hdr)];
471
Ky Srinivasan245ba562010-12-16 18:54:16 -0700472 /*
473 * Stash away this global state for completing the
474 * transaction; note transactions are serialized.
475 */
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700476
Ky Srinivasan245ba562010-12-16 18:54:16 -0700477 kvp_transaction.recv_len = recvlen;
478 kvp_transaction.recv_channel = channel;
479 kvp_transaction.recv_req_id = requestid;
480 kvp_transaction.active = true;
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700481 kvp_transaction.kvp_msg = kvp_msg;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700482
483 /*
484 * Get the information from the
485 * user-mode component.
486 * component. This transaction will be
487 * completed when we get the value from
488 * the user-mode component.
489 * Set a timeout to deal with
490 * user-mode not responding.
491 */
K. Y. Srinivasane2bb6532011-10-09 19:42:28 -0700492 schedule_work(&kvp_sendkey_work);
493 schedule_delayed_work(&kvp_work, 5*HZ);
Ky Srinivasan245ba562010-12-16 18:54:16 -0700494
495 return;
496
497 }
498
Ky Srinivasan245ba562010-12-16 18:54:16 -0700499 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
500 | ICMSGHDRFLAG_RESPONSE;
501
502 vmbus_sendpacket(channel, recv_buffer,
503 recvlen, requestid,
Haiyang Zhang415f2282011-01-26 12:12:13 -0800504 VM_PKT_DATA_INBAND, 0);
Ky Srinivasan245ba562010-12-16 18:54:16 -0700505 }
506
507}
508
509int
K. Y. Srinivasana29b6432011-09-18 10:31:33 -0700510hv_kvp_init(struct hv_util_service *srv)
Ky Srinivasan245ba562010-12-16 18:54:16 -0700511{
512 int err;
513
514 err = cn_add_callback(&kvp_id, kvp_name, kvp_cn_callback);
515 if (err)
516 return err;
K. Y. Srinivasana29b6432011-09-18 10:31:33 -0700517 recv_buffer = srv->recv_buffer;
Ky Srinivasan245ba562010-12-16 18:54:16 -0700518
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700519 /*
520 * When this driver loads, the user level daemon that
521 * processes the host requests may not yet be running.
522 * Defer processing channel callbacks until the daemon
523 * has registered.
524 */
525 kvp_transaction.active = true;
526
Ky Srinivasan245ba562010-12-16 18:54:16 -0700527 return 0;
528}
529
530void hv_kvp_deinit(void)
531{
532 cn_del_callback(&kvp_id);
533 cancel_delayed_work_sync(&kvp_work);
K. Y. Srinivasane2bb6532011-10-09 19:42:28 -0700534 cancel_work_sync(&kvp_sendkey_work);
Ky Srinivasan245ba562010-12-16 18:54:16 -0700535}