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