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