Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1 | /* |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2 | * Copyright (c) 2009, Microsoft Corporation. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 15 | * Place - Suite 330, Boston, MA 02111-1307 USA. |
| 16 | * |
| 17 | * Authors: |
| 18 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 19 | * Hank Janssen <hjanssen@microsoft.com> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 20 | */ |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 22 | |
Greg Kroah-Hartman | 5654e93 | 2009-07-14 15:08:20 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 24 | #include <linux/sched.h> |
| 25 | #include <linux/wait.h> |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 26 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 29 | #include <linux/hyperv.h> |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 30 | #include <linux/uio.h> |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 31 | #include <linux/interrupt.h> |
K. Y. Srinivasan | 3f335ea | 2011-05-12 19:34:15 -0700 | [diff] [blame] | 32 | |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 33 | #include "hyperv_vmbus.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 34 | |
K. Y. Srinivasan | e3fe0bb | 2011-02-11 10:00:12 -0800 | [diff] [blame] | 35 | #define NUM_PAGES_SPANNED(addr, len) \ |
| 36 | ((PAGE_ALIGN(addr + len) >> PAGE_SHIFT) - (addr >> PAGE_SHIFT)) |
| 37 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 38 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 39 | * vmbus_setevent- Trigger an event notification on the specified |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 40 | * channel. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 41 | */ |
K. Y. Srinivasan | 1f6ee4e | 2016-11-06 13:14:17 -0800 | [diff] [blame] | 42 | void vmbus_setevent(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 43 | { |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 44 | struct hv_monitor_page *monitorpage; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 45 | |
K. Y. Srinivasan | 3724287 | 2016-07-01 16:26:37 -0700 | [diff] [blame] | 46 | /* |
| 47 | * For channels marked as in "low latency" mode |
| 48 | * bypass the monitor page mechanism. |
| 49 | */ |
Stephen Hemminger | 5c1bec6 | 2017-02-05 17:20:31 -0700 | [diff] [blame] | 50 | if (channel->offermsg.monitor_allocated && !channel->low_latency) { |
| 51 | vmbus_send_interrupt(channel->offermsg.child_relid); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 52 | |
Greg Kroah-Hartman | 8681db4 | 2013-09-13 11:32:55 -0700 | [diff] [blame] | 53 | /* Get the child to parent monitor page */ |
| 54 | monitorpage = vmbus_connection.monitor_pages[1]; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 55 | |
Olaf Hering | 2235658 | 2011-03-21 14:41:37 +0100 | [diff] [blame] | 56 | sync_set_bit(channel->monitor_bit, |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 57 | (unsigned long *)&monitorpage->trigger_group |
| 58 | [channel->monitor_grp].pending); |
Bill Pemberton | 7c369f4 | 2009-07-29 17:00:11 -0400 | [diff] [blame] | 59 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 60 | } else { |
K. Y. Srinivasan | 21c3bef | 2012-12-01 06:46:43 -0800 | [diff] [blame] | 61 | vmbus_set_event(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 62 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 63 | } |
K. Y. Srinivasan | 1f6ee4e | 2016-11-06 13:14:17 -0800 | [diff] [blame] | 64 | EXPORT_SYMBOL_GPL(vmbus_setevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 65 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 66 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 67 | * vmbus_open - Open the specified channel. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 68 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 69 | int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 70 | u32 recv_ringbuffer_size, void *userdata, u32 userdatalen, |
| 71 | void (*onchannelcallback)(void *context), void *context) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 72 | { |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 73 | struct vmbus_channel_open_channel *open_msg; |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 74 | struct vmbus_channel_msginfo *open_info = NULL; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 75 | unsigned long flags; |
Nicholas Mc Guire | 08a9513 | 2015-02-27 11:26:01 -0800 | [diff] [blame] | 76 | int ret, err = 0; |
K. Y. Srinivasan | 294409d | 2015-05-31 21:27:03 -0700 | [diff] [blame] | 77 | struct page *page; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 78 | |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 79 | if (send_ringbuffer_size % PAGE_SIZE || |
| 80 | recv_ringbuffer_size % PAGE_SIZE) |
| 81 | return -EINVAL; |
| 82 | |
Vitaly Kuznetsov | 67fae05 | 2015-01-20 16:45:05 +0100 | [diff] [blame] | 83 | spin_lock_irqsave(&newchannel->lock, flags); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 84 | if (newchannel->state == CHANNEL_OPEN_STATE) { |
| 85 | newchannel->state = CHANNEL_OPENING_STATE; |
| 86 | } else { |
Vitaly Kuznetsov | 67fae05 | 2015-01-20 16:45:05 +0100 | [diff] [blame] | 87 | spin_unlock_irqrestore(&newchannel->lock, flags); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 88 | return -EINVAL; |
| 89 | } |
Vitaly Kuznetsov | 67fae05 | 2015-01-20 16:45:05 +0100 | [diff] [blame] | 90 | spin_unlock_irqrestore(&newchannel->lock, flags); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 91 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 92 | newchannel->onchannel_callback = onchannelcallback; |
| 93 | newchannel->channel_callback_context = context; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 94 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 95 | /* Allocate the ring buffer */ |
K. Y. Srinivasan | 294409d | 2015-05-31 21:27:03 -0700 | [diff] [blame] | 96 | page = alloc_pages_node(cpu_to_node(newchannel->target_cpu), |
| 97 | GFP_KERNEL|__GFP_ZERO, |
| 98 | get_order(send_ringbuffer_size + |
| 99 | recv_ringbuffer_size)); |
| 100 | |
| 101 | if (!page) |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 102 | page = alloc_pages(GFP_KERNEL|__GFP_ZERO, |
| 103 | get_order(send_ringbuffer_size + |
| 104 | recv_ringbuffer_size)); |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame] | 105 | |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 106 | if (!page) { |
Dexuan Cui | ac0d12b | 2015-02-27 11:26:00 -0800 | [diff] [blame] | 107 | err = -ENOMEM; |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 108 | goto error_set_chnstate; |
Dexuan Cui | ac0d12b | 2015-02-27 11:26:00 -0800 | [diff] [blame] | 109 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 110 | |
Vitaly Kuznetsov | 9988ce6 | 2016-09-02 05:58:20 -0700 | [diff] [blame] | 111 | newchannel->ringbuffer_pages = page_address(page); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 112 | newchannel->ringbuffer_pagecount = (send_ringbuffer_size + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 113 | recv_ringbuffer_size) >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 114 | |
Vitaly Kuznetsov | 9988ce6 | 2016-09-02 05:58:20 -0700 | [diff] [blame] | 115 | ret = hv_ringbuffer_init(&newchannel->outbound, page, |
| 116 | send_ringbuffer_size >> PAGE_SHIFT); |
K. Y. Srinivasan | 72a95cb | 2011-05-10 07:55:21 -0700 | [diff] [blame] | 117 | |
Haiyang Zhang | fd4dc88 | 2010-05-13 15:56:30 +0000 | [diff] [blame] | 118 | if (ret != 0) { |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 119 | err = ret; |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 120 | goto error_free_pages; |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 121 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 122 | |
Vitaly Kuznetsov | 9988ce6 | 2016-09-02 05:58:20 -0700 | [diff] [blame] | 123 | ret = hv_ringbuffer_init(&newchannel->inbound, |
| 124 | &page[send_ringbuffer_size >> PAGE_SHIFT], |
| 125 | recv_ringbuffer_size >> PAGE_SHIFT); |
Haiyang Zhang | fd4dc88 | 2010-05-13 15:56:30 +0000 | [diff] [blame] | 126 | if (ret != 0) { |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 127 | err = ret; |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 128 | goto error_free_pages; |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 129 | } |
| 130 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 131 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 132 | /* Establish the gpadl for the ring buffer */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 133 | newchannel->ringbuffer_gpadlhandle = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 134 | |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 135 | ret = vmbus_establish_gpadl(newchannel, |
Vitaly Kuznetsov | 9988ce6 | 2016-09-02 05:58:20 -0700 | [diff] [blame] | 136 | page_address(page), |
| 137 | send_ringbuffer_size + |
| 138 | recv_ringbuffer_size, |
| 139 | &newchannel->ringbuffer_gpadlhandle); |
Bill Pemberton | b94ef34 | 2010-05-05 15:27:37 -0400 | [diff] [blame] | 140 | |
Haiyang Zhang | fd4dc88 | 2010-05-13 15:56:30 +0000 | [diff] [blame] | 141 | if (ret != 0) { |
Bill Pemberton | b94ef34 | 2010-05-05 15:27:37 -0400 | [diff] [blame] | 142 | err = ret; |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 143 | goto error_free_pages; |
Bill Pemberton | b94ef34 | 2010-05-05 15:27:37 -0400 | [diff] [blame] | 144 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 145 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 146 | /* Create and init the channel open message */ |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 147 | open_info = kmalloc(sizeof(*open_info) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 148 | sizeof(struct vmbus_channel_open_channel), |
| 149 | GFP_KERNEL); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 150 | if (!open_info) { |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 151 | err = -ENOMEM; |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 152 | goto error_free_gpadl; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 153 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 154 | |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 155 | init_completion(&open_info->waitevent); |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 156 | open_info->waiting_channel = newchannel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 157 | |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 158 | open_msg = (struct vmbus_channel_open_channel *)open_info->msg; |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 159 | open_msg->header.msgtype = CHANNELMSG_OPENCHANNEL; |
| 160 | open_msg->openid = newchannel->offermsg.child_relid; |
| 161 | open_msg->child_relid = newchannel->offermsg.child_relid; |
| 162 | open_msg->ringbuffer_gpadlhandle = newchannel->ringbuffer_gpadlhandle; |
| 163 | open_msg->downstream_ringbuffer_pageoffset = send_ringbuffer_size >> |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 164 | PAGE_SHIFT; |
K. Y. Srinivasan | abbf3b2 | 2012-12-01 06:46:48 -0800 | [diff] [blame] | 165 | open_msg->target_vp = newchannel->target_vp; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 166 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 167 | if (userdatalen > MAX_USER_DEFINED_BYTES) { |
Bill Pemberton | c827f94 | 2010-05-05 15:27:38 -0400 | [diff] [blame] | 168 | err = -EINVAL; |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 169 | goto error_free_gpadl; |
Bill Pemberton | c827f94 | 2010-05-05 15:27:38 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 172 | if (userdatalen) |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 173 | memcpy(open_msg->userdata, userdata, userdatalen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 174 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 175 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 176 | list_add_tail(&open_info->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 177 | &vmbus_connection.chn_msg_list); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 178 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 179 | |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 180 | ret = vmbus_post_msg(open_msg, |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 181 | sizeof(struct vmbus_channel_open_channel), true); |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 182 | |
K. Y. Srinivasan | 45d727c | 2014-08-27 16:25:35 -0700 | [diff] [blame] | 183 | if (ret != 0) { |
| 184 | err = ret; |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 185 | goto error_clean_msglist; |
K. Y. Srinivasan | 45d727c | 2014-08-27 16:25:35 -0700 | [diff] [blame] | 186 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 187 | |
Vitaly Kuznetsov | 396e287 | 2016-06-09 17:08:56 -0700 | [diff] [blame] | 188 | wait_for_completion(&open_info->waitevent); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 189 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 190 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 191 | list_del(&open_info->msglistentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 192 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 193 | |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 194 | if (newchannel->rescind) { |
| 195 | err = -ENODEV; |
| 196 | goto error_free_gpadl; |
| 197 | } |
| 198 | |
Vitaly Kuznetsov | ffc151f | 2015-05-06 17:47:40 -0700 | [diff] [blame] | 199 | if (open_info->response.open_result.status) { |
| 200 | err = -EAGAIN; |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 201 | goto error_free_gpadl; |
Vitaly Kuznetsov | ffc151f | 2015-05-06 17:47:40 -0700 | [diff] [blame] | 202 | } |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 203 | |
Vitaly Kuznetsov | ffc151f | 2015-05-06 17:47:40 -0700 | [diff] [blame] | 204 | newchannel->state = CHANNEL_OPENED_STATE; |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 205 | kfree(open_info); |
Vitaly Kuznetsov | ffc151f | 2015-05-06 17:47:40 -0700 | [diff] [blame] | 206 | return 0; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 207 | |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 208 | error_clean_msglist: |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 209 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
| 210 | list_del(&open_info->msglistentry); |
| 211 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
| 212 | |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 213 | error_free_gpadl: |
K. Y. Srinivasan | 40384e4 | 2015-02-27 11:26:04 -0800 | [diff] [blame] | 214 | vmbus_teardown_gpadl(newchannel, newchannel->ringbuffer_gpadlhandle); |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 215 | kfree(open_info); |
| 216 | error_free_pages: |
Vitaly Kuznetsov | 9988ce6 | 2016-09-02 05:58:20 -0700 | [diff] [blame] | 217 | hv_ringbuffer_cleanup(&newchannel->outbound); |
| 218 | hv_ringbuffer_cleanup(&newchannel->inbound); |
| 219 | __free_pages(page, |
| 220 | get_order(send_ringbuffer_size + recv_ringbuffer_size)); |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 221 | error_set_chnstate: |
Dexuan Cui | ac0d12b | 2015-02-27 11:26:00 -0800 | [diff] [blame] | 222 | newchannel->state = CHANNEL_OPEN_STATE; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 223 | return err; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 224 | } |
Greg Kroah-Hartman | 36ceadf | 2010-10-21 09:58:21 -0700 | [diff] [blame] | 225 | EXPORT_SYMBOL_GPL(vmbus_open); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 226 | |
Dexuan Cui | 5c23a1a | 2016-01-27 22:29:40 -0800 | [diff] [blame] | 227 | /* Used for Hyper-V Socket: a guest client's connect() to the host */ |
| 228 | int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id, |
| 229 | const uuid_le *shv_host_servie_id) |
| 230 | { |
| 231 | struct vmbus_channel_tl_connect_request conn_msg; |
| 232 | |
| 233 | memset(&conn_msg, 0, sizeof(conn_msg)); |
| 234 | conn_msg.header.msgtype = CHANNELMSG_TL_CONNECT_REQUEST; |
| 235 | conn_msg.guest_endpoint_id = *shv_guest_servie_id; |
| 236 | conn_msg.host_service_id = *shv_host_servie_id; |
| 237 | |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 238 | return vmbus_post_msg(&conn_msg, sizeof(conn_msg), true); |
Dexuan Cui | 5c23a1a | 2016-01-27 22:29:40 -0800 | [diff] [blame] | 239 | } |
| 240 | EXPORT_SYMBOL_GPL(vmbus_send_tl_connect_request); |
| 241 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 242 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 243 | * create_gpadl_header - Creates a gpadl for the specified buffer |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 244 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 245 | static int create_gpadl_header(void *kbuffer, u32 size, |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 246 | struct vmbus_channel_msginfo **msginfo) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 247 | { |
| 248 | int i; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 249 | int pagecount; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 250 | struct vmbus_channel_gpadl_header *gpadl_header; |
| 251 | struct vmbus_channel_gpadl_body *gpadl_body; |
| 252 | struct vmbus_channel_msginfo *msgheader; |
| 253 | struct vmbus_channel_msginfo *msgbody = NULL; |
| 254 | u32 msgsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 255 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 256 | int pfnsum, pfncount, pfnleft, pfncurr, pfnsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 257 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 258 | pagecount = size >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 259 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 260 | /* do we need a gpadl body msg */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 261 | pfnsize = MAX_SIZE_CHANNEL_MESSAGE - |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 262 | sizeof(struct vmbus_channel_gpadl_header) - |
| 263 | sizeof(struct gpa_range); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 264 | pfncount = pfnsize / sizeof(u64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 265 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 266 | if (pagecount > pfncount) { |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 267 | /* we need a gpadl body */ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 268 | /* fill in the header */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 269 | msgsize = sizeof(struct vmbus_channel_msginfo) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 270 | sizeof(struct vmbus_channel_gpadl_header) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 271 | sizeof(struct gpa_range) + pfncount * sizeof(u64); |
| 272 | msgheader = kzalloc(msgsize, GFP_KERNEL); |
| 273 | if (!msgheader) |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 274 | goto nomem; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 275 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 276 | INIT_LIST_HEAD(&msgheader->submsglist); |
| 277 | msgheader->msgsize = msgsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 278 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 279 | gpadl_header = (struct vmbus_channel_gpadl_header *) |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 280 | msgheader->msg; |
| 281 | gpadl_header->rangecount = 1; |
| 282 | gpadl_header->range_buflen = sizeof(struct gpa_range) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 283 | pagecount * sizeof(u64); |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 284 | gpadl_header->range[0].byte_offset = 0; |
| 285 | gpadl_header->range[0].byte_count = size; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 286 | for (i = 0; i < pfncount; i++) |
Haiyang Zhang | b679ef7 | 2014-01-27 15:03:42 -0800 | [diff] [blame] | 287 | gpadl_header->range[0].pfn_array[i] = slow_virt_to_phys( |
| 288 | kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 289 | *msginfo = msgheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 290 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 291 | pfnsum = pfncount; |
| 292 | pfnleft = pagecount - pfncount; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 293 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 294 | /* how many pfns can we fit */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 295 | pfnsize = MAX_SIZE_CHANNEL_MESSAGE - |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 296 | sizeof(struct vmbus_channel_gpadl_body); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 297 | pfncount = pfnsize / sizeof(u64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 298 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 299 | /* fill in the body */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 300 | while (pfnleft) { |
| 301 | if (pfnleft > pfncount) |
| 302 | pfncurr = pfncount; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 303 | else |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 304 | pfncurr = pfnleft; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 305 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 306 | msgsize = sizeof(struct vmbus_channel_msginfo) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 307 | sizeof(struct vmbus_channel_gpadl_body) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 308 | pfncurr * sizeof(u64); |
| 309 | msgbody = kzalloc(msgsize, GFP_KERNEL); |
K. Y. Srinivasan | f38cf9c | 2011-06-06 15:50:06 -0700 | [diff] [blame] | 310 | |
| 311 | if (!msgbody) { |
| 312 | struct vmbus_channel_msginfo *pos = NULL; |
| 313 | struct vmbus_channel_msginfo *tmp = NULL; |
| 314 | /* |
| 315 | * Free up all the allocated messages. |
| 316 | */ |
| 317 | list_for_each_entry_safe(pos, tmp, |
| 318 | &msgheader->submsglist, |
| 319 | msglistentry) { |
| 320 | |
| 321 | list_del(&pos->msglistentry); |
| 322 | kfree(pos); |
| 323 | } |
| 324 | |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 325 | goto nomem; |
K. Y. Srinivasan | f38cf9c | 2011-06-06 15:50:06 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 328 | msgbody->msgsize = msgsize; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 329 | gpadl_body = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 330 | (struct vmbus_channel_gpadl_body *)msgbody->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 331 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 332 | /* |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 333 | * Gpadl is u32 and we are using a pointer which could |
| 334 | * be 64-bit |
K. Y. Srinivasan | f27df64 | 2011-06-06 15:49:56 -0700 | [diff] [blame] | 335 | * This is governed by the guest/host protocol and |
| 336 | * so the hypervisor gurantees that this is ok. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 337 | */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 338 | for (i = 0; i < pfncurr; i++) |
Haiyang Zhang | b679ef7 | 2014-01-27 15:03:42 -0800 | [diff] [blame] | 339 | gpadl_body->pfn[i] = slow_virt_to_phys( |
| 340 | kbuffer + PAGE_SIZE * (pfnsum + i)) >> |
| 341 | PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 342 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 343 | /* add to msg header */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 344 | list_add_tail(&msgbody->msglistentry, |
| 345 | &msgheader->submsglist); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 346 | pfnsum += pfncurr; |
| 347 | pfnleft -= pfncurr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 348 | } |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 349 | } else { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 350 | /* everything fits in a header */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 351 | msgsize = sizeof(struct vmbus_channel_msginfo) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 352 | sizeof(struct vmbus_channel_gpadl_header) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 353 | sizeof(struct gpa_range) + pagecount * sizeof(u64); |
| 354 | msgheader = kzalloc(msgsize, GFP_KERNEL); |
| 355 | if (msgheader == NULL) |
Kulikov Vasiliy | e3eb7cd | 2010-07-16 20:13:51 +0400 | [diff] [blame] | 356 | goto nomem; |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 357 | |
| 358 | INIT_LIST_HEAD(&msgheader->submsglist); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 359 | msgheader->msgsize = msgsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 360 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 361 | gpadl_header = (struct vmbus_channel_gpadl_header *) |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 362 | msgheader->msg; |
| 363 | gpadl_header->rangecount = 1; |
| 364 | gpadl_header->range_buflen = sizeof(struct gpa_range) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 365 | pagecount * sizeof(u64); |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 366 | gpadl_header->range[0].byte_offset = 0; |
| 367 | gpadl_header->range[0].byte_count = size; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 368 | for (i = 0; i < pagecount; i++) |
Haiyang Zhang | b679ef7 | 2014-01-27 15:03:42 -0800 | [diff] [blame] | 369 | gpadl_header->range[0].pfn_array[i] = slow_virt_to_phys( |
| 370 | kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 371 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 372 | *msginfo = msgheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | return 0; |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 376 | nomem: |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 377 | kfree(msgheader); |
| 378 | kfree(msgbody); |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 379 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 382 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 383 | * vmbus_establish_gpadl - Estabish a GPADL for the specified buffer |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 384 | * |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 385 | * @channel: a channel |
Haiyang Zhang | b679ef7 | 2014-01-27 15:03:42 -0800 | [diff] [blame] | 386 | * @kbuffer: from kmalloc or vmalloc |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 387 | * @size: page-size multiple |
| 388 | * @gpadl_handle: some funky thing |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 389 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 390 | int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 391 | u32 size, u32 *gpadl_handle) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 392 | { |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 393 | struct vmbus_channel_gpadl_header *gpadlmsg; |
| 394 | struct vmbus_channel_gpadl_body *gpadl_body; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 395 | struct vmbus_channel_msginfo *msginfo = NULL; |
Vitaly Kuznetsov | 7cc80c9 | 2016-06-03 17:09:24 -0700 | [diff] [blame] | 396 | struct vmbus_channel_msginfo *submsginfo, *tmp; |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 397 | struct list_head *curr; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 398 | u32 next_gpadl_handle; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 399 | unsigned long flags; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 400 | int ret = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 401 | |
K. Y. Srinivasan | 9f52a16 | 2015-01-09 23:54:33 -0800 | [diff] [blame] | 402 | next_gpadl_handle = |
| 403 | (atomic_inc_return(&vmbus_connection.next_gpadl_handle) - 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 404 | |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 405 | ret = create_gpadl_header(kbuffer, size, &msginfo); |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 406 | if (ret) |
| 407 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 408 | |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 409 | init_completion(&msginfo->waitevent); |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 410 | msginfo->waiting_channel = channel; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 411 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 412 | gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->msg; |
| 413 | gpadlmsg->header.msgtype = CHANNELMSG_GPADL_HEADER; |
| 414 | gpadlmsg->child_relid = channel->offermsg.child_relid; |
| 415 | gpadlmsg->gpadl = next_gpadl_handle; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 416 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 417 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 418 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 419 | list_add_tail(&msginfo->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 420 | &vmbus_connection.chn_msg_list); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 421 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 422 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 423 | |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 424 | ret = vmbus_post_msg(gpadlmsg, msginfo->msgsize - |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 425 | sizeof(*msginfo), true); |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 426 | if (ret != 0) |
K. Y. Srinivasan | 00d760b | 2011-06-06 15:50:12 -0700 | [diff] [blame] | 427 | goto cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 428 | |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 429 | list_for_each(curr, &msginfo->submsglist) { |
| 430 | submsginfo = (struct vmbus_channel_msginfo *)curr; |
| 431 | gpadl_body = |
| 432 | (struct vmbus_channel_gpadl_body *)submsginfo->msg; |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 433 | |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 434 | gpadl_body->header.msgtype = |
| 435 | CHANNELMSG_GPADL_BODY; |
| 436 | gpadl_body->gpadl = next_gpadl_handle; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 437 | |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 438 | ret = vmbus_post_msg(gpadl_body, |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 439 | submsginfo->msgsize - sizeof(*submsginfo), |
| 440 | true); |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 441 | if (ret != 0) |
| 442 | goto cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 443 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 444 | } |
K. Y. Srinivasan | 72c6b71 | 2014-08-27 16:25:34 -0700 | [diff] [blame] | 445 | wait_for_completion(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 446 | |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 447 | if (channel->rescind) { |
| 448 | ret = -ENODEV; |
| 449 | goto cleanup; |
| 450 | } |
| 451 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 452 | /* At this point, we received the gpadl created msg */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 453 | *gpadl_handle = gpadlmsg->gpadl; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 454 | |
K. Y. Srinivasan | 00d760b | 2011-06-06 15:50:12 -0700 | [diff] [blame] | 455 | cleanup: |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 456 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 457 | list_del(&msginfo->msglistentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 458 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Vitaly Kuznetsov | 7cc80c9 | 2016-06-03 17:09:24 -0700 | [diff] [blame] | 459 | list_for_each_entry_safe(submsginfo, tmp, &msginfo->submsglist, |
| 460 | msglistentry) { |
| 461 | kfree(submsginfo); |
| 462 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 463 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 464 | kfree(msginfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 465 | return ret; |
| 466 | } |
Greg Kroah-Hartman | 9887372 | 2010-10-21 08:47:43 -0700 | [diff] [blame] | 467 | EXPORT_SYMBOL_GPL(vmbus_establish_gpadl); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 468 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 469 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 470 | * vmbus_teardown_gpadl -Teardown the specified GPADL handle |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 471 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 472 | int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 473 | { |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 474 | struct vmbus_channel_gpadl_teardown *msg; |
Greg Kroah-Hartman | aded716 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 475 | struct vmbus_channel_msginfo *info; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 476 | unsigned long flags; |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 477 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 478 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 479 | info = kmalloc(sizeof(*info) + |
| 480 | sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL); |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 481 | if (!info) |
| 482 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 483 | |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 484 | init_completion(&info->waitevent); |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 485 | info->waiting_channel = channel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 486 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 487 | msg = (struct vmbus_channel_gpadl_teardown *)info->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 488 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 489 | msg->header.msgtype = CHANNELMSG_GPADL_TEARDOWN; |
| 490 | msg->child_relid = channel->offermsg.child_relid; |
| 491 | msg->gpadl = gpadl_handle; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 492 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 493 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 494 | list_add_tail(&info->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 495 | &vmbus_connection.chn_msg_list); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 496 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 497 | ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_gpadl_teardown), |
| 498 | true); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 499 | |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 500 | if (ret) |
| 501 | goto post_msg_err; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 502 | |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 503 | wait_for_completion(&info->waitevent); |
| 504 | |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 505 | if (channel->rescind) { |
| 506 | ret = -ENODEV; |
| 507 | goto post_msg_err; |
| 508 | } |
| 509 | |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 510 | post_msg_err: |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 511 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 512 | list_del(&info->msglistentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 513 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 514 | |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 515 | kfree(info); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 516 | return ret; |
| 517 | } |
Greg Kroah-Hartman | 18726d7 | 2010-10-21 08:39:59 -0700 | [diff] [blame] | 518 | EXPORT_SYMBOL_GPL(vmbus_teardown_gpadl); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 519 | |
K. Y. Srinivasan | d3ba720 | 2014-04-08 18:45:53 -0700 | [diff] [blame] | 520 | static void reset_channel_cb(void *arg) |
| 521 | { |
| 522 | struct vmbus_channel *channel = arg; |
| 523 | |
| 524 | channel->onchannel_callback = NULL; |
| 525 | } |
| 526 | |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 527 | static int vmbus_close_internal(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 528 | { |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 529 | struct vmbus_channel_close_channel *msg; |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 530 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 531 | |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 532 | /* |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 533 | * vmbus_on_event(), running in the tasklet, can race |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 534 | * with vmbus_close_internal() in the case of SMP guest, e.g., when |
| 535 | * the former is accessing channel->inbound.ring_buffer, the latter |
| 536 | * could be freeing the ring_buffer pages. |
| 537 | * |
| 538 | * To resolve the race, we can serialize them by disabling the |
| 539 | * tasklet when the latter is running here. |
| 540 | */ |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 541 | hv_event_tasklet_disable(channel); |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 542 | |
Dexuan Cui | 64b7faf | 2015-12-14 16:01:48 -0800 | [diff] [blame] | 543 | /* |
| 544 | * In case a device driver's probe() fails (e.g., |
| 545 | * util_probe() -> vmbus_open() returns -ENOMEM) and the device is |
| 546 | * rescinded later (e.g., we dynamically disble an Integrated Service |
| 547 | * in Hyper-V Manager), the driver's remove() invokes vmbus_close(): |
| 548 | * here we should skip most of the below cleanup work. |
| 549 | */ |
| 550 | if (channel->state != CHANNEL_OPENED_STATE) { |
| 551 | ret = -EINVAL; |
| 552 | goto out; |
| 553 | } |
| 554 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 555 | channel->state = CHANNEL_OPEN_STATE; |
| 556 | channel->sc_creation_callback = NULL; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 557 | /* Stop callback and cancel the timer asap */ |
K. Y. Srinivasan | 2115b56 | 2014-08-28 18:29:53 -0700 | [diff] [blame] | 558 | if (channel->target_cpu != get_cpu()) { |
| 559 | put_cpu(); |
K. Y. Srinivasan | d3ba720 | 2014-04-08 18:45:53 -0700 | [diff] [blame] | 560 | smp_call_function_single(channel->target_cpu, reset_channel_cb, |
| 561 | channel, true); |
K. Y. Srinivasan | 2115b56 | 2014-08-28 18:29:53 -0700 | [diff] [blame] | 562 | } else { |
K. Y. Srinivasan | d3ba720 | 2014-04-08 18:45:53 -0700 | [diff] [blame] | 563 | reset_channel_cb(channel); |
K. Y. Srinivasan | 2115b56 | 2014-08-28 18:29:53 -0700 | [diff] [blame] | 564 | put_cpu(); |
| 565 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 566 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 567 | /* Send a closing message */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 568 | |
K. Y. Srinivasan | e9a27a9 | 2011-06-06 15:49:59 -0700 | [diff] [blame] | 569 | msg = &channel->close_msg.msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 570 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 571 | msg->header.msgtype = CHANNELMSG_CLOSECHANNEL; |
| 572 | msg->child_relid = channel->offermsg.child_relid; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 573 | |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 574 | ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_close_channel), |
| 575 | true); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 576 | |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 577 | if (ret) { |
| 578 | pr_err("Close failed: close post msg return is %d\n", ret); |
| 579 | /* |
| 580 | * If we failed to post the close msg, |
| 581 | * it is perhaps better to leak memory. |
| 582 | */ |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 583 | goto out; |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 586 | /* Tear down the gpadl for the channel's ring buffer */ |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 587 | if (channel->ringbuffer_gpadlhandle) { |
| 588 | ret = vmbus_teardown_gpadl(channel, |
| 589 | channel->ringbuffer_gpadlhandle); |
| 590 | if (ret) { |
| 591 | pr_err("Close failed: teardown gpadl return %d\n", ret); |
| 592 | /* |
| 593 | * If we failed to teardown gpadl, |
| 594 | * it is perhaps better to leak memory. |
| 595 | */ |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 596 | goto out; |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 599 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 600 | /* Cleanup the ring buffers for this channel */ |
K. Y. Srinivasan | 2dba688 | 2011-05-10 07:55:22 -0700 | [diff] [blame] | 601 | hv_ringbuffer_cleanup(&channel->outbound); |
| 602 | hv_ringbuffer_cleanup(&channel->inbound); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 603 | |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame] | 604 | free_pages((unsigned long)channel->ringbuffer_pages, |
| 605 | get_order(channel->ringbuffer_pagecount * PAGE_SIZE)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 606 | |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 607 | out: |
Dexuan Cui | 638fea3 | 2016-06-09 18:47:24 -0700 | [diff] [blame] | 608 | hv_event_tasklet_enable(channel); |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 609 | |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 610 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 611 | } |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 612 | |
| 613 | /* |
| 614 | * vmbus_close - Close the specified channel |
| 615 | */ |
| 616 | void vmbus_close(struct vmbus_channel *channel) |
| 617 | { |
| 618 | struct list_head *cur, *tmp; |
| 619 | struct vmbus_channel *cur_channel; |
| 620 | |
| 621 | if (channel->primary_channel != NULL) { |
| 622 | /* |
| 623 | * We will only close sub-channels when |
| 624 | * the primary is closed. |
| 625 | */ |
| 626 | return; |
| 627 | } |
| 628 | /* |
| 629 | * Close all the sub-channels first and then close the |
| 630 | * primary channel. |
| 631 | */ |
| 632 | list_for_each_safe(cur, tmp, &channel->sc_list) { |
| 633 | cur_channel = list_entry(cur, struct vmbus_channel, sc_list); |
| 634 | if (cur_channel->state != CHANNEL_OPENED_STATE) |
| 635 | continue; |
| 636 | vmbus_close_internal(cur_channel); |
| 637 | } |
| 638 | /* |
| 639 | * Now close the primary. |
| 640 | */ |
| 641 | vmbus_close_internal(channel); |
| 642 | } |
Greg Kroah-Hartman | 70bfa30 | 2010-10-21 09:52:22 -0700 | [diff] [blame] | 643 | EXPORT_SYMBOL_GPL(vmbus_close); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 644 | |
K. Y. Srinivasan | e9395e3 | 2015-02-28 11:39:04 -0800 | [diff] [blame] | 645 | int vmbus_sendpacket_ctl(struct vmbus_channel *channel, void *buffer, |
Stephen Hemminger | 3454323 | 2017-02-05 17:20:34 -0700 | [diff] [blame] | 646 | u32 bufferlen, u64 requestid, |
| 647 | enum vmbus_packet_type type, u32 flags) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 648 | { |
Greg Kroah-Hartman | 8dc0a06 | 2009-08-27 16:02:36 -0700 | [diff] [blame] | 649 | struct vmpacket_descriptor desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 650 | u32 packetlen = sizeof(struct vmpacket_descriptor) + bufferlen; |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 651 | u32 packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 652 | struct kvec bufferlist[3]; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 653 | u64 aligned_data = 0; |
K. Y. Srinivasan | b81658c | 2015-08-01 16:08:14 -0700 | [diff] [blame] | 654 | int num_vecs = ((bufferlen != 0) ? 3 : 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 655 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 656 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 657 | /* Setup the descriptor */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 658 | desc.type = type; /* VmbusPacketTypeDataInBand; */ |
| 659 | desc.flags = flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 660 | /* in 8-bytes granularity */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 661 | desc.offset8 = sizeof(struct vmpacket_descriptor) >> 3; |
| 662 | desc.len8 = (u16)(packetlen_aligned >> 3); |
| 663 | desc.trans_id = requestid; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 664 | |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 665 | bufferlist[0].iov_base = &desc; |
| 666 | bufferlist[0].iov_len = sizeof(struct vmpacket_descriptor); |
| 667 | bufferlist[1].iov_base = buffer; |
| 668 | bufferlist[1].iov_len = bufferlen; |
| 669 | bufferlist[2].iov_base = &aligned_data; |
| 670 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 671 | |
Stephen Hemminger | 5529eaf | 2017-02-11 23:02:22 -0700 | [diff] [blame] | 672 | return hv_ringbuffer_write(channel, bufferlist, num_vecs); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 673 | } |
K. Y. Srinivasan | e9395e3 | 2015-02-28 11:39:04 -0800 | [diff] [blame] | 674 | EXPORT_SYMBOL(vmbus_sendpacket_ctl); |
| 675 | |
| 676 | /** |
| 677 | * vmbus_sendpacket() - Send the specified buffer on the given channel |
| 678 | * @channel: Pointer to vmbus_channel structure. |
| 679 | * @buffer: Pointer to the buffer you want to receive the data into. |
| 680 | * @bufferlen: Maximum size of what the the buffer will hold |
| 681 | * @requestid: Identifier of the request |
| 682 | * @type: Type of packet that is being send e.g. negotiate, time |
| 683 | * packet etc. |
| 684 | * |
| 685 | * Sends data in @buffer directly to hyper-v via the vmbus |
| 686 | * This will send the data unparsed to hyper-v. |
| 687 | * |
| 688 | * Mainly used by Hyper-V drivers. |
| 689 | */ |
| 690 | int vmbus_sendpacket(struct vmbus_channel *channel, void *buffer, |
| 691 | u32 bufferlen, u64 requestid, |
| 692 | enum vmbus_packet_type type, u32 flags) |
| 693 | { |
| 694 | return vmbus_sendpacket_ctl(channel, buffer, bufferlen, requestid, |
Stephen Hemminger | 3454323 | 2017-02-05 17:20:34 -0700 | [diff] [blame] | 695 | type, flags); |
K. Y. Srinivasan | e9395e3 | 2015-02-28 11:39:04 -0800 | [diff] [blame] | 696 | } |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 697 | EXPORT_SYMBOL(vmbus_sendpacket); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 698 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 699 | /* |
K. Y. Srinivasan | 87e93d6 | 2015-02-28 11:39:03 -0800 | [diff] [blame] | 700 | * vmbus_sendpacket_pagebuffer_ctl - Send a range of single-page buffer |
| 701 | * packets using a GPADL Direct packet type. This interface allows you |
| 702 | * to control notifying the host. This will be useful for sending |
| 703 | * batched data. Also the sender can control the send flags |
| 704 | * explicitly. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 705 | */ |
K. Y. Srinivasan | 87e93d6 | 2015-02-28 11:39:03 -0800 | [diff] [blame] | 706 | int vmbus_sendpacket_pagebuffer_ctl(struct vmbus_channel *channel, |
Stephen Hemminger | 3454323 | 2017-02-05 17:20:34 -0700 | [diff] [blame] | 707 | struct hv_page_buffer pagebuffers[], |
| 708 | u32 pagecount, void *buffer, u32 bufferlen, |
| 709 | u64 requestid, u32 flags) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 710 | { |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 711 | int i; |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 712 | struct vmbus_channel_packet_page_buffer desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 713 | u32 descsize; |
| 714 | u32 packetlen; |
| 715 | u32 packetlen_aligned; |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 716 | struct kvec bufferlist[3]; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 717 | u64 aligned_data = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 718 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 719 | if (pagecount > MAX_PAGE_BUFFER_COUNT) |
Bill Pemberton | 002b53e | 2010-05-05 15:27:39 -0400 | [diff] [blame] | 720 | return -EINVAL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 721 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 722 | /* |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 723 | * Adjust the size down since vmbus_channel_packet_page_buffer is the |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 724 | * largest size we support |
| 725 | */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 726 | descsize = sizeof(struct vmbus_channel_packet_page_buffer) - |
| 727 | ((MAX_PAGE_BUFFER_COUNT - pagecount) * |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 728 | sizeof(struct hv_page_buffer)); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 729 | packetlen = descsize + bufferlen; |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 730 | packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 731 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 732 | /* Setup the descriptor */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 733 | desc.type = VM_PKT_DATA_USING_GPA_DIRECT; |
K. Y. Srinivasan | 87e93d6 | 2015-02-28 11:39:03 -0800 | [diff] [blame] | 734 | desc.flags = flags; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 735 | desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ |
| 736 | desc.length8 = (u16)(packetlen_aligned >> 3); |
| 737 | desc.transactionid = requestid; |
| 738 | desc.rangecount = pagecount; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 739 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 740 | for (i = 0; i < pagecount; i++) { |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 741 | desc.range[i].len = pagebuffers[i].len; |
| 742 | desc.range[i].offset = pagebuffers[i].offset; |
| 743 | desc.range[i].pfn = pagebuffers[i].pfn; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 744 | } |
| 745 | |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 746 | bufferlist[0].iov_base = &desc; |
| 747 | bufferlist[0].iov_len = descsize; |
| 748 | bufferlist[1].iov_base = buffer; |
| 749 | bufferlist[1].iov_len = bufferlen; |
| 750 | bufferlist[2].iov_base = &aligned_data; |
| 751 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 752 | |
Stephen Hemminger | 5529eaf | 2017-02-11 23:02:22 -0700 | [diff] [blame] | 753 | return hv_ringbuffer_write(channel, bufferlist, 3); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 754 | } |
K. Y. Srinivasan | b3a19b3 | 2015-03-18 12:29:29 -0700 | [diff] [blame] | 755 | EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer_ctl); |
K. Y. Srinivasan | 87e93d6 | 2015-02-28 11:39:03 -0800 | [diff] [blame] | 756 | |
| 757 | /* |
| 758 | * vmbus_sendpacket_pagebuffer - Send a range of single-page buffer |
| 759 | * packets using a GPADL Direct packet type. |
| 760 | */ |
| 761 | int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, |
| 762 | struct hv_page_buffer pagebuffers[], |
| 763 | u32 pagecount, void *buffer, u32 bufferlen, |
| 764 | u64 requestid) |
| 765 | { |
| 766 | u32 flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; |
Stephen Hemminger | 3454323 | 2017-02-05 17:20:34 -0700 | [diff] [blame] | 767 | |
K. Y. Srinivasan | 87e93d6 | 2015-02-28 11:39:03 -0800 | [diff] [blame] | 768 | return vmbus_sendpacket_pagebuffer_ctl(channel, pagebuffers, pagecount, |
Stephen Hemminger | 3454323 | 2017-02-05 17:20:34 -0700 | [diff] [blame] | 769 | buffer, bufferlen, |
| 770 | requestid, flags); |
K. Y. Srinivasan | 87e93d6 | 2015-02-28 11:39:03 -0800 | [diff] [blame] | 771 | |
| 772 | } |
Greg Kroah-Hartman | 713efeb | 2010-10-21 09:29:54 -0700 | [diff] [blame] | 773 | EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 774 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 775 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 776 | * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 777 | * using a GPADL Direct packet type. |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 778 | * The buffer includes the vmbus descriptor. |
| 779 | */ |
| 780 | int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel, |
| 781 | struct vmbus_packet_mpb_array *desc, |
| 782 | u32 desc_size, |
| 783 | void *buffer, u32 bufferlen, u64 requestid) |
| 784 | { |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 785 | u32 packetlen; |
| 786 | u32 packetlen_aligned; |
| 787 | struct kvec bufferlist[3]; |
| 788 | u64 aligned_data = 0; |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 789 | |
| 790 | packetlen = desc_size + bufferlen; |
| 791 | packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
| 792 | |
| 793 | /* Setup the descriptor */ |
| 794 | desc->type = VM_PKT_DATA_USING_GPA_DIRECT; |
| 795 | desc->flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; |
| 796 | desc->dataoffset8 = desc_size >> 3; /* in 8-bytes grandularity */ |
| 797 | desc->length8 = (u16)(packetlen_aligned >> 3); |
| 798 | desc->transactionid = requestid; |
| 799 | desc->rangecount = 1; |
| 800 | |
| 801 | bufferlist[0].iov_base = desc; |
| 802 | bufferlist[0].iov_len = desc_size; |
| 803 | bufferlist[1].iov_base = buffer; |
| 804 | bufferlist[1].iov_len = bufferlen; |
| 805 | bufferlist[2].iov_base = &aligned_data; |
| 806 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
| 807 | |
Stephen Hemminger | 5529eaf | 2017-02-11 23:02:22 -0700 | [diff] [blame] | 808 | return hv_ringbuffer_write(channel, bufferlist, 3); |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 809 | } |
| 810 | EXPORT_SYMBOL_GPL(vmbus_sendpacket_mpb_desc); |
| 811 | |
| 812 | /* |
| 813 | * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet |
| 814 | * using a GPADL Direct packet type. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 815 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 816 | int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 817 | struct hv_multipage_buffer *multi_pagebuffer, |
| 818 | void *buffer, u32 bufferlen, u64 requestid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 819 | { |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 820 | struct vmbus_channel_packet_multipage_buffer desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 821 | u32 descsize; |
| 822 | u32 packetlen; |
| 823 | u32 packetlen_aligned; |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 824 | struct kvec bufferlist[3]; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 825 | u64 aligned_data = 0; |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 826 | u32 pfncount = NUM_PAGES_SPANNED(multi_pagebuffer->offset, |
| 827 | multi_pagebuffer->len); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 828 | |
Tobias Klauser | 24b8a40 | 2014-04-25 17:03:50 +0200 | [diff] [blame] | 829 | if (pfncount > MAX_MULTIPAGE_BUFFER_COUNT) |
Bill Pemberton | 002b53e | 2010-05-05 15:27:39 -0400 | [diff] [blame] | 830 | return -EINVAL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 831 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 832 | /* |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 833 | * Adjust the size down since vmbus_channel_packet_multipage_buffer is |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 834 | * the largest size we support |
| 835 | */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 836 | descsize = sizeof(struct vmbus_channel_packet_multipage_buffer) - |
| 837 | ((MAX_MULTIPAGE_BUFFER_COUNT - pfncount) * |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 838 | sizeof(u64)); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 839 | packetlen = descsize + bufferlen; |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 840 | packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 841 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 842 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 843 | /* Setup the descriptor */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 844 | desc.type = VM_PKT_DATA_USING_GPA_DIRECT; |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 845 | desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 846 | desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ |
| 847 | desc.length8 = (u16)(packetlen_aligned >> 3); |
| 848 | desc.transactionid = requestid; |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 849 | desc.rangecount = 1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 850 | |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 851 | desc.range.len = multi_pagebuffer->len; |
| 852 | desc.range.offset = multi_pagebuffer->offset; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 853 | |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 854 | memcpy(desc.range.pfn_array, multi_pagebuffer->pfn_array, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 855 | pfncount * sizeof(u64)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 856 | |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 857 | bufferlist[0].iov_base = &desc; |
| 858 | bufferlist[0].iov_len = descsize; |
| 859 | bufferlist[1].iov_base = buffer; |
| 860 | bufferlist[1].iov_len = bufferlen; |
| 861 | bufferlist[2].iov_base = &aligned_data; |
| 862 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 863 | |
Stephen Hemminger | 5529eaf | 2017-02-11 23:02:22 -0700 | [diff] [blame] | 864 | return hv_ringbuffer_write(channel, bufferlist, 3); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 865 | } |
Greg Kroah-Hartman | 4cb106f | 2010-10-21 09:23:59 -0700 | [diff] [blame] | 866 | EXPORT_SYMBOL_GPL(vmbus_sendpacket_multipagebuffer); |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 867 | |
| 868 | /** |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 869 | * vmbus_recvpacket() - Retrieve the user packet on the specified channel |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 870 | * @channel: Pointer to vmbus_channel structure. |
| 871 | * @buffer: Pointer to the buffer you want to receive the data into. |
| 872 | * @bufferlen: Maximum size of what the the buffer will hold |
| 873 | * @buffer_actual_len: The actual size of the data after it was received |
| 874 | * @requestid: Identifier of the request |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 875 | * |
| 876 | * Receives directly from the hyper-v vmbus and puts the data it received |
| 877 | * into Buffer. This will receive the data unparsed from hyper-v. |
| 878 | * |
| 879 | * Mainly used by Hyper-V drivers. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 880 | */ |
Vitaly Kuznetsov | 667d374 | 2015-12-14 19:02:00 -0800 | [diff] [blame] | 881 | static inline int |
| 882 | __vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, |
| 883 | u32 bufferlen, u32 *buffer_actual_len, u64 *requestid, |
| 884 | bool raw) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 885 | { |
K. Y. Srinivasan | 3372592 | 2016-11-06 13:14:18 -0800 | [diff] [blame] | 886 | return hv_ringbuffer_read(channel, buffer, bufferlen, |
| 887 | buffer_actual_len, requestid, raw); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 888 | |
Vitaly Kuznetsov | 667d374 | 2015-12-14 19:02:00 -0800 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, |
| 892 | u32 bufferlen, u32 *buffer_actual_len, |
| 893 | u64 *requestid) |
| 894 | { |
| 895 | return __vmbus_recvpacket(channel, buffer, bufferlen, |
| 896 | buffer_actual_len, requestid, false); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 897 | } |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 898 | EXPORT_SYMBOL(vmbus_recvpacket); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 899 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 900 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 901 | * vmbus_recvpacket_raw - Retrieve the raw packet on the specified channel |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 902 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 903 | int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 904 | u32 bufferlen, u32 *buffer_actual_len, |
| 905 | u64 *requestid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 906 | { |
Vitaly Kuznetsov | 667d374 | 2015-12-14 19:02:00 -0800 | [diff] [blame] | 907 | return __vmbus_recvpacket(channel, buffer, bufferlen, |
| 908 | buffer_actual_len, requestid, true); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 909 | } |
Greg Kroah-Hartman | adaee6b | 2010-10-21 09:09:23 -0700 | [diff] [blame] | 910 | EXPORT_SYMBOL_GPL(vmbus_recvpacket_raw); |