channel_mgmt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * Copyright (c) 2009, Microsoft Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  15. * Place - Suite 330, Boston, MA 02111-1307 USA.
  16. *
  17. * Authors:
  18. * Haiyang Zhang <haiyangz@microsoft.com>
  19. * Hank Janssen <hjanssen@microsoft.com>
  20. */
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include <linux/wait.h>
  25. #include <linux/mm.h>
  26. #include <linux/slab.h>
  27. #include <linux/list.h>
  28. #include <linux/module.h>
  29. #include <linux/completion.h>
  30. #include <linux/hyperv.h>
  31. #include "hyperv_vmbus.h"
  32. struct vmbus_channel_message_table_entry {
  33. enum vmbus_channel_message_type message_type;
  34. void (*message_handler)(struct vmbus_channel_message_header *msg);
  35. };
  36. /**
  37. * vmbus_prep_negotiate_resp() - Create default response for Hyper-V Negotiate message
  38. * @icmsghdrp: Pointer to msg header structure
  39. * @icmsg_negotiate: Pointer to negotiate message structure
  40. * @buf: Raw buffer channel data
  41. *
  42. * @icmsghdrp is of type &struct icmsg_hdr.
  43. * @negop is of type &struct icmsg_negotiate.
  44. * Set up and fill in default negotiate response message.
  45. *
  46. * The max_fw_version specifies the maximum framework version that
  47. * we can support and max _srv_version specifies the maximum service
  48. * version we can support. A special value MAX_SRV_VER can be
  49. * specified to indicate that we can handle the maximum version
  50. * exposed by the host.
  51. *
  52. * Mainly used by Hyper-V drivers.
  53. */
  54. void vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp,
  55. struct icmsg_negotiate *negop, u8 *buf,
  56. int max_fw_version, int max_srv_version)
  57. {
  58. int icframe_vercnt;
  59. int icmsg_vercnt;
  60. int i;
  61. icmsghdrp->icmsgsize = 0x10;
  62. negop = (struct icmsg_negotiate *)&buf[
  63. sizeof(struct vmbuspipe_hdr) +
  64. sizeof(struct icmsg_hdr)];
  65. icframe_vercnt = negop->icframe_vercnt;
  66. icmsg_vercnt = negop->icmsg_vercnt;
  67. /*
  68. * Select the framework version number we will
  69. * support.
  70. */
  71. for (i = 0; i < negop->icframe_vercnt; i++) {
  72. if (negop->icversion_data[i].major <= max_fw_version)
  73. icframe_vercnt = negop->icversion_data[i].major;
  74. }
  75. for (i = negop->icframe_vercnt;
  76. (i < negop->icframe_vercnt + negop->icmsg_vercnt); i++) {
  77. if (negop->icversion_data[i].major <= max_srv_version)
  78. icmsg_vercnt = negop->icversion_data[i].major;
  79. }
  80. /*
  81. * Respond with the maximum framework and service
  82. * version numbers we can support.
  83. */
  84. negop->icframe_vercnt = 1;
  85. negop->icmsg_vercnt = 1;
  86. negop->icversion_data[0].major = icframe_vercnt;
  87. negop->icversion_data[0].minor = 0;
  88. negop->icversion_data[1].major = icmsg_vercnt;
  89. negop->icversion_data[1].minor = 0;
  90. }
  91. EXPORT_SYMBOL_GPL(vmbus_prep_negotiate_resp);
  92. /*
  93. * alloc_channel - Allocate and initialize a vmbus channel object
  94. */
  95. static struct vmbus_channel *alloc_channel(void)
  96. {
  97. struct vmbus_channel *channel;
  98. channel = kzalloc(sizeof(*channel), GFP_ATOMIC);
  99. if (!channel)
  100. return NULL;
  101. spin_lock_init(&channel->inbound_lock);
  102. channel->controlwq = create_workqueue("hv_vmbus_ctl");
  103. if (!channel->controlwq) {
  104. kfree(channel);
  105. return NULL;
  106. }
  107. return channel;
  108. }
  109. /*
  110. * release_hannel - Release the vmbus channel object itself
  111. */
  112. static void release_channel(struct work_struct *work)
  113. {
  114. struct vmbus_channel *channel = container_of(work,
  115. struct vmbus_channel,
  116. work);
  117. destroy_workqueue(channel->controlwq);
  118. kfree(channel);
  119. }
  120. /*
  121. * free_channel - Release the resources used by the vmbus channel object
  122. */
  123. static void free_channel(struct vmbus_channel *channel)
  124. {
  125. /*
  126. * We have to release the channel's workqueue/thread in the vmbus's
  127. * workqueue/thread context
  128. * ie we can't destroy ourselves.
  129. */
  130. INIT_WORK(&channel->work, release_channel);
  131. queue_work(vmbus_connection.work_queue, &channel->work);
  132. }
  133. /*
  134. * vmbus_process_rescind_offer -
  135. * Rescind the offer by initiating a device removal
  136. */
  137. static void vmbus_process_rescind_offer(struct work_struct *work)
  138. {
  139. struct vmbus_channel *channel = container_of(work,
  140. struct vmbus_channel,
  141. work);
  142. unsigned long flags;
  143. struct vmbus_channel_relid_released msg;
  144. vmbus_device_unregister(channel->device_obj);
  145. memset(&msg, 0, sizeof(struct vmbus_channel_relid_released));
  146. msg.child_relid = channel->offermsg.child_relid;
  147. msg.header.msgtype = CHANNELMSG_RELID_RELEASED;
  148. vmbus_post_msg(&msg, sizeof(struct vmbus_channel_relid_released));
  149. spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
  150. list_del(&channel->listentry);
  151. spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
  152. free_channel(channel);
  153. }
  154. void vmbus_free_channels(void)
  155. {
  156. struct vmbus_channel *channel;
  157. list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) {
  158. vmbus_device_unregister(channel->device_obj);
  159. kfree(channel->device_obj);
  160. free_channel(channel);
  161. }
  162. }
  163. /*
  164. * vmbus_process_offer - Process the offer by creating a channel/device
  165. * associated with this offer
  166. */
  167. static void vmbus_process_offer(struct work_struct *work)
  168. {
  169. struct vmbus_channel *newchannel = container_of(work,
  170. struct vmbus_channel,
  171. work);
  172. struct vmbus_channel *channel;
  173. bool fnew = true;
  174. int ret;
  175. unsigned long flags;
  176. /* The next possible work is rescind handling */
  177. INIT_WORK(&newchannel->work, vmbus_process_rescind_offer);
  178. /* Make sure this is a new offer */
  179. spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
  180. list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) {
  181. if (!uuid_le_cmp(channel->offermsg.offer.if_type,
  182. newchannel->offermsg.offer.if_type) &&
  183. !uuid_le_cmp(channel->offermsg.offer.if_instance,
  184. newchannel->offermsg.offer.if_instance)) {
  185. fnew = false;
  186. break;
  187. }
  188. }
  189. if (fnew)
  190. list_add_tail(&newchannel->listentry,
  191. &vmbus_connection.chn_list);
  192. spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
  193. if (!fnew) {
  194. free_channel(newchannel);
  195. return;
  196. }
  197. /*
  198. * Start the process of binding this offer to the driver
  199. * We need to set the DeviceObject field before calling
  200. * vmbus_child_dev_add()
  201. */
  202. newchannel->device_obj = vmbus_device_create(
  203. &newchannel->offermsg.offer.if_type,
  204. &newchannel->offermsg.offer.if_instance,
  205. newchannel);
  206. /*
  207. * Add the new device to the bus. This will kick off device-driver
  208. * binding which eventually invokes the device driver's AddDevice()
  209. * method.
  210. */
  211. ret = vmbus_device_register(newchannel->device_obj);
  212. if (ret != 0) {
  213. pr_err("unable to add child device object (relid %d)\n",
  214. newchannel->offermsg.child_relid);
  215. spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
  216. list_del(&newchannel->listentry);
  217. spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
  218. kfree(newchannel->device_obj);
  219. free_channel(newchannel);
  220. } else {
  221. /*
  222. * This state is used to indicate a successful open
  223. * so that when we do close the channel normally, we
  224. * can cleanup properly
  225. */
  226. newchannel->state = CHANNEL_OPEN_STATE;
  227. }
  228. }
  229. enum {
  230. IDE = 0,
  231. SCSI,
  232. NIC,
  233. MAX_PERF_CHN,
  234. };
  235. /*
  236. * This is an array of device_ids (device types) that are performance critical.
  237. * We attempt to distribute the interrupt load for these devices across
  238. * all available CPUs.
  239. */
  240. static const struct hv_vmbus_device_id hp_devs[] = {
  241. /* IDE */
  242. { HV_IDE_GUID, },
  243. /* Storage - SCSI */
  244. { HV_SCSI_GUID, },
  245. /* Network */
  246. { HV_NIC_GUID, },
  247. };
  248. /*
  249. * We use this state to statically distribute the channel interrupt load.
  250. */
  251. static u32 next_vp;
  252. /*
  253. * Starting with Win8, we can statically distribute the incoming
  254. * channel interrupt load by binding a channel to VCPU. We
  255. * implement here a simple round robin scheme for distributing
  256. * the interrupt load.
  257. * We will bind channels that are not performance critical to cpu 0 and
  258. * performance critical channels (IDE, SCSI and Network) will be uniformly
  259. * distributed across all available CPUs.
  260. */
  261. static u32 get_vp_index(uuid_le *type_guid)
  262. {
  263. u32 cur_cpu;
  264. int i;
  265. bool perf_chn = false;
  266. u32 max_cpus = num_online_cpus();
  267. for (i = IDE; i < MAX_PERF_CHN; i++) {
  268. if (!memcmp(type_guid->b, hp_devs[i].guid,
  269. sizeof(uuid_le))) {
  270. perf_chn = true;
  271. break;
  272. }
  273. }
  274. if ((vmbus_proto_version == VERSION_WS2008) ||
  275. (vmbus_proto_version == VERSION_WIN7) || (!perf_chn)) {
  276. /*
  277. * Prior to win8, all channel interrupts are
  278. * delivered on cpu 0.
  279. * Also if the channel is not a performance critical
  280. * channel, bind it to cpu 0.
  281. */
  282. return 0;
  283. }
  284. cur_cpu = (++next_vp % max_cpus);
  285. return cur_cpu;
  286. }
  287. /*
  288. * vmbus_onoffer - Handler for channel offers from vmbus in parent partition.
  289. *
  290. */
  291. static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
  292. {
  293. struct vmbus_channel_offer_channel *offer;
  294. struct vmbus_channel *newchannel;
  295. offer = (struct vmbus_channel_offer_channel *)hdr;
  296. /* Allocate the channel object and save this offer. */
  297. newchannel = alloc_channel();
  298. if (!newchannel) {
  299. pr_err("Unable to allocate channel object\n");
  300. return;
  301. }
  302. /*
  303. * By default we setup state to enable batched
  304. * reading. A specific service can choose to
  305. * disable this prior to opening the channel.
  306. */
  307. newchannel->batched_reading = true;
  308. /*
  309. * Setup state for signalling the host.
  310. */
  311. newchannel->sig_event = (struct hv_input_signal_event *)
  312. (ALIGN((unsigned long)
  313. &newchannel->sig_buf,
  314. HV_HYPERCALL_PARAM_ALIGN));
  315. newchannel->sig_event->connectionid.asu32 = 0;
  316. newchannel->sig_event->connectionid.u.id = VMBUS_EVENT_CONNECTION_ID;
  317. newchannel->sig_event->flag_number = 0;
  318. newchannel->sig_event->rsvdz = 0;
  319. if (vmbus_proto_version != VERSION_WS2008) {
  320. newchannel->is_dedicated_interrupt =
  321. (offer->is_dedicated_interrupt != 0);
  322. newchannel->sig_event->connectionid.u.id =
  323. offer->connection_id;
  324. }
  325. newchannel->target_vp = get_vp_index(&offer->offer.if_type);
  326. memcpy(&newchannel->offermsg, offer,
  327. sizeof(struct vmbus_channel_offer_channel));
  328. newchannel->monitor_grp = (u8)offer->monitorid / 32;
  329. newchannel->monitor_bit = (u8)offer->monitorid % 32;
  330. INIT_WORK(&newchannel->work, vmbus_process_offer);
  331. queue_work(newchannel->controlwq, &newchannel->work);
  332. }
  333. /*
  334. * vmbus_onoffer_rescind - Rescind offer handler.
  335. *
  336. * We queue a work item to process this offer synchronously
  337. */
  338. static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
  339. {
  340. struct vmbus_channel_rescind_offer *rescind;
  341. struct vmbus_channel *channel;
  342. rescind = (struct vmbus_channel_rescind_offer *)hdr;
  343. channel = relid2channel(rescind->child_relid);
  344. if (channel == NULL)
  345. /* Just return here, no channel found */
  346. return;
  347. /* work is initialized for vmbus_process_rescind_offer() from
  348. * vmbus_process_offer() where the channel got created */
  349. queue_work(channel->controlwq, &channel->work);
  350. }
  351. /*
  352. * vmbus_onoffers_delivered -
  353. * This is invoked when all offers have been delivered.
  354. *
  355. * Nothing to do here.
  356. */
  357. static void vmbus_onoffers_delivered(
  358. struct vmbus_channel_message_header *hdr)
  359. {
  360. }
  361. /*
  362. * vmbus_onopen_result - Open result handler.
  363. *
  364. * This is invoked when we received a response to our channel open request.
  365. * Find the matching request, copy the response and signal the requesting
  366. * thread.
  367. */
  368. static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
  369. {
  370. struct vmbus_channel_open_result *result;
  371. struct vmbus_channel_msginfo *msginfo;
  372. struct vmbus_channel_message_header *requestheader;
  373. struct vmbus_channel_open_channel *openmsg;
  374. unsigned long flags;
  375. result = (struct vmbus_channel_open_result *)hdr;
  376. /*
  377. * Find the open msg, copy the result and signal/unblock the wait event
  378. */
  379. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  380. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  381. msglistentry) {
  382. requestheader =
  383. (struct vmbus_channel_message_header *)msginfo->msg;
  384. if (requestheader->msgtype == CHANNELMSG_OPENCHANNEL) {
  385. openmsg =
  386. (struct vmbus_channel_open_channel *)msginfo->msg;
  387. if (openmsg->child_relid == result->child_relid &&
  388. openmsg->openid == result->openid) {
  389. memcpy(&msginfo->response.open_result,
  390. result,
  391. sizeof(
  392. struct vmbus_channel_open_result));
  393. complete(&msginfo->waitevent);
  394. break;
  395. }
  396. }
  397. }
  398. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  399. }
  400. /*
  401. * vmbus_ongpadl_created - GPADL created handler.
  402. *
  403. * This is invoked when we received a response to our gpadl create request.
  404. * Find the matching request, copy the response and signal the requesting
  405. * thread.
  406. */
  407. static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
  408. {
  409. struct vmbus_channel_gpadl_created *gpadlcreated;
  410. struct vmbus_channel_msginfo *msginfo;
  411. struct vmbus_channel_message_header *requestheader;
  412. struct vmbus_channel_gpadl_header *gpadlheader;
  413. unsigned long flags;
  414. gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr;
  415. /*
  416. * Find the establish msg, copy the result and signal/unblock the wait
  417. * event
  418. */
  419. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  420. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  421. msglistentry) {
  422. requestheader =
  423. (struct vmbus_channel_message_header *)msginfo->msg;
  424. if (requestheader->msgtype == CHANNELMSG_GPADL_HEADER) {
  425. gpadlheader =
  426. (struct vmbus_channel_gpadl_header *)requestheader;
  427. if ((gpadlcreated->child_relid ==
  428. gpadlheader->child_relid) &&
  429. (gpadlcreated->gpadl == gpadlheader->gpadl)) {
  430. memcpy(&msginfo->response.gpadl_created,
  431. gpadlcreated,
  432. sizeof(
  433. struct vmbus_channel_gpadl_created));
  434. complete(&msginfo->waitevent);
  435. break;
  436. }
  437. }
  438. }
  439. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  440. }
  441. /*
  442. * vmbus_ongpadl_torndown - GPADL torndown handler.
  443. *
  444. * This is invoked when we received a response to our gpadl teardown request.
  445. * Find the matching request, copy the response and signal the requesting
  446. * thread.
  447. */
  448. static void vmbus_ongpadl_torndown(
  449. struct vmbus_channel_message_header *hdr)
  450. {
  451. struct vmbus_channel_gpadl_torndown *gpadl_torndown;
  452. struct vmbus_channel_msginfo *msginfo;
  453. struct vmbus_channel_message_header *requestheader;
  454. struct vmbus_channel_gpadl_teardown *gpadl_teardown;
  455. unsigned long flags;
  456. gpadl_torndown = (struct vmbus_channel_gpadl_torndown *)hdr;
  457. /*
  458. * Find the open msg, copy the result and signal/unblock the wait event
  459. */
  460. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  461. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  462. msglistentry) {
  463. requestheader =
  464. (struct vmbus_channel_message_header *)msginfo->msg;
  465. if (requestheader->msgtype == CHANNELMSG_GPADL_TEARDOWN) {
  466. gpadl_teardown =
  467. (struct vmbus_channel_gpadl_teardown *)requestheader;
  468. if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) {
  469. memcpy(&msginfo->response.gpadl_torndown,
  470. gpadl_torndown,
  471. sizeof(
  472. struct vmbus_channel_gpadl_torndown));
  473. complete(&msginfo->waitevent);
  474. break;
  475. }
  476. }
  477. }
  478. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  479. }
  480. /*
  481. * vmbus_onversion_response - Version response handler
  482. *
  483. * This is invoked when we received a response to our initiate contact request.
  484. * Find the matching request, copy the response and signal the requesting
  485. * thread.
  486. */
  487. static void vmbus_onversion_response(
  488. struct vmbus_channel_message_header *hdr)
  489. {
  490. struct vmbus_channel_msginfo *msginfo;
  491. struct vmbus_channel_message_header *requestheader;
  492. struct vmbus_channel_version_response *version_response;
  493. unsigned long flags;
  494. version_response = (struct vmbus_channel_version_response *)hdr;
  495. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  496. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  497. msglistentry) {
  498. requestheader =
  499. (struct vmbus_channel_message_header *)msginfo->msg;
  500. if (requestheader->msgtype ==
  501. CHANNELMSG_INITIATE_CONTACT) {
  502. memcpy(&msginfo->response.version_response,
  503. version_response,
  504. sizeof(struct vmbus_channel_version_response));
  505. complete(&msginfo->waitevent);
  506. }
  507. }
  508. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  509. }
  510. /* Channel message dispatch table */
  511. static struct vmbus_channel_message_table_entry
  512. channel_message_table[CHANNELMSG_COUNT] = {
  513. {CHANNELMSG_INVALID, NULL},
  514. {CHANNELMSG_OFFERCHANNEL, vmbus_onoffer},
  515. {CHANNELMSG_RESCIND_CHANNELOFFER, vmbus_onoffer_rescind},
  516. {CHANNELMSG_REQUESTOFFERS, NULL},
  517. {CHANNELMSG_ALLOFFERS_DELIVERED, vmbus_onoffers_delivered},
  518. {CHANNELMSG_OPENCHANNEL, NULL},
  519. {CHANNELMSG_OPENCHANNEL_RESULT, vmbus_onopen_result},
  520. {CHANNELMSG_CLOSECHANNEL, NULL},
  521. {CHANNELMSG_GPADL_HEADER, NULL},
  522. {CHANNELMSG_GPADL_BODY, NULL},
  523. {CHANNELMSG_GPADL_CREATED, vmbus_ongpadl_created},
  524. {CHANNELMSG_GPADL_TEARDOWN, NULL},
  525. {CHANNELMSG_GPADL_TORNDOWN, vmbus_ongpadl_torndown},
  526. {CHANNELMSG_RELID_RELEASED, NULL},
  527. {CHANNELMSG_INITIATE_CONTACT, NULL},
  528. {CHANNELMSG_VERSION_RESPONSE, vmbus_onversion_response},
  529. {CHANNELMSG_UNLOAD, NULL},
  530. };
  531. /*
  532. * vmbus_onmessage - Handler for channel protocol messages.
  533. *
  534. * This is invoked in the vmbus worker thread context.
  535. */
  536. void vmbus_onmessage(void *context)
  537. {
  538. struct hv_message *msg = context;
  539. struct vmbus_channel_message_header *hdr;
  540. int size;
  541. hdr = (struct vmbus_channel_message_header *)msg->u.payload;
  542. size = msg->header.payload_size;
  543. if (hdr->msgtype >= CHANNELMSG_COUNT) {
  544. pr_err("Received invalid channel message type %d size %d\n",
  545. hdr->msgtype, size);
  546. print_hex_dump_bytes("", DUMP_PREFIX_NONE,
  547. (unsigned char *)msg->u.payload, size);
  548. return;
  549. }
  550. if (channel_message_table[hdr->msgtype].message_handler)
  551. channel_message_table[hdr->msgtype].message_handler(hdr);
  552. else
  553. pr_err("Unhandled channel message type %d\n", hdr->msgtype);
  554. }
  555. /*
  556. * vmbus_request_offers - Send a request to get all our pending offers.
  557. */
  558. int vmbus_request_offers(void)
  559. {
  560. struct vmbus_channel_message_header *msg;
  561. struct vmbus_channel_msginfo *msginfo;
  562. int ret, t;
  563. msginfo = kmalloc(sizeof(*msginfo) +
  564. sizeof(struct vmbus_channel_message_header),
  565. GFP_KERNEL);
  566. if (!msginfo)
  567. return -ENOMEM;
  568. init_completion(&msginfo->waitevent);
  569. msg = (struct vmbus_channel_message_header *)msginfo->msg;
  570. msg->msgtype = CHANNELMSG_REQUESTOFFERS;
  571. ret = vmbus_post_msg(msg,
  572. sizeof(struct vmbus_channel_message_header));
  573. if (ret != 0) {
  574. pr_err("Unable to request offers - %d\n", ret);
  575. goto cleanup;
  576. }
  577. t = wait_for_completion_timeout(&msginfo->waitevent, 5*HZ);
  578. if (t == 0) {
  579. ret = -ETIMEDOUT;
  580. goto cleanup;
  581. }
  582. cleanup:
  583. kfree(msginfo);
  584. return ret;
  585. }
  586. /* eof */