Thomas Gleixner | 3b20eb2 | 2019-05-29 16:57:35 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2 | /* |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 3 | * Copyright (c) 2009, Microsoft Corporation. |
| 4 | * |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 5 | * Authors: |
| 6 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 7 | * Hank Janssen <hjanssen@microsoft.com> |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 8 | * K. Y. Srinivasan <kys@microsoft.com> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 9 | */ |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/device.h> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/sysctl.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 18 | #include <linux/acpi.h> |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 19 | #include <linux/completion.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 20 | #include <linux/hyperv.h> |
K. Y. Srinivasan | b020950 | 2012-12-01 06:46:54 -0800 | [diff] [blame] | 21 | #include <linux/kernel_stat.h> |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 22 | #include <linux/clockchips.h> |
Vitaly Kuznetsov | e513229 | 2015-02-27 11:25:51 -0800 | [diff] [blame] | 23 | #include <linux/cpu.h> |
Ingo Molnar | 68db0cf | 2017-02-08 18:51:37 +0100 | [diff] [blame] | 24 | #include <linux/sched/task_stack.h> |
| 25 | |
K. Y. Srinivasan | 302a3c0 | 2013-02-17 11:30:44 -0800 | [diff] [blame] | 26 | #include <asm/mshyperv.h> |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 27 | #include <linux/notifier.h> |
| 28 | #include <linux/ptrace.h> |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 29 | #include <linux/screen_info.h> |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 30 | #include <linux/kdebug.h> |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 31 | #include <linux/efi.h> |
Stephan Mueller | 4b44f2d | 2016-05-02 02:14:34 -0400 | [diff] [blame] | 32 | #include <linux/random.h> |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame^] | 33 | #include <linux/syscore_ops.h> |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 34 | #include <clocksource/hyperv_timer.h> |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 35 | #include "hyperv_vmbus.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 36 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 37 | struct vmbus_dynid { |
| 38 | struct list_head node; |
| 39 | struct hv_vmbus_device_id id; |
| 40 | }; |
| 41 | |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 42 | static struct acpi_device *hv_acpi_dev; |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 43 | |
K. Y. Srinivasan | 71a6655 | 2011-04-29 13:45:04 -0700 | [diff] [blame] | 44 | static struct completion probe_event; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 45 | |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 46 | static int hyperv_cpuhp_online; |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 47 | |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 48 | static void *hv_panic_page; |
| 49 | |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 50 | static int hyperv_panic_event(struct notifier_block *nb, unsigned long val, |
| 51 | void *args) |
| 52 | { |
| 53 | struct pt_regs *regs; |
| 54 | |
| 55 | regs = current_pt_regs(); |
| 56 | |
K. Y. Srinivasan | 7ed4325 | 2017-10-29 11:33:41 -0700 | [diff] [blame] | 57 | hyperv_report_panic(regs, val); |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 58 | return NOTIFY_DONE; |
| 59 | } |
| 60 | |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 61 | static int hyperv_die_event(struct notifier_block *nb, unsigned long val, |
| 62 | void *args) |
| 63 | { |
| 64 | struct die_args *die = (struct die_args *)args; |
| 65 | struct pt_regs *regs = die->regs; |
| 66 | |
K. Y. Srinivasan | 7ed4325 | 2017-10-29 11:33:41 -0700 | [diff] [blame] | 67 | hyperv_report_panic(regs, val); |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 68 | return NOTIFY_DONE; |
| 69 | } |
| 70 | |
| 71 | static struct notifier_block hyperv_die_block = { |
| 72 | .notifier_call = hyperv_die_event, |
| 73 | }; |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 74 | static struct notifier_block hyperv_panic_block = { |
| 75 | .notifier_call = hyperv_panic_event, |
| 76 | }; |
| 77 | |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 78 | static const char *fb_mmio_name = "fb_range"; |
| 79 | static struct resource *fb_mmio; |
Stephen Hemminger | e2e8084 | 2016-09-07 05:39:33 -0700 | [diff] [blame] | 80 | static struct resource *hyperv_mmio; |
| 81 | static DEFINE_SEMAPHORE(hyperv_mmio_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 82 | |
K. Y. Srinivasan | cf6a2ea | 2011-12-01 09:59:34 -0800 | [diff] [blame] | 83 | static int vmbus_exists(void) |
| 84 | { |
| 85 | if (hv_acpi_dev == NULL) |
| 86 | return -ENODEV; |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Olaf Hering | fd776ba | 2011-09-02 18:25:56 +0200 | [diff] [blame] | 91 | #define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)->guid) * 2) |
| 92 | static void print_alias_name(struct hv_device *hv_dev, char *alias_name) |
| 93 | { |
| 94 | int i; |
| 95 | for (i = 0; i < VMBUS_ALIAS_LEN; i += 2) |
| 96 | sprintf(&alias_name[i], "%02x", hv_dev->dev_type.b[i/2]); |
| 97 | } |
| 98 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 99 | static u8 channel_monitor_group(const struct vmbus_channel *channel) |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 100 | { |
| 101 | return (u8)channel->offermsg.monitorid / 32; |
| 102 | } |
| 103 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 104 | static u8 channel_monitor_offset(const struct vmbus_channel *channel) |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 105 | { |
| 106 | return (u8)channel->offermsg.monitorid % 32; |
| 107 | } |
| 108 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 109 | static u32 channel_pending(const struct vmbus_channel *channel, |
| 110 | const struct hv_monitor_page *monitor_page) |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 111 | { |
| 112 | u8 monitor_group = channel_monitor_group(channel); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 113 | |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 114 | return monitor_page->trigger_group[monitor_group].pending; |
| 115 | } |
| 116 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 117 | static u32 channel_latency(const struct vmbus_channel *channel, |
| 118 | const struct hv_monitor_page *monitor_page) |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 119 | { |
| 120 | u8 monitor_group = channel_monitor_group(channel); |
| 121 | u8 monitor_offset = channel_monitor_offset(channel); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 122 | |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 123 | return monitor_page->latency[monitor_group][monitor_offset]; |
| 124 | } |
| 125 | |
Greg Kroah-Hartman | 4947c74 | 2013-09-13 11:32:58 -0700 | [diff] [blame] | 126 | static u32 channel_conn_id(struct vmbus_channel *channel, |
| 127 | struct hv_monitor_page *monitor_page) |
| 128 | { |
| 129 | u8 monitor_group = channel_monitor_group(channel); |
| 130 | u8 monitor_offset = channel_monitor_offset(channel); |
| 131 | return monitor_page->parameter[monitor_group][monitor_offset].connectionid.u.id; |
| 132 | } |
| 133 | |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 134 | static ssize_t id_show(struct device *dev, struct device_attribute *dev_attr, |
| 135 | char *buf) |
| 136 | { |
| 137 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 138 | |
| 139 | if (!hv_dev->channel) |
| 140 | return -ENODEV; |
| 141 | return sprintf(buf, "%d\n", hv_dev->channel->offermsg.child_relid); |
| 142 | } |
| 143 | static DEVICE_ATTR_RO(id); |
| 144 | |
Greg Kroah-Hartman | a8fb5f3 | 2013-09-13 11:32:50 -0700 | [diff] [blame] | 145 | static ssize_t state_show(struct device *dev, struct device_attribute *dev_attr, |
| 146 | char *buf) |
| 147 | { |
| 148 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 149 | |
| 150 | if (!hv_dev->channel) |
| 151 | return -ENODEV; |
| 152 | return sprintf(buf, "%d\n", hv_dev->channel->state); |
| 153 | } |
| 154 | static DEVICE_ATTR_RO(state); |
| 155 | |
Greg Kroah-Hartman | 5ffd00e | 2013-09-13 11:32:51 -0700 | [diff] [blame] | 156 | static ssize_t monitor_id_show(struct device *dev, |
| 157 | struct device_attribute *dev_attr, char *buf) |
| 158 | { |
| 159 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 160 | |
| 161 | if (!hv_dev->channel) |
| 162 | return -ENODEV; |
| 163 | return sprintf(buf, "%d\n", hv_dev->channel->offermsg.monitorid); |
| 164 | } |
| 165 | static DEVICE_ATTR_RO(monitor_id); |
| 166 | |
Greg Kroah-Hartman | 68234c0 | 2013-09-13 11:32:53 -0700 | [diff] [blame] | 167 | static ssize_t class_id_show(struct device *dev, |
| 168 | struct device_attribute *dev_attr, char *buf) |
| 169 | { |
| 170 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 171 | |
| 172 | if (!hv_dev->channel) |
| 173 | return -ENODEV; |
| 174 | return sprintf(buf, "{%pUl}\n", |
| 175 | hv_dev->channel->offermsg.offer.if_type.b); |
| 176 | } |
| 177 | static DEVICE_ATTR_RO(class_id); |
| 178 | |
Greg Kroah-Hartman | 7c55e1d | 2013-09-13 11:32:54 -0700 | [diff] [blame] | 179 | static ssize_t device_id_show(struct device *dev, |
| 180 | struct device_attribute *dev_attr, char *buf) |
| 181 | { |
| 182 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 183 | |
| 184 | if (!hv_dev->channel) |
| 185 | return -ENODEV; |
| 186 | return sprintf(buf, "{%pUl}\n", |
| 187 | hv_dev->channel->offermsg.offer.if_instance.b); |
| 188 | } |
| 189 | static DEVICE_ATTR_RO(device_id); |
| 190 | |
Greg Kroah-Hartman | 647fa37 | 2013-09-13 11:32:52 -0700 | [diff] [blame] | 191 | static ssize_t modalias_show(struct device *dev, |
| 192 | struct device_attribute *dev_attr, char *buf) |
| 193 | { |
| 194 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 195 | char alias_name[VMBUS_ALIAS_LEN + 1]; |
| 196 | |
| 197 | print_alias_name(hv_dev, alias_name); |
| 198 | return sprintf(buf, "vmbus:%s\n", alias_name); |
| 199 | } |
| 200 | static DEVICE_ATTR_RO(modalias); |
| 201 | |
Stephen Hemminger | 7ceb1c3 | 2018-07-28 21:58:48 +0000 | [diff] [blame] | 202 | #ifdef CONFIG_NUMA |
| 203 | static ssize_t numa_node_show(struct device *dev, |
| 204 | struct device_attribute *attr, char *buf) |
| 205 | { |
| 206 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 207 | |
| 208 | if (!hv_dev->channel) |
| 209 | return -ENODEV; |
| 210 | |
| 211 | return sprintf(buf, "%d\n", hv_dev->channel->numa_node); |
| 212 | } |
| 213 | static DEVICE_ATTR_RO(numa_node); |
| 214 | #endif |
| 215 | |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 216 | static ssize_t server_monitor_pending_show(struct device *dev, |
| 217 | struct device_attribute *dev_attr, |
| 218 | char *buf) |
| 219 | { |
| 220 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 221 | |
| 222 | if (!hv_dev->channel) |
| 223 | return -ENODEV; |
| 224 | return sprintf(buf, "%d\n", |
| 225 | channel_pending(hv_dev->channel, |
Kimberly Brown | fd8e3c3 | 2019-02-19 00:38:06 -0500 | [diff] [blame] | 226 | vmbus_connection.monitor_pages[0])); |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 227 | } |
| 228 | static DEVICE_ATTR_RO(server_monitor_pending); |
| 229 | |
| 230 | static ssize_t client_monitor_pending_show(struct device *dev, |
| 231 | struct device_attribute *dev_attr, |
| 232 | char *buf) |
| 233 | { |
| 234 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 235 | |
| 236 | if (!hv_dev->channel) |
| 237 | return -ENODEV; |
| 238 | return sprintf(buf, "%d\n", |
| 239 | channel_pending(hv_dev->channel, |
| 240 | vmbus_connection.monitor_pages[1])); |
| 241 | } |
| 242 | static DEVICE_ATTR_RO(client_monitor_pending); |
Greg Kroah-Hartman | 68234c0 | 2013-09-13 11:32:53 -0700 | [diff] [blame] | 243 | |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 244 | static ssize_t server_monitor_latency_show(struct device *dev, |
| 245 | struct device_attribute *dev_attr, |
| 246 | char *buf) |
| 247 | { |
| 248 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 249 | |
| 250 | if (!hv_dev->channel) |
| 251 | return -ENODEV; |
| 252 | return sprintf(buf, "%d\n", |
| 253 | channel_latency(hv_dev->channel, |
| 254 | vmbus_connection.monitor_pages[0])); |
| 255 | } |
| 256 | static DEVICE_ATTR_RO(server_monitor_latency); |
| 257 | |
| 258 | static ssize_t client_monitor_latency_show(struct device *dev, |
| 259 | struct device_attribute *dev_attr, |
| 260 | char *buf) |
| 261 | { |
| 262 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 263 | |
| 264 | if (!hv_dev->channel) |
| 265 | return -ENODEV; |
| 266 | return sprintf(buf, "%d\n", |
| 267 | channel_latency(hv_dev->channel, |
| 268 | vmbus_connection.monitor_pages[1])); |
| 269 | } |
| 270 | static DEVICE_ATTR_RO(client_monitor_latency); |
| 271 | |
Greg Kroah-Hartman | 4947c74 | 2013-09-13 11:32:58 -0700 | [diff] [blame] | 272 | static ssize_t server_monitor_conn_id_show(struct device *dev, |
| 273 | struct device_attribute *dev_attr, |
| 274 | char *buf) |
| 275 | { |
| 276 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 277 | |
| 278 | if (!hv_dev->channel) |
| 279 | return -ENODEV; |
| 280 | return sprintf(buf, "%d\n", |
| 281 | channel_conn_id(hv_dev->channel, |
| 282 | vmbus_connection.monitor_pages[0])); |
| 283 | } |
| 284 | static DEVICE_ATTR_RO(server_monitor_conn_id); |
| 285 | |
| 286 | static ssize_t client_monitor_conn_id_show(struct device *dev, |
| 287 | struct device_attribute *dev_attr, |
| 288 | char *buf) |
| 289 | { |
| 290 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 291 | |
| 292 | if (!hv_dev->channel) |
| 293 | return -ENODEV; |
| 294 | return sprintf(buf, "%d\n", |
| 295 | channel_conn_id(hv_dev->channel, |
| 296 | vmbus_connection.monitor_pages[1])); |
| 297 | } |
| 298 | static DEVICE_ATTR_RO(client_monitor_conn_id); |
| 299 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 300 | static ssize_t out_intr_mask_show(struct device *dev, |
| 301 | struct device_attribute *dev_attr, char *buf) |
| 302 | { |
| 303 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 304 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 305 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 306 | |
| 307 | if (!hv_dev->channel) |
| 308 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 309 | |
| 310 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 311 | &outbound); |
| 312 | if (ret < 0) |
| 313 | return ret; |
| 314 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 315 | return sprintf(buf, "%d\n", outbound.current_interrupt_mask); |
| 316 | } |
| 317 | static DEVICE_ATTR_RO(out_intr_mask); |
| 318 | |
| 319 | static ssize_t out_read_index_show(struct device *dev, |
| 320 | struct device_attribute *dev_attr, char *buf) |
| 321 | { |
| 322 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 323 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 324 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 325 | |
| 326 | if (!hv_dev->channel) |
| 327 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 328 | |
| 329 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 330 | &outbound); |
| 331 | if (ret < 0) |
| 332 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 333 | return sprintf(buf, "%d\n", outbound.current_read_index); |
| 334 | } |
| 335 | static DEVICE_ATTR_RO(out_read_index); |
| 336 | |
| 337 | static ssize_t out_write_index_show(struct device *dev, |
| 338 | struct device_attribute *dev_attr, |
| 339 | char *buf) |
| 340 | { |
| 341 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 342 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 343 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 344 | |
| 345 | if (!hv_dev->channel) |
| 346 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 347 | |
| 348 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 349 | &outbound); |
| 350 | if (ret < 0) |
| 351 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 352 | return sprintf(buf, "%d\n", outbound.current_write_index); |
| 353 | } |
| 354 | static DEVICE_ATTR_RO(out_write_index); |
| 355 | |
| 356 | static ssize_t out_read_bytes_avail_show(struct device *dev, |
| 357 | struct device_attribute *dev_attr, |
| 358 | char *buf) |
| 359 | { |
| 360 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 361 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 362 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 363 | |
| 364 | if (!hv_dev->channel) |
| 365 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 366 | |
| 367 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 368 | &outbound); |
| 369 | if (ret < 0) |
| 370 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 371 | return sprintf(buf, "%d\n", outbound.bytes_avail_toread); |
| 372 | } |
| 373 | static DEVICE_ATTR_RO(out_read_bytes_avail); |
| 374 | |
| 375 | static ssize_t out_write_bytes_avail_show(struct device *dev, |
| 376 | struct device_attribute *dev_attr, |
| 377 | char *buf) |
| 378 | { |
| 379 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 380 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 381 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 382 | |
| 383 | if (!hv_dev->channel) |
| 384 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 385 | |
| 386 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 387 | &outbound); |
| 388 | if (ret < 0) |
| 389 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 390 | return sprintf(buf, "%d\n", outbound.bytes_avail_towrite); |
| 391 | } |
| 392 | static DEVICE_ATTR_RO(out_write_bytes_avail); |
| 393 | |
| 394 | static ssize_t in_intr_mask_show(struct device *dev, |
| 395 | struct device_attribute *dev_attr, char *buf) |
| 396 | { |
| 397 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 398 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 399 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 400 | |
| 401 | if (!hv_dev->channel) |
| 402 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 403 | |
| 404 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 405 | if (ret < 0) |
| 406 | return ret; |
| 407 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 408 | return sprintf(buf, "%d\n", inbound.current_interrupt_mask); |
| 409 | } |
| 410 | static DEVICE_ATTR_RO(in_intr_mask); |
| 411 | |
| 412 | static ssize_t in_read_index_show(struct device *dev, |
| 413 | struct device_attribute *dev_attr, char *buf) |
| 414 | { |
| 415 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 416 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 417 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 418 | |
| 419 | if (!hv_dev->channel) |
| 420 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 421 | |
| 422 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 423 | if (ret < 0) |
| 424 | return ret; |
| 425 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 426 | return sprintf(buf, "%d\n", inbound.current_read_index); |
| 427 | } |
| 428 | static DEVICE_ATTR_RO(in_read_index); |
| 429 | |
| 430 | static ssize_t in_write_index_show(struct device *dev, |
| 431 | struct device_attribute *dev_attr, char *buf) |
| 432 | { |
| 433 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 434 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 435 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 436 | |
| 437 | if (!hv_dev->channel) |
| 438 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 439 | |
| 440 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 441 | if (ret < 0) |
| 442 | return ret; |
| 443 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 444 | return sprintf(buf, "%d\n", inbound.current_write_index); |
| 445 | } |
| 446 | static DEVICE_ATTR_RO(in_write_index); |
| 447 | |
| 448 | static ssize_t in_read_bytes_avail_show(struct device *dev, |
| 449 | struct device_attribute *dev_attr, |
| 450 | char *buf) |
| 451 | { |
| 452 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 453 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 454 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 455 | |
| 456 | if (!hv_dev->channel) |
| 457 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 458 | |
| 459 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 460 | if (ret < 0) |
| 461 | return ret; |
| 462 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 463 | return sprintf(buf, "%d\n", inbound.bytes_avail_toread); |
| 464 | } |
| 465 | static DEVICE_ATTR_RO(in_read_bytes_avail); |
| 466 | |
| 467 | static ssize_t in_write_bytes_avail_show(struct device *dev, |
| 468 | struct device_attribute *dev_attr, |
| 469 | char *buf) |
| 470 | { |
| 471 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 472 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 473 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 474 | |
| 475 | if (!hv_dev->channel) |
| 476 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 477 | |
| 478 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 479 | if (ret < 0) |
| 480 | return ret; |
| 481 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 482 | return sprintf(buf, "%d\n", inbound.bytes_avail_towrite); |
| 483 | } |
| 484 | static DEVICE_ATTR_RO(in_write_bytes_avail); |
| 485 | |
Dexuan Cui | 042ab03 | 2015-08-05 00:52:43 -0700 | [diff] [blame] | 486 | static ssize_t channel_vp_mapping_show(struct device *dev, |
| 487 | struct device_attribute *dev_attr, |
| 488 | char *buf) |
| 489 | { |
| 490 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 491 | struct vmbus_channel *channel = hv_dev->channel, *cur_sc; |
| 492 | unsigned long flags; |
| 493 | int buf_size = PAGE_SIZE, n_written, tot_written; |
| 494 | struct list_head *cur; |
| 495 | |
| 496 | if (!channel) |
| 497 | return -ENODEV; |
| 498 | |
| 499 | tot_written = snprintf(buf, buf_size, "%u:%u\n", |
| 500 | channel->offermsg.child_relid, channel->target_cpu); |
| 501 | |
| 502 | spin_lock_irqsave(&channel->lock, flags); |
| 503 | |
| 504 | list_for_each(cur, &channel->sc_list) { |
| 505 | if (tot_written >= buf_size - 1) |
| 506 | break; |
| 507 | |
| 508 | cur_sc = list_entry(cur, struct vmbus_channel, sc_list); |
| 509 | n_written = scnprintf(buf + tot_written, |
| 510 | buf_size - tot_written, |
| 511 | "%u:%u\n", |
| 512 | cur_sc->offermsg.child_relid, |
| 513 | cur_sc->target_cpu); |
| 514 | tot_written += n_written; |
| 515 | } |
| 516 | |
| 517 | spin_unlock_irqrestore(&channel->lock, flags); |
| 518 | |
| 519 | return tot_written; |
| 520 | } |
| 521 | static DEVICE_ATTR_RO(channel_vp_mapping); |
| 522 | |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 523 | static ssize_t vendor_show(struct device *dev, |
| 524 | struct device_attribute *dev_attr, |
| 525 | char *buf) |
| 526 | { |
| 527 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 528 | return sprintf(buf, "0x%x\n", hv_dev->vendor_id); |
| 529 | } |
| 530 | static DEVICE_ATTR_RO(vendor); |
| 531 | |
| 532 | static ssize_t device_show(struct device *dev, |
| 533 | struct device_attribute *dev_attr, |
| 534 | char *buf) |
| 535 | { |
| 536 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 537 | return sprintf(buf, "0x%x\n", hv_dev->device_id); |
| 538 | } |
| 539 | static DEVICE_ATTR_RO(device); |
| 540 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 541 | static ssize_t driver_override_store(struct device *dev, |
| 542 | struct device_attribute *attr, |
| 543 | const char *buf, size_t count) |
| 544 | { |
| 545 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 546 | char *driver_override, *old, *cp; |
| 547 | |
| 548 | /* We need to keep extra room for a newline */ |
| 549 | if (count >= (PAGE_SIZE - 1)) |
| 550 | return -EINVAL; |
| 551 | |
| 552 | driver_override = kstrndup(buf, count, GFP_KERNEL); |
| 553 | if (!driver_override) |
| 554 | return -ENOMEM; |
| 555 | |
| 556 | cp = strchr(driver_override, '\n'); |
| 557 | if (cp) |
| 558 | *cp = '\0'; |
| 559 | |
| 560 | device_lock(dev); |
| 561 | old = hv_dev->driver_override; |
| 562 | if (strlen(driver_override)) { |
| 563 | hv_dev->driver_override = driver_override; |
| 564 | } else { |
| 565 | kfree(driver_override); |
| 566 | hv_dev->driver_override = NULL; |
| 567 | } |
| 568 | device_unlock(dev); |
| 569 | |
| 570 | kfree(old); |
| 571 | |
| 572 | return count; |
| 573 | } |
| 574 | |
| 575 | static ssize_t driver_override_show(struct device *dev, |
| 576 | struct device_attribute *attr, char *buf) |
| 577 | { |
| 578 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 579 | ssize_t len; |
| 580 | |
| 581 | device_lock(dev); |
| 582 | len = snprintf(buf, PAGE_SIZE, "%s\n", hv_dev->driver_override); |
| 583 | device_unlock(dev); |
| 584 | |
| 585 | return len; |
| 586 | } |
| 587 | static DEVICE_ATTR_RW(driver_override); |
| 588 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 589 | /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */ |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 590 | static struct attribute *vmbus_dev_attrs[] = { |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 591 | &dev_attr_id.attr, |
Greg Kroah-Hartman | a8fb5f3 | 2013-09-13 11:32:50 -0700 | [diff] [blame] | 592 | &dev_attr_state.attr, |
Greg Kroah-Hartman | 5ffd00e | 2013-09-13 11:32:51 -0700 | [diff] [blame] | 593 | &dev_attr_monitor_id.attr, |
Greg Kroah-Hartman | 68234c0 | 2013-09-13 11:32:53 -0700 | [diff] [blame] | 594 | &dev_attr_class_id.attr, |
Greg Kroah-Hartman | 7c55e1d | 2013-09-13 11:32:54 -0700 | [diff] [blame] | 595 | &dev_attr_device_id.attr, |
Greg Kroah-Hartman | 647fa37 | 2013-09-13 11:32:52 -0700 | [diff] [blame] | 596 | &dev_attr_modalias.attr, |
Stephen Hemminger | 7ceb1c3 | 2018-07-28 21:58:48 +0000 | [diff] [blame] | 597 | #ifdef CONFIG_NUMA |
| 598 | &dev_attr_numa_node.attr, |
| 599 | #endif |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 600 | &dev_attr_server_monitor_pending.attr, |
| 601 | &dev_attr_client_monitor_pending.attr, |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 602 | &dev_attr_server_monitor_latency.attr, |
| 603 | &dev_attr_client_monitor_latency.attr, |
Greg Kroah-Hartman | 4947c74 | 2013-09-13 11:32:58 -0700 | [diff] [blame] | 604 | &dev_attr_server_monitor_conn_id.attr, |
| 605 | &dev_attr_client_monitor_conn_id.attr, |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 606 | &dev_attr_out_intr_mask.attr, |
| 607 | &dev_attr_out_read_index.attr, |
| 608 | &dev_attr_out_write_index.attr, |
| 609 | &dev_attr_out_read_bytes_avail.attr, |
| 610 | &dev_attr_out_write_bytes_avail.attr, |
| 611 | &dev_attr_in_intr_mask.attr, |
| 612 | &dev_attr_in_read_index.attr, |
| 613 | &dev_attr_in_write_index.attr, |
| 614 | &dev_attr_in_read_bytes_avail.attr, |
| 615 | &dev_attr_in_write_bytes_avail.attr, |
Dexuan Cui | 042ab03 | 2015-08-05 00:52:43 -0700 | [diff] [blame] | 616 | &dev_attr_channel_vp_mapping.attr, |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 617 | &dev_attr_vendor.attr, |
| 618 | &dev_attr_device.attr, |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 619 | &dev_attr_driver_override.attr, |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 620 | NULL, |
| 621 | }; |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 622 | |
| 623 | /* |
| 624 | * Device-level attribute_group callback function. Returns the permission for |
| 625 | * each attribute, and returns 0 if an attribute is not visible. |
| 626 | */ |
| 627 | static umode_t vmbus_dev_attr_is_visible(struct kobject *kobj, |
| 628 | struct attribute *attr, int idx) |
| 629 | { |
| 630 | struct device *dev = kobj_to_dev(kobj); |
| 631 | const struct hv_device *hv_dev = device_to_hv_device(dev); |
| 632 | |
| 633 | /* Hide the monitor attributes if the monitor mechanism is not used. */ |
| 634 | if (!hv_dev->channel->offermsg.monitor_allocated && |
| 635 | (attr == &dev_attr_monitor_id.attr || |
| 636 | attr == &dev_attr_server_monitor_pending.attr || |
| 637 | attr == &dev_attr_client_monitor_pending.attr || |
| 638 | attr == &dev_attr_server_monitor_latency.attr || |
| 639 | attr == &dev_attr_client_monitor_latency.attr || |
| 640 | attr == &dev_attr_server_monitor_conn_id.attr || |
| 641 | attr == &dev_attr_client_monitor_conn_id.attr)) |
| 642 | return 0; |
| 643 | |
| 644 | return attr->mode; |
| 645 | } |
| 646 | |
| 647 | static const struct attribute_group vmbus_dev_group = { |
| 648 | .attrs = vmbus_dev_attrs, |
| 649 | .is_visible = vmbus_dev_attr_is_visible |
| 650 | }; |
| 651 | __ATTRIBUTE_GROUPS(vmbus_dev); |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 652 | |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 653 | /* |
| 654 | * vmbus_uevent - add uevent for our device |
| 655 | * |
| 656 | * This routine is invoked when a device is added or removed on the vmbus to |
| 657 | * generate a uevent to udev in the userspace. The udev will then look at its |
| 658 | * rule and the uevent generated here to load the appropriate driver |
K. Y. Srinivasan | 0ddda66 | 2011-08-25 09:48:38 -0700 | [diff] [blame] | 659 | * |
| 660 | * The alias string will be of the form vmbus:guid where guid is the string |
| 661 | * representation of the device guid (each byte of the guid will be |
| 662 | * represented with two hex characters. |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 663 | */ |
| 664 | static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) |
| 665 | { |
| 666 | struct hv_device *dev = device_to_hv_device(device); |
Olaf Hering | fd776ba | 2011-09-02 18:25:56 +0200 | [diff] [blame] | 667 | int ret; |
| 668 | char alias_name[VMBUS_ALIAS_LEN + 1]; |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 669 | |
Olaf Hering | fd776ba | 2011-09-02 18:25:56 +0200 | [diff] [blame] | 670 | print_alias_name(dev, alias_name); |
K. Y. Srinivasan | 0ddda66 | 2011-08-25 09:48:38 -0700 | [diff] [blame] | 671 | ret = add_uevent_var(env, "MODALIAS=vmbus:%s", alias_name); |
| 672 | return ret; |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 675 | static const struct hv_vmbus_device_id * |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 676 | hv_vmbus_dev_match(const struct hv_vmbus_device_id *id, const guid_t *guid) |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 677 | { |
| 678 | if (id == NULL) |
| 679 | return NULL; /* empty device table */ |
| 680 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 681 | for (; !guid_is_null(&id->guid); id++) |
| 682 | if (guid_equal(&id->guid, guid)) |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 683 | return id; |
| 684 | |
| 685 | return NULL; |
| 686 | } |
| 687 | |
| 688 | static const struct hv_vmbus_device_id * |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 689 | hv_vmbus_dynid_match(struct hv_driver *drv, const guid_t *guid) |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 690 | { |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 691 | const struct hv_vmbus_device_id *id = NULL; |
| 692 | struct vmbus_dynid *dynid; |
| 693 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 694 | spin_lock(&drv->dynids.lock); |
| 695 | list_for_each_entry(dynid, &drv->dynids.list, node) { |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 696 | if (guid_equal(&dynid->id.guid, guid)) { |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 697 | id = &dynid->id; |
| 698 | break; |
| 699 | } |
| 700 | } |
| 701 | spin_unlock(&drv->dynids.lock); |
| 702 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 703 | return id; |
| 704 | } |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 705 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 706 | static const struct hv_vmbus_device_id vmbus_device_null; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 707 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 708 | /* |
| 709 | * Return a matching hv_vmbus_device_id pointer. |
| 710 | * If there is no match, return NULL. |
| 711 | */ |
| 712 | static const struct hv_vmbus_device_id *hv_vmbus_get_id(struct hv_driver *drv, |
| 713 | struct hv_device *dev) |
| 714 | { |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 715 | const guid_t *guid = &dev->dev_type; |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 716 | const struct hv_vmbus_device_id *id; |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 717 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 718 | /* When driver_override is set, only bind to the matching driver */ |
| 719 | if (dev->driver_override && strcmp(dev->driver_override, drv->name)) |
| 720 | return NULL; |
| 721 | |
| 722 | /* Look at the dynamic ids first, before the static ones */ |
| 723 | id = hv_vmbus_dynid_match(drv, guid); |
| 724 | if (!id) |
| 725 | id = hv_vmbus_dev_match(drv->id_table, guid); |
| 726 | |
| 727 | /* driver_override will always match, send a dummy id */ |
| 728 | if (!id && dev->driver_override) |
| 729 | id = &vmbus_device_null; |
| 730 | |
| 731 | return id; |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 734 | /* vmbus_add_dynid - add a new device ID to this driver and re-probe devices */ |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 735 | static int vmbus_add_dynid(struct hv_driver *drv, guid_t *guid) |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 736 | { |
| 737 | struct vmbus_dynid *dynid; |
| 738 | |
| 739 | dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); |
| 740 | if (!dynid) |
| 741 | return -ENOMEM; |
| 742 | |
| 743 | dynid->id.guid = *guid; |
| 744 | |
| 745 | spin_lock(&drv->dynids.lock); |
| 746 | list_add_tail(&dynid->node, &drv->dynids.list); |
| 747 | spin_unlock(&drv->dynids.lock); |
| 748 | |
| 749 | return driver_attach(&drv->driver); |
| 750 | } |
| 751 | |
| 752 | static void vmbus_free_dynids(struct hv_driver *drv) |
| 753 | { |
| 754 | struct vmbus_dynid *dynid, *n; |
| 755 | |
| 756 | spin_lock(&drv->dynids.lock); |
| 757 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { |
| 758 | list_del(&dynid->node); |
| 759 | kfree(dynid); |
| 760 | } |
| 761 | spin_unlock(&drv->dynids.lock); |
| 762 | } |
| 763 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 764 | /* |
| 765 | * store_new_id - sysfs frontend to vmbus_add_dynid() |
| 766 | * |
| 767 | * Allow GUIDs to be added to an existing driver via sysfs. |
| 768 | */ |
| 769 | static ssize_t new_id_store(struct device_driver *driver, const char *buf, |
| 770 | size_t count) |
| 771 | { |
| 772 | struct hv_driver *drv = drv_to_hv_drv(driver); |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 773 | guid_t guid; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 774 | ssize_t retval; |
| 775 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 776 | retval = guid_parse(buf, &guid); |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 777 | if (retval) |
| 778 | return retval; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 779 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 780 | if (hv_vmbus_dynid_match(drv, &guid)) |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 781 | return -EEXIST; |
| 782 | |
| 783 | retval = vmbus_add_dynid(drv, &guid); |
| 784 | if (retval) |
| 785 | return retval; |
| 786 | return count; |
| 787 | } |
| 788 | static DRIVER_ATTR_WO(new_id); |
| 789 | |
| 790 | /* |
| 791 | * store_remove_id - remove a PCI device ID from this driver |
| 792 | * |
| 793 | * Removes a dynamic pci device ID to this driver. |
| 794 | */ |
| 795 | static ssize_t remove_id_store(struct device_driver *driver, const char *buf, |
| 796 | size_t count) |
| 797 | { |
| 798 | struct hv_driver *drv = drv_to_hv_drv(driver); |
| 799 | struct vmbus_dynid *dynid, *n; |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 800 | guid_t guid; |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 801 | ssize_t retval; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 802 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 803 | retval = guid_parse(buf, &guid); |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 804 | if (retval) |
| 805 | return retval; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 806 | |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 807 | retval = -ENODEV; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 808 | spin_lock(&drv->dynids.lock); |
| 809 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { |
| 810 | struct hv_vmbus_device_id *id = &dynid->id; |
| 811 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 812 | if (guid_equal(&id->guid, &guid)) { |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 813 | list_del(&dynid->node); |
| 814 | kfree(dynid); |
| 815 | retval = count; |
| 816 | break; |
| 817 | } |
| 818 | } |
| 819 | spin_unlock(&drv->dynids.lock); |
| 820 | |
| 821 | return retval; |
| 822 | } |
| 823 | static DRIVER_ATTR_WO(remove_id); |
| 824 | |
| 825 | static struct attribute *vmbus_drv_attrs[] = { |
| 826 | &driver_attr_new_id.attr, |
| 827 | &driver_attr_remove_id.attr, |
| 828 | NULL, |
| 829 | }; |
| 830 | ATTRIBUTE_GROUPS(vmbus_drv); |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 831 | |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 832 | |
| 833 | /* |
| 834 | * vmbus_match - Attempt to match the specified device to the specified driver |
| 835 | */ |
| 836 | static int vmbus_match(struct device *device, struct device_driver *driver) |
| 837 | { |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 838 | struct hv_driver *drv = drv_to_hv_drv(driver); |
K. Y. Srinivasan | e8e2704 | 2011-06-06 15:50:04 -0700 | [diff] [blame] | 839 | struct hv_device *hv_dev = device_to_hv_device(device); |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 840 | |
Dexuan Cui | 8981da3 | 2016-01-27 22:29:41 -0800 | [diff] [blame] | 841 | /* The hv_sock driver handles all hv_sock offers. */ |
| 842 | if (is_hvsock_channel(hv_dev->channel)) |
| 843 | return drv->hvsock; |
| 844 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 845 | if (hv_vmbus_get_id(drv, hv_dev)) |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 846 | return 1; |
K. Y. Srinivasan | de632a2b | 2011-04-26 09:20:24 -0700 | [diff] [blame] | 847 | |
K. Y. Srinivasan | 5841a82 | 2011-08-25 09:48:39 -0700 | [diff] [blame] | 848 | return 0; |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 849 | } |
| 850 | |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 851 | /* |
| 852 | * vmbus_probe - Add the new vmbus's child device |
| 853 | */ |
| 854 | static int vmbus_probe(struct device *child_device) |
| 855 | { |
| 856 | int ret = 0; |
| 857 | struct hv_driver *drv = |
| 858 | drv_to_hv_drv(child_device->driver); |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 859 | struct hv_device *dev = device_to_hv_device(child_device); |
K. Y. Srinivasan | 8494689 | 2011-09-13 10:59:38 -0700 | [diff] [blame] | 860 | const struct hv_vmbus_device_id *dev_id; |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 861 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 862 | dev_id = hv_vmbus_get_id(drv, dev); |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 863 | if (drv->probe) { |
K. Y. Srinivasan | 8494689 | 2011-09-13 10:59:38 -0700 | [diff] [blame] | 864 | ret = drv->probe(dev, dev_id); |
K. Y. Srinivasan | b14a7b3 | 2011-04-29 13:45:03 -0700 | [diff] [blame] | 865 | if (ret != 0) |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 866 | pr_err("probe failed for device %s (%d)\n", |
| 867 | dev_name(child_device), ret); |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 868 | |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 869 | } else { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 870 | pr_err("probe not set for driver %s\n", |
| 871 | dev_name(child_device)); |
K. Y. Srinivasan | 6de925b | 2011-06-06 15:50:07 -0700 | [diff] [blame] | 872 | ret = -ENODEV; |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 873 | } |
| 874 | return ret; |
| 875 | } |
| 876 | |
K. Y. Srinivasan | c5dce3d | 2011-03-15 15:03:40 -0700 | [diff] [blame] | 877 | /* |
| 878 | * vmbus_remove - Remove a vmbus device |
| 879 | */ |
| 880 | static int vmbus_remove(struct device *child_device) |
| 881 | { |
K. Y. Srinivasan | d15a030 | 2015-02-28 11:18:16 -0800 | [diff] [blame] | 882 | struct hv_driver *drv; |
K. Y. Srinivasan | 415b023 | 2011-04-29 13:45:12 -0700 | [diff] [blame] | 883 | struct hv_device *dev = device_to_hv_device(child_device); |
K. Y. Srinivasan | c5dce3d | 2011-03-15 15:03:40 -0700 | [diff] [blame] | 884 | |
K. Y. Srinivasan | d15a030 | 2015-02-28 11:18:16 -0800 | [diff] [blame] | 885 | if (child_device->driver) { |
| 886 | drv = drv_to_hv_drv(child_device->driver); |
| 887 | if (drv->remove) |
| 888 | drv->remove(dev); |
K. Y. Srinivasan | d15a030 | 2015-02-28 11:18:16 -0800 | [diff] [blame] | 889 | } |
K. Y. Srinivasan | c5dce3d | 2011-03-15 15:03:40 -0700 | [diff] [blame] | 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
K. Y. Srinivasan | eb1bb25 | 2011-03-15 15:03:41 -0700 | [diff] [blame] | 894 | |
| 895 | /* |
| 896 | * vmbus_shutdown - Shutdown a vmbus device |
| 897 | */ |
| 898 | static void vmbus_shutdown(struct device *child_device) |
| 899 | { |
| 900 | struct hv_driver *drv; |
K. Y. Srinivasan | ca6887f | 2011-04-29 13:45:14 -0700 | [diff] [blame] | 901 | struct hv_device *dev = device_to_hv_device(child_device); |
K. Y. Srinivasan | eb1bb25 | 2011-03-15 15:03:41 -0700 | [diff] [blame] | 902 | |
| 903 | |
| 904 | /* The device may not be attached yet */ |
| 905 | if (!child_device->driver) |
| 906 | return; |
| 907 | |
| 908 | drv = drv_to_hv_drv(child_device->driver); |
| 909 | |
K. Y. Srinivasan | ca6887f | 2011-04-29 13:45:14 -0700 | [diff] [blame] | 910 | if (drv->shutdown) |
| 911 | drv->shutdown(dev); |
K. Y. Srinivasan | eb1bb25 | 2011-03-15 15:03:41 -0700 | [diff] [blame] | 912 | } |
| 913 | |
K. Y. Srinivasan | 086e7a5 | 2011-03-15 15:03:42 -0700 | [diff] [blame] | 914 | |
| 915 | /* |
| 916 | * vmbus_device_release - Final callback release of the vmbus child device |
| 917 | */ |
| 918 | static void vmbus_device_release(struct device *device) |
| 919 | { |
K. Y. Srinivasan | e8e2704 | 2011-06-06 15:50:04 -0700 | [diff] [blame] | 920 | struct hv_device *hv_dev = device_to_hv_device(device); |
Dexuan Cui | 34c6801 | 2015-12-14 16:01:49 -0800 | [diff] [blame] | 921 | struct vmbus_channel *channel = hv_dev->channel; |
K. Y. Srinivasan | 086e7a5 | 2011-03-15 15:03:42 -0700 | [diff] [blame] | 922 | |
K. Y. Srinivasan | 54a66265 | 2017-04-30 16:21:18 -0700 | [diff] [blame] | 923 | mutex_lock(&vmbus_connection.channel_mutex); |
Stephen Hemminger | 800b932 | 2018-09-14 09:10:15 -0700 | [diff] [blame] | 924 | hv_process_channel_removal(channel); |
K. Y. Srinivasan | 54a66265 | 2017-04-30 16:21:18 -0700 | [diff] [blame] | 925 | mutex_unlock(&vmbus_connection.channel_mutex); |
K. Y. Srinivasan | e8e2704 | 2011-06-06 15:50:04 -0700 | [diff] [blame] | 926 | kfree(hv_dev); |
K. Y. Srinivasan | 086e7a5 | 2011-03-15 15:03:42 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 929 | /* The one and only one */ |
K. Y. Srinivasan | 9adcac5 | 2011-04-29 13:45:08 -0700 | [diff] [blame] | 930 | static struct bus_type hv_bus = { |
| 931 | .name = "vmbus", |
| 932 | .match = vmbus_match, |
| 933 | .shutdown = vmbus_shutdown, |
| 934 | .remove = vmbus_remove, |
| 935 | .probe = vmbus_probe, |
| 936 | .uevent = vmbus_uevent, |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 937 | .dev_groups = vmbus_dev_groups, |
| 938 | .drv_groups = vmbus_drv_groups, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 939 | }; |
| 940 | |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 941 | struct onmessage_work_context { |
| 942 | struct work_struct work; |
| 943 | struct hv_message msg; |
| 944 | }; |
| 945 | |
| 946 | static void vmbus_onmessage_work(struct work_struct *work) |
| 947 | { |
| 948 | struct onmessage_work_context *ctx; |
| 949 | |
Vitaly Kuznetsov | 09a1962 | 2015-02-27 11:25:54 -0800 | [diff] [blame] | 950 | /* Do not process messages if we're in DISCONNECTED state */ |
| 951 | if (vmbus_connection.conn_state == DISCONNECTED) |
| 952 | return; |
| 953 | |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 954 | ctx = container_of(work, struct onmessage_work_context, |
| 955 | work); |
| 956 | vmbus_onmessage(&ctx->msg); |
| 957 | kfree(ctx); |
| 958 | } |
| 959 | |
K. Y. Srinivasan | d81274a | 2016-02-26 15:13:21 -0800 | [diff] [blame] | 960 | void vmbus_on_msg_dpc(unsigned long data) |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 961 | { |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 962 | struct hv_per_cpu_context *hv_cpu = (void *)data; |
| 963 | void *page_addr = hv_cpu->synic_message_page; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 964 | struct hv_message *msg = (struct hv_message *)page_addr + |
| 965 | VMBUS_MESSAGE_SINT; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 966 | struct vmbus_channel_message_header *hdr; |
Stephen Hemminger | e6242fa | 2017-03-04 18:27:16 -0700 | [diff] [blame] | 967 | const struct vmbus_channel_message_table_entry *entry; |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 968 | struct onmessage_work_context *ctx; |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 969 | u32 message_type = msg->header.message_type; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 970 | |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 971 | if (message_type == HVMSG_NONE) |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 972 | /* no msg */ |
| 973 | return; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 974 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 975 | hdr = (struct vmbus_channel_message_header *)msg->u.payload; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 976 | |
Vitaly Kuznetsov | c9fe0f8 | 2017-10-29 12:21:00 -0700 | [diff] [blame] | 977 | trace_vmbus_on_msg_dpc(hdr); |
| 978 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 979 | if (hdr->msgtype >= CHANNELMSG_COUNT) { |
| 980 | WARN_ONCE(1, "unknown msgtype=%d\n", hdr->msgtype); |
| 981 | goto msg_handled; |
| 982 | } |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 983 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 984 | entry = &channel_message_table[hdr->msgtype]; |
| 985 | if (entry->handler_type == VMHT_BLOCKING) { |
| 986 | ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC); |
| 987 | if (ctx == NULL) |
| 988 | return; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 989 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 990 | INIT_WORK(&ctx->work, vmbus_onmessage_work); |
| 991 | memcpy(&ctx->msg, msg, sizeof(*msg)); |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 992 | |
K. Y. Srinivasan | 54a66265 | 2017-04-30 16:21:18 -0700 | [diff] [blame] | 993 | /* |
| 994 | * The host can generate a rescind message while we |
| 995 | * may still be handling the original offer. We deal with |
| 996 | * this condition by ensuring the processing is done on the |
| 997 | * same CPU. |
| 998 | */ |
| 999 | switch (hdr->msgtype) { |
| 1000 | case CHANNELMSG_RESCIND_CHANNELOFFER: |
| 1001 | /* |
| 1002 | * If we are handling the rescind message; |
| 1003 | * schedule the work on the global work queue. |
| 1004 | */ |
| 1005 | schedule_work_on(vmbus_connection.connect_cpu, |
| 1006 | &ctx->work); |
| 1007 | break; |
| 1008 | |
| 1009 | case CHANNELMSG_OFFERCHANNEL: |
| 1010 | atomic_inc(&vmbus_connection.offer_in_progress); |
| 1011 | queue_work_on(vmbus_connection.connect_cpu, |
| 1012 | vmbus_connection.work_queue, |
| 1013 | &ctx->work); |
| 1014 | break; |
| 1015 | |
| 1016 | default: |
| 1017 | queue_work(vmbus_connection.work_queue, &ctx->work); |
| 1018 | } |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1019 | } else |
| 1020 | entry->message_handler(hdr); |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1021 | |
| 1022 | msg_handled: |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 1023 | vmbus_signal_eom(msg, message_type); |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1024 | } |
| 1025 | |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1026 | |
| 1027 | /* |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1028 | * Direct callback for channels using other deferred processing |
| 1029 | */ |
| 1030 | static void vmbus_channel_isr(struct vmbus_channel *channel) |
| 1031 | { |
| 1032 | void (*callback_fn)(void *); |
| 1033 | |
| 1034 | callback_fn = READ_ONCE(channel->onchannel_callback); |
| 1035 | if (likely(callback_fn != NULL)) |
| 1036 | (*callback_fn)(channel->channel_callback_context); |
| 1037 | } |
| 1038 | |
| 1039 | /* |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1040 | * Schedule all channels with events pending |
| 1041 | */ |
| 1042 | static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu) |
| 1043 | { |
| 1044 | unsigned long *recv_int_page; |
| 1045 | u32 maxbits, relid; |
| 1046 | |
| 1047 | if (vmbus_proto_version < VERSION_WIN8) { |
| 1048 | maxbits = MAX_NUM_CHANNELS_SUPPORTED; |
| 1049 | recv_int_page = vmbus_connection.recv_int_page; |
| 1050 | } else { |
| 1051 | /* |
| 1052 | * When the host is win8 and beyond, the event page |
| 1053 | * can be directly checked to get the id of the channel |
| 1054 | * that has the interrupt pending. |
| 1055 | */ |
| 1056 | void *page_addr = hv_cpu->synic_event_page; |
| 1057 | union hv_synic_event_flags *event |
| 1058 | = (union hv_synic_event_flags *)page_addr + |
| 1059 | VMBUS_MESSAGE_SINT; |
| 1060 | |
| 1061 | maxbits = HV_EVENT_FLAGS_COUNT; |
| 1062 | recv_int_page = event->flags; |
| 1063 | } |
| 1064 | |
| 1065 | if (unlikely(!recv_int_page)) |
| 1066 | return; |
| 1067 | |
| 1068 | for_each_set_bit(relid, recv_int_page, maxbits) { |
| 1069 | struct vmbus_channel *channel; |
| 1070 | |
| 1071 | if (!sync_test_and_clear_bit(relid, recv_int_page)) |
| 1072 | continue; |
| 1073 | |
| 1074 | /* Special case - vmbus channel protocol msg */ |
| 1075 | if (relid == 0) |
| 1076 | continue; |
| 1077 | |
Stephen Hemminger | 8200f20 | 2017-03-04 18:13:57 -0700 | [diff] [blame] | 1078 | rcu_read_lock(); |
| 1079 | |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1080 | /* Find channel based on relid */ |
Stephen Hemminger | 8200f20 | 2017-03-04 18:13:57 -0700 | [diff] [blame] | 1081 | list_for_each_entry_rcu(channel, &hv_cpu->chan_list, percpu_list) { |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1082 | if (channel->offermsg.child_relid != relid) |
| 1083 | continue; |
| 1084 | |
K. Y. Srinivasan | 6f3d791 | 2017-08-11 10:03:59 -0700 | [diff] [blame] | 1085 | if (channel->rescind) |
| 1086 | continue; |
| 1087 | |
Vitaly Kuznetsov | 991f8f1 | 2017-10-29 12:21:16 -0700 | [diff] [blame] | 1088 | trace_vmbus_chan_sched(channel); |
| 1089 | |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1090 | ++channel->interrupts; |
| 1091 | |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1092 | switch (channel->callback_mode) { |
| 1093 | case HV_CALL_ISR: |
| 1094 | vmbus_channel_isr(channel); |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1095 | break; |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1096 | |
| 1097 | case HV_CALL_BATCHED: |
| 1098 | hv_begin_read(&channel->inbound); |
| 1099 | /* fallthrough */ |
| 1100 | case HV_CALL_DIRECT: |
| 1101 | tasklet_schedule(&channel->callback_event); |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1102 | } |
| 1103 | } |
Stephen Hemminger | 8200f20 | 2017-03-04 18:13:57 -0700 | [diff] [blame] | 1104 | |
| 1105 | rcu_read_unlock(); |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1109 | static void vmbus_isr(void) |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1110 | { |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1111 | struct hv_per_cpu_context *hv_cpu |
| 1112 | = this_cpu_ptr(hv_context.cpu_context); |
| 1113 | void *page_addr = hv_cpu->synic_event_page; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1114 | struct hv_message *msg; |
| 1115 | union hv_synic_event_flags *event; |
K. Y. Srinivasan | ae4636e | 2011-08-27 11:31:35 -0700 | [diff] [blame] | 1116 | bool handled = false; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1117 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1118 | if (unlikely(page_addr == NULL)) |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1119 | return; |
K. Y. Srinivasan | 5ab0595 | 2012-12-01 06:46:55 -0800 | [diff] [blame] | 1120 | |
| 1121 | event = (union hv_synic_event_flags *)page_addr + |
| 1122 | VMBUS_MESSAGE_SINT; |
K. Y. Srinivasan | 7341d90 | 2011-08-31 14:35:56 -0700 | [diff] [blame] | 1123 | /* |
| 1124 | * Check for events before checking for messages. This is the order |
| 1125 | * in which events and messages are checked in Windows guests on |
| 1126 | * Hyper-V, and the Windows team suggested we do the same. |
| 1127 | */ |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1128 | |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1129 | if ((vmbus_proto_version == VERSION_WS2008) || |
| 1130 | (vmbus_proto_version == VERSION_WIN7)) { |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1131 | |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1132 | /* Since we are a child, we only need to check bit 0 */ |
Stephen Hemminger | 5c1bec6 | 2017-02-05 17:20:31 -0700 | [diff] [blame] | 1133 | if (sync_test_and_clear_bit(0, event->flags)) |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1134 | handled = true; |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1135 | } else { |
| 1136 | /* |
| 1137 | * Our host is win8 or above. The signaling mechanism |
| 1138 | * has changed and we can directly look at the event page. |
| 1139 | * If bit n is set then we have an interrup on the channel |
| 1140 | * whose id is n. |
| 1141 | */ |
K. Y. Srinivasan | ae4636e | 2011-08-27 11:31:35 -0700 | [diff] [blame] | 1142 | handled = true; |
K. Y. Srinivasan | 793be9c | 2011-03-15 15:03:43 -0700 | [diff] [blame] | 1143 | } |
K. Y. Srinivasan | ae4636e | 2011-08-27 11:31:35 -0700 | [diff] [blame] | 1144 | |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1145 | if (handled) |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1146 | vmbus_chan_sched(hv_cpu); |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1147 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1148 | page_addr = hv_cpu->synic_message_page; |
K. Y. Srinivasan | 7341d90 | 2011-08-31 14:35:56 -0700 | [diff] [blame] | 1149 | msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; |
| 1150 | |
| 1151 | /* Check if there are actual msgs to be processed */ |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 1152 | if (msg->header.message_type != HVMSG_NONE) { |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1153 | if (msg->header.message_type == HVMSG_TIMER_EXPIRED) { |
| 1154 | hv_stimer0_isr(); |
| 1155 | vmbus_signal_eom(msg, HVMSG_TIMER_EXPIRED); |
| 1156 | } else |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1157 | tasklet_schedule(&hv_cpu->msg_dpc); |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 1158 | } |
Stephan Mueller | 4b44f2d | 2016-05-02 02:14:34 -0400 | [diff] [blame] | 1159 | |
| 1160 | add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0); |
K. Y. Srinivasan | 793be9c | 2011-03-15 15:03:43 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1163 | /* |
| 1164 | * Boolean to control whether to report panic messages over Hyper-V. |
| 1165 | * |
| 1166 | * It can be set via /proc/sys/kernel/hyperv/record_panic_msg |
| 1167 | */ |
| 1168 | static int sysctl_record_panic_msg = 1; |
| 1169 | |
| 1170 | /* |
| 1171 | * Callback from kmsg_dump. Grab as much as possible from the end of the kmsg |
| 1172 | * buffer and call into Hyper-V to transfer the data. |
| 1173 | */ |
| 1174 | static void hv_kmsg_dump(struct kmsg_dumper *dumper, |
| 1175 | enum kmsg_dump_reason reason) |
| 1176 | { |
| 1177 | size_t bytes_written; |
| 1178 | phys_addr_t panic_pa; |
| 1179 | |
| 1180 | /* We are only interested in panics. */ |
| 1181 | if ((reason != KMSG_DUMP_PANIC) || (!sysctl_record_panic_msg)) |
| 1182 | return; |
| 1183 | |
| 1184 | panic_pa = virt_to_phys(hv_panic_page); |
| 1185 | |
| 1186 | /* |
| 1187 | * Write dump contents to the page. No need to synchronize; panic should |
| 1188 | * be single-threaded. |
| 1189 | */ |
Sunil Muthuswamy | ddcaf3c | 2018-07-28 21:58:45 +0000 | [diff] [blame] | 1190 | kmsg_dump_get_buffer(dumper, true, hv_panic_page, PAGE_SIZE, |
| 1191 | &bytes_written); |
| 1192 | if (bytes_written) |
| 1193 | hyperv_report_panic_msg(panic_pa, bytes_written); |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | static struct kmsg_dumper hv_kmsg_dumper = { |
| 1197 | .dump = hv_kmsg_dump, |
| 1198 | }; |
| 1199 | |
| 1200 | static struct ctl_table_header *hv_ctl_table_hdr; |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1201 | |
| 1202 | /* |
| 1203 | * sysctl option to allow the user to control whether kmsg data should be |
| 1204 | * reported to Hyper-V on panic. |
| 1205 | */ |
| 1206 | static struct ctl_table hv_ctl_table[] = { |
| 1207 | { |
| 1208 | .procname = "hyperv_record_panic_msg", |
| 1209 | .data = &sysctl_record_panic_msg, |
| 1210 | .maxlen = sizeof(int), |
| 1211 | .mode = 0644, |
| 1212 | .proc_handler = proc_dointvec_minmax, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 1213 | .extra1 = SYSCTL_ZERO, |
| 1214 | .extra2 = SYSCTL_ONE |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1215 | }, |
| 1216 | {} |
| 1217 | }; |
| 1218 | |
| 1219 | static struct ctl_table hv_root_table[] = { |
| 1220 | { |
| 1221 | .procname = "kernel", |
| 1222 | .mode = 0555, |
| 1223 | .child = hv_ctl_table |
| 1224 | }, |
| 1225 | {} |
| 1226 | }; |
Vitaly Kuznetsov | e513229 | 2015-02-27 11:25:51 -0800 | [diff] [blame] | 1227 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1228 | /* |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1229 | * vmbus_bus_init -Main vmbus driver initialization routine. |
| 1230 | * |
| 1231 | * Here, we |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 1232 | * - initialize the vmbus driver context |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 1233 | * - invoke the vmbus hv main init routine |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 1234 | * - retrieve the channel offers |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1235 | */ |
K. Y. Srinivasan | efc2672 | 2015-12-14 16:01:46 -0800 | [diff] [blame] | 1236 | static int vmbus_bus_init(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1237 | { |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1238 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1239 | |
Greg Kroah-Hartman | 6d26e38fa2 | 2010-12-02 12:08:08 -0800 | [diff] [blame] | 1240 | /* Hypervisor initialization...setup hypercall page..etc */ |
| 1241 | ret = hv_init(); |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1242 | if (ret != 0) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1243 | pr_err("Unable to initialize the hypervisor - 0x%x\n", ret); |
K. Y. Srinivasan | d6c1c5d | 2011-06-06 15:50:08 -0700 | [diff] [blame] | 1244 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
K. Y. Srinivasan | 9adcac5 | 2011-04-29 13:45:08 -0700 | [diff] [blame] | 1247 | ret = bus_register(&hv_bus); |
K. Y. Srinivasan | d6c1c5d | 2011-06-06 15:50:08 -0700 | [diff] [blame] | 1248 | if (ret) |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 1249 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1250 | |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1251 | hv_setup_vmbus_irq(vmbus_isr); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1252 | |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 1253 | ret = hv_synic_alloc(); |
| 1254 | if (ret) |
| 1255 | goto err_alloc; |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1256 | |
| 1257 | ret = hv_stimer_alloc(VMBUS_MESSAGE_SINT); |
| 1258 | if (ret < 0) |
| 1259 | goto err_alloc; |
| 1260 | |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1261 | /* |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1262 | * Initialize the per-cpu interrupt state and stimer state. |
| 1263 | * Then connect to the host. |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1264 | */ |
Michael Kelley | 4a5f3cd | 2017-12-22 11:19:02 -0700 | [diff] [blame] | 1265 | ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hyperv/vmbus:online", |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 1266 | hv_synic_init, hv_synic_cleanup); |
| 1267 | if (ret < 0) |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1268 | goto err_cpuhp; |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 1269 | hyperv_cpuhp_online = ret; |
| 1270 | |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1271 | ret = vmbus_connect(); |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1272 | if (ret) |
Andrey Smetanin | 17efbee | 2015-12-14 16:01:38 -0800 | [diff] [blame] | 1273 | goto err_connect; |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1274 | |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 1275 | /* |
| 1276 | * Only register if the crash MSRs are available |
| 1277 | */ |
Denis V. Lunev | cc2dd40 | 2015-08-01 16:08:20 -0700 | [diff] [blame] | 1278 | if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) { |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1279 | u64 hyperv_crash_ctl; |
| 1280 | /* |
| 1281 | * Sysctl registration is not fatal, since by default |
| 1282 | * reporting is enabled. |
| 1283 | */ |
| 1284 | hv_ctl_table_hdr = register_sysctl_table(hv_root_table); |
| 1285 | if (!hv_ctl_table_hdr) |
| 1286 | pr_err("Hyper-V: sysctl table register error"); |
| 1287 | |
| 1288 | /* |
| 1289 | * Register for panic kmsg callback only if the right |
| 1290 | * capability is supported by the hypervisor. |
| 1291 | */ |
Sunil Muthuswamy | 9d9c965 | 2018-07-28 21:58:47 +0000 | [diff] [blame] | 1292 | hv_get_crash_ctl(hyperv_crash_ctl); |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1293 | if (hyperv_crash_ctl & HV_CRASH_CTL_CRASH_NOTIFY_MSG) { |
| 1294 | hv_panic_page = (void *)get_zeroed_page(GFP_KERNEL); |
| 1295 | if (hv_panic_page) { |
| 1296 | ret = kmsg_dump_register(&hv_kmsg_dumper); |
| 1297 | if (ret) |
| 1298 | pr_err("Hyper-V: kmsg dump register " |
| 1299 | "error 0x%x\n", ret); |
| 1300 | } else |
| 1301 | pr_err("Hyper-V: panic message page memory " |
| 1302 | "allocation failed"); |
| 1303 | } |
| 1304 | |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 1305 | register_die_notifier(&hyperv_die_block); |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 1306 | atomic_notifier_chain_register(&panic_notifier_list, |
| 1307 | &hyperv_panic_block); |
| 1308 | } |
| 1309 | |
Greg Kroah-Hartman | 2d6e882 | 2010-12-02 08:50:58 -0800 | [diff] [blame] | 1310 | vmbus_request_offers(); |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 1311 | |
K. Y. Srinivasan | d6c1c5d | 2011-06-06 15:50:08 -0700 | [diff] [blame] | 1312 | return 0; |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1313 | |
Andrey Smetanin | 17efbee | 2015-12-14 16:01:38 -0800 | [diff] [blame] | 1314 | err_connect: |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 1315 | cpuhp_remove_state(hyperv_cpuhp_online); |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1316 | err_cpuhp: |
| 1317 | hv_stimer_free(); |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 1318 | err_alloc: |
| 1319 | hv_synic_free(); |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1320 | hv_remove_vmbus_irq(); |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1321 | |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1322 | bus_unregister(&hv_bus); |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1323 | free_page((unsigned long)hv_panic_page); |
Sunil Muthuswamy | 8afc06d | 2018-07-28 21:58:46 +0000 | [diff] [blame] | 1324 | unregister_sysctl_table(hv_ctl_table_hdr); |
| 1325 | hv_ctl_table_hdr = NULL; |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1326 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1329 | /** |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1330 | * __vmbus_child_driver_register() - Register a vmbus's driver |
| 1331 | * @hv_driver: Pointer to driver structure you want to register |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1332 | * @owner: owner module of the drv |
| 1333 | * @mod_name: module name string |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1334 | * |
| 1335 | * Registers the given driver with Linux through the 'driver_register()' call |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1336 | * and sets up the hyper-v vmbus handling for this driver. |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1337 | * It will return the state of the 'driver_register()' call. |
| 1338 | * |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1339 | */ |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1340 | int __vmbus_driver_register(struct hv_driver *hv_driver, struct module *owner, const char *mod_name) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1341 | { |
Bill Pemberton | 5d48a1c | 2009-07-27 16:47:36 -0400 | [diff] [blame] | 1342 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1343 | |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1344 | pr_info("registering driver %s\n", hv_driver->name); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1345 | |
K. Y. Srinivasan | cf6a2ea | 2011-12-01 09:59:34 -0800 | [diff] [blame] | 1346 | ret = vmbus_exists(); |
| 1347 | if (ret < 0) |
| 1348 | return ret; |
| 1349 | |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1350 | hv_driver->driver.name = hv_driver->name; |
| 1351 | hv_driver->driver.owner = owner; |
| 1352 | hv_driver->driver.mod_name = mod_name; |
| 1353 | hv_driver->driver.bus = &hv_bus; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1354 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1355 | spin_lock_init(&hv_driver->dynids.lock); |
| 1356 | INIT_LIST_HEAD(&hv_driver->dynids.list); |
| 1357 | |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1358 | ret = driver_register(&hv_driver->driver); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1359 | |
Bill Pemberton | 5d48a1c | 2009-07-27 16:47:36 -0400 | [diff] [blame] | 1360 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1361 | } |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1362 | EXPORT_SYMBOL_GPL(__vmbus_driver_register); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1363 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1364 | /** |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1365 | * vmbus_driver_unregister() - Unregister a vmbus's driver |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1366 | * @hv_driver: Pointer to driver structure you want to |
| 1367 | * un-register |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1368 | * |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1369 | * Un-register the given driver that was previous registered with a call to |
| 1370 | * vmbus_driver_register() |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1371 | */ |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1372 | void vmbus_driver_unregister(struct hv_driver *hv_driver) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1373 | { |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1374 | pr_info("unregistering driver %s\n", hv_driver->name); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1375 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1376 | if (!vmbus_exists()) { |
K. Y. Srinivasan | 8f257a1 | 2011-12-27 13:49:37 -0800 | [diff] [blame] | 1377 | driver_unregister(&hv_driver->driver); |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1378 | vmbus_free_dynids(hv_driver); |
| 1379 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1380 | } |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1381 | EXPORT_SYMBOL_GPL(vmbus_driver_unregister); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1382 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1383 | |
| 1384 | /* |
| 1385 | * Called when last reference to channel is gone. |
| 1386 | */ |
| 1387 | static void vmbus_chan_release(struct kobject *kobj) |
| 1388 | { |
| 1389 | struct vmbus_channel *channel |
| 1390 | = container_of(kobj, struct vmbus_channel, kobj); |
| 1391 | |
| 1392 | kfree_rcu(channel, rcu); |
| 1393 | } |
| 1394 | |
| 1395 | struct vmbus_chan_attribute { |
| 1396 | struct attribute attr; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1397 | ssize_t (*show)(struct vmbus_channel *chan, char *buf); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1398 | ssize_t (*store)(struct vmbus_channel *chan, |
| 1399 | const char *buf, size_t count); |
| 1400 | }; |
| 1401 | #define VMBUS_CHAN_ATTR(_name, _mode, _show, _store) \ |
| 1402 | struct vmbus_chan_attribute chan_attr_##_name \ |
| 1403 | = __ATTR(_name, _mode, _show, _store) |
| 1404 | #define VMBUS_CHAN_ATTR_RW(_name) \ |
| 1405 | struct vmbus_chan_attribute chan_attr_##_name = __ATTR_RW(_name) |
| 1406 | #define VMBUS_CHAN_ATTR_RO(_name) \ |
| 1407 | struct vmbus_chan_attribute chan_attr_##_name = __ATTR_RO(_name) |
| 1408 | #define VMBUS_CHAN_ATTR_WO(_name) \ |
| 1409 | struct vmbus_chan_attribute chan_attr_##_name = __ATTR_WO(_name) |
| 1410 | |
| 1411 | static ssize_t vmbus_chan_attr_show(struct kobject *kobj, |
| 1412 | struct attribute *attr, char *buf) |
| 1413 | { |
| 1414 | const struct vmbus_chan_attribute *attribute |
| 1415 | = container_of(attr, struct vmbus_chan_attribute, attr); |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1416 | struct vmbus_channel *chan |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1417 | = container_of(kobj, struct vmbus_channel, kobj); |
| 1418 | |
| 1419 | if (!attribute->show) |
| 1420 | return -EIO; |
| 1421 | |
| 1422 | return attribute->show(chan, buf); |
| 1423 | } |
| 1424 | |
| 1425 | static const struct sysfs_ops vmbus_chan_sysfs_ops = { |
| 1426 | .show = vmbus_chan_attr_show, |
| 1427 | }; |
| 1428 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1429 | static ssize_t out_mask_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1430 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1431 | struct hv_ring_buffer_info *rbi = &channel->outbound; |
| 1432 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1433 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1434 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1435 | if (!rbi->ring_buffer) { |
| 1436 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1437 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1438 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1439 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1440 | ret = sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); |
| 1441 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1442 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1443 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1444 | static VMBUS_CHAN_ATTR_RO(out_mask); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1445 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1446 | static ssize_t in_mask_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1447 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1448 | struct hv_ring_buffer_info *rbi = &channel->inbound; |
| 1449 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1450 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1451 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1452 | if (!rbi->ring_buffer) { |
| 1453 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1454 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1455 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1456 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1457 | ret = sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); |
| 1458 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1459 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1460 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1461 | static VMBUS_CHAN_ATTR_RO(in_mask); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1462 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1463 | static ssize_t read_avail_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1464 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1465 | struct hv_ring_buffer_info *rbi = &channel->inbound; |
| 1466 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1467 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1468 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1469 | if (!rbi->ring_buffer) { |
| 1470 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1471 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1472 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1473 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1474 | ret = sprintf(buf, "%u\n", hv_get_bytes_to_read(rbi)); |
| 1475 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1476 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1477 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1478 | static VMBUS_CHAN_ATTR_RO(read_avail); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1479 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1480 | static ssize_t write_avail_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1481 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1482 | struct hv_ring_buffer_info *rbi = &channel->outbound; |
| 1483 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1484 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1485 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1486 | if (!rbi->ring_buffer) { |
| 1487 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1488 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1489 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1490 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1491 | ret = sprintf(buf, "%u\n", hv_get_bytes_to_write(rbi)); |
| 1492 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1493 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1494 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1495 | static VMBUS_CHAN_ATTR_RO(write_avail); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1496 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1497 | static ssize_t show_target_cpu(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1498 | { |
| 1499 | return sprintf(buf, "%u\n", channel->target_cpu); |
| 1500 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1501 | static VMBUS_CHAN_ATTR(cpu, S_IRUGO, show_target_cpu, NULL); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1502 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1503 | static ssize_t channel_pending_show(struct vmbus_channel *channel, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1504 | char *buf) |
| 1505 | { |
| 1506 | return sprintf(buf, "%d\n", |
| 1507 | channel_pending(channel, |
| 1508 | vmbus_connection.monitor_pages[1])); |
| 1509 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1510 | static VMBUS_CHAN_ATTR(pending, S_IRUGO, channel_pending_show, NULL); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1511 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1512 | static ssize_t channel_latency_show(struct vmbus_channel *channel, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1513 | char *buf) |
| 1514 | { |
| 1515 | return sprintf(buf, "%d\n", |
| 1516 | channel_latency(channel, |
| 1517 | vmbus_connection.monitor_pages[1])); |
| 1518 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1519 | static VMBUS_CHAN_ATTR(latency, S_IRUGO, channel_latency_show, NULL); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1520 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1521 | static ssize_t channel_interrupts_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1522 | { |
| 1523 | return sprintf(buf, "%llu\n", channel->interrupts); |
| 1524 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1525 | static VMBUS_CHAN_ATTR(interrupts, S_IRUGO, channel_interrupts_show, NULL); |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1526 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1527 | static ssize_t channel_events_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1528 | { |
| 1529 | return sprintf(buf, "%llu\n", channel->sig_events); |
| 1530 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1531 | static VMBUS_CHAN_ATTR(events, S_IRUGO, channel_events_show, NULL); |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1532 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1533 | static ssize_t channel_intr_in_full_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1534 | char *buf) |
| 1535 | { |
| 1536 | return sprintf(buf, "%llu\n", |
| 1537 | (unsigned long long)channel->intr_in_full); |
| 1538 | } |
| 1539 | static VMBUS_CHAN_ATTR(intr_in_full, 0444, channel_intr_in_full_show, NULL); |
| 1540 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1541 | static ssize_t channel_intr_out_empty_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1542 | char *buf) |
| 1543 | { |
| 1544 | return sprintf(buf, "%llu\n", |
| 1545 | (unsigned long long)channel->intr_out_empty); |
| 1546 | } |
| 1547 | static VMBUS_CHAN_ATTR(intr_out_empty, 0444, channel_intr_out_empty_show, NULL); |
| 1548 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1549 | static ssize_t channel_out_full_first_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1550 | char *buf) |
| 1551 | { |
| 1552 | return sprintf(buf, "%llu\n", |
| 1553 | (unsigned long long)channel->out_full_first); |
| 1554 | } |
| 1555 | static VMBUS_CHAN_ATTR(out_full_first, 0444, channel_out_full_first_show, NULL); |
| 1556 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1557 | static ssize_t channel_out_full_total_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1558 | char *buf) |
| 1559 | { |
| 1560 | return sprintf(buf, "%llu\n", |
| 1561 | (unsigned long long)channel->out_full_total); |
| 1562 | } |
| 1563 | static VMBUS_CHAN_ATTR(out_full_total, 0444, channel_out_full_total_show, NULL); |
| 1564 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1565 | static ssize_t subchannel_monitor_id_show(struct vmbus_channel *channel, |
Stephen Hemminger | f0fa297 | 2018-01-09 10:29:06 -0800 | [diff] [blame] | 1566 | char *buf) |
| 1567 | { |
| 1568 | return sprintf(buf, "%u\n", channel->offermsg.monitorid); |
| 1569 | } |
| 1570 | static VMBUS_CHAN_ATTR(monitor_id, S_IRUGO, subchannel_monitor_id_show, NULL); |
| 1571 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1572 | static ssize_t subchannel_id_show(struct vmbus_channel *channel, |
Stephen Hemminger | f0fa297 | 2018-01-09 10:29:06 -0800 | [diff] [blame] | 1573 | char *buf) |
| 1574 | { |
| 1575 | return sprintf(buf, "%u\n", |
| 1576 | channel->offermsg.offer.sub_channel_index); |
| 1577 | } |
| 1578 | static VMBUS_CHAN_ATTR_RO(subchannel_id); |
| 1579 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1580 | static struct attribute *vmbus_chan_attrs[] = { |
| 1581 | &chan_attr_out_mask.attr, |
| 1582 | &chan_attr_in_mask.attr, |
| 1583 | &chan_attr_read_avail.attr, |
| 1584 | &chan_attr_write_avail.attr, |
| 1585 | &chan_attr_cpu.attr, |
| 1586 | &chan_attr_pending.attr, |
| 1587 | &chan_attr_latency.attr, |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1588 | &chan_attr_interrupts.attr, |
| 1589 | &chan_attr_events.attr, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1590 | &chan_attr_intr_in_full.attr, |
| 1591 | &chan_attr_intr_out_empty.attr, |
| 1592 | &chan_attr_out_full_first.attr, |
| 1593 | &chan_attr_out_full_total.attr, |
Stephen Hemminger | f0fa297 | 2018-01-09 10:29:06 -0800 | [diff] [blame] | 1594 | &chan_attr_monitor_id.attr, |
| 1595 | &chan_attr_subchannel_id.attr, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1596 | NULL |
| 1597 | }; |
| 1598 | |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1599 | /* |
| 1600 | * Channel-level attribute_group callback function. Returns the permission for |
| 1601 | * each attribute, and returns 0 if an attribute is not visible. |
| 1602 | */ |
| 1603 | static umode_t vmbus_chan_attr_is_visible(struct kobject *kobj, |
| 1604 | struct attribute *attr, int idx) |
| 1605 | { |
| 1606 | const struct vmbus_channel *channel = |
| 1607 | container_of(kobj, struct vmbus_channel, kobj); |
| 1608 | |
| 1609 | /* Hide the monitor attributes if the monitor mechanism is not used. */ |
| 1610 | if (!channel->offermsg.monitor_allocated && |
| 1611 | (attr == &chan_attr_pending.attr || |
| 1612 | attr == &chan_attr_latency.attr || |
| 1613 | attr == &chan_attr_monitor_id.attr)) |
| 1614 | return 0; |
| 1615 | |
| 1616 | return attr->mode; |
| 1617 | } |
| 1618 | |
| 1619 | static struct attribute_group vmbus_chan_group = { |
| 1620 | .attrs = vmbus_chan_attrs, |
| 1621 | .is_visible = vmbus_chan_attr_is_visible |
| 1622 | }; |
| 1623 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1624 | static struct kobj_type vmbus_chan_ktype = { |
| 1625 | .sysfs_ops = &vmbus_chan_sysfs_ops, |
| 1626 | .release = vmbus_chan_release, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1627 | }; |
| 1628 | |
| 1629 | /* |
| 1630 | * vmbus_add_channel_kobj - setup a sub-directory under device/channels |
| 1631 | */ |
| 1632 | int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) |
| 1633 | { |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1634 | const struct device *device = &dev->device; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1635 | struct kobject *kobj = &channel->kobj; |
| 1636 | u32 relid = channel->offermsg.child_relid; |
| 1637 | int ret; |
| 1638 | |
| 1639 | kobj->kset = dev->channels_kset; |
| 1640 | ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL, |
| 1641 | "%u", relid); |
| 1642 | if (ret) |
| 1643 | return ret; |
| 1644 | |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1645 | ret = sysfs_create_group(kobj, &vmbus_chan_group); |
| 1646 | |
| 1647 | if (ret) { |
| 1648 | /* |
| 1649 | * The calling functions' error handling paths will cleanup the |
| 1650 | * empty channel directory. |
| 1651 | */ |
| 1652 | dev_err(device, "Unable to set up channel sysfs files\n"); |
| 1653 | return ret; |
| 1654 | } |
| 1655 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1656 | kobject_uevent(kobj, KOBJ_ADD); |
| 1657 | |
| 1658 | return 0; |
| 1659 | } |
| 1660 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1661 | /* |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1662 | * vmbus_remove_channel_attr_group - remove the channel's attribute group |
| 1663 | */ |
| 1664 | void vmbus_remove_channel_attr_group(struct vmbus_channel *channel) |
| 1665 | { |
| 1666 | sysfs_remove_group(&channel->kobj, &vmbus_chan_group); |
| 1667 | } |
| 1668 | |
| 1669 | /* |
K. Y. Srinivasan | f2c7301 | 2011-09-08 07:24:12 -0700 | [diff] [blame] | 1670 | * vmbus_device_create - Creates and registers a new child device |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1671 | * on the vmbus. |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1672 | */ |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 1673 | struct hv_device *vmbus_device_create(const guid_t *type, |
| 1674 | const guid_t *instance, |
stephen hemminger | 1b9d48f | 2014-06-03 08:38:15 -0700 | [diff] [blame] | 1675 | struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1676 | { |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 1677 | struct hv_device *child_device_obj; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1678 | |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1679 | child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL); |
| 1680 | if (!child_device_obj) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1681 | pr_err("Unable to allocate device object for child device\n"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1682 | return NULL; |
| 1683 | } |
| 1684 | |
Greg Kroah-Hartman | cae5b84 | 2010-10-21 09:05:27 -0700 | [diff] [blame] | 1685 | child_device_obj->channel = channel; |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 1686 | guid_copy(&child_device_obj->dev_type, type); |
| 1687 | guid_copy(&child_device_obj->dev_instance, instance); |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 1688 | child_device_obj->vendor_id = 0x1414; /* MSFT vendor ID */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1689 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1690 | return child_device_obj; |
| 1691 | } |
| 1692 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1693 | /* |
K. Y. Srinivasan | 22794281 | 2011-09-08 07:24:13 -0700 | [diff] [blame] | 1694 | * vmbus_device_register - Register the child device |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1695 | */ |
K. Y. Srinivasan | 22794281 | 2011-09-08 07:24:13 -0700 | [diff] [blame] | 1696 | int vmbus_device_register(struct hv_device *child_device_obj) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1697 | { |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1698 | struct kobject *kobj = &child_device_obj->device.kobj; |
| 1699 | int ret; |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1700 | |
Stephen Hemminger | f6b2db0 | 2016-11-01 00:01:59 -0700 | [diff] [blame] | 1701 | dev_set_name(&child_device_obj->device, "%pUl", |
Vitaly Kuznetsov | b294809 | 2016-09-16 09:01:17 -0700 | [diff] [blame] | 1702 | child_device_obj->channel->offermsg.offer.if_instance.b); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1703 | |
K. Y. Srinivasan | 0bce28b | 2011-08-27 11:31:39 -0700 | [diff] [blame] | 1704 | child_device_obj->device.bus = &hv_bus; |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 1705 | child_device_obj->device.parent = &hv_acpi_dev->dev; |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1706 | child_device_obj->device.release = vmbus_device_release; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1707 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1708 | /* |
| 1709 | * Register with the LDM. This will kick off the driver/device |
| 1710 | * binding...which will eventually call vmbus_match() and vmbus_probe() |
| 1711 | */ |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1712 | ret = device_register(&child_device_obj->device); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1713 | if (ret) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1714 | pr_err("Unable to register child device\n"); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1715 | return ret; |
| 1716 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1717 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1718 | child_device_obj->channels_kset = kset_create_and_add("channels", |
| 1719 | NULL, kobj); |
| 1720 | if (!child_device_obj->channels_kset) { |
| 1721 | ret = -ENOMEM; |
| 1722 | goto err_dev_unregister; |
| 1723 | } |
| 1724 | |
| 1725 | ret = vmbus_add_channel_kobj(child_device_obj, |
| 1726 | child_device_obj->channel); |
| 1727 | if (ret) { |
| 1728 | pr_err("Unable to register primary channeln"); |
| 1729 | goto err_kset_unregister; |
| 1730 | } |
| 1731 | |
| 1732 | return 0; |
| 1733 | |
| 1734 | err_kset_unregister: |
| 1735 | kset_unregister(child_device_obj->channels_kset); |
| 1736 | |
| 1737 | err_dev_unregister: |
| 1738 | device_unregister(&child_device_obj->device); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1739 | return ret; |
| 1740 | } |
| 1741 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1742 | /* |
K. Y. Srinivasan | 696453b | 2011-09-08 07:24:14 -0700 | [diff] [blame] | 1743 | * vmbus_device_unregister - Remove the specified child device |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1744 | * from the vmbus. |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1745 | */ |
K. Y. Srinivasan | 696453b | 2011-09-08 07:24:14 -0700 | [diff] [blame] | 1746 | void vmbus_device_unregister(struct hv_device *device_obj) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1747 | { |
Fernando Soto | 8467236 | 2013-06-14 23:13:35 +0000 | [diff] [blame] | 1748 | pr_debug("child device %s unregistered\n", |
| 1749 | dev_name(&device_obj->device)); |
| 1750 | |
Dexuan Cui | 869b556 | 2017-11-14 06:53:32 -0700 | [diff] [blame] | 1751 | kset_unregister(device_obj->channels_kset); |
| 1752 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1753 | /* |
| 1754 | * Kick off the process of unregistering the device. |
| 1755 | * This will call vmbus_remove() and eventually vmbus_device_release() |
| 1756 | */ |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1757 | device_unregister(&device_obj->device); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1760 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1761 | /* |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1762 | * VMBUS is an acpi enumerated device. Get the information we |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1763 | * need from DSDT. |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1764 | */ |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1765 | #define VTPM_BASE_ADDRESS 0xfed40000 |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1766 | static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx) |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1767 | { |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1768 | resource_size_t start = 0; |
| 1769 | resource_size_t end = 0; |
| 1770 | struct resource *new_res; |
| 1771 | struct resource **old_res = &hyperv_mmio; |
| 1772 | struct resource **prev_res = NULL; |
| 1773 | |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1774 | switch (res->type) { |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1775 | |
| 1776 | /* |
| 1777 | * "Address" descriptors are for bus windows. Ignore |
| 1778 | * "memory" descriptors, which are for registers on |
| 1779 | * devices. |
| 1780 | */ |
| 1781 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
| 1782 | start = res->data.address32.address.minimum; |
| 1783 | end = res->data.address32.address.maximum; |
Gerd Hoffmann | 4eb923f | 2014-02-24 14:17:08 +0100 | [diff] [blame] | 1784 | break; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1785 | |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1786 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1787 | start = res->data.address64.address.minimum; |
| 1788 | end = res->data.address64.address.maximum; |
Gerd Hoffmann | 4eb923f | 2014-02-24 14:17:08 +0100 | [diff] [blame] | 1789 | break; |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1790 | |
| 1791 | default: |
| 1792 | /* Unused resource type */ |
| 1793 | return AE_OK; |
| 1794 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1795 | } |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1796 | /* |
| 1797 | * Ignore ranges that are below 1MB, as they're not |
| 1798 | * necessary or useful here. |
| 1799 | */ |
| 1800 | if (end < 0x100000) |
| 1801 | return AE_OK; |
| 1802 | |
| 1803 | new_res = kzalloc(sizeof(*new_res), GFP_ATOMIC); |
| 1804 | if (!new_res) |
| 1805 | return AE_NO_MEMORY; |
| 1806 | |
| 1807 | /* If this range overlaps the virtual TPM, truncate it. */ |
| 1808 | if (end > VTPM_BASE_ADDRESS && start < VTPM_BASE_ADDRESS) |
| 1809 | end = VTPM_BASE_ADDRESS; |
| 1810 | |
| 1811 | new_res->name = "hyperv mmio"; |
| 1812 | new_res->flags = IORESOURCE_MEM; |
| 1813 | new_res->start = start; |
| 1814 | new_res->end = end; |
| 1815 | |
Jake Oshins | 40f26f3 | 2015-12-14 16:01:52 -0800 | [diff] [blame] | 1816 | /* |
Jake Oshins | 40f26f3 | 2015-12-14 16:01:52 -0800 | [diff] [blame] | 1817 | * If two ranges are adjacent, merge them. |
| 1818 | */ |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1819 | do { |
| 1820 | if (!*old_res) { |
| 1821 | *old_res = new_res; |
| 1822 | break; |
| 1823 | } |
| 1824 | |
Jake Oshins | 40f26f3 | 2015-12-14 16:01:52 -0800 | [diff] [blame] | 1825 | if (((*old_res)->end + 1) == new_res->start) { |
| 1826 | (*old_res)->end = new_res->end; |
| 1827 | kfree(new_res); |
| 1828 | break; |
| 1829 | } |
| 1830 | |
| 1831 | if ((*old_res)->start == new_res->end + 1) { |
| 1832 | (*old_res)->start = new_res->start; |
| 1833 | kfree(new_res); |
| 1834 | break; |
| 1835 | } |
| 1836 | |
Jake Oshins | 23a0683 | 2016-04-05 10:22:53 -0700 | [diff] [blame] | 1837 | if ((*old_res)->start > new_res->end) { |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1838 | new_res->sibling = *old_res; |
| 1839 | if (prev_res) |
| 1840 | (*prev_res)->sibling = new_res; |
| 1841 | *old_res = new_res; |
| 1842 | break; |
| 1843 | } |
| 1844 | |
| 1845 | prev_res = old_res; |
| 1846 | old_res = &(*old_res)->sibling; |
| 1847 | |
| 1848 | } while (1); |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1849 | |
| 1850 | return AE_OK; |
| 1851 | } |
| 1852 | |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1853 | static int vmbus_acpi_remove(struct acpi_device *device) |
| 1854 | { |
| 1855 | struct resource *cur_res; |
| 1856 | struct resource *next_res; |
| 1857 | |
| 1858 | if (hyperv_mmio) { |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 1859 | if (fb_mmio) { |
| 1860 | __release_region(hyperv_mmio, fb_mmio->start, |
| 1861 | resource_size(fb_mmio)); |
| 1862 | fb_mmio = NULL; |
| 1863 | } |
| 1864 | |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1865 | for (cur_res = hyperv_mmio; cur_res; cur_res = next_res) { |
| 1866 | next_res = cur_res->sibling; |
| 1867 | kfree(cur_res); |
| 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | return 0; |
| 1872 | } |
| 1873 | |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 1874 | static void vmbus_reserve_fb(void) |
| 1875 | { |
| 1876 | int size; |
| 1877 | /* |
| 1878 | * Make a claim for the frame buffer in the resource tree under the |
| 1879 | * first node, which will be the one below 4GB. The length seems to |
| 1880 | * be underreported, particularly in a Generation 1 VM. So start out |
| 1881 | * reserving a larger area and make it smaller until it succeeds. |
| 1882 | */ |
| 1883 | |
| 1884 | if (screen_info.lfb_base) { |
| 1885 | if (efi_enabled(EFI_BOOT)) |
| 1886 | size = max_t(__u32, screen_info.lfb_size, 0x800000); |
| 1887 | else |
| 1888 | size = max_t(__u32, screen_info.lfb_size, 0x4000000); |
| 1889 | |
| 1890 | for (; !fb_mmio && (size >= 0x100000); size >>= 1) { |
| 1891 | fb_mmio = __request_region(hyperv_mmio, |
| 1892 | screen_info.lfb_base, size, |
| 1893 | fb_mmio_name, 0); |
| 1894 | } |
| 1895 | } |
| 1896 | } |
| 1897 | |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1898 | /** |
| 1899 | * vmbus_allocate_mmio() - Pick a memory-mapped I/O range. |
| 1900 | * @new: If successful, supplied a pointer to the |
| 1901 | * allocated MMIO space. |
| 1902 | * @device_obj: Identifies the caller |
| 1903 | * @min: Minimum guest physical address of the |
| 1904 | * allocation |
| 1905 | * @max: Maximum guest physical address |
| 1906 | * @size: Size of the range to be allocated |
| 1907 | * @align: Alignment of the range to be allocated |
| 1908 | * @fb_overlap_ok: Whether this allocation can be allowed |
| 1909 | * to overlap the video frame buffer. |
| 1910 | * |
| 1911 | * This function walks the resources granted to VMBus by the |
| 1912 | * _CRS object in the ACPI namespace underneath the parent |
| 1913 | * "bridge" whether that's a root PCI bus in the Generation 1 |
| 1914 | * case or a Module Device in the Generation 2 case. It then |
| 1915 | * attempts to allocate from the global MMIO pool in a way that |
| 1916 | * matches the constraints supplied in these parameters and by |
| 1917 | * that _CRS. |
| 1918 | * |
| 1919 | * Return: 0 on success, -errno on failure |
| 1920 | */ |
| 1921 | int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, |
| 1922 | resource_size_t min, resource_size_t max, |
| 1923 | resource_size_t size, resource_size_t align, |
| 1924 | bool fb_overlap_ok) |
| 1925 | { |
Jake Oshins | be000f9 | 2016-04-05 10:22:54 -0700 | [diff] [blame] | 1926 | struct resource *iter, *shadow; |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1927 | resource_size_t range_min, range_max, start; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1928 | const char *dev_n = dev_name(&device_obj->device); |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1929 | int retval; |
Jake Oshins | e16dad6 | 2016-04-05 10:22:50 -0700 | [diff] [blame] | 1930 | |
| 1931 | retval = -ENXIO; |
| 1932 | down(&hyperv_mmio_lock); |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1933 | |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1934 | /* |
| 1935 | * If overlaps with frame buffers are allowed, then first attempt to |
| 1936 | * make the allocation from within the reserved region. Because it |
| 1937 | * is already reserved, no shadow allocation is necessary. |
| 1938 | */ |
| 1939 | if (fb_overlap_ok && fb_mmio && !(min > fb_mmio->end) && |
| 1940 | !(max < fb_mmio->start)) { |
| 1941 | |
| 1942 | range_min = fb_mmio->start; |
| 1943 | range_max = fb_mmio->end; |
| 1944 | start = (range_min + align - 1) & ~(align - 1); |
| 1945 | for (; start + size - 1 <= range_max; start += align) { |
| 1946 | *new = request_mem_region_exclusive(start, size, dev_n); |
| 1947 | if (*new) { |
| 1948 | retval = 0; |
| 1949 | goto exit; |
| 1950 | } |
| 1951 | } |
| 1952 | } |
| 1953 | |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1954 | for (iter = hyperv_mmio; iter; iter = iter->sibling) { |
| 1955 | if ((iter->start >= max) || (iter->end <= min)) |
| 1956 | continue; |
| 1957 | |
| 1958 | range_min = iter->start; |
| 1959 | range_max = iter->end; |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1960 | start = (range_min + align - 1) & ~(align - 1); |
| 1961 | for (; start + size - 1 <= range_max; start += align) { |
| 1962 | shadow = __request_region(iter, start, size, NULL, |
| 1963 | IORESOURCE_BUSY); |
| 1964 | if (!shadow) |
| 1965 | continue; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1966 | |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1967 | *new = request_mem_region_exclusive(start, size, dev_n); |
| 1968 | if (*new) { |
| 1969 | shadow->name = (char *)*new; |
| 1970 | retval = 0; |
| 1971 | goto exit; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1974 | __release_region(iter, start, size); |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1975 | } |
| 1976 | } |
| 1977 | |
Jake Oshins | e16dad6 | 2016-04-05 10:22:50 -0700 | [diff] [blame] | 1978 | exit: |
| 1979 | up(&hyperv_mmio_lock); |
| 1980 | return retval; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1981 | } |
| 1982 | EXPORT_SYMBOL_GPL(vmbus_allocate_mmio); |
| 1983 | |
Jake Oshins | 619848b | 2015-12-14 16:01:39 -0800 | [diff] [blame] | 1984 | /** |
Jake Oshins | 97fb77dc | 2016-04-05 10:22:51 -0700 | [diff] [blame] | 1985 | * vmbus_free_mmio() - Free a memory-mapped I/O range. |
| 1986 | * @start: Base address of region to release. |
| 1987 | * @size: Size of the range to be allocated |
| 1988 | * |
| 1989 | * This function releases anything requested by |
| 1990 | * vmbus_mmio_allocate(). |
| 1991 | */ |
| 1992 | void vmbus_free_mmio(resource_size_t start, resource_size_t size) |
| 1993 | { |
Jake Oshins | be000f9 | 2016-04-05 10:22:54 -0700 | [diff] [blame] | 1994 | struct resource *iter; |
| 1995 | |
| 1996 | down(&hyperv_mmio_lock); |
| 1997 | for (iter = hyperv_mmio; iter; iter = iter->sibling) { |
| 1998 | if ((iter->start >= start + size) || (iter->end <= start)) |
| 1999 | continue; |
| 2000 | |
| 2001 | __release_region(iter, start, size); |
| 2002 | } |
Jake Oshins | 97fb77dc | 2016-04-05 10:22:51 -0700 | [diff] [blame] | 2003 | release_mem_region(start, size); |
Jake Oshins | be000f9 | 2016-04-05 10:22:54 -0700 | [diff] [blame] | 2004 | up(&hyperv_mmio_lock); |
Jake Oshins | 97fb77dc | 2016-04-05 10:22:51 -0700 | [diff] [blame] | 2005 | |
| 2006 | } |
| 2007 | EXPORT_SYMBOL_GPL(vmbus_free_mmio); |
| 2008 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2009 | static int vmbus_acpi_add(struct acpi_device *device) |
| 2010 | { |
| 2011 | acpi_status result; |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2012 | int ret_val = -ENODEV; |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2013 | struct acpi_device *ancestor; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2014 | |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 2015 | hv_acpi_dev = device; |
| 2016 | |
K. Y. Srinivasan | 0a4425b | 2011-08-27 11:31:38 -0700 | [diff] [blame] | 2017 | result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2018 | vmbus_walk_resources, NULL); |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2019 | |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2020 | if (ACPI_FAILURE(result)) |
| 2021 | goto acpi_walk_err; |
| 2022 | /* |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2023 | * Some ancestor of the vmbus acpi device (Gen1 or Gen2 |
| 2024 | * firmware) is the VMOD that has the mmio ranges. Get that. |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2025 | */ |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2026 | for (ancestor = device->parent; ancestor; ancestor = ancestor->parent) { |
| 2027 | result = acpi_walk_resources(ancestor->handle, METHOD_NAME__CRS, |
| 2028 | vmbus_walk_resources, NULL); |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2029 | |
| 2030 | if (ACPI_FAILURE(result)) |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2031 | continue; |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 2032 | if (hyperv_mmio) { |
| 2033 | vmbus_reserve_fb(); |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2034 | break; |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 2035 | } |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2036 | } |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2037 | ret_val = 0; |
| 2038 | |
| 2039 | acpi_walk_err: |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2040 | complete(&probe_event); |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2041 | if (ret_val) |
| 2042 | vmbus_acpi_remove(device); |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2043 | return ret_val; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | static const struct acpi_device_id vmbus_acpi_device_ids[] = { |
| 2047 | {"VMBUS", 0}, |
K. Y. Srinivasan | 9d7b18d | 2011-06-06 15:49:42 -0700 | [diff] [blame] | 2048 | {"VMBus", 0}, |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2049 | {"", 0}, |
| 2050 | }; |
| 2051 | MODULE_DEVICE_TABLE(acpi, vmbus_acpi_device_ids); |
| 2052 | |
| 2053 | static struct acpi_driver vmbus_acpi_driver = { |
| 2054 | .name = "vmbus", |
| 2055 | .ids = vmbus_acpi_device_ids, |
| 2056 | .ops = { |
| 2057 | .add = vmbus_acpi_add, |
Vitaly Kuznetsov | e4ecb41 | 2015-04-22 21:31:28 -0700 | [diff] [blame] | 2058 | .remove = vmbus_acpi_remove, |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2059 | }, |
| 2060 | }; |
| 2061 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2062 | static void hv_kexec_handler(void) |
| 2063 | { |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 2064 | hv_stimer_global_cleanup(); |
Vitaly Kuznetsov | 75ff3a8 | 2016-02-26 15:13:16 -0800 | [diff] [blame] | 2065 | vmbus_initiate_unload(false); |
Vitaly Kuznetsov | 523b940 | 2016-12-07 14:53:12 -0800 | [diff] [blame] | 2066 | vmbus_connection.conn_state = DISCONNECTED; |
| 2067 | /* Make sure conn_state is set as hv_synic_cleanup checks for it */ |
| 2068 | mb(); |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 2069 | cpuhp_remove_state(hyperv_cpuhp_online); |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 2070 | hyperv_cleanup(); |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2071 | }; |
| 2072 | |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2073 | static void hv_crash_handler(struct pt_regs *regs) |
| 2074 | { |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 2075 | int cpu; |
| 2076 | |
Vitaly Kuznetsov | 75ff3a8 | 2016-02-26 15:13:16 -0800 | [diff] [blame] | 2077 | vmbus_initiate_unload(true); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2078 | /* |
| 2079 | * In crash handler we can't schedule synic cleanup for all CPUs, |
| 2080 | * doing the cleanup for current CPU only. This should be sufficient |
| 2081 | * for kdump. |
| 2082 | */ |
Vitaly Kuznetsov | 523b940 | 2016-12-07 14:53:12 -0800 | [diff] [blame] | 2083 | vmbus_connection.conn_state = DISCONNECTED; |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 2084 | cpu = smp_processor_id(); |
| 2085 | hv_stimer_cleanup(cpu); |
| 2086 | hv_synic_cleanup(cpu); |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 2087 | hyperv_cleanup(); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2088 | }; |
| 2089 | |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame^] | 2090 | static int hv_synic_suspend(void) |
| 2091 | { |
| 2092 | /* |
| 2093 | * When we reach here, all the non-boot CPUs have been offlined, and |
| 2094 | * the stimers on them have been unbound in hv_synic_cleanup() -> |
| 2095 | * hv_stimer_cleanup() -> clockevents_unbind_device(). |
| 2096 | * |
| 2097 | * hv_synic_suspend() only runs on CPU0 with interrupts disabled. Here |
| 2098 | * we do not unbind the stimer on CPU0 because: 1) it's unnecessary |
| 2099 | * because the interrupts remain disabled between syscore_suspend() |
| 2100 | * and syscore_resume(): see create_image() and resume_target_kernel(); |
| 2101 | * 2) the stimer on CPU0 is automatically disabled later by |
| 2102 | * syscore_suspend() -> timekeeping_suspend() -> tick_suspend() -> ... |
| 2103 | * -> clockevents_shutdown() -> ... -> hv_ce_shutdown(); 3) a warning |
| 2104 | * would be triggered if we call clockevents_unbind_device(), which |
| 2105 | * may sleep, in an interrupts-disabled context. So, we intentionally |
| 2106 | * don't call hv_stimer_cleanup(0) here. |
| 2107 | */ |
| 2108 | |
| 2109 | hv_synic_disable_regs(0); |
| 2110 | |
| 2111 | return 0; |
| 2112 | } |
| 2113 | |
| 2114 | static void hv_synic_resume(void) |
| 2115 | { |
| 2116 | hv_synic_enable_regs(0); |
| 2117 | |
| 2118 | /* |
| 2119 | * Note: we don't need to call hv_stimer_init(0), because the timer |
| 2120 | * on CPU0 is not unbound in hv_synic_suspend(), and the timer is |
| 2121 | * automatically re-enabled in timekeeping_resume(). |
| 2122 | */ |
| 2123 | } |
| 2124 | |
| 2125 | /* The callbacks run only on CPU0, with irqs_disabled. */ |
| 2126 | static struct syscore_ops hv_synic_syscore_ops = { |
| 2127 | .suspend = hv_synic_suspend, |
| 2128 | .resume = hv_synic_resume, |
| 2129 | }; |
| 2130 | |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 2131 | static int __init hv_acpi_init(void) |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 2132 | { |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2133 | int ret, t; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2134 | |
Michael Kelley | 4a5f3cd | 2017-12-22 11:19:02 -0700 | [diff] [blame] | 2135 | if (!hv_is_hyperv_initialized()) |
Jason Wang | 0592969 | 2012-08-17 18:52:43 +0800 | [diff] [blame] | 2136 | return -ENODEV; |
| 2137 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2138 | init_completion(&probe_event); |
| 2139 | |
| 2140 | /* |
K. Y. Srinivasan | efc2672 | 2015-12-14 16:01:46 -0800 | [diff] [blame] | 2141 | * Get ACPI resources first. |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2142 | */ |
K. Y. Srinivasan | 0246604 | 2011-06-06 15:49:40 -0700 | [diff] [blame] | 2143 | ret = acpi_bus_register_driver(&vmbus_acpi_driver); |
| 2144 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2145 | if (ret) |
| 2146 | return ret; |
| 2147 | |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2148 | t = wait_for_completion_timeout(&probe_event, 5*HZ); |
| 2149 | if (t == 0) { |
| 2150 | ret = -ETIMEDOUT; |
| 2151 | goto cleanup; |
| 2152 | } |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2153 | |
K. Y. Srinivasan | efc2672 | 2015-12-14 16:01:46 -0800 | [diff] [blame] | 2154 | ret = vmbus_bus_init(); |
K. Y. Srinivasan | 91fd799 | 2011-06-16 13:16:38 -0700 | [diff] [blame] | 2155 | if (ret) |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2156 | goto cleanup; |
| 2157 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2158 | hv_setup_kexec_handler(hv_kexec_handler); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2159 | hv_setup_crash_handler(hv_crash_handler); |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2160 | |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame^] | 2161 | register_syscore_ops(&hv_synic_syscore_ops); |
| 2162 | |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2163 | return 0; |
| 2164 | |
| 2165 | cleanup: |
| 2166 | acpi_bus_unregister_driver(&vmbus_acpi_driver); |
K. Y. Srinivasan | cf6a2ea | 2011-12-01 09:59:34 -0800 | [diff] [blame] | 2167 | hv_acpi_dev = NULL; |
K. Y. Srinivasan | 91fd799 | 2011-06-16 13:16:38 -0700 | [diff] [blame] | 2168 | return ret; |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2171 | static void __exit vmbus_exit(void) |
| 2172 | { |
Vitaly Kuznetsov | e72e7ac | 2015-02-27 11:25:55 -0800 | [diff] [blame] | 2173 | int cpu; |
| 2174 | |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame^] | 2175 | unregister_syscore_ops(&hv_synic_syscore_ops); |
| 2176 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2177 | hv_remove_kexec_handler(); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2178 | hv_remove_crash_handler(); |
Vitaly Kuznetsov | 09a1962 | 2015-02-27 11:25:54 -0800 | [diff] [blame] | 2179 | vmbus_connection.conn_state = DISCONNECTED; |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 2180 | hv_stimer_global_cleanup(); |
K. Y. Srinivasan | 2db84ef | 2015-04-22 21:31:32 -0700 | [diff] [blame] | 2181 | vmbus_disconnect(); |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 2182 | hv_remove_vmbus_irq(); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 2183 | for_each_online_cpu(cpu) { |
| 2184 | struct hv_per_cpu_context *hv_cpu |
| 2185 | = per_cpu_ptr(hv_context.cpu_context, cpu); |
| 2186 | |
| 2187 | tasklet_kill(&hv_cpu->msg_dpc); |
| 2188 | } |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2189 | vmbus_free_channels(); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 2190 | |
Denis V. Lunev | cc2dd40 | 2015-08-01 16:08:20 -0700 | [diff] [blame] | 2191 | if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) { |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 2192 | kmsg_dump_unregister(&hv_kmsg_dumper); |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 2193 | unregister_die_notifier(&hyperv_die_block); |
Vitaly Kuznetsov | 096c605 | 2015-04-22 21:31:29 -0700 | [diff] [blame] | 2194 | atomic_notifier_chain_unregister(&panic_notifier_list, |
| 2195 | &hyperv_panic_block); |
| 2196 | } |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 2197 | |
| 2198 | free_page((unsigned long)hv_panic_page); |
Sunil Muthuswamy | 8afc06d | 2018-07-28 21:58:46 +0000 | [diff] [blame] | 2199 | unregister_sysctl_table(hv_ctl_table_hdr); |
| 2200 | hv_ctl_table_hdr = NULL; |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2201 | bus_unregister(&hv_bus); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 2202 | |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 2203 | cpuhp_remove_state(hyperv_cpuhp_online); |
Vitaly Kuznetsov | 06210b4 | 2015-08-01 16:08:05 -0700 | [diff] [blame] | 2204 | hv_synic_free(); |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2205 | acpi_bus_unregister_driver(&vmbus_acpi_driver); |
| 2206 | } |
| 2207 | |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 2208 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 2209 | MODULE_LICENSE("GPL"); |
Joseph Salisbury | 674eecb | 2019-04-23 03:47:27 +0000 | [diff] [blame] | 2210 | MODULE_DESCRIPTION("Microsoft Hyper-V VMBus Driver"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2211 | |
K. Y. Srinivasan | 43d4e11 | 2011-10-24 11:28:12 -0700 | [diff] [blame] | 2212 | subsys_initcall(hv_acpi_init); |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2213 | module_exit(vmbus_exit); |