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