hv_kvp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  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. */
  23. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/net.h>
  25. #include <linux/nls.h>
  26. #include <linux/connector.h>
  27. #include <linux/workqueue.h>
  28. #include <linux/hyperv.h>
  29. /*
  30. * Pre win8 version numbers used in ws2008 and ws 2008 r2 (win7)
  31. */
  32. #define WS2008_SRV_MAJOR 1
  33. #define WS2008_SRV_MINOR 0
  34. #define WS2008_SRV_VERSION (WS2008_SRV_MAJOR << 16 | WS2008_SRV_MINOR)
  35. #define WIN7_SRV_MAJOR 3
  36. #define WIN7_SRV_MINOR 0
  37. #define WIN7_SRV_VERSION (WIN7_SRV_MAJOR << 16 | WIN7_SRV_MINOR)
  38. #define WIN8_SRV_MAJOR 4
  39. #define WIN8_SRV_MINOR 0
  40. #define WIN8_SRV_VERSION (WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)
  41. /*
  42. * Global state maintained for transaction that is being processed.
  43. * Note that only one transaction can be active at any point in time.
  44. *
  45. * This state is set when we receive a request from the host; we
  46. * cleanup this state when the transaction is completed - when we respond
  47. * to the host with the key value.
  48. */
  49. static struct {
  50. bool active; /* transaction status - active or not */
  51. int recv_len; /* number of bytes received. */
  52. struct hv_kvp_msg *kvp_msg; /* current message */
  53. struct vmbus_channel *recv_channel; /* chn we got the request */
  54. u64 recv_req_id; /* request ID. */
  55. void *kvp_context; /* for the channel callback */
  56. } kvp_transaction;
  57. /*
  58. * Before we can accept KVP messages from the host, we need
  59. * to handshake with the user level daemon. This state tracks
  60. * if we are in the handshake phase.
  61. */
  62. static bool in_hand_shake = true;
  63. /*
  64. * This state maintains the version number registered by the daemon.
  65. */
  66. static int dm_reg_value;
  67. static void kvp_send_key(struct work_struct *dummy);
  68. static void kvp_respond_to_host(struct hv_kvp_msg *msg, int error);
  69. static void kvp_work_func(struct work_struct *dummy);
  70. static void kvp_register(int);
  71. static DECLARE_DELAYED_WORK(kvp_work, kvp_work_func);
  72. static DECLARE_WORK(kvp_sendkey_work, kvp_send_key);
  73. static struct cb_id kvp_id = { CN_KVP_IDX, CN_KVP_VAL };
  74. static const char kvp_name[] = "kvp_kernel_module";
  75. static 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. * This number has no meaning, it satisfies the registration protocol.
  80. */
  81. #define HV_DRV_VERSION "3.1"
  82. static void
  83. kvp_register(int reg_value)
  84. {
  85. struct cn_msg *msg;
  86. struct hv_kvp_msg *kvp_msg;
  87. char *version;
  88. msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg), GFP_ATOMIC);
  89. if (msg) {
  90. kvp_msg = (struct hv_kvp_msg *)msg->data;
  91. version = kvp_msg->body.kvp_register.version;
  92. msg->id.idx = CN_KVP_IDX;
  93. msg->id.val = CN_KVP_VAL;
  94. kvp_msg->kvp_hdr.operation = reg_value;
  95. strcpy(version, HV_DRV_VERSION);
  96. msg->len = sizeof(struct hv_kvp_msg);
  97. cn_netlink_send(msg, 0, GFP_ATOMIC);
  98. kfree(msg);
  99. }
  100. }
  101. static void
  102. kvp_work_func(struct work_struct *dummy)
  103. {
  104. /*
  105. * If the timer fires, the user-mode component has not responded;
  106. * process the pending transaction.
  107. */
  108. kvp_respond_to_host(NULL, HV_E_FAIL);
  109. }
  110. static int kvp_handle_handshake(struct hv_kvp_msg *msg)
  111. {
  112. int ret = 1;
  113. switch (msg->kvp_hdr.operation) {
  114. case KVP_OP_REGISTER:
  115. dm_reg_value = KVP_OP_REGISTER;
  116. pr_info("KVP: IP injection functionality not available\n");
  117. pr_info("KVP: Upgrade the KVP daemon\n");
  118. break;
  119. case KVP_OP_REGISTER1:
  120. dm_reg_value = KVP_OP_REGISTER1;
  121. break;
  122. default:
  123. pr_info("KVP: incompatible daemon\n");
  124. pr_info("KVP: KVP version: %d, Daemon version: %d\n",
  125. KVP_OP_REGISTER1, msg->kvp_hdr.operation);
  126. ret = 0;
  127. }
  128. if (ret) {
  129. /*
  130. * We have a compatible daemon; complete the handshake.
  131. */
  132. pr_info("KVP: user-mode registering done.\n");
  133. kvp_register(dm_reg_value);
  134. kvp_transaction.active = false;
  135. if (kvp_transaction.kvp_context)
  136. hv_kvp_onchannelcallback(kvp_transaction.kvp_context);
  137. }
  138. return ret;
  139. }
  140. /*
  141. * Callback when data is received from user mode.
  142. */
  143. static void
  144. kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
  145. {
  146. struct hv_kvp_msg *message;
  147. struct hv_kvp_msg_enumerate *data;
  148. int error = 0;
  149. message = (struct hv_kvp_msg *)msg->data;
  150. /*
  151. * If we are negotiating the version information
  152. * with the daemon; handle that first.
  153. */
  154. if (in_hand_shake) {
  155. if (kvp_handle_handshake(message))
  156. in_hand_shake = false;
  157. return;
  158. }
  159. /*
  160. * Based on the version of the daemon, we propagate errors from the
  161. * daemon differently.
  162. */
  163. data = &message->body.kvp_enum_data;
  164. switch (dm_reg_value) {
  165. case KVP_OP_REGISTER:
  166. /*
  167. * Null string is used to pass back error condition.
  168. */
  169. if (data->data.key[0] == 0)
  170. error = HV_S_CONT;
  171. break;
  172. case KVP_OP_REGISTER1:
  173. /*
  174. * We use the message header information from
  175. * the user level daemon to transmit errors.
  176. */
  177. error = message->error;
  178. break;
  179. }
  180. /*
  181. * Complete the transaction by forwarding the key value
  182. * to the host. But first, cancel the timeout.
  183. */
  184. if (cancel_delayed_work_sync(&kvp_work))
  185. kvp_respond_to_host(message, error);
  186. }
  187. static int process_ob_ipinfo(void *in_msg, void *out_msg, int op)
  188. {
  189. struct hv_kvp_msg *in = in_msg;
  190. struct hv_kvp_ip_msg *out = out_msg;
  191. int len;
  192. switch (op) {
  193. case KVP_OP_GET_IP_INFO:
  194. /*
  195. * Transform all parameters into utf16 encoding.
  196. */
  197. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.ip_addr,
  198. strlen((char *)in->body.kvp_ip_val.ip_addr),
  199. UTF16_HOST_ENDIAN,
  200. (wchar_t *)out->kvp_ip_val.ip_addr,
  201. MAX_IP_ADDR_SIZE);
  202. if (len < 0)
  203. return len;
  204. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.sub_net,
  205. strlen((char *)in->body.kvp_ip_val.sub_net),
  206. UTF16_HOST_ENDIAN,
  207. (wchar_t *)out->kvp_ip_val.sub_net,
  208. MAX_IP_ADDR_SIZE);
  209. if (len < 0)
  210. return len;
  211. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.gate_way,
  212. strlen((char *)in->body.kvp_ip_val.gate_way),
  213. UTF16_HOST_ENDIAN,
  214. (wchar_t *)out->kvp_ip_val.gate_way,
  215. MAX_GATEWAY_SIZE);
  216. if (len < 0)
  217. return len;
  218. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.dns_addr,
  219. strlen((char *)in->body.kvp_ip_val.dns_addr),
  220. UTF16_HOST_ENDIAN,
  221. (wchar_t *)out->kvp_ip_val.dns_addr,
  222. MAX_IP_ADDR_SIZE);
  223. if (len < 0)
  224. return len;
  225. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.adapter_id,
  226. strlen((char *)in->body.kvp_ip_val.adapter_id),
  227. UTF16_HOST_ENDIAN,
  228. (wchar_t *)out->kvp_ip_val.adapter_id,
  229. MAX_IP_ADDR_SIZE);
  230. if (len < 0)
  231. return len;
  232. out->kvp_ip_val.dhcp_enabled =
  233. in->body.kvp_ip_val.dhcp_enabled;
  234. out->kvp_ip_val.addr_family =
  235. in->body.kvp_ip_val.addr_family;
  236. }
  237. return 0;
  238. }
  239. static void process_ib_ipinfo(void *in_msg, void *out_msg, int op)
  240. {
  241. struct hv_kvp_ip_msg *in = in_msg;
  242. struct hv_kvp_msg *out = out_msg;
  243. switch (op) {
  244. case KVP_OP_SET_IP_INFO:
  245. /*
  246. * Transform all parameters into utf8 encoding.
  247. */
  248. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.ip_addr,
  249. MAX_IP_ADDR_SIZE,
  250. UTF16_LITTLE_ENDIAN,
  251. (__u8 *)out->body.kvp_ip_val.ip_addr,
  252. MAX_IP_ADDR_SIZE);
  253. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.sub_net,
  254. MAX_IP_ADDR_SIZE,
  255. UTF16_LITTLE_ENDIAN,
  256. (__u8 *)out->body.kvp_ip_val.sub_net,
  257. MAX_IP_ADDR_SIZE);
  258. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.gate_way,
  259. MAX_GATEWAY_SIZE,
  260. UTF16_LITTLE_ENDIAN,
  261. (__u8 *)out->body.kvp_ip_val.gate_way,
  262. MAX_GATEWAY_SIZE);
  263. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.dns_addr,
  264. MAX_IP_ADDR_SIZE,
  265. UTF16_LITTLE_ENDIAN,
  266. (__u8 *)out->body.kvp_ip_val.dns_addr,
  267. MAX_IP_ADDR_SIZE);
  268. out->body.kvp_ip_val.dhcp_enabled = in->kvp_ip_val.dhcp_enabled;
  269. default:
  270. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.adapter_id,
  271. MAX_ADAPTER_ID_SIZE,
  272. UTF16_LITTLE_ENDIAN,
  273. (__u8 *)out->body.kvp_ip_val.adapter_id,
  274. MAX_ADAPTER_ID_SIZE);
  275. out->body.kvp_ip_val.addr_family = in->kvp_ip_val.addr_family;
  276. }
  277. }
  278. static void
  279. kvp_send_key(struct work_struct *dummy)
  280. {
  281. struct cn_msg *msg;
  282. struct hv_kvp_msg *message;
  283. struct hv_kvp_msg *in_msg;
  284. __u8 operation = kvp_transaction.kvp_msg->kvp_hdr.operation;
  285. __u8 pool = kvp_transaction.kvp_msg->kvp_hdr.pool;
  286. __u32 val32;
  287. __u64 val64;
  288. msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg) , GFP_ATOMIC);
  289. if (!msg)
  290. return;
  291. msg->id.idx = CN_KVP_IDX;
  292. msg->id.val = CN_KVP_VAL;
  293. message = (struct hv_kvp_msg *)msg->data;
  294. message->kvp_hdr.operation = operation;
  295. message->kvp_hdr.pool = pool;
  296. in_msg = kvp_transaction.kvp_msg;
  297. /*
  298. * The key/value strings sent from the host are encoded in
  299. * in utf16; convert it to utf8 strings.
  300. * The host assures us that the utf16 strings will not exceed
  301. * the max lengths specified. We will however, reserve room
  302. * for the string terminating character - in the utf16s_utf8s()
  303. * function we limit the size of the buffer where the converted
  304. * string is placed to HV_KVP_EXCHANGE_MAX_*_SIZE -1 to gaurantee
  305. * that the strings can be properly terminated!
  306. */
  307. switch (message->kvp_hdr.operation) {
  308. case KVP_OP_SET_IP_INFO:
  309. process_ib_ipinfo(in_msg, message, KVP_OP_SET_IP_INFO);
  310. break;
  311. case KVP_OP_GET_IP_INFO:
  312. process_ib_ipinfo(in_msg, message, KVP_OP_GET_IP_INFO);
  313. break;
  314. case KVP_OP_SET:
  315. switch (in_msg->body.kvp_set.data.value_type) {
  316. case REG_SZ:
  317. /*
  318. * The value is a string - utf16 encoding.
  319. */
  320. message->body.kvp_set.data.value_size =
  321. utf16s_to_utf8s(
  322. (wchar_t *)in_msg->body.kvp_set.data.value,
  323. in_msg->body.kvp_set.data.value_size,
  324. UTF16_LITTLE_ENDIAN,
  325. message->body.kvp_set.data.value,
  326. HV_KVP_EXCHANGE_MAX_VALUE_SIZE - 1) + 1;
  327. break;
  328. case REG_U32:
  329. /*
  330. * The value is a 32 bit scalar.
  331. * We save this as a utf8 string.
  332. */
  333. val32 = in_msg->body.kvp_set.data.value_u32;
  334. message->body.kvp_set.data.value_size =
  335. sprintf(message->body.kvp_set.data.value,
  336. "%d", val32) + 1;
  337. break;
  338. case REG_U64:
  339. /*
  340. * The value is a 64 bit scalar.
  341. * We save this as a utf8 string.
  342. */
  343. val64 = in_msg->body.kvp_set.data.value_u64;
  344. message->body.kvp_set.data.value_size =
  345. sprintf(message->body.kvp_set.data.value,
  346. "%llu", val64) + 1;
  347. break;
  348. }
  349. case KVP_OP_GET:
  350. message->body.kvp_set.data.key_size =
  351. utf16s_to_utf8s(
  352. (wchar_t *)in_msg->body.kvp_set.data.key,
  353. in_msg->body.kvp_set.data.key_size,
  354. UTF16_LITTLE_ENDIAN,
  355. message->body.kvp_set.data.key,
  356. HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
  357. break;
  358. case KVP_OP_DELETE:
  359. message->body.kvp_delete.key_size =
  360. utf16s_to_utf8s(
  361. (wchar_t *)in_msg->body.kvp_delete.key,
  362. in_msg->body.kvp_delete.key_size,
  363. UTF16_LITTLE_ENDIAN,
  364. message->body.kvp_delete.key,
  365. HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
  366. break;
  367. case KVP_OP_ENUMERATE:
  368. message->body.kvp_enum_data.index =
  369. in_msg->body.kvp_enum_data.index;
  370. break;
  371. }
  372. msg->len = sizeof(struct hv_kvp_msg);
  373. cn_netlink_send(msg, 0, GFP_ATOMIC);
  374. kfree(msg);
  375. return;
  376. }
  377. /*
  378. * Send a response back to the host.
  379. */
  380. static void
  381. kvp_respond_to_host(struct hv_kvp_msg *msg_to_host, int error)
  382. {
  383. struct hv_kvp_msg *kvp_msg;
  384. struct hv_kvp_exchg_msg_value *kvp_data;
  385. char *key_name;
  386. char *value;
  387. struct icmsg_hdr *icmsghdrp;
  388. int keylen = 0;
  389. int valuelen = 0;
  390. u32 buf_len;
  391. struct vmbus_channel *channel;
  392. u64 req_id;
  393. int ret;
  394. /*
  395. * If a transaction is not active; log and return.
  396. */
  397. if (!kvp_transaction.active) {
  398. /*
  399. * This is a spurious call!
  400. */
  401. pr_warn("KVP: Transaction not active\n");
  402. return;
  403. }
  404. /*
  405. * Copy the global state for completing the transaction. Note that
  406. * only one transaction can be active at a time.
  407. */
  408. buf_len = kvp_transaction.recv_len;
  409. channel = kvp_transaction.recv_channel;
  410. req_id = kvp_transaction.recv_req_id;
  411. kvp_transaction.active = false;
  412. icmsghdrp = (struct icmsg_hdr *)
  413. &recv_buffer[sizeof(struct vmbuspipe_hdr)];
  414. if (channel->onchannel_callback == NULL)
  415. /*
  416. * We have raced with util driver being unloaded;
  417. * silently return.
  418. */
  419. return;
  420. icmsghdrp->status = error;
  421. /*
  422. * If the error parameter is set, terminate the host's enumeration
  423. * on this pool.
  424. */
  425. if (error) {
  426. /*
  427. * Something failed or we have timedout;
  428. * terminate the current host-side iteration.
  429. */
  430. goto response_done;
  431. }
  432. kvp_msg = (struct hv_kvp_msg *)
  433. &recv_buffer[sizeof(struct vmbuspipe_hdr) +
  434. sizeof(struct icmsg_hdr)];
  435. switch (kvp_transaction.kvp_msg->kvp_hdr.operation) {
  436. case KVP_OP_GET_IP_INFO:
  437. ret = process_ob_ipinfo(msg_to_host,
  438. (struct hv_kvp_ip_msg *)kvp_msg,
  439. KVP_OP_GET_IP_INFO);
  440. if (ret < 0)
  441. icmsghdrp->status = HV_E_FAIL;
  442. goto response_done;
  443. case KVP_OP_SET_IP_INFO:
  444. goto response_done;
  445. case KVP_OP_GET:
  446. kvp_data = &kvp_msg->body.kvp_get.data;
  447. goto copy_value;
  448. case KVP_OP_SET:
  449. case KVP_OP_DELETE:
  450. goto response_done;
  451. default:
  452. break;
  453. }
  454. kvp_data = &kvp_msg->body.kvp_enum_data.data;
  455. key_name = msg_to_host->body.kvp_enum_data.data.key;
  456. /*
  457. * The windows host expects the key/value pair to be encoded
  458. * in utf16. Ensure that the key/value size reported to the host
  459. * will be less than or equal to the MAX size (including the
  460. * terminating character).
  461. */
  462. keylen = utf8s_to_utf16s(key_name, strlen(key_name), UTF16_HOST_ENDIAN,
  463. (wchar_t *) kvp_data->key,
  464. (HV_KVP_EXCHANGE_MAX_KEY_SIZE / 2) - 2);
  465. kvp_data->key_size = 2*(keylen + 1); /* utf16 encoding */
  466. copy_value:
  467. value = msg_to_host->body.kvp_enum_data.data.value;
  468. valuelen = utf8s_to_utf16s(value, strlen(value), UTF16_HOST_ENDIAN,
  469. (wchar_t *) kvp_data->value,
  470. (HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2) - 2);
  471. kvp_data->value_size = 2*(valuelen + 1); /* utf16 encoding */
  472. /*
  473. * If the utf8s to utf16s conversion failed; notify host
  474. * of the error.
  475. */
  476. if ((keylen < 0) || (valuelen < 0))
  477. icmsghdrp->status = HV_E_FAIL;
  478. kvp_data->value_type = REG_SZ; /* all our values are strings */
  479. response_done:
  480. icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE;
  481. vmbus_sendpacket(channel, recv_buffer, buf_len, req_id,
  482. VM_PKT_DATA_INBAND, 0);
  483. }
  484. /*
  485. * This callback is invoked when we get a KVP message from the host.
  486. * The host ensures that only one KVP transaction can be active at a time.
  487. * KVP implementation in Linux needs to forward the key to a user-mde
  488. * component to retrive the corresponding value. Consequently, we cannot
  489. * respond to the host in the conext of this callback. Since the host
  490. * guarantees that at most only one transaction can be active at a time,
  491. * we stash away the transaction state in a set of global variables.
  492. */
  493. void hv_kvp_onchannelcallback(void *context)
  494. {
  495. struct vmbus_channel *channel = context;
  496. u32 recvlen;
  497. u64 requestid;
  498. struct hv_kvp_msg *kvp_msg;
  499. struct icmsg_hdr *icmsghdrp;
  500. struct icmsg_negotiate *negop = NULL;
  501. int util_fw_version;
  502. int kvp_srv_version;
  503. if (kvp_transaction.active) {
  504. /*
  505. * We will defer processing this callback once
  506. * the current transaction is complete.
  507. */
  508. kvp_transaction.kvp_context = context;
  509. return;
  510. }
  511. vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen,
  512. &requestid);
  513. if (recvlen > 0) {
  514. icmsghdrp = (struct icmsg_hdr *)&recv_buffer[
  515. sizeof(struct vmbuspipe_hdr)];
  516. if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
  517. /*
  518. * Based on the host, select appropriate
  519. * framework and service versions we will
  520. * negotiate.
  521. */
  522. switch (vmbus_proto_version) {
  523. case (VERSION_WS2008):
  524. util_fw_version = UTIL_WS2K8_FW_VERSION;
  525. kvp_srv_version = WS2008_SRV_VERSION;
  526. break;
  527. case (VERSION_WIN7):
  528. util_fw_version = UTIL_FW_VERSION;
  529. kvp_srv_version = WIN7_SRV_VERSION;
  530. break;
  531. default:
  532. util_fw_version = UTIL_FW_VERSION;
  533. kvp_srv_version = WIN8_SRV_VERSION;
  534. }
  535. vmbus_prep_negotiate_resp(icmsghdrp, negop,
  536. recv_buffer, util_fw_version,
  537. kvp_srv_version);
  538. } else {
  539. kvp_msg = (struct hv_kvp_msg *)&recv_buffer[
  540. sizeof(struct vmbuspipe_hdr) +
  541. sizeof(struct icmsg_hdr)];
  542. /*
  543. * Stash away this global state for completing the
  544. * transaction; note transactions are serialized.
  545. */
  546. kvp_transaction.recv_len = recvlen;
  547. kvp_transaction.recv_channel = channel;
  548. kvp_transaction.recv_req_id = requestid;
  549. kvp_transaction.active = true;
  550. kvp_transaction.kvp_msg = kvp_msg;
  551. /*
  552. * Get the information from the
  553. * user-mode component.
  554. * component. This transaction will be
  555. * completed when we get the value from
  556. * the user-mode component.
  557. * Set a timeout to deal with
  558. * user-mode not responding.
  559. */
  560. schedule_work(&kvp_sendkey_work);
  561. schedule_delayed_work(&kvp_work, 5*HZ);
  562. return;
  563. }
  564. icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
  565. | ICMSGHDRFLAG_RESPONSE;
  566. vmbus_sendpacket(channel, recv_buffer,
  567. recvlen, requestid,
  568. VM_PKT_DATA_INBAND, 0);
  569. }
  570. }
  571. int
  572. hv_kvp_init(struct hv_util_service *srv)
  573. {
  574. int err;
  575. err = cn_add_callback(&kvp_id, kvp_name, kvp_cn_callback);
  576. if (err)
  577. return err;
  578. recv_buffer = srv->recv_buffer;
  579. /*
  580. * When this driver loads, the user level daemon that
  581. * processes the host requests may not yet be running.
  582. * Defer processing channel callbacks until the daemon
  583. * has registered.
  584. */
  585. kvp_transaction.active = true;
  586. return 0;
  587. }
  588. void hv_kvp_deinit(void)
  589. {
  590. cn_del_callback(&kvp_id);
  591. cancel_delayed_work_sync(&kvp_work);
  592. cancel_work_sync(&kvp_sendkey_work);
  593. }