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