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