Commit | Line | Data |
---|---|---|
12e364b9 KC |
1 | /* visorchipset_main.c |
2 | * | |
f6d0c1e6 | 3 | * Copyright (C) 2010 - 2013 UNISYS CORPORATION |
12e364b9 KC |
4 | * All rights reserved. |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or (at | |
9 | * your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | |
14 | * NON INFRINGEMENT. See the GNU General Public License for more | |
15 | * details. | |
16 | */ | |
17 | ||
7023638c | 18 | #include "version.h" |
12e364b9 KC |
19 | #include "visorchipset.h" |
20 | #include "procobjecttree.h" | |
21 | #include "visorchannel.h" | |
22 | #include "periodic_work.h" | |
12e364b9 KC |
23 | #include "file.h" |
24 | #include "parser.h" | |
12e364b9 | 25 | #include "uisutils.h" |
12e364b9 KC |
26 | #include "controlvmcompletionstatus.h" |
27 | #include "guestlinuxdebug.h" | |
12e364b9 KC |
28 | |
29 | #include <linux/nls.h> | |
30 | #include <linux/netdevice.h> | |
31 | #include <linux/platform_device.h> | |
90addb02 | 32 | #include <linux/uuid.h> |
1ba00980 | 33 | #include <linux/crash_dump.h> |
12e364b9 KC |
34 | |
35 | #define CURRENT_FILE_PC VISOR_CHIPSET_PC_visorchipset_main_c | |
36 | #define TEST_VNIC_PHYSITF "eth0" /* physical network itf for | |
37 | * vnic loopback test */ | |
38 | #define TEST_VNIC_SWITCHNO 1 | |
39 | #define TEST_VNIC_BUSNO 9 | |
40 | ||
41 | #define MAX_NAME_SIZE 128 | |
42 | #define MAX_IP_SIZE 50 | |
43 | #define MAXOUTSTANDINGCHANNELCOMMAND 256 | |
44 | #define POLLJIFFIES_CONTROLVMCHANNEL_FAST 1 | |
45 | #define POLLJIFFIES_CONTROLVMCHANNEL_SLOW 100 | |
46 | ||
b615d628 JS |
47 | /* |
48 | * Module parameters | |
49 | */ | |
50 | static int visorchipset_testvnic; | |
51 | static int visorchipset_testvnicclient; | |
52 | static int visorchipset_testmsg; | |
53 | static int visorchipset_major; | |
54 | static int visorchipset_serverregwait; | |
55 | static int visorchipset_clientregwait = 1; /* default is on */ | |
56 | static int visorchipset_testteardown; | |
57 | static int visorchipset_disable_controlvm; | |
58 | static int visorchipset_holdchipsetready; | |
59 | ||
12e364b9 KC |
60 | /* When the controlvm channel is idle for at least MIN_IDLE_SECONDS, |
61 | * we switch to slow polling mode. As soon as we get a controlvm | |
62 | * message, we switch back to fast polling mode. | |
63 | */ | |
64 | #define MIN_IDLE_SECONDS 10 | |
52063eca JS |
65 | static unsigned long poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST; |
66 | static unsigned long most_recent_message_jiffies; /* when we got our last | |
bd5b9b32 | 67 | * controlvm message */ |
12e364b9 KC |
68 | static int serverregistered; |
69 | static int clientregistered; | |
70 | ||
71 | #define MAX_CHIPSET_EVENTS 2 | |
c242233e | 72 | static u8 chipset_events[MAX_CHIPSET_EVENTS] = { 0, 0 }; |
12e364b9 | 73 | |
9232d2d6 BR |
74 | static struct delayed_work periodic_controlvm_work; |
75 | static struct workqueue_struct *periodic_controlvm_workqueue; | |
8f1947ac | 76 | static DEFINE_SEMAPHORE(notifier_lock); |
12e364b9 | 77 | |
da021f02 BR |
78 | static struct controlvm_message_header g_diag_msg_hdr; |
79 | static struct controlvm_message_header g_chipset_msg_hdr; | |
80 | static struct controlvm_message_header g_del_dump_msg_hdr; | |
59827f00 | 81 | static const uuid_le spar_diag_pool_channel_protocol_uuid = |
9eee5d1f | 82 | SPAR_DIAG_POOL_CHANNEL_PROTOCOL_UUID; |
12e364b9 | 83 | /* 0xffffff is an invalid Bus/Device number */ |
52063eca JS |
84 | static u32 g_diagpool_bus_no = 0xffffff; |
85 | static u32 g_diagpool_dev_no = 0xffffff; | |
4f44b72d | 86 | static struct controlvm_message_packet g_devicechangestate_packet; |
12e364b9 KC |
87 | |
88 | /* Only VNIC and VHBA channels are sent to visorclientbus (aka | |
89 | * "visorhackbus") | |
90 | */ | |
91 | #define FOR_VISORHACKBUS(channel_type_guid) \ | |
9eee5d1f | 92 | (((uuid_le_cmp(channel_type_guid,\ |
0639ba67 BR |
93 | spar_vnic_channel_protocol_uuid) == 0) ||\ |
94 | (uuid_le_cmp(channel_type_guid,\ | |
9eee5d1f | 95 | spar_vhba_channel_protocol_uuid) == 0))) |
12e364b9 KC |
96 | #define FOR_VISORBUS(channel_type_guid) (!(FOR_VISORHACKBUS(channel_type_guid))) |
97 | ||
98 | #define is_diagpool_channel(channel_type_guid) \ | |
59827f00 BR |
99 | (uuid_le_cmp(channel_type_guid,\ |
100 | spar_diag_pool_channel_protocol_uuid) == 0) | |
12e364b9 | 101 | |
1390b88c BR |
102 | static LIST_HEAD(bus_info_list); |
103 | static LIST_HEAD(dev_info_list); | |
12e364b9 | 104 | |
c3d9a224 | 105 | static struct visorchannel *controlvm_channel; |
12e364b9 | 106 | |
84982fbf | 107 | /* Manages the request payload in the controlvm channel */ |
c1f834eb | 108 | struct visor_controlvm_payload_info { |
c242233e | 109 | u8 __iomem *ptr; /* pointer to base address of payload pool */ |
5fc0229a | 110 | u64 offset; /* offset from beginning of controlvm |
12e364b9 | 111 | * channel to beginning of payload * pool */ |
b3c55b13 | 112 | u32 bytes; /* number of bytes in payload pool */ |
c1f834eb JS |
113 | }; |
114 | ||
115 | static struct visor_controlvm_payload_info controlvm_payload_info; | |
12e364b9 | 116 | |
ea33b4ee BR |
117 | /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE / |
118 | * CONTROLVM_DUMP_GETTEXTDUMP / CONTROLVM_DUMP_COMPLETE conversation. | |
119 | */ | |
c1f834eb | 120 | struct visor_livedump_info { |
ea33b4ee BR |
121 | struct controlvm_message_header dumpcapture_header; |
122 | struct controlvm_message_header gettextdump_header; | |
123 | struct controlvm_message_header dumpcomplete_header; | |
f4c11551 | 124 | bool gettextdump_outstanding; |
12e364b9 | 125 | u32 crc32; |
52063eca | 126 | unsigned long length; |
12e364b9 | 127 | atomic_t buffers_in_use; |
52063eca | 128 | unsigned long destination; |
c1f834eb JS |
129 | }; |
130 | ||
131 | static struct visor_livedump_info livedump_info; | |
12e364b9 KC |
132 | |
133 | /* The following globals are used to handle the scenario where we are unable to | |
134 | * offload the payload from a controlvm message due to memory requirements. In | |
135 | * this scenario, we simply stash the controlvm message, then attempt to | |
136 | * process it again the next time controlvm_periodic_work() runs. | |
137 | */ | |
7166ed19 | 138 | static struct controlvm_message controlvm_pending_msg; |
f4c11551 | 139 | static bool controlvm_pending_msg_valid = false; |
12e364b9 KC |
140 | |
141 | /* Pool of struct putfile_buffer_entry, for keeping track of pending (incoming) | |
142 | * TRANSMIT_FILE PutFile payloads. | |
143 | */ | |
1eee0011 BR |
144 | static struct kmem_cache *putfile_buffer_list_pool; |
145 | static const char putfile_buffer_list_pool_name[] = | |
12e364b9 KC |
146 | "controlvm_putfile_buffer_list_pool"; |
147 | ||
148 | /* This identifies a data buffer that has been received via a controlvm messages | |
149 | * in a remote --> local CONTROLVM_TRANSMIT_FILE conversation. | |
150 | */ | |
151 | struct putfile_buffer_entry { | |
152 | struct list_head next; /* putfile_buffer_entry list */ | |
317d9614 | 153 | struct parser_context *parser_ctx; /* points to input data buffer */ |
12e364b9 KC |
154 | }; |
155 | ||
156 | /* List of struct putfile_request *, via next_putfile_request member. | |
157 | * Each entry in this list identifies an outstanding TRANSMIT_FILE | |
158 | * conversation. | |
159 | */ | |
1eee0011 | 160 | static LIST_HEAD(putfile_request_list); |
12e364b9 KC |
161 | |
162 | /* This describes a buffer and its current state of transfer (e.g., how many | |
163 | * bytes have already been supplied as putfile data, and how many bytes are | |
164 | * remaining) for a putfile_request. | |
165 | */ | |
166 | struct putfile_active_buffer { | |
167 | /* a payload from a controlvm message, containing a file data buffer */ | |
317d9614 | 168 | struct parser_context *parser_ctx; |
12e364b9 KC |
169 | /* points within data area of parser_ctx to next byte of data */ |
170 | u8 *pnext; | |
171 | /* # bytes left from <pnext> to the end of this data buffer */ | |
172 | size_t bytes_remaining; | |
173 | }; | |
174 | ||
175 | #define PUTFILE_REQUEST_SIG 0x0906101302281211 | |
176 | /* This identifies a single remote --> local CONTROLVM_TRANSMIT_FILE | |
177 | * conversation. Structs of this type are dynamically linked into | |
178 | * <Putfile_request_list>. | |
179 | */ | |
180 | struct putfile_request { | |
181 | u64 sig; /* PUTFILE_REQUEST_SIG */ | |
182 | ||
183 | /* header from original TransmitFile request */ | |
98d7b594 | 184 | struct controlvm_message_header controlvm_header; |
12e364b9 KC |
185 | u64 file_request_number; /* from original TransmitFile request */ |
186 | ||
187 | /* link to next struct putfile_request */ | |
188 | struct list_head next_putfile_request; | |
189 | ||
190 | /* most-recent sequence number supplied via a controlvm message */ | |
191 | u64 data_sequence_number; | |
192 | ||
193 | /* head of putfile_buffer_entry list, which describes the data to be | |
194 | * supplied as putfile data; | |
195 | * - this list is added to when controlvm messages come in that supply | |
196 | * file data | |
197 | * - this list is removed from via the hotplug program that is actually | |
198 | * consuming these buffers to write as file data */ | |
199 | struct list_head input_buffer_list; | |
200 | spinlock_t req_list_lock; /* lock for input_buffer_list */ | |
201 | ||
202 | /* waiters for input_buffer_list to go non-empty */ | |
203 | wait_queue_head_t input_buffer_wq; | |
204 | ||
205 | /* data not yet read within current putfile_buffer_entry */ | |
206 | struct putfile_active_buffer active_buf; | |
207 | ||
208 | /* <0 = failed, 0 = in-progress, >0 = successful; */ | |
209 | /* note that this must be set with req_list_lock, and if you set <0, */ | |
210 | /* it is your responsibility to also free up all of the other objects */ | |
211 | /* in this struct (like input_buffer_list, active_buf.parser_ctx) */ | |
212 | /* before releasing the lock */ | |
213 | int completion_status; | |
214 | }; | |
215 | ||
712f42cd | 216 | static atomic_t visorchipset_cache_buffers_in_use = ATOMIC_INIT(0); |
12e364b9 KC |
217 | |
218 | struct parahotplug_request { | |
219 | struct list_head list; | |
220 | int id; | |
221 | unsigned long expiration; | |
3ab47701 | 222 | struct controlvm_message msg; |
12e364b9 KC |
223 | }; |
224 | ||
ddf5de53 BR |
225 | static LIST_HEAD(parahotplug_request_list); |
226 | static DEFINE_SPINLOCK(parahotplug_request_list_lock); /* lock for above */ | |
12e364b9 KC |
227 | static void parahotplug_process_list(void); |
228 | ||
229 | /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE / | |
230 | * CONTROLVM_REPORTEVENT. | |
231 | */ | |
6fe345af BR |
232 | static struct visorchipset_busdev_notifiers busdev_server_notifiers; |
233 | static struct visorchipset_busdev_notifiers busdev_client_notifiers; | |
12e364b9 | 234 | |
52063eca JS |
235 | static void bus_create_response(u32 bus_no, int response); |
236 | static void bus_destroy_response(u32 bus_no, int response); | |
237 | static void device_create_response(u32 bus_no, u32 dev_no, int response); | |
238 | static void device_destroy_response(u32 bus_no, u32 dev_no, int response); | |
239 | static void device_resume_response(u32 bus_no, u32 dev_no, int response); | |
12e364b9 | 240 | |
8e3fedd6 | 241 | static struct visorchipset_busdev_responders busdev_responders = { |
12e364b9 KC |
242 | .bus_create = bus_create_response, |
243 | .bus_destroy = bus_destroy_response, | |
244 | .device_create = device_create_response, | |
245 | .device_destroy = device_destroy_response, | |
927c7927 | 246 | .device_pause = visorchipset_device_pause_response, |
12e364b9 KC |
247 | .device_resume = device_resume_response, |
248 | }; | |
249 | ||
250 | /* info for /dev/visorchipset */ | |
5aa8ae57 | 251 | static dev_t major_dev = -1; /**< indicates major num for device */ |
12e364b9 | 252 | |
19f6634f BR |
253 | /* prototypes for attributes */ |
254 | static ssize_t toolaction_show(struct device *dev, | |
8e76e695 | 255 | struct device_attribute *attr, char *buf); |
19f6634f | 256 | static ssize_t toolaction_store(struct device *dev, |
8e76e695 BR |
257 | struct device_attribute *attr, |
258 | const char *buf, size_t count); | |
19f6634f BR |
259 | static DEVICE_ATTR_RW(toolaction); |
260 | ||
54b31229 | 261 | static ssize_t boottotool_show(struct device *dev, |
8e76e695 | 262 | struct device_attribute *attr, char *buf); |
54b31229 | 263 | static ssize_t boottotool_store(struct device *dev, |
8e76e695 BR |
264 | struct device_attribute *attr, const char *buf, |
265 | size_t count); | |
54b31229 BR |
266 | static DEVICE_ATTR_RW(boottotool); |
267 | ||
422af17c | 268 | static ssize_t error_show(struct device *dev, struct device_attribute *attr, |
8e76e695 | 269 | char *buf); |
422af17c | 270 | static ssize_t error_store(struct device *dev, struct device_attribute *attr, |
8e76e695 | 271 | const char *buf, size_t count); |
422af17c BR |
272 | static DEVICE_ATTR_RW(error); |
273 | ||
274 | static ssize_t textid_show(struct device *dev, struct device_attribute *attr, | |
8e76e695 | 275 | char *buf); |
422af17c | 276 | static ssize_t textid_store(struct device *dev, struct device_attribute *attr, |
8e76e695 | 277 | const char *buf, size_t count); |
422af17c BR |
278 | static DEVICE_ATTR_RW(textid); |
279 | ||
280 | static ssize_t remaining_steps_show(struct device *dev, | |
8e76e695 | 281 | struct device_attribute *attr, char *buf); |
422af17c | 282 | static ssize_t remaining_steps_store(struct device *dev, |
8e76e695 BR |
283 | struct device_attribute *attr, |
284 | const char *buf, size_t count); | |
422af17c BR |
285 | static DEVICE_ATTR_RW(remaining_steps); |
286 | ||
18b87ed1 | 287 | static ssize_t chipsetready_store(struct device *dev, |
8e76e695 BR |
288 | struct device_attribute *attr, |
289 | const char *buf, size_t count); | |
18b87ed1 BR |
290 | static DEVICE_ATTR_WO(chipsetready); |
291 | ||
e56fa7cd | 292 | static ssize_t devicedisabled_store(struct device *dev, |
8e76e695 BR |
293 | struct device_attribute *attr, |
294 | const char *buf, size_t count); | |
e56fa7cd BR |
295 | static DEVICE_ATTR_WO(devicedisabled); |
296 | ||
297 | static ssize_t deviceenabled_store(struct device *dev, | |
8e76e695 BR |
298 | struct device_attribute *attr, |
299 | const char *buf, size_t count); | |
e56fa7cd BR |
300 | static DEVICE_ATTR_WO(deviceenabled); |
301 | ||
19f6634f BR |
302 | static struct attribute *visorchipset_install_attrs[] = { |
303 | &dev_attr_toolaction.attr, | |
54b31229 | 304 | &dev_attr_boottotool.attr, |
422af17c BR |
305 | &dev_attr_error.attr, |
306 | &dev_attr_textid.attr, | |
307 | &dev_attr_remaining_steps.attr, | |
19f6634f BR |
308 | NULL |
309 | }; | |
310 | ||
311 | static struct attribute_group visorchipset_install_group = { | |
312 | .name = "install", | |
313 | .attrs = visorchipset_install_attrs | |
314 | }; | |
315 | ||
18b87ed1 BR |
316 | static struct attribute *visorchipset_guest_attrs[] = { |
317 | &dev_attr_chipsetready.attr, | |
318 | NULL | |
319 | }; | |
320 | ||
321 | static struct attribute_group visorchipset_guest_group = { | |
322 | .name = "guest", | |
323 | .attrs = visorchipset_guest_attrs | |
324 | }; | |
325 | ||
e56fa7cd BR |
326 | static struct attribute *visorchipset_parahotplug_attrs[] = { |
327 | &dev_attr_devicedisabled.attr, | |
328 | &dev_attr_deviceenabled.attr, | |
329 | NULL | |
330 | }; | |
331 | ||
332 | static struct attribute_group visorchipset_parahotplug_group = { | |
333 | .name = "parahotplug", | |
334 | .attrs = visorchipset_parahotplug_attrs | |
335 | }; | |
336 | ||
19f6634f BR |
337 | static const struct attribute_group *visorchipset_dev_groups[] = { |
338 | &visorchipset_install_group, | |
18b87ed1 | 339 | &visorchipset_guest_group, |
e56fa7cd | 340 | &visorchipset_parahotplug_group, |
19f6634f BR |
341 | NULL |
342 | }; | |
343 | ||
12e364b9 | 344 | /* /sys/devices/platform/visorchipset */ |
eb34e877 | 345 | static struct platform_device visorchipset_platform_device = { |
12e364b9 KC |
346 | .name = "visorchipset", |
347 | .id = -1, | |
19f6634f | 348 | .dev.groups = visorchipset_dev_groups, |
12e364b9 KC |
349 | }; |
350 | ||
351 | /* Function prototypes */ | |
b3168c70 | 352 | static void controlvm_respond(struct controlvm_message_header *msg_hdr, |
98d7b594 BR |
353 | int response); |
354 | static void controlvm_respond_chipset_init( | |
b3168c70 | 355 | struct controlvm_message_header *msg_hdr, int response, |
98d7b594 BR |
356 | enum ultra_chipset_feature features); |
357 | static void controlvm_respond_physdev_changestate( | |
b3168c70 | 358 | struct controlvm_message_header *msg_hdr, int response, |
98d7b594 | 359 | struct spar_segment_state state); |
12e364b9 | 360 | |
d746cb55 VB |
361 | static ssize_t toolaction_show(struct device *dev, |
362 | struct device_attribute *attr, | |
363 | char *buf) | |
19f6634f | 364 | { |
01f4d85a | 365 | u8 tool_action; |
19f6634f | 366 | |
c3d9a224 | 367 | visorchannel_read(controlvm_channel, |
d19642f6 | 368 | offsetof(struct spar_controlvm_channel_protocol, |
8e76e695 | 369 | tool_action), &tool_action, sizeof(u8)); |
01f4d85a | 370 | return scnprintf(buf, PAGE_SIZE, "%u\n", tool_action); |
19f6634f BR |
371 | } |
372 | ||
d746cb55 VB |
373 | static ssize_t toolaction_store(struct device *dev, |
374 | struct device_attribute *attr, | |
375 | const char *buf, size_t count) | |
19f6634f | 376 | { |
01f4d85a | 377 | u8 tool_action; |
66e24b76 | 378 | int ret; |
19f6634f | 379 | |
01f4d85a | 380 | if (kstrtou8(buf, 10, &tool_action) != 0) |
66e24b76 BR |
381 | return -EINVAL; |
382 | ||
c3d9a224 | 383 | ret = visorchannel_write(controlvm_channel, |
8e76e695 BR |
384 | offsetof(struct spar_controlvm_channel_protocol, |
385 | tool_action), | |
01f4d85a | 386 | &tool_action, sizeof(u8)); |
66e24b76 BR |
387 | |
388 | if (ret) | |
389 | return ret; | |
e22a4a0f | 390 | return count; |
19f6634f BR |
391 | } |
392 | ||
d746cb55 VB |
393 | static ssize_t boottotool_show(struct device *dev, |
394 | struct device_attribute *attr, | |
395 | char *buf) | |
54b31229 | 396 | { |
365522d9 | 397 | struct efi_spar_indication efi_spar_indication; |
54b31229 | 398 | |
c3d9a224 | 399 | visorchannel_read(controlvm_channel, |
8e76e695 BR |
400 | offsetof(struct spar_controlvm_channel_protocol, |
401 | efi_spar_ind), &efi_spar_indication, | |
402 | sizeof(struct efi_spar_indication)); | |
54b31229 | 403 | return scnprintf(buf, PAGE_SIZE, "%u\n", |
8e76e695 | 404 | efi_spar_indication.boot_to_tool); |
54b31229 BR |
405 | } |
406 | ||
d746cb55 VB |
407 | static ssize_t boottotool_store(struct device *dev, |
408 | struct device_attribute *attr, | |
409 | const char *buf, size_t count) | |
54b31229 | 410 | { |
66e24b76 | 411 | int val, ret; |
365522d9 | 412 | struct efi_spar_indication efi_spar_indication; |
54b31229 | 413 | |
66e24b76 BR |
414 | if (kstrtoint(buf, 10, &val) != 0) |
415 | return -EINVAL; | |
416 | ||
365522d9 | 417 | efi_spar_indication.boot_to_tool = val; |
c3d9a224 | 418 | ret = visorchannel_write(controlvm_channel, |
d19642f6 | 419 | offsetof(struct spar_controlvm_channel_protocol, |
8e76e695 BR |
420 | efi_spar_ind), &(efi_spar_indication), |
421 | sizeof(struct efi_spar_indication)); | |
66e24b76 BR |
422 | |
423 | if (ret) | |
424 | return ret; | |
e22a4a0f | 425 | return count; |
54b31229 | 426 | } |
422af17c BR |
427 | |
428 | static ssize_t error_show(struct device *dev, struct device_attribute *attr, | |
8e76e695 | 429 | char *buf) |
422af17c BR |
430 | { |
431 | u32 error; | |
432 | ||
8e76e695 BR |
433 | visorchannel_read(controlvm_channel, |
434 | offsetof(struct spar_controlvm_channel_protocol, | |
435 | installation_error), | |
436 | &error, sizeof(u32)); | |
422af17c BR |
437 | return scnprintf(buf, PAGE_SIZE, "%i\n", error); |
438 | } | |
439 | ||
440 | static ssize_t error_store(struct device *dev, struct device_attribute *attr, | |
8e76e695 | 441 | const char *buf, size_t count) |
422af17c BR |
442 | { |
443 | u32 error; | |
66e24b76 | 444 | int ret; |
422af17c | 445 | |
66e24b76 BR |
446 | if (kstrtou32(buf, 10, &error) != 0) |
447 | return -EINVAL; | |
448 | ||
c3d9a224 | 449 | ret = visorchannel_write(controlvm_channel, |
8e76e695 BR |
450 | offsetof(struct spar_controlvm_channel_protocol, |
451 | installation_error), | |
452 | &error, sizeof(u32)); | |
66e24b76 BR |
453 | if (ret) |
454 | return ret; | |
e22a4a0f | 455 | return count; |
422af17c BR |
456 | } |
457 | ||
458 | static ssize_t textid_show(struct device *dev, struct device_attribute *attr, | |
8e76e695 | 459 | char *buf) |
422af17c | 460 | { |
10dbf0e3 | 461 | u32 text_id; |
422af17c | 462 | |
8e76e695 BR |
463 | visorchannel_read(controlvm_channel, |
464 | offsetof(struct spar_controlvm_channel_protocol, | |
465 | installation_text_id), | |
466 | &text_id, sizeof(u32)); | |
10dbf0e3 | 467 | return scnprintf(buf, PAGE_SIZE, "%i\n", text_id); |
422af17c BR |
468 | } |
469 | ||
470 | static ssize_t textid_store(struct device *dev, struct device_attribute *attr, | |
8e76e695 | 471 | const char *buf, size_t count) |
422af17c | 472 | { |
10dbf0e3 | 473 | u32 text_id; |
66e24b76 | 474 | int ret; |
422af17c | 475 | |
10dbf0e3 | 476 | if (kstrtou32(buf, 10, &text_id) != 0) |
66e24b76 BR |
477 | return -EINVAL; |
478 | ||
c3d9a224 | 479 | ret = visorchannel_write(controlvm_channel, |
8e76e695 BR |
480 | offsetof(struct spar_controlvm_channel_protocol, |
481 | installation_text_id), | |
482 | &text_id, sizeof(u32)); | |
66e24b76 BR |
483 | if (ret) |
484 | return ret; | |
e22a4a0f | 485 | return count; |
422af17c BR |
486 | } |
487 | ||
422af17c | 488 | static ssize_t remaining_steps_show(struct device *dev, |
8e76e695 | 489 | struct device_attribute *attr, char *buf) |
422af17c | 490 | { |
ee8da290 | 491 | u16 remaining_steps; |
422af17c | 492 | |
c3d9a224 | 493 | visorchannel_read(controlvm_channel, |
8e76e695 BR |
494 | offsetof(struct spar_controlvm_channel_protocol, |
495 | installation_remaining_steps), | |
496 | &remaining_steps, sizeof(u16)); | |
ee8da290 | 497 | return scnprintf(buf, PAGE_SIZE, "%hu\n", remaining_steps); |
422af17c BR |
498 | } |
499 | ||
500 | static ssize_t remaining_steps_store(struct device *dev, | |
8e76e695 BR |
501 | struct device_attribute *attr, |
502 | const char *buf, size_t count) | |
422af17c | 503 | { |
ee8da290 | 504 | u16 remaining_steps; |
66e24b76 | 505 | int ret; |
422af17c | 506 | |
ee8da290 | 507 | if (kstrtou16(buf, 10, &remaining_steps) != 0) |
66e24b76 BR |
508 | return -EINVAL; |
509 | ||
c3d9a224 | 510 | ret = visorchannel_write(controlvm_channel, |
8e76e695 BR |
511 | offsetof(struct spar_controlvm_channel_protocol, |
512 | installation_remaining_steps), | |
513 | &remaining_steps, sizeof(u16)); | |
66e24b76 BR |
514 | if (ret) |
515 | return ret; | |
e22a4a0f | 516 | return count; |
422af17c BR |
517 | } |
518 | ||
12e364b9 | 519 | static void |
9b989a98 | 520 | bus_info_clear(void *v) |
12e364b9 | 521 | { |
33192fa1 | 522 | struct visorchipset_bus_info *p = (struct visorchipset_bus_info *) (v); |
12e364b9 | 523 | |
12e364b9 KC |
524 | kfree(p->name); |
525 | p->name = NULL; | |
526 | ||
527 | kfree(p->description); | |
528 | p->description = NULL; | |
529 | ||
530 | p->state.created = 0; | |
33192fa1 | 531 | memset(p, 0, sizeof(struct visorchipset_bus_info)); |
12e364b9 KC |
532 | } |
533 | ||
534 | static void | |
9b989a98 | 535 | dev_info_clear(void *v) |
12e364b9 | 536 | { |
246e0cd0 BR |
537 | struct visorchipset_device_info *p = |
538 | (struct visorchipset_device_info *)(v); | |
26eb2c0c | 539 | |
12e364b9 | 540 | p->state.created = 0; |
246e0cd0 | 541 | memset(p, 0, sizeof(struct visorchipset_device_info)); |
12e364b9 KC |
542 | } |
543 | ||
c242233e | 544 | static u8 |
12e364b9 KC |
545 | check_chipset_events(void) |
546 | { | |
547 | int i; | |
c242233e | 548 | u8 send_msg = 1; |
12e364b9 KC |
549 | /* Check events to determine if response should be sent */ |
550 | for (i = 0; i < MAX_CHIPSET_EVENTS; i++) | |
551 | send_msg &= chipset_events[i]; | |
552 | return send_msg; | |
553 | } | |
554 | ||
555 | static void | |
556 | clear_chipset_events(void) | |
557 | { | |
558 | int i; | |
559 | /* Clear chipset_events */ | |
560 | for (i = 0; i < MAX_CHIPSET_EVENTS; i++) | |
561 | chipset_events[i] = 0; | |
562 | } | |
563 | ||
564 | void | |
fe90d892 BR |
565 | visorchipset_register_busdev_server( |
566 | struct visorchipset_busdev_notifiers *notifiers, | |
929aa8ae | 567 | struct visorchipset_busdev_responders *responders, |
1e7a59c1 | 568 | struct ultra_vbus_deviceinfo *driver_info) |
12e364b9 | 569 | { |
8f1947ac | 570 | down(¬ifier_lock); |
38f736e9 | 571 | if (!notifiers) { |
6fe345af BR |
572 | memset(&busdev_server_notifiers, 0, |
573 | sizeof(busdev_server_notifiers)); | |
12e364b9 KC |
574 | serverregistered = 0; /* clear flag */ |
575 | } else { | |
6fe345af | 576 | busdev_server_notifiers = *notifiers; |
12e364b9 KC |
577 | serverregistered = 1; /* set flag */ |
578 | } | |
579 | if (responders) | |
8e3fedd6 | 580 | *responders = busdev_responders; |
1e7a59c1 BR |
581 | if (driver_info) |
582 | bus_device_info_init(driver_info, "chipset", "visorchipset", | |
8e76e695 | 583 | VERSION, NULL); |
12e364b9 | 584 | |
8f1947ac | 585 | up(¬ifier_lock); |
12e364b9 KC |
586 | } |
587 | EXPORT_SYMBOL_GPL(visorchipset_register_busdev_server); | |
588 | ||
589 | void | |
fe90d892 BR |
590 | visorchipset_register_busdev_client( |
591 | struct visorchipset_busdev_notifiers *notifiers, | |
929aa8ae | 592 | struct visorchipset_busdev_responders *responders, |
43fce019 | 593 | struct ultra_vbus_deviceinfo *driver_info) |
12e364b9 | 594 | { |
8f1947ac | 595 | down(¬ifier_lock); |
38f736e9 | 596 | if (!notifiers) { |
6fe345af BR |
597 | memset(&busdev_client_notifiers, 0, |
598 | sizeof(busdev_client_notifiers)); | |
12e364b9 KC |
599 | clientregistered = 0; /* clear flag */ |
600 | } else { | |
6fe345af | 601 | busdev_client_notifiers = *notifiers; |
12e364b9 KC |
602 | clientregistered = 1; /* set flag */ |
603 | } | |
604 | if (responders) | |
8e3fedd6 | 605 | *responders = busdev_responders; |
43fce019 BR |
606 | if (driver_info) |
607 | bus_device_info_init(driver_info, "chipset(bolts)", | |
608 | "visorchipset", VERSION, NULL); | |
8f1947ac | 609 | up(¬ifier_lock); |
12e364b9 KC |
610 | } |
611 | EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client); | |
612 | ||
613 | static void | |
614 | cleanup_controlvm_structures(void) | |
615 | { | |
33192fa1 | 616 | struct visorchipset_bus_info *bi, *tmp_bi; |
246e0cd0 | 617 | struct visorchipset_device_info *di, *tmp_di; |
12e364b9 | 618 | |
1390b88c | 619 | list_for_each_entry_safe(bi, tmp_bi, &bus_info_list, entry) { |
9b989a98 | 620 | bus_info_clear(bi); |
12e364b9 KC |
621 | list_del(&bi->entry); |
622 | kfree(bi); | |
623 | } | |
624 | ||
1390b88c | 625 | list_for_each_entry_safe(di, tmp_di, &dev_info_list, entry) { |
9b989a98 | 626 | dev_info_clear(di); |
12e364b9 KC |
627 | list_del(&di->entry); |
628 | kfree(di); | |
629 | } | |
630 | } | |
631 | ||
632 | static void | |
3ab47701 | 633 | chipset_init(struct controlvm_message *inmsg) |
12e364b9 KC |
634 | { |
635 | static int chipset_inited; | |
b9b141e8 | 636 | enum ultra_chipset_feature features = 0; |
12e364b9 KC |
637 | int rc = CONTROLVM_RESP_SUCCESS; |
638 | ||
639 | POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO); | |
640 | if (chipset_inited) { | |
22ad57ba | 641 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
e3199b2e | 642 | goto cleanup; |
12e364b9 KC |
643 | } |
644 | chipset_inited = 1; | |
645 | POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC, POSTCODE_SEVERITY_INFO); | |
646 | ||
647 | /* Set features to indicate we support parahotplug (if Command | |
648 | * also supports it). */ | |
649 | features = | |
2ea5117b | 650 | inmsg->cmd.init_chipset. |
12e364b9 KC |
651 | features & ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG; |
652 | ||
653 | /* Set the "reply" bit so Command knows this is a | |
654 | * features-aware driver. */ | |
655 | features |= ULTRA_CHIPSET_FEATURE_REPLY; | |
656 | ||
e3199b2e | 657 | cleanup: |
12e364b9 KC |
658 | if (rc < 0) |
659 | cleanup_controlvm_structures(); | |
98d7b594 | 660 | if (inmsg->hdr.flags.response_expected) |
12e364b9 KC |
661 | controlvm_respond_chipset_init(&inmsg->hdr, rc, features); |
662 | } | |
663 | ||
664 | static void | |
3ab47701 | 665 | controlvm_init_response(struct controlvm_message *msg, |
b3168c70 | 666 | struct controlvm_message_header *msg_hdr, int response) |
12e364b9 | 667 | { |
3ab47701 | 668 | memset(msg, 0, sizeof(struct controlvm_message)); |
b3168c70 | 669 | memcpy(&msg->hdr, msg_hdr, sizeof(struct controlvm_message_header)); |
98d7b594 BR |
670 | msg->hdr.payload_bytes = 0; |
671 | msg->hdr.payload_vm_offset = 0; | |
672 | msg->hdr.payload_max_bytes = 0; | |
12e364b9 | 673 | if (response < 0) { |
98d7b594 BR |
674 | msg->hdr.flags.failed = 1; |
675 | msg->hdr.completion_status = (u32) (-response); | |
12e364b9 KC |
676 | } |
677 | } | |
678 | ||
679 | static void | |
b3168c70 | 680 | controlvm_respond(struct controlvm_message_header *msg_hdr, int response) |
12e364b9 | 681 | { |
3ab47701 | 682 | struct controlvm_message outmsg; |
26eb2c0c | 683 | |
b3168c70 | 684 | controlvm_init_response(&outmsg, msg_hdr, response); |
12e364b9 KC |
685 | /* For DiagPool channel DEVICE_CHANGESTATE, we need to send |
686 | * back the deviceChangeState structure in the packet. */ | |
b3168c70 | 687 | if (msg_hdr->id == CONTROLVM_DEVICE_CHANGESTATE && |
0639ba67 BR |
688 | g_devicechangestate_packet.device_change_state.bus_no == |
689 | g_diagpool_bus_no && | |
690 | g_devicechangestate_packet.device_change_state.dev_no == | |
83d48905 | 691 | g_diagpool_dev_no) |
4f44b72d | 692 | outmsg.cmd = g_devicechangestate_packet; |
2098dbd1 | 693 | if (outmsg.hdr.flags.test_message == 1) |
12e364b9 | 694 | return; |
2098dbd1 | 695 | |
c3d9a224 | 696 | if (!visorchannel_signalinsert(controlvm_channel, |
12e364b9 | 697 | CONTROLVM_QUEUE_REQUEST, &outmsg)) { |
12e364b9 KC |
698 | return; |
699 | } | |
700 | } | |
701 | ||
702 | static void | |
b3168c70 | 703 | controlvm_respond_chipset_init(struct controlvm_message_header *msg_hdr, |
98d7b594 | 704 | int response, |
b9b141e8 | 705 | enum ultra_chipset_feature features) |
12e364b9 | 706 | { |
3ab47701 | 707 | struct controlvm_message outmsg; |
26eb2c0c | 708 | |
b3168c70 | 709 | controlvm_init_response(&outmsg, msg_hdr, response); |
2ea5117b | 710 | outmsg.cmd.init_chipset.features = features; |
c3d9a224 | 711 | if (!visorchannel_signalinsert(controlvm_channel, |
12e364b9 | 712 | CONTROLVM_QUEUE_REQUEST, &outmsg)) { |
12e364b9 KC |
713 | return; |
714 | } | |
715 | } | |
716 | ||
98d7b594 | 717 | static void controlvm_respond_physdev_changestate( |
b3168c70 | 718 | struct controlvm_message_header *msg_hdr, int response, |
98d7b594 | 719 | struct spar_segment_state state) |
12e364b9 | 720 | { |
3ab47701 | 721 | struct controlvm_message outmsg; |
26eb2c0c | 722 | |
b3168c70 | 723 | controlvm_init_response(&outmsg, msg_hdr, response); |
2ea5117b BR |
724 | outmsg.cmd.device_change_state.state = state; |
725 | outmsg.cmd.device_change_state.flags.phys_device = 1; | |
c3d9a224 | 726 | if (!visorchannel_signalinsert(controlvm_channel, |
12e364b9 | 727 | CONTROLVM_QUEUE_REQUEST, &outmsg)) { |
12e364b9 KC |
728 | return; |
729 | } | |
730 | } | |
731 | ||
732 | void | |
2c683cde BR |
733 | visorchipset_save_message(struct controlvm_message *msg, |
734 | enum crash_obj_type type) | |
12e364b9 | 735 | { |
4577225d BR |
736 | u32 crash_msg_offset; |
737 | u16 crash_msg_count; | |
12e364b9 KC |
738 | |
739 | /* get saved message count */ | |
c3d9a224 | 740 | if (visorchannel_read(controlvm_channel, |
d19642f6 BR |
741 | offsetof(struct spar_controlvm_channel_protocol, |
742 | saved_crash_message_count), | |
4577225d | 743 | &crash_msg_count, sizeof(u16)) < 0) { |
12e364b9 KC |
744 | POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, |
745 | POSTCODE_SEVERITY_ERR); | |
746 | return; | |
747 | } | |
748 | ||
4577225d | 749 | if (crash_msg_count != CONTROLVM_CRASHMSG_MAX) { |
12e364b9 | 750 | POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC, |
4577225d | 751 | crash_msg_count, |
12e364b9 KC |
752 | POSTCODE_SEVERITY_ERR); |
753 | return; | |
754 | } | |
755 | ||
756 | /* get saved crash message offset */ | |
c3d9a224 | 757 | if (visorchannel_read(controlvm_channel, |
d19642f6 BR |
758 | offsetof(struct spar_controlvm_channel_protocol, |
759 | saved_crash_message_offset), | |
4577225d | 760 | &crash_msg_offset, sizeof(u32)) < 0) { |
12e364b9 KC |
761 | POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, |
762 | POSTCODE_SEVERITY_ERR); | |
763 | return; | |
764 | } | |
765 | ||
2c683cde | 766 | if (type == CRASH_BUS) { |
c3d9a224 | 767 | if (visorchannel_write(controlvm_channel, |
4577225d | 768 | crash_msg_offset, |
3ab47701 BR |
769 | msg, |
770 | sizeof(struct controlvm_message)) < 0) { | |
12e364b9 KC |
771 | POSTCODE_LINUX_2(SAVE_MSG_BUS_FAILURE_PC, |
772 | POSTCODE_SEVERITY_ERR); | |
773 | return; | |
774 | } | |
775 | } else { | |
c3d9a224 | 776 | if (visorchannel_write(controlvm_channel, |
4577225d | 777 | crash_msg_offset + |
3ab47701 BR |
778 | sizeof(struct controlvm_message), msg, |
779 | sizeof(struct controlvm_message)) < 0) { | |
12e364b9 KC |
780 | POSTCODE_LINUX_2(SAVE_MSG_DEV_FAILURE_PC, |
781 | POSTCODE_SEVERITY_ERR); | |
782 | return; | |
783 | } | |
784 | } | |
785 | } | |
786 | EXPORT_SYMBOL_GPL(visorchipset_save_message); | |
787 | ||
788 | static void | |
52063eca | 789 | bus_responder(enum controlvm_id cmd_id, u32 bus_no, int response) |
12e364b9 | 790 | { |
33192fa1 | 791 | struct visorchipset_bus_info *p = NULL; |
f4c11551 | 792 | bool need_clear = false; |
12e364b9 | 793 | |
fbb31f48 | 794 | p = findbus(&bus_info_list, bus_no); |
0aca7844 | 795 | if (!p) |
12e364b9 | 796 | return; |
0aca7844 | 797 | |
12e364b9 | 798 | if (response < 0) { |
fbb31f48 | 799 | if ((cmd_id == CONTROLVM_BUS_CREATE) && |
12e364b9 KC |
800 | (response != (-CONTROLVM_RESP_ERROR_ALREADY_DONE))) |
801 | /* undo the row we just created... */ | |
fbb31f48 | 802 | delbusdevices(&dev_info_list, bus_no); |
12e364b9 | 803 | } else { |
fbb31f48 | 804 | if (cmd_id == CONTROLVM_BUS_CREATE) |
12e364b9 | 805 | p->state.created = 1; |
fbb31f48 | 806 | if (cmd_id == CONTROLVM_BUS_DESTROY) |
f4c11551 | 807 | need_clear = true; |
12e364b9 KC |
808 | } |
809 | ||
0aca7844 | 810 | if (p->pending_msg_hdr.id == CONTROLVM_INVALID) |
12e364b9 | 811 | return; /* no controlvm response needed */ |
6b59b31d | 812 | if (p->pending_msg_hdr.id != (u32)cmd_id) |
12e364b9 | 813 | return; |
33192fa1 BR |
814 | controlvm_respond(&p->pending_msg_hdr, response); |
815 | p->pending_msg_hdr.id = CONTROLVM_INVALID; | |
12e364b9 | 816 | if (need_clear) { |
9b989a98 | 817 | bus_info_clear(p); |
fbb31f48 | 818 | delbusdevices(&dev_info_list, bus_no); |
12e364b9 KC |
819 | } |
820 | } | |
821 | ||
822 | static void | |
fbb31f48 | 823 | device_changestate_responder(enum controlvm_id cmd_id, |
52063eca | 824 | u32 bus_no, u32 dev_no, int response, |
fbb31f48 | 825 | struct spar_segment_state response_state) |
12e364b9 | 826 | { |
246e0cd0 | 827 | struct visorchipset_device_info *p = NULL; |
3ab47701 | 828 | struct controlvm_message outmsg; |
12e364b9 | 829 | |
fbb31f48 | 830 | p = finddevice(&dev_info_list, bus_no, dev_no); |
0aca7844 | 831 | if (!p) |
12e364b9 | 832 | return; |
0aca7844 | 833 | if (p->pending_msg_hdr.id == CONTROLVM_INVALID) |
12e364b9 | 834 | return; /* no controlvm response needed */ |
fbb31f48 | 835 | if (p->pending_msg_hdr.id != cmd_id) |
12e364b9 | 836 | return; |
12e364b9 | 837 | |
246e0cd0 | 838 | controlvm_init_response(&outmsg, &p->pending_msg_hdr, response); |
12e364b9 | 839 | |
fbb31f48 BR |
840 | outmsg.cmd.device_change_state.bus_no = bus_no; |
841 | outmsg.cmd.device_change_state.dev_no = dev_no; | |
842 | outmsg.cmd.device_change_state.state = response_state; | |
12e364b9 | 843 | |
c3d9a224 | 844 | if (!visorchannel_signalinsert(controlvm_channel, |
0aca7844 | 845 | CONTROLVM_QUEUE_REQUEST, &outmsg)) |
12e364b9 | 846 | return; |
12e364b9 | 847 | |
246e0cd0 | 848 | p->pending_msg_hdr.id = CONTROLVM_INVALID; |
12e364b9 KC |
849 | } |
850 | ||
851 | static void | |
52063eca | 852 | device_responder(enum controlvm_id cmd_id, u32 bus_no, u32 dev_no, int response) |
12e364b9 | 853 | { |
246e0cd0 | 854 | struct visorchipset_device_info *p = NULL; |
f4c11551 | 855 | bool need_clear = false; |
12e364b9 | 856 | |
fbb31f48 | 857 | p = finddevice(&dev_info_list, bus_no, dev_no); |
0aca7844 | 858 | if (!p) |
12e364b9 | 859 | return; |
12e364b9 | 860 | if (response >= 0) { |
fbb31f48 | 861 | if (cmd_id == CONTROLVM_DEVICE_CREATE) |
12e364b9 | 862 | p->state.created = 1; |
fbb31f48 | 863 | if (cmd_id == CONTROLVM_DEVICE_DESTROY) |
f4c11551 | 864 | need_clear = true; |
12e364b9 KC |
865 | } |
866 | ||
0aca7844 | 867 | if (p->pending_msg_hdr.id == CONTROLVM_INVALID) |
12e364b9 | 868 | return; /* no controlvm response needed */ |
0aca7844 | 869 | |
6b59b31d | 870 | if (p->pending_msg_hdr.id != (u32)cmd_id) |
12e364b9 | 871 | return; |
0aca7844 | 872 | |
246e0cd0 BR |
873 | controlvm_respond(&p->pending_msg_hdr, response); |
874 | p->pending_msg_hdr.id = CONTROLVM_INVALID; | |
12e364b9 | 875 | if (need_clear) |
9b989a98 | 876 | dev_info_clear(p); |
12e364b9 KC |
877 | } |
878 | ||
879 | static void | |
2836c6a8 BR |
880 | bus_epilog(u32 bus_no, |
881 | u32 cmd, struct controlvm_message_header *msg_hdr, | |
f4c11551 | 882 | int response, bool need_response) |
12e364b9 | 883 | { |
f4c11551 | 884 | bool notified = false; |
12e364b9 | 885 | |
2836c6a8 BR |
886 | struct visorchipset_bus_info *bus_info = findbus(&bus_info_list, |
887 | bus_no); | |
12e364b9 | 888 | |
2836c6a8 | 889 | if (!bus_info) |
12e364b9 | 890 | return; |
0aca7844 | 891 | |
2836c6a8 BR |
892 | if (need_response) { |
893 | memcpy(&bus_info->pending_msg_hdr, msg_hdr, | |
98d7b594 | 894 | sizeof(struct controlvm_message_header)); |
75c1f8b7 | 895 | } else { |
2836c6a8 | 896 | bus_info->pending_msg_hdr.id = CONTROLVM_INVALID; |
75c1f8b7 | 897 | } |
12e364b9 | 898 | |
8f1947ac | 899 | down(¬ifier_lock); |
12e364b9 KC |
900 | if (response == CONTROLVM_RESP_SUCCESS) { |
901 | switch (cmd) { | |
902 | case CONTROLVM_BUS_CREATE: | |
903 | /* We can't tell from the bus_create | |
904 | * information which of our 2 bus flavors the | |
905 | * devices on this bus will ultimately end up. | |
906 | * FORTUNATELY, it turns out it is harmless to | |
907 | * send the bus_create to both of them. We can | |
908 | * narrow things down a little bit, though, | |
909 | * because we know: - BusDev_Server can handle | |
910 | * either server or client devices | |
911 | * - BusDev_Client can handle ONLY client | |
912 | * devices */ | |
6fe345af BR |
913 | if (busdev_server_notifiers.bus_create) { |
914 | (*busdev_server_notifiers.bus_create) (bus_no); | |
f4c11551 | 915 | notified = true; |
12e364b9 | 916 | } |
2836c6a8 | 917 | if ((!bus_info->flags.server) /*client */ && |
6fe345af BR |
918 | busdev_client_notifiers.bus_create) { |
919 | (*busdev_client_notifiers.bus_create) (bus_no); | |
f4c11551 | 920 | notified = true; |
12e364b9 KC |
921 | } |
922 | break; | |
923 | case CONTROLVM_BUS_DESTROY: | |
6fe345af BR |
924 | if (busdev_server_notifiers.bus_destroy) { |
925 | (*busdev_server_notifiers.bus_destroy) (bus_no); | |
f4c11551 | 926 | notified = true; |
12e364b9 | 927 | } |
2836c6a8 | 928 | if ((!bus_info->flags.server) /*client */ && |
6fe345af BR |
929 | busdev_client_notifiers.bus_destroy) { |
930 | (*busdev_client_notifiers.bus_destroy) (bus_no); | |
f4c11551 | 931 | notified = true; |
12e364b9 KC |
932 | } |
933 | break; | |
934 | } | |
935 | } | |
936 | if (notified) | |
937 | /* The callback function just called above is responsible | |
929aa8ae | 938 | * for calling the appropriate visorchipset_busdev_responders |
12e364b9 KC |
939 | * function, which will call bus_responder() |
940 | */ | |
941 | ; | |
942 | else | |
2836c6a8 | 943 | bus_responder(cmd, bus_no, response); |
8f1947ac | 944 | up(¬ifier_lock); |
12e364b9 KC |
945 | } |
946 | ||
947 | static void | |
2836c6a8 BR |
948 | device_epilog(u32 bus_no, u32 dev_no, struct spar_segment_state state, u32 cmd, |
949 | struct controlvm_message_header *msg_hdr, int response, | |
f4c11551 | 950 | bool need_response, bool for_visorbus) |
12e364b9 | 951 | { |
fe90d892 | 952 | struct visorchipset_busdev_notifiers *notifiers = NULL; |
f4c11551 | 953 | bool notified = false; |
12e364b9 | 954 | |
2836c6a8 BR |
955 | struct visorchipset_device_info *dev_info = |
956 | finddevice(&dev_info_list, bus_no, dev_no); | |
12e364b9 KC |
957 | char *envp[] = { |
958 | "SPARSP_DIAGPOOL_PAUSED_STATE = 1", | |
959 | NULL | |
960 | }; | |
961 | ||
2836c6a8 | 962 | if (!dev_info) |
12e364b9 | 963 | return; |
0aca7844 | 964 | |
12e364b9 | 965 | if (for_visorbus) |
6fe345af | 966 | notifiers = &busdev_server_notifiers; |
12e364b9 | 967 | else |
6fe345af | 968 | notifiers = &busdev_client_notifiers; |
2836c6a8 BR |
969 | if (need_response) { |
970 | memcpy(&dev_info->pending_msg_hdr, msg_hdr, | |
98d7b594 | 971 | sizeof(struct controlvm_message_header)); |
75c1f8b7 | 972 | } else { |
2836c6a8 | 973 | dev_info->pending_msg_hdr.id = CONTROLVM_INVALID; |
75c1f8b7 | 974 | } |
12e364b9 | 975 | |
8f1947ac | 976 | down(¬ifier_lock); |
12e364b9 KC |
977 | if (response >= 0) { |
978 | switch (cmd) { | |
979 | case CONTROLVM_DEVICE_CREATE: | |
980 | if (notifiers->device_create) { | |
2836c6a8 | 981 | (*notifiers->device_create) (bus_no, dev_no); |
f4c11551 | 982 | notified = true; |
12e364b9 KC |
983 | } |
984 | break; | |
985 | case CONTROLVM_DEVICE_CHANGESTATE: | |
986 | /* ServerReady / ServerRunning / SegmentStateRunning */ | |
bd0d2dcc BR |
987 | if (state.alive == segment_state_running.alive && |
988 | state.operating == | |
989 | segment_state_running.operating) { | |
12e364b9 | 990 | if (notifiers->device_resume) { |
2836c6a8 BR |
991 | (*notifiers->device_resume) (bus_no, |
992 | dev_no); | |
f4c11551 | 993 | notified = true; |
12e364b9 KC |
994 | } |
995 | } | |
996 | /* ServerNotReady / ServerLost / SegmentStateStandby */ | |
bd0d2dcc | 997 | else if (state.alive == segment_state_standby.alive && |
3f833b54 | 998 | state.operating == |
bd0d2dcc | 999 | segment_state_standby.operating) { |
12e364b9 KC |
1000 | /* technically this is standby case |
1001 | * where server is lost | |
1002 | */ | |
1003 | if (notifiers->device_pause) { | |
2836c6a8 BR |
1004 | (*notifiers->device_pause) (bus_no, |
1005 | dev_no); | |
f4c11551 | 1006 | notified = true; |
12e364b9 | 1007 | } |
bd0d2dcc | 1008 | } else if (state.alive == segment_state_paused.alive && |
3f833b54 | 1009 | state.operating == |
bd0d2dcc | 1010 | segment_state_paused.operating) { |
12e364b9 KC |
1011 | /* this is lite pause where channel is |
1012 | * still valid just 'pause' of it | |
1013 | */ | |
2836c6a8 BR |
1014 | if (bus_no == g_diagpool_bus_no && |
1015 | dev_no == g_diagpool_dev_no) { | |
12e364b9 KC |
1016 | /* this will trigger the |
1017 | * diag_shutdown.sh script in | |
1018 | * the visorchipset hotplug */ | |
1019 | kobject_uevent_env | |
eb34e877 | 1020 | (&visorchipset_platform_device.dev. |
12e364b9 KC |
1021 | kobj, KOBJ_ONLINE, envp); |
1022 | } | |
1023 | } | |
1024 | break; | |
1025 | case CONTROLVM_DEVICE_DESTROY: | |
1026 | if (notifiers->device_destroy) { | |
2836c6a8 | 1027 | (*notifiers->device_destroy) (bus_no, dev_no); |
f4c11551 | 1028 | notified = true; |
12e364b9 KC |
1029 | } |
1030 | break; | |
1031 | } | |
1032 | } | |
1033 | if (notified) | |
1034 | /* The callback function just called above is responsible | |
929aa8ae | 1035 | * for calling the appropriate visorchipset_busdev_responders |
12e364b9 KC |
1036 | * function, which will call device_responder() |
1037 | */ | |
1038 | ; | |
1039 | else | |
2836c6a8 | 1040 | device_responder(cmd, bus_no, dev_no, response); |
8f1947ac | 1041 | up(¬ifier_lock); |
12e364b9 KC |
1042 | } |
1043 | ||
1044 | static void | |
3ab47701 | 1045 | bus_create(struct controlvm_message *inmsg) |
12e364b9 | 1046 | { |
2ea5117b | 1047 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
52063eca | 1048 | u32 bus_no = cmd->create_bus.bus_no; |
12e364b9 | 1049 | int rc = CONTROLVM_RESP_SUCCESS; |
6c5fed35 | 1050 | struct visorchipset_bus_info *bus_info = NULL; |
12e364b9 | 1051 | |
6c5fed35 BR |
1052 | bus_info = findbus(&bus_info_list, bus_no); |
1053 | if (bus_info && (bus_info->state.created == 1)) { | |
1054 | POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no, | |
12e364b9 | 1055 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1056 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
6c5fed35 | 1057 | goto cleanup; |
12e364b9 | 1058 | } |
6c5fed35 BR |
1059 | bus_info = kzalloc(sizeof(*bus_info), GFP_KERNEL); |
1060 | if (!bus_info) { | |
1061 | POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no, | |
12e364b9 | 1062 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1063 | rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED; |
6c5fed35 | 1064 | goto cleanup; |
12e364b9 KC |
1065 | } |
1066 | ||
6c5fed35 BR |
1067 | INIT_LIST_HEAD(&bus_info->entry); |
1068 | bus_info->bus_no = bus_no; | |
1069 | bus_info->dev_no = cmd->create_bus.dev_count; | |
12e364b9 | 1070 | |
6c5fed35 | 1071 | POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, bus_no, POSTCODE_SEVERITY_INFO); |
12e364b9 | 1072 | |
98d7b594 | 1073 | if (inmsg->hdr.flags.test_message == 1) |
6c5fed35 | 1074 | bus_info->chan_info.addr_type = ADDRTYPE_LOCALTEST; |
12e364b9 | 1075 | else |
6c5fed35 | 1076 | bus_info->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL; |
12e364b9 | 1077 | |
6c5fed35 BR |
1078 | bus_info->flags.server = inmsg->hdr.flags.server; |
1079 | bus_info->chan_info.channel_addr = cmd->create_bus.channel_addr; | |
1080 | bus_info->chan_info.n_channel_bytes = cmd->create_bus.channel_bytes; | |
1081 | bus_info->chan_info.channel_type_uuid = | |
9b1caee7 | 1082 | cmd->create_bus.bus_data_type_uuid; |
6c5fed35 | 1083 | bus_info->chan_info.channel_inst_uuid = cmd->create_bus.bus_inst_uuid; |
12e364b9 | 1084 | |
6c5fed35 | 1085 | list_add(&bus_info->entry, &bus_info_list); |
12e364b9 | 1086 | |
6c5fed35 | 1087 | POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus_no, POSTCODE_SEVERITY_INFO); |
12e364b9 | 1088 | |
6c5fed35 BR |
1089 | cleanup: |
1090 | bus_epilog(bus_no, CONTROLVM_BUS_CREATE, &inmsg->hdr, | |
98d7b594 | 1091 | rc, inmsg->hdr.flags.response_expected == 1); |
12e364b9 KC |
1092 | } |
1093 | ||
1094 | static void | |
3ab47701 | 1095 | bus_destroy(struct controlvm_message *inmsg) |
12e364b9 | 1096 | { |
2ea5117b | 1097 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
52063eca | 1098 | u32 bus_no = cmd->destroy_bus.bus_no; |
dff54cd6 | 1099 | struct visorchipset_bus_info *bus_info; |
12e364b9 KC |
1100 | int rc = CONTROLVM_RESP_SUCCESS; |
1101 | ||
dff54cd6 BR |
1102 | bus_info = findbus(&bus_info_list, bus_no); |
1103 | if (!bus_info) | |
22ad57ba | 1104 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
dff54cd6 | 1105 | else if (bus_info->state.created == 0) |
22ad57ba | 1106 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
12e364b9 | 1107 | |
dff54cd6 | 1108 | bus_epilog(bus_no, CONTROLVM_BUS_DESTROY, &inmsg->hdr, |
98d7b594 | 1109 | rc, inmsg->hdr.flags.response_expected == 1); |
12e364b9 KC |
1110 | } |
1111 | ||
1112 | static void | |
317d9614 BR |
1113 | bus_configure(struct controlvm_message *inmsg, |
1114 | struct parser_context *parser_ctx) | |
12e364b9 | 1115 | { |
2ea5117b | 1116 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
52063eca | 1117 | u32 bus_no = cmd->configure_bus.bus_no; |
654bada0 | 1118 | struct visorchipset_bus_info *bus_info = NULL; |
12e364b9 KC |
1119 | int rc = CONTROLVM_RESP_SUCCESS; |
1120 | char s[99]; | |
1121 | ||
654bada0 BR |
1122 | bus_no = cmd->configure_bus.bus_no; |
1123 | POSTCODE_LINUX_3(BUS_CONFIGURE_ENTRY_PC, bus_no, | |
1124 | POSTCODE_SEVERITY_INFO); | |
12e364b9 | 1125 | |
654bada0 BR |
1126 | bus_info = findbus(&bus_info_list, bus_no); |
1127 | if (!bus_info) { | |
1128 | POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, bus_no, | |
12e364b9 | 1129 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1130 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
654bada0 BR |
1131 | } else if (bus_info->state.created == 0) { |
1132 | POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, bus_no, | |
12e364b9 | 1133 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1134 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
654bada0 BR |
1135 | } else if (bus_info->pending_msg_hdr.id != CONTROLVM_INVALID) { |
1136 | POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, bus_no, | |
12e364b9 | 1137 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1138 | rc = -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT; |
654bada0 BR |
1139 | } else { |
1140 | bus_info->partition_handle = cmd->configure_bus.guest_handle; | |
1141 | bus_info->partition_uuid = parser_id_get(parser_ctx); | |
1142 | parser_param_start(parser_ctx, PARSERSTRING_NAME); | |
1143 | bus_info->name = parser_string_get(parser_ctx); | |
1144 | ||
1145 | visorchannel_uuid_id(&bus_info->partition_uuid, s); | |
1146 | POSTCODE_LINUX_3(BUS_CONFIGURE_EXIT_PC, bus_no, | |
1147 | POSTCODE_SEVERITY_INFO); | |
12e364b9 | 1148 | } |
654bada0 | 1149 | bus_epilog(bus_no, CONTROLVM_BUS_CONFIGURE, &inmsg->hdr, |
98d7b594 | 1150 | rc, inmsg->hdr.flags.response_expected == 1); |
12e364b9 KC |
1151 | } |
1152 | ||
1153 | static void | |
3ab47701 | 1154 | my_device_create(struct controlvm_message *inmsg) |
12e364b9 | 1155 | { |
2ea5117b | 1156 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
52063eca JS |
1157 | u32 bus_no = cmd->create_device.bus_no; |
1158 | u32 dev_no = cmd->create_device.dev_no; | |
c60c8e26 BR |
1159 | struct visorchipset_device_info *dev_info = NULL; |
1160 | struct visorchipset_bus_info *bus_info = NULL; | |
12e364b9 KC |
1161 | int rc = CONTROLVM_RESP_SUCCESS; |
1162 | ||
c60c8e26 BR |
1163 | dev_info = finddevice(&dev_info_list, bus_no, dev_no); |
1164 | if (dev_info && (dev_info->state.created == 1)) { | |
1165 | POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, | |
12e364b9 | 1166 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1167 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
c60c8e26 | 1168 | goto cleanup; |
12e364b9 | 1169 | } |
c60c8e26 BR |
1170 | bus_info = findbus(&bus_info_list, bus_no); |
1171 | if (!bus_info) { | |
1172 | POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, | |
12e364b9 | 1173 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1174 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
c60c8e26 | 1175 | goto cleanup; |
12e364b9 | 1176 | } |
c60c8e26 BR |
1177 | if (bus_info->state.created == 0) { |
1178 | POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, | |
12e364b9 | 1179 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1180 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
c60c8e26 | 1181 | goto cleanup; |
12e364b9 | 1182 | } |
c60c8e26 BR |
1183 | dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL); |
1184 | if (!dev_info) { | |
1185 | POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, | |
12e364b9 | 1186 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1187 | rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED; |
c60c8e26 | 1188 | goto cleanup; |
12e364b9 | 1189 | } |
97a84f12 | 1190 | |
c60c8e26 BR |
1191 | INIT_LIST_HEAD(&dev_info->entry); |
1192 | dev_info->bus_no = bus_no; | |
1193 | dev_info->dev_no = dev_no; | |
1194 | dev_info->dev_inst_uuid = cmd->create_device.dev_inst_uuid; | |
1195 | POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no, | |
12e364b9 KC |
1196 | POSTCODE_SEVERITY_INFO); |
1197 | ||
98d7b594 | 1198 | if (inmsg->hdr.flags.test_message == 1) |
c60c8e26 | 1199 | dev_info->chan_info.addr_type = ADDRTYPE_LOCALTEST; |
12e364b9 | 1200 | else |
c60c8e26 BR |
1201 | dev_info->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL; |
1202 | dev_info->chan_info.channel_addr = cmd->create_device.channel_addr; | |
1203 | dev_info->chan_info.n_channel_bytes = cmd->create_device.channel_bytes; | |
1204 | dev_info->chan_info.channel_type_uuid = | |
9b1caee7 | 1205 | cmd->create_device.data_type_uuid; |
c60c8e26 BR |
1206 | dev_info->chan_info.intr = cmd->create_device.intr; |
1207 | list_add(&dev_info->entry, &dev_info_list); | |
1208 | POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, dev_no, bus_no, | |
12e364b9 | 1209 | POSTCODE_SEVERITY_INFO); |
c60c8e26 | 1210 | cleanup: |
12e364b9 | 1211 | /* get the bus and devNo for DiagPool channel */ |
c60c8e26 BR |
1212 | if (dev_info && |
1213 | is_diagpool_channel(dev_info->chan_info.channel_type_uuid)) { | |
1214 | g_diagpool_bus_no = bus_no; | |
1215 | g_diagpool_dev_no = dev_no; | |
12e364b9 | 1216 | } |
c60c8e26 | 1217 | device_epilog(bus_no, dev_no, segment_state_running, |
12e364b9 | 1218 | CONTROLVM_DEVICE_CREATE, &inmsg->hdr, rc, |
98d7b594 | 1219 | inmsg->hdr.flags.response_expected == 1, |
c60c8e26 | 1220 | FOR_VISORBUS(dev_info->chan_info.channel_type_uuid)); |
12e364b9 KC |
1221 | } |
1222 | ||
1223 | static void | |
3ab47701 | 1224 | my_device_changestate(struct controlvm_message *inmsg) |
12e364b9 | 1225 | { |
2ea5117b | 1226 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
52063eca JS |
1227 | u32 bus_no = cmd->device_change_state.bus_no; |
1228 | u32 dev_no = cmd->device_change_state.dev_no; | |
2ea5117b | 1229 | struct spar_segment_state state = cmd->device_change_state.state; |
0278a905 | 1230 | struct visorchipset_device_info *dev_info = NULL; |
12e364b9 KC |
1231 | int rc = CONTROLVM_RESP_SUCCESS; |
1232 | ||
0278a905 BR |
1233 | dev_info = finddevice(&dev_info_list, bus_no, dev_no); |
1234 | if (!dev_info) { | |
1235 | POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no, | |
12e364b9 | 1236 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1237 | rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID; |
0278a905 BR |
1238 | } else if (dev_info->state.created == 0) { |
1239 | POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no, | |
12e364b9 | 1240 | POSTCODE_SEVERITY_ERR); |
22ad57ba | 1241 | rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID; |
12e364b9 | 1242 | } |
0278a905 BR |
1243 | if ((rc >= CONTROLVM_RESP_SUCCESS) && dev_info) |
1244 | device_epilog(bus_no, dev_no, state, | |
1245 | CONTROLVM_DEVICE_CHANGESTATE, &inmsg->hdr, rc, | |
98d7b594 | 1246 | inmsg->hdr.flags.response_expected == 1, |
9b1caee7 | 1247 | FOR_VISORBUS( |
0278a905 | 1248 | dev_info->chan_info.channel_type_uuid)); |
12e364b9 KC |
1249 | } |
1250 | ||
1251 | static void | |
3ab47701 | 1252 | my_device_destroy(struct controlvm_message *inmsg) |
12e364b9 | 1253 | { |
2ea5117b | 1254 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
52063eca JS |
1255 | u32 bus_no = cmd->destroy_device.bus_no; |
1256 | u32 dev_no = cmd->destroy_device.dev_no; | |
61715c8b | 1257 | struct visorchipset_device_info *dev_info = NULL; |
12e364b9 KC |
1258 | int rc = CONTROLVM_RESP_SUCCESS; |
1259 | ||
61715c8b BR |
1260 | dev_info = finddevice(&dev_info_list, bus_no, dev_no); |
1261 | if (!dev_info) | |
22ad57ba | 1262 | rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID; |
61715c8b | 1263 | else if (dev_info->state.created == 0) |
22ad57ba | 1264 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
12e364b9 | 1265 | |
61715c8b BR |
1266 | if ((rc >= CONTROLVM_RESP_SUCCESS) && dev_info) |
1267 | device_epilog(bus_no, dev_no, segment_state_running, | |
12e364b9 | 1268 | CONTROLVM_DEVICE_DESTROY, &inmsg->hdr, rc, |
98d7b594 | 1269 | inmsg->hdr.flags.response_expected == 1, |
9b1caee7 | 1270 | FOR_VISORBUS( |
61715c8b | 1271 | dev_info->chan_info.channel_type_uuid)); |
12e364b9 KC |
1272 | } |
1273 | ||
1274 | /* When provided with the physical address of the controlvm channel | |
1275 | * (phys_addr), the offset to the payload area we need to manage | |
1276 | * (offset), and the size of this payload area (bytes), fills in the | |
f4c11551 | 1277 | * controlvm_payload_info struct. Returns true for success or false |
12e364b9 KC |
1278 | * for failure. |
1279 | */ | |
1280 | static int | |
5fc0229a | 1281 | initialize_controlvm_payload_info(HOSTADDRESS phys_addr, u64 offset, u32 bytes, |
c1f834eb | 1282 | struct visor_controlvm_payload_info *info) |
12e364b9 | 1283 | { |
c242233e | 1284 | u8 __iomem *payload = NULL; |
12e364b9 KC |
1285 | int rc = CONTROLVM_RESP_SUCCESS; |
1286 | ||
38f736e9 | 1287 | if (!info) { |
22ad57ba | 1288 | rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID; |
f118a39b | 1289 | goto cleanup; |
12e364b9 | 1290 | } |
c1f834eb | 1291 | memset(info, 0, sizeof(struct visor_controlvm_payload_info)); |
12e364b9 | 1292 | if ((offset == 0) || (bytes == 0)) { |
22ad57ba | 1293 | rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID; |
f118a39b | 1294 | goto cleanup; |
12e364b9 KC |
1295 | } |
1296 | payload = ioremap_cache(phys_addr + offset, bytes); | |
38f736e9 | 1297 | if (!payload) { |
22ad57ba | 1298 | rc = -CONTROLVM_RESP_ERROR_IOREMAP_FAILED; |
f118a39b | 1299 | goto cleanup; |
12e364b9 KC |
1300 | } |
1301 | ||
1302 | info->offset = offset; | |
1303 | info->bytes = bytes; | |
1304 | info->ptr = payload; | |
12e364b9 | 1305 | |
f118a39b | 1306 | cleanup: |
12e364b9 | 1307 | if (rc < 0) { |
f118a39b | 1308 | if (payload) { |
12e364b9 KC |
1309 | iounmap(payload); |
1310 | payload = NULL; | |
1311 | } | |
1312 | } | |
1313 | return rc; | |
1314 | } | |
1315 | ||
1316 | static void | |
c1f834eb | 1317 | destroy_controlvm_payload_info(struct visor_controlvm_payload_info *info) |
12e364b9 | 1318 | { |
597c338f | 1319 | if (info->ptr) { |
12e364b9 KC |
1320 | iounmap(info->ptr); |
1321 | info->ptr = NULL; | |
1322 | } | |
c1f834eb | 1323 | memset(info, 0, sizeof(struct visor_controlvm_payload_info)); |
12e364b9 KC |
1324 | } |
1325 | ||
1326 | static void | |
1327 | initialize_controlvm_payload(void) | |
1328 | { | |
c3d9a224 | 1329 | HOSTADDRESS phys_addr = visorchannel_get_physaddr(controlvm_channel); |
cafefc0c BR |
1330 | u64 payload_offset = 0; |
1331 | u32 payload_bytes = 0; | |
26eb2c0c | 1332 | |
c3d9a224 | 1333 | if (visorchannel_read(controlvm_channel, |
d19642f6 BR |
1334 | offsetof(struct spar_controlvm_channel_protocol, |
1335 | request_payload_offset), | |
cafefc0c | 1336 | &payload_offset, sizeof(payload_offset)) < 0) { |
12e364b9 KC |
1337 | POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC, |
1338 | POSTCODE_SEVERITY_ERR); | |
1339 | return; | |
1340 | } | |
c3d9a224 | 1341 | if (visorchannel_read(controlvm_channel, |
d19642f6 BR |
1342 | offsetof(struct spar_controlvm_channel_protocol, |
1343 | request_payload_bytes), | |
cafefc0c | 1344 | &payload_bytes, sizeof(payload_bytes)) < 0) { |
12e364b9 KC |
1345 | POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC, |
1346 | POSTCODE_SEVERITY_ERR); | |
1347 | return; | |
1348 | } | |
1349 | initialize_controlvm_payload_info(phys_addr, | |
cafefc0c | 1350 | payload_offset, payload_bytes, |
84982fbf | 1351 | &controlvm_payload_info); |
12e364b9 KC |
1352 | } |
1353 | ||
1354 | /* Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset. | |
1355 | * Returns CONTROLVM_RESP_xxx code. | |
1356 | */ | |
1357 | int | |
1358 | visorchipset_chipset_ready(void) | |
1359 | { | |
eb34e877 | 1360 | kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_ONLINE); |
12e364b9 KC |
1361 | return CONTROLVM_RESP_SUCCESS; |
1362 | } | |
1363 | EXPORT_SYMBOL_GPL(visorchipset_chipset_ready); | |
1364 | ||
1365 | int | |
1366 | visorchipset_chipset_selftest(void) | |
1367 | { | |
1368 | char env_selftest[20]; | |
1369 | char *envp[] = { env_selftest, NULL }; | |
26eb2c0c | 1370 | |
12e364b9 | 1371 | sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1); |
eb34e877 | 1372 | kobject_uevent_env(&visorchipset_platform_device.dev.kobj, KOBJ_CHANGE, |
12e364b9 KC |
1373 | envp); |
1374 | return CONTROLVM_RESP_SUCCESS; | |
1375 | } | |
1376 | EXPORT_SYMBOL_GPL(visorchipset_chipset_selftest); | |
1377 | ||
1378 | /* Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset. | |
1379 | * Returns CONTROLVM_RESP_xxx code. | |
1380 | */ | |
1381 | int | |
1382 | visorchipset_chipset_notready(void) | |
1383 | { | |
eb34e877 | 1384 | kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_OFFLINE); |
12e364b9 KC |
1385 | return CONTROLVM_RESP_SUCCESS; |
1386 | } | |
1387 | EXPORT_SYMBOL_GPL(visorchipset_chipset_notready); | |
1388 | ||
1389 | static void | |
77a0449d | 1390 | chipset_ready(struct controlvm_message_header *msg_hdr) |
12e364b9 KC |
1391 | { |
1392 | int rc = visorchipset_chipset_ready(); | |
26eb2c0c | 1393 | |
12e364b9 KC |
1394 | if (rc != CONTROLVM_RESP_SUCCESS) |
1395 | rc = -rc; | |
77a0449d BR |
1396 | if (msg_hdr->flags.response_expected && !visorchipset_holdchipsetready) |
1397 | controlvm_respond(msg_hdr, rc); | |
1398 | if (msg_hdr->flags.response_expected && visorchipset_holdchipsetready) { | |
12e364b9 KC |
1399 | /* Send CHIPSET_READY response when all modules have been loaded |
1400 | * and disks mounted for the partition | |
1401 | */ | |
77a0449d | 1402 | g_chipset_msg_hdr = *msg_hdr; |
12e364b9 KC |
1403 | } |
1404 | } | |
1405 | ||
1406 | static void | |
77a0449d | 1407 | chipset_selftest(struct controlvm_message_header *msg_hdr) |
12e364b9 KC |
1408 | { |
1409 | int rc = visorchipset_chipset_selftest(); | |
26eb2c0c | 1410 | |
12e364b9 KC |
1411 | if (rc != CONTROLVM_RESP_SUCCESS) |
1412 | rc = -rc; | |
77a0449d BR |
1413 | if (msg_hdr->flags.response_expected) |
1414 | controlvm_respond(msg_hdr, rc); | |
12e364b9 KC |
1415 | } |
1416 | ||
1417 | static void | |
77a0449d | 1418 | chipset_notready(struct controlvm_message_header *msg_hdr) |
12e364b9 KC |
1419 | { |
1420 | int rc = visorchipset_chipset_notready(); | |
26eb2c0c | 1421 | |
12e364b9 KC |
1422 | if (rc != CONTROLVM_RESP_SUCCESS) |
1423 | rc = -rc; | |
77a0449d BR |
1424 | if (msg_hdr->flags.response_expected) |
1425 | controlvm_respond(msg_hdr, rc); | |
12e364b9 KC |
1426 | } |
1427 | ||
1428 | /* This is your "one-stop" shop for grabbing the next message from the | |
1429 | * CONTROLVM_QUEUE_EVENT queue in the controlvm channel. | |
1430 | */ | |
f4c11551 | 1431 | static bool |
3ab47701 | 1432 | read_controlvm_event(struct controlvm_message *msg) |
12e364b9 | 1433 | { |
c3d9a224 | 1434 | if (visorchannel_signalremove(controlvm_channel, |
12e364b9 KC |
1435 | CONTROLVM_QUEUE_EVENT, msg)) { |
1436 | /* got a message */ | |
0aca7844 | 1437 | if (msg->hdr.flags.test_message == 1) |
f4c11551 JS |
1438 | return false; |
1439 | return true; | |
12e364b9 | 1440 | } |
f4c11551 | 1441 | return false; |
12e364b9 KC |
1442 | } |
1443 | ||
1444 | /* | |
1445 | * The general parahotplug flow works as follows. The visorchipset | |
1446 | * driver receives a DEVICE_CHANGESTATE message from Command | |
1447 | * specifying a physical device to enable or disable. The CONTROLVM | |
1448 | * message handler calls parahotplug_process_message, which then adds | |
1449 | * the message to a global list and kicks off a udev event which | |
1450 | * causes a user level script to enable or disable the specified | |
1451 | * device. The udev script then writes to | |
1452 | * /proc/visorchipset/parahotplug, which causes parahotplug_proc_write | |
1453 | * to get called, at which point the appropriate CONTROLVM message is | |
1454 | * retrieved from the list and responded to. | |
1455 | */ | |
1456 | ||
1457 | #define PARAHOTPLUG_TIMEOUT_MS 2000 | |
1458 | ||
1459 | /* | |
1460 | * Generate unique int to match an outstanding CONTROLVM message with a | |
1461 | * udev script /proc response | |
1462 | */ | |
1463 | static int | |
1464 | parahotplug_next_id(void) | |
1465 | { | |
1466 | static atomic_t id = ATOMIC_INIT(0); | |
26eb2c0c | 1467 | |
12e364b9 KC |
1468 | return atomic_inc_return(&id); |
1469 | } | |
1470 | ||
1471 | /* | |
1472 | * Returns the time (in jiffies) when a CONTROLVM message on the list | |
1473 | * should expire -- PARAHOTPLUG_TIMEOUT_MS in the future | |
1474 | */ | |
1475 | static unsigned long | |
1476 | parahotplug_next_expiration(void) | |
1477 | { | |
2cc1a1b3 | 1478 | return jiffies + msecs_to_jiffies(PARAHOTPLUG_TIMEOUT_MS); |
12e364b9 KC |
1479 | } |
1480 | ||
1481 | /* | |
1482 | * Create a parahotplug_request, which is basically a wrapper for a | |
1483 | * CONTROLVM_MESSAGE that we can stick on a list | |
1484 | */ | |
1485 | static struct parahotplug_request * | |
3ab47701 | 1486 | parahotplug_request_create(struct controlvm_message *msg) |
12e364b9 | 1487 | { |
ea0dcfcf QL |
1488 | struct parahotplug_request *req; |
1489 | ||
6a55e3c3 | 1490 | req = kmalloc(sizeof(*req), GFP_KERNEL | __GFP_NORETRY); |
38f736e9 | 1491 | if (!req) |
12e364b9 KC |
1492 | return NULL; |
1493 | ||
1494 | req->id = parahotplug_next_id(); | |
1495 | req->expiration = parahotplug_next_expiration(); | |
1496 | req->msg = *msg; | |
1497 | ||
1498 | return req; | |
1499 | } | |
1500 | ||
1501 | /* | |
1502 | * Free a parahotplug_request. | |
1503 | */ | |
1504 | static void | |
1505 | parahotplug_request_destroy(struct parahotplug_request *req) | |
1506 | { | |
1507 | kfree(req); | |
1508 | } | |
1509 | ||
1510 | /* | |
1511 | * Cause uevent to run the user level script to do the disable/enable | |
1512 | * specified in (the CONTROLVM message in) the specified | |
1513 | * parahotplug_request | |
1514 | */ | |
1515 | static void | |
1516 | parahotplug_request_kickoff(struct parahotplug_request *req) | |
1517 | { | |
2ea5117b | 1518 | struct controlvm_message_packet *cmd = &req->msg.cmd; |
12e364b9 KC |
1519 | char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40], |
1520 | env_func[40]; | |
1521 | char *envp[] = { | |
1522 | env_cmd, env_id, env_state, env_bus, env_dev, env_func, NULL | |
1523 | }; | |
1524 | ||
1525 | sprintf(env_cmd, "SPAR_PARAHOTPLUG=1"); | |
1526 | sprintf(env_id, "SPAR_PARAHOTPLUG_ID=%d", req->id); | |
1527 | sprintf(env_state, "SPAR_PARAHOTPLUG_STATE=%d", | |
2ea5117b | 1528 | cmd->device_change_state.state.active); |
12e364b9 | 1529 | sprintf(env_bus, "SPAR_PARAHOTPLUG_BUS=%d", |
2ea5117b | 1530 | cmd->device_change_state.bus_no); |
12e364b9 | 1531 | sprintf(env_dev, "SPAR_PARAHOTPLUG_DEVICE=%d", |
2ea5117b | 1532 | cmd->device_change_state.dev_no >> 3); |
12e364b9 | 1533 | sprintf(env_func, "SPAR_PARAHOTPLUG_FUNCTION=%d", |
2ea5117b | 1534 | cmd->device_change_state.dev_no & 0x7); |
12e364b9 | 1535 | |
eb34e877 | 1536 | kobject_uevent_env(&visorchipset_platform_device.dev.kobj, KOBJ_CHANGE, |
12e364b9 KC |
1537 | envp); |
1538 | } | |
1539 | ||
1540 | /* | |
1541 | * Remove any request from the list that's been on there too long and | |
1542 | * respond with an error. | |
1543 | */ | |
1544 | static void | |
1545 | parahotplug_process_list(void) | |
1546 | { | |
1547 | struct list_head *pos = NULL; | |
1548 | struct list_head *tmp = NULL; | |
1549 | ||
ddf5de53 | 1550 | spin_lock(¶hotplug_request_list_lock); |
12e364b9 | 1551 | |
ddf5de53 | 1552 | list_for_each_safe(pos, tmp, ¶hotplug_request_list) { |
12e364b9 KC |
1553 | struct parahotplug_request *req = |
1554 | list_entry(pos, struct parahotplug_request, list); | |
55b33413 BR |
1555 | |
1556 | if (!time_after_eq(jiffies, req->expiration)) | |
1557 | continue; | |
1558 | ||
1559 | list_del(pos); | |
1560 | if (req->msg.hdr.flags.response_expected) | |
1561 | controlvm_respond_physdev_changestate( | |
1562 | &req->msg.hdr, | |
1563 | CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT, | |
1564 | req->msg.cmd.device_change_state.state); | |
1565 | parahotplug_request_destroy(req); | |
12e364b9 KC |
1566 | } |
1567 | ||
ddf5de53 | 1568 | spin_unlock(¶hotplug_request_list_lock); |
12e364b9 KC |
1569 | } |
1570 | ||
1571 | /* | |
1572 | * Called from the /proc handler, which means the user script has | |
1573 | * finished the enable/disable. Find the matching identifier, and | |
1574 | * respond to the CONTROLVM message with success. | |
1575 | */ | |
1576 | static int | |
b06bdf7d | 1577 | parahotplug_request_complete(int id, u16 active) |
12e364b9 KC |
1578 | { |
1579 | struct list_head *pos = NULL; | |
1580 | struct list_head *tmp = NULL; | |
1581 | ||
ddf5de53 | 1582 | spin_lock(¶hotplug_request_list_lock); |
12e364b9 KC |
1583 | |
1584 | /* Look for a request matching "id". */ | |
ddf5de53 | 1585 | list_for_each_safe(pos, tmp, ¶hotplug_request_list) { |
12e364b9 KC |
1586 | struct parahotplug_request *req = |
1587 | list_entry(pos, struct parahotplug_request, list); | |
1588 | if (req->id == id) { | |
1589 | /* Found a match. Remove it from the list and | |
1590 | * respond. | |
1591 | */ | |
1592 | list_del(pos); | |
ddf5de53 | 1593 | spin_unlock(¶hotplug_request_list_lock); |
2ea5117b | 1594 | req->msg.cmd.device_change_state.state.active = active; |
98d7b594 | 1595 | if (req->msg.hdr.flags.response_expected) |
12e364b9 KC |
1596 | controlvm_respond_physdev_changestate( |
1597 | &req->msg.hdr, CONTROLVM_RESP_SUCCESS, | |
2ea5117b | 1598 | req->msg.cmd.device_change_state.state); |
12e364b9 KC |
1599 | parahotplug_request_destroy(req); |
1600 | return 0; | |
1601 | } | |
1602 | } | |
1603 | ||
ddf5de53 | 1604 | spin_unlock(¶hotplug_request_list_lock); |
12e364b9 KC |
1605 | return -1; |
1606 | } | |
1607 | ||
1608 | /* | |
1609 | * Enables or disables a PCI device by kicking off a udev script | |
1610 | */ | |
bd5b9b32 | 1611 | static void |
3ab47701 | 1612 | parahotplug_process_message(struct controlvm_message *inmsg) |
12e364b9 KC |
1613 | { |
1614 | struct parahotplug_request *req; | |
1615 | ||
1616 | req = parahotplug_request_create(inmsg); | |
1617 | ||
38f736e9 | 1618 | if (!req) |
12e364b9 | 1619 | return; |
12e364b9 | 1620 | |
2ea5117b | 1621 | if (inmsg->cmd.device_change_state.state.active) { |
12e364b9 KC |
1622 | /* For enable messages, just respond with success |
1623 | * right away. This is a bit of a hack, but there are | |
1624 | * issues with the early enable messages we get (with | |
1625 | * either the udev script not detecting that the device | |
1626 | * is up, or not getting called at all). Fortunately | |
1627 | * the messages that get lost don't matter anyway, as | |
1628 | * devices are automatically enabled at | |
1629 | * initialization. | |
1630 | */ | |
1631 | parahotplug_request_kickoff(req); | |
1632 | controlvm_respond_physdev_changestate(&inmsg->hdr, | |
8e76e695 BR |
1633 | CONTROLVM_RESP_SUCCESS, |
1634 | inmsg->cmd.device_change_state.state); | |
12e364b9 KC |
1635 | parahotplug_request_destroy(req); |
1636 | } else { | |
1637 | /* For disable messages, add the request to the | |
1638 | * request list before kicking off the udev script. It | |
1639 | * won't get responded to until the script has | |
1640 | * indicated it's done. | |
1641 | */ | |
ddf5de53 BR |
1642 | spin_lock(¶hotplug_request_list_lock); |
1643 | list_add_tail(&req->list, ¶hotplug_request_list); | |
1644 | spin_unlock(¶hotplug_request_list_lock); | |
12e364b9 KC |
1645 | |
1646 | parahotplug_request_kickoff(req); | |
1647 | } | |
1648 | } | |
1649 | ||
12e364b9 KC |
1650 | /* Process a controlvm message. |
1651 | * Return result: | |
f4c11551 | 1652 | * false - this function will return FALSE only in the case where the |
12e364b9 KC |
1653 | * controlvm message was NOT processed, but processing must be |
1654 | * retried before reading the next controlvm message; a | |
1655 | * scenario where this can occur is when we need to throttle | |
1656 | * the allocation of memory in which to copy out controlvm | |
1657 | * payload data | |
f4c11551 | 1658 | * true - processing of the controlvm message completed, |
12e364b9 KC |
1659 | * either successfully or with an error. |
1660 | */ | |
f4c11551 | 1661 | static bool |
3ab47701 | 1662 | handle_command(struct controlvm_message inmsg, HOSTADDRESS channel_addr) |
12e364b9 | 1663 | { |
2ea5117b | 1664 | struct controlvm_message_packet *cmd = &inmsg.cmd; |
818352a8 BR |
1665 | u64 parm_addr = 0; |
1666 | u32 parm_bytes = 0; | |
317d9614 | 1667 | struct parser_context *parser_ctx = NULL; |
818352a8 | 1668 | bool local_addr = false; |
3ab47701 | 1669 | struct controlvm_message ackmsg; |
12e364b9 KC |
1670 | |
1671 | /* create parsing context if necessary */ | |
818352a8 | 1672 | local_addr = (inmsg.hdr.flags.test_message == 1); |
0aca7844 | 1673 | if (channel_addr == 0) |
f4c11551 | 1674 | return true; |
818352a8 BR |
1675 | parm_addr = channel_addr + inmsg.hdr.payload_vm_offset; |
1676 | parm_bytes = inmsg.hdr.payload_bytes; | |
12e364b9 KC |
1677 | |
1678 | /* Parameter and channel addresses within test messages actually lie | |
1679 | * within our OS-controlled memory. We need to know that, because it | |
1680 | * makes a difference in how we compute the virtual address. | |
1681 | */ | |
818352a8 | 1682 | if (parm_addr != 0 && parm_bytes != 0) { |
f4c11551 | 1683 | bool retry = false; |
26eb2c0c | 1684 | |
12e364b9 | 1685 | parser_ctx = |
818352a8 BR |
1686 | parser_init_byte_stream(parm_addr, parm_bytes, |
1687 | local_addr, &retry); | |
1b08872e | 1688 | if (!parser_ctx && retry) |
f4c11551 | 1689 | return false; |
12e364b9 KC |
1690 | } |
1691 | ||
818352a8 | 1692 | if (!local_addr) { |
12e364b9 KC |
1693 | controlvm_init_response(&ackmsg, &inmsg.hdr, |
1694 | CONTROLVM_RESP_SUCCESS); | |
c3d9a224 BR |
1695 | if (controlvm_channel) |
1696 | visorchannel_signalinsert(controlvm_channel, | |
1b08872e BR |
1697 | CONTROLVM_QUEUE_ACK, |
1698 | &ackmsg); | |
12e364b9 | 1699 | } |
98d7b594 | 1700 | switch (inmsg.hdr.id) { |
12e364b9 | 1701 | case CONTROLVM_CHIPSET_INIT: |
12e364b9 KC |
1702 | chipset_init(&inmsg); |
1703 | break; | |
1704 | case CONTROLVM_BUS_CREATE: | |
12e364b9 KC |
1705 | bus_create(&inmsg); |
1706 | break; | |
1707 | case CONTROLVM_BUS_DESTROY: | |
12e364b9 KC |
1708 | bus_destroy(&inmsg); |
1709 | break; | |
1710 | case CONTROLVM_BUS_CONFIGURE: | |
12e364b9 KC |
1711 | bus_configure(&inmsg, parser_ctx); |
1712 | break; | |
1713 | case CONTROLVM_DEVICE_CREATE: | |
12e364b9 KC |
1714 | my_device_create(&inmsg); |
1715 | break; | |
1716 | case CONTROLVM_DEVICE_CHANGESTATE: | |
2ea5117b | 1717 | if (cmd->device_change_state.flags.phys_device) { |
12e364b9 KC |
1718 | parahotplug_process_message(&inmsg); |
1719 | } else { | |
12e364b9 KC |
1720 | /* save the hdr and cmd structures for later use */ |
1721 | /* when sending back the response to Command */ | |
1722 | my_device_changestate(&inmsg); | |
da021f02 | 1723 | g_diag_msg_hdr = inmsg.hdr; |
4f44b72d | 1724 | g_devicechangestate_packet = inmsg.cmd; |
12e364b9 KC |
1725 | break; |
1726 | } | |
1727 | break; | |
1728 | case CONTROLVM_DEVICE_DESTROY: | |
12e364b9 KC |
1729 | my_device_destroy(&inmsg); |
1730 | break; | |
1731 | case CONTROLVM_DEVICE_CONFIGURE: | |
12e364b9 | 1732 | /* no op for now, just send a respond that we passed */ |
98d7b594 | 1733 | if (inmsg.hdr.flags.response_expected) |
12e364b9 KC |
1734 | controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS); |
1735 | break; | |
1736 | case CONTROLVM_CHIPSET_READY: | |
12e364b9 KC |
1737 | chipset_ready(&inmsg.hdr); |
1738 | break; | |
1739 | case CONTROLVM_CHIPSET_SELFTEST: | |
12e364b9 KC |
1740 | chipset_selftest(&inmsg.hdr); |
1741 | break; | |
1742 | case CONTROLVM_CHIPSET_STOP: | |
12e364b9 KC |
1743 | chipset_notready(&inmsg.hdr); |
1744 | break; | |
1745 | default: | |
98d7b594 | 1746 | if (inmsg.hdr.flags.response_expected) |
12e364b9 | 1747 | controlvm_respond(&inmsg.hdr, |
818352a8 | 1748 | -CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN); |
12e364b9 KC |
1749 | break; |
1750 | } | |
1751 | ||
38f736e9 | 1752 | if (parser_ctx) { |
12e364b9 KC |
1753 | parser_done(parser_ctx); |
1754 | parser_ctx = NULL; | |
1755 | } | |
f4c11551 | 1756 | return true; |
12e364b9 KC |
1757 | } |
1758 | ||
d746cb55 | 1759 | static HOSTADDRESS controlvm_get_channel_address(void) |
524b0b63 | 1760 | { |
5fc0229a | 1761 | u64 addr = 0; |
b3c55b13 | 1762 | u32 size = 0; |
524b0b63 | 1763 | |
0aca7844 | 1764 | if (!VMCALL_SUCCESSFUL(issue_vmcall_io_controlvm_addr(&addr, &size))) |
524b0b63 | 1765 | return 0; |
0aca7844 | 1766 | |
524b0b63 BR |
1767 | return addr; |
1768 | } | |
1769 | ||
12e364b9 KC |
1770 | static void |
1771 | controlvm_periodic_work(struct work_struct *work) | |
1772 | { | |
3ab47701 | 1773 | struct controlvm_message inmsg; |
f4c11551 JS |
1774 | bool got_command = false; |
1775 | bool handle_command_failed = false; | |
1c1ed292 | 1776 | static u64 poll_count; |
12e364b9 KC |
1777 | |
1778 | /* make sure visorbus server is registered for controlvm callbacks */ | |
1779 | if (visorchipset_serverregwait && !serverregistered) | |
1c1ed292 | 1780 | goto cleanup; |
12e364b9 KC |
1781 | /* make sure visorclientbus server is regsitered for controlvm |
1782 | * callbacks | |
1783 | */ | |
1784 | if (visorchipset_clientregwait && !clientregistered) | |
1c1ed292 | 1785 | goto cleanup; |
12e364b9 | 1786 | |
1c1ed292 BR |
1787 | poll_count++; |
1788 | if (poll_count >= 250) | |
12e364b9 KC |
1789 | ; /* keep going */ |
1790 | else | |
1c1ed292 | 1791 | goto cleanup; |
12e364b9 KC |
1792 | |
1793 | /* Check events to determine if response to CHIPSET_READY | |
1794 | * should be sent | |
1795 | */ | |
0639ba67 BR |
1796 | if (visorchipset_holdchipsetready && |
1797 | (g_chipset_msg_hdr.id != CONTROLVM_INVALID)) { | |
12e364b9 | 1798 | if (check_chipset_events() == 1) { |
da021f02 | 1799 | controlvm_respond(&g_chipset_msg_hdr, 0); |
12e364b9 | 1800 | clear_chipset_events(); |
da021f02 | 1801 | memset(&g_chipset_msg_hdr, 0, |
98d7b594 | 1802 | sizeof(struct controlvm_message_header)); |
12e364b9 KC |
1803 | } |
1804 | } | |
1805 | ||
c3d9a224 | 1806 | while (visorchannel_signalremove(controlvm_channel, |
8a1182eb | 1807 | CONTROLVM_QUEUE_RESPONSE, |
c3d9a224 BR |
1808 | &inmsg)) |
1809 | ; | |
1c1ed292 | 1810 | if (!got_command) { |
7166ed19 | 1811 | if (controlvm_pending_msg_valid) { |
8a1182eb BR |
1812 | /* we throttled processing of a prior |
1813 | * msg, so try to process it again | |
1814 | * rather than reading a new one | |
1815 | */ | |
7166ed19 | 1816 | inmsg = controlvm_pending_msg; |
f4c11551 | 1817 | controlvm_pending_msg_valid = false; |
1c1ed292 | 1818 | got_command = true; |
75c1f8b7 | 1819 | } else { |
1c1ed292 | 1820 | got_command = read_controlvm_event(&inmsg); |
75c1f8b7 | 1821 | } |
8a1182eb | 1822 | } |
12e364b9 | 1823 | |
f4c11551 | 1824 | handle_command_failed = false; |
1c1ed292 | 1825 | while (got_command && (!handle_command_failed)) { |
b53e0e93 | 1826 | most_recent_message_jiffies = jiffies; |
8a1182eb BR |
1827 | if (handle_command(inmsg, |
1828 | visorchannel_get_physaddr | |
c3d9a224 | 1829 | (controlvm_channel))) |
1c1ed292 | 1830 | got_command = read_controlvm_event(&inmsg); |
8a1182eb BR |
1831 | else { |
1832 | /* this is a scenario where throttling | |
1833 | * is required, but probably NOT an | |
1834 | * error...; we stash the current | |
1835 | * controlvm msg so we will attempt to | |
1836 | * reprocess it on our next loop | |
1837 | */ | |
f4c11551 | 1838 | handle_command_failed = true; |
7166ed19 | 1839 | controlvm_pending_msg = inmsg; |
f4c11551 | 1840 | controlvm_pending_msg_valid = true; |
12e364b9 KC |
1841 | } |
1842 | } | |
1843 | ||
1844 | /* parahotplug_worker */ | |
1845 | parahotplug_process_list(); | |
1846 | ||
1c1ed292 | 1847 | cleanup: |
12e364b9 KC |
1848 | |
1849 | if (time_after(jiffies, | |
b53e0e93 | 1850 | most_recent_message_jiffies + (HZ * MIN_IDLE_SECONDS))) { |
12e364b9 KC |
1851 | /* it's been longer than MIN_IDLE_SECONDS since we |
1852 | * processed our last controlvm message; slow down the | |
1853 | * polling | |
1854 | */ | |
911e213e BR |
1855 | if (poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_SLOW) |
1856 | poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW; | |
12e364b9 | 1857 | } else { |
911e213e BR |
1858 | if (poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_FAST) |
1859 | poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST; | |
12e364b9 KC |
1860 | } |
1861 | ||
9232d2d6 BR |
1862 | queue_delayed_work(periodic_controlvm_workqueue, |
1863 | &periodic_controlvm_work, poll_jiffies); | |
12e364b9 KC |
1864 | } |
1865 | ||
1866 | static void | |
1867 | setup_crash_devices_work_queue(struct work_struct *work) | |
1868 | { | |
e6bdb904 BR |
1869 | struct controlvm_message local_crash_bus_msg; |
1870 | struct controlvm_message local_crash_dev_msg; | |
3ab47701 | 1871 | struct controlvm_message msg; |
e6bdb904 BR |
1872 | u32 local_crash_msg_offset; |
1873 | u16 local_crash_msg_count; | |
12e364b9 KC |
1874 | |
1875 | /* make sure visorbus server is registered for controlvm callbacks */ | |
1876 | if (visorchipset_serverregwait && !serverregistered) | |
e6bdb904 | 1877 | goto cleanup; |
12e364b9 KC |
1878 | |
1879 | /* make sure visorclientbus server is regsitered for controlvm | |
1880 | * callbacks | |
1881 | */ | |
1882 | if (visorchipset_clientregwait && !clientregistered) | |
e6bdb904 | 1883 | goto cleanup; |
12e364b9 KC |
1884 | |
1885 | POSTCODE_LINUX_2(CRASH_DEV_ENTRY_PC, POSTCODE_SEVERITY_INFO); | |
1886 | ||
1887 | /* send init chipset msg */ | |
98d7b594 | 1888 | msg.hdr.id = CONTROLVM_CHIPSET_INIT; |
2ea5117b BR |
1889 | msg.cmd.init_chipset.bus_count = 23; |
1890 | msg.cmd.init_chipset.switch_count = 0; | |
12e364b9 KC |
1891 | |
1892 | chipset_init(&msg); | |
1893 | ||
12e364b9 | 1894 | /* get saved message count */ |
c3d9a224 | 1895 | if (visorchannel_read(controlvm_channel, |
d19642f6 BR |
1896 | offsetof(struct spar_controlvm_channel_protocol, |
1897 | saved_crash_message_count), | |
e6bdb904 | 1898 | &local_crash_msg_count, sizeof(u16)) < 0) { |
12e364b9 KC |
1899 | POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, |
1900 | POSTCODE_SEVERITY_ERR); | |
1901 | return; | |
1902 | } | |
1903 | ||
e6bdb904 | 1904 | if (local_crash_msg_count != CONTROLVM_CRASHMSG_MAX) { |
12e364b9 | 1905 | POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC, |
e6bdb904 | 1906 | local_crash_msg_count, |
12e364b9 KC |
1907 | POSTCODE_SEVERITY_ERR); |
1908 | return; | |
1909 | } | |
1910 | ||
1911 | /* get saved crash message offset */ | |
c3d9a224 | 1912 | if (visorchannel_read(controlvm_channel, |
d19642f6 BR |
1913 | offsetof(struct spar_controlvm_channel_protocol, |
1914 | saved_crash_message_offset), | |
e6bdb904 | 1915 | &local_crash_msg_offset, sizeof(u32)) < 0) { |
12e364b9 KC |
1916 | POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, |
1917 | POSTCODE_SEVERITY_ERR); | |
1918 | return; | |
1919 | } | |
1920 | ||
1921 | /* read create device message for storage bus offset */ | |
c3d9a224 | 1922 | if (visorchannel_read(controlvm_channel, |
e6bdb904 BR |
1923 | local_crash_msg_offset, |
1924 | &local_crash_bus_msg, | |
3ab47701 | 1925 | sizeof(struct controlvm_message)) < 0) { |
12e364b9 KC |
1926 | POSTCODE_LINUX_2(CRASH_DEV_RD_BUS_FAIULRE_PC, |
1927 | POSTCODE_SEVERITY_ERR); | |
1928 | return; | |
1929 | } | |
1930 | ||
1931 | /* read create device message for storage device */ | |
c3d9a224 | 1932 | if (visorchannel_read(controlvm_channel, |
e6bdb904 | 1933 | local_crash_msg_offset + |
3ab47701 | 1934 | sizeof(struct controlvm_message), |
e6bdb904 | 1935 | &local_crash_dev_msg, |
3ab47701 | 1936 | sizeof(struct controlvm_message)) < 0) { |
12e364b9 KC |
1937 | POSTCODE_LINUX_2(CRASH_DEV_RD_DEV_FAIULRE_PC, |
1938 | POSTCODE_SEVERITY_ERR); | |
1939 | return; | |
1940 | } | |
1941 | ||
1942 | /* reuse IOVM create bus message */ | |
e6bdb904 BR |
1943 | if (local_crash_bus_msg.cmd.create_bus.channel_addr != 0) { |
1944 | bus_create(&local_crash_bus_msg); | |
75c1f8b7 | 1945 | } else { |
12e364b9 KC |
1946 | POSTCODE_LINUX_2(CRASH_DEV_BUS_NULL_FAILURE_PC, |
1947 | POSTCODE_SEVERITY_ERR); | |
1948 | return; | |
1949 | } | |
1950 | ||
1951 | /* reuse create device message for storage device */ | |
e6bdb904 BR |
1952 | if (local_crash_dev_msg.cmd.create_device.channel_addr != 0) { |
1953 | my_device_create(&local_crash_dev_msg); | |
75c1f8b7 | 1954 | } else { |
12e364b9 KC |
1955 | POSTCODE_LINUX_2(CRASH_DEV_DEV_NULL_FAILURE_PC, |
1956 | POSTCODE_SEVERITY_ERR); | |
1957 | return; | |
1958 | } | |
12e364b9 KC |
1959 | POSTCODE_LINUX_2(CRASH_DEV_EXIT_PC, POSTCODE_SEVERITY_INFO); |
1960 | return; | |
1961 | ||
e6bdb904 | 1962 | cleanup: |
12e364b9 | 1963 | |
911e213e | 1964 | poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW; |
12e364b9 | 1965 | |
9232d2d6 BR |
1966 | queue_delayed_work(periodic_controlvm_workqueue, |
1967 | &periodic_controlvm_work, poll_jiffies); | |
12e364b9 KC |
1968 | } |
1969 | ||
1970 | static void | |
52063eca | 1971 | bus_create_response(u32 bus_no, int response) |
12e364b9 | 1972 | { |
8e3fedd6 | 1973 | bus_responder(CONTROLVM_BUS_CREATE, bus_no, response); |
12e364b9 KC |
1974 | } |
1975 | ||
1976 | static void | |
52063eca | 1977 | bus_destroy_response(u32 bus_no, int response) |
12e364b9 | 1978 | { |
8e3fedd6 | 1979 | bus_responder(CONTROLVM_BUS_DESTROY, bus_no, response); |
12e364b9 KC |
1980 | } |
1981 | ||
1982 | static void | |
52063eca | 1983 | device_create_response(u32 bus_no, u32 dev_no, int response) |
12e364b9 | 1984 | { |
8e3fedd6 | 1985 | device_responder(CONTROLVM_DEVICE_CREATE, bus_no, dev_no, response); |
12e364b9 KC |
1986 | } |
1987 | ||
1988 | static void | |
52063eca | 1989 | device_destroy_response(u32 bus_no, u32 dev_no, int response) |
12e364b9 | 1990 | { |
8e3fedd6 | 1991 | device_responder(CONTROLVM_DEVICE_DESTROY, bus_no, dev_no, response); |
12e364b9 KC |
1992 | } |
1993 | ||
1994 | void | |
52063eca | 1995 | visorchipset_device_pause_response(u32 bus_no, u32 dev_no, int response) |
12e364b9 | 1996 | { |
12e364b9 | 1997 | device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE, |
8420f417 | 1998 | bus_no, dev_no, response, |
bd0d2dcc | 1999 | segment_state_standby); |
12e364b9 | 2000 | } |
927c7927 | 2001 | EXPORT_SYMBOL_GPL(visorchipset_device_pause_response); |
12e364b9 KC |
2002 | |
2003 | static void | |
52063eca | 2004 | device_resume_response(u32 bus_no, u32 dev_no, int response) |
12e364b9 KC |
2005 | { |
2006 | device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE, | |
8e3fedd6 | 2007 | bus_no, dev_no, response, |
bd0d2dcc | 2008 | segment_state_running); |
12e364b9 KC |
2009 | } |
2010 | ||
f4c11551 | 2011 | bool |
52063eca | 2012 | visorchipset_get_bus_info(u32 bus_no, struct visorchipset_bus_info *bus_info) |
12e364b9 | 2013 | { |
1390b88c | 2014 | void *p = findbus(&bus_info_list, bus_no); |
26eb2c0c | 2015 | |
0aca7844 | 2016 | if (!p) |
f4c11551 | 2017 | return false; |
77db7127 | 2018 | memcpy(bus_info, p, sizeof(struct visorchipset_bus_info)); |
f4c11551 | 2019 | return true; |
12e364b9 KC |
2020 | } |
2021 | EXPORT_SYMBOL_GPL(visorchipset_get_bus_info); | |
2022 | ||
f4c11551 | 2023 | bool |
52063eca | 2024 | visorchipset_set_bus_context(u32 bus_no, void *context) |
12e364b9 | 2025 | { |
1390b88c | 2026 | struct visorchipset_bus_info *p = findbus(&bus_info_list, bus_no); |
26eb2c0c | 2027 | |
0aca7844 | 2028 | if (!p) |
f4c11551 | 2029 | return false; |
12e364b9 | 2030 | p->bus_driver_context = context; |
f4c11551 | 2031 | return true; |
12e364b9 KC |
2032 | } |
2033 | EXPORT_SYMBOL_GPL(visorchipset_set_bus_context); | |
2034 | ||
f4c11551 | 2035 | bool |
52063eca | 2036 | visorchipset_get_device_info(u32 bus_no, u32 dev_no, |
b486df19 | 2037 | struct visorchipset_device_info *dev_info) |
12e364b9 | 2038 | { |
1390b88c | 2039 | void *p = finddevice(&dev_info_list, bus_no, dev_no); |
26eb2c0c | 2040 | |
0aca7844 | 2041 | if (!p) |
f4c11551 | 2042 | return false; |
b486df19 | 2043 | memcpy(dev_info, p, sizeof(struct visorchipset_device_info)); |
f4c11551 | 2044 | return true; |
12e364b9 KC |
2045 | } |
2046 | EXPORT_SYMBOL_GPL(visorchipset_get_device_info); | |
2047 | ||
f4c11551 | 2048 | bool |
52063eca | 2049 | visorchipset_set_device_context(u32 bus_no, u32 dev_no, void *context) |
12e364b9 | 2050 | { |
246e0cd0 | 2051 | struct visorchipset_device_info *p = |
1390b88c | 2052 | finddevice(&dev_info_list, bus_no, dev_no); |
26eb2c0c | 2053 | |
0aca7844 | 2054 | if (!p) |
f4c11551 | 2055 | return false; |
12e364b9 | 2056 | p->bus_driver_context = context; |
f4c11551 | 2057 | return true; |
12e364b9 KC |
2058 | } |
2059 | EXPORT_SYMBOL_GPL(visorchipset_set_device_context); | |
2060 | ||
2061 | /* Generic wrapper function for allocating memory from a kmem_cache pool. | |
2062 | */ | |
2063 | void * | |
f4c11551 | 2064 | visorchipset_cache_alloc(struct kmem_cache *pool, bool ok_to_block, |
12e364b9 KC |
2065 | char *fn, int ln) |
2066 | { | |
2067 | gfp_t gfp; | |
2068 | void *p; | |
2069 | ||
2070 | if (ok_to_block) | |
2071 | gfp = GFP_KERNEL; | |
2072 | else | |
2073 | gfp = GFP_ATOMIC; | |
2074 | /* __GFP_NORETRY means "ok to fail", meaning | |
2075 | * kmem_cache_alloc() can return NULL, implying the caller CAN | |
2076 | * cope with failure. If you do NOT specify __GFP_NORETRY, | |
2077 | * Linux will go to extreme measures to get memory for you | |
2078 | * (like, invoke oom killer), which will probably cripple the | |
2079 | * system. | |
2080 | */ | |
2081 | gfp |= __GFP_NORETRY; | |
2082 | p = kmem_cache_alloc(pool, gfp); | |
0aca7844 | 2083 | if (!p) |
12e364b9 | 2084 | return NULL; |
0aca7844 | 2085 | |
712f42cd | 2086 | atomic_inc(&visorchipset_cache_buffers_in_use); |
12e364b9 KC |
2087 | return p; |
2088 | } | |
2089 | ||
2090 | /* Generic wrapper function for freeing memory from a kmem_cache pool. | |
2091 | */ | |
2092 | void | |
2093 | visorchipset_cache_free(struct kmem_cache *pool, void *p, char *fn, int ln) | |
2094 | { | |
0aca7844 | 2095 | if (!p) |
12e364b9 | 2096 | return; |
0aca7844 | 2097 | |
712f42cd | 2098 | atomic_dec(&visorchipset_cache_buffers_in_use); |
12e364b9 KC |
2099 | kmem_cache_free(pool, p); |
2100 | } | |
2101 | ||
18b87ed1 | 2102 | static ssize_t chipsetready_store(struct device *dev, |
8e76e695 BR |
2103 | struct device_attribute *attr, |
2104 | const char *buf, size_t count) | |
12e364b9 | 2105 | { |
18b87ed1 | 2106 | char msgtype[64]; |
12e364b9 | 2107 | |
66e24b76 BR |
2108 | if (sscanf(buf, "%63s", msgtype) != 1) |
2109 | return -EINVAL; | |
2110 | ||
2111 | if (strcmp(msgtype, "CALLHOMEDISK_MOUNTED") == 0) { | |
2112 | chipset_events[0] = 1; | |
2113 | return count; | |
2114 | } else if (strcmp(msgtype, "MODULES_LOADED") == 0) { | |
2115 | chipset_events[1] = 1; | |
2116 | return count; | |
e22a4a0f BR |
2117 | } |
2118 | return -EINVAL; | |
12e364b9 KC |
2119 | } |
2120 | ||
e56fa7cd BR |
2121 | /* The parahotplug/devicedisabled interface gets called by our support script |
2122 | * when an SR-IOV device has been shut down. The ID is passed to the script | |
2123 | * and then passed back when the device has been removed. | |
2124 | */ | |
2125 | static ssize_t devicedisabled_store(struct device *dev, | |
8e76e695 BR |
2126 | struct device_attribute *attr, |
2127 | const char *buf, size_t count) | |
e56fa7cd BR |
2128 | { |
2129 | uint id; | |
2130 | ||
2131 | if (kstrtouint(buf, 10, &id) != 0) | |
2132 | return -EINVAL; | |
2133 | ||
2134 | parahotplug_request_complete(id, 0); | |
2135 | return count; | |
2136 | } | |
2137 | ||
2138 | /* The parahotplug/deviceenabled interface gets called by our support script | |
2139 | * when an SR-IOV device has been recovered. The ID is passed to the script | |
2140 | * and then passed back when the device has been brought back up. | |
2141 | */ | |
2142 | static ssize_t deviceenabled_store(struct device *dev, | |
8e76e695 BR |
2143 | struct device_attribute *attr, |
2144 | const char *buf, size_t count) | |
e56fa7cd BR |
2145 | { |
2146 | uint id; | |
2147 | ||
2148 | if (kstrtouint(buf, 10, &id) != 0) | |
2149 | return -EINVAL; | |
2150 | ||
2151 | parahotplug_request_complete(id, 1); | |
2152 | return count; | |
2153 | } | |
2154 | ||
12e364b9 KC |
2155 | static int __init |
2156 | visorchipset_init(void) | |
2157 | { | |
2158 | int rc = 0, x = 0; | |
8a1182eb | 2159 | HOSTADDRESS addr; |
12e364b9 | 2160 | |
fcd0157e KC |
2161 | if (!unisys_spar_platform) |
2162 | return -ENODEV; | |
2163 | ||
6fe345af BR |
2164 | memset(&busdev_server_notifiers, 0, sizeof(busdev_server_notifiers)); |
2165 | memset(&busdev_client_notifiers, 0, sizeof(busdev_client_notifiers)); | |
84982fbf | 2166 | memset(&controlvm_payload_info, 0, sizeof(controlvm_payload_info)); |
ea33b4ee BR |
2167 | memset(&livedump_info, 0, sizeof(livedump_info)); |
2168 | atomic_set(&livedump_info.buffers_in_use, 0); | |
12e364b9 | 2169 | |
9f8d0e8b | 2170 | if (visorchipset_testvnic) { |
9f8d0e8b KC |
2171 | POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, x, DIAG_SEVERITY_ERR); |
2172 | rc = x; | |
a6a3989b | 2173 | goto cleanup; |
9f8d0e8b | 2174 | } |
12e364b9 | 2175 | |
8a1182eb BR |
2176 | addr = controlvm_get_channel_address(); |
2177 | if (addr != 0) { | |
c3d9a224 | 2178 | controlvm_channel = |
8a1182eb BR |
2179 | visorchannel_create_with_lock |
2180 | (addr, | |
d19642f6 | 2181 | sizeof(struct spar_controlvm_channel_protocol), |
5fbaa4b3 | 2182 | spar_controlvm_channel_protocol_uuid); |
93a84565 | 2183 | if (SPAR_CONTROLVM_CHANNEL_OK_CLIENT( |
c3d9a224 | 2184 | visorchannel_get_header(controlvm_channel))) { |
8a1182eb BR |
2185 | initialize_controlvm_payload(); |
2186 | } else { | |
c3d9a224 BR |
2187 | visorchannel_destroy(controlvm_channel); |
2188 | controlvm_channel = NULL; | |
8a1182eb BR |
2189 | return -ENODEV; |
2190 | } | |
2191 | } else { | |
8a1182eb BR |
2192 | return -ENODEV; |
2193 | } | |
2194 | ||
5aa8ae57 BR |
2195 | major_dev = MKDEV(visorchipset_major, 0); |
2196 | rc = visorchipset_file_init(major_dev, &controlvm_channel); | |
4cb005a9 | 2197 | if (rc < 0) { |
4cb005a9 | 2198 | POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR); |
a6a3989b | 2199 | goto cleanup; |
4cb005a9 | 2200 | } |
9f8d0e8b | 2201 | |
da021f02 | 2202 | memset(&g_diag_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
12e364b9 | 2203 | |
da021f02 | 2204 | memset(&g_chipset_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
12e364b9 | 2205 | |
da021f02 | 2206 | memset(&g_del_dump_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
12e364b9 | 2207 | |
1eee0011 BR |
2208 | putfile_buffer_list_pool = |
2209 | kmem_cache_create(putfile_buffer_list_pool_name, | |
12e364b9 KC |
2210 | sizeof(struct putfile_buffer_entry), |
2211 | 0, SLAB_HWCACHE_ALIGN, NULL); | |
1eee0011 | 2212 | if (!putfile_buffer_list_pool) { |
4cb005a9 KC |
2213 | POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR); |
2214 | rc = -1; | |
a6a3989b | 2215 | goto cleanup; |
12e364b9 | 2216 | } |
2098dbd1 | 2217 | if (!visorchipset_disable_controlvm) { |
12e364b9 | 2218 | /* if booting in a crash kernel */ |
1ba00980 | 2219 | if (is_kdump_kernel()) |
9232d2d6 | 2220 | INIT_DELAYED_WORK(&periodic_controlvm_work, |
12e364b9 KC |
2221 | setup_crash_devices_work_queue); |
2222 | else | |
9232d2d6 | 2223 | INIT_DELAYED_WORK(&periodic_controlvm_work, |
12e364b9 | 2224 | controlvm_periodic_work); |
9232d2d6 | 2225 | periodic_controlvm_workqueue = |
12e364b9 KC |
2226 | create_singlethread_workqueue("visorchipset_controlvm"); |
2227 | ||
38f736e9 | 2228 | if (!periodic_controlvm_workqueue) { |
4cb005a9 KC |
2229 | POSTCODE_LINUX_2(CREATE_WORKQUEUE_FAILED_PC, |
2230 | DIAG_SEVERITY_ERR); | |
2231 | rc = -ENOMEM; | |
a6a3989b | 2232 | goto cleanup; |
4cb005a9 | 2233 | } |
b53e0e93 | 2234 | most_recent_message_jiffies = jiffies; |
911e213e | 2235 | poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST; |
9232d2d6 BR |
2236 | rc = queue_delayed_work(periodic_controlvm_workqueue, |
2237 | &periodic_controlvm_work, poll_jiffies); | |
4cb005a9 | 2238 | if (rc < 0) { |
4cb005a9 KC |
2239 | POSTCODE_LINUX_2(QUEUE_DELAYED_WORK_PC, |
2240 | DIAG_SEVERITY_ERR); | |
a6a3989b | 2241 | goto cleanup; |
4cb005a9 | 2242 | } |
12e364b9 KC |
2243 | } |
2244 | ||
eb34e877 BR |
2245 | visorchipset_platform_device.dev.devt = major_dev; |
2246 | if (platform_device_register(&visorchipset_platform_device) < 0) { | |
4cb005a9 KC |
2247 | POSTCODE_LINUX_2(DEVICE_REGISTER_FAILURE_PC, DIAG_SEVERITY_ERR); |
2248 | rc = -1; | |
a6a3989b | 2249 | goto cleanup; |
4cb005a9 | 2250 | } |
12e364b9 | 2251 | POSTCODE_LINUX_2(CHIPSET_INIT_SUCCESS_PC, POSTCODE_SEVERITY_INFO); |
22ad57ba | 2252 | rc = 0; |
a6a3989b | 2253 | cleanup: |
12e364b9 | 2254 | if (rc) { |
12e364b9 KC |
2255 | POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc, |
2256 | POSTCODE_SEVERITY_ERR); | |
2257 | } | |
2258 | return rc; | |
2259 | } | |
2260 | ||
2261 | static void | |
2262 | visorchipset_exit(void) | |
2263 | { | |
12e364b9 KC |
2264 | POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO); |
2265 | ||
2266 | if (visorchipset_disable_controlvm) { | |
2267 | ; | |
2268 | } else { | |
9232d2d6 BR |
2269 | cancel_delayed_work(&periodic_controlvm_work); |
2270 | flush_workqueue(periodic_controlvm_workqueue); | |
2271 | destroy_workqueue(periodic_controlvm_workqueue); | |
2272 | periodic_controlvm_workqueue = NULL; | |
84982fbf | 2273 | destroy_controlvm_payload_info(&controlvm_payload_info); |
12e364b9 | 2274 | } |
1eee0011 BR |
2275 | if (putfile_buffer_list_pool) { |
2276 | kmem_cache_destroy(putfile_buffer_list_pool); | |
2277 | putfile_buffer_list_pool = NULL; | |
12e364b9 | 2278 | } |
1783319f | 2279 | |
12e364b9 KC |
2280 | cleanup_controlvm_structures(); |
2281 | ||
da021f02 | 2282 | memset(&g_diag_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
12e364b9 | 2283 | |
da021f02 | 2284 | memset(&g_chipset_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
12e364b9 | 2285 | |
da021f02 | 2286 | memset(&g_del_dump_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
12e364b9 | 2287 | |
c3d9a224 | 2288 | visorchannel_destroy(controlvm_channel); |
8a1182eb | 2289 | |
addceb12 | 2290 | visorchipset_file_cleanup(visorchipset_platform_device.dev.devt); |
12e364b9 | 2291 | POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO); |
12e364b9 KC |
2292 | } |
2293 | ||
2294 | module_param_named(testvnic, visorchipset_testvnic, int, S_IRUGO); | |
2295 | MODULE_PARM_DESC(visorchipset_testvnic, "1 to test vnic, using dummy VNIC connected via a loopback to a physical ethernet"); | |
12e364b9 KC |
2296 | module_param_named(testvnicclient, visorchipset_testvnicclient, int, S_IRUGO); |
2297 | MODULE_PARM_DESC(visorchipset_testvnicclient, "1 to test vnic, using real VNIC channel attached to a separate IOVM guest"); | |
12e364b9 KC |
2298 | module_param_named(testmsg, visorchipset_testmsg, int, S_IRUGO); |
2299 | MODULE_PARM_DESC(visorchipset_testmsg, | |
2300 | "1 to manufacture the chipset, bus, and switch messages"); | |
12e364b9 | 2301 | module_param_named(major, visorchipset_major, int, S_IRUGO); |
b615d628 JS |
2302 | MODULE_PARM_DESC(visorchipset_major, |
2303 | "major device number to use for the device node"); | |
12e364b9 KC |
2304 | module_param_named(serverregwait, visorchipset_serverregwait, int, S_IRUGO); |
2305 | MODULE_PARM_DESC(visorchipset_serverreqwait, | |
2306 | "1 to have the module wait for the visor bus to register"); | |
12e364b9 KC |
2307 | module_param_named(clientregwait, visorchipset_clientregwait, int, S_IRUGO); |
2308 | MODULE_PARM_DESC(visorchipset_clientregwait, "1 to have the module wait for the visorclientbus to register"); | |
12e364b9 KC |
2309 | module_param_named(testteardown, visorchipset_testteardown, int, S_IRUGO); |
2310 | MODULE_PARM_DESC(visorchipset_testteardown, | |
2311 | "1 to test teardown of the chipset, bus, and switch"); | |
12e364b9 KC |
2312 | module_param_named(disable_controlvm, visorchipset_disable_controlvm, int, |
2313 | S_IRUGO); | |
2314 | MODULE_PARM_DESC(visorchipset_disable_controlvm, | |
2315 | "1 to disable polling of controlVm channel"); | |
12e364b9 KC |
2316 | module_param_named(holdchipsetready, visorchipset_holdchipsetready, |
2317 | int, S_IRUGO); | |
2318 | MODULE_PARM_DESC(visorchipset_holdchipsetready, | |
2319 | "1 to hold response to CHIPSET_READY"); | |
b615d628 | 2320 | |
12e364b9 KC |
2321 | module_init(visorchipset_init); |
2322 | module_exit(visorchipset_exit); | |
2323 | ||
2324 | MODULE_AUTHOR("Unisys"); | |
2325 | MODULE_LICENSE("GPL"); | |
2326 | MODULE_DESCRIPTION("Supervisor chipset driver for service partition: ver " | |
2327 | VERSION); | |
2328 | MODULE_VERSION(VERSION); |