3 * Copyright (C) 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 "visorchipset.h"
20 #include "procobjecttree.h"
21 #include "visorchannel.h"
22 #include "periodic_work.h"
26 #include "controlvmcompletionstatus.h"
27 #include "guestlinuxdebug.h"
29 #include <linux/nls.h>
30 #include <linux/netdevice.h>
31 #include <linux/platform_device.h>
32 #include <linux/uuid.h>
34 #define CURRENT_FILE_PC VISOR_CHIPSET_PC_visorchipset_main_c
35 #define TEST_VNIC_PHYSITF "eth0" /* physical network itf for
36 * vnic loopback test */
37 #define TEST_VNIC_SWITCHNO 1
38 #define TEST_VNIC_BUSNO 9
40 #define MAX_NAME_SIZE 128
41 #define MAX_IP_SIZE 50
42 #define MAXOUTSTANDINGCHANNELCOMMAND 256
43 #define POLLJIFFIES_CONTROLVMCHANNEL_FAST 1
44 #define POLLJIFFIES_CONTROLVMCHANNEL_SLOW 100
46 /* When the controlvm channel is idle for at least MIN_IDLE_SECONDS,
47 * we switch to slow polling mode. As soon as we get a controlvm
48 * message, we switch back to fast polling mode.
50 #define MIN_IDLE_SECONDS 10
51 static ulong Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
52 static ulong Most_recent_message_jiffies; /* when we got our last
53 * controlvm message */
62 static int serverregistered;
63 static int clientregistered;
65 #define MAX_CHIPSET_EVENTS 2
66 static u8 chipset_events[MAX_CHIPSET_EVENTS] = { 0, 0 };
68 static struct delayed_work Periodic_controlvm_work;
69 static struct workqueue_struct *Periodic_controlvm_workqueue;
70 static DEFINE_SEMAPHORE(NotifierLock);
72 static struct controlvm_message_header g_DiagMsgHdr;
73 static struct controlvm_message_header g_ChipSetMsgHdr;
74 static struct controlvm_message_header g_DelDumpMsgHdr;
75 static const uuid_le UltraDiagPoolChannelProtocolGuid =
76 SPAR_DIAG_POOL_CHANNEL_PROTOCOL_UUID;
77 /* 0xffffff is an invalid Bus/Device number */
78 static ulong g_diagpoolBusNo = 0xffffff;
79 static ulong g_diagpoolDevNo = 0xffffff;
80 static struct controlvm_message_packet g_DeviceChangeStatePacket;
82 /* Only VNIC and VHBA channels are sent to visorclientbus (aka
85 #define FOR_VISORHACKBUS(channel_type_guid) \
86 (((uuid_le_cmp(channel_type_guid,\
87 spar_vnic_channel_protocol_uuid) == 0)\
88 || (uuid_le_cmp(channel_type_guid,\
89 spar_vhba_channel_protocol_uuid) == 0)))
90 #define FOR_VISORBUS(channel_type_guid) (!(FOR_VISORHACKBUS(channel_type_guid)))
92 #define is_diagpool_channel(channel_type_guid) \
93 (uuid_le_cmp(channel_type_guid, UltraDiagPoolChannelProtocolGuid) == 0)
95 static LIST_HEAD(BusInfoList);
96 static LIST_HEAD(DevInfoList);
98 static struct visorchannel *ControlVm_channel;
100 struct controlvm_payload_info {
101 u8 __iomem *ptr; /* pointer to base address of payload pool */
102 u64 offset; /* offset from beginning of controlvm
103 * channel to beginning of payload * pool */
104 u32 bytes; /* number of bytes in payload pool */
107 /* Manages the request payload in the controlvm channel */
108 static struct controlvm_payload_info ControlVm_payload_info;
110 static struct channel_header *Test_Vnic_channel;
112 struct livedump_info {
113 struct controlvm_message_header Dumpcapture_header;
114 struct controlvm_message_header Gettextdump_header;
115 struct controlvm_message_header Dumpcomplete_header;
116 BOOL Gettextdump_outstanding;
119 atomic_t buffers_in_use;
122 /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
123 * CONTROLVM_DUMP_GETTEXTDUMP / CONTROLVM_DUMP_COMPLETE conversation.
125 static struct livedump_info LiveDump_info;
127 /* The following globals are used to handle the scenario where we are unable to
128 * offload the payload from a controlvm message due to memory requirements. In
129 * this scenario, we simply stash the controlvm message, then attempt to
130 * process it again the next time controlvm_periodic_work() runs.
132 static struct controlvm_message ControlVm_Pending_Msg;
133 static BOOL ControlVm_Pending_Msg_Valid = FALSE;
135 /* Pool of struct putfile_buffer_entry, for keeping track of pending (incoming)
136 * TRANSMIT_FILE PutFile payloads.
138 static struct kmem_cache *Putfile_buffer_list_pool;
139 static const char Putfile_buffer_list_pool_name[] =
140 "controlvm_putfile_buffer_list_pool";
142 /* This identifies a data buffer that has been received via a controlvm messages
143 * in a remote --> local CONTROLVM_TRANSMIT_FILE conversation.
145 struct putfile_buffer_entry {
146 struct list_head next; /* putfile_buffer_entry list */
147 PARSER_CONTEXT *parser_ctx; /* points to buffer containing input data */
150 /* List of struct putfile_request *, via next_putfile_request member.
151 * Each entry in this list identifies an outstanding TRANSMIT_FILE
154 static LIST_HEAD(Putfile_request_list);
156 /* This describes a buffer and its current state of transfer (e.g., how many
157 * bytes have already been supplied as putfile data, and how many bytes are
158 * remaining) for a putfile_request.
160 struct putfile_active_buffer {
161 /* a payload from a controlvm message, containing a file data buffer */
162 PARSER_CONTEXT *parser_ctx;
163 /* points within data area of parser_ctx to next byte of data */
165 /* # bytes left from <pnext> to the end of this data buffer */
166 size_t bytes_remaining;
169 #define PUTFILE_REQUEST_SIG 0x0906101302281211
170 /* This identifies a single remote --> local CONTROLVM_TRANSMIT_FILE
171 * conversation. Structs of this type are dynamically linked into
172 * <Putfile_request_list>.
174 struct putfile_request {
175 u64 sig; /* PUTFILE_REQUEST_SIG */
177 /* header from original TransmitFile request */
178 struct controlvm_message_header controlvm_header;
179 u64 file_request_number; /* from original TransmitFile request */
181 /* link to next struct putfile_request */
182 struct list_head next_putfile_request;
184 /* most-recent sequence number supplied via a controlvm message */
185 u64 data_sequence_number;
187 /* head of putfile_buffer_entry list, which describes the data to be
188 * supplied as putfile data;
189 * - this list is added to when controlvm messages come in that supply
191 * - this list is removed from via the hotplug program that is actually
192 * consuming these buffers to write as file data */
193 struct list_head input_buffer_list;
194 spinlock_t req_list_lock; /* lock for input_buffer_list */
196 /* waiters for input_buffer_list to go non-empty */
197 wait_queue_head_t input_buffer_wq;
199 /* data not yet read within current putfile_buffer_entry */
200 struct putfile_active_buffer active_buf;
202 /* <0 = failed, 0 = in-progress, >0 = successful; */
203 /* note that this must be set with req_list_lock, and if you set <0, */
204 /* it is your responsibility to also free up all of the other objects */
205 /* in this struct (like input_buffer_list, active_buf.parser_ctx) */
206 /* before releasing the lock */
207 int completion_status;
210 static atomic_t Visorchipset_cache_buffers_in_use = ATOMIC_INIT(0);
212 struct parahotplug_request {
213 struct list_head list;
215 unsigned long expiration;
216 struct controlvm_message msg;
219 static LIST_HEAD(Parahotplug_request_list);
220 static DEFINE_SPINLOCK(Parahotplug_request_list_lock); /* lock for above */
221 static void parahotplug_process_list(void);
223 /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
224 * CONTROLVM_REPORTEVENT.
226 static struct visorchipset_busdev_notifiers BusDev_Server_Notifiers;
227 static struct visorchipset_busdev_notifiers BusDev_Client_Notifiers;
229 static void bus_create_response(ulong busNo, int response);
230 static void bus_destroy_response(ulong busNo, int response);
231 static void device_create_response(ulong busNo, ulong devNo, int response);
232 static void device_destroy_response(ulong busNo, ulong devNo, int response);
233 static void device_resume_response(ulong busNo, ulong devNo, int response);
235 static struct visorchipset_busdev_responders BusDev_Responders = {
236 .bus_create = bus_create_response,
237 .bus_destroy = bus_destroy_response,
238 .device_create = device_create_response,
239 .device_destroy = device_destroy_response,
240 .device_pause = visorchipset_device_pause_response,
241 .device_resume = device_resume_response,
244 /* info for /dev/visorchipset */
245 static dev_t MajorDev = -1; /**< indicates major num for device */
247 /* prototypes for attributes */
248 static ssize_t toolaction_show(struct device *dev,
249 struct device_attribute *attr, char *buf);
250 static ssize_t toolaction_store(struct device *dev,
251 struct device_attribute *attr, const char *buf, size_t count);
252 static DEVICE_ATTR_RW(toolaction);
254 static ssize_t boottotool_show(struct device *dev,
255 struct device_attribute *attr, char *buf);
256 static ssize_t boottotool_store(struct device *dev,
257 struct device_attribute *attr, const char *buf, size_t count);
258 static DEVICE_ATTR_RW(boottotool);
260 static ssize_t error_show(struct device *dev, struct device_attribute *attr,
262 static ssize_t error_store(struct device *dev, struct device_attribute *attr,
263 const char *buf, size_t count);
264 static DEVICE_ATTR_RW(error);
266 static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
268 static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
269 const char *buf, size_t count);
270 static DEVICE_ATTR_RW(textid);
272 static ssize_t remaining_steps_show(struct device *dev,
273 struct device_attribute *attr, char *buf);
274 static ssize_t remaining_steps_store(struct device *dev,
275 struct device_attribute *attr, const char *buf, size_t count);
276 static DEVICE_ATTR_RW(remaining_steps);
278 static ssize_t chipsetready_store(struct device *dev,
279 struct device_attribute *attr, const char *buf, size_t count);
280 static DEVICE_ATTR_WO(chipsetready);
282 static ssize_t devicedisabled_store(struct device *dev,
283 struct device_attribute *attr, const char *buf, size_t count);
284 static DEVICE_ATTR_WO(devicedisabled);
286 static ssize_t deviceenabled_store(struct device *dev,
287 struct device_attribute *attr, const char *buf, size_t count);
288 static DEVICE_ATTR_WO(deviceenabled);
290 static struct attribute *visorchipset_install_attrs[] = {
291 &dev_attr_toolaction.attr,
292 &dev_attr_boottotool.attr,
293 &dev_attr_error.attr,
294 &dev_attr_textid.attr,
295 &dev_attr_remaining_steps.attr,
299 static struct attribute_group visorchipset_install_group = {
301 .attrs = visorchipset_install_attrs
304 static struct attribute *visorchipset_guest_attrs[] = {
305 &dev_attr_chipsetready.attr,
309 static struct attribute_group visorchipset_guest_group = {
311 .attrs = visorchipset_guest_attrs
314 static struct attribute *visorchipset_parahotplug_attrs[] = {
315 &dev_attr_devicedisabled.attr,
316 &dev_attr_deviceenabled.attr,
320 static struct attribute_group visorchipset_parahotplug_group = {
321 .name = "parahotplug",
322 .attrs = visorchipset_parahotplug_attrs
325 static const struct attribute_group *visorchipset_dev_groups[] = {
326 &visorchipset_install_group,
327 &visorchipset_guest_group,
328 &visorchipset_parahotplug_group,
332 /* /sys/devices/platform/visorchipset */
333 static struct platform_device Visorchipset_platform_device = {
334 .name = "visorchipset",
336 .dev.groups = visorchipset_dev_groups,
339 /* Function prototypes */
340 static void controlvm_respond(struct controlvm_message_header *msgHdr,
342 static void controlvm_respond_chipset_init(
343 struct controlvm_message_header *msgHdr, int response,
344 enum ultra_chipset_feature features);
345 static void controlvm_respond_physdev_changestate(
346 struct controlvm_message_header *msgHdr, int response,
347 struct spar_segment_state state);
349 static ssize_t toolaction_show(struct device *dev,
350 struct device_attribute *attr,
355 visorchannel_read(ControlVm_channel,
356 offsetof(struct spar_controlvm_channel_protocol,
357 tool_action), &toolAction, sizeof(u8));
358 return scnprintf(buf, PAGE_SIZE, "%u\n", toolAction);
361 static ssize_t toolaction_store(struct device *dev,
362 struct device_attribute *attr,
363 const char *buf, size_t count)
368 if (kstrtou8(buf, 10, &toolAction) != 0)
371 ret = visorchannel_write(ControlVm_channel,
372 offsetof(struct spar_controlvm_channel_protocol, tool_action),
373 &toolAction, sizeof(u8));
380 static ssize_t boottotool_show(struct device *dev,
381 struct device_attribute *attr,
384 struct efi_spar_indication efiSparIndication;
386 visorchannel_read(ControlVm_channel,
387 offsetof(struct spar_controlvm_channel_protocol,
388 efi_spar_ind), &efiSparIndication,
389 sizeof(struct efi_spar_indication));
390 return scnprintf(buf, PAGE_SIZE, "%u\n",
391 efiSparIndication.boot_to_tool);
394 static ssize_t boottotool_store(struct device *dev,
395 struct device_attribute *attr,
396 const char *buf, size_t count)
399 struct efi_spar_indication efiSparIndication;
401 if (kstrtoint(buf, 10, &val) != 0)
404 efiSparIndication.boot_to_tool = val;
405 ret = visorchannel_write(ControlVm_channel,
406 offsetof(struct spar_controlvm_channel_protocol,
408 &(efiSparIndication),
409 sizeof(struct efi_spar_indication));
416 static ssize_t error_show(struct device *dev, struct device_attribute *attr,
421 visorchannel_read(ControlVm_channel, offsetof(
422 struct spar_controlvm_channel_protocol, installation_error),
423 &error, sizeof(u32));
424 return scnprintf(buf, PAGE_SIZE, "%i\n", error);
427 static ssize_t error_store(struct device *dev, struct device_attribute *attr,
428 const char *buf, size_t count)
433 if (kstrtou32(buf, 10, &error) != 0)
436 ret = visorchannel_write(ControlVm_channel,
437 offsetof(struct spar_controlvm_channel_protocol,
439 &error, sizeof(u32));
445 static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
450 visorchannel_read(ControlVm_channel, offsetof(
451 struct spar_controlvm_channel_protocol, installation_text_id),
452 &textId, sizeof(u32));
453 return scnprintf(buf, PAGE_SIZE, "%i\n", textId);
456 static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
457 const char *buf, size_t count)
462 if (kstrtou32(buf, 10, &textId) != 0)
465 ret = visorchannel_write(ControlVm_channel,
466 offsetof(struct spar_controlvm_channel_protocol,
467 installation_text_id),
468 &textId, sizeof(u32));
475 static ssize_t remaining_steps_show(struct device *dev,
476 struct device_attribute *attr, char *buf)
480 visorchannel_read(ControlVm_channel,
481 offsetof(struct spar_controlvm_channel_protocol,
482 installation_remaining_steps),
485 return scnprintf(buf, PAGE_SIZE, "%hu\n", remainingSteps);
488 static ssize_t remaining_steps_store(struct device *dev,
489 struct device_attribute *attr, const char *buf, size_t count)
494 if (kstrtou16(buf, 10, &remainingSteps) != 0)
497 ret = visorchannel_write(ControlVm_channel,
498 offsetof(struct spar_controlvm_channel_protocol,
499 installation_remaining_steps),
500 &remainingSteps, sizeof(u16));
510 wchar_t unicodeString[] = { 'a', 'b', 'c', 0 };
511 char s[sizeof(unicodeString) * NLS_MAX_CHARSET_SIZE];
512 wchar_t unicode2[99];
514 /* NOTE: Either due to a bug, or feature I don't understand, the
515 * kernel utf8_mbstowcs() and utf_wcstombs() do NOT copy the
516 * trailed NUL byte!! REALLY!!!!! Arrrrgggghhhhh
519 LOGINF("sizeof(wchar_t) = %d", sizeof(wchar_t));
520 LOGINF("utf8_wcstombs=%d",
521 chrs = utf8_wcstombs(s, unicodeString, sizeof(s)));
523 s[chrs] = '\0'; /* GRRRRRRRR */
525 LOGINF("utf8_mbstowcs=%d", chrs = utf8_mbstowcs(unicode2, s, 100));
527 unicode2[chrs] = 0; /* GRRRRRRRR */
528 if (memcmp(unicodeString, unicode2, sizeof(unicodeString)) == 0)
529 LOGINF("strings match... good");
531 LOGINF("strings did not match!!");
536 busInfo_clear(void *v)
538 struct visorchipset_bus_info *p = (struct visorchipset_bus_info *) (v);
540 if (p->proc_object) {
541 visor_proc_DestroyObject(p->proc_object);
542 p->proc_object = NULL;
547 kfree(p->description);
548 p->description = NULL;
550 p->state.created = 0;
551 memset(p, 0, sizeof(struct visorchipset_bus_info));
555 devInfo_clear(void *v)
557 struct visorchipset_device_info *p =
558 (struct visorchipset_device_info *)(v);
560 p->state.created = 0;
561 memset(p, 0, sizeof(struct visorchipset_device_info));
565 check_chipset_events(void)
569 /* Check events to determine if response should be sent */
570 for (i = 0; i < MAX_CHIPSET_EVENTS; i++)
571 send_msg &= chipset_events[i];
576 clear_chipset_events(void)
579 /* Clear chipset_events */
580 for (i = 0; i < MAX_CHIPSET_EVENTS; i++)
581 chipset_events[i] = 0;
585 visorchipset_register_busdev_server(
586 struct visorchipset_busdev_notifiers *notifiers,
587 struct visorchipset_busdev_responders *responders,
588 struct ultra_vbus_deviceinfo *driver_info)
591 if (notifiers == NULL) {
592 memset(&BusDev_Server_Notifiers, 0,
593 sizeof(BusDev_Server_Notifiers));
594 serverregistered = 0; /* clear flag */
596 BusDev_Server_Notifiers = *notifiers;
597 serverregistered = 1; /* set flag */
600 *responders = BusDev_Responders;
602 bus_device_info_init(driver_info, "chipset", "visorchipset",
607 EXPORT_SYMBOL_GPL(visorchipset_register_busdev_server);
610 visorchipset_register_busdev_client(
611 struct visorchipset_busdev_notifiers *notifiers,
612 struct visorchipset_busdev_responders *responders,
613 struct ultra_vbus_deviceinfo *driver_info)
616 if (notifiers == NULL) {
617 memset(&BusDev_Client_Notifiers, 0,
618 sizeof(BusDev_Client_Notifiers));
619 clientregistered = 0; /* clear flag */
621 BusDev_Client_Notifiers = *notifiers;
622 clientregistered = 1; /* set flag */
625 *responders = BusDev_Responders;
627 bus_device_info_init(driver_info, "chipset(bolts)",
628 "visorchipset", VERSION, NULL);
631 EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client);
634 cleanup_controlvm_structures(void)
636 struct visorchipset_bus_info *bi, *tmp_bi;
637 struct visorchipset_device_info *di, *tmp_di;
639 list_for_each_entry_safe(bi, tmp_bi, &BusInfoList, entry) {
641 list_del(&bi->entry);
645 list_for_each_entry_safe(di, tmp_di, &DevInfoList, entry) {
647 list_del(&di->entry);
653 chipset_init(struct controlvm_message *inmsg)
655 static int chipset_inited;
656 enum ultra_chipset_feature features = 0;
657 int rc = CONTROLVM_RESP_SUCCESS;
659 POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO);
660 if (chipset_inited) {
661 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
665 POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC, POSTCODE_SEVERITY_INFO);
667 /* Set features to indicate we support parahotplug (if Command
668 * also supports it). */
670 inmsg->cmd.init_chipset.
671 features & ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG;
673 /* Set the "reply" bit so Command knows this is a
674 * features-aware driver. */
675 features |= ULTRA_CHIPSET_FEATURE_REPLY;
679 cleanup_controlvm_structures();
680 if (inmsg->hdr.flags.response_expected)
681 controlvm_respond_chipset_init(&inmsg->hdr, rc, features);
685 controlvm_init_response(struct controlvm_message *msg,
686 struct controlvm_message_header *msgHdr, int response)
688 memset(msg, 0, sizeof(struct controlvm_message));
689 memcpy(&msg->hdr, msgHdr, sizeof(struct controlvm_message_header));
690 msg->hdr.payload_bytes = 0;
691 msg->hdr.payload_vm_offset = 0;
692 msg->hdr.payload_max_bytes = 0;
694 msg->hdr.flags.failed = 1;
695 msg->hdr.completion_status = (u32) (-response);
700 controlvm_respond(struct controlvm_message_header *msgHdr, int response)
702 struct controlvm_message outmsg;
704 controlvm_init_response(&outmsg, msgHdr, response);
705 /* For DiagPool channel DEVICE_CHANGESTATE, we need to send
706 * back the deviceChangeState structure in the packet. */
707 if (msgHdr->id == CONTROLVM_DEVICE_CHANGESTATE
708 && g_DeviceChangeStatePacket.device_change_state.bus_no ==
710 && g_DeviceChangeStatePacket.device_change_state.dev_no ==
712 outmsg.cmd = g_DeviceChangeStatePacket;
713 if (outmsg.hdr.flags.test_message == 1)
716 if (!visorchannel_signalinsert(ControlVm_channel,
717 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
723 controlvm_respond_chipset_init(struct controlvm_message_header *msgHdr,
725 enum ultra_chipset_feature features)
727 struct controlvm_message outmsg;
729 controlvm_init_response(&outmsg, msgHdr, response);
730 outmsg.cmd.init_chipset.features = features;
731 if (!visorchannel_signalinsert(ControlVm_channel,
732 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
737 static void controlvm_respond_physdev_changestate(
738 struct controlvm_message_header *msgHdr, int response,
739 struct spar_segment_state state)
741 struct controlvm_message outmsg;
743 controlvm_init_response(&outmsg, msgHdr, response);
744 outmsg.cmd.device_change_state.state = state;
745 outmsg.cmd.device_change_state.flags.phys_device = 1;
746 if (!visorchannel_signalinsert(ControlVm_channel,
747 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
753 visorchipset_save_message(struct controlvm_message *msg,
754 enum crash_obj_type type)
756 u32 localSavedCrashMsgOffset;
757 u16 localSavedCrashMsgCount;
759 /* get saved message count */
760 if (visorchannel_read(ControlVm_channel,
761 offsetof(struct spar_controlvm_channel_protocol,
762 saved_crash_message_count),
763 &localSavedCrashMsgCount, sizeof(u16)) < 0) {
764 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
765 POSTCODE_SEVERITY_ERR);
769 if (localSavedCrashMsgCount != CONTROLVM_CRASHMSG_MAX) {
770 POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC,
771 localSavedCrashMsgCount,
772 POSTCODE_SEVERITY_ERR);
776 /* get saved crash message offset */
777 if (visorchannel_read(ControlVm_channel,
778 offsetof(struct spar_controlvm_channel_protocol,
779 saved_crash_message_offset),
780 &localSavedCrashMsgOffset, sizeof(u32)) < 0) {
781 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
782 POSTCODE_SEVERITY_ERR);
786 if (type == CRASH_BUS) {
787 if (visorchannel_write(ControlVm_channel,
788 localSavedCrashMsgOffset,
790 sizeof(struct controlvm_message)) < 0) {
791 POSTCODE_LINUX_2(SAVE_MSG_BUS_FAILURE_PC,
792 POSTCODE_SEVERITY_ERR);
796 if (visorchannel_write(ControlVm_channel,
797 localSavedCrashMsgOffset +
798 sizeof(struct controlvm_message), msg,
799 sizeof(struct controlvm_message)) < 0) {
800 POSTCODE_LINUX_2(SAVE_MSG_DEV_FAILURE_PC,
801 POSTCODE_SEVERITY_ERR);
806 EXPORT_SYMBOL_GPL(visorchipset_save_message);
809 bus_responder(enum controlvm_id cmdId, ulong busNo, int response)
811 struct visorchipset_bus_info *p = NULL;
812 BOOL need_clear = FALSE;
814 p = findbus(&BusInfoList, busNo);
819 if ((cmdId == CONTROLVM_BUS_CREATE) &&
820 (response != (-CONTROLVM_RESP_ERROR_ALREADY_DONE)))
821 /* undo the row we just created... */
822 delbusdevices(&DevInfoList, busNo);
824 if (cmdId == CONTROLVM_BUS_CREATE)
825 p->state.created = 1;
826 if (cmdId == CONTROLVM_BUS_DESTROY)
830 if (p->pending_msg_hdr.id == CONTROLVM_INVALID)
831 return; /* no controlvm response needed */
832 if (p->pending_msg_hdr.id != (u32) cmdId)
834 controlvm_respond(&p->pending_msg_hdr, response);
835 p->pending_msg_hdr.id = CONTROLVM_INVALID;
838 delbusdevices(&DevInfoList, busNo);
843 device_changestate_responder(enum controlvm_id cmdId,
844 ulong busNo, ulong devNo, int response,
845 struct spar_segment_state responseState)
847 struct visorchipset_device_info *p = NULL;
848 struct controlvm_message outmsg;
850 p = finddevice(&DevInfoList, busNo, devNo);
853 if (p->pending_msg_hdr.id == CONTROLVM_INVALID)
854 return; /* no controlvm response needed */
855 if (p->pending_msg_hdr.id != cmdId)
858 controlvm_init_response(&outmsg, &p->pending_msg_hdr, response);
860 outmsg.cmd.device_change_state.bus_no = busNo;
861 outmsg.cmd.device_change_state.dev_no = devNo;
862 outmsg.cmd.device_change_state.state = responseState;
864 if (!visorchannel_signalinsert(ControlVm_channel,
865 CONTROLVM_QUEUE_REQUEST, &outmsg))
868 p->pending_msg_hdr.id = CONTROLVM_INVALID;
872 device_responder(enum controlvm_id cmdId, ulong busNo, ulong devNo,
875 struct visorchipset_device_info *p = NULL;
876 BOOL need_clear = FALSE;
878 p = finddevice(&DevInfoList, busNo, devNo);
882 if (cmdId == CONTROLVM_DEVICE_CREATE)
883 p->state.created = 1;
884 if (cmdId == CONTROLVM_DEVICE_DESTROY)
888 if (p->pending_msg_hdr.id == CONTROLVM_INVALID)
889 return; /* no controlvm response needed */
891 if (p->pending_msg_hdr.id != (u32) cmdId)
894 controlvm_respond(&p->pending_msg_hdr, response);
895 p->pending_msg_hdr.id = CONTROLVM_INVALID;
901 bus_epilog(u32 busNo,
902 u32 cmd, struct controlvm_message_header *msgHdr,
903 int response, BOOL needResponse)
905 BOOL notified = FALSE;
907 struct visorchipset_bus_info *pBusInfo = findbus(&BusInfoList, busNo);
913 memcpy(&pBusInfo->pending_msg_hdr, msgHdr,
914 sizeof(struct controlvm_message_header));
916 pBusInfo->pending_msg_hdr.id = CONTROLVM_INVALID;
919 if (response == CONTROLVM_RESP_SUCCESS) {
921 case CONTROLVM_BUS_CREATE:
922 /* We can't tell from the bus_create
923 * information which of our 2 bus flavors the
924 * devices on this bus will ultimately end up.
925 * FORTUNATELY, it turns out it is harmless to
926 * send the bus_create to both of them. We can
927 * narrow things down a little bit, though,
928 * because we know: - BusDev_Server can handle
929 * either server or client devices
930 * - BusDev_Client can handle ONLY client
932 if (BusDev_Server_Notifiers.bus_create) {
933 (*BusDev_Server_Notifiers.bus_create) (busNo);
936 if ((!pBusInfo->flags.server) /*client */ &&
937 BusDev_Client_Notifiers.bus_create) {
938 (*BusDev_Client_Notifiers.bus_create) (busNo);
942 case CONTROLVM_BUS_DESTROY:
943 if (BusDev_Server_Notifiers.bus_destroy) {
944 (*BusDev_Server_Notifiers.bus_destroy) (busNo);
947 if ((!pBusInfo->flags.server) /*client */ &&
948 BusDev_Client_Notifiers.bus_destroy) {
949 (*BusDev_Client_Notifiers.bus_destroy) (busNo);
956 /* The callback function just called above is responsible
957 * for calling the appropriate visorchipset_busdev_responders
958 * function, which will call bus_responder()
962 bus_responder(cmd, busNo, response);
967 device_epilog(u32 busNo, u32 devNo, struct spar_segment_state state, u32 cmd,
968 struct controlvm_message_header *msgHdr, int response,
969 BOOL needResponse, BOOL for_visorbus)
971 struct visorchipset_busdev_notifiers *notifiers = NULL;
972 BOOL notified = FALSE;
974 struct visorchipset_device_info *pDevInfo =
975 finddevice(&DevInfoList, busNo, devNo);
977 "SPARSP_DIAGPOOL_PAUSED_STATE = 1",
985 notifiers = &BusDev_Server_Notifiers;
987 notifiers = &BusDev_Client_Notifiers;
989 memcpy(&pDevInfo->pending_msg_hdr, msgHdr,
990 sizeof(struct controlvm_message_header));
992 pDevInfo->pending_msg_hdr.id = CONTROLVM_INVALID;
997 case CONTROLVM_DEVICE_CREATE:
998 if (notifiers->device_create) {
999 (*notifiers->device_create) (busNo, devNo);
1003 case CONTROLVM_DEVICE_CHANGESTATE:
1004 /* ServerReady / ServerRunning / SegmentStateRunning */
1005 if (state.alive == segment_state_running.alive &&
1007 segment_state_running.operating) {
1008 if (notifiers->device_resume) {
1009 (*notifiers->device_resume) (busNo,
1014 /* ServerNotReady / ServerLost / SegmentStateStandby */
1015 else if (state.alive == segment_state_standby.alive &&
1017 segment_state_standby.operating) {
1018 /* technically this is standby case
1019 * where server is lost
1021 if (notifiers->device_pause) {
1022 (*notifiers->device_pause) (busNo,
1026 } else if (state.alive == segment_state_paused.alive &&
1028 segment_state_paused.operating) {
1029 /* this is lite pause where channel is
1030 * still valid just 'pause' of it
1032 if (busNo == g_diagpoolBusNo
1033 && devNo == g_diagpoolDevNo) {
1034 /* this will trigger the
1035 * diag_shutdown.sh script in
1036 * the visorchipset hotplug */
1038 (&Visorchipset_platform_device.dev.
1039 kobj, KOBJ_ONLINE, envp);
1043 case CONTROLVM_DEVICE_DESTROY:
1044 if (notifiers->device_destroy) {
1045 (*notifiers->device_destroy) (busNo, devNo);
1052 /* The callback function just called above is responsible
1053 * for calling the appropriate visorchipset_busdev_responders
1054 * function, which will call device_responder()
1058 device_responder(cmd, busNo, devNo, response);
1063 bus_create(struct controlvm_message *inmsg)
1065 struct controlvm_message_packet *cmd = &inmsg->cmd;
1066 ulong busNo = cmd->create_bus.bus_no;
1067 int rc = CONTROLVM_RESP_SUCCESS;
1068 struct visorchipset_bus_info *pBusInfo = NULL;
1071 pBusInfo = findbus(&BusInfoList, busNo);
1072 if (pBusInfo && (pBusInfo->state.created == 1)) {
1073 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, busNo,
1074 POSTCODE_SEVERITY_ERR);
1075 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
1078 pBusInfo = kzalloc(sizeof(struct visorchipset_bus_info), GFP_KERNEL);
1079 if (pBusInfo == NULL) {
1080 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, busNo,
1081 POSTCODE_SEVERITY_ERR);
1082 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED;
1086 INIT_LIST_HEAD(&pBusInfo->entry);
1087 pBusInfo->bus_no = busNo;
1088 pBusInfo->dev_no = cmd->create_bus.dev_count;
1090 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, busNo, POSTCODE_SEVERITY_INFO);
1092 if (inmsg->hdr.flags.test_message == 1)
1093 pBusInfo->chan_info.addr_type = ADDRTYPE_LOCALTEST;
1095 pBusInfo->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL;
1097 pBusInfo->flags.server = inmsg->hdr.flags.server;
1098 pBusInfo->chan_info.channel_addr = cmd->create_bus.channel_addr;
1099 pBusInfo->chan_info.n_channel_bytes = cmd->create_bus.channel_bytes;
1100 pBusInfo->chan_info.channel_type_uuid =
1101 cmd->create_bus.bus_data_type_uuid;
1102 pBusInfo->chan_info.channel_inst_uuid = cmd->create_bus.bus_inst_uuid;
1104 list_add(&pBusInfo->entry, &BusInfoList);
1106 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, busNo, POSTCODE_SEVERITY_INFO);
1109 bus_epilog(busNo, CONTROLVM_BUS_CREATE, &inmsg->hdr,
1110 rc, inmsg->hdr.flags.response_expected == 1);
1114 bus_destroy(struct controlvm_message *inmsg)
1116 struct controlvm_message_packet *cmd = &inmsg->cmd;
1117 ulong busNo = cmd->destroy_bus.bus_no;
1118 struct visorchipset_bus_info *pBusInfo;
1119 int rc = CONTROLVM_RESP_SUCCESS;
1121 pBusInfo = findbus(&BusInfoList, busNo);
1123 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1126 if (pBusInfo->state.created == 0) {
1127 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
1132 bus_epilog(busNo, CONTROLVM_BUS_DESTROY, &inmsg->hdr,
1133 rc, inmsg->hdr.flags.response_expected == 1);
1137 bus_configure(struct controlvm_message *inmsg, PARSER_CONTEXT *parser_ctx)
1139 struct controlvm_message_packet *cmd = &inmsg->cmd;
1140 ulong busNo = cmd->configure_bus.bus_no;
1141 struct visorchipset_bus_info *pBusInfo = NULL;
1142 int rc = CONTROLVM_RESP_SUCCESS;
1145 busNo = cmd->configure_bus.bus_no;
1146 POSTCODE_LINUX_3(BUS_CONFIGURE_ENTRY_PC, busNo, POSTCODE_SEVERITY_INFO);
1148 pBusInfo = findbus(&BusInfoList, busNo);
1150 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, busNo,
1151 POSTCODE_SEVERITY_ERR);
1152 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1155 if (pBusInfo->state.created == 0) {
1156 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, busNo,
1157 POSTCODE_SEVERITY_ERR);
1158 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1161 /* TBD - add this check to other commands also... */
1162 if (pBusInfo->pending_msg_hdr.id != CONTROLVM_INVALID) {
1163 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, busNo,
1164 POSTCODE_SEVERITY_ERR);
1165 rc = -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT;
1169 pBusInfo->partition_handle = cmd->configure_bus.guest_handle;
1170 pBusInfo->partition_uuid = parser_id_get(parser_ctx);
1171 parser_param_start(parser_ctx, PARSERSTRING_NAME);
1172 pBusInfo->name = parser_string_get(parser_ctx);
1174 visorchannel_uuid_id(&pBusInfo->partition_uuid, s);
1175 POSTCODE_LINUX_3(BUS_CONFIGURE_EXIT_PC, busNo, POSTCODE_SEVERITY_INFO);
1177 bus_epilog(busNo, CONTROLVM_BUS_CONFIGURE, &inmsg->hdr,
1178 rc, inmsg->hdr.flags.response_expected == 1);
1182 my_device_create(struct controlvm_message *inmsg)
1184 struct controlvm_message_packet *cmd = &inmsg->cmd;
1185 ulong busNo = cmd->create_device.bus_no;
1186 ulong devNo = cmd->create_device.dev_no;
1187 struct visorchipset_device_info *pDevInfo = NULL;
1188 struct visorchipset_bus_info *pBusInfo = NULL;
1189 int rc = CONTROLVM_RESP_SUCCESS;
1191 pDevInfo = finddevice(&DevInfoList, busNo, devNo);
1192 if (pDevInfo && (pDevInfo->state.created == 1)) {
1193 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
1194 POSTCODE_SEVERITY_ERR);
1195 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
1198 pBusInfo = findbus(&BusInfoList, busNo);
1200 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
1201 POSTCODE_SEVERITY_ERR);
1202 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1205 if (pBusInfo->state.created == 0) {
1206 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
1207 POSTCODE_SEVERITY_ERR);
1208 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1211 pDevInfo = kzalloc(sizeof(struct visorchipset_device_info), GFP_KERNEL);
1212 if (pDevInfo == NULL) {
1213 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
1214 POSTCODE_SEVERITY_ERR);
1215 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED;
1219 INIT_LIST_HEAD(&pDevInfo->entry);
1220 pDevInfo->bus_no = busNo;
1221 pDevInfo->dev_no = devNo;
1222 pDevInfo->dev_inst_uuid = cmd->create_device.dev_inst_uuid;
1223 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, devNo, busNo,
1224 POSTCODE_SEVERITY_INFO);
1226 if (inmsg->hdr.flags.test_message == 1)
1227 pDevInfo->chan_info.addr_type = ADDRTYPE_LOCALTEST;
1229 pDevInfo->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL;
1230 pDevInfo->chan_info.channel_addr = cmd->create_device.channel_addr;
1231 pDevInfo->chan_info.n_channel_bytes = cmd->create_device.channel_bytes;
1232 pDevInfo->chan_info.channel_type_uuid =
1233 cmd->create_device.data_type_uuid;
1234 pDevInfo->chan_info.intr = cmd->create_device.intr;
1235 list_add(&pDevInfo->entry, &DevInfoList);
1236 POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, devNo, busNo,
1237 POSTCODE_SEVERITY_INFO);
1239 /* get the bus and devNo for DiagPool channel */
1241 is_diagpool_channel(pDevInfo->chan_info.channel_type_uuid)) {
1242 g_diagpoolBusNo = busNo;
1243 g_diagpoolDevNo = devNo;
1245 device_epilog(busNo, devNo, segment_state_running,
1246 CONTROLVM_DEVICE_CREATE, &inmsg->hdr, rc,
1247 inmsg->hdr.flags.response_expected == 1,
1248 FOR_VISORBUS(pDevInfo->chan_info.channel_type_uuid));
1252 my_device_changestate(struct controlvm_message *inmsg)
1254 struct controlvm_message_packet *cmd = &inmsg->cmd;
1255 ulong busNo = cmd->device_change_state.bus_no;
1256 ulong devNo = cmd->device_change_state.dev_no;
1257 struct spar_segment_state state = cmd->device_change_state.state;
1258 struct visorchipset_device_info *pDevInfo = NULL;
1259 int rc = CONTROLVM_RESP_SUCCESS;
1261 pDevInfo = finddevice(&DevInfoList, busNo, devNo);
1263 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, devNo, busNo,
1264 POSTCODE_SEVERITY_ERR);
1265 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID;
1268 if (pDevInfo->state.created == 0) {
1269 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, devNo, busNo,
1270 POSTCODE_SEVERITY_ERR);
1271 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID;
1274 if ((rc >= CONTROLVM_RESP_SUCCESS) && pDevInfo)
1275 device_epilog(busNo, devNo, state, CONTROLVM_DEVICE_CHANGESTATE,
1277 inmsg->hdr.flags.response_expected == 1,
1279 pDevInfo->chan_info.channel_type_uuid));
1283 my_device_destroy(struct controlvm_message *inmsg)
1285 struct controlvm_message_packet *cmd = &inmsg->cmd;
1286 ulong busNo = cmd->destroy_device.bus_no;
1287 ulong devNo = cmd->destroy_device.dev_no;
1288 struct visorchipset_device_info *pDevInfo = NULL;
1289 int rc = CONTROLVM_RESP_SUCCESS;
1291 pDevInfo = finddevice(&DevInfoList, busNo, devNo);
1293 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID;
1296 if (pDevInfo->state.created == 0) {
1297 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
1301 if ((rc >= CONTROLVM_RESP_SUCCESS) && pDevInfo)
1302 device_epilog(busNo, devNo, segment_state_running,
1303 CONTROLVM_DEVICE_DESTROY, &inmsg->hdr, rc,
1304 inmsg->hdr.flags.response_expected == 1,
1306 pDevInfo->chan_info.channel_type_uuid));
1309 /* When provided with the physical address of the controlvm channel
1310 * (phys_addr), the offset to the payload area we need to manage
1311 * (offset), and the size of this payload area (bytes), fills in the
1312 * controlvm_payload_info struct. Returns TRUE for success or FALSE
1316 initialize_controlvm_payload_info(HOSTADDRESS phys_addr, u64 offset, u32 bytes,
1317 struct controlvm_payload_info *info)
1319 u8 __iomem *payload = NULL;
1320 int rc = CONTROLVM_RESP_SUCCESS;
1323 rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
1326 memset(info, 0, sizeof(struct controlvm_payload_info));
1327 if ((offset == 0) || (bytes == 0)) {
1328 rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
1331 payload = ioremap_cache(phys_addr + offset, bytes);
1332 if (payload == NULL) {
1333 rc = -CONTROLVM_RESP_ERROR_IOREMAP_FAILED;
1337 info->offset = offset;
1338 info->bytes = bytes;
1339 info->ptr = payload;
1343 if (payload != NULL) {
1352 destroy_controlvm_payload_info(struct controlvm_payload_info *info)
1354 if (info->ptr != NULL) {
1358 memset(info, 0, sizeof(struct controlvm_payload_info));
1362 initialize_controlvm_payload(void)
1364 HOSTADDRESS phys_addr = visorchannel_get_physaddr(ControlVm_channel);
1365 u64 payloadOffset = 0;
1366 u32 payloadBytes = 0;
1368 if (visorchannel_read(ControlVm_channel,
1369 offsetof(struct spar_controlvm_channel_protocol,
1370 request_payload_offset),
1371 &payloadOffset, sizeof(payloadOffset)) < 0) {
1372 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC,
1373 POSTCODE_SEVERITY_ERR);
1376 if (visorchannel_read(ControlVm_channel,
1377 offsetof(struct spar_controlvm_channel_protocol,
1378 request_payload_bytes),
1379 &payloadBytes, sizeof(payloadBytes)) < 0) {
1380 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC,
1381 POSTCODE_SEVERITY_ERR);
1384 initialize_controlvm_payload_info(phys_addr,
1385 payloadOffset, payloadBytes,
1386 &ControlVm_payload_info);
1389 /* Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1390 * Returns CONTROLVM_RESP_xxx code.
1393 visorchipset_chipset_ready(void)
1395 kobject_uevent(&Visorchipset_platform_device.dev.kobj, KOBJ_ONLINE);
1396 return CONTROLVM_RESP_SUCCESS;
1398 EXPORT_SYMBOL_GPL(visorchipset_chipset_ready);
1401 visorchipset_chipset_selftest(void)
1403 char env_selftest[20];
1404 char *envp[] = { env_selftest, NULL };
1406 sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1);
1407 kobject_uevent_env(&Visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
1409 return CONTROLVM_RESP_SUCCESS;
1411 EXPORT_SYMBOL_GPL(visorchipset_chipset_selftest);
1413 /* Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset.
1414 * Returns CONTROLVM_RESP_xxx code.
1417 visorchipset_chipset_notready(void)
1419 kobject_uevent(&Visorchipset_platform_device.dev.kobj, KOBJ_OFFLINE);
1420 return CONTROLVM_RESP_SUCCESS;
1422 EXPORT_SYMBOL_GPL(visorchipset_chipset_notready);
1425 chipset_ready(struct controlvm_message_header *msgHdr)
1427 int rc = visorchipset_chipset_ready();
1429 if (rc != CONTROLVM_RESP_SUCCESS)
1431 if (msgHdr->flags.response_expected && !visorchipset_holdchipsetready)
1432 controlvm_respond(msgHdr, rc);
1433 if (msgHdr->flags.response_expected && visorchipset_holdchipsetready) {
1434 /* Send CHIPSET_READY response when all modules have been loaded
1435 * and disks mounted for the partition
1437 g_ChipSetMsgHdr = *msgHdr;
1442 chipset_selftest(struct controlvm_message_header *msgHdr)
1444 int rc = visorchipset_chipset_selftest();
1446 if (rc != CONTROLVM_RESP_SUCCESS)
1448 if (msgHdr->flags.response_expected)
1449 controlvm_respond(msgHdr, rc);
1453 chipset_notready(struct controlvm_message_header *msgHdr)
1455 int rc = visorchipset_chipset_notready();
1457 if (rc != CONTROLVM_RESP_SUCCESS)
1459 if (msgHdr->flags.response_expected)
1460 controlvm_respond(msgHdr, rc);
1463 /* This is your "one-stop" shop for grabbing the next message from the
1464 * CONTROLVM_QUEUE_EVENT queue in the controlvm channel.
1467 read_controlvm_event(struct controlvm_message *msg)
1469 if (visorchannel_signalremove(ControlVm_channel,
1470 CONTROLVM_QUEUE_EVENT, msg)) {
1472 if (msg->hdr.flags.test_message == 1)
1480 * The general parahotplug flow works as follows. The visorchipset
1481 * driver receives a DEVICE_CHANGESTATE message from Command
1482 * specifying a physical device to enable or disable. The CONTROLVM
1483 * message handler calls parahotplug_process_message, which then adds
1484 * the message to a global list and kicks off a udev event which
1485 * causes a user level script to enable or disable the specified
1486 * device. The udev script then writes to
1487 * /proc/visorchipset/parahotplug, which causes parahotplug_proc_write
1488 * to get called, at which point the appropriate CONTROLVM message is
1489 * retrieved from the list and responded to.
1492 #define PARAHOTPLUG_TIMEOUT_MS 2000
1495 * Generate unique int to match an outstanding CONTROLVM message with a
1496 * udev script /proc response
1499 parahotplug_next_id(void)
1501 static atomic_t id = ATOMIC_INIT(0);
1503 return atomic_inc_return(&id);
1507 * Returns the time (in jiffies) when a CONTROLVM message on the list
1508 * should expire -- PARAHOTPLUG_TIMEOUT_MS in the future
1510 static unsigned long
1511 parahotplug_next_expiration(void)
1513 return jiffies + msecs_to_jiffies(PARAHOTPLUG_TIMEOUT_MS);
1517 * Create a parahotplug_request, which is basically a wrapper for a
1518 * CONTROLVM_MESSAGE that we can stick on a list
1520 static struct parahotplug_request *
1521 parahotplug_request_create(struct controlvm_message *msg)
1523 struct parahotplug_request *req;
1525 req = kmalloc(sizeof(*req), GFP_KERNEL|__GFP_NORETRY);
1529 req->id = parahotplug_next_id();
1530 req->expiration = parahotplug_next_expiration();
1537 * Free a parahotplug_request.
1540 parahotplug_request_destroy(struct parahotplug_request *req)
1546 * Cause uevent to run the user level script to do the disable/enable
1547 * specified in (the CONTROLVM message in) the specified
1548 * parahotplug_request
1551 parahotplug_request_kickoff(struct parahotplug_request *req)
1553 struct controlvm_message_packet *cmd = &req->msg.cmd;
1554 char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40],
1557 env_cmd, env_id, env_state, env_bus, env_dev, env_func, NULL
1560 sprintf(env_cmd, "SPAR_PARAHOTPLUG=1");
1561 sprintf(env_id, "SPAR_PARAHOTPLUG_ID=%d", req->id);
1562 sprintf(env_state, "SPAR_PARAHOTPLUG_STATE=%d",
1563 cmd->device_change_state.state.active);
1564 sprintf(env_bus, "SPAR_PARAHOTPLUG_BUS=%d",
1565 cmd->device_change_state.bus_no);
1566 sprintf(env_dev, "SPAR_PARAHOTPLUG_DEVICE=%d",
1567 cmd->device_change_state.dev_no >> 3);
1568 sprintf(env_func, "SPAR_PARAHOTPLUG_FUNCTION=%d",
1569 cmd->device_change_state.dev_no & 0x7);
1571 kobject_uevent_env(&Visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
1576 * Remove any request from the list that's been on there too long and
1577 * respond with an error.
1580 parahotplug_process_list(void)
1582 struct list_head *pos = NULL;
1583 struct list_head *tmp = NULL;
1585 spin_lock(&Parahotplug_request_list_lock);
1587 list_for_each_safe(pos, tmp, &Parahotplug_request_list) {
1588 struct parahotplug_request *req =
1589 list_entry(pos, struct parahotplug_request, list);
1590 if (time_after_eq(jiffies, req->expiration)) {
1592 if (req->msg.hdr.flags.response_expected)
1593 controlvm_respond_physdev_changestate(
1595 CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT,
1596 req->msg.cmd.device_change_state.state);
1597 parahotplug_request_destroy(req);
1601 spin_unlock(&Parahotplug_request_list_lock);
1605 * Called from the /proc handler, which means the user script has
1606 * finished the enable/disable. Find the matching identifier, and
1607 * respond to the CONTROLVM message with success.
1610 parahotplug_request_complete(int id, u16 active)
1612 struct list_head *pos = NULL;
1613 struct list_head *tmp = NULL;
1615 spin_lock(&Parahotplug_request_list_lock);
1617 /* Look for a request matching "id". */
1618 list_for_each_safe(pos, tmp, &Parahotplug_request_list) {
1619 struct parahotplug_request *req =
1620 list_entry(pos, struct parahotplug_request, list);
1621 if (req->id == id) {
1622 /* Found a match. Remove it from the list and
1626 spin_unlock(&Parahotplug_request_list_lock);
1627 req->msg.cmd.device_change_state.state.active = active;
1628 if (req->msg.hdr.flags.response_expected)
1629 controlvm_respond_physdev_changestate(
1630 &req->msg.hdr, CONTROLVM_RESP_SUCCESS,
1631 req->msg.cmd.device_change_state.state);
1632 parahotplug_request_destroy(req);
1637 spin_unlock(&Parahotplug_request_list_lock);
1642 * Enables or disables a PCI device by kicking off a udev script
1645 parahotplug_process_message(struct controlvm_message *inmsg)
1647 struct parahotplug_request *req;
1649 req = parahotplug_request_create(inmsg);
1654 if (inmsg->cmd.device_change_state.state.active) {
1655 /* For enable messages, just respond with success
1656 * right away. This is a bit of a hack, but there are
1657 * issues with the early enable messages we get (with
1658 * either the udev script not detecting that the device
1659 * is up, or not getting called at all). Fortunately
1660 * the messages that get lost don't matter anyway, as
1661 * devices are automatically enabled at
1664 parahotplug_request_kickoff(req);
1665 controlvm_respond_physdev_changestate(&inmsg->hdr,
1666 CONTROLVM_RESP_SUCCESS, inmsg->cmd.
1667 device_change_state.state);
1668 parahotplug_request_destroy(req);
1670 /* For disable messages, add the request to the
1671 * request list before kicking off the udev script. It
1672 * won't get responded to until the script has
1673 * indicated it's done.
1675 spin_lock(&Parahotplug_request_list_lock);
1676 list_add_tail(&(req->list), &Parahotplug_request_list);
1677 spin_unlock(&Parahotplug_request_list_lock);
1679 parahotplug_request_kickoff(req);
1683 /* Process a controlvm message.
1685 * FALSE - this function will return FALSE only in the case where the
1686 * controlvm message was NOT processed, but processing must be
1687 * retried before reading the next controlvm message; a
1688 * scenario where this can occur is when we need to throttle
1689 * the allocation of memory in which to copy out controlvm
1691 * TRUE - processing of the controlvm message completed,
1692 * either successfully or with an error.
1695 handle_command(struct controlvm_message inmsg, HOSTADDRESS channel_addr)
1697 struct controlvm_message_packet *cmd = &inmsg.cmd;
1698 u64 parametersAddr = 0;
1699 u32 parametersBytes = 0;
1700 PARSER_CONTEXT *parser_ctx = NULL;
1701 BOOL isLocalAddr = FALSE;
1702 struct controlvm_message ackmsg;
1704 /* create parsing context if necessary */
1705 isLocalAddr = (inmsg.hdr.flags.test_message == 1);
1706 if (channel_addr == 0)
1708 parametersAddr = channel_addr + inmsg.hdr.payload_vm_offset;
1709 parametersBytes = inmsg.hdr.payload_bytes;
1711 /* Parameter and channel addresses within test messages actually lie
1712 * within our OS-controlled memory. We need to know that, because it
1713 * makes a difference in how we compute the virtual address.
1715 if (parametersAddr != 0 && parametersBytes != 0) {
1719 parser_init_byteStream(parametersAddr, parametersBytes,
1720 isLocalAddr, &retry);
1721 if (!parser_ctx && retry)
1726 controlvm_init_response(&ackmsg, &inmsg.hdr,
1727 CONTROLVM_RESP_SUCCESS);
1728 if (ControlVm_channel)
1729 visorchannel_signalinsert(ControlVm_channel,
1730 CONTROLVM_QUEUE_ACK,
1733 switch (inmsg.hdr.id) {
1734 case CONTROLVM_CHIPSET_INIT:
1735 chipset_init(&inmsg);
1737 case CONTROLVM_BUS_CREATE:
1740 case CONTROLVM_BUS_DESTROY:
1741 bus_destroy(&inmsg);
1743 case CONTROLVM_BUS_CONFIGURE:
1744 bus_configure(&inmsg, parser_ctx);
1746 case CONTROLVM_DEVICE_CREATE:
1747 my_device_create(&inmsg);
1749 case CONTROLVM_DEVICE_CHANGESTATE:
1750 if (cmd->device_change_state.flags.phys_device) {
1751 parahotplug_process_message(&inmsg);
1753 /* save the hdr and cmd structures for later use */
1754 /* when sending back the response to Command */
1755 my_device_changestate(&inmsg);
1756 g_DiagMsgHdr = inmsg.hdr;
1757 g_DeviceChangeStatePacket = inmsg.cmd;
1761 case CONTROLVM_DEVICE_DESTROY:
1762 my_device_destroy(&inmsg);
1764 case CONTROLVM_DEVICE_CONFIGURE:
1765 /* no op for now, just send a respond that we passed */
1766 if (inmsg.hdr.flags.response_expected)
1767 controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS);
1769 case CONTROLVM_CHIPSET_READY:
1770 chipset_ready(&inmsg.hdr);
1772 case CONTROLVM_CHIPSET_SELFTEST:
1773 chipset_selftest(&inmsg.hdr);
1775 case CONTROLVM_CHIPSET_STOP:
1776 chipset_notready(&inmsg.hdr);
1779 if (inmsg.hdr.flags.response_expected)
1780 controlvm_respond(&inmsg.hdr,
1781 -CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN);
1785 if (parser_ctx != NULL) {
1786 parser_done(parser_ctx);
1792 static HOSTADDRESS controlvm_get_channel_address(void)
1797 if (!VMCALL_SUCCESSFUL(issue_vmcall_io_controlvm_addr(&addr, &size)))
1804 controlvm_periodic_work(struct work_struct *work)
1806 struct controlvm_message inmsg;
1807 BOOL gotACommand = FALSE;
1808 BOOL handle_command_failed = FALSE;
1809 static u64 Poll_Count;
1811 /* make sure visorbus server is registered for controlvm callbacks */
1812 if (visorchipset_serverregwait && !serverregistered)
1814 /* make sure visorclientbus server is regsitered for controlvm
1817 if (visorchipset_clientregwait && !clientregistered)
1821 if (Poll_Count >= 250)
1826 /* Check events to determine if response to CHIPSET_READY
1829 if (visorchipset_holdchipsetready
1830 && (g_ChipSetMsgHdr.id != CONTROLVM_INVALID)) {
1831 if (check_chipset_events() == 1) {
1832 controlvm_respond(&g_ChipSetMsgHdr, 0);
1833 clear_chipset_events();
1834 memset(&g_ChipSetMsgHdr, 0,
1835 sizeof(struct controlvm_message_header));
1839 while (visorchannel_signalremove(ControlVm_channel,
1840 CONTROLVM_QUEUE_RESPONSE,
1844 if (ControlVm_Pending_Msg_Valid) {
1845 /* we throttled processing of a prior
1846 * msg, so try to process it again
1847 * rather than reading a new one
1849 inmsg = ControlVm_Pending_Msg;
1850 ControlVm_Pending_Msg_Valid = FALSE;
1853 gotACommand = read_controlvm_event(&inmsg);
1856 handle_command_failed = FALSE;
1857 while (gotACommand && (!handle_command_failed)) {
1858 Most_recent_message_jiffies = jiffies;
1859 if (handle_command(inmsg,
1860 visorchannel_get_physaddr
1861 (ControlVm_channel)))
1862 gotACommand = read_controlvm_event(&inmsg);
1864 /* this is a scenario where throttling
1865 * is required, but probably NOT an
1866 * error...; we stash the current
1867 * controlvm msg so we will attempt to
1868 * reprocess it on our next loop
1870 handle_command_failed = TRUE;
1871 ControlVm_Pending_Msg = inmsg;
1872 ControlVm_Pending_Msg_Valid = TRUE;
1876 /* parahotplug_worker */
1877 parahotplug_process_list();
1881 if (time_after(jiffies,
1882 Most_recent_message_jiffies + (HZ * MIN_IDLE_SECONDS))) {
1883 /* it's been longer than MIN_IDLE_SECONDS since we
1884 * processed our last controlvm message; slow down the
1887 if (Poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_SLOW) {
1888 Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW;
1891 if (Poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_FAST) {
1892 Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
1896 queue_delayed_work(Periodic_controlvm_workqueue,
1897 &Periodic_controlvm_work, Poll_jiffies);
1901 setup_crash_devices_work_queue(struct work_struct *work)
1904 struct controlvm_message localCrashCreateBusMsg;
1905 struct controlvm_message localCrashCreateDevMsg;
1906 struct controlvm_message msg;
1907 u32 localSavedCrashMsgOffset;
1908 u16 localSavedCrashMsgCount;
1910 /* make sure visorbus server is registered for controlvm callbacks */
1911 if (visorchipset_serverregwait && !serverregistered)
1914 /* make sure visorclientbus server is regsitered for controlvm
1917 if (visorchipset_clientregwait && !clientregistered)
1920 POSTCODE_LINUX_2(CRASH_DEV_ENTRY_PC, POSTCODE_SEVERITY_INFO);
1922 /* send init chipset msg */
1923 msg.hdr.id = CONTROLVM_CHIPSET_INIT;
1924 msg.cmd.init_chipset.bus_count = 23;
1925 msg.cmd.init_chipset.switch_count = 0;
1929 /* get saved message count */
1930 if (visorchannel_read(ControlVm_channel,
1931 offsetof(struct spar_controlvm_channel_protocol,
1932 saved_crash_message_count),
1933 &localSavedCrashMsgCount, sizeof(u16)) < 0) {
1934 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
1935 POSTCODE_SEVERITY_ERR);
1939 if (localSavedCrashMsgCount != CONTROLVM_CRASHMSG_MAX) {
1940 POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC,
1941 localSavedCrashMsgCount,
1942 POSTCODE_SEVERITY_ERR);
1946 /* get saved crash message offset */
1947 if (visorchannel_read(ControlVm_channel,
1948 offsetof(struct spar_controlvm_channel_protocol,
1949 saved_crash_message_offset),
1950 &localSavedCrashMsgOffset, sizeof(u32)) < 0) {
1951 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
1952 POSTCODE_SEVERITY_ERR);
1956 /* read create device message for storage bus offset */
1957 if (visorchannel_read(ControlVm_channel,
1958 localSavedCrashMsgOffset,
1959 &localCrashCreateBusMsg,
1960 sizeof(struct controlvm_message)) < 0) {
1961 POSTCODE_LINUX_2(CRASH_DEV_RD_BUS_FAIULRE_PC,
1962 POSTCODE_SEVERITY_ERR);
1966 /* read create device message for storage device */
1967 if (visorchannel_read(ControlVm_channel,
1968 localSavedCrashMsgOffset +
1969 sizeof(struct controlvm_message),
1970 &localCrashCreateDevMsg,
1971 sizeof(struct controlvm_message)) < 0) {
1972 POSTCODE_LINUX_2(CRASH_DEV_RD_DEV_FAIULRE_PC,
1973 POSTCODE_SEVERITY_ERR);
1977 /* reuse IOVM create bus message */
1978 if (localCrashCreateBusMsg.cmd.create_bus.channel_addr != 0)
1979 bus_create(&localCrashCreateBusMsg);
1981 POSTCODE_LINUX_2(CRASH_DEV_BUS_NULL_FAILURE_PC,
1982 POSTCODE_SEVERITY_ERR);
1986 /* reuse create device message for storage device */
1987 if (localCrashCreateDevMsg.cmd.create_device.channel_addr != 0)
1988 my_device_create(&localCrashCreateDevMsg);
1990 POSTCODE_LINUX_2(CRASH_DEV_DEV_NULL_FAILURE_PC,
1991 POSTCODE_SEVERITY_ERR);
1994 POSTCODE_LINUX_2(CRASH_DEV_EXIT_PC, POSTCODE_SEVERITY_INFO);
1999 Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW;
2001 queue_delayed_work(Periodic_controlvm_workqueue,
2002 &Periodic_controlvm_work, Poll_jiffies);
2006 bus_create_response(ulong busNo, int response)
2008 bus_responder(CONTROLVM_BUS_CREATE, busNo, response);
2012 bus_destroy_response(ulong busNo, int response)
2014 bus_responder(CONTROLVM_BUS_DESTROY, busNo, response);
2018 device_create_response(ulong busNo, ulong devNo, int response)
2020 device_responder(CONTROLVM_DEVICE_CREATE, busNo, devNo, response);
2024 device_destroy_response(ulong busNo, ulong devNo, int response)
2026 device_responder(CONTROLVM_DEVICE_DESTROY, busNo, devNo, response);
2030 visorchipset_device_pause_response(ulong bus_no, ulong dev_no, int response)
2033 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
2034 bus_no, dev_no, response,
2035 segment_state_standby);
2037 EXPORT_SYMBOL_GPL(visorchipset_device_pause_response);
2040 device_resume_response(ulong busNo, ulong devNo, int response)
2042 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
2043 busNo, devNo, response,
2044 segment_state_running);
2048 visorchipset_get_bus_info(ulong bus_no, struct visorchipset_bus_info *bus_info)
2050 void *p = findbus(&BusInfoList, bus_no);
2054 memcpy(bus_info, p, sizeof(struct visorchipset_bus_info));
2057 EXPORT_SYMBOL_GPL(visorchipset_get_bus_info);
2060 visorchipset_set_bus_context(ulong bus_no, void *context)
2062 struct visorchipset_bus_info *p = findbus(&BusInfoList, bus_no);
2066 p->bus_driver_context = context;
2069 EXPORT_SYMBOL_GPL(visorchipset_set_bus_context);
2072 visorchipset_get_device_info(ulong bus_no, ulong dev_no,
2073 struct visorchipset_device_info *dev_info)
2075 void *p = finddevice(&DevInfoList, bus_no, dev_no);
2079 memcpy(dev_info, p, sizeof(struct visorchipset_device_info));
2082 EXPORT_SYMBOL_GPL(visorchipset_get_device_info);
2085 visorchipset_set_device_context(ulong bus_no, ulong dev_no, void *context)
2087 struct visorchipset_device_info *p =
2088 finddevice(&DevInfoList, bus_no, dev_no);
2092 p->bus_driver_context = context;
2095 EXPORT_SYMBOL_GPL(visorchipset_set_device_context);
2097 /* Generic wrapper function for allocating memory from a kmem_cache pool.
2100 visorchipset_cache_alloc(struct kmem_cache *pool, BOOL ok_to_block,
2110 /* __GFP_NORETRY means "ok to fail", meaning
2111 * kmem_cache_alloc() can return NULL, implying the caller CAN
2112 * cope with failure. If you do NOT specify __GFP_NORETRY,
2113 * Linux will go to extreme measures to get memory for you
2114 * (like, invoke oom killer), which will probably cripple the
2117 gfp |= __GFP_NORETRY;
2118 p = kmem_cache_alloc(pool, gfp);
2122 atomic_inc(&Visorchipset_cache_buffers_in_use);
2126 /* Generic wrapper function for freeing memory from a kmem_cache pool.
2129 visorchipset_cache_free(struct kmem_cache *pool, void *p, char *fn, int ln)
2134 atomic_dec(&Visorchipset_cache_buffers_in_use);
2135 kmem_cache_free(pool, p);
2138 static ssize_t chipsetready_store(struct device *dev,
2139 struct device_attribute *attr, const char *buf, size_t count)
2143 if (sscanf(buf, "%63s", msgtype) != 1)
2146 if (strcmp(msgtype, "CALLHOMEDISK_MOUNTED") == 0) {
2147 chipset_events[0] = 1;
2149 } else if (strcmp(msgtype, "MODULES_LOADED") == 0) {
2150 chipset_events[1] = 1;
2156 /* The parahotplug/devicedisabled interface gets called by our support script
2157 * when an SR-IOV device has been shut down. The ID is passed to the script
2158 * and then passed back when the device has been removed.
2160 static ssize_t devicedisabled_store(struct device *dev,
2161 struct device_attribute *attr, const char *buf, size_t count)
2165 if (kstrtouint(buf, 10, &id) != 0)
2168 parahotplug_request_complete(id, 0);
2172 /* The parahotplug/deviceenabled interface gets called by our support script
2173 * when an SR-IOV device has been recovered. The ID is passed to the script
2174 * and then passed back when the device has been brought back up.
2176 static ssize_t deviceenabled_store(struct device *dev,
2177 struct device_attribute *attr, const char *buf, size_t count)
2181 if (kstrtouint(buf, 10, &id) != 0)
2184 parahotplug_request_complete(id, 1);
2189 visorchipset_init(void)
2194 if (!unisys_spar_platform)
2197 memset(&BusDev_Server_Notifiers, 0, sizeof(BusDev_Server_Notifiers));
2198 memset(&BusDev_Client_Notifiers, 0, sizeof(BusDev_Client_Notifiers));
2199 memset(&ControlVm_payload_info, 0, sizeof(ControlVm_payload_info));
2200 memset(&LiveDump_info, 0, sizeof(LiveDump_info));
2201 atomic_set(&LiveDump_info.buffers_in_use, 0);
2203 if (visorchipset_testvnic) {
2204 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, x, DIAG_SEVERITY_ERR);
2209 addr = controlvm_get_channel_address();
2212 visorchannel_create_with_lock
2214 sizeof(struct spar_controlvm_channel_protocol),
2215 spar_controlvm_channel_protocol_uuid);
2216 if (SPAR_CONTROLVM_CHANNEL_OK_CLIENT(
2217 visorchannel_get_header(ControlVm_channel))) {
2218 initialize_controlvm_payload();
2220 visorchannel_destroy(ControlVm_channel);
2221 ControlVm_channel = NULL;
2228 MajorDev = MKDEV(visorchipset_major, 0);
2229 rc = visorchipset_file_init(MajorDev, &ControlVm_channel);
2231 POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR);
2235 memset(&g_DiagMsgHdr, 0, sizeof(struct controlvm_message_header));
2237 memset(&g_ChipSetMsgHdr, 0, sizeof(struct controlvm_message_header));
2239 memset(&g_DelDumpMsgHdr, 0, sizeof(struct controlvm_message_header));
2241 Putfile_buffer_list_pool =
2242 kmem_cache_create(Putfile_buffer_list_pool_name,
2243 sizeof(struct putfile_buffer_entry),
2244 0, SLAB_HWCACHE_ALIGN, NULL);
2245 if (!Putfile_buffer_list_pool) {
2246 POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR);
2250 if (!visorchipset_disable_controlvm) {
2251 /* if booting in a crash kernel */
2252 if (visorchipset_crash_kernel)
2253 INIT_DELAYED_WORK(&Periodic_controlvm_work,
2254 setup_crash_devices_work_queue);
2256 INIT_DELAYED_WORK(&Periodic_controlvm_work,
2257 controlvm_periodic_work);
2258 Periodic_controlvm_workqueue =
2259 create_singlethread_workqueue("visorchipset_controlvm");
2261 if (Periodic_controlvm_workqueue == NULL) {
2262 POSTCODE_LINUX_2(CREATE_WORKQUEUE_FAILED_PC,
2267 Most_recent_message_jiffies = jiffies;
2268 Poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
2269 rc = queue_delayed_work(Periodic_controlvm_workqueue,
2270 &Periodic_controlvm_work, Poll_jiffies);
2272 POSTCODE_LINUX_2(QUEUE_DELAYED_WORK_PC,
2279 Visorchipset_platform_device.dev.devt = MajorDev;
2280 if (platform_device_register(&Visorchipset_platform_device) < 0) {
2281 POSTCODE_LINUX_2(DEVICE_REGISTER_FAILURE_PC, DIAG_SEVERITY_ERR);
2285 POSTCODE_LINUX_2(CHIPSET_INIT_SUCCESS_PC, POSTCODE_SEVERITY_INFO);
2289 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc,
2290 POSTCODE_SEVERITY_ERR);
2296 visorchipset_exit(void)
2298 POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO);
2300 if (visorchipset_disable_controlvm) {
2303 cancel_delayed_work(&Periodic_controlvm_work);
2304 flush_workqueue(Periodic_controlvm_workqueue);
2305 destroy_workqueue(Periodic_controlvm_workqueue);
2306 Periodic_controlvm_workqueue = NULL;
2307 destroy_controlvm_payload_info(&ControlVm_payload_info);
2309 Test_Vnic_channel = NULL;
2310 if (Putfile_buffer_list_pool) {
2311 kmem_cache_destroy(Putfile_buffer_list_pool);
2312 Putfile_buffer_list_pool = NULL;
2315 cleanup_controlvm_structures();
2317 memset(&g_DiagMsgHdr, 0, sizeof(struct controlvm_message_header));
2319 memset(&g_ChipSetMsgHdr, 0, sizeof(struct controlvm_message_header));
2321 memset(&g_DelDumpMsgHdr, 0, sizeof(struct controlvm_message_header));
2323 visorchannel_destroy(ControlVm_channel);
2325 visorchipset_file_cleanup();
2326 POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO);
2329 module_param_named(testvnic, visorchipset_testvnic, int, S_IRUGO);
2330 MODULE_PARM_DESC(visorchipset_testvnic, "1 to test vnic, using dummy VNIC connected via a loopback to a physical ethernet");
2331 int visorchipset_testvnic = 0;
2333 module_param_named(testvnicclient, visorchipset_testvnicclient, int, S_IRUGO);
2334 MODULE_PARM_DESC(visorchipset_testvnicclient, "1 to test vnic, using real VNIC channel attached to a separate IOVM guest");
2335 int visorchipset_testvnicclient = 0;
2337 module_param_named(testmsg, visorchipset_testmsg, int, S_IRUGO);
2338 MODULE_PARM_DESC(visorchipset_testmsg,
2339 "1 to manufacture the chipset, bus, and switch messages");
2340 int visorchipset_testmsg = 0;
2342 module_param_named(major, visorchipset_major, int, S_IRUGO);
2343 MODULE_PARM_DESC(visorchipset_major, "major device number to use for the device node");
2344 int visorchipset_major = 0;
2346 module_param_named(serverregwait, visorchipset_serverregwait, int, S_IRUGO);
2347 MODULE_PARM_DESC(visorchipset_serverreqwait,
2348 "1 to have the module wait for the visor bus to register");
2349 int visorchipset_serverregwait = 0; /* default is off */
2350 module_param_named(clientregwait, visorchipset_clientregwait, int, S_IRUGO);
2351 MODULE_PARM_DESC(visorchipset_clientregwait, "1 to have the module wait for the visorclientbus to register");
2352 int visorchipset_clientregwait = 1; /* default is on */
2353 module_param_named(testteardown, visorchipset_testteardown, int, S_IRUGO);
2354 MODULE_PARM_DESC(visorchipset_testteardown,
2355 "1 to test teardown of the chipset, bus, and switch");
2356 int visorchipset_testteardown = 0; /* default is off */
2357 module_param_named(disable_controlvm, visorchipset_disable_controlvm, int,
2359 MODULE_PARM_DESC(visorchipset_disable_controlvm,
2360 "1 to disable polling of controlVm channel");
2361 int visorchipset_disable_controlvm = 0; /* default is off */
2362 module_param_named(crash_kernel, visorchipset_crash_kernel, int, S_IRUGO);
2363 MODULE_PARM_DESC(visorchipset_crash_kernel,
2364 "1 means we are running in crash kernel");
2365 int visorchipset_crash_kernel = 0; /* default is running in non-crash kernel */
2366 module_param_named(holdchipsetready, visorchipset_holdchipsetready,
2368 MODULE_PARM_DESC(visorchipset_holdchipsetready,
2369 "1 to hold response to CHIPSET_READY");
2370 int visorchipset_holdchipsetready = 0; /* default is to send CHIPSET_READY
2371 * response immediately */
2372 module_init(visorchipset_init);
2373 module_exit(visorchipset_exit);
2375 MODULE_AUTHOR("Unisys");
2376 MODULE_LICENSE("GPL");
2377 MODULE_DESCRIPTION("Supervisor chipset driver for service partition: ver "
2379 MODULE_VERSION(VERSION);