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"
28 #include "controlvmcompletionstatus.h"
29 #include "guestlinuxdebug.h"
31 #include <linux/nls.h>
32 #include <linux/netdevice.h>
33 #include <linux/platform_device.h>
34 #include <linux/uuid.h>
36 #define CURRENT_FILE_PC VISOR_CHIPSET_PC_visorchipset_main_c
37 #define TEST_VNIC_PHYSITF "eth0" /* physical network itf for
38 * vnic loopback test */
39 #define TEST_VNIC_SWITCHNO 1
40 #define TEST_VNIC_BUSNO 9
42 #define MAX_NAME_SIZE 128
43 #define MAX_IP_SIZE 50
44 #define MAXOUTSTANDINGCHANNELCOMMAND 256
45 #define POLLJIFFIES_CONTROLVMCHANNEL_FAST 1
46 #define POLLJIFFIES_CONTROLVMCHANNEL_SLOW 100
48 /* When the controlvm channel is idle for at least MIN_IDLE_SECONDS,
49 * we switch to slow polling mode. As soon as we get a controlvm
50 * message, we switch back to fast polling mode.
52 #define MIN_IDLE_SECONDS 10
53 static ulong Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_FAST
;
54 static ulong Most_recent_message_jiffies
; /* when we got our last
55 * controlvm message */
64 static int serverregistered
;
65 static int clientregistered
;
67 #define MAX_CHIPSET_EVENTS 2
68 static u8 chipset_events
[MAX_CHIPSET_EVENTS
] = { 0, 0 };
70 static struct delayed_work Periodic_controlvm_work
;
71 static struct workqueue_struct
*Periodic_controlvm_workqueue
;
72 static DEFINE_SEMAPHORE(NotifierLock
);
75 struct controlvm_message message
;
79 static struct controlvm_message_header g_DiagMsgHdr
;
80 static struct controlvm_message_header g_ChipSetMsgHdr
;
81 static struct controlvm_message_header g_DelDumpMsgHdr
;
82 static const uuid_le UltraDiagPoolChannelProtocolGuid
=
83 SPAR_DIAG_POOL_CHANNEL_PROTOCOL_UUID
;
84 /* 0xffffff is an invalid Bus/Device number */
85 static ulong g_diagpoolBusNo
= 0xffffff;
86 static ulong g_diagpoolDevNo
= 0xffffff;
87 static struct controlvm_message_packet g_DeviceChangeStatePacket
;
89 /* Only VNIC and VHBA channels are sent to visorclientbus (aka
92 #define FOR_VISORHACKBUS(channel_type_guid) \
93 (((uuid_le_cmp(channel_type_guid,\
94 spar_vnic_channel_protocol_uuid) == 0)\
95 || (uuid_le_cmp(channel_type_guid,\
96 spar_vhba_channel_protocol_uuid) == 0)))
97 #define FOR_VISORBUS(channel_type_guid) (!(FOR_VISORHACKBUS(channel_type_guid)))
99 #define is_diagpool_channel(channel_type_guid) \
100 (uuid_le_cmp(channel_type_guid, UltraDiagPoolChannelProtocolGuid) == 0)
102 static LIST_HEAD(BusInfoList
);
103 static LIST_HEAD(DevInfoList
);
105 static VISORCHANNEL
*ControlVm_channel
;
108 u8 __iomem
*ptr
; /* pointer to base address of payload pool */
109 u64 offset
; /* offset from beginning of controlvm
110 * channel to beginning of payload * pool */
111 u32 bytes
; /* number of bytes in payload pool */
112 } CONTROLVM_PAYLOAD_INFO
;
114 /* Manages the request payload in the controlvm channel */
115 static CONTROLVM_PAYLOAD_INFO ControlVm_payload_info
;
117 static struct channel_header
*Test_Vnic_channel
;
120 struct controlvm_message_header Dumpcapture_header
;
121 struct controlvm_message_header Gettextdump_header
;
122 struct controlvm_message_header Dumpcomplete_header
;
123 BOOL Gettextdump_outstanding
;
126 atomic_t buffers_in_use
;
129 /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
130 * CONTROLVM_DUMP_GETTEXTDUMP / CONTROLVM_DUMP_COMPLETE conversation.
132 static LIVEDUMP_INFO LiveDump_info
;
134 /* The following globals are used to handle the scenario where we are unable to
135 * offload the payload from a controlvm message due to memory requirements. In
136 * this scenario, we simply stash the controlvm message, then attempt to
137 * process it again the next time controlvm_periodic_work() runs.
139 static struct controlvm_message ControlVm_Pending_Msg
;
140 static BOOL ControlVm_Pending_Msg_Valid
= FALSE
;
142 /* Pool of struct putfile_buffer_entry, for keeping track of pending (incoming)
143 * TRANSMIT_FILE PutFile payloads.
145 static struct kmem_cache
*Putfile_buffer_list_pool
;
146 static const char Putfile_buffer_list_pool_name
[] =
147 "controlvm_putfile_buffer_list_pool";
149 /* This identifies a data buffer that has been received via a controlvm messages
150 * in a remote --> local CONTROLVM_TRANSMIT_FILE conversation.
152 struct putfile_buffer_entry
{
153 struct list_head next
; /* putfile_buffer_entry list */
154 PARSER_CONTEXT
*parser_ctx
; /* points to buffer containing input data */
157 /* List of struct putfile_request *, via next_putfile_request member.
158 * Each entry in this list identifies an outstanding TRANSMIT_FILE
161 static LIST_HEAD(Putfile_request_list
);
163 /* This describes a buffer and its current state of transfer (e.g., how many
164 * bytes have already been supplied as putfile data, and how many bytes are
165 * remaining) for a putfile_request.
167 struct putfile_active_buffer
{
168 /* a payload from a controlvm message, containing a file data buffer */
169 PARSER_CONTEXT
*parser_ctx
;
170 /* points within data area of parser_ctx to next byte of data */
172 /* # bytes left from <pnext> to the end of this data buffer */
173 size_t bytes_remaining
;
176 #define PUTFILE_REQUEST_SIG 0x0906101302281211
177 /* This identifies a single remote --> local CONTROLVM_TRANSMIT_FILE
178 * conversation. Structs of this type are dynamically linked into
179 * <Putfile_request_list>.
181 struct putfile_request
{
182 u64 sig
; /* PUTFILE_REQUEST_SIG */
184 /* header from original TransmitFile request */
185 struct controlvm_message_header controlvm_header
;
186 u64 file_request_number
; /* from original TransmitFile request */
188 /* link to next struct putfile_request */
189 struct list_head next_putfile_request
;
191 /* most-recent sequence number supplied via a controlvm message */
192 u64 data_sequence_number
;
194 /* head of putfile_buffer_entry list, which describes the data to be
195 * supplied as putfile data;
196 * - this list is added to when controlvm messages come in that supply
198 * - this list is removed from via the hotplug program that is actually
199 * consuming these buffers to write as file data */
200 struct list_head input_buffer_list
;
201 spinlock_t req_list_lock
; /* lock for input_buffer_list */
203 /* waiters for input_buffer_list to go non-empty */
204 wait_queue_head_t input_buffer_wq
;
206 /* data not yet read within current putfile_buffer_entry */
207 struct putfile_active_buffer active_buf
;
209 /* <0 = failed, 0 = in-progress, >0 = successful; */
210 /* note that this must be set with req_list_lock, and if you set <0, */
211 /* it is your responsibility to also free up all of the other objects */
212 /* in this struct (like input_buffer_list, active_buf.parser_ctx) */
213 /* before releasing the lock */
214 int completion_status
;
217 static atomic_t Visorchipset_cache_buffers_in_use
= ATOMIC_INIT(0);
219 struct parahotplug_request
{
220 struct list_head list
;
222 unsigned long expiration
;
223 struct controlvm_message msg
;
226 static LIST_HEAD(Parahotplug_request_list
);
227 static DEFINE_SPINLOCK(Parahotplug_request_list_lock
); /* lock for above */
228 static void parahotplug_process_list(void);
230 /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
231 * CONTROLVM_REPORTEVENT.
233 static VISORCHIPSET_BUSDEV_NOTIFIERS BusDev_Server_Notifiers
;
234 static VISORCHIPSET_BUSDEV_NOTIFIERS BusDev_Client_Notifiers
;
236 static void bus_create_response(ulong busNo
, int response
);
237 static void bus_destroy_response(ulong busNo
, int response
);
238 static void device_create_response(ulong busNo
, ulong devNo
, int response
);
239 static void device_destroy_response(ulong busNo
, ulong devNo
, int response
);
240 static void device_resume_response(ulong busNo
, ulong devNo
, int response
);
242 static VISORCHIPSET_BUSDEV_RESPONDERS BusDev_Responders
= {
243 .bus_create
= bus_create_response
,
244 .bus_destroy
= bus_destroy_response
,
245 .device_create
= device_create_response
,
246 .device_destroy
= device_destroy_response
,
247 .device_pause
= visorchipset_device_pause_response
,
248 .device_resume
= device_resume_response
,
251 /* info for /dev/visorchipset */
252 static dev_t MajorDev
= -1; /**< indicates major num for device */
254 /* prototypes for attributes */
255 static ssize_t
toolaction_show(struct device
*dev
,
256 struct device_attribute
*attr
, char *buf
);
257 static ssize_t
toolaction_store(struct device
*dev
,
258 struct device_attribute
*attr
, const char *buf
, size_t count
);
259 static DEVICE_ATTR_RW(toolaction
);
261 static ssize_t
boottotool_show(struct device
*dev
,
262 struct device_attribute
*attr
, char *buf
);
263 static ssize_t
boottotool_store(struct device
*dev
,
264 struct device_attribute
*attr
, const char *buf
, size_t count
);
265 static DEVICE_ATTR_RW(boottotool
);
267 static ssize_t
error_show(struct device
*dev
, struct device_attribute
*attr
,
269 static ssize_t
error_store(struct device
*dev
, struct device_attribute
*attr
,
270 const char *buf
, size_t count
);
271 static DEVICE_ATTR_RW(error
);
273 static ssize_t
textid_show(struct device
*dev
, struct device_attribute
*attr
,
275 static ssize_t
textid_store(struct device
*dev
, struct device_attribute
*attr
,
276 const char *buf
, size_t count
);
277 static DEVICE_ATTR_RW(textid
);
279 static ssize_t
remaining_steps_show(struct device
*dev
,
280 struct device_attribute
*attr
, char *buf
);
281 static ssize_t
remaining_steps_store(struct device
*dev
,
282 struct device_attribute
*attr
, const char *buf
, size_t count
);
283 static DEVICE_ATTR_RW(remaining_steps
);
285 static ssize_t
chipsetready_store(struct device
*dev
,
286 struct device_attribute
*attr
, const char *buf
, size_t count
);
287 static DEVICE_ATTR_WO(chipsetready
);
289 static ssize_t
devicedisabled_store(struct device
*dev
,
290 struct device_attribute
*attr
, const char *buf
, size_t count
);
291 static DEVICE_ATTR_WO(devicedisabled
);
293 static ssize_t
deviceenabled_store(struct device
*dev
,
294 struct device_attribute
*attr
, const char *buf
, size_t count
);
295 static DEVICE_ATTR_WO(deviceenabled
);
297 static struct attribute
*visorchipset_install_attrs
[] = {
298 &dev_attr_toolaction
.attr
,
299 &dev_attr_boottotool
.attr
,
300 &dev_attr_error
.attr
,
301 &dev_attr_textid
.attr
,
302 &dev_attr_remaining_steps
.attr
,
306 static struct attribute_group visorchipset_install_group
= {
308 .attrs
= visorchipset_install_attrs
311 static struct attribute
*visorchipset_guest_attrs
[] = {
312 &dev_attr_chipsetready
.attr
,
316 static struct attribute_group visorchipset_guest_group
= {
318 .attrs
= visorchipset_guest_attrs
321 static struct attribute
*visorchipset_parahotplug_attrs
[] = {
322 &dev_attr_devicedisabled
.attr
,
323 &dev_attr_deviceenabled
.attr
,
327 static struct attribute_group visorchipset_parahotplug_group
= {
328 .name
= "parahotplug",
329 .attrs
= visorchipset_parahotplug_attrs
332 static const struct attribute_group
*visorchipset_dev_groups
[] = {
333 &visorchipset_install_group
,
334 &visorchipset_guest_group
,
335 &visorchipset_parahotplug_group
,
339 /* /sys/devices/platform/visorchipset */
340 static struct platform_device Visorchipset_platform_device
= {
341 .name
= "visorchipset",
343 .dev
.groups
= visorchipset_dev_groups
,
346 /* Function prototypes */
347 static void controlvm_respond(struct controlvm_message_header
*msgHdr
,
349 static void controlvm_respond_chipset_init(
350 struct controlvm_message_header
*msgHdr
, int response
,
351 enum ultra_chipset_feature features
);
352 static void controlvm_respond_physdev_changestate(
353 struct controlvm_message_header
*msgHdr
, int response
,
354 struct spar_segment_state state
);
356 static ssize_t
toolaction_show(struct device
*dev
,
357 struct device_attribute
*attr
,
362 visorchannel_read(ControlVm_channel
,
363 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
364 ToolAction
), &toolAction
, sizeof(u8
));
365 return scnprintf(buf
, PAGE_SIZE
, "%u\n", toolAction
);
368 static ssize_t
toolaction_store(struct device
*dev
,
369 struct device_attribute
*attr
,
370 const char *buf
, size_t count
)
375 if (kstrtou8(buf
, 10, &toolAction
) != 0)
378 ret
= visorchannel_write(ControlVm_channel
,
379 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
, ToolAction
),
380 &toolAction
, sizeof(u8
));
387 static ssize_t
boottotool_show(struct device
*dev
,
388 struct device_attribute
*attr
,
391 struct efi_spar_indication efiSparIndication
;
393 visorchannel_read(ControlVm_channel
,
394 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
395 EfiSparIndication
), &efiSparIndication
,
396 sizeof(struct efi_spar_indication
));
397 return scnprintf(buf
, PAGE_SIZE
, "%u\n",
398 efiSparIndication
.boot_to_tool
);
401 static ssize_t
boottotool_store(struct device
*dev
,
402 struct device_attribute
*attr
,
403 const char *buf
, size_t count
)
406 struct efi_spar_indication efiSparIndication
;
408 if (kstrtoint(buf
, 10, &val
) != 0)
411 efiSparIndication
.boot_to_tool
= val
;
412 ret
= visorchannel_write(ControlVm_channel
,
413 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
415 &(efiSparIndication
),
416 sizeof(struct efi_spar_indication
));
423 static ssize_t
error_show(struct device
*dev
, struct device_attribute
*attr
,
428 visorchannel_read(ControlVm_channel
, offsetof(
429 ULTRA_CONTROLVM_CHANNEL_PROTOCOL
, InstallationError
),
430 &error
, sizeof(u32
));
431 return scnprintf(buf
, PAGE_SIZE
, "%i\n", error
);
434 static ssize_t
error_store(struct device
*dev
, struct device_attribute
*attr
,
435 const char *buf
, size_t count
)
440 if (kstrtou32(buf
, 10, &error
) != 0)
443 ret
= visorchannel_write(ControlVm_channel
,
444 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
446 &error
, sizeof(u32
));
452 static ssize_t
textid_show(struct device
*dev
, struct device_attribute
*attr
,
457 visorchannel_read(ControlVm_channel
, offsetof(
458 ULTRA_CONTROLVM_CHANNEL_PROTOCOL
, InstallationTextId
),
459 &textId
, sizeof(u32
));
460 return scnprintf(buf
, PAGE_SIZE
, "%i\n", textId
);
463 static ssize_t
textid_store(struct device
*dev
, struct device_attribute
*attr
,
464 const char *buf
, size_t count
)
469 if (kstrtou32(buf
, 10, &textId
) != 0)
472 ret
= visorchannel_write(ControlVm_channel
,
473 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
475 &textId
, sizeof(u32
));
482 static ssize_t
remaining_steps_show(struct device
*dev
,
483 struct device_attribute
*attr
, char *buf
)
487 visorchannel_read(ControlVm_channel
,
488 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
489 InstallationRemainingSteps
),
492 return scnprintf(buf
, PAGE_SIZE
, "%hu\n", remainingSteps
);
495 static ssize_t
remaining_steps_store(struct device
*dev
,
496 struct device_attribute
*attr
, const char *buf
, size_t count
)
501 if (kstrtou16(buf
, 10, &remainingSteps
) != 0)
504 ret
= visorchannel_write(ControlVm_channel
,
505 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
506 InstallationRemainingSteps
),
507 &remainingSteps
, sizeof(u16
));
517 wchar_t unicodeString
[] = { 'a', 'b', 'c', 0 };
518 char s
[sizeof(unicodeString
) * NLS_MAX_CHARSET_SIZE
];
519 wchar_t unicode2
[99];
521 /* NOTE: Either due to a bug, or feature I don't understand, the
522 * kernel utf8_mbstowcs() and utf_wcstombs() do NOT copy the
523 * trailed NUL byte!! REALLY!!!!! Arrrrgggghhhhh
526 LOGINF("sizeof(wchar_t) = %d", sizeof(wchar_t));
527 LOGINF("utf8_wcstombs=%d",
528 chrs
= utf8_wcstombs(s
, unicodeString
, sizeof(s
)));
530 s
[chrs
] = '\0'; /* GRRRRRRRR */
532 LOGINF("utf8_mbstowcs=%d", chrs
= utf8_mbstowcs(unicode2
, s
, 100));
534 unicode2
[chrs
] = 0; /* GRRRRRRRR */
535 if (memcmp(unicodeString
, unicode2
, sizeof(unicodeString
)) == 0)
536 LOGINF("strings match... good");
538 LOGINF("strings did not match!!");
543 busInfo_clear(void *v
)
545 VISORCHIPSET_BUS_INFO
*p
= (VISORCHIPSET_BUS_INFO
*) (v
);
548 visor_proc_DestroyObject(p
->procObject
);
549 p
->procObject
= NULL
;
554 kfree(p
->description
);
555 p
->description
= NULL
;
557 p
->state
.created
= 0;
558 memset(p
, 0, sizeof(VISORCHIPSET_BUS_INFO
));
562 devInfo_clear(void *v
)
564 VISORCHIPSET_DEVICE_INFO
*p
= (VISORCHIPSET_DEVICE_INFO
*) (v
);
566 p
->state
.created
= 0;
567 memset(p
, 0, sizeof(VISORCHIPSET_DEVICE_INFO
));
571 check_chipset_events(void)
575 /* Check events to determine if response should be sent */
576 for (i
= 0; i
< MAX_CHIPSET_EVENTS
; i
++)
577 send_msg
&= chipset_events
[i
];
582 clear_chipset_events(void)
585 /* Clear chipset_events */
586 for (i
= 0; i
< MAX_CHIPSET_EVENTS
; i
++)
587 chipset_events
[i
] = 0;
591 visorchipset_register_busdev_server(VISORCHIPSET_BUSDEV_NOTIFIERS
*notifiers
,
592 VISORCHIPSET_BUSDEV_RESPONDERS
*responders
,
593 struct ultra_vbus_deviceinfo
*driverInfo
)
596 if (notifiers
== NULL
) {
597 memset(&BusDev_Server_Notifiers
, 0,
598 sizeof(BusDev_Server_Notifiers
));
599 serverregistered
= 0; /* clear flag */
601 BusDev_Server_Notifiers
= *notifiers
;
602 serverregistered
= 1; /* set flag */
605 *responders
= BusDev_Responders
;
607 bus_device_info_init(driverInfo
, "chipset", "visorchipset",
612 EXPORT_SYMBOL_GPL(visorchipset_register_busdev_server
);
615 visorchipset_register_busdev_client(VISORCHIPSET_BUSDEV_NOTIFIERS
*notifiers
,
616 VISORCHIPSET_BUSDEV_RESPONDERS
*responders
,
617 struct ultra_vbus_deviceinfo
*driverInfo
)
620 if (notifiers
== NULL
) {
621 memset(&BusDev_Client_Notifiers
, 0,
622 sizeof(BusDev_Client_Notifiers
));
623 clientregistered
= 0; /* clear flag */
625 BusDev_Client_Notifiers
= *notifiers
;
626 clientregistered
= 1; /* set flag */
629 *responders
= BusDev_Responders
;
631 bus_device_info_init(driverInfo
, "chipset(bolts)", "visorchipset",
635 EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client
);
638 cleanup_controlvm_structures(void)
640 VISORCHIPSET_BUS_INFO
*bi
, *tmp_bi
;
641 VISORCHIPSET_DEVICE_INFO
*di
, *tmp_di
;
643 list_for_each_entry_safe(bi
, tmp_bi
, &BusInfoList
, entry
) {
645 list_del(&bi
->entry
);
649 list_for_each_entry_safe(di
, tmp_di
, &DevInfoList
, entry
) {
651 list_del(&di
->entry
);
657 chipset_init(struct controlvm_message
*inmsg
)
659 static int chipset_inited
;
660 enum ultra_chipset_feature features
= 0;
661 int rc
= CONTROLVM_RESP_SUCCESS
;
663 POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
664 if (chipset_inited
) {
665 LOGERR("CONTROLVM_CHIPSET_INIT Failed: Already Done.");
666 rc
= -CONTROLVM_RESP_ERROR_ALREADY_DONE
;
670 POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
672 /* Set features to indicate we support parahotplug (if Command
673 * also supports it). */
675 inmsg
->cmd
.init_chipset
.
676 features
& ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG
;
678 /* Set the "reply" bit so Command knows this is a
679 * features-aware driver. */
680 features
|= ULTRA_CHIPSET_FEATURE_REPLY
;
684 cleanup_controlvm_structures();
685 if (inmsg
->hdr
.flags
.response_expected
)
686 controlvm_respond_chipset_init(&inmsg
->hdr
, rc
, features
);
690 controlvm_init_response(struct controlvm_message
*msg
,
691 struct controlvm_message_header
*msgHdr
, int response
)
693 memset(msg
, 0, sizeof(struct controlvm_message
));
694 memcpy(&msg
->hdr
, msgHdr
, sizeof(struct controlvm_message_header
));
695 msg
->hdr
.payload_bytes
= 0;
696 msg
->hdr
.payload_vm_offset
= 0;
697 msg
->hdr
.payload_max_bytes
= 0;
699 msg
->hdr
.flags
.failed
= 1;
700 msg
->hdr
.completion_status
= (u32
) (-response
);
705 controlvm_respond(struct controlvm_message_header
*msgHdr
, int response
)
707 struct controlvm_message outmsg
;
709 controlvm_init_response(&outmsg
, msgHdr
, response
);
710 /* For DiagPool channel DEVICE_CHANGESTATE, we need to send
711 * back the deviceChangeState structure in the packet. */
712 if (msgHdr
->id
== CONTROLVM_DEVICE_CHANGESTATE
713 && g_DeviceChangeStatePacket
.device_change_state
.bus_no
==
715 && g_DeviceChangeStatePacket
.device_change_state
.dev_no
==
717 outmsg
.cmd
= g_DeviceChangeStatePacket
;
718 if (outmsg
.hdr
.flags
.test_message
== 1) {
719 LOGINF("%s controlvm_msg=0x%x response=%d for test message",
720 __func__
, outmsg
.hdr
.id
, response
);
723 if (!visorchannel_signalinsert(ControlVm_channel
,
724 CONTROLVM_QUEUE_REQUEST
, &outmsg
)) {
725 LOGERR("signalinsert failed!");
731 controlvm_respond_chipset_init(struct controlvm_message_header
*msgHdr
,
733 enum ultra_chipset_feature features
)
735 struct controlvm_message outmsg
;
737 controlvm_init_response(&outmsg
, msgHdr
, response
);
738 outmsg
.cmd
.init_chipset
.features
= features
;
739 if (!visorchannel_signalinsert(ControlVm_channel
,
740 CONTROLVM_QUEUE_REQUEST
, &outmsg
)) {
741 LOGERR("signalinsert failed!");
746 static void controlvm_respond_physdev_changestate(
747 struct controlvm_message_header
*msgHdr
, int response
,
748 struct spar_segment_state state
)
750 struct controlvm_message outmsg
;
752 controlvm_init_response(&outmsg
, msgHdr
, response
);
753 outmsg
.cmd
.device_change_state
.state
= state
;
754 outmsg
.cmd
.device_change_state
.flags
.phys_device
= 1;
755 if (!visorchannel_signalinsert(ControlVm_channel
,
756 CONTROLVM_QUEUE_REQUEST
, &outmsg
)) {
757 LOGERR("signalinsert failed!");
763 visorchipset_save_message(struct controlvm_message
*msg
, CRASH_OBJ_TYPE type
)
765 u32 localSavedCrashMsgOffset
;
766 u16 localSavedCrashMsgCount
;
768 /* get saved message count */
769 if (visorchannel_read(ControlVm_channel
,
770 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
772 &localSavedCrashMsgCount
, sizeof(u16
)) < 0) {
773 LOGERR("failed to get Saved Message Count");
774 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC
,
775 POSTCODE_SEVERITY_ERR
);
779 if (localSavedCrashMsgCount
!= CONTROLVM_CRASHMSG_MAX
) {
780 LOGERR("Saved Message Count incorrect %d",
781 localSavedCrashMsgCount
);
782 POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC
,
783 localSavedCrashMsgCount
,
784 POSTCODE_SEVERITY_ERR
);
788 /* get saved crash message offset */
789 if (visorchannel_read(ControlVm_channel
,
790 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
791 SavedCrashMsgOffset
),
792 &localSavedCrashMsgOffset
, sizeof(u32
)) < 0) {
793 LOGERR("failed to get Saved Message Offset");
794 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC
,
795 POSTCODE_SEVERITY_ERR
);
799 if (type
== CRASH_bus
) {
800 if (visorchannel_write(ControlVm_channel
,
801 localSavedCrashMsgOffset
,
803 sizeof(struct controlvm_message
)) < 0) {
804 LOGERR("SAVE_MSG_BUS_FAILURE: Failed to write CrashCreateBusMsg!");
805 POSTCODE_LINUX_2(SAVE_MSG_BUS_FAILURE_PC
,
806 POSTCODE_SEVERITY_ERR
);
810 if (visorchannel_write(ControlVm_channel
,
811 localSavedCrashMsgOffset
+
812 sizeof(struct controlvm_message
), msg
,
813 sizeof(struct controlvm_message
)) < 0) {
814 LOGERR("SAVE_MSG_DEV_FAILURE: Failed to write CrashCreateDevMsg!");
815 POSTCODE_LINUX_2(SAVE_MSG_DEV_FAILURE_PC
,
816 POSTCODE_SEVERITY_ERR
);
821 EXPORT_SYMBOL_GPL(visorchipset_save_message
);
824 bus_responder(enum controlvm_id cmdId
, ulong busNo
, int response
)
826 VISORCHIPSET_BUS_INFO
*p
= NULL
;
827 BOOL need_clear
= FALSE
;
829 p
= findbus(&BusInfoList
, busNo
);
831 LOGERR("internal error busNo=%lu", busNo
);
835 if ((cmdId
== CONTROLVM_BUS_CREATE
) &&
836 (response
!= (-CONTROLVM_RESP_ERROR_ALREADY_DONE
)))
837 /* undo the row we just created... */
838 delbusdevices(&DevInfoList
, busNo
);
840 if (cmdId
== CONTROLVM_BUS_CREATE
)
841 p
->state
.created
= 1;
842 if (cmdId
== CONTROLVM_BUS_DESTROY
)
846 if (p
->pendingMsgHdr
.id
== CONTROLVM_INVALID
) {
847 LOGERR("bus_responder no pending msg");
848 return; /* no controlvm response needed */
850 if (p
->pendingMsgHdr
.id
!= (u32
) cmdId
) {
851 LOGERR("expected=%d, found=%d", cmdId
, p
->pendingMsgHdr
.id
);
854 controlvm_respond(&p
->pendingMsgHdr
, response
);
855 p
->pendingMsgHdr
.id
= CONTROLVM_INVALID
;
858 delbusdevices(&DevInfoList
, busNo
);
863 device_changestate_responder(enum controlvm_id cmdId
,
864 ulong busNo
, ulong devNo
, int response
,
865 struct spar_segment_state responseState
)
867 VISORCHIPSET_DEVICE_INFO
*p
= NULL
;
868 struct controlvm_message outmsg
;
870 p
= finddevice(&DevInfoList
, busNo
, devNo
);
872 LOGERR("internal error; busNo=%lu, devNo=%lu", busNo
, devNo
);
875 if (p
->pendingMsgHdr
.id
== CONTROLVM_INVALID
) {
876 LOGERR("device_responder no pending msg");
877 return; /* no controlvm response needed */
879 if (p
->pendingMsgHdr
.id
!= cmdId
) {
880 LOGERR("expected=%d, found=%d", cmdId
, p
->pendingMsgHdr
.id
);
884 controlvm_init_response(&outmsg
, &p
->pendingMsgHdr
, response
);
886 outmsg
.cmd
.device_change_state
.bus_no
= busNo
;
887 outmsg
.cmd
.device_change_state
.dev_no
= devNo
;
888 outmsg
.cmd
.device_change_state
.state
= responseState
;
890 if (!visorchannel_signalinsert(ControlVm_channel
,
891 CONTROLVM_QUEUE_REQUEST
, &outmsg
)) {
892 LOGERR("signalinsert failed!");
896 p
->pendingMsgHdr
.id
= CONTROLVM_INVALID
;
900 device_responder(enum controlvm_id cmdId
, ulong busNo
, ulong devNo
,
903 VISORCHIPSET_DEVICE_INFO
*p
= NULL
;
904 BOOL need_clear
= FALSE
;
906 p
= finddevice(&DevInfoList
, busNo
, devNo
);
908 LOGERR("internal error; busNo=%lu, devNo=%lu", busNo
, devNo
);
912 if (cmdId
== CONTROLVM_DEVICE_CREATE
)
913 p
->state
.created
= 1;
914 if (cmdId
== CONTROLVM_DEVICE_DESTROY
)
918 if (p
->pendingMsgHdr
.id
== CONTROLVM_INVALID
) {
919 LOGERR("device_responder no pending msg");
920 return; /* no controlvm response needed */
922 if (p
->pendingMsgHdr
.id
!= (u32
) cmdId
) {
923 LOGERR("expected=%d, found=%d", cmdId
, p
->pendingMsgHdr
.id
);
926 controlvm_respond(&p
->pendingMsgHdr
, response
);
927 p
->pendingMsgHdr
.id
= CONTROLVM_INVALID
;
933 bus_epilog(u32 busNo
,
934 u32 cmd
, struct controlvm_message_header
*msgHdr
,
935 int response
, BOOL needResponse
)
937 BOOL notified
= FALSE
;
939 VISORCHIPSET_BUS_INFO
*pBusInfo
= findbus(&BusInfoList
, busNo
);
942 LOGERR("HUH? bad busNo=%d", busNo
);
946 memcpy(&pBusInfo
->pendingMsgHdr
, msgHdr
,
947 sizeof(struct controlvm_message_header
));
949 pBusInfo
->pendingMsgHdr
.id
= CONTROLVM_INVALID
;
952 if (response
== CONTROLVM_RESP_SUCCESS
) {
954 case CONTROLVM_BUS_CREATE
:
955 /* We can't tell from the bus_create
956 * information which of our 2 bus flavors the
957 * devices on this bus will ultimately end up.
958 * FORTUNATELY, it turns out it is harmless to
959 * send the bus_create to both of them. We can
960 * narrow things down a little bit, though,
961 * because we know: - BusDev_Server can handle
962 * either server or client devices
963 * - BusDev_Client can handle ONLY client
965 if (BusDev_Server_Notifiers
.bus_create
) {
966 (*BusDev_Server_Notifiers
.bus_create
) (busNo
);
969 if ((!pBusInfo
->flags
.server
) /*client */ &&
970 BusDev_Client_Notifiers
.bus_create
) {
971 (*BusDev_Client_Notifiers
.bus_create
) (busNo
);
975 case CONTROLVM_BUS_DESTROY
:
976 if (BusDev_Server_Notifiers
.bus_destroy
) {
977 (*BusDev_Server_Notifiers
.bus_destroy
) (busNo
);
980 if ((!pBusInfo
->flags
.server
) /*client */ &&
981 BusDev_Client_Notifiers
.bus_destroy
) {
982 (*BusDev_Client_Notifiers
.bus_destroy
) (busNo
);
989 /* The callback function just called above is responsible
990 * for calling the appropriate VISORCHIPSET_BUSDEV_RESPONDERS
991 * function, which will call bus_responder()
995 bus_responder(cmd
, busNo
, response
);
1000 device_epilog(u32 busNo
, u32 devNo
, struct spar_segment_state state
, u32 cmd
,
1001 struct controlvm_message_header
*msgHdr
, int response
,
1002 BOOL needResponse
, BOOL for_visorbus
)
1004 VISORCHIPSET_BUSDEV_NOTIFIERS
*notifiers
= NULL
;
1005 BOOL notified
= FALSE
;
1007 VISORCHIPSET_DEVICE_INFO
*pDevInfo
=
1008 finddevice(&DevInfoList
, busNo
, devNo
);
1010 "SPARSP_DIAGPOOL_PAUSED_STATE = 1",
1015 LOGERR("HUH? bad busNo=%d, devNo=%d", busNo
, devNo
);
1019 notifiers
= &BusDev_Server_Notifiers
;
1021 notifiers
= &BusDev_Client_Notifiers
;
1023 memcpy(&pDevInfo
->pendingMsgHdr
, msgHdr
,
1024 sizeof(struct controlvm_message_header
));
1026 pDevInfo
->pendingMsgHdr
.id
= CONTROLVM_INVALID
;
1028 down(&NotifierLock
);
1029 if (response
>= 0) {
1031 case CONTROLVM_DEVICE_CREATE
:
1032 if (notifiers
->device_create
) {
1033 (*notifiers
->device_create
) (busNo
, devNo
);
1037 case CONTROLVM_DEVICE_CHANGESTATE
:
1038 /* ServerReady / ServerRunning / SegmentStateRunning */
1039 if (state
.alive
== segment_state_running
.alive
&&
1041 segment_state_running
.operating
) {
1042 if (notifiers
->device_resume
) {
1043 (*notifiers
->device_resume
) (busNo
,
1048 /* ServerNotReady / ServerLost / SegmentStateStandby */
1049 else if (state
.alive
== segment_state_standby
.alive
&&
1051 segment_state_standby
.operating
) {
1052 /* technically this is standby case
1053 * where server is lost
1055 if (notifiers
->device_pause
) {
1056 (*notifiers
->device_pause
) (busNo
,
1060 } else if (state
.alive
== segment_state_paused
.alive
&&
1062 segment_state_paused
.operating
) {
1063 /* this is lite pause where channel is
1064 * still valid just 'pause' of it
1066 if (busNo
== g_diagpoolBusNo
1067 && devNo
== g_diagpoolDevNo
) {
1068 LOGINF("DEVICE_CHANGESTATE(DiagpoolChannel busNo=%d devNo=%d is pausing...)",
1070 /* this will trigger the
1071 * diag_shutdown.sh script in
1072 * the visorchipset hotplug */
1074 (&Visorchipset_platform_device
.dev
.
1075 kobj
, KOBJ_ONLINE
, envp
);
1079 case CONTROLVM_DEVICE_DESTROY
:
1080 if (notifiers
->device_destroy
) {
1081 (*notifiers
->device_destroy
) (busNo
, devNo
);
1088 /* The callback function just called above is responsible
1089 * for calling the appropriate VISORCHIPSET_BUSDEV_RESPONDERS
1090 * function, which will call device_responder()
1094 device_responder(cmd
, busNo
, devNo
, response
);
1099 bus_create(struct controlvm_message
*inmsg
)
1101 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
1102 ulong busNo
= cmd
->create_bus
.bus_no
;
1103 int rc
= CONTROLVM_RESP_SUCCESS
;
1104 VISORCHIPSET_BUS_INFO
*pBusInfo
= NULL
;
1107 pBusInfo
= findbus(&BusInfoList
, busNo
);
1108 if (pBusInfo
&& (pBusInfo
->state
.created
== 1)) {
1109 LOGERR("CONTROLVM_BUS_CREATE Failed: bus %lu already exists",
1111 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC
, busNo
,
1112 POSTCODE_SEVERITY_ERR
);
1113 rc
= -CONTROLVM_RESP_ERROR_ALREADY_DONE
;
1116 pBusInfo
= kzalloc(sizeof(VISORCHIPSET_BUS_INFO
), GFP_KERNEL
);
1117 if (pBusInfo
== NULL
) {
1118 LOGERR("CONTROLVM_BUS_CREATE Failed: bus %lu kzalloc failed",
1120 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC
, busNo
,
1121 POSTCODE_SEVERITY_ERR
);
1122 rc
= -CONTROLVM_RESP_ERROR_KMALLOC_FAILED
;
1126 INIT_LIST_HEAD(&pBusInfo
->entry
);
1127 pBusInfo
->busNo
= busNo
;
1128 pBusInfo
->devNo
= cmd
->create_bus
.dev_count
;
1130 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC
, busNo
, POSTCODE_SEVERITY_INFO
);
1132 if (inmsg
->hdr
.flags
.test_message
== 1)
1133 pBusInfo
->chanInfo
.addrType
= ADDRTYPE_localTest
;
1135 pBusInfo
->chanInfo
.addrType
= ADDRTYPE_localPhysical
;
1137 pBusInfo
->flags
.server
= inmsg
->hdr
.flags
.server
;
1138 pBusInfo
->chanInfo
.channelAddr
= cmd
->create_bus
.channel_addr
;
1139 pBusInfo
->chanInfo
.nChannelBytes
= cmd
->create_bus
.channel_bytes
;
1140 pBusInfo
->chanInfo
.channelTypeGuid
= cmd
->create_bus
.bus_data_type_uuid
;
1141 pBusInfo
->chanInfo
.channelInstGuid
= cmd
->create_bus
.bus_inst_uuid
;
1143 list_add(&pBusInfo
->entry
, &BusInfoList
);
1145 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC
, busNo
, POSTCODE_SEVERITY_INFO
);
1148 bus_epilog(busNo
, CONTROLVM_BUS_CREATE
, &inmsg
->hdr
,
1149 rc
, inmsg
->hdr
.flags
.response_expected
== 1);
1153 bus_destroy(struct controlvm_message
*inmsg
)
1155 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
1156 ulong busNo
= cmd
->destroy_bus
.bus_no
;
1157 VISORCHIPSET_BUS_INFO
*pBusInfo
;
1158 int rc
= CONTROLVM_RESP_SUCCESS
;
1160 pBusInfo
= findbus(&BusInfoList
, busNo
);
1162 LOGERR("CONTROLVM_BUS_DESTROY Failed: bus %lu invalid", busNo
);
1163 rc
= -CONTROLVM_RESP_ERROR_BUS_INVALID
;
1166 if (pBusInfo
->state
.created
== 0) {
1167 LOGERR("CONTROLVM_BUS_DESTROY Failed: bus %lu already destroyed",
1169 rc
= -CONTROLVM_RESP_ERROR_ALREADY_DONE
;
1174 bus_epilog(busNo
, CONTROLVM_BUS_DESTROY
, &inmsg
->hdr
,
1175 rc
, inmsg
->hdr
.flags
.response_expected
== 1);
1179 bus_configure(struct controlvm_message
*inmsg
, PARSER_CONTEXT
*parser_ctx
)
1181 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
1182 ulong busNo
= cmd
->configure_bus
.bus_no
;
1183 VISORCHIPSET_BUS_INFO
*pBusInfo
= NULL
;
1184 int rc
= CONTROLVM_RESP_SUCCESS
;
1187 busNo
= cmd
->configure_bus
.bus_no
;
1188 POSTCODE_LINUX_3(BUS_CONFIGURE_ENTRY_PC
, busNo
, POSTCODE_SEVERITY_INFO
);
1190 pBusInfo
= findbus(&BusInfoList
, busNo
);
1192 LOGERR("CONTROLVM_BUS_CONFIGURE Failed: bus %lu invalid",
1194 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC
, busNo
,
1195 POSTCODE_SEVERITY_ERR
);
1196 rc
= -CONTROLVM_RESP_ERROR_BUS_INVALID
;
1199 if (pBusInfo
->state
.created
== 0) {
1200 LOGERR("CONTROLVM_BUS_CONFIGURE Failed: Invalid bus %lu - not created yet",
1202 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC
, busNo
,
1203 POSTCODE_SEVERITY_ERR
);
1204 rc
= -CONTROLVM_RESP_ERROR_BUS_INVALID
;
1207 /* TBD - add this check to other commands also... */
1208 if (pBusInfo
->pendingMsgHdr
.id
!= CONTROLVM_INVALID
) {
1209 LOGERR("CONTROLVM_BUS_CONFIGURE Failed: bus %lu MsgId=%u outstanding",
1210 busNo
, (uint
) pBusInfo
->pendingMsgHdr
.id
);
1211 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC
, busNo
,
1212 POSTCODE_SEVERITY_ERR
);
1213 rc
= -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT
;
1217 pBusInfo
->partitionHandle
= cmd
->configure_bus
.guest_handle
;
1218 pBusInfo
->partitionGuid
= parser_id_get(parser_ctx
);
1219 parser_param_start(parser_ctx
, PARSERSTRING_NAME
);
1220 pBusInfo
->name
= parser_string_get(parser_ctx
);
1222 visorchannel_uuid_id(&pBusInfo
->partitionGuid
, s
);
1223 POSTCODE_LINUX_3(BUS_CONFIGURE_EXIT_PC
, busNo
, POSTCODE_SEVERITY_INFO
);
1225 bus_epilog(busNo
, CONTROLVM_BUS_CONFIGURE
, &inmsg
->hdr
,
1226 rc
, inmsg
->hdr
.flags
.response_expected
== 1);
1230 my_device_create(struct controlvm_message
*inmsg
)
1232 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
1233 ulong busNo
= cmd
->create_device
.bus_no
;
1234 ulong devNo
= cmd
->create_device
.dev_no
;
1235 VISORCHIPSET_DEVICE_INFO
*pDevInfo
= NULL
;
1236 VISORCHIPSET_BUS_INFO
*pBusInfo
= NULL
;
1237 int rc
= CONTROLVM_RESP_SUCCESS
;
1239 pDevInfo
= finddevice(&DevInfoList
, busNo
, devNo
);
1240 if (pDevInfo
&& (pDevInfo
->state
.created
== 1)) {
1241 LOGERR("CONTROLVM_DEVICE_CREATE Failed: busNo=%lu, devNo=%lu already exists",
1243 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC
, devNo
, busNo
,
1244 POSTCODE_SEVERITY_ERR
);
1245 rc
= -CONTROLVM_RESP_ERROR_ALREADY_DONE
;
1248 pBusInfo
= findbus(&BusInfoList
, busNo
);
1250 LOGERR("CONTROLVM_DEVICE_CREATE Failed: Invalid bus %lu - out of range",
1252 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC
, devNo
, busNo
,
1253 POSTCODE_SEVERITY_ERR
);
1254 rc
= -CONTROLVM_RESP_ERROR_BUS_INVALID
;
1257 if (pBusInfo
->state
.created
== 0) {
1258 LOGERR("CONTROLVM_DEVICE_CREATE Failed: Invalid bus %lu - not created yet",
1260 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC
, devNo
, busNo
,
1261 POSTCODE_SEVERITY_ERR
);
1262 rc
= -CONTROLVM_RESP_ERROR_BUS_INVALID
;
1265 pDevInfo
= kzalloc(sizeof(VISORCHIPSET_DEVICE_INFO
), GFP_KERNEL
);
1266 if (pDevInfo
== NULL
) {
1267 LOGERR("CONTROLVM_DEVICE_CREATE Failed: busNo=%lu, devNo=%lu kmaloc failed",
1269 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC
, devNo
, busNo
,
1270 POSTCODE_SEVERITY_ERR
);
1271 rc
= -CONTROLVM_RESP_ERROR_KMALLOC_FAILED
;
1275 INIT_LIST_HEAD(&pDevInfo
->entry
);
1276 pDevInfo
->busNo
= busNo
;
1277 pDevInfo
->devNo
= devNo
;
1278 pDevInfo
->devInstGuid
= cmd
->create_device
.dev_inst_uuid
;
1279 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC
, devNo
, busNo
,
1280 POSTCODE_SEVERITY_INFO
);
1282 if (inmsg
->hdr
.flags
.test_message
== 1)
1283 pDevInfo
->chanInfo
.addrType
= ADDRTYPE_localTest
;
1285 pDevInfo
->chanInfo
.addrType
= ADDRTYPE_localPhysical
;
1286 pDevInfo
->chanInfo
.channelAddr
= cmd
->create_device
.channel_addr
;
1287 pDevInfo
->chanInfo
.nChannelBytes
= cmd
->create_device
.channel_bytes
;
1288 pDevInfo
->chanInfo
.channelTypeGuid
= cmd
->create_device
.data_type_uuid
;
1289 pDevInfo
->chanInfo
.intr
= cmd
->create_device
.intr
;
1290 list_add(&pDevInfo
->entry
, &DevInfoList
);
1291 POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC
, devNo
, busNo
,
1292 POSTCODE_SEVERITY_INFO
);
1294 /* get the bus and devNo for DiagPool channel */
1295 if (is_diagpool_channel(pDevInfo
->chanInfo
.channelTypeGuid
)) {
1296 g_diagpoolBusNo
= busNo
;
1297 g_diagpoolDevNo
= devNo
;
1298 LOGINF("CONTROLVM_DEVICE_CREATE for DiagPool channel: busNo=%lu, devNo=%lu",
1299 g_diagpoolBusNo
, g_diagpoolDevNo
);
1301 device_epilog(busNo
, devNo
, segment_state_running
,
1302 CONTROLVM_DEVICE_CREATE
, &inmsg
->hdr
, rc
,
1303 inmsg
->hdr
.flags
.response_expected
== 1,
1304 FOR_VISORBUS(pDevInfo
->chanInfo
.channelTypeGuid
));
1308 my_device_changestate(struct controlvm_message
*inmsg
)
1310 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
1311 ulong busNo
= cmd
->device_change_state
.bus_no
;
1312 ulong devNo
= cmd
->device_change_state
.dev_no
;
1313 struct spar_segment_state state
= cmd
->device_change_state
.state
;
1314 VISORCHIPSET_DEVICE_INFO
*pDevInfo
= NULL
;
1315 int rc
= CONTROLVM_RESP_SUCCESS
;
1317 pDevInfo
= finddevice(&DevInfoList
, busNo
, devNo
);
1319 LOGERR("CONTROLVM_DEVICE_CHANGESTATE Failed: busNo=%lu, devNo=%lu invalid (doesn't exist)",
1321 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC
, devNo
, busNo
,
1322 POSTCODE_SEVERITY_ERR
);
1323 rc
= -CONTROLVM_RESP_ERROR_DEVICE_INVALID
;
1326 if (pDevInfo
->state
.created
== 0) {
1327 LOGERR("CONTROLVM_DEVICE_CHANGESTATE Failed: busNo=%lu, devNo=%lu invalid (not created)",
1329 POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC
, devNo
, busNo
,
1330 POSTCODE_SEVERITY_ERR
);
1331 rc
= -CONTROLVM_RESP_ERROR_DEVICE_INVALID
;
1334 if ((rc
>= CONTROLVM_RESP_SUCCESS
) && pDevInfo
)
1335 device_epilog(busNo
, devNo
, state
, CONTROLVM_DEVICE_CHANGESTATE
,
1337 inmsg
->hdr
.flags
.response_expected
== 1,
1338 FOR_VISORBUS(pDevInfo
->chanInfo
.channelTypeGuid
));
1342 my_device_destroy(struct controlvm_message
*inmsg
)
1344 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
1345 ulong busNo
= cmd
->destroy_device
.bus_no
;
1346 ulong devNo
= cmd
->destroy_device
.dev_no
;
1347 VISORCHIPSET_DEVICE_INFO
*pDevInfo
= NULL
;
1348 int rc
= CONTROLVM_RESP_SUCCESS
;
1350 pDevInfo
= finddevice(&DevInfoList
, busNo
, devNo
);
1352 LOGERR("CONTROLVM_DEVICE_DESTROY Failed: busNo=%lu, devNo=%lu invalid",
1354 rc
= -CONTROLVM_RESP_ERROR_DEVICE_INVALID
;
1357 if (pDevInfo
->state
.created
== 0) {
1358 LOGERR("CONTROLVM_DEVICE_DESTROY Failed: busNo=%lu, devNo=%lu already destroyed",
1360 rc
= -CONTROLVM_RESP_ERROR_ALREADY_DONE
;
1364 if ((rc
>= CONTROLVM_RESP_SUCCESS
) && pDevInfo
)
1365 device_epilog(busNo
, devNo
, segment_state_running
,
1366 CONTROLVM_DEVICE_DESTROY
, &inmsg
->hdr
, rc
,
1367 inmsg
->hdr
.flags
.response_expected
== 1,
1368 FOR_VISORBUS(pDevInfo
->chanInfo
.channelTypeGuid
));
1371 /* When provided with the physical address of the controlvm channel
1372 * (phys_addr), the offset to the payload area we need to manage
1373 * (offset), and the size of this payload area (bytes), fills in the
1374 * CONTROLVM_PAYLOAD_INFO struct. Returns TRUE for success or FALSE
1378 initialize_controlvm_payload_info(HOSTADDRESS phys_addr
, u64 offset
, u32 bytes
,
1379 CONTROLVM_PAYLOAD_INFO
*info
)
1381 u8 __iomem
*payload
= NULL
;
1382 int rc
= CONTROLVM_RESP_SUCCESS
;
1385 LOGERR("HUH ? CONTROLVM_PAYLOAD_INIT Failed : Programmer check at %s:%d",
1386 __FILE__
, __LINE__
);
1387 rc
= -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID
;
1390 memset(info
, 0, sizeof(CONTROLVM_PAYLOAD_INFO
));
1391 if ((offset
== 0) || (bytes
== 0)) {
1392 LOGERR("CONTROLVM_PAYLOAD_INIT Failed: RequestPayloadOffset=%llu RequestPayloadBytes=%llu!",
1393 (u64
) offset
, (u64
) bytes
);
1394 rc
= -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID
;
1397 payload
= ioremap_cache(phys_addr
+ offset
, bytes
);
1398 if (payload
== NULL
) {
1399 LOGERR("CONTROLVM_PAYLOAD_INIT Failed: ioremap_cache %llu for %llu bytes failed",
1400 (u64
) offset
, (u64
) bytes
);
1401 rc
= -CONTROLVM_RESP_ERROR_IOREMAP_FAILED
;
1405 info
->offset
= offset
;
1406 info
->bytes
= bytes
;
1407 info
->ptr
= payload
;
1408 LOGINF("offset=%llu, bytes=%lu, ptr=%p",
1409 (u64
) (info
->offset
), (ulong
) (info
->bytes
), info
->ptr
);
1413 if (payload
!= NULL
) {
1422 destroy_controlvm_payload_info(CONTROLVM_PAYLOAD_INFO
*info
)
1424 if (info
->ptr
!= NULL
) {
1428 memset(info
, 0, sizeof(CONTROLVM_PAYLOAD_INFO
));
1432 initialize_controlvm_payload(void)
1434 HOSTADDRESS phys_addr
= visorchannel_get_physaddr(ControlVm_channel
);
1435 u64 payloadOffset
= 0;
1436 u32 payloadBytes
= 0;
1438 if (visorchannel_read(ControlVm_channel
,
1439 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
1440 RequestPayloadOffset
),
1441 &payloadOffset
, sizeof(payloadOffset
)) < 0) {
1442 LOGERR("CONTROLVM_PAYLOAD_INIT Failed to read controlvm channel!");
1443 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC
,
1444 POSTCODE_SEVERITY_ERR
);
1447 if (visorchannel_read(ControlVm_channel
,
1448 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
1449 RequestPayloadBytes
),
1450 &payloadBytes
, sizeof(payloadBytes
)) < 0) {
1451 LOGERR("CONTROLVM_PAYLOAD_INIT Failed to read controlvm channel!");
1452 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC
,
1453 POSTCODE_SEVERITY_ERR
);
1456 initialize_controlvm_payload_info(phys_addr
,
1457 payloadOffset
, payloadBytes
,
1458 &ControlVm_payload_info
);
1461 /* Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1462 * Returns CONTROLVM_RESP_xxx code.
1465 visorchipset_chipset_ready(void)
1467 kobject_uevent(&Visorchipset_platform_device
.dev
.kobj
, KOBJ_ONLINE
);
1468 return CONTROLVM_RESP_SUCCESS
;
1470 EXPORT_SYMBOL_GPL(visorchipset_chipset_ready
);
1473 visorchipset_chipset_selftest(void)
1475 char env_selftest
[20];
1476 char *envp
[] = { env_selftest
, NULL
};
1478 sprintf(env_selftest
, "SPARSP_SELFTEST=%d", 1);
1479 kobject_uevent_env(&Visorchipset_platform_device
.dev
.kobj
, KOBJ_CHANGE
,
1481 return CONTROLVM_RESP_SUCCESS
;
1483 EXPORT_SYMBOL_GPL(visorchipset_chipset_selftest
);
1485 /* Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset.
1486 * Returns CONTROLVM_RESP_xxx code.
1489 visorchipset_chipset_notready(void)
1491 kobject_uevent(&Visorchipset_platform_device
.dev
.kobj
, KOBJ_OFFLINE
);
1492 return CONTROLVM_RESP_SUCCESS
;
1494 EXPORT_SYMBOL_GPL(visorchipset_chipset_notready
);
1497 chipset_ready(struct controlvm_message_header
*msgHdr
)
1499 int rc
= visorchipset_chipset_ready();
1501 if (rc
!= CONTROLVM_RESP_SUCCESS
)
1503 if (msgHdr
->flags
.response_expected
&& !visorchipset_holdchipsetready
)
1504 controlvm_respond(msgHdr
, rc
);
1505 if (msgHdr
->flags
.response_expected
&& visorchipset_holdchipsetready
) {
1506 /* Send CHIPSET_READY response when all modules have been loaded
1507 * and disks mounted for the partition
1509 g_ChipSetMsgHdr
= *msgHdr
;
1510 LOGINF("Holding CHIPSET_READY response");
1515 chipset_selftest(struct controlvm_message_header
*msgHdr
)
1517 int rc
= visorchipset_chipset_selftest();
1519 if (rc
!= CONTROLVM_RESP_SUCCESS
)
1521 if (msgHdr
->flags
.response_expected
)
1522 controlvm_respond(msgHdr
, rc
);
1526 chipset_notready(struct controlvm_message_header
*msgHdr
)
1528 int rc
= visorchipset_chipset_notready();
1530 if (rc
!= CONTROLVM_RESP_SUCCESS
)
1532 if (msgHdr
->flags
.response_expected
)
1533 controlvm_respond(msgHdr
, rc
);
1536 /* This is your "one-stop" shop for grabbing the next message from the
1537 * CONTROLVM_QUEUE_EVENT queue in the controlvm channel.
1540 read_controlvm_event(struct controlvm_message
*msg
)
1542 if (visorchannel_signalremove(ControlVm_channel
,
1543 CONTROLVM_QUEUE_EVENT
, msg
)) {
1545 if (msg
->hdr
.flags
.test_message
== 1) {
1546 LOGERR("ignoring bad CONTROLVM_QUEUE_EVENT msg with controlvm_msg_id=0x%x because Flags.testMessage is nonsensical (=1)",
1556 * The general parahotplug flow works as follows. The visorchipset
1557 * driver receives a DEVICE_CHANGESTATE message from Command
1558 * specifying a physical device to enable or disable. The CONTROLVM
1559 * message handler calls parahotplug_process_message, which then adds
1560 * the message to a global list and kicks off a udev event which
1561 * causes a user level script to enable or disable the specified
1562 * device. The udev script then writes to
1563 * /proc/visorchipset/parahotplug, which causes parahotplug_proc_write
1564 * to get called, at which point the appropriate CONTROLVM message is
1565 * retrieved from the list and responded to.
1568 #define PARAHOTPLUG_TIMEOUT_MS 2000
1571 * Generate unique int to match an outstanding CONTROLVM message with a
1572 * udev script /proc response
1575 parahotplug_next_id(void)
1577 static atomic_t id
= ATOMIC_INIT(0);
1579 return atomic_inc_return(&id
);
1583 * Returns the time (in jiffies) when a CONTROLVM message on the list
1584 * should expire -- PARAHOTPLUG_TIMEOUT_MS in the future
1586 static unsigned long
1587 parahotplug_next_expiration(void)
1589 return jiffies
+ PARAHOTPLUG_TIMEOUT_MS
* HZ
/ 1000;
1593 * Create a parahotplug_request, which is basically a wrapper for a
1594 * CONTROLVM_MESSAGE that we can stick on a list
1596 static struct parahotplug_request
*
1597 parahotplug_request_create(struct controlvm_message
*msg
)
1599 struct parahotplug_request
*req
=
1600 kmalloc(sizeof(struct parahotplug_request
),
1601 GFP_KERNEL
|__GFP_NORETRY
);
1605 req
->id
= parahotplug_next_id();
1606 req
->expiration
= parahotplug_next_expiration();
1613 * Free a parahotplug_request.
1616 parahotplug_request_destroy(struct parahotplug_request
*req
)
1622 * Cause uevent to run the user level script to do the disable/enable
1623 * specified in (the CONTROLVM message in) the specified
1624 * parahotplug_request
1627 parahotplug_request_kickoff(struct parahotplug_request
*req
)
1629 struct controlvm_message_packet
*cmd
= &req
->msg
.cmd
;
1630 char env_cmd
[40], env_id
[40], env_state
[40], env_bus
[40], env_dev
[40],
1633 env_cmd
, env_id
, env_state
, env_bus
, env_dev
, env_func
, NULL
1636 sprintf(env_cmd
, "SPAR_PARAHOTPLUG=1");
1637 sprintf(env_id
, "SPAR_PARAHOTPLUG_ID=%d", req
->id
);
1638 sprintf(env_state
, "SPAR_PARAHOTPLUG_STATE=%d",
1639 cmd
->device_change_state
.state
.active
);
1640 sprintf(env_bus
, "SPAR_PARAHOTPLUG_BUS=%d",
1641 cmd
->device_change_state
.bus_no
);
1642 sprintf(env_dev
, "SPAR_PARAHOTPLUG_DEVICE=%d",
1643 cmd
->device_change_state
.dev_no
>> 3);
1644 sprintf(env_func
, "SPAR_PARAHOTPLUG_FUNCTION=%d",
1645 cmd
->device_change_state
.dev_no
& 0x7);
1647 LOGINF("parahotplug_request_kickoff: state=%d, bdf=%d/%d/%d, id=%u\n",
1648 cmd
->device_change_state
.state
.active
,
1649 cmd
->device_change_state
.bus_no
,
1650 cmd
->device_change_state
.dev_no
>> 3,
1651 cmd
->device_change_state
.dev_no
& 7, req
->id
);
1653 kobject_uevent_env(&Visorchipset_platform_device
.dev
.kobj
, KOBJ_CHANGE
,
1658 * Remove any request from the list that's been on there too long and
1659 * respond with an error.
1662 parahotplug_process_list(void)
1664 struct list_head
*pos
= NULL
;
1665 struct list_head
*tmp
= NULL
;
1667 spin_lock(&Parahotplug_request_list_lock
);
1669 list_for_each_safe(pos
, tmp
, &Parahotplug_request_list
) {
1670 struct parahotplug_request
*req
=
1671 list_entry(pos
, struct parahotplug_request
, list
);
1672 if (time_after_eq(jiffies
, req
->expiration
)) {
1674 if (req
->msg
.hdr
.flags
.response_expected
)
1675 controlvm_respond_physdev_changestate(
1677 CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT
,
1678 req
->msg
.cmd
.device_change_state
.state
);
1679 parahotplug_request_destroy(req
);
1683 spin_unlock(&Parahotplug_request_list_lock
);
1687 * Called from the /proc handler, which means the user script has
1688 * finished the enable/disable. Find the matching identifier, and
1689 * respond to the CONTROLVM message with success.
1692 parahotplug_request_complete(int id
, u16 active
)
1694 struct list_head
*pos
= NULL
;
1695 struct list_head
*tmp
= NULL
;
1697 spin_lock(&Parahotplug_request_list_lock
);
1699 /* Look for a request matching "id". */
1700 list_for_each_safe(pos
, tmp
, &Parahotplug_request_list
) {
1701 struct parahotplug_request
*req
=
1702 list_entry(pos
, struct parahotplug_request
, list
);
1703 if (req
->id
== id
) {
1704 /* Found a match. Remove it from the list and
1708 spin_unlock(&Parahotplug_request_list_lock
);
1709 req
->msg
.cmd
.device_change_state
.state
.active
= active
;
1710 if (req
->msg
.hdr
.flags
.response_expected
)
1711 controlvm_respond_physdev_changestate(
1712 &req
->msg
.hdr
, CONTROLVM_RESP_SUCCESS
,
1713 req
->msg
.cmd
.device_change_state
.state
);
1714 parahotplug_request_destroy(req
);
1719 spin_unlock(&Parahotplug_request_list_lock
);
1724 * Enables or disables a PCI device by kicking off a udev script
1727 parahotplug_process_message(struct controlvm_message
*inmsg
)
1729 struct parahotplug_request
*req
;
1731 req
= parahotplug_request_create(inmsg
);
1734 LOGERR("parahotplug_process_message: couldn't allocate request");
1738 if (inmsg
->cmd
.device_change_state
.state
.active
) {
1739 /* For enable messages, just respond with success
1740 * right away. This is a bit of a hack, but there are
1741 * issues with the early enable messages we get (with
1742 * either the udev script not detecting that the device
1743 * is up, or not getting called at all). Fortunately
1744 * the messages that get lost don't matter anyway, as
1745 * devices are automatically enabled at
1748 parahotplug_request_kickoff(req
);
1749 controlvm_respond_physdev_changestate(&inmsg
->hdr
,
1750 CONTROLVM_RESP_SUCCESS
, inmsg
->cmd
.
1751 device_change_state
.state
);
1752 parahotplug_request_destroy(req
);
1754 /* For disable messages, add the request to the
1755 * request list before kicking off the udev script. It
1756 * won't get responded to until the script has
1757 * indicated it's done.
1759 spin_lock(&Parahotplug_request_list_lock
);
1760 list_add_tail(&(req
->list
), &Parahotplug_request_list
);
1761 spin_unlock(&Parahotplug_request_list_lock
);
1763 parahotplug_request_kickoff(req
);
1767 /* Process a controlvm message.
1769 * FALSE - this function will return FALSE only in the case where the
1770 * controlvm message was NOT processed, but processing must be
1771 * retried before reading the next controlvm message; a
1772 * scenario where this can occur is when we need to throttle
1773 * the allocation of memory in which to copy out controlvm
1775 * TRUE - processing of the controlvm message completed,
1776 * either successfully or with an error.
1779 handle_command(struct controlvm_message inmsg
, HOSTADDRESS channel_addr
)
1781 struct controlvm_message_packet
*cmd
= &inmsg
.cmd
;
1782 u64 parametersAddr
= 0;
1783 u32 parametersBytes
= 0;
1784 PARSER_CONTEXT
*parser_ctx
= NULL
;
1785 BOOL isLocalAddr
= FALSE
;
1786 struct controlvm_message ackmsg
;
1788 /* create parsing context if necessary */
1789 isLocalAddr
= (inmsg
.hdr
.flags
.test_message
== 1);
1790 if (channel_addr
== 0) {
1791 LOGERR("HUH? channel_addr is 0!");
1794 parametersAddr
= channel_addr
+ inmsg
.hdr
.payload_vm_offset
;
1795 parametersBytes
= inmsg
.hdr
.payload_bytes
;
1797 /* Parameter and channel addresses within test messages actually lie
1798 * within our OS-controlled memory. We need to know that, because it
1799 * makes a difference in how we compute the virtual address.
1801 if (parametersAddr
!= 0 && parametersBytes
!= 0) {
1805 parser_init_byteStream(parametersAddr
, parametersBytes
,
1806 isLocalAddr
, &retry
);
1809 LOGWRN("throttling to copy payload");
1812 LOGWRN("parsing failed");
1813 LOGWRN("inmsg.hdr.Id=0x%lx", (ulong
) inmsg
.hdr
.id
);
1814 LOGWRN("parametersAddr=0x%llx", (u64
) parametersAddr
);
1815 LOGWRN("parametersBytes=%lu", (ulong
) parametersBytes
);
1816 LOGWRN("isLocalAddr=%d", isLocalAddr
);
1821 controlvm_init_response(&ackmsg
, &inmsg
.hdr
,
1822 CONTROLVM_RESP_SUCCESS
);
1823 if ((ControlVm_channel
)
1825 (!visorchannel_signalinsert
1826 (ControlVm_channel
, CONTROLVM_QUEUE_ACK
, &ackmsg
)))
1827 LOGWRN("failed to send ACK failed");
1829 switch (inmsg
.hdr
.id
) {
1830 case CONTROLVM_CHIPSET_INIT
:
1831 LOGINF("CHIPSET_INIT(#busses=%lu,#switches=%lu)",
1832 (ulong
) inmsg
.cmd
.init_chipset
.bus_count
,
1833 (ulong
) inmsg
.cmd
.init_chipset
.switch_count
);
1834 chipset_init(&inmsg
);
1836 case CONTROLVM_BUS_CREATE
:
1837 LOGINF("BUS_CREATE(%lu,#devs=%lu)",
1838 (ulong
) cmd
->create_bus
.bus_no
,
1839 (ulong
) cmd
->create_bus
.dev_count
);
1842 case CONTROLVM_BUS_DESTROY
:
1843 LOGINF("BUS_DESTROY(%lu)", (ulong
) cmd
->destroy_bus
.bus_no
);
1844 bus_destroy(&inmsg
);
1846 case CONTROLVM_BUS_CONFIGURE
:
1847 LOGINF("BUS_CONFIGURE(%lu)", (ulong
) cmd
->configure_bus
.bus_no
);
1848 bus_configure(&inmsg
, parser_ctx
);
1850 case CONTROLVM_DEVICE_CREATE
:
1851 LOGINF("DEVICE_CREATE(%lu,%lu)",
1852 (ulong
) cmd
->create_device
.bus_no
,
1853 (ulong
) cmd
->create_device
.dev_no
);
1854 my_device_create(&inmsg
);
1856 case CONTROLVM_DEVICE_CHANGESTATE
:
1857 if (cmd
->device_change_state
.flags
.phys_device
) {
1858 LOGINF("DEVICE_CHANGESTATE for physical device (%lu,%lu, active=%lu)",
1859 (ulong
) cmd
->device_change_state
.bus_no
,
1860 (ulong
) cmd
->device_change_state
.dev_no
,
1861 (ulong
) cmd
->device_change_state
.state
.active
);
1862 parahotplug_process_message(&inmsg
);
1864 LOGINF("DEVICE_CHANGESTATE for virtual device (%lu,%lu, state.Alive=0x%lx)",
1865 (ulong
) cmd
->device_change_state
.bus_no
,
1866 (ulong
) cmd
->device_change_state
.dev_no
,
1867 (ulong
) cmd
->device_change_state
.state
.alive
);
1868 /* save the hdr and cmd structures for later use */
1869 /* when sending back the response to Command */
1870 my_device_changestate(&inmsg
);
1871 g_DiagMsgHdr
= inmsg
.hdr
;
1872 g_DeviceChangeStatePacket
= inmsg
.cmd
;
1876 case CONTROLVM_DEVICE_DESTROY
:
1877 LOGINF("DEVICE_DESTROY(%lu,%lu)",
1878 (ulong
) cmd
->destroy_device
.bus_no
,
1879 (ulong
) cmd
->destroy_device
.dev_no
);
1880 my_device_destroy(&inmsg
);
1882 case CONTROLVM_DEVICE_CONFIGURE
:
1883 LOGINF("DEVICE_CONFIGURE(%lu,%lu)",
1884 (ulong
) cmd
->configure_device
.bus_no
,
1885 (ulong
) cmd
->configure_device
.dev_no
);
1886 /* no op for now, just send a respond that we passed */
1887 if (inmsg
.hdr
.flags
.response_expected
)
1888 controlvm_respond(&inmsg
.hdr
, CONTROLVM_RESP_SUCCESS
);
1890 case CONTROLVM_CHIPSET_READY
:
1891 LOGINF("CHIPSET_READY");
1892 chipset_ready(&inmsg
.hdr
);
1894 case CONTROLVM_CHIPSET_SELFTEST
:
1895 LOGINF("CHIPSET_SELFTEST");
1896 chipset_selftest(&inmsg
.hdr
);
1898 case CONTROLVM_CHIPSET_STOP
:
1899 LOGINF("CHIPSET_STOP");
1900 chipset_notready(&inmsg
.hdr
);
1903 LOGERR("unrecognized controlvm cmd=%d", (int) inmsg
.hdr
.id
);
1904 if (inmsg
.hdr
.flags
.response_expected
)
1905 controlvm_respond(&inmsg
.hdr
,
1906 -CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN
);
1910 if (parser_ctx
!= NULL
) {
1911 parser_done(parser_ctx
);
1917 static HOSTADDRESS
controlvm_get_channel_address(void)
1922 if (!VMCALL_SUCCESSFUL(issue_vmcall_io_controlvm_addr(&addr
, &size
))) {
1923 ERRDRV("%s - vmcall to determine controlvm channel addr failed",
1927 INFODRV("controlvm addr=%Lx", addr
);
1932 controlvm_periodic_work(struct work_struct
*work
)
1934 VISORCHIPSET_CHANNEL_INFO chanInfo
;
1935 struct controlvm_message inmsg
;
1936 BOOL gotACommand
= FALSE
;
1937 BOOL handle_command_failed
= FALSE
;
1938 static u64 Poll_Count
;
1940 /* make sure visorbus server is registered for controlvm callbacks */
1941 if (visorchipset_serverregwait
&& !serverregistered
)
1943 /* make sure visorclientbus server is regsitered for controlvm
1946 if (visorchipset_clientregwait
&& !clientregistered
)
1949 memset(&chanInfo
, 0, sizeof(VISORCHIPSET_CHANNEL_INFO
));
1952 if (Poll_Count
>= 250)
1957 /* Check events to determine if response to CHIPSET_READY
1960 if (visorchipset_holdchipsetready
1961 && (g_ChipSetMsgHdr
.id
!= CONTROLVM_INVALID
)) {
1962 if (check_chipset_events() == 1) {
1963 LOGINF("Sending CHIPSET_READY response");
1964 controlvm_respond(&g_ChipSetMsgHdr
, 0);
1965 clear_chipset_events();
1966 memset(&g_ChipSetMsgHdr
, 0,
1967 sizeof(struct controlvm_message_header
));
1971 while (visorchannel_signalremove(ControlVm_channel
,
1972 CONTROLVM_QUEUE_RESPONSE
,
1974 if (inmsg
.hdr
.payload_max_bytes
!= 0) {
1975 LOGERR("Payload of size %lu returned @%lu with unexpected message id %d.",
1976 (ulong
) inmsg
.hdr
.payload_max_bytes
,
1977 (ulong
) inmsg
.hdr
.payload_vm_offset
,
1982 if (ControlVm_Pending_Msg_Valid
) {
1983 /* we throttled processing of a prior
1984 * msg, so try to process it again
1985 * rather than reading a new one
1987 inmsg
= ControlVm_Pending_Msg
;
1988 ControlVm_Pending_Msg_Valid
= FALSE
;
1991 gotACommand
= read_controlvm_event(&inmsg
);
1994 handle_command_failed
= FALSE
;
1995 while (gotACommand
&& (!handle_command_failed
)) {
1996 Most_recent_message_jiffies
= jiffies
;
1997 if (handle_command(inmsg
,
1998 visorchannel_get_physaddr
1999 (ControlVm_channel
)))
2000 gotACommand
= read_controlvm_event(&inmsg
);
2002 /* this is a scenario where throttling
2003 * is required, but probably NOT an
2004 * error...; we stash the current
2005 * controlvm msg so we will attempt to
2006 * reprocess it on our next loop
2008 handle_command_failed
= TRUE
;
2009 ControlVm_Pending_Msg
= inmsg
;
2010 ControlVm_Pending_Msg_Valid
= TRUE
;
2014 /* parahotplug_worker */
2015 parahotplug_process_list();
2019 if (time_after(jiffies
,
2020 Most_recent_message_jiffies
+ (HZ
* MIN_IDLE_SECONDS
))) {
2021 /* it's been longer than MIN_IDLE_SECONDS since we
2022 * processed our last controlvm message; slow down the
2025 if (Poll_jiffies
!= POLLJIFFIES_CONTROLVMCHANNEL_SLOW
) {
2026 LOGINF("switched to slow controlvm polling");
2027 Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_SLOW
;
2030 if (Poll_jiffies
!= POLLJIFFIES_CONTROLVMCHANNEL_FAST
) {
2031 Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_FAST
;
2032 LOGINF("switched to fast controlvm polling");
2036 queue_delayed_work(Periodic_controlvm_workqueue
,
2037 &Periodic_controlvm_work
, Poll_jiffies
);
2041 setup_crash_devices_work_queue(struct work_struct
*work
)
2044 struct controlvm_message localCrashCreateBusMsg
;
2045 struct controlvm_message localCrashCreateDevMsg
;
2046 struct controlvm_message msg
;
2047 u32 localSavedCrashMsgOffset
;
2048 u16 localSavedCrashMsgCount
;
2050 /* make sure visorbus server is registered for controlvm callbacks */
2051 if (visorchipset_serverregwait
&& !serverregistered
)
2054 /* make sure visorclientbus server is regsitered for controlvm
2057 if (visorchipset_clientregwait
&& !clientregistered
)
2060 POSTCODE_LINUX_2(CRASH_DEV_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
2062 /* send init chipset msg */
2063 msg
.hdr
.id
= CONTROLVM_CHIPSET_INIT
;
2064 msg
.cmd
.init_chipset
.bus_count
= 23;
2065 msg
.cmd
.init_chipset
.switch_count
= 0;
2069 /* get saved message count */
2070 if (visorchannel_read(ControlVm_channel
,
2071 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2072 SavedCrashMsgCount
),
2073 &localSavedCrashMsgCount
, sizeof(u16
)) < 0) {
2074 LOGERR("failed to get Saved Message Count");
2075 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC
,
2076 POSTCODE_SEVERITY_ERR
);
2080 if (localSavedCrashMsgCount
!= CONTROLVM_CRASHMSG_MAX
) {
2081 LOGERR("Saved Message Count incorrect %d",
2082 localSavedCrashMsgCount
);
2083 POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC
,
2084 localSavedCrashMsgCount
,
2085 POSTCODE_SEVERITY_ERR
);
2089 /* get saved crash message offset */
2090 if (visorchannel_read(ControlVm_channel
,
2091 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
,
2092 SavedCrashMsgOffset
),
2093 &localSavedCrashMsgOffset
, sizeof(u32
)) < 0) {
2094 LOGERR("failed to get Saved Message Offset");
2095 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC
,
2096 POSTCODE_SEVERITY_ERR
);
2100 /* read create device message for storage bus offset */
2101 if (visorchannel_read(ControlVm_channel
,
2102 localSavedCrashMsgOffset
,
2103 &localCrashCreateBusMsg
,
2104 sizeof(struct controlvm_message
)) < 0) {
2105 LOGERR("CRASH_DEV_RD_BUS_FAIULRE: Failed to read CrashCreateBusMsg!");
2106 POSTCODE_LINUX_2(CRASH_DEV_RD_BUS_FAIULRE_PC
,
2107 POSTCODE_SEVERITY_ERR
);
2111 /* read create device message for storage device */
2112 if (visorchannel_read(ControlVm_channel
,
2113 localSavedCrashMsgOffset
+
2114 sizeof(struct controlvm_message
),
2115 &localCrashCreateDevMsg
,
2116 sizeof(struct controlvm_message
)) < 0) {
2117 LOGERR("CRASH_DEV_RD_DEV_FAIULRE: Failed to read CrashCreateDevMsg!");
2118 POSTCODE_LINUX_2(CRASH_DEV_RD_DEV_FAIULRE_PC
,
2119 POSTCODE_SEVERITY_ERR
);
2123 /* reuse IOVM create bus message */
2124 if (localCrashCreateBusMsg
.cmd
.create_bus
.channel_addr
!= 0)
2125 bus_create(&localCrashCreateBusMsg
);
2127 LOGERR("CrashCreateBusMsg is null, no dump will be taken");
2128 POSTCODE_LINUX_2(CRASH_DEV_BUS_NULL_FAILURE_PC
,
2129 POSTCODE_SEVERITY_ERR
);
2133 /* reuse create device message for storage device */
2134 if (localCrashCreateDevMsg
.cmd
.create_device
.channel_addr
!= 0)
2135 my_device_create(&localCrashCreateDevMsg
);
2137 LOGERR("CrashCreateDevMsg is null, no dump will be taken");
2138 POSTCODE_LINUX_2(CRASH_DEV_DEV_NULL_FAILURE_PC
,
2139 POSTCODE_SEVERITY_ERR
);
2142 LOGINF("Bus and device ready for dumping");
2143 POSTCODE_LINUX_2(CRASH_DEV_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
2148 Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_SLOW
;
2150 queue_delayed_work(Periodic_controlvm_workqueue
,
2151 &Periodic_controlvm_work
, Poll_jiffies
);
2155 bus_create_response(ulong busNo
, int response
)
2157 bus_responder(CONTROLVM_BUS_CREATE
, busNo
, response
);
2161 bus_destroy_response(ulong busNo
, int response
)
2163 bus_responder(CONTROLVM_BUS_DESTROY
, busNo
, response
);
2167 device_create_response(ulong busNo
, ulong devNo
, int response
)
2169 device_responder(CONTROLVM_DEVICE_CREATE
, busNo
, devNo
, response
);
2173 device_destroy_response(ulong busNo
, ulong devNo
, int response
)
2175 device_responder(CONTROLVM_DEVICE_DESTROY
, busNo
, devNo
, response
);
2179 visorchipset_device_pause_response(ulong busNo
, ulong devNo
, int response
)
2182 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE
,
2183 busNo
, devNo
, response
,
2184 segment_state_standby
);
2186 EXPORT_SYMBOL_GPL(visorchipset_device_pause_response
);
2189 device_resume_response(ulong busNo
, ulong devNo
, int response
)
2191 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE
,
2192 busNo
, devNo
, response
,
2193 segment_state_running
);
2197 visorchipset_get_bus_info(ulong busNo
, VISORCHIPSET_BUS_INFO
*busInfo
)
2199 void *p
= findbus(&BusInfoList
, busNo
);
2202 LOGERR("(%lu) failed", busNo
);
2205 memcpy(busInfo
, p
, sizeof(VISORCHIPSET_BUS_INFO
));
2208 EXPORT_SYMBOL_GPL(visorchipset_get_bus_info
);
2211 visorchipset_set_bus_context(ulong busNo
, void *context
)
2213 VISORCHIPSET_BUS_INFO
*p
= findbus(&BusInfoList
, busNo
);
2216 LOGERR("(%lu) failed", busNo
);
2219 p
->bus_driver_context
= context
;
2222 EXPORT_SYMBOL_GPL(visorchipset_set_bus_context
);
2225 visorchipset_get_device_info(ulong busNo
, ulong devNo
,
2226 VISORCHIPSET_DEVICE_INFO
*devInfo
)
2228 void *p
= finddevice(&DevInfoList
, busNo
, devNo
);
2231 LOGERR("(%lu,%lu) failed", busNo
, devNo
);
2234 memcpy(devInfo
, p
, sizeof(VISORCHIPSET_DEVICE_INFO
));
2237 EXPORT_SYMBOL_GPL(visorchipset_get_device_info
);
2240 visorchipset_set_device_context(ulong busNo
, ulong devNo
, void *context
)
2242 VISORCHIPSET_DEVICE_INFO
*p
= finddevice(&DevInfoList
, busNo
, devNo
);
2245 LOGERR("(%lu,%lu) failed", busNo
, devNo
);
2248 p
->bus_driver_context
= context
;
2251 EXPORT_SYMBOL_GPL(visorchipset_set_device_context
);
2253 /* Generic wrapper function for allocating memory from a kmem_cache pool.
2256 visorchipset_cache_alloc(struct kmem_cache
*pool
, BOOL ok_to_block
,
2266 /* __GFP_NORETRY means "ok to fail", meaning
2267 * kmem_cache_alloc() can return NULL, implying the caller CAN
2268 * cope with failure. If you do NOT specify __GFP_NORETRY,
2269 * Linux will go to extreme measures to get memory for you
2270 * (like, invoke oom killer), which will probably cripple the
2273 gfp
|= __GFP_NORETRY
;
2274 p
= kmem_cache_alloc(pool
, gfp
);
2276 LOGERR("kmem_cache_alloc failed early @%s:%d\n", fn
, ln
);
2279 atomic_inc(&Visorchipset_cache_buffers_in_use
);
2283 /* Generic wrapper function for freeing memory from a kmem_cache pool.
2286 visorchipset_cache_free(struct kmem_cache
*pool
, void *p
, char *fn
, int ln
)
2289 LOGERR("NULL pointer @%s:%d\n", fn
, ln
);
2292 atomic_dec(&Visorchipset_cache_buffers_in_use
);
2293 kmem_cache_free(pool
, p
);
2296 static ssize_t
chipsetready_store(struct device
*dev
,
2297 struct device_attribute
*attr
, const char *buf
, size_t count
)
2301 if (sscanf(buf
, "%63s", msgtype
) != 1)
2304 if (strcmp(msgtype
, "CALLHOMEDISK_MOUNTED") == 0) {
2305 chipset_events
[0] = 1;
2307 } else if (strcmp(msgtype
, "MODULES_LOADED") == 0) {
2308 chipset_events
[1] = 1;
2314 /* The parahotplug/devicedisabled interface gets called by our support script
2315 * when an SR-IOV device has been shut down. The ID is passed to the script
2316 * and then passed back when the device has been removed.
2318 static ssize_t
devicedisabled_store(struct device
*dev
,
2319 struct device_attribute
*attr
, const char *buf
, size_t count
)
2323 if (kstrtouint(buf
, 10, &id
) != 0)
2326 parahotplug_request_complete(id
, 0);
2330 /* The parahotplug/deviceenabled interface gets called by our support script
2331 * when an SR-IOV device has been recovered. The ID is passed to the script
2332 * and then passed back when the device has been brought back up.
2334 static ssize_t
deviceenabled_store(struct device
*dev
,
2335 struct device_attribute
*attr
, const char *buf
, size_t count
)
2339 if (kstrtouint(buf
, 10, &id
) != 0)
2342 parahotplug_request_complete(id
, 1);
2347 visorchipset_init(void)
2353 if (!unisys_spar_platform
)
2356 LOGINF("chipset driver version %s loaded", VERSION
);
2357 /* process module options */
2358 POSTCODE_LINUX_2(DRIVER_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
2360 LOGINF("option - testvnic=%d", visorchipset_testvnic
);
2361 LOGINF("option - testvnicclient=%d", visorchipset_testvnicclient
);
2362 LOGINF("option - testmsg=%d", visorchipset_testmsg
);
2363 LOGINF("option - testteardown=%d", visorchipset_testteardown
);
2364 LOGINF("option - major=%d", visorchipset_major
);
2365 LOGINF("option - serverregwait=%d", visorchipset_serverregwait
);
2366 LOGINF("option - clientregwait=%d", visorchipset_clientregwait
);
2367 LOGINF("option - holdchipsetready=%d", visorchipset_holdchipsetready
);
2369 memset(&BusDev_Server_Notifiers
, 0, sizeof(BusDev_Server_Notifiers
));
2370 memset(&BusDev_Client_Notifiers
, 0, sizeof(BusDev_Client_Notifiers
));
2371 memset(&ControlVm_payload_info
, 0, sizeof(ControlVm_payload_info
));
2372 memset(&LiveDump_info
, 0, sizeof(LiveDump_info
));
2373 atomic_set(&LiveDump_info
.buffers_in_use
, 0);
2375 if (visorchipset_testvnic
) {
2376 ERRDRV("testvnic option no longer supported: (status = %d)\n",
2378 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC
, x
, DIAG_SEVERITY_ERR
);
2383 addr
= controlvm_get_channel_address();
2386 visorchannel_create_with_lock
2388 sizeof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL
),
2389 spar_controlvm_channel_protocol_uuid
);
2390 if (SPAR_CONTROLVM_CHANNEL_OK_CLIENT(
2391 visorchannel_get_header(ControlVm_channel
))) {
2392 LOGINF("Channel %s (ControlVm) discovered",
2393 visorchannel_id(ControlVm_channel
, s
));
2394 initialize_controlvm_payload();
2396 LOGERR("controlvm channel is invalid");
2397 visorchannel_destroy(ControlVm_channel
);
2398 ControlVm_channel
= NULL
;
2402 LOGERR("no controlvm channel discovered");
2406 MajorDev
= MKDEV(visorchipset_major
, 0);
2407 rc
= visorchipset_file_init(MajorDev
, &ControlVm_channel
);
2409 ERRDRV("visorchipset_file_init(MajorDev, &ControlVm_channel): error (status=%d)\n", rc
);
2410 POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC
, DIAG_SEVERITY_ERR
);
2414 memset(&g_DiagMsgHdr
, 0, sizeof(struct controlvm_message_header
));
2416 memset(&g_ChipSetMsgHdr
, 0, sizeof(struct controlvm_message_header
));
2418 memset(&g_DelDumpMsgHdr
, 0, sizeof(struct controlvm_message_header
));
2420 Putfile_buffer_list_pool
=
2421 kmem_cache_create(Putfile_buffer_list_pool_name
,
2422 sizeof(struct putfile_buffer_entry
),
2423 0, SLAB_HWCACHE_ALIGN
, NULL
);
2424 if (!Putfile_buffer_list_pool
) {
2425 ERRDRV("failed to alloc Putfile_buffer_list_pool: (status=-1)\n");
2426 POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC
, DIAG_SEVERITY_ERR
);
2430 if (visorchipset_disable_controlvm
) {
2431 LOGINF("visorchipset_init:controlvm disabled");
2433 /* if booting in a crash kernel */
2434 if (visorchipset_crash_kernel
)
2435 INIT_DELAYED_WORK(&Periodic_controlvm_work
,
2436 setup_crash_devices_work_queue
);
2438 INIT_DELAYED_WORK(&Periodic_controlvm_work
,
2439 controlvm_periodic_work
);
2440 Periodic_controlvm_workqueue
=
2441 create_singlethread_workqueue("visorchipset_controlvm");
2443 if (Periodic_controlvm_workqueue
== NULL
) {
2444 ERRDRV("cannot create controlvm workqueue: (status=%d)\n",
2446 POSTCODE_LINUX_2(CREATE_WORKQUEUE_FAILED_PC
,
2451 Most_recent_message_jiffies
= jiffies
;
2452 Poll_jiffies
= POLLJIFFIES_CONTROLVMCHANNEL_FAST
;
2453 rc
= queue_delayed_work(Periodic_controlvm_workqueue
,
2454 &Periodic_controlvm_work
, Poll_jiffies
);
2456 ERRDRV("queue_delayed_work(Periodic_controlvm_workqueue, &Periodic_controlvm_work, Poll_jiffies): error (status=%d)\n", rc
);
2457 POSTCODE_LINUX_2(QUEUE_DELAYED_WORK_PC
,
2464 Visorchipset_platform_device
.dev
.devt
= MajorDev
;
2465 if (platform_device_register(&Visorchipset_platform_device
) < 0) {
2466 ERRDRV("platform_device_register(visorchipset) failed: (status=-1)\n");
2467 POSTCODE_LINUX_2(DEVICE_REGISTER_FAILURE_PC
, DIAG_SEVERITY_ERR
);
2471 LOGINF("visorchipset device created");
2472 POSTCODE_LINUX_2(CHIPSET_INIT_SUCCESS_PC
, POSTCODE_SEVERITY_INFO
);
2476 LOGERR("visorchipset_init failed");
2477 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC
, rc
,
2478 POSTCODE_SEVERITY_ERR
);
2484 visorchipset_exit(void)
2488 POSTCODE_LINUX_2(DRIVER_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
2490 if (visorchipset_disable_controlvm
) {
2493 cancel_delayed_work(&Periodic_controlvm_work
);
2494 flush_workqueue(Periodic_controlvm_workqueue
);
2495 destroy_workqueue(Periodic_controlvm_workqueue
);
2496 Periodic_controlvm_workqueue
= NULL
;
2497 destroy_controlvm_payload_info(&ControlVm_payload_info
);
2499 Test_Vnic_channel
= NULL
;
2500 if (Putfile_buffer_list_pool
) {
2501 kmem_cache_destroy(Putfile_buffer_list_pool
);
2502 Putfile_buffer_list_pool
= NULL
;
2505 cleanup_controlvm_structures();
2507 memset(&g_DiagMsgHdr
, 0, sizeof(struct controlvm_message_header
));
2509 memset(&g_ChipSetMsgHdr
, 0, sizeof(struct controlvm_message_header
));
2511 memset(&g_DelDumpMsgHdr
, 0, sizeof(struct controlvm_message_header
));
2513 LOGINF("Channel %s (ControlVm) disconnected",
2514 visorchannel_id(ControlVm_channel
, s
));
2515 visorchannel_destroy(ControlVm_channel
);
2517 visorchipset_file_cleanup();
2518 POSTCODE_LINUX_2(DRIVER_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
2519 LOGINF("chipset driver unloaded");
2522 module_param_named(testvnic
, visorchipset_testvnic
, int, S_IRUGO
);
2523 MODULE_PARM_DESC(visorchipset_testvnic
, "1 to test vnic, using dummy VNIC connected via a loopback to a physical ethernet");
2524 int visorchipset_testvnic
= 0;
2526 module_param_named(testvnicclient
, visorchipset_testvnicclient
, int, S_IRUGO
);
2527 MODULE_PARM_DESC(visorchipset_testvnicclient
, "1 to test vnic, using real VNIC channel attached to a separate IOVM guest");
2528 int visorchipset_testvnicclient
= 0;
2530 module_param_named(testmsg
, visorchipset_testmsg
, int, S_IRUGO
);
2531 MODULE_PARM_DESC(visorchipset_testmsg
,
2532 "1 to manufacture the chipset, bus, and switch messages");
2533 int visorchipset_testmsg
= 0;
2535 module_param_named(major
, visorchipset_major
, int, S_IRUGO
);
2536 MODULE_PARM_DESC(visorchipset_major
, "major device number to use for the device node");
2537 int visorchipset_major
= 0;
2539 module_param_named(serverregwait
, visorchipset_serverregwait
, int, S_IRUGO
);
2540 MODULE_PARM_DESC(visorchipset_serverreqwait
,
2541 "1 to have the module wait for the visor bus to register");
2542 int visorchipset_serverregwait
= 0; /* default is off */
2543 module_param_named(clientregwait
, visorchipset_clientregwait
, int, S_IRUGO
);
2544 MODULE_PARM_DESC(visorchipset_clientregwait
, "1 to have the module wait for the visorclientbus to register");
2545 int visorchipset_clientregwait
= 1; /* default is on */
2546 module_param_named(testteardown
, visorchipset_testteardown
, int, S_IRUGO
);
2547 MODULE_PARM_DESC(visorchipset_testteardown
,
2548 "1 to test teardown of the chipset, bus, and switch");
2549 int visorchipset_testteardown
= 0; /* default is off */
2550 module_param_named(disable_controlvm
, visorchipset_disable_controlvm
, int,
2552 MODULE_PARM_DESC(visorchipset_disable_controlvm
,
2553 "1 to disable polling of controlVm channel");
2554 int visorchipset_disable_controlvm
= 0; /* default is off */
2555 module_param_named(crash_kernel
, visorchipset_crash_kernel
, int, S_IRUGO
);
2556 MODULE_PARM_DESC(visorchipset_crash_kernel
,
2557 "1 means we are running in crash kernel");
2558 int visorchipset_crash_kernel
= 0; /* default is running in non-crash kernel */
2559 module_param_named(holdchipsetready
, visorchipset_holdchipsetready
,
2561 MODULE_PARM_DESC(visorchipset_holdchipsetready
,
2562 "1 to hold response to CHIPSET_READY");
2563 int visorchipset_holdchipsetready
= 0; /* default is to send CHIPSET_READY
2564 * response immediately */
2565 module_init(visorchipset_init
);
2566 module_exit(visorchipset_exit
);
2568 MODULE_AUTHOR("Unisys");
2569 MODULE_LICENSE("GPL");
2570 MODULE_DESCRIPTION("Supervisor chipset driver for service partition: ver "
2572 MODULE_VERSION(VERSION
);