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