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