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 | a0086dc | 2009-08-17 17:22:08 -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> |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 28 | #include <linux/list.h> |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 30 | #include <linux/completion.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 31 | #include <linux/hyperv.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 | |
Greg Kroah-Hartman | 1d7e907 | 2009-08-28 16:26:11 -0700 | [diff] [blame] | 35 | struct vmbus_channel_message_table_entry { |
K. Y. Srinivasan | cf9dcba | 2011-05-10 07:55:37 -0700 | [diff] [blame] | 36 | enum vmbus_channel_message_type message_type; |
K. Y. Srinivasan | fa90f1d | 2011-05-10 07:55:36 -0700 | [diff] [blame] | 37 | void (*message_handler)(struct vmbus_channel_message_header *msg); |
Greg Kroah-Hartman | 1d7e907 | 2009-08-28 16:26:11 -0700 | [diff] [blame] | 38 | }; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 39 | |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
Greg Kroah-Hartman | da0e963 | 2011-10-11 08:42:28 -0600 | [diff] [blame] | 42 | * vmbus_prep_negotiate_resp() - Create default response for Hyper-V Negotiate message |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 43 | * @icmsghdrp: Pointer to msg header structure |
| 44 | * @icmsg_negotiate: Pointer to negotiate message structure |
| 45 | * @buf: Raw buffer channel data |
| 46 | * |
| 47 | * @icmsghdrp is of type &struct icmsg_hdr. |
| 48 | * @negop is of type &struct icmsg_negotiate. |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 49 | * Set up and fill in default negotiate response message. |
| 50 | * |
| 51 | * The max_fw_version specifies the maximum framework version that |
| 52 | * we can support and max _srv_version specifies the maximum service |
| 53 | * version we can support. A special value MAX_SRV_VER can be |
| 54 | * specified to indicate that we can handle the maximum version |
| 55 | * exposed by the host. |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 56 | * |
| 57 | * Mainly used by Hyper-V drivers. |
| 58 | */ |
Greg Kroah-Hartman | da0e963 | 2011-10-11 08:42:28 -0600 | [diff] [blame] | 59 | void vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 60 | struct icmsg_negotiate *negop, u8 *buf, |
| 61 | int max_fw_version, int max_srv_version) |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 62 | { |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 63 | int icframe_vercnt; |
| 64 | int icmsg_vercnt; |
| 65 | int i; |
| 66 | |
K. Y. Srinivasan | a360530 | 2012-05-12 13:44:57 -0700 | [diff] [blame] | 67 | icmsghdrp->icmsgsize = 0x10; |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 68 | |
K. Y. Srinivasan | a360530 | 2012-05-12 13:44:57 -0700 | [diff] [blame] | 69 | negop = (struct icmsg_negotiate *)&buf[ |
| 70 | sizeof(struct vmbuspipe_hdr) + |
| 71 | sizeof(struct icmsg_hdr)]; |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 72 | |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 73 | icframe_vercnt = negop->icframe_vercnt; |
| 74 | icmsg_vercnt = negop->icmsg_vercnt; |
| 75 | |
| 76 | /* |
| 77 | * Select the framework version number we will |
| 78 | * support. |
| 79 | */ |
| 80 | |
| 81 | for (i = 0; i < negop->icframe_vercnt; i++) { |
| 82 | if (negop->icversion_data[i].major <= max_fw_version) |
| 83 | icframe_vercnt = negop->icversion_data[i].major; |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 84 | } |
K. Y. Srinivasan | a360530 | 2012-05-12 13:44:57 -0700 | [diff] [blame] | 85 | |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 86 | for (i = negop->icframe_vercnt; |
| 87 | (i < negop->icframe_vercnt + negop->icmsg_vercnt); i++) { |
| 88 | if (negop->icversion_data[i].major <= max_srv_version) |
| 89 | icmsg_vercnt = negop->icversion_data[i].major; |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | * Respond with the maximum framework and service |
| 94 | * version numbers we can support. |
| 95 | */ |
K. Y. Srinivasan | a360530 | 2012-05-12 13:44:57 -0700 | [diff] [blame] | 96 | negop->icframe_vercnt = 1; |
| 97 | negop->icmsg_vercnt = 1; |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 98 | negop->icversion_data[0].major = icframe_vercnt; |
| 99 | negop->icversion_data[0].minor = 0; |
| 100 | negop->icversion_data[1].major = icmsg_vercnt; |
| 101 | negop->icversion_data[1].minor = 0; |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 102 | } |
K. Y. Srinivasan | a360530 | 2012-05-12 13:44:57 -0700 | [diff] [blame] | 103 | |
Greg Kroah-Hartman | da0e963 | 2011-10-11 08:42:28 -0600 | [diff] [blame] | 104 | EXPORT_SYMBOL_GPL(vmbus_prep_negotiate_resp); |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 105 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 106 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 107 | * alloc_channel - Allocate and initialize a vmbus channel object |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 108 | */ |
Greg Kroah-Hartman | 50fe56d | 2010-10-20 15:51:57 -0700 | [diff] [blame] | 109 | static struct vmbus_channel *alloc_channel(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 110 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 111 | struct vmbus_channel *channel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 112 | |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 113 | channel = kzalloc(sizeof(*channel), GFP_ATOMIC); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 114 | if (!channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 115 | return NULL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 116 | |
Greg Kroah-Hartman | 54411c4 | 2009-07-15 14:48:32 -0700 | [diff] [blame] | 117 | spin_lock_init(&channel->inbound_lock); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 118 | spin_lock_init(&channel->sc_lock); |
| 119 | |
| 120 | INIT_LIST_HEAD(&channel->sc_list); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 121 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 122 | channel->controlwq = create_workqueue("hv_vmbus_ctl"); |
| 123 | if (!channel->controlwq) { |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 124 | kfree(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 125 | return NULL; |
| 126 | } |
| 127 | |
| 128 | return channel; |
| 129 | } |
| 130 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 131 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 132 | * release_hannel - Release the vmbus channel object itself |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 133 | */ |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 134 | static void release_channel(struct work_struct *work) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 135 | { |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 136 | struct vmbus_channel *channel = container_of(work, |
| 137 | struct vmbus_channel, |
| 138 | work); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 139 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 140 | destroy_workqueue(channel->controlwq); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 141 | |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 142 | kfree(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 145 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 146 | * free_channel - Release the resources used by the vmbus channel object |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 147 | */ |
Greg Kroah-Hartman | 9f3e28e | 2011-10-11 09:40:01 -0600 | [diff] [blame] | 148 | static void free_channel(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 149 | { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 150 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 151 | /* |
| 152 | * We have to release the channel's workqueue/thread in the vmbus's |
| 153 | * workqueue/thread context |
| 154 | * ie we can't destroy ourselves. |
| 155 | */ |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 156 | INIT_WORK(&channel->work, release_channel); |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 157 | queue_work(vmbus_connection.work_queue, &channel->work); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 160 | |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 161 | |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 162 | /* |
| 163 | * vmbus_process_rescind_offer - |
| 164 | * Rescind the offer by initiating a device removal |
| 165 | */ |
| 166 | static void vmbus_process_rescind_offer(struct work_struct *work) |
| 167 | { |
| 168 | struct vmbus_channel *channel = container_of(work, |
| 169 | struct vmbus_channel, |
| 170 | work); |
K. Y. Srinivasan | c870597 | 2013-03-15 12:25:44 -0700 | [diff] [blame] | 171 | unsigned long flags; |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 172 | struct vmbus_channel *primary_channel; |
K. Y. Srinivasan | c870597 | 2013-03-15 12:25:44 -0700 | [diff] [blame] | 173 | struct vmbus_channel_relid_released msg; |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 174 | |
K. Y. Srinivasan | 696453b | 2011-09-08 07:24:14 -0700 | [diff] [blame] | 175 | vmbus_device_unregister(channel->device_obj); |
K. Y. Srinivasan | c870597 | 2013-03-15 12:25:44 -0700 | [diff] [blame] | 176 | memset(&msg, 0, sizeof(struct vmbus_channel_relid_released)); |
| 177 | msg.child_relid = channel->offermsg.child_relid; |
| 178 | msg.header.msgtype = CHANNELMSG_RELID_RELEASED; |
| 179 | vmbus_post_msg(&msg, sizeof(struct vmbus_channel_relid_released)); |
| 180 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 181 | if (channel->primary_channel == NULL) { |
| 182 | spin_lock_irqsave(&vmbus_connection.channel_lock, flags); |
| 183 | list_del(&channel->listentry); |
| 184 | spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); |
| 185 | } else { |
| 186 | primary_channel = channel->primary_channel; |
| 187 | spin_lock_irqsave(&primary_channel->sc_lock, flags); |
| 188 | list_del(&channel->listentry); |
| 189 | spin_unlock_irqrestore(&primary_channel->sc_lock, flags); |
| 190 | } |
K. Y. Srinivasan | c870597 | 2013-03-15 12:25:44 -0700 | [diff] [blame] | 191 | free_channel(channel); |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 192 | } |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 193 | |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 194 | void vmbus_free_channels(void) |
| 195 | { |
| 196 | struct vmbus_channel *channel; |
| 197 | |
| 198 | list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { |
| 199 | vmbus_device_unregister(channel->device_obj); |
| 200 | kfree(channel->device_obj); |
| 201 | free_channel(channel); |
| 202 | } |
| 203 | } |
| 204 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 205 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 206 | * vmbus_process_offer - Process the offer by creating a channel/device |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 207 | * associated with this offer |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 208 | */ |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 209 | static void vmbus_process_offer(struct work_struct *work) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 210 | { |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 211 | struct vmbus_channel *newchannel = container_of(work, |
| 212 | struct vmbus_channel, |
| 213 | work); |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 214 | struct vmbus_channel *channel; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 215 | bool fnew = true; |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 216 | int ret; |
Greg Kroah-Hartman | 0f5e44c | 2009-07-15 14:57:16 -0700 | [diff] [blame] | 217 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 218 | |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 219 | /* The next possible work is rescind handling */ |
| 220 | INIT_WORK(&newchannel->work, vmbus_process_rescind_offer); |
| 221 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 222 | /* Make sure this is a new offer */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 223 | spin_lock_irqsave(&vmbus_connection.channel_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 224 | |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 225 | list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 226 | if (!uuid_le_cmp(channel->offermsg.offer.if_type, |
| 227 | newchannel->offermsg.offer.if_type) && |
| 228 | !uuid_le_cmp(channel->offermsg.offer.if_instance, |
| 229 | newchannel->offermsg.offer.if_instance)) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 230 | fnew = false; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 231 | break; |
| 232 | } |
| 233 | } |
| 234 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 235 | if (fnew) |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 236 | list_add_tail(&newchannel->listentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 237 | &vmbus_connection.chn_list); |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 238 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 239 | spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 240 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 241 | if (!fnew) { |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 242 | /* |
| 243 | * Check to see if this is a sub-channel. |
| 244 | */ |
| 245 | if (newchannel->offermsg.offer.sub_channel_index != 0) { |
| 246 | /* |
| 247 | * Process the sub-channel. |
| 248 | */ |
| 249 | newchannel->primary_channel = channel; |
| 250 | spin_lock_irqsave(&channel->sc_lock, flags); |
| 251 | list_add_tail(&newchannel->sc_list, &channel->sc_list); |
| 252 | spin_unlock_irqrestore(&channel->sc_lock, flags); |
| 253 | newchannel->state = CHANNEL_OPEN_STATE; |
| 254 | if (channel->sc_creation_callback != NULL) |
| 255 | channel->sc_creation_callback(newchannel); |
| 256 | |
| 257 | return; |
| 258 | } |
| 259 | |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 260 | free_channel(newchannel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 261 | return; |
| 262 | } |
| 263 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 264 | /* |
| 265 | * Start the process of binding this offer to the driver |
| 266 | * We need to set the DeviceObject field before calling |
Haiyang Zhang | 646f1ea | 2011-01-26 12:12:10 -0800 | [diff] [blame] | 267 | * vmbus_child_dev_add() |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 268 | */ |
K. Y. Srinivasan | f2c7301 | 2011-09-08 07:24:12 -0700 | [diff] [blame] | 269 | newchannel->device_obj = vmbus_device_create( |
Haiyang Zhang | 767dff6 | 2011-01-26 12:12:12 -0800 | [diff] [blame] | 270 | &newchannel->offermsg.offer.if_type, |
| 271 | &newchannel->offermsg.offer.if_instance, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 272 | newchannel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 273 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 274 | /* |
| 275 | * Add the new device to the bus. This will kick off device-driver |
| 276 | * binding which eventually invokes the device driver's AddDevice() |
| 277 | * method. |
| 278 | */ |
K. Y. Srinivasan | 22794281 | 2011-09-08 07:24:13 -0700 | [diff] [blame] | 279 | ret = vmbus_device_register(newchannel->device_obj); |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 280 | if (ret != 0) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 281 | pr_err("unable to add child device object (relid %d)\n", |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 282 | newchannel->offermsg.child_relid); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 283 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 284 | spin_lock_irqsave(&vmbus_connection.channel_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 285 | list_del(&newchannel->listentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 286 | spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); |
K. Y. Srinivasan | 8b8ee67 | 2011-12-12 09:29:16 -0800 | [diff] [blame] | 287 | kfree(newchannel->device_obj); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 288 | |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 289 | free_channel(newchannel); |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 290 | } else { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 291 | /* |
| 292 | * This state is used to indicate a successful open |
| 293 | * so that when we do close the channel normally, we |
| 294 | * can cleanup properly |
| 295 | */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 296 | newchannel->state = CHANNEL_OPEN_STATE; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 297 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 298 | } |
| 299 | |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 300 | enum { |
| 301 | IDE = 0, |
| 302 | SCSI, |
| 303 | NIC, |
| 304 | MAX_PERF_CHN, |
| 305 | }; |
| 306 | |
| 307 | /* |
K. Y. Srinivasan | 7fb9656 | 2013-01-23 17:42:40 -0800 | [diff] [blame] | 308 | * This is an array of device_ids (device types) that are performance critical. |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 309 | * We attempt to distribute the interrupt load for these devices across |
| 310 | * all available CPUs. |
| 311 | */ |
K. Y. Srinivasan | 7fb9656 | 2013-01-23 17:42:40 -0800 | [diff] [blame] | 312 | static const struct hv_vmbus_device_id hp_devs[] = { |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 313 | /* IDE */ |
K. Y. Srinivasan | 7fb9656 | 2013-01-23 17:42:40 -0800 | [diff] [blame] | 314 | { HV_IDE_GUID, }, |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 315 | /* Storage - SCSI */ |
K. Y. Srinivasan | 7fb9656 | 2013-01-23 17:42:40 -0800 | [diff] [blame] | 316 | { HV_SCSI_GUID, }, |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 317 | /* Network */ |
K. Y. Srinivasan | 7fb9656 | 2013-01-23 17:42:40 -0800 | [diff] [blame] | 318 | { HV_NIC_GUID, }, |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | |
| 322 | /* |
| 323 | * We use this state to statically distribute the channel interrupt load. |
| 324 | */ |
| 325 | static u32 next_vp; |
| 326 | |
| 327 | /* |
| 328 | * Starting with Win8, we can statically distribute the incoming |
| 329 | * channel interrupt load by binding a channel to VCPU. We |
| 330 | * implement here a simple round robin scheme for distributing |
| 331 | * the interrupt load. |
| 332 | * We will bind channels that are not performance critical to cpu 0 and |
| 333 | * performance critical channels (IDE, SCSI and Network) will be uniformly |
| 334 | * distributed across all available CPUs. |
| 335 | */ |
| 336 | static u32 get_vp_index(uuid_le *type_guid) |
| 337 | { |
| 338 | u32 cur_cpu; |
| 339 | int i; |
| 340 | bool perf_chn = false; |
| 341 | u32 max_cpus = num_online_cpus(); |
| 342 | |
| 343 | for (i = IDE; i < MAX_PERF_CHN; i++) { |
K. Y. Srinivasan | 7fb9656 | 2013-01-23 17:42:40 -0800 | [diff] [blame] | 344 | if (!memcmp(type_guid->b, hp_devs[i].guid, |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 345 | sizeof(uuid_le))) { |
| 346 | perf_chn = true; |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | if ((vmbus_proto_version == VERSION_WS2008) || |
| 351 | (vmbus_proto_version == VERSION_WIN7) || (!perf_chn)) { |
| 352 | /* |
| 353 | * Prior to win8, all channel interrupts are |
| 354 | * delivered on cpu 0. |
| 355 | * Also if the channel is not a performance critical |
| 356 | * channel, bind it to cpu 0. |
| 357 | */ |
| 358 | return 0; |
| 359 | } |
| 360 | cur_cpu = (++next_vp % max_cpus); |
K. Y. Srinivasan | d2242a3 | 2013-05-17 09:30:35 -0700 | [diff] [blame] | 361 | return hv_context.vp_index[cur_cpu]; |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 364 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 365 | * vmbus_onoffer - Handler for channel offers from vmbus in parent partition. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 366 | * |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 367 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 368 | static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 369 | { |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 370 | struct vmbus_channel_offer_channel *offer; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 371 | struct vmbus_channel *newchannel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 372 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 373 | offer = (struct vmbus_channel_offer_channel *)hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 374 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 375 | /* Allocate the channel object and save this offer. */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 376 | newchannel = alloc_channel(); |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 377 | if (!newchannel) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 378 | pr_err("Unable to allocate channel object\n"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 379 | return; |
| 380 | } |
| 381 | |
K. Y. Srinivasan | 132368b | 2012-12-01 06:46:33 -0800 | [diff] [blame] | 382 | /* |
| 383 | * By default we setup state to enable batched |
| 384 | * reading. A specific service can choose to |
| 385 | * disable this prior to opening the channel. |
| 386 | */ |
| 387 | newchannel->batched_reading = true; |
| 388 | |
K. Y. Srinivasan | b3bf60c | 2012-12-01 06:46:45 -0800 | [diff] [blame] | 389 | /* |
| 390 | * Setup state for signalling the host. |
| 391 | */ |
| 392 | newchannel->sig_event = (struct hv_input_signal_event *) |
| 393 | (ALIGN((unsigned long) |
| 394 | &newchannel->sig_buf, |
| 395 | HV_HYPERCALL_PARAM_ALIGN)); |
| 396 | |
| 397 | newchannel->sig_event->connectionid.asu32 = 0; |
| 398 | newchannel->sig_event->connectionid.u.id = VMBUS_EVENT_CONNECTION_ID; |
| 399 | newchannel->sig_event->flag_number = 0; |
| 400 | newchannel->sig_event->rsvdz = 0; |
| 401 | |
| 402 | if (vmbus_proto_version != VERSION_WS2008) { |
| 403 | newchannel->is_dedicated_interrupt = |
| 404 | (offer->is_dedicated_interrupt != 0); |
| 405 | newchannel->sig_event->connectionid.u.id = |
| 406 | offer->connection_id; |
| 407 | } |
| 408 | |
K. Y. Srinivasan | a119845 | 2012-12-01 06:46:50 -0800 | [diff] [blame] | 409 | newchannel->target_vp = get_vp_index(&offer->offer.if_type); |
K. Y. Srinivasan | abbf3b2 | 2012-12-01 06:46:48 -0800 | [diff] [blame] | 410 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 411 | memcpy(&newchannel->offermsg, offer, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 412 | sizeof(struct vmbus_channel_offer_channel)); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 413 | newchannel->monitor_grp = (u8)offer->monitorid / 32; |
| 414 | newchannel->monitor_bit = (u8)offer->monitorid % 32; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 415 | |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 416 | INIT_WORK(&newchannel->work, vmbus_process_offer); |
| 417 | queue_work(newchannel->controlwq, &newchannel->work); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 420 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 421 | * vmbus_onoffer_rescind - Rescind offer handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 422 | * |
| 423 | * We queue a work item to process this offer synchronously |
| 424 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 425 | static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 426 | { |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 427 | struct vmbus_channel_rescind_offer *rescind; |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 428 | struct vmbus_channel *channel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 429 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 430 | rescind = (struct vmbus_channel_rescind_offer *)hdr; |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 431 | channel = relid2channel(rescind->child_relid); |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 432 | |
| 433 | if (channel == NULL) |
| 434 | /* Just return here, no channel found */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 435 | return; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 436 | |
Timo Teräs | 4b2f9ab | 2010-12-15 20:48:09 +0200 | [diff] [blame] | 437 | /* work is initialized for vmbus_process_rescind_offer() from |
| 438 | * vmbus_process_offer() where the channel got created */ |
| 439 | queue_work(channel->controlwq, &channel->work); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 442 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 443 | * vmbus_onoffers_delivered - |
| 444 | * This is invoked when all offers have been delivered. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 445 | * |
| 446 | * Nothing to do here. |
| 447 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 448 | static void vmbus_onoffers_delivered( |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 449 | struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 450 | { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 453 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 454 | * vmbus_onopen_result - Open result handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 455 | * |
| 456 | * This is invoked when we received a response to our channel open request. |
| 457 | * Find the matching request, copy the response and signal the requesting |
| 458 | * thread. |
| 459 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 460 | static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 461 | { |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 462 | struct vmbus_channel_open_result *result; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 463 | struct vmbus_channel_msginfo *msginfo; |
| 464 | struct vmbus_channel_message_header *requestheader; |
| 465 | struct vmbus_channel_open_channel *openmsg; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 466 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 467 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 468 | result = (struct vmbus_channel_open_result *)hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 469 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 470 | /* |
| 471 | * Find the open msg, copy the result and signal/unblock the wait event |
| 472 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 473 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 474 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 475 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 476 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 477 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 478 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 479 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 480 | if (requestheader->msgtype == CHANNELMSG_OPENCHANNEL) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 481 | openmsg = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 482 | (struct vmbus_channel_open_channel *)msginfo->msg; |
| 483 | if (openmsg->child_relid == result->child_relid && |
| 484 | openmsg->openid == result->openid) { |
| 485 | memcpy(&msginfo->response.open_result, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 486 | result, |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 487 | sizeof( |
| 488 | struct vmbus_channel_open_result)); |
| 489 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 490 | break; |
| 491 | } |
| 492 | } |
| 493 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 494 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 497 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 498 | * vmbus_ongpadl_created - GPADL created handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 499 | * |
| 500 | * This is invoked when we received a response to our gpadl create request. |
| 501 | * Find the matching request, copy the response and signal the requesting |
| 502 | * thread. |
| 503 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 504 | static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 505 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 506 | struct vmbus_channel_gpadl_created *gpadlcreated; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 507 | struct vmbus_channel_msginfo *msginfo; |
| 508 | struct vmbus_channel_message_header *requestheader; |
| 509 | struct vmbus_channel_gpadl_header *gpadlheader; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 510 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 511 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 512 | gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 513 | |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 514 | /* |
| 515 | * Find the establish msg, copy the result and signal/unblock the wait |
| 516 | * event |
| 517 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 518 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 519 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 520 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 521 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 522 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 523 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 524 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 525 | if (requestheader->msgtype == CHANNELMSG_GPADL_HEADER) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 526 | gpadlheader = |
| 527 | (struct vmbus_channel_gpadl_header *)requestheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 528 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 529 | if ((gpadlcreated->child_relid == |
| 530 | gpadlheader->child_relid) && |
| 531 | (gpadlcreated->gpadl == gpadlheader->gpadl)) { |
| 532 | memcpy(&msginfo->response.gpadl_created, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 533 | gpadlcreated, |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 534 | sizeof( |
| 535 | struct vmbus_channel_gpadl_created)); |
| 536 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 537 | break; |
| 538 | } |
| 539 | } |
| 540 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 541 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 544 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 545 | * vmbus_ongpadl_torndown - GPADL torndown handler. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 546 | * |
| 547 | * This is invoked when we received a response to our gpadl teardown request. |
| 548 | * Find the matching request, copy the response and signal the requesting |
| 549 | * thread. |
| 550 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 551 | static void vmbus_ongpadl_torndown( |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 552 | struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 553 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 554 | struct vmbus_channel_gpadl_torndown *gpadl_torndown; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 555 | struct vmbus_channel_msginfo *msginfo; |
| 556 | struct vmbus_channel_message_header *requestheader; |
| 557 | struct vmbus_channel_gpadl_teardown *gpadl_teardown; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 558 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 559 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 560 | gpadl_torndown = (struct vmbus_channel_gpadl_torndown *)hdr; |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 561 | |
| 562 | /* |
| 563 | * Find the open msg, copy the result and signal/unblock the wait event |
| 564 | */ |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 565 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 566 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 567 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 568 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 569 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 570 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 571 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 572 | if (requestheader->msgtype == CHANNELMSG_GPADL_TEARDOWN) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 573 | gpadl_teardown = |
| 574 | (struct vmbus_channel_gpadl_teardown *)requestheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 575 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 576 | if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) { |
| 577 | memcpy(&msginfo->response.gpadl_torndown, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 578 | gpadl_torndown, |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 579 | sizeof( |
| 580 | struct vmbus_channel_gpadl_torndown)); |
| 581 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 582 | break; |
| 583 | } |
| 584 | } |
| 585 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 586 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 589 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 590 | * vmbus_onversion_response - Version response handler |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 591 | * |
| 592 | * This is invoked when we received a response to our initiate contact request. |
| 593 | * Find the matching request, copy the response and signal the requesting |
| 594 | * thread. |
| 595 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 596 | static void vmbus_onversion_response( |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 597 | struct vmbus_channel_message_header *hdr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 598 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 599 | struct vmbus_channel_msginfo *msginfo; |
| 600 | struct vmbus_channel_message_header *requestheader; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 601 | struct vmbus_channel_version_response *version_response; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 602 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 603 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 604 | version_response = (struct vmbus_channel_version_response *)hdr; |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 605 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 606 | |
Hank Janssen | ebb61e5 | 2011-02-18 12:39:57 -0800 | [diff] [blame] | 607 | list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list, |
| 608 | msglistentry) { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 609 | requestheader = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 610 | (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 611 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 612 | if (requestheader->msgtype == |
| 613 | CHANNELMSG_INITIATE_CONTACT) { |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 614 | memcpy(&msginfo->response.version_response, |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 615 | version_response, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 616 | sizeof(struct vmbus_channel_version_response)); |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 617 | complete(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 618 | } |
| 619 | } |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 620 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Greg Kroah-Hartman | c8212f0 | 2009-08-31 21:51:50 -0700 | [diff] [blame] | 623 | /* Channel message dispatch table */ |
| 624 | static struct vmbus_channel_message_table_entry |
K. Y. Srinivasan | b7c6b02 | 2011-05-10 07:55:38 -0700 | [diff] [blame] | 625 | channel_message_table[CHANNELMSG_COUNT] = { |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 626 | {CHANNELMSG_INVALID, NULL}, |
| 627 | {CHANNELMSG_OFFERCHANNEL, vmbus_onoffer}, |
| 628 | {CHANNELMSG_RESCIND_CHANNELOFFER, vmbus_onoffer_rescind}, |
| 629 | {CHANNELMSG_REQUESTOFFERS, NULL}, |
| 630 | {CHANNELMSG_ALLOFFERS_DELIVERED, vmbus_onoffers_delivered}, |
| 631 | {CHANNELMSG_OPENCHANNEL, NULL}, |
| 632 | {CHANNELMSG_OPENCHANNEL_RESULT, vmbus_onopen_result}, |
| 633 | {CHANNELMSG_CLOSECHANNEL, NULL}, |
| 634 | {CHANNELMSG_GPADL_HEADER, NULL}, |
| 635 | {CHANNELMSG_GPADL_BODY, NULL}, |
| 636 | {CHANNELMSG_GPADL_CREATED, vmbus_ongpadl_created}, |
| 637 | {CHANNELMSG_GPADL_TEARDOWN, NULL}, |
| 638 | {CHANNELMSG_GPADL_TORNDOWN, vmbus_ongpadl_torndown}, |
| 639 | {CHANNELMSG_RELID_RELEASED, NULL}, |
| 640 | {CHANNELMSG_INITIATE_CONTACT, NULL}, |
| 641 | {CHANNELMSG_VERSION_RESPONSE, vmbus_onversion_response}, |
| 642 | {CHANNELMSG_UNLOAD, NULL}, |
Greg Kroah-Hartman | c8212f0 | 2009-08-31 21:51:50 -0700 | [diff] [blame] | 643 | }; |
| 644 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 645 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 646 | * vmbus_onmessage - Handler for channel protocol messages. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 647 | * |
| 648 | * This is invoked in the vmbus worker thread context. |
| 649 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 650 | void vmbus_onmessage(void *context) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 651 | { |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 652 | struct hv_message *msg = context; |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 653 | struct vmbus_channel_message_header *hdr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 654 | int size; |
| 655 | |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 656 | hdr = (struct vmbus_channel_message_header *)msg->u.payload; |
| 657 | size = msg->header.payload_size; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 658 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 659 | if (hdr->msgtype >= CHANNELMSG_COUNT) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 660 | pr_err("Received invalid channel message type %d size %d\n", |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 661 | hdr->msgtype, size); |
Greg Kroah-Hartman | 04f50c4 | 2009-07-16 12:35:37 -0700 | [diff] [blame] | 662 | print_hex_dump_bytes("", DUMP_PREFIX_NONE, |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 663 | (unsigned char *)msg->u.payload, size); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 664 | return; |
| 665 | } |
| 666 | |
K. Y. Srinivasan | b7c6b02 | 2011-05-10 07:55:38 -0700 | [diff] [blame] | 667 | if (channel_message_table[hdr->msgtype].message_handler) |
| 668 | channel_message_table[hdr->msgtype].message_handler(hdr); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 669 | else |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 670 | pr_err("Unhandled channel message type %d\n", hdr->msgtype); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 673 | /* |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 674 | * vmbus_request_offers - Send a request to get all our pending offers. |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 675 | */ |
Haiyang Zhang | e98cb27 | 2010-10-15 10:14:07 -0700 | [diff] [blame] | 676 | int vmbus_request_offers(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 677 | { |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 678 | struct vmbus_channel_message_header *msg; |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 679 | struct vmbus_channel_msginfo *msginfo; |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 680 | int ret, t; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 681 | |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 682 | msginfo = kmalloc(sizeof(*msginfo) + |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 683 | sizeof(struct vmbus_channel_message_header), |
| 684 | GFP_KERNEL); |
Haiyang Zhang | 188963e | 2010-10-15 10:14:06 -0700 | [diff] [blame] | 685 | if (!msginfo) |
Bill Pemberton | 75910f2 | 2010-05-05 15:27:31 -0400 | [diff] [blame] | 686 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 687 | |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 688 | init_completion(&msginfo->waitevent); |
Bill Pemberton | 75910f2 | 2010-05-05 15:27:31 -0400 | [diff] [blame] | 689 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 690 | msg = (struct vmbus_channel_message_header *)msginfo->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 691 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 692 | msg->msgtype = CHANNELMSG_REQUESTOFFERS; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 693 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 694 | |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 695 | ret = vmbus_post_msg(msg, |
Greg Kroah-Hartman | bd60c33 | 2009-08-31 21:47:21 -0700 | [diff] [blame] | 696 | sizeof(struct vmbus_channel_message_header)); |
| 697 | if (ret != 0) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 698 | pr_err("Unable to request offers - %d\n", ret); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 699 | |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 700 | goto cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 701 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 702 | |
K. Y. Srinivasan | 2dfde96 | 2011-06-16 13:16:34 -0700 | [diff] [blame] | 703 | t = wait_for_completion_timeout(&msginfo->waitevent, 5*HZ); |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 704 | if (t == 0) { |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 705 | ret = -ETIMEDOUT; |
| 706 | goto cleanup; |
| 707 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 708 | |
| 709 | |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 710 | |
| 711 | cleanup: |
Ilia Mirkin | dd9b15d | 2011-03-13 00:29:00 -0500 | [diff] [blame] | 712 | kfree(msginfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 713 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 714 | return ret; |
| 715 | } |
| 716 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 717 | /* |
| 718 | * Retrieve the (sub) channel on which to send an outgoing request. |
| 719 | * When a primary channel has multiple sub-channels, we choose a |
| 720 | * channel whose VCPU binding is closest to the VCPU on which |
| 721 | * this call is being made. |
| 722 | */ |
| 723 | struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary) |
| 724 | { |
| 725 | struct list_head *cur, *tmp; |
| 726 | int cur_cpu = hv_context.vp_index[smp_processor_id()]; |
| 727 | struct vmbus_channel *cur_channel; |
| 728 | struct vmbus_channel *outgoing_channel = primary; |
| 729 | int cpu_distance, new_cpu_distance; |
| 730 | |
| 731 | if (list_empty(&primary->sc_list)) |
| 732 | return outgoing_channel; |
| 733 | |
| 734 | list_for_each_safe(cur, tmp, &primary->sc_list) { |
| 735 | cur_channel = list_entry(cur, struct vmbus_channel, sc_list); |
| 736 | if (cur_channel->state != CHANNEL_OPENED_STATE) |
| 737 | continue; |
| 738 | |
| 739 | if (cur_channel->target_vp == cur_cpu) |
| 740 | return cur_channel; |
| 741 | |
| 742 | cpu_distance = ((outgoing_channel->target_vp > cur_cpu) ? |
| 743 | (outgoing_channel->target_vp - cur_cpu) : |
| 744 | (cur_cpu - outgoing_channel->target_vp)); |
| 745 | |
| 746 | new_cpu_distance = ((cur_channel->target_vp > cur_cpu) ? |
| 747 | (cur_channel->target_vp - cur_cpu) : |
| 748 | (cur_cpu - cur_channel->target_vp)); |
| 749 | |
| 750 | if (cpu_distance < new_cpu_distance) |
| 751 | continue; |
| 752 | |
| 753 | outgoing_channel = cur_channel; |
| 754 | } |
| 755 | |
| 756 | return outgoing_channel; |
| 757 | } |
| 758 | EXPORT_SYMBOL_GPL(vmbus_get_outgoing_channel); |
| 759 | |
| 760 | static void invoke_sc_cb(struct vmbus_channel *primary_channel) |
| 761 | { |
| 762 | struct list_head *cur, *tmp; |
| 763 | struct vmbus_channel *cur_channel; |
| 764 | |
| 765 | if (primary_channel->sc_creation_callback == NULL) |
| 766 | return; |
| 767 | |
| 768 | list_for_each_safe(cur, tmp, &primary_channel->sc_list) { |
| 769 | cur_channel = list_entry(cur, struct vmbus_channel, sc_list); |
| 770 | |
| 771 | primary_channel->sc_creation_callback(cur_channel); |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel, |
| 776 | void (*sc_cr_cb)(struct vmbus_channel *new_sc)) |
| 777 | { |
| 778 | primary_channel->sc_creation_callback = sc_cr_cb; |
| 779 | } |
| 780 | EXPORT_SYMBOL_GPL(vmbus_set_sc_create_callback); |
| 781 | |
| 782 | bool vmbus_are_subchannels_present(struct vmbus_channel *primary) |
| 783 | { |
| 784 | bool ret; |
| 785 | |
| 786 | ret = !list_empty(&primary->sc_list); |
| 787 | |
| 788 | if (ret) { |
| 789 | /* |
| 790 | * Invoke the callback on sub-channel creation. |
| 791 | * This will present a uniform interface to the |
| 792 | * clients. |
| 793 | */ |
| 794 | invoke_sc_cb(primary); |
| 795 | } |
| 796 | |
| 797 | return ret; |
| 798 | } |
| 799 | EXPORT_SYMBOL_GPL(vmbus_are_subchannels_present); |