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