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> |
K. Y. Srinivasan | 3f335ea | 2011-05-12 19:34:15 -0700 | [diff] [blame] | 31 | |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 32 | #include "hyperv_vmbus.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 33 | |
K. Y. Srinivasan | e3fe0bb | 2011-02-11 10:00:12 -0800 | [diff] [blame] | 34 | #define NUM_PAGES_SPANNED(addr, len) \ |
| 35 | ((PAGE_ALIGN(addr + len) >> PAGE_SHIFT) - (addr >> PAGE_SHIFT)) |
| 36 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 37 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 38 | * vmbus_setevent- Trigger an event notification on the specified |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 39 | * channel. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 40 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 41 | static void vmbus_setevent(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 42 | { |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 43 | struct hv_monitor_page *monitorpage; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 44 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 45 | if (channel->offermsg.monitor_allocated) { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 46 | /* Each u32 represents 32 channels */ |
Olaf Hering | 2235658 | 2011-03-21 14:41:37 +0100 | [diff] [blame] | 47 | sync_set_bit(channel->offermsg.child_relid & 31, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 48 | (unsigned long *) vmbus_connection.send_int_page + |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 49 | (channel->offermsg.child_relid >> 5)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 50 | |
Greg Kroah-Hartman | 8681db4 | 2013-09-13 11:32:55 -0700 | [diff] [blame] | 51 | /* Get the child to parent monitor page */ |
| 52 | monitorpage = vmbus_connection.monitor_pages[1]; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 53 | |
Olaf Hering | 2235658 | 2011-03-21 14:41:37 +0100 | [diff] [blame] | 54 | sync_set_bit(channel->monitor_bit, |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 55 | (unsigned long *)&monitorpage->trigger_group |
| 56 | [channel->monitor_grp].pending); |
Bill Pemberton | 7c369f4 | 2009-07-29 17:00:11 -0400 | [diff] [blame] | 57 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 58 | } else { |
K. Y. Srinivasan | 21c3bef | 2012-12-01 06:46:43 -0800 | [diff] [blame] | 59 | vmbus_set_event(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 60 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 63 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 64 | * vmbus_open - Open the specified channel. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 65 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 66 | int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 67 | u32 recv_ringbuffer_size, void *userdata, u32 userdatalen, |
| 68 | void (*onchannelcallback)(void *context), void *context) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 69 | { |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 70 | struct vmbus_channel_open_channel *open_msg; |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 71 | struct vmbus_channel_msginfo *open_info = NULL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 72 | void *in, *out; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 73 | unsigned long flags; |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 74 | int ret, t, err = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 75 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 76 | spin_lock_irqsave(&newchannel->sc_lock, flags); |
| 77 | if (newchannel->state == CHANNEL_OPEN_STATE) { |
| 78 | newchannel->state = CHANNEL_OPENING_STATE; |
| 79 | } else { |
| 80 | spin_unlock_irqrestore(&newchannel->sc_lock, flags); |
| 81 | return -EINVAL; |
| 82 | } |
| 83 | spin_unlock_irqrestore(&newchannel->sc_lock, flags); |
| 84 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 85 | newchannel->onchannel_callback = onchannelcallback; |
| 86 | newchannel->channel_callback_context = context; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 87 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 88 | /* Allocate the ring buffer */ |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame] | 89 | out = (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, |
| 90 | get_order(send_ringbuffer_size + recv_ringbuffer_size)); |
| 91 | |
Bill Pemberton | 7e052d9 | 2010-05-05 15:27:30 -0400 | [diff] [blame] | 92 | if (!out) |
| 93 | return -ENOMEM; |
| 94 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 95 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 96 | in = (void *)((unsigned long)out + send_ringbuffer_size); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 97 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 98 | newchannel->ringbuffer_pages = out; |
| 99 | newchannel->ringbuffer_pagecount = (send_ringbuffer_size + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 100 | recv_ringbuffer_size) >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 101 | |
K. Y. Srinivasan | 72a95cb | 2011-05-10 07:55:21 -0700 | [diff] [blame] | 102 | ret = hv_ringbuffer_init( |
| 103 | &newchannel->outbound, out, send_ringbuffer_size); |
| 104 | |
Haiyang Zhang | fd4dc88 | 2010-05-13 15:56:30 +0000 | [diff] [blame] | 105 | if (ret != 0) { |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 106 | err = ret; |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 107 | goto error0; |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 108 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 109 | |
K. Y. Srinivasan | 72a95cb | 2011-05-10 07:55:21 -0700 | [diff] [blame] | 110 | ret = hv_ringbuffer_init( |
| 111 | &newchannel->inbound, in, recv_ringbuffer_size); |
Haiyang Zhang | fd4dc88 | 2010-05-13 15:56:30 +0000 | [diff] [blame] | 112 | if (ret != 0) { |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 113 | err = ret; |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 114 | goto error0; |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 117 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 118 | /* Establish the gpadl for the ring buffer */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 119 | newchannel->ringbuffer_gpadlhandle = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 120 | |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 121 | ret = vmbus_establish_gpadl(newchannel, |
Haiyang Zhang | 82f8bd4 | 2010-11-08 14:04:45 -0800 | [diff] [blame] | 122 | newchannel->outbound.ring_buffer, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 123 | send_ringbuffer_size + |
| 124 | recv_ringbuffer_size, |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 125 | &newchannel->ringbuffer_gpadlhandle); |
Bill Pemberton | b94ef34 | 2010-05-05 15:27:37 -0400 | [diff] [blame] | 126 | |
Haiyang Zhang | fd4dc88 | 2010-05-13 15:56:30 +0000 | [diff] [blame] | 127 | if (ret != 0) { |
Bill Pemberton | b94ef34 | 2010-05-05 15:27:37 -0400 | [diff] [blame] | 128 | err = ret; |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 129 | goto error0; |
Bill Pemberton | b94ef34 | 2010-05-05 15:27:37 -0400 | [diff] [blame] | 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 | /* Create and init the channel open message */ |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 133 | open_info = kmalloc(sizeof(*open_info) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 134 | sizeof(struct vmbus_channel_open_channel), |
| 135 | GFP_KERNEL); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 136 | if (!open_info) { |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 137 | err = -ENOMEM; |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 138 | goto error0; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 139 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 140 | |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 141 | init_completion(&open_info->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 142 | |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 143 | open_msg = (struct vmbus_channel_open_channel *)open_info->msg; |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 144 | open_msg->header.msgtype = CHANNELMSG_OPENCHANNEL; |
| 145 | open_msg->openid = newchannel->offermsg.child_relid; |
| 146 | open_msg->child_relid = newchannel->offermsg.child_relid; |
| 147 | open_msg->ringbuffer_gpadlhandle = newchannel->ringbuffer_gpadlhandle; |
| 148 | open_msg->downstream_ringbuffer_pageoffset = send_ringbuffer_size >> |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 149 | PAGE_SHIFT; |
K. Y. Srinivasan | abbf3b2 | 2012-12-01 06:46:48 -0800 | [diff] [blame] | 150 | open_msg->target_vp = newchannel->target_vp; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 151 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 152 | if (userdatalen > MAX_USER_DEFINED_BYTES) { |
Bill Pemberton | c827f94 | 2010-05-05 15:27:38 -0400 | [diff] [blame] | 153 | err = -EINVAL; |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 154 | goto error0; |
Bill Pemberton | c827f94 | 2010-05-05 15:27:38 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 157 | if (userdatalen) |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 158 | memcpy(open_msg->userdata, userdata, userdatalen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 159 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 160 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 161 | list_add_tail(&open_info->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 162 | &vmbus_connection.chn_msg_list); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 163 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 164 | |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 165 | ret = vmbus_post_msg(open_msg, |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 166 | sizeof(struct vmbus_channel_open_channel)); |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 167 | |
K. Y. Srinivasan | 45d727c | 2014-08-27 16:25:35 -0700 | [diff] [blame] | 168 | if (ret != 0) { |
| 169 | err = ret; |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 170 | goto error1; |
K. Y. Srinivasan | 45d727c | 2014-08-27 16:25:35 -0700 | [diff] [blame] | 171 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 172 | |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 173 | t = wait_for_completion_timeout(&open_info->waitevent, 5*HZ); |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 174 | if (t == 0) { |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 175 | err = -ETIMEDOUT; |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 176 | goto error1; |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 179 | |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 180 | if (open_info->response.open_result.status) |
| 181 | err = open_info->response.open_result.status; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 182 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 183 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 184 | list_del(&open_info->msglistentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 185 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 186 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 187 | if (err == 0) |
| 188 | newchannel->state = CHANNEL_OPENED_STATE; |
| 189 | |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 190 | kfree(open_info); |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 191 | return err; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 192 | |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 193 | error1: |
| 194 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
| 195 | list_del(&open_info->msglistentry); |
| 196 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
| 197 | |
| 198 | error0: |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame] | 199 | free_pages((unsigned long)out, |
| 200 | get_order(send_ringbuffer_size + recv_ringbuffer_size)); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 201 | kfree(open_info); |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 202 | return err; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 203 | } |
Greg Kroah-Hartman | 36ceadf | 2010-10-21 09:58:21 -0700 | [diff] [blame] | 204 | EXPORT_SYMBOL_GPL(vmbus_open); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 205 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 206 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 207 | * create_gpadl_header - Creates a gpadl for the specified buffer |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 208 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 209 | static int create_gpadl_header(void *kbuffer, u32 size, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 210 | struct vmbus_channel_msginfo **msginfo, |
| 211 | u32 *messagecount) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 212 | { |
| 213 | int i; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 214 | int pagecount; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 215 | struct vmbus_channel_gpadl_header *gpadl_header; |
| 216 | struct vmbus_channel_gpadl_body *gpadl_body; |
| 217 | struct vmbus_channel_msginfo *msgheader; |
| 218 | struct vmbus_channel_msginfo *msgbody = NULL; |
| 219 | u32 msgsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 220 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 221 | int pfnsum, pfncount, pfnleft, pfncurr, pfnsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 222 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 223 | pagecount = size >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 224 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 225 | /* do we need a gpadl body msg */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 226 | pfnsize = MAX_SIZE_CHANNEL_MESSAGE - |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 227 | sizeof(struct vmbus_channel_gpadl_header) - |
| 228 | sizeof(struct gpa_range); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 229 | pfncount = pfnsize / sizeof(u64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 230 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 231 | if (pagecount > pfncount) { |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 232 | /* we need a gpadl body */ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 233 | /* fill in the header */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 234 | msgsize = sizeof(struct vmbus_channel_msginfo) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 235 | sizeof(struct vmbus_channel_gpadl_header) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 236 | sizeof(struct gpa_range) + pfncount * sizeof(u64); |
| 237 | msgheader = kzalloc(msgsize, GFP_KERNEL); |
| 238 | if (!msgheader) |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 239 | goto nomem; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 240 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 241 | INIT_LIST_HEAD(&msgheader->submsglist); |
| 242 | msgheader->msgsize = msgsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 243 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 244 | gpadl_header = (struct vmbus_channel_gpadl_header *) |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 245 | msgheader->msg; |
| 246 | gpadl_header->rangecount = 1; |
| 247 | gpadl_header->range_buflen = sizeof(struct gpa_range) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 248 | pagecount * sizeof(u64); |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 249 | gpadl_header->range[0].byte_offset = 0; |
| 250 | gpadl_header->range[0].byte_count = size; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 251 | for (i = 0; i < pfncount; i++) |
Haiyang Zhang | b679ef7 | 2014-01-27 15:03:42 -0800 | [diff] [blame] | 252 | gpadl_header->range[0].pfn_array[i] = slow_virt_to_phys( |
| 253 | kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 254 | *msginfo = msgheader; |
| 255 | *messagecount = 1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 256 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 257 | pfnsum = pfncount; |
| 258 | pfnleft = pagecount - pfncount; |
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 | /* how many pfns can we fit */ |
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_body); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 263 | pfncount = pfnsize / sizeof(u64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 264 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 265 | /* fill in the body */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 266 | while (pfnleft) { |
| 267 | if (pfnleft > pfncount) |
| 268 | pfncurr = pfncount; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 269 | else |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 270 | pfncurr = pfnleft; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 271 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 272 | msgsize = sizeof(struct vmbus_channel_msginfo) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 273 | sizeof(struct vmbus_channel_gpadl_body) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 274 | pfncurr * sizeof(u64); |
| 275 | msgbody = kzalloc(msgsize, GFP_KERNEL); |
K. Y. Srinivasan | f38cf9c | 2011-06-06 15:50:06 -0700 | [diff] [blame] | 276 | |
| 277 | if (!msgbody) { |
| 278 | struct vmbus_channel_msginfo *pos = NULL; |
| 279 | struct vmbus_channel_msginfo *tmp = NULL; |
| 280 | /* |
| 281 | * Free up all the allocated messages. |
| 282 | */ |
| 283 | list_for_each_entry_safe(pos, tmp, |
| 284 | &msgheader->submsglist, |
| 285 | msglistentry) { |
| 286 | |
| 287 | list_del(&pos->msglistentry); |
| 288 | kfree(pos); |
| 289 | } |
| 290 | |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 291 | goto nomem; |
K. Y. Srinivasan | f38cf9c | 2011-06-06 15:50:06 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 294 | msgbody->msgsize = msgsize; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 295 | (*messagecount)++; |
| 296 | gpadl_body = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 297 | (struct vmbus_channel_gpadl_body *)msgbody->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 298 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 299 | /* |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 300 | * Gpadl is u32 and we are using a pointer which could |
| 301 | * be 64-bit |
K. Y. Srinivasan | f27df64 | 2011-06-06 15:49:56 -0700 | [diff] [blame] | 302 | * This is governed by the guest/host protocol and |
| 303 | * so the hypervisor gurantees that this is ok. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 304 | */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 305 | for (i = 0; i < pfncurr; i++) |
Haiyang Zhang | b679ef7 | 2014-01-27 15:03:42 -0800 | [diff] [blame] | 306 | gpadl_body->pfn[i] = slow_virt_to_phys( |
| 307 | kbuffer + PAGE_SIZE * (pfnsum + i)) >> |
| 308 | PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 309 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 310 | /* add to msg header */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 311 | list_add_tail(&msgbody->msglistentry, |
| 312 | &msgheader->submsglist); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 313 | pfnsum += pfncurr; |
| 314 | pfnleft -= pfncurr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 315 | } |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 316 | } else { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 317 | /* everything fits in a header */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 318 | msgsize = sizeof(struct vmbus_channel_msginfo) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 319 | sizeof(struct vmbus_channel_gpadl_header) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 320 | sizeof(struct gpa_range) + pagecount * sizeof(u64); |
| 321 | msgheader = kzalloc(msgsize, GFP_KERNEL); |
| 322 | if (msgheader == NULL) |
Kulikov Vasiliy | e3eb7cd | 2010-07-16 20:13:51 +0400 | [diff] [blame] | 323 | goto nomem; |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 324 | msgheader->msgsize = msgsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 325 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 326 | gpadl_header = (struct vmbus_channel_gpadl_header *) |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 327 | msgheader->msg; |
| 328 | gpadl_header->rangecount = 1; |
| 329 | gpadl_header->range_buflen = sizeof(struct gpa_range) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 330 | pagecount * sizeof(u64); |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 331 | gpadl_header->range[0].byte_offset = 0; |
| 332 | gpadl_header->range[0].byte_count = size; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 333 | for (i = 0; i < pagecount; i++) |
Haiyang Zhang | b679ef7 | 2014-01-27 15:03:42 -0800 | [diff] [blame] | 334 | gpadl_header->range[0].pfn_array[i] = slow_virt_to_phys( |
| 335 | kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 336 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 337 | *msginfo = msgheader; |
| 338 | *messagecount = 1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | return 0; |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 342 | nomem: |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 343 | kfree(msgheader); |
| 344 | kfree(msgbody); |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 345 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 348 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 349 | * vmbus_establish_gpadl - Estabish a GPADL for the specified buffer |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 350 | * |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 351 | * @channel: a channel |
Haiyang Zhang | b679ef7 | 2014-01-27 15:03:42 -0800 | [diff] [blame] | 352 | * @kbuffer: from kmalloc or vmalloc |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 353 | * @size: page-size multiple |
| 354 | * @gpadl_handle: some funky thing |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 355 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 356 | int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 357 | u32 size, u32 *gpadl_handle) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 358 | { |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 359 | struct vmbus_channel_gpadl_header *gpadlmsg; |
| 360 | struct vmbus_channel_gpadl_body *gpadl_body; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 361 | struct vmbus_channel_msginfo *msginfo = NULL; |
| 362 | struct vmbus_channel_msginfo *submsginfo; |
| 363 | u32 msgcount; |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 364 | struct list_head *curr; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 365 | u32 next_gpadl_handle; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 366 | unsigned long flags; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 367 | int ret = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 368 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 369 | next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle); |
| 370 | atomic_inc(&vmbus_connection.next_gpadl_handle); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 371 | |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 372 | ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount); |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 373 | if (ret) |
| 374 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 375 | |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 376 | init_completion(&msginfo->waitevent); |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 377 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 378 | gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->msg; |
| 379 | gpadlmsg->header.msgtype = CHANNELMSG_GPADL_HEADER; |
| 380 | gpadlmsg->child_relid = channel->offermsg.child_relid; |
| 381 | gpadlmsg->gpadl = next_gpadl_handle; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 382 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 383 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 384 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 385 | list_add_tail(&msginfo->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 386 | &vmbus_connection.chn_msg_list); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 387 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 388 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 389 | |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 390 | ret = vmbus_post_msg(gpadlmsg, msginfo->msgsize - |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 391 | sizeof(*msginfo)); |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 392 | if (ret != 0) |
K. Y. Srinivasan | 00d760b | 2011-06-06 15:50:12 -0700 | [diff] [blame] | 393 | goto cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 394 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 395 | if (msgcount > 1) { |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 396 | list_for_each(curr, &msginfo->submsglist) { |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 397 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 398 | submsginfo = (struct vmbus_channel_msginfo *)curr; |
| 399 | gpadl_body = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 400 | (struct vmbus_channel_gpadl_body *)submsginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 401 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 402 | gpadl_body->header.msgtype = |
| 403 | CHANNELMSG_GPADL_BODY; |
| 404 | gpadl_body->gpadl = next_gpadl_handle; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 405 | |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 406 | ret = vmbus_post_msg(gpadl_body, |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 407 | submsginfo->msgsize - |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 408 | sizeof(*submsginfo)); |
Haiyang Zhang | fd4dc88 | 2010-05-13 15:56:30 +0000 | [diff] [blame] | 409 | if (ret != 0) |
K. Y. Srinivasan | 00d760b | 2011-06-06 15:50:12 -0700 | [diff] [blame] | 410 | goto cleanup; |
Bill Pemberton | 9925915 | 2010-05-05 15:27:36 -0400 | [diff] [blame] | 411 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 412 | } |
| 413 | } |
K. Y. Srinivasan | 72c6b71 | 2014-08-27 16:25:34 -0700 | [diff] [blame] | 414 | wait_for_completion(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 415 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 416 | /* At this point, we received the gpadl created msg */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 417 | *gpadl_handle = gpadlmsg->gpadl; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 418 | |
K. Y. Srinivasan | 00d760b | 2011-06-06 15:50:12 -0700 | [diff] [blame] | 419 | cleanup: |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 420 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 421 | list_del(&msginfo->msglistentry); |
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 | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 424 | kfree(msginfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 425 | return ret; |
| 426 | } |
Greg Kroah-Hartman | 9887372 | 2010-10-21 08:47:43 -0700 | [diff] [blame] | 427 | EXPORT_SYMBOL_GPL(vmbus_establish_gpadl); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 428 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 429 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 430 | * vmbus_teardown_gpadl -Teardown the specified GPADL handle |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 431 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 432 | int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 433 | { |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 434 | struct vmbus_channel_gpadl_teardown *msg; |
Greg Kroah-Hartman | aded716 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 435 | struct vmbus_channel_msginfo *info; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 436 | unsigned long flags; |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 437 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 438 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 439 | info = kmalloc(sizeof(*info) + |
| 440 | sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL); |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 441 | if (!info) |
| 442 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 443 | |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 444 | init_completion(&info->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 445 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 446 | msg = (struct vmbus_channel_gpadl_teardown *)info->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 447 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 448 | msg->header.msgtype = CHANNELMSG_GPADL_TEARDOWN; |
| 449 | msg->child_relid = channel->offermsg.child_relid; |
| 450 | msg->gpadl = gpadl_handle; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 451 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 452 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 453 | list_add_tail(&info->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 454 | &vmbus_connection.chn_msg_list); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 455 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 456 | ret = vmbus_post_msg(msg, |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 457 | sizeof(struct vmbus_channel_gpadl_teardown)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 458 | |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 459 | if (ret) |
| 460 | goto post_msg_err; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 461 | |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 462 | wait_for_completion(&info->waitevent); |
| 463 | |
| 464 | post_msg_err: |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 465 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 466 | list_del(&info->msglistentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 467 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 468 | |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 469 | kfree(info); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 470 | return ret; |
| 471 | } |
Greg Kroah-Hartman | 18726d7 | 2010-10-21 08:39:59 -0700 | [diff] [blame] | 472 | EXPORT_SYMBOL_GPL(vmbus_teardown_gpadl); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 473 | |
K. Y. Srinivasan | d3ba720 | 2014-04-08 18:45:53 -0700 | [diff] [blame] | 474 | static void reset_channel_cb(void *arg) |
| 475 | { |
| 476 | struct vmbus_channel *channel = arg; |
| 477 | |
| 478 | channel->onchannel_callback = NULL; |
| 479 | } |
| 480 | |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 481 | static int vmbus_close_internal(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 482 | { |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 483 | struct vmbus_channel_close_channel *msg; |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 484 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 485 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 486 | channel->state = CHANNEL_OPEN_STATE; |
| 487 | channel->sc_creation_callback = NULL; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 488 | /* Stop callback and cancel the timer asap */ |
K. Y. Srinivasan | 2115b56 | 2014-08-28 18:29:53 -0700 | [diff] [blame] | 489 | if (channel->target_cpu != get_cpu()) { |
| 490 | put_cpu(); |
K. Y. Srinivasan | d3ba720 | 2014-04-08 18:45:53 -0700 | [diff] [blame] | 491 | smp_call_function_single(channel->target_cpu, reset_channel_cb, |
| 492 | channel, true); |
K. Y. Srinivasan | 2115b56 | 2014-08-28 18:29:53 -0700 | [diff] [blame] | 493 | } else { |
K. Y. Srinivasan | d3ba720 | 2014-04-08 18:45:53 -0700 | [diff] [blame] | 494 | reset_channel_cb(channel); |
K. Y. Srinivasan | 2115b56 | 2014-08-28 18:29:53 -0700 | [diff] [blame] | 495 | put_cpu(); |
| 496 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 497 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 498 | /* Send a closing message */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 499 | |
K. Y. Srinivasan | e9a27a9 | 2011-06-06 15:49:59 -0700 | [diff] [blame] | 500 | msg = &channel->close_msg.msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 501 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 502 | msg->header.msgtype = CHANNELMSG_CLOSECHANNEL; |
| 503 | msg->child_relid = channel->offermsg.child_relid; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 504 | |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 505 | ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_close_channel)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 506 | |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 507 | if (ret) { |
| 508 | pr_err("Close failed: close post msg return is %d\n", ret); |
| 509 | /* |
| 510 | * If we failed to post the close msg, |
| 511 | * it is perhaps better to leak memory. |
| 512 | */ |
| 513 | return ret; |
| 514 | } |
| 515 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 516 | /* Tear down the gpadl for the channel's ring buffer */ |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 517 | if (channel->ringbuffer_gpadlhandle) { |
| 518 | ret = vmbus_teardown_gpadl(channel, |
| 519 | channel->ringbuffer_gpadlhandle); |
| 520 | if (ret) { |
| 521 | pr_err("Close failed: teardown gpadl return %d\n", ret); |
| 522 | /* |
| 523 | * If we failed to teardown gpadl, |
| 524 | * it is perhaps better to leak memory. |
| 525 | */ |
| 526 | return ret; |
| 527 | } |
| 528 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 529 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 530 | /* Cleanup the ring buffers for this channel */ |
K. Y. Srinivasan | 2dba688 | 2011-05-10 07:55:22 -0700 | [diff] [blame] | 531 | hv_ringbuffer_cleanup(&channel->outbound); |
| 532 | hv_ringbuffer_cleanup(&channel->inbound); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 533 | |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame] | 534 | free_pages((unsigned long)channel->ringbuffer_pages, |
| 535 | get_order(channel->ringbuffer_pagecount * PAGE_SIZE)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 536 | |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 537 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 538 | } |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 539 | |
| 540 | /* |
| 541 | * vmbus_close - Close the specified channel |
| 542 | */ |
| 543 | void vmbus_close(struct vmbus_channel *channel) |
| 544 | { |
| 545 | struct list_head *cur, *tmp; |
| 546 | struct vmbus_channel *cur_channel; |
| 547 | |
| 548 | if (channel->primary_channel != NULL) { |
| 549 | /* |
| 550 | * We will only close sub-channels when |
| 551 | * the primary is closed. |
| 552 | */ |
| 553 | return; |
| 554 | } |
| 555 | /* |
| 556 | * Close all the sub-channels first and then close the |
| 557 | * primary channel. |
| 558 | */ |
| 559 | list_for_each_safe(cur, tmp, &channel->sc_list) { |
| 560 | cur_channel = list_entry(cur, struct vmbus_channel, sc_list); |
| 561 | if (cur_channel->state != CHANNEL_OPENED_STATE) |
| 562 | continue; |
| 563 | vmbus_close_internal(cur_channel); |
| 564 | } |
| 565 | /* |
| 566 | * Now close the primary. |
| 567 | */ |
| 568 | vmbus_close_internal(channel); |
| 569 | } |
Greg Kroah-Hartman | 70bfa30 | 2010-10-21 09:52:22 -0700 | [diff] [blame] | 570 | EXPORT_SYMBOL_GPL(vmbus_close); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 571 | |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 572 | /** |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 573 | * vmbus_sendpacket() - Send the specified buffer on the given channel |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 574 | * @channel: Pointer to vmbus_channel structure. |
| 575 | * @buffer: Pointer to the buffer you want to receive the data into. |
| 576 | * @bufferlen: Maximum size of what the the buffer will hold |
| 577 | * @requestid: Identifier of the request |
| 578 | * @type: Type of packet that is being send e.g. negotiate, time |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 579 | * packet etc. |
| 580 | * |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 581 | * Sends data in @buffer directly to hyper-v via the vmbus |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 582 | * This will send the data unparsed to hyper-v. |
| 583 | * |
| 584 | * Mainly used by Hyper-V drivers. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 585 | */ |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 586 | int vmbus_sendpacket(struct vmbus_channel *channel, void *buffer, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 587 | u32 bufferlen, u64 requestid, |
| 588 | enum vmbus_packet_type type, u32 flags) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 589 | { |
Greg Kroah-Hartman | 8dc0a06 | 2009-08-27 16:02:36 -0700 | [diff] [blame] | 590 | struct vmpacket_descriptor desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 591 | u32 packetlen = sizeof(struct vmpacket_descriptor) + bufferlen; |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 592 | u32 packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 593 | struct kvec bufferlist[3]; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 594 | u64 aligned_data = 0; |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 595 | int ret; |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 596 | bool signal = false; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 597 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 598 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 599 | /* Setup the descriptor */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 600 | desc.type = type; /* VmbusPacketTypeDataInBand; */ |
| 601 | desc.flags = flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 602 | /* in 8-bytes granularity */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 603 | desc.offset8 = sizeof(struct vmpacket_descriptor) >> 3; |
| 604 | desc.len8 = (u16)(packetlen_aligned >> 3); |
| 605 | desc.trans_id = requestid; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 606 | |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 607 | bufferlist[0].iov_base = &desc; |
| 608 | bufferlist[0].iov_len = sizeof(struct vmpacket_descriptor); |
| 609 | bufferlist[1].iov_base = buffer; |
| 610 | bufferlist[1].iov_len = bufferlen; |
| 611 | bufferlist[2].iov_base = &aligned_data; |
| 612 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 613 | |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 614 | ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 615 | |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 616 | if (ret == 0 && signal) |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 617 | vmbus_setevent(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 618 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 619 | return ret; |
| 620 | } |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 621 | EXPORT_SYMBOL(vmbus_sendpacket); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 622 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 623 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 624 | * vmbus_sendpacket_pagebuffer - Send a range of single-page buffer |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 625 | * packets using a GPADL Direct packet type. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 626 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 627 | int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 628 | struct hv_page_buffer pagebuffers[], |
| 629 | u32 pagecount, void *buffer, u32 bufferlen, |
| 630 | u64 requestid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 631 | { |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 632 | int ret; |
| 633 | int i; |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 634 | struct vmbus_channel_packet_page_buffer desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 635 | u32 descsize; |
| 636 | u32 packetlen; |
| 637 | u32 packetlen_aligned; |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 638 | struct kvec bufferlist[3]; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 639 | u64 aligned_data = 0; |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 640 | bool signal = false; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 641 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 642 | if (pagecount > MAX_PAGE_BUFFER_COUNT) |
Bill Pemberton | 002b53e | 2010-05-05 15:27:39 -0400 | [diff] [blame] | 643 | return -EINVAL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 644 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 645 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 646 | /* |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 647 | * 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] | 648 | * largest size we support |
| 649 | */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 650 | descsize = sizeof(struct vmbus_channel_packet_page_buffer) - |
| 651 | ((MAX_PAGE_BUFFER_COUNT - pagecount) * |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 652 | sizeof(struct hv_page_buffer)); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 653 | packetlen = descsize + bufferlen; |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 654 | packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 655 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 656 | /* Setup the descriptor */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 657 | desc.type = VM_PKT_DATA_USING_GPA_DIRECT; |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 658 | desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 659 | desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ |
| 660 | desc.length8 = (u16)(packetlen_aligned >> 3); |
| 661 | desc.transactionid = requestid; |
| 662 | desc.rangecount = pagecount; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 663 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 664 | for (i = 0; i < pagecount; i++) { |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 665 | desc.range[i].len = pagebuffers[i].len; |
| 666 | desc.range[i].offset = pagebuffers[i].offset; |
| 667 | desc.range[i].pfn = pagebuffers[i].pfn; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 668 | } |
| 669 | |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 670 | bufferlist[0].iov_base = &desc; |
| 671 | bufferlist[0].iov_len = descsize; |
| 672 | bufferlist[1].iov_base = buffer; |
| 673 | bufferlist[1].iov_len = bufferlen; |
| 674 | bufferlist[2].iov_base = &aligned_data; |
| 675 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 676 | |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 677 | ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 678 | |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 679 | if (ret == 0 && signal) |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 680 | vmbus_setevent(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 681 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 682 | return ret; |
| 683 | } |
Greg Kroah-Hartman | 713efeb | 2010-10-21 09:29:54 -0700 | [diff] [blame] | 684 | EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 685 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 686 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 687 | * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 688 | * using a GPADL Direct packet type. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 689 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 690 | int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 691 | struct hv_multipage_buffer *multi_pagebuffer, |
| 692 | void *buffer, u32 bufferlen, u64 requestid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 693 | { |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 694 | int ret; |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 695 | struct vmbus_channel_packet_multipage_buffer desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 696 | u32 descsize; |
| 697 | u32 packetlen; |
| 698 | u32 packetlen_aligned; |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 699 | struct kvec bufferlist[3]; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 700 | u64 aligned_data = 0; |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 701 | bool signal = false; |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 702 | u32 pfncount = NUM_PAGES_SPANNED(multi_pagebuffer->offset, |
| 703 | multi_pagebuffer->len); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 704 | |
Tobias Klauser | 24b8a40 | 2014-04-25 17:03:50 +0200 | [diff] [blame] | 705 | if (pfncount > MAX_MULTIPAGE_BUFFER_COUNT) |
Bill Pemberton | 002b53e | 2010-05-05 15:27:39 -0400 | [diff] [blame] | 706 | return -EINVAL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 707 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 708 | /* |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 709 | * Adjust the size down since vmbus_channel_packet_multipage_buffer is |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 710 | * the largest size we support |
| 711 | */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 712 | descsize = sizeof(struct vmbus_channel_packet_multipage_buffer) - |
| 713 | ((MAX_MULTIPAGE_BUFFER_COUNT - pfncount) * |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 714 | sizeof(u64)); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 715 | packetlen = descsize + bufferlen; |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 716 | packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 717 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 718 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 719 | /* Setup the descriptor */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 720 | desc.type = VM_PKT_DATA_USING_GPA_DIRECT; |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 721 | desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 722 | desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ |
| 723 | desc.length8 = (u16)(packetlen_aligned >> 3); |
| 724 | desc.transactionid = requestid; |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 725 | desc.rangecount = 1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 726 | |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 727 | desc.range.len = multi_pagebuffer->len; |
| 728 | desc.range.offset = multi_pagebuffer->offset; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 729 | |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 730 | memcpy(desc.range.pfn_array, multi_pagebuffer->pfn_array, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 731 | pfncount * sizeof(u64)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 732 | |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 733 | bufferlist[0].iov_base = &desc; |
| 734 | bufferlist[0].iov_len = descsize; |
| 735 | bufferlist[1].iov_base = buffer; |
| 736 | bufferlist[1].iov_len = bufferlen; |
| 737 | bufferlist[2].iov_base = &aligned_data; |
| 738 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 739 | |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 740 | ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 741 | |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 742 | if (ret == 0 && signal) |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 743 | vmbus_setevent(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 744 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 745 | return ret; |
| 746 | } |
Greg Kroah-Hartman | 4cb106f | 2010-10-21 09:23:59 -0700 | [diff] [blame] | 747 | EXPORT_SYMBOL_GPL(vmbus_sendpacket_multipagebuffer); |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 748 | |
| 749 | /** |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 750 | * vmbus_recvpacket() - Retrieve the user packet on the specified channel |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 751 | * @channel: Pointer to vmbus_channel structure. |
| 752 | * @buffer: Pointer to the buffer you want to receive the data into. |
| 753 | * @bufferlen: Maximum size of what the the buffer will hold |
| 754 | * @buffer_actual_len: The actual size of the data after it was received |
| 755 | * @requestid: Identifier of the request |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 756 | * |
| 757 | * Receives directly from the hyper-v vmbus and puts the data it received |
| 758 | * into Buffer. This will receive the data unparsed from hyper-v. |
| 759 | * |
| 760 | * Mainly used by Hyper-V drivers. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 761 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 762 | int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 763 | u32 bufferlen, u32 *buffer_actual_len, u64 *requestid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 764 | { |
Greg Kroah-Hartman | 8dc0a06 | 2009-08-27 16:02:36 -0700 | [diff] [blame] | 765 | struct vmpacket_descriptor desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 766 | u32 packetlen; |
| 767 | u32 userlen; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 768 | int ret; |
K. Y. Srinivasan | c2b8e52 | 2012-12-01 06:46:57 -0800 | [diff] [blame] | 769 | bool signal = false; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 770 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 771 | *buffer_actual_len = 0; |
| 772 | *requestid = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 773 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 774 | |
K. Y. Srinivasan | a89186c | 2011-05-10 07:55:24 -0700 | [diff] [blame] | 775 | ret = hv_ringbuffer_peek(&channel->inbound, &desc, |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 776 | sizeof(struct vmpacket_descriptor)); |
K. Y. Srinivasan | dad76bf | 2011-08-27 11:31:33 -0700 | [diff] [blame] | 777 | if (ret != 0) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 778 | return 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 779 | |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 780 | packetlen = desc.len8 << 3; |
| 781 | userlen = packetlen - (desc.offset8 << 3); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 782 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 783 | *buffer_actual_len = userlen; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 784 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 785 | if (userlen > bufferlen) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 786 | |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 787 | pr_err("Buffer too small - got %d needs %d\n", |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 788 | bufferlen, userlen); |
K. Y. Srinivasan | 926ae526 | 2011-06-06 15:50:11 -0700 | [diff] [blame] | 789 | return -ETOOSMALL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 792 | *requestid = desc.trans_id; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 793 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 794 | /* Copy over the packet to the user buffer */ |
K. Y. Srinivasan | 38397c8 | 2011-05-10 07:55:25 -0700 | [diff] [blame] | 795 | ret = hv_ringbuffer_read(&channel->inbound, buffer, userlen, |
K. Y. Srinivasan | c2b8e52 | 2012-12-01 06:46:57 -0800 | [diff] [blame] | 796 | (desc.offset8 << 3), &signal); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 797 | |
K. Y. Srinivasan | c2b8e52 | 2012-12-01 06:46:57 -0800 | [diff] [blame] | 798 | if (signal) |
| 799 | vmbus_setevent(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 800 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 801 | return 0; |
| 802 | } |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 803 | EXPORT_SYMBOL(vmbus_recvpacket); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 804 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 805 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 806 | * vmbus_recvpacket_raw - Retrieve the raw packet on the specified channel |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 807 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 808 | int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 809 | u32 bufferlen, u32 *buffer_actual_len, |
| 810 | u64 *requestid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 811 | { |
Greg Kroah-Hartman | 8dc0a06 | 2009-08-27 16:02:36 -0700 | [diff] [blame] | 812 | struct vmpacket_descriptor desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 813 | u32 packetlen; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 814 | int ret; |
K. Y. Srinivasan | c2b8e52 | 2012-12-01 06:46:57 -0800 | [diff] [blame] | 815 | bool signal = false; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 816 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 817 | *buffer_actual_len = 0; |
| 818 | *requestid = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 819 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 820 | |
K. Y. Srinivasan | a89186c | 2011-05-10 07:55:24 -0700 | [diff] [blame] | 821 | ret = hv_ringbuffer_peek(&channel->inbound, &desc, |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 822 | sizeof(struct vmpacket_descriptor)); |
K. Y. Srinivasan | dad76bf | 2011-08-27 11:31:33 -0700 | [diff] [blame] | 823 | if (ret != 0) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 824 | return 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 825 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 826 | |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 827 | packetlen = desc.len8 << 3; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 828 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 829 | *buffer_actual_len = packetlen; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 830 | |
Jason Wang | 7a446d6 | 2014-06-30 14:14:48 +0800 | [diff] [blame] | 831 | if (packetlen > bufferlen) |
K. Y. Srinivasan | 3d5cad9 | 2011-08-25 09:48:59 -0700 | [diff] [blame] | 832 | return -ENOBUFS; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 833 | |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 834 | *requestid = desc.trans_id; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 835 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 836 | /* Copy over the entire packet to the user buffer */ |
K. Y. Srinivasan | c2b8e52 | 2012-12-01 06:46:57 -0800 | [diff] [blame] | 837 | ret = hv_ringbuffer_read(&channel->inbound, buffer, packetlen, 0, |
| 838 | &signal); |
| 839 | |
| 840 | if (signal) |
| 841 | vmbus_setevent(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 842 | |
Dan Carpenter | 33b0693 | 2013-09-17 00:58:36 +0300 | [diff] [blame] | 843 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 844 | } |
Greg Kroah-Hartman | adaee6b | 2010-10-21 09:09:23 -0700 | [diff] [blame] | 845 | EXPORT_SYMBOL_GPL(vmbus_recvpacket_raw); |