3 * Copyright � 2010 - 2013 UNISYS CORPORATION
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.
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
19 #include "controlvm.h"
20 #include "visorchipset.h"
21 #include "procobjecttree.h"
22 #include "visorchannel.h"
23 #include "periodic_work.h"
29 #include "guidutils.h"
30 #include "controlvmcompletionstatus.h"
31 #include "guestlinuxdebug.h"
34 #include <linux/nls.h>
35 #include <linux/netdevice.h>
36 #include <linux/platform_device.h>
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
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
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.
54 #define MIN_IDLE_SECONDS 10
55 ulong Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_FAST
;
56 ulong Most_recent_message_jiffies
; /* when we got our last
57 * controlvm message */
67 static int serverregistered
;
68 static int clientregistered
;
70 #define MAX_CHIPSET_EVENTS 2
71 static U8 chipset_events
[MAX_CHIPSET_EVENTS
] = { 0, 0 };
73 static struct delayed_work Periodic_controlvm_work
;
74 static struct workqueue_struct
*Periodic_controlvm_workqueue
;
75 DEFINE_SEMAPHORE(NotifierLock
);
78 CONTROLVM_MESSAGE message
;
82 static CONTROLVM_MESSAGE_HEADER g_DiagMsgHdr
;
83 static CONTROLVM_MESSAGE_HEADER g_ChipSetMsgHdr
;
84 static CONTROLVM_MESSAGE_HEADER g_DelDumpMsgHdr
;
85 static const GUID UltraDiagPoolChannelProtocolGuid
=
86 ULTRA_DIAG_POOL_CHANNEL_PROTOCOL_GUID
;
87 /* 0xffffff is an invalid Bus/Device number */
88 static ulong g_diagpoolBusNo
= 0xffffff;
89 static ulong g_diagpoolDevNo
= 0xffffff;
90 static CONTROLVM_MESSAGE_PACKET g_DeviceChangeStatePacket
;
92 /* Only VNIC and VHBA channels are sent to visorclientbus (aka
95 #define FOR_VISORHACKBUS(channel_type_guid) \
96 ((memcmp(&channel_type_guid, &UltraVnicChannelProtocolGuid, \
97 sizeof(GUID)) == 0) || \
98 (memcmp(&channel_type_guid, &UltraVhbaChannelProtocolGuid, \
100 #define FOR_VISORBUS(channel_type_guid) (!(FOR_VISORHACKBUS(channel_type_guid)))
102 #define is_diagpool_channel(channel_type_guid) \
103 (memcmp(&channel_type_guid, \
104 &UltraDiagPoolChannelProtocolGuid, sizeof(GUID)) == 0)
109 PARTPROP_description
,
112 /* add new properties above, but don't forget to change
113 * InitPartitionProperties() and show_partition_property() also...
116 } PARTITION_property
;
117 static const char *PartitionTypeNames
[] = { "partition", NULL
};
119 static char *PartitionPropertyNames
[PARTPROP_last
+ 1];
121 InitPartitionProperties(void)
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
;
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...
145 } CONTROLVM_property
;
147 static const char *ControlVmTypeNames
[] = { "controlvm", NULL
};
149 static char *ControlVmPropertyNames
[CTLVMPROP_last
+ 1];
151 InitControlVmProperties(void)
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
;
165 static MYPROCOBJECT
*ControlVmObject
;
166 static MYPROCTYPE
*PartitionType
;
167 static MYPROCTYPE
*ControlVmType
;
169 #define VISORCHIPSET_DIAG_PROC_ENTRY_FN "diagdump"
170 static struct proc_dir_entry
*diag_proc_dir
;
172 #define VISORCHIPSET_CHIPSET_PROC_ENTRY_FN "chipsetready"
173 static struct proc_dir_entry
*chipset_proc_dir
;
175 #define VISORCHIPSET_PARAHOTPLUG_PROC_ENTRY_FN "parahotplug"
176 static struct proc_dir_entry
*parahotplug_proc_dir
;
178 static LIST_HEAD(BusInfoList
);
179 static LIST_HEAD(DevInfoList
);
181 static struct proc_dir_entry
*ProcDir
;
182 static VISORCHANNEL
*ControlVm_channel
;
184 static ssize_t
visorchipset_proc_read_writeonly(struct file
*file
,
186 size_t len
, loff_t
*offset
);
187 static ssize_t
proc_read_installer(struct file
*file
, char __user
*buf
,
188 size_t len
, loff_t
*offset
);
189 static ssize_t
proc_write_installer(struct file
*file
,
190 const char __user
*buffer
,
191 size_t count
, loff_t
*ppos
);
192 static ssize_t
proc_read_toolaction(struct file
*file
, char __user
*buf
,
193 size_t len
, loff_t
*offset
);
194 static ssize_t
proc_write_toolaction(struct file
*file
,
195 const char __user
*buffer
,
196 size_t count
, loff_t
*ppos
);
197 static ssize_t
proc_read_bootToTool(struct file
*file
, char __user
*buf
,
198 size_t len
, loff_t
*offset
);
199 static ssize_t
proc_write_bootToTool(struct file
*file
,
200 const char __user
*buffer
,
201 size_t count
, loff_t
*ppos
);
202 static const struct file_operations proc_installer_fops
= {
203 .read
= proc_read_installer
,
204 .write
= proc_write_installer
,
207 static const struct file_operations proc_toolaction_fops
= {
208 .read
= proc_read_toolaction
,
209 .write
= proc_write_toolaction
,
212 static const struct file_operations proc_bootToTool_fops
= {
213 .read
= proc_read_bootToTool
,
214 .write
= proc_write_bootToTool
,
218 U8
*ptr
; /* pointer to base address of payload pool */
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
;
224 /* Manages the request payload in the controlvm channel */
225 static CONTROLVM_PAYLOAD_INFO ControlVm_payload_info
;
227 static pCHANNEL_HEADER Test_Vnic_channel
;
230 CONTROLVM_MESSAGE_HEADER Dumpcapture_header
;
231 CONTROLVM_MESSAGE_HEADER Gettextdump_header
;
232 CONTROLVM_MESSAGE_HEADER Dumpcomplete_header
;
233 BOOL Gettextdump_outstanding
;
236 atomic_t buffers_in_use
;
239 /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
240 * CONTROLVM_DUMP_GETTEXTDUMP / CONTROLVM_DUMP_COMPLETE conversation.
242 static LIVEDUMP_INFO LiveDump_info
;
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.
249 static CONTROLVM_MESSAGE ControlVm_Pending_Msg
;
250 static BOOL ControlVm_Pending_Msg_Valid
= FALSE
;
252 /* Pool of struct putfile_buffer_entry, for keeping track of pending (incoming)
253 * TRANSMIT_FILE PutFile payloads.
255 static struct kmem_cache
*Putfile_buffer_list_pool
;
256 static const char Putfile_buffer_list_pool_name
[] =
257 "controlvm_putfile_buffer_list_pool";
259 /* This identifies a data buffer that has been received via a controlvm messages
260 * in a remote --> local CONTROLVM_TRANSMIT_FILE conversation.
262 struct putfile_buffer_entry
{
263 struct list_head next
; /* putfile_buffer_entry list */
264 PARSER_CONTEXT
*parser_ctx
; /* points to buffer containing input data */
267 /* List of struct putfile_request *, via next_putfile_request member.
268 * Each entry in this list identifies an outstanding TRANSMIT_FILE
271 static LIST_HEAD(Putfile_request_list
);
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.
277 struct 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 */
282 /* # bytes left from <pnext> to the end of this data buffer */
283 size_t bytes_remaining
;
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>.
291 struct putfile_request
{
292 u64 sig
; /* PUTFILE_REQUEST_SIG */
294 /* header from original TransmitFile request */
295 CONTROLVM_MESSAGE_HEADER controlvm_header
;
296 u64 file_request_number
; /* from original TransmitFile request */
298 /* link to next struct putfile_request */
299 struct list_head next_putfile_request
;
301 /* most-recent sequence number supplied via a controlvm message */
302 u64 data_sequence_number
;
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
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 */
313 /* waiters for input_buffer_list to go non-empty */
314 wait_queue_head_t input_buffer_wq
;
316 /* data not yet read within current putfile_buffer_entry */
317 struct putfile_active_buffer active_buf
;
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
;
327 atomic_t Visorchipset_cache_buffers_in_use
= ATOMIC_INIT(0);
329 struct parahotplug_request
{
330 struct list_head list
;
332 unsigned long expiration
;
333 CONTROLVM_MESSAGE msg
;
336 static LIST_HEAD(Parahotplug_request_list
);
337 static DEFINE_SPINLOCK(Parahotplug_request_list_lock
); /* lock for above */
338 static void parahotplug_process_list(void);
340 /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
341 * CONTROLVM_REPORTEVENT.
343 static VISORCHIPSET_BUSDEV_NOTIFIERS BusDev_Server_Notifiers
;
344 static VISORCHIPSET_BUSDEV_NOTIFIERS BusDev_Client_Notifiers
;
346 static void bus_create_response(ulong busNo
, int response
);
347 static void bus_destroy_response(ulong busNo
, int response
);
348 static void device_create_response(ulong busNo
, ulong devNo
, int response
);
349 static void device_destroy_response(ulong busNo
, ulong devNo
, int response
);
350 static void device_resume_response(ulong busNo
, ulong devNo
, int response
);
352 static 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
,
357 .device_pause
= visorchipset_device_pause_response
,
358 .device_resume
= device_resume_response
,
361 /* info for /dev/visorchipset */
362 static dev_t MajorDev
= -1; /**< indicates major num for device */
364 /* /sys/devices/platform/visorchipset */
365 static struct platform_device Visorchipset_platform_device
= {
366 .name
= "visorchipset",
370 /* Function prototypes */
371 static void controlvm_respond(CONTROLVM_MESSAGE_HEADER
*msgHdr
, int response
);
372 static void controlvm_respond_chipset_init(CONTROLVM_MESSAGE_HEADER
*msgHdr
,
374 ULTRA_CHIPSET_FEATURE features
);
375 static void controlvm_respond_physdev_changestate(CONTROLVM_MESSAGE_HEADER
*
376 msgHdr
, int response
,
377 ULTRA_SEGMENT_STATE state
);
380 show_partition_property(struct seq_file
*f
, void *ctx
, int property
)
382 VISORCHIPSET_BUS_INFO
*info
= (VISORCHIPSET_BUS_INFO
*) (ctx
);
386 seq_printf(f
, "%s\n", NONULLSTR(info
->name
));
388 case PARTPROP_description
:
389 seq_printf(f
, "%s\n", NONULLSTR(info
->description
));
391 case PARTPROP_handle
:
392 seq_printf(f
, "0x%-16.16Lx\n", info
->partitionHandle
);
394 case PARTPROP_busNumber
:
395 seq_printf(f
, "%d\n", info
->busNo
);
398 seq_printf(f
, "(%d??)\n", property
);
404 show_controlvm_property(struct seq_file
*f
, void *ctx
, int property
)
406 /* Note: ctx is not needed since we only have 1 controlvm channel */
408 case CTLVMPROP_physAddr
:
409 if (ControlVm_channel
== NULL
)
410 seq_puts(f
, "0x0\n");
412 seq_printf(f
, "0x%-16.16Lx\n",
413 visorchannel_get_physaddr
414 (ControlVm_channel
));
416 case CTLVMPROP_controlChannelAddr
:
417 if (ControlVm_channel
== NULL
)
418 seq_puts(f
, "0x0\n");
420 GUEST_PHYSICAL_ADDRESS addr
= 0;
421 visorchannel_read(ControlVm_channel
,
423 (ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
424 gpControlChannel
), &addr
,
426 seq_printf(f
, "0x%-16.16Lx\n", (u64
) (addr
));
429 case CTLVMPROP_controlChannelBytes
:
430 if (ControlVm_channel
== NULL
)
431 seq_puts(f
, "0x0\n");
434 visorchannel_read(ControlVm_channel
,
436 (ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
437 ControlChannelBytes
), &bytes
,
439 seq_printf(f
, "%lu\n", (ulong
) (bytes
));
442 case CTLVMPROP_sparBootPart
:
443 seq_puts(f
, "0:0:0:0/1\n");
445 case CTLVMPROP_sparStoragePart
:
446 seq_puts(f
, "0:0:0:0/2\n");
448 case CTLVMPROP_livedumpLength
:
449 seq_printf(f
, "%lu\n", LiveDump_info
.length
);
451 case CTLVMPROP_livedumpCrc32
:
452 seq_printf(f
, "%lu\n", (ulong
) LiveDump_info
.crc32
);
455 seq_printf(f
, "(%d??)\n", property
);
463 if (ProcDir
== NULL
) {
464 ProcDir
= proc_mkdir(MYDRVNAME
, NULL
);
465 if (ProcDir
== NULL
) {
466 LOGERR("failed to create /proc directory %s",
468 POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC
,
469 POSTCODE_SEVERITY_ERR
);
478 remove_proc_entry(MYDRVNAME
, NULL
);
486 wchar_t unicodeString
[] = { 'a', 'b', 'c', 0 };
487 char s
[sizeof(unicodeString
) * NLS_MAX_CHARSET_SIZE
];
488 wchar_t unicode2
[99];
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
495 LOGINF("sizeof(wchar_t) = %d", sizeof(wchar_t));
496 LOGINF("utf8_wcstombs=%d",
497 chrs
= utf8_wcstombs(s
, unicodeString
, sizeof(s
)));
499 s
[chrs
] = '\0'; /* GRRRRRRRR */
501 LOGINF("utf8_mbstowcs=%d", chrs
= utf8_mbstowcs(unicode2
, s
, 100));
503 unicode2
[chrs
] = 0; /* GRRRRRRRR */
504 if (memcmp(unicodeString
, unicode2
, sizeof(unicodeString
)) == 0)
505 LOGINF("strings match... good");
507 LOGINF("strings did not match!!");
512 busInfo_clear(void *v
)
514 VISORCHIPSET_BUS_INFO
*p
= (VISORCHIPSET_BUS_INFO
*) (v
);
517 visor_proc_DestroyObject(p
->procObject
);
518 p
->procObject
= NULL
;
523 kfree(p
->description
);
524 p
->description
= NULL
;
526 p
->state
.created
= 0;
527 memset(p
, 0, sizeof(VISORCHIPSET_BUS_INFO
));
531 devInfo_clear(void *v
)
533 VISORCHIPSET_DEVICE_INFO
*p
= (VISORCHIPSET_DEVICE_INFO
*) (v
);
534 p
->state
.created
= 0;
535 memset(p
, 0, sizeof(VISORCHIPSET_DEVICE_INFO
));
539 check_chipset_events(void)
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
];
550 clear_chipset_events(void)
553 /* Clear chipset_events */
554 for (i
= 0; i
< MAX_CHIPSET_EVENTS
; i
++)
555 chipset_events
[i
] = 0;
559 visorchipset_register_busdev_server(VISORCHIPSET_BUSDEV_NOTIFIERS
*notifiers
,
560 VISORCHIPSET_BUSDEV_RESPONDERS
*responders
,
561 ULTRA_VBUS_DEVICEINFO
*driverInfo
)
563 LOCKSEM_UNINTERRUPTIBLE(&NotifierLock
);
564 if (notifiers
== NULL
) {
565 memset(&BusDev_Server_Notifiers
, 0,
566 sizeof(BusDev_Server_Notifiers
));
567 serverregistered
= 0; /* clear flag */
569 BusDev_Server_Notifiers
= *notifiers
;
570 serverregistered
= 1; /* set flag */
573 *responders
= BusDev_Responders
;
575 BusDeviceInfo_Init(driverInfo
, "chipset", "visorchipset",
576 VERSION
, NULL
, __DATE__
, __TIME__
);
578 UNLOCKSEM(&NotifierLock
);
580 EXPORT_SYMBOL_GPL(visorchipset_register_busdev_server
);
583 visorchipset_register_busdev_client(VISORCHIPSET_BUSDEV_NOTIFIERS
*notifiers
,
584 VISORCHIPSET_BUSDEV_RESPONDERS
*responders
,
585 ULTRA_VBUS_DEVICEINFO
*driverInfo
)
587 LOCKSEM_UNINTERRUPTIBLE(&NotifierLock
);
588 if (notifiers
== NULL
) {
589 memset(&BusDev_Client_Notifiers
, 0,
590 sizeof(BusDev_Client_Notifiers
));
591 clientregistered
= 0; /* clear flag */
593 BusDev_Client_Notifiers
= *notifiers
;
594 clientregistered
= 1; /* set flag */
597 *responders
= BusDev_Responders
;
599 BusDeviceInfo_Init(driverInfo
, "chipset(bolts)", "visorchipset",
600 VERSION
, NULL
, __DATE__
, __TIME__
);
601 UNLOCKSEM(&NotifierLock
);
603 EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client
);
606 cleanup_controlvm_structures(void)
608 VISORCHIPSET_BUS_INFO
*bi
;
609 VISORCHIPSET_DEVICE_INFO
*di
;
611 list_for_each_entry(bi
, &BusInfoList
, entry
) {
613 list_del(&bi
->entry
);
617 list_for_each_entry(di
, &DevInfoList
, entry
) {
619 list_del(&di
->entry
);
625 chipset_init(CONTROLVM_MESSAGE
*inmsg
)
627 static int chipset_inited
;
628 ULTRA_CHIPSET_FEATURE features
= 0;
629 int rc
= CONTROLVM_RESP_SUCCESS
;
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
);
637 POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
639 /* Set features to indicate we support parahotplug (if Command
640 * also supports it). */
642 inmsg
->cmd
.initChipset
.
643 features
& ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG
;
645 /* Set the "reply" bit so Command knows this is a
646 * features-aware driver. */
647 features
|= ULTRA_CHIPSET_FEATURE_REPLY
;
651 cleanup_controlvm_structures();
652 if (inmsg
->hdr
.Flags
.responseExpected
)
653 controlvm_respond_chipset_init(&inmsg
->hdr
, rc
, features
);
657 controlvm_init_response(CONTROLVM_MESSAGE
*msg
,
658 CONTROLVM_MESSAGE_HEADER
*msgHdr
, int response
)
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;
666 msg
->hdr
.Flags
.failed
= 1;
667 msg
->hdr
.CompletionStatus
= (U32
) (-response
);
672 controlvm_respond(CONTROLVM_MESSAGE_HEADER
*msgHdr
, int response
)
674 CONTROLVM_MESSAGE outmsg
;
675 if (!ControlVm_channel
)
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
==
683 && g_DeviceChangeStatePacket
.deviceChangeState
.devNo
==
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
);
691 if (!visorchannel_signalinsert(ControlVm_channel
,
692 CONTROLVM_QUEUE_REQUEST
, &outmsg
)) {
693 LOGERR("signalinsert failed!");
699 controlvm_respond_chipset_init(CONTROLVM_MESSAGE_HEADER
*msgHdr
, int response
,
700 ULTRA_CHIPSET_FEATURE features
)
702 CONTROLVM_MESSAGE outmsg
;
703 if (!ControlVm_channel
)
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!");
715 controlvm_respond_physdev_changestate(CONTROLVM_MESSAGE_HEADER
*msgHdr
,
716 int response
, ULTRA_SEGMENT_STATE state
)
718 CONTROLVM_MESSAGE outmsg
;
719 if (!ControlVm_channel
)
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!");
732 visorchipset_save_message(CONTROLVM_MESSAGE
*msg
, CRASH_OBJ_TYPE type
)
734 U32 localSavedCrashMsgOffset
;
735 U16 localSavedCrashMsgCount
;
737 /* get saved message count */
738 if (visorchannel_read(ControlVm_channel
,
739 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
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
);
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
);
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
);
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
);
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
);
789 EXPORT_SYMBOL_GPL(visorchipset_save_message
);
792 bus_responder(CONTROLVM_ID cmdId
, ulong busNo
, int response
)
794 VISORCHIPSET_BUS_INFO
*p
= NULL
;
795 BOOL need_clear
= FALSE
;
797 p
= findbus(&BusInfoList
, busNo
);
799 LOGERR("internal error busNo=%lu", busNo
);
803 if ((cmdId
== CONTROLVM_BUS_CREATE
) &&
804 (response
!= (-CONTROLVM_RESP_ERROR_ALREADY_DONE
)))
805 /* undo the row we just created... */
806 delbusdevices(&DevInfoList
, busNo
);
808 if (cmdId
== CONTROLVM_BUS_CREATE
)
809 p
->state
.created
= 1;
810 if (cmdId
== CONTROLVM_BUS_DESTROY
)
814 if (p
->pendingMsgHdr
.Id
== CONTROLVM_INVALID
) {
815 LOGERR("bus_responder no pending msg");
816 return; /* no controlvm response needed */
818 if (p
->pendingMsgHdr
.Id
!= (U32
) cmdId
) {
819 LOGERR("expected=%d, found=%d", cmdId
, p
->pendingMsgHdr
.Id
);
822 controlvm_respond(&p
->pendingMsgHdr
, response
);
823 p
->pendingMsgHdr
.Id
= CONTROLVM_INVALID
;
826 delbusdevices(&DevInfoList
, busNo
);
831 device_changestate_responder(CONTROLVM_ID cmdId
,
832 ulong busNo
, ulong devNo
, int response
,
833 ULTRA_SEGMENT_STATE responseState
)
835 VISORCHIPSET_DEVICE_INFO
*p
= NULL
;
836 CONTROLVM_MESSAGE outmsg
;
838 if (!ControlVm_channel
)
841 p
= finddevice(&DevInfoList
, busNo
, devNo
);
843 LOGERR("internal error; busNo=%lu, devNo=%lu", busNo
, devNo
);
846 if (p
->pendingMsgHdr
.Id
== CONTROLVM_INVALID
) {
847 LOGERR("device_responder no pending msg");
848 return; /* no controlvm response needed */
850 if (p
->pendingMsgHdr
.Id
!= cmdId
) {
851 LOGERR("expected=%d, found=%d", cmdId
, p
->pendingMsgHdr
.Id
);
855 controlvm_init_response(&outmsg
, &p
->pendingMsgHdr
, response
);
857 outmsg
.cmd
.deviceChangeState
.busNo
= busNo
;
858 outmsg
.cmd
.deviceChangeState
.devNo
= devNo
;
859 outmsg
.cmd
.deviceChangeState
.state
= responseState
;
861 if (!visorchannel_signalinsert(ControlVm_channel
,
862 CONTROLVM_QUEUE_REQUEST
, &outmsg
)) {
863 LOGERR("signalinsert failed!");
867 p
->pendingMsgHdr
.Id
= CONTROLVM_INVALID
;
871 device_responder(CONTROLVM_ID cmdId
, ulong busNo
, ulong devNo
, int response
)
873 VISORCHIPSET_DEVICE_INFO
*p
= NULL
;
874 BOOL need_clear
= FALSE
;
876 p
= finddevice(&DevInfoList
, busNo
, devNo
);
878 LOGERR("internal error; busNo=%lu, devNo=%lu", busNo
, devNo
);
882 if (cmdId
== CONTROLVM_DEVICE_CREATE
)
883 p
->state
.created
= 1;
884 if (cmdId
== CONTROLVM_DEVICE_DESTROY
)
888 if (p
->pendingMsgHdr
.Id
== CONTROLVM_INVALID
) {
889 LOGERR("device_responder no pending msg");
890 return; /* no controlvm response needed */
892 if (p
->pendingMsgHdr
.Id
!= (U32
) cmdId
) {
893 LOGERR("expected=%d, found=%d", cmdId
, p
->pendingMsgHdr
.Id
);
896 controlvm_respond(&p
->pendingMsgHdr
, response
);
897 p
->pendingMsgHdr
.Id
= CONTROLVM_INVALID
;
903 bus_epilog(U32 busNo
,
904 U32 cmd
, CONTROLVM_MESSAGE_HEADER
*msgHdr
,
905 int response
, BOOL needResponse
)
907 BOOL notified
= FALSE
;
909 VISORCHIPSET_BUS_INFO
*pBusInfo
= findbus(&BusInfoList
, busNo
);
912 LOGERR("HUH? bad busNo=%d", busNo
);
916 memcpy(&pBusInfo
->pendingMsgHdr
, msgHdr
,
917 sizeof(CONTROLVM_MESSAGE_HEADER
));
919 pBusInfo
->pendingMsgHdr
.Id
= CONTROLVM_INVALID
;
921 LOCKSEM_UNINTERRUPTIBLE(&NotifierLock
);
922 if (response
== CONTROLVM_RESP_SUCCESS
) {
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
935 if (BusDev_Server_Notifiers
.bus_create
) {
936 (*BusDev_Server_Notifiers
.bus_create
) (busNo
);
939 if ((!pBusInfo
->flags
.server
) /*client */ &&
940 BusDev_Client_Notifiers
.bus_create
) {
941 (*BusDev_Client_Notifiers
.bus_create
) (busNo
);
945 case CONTROLVM_BUS_DESTROY
:
946 if (BusDev_Server_Notifiers
.bus_destroy
) {
947 (*BusDev_Server_Notifiers
.bus_destroy
) (busNo
);
950 if ((!pBusInfo
->flags
.server
) /*client */ &&
951 BusDev_Client_Notifiers
.bus_destroy
) {
952 (*BusDev_Client_Notifiers
.bus_destroy
) (busNo
);
959 /* The callback function just called above is responsible
960 * for calling the appropriate VISORCHIPSET_BUSDEV_RESPONDERS
961 * function, which will call bus_responder()
965 bus_responder(cmd
, busNo
, response
);
966 UNLOCKSEM(&NotifierLock
);
970 device_epilog(U32 busNo
, U32 devNo
, ULTRA_SEGMENT_STATE state
, U32 cmd
,
971 CONTROLVM_MESSAGE_HEADER
*msgHdr
, int response
,
972 BOOL needResponse
, BOOL for_visorbus
)
974 VISORCHIPSET_BUSDEV_NOTIFIERS
*notifiers
= NULL
;
975 BOOL notified
= FALSE
;
977 VISORCHIPSET_DEVICE_INFO
*pDevInfo
=
978 finddevice(&DevInfoList
, busNo
, devNo
);
980 "SPARSP_DIAGPOOL_PAUSED_STATE = 1",
985 LOGERR("HUH? bad busNo=%d, devNo=%d", busNo
, devNo
);
989 notifiers
= &BusDev_Server_Notifiers
;
991 notifiers
= &BusDev_Client_Notifiers
;
993 memcpy(&pDevInfo
->pendingMsgHdr
, msgHdr
,
994 sizeof(CONTROLVM_MESSAGE_HEADER
));
996 pDevInfo
->pendingMsgHdr
.Id
= CONTROLVM_INVALID
;
998 LOCKSEM_UNINTERRUPTIBLE(&NotifierLock
);
1001 case CONTROLVM_DEVICE_CREATE
:
1002 if (notifiers
->device_create
) {
1003 (*notifiers
->device_create
) (busNo
, devNo
);
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
,
1017 /* ServerNotReady / ServerLost / SegmentStateStandby */
1018 else if (state
.Alive
== SegmentStateStandby
.Alive
&&
1020 SegmentStateStandby
.Operating
) {
1021 /* technically this is standby case
1022 * where server is lost
1024 if (notifiers
->device_pause
) {
1025 (*notifiers
->device_pause
) (busNo
,
1029 } else if (state
.Alive
== SegmentStatePaused
.Alive
&&
1031 SegmentStatePaused
.Operating
) {
1032 /* this is lite pause where channel is
1033 * still valid just 'pause' of it
1035 if (busNo
== g_diagpoolBusNo
1036 && devNo
== g_diagpoolDevNo
) {
1037 LOGINF("DEVICE_CHANGESTATE(DiagpoolChannel busNo=%d devNo=%d is pausing...)",
1039 /* this will trigger the
1040 * diag_shutdown.sh script in
1041 * the visorchipset hotplug */
1043 (&Visorchipset_platform_device
.dev
.
1044 kobj
, KOBJ_ONLINE
, envp
);
1048 case CONTROLVM_DEVICE_DESTROY
:
1049 if (notifiers
->device_destroy
) {
1050 (*notifiers
->device_destroy
) (busNo
, devNo
);
1057 /* The callback function just called above is responsible
1058 * for calling the appropriate VISORCHIPSET_BUSDEV_RESPONDERS
1059 * function, which will call device_responder()
1063 device_responder(cmd
, busNo
, devNo
, response
);
1064 UNLOCKSEM(&NotifierLock
);
1068 bus_create(CONTROLVM_MESSAGE
*inmsg
)
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
;
1076 pBusInfo
= findbus(&BusInfoList
, busNo
);
1077 if (pBusInfo
&& (pBusInfo
->state
.created
== 1)) {
1078 LOGERR("CONTROLVM_BUS_CREATE Failed: bus %lu already exists",
1080 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC
, busNo
,
1081 POSTCODE_SEVERITY_ERR
);
1082 RETINT(-CONTROLVM_RESP_ERROR_ALREADY_DONE
);
1084 pBusInfo
= kzalloc(sizeof(VISORCHIPSET_BUS_INFO
), GFP_KERNEL
);
1085 if (pBusInfo
== NULL
) {
1086 LOGERR("CONTROLVM_BUS_CREATE Failed: bus %lu kzalloc failed",
1088 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC
, busNo
,
1089 POSTCODE_SEVERITY_ERR
);
1090 RETINT(-CONTROLVM_RESP_ERROR_KMALLOC_FAILED
);
1093 INIT_LIST_HEAD(&pBusInfo
->entry
);
1094 pBusInfo
->busNo
= busNo
;
1095 pBusInfo
->devNo
= cmd
->createBus
.deviceCount
;
1097 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC
, busNo
, POSTCODE_SEVERITY_INFO
);
1099 if (inmsg
->hdr
.Flags
.testMessage
== 1)
1100 pBusInfo
->chanInfo
.addrType
= ADDRTYPE_localTest
;
1102 pBusInfo
->chanInfo
.addrType
= ADDRTYPE_localPhysical
;
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
;
1110 list_add(&pBusInfo
->entry
, &BusInfoList
);
1112 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC
, busNo
, POSTCODE_SEVERITY_INFO
);
1115 bus_epilog(busNo
, CONTROLVM_BUS_CREATE
, &inmsg
->hdr
,
1116 rc
, inmsg
->hdr
.Flags
.responseExpected
== 1);
1120 bus_destroy(CONTROLVM_MESSAGE
*inmsg
)
1122 CONTROLVM_MESSAGE_PACKET
*cmd
= &inmsg
->cmd
;
1123 ulong busNo
= cmd
->destroyBus
.busNo
;
1124 VISORCHIPSET_BUS_INFO
*pBusInfo
;
1125 int rc
= CONTROLVM_RESP_SUCCESS
;
1127 pBusInfo
= findbus(&BusInfoList
, busNo
);
1129 LOGERR("CONTROLVM_BUS_DESTROY Failed: bus %lu invalid", busNo
);
1130 RETINT(-CONTROLVM_RESP_ERROR_BUS_INVALID
);
1132 if (pBusInfo
->state
.created
== 0) {
1133 LOGERR("CONTROLVM_BUS_DESTROY Failed: bus %lu already destroyed",
1135 RETINT(-CONTROLVM_RESP_ERROR_ALREADY_DONE
);
1139 bus_epilog(busNo
, CONTROLVM_BUS_DESTROY
, &inmsg
->hdr
,
1140 rc
, inmsg
->hdr
.Flags
.responseExpected
== 1);
1144 bus_configure(CONTROLVM_MESSAGE
*inmsg
, PARSER_CONTEXT
*parser_ctx
)
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
;
1152 busNo
= cmd
->configureBus
.busNo
;
1153 POSTCODE_LINUX_3(BUS_CONFIGURE_ENTRY_PC
, busNo
, POSTCODE_SEVERITY_INFO
);
1155 pBusInfo
= findbus(&BusInfoList
, busNo
);
1157 LOGERR("CONTROLVM_BUS_CONFIGURE Failed: bus %lu invalid",
1159 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC
, busNo
,
1160 POSTCODE_SEVERITY_ERR
);
1161 RETINT(-CONTROLVM_RESP_ERROR_BUS_INVALID
);
1163 if (pBusInfo
->state
.created
== 0) {
1164 LOGERR("CONTROLVM_BUS_CONFIGURE Failed: Invalid bus %lu - not created yet",
1166 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC
, busNo
,
1167 POSTCODE_SEVERITY_ERR
);
1168 RETINT(-CONTROLVM_RESP_ERROR_BUS_INVALID
);
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
);
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
);
1184 visorchannel_GUID_id(&pBusInfo
->partitionGuid
, s
);
1185 pBusInfo
->procObject
=
1186 visor_proc_CreateObject(PartitionType
, s
, (void *) (pBusInfo
));
1187 if (pBusInfo
->procObject
== NULL
) {
1188 LOGERR("CONTROLVM_BUS_CONFIGURE Failed: busNo=%lu failed to create /proc entry",
1190 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC
, busNo
,
1191 POSTCODE_SEVERITY_ERR
);
1192 RETINT(-CONTROLVM_RESP_ERROR_KMALLOC_FAILED
);
1194 POSTCODE_LINUX_3(BUS_CONFIGURE_EXIT_PC
, busNo
, POSTCODE_SEVERITY_INFO
);
1196 bus_epilog(busNo
, CONTROLVM_BUS_CONFIGURE
, &inmsg
->hdr
,
1197 rc
, inmsg
->hdr
.Flags
.responseExpected
== 1);
1201 my_device_create(CONTROLVM_MESSAGE
*inmsg
)
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
;
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",
1214 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC
, devNo
, busNo
,
1215 POSTCODE_SEVERITY_ERR
);
1216 RETINT(-CONTROLVM_RESP_ERROR_ALREADY_DONE
);
1218 pBusInfo
= findbus(&BusInfoList
, busNo
);
1220 LOGERR("CONTROLVM_DEVICE_CREATE Failed: Invalid bus %lu - out of range",
1222 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC
, devNo
, busNo
,
1223 POSTCODE_SEVERITY_ERR
);
1224 RETINT(-CONTROLVM_RESP_ERROR_BUS_INVALID
);
1226 if (pBusInfo
->state
.created
== 0) {
1227 LOGERR("CONTROLVM_DEVICE_CREATE Failed: Invalid bus %lu - not created yet",
1229 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC
, devNo
, busNo
,
1230 POSTCODE_SEVERITY_ERR
);
1231 RETINT(-CONTROLVM_RESP_ERROR_BUS_INVALID
);
1233 pDevInfo
= kzalloc(sizeof(VISORCHIPSET_DEVICE_INFO
), GFP_KERNEL
);
1234 if (pDevInfo
== NULL
) {
1235 LOGERR("CONTROLVM_DEVICE_CREATE Failed: busNo=%lu, devNo=%lu kmaloc failed",
1237 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC
, devNo
, busNo
,
1238 POSTCODE_SEVERITY_ERR
);
1239 RETINT(-CONTROLVM_RESP_ERROR_KMALLOC_FAILED
);
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
);
1249 if (inmsg
->hdr
.Flags
.testMessage
== 1)
1250 pDevInfo
->chanInfo
.addrType
= ADDRTYPE_localTest
;
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
);
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
);
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
));
1275 my_device_changestate(CONTROLVM_MESSAGE
*inmsg
)
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
;
1284 pDevInfo
= finddevice(&DevInfoList
, busNo
, devNo
);
1286 LOGERR("CONTROLVM_DEVICE_CHANGESTATE Failed: busNo=%lu, devNo=%lu invalid (doesn't exist)",
1288 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC
, devNo
, busNo
,
1289 POSTCODE_SEVERITY_ERR
);
1290 RETINT(-CONTROLVM_RESP_ERROR_DEVICE_INVALID
);
1292 if (pDevInfo
->state
.created
== 0) {
1293 LOGERR("CONTROLVM_DEVICE_CHANGESTATE Failed: busNo=%lu, devNo=%lu invalid (not created)",
1295 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC
, devNo
, busNo
,
1296 POSTCODE_SEVERITY_ERR
);
1297 RETINT(-CONTROLVM_RESP_ERROR_DEVICE_INVALID
);
1300 if ((rc
>= CONTROLVM_RESP_SUCCESS
) && pDevInfo
)
1301 device_epilog(busNo
, devNo
, state
, CONTROLVM_DEVICE_CHANGESTATE
,
1303 inmsg
->hdr
.Flags
.responseExpected
== 1,
1304 FOR_VISORBUS(pDevInfo
->chanInfo
.channelTypeGuid
));
1308 my_device_destroy(CONTROLVM_MESSAGE
*inmsg
)
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
;
1316 pDevInfo
= finddevice(&DevInfoList
, busNo
, devNo
);
1318 LOGERR("CONTROLVM_DEVICE_DESTROY Failed: busNo=%lu, devNo=%lu invalid",
1320 RETINT(-CONTROLVM_RESP_ERROR_DEVICE_INVALID
);
1322 if (pDevInfo
->state
.created
== 0) {
1323 LOGERR("CONTROLVM_DEVICE_DESTROY Failed: busNo=%lu, devNo=%lu already destroyed",
1325 RETINT(-CONTROLVM_RESP_ERROR_ALREADY_DONE
);
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
));
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
1343 initialize_controlvm_payload_info(HOSTADDRESS phys_addr
, U64 offset
, U32 bytes
,
1344 CONTROLVM_PAYLOAD_INFO
*info
)
1347 int rc
= CONTROLVM_RESP_SUCCESS
;
1350 LOGERR("HUH ? CONTROLVM_PAYLOAD_INIT Failed : Programmer check at %s:%d",
1351 __FILE__
, __LINE__
);
1352 RETINT(-CONTROLVM_RESP_ERROR_PAYLOAD_INVALID
);
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
);
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
);
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
);
1375 if (payload
!= NULL
) {
1384 destroy_controlvm_payload_info(CONTROLVM_PAYLOAD_INFO
*info
)
1386 if (info
->ptr
!= NULL
) {
1390 memset(info
, 0, sizeof(CONTROLVM_PAYLOAD_INFO
));
1394 initialize_controlvm_payload(void)
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
);
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
);
1417 initialize_controlvm_payload_info(phys_addr
,
1418 payloadOffset
, payloadBytes
,
1419 &ControlVm_payload_info
);
1422 /* Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1423 * Returns CONTROLVM_RESP_xxx code.
1426 visorchipset_chipset_ready(void)
1428 kobject_uevent(&Visorchipset_platform_device
.dev
.kobj
, KOBJ_ONLINE
);
1429 return CONTROLVM_RESP_SUCCESS
;
1431 EXPORT_SYMBOL_GPL(visorchipset_chipset_ready
);
1434 visorchipset_chipset_selftest(void)
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
,
1441 return CONTROLVM_RESP_SUCCESS
;
1443 EXPORT_SYMBOL_GPL(visorchipset_chipset_selftest
);
1445 /* Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset.
1446 * Returns CONTROLVM_RESP_xxx code.
1449 visorchipset_chipset_notready(void)
1451 kobject_uevent(&Visorchipset_platform_device
.dev
.kobj
, KOBJ_OFFLINE
);
1452 return CONTROLVM_RESP_SUCCESS
;
1454 EXPORT_SYMBOL_GPL(visorchipset_chipset_notready
);
1457 chipset_ready(CONTROLVM_MESSAGE_HEADER
*msgHdr
)
1459 int rc
= visorchipset_chipset_ready();
1460 if (rc
!= CONTROLVM_RESP_SUCCESS
)
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
1468 g_ChipSetMsgHdr
= *msgHdr
;
1469 LOGINF("Holding CHIPSET_READY response");
1474 chipset_selftest(CONTROLVM_MESSAGE_HEADER
*msgHdr
)
1476 int rc
= visorchipset_chipset_selftest();
1477 if (rc
!= CONTROLVM_RESP_SUCCESS
)
1479 if (msgHdr
->Flags
.responseExpected
)
1480 controlvm_respond(msgHdr
, rc
);
1484 chipset_notready(CONTROLVM_MESSAGE_HEADER
*msgHdr
)
1486 int rc
= visorchipset_chipset_notready();
1487 if (rc
!= CONTROLVM_RESP_SUCCESS
)
1489 if (msgHdr
->Flags
.responseExpected
)
1490 controlvm_respond(msgHdr
, rc
);
1493 /* This is your "one-stop" shop for grabbing the next message from the
1494 * CONTROLVM_QUEUE_EVENT queue in the controlvm channel.
1497 read_controlvm_event(CONTROLVM_MESSAGE
*msg
)
1499 if (visorchannel_signalremove(ControlVm_channel
,
1500 CONTROLVM_QUEUE_EVENT
, msg
)) {
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
);
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.
1524 #define PARAHOTPLUG_TIMEOUT_MS 2000
1527 * Generate unique int to match an outstanding CONTROLVM message with a
1528 * udev script /proc response
1531 parahotplug_next_id(void)
1533 static atomic_t id
= ATOMIC_INIT(0);
1534 return atomic_inc_return(&id
);
1538 * Returns the time (in jiffies) when a CONTROLVM message on the list
1539 * should expire -- PARAHOTPLUG_TIMEOUT_MS in the future
1541 static unsigned long
1542 parahotplug_next_expiration(void)
1544 return jiffies
+ PARAHOTPLUG_TIMEOUT_MS
* HZ
/ 1000;
1548 * Create a parahotplug_request, which is basically a wrapper for a
1549 * CONTROLVM_MESSAGE that we can stick on a list
1551 static struct parahotplug_request
*
1552 parahotplug_request_create(CONTROLVM_MESSAGE
*msg
)
1554 struct parahotplug_request
*req
=
1555 kmalloc(sizeof(struct parahotplug_request
),
1556 GFP_KERNEL
|__GFP_NORETRY
);
1560 req
->id
= parahotplug_next_id();
1561 req
->expiration
= parahotplug_next_expiration();
1568 * Free a parahotplug_request.
1571 parahotplug_request_destroy(struct parahotplug_request
*req
)
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
1582 parahotplug_request_kickoff(struct parahotplug_request
*req
)
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],
1588 env_cmd
, env_id
, env_state
, env_bus
, env_dev
, env_func
, NULL
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);
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
);
1607 kobject_uevent_env(&Visorchipset_platform_device
.dev
.kobj
, KOBJ_CHANGE
,
1612 * Remove any request from the list that's been on there too long and
1613 * respond with an error.
1616 parahotplug_process_list(void)
1618 struct list_head
*pos
= NULL
;
1619 struct list_head
*tmp
= NULL
;
1621 spin_lock(&Parahotplug_request_list_lock
);
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
)) {
1628 if (req
->msg
.hdr
.Flags
.responseExpected
)
1629 controlvm_respond_physdev_changestate(
1631 CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT
,
1632 req
->msg
.cmd
.deviceChangeState
.state
);
1633 parahotplug_request_destroy(req
);
1637 spin_unlock(&Parahotplug_request_list_lock
);
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.
1646 parahotplug_request_complete(int id
, U16 active
)
1648 struct list_head
*pos
= NULL
;
1649 struct list_head
*tmp
= NULL
;
1651 spin_lock(&Parahotplug_request_list_lock
);
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
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
);
1673 spin_unlock(&Parahotplug_request_list_lock
);
1678 * Enables or disables a PCI device by kicking off a udev script
1681 parahotplug_process_message(CONTROLVM_MESSAGE
*inmsg
)
1683 struct parahotplug_request
*req
;
1685 req
= parahotplug_request_create(inmsg
);
1688 LOGERR("parahotplug_process_message: couldn't allocate request");
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
1702 parahotplug_request_kickoff(req
);
1703 controlvm_respond_physdev_changestate(&inmsg
->hdr
,
1704 CONTROLVM_RESP_SUCCESS
,
1706 deviceChangeState
.state
);
1707 parahotplug_request_destroy(req
);
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.
1714 spin_lock(&Parahotplug_request_list_lock
);
1715 list_add_tail(&(req
->list
), &Parahotplug_request_list
);
1716 spin_unlock(&Parahotplug_request_list_lock
);
1718 parahotplug_request_kickoff(req
);
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.
1730 parahotplug_proc_write(struct file
*file
, const char __user
*buffer
,
1731 size_t count
, loff_t
*ppos
)
1737 if (count
> sizeof(buf
) - 1) {
1738 LOGERR("parahotplug_proc_write: count (%d) exceeds size of buffer (%d)",
1739 (int) count
, (int) sizeof(buf
));
1742 if (copy_from_user(buf
, buffer
, count
)) {
1743 LOGERR("parahotplug_proc_write: copy_from_user failed");
1748 if (sscanf(buf
, "%u %hu", &id
, &active
) != 2) {
1753 if (active
!= 1 && active
!= 0) {
1754 LOGERR("parahotplug_proc_write: invalid active field");
1758 parahotplug_request_complete((int) id
, (U16
) active
);
1763 static const struct file_operations parahotplug_proc_fops
= {
1764 .owner
= THIS_MODULE
,
1765 .read
= visorchipset_proc_read_writeonly
,
1766 .write
= parahotplug_proc_write
,
1769 /* Process a controlvm message.
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
1777 * TRUE - processing of the controlvm message completed,
1778 * either successfully or with an error.
1781 handle_command(CONTROLVM_MESSAGE inmsg
, HOSTADDRESS channel_addr
)
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
;
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!");
1796 parametersAddr
= channel_addr
+ inmsg
.hdr
.PayloadVmOffset
;
1797 parametersBytes
= inmsg
.hdr
.PayloadBytes
;
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.
1803 if (parametersAddr
!= 0 && parametersBytes
!= 0) {
1806 parser_init_byteStream(parametersAddr
, parametersBytes
,
1807 isLocalAddr
, &retry
);
1810 LOGWRN("throttling to copy payload");
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
);
1822 controlvm_init_response(&ackmsg
, &inmsg
.hdr
,
1823 CONTROLVM_RESP_SUCCESS
);
1824 if ((ControlVm_channel
)
1826 (!visorchannel_signalinsert
1827 (ControlVm_channel
, CONTROLVM_QUEUE_ACK
, &ackmsg
)))
1828 LOGWRN("failed to send ACK failed");
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
);
1837 case CONTROLVM_BUS_CREATE
:
1838 LOGINF("BUS_CREATE(%lu,#devs=%lu)",
1839 (ulong
) cmd
->createBus
.busNo
,
1840 (ulong
) cmd
->createBus
.deviceCount
);
1843 case CONTROLVM_BUS_DESTROY
:
1844 LOGINF("BUS_DESTROY(%lu)", (ulong
) cmd
->destroyBus
.busNo
);
1845 bus_destroy(&inmsg
);
1847 case CONTROLVM_BUS_CONFIGURE
:
1848 LOGINF("BUS_CONFIGURE(%lu)", (ulong
) cmd
->configureBus
.busNo
);
1849 bus_configure(&inmsg
, parser_ctx
);
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
);
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
);
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
;
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
);
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
);
1891 case CONTROLVM_CHIPSET_READY
:
1892 LOGINF("CHIPSET_READY");
1893 chipset_ready(&inmsg
.hdr
);
1895 case CONTROLVM_CHIPSET_SELFTEST
:
1896 LOGINF("CHIPSET_SELFTEST");
1897 chipset_selftest(&inmsg
.hdr
);
1899 case CONTROLVM_CHIPSET_STOP
:
1900 LOGINF("CHIPSET_STOP");
1901 chipset_notready(&inmsg
.hdr
);
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
);
1911 if (parser_ctx
!= NULL
) {
1912 parser_done(parser_ctx
);
1919 controlvm_periodic_work(struct work_struct
*work
)
1921 VISORCHIPSET_CHANNEL_INFO chanInfo
;
1922 CONTROLVM_MESSAGE inmsg
;
1924 BOOL gotACommand
= FALSE
;
1925 BOOL handle_command_failed
= FALSE
;
1926 static U64 Poll_Count
;
1928 /* make sure visorbus server is registered for controlvm callbacks */
1929 if (visorchipset_serverregwait
&& !serverregistered
)
1931 /* make sure visorclientbus server is regsitered for controlvm
1934 if (visorchipset_clientregwait
&& !clientregistered
)
1937 memset(&chanInfo
, 0, sizeof(VISORCHIPSET_CHANNEL_INFO
));
1938 if (!ControlVm_channel
) {
1939 HOSTADDRESS addr
= controlvm_get_channel_address();
1942 visorchannel_create_with_lock
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
),
1951 LOGINF("Channel %s (ControlVm) discovered",
1952 visorchannel_id(ControlVm_channel
, s
));
1953 initialize_controlvm_payload();
1955 LOGERR("controlvm channel is invalid");
1956 visorchannel_destroy(ControlVm_channel
);
1957 ControlVm_channel
= NULL
;
1963 if ((ControlVm_channel
!= NULL
) || (Poll_Count
>= 250))
1968 /* Check events to determine if response to CHIPSET_READY
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
));
1982 if (ControlVm_channel
) {
1983 while (visorchannel_signalremove(ControlVm_channel
,
1984 CONTROLVM_QUEUE_RESPONSE
,
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
,
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
1999 inmsg
= ControlVm_Pending_Msg
;
2000 ControlVm_Pending_Msg_Valid
= FALSE
;
2003 gotACommand
= read_controlvm_event(&inmsg
);
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
);
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
2022 handle_command_failed
= TRUE
;
2023 ControlVm_Pending_Msg
= inmsg
;
2024 ControlVm_Pending_Msg_Valid
= TRUE
;
2028 handle_command(inmsg
, 0);
2029 gotACommand
= FALSE
;
2033 /* parahotplug_worker */
2034 parahotplug_process_list();
2040 if (time_after(jiffies
,
2041 Most_recent_message_jiffies
+ (HZ
* MIN_IDLE_SECONDS
))) {
2042 /* it's been longer than MIN_IDLE_SECONDS since we
2043 * processed our last controlvm message; slow down the
2046 if (Poll_jiffies
!= POLLJIFFIES_CONTROLVMCHANNEL_SLOW
) {
2047 LOGINF("switched to slow controlvm polling");
2048 Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_SLOW
;
2051 if (Poll_jiffies
!= POLLJIFFIES_CONTROLVMCHANNEL_FAST
) {
2052 Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_FAST
;
2053 LOGINF("switched to fast controlvm polling");
2057 queue_delayed_work(Periodic_controlvm_workqueue
,
2058 &Periodic_controlvm_work
, Poll_jiffies
);
2062 setup_crash_devices_work_queue(struct work_struct
*work
)
2065 CONTROLVM_MESSAGE localCrashCreateBusMsg
;
2066 CONTROLVM_MESSAGE localCrashCreateDevMsg
;
2067 CONTROLVM_MESSAGE msg
;
2068 HOSTADDRESS host_addr
;
2069 U32 localSavedCrashMsgOffset
;
2070 U16 localSavedCrashMsgCount
;
2072 /* make sure visorbus server is registered for controlvm callbacks */
2073 if (visorchipset_serverregwait
&& !serverregistered
)
2076 /* make sure visorclientbus server is regsitered for controlvm
2079 if (visorchipset_clientregwait
&& !clientregistered
)
2082 POSTCODE_LINUX_2(CRASH_DEV_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
2084 /* send init chipset msg */
2085 msg
.hdr
.Id
= CONTROLVM_CHIPSET_INIT
;
2086 msg
.cmd
.initChipset
.busCount
= 23;
2087 msg
.cmd
.initChipset
.switchCount
= 0;
2091 host_addr
= controlvm_get_channel_address();
2093 LOGERR("Huh? Host address is NULL");
2094 POSTCODE_LINUX_2(CRASH_DEV_HADDR_NULL
, POSTCODE_SEVERITY_ERR
);
2099 visorchannel_create_with_lock
2101 sizeof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
),
2102 UltraControlvmChannelProtocolGuid
);
2104 if (ControlVm_channel
== NULL
) {
2105 LOGERR("failed to create controlvm channel");
2106 POSTCODE_LINUX_2(CRASH_DEV_CONTROLVM_NULL
,
2107 POSTCODE_SEVERITY_ERR
);
2111 /* get saved message count */
2112 if (visorchannel_read(ControlVm_channel
,
2113 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2114 SavedCrashMsgCount
),
2115 &localSavedCrashMsgCount
, sizeof(U16
)) < 0) {
2116 LOGERR("failed to get Saved Message Count");
2117 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC
,
2118 POSTCODE_SEVERITY_ERR
);
2122 if (localSavedCrashMsgCount
!= CONTROLVM_CRASHMSG_MAX
) {
2123 LOGERR("Saved Message Count incorrect %d",
2124 localSavedCrashMsgCount
);
2125 POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC
,
2126 localSavedCrashMsgCount
,
2127 POSTCODE_SEVERITY_ERR
);
2131 /* get saved crash message offset */
2132 if (visorchannel_read(ControlVm_channel
,
2133 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2134 SavedCrashMsgOffset
),
2135 &localSavedCrashMsgOffset
, sizeof(U32
)) < 0) {
2136 LOGERR("failed to get Saved Message Offset");
2137 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC
,
2138 POSTCODE_SEVERITY_ERR
);
2142 /* read create device message for storage bus offset */
2143 if (visorchannel_read(ControlVm_channel
,
2144 localSavedCrashMsgOffset
,
2145 &localCrashCreateBusMsg
,
2146 sizeof(CONTROLVM_MESSAGE
)) < 0) {
2147 LOGERR("CRASH_DEV_RD_BUS_FAIULRE: Failed to read CrashCreateBusMsg!");
2148 POSTCODE_LINUX_2(CRASH_DEV_RD_BUS_FAIULRE_PC
,
2149 POSTCODE_SEVERITY_ERR
);
2153 /* read create device message for storage device */
2154 if (visorchannel_read(ControlVm_channel
,
2155 localSavedCrashMsgOffset
+
2156 sizeof(CONTROLVM_MESSAGE
),
2157 &localCrashCreateDevMsg
,
2158 sizeof(CONTROLVM_MESSAGE
)) < 0) {
2159 LOGERR("CRASH_DEV_RD_DEV_FAIULRE: Failed to read CrashCreateDevMsg!");
2160 POSTCODE_LINUX_2(CRASH_DEV_RD_DEV_FAIULRE_PC
,
2161 POSTCODE_SEVERITY_ERR
);
2165 /* reuse IOVM create bus message */
2166 if (localCrashCreateBusMsg
.cmd
.createBus
.channelAddr
!= 0)
2167 bus_create(&localCrashCreateBusMsg
);
2169 LOGERR("CrashCreateBusMsg is null, no dump will be taken");
2170 POSTCODE_LINUX_2(CRASH_DEV_BUS_NULL_FAILURE_PC
,
2171 POSTCODE_SEVERITY_ERR
);
2175 /* reuse create device message for storage device */
2176 if (localCrashCreateDevMsg
.cmd
.createDevice
.channelAddr
!= 0)
2177 my_device_create(&localCrashCreateDevMsg
);
2179 LOGERR("CrashCreateDevMsg is null, no dump will be taken");
2180 POSTCODE_LINUX_2(CRASH_DEV_DEV_NULL_FAILURE_PC
,
2181 POSTCODE_SEVERITY_ERR
);
2184 LOGINF("Bus and device ready for dumping");
2185 POSTCODE_LINUX_2(CRASH_DEV_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
2190 Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_SLOW
;
2192 queue_delayed_work(Periodic_controlvm_workqueue
,
2193 &Periodic_controlvm_work
, Poll_jiffies
);
2197 bus_create_response(ulong busNo
, int response
)
2199 bus_responder(CONTROLVM_BUS_CREATE
, busNo
, response
);
2203 bus_destroy_response(ulong busNo
, int response
)
2205 bus_responder(CONTROLVM_BUS_DESTROY
, busNo
, response
);
2209 device_create_response(ulong busNo
, ulong devNo
, int response
)
2211 device_responder(CONTROLVM_DEVICE_CREATE
, busNo
, devNo
, response
);
2215 device_destroy_response(ulong busNo
, ulong devNo
, int response
)
2217 device_responder(CONTROLVM_DEVICE_DESTROY
, busNo
, devNo
, response
);
2221 visorchipset_device_pause_response(ulong busNo
, ulong devNo
, int response
)
2224 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE
,
2225 busNo
, devNo
, response
,
2226 SegmentStateStandby
);
2228 EXPORT_SYMBOL_GPL(visorchipset_device_pause_response
);
2231 device_resume_response(ulong busNo
, ulong devNo
, int response
)
2233 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE
,
2234 busNo
, devNo
, response
,
2235 SegmentStateRunning
);
2239 visorchipset_get_bus_info(ulong busNo
, VISORCHIPSET_BUS_INFO
*busInfo
)
2241 void *p
= findbus(&BusInfoList
, busNo
);
2243 LOGERR("(%lu) failed", busNo
);
2246 memcpy(busInfo
, p
, sizeof(VISORCHIPSET_BUS_INFO
));
2249 EXPORT_SYMBOL_GPL(visorchipset_get_bus_info
);
2252 visorchipset_set_bus_context(ulong busNo
, void *context
)
2254 VISORCHIPSET_BUS_INFO
*p
= findbus(&BusInfoList
, busNo
);
2256 LOGERR("(%lu) failed", busNo
);
2259 p
->bus_driver_context
= context
;
2262 EXPORT_SYMBOL_GPL(visorchipset_set_bus_context
);
2265 visorchipset_get_device_info(ulong busNo
, ulong devNo
,
2266 VISORCHIPSET_DEVICE_INFO
*devInfo
)
2268 void *p
= finddevice(&DevInfoList
, busNo
, devNo
);
2270 LOGERR("(%lu,%lu) failed", busNo
, devNo
);
2273 memcpy(devInfo
, p
, sizeof(VISORCHIPSET_DEVICE_INFO
));
2276 EXPORT_SYMBOL_GPL(visorchipset_get_device_info
);
2279 visorchipset_set_device_context(ulong busNo
, ulong devNo
, void *context
)
2281 VISORCHIPSET_DEVICE_INFO
*p
= finddevice(&DevInfoList
, busNo
, devNo
);
2283 LOGERR("(%lu,%lu) failed", busNo
, devNo
);
2286 p
->bus_driver_context
= context
;
2289 EXPORT_SYMBOL_GPL(visorchipset_set_device_context
);
2291 /* Generic wrapper function for allocating memory from a kmem_cache pool.
2294 visorchipset_cache_alloc(struct kmem_cache
*pool
, BOOL ok_to_block
,
2304 /* __GFP_NORETRY means "ok to fail", meaning
2305 * kmem_cache_alloc() can return NULL, implying the caller CAN
2306 * cope with failure. If you do NOT specify __GFP_NORETRY,
2307 * Linux will go to extreme measures to get memory for you
2308 * (like, invoke oom killer), which will probably cripple the
2311 gfp
|= __GFP_NORETRY
;
2312 p
= kmem_cache_alloc(pool
, gfp
);
2314 LOGERR("kmem_cache_alloc failed early @%s:%d\n", fn
, ln
);
2317 atomic_inc(&Visorchipset_cache_buffers_in_use
);
2321 /* Generic wrapper function for freeing memory from a kmem_cache pool.
2324 visorchipset_cache_free(struct kmem_cache
*pool
, void *p
, char *fn
, int ln
)
2327 LOGERR("NULL pointer @%s:%d\n", fn
, ln
);
2330 atomic_dec(&Visorchipset_cache_buffers_in_use
);
2331 kmem_cache_free(pool
, p
);
2334 #define gettoken(bufp) strsep(bufp, " -\t\n")
2337 chipset_proc_write(struct file
*file
, const char __user
*buffer
,
2338 size_t count
, loff_t
*ppos
)
2343 if (count
> sizeof(buf
) - 1) {
2344 LOGERR("chipset_proc_write: count (%d) exceeds size of buffer (%d)",
2345 (int) count
, (int) sizeof(buffer
));
2348 if (copy_from_user(buf
, buffer
, count
)) {
2349 LOGERR("chipset_proc_write: copy_from_user failed");
2355 token
= gettoken(&p
);
2357 if (strcmp(token
, "CALLHOMEDISK_MOUNTED") == 0) {
2358 token
= gettoken(&p
);
2359 /* The Call Home Disk has been mounted */
2360 if (strcmp(token
, "0") == 0)
2361 chipset_events
[0] = 1;
2362 } else if (strcmp(token
, "MODULES_LOADED") == 0) {
2363 token
= gettoken(&p
);
2364 /* All modules for the partition have been loaded */
2365 if (strcmp(token
, "0") == 0)
2366 chipset_events
[1] = 1;
2367 } else if (token
== NULL
) {
2368 /* No event specified */
2369 LOGERR("No event was specified to send CHIPSET_READY response");
2372 /* Unsupported event specified */
2373 LOGERR("%s is an invalid event for sending CHIPSET_READY response", token
);
2381 visorchipset_proc_read_writeonly(struct file
*file
, char __user
*buf
,
2382 size_t len
, loff_t
*offset
)
2388 * Reads the InstallationError, InstallationTextId,
2389 * InstallationRemainingSteps fields of ControlVMChannel.
2392 proc_read_installer(struct file
*file
, char __user
*buf
,
2393 size_t len
, loff_t
*offset
)
2399 loff_t pos
= *offset
;
2404 if (pos
> 0 || !len
)
2407 vbuf
= kzalloc(len
, GFP_KERNEL
);
2411 visorchannel_read(ControlVm_channel
,
2412 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2413 InstallationRemainingSteps
), &remainingSteps
,
2415 visorchannel_read(ControlVm_channel
,
2416 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2417 InstallationError
), &error
, sizeof(U32
));
2418 visorchannel_read(ControlVm_channel
,
2419 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2420 InstallationTextId
), &textId
, sizeof(U32
));
2422 length
= sprintf(vbuf
, "%u %u %u\n", remainingSteps
, error
, textId
);
2423 if (copy_to_user(buf
, vbuf
, length
)) {
2434 * Writes to the InstallationError, InstallationTextId,
2435 * InstallationRemainingSteps fields of
2437 * Input: RemainingSteps Error TextId
2438 * Limit 32 characters input
2440 #define UINT16_MAX (65535U)
2441 #define UINT32_MAX (4294967295U)
2443 proc_write_installer(struct file
*file
,
2444 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
2450 /* Check to make sure there is no buffer overflow */
2451 if (count
> (sizeof(buf
) - 1))
2454 if (copy_from_user(buf
, buffer
, count
)) {
2455 WARN(1, "Error copying from user space\n");
2459 if (sscanf(buf
, "%hu %i %i", &remainingSteps
, &error
, &textId
) != 3) {
2460 remainingSteps
= UINT16_MAX
;
2462 textId
= UINT32_MAX
;
2465 if (remainingSteps
!= UINT16_MAX
) {
2466 if (visorchannel_write
2468 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2469 InstallationRemainingSteps
), &remainingSteps
,
2471 WARN(1, "Installation Status Write Failed - Write function error - RemainingSteps = %d\n",
2475 if (error
!= UINT32_MAX
) {
2476 if (visorchannel_write
2478 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2479 InstallationError
), &error
, sizeof(U32
)) < 0)
2480 WARN(1, "Installation Status Write Failed - Write function error - Error = %d\n",
2484 if (textId
!= UINT32_MAX
) {
2485 if (visorchannel_write
2487 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2488 InstallationTextId
), &textId
, sizeof(U32
)) < 0)
2489 WARN(1, "Installation Status Write Failed - Write function error - TextId = %d\n",
2493 /* So this function isn't called multiple times, must return
2500 * Reads the ToolAction field of ControlVMChannel.
2503 proc_read_toolaction(struct file
*file
, char __user
*buf
,
2504 size_t len
, loff_t
*offset
)
2509 loff_t pos
= *offset
;
2514 if (pos
> 0 || !len
)
2517 vbuf
= kzalloc(len
, GFP_KERNEL
);
2521 visorchannel_read(ControlVm_channel
,
2522 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2523 ToolAction
), &toolAction
, sizeof(U8
));
2525 length
= sprintf(vbuf
, "%u\n", toolAction
);
2526 if (copy_to_user(buf
, vbuf
, length
)) {
2537 * Writes to the ToolAction field of ControlVMChannel.
2539 * Limit 3 characters input
2541 #define UINT8_MAX (255U)
2543 proc_write_toolaction(struct file
*file
,
2544 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
2549 /* Check to make sure there is no buffer overflow */
2550 if (count
> (sizeof(buf
) - 1))
2553 if (copy_from_user(buf
, buffer
, count
)) {
2554 WARN(1, "Error copying from user space\n");
2558 if (sscanf(buf
, "%hhd", &toolAction
) != 1)
2559 toolAction
= UINT8_MAX
;
2561 if (toolAction
!= UINT8_MAX
) {
2562 if (visorchannel_write
2564 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
, ToolAction
),
2565 &toolAction
, sizeof(U8
)) < 0)
2566 WARN(1, "Installation ToolAction Write Failed - ToolAction = %d\n",
2570 /* So this function isn't called multiple times, must return
2577 * Reads the EfiSparIndication.BootToTool field of ControlVMChannel.
2580 proc_read_bootToTool(struct file
*file
, char __user
*buf
,
2581 size_t len
, loff_t
*offset
)
2584 ULTRA_EFI_SPAR_INDICATION efiSparIndication
;
2586 loff_t pos
= *offset
;
2591 if (pos
> 0 || !len
)
2594 vbuf
= kzalloc(len
, GFP_KERNEL
);
2598 visorchannel_read(ControlVm_channel
,
2599 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2600 EfiSparIndication
), &efiSparIndication
,
2601 sizeof(ULTRA_EFI_SPAR_INDICATION
));
2603 length
= sprintf(vbuf
, "%d\n", (int) efiSparIndication
.BootToTool
);
2604 if (copy_to_user(buf
, vbuf
, length
)) {
2615 * Writes to the EfiSparIndication.BootToTool field of ControlVMChannel.
2616 * Input: 1 or 0 (1 being on, 0 being off)
2619 proc_write_bootToTool(struct file
*file
,
2620 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
2624 ULTRA_EFI_SPAR_INDICATION efiSparIndication
;
2626 /* Check to make sure there is no buffer overflow */
2627 if (count
> (sizeof(buf
) - 1))
2630 if (copy_from_user(buf
, buffer
, count
)) {
2631 WARN(1, "Error copying from user space\n");
2635 if (sscanf(buf
, "%i", &inputVal
) != 1)
2638 efiSparIndication
.BootToTool
= (inputVal
== 1 ? 1 : 0);
2640 if (visorchannel_write
2642 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
, EfiSparIndication
),
2643 &efiSparIndication
, sizeof(ULTRA_EFI_SPAR_INDICATION
)) < 0)
2645 ("Installation BootToTool Write Failed - BootToTool = %d\n",
2646 (int) efiSparIndication
.BootToTool
);
2648 /* So this function isn't called multiple times, must return
2654 static const struct file_operations chipset_proc_fops
= {
2655 .owner
= THIS_MODULE
,
2656 .read
= visorchipset_proc_read_writeonly
,
2657 .write
= chipset_proc_write
,
2661 visorchipset_init(void)
2664 struct proc_dir_entry
*installer_file
;
2665 struct proc_dir_entry
*toolaction_file
;
2666 struct proc_dir_entry
*bootToTool_file
;
2668 LOGINF("chipset driver version %s loaded", VERSION
);
2669 /* process module options */
2670 POSTCODE_LINUX_2(DRIVER_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
2672 LOGINF("option - testvnic=%d", visorchipset_testvnic
);
2673 LOGINF("option - testvnicclient=%d", visorchipset_testvnicclient
);
2674 LOGINF("option - testmsg=%d", visorchipset_testmsg
);
2675 LOGINF("option - testteardown=%d", visorchipset_testteardown
);
2676 LOGINF("option - major=%d", visorchipset_major
);
2677 LOGINF("option - serverregwait=%d", visorchipset_serverregwait
);
2678 LOGINF("option - clientregwait=%d", visorchipset_clientregwait
);
2679 LOGINF("option - holdchipsetready=%d", visorchipset_holdchipsetready
);
2681 memset(&BusDev_Server_Notifiers
, 0, sizeof(BusDev_Server_Notifiers
));
2682 memset(&BusDev_Client_Notifiers
, 0, sizeof(BusDev_Client_Notifiers
));
2683 memset(&ControlVm_payload_info
, 0, sizeof(ControlVm_payload_info
));
2684 memset(&LiveDump_info
, 0, sizeof(LiveDump_info
));
2685 atomic_set(&LiveDump_info
.buffers_in_use
, 0);
2687 if (visorchipset_testvnic
)
2688 FAIL_WPOSTCODE_2("testvnic option no longer supported", x
,
2689 CHIPSET_INIT_FAILURE_PC
, x
);
2692 MajorDev
= MKDEV(visorchipset_major
, 0);
2693 TRY_WPOSTCODE_1(visorchipset_file_init(MajorDev
, &ControlVm_channel
),
2694 CHIPSET_INIT_FAILURE_PC
);
2696 memset(PartitionPropertyNames
, 0, sizeof(PartitionPropertyNames
));
2697 memset(ControlVmPropertyNames
, 0, sizeof(ControlVmPropertyNames
));
2698 InitPartitionProperties();
2699 InitControlVmProperties();
2701 PartitionType
= visor_proc_CreateType(ProcDir
, PartitionTypeNames
,
2703 PartitionPropertyNames
,
2704 &show_partition_property
);
2706 visor_proc_CreateType(ProcDir
, ControlVmTypeNames
,
2707 (const char **) ControlVmPropertyNames
,
2708 &show_controlvm_property
);
2710 ControlVmObject
= visor_proc_CreateObject(ControlVmType
, NULL
, NULL
);
2712 /* Setup Installation fields */
2713 installer_file
= proc_create("installer", 0644, ProcDir
,
2714 &proc_installer_fops
);
2715 /* Setup the ToolAction field */
2716 toolaction_file
= proc_create("toolaction", 0644, ProcDir
,
2717 &proc_toolaction_fops
);
2718 /* Setup the BootToTool field */
2719 bootToTool_file
= proc_create("boottotool", 0644, ProcDir
,
2720 &proc_bootToTool_fops
);
2722 memset(&g_DiagMsgHdr
, 0, sizeof(CONTROLVM_MESSAGE_HEADER
));
2724 chipset_proc_dir
= proc_create(VISORCHIPSET_CHIPSET_PROC_ENTRY_FN
,
2725 0644, ProcDir
, &chipset_proc_fops
);
2726 memset(&g_ChipSetMsgHdr
, 0, sizeof(CONTROLVM_MESSAGE_HEADER
));
2728 parahotplug_proc_dir
=
2729 proc_create(VISORCHIPSET_PARAHOTPLUG_PROC_ENTRY_FN
, 0200,
2730 ProcDir
, ¶hotplug_proc_fops
);
2731 memset(&g_DelDumpMsgHdr
, 0, sizeof(CONTROLVM_MESSAGE_HEADER
));
2733 if (filexfer_constructor(sizeof(struct putfile_request
)) < 0) {
2734 FAIL_WPOSTCODE_1("filexfer_constructor failed", -1,
2735 CHIPSET_INIT_FAILURE_PC
);
2737 Putfile_buffer_list_pool
=
2738 kmem_cache_create(Putfile_buffer_list_pool_name
,
2739 sizeof(struct putfile_buffer_entry
),
2740 0, SLAB_HWCACHE_ALIGN
, NULL
);
2741 if (!Putfile_buffer_list_pool
) {
2742 FAIL_WPOSTCODE_1("failed to alloc Putfile_buffer_list_pool", -1,
2743 CHIPSET_INIT_FAILURE_PC
);
2745 if (visorchipset_disable_controlvm
) {
2746 LOGINF("visorchipset_init:controlvm disabled");
2748 /* if booting in a crash kernel */
2749 if (visorchipset_crash_kernel
)
2750 INIT_DELAYED_WORK(&Periodic_controlvm_work
,
2751 setup_crash_devices_work_queue
);
2753 INIT_DELAYED_WORK(&Periodic_controlvm_work
,
2754 controlvm_periodic_work
);
2755 Periodic_controlvm_workqueue
=
2756 create_singlethread_workqueue("visorchipset_controlvm");
2758 if (Periodic_controlvm_workqueue
== NULL
)
2759 FAIL_WPOSTCODE_1("cannot create controlvm workqueue",
2760 -ENOMEM
, CREATE_WORKQUEUE_FAILED_PC
);
2761 Most_recent_message_jiffies
= jiffies
;
2762 Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_FAST
;
2763 TRY_WPOSTCODE_1(queue_delayed_work
2764 (Periodic_controlvm_workqueue
,
2765 &Periodic_controlvm_work
, Poll_jiffies
),
2766 QUEUE_DELAYED_WORK_PC
);
2769 Visorchipset_platform_device
.dev
.devt
= MajorDev
;
2770 if (platform_device_register(&Visorchipset_platform_device
) < 0)
2772 ("platform_device_register(visorchipset) failed", -1,
2773 DEVICE_REGISTER_FAILURE_PC
);
2774 LOGINF("visorchipset device created");
2775 POSTCODE_LINUX_2(CHIPSET_INIT_SUCCESS_PC
, POSTCODE_SEVERITY_INFO
);
2781 LOGERR("visorchipset_init failed");
2782 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC
, rc
,
2783 POSTCODE_SEVERITY_ERR
);
2789 visorchipset_exit(void)
2792 POSTCODE_LINUX_2(DRIVER_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
2794 if (visorchipset_disable_controlvm
) {
2797 cancel_delayed_work(&Periodic_controlvm_work
);
2798 flush_workqueue(Periodic_controlvm_workqueue
);
2799 destroy_workqueue(Periodic_controlvm_workqueue
);
2800 Periodic_controlvm_workqueue
= NULL
;
2801 destroy_controlvm_payload_info(&ControlVm_payload_info
);
2803 Test_Vnic_channel
= NULL
;
2804 if (Putfile_buffer_list_pool
) {
2805 kmem_cache_destroy(Putfile_buffer_list_pool
);
2806 Putfile_buffer_list_pool
= NULL
;
2808 filexfer_destructor();
2809 if (ControlVmObject
) {
2810 visor_proc_DestroyObject(ControlVmObject
);
2811 ControlVmObject
= NULL
;
2813 cleanup_controlvm_structures();
2815 if (ControlVmType
) {
2816 visor_proc_DestroyType(ControlVmType
);
2817 ControlVmType
= NULL
;
2819 if (PartitionType
) {
2820 visor_proc_DestroyType(PartitionType
);
2821 PartitionType
= NULL
;
2823 if (diag_proc_dir
) {
2824 remove_proc_entry(VISORCHIPSET_DIAG_PROC_ENTRY_FN
, ProcDir
);
2825 diag_proc_dir
= NULL
;
2827 memset(&g_DiagMsgHdr
, 0, sizeof(CONTROLVM_MESSAGE_HEADER
));
2829 if (chipset_proc_dir
) {
2830 remove_proc_entry(VISORCHIPSET_CHIPSET_PROC_ENTRY_FN
, ProcDir
);
2831 chipset_proc_dir
= NULL
;
2833 memset(&g_ChipSetMsgHdr
, 0, sizeof(CONTROLVM_MESSAGE_HEADER
));
2835 if (parahotplug_proc_dir
) {
2836 remove_proc_entry(VISORCHIPSET_PARAHOTPLUG_PROC_ENTRY_FN
,
2838 parahotplug_proc_dir
= NULL
;
2841 memset(&g_DelDumpMsgHdr
, 0, sizeof(CONTROLVM_MESSAGE_HEADER
));
2844 if (ControlVm_channel
!= NULL
) {
2845 LOGINF("Channel %s (ControlVm) disconnected",
2846 visorchannel_id(ControlVm_channel
, s
));
2847 visorchannel_destroy(ControlVm_channel
);
2848 ControlVm_channel
= NULL
;
2851 visorchipset_file_cleanup();
2852 POSTCODE_LINUX_2(DRIVER_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
2853 LOGINF("chipset driver unloaded");
2856 module_param_named(testvnic
, visorchipset_testvnic
, int, S_IRUGO
);
2857 MODULE_PARM_DESC(visorchipset_testvnic
, "1 to test vnic, using dummy VNIC connected via a loopback to a physical ethernet");
2858 int visorchipset_testvnic
= 0;
2860 module_param_named(testvnicclient
, visorchipset_testvnicclient
, int, S_IRUGO
);
2861 MODULE_PARM_DESC(visorchipset_testvnicclient
, "1 to test vnic, using real VNIC channel attached to a separate IOVM guest");
2862 int visorchipset_testvnicclient
= 0;
2864 module_param_named(testmsg
, visorchipset_testmsg
, int, S_IRUGO
);
2865 MODULE_PARM_DESC(visorchipset_testmsg
,
2866 "1 to manufacture the chipset, bus, and switch messages");
2867 int visorchipset_testmsg
= 0;
2869 module_param_named(major
, visorchipset_major
, int, S_IRUGO
);
2870 MODULE_PARM_DESC(visorchipset_major
, "major device number to use for the device node");
2871 int visorchipset_major
= 0;
2873 module_param_named(serverregwait
, visorchipset_serverregwait
, int, S_IRUGO
);
2874 MODULE_PARM_DESC(visorchipset_serverreqwait
,
2875 "1 to have the module wait for the visor bus to register");
2876 int visorchipset_serverregwait
= 0; /* default is off */
2877 module_param_named(clientregwait
, visorchipset_clientregwait
, int, S_IRUGO
);
2878 MODULE_PARM_DESC(visorchipset_clientregwait
, "1 to have the module wait for the visorclientbus to register");
2879 int visorchipset_clientregwait
= 1; /* default is on */
2880 module_param_named(testteardown
, visorchipset_testteardown
, int, S_IRUGO
);
2881 MODULE_PARM_DESC(visorchipset_testteardown
,
2882 "1 to test teardown of the chipset, bus, and switch");
2883 int visorchipset_testteardown
= 0; /* default is off */
2884 module_param_named(disable_controlvm
, visorchipset_disable_controlvm
, int,
2886 MODULE_PARM_DESC(visorchipset_disable_controlvm
,
2887 "1 to disable polling of controlVm channel");
2888 int visorchipset_disable_controlvm
= 0; /* default is off */
2889 module_param_named(crash_kernel
, visorchipset_crash_kernel
, int, S_IRUGO
);
2890 MODULE_PARM_DESC(visorchipset_crash_kernel
,
2891 "1 means we are running in crash kernel");
2892 int visorchipset_crash_kernel
= 0; /* default is running in non-crash kernel */
2893 module_param_named(holdchipsetready
, visorchipset_holdchipsetready
,
2895 MODULE_PARM_DESC(visorchipset_holdchipsetready
,
2896 "1 to hold response to CHIPSET_READY");
2897 int visorchipset_holdchipsetready
= 0; /* default is to send CHIPSET_READY
2898 * response immediately */
2899 module_init(visorchipset_init
);
2900 module_exit(visorchipset_exit
);
2902 MODULE_AUTHOR("Unisys");
2903 MODULE_LICENSE("GPL");
2904 MODULE_DESCRIPTION("Supervisor chipset driver for service partition: ver "
2906 MODULE_VERSION(VERSION
);