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